summaryrefslogtreecommitdiff
path: root/spec/ruby/core/float/next_float_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/core/float/next_float_spec.rb')
-rw-r--r--spec/ruby/core/float/next_float_spec.rb2
1 files changed, 1 insertions, 1 deletions
diff --git a/spec/ruby/core/float/next_float_spec.rb b/spec/ruby/core/float/next_float_spec.rb
index 29e2d31146..59892be343 100644
--- a/spec/ruby/core/float/next_float_spec.rb
+++ b/spec/ruby/core/float/next_float_spec.rb
@@ -9,7 +9,7 @@ describe "Float#next_float" do
barely_positive.should < barely_positive.next_float
midpoint = barely_positive / 2
- [0.0, barely_positive].should include midpoint
+ [0.0, barely_positive].should.include? midpoint
end
it "returns Float::INFINITY for Float::INFINITY" do
td class='rem' style='width: 0.2%;'/> -rw-r--r--spec/ruby/README.md103
-rw-r--r--spec/ruby/appveyor.yml30
-rwxr-xr-xspec/ruby/bin/rubocop12
-rw-r--r--spec/ruby/command_line/backtrace_limit_spec.rb93
-rwxr-xr-xspec/ruby/command_line/dash_0_spec.rb13
-rw-r--r--spec/ruby/command_line/dash_a_spec.rb6
-rw-r--r--spec/ruby/command_line/dash_c_spec.rb2
-rw-r--r--spec/ruby/command_line/dash_d_spec.rb2
-rw-r--r--spec/ruby/command_line/dash_e_spec.rb4
-rw-r--r--spec/ruby/command_line/dash_encoding_spec.rb36
-rw-r--r--spec/ruby/command_line/dash_external_encoding_spec.rb15
-rw-r--r--spec/ruby/command_line/dash_internal_encoding_spec.rb15
-rw-r--r--spec/ruby/command_line/dash_l_spec.rb31
-rw-r--r--spec/ruby/command_line/dash_n_spec.rb10
-rw-r--r--spec/ruby/command_line/dash_p_spec.rb6
-rw-r--r--spec/ruby/command_line/dash_r_spec.rb21
-rw-r--r--spec/ruby/command_line/dash_s_spec.rb2
-rw-r--r--spec/ruby/command_line/dash_upper_c_spec.rb20
-rw-r--r--spec/ruby/command_line/dash_upper_e_spec.rb32
-rw-r--r--spec/ruby/command_line/dash_upper_f_spec.rb4
-rw-r--r--spec/ruby/command_line/dash_upper_i_spec.rb44
-rw-r--r--spec/ruby/command_line/dash_upper_k_spec.rb76
-rw-r--r--spec/ruby/command_line/dash_upper_s_spec.rb44
-rw-r--r--spec/ruby/command_line/dash_upper_u_spec.rb39
-rw-r--r--spec/ruby/command_line/dash_upper_w_spec.rb28
-rw-r--r--spec/ruby/command_line/dash_upper_x_spec.rb6
-rw-r--r--spec/ruby/command_line/dash_v_spec.rb11
-rw-r--r--spec/ruby/command_line/dash_w_spec.rb8
-rw-r--r--spec/ruby/command_line/dash_x_spec.rb8
-rw-r--r--spec/ruby/command_line/error_message_spec.rb15
-rw-r--r--spec/ruby/command_line/feature_spec.rb71
-rw-r--r--spec/ruby/command_line/fixtures/backtrace.rb35
-rw-r--r--spec/ruby/command_line/fixtures/bin/bad_embedded_ruby.txt2
-rw-r--r--spec/ruby/command_line/fixtures/bin/embedded_ruby.txt4
-rw-r--r--spec/ruby/command_line/fixtures/bin/hybrid_launcher.sh2
-rwxr-xr-x[-rw-r--r--]spec/ruby/command_line/fixtures/bin/launcher.rb0
-rw-r--r--spec/ruby/command_line/fixtures/change_directory_script.rb (renamed from spec/ruby/command_line/fixtures/dash_upper_c_script.rb)0
-rw-r--r--spec/ruby/command_line/fixtures/debug_info.rb1
-rw-r--r--spec/ruby/command_line/fixtures/freeze_flag_required_diff_enc.rbbin121 -> 90 bytes-rw-r--r--spec/ruby/command_line/fixtures/freeze_flag_two_literals.rb2
-rw-r--r--spec/ruby/command_line/fixtures/string_literal_frozen_comment.rb4
-rw-r--r--spec/ruby/command_line/fixtures/string_literal_mutable_comment.rb4
-rw-r--r--spec/ruby/command_line/fixtures/string_literal_raw.rb3
-rw-r--r--spec/ruby/command_line/fixtures/test_file.rb2
-rw-r--r--spec/ruby/command_line/frozen_strings_spec.rb100
-rw-r--r--spec/ruby/command_line/rubylib_spec.rb69
-rw-r--r--spec/ruby/command_line/rubyopt_spec.rb91
-rw-r--r--spec/ruby/command_line/shared/change_directory.rb21
-rw-r--r--spec/ruby/command_line/shared/verbose.rb2
-rw-r--r--spec/ruby/command_line/syntax_error_spec.rb10
-rw-r--r--spec/ruby/core/argf/argf_spec.rb6
-rw-r--r--spec/ruby/core/argf/argv_spec.rb4
-rw-r--r--spec/ruby/core/argf/binmode_spec.rb14
-rw-r--r--spec/ruby/core/argf/bytes_spec.rb6
-rw-r--r--spec/ruby/core/argf/chars_spec.rb6
-rw-r--r--spec/ruby/core/argf/close_spec.rb25
-rw-r--r--spec/ruby/core/argf/closed_spec.rb4
-rw-r--r--spec/ruby/core/argf/codepoints_spec.rb6
-rw-r--r--spec/ruby/core/argf/each_byte_spec.rb60
-rw-r--r--spec/ruby/core/argf/each_char_spec.rb60
-rw-r--r--spec/ruby/core/argf/each_codepoint_spec.rb60
-rw-r--r--spec/ruby/core/argf/each_line_spec.rb64
-rw-r--r--spec/ruby/core/argf/each_spec.rb7
-rw-r--r--spec/ruby/core/argf/eof_spec.rb30
-rw-r--r--spec/ruby/core/argf/file_spec.rb2
-rw-r--r--spec/ruby/core/argf/filename_spec.rb30
-rw-r--r--spec/ruby/core/argf/fileno_spec.rb26
-rw-r--r--spec/ruby/core/argf/getc_spec.rb4
-rw-r--r--spec/ruby/core/argf/gets_spec.rb34
-rw-r--r--spec/ruby/core/argf/inspect_spec.rb7
-rw-r--r--spec/ruby/core/argf/lineno_spec.rb2
-rw-r--r--spec/ruby/core/argf/lines_spec.rb6
-rw-r--r--spec/ruby/core/argf/path_spec.rb7
-rw-r--r--spec/ruby/core/argf/pos_spec.rb33
-rw-r--r--spec/ruby/core/argf/read_nonblock_spec.rb16
-rw-r--r--spec/ruby/core/argf/read_spec.rb34
-rw-r--r--spec/ruby/core/argf/readchar_spec.rb6
-rw-r--r--spec/ruby/core/argf/readline_spec.rb6
-rw-r--r--spec/ruby/core/argf/readlines_spec.rb24
-rw-r--r--spec/ruby/core/argf/readpartial_spec.rb26
-rw-r--r--spec/ruby/core/argf/rewind_spec.rb4
-rw-r--r--spec/ruby/core/argf/seek_spec.rb4
-rw-r--r--spec/ruby/core/argf/set_encoding_spec.rb2
-rw-r--r--spec/ruby/core/argf/shared/each_byte.rb58
-rw-r--r--spec/ruby/core/argf/shared/each_char.rb58
-rw-r--r--spec/ruby/core/argf/shared/each_codepoint.rb58
-rw-r--r--spec/ruby/core/argf/shared/each_line.rb62
-rw-r--r--spec/ruby/core/argf/shared/eof.rb24
-rw-r--r--spec/ruby/core/argf/shared/filename.rb28
-rw-r--r--spec/ruby/core/argf/shared/fileno.rb24
-rw-r--r--spec/ruby/core/argf/shared/getc.rb2
-rw-r--r--spec/ruby/core/argf/shared/pos.rb31
-rw-r--r--spec/ruby/core/argf/shared/read.rb4
-rw-r--r--spec/ruby/core/argf/shared/readlines.rb22
-rw-r--r--spec/ruby/core/argf/skip_spec.rb4
-rw-r--r--spec/ruby/core/argf/tell_spec.rb7
-rw-r--r--spec/ruby/core/argf/to_a_spec.rb7
-rw-r--r--spec/ruby/core/argf/to_i_spec.rb7
-rw-r--r--spec/ruby/core/argf/to_io_spec.rb4
-rw-r--r--spec/ruby/core/argf/to_s_spec.rb2
-rw-r--r--spec/ruby/core/array/all_spec.rb13
-rw-r--r--spec/ruby/core/array/allocate_spec.rb6
-rw-r--r--spec/ruby/core/array/any_spec.rb20
-rw-r--r--spec/ruby/core/array/append_spec.rb18
-rw-r--r--spec/ruby/core/array/array_spec.rb2
-rw-r--r--spec/ruby/core/array/assoc_spec.rb44
-rw-r--r--spec/ruby/core/array/at_spec.rb8
-rw-r--r--spec/ruby/core/array/bsearch_index_spec.rb120
-rw-r--r--spec/ruby/core/array/bsearch_spec.rb30
-rw-r--r--spec/ruby/core/array/clear_spec.rb33
-rw-r--r--spec/ruby/core/array/clone_spec.rb18
-rw-r--r--spec/ruby/core/array/collect_spec.rb12
-rw-r--r--spec/ruby/core/array/combination_spec.rb10
-rw-r--r--spec/ruby/core/array/compact_spec.rb46
-rw-r--r--spec/ruby/core/array/comparison_spec.rb6
-rw-r--r--spec/ruby/core/array/concat_spec.rb102
-rw-r--r--spec/ruby/core/array/constructor_spec.rb8
-rw-r--r--spec/ruby/core/array/count_spec.rb13
-rw-r--r--spec/ruby/core/array/cycle_spec.rb30
-rw-r--r--spec/ruby/core/array/deconstruct_spec.rb9
-rw-r--r--spec/ruby/core/array/delete_at_spec.rb28
-rw-r--r--spec/ruby/core/array/delete_if_spec.rb66
-rw-r--r--spec/ruby/core/array/delete_spec.rb28
-rw-r--r--spec/ruby/core/array/difference_spec.rb22
-rw-r--r--spec/ruby/core/array/dig_spec.rb100
-rw-r--r--spec/ruby/core/array/drop_spec.rb27
-rw-r--r--spec/ruby/core/array/drop_while_spec.rb11
-rw-r--r--spec/ruby/core/array/dup_spec.rb18
-rw-r--r--spec/ruby/core/array/each_index_spec.rb28
-rw-r--r--spec/ruby/core/array/each_spec.rb66
-rw-r--r--spec/ruby/core/array/element_reference_spec.rb865
-rw-r--r--spec/ruby/core/array/element_set_spec.rb190
-rw-r--r--spec/ruby/core/array/empty_spec.rb10
-rw-r--r--spec/ruby/core/array/eql_spec.rb12
-rw-r--r--spec/ruby/core/array/equal_value_spec.rb22
-rw-r--r--spec/ruby/core/array/fetch_spec.rb16
-rw-r--r--spec/ruby/core/array/fetch_values_spec.rb55
-rw-r--r--spec/ruby/core/array/fill_spec.rb155
-rw-r--r--spec/ruby/core/array/filter_spec.rb13
-rw-r--r--spec/ruby/core/array/find_index_spec.rb42
-rw-r--r--spec/ruby/core/array/first_spec.rb28
-rw-r--r--spec/ruby/core/array/fixtures/classes.rb809
-rw-r--r--spec/ruby/core/array/fixtures/encoded_strings.rb30
-rw-r--r--spec/ruby/core/array/flatten_spec.rb84
-rw-r--r--spec/ruby/core/array/frozen_spec.rb10
-rw-r--r--spec/ruby/core/array/hash_spec.rb12
-rw-r--r--spec/ruby/core/array/include_spec.rb4
-rw-r--r--spec/ruby/core/array/index_spec.rb7
-rw-r--r--spec/ruby/core/array/initialize_spec.rb50
-rw-r--r--spec/ruby/core/array/insert_spec.rb22
-rw-r--r--spec/ruby/core/array/inspect_spec.rb109
-rw-r--r--spec/ruby/core/array/intersect_spec.rb64
-rw-r--r--spec/ruby/core/array/intersection_spec.rb90
-rw-r--r--spec/ruby/core/array/join_spec.rb116
-rw-r--r--spec/ruby/core/array/keep_if_spec.rb5
-rw-r--r--spec/ruby/core/array/last_spec.rb28
-rw-r--r--spec/ruby/core/array/length_spec.rb8
-rw-r--r--spec/ruby/core/array/map_spec.rb142
-rw-r--r--spec/ruby/core/array/max_spec.rb20
-rw-r--r--spec/ruby/core/array/min_spec.rb22
-rw-r--r--spec/ruby/core/array/minmax_spec.rb14
-rw-r--r--spec/ruby/core/array/minus_spec.rb88
-rw-r--r--spec/ruby/core/array/multiply_spec.rb68
-rw-r--r--spec/ruby/core/array/new_spec.rb40
-rw-r--r--spec/ruby/core/array/none_spec.rb13
-rw-r--r--spec/ruby/core/array/one_spec.rb13
-rw-r--r--spec/ruby/core/array/pack/a_spec.rb28
-rw-r--r--spec/ruby/core/array/pack/at_spec.rb8
-rw-r--r--spec/ruby/core/array/pack/b_spec.rb28
-rw-r--r--spec/ruby/core/array/pack/buffer_spec.rb86
-rw-r--r--spec/ruby/core/array/pack/c_spec.rb16
-rw-r--r--spec/ruby/core/array/pack/comment_spec.rb6
-rw-r--r--spec/ruby/core/array/pack/d_spec.rb10
-rw-r--r--spec/ruby/core/array/pack/e_spec.rb10
-rw-r--r--spec/ruby/core/array/pack/empty_spec.rb2
-rw-r--r--spec/ruby/core/array/pack/f_spec.rb10
-rw-r--r--spec/ruby/core/array/pack/g_spec.rb10
-rw-r--r--spec/ruby/core/array/pack/h_spec.rb26
-rw-r--r--spec/ruby/core/array/pack/i_spec.rb10
-rw-r--r--spec/ruby/core/array/pack/j_spec.rb319
-rw-r--r--spec/ruby/core/array/pack/l_spec.rb26
-rw-r--r--spec/ruby/core/array/pack/m_spec.rb33
-rw-r--r--spec/ruby/core/array/pack/n_spec.rb10
-rw-r--r--spec/ruby/core/array/pack/p_spec.rb33
-rw-r--r--spec/ruby/core/array/pack/percent_spec.rb4
-rw-r--r--spec/ruby/core/array/pack/q_spec.rb10
-rw-r--r--spec/ruby/core/array/pack/r_spec.rb89
-rw-r--r--spec/ruby/core/array/pack/s_spec.rb10
-rw-r--r--spec/ruby/core/array/pack/shared/basic.rb42
-rw-r--r--spec/ruby/core/array/pack/shared/encodings.rb4
-rw-r--r--spec/ruby/core/array/pack/shared/float.rb112
-rw-r--r--spec/ruby/core/array/pack/shared/integer.rb48
-rw-r--r--spec/ruby/core/array/pack/shared/numeric_basic.rb30
-rw-r--r--spec/ruby/core/array/pack/shared/string.rb48
-rw-r--r--spec/ruby/core/array/pack/shared/taint.rb2
-rw-r--r--spec/ruby/core/array/pack/shared/unicode.rb14
-rw-r--r--spec/ruby/core/array/pack/u_spec.rb30
-rw-r--r--spec/ruby/core/array/pack/v_spec.rb10
-rw-r--r--spec/ruby/core/array/pack/w_spec.rb22
-rw-r--r--spec/ruby/core/array/pack/x_spec.rb13
-rw-r--r--spec/ruby/core/array/pack/z_spec.rb24
-rw-r--r--spec/ruby/core/array/partition_spec.rb10
-rw-r--r--spec/ruby/core/array/permutation_spec.rb14
-rw-r--r--spec/ruby/core/array/plus_spec.rb45
-rw-r--r--spec/ruby/core/array/pop_spec.rb78
-rw-r--r--spec/ruby/core/array/prepend_spec.rb7
-rw-r--r--spec/ruby/core/array/product_spec.rb29
-rw-r--r--spec/ruby/core/array/push_spec.rb14
-rw-r--r--spec/ruby/core/array/rassoc_spec.rb22
-rw-r--r--spec/ruby/core/array/reject_spec.rb69
-rw-r--r--spec/ruby/core/array/repeated_combination_spec.rb12
-rw-r--r--spec/ruby/core/array/repeated_permutation_spec.rb6
-rw-r--r--spec/ruby/core/array/replace_spec.rb64
-rw-r--r--spec/ruby/core/array/reverse_each_spec.rb26
-rw-r--r--spec/ruby/core/array/reverse_spec.rb12
-rw-r--r--spec/ruby/core/array/rindex_spec.rb27
-rw-r--r--spec/ruby/core/array/rotate_spec.rb58
-rw-r--r--spec/ruby/core/array/sample_spec.rb88
-rw-r--r--spec/ruby/core/array/select_spec.rb23
-rw-r--r--spec/ruby/core/array/shared/clone.rb30
-rw-r--r--spec/ruby/core/array/shared/collect.rb136
-rw-r--r--spec/ruby/core/array/shared/delete_if.rb24
-rw-r--r--spec/ruby/core/array/shared/difference.rb78
-rw-r--r--spec/ruby/core/array/shared/enumeratorize.rb2
-rw-r--r--spec/ruby/core/array/shared/eql.rb66
-rw-r--r--spec/ruby/core/array/shared/index.rb37
-rw-r--r--spec/ruby/core/array/shared/inspect.rb144
-rw-r--r--spec/ruby/core/array/shared/intersection.rb85
-rw-r--r--spec/ruby/core/array/shared/iterable_and_tolerating_size_increasing.rb25
-rw-r--r--spec/ruby/core/array/shared/join.rb150
-rw-r--r--spec/ruby/core/array/shared/keep_if.rb55
-rw-r--r--spec/ruby/core/array/shared/length.rb11
-rw-r--r--spec/ruby/core/array/shared/replace.rb60
-rw-r--r--spec/ruby/core/array/shared/slice.rb459
-rw-r--r--spec/ruby/core/array/shared/union.rb79
-rw-r--r--spec/ruby/core/array/shift_spec.rb42
-rw-r--r--spec/ruby/core/array/shuffle_spec.rb63
-rw-r--r--spec/ruby/core/array/size_spec.rb15
-rw-r--r--spec/ruby/core/array/slice_spec.rb75
-rw-r--r--spec/ruby/core/array/sort_by_spec.rb57
-rw-r--r--spec/ruby/core/array/sort_spec.rb68
-rw-r--r--spec/ruby/core/array/sum_spec.rb110
-rw-r--r--spec/ruby/core/array/take_spec.rb9
-rw-r--r--spec/ruby/core/array/take_while_spec.rb13
-rw-r--r--spec/ruby/core/array/to_a_spec.rb8
-rw-r--r--spec/ruby/core/array/to_ary_spec.rb8
-rw-r--r--spec/ruby/core/array/to_h_spec.rb64
-rw-r--r--spec/ruby/core/array/to_s_spec.rb9
-rw-r--r--spec/ruby/core/array/transpose_spec.rb14
-rw-r--r--spec/ruby/core/array/try_convert_spec.rb20
-rw-r--r--spec/ruby/core/array/union_spec.rb85
-rw-r--r--spec/ruby/core/array/uniq_spec.rb68
-rw-r--r--spec/ruby/core/array/unshift_spec.rb37
-rw-r--r--spec/ruby/core/array/values_at_spec.rb17
-rw-r--r--spec/ruby/core/array/zip_spec.rb14
-rw-r--r--spec/ruby/core/basicobject/__id__spec.rb4
-rw-r--r--spec/ruby/core/basicobject/__send___spec.rb8
-rw-r--r--spec/ruby/core/basicobject/basicobject_spec.rb26
-rw-r--r--spec/ruby/core/basicobject/equal_spec.rb51
-rw-r--r--spec/ruby/core/basicobject/equal_value_spec.rb50
-rw-r--r--spec/ruby/core/basicobject/fixtures/classes.rb228
-rw-r--r--spec/ruby/core/basicobject/initialize_spec.rb8
-rw-r--r--spec/ruby/core/basicobject/instance_eval_spec.rb223
-rw-r--r--spec/ruby/core/basicobject/instance_exec_spec.rb60
-rw-r--r--spec/ruby/core/basicobject/method_missing_spec.rb5
-rw-r--r--spec/ruby/core/basicobject/not_equal_spec.rb18
-rw-r--r--spec/ruby/core/basicobject/not_spec.rb6
-rw-r--r--spec/ruby/core/basicobject/singleton_method_added_spec.rb69
-rw-r--r--spec/ruby/core/basicobject/singleton_method_removed_spec.rb4
-rw-r--r--spec/ruby/core/basicobject/singleton_method_undefined_spec.rb4
-rw-r--r--spec/ruby/core/bignum/abs_spec.rb7
-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.rb14
-rw-r--r--spec/ruby/core/binding/dup_spec.rb31
-rw-r--r--spec/ruby/core/binding/eval_spec.rb78
-rw-r--r--spec/ruby/core/binding/fixtures/classes.rb26
-rw-r--r--spec/ruby/core/binding/fixtures/location.rb6
-rw-r--r--spec/ruby/core/binding/local_variable_defined_spec.rb4
-rw-r--r--spec/ruby/core/binding/local_variable_get_spec.rb20
-rw-r--r--spec/ruby/core/binding/local_variable_set_spec.rb12
-rw-r--r--spec/ruby/core/binding/local_variables_spec.rb4
-rw-r--r--spec/ruby/core/binding/location_spec.rb46
-rw-r--r--spec/ruby/core/binding/receiver_spec.rb4
-rw-r--r--spec/ruby/core/binding/shared/clone.rb22
-rw-r--r--spec/ruby/core/binding/source_location_spec.rb14
-rw-r--r--spec/ruby/core/builtin_constants/builtin_constants_spec.rb122
-rw-r--r--spec/ruby/core/class/allocate_spec.rb14
-rw-r--r--spec/ruby/core/class/attached_object_spec.rb29
-rw-r--r--spec/ruby/core/class/dup_spec.rb11
-rw-r--r--spec/ruby/core/class/inherited_spec.rb26
-rw-r--r--spec/ruby/core/class/initialize_spec.rb20
-rw-r--r--spec/ruby/core/class/new_spec.rb31
-rw-r--r--spec/ruby/core/class/subclasses_spec.rb85
-rw-r--r--spec/ruby/core/class/superclass_spec.rb8
-rw-r--r--spec/ruby/core/class/to_s_spec.rb23
-rw-r--r--spec/ruby/core/comparable/between_spec.rb4
-rw-r--r--spec/ruby/core/comparable/clamp_spec.rb223
-rw-r--r--spec/ruby/core/comparable/equal_value_spec.rb45
-rw-r--r--spec/ruby/core/comparable/fixtures/classes.rb1
-rw-r--r--spec/ruby/core/comparable/gt_spec.rb6
-rw-r--r--spec/ruby/core/comparable/gte_spec.rb6
-rw-r--r--spec/ruby/core/comparable/lt_spec.rb12
-rw-r--r--spec/ruby/core/comparable/lte_spec.rb6
-rw-r--r--spec/ruby/core/complex/abs2_spec.rb8
-rw-r--r--spec/ruby/core/complex/abs_spec.rb11
-rw-r--r--spec/ruby/core/complex/angle_spec.rb8
-rw-r--r--spec/ruby/core/complex/arg_spec.rb12
-rw-r--r--spec/ruby/core/complex/coerce_spec.rb69
-rw-r--r--spec/ruby/core/complex/comparison_spec.rb25
-rw-r--r--spec/ruby/core/complex/conj_spec.rb7
-rw-r--r--spec/ruby/core/complex/conjugate_spec.rb10
-rw-r--r--spec/ruby/core/complex/constants_spec.rb6
-rw-r--r--spec/ruby/core/complex/denominator_spec.rb12
-rw-r--r--spec/ruby/core/complex/divide_spec.rb83
-rw-r--r--spec/ruby/core/complex/eql_spec.rb14
-rw-r--r--spec/ruby/core/complex/equal_value_spec.rb92
-rw-r--r--spec/ruby/core/complex/exponent_spec.rb60
-rw-r--r--spec/ruby/core/complex/fdiv_spec.rb44
-rw-r--r--spec/ruby/core/complex/finite_spec.rb52
-rw-r--r--spec/ruby/core/complex/hash_spec.rb16
-rw-r--r--spec/ruby/core/complex/imag_spec.rb6
-rw-r--r--spec/ruby/core/complex/imaginary_spec.rb9
-rw-r--r--spec/ruby/core/complex/infinite_spec.rb50
-rw-r--r--spec/ruby/core/complex/inspect_spec.rb36
-rw-r--r--spec/ruby/core/complex/integer_spec.rb6
-rw-r--r--spec/ruby/core/complex/magnitude_spec.rb6
-rw-r--r--spec/ruby/core/complex/marshal_dump_spec.rb4
-rw-r--r--spec/ruby/core/complex/minus_spec.rb44
-rw-r--r--spec/ruby/core/complex/multiply_spec.rb48
-rw-r--r--spec/ruby/core/complex/negative_spec.rb8
-rw-r--r--spec/ruby/core/complex/numerator_spec.rb18
-rw-r--r--spec/ruby/core/complex/phase_spec.rb7
-rw-r--r--spec/ruby/core/complex/plus_spec.rb44
-rw-r--r--spec/ruby/core/complex/polar_spec.rb37
-rw-r--r--spec/ruby/core/complex/positive_spec.rb8
-rw-r--r--spec/ruby/core/complex/quo_spec.rb6
-rw-r--r--spec/ruby/core/complex/rationalize_spec.rb10
-rw-r--r--spec/ruby/core/complex/real_spec.rb17
-rw-r--r--spec/ruby/core/complex/rect_spec.rb10
-rw-r--r--spec/ruby/core/complex/rectangular_spec.rb111
-rw-r--r--spec/ruby/core/complex/to_c_spec.rb12
-rw-r--r--spec/ruby/core/complex/to_f_spec.rb8
-rw-r--r--spec/ruby/core/complex/to_i_spec.rb8
-rw-r--r--spec/ruby/core/complex/to_r_spec.rb18
-rw-r--r--spec/ruby/core/complex/to_s_spec.rb54
-rw-r--r--spec/ruby/core/complex/uminus_spec.rb2
-rw-r--r--spec/ruby/core/conditionvariable/broadcast_spec.rb39
-rw-r--r--spec/ruby/core/conditionvariable/marshal_dump_spec.rb8
-rw-r--r--spec/ruby/core/conditionvariable/signal_spec.rb76
-rw-r--r--spec/ruby/core/conditionvariable/wait_spec.rb174
-rw-r--r--spec/ruby/core/data/constants_spec.rb11
-rw-r--r--spec/ruby/core/data/deconstruct_keys_spec.rb110
-rw-r--r--spec/ruby/core/data/deconstruct_spec.rb8
-rw-r--r--spec/ruby/core/data/define_spec.rb34
-rw-r--r--spec/ruby/core/data/eql_spec.rb63
-rw-r--r--spec/ruby/core/data/equal_value_spec.rb63
-rw-r--r--spec/ruby/core/data/fixtures/classes.rb41
-rw-r--r--spec/ruby/core/data/hash_spec.rb25
-rw-r--r--spec/ruby/core/data/initialize_spec.rb204
-rw-r--r--spec/ruby/core/data/inspect_spec.rb8
-rw-r--r--spec/ruby/core/data/members_spec.rb21
-rw-r--r--spec/ruby/core/data/to_h_spec.rb63
-rw-r--r--spec/ruby/core/data/to_s_spec.rb63
-rw-r--r--spec/ruby/core/data/with_spec.rb55
-rw-r--r--spec/ruby/core/dir/chdir_spec.rb132
-rw-r--r--spec/ruby/core/dir/children_spec.rb147
-rw-r--r--spec/ruby/core/dir/chroot_spec.rb14
-rw-r--r--spec/ruby/core/dir/close_spec.rb52
-rw-r--r--spec/ruby/core/dir/delete_spec.rb57
-rw-r--r--spec/ruby/core/dir/dir_spec.rb2
-rw-r--r--spec/ruby/core/dir/each_child_spec.rb119
-rw-r--r--spec/ruby/core/dir/each_spec.rb21
-rw-r--r--spec/ruby/core/dir/element_reference_spec.rb6
-rw-r--r--spec/ruby/core/dir/empty_spec.rb48
-rw-r--r--spec/ruby/core/dir/entries_spec.rb26
-rw-r--r--spec/ruby/core/dir/exist_spec.rb67
-rw-r--r--spec/ruby/core/dir/exists_spec.rb15
-rw-r--r--spec/ruby/core/dir/fchdir_spec.rb71
-rw-r--r--spec/ruby/core/dir/fileno_spec.rb8
-rw-r--r--spec/ruby/core/dir/fixtures/common.rb68
-rw-r--r--spec/ruby/core/dir/for_fd_spec.rb77
-rw-r--r--spec/ruby/core/dir/foreach_spec.rb22
-rw-r--r--spec/ruby/core/dir/getwd_spec.rb14
-rw-r--r--spec/ruby/core/dir/glob_spec.rb220
-rw-r--r--spec/ruby/core/dir/home_spec.rb85
-rw-r--r--spec/ruby/core/dir/initialize_spec.rb4
-rw-r--r--spec/ruby/core/dir/inspect_spec.rb8
-rw-r--r--spec/ruby/core/dir/mkdir_spec.rb86
-rw-r--r--spec/ruby/core/dir/open_spec.rb77
-rw-r--r--spec/ruby/core/dir/path_spec.rb14
-rw-r--r--spec/ruby/core/dir/pos_spec.rb37
-rw-r--r--spec/ruby/core/dir/pwd_spec.rb49
-rw-r--r--spec/ruby/core/dir/read_spec.rb41
-rw-r--r--spec/ruby/core/dir/rewind_spec.rb6
-rw-r--r--spec/ruby/core/dir/rmdir_spec.rb14
-rw-r--r--spec/ruby/core/dir/scan_spec.rb224
-rw-r--r--spec/ruby/core/dir/seek_spec.rb6
-rw-r--r--spec/ruby/core/dir/shared/chroot.rb21
-rw-r--r--spec/ruby/core/dir/shared/closed.rb4
-rw-r--r--spec/ruby/core/dir/shared/delete.rb61
-rw-r--r--spec/ruby/core/dir/shared/exist.rb56
-rw-r--r--spec/ruby/core/dir/shared/glob.rb147
-rw-r--r--spec/ruby/core/dir/shared/open.rb63
-rw-r--r--spec/ruby/core/dir/shared/path.rb32
-rw-r--r--spec/ruby/core/dir/shared/pos.rb27
-rw-r--r--spec/ruby/core/dir/shared/pwd.rb49
-rw-r--r--spec/ruby/core/dir/tell_spec.rb19
-rw-r--r--spec/ruby/core/dir/to_path_spec.rb30
-rw-r--r--spec/ruby/core/dir/unlink_spec.rb14
-rw-r--r--spec/ruby/core/encoding/_dump_spec.rb2
-rw-r--r--spec/ruby/core/encoding/_load_spec.rb2
-rw-r--r--spec/ruby/core/encoding/aliases_spec.rb62
-rw-r--r--spec/ruby/core/encoding/ascii_compatible_spec.rb25
-rw-r--r--spec/ruby/core/encoding/compatible_spec.rb965
-rw-r--r--spec/ruby/core/encoding/converter/asciicompat_encoding_spec.rb56
-rw-r--r--spec/ruby/core/encoding/converter/constants_spec.rb184
-rw-r--r--spec/ruby/core/encoding/converter/convert_spec.rb74
-rw-r--r--spec/ruby/core/encoding/converter/convpath_spec.rb77
-rw-r--r--spec/ruby/core/encoding/converter/destination_encoding_spec.rb16
-rw-r--r--spec/ruby/core/encoding/converter/finish_spec.rb56
-rw-r--r--spec/ruby/core/encoding/converter/insert_output_spec.rb2
-rw-r--r--spec/ruby/core/encoding/converter/inspect_spec.rb2
-rw-r--r--spec/ruby/core/encoding/converter/last_error_spec.rb152
-rw-r--r--spec/ruby/core/encoding/converter/new_spec.rb200
-rw-r--r--spec/ruby/core/encoding/converter/primitive_convert_spec.rb425
-rw-r--r--spec/ruby/core/encoding/converter/primitive_errinfo_spec.rb115
-rw-r--r--spec/ruby/core/encoding/converter/putback_spec.rb101
-rw-r--r--spec/ruby/core/encoding/converter/replacement_spec.rb116
-rw-r--r--spec/ruby/core/encoding/converter/search_convpath_spec.rb89
-rw-r--r--spec/ruby/core/encoding/converter/source_encoding_spec.rb16
-rw-r--r--spec/ruby/core/encoding/default_external_spec.rb107
-rw-r--r--spec/ruby/core/encoding/default_internal_spec.rb141
-rw-r--r--spec/ruby/core/encoding/dummy_spec.rb31
-rw-r--r--spec/ruby/core/encoding/find_spec.rb120
-rw-r--r--spec/ruby/core/encoding/fixtures/classes.rb2
-rw-r--r--spec/ruby/core/encoding/inspect_spec.rb30
-rw-r--r--spec/ruby/core/encoding/invalid_byte_sequence_error/destination_encoding_name_spec.rb29
-rw-r--r--spec/ruby/core/encoding/invalid_byte_sequence_error/destination_encoding_spec.rb29
-rw-r--r--spec/ruby/core/encoding/invalid_byte_sequence_error/error_bytes_spec.rb47
-rw-r--r--spec/ruby/core/encoding/invalid_byte_sequence_error/incomplete_input_spec.rb45
-rw-r--r--spec/ruby/core/encoding/invalid_byte_sequence_error/readagain_bytes_spec.rb47
-rw-r--r--spec/ruby/core/encoding/invalid_byte_sequence_error/source_encoding_name_spec.rb47
-rw-r--r--spec/ruby/core/encoding/invalid_byte_sequence_error/source_encoding_spec.rb55
-rw-r--r--spec/ruby/core/encoding/list_spec.rb66
-rw-r--r--spec/ruby/core/encoding/locale_charmap_spec.rb45
-rw-r--r--spec/ruby/core/encoding/name_list_spec.rb32
-rw-r--r--spec/ruby/core/encoding/name_spec.rb16
-rw-r--r--spec/ruby/core/encoding/names_spec.rb50
-rw-r--r--spec/ruby/core/encoding/replicate_spec.rb50
-rw-r--r--spec/ruby/core/encoding/shared/name.rb15
-rw-r--r--spec/ruby/core/encoding/to_s_spec.rb8
-rw-r--r--spec/ruby/core/encoding/undefined_conversion_error/destination_encoding_name_spec.rb23
-rw-r--r--spec/ruby/core/encoding/undefined_conversion_error/destination_encoding_spec.rb23
-rw-r--r--spec/ruby/core/encoding/undefined_conversion_error/error_char_spec.rb41
-rw-r--r--spec/ruby/core/encoding/undefined_conversion_error/source_encoding_name_spec.rb47
-rw-r--r--spec/ruby/core/encoding/undefined_conversion_error/source_encoding_spec.rb49
-rw-r--r--spec/ruby/core/enumerable/all_spec.rb128
-rw-r--r--spec/ruby/core/enumerable/any_spec.rb139
-rw-r--r--spec/ruby/core/enumerable/chain_spec.rb23
-rw-r--r--spec/ruby/core/enumerable/chunk_spec.rb71
-rw-r--r--spec/ruby/core/enumerable/chunk_while_spec.rb64
-rw-r--r--spec/ruby/core/enumerable/collect_concat_spec.rb8
-rw-r--r--spec/ruby/core/enumerable/collect_spec.rb8
-rw-r--r--spec/ruby/core/enumerable/compact_spec.rb9
-rw-r--r--spec/ruby/core/enumerable/count_spec.rb4
-rw-r--r--spec/ruby/core/enumerable/cycle_spec.rb16
-rw-r--r--spec/ruby/core/enumerable/detect_spec.rb8
-rw-r--r--spec/ruby/core/enumerable/drop_spec.rb14
-rw-r--r--spec/ruby/core/enumerable/drop_while_spec.rb10
-rw-r--r--spec/ruby/core/enumerable/each_cons_spec.rb32
-rw-r--r--spec/ruby/core/enumerable/each_entry_spec.rb14
-rw-r--r--spec/ruby/core/enumerable/each_slice_spec.rb34
-rw-r--r--spec/ruby/core/enumerable/each_with_index_spec.rb12
-rw-r--r--spec/ruby/core/enumerable/each_with_object_spec.rb14
-rw-r--r--spec/ruby/core/enumerable/entries_spec.rb8
-rw-r--r--spec/ruby/core/enumerable/filter_map_spec.rb24
-rw-r--r--spec/ruby/core/enumerable/filter_spec.rb7
-rw-r--r--spec/ruby/core/enumerable/find_all_spec.rb8
-rw-r--r--spec/ruby/core/enumerable/find_index_spec.rb8
-rw-r--r--spec/ruby/core/enumerable/find_spec.rb79
-rw-r--r--spec/ruby/core/enumerable/first_spec.rb8
-rw-r--r--spec/ruby/core/enumerable/fixtures/classes.rb25
-rw-r--r--spec/ruby/core/enumerable/flat_map_spec.rb57
-rw-r--r--spec/ruby/core/enumerable/grep_spec.rb41
-rw-r--r--spec/ruby/core/enumerable/grep_v_spec.rb113
-rw-r--r--spec/ruby/core/enumerable/group_by_spec.rb22
-rw-r--r--spec/ruby/core/enumerable/include_spec.rb37
-rw-r--r--spec/ruby/core/enumerable/inject_spec.rb145
-rw-r--r--spec/ruby/core/enumerable/lazy_spec.rb6
-rw-r--r--spec/ruby/core/enumerable/map_spec.rb110
-rw-r--r--spec/ruby/core/enumerable/max_by_spec.rb14
-rw-r--r--spec/ruby/core/enumerable/max_spec.rb18
-rw-r--r--spec/ruby/core/enumerable/member_spec.rb8
-rw-r--r--spec/ruby/core/enumerable/min_by_spec.rb14
-rw-r--r--spec/ruby/core/enumerable/min_spec.rb20
-rw-r--r--spec/ruby/core/enumerable/minmax_by_spec.rb12
-rw-r--r--spec/ruby/core/enumerable/minmax_spec.rb38
-rw-r--r--spec/ruby/core/enumerable/none_spec.rb172
-rw-r--r--spec/ruby/core/enumerable/one_spec.rb143
-rw-r--r--spec/ruby/core/enumerable/partition_spec.rb8
-rw-r--r--spec/ruby/core/enumerable/reduce_spec.rb8
-rw-r--r--spec/ruby/core/enumerable/reject_spec.rb8
-rw-r--r--spec/ruby/core/enumerable/reverse_each_spec.rb8
-rw-r--r--spec/ruby/core/enumerable/select_spec.rb34
-rw-r--r--spec/ruby/core/enumerable/shared/collect.rb32
-rw-r--r--spec/ruby/core/enumerable/shared/collect_concat.rb54
-rw-r--r--spec/ruby/core/enumerable/shared/entries.rb24
-rw-r--r--spec/ruby/core/enumerable/shared/enumerable_enumeratorized.rb2
-rw-r--r--spec/ruby/core/enumerable/shared/find.rb73
-rw-r--r--spec/ruby/core/enumerable/shared/find_all.rb31
-rw-r--r--spec/ruby/core/enumerable/shared/include.rb34
-rw-r--r--spec/ruby/core/enumerable/shared/inject.rb69
-rw-r--r--spec/ruby/core/enumerable/shared/take.rb8
-rw-r--r--spec/ruby/core/enumerable/shared/value_packing.rb26
-rw-r--r--spec/ruby/core/enumerable/slice_after_spec.rb14
-rw-r--r--spec/ruby/core/enumerable/slice_before_spec.rb45
-rw-r--r--spec/ruby/core/enumerable/slice_when_spec.rb8
-rw-r--r--spec/ruby/core/enumerable/sort_by_spec.rb15
-rw-r--r--spec/ruby/core/enumerable/sort_spec.rb16
-rw-r--r--spec/ruby/core/enumerable/sum_spec.rb60
-rw-r--r--spec/ruby/core/enumerable/take_spec.rb16
-rw-r--r--spec/ruby/core/enumerable/take_while_spec.rb10
-rw-r--r--spec/ruby/core/enumerable/tally_spec.rb91
-rw-r--r--spec/ruby/core/enumerable/to_a_spec.rb20
-rw-r--r--spec/ruby/core/enumerable/to_h_spec.rb58
-rw-r--r--spec/ruby/core/enumerable/to_set_spec.rb30
-rw-r--r--spec/ruby/core/enumerable/uniq_spec.rb124
-rw-r--r--spec/ruby/core/enumerable/zip_spec.rb24
-rw-r--r--spec/ruby/core/enumerator/arithmetic_sequence/begin_spec.rb16
-rw-r--r--spec/ruby/core/enumerator/arithmetic_sequence/each_spec.rb17
-rw-r--r--spec/ruby/core/enumerator/arithmetic_sequence/end_spec.rb16
-rw-r--r--spec/ruby/core/enumerator/arithmetic_sequence/eq_spec.rb18
-rw-r--r--spec/ruby/core/enumerator/arithmetic_sequence/exclude_end_spec.rb17
-rw-r--r--spec/ruby/core/enumerator/arithmetic_sequence/first_spec.rb9
-rw-r--r--spec/ruby/core/enumerator/arithmetic_sequence/hash_spec.rb20
-rw-r--r--spec/ruby/core/enumerator/arithmetic_sequence/inspect_spec.rb20
-rw-r--r--spec/ruby/core/enumerator/arithmetic_sequence/last_spec.rb9
-rw-r--r--spec/ruby/core/enumerator/arithmetic_sequence/new_spec.rb17
-rw-r--r--spec/ruby/core/enumerator/arithmetic_sequence/size_spec.rb17
-rw-r--r--spec/ruby/core/enumerator/arithmetic_sequence/step_spec.rb11
-rw-r--r--spec/ruby/core/enumerator/chain/each_spec.rb15
-rw-r--r--spec/ruby/core/enumerator/chain/initialize_spec.rb31
-rw-r--r--spec/ruby/core/enumerator/chain/inspect_spec.rb18
-rw-r--r--spec/ruby/core/enumerator/chain/rewind_spec.rb51
-rw-r--r--spec/ruby/core/enumerator/chain/size_spec.rb22
-rw-r--r--spec/ruby/core/enumerator/each_spec.rb118
-rw-r--r--spec/ruby/core/enumerator/each_with_index_spec.rb26
-rw-r--r--spec/ruby/core/enumerator/each_with_object_spec.rb42
-rw-r--r--spec/ruby/core/enumerator/enum_for_spec.rb6
-rw-r--r--spec/ruby/core/enumerator/enumerator_spec.rb2
-rw-r--r--spec/ruby/core/enumerator/feed_spec.rb10
-rw-r--r--spec/ruby/core/enumerator/first_spec.rb2
-rw-r--r--spec/ruby/core/enumerator/fixtures/classes.rb (renamed from spec/ruby/fixtures/enumerator/classes.rb)0
-rw-r--r--spec/ruby/core/enumerator/generator/each_spec.rb40
-rw-r--r--spec/ruby/core/enumerator/generator/initialize_spec.rb26
-rw-r--r--spec/ruby/core/enumerator/initialize_spec.rb28
-rw-r--r--spec/ruby/core/enumerator/inject_spec.rb15
-rw-r--r--spec/ruby/core/enumerator/inspect_spec.rb7
-rw-r--r--spec/ruby/core/enumerator/lazy/chunk_spec.rb67
-rw-r--r--spec/ruby/core/enumerator/lazy/chunk_while_spec.rb14
-rw-r--r--spec/ruby/core/enumerator/lazy/collect_concat_spec.rb10
-rw-r--r--spec/ruby/core/enumerator/lazy/collect_spec.rb10
-rw-r--r--spec/ruby/core/enumerator/lazy/compact_spec.rb14
-rw-r--r--spec/ruby/core/enumerator/lazy/drop_spec.rb14
-rw-r--r--spec/ruby/core/enumerator/lazy/drop_while_spec.rb16
-rw-r--r--spec/ruby/core/enumerator/lazy/eager_spec.rb27
-rw-r--r--spec/ruby/core/enumerator/lazy/enum_for_spec.rb10
-rw-r--r--spec/ruby/core/enumerator/lazy/filter_map_spec.rb14
-rw-r--r--spec/ruby/core/enumerator/lazy/filter_spec.rb8
-rw-r--r--spec/ruby/core/enumerator/lazy/find_all_spec.rb10
-rw-r--r--spec/ruby/core/enumerator/lazy/flat_map_spec.rb86
-rw-r--r--spec/ruby/core/enumerator/lazy/force_spec.rb10
-rw-r--r--spec/ruby/core/enumerator/lazy/grep_spec.rb51
-rw-r--r--spec/ruby/core/enumerator/lazy/grep_v_spec.rb161
-rw-r--r--spec/ruby/core/enumerator/lazy/initialize_spec.rb22
-rw-r--r--spec/ruby/core/enumerator/lazy/lazy_spec.rb17
-rw-r--r--spec/ruby/core/enumerator/lazy/map_spec.rb62
-rw-r--r--spec/ruby/core/enumerator/lazy/reject_spec.rb28
-rw-r--r--spec/ruby/core/enumerator/lazy/select_spec.rb105
-rw-r--r--spec/ruby/core/enumerator/lazy/shared/collect.rb56
-rw-r--r--spec/ruby/core/enumerator/lazy/shared/collect_concat.rb72
-rw-r--r--spec/ruby/core/enumerator/lazy/shared/select.rb60
-rw-r--r--spec/ruby/core/enumerator/lazy/shared/to_enum.rb50
-rw-r--r--spec/ruby/core/enumerator/lazy/slice_after_spec.rb14
-rw-r--r--spec/ruby/core/enumerator/lazy/slice_before_spec.rb14
-rw-r--r--spec/ruby/core/enumerator/lazy/slice_when_spec.rb14
-rw-r--r--spec/ruby/core/enumerator/lazy/take_spec.rb16
-rw-r--r--spec/ruby/core/enumerator/lazy/take_while_spec.rb10
-rw-r--r--spec/ruby/core/enumerator/lazy/to_enum_spec.rb56
-rw-r--r--spec/ruby/core/enumerator/lazy/uniq_spec.rb93
-rw-r--r--spec/ruby/core/enumerator/lazy/with_index_spec.rb36
-rw-r--r--spec/ruby/core/enumerator/lazy/zip_spec.rb24
-rw-r--r--spec/ruby/core/enumerator/new_spec.rb115
-rw-r--r--spec/ruby/core/enumerator/next_spec.rb38
-rw-r--r--spec/ruby/core/enumerator/next_values_spec.rb12
-rw-r--r--spec/ruby/core/enumerator/peek_spec.rb4
-rw-r--r--spec/ruby/core/enumerator/peek_values_spec.rb12
-rw-r--r--spec/ruby/core/enumerator/plus_spec.rb33
-rw-r--r--spec/ruby/core/enumerator/produce_spec.rb78
-rw-r--r--spec/ruby/core/enumerator/product/each_spec.rb85
-rw-r--r--spec/ruby/core/enumerator/product/initialize_copy_spec.rb52
-rw-r--r--spec/ruby/core/enumerator/product/initialize_spec.rb31
-rw-r--r--spec/ruby/core/enumerator/product/inspect_spec.rb20
-rw-r--r--spec/ruby/core/enumerator/product/rewind_spec.rb62
-rw-r--r--spec/ruby/core/enumerator/product/size_spec.rb64
-rw-r--r--spec/ruby/core/enumerator/product_spec.rb91
-rw-r--r--spec/ruby/core/enumerator/rewind_spec.rb42
-rw-r--r--spec/ruby/core/enumerator/shared/each.rb46
-rw-r--r--spec/ruby/core/enumerator/shared/with_index.rb33
-rw-r--r--spec/ruby/core/enumerator/size_spec.rb6
-rw-r--r--spec/ruby/core/enumerator/to_enum_spec.rb6
-rw-r--r--spec/ruby/core/enumerator/with_index_spec.rb41
-rw-r--r--spec/ruby/core/enumerator/with_object_spec.rb7
-rw-r--r--spec/ruby/core/enumerator/yielder/append_spec.rb35
-rw-r--r--spec/ruby/core/enumerator/yielder/initialize_spec.rb18
-rw-r--r--spec/ruby/core/enumerator/yielder/yield_spec.rb16
-rw-r--r--spec/ruby/core/env/assoc_spec.rb12
-rw-r--r--spec/ruby/core/env/clear_spec.rb4
-rw-r--r--spec/ruby/core/env/clone_spec.rb21
-rw-r--r--spec/ruby/core/env/delete_if_spec.rb43
-rw-r--r--spec/ruby/core/env/delete_spec.rb35
-rw-r--r--spec/ruby/core/env/dup_spec.rb9
-rw-r--r--spec/ruby/core/env/each_key_spec.rb14
-rw-r--r--spec/ruby/core/env/each_pair_spec.rb63
-rw-r--r--spec/ruby/core/env/each_spec.rb7
-rw-r--r--spec/ruby/core/env/each_value_spec.rb16
-rw-r--r--spec/ruby/core/env/element_reference_spec.rb70
-rw-r--r--spec/ruby/core/env/element_set_spec.rb62
-rw-r--r--spec/ruby/core/env/empty_spec.rb8
-rw-r--r--spec/ruby/core/env/except_spec.rb34
-rw-r--r--spec/ruby/core/env/fetch_spec.rb48
-rw-r--r--spec/ruby/core/env/fetch_values_spec.rb51
-rw-r--r--spec/ruby/core/env/filter_spec.rb13
-rw-r--r--spec/ruby/core/env/fixtures/common.rb9
-rw-r--r--spec/ruby/core/env/has_key_spec.rb7
-rw-r--r--spec/ruby/core/env/has_value_spec.rb7
-rw-r--r--spec/ruby/core/env/include_spec.rb32
-rw-r--r--spec/ruby/core/env/index_spec.rb6
-rw-r--r--spec/ruby/core/env/indexes_spec.rb1
-rw-r--r--spec/ruby/core/env/indices_spec.rb1
-rw-r--r--spec/ruby/core/env/inspect_spec.rb4
-rw-r--r--spec/ruby/core/env/invert_spec.rb2
-rw-r--r--spec/ruby/core/env/keep_if_spec.rb37
-rw-r--r--spec/ruby/core/env/key_spec.rb39
-rw-r--r--spec/ruby/core/env/keys_spec.rb6
-rw-r--r--spec/ruby/core/env/length_spec.rb7
-rw-r--r--spec/ruby/core/env/member_spec.rb7
-rw-r--r--spec/ruby/core/env/merge_spec.rb106
-rw-r--r--spec/ruby/core/env/rassoc_spec.rb23
-rw-r--r--spec/ruby/core/env/rehash_spec.rb8
-rw-r--r--spec/ruby/core/env/reject_spec.rb40
-rw-r--r--spec/ruby/core/env/replace_spec.rb52
-rw-r--r--spec/ruby/core/env/select_spec.rb53
-rw-r--r--spec/ruby/core/env/shared/each.rb65
-rw-r--r--spec/ruby/core/env/shared/include.rb11
-rw-r--r--spec/ruby/core/env/shared/key.rb15
-rw-r--r--spec/ruby/core/env/shared/length.rb13
-rw-r--r--spec/ruby/core/env/shared/store.rb56
-rw-r--r--spec/ruby/core/env/shared/to_hash.rb21
-rw-r--r--spec/ruby/core/env/shared/value.rb11
-rw-r--r--spec/ruby/core/env/shift_spec.rb86
-rw-r--r--spec/ruby/core/env/size_spec.rb15
-rw-r--r--spec/ruby/core/env/slice_spec.rb37
-rw-r--r--spec/ruby/core/env/spec_helper.rb26
-rw-r--r--spec/ruby/core/env/store_spec.rb7
-rw-r--r--spec/ruby/core/env/to_a_spec.rb14
-rw-r--r--spec/ruby/core/env/to_h_spec.rb72
-rw-r--r--spec/ruby/core/env/to_hash_spec.rb6
-rw-r--r--spec/ruby/core/env/to_s_spec.rb2
-rw-r--r--spec/ruby/core/env/update_spec.rb24
-rw-r--r--spec/ruby/core/env/value_spec.rb31
-rw-r--r--spec/ruby/core/env/values_at_spec.rb33
-rw-r--r--spec/ruby/core/env/values_spec.rb13
-rw-r--r--spec/ruby/core/exception/args_spec.rb5
-rw-r--r--spec/ruby/core/exception/arguments_spec.rb11
-rw-r--r--spec/ruby/core/exception/backtrace_locations_spec.rb39
-rw-r--r--spec/ruby/core/exception/backtrace_spec.rb64
-rw-r--r--spec/ruby/core/exception/case_compare_spec.rb36
-rw-r--r--spec/ruby/core/exception/cause_spec.rb37
-rw-r--r--spec/ruby/core/exception/destination_encoding_name_spec.rb9
-rw-r--r--spec/ruby/core/exception/destination_encoding_spec.rb9
-rw-r--r--spec/ruby/core/exception/detailed_message_spec.rb50
-rw-r--r--spec/ruby/core/exception/dup_spec.rb74
-rw-r--r--spec/ruby/core/exception/equal_value_spec.rb22
-rw-r--r--spec/ruby/core/exception/errno_spec.rb41
-rw-r--r--spec/ruby/core/exception/error_bytes_spec.rb5
-rw-r--r--spec/ruby/core/exception/error_char_spec.rb5
-rw-r--r--spec/ruby/core/exception/exception_spec.rb82
-rw-r--r--spec/ruby/core/exception/exit_value_spec.rb12
-rw-r--r--spec/ruby/core/exception/fixtures/common.rb40
-rw-r--r--spec/ruby/core/exception/fixtures/syntax_error.rb3
-rw-r--r--spec/ruby/core/exception/fixtures/thread_fiber_ensure.rb22
-rw-r--r--spec/ruby/core/exception/fixtures/thread_fiber_ensure_non_root_fiber.rb25
-rw-r--r--spec/ruby/core/exception/frozen_error_spec.rb54
-rw-r--r--spec/ruby/core/exception/full_message_spec.rb226
-rw-r--r--spec/ruby/core/exception/hierarchy_spec.rb62
-rw-r--r--spec/ruby/core/exception/incomplete_input_spec.rb5
-rw-r--r--spec/ruby/core/exception/initialize_spec.rb1
-rw-r--r--spec/ruby/core/exception/inspect_spec.rb8
-rw-r--r--spec/ruby/core/exception/interrupt_spec.rb37
-rw-r--r--spec/ruby/core/exception/io_error_spec.rb24
-rw-r--r--spec/ruby/core/exception/key_error_spec.rb19
-rw-r--r--spec/ruby/core/exception/load_error_spec.rb2
-rw-r--r--spec/ruby/core/exception/message_spec.rb4
-rw-r--r--spec/ruby/core/exception/name_error_spec.rb29
-rw-r--r--spec/ruby/core/exception/name_spec.rb52
-rw-r--r--spec/ruby/core/exception/new_spec.rb8
-rw-r--r--spec/ruby/core/exception/no_method_error_spec.rb181
-rw-r--r--spec/ruby/core/exception/range_error_spec.rb7
-rw-r--r--spec/ruby/core/exception/readagain_bytes_spec.rb5
-rw-r--r--spec/ruby/core/exception/reason_spec.rb12
-rw-r--r--spec/ruby/core/exception/receiver_spec.rb116
-rw-r--r--spec/ruby/core/exception/result_spec.rb16
-rw-r--r--spec/ruby/core/exception/script_error_spec.rb15
-rw-r--r--spec/ruby/core/exception/set_backtrace_spec.rb55
-rw-r--r--spec/ruby/core/exception/shared/new.rb4
-rw-r--r--spec/ruby/core/exception/shared/set_backtrace.rb64
-rw-r--r--spec/ruby/core/exception/signal_exception_spec.rb61
-rw-r--r--spec/ruby/core/exception/signm_spec.rb8
-rw-r--r--spec/ruby/core/exception/signo_spec.rb8
-rw-r--r--spec/ruby/core/exception/source_encoding_name_spec.rb9
-rw-r--r--spec/ruby/core/exception/source_encoding_spec.rb9
-rw-r--r--spec/ruby/core/exception/standard_error_spec.rb57
-rw-r--r--spec/ruby/core/exception/status_spec.rb8
-rw-r--r--spec/ruby/core/exception/success_spec.rb14
-rw-r--r--spec/ruby/core/exception/syntax_error_spec.rb25
-rw-r--r--spec/ruby/core/exception/system_call_error_spec.rb126
-rw-r--r--spec/ruby/core/exception/system_exit_spec.rb59
-rw-r--r--spec/ruby/core/exception/system_stack_error_spec.rb7
-rw-r--r--spec/ruby/core/exception/to_s_spec.rb20
-rw-r--r--spec/ruby/core/exception/top_level_spec.rb65
-rw-r--r--spec/ruby/core/exception/uncaught_throw_error_spec.rb9
-rw-r--r--spec/ruby/core/false/and_spec.rb2
-rw-r--r--spec/ruby/core/false/case_compare_spec.rb14
-rw-r--r--spec/ruby/core/false/dup_spec.rb10
-rw-r--r--spec/ruby/core/false/falseclass_spec.rb10
-rw-r--r--spec/ruby/core/false/inspect_spec.rb6
-rw-r--r--spec/ruby/core/false/or_spec.rb2
-rw-r--r--spec/ruby/core/false/singleton_method_spec.rb13
-rw-r--r--spec/ruby/core/false/to_s_spec.rb10
-rw-r--r--spec/ruby/core/false/xor_spec.rb10
-rw-r--r--spec/ruby/core/fiber/alive_spec.rb44
-rw-r--r--spec/ruby/core/fiber/blocking_spec.rb73
-rw-r--r--spec/ruby/core/fiber/current_spec.rb50
-rw-r--r--spec/ruby/core/fiber/fixtures/classes.rb22
-rw-r--r--spec/ruby/core/fiber/fixtures/scheduler.rb35
-rw-r--r--spec/ruby/core/fiber/inspect_spec.rb35
-rw-r--r--spec/ruby/core/fiber/kill_spec.rb88
-rw-r--r--spec/ruby/core/fiber/new_spec.rb62
-rw-r--r--spec/ruby/core/fiber/raise_spec.rb141
-rw-r--r--spec/ruby/core/fiber/resume_spec.rb127
-rw-r--r--spec/ruby/core/fiber/scheduler_spec.rb5
-rw-r--r--spec/ruby/core/fiber/set_scheduler_spec.rb55
-rw-r--r--spec/ruby/core/fiber/shared/blocking.rb41
-rw-r--r--spec/ruby/core/fiber/shared/resume.rb58
-rw-r--r--spec/ruby/core/fiber/storage_spec.rb177
-rw-r--r--spec/ruby/core/fiber/transfer_spec.rb84
-rw-r--r--spec/ruby/core/fiber/yield_spec.rb80
-rw-r--r--spec/ruby/core/file/absolute_path_spec.rb61
-rw-r--r--spec/ruby/core/file/atime_spec.rb37
-rw-r--r--spec/ruby/core/file/basename_spec.rb63
-rw-r--r--spec/ruby/core/file/birthtime_spec.rb66
-rw-r--r--spec/ruby/core/file/blockdev_spec.rb4
-rw-r--r--spec/ruby/core/file/chardev_spec.rb4
-rw-r--r--spec/ruby/core/file/chmod_spec.rb184
-rw-r--r--spec/ruby/core/file/chown_spec.rb46
-rw-r--r--spec/ruby/core/file/constants/constants_spec.rb10
-rw-r--r--spec/ruby/core/file/constants_spec.rb2
-rw-r--r--spec/ruby/core/file/ctime_spec.rb15
-rw-r--r--spec/ruby/core/file/delete_spec.rb63
-rw-r--r--spec/ruby/core/file/directory_spec.rb4
-rw-r--r--spec/ruby/core/file/dirname_spec.rb100
-rw-r--r--spec/ruby/core/file/empty_spec.rb16
-rw-r--r--spec/ruby/core/file/executable_real_spec.rb4
-rw-r--r--spec/ruby/core/file/executable_spec.rb4
-rw-r--r--spec/ruby/core/file/exist_spec.rb12
-rw-r--r--spec/ruby/core/file/exists_spec.rb6
-rw-r--r--spec/ruby/core/file/expand_path_spec.rb185
-rw-r--r--spec/ruby/core/file/extname_spec.rb54
-rw-r--r--spec/ruby/core/file/file_spec.rb4
-rw-r--r--spec/ruby/core/file/fixtures/file_types.rb36
-rw-r--r--spec/ruby/core/file/flock_spec.rb38
-rw-r--r--spec/ruby/core/file/fnmatch_spec.rb300
-rw-r--r--spec/ruby/core/file/ftype_spec.rb23
-rw-r--r--spec/ruby/core/file/grpowned_spec.rb4
-rw-r--r--spec/ruby/core/file/identical_spec.rb4
-rw-r--r--spec/ruby/core/file/initialize_spec.rb6
-rw-r--r--spec/ruby/core/file/inspect_spec.rb4
-rw-r--r--spec/ruby/core/file/join_spec.rb21
-rw-r--r--spec/ruby/core/file/lchmod_spec.rb26
-rw-r--r--spec/ruby/core/file/lchown_spec.rb6
-rw-r--r--spec/ruby/core/file/link_spec.rb18
-rw-r--r--spec/ruby/core/file/lstat_spec.rb8
-rw-r--r--spec/ruby/core/file/lutime_spec.rb43
-rw-r--r--spec/ruby/core/file/mkfifo_spec.rb74
-rw-r--r--spec/ruby/core/file/mtime_spec.rb37
-rw-r--r--spec/ruby/core/file/new_spec.rb133
-rw-r--r--spec/ruby/core/file/null_spec.rb2
-rw-r--r--spec/ruby/core/file/open_spec.rb359
-rw-r--r--spec/ruby/core/file/owned_spec.rb12
-rw-r--r--spec/ruby/core/file/path_spec.rb75
-rw-r--r--spec/ruby/core/file/pipe_spec.rb6
-rw-r--r--spec/ruby/core/file/printf_spec.rb18
-rw-r--r--spec/ruby/core/file/read_spec.rb4
-rw-r--r--spec/ruby/core/file/readable_real_spec.rb4
-rw-r--r--spec/ruby/core/file/readable_spec.rb4
-rw-r--r--spec/ruby/core/file/readlink_spec.rb8
-rw-r--r--spec/ruby/core/file/realdirpath_spec.rb8
-rw-r--r--spec/ruby/core/file/realpath_spec.rb18
-rw-r--r--spec/ruby/core/file/rename_spec.rb18
-rw-r--r--spec/ruby/core/file/reopen_spec.rb4
-rw-r--r--spec/ruby/core/file/setgid_spec.rb4
-rw-r--r--spec/ruby/core/file/setuid_spec.rb8
-rw-r--r--spec/ruby/core/file/shared/fnmatch.rb241
-rw-r--r--spec/ruby/core/file/shared/open.rb4
-rw-r--r--spec/ruby/core/file/shared/read.rb10
-rw-r--r--spec/ruby/core/file/shared/stat.rb8
-rw-r--r--spec/ruby/core/file/shared/unlink.rb63
-rw-r--r--spec/ruby/core/file/shared/update_time.rb105
-rw-r--r--spec/ruby/core/file/size_spec.rb12
-rw-r--r--spec/ruby/core/file/socket_spec.rb36
-rw-r--r--spec/ruby/core/file/split_spec.rb13
-rw-r--r--spec/ruby/core/file/stat/atime_spec.rb4
-rw-r--r--spec/ruby/core/file/stat/birthtime_spec.rb38
-rw-r--r--spec/ruby/core/file/stat/blksize_spec.rb2
-rw-r--r--spec/ruby/core/file/stat/blockdev_spec.rb6
-rw-r--r--spec/ruby/core/file/stat/blocks_spec.rb8
-rw-r--r--spec/ruby/core/file/stat/chardev_spec.rb6
-rw-r--r--spec/ruby/core/file/stat/comparison_spec.rb2
-rw-r--r--spec/ruby/core/file/stat/ctime_spec.rb4
-rw-r--r--spec/ruby/core/file/stat/dev_major_spec.rb6
-rw-r--r--spec/ruby/core/file/stat/dev_minor_spec.rb6
-rw-r--r--spec/ruby/core/file/stat/dev_spec.rb4
-rw-r--r--spec/ruby/core/file/stat/directory_spec.rb6
-rw-r--r--spec/ruby/core/file/stat/executable_real_spec.rb6
-rw-r--r--spec/ruby/core/file/stat/executable_spec.rb6
-rw-r--r--spec/ruby/core/file/stat/file_spec.rb6
-rw-r--r--spec/ruby/core/file/stat/ftype_spec.rb10
-rw-r--r--spec/ruby/core/file/stat/gid_spec.rb2
-rw-r--r--spec/ruby/core/file/stat/grpowned_spec.rb6
-rw-r--r--spec/ruby/core/file/stat/ino_spec.rb22
-rw-r--r--spec/ruby/core/file/stat/inspect_spec.rb8
-rw-r--r--spec/ruby/core/file/stat/mode_spec.rb2
-rw-r--r--spec/ruby/core/file/stat/mtime_spec.rb4
-rw-r--r--spec/ruby/core/file/stat/new_spec.rb8
-rw-r--r--spec/ruby/core/file/stat/nlink_spec.rb4
-rw-r--r--spec/ruby/core/file/stat/owned_spec.rb20
-rw-r--r--spec/ruby/core/file/stat/pipe_spec.rb12
-rw-r--r--spec/ruby/core/file/stat/rdev_major_spec.rb19
-rw-r--r--spec/ruby/core/file/stat/rdev_minor_spec.rb19
-rw-r--r--spec/ruby/core/file/stat/rdev_spec.rb4
-rw-r--r--spec/ruby/core/file/stat/readable_real_spec.rb6
-rw-r--r--spec/ruby/core/file/stat/readable_spec.rb6
-rw-r--r--spec/ruby/core/file/stat/setgid_spec.rb10
-rw-r--r--spec/ruby/core/file/stat/setuid_spec.rb10
-rw-r--r--spec/ruby/core/file/stat/size_spec.rb6
-rw-r--r--spec/ruby/core/file/stat/socket_spec.rb10
-rw-r--r--spec/ruby/core/file/stat/sticky_spec.rb10
-rw-r--r--spec/ruby/core/file/stat/symlink_spec.rb6
-rw-r--r--spec/ruby/core/file/stat/uid_spec.rb2
-rw-r--r--spec/ruby/core/file/stat/world_readable_spec.rb8
-rw-r--r--spec/ruby/core/file/stat/world_writable_spec.rb8
-rw-r--r--spec/ruby/core/file/stat/writable_real_spec.rb6
-rw-r--r--spec/ruby/core/file/stat/writable_spec.rb6
-rw-r--r--spec/ruby/core/file/stat/zero_spec.rb6
-rw-r--r--spec/ruby/core/file/stat_spec.rb28
-rw-r--r--spec/ruby/core/file/sticky_spec.rb8
-rw-r--r--spec/ruby/core/file/symlink_spec.rb16
-rw-r--r--spec/ruby/core/file/to_path_spec.rb53
-rw-r--r--spec/ruby/core/file/truncate_spec.rb32
-rw-r--r--spec/ruby/core/file/umask_spec.rb27
-rw-r--r--spec/ruby/core/file/unlink_spec.rb7
-rw-r--r--spec/ruby/core/file/utime_spec.rb36
-rw-r--r--spec/ruby/core/file/world_readable_spec.rb10
-rw-r--r--spec/ruby/core/file/world_writable_spec.rb10
-rw-r--r--spec/ruby/core/file/writable_real_spec.rb4
-rw-r--r--spec/ruby/core/file/writable_spec.rb4
-rw-r--r--spec/ruby/core/file/zero_spec.rb12
-rw-r--r--spec/ruby/core/filetest/blockdev_spec.rb4
-rw-r--r--spec/ruby/core/filetest/chardev_spec.rb4
-rw-r--r--spec/ruby/core/filetest/directory_spec.rb4
-rw-r--r--spec/ruby/core/filetest/empty_spec.rb7
-rw-r--r--spec/ruby/core/filetest/executable_real_spec.rb4
-rw-r--r--spec/ruby/core/filetest/executable_spec.rb4
-rw-r--r--spec/ruby/core/filetest/exist_spec.rb10
-rw-r--r--spec/ruby/core/filetest/exists_spec.rb6
-rw-r--r--spec/ruby/core/filetest/file_spec.rb4
-rw-r--r--spec/ruby/core/filetest/grpowned_spec.rb6
-rw-r--r--spec/ruby/core/filetest/identical_spec.rb4
-rw-r--r--spec/ruby/core/filetest/owned_spec.rb8
-rw-r--r--spec/ruby/core/filetest/pipe_spec.rb8
-rw-r--r--spec/ruby/core/filetest/readable_real_spec.rb4
-rw-r--r--spec/ruby/core/filetest/readable_spec.rb4
-rw-r--r--spec/ruby/core/filetest/setgid_spec.rb8
-rw-r--r--spec/ruby/core/filetest/setuid_spec.rb8
-rw-r--r--spec/ruby/core/filetest/size_spec.rb4
-rw-r--r--spec/ruby/core/filetest/socket_spec.rb10
-rw-r--r--spec/ruby/core/filetest/sticky_spec.rb4
-rw-r--r--spec/ruby/core/filetest/symlink_spec.rb4
-rw-r--r--spec/ruby/core/filetest/world_readable_spec.rb2
-rw-r--r--spec/ruby/core/filetest/world_writable_spec.rb2
-rw-r--r--spec/ruby/core/filetest/writable_real_spec.rb4
-rw-r--r--spec/ruby/core/filetest/writable_spec.rb4
-rw-r--r--spec/ruby/core/filetest/zero_spec.rb12
-rw-r--r--spec/ruby/core/fixnum/abs_spec.rb7
-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/case_compare_spec.rb6
-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/equal_value_spec.rb6
-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/fdiv_spec.rb49
-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.rb5
-rw-r--r--spec/ruby/core/float/angle_spec.rb6
-rw-r--r--spec/ruby/core/float/arg_spec.rb37
-rw-r--r--spec/ruby/core/float/case_compare_spec.rb7
-rw-r--r--spec/ruby/core/float/ceil_spec.rb37
-rw-r--r--spec/ruby/core/float/coerce_spec.rb6
-rw-r--r--spec/ruby/core/float/comparison_spec.rb105
-rw-r--r--spec/ruby/core/float/constants_spec.rb4
-rw-r--r--spec/ruby/core/float/denominator_spec.rb4
-rw-r--r--spec/ruby/core/float/divide_spec.rb31
-rw-r--r--spec/ruby/core/float/divmod_spec.rb26
-rw-r--r--spec/ruby/core/float/dup_spec.rb12
-rw-r--r--spec/ruby/core/float/eql_spec.rb10
-rw-r--r--spec/ruby/core/float/equal_value_spec.rb40
-rw-r--r--spec/ruby/core/float/exponent_spec.rb2
-rw-r--r--spec/ruby/core/float/fdiv_spec.rb61
-rw-r--r--spec/ruby/core/float/finite_spec.rb10
-rw-r--r--spec/ruby/core/float/fixtures/classes.rb4
-rw-r--r--spec/ruby/core/float/float_spec.rb10
-rw-r--r--spec/ruby/core/float/floor_spec.rb37
-rw-r--r--spec/ruby/core/float/gt_spec.rb30
-rw-r--r--spec/ruby/core/float/gte_spec.rb30
-rw-r--r--spec/ruby/core/float/hash_spec.rb2
-rw-r--r--spec/ruby/core/float/infinite_spec.rb2
-rw-r--r--spec/ruby/core/float/inspect_spec.rb7
-rw-r--r--spec/ruby/core/float/lt_spec.rb30
-rw-r--r--spec/ruby/core/float/lte_spec.rb30
-rw-r--r--spec/ruby/core/float/magnitude_spec.rb13
-rw-r--r--spec/ruby/core/float/minus_spec.rb7
-rw-r--r--spec/ruby/core/float/modulo_spec.rb54
-rw-r--r--spec/ruby/core/float/multiply_spec.rb11
-rw-r--r--spec/ruby/core/float/nan_spec.rb8
-rw-r--r--spec/ruby/core/float/negative_spec.rb33
-rw-r--r--spec/ruby/core/float/next_float_spec.rb6
-rw-r--r--spec/ruby/core/float/numerator_spec.rb6
-rw-r--r--spec/ruby/core/float/phase_spec.rb6
-rw-r--r--spec/ruby/core/float/plus_spec.rb7
-rw-r--r--spec/ruby/core/float/positive_spec.rb33
-rw-r--r--spec/ruby/core/float/prev_float_spec.rb6
-rw-r--r--spec/ruby/core/float/quo_spec.rb7
-rw-r--r--spec/ruby/core/float/rationalize_spec.rb10
-rw-r--r--spec/ruby/core/float/round_spec.rb201
-rw-r--r--spec/ruby/core/float/shared/abs.rb4
-rw-r--r--spec/ruby/core/float/shared/arithmetic_exception_in_coerce.rb11
-rw-r--r--spec/ruby/core/float/shared/comparison_exception_in_coerce.rb11
-rw-r--r--spec/ruby/core/float/shared/equal.rb17
-rw-r--r--spec/ruby/core/float/shared/modulo.rb48
-rw-r--r--spec/ruby/core/float/shared/quo.rb59
-rw-r--r--spec/ruby/core/float/shared/to_i.rb16
-rw-r--r--spec/ruby/core/float/to_f_spec.rb2
-rw-r--r--spec/ruby/core/float/to_i_spec.rb6
-rw-r--r--spec/ruby/core/float/to_int_spec.rb7
-rw-r--r--spec/ruby/core/float/to_r_spec.rb2
-rw-r--r--spec/ruby/core/float/to_s_spec.rb206
-rw-r--r--spec/ruby/core/float/truncate_spec.rb20
-rw-r--r--spec/ruby/core/float/uminus_spec.rb4
-rw-r--r--spec/ruby/core/float/uplus_spec.rb4
-rw-r--r--spec/ruby/core/float/zero_spec.rb8
-rw-r--r--spec/ruby/core/gc/auto_compact_spec.rb24
-rw-r--r--spec/ruby/core/gc/config_spec.rb97
-rw-r--r--spec/ruby/core/gc/count_spec.rb14
-rw-r--r--spec/ruby/core/gc/disable_spec.rb4
-rw-r--r--spec/ruby/core/gc/enable_spec.rb4
-rw-r--r--spec/ruby/core/gc/garbage_collect_spec.rb2
-rw-r--r--spec/ruby/core/gc/measure_total_time_spec.rb17
-rw-r--r--spec/ruby/core/gc/profiler/clear_spec.rb2
-rw-r--r--spec/ruby/core/gc/profiler/disable_spec.rb4
-rw-r--r--spec/ruby/core/gc/profiler/enable_spec.rb4
-rw-r--r--spec/ruby/core/gc/profiler/enabled_spec.rb6
-rw-r--r--spec/ruby/core/gc/profiler/report_spec.rb2
-rw-r--r--spec/ruby/core/gc/profiler/result_spec.rb4
-rw-r--r--spec/ruby/core/gc/profiler/total_time_spec.rb4
-rw-r--r--spec/ruby/core/gc/start_spec.rb6
-rw-r--r--spec/ruby/core/gc/stat_spec.rb62
-rw-r--r--spec/ruby/core/gc/stress_spec.rb10
-rw-r--r--spec/ruby/core/gc/total_time_spec.rb13
-rw-r--r--spec/ruby/core/hash/allocate_spec.rb4
-rw-r--r--spec/ruby/core/hash/any_spec.rb6
-rw-r--r--spec/ruby/core/hash/assoc_spec.rb16
-rw-r--r--spec/ruby/core/hash/clear_spec.rb12
-rw-r--r--spec/ruby/core/hash/clone_spec.rb5
-rw-r--r--spec/ruby/core/hash/compact_spec.rb110
-rw-r--r--spec/ruby/core/hash/compare_by_identity_spec.rb71
-rw-r--r--spec/ruby/core/hash/constructor_spec.rb59
-rw-r--r--spec/ruby/core/hash/deconstruct_keys_spec.rb23
-rw-r--r--spec/ruby/core/hash/default_proc_spec.rb38
-rw-r--r--spec/ruby/core/hash/default_spec.rb12
-rw-r--r--spec/ruby/core/hash/delete_if_spec.rb22
-rw-r--r--spec/ruby/core/hash/delete_spec.rb26
-rw-r--r--spec/ruby/core/hash/dig_spec.rb108
-rw-r--r--spec/ruby/core/hash/each_key_spec.rb14
-rw-r--r--spec/ruby/core/hash/each_pair_spec.rb116
-rw-r--r--spec/ruby/core/hash/each_spec.rb12
-rw-r--r--spec/ruby/core/hash/each_value_spec.rb14
-rw-r--r--spec/ruby/core/hash/element_reference_spec.rb24
-rw-r--r--spec/ruby/core/hash/element_set_spec.rb122
-rw-r--r--spec/ruby/core/hash/empty_spec.rb14
-rw-r--r--spec/ruby/core/hash/eql_spec.rb6
-rw-r--r--spec/ruby/core/hash/equal_value_spec.rb8
-rw-r--r--spec/ruby/core/hash/except_spec.rb42
-rw-r--r--spec/ruby/core/hash/fetch_spec.rb30
-rw-r--r--spec/ruby/core/hash/fetch_values_spec.rb48
-rw-r--r--spec/ruby/core/hash/filter_spec.rb13
-rw-r--r--spec/ruby/core/hash/fixtures/classes.rb7
-rw-r--r--spec/ruby/core/hash/fixtures/name.rb30
-rw-r--r--spec/ruby/core/hash/flatten_spec.rb8
-rw-r--r--spec/ruby/core/hash/gt_spec.rb66
-rw-r--r--spec/ruby/core/hash/gte_spec.rb66
-rw-r--r--spec/ruby/core/hash/has_key_spec.rb9
-rw-r--r--spec/ruby/core/hash/has_value_spec.rb9
-rw-r--r--spec/ruby/core/hash/hash_spec.rb17
-rw-r--r--spec/ruby/core/hash/include_spec.rb41
-rw-r--r--spec/ruby/core/hash/index_spec.rb7
-rw-r--r--spec/ruby/core/hash/initialize_spec.rb49
-rw-r--r--spec/ruby/core/hash/inspect_spec.rb124
-rw-r--r--spec/ruby/core/hash/invert_spec.rb25
-rw-r--r--spec/ruby/core/hash/keep_if_spec.rb24
-rw-r--r--spec/ruby/core/hash/key_spec.rb32
-rw-r--r--spec/ruby/core/hash/keys_spec.rb8
-rw-r--r--spec/ruby/core/hash/length_spec.rb8
-rw-r--r--spec/ruby/core/hash/lt_spec.rb66
-rw-r--r--spec/ruby/core/hash/lte_spec.rb66
-rw-r--r--spec/ruby/core/hash/member_spec.rb8
-rw-r--r--spec/ruby/core/hash/merge_spec.rb143
-rw-r--r--spec/ruby/core/hash/new_spec.rb44
-rw-r--r--spec/ruby/core/hash/rassoc_spec.rb12
-rw-r--r--spec/ruby/core/hash/rehash_spec.rb98
-rw-r--r--spec/ruby/core/hash/reject_spec.rb56
-rw-r--r--spec/ruby/core/hash/replace_spec.rb80
-rw-r--r--spec/ruby/core/hash/ruby2_keywords_hash_spec.rb81
-rw-r--r--spec/ruby/core/hash/select_spec.rb65
-rw-r--r--spec/ruby/core/hash/shared/comparison.rb10
-rw-r--r--spec/ruby/core/hash/shared/each.rb68
-rw-r--r--spec/ruby/core/hash/shared/eql.rb102
-rw-r--r--spec/ruby/core/hash/shared/equal.rb90
-rw-r--r--spec/ruby/core/hash/shared/greater_than.rb6
-rw-r--r--spec/ruby/core/hash/shared/index.rb27
-rw-r--r--spec/ruby/core/hash/shared/iteration.rb6
-rw-r--r--spec/ruby/core/hash/shared/key.rb38
-rw-r--r--spec/ruby/core/hash/shared/length.rb12
-rw-r--r--spec/ruby/core/hash/shared/less_than.rb6
-rw-r--r--spec/ruby/core/hash/shared/replace.rb51
-rw-r--r--spec/ruby/core/hash/shared/store.rb98
-rw-r--r--spec/ruby/core/hash/shared/to_s.rb109
-rw-r--r--spec/ruby/core/hash/shared/update.rb59
-rw-r--r--spec/ruby/core/hash/shared/value.rb14
-rw-r--r--spec/ruby/core/hash/shared/values_at.rb9
-rw-r--r--spec/ruby/core/hash/shift_spec.rb40
-rw-r--r--spec/ruby/core/hash/size_spec.rb15
-rw-r--r--spec/ruby/core/hash/slice_spec.rb74
-rw-r--r--spec/ruby/core/hash/sort_spec.rb4
-rw-r--r--spec/ruby/core/hash/store_spec.rb8
-rw-r--r--spec/ruby/core/hash/to_a_spec.rb16
-rw-r--r--spec/ruby/core/hash/to_h_spec.rb84
-rw-r--r--spec/ruby/core/hash/to_hash_spec.rb8
-rw-r--r--spec/ruby/core/hash/to_proc_spec.rb124
-rw-r--r--spec/ruby/core/hash/to_s_spec.rb8
-rw-r--r--spec/ruby/core/hash/transform_keys_spec.rb150
-rw-r--r--spec/ruby/core/hash/transform_values_spec.rb166
-rw-r--r--spec/ruby/core/hash/try_convert_spec.rb20
-rw-r--r--spec/ruby/core/hash/update_spec.rb8
-rw-r--r--spec/ruby/core/hash/value_spec.rb18
-rw-r--r--spec/ruby/core/hash/values_at_spec.rb12
-rw-r--r--spec/ruby/core/hash/values_spec.rb6
-rw-r--r--spec/ruby/core/integer/abs_spec.rb20
-rw-r--r--spec/ruby/core/integer/allbits_spec.rb37
-rw-r--r--spec/ruby/core/integer/anybits_spec.rb36
-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.rb89
-rw-r--r--spec/ruby/core/integer/bit_xor_spec.rb93
-rw-r--r--spec/ruby/core/integer/case_compare_spec.rb7
-rw-r--r--spec/ruby/core/integer/ceil_spec.rb24
-rw-r--r--spec/ruby/core/integer/ceildiv_spec.rb20
-rw-r--r--spec/ruby/core/integer/chr_spec.rb112
-rw-r--r--spec/ruby/core/integer/coerce_spec.rb91
-rw-r--r--spec/ruby/core/integer/comparison_spec.rb185
-rw-r--r--spec/ruby/core/integer/complement_spec.rb20
-rw-r--r--spec/ruby/core/integer/constants_spec.rb13
-rw-r--r--spec/ruby/core/integer/denominator_spec.rb2
-rw-r--r--spec/ruby/core/integer/digits_spec.rb71
-rw-r--r--spec/ruby/core/integer/div_spec.rb154
-rw-r--r--spec/ruby/core/integer/divide_spec.rb126
-rw-r--r--spec/ruby/core/integer/divmod_spec.rb117
-rw-r--r--spec/ruby/core/integer/downto_spec.rb12
-rw-r--r--spec/ruby/core/integer/dup_spec.rb17
-rw-r--r--spec/ruby/core/integer/element_reference_spec.rb188
-rw-r--r--spec/ruby/core/integer/eql_spec.rb25
-rw-r--r--spec/ruby/core/integer/equal_value_spec.rb65
-rw-r--r--spec/ruby/core/integer/even_spec.rb44
-rw-r--r--spec/ruby/core/integer/exponent_spec.rb7
-rw-r--r--spec/ruby/core/integer/fdiv_spec.rb100
-rw-r--r--spec/ruby/core/integer/fixtures/classes.rb14
-rw-r--r--spec/ruby/core/integer/floor_spec.rb24
-rw-r--r--spec/ruby/core/integer/gcd_spec.rb29
-rw-r--r--spec/ruby/core/integer/gcdlcm_spec.rb18
-rw-r--r--spec/ruby/core/integer/gt_spec.rb48
-rw-r--r--spec/ruby/core/integer/gte_spec.rb48
-rw-r--r--spec/ruby/core/integer/inspect_spec.rb7
-rw-r--r--spec/ruby/core/integer/integer_spec.rb16
-rw-r--r--spec/ruby/core/integer/lcm_spec.rb18
-rw-r--r--spec/ruby/core/integer/left_shift_spec.rb211
-rw-r--r--spec/ruby/core/integer/lt_spec.rb50
-rw-r--r--spec/ruby/core/integer/lte_spec.rb58
-rw-r--r--spec/ruby/core/integer/magnitude_spec.rb7
-rw-r--r--spec/ruby/core/integer/minus_spec.rb60
-rw-r--r--spec/ruby/core/integer/modulo_spec.rb122
-rw-r--r--spec/ruby/core/integer/multiply_spec.rb45
-rw-r--r--spec/ruby/core/integer/next_spec.rb7
-rw-r--r--spec/ruby/core/integer/nobits_spec.rb36
-rw-r--r--spec/ruby/core/integer/numerator_spec.rb2
-rw-r--r--spec/ruby/core/integer/odd_spec.rb42
-rw-r--r--spec/ruby/core/integer/ord_spec.rb18
-rw-r--r--spec/ruby/core/integer/plus_spec.rb75
-rw-r--r--spec/ruby/core/integer/pow_spec.rb51
-rw-r--r--spec/ruby/core/integer/pred_spec.rb12
-rw-r--r--spec/ruby/core/integer/rationalize_spec.rb8
-rw-r--r--spec/ruby/core/integer/remainder_spec.rb51
-rw-r--r--spec/ruby/core/integer/right_shift_spec.rb233
-rw-r--r--spec/ruby/core/integer/round_spec.rb94
-rw-r--r--spec/ruby/core/integer/shared/arithmetic_coerce.rb11
-rw-r--r--spec/ruby/core/integer/shared/comparison_coerce.rb11
-rw-r--r--spec/ruby/core/integer/shared/exponent.rb162
-rw-r--r--spec/ruby/core/integer/shared/integer_ceil_precision.rb54
-rw-r--r--spec/ruby/core/integer/shared/integer_floor_precision.rb42
-rw-r--r--spec/ruby/core/integer/shared/integer_rounding.rb26
-rw-r--r--spec/ruby/core/integer/shared/next.rb25
-rw-r--r--spec/ruby/core/integer/shared/to_i.rb8
-rw-r--r--spec/ruby/core/integer/size_spec.rb34
-rw-r--r--spec/ruby/core/integer/sqrt_spec.rb48
-rw-r--r--spec/ruby/core/integer/succ_spec.rb27
-rw-r--r--spec/ruby/core/integer/times_spec.rb2
-rw-r--r--spec/ruby/core/integer/to_f_spec.rb23
-rw-r--r--spec/ruby/core/integer/to_i_spec.rb6
-rw-r--r--spec/ruby/core/integer/to_int_spec.rb6
-rw-r--r--spec/ruby/core/integer/to_r_spec.rb10
-rw-r--r--spec/ruby/core/integer/to_s_spec.rb95
-rw-r--r--spec/ruby/core/integer/truncate_spec.rb28
-rw-r--r--spec/ruby/core/integer/try_convert_spec.rb48
-rw-r--r--spec/ruby/core/integer/uminus_spec.rb30
-rw-r--r--spec/ruby/core/integer/upto_spec.rb12
-rw-r--r--spec/ruby/core/integer/zero_spec.rb13
-rw-r--r--spec/ruby/core/io/advise_spec.rb57
-rw-r--r--spec/ruby/core/io/autoclose_spec.rb77
-rw-r--r--spec/ruby/core/io/binmode_spec.rb16
-rw-r--r--spec/ruby/core/io/binread_spec.rb28
-rw-r--r--spec/ruby/core/io/binwrite_spec.rb6
-rw-r--r--spec/ruby/core/io/buffer/and_spec.rb62
-rw-r--r--spec/ruby/core/io/buffer/bit_count_spec.rb64
-rw-r--r--spec/ruby/core/io/buffer/empty_spec.rb27
-rw-r--r--spec/ruby/core/io/buffer/external_spec.rb23
-rw-r--r--spec/ruby/core/io/buffer/for_spec.rb95
-rw-r--r--spec/ruby/core/io/buffer/free_spec.rb102
-rw-r--r--spec/ruby/core/io/buffer/initialize_spec.rb119
-rw-r--r--spec/ruby/core/io/buffer/internal_spec.rb23
-rw-r--r--spec/ruby/core/io/buffer/locked_spec.rb75
-rw-r--r--spec/ruby/core/io/buffer/map_spec.rb347
-rw-r--r--spec/ruby/core/io/buffer/mapped_spec.rb23
-rw-r--r--spec/ruby/core/io/buffer/not_spec.rb37
-rw-r--r--spec/ruby/core/io/buffer/null_spec.rb27
-rw-r--r--spec/ruby/core/io/buffer/or_spec.rb62
-rw-r--r--spec/ruby/core/io/buffer/private_spec.rb23
-rw-r--r--spec/ruby/core/io/buffer/readonly_spec.rb28
-rw-r--r--spec/ruby/core/io/buffer/resize_spec.rb151
-rw-r--r--spec/ruby/core/io/buffer/shared/null_and_empty.rb57
-rw-r--r--spec/ruby/core/io/buffer/shared_spec.rb33
-rw-r--r--spec/ruby/core/io/buffer/string_spec.rb62
-rw-r--r--spec/ruby/core/io/buffer/transfer_spec.rb117
-rw-r--r--spec/ruby/core/io/buffer/valid_spec.rb99
-rw-r--r--spec/ruby/core/io/buffer/xor_spec.rb62
-rw-r--r--spec/ruby/core/io/bytes_spec.rb43
-rw-r--r--spec/ruby/core/io/chars_spec.rb12
-rw-r--r--spec/ruby/core/io/close_on_exec_spec.rb46
-rw-r--r--spec/ruby/core/io/close_read_spec.rb47
-rw-r--r--spec/ruby/core/io/close_spec.rb70
-rw-r--r--spec/ruby/core/io/close_write_spec.rb56
-rw-r--r--spec/ruby/core/io/closed_spec.rb8
-rw-r--r--spec/ruby/core/io/codepoints_spec.rb25
-rw-r--r--spec/ruby/core/io/constants_spec.rb2
-rw-r--r--spec/ruby/core/io/copy_stream_spec.rb95
-rw-r--r--spec/ruby/core/io/dup_spec.rb87
-rw-r--r--spec/ruby/core/io/each_byte_spec.rb10
-rw-r--r--spec/ruby/core/io/each_char_spec.rb75
-rw-r--r--spec/ruby/core/io/each_codepoint_spec.rb63
-rw-r--r--spec/ruby/core/io/each_line_spec.rb250
-rw-r--r--spec/ruby/core/io/each_spec.rb12
-rw-r--r--spec/ruby/core/io/eof_spec.rb46
-rw-r--r--spec/ruby/core/io/external_encoding_spec.rb317
-rw-r--r--spec/ruby/core/io/fcntl_spec.rb6
-rw-r--r--spec/ruby/core/io/fdatasync_spec.rb2
-rw-r--r--spec/ruby/core/io/fileno_spec.rb6
-rw-r--r--spec/ruby/core/io/fixtures/classes.rb37
-rw-r--r--spec/ruby/core/io/fixtures/copy_in_out.rb2
-rw-r--r--spec/ruby/core/io/flush_spec.rb35
-rw-r--r--spec/ruby/core/io/for_fd_spec.rb4
-rw-r--r--spec/ruby/core/io/foreach_spec.rb61
-rw-r--r--spec/ruby/core/io/fsync_spec.rb6
-rw-r--r--spec/ruby/core/io/getbyte_spec.rb22
-rw-r--r--spec/ruby/core/io/getc_spec.rb10
-rw-r--r--spec/ruby/core/io/gets_spec.rb117
-rw-r--r--spec/ruby/core/io/initialize_spec.rb33
-rw-r--r--spec/ruby/core/io/inspect_spec.rb6
-rw-r--r--spec/ruby/core/io/internal_encoding_spec.rb239
-rw-r--r--spec/ruby/core/io/io_spec.rb2
-rw-r--r--spec/ruby/core/io/ioctl_spec.rb18
-rw-r--r--spec/ruby/core/io/isatty_spec.rb7
-rw-r--r--spec/ruby/core/io/lineno_spec.rb55
-rw-r--r--spec/ruby/core/io/lines_spec.rb42
-rw-r--r--spec/ruby/core/io/new_spec.rb12
-rw-r--r--spec/ruby/core/io/nonblock_spec.rb48
-rw-r--r--spec/ruby/core/io/open_spec.rb33
-rw-r--r--spec/ruby/core/io/output_spec.rb12
-rw-r--r--spec/ruby/core/io/path_spec.rb12
-rw-r--r--spec/ruby/core/io/pid_spec.rb8
-rw-r--r--spec/ruby/core/io/pipe_spec.rb59
-rw-r--r--spec/ruby/core/io/popen_spec.rb101
-rw-r--r--spec/ruby/core/io/pos_spec.rb39
-rw-r--r--spec/ruby/core/io/pread_spec.rb138
-rw-r--r--spec/ruby/core/io/print_spec.rb34
-rw-r--r--spec/ruby/core/io/printf_spec.rb6
-rw-r--r--spec/ruby/core/io/putc_spec.rb4
-rw-r--r--spec/ruby/core/io/puts_spec.rb48
-rw-r--r--spec/ruby/core/io/pwrite_spec.rb67
-rw-r--r--spec/ruby/core/io/read_nonblock_spec.rb105
-rw-r--r--spec/ruby/core/io/read_spec.rb487
-rw-r--r--spec/ruby/core/io/readbyte_spec.rb8
-rw-r--r--spec/ruby/core/io/readchar_spec.rb76
-rw-r--r--spec/ruby/core/io/readline_spec.rb49
-rw-r--r--spec/ruby/core/io/readlines_spec.rb135
-rw-r--r--spec/ruby/core/io/readpartial_spec.rb45
-rw-r--r--spec/ruby/core/io/reopen_spec.rb61
-rw-r--r--spec/ruby/core/io/rewind_spec.rb23
-rw-r--r--spec/ruby/core/io/seek_spec.rb14
-rw-r--r--spec/ruby/core/io/select_spec.rb128
-rw-r--r--spec/ruby/core/io/set_encoding_by_bom_spec.rb262
-rw-r--r--spec/ruby/core/io/set_encoding_spec.rb331
-rw-r--r--spec/ruby/core/io/shared/binwrite.rb29
-rw-r--r--spec/ruby/core/io/shared/chars.rb73
-rw-r--r--spec/ruby/core/io/shared/codepoints.rb54
-rw-r--r--spec/ruby/core/io/shared/each.rb144
-rw-r--r--spec/ruby/core/io/shared/gets_ascii.rb2
-rw-r--r--spec/ruby/core/io/shared/new.rb237
-rw-r--r--spec/ruby/core/io/shared/pos.rb46
-rw-r--r--spec/ruby/core/io/shared/readlines.rb176
-rw-r--r--spec/ruby/core/io/shared/tty.rb25
-rw-r--r--spec/ruby/core/io/shared/write.rb90
-rw-r--r--spec/ruby/core/io/stat_spec.rb13
-rw-r--r--spec/ruby/core/io/sync_spec.rb8
-rw-r--r--spec/ruby/core/io/sysopen_spec.rb18
-rw-r--r--spec/ruby/core/io/sysread_spec.rb75
-rw-r--r--spec/ruby/core/io/sysseek_spec.rb17
-rw-r--r--spec/ruby/core/io/syswrite_spec.rb38
-rw-r--r--spec/ruby/core/io/tell_spec.rb8
-rw-r--r--spec/ruby/core/io/to_i_spec.rb11
-rw-r--r--spec/ruby/core/io/to_io_spec.rb8
-rw-r--r--spec/ruby/core/io/to_path_spec.rb7
-rw-r--r--spec/ruby/core/io/try_convert_spec.rb16
-rw-r--r--spec/ruby/core/io/tty_spec.rb25
-rw-r--r--spec/ruby/core/io/ungetbyte_spec.rb22
-rw-r--r--spec/ruby/core/io/ungetc_spec.rb43
-rw-r--r--spec/ruby/core/io/write_nonblock_spec.rb48
-rw-r--r--spec/ruby/core/io/write_spec.rb237
-rw-r--r--spec/ruby/core/kernel/Array_spec.rb10
-rw-r--r--spec/ruby/core/kernel/Complex_spec.rb276
-rw-r--r--spec/ruby/core/kernel/Float_spec.rb271
-rw-r--r--spec/ruby/core/kernel/Hash_spec.rb18
-rw-r--r--spec/ruby/core/kernel/Integer_spec.rb380
-rw-r--r--spec/ruby/core/kernel/Rational_spec.rb236
-rw-r--r--spec/ruby/core/kernel/String_spec.rb20
-rw-r--r--spec/ruby/core/kernel/__callee___spec.rb4
-rw-r--r--spec/ruby/core/kernel/__dir___spec.rb20
-rw-r--r--spec/ruby/core/kernel/__method___spec.rb4
-rw-r--r--spec/ruby/core/kernel/abort_spec.rb8
-rw-r--r--spec/ruby/core/kernel/at_exit_spec.rb41
-rw-r--r--spec/ruby/core/kernel/autoload_relative_spec.rb114
-rw-r--r--spec/ruby/core/kernel/autoload_spec.rb87
-rw-r--r--spec/ruby/core/kernel/backtick_spec.rb48
-rw-r--r--spec/ruby/core/kernel/binding_spec.rb8
-rw-r--r--spec/ruby/core/kernel/block_given_spec.rb11
-rw-r--r--spec/ruby/core/kernel/caller_locations_spec.rb91
-rw-r--r--spec/ruby/core/kernel/caller_spec.rb94
-rw-r--r--spec/ruby/core/kernel/case_compare_spec.rb18
-rw-r--r--spec/ruby/core/kernel/catch_spec.rb14
-rw-r--r--spec/ruby/core/kernel/chomp_spec.rb42
-rw-r--r--spec/ruby/core/kernel/chop_spec.rb42
-rw-r--r--spec/ruby/core/kernel/class_spec.rb26
-rw-r--r--spec/ruby/core/kernel/clone_spec.rb109
-rw-r--r--spec/ruby/core/kernel/comparison_spec.rb8
-rw-r--r--spec/ruby/core/kernel/define_singleton_method_spec.rb65
-rw-r--r--spec/ruby/core/kernel/display_spec.rb4
-rw-r--r--spec/ruby/core/kernel/dup_spec.rb22
-rw-r--r--spec/ruby/core/kernel/enum_for_spec.rb6
-rw-r--r--spec/ruby/core/kernel/eql_spec.rb7
-rw-r--r--spec/ruby/core/kernel/equal_value_spec.rb4
-rw-r--r--spec/ruby/core/kernel/eval_spec.rb384
-rw-r--r--spec/ruby/core/kernel/exec_spec.rb10
-rw-r--r--spec/ruby/core/kernel/exit_spec.rb20
-rw-r--r--spec/ruby/core/kernel/extend_spec.rb30
-rw-r--r--spec/ruby/core/kernel/fail_spec.rb46
-rw-r--r--spec/ruby/core/kernel/fixtures/Complex.rb5
-rw-r--r--spec/ruby/core/kernel/fixtures/__dir__.rb2
-rw-r--r--spec/ruby/core/kernel/fixtures/autoload_c.rb5
-rw-r--r--spec/ruby/core/kernel/fixtures/autoload_from_included_module.rb9
-rw-r--r--spec/ruby/core/kernel/fixtures/autoload_from_included_module2.rb9
-rw-r--r--spec/ruby/core/kernel/fixtures/autoload_relative_b.rb7
-rw-r--r--spec/ruby/core/kernel/fixtures/autoload_relative_d.rb5
-rw-r--r--spec/ruby/core/kernel/fixtures/caller_at_exit.rb7
-rw-r--r--spec/ruby/core/kernel/fixtures/classes.rb200
-rw-r--r--spec/ruby/core/kernel/fixtures/eval_return_with_lambda.rb2
-rw-r--r--spec/ruby/core/kernel/fixtures/singleton_methods.rb13
-rw-r--r--spec/ruby/core/kernel/fixtures/warn_core_method.rb14
-rw-r--r--spec/ruby/core/kernel/fixtures/warn_require.rb1
-rw-r--r--spec/ruby/core/kernel/fixtures/warn_require_caller.rb2
-rw-r--r--spec/ruby/core/kernel/fork_spec.rb8
-rw-r--r--spec/ruby/core/kernel/format_spec.rb11
-rw-r--r--spec/ruby/core/kernel/freeze_spec.rb60
-rw-r--r--spec/ruby/core/kernel/frozen_spec.rb58
-rw-r--r--spec/ruby/core/kernel/gets_spec.rb6
-rw-r--r--spec/ruby/core/kernel/global_variables_spec.rb10
-rw-r--r--spec/ruby/core/kernel/gsub_spec.rb14
-rw-r--r--spec/ruby/core/kernel/initialize_clone_spec.rb26
-rw-r--r--spec/ruby/core/kernel/initialize_copy_spec.rb36
-rw-r--r--spec/ruby/core/kernel/initialize_dup_spec.rb20
-rw-r--r--spec/ruby/core/kernel/inspect_spec.rb94
-rw-r--r--spec/ruby/core/kernel/instance_of_spec.rb12
-rw-r--r--spec/ruby/core/kernel/instance_variable_defined_spec.rb18
-rw-r--r--spec/ruby/core/kernel/instance_variable_get_spec.rb38
-rw-r--r--spec/ruby/core/kernel/instance_variable_set_spec.rb58
-rw-r--r--spec/ruby/core/kernel/instance_variables_spec.rb21
-rw-r--r--spec/ruby/core/kernel/is_a_spec.rb56
-rw-r--r--spec/ruby/core/kernel/iterator_spec.rb12
-rw-r--r--spec/ruby/core/kernel/itself_spec.rb6
-rw-r--r--spec/ruby/core/kernel/kind_of_spec.rb7
-rw-r--r--spec/ruby/core/kernel/lambda_spec.rb68
-rw-r--r--spec/ruby/core/kernel/load_spec.rb10
-rw-r--r--spec/ruby/core/kernel/local_variables_spec.rb26
-rw-r--r--spec/ruby/core/kernel/loop_spec.rb26
-rw-r--r--spec/ruby/core/kernel/match_spec.rb13
-rw-r--r--spec/ruby/core/kernel/method_spec.rb67
-rw-r--r--spec/ruby/core/kernel/methods_spec.rb40
-rw-r--r--spec/ruby/core/kernel/nil_spec.rb14
-rw-r--r--spec/ruby/core/kernel/not_match_spec.rb8
-rw-r--r--spec/ruby/core/kernel/object_id_spec.rb4
-rw-r--r--spec/ruby/core/kernel/open_spec.rb131
-rw-r--r--spec/ruby/core/kernel/p_spec.rb46
-rw-r--r--spec/ruby/core/kernel/pp_spec.rb9
-rw-r--r--spec/ruby/core/kernel/print_spec.rb18
-rw-r--r--spec/ruby/core/kernel/printf_spec.rb44
-rw-r--r--spec/ruby/core/kernel/private_methods_spec.rb16
-rw-r--r--spec/ruby/core/kernel/proc_spec.rb38
-rw-r--r--spec/ruby/core/kernel/protected_methods_spec.rb16
-rw-r--r--spec/ruby/core/kernel/public_method_spec.rb20
-rw-r--r--spec/ruby/core/kernel/public_methods_spec.rb25
-rw-r--r--spec/ruby/core/kernel/public_send_spec.rb34
-rw-r--r--spec/ruby/core/kernel/putc_spec.rb8
-rw-r--r--spec/ruby/core/kernel/puts_spec.rb6
-rw-r--r--spec/ruby/core/kernel/raise_spec.rb219
-rw-r--r--spec/ruby/core/kernel/rand_spec.rb130
-rw-r--r--spec/ruby/core/kernel/readline_spec.rb6
-rw-r--r--spec/ruby/core/kernel/readlines_spec.rb6
-rw-r--r--spec/ruby/core/kernel/remove_instance_variable_spec.rb33
-rw-r--r--spec/ruby/core/kernel/require_relative_spec.rb236
-rw-r--r--spec/ruby/core/kernel/require_spec.rb43
-rw-r--r--spec/ruby/core/kernel/respond_to_missing_spec.rb24
-rw-r--r--spec/ruby/core/kernel/respond_to_spec.rb36
-rw-r--r--spec/ruby/core/kernel/select_spec.rb12
-rw-r--r--spec/ruby/core/kernel/send_spec.rb8
-rw-r--r--spec/ruby/core/kernel/set_trace_func_spec.rb6
-rw-r--r--spec/ruby/core/kernel/shared/dup_clone.rb98
-rw-r--r--spec/ruby/core/kernel/shared/kind_of.rb44
-rw-r--r--spec/ruby/core/kernel/shared/lambda.rb4
-rw-r--r--spec/ruby/core/kernel/shared/load.rb150
-rw-r--r--spec/ruby/core/kernel/shared/method.rb22
-rw-r--r--spec/ruby/core/kernel/shared/require.rb431
-rw-r--r--spec/ruby/core/kernel/shared/sprintf.rb1057
-rw-r--r--spec/ruby/core/kernel/shared/sprintf_encoding.rb67
-rw-r--r--spec/ruby/core/kernel/shared/then.rb20
-rw-r--r--spec/ruby/core/kernel/singleton_class_spec.rb53
-rw-r--r--spec/ruby/core/kernel/singleton_method_spec.rb54
-rw-r--r--spec/ruby/core/kernel/singleton_methods_spec.rb95
-rw-r--r--spec/ruby/core/kernel/sleep_spec.rb92
-rw-r--r--spec/ruby/core/kernel/spawn_spec.rb10
-rw-r--r--spec/ruby/core/kernel/sprintf_spec.rb362
-rw-r--r--spec/ruby/core/kernel/srand_spec.rb30
-rw-r--r--spec/ruby/core/kernel/sub_spec.rb8
-rw-r--r--spec/ruby/core/kernel/syscall_spec.rb6
-rw-r--r--spec/ruby/core/kernel/system_spec.rb65
-rw-r--r--spec/ruby/core/kernel/taint_spec.rb45
-rw-r--r--spec/ruby/core/kernel/tainted_spec.rb12
-rw-r--r--spec/ruby/core/kernel/tap_spec.rb8
-rw-r--r--spec/ruby/core/kernel/test_spec.rb20
-rw-r--r--spec/ruby/core/kernel/then_spec.rb14
-rw-r--r--spec/ruby/core/kernel/throw_spec.rb26
-rw-r--r--spec/ruby/core/kernel/to_enum_spec.rb58
-rw-r--r--spec/ruby/core/kernel/to_s_spec.rb12
-rw-r--r--spec/ruby/core/kernel/trace_var_spec.rb10
-rw-r--r--spec/ruby/core/kernel/trap_spec.rb9
-rw-r--r--spec/ruby/core/kernel/trust_spec.rb25
-rw-r--r--spec/ruby/core/kernel/untaint_spec.rb25
-rw-r--r--spec/ruby/core/kernel/untrace_var_spec.rb6
-rw-r--r--spec/ruby/core/kernel/untrust_spec.rb25
-rw-r--r--spec/ruby/core/kernel/untrusted_spec.rb28
-rw-r--r--spec/ruby/core/kernel/warn_spec.rb245
-rw-r--r--spec/ruby/core/kernel/yield_self_spec.rb28
-rw-r--r--spec/ruby/core/main/define_method_spec.rb10
-rw-r--r--spec/ruby/core/main/fixtures/classes.rb8
-rw-r--r--spec/ruby/core/main/fixtures/using.rb1
-rw-r--r--spec/ruby/core/main/fixtures/using_in_main.rb5
-rw-r--r--spec/ruby/core/main/fixtures/using_in_method.rb5
-rw-r--r--spec/ruby/core/main/include_spec.rb8
-rw-r--r--spec/ruby/core/main/private_spec.rb41
-rw-r--r--spec/ruby/core/main/public_spec.rb38
-rw-r--r--spec/ruby/core/main/ruby2_keywords_spec.rb9
-rw-r--r--spec/ruby/core/main/to_s_spec.rb2
-rw-r--r--spec/ruby/core/main/using_spec.rb240
-rw-r--r--spec/ruby/core/marshal/dump_spec.rb724
-rw-r--r--spec/ruby/core/marshal/fixtures/classes.rb4
-rw-r--r--spec/ruby/core/marshal/fixtures/marshal_data.rb217
-rw-r--r--spec/ruby/core/marshal/fixtures/marshal_multibyte_data.rb12
-rw-r--r--spec/ruby/core/marshal/float_spec.rb4
-rw-r--r--spec/ruby/core/marshal/load_spec.rb1291
-rw-r--r--spec/ruby/core/marshal/major_version_spec.rb2
-rw-r--r--spec/ruby/core/marshal/minor_version_spec.rb2
-rw-r--r--spec/ruby/core/marshal/restore_spec.rb7
-rw-r--r--spec/ruby/core/marshal/shared/load.rb830
-rw-r--r--spec/ruby/core/matchdata/allocate_spec.rb8
-rw-r--r--spec/ruby/core/matchdata/begin_spec.rb138
-rw-r--r--spec/ruby/core/matchdata/bytebegin_spec.rb132
-rw-r--r--spec/ruby/core/matchdata/byteend_spec.rb104
-rw-r--r--spec/ruby/core/matchdata/byteoffset_spec.rb93
-rw-r--r--spec/ruby/core/matchdata/captures_spec.rb8
-rw-r--r--spec/ruby/core/matchdata/deconstruct_keys_spec.rb78
-rw-r--r--spec/ruby/core/matchdata/deconstruct_spec.rb7
-rw-r--r--spec/ruby/core/matchdata/dup_spec.rb14
-rw-r--r--spec/ruby/core/matchdata/element_reference_spec.rb45
-rw-r--r--spec/ruby/core/matchdata/end_spec.rb110
-rw-r--r--spec/ruby/core/matchdata/eql_spec.rb7
-rw-r--r--spec/ruby/core/matchdata/equal_value_spec.rb26
-rw-r--r--spec/ruby/core/matchdata/fixtures/classes.rb3
-rw-r--r--spec/ruby/core/matchdata/hash_spec.rb2
-rw-r--r--spec/ruby/core/matchdata/inspect_spec.rb10
-rw-r--r--spec/ruby/core/matchdata/integer_at_spec.rb38
-rw-r--r--spec/ruby/core/matchdata/length_spec.rb7
-rw-r--r--spec/ruby/core/matchdata/match_length_spec.rb32
-rw-r--r--spec/ruby/core/matchdata/match_spec.rb32
-rw-r--r--spec/ruby/core/matchdata/named_captures_spec.rb30
-rw-r--r--spec/ruby/core/matchdata/names_spec.rb6
-rw-r--r--spec/ruby/core/matchdata/offset_spec.rb108
-rw-r--r--spec/ruby/core/matchdata/post_match_spec.rb34
-rw-r--r--spec/ruby/core/matchdata/pre_match_spec.rb34
-rw-r--r--spec/ruby/core/matchdata/regexp_spec.rb15
-rw-r--r--spec/ruby/core/matchdata/shared/eql.rb26
-rw-r--r--spec/ruby/core/matchdata/shared/length.rb5
-rw-r--r--spec/ruby/core/matchdata/size_spec.rb7
-rw-r--r--spec/ruby/core/matchdata/string_spec.rb16
-rw-r--r--spec/ruby/core/matchdata/to_a_spec.rb8
-rw-r--r--spec/ruby/core/matchdata/to_s_spec.rb8
-rw-r--r--spec/ruby/core/matchdata/values_at_spec.rb71
-rw-r--r--spec/ruby/core/math/acos_spec.rb26
-rw-r--r--spec/ruby/core/math/acosh_spec.rb22
-rw-r--r--spec/ruby/core/math/asin_spec.rb24
-rw-r--r--spec/ruby/core/math/asinh_spec.rb12
-rw-r--r--spec/ruby/core/math/atan2_spec.rb18
-rw-r--r--spec/ruby/core/math/atan_spec.rb12
-rw-r--r--spec/ruby/core/math/atanh_spec.rb6
-rw-r--r--spec/ruby/core/math/cbrt_spec.rb10
-rw-r--r--spec/ruby/core/math/constants_spec.rb4
-rw-r--r--spec/ruby/core/math/cos_spec.rb36
-rw-r--r--spec/ruby/core/math/cosh_spec.rb12
-rw-r--r--spec/ruby/core/math/erf_spec.rb12
-rw-r--r--spec/ruby/core/math/erfc_spec.rb12
-rw-r--r--spec/ruby/core/math/exp_spec.rb12
-rw-r--r--spec/ruby/core/math/expm1_spec.rb37
-rw-r--r--spec/ruby/core/math/fixtures/common.rb (renamed from spec/ruby/fixtures/math/common.rb)0
-rw-r--r--spec/ruby/core/math/frexp_spec.rb10
-rw-r--r--spec/ruby/core/math/gamma_spec.rb8
-rw-r--r--spec/ruby/core/math/hypot_spec.rb16
-rw-r--r--spec/ruby/core/math/ldexp_spec.rb24
-rw-r--r--spec/ruby/core/math/lgamma_spec.rb21
-rw-r--r--spec/ruby/core/math/log10_spec.rb22
-rw-r--r--spec/ruby/core/math/log1p_spec.rb49
-rw-r--r--spec/ruby/core/math/log2_spec.rb16
-rw-r--r--spec/ruby/core/math/log_spec.rb24
-rw-r--r--spec/ruby/core/math/shared/atanh.rb44
-rw-r--r--spec/ruby/core/math/sin_spec.rb12
-rw-r--r--spec/ruby/core/math/sinh_spec.rb12
-rw-r--r--spec/ruby/core/math/sqrt_spec.rb16
-rw-r--r--spec/ruby/core/math/tan_spec.rb18
-rw-r--r--spec/ruby/core/math/tanh_spec.rb12
-rw-r--r--spec/ruby/core/method/arity_spec.rb4
-rw-r--r--spec/ruby/core/method/call_spec.rb55
-rw-r--r--spec/ruby/core/method/case_compare_spec.rb7
-rw-r--r--spec/ruby/core/method/clone_spec.rb17
-rw-r--r--spec/ruby/core/method/compose_spec.rb99
-rw-r--r--spec/ruby/core/method/curry_spec.rb22
-rw-r--r--spec/ruby/core/method/dup_spec.rb15
-rw-r--r--spec/ruby/core/method/element_reference_spec.rb8
-rw-r--r--spec/ruby/core/method/eql_spec.rb7
-rw-r--r--spec/ruby/core/method/equal_value_spec.rb94
-rw-r--r--spec/ruby/core/method/fixtures/classes.rb63
-rw-r--r--spec/ruby/core/method/hash_spec.rb6
-rw-r--r--spec/ruby/core/method/inspect_spec.rb7
-rw-r--r--spec/ruby/core/method/name_spec.rb4
-rw-r--r--spec/ruby/core/method/original_name_spec.rb59
-rw-r--r--spec/ruby/core/method/owner_spec.rb8
-rw-r--r--spec/ruby/core/method/parameters_spec.rb83
-rw-r--r--spec/ruby/core/method/private_spec.rb9
-rw-r--r--spec/ruby/core/method/protected_spec.rb9
-rw-r--r--spec/ruby/core/method/public_spec.rb9
-rw-r--r--spec/ruby/core/method/receiver_spec.rb12
-rw-r--r--spec/ruby/core/method/shared/aliased_inspect.rb31
-rw-r--r--spec/ruby/core/method/shared/call.rb51
-rw-r--r--spec/ruby/core/method/shared/dup.rb32
-rw-r--r--spec/ruby/core/method/shared/eql.rb94
-rw-r--r--spec/ruby/core/method/shared/to_s.rb57
-rw-r--r--spec/ruby/core/method/source_location_spec.rb41
-rw-r--r--spec/ruby/core/method/super_method_spec.rb23
-rw-r--r--spec/ruby/core/method/to_proc_spec.rb21
-rw-r--r--spec/ruby/core/method/to_s_spec.rb8
-rw-r--r--spec/ruby/core/method/unbind_spec.rb35
-rw-r--r--spec/ruby/core/module/alias_method_spec.rb77
-rw-r--r--spec/ruby/core/module/allocate_spec.rb14
-rw-r--r--spec/ruby/core/module/ancestors_spec.rb44
-rw-r--r--spec/ruby/core/module/append_features_spec.rb38
-rw-r--r--spec/ruby/core/module/attr_accessor_spec.rb54
-rw-r--r--spec/ruby/core/module/attr_reader_spec.rb27
-rw-r--r--spec/ruby/core/module/attr_spec.rb40
-rw-r--r--spec/ruby/core/module/attr_writer_spec.rb37
-rw-r--r--spec/ruby/core/module/autoload_relative_spec.rb128
-rw-r--r--spec/ruby/core/module/autoload_spec.rb814
-rw-r--r--spec/ruby/core/module/case_compare_spec.rb4
-rw-r--r--spec/ruby/core/module/class_eval_spec.rb8
-rw-r--r--spec/ruby/core/module/class_exec_spec.rb8
-rw-r--r--spec/ruby/core/module/class_variable_defined_spec.rb26
-rw-r--r--spec/ruby/core/module/class_variable_get_spec.rb24
-rw-r--r--spec/ruby/core/module/class_variable_set_spec.rb28
-rw-r--r--spec/ruby/core/module/class_variables_spec.rb20
-rw-r--r--spec/ruby/core/module/comparison_spec.rb6
-rw-r--r--spec/ruby/core/module/const_added_spec.rb238
-rw-r--r--spec/ruby/core/module/const_defined_spec.rb91
-rw-r--r--spec/ruby/core/module/const_get_spec.rb125
-rw-r--r--spec/ruby/core/module/const_missing_spec.rb17
-rw-r--r--spec/ruby/core/module/const_set_spec.rb91
-rw-r--r--spec/ruby/core/module/const_source_location_spec.rb281
-rw-r--r--spec/ruby/core/module/constants_spec.rb31
-rw-r--r--spec/ruby/core/module/define_method_spec.rb368
-rw-r--r--spec/ruby/core/module/define_singleton_method_spec.rb6
-rw-r--r--spec/ruby/core/module/deprecate_constant_spec.rb90
-rw-r--r--spec/ruby/core/module/eql_spec.rb8
-rw-r--r--spec/ruby/core/module/equal_spec.rb8
-rw-r--r--spec/ruby/core/module/equal_value_spec.rb8
-rw-r--r--spec/ruby/core/module/extend_object_spec.rb28
-rw-r--r--spec/ruby/core/module/extended_spec.rb6
-rw-r--r--spec/ruby/core/module/fixtures/autoload_callback.rb2
-rw-r--r--spec/ruby/core/module/fixtures/autoload_const_source_location.rb6
-rw-r--r--spec/ruby/core/module/fixtures/autoload_during_autoload.rb7
-rw-r--r--spec/ruby/core/module/fixtures/autoload_during_autoload_after_define.rb6
-rw-r--r--spec/ruby/core/module/fixtures/autoload_during_require.rb4
-rw-r--r--spec/ruby/core/module/fixtures/autoload_during_require_current_file.rb5
-rw-r--r--spec/ruby/core/module/fixtures/autoload_exception.rb3
-rw-r--r--spec/ruby/core/module/fixtures/autoload_location.rb3
-rw-r--r--spec/ruby/core/module/fixtures/autoload_nested.rb8
-rw-r--r--spec/ruby/core/module/fixtures/autoload_never_set.rb1
-rw-r--r--spec/ruby/core/module/fixtures/autoload_o.rb1
-rw-r--r--spec/ruby/core/module/fixtures/autoload_overridden.rb3
-rw-r--r--spec/ruby/core/module/fixtures/autoload_raise.rb2
-rw-r--r--spec/ruby/core/module/fixtures/autoload_relative_a.rb9
-rw-r--r--spec/ruby/core/module/fixtures/autoload_required_directly.rb7
-rw-r--r--spec/ruby/core/module/fixtures/autoload_required_directly_nested.rb1
-rw-r--r--spec/ruby/core/module/fixtures/autoload_required_directly_no_constant.rb2
-rw-r--r--spec/ruby/core/module/fixtures/autoload_scope.rb8
-rw-r--r--spec/ruby/core/module/fixtures/autoload_self_during_require.rb5
-rw-r--r--spec/ruby/core/module/fixtures/autoload_subclass.rb4
-rw-r--r--spec/ruby/core/module/fixtures/classes.rb50
-rw-r--r--spec/ruby/core/module/fixtures/const_added.rb4
-rw-r--r--spec/ruby/core/module/fixtures/constants_autoload.rb6
-rw-r--r--spec/ruby/core/module/fixtures/constants_autoload_a.rb2
-rw-r--r--spec/ruby/core/module/fixtures/constants_autoload_b.rb2
-rw-r--r--spec/ruby/core/module/fixtures/constants_autoload_c.rb3
-rw-r--r--spec/ruby/core/module/fixtures/constants_autoload_d.rb4
-rw-r--r--spec/ruby/core/module/fixtures/module.rb4
-rw-r--r--spec/ruby/core/module/fixtures/multi/foo.rb6
-rw-r--r--spec/ruby/core/module/fixtures/multi/foo/bar_baz.rb11
-rw-r--r--spec/ruby/core/module/fixtures/name.rb3
-rw-r--r--spec/ruby/core/module/fixtures/refine.rb12
-rw-r--r--spec/ruby/core/module/fixtures/set_temporary_name.rb4
-rw-r--r--spec/ruby/core/module/fixtures/using.rb10
-rw-r--r--spec/ruby/core/module/freeze_spec.rb4
-rw-r--r--spec/ruby/core/module/gt_spec.rb14
-rw-r--r--spec/ruby/core/module/gte_spec.rb6
-rw-r--r--spec/ruby/core/module/include_spec.rb436
-rw-r--r--spec/ruby/core/module/included_modules_spec.rb12
-rw-r--r--spec/ruby/core/module/included_spec.rb8
-rw-r--r--spec/ruby/core/module/initialize_copy_spec.rb10
-rw-r--r--spec/ruby/core/module/initialize_spec.rb4
-rw-r--r--spec/ruby/core/module/inspect_spec.rb7
-rw-r--r--spec/ruby/core/module/instance_method_spec.rb59
-rw-r--r--spec/ruby/core/module/instance_methods_spec.rb34
-rw-r--r--spec/ruby/core/module/lt_spec.rb14
-rw-r--r--spec/ruby/core/module/lte_spec.rb6
-rw-r--r--spec/ruby/core/module/method_added_spec.rb100
-rw-r--r--spec/ruby/core/module/method_defined_spec.rb61
-rw-r--r--spec/ruby/core/module/method_removed_spec.rb6
-rw-r--r--spec/ruby/core/module/method_undefined_spec.rb6
-rw-r--r--spec/ruby/core/module/module_eval_spec.rb176
-rw-r--r--spec/ruby/core/module/module_exec_spec.rb39
-rw-r--r--spec/ruby/core/module/module_function_spec.rb185
-rw-r--r--spec/ruby/core/module/name_spec.rb153
-rw-r--r--spec/ruby/core/module/nesting_spec.rb4
-rw-r--r--spec/ruby/core/module/new_spec.rb8
-rw-r--r--spec/ruby/core/module/prepend_features_spec.rb28
-rw-r--r--spec/ruby/core/module/prepend_spec.rb540
-rw-r--r--spec/ruby/core/module/prepended_spec.rb4
-rw-r--r--spec/ruby/core/module/private_class_method_spec.rb40
-rw-r--r--spec/ruby/core/module/private_constant_spec.rb12
-rw-r--r--spec/ruby/core/module/private_instance_methods_spec.rb24
-rw-r--r--spec/ruby/core/module/private_method_defined_spec.rb74
-rw-r--r--spec/ruby/core/module/private_spec.rb67
-rw-r--r--spec/ruby/core/module/protected_instance_methods_spec.rb18
-rw-r--r--spec/ruby/core/module/protected_method_defined_spec.rb74
-rw-r--r--spec/ruby/core/module/protected_spec.rb29
-rw-r--r--spec/ruby/core/module/public_class_method_spec.rb38
-rw-r--r--spec/ruby/core/module/public_constant_spec.rb6
-rw-r--r--spec/ruby/core/module/public_instance_method_spec.rb32
-rw-r--r--spec/ruby/core/module/public_instance_methods_spec.rb20
-rw-r--r--spec/ruby/core/module/public_method_defined_spec.rb26
-rw-r--r--spec/ruby/core/module/public_spec.rb27
-rw-r--r--spec/ruby/core/module/refine_spec.rb454
-rw-r--r--spec/ruby/core/module/refinements_spec.rb43
-rw-r--r--spec/ruby/core/module/remove_class_variable_spec.rb16
-rw-r--r--spec/ruby/core/module/remove_const_spec.rb59
-rw-r--r--spec/ruby/core/module/remove_method_spec.rb60
-rw-r--r--spec/ruby/core/module/ruby2_keywords_spec.rb248
-rw-r--r--spec/ruby/core/module/set_temporary_name_spec.rb145
-rw-r--r--spec/ruby/core/module/shared/attr_added.rb34
-rw-r--r--spec/ruby/core/module/shared/class_eval.rb115
-rw-r--r--spec/ruby/core/module/shared/class_exec.rb29
-rw-r--r--spec/ruby/core/module/shared/set_visibility.rb75
-rw-r--r--spec/ruby/core/module/singleton_class_spec.rb12
-rw-r--r--spec/ruby/core/module/to_s_spec.rb60
-rw-r--r--spec/ruby/core/module/undef_method_spec.rb67
-rw-r--r--spec/ruby/core/module/undefined_instance_methods_spec.rb25
-rw-r--r--spec/ruby/core/module/used_refinements_spec.rb85
-rw-r--r--spec/ruby/core/module/using_spec.rb135
-rw-r--r--spec/ruby/core/mutex/lock_spec.rb91
-rw-r--r--spec/ruby/core/mutex/locked_spec.rb10
-rw-r--r--spec/ruby/core/mutex/owned_spec.rb18
-rw-r--r--spec/ruby/core/mutex/sleep_spec.rb69
-rw-r--r--spec/ruby/core/mutex/synchronize_spec.rb49
-rw-r--r--spec/ruby/core/mutex/try_lock_spec.rb10
-rw-r--r--spec/ruby/core/mutex/unlock_spec.rb10
-rw-r--r--spec/ruby/core/nil/and_spec.rb2
-rw-r--r--spec/ruby/core/nil/case_compare_spec.rb13
-rw-r--r--spec/ruby/core/nil/dup_spec.rb10
-rw-r--r--spec/ruby/core/nil/inspect_spec.rb2
-rw-r--r--spec/ruby/core/nil/match_spec.rb21
-rw-r--r--spec/ruby/core/nil/nil_spec.rb4
-rw-r--r--spec/ruby/core/nil/nilclass_spec.rb10
-rw-r--r--spec/ruby/core/nil/or_spec.rb2
-rw-r--r--spec/ruby/core/nil/rationalize_spec.rb6
-rw-r--r--spec/ruby/core/nil/singleton_method_spec.rb13
-rw-r--r--spec/ruby/core/nil/to_a_spec.rb2
-rw-r--r--spec/ruby/core/nil/to_c_spec.rb4
-rw-r--r--spec/ruby/core/nil/to_f_spec.rb2
-rw-r--r--spec/ruby/core/nil/to_h_spec.rb2
-rw-r--r--spec/ruby/core/nil/to_i_spec.rb4
-rw-r--r--spec/ruby/core/nil/to_r_spec.rb2
-rw-r--r--spec/ruby/core/nil/to_s_spec.rb10
-rw-r--r--spec/ruby/core/nil/xor_spec.rb10
-rw-r--r--spec/ruby/core/numeric/abs2_spec.rb6
-rw-r--r--spec/ruby/core/numeric/abs_spec.rb18
-rw-r--r--spec/ruby/core/numeric/angle_spec.rb7
-rw-r--r--spec/ruby/core/numeric/arg_spec.rb38
-rw-r--r--spec/ruby/core/numeric/ceil_spec.rb4
-rw-r--r--spec/ruby/core/numeric/clone_spec.rb30
-rw-r--r--spec/ruby/core/numeric/coerce_spec.rb49
-rw-r--r--spec/ruby/core/numeric/comparison_spec.rb12
-rw-r--r--spec/ruby/core/numeric/conj_spec.rb7
-rw-r--r--spec/ruby/core/numeric/conjugate_spec.rb20
-rw-r--r--spec/ruby/core/numeric/denominator_spec.rb2
-rw-r--r--spec/ruby/core/numeric/div_spec.rb10
-rw-r--r--spec/ruby/core/numeric/divmod_spec.rb4
-rw-r--r--spec/ruby/core/numeric/dup_spec.rb16
-rw-r--r--spec/ruby/core/numeric/eql_spec.rb16
-rw-r--r--spec/ruby/core/numeric/fdiv_spec.rb7
-rw-r--r--spec/ruby/core/numeric/finite_spec.rb12
-rw-r--r--spec/ruby/core/numeric/floor_spec.rb4
-rw-r--r--spec/ruby/core/numeric/i_spec.rb4
-rw-r--r--spec/ruby/core/numeric/imag_spec.rb7
-rw-r--r--spec/ruby/core/numeric/imaginary_spec.rb26
-rw-r--r--spec/ruby/core/numeric/infinite_spec.rb12
-rw-r--r--spec/ruby/core/numeric/integer_spec.rb6
-rw-r--r--spec/ruby/core/numeric/magnitude_spec.rb6
-rw-r--r--spec/ruby/core/numeric/modulo_spec.rb21
-rw-r--r--spec/ruby/core/numeric/negative_spec.rb60
-rw-r--r--spec/ruby/core/numeric/nonzero_spec.rb4
-rw-r--r--spec/ruby/core/numeric/numerator_spec.rb2
-rw-r--r--spec/ruby/core/numeric/numeric_spec.rb2
-rw-r--r--spec/ruby/core/numeric/phase_spec.rb7
-rw-r--r--spec/ruby/core/numeric/polar_spec.rb50
-rw-r--r--spec/ruby/core/numeric/positive_spec.rb60
-rw-r--r--spec/ruby/core/numeric/quo_spec.rb38
-rw-r--r--spec/ruby/core/numeric/real_spec.rb34
-rw-r--r--spec/ruby/core/numeric/rect_spec.rb7
-rw-r--r--spec/ruby/core/numeric/rectangular_spec.rb48
-rw-r--r--spec/ruby/core/numeric/remainder_spec.rb11
-rw-r--r--spec/ruby/core/numeric/round_spec.rb4
-rw-r--r--spec/ruby/core/numeric/shared/abs.rb19
-rw-r--r--spec/ruby/core/numeric/shared/quo.rb7
-rw-r--r--spec/ruby/core/numeric/shared/rect.rb48
-rw-r--r--spec/ruby/core/numeric/shared/step.rb325
-rw-r--r--spec/ruby/core/numeric/singleton_method_added_spec.rb20
-rw-r--r--spec/ruby/core/numeric/step_spec.rb102
-rw-r--r--spec/ruby/core/numeric/to_c_spec.rb6
-rw-r--r--spec/ruby/core/numeric/to_int_spec.rb4
-rw-r--r--spec/ruby/core/numeric/truncate_spec.rb4
-rw-r--r--spec/ruby/core/numeric/uminus_spec.rb2
-rw-r--r--spec/ruby/core/numeric/uplus_spec.rb4
-rw-r--r--spec/ruby/core/numeric/zero_spec.rb8
-rw-r--r--spec/ruby/core/objectspace/_id2ref_spec.rb76
-rw-r--r--spec/ruby/core/objectspace/add_finalizer_spec.rb5
-rw-r--r--spec/ruby/core/objectspace/call_finalizer_spec.rb5
-rw-r--r--spec/ruby/core/objectspace/count_objects_spec.rb2
-rw-r--r--spec/ruby/core/objectspace/define_finalizer_spec.rb246
-rw-r--r--spec/ruby/core/objectspace/each_object_spec.rb66
-rw-r--r--spec/ruby/core/objectspace/finalizers_spec.rb5
-rw-r--r--spec/ruby/core/objectspace/fixtures/classes.rb2
-rw-r--r--spec/ruby/core/objectspace/garbage_collect_spec.rb10
-rw-r--r--spec/ruby/core/objectspace/remove_finalizer_spec.rb5
-rw-r--r--spec/ruby/core/objectspace/undefine_finalizer_spec.rb32
-rw-r--r--spec/ruby/core/objectspace/weakkeymap/clear_spec.rb25
-rw-r--r--spec/ruby/core/objectspace/weakkeymap/delete_spec.rb49
-rw-r--r--spec/ruby/core/objectspace/weakkeymap/element_reference_spec.rb105
-rw-r--r--spec/ruby/core/objectspace/weakkeymap/element_set_spec.rb80
-rw-r--r--spec/ruby/core/objectspace/weakkeymap/fixtures/classes.rb5
-rw-r--r--spec/ruby/core/objectspace/weakkeymap/getkey_spec.rb26
-rw-r--r--spec/ruby/core/objectspace/weakkeymap/inspect_spec.rb19
-rw-r--r--spec/ruby/core/objectspace/weakkeymap/key_spec.rb42
-rw-r--r--spec/ruby/core/objectspace/weakmap/delete_spec.rb28
-rw-r--r--spec/ruby/core/objectspace/weakmap/each_key_spec.rb11
-rw-r--r--spec/ruby/core/objectspace/weakmap/each_pair_spec.rb8
-rw-r--r--spec/ruby/core/objectspace/weakmap/each_spec.rb11
-rw-r--r--spec/ruby/core/objectspace/weakmap/each_value_spec.rb11
-rw-r--r--spec/ruby/core/objectspace/weakmap/element_reference_spec.rb24
-rw-r--r--spec/ruby/core/objectspace/weakmap/element_set_spec.rb38
-rw-r--r--spec/ruby/core/objectspace/weakmap/include_spec.rb32
-rw-r--r--spec/ruby/core/objectspace/weakmap/inspect_spec.rb25
-rw-r--r--spec/ruby/core/objectspace/weakmap/key_spec.rb8
-rw-r--r--spec/ruby/core/objectspace/weakmap/keys_spec.rb6
-rw-r--r--spec/ruby/core/objectspace/weakmap/length_spec.rb8
-rw-r--r--spec/ruby/core/objectspace/weakmap/member_spec.rb8
-rw-r--r--spec/ruby/core/objectspace/weakmap/shared/each.rb10
-rw-r--r--spec/ruby/core/objectspace/weakmap/shared/members.rb14
-rw-r--r--spec/ruby/core/objectspace/weakmap/size_spec.rb16
-rw-r--r--spec/ruby/core/objectspace/weakmap/values_spec.rb6
-rw-r--r--spec/ruby/core/objectspace/weakmap_spec.rb12
-rw-r--r--spec/ruby/core/proc/allocate_spec.rb6
-rw-r--r--spec/ruby/core/proc/arity_spec.rb18
-rw-r--r--spec/ruby/core/proc/binding_spec.rb8
-rw-r--r--spec/ruby/core/proc/block_pass_spec.rb26
-rw-r--r--spec/ruby/core/proc/call_spec.rb144
-rw-r--r--spec/ruby/core/proc/case_compare_spec.rb17
-rw-r--r--spec/ruby/core/proc/clone_spec.rb28
-rw-r--r--spec/ruby/core/proc/compose_spec.rb142
-rw-r--r--spec/ruby/core/proc/curry_spec.rb87
-rw-r--r--spec/ruby/core/proc/dup_spec.rb26
-rw-r--r--spec/ruby/core/proc/element_reference_spec.rb17
-rw-r--r--spec/ruby/core/proc/eql_spec.rb7
-rw-r--r--spec/ruby/core/proc/equal_value_spec.rb83
-rw-r--r--spec/ruby/core/proc/fixtures/common.rb23
-rw-r--r--spec/ruby/core/proc/fixtures/proc_call.rb10
-rw-r--r--spec/ruby/core/proc/fixtures/proc_call_frozen.rb10
-rw-r--r--spec/ruby/core/proc/fixtures/source_location.rb8
-rw-r--r--spec/ruby/core/proc/hash_spec.rb8
-rw-r--r--spec/ruby/core/proc/inspect_spec.rb7
-rw-r--r--spec/ruby/core/proc/lambda_spec.rb47
-rw-r--r--spec/ruby/core/proc/new_spec.rb46
-rw-r--r--spec/ruby/core/proc/parameters_spec.rb136
-rw-r--r--spec/ruby/core/proc/ruby2_keywords_spec.rb66
-rw-r--r--spec/ruby/core/proc/shared/call.rb96
-rw-r--r--spec/ruby/core/proc/shared/call_arguments.rb7
-rw-r--r--spec/ruby/core/proc/shared/compose.rb22
-rw-r--r--spec/ruby/core/proc/shared/dup.rb33
-rw-r--r--spec/ruby/core/proc/shared/equal.rb100
-rw-r--r--spec/ruby/core/proc/shared/to_s.rb27
-rw-r--r--spec/ruby/core/proc/source_location_spec.rb59
-rw-r--r--spec/ruby/core/proc/to_proc_spec.rb6
-rw-r--r--spec/ruby/core/proc/to_s_spec.rb62
-rw-r--r--spec/ruby/core/proc/yield_spec.rb17
-rw-r--r--spec/ruby/core/process/_fork_spec.rb24
-rw-r--r--spec/ruby/core/process/abort_spec.rb4
-rw-r--r--spec/ruby/core/process/argv0_spec.rb23
-rw-r--r--spec/ruby/core/process/clock_getres_spec.rb33
-rw-r--r--spec/ruby/core/process/clock_gettime_spec.rb152
-rw-r--r--spec/ruby/core/process/constants_spec.rb153
-rw-r--r--spec/ruby/core/process/daemon_spec.rb30
-rw-r--r--spec/ruby/core/process/detach_spec.rb104
-rw-r--r--spec/ruby/core/process/egid_spec.rb45
-rw-r--r--spec/ruby/core/process/euid_spec.rb45
-rw-r--r--spec/ruby/core/process/exec_spec.rb109
-rw-r--r--spec/ruby/core/process/exit_spec.rb6
-rw-r--r--spec/ruby/core/process/fixtures/argv0.rb6
-rw-r--r--spec/ruby/core/process/fixtures/clocks.rb18
-rw-r--r--spec/ruby/core/process/fixtures/common.rb8
-rw-r--r--spec/ruby/core/process/fixtures/in.txt1
-rw-r--r--spec/ruby/core/process/fixtures/kill.rb2
-rw-r--r--spec/ruby/core/process/fixtures/map_fd.rb3
-rw-r--r--spec/ruby/core/process/fork_spec.rb4
-rw-r--r--spec/ruby/core/process/getpgid_spec.rb2
-rw-r--r--spec/ruby/core/process/getpgrp_spec.rb2
-rw-r--r--spec/ruby/core/process/getpriority_spec.rb10
-rw-r--r--spec/ruby/core/process/getrlimit_spec.rb39
-rw-r--r--spec/ruby/core/process/gid/change_privilege_spec.rb2
-rw-r--r--spec/ruby/core/process/gid/eid_spec.rb2
-rw-r--r--spec/ruby/core/process/gid/grant_privilege_spec.rb2
-rw-r--r--spec/ruby/core/process/gid/re_exchange_spec.rb2
-rw-r--r--spec/ruby/core/process/gid/re_exchangeable_spec.rb2
-rw-r--r--spec/ruby/core/process/gid/rid_spec.rb2
-rw-r--r--spec/ruby/core/process/gid/sid_available_spec.rb2
-rw-r--r--spec/ruby/core/process/gid/switch_spec.rb2
-rw-r--r--spec/ruby/core/process/gid_spec.rb6
-rw-r--r--spec/ruby/core/process/groups_spec.rb45
-rw-r--r--spec/ruby/core/process/initgroups_spec.rb30
-rw-r--r--spec/ruby/core/process/kill_spec.rb22
-rw-r--r--spec/ruby/core/process/last_status_spec.rb18
-rw-r--r--spec/ruby/core/process/maxgroups_spec.rb4
-rw-r--r--spec/ruby/core/process/pid_spec.rb4
-rw-r--r--spec/ruby/core/process/ppid_spec.rb20
-rw-r--r--spec/ruby/core/process/set_proctitle_spec.rb4
-rw-r--r--spec/ruby/core/process/setpgid_spec.rb5
-rw-r--r--spec/ruby/core/process/setpgrp_spec.rb4
-rw-r--r--spec/ruby/core/process/setpriority_spec.rb33
-rw-r--r--spec/ruby/core/process/setrlimit_spec.rb123
-rw-r--r--spec/ruby/core/process/setsid_spec.rb39
-rw-r--r--spec/ruby/core/process/spawn_spec.rb466
-rw-r--r--spec/ruby/core/process/status/bit_and_spec.rb39
-rw-r--r--spec/ruby/core/process/status/coredump_spec.rb2
-rw-r--r--spec/ruby/core/process/status/equal_value_spec.rb14
-rw-r--r--spec/ruby/core/process/status/exited_spec.rb15
-rw-r--r--spec/ruby/core/process/status/exitstatus_spec.rb18
-rw-r--r--spec/ruby/core/process/status/inspect_spec.rb2
-rw-r--r--spec/ruby/core/process/status/pid_spec.rb2
-rw-r--r--spec/ruby/core/process/status/right_shift_spec.rb38
-rw-r--r--spec/ruby/core/process/status/signaled_spec.rb14
-rw-r--r--spec/ruby/core/process/status/stopped_spec.rb2
-rw-r--r--spec/ruby/core/process/status/stopsig_spec.rb2
-rw-r--r--spec/ruby/core/process/status/success_spec.rb24
-rw-r--r--spec/ruby/core/process/status/termsig_spec.rb30
-rw-r--r--spec/ruby/core/process/status/to_i_spec.rb12
-rw-r--r--spec/ruby/core/process/status/to_int_spec.rb2
-rw-r--r--spec/ruby/core/process/status/to_s_spec.rb2
-rw-r--r--spec/ruby/core/process/status/wait_spec.rb102
-rw-r--r--spec/ruby/core/process/sys/getegid_spec.rb2
-rw-r--r--spec/ruby/core/process/sys/geteuid_spec.rb2
-rw-r--r--spec/ruby/core/process/sys/getgid_spec.rb2
-rw-r--r--spec/ruby/core/process/sys/getuid_spec.rb2
-rw-r--r--spec/ruby/core/process/sys/issetugid_spec.rb2
-rw-r--r--spec/ruby/core/process/sys/setegid_spec.rb2
-rw-r--r--spec/ruby/core/process/sys/seteuid_spec.rb2
-rw-r--r--spec/ruby/core/process/sys/setgid_spec.rb2
-rw-r--r--spec/ruby/core/process/sys/setregid_spec.rb2
-rw-r--r--spec/ruby/core/process/sys/setresgid_spec.rb2
-rw-r--r--spec/ruby/core/process/sys/setresuid_spec.rb2
-rw-r--r--spec/ruby/core/process/sys/setreuid_spec.rb2
-rw-r--r--spec/ruby/core/process/sys/setrgid_spec.rb2
-rw-r--r--spec/ruby/core/process/sys/setruid_spec.rb2
-rw-r--r--spec/ruby/core/process/sys/setuid_spec.rb2
-rw-r--r--spec/ruby/core/process/times_spec.rb32
-rw-r--r--spec/ruby/core/process/tms/cstime_spec.rb17
-rw-r--r--spec/ruby/core/process/tms/cutime_spec.rb17
-rw-r--r--spec/ruby/core/process/tms/stime_spec.rb17
-rw-r--r--spec/ruby/core/process/tms/utime_spec.rb17
-rw-r--r--spec/ruby/core/process/uid/change_privilege_spec.rb2
-rw-r--r--spec/ruby/core/process/uid/eid_spec.rb2
-rw-r--r--spec/ruby/core/process/uid/grant_privilege_spec.rb2
-rw-r--r--spec/ruby/core/process/uid/re_exchange_spec.rb2
-rw-r--r--spec/ruby/core/process/uid/re_exchangeable_spec.rb2
-rw-r--r--spec/ruby/core/process/uid/rid_spec.rb2
-rw-r--r--spec/ruby/core/process/uid/sid_available_spec.rb2
-rw-r--r--spec/ruby/core/process/uid/switch_spec.rb2
-rw-r--r--spec/ruby/core/process/uid_spec.rb63
-rw-r--r--spec/ruby/core/process/wait2_spec.rb40
-rw-r--r--spec/ruby/core/process/wait_spec.rb58
-rw-r--r--spec/ruby/core/process/waitall_spec.rb32
-rw-r--r--spec/ruby/core/process/waitpid2_spec.rb6
-rw-r--r--spec/ruby/core/process/waitpid_spec.rb14
-rw-r--r--spec/ruby/core/process/warmup_spec.rb9
-rw-r--r--spec/ruby/core/queue/append_spec.rb6
-rw-r--r--spec/ruby/core/queue/clear_spec.rb6
-rw-r--r--spec/ruby/core/queue/close_spec.rb6
-rw-r--r--spec/ruby/core/queue/closed_spec.rb6
-rw-r--r--spec/ruby/core/queue/deq_spec.rb7
-rw-r--r--spec/ruby/core/queue/empty_spec.rb6
-rw-r--r--spec/ruby/core/queue/enq_spec.rb7
-rw-r--r--spec/ruby/core/queue/freeze_spec.rb6
-rw-r--r--spec/ruby/core/queue/initialize_spec.rb60
-rw-r--r--spec/ruby/core/queue/length_spec.rb7
-rw-r--r--spec/ruby/core/queue/num_waiting_spec.rb6
-rw-r--r--spec/ruby/core/queue/pop_spec.rb11
-rw-r--r--spec/ruby/core/queue/push_spec.rb7
-rw-r--r--spec/ruby/core/queue/shift_spec.rb7
-rw-r--r--spec/ruby/core/queue/size_spec.rb6
-rw-r--r--spec/ruby/core/random/bytes_spec.rb26
-rw-r--r--spec/ruby/core/random/default_spec.rb6
-rw-r--r--spec/ruby/core/random/equal_value_spec.rb2
-rw-r--r--spec/ruby/core/random/fixtures/classes.rb15
-rw-r--r--spec/ruby/core/random/new_seed_spec.rb6
-rw-r--r--spec/ruby/core/random/new_spec.rb11
-rw-r--r--spec/ruby/core/random/rand_spec.rb64
-rw-r--r--spec/ruby/core/random/random_number_spec.rb8
-rw-r--r--spec/ruby/core/random/raw_seed_spec.rb9
-rw-r--r--spec/ruby/core/random/seed_spec.rb4
-rw-r--r--spec/ruby/core/random/shared/bytes.rb17
-rw-r--r--spec/ruby/core/random/shared/rand.rb9
-rw-r--r--spec/ruby/core/random/shared/urandom.rb23
-rw-r--r--spec/ruby/core/random/srand_spec.rb2
-rw-r--r--spec/ruby/core/random/urandom_spec.rb28
-rw-r--r--spec/ruby/core/range/begin_spec.rb6
-rw-r--r--spec/ruby/core/range/bsearch_spec.rb381
-rw-r--r--spec/ruby/core/range/case_compare_spec.rb20
-rw-r--r--spec/ruby/core/range/clone_spec.rb26
-rw-r--r--spec/ruby/core/range/count_spec.rb12
-rw-r--r--spec/ruby/core/range/cover_spec.rb13
-rw-r--r--spec/ruby/core/range/dup_spec.rb16
-rw-r--r--spec/ruby/core/range/each_spec.rb53
-rw-r--r--spec/ruby/core/range/end_spec.rb6
-rw-r--r--spec/ruby/core/range/entries_spec.rb7
-rw-r--r--spec/ruby/core/range/eql_spec.rb8
-rw-r--r--spec/ruby/core/range/equal_value_spec.rb16
-rw-r--r--spec/ruby/core/range/exclude_end_spec.rb22
-rw-r--r--spec/ruby/core/range/first_spec.rb18
-rw-r--r--spec/ruby/core/range/fixtures/classes.rb25
-rw-r--r--spec/ruby/core/range/frozen_spec.rb25
-rw-r--r--spec/ruby/core/range/hash_spec.rb12
-rw-r--r--spec/ruby/core/range/include_spec.rb100
-rw-r--r--spec/ruby/core/range/initialize_spec.rb24
-rw-r--r--spec/ruby/core/range/inspect_spec.rb21
-rw-r--r--spec/ruby/core/range/last_spec.rb22
-rw-r--r--spec/ruby/core/range/max_spec.rb59
-rw-r--r--spec/ruby/core/range/member_spec.rb11
-rw-r--r--spec/ruby/core/range/min_spec.rb37
-rw-r--r--spec/ruby/core/range/minmax_spec.rb130
-rw-r--r--spec/ruby/core/range/new_spec.rb51
-rw-r--r--spec/ruby/core/range/overlap_spec.rb87
-rw-r--r--spec/ruby/core/range/percent_spec.rb16
-rw-r--r--spec/ruby/core/range/range_spec.rb2
-rw-r--r--spec/ruby/core/range/reverse_each_spec.rb125
-rw-r--r--spec/ruby/core/range/shared/cover.rb150
-rw-r--r--spec/ruby/core/range/shared/cover_and_include.rb56
-rw-r--r--spec/ruby/core/range/shared/equal_value.rb8
-rw-r--r--spec/ruby/core/range/shared/include.rb91
-rw-r--r--spec/ruby/core/range/size_spec.rb87
-rw-r--r--spec/ruby/core/range/step_spec.rb604
-rw-r--r--spec/ruby/core/range/to_a_spec.rb21
-rw-r--r--spec/ruby/core/range/to_s_spec.rb16
-rw-r--r--spec/ruby/core/range/to_set_spec.rb54
-rw-r--r--spec/ruby/core/rational/abs_spec.rb10
-rw-r--r--spec/ruby/core/rational/ceil_spec.rb47
-rw-r--r--spec/ruby/core/rational/coerce_spec.rb5
-rw-r--r--spec/ruby/core/rational/comparison_spec.rb86
-rw-r--r--spec/ruby/core/rational/denominator_spec.rb13
-rw-r--r--spec/ruby/core/rational/div_spec.rb47
-rw-r--r--spec/ruby/core/rational/divide_spec.rb67
-rw-r--r--spec/ruby/core/rational/divmod_spec.rb37
-rw-r--r--spec/ruby/core/rational/equal_value_spec.rb32
-rw-r--r--spec/ruby/core/rational/exponent_spec.rb235
-rw-r--r--spec/ruby/core/rational/fdiv_spec.rb4
-rw-r--r--spec/ruby/core/rational/fixtures/rational.rb14
-rw-r--r--spec/ruby/core/rational/floor_spec.rb48
-rw-r--r--spec/ruby/core/rational/hash_spec.rb8
-rw-r--r--spec/ruby/core/rational/inspect_spec.rb13
-rw-r--r--spec/ruby/core/rational/integer_spec.rb10
-rw-r--r--spec/ruby/core/rational/magnitude_spec.rb8
-rw-r--r--spec/ruby/core/rational/marshal_dump_spec.rb4
-rw-r--r--spec/ruby/core/rational/minus_spec.rb50
-rw-r--r--spec/ruby/core/rational/modulo_spec.rb42
-rw-r--r--spec/ruby/core/rational/multiply_spec.rb58
-rw-r--r--spec/ruby/core/rational/numerator_spec.rb9
-rw-r--r--spec/ruby/core/rational/plus_spec.rb44
-rw-r--r--spec/ruby/core/rational/quo_spec.rb6
-rw-r--r--spec/ruby/core/rational/rational_spec.rb6
-rw-r--r--spec/ruby/core/rational/rationalize_spec.rb6
-rw-r--r--spec/ruby/core/rational/remainder_spec.rb4
-rw-r--r--spec/ruby/core/rational/round_spec.rb105
-rw-r--r--spec/ruby/core/rational/shared/arithmetic_exception_in_coerce.rb11
-rw-r--r--spec/ruby/core/rational/to_f_spec.rb15
-rw-r--r--spec/ruby/core/rational/to_i_spec.rb11
-rw-r--r--spec/ruby/core/rational/to_r_spec.rb14
-rw-r--r--spec/ruby/core/rational/to_s_spec.rb13
-rw-r--r--spec/ruby/core/rational/truncate_spec.rb70
-rw-r--r--spec/ruby/core/rational/zero_spec.rb7
-rw-r--r--spec/ruby/core/refinement/append_features_spec.rb19
-rw-r--r--spec/ruby/core/refinement/extend_object_spec.rb21
-rw-r--r--spec/ruby/core/refinement/fixtures/classes.rb10
-rw-r--r--spec/ruby/core/refinement/import_methods_spec.rb287
-rw-r--r--spec/ruby/core/refinement/include_spec.rb13
-rw-r--r--spec/ruby/core/refinement/prepend_features_spec.rb19
-rw-r--r--spec/ruby/core/refinement/prepend_spec.rb13
-rw-r--r--spec/ruby/core/refinement/refined_class_spec.rb33
-rw-r--r--spec/ruby/core/refinement/target_spec.rb15
-rw-r--r--spec/ruby/core/regexp/case_compare_spec.rb26
-rw-r--r--spec/ruby/core/regexp/casefold_spec.rb6
-rw-r--r--spec/ruby/core/regexp/compile_spec.rb19
-rw-r--r--spec/ruby/core/regexp/encoding_spec.rb12
-rw-r--r--spec/ruby/core/regexp/eql_spec.rb7
-rw-r--r--spec/ruby/core/regexp/equal_value_spec.rb33
-rw-r--r--spec/ruby/core/regexp/escape_spec.rb7
-rw-r--r--spec/ruby/core/regexp/fixed_encoding_spec.rb18
-rw-r--r--spec/ruby/core/regexp/hash_spec.rb2
-rw-r--r--spec/ruby/core/regexp/initialize_spec.rb26
-rw-r--r--spec/ruby/core/regexp/inspect_spec.rb2
-rw-r--r--spec/ruby/core/regexp/last_match_spec.rb48
-rw-r--r--spec/ruby/core/regexp/linear_time_spec.rb80
-rw-r--r--spec/ruby/core/regexp/match_spec.rb100
-rw-r--r--spec/ruby/core/regexp/named_captures_spec.rb6
-rw-r--r--spec/ruby/core/regexp/names_spec.rb6
-rw-r--r--spec/ruby/core/regexp/new_spec.rb27
-rw-r--r--spec/ruby/core/regexp/options_spec.rb10
-rw-r--r--spec/ruby/core/regexp/quote_spec.rb43
-rw-r--r--spec/ruby/core/regexp/shared/equal_value.rb31
-rw-r--r--spec/ruby/core/regexp/shared/new.rb321
-rw-r--r--spec/ruby/core/regexp/shared/new_ascii.rb464
-rw-r--r--spec/ruby/core/regexp/shared/new_ascii_8bit.rb553
-rw-r--r--spec/ruby/core/regexp/shared/quote.rb31
-rw-r--r--spec/ruby/core/regexp/source_spec.rb28
-rw-r--r--spec/ruby/core/regexp/timeout_spec.rb33
-rw-r--r--spec/ruby/core/regexp/to_s_spec.rb2
-rw-r--r--spec/ruby/core/regexp/try_convert_spec.rb10
-rw-r--r--spec/ruby/core/regexp/union_spec.rb89
-rw-r--r--spec/ruby/core/set/add_spec.rb44
-rw-r--r--spec/ruby/core/set/append_spec.rb7
-rw-r--r--spec/ruby/core/set/case_compare_spec.rb7
-rw-r--r--spec/ruby/core/set/classify_spec.rb26
-rw-r--r--spec/ruby/core/set/clear_spec.rb16
-rw-r--r--spec/ruby/core/set/collect_spec.rb7
-rw-r--r--spec/ruby/core/set/compare_by_identity_spec.rb153
-rw-r--r--spec/ruby/core/set/comparison_spec.rb26
-rw-r--r--spec/ruby/core/set/constructor_spec.rb14
-rw-r--r--spec/ruby/core/set/delete_if_spec.rb37
-rw-r--r--spec/ruby/core/set/delete_spec.rb36
-rw-r--r--spec/ruby/core/set/difference_spec.rb7
-rw-r--r--spec/ruby/core/set/disjoint_spec.rb22
-rw-r--r--spec/ruby/core/set/divide_spec.rb68
-rw-r--r--spec/ruby/core/set/each_spec.rb26
-rw-r--r--spec/ruby/core/set/empty_spec.rb9
-rw-r--r--spec/ruby/core/set/enumerable/to_set_spec.rb12
-rw-r--r--spec/ruby/core/set/eql_spec.rb22
-rw-r--r--spec/ruby/core/set/equal_value_spec.rb34
-rw-r--r--spec/ruby/core/set/exclusion_spec.rb17
-rw-r--r--spec/ruby/core/set/filter_spec.rb7
-rw-r--r--spec/ruby/core/set/fixtures/set_like.rb30
-rw-r--r--spec/ruby/core/set/flatten_merge_spec.rb24
-rw-r--r--spec/ruby/core/set/flatten_spec.rb49
-rw-r--r--spec/ruby/core/set/gt_spec.rb7
-rw-r--r--spec/ruby/core/set/gte_spec.rb7
-rw-r--r--spec/ruby/core/set/hash_spec.rb19
-rw-r--r--spec/ruby/core/set/include_spec.rb31
-rw-r--r--spec/ruby/core/set/initialize_clone_spec.rb15
-rw-r--r--spec/ruby/core/set/initialize_spec.rb88
-rw-r--r--spec/ruby/core/set/inspect_spec.rb7
-rw-r--r--spec/ruby/core/set/intersect_spec.rb22
-rw-r--r--spec/ruby/core/set/intersection_spec.rb23
-rw-r--r--spec/ruby/core/set/join_spec.rb30
-rw-r--r--spec/ruby/core/set/keep_if_spec.rb37
-rw-r--r--spec/ruby/core/set/length_spec.rb7
-rw-r--r--spec/ruby/core/set/lt_spec.rb7
-rw-r--r--spec/ruby/core/set/lte_spec.rb7
-rw-r--r--spec/ruby/core/set/map_spec.rb22
-rw-r--r--spec/ruby/core/set/member_spec.rb7
-rw-r--r--spec/ruby/core/set/merge_spec.rb29
-rw-r--r--spec/ruby/core/set/minus_spec.rb17
-rw-r--r--spec/ruby/core/set/plus_spec.rb7
-rw-r--r--spec/ruby/core/set/pretty_print_cycle_spec.rb14
-rw-r--r--spec/ruby/core/set/proper_subset_spec.rb35
-rw-r--r--spec/ruby/core/set/proper_superset_spec.rb42
-rw-r--r--spec/ruby/core/set/reject_spec.rb41
-rw-r--r--spec/ruby/core/set/replace_spec.rb24
-rw-r--r--spec/ruby/core/set/select_spec.rb41
-rw-r--r--spec/ruby/core/set/set_spec.rb10
-rw-r--r--spec/ruby/core/set/size_spec.rb8
-rw-r--r--spec/ruby/core/set/sortedset/sortedset_spec.rb13
-rw-r--r--spec/ruby/core/set/subset_spec.rb35
-rw-r--r--spec/ruby/core/set/subtract_spec.rb16
-rw-r--r--spec/ruby/core/set/superset_spec.rb42
-rw-r--r--spec/ruby/core/set/to_a_spec.rb7
-rw-r--r--spec/ruby/core/set/to_s_spec.rb47
-rw-r--r--spec/ruby/core/set/union_spec.rb23
-rw-r--r--spec/ruby/core/signal/fixtures/trap_all.rb15
-rw-r--r--spec/ruby/core/signal/list_spec.rb6
-rw-r--r--spec/ruby/core/signal/signame_spec.rb31
-rw-r--r--spec/ruby/core/signal/trap_spec.rb265
-rw-r--r--spec/ruby/core/sizedqueue/append_spec.rb16
-rw-r--r--spec/ruby/core/sizedqueue/clear_spec.rb6
-rw-r--r--spec/ruby/core/sizedqueue/close_spec.rb6
-rw-r--r--spec/ruby/core/sizedqueue/closed_spec.rb6
-rw-r--r--spec/ruby/core/sizedqueue/deq_spec.rb7
-rw-r--r--spec/ruby/core/sizedqueue/empty_spec.rb6
-rw-r--r--spec/ruby/core/sizedqueue/enq_spec.rb7
-rw-r--r--spec/ruby/core/sizedqueue/freeze_spec.rb6
-rw-r--r--spec/ruby/core/sizedqueue/length_spec.rb7
-rw-r--r--spec/ruby/core/sizedqueue/max_spec.rb10
-rw-r--r--spec/ruby/core/sizedqueue/new_spec.rb6
-rw-r--r--spec/ruby/core/sizedqueue/num_waiting_spec.rb6
-rw-r--r--spec/ruby/core/sizedqueue/pop_spec.rb11
-rw-r--r--spec/ruby/core/sizedqueue/push_spec.rb7
-rw-r--r--spec/ruby/core/sizedqueue/shift_spec.rb7
-rw-r--r--spec/ruby/core/sizedqueue/size_spec.rb6
-rw-r--r--spec/ruby/core/string/allocate_spec.rb6
-rw-r--r--spec/ruby/core/string/append_as_bytes_spec.rb60
-rw-r--r--spec/ruby/core/string/append_spec.rb12
-rw-r--r--spec/ruby/core/string/ascii_only_spec.rb129
-rw-r--r--spec/ruby/core/string/b_spec.rb28
-rw-r--r--spec/ruby/core/string/byteindex_spec.rb298
-rw-r--r--spec/ruby/core/string/byterindex_spec.rb353
-rw-r--r--spec/ruby/core/string/bytes_spec.rb36
-rw-r--r--spec/ruby/core/string/bytesize_spec.rb52
-rw-r--r--spec/ruby/core/string/byteslice_spec.rb28
-rw-r--r--spec/ruby/core/string/bytesplice_spec.rb290
-rw-r--r--spec/ruby/core/string/capitalize_spec.rb191
-rw-r--r--spec/ruby/core/string/case_compare_spec.rb9
-rw-r--r--spec/ruby/core/string/casecmp_spec.rb134
-rw-r--r--spec/ruby/core/string/center_spec.rb86
-rw-r--r--spec/ruby/core/string/chars_spec.rb15
-rw-r--r--spec/ruby/core/string/chilled_string_spec.rb151
-rw-r--r--spec/ruby/core/string/chomp_spec.rb205
-rw-r--r--spec/ruby/core/string/chop_spec.rb77
-rw-r--r--spec/ruby/core/string/chr_spec.rb82
-rw-r--r--spec/ruby/core/string/clear_spec.rb61
-rw-r--r--spec/ruby/core/string/clone_spec.rb13
-rw-r--r--spec/ruby/core/string/codepoints_spec.rb27
-rw-r--r--spec/ruby/core/string/comparison_spec.rb18
-rw-r--r--spec/ruby/core/string/concat_spec.rb37
-rw-r--r--spec/ruby/core/string/count_spec.rb18
-rw-r--r--spec/ruby/core/string/crypt_spec.rb135
-rw-r--r--spec/ruby/core/string/dedup_spec.rb7
-rw-r--r--spec/ruby/core/string/delete_prefix_spec.rb83
-rw-r--r--spec/ruby/core/string/delete_spec.rb42
-rw-r--r--spec/ruby/core/string/delete_suffix_spec.rb83
-rw-r--r--spec/ruby/core/string/downcase_spec.rb184
-rw-r--r--spec/ruby/core/string/dump_spec.rb144
-rw-r--r--spec/ruby/core/string/dup_spec.rb23
-rw-r--r--spec/ruby/core/string/each_byte_spec.rb24
-rw-r--r--spec/ruby/core/string/each_char_spec.rb9
-rw-r--r--spec/ruby/core/string/each_codepoint_spec.rb44
-rw-r--r--spec/ruby/core/string/each_grapheme_cluster_spec.rb16
-rw-r--r--spec/ruby/core/string/each_line_spec.rb12
-rw-r--r--spec/ruby/core/string/element_reference_spec.rb6
-rw-r--r--spec/ruby/core/string/element_set_spec.rb459
-rw-r--r--spec/ruby/core/string/empty_spec.rb14
-rw-r--r--spec/ruby/core/string/encode_spec.rb307
-rw-r--r--spec/ruby/core/string/encoding_spec.rb367
-rw-r--r--spec/ruby/core/string/end_with_spec.rb50
-rw-r--r--spec/ruby/core/string/eql_spec.rb14
-rw-r--r--spec/ruby/core/string/equal_value_spec.rb32
-rw-r--r--spec/ruby/core/string/fixtures/classes.rb13
-rw-r--r--spec/ruby/core/string/fixtures/iso-8859-9-encoding.rb2
-rw-r--r--spec/ruby/core/string/fixtures/to_c.rb5
-rw-r--r--spec/ruby/core/string/fixtures/utf-8-encoding.rb7
-rw-r--r--spec/ruby/core/string/force_encoding_spec.rb93
-rw-r--r--spec/ruby/core/string/freeze_spec.rb8
-rw-r--r--spec/ruby/core/string/getbyte_spec.rb14
-rw-r--r--spec/ruby/core/string/grapheme_clusters_spec.rb14
-rw-r--r--spec/ruby/core/string/gsub_spec.rb251
-rw-r--r--spec/ruby/core/string/hash_spec.rb4
-rw-r--r--spec/ruby/core/string/hex_spec.rb4
-rw-r--r--spec/ruby/core/string/include_spec.rb28
-rw-r--r--spec/ruby/core/string/index_spec.rb102
-rw-r--r--spec/ruby/core/string/initialize_spec.rb10
-rw-r--r--spec/ruby/core/string/insert_spec.rb67
-rw-r--r--spec/ruby/core/string/inspect_spec.rb54
-rw-r--r--spec/ruby/core/string/intern_spec.rb8
-rw-r--r--spec/ruby/core/string/length_spec.rb57
-rw-r--r--spec/ruby/core/string/lines_spec.rb21
-rw-r--r--spec/ruby/core/string/ljust_spec.rb84
-rw-r--r--spec/ruby/core/string/lstrip_spec.rb70
-rw-r--r--spec/ruby/core/string/match_spec.rb80
-rw-r--r--spec/ruby/core/string/modulo_spec.rb290
-rw-r--r--spec/ruby/core/string/multiply_spec.rb8
-rw-r--r--spec/ruby/core/string/new_spec.rb32
-rw-r--r--spec/ruby/core/string/next_spec.rb12
-rw-r--r--spec/ruby/core/string/oct_spec.rb4
-rw-r--r--spec/ruby/core/string/ord_spec.rb45
-rw-r--r--spec/ruby/core/string/partition_spec.rb33
-rw-r--r--spec/ruby/core/string/plus_spec.rb40
-rw-r--r--spec/ruby/core/string/prepend_spec.rb53
-rw-r--r--spec/ruby/core/string/replace_spec.rb6
-rw-r--r--spec/ruby/core/string/reverse_spec.rb60
-rw-r--r--spec/ruby/core/string/rindex_spec.rb64
-rw-r--r--spec/ruby/core/string/rjust_spec.rb84
-rw-r--r--spec/ruby/core/string/rpartition_spec.rb46
-rw-r--r--spec/ruby/core/string/rstrip_spec.rb56
-rw-r--r--spec/ruby/core/string/scan_spec.rb79
-rw-r--r--spec/ruby/core/string/scrub_spec.rb75
-rw-r--r--spec/ruby/core/string/setbyte_spec.rb29
-rw-r--r--spec/ruby/core/string/shared/byte_index_common.rb63
-rw-r--r--spec/ruby/core/string/shared/chars.rb110
-rw-r--r--spec/ruby/core/string/shared/codepoints.rb39
-rw-r--r--spec/ruby/core/string/shared/concat.rb91
-rw-r--r--spec/ruby/core/string/shared/each_char_without_block.rb6
-rw-r--r--spec/ruby/core/string/shared/each_codepoint_without_block.rb33
-rw-r--r--spec/ruby/core/string/shared/each_line.rb120
-rw-r--r--spec/ruby/core/string/shared/each_line_without_block.rb2
-rw-r--r--spec/ruby/core/string/shared/encode.rb259
-rw-r--r--spec/ruby/core/string/shared/eql.rb26
-rw-r--r--spec/ruby/core/string/shared/equal_value.rb29
-rw-r--r--spec/ruby/core/string/shared/grapheme_clusters.rb25
-rw-r--r--spec/ruby/core/string/shared/length.rb28
-rw-r--r--spec/ruby/core/string/shared/partition.rb33
-rw-r--r--spec/ruby/core/string/shared/replace.rb47
-rw-r--r--spec/ruby/core/string/shared/slice.rb264
-rw-r--r--spec/ruby/core/string/shared/strip.rb14
-rw-r--r--spec/ruby/core/string/shared/succ.rb88
-rw-r--r--spec/ruby/core/string/shared/to_a.rb9
-rw-r--r--spec/ruby/core/string/shared/to_s.rb18
-rw-r--r--spec/ruby/core/string/shared/to_sym.rb63
-rw-r--r--spec/ruby/core/string/size_spec.rb8
-rw-r--r--spec/ruby/core/string/slice_spec.rb279
-rw-r--r--spec/ruby/core/string/split_spec.rb351
-rw-r--r--spec/ruby/core/string/squeeze_spec.rb46
-rw-r--r--spec/ruby/core/string/start_with_spec.rb47
-rw-r--r--spec/ruby/core/string/string_spec.rb2
-rw-r--r--spec/ruby/core/string/strip_spec.rb48
-rw-r--r--spec/ruby/core/string/sub_spec.rb197
-rw-r--r--spec/ruby/core/string/succ_spec.rb89
-rw-r--r--spec/ruby/core/string/sum_spec.rb4
-rw-r--r--spec/ruby/core/string/swapcase_spec.rb177
-rw-r--r--spec/ruby/core/string/to_c_spec.rb118
-rw-r--r--spec/ruby/core/string/to_f_spec.rb107
-rw-r--r--spec/ruby/core/string/to_i_spec.rb40
-rw-r--r--spec/ruby/core/string/to_r_spec.rb10
-rw-r--r--spec/ruby/core/string/to_s_spec.rb17
-rw-r--r--spec/ruby/core/string/to_str_spec.rb8
-rw-r--r--spec/ruby/core/string/to_sym_spec.rb75
-rw-r--r--spec/ruby/core/string/tr_s_spec.rb105
-rw-r--r--spec/ruby/core/string/tr_spec.rb81
-rw-r--r--spec/ruby/core/string/try_convert_spec.rb20
-rw-r--r--spec/ruby/core/string/uminus_spec.rb62
-rw-r--r--spec/ruby/core/string/undump_spec.rb441
-rw-r--r--spec/ruby/core/string/unicode_normalize_spec.rb19
-rw-r--r--spec/ruby/core/string/unicode_normalized_spec.rb31
-rw-r--r--spec/ruby/core/string/unpack/a_spec.rb19
-rw-r--r--spec/ruby/core/string/unpack/at_spec.rb10
-rw-r--r--spec/ruby/core/string/unpack/b_spec.rb31
-rw-r--r--spec/ruby/core/string/unpack/c_spec.rb16
-rw-r--r--spec/ruby/core/string/unpack/carret_spec.rb43
-rw-r--r--spec/ruby/core/string/unpack/comment_spec.rb6
-rw-r--r--spec/ruby/core/string/unpack/d_spec.rb8
-rw-r--r--spec/ruby/core/string/unpack/e_spec.rb8
-rw-r--r--spec/ruby/core/string/unpack/f_spec.rb8
-rw-r--r--spec/ruby/core/string/unpack/g_spec.rb8
-rw-r--r--spec/ruby/core/string/unpack/h_spec.rb31
-rw-r--r--spec/ruby/core/string/unpack/i_spec.rb8
-rw-r--r--spec/ruby/core/string/unpack/j_spec.rb427
-rw-r--r--spec/ruby/core/string/unpack/l_spec.rb24
-rw-r--r--spec/ruby/core/string/unpack/m_spec.rb30
-rw-r--r--spec/ruby/core/string/unpack/n_spec.rb8
-rw-r--r--spec/ruby/core/string/unpack/p_spec.rb41
-rw-r--r--spec/ruby/core/string/unpack/percent_spec.rb4
-rw-r--r--spec/ruby/core/string/unpack/q_spec.rb8
-rw-r--r--spec/ruby/core/string/unpack/r_spec.rb85
-rw-r--r--spec/ruby/core/string/unpack/s_spec.rb8
-rw-r--r--spec/ruby/core/string/unpack/shared/basic.rb18
-rw-r--r--spec/ruby/core/string/unpack/shared/float.rb36
-rw-r--r--spec/ruby/core/string/unpack/shared/integer.rb40
-rw-r--r--spec/ruby/core/string/unpack/shared/taint.rb2
-rw-r--r--spec/ruby/core/string/unpack/shared/unicode.rb6
-rw-r--r--spec/ruby/core/string/unpack/u_spec.rb23
-rw-r--r--spec/ruby/core/string/unpack/v_spec.rb8
-rw-r--r--spec/ruby/core/string/unpack/w_spec.rb24
-rw-r--r--spec/ruby/core/string/unpack/x_spec.rb14
-rw-r--r--spec/ruby/core/string/unpack/z_spec.rb17
-rw-r--r--spec/ruby/core/string/unpack1_spec.rb67
-rw-r--r--spec/ruby/core/string/unpack_spec.rb46
-rw-r--r--spec/ruby/core/string/upcase_spec.rb173
-rw-r--r--spec/ruby/core/string/uplus_spec.rb58
-rw-r--r--spec/ruby/core/string/upto_spec.rb26
-rw-r--r--spec/ruby/core/string/valid_encoding/utf_8_spec.rb214
-rw-r--r--spec/ruby/core/string/valid_encoding_spec.rb244
-rw-r--r--spec/ruby/core/struct/clone_spec.rb7
-rw-r--r--spec/ruby/core/struct/constants_spec.rb13
-rw-r--r--spec/ruby/core/struct/deconstruct_keys_spec.rb130
-rw-r--r--spec/ruby/core/struct/deconstruct_spec.rb7
-rw-r--r--spec/ruby/core/struct/dig_spec.rb72
-rw-r--r--spec/ruby/core/struct/dup_spec.rb7
-rw-r--r--spec/ruby/core/struct/each_pair_spec.rb12
-rw-r--r--spec/ruby/core/struct/each_spec.rb10
-rw-r--r--spec/ruby/core/struct/element_reference_spec.rb18
-rw-r--r--spec/ruby/core/struct/element_set_spec.rb19
-rw-r--r--spec/ruby/core/struct/eql_spec.rb10
-rw-r--r--spec/ruby/core/struct/equal_value_spec.rb8
-rw-r--r--spec/ruby/core/struct/filter_spec.rb8
-rw-r--r--spec/ruby/core/struct/fixtures/classes.rb9
-rw-r--r--spec/ruby/core/struct/hash_spec.rb30
-rw-r--r--spec/ruby/core/struct/initialize_spec.rb37
-rw-r--r--spec/ruby/core/struct/inspect_spec.rb15
-rw-r--r--spec/ruby/core/struct/instance_variable_get_spec.rb16
-rw-r--r--spec/ruby/core/struct/instance_variables_spec.rb4
-rw-r--r--spec/ruby/core/struct/keyword_init_spec.rb45
-rw-r--r--spec/ruby/core/struct/length_spec.rb12
-rw-r--r--spec/ruby/core/struct/members_spec.rb18
-rw-r--r--spec/ruby/core/struct/new_spec.rb182
-rw-r--r--spec/ruby/core/struct/select_spec.rb21
-rw-r--r--spec/ruby/core/struct/shared/dup.rb9
-rw-r--r--spec/ruby/core/struct/shared/equal_value.rb7
-rw-r--r--spec/ruby/core/struct/shared/inspect.rb5
-rw-r--r--spec/ruby/core/struct/size_spec.rb11
-rw-r--r--spec/ruby/core/struct/struct_spec.rb13
-rw-r--r--spec/ruby/core/struct/tms/cstime_spec.rb9
-rw-r--r--spec/ruby/core/struct/tms/cutime_spec.rb9
-rw-r--r--spec/ruby/core/struct/tms/element_reference_spec.rb5
-rw-r--r--spec/ruby/core/struct/tms/members_spec.rb5
-rw-r--r--spec/ruby/core/struct/tms/new_spec.rb5
-rw-r--r--spec/ruby/core/struct/tms/stime_spec.rb9
-rw-r--r--spec/ruby/core/struct/tms/utime_spec.rb9
-rw-r--r--spec/ruby/core/struct/to_a_spec.rb6
-rw-r--r--spec/ruby/core/struct/to_h_spec.rb57
-rw-r--r--spec/ruby/core/struct/to_s_spec.rb43
-rw-r--r--spec/ruby/core/struct/values_at_spec.rb59
-rw-r--r--spec/ruby/core/struct/values_spec.rb11
-rw-r--r--spec/ruby/core/symbol/all_symbols_spec.rb17
-rw-r--r--spec/ruby/core/symbol/capitalize_spec.rb25
-rw-r--r--spec/ruby/core/symbol/case_compare_spec.rb10
-rw-r--r--spec/ruby/core/symbol/casecmp_spec.rb154
-rw-r--r--spec/ruby/core/symbol/comparison_spec.rb10
-rw-r--r--spec/ruby/core/symbol/downcase_spec.rb18
-rw-r--r--spec/ruby/core/symbol/dup_spec.rb10
-rw-r--r--spec/ruby/core/symbol/element_reference_spec.rb263
-rw-r--r--spec/ruby/core/symbol/empty_spec.rb6
-rw-r--r--spec/ruby/core/symbol/encoding_spec.rb2
-rw-r--r--spec/ruby/core/symbol/end_with_spec.rb8
-rw-r--r--spec/ruby/core/symbol/equal_value_spec.rb2
-rw-r--r--spec/ruby/core/symbol/id2name_spec.rb7
-rw-r--r--spec/ruby/core/symbol/inspect_spec.rb36
-rw-r--r--spec/ruby/core/symbol/intern_spec.rb10
-rw-r--r--spec/ruby/core/symbol/length_spec.rb23
-rw-r--r--spec/ruby/core/symbol/match_spec.rb77
-rw-r--r--spec/ruby/core/symbol/name_spec.rb17
-rw-r--r--spec/ruby/core/symbol/next_spec.rb7
-rw-r--r--spec/ruby/core/symbol/shared/id2name.rb9
-rw-r--r--spec/ruby/core/symbol/shared/length.rb23
-rw-r--r--spec/ruby/core/symbol/shared/slice.rb278
-rw-r--r--spec/ruby/core/symbol/shared/succ.rb18
-rw-r--r--spec/ruby/core/symbol/size_spec.rb7
-rw-r--r--spec/ruby/core/symbol/slice_spec.rb7
-rw-r--r--spec/ruby/core/symbol/start_with_spec.rb8
-rw-r--r--spec/ruby/core/symbol/succ_spec.rb18
-rw-r--r--spec/ruby/core/symbol/swapcase_spec.rb22
-rw-r--r--spec/ruby/core/symbol/symbol_spec.rb10
-rw-r--r--spec/ruby/core/symbol/to_proc_spec.rb61
-rw-r--r--spec/ruby/core/symbol/to_s_spec.rb32
-rw-r--r--spec/ruby/core/symbol/to_sym_spec.rb4
-rw-r--r--spec/ruby/core/symbol/upcase_spec.rb18
-rw-r--r--spec/ruby/core/systemexit/initialize_spec.rb3
-rw-r--r--spec/ruby/core/systemexit/success_spec.rb6
-rw-r--r--spec/ruby/core/thread/abort_on_exception_spec.rb16
-rw-r--r--spec/ruby/core/thread/add_trace_func_spec.rb2
-rw-r--r--spec/ruby/core/thread/alive_spec.rb24
-rw-r--r--spec/ruby/core/thread/allocate_spec.rb6
-rw-r--r--spec/ruby/core/thread/backtrace/limit_spec.rb13
-rw-r--r--spec/ruby/core/thread/backtrace/location/absolute_path_spec.rb85
-rw-r--r--spec/ruby/core/thread/backtrace/location/base_label_spec.rb41
-rw-r--r--spec/ruby/core/thread/backtrace/location/fixtures/absolute_path.rb4
-rw-r--r--spec/ruby/core/thread/backtrace/location/fixtures/absolute_path_main.rb2
-rw-r--r--spec/ruby/core/thread/backtrace/location/fixtures/absolute_path_method_added.rb10
-rw-r--r--spec/ruby/core/thread/backtrace/location/fixtures/classes.rb122
-rw-r--r--spec/ruby/core/thread/backtrace/location/fixtures/locations_in_main.rb5
-rw-r--r--spec/ruby/core/thread/backtrace/location/fixtures/locations_in_required.rb3
-rw-r--r--spec/ruby/core/thread/backtrace/location/fixtures/main.rb4
-rw-r--r--spec/ruby/core/thread/backtrace/location/fixtures/path.rb2
-rw-r--r--spec/ruby/core/thread/backtrace/location/fixtures/subdir/absolute_path_main_chdir.rb11
-rw-r--r--spec/ruby/core/thread/backtrace/location/fixtures/subdir/sibling.rb1
-rw-r--r--spec/ruby/core/thread/backtrace/location/inspect_spec.rb6
-rw-r--r--spec/ruby/core/thread/backtrace/location/label_spec.rb219
-rw-r--r--spec/ruby/core/thread/backtrace/location/lineno_spec.rb16
-rw-r--r--spec/ruby/core/thread/backtrace/location/path_spec.rb47
-rw-r--r--spec/ruby/core/thread/backtrace/location/to_s_spec.rb6
-rw-r--r--spec/ruby/core/thread/backtrace_locations_spec.rb79
-rw-r--r--spec/ruby/core/thread/backtrace_spec.rb48
-rw-r--r--spec/ruby/core/thread/current_spec.rb26
-rw-r--r--spec/ruby/core/thread/each_caller_location_spec.rb47
-rw-r--r--spec/ruby/core/thread/element_reference_spec.rb19
-rw-r--r--spec/ruby/core/thread/element_set_spec.rb48
-rw-r--r--spec/ruby/core/thread/exclusive_spec.rb18
-rw-r--r--spec/ruby/core/thread/exit_spec.rb13
-rw-r--r--spec/ruby/core/thread/fetch_spec.rb66
-rw-r--r--spec/ruby/core/thread/fixtures/classes.rb37
-rw-r--r--spec/ruby/core/thread/fork_spec.rb8
-rw-r--r--spec/ruby/core/thread/group_spec.rb17
-rw-r--r--spec/ruby/core/thread/handle_interrupt_spec.rb125
-rw-r--r--spec/ruby/core/thread/ignore_deadlock_spec.rb19
-rw-r--r--spec/ruby/core/thread/initialize_spec.rb8
-rw-r--r--spec/ruby/core/thread/inspect_spec.rb43
-rw-r--r--spec/ruby/core/thread/join_spec.rb41
-rw-r--r--spec/ruby/core/thread/key_spec.rb27
-rw-r--r--spec/ruby/core/thread/keys_spec.rb16
-rw-r--r--spec/ruby/core/thread/kill_spec.rb241
-rw-r--r--spec/ruby/core/thread/list_spec.rb39
-rw-r--r--spec/ruby/core/thread/main_spec.rb4
-rw-r--r--spec/ruby/core/thread/name_spec.rb106
-rw-r--r--spec/ruby/core/thread/native_thread_id_spec.rb31
-rw-r--r--spec/ruby/core/thread/new_spec.rb45
-rw-r--r--spec/ruby/core/thread/pass_spec.rb4
-rw-r--r--spec/ruby/core/thread/pending_interrupt_spec.rb32
-rw-r--r--spec/ruby/core/thread/priority_spec.rb32
-rw-r--r--spec/ruby/core/thread/raise_spec.rb128
-rw-r--r--spec/ruby/core/thread/report_on_exception_spec.rb215
-rw-r--r--spec/ruby/core/thread/run_spec.rb7
-rw-r--r--spec/ruby/core/thread/set_trace_func_spec.rb2
-rw-r--r--spec/ruby/core/thread/shared/exit.rb176
-rw-r--r--spec/ruby/core/thread/shared/start.rb41
-rw-r--r--spec/ruby/core/thread/shared/wakeup.rb5
-rw-r--r--spec/ruby/core/thread/start_spec.rb44
-rw-r--r--spec/ruby/core/thread/status_spec.rb4
-rw-r--r--spec/ruby/core/thread/stop_spec.rb24
-rw-r--r--spec/ruby/core/thread/terminate_spec.rb8
-rw-r--r--spec/ruby/core/thread/thread_variable_get_spec.rb47
-rw-r--r--spec/ruby/core/thread/thread_variable_set_spec.rb46
-rw-r--r--spec/ruby/core/thread/thread_variable_spec.rb49
-rw-r--r--spec/ruby/core/thread/thread_variables_spec.rb30
-rw-r--r--spec/ruby/core/thread/to_s_spec.rb54
-rw-r--r--spec/ruby/core/thread/value_spec.rb16
-rw-r--r--spec/ruby/core/thread/wakeup_spec.rb6
-rw-r--r--spec/ruby/core/threadgroup/add_spec.rb47
-rw-r--r--spec/ruby/core/threadgroup/default_spec.rb4
-rw-r--r--spec/ruby/core/threadgroup/enclose_spec.rb15
-rw-r--r--spec/ruby/core/threadgroup/enclosed_spec.rb6
-rw-r--r--spec/ruby/core/threadgroup/fixtures/classes.rb6
-rw-r--r--spec/ruby/core/threadgroup/list_spec.rb17
-rw-r--r--spec/ruby/core/time/_dump_spec.rb13
-rw-r--r--spec/ruby/core/time/_load_spec.rb17
-rw-r--r--spec/ruby/core/time/asctime_spec.rb8
-rw-r--r--spec/ruby/core/time/at_spec.rb203
-rw-r--r--spec/ruby/core/time/ceil_spec.rb44
-rw-r--r--spec/ruby/core/time/comparison_spec.rb40
-rw-r--r--spec/ruby/core/time/ctime_spec.rb7
-rw-r--r--spec/ruby/core/time/day_spec.rb17
-rw-r--r--spec/ruby/core/time/deconstruct_keys_spec.rb43
-rw-r--r--spec/ruby/core/time/dst_spec.rb10
-rw-r--r--spec/ruby/core/time/dup_spec.rb20
-rw-r--r--spec/ruby/core/time/eql_spec.rb18
-rw-r--r--spec/ruby/core/time/fixtures/classes.rb93
-rw-r--r--spec/ruby/core/time/floor_spec.rb36
-rw-r--r--spec/ruby/core/time/friday_spec.rb6
-rw-r--r--spec/ruby/core/time/getgm_spec.rb7
-rw-r--r--spec/ruby/core/time/getlocal_spec.rb122
-rw-r--r--spec/ruby/core/time/getutc_spec.rb11
-rw-r--r--spec/ruby/core/time/gm_spec.rb11
-rw-r--r--spec/ruby/core/time/gmt_offset_spec.rb7
-rw-r--r--spec/ruby/core/time/gmt_spec.rb7
-rw-r--r--spec/ruby/core/time/gmtime_spec.rb7
-rw-r--r--spec/ruby/core/time/gmtoff_spec.rb7
-rw-r--r--spec/ruby/core/time/hash_spec.rb6
-rw-r--r--spec/ruby/core/time/hour_spec.rb2
-rw-r--r--spec/ruby/core/time/inspect_spec.rb31
-rw-r--r--spec/ruby/core/time/isdst_spec.rb7
-rw-r--r--spec/ruby/core/time/iso8601_spec.rb33
-rw-r--r--spec/ruby/core/time/local_spec.rb16
-rw-r--r--spec/ruby/core/time/localtime_spec.rb98
-rw-r--r--spec/ruby/core/time/mday_spec.rb7
-rw-r--r--spec/ruby/core/time/min_spec.rb2
-rw-r--r--spec/ruby/core/time/minus_spec.rb40
-rw-r--r--spec/ruby/core/time/mktime_spec.rb12
-rw-r--r--spec/ruby/core/time/mon_spec.rb7
-rw-r--r--spec/ruby/core/time/monday_spec.rb6
-rw-r--r--spec/ruby/core/time/month_spec.rb17
-rw-r--r--spec/ruby/core/time/new_spec.rb678
-rw-r--r--spec/ruby/core/time/now_spec.rb181
-rw-r--r--spec/ruby/core/time/nsec_spec.rb6
-rw-r--r--spec/ruby/core/time/plus_spec.rb40
-rw-r--r--spec/ruby/core/time/round_spec.rb8
-rw-r--r--spec/ruby/core/time/saturday_spec.rb6
-rw-r--r--spec/ruby/core/time/sec_spec.rb2
-rw-r--r--spec/ruby/core/time/shared/asctime.rb6
-rw-r--r--spec/ruby/core/time/shared/day.rb15
-rw-r--r--spec/ruby/core/time/shared/getgm.rb9
-rw-r--r--spec/ruby/core/time/shared/gm.rb22
-rw-r--r--spec/ruby/core/time/shared/gmt_offset.rb53
-rw-r--r--spec/ruby/core/time/shared/gmtime.rb33
-rw-r--r--spec/ruby/core/time/shared/inspect.rb6
-rw-r--r--spec/ruby/core/time/shared/isdst.rb8
-rw-r--r--spec/ruby/core/time/shared/local.rb11
-rw-r--r--spec/ruby/core/time/shared/month.rb15
-rw-r--r--spec/ruby/core/time/shared/now.rb21
-rw-r--r--spec/ruby/core/time/shared/time_params.rb63
-rw-r--r--spec/ruby/core/time/shared/to_i.rb9
-rw-r--r--spec/ruby/core/time/strftime_spec.rb55
-rw-r--r--spec/ruby/core/time/subsec_spec.rb16
-rw-r--r--spec/ruby/core/time/succ_spec.rb19
-rw-r--r--spec/ruby/core/time/sunday_spec.rb6
-rw-r--r--spec/ruby/core/time/thursday_spec.rb6
-rw-r--r--spec/ruby/core/time/time_spec.rb2
-rw-r--r--spec/ruby/core/time/to_a_spec.rb2
-rw-r--r--spec/ruby/core/time/to_f_spec.rb2
-rw-r--r--spec/ruby/core/time/to_i_spec.rb18
-rw-r--r--spec/ruby/core/time/to_r_spec.rb6
-rw-r--r--spec/ruby/core/time/to_s_spec.rb4
-rw-r--r--spec/ruby/core/time/tuesday_spec.rb6
-rw-r--r--spec/ruby/core/time/tv_nsec_spec.rb6
-rw-r--r--spec/ruby/core/time/tv_sec_spec.rb7
-rw-r--r--spec/ruby/core/time/tv_usec_spec.rb6
-rw-r--r--spec/ruby/core/time/usec_spec.rb6
-rw-r--r--spec/ruby/core/time/utc_offset_spec.rb61
-rw-r--r--spec/ruby/core/time/utc_spec.rb168
-rw-r--r--spec/ruby/core/time/wday_spec.rb2
-rw-r--r--spec/ruby/core/time/wednesday_spec.rb6
-rw-r--r--spec/ruby/core/time/xmlschema_spec.rb9
-rw-r--r--spec/ruby/core/time/yday_spec.rb15
-rw-r--r--spec/ruby/core/time/year_spec.rb2
-rw-r--r--spec/ruby/core/time/zone_spec.rb33
-rw-r--r--spec/ruby/core/tracepoint/allow_reentry_spec.rb30
-rw-r--r--spec/ruby/core/tracepoint/binding_spec.rb21
-rw-r--r--spec/ruby/core/tracepoint/callee_id_spec.rb28
-rw-r--r--spec/ruby/core/tracepoint/defined_class_spec.rb27
-rw-r--r--spec/ruby/core/tracepoint/disable_spec.rb76
-rw-r--r--spec/ruby/core/tracepoint/enable_spec.rb543
-rw-r--r--spec/ruby/core/tracepoint/enabled_spec.rb15
-rw-r--r--spec/ruby/core/tracepoint/eval_script_spec.rb23
-rw-r--r--spec/ruby/core/tracepoint/event_spec.rb22
-rw-r--r--spec/ruby/core/tracepoint/fixtures/classes.rb34
-rw-r--r--spec/ruby/core/tracepoint/inspect_spec.rb141
-rw-r--r--spec/ruby/core/tracepoint/lineno_spec.rb20
-rw-r--r--spec/ruby/core/tracepoint/method_id_spec.rb15
-rw-r--r--spec/ruby/core/tracepoint/new_spec.rb72
-rw-r--r--spec/ruby/core/tracepoint/parameters_spec.rb28
-rw-r--r--spec/ruby/core/tracepoint/path_spec.rb26
-rw-r--r--spec/ruby/core/tracepoint/raised_exception_spec.rb36
-rw-r--r--spec/ruby/core/tracepoint/return_value_spec.rb17
-rw-r--r--spec/ruby/core/tracepoint/self_spec.rb26
-rw-r--r--spec/ruby/core/tracepoint/trace_spec.rb10
-rw-r--r--spec/ruby/core/true/and_spec.rb2
-rw-r--r--spec/ruby/core/true/case_compare_spec.rb13
-rw-r--r--spec/ruby/core/true/dup_spec.rb10
-rw-r--r--spec/ruby/core/true/inspect_spec.rb6
-rw-r--r--spec/ruby/core/true/or_spec.rb2
-rw-r--r--spec/ruby/core/true/singleton_method_spec.rb13
-rw-r--r--spec/ruby/core/true/to_s_spec.rb10
-rw-r--r--spec/ruby/core/true/trueclass_spec.rb10
-rw-r--r--spec/ruby/core/true/xor_spec.rb2
-rw-r--r--spec/ruby/core/unboundmethod/arity_spec.rb2
-rw-r--r--spec/ruby/core/unboundmethod/bind_call_spec.rb58
-rw-r--r--spec/ruby/core/unboundmethod/bind_spec.rb34
-rw-r--r--spec/ruby/core/unboundmethod/clone_spec.rb15
-rw-r--r--spec/ruby/core/unboundmethod/dup_spec.rb15
-rw-r--r--spec/ruby/core/unboundmethod/eql_spec.rb6
-rw-r--r--spec/ruby/core/unboundmethod/equal_value_spec.rb90
-rw-r--r--spec/ruby/core/unboundmethod/fixtures/classes.rb38
-rw-r--r--spec/ruby/core/unboundmethod/hash_spec.rb13
-rw-r--r--spec/ruby/core/unboundmethod/inspect_spec.rb8
-rw-r--r--spec/ruby/core/unboundmethod/name_spec.rb4
-rw-r--r--spec/ruby/core/unboundmethod/original_name_spec.rb59
-rw-r--r--spec/ruby/core/unboundmethod/owner_spec.rb9
-rw-r--r--spec/ruby/core/unboundmethod/parameters_spec.rb2
-rw-r--r--spec/ruby/core/unboundmethod/private_spec.rb9
-rw-r--r--spec/ruby/core/unboundmethod/protected_spec.rb9
-rw-r--r--spec/ruby/core/unboundmethod/public_spec.rb9
-rw-r--r--spec/ruby/core/unboundmethod/shared/dup.rb32
-rw-r--r--spec/ruby/core/unboundmethod/shared/to_s.rb25
-rw-r--r--spec/ruby/core/unboundmethod/source_location_spec.rb19
-rw-r--r--spec/ruby/core/unboundmethod/super_method_spec.rb25
-rw-r--r--spec/ruby/core/unboundmethod/to_s_spec.rb37
-rw-r--r--spec/ruby/core/warning/categories_spec.rb12
-rw-r--r--spec/ruby/core/warning/element_reference_spec.rb27
-rw-r--r--spec/ruby/core/warning/element_set_spec.rb39
-rw-r--r--spec/ruby/core/warning/performance_warning_spec.rb28
-rw-r--r--spec/ruby/core/warning/warn_spec.rb201
-rw-r--r--spec/ruby/default.mspec30
-rw-r--r--spec/ruby/fixtures/class.rb8
-rw-r--r--spec/ruby/fixtures/code/a/load_fixture.dylib1
-rw-r--r--spec/ruby/fixtures/code/c/load_fixture.rb1
-rw-r--r--spec/ruby/fixtures/code/concurrent.rb2
-rw-r--r--spec/ruby/fixtures/code/concurrent_require_fixture.rb4
-rw-r--r--spec/ruby/fixtures/code/d/load_fixture.rb.rb1
-rw-r--r--spec/ruby/fixtures/code/load_fixture.dylib1
-rw-r--r--spec/ruby/fixtures/code/load_fixture.ext.dylib1
-rw-r--r--spec/ruby/fixtures/code/load_fixture_and__FILE__.rb1
-rw-r--r--spec/ruby/fixtures/code/load_wrap_fixture.rb12
-rw-r--r--spec/ruby/fixtures/code/recursive_require_fixture.rb2
-rw-r--r--spec/ruby/fixtures/code/wrap_fixture.rb3
-rw-r--r--spec/ruby/fixtures/code_loading.rb15
-rw-r--r--spec/ruby/fixtures/constants.rb42
-rw-r--r--spec/ruby/fixtures/io.rb12
-rw-r--r--spec/ruby/fixtures/rational.rb11
-rw-r--r--spec/ruby/language/BEGIN_spec.rb13
-rw-r--r--spec/ruby/language/END_spec.rb33
-rw-r--r--spec/ruby/language/README2
-rw-r--r--spec/ruby/language/alias_spec.rb82
-rw-r--r--spec/ruby/language/and_spec.rb18
-rw-r--r--spec/ruby/language/array_spec.rb29
-rw-r--r--spec/ruby/language/assignments_spec.rb582
-rw-r--r--spec/ruby/language/block_spec.rb503
-rw-r--r--spec/ruby/language/break_spec.rb77
-rw-r--r--spec/ruby/language/case_spec.rb435
-rw-r--r--spec/ruby/language/class_spec.rb152
-rw-r--r--spec/ruby/language/class_variable_spec.rb48
-rw-r--r--spec/ruby/language/comment_spec.rb13
-rw-r--r--spec/ruby/language/constants_spec.rb365
-rw-r--r--spec/ruby/language/def_spec.rb250
-rw-r--r--spec/ruby/language/defined_spec.rb498
-rw-r--r--spec/ruby/language/delegation_spec.rb176
-rw-r--r--spec/ruby/language/encoding_spec.rb20
-rw-r--r--spec/ruby/language/ensure_spec.rb292
-rw-r--r--spec/ruby/language/execution_spec.rb80
-rw-r--r--spec/ruby/language/file_spec.rb24
-rw-r--r--spec/ruby/language/fixtures/array.rb21
-rw-r--r--spec/ruby/language/fixtures/begin_file.rb3
-rw-r--r--spec/ruby/language/fixtures/block.rb4
-rw-r--r--spec/ruby/language/fixtures/break.rb38
-rw-r--r--spec/ruby/language/fixtures/break_lambda_toplevel.rb2
-rw-r--r--spec/ruby/language/fixtures/break_lambda_toplevel_block.rb2
-rw-r--r--spec/ruby/language/fixtures/break_lambda_toplevel_method.rb2
-rw-r--r--spec/ruby/language/fixtures/bytes_magic_comment.rb2
-rw-r--r--spec/ruby/language/fixtures/case_magic_comment.rb2
-rw-r--r--spec/ruby/language/fixtures/class_with_class_variable.rb9
-rw-r--r--spec/ruby/language/fixtures/constant_visibility.rb18
-rw-r--r--spec/ruby/language/fixtures/def.rb6
-rw-r--r--spec/ruby/language/fixtures/defined.rb41
-rw-r--r--spec/ruby/language/fixtures/delegation.rb15
-rw-r--r--spec/ruby/language/fixtures/emacs_magic_comment.rb2
-rw-r--r--spec/ruby/language/fixtures/ensure.rb51
-rw-r--r--spec/ruby/language/fixtures/for_scope.rb15
-rw-r--r--spec/ruby/language/fixtures/freeze_magic_comment_across_files.rb3
-rw-r--r--spec/ruby/language/fixtures/freeze_magic_comment_across_files_diff_enc.rb3
-rw-r--r--spec/ruby/language/fixtures/freeze_magic_comment_across_files_no_comment.rb3
-rw-r--r--spec/ruby/language/fixtures/freeze_magic_comment_one_literal.rb4
-rw-r--r--spec/ruby/language/fixtures/freeze_magic_comment_required.rb2
-rw-r--r--spec/ruby/language/fixtures/freeze_magic_comment_required_diff_enc.rbbin181 -> 107 bytes-rw-r--r--spec/ruby/language/fixtures/freeze_magic_comment_required_no_comment.rb2
-rw-r--r--spec/ruby/language/fixtures/freeze_magic_comment_two_literals.rb2
-rw-r--r--spec/ruby/language/fixtures/hash_strings_ascii8bit.rb7
-rw-r--r--spec/ruby/language/fixtures/hash_strings_binary.rb7
-rw-r--r--spec/ruby/language/fixtures/magic_comment.rb2
-rw-r--r--spec/ruby/language/fixtures/metaclass.rb1
-rw-r--r--spec/ruby/language/fixtures/module.rb9
-rw-r--r--spec/ruby/language/fixtures/no_magic_comment.rb1
-rw-r--r--spec/ruby/language/fixtures/print_magic_comment_result_at_exit.rb3
-rw-r--r--spec/ruby/language/fixtures/private.rb26
-rw-r--r--spec/ruby/language/fixtures/rescue.rb4
-rw-r--r--spec/ruby/language/fixtures/rescue/top_level.rb7
-rw-r--r--spec/ruby/language/fixtures/rescue_captures.rb107
-rw-r--r--spec/ruby/language/fixtures/return.rb8
-rw-r--r--spec/ruby/language/fixtures/second_line_magic_comment.rb3
-rw-r--r--spec/ruby/language/fixtures/second_token_magic_comment.rb2
-rw-r--r--spec/ruby/language/fixtures/send.rb19
-rwxr-xr-xspec/ruby/language/fixtures/shebang_magic_comment.rb3
-rw-r--r--spec/ruby/language/fixtures/squiggly_heredoc.rb32
-rw-r--r--spec/ruby/language/fixtures/super.rb150
-rw-r--r--spec/ruby/language/fixtures/utf16-be-nobom.rbbin0 -> 68 bytes-rw-r--r--spec/ruby/language/fixtures/utf16-le-nobom.rbbin0 -> 69 bytes-rw-r--r--spec/ruby/language/fixtures/utf8-bom.rb2
-rw-r--r--spec/ruby/language/fixtures/utf8-nobom.rb2
-rw-r--r--spec/ruby/language/fixtures/variables.rb72
-rw-r--r--spec/ruby/language/fixtures/vim_magic_comment.rb2
-rw-r--r--spec/ruby/language/fixtures/yield.rb4
-rw-r--r--spec/ruby/language/for_spec.rb219
-rw-r--r--spec/ruby/language/hash_spec.rb215
-rw-r--r--spec/ruby/language/heredoc_spec.rb94
-rw-r--r--spec/ruby/language/if_spec.rb83
-rw-r--r--spec/ruby/language/it_parameter_spec.rb108
-rw-r--r--spec/ruby/language/keyword_arguments_spec.rb398
-rw-r--r--spec/ruby/language/lambda_spec.rb198
-rw-r--r--spec/ruby/language/line_spec.rb8
-rw-r--r--spec/ruby/language/loop_spec.rb4
-rw-r--r--spec/ruby/language/magic_comment_spec.rb111
-rw-r--r--spec/ruby/language/match_spec.rb19
-rw-r--r--spec/ruby/language/metaclass_spec.rb34
-rw-r--r--spec/ruby/language/method_spec.rb775
-rw-r--r--spec/ruby/language/module_spec.rb74
-rw-r--r--spec/ruby/language/next_spec.rb18
-rw-r--r--spec/ruby/language/not_spec.rb34
-rw-r--r--spec/ruby/language/numbered_parameters_spec.rb113
-rw-r--r--spec/ruby/language/numbers_spec.rb18
-rw-r--r--spec/ruby/language/optional_assignments_spec.rb530
-rw-r--r--spec/ruby/language/or_spec.rb34
-rw-r--r--spec/ruby/language/order_spec.rb2
-rw-r--r--spec/ruby/language/pattern_matching_spec.rb1310
-rw-r--r--spec/ruby/language/precedence_spec.rb117
-rw-r--r--spec/ruby/language/predefined/data_spec.rb21
-rw-r--r--spec/ruby/language/predefined/fixtures/data2.rb3
-rw-r--r--spec/ruby/language/predefined/fixtures/data3.rb3
-rw-r--r--spec/ruby/language/predefined/fixtures/data_offset.rb12
-rw-r--r--spec/ruby/language/predefined/fixtures/empty_data.rb3
-rw-r--r--spec/ruby/language/predefined/fixtures/toplevel_binding_dynamic.rb4
-rw-r--r--spec/ruby/language/predefined/fixtures/toplevel_binding_dynamic_required.rb2
-rw-r--r--spec/ruby/language/predefined/fixtures/toplevel_binding_id.rb4
-rw-r--r--spec/ruby/language/predefined/fixtures/toplevel_binding_id_required.rb1
-rw-r--r--spec/ruby/language/predefined/fixtures/toplevel_binding_required_before.rb2
-rw-r--r--spec/ruby/language/predefined/fixtures/toplevel_binding_values.rb9
-rw-r--r--spec/ruby/language/predefined/fixtures/toplevel_binding_variables.rb4
-rw-r--r--spec/ruby/language/predefined/fixtures/toplevel_binding_variables_required.rb2
-rw-r--r--spec/ruby/language/predefined/toplevel_binding_spec.rb34
-rw-r--r--spec/ruby/language/predefined_spec.rb1101
-rw-r--r--spec/ruby/language/private_spec.rb30
-rw-r--r--spec/ruby/language/proc_spec.rb77
-rw-r--r--spec/ruby/language/range_spec.rb30
-rw-r--r--spec/ruby/language/redo_spec.rb8
-rw-r--r--spec/ruby/language/regexp/anchors_spec.rb66
-rw-r--r--spec/ruby/language/regexp/back-references_spec.rb109
-rw-r--r--spec/ruby/language/regexp/character_classes_spec.rb270
-rw-r--r--spec/ruby/language/regexp/empty_checks_spec.rb135
-rw-r--r--spec/ruby/language/regexp/encoding_spec.rb93
-rw-r--r--spec/ruby/language/regexp/escapes_spec.rb118
-rw-r--r--spec/ruby/language/regexp/grouping_spec.rb46
-rw-r--r--spec/ruby/language/regexp/interpolation_spec.rb10
-rw-r--r--spec/ruby/language/regexp/modifiers_spec.rb56
-rw-r--r--spec/ruby/language/regexp/repetition_spec.rb113
-rw-r--r--spec/ruby/language/regexp/subexpression_call_spec.rb50
-rw-r--r--spec/ruby/language/regexp_spec.rb49
-rw-r--r--spec/ruby/language/rescue_spec.rb384
-rw-r--r--spec/ruby/language/reserved_keywords.rb149
-rw-r--r--spec/ruby/language/retry_spec.rb9
-rw-r--r--spec/ruby/language/return_spec.rb366
-rw-r--r--spec/ruby/language/safe_navigator_spec.rb186
-rw-r--r--spec/ruby/language/safe_spec.rb11
-rw-r--r--spec/ruby/language/send_spec.rb124
-rw-r--r--spec/ruby/language/shared/__FILE__.rb4
-rw-r--r--spec/ruby/language/shared/__LINE__.rb2
-rw-r--r--spec/ruby/language/singleton_class_spec.rb128
-rw-r--r--spec/ruby/language/source_encoding_spec.rb61
-rw-r--r--spec/ruby/language/string_spec.rb143
-rw-r--r--spec/ruby/language/super_spec.rb281
-rw-r--r--spec/ruby/language/symbol_spec.rb38
-rw-r--r--spec/ruby/language/throw_spec.rb14
-rw-r--r--spec/ruby/language/undef_spec.rb27
-rw-r--r--spec/ruby/language/unless_spec.rb2
-rw-r--r--spec/ruby/language/until_spec.rb4
-rw-r--r--spec/ruby/language/variables_spec.rb224
-rw-r--r--spec/ruby/language/while_spec.rb20
-rw-r--r--spec/ruby/language/yield_spec.rb101
-rw-r--r--spec/ruby/library/English/English_spec.rb88
-rw-r--r--spec/ruby/library/English/alias_spec.rb14
-rw-r--r--spec/ruby/library/abbrev/abbrev_spec.rb6
-rw-r--r--spec/ruby/library/base64/decode64_spec.rb22
-rw-r--r--spec/ruby/library/base64/encode64_spec.rb11
-rw-r--r--spec/ruby/library/base64/strict_decode64_spec.rb41
-rw-r--r--spec/ruby/library/base64/strict_encode64_spec.rb19
-rw-r--r--spec/ruby/library/base64/urlsafe_decode64_spec.rb14
-rw-r--r--spec/ruby/library/base64/urlsafe_encode64_spec.rb10
-rw-r--r--spec/ruby/library/bigdecimal/BigDecimal_spec.rb239
-rw-r--r--spec/ruby/library/bigdecimal/abs_spec.rb4
-rw-r--r--spec/ruby/library/bigdecimal/add_spec.rb38
-rw-r--r--spec/ruby/library/bigdecimal/case_compare_spec.rb8
-rw-r--r--spec/ruby/library/bigdecimal/ceil_spec.rb8
-rw-r--r--spec/ruby/library/bigdecimal/clone_spec.rb8
-rw-r--r--spec/ruby/library/bigdecimal/coerce_spec.rb2
-rw-r--r--spec/ruby/library/bigdecimal/comparison_spec.rb4
-rw-r--r--spec/ruby/library/bigdecimal/constants_spec.rb70
-rw-r--r--spec/ruby/library/bigdecimal/core_spec.rb62
-rw-r--r--spec/ruby/library/bigdecimal/div_spec.rb56
-rw-r--r--spec/ruby/library/bigdecimal/divide_spec.rb14
-rw-r--r--spec/ruby/library/bigdecimal/divmod_spec.rb106
-rw-r--r--spec/ruby/library/bigdecimal/double_fig_spec.rb2
-rw-r--r--spec/ruby/library/bigdecimal/dup_spec.rb14
-rw-r--r--spec/ruby/library/bigdecimal/eql_spec.rb8
-rw-r--r--spec/ruby/library/bigdecimal/equal_value_spec.rb62
-rw-r--r--spec/ruby/library/bigdecimal/exponent_spec.rb17
-rw-r--r--spec/ruby/library/bigdecimal/finite_spec.rb11
-rw-r--r--spec/ruby/library/bigdecimal/fix_spec.rb36
-rw-r--r--spec/ruby/library/bigdecimal/floor_spec.rb8
-rw-r--r--spec/ruby/library/bigdecimal/frac_spec.rb4
-rw-r--r--spec/ruby/library/bigdecimal/gt_spec.rb32
-rw-r--r--spec/ruby/library/bigdecimal/gte_spec.rb32
-rw-r--r--spec/ruby/library/bigdecimal/hash_spec.rb30
-rw-r--r--spec/ruby/library/bigdecimal/infinite_spec.rb2
-rw-r--r--spec/ruby/library/bigdecimal/inspect_spec.rb45
-rw-r--r--spec/ruby/library/bigdecimal/limit_spec.rb31
-rw-r--r--spec/ruby/library/bigdecimal/lt_spec.rb32
-rw-r--r--spec/ruby/library/bigdecimal/lte_spec.rb32
-rw-r--r--spec/ruby/library/bigdecimal/minus_spec.rb28
-rw-r--r--spec/ruby/library/bigdecimal/mode_spec.rb14
-rw-r--r--spec/ruby/library/bigdecimal/modulo_spec.rb21
-rw-r--r--spec/ruby/library/bigdecimal/mult_spec.rb8
-rw-r--r--spec/ruby/library/bigdecimal/multiply_spec.rb19
-rw-r--r--spec/ruby/library/bigdecimal/nan_spec.rb24
-rw-r--r--spec/ruby/library/bigdecimal/new_spec.rb109
-rw-r--r--spec/ruby/library/bigdecimal/nonzero_spec.rb12
-rw-r--r--spec/ruby/library/bigdecimal/plus_spec.rb15
-rw-r--r--spec/ruby/library/bigdecimal/power_spec.rb6
-rw-r--r--spec/ruby/library/bigdecimal/precs_spec.rb49
-rw-r--r--spec/ruby/library/bigdecimal/quo_spec.rb9
-rw-r--r--spec/ruby/library/bigdecimal/remainder_spec.rb53
-rw-r--r--spec/ruby/library/bigdecimal/round_spec.rb256
-rw-r--r--spec/ruby/library/bigdecimal/shared/eql.rb61
-rw-r--r--spec/ruby/library/bigdecimal/shared/modulo.rb69
-rw-r--r--spec/ruby/library/bigdecimal/shared/mult.rb20
-rw-r--r--spec/ruby/library/bigdecimal/shared/power.rb8
-rw-r--r--spec/ruby/library/bigdecimal/shared/quo.rb19
-rw-r--r--spec/ruby/library/bigdecimal/shared/to_int.rb16
-rw-r--r--spec/ruby/library/bigdecimal/sign_spec.rb3
-rw-r--r--spec/ruby/library/bigdecimal/split_spec.rb24
-rw-r--r--spec/ruby/library/bigdecimal/sqrt_spec.rb48
-rw-r--r--spec/ruby/library/bigdecimal/sub_spec.rb19
-rw-r--r--spec/ruby/library/bigdecimal/to_d_spec.rb10
-rw-r--r--spec/ruby/library/bigdecimal/to_f_spec.rb11
-rw-r--r--spec/ruby/library/bigdecimal/to_i_spec.rb16
-rw-r--r--spec/ruby/library/bigdecimal/to_int_spec.rb8
-rw-r--r--spec/ruby/library/bigdecimal/to_r_spec.rb22
-rw-r--r--spec/ruby/library/bigdecimal/to_s_spec.rb71
-rw-r--r--spec/ruby/library/bigdecimal/truncate_spec.rb24
-rw-r--r--spec/ruby/library/bigdecimal/uminus_spec.rb4
-rw-r--r--spec/ruby/library/bigdecimal/uplus_spec.rb5
-rw-r--r--spec/ruby/library/bigdecimal/util_spec.rb40
-rw-r--r--spec/ruby/library/bigdecimal/ver_spec.rb11
-rw-r--r--spec/ruby/library/bigdecimal/zero_spec.rb29
-rw-r--r--spec/ruby/library/bigmath/log_spec.rb10
-rw-r--r--spec/ruby/library/cgi/cookie/domain_spec.rb35
-rw-r--r--spec/ruby/library/cgi/cookie/expires_spec.rb35
-rw-r--r--spec/ruby/library/cgi/cookie/initialize_spec.rb237
-rw-r--r--spec/ruby/library/cgi/cookie/name_spec.rb35
-rw-r--r--spec/ruby/library/cgi/cookie/parse_spec.rb44
-rw-r--r--spec/ruby/library/cgi/cookie/path_spec.rb35
-rw-r--r--spec/ruby/library/cgi/cookie/secure_spec.rb101
-rw-r--r--spec/ruby/library/cgi/cookie/to_s_spec.rb62
-rw-r--r--spec/ruby/library/cgi/cookie/value_spec.rb123
-rw-r--r--spec/ruby/library/cgi/escapeElement_spec.rb10
-rw-r--r--spec/ruby/library/cgi/escapeHTML_spec.rb12
-rw-r--r--spec/ruby/library/cgi/escapeURIComponent_spec.rb78
-rw-r--r--spec/ruby/library/cgi/escape_spec.rb24
-rw-r--r--spec/ruby/library/cgi/htmlextension/a_spec.rb75
-rw-r--r--spec/ruby/library/cgi/htmlextension/base_spec.rb49
-rw-r--r--spec/ruby/library/cgi/htmlextension/blockquote_spec.rb49
-rw-r--r--spec/ruby/library/cgi/htmlextension/br_spec.rb33
-rw-r--r--spec/ruby/library/cgi/htmlextension/caption_spec.rb49
-rw-r--r--spec/ruby/library/cgi/htmlextension/checkbox_group_spec.rb123
-rw-r--r--spec/ruby/library/cgi/htmlextension/checkbox_spec.rb115
-rw-r--r--spec/ruby/library/cgi/htmlextension/doctype_spec.rb43
-rw-r--r--spec/ruby/library/cgi/htmlextension/file_field_spec.rb107
-rw-r--r--spec/ruby/library/cgi/htmlextension/form_spec.rb89
-rw-r--r--spec/ruby/library/cgi/htmlextension/frame_spec.rb23
-rw-r--r--spec/ruby/library/cgi/htmlextension/frameset_spec.rb23
-rw-r--r--spec/ruby/library/cgi/htmlextension/hidden_spec.rb89
-rw-r--r--spec/ruby/library/cgi/htmlextension/html_spec.rb101
-rw-r--r--spec/ruby/library/cgi/htmlextension/image_button_spec.rb103
-rw-r--r--spec/ruby/library/cgi/htmlextension/img_spec.rb125
-rw-r--r--spec/ruby/library/cgi/htmlextension/multipart_form_spec.rb95
-rw-r--r--spec/ruby/library/cgi/htmlextension/password_field_spec.rb125
-rw-r--r--spec/ruby/library/cgi/htmlextension/popup_menu_spec.rb15
-rw-r--r--spec/ruby/library/cgi/htmlextension/radio_button_spec.rb115
-rw-r--r--spec/ruby/library/cgi/htmlextension/radio_group_spec.rb125
-rw-r--r--spec/ruby/library/cgi/htmlextension/reset_spec.rb85
-rw-r--r--spec/ruby/library/cgi/htmlextension/scrolling_list_spec.rb15
-rw-r--r--spec/ruby/library/cgi/htmlextension/submit_spec.rb85
-rw-r--r--spec/ruby/library/cgi/htmlextension/text_field_spec.rb125
-rw-r--r--spec/ruby/library/cgi/htmlextension/textarea_spec.rb109
-rw-r--r--spec/ruby/library/cgi/http_header_spec.rb13
-rw-r--r--spec/ruby/library/cgi/initialize_spec.rb211
-rw-r--r--spec/ruby/library/cgi/out_spec.rb101
-rw-r--r--spec/ruby/library/cgi/parse_spec.rb39
-rw-r--r--spec/ruby/library/cgi/pretty_spec.rb21
-rw-r--r--spec/ruby/library/cgi/print_spec.rb41
-rw-r--r--spec/ruby/library/cgi/queryextension/accept_charset_spec.rb35
-rw-r--r--spec/ruby/library/cgi/queryextension/accept_encoding_spec.rb35
-rw-r--r--spec/ruby/library/cgi/queryextension/accept_language_spec.rb35
-rw-r--r--spec/ruby/library/cgi/queryextension/accept_spec.rb35
-rw-r--r--spec/ruby/library/cgi/queryextension/auth_type_spec.rb35
-rw-r--r--spec/ruby/library/cgi/queryextension/cache_control_spec.rb35
-rw-r--r--spec/ruby/library/cgi/queryextension/content_length_spec.rb41
-rw-r--r--spec/ruby/library/cgi/queryextension/content_type_spec.rb35
-rw-r--r--spec/ruby/library/cgi/queryextension/cookies_spec.rb17
-rw-r--r--spec/ruby/library/cgi/queryextension/element_reference_spec.rb43
-rw-r--r--spec/ruby/library/cgi/queryextension/from_spec.rb35
-rw-r--r--spec/ruby/library/cgi/queryextension/gateway_interface_spec.rb35
-rw-r--r--spec/ruby/library/cgi/queryextension/has_key_spec.rb13
-rw-r--r--spec/ruby/library/cgi/queryextension/host_spec.rb35
-rw-r--r--spec/ruby/library/cgi/queryextension/include_spec.rb13
-rw-r--r--spec/ruby/library/cgi/queryextension/key_spec.rb13
-rw-r--r--spec/ruby/library/cgi/queryextension/keys_spec.rb31
-rw-r--r--spec/ruby/library/cgi/queryextension/multipart_spec.rb49
-rw-r--r--spec/ruby/library/cgi/queryextension/negotiate_spec.rb35
-rw-r--r--spec/ruby/library/cgi/queryextension/params_spec.rb59
-rw-r--r--spec/ruby/library/cgi/queryextension/path_info_spec.rb35
-rw-r--r--spec/ruby/library/cgi/queryextension/path_translated_spec.rb35
-rw-r--r--spec/ruby/library/cgi/queryextension/pragma_spec.rb35
-rw-r--r--spec/ruby/library/cgi/queryextension/query_string_spec.rb35
-rw-r--r--spec/ruby/library/cgi/queryextension/raw_cookie2_spec.rb35
-rw-r--r--spec/ruby/library/cgi/queryextension/raw_cookie_spec.rb35
-rw-r--r--spec/ruby/library/cgi/queryextension/referer_spec.rb35
-rw-r--r--spec/ruby/library/cgi/queryextension/remote_addr_spec.rb35
-rw-r--r--spec/ruby/library/cgi/queryextension/remote_host_spec.rb35
-rw-r--r--spec/ruby/library/cgi/queryextension/remote_ident_spec.rb35
-rw-r--r--spec/ruby/library/cgi/queryextension/remote_user_spec.rb35
-rw-r--r--spec/ruby/library/cgi/queryextension/request_method_spec.rb35
-rw-r--r--spec/ruby/library/cgi/queryextension/script_name_spec.rb35
-rw-r--r--spec/ruby/library/cgi/queryextension/server_name_spec.rb35
-rw-r--r--spec/ruby/library/cgi/queryextension/server_port_spec.rb41
-rw-r--r--spec/ruby/library/cgi/queryextension/server_protocol_spec.rb35
-rw-r--r--spec/ruby/library/cgi/queryextension/server_software_spec.rb35
-rw-r--r--spec/ruby/library/cgi/queryextension/shared/has_key.rb6
-rw-r--r--spec/ruby/library/cgi/queryextension/user_agent_spec.rb35
-rw-r--r--spec/ruby/library/cgi/rfc1123_date_spec.rb17
-rw-r--r--spec/ruby/library/cgi/shared/http_header.rb12
-rw-r--r--spec/ruby/library/cgi/unescapeElement_spec.rb10
-rw-r--r--spec/ruby/library/cgi/unescapeHTML_spec.rb13
-rw-r--r--spec/ruby/library/cgi/unescapeURIComponent_spec.rb128
-rw-r--r--spec/ruby/library/cgi/unescape_spec.rb14
-rw-r--r--spec/ruby/library/complex/math/acos_spec.rb15
-rw-r--r--spec/ruby/library/complex/math/acosh_spec.rb15
-rw-r--r--spec/ruby/library/complex/math/asin_spec.rb15
-rw-r--r--spec/ruby/library/complex/math/asinh_spec.rb15
-rw-r--r--spec/ruby/library/complex/math/atan2_spec.rb15
-rw-r--r--spec/ruby/library/complex/math/atan_spec.rb15
-rw-r--r--spec/ruby/library/complex/math/atanh_spec.rb17
-rw-r--r--spec/ruby/library/complex/math/cos_spec.rb15
-rw-r--r--spec/ruby/library/complex/math/cosh_spec.rb15
-rw-r--r--spec/ruby/library/complex/math/exp_spec.rb15
-rw-r--r--spec/ruby/library/complex/math/fixtures/classes.rb4
-rw-r--r--spec/ruby/library/complex/math/log10_spec.rb15
-rw-r--r--spec/ruby/library/complex/math/log_spec.rb15
-rw-r--r--spec/ruby/library/complex/math/shared/acos.rb41
-rw-r--r--spec/ruby/library/complex/math/shared/acosh.rb37
-rw-r--r--spec/ruby/library/complex/math/shared/asin.rb47
-rw-r--r--spec/ruby/library/complex/math/shared/asinh.rb32
-rw-r--r--spec/ruby/library/complex/math/shared/atan.rb32
-rw-r--r--spec/ruby/library/complex/math/shared/atan2.rb34
-rw-r--r--spec/ruby/library/complex/math/shared/atanh.rb30
-rw-r--r--spec/ruby/library/complex/math/shared/cos.rb30
-rw-r--r--spec/ruby/library/complex/math/shared/cosh.rb28
-rw-r--r--spec/ruby/library/complex/math/shared/exp.rb28
-rw-r--r--spec/ruby/library/complex/math/shared/log.rb39
-rw-r--r--spec/ruby/library/complex/math/shared/log10.rb41
-rw-r--r--spec/ruby/library/complex/math/shared/sin.rb30
-rw-r--r--spec/ruby/library/complex/math/shared/sinh.rb28
-rw-r--r--spec/ruby/library/complex/math/shared/sqrt.rb34
-rw-r--r--spec/ruby/library/complex/math/shared/tan.rb28
-rw-r--r--spec/ruby/library/complex/math/shared/tanh.rb32
-rw-r--r--spec/ruby/library/complex/math/sin_spec.rb15
-rw-r--r--spec/ruby/library/complex/math/sinh_spec.rb15
-rw-r--r--spec/ruby/library/complex/math/sqrt_spec.rb15
-rw-r--r--spec/ruby/library/complex/math/tan_spec.rb15
-rw-r--r--spec/ruby/library/complex/math/tanh_spec.rb15
-rw-r--r--spec/ruby/library/complex/numeric/im_spec.rb3
-rw-r--r--spec/ruby/library/conditionvariable/broadcast_spec.rb67
-rw-r--r--spec/ruby/library/conditionvariable/marshal_dump_spec.rb9
-rw-r--r--spec/ruby/library/conditionvariable/signal_spec.rb69
-rw-r--r--spec/ruby/library/conditionvariable/wait_spec.rb25
-rw-r--r--spec/ruby/library/coverage/fixtures/code_with_begin.rb3
-rw-r--r--spec/ruby/library/coverage/fixtures/eval_code.rb11
-rw-r--r--spec/ruby/library/coverage/fixtures/spec_helper.rb11
-rw-r--r--spec/ruby/library/coverage/peek_result_spec.rb105
-rw-r--r--spec/ruby/library/coverage/result_spec.rb297
-rw-r--r--spec/ruby/library/coverage/running_spec.rb20
-rw-r--r--spec/ruby/library/coverage/start_spec.rb85
-rw-r--r--spec/ruby/library/coverage/supported_spec.rb30
-rw-r--r--spec/ruby/library/csv/basicwriter/close_on_terminate_spec.rb2
-rw-r--r--spec/ruby/library/csv/basicwriter/initialize_spec.rb2
-rw-r--r--spec/ruby/library/csv/basicwriter/terminate_spec.rb2
-rw-r--r--spec/ruby/library/csv/cell/data_spec.rb2
-rw-r--r--spec/ruby/library/csv/cell/initialize_spec.rb2
-rw-r--r--spec/ruby/library/csv/foreach_spec.rb2
-rw-r--r--spec/ruby/library/csv/generate_line_spec.rb2
-rw-r--r--spec/ruby/library/csv/generate_row_spec.rb2
-rw-r--r--spec/ruby/library/csv/generate_spec.rb6
-rw-r--r--spec/ruby/library/csv/iobuf/close_spec.rb2
-rw-r--r--spec/ruby/library/csv/iobuf/initialize_spec.rb2
-rw-r--r--spec/ruby/library/csv/iobuf/read_spec.rb2
-rw-r--r--spec/ruby/library/csv/iobuf/terminate_spec.rb2
-rw-r--r--spec/ruby/library/csv/ioreader/close_on_terminate_spec.rb2
-rw-r--r--spec/ruby/library/csv/ioreader/get_row_spec.rb2
-rw-r--r--spec/ruby/library/csv/ioreader/initialize_spec.rb2
-rw-r--r--spec/ruby/library/csv/ioreader/terminate_spec.rb2
-rw-r--r--spec/ruby/library/csv/liberal_parsing_spec.rb28
-rw-r--r--spec/ruby/library/csv/open_spec.rb2
-rw-r--r--spec/ruby/library/csv/parse_spec.rb16
-rw-r--r--spec/ruby/library/csv/read_spec.rb2
-rw-r--r--spec/ruby/library/csv/readlines_spec.rb16
-rw-r--r--spec/ruby/library/csv/streambuf/add_buf_spec.rb2
-rw-r--r--spec/ruby/library/csv/streambuf/buf_size_spec.rb2
-rw-r--r--spec/ruby/library/csv/streambuf/drop_spec.rb2
-rw-r--r--spec/ruby/library/csv/streambuf/element_reference_spec.rb2
-rw-r--r--spec/ruby/library/csv/streambuf/get_spec.rb2
-rw-r--r--spec/ruby/library/csv/streambuf/idx_is_eos_spec.rb2
-rw-r--r--spec/ruby/library/csv/streambuf/initialize_spec.rb2
-rw-r--r--spec/ruby/library/csv/streambuf/is_eos_spec.rb2
-rw-r--r--spec/ruby/library/csv/streambuf/read_spec.rb2
-rw-r--r--spec/ruby/library/csv/streambuf/rel_buf_spec.rb2
-rw-r--r--spec/ruby/library/csv/streambuf/terminate_spec.rb2
-rw-r--r--spec/ruby/library/csv/stringreader/get_row_spec.rb2
-rw-r--r--spec/ruby/library/csv/stringreader/initialize_spec.rb2
-rw-r--r--spec/ruby/library/csv/writer/add_row_spec.rb2
-rw-r--r--spec/ruby/library/csv/writer/append_spec.rb2
-rw-r--r--spec/ruby/library/csv/writer/close_spec.rb2
-rw-r--r--spec/ruby/library/csv/writer/create_spec.rb2
-rw-r--r--spec/ruby/library/csv/writer/generate_spec.rb2
-rw-r--r--spec/ruby/library/csv/writer/initialize_spec.rb2
-rw-r--r--spec/ruby/library/csv/writer/terminate_spec.rb2
-rw-r--r--spec/ruby/library/date/accessor_spec.rb4
-rw-r--r--spec/ruby/library/date/add_month_spec.rb10
-rw-r--r--spec/ruby/library/date/add_spec.rb10
-rw-r--r--spec/ruby/library/date/ajd_spec.rb2
-rw-r--r--spec/ruby/library/date/ajd_to_amjd_spec.rb2
-rw-r--r--spec/ruby/library/date/ajd_to_jd_spec.rb2
-rw-r--r--spec/ruby/library/date/amjd_spec.rb2
-rw-r--r--spec/ruby/library/date/amjd_to_ajd_spec.rb2
-rw-r--r--spec/ruby/library/date/append_spec.rb2
-rw-r--r--spec/ruby/library/date/asctime_spec.rb7
-rw-r--r--spec/ruby/library/date/boat_spec.rb2
-rw-r--r--spec/ruby/library/date/case_compare_spec.rb2
-rw-r--r--spec/ruby/library/date/civil_spec.rb11
-rw-r--r--spec/ruby/library/date/commercial_spec.rb47
-rw-r--r--spec/ruby/library/date/commercial_to_jd_spec.rb2
-rw-r--r--spec/ruby/library/date/comparison_spec.rb2
-rw-r--r--spec/ruby/library/date/constants_spec.rb10
-rw-r--r--spec/ruby/library/date/conversions_spec.rb2
-rw-r--r--spec/ruby/library/date/ctime_spec.rb6
-rw-r--r--spec/ruby/library/date/cwday_spec.rb2
-rw-r--r--spec/ruby/library/date/cweek_spec.rb2
-rw-r--r--spec/ruby/library/date/cwyear_spec.rb2
-rw-r--r--spec/ruby/library/date/day_fraction_spec.rb2
-rw-r--r--spec/ruby/library/date/day_fraction_to_time_spec.rb2
-rw-r--r--spec/ruby/library/date/day_spec.rb2
-rw-r--r--spec/ruby/library/date/deconstruct_keys_spec.rb42
-rw-r--r--spec/ruby/library/date/downto_spec.rb2
-rw-r--r--spec/ruby/library/date/england_spec.rb2
-rw-r--r--spec/ruby/library/date/eql_spec.rb6
-rw-r--r--spec/ruby/library/date/format/bag/method_missing_spec.rb2
-rw-r--r--spec/ruby/library/date/format/bag/to_hash_spec.rb2
-rw-r--r--spec/ruby/library/date/friday_spec.rb6
-rw-r--r--spec/ruby/library/date/gregorian_leap_spec.rb13
-rw-r--r--spec/ruby/library/date/gregorian_spec.rb10
-rw-r--r--spec/ruby/library/date/hash_spec.rb2
-rw-r--r--spec/ruby/library/date/infinity/abs_spec.rb2
-rw-r--r--spec/ruby/library/date/infinity/coerce_spec.rb2
-rw-r--r--spec/ruby/library/date/infinity/comparison_spec.rb2
-rw-r--r--spec/ruby/library/date/infinity/d_spec.rb2
-rw-r--r--spec/ruby/library/date/infinity/finite_spec.rb2
-rw-r--r--spec/ruby/library/date/infinity/infinite_spec.rb2
-rw-r--r--spec/ruby/library/date/infinity/nan_spec.rb2
-rw-r--r--spec/ruby/library/date/infinity/uminus_spec.rb2
-rw-r--r--spec/ruby/library/date/infinity/uplus_spec.rb2
-rw-r--r--spec/ruby/library/date/infinity/zero_spec.rb2
-rw-r--r--spec/ruby/library/date/infinity_spec.rb16
-rw-r--r--spec/ruby/library/date/inspect_spec.rb2
-rw-r--r--spec/ruby/library/date/iso8601_spec.rb56
-rw-r--r--spec/ruby/library/date/italy_spec.rb2
-rw-r--r--spec/ruby/library/date/jd_spec.rb17
-rw-r--r--spec/ruby/library/date/jd_to_ajd_spec.rb2
-rw-r--r--spec/ruby/library/date/jd_to_civil_spec.rb2
-rw-r--r--spec/ruby/library/date/jd_to_commercial_spec.rb2
-rw-r--r--spec/ruby/library/date/jd_to_ld_spec.rb2
-rw-r--r--spec/ruby/library/date/jd_to_mjd_spec.rb2
-rw-r--r--spec/ruby/library/date/jd_to_ordinal_spec.rb2
-rw-r--r--spec/ruby/library/date/jd_to_wday_spec.rb2
-rw-r--r--spec/ruby/library/date/julian_leap_spec.rb12
-rw-r--r--spec/ruby/library/date/julian_spec.rb10
-rw-r--r--spec/ruby/library/date/ld_spec.rb2
-rw-r--r--spec/ruby/library/date/ld_to_jd_spec.rb2
-rw-r--r--spec/ruby/library/date/leap_spec.rb2
-rw-r--r--spec/ruby/library/date/mday_spec.rb6
-rw-r--r--spec/ruby/library/date/minus_month_spec.rb23
-rw-r--r--spec/ruby/library/date/minus_spec.rb8
-rw-r--r--spec/ruby/library/date/mjd_spec.rb2
-rw-r--r--spec/ruby/library/date/mjd_to_jd_spec.rb2
-rw-r--r--spec/ruby/library/date/mon_spec.rb6
-rw-r--r--spec/ruby/library/date/monday_spec.rb4
-rw-r--r--spec/ruby/library/date/month_spec.rb2
-rw-r--r--spec/ruby/library/date/new_spec.rb7
-rw-r--r--spec/ruby/library/date/new_start_spec.rb2
-rw-r--r--spec/ruby/library/date/next_day_spec.rb2
-rw-r--r--spec/ruby/library/date/next_month_spec.rb2
-rw-r--r--spec/ruby/library/date/next_spec.rb2
-rw-r--r--spec/ruby/library/date/next_year_spec.rb2
-rw-r--r--spec/ruby/library/date/ordinal_spec.rb17
-rw-r--r--spec/ruby/library/date/ordinal_to_jd_spec.rb2
-rw-r--r--spec/ruby/library/date/parse_spec.rb42
-rw-r--r--spec/ruby/library/date/plus_spec.rb4
-rw-r--r--spec/ruby/library/date/prev_day_spec.rb2
-rw-r--r--spec/ruby/library/date/prev_month_spec.rb2
-rw-r--r--spec/ruby/library/date/prev_year_spec.rb2
-rw-r--r--spec/ruby/library/date/relationship_spec.rb2
-rw-r--r--spec/ruby/library/date/rfc3339_spec.rb13
-rw-r--r--spec/ruby/library/date/right_shift_spec.rb2
-rw-r--r--spec/ruby/library/date/saturday_spec.rb4
-rw-r--r--spec/ruby/library/date/shared/civil.rb24
-rw-r--r--spec/ruby/library/date/shared/commercial.rb39
-rw-r--r--spec/ruby/library/date/shared/jd.rb14
-rw-r--r--spec/ruby/library/date/shared/new_bang.rb14
-rw-r--r--spec/ruby/library/date/shared/ordinal.rb22
-rw-r--r--spec/ruby/library/date/shared/parse.rb4
-rw-r--r--spec/ruby/library/date/shared/parse_eu.rb8
-rw-r--r--spec/ruby/library/date/shared/parse_us.rb8
-rw-r--r--spec/ruby/library/date/shared/valid_civil.rb36
-rw-r--r--spec/ruby/library/date/shared/valid_commercial.rb34
-rw-r--r--spec/ruby/library/date/shared/valid_jd.rb15
-rw-r--r--spec/ruby/library/date/shared/valid_ordinal.rb26
-rw-r--r--spec/ruby/library/date/start_spec.rb2
-rw-r--r--spec/ruby/library/date/step_spec.rb2
-rw-r--r--spec/ruby/library/date/strftime_spec.rb11
-rw-r--r--spec/ruby/library/date/strptime_spec.rb2
-rw-r--r--spec/ruby/library/date/succ_spec.rb6
-rw-r--r--spec/ruby/library/date/sunday_spec.rb4
-rw-r--r--spec/ruby/library/date/thursday_spec.rb4
-rw-r--r--spec/ruby/library/date/time/to_date_spec.rb42
-rw-r--r--spec/ruby/library/date/time_to_day_fraction_spec.rb2
-rw-r--r--spec/ruby/library/date/to_s_spec.rb2
-rw-r--r--spec/ruby/library/date/today_spec.rb4
-rw-r--r--spec/ruby/library/date/tuesday_spec.rb4
-rw-r--r--spec/ruby/library/date/upto_spec.rb2
-rw-r--r--spec/ruby/library/date/valid_civil_spec.rb12
-rw-r--r--spec/ruby/library/date/valid_commercial_spec.rb37
-rw-r--r--spec/ruby/library/date/valid_date_spec.rb37
-rw-r--r--spec/ruby/library/date/valid_jd_spec.rb21
-rw-r--r--spec/ruby/library/date/valid_ordinal_spec.rb29
-rw-r--r--spec/ruby/library/date/valid_time_spec.rb2
-rw-r--r--spec/ruby/library/date/wday_spec.rb2
-rw-r--r--spec/ruby/library/date/wednesday_spec.rb4
-rw-r--r--spec/ruby/library/date/yday_spec.rb5
-rw-r--r--spec/ruby/library/date/year_spec.rb2
-rw-r--r--spec/ruby/library/date/zone_to_diff_spec.rb2
-rw-r--r--spec/ruby/library/datetime/_strptime_spec.rb2
-rw-r--r--spec/ruby/library/datetime/add_spec.rb9
-rw-r--r--spec/ruby/library/datetime/civil_spec.rb2
-rw-r--r--spec/ruby/library/datetime/commercial_spec.rb2
-rw-r--r--spec/ruby/library/datetime/deconstruct_keys_spec.rb44
-rw-r--r--spec/ruby/library/datetime/hour_spec.rb15
-rw-r--r--spec/ruby/library/datetime/httpdate_spec.rb2
-rw-r--r--spec/ruby/library/datetime/iso8601_spec.rb6
-rw-r--r--spec/ruby/library/datetime/jd_spec.rb2
-rw-r--r--spec/ruby/library/datetime/jisx0301_spec.rb2
-rw-r--r--spec/ruby/library/datetime/min_spec.rb10
-rw-r--r--spec/ruby/library/datetime/minute_spec.rb42
-rw-r--r--spec/ruby/library/datetime/new_offset_spec.rb2
-rw-r--r--spec/ruby/library/datetime/new_spec.rb4
-rw-r--r--spec/ruby/library/datetime/now_spec.rb8
-rw-r--r--spec/ruby/library/datetime/offset_spec.rb2
-rw-r--r--spec/ruby/library/datetime/ordinal_spec.rb2
-rw-r--r--spec/ruby/library/datetime/parse_spec.rb14
-rw-r--r--spec/ruby/library/datetime/rfc2822_spec.rb6
-rw-r--r--spec/ruby/library/datetime/rfc3339_spec.rb2
-rw-r--r--spec/ruby/library/datetime/rfc822_spec.rb2
-rw-r--r--spec/ruby/library/datetime/sec_fraction_spec.rb2
-rw-r--r--spec/ruby/library/datetime/sec_spec.rb10
-rw-r--r--spec/ruby/library/datetime/second_fraction_spec.rb6
-rw-r--r--spec/ruby/library/datetime/second_spec.rb45
-rw-r--r--spec/ruby/library/datetime/shared/min.rb40
-rw-r--r--spec/ruby/library/datetime/shared/sec.rb45
-rw-r--r--spec/ruby/library/datetime/strftime_spec.rb19
-rw-r--r--spec/ruby/library/datetime/strptime_spec.rb2
-rw-r--r--spec/ruby/library/datetime/subtract_spec.rb19
-rw-r--r--spec/ruby/library/datetime/time/to_datetime_spec.rb40
-rw-r--r--spec/ruby/library/datetime/to_date_spec.rb6
-rw-r--r--spec/ruby/library/datetime/to_datetime_spec.rb2
-rw-r--r--spec/ruby/library/datetime/to_s_spec.rb6
-rw-r--r--spec/ruby/library/datetime/to_time_spec.rb52
-rw-r--r--spec/ruby/library/datetime/xmlschema_spec.rb2
-rw-r--r--spec/ruby/library/datetime/yday_spec.rb7
-rw-r--r--spec/ruby/library/datetime/zone_spec.rb2
-rw-r--r--spec/ruby/library/delegate/delegate_class/instance_method_spec.rb22
-rw-r--r--spec/ruby/library/delegate/delegate_class/instance_methods_spec.rb16
-rw-r--r--spec/ruby/library/delegate/delegate_class/private_instance_methods_spec.rb16
-rw-r--r--spec/ruby/library/delegate/delegate_class/protected_instance_methods_spec.rb16
-rw-r--r--spec/ruby/library/delegate/delegate_class/public_instance_methods_spec.rb14
-rw-r--r--spec/ruby/library/delegate/delegate_class/respond_to_missing_spec.rb1
-rw-r--r--spec/ruby/library/delegate/delegator/case_compare_spec.rb4
-rw-r--r--spec/ruby/library/delegate/delegator/compare_spec.rb4
-rw-r--r--spec/ruby/library/delegate/delegator/complement_spec.rb4
-rw-r--r--spec/ruby/library/delegate/delegator/eql_spec.rb59
-rw-r--r--spec/ruby/library/delegate/delegator/equal_spec.rb10
-rw-r--r--spec/ruby/library/delegate/delegator/equal_value_spec.rb10
-rw-r--r--spec/ruby/library/delegate/delegator/frozen_spec.rb20
-rw-r--r--spec/ruby/library/delegate/delegator/hash_spec.rb4
-rw-r--r--spec/ruby/library/delegate/delegator/marshal_spec.rb4
-rw-r--r--spec/ruby/library/delegate/delegator/method_spec.rb30
-rw-r--r--spec/ruby/library/delegate/delegator/methods_spec.rb18
-rw-r--r--spec/ruby/library/delegate/delegator/not_equal_spec.rb10
-rw-r--r--spec/ruby/library/delegate/delegator/not_spec.rb4
-rw-r--r--spec/ruby/library/delegate/delegator/private_methods_spec.rb12
-rw-r--r--spec/ruby/library/delegate/delegator/protected_methods_spec.rb8
-rw-r--r--spec/ruby/library/delegate/delegator/public_methods_spec.rb8
-rw-r--r--spec/ruby/library/delegate/delegator/send_spec.rb12
-rw-r--r--spec/ruby/library/delegate/delegator/taint_spec.rb19
-rw-r--r--spec/ruby/library/delegate/delegator/tap_spec.rb6
-rw-r--r--spec/ruby/library/delegate/delegator/trust_spec.rb18
-rw-r--r--spec/ruby/library/delegate/delegator/untaint_spec.rb22
-rw-r--r--spec/ruby/library/delegate/delegator/untrust_spec.rb19
-rw-r--r--spec/ruby/library/digest/bubblebabble_spec.rb12
-rw-r--r--spec/ruby/library/digest/hexencode_spec.rb8
-rw-r--r--spec/ruby/library/digest/instance/append_spec.rb11
-rw-r--r--spec/ruby/library/digest/instance/new_spec.rb19
-rw-r--r--spec/ruby/library/digest/instance/update_spec.rb8
-rw-r--r--spec/ruby/library/digest/md5/append_spec.rb11
-rw-r--r--spec/ruby/library/digest/md5/block_length_spec.rb5
-rw-r--r--spec/ruby/library/digest/md5/digest_bang_spec.rb4
-rw-r--r--spec/ruby/library/digest/md5/digest_length_spec.rb5
-rw-r--r--spec/ruby/library/digest/md5/digest_spec.rb4
-rw-r--r--spec/ruby/library/digest/md5/equal_spec.rb5
-rw-r--r--spec/ruby/library/digest/md5/file_spec.rb14
-rw-r--r--spec/ruby/library/digest/md5/hexdigest_bang_spec.rb4
-rw-r--r--spec/ruby/library/digest/md5/hexdigest_spec.rb4
-rw-r--r--spec/ruby/library/digest/md5/inspect_spec.rb5
-rw-r--r--spec/ruby/library/digest/md5/length_spec.rb13
-rw-r--r--spec/ruby/library/digest/md5/reset_spec.rb5
-rw-r--r--spec/ruby/library/digest/md5/shared/constants.rb3
-rw-r--r--spec/ruby/library/digest/md5/shared/length.rb8
-rw-r--r--spec/ruby/library/digest/md5/shared/sample.rb17
-rw-r--r--spec/ruby/library/digest/md5/shared/update.rb7
-rw-r--r--spec/ruby/library/digest/md5/size_spec.rb10
-rw-r--r--spec/ruby/library/digest/md5/to_s_spec.rb4
-rw-r--r--spec/ruby/library/digest/md5/update_spec.rb9
-rw-r--r--spec/ruby/library/digest/sha1/digest_spec.rb4
-rw-r--r--spec/ruby/library/digest/sha1/file_spec.rb14
-rw-r--r--spec/ruby/library/digest/sha1/shared/constants.rb5
-rw-r--r--spec/ruby/library/digest/sha2/hexdigest_spec.rb32
-rw-r--r--spec/ruby/library/digest/sha256/append_spec.rb11
-rw-r--r--spec/ruby/library/digest/sha256/block_length_spec.rb5
-rw-r--r--spec/ruby/library/digest/sha256/digest_bang_spec.rb4
-rw-r--r--spec/ruby/library/digest/sha256/digest_length_spec.rb5
-rw-r--r--spec/ruby/library/digest/sha256/digest_spec.rb4
-rw-r--r--spec/ruby/library/digest/sha256/equal_spec.rb5
-rw-r--r--spec/ruby/library/digest/sha256/file_spec.rb18
-rw-r--r--spec/ruby/library/digest/sha256/hexdigest_bang_spec.rb4
-rw-r--r--spec/ruby/library/digest/sha256/hexdigest_spec.rb4
-rw-r--r--spec/ruby/library/digest/sha256/inspect_spec.rb5
-rw-r--r--spec/ruby/library/digest/sha256/length_spec.rb13
-rw-r--r--spec/ruby/library/digest/sha256/reset_spec.rb5
-rw-r--r--spec/ruby/library/digest/sha256/shared/constants.rb3
-rw-r--r--spec/ruby/library/digest/sha256/shared/length.rb8
-rw-r--r--spec/ruby/library/digest/sha256/shared/update.rb7
-rw-r--r--spec/ruby/library/digest/sha256/size_spec.rb10
-rw-r--r--spec/ruby/library/digest/sha256/to_s_spec.rb4
-rw-r--r--spec/ruby/library/digest/sha256/update_spec.rb9
-rw-r--r--spec/ruby/library/digest/sha384/append_spec.rb11
-rw-r--r--spec/ruby/library/digest/sha384/block_length_spec.rb5
-rw-r--r--spec/ruby/library/digest/sha384/digest_bang_spec.rb4
-rw-r--r--spec/ruby/library/digest/sha384/digest_length_spec.rb5
-rw-r--r--spec/ruby/library/digest/sha384/digest_spec.rb4
-rw-r--r--spec/ruby/library/digest/sha384/equal_spec.rb5
-rw-r--r--spec/ruby/library/digest/sha384/file_spec.rb14
-rw-r--r--spec/ruby/library/digest/sha384/hexdigest_bang_spec.rb4
-rw-r--r--spec/ruby/library/digest/sha384/hexdigest_spec.rb4
-rw-r--r--spec/ruby/library/digest/sha384/inspect_spec.rb5
-rw-r--r--spec/ruby/library/digest/sha384/length_spec.rb13
-rw-r--r--spec/ruby/library/digest/sha384/reset_spec.rb5
-rw-r--r--spec/ruby/library/digest/sha384/shared/constants.rb3
-rw-r--r--spec/ruby/library/digest/sha384/shared/length.rb8
-rw-r--r--spec/ruby/library/digest/sha384/shared/update.rb7
-rw-r--r--spec/ruby/library/digest/sha384/size_spec.rb10
-rw-r--r--spec/ruby/library/digest/sha384/to_s_spec.rb4
-rw-r--r--spec/ruby/library/digest/sha384/update_spec.rb9
-rw-r--r--spec/ruby/library/digest/sha512/append_spec.rb11
-rw-r--r--spec/ruby/library/digest/sha512/block_length_spec.rb5
-rw-r--r--spec/ruby/library/digest/sha512/digest_bang_spec.rb4
-rw-r--r--spec/ruby/library/digest/sha512/digest_length_spec.rb5
-rw-r--r--spec/ruby/library/digest/sha512/digest_spec.rb4
-rw-r--r--spec/ruby/library/digest/sha512/equal_spec.rb5
-rw-r--r--spec/ruby/library/digest/sha512/file_spec.rb14
-rw-r--r--spec/ruby/library/digest/sha512/hexdigest_bang_spec.rb4
-rw-r--r--spec/ruby/library/digest/sha512/hexdigest_spec.rb4
-rw-r--r--spec/ruby/library/digest/sha512/inspect_spec.rb5
-rw-r--r--spec/ruby/library/digest/sha512/length_spec.rb13
-rw-r--r--spec/ruby/library/digest/sha512/reset_spec.rb5
-rw-r--r--spec/ruby/library/digest/sha512/shared/constants.rb3
-rw-r--r--spec/ruby/library/digest/sha512/shared/length.rb8
-rw-r--r--spec/ruby/library/digest/sha512/shared/update.rb7
-rw-r--r--spec/ruby/library/digest/sha512/size_spec.rb10
-rw-r--r--spec/ruby/library/digest/sha512/to_s_spec.rb4
-rw-r--r--spec/ruby/library/digest/sha512/update_spec.rb9
-rw-r--r--spec/ruby/library/drb/start_service_spec.rb49
-rw-r--r--spec/ruby/library/erb/def_class_spec.rb4
-rw-r--r--spec/ruby/library/erb/def_method_spec.rb2
-rw-r--r--spec/ruby/library/erb/def_module_spec.rb5
-rw-r--r--spec/ruby/library/erb/defmethod/def_erb_method_spec.rb7
-rw-r--r--spec/ruby/library/erb/filename_spec.rb10
-rw-r--r--spec/ruby/library/erb/fixtures/classes.rb5
-rw-r--r--spec/ruby/library/erb/new_spec.rb59
-rw-r--r--spec/ruby/library/erb/result_spec.rb10
-rw-r--r--spec/ruby/library/erb/run_spec.rb13
-rw-r--r--spec/ruby/library/erb/src_spec.rb2
-rw-r--r--spec/ruby/library/erb/util/h_spec.rb4
-rw-r--r--spec/ruby/library/erb/util/html_escape_spec.rb5
-rw-r--r--spec/ruby/library/erb/util/shared/url_encode.rb16
-rw-r--r--spec/ruby/library/erb/util/u_spec.rb5
-rw-r--r--spec/ruby/library/erb/util/url_encode_spec.rb4
-rw-r--r--spec/ruby/library/etc/confstr_spec.rb14
-rw-r--r--spec/ruby/library/etc/endgrent_spec.rb6
-rw-r--r--spec/ruby/library/etc/endpwent_spec.rb6
-rw-r--r--spec/ruby/library/etc/getgrent_spec.rb6
-rw-r--r--spec/ruby/library/etc/getgrgid_spec.rb87
-rw-r--r--spec/ruby/library/etc/getgrnam_spec.rb8
-rw-r--r--spec/ruby/library/etc/getlogin_spec.rb13
-rw-r--r--spec/ruby/library/etc/getpwent_spec.rb6
-rw-r--r--spec/ruby/library/etc/getpwnam_spec.rb6
-rw-r--r--spec/ruby/library/etc/getpwuid_spec.rb6
-rw-r--r--spec/ruby/library/etc/group_spec.rb19
-rw-r--r--spec/ruby/library/etc/nprocessors_spec.rb12
-rw-r--r--spec/ruby/library/etc/passwd_spec.rb15
-rw-r--r--spec/ruby/library/etc/struct_group_spec.rb10
-rw-r--r--spec/ruby/library/etc/struct_passwd_spec.rb4
-rw-r--r--spec/ruby/library/etc/sysconf_spec.rb22
-rw-r--r--spec/ruby/library/etc/sysconfdir_spec.rb8
-rw-r--r--spec/ruby/library/etc/systmpdir_spec.rb8
-rw-r--r--spec/ruby/library/etc/uname_spec.rb14
-rw-r--r--spec/ruby/library/expect/expect_spec.rb9
-rw-r--r--spec/ruby/library/fiber/alive_spec.rb48
-rw-r--r--spec/ruby/library/fiber/current_spec.rb53
-rw-r--r--spec/ruby/library/fiber/resume_spec.rb14
-rw-r--r--spec/ruby/library/fiber/transfer_spec.rb51
-rw-r--r--spec/ruby/library/fiddle/handle/initialize_spec.rb10
-rw-r--r--spec/ruby/library/find/find_spec.rb6
-rw-r--r--spec/ruby/library/find/fixtures/common.rb14
-rw-r--r--spec/ruby/library/find/prune_spec.rb2
-rw-r--r--spec/ruby/library/getoptlong/each_option_spec.rb20
-rw-r--r--spec/ruby/library/getoptlong/each_spec.rb7
-rw-r--r--spec/ruby/library/getoptlong/error_message_spec.rb4
-rw-r--r--spec/ruby/library/getoptlong/get_option_spec.rb7
-rw-r--r--spec/ruby/library/getoptlong/get_spec.rb64
-rw-r--r--spec/ruby/library/getoptlong/initialize_spec.rb2
-rw-r--r--spec/ruby/library/getoptlong/ordering_spec.rb10
-rw-r--r--spec/ruby/library/getoptlong/set_options_spec.rb30
-rw-r--r--spec/ruby/library/getoptlong/shared/each.rb18
-rw-r--r--spec/ruby/library/getoptlong/shared/get.rb64
-rw-r--r--spec/ruby/library/getoptlong/terminate_spec.rb4
-rw-r--r--spec/ruby/library/getoptlong/terminated_spec.rb8
-rw-r--r--spec/ruby/library/io-wait/wait_readable_spec.rb42
-rw-r--r--spec/ruby/library/io-wait/wait_spec.rb162
-rw-r--r--spec/ruby/library/io-wait/wait_writable_spec.rb37
-rw-r--r--spec/ruby/library/ipaddr/hton_spec.rb2
-rw-r--r--spec/ruby/library/ipaddr/ipv4_conversion_spec.rb12
-rw-r--r--spec/ruby/library/ipaddr/new_spec.rb21
-rw-r--r--spec/ruby/library/ipaddr/operator_spec.rb33
-rw-r--r--spec/ruby/library/ipaddr/reverse_spec.rb10
-rw-r--r--spec/ruby/library/ipaddr/to_s_spec.rb2
-rw-r--r--spec/ruby/library/irb/fixtures/irb.rb3
-rw-r--r--spec/ruby/library/irb/irb_spec.rb19
-rw-r--r--spec/ruby/library/logger/device/close_spec.rb6
-rw-r--r--spec/ruby/library/logger/device/new_spec.rb18
-rw-r--r--spec/ruby/library/logger/device/write_spec.rb6
-rw-r--r--spec/ruby/library/logger/logger/add_spec.rb16
-rw-r--r--spec/ruby/library/logger/logger/close_spec.rb6
-rw-r--r--spec/ruby/library/logger/logger/datetime_format_spec.rb6
-rw-r--r--spec/ruby/library/logger/logger/debug_spec.rb8
-rw-r--r--spec/ruby/library/logger/logger/error_spec.rb8
-rw-r--r--spec/ruby/library/logger/logger/fatal_spec.rb8
-rw-r--r--spec/ruby/library/logger/logger/info_spec.rb8
-rw-r--r--spec/ruby/library/logger/logger/new_spec.rb118
-rw-r--r--spec/ruby/library/logger/logger/unknown_spec.rb6
-rw-r--r--spec/ruby/library/logger/logger/warn_spec.rb8
-rw-r--r--spec/ruby/library/logger/severity_spec.rb2
-rw-r--r--spec/ruby/library/mathn/bignum/exponent_spec.rb21
-rw-r--r--spec/ruby/library/mathn/complex/Complex_spec.rb14
-rw-r--r--spec/ruby/library/mathn/fixnum/exponent_spec.rb17
-rw-r--r--spec/ruby/library/mathn/float/exponent_spec.rb17
-rw-r--r--spec/ruby/library/mathn/integer/from_prime_division_spec.rb11
-rw-r--r--spec/ruby/library/mathn/integer/prime_division_spec.rb21
-rw-r--r--spec/ruby/library/mathn/math/fixtures/classes.rb3
-rw-r--r--spec/ruby/library/mathn/math/rsqrt_spec.rb17
-rw-r--r--spec/ruby/library/mathn/math/shared/rsqrt.rb21
-rw-r--r--spec/ruby/library/mathn/math/shared/sqrt.rb25
-rw-r--r--spec/ruby/library/mathn/math/sqrt_spec.rb17
-rw-r--r--spec/ruby/library/mathn/rational/Rational_spec.rb14
-rw-r--r--spec/ruby/library/mathn/rational/inspect_spec.rb15
-rw-r--r--spec/ruby/library/matrix/I_spec.rb8
-rw-r--r--spec/ruby/library/matrix/antisymmetric_spec.rb36
-rw-r--r--spec/ruby/library/matrix/build_spec.rb24
-rw-r--r--spec/ruby/library/matrix/clone_spec.rb12
-rw-r--r--spec/ruby/library/matrix/coerce_spec.rb6
-rw-r--r--spec/ruby/library/matrix/collect_spec.rb8
-rw-r--r--spec/ruby/library/matrix/column_size_spec.rb2
-rw-r--r--spec/ruby/library/matrix/column_spec.rb8
-rw-r--r--spec/ruby/library/matrix/column_vector_spec.rb10
-rw-r--r--spec/ruby/library/matrix/column_vectors_spec.rb6
-rw-r--r--spec/ruby/library/matrix/columns_spec.rb8
-rw-r--r--spec/ruby/library/matrix/conj_spec.rb8
-rw-r--r--spec/ruby/library/matrix/conjugate_spec.rb20
-rw-r--r--spec/ruby/library/matrix/constructor_spec.rb24
-rw-r--r--spec/ruby/library/matrix/det_spec.rb7
-rw-r--r--spec/ruby/library/matrix/determinant_spec.rb38
-rw-r--r--spec/ruby/library/matrix/diagonal_spec.rb22
-rw-r--r--spec/ruby/library/matrix/divide_spec.rb27
-rw-r--r--spec/ruby/library/matrix/each_spec.rb18
-rw-r--r--spec/ruby/library/matrix/each_with_index_spec.rb18
-rw-r--r--spec/ruby/library/matrix/eigenvalue_decomposition/eigenvalue_matrix_spec.rb2
-rw-r--r--spec/ruby/library/matrix/eigenvalue_decomposition/eigenvalues_spec.rb4
-rw-r--r--spec/ruby/library/matrix/eigenvalue_decomposition/eigenvector_matrix_spec.rb4
-rw-r--r--spec/ruby/library/matrix/eigenvalue_decomposition/eigenvectors_spec.rb4
-rw-r--r--spec/ruby/library/matrix/eigenvalue_decomposition/initialize_spec.rb14
-rw-r--r--spec/ruby/library/matrix/eigenvalue_decomposition/to_a_spec.rb2
-rw-r--r--spec/ruby/library/matrix/element_reference_spec.rb6
-rw-r--r--spec/ruby/library/matrix/empty_spec.rb36
-rw-r--r--spec/ruby/library/matrix/eql_spec.rb8
-rw-r--r--spec/ruby/library/matrix/equal_value_spec.rb6
-rw-r--r--spec/ruby/library/matrix/exponent_spec.rb29
-rw-r--r--spec/ruby/library/matrix/find_index_spec.rb26
-rw-r--r--spec/ruby/library/matrix/hash_spec.rb6
-rw-r--r--spec/ruby/library/matrix/hermitian_spec.rb16
-rw-r--r--spec/ruby/library/matrix/identity_spec.rb20
-rw-r--r--spec/ruby/library/matrix/imag_spec.rb8
-rw-r--r--spec/ruby/library/matrix/imaginary_spec.rb21
-rw-r--r--spec/ruby/library/matrix/inspect_spec.rb4
-rw-r--r--spec/ruby/library/matrix/inv_spec.rb9
-rw-r--r--spec/ruby/library/matrix/inverse_from_spec.rb2
-rw-r--r--spec/ruby/library/matrix/inverse_spec.rb40
-rw-r--r--spec/ruby/library/matrix/lower_triangular_spec.rb24
-rw-r--r--spec/ruby/library/matrix/lup_decomposition/determinant_spec.rb6
-rw-r--r--spec/ruby/library/matrix/lup_decomposition/initialize_spec.rb10
-rw-r--r--spec/ruby/library/matrix/lup_decomposition/l_spec.rb4
-rw-r--r--spec/ruby/library/matrix/lup_decomposition/p_spec.rb4
-rw-r--r--spec/ruby/library/matrix/lup_decomposition/solve_spec.rb14
-rw-r--r--spec/ruby/library/matrix/lup_decomposition/to_a_spec.rb6
-rw-r--r--spec/ruby/library/matrix/lup_decomposition/u_spec.rb4
-rw-r--r--spec/ruby/library/matrix/map_spec.rb26
-rw-r--r--spec/ruby/library/matrix/minor_spec.rb6
-rw-r--r--spec/ruby/library/matrix/minus_spec.rb24
-rw-r--r--spec/ruby/library/matrix/multiply_spec.rb23
-rw-r--r--spec/ruby/library/matrix/new_spec.rb4
-rw-r--r--spec/ruby/library/matrix/normal_spec.rb12
-rw-r--r--spec/ruby/library/matrix/orthogonal_spec.rb12
-rw-r--r--spec/ruby/library/matrix/permutation_spec.rb18
-rw-r--r--spec/ruby/library/matrix/plus_spec.rb24
-rw-r--r--spec/ruby/library/matrix/rank_spec.rb2
-rw-r--r--spec/ruby/library/matrix/real_spec.rb19
-rw-r--r--spec/ruby/library/matrix/rect_spec.rb8
-rw-r--r--spec/ruby/library/matrix/rectangular_spec.rb19
-rw-r--r--spec/ruby/library/matrix/regular_spec.rb18
-rw-r--r--spec/ruby/library/matrix/round_spec.rb6
-rw-r--r--spec/ruby/library/matrix/row_size_spec.rb2
-rw-r--r--spec/ruby/library/matrix/row_spec.rb8
-rw-r--r--spec/ruby/library/matrix/row_vector_spec.rb8
-rw-r--r--spec/ruby/library/matrix/row_vectors_spec.rb6
-rw-r--r--spec/ruby/library/matrix/rows_spec.rb12
-rw-r--r--spec/ruby/library/matrix/scalar/Fail_spec.rb2
-rw-r--r--spec/ruby/library/matrix/scalar/Raise_spec.rb2
-rw-r--r--spec/ruby/library/matrix/scalar/divide_spec.rb2
-rw-r--r--spec/ruby/library/matrix/scalar/exponent_spec.rb2
-rw-r--r--spec/ruby/library/matrix/scalar/included_spec.rb2
-rw-r--r--spec/ruby/library/matrix/scalar/initialize_spec.rb2
-rw-r--r--spec/ruby/library/matrix/scalar/minus_spec.rb2
-rw-r--r--spec/ruby/library/matrix/scalar/multiply_spec.rb2
-rw-r--r--spec/ruby/library/matrix/scalar/plus_spec.rb2
-rw-r--r--spec/ruby/library/matrix/scalar_spec.rb6
-rw-r--r--spec/ruby/library/matrix/shared/collect.rb26
-rw-r--r--spec/ruby/library/matrix/shared/conjugate.rb20
-rw-r--r--spec/ruby/library/matrix/shared/determinant.rb38
-rw-r--r--spec/ruby/library/matrix/shared/equal_value.rb22
-rw-r--r--spec/ruby/library/matrix/shared/identity.rb19
-rw-r--r--spec/ruby/library/matrix/shared/imaginary.rb20
-rw-r--r--spec/ruby/library/matrix/shared/inverse.rb38
-rw-r--r--spec/ruby/library/matrix/shared/rectangular.rb18
-rw-r--r--spec/ruby/library/matrix/shared/trace.rb12
-rw-r--r--spec/ruby/library/matrix/shared/transpose.rb19
-rw-r--r--spec/ruby/library/matrix/singular_spec.rb18
-rw-r--r--spec/ruby/library/matrix/square_spec.rb18
-rw-r--r--spec/ruby/library/matrix/symmetric_spec.rb12
-rw-r--r--spec/ruby/library/matrix/t_spec.rb10
-rw-r--r--spec/ruby/library/matrix/to_a_spec.rb2
-rw-r--r--spec/ruby/library/matrix/to_s_spec.rb2
-rw-r--r--spec/ruby/library/matrix/tr_spec.rb7
-rw-r--r--spec/ruby/library/matrix/trace_spec.rb11
-rw-r--r--spec/ruby/library/matrix/transpose_spec.rb19
-rw-r--r--spec/ruby/library/matrix/unit_spec.rb8
-rw-r--r--spec/ruby/library/matrix/unitary_spec.rb20
-rw-r--r--spec/ruby/library/matrix/upper_triangular_spec.rb24
-rw-r--r--spec/ruby/library/matrix/vector/cross_product_spec.rb6
-rw-r--r--spec/ruby/library/matrix/vector/each2_spec.rb14
-rw-r--r--spec/ruby/library/matrix/vector/eql_spec.rb6
-rw-r--r--spec/ruby/library/matrix/vector/inner_product_spec.rb6
-rw-r--r--spec/ruby/library/matrix/vector/normalize_spec.rb10
-rw-r--r--spec/ruby/library/matrix/zero_spec.rb18
-rw-r--r--spec/ruby/library/mkmf/mkmf_spec.rb7
-rw-r--r--spec/ruby/library/monitor/enter_spec.rb28
-rw-r--r--spec/ruby/library/monitor/exit_spec.rb10
-rw-r--r--spec/ruby/library/monitor/mon_initialize_spec.rb31
-rw-r--r--spec/ruby/library/monitor/new_cond_spec.rb88
-rw-r--r--spec/ruby/library/monitor/synchronize_spec.rb41
-rw-r--r--spec/ruby/library/monitor/try_enter_spec.rb39
-rw-r--r--spec/ruby/library/net-ftp/FTPError_spec.rb11
-rw-r--r--spec/ruby/library/net-ftp/FTPPermError_spec.rb15
-rw-r--r--spec/ruby/library/net-ftp/FTPProtoError_spec.rb15
-rw-r--r--spec/ruby/library/net-ftp/FTPReplyError_spec.rb15
-rw-r--r--spec/ruby/library/net-ftp/FTPTempError_spec.rb15
-rw-r--r--spec/ruby/library/net-ftp/abort_spec.rb65
-rw-r--r--spec/ruby/library/net-ftp/acct_spec.rb61
-rw-r--r--spec/ruby/library/net-ftp/binary_spec.rb27
-rw-r--r--spec/ruby/library/net-ftp/chdir_spec.rb102
-rw-r--r--spec/ruby/library/net-ftp/close_spec.rb33
-rw-r--r--spec/ruby/library/net-ftp/closed_spec.rb24
-rw-r--r--spec/ruby/library/net-ftp/connect_spec.rb46
-rw-r--r--spec/ruby/library/net-ftp/debug_mode_spec.rb26
-rw-r--r--spec/ruby/library/net-ftp/default_passive_spec.rb11
-rw-r--r--spec/ruby/library/net-ftp/delete_spec.rb62
-rw-r--r--spec/ruby/library/net-ftp/dir_spec.rb11
-rw-r--r--spec/ruby/library/net-ftp/fixtures/default_passive.rb (renamed from spec/ruby/library/net/ftp/fixtures/default_passive.rb)0
-rw-r--r--spec/ruby/library/net-ftp/fixtures/passive.rb (renamed from spec/ruby/library/net/ftp/fixtures/passive.rb)0
-rw-r--r--spec/ruby/library/net-ftp/fixtures/putbinaryfile (renamed from spec/ruby/library/net/ftp/fixtures/putbinaryfile)0
-rw-r--r--spec/ruby/library/net-ftp/fixtures/puttextfile (renamed from spec/ruby/library/net/ftp/fixtures/puttextfile)0
-rw-r--r--spec/ruby/library/net-ftp/fixtures/server.rb279
-rw-r--r--spec/ruby/library/net-ftp/get_spec.rb24
-rw-r--r--spec/ruby/library/net-ftp/getbinaryfile_spec.rb11
-rw-r--r--spec/ruby/library/net-ftp/getdir_spec.rb10
-rw-r--r--spec/ruby/library/net-ftp/gettextfile_spec.rb11
-rw-r--r--spec/ruby/library/net-ftp/help_spec.rb69
-rw-r--r--spec/ruby/library/net-ftp/initialize_spec.rb408
-rw-r--r--spec/ruby/library/net-ftp/last_response_code_spec.rb11
-rw-r--r--spec/ruby/library/net-ftp/last_response_spec.rb28
-rw-r--r--spec/ruby/library/net-ftp/lastresp_spec.rb11
-rw-r--r--spec/ruby/library/net-ftp/list_spec.rb11
-rw-r--r--spec/ruby/library/net-ftp/login_spec.rb198
-rw-r--r--spec/ruby/library/net-ftp/ls_spec.rb11
-rw-r--r--spec/ruby/library/net-ftp/mdtm_spec.rb41
-rw-r--r--spec/ruby/library/net-ftp/mkdir_spec.rb64
-rw-r--r--spec/ruby/library/net-ftp/mtime_spec.rb53
-rw-r--r--spec/ruby/library/net-ftp/nlst_spec.rb95
-rw-r--r--spec/ruby/library/net-ftp/noop_spec.rb41
-rw-r--r--spec/ruby/library/net-ftp/open_spec.rb58
-rw-r--r--spec/ruby/library/net-ftp/passive_spec.rb31
-rw-r--r--spec/ruby/library/net-ftp/put_spec.rb24
-rw-r--r--spec/ruby/library/net-ftp/putbinaryfile_spec.rb11
-rw-r--r--spec/ruby/library/net-ftp/puttextfile_spec.rb11
-rw-r--r--spec/ruby/library/net-ftp/pwd_spec.rb56
-rw-r--r--spec/ruby/library/net-ftp/quit_spec.rb36
-rw-r--r--spec/ruby/library/net-ftp/rename_spec.rb97
-rw-r--r--spec/ruby/library/net-ftp/resume_spec.rb26
-rw-r--r--spec/ruby/library/net-ftp/retrbinary_spec.rb33
-rw-r--r--spec/ruby/library/net-ftp/retrlines_spec.rb37
-rw-r--r--spec/ruby/library/net-ftp/return_code_spec.rb27
-rw-r--r--spec/ruby/library/net-ftp/rmdir_spec.rb61
-rw-r--r--spec/ruby/library/net-ftp/sendcmd_spec.rb57
-rw-r--r--spec/ruby/library/net-ftp/set_socket_spec.rb11
-rw-r--r--spec/ruby/library/net-ftp/shared/getbinaryfile.rb152
-rw-r--r--spec/ruby/library/net-ftp/shared/gettextfile.rb102
-rw-r--r--spec/ruby/library/net-ftp/shared/last_response_code.rb27
-rw-r--r--spec/ruby/library/net-ftp/shared/list.rb106
-rw-r--r--spec/ruby/library/net-ftp/shared/putbinaryfile.rb169
-rw-r--r--spec/ruby/library/net-ftp/shared/puttextfile.rb130
-rw-r--r--spec/ruby/library/net-ftp/shared/pwd.rb5
-rw-r--r--spec/ruby/library/net-ftp/site_spec.rb56
-rw-r--r--spec/ruby/library/net-ftp/size_spec.rb51
-rw-r--r--spec/ruby/library/net-ftp/spec_helper.rb7
-rw-r--r--spec/ruby/library/net-ftp/status_spec.rb70
-rw-r--r--spec/ruby/library/net-ftp/storbinary_spec.rb52
-rw-r--r--spec/ruby/library/net-ftp/storlines_spec.rb47
-rw-r--r--spec/ruby/library/net-ftp/system_spec.rb51
-rw-r--r--spec/ruby/library/net-ftp/voidcmd_spec.rb57
-rw-r--r--spec/ruby/library/net-ftp/welcome_spec.rb28
-rw-r--r--spec/ruby/library/net-http/HTTPBadResponse_spec.rb8
-rw-r--r--spec/ruby/library/net-http/HTTPClientExcepton_spec.rb12
-rw-r--r--spec/ruby/library/net-http/HTTPError_spec.rb12
-rw-r--r--spec/ruby/library/net-http/HTTPFatalError_spec.rb12
-rw-r--r--spec/ruby/library/net-http/HTTPHeaderSyntaxError_spec.rb8
-rw-r--r--spec/ruby/library/net-http/HTTPRetriableError_spec.rb12
-rw-r--r--spec/ruby/library/net-http/HTTPServerException_spec.rb12
-rw-r--r--spec/ruby/library/net-http/http/Proxy_spec.rb35
-rw-r--r--spec/ruby/library/net-http/http/active_spec.rb8
-rw-r--r--spec/ruby/library/net-http/http/address_spec.rb9
-rw-r--r--spec/ruby/library/net-http/http/close_on_empty_response_spec.rb10
-rw-r--r--spec/ruby/library/net-http/http/copy_spec.rb21
-rw-r--r--spec/ruby/library/net-http/http/default_port_spec.rb8
-rw-r--r--spec/ruby/library/net-http/http/delete_spec.rb21
-rw-r--r--spec/ruby/library/net-http/http/finish_spec.rb29
-rw-r--r--spec/ruby/library/net-http/http/fixtures/http_server.rb123
-rw-r--r--spec/ruby/library/net-http/http/get2_spec.rb8
-rw-r--r--spec/ruby/library/net-http/http/get_print_spec.rb30
-rw-r--r--spec/ruby/library/net-http/http/get_response_spec.rb30
-rw-r--r--spec/ruby/library/net-http/http/get_spec.rb94
-rw-r--r--spec/ruby/library/net-http/http/head2_spec.rb8
-rw-r--r--spec/ruby/library/net-http/http/head_spec.rb25
-rw-r--r--spec/ruby/library/net-http/http/http_default_port_spec.rb8
-rw-r--r--spec/ruby/library/net-http/http/https_default_port_spec.rb8
-rw-r--r--spec/ruby/library/net-http/http/initialize_spec.rb46
-rw-r--r--spec/ruby/library/net-http/http/inspect_spec.rb24
-rw-r--r--spec/ruby/library/net-http/http/is_version_1_1_spec.rb8
-rw-r--r--spec/ruby/library/net-http/http/is_version_1_2_spec.rb8
-rw-r--r--spec/ruby/library/net-http/http/lock_spec.rb21
-rw-r--r--spec/ruby/library/net-http/http/mkcol_spec.rb21
-rw-r--r--spec/ruby/library/net-http/http/move_spec.rb25
-rw-r--r--spec/ruby/library/net-http/http/new_spec.rb86
-rw-r--r--spec/ruby/library/net-http/http/newobj_spec.rb48
-rw-r--r--spec/ruby/library/net-http/http/open_timeout_spec.rb24
-rw-r--r--spec/ruby/library/net-http/http/options_spec.rb25
-rw-r--r--spec/ruby/library/net-http/http/port_spec.rb9
-rw-r--r--spec/ruby/library/net-http/http/post2_spec.rb8
-rw-r--r--spec/ruby/library/net-http/http/post_form_spec.rb22
-rw-r--r--spec/ruby/library/net-http/http/post_spec.rb76
-rw-r--r--spec/ruby/library/net-http/http/propfind_spec.rb24
-rw-r--r--spec/ruby/library/net-http/http/proppatch_spec.rb24
-rw-r--r--spec/ruby/library/net-http/http/proxy_address_spec.rb31
-rw-r--r--spec/ruby/library/net-http/http/proxy_class_spec.rb9
-rw-r--r--spec/ruby/library/net-http/http/proxy_pass_spec.rb39
-rw-r--r--spec/ruby/library/net-http/http/proxy_port_spec.rb39
-rw-r--r--spec/ruby/library/net-http/http/proxy_user_spec.rb39
-rw-r--r--spec/ruby/library/net-http/http/put2_spec.rb8
-rw-r--r--spec/ruby/library/net-http/http/put_spec.rb24
-rw-r--r--spec/ruby/library/net-http/http/read_timeout_spec.rb24
-rw-r--r--spec/ruby/library/net-http/http/request_get_spec.rb45
-rw-r--r--spec/ruby/library/net-http/http/request_head_spec.rb45
-rw-r--r--spec/ruby/library/net-http/http/request_post_spec.rb45
-rw-r--r--spec/ruby/library/net-http/http/request_put_spec.rb45
-rw-r--r--spec/ruby/library/net-http/http/request_spec.rb109
-rw-r--r--spec/ruby/library/net-http/http/request_types_spec.rb254
-rw-r--r--spec/ruby/library/net-http/http/send_request_spec.rb61
-rw-r--r--spec/ruby/library/net-http/http/set_debug_output_spec.rb33
-rw-r--r--spec/ruby/library/net-http/http/socket_type_spec.rb8
-rw-r--r--spec/ruby/library/net-http/http/start_spec.rb111
-rw-r--r--spec/ruby/library/net-http/http/started_spec.rb30
-rw-r--r--spec/ruby/library/net-http/http/trace_spec.rb24
-rw-r--r--spec/ruby/library/net-http/http/unlock_spec.rb24
-rw-r--r--spec/ruby/library/net-http/http/use_ssl_spec.rb9
-rw-r--r--spec/ruby/library/net-http/http/version_1_1_spec.rb9
-rw-r--r--spec/ruby/library/net-http/http/version_1_2_spec.rb22
-rw-r--r--spec/ruby/library/net-http/httpexceptions/fixtures/classes.rb (renamed from spec/ruby/library/net/http/httpexceptions/fixtures/classes.rb)0
-rw-r--r--spec/ruby/library/net-http/httpexceptions/initialize_spec.rb17
-rw-r--r--spec/ruby/library/net-http/httpexceptions/response_spec.rb10
-rw-r--r--spec/ruby/library/net-http/httpgenericrequest/body_exist_spec.rb21
-rw-r--r--spec/ruby/library/net-http/httpgenericrequest/body_spec.rb30
-rw-r--r--spec/ruby/library/net-http/httpgenericrequest/body_stream_spec.rb32
-rw-r--r--spec/ruby/library/net-http/httpgenericrequest/exec_spec.rb135
-rw-r--r--spec/ruby/library/net-http/httpgenericrequest/inspect_spec.rb25
-rw-r--r--spec/ruby/library/net-http/httpgenericrequest/method_spec.rb15
-rw-r--r--spec/ruby/library/net-http/httpgenericrequest/path_spec.rb12
-rw-r--r--spec/ruby/library/net-http/httpgenericrequest/request_body_permitted_spec.rb12
-rw-r--r--spec/ruby/library/net-http/httpgenericrequest/response_body_permitted_spec.rb12
-rw-r--r--spec/ruby/library/net-http/httpgenericrequest/set_body_internal_spec.rb21
-rw-r--r--spec/ruby/library/net-http/httpheader/add_field_spec.rb31
-rw-r--r--spec/ruby/library/net-http/httpheader/basic_auth_spec.rb14
-rw-r--r--spec/ruby/library/net-http/httpheader/canonical_each_spec.rb9
-rw-r--r--spec/ruby/library/net-http/httpheader/chunked_spec.rb22
-rw-r--r--spec/ruby/library/net-http/httpheader/content_length_spec.rb54
-rw-r--r--spec/ruby/library/net-http/httpheader/content_range_spec.rb32
-rw-r--r--spec/ruby/library/net-http/httpheader/content_type_spec.rb28
-rw-r--r--spec/ruby/library/net-http/httpheader/delete_spec.rb30
-rw-r--r--spec/ruby/library/net-http/httpheader/each_capitalized_name_spec.rb35
-rw-r--r--spec/ruby/library/net-http/httpheader/each_capitalized_spec.rb35
-rw-r--r--spec/ruby/library/net-http/httpheader/each_header_spec.rb35
-rw-r--r--spec/ruby/library/net-http/httpheader/each_key_spec.rb35
-rw-r--r--spec/ruby/library/net-http/httpheader/each_name_spec.rb10
-rw-r--r--spec/ruby/library/net-http/httpheader/each_spec.rb9
-rw-r--r--spec/ruby/library/net-http/httpheader/each_value_spec.rb35
-rw-r--r--spec/ruby/library/net-http/httpheader/element_reference_spec.rb39
-rw-r--r--spec/ruby/library/net-http/httpheader/element_set_spec.rb41
-rw-r--r--spec/ruby/library/net-http/httpheader/fetch_spec.rb68
-rw-r--r--spec/ruby/library/net-http/httpheader/fixtures/classes.rb (renamed from spec/ruby/library/net/http/httpheader/fixtures/classes.rb)0
-rw-r--r--spec/ruby/library/net-http/httpheader/form_data_spec.rb10
-rw-r--r--spec/ruby/library/net-http/httpheader/get_fields_spec.rb39
-rw-r--r--spec/ruby/library/net-http/httpheader/initialize_http_header_spec.rb21
-rw-r--r--spec/ruby/library/net-http/httpheader/key_spec.rb21
-rw-r--r--spec/ruby/library/net-http/httpheader/length_spec.rb9
-rw-r--r--spec/ruby/library/net-http/httpheader/main_type_spec.rb24
-rw-r--r--spec/ruby/library/net-http/httpheader/proxy_basic_auth_spec.rb14
-rw-r--r--spec/ruby/library/net-http/httpheader/range_length_spec.rb32
-rw-r--r--spec/ruby/library/net-http/httpheader/range_spec.rb50
-rw-r--r--spec/ruby/library/net-http/httpheader/set_content_type_spec.rb22
-rw-r--r--spec/ruby/library/net-http/httpheader/set_form_data_spec.rb31
-rw-r--r--spec/ruby/library/net-http/httpheader/set_range_spec.rb93
-rw-r--r--spec/ruby/library/net-http/httpheader/size_spec.rb22
-rw-r--r--spec/ruby/library/net-http/httpheader/sub_type_spec.rb32
-rw-r--r--spec/ruby/library/net-http/httpheader/to_hash_spec.rb25
-rw-r--r--spec/ruby/library/net-http/httpheader/type_params_spec.rb24
-rw-r--r--spec/ruby/library/net-http/httprequest/initialize_spec.rb45
-rw-r--r--spec/ruby/library/net-http/httpresponse/body_permitted_spec.rb13
-rw-r--r--spec/ruby/library/net-http/httpresponse/body_spec.rb22
-rw-r--r--spec/ruby/library/net-http/httpresponse/code_spec.rb24
-rw-r--r--spec/ruby/library/net-http/httpresponse/code_type_spec.rb24
-rw-r--r--spec/ruby/library/net-http/httpresponse/entity_spec.rb9
-rw-r--r--spec/ruby/library/net-http/httpresponse/error_spec.rb24
-rw-r--r--spec/ruby/library/net-http/httpresponse/error_type_spec.rb24
-rw-r--r--spec/ruby/library/net-http/httpresponse/exception_type_spec.rb13
-rw-r--r--spec/ruby/library/net-http/httpresponse/header_spec.rb9
-rw-r--r--spec/ruby/library/net-http/httpresponse/http_version_spec.rb12
-rw-r--r--spec/ruby/library/net-http/httpresponse/initialize_spec.rb11
-rw-r--r--spec/ruby/library/net-http/httpresponse/inspect_spec.rb15
-rw-r--r--spec/ruby/library/net-http/httpresponse/message_spec.rb9
-rw-r--r--spec/ruby/library/net-http/httpresponse/msg_spec.rb9
-rw-r--r--spec/ruby/library/net-http/httpresponse/read_body_spec.rb86
-rw-r--r--spec/ruby/library/net-http/httpresponse/read_header_spec.rb9
-rw-r--r--spec/ruby/library/net-http/httpresponse/read_new_spec.rb23
-rw-r--r--spec/ruby/library/net-http/httpresponse/reading_body_spec.rb58
-rw-r--r--spec/ruby/library/net-http/httpresponse/response_spec.rb9
-rw-r--r--spec/ruby/library/net-http/httpresponse/value_spec.rb24
-rw-r--r--spec/ruby/library/net/FTPError_spec.rb8
-rw-r--r--spec/ruby/library/net/FTPPermError_spec.rb12
-rw-r--r--spec/ruby/library/net/FTPProtoError_spec.rb12
-rw-r--r--spec/ruby/library/net/FTPReplyError_spec.rb12
-rw-r--r--spec/ruby/library/net/FTPTempError_spec.rb12
-rw-r--r--spec/ruby/library/net/ftp/abort_spec.rb62
-rw-r--r--spec/ruby/library/net/ftp/acct_spec.rb58
-rw-r--r--spec/ruby/library/net/ftp/binary_spec.rb24
-rw-r--r--spec/ruby/library/net/ftp/chdir_spec.rb99
-rw-r--r--spec/ruby/library/net/ftp/close_spec.rb30
-rw-r--r--spec/ruby/library/net/ftp/closed_spec.rb21
-rw-r--r--spec/ruby/library/net/ftp/connect_spec.rb49
-rw-r--r--spec/ruby/library/net/ftp/debug_mode_spec.rb23
-rw-r--r--spec/ruby/library/net/ftp/default_passive_spec.rb10
-rw-r--r--spec/ruby/library/net/ftp/delete_spec.rb59
-rw-r--r--spec/ruby/library/net/ftp/dir_spec.rb8
-rw-r--r--spec/ruby/library/net/ftp/fixtures/server.rb277
-rw-r--r--spec/ruby/library/net/ftp/get_spec.rb21
-rw-r--r--spec/ruby/library/net/ftp/getbinaryfile_spec.rb8
-rw-r--r--spec/ruby/library/net/ftp/getdir_spec.rb7
-rw-r--r--spec/ruby/library/net/ftp/gettextfile_spec.rb8
-rw-r--r--spec/ruby/library/net/ftp/help_spec.rb66
-rw-r--r--spec/ruby/library/net/ftp/initialize_spec.rb91
-rw-r--r--spec/ruby/library/net/ftp/last_response_code_spec.rb8
-rw-r--r--spec/ruby/library/net/ftp/last_response_spec.rb25
-rw-r--r--spec/ruby/library/net/ftp/lastresp_spec.rb8
-rw-r--r--spec/ruby/library/net/ftp/list_spec.rb8
-rw-r--r--spec/ruby/library/net/ftp/login_spec.rb195
-rw-r--r--spec/ruby/library/net/ftp/ls_spec.rb8
-rw-r--r--spec/ruby/library/net/ftp/mdtm_spec.rb38
-rw-r--r--spec/ruby/library/net/ftp/mkdir_spec.rb61
-rw-r--r--spec/ruby/library/net/ftp/mtime_spec.rb50
-rw-r--r--spec/ruby/library/net/ftp/nlst_spec.rb92
-rw-r--r--spec/ruby/library/net/ftp/noop_spec.rb38
-rw-r--r--spec/ruby/library/net/ftp/open_spec.rb55
-rw-r--r--spec/ruby/library/net/ftp/passive_spec.rb36
-rw-r--r--spec/ruby/library/net/ftp/put_spec.rb21
-rw-r--r--spec/ruby/library/net/ftp/putbinaryfile_spec.rb8
-rw-r--r--spec/ruby/library/net/ftp/puttextfile_spec.rb8
-rw-r--r--spec/ruby/library/net/ftp/pwd_spec.rb53
-rw-r--r--spec/ruby/library/net/ftp/quit_spec.rb33
-rw-r--r--spec/ruby/library/net/ftp/rename_spec.rb94
-rw-r--r--spec/ruby/library/net/ftp/resume_spec.rb23
-rw-r--r--spec/ruby/library/net/ftp/retrbinary_spec.rb30
-rw-r--r--spec/ruby/library/net/ftp/retrlines_spec.rb34
-rw-r--r--spec/ruby/library/net/ftp/return_code_spec.rb24
-rw-r--r--spec/ruby/library/net/ftp/rmdir_spec.rb58
-rw-r--r--spec/ruby/library/net/ftp/sendcmd_spec.rb54
-rw-r--r--spec/ruby/library/net/ftp/set_socket_spec.rb8
-rw-r--r--spec/ruby/library/net/ftp/shared/getbinaryfile.rb150
-rw-r--r--spec/ruby/library/net/ftp/shared/gettextfile.rb100
-rw-r--r--spec/ruby/library/net/ftp/shared/last_response_code.rb25
-rw-r--r--spec/ruby/library/net/ftp/shared/list.rb104
-rw-r--r--spec/ruby/library/net/ftp/shared/putbinaryfile.rb167
-rw-r--r--spec/ruby/library/net/ftp/shared/puttextfile.rb120
-rw-r--r--spec/ruby/library/net/ftp/shared/pwd.rb3
-rw-r--r--spec/ruby/library/net/ftp/site_spec.rb53
-rw-r--r--spec/ruby/library/net/ftp/size_spec.rb48
-rw-r--r--spec/ruby/library/net/ftp/spec_helper.rb5
-rw-r--r--spec/ruby/library/net/ftp/status_spec.rb69
-rw-r--r--spec/ruby/library/net/ftp/storbinary_spec.rb48
-rw-r--r--spec/ruby/library/net/ftp/storlines_spec.rb43
-rw-r--r--spec/ruby/library/net/ftp/system_spec.rb48
-rw-r--r--spec/ruby/library/net/ftp/voidcmd_spec.rb54
-rw-r--r--spec/ruby/library/net/ftp/welcome_spec.rb25
-rw-r--r--spec/ruby/library/net/http/HTTPBadResponse_spec.rb8
-rw-r--r--spec/ruby/library/net/http/HTTPError_spec.rb12
-rw-r--r--spec/ruby/library/net/http/HTTPFatalError_spec.rb12
-rw-r--r--spec/ruby/library/net/http/HTTPHeaderSyntaxError_spec.rb8
-rw-r--r--spec/ruby/library/net/http/HTTPRetriableError_spec.rb12
-rw-r--r--spec/ruby/library/net/http/HTTPServerException_spec.rb12
-rw-r--r--spec/ruby/library/net/http/http/Proxy_spec.rb35
-rw-r--r--spec/ruby/library/net/http/http/active_spec.rb8
-rw-r--r--spec/ruby/library/net/http/http/address_spec.rb9
-rw-r--r--spec/ruby/library/net/http/http/close_on_empty_response_spec.rb10
-rw-r--r--spec/ruby/library/net/http/http/copy_spec.rb21
-rw-r--r--spec/ruby/library/net/http/http/default_port_spec.rb8
-rw-r--r--spec/ruby/library/net/http/http/delete_spec.rb21
-rw-r--r--spec/ruby/library/net/http/http/finish_spec.rb29
-rw-r--r--spec/ruby/library/net/http/http/fixtures/http_server.rb105
-rw-r--r--spec/ruby/library/net/http/http/get2_spec.rb8
-rw-r--r--spec/ruby/library/net/http/http/get_print_spec.rb30
-rw-r--r--spec/ruby/library/net/http/http/get_response_spec.rb30
-rw-r--r--spec/ruby/library/net/http/http/get_spec.rb26
-rw-r--r--spec/ruby/library/net/http/http/head2_spec.rb9
-rw-r--r--spec/ruby/library/net/http/http/head_spec.rb25
-rw-r--r--spec/ruby/library/net/http/http/http_default_port_spec.rb8
-rw-r--r--spec/ruby/library/net/http/http/https_default_port_spec.rb8
-rw-r--r--spec/ruby/library/net/http/http/initialize_spec.rb46
-rw-r--r--spec/ruby/library/net/http/http/inspect_spec.rb24
-rw-r--r--spec/ruby/library/net/http/http/is_version_1_1_spec.rb7
-rw-r--r--spec/ruby/library/net/http/http/is_version_1_2_spec.rb7
-rw-r--r--spec/ruby/library/net/http/http/lock_spec.rb21
-rw-r--r--spec/ruby/library/net/http/http/mkcol_spec.rb21
-rw-r--r--spec/ruby/library/net/http/http/move_spec.rb25
-rw-r--r--spec/ruby/library/net/http/http/new_spec.rb86
-rw-r--r--spec/ruby/library/net/http/http/newobj_spec.rb48
-rw-r--r--spec/ruby/library/net/http/http/open_timeout_spec.rb35
-rw-r--r--spec/ruby/library/net/http/http/options_spec.rb25
-rw-r--r--spec/ruby/library/net/http/http/port_spec.rb9
-rw-r--r--spec/ruby/library/net/http/http/post2_spec.rb8
-rw-r--r--spec/ruby/library/net/http/http/post_form_spec.rb22
-rw-r--r--spec/ruby/library/net/http/http/post_spec.rb77
-rw-r--r--spec/ruby/library/net/http/http/propfind_spec.rb24
-rw-r--r--spec/ruby/library/net/http/http/proppatch_spec.rb24
-rw-r--r--spec/ruby/library/net/http/http/proxy_address_spec.rb31
-rw-r--r--spec/ruby/library/net/http/http/proxy_class_spec.rb9
-rw-r--r--spec/ruby/library/net/http/http/proxy_pass_spec.rb39
-rw-r--r--spec/ruby/library/net/http/http/proxy_port_spec.rb39
-rw-r--r--spec/ruby/library/net/http/http/proxy_user_spec.rb39
-rw-r--r--spec/ruby/library/net/http/http/put2_spec.rb8
-rw-r--r--spec/ruby/library/net/http/http/put_spec.rb24
-rw-r--r--spec/ruby/library/net/http/http/read_timeout_spec.rb24
-rw-r--r--spec/ruby/library/net/http/http/request_get_spec.rb8
-rw-r--r--spec/ruby/library/net/http/http/request_head_spec.rb8
-rw-r--r--spec/ruby/library/net/http/http/request_post_spec.rb8
-rw-r--r--spec/ruby/library/net/http/http/request_put_spec.rb8
-rw-r--r--spec/ruby/library/net/http/http/request_spec.rb109
-rw-r--r--spec/ruby/library/net/http/http/request_types_spec.rb254
-rw-r--r--spec/ruby/library/net/http/http/send_request_spec.rb61
-rw-r--r--spec/ruby/library/net/http/http/set_debug_output_spec.rb33
-rw-r--r--spec/ruby/library/net/http/http/shared/request_get.rb41
-rw-r--r--spec/ruby/library/net/http/http/shared/request_head.rb41
-rw-r--r--spec/ruby/library/net/http/http/shared/request_post.rb41
-rw-r--r--spec/ruby/library/net/http/http/shared/request_put.rb41
-rw-r--r--spec/ruby/library/net/http/http/shared/started.rb26
-rw-r--r--spec/ruby/library/net/http/http/shared/version_1_1.rb6
-rw-r--r--spec/ruby/library/net/http/http/shared/version_1_2.rb6
-rw-r--r--spec/ruby/library/net/http/http/socket_type_spec.rb8
-rw-r--r--spec/ruby/library/net/http/http/start_spec.rb111
-rw-r--r--spec/ruby/library/net/http/http/started_spec.rb8
-rw-r--r--spec/ruby/library/net/http/http/trace_spec.rb24
-rw-r--r--spec/ruby/library/net/http/http/unlock_spec.rb24
-rw-r--r--spec/ruby/library/net/http/http/use_ssl_spec.rb9
-rw-r--r--spec/ruby/library/net/http/http/version_1_1_spec.rb7
-rw-r--r--spec/ruby/library/net/http/http/version_1_2_spec.rb20
-rw-r--r--spec/ruby/library/net/http/httpexceptions/initialize_spec.rb17
-rw-r--r--spec/ruby/library/net/http/httpexceptions/response_spec.rb10
-rw-r--r--spec/ruby/library/net/http/httpgenericrequest/body_exist_spec.rb22
-rw-r--r--spec/ruby/library/net/http/httpgenericrequest/body_spec.rb30
-rw-r--r--spec/ruby/library/net/http/httpgenericrequest/body_stream_spec.rb32
-rw-r--r--spec/ruby/library/net/http/httpgenericrequest/exec_spec.rb131
-rw-r--r--spec/ruby/library/net/http/httpgenericrequest/inspect_spec.rb25
-rw-r--r--spec/ruby/library/net/http/httpgenericrequest/method_spec.rb15
-rw-r--r--spec/ruby/library/net/http/httpgenericrequest/path_spec.rb12
-rw-r--r--spec/ruby/library/net/http/httpgenericrequest/request_body_permitted_spec.rb12
-rw-r--r--spec/ruby/library/net/http/httpgenericrequest/response_body_permitted_spec.rb12
-rw-r--r--spec/ruby/library/net/http/httpgenericrequest/set_body_internal_spec.rb21
-rw-r--r--spec/ruby/library/net/http/httpheader/add_field_spec.rb31
-rw-r--r--spec/ruby/library/net/http/httpheader/basic_auth_spec.rb14
-rw-r--r--spec/ruby/library/net/http/httpheader/canonical_each_spec.rb8
-rw-r--r--spec/ruby/library/net/http/httpheader/chunked_spec.rb22
-rw-r--r--spec/ruby/library/net/http/httpheader/content_length_spec.rb54
-rw-r--r--spec/ruby/library/net/http/httpheader/content_range_spec.rb32
-rw-r--r--spec/ruby/library/net/http/httpheader/content_type_spec.rb26
-rw-r--r--spec/ruby/library/net/http/httpheader/delete_spec.rb30
-rw-r--r--spec/ruby/library/net/http/httpheader/each_capitalized_name_spec.rb35
-rw-r--r--spec/ruby/library/net/http/httpheader/each_capitalized_spec.rb9
-rw-r--r--spec/ruby/library/net/http/httpheader/each_header_spec.rb8
-rw-r--r--spec/ruby/library/net/http/httpheader/each_key_spec.rb8
-rw-r--r--spec/ruby/library/net/http/httpheader/each_name_spec.rb8
-rw-r--r--spec/ruby/library/net/http/httpheader/each_spec.rb8
-rw-r--r--spec/ruby/library/net/http/httpheader/each_value_spec.rb35
-rw-r--r--spec/ruby/library/net/http/httpheader/element_reference_spec.rb39
-rw-r--r--spec/ruby/library/net/http/httpheader/element_set_spec.rb41
-rw-r--r--spec/ruby/library/net/http/httpheader/fetch_spec.rb68
-rw-r--r--spec/ruby/library/net/http/httpheader/form_data_spec.rb8
-rw-r--r--spec/ruby/library/net/http/httpheader/get_fields_spec.rb39
-rw-r--r--spec/ruby/library/net/http/httpheader/initialize_http_header_spec.rb22
-rw-r--r--spec/ruby/library/net/http/httpheader/key_spec.rb21
-rw-r--r--spec/ruby/library/net/http/httpheader/length_spec.rb8
-rw-r--r--spec/ruby/library/net/http/httpheader/main_type_spec.rb24
-rw-r--r--spec/ruby/library/net/http/httpheader/proxy_basic_auth_spec.rb14
-rw-r--r--spec/ruby/library/net/http/httpheader/range_length_spec.rb32
-rw-r--r--spec/ruby/library/net/http/httpheader/range_spec.rb48
-rw-r--r--spec/ruby/library/net/http/httpheader/set_content_type_spec.rb8
-rw-r--r--spec/ruby/library/net/http/httpheader/set_form_data_spec.rb8
-rw-r--r--spec/ruby/library/net/http/httpheader/set_range_spec.rb8
-rw-r--r--spec/ruby/library/net/http/httpheader/shared/each_capitalized.rb31
-rw-r--r--spec/ruby/library/net/http/httpheader/shared/each_header.rb31
-rw-r--r--spec/ruby/library/net/http/httpheader/shared/each_name.rb31
-rw-r--r--spec/ruby/library/net/http/httpheader/shared/set_content_type.rb18
-rw-r--r--spec/ruby/library/net/http/httpheader/shared/set_form_data.rb27
-rw-r--r--spec/ruby/library/net/http/httpheader/shared/set_range.rb89
-rw-r--r--spec/ruby/library/net/http/httpheader/shared/size.rb18
-rw-r--r--spec/ruby/library/net/http/httpheader/size_spec.rb8
-rw-r--r--spec/ruby/library/net/http/httpheader/sub_type_spec.rb32
-rw-r--r--spec/ruby/library/net/http/httpheader/to_hash_spec.rb25
-rw-r--r--spec/ruby/library/net/http/httpheader/type_params_spec.rb24
-rw-r--r--spec/ruby/library/net/http/httprequest/initialize_spec.rb45
-rw-r--r--spec/ruby/library/net/http/httpresponse/body_permitted_spec.rb13
-rw-r--r--spec/ruby/library/net/http/httpresponse/body_spec.rb7
-rw-r--r--spec/ruby/library/net/http/httpresponse/code_spec.rb24
-rw-r--r--spec/ruby/library/net/http/httpresponse/code_type_spec.rb24
-rw-r--r--spec/ruby/library/net/http/httpresponse/entity_spec.rb7
-rw-r--r--spec/ruby/library/net/http/httpresponse/error_spec.rb24
-rw-r--r--spec/ruby/library/net/http/httpresponse/error_type_spec.rb24
-rw-r--r--spec/ruby/library/net/http/httpresponse/exception_type_spec.rb13
-rw-r--r--spec/ruby/library/net/http/httpresponse/header_spec.rb9
-rw-r--r--spec/ruby/library/net/http/httpresponse/http_version_spec.rb12
-rw-r--r--spec/ruby/library/net/http/httpresponse/initialize_spec.rb11
-rw-r--r--spec/ruby/library/net/http/httpresponse/inspect_spec.rb15
-rw-r--r--spec/ruby/library/net/http/httpresponse/message_spec.rb9
-rw-r--r--spec/ruby/library/net/http/httpresponse/msg_spec.rb9
-rw-r--r--spec/ruby/library/net/http/httpresponse/read_body_spec.rb86
-rw-r--r--spec/ruby/library/net/http/httpresponse/read_header_spec.rb9
-rw-r--r--spec/ruby/library/net/http/httpresponse/read_new_spec.rb22
-rw-r--r--spec/ruby/library/net/http/httpresponse/reading_body_spec.rb58
-rw-r--r--spec/ruby/library/net/http/httpresponse/response_spec.rb9
-rw-r--r--spec/ruby/library/net/http/httpresponse/shared/body.rb18
-rw-r--r--spec/ruby/library/net/http/httpresponse/value_spec.rb24
-rw-r--r--spec/ruby/library/objectspace/dump_all_spec.rb112
-rw-r--r--spec/ruby/library/objectspace/dump_spec.rb70
-rw-r--r--spec/ruby/library/objectspace/fixtures/trace.rb6
-rw-r--r--spec/ruby/library/objectspace/memsize_of_all_spec.rb22
-rw-r--r--spec/ruby/library/objectspace/memsize_of_spec.rb34
-rw-r--r--spec/ruby/library/objectspace/reachable_objects_from_spec.rb59
-rw-r--r--spec/ruby/library/objectspace/trace_object_allocations_spec.rb163
-rw-r--r--spec/ruby/library/objectspace/trace_spec.rb13
-rw-r--r--spec/ruby/library/observer/add_observer_spec.rb4
-rw-r--r--spec/ruby/library/observer/count_observers_spec.rb4
-rw-r--r--spec/ruby/library/observer/delete_observer_spec.rb4
-rw-r--r--spec/ruby/library/observer/delete_observers_spec.rb4
-rw-r--r--spec/ruby/library/observer/notify_observers_spec.rb8
-rw-r--r--spec/ruby/library/open3/capture2_spec.rb2
-rw-r--r--spec/ruby/library/open3/capture2e_spec.rb2
-rw-r--r--spec/ruby/library/open3/capture3_spec.rb2
-rw-r--r--spec/ruby/library/open3/pipeline_r_spec.rb2
-rw-r--r--spec/ruby/library/open3/pipeline_rw_spec.rb2
-rw-r--r--spec/ruby/library/open3/pipeline_spec.rb2
-rw-r--r--spec/ruby/library/open3/pipeline_start_spec.rb2
-rw-r--r--spec/ruby/library/open3/pipeline_w_spec.rb2
-rw-r--r--spec/ruby/library/open3/popen2_spec.rb2
-rw-r--r--spec/ruby/library/open3/popen2e_spec.rb2
-rw-r--r--spec/ruby/library/open3/popen3_spec.rb12
-rw-r--r--spec/ruby/library/openssl/cipher_spec.rb6
-rw-r--r--spec/ruby/library/openssl/config/freeze_spec.rb16
-rw-r--r--spec/ruby/library/openssl/digest/append_spec.rb6
-rw-r--r--spec/ruby/library/openssl/digest/block_length_spec.rb44
-rw-r--r--spec/ruby/library/openssl/digest/digest_length_spec.rb44
-rw-r--r--spec/ruby/library/openssl/digest/digest_spec.rb62
-rw-r--r--spec/ruby/library/openssl/digest/initialize_spec.rb137
-rw-r--r--spec/ruby/library/openssl/digest/name_spec.rb16
-rw-r--r--spec/ruby/library/openssl/digest/reset_spec.rb36
-rw-r--r--spec/ruby/library/openssl/digest/shared/update.rb123
-rw-r--r--spec/ruby/library/openssl/digest/update_spec.rb6
-rw-r--r--spec/ruby/library/openssl/fixed_length_secure_compare_spec.rb42
-rw-r--r--spec/ruby/library/openssl/hmac/digest_spec.rb6
-rw-r--r--spec/ruby/library/openssl/hmac/hexdigest_spec.rb6
-rw-r--r--spec/ruby/library/openssl/kdf/pbkdf2_hmac_spec.rb162
-rw-r--r--spec/ruby/library/openssl/kdf/scrypt_spec.rb210
-rw-r--r--spec/ruby/library/openssl/random/pseudo_bytes_spec.rb4
-rw-r--r--spec/ruby/library/openssl/random/random_bytes_spec.rb4
-rw-r--r--spec/ruby/library/openssl/random/shared/random_bytes.rb10
-rw-r--r--spec/ruby/library/openssl/secure_compare_spec.rb38
-rw-r--r--spec/ruby/library/openssl/shared/constants.rb2
-rw-r--r--spec/ruby/library/openssl/x509/name/parse_spec.rb10
-rw-r--r--spec/ruby/library/openssl/x509/store/verify_spec.rb78
-rw-r--r--spec/ruby/library/openstruct/delete_field_spec.rb8
-rw-r--r--spec/ruby/library/openstruct/element_reference_spec.rb2
-rw-r--r--spec/ruby/library/openstruct/element_set_spec.rb2
-rw-r--r--spec/ruby/library/openstruct/equal_value_spec.rb28
-rw-r--r--spec/ruby/library/openstruct/frozen_spec.rb18
-rw-r--r--spec/ruby/library/openstruct/initialize_spec.rb4
-rw-r--r--spec/ruby/library/openstruct/inspect_spec.rb8
-rw-r--r--spec/ruby/library/openstruct/marshal_dump_spec.rb2
-rw-r--r--spec/ruby/library/openstruct/marshal_load_spec.rb6
-rw-r--r--spec/ruby/library/openstruct/method_missing_spec.rb37
-rw-r--r--spec/ruby/library/openstruct/new_spec.rb6
-rw-r--r--spec/ruby/library/openstruct/shared/inspect.rb20
-rw-r--r--spec/ruby/library/openstruct/to_h_spec.rb43
-rw-r--r--spec/ruby/library/openstruct/to_s_spec.rb24
-rw-r--r--spec/ruby/library/optionparser/order_spec.rb38
-rw-r--r--spec/ruby/library/optionparser/parse_spec.rb38
-rw-r--r--spec/ruby/library/pathname/absolute_spec.rb11
-rw-r--r--spec/ruby/library/pathname/birthtime_spec.rb16
-rw-r--r--spec/ruby/library/pathname/case_compare_spec.rb8
-rw-r--r--spec/ruby/library/pathname/divide_spec.rb8
-rw-r--r--spec/ruby/library/pathname/empty_spec.rb48
-rw-r--r--spec/ruby/library/pathname/equal_value_spec.rb3
-rw-r--r--spec/ruby/library/pathname/glob_spec.rb92
-rw-r--r--spec/ruby/library/pathname/hash_spec.rb3
-rw-r--r--spec/ruby/library/pathname/inspect_spec.rb10
-rw-r--r--spec/ruby/library/pathname/join_spec.rb2
-rw-r--r--spec/ruby/library/pathname/new_spec.rb19
-rw-r--r--spec/ruby/library/pathname/parent_spec.rb3
-rw-r--r--spec/ruby/library/pathname/pathname_spec.rb19
-rw-r--r--spec/ruby/library/pathname/plus_spec.rb9
-rw-r--r--spec/ruby/library/pathname/realdirpath_spec.rb4
-rw-r--r--spec/ruby/library/pathname/realpath_spec.rb4
-rw-r--r--spec/ruby/library/pathname/relative_path_from_spec.rb10
-rw-r--r--spec/ruby/library/pathname/relative_spec.rb11
-rw-r--r--spec/ruby/library/pathname/root_spec.rb13
-rw-r--r--spec/ruby/library/pathname/sub_spec.rb3
-rw-r--r--spec/ruby/library/pp/pp_spec.rb13
-rw-r--r--spec/ruby/library/prime/each_spec.rb24
-rw-r--r--spec/ruby/library/prime/instance_spec.rb12
-rw-r--r--spec/ruby/library/prime/int_from_prime_division_spec.rb2
-rw-r--r--spec/ruby/library/prime/integer/each_prime_spec.rb2
-rw-r--r--spec/ruby/library/prime/integer/from_prime_division_spec.rb2
-rw-r--r--spec/ruby/library/prime/integer/prime_division_spec.rb4
-rw-r--r--spec/ruby/library/prime/integer/prime_spec.rb16
-rw-r--r--spec/ruby/library/prime/next_spec.rb10
-rw-r--r--spec/ruby/library/prime/prime_division_spec.rb6
-rw-r--r--spec/ruby/library/prime/prime_spec.rb16
-rw-r--r--spec/ruby/library/prime/shared/next.rb8
-rw-r--r--spec/ruby/library/prime/succ_spec.rb8
-rw-r--r--spec/ruby/library/random/formatter/alphanumeric_spec.rb54
-rw-r--r--spec/ruby/library/rbconfig/rbconfig_spec.rb163
-rw-r--r--spec/ruby/library/rbconfig/sizeof/limits_spec.rb40
-rw-r--r--spec/ruby/library/rbconfig/sizeof/sizeof_spec.rb30
-rw-r--r--spec/ruby/library/rbconfig/unicode_emoji_version_spec.rb17
-rw-r--r--spec/ruby/library/rbconfig/unicode_version_spec.rb17
-rw-r--r--spec/ruby/library/readline/basic_quote_characters_spec.rb4
-rw-r--r--spec/ruby/library/readline/basic_word_break_characters_spec.rb4
-rw-r--r--spec/ruby/library/readline/completer_quote_characters_spec.rb4
-rw-r--r--spec/ruby/library/readline/completer_word_break_characters_spec.rb4
-rw-r--r--spec/ruby/library/readline/completion_append_character_spec.rb4
-rw-r--r--spec/ruby/library/readline/completion_case_fold_spec.rb4
-rw-r--r--spec/ruby/library/readline/completion_proc_spec.rb6
-rw-r--r--spec/ruby/library/readline/constants_spec.rb6
-rw-r--r--spec/ruby/library/readline/emacs_editing_mode_spec.rb4
-rw-r--r--spec/ruby/library/readline/filename_quote_characters_spec.rb4
-rw-r--r--spec/ruby/library/readline/history/append_spec.rb4
-rw-r--r--spec/ruby/library/readline/history/delete_at_spec.rb13
-rw-r--r--spec/ruby/library/readline/history/each_spec.rb8
-rw-r--r--spec/ruby/library/readline/history/element_reference_spec.rb19
-rw-r--r--spec/ruby/library/readline/history/element_set_spec.rb6
-rw-r--r--spec/ruby/library/readline/history/empty_spec.rb8
-rw-r--r--spec/ruby/library/readline/history/history_spec.rb4
-rw-r--r--spec/ruby/library/readline/history/length_spec.rb4
-rw-r--r--spec/ruby/library/readline/history/pop_spec.rb11
-rw-r--r--spec/ruby/library/readline/history/push_spec.rb4
-rw-r--r--spec/ruby/library/readline/history/shift_spec.rb11
-rw-r--r--spec/ruby/library/readline/history/size_spec.rb4
-rw-r--r--spec/ruby/library/readline/history/to_s_spec.rb2
-rw-r--r--spec/ruby/library/readline/readline_spec.rb7
-rw-r--r--spec/ruby/library/readline/spec_helper.rb6
-rw-r--r--spec/ruby/library/readline/vi_editing_mode_spec.rb4
-rw-r--r--spec/ruby/library/resolv/fixtures/hosts1
-rw-r--r--spec/ruby/library/resolv/get_address_spec.rb18
-rw-r--r--spec/ruby/library/resolv/get_addresses_spec.rb14
-rw-r--r--spec/ruby/library/resolv/get_name_spec.rb17
-rw-r--r--spec/ruby/library/resolv/get_names_spec.rb13
-rw-r--r--spec/ruby/library/rexml/attribute/clone_spec.rb11
-rw-r--r--spec/ruby/library/rexml/attribute/element_spec.rb23
-rw-r--r--spec/ruby/library/rexml/attribute/equal_value_spec.rb18
-rw-r--r--spec/ruby/library/rexml/attribute/hash_spec.rb13
-rw-r--r--spec/ruby/library/rexml/attribute/initialize_spec.rb29
-rw-r--r--spec/ruby/library/rexml/attribute/inspect_spec.rb20
-rw-r--r--spec/ruby/library/rexml/attribute/namespace_spec.rb24
-rw-r--r--spec/ruby/library/rexml/attribute/node_type_spec.rb10
-rw-r--r--spec/ruby/library/rexml/attribute/prefix_spec.rb18
-rw-r--r--spec/ruby/library/rexml/attribute/remove_spec.rb20
-rw-r--r--spec/ruby/library/rexml/attribute/to_s_spec.rb14
-rw-r--r--spec/ruby/library/rexml/attribute/to_string_spec.rb15
-rw-r--r--spec/ruby/library/rexml/attribute/value_spec.rb15
-rw-r--r--spec/ruby/library/rexml/attribute/write_spec.rb23
-rw-r--r--spec/ruby/library/rexml/attribute/xpath_spec.rb20
-rw-r--r--spec/ruby/library/rexml/attributes/add_spec.rb7
-rw-r--r--spec/ruby/library/rexml/attributes/append_spec.rb7
-rw-r--r--spec/ruby/library/rexml/attributes/delete_all_spec.rb31
-rw-r--r--spec/ruby/library/rexml/attributes/delete_spec.rb27
-rw-r--r--spec/ruby/library/rexml/attributes/each_attribute_spec.rb25
-rw-r--r--spec/ruby/library/rexml/attributes/each_spec.rb25
-rw-r--r--spec/ruby/library/rexml/attributes/element_reference_spec.rb19
-rw-r--r--spec/ruby/library/rexml/attributes/element_set_spec.rb26
-rw-r--r--spec/ruby/library/rexml/attributes/get_attribute_ns_spec.rb14
-rw-r--r--spec/ruby/library/rexml/attributes/get_attribute_spec.rb29
-rw-r--r--spec/ruby/library/rexml/attributes/initialize_spec.rb18
-rw-r--r--spec/ruby/library/rexml/attributes/length_spec.rb7
-rw-r--r--spec/ruby/library/rexml/attributes/namespaces_spec.rb6
-rw-r--r--spec/ruby/library/rexml/attributes/prefixes_spec.rb24
-rw-r--r--spec/ruby/library/rexml/attributes/shared/add.rb17
-rw-r--r--spec/ruby/library/rexml/attributes/shared/length.rb13
-rw-r--r--spec/ruby/library/rexml/attributes/size_spec.rb7
-rw-r--r--spec/ruby/library/rexml/attributes/to_a_spec.rb20
-rw-r--r--spec/ruby/library/rexml/cdata/clone_spec.rb10
-rw-r--r--spec/ruby/library/rexml/cdata/initialize_spec.rb24
-rw-r--r--spec/ruby/library/rexml/cdata/shared/to_s.rb11
-rw-r--r--spec/ruby/library/rexml/cdata/to_s_spec.rb7
-rw-r--r--spec/ruby/library/rexml/cdata/value_spec.rb7
-rw-r--r--spec/ruby/library/rexml/document/add_element_spec.rb31
-rw-r--r--spec/ruby/library/rexml/document/add_spec.rb57
-rw-r--r--spec/ruby/library/rexml/document/clone_spec.rb20
-rw-r--r--spec/ruby/library/rexml/document/doctype_spec.rb15
-rw-r--r--spec/ruby/library/rexml/document/encoding_spec.rb22
-rw-r--r--spec/ruby/library/rexml/document/expanded_name_spec.rb16
-rw-r--r--spec/ruby/library/rexml/document/new_spec.rb36
-rw-r--r--spec/ruby/library/rexml/document/node_type_spec.rb8
-rw-r--r--spec/ruby/library/rexml/document/root_spec.rb12
-rw-r--r--spec/ruby/library/rexml/document/stand_alone_spec.rb19
-rw-r--r--spec/ruby/library/rexml/document/version_spec.rb14
-rw-r--r--spec/ruby/library/rexml/document/write_spec.rb35
-rw-r--r--spec/ruby/library/rexml/document/xml_decl_spec.rb15
-rw-r--r--spec/ruby/library/rexml/element/add_attribute_spec.rb41
-rw-r--r--spec/ruby/library/rexml/element/add_attributes_spec.rb22
-rw-r--r--spec/ruby/library/rexml/element/add_element_spec.rb39
-rw-r--r--spec/ruby/library/rexml/element/add_namespace_spec.rb24
-rw-r--r--spec/ruby/library/rexml/element/add_text_spec.rb24
-rw-r--r--spec/ruby/library/rexml/element/attribute_spec.rb17
-rw-r--r--spec/ruby/library/rexml/element/attributes_spec.rb19
-rw-r--r--spec/ruby/library/rexml/element/cdatas_spec.rb24
-rw-r--r--spec/ruby/library/rexml/element/clone_spec.rb29
-rw-r--r--spec/ruby/library/rexml/element/comments_spec.rb20
-rw-r--r--spec/ruby/library/rexml/element/delete_attribute_spec.rb39
-rw-r--r--spec/ruby/library/rexml/element/delete_element_spec.rb49
-rw-r--r--spec/ruby/library/rexml/element/delete_namespace_spec.rb25
-rw-r--r--spec/ruby/library/rexml/element/document_spec.rb18
-rw-r--r--spec/ruby/library/rexml/element/each_element_with_attribute_spec.rb35
-rw-r--r--spec/ruby/library/rexml/element/each_element_with_text_spec.rb31
-rw-r--r--spec/ruby/library/rexml/element/element_reference_spec.rb22
-rw-r--r--spec/ruby/library/rexml/element/get_text_spec.rb18
-rw-r--r--spec/ruby/library/rexml/element/has_attributes_spec.rb17
-rw-r--r--spec/ruby/library/rexml/element/has_elements_spec.rb18
-rw-r--r--spec/ruby/library/rexml/element/has_text_spec.rb16
-rw-r--r--spec/ruby/library/rexml/element/inspect_spec.rb27
-rw-r--r--spec/ruby/library/rexml/element/instructions_spec.rb21
-rw-r--r--spec/ruby/library/rexml/element/namespace_spec.rb27
-rw-r--r--spec/ruby/library/rexml/element/namespaces_spec.rb32
-rw-r--r--spec/ruby/library/rexml/element/new_spec.rb35
-rw-r--r--spec/ruby/library/rexml/element/next_element_spec.rb19
-rw-r--r--spec/ruby/library/rexml/element/node_type_spec.rb8
-rw-r--r--spec/ruby/library/rexml/element/prefixes_spec.rb23
-rw-r--r--spec/ruby/library/rexml/element/previous_element_spec.rb20
-rw-r--r--spec/ruby/library/rexml/element/raw_spec.rb24
-rw-r--r--spec/ruby/library/rexml/element/root_spec.rb28
-rw-r--r--spec/ruby/library/rexml/element/text_spec.rb46
-rw-r--r--spec/ruby/library/rexml/element/texts_spec.rb16
-rw-r--r--spec/ruby/library/rexml/element/whitespace_spec.rb23
-rw-r--r--spec/ruby/library/rexml/node/each_recursive_spec.rb21
-rw-r--r--spec/ruby/library/rexml/node/find_first_recursive_spec.rb25
-rw-r--r--spec/ruby/library/rexml/node/index_in_parent_spec.rb15
-rw-r--r--spec/ruby/library/rexml/node/next_sibling_node_spec.rb21
-rw-r--r--spec/ruby/library/rexml/node/parent_spec.rb21
-rw-r--r--spec/ruby/library/rexml/node/previous_sibling_node_spec.rb21
-rw-r--r--spec/ruby/library/rexml/shared/each_element.rb36
-rw-r--r--spec/ruby/library/rexml/shared/elements_to_a.rb34
-rw-r--r--spec/ruby/library/rexml/text/append_spec.rb10
-rw-r--r--spec/ruby/library/rexml/text/clone_spec.rb10
-rw-r--r--spec/ruby/library/rexml/text/comparison_spec.rb25
-rw-r--r--spec/ruby/library/rexml/text/empty_spec.rb12
-rw-r--r--spec/ruby/library/rexml/text/indent_text_spec.rb24
-rw-r--r--spec/ruby/library/rexml/text/inspect_spec.rb8
-rw-r--r--spec/ruby/library/rexml/text/new_spec.rb49
-rw-r--r--spec/ruby/library/rexml/text/node_type_spec.rb8
-rw-r--r--spec/ruby/library/rexml/text/normalize_spec.rb8
-rw-r--r--spec/ruby/library/rexml/text/read_with_substitution_spec.rb13
-rw-r--r--spec/ruby/library/rexml/text/to_s_spec.rb18
-rw-r--r--spec/ruby/library/rexml/text/unnormalize_spec.rb8
-rw-r--r--spec/ruby/library/rexml/text/value_spec.rb37
-rw-r--r--spec/ruby/library/rexml/text/wrap_spec.rb21
-rw-r--r--spec/ruby/library/rexml/text/write_with_substitution_spec.rb33
-rw-r--r--spec/ruby/library/ripper/lex_spec.rb23
-rw-r--r--spec/ruby/library/ripper/sexp_spec.rb13
-rw-r--r--spec/ruby/library/rubygems/gem/bin_path_spec.rb35
-rw-r--r--spec/ruby/library/rubygems/gem/load_path_insert_index_spec.rb10
-rw-r--r--spec/ruby/library/scanf/io/block_scanf_spec.rb7
-rw-r--r--spec/ruby/library/scanf/io/fixtures/date.txt4
-rw-r--r--spec/ruby/library/scanf/io/fixtures/helloworld.txt1
-rw-r--r--spec/ruby/library/scanf/io/scanf_spec.rb35
-rw-r--r--spec/ruby/library/scanf/io/shared/block_scanf.rb28
-rw-r--r--spec/ruby/library/scanf/string/block_scanf_spec.rb7
-rw-r--r--spec/ruby/library/scanf/string/scanf_spec.rb53
-rw-r--r--spec/ruby/library/scanf/string/shared/block_scanf.rb25
-rw-r--r--spec/ruby/library/securerandom/base64_spec.rb14
-rw-r--r--spec/ruby/library/securerandom/bytes_spec.rb8
-rw-r--r--spec/ruby/library/securerandom/hex_spec.rb20
-rw-r--r--spec/ruby/library/securerandom/random_bytes_spec.rb19
-rw-r--r--spec/ruby/library/securerandom/random_number_spec.rb88
-rw-r--r--spec/ruby/library/set/add_spec.rb27
-rw-r--r--spec/ruby/library/set/append_spec.rb7
-rw-r--r--spec/ruby/library/set/case_equality_spec.rb9
-rw-r--r--spec/ruby/library/set/classify_spec.rb27
-rw-r--r--spec/ruby/library/set/clear_spec.rb17
-rw-r--r--spec/ruby/library/set/collect_spec.rb7
-rw-r--r--spec/ruby/library/set/compare_by_identity_spec.rb147
-rw-r--r--spec/ruby/library/set/constructor_spec.rb15
-rw-r--r--spec/ruby/library/set/delete_if_spec.rb38
-rw-r--r--spec/ruby/library/set/delete_spec.rb37
-rw-r--r--spec/ruby/library/set/difference_spec.rb7
-rw-r--r--spec/ruby/library/set/divide_spec.rb34
-rw-r--r--spec/ruby/library/set/each_spec.rb26
-rw-r--r--spec/ruby/library/set/empty_spec.rb10
-rw-r--r--spec/ruby/library/set/enumerable/to_set_spec.rb19
-rw-r--r--spec/ruby/library/set/eql_spec.rb15
-rw-r--r--spec/ruby/library/set/equal_value_spec.rb26
-rw-r--r--spec/ruby/library/set/exclusion_spec.rb18
-rw-r--r--spec/ruby/library/set/flatten_merge_spec.rb23
-rw-r--r--spec/ruby/library/set/flatten_spec.rb40
-rw-r--r--spec/ruby/library/set/hash_spec.rb13
-rw-r--r--spec/ruby/library/set/include_spec.rb7
-rw-r--r--spec/ruby/library/set/initialize_spec.rb24
-rw-r--r--spec/ruby/library/set/inspect_spec.rb18
-rw-r--r--spec/ruby/library/set/intersection_spec.rb11
-rw-r--r--spec/ruby/library/set/keep_if_spec.rb38
-rw-r--r--spec/ruby/library/set/length_spec.rb7
-rw-r--r--spec/ruby/library/set/map_spec.rb7
-rw-r--r--spec/ruby/library/set/member_spec.rb7
-rw-r--r--spec/ruby/library/set/merge_spec.rb19
-rw-r--r--spec/ruby/library/set/minus_spec.rb7
-rw-r--r--spec/ruby/library/set/plus_spec.rb7
-rw-r--r--spec/ruby/library/set/pretty_print_cycle_spec.rb10
-rw-r--r--spec/ruby/library/set/pretty_print_spec.rb17
-rw-r--r--spec/ruby/library/set/proper_subset_spec.rb34
-rw-r--r--spec/ruby/library/set/proper_superset_spec.rb34
-rw-r--r--spec/ruby/library/set/reject_spec.rb42
-rw-r--r--spec/ruby/library/set/replace_spec.rb17
-rw-r--r--spec/ruby/library/set/select_spec.rb42
-rw-r--r--spec/ruby/library/set/shared/add.rb14
-rw-r--r--spec/ruby/library/set/shared/collect.rb20
-rw-r--r--spec/ruby/library/set/shared/difference.rb15
-rw-r--r--spec/ruby/library/set/shared/include.rb7
-rw-r--r--spec/ruby/library/set/shared/intersection.rb15
-rw-r--r--spec/ruby/library/set/shared/length.rb6
-rw-r--r--spec/ruby/library/set/shared/union.rb15
-rw-r--r--spec/ruby/library/set/size_spec.rb7
-rw-r--r--spec/ruby/library/set/sortedset/add_spec.rb39
-rw-r--r--spec/ruby/library/set/sortedset/append_spec.rb7
-rw-r--r--spec/ruby/library/set/sortedset/case_equality_spec.rb9
-rw-r--r--spec/ruby/library/set/sortedset/classify_spec.rb27
-rw-r--r--spec/ruby/library/set/sortedset/clear_spec.rb17
-rw-r--r--spec/ruby/library/set/sortedset/collect_spec.rb7
-rw-r--r--spec/ruby/library/set/sortedset/constructor_spec.rb15
-rw-r--r--spec/ruby/library/set/sortedset/delete_if_spec.rb38
-rw-r--r--spec/ruby/library/set/sortedset/delete_spec.rb37
-rw-r--r--spec/ruby/library/set/sortedset/difference_spec.rb7
-rw-r--r--spec/ruby/library/set/sortedset/divide_spec.rb34
-rw-r--r--spec/ruby/library/set/sortedset/each_spec.rb26
-rw-r--r--spec/ruby/library/set/sortedset/empty_spec.rb10
-rw-r--r--spec/ruby/library/set/sortedset/eql_spec.rb16
-rw-r--r--spec/ruby/library/set/sortedset/equal_value_spec.rb13
-rw-r--r--spec/ruby/library/set/sortedset/exclusion_spec.rb18
-rw-r--r--spec/ruby/library/set/sortedset/flatten_merge_spec.rb8
-rw-r--r--spec/ruby/library/set/sortedset/flatten_spec.rb44
-rw-r--r--spec/ruby/library/set/sortedset/hash_spec.rb13
-rw-r--r--spec/ruby/library/set/sortedset/include_spec.rb7
-rw-r--r--spec/ruby/library/set/sortedset/initialize_spec.rb30
-rw-r--r--spec/ruby/library/set/sortedset/inspect_spec.rb10
-rw-r--r--spec/ruby/library/set/sortedset/intersection_spec.rb11
-rw-r--r--spec/ruby/library/set/sortedset/keep_if_spec.rb31
-rw-r--r--spec/ruby/library/set/sortedset/length_spec.rb7
-rw-r--r--spec/ruby/library/set/sortedset/map_spec.rb7
-rw-r--r--spec/ruby/library/set/sortedset/member_spec.rb7
-rw-r--r--spec/ruby/library/set/sortedset/merge_spec.rb19
-rw-r--r--spec/ruby/library/set/sortedset/minus_spec.rb7
-rw-r--r--spec/ruby/library/set/sortedset/plus_spec.rb7
-rw-r--r--spec/ruby/library/set/sortedset/pretty_print_cycle_spec.rb10
-rw-r--r--spec/ruby/library/set/sortedset/pretty_print_spec.rb17
-rw-r--r--spec/ruby/library/set/sortedset/proper_subset_spec.rb33
-rw-r--r--spec/ruby/library/set/sortedset/proper_superset_spec.rb33
-rw-r--r--spec/ruby/library/set/sortedset/reject_spec.rb42
-rw-r--r--spec/ruby/library/set/sortedset/replace_spec.rb17
-rw-r--r--spec/ruby/library/set/sortedset/select_spec.rb35
-rw-r--r--spec/ruby/library/set/sortedset/shared/add.rb14
-rw-r--r--spec/ruby/library/set/sortedset/shared/collect.rb20
-rw-r--r--spec/ruby/library/set/sortedset/shared/difference.rb15
-rw-r--r--spec/ruby/library/set/sortedset/shared/include.rb7
-rw-r--r--spec/ruby/library/set/sortedset/shared/intersection.rb15
-rw-r--r--spec/ruby/library/set/sortedset/shared/length.rb6
-rw-r--r--spec/ruby/library/set/sortedset/shared/union.rb15
-rw-r--r--spec/ruby/library/set/sortedset/size_spec.rb7
-rw-r--r--spec/ruby/library/set/sortedset/subset_spec.rb33
-rw-r--r--spec/ruby/library/set/sortedset/subtract_spec.rb17
-rw-r--r--spec/ruby/library/set/sortedset/superset_spec.rb33
-rw-r--r--spec/ruby/library/set/sortedset/to_a_spec.rb17
-rw-r--r--spec/ruby/library/set/sortedset/union_spec.rb11
-rw-r--r--spec/ruby/library/set/subset_spec.rb34
-rw-r--r--spec/ruby/library/set/subtract_spec.rb17
-rw-r--r--spec/ruby/library/set/superset_spec.rb34
-rw-r--r--spec/ruby/library/set/to_a_spec.rb8
-rw-r--r--spec/ruby/library/set/union_spec.rb11
-rw-r--r--spec/ruby/library/shellwords/shellwords_spec.rb23
-rw-r--r--spec/ruby/library/singleton/allocate_spec.rb6
-rw-r--r--spec/ruby/library/singleton/clone_spec.rb6
-rw-r--r--spec/ruby/library/singleton/dump_spec.rb4
-rw-r--r--spec/ruby/library/singleton/dup_spec.rb6
-rw-r--r--spec/ruby/library/singleton/instance_spec.rb16
-rw-r--r--spec/ruby/library/singleton/load_spec.rb17
-rw-r--r--spec/ruby/library/singleton/new_spec.rb6
-rw-r--r--spec/ruby/library/socket/addrinfo/afamily_spec.rb17
-rw-r--r--spec/ruby/library/socket/addrinfo/bind_spec.rb13
-rw-r--r--spec/ruby/library/socket/addrinfo/canonname_spec.rb16
-rw-r--r--spec/ruby/library/socket/addrinfo/connect_from_spec.rb75
-rw-r--r--spec/ruby/library/socket/addrinfo/connect_spec.rb35
-rw-r--r--spec/ruby/library/socket/addrinfo/connect_to_spec.rb75
-rw-r--r--spec/ruby/library/socket/addrinfo/family_addrinfo_spec.rb113
-rw-r--r--spec/ruby/library/socket/addrinfo/foreach_spec.rb9
-rw-r--r--spec/ruby/library/socket/addrinfo/getaddrinfo_spec.rb87
-rw-r--r--spec/ruby/library/socket/addrinfo/getnameinfo_spec.rb40
-rw-r--r--spec/ruby/library/socket/addrinfo/initialize_spec.rb372
-rw-r--r--spec/ruby/library/socket/addrinfo/inspect_sockaddr_spec.rb53
-rw-r--r--spec/ruby/library/socket/addrinfo/inspect_spec.rb63
-rw-r--r--spec/ruby/library/socket/addrinfo/ip_address_spec.rb48
-rw-r--r--spec/ruby/library/socket/addrinfo/ip_port_spec.rb17
-rw-r--r--spec/ruby/library/socket/addrinfo/ip_spec.rb50
-rw-r--r--spec/ruby/library/socket/addrinfo/ip_unpack_spec.rb17
-rw-r--r--spec/ruby/library/socket/addrinfo/ipv4_loopback_spec.rb33
-rw-r--r--spec/ruby/library/socket/addrinfo/ipv4_multicast_spec.rb49
-rw-r--r--spec/ruby/library/socket/addrinfo/ipv4_private_spec.rb30
-rw-r--r--spec/ruby/library/socket/addrinfo/ipv4_spec.rb21
-rw-r--r--spec/ruby/library/socket/addrinfo/ipv6_linklocal_spec.rb23
-rw-r--r--spec/ruby/library/socket/addrinfo/ipv6_loopback_spec.rb29
-rw-r--r--spec/ruby/library/socket/addrinfo/ipv6_mc_global_spec.rb20
-rw-r--r--spec/ruby/library/socket/addrinfo/ipv6_mc_linklocal_spec.rb19
-rw-r--r--spec/ruby/library/socket/addrinfo/ipv6_mc_nodelocal_spec.rb18
-rw-r--r--spec/ruby/library/socket/addrinfo/ipv6_mc_orglocal_spec.rb18
-rw-r--r--spec/ruby/library/socket/addrinfo/ipv6_mc_sitelocal_spec.rb18
-rw-r--r--spec/ruby/library/socket/addrinfo/ipv6_multicast_spec.rb42
-rw-r--r--spec/ruby/library/socket/addrinfo/ipv6_sitelocal_spec.rb23
-rw-r--r--spec/ruby/library/socket/addrinfo/ipv6_spec.rb21
-rw-r--r--spec/ruby/library/socket/addrinfo/ipv6_to_ipv4_spec.rb71
-rw-r--r--spec/ruby/library/socket/addrinfo/ipv6_unique_local_spec.rb18
-rw-r--r--spec/ruby/library/socket/addrinfo/ipv6_unspecified_spec.rb15
-rw-r--r--spec/ruby/library/socket/addrinfo/ipv6_v4compat_spec.rb20
-rw-r--r--spec/ruby/library/socket/addrinfo/ipv6_v4mapped_spec.rb20
-rw-r--r--spec/ruby/library/socket/addrinfo/listen_spec.rb34
-rw-r--r--spec/ruby/library/socket/addrinfo/marshal_dump_spec.rb80
-rw-r--r--spec/ruby/library/socket/addrinfo/marshal_load_spec.rb33
-rw-r--r--spec/ruby/library/socket/addrinfo/pfamily_spec.rb23
-rw-r--r--spec/ruby/library/socket/addrinfo/protocol_spec.rb38
-rw-r--r--spec/ruby/library/socket/addrinfo/shared/to_sockaddr.rb35
-rw-r--r--spec/ruby/library/socket/addrinfo/socktype_spec.rb33
-rw-r--r--spec/ruby/library/socket/addrinfo/tcp_spec.rb42
-rw-r--r--spec/ruby/library/socket/addrinfo/to_s_spec.rb8
-rw-r--r--spec/ruby/library/socket/addrinfo/to_sockaddr_spec.rb50
-rw-r--r--spec/ruby/library/socket/addrinfo/udp_spec.rb42
-rw-r--r--spec/ruby/library/socket/addrinfo/unix_path_spec.rb51
-rw-r--r--spec/ruby/library/socket/addrinfo/unix_spec.rb47
-rw-r--r--spec/ruby/library/socket/ancillarydata/cmsg_is_spec.rb33
-rw-r--r--spec/ruby/library/socket/ancillarydata/data_spec.rb9
-rw-r--r--spec/ruby/library/socket/ancillarydata/family_spec.rb9
-rw-r--r--spec/ruby/library/socket/ancillarydata/initialize_spec.rb284
-rw-r--r--spec/ruby/library/socket/ancillarydata/int_spec.rb43
-rw-r--r--spec/ruby/library/socket/ancillarydata/ip_pktinfo_spec.rb145
-rw-r--r--spec/ruby/library/socket/ancillarydata/ipv6_pktinfo_addr_spec.rb11
-rw-r--r--spec/ruby/library/socket/ancillarydata/ipv6_pktinfo_ifindex_spec.rb11
-rw-r--r--spec/ruby/library/socket/ancillarydata/ipv6_pktinfo_spec.rb89
-rw-r--r--spec/ruby/library/socket/ancillarydata/level_spec.rb9
-rw-r--r--spec/ruby/library/socket/ancillarydata/type_spec.rb9
-rw-r--r--spec/ruby/library/socket/ancillarydata/unix_rights_spec.rb61
-rw-r--r--spec/ruby/library/socket/basicsocket/close_read_spec.rb24
-rw-r--r--spec/ruby/library/socket/basicsocket/close_write_spec.rb24
-rw-r--r--spec/ruby/library/socket/basicsocket/connect_address_spec.rb152
-rw-r--r--spec/ruby/library/socket/basicsocket/do_not_reverse_lookup_spec.rb70
-rw-r--r--spec/ruby/library/socket/basicsocket/for_fd_spec.rb27
-rw-r--r--spec/ruby/library/socket/basicsocket/getpeereid_spec.rb36
-rw-r--r--spec/ruby/library/socket/basicsocket/getpeername_spec.rb9
-rw-r--r--spec/ruby/library/socket/basicsocket/getsockname_spec.rb12
-rw-r--r--spec/ruby/library/socket/basicsocket/getsockopt_spec.rb150
-rw-r--r--spec/ruby/library/socket/basicsocket/ioctl_spec.rb3
-rw-r--r--spec/ruby/library/socket/basicsocket/local_address_spec.rb10
-rw-r--r--spec/ruby/library/socket/basicsocket/read_nonblock_spec.rb74
-rw-r--r--spec/ruby/library/socket/basicsocket/read_spec.rb47
-rw-r--r--spec/ruby/library/socket/basicsocket/recv_nonblock_spec.rb143
-rw-r--r--spec/ruby/library/socket/basicsocket/recv_spec.rb205
-rw-r--r--spec/ruby/library/socket/basicsocket/recvmsg_nonblock_spec.rb267
-rw-r--r--spec/ruby/library/socket/basicsocket/recvmsg_spec.rb257
-rw-r--r--spec/ruby/library/socket/basicsocket/remote_address_spec.rb10
-rw-r--r--spec/ruby/library/socket/basicsocket/send_spec.rb229
-rw-r--r--spec/ruby/library/socket/basicsocket/sendmsg_nonblock_spec.rb118
-rw-r--r--spec/ruby/library/socket/basicsocket/sendmsg_spec.rb111
-rw-r--r--spec/ruby/library/socket/basicsocket/setsockopt_spec.rb171
-rw-r--r--spec/ruby/library/socket/basicsocket/shutdown_spec.rb155
-rw-r--r--spec/ruby/library/socket/basicsocket/write_nonblock_spec.rb43
-rw-r--r--spec/ruby/library/socket/constants/constants_spec.rb48
-rw-r--r--spec/ruby/library/socket/fixtures/classes.rb91
-rw-r--r--spec/ruby/library/socket/ipsocket/addr_spec.rb73
-rw-r--r--spec/ruby/library/socket/ipsocket/getaddress_spec.rb21
-rw-r--r--spec/ruby/library/socket/ipsocket/inspect_spec.rb24
-rw-r--r--spec/ruby/library/socket/ipsocket/peeraddr_spec.rb74
-rw-r--r--spec/ruby/library/socket/ipsocket/recvfrom_spec.rb119
-rw-r--r--spec/ruby/library/socket/option/bool_spec.rb14
-rw-r--r--spec/ruby/library/socket/option/initialize_spec.rb83
-rw-r--r--spec/ruby/library/socket/option/inspect_spec.rb5
-rw-r--r--spec/ruby/library/socket/option/int_spec.rb27
-rw-r--r--spec/ruby/library/socket/option/linger_spec.rb32
-rw-r--r--spec/ruby/library/socket/option/new_spec.rb10
-rw-r--r--spec/ruby/library/socket/shared/address.rb259
-rw-r--r--spec/ruby/library/socket/shared/pack_sockaddr.rb50
-rw-r--r--spec/ruby/library/socket/shared/partially_closable_sockets.rb2
-rw-r--r--spec/ruby/library/socket/shared/recv_nonblock.rb54
-rw-r--r--spec/ruby/library/socket/shared/socketpair.rb23
-rw-r--r--spec/ruby/library/socket/socket/accept_loop_spec.rb84
-rw-r--r--spec/ruby/library/socket/socket/accept_nonblock_spec.rb126
-rw-r--r--spec/ruby/library/socket/socket/accept_spec.rb123
-rw-r--r--spec/ruby/library/socket/socket/bind_spec.rb111
-rw-r--r--spec/ruby/library/socket/socket/connect_nonblock_spec.rb98
-rw-r--r--spec/ruby/library/socket/socket/connect_spec.rb80
-rw-r--r--spec/ruby/library/socket/socket/for_fd_spec.rb5
-rw-r--r--spec/ruby/library/socket/socket/getaddrinfo_spec.rb293
-rw-r--r--spec/ruby/library/socket/socket/gethostbyaddr_spec.rb123
-rw-r--r--spec/ruby/library/socket/socket/gethostbyname_spec.rb138
-rw-r--r--spec/ruby/library/socket/socket/gethostname_spec.rb16
-rw-r--r--spec/ruby/library/socket/socket/getifaddrs_spec.rb117
-rw-r--r--spec/ruby/library/socket/socket/getnameinfo_spec.rb97
-rw-r--r--spec/ruby/library/socket/socket/getservbyname_spec.rb14
-rw-r--r--spec/ruby/library/socket/socket/getservbyport_spec.rb23
-rw-r--r--spec/ruby/library/socket/socket/initialize_spec.rb87
-rw-r--r--spec/ruby/library/socket/socket/ip_address_list_spec.rb50
-rw-r--r--spec/ruby/library/socket/socket/ipv6only_bang_spec.rb20
-rw-r--r--spec/ruby/library/socket/socket/listen_spec.rb56
-rw-r--r--spec/ruby/library/socket/socket/local_address_spec.rb43
-rw-r--r--spec/ruby/library/socket/socket/new_spec.rb2
-rw-r--r--spec/ruby/library/socket/socket/pack_sockaddr_in_spec.rb10
-rw-r--r--spec/ruby/library/socket/socket/pack_sockaddr_un_spec.rb10
-rw-r--r--spec/ruby/library/socket/socket/pair_spec.rb144
-rw-r--r--spec/ruby/library/socket/socket/recvfrom_nonblock_spec.rb190
-rw-r--r--spec/ruby/library/socket/socket/recvfrom_spec.rb159
-rw-r--r--spec/ruby/library/socket/socket/remote_address_spec.rb54
-rw-r--r--spec/ruby/library/socket/socket/sockaddr_in_spec.rb52
-rw-r--r--spec/ruby/library/socket/socket/sockaddr_un_spec.rb50
-rw-r--r--spec/ruby/library/socket/socket/socket_spec.rb4
-rw-r--r--spec/ruby/library/socket/socket/socketpair_spec.rb10
-rw-r--r--spec/ruby/library/socket/socket/sysaccept_spec.rb93
-rw-r--r--spec/ruby/library/socket/socket/tcp_server_loop_spec.rb54
-rw-r--r--spec/ruby/library/socket/socket/tcp_server_sockets_spec.rb39
-rw-r--r--spec/ruby/library/socket/socket/tcp_spec.rb88
-rw-r--r--spec/ruby/library/socket/socket/udp_server_loop_on_spec.rb47
-rw-r--r--spec/ruby/library/socket/socket/udp_server_loop_spec.rb59
-rw-r--r--spec/ruby/library/socket/socket/udp_server_recv_spec.rb35
-rw-r--r--spec/ruby/library/socket/socket/udp_server_sockets_spec.rb39
-rw-r--r--spec/ruby/library/socket/socket/unix_server_loop_spec.rb56
-rw-r--r--spec/ruby/library/socket/socket/unix_server_socket_spec.rb46
-rw-r--r--spec/ruby/library/socket/socket/unix_spec.rb43
-rw-r--r--spec/ruby/library/socket/socket/unpack_sockaddr_in_spec.rb37
-rw-r--r--spec/ruby/library/socket/socket/unpack_sockaddr_un_spec.rb36
-rw-r--r--spec/ruby/library/socket/spec_helper.rb14
-rw-r--r--spec/ruby/library/socket/tcpserver/accept_nonblock_spec.rb57
-rw-r--r--spec/ruby/library/socket/tcpserver/accept_spec.rb78
-rw-r--r--spec/ruby/library/socket/tcpserver/gets_spec.rb6
-rw-r--r--spec/ruby/library/socket/tcpserver/initialize_spec.rb101
-rw-r--r--spec/ruby/library/socket/tcpserver/listen_spec.rb28
-rw-r--r--spec/ruby/library/socket/tcpserver/new_spec.rb71
-rw-r--r--spec/ruby/library/socket/tcpserver/sysaccept_spec.rb46
-rw-r--r--spec/ruby/library/socket/tcpsocket/gethostbyname_spec.rb84
-rw-r--r--spec/ruby/library/socket/tcpsocket/initialize_spec.rb100
-rw-r--r--spec/ruby/library/socket/tcpsocket/local_address_spec.rb73
-rw-r--r--spec/ruby/library/socket/tcpsocket/new_spec.rb5
-rw-r--r--spec/ruby/library/socket/tcpsocket/open_spec.rb3
-rw-r--r--spec/ruby/library/socket/tcpsocket/partially_closable_spec.rb8
-rw-r--r--spec/ruby/library/socket/tcpsocket/recv_nonblock_spec.rb26
-rw-r--r--spec/ruby/library/socket/tcpsocket/recv_spec.rb28
-rw-r--r--spec/ruby/library/socket/tcpsocket/remote_address_spec.rb72
-rw-r--r--spec/ruby/library/socket/tcpsocket/setsockopt_spec.rb4
-rw-r--r--spec/ruby/library/socket/tcpsocket/shared/new.rb75
-rw-r--r--spec/ruby/library/socket/udpsocket/bind_spec.rb57
-rw-r--r--spec/ruby/library/socket/udpsocket/connect_spec.rb35
-rw-r--r--spec/ruby/library/socket/udpsocket/initialize_spec.rb53
-rw-r--r--spec/ruby/library/socket/udpsocket/local_address_spec.rb80
-rw-r--r--spec/ruby/library/socket/udpsocket/new_spec.rb26
-rw-r--r--spec/ruby/library/socket/udpsocket/open_spec.rb6
-rw-r--r--spec/ruby/library/socket/udpsocket/recvfrom_nonblock_spec.rb111
-rw-r--r--spec/ruby/library/socket/udpsocket/remote_address_spec.rb79
-rw-r--r--spec/ruby/library/socket/udpsocket/send_spec.rb94
-rw-r--r--spec/ruby/library/socket/udpsocket/write_spec.rb8
-rw-r--r--spec/ruby/library/socket/unixserver/accept_nonblock_spec.rb93
-rw-r--r--spec/ruby/library/socket/unixserver/accept_spec.rb155
-rw-r--r--spec/ruby/library/socket/unixserver/for_fd_spec.rb32
-rw-r--r--spec/ruby/library/socket/unixserver/initialize_spec.rb26
-rw-r--r--spec/ruby/library/socket/unixserver/listen_spec.rb19
-rw-r--r--spec/ruby/library/socket/unixserver/new_spec.rb10
-rw-r--r--spec/ruby/library/socket/unixserver/open_spec.rb31
-rw-r--r--spec/ruby/library/socket/unixserver/shared/new.rb31
-rw-r--r--spec/ruby/library/socket/unixserver/sysaccept_spec.rb50
-rw-r--r--spec/ruby/library/socket/unixsocket/addr_spec.rb51
-rw-r--r--spec/ruby/library/socket/unixsocket/initialize_spec.rb56
-rw-r--r--spec/ruby/library/socket/unixsocket/inspect_spec.rb22
-rw-r--r--spec/ruby/library/socket/unixsocket/local_address_spec.rb92
-rw-r--r--spec/ruby/library/socket/unixsocket/new_spec.rb10
-rw-r--r--spec/ruby/library/socket/unixsocket/open_spec.rb31
-rw-r--r--spec/ruby/library/socket/unixsocket/pair_spec.rb62
-rw-r--r--spec/ruby/library/socket/unixsocket/partially_closable_spec.rb38
-rw-r--r--spec/ruby/library/socket/unixsocket/path_spec.rb38
-rw-r--r--spec/ruby/library/socket/unixsocket/peeraddr_spec.rb40
-rw-r--r--spec/ruby/library/socket/unixsocket/recv_io_spec.rb52
-rw-r--r--spec/ruby/library/socket/unixsocket/recvfrom_spec.rb173
-rw-r--r--spec/ruby/library/socket/unixsocket/remote_address_spec.rb43
-rw-r--r--spec/ruby/library/socket/unixsocket/send_io_spec.rb30
-rw-r--r--spec/ruby/library/socket/unixsocket/shared/new.rb32
-rw-r--r--spec/ruby/library/socket/unixsocket/socketpair_spec.rb7
-rw-r--r--spec/ruby/library/stringio/append_spec.rb32
-rw-r--r--spec/ruby/library/stringio/binmode_spec.rb22
-rw-r--r--spec/ruby/library/stringio/bytes_spec.rb11
-rw-r--r--spec/ruby/library/stringio/chars_spec.rb11
-rw-r--r--spec/ruby/library/stringio/close_read_spec.rb21
-rw-r--r--spec/ruby/library/stringio/close_spec.rb25
-rw-r--r--spec/ruby/library/stringio/close_write_spec.rb23
-rw-r--r--spec/ruby/library/stringio/closed_read_spec.rb10
-rw-r--r--spec/ruby/library/stringio/closed_spec.rb14
-rw-r--r--spec/ruby/library/stringio/closed_write_spec.rb10
-rw-r--r--spec/ruby/library/stringio/codepoints_spec.rb9
-rw-r--r--spec/ruby/library/stringio/each_byte_spec.rb48
-rw-r--r--spec/ruby/library/stringio/each_char_spec.rb35
-rw-r--r--spec/ruby/library/stringio/each_codepoint_spec.rb49
-rw-r--r--spec/ruby/library/stringio/each_line_spec.rb209
-rw-r--r--spec/ruby/library/stringio/each_spec.rb23
-rw-r--r--spec/ruby/library/stringio/eof_spec.rb32
-rw-r--r--spec/ruby/library/stringio/external_encoding_spec.rb24
-rw-r--r--spec/ruby/library/stringio/fcntl_spec.rb6
-rw-r--r--spec/ruby/library/stringio/fileno_spec.rb7
-rw-r--r--spec/ruby/library/stringio/fixtures/classes.rb4
-rw-r--r--spec/ruby/library/stringio/flush_spec.rb8
-rw-r--r--spec/ruby/library/stringio/fsync_spec.rb8
-rw-r--r--spec/ruby/library/stringio/getbyte_spec.rb10
-rw-r--r--spec/ruby/library/stringio/getc_spec.rb10
-rw-r--r--spec/ruby/library/stringio/getch_spec.rb32
-rw-r--r--spec/ruby/library/stringio/getpass_spec.rb11
-rw-r--r--spec/ruby/library/stringio/gets_spec.rb262
-rw-r--r--spec/ruby/library/stringio/initialize_spec.rb299
-rw-r--r--spec/ruby/library/stringio/inspect_spec.rb19
-rw-r--r--spec/ruby/library/stringio/internal_encoding_spec.rb2
-rw-r--r--spec/ruby/library/stringio/isatty_spec.rb9
-rw-r--r--spec/ruby/library/stringio/length_spec.rb9
-rw-r--r--spec/ruby/library/stringio/lineno_spec.rb10
-rw-r--r--spec/ruby/library/stringio/lines_spec.rb21
-rw-r--r--spec/ruby/library/stringio/new_spec.rb10
-rw-r--r--spec/ruby/library/stringio/open_spec.rb193
-rw-r--r--spec/ruby/library/stringio/path_spec.rb6
-rw-r--r--spec/ruby/library/stringio/pid_spec.rb6
-rw-r--r--spec/ruby/library/stringio/pos_spec.rb18
-rw-r--r--spec/ruby/library/stringio/print_spec.rb36
-rw-r--r--spec/ruby/library/stringio/printf_spec.rb58
-rw-r--r--spec/ruby/library/stringio/putc_spec.rb37
-rw-r--r--spec/ruby/library/stringio/puts_spec.rb57
-rw-r--r--spec/ruby/library/stringio/read_nonblock_spec.rb39
-rw-r--r--spec/ruby/library/stringio/read_spec.rb10
-rw-r--r--spec/ruby/library/stringio/readbyte_spec.rb8
-rw-r--r--spec/ruby/library/stringio/readchar_spec.rb8
-rw-r--r--spec/ruby/library/stringio/readline_spec.rb145
-rw-r--r--spec/ruby/library/stringio/readlines_spec.rb51
-rw-r--r--spec/ruby/library/stringio/readpartial_spec.rb54
-rw-r--r--spec/ruby/library/stringio/reopen_spec.rb155
-rw-r--r--spec/ruby/library/stringio/rewind_spec.rb6
-rw-r--r--spec/ruby/library/stringio/seek_spec.rb28
-rw-r--r--spec/ruby/library/stringio/set_encoding_by_bom_spec.rb237
-rw-r--r--spec/ruby/library/stringio/set_encoding_spec.rb24
-rw-r--r--spec/ruby/library/stringio/shared/codepoints.rb45
-rw-r--r--spec/ruby/library/stringio/shared/each.rb114
-rw-r--r--spec/ruby/library/stringio/shared/each_byte.rb48
-rw-r--r--spec/ruby/library/stringio/shared/each_char.rb36
-rw-r--r--spec/ruby/library/stringio/shared/eof.rb24
-rw-r--r--spec/ruby/library/stringio/shared/getc.rb22
-rw-r--r--spec/ruby/library/stringio/shared/gets.rb249
-rw-r--r--spec/ruby/library/stringio/shared/isatty.rb5
-rw-r--r--spec/ruby/library/stringio/shared/length.rb5
-rw-r--r--spec/ruby/library/stringio/shared/read.rb62
-rw-r--r--spec/ruby/library/stringio/shared/readchar.rb8
-rw-r--r--spec/ruby/library/stringio/shared/sysread.rb4
-rw-r--r--spec/ruby/library/stringio/shared/tell.rb12
-rw-r--r--spec/ruby/library/stringio/shared/write.rb78
-rw-r--r--spec/ruby/library/stringio/size_spec.rb9
-rw-r--r--spec/ruby/library/stringio/string_spec.rb16
-rw-r--r--spec/ruby/library/stringio/stringio_spec.rb5
-rw-r--r--spec/ruby/library/stringio/sync_spec.rb8
-rw-r--r--spec/ruby/library/stringio/sysread_spec.rb11
-rw-r--r--spec/ruby/library/stringio/syswrite_spec.rb6
-rw-r--r--spec/ruby/library/stringio/tell_spec.rb9
-rw-r--r--spec/ruby/library/stringio/truncate_spec.rb36
-rw-r--r--spec/ruby/library/stringio/tty_spec.rb9
-rw-r--r--spec/ruby/library/stringio/ungetbyte_spec.rb40
-rw-r--r--spec/ruby/library/stringio/ungetc_spec.rb28
-rw-r--r--spec/ruby/library/stringio/write_nonblock_spec.rb12
-rw-r--r--spec/ruby/library/stringio/write_spec.rb6
-rw-r--r--spec/ruby/library/stringscanner/append_spec.rb32
-rw-r--r--spec/ruby/library/stringscanner/beginning_of_line_spec.rb27
-rw-r--r--spec/ruby/library/stringscanner/bol_spec.rb7
-rw-r--r--spec/ruby/library/stringscanner/captures_spec.rb36
-rw-r--r--spec/ruby/library/stringscanner/charpos_spec.rb18
-rw-r--r--spec/ruby/library/stringscanner/check_spec.rb79
-rw-r--r--spec/ruby/library/stringscanner/check_until_spec.rb122
-rw-r--r--spec/ruby/library/stringscanner/clear_spec.rb20
-rw-r--r--spec/ruby/library/stringscanner/concat_spec.rb11
-rw-r--r--spec/ruby/library/stringscanner/dup_spec.rb8
-rw-r--r--spec/ruby/library/stringscanner/element_reference_spec.rb22
-rw-r--r--spec/ruby/library/stringscanner/empty_spec.rb20
-rw-r--r--spec/ruby/library/stringscanner/eos_spec.rb19
-rw-r--r--spec/ruby/library/stringscanner/exist_spec.rb101
-rw-r--r--spec/ruby/library/stringscanner/fixed_anchor_spec.rb17
-rw-r--r--spec/ruby/library/stringscanner/get_byte_spec.rb83
-rw-r--r--spec/ruby/library/stringscanner/getbyte_spec.rb23
-rw-r--r--spec/ruby/library/stringscanner/getch_spec.rb69
-rw-r--r--spec/ruby/library/stringscanner/initialize_spec.rb14
-rw-r--r--spec/ruby/library/stringscanner/inspect_spec.rb4
-rw-r--r--spec/ruby/library/stringscanner/match_spec.rb25
-rw-r--r--spec/ruby/library/stringscanner/matched_size_spec.rb23
-rw-r--r--spec/ruby/library/stringscanner/matched_spec.rb8
-rw-r--r--spec/ruby/library/stringscanner/must_C_version_spec.rb4
-rw-r--r--spec/ruby/library/stringscanner/named_captures_spec.rb28
-rw-r--r--spec/ruby/library/stringscanner/peek_byte_spec.rb35
-rw-r--r--spec/ruby/library/stringscanner/peek_spec.rb42
-rw-r--r--spec/ruby/library/stringscanner/peep_spec.rb20
-rw-r--r--spec/ruby/library/stringscanner/pointer_spec.rb11
-rw-r--r--spec/ruby/library/stringscanner/pos_spec.rb59
-rw-r--r--spec/ruby/library/stringscanner/post_match_spec.rb4
-rw-r--r--spec/ruby/library/stringscanner/pre_match_spec.rb4
-rw-r--r--spec/ruby/library/stringscanner/reset_spec.rb2
-rw-r--r--spec/ruby/library/stringscanner/rest_size_spec.rb29
-rw-r--r--spec/ruby/library/stringscanner/rest_spec.rb10
-rw-r--r--spec/ruby/library/stringscanner/restsize_spec.rb20
-rw-r--r--spec/ruby/library/stringscanner/scan_byte_spec.rb98
-rw-r--r--spec/ruby/library/stringscanner/scan_full_spec.rb16
-rw-r--r--spec/ruby/library/stringscanner/scan_integer_spec.rb157
-rw-r--r--spec/ruby/library/stringscanner/scan_spec.rb76
-rw-r--r--spec/ruby/library/stringscanner/scan_until_spec.rb122
-rw-r--r--spec/ruby/library/stringscanner/search_full_spec.rb107
-rw-r--r--spec/ruby/library/stringscanner/shared/bol.rb25
-rw-r--r--spec/ruby/library/stringscanner/shared/concat.rb30
-rw-r--r--spec/ruby/library/stringscanner/shared/eos.rb17
-rw-r--r--spec/ruby/library/stringscanner/shared/extract_range.rb15
-rw-r--r--spec/ruby/library/stringscanner/shared/extract_range_matched.rb13
-rw-r--r--spec/ruby/library/stringscanner/shared/get_byte.rb29
-rw-r--r--spec/ruby/library/stringscanner/shared/matched_size.rb21
-rw-r--r--spec/ruby/library/stringscanner/shared/peek.rb47
-rw-r--r--spec/ruby/library/stringscanner/shared/pos.rb52
-rw-r--r--spec/ruby/library/stringscanner/shared/rest_size.rb18
-rw-r--r--spec/ruby/library/stringscanner/shared/terminate.rb8
-rw-r--r--spec/ruby/library/stringscanner/size_spec.rb17
-rw-r--r--spec/ruby/library/stringscanner/skip_spec.rb16
-rw-r--r--spec/ruby/library/stringscanner/skip_until_spec.rb118
-rw-r--r--spec/ruby/library/stringscanner/string_spec.rb6
-rw-r--r--spec/ruby/library/stringscanner/terminate_spec.rb10
-rw-r--r--spec/ruby/library/stringscanner/unscan_spec.rb8
-rw-r--r--spec/ruby/library/stringscanner/values_at_spec.rb68
-rw-r--r--spec/ruby/library/syslog/alert_spec.rb5
-rw-r--r--spec/ruby/library/syslog/close_spec.rb23
-rw-r--r--spec/ruby/library/syslog/constants_spec.rb7
-rw-r--r--spec/ruby/library/syslog/crit_spec.rb5
-rw-r--r--spec/ruby/library/syslog/debug_spec.rb5
-rw-r--r--spec/ruby/library/syslog/emerg_spec.rb5
-rw-r--r--spec/ruby/library/syslog/err_spec.rb5
-rw-r--r--spec/ruby/library/syslog/facility_spec.rb9
-rw-r--r--spec/ruby/library/syslog/ident_spec.rb9
-rw-r--r--spec/ruby/library/syslog/info_spec.rb5
-rw-r--r--spec/ruby/library/syslog/inspect_spec.rb7
-rw-r--r--spec/ruby/library/syslog/instance_spec.rb3
-rw-r--r--spec/ruby/library/syslog/log_spec.rb29
-rw-r--r--spec/ruby/library/syslog/mask_spec.rb19
-rw-r--r--spec/ruby/library/syslog/notice_spec.rb5
-rw-r--r--spec/ruby/library/syslog/open_spec.rb56
-rw-r--r--spec/ruby/library/syslog/opened_spec.rb19
-rw-r--r--spec/ruby/library/syslog/options_spec.rb9
-rw-r--r--spec/ruby/library/syslog/reopen_spec.rb8
-rw-r--r--spec/ruby/library/syslog/shared/log.rb19
-rw-r--r--spec/ruby/library/syslog/shared/reopen.rb40
-rw-r--r--spec/ruby/library/syslog/warning_spec.rb5
-rw-r--r--spec/ruby/library/tempfile/_close_spec.rb6
-rw-r--r--spec/ruby/library/tempfile/callback_spec.rb6
-rw-r--r--spec/ruby/library/tempfile/close_spec.rb14
-rw-r--r--spec/ruby/library/tempfile/create_spec.rb176
-rw-r--r--spec/ruby/library/tempfile/delete_spec.rb14
-rw-r--r--spec/ruby/library/tempfile/initialize_spec.rb13
-rw-r--r--spec/ruby/library/tempfile/length_spec.rb7
-rw-r--r--spec/ruby/library/tempfile/open_spec.rb33
-rw-r--r--spec/ruby/library/tempfile/path_spec.rb4
-rw-r--r--spec/ruby/library/tempfile/shared/length.rb21
-rw-r--r--spec/ruby/library/tempfile/shared/unlink.rb12
-rw-r--r--spec/ruby/library/tempfile/size_spec.rb23
-rw-r--r--spec/ruby/library/tempfile/unlink_spec.rb7
-rw-r--r--spec/ruby/library/thread/exclusive_spec.rb12
-rw-r--r--spec/ruby/library/thread/queue/append_spec.rb7
-rw-r--r--spec/ruby/library/thread/queue/clear_spec.rb9
-rw-r--r--spec/ruby/library/thread/queue/close_spec.rb9
-rw-r--r--spec/ruby/library/thread/queue/closed_spec.rb9
-rw-r--r--spec/ruby/library/thread/queue/deq_spec.rb7
-rw-r--r--spec/ruby/library/thread/queue/empty_spec.rb7
-rw-r--r--spec/ruby/library/thread/queue/enq_spec.rb7
-rw-r--r--spec/ruby/library/thread/queue/length_spec.rb7
-rw-r--r--spec/ruby/library/thread/queue/num_waiting_spec.rb7
-rw-r--r--spec/ruby/library/thread/queue/pop_spec.rb7
-rw-r--r--spec/ruby/library/thread/queue/push_spec.rb7
-rw-r--r--spec/ruby/library/thread/queue/shift_spec.rb7
-rw-r--r--spec/ruby/library/thread/queue/size_spec.rb7
-rw-r--r--spec/ruby/library/thread/queue_spec.rb8
-rw-r--r--spec/ruby/library/thread/shared/queue/clear.rb10
-rw-r--r--spec/ruby/library/thread/shared/queue/close.rb26
-rw-r--r--spec/ruby/library/thread/shared/queue/closed.rb12
-rw-r--r--spec/ruby/library/thread/shared/queue/deque.rb37
-rw-r--r--spec/ruby/library/thread/shared/queue/empty.rb12
-rw-r--r--spec/ruby/library/thread/shared/queue/enque.rb10
-rw-r--r--spec/ruby/library/thread/sizedqueue/append_spec.rb12
-rw-r--r--spec/ruby/library/thread/sizedqueue/clear_spec.rb9
-rw-r--r--spec/ruby/library/thread/sizedqueue/close_spec.rb9
-rw-r--r--spec/ruby/library/thread/sizedqueue/closed_spec.rb9
-rw-r--r--spec/ruby/library/thread/sizedqueue/deq_spec.rb7
-rw-r--r--spec/ruby/library/thread/sizedqueue/empty_spec.rb7
-rw-r--r--spec/ruby/library/thread/sizedqueue/enq_spec.rb12
-rw-r--r--spec/ruby/library/thread/sizedqueue/length_spec.rb7
-rw-r--r--spec/ruby/library/thread/sizedqueue/max_spec.rb52
-rw-r--r--spec/ruby/library/thread/sizedqueue/new_spec.rb25
-rw-r--r--spec/ruby/library/thread/sizedqueue/num_waiting_spec.rb18
-rw-r--r--spec/ruby/library/thread/sizedqueue/pop_spec.rb7
-rw-r--r--spec/ruby/library/thread/sizedqueue/push_spec.rb12
-rw-r--r--spec/ruby/library/thread/sizedqueue/shared/enque.rb34
-rw-r--r--spec/ruby/library/thread/sizedqueue/shift_spec.rb7
-rw-r--r--spec/ruby/library/thread/sizedqueue/size_spec.rb7
-rw-r--r--spec/ruby/library/thread/sizedqueue_spec.rb8
-rw-r--r--spec/ruby/library/time/httpdate_spec.rb2
-rw-r--r--spec/ruby/library/time/iso8601_spec.rb9
-rw-r--r--spec/ruby/library/time/rfc2822_spec.rb67
-rw-r--r--spec/ruby/library/time/rfc822_spec.rb7
-rw-r--r--spec/ruby/library/time/shared/rfc2822.rb65
-rw-r--r--spec/ruby/library/time/shared/xmlschema.rb53
-rw-r--r--spec/ruby/library/time/to_date_spec.rb42
-rw-r--r--spec/ruby/library/time/to_time_spec.rb20
-rw-r--r--spec/ruby/library/time/xmlschema_spec.rb55
-rw-r--r--spec/ruby/library/timeout/error_spec.rb4
-rw-r--r--spec/ruby/library/timeout/timeout_spec.rb41
-rw-r--r--spec/ruby/library/tmpdir/dir/mktmpdir_spec.rb24
-rw-r--r--spec/ruby/library/tmpdir/dir/tmpdir_spec.rb6
-rw-r--r--spec/ruby/library/uri/decode_www_form_component_spec.rb2
-rw-r--r--spec/ruby/library/uri/decode_www_form_spec.rb2
-rw-r--r--spec/ruby/library/uri/encode_www_form_component_spec.rb2
-rw-r--r--spec/ruby/library/uri/encode_www_form_spec.rb2
-rw-r--r--spec/ruby/library/uri/eql_spec.rb6
-rw-r--r--spec/ruby/library/uri/equality_spec.rb6
-rw-r--r--spec/ruby/library/uri/escape/decode_spec.rb2
-rw-r--r--spec/ruby/library/uri/escape/encode_spec.rb2
-rw-r--r--spec/ruby/library/uri/escape/escape_spec.rb2
-rw-r--r--spec/ruby/library/uri/escape/unescape_spec.rb2
-rw-r--r--spec/ruby/library/uri/extract_spec.rb2
-rw-r--r--spec/ruby/library/uri/ftp/build_spec.rb2
-rw-r--r--spec/ruby/library/uri/ftp/merge_spec.rb2
-rw-r--r--spec/ruby/library/uri/ftp/new2_spec.rb2
-rw-r--r--spec/ruby/library/uri/ftp/path_spec.rb2
-rw-r--r--spec/ruby/library/uri/ftp/set_typecode_spec.rb2
-rw-r--r--spec/ruby/library/uri/ftp/to_s_spec.rb2
-rw-r--r--spec/ruby/library/uri/ftp/typecode_spec.rb2
-rw-r--r--spec/ruby/library/uri/generic/absolute_spec.rb2
-rw-r--r--spec/ruby/library/uri/generic/build2_spec.rb2
-rw-r--r--spec/ruby/library/uri/generic/build_spec.rb2
-rw-r--r--spec/ruby/library/uri/generic/coerce_spec.rb2
-rw-r--r--spec/ruby/library/uri/generic/component_ary_spec.rb2
-rw-r--r--spec/ruby/library/uri/generic/component_spec.rb2
-rw-r--r--spec/ruby/library/uri/generic/default_port_spec.rb2
-rw-r--r--spec/ruby/library/uri/generic/eql_spec.rb2
-rw-r--r--spec/ruby/library/uri/generic/equal_value_spec.rb2
-rw-r--r--spec/ruby/library/uri/generic/fragment_spec.rb2
-rw-r--r--spec/ruby/library/uri/generic/hash_spec.rb2
-rw-r--r--spec/ruby/library/uri/generic/hierarchical_spec.rb2
-rw-r--r--spec/ruby/library/uri/generic/host_spec.rb7
-rw-r--r--spec/ruby/library/uri/generic/inspect_spec.rb2
-rw-r--r--spec/ruby/library/uri/generic/merge_spec.rb2
-rw-r--r--spec/ruby/library/uri/generic/minus_spec.rb2
-rw-r--r--spec/ruby/library/uri/generic/normalize_spec.rb2
-rw-r--r--spec/ruby/library/uri/generic/opaque_spec.rb2
-rw-r--r--spec/ruby/library/uri/generic/password_spec.rb2
-rw-r--r--spec/ruby/library/uri/generic/path_spec.rb2
-rw-r--r--spec/ruby/library/uri/generic/plus_spec.rb2
-rw-r--r--spec/ruby/library/uri/generic/port_spec.rb2
-rw-r--r--spec/ruby/library/uri/generic/query_spec.rb2
-rw-r--r--spec/ruby/library/uri/generic/registry_spec.rb2
-rw-r--r--spec/ruby/library/uri/generic/relative_spec.rb2
-rw-r--r--spec/ruby/library/uri/generic/route_from_spec.rb2
-rw-r--r--spec/ruby/library/uri/generic/route_to_spec.rb2
-rw-r--r--spec/ruby/library/uri/generic/scheme_spec.rb2
-rw-r--r--spec/ruby/library/uri/generic/select_spec.rb2
-rw-r--r--spec/ruby/library/uri/generic/set_fragment_spec.rb2
-rw-r--r--spec/ruby/library/uri/generic/set_host_spec.rb2
-rw-r--r--spec/ruby/library/uri/generic/set_opaque_spec.rb2
-rw-r--r--spec/ruby/library/uri/generic/set_password_spec.rb2
-rw-r--r--spec/ruby/library/uri/generic/set_path_spec.rb2
-rw-r--r--spec/ruby/library/uri/generic/set_port_spec.rb2
-rw-r--r--spec/ruby/library/uri/generic/set_query_spec.rb2
-rw-r--r--spec/ruby/library/uri/generic/set_registry_spec.rb2
-rw-r--r--spec/ruby/library/uri/generic/set_scheme_spec.rb2
-rw-r--r--spec/ruby/library/uri/generic/set_user_spec.rb2
-rw-r--r--spec/ruby/library/uri/generic/set_userinfo_spec.rb2
-rw-r--r--spec/ruby/library/uri/generic/to_s_spec.rb7
-rw-r--r--spec/ruby/library/uri/generic/use_registry_spec.rb2
-rw-r--r--spec/ruby/library/uri/generic/user_spec.rb2
-rw-r--r--spec/ruby/library/uri/generic/userinfo_spec.rb2
-rw-r--r--spec/ruby/library/uri/http/build_spec.rb2
-rw-r--r--spec/ruby/library/uri/http/request_uri_spec.rb2
-rw-r--r--spec/ruby/library/uri/join_spec.rb6
-rw-r--r--spec/ruby/library/uri/ldap/attributes_spec.rb2
-rw-r--r--spec/ruby/library/uri/ldap/build_spec.rb2
-rw-r--r--spec/ruby/library/uri/ldap/dn_spec.rb2
-rw-r--r--spec/ruby/library/uri/ldap/extensions_spec.rb2
-rw-r--r--spec/ruby/library/uri/ldap/filter_spec.rb2
-rw-r--r--spec/ruby/library/uri/ldap/hierarchical_spec.rb2
-rw-r--r--spec/ruby/library/uri/ldap/scope_spec.rb2
-rw-r--r--spec/ruby/library/uri/ldap/set_attributes_spec.rb2
-rw-r--r--spec/ruby/library/uri/ldap/set_dn_spec.rb2
-rw-r--r--spec/ruby/library/uri/ldap/set_extensions_spec.rb2
-rw-r--r--spec/ruby/library/uri/ldap/set_filter_spec.rb2
-rw-r--r--spec/ruby/library/uri/ldap/set_scope_spec.rb2
-rw-r--r--spec/ruby/library/uri/mailto/build_spec.rb10
-rw-r--r--spec/ruby/library/uri/mailto/headers_spec.rb2
-rw-r--r--spec/ruby/library/uri/mailto/set_headers_spec.rb2
-rw-r--r--spec/ruby/library/uri/mailto/set_to_spec.rb2
-rw-r--r--spec/ruby/library/uri/mailto/to_mailtext_spec.rb2
-rw-r--r--spec/ruby/library/uri/mailto/to_rfc822text_spec.rb2
-rw-r--r--spec/ruby/library/uri/mailto/to_s_spec.rb2
-rw-r--r--spec/ruby/library/uri/mailto/to_spec.rb2
-rw-r--r--spec/ruby/library/uri/merge_spec.rb2
-rw-r--r--spec/ruby/library/uri/normalize_spec.rb4
-rw-r--r--spec/ruby/library/uri/parse_spec.rb28
-rw-r--r--spec/ruby/library/uri/parser/escape_spec.rb2
-rw-r--r--spec/ruby/library/uri/parser/extract_spec.rb89
-rw-r--r--spec/ruby/library/uri/parser/inspect_spec.rb2
-rw-r--r--spec/ruby/library/uri/parser/join_spec.rb61
-rw-r--r--spec/ruby/library/uri/parser/make_regexp_spec.rb2
-rw-r--r--spec/ruby/library/uri/parser/parse_spec.rb214
-rw-r--r--spec/ruby/library/uri/parser/split_spec.rb2
-rw-r--r--spec/ruby/library/uri/parser/unescape_spec.rb2
-rw-r--r--spec/ruby/library/uri/plus_spec.rb174
-rw-r--r--spec/ruby/library/uri/regexp_spec.rb2
-rw-r--r--spec/ruby/library/uri/route_from_spec.rb2
-rw-r--r--spec/ruby/library/uri/route_to_spec.rb2
-rw-r--r--spec/ruby/library/uri/select_spec.rb14
-rw-r--r--spec/ruby/library/uri/set_component_spec.rb64
-rw-r--r--spec/ruby/library/uri/shared/eql.rb6
-rw-r--r--spec/ruby/library/uri/shared/extract.rb83
-rw-r--r--spec/ruby/library/uri/shared/join.rb54
-rw-r--r--spec/ruby/library/uri/shared/parse.rb199
-rw-r--r--spec/ruby/library/uri/split_spec.rb2
-rw-r--r--spec/ruby/library/uri/uri_spec.rb6
-rw-r--r--spec/ruby/library/uri/util/make_components_hash_spec.rb2
-rw-r--r--spec/ruby/library/weakref/__getobj___spec.rb10
-rw-r--r--spec/ruby/library/weakref/allocate_spec.rb8
-rw-r--r--spec/ruby/library/weakref/fixtures/classes.rb6
-rw-r--r--spec/ruby/library/weakref/new_spec.rb13
-rw-r--r--spec/ruby/library/weakref/send_spec.rb6
-rw-r--r--spec/ruby/library/weakref/weakref_alive_spec.rb8
-rw-r--r--spec/ruby/library/win32ole/fixtures/classes.rb29
-rw-r--r--spec/ruby/library/win32ole/fixtures/event.xml4
-rw-r--r--spec/ruby/library/win32ole/win32ole/_getproperty_spec.rb16
-rw-r--r--spec/ruby/library/win32ole/win32ole/_invoke_spec.rb11
-rw-r--r--spec/ruby/library/win32ole/win32ole/codepage_spec.rb5
-rw-r--r--spec/ruby/library/win32ole/win32ole/connect_spec.rb9
-rw-r--r--spec/ruby/library/win32ole/win32ole/const_load_spec.rb13
-rw-r--r--spec/ruby/library/win32ole/win32ole/constants_spec.rb5
-rw-r--r--spec/ruby/library/win32ole/win32ole/create_guid_spec.rb5
-rw-r--r--spec/ruby/library/win32ole/win32ole/invoke_spec.rb16
-rw-r--r--spec/ruby/library/win32ole/win32ole/locale_spec.rb9
-rw-r--r--spec/ruby/library/win32ole/win32ole/new_spec.rb15
-rw-r--r--spec/ruby/library/win32ole/win32ole/ole_func_methods_spec.rb21
-rw-r--r--spec/ruby/library/win32ole/win32ole/ole_get_methods_spec.rb9
-rw-r--r--spec/ruby/library/win32ole/win32ole/ole_method_help_spec.rb7
-rw-r--r--spec/ruby/library/win32ole/win32ole/ole_method_spec.rb7
-rw-r--r--spec/ruby/library/win32ole/win32ole/ole_methods_spec.rb21
-rw-r--r--spec/ruby/library/win32ole/win32ole/ole_obj_help_spec.rb16
-rw-r--r--spec/ruby/library/win32ole/win32ole/ole_put_methods_spec.rb21
-rw-r--r--spec/ruby/library/win32ole/win32ole/setproperty_spec.rb7
-rw-r--r--spec/ruby/library/win32ole/win32ole/shared/ole_method.rb20
-rw-r--r--spec/ruby/library/win32ole/win32ole/shared/setproperty.rb22
-rw-r--r--spec/ruby/library/win32ole/win32ole_event/new_spec.rb47
-rw-r--r--spec/ruby/library/win32ole/win32ole_event/on_event_spec.rb105
-rw-r--r--spec/ruby/library/win32ole/win32ole_method/dispid_spec.rb9
-rw-r--r--spec/ruby/library/win32ole/win32ole_method/event_interface_spec.rb37
-rw-r--r--spec/ruby/library/win32ole/win32ole_method/event_spec.rb27
-rw-r--r--spec/ruby/library/win32ole/win32ole_method/helpcontext_spec.rb17
-rw-r--r--spec/ruby/library/win32ole/win32ole_method/helpfile_spec.rb9
-rw-r--r--spec/ruby/library/win32ole/win32ole_method/helpstring_spec.rb9
-rw-r--r--spec/ruby/library/win32ole/win32ole_method/invkind_spec.rb9
-rw-r--r--spec/ruby/library/win32ole/win32ole_method/invoke_kind_spec.rb9
-rw-r--r--spec/ruby/library/win32ole/win32ole_method/name_spec.rb5
-rw-r--r--spec/ruby/library/win32ole/win32ole_method/new_spec.rb23
-rw-r--r--spec/ruby/library/win32ole/win32ole_method/offset_vtbl_spec.rb11
-rw-r--r--spec/ruby/library/win32ole/win32ole_method/params_spec.rb21
-rw-r--r--spec/ruby/library/win32ole/win32ole_method/return_type_detail_spec.rb11
-rw-r--r--spec/ruby/library/win32ole/win32ole_method/return_type_spec.rb9
-rw-r--r--spec/ruby/library/win32ole/win32ole_method/return_vtype_spec.rb9
-rw-r--r--spec/ruby/library/win32ole/win32ole_method/shared/name.rb6
-rw-r--r--spec/ruby/library/win32ole/win32ole_method/size_opt_params_spec.rb9
-rw-r--r--spec/ruby/library/win32ole/win32ole_method/size_params_spec.rb9
-rw-r--r--spec/ruby/library/win32ole/win32ole_method/to_s_spec.rb5
-rw-r--r--spec/ruby/library/win32ole/win32ole_method/visible_spec.rb11
-rw-r--r--spec/ruby/library/win32ole/win32ole_param/default_spec.rb17
-rw-r--r--spec/ruby/library/win32ole/win32ole_param/input_spec.rb11
-rw-r--r--spec/ruby/library/win32ole/win32ole_param/name_spec.rb5
-rw-r--r--spec/ruby/library/win32ole/win32ole_param/ole_type_detail_spec.rb9
-rw-r--r--spec/ruby/library/win32ole/win32ole_param/ole_type_spec.rb9
-rw-r--r--spec/ruby/library/win32ole/win32ole_param/optional_spec.rb11
-rw-r--r--spec/ruby/library/win32ole/win32ole_param/retval_spec.rb11
-rw-r--r--spec/ruby/library/win32ole/win32ole_param/shared/name.rb6
-rw-r--r--spec/ruby/library/win32ole/win32ole_param/to_s_spec.rb5
-rw-r--r--spec/ruby/library/win32ole/win32ole_type/guid_spec.rb5
-rw-r--r--spec/ruby/library/win32ole/win32ole_type/helpcontext_spec.rb7
-rw-r--r--spec/ruby/library/win32ole/win32ole_type/helpfile_spec.rb7
-rw-r--r--spec/ruby/library/win32ole/win32ole_type/helpstring_spec.rb5
-rw-r--r--spec/ruby/library/win32ole/win32ole_type/major_version_spec.rb7
-rw-r--r--spec/ruby/library/win32ole/win32ole_type/minor_version_spec.rb7
-rw-r--r--spec/ruby/library/win32ole/win32ole_type/name_spec.rb5
-rw-r--r--spec/ruby/library/win32ole/win32ole_type/new_spec.rb38
-rw-r--r--spec/ruby/library/win32ole/win32ole_type/ole_classes_spec.rb7
-rw-r--r--spec/ruby/library/win32ole/win32ole_type/ole_methods_spec.rb7
-rw-r--r--spec/ruby/library/win32ole/win32ole_type/ole_type_spec.rb5
-rw-r--r--spec/ruby/library/win32ole/win32ole_type/progid_spec.rb5
-rw-r--r--spec/ruby/library/win32ole/win32ole_type/progids_spec.rb7
-rw-r--r--spec/ruby/library/win32ole/win32ole_type/shared/name.rb4
-rw-r--r--spec/ruby/library/win32ole/win32ole_type/src_type_spec.rb7
-rw-r--r--spec/ruby/library/win32ole/win32ole_type/to_s_spec.rb5
-rw-r--r--spec/ruby/library/win32ole/win32ole_type/typekind_spec.rb7
-rw-r--r--spec/ruby/library/win32ole/win32ole_type/typelibs_spec.rb9
-rw-r--r--spec/ruby/library/win32ole/win32ole_type/variables_spec.rb5
-rw-r--r--spec/ruby/library/win32ole/win32ole_type/visible_spec.rb7
-rw-r--r--spec/ruby/library/win32ole/win32ole_variable/name_spec.rb3
-rw-r--r--spec/ruby/library/win32ole/win32ole_variable/ole_type_detail_spec.rb7
-rw-r--r--spec/ruby/library/win32ole/win32ole_variable/ole_type_spec.rb5
-rw-r--r--spec/ruby/library/win32ole/win32ole_variable/shared/name.rb4
-rw-r--r--spec/ruby/library/win32ole/win32ole_variable/to_s_spec.rb3
-rw-r--r--spec/ruby/library/win32ole/win32ole_variable/value_spec.rb7
-rw-r--r--spec/ruby/library/win32ole/win32ole_variable/variable_kind_spec.rb5
-rw-r--r--spec/ruby/library/win32ole/win32ole_variable/varkind_spec.rb5
-rw-r--r--spec/ruby/library/win32ole/win32ole_variable/visible_spec.rb5
-rw-r--r--spec/ruby/library/yaml/add_builtin_type_spec.rb2
-rw-r--r--spec/ruby/library/yaml/add_domain_type_spec.rb2
-rw-r--r--spec/ruby/library/yaml/add_private_type_spec.rb2
-rw-r--r--spec/ruby/library/yaml/add_ruby_type_spec.rb2
-rw-r--r--spec/ruby/library/yaml/detect_implicit_spec.rb2
-rw-r--r--spec/ruby/library/yaml/dump_spec.rb29
-rw-r--r--spec/ruby/library/yaml/dump_stream_spec.rb5
-rw-r--r--spec/ruby/library/yaml/each_node_spec.rb2
-rw-r--r--spec/ruby/library/yaml/emitter_spec.rb2
-rw-r--r--spec/ruby/library/yaml/fixtures/common.rb10
-rw-r--r--spec/ruby/library/yaml/fixtures/example_class.rb8
-rw-r--r--spec/ruby/library/yaml/fixtures/strings.rb56
-rw-r--r--spec/ruby/library/yaml/generic_parser_spec.rb2
-rw-r--r--spec/ruby/library/yaml/load_documents_spec.rb10
-rw-r--r--spec/ruby/library/yaml/load_file_spec.rb15
-rw-r--r--spec/ruby/library/yaml/load_spec.rb116
-rw-r--r--spec/ruby/library/yaml/load_stream_spec.rb25
-rw-r--r--spec/ruby/library/yaml/object_maker_spec.rb2
-rw-r--r--spec/ruby/library/yaml/parse_documents_spec.rb2
-rw-r--r--spec/ruby/library/yaml/parse_file_spec.rb14
-rw-r--r--spec/ruby/library/yaml/parse_spec.rb11
-rw-r--r--spec/ruby/library/yaml/parser_spec.rb2
-rw-r--r--spec/ruby/library/yaml/quick_emit_spec.rb2
-rw-r--r--spec/ruby/library/yaml/read_type_class_spec.rb2
-rw-r--r--spec/ruby/library/yaml/shared/each_document.rb18
-rw-r--r--spec/ruby/library/yaml/shared/load.rb142
-rw-r--r--spec/ruby/library/yaml/tagurize_spec.rb11
-rw-r--r--spec/ruby/library/yaml/to_yaml_spec.rb45
-rw-r--r--spec/ruby/library/yaml/transfer_spec.rb2
-rw-r--r--spec/ruby/library/yaml/try_implicit_spec.rb2
-rw-r--r--spec/ruby/library/yaml/unsafe_load_spec.rb9
-rw-r--r--spec/ruby/library/zlib/adler32_spec.rb6
-rw-r--r--spec/ruby/library/zlib/crc32_spec.rb8
-rw-r--r--spec/ruby/library/zlib/crc_table_spec.rb145
-rw-r--r--spec/ruby/library/zlib/deflate/append_spec.rb1
-rw-r--r--spec/ruby/library/zlib/deflate/deflate_spec.rb13
-rw-r--r--spec/ruby/library/zlib/deflate/flush_spec.rb1
-rw-r--r--spec/ruby/library/zlib/deflate/new_spec.rb1
-rw-r--r--spec/ruby/library/zlib/deflate/params_spec.rb4
-rw-r--r--spec/ruby/library/zlib/deflate/set_dictionary_spec.rb3
-rw-r--r--spec/ruby/library/zlib/deflate_spec.rb8
-rw-r--r--spec/ruby/library/zlib/gunzip_spec.rb14
-rw-r--r--spec/ruby/library/zlib/gzip_spec.rb15
-rw-r--r--spec/ruby/library/zlib/gzipfile/close_spec.rb11
-rw-r--r--spec/ruby/library/zlib/gzipfile/closed_spec.rb7
-rw-r--r--spec/ruby/library/zlib/gzipfile/comment_spec.rb6
-rw-r--r--spec/ruby/library/zlib/gzipfile/crc_spec.rb1
-rw-r--r--spec/ruby/library/zlib/gzipfile/finish_spec.rb1
-rw-r--r--spec/ruby/library/zlib/gzipfile/level_spec.rb1
-rw-r--r--spec/ruby/library/zlib/gzipfile/mtime_spec.rb1
-rw-r--r--spec/ruby/library/zlib/gzipfile/orig_name_spec.rb6
-rw-r--r--spec/ruby/library/zlib/gzipfile/os_code_spec.rb1
-rw-r--r--spec/ruby/library/zlib/gzipfile/sync_spec.rb1
-rw-r--r--spec/ruby/library/zlib/gzipfile/to_io_spec.rb1
-rw-r--r--spec/ruby/library/zlib/gzipfile/wrap_spec.rb1
-rw-r--r--spec/ruby/library/zlib/gzipreader/each_byte_spec.rb4
-rw-r--r--spec/ruby/library/zlib/gzipreader/each_char_spec.rb51
-rw-r--r--spec/ruby/library/zlib/gzipreader/each_line_spec.rb10
-rw-r--r--spec/ruby/library/zlib/gzipreader/each_spec.rb50
-rw-r--r--spec/ruby/library/zlib/gzipreader/eof_spec.rb35
-rw-r--r--spec/ruby/library/zlib/gzipreader/getc_spec.rb8
-rw-r--r--spec/ruby/library/zlib/gzipreader/gets_spec.rb6
-rw-r--r--spec/ruby/library/zlib/gzipreader/lineno_spec.rb1
-rw-r--r--spec/ruby/library/zlib/gzipreader/mtime_spec.rb11
-rw-r--r--spec/ruby/library/zlib/gzipreader/new_spec.rb1
-rw-r--r--spec/ruby/library/zlib/gzipreader/open_spec.rb1
-rw-r--r--spec/ruby/library/zlib/gzipreader/pos_spec.rb7
-rw-r--r--spec/ruby/library/zlib/gzipreader/read_spec.rb18
-rw-r--r--spec/ruby/library/zlib/gzipreader/readchar_spec.rb1
-rw-r--r--spec/ruby/library/zlib/gzipreader/readline_spec.rb1
-rw-r--r--spec/ruby/library/zlib/gzipreader/readlines_spec.rb1
-rw-r--r--spec/ruby/library/zlib/gzipreader/readpartial_spec.rb4
-rw-r--r--spec/ruby/library/zlib/gzipreader/rewind_spec.rb5
-rw-r--r--spec/ruby/library/zlib/gzipreader/shared/each.rb51
-rw-r--r--spec/ruby/library/zlib/gzipreader/tell_spec.rb10
-rw-r--r--spec/ruby/library/zlib/gzipreader/ungetbyte_spec.rb16
-rw-r--r--spec/ruby/library/zlib/gzipreader/ungetc_spec.rb48
-rw-r--r--spec/ruby/library/zlib/gzipreader/unused_spec.rb1
-rw-r--r--spec/ruby/library/zlib/gzipwriter/append_spec.rb6
-rw-r--r--spec/ruby/library/zlib/gzipwriter/comment_spec.rb1
-rw-r--r--spec/ruby/library/zlib/gzipwriter/flush_spec.rb1
-rw-r--r--spec/ruby/library/zlib/gzipwriter/mtime_spec.rb5
-rw-r--r--spec/ruby/library/zlib/gzipwriter/new_spec.rb1
-rw-r--r--spec/ruby/library/zlib/gzipwriter/open_spec.rb1
-rw-r--r--spec/ruby/library/zlib/gzipwriter/orig_name_spec.rb1
-rw-r--r--spec/ruby/library/zlib/gzipwriter/pos_spec.rb1
-rw-r--r--spec/ruby/library/zlib/gzipwriter/print_spec.rb1
-rw-r--r--spec/ruby/library/zlib/gzipwriter/printf_spec.rb1
-rw-r--r--spec/ruby/library/zlib/gzipwriter/putc_spec.rb1
-rw-r--r--spec/ruby/library/zlib/gzipwriter/puts_spec.rb1
-rw-r--r--spec/ruby/library/zlib/gzipwriter/tell_spec.rb1
-rw-r--r--spec/ruby/library/zlib/gzipwriter/write_spec.rb4
-rw-r--r--spec/ruby/library/zlib/inflate/append_spec.rb4
-rw-r--r--spec/ruby/library/zlib/inflate/finish_spec.rb3
-rw-r--r--spec/ruby/library/zlib/inflate/inflate_spec.rb21
-rw-r--r--spec/ruby/library/zlib/inflate/new_spec.rb1
-rw-r--r--spec/ruby/library/zlib/inflate/set_dictionary_spec.rb5
-rw-r--r--spec/ruby/library/zlib/inflate/sync_point_spec.rb1
-rw-r--r--spec/ruby/library/zlib/inflate/sync_spec.rb1
-rw-r--r--spec/ruby/library/zlib/inflate_spec.rb8
-rw-r--r--spec/ruby/library/zlib/zlib_version_spec.rb9
-rw-r--r--spec/ruby/library/zlib/zstream/adler_spec.rb2
-rw-r--r--spec/ruby/library/zlib/zstream/avail_in_spec.rb2
-rw-r--r--spec/ruby/library/zlib/zstream/avail_out_spec.rb2
-rw-r--r--spec/ruby/library/zlib/zstream/close_spec.rb1
-rw-r--r--spec/ruby/library/zlib/zstream/closed_spec.rb1
-rw-r--r--spec/ruby/library/zlib/zstream/data_type_spec.rb2
-rw-r--r--spec/ruby/library/zlib/zstream/end_spec.rb1
-rw-r--r--spec/ruby/library/zlib/zstream/ended_spec.rb1
-rw-r--r--spec/ruby/library/zlib/zstream/finish_spec.rb1
-rw-r--r--spec/ruby/library/zlib/zstream/finished_spec.rb1
-rw-r--r--spec/ruby/library/zlib/zstream/flush_next_in_spec.rb1
-rw-r--r--spec/ruby/library/zlib/zstream/flush_next_out_spec.rb6
-rw-r--r--spec/ruby/library/zlib/zstream/reset_spec.rb1
-rw-r--r--spec/ruby/library/zlib/zstream/stream_end_spec.rb1
-rw-r--r--spec/ruby/library/zlib/zstream/total_in_spec.rb1
-rw-r--r--spec/ruby/library/zlib/zstream/total_out_spec.rb1
-rw-r--r--spec/ruby/optional/capi/README9
-rw-r--r--spec/ruby/optional/capi/array_spec.rb124
-rw-r--r--spec/ruby/optional/capi/basic_object_spec.rb24
-rw-r--r--spec/ruby/optional/capi/bignum_spec.rb60
-rw-r--r--spec/ruby/optional/capi/binding_spec.rb16
-rw-r--r--spec/ruby/optional/capi/boolean_spec.rb2
-rw-r--r--spec/ruby/optional/capi/class_spec.rb270
-rw-r--r--spec/ruby/optional/capi/complex_spec.rb2
-rw-r--r--spec/ruby/optional/capi/constants_spec.rb109
-rw-r--r--spec/ruby/optional/capi/data_spec.rb77
-rw-r--r--spec/ruby/optional/capi/debug_spec.rb74
-rw-r--r--spec/ruby/optional/capi/digest_spec.rb103
-rw-r--r--spec/ruby/optional/capi/encoding_spec.rb478
-rw-r--r--spec/ruby/optional/capi/enumerator_spec.rb29
-rw-r--r--spec/ruby/optional/capi/exception_spec.rb155
-rw-r--r--spec/ruby/optional/capi/ext/array_spec.c247
-rw-r--r--spec/ruby/optional/capi/ext/basic_object_spec.c19
-rw-r--r--spec/ruby/optional/capi/ext/bignum_spec.c59
-rw-r--r--spec/ruby/optional/capi/ext/binding_spec.c19
-rw-r--r--spec/ruby/optional/capi/ext/boolean_spec.c5
-rw-r--r--spec/ruby/optional/capi/ext/class_id_under_autoload_spec.c8
-rw-r--r--spec/ruby/optional/capi/ext/class_spec.c163
-rw-r--r--spec/ruby/optional/capi/ext/class_under_autoload_spec.c8
-rw-r--r--spec/ruby/optional/capi/ext/complex_spec.c33
-rw-r--r--spec/ruby/optional/capi/ext/constants_spec.c690
-rw-r--r--spec/ruby/optional/capi/ext/data_spec.c30
-rw-r--r--spec/ruby/optional/capi/ext/debug_spec.c93
-rw-r--r--spec/ruby/optional/capi/ext/digest_spec.c168
-rw-r--r--spec/ruby/optional/capi/ext/encoding_spec.c362
-rw-r--r--spec/ruby/optional/capi/ext/enumerator_spec.c19
-rw-r--r--spec/ruby/optional/capi/ext/exception_spec.c68
-rw-r--r--spec/ruby/optional/capi/ext/fiber_spec.c64
-rw-r--r--spec/ruby/optional/capi/ext/file_spec.c15
-rw-r--r--spec/ruby/optional/capi/ext/finalizer_spec.c25
-rw-r--r--spec/ruby/optional/capi/ext/fixnum_spec.c28
-rw-r--r--spec/ruby/optional/capi/ext/float_spec.c27
-rw-r--r--spec/ruby/optional/capi/ext/gc_spec.c160
-rw-r--r--spec/ruby/optional/capi/ext/globals_spec.c130
-rw-r--r--spec/ruby/optional/capi/ext/hash_spec.c126
-rw-r--r--spec/ruby/optional/capi/ext/integer_spec.c20
-rw-r--r--spec/ruby/optional/capi/ext/io_spec.c319
-rw-r--r--spec/ruby/optional/capi/ext/kernel_spec.c333
-rw-r--r--spec/ruby/optional/capi/ext/language_spec.c42
-rw-r--r--spec/ruby/optional/capi/ext/marshal_spec.c14
-rw-r--r--spec/ruby/optional/capi/ext/module_spec.c148
-rw-r--r--spec/ruby/optional/capi/ext/module_under_autoload_spec.c8
-rw-r--r--spec/ruby/optional/capi/ext/mutex_spec.c61
-rw-r--r--spec/ruby/optional/capi/ext/numeric_spec.c154
-rw-r--r--spec/ruby/optional/capi/ext/object_spec.c389
-rw-r--r--spec/ruby/optional/capi/ext/proc_spec.c100
-rw-r--r--spec/ruby/optional/capi/ext/range_spec.c68
-rw-r--r--spec/ruby/optional/capi/ext/rational_spec.c43
-rw-r--r--spec/ruby/optional/capi/ext/rbasic_spec.c104
-rw-r--r--spec/ruby/optional/capi/ext/regexp_spec.c58
-rw-r--r--spec/ruby/optional/capi/ext/rubyspec.h614
-rw-r--r--spec/ruby/optional/capi/ext/set_spec.c65
-rw-r--r--spec/ruby/optional/capi/ext/st_spec.c12
-rw-r--r--spec/ruby/optional/capi/ext/string_spec.c659
-rw-r--r--spec/ruby/optional/capi/ext/struct_spec.c90
-rw-r--r--spec/ruby/optional/capi/ext/symbol_spec.c76
-rw-r--r--spec/ruby/optional/capi/ext/thread_spec.c113
-rw-r--r--spec/ruby/optional/capi/ext/time_spec.c48
-rw-r--r--spec/ruby/optional/capi/ext/tracepoint_spec.c49
-rw-r--r--spec/ruby/optional/capi/ext/typed_data_spec.c109
-rw-r--r--spec/ruby/optional/capi/ext/util_spec.c92
-rw-r--r--spec/ruby/optional/capi/fiber_spec.rb86
-rw-r--r--spec/ruby/optional/capi/file_spec.rb12
-rw-r--r--spec/ruby/optional/capi/finalizer_spec.rb40
-rw-r--r--spec/ruby/optional/capi/fixnum_spec.rb113
-rw-r--r--spec/ruby/optional/capi/fixtures/class.rb24
-rw-r--r--spec/ruby/optional/capi/fixtures/kernel.rb19
-rw-r--r--spec/ruby/optional/capi/fixtures/module.rb4
-rw-r--r--spec/ruby/optional/capi/fixtures/object.rb29
-rw-r--r--spec/ruby/optional/capi/fixtures/read.txt1
-rw-r--r--spec/ruby/optional/capi/float_spec.rb19
-rw-r--r--spec/ruby/optional/capi/gc_spec.rb124
-rw-r--r--spec/ruby/optional/capi/globals_spec.rb116
-rw-r--r--spec/ruby/optional/capi/hash_spec.rb136
-rw-r--r--spec/ruby/optional/capi/integer_spec.rb36
-rw-r--r--spec/ruby/optional/capi/io_spec.rb530
-rw-r--r--spec/ruby/optional/capi/kernel_spec.rb661
-rw-r--r--spec/ruby/optional/capi/language_spec.rb37
-rw-r--r--spec/ruby/optional/capi/marshal_spec.rb2
-rw-r--r--spec/ruby/optional/capi/module_spec.rb146
-rw-r--r--spec/ruby/optional/capi/mutex_spec.rb56
-rw-r--r--spec/ruby/optional/capi/numeric_spec.rb355
-rw-r--r--spec/ruby/optional/capi/object_spec.rb495
-rw-r--r--spec/ruby/optional/capi/proc_spec.rb136
-rw-r--r--spec/ruby/optional/capi/rake_helper.rb1
-rw-r--r--spec/ruby/optional/capi/range_spec.rb160
-rw-r--r--spec/ruby/optional/capi/rational_spec.rb2
-rw-r--r--spec/ruby/optional/capi/rbasic_spec.rb48
-rw-r--r--spec/ruby/optional/capi/regexp_spec.rb61
-rw-r--r--spec/ruby/optional/capi/set_spec.rb96
-rw-r--r--spec/ruby/optional/capi/shared/rbasic.rb27
-rw-r--r--spec/ruby/optional/capi/spec_helper.rb134
-rw-r--r--spec/ruby/optional/capi/st_spec.rb2
-rw-r--r--spec/ruby/optional/capi/string_spec.rb1016
-rw-r--r--spec/ruby/optional/capi/struct_spec.rb151
-rw-r--r--spec/ruby/optional/capi/symbol_spec.rb49
-rw-r--r--spec/ruby/optional/capi/thread_spec.rb104
-rw-r--r--spec/ruby/optional/capi/time_spec.rb223
-rw-r--r--spec/ruby/optional/capi/tracepoint_spec.rb56
-rw-r--r--spec/ruby/optional/capi/typed_data_spec.rb60
-rw-r--r--spec/ruby/optional/capi/util_spec.rb163
-rw-r--r--spec/ruby/optional/thread_safety/fixtures/classes.rb39
-rw-r--r--spec/ruby/optional/thread_safety/hash_spec.rb210
-rw-r--r--spec/ruby/security/cve_2010_1330_spec.rb19
-rw-r--r--spec/ruby/security/cve_2011_4815_spec.rb14
-rw-r--r--spec/ruby/security/cve_2013_4164_spec.rb6
-rw-r--r--spec/ruby/security/cve_2014_8080_spec.rb32
-rw-r--r--spec/ruby/security/cve_2018_16396_spec.rb7
-rw-r--r--spec/ruby/security/cve_2018_6914_spec.rb55
-rw-r--r--spec/ruby/security/cve_2018_8778_spec.rb10
-rw-r--r--spec/ruby/security/cve_2018_8779_spec.rb30
-rw-r--r--spec/ruby/security/cve_2018_8780_spec.rb43
-rw-r--r--spec/ruby/security/cve_2019_8321_spec.rb20
-rw-r--r--spec/ruby/security/cve_2019_8322_spec.rb24
-rw-r--r--spec/ruby/security/cve_2019_8323_spec.rb46
-rw-r--r--spec/ruby/security/cve_2019_8325_spec.rb46
-rw-r--r--spec/ruby/security/cve_2020_10663_spec.rb49
-rw-r--r--spec/ruby/security/cve_2024_49761_spec.rb7
-rw-r--r--spec/ruby/shared/basicobject/method_missing.rb36
-rw-r--r--spec/ruby/shared/basicobject/send.rb28
-rw-r--r--spec/ruby/shared/complex/Complex.rb133
-rw-r--r--spec/ruby/shared/complex/abs.rb12
-rw-r--r--spec/ruby/shared/complex/abs2.rb12
-rw-r--r--spec/ruby/shared/complex/arg.rb9
-rw-r--r--spec/ruby/shared/complex/coerce.rb70
-rw-r--r--spec/ruby/shared/complex/conjugate.rb8
-rw-r--r--spec/ruby/shared/complex/constants.rb7
-rw-r--r--spec/ruby/shared/complex/denominator.rb13
-rw-r--r--spec/ruby/shared/complex/divide.rb84
-rw-r--r--spec/ruby/shared/complex/equal_value.rb93
-rw-r--r--spec/ruby/shared/complex/exponent.rb61
-rw-r--r--spec/ruby/shared/complex/float/arg.rb38
-rw-r--r--spec/ruby/shared/complex/hash.rb16
-rw-r--r--spec/ruby/shared/complex/image.rb10
-rw-r--r--spec/ruby/shared/complex/inspect.rb14
-rw-r--r--spec/ruby/shared/complex/minus.rb45
-rw-r--r--spec/ruby/shared/complex/multiply.rb49
-rw-r--r--spec/ruby/shared/complex/numerator.rb19
-rw-r--r--spec/ruby/shared/complex/numeric/arg.rb38
-rw-r--r--spec/ruby/shared/complex/numeric/conj.rb20
-rw-r--r--spec/ruby/shared/complex/numeric/imag.rb26
-rw-r--r--spec/ruby/shared/complex/numeric/polar.rb50
-rw-r--r--spec/ruby/shared/complex/numeric/real.rb30
-rw-r--r--spec/ruby/shared/complex/plus.rb45
-rw-r--r--spec/ruby/shared/complex/polar.rb22
-rw-r--r--spec/ruby/shared/complex/real.rb8
-rw-r--r--spec/ruby/shared/complex/rect.rb96
-rw-r--r--spec/ruby/shared/complex/to_s.rb44
-rw-r--r--spec/ruby/shared/enumerable/minmax.rb24
-rw-r--r--spec/ruby/shared/enumerator/each.rb89
-rw-r--r--spec/ruby/shared/enumerator/enum_cons.rb12
-rw-r--r--spec/ruby/shared/enumerator/enum_for.rb50
-rw-r--r--spec/ruby/shared/enumerator/new.rb42
-rw-r--r--spec/ruby/shared/enumerator/next.rb28
-rw-r--r--spec/ruby/shared/enumerator/rewind.rb39
-rw-r--r--spec/ruby/shared/enumerator/with_index.rb32
-rw-r--r--spec/ruby/shared/enumerator/with_object.rb42
-rw-r--r--spec/ruby/shared/fiber/resume.rb82
-rw-r--r--spec/ruby/shared/file/directory.rb18
-rw-r--r--spec/ruby/shared/file/executable.rb45
-rw-r--r--spec/ruby/shared/file/executable_real.rb43
-rw-r--r--spec/ruby/shared/file/exist.rb11
-rw-r--r--spec/ruby/shared/file/file.rb8
-rw-r--r--spec/ruby/shared/file/grpowned.rb9
-rw-r--r--spec/ruby/shared/file/identical.rb24
-rw-r--r--spec/ruby/shared/file/readable.rb21
-rw-r--r--spec/ruby/shared/file/readable_real.rb16
-rw-r--r--spec/ruby/shared/file/size.rb4
-rw-r--r--spec/ruby/shared/file/socket.rb32
-rw-r--r--spec/ruby/shared/file/sticky.rb2
-rw-r--r--spec/ruby/shared/file/world_readable.rb22
-rw-r--r--spec/ruby/shared/file/world_writable.rb22
-rw-r--r--spec/ruby/shared/file/writable.rb22
-rw-r--r--spec/ruby/shared/file/writable_real.rb24
-rw-r--r--spec/ruby/shared/file/zero.rb22
-rw-r--r--spec/ruby/shared/hash/key_error.rb23
-rw-r--r--spec/ruby/shared/io/putc.rb12
-rw-r--r--spec/ruby/shared/kernel/at_exit.rb73
-rw-r--r--spec/ruby/shared/kernel/complex.rb133
-rw-r--r--spec/ruby/shared/kernel/equal.rb4
-rw-r--r--spec/ruby/shared/kernel/fixtures/END.rb3
-rw-r--r--spec/ruby/shared/kernel/fixtures/at_exit.rb3
-rw-r--r--spec/ruby/shared/kernel/object_id.rb30
-rw-r--r--spec/ruby/shared/kernel/raise.rb389
-rw-r--r--spec/ruby/shared/math/atanh.rb44
-rw-r--r--spec/ruby/shared/process/abort.rb12
-rw-r--r--spec/ruby/shared/process/exit.rb58
-rw-r--r--spec/ruby/shared/process/fork.rb47
-rw-r--r--spec/ruby/shared/queue/clear.rb12
-rw-r--r--spec/ruby/shared/queue/close.rb14
-rw-r--r--spec/ruby/shared/queue/closed.rb12
-rw-r--r--spec/ruby/shared/queue/deque.rb164
-rw-r--r--spec/ruby/shared/queue/empty.rb12
-rw-r--r--spec/ruby/shared/queue/enque.rb18
-rw-r--r--spec/ruby/shared/queue/freeze.rb8
-rw-r--r--spec/ruby/shared/queue/length.rb (renamed from spec/ruby/library/thread/shared/queue/length.rb)0
-rw-r--r--spec/ruby/shared/queue/num_waiting.rb (renamed from spec/ruby/library/thread/shared/queue/num_waiting.rb)0
-rw-r--r--spec/ruby/shared/rational/Rational.rb103
-rw-r--r--spec/ruby/shared/rational/abs.rb11
-rw-r--r--spec/ruby/shared/rational/ceil.rb45
-rw-r--r--spec/ruby/shared/rational/coerce.rb21
-rw-r--r--spec/ruby/shared/rational/comparison.rb85
-rw-r--r--spec/ruby/shared/rational/denominator.rb14
-rw-r--r--spec/ruby/shared/rational/div.rb54
-rw-r--r--spec/ruby/shared/rational/divide.rb71
-rw-r--r--spec/ruby/shared/rational/divmod.rb42
-rw-r--r--spec/ruby/shared/rational/equal_value.rb39
-rw-r--r--spec/ruby/shared/rational/exponent.rb176
-rw-r--r--spec/ruby/shared/rational/fdiv.rb5
-rw-r--r--spec/ruby/shared/rational/floor.rb45
-rw-r--r--spec/ruby/shared/rational/hash.rb9
-rw-r--r--spec/ruby/shared/rational/inspect.rb12
-rw-r--r--spec/ruby/shared/rational/marshal_dump.rb5
-rw-r--r--spec/ruby/shared/rational/marshal_load.rb5
-rw-r--r--spec/ruby/shared/rational/minus.rb48
-rw-r--r--spec/ruby/shared/rational/modulo.rb43
-rw-r--r--spec/ruby/shared/rational/multiply.rb62
-rw-r--r--spec/ruby/shared/rational/numerator.rb10
-rw-r--r--spec/ruby/shared/rational/plus.rb48
-rw-r--r--spec/ruby/shared/rational/quo.rb5
-rw-r--r--spec/ruby/shared/rational/remainder.rb5
-rw-r--r--spec/ruby/shared/rational/round.rb96
-rw-r--r--spec/ruby/shared/rational/to_f.rb10
-rw-r--r--spec/ruby/shared/rational/to_i.rb12
-rw-r--r--spec/ruby/shared/rational/to_r.rb13
-rw-r--r--spec/ruby/shared/rational/to_s.rb11
-rw-r--r--spec/ruby/shared/rational/truncate.rb45
-rw-r--r--spec/ruby/shared/sizedqueue/enque.rb129
-rw-r--r--spec/ruby/shared/sizedqueue/max.rb47
-rw-r--r--spec/ruby/shared/sizedqueue/new.rb23
-rw-r--r--spec/ruby/shared/sizedqueue/num_waiting.rb12
-rw-r--r--spec/ruby/shared/string/end_with.rb61
-rw-r--r--spec/ruby/shared/string/start_with.rb76
-rw-r--r--spec/ruby/shared/string/times.rb44
-rw-r--r--spec/ruby/shared/time/strftime_for_date.rb10
-rw-r--r--spec/ruby/shared/time/strftime_for_time.rb8
-rw-r--r--spec/ruby/shared/time/yday.rb18
-rw-r--r--spec/ruby/shared/types/rb_num2dbl_fails.rb17
-rw-r--r--spec/ruby/spec_helper.rb17
5322 files changed, 135386 insertions, 87618 deletions
diff --git a/spec/ruby/.mspec.constants b/spec/ruby/.mspec.constants
new file mode 100644
index 0000000000..4da3633715
--- /dev/null
+++ b/spec/ruby/.mspec.constants
@@ -0,0 +1,236 @@
+Abbrev
+Addrinfo
+AliasObject
+AliasObject2
+AnonWithConstant
+ArbitraryException
+ArraySub
+ArraySubPush
+AryChild
+Base64
+BaseClass
+BasicSocket
+BeCloseToMatrixMatcher
+BigDecimal
+BigMath
+BitwiseAndTest
+BreakTest
+BreakTest2
+CAPI_SIZEOF_LONG
+CApiModuleSpecsAutoload
+CApiModuleSpecsModuleA
+CGI
+CMath
+CODE_LOADING_DIR
+CSAutoloadA
+CSAutoloadB
+CSAutoloadC
+CSAutoloadD
+CSV
+ChainedNextTest
+ChildClass
+ClassIdUnderAutoload
+ClassSpecDefineClass
+ClassSpecsKeywordWithSemicolon
+ClassSpecsKeywordWithoutSemicolon
+ClassSpecsNumber
+ClassUnderAutoload
+CodingUS_ASCII
+CodingUTF_8
+ComparisonTest
+ConstantSpecsIncludedModule
+ConstantSpecsTwo
+ConstantSpecsThree
+ConstantVisibility
+Coverage
+CoverageSpecs
+CustomArgumentError
+DRb
+DRbIdConv
+DRbObject
+DRbUndumped
+Date
+DateTime
+DefSpecNested
+DefSpecNestedB
+DefSpecSingleton
+DefSpecsLambdaVisibility
+DefineMethodByProcClass
+DefineMethodSpecClass
+DefineSingletonMethodSpecClass
+Delegator
+DescArray
+DescObjectTest
+Digest
+DumpableDir
+ERB
+EnsureInClassExample
+EnumerableSpecGrep
+EnumerableSpecGrep2
+EnumerableSpecIncludeP
+EnumerableSpecIncludeP11
+Etc
+EvalBindingA
+EvalBindingProcA
+Exception2MessageMapper
+ExceptionForMatrix
+Fcntl
+Fiddle
+FileStat
+FileUtils
+Find
+Forwardable
+GetoptLong
+HMACConstants
+HashStringsBinary
+HashStringsUSASCII
+HashStringsUTF8
+IPAddr
+IPSocket
+Importer
+IncludeSpecsClass
+IncludeSpecsMiddle
+IncludeSpecsTop
+IncludesMath
+JSON
+KSAutoloadA
+KSAutoloadB
+KSAutoloadBB
+KSAutoloadCallsRequire
+KSAutoloadD
+Logger
+MD5Constants
+MY_INPUT4_FOR_ERB
+Matrix
+MatrixSub
+MethodArity
+Meths
+MethsMore
+Mixin
+ModuleSpecsKeywordWithoutSemicolon
+ModuleSpecsToplevel
+ModuleSpecs_CS1
+ModuleSpecs_CS2
+ModuleSpecs_CS3
+MyClass
+MyClass0ForErb
+MyClass1ForErb
+MyClass1ForErb_
+MyClass2ForErb
+MyClass4ForErb
+MyFiber
+MyModule2ForErb
+MyString
+NamespaceTest
+Net
+OBJDIR
+OBJECT_SPACE_TOP_LEVEL_CONSTANT
+OFor
+ObjectSpaceFixtures
+ObjectSpecDup
+ObjectSpecDupInitCopy
+ObjectTest
+Observable
+Open3
+OpenSSL
+OpenStruct
+OperatorImplementor
+OptParse
+OptionParser
+OrAndXorTest
+OtherCustomException
+ParentClass
+Pathname
+Person
+Prime
+Private
+ProcFromMethod
+Psych
+RactorLocalSingleton
+REXML
+RUBY_SIGNALS
+RbReadline
+Readline
+ReceiverClass
+RegexpSpecsSubclass
+RegexpSpecsSubclassTwo
+Reline
+RescueInClassExample
+Resolv
+Ripper
+SHA1Constants
+SHA256Constants
+SHA384Constants
+SHA512Constants
+SameName
+ScanError
+Scanf
+SecondClass
+SecureRandom
+Set
+Shellwords
+SimpleDelegator
+SingleForwardable
+Singleton
+Socket
+SocketError
+SomeClass
+SortedSet
+SpecificExampleException
+Specs
+StrChild
+StrangeEach
+StringIO
+StringRefinement
+StringScanner
+StringSubclass
+StructClasses
+Syck
+Syslog
+TCPServer
+TCPSocket
+TSort
+Tempfile
+TestServer
+Timeout
+TimeoutError
+UDPSocket
+UNIXServer
+UNIXSocket
+URI
+UnaryMinusTest
+UnicodeNormalize
+UnloadableDumpableDir
+UserArray
+UserCustomConstructorString
+UserDefined
+UserDefinedImmediate
+UserDefinedString
+UserDefinedWithIvar
+UserHash
+UserHashInitParams
+UserMarshal
+UserMarshalWithClassName
+UserMarshalWithIvar
+UserObject
+UserPreviouslyDefinedWithInitializedIvar
+UserRegexp
+UserString
+Vector
+WEBrick
+WIN32OLE
+WIN32OLEQueryInterfaceError
+WIN32OLERuntimeError
+WIN32OLE_EVENT
+WIN32OLE_METHOD
+WIN32OLE_PARAM
+WIN32OLE_RECORD
+WIN32OLE_RUBYSPEC
+WIN32OLE_TYPE
+WIN32OLE_TYPELIB
+WIN32OLE_VARIABLE
+WIN32OLE_VARIANT
+WeakRef
+Win32
+YAML
+Zlib
diff --git a/spec/ruby/.rubocop.yml b/spec/ruby/.rubocop.yml
index d8b9aa7f8a..0b5dcb80a2 100644
--- a/spec/ruby/.rubocop.yml
+++ b/spec/ruby/.rubocop.yml
@@ -1,34 +1,63 @@
inherit_from: .rubocop_todo.yml
AllCops:
- TargetRubyVersion: 2.4
+ TargetRubyVersion: 3.2
DisplayCopNames: true
Exclude:
- command_line/fixtures/bad_syntax.rb
+ - core/exception/fixtures/syntax_error.rb
DisabledByDefault: true
+ NewCops: disable
+
+Layout/IndentationConsistency:
+ Enabled: true
Layout/TrailingWhitespace:
Enabled: true
+Layout/TrailingEmptyLines:
+ Enabled: true
+ Exclude:
+ - library/coverage/fixtures/some_class.rb
+
+Layout/SpaceInLambdaLiteral:
+ Enabled: true
+ EnforcedStyle: require_space
+
Lint:
Enabled: true
+# {...} has higher precedence than do ... end, on purpose
+Lint/AmbiguousBlockAssociation:
+ Enabled: false
+
Lint/AssignmentInCondition:
Enabled: false
Lint/BooleanSymbol:
Enabled: false
+Lint/DeprecatedOpenSSLConstant:
+ Exclude:
+ - library/openssl/digest/**/*.rb
+
Lint/InterpolationCheck:
Enabled: false
Lint/LiteralAsCondition:
Enabled: false
-Lint/UnneededRequireStatement:
+# Required to support Ruby 3.0
+Lint/RedundantRequireStatement:
+ Exclude:
+ - core/fiber/**/*.rb
+ - library/fiber/**/*.rb
+ - optional/capi/fiber_spec.rb
+
+Lint/RedundantSplatExpansion:
Enabled: false
-Lint/RescueWithoutErrorClass:
+Lint/RescueException:
Enabled: false
Lint/UnifiedInteger:
@@ -43,17 +72,133 @@ Lint/UnusedMethodArgument:
Lint/UselessAssignment:
Enabled: false
-Lint/UselessComparison:
+Lint/BinaryOperatorWithIdenticalOperands:
Enabled: false
-# The cop registers too many false positives to `.should == something`
+Lint/EmptyConditionalBody:
+ Enabled: false # buggy
+
Lint/Void:
Enabled: false
+Lint/ConstantDefinitionInBlock:
+ Enabled: false
+
+Lint/RaiseException:
+ Enabled: false
+
+Lint/FloatComparison:
+ Enabled: false
+
+Lint/DeprecatedClassMethods:
+ Enabled: false
+
+Lint/UnreachableLoop:
+ Enabled: false
+
+Lint/MissingSuper:
+ Enabled: false
+
+Lint/UselessMethodDefinition:
+ Enabled: false
+
+Lint/UselessTimes:
+ Enabled: false
+
+Lint/MixedRegexpCaptureTypes:
+ Enabled: false
+
+Lint/DuplicateElsifCondition:
+ Enabled: false
+
+Lint/OutOfRangeRegexpRef:
+ Enabled: false
+
+Lint/InheritException:
+ Enabled: false
+
+Lint/SafeNavigationChain:
+ Enabled: false
+
+Lint/ElseLayout:
+ Exclude:
+ - 'language/if_spec.rb'
+
Lint/EmptyExpression:
Exclude:
- 'language/**/*.rb'
+Lint/EmptyWhen:
+ Exclude:
+ - language/case_spec.rb
+ - optional/capi/spec_helper.rb
+
+Lint/ErbNewArguments:
+ Exclude:
+ - 'library/erb/new_spec.rb'
+
+Lint/FormatParameterMismatch:
+ Exclude:
+ - 'core/kernel/shared/sprintf.rb'
+ - 'core/string/modulo_spec.rb'
+
+Lint/NestedMethodDefinition:
+ Exclude:
+ - language/def_spec.rb
+ - language/fixtures/def.rb
+
+Lint/ShadowingOuterLocalVariable:
+ Exclude:
+ - 'core/binding/local_variables_spec.rb'
+ - 'core/kernel/local_variables_spec.rb'
+ - 'language/block_spec.rb'
+ - 'language/proc_spec.rb'
+
+Lint/UnreachableCode:
+ Exclude:
+ - 'core/enumerator/lazy/fixtures/classes.rb'
+ - 'core/kernel/catch_spec.rb'
+ - 'core/kernel/raise_spec.rb'
+ - 'core/kernel/throw_spec.rb'
+ - 'language/break_spec.rb'
+ - 'language/optional_assignments_spec.rb'
+ - 'language/fixtures/break.rb'
+ - 'language/fixtures/break_lambda_toplevel.rb'
+ - 'language/fixtures/break_lambda_toplevel_block.rb'
+ - 'language/fixtures/break_lambda_toplevel_method.rb'
+ - 'language/fixtures/return.rb'
+ - 'language/next_spec.rb'
+ - 'language/return_spec.rb'
+ - 'optional/capi/kernel_spec.rb'
+ - 'shared/kernel/raise.rb'
+
Lint/UriRegexp:
Exclude:
- 'library/uri/regexp_spec.rb'
+
+Lint/Debugger:
+ Exclude:
+ - 'core/binding/fixtures/irb.rb'
+
+Lint/Loop:
+ Enabled: false
+
+Style/BlockComments:
+ Enabled: true
+
+Style/Lambda:
+ Enabled: true
+ EnforcedStyle: literal
+ Exclude:
+ - 'language/lambda_spec.rb'
+ - 'language/proc_spec.rb'
+ - 'language/numbered_parameters_spec.rb'
+ - 'language/it_parameter_spec.rb'
+ - 'core/kernel/lambda_spec.rb'
+
+Style/EmptyLambdaParameter:
+ Enabled: true
+
+Style/StabbyLambdaParentheses:
+ Enabled: true
+ EnforcedStyle: require_no_parentheses
diff --git a/spec/ruby/.rubocop_todo.yml b/spec/ruby/.rubocop_todo.yml
index 1d68068121..f998002c6d 100644
--- a/spec/ruby/.rubocop_todo.yml
+++ b/spec/ruby/.rubocop_todo.yml
@@ -1,46 +1,32 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
-# on 2017-10-09 20:22:01 +0200 using RuboCop version 0.50.0.
+# on 2026-05-29 08:10:07 UTC using RuboCop version 1.86.2.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.
-# Offense count: 6
-Lint/AmbiguousBlockAssociation:
- Exclude:
- - 'core/kernel/trace_var_spec.rb'
- - 'language/fixtures/argv_encoding.rb'
- - 'language/fixtures/break.rb'
- - 'shared/process/abort.rb'
-
-# Offense count: 3
-Lint/CircularArgumentReference:
- Exclude:
- - 'language/block_spec.rb'
- - 'language/def_spec.rb'
- - 'language/lambda_spec.rb'
-
# Offense count: 2
Lint/DuplicateCaseCondition:
Exclude:
- 'language/case_spec.rb'
-# Offense count: 6
+# Offense count: 20
Lint/DuplicateMethods:
Exclude:
- 'core/array/fixtures/encoded_strings.rb'
- 'core/method/fixtures/classes.rb'
+ - 'core/module/const_added_spec.rb'
+ - 'core/module/define_method_spec.rb'
- 'core/module/fixtures/classes.rb'
+ - 'core/module/method_added_spec.rb'
+ - 'core/module/name_spec.rb'
+ - 'core/proc/new_spec.rb'
- 'core/unboundmethod/fixtures/classes.rb'
- 'fixtures/class.rb'
+ - 'language/assignments_spec.rb'
-# Offense count: 4
-Lint/EmptyWhen:
- Exclude:
- - 'language/case_spec.rb'
-
-# Offense count: 5
+# Offense count: 8
Lint/EnsureReturn:
Exclude:
- 'language/fixtures/ensure.rb'
@@ -48,23 +34,21 @@ Lint/EnsureReturn:
- 'language/return_spec.rb'
# Offense count: 10
-Lint/FloatOutOfRange:
+Lint/FlipFlop:
Exclude:
- - 'core/string/modulo_spec.rb'
+ - 'language/if_spec.rb'
+ - 'language/precedence_spec.rb'
-# Offense count: 43
-Lint/FormatParameterMismatch:
+# Offense count: 10
+Lint/FloatOutOfRange:
Exclude:
- - 'core/kernel/sprintf_spec.rb'
- 'core/string/modulo_spec.rb'
-# Offense count: 25
-Lint/HandleExceptions:
- Enabled: false
-
-# Offense count: 2
+# Offense count: 3
+# This cop supports safe autocorrection (--autocorrect).
Lint/ImplicitStringConcatenation:
Exclude:
+ - 'core/string/chilled_string_spec.rb'
- 'language/string_spec.rb'
# Offense count: 4
@@ -74,132 +58,75 @@ Lint/IneffectiveAccessModifier:
- 'core/module/fixtures/classes.rb'
- 'language/fixtures/private.rb'
-# Offense count: 5
-# Cop supports --auto-correct.
-# Configuration parameters: EnforcedStyle, SupportedStyles.
-# SupportedStyles: runtime_error, standard_error
-Lint/InheritException:
- Exclude:
- - 'core/enumerator/lazy/fixtures/classes.rb'
- - 'core/exception/fixtures/common.rb'
- - 'core/module/fixtures/autoload_ex1.rb'
-
-# Offense count: 3
-# Cop supports --auto-correct.
+# Offense count: 12
+# This cop supports safe autocorrection (--autocorrect).
Lint/LiteralInInterpolation:
Exclude:
+ - 'core/module/refine_spec.rb'
+ - 'core/string/shared/to_sym.rb'
+ - 'language/alias_spec.rb'
- 'language/defined_spec.rb'
- 'language/fixtures/squiggly_heredoc.rb'
-
-# Offense count: 16
-Lint/Loop:
- Exclude:
- - 'language/until_spec.rb'
- - 'language/while_spec.rb'
+ - 'language/string_spec.rb'
+ - 'language/symbol_spec.rb'
+ - 'language/undef_spec.rb'
# Offense count: 8
-# Cop supports --auto-correct.
-Lint/MultipleCompare:
+# This cop supports safe autocorrection (--autocorrect).
+Lint/MultipleComparison:
Exclude:
- 'language/precedence_spec.rb'
-# Offense count: 8
-Lint/NestedMethodDefinition:
- Exclude:
- - 'language/def_spec.rb'
-
-# Offense count: 12
+# Offense count: 9
+# This cop supports safe autocorrection (--autocorrect).
Lint/ParenthesesAsGroupedExpression:
Exclude:
- - 'command_line/rubyopt_spec.rb'
- - 'core/string/fixtures/freeze_magic_comment.rb'
- 'language/block_spec.rb'
- - 'language/fixtures/send.rb'
- 'language/method_spec.rb'
- - 'library/socket/socket/getaddrinfo_spec.rb'
-
-# Offense count: 22
-Lint/RescueException:
- Exclude:
- - 'command_line/fixtures/debug_info.rb'
- - 'core/dir/fileno_spec.rb'
- - 'core/exception/cause_spec.rb'
- - 'core/exception/no_method_error_spec.rb'
- - 'core/kernel/fixtures/autoload_frozen.rb'
- - 'core/module/autoload_spec.rb'
- - 'core/mutex/sleep_spec.rb'
- - 'core/process/euid_spec.rb'
- - 'core/process/setsid_spec.rb'
- - 'core/process/uid_spec.rb'
- - 'core/thread/abort_on_exception_spec.rb'
- - 'core/thread/shared/exit.rb'
- - 'language/rescue_spec.rb'
- - 'library/erb/filename_spec.rb'
# Offense count: 1
-# Cop supports --auto-correct.
-Lint/ScriptPermission:
- Exclude:
- - 'command_line/fixtures/bin/launcher.rb'
-
-# Offense count: 10
-Lint/ShadowingOuterLocalVariable:
+# This cop supports unsafe autocorrection (--autocorrect-all).
+# Configuration parameters: AllowedMethods, InferNonNilReceiver, AdditionalNilMethods.
+# AllowedMethods: instance_of?, kind_of?, is_a?, eql?, respond_to?, equal?
+# AdditionalNilMethods: present?, blank?, try, try!
+Lint/RedundantSafeNavigation:
Exclude:
- - 'core/binding/local_variables_spec.rb'
- - 'language/block_spec.rb'
- - 'language/proc_spec.rb'
+ - 'language/safe_navigator_spec.rb'
+ - 'language/fixtures/rescue_captures.rb'
# Offense count: 2
-# Cop supports --auto-correct.
-Lint/StringConversionInInterpolation:
+# This cop supports safe autocorrection (--autocorrect).
+Lint/RedundantStringCoercion:
Exclude:
- 'core/io/print_spec.rb'
+# Offense count: 1
+# Configuration parameters: AllowRBSInlineAnnotation.
+Lint/SelfAssignment:
+ Exclude:
+ - 'core/gc/auto_compact_spec.rb'
+
+# Offense count: 4
+# Configuration parameters: IgnoreImplicitReferences.
+Lint/ShadowedArgument:
+ Exclude:
+ - 'language/fixtures/super.rb'
+
+# Offense count: 49
+# Configuration parameters: AllowComments, AllowNil.
+Lint/SuppressedException:
+ Enabled: false
+
# Offense count: 9
+# Configuration parameters: AllowKeywordBlockArguments.
Lint/UnderscorePrefixedVariableName:
Exclude:
- 'core/io/pipe_spec.rb'
- 'core/io/popen_spec.rb'
- 'language/block_spec.rb'
-# Offense count: 91
-# Cop supports --auto-correct.
-Lint/UnneededSplatExpansion:
- Exclude:
- - 'core/array/element_reference_spec.rb'
- - 'core/array/unshift_spec.rb'
- - 'core/enumerable/fixtures/classes.rb'
- - 'core/enumerable/max_by_spec.rb'
- - 'core/enumerable/min_by_spec.rb'
- - 'core/enumerable/minmax_by_spec.rb'
- - 'core/enumerator/lazy/fixtures/classes.rb'
- - 'core/file/basename_spec.rb'
- - 'core/kernel/p_spec.rb'
- - 'language/array_spec.rb'
- - 'language/break_spec.rb'
- - 'language/case_spec.rb'
- - 'language/next_spec.rb'
- - 'language/send_spec.rb'
- - 'language/variables_spec.rb'
-
-# Offense count: 55
-Lint/UnreachableCode:
- Exclude:
- - 'core/enumerator/lazy/fixtures/classes.rb'
- - 'core/kernel/catch_spec.rb'
- - 'core/kernel/throw_spec.rb'
- - 'language/break_spec.rb'
- - 'language/fixtures/break.rb'
- - 'language/fixtures/break_lambda_toplevel.rb'
- - 'language/fixtures/break_lambda_toplevel_block.rb'
- - 'language/fixtures/break_lambda_toplevel_method.rb'
- - 'language/fixtures/return.rb'
- - 'language/next_spec.rb'
- - 'language/return_spec.rb'
- - 'optional/capi/kernel_spec.rb'
- - 'shared/kernel/raise.rb'
-
-# Offense count: 7
+# Offense count: 9
+# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: ContextCreatingMethods, MethodCreatingMethods.
Lint/UselessAccessModifier:
Exclude:
@@ -207,4 +134,5 @@ Lint/UselessAccessModifier:
- 'core/module/fixtures/classes.rb'
- 'core/module/module_function_spec.rb'
- 'core/module/private_class_method_spec.rb'
+ - 'language/fixtures/def.rb'
- 'language/fixtures/send.rb'
diff --git a/spec/ruby/.travis.yml b/spec/ruby/.travis.yml
deleted file mode 100644
index e8a9106ac1..0000000000
--- a/spec/ruby/.travis.yml
+++ /dev/null
@@ -1,36 +0,0 @@
-sudo: false
-language: ruby
-install:
- - git clone https://github.com/ruby/mspec.git ../mspec
-script:
- - if [ -n "$RUBOCOP" ]; then gem install rubocop -v 0.51.0 && rubocop; fi
- - ../mspec/bin/mspec $MSPEC_OPTS
-matrix:
- include:
- - os: osx
- osx_image: xcode9
- rvm: 2.4.2
- env: CHECK_LEAKS=true
- - os: linux
- rvm: 2.4.2
- env: MSPEC_OPTS="-R2 -ff"
- - os: linux
- rvm: 2.2.8
- - os: linux
- rvm: 2.3.5
- - os: linux
- rvm: 2.4.2
- env: CHECK_LEAKS=true RUBOCOP=true
- - os: linux
- rvm: ruby-head
- allow_failures:
- - os: linux
- rvm: ruby-head
-branches:
- only:
- - master
- - /^try/
-notifications:
- email:
- on_success: change
- on_failure: change
diff --git a/spec/ruby/CHANGES.before-2008-05-10 b/spec/ruby/CHANGES.before-2008-05-10
deleted file mode 100644
index 18778bc146..0000000000
--- a/spec/ruby/CHANGES.before-2008-05-10
+++ /dev/null
@@ -1,17796 +0,0 @@
- Changelog
-===========
-
-This file contains the entire revision history of the specs from
-December 2006 onwards, when the spec project got started more or
-less officially by converting the remaining Test::Unit style tests
-in Rubinius to the spec style. The history is not preserved in the
-git repository history itself, so this data is here for reference.
-All the commit hashes are from the Rubinius repository.
-
-It still misses quite a few of the earlier, disparate specs and
-tests because up to that point the organisation was much looser
-and gathering an exhaustive accounting of the entire history of
-TDD/BDD would be time-consuming, particularly with the few full
-directory moves in there and such. All of the data is preserved
-in the Rubinius repository if someone is interested in that bit
-of history.
-
-Be aware that the history contains some Rubinius-specific specs
-by necessity. If you find any commits listed that were _solely_
-for Rubinius, feel free to strip them out.
-
-Thanks to everyone committing up to this point--over 2600 commits
-in just this incomplete version. Keep it up.
-
-
-
- Revision History
-------------------
-
-
-commit 2b24a1e84c350810817885eeb6532f43c698a95c
-Author: Ryan Davis <rdavis@engineyard.com>
-Date: Fri May 9 16:45:07 2008 -0700
-
- Fixed up pack for base64 and uuencode to be MUCH MUCH cleaner and 2x faster
-
-commit 022bc5dbfafcf1f9fd5e25820104718bd4d45661
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Fri May 9 23:51:47 2008 +0200
-
- Share common specs for BigDecimal's #mult and #*.
-
-commit 414e7eedce9d0cea982e24f1031c407daccc648b
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Fri May 9 23:19:38 2008 +0200
-
- New rubyspecs for BigDecimal#mult
-
- * Verifies that proper signs are calculated when
- zero is involved.
-
-commit 6883d7d0c67f7be84e7ea1703912452eaecaac6c
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Fri May 9 22:54:49 2008 +0200
-
- New rubyspec for Module#new with block.
-
-commit f8bd3e34014a7351470685676b6b168abd787794
-Author: Phil Hagelberg <technomancy@gmail.com>
-Date: Fri May 9 12:53:00 2008 -0700
-
- Added specs for OpenSSL::HMAC.hexdigest and .digest
-
-commit 686c28493d42b9c798aa791823395d1000423225
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Fri May 9 20:20:13 2008 +0200
-
- Some more rubyspecs for BigDecimal's #floor and #ceil.
-
-commit aba022a6620ec8d3a09067e9677f0f9c5d8078ee
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Fri May 9 17:51:35 2008 +0200
-
- New rubyspecs for BigDecimal's #floor and #ceil.
-
-commit e4d844ba5851a798b7acb684cf68fdcef353d13c
-Author: Brian Ford <bford@engineyard.com>
-Date: Thu May 8 22:13:58 2008 -0700
-
- Excluded stdlib specs from default CI run. Added spec/full.mspec.
-
-commit 6a133574617cb435ad1684f208430112ff6839f6
-Author: Ryan Davis <rdavis@engineyard.com>
-Date: Thu May 8 16:19:50 2008 -0700
-
- String#unpack overhaul. NO extra methods littered through Fixnum/Integer/String. NO procs. More readable, but still messy.
-
-commit 11dd3ae2c4e0dd81304e85ba662db41196f1ce4c
-Author: Brian Ford <bford@engineyard.com>
-Date: Wed May 7 23:59:31 2008 -0700
-
- Fixed constant type clash for ModuleSpecs modules.
-
-commit 4e702d10b32fdba62cdeae476b8217019839c3b0
-Author: Brian Ford <bford@engineyard.com>
-Date: Wed May 7 21:42:11 2008 -0700
-
- Some specs for Kernel#__add_method__ and Module.__add_method__.
-
-commit 819649f24f59819be185b0562b94f9089f8c000c
-Author: Brian Ford <bford@engineyard.com>
-Date: Wed May 7 14:48:01 2008 -0700
-
- Added spec for Kernel#eval with binding from method defined by #eval.
-
-commit d73b17b88b6084fdf7cab764b0fbdd3b3882dd81
-Author: Brian Ford <bford@engineyard.com>
-Date: Wed May 7 10:06:26 2008 -0700
-
- Use literals in Bignum#to_f specs (alternate fix for #535).
-
-commit ee211770eb8792b3f58f78ff60eec6d5289caa20
-Author: Ryan Davis <rdavis@engineyard.com>
-Date: Wed May 7 02:38:00 2008 -0700
-
- Added specs for big uncovered areas, still not 100%
-
-commit 7ce9bc2d7edc64f6886c3d34836bc0394414ed66
-Author: Ryan Davis <rdavis@engineyard.com>
-Date: Tue May 6 03:56:19 2008 -0700
-
- Fixed typo
-
-commit af3407251ee0f287ec80232c354153af169636e4
-Author: Adam Gardiner <adam.b.gardiner@gmail.com>
-Date: Tue May 6 22:01:23 2008 +1000
-
- Fix bug in Debugger::Output.wrap
-
-commit d9322306ea70f2b847b0f806bdb13ea02f2d6b4d
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Mon May 5 13:09:32 2008 -0400
-
- Fix some bugs in BigDecimal#/. More may yet lurk.
-
-commit 2f3a4cc14433858b13caa932c8a50c31e024c7e8
-Author: Federico Builes <federico.builes@gmail.com>
-Date: Mon May 5 12:04:26 2008 -0500
-
- Adding more specs for REXML::Element
-
- * Covers REXML::Element#{add_attribute, add_attributes, add_namespace, add_text, clone, comments}
-
-commit 7db8c2b563ea474cf2db5fa14bb2a6345c8c469f
-Author: Federico Builes <federico.builes@gmail.com>
-Date: Mon May 5 10:54:00 2008 -0500
-
- One more case for YAML.load specs
-
-commit 098decdf510b05f82ff9a6cc6769cf478a3236ab
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Sun May 4 22:29:35 2008 -0400
-
- Define BigDecimal#ver.
-
-commit f6f1fe6a667570e4c1521649b964dca1352d1c32
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Sun May 4 22:12:08 2008 -0400
-
- BigDecimal#new: Make space between '-' and 'Infinity' unparsable, as per spec.
-
-commit 503aae7cdbb208da8f25080762e17f0866845c4d
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Mon May 5 06:19:40 2008 -0400
-
- Method call parsing spec from Jim Kingdon with minor addition.
-
- * Moved the SyntaxError producing code into an #eval because the file
- cannot be compiled to run otherwise.
-
-commit 398d5de0a0ffaf746e39e5f6a6ded02483fd1842
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Mon May 5 02:26:39 2008 -0400
-
- Spec for :match node, implicit Regexp matches against $_.
-
- * Compiler and Language specs.
-
-commit 206cea31c6a93fe434948dcb79321e2c119edf21
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Sat May 3 11:40:17 2008 -0400
-
- Implement BigDecimal#power and #**, fix some bugs in #mult.
-
-commit a197099d9be6e48ad32480ae323302c83146147b
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Sat May 3 02:18:35 2008 -0400
-
- Fixed a logic and syntax error in BigDecimal#mult specs.
-
- * Removed some parentheses too.
-
-commit 081afd58a29ccd5025b806f53e9d7679b9296a7f
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Sat May 3 02:25:45 2008 -0400
-
- Make sure subclasses that implement their own Hash#default work (Merb)
-
-commit 203ca288175416fadb110b2aa9cdf8cfbf13215d
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Sat May 3 01:49:35 2008 -0400
-
- Specs and implementation for module include order (fixes abstract.rb)
-
-commit c788a9f2d9c4561a2837bbf78f68a6885d626917
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Fri May 2 18:14:32 2008 -0400
-
- Implement BigDecimal#*, as well as #mult without precision support.
-
-commit 57d78528ff4cf249d906785ffbfdde1fda4aa3cc
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Fri May 2 17:36:15 2008 -0400
-
- Implement BigDecimal#/ and #quo. Not perfect; still relies on #/.
-
-commit c42cc2cacc347d8284650c7046d4dadf94d7d4a5
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Fri May 2 16:13:07 2008 -0400
-
- Fix a typo in specs.
-
-commit ae179b410665da18628f249e6796f1e07ab83763
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Fri May 2 16:10:43 2008 -0400
-
- Get BigDecimal#floor basically working.
- * The failing specs depend on #/, which isn't implemented yet.
-
-commit f8221117d174b91affe406c8089ed25e887232b3
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Fri May 2 16:06:32 2008 -0400
-
- Fix bugs in BigDecimal#add and #+. This also affects #sub, #-, and #ceil.
-
-commit cdd196daf7643e846b7f3582b1e441b883e02aba
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Fri May 2 15:41:29 2008 -0400
-
- More specs to fix bugs in BigDecimal#add and #+.
-
-commit c1c52a2a531b570fa1025d99e464d93c570cf59e
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Fri May 2 15:22:33 2008 -0400
-
- Write another spec for BigDecimal#ceil.
-
-commit 71b65cdbfa5aae461fc52c997df9fca3bee9c8d5
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Fri May 2 14:47:34 2008 -0400
-
- Write tests for a bug in BigDecimal#add and #+ where 0 + 1 = 0.1.
-
-commit 55988ef53879c1c489c570b3f37717365c7f8e2b
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Sat May 3 01:04:11 2008 -0400
-
- Fix use of alias keyword inside instance_eval
-
-commit d4011595a0077e91665f85410d458c57367cf50b
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Fri May 2 20:38:15 2008 +0200
-
- Added news specs for BigDecimal#mult.
-
-commit b6771644d35b6b8f3c87f7f4461bcaba99cd976f
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Fri May 2 19:41:09 2008 +0200
-
- More BigDecimal#divmod rubyspecs.
-
- MRI-specific bug is hidden behind ruby-bug guard.
-
-commit 854a011324ce717cfd47ddec6389a9e9abb0db18
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Fri May 2 18:45:29 2008 +0200
-
- New BigDecimal#divmod specs.
-
-commit b9806e0efb2a8e51d70f6d51733df7bed88152d9
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Fri May 2 16:45:10 2008 +0200
-
- A couple of test cases for BigDecimal's #quo, #div, #/.
-
-commit 3cf6c1e03001ba1dda966e3392b665f5b08a1b9d
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Fri May 2 15:03:37 2008 +0200
-
- More tests for BigDecimal#floor.
-
-commit b70023978562af89cf4349e14e9443adb37ecbbe
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Thu May 1 21:15:29 2008 -0400
-
- Improved a spec description for String#index.
-
- * The description looks exactly like we had the wrong implementation
- relying on % 256 and someone wrote a spec to make sure that did not
- happen. However, the description was more or less meaningless to
- what was actually being specced.
-
-commit 6e6aa411ff4c7a837d5d4adb9ab893719cf9e122
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Thu May 1 10:48:20 2008 -0700
-
- Fix a number of things to pass all def specs
-
- This is the result of ping-pong between Evan and Wilson. It refactors
- out enclosing_class from being used, and instead information is always
- pulled directly from the StaticScope object. This lets us inject proper
- scoping changes in ruby.
-
-commit 2db27aef88e2ca7752beba846d172ede276275e0
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Thu May 1 19:03:50 2008 +0200
-
- Implemented Socket.unpack_sockaddr_un
-
-commit d515221698e02b52ed4661113d659744fbfae36f
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Thu May 1 18:18:32 2008 +0200
-
- Forgot to update spec tags for TCPSocket.gethostbyname
-
-commit bf839a99c3a5b773b6b96c6d5a1fcc5056511e7a
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Thu May 1 14:03:30 2008 +0200
-
- Implement File#mtime specs
-
-commit b8c713e6b972b464788c740b4283a5b4226c123c
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Thu May 1 13:55:36 2008 +0200
-
- Implemented File.lchmod and initial specs
-
-commit 059c926d7280c2e7c9f8bf710c5aef70cde3e777
-Author: Adam Wiggins <adam@heroku.com>
-Date: Sun Apr 27 15:03:31 2008 -0700
-
- IO.popen read/write pipes
-
- Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
-
-commit d9a050aa45efd00a40395b7ac7ac069f4be1fd1c
-Author: Adam Gardiner <adam.b.gardiner@gmail.com>
-Date: Thu May 1 16:25:18 2008 +1000
-
- Spec fixes for Tuple#to_a
-
-commit 0b610359fbfe8137fdba95d90b659238168d6788
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Wed Apr 30 17:45:51 2008 -0400
-
- Update spectags.
-
-commit 024ebfdf3fa9c54b8a81134edb52fe10b09e4b91
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Wed Apr 30 22:56:44 2008 +0200
-
- Added BigDecimal#divmod excludes.
-
-commit e12d21a90760df723c0f48265cb49a9c4463db7c
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Wed Apr 30 20:51:06 2008 +0200
-
- More tests for BigDecimal#divmod.
-
-commit 68cfef604f9b5411ca9e0349883bac4f59541f0d
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Wed Apr 30 16:47:31 2008 -0400
-
- Make BigDecimal#finite? handle NaN correctly, and refactor accordingly.
-
-commit 5066bcb8881241caf6d13be625b32633bda6567e
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Wed Apr 30 15:01:12 2008 -0400
-
- Make BigDecimal#<= and #>= pass Vladimir's new specs.
-
-commit 49601aff01c394fe2168f5f221a987be63a9ebc7
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Wed Apr 30 20:20:18 2008 +0200
-
- Various improvements to BigDecimal rubyspecs.
-
- * Corrected comparison specs (properly add arrays there)
- * New reminder specs
- * New modulo and % specs
- * Tagged rbx failures
-
-commit dd1700b747ba26b27eff0b249623aca559db06e1
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Wed Apr 30 17:48:20 2008 +0200
-
- More test cases for BigDecimal#modulo and #%.
-
-commit 8eb9dc1b0aee3587f4da8b9cbe306fd431159d79
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Wed Apr 30 16:57:16 2008 +0200
-
- New specs for BigDecimal#modulo and #%.
-
-commit 4a846f807fe2c4c12d8719bc5c9ccb4ab696aff9
-Author: Federico Builes <federico.builes@gmail.com>
-Date: Tue Apr 29 15:29:34 2008 -0500
-
- Fixes REXML::Element#namespaces specs
-
- * Use sort on the arrays to make sure the specs pass on JRuby too.
-
-commit 823683a864072ef6a81e808dbf792dee45d29c52
-Author: Federico Builes <federico.builes@gmail.com>
-Date: Tue Apr 29 14:54:08 2008 -0500
-
- Adds more specs for REXML.
-
- * Specs for REXML#{inspect, namespace, namespaces, prefixes, text and text=}.
-
-commit a11a10760ce92ee373e04a5445234521a27874cc
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Mon Apr 28 17:55:55 2008 -0400
-
- Committing so we can bisect.
-
-commit df94214b1d132b02e3dd5b166d1c7c5cd5d50a21
-Author: Drew Olson <olsonas@gmail.com>
-Date: Mon Apr 28 19:21:07 2008 -0700
-
- Added spec for Array#remove_outer_arrays
-
-commit ec4ece9c06b42c257b4ffce2cf319f0ad23f65e8
-Author: Drew Olson <olsonas@gmail.com>
-Date: Sun Apr 27 20:15:47 2008 -0500
-
- Added more edge cases for recursive arrays to spec for File#join
- * an empty array containing an empty array which contains a recursive array should return
- '[...]' when File#join is called on it.
-
-commit 698a5d291cf63e56e9a3508a8850c77fa2c23430
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Mon Apr 28 16:17:05 2008 -0400
-
- Implement BigDecimal#=== as alias of #eql?.
-
-commit 18f515e735eecc519be55a6e3253db7135a137ad
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Mon Apr 28 16:09:43 2008 -0400
-
- Implement BigDecimal#sub.
-
-commit b331faa567dc1d98163c6447897221877cf756eb
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Mon Apr 28 16:04:06 2008 -0400
-
- Implement BigDecimal#add.
-
-commit f3f94c9b53045ddde335981897e2f6087dab7ef2
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Mon Apr 28 12:01:41 2008 -0500
-
- hack to fix DRb.start_service spec to at least test start_service
-
-commit 4c8d6d90c69615386e26c71633e242f4e1f19342
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Mon Apr 28 11:56:47 2008 -0500
-
- spec for DRb.stop_service to see if it clears the socket correctly
-
-commit 03cb539f42f0b558fa29911c1dfc71ec5f2b183f
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Mon Apr 28 11:20:17 2008 -0500
-
- Revert "Revert "Made DRb spec depend partially on PID so multiple runs don't clash.""
-
- Apparently this is a supposed fix for concurrent spec runs, not for the spec failure
-
- This reverts commit 08695d9a6940ab74f6eb8965e449a417002a42a6.
-
-commit 2172e2ac20b69a97c2ad66551b3620a43bfda700
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Mon Apr 28 02:14:18 2008 -0400
-
- Make BigDecimal#exponent return Bignums as necessary, not just Fixnums.
-
-commit dc93d06163e80cdf89a67532654a850828119287
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Mon Apr 28 01:23:19 2008 -0400
-
- Correct implementation of BigDecimal#+ and #-. There's still a lot of repetition to be factored out, but this algorithm is more correct than the last try.
-
-commit 1da58bb7f0afbba4f8412e06983304dc7d887ac9
-Author: Luis Lavena <luislavena@gmail.com>
-Date: Thu Apr 24 16:37:59 2008 -0300
-
- Corrected small typo on File#join specs under Windows.
-
-commit b287619579ad11535722a2374b6f849d88fe9931
-Author: Drew Olson <olsonas@gmail.com>
-Date: Thu Apr 24 14:24:10 2008 -0700
-
- Spec for File#join now describes correct behavior for arrays with recursive sub-arrays.
-
-commit 5830380895c0bec16c6af39d0f29d8d70268028d
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Sun Apr 27 14:53:47 2008 -0500
-
- DRb.start_service spec fails because of a timing bug in DRb
-
- See http://jira.codehaus.org/browse/JRUBY-2347
-
-commit 08695d9a6940ab74f6eb8965e449a417002a42a6
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Sun Apr 27 14:51:16 2008 -0500
-
- Revert "Made DRb spec depend partially on PID so multiple runs don't clash."
-
- The spec is designed for sane behavior, if Rubinius or the
- implementation of DRb is causing problems then they should be
- fixed, not the spec in this case. Fixing the spec will only
- hide the bug.
-
- See http://jira.codehaus.org/browse/JRUBY-2347 for more commentary on the problem.
-
- This reverts commit f89bd8c6c425c9d9bcc3e589b8d3b05ce3ccbced.
-
-commit 94ba0884c8e7f398b6fe8d6736834f62f6a49815
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Sun Apr 27 21:23:47 2008 +0200
-
- More checks for BigDecimal#abs specs.
-
-commit 80932d25ca95e2e8c803d244a7636e3004525ade
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Sun Apr 27 21:10:26 2008 +0200
-
- More test cases for BigDecimal#finite? specs.
-
-commit 4b541ed23ccac65f6f4b2ef8aad56e9aa7a69e12
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Sun Apr 27 21:04:08 2008 +0200
-
- Added testcase for BigDecimal#infinite? for NaN.
-
-commit 4a1f39426fc60ae7c2ed0470259fa0752a46d030
-Author: Adam Wiggins <adam@heroku.com>
-Date: Sat Apr 26 22:57:09 2008 -0700
-
- IO#write returns 0 when writing a blank string, to match behavior of MRI
-
- Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
-
-commit 56c0088f9b075769933c8c87e3c2d256cff3a3e8
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Sun Apr 27 00:28:47 2008 -0400
-
- Typo.
-
-commit c11410654b9046cdb58dba1d116f58ce74f4c263
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Sun Apr 27 00:24:32 2008 -0400
-
- Finish implementing #@- and #infinite?. Update spectags, of course
-
-commit dc9f427ecb9d55559d800af70f9c1a3f2f2123b5
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Sun Apr 27 00:07:31 2008 -0400
-
- Amplify a comment.
-
-commit b9776b953ae67f2088e44b640145af464a1cf942
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Sun Apr 27 00:02:48 2008 -0400
-
- Get BigDecimal#+ working. I hate this algorithm, but it works without running out of memory.
- * Update spec tags.
-
-commit b87ff5c22891f19ad0b956e7e02cc3a3d1adcc93
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Sat Apr 26 14:27:00 2008 -0400
-
- Implement BigDecimal#coerce.
- * Update spectags.
- * Rewrite one spec so it doesn't depend on BigDecimal#-, which is not yet implemented.
-
-commit f89bd8c6c425c9d9bcc3e589b8d3b05ce3ccbced
-Author: Brian Ford <bford@engineyard.com>
-Date: Sat Apr 26 15:52:49 2008 -0700
-
- Made DRb spec depend partially on PID so multiple runs don't clash.
-
-commit 3c49a1d16f20726c4ee2d7eb5f5c671537aa59d5
-Author: Brian Ford <bford@engineyard.com>
-Date: Sat Apr 26 15:13:47 2008 -0700
-
- Added wordsize guard for BigDecimal#exponent spec.
-
-commit 3aac5f6d64f4cbbca70ecf01b7ed9be596fa5b76
-Author: Brian Ford <bford@engineyard.com>
-Date: Sat Apr 26 15:09:40 2008 -0700
-
- Updated spec_helper and renamed CaptureOutput to IOStub.
-
-commit 94322a6a95770a030d28925cc7213a38c5687ea1
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Sat Apr 26 23:16:59 2008 +0200
-
- A bit more test cases for BigDecimal#-@.
-
-commit 9919c5e3be59562532c967b479c959cf6270046e
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Sat Apr 26 21:01:44 2008 +0200
-
- New specs for BigDecimal#uminus.
-
-commit c3e74531f1ca1e70671f529671c0fa474968dc87
-Author: Marius Nuennerich <marius@nuenneri.ch>
-Date: Sat Apr 26 13:08:04 2008 +0200
-
- FreeBSD seems to work like the rest, not darwin
-
- Tested on FreeBSD/i386 7-STABLE
-
-commit c06a091b285f388f09b11037975921662759eea2
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Sat Apr 26 12:14:33 2008 -0400
-
- Implement BigDecimal#exponent, update spectags. Looks like parts of #** have accidentally stopped failing too. :)
-
-commit e5b753b7e659b29f5ed4aa57018f922111b238f5
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Sat Apr 26 11:53:55 2008 -0400
-
- Specify return type of BigDecimal#ceil as BigDecimal, as per library documentation.
-
-commit 0ca3b9ceb6ef5ca1898250b89f75c0194b5da481
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Sat Apr 26 11:50:24 2008 -0400
-
- Fix BigDecimal#inspect output, update spectags.
-
-commit ca99aa062afe9106ec614e2d8969d3491803c9a2
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Sat Apr 26 11:48:00 2008 -0400
-
- Specify return type of BigDecimal#ceil as BigDecimal, as per library documentation.
-
-commit 587a5cdbbfa4cccdbfe98339ca999f1d63bd66cf
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Sat Apr 26 15:02:33 2008 +0200
-
- Corrected one Array#hash test case.
-
- Now Array#hash pass MRI 1.8.6, 1.8.7, 1.9 and JRuby.
-
-commit f86bdb98b8b9f5ea878c5d142f3a694e5278db77
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Sat Apr 26 14:19:14 2008 +0200
-
- Quarantined couple of specs that fail on *ALL* implmenetations.
-
- Probably, we need a better way to do that, but quarantine
- is a quick and simple way, easily detectable later on.
-
-commit 7ca928211180c66b9879afbc382c376a7649e1b0
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Sat Apr 26 00:51:39 2008 -0400
-
- Implement BigDecimal#to_f, update tags. Will this need more work?
-
-commit 69dec41f6b5b532c5de7f46e97f97c9e102305c7
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Sat Apr 26 00:44:40 2008 -0400
-
- Implement BigDecimal#truncate.
- * Update spec tags.
- * Reorganize variables slightly to remove duplication.
-
-commit c823e62c3a6776b62f65c34b16bdca5748d1add9
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Sat Apr 26 00:36:43 2008 -0400
-
- Implement BigDecimal#truncate.
- * Update spec tags.
- * Reorganize variables slightly to remove duplication.
-
-commit 3f4e5dc78de5bf3e81ae1ce7a0d14852a32aeade
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Sat Apr 26 00:16:38 2008 -0400
-
- Rewrite spec description to bring it in line with what the spec actually does. :)
-
-commit 15d87e8a983d08d99fc3ec6bfbb7f36ed0cd4c4e
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Fri Apr 25 18:09:33 2008 -0400
-
- Implement BigDecimal#to_i, update spec tags.
-
-commit 59873b144ea836e2f9bbef7d5186a1287155e76a
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Fri Apr 25 20:46:17 2008 -0400
-
- Specs for autoload path normalization
-
-commit 71fe2d45d147fe2c41937ae5ef6dbb8814f491c4
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Fri Apr 25 17:05:17 2008 -0400
-
- Use a separate class in Singleton 'new' specs to avoid contamination
-
-commit 2dc8f9eb9c6db014bd6cc132d987fdb4612816f8
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Fri Apr 25 16:45:28 2008 -0400
-
- Handle more nightmare Autoload edge cases by hooking into Kernel#require
-
-commit 5c1a375a15adbe20a9bf3d1b95e1f2d30feaa90e
-Author: Michael Fellinger <m.fellinger@gmail.com>
-Date: Sat Apr 26 04:26:52 2008 +0900
-
- Spec for Module#autoload when the load path has already been required
-
- Signed-off-by: Wilson Bilkovich <wilson@supremetyrant.com>
-
-commit ee47a0cc0da787599479fc8dd085b7481b591176
-Author: Charles Oliver Nutter <charles.nutter@sun.com>
-Date: Fri Apr 25 15:41:19 2008 -0500
-
- Enabled another $_ spec and added a proc dispatch scoping test to $~ and $_
-
-commit eabc4609758dc99727c77493c58f187782ea957f
-Author: Charles Oliver Nutter <charles.nutter@sun.com>
-Date: Fri Apr 25 15:32:03 2008 -0500
-
- Added some basic specs for $_: implicit assign, explicit assign, scoping
-
-commit 61194dec429a9f288791156639f058e45a4e72e9
-Author: Charles Oliver Nutter <charles.nutter@sun.com>
-Date: Fri Apr 25 14:49:53 2008 -0500
-
- Add some specs for $~ scoping and assignment.
-
-commit 4c5cec4f6e10864c68b140e71cc2559e7a7d636b
-Author: Brian Ford <bford@engineyard.com>
-Date: Thu Apr 24 18:28:08 2008 -0700
-
- Added incomplete tags for CSV spec stubs.
-
-commit 6e231caef62e678413e86317881aaab200d0802e
-Author: Brian Ford <bford@engineyard.com>
-Date: Thu Apr 24 18:15:06 2008 -0700
-
- Reprocessed library CSV specs with new mkspec.
-
-commit 4cdc61a76cce73b52f05f53f820838cc7e3c2823
-Author: Michael Fellinger <m.fellinger@gmail.com>
-Date: Fri Apr 25 08:46:32 2008 +0900
-
- Updating specs for the module #included calling #extend issue.
-
- Signed-off-by: Brian Ford <bford@engineyard.com>
-
-commit 40e775bf036aa59e69268708f8c78b8a56e0f9ce
-Author: Brian Ford <bford@engineyard.com>
-Date: Thu Apr 24 17:10:55 2008 -0700
-
- Moved #bignum_value helper to MSpec.
-
-commit 9b52edbb14ff2fc18faa429daf4ceaff5b87db11
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Thu Apr 24 14:37:53 2008 -0400
-
- Implement BigDecimal#fix, make #frac trap for a few common cases without running out of memory for big numbers.
-
- * Update spec tags.
-
-commit 6a604c0a9863073cfd7540ff755e7ca035a7dff5
-Author: Marius Nuennerich <marius@nuenneri.ch>
-Date: Thu Apr 24 19:32:14 2008 +0200
-
- Don't run Process.setpriority spec on FreeBSD
-
-commit 0ab639af500d947c5b5feb1d8f00f5fbc97a0edc
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Thu Apr 24 13:37:23 2008 +0200
-
- Adjusted IO specs to supply blocks for each-like methods.
-
- See [ruby-core:16557] for more details.
-
-commit a7b603a9ce6bfb570785e803bdb89ae36bb6253d
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Thu Apr 24 13:14:40 2008 +0200
-
- Fixed IO, Process, Regexp specs ('should' was missing).
-
-commit 26de6c05c050d0dbcb073c407abda47f964bfd29
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Thu Apr 24 12:50:46 2008 +0200
-
- Fixed File specs ('should' is misspelled)
-
-commit 99a2b23d8fb42cb377cb3fb9ab2569c555aec8bf
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Thu Apr 24 12:47:57 2008 +0200
-
- Fixed Array specs ('should' was missing).
-
-commit 67b301a03fd6f7f0fa38ce106ab05825f2cbb15c
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Thu Apr 24 12:43:39 2008 +0200
-
- Fixed specs ('should' was missing), some new test cases for BigDecimal.
-
-commit aecbea57de7ee1b50bd4b06871dd08e762a6ccb8
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Thu Apr 24 12:35:54 2008 +0200
-
- More test cases for BigDecimal#nan?
-
-commit 7aaf8fa137b8961ca122eb92e7447936ad7a44cc
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Thu Apr 24 12:26:20 2008 +0200
-
- More test cases for BigDecimal#zero?
-
-commit 58ecee694f191aa05e7867544cf8d63129558447
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Thu Apr 24 12:19:11 2008 +0200
-
- A bit more test cases for BigDecimas#-.
-
-commit e946dd03d590e29a1d344e7579d5ff047df4a76b
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Thu Apr 24 12:17:16 2008 +0200
-
- New and updated specs for BigDecimal#-.
-
-commit 01d82db424b4e447b98e5f2eb3e162b991dece8a
-Author: Brian Ford <bford@engineyard.com>
-Date: Thu Apr 24 01:25:20 2008 -0700
-
- Tag for new private setter method spec.
-
-commit c0ee2e133a4e5fc179b96329ffd3934dd9263c2b
-Merge: 374ab81... e9826b9...
-Author: Tony Arcieri <tony@medioh.com>
-Date: Thu Apr 24 02:19:00 2008 -0600
-
- Merge branch 'master' of git@git.rubini.us:code
-
-commit 374ab81e2c01ea5ac48cda2004ae92a989d7f3d7
-Author: Tony Arcieri <tony@medioh.com>
-Date: Thu Apr 24 02:18:26 2008 -0600
-
- Specs for calling a private setter method on self
-
- * Not presently working under rbx, works under MRI
- * I don't entirely know the process for this, but this is expected to break
-
-commit 39505393f330b5f622788f1d98ea8ff3781499c7
-Author: Luis Lavena <luislavena@gmail.com>
-Date: Thu Apr 24 04:04:32 2008 -0300
-
- Fixes Dir fixtures and specs for Windows.
-
- Usage of special characters *, ?, | and : is not allowed under Windows
- * and ? represent wildcards, | is pipe tunelling and : is drive letter
- separator.
-
- Files or Directories cannot contain slashes (\/), wildcards, double-
- quotes, pipe tunelling or stream redirectors (<>).
-
-commit 2ecc076e488ed1a519fc5b6876c68a3d91d55c87
-Author: Brian Ford <bford@engineyard.com>
-Date: Wed Apr 23 22:55:44 2008 -0700
-
- Update tags for newly passing File.join specs.
-
-commit ff3756e179920b84d5a55fc7bbc2688706df044f
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Thu Apr 24 01:09:17 2008 -0400
-
- Add specs for nested method definitions and other complex scenarios
-
-commit 24785f7c28cde09ce0400e5d80f832ae11cddefa
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Wed Apr 23 20:56:55 2008 -0400
-
- Spec for using ||= to initialize a class variable
-
-commit 98b0c44057cb827107cae0f0174b5e81ac2064fd
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Wed Apr 23 19:49:21 2008 -0400
-
- Rewrite descriptions of language/def specs
-
-commit 598c287cc36179644a1bbf2a303a56fc85bb1b12
-Author: Brian Ford <bford@engineyard.com>
-Date: Wed Apr 23 12:39:04 2008 -0700
-
- Replaced use of :mswin with :windows in platform_is[_not] guards.
-
-commit 01fe417f27ad43495327a522ece2f02769064df7
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Wed Apr 23 21:30:34 2008 +0200
-
- Added excludes for BigDecimal#div specs.
-
-commit 46f022d49c394b027491295e7fd5cb305af33404
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Wed Apr 23 21:27:42 2008 +0200
-
- More specs for BigDecimal#div
-
-commit 72433091c6a845c5f550b27111748e29fb5eac09
-Author: Brian Ford <bford@engineyard.com>
-Date: Wed Apr 23 10:56:57 2008 -0700
-
- Added #tmp helper to MSpec for returning a temp file name.
-
-commit f4e975e5255fb36bb8e9be7d310850135ce3515f
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Wed Apr 23 10:54:42 2008 -0400
-
- Implement BigDecimal#frac, update spec tags.
-
-commit b60deba2368a1212d6acd3e49481ba9495de7f2f
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Wed Apr 23 10:49:39 2008 -0400
-
- Correct a spec error.
-
-commit e19cf9401c029f90e117b1c17083c928b0d1c9ca
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Wed Apr 23 10:24:50 2008 -0400
-
- Implement BigDecimal#-@, update spec tags.
-
-commit c3fc05389c75aca3150038814b324266501fdb8f
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Wed Apr 23 16:12:24 2008 +0200
-
- A bit more test cases for BigDecimal#sqrt.
-
-commit b2a220f86887bfe6030a34bc8cd1b748c88cc2b8
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Wed Apr 23 01:43:16 2008 -0400
-
- Get BigDecimal#to_s working according to spec.
-
- * Implement #to_s.
- * Update spec tags.
-
-commit 82638601be12e410413047779f01840d6d0db3d8
-Author: Adam Gardiner <adam.b.gardiner@gmail.com>
-Date: Wed Apr 23 09:56:48 2008 +1000
-
- Refactor Debugger to remove dependencies on Debugger::Interface
-
- Also:
- - Add List#inspect to show number of items in list
- - Fix decode output to show original instructions in place of
- yield_debugger
- - Improve regex used to match method names to handle more
- operators
-
-commit 41c64f2825d347fbe2ef9edc33dd8f1e84773251
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Tue Apr 22 18:12:06 2008 -0400
-
- Spec and implementation for NilClass#dup
-
-commit d3e313ed38a847e29225ba814a956d0929ea6460
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Tue Apr 22 22:03:47 2008 +0200
-
- New and updated specs for Bigdecimal's #abs and #sqrt.
-
-commit 2013e106181879b886f2e1cb78e81f52cd284666
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Tue Apr 22 15:52:10 2008 -0400
-
- Re-implement Module#autoload and autoload?. Now passing all autoload specs.
-
-commit 9156271e2b12138e2b2b712a76f0110f20a757b7
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Tue Apr 22 15:34:43 2008 -0400
-
- Add (failing) spec for toplevel autoloaded constant access
-
-commit 8eb5451f88a37dc247e42913c1d72d072a9b02ef
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Tue Apr 22 19:06:00 2008 +0200
-
- One more test case, for BigDecimal#sqrt with nil.
-
-commit e7894fb78cf92b53e9bdc6dcf023d8dd2d66b2ed
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Tue Apr 22 18:52:24 2008 +0200
-
- More detailed specs for BigDecimal#sqrt and fixes for old ones.
-
-commit 527a4b663c487cd9222ee2e6917e330ff9a130a1
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Tue Apr 22 12:38:53 2008 -0400
-
- Rename ambiguously-worded autoload spec
-
-commit 3e6f16c41569dbba291bc3cececf137fc8952ee2
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Tue Apr 22 12:31:17 2008 -0400
-
- Change to a significand-and-exponent implementation.
-
- * Update spec tags.
-
-commit f1b2bf51042ca563ca74a9cf83db0e46a1bfabce
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Tue Apr 22 09:54:53 2008 -0400
-
- Fix BigDecimal#zero, update spec tags. Also make #precs deal correctly with lowercase exponents.
-
-commit d0171de114e777f07a3e62972663475dd7747b05
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Tue Apr 22 09:24:06 2008 -0400
-
- Implement BigDecimal#precs.
-
- * Get #precs working. This will be less tortured once I implement a significand-and-exponent format.
- * Update spec tags.
-
-commit e1fc7c6dc4c02c1763947c34d05f894661a84525
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Tue Apr 22 01:30:10 2008 -0400
-
- Continue implementing bits of #inspect and updating spec tags.
-
-commit e4371f120c9c5c3c88a26d5f24f0d3ab888c954f
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Tue Apr 22 01:24:14 2008 -0400
-
- Implement BigDecimal#==/eql? and the beginnings of #inspect.
-
- * Find a way of implementing the equality test that satisfies the specs.
- * Don't be so baroque in parsing strings in constructor.
- * Update spec tags.
- * Fix regression in abs_spec.
- * Start implementing #inspect. Not really ready for prime time yet.
-
-commit 0494c1c35582381345194c76f7384eb9044797fc
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Tue Apr 22 00:41:03 2008 -0400
-
- Start implementing BigDecimal#sign and #zero?.
-
- * Clean up specs for #sign.
- * Write some initial code to get these working. Not all there yet.
-
-commit 3c071b5f921898d87437803a500535b639d465ef
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Mon Apr 21 23:43:10 2008 -0400
-
- Get BigDecimal#abs working.
-
- * Implement the function.
- * Improve the spec.
-
-commit 054582f3b89d757f033cd5f09cbf90fa08ad81d6
-Author: MenTaLguY <mental@rydia.net>
-Date: Mon Apr 21 22:32:42 2008 -0400
-
- fix linked actors spec (sort of)
-
-commit d7a7d0c4d0d83d7e69216c96a249c4091fe75323
-Author: MenTaLguY <mental@rydia.net>
-Date: Mon Apr 21 22:28:29 2008 -0400
-
- fix up registration spec
-
-commit 645784c3d39f776f583874e7c9244ff3de64cfe7
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Mon Apr 21 19:56:51 2008 -0400
-
- Update tags on failing specs.
-
-commit 960faf5382d90db376ff14bb836463f1860a4b62
-Merge: 2e2150f... 046ba62...
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Mon Apr 21 18:46:45 2008 -0400
-
- Merge branch 'master' of git@git.rubini.us:code
-
-commit 046ba622836321f487f241c145a3bdf0968f0a67
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Mon Apr 21 18:44:50 2008 -0400
-
- Specs for failing Module#autoload case (replicates a scenario from Merb)
-
-commit 18a2a26fa511d4943a724e27ce09e5855a257e90
-Merge: 1f5f4b5... 991c6e6...
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Mon Apr 21 14:15:07 2008 -0400
-
- Merge branch 'master' of git://git.rubini.us/code
-
- Conflicts:
-
- lib/bigdecimal.rb
- spec/ruby/1.8/library/matrix/diagonal_spec.rb
- spec/ruby/1.8/library/matrix/element_reference_spec.rb
- spec/ruby/1.8/library/matrix/shared/identity.rb
- spec/ruby/1.8/library/matrix/shared/transpose.rb
-
-commit edd397c82a924e406eabbcd7e84243d94f8e8067
-Author: Federico Builes <federico.builes@gmail.com>
-Date: Sun Apr 20 18:11:23 2008 -0500
-
- Adds MinGW to the IO#popen spec guard
-
-commit 10df9f89189637b2c5a54b01a88eca6c9fbb4601
-Author: Adam Wiggins <adam@heroku.com>
-Date: Sun Apr 20 14:53:41 2008 -0700
-
- IO.popen specs for reading and writing to pipes
-
-commit 3f70eceb3b9415a14f602c5b96121a459dca1e67
-Author: Brian Ford <bford@engineyard.com>
-Date: Sat Apr 19 22:32:28 2008 -0700
-
- Fix silly typo in Numeric#quo specs.
-
-commit 6101a4992ddc15c0140f4d7702cf88d2d3a2ac53
-Author: Brian Ford <bford@engineyard.com>
-Date: Sat Apr 19 22:23:14 2008 -0700
-
- Guard affected specs with conflicts_with :Rational.
-
-commit 354445f4d20ec66f207d65d1ccceb681bba7fff0
-Author: Federico Builes <federico.builes@gmail.com>
-Date: Sat Apr 19 14:23:14 2008 -0500
-
- Clarifying some of the Matrix specs
-
- * Fixes two errors introduced by 28700c5cf7
-
-commit 2f5ca541fc08f0c033bc6541c72962228ea607de
-Author: Eero Saynatkari <projects@kittensoft.org>
-Date: Sat Apr 19 15:07:49 2008 -0400
-
- Compiler specs' TestGenerator relies on broken #=== semantics, comply.
-
-commit 37cc9d4d6eb3442814ecc51845f025f464da64f7
-Author: Eero Saynatkari <projects@kittensoft.org>
-Date: Sat Apr 19 15:05:30 2008 -0400
-
- Specs for default #=== and its relationship with #== and #equal?
-
- * Rubinius deviates to not check object id directly.
-
-commit 28700c5cf7630be59877122e6470c42622b7365a
-Author: Federico Builes <federico.builes@gmail.com>
-Date: Sat Apr 19 13:53:33 2008 -0500
-
- Additional specs for Matrix
-
- * Some of the constructors in Matrix keep referencing the original arguments after creation, these specs cover those cases.
-
-commit 12b0bc93e5a6b328ad0968c03c47af71f671aae2
-Author: Federico Builes <federico.builes@gmail.com>
-Date: Sat Apr 19 13:06:04 2008 -0500
-
- Replace object_id for equal? in Matrix specs
-
-commit ae377f0e56b8f31356935b3ac0800f561b2d1b2c
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Sat Apr 19 14:49:34 2008 +0200
-
- Fix File::Stat#uid specs
-
-commit 2e01a86a3977fe87f4f0734e50598b41f66f29d7
-Author: MenTaLguY <mental@rydia.net>
-Date: Sat Apr 19 03:24:32 2008 -0400
-
- Gutted and reworked Actor, following Erlang more closely.
-
-commit de40303e17e2de1e7980564b43ee162c5080afa6
-Author: Federico Builes <federico.builes@gmail.com>
-Date: Sat Apr 19 01:05:43 2008 -0500
-
- Fixes Matrix#clone specs for MRI
-
- * Makes sure the values (not the references) of the original rows are copied.
-
-commit 2b3a44158ae93ab5883da22e5f36df92485f3ad4
-Author: Federico Builes <federico.builes@gmail.com>
-Date: Fri Apr 18 22:47:15 2008 -0500
-
- Fixes a few things inside the Matrix specs.
-
- * Removes some of the "needs to be reviewed for completeness" messages.
- * Changes some of the descriptions
-
-commit 3be265a93a75b6a0267b1770f8cad671c4244671
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Fri Apr 18 12:26:29 2008 -0400
-
- Matrix.unit, one more alias for .identity.
-
- Signed-off-by: Federico Builes <federico.builes@gmail.com>
-
-commit 57aa8ba9a1dbdf62e9cf644bbde4603b841ffc76
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Fri Apr 18 12:25:55 2008 -0400
-
- Name spec correctly.
-
- Signed-off-by: Federico Builes <federico.builes@gmail.com>
-
-commit 3390dc4c6725d996eeb0c2e4ec73949bc0be2290
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Fri Apr 18 12:23:54 2008 -0400
-
- Specs for Matrix.scalar and .identity/I.
-
- Signed-off-by: Federico Builes <federico.builes@gmail.com>
-
-commit 958ca1faa1dc60ce591b4b2f768f22ac7f6cb56f
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Fri Apr 18 12:22:09 2008 -0400
-
- Move the "needs to be reviewed" indicator to the right place.
-
- Signed-off-by: Federico Builes <federico.builes@gmail.com>
-
-commit bf3eab630654eaaca9256850d258343e3024989e
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Fri Apr 18 12:03:45 2008 -0400
-
- Use size functions instead of constants.
-
- Signed-off-by: Federico Builes <federico.builes@gmail.com>
-
-commit 3981c931e7f4fde730d51614d40e44b9209347f9
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Fri Apr 18 11:58:22 2008 -0400
-
- Specs for Matrix#clone and #transpose (alias #t).
-
- Signed-off-by: Federico Builes <federico.builes@gmail.com>
-
-commit 72e1ea8900a638c796de9e715c5dffcf4ac90546
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Fri Apr 18 01:27:06 2008 -0400
-
- Basic specs for Matrix.zero.
-
- Signed-off-by: Federico Builes <federico.builes@gmail.com>
-
-commit f5d294ad941c477060e9b5d2329790db7e1e5700
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Fri Apr 18 01:20:27 2008 -0400
-
- Move before block to a clearer place.
-
- Signed-off-by: Federico Builes <federico.builes@gmail.com>
-
-commit b6bc5b224ade56ab96f3585b6b1c25e6dd5e1ad5
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Fri Apr 18 01:19:27 2008 -0400
-
- Write specs for Matrix.diagonal.
-
- Signed-off-by: Federico Builes <federico.builes@gmail.com>
-
-commit b4d056baa33a2181ab64c065ad1eb4adebcfaddf
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Fri Apr 18 01:11:11 2008 -0400
-
- Some initial specs for Matrix#[] and Matrix.[].
-
- These are in the same file because of coding conventions, but they probably should not be since .[] is a constructor and has very little in common conceptually with #[], which is a subscript operator.
-
- Signed-off-by: Federico Builes <federico.builes@gmail.com>
-
-commit 5476d836577c0fbdbda097762862cf153ffb5e07
-Author: Brian Ford <bford@engineyard.com>
-Date: Fri Apr 18 18:35:34 2008 -0700
-
- Some method profiles of data provided by John Lam.
-
- Run these as follows:
-
- bin/mspec -w rails.yaml spec/ruby
-
- We'll be adding our own trace script, but for now, these
- are snapshots of methods used by Rails loading a simple
- "hello world" controller. The rails.yaml file is core
- methods. The core.yaml file is generated by NameMap from
- mspec/bin/name_map.rb.
-
-commit 24c71675cc63c86832ef8bc55d2f0167dff53073
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Fri Apr 18 17:24:08 2008 -0400
-
- First stab at BigDecimal.
-
- * A skeleton of a somewhat naïve implementation of BigDecimal.
- * Updated spec tags.
-
-commit 1f5f4b59400b8b11df83b274efc8ce98186220ef
-Merge: 9d21b0e... 968a0ec...
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Fri Apr 18 17:28:02 2008 -0400
-
- Merge branch 'bigdecimal'
-
-commit 9d21b0e890a9394658689af2bdee7e449cd2200b
-Merge: c3f3507... 1a08506...
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Fri Apr 18 17:25:09 2008 -0400
-
- Merge branch 'master' of git://git.rubini.us/code
-
-commit 968a0ecda8477b33ceab2e7d0c7e7d084a105bdb
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Fri Apr 18 17:24:08 2008 -0400
-
- First stab at BigDecimal.
-
- * A skeleton of a somewhat naïve implementation of BigDecimal.
- * Updated spec tags.
-
-commit 1f410d918a59b9b49e87a407cc8fba4bbf342a79
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Fri Apr 18 22:34:53 2008 +0200
-
- Fix a bunch of specs and minor issues in File::Stat
-
- Specs for File::Stat#<=>, File::Stat#ino, File::Stat#inspect,
- File::Stat#mode, File#Stat.initialize and some minor bugfixes
- such as the fact that File::Stat needs to include Comparable
- (like MRI).
-
-commit d6f2c6995941762878f4b777a39b0c23ea654605
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Thu Apr 17 22:30:36 2008 +0200
-
- Remove specs for non-existent File::Stat#initialize_copy
-
-commit c3f350716a35cb869b3ea0289c0e404d07b8819f
-Merge: 810afff... b861102...
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Fri Apr 18 16:18:34 2008 -0400
-
- Merge branch 'master' of git://git.rubini.us/code
-
-commit 72101783ec6e66a4f9ac3f9c90f7e8f5b67058ec
-Author: Ryan Davis <rdavis@engineyard.com>
-Date: Tue Apr 8 17:05:26 2008 -0700
-
- Reworked masgn specs to evaluate L2R and assign L2R. excluded.
-
-commit 4e4bec628b21938617bdfa5a2ef17aedf02c112c
-Author: Ryan Davis <rdavis@engineyard.com>
-Date: Tue Apr 8 15:17:00 2008 -0700
-
- trailing whitespace is killing me... evan\! fix your editor\!
-
-commit 810afffa2e549048947c07b30d77be255db42d73
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Fri Apr 18 12:26:29 2008 -0400
-
- Matrix.unit, one more alias for .identity.
-
-commit 2c84f77535d677a42bee93759c77f79c2cdd4d93
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Fri Apr 18 12:25:55 2008 -0400
-
- Name spec correctly.
-
-commit 762f5ee0f7ba4234847c695c92e3ed27dd05e134
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Fri Apr 18 12:23:54 2008 -0400
-
- Specs for Matrix.scalar and .identity/I.
-
-commit b68295e0046a2eb1fb911ea891d6e0a29174ea30
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Fri Apr 18 12:22:09 2008 -0400
-
- Move the "needs to be reviewed" indicator to the right place.
-
-commit 4b6e1097feafe2247e59d6004a36bb0987734138
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Fri Apr 18 12:03:45 2008 -0400
-
- Use size functions instead of constants.
-
-commit 2086f0c1f1f899f2e41307a5434a5bb6446e20a2
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Fri Apr 18 11:58:22 2008 -0400
-
- Specs for Matrix#clone and #transpose (alias #t).
-
-commit 2939c55b2e9f38b5115b98429de97bc4fff6f165
-Merge: a47f2b8... 42d3212...
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Fri Apr 18 02:09:07 2008 -0400
-
- Merge branch 'master' of git://github.com/evanphx/rubinius
-
-commit a47f2b852ca309a68b687157a6cd973716328887
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Fri Apr 18 01:27:06 2008 -0400
-
- Basic specs for Matrix.zero.
-
-commit aa3b2eeef70cb8967ef6c92ee24a226c2d1202c1
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Fri Apr 18 01:20:27 2008 -0400
-
- Move before block to a clearer place.
-
-commit ca6ac1e59ddb268b388975a2fb5b11e6026e65c8
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Fri Apr 18 01:19:27 2008 -0400
-
- Write specs for Matrix.diagonal.
-
-commit b24216d8b0ecfba6888f909415e2523eaed2aeb2
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Fri Apr 18 01:11:11 2008 -0400
-
- Some initial specs for Matrix#[] and Matrix.[].
-
- These are in the same file because of coding conventions, but they probably should not be since .[] is a constructor and has very little in common conceptually with #[], which is a subscript operator.
-
-commit 9313f29ed952f604e0d124ced38ee930b5780b27
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Thu Apr 17 22:35:43 2008 -0400
-
- New spec tags for Complex#%.
-
-commit 08f316de96c94b7d4865d77873327deddeabb664
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Thu Apr 17 22:32:08 2008 -0400
-
- More specs for Complex.
-
- * Specs for <=>, conj/conjugate, to_s.
-
-commit 973c304cc16fa6b78dba31de11b151da2daae762
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Thu Apr 17 22:09:20 2008 -0400
-
- More specs for Complex
- * Complex#abs, abs2, angle, arg, and %. Not sure that % is correctly specified.
-
-commit e32b26694277065fe28f138dca837b8c0509c735
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Thu Apr 17 21:17:26 2008 -0400
-
- More specs for Complex.
-
- * Write specs for * and /.
- * Rewrite + and - to use alternate constructor syntax.
-
- Signed-off-by: Marnen Laibow-Koser <marnen@marnen.org>
-
-commit 0cbf88a6c61e477f4b9a7758a9fab1258efbf30f
-Author: Marnen Laibow-Koser <marnen@marnen.org>
-Date: Thu Apr 17 20:46:04 2008 -0400
-
- Write some specs for Complex.
-
- * Basic specs for Complex.new, Complex.new!, Complex#+, and Complex#-.
-
- Signed-off-by: Marnen Laibow-Koser <marnen@marnen.org>
-
-commit 71909e78b8d77f7e48d306e30f51fbc21b5fbefb
-Author: Brian Ford <bford@engineyard.com>
-Date: Thu Apr 17 15:26:53 2008 -0700
-
- Reorganize and fix Matrix specs.
-
-commit 5a9325457696dfba3c410c0adcbdec706ecda3bf
-Author: Brian Ford <bford@engineyard.com>
-Date: Thu Apr 17 12:49:45 2008 -0700
-
- Added spec templates and incomplete tags for CGI.
-
-commit d62de6b4096a9b3bd3fda197b70d6e603596e865
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Thu Apr 17 21:12:08 2008 +0200
-
- More detailed speecs for BigDecimal#new
-
-commit ebd6fb8f879f94ff51b74cb4e76080fad7b66cb5
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Thu Apr 17 19:55:31 2008 +0200
-
- More detailed specs for BigDecimal's <, <=, >, >=, <=>.
-
-commit 8caef40cbe873dc2825bc0ba1e66f983b8219cca
-Author: MenTaLguY <mental@rydia.net>
-Date: Thu Apr 17 01:16:25 2008 -0400
-
- add tag object argument to send_in_*
-
-commit 0596b1aca45a85de5f3d727632585da924fd3eb0
-Author: Matthias Reitinger <m.reitinger@mytum.de>
-Date: Sat Apr 12 10:11:13 2008 +0200
-
- New specs for BigDecimal.new.
-
- Signed-off-by: Marius Nuennerich <marius@nuenneri.ch>
-
-commit 5c176e50fe962de1095a75221b4d63e75acc505f
-Author: Benjamin Stiglitz <ben@tanjero.com>
-Date: Wed Apr 16 11:32:18 2008 -0700
-
- Cleaned up Numeric#div spec
-
- The spec names are no longer quite as atrocious; the spec output is now fairly
- readable. The different Integer-Float quotient permutations are now correctly
- specified as well.
-
- Signed-off-by: Brian Ford <bford@engineyard.com>
-
-commit e1406b19c51bfca5f6936d143087043316c68c13
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Tue Apr 15 20:07:48 2008 -0400
-
- Specs for Kernel#p behaviour.
-
- * Args vs. no args.
- * Record separator is not taken into account.
-
-commit 30c717e1736b65a852df501f71e320599fc17786
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Tue Apr 15 21:32:13 2008 +0200
-
- Fix typo in File.grpowned? spec
-
-commit 1bc17a0b4c8f19b84ffdd0b17ec24243a1df6092
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Tue Apr 15 21:31:02 2008 +0200
-
- Fix File.grpowned? and it's spec
-
-commit f49cf4d0319b5772ede7bcddd763c691d5253b18
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Tue Apr 15 20:44:18 2008 +0200
-
- Update tags for implemented File.grpowned? specs
-
-commit ea19fb07cb7b789165aec5da0f571345b96f1f0f
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Tue Apr 15 20:41:02 2008 +0200
-
- Spec File::Stat#grpowned? and implement File.grpowned?
-
-commit c411b15b9f94fec21b02a9208cbae4b42452431d
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Tue Apr 15 20:19:24 2008 +0200
-
- Properly rename File::Stat#dev_major and File::Stat#dev_minor specs
-
-commit 26ba3ad30cd726b058cd76f23dc7a79555be724e
-Author: Charles Oliver Nutter <charles.nutter@sun.com>
-Date: Tue Apr 15 10:25:44 2008 -0700
-
- Quarantine the cvar-related instance_eval spec for now; it's not clean.
-
-commit d72c609ce4567d7a7fdfd2ee4713ac07033c81db
-Author: Marius Nuennerich <marius@nuenneri.ch>
-Date: Mon Apr 14 20:13:38 2008 +0200
-
- Use EnvSpecs where possible
-
-commit 8ccdf2d612f15515837095e2e4a570861024294c
-Author: Marius Nuennerich <marius@nuenneri.ch>
-Date: Mon Apr 14 17:42:36 2008 +0200
-
- Use EnvSpecs module for platform dependent stuff
-
-commit 130e4bdb1d9fa9512dfe45d4ff4d718096683cdb
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Mon Apr 14 19:45:24 2008 +0200
-
- Fix specs for a bunch of File::Stat methods and implement File::Stat#<=>
-
- Created specs for atime, blksize, blocks, ctime, mtime and <=>
-
-commit e5aa89ff13128afb9b43ad77678792aeae4d48ea
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Sat Apr 12 17:54:57 2008 +0200
-
- Remove tag for fixed File#lstat
-
-commit 21cd4a10833ef3bdda1593423faccb334de16536
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Sat Apr 12 17:52:33 2008 +0200
-
- Remove unneccary spec placeholders for File#stat / File#lstat
-
- The shared spec already tests this behavior. With the new added spec
- for the difference between the two, File.stat / File.lstat is pretty
- well covered for now.
-
-commit eacb4f8a4d0ba606458a5756ddd6f2ce723a3dfa
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Sat Apr 12 17:45:55 2008 +0200
-
- Specced different behavior between File.stat and File.lstat
-
-commit 4ae163810074effc068babf538f004e9ff117156
-Author: Adam Gardiner <adam.b.gardiner@gmail.com>
-Date: Mon Apr 14 16:49:04 2008 +1000
-
- Refactor Debugger interface into a CmdLineInterface class
-
-commit e61241498f6ca63b7d5e50e94a70456bc40e929b
-Author: Adam Gardiner <adam.b.gardiner@gmail.com>
-Date: Mon Apr 14 14:17:03 2008 +1000
-
- Breakpoint clean-up
-
-commit ae738f21979edf727437438b992629dd0b59a42e
-Author: MenTaLguY <mental@rydia.net>
-Date: Sun Apr 13 16:14:34 2008 -0400
-
- elminate Mailbox#clear; difficult to implement with sane semanitics
-
-commit 76385484049e47f53b840ddf3c0dfe9e365ca8cf
-Author: Federico Builes <federico.builes@gmail.com>
-Date: Sat Apr 12 16:39:19 2008 -0500
-
- More specs for REXML::Element
-
-commit 00547bc562c359ddac13d04a5c955ee25171bcb4
-Author: Matthias Reitinger <m.reitinger@mytum.de>
-Date: Sat Apr 12 11:15:12 2008 +0200
-
- Fixed incorrect check for object equality in BigDecimal#nonzero? spec
-
- One should not use == to check if the method returns self, but equal?
-
- Signed-off-by: Federico Builes <federico.builes@gmail.com>
-
-commit e8403792167c86f120ce7bdcd1e2c7ce1bc31fea
-Author: Matthias Reitinger <m.reitinger@mytum.de>
-Date: Sat Apr 12 11:31:25 2008 +0200
-
- Eliminated use of to_s to check for NaN in BigDecimal specs
-
- Changed "to_s.should == 'NaN'" to "nan?.should == true"
-
- Signed-off-by: Federico Builes <federico.builes@gmail.com>
-
-commit 5883dd78ad92031c920bb9ee2b703702969a5854
-Author: Charles Oliver Nutter <charles.nutter@sun.com>
-Date: Sat Apr 12 09:42:11 2008 -0500
-
- A few more instance_eval specs, for non-immediate numerics and cvars.
-
-commit e8fd8e696d5487fa698a9a8b1bab2fb54b420133
-Author: Charles Oliver Nutter <charles.nutter@sun.com>
-Date: Sat Apr 12 08:28:41 2008 -0500
-
- Added instance_eval spec for defining methods under immediates.
-
-commit c23b365a95862cd438e6228929a3a4e935d60de9
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Fri Apr 11 22:09:06 2008 +0200
-
- New rubypsecs for BigDecimal#fix and #frac.
-
-commit 6b6b63ebedb61466b4f04f510bf859574efec7d9
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Fri Apr 11 20:07:07 2008 +0200
-
- New rubyspecs for Bigdecimal#floor and #ceil.
-
-commit 75e9118aea32baaeec82efedb5106c63bb0eef44
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Fri Apr 11 17:50:36 2008 +0200
-
- Corrected Bigdecimal specs since they were missing "should" statements. :)
-
- Also, added some more cases.
-
-commit 18fafb2e1f653887fdd3cdef693448d9b2bea29e
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Fri Apr 11 17:21:02 2008 +0200
-
- New rubyspecs for BigDecimal's #power, #** and #exponent.
-
-commit 35e32daa38c7df385aac99f7b709a4038141faaa
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Fri Apr 11 13:41:13 2008 +0200
-
- New and updated rubyspecs for BigDecimal#precs.
-
-commit e0172d4eee7a775ab53562477997855ed66615a7
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Fri Apr 11 12:31:22 2008 +0200
-
- More rubyspecs for BigDecimal#split and some corrections for older ones.
-
-commit 37d312770700da5eb124fdce7a7b1687c2d9b839
-Author: Adam Gardiner <adam.b.gardiner@gmail.com>
-Date: Fri Apr 11 13:55:00 2008 +1000
-
- Get breakpoint handling working properly
-
-commit 498b95a720e98b70b56af9dfd2c1ba20c0bf89c3
-Author: Adam Gardiner <adam.b.gardiner@gmail.com>
-Date: Wed Apr 9 17:23:56 2008 +1000
-
- Make ISeq#decode return symbols rather than objects by default
-
-commit b8bda0546cdb9ac04ae629f13ccfce5f474e6f2c
-Author: Adam Gardiner <adam.b.gardiner@gmail.com>
-Date: Mon Mar 17 14:33:45 2008 +1100
-
- Ensure breakpoint original instruction is correct
-
- When multiple breakpoints are set at the same location,
- only the first breakpoint sees the original instruction.
- This commit ensures the BreakpointTracker detects such
- situations, and updates the breakpoint to set the correct
- oringinal instruction to use.
-
-commit 2700924f23e0283a059583f9e92188b1c3c4f220
-Author: Adam Gardiner <adam.b.gardiner@gmail.com>
-Date: Thu Mar 13 17:20:49 2008 +1100
-
- Reorganize Breakpoint class hierarchy
-
- Refactor Breakpoint class hierarchy in preparation for
- adding PersistentBreakpoint and BreakpointRestorer classes.
-
-commit bfa69d930c38897df18b656d7b86f0b549bed57f
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Fri Apr 11 03:01:37 2008 +0200
-
- Some more test cases for BigDecimas#finite? and #nonzero?.
-
-commit 71a4b0a51ea4da0c41d7b096aa7b88deb8d0d049
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Fri Apr 11 02:42:33 2008 +0200
-
- A bit more rubyspecs for BigDecimal#sub and #to_s.
-
-commit 8ff9ae455c6c7f4b38f3b4dcbdc6c677759f13e2
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Fri Apr 11 01:35:16 2008 +0200
-
- New rubyspecs for BigDecimal#truncate.
-
-commit f0a5c13f218d1e2187dfff09bd27cbd6dde544ca
-Author: Brian Ford <bford@engineyard.com>
-Date: Thu Apr 10 15:09:55 2008 -0700
-
- Converted VMActor specs to dir/files. Added incomplete tags.
-
-commit df74b0fd98597b51d4c1d51ae09706d51e1a5d3c
-Author: Brian Ford <bford@engineyard.com>
-Date: Thu Apr 10 15:01:08 2008 -0700
-
- Converted Mailbox specs to dir/files. Added incomplete tags.
-
-commit 29d223d8bfcc36edc16db58d50f8186905df773a
-Author: Brian Ford <bford@engineyard.com>
-Date: Thu Apr 10 14:49:52 2008 -0700
-
- Converted Actor specs to dir/files. Added incomplete tags.
-
-commit 08ab8db440cfdaa7e06b19a0d88750678d4fccbf
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Thu Apr 10 22:09:39 2008 +0200
-
- New rubyspecs for bigdecimal, and excludes.
-
-commit b76a9e964899348d667181d288c5d4ec0e422c9f
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Thu Apr 10 19:33:03 2008 +0200
-
- One rubyspec for the class definition: def nil:Foo; end
-
-commit c526f5744ece40e312340556991ee54e4504ebcd
-Author: Brian Ford <bford@engineyard.com>
-Date: Thu Apr 10 00:53:06 2008 -0700
-
- Processed Rational, Complex, Matrix with mkspec.
-
-commit 3de6f530c42bdca8c9b1202e60d0d14850024d15
-Author: Brian Ford <bford@engineyard.com>
-Date: Thu Apr 10 00:27:40 2008 -0700
-
- Processed IO with mkspec. Added incomplete tags.
-
-commit faaf8bdb8893f71234d7e2fab07aa11d6c556384
-Author: Brian Ford <bford@engineyard.com>
-Date: Thu Apr 10 00:17:35 2008 -0700
-
- Clean up especially bad whitespace in File specs.
-
-commit fedda8f6865c6cdb07c7599606204f0700042574
-Author: Brian Ford <bford@engineyard.com>
-Date: Thu Apr 10 00:09:56 2008 -0700
-
- Processed File specs with mkspec. Added incomplete tags.
-
-commit 09f6f1b5138b7ca1d276a8c68ee6bf1cba7691b7
-Author: Brian Ford <bford@engineyard.com>
-Date: Wed Apr 9 23:42:40 2008 -0700
-
- Processed Kernel specs with mkspec. Added incomplete tags.
-
-commit e3ca2e3e077c0e026b96e1e68808b95d44233cf5
-Merge: cf0c855... 4d0d1f6...
-Author: Thomas Lachmann <thomas_lachmann@gmx.de>
-Date: Thu Apr 10 02:48:31 2008 +0200
-
- Merge branch 'master' into bigdecimal_specs
-
-commit cf0c8552f31cfd856822c8aa43a5d9d265481ac0
-Author: Thomas Lachmann <thomas_lachmann@gmx.de>
-Date: Thu Apr 10 02:40:22 2008 +0200
-
- Next bunch of specs for Bigdecimal.
-
-commit 4d0d1f6b98ac2dafa487ece31512443a07bbc928
-Author: Marius Nuennerich <marius@nuenneri.ch>
-Date: Wed Apr 9 23:42:10 2008 +0200
-
- Fix ENV specs
-
- * Try to avoid `env`
-
-commit dfcc69ea8bd78e9e463defdef3b4529a5af40bb5
-Merge: 75e6ccd... 6a50f0d...
-Author: Marius Nuennerich <marius@nuenneri.ch>
-Date: Wed Apr 9 22:26:26 2008 +0200
-
- Merge branch 'master' of git://git.rubini.us/code
-
-commit 75e6ccd48bce9e0e939a0ff1d484f14a029969f9
-Author: Marius Nuennerich <marius@nuenneri.ch>
-Date: Wed Apr 9 22:26:11 2008 +0200
-
- Fixes for ENV
-
- * Add specs
- * Add some missing methods to ENV
-
-commit 6a50f0d2f5146901fe96fe86802df155c9266a21
-Author: Thomas Lachmann <thomas_lachmann@gmx.de>
-Date: Wed Apr 9 21:11:05 2008 +0200
-
- Fixed failures for BigDecimal#specs.
-
-commit 09bc62e39a8b92c25aeb6287f9fbf4e9cd2b9a6f
-Author: Thomas Lachmann <thomas_lachmann@gmx.de>
-Date: Wed Apr 9 19:55:45 2008 +0200
-
- Bunch of specs for BigDecimal.
-
-commit c281add79d621f6327740109895c624dd25a2e1b
-Author: Federico Builes <federico.builes@gmail.com>
-Date: Wed Apr 9 09:13:29 2008 -0500
-
- Cleaning up UPSocket#send specs
-
- * Got rid of the weird exception catching
- * DRY things up a bit with before :each
-
-commit 8ebefe3c0a61b7aab8ac3d0ae9768c35b657cdb6
-Author: Federico Builes <federico.builes@gmail.com>
-Date: Wed Apr 9 09:11:43 2008 -0500
-
- Adding spec helpers to REXML specs
-
-commit e3064084efbbac1147d477435010d933ce101413
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Tue Apr 8 22:20:43 2008 -0400
-
- Amended spec wording for Singleton._load slightly. Updated exclude.
-
-commit 23e621625b95e0db82bd406a5eb8fa7324e41a6e
-Author: Chris Shea <chris@tie-rack.org>
-Date: Tue Apr 8 15:49:11 2008 -0600
-
- Create spec for Marshal.load of Singleton instance
-
- Signed-off-by: Eero Saynatkari <rubinius@projects.kittensoft.org>
-
-commit eec07baa07d591059c64f32c0ddef169cfcccaef
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Tue Apr 8 20:20:02 2008 -0500
-
- Thread#wakeup deadlock for MRI marked as ruby_bug
-
-commit dbb744d9692c2432d7aebecac17365125efe9087
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Tue Apr 8 20:02:08 2008 -0500
-
- spec for wakeup which causes MRI to deadlock when it shouldn't
-
-commit 208a7df6ec2d3c8f550a7ac24db849e593cdc9f3
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Tue Apr 8 17:58:15 2008 -0500
-
- specs for Thread::list
-
-commit f6f307e75e49cdf597b0b3755ab214c6fc1950dd
-Author: Thomas Lachmann <thomas_lachmann@gmx.de>
-Date: Wed Apr 9 00:54:34 2008 +0200
-
- specs for BigDecimal.new and BigDecimal#zero? (plus tag files).
-
- Signed-off-by: Eero Saynatkari <rubinius@projects.kittensoft.org>
-
-commit 5b1f2043f70b0088f1c32be79eeaa8179c2210a6
-Author: Jeff Rose <jeff@rosejn.net>
-Date: Wed Apr 9 00:44:27 2008 +0200
-
- Specs for Actor linking and registration, and Mailbox timeouts.
-
- Signed-off-by: Eero Saynatkari <rubinius@projects.kittensoft.org>
-
-commit 4eea149d3d503c121fb7c65115e374838fff8c8a
-Author: Ryan Davis <rdavis@engineyard.com>
-Date: Tue Apr 8 14:55:18 2008 -0700
-
- Added extra Array subclass dup spec
-
-commit 783a884931b718b8fa65dd9768fbebd8a0d1ac0c
-Author: Ryan Davis <rdavis@engineyard.com>
-Date: Tue Apr 8 14:18:45 2008 -0700
-
- minor cleanup
-
-commit 0e047cc97aa6a5acd7193bdde1139f6a89f108b8
-Author: Ryan Davis <rdavis@engineyard.com>
-Date: Tue Apr 8 14:18:27 2008 -0700
-
- minor cleanup
-
-commit f4797827393e0d9d0e5df5aa5184ecebb066d766
-Author: Matthias Reitinger <m.reitinger@mytum.de>
-Date: Tue Apr 8 17:08:32 2008 +0200
-
- Extended Symbol#inspect spec and reworked Symbol#inspect to fulfill them
-
- Signed-off-by: Eero Saynatkari <rubinius@projects.kittensoft.org>
-
-commit b3c3a5f60177f9c52725b6cacf019412d2c747ea
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Tue Apr 8 17:29:58 2008 -0400
-
- Excludes for BigDecimal specs.
-
-commit b7cd3c38d146a7833ef1d426ea8acd4ee4cb09bf
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Tue Apr 8 17:13:48 2008 -0400
-
- Switched #requires around to have access to #pretty_inspect.
-
-commit aba428095e09ead8ed66895b175e5f3673c4310e
-Author: Thomas Lachmann <thomas_lachmann@gmx.de>
-Date: Tue Apr 8 17:45:13 2008 +0200
-
- Spec for BigDecimal#to_f.
-
- Signed-off-by: Eero Saynatkari <rubinius@projects.kittensoft.org>
-
-commit 20a5789f9dc4e6d30dffb594476b354e4aeee201
-Author: Thomas Lachmann <thomas_lachmann@gmx.de>
-Date: Tue Apr 8 17:21:39 2008 +0200
-
- Spec for BigDecimal#finite?
-
- Signed-off-by: Eero Saynatkari <rubinius@projects.kittensoft.org>
-
-commit 896609e7ae8ee12c72e4e3ce86897c1f8b98f3fb
-Author: Ryan Davis <rdavis@engineyard.com>
-Date: Tue Apr 8 02:03:22 2008 -0700
-
- overlooked 2 specs
-
-commit 77774ed4300d5245c58dbcc686cd72dc48f08a1f
-Author: Ryan Davis <rdavis@engineyard.com>
-Date: Tue Apr 8 02:00:24 2008 -0700
-
- Added a bunch of specs to String#to_f
-
-commit 1b91113c3e8fb46a0d355cae9000ee4c82f95ac3
-Author: Federico Builes <federico.builes@gmail.com>
-Date: Mon Apr 7 21:46:17 2008 -0500
-
- More specs for REXML
-
-commit 2460839e3fbe2967b9df70db3de33b2a102b9a44
-Author: Brian Ford <bford@engineyard.com>
-Date: Mon Apr 7 12:19:40 2008 -0700
-
- Reworked how MSpec handles config files. Use 'set :sym, value' now.
-
-commit 67d3869e9b3fef6d47727206d02814da410e02fc
-Author: Jeff <rosejn@warp.(none)>
-Date: Mon Apr 7 15:04:09 2008 +0200
-
- Adding specs for Mailbox and Actor, and renaming the VMActor describe to match the standard scheme.
-
- Signed-off-by: Charles Comstock <dgtized@gmail.com>
-
-commit 7391c1fbc02966165de03724c42fc1d5243ac99f
-Author: Marius Nuennerich <marius@nuenneri.ch>
-Date: Sun Apr 6 22:29:22 2008 +0200
-
- repair UDPSocket spec
-
- Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
-
-commit 5a205207faad0a85271bfcb459390793702c4143
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Sat Apr 5 04:54:21 2008 -0400
-
- Partially revert "Add spec files for cgi.rb."
-
- This partially reverts commit e2714f2fd2d8825ac8af761a5a4545e4d0731735.
-
- Conflicts, left these files:
-
- spec/ruby/1.8/library/cgi/escapeHTML_spec.rb
- spec/ruby/1.8/library/cgi/escape_spec.rb
- spec/ruby/1.8/library/cgi/rfc1123_date_spec.rb
- spec/ruby/1.8/library/cgi/unescapeHTML_spec.rb
- spec/ruby/1.8/library/cgi/unescape_spec.rb
-
-commit 22f3042377731cb6ff963b9e322b24014b286895
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Sat Apr 5 03:18:15 2008 -0400
-
- Added excludes for the CGI specs.
-
-commit 7b9f5a213c971636b663e992fcb8578888d27f52
-Author: makoto kuwata <kwa@kuwata-lab.com>
-Date: Sat Apr 5 13:03:59 2008 +0900
-
- Add spec file for CGI::rfc1123_date().
-
- Signed-off-by: Eero Saynatkari <rubinius@projects.kittensoft.org>
-
-commit 31edbd64bba7f352930ac04d51b63e72553796a9
-Author: makoto kuwata <kwa@kuwata-lab.com>
-Date: Sat Apr 5 13:03:14 2008 +0900
-
- Add spec files for CGI::escapeHTML() and CGI::unescapeHTML().
-
- Signed-off-by: Eero Saynatkari <rubinius@projects.kittensoft.org>
-
-commit fc321869d73f58dcfbb55ba374646c1568528004
-Author: makoto kuwata <kwa@kuwata-lab.com>
-Date: Sat Apr 5 13:01:33 2008 +0900
-
- Add spec files for CGI::escape() and CGI::unescape().
-
- Signed-off-by: Eero Saynatkari <rubinius@projects.kittensoft.org>
-
-commit e2714f2fd2d8825ac8af761a5a4545e4d0731735
-Author: makoto kuwata <kwa@kuwata-lab.com>
-Date: Sat Apr 5 12:44:57 2008 +0900
-
- Add spec files for cgi.rb.
-
- Signed-off-by: Eero Saynatkari <rubinius@projects.kittensoft.org>
-
-commit 2a1d0ad7e51ba52a918111d53be6a641c41a0445
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Fri Apr 4 22:21:47 2008 -0400
-
- Improved the *rest argument count spec a bit.
-
-commit e8053e4bb108cf877ac8fdafc104eb34bad671f0
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Fri Apr 4 20:38:23 2008 -0400
-
- Specs for unlimited argument count for *rest defns.
-
-commit 03e092e45015f8115f806e11460121c560e60b4b
-Author: Ryan Davis <rdavis@engineyard.com>
-Date: Fri Apr 4 17:54:25 2008 -0700
-
- Converted symbol spec to be generative, allowing easier pattern detection
-
-commit bbda617127a8ac319a58fa190d43b3a0d960d309
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Fri Apr 4 14:07:50 2008 -0500
-
- updated File#inspect tags
-
-commit 38eb679d6b6c5aef8bccb2139e681c926b3290c7
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Fri Apr 4 06:00:37 2008 -0400
-
- Specs for ~/ expansion in #require, #load. It has broken at some point.
-
-commit 2d600c01205fbb7ccd98e7f7a88ebcbd0e1d1d43
-Author: Paul Thornthwaite <tokengeek@gmail.com>
-Date: Fri Apr 4 08:43:42 2008 +0100
-
- Updated specs for Set library
-
- * Added specs for Set#subset and Set#proper_subset
- * Added specs covering empty sets and comparisons
- * Corrected spec string to include ? on superset method names
-
- Signed-off-by: Eero Saynatkari <rubinius@projects.kittensoft.org>
-
-commit 3a547c2b82434c64b72967ebd917fc063ff1317d
-Author: Brian Ford <bford@engineyard.com>
-Date: Thu Apr 3 23:16:18 2008 -0700
-
- Fixed GetoptLong specs to not depend on value of ARGV.
-
-commit 5dd9b0ecdddfd990d6387a0a7c70173ea0cededa
-Author: Brian Ford <bford@engineyard.com>
-Date: Wed Apr 2 23:27:04 2008 -0700
-
- Add config file for and rework MSpec runners.
-
-commit 773a13ed9005628e48ed146180041caa035f4072
-Author: David Yip <yipdw@member.fsf.org>
-Date: Thu Apr 3 03:18:48 2008 -0400
-
- Added spec: full contents of StringIO stream should be accessible after rewind.
-
- Spec tested against Ruby 1.8.6p111 and Ruby 1.8.6p114 on OS X 10.4.11.
-
- Signed-off-by: Eero Saynatkari <rubinius@projects.kittensoft.org>
-
-commit ba2ca41cb29ac08c94231a2383940464e6fd1c9d
-Author: Federico Builes <federico.builes@gmail.com>
-Date: Thu Apr 3 08:45:49 2008 -0500
-
- Updated tags for REXML specs
-
- Signed-off-by: Eero Saynatkari <rubinius@projects.kittensoft.org>
-
-commit 09c080bf33092b9d147d1b0a5de920fce8527fdc
-Author: Federico Builes <federico.builes@gmail.com>
-Date: Thu Apr 3 08:45:26 2008 -0500
-
- Fixes whitespace in REXML::Element specs
-
- Signed-off-by: Eero Saynatkari <rubinius@projects.kittensoft.org>
-
-commit 3a997bc18f589b91b4cd518448644171f3054abf
-Author: Federico Builes <federico.builes@gmail.com>
-Date: Thu Apr 3 08:29:23 2008 -0500
-
- More specs for REXML::Element
-
- Signed-off-by: Eero Saynatkari <rubinius@projects.kittensoft.org>
-
-commit d250939060a4a91a6fee59bd4bfa4e86eb271373
-Author: Paul Thornthwaite <tokengeek@gmail.com>
-Date: Thu Apr 3 14:36:42 2008 +0100
-
- Specs for Set#superset and Set#proper_superset added
-
- Signed-off-by: Eero Saynatkari <rubinius@projects.kittensoft.org>
-
-commit 01399738d5ad0136ef205b8501b12012c7e42230
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Thu Apr 3 18:09:20 2008 -0400
-
- Removed excludes for Object#kind_of?, #is_a?.
-
-commit 0e7d1c6e02e5617bb251366e0d60760edb29377e
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Thu Apr 3 20:04:34 2008 +0200
-
- Fixed copy-paste error in Object#is_a? specs.
-
- Adjusted the Object#is_a? exclude.
-
-commit 4a9cb7cc0c734b4280c3a65906c85e1c1e2f4990
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Thu Apr 3 19:02:05 2008 +0200
-
- Add specs for #kind_of? / #is_a? behaviour that are failing in Rubinius.
-
-commit e88fdb6cbd9fa829a81e6c7664e88f6956ddae64
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Thu Apr 3 07:18:56 2008 -0400
-
- Spec to check `A = 12; class A; end` raises TypeError. Works as is.
-
-commit 3c0db09626333405bdcb72e62ddb8fb2ea176ff5
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Thu Apr 3 06:44:32 2008 -0400
-
- Spec for const lookup: `A = 12; class A::B; end` should raise TypeError.
-
- * Currently crashes due to a lookup problem.
- * VVSiz discovered and reported.
-
-commit edda5994c293e4d26b4a741e90e0ab61513e8dec
-Author: Adam Gardiner <adam.b.gardiner@gmail.com>
-Date: Wed Apr 2 16:39:09 2008 +1100
-
- Do not strip leading spaces in debugger output
-
-commit eecc2bca5045921368378abfccafcf70339441f9
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Wed Apr 2 21:34:52 2008 +0200
-
- Enabled File#truncate testcase for JRuby.
-
-commit 4d555cf50dfe6a8e9cb2f24a6a636a9df3f03768
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Wed Apr 2 20:03:02 2008 +0200
-
- Added test case to File.open rubyspecs.
-
- Courtesy of David Yip.
-
-commit 42f0b52cd9fbac4a39fc1e5c2a241462bee5bf3b
-Author: Brian Ford <bford@engineyard.com>
-Date: Wed Apr 2 01:11:38 2008 -0700
-
- Use kind_of instruction since #kind_of? is not available at all times.
-
-commit 9ee52514eee820b9af7c9e6d2eaaca8d2bca363b
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Tue Apr 1 17:16:47 2008 -0500
-
- IO#reopen should return self
-
-commit f1481283091fcbe662fd01d409f5a2d2d7e3aa59
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Tue Apr 1 18:57:06 2008 -0500
-
- added primitive io_close_ng and tagged IO#close spec failures
-
-commit 3861e75e01af9319e2af879e2644fc8509947903
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Tue Apr 1 16:07:27 2008 -0500
-
- IO#close should return nil and refactored TCPServer.accept specs
-
-commit d6dfbd3b0bab57453e67991c3320744b08346979
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Tue Apr 1 15:04:18 2008 -0500
-
- DRb specs now attempt to check if server is up/down prior to each call to start_server
-
- note that there is something wrong with the way stop_server works in rubinius as it appears that the TCPServer is still binding the port. Spec is tagged to deal with this but technically it's probably a bug in TCPServer
-
-commit 4119fe8baab45be6b1d1370b8a9537e710b1a60a
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Tue Apr 1 12:40:47 2008 -0400
-
- Sanity changes to #load specs to bring them up to date.
-
- * Please change the specs if you change the implementation, sheesh.
-
-commit 3b58cb35abeba31f7ac72e3ab37b2630949406a7
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Tue Apr 1 10:59:58 2008 -0400
-
- Spec for forced recompiling through second parameter of Kernel#load.
-
-commit 5d7a73ae15a4c40e31486a60cbb66f3de1ac4697
-Author: David Whittington <djwhitt@gmail.com>
-Date: Wed Apr 2 02:57:35 2008 +0000
-
- Add tags for failing private keyword specs
-
-commit 1b2f118be7ff9b6adfea736ecbbb8f3fd8dd0f49
-Author: David Whittington <djwhitt@gmail.com>
-Date: Wed Apr 2 02:53:43 2008 +0000
-
- Added a couple evil private keyword tests
-
-commit f58c67e33a99f751c3520ab65c96e28a91c45900
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Tue Apr 1 09:59:22 2008 -0400
-
- Conditional compilation. Rubinius.compile_if($DEBUG) { p somevariable }.
-
- * Hacky and probably fragile but it seems to work. Whenever the gvar
- given as condition evaluates to false, the entire block is omitted
- from the produced bytecode. If it evaluates to true, then the extra
- block itself is stripped and only the block contents remain.
- * Do NOT use indiscriminately until we have played around with it for
- a bit to avoid problems.
- * Manipulates the sexp, not the AST to avoid worrying about locals
- and scopes and whatnot.
- * Enabled by default; for example -d will work out of the box (you
- do need to have the file recompiled obviously.)
-
-commit 4f78ee2b0bebb9170a483927af9c7520ca67f912
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Tue Apr 1 09:58:53 2008 -0400
-
- Specs to verify conditional compilation in the compiler.
-
-commit 8dfece35e3bc83e14e92bfee9ea0ebabb795da70
-Author: Brian Ford <bford@engineyard.com>
-Date: Tue Apr 1 01:07:14 2008 -0700
-
- Fix up language symbol specs.
-
-commit 29cc22f2c1f7ce2ce15a7f339d1159cf93510daa
-Author: Brian Ford <bford@engineyard.com>
-Date: Tue Apr 1 00:40:34 2008 -0700
-
- Constant lookup only searches class or module (#457).
-
-commit 538611f2aa06a1cf1c3958583bd6a8487deee994
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Mon Mar 31 18:03:41 2008 -0400
-
- Spec for empty loop body.
-
-commit fd0d1079671d7664de3a6a836c5e5624d487a4e1
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Mon Mar 31 23:47:40 2008 +0200
-
- Spec for constant lookup on non Module or Class objects
-
- This exposes the bug also described in ticket \#457
-
-commit 3b7cf550c70db2dd53cb58ef3efd2651ee352134
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Mon Mar 31 21:53:40 2008 +0200
-
- Added a couple of Dir.glob/Dir[] rubyspecs.
- (Courtesy of Roland Swingler)
-
-commit bbfa77a8517390bdc807f41bfe6d101791980d8f
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Mon Mar 31 19:04:09 2008 +0200
-
- Fixed DRb rubyspecs (proper spec name, removed invalid file, better cleanup).
-
-commit d8a4fb0b16dc4c722cf148ff83bcad05fbb4af1e
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Mon Mar 31 14:29:54 2008 +0200
-
- Make sure Marshall#load rubyspec closes the file.
-
-commit 4082a7663eaef50000be46d909c22fbb97a1a3e8
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Mon Mar 31 13:57:35 2008 +0200
-
- Reverted new Range#step rubyspecs, since they fail on MRI and JRuby.
-
- Partial revert "Fixes for Range#step."
- This (PARTIALLY) reverts commit a6b06a67207c40ffa9ccf191c051fdf2fa0f5359.
-
- The specs are reverted since they fail on:
- MRI 1.8.6 pl 36 (Ubuntu default)
- MRI 1.8.6 pl 114 (Current compatibility target)
- MRI 1.8.6 from 1_8 branch
- MRI 1.9 from Ruby trunk
- JRuby 1.1 from trunk
-
- The specs expect that to_f is invoked, but MRI and JRuby don't behave
- that way. Furthermore, Float is not a special case. There are other
- cases, like Rational. Take a look into MRI code, there is no special
- handling for Float.
-
- Please, test your spec updates at least against the current
- compatibility target (MRI 1.8.6 patchlevel 114) to avoid problems.
-
-commit 6d9680ecaaa2a9aadd35699c8064bf6481acc107
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Mon Mar 31 13:23:20 2008 +0200
-
- Added new rubyspecs for IndexError out of String#[]=
-
-commit c8a52bb7cf191bb35efc89c560bdeced4241f015
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Mon Mar 31 04:38:49 2008 -0400
-
- Split Regexp#=~, #match specs; they behave differently on match.
-
- * #=~ Returns index, #match returns MatchData.
- * Grammar fixes.
-
-commit 6c2727e928991cdf9f809cb5941c3afedb5171ff
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Mon Mar 31 04:07:17 2008 -0400
-
- Fix Regexp#match, #=~ spec to actually be shared. Exposes #454.
-
-commit e258a2bccafffba57ab86d1c1a104839bda424da
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Mon Mar 31 03:30:48 2008 -0400
-
- Spec to verify IO behaviour with an altered BufferSize from Le Huy.
-
- * Moved spec to spec/core/io/ and simply used the first one.
- * This problem seems to have been largely corrected.
-
-commit 7a39be8bea055464838ff24c70e170a91f8df68c
-Author: Ben Burkert <ben@benburkert.com>
-Date: Sat Mar 29 19:39:11 2008 -0500
-
- Added spec for Module#define_method
-
- Methods defined by define_method with a proc should have the
- same scope for local variables as the proc.
-
- Signed-off-by: Eero Saynatkari <rubinius@projects.kittensoft.org>
-
-commit 12c639d90ff3d14f8010ca7c782612bd7c1777ab
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Sat Mar 29 23:58:13 2008 -0400
-
- Tony Arcieri's specs for inter-VM Actors.
-
- * VMActor implements the Actor interface to work in Rubinius' Multi-VM
- context: VMActors can reside on any VM instance.
-
-commit a0d0884aa3c9e7a6fa949cbde1cdf2392bc4ff23
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Sat Mar 29 15:59:42 2008 -0400
-
- Module#attach_foreign allows using a symbol to give the function name.
-
- * Specs for the same.
-
-commit a5f397f38d6c9eafcac163c2cf678d5c55a6b79b
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Fri Mar 28 23:40:04 2008 -0400
-
- Specs for FFI in general and Module#attach_foreign in particular.
-
- * Very basic specs to verify that FFI in fact works correctly.
- * We need to define what the behaviour should be in the case of e.g. an
- incorrect function signature. Currently it may or may not cause SEGVs
- depending on the exact usage. Remainder specs are in but quarantined.
-
-commit 3dc5c635b56bc599a718a94f990976b67ab52b6c
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Wed Mar 26 02:01:12 2008 -0400
-
- Specs for Module#attach_foreign.
-
- * The method is a replacement for #attach_function but allows
- giving the library name as well to access external libs.
- * This acts a higher-level interface to FFI.create_function. The
- "real" FFI specs will be written for that method instead.
-
-commit 677412353409ba4e5d67f19a3d095c62d009c88f
-Author: Brian Ford <bford@engineyard.com>
-Date: Fri Mar 28 18:04:40 2008 -0700
-
- Added CType#isctrl, #toprint. Rework String#inspect, #dump.
-
-commit 87ba991b9b488b808ebf729b9e41765df76cc602
-Author: Brian Ford <bford@engineyard.com>
-Date: Fri Mar 28 15:09:11 2008 -0700
-
- Reworked String#each and #sum. Added String#modified? and specs.
-
-commit 204d8ce1a792a61882e549953b5b878139ac9cda
-Author: Hongli Lai <hongli@plan99.net>
-Date: Fri Mar 28 23:32:18 2008 +0100
-
- Spec: Marshal raises EOFError on loading an empty file
-
- Signed-off-by: Michael S. Klishin <michael@novemberain.com>
-
-commit f6e698f96ce9e2a8c8abe856322add02931df8b7
-Author: Michael S. Klishin <michael@novemberain.com>
-Date: Sat Mar 29 02:20:23 2008 +0200
-
- Tag new spec for ensure as failing
-
-commit ef7e4436389a0f4346b3a3bc5c275b653f46d6bb
-Author: Hongli Lai <hongli@plan99.net>
-Date: Fri Mar 28 23:22:44 2008 +0100
-
- Add spec for exception handling inside ensure block.
-
- Signed-off-by: Michael S. Klishin <michael@novemberain.com>
-
-commit f54c91f6cb7498fe44b1b05a1372d9f6ed3ea1ee
-Author: Stuart Halloway <stu@thinkrelevance.com>
-Date: Fri Mar 28 10:11:05 2008 -0400
-
- Fixes Pathname#absolute? and #relative?.
-
- * specs now pass
- * underlying cause was corner case in File#basename
- * new passing spec for corner case
-
- Signed-off-by: Charles Comstock <dgtized@gmail.com>
-
-commit 0d4606d53d8fc0bcb2370bd648546abffd402673
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Fri Mar 28 16:45:47 2008 -0500
-
- fixed CSV::Reader.parse spec to use local fixtures
-
-commit 35a15c6c85ebb6eabaec16e03aa88399061844e9
-Author: Alister Lee <rubinius@dev.shortepic.com>
-Date: Sat Mar 8 18:11:24 2008 +1100
-
- Beginning of specs for CVS::Reader.parse
-
- Signed-off-by: Charles Comstock <dgtized@gmail.com>
-
-commit d4161a379eab621e338a8c82f088b834756082e9
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Fri Mar 28 16:39:50 2008 -0500
-
- removed csv/reader/parse_spec to commit alister lee's spec
-
-commit 534806c10a95435873efcb0d215732d7da4f2fd6
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Fri Mar 28 16:38:03 2008 -0500
-
- mkspec generated specs for csv.rb
-
-commit a6b06a67207c40ffa9ccf191c051fdf2fa0f5359
-Author: Stuart Halloway <stu@thinkrelevance.com>
-Date: Fri Mar 28 06:09:34 2008 -0400
-
- Fixes for Range#step.
-
- * previously failing specs pass
- * new spec added to cover float/int difference
-
- Signed-off-by: Michael S. Klishin <michael@novemberain.com>
-
-commit 6886ec5851783c5364ff5bc464ee94071fc8535e
-Author: Michael S. Klishin <michael@novemberain.com>
-Date: Fri Mar 28 00:06:56 2008 +0200
-
- Update stdlib and specs for REXML from 1.8.6 patchlevel 114 (see details!)
-
- * Update stdlib/rexml to use REXML from Ruby 1.8.6 p114.
- * REXML in p114 is screwed up: call sites were not updated
- after REXML::Formatters::Transient#initialize arity
- change. Ruby 1.8.x branch in SVN though has
- completely different REXML layout and organization
- (rev. 15833) so there's no way to fix it until we know
- where REXML changes are headed in 1.8.x branch.
- * Update REXML spec and tags for it.
-
-commit 3145a74a85d72f6ef8a93384a74d96a589bfb5eb
-Author: Brian Ford <bford@engineyard.com>
-Date: Wed Mar 26 22:27:41 2008 -0700
-
- Rework and cleanup of various String methods.
-
- Also, ensure that when Strings are converted through FFI
- and passed to C functions, the char array is explicitly
- terminated with \0.
-
-commit 9ba3e515b49729e0cb80181af9e28e3ce4c70e97
-Author: Brian Ford <bford@engineyard.com>
-Date: Wed Mar 26 18:40:57 2008 -0700
-
- Shuffle some String methods. Add specs for and rework String#substring.
-
-commit 990d47b84bc6301be2a8bcbaccbae65ef697c417
-Author: Brian Ford <bford@engineyard.com>
-Date: Tue Mar 25 16:22:45 2008 -0700
-
- Added String#compare_substring. Reworked String#chop! and #chomp!.
-
- Also, to ensure that ByteArray instances that are accessible in
- Ruby are properly handled by C functions, changed string_equal_p
- to use strncmp instead of strcmp.
-
-commit f47c446daa136e6f31f5c590dd535ba22e89a0b2
-Author: Brian Ford <bford@engineyard.com>
-Date: Tue Mar 25 11:36:16 2008 -0700
-
- Fix errors in String#count_table spec descriptions.
-
-commit 9425d0de9a7883c14de6ae9ae5db05ab92141ab9
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Wed Mar 26 22:38:48 2008 +0100
-
- Guarded two failing specs on OpenBSD that also fail on MRI
-
- MRI on OpenBSD also suffers from the 0.0 / -0.0 issue (the
- GCC version on that platform too). The child reaping spec
- also fails on both MRI and Rubinius
-
-commit 288a6e2ca3675a1e60bfd6b8b328c2a4d513c12f
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Wed Mar 26 22:15:16 2008 +0100
-
- Fix Socket specs for more strict BSD behavior
-
-commit 63513d23f16ca7919b8605e016a3a941b79c0834
-Author: Ryan Davis <rdavis@engineyard.com>
-Date: Tue Mar 25 17:20:53 2008 -0700
-
- oops! extra exclude
-
-commit a36a4bf8cde95c99282e07f46438430588288736
-Author: Ryan Davis <rdavis@engineyard.com>
-Date: Tue Mar 25 17:20:19 2008 -0700
-
- really minor changes
-
-commit e9b759812deaf97e7fe5846c116d53f69b63e244
-Author: Ryan Davis <rdavis@engineyard.com>
-Date: Tue Mar 25 17:19:41 2008 -0700
-
- Added the sucky parser spec--not passed yet
-
-commit 90eb74998e132373e6b96e3c66bfa909854e3ef0
-Author: Ryan Davis <rdavis@engineyard.com>
-Date: Tue Mar 18 17:41:50 2008 -0700
-
- Added spec for 'a [ 42 ]'
-
-commit 2d34643c75b53b832e89d2473d501ab1c8a5df02
-Author: David Whittington <djwhitt@gmail.com>
-Date: Wed Mar 26 08:01:20 2008 +0000
-
- Tagged Generator specs as unstable due to memory consumption
-
- Each spec consumes > 60MB of memory. After looking at the specs there is no way
- they should be consuming that much memory.
-
-commit 52d81e0593dbca8abfecefe2e9c3d2ab504cfe0b
-Author: Brian Ford <bford@engineyard.com>
-Date: Tue Mar 25 10:43:17 2008 -0700
-
- Added String#copy_from primitive. Reworked String justify methods.
-
-commit 1aabda50ea82974b96a7032a0ea13865b2332b5d
-Author: Brian Ford <bford@engineyard.com>
-Date: Mon Mar 24 21:57:02 2008 -0700
-
- Added Tuple.template and reworked String#tr and friends.
-
-commit bc7d9ccb8b8ca77d8479f325ea314fc09bc34907
-Author: Brian Ford <bford@engineyard.com>
-Date: Fri Mar 21 00:51:10 2008 -0700
-
- Rework methods that behave like String#count.
-
-commit 1e5ac9a6818c972882e080aeb723a105108e0c57
-Author: Brian Ford <bford@engineyard.com>
-Date: Wed Mar 19 21:25:07 2008 -0700
-
- Rewrite of String#casecmp, approx 2x faster.
-
-commit c39f2cb708169d35c2fbeb969ee3323c704f0566
-Author: Matt Palmer <mpalmer@engineyard.com>
-Date: Tue Mar 25 21:09:37 2008 +1100
-
- Some specs for the timeout library
-
-commit cb69bdadeb10cf6b4b2c71a095562f8d8371d76d
-Author: Federico Builes <federico.builes@gmail.com>
-Date: Mon Mar 24 17:55:23 2008 -0500
-
- Small fix for Socket.getaddrinfo spec
-
- Signed-off-by: Michael S. Klishin <michael@novemberain.com>
-
-commit 5c3a61edef3c456b8296e65f8e06026347339a36
-Author: Federico Builes <federico.builes@gmail.com>
-Date: Mon Mar 24 17:06:36 2008 -0500
-
- Fix for the socket's issue
-
- Signed-off-by: Michael S. Klishin <michael@novemberain.com>
-
-commit f3fd9ac4eebd0bc2a0a06bbe06921463d03177eb
-Author: Federico Builes <federico.builes@gmail.com>
-Date: Mon Mar 24 14:10:46 2008 -0500
-
- Fixes specs for Socket and adds a gethostname spec
-
- * Changes hardcoded "localhost"s to Socket#gethostname calls.
- * Adds a simple spec for Socket#gethostname
-
- Signed-off-by: Michael S. Klishin <michael@novemberain.com>
-
-commit 7131328bc02057b16071a933fe98f331b27e00bb
-Author: Michael S. Klishin <michael@novemberain.com>
-Date: Tue Mar 25 00:24:01 2008 +0200
-
- Applied slightly modified patch by Federico Builes:
-
- * Add REXML::Document and REXML::Attribute specs
-
-commit cb464295e5accb00e783f7f9e2a0b10c64ad6579
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Sun Mar 23 12:06:07 2008 +0100
-
- Added new Range#step rubyspecs.
-
- Excludes for rbx also updated.
-
-commit 7d181716ac3b92d8a31a20ec30daee455d36fc58
-Author: Charles Oliver Nutter <charles.nutter@sun.com>
-Date: Sat Mar 22 14:51:30 2008 -0500
-
- Added order-of-evaluation spec and tags for rubinius failures.
-
-commit 5caf94ce6deb5e28c9a3de02e60a9b86cbdaf7ec
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Fri Mar 21 12:37:02 2008 -0500
-
- tagged new specs for pathname
-
-commit 62f88983ee3fa1b09d8f7df56e35cbfdac6d2a06
-Author: Martin Stannard <mstannard@gmail.com>
-Date: Fri Mar 21 12:10:23 2008 +1100
-
- added some specs for pathname library
-
- there are failures in absolute and relative specs
-
- Signed-off-by: Charles Comstock <dgtized@gmail.com>
-
-commit 655f61650bb299f38c9fd978594baa483fc0d0cc
-Author: Ryan Davis <rdavis@engineyard.com>
-Date: Tue Mar 18 16:22:24 2008 -0700
-
- Reduced parser todos from 113 to 89
-
-commit f97b2fc2ee3310e81871200125bbd7e33c2636bf
-Author: Ryan Davis <rdavis@engineyard.com>
-Date: Tue Mar 18 13:51:31 2008 -0700
-
- Moved sexp_expectations.rb to fixtures subdir
-
-commit 0a185e5ac48954cf4addae0c8f09dcb5be259f8e
-Author: Ryan Davis <rdavis@engineyard.com>
-Date: Mon Mar 17 17:55:50 2008 -0700
-
- Added f'd up note about the spec failing
-
-commit 978f043e1ed3a2b7cb7d4129e0002be485b0a78c
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Tue Mar 18 21:17:32 2008 +0100
-
- Fix Process.groups spec
-
- Process.groups can return an array with the same gid multiple
- times on certain platforms (at least on FreeBSD and OpenBSD).
-
-commit 8812658dde5e317dfebd0ea3c159ad0a1b98e8e8
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Tue Mar 18 21:02:00 2008 +0100
-
- Update spec tags for ERB
-
-commit 47216560d4a980cbaac2855e0c5ee302e0754bf8
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Tue Mar 18 20:53:16 2008 +0100
-
- Update spec tags for IO
-
-commit 7d34f4053023d99c3be4964bfebb3a1c74cd40c9
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Tue Mar 18 20:32:39 2008 +0100
-
- Update spec tags for File
-
-commit 8a66bc6f5e378f49febb80fba37723a7de0d2475
-Author: Brian Ford <bford@engineyard.com>
-Date: Mon Mar 17 15:46:51 2008 -0700
-
- Added specs for File.[l]chown/#chown, code for File.lchown.
-
-commit 960872ae163a5615f513c58d727a7fd93664673e
-Author: Glenn Davy <glenn@thor.local>
-Date: Mon Mar 10 10:00:40 2008 +1100
-
- Make File.fnmatch respect case when using square brackets
-
-commit 0e32f8e224543a3c152b0351540eaa36fdfcdb06
-Author: Brian Ford <bford@engineyard.com>
-Date: Mon Mar 17 11:04:27 2008 -0700
-
- Added exclude for failing spec added in b635fcf0.
-
-commit 62687753b239984acba4f0e80899ca75a8a08cfe
-Author: Brian Ford <bford@engineyard.com>
-Date: Mon Mar 17 10:56:31 2008 -0700
-
- Fixes and specs for Module class_variables methods.
-
-commit b635fcf041707fe55a26b7709aef8dc1b2509161
-Author: Charles Oliver Nutter <charles.nutter@sun.com>
-Date: Mon Mar 17 12:52:13 2008 -0500
-
- Add a simple Module#private spec.
-
-commit 2aa98e1df50bba768b57018f6e90c56fe39206f4
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Mon Mar 17 13:28:17 2008 +0100
-
- Make sure no processes left hanging after IO#close specs.
-
-commit 8f332dde4460c03c378f1d1ecc1fbae54557d8ee
-Author: Matt Palmer <mpalmer@engineyard.com>
-Date: Mon Mar 17 16:44:24 2008 +1100
-
- Raise an Errno exception if a write fails
-
-commit 55c830063115e4455eeda3f8de639a7f7e0624f5
-Author: Matt Palmer <mpalmer@engineyard.com>
-Date: Mon Mar 17 16:42:16 2008 +1100
-
- Raise IOError if we attempt to write to a readonly file
-
-commit ad64c0ea7598b8a4c62ba2dd435f70c976186a50
-Author: David Whittington <djwhitt@gmail.com>
-Date: Sun Mar 16 04:24:54 2008 +0000
-
- Modified file type specs to search for sockets in /var/run instead of /var
-
- Doing a find on /var could take quite a while + might do nasty things like do
- finds on backup files etc. Running a find on /var/run should be faster and
- safer.
-
-commit ff5e9d3b9d7f3e484211b66fff96e665ed13614b
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Wed Mar 12 17:44:55 2008 +0100
-
- Revert "Added simple spec for range splatting".
-
- This reverts commit 9b3988436a21f61c86168a7566d472c4dfa22162.
-
- The spec uses '=' instead of '==', and it verifies something
- that is not true for MRI (1.8, 1.9) or JRuby.
-
-commit 004662e54477269a98475f84724972b82885d9cb
-Author: Brian Ford <bford@engineyard.com>
-Date: Sat Mar 15 01:09:43 2008 -0700
-
- Exclude failing UNIXServer.new spec.
-
-commit 13340924519f607d9c48da04c3f3ab41a1de3e86
-Author: Brian Ford <bford@engineyard.com>
-Date: Fri Mar 14 18:14:06 2008 -0700
-
- Tagged unstable Process.kill specs that cause hangup on linux.
-
-commit c4a4dc19a26db058594c8056933cdab42d4f26fd
-Author: Matt Palmer <mpalmer@engineyard.com>
-Date: Fri Mar 14 21:13:31 2008 +1100
-
- Fix up IO#write spec so it works cross-platform
-
- It looks like the Linux implementation of IO#write and IO#read are a bit
- different from the OS X version, because the spec worked on OS X.
- Presumably this tiny change won't cause any conniptions.
-
-commit 33890d9a77d5a34c15263f84b9b415ffc084815a
-Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
-Date: Fri Mar 14 14:42:11 2008 +0800
-
- Remove fail tags from passing ruby/1.8/core specs
-
-commit 4bdd3df099fe627d158f4c6d35e5a7df0a891e86
-Author: Adam Gardiner <adam.b.gardiner@gmail.com>
-Date: Fri Mar 14 12:58:40 2008 +1100
-
- Fix bug where stepping by line would sometimes skip a line
-
-commit 260190092afbcfadd1a6e1d6db1674ecf021b686
-Author: Matt Palmer <mpalmer@hezmatt.org>
-Date: Sat Mar 8 19:26:41 2008 +1100
-
- Put in an explicit IO.new test for single-argument
-
- Assuming that your UDPSocket tests passing will prove that IO.new takes
- one argument might have been, in retrospect, a little retarded.
-
-commit 58216e07f0728415762fe5fbe98e1e984dfea31b
-Author: Matt Palmer <mpalmer@hezmatt.org>
-Date: Sat Mar 8 18:45:17 2008 +1100
-
- Mark changing failures in the CI test suite
-
- Fix up so that the CI doesn't fail as a result of my previous changes to the
- UDPSocket specs.
-
-commit 36f91c5da132f309fbf6d047fd74ebd8aa7cbf22
-Author: Matt Palmer <mpalmer@hezmatt.org>
-Date: Sat Mar 8 17:26:49 2008 +1100
-
- Rearrange the UDPSocket test cases for better separation
-
- * open_specs now only contains a spec that calls UDPSocket.open;
- * send_specs now has separate tests for ad-hoc and connection-oriented
- sends.
-
-commit b40c1cf434bd0879f672ec1dc471f1e1dfaccc1c
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Thu Mar 13 17:07:50 2008 -0700
-
- Add (failing) Symbol#to_yaml spec based on ticket 322
-
-commit c0bcb0151379fe9858d0fafd2ef56cf1b08daff3
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Thu Mar 13 16:23:37 2008 -0700
-
- Apply ticket 351 and resolve ticket 350 (RbYAML bugs)
-
-commit a8d6e8cddfd8bc2dccaa93b25adfb31b39b96dba
-Author: Ryan Davis <rdavis@engineyard.com>
-Date: Thu Mar 13 16:25:55 2008 -0700
-
- Removed all should_not raise_error from shared/time_params.rb
-
-commit 01f09f4e5697c4a775ac321a71d3b777196d9001
-Author: Ryan Davis <rdavis@engineyard.com>
-Date: Thu Mar 13 15:47:37 2008 -0700
-
- cleaned up spec with new raise_error block form
-
-commit e965fc735311915dd43c47cc4853e163376cc6be
-Author: Lachie Cox <lachie@smartbomb.com.au>
-Date: Sat Mar 8 17:14:37 2008 +1100
-
- enhanced syntax error to give same message as MRI
-
-commit 868b38152ca99189fce85542a9068c0d01ee4a41
-Author: Ryan Davis <rdavis@engineyard.com>
-Date: Thu Mar 13 15:07:33 2008 -0700
-
- Added exclude for last patch applied
-
-commit 9b3988436a21f61c86168a7566d472c4dfa22162
-Author: Patrick Hurley <phurley@gmail.com>
-Date: Mon Mar 3 14:04:14 2008 -0500
-
- Added simple spec for range splatting
-
-commit 3c7a017e173945d3f9b18d566bb1c3d6d04e97e4
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Thu Mar 13 17:18:39 2008 -0500
-
- fixed tags for new constant specs
-
-commit a966436b7be78bc063e32bc16496f5cabbb0a152
-Author: Matt Palmer <mpalmer@hezmatt.org>
-Date: Sat Mar 8 14:56:58 2008 +1100
-
- Make sure modules included in Object are found
-
- Add a spec to make sure that constants from modules included in Object are
- found. Evan is committing the fix for this separately.
-
- Signed-off-by: Charles Comstock <dgtized@gmail.com>
-
-commit 4e0ddd3e701f68b592cb69972f7d587b90392913
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Thu Mar 13 15:05:54 2008 -0700
-
- Correct a 'defined?' spec added by ticket 388
-
-commit 407095d8ffbf0563fa46e5d4ed6a08423eddb2ad
-Author: Martin Stannard <mstannard@gmail.com>
-Date: Sat Mar 8 15:47:59 2008 +1100
-
- Added tests where defined? method should return string descriptions of objects
-
-commit f366309a8fff28552d7d27101d8b3d7b4352e235
-Author: Gianluigi Spagnuolo <glgspg@gmail.com>
-Date: Fri Feb 29 10:42:42 2008 +0100
-
- Fixed Array set element problem
-
-commit 42c22bf542edc8c8379587507fd9e35ba25b190c
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Thu Mar 13 17:00:31 2008 -0500
-
- updated tags for new read specs
-
-commit 45c43a7ab3310a41b0b3367f4762a1bb55b02405
-Author: Ben Askins <benj@supernova.local>
-Date: Sun Mar 9 11:41:49 2008 +1100
-
- Fix typo in file/open_spec.rb
-
- Signed-off-by: Charles Comstock <dgtized@gmail.com>
-
-commit a221ea56325fe082154a629094abb27d40919a39
-Author: Alister Lee <rubinius@dev.shortepic.com>
-Date: Sun Mar 9 15:27:34 2008 +1100
-
- Specs to expose defect in eof treatment in IO.read
-
- Signed-off-by: Charles Comstock <dgtized@gmail.com>
-
-commit 4967adb3d49252aae75b6b57159fb5879ac75db1
-Author: Myles Byrne <myles@ducknewmedia.com.au>
-Date: Sat Mar 8 12:14:20 2008 +1100
-
- Check existence of ArgumentError
-
-commit 45e46234da288052e639bb5c9c122874fd4d4e1c
-Author: Brian Ford <bford@engineyard.com>
-Date: Thu Mar 13 10:28:54 2008 -0700
-
- Fix File[Test].size? and specs for it.
-
-commit d467bf21c4037784a21ba964b24c28fc80b34736
-Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
-Date: Thu Mar 13 17:36:56 2008 +0800
-
- Fix IO::foreach when separator is nil
-
-commit 70615e1c15692b8a8149e1616c802db9eb5bad11
-Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
-Date: Thu Mar 13 17:32:40 2008 +0800
-
- Fix IO#flush to raise IOError on closed stream. Remove empty tag files.
-
-commit 9c9e7f422c98bf6add6c9a426ae25e3a6dbced85
-Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
-Date: Thu Mar 13 17:29:31 2008 +0800
-
- Fix IO#fcntl to raise IOError on closed stream
-
-commit 215d600002948efb949422c0163aa9bbe5790507
-Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
-Date: Thu Mar 13 17:27:43 2008 +0800
-
- Fix IO#dup to raise IOError on closed stream
-
-commit 879ee8124a2ad8ce83bcd9c51b2d6df0baecb40d
-Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
-Date: Thu Mar 13 16:29:03 2008 +0800
-
- Fix a bunch more IOError when closed stream
-
-commit 487d9561992eb03c3d12de5128772cd194b37b8b
-Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
-Date: Thu Mar 13 16:26:33 2008 +0800
-
- Implement IO#read_nonblock
-
-commit 15c58fa2c47d2dc61b3dac436ab3b56a727b7dc5
-Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
-Date: Thu Mar 13 15:46:22 2008 +0800
-
- Fix remaining IO.read specs
-
- * Passing nil to length treats it as no length limit
- * Passing nil to offset treats it as 0
-
-commit 9daee4f9c3b62db34b07d74171d1017fa823533c
-Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
-Date: Thu Mar 13 15:32:13 2008 +0800
-
- Fix IO#sync to raise IOError on closed stream
-
-commit 2ac848c09e055b3eacc8bb18f713d56715484063
-Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
-Date: Thu Mar 13 15:24:36 2008 +0800
-
- Fix IO#sync to raise IOError on closed stream
-
-commit 36aa8577603f1d8ca76344fc3e889bb7c991bfe9
-Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
-Date: Thu Mar 13 14:51:13 2008 +0800
-
- Fix IO#sysseek to raise IOError on closed stream
-
-commit 3307f5a4db121c2097b450278bc3cf19550f267b
-Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
-Date: Thu Mar 13 14:48:30 2008 +0800
-
- Fix IO#pos and #IO#tell to raise IOError, move their specs to shared
-
-commit 72890065371f3e1d1cde43618a3da04c900749aa
-Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
-Date: Thu Mar 13 14:39:21 2008 +0800
-
- Implement IO#to_io
-
-commit 4977bd1f22278e19ba69203c2545ad97c297ae23
-Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
-Date: Thu Mar 13 14:33:03 2008 +0800
-
- Remove IO#isatty tag file also, since they are sharing the same specs
-
-commit 5dd3115465852ddb03b7100b21739f9d38f0ee58
-Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
-Date: Thu Mar 13 14:29:13 2008 +0800
-
- Fix IO#tty? should raise IOError on closed stream
-
-commit 063f56b4c402180c2c989a15b75fe7a15d4c5c61
-Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
-Date: Thu Mar 13 13:55:55 2008 +0800
-
- Make IO#syswrite use the shared IO#write specs
-
-commit 22de413f6cccb3eb100fd29da90c2ded84ea19f3
-Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
-Date: Thu Mar 13 12:08:50 2008 +0800
-
- Update IO#write_nonblock's tag
-
-commit 25a5ac7e9123512e87e6460f1fa5ecbcfc7349b5
-Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
-Date: Thu Mar 13 12:07:22 2008 +0800
-
- Pull out 2 differences between IO#write and IO#write_nonblock specs
-
-commit a40dbd0f36f0237bc27c905c399aba1e62bbfa70
-Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
-Date: Thu Mar 13 11:39:03 2008 +0800
-
- Alias IO#write_nonblock IO#write and make IO#write specs shared
-
-commit 1c8eb4bc04405753dd607af1f5d231df01fd2536
-Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
-Date: Thu Mar 13 11:06:09 2008 +0800
-
- Make the mock return a string to prevent a coercion error
-
-commit a85b2105c826a7d39dc45c90cad37faf75baac86
-Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
-Date: Thu Mar 13 10:39:00 2008 +0800
-
- Fix IO#write should raise IOError on closed stream
-
-commit e8c8af1aa888dc3e5600cad64f03c09aebaf6d22
-Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
-Date: Thu Mar 13 10:34:08 2008 +0800
-
- Fix IO#to_i should raise IOError on closed stream
-
-commit 49d48c381b7ed0f2576c2c5bff3ac8825a0dd49e
-Author: Ryan Davis <rdavis@engineyard.com>
-Date: Wed Mar 12 17:56:26 2008 -0700
-
- Fix the insanity
-
-commit 646136d0f75b165a3a62266791556d3f4f03c835
-Author: Ryan Davis <rdavis@engineyard.com>
-Date: Wed Mar 12 17:04:30 2008 -0700
-
- Finally got compiler specs passing
-
-commit 052bbcbe4f51b322ae44dc387320f9b4964d74cd
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Wed Mar 12 16:23:58 2008 -0700
-
- Correctly set Syslog mask in Syslog::open and add crappy spec for it
-
-commit dbabc5bda94a2bd77b2cb777666d286155c75ee0
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Wed Mar 12 14:55:08 2008 -0700
-
- Correct Syslog specs and modify syslog.rb to pass them
-
-commit 5b8bee08f2a19d6f25df98183a24745ed33ed519
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Wed Mar 12 14:54:38 2008 -0700
-
- Modify Kernel#load specs so that they pass on 1.8.6-p111
-
-commit b96974693cee75772b09052f8ec7110a000c2429
-Author: Ryan Davis <rdavis@engineyard.com>
-Date: Wed Mar 12 14:00:42 2008 -0700
-
- Fixed specs for wilson's compiler encloser changes
-
-commit 2a21597719bea1ea7db27a552ea6dfb6865963d7
-Author: Ryan Davis <rdavis@engineyard.com>
-Date: Wed Mar 12 14:00:06 2008 -0700
-
- half work on pretty_inspect
-
-commit 6e398ca491b67a6c468798fd92a9764f70bc68a8
-Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
-Date: Wed Mar 12 15:18:02 2008 +0800
-
- Share String#to_a a specs with String#entries
-
-commit 2ff775cbcf2ade4315fbdbb37fa78ee84a1e645a
-Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
-Date: Wed Mar 12 11:59:26 2008 +0800
-
- Add String#to_a specs
-
-commit 4f1204bac224ad28375f06e5fb77156367895156
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Tue Mar 11 19:53:32 2008 -0700
-
- Spec and implement Array#pack 'v' option
-
-commit 91d51783f44c3a9b1adfe03b7b9fa35476494ce1
-Author: Adam Gardiner <adam.b.gardiner@gmail.com>
-Date: Wed Mar 12 12:45:56 2008 +1100
-
- Debugger::Output#wrap should handle width of 0
-
-commit 51c316464ad44cadad7ecd997ce45e8392695f4c
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Tue Mar 11 15:26:52 2008 -0700
-
- Implement support for :postexe nodes (END { some_code })
-
-commit 569dd9f10d5194c22335ce58a678d1f9c73f91d0
-Author: oleg dashevskii <be9@be9.ru>
-Date: Wed Mar 12 03:54:39 2008 +0600
-
- Import matrix lib with specs (#389 and #400)
-
- Original patches by Chris Lloyd and matta.
-
-commit 6beb50b7cc2dd3a0f57f3dee45767bb363082159
-Author: Brian Ford <bford@engineyard.com>
-Date: Tue Mar 11 13:20:07 2008 -0700
-
- More Integer#times specs.
-
-commit 746d89d6d55c82f26be08f182301926efd62d362
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Mon Mar 10 15:39:26 2008 -0700
-
- Correctly set the enclosing class for evaled code.
-
-commit 218cc7fbdd1b5d1c52248e65817752b8a50821ad
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Mon Mar 10 04:46:00 2008 +0100
-
- Added JRuby speciifc guard to singleton rubyspecs (JRUBY-2239).
-
-commit 25e3f23e78f2b17e02d2c0a058925f8a0ec0d790
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Mon Mar 10 11:25:38 2008 +0100
-
- Be sure not to close the socket before the Errno.handle call
-
- Also a small fix for a spec that fails on OpenBSD
-
-commit 9e7fdf3b0040971f7b8402b9cf5422efaedb2f4f
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Mon Mar 10 09:54:16 2008 +0100
-
- Fix TCPSocket#new spec, BSD systems make a distinction between IPv6/IPv4 localhost
-
-commit e5512b2a7725a67471eba086b107b0f4b1f136b2
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Mon Mar 10 08:35:50 2008 +0100
-
- Fix for failing unpack_sockaddr_in spec on Linux
-
-commit b9eab2266e5d1f073b6f876710dc9e848fe25b0c
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Sun Mar 9 23:37:05 2008 +0100
-
- Remove spec tag for now fixed Hash.allocate
-
-commit b6ba9a757b0531791424df38bce6587a53db6002
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Sun Mar 9 23:12:16 2008 +0100
-
- Remove tag for now correct Fixnum#[] spec
-
-commit 6785c2b44da90d95ef77e98cba42a953828b622f
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Sun Mar 9 23:11:37 2008 +0100
-
- Fix Fixnum#[] specs
-
-commit 0aa09ce9b7269d54cdef583a2eaf0cb57c32f773
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Sun Mar 9 23:05:21 2008 +0100
-
- Removed tags for working Socket specs
-
-commit 18b27b0ebdc3713962771ca75c1321cabee08d61
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Sun Mar 9 22:48:45 2008 +0100
-
- Untag now working IPAddr specs
-
-commit f4c0d08bec8fb2db7d130363b0609de7b7720d7e
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Sun Mar 9 19:56:25 2008 +0100
-
- Slow IPAddr specs are now fast
-
-commit ff71385a67b2853130e63f9942bcea6ac69d591f
-Author: Eero <ruerue@yawn.kittensoft.org>
-Date: Sun Mar 9 10:35:27 2008 -0400
-
- Specs for #412. Array#sort and #sort block form calls #<=> on elements.
-
- * Block form should not expect anything of the elements, all is
- done through the return value of the block.
-
-commit e6edd1bb4bc52053bdb834d52e31fa185f2a2d62
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Sun Mar 9 14:51:00 2008 +0100
-
- Updated tags for IPAddr because of fixed bit operations
-
-commit 4f59fa9bd187822cd836aa046bb8fd40e4412c30
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Sun Mar 9 14:49:02 2008 +0100
-
- Fix Fixnum and Bignum shift operations to match MRI
-
- Added behavior for the edge cases, but took a different
- approach than the LH tickets. I don't think we should
- change coercion functions for this.
-
-commit ad8c630662dcb611cd955db08a6f4d53d1dc0dfd
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Sun Mar 9 13:43:38 2008 +0100
-
- Fix Bignum#& and specs for Fixnum AND, OR and XOR
-
-commit 2529acd5e1cc8e61bd995e00834ee1f6941b1d9d
-Author: Eric Hodel <ehodel@engineyard.com>
-Date: Sun Mar 9 14:18:04 2008 +1100
-
- Fix require_spec and load_spec.
-
-commit 57c7ded8e4d9567aa3c392e8a8262389387ebbfb
-Author: Eric Hodel <ehodel@engineyard.com>
-Date: Sun Mar 9 12:25:40 2008 +1100
-
- Don't spec .rba require behavior in spec/ruby/1.8.
-
-commit ac630b23da01dcc3a1de1bfa06bac4d301a5031b
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Sat Mar 8 17:23:34 2008 -0800
-
- Better fix for calling to_proc on BlockPass nodes
-
-commit c17b32d44be8452cd867a8212a0fd8bb49c94821
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Sat Mar 8 16:34:02 2008 -0800
-
- Tag failing Method spec for CI
-
-commit c5d4a3b8f84b7558a5dfedb699a1a3ee4d61f118
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Sat Mar 8 16:26:58 2008 -0800
-
- Call Proc.__from_block__ on block_pass arguments
-
-commit a63f457821e67d138d9cf1c5ac8b0760cb25bfc2
-Author: Eric Hodel <ehodel@engineyard.com>
-Date: Sun Mar 9 10:42:51 2008 +1100
-
- Remove support for zip rba files, libzip. rake clean required.
-
-commit 142222e41bddd2138d82f349f73dbc0fe2cf3fc2
-Author: Charles Nutter <headius@wlan100.headius.com>
-Date: Sat Mar 8 16:23:37 2008 -0600
-
- Adding a spec for Method#to_proc proc used in define_method.
-
-commit b748efa9904baf0be26aa5b7297fc8ba76e46a74
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Sat Mar 8 13:09:44 2008 -0800
-
- Fix Module#method_defined? and friends for accessors
-
-commit 9b9d8216014c95eb7b4a925e93d0db8e9f5fd308
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Sat Mar 8 10:46:18 2008 +0100
-
- Adedd a couple of GzipReader#rewind specs.
-
-commit 4612812bde4a2fccbaa72ea54ef76c7d964d216b
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Sat Mar 8 15:49:57 2008 +0100
-
- Fix the Array#pack specs, network order is the same everywhere
-
-commit a720bba1619deb4358b453f58913d30a1a311b07
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Sat Mar 8 15:27:47 2008 +0100
-
- Fix Sprintf for positive non decimal notation
-
- This fix combined with the pack/unpack implementation for
- type n also fix some IPAddr specs.
-
-commit caef838aca82665d4c2f691e4873e339a9c7238d
-Author: Lachie Cox <lachie@smartbomb.com.au>
-Date: Sat Mar 8 12:47:19 2008 +1100
-
- updated Array#pack specs to work on big endian machines
-
- Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
-
-commit e3763469a224b4b3668bc1ddef2d982245787646
-Author: Lachie Cox <lachie@smartbomb.com.au>
-Date: Sat Mar 8 12:42:36 2008 +1100
-
- Added implementation of pack schemes for "n" and added handling of multiple items for "i","s" and "l"
-
- Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
-
-commit 41b26c49f5a16377af2c677eb702d665dd062a56
-Author: Eric Hodel <ehodel@engineyard.com>
-Date: Sat Mar 8 15:35:10 2008 +1100
-
- Fix IO#pos EOF spec. Pair: Lincoln, Evan.
-
-commit 1e039fb5c9bcff987769c8644ec47c30aa250952
-Author: Eric Hodel <ehodel@engineyard.com>
-Date: Sat Mar 8 14:53:01 2008 +1100
-
- Fix Zlib::GzipWriter#finish. Pair: Lincoln.
-
-commit 8551da47a01ef24eaf31fac55253fb05fe81cfcd
-Author: Eric Hodel <ehodel@engineyard.com>
-Date: Sat Mar 8 14:21:08 2008 +1100
-
- Add Zlib::GzipReader #eof?, #pos, #read w/length
-
-commit a4dba8317311cc3a51231895b2eaea09daaa61be
-Author: Eric Hodel <ehodel@engineyard.com>
-Date: Sat Mar 8 10:41:33 2008 +1100
-
- Ensure #pos clears internal eof flag
-
-commit 407e1a4191da6ecd59c1347198a60be2556e043b
-Author: Brian Ford <bford@engineyard.com>
-Date: Fri Mar 7 17:04:09 2008 -0800
-
- Tweaks to LookupTable. Converted Errno::Mapping to use LT.
-
-commit eb937c8f1041884e412e3d074387ca9f14bb03ef
-Author: Brian Ford <bford@engineyard.com>
-Date: Fri Mar 7 13:48:45 2008 -0800
-
- Fixed LookupTable#delete. Added LookupTable#entries, #dup.
-
-commit d7d9bfd01180cf2c4fc74d2709f71fc7dd59f2f6
-Author: Brian Ford <bford@engineyard.com>
-Date: Fri Mar 7 15:03:14 2008 -0800
-
- Bandaid fix for failing #autoload specs.
-
- These need to be properly scoped. However, changing
- :A to ModuleSpec:A causes a sigbus.
-
-commit aea5cc446cd2c1b0cbd29e606b21b6d5959eb5ee
-Author: Caleb Tennis <ctennis@engineyard.com>
-Date: Fri Mar 7 16:18:19 2008 -0500
-
- Add rb_gv_get and rb_gv_set, plus specs.
-
- Add rb_set_safe_level, rb_secure, and rb_safe_level methods, and specs.
-
-commit cd0b8969487af84a4f40466714dab2d5a1efc224
-Author: Ryan Davis <rdavis@engineyard.com>
-Date: Thu Mar 6 17:11:20 2008 -0800
-
- excluded
-
-commit e40f2bb09d8e3137de2856cb1e9c9438945603dc
-Author: Ryan Davis <rdavis@engineyard.com>
-Date: Thu Mar 6 17:11:00 2008 -0800
-
- More specs to test out const scoping with eval
-
-commit 3926add9039d1af4a60b633ef8805d471f28e02f
-Author: Ryan Davis <rdavis@engineyard.com>
-Date: Thu Mar 6 17:01:21 2008 -0800
-
- Further clarified StringIO#getc specs.
- They weren't really testing what they were doing.
- Fixed StringIO#getc. now properly pushes single chars and sets @pos so it can be mixed with puts/write as needed
-
-commit d2d3750c4960d4a6f2a5d2b16b8bae3d598fbe36
-Author: Caleb Tennis <caleb@tarknology.com>
-Date: Thu Mar 6 19:16:24 2008 -0500
-
- Add rb_define_global_function to subtend, with tests
-
-commit 4ab5cc17b70b6569cf9311142d4b278dedfd0a64
-Author: Brian Ford <bford@engineyard.com>
-Date: Thu Mar 6 09:53:20 2008 -0800
-
- Added LookupTable and specs.
-
-commit 1ca8a272137ed7020cb977bf51dd2b7164ccbd7e
-Author: Charles Nutter <headius@wlan100.headius.com>
-Date: Wed Mar 5 17:28:40 2008 -0600
-
- TCPServer.new coerces non-integer port to string and uses getservbyname logic.
-
-commit f0c03880972c19d1a12367dc51ed77f69d9ce8ca
-Author: Charles Nutter <headius@wlan100.headius.com>
-Date: Wed Mar 5 16:44:33 2008 -0600
-
- Add a couple specs for killing/raising in a thread blocked on accept.
-
-commit 9f80ef157851671727653f46225b99af5d1a259e
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Tue Mar 4 21:26:33 2008 +0100
-
- Proper spec for %u with negative bignums and comments on MRI behavior.
-
-commit 3f9c36081c9b62bcde40206e64afdc2ac088bee8
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Tue Mar 4 19:09:56 2008 +0100
-
- Update tags for fixed File#chmod specs
-
-commit 735e818c38f8cefe0cd90514dac5282845a67dd4
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Tue Mar 4 15:13:23 2008 +0100
-
- Improve testing of coercion in File#chmod specs
-
-commit 77a717f5962b2965ad9146e16cb36bedac891c80
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Mon Mar 3 18:16:04 2008 +0100
-
- Adjusted syslog specs to better handle impls that don't provide syslog.
-
- For example, JRuby does not provide syslog (yet).
-
-commit 605bdc53e9dd4fb95dae6557d9ee6f9e2b8ceb80
-Author: David Whittington <djwhitt@gmail.com>
-Date: Mon Mar 3 08:44:33 2008 +0000
-
- Modified Bignum threshold specs to take into account platform wordsize
-
-commit 0af27d11d7dd68cfe49985dc4588933cc41f4fc8
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Sun Mar 2 16:40:15 2008 -0500
-
- Tag headius's new to_proc spec as failing
-
-commit b1caeeac673451a960917bb699a20e74cf488432
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Sun Mar 2 13:30:35 2008 +0100
-
- Adjusted Kernel#catch test a bit, to make it more generic.
-
-commit 60f9544ade9d6e71fe3e423ab82cc87838478032
-Author: Charles Nutter <headius@wlan100.headius.com>
-Date: Sun Mar 2 04:36:53 2008 -0600
-
- Add a spec for #363, & not coercing using to_proc.
-
-commit 70aa320f7f5bc75ed95362b0fb6d724e64224a88
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Sat Mar 1 17:17:55 2008 -0500
-
- Tweak new Marshal spec to pass on MatzRuby
-
-commit 35476e1bde23de26c01df409b750e91ef981fefc
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Sat Mar 1 17:11:53 2008 -0500
-
- Tag new failing Marshal spec
-
-commit d9f83819f1ed2505740ae0737199fecab29809bb
-Author: Jared Luxenberg <jared@jaredlux.com>
-Date: Sat Mar 1 16:20:18 2008 -0500
-
- Added specs for marshalling subclasses of Hash with init parameters
-
- Test that Marshal.dump gives correct output for such an object (passes)
- Test that Marshal.load is able to deal such an object (fails)
-
-commit 6039a3bd457c5d3dc99f5935999da574d17f1e5d
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Sat Mar 1 16:20:08 2008 -0500
-
- Tweak Process.setrlimit spec for odd Linux platforms
-
-commit 25cfa6a96315ee203d06381ee3ddb76b60023360
-Author: Chuck Remes <cremes.devlist@mac.com>
-Date: Sat Mar 1 10:24:55 2008 -0600
-
- Fixes a race condition on OSX when "find"-ing character devices
-
- - on OSX the spec fixture would return /dev/fd/0 as a character
- device when run from the command line. This always succeeded.
- When run as a subprocess (like from cron or rubuildius'
- IO#popen) then OSX uses /dev/fd/0 and /dev/fd/2 for capturing
- stdin, stdout, stderr and others in that environment. While
- the fixture would "find" /dev/fd/2 as a character device, by
- the time the assertion tested it the underlying OS would change
- it to another device type causing the assertion to fail. This
- is just bad luck. We now grab the #last device found rather
- than the first.
-
-commit b6e95321df023ac989c4e5bb926ec55493260bc9
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Fri Feb 29 16:04:10 2008 +0100
-
- New rubyspecs for IO#ungetc.
-
-commit 9bd2f0740c71d426cfa3c3636c2451762f640c14
-Author: Brian Ford <bford@engineyard.com>
-Date: Thu Feb 28 21:59:35 2008 -0800
-
- Specs for Hash.allocate. Fix awaits replacing Hash with LookupTable in core.
-
-commit c1d979639bfc19072351211815ffd5c8da772dcd
-Author: Brian Ford <bford@engineyard.com>
-Date: Thu Feb 28 21:56:33 2008 -0800
-
- Specs and fixes for Module.allocate.
-
-commit 904fd6136f00bab5fec62e8e702a0508dec44bac
-Author: Brian Ford <bford@engineyard.com>
-Date: Thu Feb 28 19:45:39 2008 -0800
-
- Specs and fixes for Array.allocate.
-
-commit 776a24f0d14bbb5127c804cf0579960335c1a049
-Author: Brian Ford <bford@engineyard.com>
-Date: Thu Feb 28 19:35:55 2008 -0800
-
- Specs for String.allocate and fixes to make them pass.
-
-commit fa35211f357ff1b9660a318c12b86ca156c5f26d
-Author: Ari Brown <ari@aribrown.com>
-Date: Thu Feb 28 20:27:55 2008 -0500
-
- Moved stdlib/syslog.rb to lib/syslog.rb . it works!
-
- * everything runs! yay!
-
-commit 8f103a6f9d7a168e37d1063e40bee960d64fc609
-Author: Ari Brown <ari@aribrown.com>
-Date: Thu Feb 28 19:42:11 2008 -0500
-
- Added specs and the constant module for stdlib/syslog.rb
-
- * added some specs for that which is testable
- * fixed the constant module so the constants are defined
- * fixed 'undefined method' problem in #write (private)
-
-commit 0c89dc90fdcb7933169e23462197d59f9627f510
-Author: Ryan Davis <rdavis@engineyard.com>
-Date: Thu Feb 28 14:31:05 2008 -0800
-
- Added basic throw/catch specs. Fixed raised NameError to contain the name
-
-commit c8f4db4270984b60a087dd423c9e0da3e3760622
-Author: Phil Hagelberg <phil@hagelb.org>
-Date: Thu Feb 28 14:11:30 2008 -0800
-
- tag failing proc spec
-
-commit a1591319696385191f3301516d2f8265cd8fedcb
-Merge: f167f8f... 3f1acce...
-Author: Phil Hagelberg <phil@hagelb.org>
-Date: Thu Feb 28 13:43:52 2008 -0800
-
- Merge branch 'master' of git@git.rubini.us:code
-
-commit f167f8f6f7f3a1b8804a5452643236a23c0ce4c4
-Author: Phil Hagelberg <phil@hagelb.org>
-Date: Thu Feb 28 13:43:40 2008 -0800
-
- failing spec for returning from procs
-
-commit 3f1acce781c0dcf43698441036a085a0cef02d29
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Thu Feb 28 16:14:55 2008 -0500
-
- Basic support for UNIXSocket and UNIXServer
- Fix some 'Errno' typos in socket.rb
-
-commit afbf38613364436630933753d99ee94c03b85074
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Thu Feb 28 21:34:10 2008 +0100
-
- Added specs for File.fnmatch with case-sensitive brackets.
-
-commit 28323bda3d1f3295371b6ea99ed8ba6ee15661bb
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Thu Feb 28 20:47:51 2008 +0100
-
- Added specs for File.fnmatch with '**/' patterns.
-
-commit 893ff4729d024198d5b423cc4426153f49cb5ebe
-Author: Brian Ford <bford@engineyard.com>
-Date: Thu Feb 28 11:30:49 2008 -0800
-
- Fixed lookup of class variables defined in metaclasses.
-
-commit dee531b18d96199d608d8e2e8e27f54ef500a716
-Author: Brian Ford <bford@engineyard.com>
-Date: Wed Feb 27 21:47:13 2008 -0800
-
- Additional Symbol#inspect specs. Another try at making them pass.
-
-commit 3bfb705b709ab35593684a68b35fb0ee8e1e01d7
-Author: Brian Ford <bford@engineyard.com>
-Date: Wed Feb 27 21:46:37 2008 -0800
-
- Silence 'woot' echo on ubuntu from #system specs.
-
-commit 7fb76f2c4a9fb0c5695a38b90150ea6f50097237
-Author: Ryan Davis <rdavis@engineyard.com>
-Date: Wed Feb 27 18:05:48 2008 -0800
-
- Fixed Symbol#inspect from over quoting
-
-commit 4ac32e4c9d0ff55aad50a00944f1a64931cfd1c6
-Author: Ryan Davis <rdavis@engineyard.com>
-Date: Wed Feb 27 17:18:09 2008 -0800
-
- Added some pretty rude specs for Kernel#system and got them to pass.
- Fixed a wierd problem with system/exec not cleaning up the fork process right
-
-commit 73be3b88af1ac96a6d4afabddd2871cfc4691eec
-Author: Brian Ford <bford@engineyard.com>
-Date: Wed Feb 27 15:36:17 2008 -0800
-
- Fix String to properly initialize backing store when subclassed.
-
-commit 5ab2f9e594b7e66a04028e60f3517488e345f508
-Author: Brian Ford <bford@engineyard.com>
-Date: Wed Feb 27 15:04:09 2008 -0800
-
- Scope classes used in String specs.
-
-commit e45d58100850443fedada905f654bae3f4144790
-Author: Charles Nutter <headius@wlan100.headius.com>
-Date: Wed Feb 27 17:04:58 2008 -0600
-
- Add /devices to find commands; Solaris uses /devices instead of /dev.
-
-commit 1403477197873d613cfb93d644f78b4067d180d3
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Wed Feb 27 20:21:48 2008 +0100
-
- Adjusted Env spec, to be able to run it on Solaris.
-
- grep is replaced by egrep, since older greps don't
- take -e parameter (like on Solaris).
-
-commit b239a3b615d341f982a7a4a3a1b1200d95f79684
-Author: Adam Shelly <adam.shelly@gmail.com>
-Date: Wed Feb 27 04:09:24 2008 -0500
-
- Amending specs for Array#pack('U')
-
- * rbx is now passing most specs
- * failing specs are due to String#unpack.
-
- Signed-off-by: Brian Ford <bford@engineyard.com>
-
-commit 328c40e0f24601e739f404ab252652deca477513
-Author: Brian Ford <bford@engineyard.com>
-Date: Wed Feb 27 02:46:21 2008 -0800
-
- Fixed Array instantiation to work with subclasses.
-
-commit 96c4ea885fbd075765b9d234de2754df3c857b07
-Author: Adam Gardiner <adam.b.gardiner@gmail.com>
-Date: Wed Feb 27 09:26:25 2008 +1100
-
- Move Debugger::Output specs to match new location of class
-
-commit c59f16f34f47860b200c6de4a2c1144c566de3dd
-Author: Brian Ford <bford@engineyard.com>
-Date: Tue Feb 26 10:23:14 2008 -0800
-
- Exclude new failing Array specs.
-
-commit 27248a45f079fd5a8cdb9ee71d008d135dcbe63d
-Author: Charles Nutter <headius@wlan100.headius.com>
-Date: Tue Feb 26 00:10:29 2008 -0600
-
- Add additional Array tests from BFTS.
-
-commit a0e156f4c5bc12bf39950afeb58a6962b37efaa7
-Author: Adam Gardiner <adam.b.gardiner@gmail.com>
-Date: Tue Feb 26 16:53:01 2008 +1100
-
- Fix Debugger help output formatting to use wrapping
-
-commit fa5304d42c72a07b09cece99cb22c90f6b399a51
-Author: Adam Gardiner <adam.b.gardiner@gmail.com>
-Date: Tue Feb 26 13:22:31 2008 +1100
-
- Add wrapping to debugger column output
-
-commit 1a5d830b41eef37bb78168c959dd5b2f0757fde4
-Author: Brian Ford <bford@engineyard.com>
-Date: Mon Feb 25 18:58:11 2008 -0800
-
- Conform Bignum#div, #divmod to weird MRI maths.
-
-commit eb5c6e367990bfdd193bcdf3055009f3e3e1aeaf
-Author: Adam Gardiner <adam.b.gardiner@gmail.com>
-Date: Tue Feb 26 13:23:29 2008 +1100
-
- Fix Debugger specs to pass on ci
-
-commit a2feff6782a052a9b71da90e9d4e1b2d991cc598
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Mon Feb 25 18:53:24 2008 -0500
-
- Patch by Jos Backus (josb) - Closes ticket 364 (FreeBSD warnings)
-
-commit cee08883cc3de2e41a88b506f7d7f8d40697eaa2
-Author: Ryan Davis <rdavis@engineyard.com>
-Date: Mon Feb 25 13:20:21 2008 -0800
-
- Fixed autotest churn by removing empty.txt and moving to /tmp
-
-commit f26bb0c4e3b8435a853a9f4843173748d98075fd
-Author: Brian Ford <bford@engineyard.com>
-Date: Mon Feb 25 11:25:10 2008 -0800
-
- Add the rest of spec/* directories to CI process.
-
-commit 29f36833e79de6115c27d744adf158e1b3ba42f0
-Author: Brian Ford <bford@engineyard.com>
-Date: Mon Feb 25 00:29:45 2008 -0800
-
- Excludes for spec/kernel, spec/debugger to run with CI.
-
-commit 12bbdf70af31d5168c2df0a9b53651f94b36899d
-Author: Brian Ford <bford@engineyard.com>
-Date: Mon Feb 25 00:22:13 2008 -0800
-
- Excludes for subtend specs so they will run with CI.
-
-commit 0cbc2b1f20d8aee7ea74eb14e1f9cf242f8b47d5
-Author: Brian Ford <bford@engineyard.com>
-Date: Sun Feb 24 23:57:56 2008 -0800
-
- Remove specs for removed Compression::ZLib.
-
-commit 1b4fbc76c2eb84e5cb45562f54ac105784f9e134
-Author: Brian Ford <bford@engineyard.com>
-Date: Sun Feb 24 23:49:57 2008 -0800
-
- Conform Ar specs.
-
-commit f8e62002711c3cfd8024faca497775f7253a326a
-Author: Charles Nutter <headius@charles-nutters-computer.local>
-Date: Mon Feb 25 05:24:54 2008 +0100
-
- Add a second case for truncating IO buffers that specifies too-small size.
-
-commit 9f3e25289cc52cd3f3fb240de1ad82a16a8b135c
-Author: Nikolai Lugovoi <meadow.nnick@gmail.com>
-Date: Tue Feb 12 23:19:27 2008 +0200
-
- Fixes for String#to_sub_replacement:
-
- * removed String#replace_slashes
- * using plain byte-by-byte scan instead of regexps to detect and handle backslash escapes
- * better handle unknown escapes and cases like '\\\1'
- * updated specs for String#sub
-
- Signed-off-by: Brian Ford <bford@engineyard.com>
-
-commit d87df0b7634ae37f85fc8f2795e4c8c425614b11
-Author: Charles Nutter <headius@charles-nutters-computer.local>
-Date: Mon Feb 25 02:57:27 2008 +0100
-
- Add a spec for Enumerable#inject with a *arg; JRUBY-2162 exposed it.
-
-commit f04fcabf8c064dfcbf3b118bdc83289da169a30c
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Sun Feb 24 21:24:51 2008 +0100
-
- truncate behaves different on OpenBSD, changed specs according to MRI behavior
-
-commit b74a2f45b32a02469d61d4ace04912ec25f19543
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Sun Feb 24 20:18:02 2008 +0100
-
- Looks like Darwin does provide Process::RLIMIT_AS
-
-commit 7113973abff64eeb1304b15be46f07d301d84f3f
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Sun Feb 24 18:25:55 2008 +0100
-
- OpenBSD doesn't provide Process::RLIMIT_AS, so this spec should be excluded
-
-commit 49b72719bf5c732f4aa2ad0d70e5a224556fb471
-Author: oleg dashevskii <be9@be9.ru>
-Date: Sun Feb 24 11:04:07 2008 +0600
-
- Spec for method taking lambda and block.
-
- * should raise SyntaxError
- * passes on MRI
- * fails on rubinius
-
- Signed-off-by: oleg dashevskii <be9@be9.ru>
-
-commit 60bbc8506d70571249972dbf124df520f0a4a476
-Author: Chuck Remes <cremes.devlist@mac.com>
-Date: Sat Feb 23 10:23:09 2008 -0600
-
- Fix unpack_spec expectation for little-endian byte ordering
-
- Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
-
-commit 17e45cee97057684e6c24608f97de48c28947384
-Author: Chuck Remes <cremes.devlist@mac.com>
-Date: Sat Feb 23 09:44:37 2008 -0600
-
- Fix unpack to use native host byte order for formats /ILQS/
-
- - unpack_spec had a bad expectation on little-endian platforms
- - unpack_spec got some updated description strings to correctly identify
- the host byte ordering expected in the spec
- - kernel/core/string.rb now unpacks formats /ILQS/ in the platform's native byte
- ordering
-
- Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
-
-commit 1540cb7caa0f200ed6d318971fb7302cd089e27d
-Author: Chuck Remes <cremes.devlist@mac.com>
-Date: Sat Feb 23 08:10:00 2008 -0600
-
- Add some missing endian guards to the unpack_spec
-
- - in my haste, forgot one set of guards around some specs
-
- Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
-
-commit 8488676fc0dac5db5d01dd92e061476226d58bd1
-Author: Chuck Remes <cremes.devlist@mac.com>
-Date: Sat Feb 23 00:19:33 2008 -0600
-
- Fix several Array#pack and String#unpack bugs related to byte ordering (endiannes)
-
- - added a small utility method endian? to the kernel module; determines host byte
- ordering by taking a symbol (:big, :little) and comparing it to Rubinius::ENDIAN
- - modified Array#pack to check for the native byte ordering for /ils/i formats
- - modified String#unpack to use native byte ordering for /DdFfIiLlQqSs/ formats
- - modified String#extract_number to do special processing for big-endian platforms
- and for formats using native byte ordering on a big-endian platform
- - added little_endian and big_endian guards around several String#unpack specs;
- now passes running against MRI and rbx
-
- Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
-
-commit f8146d29bfdf67349f3f9c0c7105ce595981255f
-Author: Gianluigi Spagnuolo <glgspg@gmail.com>
-Date: Sat Feb 23 12:44:25 2008 +0100
-
- Added some test to Regexp.quote to manage tab and white space
-
- Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
-
-commit 714efa8574687e1fd31f904a4f35cce8056719f5
-Author: Brian Ford <bford@engineyard.com>
-Date: Sat Feb 23 00:01:38 2008 -0800
-
- Fixed Digest specs to pass with RSpec.
-
-commit a0fe2f7fa080729b77b32ffe21be5705a162ed71
-Author: Eric Hodel <ehodel@engineyard.com>
-Date: Fri Feb 22 22:26:52 2008 -0800
-
- Remove ffi_decode_sockaddr, replace with existing ruby code.
-
-commit b2baf0911e4a88ba2f6c4cb8e3e31d2a3aa1c6bf
-Author: Eric Hodel <ehodel@engineyard.com>
-Date: Fri Feb 22 17:06:18 2008 -0800
-
- Move Ar to kernel/core.
-
-commit 01baf002a8c7bd6e249b9477c1f78e6b99a67bf6
-Author: Philipp Bruschweiler <blei42@gmail.com>
-Date: Wed Jan 16 00:11:12 2008 +0100
-
- added specs for SHA256/384/512
-
- these specs were as well shamelessly copied from the md5 specs.
- they work, but every sha* class has a folder for itsself, that's a
- lot of duplicatd code. maybe someone with more experience in
- writing specs should have a look at this.
-
- Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
-
-commit 924224fcf655da90148ebd8234033a71e1b23090
-Author: Caleb Tennis <ctennis@engineyard.com>
-Date: Fri Feb 22 17:13:14 2008 -0500
-
- Catch no block given in rb_yield, raise LocalJumpError
-
- As well, define that as an exception for subtend
-
- Update spec
-
-commit 3748843421832df5b842a677ddd2e55fbefb0b5f
-Author: Caleb Tennis <ctennis@engineyard.com>
-Date: Fri Feb 22 17:04:33 2008 -0500
-
- Update rb_yield spec
-
-commit f60ca442b1466f29432995700457e8b34f4ff294
-Author: Caleb Tennis <ctennis@engineyard.com>
-Date: Fri Feb 22 17:00:36 2008 -0500
-
- Fix rb_yield call
-
-commit a75afc4595fd20d7853ff65afe015de88b265b93
-Author: Caleb Tennis <ctennis@engineyard.com>
-Date: Fri Feb 22 16:48:17 2008 -0500
-
- Add blocks to subtend methods, as they should be able to access them like any other method.
-
- Also, update the spec
-
-commit d9911f8b00243f3c95759612dde35edf6edaa678
-Author: Caleb Tennis <ctennis@engineyard.com>
-Date: Thu Jan 31 13:54:24 2008 -0500
-
- Add block specs and rb_block_given_p
-
-commit b6c806f0d8213c4751c69638174f60b80f9ba303
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Fri Feb 22 15:31:58 2008 -0500
-
- Failing spec and exclude for left-to-right masgn evaluation order
-
-commit 8f9e3c9e5e7dfc535e8fe6b10b945587586651ec
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Fri Feb 22 13:59:44 2008 +0100
-
- Fix Socket#getservbyname, not every platform defines http/udp
-
-commit f29ff3bcaf0bf83d2924d08ea5f6c0bbb5df9948
-Author: Eric Hodel <ehodel@engineyard.com>
-Date: Thu Feb 21 16:47:02 2008 -0800
-
- Allow Ar to create archives
-
-commit e50ec6470dfc905198065a98b65b33a99da60e15
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Thu Feb 21 20:20:41 2008 -0500
-
- Some compiler specs for 'defined?' handling
-
-commit ba5a0d87182d83000205e1202f5c473568a50489
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Fri Feb 22 01:08:51 2008 +0100
-
- Fixed #332 and cleaned up Time a bit. Thanks to gls
-
-commit edf1e0d530ebb39a1b46d0fa518b9ca85db544da
-Author: Evan Phoenix <ephoenix@engineyard.com>
-Date: Thu Feb 21 02:01:21 2008 -0800
-
- Fix the last usage of block return (ie, internal long return).
-
- * LongReturnException is now used whenever a block requests that
- it's home context should return.
-
-commit 83ed7161701202d48490e7f38b568bc504f9690f
-Author: Brian Ford <bford@engineyard.com>
-Date: Wed Feb 20 23:59:47 2008 -0800
-
- Added little/big_endian guards to Array#pack and String#unpack specs.
-
-commit 65b4ed86002371f2b56759aadc61e61c1cbbdba4
-Author: Brian Ford <brixen@gmail.com>
-Date: Wed Feb 20 22:49:19 2008 -0800
-
- Exclude Socket#unpack_sockaddr_in spec. See tag comment.
-
-commit 9fbda05c4dffb964a9f10e26d62240fbd52200a0
-Author: Brian Ford <brixen@gmail.com>
-Date: Wed Feb 20 22:48:31 2008 -0800
-
- Exclude super slow IPAddr specs.
-
-commit 3d39fb35dcd3c28fa626aeb96057b927c6bfe7c9
-Author: Brian Ford <bford@engineyard.com>
-Date: Wed Feb 20 18:54:50 2008 -0800
-
- Redo expectation in Socket#getaddrinfo spec.
-
-commit 69576ede38d9bf09d1afd0120726ca756a0aa7cf
-Author: Brian Ford <bford@engineyard.com>
-Date: Wed Feb 20 18:31:27 2008 -0800
-
- Account for variable length array in Socket#getaddrinfo.
-
-commit f396bd718572d9402d0d7eeb8da02474914396a8
-Author: Brian Ford <bford@engineyard.com>
-Date: Wed Feb 20 17:59:29 2008 -0800
-
- Use File.delete in YAML specs instead of rm.
-
-commit 7698ec3855ce572f1e10962596804b82f3cd6534
-Author: Adam Gardiner <adam.b.gardiner@gmail.com>
-Date: Thu Feb 14 10:07:48 2008 +1100
-
- Hook-up new StepBreakpoint to new debugger step commands
-
- * The commands step and stepi have now been added to the
- debugger, and step into called methods.
- * The commands next, nexti and out have been converted
- to use the new StepBreakpoint. The legacy versions
- remain, but have been renamed as ln, lni, and lo; these
- will be removed once the new commands have proven stable.
- * Replaced VM method cache command with VM send site command
- to show details of SendSites in the current method.
-
-commit f192d65ec5eb31b4a807b9c3eb7360b84739d9f2
-Author: Adam Gardiner <adam.b.gardiner@gmail.com>
-Date: Thu Jan 31 16:43:19 2008 +1100
-
- Initial implementation of StepBreakpoint
-
- StepBreakpoint class moves step logic out of the Debugger
- and into breakpoint, where it more logically belongs.
-
-commit fd0ff43d2d384e221ff8de611843f3406d192657
-Author: Brian Ford <bford@engineyard.com>
-Date: Wed Feb 20 17:04:46 2008 -0800
-
- Fixed YAML spec to pass MRI. Added fails tag for rbx.
-
-commit d69834a5217ddc6667b495fbe7d4dd8ad413ba88
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Wed Feb 20 15:42:25 2008 -0500
-
- Fix dead code in TCPSocket.new specs
-
-commit 4644222e63046783933ca9b2e4514e3ff21fbb57
-Author: Brian Ford <bford@engineyard.com>
-Date: Wed Feb 20 12:31:14 2008 -0800
-
- Add missing tag file for method_spec.
-
-commit 230d5d506f4203bcd3922880fae506fa480e6308
-Author: Brian Ford <bford@engineyard.com>
-Date: Wed Feb 20 12:17:13 2008 -0800
-
- Fix typo in socket specs.
-
-commit a5d49537832a9cc33b07cade265af0834f123533
-Author: Brian Ford <bford@engineyard.com>
-Date: Wed Feb 20 12:09:11 2008 -0800
-
- Move specs for calling methods to language/method_spec.rb.
-
-commit ead32a1f2820a4e2fcc906a8e7f3603490ba901c
-Author: Brian Ford <bford@engineyard.com>
-Date: Wed Feb 20 11:53:45 2008 -0800
-
- Use bignum_value where a Bignum is intended in the specs.
-
-commit 1021345337bca1f928879713cb84a76b9c7935a1
-Author: Brian Ford <bford@engineyard.com>
-Date: Wed Feb 20 10:21:42 2008 -0800
-
- Removed unused require 'stringio' from io/syswrite specs.
-
-commit cfd51af482321b4d672d69569de185f582a21831
-Author: Brian Ford <bford@engineyard.com>
-Date: Wed Feb 20 09:00:36 2008 -0800
-
- Symbols as Fixnums is long deprecated. We don't spec it.
-
-commit a8bd2a1aba97653625a9b568d1a7112b5fce45f6
-Author: Brian Ford <bford@engineyard.com>
-Date: Wed Feb 20 00:15:54 2008 -0800
-
- RbYAML is not in Ruby standard lib. Move specs for it to spec/library/rbyaml.
-
-commit 56b454af2ded18d0459bc974efa666ccf3b8de0f
-Author: Brian Ford <bford@engineyard.com>
-Date: Wed Feb 20 00:10:24 2008 -0800
-
- Restrict specs in spec/ruby/1.8 to current stable 1.8 version.
-
-commit 22e01d1914db92d159ee15d3cf73c9d6e9d0a24b
-Author: Brian Ford <bford@engineyard.com>
-Date: Tue Feb 19 23:20:27 2008 -0800
-
- Fix Dir#pos=/#seek specs. We shouldn't spec undefined platform behavior.
-
-commit d522af83d0cfcdf39932afff7ba7d75d77dd0453
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Wed Feb 20 11:51:44 2008 +0100
-
- New IO.read specs.
-
-commit 77fdbe404e31f44e1c302eb99a7ff129523183ce
-Author: Eric Hodel <ehodel@engineyard.com>
-Date: Tue Feb 19 16:14:43 2008 -0800
-
- Add library to read/write ar(5) files
-
-commit d7702f979732de90358dc35d795c6ac621f815bc
-Author: Matthijs Langenberg <mlangenberg@gmail.com>
-Date: Mon Feb 18 18:04:27 2008 +0100
-
- writen some examples for Base64 module
-
- Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
-
-commit 33b189478c05bd687ac8b062cd5307a3290d8931
-Author: Brian Ford <bford@engineyard.com>
-Date: Tue Feb 19 00:27:51 2008 -0800
-
- Convert platform guard :size option to :wordsize.
-
-commit cbcdb8346a2c75ba65910b486cee718cd3aa5175
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Feb 18 23:07:41 2008 -0800
-
- Exclude TCPSocket.new for now, hangs on ubuntu gutsy.
-
-commit ec990b6ebcd35cbf9dc192852f37e184c3e4079b
-Author: Adam Gardiner <adam.b.gardiner@gmail.com>
-Date: Tue Feb 19 15:55:25 2008 +1100
-
- Re-enable debug on context change
-
- The cpu_yield_debugger_check was not being performed as
- a result of changes to method dispatch related to the
- implementation of SendSite.
-
-commit aa585b7e637e2fd873602ee6725256429f413582
-Author: Brian Ford <bford@engineyard.com>
-Date: Mon Feb 18 18:59:18 2008 -0800
-
- Removed :version guarded specs that are not current stable.
-
-commit 431af5920a0a02dfca927961a2d6457ae5f050e2
-Author: Brian Ford <bford@engineyard.com>
-Date: Mon Feb 18 17:40:56 2008 -0800
-
- Added new tags files for excludes.
-
-commit 10dd37903533cac9a6f77ead70f3aa9ee1dc9098
-Author: Brian Ford <bford@engineyard.com>
-Date: Mon Feb 18 16:38:58 2008 -0800
-
- Removed deprecated $deferr from getoptlong.rb. Moved to /lib.
-
- Small fixes to other library specs to get them running under CI.
-
-commit ee2dabf771a5e6d8d70c47fa49b1298d2d002c8c
-Author: Brian Ford <bford@engineyard.com>
-Date: Mon Feb 18 00:42:54 2008 -0800
-
- Use the spec guards properly.
-
-commit 91d6c64be8827768ba2e39b80a4eb81b9affc122
-Author: Brian Ford <bford@engineyard.com>
-Date: Sun Feb 17 22:40:21 2008 -0800
-
- Deprecate #setup, #teardown in specs; use #before, #after.
-
-commit 6ba49012504c08973e1fb2fd1b9fce75c351d148
-Author: Brian Ford <bford@engineyard.com>
-Date: Sun Feb 17 22:00:56 2008 -0800
-
- The #fails_on guard has been removed. Use #ruby_bug or tagged excludes.
-
-commit e24231f5c62c0b73768c7503f50b53e8ffc345d1
-Author: Brian Ford <bford@engineyard.com>
-Date: Sun Feb 17 21:08:01 2008 -0800
-
- Renamed *_excludes.txt to *_tags.txt for specs.
-
-commit a1c707b517e13115692173bc2048309e74c00915
-Author: Brian Ford <bford@engineyard.com>
-Date: Sun Feb 17 20:45:14 2008 -0800
-
- Hand merge recent excludes changes to spec/tags directory.
-
-commit 838bee7e99bb1179c9a3a7782dcab9c2b904e72e
-Author: Brian Ford <bford@engineyard.com>
-Date: Sun Feb 17 00:17:51 2008 -0800
-
- Moved excludes from spec/data to spec/tags. Added "fails" tags.
-
-commit 8ad91b03788d89ccd12fbcf19c06c9ef4f0cfee8
-Author: Brian Ford <bford@engineyard.com>
-Date: Mon Feb 4 19:19:00 2008 -0800
-
- Misc fixes to get MSpec running specs.
-
-commit a683dd75786ab6c6a255c9bac399dc6be7aaa4b5
-Author: Tyler McMullen <tbmcmullen@gmail.com>
-Date: Sat Feb 16 23:39:38 2008 -0500
-
- Add support for H and h to Array#pack.
-
- * Updated array/pack_spec with specs for H and h, separately
- * Updated Array#pack to handle both with a single block of code
-
- Signed-off-by: Brian Ford <bford@engineyard.com>
-
-commit b1d3ba9d10f6a9ea87d8cb9be21d0d432e973117
-Author: oleg dashevskii <be9@be9.ru>
-Date: Mon Feb 18 01:18:24 2008 +0600
-
- Update specs for calling methods.
-
- Nasty binding stuff (first noted in #293) got specced and put into excludes.
-
-commit 02225daa5cef4fa3f48cac73d4bf0f9d02f3ebe0
-Author: oleg dashevskii <be9@be9.ru>
-Date: Sun Feb 17 23:20:08 2008 +0600
-
- Cross-breed and update for, while & until language specs. Little fix for hash spec.
-
- The compiler drops out on "for @@var in 1..3", so this is commented out.
- Variable scope stuff arrived into excludes.
-
-commit f43383a150131278d30535196e8da4e60dff97b1
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Sun Feb 17 13:10:55 2008 +0100
-
- New specs for RangeExceptions out of Fixnum and Array methods.
-
-commit 7d1c744d9c1ae50376be406a28e383a04ca6b4fc
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Sat Feb 16 13:49:11 2008 +0100
-
- Corrected copy-paste error in recent fixnum specs.
-
-commit 08982321472008f7645212289d2624d19053ed7e
-Author: Eric Hodel <ehodel@engineyard.com>
-Date: Fri Feb 15 21:18:53 2008 -0800
-
- Fix IO#read for large files and small parts of files.
-
- Fix IO#read with buffer.
-
- Fix IO#eof? when buffer reaches eof.
-
-commit 1d07588d61b3835a6165c5de1f731277812cff79
-Author: Eric Hodel <ehodel@engineyard.com>
-Date: Fri Feb 15 19:11:42 2008 -0800
-
- Add missing spec for IO#eof? and fix.
-
-commit e0a6c8e179e48b423b6eb142b27460cd86d0223b
-Author: Eric Hodel <ehodel@engineyard.com>
-Date: Fri Feb 15 17:50:47 2008 -0800
-
- (Last change was ok). Force check for data so #eof? works
-
-commit d7e67c257c213f9e25b3123ce85576feb71a0089
-Author: Eric Hodel <ehodel@engineyard.com>
-Date: Fri Feb 15 17:28:48 2008 -0800
-
- Revert "Force a check for more data on the IO for IO#eof?"
-
- This reverts commit 3d4427e802756678608bf9840ba6f26fc81cf7fe.
-
-commit 4c1182c184bb6c2c97c5fc8ce83f242fe5f5144b
-Author: Eric Hodel <ehodel@engineyard.com>
-Date: Fri Feb 15 17:26:08 2008 -0800
-
- Force a check for more data on the IO for IO#eof?
-
-commit 94466db3347889850feb25dd7c83883df21bac92
-Author: Brian Ford <bford@engineyard.com>
-Date: Fri Feb 15 14:13:29 2008 -0800
-
- Added Float examples to Bignum bitwise operator specs.
-
-commit 3a668451d3bcc46b162a69ce1f8ec5d6a98b2d22
-Author: Brian Ford <bford@engineyard.com>
-Date: Fri Feb 15 13:44:24 2008 -0800
-
- Added bignum_value helper. Added specs for Fixnum bitwise operators.
-
-commit 217eb67a4c2f0bf1222628abfecfadbede5fb3b8
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Fri Feb 15 21:09:43 2008 +0100
-
- Fix process specs for FreeBSD
-
-commit f25e0e130110ebbef0b5bc0c28c9b08db6c73a1f
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Fri Feb 15 13:18:40 2008 +0100
-
- Removed now working exclude for Array#sort
-
-commit 56af7be26dcc9b7270de6d96e73e09a4f17cc710
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Thu Feb 14 20:48:37 2008 -0500
-
- Improved Array#sort, #sort! specs.
-
-commit 714ea4b5245172cc6d5c815ef7399d1a991dd83f
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Wed Feb 13 10:30:22 2008 -0500
-
- Improved Array#sort specs a bit.
-
-commit 8944e873848c610182405c2de466e41e6260573d
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Wed Feb 13 02:34:37 2008 -0500
-
- Tuple#swap specs.
-
-commit 24199f731dba40b72af6d121121dec9f085f890d
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Thu Feb 14 20:03:16 2008 +0100
-
- New rubyspecs for IO#reopen.
-
-commit 4f70320e5b7089c74b3899216763cd37d8854230
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Thu Feb 14 17:27:32 2008 +0100
-
- Removed JRuby-specific guards. Please don't use guards to hide bugs.
-
- Guards to be used only when it is agreed that the JRuby behavior
- is intentionally differs from MRI. For plain bugs, guards should
- not be used. Instead, we maintain spec exclusions in JRuby repository.
-
-commit 0198a11b3bdf60983846a6c722dfa11d1b9f57bb
-Merge: ef3393e... 1f1e32e...
-Author: Mutwin Kraus <mutwin.kraus@blogage.de>
-Date: Thu Feb 14 15:57:57 2008 +0100
-
- Merge branch 'mutle_file_specs_refactoring'
-
-commit 1f1e32e5e1fd12fb323e2a74a7f5caae96aa867b
-Author: Mutwin Kraus <mutwin.kraus@blogage.de>
-Date: Thu Feb 14 15:18:14 2008 +0100
-
- Specs for File#chown #flock and #truncate now pass on JRuby
-
-commit 3a8e601d5205e050f83179376d2be3e922e80c20
-Author: Adam Gardiner <adam.b.gardiner@gmail.com>
-Date: Thu Feb 14 17:25:02 2008 +1100
-
- Fix context specs to wait for debug listener thread
-
-commit 608d7a99e75d293d6f9786cee940c0dd23156be3
-Author: Mutwin Kraus <mutwin.kraus@blogage.de>
-Date: Thu Feb 14 12:59:32 2008 +0100
-
- Adding guards to only run File#chown and File.chown specs as root.
-
-commit b3a1069cf6c18b844b9eced32b7bcdb91ad7c558
-Author: Brian Ford <bford@engineyard.com>
-Date: Thu Feb 14 01:31:47 2008 -0800
-
- Rework Bignum#==. Change Numeric#== to conform to MRI.
-
-commit 4eb58ebc45b2ee79f01d75fdb3e9104c73ad66e2
-Author: Eric Hodel <ehodel@engineyard.com>
-Date: Wed Feb 13 23:56:37 2008 -0800
-
- Common implementation for Zlib::Inflate and Zlib::Deflate.
-
-commit 1804fdacce5c195a90befe502706d1f1e066e886
-Author: Brian Ford <bford@engineyard.com>
-Date: Wed Feb 13 19:31:20 2008 -0800
-
- Port of JRuby's File.fnmatch to Ruby (yeah, like writing Java in Ruby).
-
-commit 1a78da8438535ee8ed231359bdb15ff3624c6b37
-Author: Mutwin Kraus <mutwin.kraus@blogage.de>
-Date: Thu Feb 14 01:27:52 2008 +0100
-
- Adding File#truncate improvements from #325 and #326
-
-commit 5b62acbdcf0aab2e89be5ac3e12859ae36cd6950
-Author: Mutwin Kraus <mutwin.kraus@blogage.de>
-Date: Thu Feb 14 00:47:53 2008 +0100
-
- Adding File#truncate with specs
-
-commit 1a2b3dde4f67abe0936e7ec6fb749e5bb8fda7d2
-Author: Mutwin Kraus <mutwin.kraus@blogage.de>
-Date: Thu Feb 14 00:36:32 2008 +0100
-
- Adding File#chown with specs
-
-commit e132cd6f11285f0e106a5d2a292e23c8375fa1ee
-Author: Mutwin Kraus <mutwin.kraus@blogage.de>
-Date: Thu Feb 14 00:12:31 2008 +0100
-
- Renamed File#flock spec to properly reflect an instance method
-
-commit 00cd22ccdf2b70fa53693000d4a5bb803c7d6df6
-Author: Mutwin Kraus <mutwin.kraus@blogage.de>
-Date: Thu Feb 14 00:07:05 2008 +0100
-
- Adding File::flock with specs
-
-commit 3c9b3e4e4272889dd26ec9ddb25f7aaf88c6c380
-Author: Mutwin Kraus <mutwin.kraus@blogage.de>
-Date: Wed Feb 13 23:25:30 2008 +0100
-
- Adding File::chown with specs
-
- * The spec works fine on OS X, but was not tested anywhere else
-
-commit c894a6c46b4a3d0b9010020c394d3ba366bf145e
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Wed Feb 13 11:59:38 2008 +0100
-
- Module#undef_method should accept string parameter, not only symbols by Nikolai Lugovoi (#321)
-
-commit c968d5c29cc3126c789cf5bb2005bd9637e85312
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Wed Feb 13 11:52:10 2008 +0100
-
- Update excludes for File#truncate
-
-commit 408e69864546aea061e006073bb452b8db8c4610
-Author: Ragnar Dahlén <r.dahlen@gmail.com>
-Date: Wed Feb 13 11:15:31 2008 +0100
-
- Implement File.truncate, passes specs.
-
- * Adds truncate, ftruncate (not used yet) to posix.rb
-
- Only tested on Mac OS X 10.5.1.
-
- Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
-
-commit 5c75721d5a78e25a77e9f068bf4c95e729604959
-Author: oleg dashevskii <be9@be9.ru>
-Date: Wed Feb 13 11:26:34 2008 +0600
-
- Remove tests that have been superseded by precedence_spec.
-
-commit 83a372674786a0be51a206cadcae644d72a1e8d2
-Author: oleg dashevskii <be9@be9.ru>
-Date: Wed Feb 13 11:05:34 2008 +0600
-
- Made a real precedence_spec.
-
- One test still commented out till the bug with flip2 is fixed.
-
-commit c3988a4a906594c050e058add8aa6996870dc115
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Wed Feb 13 02:10:49 2008 +0100
-
- Remove excludes for File#stats specs
-
-commit 1624b463d0f70a27b6772d90626c94b6eed4e5c4
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Tue Feb 12 18:25:05 2008 -0500
-
- Add specs for pass subclasses of Module to 'include'
-
-commit 64b0fb4131276feda0d0ab13301824b20f8d7f8e
-Author: oleg dashevskii <be9@be9.ru>
-Date: Wed Feb 13 00:49:37 2008 +0600
-
- Make Dir.chdir spec work when /home is symlinked to /usr/home.
-
-commit 8cbf6312df160f30e284a4537039f808a42543fe
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Tue Feb 12 12:30:19 2008 -0500
-
- Add failing Array#sort spec and matching exclude
-
-commit 9bef807b3b469b8790edbe96f1442394d528cb5a
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Tue Feb 12 12:09:11 2008 -0500
-
- Move Time#<=> specs around until the descriptions make sense
-
-commit 60fbbc62cb04b2fddcd406f01f906482fbc84370
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Tue Feb 12 05:33:49 2008 +0100
-
- Mark JRuby as not deviating from MRI on unboundmethod specs.
-
-commit 4e6d8f7e3326f937a6916ed11984172670a71094
-Author: Yehuda Katz <ephoenix@engineyard.com>
-Date: Mon Feb 11 23:26:31 2008 -0800
-
- Zlib.adler32
-
-commit 2f2d10e1aa57bae79f7fcda5e5a30b2a2ef3e37c
-Author: Yehuda Katz <ephoenix@engineyard.com>
-Date: Mon Feb 11 23:12:40 2008 -0800
-
- Zlib.crc_table
-
-commit 49b9e4b624074d151e89f078c4080a0a7584abaa
-Author: Yehuda Katz <ephoenix@engineyard.com>
-Date: Mon Feb 11 22:56:52 2008 -0800
-
- Zlib#crc32
-
-commit 7cb2ebfa008afc96135912ceefdbd81b1cd7e478
-Author: Eric Hodel <ehodel@engineyard.com>
-Date: Mon Feb 11 17:36:32 2008 -0800
-
- Fix class variables for RDoc.
-
-commit 571d837bbeff221daacebc79c1ccab7de15c77f2
-Author: Brian Ford <bford@engineyard.com>
-Date: Mon Feb 11 08:54:36 2008 -0800
-
- Exclude [r]dev_(major|minor) specs. We need some autoconf facilities.
-
-commit fb2bc81d50bf504e3997d009e3c13f841b859803
-Merge: 55a52f1... 9b58a59...
-Author: Jonas Pfenniger <zimbatm@oree.ch>
-Date: Mon Feb 11 16:19:02 2008 +0100
-
- Merge branch 'master' of git@git.rubini.us:code
-
-commit 55a52f18133fc9f92eef64838008a83dfaab3ffc
-Author: Jonas Pfenniger <zimbatm@oree.ch>
-Date: Mon Feb 11 16:18:37 2008 +0100
-
- Removed Math.asinh excludes.
-
- It wasn't working on OS X. Evan fixed the culprit FFI over the weekend.
-
-commit 9b58a59ca21c6622d246e629410230bfbe8cd4ce
-Author: makoto kuwata <kwa@kuwata-lab.com>
-Date: Mon Feb 11 21:24:05 2008 +0900
-
- Modified to address differences of SyntaxError class between MRI and Rubinius in 'erb/filename_spec.rb'
-
- Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
-
-commit d1c4280b70b82d6cd541251e3d7e1a3091fb304f
-Author: makoto kuwata <kwa@kuwata-lab.com>
-Date: Mon Feb 11 20:19:12 2008 +0900
-
- Add 'erb/util/shared/url_encode.rb' which is missed file
-
- Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
-
-commit b4b1114ac7dffabd672d462b5857a7e1957e8f07
-Author: makoto kuwata <kwa@kuwata-lab.com>
-Date: Mon Feb 11 19:10:58 2008 +0900
-
- Add spec files for erb.rb
-
- Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
-
-commit dfdf90968e78f14e0755b5f3279ec878034dbdb5
-Author: Yehuda Katz <ephoenix@engineyard.com>
-Date: Mon Feb 11 00:09:23 2008 -0800
-
- Added singleton specs (and reorganized stale one):
- * Singleton#_dump
- * Singleton._load
- * Singleton#instance
- * Singleton.instantiate?
- * Singleton.new and Singleton.allocate
- * Singleton#dup and Singleton#clone
-
-commit 54c4a4cab187be4328d6a810bae4bc4bd01ca1d8
-Author: Brian Ford <bford@engineyard.com>
-Date: Sun Feb 10 20:19:30 2008 -0800
-
- Additional specs for File::Stat#rdev, #rdev_major, #rdev_minor.
-
-commit 6b2f05af4758c488b3e2e3b19ee9d2e872817932
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Sun Feb 10 23:00:41 2008 -0500
-
- Rubinius now passes all 'super' specs
-
-commit 5be84fce241c67bd8439bccbe54cec575b0ea93a
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Sun Feb 10 22:53:11 2008 -0500
-
- Failing spec for 'super' behavior
-
-commit 975d51e80d3df437eaa8ddd3c3384a5766255b12
-Author: Brian Ford <bford@engineyard.com>
-Date: Sat Feb 9 15:18:37 2008 -0800
-
- Exclude Process constants spec until LFS is fixed on 32bit linux.
-
-commit 236def62bcfa3dca75a6eebf378a68235c4613ed
-Author: Yehuda Katz <ephoenix@engineyard.com>
-Date: Sat Feb 9 17:04:59 2008 -0500
-
- Fixes exclude
-
-commit 26bedb481b45e77434b487c6395903c6110ef99e
-Author: Yehuda Katz <ephoenix@engineyard.com>
-Date: Sat Feb 9 16:01:58 2008 -0500
-
- Moved bad variables spec out
-
-commit 87efbf9036e5c524e1b40481c89107538d574ba8
-Author: Brian Ford <bford@engineyard.com>
-Date: Sat Feb 9 11:26:30 2008 -0800
-
- Revert all File::Stat stuff. We'll fix Dir first.
-
-commit 1f5bc0f98a23fc90b9bd00048af1551df8e534f7
-Author: Brian Ford <bford@engineyard.com>
-Date: Sat Feb 9 00:39:20 2008 -0800
-
- Reduced File::Stat.stat primitive further. Details follow.
-
- * Added ffi_major and ffi_minor to calculate the major, minor
- parts of st_dev and st_rdev.
- * Added (temporary) new primitive basic_stat to change the
- return type from a tuple to a single MemoryPointer instance.
- * Added simple specs for rdev, rdev_major, rdev_minor, nlink.
-
-commit e478731a2fc558c62cecbe327c5b35882d90b53d
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Fri Feb 8 16:45:05 2008 +0100
-
- One more rubyspec for File#open.
-
-commit 5f6ac709500cb64df110a44d31e0c0b89dd68aec
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Fri Feb 8 16:39:47 2008 +0100
-
- New rubyspecs for File#umask.
-
-commit fddaa684bd7e8c403ff96179ca71a5837f609b63
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Fri Feb 8 16:30:20 2008 +0100
-
- New File#chmod rubyspecs.
-
-commit ed20c3f9f36f343a37e2ac05ea91d84b54c87bc8
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Fri Feb 8 12:00:57 2008 -0500
-
- Correctly guard Bignum specs for CI
-
-commit 36e9749984d6e4412c26d348afa8c501cf043ecf
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Fri Feb 8 13:09:37 2008 +0100
-
- Some more specs for File#new and File#open, and permissions.
-
-commit 29376695550c5608f466d63d49de76a6ee163e37
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Fri Feb 8 12:10:27 2008 +0100
-
- New specs for IO#new and IO#open, invoked with permissions parameter..
-
-commit 8cf27fcd86f88b75716b65dc1d94b721c01c3af9
-Author: oleg dashevskii <be9@be9.ru>
-Date: Fri Feb 1 21:03:08 2008 +0600
-
- Heredocs and more stuff added to string_spec.
-
-commit 2cccd38a081c0303f8fa567058e4c26fa354abc5
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Fri Feb 8 12:51:53 2008 +0100
-
- Add exclude for currently failing for_spec
-
-commit 031bb1b565a3446ab995ea55e6ae8890573ba6c0
-Author: oleg dashevskii <be9@be9.ru>
-Date: Fri Feb 1 20:23:56 2008 +0600
-
- Added more tests to for expression spec.
-
-commit 73e40331c6b4c1c1b6e41ae312299f6815e089c2
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Thu Feb 7 19:12:46 2008 -0500
-
- Add a failing spec for Array#join and then fix it
-
-commit fa49548fe704252c352a1bc4833b5da20262061a
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Thu Feb 7 23:12:03 2008 +0100
-
- Fix last two Failing Time specs for Time#+ and Time#-
-
-commit e4e51c6aa39e5a5a61b0df919ba02b88d4878f43
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Thu Feb 7 22:35:57 2008 +0100
-
- Fix Time.at so it also works with floats
-
-commit f5505522fd0396c3864fce155681ac577bf2e7e6
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Thu Feb 7 17:10:48 2008 +0100
-
- Fix Time#<=> for objects other than Time
-
-commit e8ab7b5eb30da84262a9395e20ac420e83674edf
-Author: Eric Hodel <ehodel@engineyard.com>
-Date: Wed Feb 6 13:59:18 2008 -0800
-
- Only call Class#inherited once
-
-commit dc9ff28ae919292287f5562b8c105ff6310c5920
-Author: Phil Hagelberg <phil@hagelb.org>
-Date: Wed Feb 6 15:00:59 2008 -0800
-
- Kernel#eval should be a module function
-
- Added a spec as well
-
-commit 7dd83410a2159fd65f951689a8a1297baded4fa6
-Merge: 698ffa4... 339fed9...
-Author: Mutwin Kraus <mutwin.kraus@blogage.de>
-Date: Wed Feb 6 22:54:12 2008 +0100
-
- Merge branch 'master' of git@git.rubini.us:code
-
-commit 698ffa4e04fee58da5c3f2191372c4e4f2bc070d
-Author: Mutwin Kraus <mutwin.kraus@blogage.de>
-Date: Wed Feb 6 22:51:54 2008 +0100
-
- Adding missing specs for ftools
-
- * specs for chmod, compare, copy, install, makedirs, move and safe_unlink
-
-commit 339fed9821b75de056febc406b32fe52ff9354a9
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Wed Feb 6 22:00:46 2008 +0100
-
- Forgot to remove spec excludes...
-
-commit 7ecca7222823a82252ed09b17eefafe6fec9f12e
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Wed Feb 6 21:46:19 2008 +0100
-
- Fix last two failing Dir#glob specs
-
-commit fec39f27d287ca74becbecc120de8533e346b864
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Wed Feb 6 18:13:13 2008 +0100
-
- A few more corner cases fo IO#lineno specs.
-
-commit 3691d3f9a202abb22e11024e41b868d531a549be
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Wed Feb 6 18:02:50 2008 +0100
-
- New rubyspecs for IO#lineno.
-
-commit a5b0f9aa15c9372f74816e77073926780a9cc219
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Wed Feb 6 15:58:26 2008 +0100
-
- Improved IO#foreach specs.
-
-commit 91ea9f304c75592e7454411ef21391a0e34da5e5
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Wed Feb 6 15:03:02 2008 +0100
-
- New rubyspecs for IO#gets and IO#foreach.
-
-commit 9c494786fbf400bb295e1f19d142e2c903c21e54
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Wed Feb 6 13:37:43 2008 +0100
-
- New rubyspecs for IO#foreach.
-
-commit cdbbeba8f3351fe43f44d732348f380599ad5719
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Wed Feb 6 10:40:13 2008 +0100
-
- New rubyspecs for IO's sysread and read with buffer argument.
-
-commit e1cb4410b7e0a0ba2fd580784334bdfd05ba4b8a
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Wed Feb 6 10:15:29 2008 +0100
-
- Excluded rbx failure after spec rename.
-
-commit 1fde018b9378b55f6d51cb85bd65813b5cef5493
-Author: Charles Nutter <headius@charles-nutters-computer.local>
-Date: Wed Feb 6 02:50:44 2008 -0600
-
- Tidy up an apparent copy/paste mistake in IO#syswrite spec
-
-commit 1aa624e625dafaeebd70eac11819f02ecf570f8e
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Wed Feb 6 00:19:39 2008 +0100
-
- New IO specs for writing non-string data.
-
-commit f94a0cffd5fd0e186a9403d97800b55f8c44bdd1
-Author: Eric Hodel <ehodel@engineyard.com>
-Date: Tue Feb 5 15:13:47 2008 -0800
-
- Regenerate zlib stubs.
-
-commit 52ce0e702170676ce02dcc288305097d58834cf8
-Author: Eric Hodel <ehodel@engineyard.com>
-Date: Tue Feb 5 13:34:47 2008 -0800
-
- Add Zlib spec stubs
-
-commit b24ad594837b974a3ae3b207d63ce5cdc956a1a0
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Tue Feb 5 21:45:09 2008 +0100
-
- Added some boundary test cases for Float.
-
-commit 1a8c9966fa148fc3e912f8aecd42c8c00ca4f89c
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Tue Feb 5 22:46:18 2008 +0100
-
- Removed problematic Marshal spec because 2**40 is a Bignum on some archs and a Fixnum on others
-
-commit 6ad8a0a25f20fd137bcb7fcb83bc88440a2a2069
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Tue Feb 5 17:03:56 2008 +0100
-
- Eliminated file descriptors leakage out of IO tests.
-
- These things make runs unpredictable, causing all kinds
- of troubles (non-deterministic failures, fluctating
- number of tests).
-
-commit 95ac3cb9900c52e4819b37166c71840d4bb4e3d9
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Tue Feb 5 14:50:31 2008 +0100
-
- New rubyspecs for File.open with block.
-
- Also, IO.open specs improved to handle closing better.
-
-commit 66f636c346a63853ae37a06f1c3e8b5083370892
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Tue Feb 5 13:22:34 2008 +0100
-
- New tests for IO.open, and additional cases for IO's inspect and stat.
-
-commit dfb941da0f7503bce58dc88a85ccfd201615e13b
-Author: Brian Ford <bford@engineyard.com>
-Date: Tue Feb 5 01:57:20 2008 -0800
-
- Ezra's patch for Regexp#inspect, #309.
-
-commit c5f9381ee74ed2d9c91cca1dd2ce9719b6f51bd8
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Tue Feb 5 10:07:57 2008 +0100
-
- Corrected IO test to not interfere with Kernel#puts tests.
-
-commit 751293c1ea14de1b1d2757bf5d60b082cc771e7a
-Author: Ryan Davis <rdavis@engineyard.com>
-Date: Mon Feb 4 17:43:06 2008 -0800
-
- removed empty excludes
-
-commit 206399aee9ae7845d76c0726702c424b9fc44e80
-Author: Ryan Davis <rdavis@engineyard.com>
-Date: Mon Feb 4 17:39:45 2008 -0800
-
- StringIO#seek now raises if passed bignum offset - should be platform specific, but this'll do for now
-
-commit b00f04ec0fcd8f8edf9943abb5999f1cca9e9e9e
-Author: Ryan Davis <rdavis@engineyard.com>
-Date: Mon Feb 4 17:06:34 2008 -0800
-
- Knocked off the last of the method excludes.
- Tightened up the spec for #to_s
-
-commit 3d4f87741135343a2e8ec6032fa3a69529cfbf69
-Author: Eric Hodel <ehodel@engineyard.com>
-Date: Mon Feb 4 16:51:37 2008 -0800
-
- Fix Hash#key? to work with objects that have the same #hash.
-
-commit f814a15639f6e6ecd47ab99ad9e37e93fd6bc165
-Author: Eric Hodel <ehodel@engineyard.com>
-Date: Mon Feb 4 15:17:08 2008 -0800
-
- Fix Marshal format version check
-
-commit 6d9e0afb5600416e5d66d5123abcfa5dd6c40903
-Author: Ryan Davis <rdavis@engineyard.com>
-Date: Mon Feb 4 14:24:48 2008 -0800
-
- removed tmpfiles from dir/fixtures and moved them to tmp where they belong
-
-commit 4e18d1cf49573b1fa3f484686352734aa39457d0
-Author: Ruben Nine <ruben@leftbee.net>
-Date: Mon Feb 4 02:32:26 2008 +0100
-
- Added support for tag:yaml.org,2002:sym to RbYAML library.
-
- Signed-off-by: Jonas Pfenniger <zimbatm@oree.ch>
-
-commit 220ed05f204f4b8fe7f1f303fae9a18988f8879b
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Mon Feb 4 17:16:44 2008 -0500
-
- Use an example number that is actually a Bignum everywhere in compiler Bignum spec
-
-commit db3f20c8ec905641de887bbd1ed581aa78f73471
-Merge: e33350e... 6e3dad3...
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Mon Feb 4 16:50:14 2008 -0500
-
- Merge branch 'wilson64'
-
-commit 6e3dad3e5b2e982f96e991e9df2d46de5bf4ee1f
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Mon Feb 4 16:49:09 2008 -0500
-
- Use the correct Fixnum#size spec on 64bit platforms
-
-commit e33350eddc3441b2ebe06336500e6445406285d1
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Mon Feb 4 22:12:14 2008 +0100
-
- Moved one IO#inspect spec to File#inspect specs.
-
- Since the behavior is File-specific.
-
-commit 1586e3a2c5d12f5438adddb8c84bc90c3defee82
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Mon Feb 4 20:57:09 2008 +0100
-
- Add more IO specs. God, make it stop!
-
-commit e64f3b02423acb783ba8a62996847b0393e7f3ee
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Mon Feb 4 20:33:57 2008 +0100
-
- And more IO specs.
-
-commit 3d584f0ee2cf988720bb5985c20b3bec6c2e143f
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Mon Feb 4 20:08:26 2008 +0100
-
- Next batch of IO methods specs with closed streams.
-
-commit 6e22a99350195cfa7a40d6049d6d72a9ae7e1168
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Mon Feb 4 19:47:06 2008 +0100
-
- And yet more specs for IO methods with closed streams.
-
-commit 12e8d881b90cbd60bc792693e799923fdb1041b0
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Mon Feb 4 19:20:39 2008 +0100
-
- More rubysecs for IO methods invoked on closed streams.
-
- Plus some refactoring to move repetitive code to the fixture.
-
- NOTE: two specs marked as fails_on :rubinius due to fact
- that they crash rubinius.
-
-commit 3ae3cafcb10725953c8e595641af277f36c88677
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Mon Feb 4 18:39:34 2008 +0100
-
- New rubyspecs for IO#to_io.
-
-commit 4980bb83f53845e88cd0d1a3b0823fdbf0c0a001
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Mon Feb 4 18:09:36 2008 +0100
-
- New rubyspecs for IO#ungetc.
-
- Unfortunately, MRI doesn't follow some of its own
- specified behaviors...
-
-commit f27fe4f3e4ccb298dcaa5014dac69d3148ee169e
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Mon Feb 4 17:18:08 2008 +0100
-
- Added rubyspecs for IO's putc, puts, printf, print and closed streams.
-
-commit a1d7b67942aed8d1b185476dee6f2d99403ed227
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Mon Feb 4 17:07:00 2008 +0100
-
- Added rubyspecs for IO#pid.
-
-commit cfa1ef21ce862a05ae352a4fe49a3ac4c04b9bed
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Mon Feb 4 16:36:21 2008 +0100
-
- Added new rubyspecs for IO#sync and IO#sync=.
-
-commit b4f6c33c17e57fa44322124af088a97d475905e2
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Mon Feb 4 16:20:50 2008 +0100
-
- New exclusions for rbx.
-
-commit 60309280c48b2bd1f1d8a5ea018f401e75b7dac1
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Mon Feb 4 16:17:27 2008 +0100
-
- Added new tests for IO's pos, pos=, rewind, seek on closed streams.
-
-commit 40414ad1b39222494ff2a79a0091890a60b7adf1
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Mon Feb 4 14:26:13 2008 +0100
-
- One more test for IO#eof?.
-
-commit 29db340f24c043b240fec6722c323fa1567ce855
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Mon Feb 4 14:19:46 2008 +0100
-
- Added new rubyspecs for IO#getc and IO#getchar.
-
-commit 0e0a987782fc7834ba95a2e8e2c8ab6cd8dcea81
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Mon Feb 4 13:54:59 2008 +0100
-
- More rubyspecs for IO#eof?.
-
-commit f7d1139e4eace4a86f0c0512bf9269964442628d
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Sun Feb 3 15:55:10 2008 +0100
-
- Fix Date#strptime specs
-
-commit ac4600fcb42928aeba508371aea2f76510e70d5c
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Sun Feb 3 13:26:52 2008 +0100
-
- Fixed Time specs for non Rubinius platforms
-
-commit a5081ca646e99ec94fedfabf03b7eb0a8d37afc3
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Sat Feb 2 23:53:52 2008 +0100
-
- Fixed Time specs for 64 bit archs
-
-commit 26eef47571b921fe6b3228033119e5969c4100db
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Sat Feb 2 13:30:16 2008 -0500
-
- Updated IO excludes.
-
-commit 8edd73d9915f72ee70b661b23e8b42f8b985fa9c
-Author: Charles Nutter <headius@charles-nutters-computer.local>
-Date: Sat Feb 2 10:45:23 2008 -0600
-
- Repair IO#sysseek spec to not write to fixture file; uses a tmpfile now.
-
-commit bf6348c935c816a981672e9c26a40354cf0d722c
-Author: Charles Nutter <headius@charles-nutters-computer.local>
-Date: Sat Feb 2 02:35:42 2008 -0600
-
- Additional IO#sysseek spec for the warning after buffered writes
-
-commit 5241316a1c74e6580fb91940a9f061047e89cdbf
-Author: Charles Nutter <headius@charles-nutters-computer.local>
-Date: Sat Feb 2 02:32:36 2008 -0600
-
- Modify IO#seek specs for IO#sysseek, adding appropriate error tests
-
-commit 7f124cbf66b96fdcdaec73917e86eedfb4a9ddf8
-Author: Ryan Davis <rdavis@engineyard.com>
-Date: Fri Feb 1 18:05:15 2008 -0800
-
- Refactored Marshal#dump specs and merged with fixtures/marshal_data.rb
-
-commit 3766b3ed41ffba71ecb1bef8079027bffe518e2a
-Author: Ryan Davis <rdavis@engineyard.com>
-Date: Fri Feb 1 16:54:32 2008 -0800
-
- Refactored specs for Marshal#load
-
-commit e134d5bf8e247f4a231bfbfc1c3251b262f219e4
-Author: Eric Hodel <ehodel@engineyard.com>
-Date: Fri Feb 1 15:36:06 2008 -0800
-
- Update excludes for recent failures
-
-commit 8ded8b443f55b47a1c30b59cfb0d96d8752d5fa9
-Author: Eric Hodel <ehodel@engineyard.com>
-Date: Fri Feb 1 15:11:37 2008 -0800
-
- Process.group spec is missing a suplemental group on OS X
-
-commit 4b7de6ff839b220115dd29f34b5a9f46cb8f5bef
-Author: Evan Phoenix <ephoenix@engineyard.com>
-Date: Thu Jan 31 17:16:13 2008 -0800
-
- Add proper primitive failures, fix empty symbol.
-
-commit dc55c88beee6a3a3a7fd352c1e374ecf84863459
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Fri Feb 1 16:17:00 2008 +0100
-
- Fixed 2 Date#strptime specs that otherwise would pass only in January.
-
-commit 86c372d0fb50aeb6235ed1595d18a876e09330db
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Fri Feb 1 15:32:40 2008 +0100
-
- Few specs for Time#<=> with non-Time arguments.
-
-commit 765ef93acd294922dc22a986213a5842ce3e67a7
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Fri Feb 1 14:09:01 2008 +0100
-
- Added more specs to Time#+ and Time#-.
-
-commit af76adac2182e46e34e68d29b3cd8614edd27d50
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Fri Feb 1 13:38:20 2008 +0100
-
- Added more test cases for Array#join on recursive arrays.
-
-commit bb15b72393b34d3d10bb644fb1d6ce47b6dc0826
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Fri Feb 1 13:15:24 2008 +0100
-
- Added more test cases for File::join with recursive arrays.
-
-commit 7041b2aef1e574dfe220a70da5210c683074f8ae
-Author: Eric Hodel <ehodel@engineyard.com>
-Date: Fri Feb 1 03:18:31 2008 -0800
-
- Describe an unambiguous method.
-
-commit 84edf54799e0ccd09276a5cda3fccf544f971c48
-Author: Eric Hodel <ehodel@engineyard.com>
-Date: Fri Feb 1 03:07:48 2008 -0800
-
- Use fixed Marshal data for all specs and fix many broken or useless specs.
-
- Clean up spec naming and definition.
-
- Use descriptive names for test classes.
-
-commit e0c3aa074c9525450a7a667ec2cc843ff3560e65
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Thu Jan 31 23:29:57 2008 -0500
-
- Hash.new patch from Phil Hagelberg + MethodTable workaround.
-
- * The Hash.new patch splits a separate #setup method so that subclasses
- can override #initialize without problems.
- * Because it is part of the core code, MethodTable needs to explicitly
- call #setup in its #initialize.
-
-commit a32f16d9288c5c0822cc6962ce3caed5e1bac5d0
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Thu Jan 31 15:35:08 2008 -0500
-
- Updated Module excludes.
-
-commit df731f327c4d47373ba6f2fe2f79d5d9acbf398e
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Thu Jan 31 15:30:11 2008 -0500
-
- More Module#module_function specs in #eval and #module_eval.
-
- * #module_eval separates the two scopes but #eval does not.
-
-commit 6358e5893c52042c10c355173d1ad8441a00bcfa
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Thu Jan 31 15:13:49 2008 -0500
-
- Better Module#module_function specs.
-
-commit 1646bb6e99a6b4190641046ae730ea1be9c8be2a
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Thu Jan 31 13:59:20 2008 -0500
-
- Various whitespace removal in preparation to fix #module_function.
-
-commit 108601d85d2c41d05f9c00945664d9980e0e46c3
-Author: Evan Phoenix <ephoenix@engineyard.com>
-Date: Thu Jan 31 13:39:53 2008 -0800
-
- Add meta_send_call instruction, speeds up calling blocks
-
-commit 50f9c50820b4305877af1c7fd7597c5dc94c623c
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Thu Jan 31 12:20:11 2008 -0500
-
- Added LC_ALL=C for all other platforms for Time specs too.
-
- * If it breaks, report and we will figure out something else.
-
-commit 26059c1570c5ad2a64a796e2678ff2d9ace23e58
-Author: Pierre Yager <pierre@levosgien.net>
-Date: Tue Jan 29 22:48:22 2008 +0100
-
- Fix for bin/ci spec failure on localised linux
-
- * Force system date to be executed against "C" locale
-
- Signed-off-by: Eero Saynatkari <rubinius@projects.kittensoft.org>
-
-commit e5ce9e7c29a34f685f7d3f8a9f855db28aece460
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Thu Jan 31 11:32:56 2008 -0500
-
- Removed trailing whitespace for Time and some Time specs.
-
-commit 3546f721ac86efa318b3802a2f498d41aa830c9f
-Author: Caleb Tennis <ctennis@engineyard.com>
-Date: Thu Jan 31 10:53:53 2008 -0500
-
- Subtend: Add rb_define_private_method, rb_define_protected_method, rb_define_module_method, etc.
-
-commit 7553cb993a0c7e60c2212800b0ecc033ffc0b206
-Author: Caleb Tennis <ctennis@engineyard.com>
-Date: Thu Jan 31 10:39:08 2008 -0500
-
- Add rb_class2name in subtend
-
-commit 4570b7c5d837025d765a6a2909d5536c466b9dcb
-Author: Ryan Davis <rdavis@engineyard.com>
-Date: Thu Jan 31 02:26:09 2008 -0800
-
- quick addition of 2 exclusions
-
-commit 53c76326e76869a87ad0fc67adbd3aef9059ee35
-Author: Ryan Davis <rdavis@engineyard.com>
-Date: Thu Jan 31 02:15:15 2008 -0800
-
- Parser spec updates
-
-commit 8fb2eb68858a1ee1dafb06b833f43d6da817756f
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Wed Jan 30 19:29:25 2008 -0500
-
- Slightly more permissive TCPServer.new spec for hostname string.
-
-commit 2a60dbbf011e806ae51c30ab2cb2b8e7b9b633a5
-Author: Mutwin Kraus <mutwin.kraus@blogage.de>
-Date: Wed Jan 23 18:41:12 2008 +0100
-
- Fixing TCPSocket#new for localhost (with specs for both IPv4 and IPv6)
-
- Signed-off-by: Eero Saynatkari <rubinius@projects.kittensoft.org>
-
-commit f485a6818a754c8110feafa9f6dced42a99187d0
-Author: Jacob Maine <jacob.maine@gmail.com>
-Date: Tue Jan 29 21:13:28 2008 -0500
-
- Making Enumerable#inject only accept one paramter
-
- Uses 'Undefined' idiom, which fixes spec, and cleans up code (thanks
- for the pointer Eero)
-
- Signed-off-by: Eero Saynatkari <rubinius@projects.kittensoft.org>
-
-commit ebfa5a0bf9f8e3efe61c0d34fe63a8cd74b7ddf8
-Author: Jacob Maine <jacob.maine@gmail.com>
-Date: Tue Jan 29 20:52:16 2008 -0500
-
- spec to verify inject accepts one argument, at the most
-
- Signed-off-by: Eero Saynatkari <rubinius@projects.kittensoft.org>
-
-commit b131b80df72a9ceaa9e920b7f78434f301135a6f
-Author: Jacob Maine <jacob.maine@gmail.com>
-Date: Wed Jan 30 00:33:03 2008 -0500
-
- Adding Enumerable#count spec, including a few failing specs.
-
- Signed-off-by: Eero Saynatkari <rubinius@projects.kittensoft.org>
-
-commit 82b63bc0f5b79735a8021b6c5c69786dc76fa7f6
-Author: Alexandre Perrin <alexandre.perrin@epfl.ch>
-Date: Tue Jan 29 15:59:22 2008 +0100
-
- udpdated language/string_spec.rb
-
- * added spec for class/global variable with the \# simple interpolation
- * added spec for ends of a \# simple interpolation
- * added more delimiter character with the percent String construction
-
- Signed-off-by: Eero Saynatkari <rubinius@projects.kittensoft.org>
-
-commit c58110bde52d64b30cf36ba3cb342357f3654812
-Author: Evan Phoenix <ephoenix@engineyard.com>
-Date: Wed Jan 30 17:19:26 2008 -0800
-
- Fix break. It now uses LRE to properly return to callsite and appear like
- it returned.
-
-commit 45109c222502de955d705f810333d8e7b331c953
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Thu Jan 31 00:42:12 2008 +0100
-
- Added Date#strptime specs
-
-commit fe60e6a022d9e64bb568ccd47494f07a99382c58
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Wed Jan 30 11:36:46 2008 -0500
-
- Updated excludes for Marshal. Looks like Fixnum/Bignum issues.
-
-commit 209dde412310edc384be7d4a86bdfb0444f3b3bf
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Wed Jan 30 01:45:27 2008 -0500
-
- Updated IO/File excludes.
-
-commit 91031e51e49a1a3ddb9f74da31e2ed65c48e1ef5
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Wed Jan 30 01:43:11 2008 -0500
-
- IO.new and IO#close use stream API.
-
- * IO.new uses fdopen() to open the given fd which also checks the mode
- string for us. The returned FILE* is stored as a MemoryPointer in
- @fptr.
- * IO#close checks for presence of @fptr and if found, uses fflush() and
- fclose() to release the handle instead of going the normal route.
-
-commit f4d64553a2a53c77235ef9acc3353ac455514057
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Wed Jan 30 01:20:32 2008 -0500
-
- Made probably broken File.open spec compliant_on :ruby.
-
- * File.open should not take three args. File.new does.
-
-commit dc496f35502b4642137d3f0f74571c8245a6ae56
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Wed Jan 30 01:19:29 2008 -0500
-
- Slight IO.new spec tweaks.
-
-commit a9d9288315e88cffd59ec1b27e3c3209ceb1a3a9
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Tue Jan 29 20:32:44 2008 -0500
-
- Combined IO.new and IO.open specs for the shared parts.
-
-commit effa81cce1d42f7c1bc2e275cb75bd9069e934b8
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Tue Jan 29 19:14:51 2008 -0500
-
- Changed specs to use the two-argument IO.new.
-
-commit 1394b360fe70966e25809a349b400a69262060ca
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Tue Jan 29 14:56:47 2008 -0500
-
- Rewrote IO.new specs (still a bit sparse.)
-
-commit 94d50eb3e60971ffeff28bffa0beaff405c581bd
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Wed Jan 30 21:47:35 2008 +0100
-
- File#utime specs to use be_close rather than ==.
-
- On some platforms, direct comparison just doesn't work,
- producing non-deterministic test failures.
-
-commit 0f5574c28ff08c96326298b98b4ea50108168044
-Author: Adam Gardiner <adam.b.gardiner@gmail.com>
-Date: Wed Jan 30 13:13:25 2008 +1100
-
- Remove race in debug_context_change specs
-
-commit 00a62c3476dd0717f5c4caece453914e1392de9d
-Author: Eric Hodel <ehodel@engineyard.com>
-Date: Tue Jan 29 14:39:06 2008 -0800
-
- Remove bogus Marshal specs for Fixnum/Bignum changeover
-
-commit db1b140db0fbecf70f8adda983e010ef2bbe94c4
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Tue Jan 29 22:58:18 2008 +0100
-
- Finished first version of Date specs. All public methods are specced
-
-commit 8ee52fd8dfd3ef6048c63b30d8aea71da944abb2
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Tue Jan 29 17:21:57 2008 +0100
-
- Follow rbx lead, and allow deviation in UnboundMethod#== for JRuby.
-
-commit f670bcb9e086ac9cc73b6ef6083966b296268f04
-Author: Caleb Tennis <ctennis@engineyard.com>
-Date: Tue Jan 29 09:46:50 2008 -0500
-
- Fix typo
-
-commit 4e990269fd42aabd48cdc29b4288c78984d0e5cf
-Author: Eric Hodel <ehodel@engineyard.com>
-Date: Tue Jan 29 02:44:20 2008 -0800
-
- Add File::join recursive Array spec.
-
-commit 4d947218e949e19515a9e89af99d4823048f3bb2
-Author: Eric Hodel <ehodel@engineyard.com>
-Date: Tue Jan 29 02:41:54 2008 -0800
-
- Fix File::join spec name, duplication
-
-commit a38e10ddc19ebd59f8775a01f3e899c5348ba23f
-Author: Eric Hodel <ehodel@engineyard.com>
-Date: Tue Jan 29 02:40:37 2008 -0800
-
- Make File::join remove extra / appropriately.
-
-commit 074251c03093ba40c0fc3558d512a77844ac45aa
-Author: Eric Hodel <ehodel@engineyard.com>
-Date: Tue Jan 29 00:53:23 2008 -0800
-
- Make File::join specs more clear, remove whitespace
-
-commit f968bbe15a27d8ac6716d103119d41c4eef37696
-Author: Eric Hodel <ehodel@engineyard.com>
-Date: Mon Jan 28 18:07:24 2008 -0800
-
- Use const_lookup in Marshal, fix #marshal_load.
-
-commit 7e00b857f56879564c1bf27f2e694f3c0783a4bb
-Author: Eric Hodel <ehodel@engineyard.com>
-Date: Mon Jan 28 17:23:26 2008 -0800
-
- Support nested modules in Marshal
-
-commit 5c6e2af3d9ace07ca8387c5aecaa5c1d85e8d81f
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Mon Jan 28 20:22:40 2008 -0500
-
- Added specs for rest of the filetypes to File::Stat#ftype specs.
-
-commit 221a077bef5e9007b548993eaf16c86137c6b0b3
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Mon Jan 28 20:08:12 2008 -0500
-
- Added support to spec file type against sockets too.
-
-commit 9cb4791db10bc79f8c30a86f17e6c099dabeea80
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Mon Jan 28 19:52:07 2008 -0500
-
- Moved File and File::Stat-related fixtures to fixtures.
-
- * Module FileSpecs defines methods that yield filenames corresponding
- to specific file types so they can be easily tested.
-
-commit c28c85602d3ab6770ed567a64b744baa15795511
-Author: Ben Hughes <ben@pixelmachine.org>
-Date: Sat Jan 19 16:10:36 2008 -0500
-
- Added spec for File::Stat#dev, dev_major, and dev_minor
-
- * Check that the result values are Integers for each operation
-
- Signed-off-by: Eero Saynatkari <rubinius@projects.kittensoft.org>
-
-commit 86ce52e32a35cb11564d0d5f306f4eea6d6b714d
-Author: Adam Gardiner <adam.b.gardiner@gmail.com>
-Date: Tue Jan 22 15:21:38 2008 +1100
-
- Added yield_debugger on context change
-
- Added capability to set a flag in the VM that causes a
- yield to the debugger to occur immediately following a
- change in the active context. This provides a foundation
- for step in logic for the debugger, which need only set
- a flag on a task and have a breakpoint triggered at
- whatever receiver is activated following a send.
-
-commit 3904ff2fbb209b8c2d476bb3f4a4ea4825a16f6e
-Author: Brian Ford <bford@engineyard.com>
-Date: Mon Jan 28 17:58:35 2008 -0800
-
- Fixes for mSpec to coexist with autotest.
-
-commit 45f2d6de4b025acfa2429d88c729a3eb58a79528
-Author: Ryan Davis <ryand-ruby@zenspider.com>
-Date: Mon Jan 28 17:08:45 2008 -0800
-
- Added more brains to .autotest. Removed bad files that it pointed out
-
-commit 70eaa7feffcfd552c51b67a651cdf6063c9b549a
-Author: Eric Hodel <drbrain@segment7.net>
-Date: Mon Jan 28 15:57:24 2008 -0800
-
- Add File::Stat#dev.
-
-commit 020f4bec691ba658fab0f1ff24fa5df5a6f1921f
-Author: Ryan Davis <ryand-ruby@zenspider.com>
-Date: Mon Jan 28 16:13:11 2008 -0800
-
- Added enough process spec exclusions to drop the HUP issues
-
-commit 76b393566f2a89001952dbf1ec46dd52a5750448
-Author: Ryan Davis <ryand-ruby@zenspider.com>
-Date: Sat Jan 26 10:58:42 2008 -0800
-
- Fixed autotest support (needs latest version of zentest).
- Minor clean up on bin/ci and kernel/core/module.rb.
- Hacked mspec/matchers/base.rb to output with pretty print.
- Fixed mspec's runner to output time BEFORE failures. Fixes unit_diff.
- Updated Parser excludes.
- Deleted a bunch of excludes.
- Updated spec/parser/sexp_expectations.rb with latest ParseTreeTestCase.
- Started adding a rewriter to make maintaining sexp_expectations easier.
-
-commit d147f6f0a87e30e240750d8c660bc89f8c84a472
-Author: Jeremy Roach <jero_rub@yahoo.com>
-Date: Mon Jan 28 18:20:38 2008 -0600
-
- update CI excludes
-
-commit 159f17a228fa6a42cea79b9e3663e1f2b9dea9e4
-Author: Jeremy Roach <jero_rub@yahoo.com>
-Date: Mon Jan 28 18:07:56 2008 -0600
-
- add Marshal specs
-
-commit 72e739590b6bbe571607df674e2f4106c64c8042
-Author: Eric Hodel <drbrain@segment7.net>
-Date: Mon Jan 28 15:15:26 2008 -0800
-
- Fix String#gsub when matching '^'.
-
-commit fc8c2c5584305b3e0b2a74ba8250a0b7072a372f
-Author: Ben Hughes <ben@pixelmachine.org>
-Date: Sat Jan 19 16:20:55 2008 -0500
-
- Added specs for File::Stat#ftype. #264.
-
- * Tests "file" and "directory"
-
- Signed-off-by: Eero Saynatkari <rubinius@projects.kittensoft.org>
-
-commit 2f9872b66d4dffc82e0a97e617fb9de18105f668
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Sun Jan 27 19:56:06 2008 -0500
-
- Better living through mocks. String#+ spec cleanup & correction.
-
- * String#+ in fact raises a TypeError when given ANY non-#to_str
- object.
- * Simplified spec code.
-
-commit f5a0f1e0e401db8f28727cdd8be99228c9c6aee3
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Sun Jan 27 19:37:08 2008 -0500
-
- Removed trailing whitespace in String.
-
-commit 03c1c270236786b66930063669b95ac7cbf17f10
-Author: Matthew Draper <matthew@trebex.net>
-Date: Thu Jan 10 22:40:35 2008 +1030
-
- String#+(65) throws a TypeError, unlike String#<<(65).
-
- Signed-off-by: Eero Saynatkari <rubinius@projects.kittensoft.org>
-
-commit a17ede3e9c85c1bd2e06efa7381c1e5dbab47f80
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Sun Jan 27 19:10:33 2008 -0500
-
- Minimal IO#open specs, IO#sysseek. Merged from Chen Yufei's patch.
-
- * Merged patch by hand, most of it was already implemented separately
- too.
-
-commit 30116d672d950687646c1668eac4d9f5b10f4df7
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Sun Jan 27 18:53:19 2008 -0500
-
- IO#readline EOFError spec modified from Chen Yufei's patch.
-
- * Patch was out-of-date, applied by hand.
-
-commit 1b81e68249741d53b38857440bba897987d00e43
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Sun Jan 27 17:44:30 2008 -0500
-
- Separated and excluded NUL byte stripping for String#lstrip specs.
-
- * Rubinius does strip leading NULs, MRI does not.
-
-commit 55f50888f22288b0fa45298d873dd265d7340aec
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Sun Jan 27 16:52:51 2008 -0500
-
- Updated various excludes.
-
-commit b085f63d66519f93b59e3851b7e6796877e97107
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Sun Jan 27 16:47:24 2008 -0500
-
- Documented Method, deleted unnecessary Method#module spec.
-
-commit f71f5c91e8ceab59d59614fe885dfeff096d7655
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Sun Jan 27 15:41:26 2008 -0500
-
- More precise specs for Method and UnboundMethod #to_s / #inspect.
-
- * Checks presence of own class, method name, name of the Module where
- the method is defined and name of the Module where the method was
- extracted from.
-
-commit 400b522d27515698e0a35b2507a4a8825ec9bf8f
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Sun Jan 27 15:22:46 2008 -0500
-
- Rewrote Method#unbind specs, touch-up for Module#instance_method spec.
-
-commit 57bddb7b38dbb762b2469c51eb961e01f03c8518
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Sun Jan 27 14:50:38 2008 -0500
-
- Updated UnboundMethod#== spec for Rubinius/MRI difference on Modules.
-
- * Rubinius' UnboundMethod#== is true for methods from included Modules also.
-
-commit 8503c92f914d72e72eeeaede225f52242a1afad9
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Sun Jan 27 14:25:29 2008 -0500
-
- Rewrote and added Module#instance_method specs.
-
-commit 8541f4cf83f8b776276e81ca41eb0f7b595e4fb7
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Sun Jan 27 13:43:36 2008 -0500
-
- Improved/added UnboundMethod#bind specs.
-
- * Removed unnecessarily specific error message check. Exception type
- is plenty.
- * Specified correct behaviour only in terms of Method since a Method
- is returned and anything after that is not #bind's responsibility.
- * Rubinius allows binding to any object that is kind_of? with respect
- to the Module that the method is *defined* in. MRI requires that it
- can only apply to objects of the same Module that the method was
- extracted from.
-
-commit fc7073c85b5e201265e24a82c19bd6413681f6e1
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Sun Jan 27 13:02:24 2008 -0500
-
- Removed trailing whitespace in UnboundMethod#bind specs.
-
-commit bde0cacff5f061accab7feb8a27b2417456f2f95
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Sun Jan 27 12:38:39 2008 -0500
-
- Specced Rubinius to deviate in UnboundMethod#==.
-
- * MRI requires that both UMs were extracted from the exact same
- Module. Subclasses etc. are not OK even if the UMs both refer to
- the original in the parent. This is somewhat nonsensical and
- harder to implement so Rubinius allows it.
-
-commit e7ba146d3d0ef0aed1d297d157008661458723eb
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Sun Jan 27 12:16:07 2008 -0500
-
- Much more comprehensive and precise UnboundMethod#== specs, documented.
-
- * #== has some stupid behaviour but this is what we get.
- * Explanation of criteria in the method doc.
-
-commit 43f2226c8882900a472f0a5347fa549936e8f000
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Sun Jan 27 09:37:51 2008 -0500
-
- UnboundMethod String representation specs improved.
-
- * Specs require that the returned String contains this object's class
- and the [Module]#[method_name] it was extracted from.
- * The spec specifies nothing else about the format or order etc.
-
-commit 67e3b5993d92776e0c9535549e8ffdb172225d52
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Sun Jan 27 09:11:19 2008 -0500
-
- Trimmed whitespace for kernel/core/method.rb for patching.
-
-commit c61c5185589cf5a86b58b2e8c8b8d7a26cdc25ec
-Author: Scott Taylor <scott@railsnewbie.com>
-Date: Mon Jan 14 00:23:27 2008 -0500
-
- fixing the specs for UnboundMethod#inspect
-
- Signed-off-by: Eero Saynatkari <rubinius@projects.kittensoft.org>
-
-commit 48bcca32329d48a20d5a6f2dd19598ea7b4167ce
-Author: Scott Taylor <scott@railsnewbie.com>
-Date: Mon Jan 14 00:16:24 2008 -0500
-
- UnboundMethod#==, plus an extra spec
-
- Signed-off-by: Eero Saynatkari <rubinius@projects.kittensoft.org>
-
-commit 232015fed94b59adf627a7712da0d5d4d44c87d0
-Author: Scott Taylor <scott@railsnewbie.com>
-Date: Mon Jan 14 00:03:32 2008 -0500
-
- UnboundMethod#bind
-
- Signed-off-by: Eero Saynatkari <rubinius@projects.kittensoft.org>
-
-commit fcd0139307fd48f78f122457af1af43a543343ce
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Sun Jan 27 12:11:34 2008 -0500
-
- Updated excludes for IO#write.
-
-commit eed253158fe0cc20b91f6c8dcc06f6a671092d84
-Author: Eric Hodel <drbrain@segment7.net>
-Date: Sat Jan 26 14:36:33 2008 -0800
-
- IO#write calls #to_s on it's argument
-
-commit bb5ff251bcc4baceac25a3a1fa64797b94551145
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Sun Jan 27 03:22:02 2008 -0500
-
- Updated #attr_writer spec that was picking up a stray method.
-
-commit fa985a57f6cf802d6a83a6d02a31dd7fd33ebd36
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Sun Jan 27 01:20:27 2008 -0500
-
- Module#const_get can now access top-level constants for Modules also.
-
- * Modules explicitly check Object last, Classes already do it since
- they all inherit from Object.
- * Added some more specs too.
-
-commit fbc1cfb2d461891ee478802f44de3736959905a7
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Sun Jan 27 00:47:52 2008 -0500
-
- Renamed the Module field 'parent' to 'encloser.' Some docs.
-
- * When dealing with Modules and Classes, 'parent' is an ambiguous term.
- In typical OO literature, 'parent' means the superclass which is not
- the case here. Two separate sections of code already showedsome
- uncertainty about the intent of this field.
- * Added a few bits of documentation to Module.
-
-commit 92903e92564857350061d83f8eb3b54886986ac3
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Sun Jan 27 00:36:10 2008 -0500
-
- Updated Module excludes.
-
-commit a705e687ce0d55e7ea184e1a3e67ba8d9d7c610c
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Sun Jan 27 00:24:20 2008 -0500
-
- Improved Module#const_get specs for better coverage.
-
-commit bca6aef9b81166f9c5f4aeaafc673a54710d4d35
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Sat Jan 26 19:57:33 2008 -0500
-
- Corrected semantics of spec statements for Module#const_get.
-
- * Specs were correct but the description was inaccurate.
- * Prettified just a little.
-
-commit f699c18b68dee73086afb92d15b61745319a5321
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Sat Jan 26 19:55:40 2008 -0500
-
- Module#const_get specs for top-level constants by Le Huy.
-
-commit f3831a0693ea90271843bcc5910516e5a40ed3c1
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Sat Jan 26 19:15:27 2008 -0500
-
- Module whitespace cleanup before patching.
-
-commit e3cbe8136351f055bd99f10646d4f77515078430
-Author: Charles Nutter <headius@charles-nutters-computer.local>
-Date: Sun Jan 27 00:51:55 2008 -0600
-
- A few basic IO#write specs for file IO
-
-commit fd05adfedf70d795d8d91f650d5b76b05104dd7a
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Sat Jan 26 18:54:35 2008 -0500
-
- Specs for Enumerable#max_by (Rubinius extension.)
-
-commit 560b6460745c7821b9479b356c032a10daaa61ec
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Sat Jan 26 18:53:52 2008 -0500
-
- Specs for Enumerable#min_by (Rubinius extension.)
-
-commit 6ab0bc901bdc60bde1e251f72f0028dfb736a2dd
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Sat Jan 26 14:25:41 2008 -0500
-
- Updated excludes for Enumerable.
-
-commit 2e09eedb31e15c791e491e97bc2af1977a629c2b
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Sat Jan 26 14:20:19 2008 -0500
-
- Fixed Enumerable#max and #min nil problems using Undefined.
-
-commit d8e6ebf604fdcc228e9158336250dd29c6d35932
-Author: Jacob Maine <jacob.maine@gmail.com>
-Date: Sat Jan 26 13:22:33 2008 -0500
-
- Failing spec for finding max when Enumerable contains nil
-
- Signed-off-by: Eero Saynatkari <rubinius@projects.kittensoft.org>
-
-commit 313ee6badb177c101e39e122c5b5d6ff4d73d93d
-Author: Jacob Maine <jacob.maine@gmail.com>
-Date: Sat Jan 26 13:01:06 2008 -0500
-
- Failing spec for sorting a list that contains nils
-
- Signed-off-by: Eero Saynatkari <rubinius@projects.kittensoft.org>
-
-commit 467e8a60e0e25003894013e68f6d48e7bd6a22fc
-Author: Jacob Maine <jacob.maine@gmail.com>
-Date: Sat Jan 26 12:01:15 2008 -0500
-
- adding failing spec for sorting enumerables that contain nils
-
- Signed-off-by: Eero Saynatkari <rubinius@projects.kittensoft.org>
-
-commit 8719a4ad46d7643c6e54aab3dffedb6831bde5f3
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Sat Jan 26 13:42:11 2008 -0500
-
- Whitespace cleanup before applying Enumerable patches.
-
-commit 015a0d023e8c649160800ddb8a269aa789266d51
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Sat Jan 26 13:31:00 2008 -0500
-
- Added/changed the Dir open specs after previous simplification.
-
-commit 6735df441af2489d47674b0cc500dab37dd4319e
-Author: Jonathan Younger <jonathan@daikini.com>
-Date: Thu Jan 24 17:09:49 2008 -0700
-
- Simplify Dir#open spec dependencies.
-
- The "takes a block which yields the Dir instance and closes it after"
- expectation was failing because it depended on File.for_fd working
- properly with closed file descriptors which it does not.
-
- This revision removes the dependency on File.for_fd as well as
- IO.sysopen (which is not yet implemented in jruby) such that
- the spec now passes on ruby, rbx and jruby.
-
- Signed-off-by: Eero Saynatkari <rubinius@projects.kittensoft.org>
-
-commit 27834ebec570c78011eaaf37998272d46ab9d118
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Sat Jan 26 21:51:13 2008 +0100
-
- Added Date#strftime specs and fixed some constants
-
-commit 767e58ec38af7c3bc78dd98541fb8235616e9691
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Sat Jan 26 21:45:23 2008 +0100
-
- Add spec for Rational#round, works because of added Numeric#round
-
-commit 2497d3b7b9d6112356204dc429c3c368e1a65573
-Author: Brian Ford <brixen@gmail.com>
-Date: Sat Jan 26 12:31:45 2008 -0800
-
- Templates for Rational specs.
-
-commit 5d63550a13cad4acbae3ae67e9ee9f672cbe5e61
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Sat Jan 26 00:47:35 2008 -0800
-
- Revert back old date.rb, but use newer date/format.rb, with some fixes
-
-commit ecd3ee8a0a528f516283558585b86e729bd388ec
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Fri Jan 25 21:47:38 2008 +0100
-
- Updated not_compliant_on --> not_supported_on, where appropriate.
-
-commit 78ca098893d6231f74386eeadf0c30787f3dd2e6
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Fri Jan 25 12:18:43 2008 -0800
-
- A couple of easy fixes, fix Time to handle 2 digit dates, pull in trunk date
-
-commit fe8433cda8ca49835e2581f35bbf0d31025e84c1
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Fri Jan 25 18:42:31 2008 +0100
-
- Better detection of AF_INET6 support in socket specs.
-
-commit 1834801229bf8b2c0abfea4c18448ed105691682
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Fri Jan 25 18:16:56 2008 +0100
-
- Added a guard for undefined AF_UNIX in Socket specs.
-
-commit 3af242cc180675272ee24d588f3328bc11342048
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Fri Jan 25 14:32:04 2008 +0100
-
- New specs for IO#seek, IO#pos=, StringIO#seek and non-fixnum args.
-
- Rubinius fails all of them.
-
-commit 0ef7d55ebb5108bd5cf2f951236c8fade3999dfb
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Fri Jan 25 13:42:08 2008 +0100
-
- New specs for String#unpack with 'Q/q' patterns.
-
-commit 907081db80262a1403f659433934ef707c2ddee0
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Fri Jan 25 12:35:07 2008 +0100
-
- Adjusted socket specs, so they pass on MacOS (MRI/JRuby).
-
-commit 9cca76acbe066da357692a19d5af1c8f5e4601c9
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Thu Jan 24 17:31:38 2008 -0800
-
- Fix race in compiler version number, fix regex spec
-
-commit be18fcc2e0ee16f861f1e2bff0636c3288bce8d6
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Thu Jan 24 15:10:00 2008 -0800
-
- Be more flexible with set_priority (OSs are a bitch)
-
-commit 845336d81df42b5d1f93123ef148b78c2b220d25
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Thu Jan 24 13:46:08 2008 -0800
-
- Kernel flesh out, passes all but 1 spec now
-
-commit ab87e7641336dfb07f0ad99cc2881ec59a25053a
-Author: Jonas Pfenniger <zimbatm@oree.ch>
-Date: Thu Jan 24 12:36:50 2008 +0100
-
- Changed __const_set__ to handle corner cases.
-
- * Kernel#__const_set__ is now the catch-all. It triggers on things like :
- M = 3
- M::M = 3
- * MAIN#__const_set__ is forwarded to Object
- * Module#__const_set__: logic has been moved here, it is no more and alias
- of Module#const_set because it needs to trigger a warning on re-assignment.
-
-commit 13dbdf62e802028cb61f9375196712f0b789ff37
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Thu Jan 24 21:30:02 2008 +0100
-
- Added some SystemCallError specs.
-
- And exclusions for rubinius too.
-
-commit 75e2aac1d4b031fa36c8967549452436521b5eea
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Wed Jan 23 19:41:30 2008 -0800
-
- Rework Class.new and Module.new to initialize without VM help
-
-commit 2551e57644d091d44e5e2fa715a017a557a0b18c
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Wed Jan 23 19:03:51 2008 -0800
-
- Userland now uses __const_set__ for 'A = 3' syntax
-
-commit 400c5ceaf677aa2cd05a451c22144613ad7bdbe9
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Wed Jan 23 14:32:26 2008 -0800
-
- Introduce kernel/user land. Adds use of Module#__add_method__
-
-commit 9ee17f227ebe572b09d44b3b0d703b9f95717751
-Author: Eric Hodel <drbrain@segment7.net>
-Date: Wed Jan 23 14:50:25 2008 -0800
-
- Fix Hash#clone
-
-commit bf4875d337017736bd94781c1bf4cd7500fae5f5
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Wed Jan 23 22:55:02 2008 +0100
-
- Implemented Enumerable#inject fix
-
-commit 0bd07f50ba75910ab579e3356dae93bc32b695bd
-Author: Jacob Maine <jacob.maine@gmail.com>
-Date: Wed Jan 23 15:46:06 2008 -0500
-
- Enumerable#inject(nil) should yield nil as the first 'memo'
-
- * Currently yields the first element of the enumerable instead
-
-commit 319f937284e60acc156c6b7f91e56d460e65ac94
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Wed Jan 23 18:12:56 2008 +0100
-
- Excluded the IO#new spec.
-
-commit 04da4120d939603d4a64aab71bbf94ca202e04b2
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Wed Jan 23 18:11:45 2008 +0100
-
- Added IO#new spec (block should be ignored, warning printed)
-
-commit 5617c3eb81a3f1d8f9a581695fe7897fadee500a
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Wed Jan 23 17:50:48 2008 +0100
-
- Excluded failures after IO specs additions.
-
-commit 107a072689bc9b97842f049f4fab2860ab79237d
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Wed Jan 23 17:48:34 2008 +0100
-
- Added specs for IO#open/popen, File#open with close inside block.
-
-commit bc3393a9041f8116d53bedfa6b604ec6dce3fd19
-Author: Jonas Pfenniger <zimbatm@oree.ch>
-Date: Wed Jan 23 14:25:13 2008 +0100
-
- Revert "Added Module#name memoization spec". dbussink told me this behavior
- is not wished.
-
- This reverts commit ff411600202a59d00ffaca2c51330599c6b84966.
-
-commit 73e7d61d756cb7a06ea18b7f92c49bbebb06cc3f
-Merge: ff41160... 1dab607...
-Author: Jonas Pfenniger <zimbatm@oree.ch>
-Date: Wed Jan 23 13:57:28 2008 +0100
-
- Merge branch 'master' of git@git.rubini.us:code
-
-commit ff411600202a59d00ffaca2c51330599c6b84966
-Author: Jonas Pfenniger <zimbatm@oree.ch>
-Date: Wed Jan 23 13:55:36 2008 +0100
-
- Added Module#name memoization spec
-
-commit 1dab607a79b79b370eda4776daf07a262451aea0
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Wed Jan 23 13:28:29 2008 +0100
-
- Added IO#close specs.
-
-commit c78091236495f4a16aa874de97cce3ec485c1f5b
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Wed Jan 23 12:54:25 2008 +0100
-
- Added IO#close_write and IO#close_read specs.
-
- And all of them fail in rubinius. (not implemented)
- And most of them fail in JRuby. (recent bugs)
- They pass just fine on MRI 1.8.6 (p111 and latest)
-
-commit dc39943a4595855d64f23f9155a4e9cf658c39a3
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Wed Jan 23 10:37:45 2008 +0100
-
- Small refactor of regexp_new
-
-commit 132ac4986a648dbf1354216145e5715a727a735b
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Wed Jan 23 00:14:34 2008 -0500
-
- Type.coerce_to no longer falls prey to identity fraudsters.
-
- * Type.obj_kind_of? directly uses the internal kind_of instruction
- so that overridden #kind_of? does not get in the way.
- * Type.coerce_to uses Type.obj_kind_of? for its checks so that
- Core can safely use it without worrying about breakage due to
- overridden #kind_of?.
- * Specs for both and a little documentation.
-
-commit 192882902154c9a68554337ccd1b8f3ee9aedd9e
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Wed Jan 23 00:42:24 2008 -0800
-
- Remove Symbol#to_i and Symbol#to_int. Farewell bastard children.
-
-commit f854667ff62528fe541c8cf67b9a1b291598d654
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Wed Jan 23 00:35:29 2008 -0800
-
- Removed Fixnum#to_sym and Fixnum#id2name, as well as fixed specs
-
-commit eb6cbc3604c81cc093edb1c182be1e456b05bef6
-Author: Adam Gardiner <adam.b.gardiner@gmail.com>
-Date: Wed Jan 23 16:30:22 2008 +1100
-
- Added specs for context iseq manipulation
-
- Added specs to test MethodContext#reload_method and
-
-commit fd5fb764ee21b354b75b84f34906663874a24639
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Tue Jan 22 22:28:02 2008 -0600
-
- spec for DRb method call using a block
-
-commit a928762b48f7dc84bba0d43125063e9d8d54f183
-Author: Eric Hodel <drbrain@segment7.net>
-Date: Tue Jan 22 19:15:10 2008 -0800
-
- Better test of #instance_method.
-
-commit c055a5981bf4ecfd2efc0df74adb071056ff83b9
-Author: Ryan Davis <ryand-ruby@zenspider.com>
-Date: Tue Jan 22 15:40:59 2008 -0800
-
- removed remove_method_excludes.txt
-
-commit 08cb27454e7ae73e79bb432887dba917feaa1f92
-Author: Ryan Davis <ryand-ruby@zenspider.com>
-Date: Tue Jan 22 15:36:36 2008 -0800
-
- Clarified undef/remove specs a bit.
- Fixed remove_method to raise NameError if you're not acting on local method.
- Removed some fails_on calls to make specs pass... gonna remove them all soon.
-
-commit 62d93ac7916ff0d56a5b40ae1b9b501f10081638
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Tue Jan 22 15:35:05 2008 -0800
-
- Fix up sysread and syswrite, disable testing for warnings on rubinius
-
-commit a482b17c4bfe9f40474839ba0cce2a37d8524c62
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Tue Jan 22 15:13:19 2008 -0800
-
- Remove stale binding excludes
-
-commit f45030d33a9e1fe3c6bc111401a893e5649239f7
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Tue Jan 22 15:03:37 2008 -0800
-
- Update Proc excludes
-
-commit 7f932fbdf5fa4e16df10d7731313d458ca21966c
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Tue Jan 22 14:55:50 2008 -0800
-
- Add Proc#==
-
-commit 811cbe8ef876ef452051a9b07b3c95dbf57a7d9f
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Tue Jan 22 23:41:55 2008 +0100
-
- Removed debugging stdout from one spec.
-
-commit 2bf52de43bb90721d921f6d29504a8f098ed09b5
-Author: Ryan Davis <ryand-ruby@zenspider.com>
-Date: Tue Jan 22 14:11:17 2008 -0800
-
- Removed a lot of passing specs from the excludes
-
-commit b0e5a9ba6577c301f2737682d745128e268ebdab
-Author: Ryan Davis <ryand-ruby@zenspider.com>
-Date: Tue Jan 22 14:02:38 2008 -0800
-
- Fixed Symbol::all_symbols
-
-commit 68ae0b5acd647b9ebd73e53638b728cfaee6b6e0
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Tue Jan 22 22:09:45 2008 +0100
-
- Revert "Completed MRI's Module#name spec with corner case."
-
- This reverts commit 970ede321d31ec75dd578866c683defe768fa356.
-
- This spec seems like an implementation detail rather than
- a specified behavior. It was agreed on IRC to revert it,
- and that rbx won't support it.
-
-commit cc0e45cab2167e0fbc1d29308a5dcb4e7e077319
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Tue Jan 22 22:06:28 2008 +0100
-
- Revert "Module#name memoization work."
-
- This reverts commit 7cd9fce4908aaeea9a35e273a3f15ed7ee7aa783.
-
-commit 996f9f4e5fc05f1b3aa618db3e1a4947730780b7
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Tue Jan 22 12:23:39 2008 -0800
-
- Fix LongReturnException to be terminated in the correct place
-
-commit f453121dd2f3b4d9506a3f1c1e61d24e46bc9083
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Tue Jan 22 20:53:45 2008 +0100
-
- Corrected Module#instance_method failing spec. It was failing on all impls.
-
-commit c1d59239ddea95e73e2edd3a97ed6e1113a35d3c
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Tue Jan 22 19:58:32 2008 +0100
-
- Corrected Module#instance_method spec, it was failing on MRI/1.8/1.9/JRuby.
-
-commit ef5f4489caac2ad4bad94783a780aa40a054481c
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Tue Jan 22 19:30:48 2008 +0100
-
- Corrected String#to_f spec.
-
-commit 7cd9fce4908aaeea9a35e273a3f15ed7ee7aa783
-Author: Charles Nutter <headius@charles-nutters-computer.local>
-Date: Sun Jan 20 22:00:34 2008 -0600
-
- Module#name memoization work.
-
- * Module#name is now memoized on access if @name is set
- * Full module path is lazily calculcated on memoization
- * Module#const_set(Ruby) and module_const_set(C) only set @name and @parent.
- * The following methods unifily use module_const_set:
- * cpu_const_set
- * cpu_open_class
- * cpu_open_module
- * module_setup_name
- * Module#calculate_name reworked, hack removed
-
-commit 7b4ef1344812faa76018ab41cc7fba97a3af8448
-Author: Jeremy Roach <jero_rub@yahoo.com>
-Date: Tue Jan 22 02:47:49 2008 -0600
-
- implement more of Marshal.load
-
- Float, obj._load, obj.marshal_load, IO.read, proc arg
-
-commit 41f07f0253a8fba205dbb0402e5d5e88c115d76c
-Author: Adam Gardiner <adam.b.gardiner@gmail.com>
-Date: Tue Jan 22 16:32:01 2008 +1100
-
- Fix Task#get_stack_value to not raise exception from primitive
-
-commit 14c811adaba3e8cfc5104d70e67c2e89c18cac4d
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Jan 21 19:28:18 2008 -0800
-
- Exclude Kernel#require is private spec when running with RSpec.
-
-commit 05a180e0051a0409c685d326a41e882545faaa53
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Jan 21 19:26:41 2008 -0800
-
- Explicitly run /bin/sh to get around limited /bin/pwd on linux.
-
-commit c09b3da391995a0e9006055ce19e838d3f180947
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Jan 21 19:09:07 2008 -0800
-
- Protect String#% specs from segfaulting on linux (ubuntu gutsy).
-
-commit d36b3f65f92b08ae078812788482387077d03380
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Jan 21 17:55:03 2008 -0800
-
- Removed use of `pwd -P` as at least ubuntu bin/pwd doesn't support it.
-
-commit 6d7a8292fb9a68a0dcfbd3f29f595e0ecf5902ae
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Jan 21 17:54:11 2008 -0800
-
- Unexclude Kernel#callcc specs as Evan's recent commits seems to fix it.
-
-commit eb04d409575772a85510770bd0db4f36490de6aa
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Mon Jan 21 13:28:06 2008 +0100
-
- Fix Regexp error handling
-
-commit 93e50808eb7355c404a7f5295923083c8cf63549
-Author: Charles Nutter <headius@charles-nutters-computer.local>
-Date: Sun Jan 20 22:00:34 2008 -0600
-
- Quarantining IO#dup spec "sharing" example due to platform differences.
-
-commit ae9e2829becc495892c7ddce5eae67514f268120
-Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
-Date: Mon Jan 21 10:26:56 2008 +0800
-
- Update Module instance_method_specs excludes after revert put it back in
-
-commit df6c82f97987c233eab0534740054e2d0f0f2f2c
-Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
-Date: Mon Jan 21 10:25:00 2008 +0800
-
- Revert "Update CI excludes for Module"
-
- This reverts commit 8aa00146f2eee9576094daa76c6f158b0deaf2e2.
-
- * Fails when run with other specs
-
-commit 6f5245d4c20bf009bc120967f4a93d24faae66ba
-Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
-Date: Mon Jan 21 10:23:15 2008 +0800
-
- Revert "Update CI excludes for Symbol.all_symbols spec"
-
- This reverts commit cb27e31b2a757ad108842bfa579eb9170d6cf244.
-
- * Returns an F if run with other specs in ./bin/ci
-
-commit ec9677e593247ed8dfcbfc680151d04ac97936e3
-Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
-Date: Mon Jan 21 10:11:35 2008 +0800
-
- Fix Module instance_method_spec to match the inspect with a regexp
-
-commit 7e3474a16ec20094630e865594405ea7f1658c58
-Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
-Date: Mon Jan 21 10:08:06 2008 +0800
-
- Module#instance_method raises TypeError/ArgumentError on invalid arg
-
- * Fixed spec to expect TypeError when passed nil
- * Fixed spec to expect ArgumentError when passed non-symbol/string
-
-commit 8aa00146f2eee9576094daa76c6f158b0deaf2e2
-Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
-Date: Mon Jan 21 09:41:37 2008 +0800
-
- Update CI excludes for Module
-
-commit 9158b959d30babdceafc416650c1ba3234e5029a
-Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
-Date: Mon Jan 21 09:10:06 2008 +0800
-
- Add alias for Proc.to_s from Proc.inspect
-
-commit cb27e31b2a757ad108842bfa579eb9170d6cf244
-Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
-Date: Mon Jan 21 09:09:40 2008 +0800
-
- Update CI excludes for Symbol.all_symbols spec
-
-commit 7f16f313c907de0e22762d97fbba24e70c3259a3
-Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
-Date: Mon Jan 21 08:46:36 2008 +0800
-
- Raise TypeError/ArgumentError for invalid Thread key
-
- * Raise TypeError is key is nil
- * Raise ArgumentError is key is not Symbol or String
- * Correct the description of Thread's element_set_spec to use #[]=
-
-commit 0b849f884beae9d11327e315da5c79fe789b8391
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Sun Jan 20 23:05:33 2008 +0100
-
- Added rubyspecs for Zlib.crc32.
-
-commit 67b52b6fb92b9e9a037e584474cff2dc97ce0163
-Merge: e6d8a61... 6f08d5e...
-Author: Jonas Pfenniger <zimbatm@oree.ch>
-Date: Sun Jan 20 22:30:52 2008 +0100
-
- Merge branch 'master' of git@git.rubini.us:code
-
-commit e6d8a61771b76198c0784677bb0a8fc97b1988bc
-Author: Jonas Pfenniger <zimbatm@oree.ch>
-Date: Sun Jan 20 22:30:29 2008 +0100
-
- Fixed Struct#[] and Struct#[]= with negative indexes.
-
- * Added corresponding specs
- * Fixed kernel/core/struct.rb code
-
- Example:
-
- s = Struct.new(:x, :y)
- x1 = s.new(:a, :b)
- x1[-4] #=> should raise IndexError: offset -2 too small for struct
-
-commit 6f08d5e21473d0f2adff66a32acd46ddd8945fa0
-Author: Brian Ford <brixen@gmail.com>
-Date: Sun Jan 20 12:47:11 2008 -0800
-
- Added spec for Kernel.format.
-
-commit 6ab2691b455ac07643d98dc58f8a0f45487ab20d
-Author: Brian Ford <brixen@gmail.com>
-Date: Sun Jan 20 11:52:56 2008 -0800
-
- Added sane handling of non-reals for #format %e, %E.
-
-commit 1caab1ce237a52d78a402a5f0a7ce1d3ed9ac6b7
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Sun Jan 20 18:55:27 2008 +0100
-
- Add spec for singleton_methods and fix for Fixnum
-
-commit d7c46a0a1660f1d53e03a97571f3ec7b2431d0e4
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Sun Jan 20 12:29:10 2008 +0100
-
- Added failing spec for Regexp#new that could cause a segfailt. Needs error handling as stated in shotgut/lib/regexp.c:122
-
-commit d15c6605b7fb7db337d87ac1bd15f9a1371caa42
-Author: Brian Ford <brixen@gmail.com>
-Date: Sat Jan 19 19:28:00 2008 -0800
-
- Added language spec for return within a block.
-
-commit 3b516c028c4c9e064fbe839f0f9402a135eb90b0
-Author: Brian Ford <brixen@gmail.com>
-Date: Sat Jan 19 17:27:13 2008 -0800
-
- Added spec for class vars set from Kernel#instance_eval based on #267.
-
-commit 970ede321d31ec75dd578866c683defe768fa356
-Author: Jonas Pfenniger <zimbatm@oree.ch>
-Date: Sun Jan 20 00:44:04 2008 +0100
-
- Completed MRI's Module#name spec with corner case.
-
- It looks like Module#name is memoized in MRI
-
-commit caf440ac6a8037a2c223834c0ca4c5decd8e68ab
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Sat Jan 19 22:48:31 2008 +0100
-
- Revert "Wrapped one spec to prevent JRuby crash."
-
- This reverts commit 9f266e3c785c7e3edbb6a30271f32debe6c14164.
- JRuby issue is resolved.
-
-commit 9673e2c1c5a1142af52a0d82d8981bdd9e236c27
-Author: Brian Ford <brixen@gmail.com>
-Date: Sat Jan 19 12:46:12 2008 -0800
-
- Changed IO#syswrite to use should complain matcher.
-
-commit 8522186df7050782c4911f40aef381106e5e8c5b
-Author: Brian Ford <brixen@gmail.com>
-Date: Sat Jan 19 12:29:12 2008 -0800
-
- Added mSpec lambda { .. }.should complain matcher for warnings.
-
-commit 9f266e3c785c7e3edbb6a30271f32debe6c14164
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Sat Jan 19 21:24:13 2008 +0100
-
- Wrapped one spec to prevent JRuby crash.
-
-commit 54d1989997561271553ba72bd99f59ef2deb7c72
-Author: Jonas Pfenniger <zimbatm@oree.ch>
-Date: Sat Jan 19 19:13:06 2008 +0100
-
- Fixed "X::X = 3". It would return a tuple instead of 3.
-
- * changed shotgun's const_set instruction to push the variable on the stack.
- * added corresponding specs under `language'
- * found a new problem but added it to excludes
-
-commit d25ec129902789bc7d636ff5ccda8ff858ae38d3
-Author: Brian Ford <brixen@gmail.com>
-Date: Sat Jan 19 10:21:19 2008 -0800
-
- Added spec/README. Reformatted mspec/README. Removed old sprintf spec.
-
-commit 5eb06e3010707de1e273c23b3f0addf2ceaa824d
-Author: Brian Ford <brixen@gmail.com>
-Date: Sat Jan 19 09:37:29 2008 -0800
-
- Removed unused Sprintf, rename YSprintf to Sprintf.
-
-commit c144abc12230175a2a503c4426804ed19c8559e7
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Sat Jan 19 16:21:08 2008 +0100
-
- File::Stat time functions should return Time objects and added stat and lstat instance methods on File
-
-commit 177ef99db435a59e942566f7904167fc5e849d8d
-Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
-Date: Sat Jan 19 22:24:16 2008 +0800
-
- Fix ThreadGroup's add spec
-
- * Fix is by initializing a new ThreadGroup on Thread setup
-
-commit 3fad84ec370eda1cab596adf5589e43240dfc381
-Author: Jonas Pfenniger <zimbatm@oree.ch>
-Date: Sat Jan 19 12:16:55 2008 +0100
-
- Removed empty *excludes.txt for better searchability
-
- `find -name "*excludes.txt" -size 0 -exec git rm {} \;`
-
-commit 9a2b1e6232f36c7a1508085b4606e25fbcf3cb4a
-Author: Jonathan Younger <jonathan@daikini.com>
-Date: Fri Jan 18 23:19:16 2008 -0700
-
- Additional String#% platform specific formatting failure fixes
-
-commit aa32d6fcbed79b9e2afedc00f429ea78f5c540d3
-Author: Jonathan Younger <jonathan@daikini.com>
-Date: Fri Jan 18 22:12:23 2008 -0700
-
- Fix String#% platform specific formatting failure
-
- Darwin and FreeBSD return a different string format than other platforms,
- so a different expectation is needed to match the appropriate format.
-
-commit c64dfd449dc89ec0016f14afd7f85522dbaa4148
-Author: Jonathan Younger <jonathan@daikini.com>
-Date: Fri Jan 18 21:05:44 2008 -0700
-
- Moved String#% specs to ruby/1.8 and fixed to work with rbx and MRI
-
-commit e5e7f44983f1dbbc79726776b56a9cc7cb910e9f
-Author: Brian Ford <brixen@gmail.com>
-Date: Fri Jan 18 19:53:50 2008 -0800
-
- Updated IO excludes.
-
-commit b8b549dbc1aaf63e15717c3902d4485c97f845f7
-Author: Charles Nutter <headius@charles-nutters-computer.local>
-Date: Fri Jan 18 21:40:01 2008 -0600
-
- Add regexp matching for output matcher and enable warning specs for syswrite.
-
-commit 004bd58b597034cbe734d9b7da318135a689190f
-Author: Jeremy Roach <jero_rub@yahoo.com>
-Date: Fri Jan 18 21:06:38 2008 -0600
-
- implement some of Marshal.load
-
-commit 2c52db8022f060866d839992aaa6bff0f61963cf
-Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
-Date: Sat Jan 19 11:21:55 2008 +0800
-
- Fix UnboundMethod#bind
-
-commit a5680db20cf998f0db292e3b9aa69ed74fb19b10
-Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
-Date: Fri Jan 18 17:49:44 2008 +0800
-
- Implement UnboundMethod#==
-
-commit a1de7b0f405830f6bfe8000c051f4445135d8f63
-Author: Charles Nutter <headius@charles-nutters-computer.local>
-Date: Fri Jan 18 20:54:11 2008 -0600
-
- Added some specs for sysread/syswrite on a file and p flushing to File.
-
-commit e7bc994d96398519ca205e87dec8e775bb0e67c6
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Sat Jan 19 01:31:46 2008 +0100
-
- Fixed File#utime segfault
-
-commit 9887c6135e9353c3094dcf3c76d8e788b98f2bed
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Fri Jan 18 22:00:10 2008 +0100
-
- Added Time#strftime specs for '%U' and '%W' patterns.
-
-commit 0338fb5adb325e58d1ce61bccc9310fc7284e235
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Fri Jan 18 20:35:23 2008 +0100
-
- Added two testcases for String#% rubyspecs ('x', 'X').
-
- There was a bug in JRuby's sprintf, which wasn't
- detected by rubyspecs.
-
-commit 97db9fb72d6205227d61d92ed3153331b2328f97
-Author: Brian Ford <brixen@gmail.com>
-Date: Fri Jan 18 10:50:00 2008 -0800
-
- File#utime spec. Some cleanup of File#open specs.
-
-commit 10647cf8abfd0ea7a87d39978a22f68fdfa9fbd6
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Fri Jan 18 17:08:04 2008 +0100
-
- Wrapped 3 IO spec tests into fails_on :jruby.
-
- Because these tests just break the spec run completely.
-
-commit cf6195eeabe382c4267e295ab786acedaed89050
-Author: Jonathan Younger <jonathan@daikini.com>
-Date: Thu Jan 17 21:55:48 2008 -0700
-
- Fix specs that use `pwd` to use -P option so that symlinks are resolved
-
-commit 1b79705fb965ecd6fc897b6bf14c605d8325dabe
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Fri Jan 18 15:57:46 2008 +0100
-
- Added IPAddr specs by manveru. Closes #262
-
-commit f05b96b33970e3f08da5c8992f7c6cb710649f42
-Author: Eric Hodel <drbrain@segment7.net>
-Date: Fri Jan 18 02:23:15 2008 -0800
-
- Fix spec for IPv6 environments
-
-commit 2007019ebad7974d7a54e6d599320675548313f0
-Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
-Date: Fri Jan 18 17:39:09 2008 +0800
-
- Fix UnboundMethod#inspect to use regexp
-
- * Also aliased UnboundMethod#to_s to UnboundMethod#inspect
-
-commit c47b473b99b59074673adb7e8d50a250e34436e7
-Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
-Date: Fri Jan 18 17:37:29 2008 +0800
-
- Use a regexp to match the inspect output instead of deviating on rbx
-
-commit 8dc2a2b3115a49a15ed931301b1999560ee27db5
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Fri Jan 18 01:05:14 2008 -0800
-
- Fix up specs and finalize LongReturnException
-
-commit 7c30ca7337b56a4194eb58952f74662e222b7707
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Thu Jan 17 23:23:27 2008 -0800
-
- Add support for return in a block obeying ensure properly
-
-commit c06fc665c6bf5898163f2854b93d62b8b314216e
-Author: Brian Ford <brixen@gmail.com>
-Date: Thu Jan 17 21:20:42 2008 -0800
-
- Changed Exception#backtrace to return an MRI compatible one.
-
- * Exception#awesome_backtrace returns an Rubinius Backtrace
- instance, as Exception#backtrace used to.
- * Added templates for Backtrace specs.
- * UnHACKed lib/test/unit to use the #backtrace as expected.
-
-commit a29f35c5a45776f10132c3ce0ef058b1e98a4f75
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Thu Jan 17 20:18:04 2008 -0500
-
- Guard failing Process.setpriority spec, add an exclude to CI
-
-commit 333d5c6920c01366c8b2887ecc7e33f775210c00
-Author: Brian Ford <brixen@gmail.com>
-Date: Thu Jan 17 16:50:31 2008 -0800
-
- Specs and fixes for Class.inherited.
-
-commit ac90d87a69c19c441b854660105d21ed771989f0
-Author: Ryan Davis <ryand-ruby@zenspider.com>
-Date: Thu Jan 17 16:37:31 2008 -0800
-
- One more step into the foray of bootstrap madness... removed useless 0 from lasgn nodes. needs full clean
-
-commit 0dbabefd081be4890d0d789a9c3ec122b9196cf8
-Author: Brian Ford <brixen@gmail.com>
-Date: Thu Jan 17 12:00:55 2008 -0800
-
- Fixes to enable RSpec 1.1.2 to run the spec/ruby specs.
-
-commit 9bd611ff5c5b411518c2f4ce5d3cd4b93f4bcebe
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Thu Jan 17 08:25:24 2008 -0500
-
- IO#puts, #isatty fixes from Dan Lucraft, slightly modified.
-
- * The #puts spec exposed an issue with String#suffix? which Ifixed in
- fa9a6c which means IO#puts did not need to be changed.
- * #puts spec uses output_to_fd.
-
-commit 3f519a98bbc3a66d59884add5fcd98d5ca095149
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Thu Jan 17 08:02:51 2008 -0500
-
- String#suffix? specs and correct behaviour.
-
- * The suffix can be the entire string, there is no need for it to
- just be a substring always.
-
-commit ca6fa9cd760b06827f4f953ff28e8baed357f447
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Thu Jan 17 12:48:20 2008 +0100
-
- Additional Date specs
-
-commit 8541022ffc918879142ecb3707e977050f774ece
-Author: Brian Ford <brixen@gmail.com>
-Date: Thu Jan 17 00:47:04 2008 -0800
-
- Added ?d, ?e, ?f to Kernel#test.
-
-commit e6f36980c2c94414e5c051b35d9ce403c492f1a2
-Author: Charles Nutter <headius@charles-nutters-computer.local>
-Date: Thu Jan 17 02:18:25 2008 -0600
-
- Fix my oops; missing 'do' for the fails_on
-
-commit 44483d8e414f107b3202cc69b8cdfbbe1222ee33
-Author: Charles Nutter <headius@charles-nutters-computer.local>
-Date: Thu Jan 17 02:07:57 2008 -0600
-
- Add a fails_on guard to IO#printf spec for JRuby; output dies otherwise
-
-commit 53a36c934ec44fad7e6d18424cb13b37496cf720
-Author: Brian Ford <brixen@gmail.com>
-Date: Wed Jan 16 18:39:34 2008 -0800
-
- Updates to compiler and core to protect Fixnum#/.
-
- * Added compiler plugin SafeMathOperators.
- * Added very simplistic way to pass flags to the compiler.
- * Added -frbx-safe-math flag
- * Changed core Fixnum, Float, Bignum, and Numeric methods
- to use #divide rather than #/. Aliased #/ to #divide.
- * Updated Rakefile to send flag when compiling core.
-
-commit feb260b904d87487428b558f7b7e9ac0170c160c
-Author: Ryan T Mulligan <ryan@ryantm.com>
-Date: Wed Jan 16 22:47:02 2008 -0600
-
- very minimal SHA1 specs
-
-commit 511732d932d2fe934968c78b89cefa46e699b996
-Author: Ryan Davis <ryand-ruby@zenspider.com>
-Date: Wed Jan 16 16:30:40 2008 -0800
-
- Moved old spec excludes to new location and deleted all old
-
-commit cae6bba077190e158ceee7b8991daf16fd8c55d1
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Wed Jan 16 13:36:19 2008 +0100
-
- Added more Date specs
-
-commit 75d49657f31091d37dfdba1fc5487164db861802
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Wed Jan 16 15:58:42 2008 -0600
-
- more specs for TcpServer and TcpSocket
-
-commit b1d45cb0fdc573bfe5995456d846c11747d48b90
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Wed Jan 16 13:31:33 2008 -0800
-
- Implement ObjectSpace.define_finalizer, using WeakRef.
-
-commit 4e8a0d264dc7d5a4866a1a1b83238bebb47e4ab6
-Author: Jonas Pfenniger <zimbatm@oree.ch>
-Date: Wed Jan 16 21:51:52 2008 +0100
-
- Removed platform-specific specs in spec/ruby/1.8/core/signal/list_spec.rb
-
- There is not direct way to know if a signal exists or not, since it all
- depends on <signal.h>. In practice, there is no real risk for rubinius
- to miss a signal.
-
-commit 32537f8d3378154f7f52c278cd56a7d4159a3446
-Author: Brian Ford <brixen@gmail.com>
-Date: Wed Jan 16 12:41:54 2008 -0800
-
- Added IO#printf, fixed Kernel#printf to use IO's.
-
-commit e7bccb3f38f6ace3cb25a9f227ab5f6b1d2be346
-Author: Jonas Pfenniger <zimbatm@oree.ch>
-Date: Wed Jan 16 21:19:48 2008 +0100
-
- Signal.list spec now passes. bin/ci removed list_excludes.txt
-
-commit b3a6461af30f2c144b4ee65e8539c51291e0156b
-Author: Jonas Pfenniger <zimbatm@oree.ch>
-Date: Wed Jan 16 20:03:15 2008 +0100
-
- kernel/core/signal is no more platform dependent
-
- * Now publishing platform.conf with rbx.platform.signal.* (only using the ones
- defined in MRI's "signal.c")
- * Signal::Names is now published with those values on @after_loaded@
- * New method: Signal.list => Signal::Names
- * Added EXIT=>0 and CLD=CHLD exceptions (see "signal.c" in MRI)
- * Updated the corresponding specs for more details (on FIXME, please help !)
-
-commit bdbd712a5953f011f8d6f1142d50a452e1607f65
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Wed Jan 16 13:42:01 2008 -0600
-
- updated Continuation excludes -- Kernel#callcc specs still bleedover
-
-commit 22d32d3461660ee7cd29760163b622fc94b6ea5b
-Author: Jeremy Roach <jero_rub@yahoo.com>
-Date: Wed Jan 16 01:55:21 2008 -0600
-
- apply Marshal.dump patch by Justin Bradford. #252
-
-commit 513de8ab67ab9c017285a48108ccceb185ebaf24
-Author: Adam Gardiner <adam.b.gardiner@gmail.com>
-Date: Wed Jan 16 16:44:34 2008 +1100
-
- Bunch of Debugger fixes
-
- * Debugger now has proper quit behaviour, which causes
- the debugger to remove all breakpoints, clear the debug
- channel, and resume the debuggee.
- * Fix singleton(-ish) semantics of Debugger; essentially,
- only a single Debugger instance can be instantiated at
- one time.
- * Added a bunch of specs for the above
- * Changed Rubinius::VM.set_debug_channel to accessor
- style Rubinius::VM.debug_channel.
-
-commit 2174009b215ce2f0445fc8df4711e7e6c64b0332
-Author: Jeremy Roach <jero_rub@yahoo.com>
-Date: Tue Jan 15 21:59:30 2008 -0600
-
- add Marshal.load specs
-
-commit ec002dd0f0daddedaa5241c4f8f6d85fad0e9768
-Author: Adam Gardiner <adam.b.gardiner@gmail.com>
-Date: Wed Jan 16 09:47:28 2008 +1100
-
- Move VM under Rubinius namespace
-
-commit 983c54400542a03535accf2705ae227ae58970dc
-Author: Charles Nutter <headius@charles-nutters-computer.local>
-Date: Tue Jan 15 15:24:10 2008 -0600
-
- Added spec for File.new coercing filename using to_str.
-
-commit ff6a081de28711b0d8c1136e6e4272baf769043c
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Tue Jan 15 14:29:43 2008 -0600
-
- since DRbObject is within DRb it should be a subdirectory but mkspec generated the wrong path to helper
-
-commit a48cbbd3f5da3c971a215423b3e27b058de04196
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Tue Jan 15 21:15:09 2008 +0100
-
- Add more Date specs
-
-commit 9de289f1bbae86b12bc383e7e535de404f8aaa5f
-Author: Caleb Tennis <caleb@tarknology.com>
-Date: Tue Jan 15 14:58:31 2008 -0500
-
- Add a servent class to StructGenerator for Socket.getservbyname
-
- Also, add Socket.htons and Socket.ntohs for byte order encoding
-
- And complete Socket.getservbyname along with specs.
-
-commit d9e37ff3c0f975a418fafbc7163ee1a9717dd92b
-Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
-Date: Wed Jan 16 03:31:05 2008 +0800
-
- Fix Proc#[] calling the wrong #call method
-
- * Re-aliasing in Proc::Function because aiases don't follow subclass
- methods
-
-commit 2273c919e80ab7186e3139941dc4d73a292bcd2d
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Tue Jan 15 19:30:23 2008 +0100
-
- Add add and minus specs for Date
-
-commit 1325e22c11c48c366d9f0387823de5941b59df66
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Tue Jan 15 16:35:23 2008 +0100
-
- First specs for Date object
-
-commit a3b76d162e58e75b4523151bb6911c840db8319f
-Author: Caleb Tennis <caleb@tarknology.com>
-Date: Tue Jan 15 12:58:14 2008 -0500
-
- Implement Socket#pair (and Socket#socketpair) with corresponding spec.
-
-commit 836f1cf828ab62606a6b0e2f7313228b7482dcbe
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Tue Jan 15 11:47:11 2008 -0600
-
- generate spec files for DRbObject
-
-commit ef99f25be36f6ccd33b297bed14c1175847f1ecc
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Tue Jan 15 11:31:08 2008 -0600
-
- generated spec files for DRb with a basic spec for DRb.start_service
-
-commit 9637cf1e77efd1a3b53e6c4d82a7c7afe8509621
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Tue Jan 15 18:48:09 2008 +0100
-
- Eliminate stdout from IO#dup spec runs.
-
- At least, under JRuby it was printing things like:
- "No such file or directory".
-
-commit 30a2fce2a4fd7e840586ce8ae390ecb632c8bee0
-Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
-Date: Tue Jan 15 23:00:32 2008 +0800
-
- Implemented Dir#pos which fixes #pos, #pos=, #seek, and #rewind specs
-
-commit 013ab2e88ecd8d887c6a0009e7f8d2add4849143
-Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
-Date: Tue Jan 15 22:52:26 2008 +0800
-
- Revert "Updated CI excludes"
-
- This reverts commit 15d1c7674496a99bf1d5ec42420864b22bf1569a.
-
-commit 15d1c7674496a99bf1d5ec42420864b22bf1569a
-Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
-Date: Tue Jan 15 21:50:55 2008 +0800
-
- Updated CI excludes
-
-commit 18470055d83a43c3371609aaac4471767adb3b1b
-Author: Eric Hodel <drbrain@segment7.net>
-Date: Tue Jan 15 04:32:54 2008 -0800
-
- Make TCPSocket.new work. Use socket library names for familiarity.
-
- Make inheritance hierarchy of sockets better match MRI.
-
- Add syscall names to Errno.handle checks.
-
- Spec less of the socket library.
-
-commit bd34303986a068b40cce1366c85ea288fc24a3f5
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Mon Jan 14 23:55:38 2008 -0500
-
- Regexp subclasses work now. Documented Regexp.new.
-
-commit 343acee55519fc97a35a9d50e8bdcfd679d432b7
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Mon Jan 14 23:49:47 2008 -0500
-
- More Regexp.new specs.
-
- * Subclass initialization verification.
- * Multibyte options are case-insensitive.
-
-commit 758a468ffafdeea78016dbbce78f21e19f6735f6
-Author: Ryan Davis <ryand-ruby@zenspider.com>
-Date: Mon Jan 14 18:22:32 2008 -0800
-
- Fixed require modifying LOADED_FEATURES even if require raises an exception
-
-commit 5c8ff74b64f7ec6bd4c413b0e0e93334dff009ca
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Mon Jan 14 21:57:19 2008 -0500
-
- Fixed Regexp#kcode specs.
-
-commit 34867cc1f1f3b7ac3145fb926491c0dc44629312
-Author: Eric Hodel <drbrain@segment7.net>
-Date: Mon Jan 14 22:41:58 2008 -0800
-
- Add Socket::getaddrinfo. Raise SocketError appropriately.
-
-commit e2009a38a8e1ef0dff6394b92a677f3120280f72
-Author: Eric Hodel <drbrain@segment7.net>
-Date: Mon Jan 14 22:39:55 2008 -0800
-
- Remove platform-specific code, remove spec of socket library behavior.
-
-commit 5afa1c34808c68c17bc02f5f76c42d64efdd7dd2
-Author: Charles Nutter <headius@charles-nutters-computer.local>
-Date: Tue Jan 15 00:32:14 2008 -0600
-
- Modified retry-in-rescue example to test nested blocks and be clearer.
-
-commit 17fd0cb781ec90d268668c5678e1135eb5f6e323
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Jan 14 22:28:46 2008 -0800
-
- Added Module#autload?.
-
-commit 96ca83312d1b5a1e38e25f94504f6f69a137b96d
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Jan 14 21:50:37 2008 -0800
-
- Updated CI excludes for language.
-
-commit ef4f49de672d40f43f53dadff1aa8fdbcafe1d45
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Mon Jan 14 21:37:23 2008 -0800
-
- Fix specs for dregx change, fix regexp for specs
-
-commit 5cd2ef2a173394910249d93d8ef433d220f2d9a9
-Author: Adam Gardiner <adam.b.gardiner@gmail.com>
-Date: Tue Jan 15 16:32:15 2008 +1100
-
- Fix breakpoint specs
-
- The breakpoint specs were interfering with one another,
- due to the fact that each was modifying the bytecode for
- a fixture class that is compiled only once.
-
- Workaround this by saving off the bytecode and resetting
- before each test.
-
-commit 29bf88b07f87182d94fcf7c550724efc07067239
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Jan 14 20:00:27 2008 -0800
-
- File spec/data/critical.txt is empty! Congrats to everyone!
-
-commit 8082760cc2215742464a9846295ec4a8a0c49244
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Jan 14 19:37:33 2008 -0800
-
- Removed Module methods from critical excludes.
-
-commit d075c115087c001d0d35562aeeea21efadc5e3b6
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Jan 14 18:53:46 2008 -0800
-
- Added not_compliant_on :rbx for class variable specs that use Fixnums.
-
-commit 23f1b523da2478f2ad962f0045dca3e7034f9b56
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Jan 14 18:16:46 2008 -0800
-
- Multiple fixes for #class_variable_get/set. Updated CI excludes.
-
-commit dbc5675058aa426dbfbbf7489d5393819edb16f8
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Mon Jan 14 16:42:27 2008 -0800
-
- Fix attrasgn usage to pass specs
-
-commit 3e250999d6f1a7fdaf2bb5cd169a1024e2ab5ddc
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Jan 14 16:07:08 2008 -0800
-
- Removed leftover excludes for compiler[12].
-
-commit a2b8b5511e79b47fa7777e716ee16511fdec3fd4
-Author: Charles Nutter <headius@charles-nutters-computer.local>
-Date: Mon Jan 14 16:47:21 2008 -0600
-
- Remove the goofy Hash#delete spec and replace with two others.
-
- The old version of this example depended on individual hash buckets having a
- specific ordering, which overreaches a bit. The new version, while a little
- cumbersome, should work correctly regardless of hash implementation or hash
- and bucket ordering.
-
- I also moved out a few lines that were unrelated to this example into a
- separate one.
-
-commit 67d858885f1841e9c9aa295150da3c472949198d
-Author: Gregor Schmidt <ruby@schmidtwisser.de>
-Date: Mon Jan 14 14:57:53 2008 +0100
-
- Passes Module#extended specs by added extended method to module and adding a call to it in Object#extend
-
- Signed-off-by: Brian Ford <brixen@gmail.com>
-
-commit 302ba965def902ccc5d3e97ed6bd5841f09d8f00
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Jan 14 14:14:08 2008 -0800
-
- Philipp Brüschweiler's patch for String#%, #242.
-
-commit abaf2efa9e467bb7b5ef3b53b8490f1e056a832e
-Author: Caleb Tennis <caleb@tarknology.com>
-Date: Mon Jan 14 16:59:23 2008 -0500
-
- Another round of socket specs, and add a Rake StructGenerator to find sockaddr_un if it's available
-
-commit f5d0e435023a80bcc4c101a8d3ab9fc056a14c80
-Author: Caleb Tennis <caleb@tarknology.com>
-Date: Mon Jan 14 15:52:47 2008 -0500
-
- More socket specs
-
-commit 7bbc927a9d8a6f9202025be62a3db861ced3216f
-Author: Caleb Tennis <caleb@tarknology.com>
-Date: Mon Jan 14 14:58:34 2008 -0500
-
- More socket functions and specs.
-
- Namely, this implements a Socket::SockAddr_In class that is a FFI::Struct around the
- sockaddr_in C struct. This gives us a better ability to inspect what's going on in the
- struct from the Ruby side of things.
-
-commit f351c6d3d8831705f0398abdae240abba9252a75
-Author: Caleb Tennis <caleb@tarknology.com>
-Date: Mon Jan 14 11:09:04 2008 -0500
-
- More socket specs update
-
-commit cb8ce936394cafa00f77008083bccf9cded59f28
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Mon Jan 14 14:39:41 2008 -0500
-
- Split process/constant expectations into Linux and BSD sections
-
-commit 0964d53edd80367611f63cd6eb4b294ec898cc8d
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Mon Jan 14 10:04:53 2008 -0500
-
- Revert IO#dup spec to unmask errors, removed FileUtils dependency.
-
- * Any errors occurring in specs should generally be raised normally
- so that any potential problem or spec deficiency is exposed.
-
-commit 04f542e928c5fa0df460d8f11b4d87e008fa343f
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Mon Jan 14 13:36:49 2008 -0500
-
- Update Process::Constants to fetch values from RUBY_CONFIG
- Update process/constants_spec so that it passes on MRI as well
-
-commit 0ad02b57fd040196d11662bd1ab9b259dc2ce6d2
-Author: Jeremy Roach <jero_rub@yahoo.com>
-Date: Mon Jan 14 12:23:20 2008 -0600
-
- squash Marshal.dump bugs
-
- * fix order of evaluation problem
- * put more objects in links and symlinks hashes
-
-commit ed98b9a14459b011f97fee5c781410c4d413ed9a
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Mon Jan 14 17:36:00 2008 +0100
-
- Updated Arry#pack specs to guard for always big-endian JRuby.
-
-commit 550f07dc7551573a975183209ba8904fdbd62607
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Mon Jan 14 15:57:04 2008 +0100
-
- More robust cleanup in IO#dup specs.
-
- Without it, mspec against JRuby was reporting EIGHT
- failures, while only 5 tests are actually exist.
-
-commit 1ea4f82183190c4c87da48c381f1db417c7403ac
-Author: Caleb Tennis <caleb@tarknology.com>
-Date: Mon Jan 14 09:26:36 2008 -0500
-
- Updated some socket specs
-
-commit e20ab7ea377cd39209011b44204d2688b53611c5
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Mon Jan 14 02:23:26 2008 -0500
-
- Fixed Regexp.new kcode setting, improved Regexp specs.
-
- * Regexp kcode can be upper- or lowercase.
- * More robust Regexp#options and #inspect specs.
- * Updated Regexp excludes.
-
-commit cc71f359aa65101d2c00cfbb0c396b7cdc697ef2
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Mon Jan 14 01:25:21 2008 -0800
-
- Improve bytecode performance a tiny bit, fix Kernel#`
-
-commit c561368c03c605de41746fac2ce5a6386fcf4f54
-Author: Charles Nutter <headius@charles-nutters-computer.local>
-Date: Mon Jan 14 03:17:15 2008 -0600
-
- Quarantine a suspicious TCPSocket.new speck failing on MRI on OS X.
-
-commit 71a9cf2afbbe6903b8d652b3ee201957e0b0c633
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Sun Jan 13 22:58:16 2008 -0500
-
- Finished IO#print specs.
-
-commit ff75b95a690051736f49a9a113d21027f7f03e92
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Sun Jan 13 22:44:21 2008 -0500
-
- IO#dup and specs.
-
-commit 02f1c03f4df3327ce1ddd20e2249a5e9830627a0
-Author: Brian Ford <brixen@gmail.com>
-Date: Sun Jan 13 23:11:48 2008 -0800
-
- Justin Bradford's patch for Float failure, #237.
-
-commit e43c148954ad609c438e5a4f14811c0349239374
-Author: Matthew Draper <matthew@trebex.net>
-Date: Fri Jan 11 21:35:57 2008 +1030
-
- Kernel#Integer is very fussy about the strings it accepts.
-
- Signed-off-by: Brian Ford <brixen@gmail.com>
-
-commit adad84f7a26bf40809366f2f7b6acfc61dcfefc2
-Author: Charles Nutter <headius@charles-nutters-computer.local>
-Date: Mon Jan 14 00:31:12 2008 -0600
-
- Class.inherited gets invoked regardless of visibility
-
-commit c746fad52e9503d04c3cf65de979b0a5a9f9e495
-Author: Matthew Draper <matthew@trebex.net>
-Date: Mon Jan 14 10:25:58 2008 +1030
-
- Many of Kernel's methods should be module_functions.
-
- Signed-off-by: Brian Ford <brixen@gmail.com>
-
-commit 0b8a4bfefaed3179f96721fdde35e32ed8ff7263
-Author: Brian Ford <brixen@gmail.com>
-Date: Sun Jan 13 21:43:45 2008 -0800
-
- Update CI excludes for Regexp. Remove empty CI exclude files.
-
-commit 89a87edbc61a877621c6f43266000aff32e92ae7
-Author: Warren Seen <warren@warrenseen.com>
-Date: Mon Jan 14 07:12:13 2008 +1100
-
- Fixes visibility of methods passed to Module#module_function
-
- * Make instance methods versions of functions passed to Module#module_function private
- * Correctly identify visibility in error message raised in Module#set_visibility
- * Added specs for module_function
-
- Signed-off-by: Brian Ford <brixen@gmail.com>
-
-commit 25d6fa558f88732d1aa28c68b0eb7c9910366243
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Sun Jan 13 20:42:52 2008 -0500
-
- Updated Regexp excludes.
-
-commit 69e200276898f1c9208be527bdc64c318c56f86e
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Sun Jan 13 20:24:42 2008 -0500
-
- Shared spec for Object#dup and Object#clone.
-
-commit 8a6fe609224c126bcf86987edd3f0690fc9e45ff
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Sun Jan 13 18:19:56 2008 -0500
-
- VM calls private hook methods now. Object#dup and #clone specs.
-
- * Object#dup and #clone have rudimentary specs which also partially
- confirm the private hook fix through #initialize_copy.
-
-commit 84773b6ba63ea6f715dcc4e99e0a8a2e2b739152
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Fri Jan 11 10:46:15 2008 -0500
-
- Specs for Regexp.{new,compile}, updated excludes for same.
-
-commit 6c1603723bba7d58203aa9b03bbf92b4900e53d1
-Author: Brian Ford <brixen@gmail.com>
-Date: Sun Jan 13 18:49:40 2008 -0800
-
- Numerous fixes for File::Stat.
-
- * Implemented readable(_real)?, writable(_real)?, executable(_real)?.
- * Implemented a number of helper methods like rowned?, rgrpowned?,
- superuser?, rsuperuser?. Made these private.
- * Implemented owned?, grpowned?.
-
-commit d1b05e0bf98a3cdfda8a3d2398e78035a49c0c66
-Author: Adam Gardiner <adam.b.gardiner@gmail.com>
-Date: Mon Jan 14 12:25:41 2008 +1100
-
- Deprecate meta_send_stack* opcodes
-
- The code path for these opcodes is almost identical to
- send_stack, and no measurable performance improvement
- comes from using them.
-
-commit 154fe5e1faad94f371c51a979240a6d7f5cd8909
-Author: Caleb Tennis <caleb@tarknology.com>
-Date: Sun Jan 13 20:07:12 2008 -0500
-
- Implement BasicSocket#setsocketopt for String optvals, and add a spec for it.
-
-commit c21636d6b2502db344049e7dc62d42ff8c18b040
-Author: Caleb Tennis <caleb@tarknology.com>
-Date: Sun Jan 13 19:34:50 2008 -0500
-
- Add specs for BasicSocket#getsockopt
-
-commit 1584f41148b8d8967df4c3ee6376b59919cb7db3
-Author: Caleb Tennis <caleb@tarknology.com>
-Date: Sun Jan 13 19:24:58 2008 -0500
-
- Add Array.pack for i, s and l arguments.
-
-commit 7131e187e19bf0889f8ece802495865f7b3f1e5c
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Sat Jan 12 13:55:20 2008 -0800
-
- Cleanup String#split, add edge case check
-
-commit 4ff46602c8a54a61697bb8d9eaa9ae89e56f7abe
-Merge: 1c95721... 908ccff...
-Author: Caleb Tennis <caleb@tarknology.com>
-Date: Sun Jan 13 14:49:48 2008 -0500
-
- Merge branch 'socketspecs'
-
-commit 908ccff0a854038372dad0780e1de35727e2d657
-Author: Caleb Tennis <caleb@tarknology.com>
-Date: Sun Jan 13 14:49:17 2008 -0500
-
- Some TCPSocket spec mods
-
-commit 1c95721bd873c4b30c187bfa7673cd7e3568a0fb
-Author: Brian Ford <brixen@gmail.com>
-Date: Sun Jan 13 10:20:43 2008 -0800
-
- Fixed File::Stat specs to output method name correctly with -f s.
-
-commit acb7505d41aa789157e50962253e686827a702d5
-Author: Jeremy Roach <jero_rub@yahoo.com>
-Date: Sun Jan 13 12:07:06 2008 -0600
-
- update CI excludes
-
-commit c8db419ae06e9642b346e1bcae99367f3b72845f
-Author: Jeremy Roach <jero_rub@yahoo.com>
-Date: Sun Jan 13 11:55:50 2008 -0600
-
- squash bug in Marshal.dump
-
- symbols need a separate links hash
-
-commit eb953ae2c3fdeac4ae13b5461246b9f51b0f39cc
-Author: Caleb Tennis <caleb@tarknology.com>
-Date: Sun Jan 13 09:40:39 2008 -0500
-
- Make the spec text more verbose
-
-commit db013bc06cef2dea4b77a215d4437e2172b391b6
-Author: Caleb Tennis <caleb@tarknology.com>
-Date: Sun Jan 13 09:04:08 2008 -0500
-
- Commit an updated spec that shows the failure on rbx and passes MRI,
- w.r.t. opening a module and aliasing a private module function from that
- module.
-
-commit 759a9f8bd70ead9b5d2fc67b3872e3bf3bd34001
-Author: Brian Ford <brixen@gmail.com>
-Date: Sun Jan 13 01:45:07 2008 -0800
-
- Updated CI excludes for File::Stat.
-
-commit 107feb74eaf01c09d8c5bd14ac29e53900a5ed26
-Author: Brian Ford <brixen@gmail.com>
-Date: Sun Jan 13 00:38:00 2008 -0800
-
- Modified File, File::Stat, FileTest specs.
-
- * Added templates for File::Stat specs.
- * Added shared specs for some File::Stat methods.
- * Altered toplevel File shared specs to take the name
- of the constant to enable File::Stat to use a fixture
- proxy but still have the correct name show with -f s.
- * Split out specs for missing files because File.[l]stat
- behaves differently than e.g. File.file?.
-
-commit e1a13f7ecfe7f2d18fd6ac20dd8c63cbd6d11855
-Author: Jeremy Roach <jero_rub@yahoo.com>
-Date: Sun Jan 13 02:26:09 2008 -0600
-
- implement more of Marshal.dump
-
- obj.marshal_dump, IO.write, depth limit, exceptions
-
-commit bc070232eab1bfa5d294897487339d259a406e74
-Author: Jeremy Roach <jero_rub@yahoo.com>
-Date: Sat Jan 12 15:16:21 2008 -0600
-
- implement more of Marshal.dump
-
- Float, obj._dump
-
-commit ad7a67ed5a3a1399773dda74c4688e9b00c8f9aa
-Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
-Date: Sun Jan 13 01:46:36 2008 +0800
-
- Update CI excludes for Process.initgroups
-
- * It was affected earlier by the Enumerable lambda/Proc-arity issue
-
-commit 7b7a1e3e4712f35688823543b7a7c3c25405ef77
-Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
-Date: Sun Jan 13 01:40:22 2008 +0800
-
- Fix implicit block in Enumerable not passing the arg check in Proc#call
-
- * Changed instances of lambda to Proc.new and arity once again
- returned the correct value. Will investigate, but until then, this
- passes.
-
-commit d9c21aaa18044bd54ed3b1f6ec5daacf9bd250fa
-Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
-Date: Sun Jan 13 01:02:00 2008 +0800
-
- WIP Fix block argument checking
-
- * Passes all the proc/lambda call specs
- * However, specs for methods that add implicit blocks like
- Enumerable#all fail because their arity is somehow 0 - excluded for now
-
-commit 3d400bc8a91a793f49dcf5655dc28e6141d999d0
-Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
-Date: Sat Jan 12 20:03:26 2008 +0800
-
- Update CI excludes and add Module#class_variable_get to critical.txt
-
-commit 6bf7b8616837649ddd2c1435a54c86ed30910985
-Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
-Date: Sat Jan 12 19:27:12 2008 +0800
-
- Move custom classes for NoMethodError specs into fixtures
-
-commit 10cc61bb816ae67a7fad5b135f66d263d7ee07b1
-Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
-Date: Sat Jan 12 19:20:27 2008 +0800
-
- Swap the protected/private method calls around in the NoMethodError spec
-
-commit 6b2e66d3f9222b52cdae42b57206363ad47949e2
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Sat Jan 12 11:51:28 2008 +0100
-
- Corrected Module#alias_method spec.
-
- Now it should pass on both MRI and JRuby.
-
-commit 67f74a936655b72c689d09c77d9fbe9d7194a0a0
-Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
-Date: Sat Jan 12 17:50:22 2008 +0800
-
- Fix proc/lambda/Proc.new arity
-
-commit 03440114d5e3f07111cdcae3657258cae4c803e7
-Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
-Date: Fri Jan 11 13:24:26 2008 +0800
-
- Fix Kernel.Integer parsing of invalid String
-
-commit 598598c10c66de38b52a8092cdd2fa99604eda6e
-Author: Eric Hodel <drbrain@segment7.net>
-Date: Sat Jan 12 00:21:22 2008 -0800
-
- Clean up expectations to use a common list.
-
- Update excludes for other things using shared glob specs.
-
-commit 55aa5a1f10655618e45d0ec84502cc13c982227e
-Author: Eric Hodel <drbrain@segment7.net>
-Date: Fri Jan 11 23:31:45 2008 -0800
-
- Specs for File.fnmatch handling of Regexp specials.
-
-commit 7c0dc7edfcdf4948047ba051b0cbed7ba761f1dc
-Author: Eric Hodel <drbrain@segment7.net>
-Date: Fri Jan 11 21:57:10 2008 -0800
-
- Dir.glob support for {}.
-
-commit 9a097fe5634c1109919d1e120b1276827371c332
-Author: Eric Hodel <drbrain@segment7.net>
-Date: Fri Jan 11 19:42:31 2008 -0800
-
- Exclude {} specs for WIP Dir.glob
-
-commit ccdc6f5ae5fabbd0d2c32072811e2ecf7cca8987
-Author: Caleb Tennis <caleb@tarknology.com>
-Date: Fri Jan 11 21:40:04 2008 -0500
-
- In MRI, you can alias private module methods. Not so here. This spec catches it.
-
-commit 8b402d1e32dc283124375374532024f6cfe7020d
-Author: Brian Ford <brixen@gmail.com>
-Date: Fri Jan 11 17:35:21 2008 -0800
-
- Added toplevel shared specs. Converted File, FileTest specs.
-
- * spec/ruby/1.8/shared is the directory for sharing
- specs across multiple classes.
- * Added methods for FileTest
-
-commit c6aea2e10d7a4d0ee14175d5b79894e1e11699b1
-Author: Brian Ford <brixen@gmail.com>
-Date: Fri Jan 11 15:59:34 2008 -0800
-
- Converted File/FileTest#exist(s)? to toplevel shared specs.
-
-commit 06a5d8a3d5874303a71e4e9b939b44c204041edf
-Author: Caleb Tennis <caleb@tarknology.com>
-Date: Fri Jan 11 17:39:39 2008 -0500
-
- Fix failing specs in udpsocket/open_spec.rb
-
-commit 530e40005d09140fdb55608890f0994f3a48d8be
-Author: Caleb Tennis <caleb@tarknology.com>
-Date: Fri Jan 11 13:11:58 2008 -0500
-
- Observer specs
-
- Signed-off-by: Brian Ford <brixen@gmail.com>
-
-commit 0907a20d2bad2207be8e937c403c49634f3a23b6
-Author: Caleb Tennis <caleb@tarknology.com>
-Date: Fri Jan 11 12:24:44 2008 -0500
-
- Add observer to lib and base-spec file
-
- Signed-off-by: Brian Ford <brixen@gmail.com>
-
-commit ec0ff1dfa1ee9de38d35537bec5071f6bb31cf7f
-Author: Jeremy Roach <jero_rub@yahoo.com>
-Date: Fri Jan 11 13:11:02 2008 -0600
-
- implement more of Marshal.dump
-
- Array, Hash, links
-
-commit 640e81394ad2385b535b08b535a4fca06a5f3eec
-Author: Brian Ford <brixen@gmail.com>
-Date: Fri Jan 11 10:24:54 2008 -0800
-
- Added CI exclude for failing MD5#== spec.
-
-commit 3c238cc9f4b32f63bc681bd64a507fc2ff49b017
-Author: Brian Ford <brixen@gmail.com>
-Date: Fri Jan 11 10:00:50 2008 -0800
-
- Converted Socket specs to use subdirs for subclasses.
-
-commit 2b98950eaa33b532fcef079b0997f9793228c608
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Fri Jan 11 09:23:23 2008 -0500
-
- Specs and implementation for IO#print. Closes #222.
-
- * IO#print without arguments spec excluded due to a lack of a lower
- level output matcher. To be added shortly.
-
-commit d65c8c6899cf8e4a1fa56486cf417451e0c7fce6
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Fri Jan 11 19:19:56 2008 +0100
-
- Fix String#* spec.
-
-commit 481e075bfeb9f8fb3bd4db645129a463307de09e
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Fri Jan 11 17:41:07 2008 +0100
-
- Improved digest/md5 specs a bit, some new test cases.
-
-commit 67f48236da3d114638310ab37bcc706719bf7fcd
-Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
-Date: Fri Jan 11 11:59:06 2008 +0800
-
- Updated Method's specs as Method#inspect and #to_s deviates on Rubinius
-
-commit 76846154773a87bc8d99c97e91250abda22f6378
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Thu Jan 10 19:24:57 2008 -0800
-
- A bunch of fixes found while working on Socket
-
-commit f69613740662d3ba4f85573c6c860a5987b29765
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Fri Jan 11 00:17:14 2008 +0100
-
- Fixed Time object for throwing errors where appropriate
-
-commit 9396386f700646d0c55b9a7a75bc399dfe055d2c
-Merge: baae72c... 4d2e53e...
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Thu Jan 10 22:39:24 2008 +0100
-
- Merge branch 'master' of git@git.rubini.us:code
-
-commit baae72cc47c9c1f41c3478732b7bbfdfe514024a
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Thu Jan 10 22:39:11 2008 +0100
-
- Fixed Time#xmlschema conversion
-
-commit 4d2e53e7376080e42b84dca486debcf4f153f32f
-Author: Jeremy Roach <jero_rub@yahoo.com>
-Date: Thu Jan 10 15:17:00 2008 -0600
-
- implement more of Marshal.dump
-
- negative Fixnum, Bignum, Regexp, Struct
-
-commit abdbcd70bba99149b7391effa48452971407b4d2
-Author: Brian Ford <brixen@gmail.com>
-Date: Thu Jan 10 13:18:52 2008 -0800
-
- Annotate Rubinius spec as non compliant.
-
-commit 2a2b3a016bfd70eb8cd14b6a043d59f119e0ad7c
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Thu Jan 10 21:52:18 2008 +0100
-
- Re-added divmod specs for Ruby/JRuby, with comments.
-
-commit 2f079e416e4389b091c8c9b5522d49c6f356c6c9
-Author: Brian Ford <brixen@gmail.com>
-Date: Thu Jan 10 12:29:39 2008 -0800
-
- Updated Bignum#divmod specs.
-
-commit 7a5c79415f2e6555bf2c69e416f6d3189f2e0c3e
-Author: Brian Ford <brixen@gmail.com>
-Date: Thu Jan 10 10:46:05 2008 -0800
-
- Simplify wording of VM.coerce_to_array specs.
-
-commit abc1237a0c96ecd77baee6ecbcf71a7bba338139
-Author: Ryan T Mulligan <ryan@ryantm.com>
-Date: Thu Jan 10 12:35:23 2008 -0600
-
- md5 is now fully 1.8.6 MRI compatible
-
- * MD5 digest specs
- * Specs pass on MRI and RBX
- * Platform::POSIX.memcpy hooked
-
-commit 9f991bd850c51cd624169b51768c2215d4b56edb
-Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
-Date: Fri Jan 11 01:35:15 2008 +0800
-
- Method#bind raises TypeError when binding a method from a non-descendant
-
-commit fc029ab13ded7eeb1ba838b99f00e2f14e232d65
-Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
-Date: Fri Jan 11 00:12:44 2008 +0800
-
- Implement that Precision.induced_from raises TypeError in certain cases
-
- * For case when mixer class doesn't define it's own induced_from method
- * Update CI exclude for precision
-
-commit 35d1a7bc3694bdcc327dd5ac89ca0f261e0bd705
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Thu Jan 10 16:57:38 2008 +0100
-
- Added one more Bignum#divmod testcase, known to fail on some implementations.
-
- In fact, this test case fails on Rubinius and JRuby.
-
-commit 955676613f5e38cf029998e2712013e4575dd03e
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Thu Jan 10 16:12:37 2008 +0100
-
- Changed spec failing on MRI
-
-commit f7b4f3fe02833081cc7f40c0feebbef0e5012f10
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Thu Jan 10 15:58:23 2008 +0100
-
- Fixed Float#divmod
-
-commit aff6e1fc1a16eb9e7b7e207ebc2234154d891a92
-Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
-Date: Thu Jan 10 22:53:25 2008 +0800
-
- Converted VM specs
-
-commit 969c0d8e0dbf43caa3999976cf259c623ff05ff1
-Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
-Date: Thu Jan 10 22:50:17 2008 +0800
-
- Convert Options specs
-
-commit cc7c9dcb6697dea991342328a9b00fa01740e809
-Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
-Date: Thu Jan 10 22:28:42 2008 +0800
-
- Replace example blocks using 'specify' with 'it'
-
-commit 7a5fa30a71072346abda17cdb79c2aa3b3922239
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Thu Jan 10 15:27:49 2008 +0100
-
- Fixed Bignum#quo
-
-commit f2aafe4a352fd884d217b0361d2e7e617f58ebd5
-Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
-Date: Thu Jan 10 20:38:45 2008 +0800
-
- Converted Generator specs and generated new CI exclude files for it
-
-commit edb7e341d9b3ab1c3bdc08bc57ec55d6bf8ace8b
-Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
-Date: Thu Jan 10 19:33:53 2008 +0800
-
- Remove generator_spec.rb because of spec conversion
-
-commit bb4de530c5980f0205875bdb5548e40a22ef6a62
-Author: Brian Ford <brixen@gmail.com>
-Date: Thu Jan 10 01:45:47 2008 -0800
-
- Updated CI excludes for library because of spec conversions.
-
-commit 61a66f69fe3a94d9ad5568ee2dd846cfc0b5211a
-Author: Brian Ford <brixen@gmail.com>
-Date: Thu Jan 10 01:45:17 2008 -0800
-
- Converted Socket specs.
-
-commit 167e05039eeeeb959f7aab1f3611268170037296
-Author: Brian Ford <brixen@gmail.com>
-Date: Thu Jan 10 00:59:20 2008 -0800
-
- Converted YAML specs and added template files for other methods.
-
-commit 027f568f79222cdee492f088edf8a2f14250635a
-Author: Brian Ford <brixen@gmail.com>
-Date: Thu Jan 10 00:47:35 2008 -0800
-
- Converted ostruct specs and added template files for other methods.
-
-commit e964c9342ade9341518bc46cf998703a2c16aa2b
-Author: Brian Ford <brixen@gmail.com>
-Date: Thu Jan 10 00:39:49 2008 -0800
-
- Converted ftools specs.
-
-commit 6263280187c81b0ee27893eae90f9d6a8a511b65
-Author: Brian Ford <brixen@gmail.com>
-Date: Thu Jan 10 00:26:40 2008 -0800
-
- Converted Etc specs.
-
-commit 7b94284063222eef42b9b7ad0d1c820adabe210d
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Thu Jan 10 00:39:01 2008 -0800
-
- Fix a few more Kernel bugs
-
-commit 1c58ee51f388da0490a7815c9a1787d21e151aab
-Author: Brian Ford <brixen@gmail.com>
-Date: Thu Jan 10 00:08:15 2008 -0800
-
- Fixed path for mock dirs in Dir specs.
-
-commit 320f7e7d3503d53216733f9b6eb75c387155ae5f
-Author: Brian Ford <brixen@gmail.com>
-Date: Wed Jan 9 22:44:37 2008 -0800
-
- Converted StringIO and Singleton specs.
-
-commit 5a94a7c3b73103c99a337a089f9cf2c7e601d2bc
-Author: Brian Ford <brixen@gmail.com>
-Date: Wed Jan 9 21:50:14 2008 -0800
-
- Converted stdlib Singleton specs.
-
-commit 12864a2057d1b6f5fa392f34d1fa3e8873a8c566
-Author: Adam Gardiner <adam.b.gardiner@gmail.com>
-Date: Mon Dec 24 23:06:12 2007 +1100
-
- Initial commit of Rubinius Debugger
-
- * Created Debugger class for debugging Ruby code in Rubinius
- * Added Kernel#debugger convenience method to set a breakpoint
- and activate the debugger at the point at which the
- debugger statement is encountered.
- * Implemented the following debug commands:
- - h: get a listing of commands
- - b: list breakpoints
- - b <Method>: set a breakpoint at the start of the method
- - n: Step to the next line
- - ni: step to the next VM instruction
- - c: continue execution until the next breakpoint
- - l: list source code around the current breakpoint
- - d: decode VM bytecode around the current breakpoint
- - v: display local variables and their values
- - vs: display the contents of the VM stack
- - Anything else is evaluated as a Ruby expression in the
- context of the current breakpoint (so you can, e.g. change
- the value of locals before resuming, etc)
-
-commit 01a189cc3e52e8bcc6f22bcc5713e765bba84160
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Wed Jan 9 10:29:27 2008 -0500
-
- Object#is_a?, #kind_of? and #instance_of? specs.
-
- * Removed obsolete kernel specs for same.
-
-commit ab9645614bbbd0bca63c215819c12cc85a1507b1
-Author: Brian Ford <brixen@gmail.com>
-Date: Wed Jan 9 21:35:39 2008 -0800
-
- Converted specs for stdlib Time.
-
-commit 733b069f11c7136175036154a45b924cf89cc8ff
-Author: Jeremy Roach <jero_rub@yahoo.com>
-Date: Wed Jan 9 20:01:09 2008 -0600
-
- update CI excludes
-
-commit 01e98dee4c24838ca518610443e43473ffdcf43c
-Author: Ryan Davis <ryand-ruby@zenspider.com>
-Date: Wed Jan 9 16:42:07 2008 -0800
-
- Fixed block args for |*a|
-
-commit dc9c1d05dd5e0e828a77acc09220f5894a9aa453
-Author: Brian Ford <brixen@gmail.com>
-Date: Wed Jan 9 16:04:11 2008 -0800
-
- Fixed Enumerator spec style. Updated YAML excludes.
-
-commit 0363685a97df83feb0d07f40a7a5c4d7a78e2a27
-Author: Eric Hodel <drbrain@segment7.net>
-Date: Wed Jan 9 14:55:53 2008 -0800
-
- Spec for String#sub bug.
-
-commit 23052eb5f993c959fdb2b327895df08e0a344edb
-Author: Eric Hodel <drbrain@segment7.net>
-Date: Tue Jan 8 23:47:27 2008 -0800
-
- Implement { } matching for Dir.glob
-
-commit c90b2531d183e4534268d4699634828f29e803cb
-Author: Eric Hodel <drbrain@segment7.net>
-Date: Tue Jan 8 23:44:35 2008 -0800
-
- Spec File::Stat#blksize.
-
-commit 62d2a1809936a304c0cf0b94fd28f5b83932f58f
-Author: Eric Hodel <drbrain@segment7.net>
-Date: Tue Jan 8 22:47:37 2008 -0800
-
- Implement Dir.glob '{a,b}'
-
-commit d9430ad1a3e582e830a994a83d6f99e017bfbe4d
-Author: Eric Hodel <drbrain@segment7.net>
-Date: Tue Jan 8 20:56:37 2008 -0800
-
- Fix module X::Y; end; X::Y.name
-
-commit 1baa9468e0d89777fdb6f23e78e8ab510a19d534
-Author: Jeremy Roach <jero_rub@yahoo.com>
-Date: Wed Jan 9 16:16:35 2008 -0600
-
- incomplete Marshal.dump
-
- an evil ivar_as_index is added to Object to hold
- the names of modules that extend the object
-
-commit 85e98490fe45446e03801840d4628149f8977098
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Wed Jan 9 12:26:19 2008 -0800
-
- Move compiler2 => compiler, and Compiler2 => Compiler
-
-commit 5aa5cc66e2b0196728c80eb394ec3b2dfccd77ae
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Wed Jan 9 10:30:42 2008 -0500
-
- Centralised specs for Object#=~.
-
-commit e1fe9f57c942460338a18e38f66fbf6feb69b4bc
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Wed Jan 9 13:23:59 2008 +0100
-
- Added few edge cases to Numeric#eql? tests.
-
-commit b8dfd675fad5e82ebfd50c737beb9a9b919a9c8b
-Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
-Date: Wed Jan 9 15:52:18 2008 +0800
-
- Remove excludes for String#slice with the fixed send in place
-
-commit d7f69f17ac30f6b3161851e8df6a1e0a7694219d
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Tue Jan 8 22:42:43 2008 -0800
-
- A couple more fixups
-
-commit 055d7545c7046102cd92b7054992b1b47f711c4a
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Tue Jan 8 22:31:50 2008 -0800
-
- A boatload of fixes done while getting flexmock and rake running
-
-commit fd7c266e52c25d151214512cc801901813630d7a
-Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
-Date: Wed Jan 9 11:49:02 2008 +0800
-
- Removed last array exclude due to fix in 02e6e28
-
-commit 690626f43f7b4ce888de081033eaadfba543acff
-Author: Brian Ford <brixen@gmail.com>
-Date: Tue Jan 8 18:58:50 2008 -0800
-
- Removed subtend specs from CI run. Increase File#mtime tolerance.
-
-commit dec4f25a47a9a962b77a97dea47985fe17421e5f
-Author: Adam Gardiner <adam.b.gardiner@gmail.com>
-Date: Wed Jan 9 13:39:51 2008 +1100
-
- Specs for stack usage
-
-commit d699f6605db86e6f6bc61d0f3a79fc1535816c70
-Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
-Date: Wed Jan 9 10:38:06 2008 +0800
-
- Add spec to illustrate Numeric#divmod bug in MRI and rubinius (excluded)
-
-commit 8a55f3047dc0fd502bb632dc9f5bdb9668b180fe
-Author: Brian Ford <brixen@gmail.com>
-Date: Tue Jan 8 18:32:18 2008 -0800
-
- Subtend CI exclude to (hopefully) fix the build server runs.
-
-commit 33bde75b57a88baa850edccea382e1130ed586da
-Author: Brian Ford <brixen@gmail.com>
-Date: Tue Jan 8 17:19:30 2008 -0800
-
- Added spec/compiler2 to CI. Added CI excludes for compiler2.
-
-commit 6964fc5644fddeef2238591674786f035d9db842
-Author: Ryan Davis <ryand-ruby@zenspider.com>
-Date: Tue Jan 8 17:19:20 2008 -0800
-
- Fixed up against evan's changes. ping
-
-commit 9423d1e8e9ed91fb9f0934b939899c753972cee1
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Tue Jan 8 20:11:54 2008 -0500
-
- Fix warnings encountered when running compiler2 specs under MRI
-
-commit d71ad87c14a4378ad2f01c49d90304c29be548f3
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Tue Jan 8 17:02:02 2008 -0800
-
- Fix a block_arg bytecode generation case
-
-commit 57199b5b468c0009512a479e13bbcf086d0d9526
-Author: Ryan Davis <ryand-ruby@zenspider.com>
-Date: Tue Jan 8 16:16:07 2008 -0800
-
- Added new combo bytecode/runtime tests for block args
-
-commit 8a88699af73d272a61332e11d022bd629aa0460d
-Author: Ryan Davis <ryand-ruby@zenspider.com>
-Date: Tue Jan 8 16:15:24 2008 -0800
-
- Improved inspect output for compiler spec objects. Added convencience methods for testing iter bytecode generation.
-
-commit 0dd9cd298cf735dc13cc2a2410ad6b5195790c11
-Author: Brian Ford <brixen@gmail.com>
-Date: Tue Jan 8 13:19:21 2008 -0800
-
- Added subtend specs to CI. Updated subtend excludes.
-
-commit c07a5273844b32fe39090bb16d0e4ad59ecb0564
-Author: Dirkjan Bussink <d.bussink@gmail.com>
-Date: Tue Jan 8 21:28:48 2008 +0100
-
- Fixed given_spec? because of changed block_given? behavior
-
-commit 0f9a8dfee9dd1c7af1f8ba69497c8dd85539760a
-Author: Nitay <nitay@powerset.com>
-Date: Tue Jan 8 11:49:41 2008 -0800
-
- Fix setpgid spec using pipes to avoid race condition
-
-commit 09feb8677c529d04969e63d1ff4e3746037611cf
-Author: Brian Ford <brixen@gmail.com>
-Date: Tue Jan 8 10:00:06 2008 -0800
-
- CI excludes for ruby/1.8/library.
-
-commit cda3d86fa44f1d62fe503e54f42c5c5df361b8f9
-Author: Benjamin Andresen <bandresen@gmail.com>
-Date: Tue Jan 8 08:22:49 2008 +0100
-
- Added explicit umask to File permission spec so it won't fail on
- non-standard umasks.
-
-commit 6df303e29d7fd04f4a1a0af379f4947854dd4635
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Mon Jan 7 23:20:22 2008 -0500
-
- Method#== and specs from Scott Taylor, slightly tweaked. Closes #137.
-
-commit 9b86b12be687bb29e25d0292786351d89a698adc
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Jan 7 19:45:24 2008 -0800
-
- Added CI exclude for Array#pack.
-
-commit 17a746b0aa2c89aa9e61b8965d125e962748c20d
-Author: Jeremy Roach <jero_rub@yahoo.com>
-Date: Mon Jan 7 21:07:25 2008 -0600
-
- adds Marshal.dump and Float#to_s specs
-
-commit d5c19db2778e0cc3cbee5bf994b511448cb6bd78
-Author: Eric Hodel <drbrain@segment7.net>
-Date: Mon Jan 7 15:31:11 2008 -0800
-
- Fix IO#pos=
-
-commit 21f44f03f0aa44b2f172f89ad27797c943dc618b
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Mon Jan 7 22:03:28 2008 +0100
-
- Remove non-needed std output from Array#pack test.
-
-commit 9ec20509ad6533876bbbc984052e6b7e05d2ea55
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Mon Jan 7 21:50:46 2008 +0100
-
- Added Array#pack tests with empty array.
-
-commit 35170103bdba14d824780a41112f12034cb5c79e
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Mon Jan 7 21:13:47 2008 +0100
-
- Added Array#pack tests with 'w' pattern.
-
-commit 71b00e03ce2c6424fd262d737feb991835605da2
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Mon Jan 7 20:46:58 2008 +0100
-
- Added Array#pack('U') test with negative values.
-
-commit 7be0813127635ea54909179c9553c5052c4a3d90
-Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
-Date: Mon Jan 7 18:00:03 2008 +0800
-
- Add specs for Array.[]
-
-commit 0b762336e8c6040cbbe794cece64c56bfa46c296
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Sun Jan 6 23:35:35 2008 -0800
-
- Fix breakages, comment out at_exit spec (need a better way to test)
-
-commit 8896e459f1bffb7ae2da2f2aa708419e6316cb4b
-Author: Matijs van Zuijlen <Matijs.van.Zuijlen@xs4all.nl>
-Date: Mon Jan 7 14:03:03 2008 +0900
-
- Spec to demo failure of cases like "yield 1, *[1, 2]"
-
-commit 79da85bb1b1d63e617251b3a3ea6b0657c1e8ddb
-Author: Adam Gardiner <adam.b.gardiner@gmail.com>
-Date: Mon Jan 7 13:04:22 2008 +1100
-
- Modified CompiledMethod#decode to use #local_names
-
- * CompiledMethod#decode now leverages new #local_names
- method to return the names of locals accessed via
- push_local/set_local etc.
- * Removed excludes, as all decode specs now pass
-
-commit 89c1026cecbb9fcd09a62139e2d28b24b5658c25
-Author: David Whittington <djwhitt@gmail.com>
-Date: Mon Jan 7 01:37:10 2008 +0000
-
- Added args to NoMethodError raised by Object.method_missing
-
-commit 0e4a02f0e2fede5d785b15a6b34c582c6ba586f1
-Author: Ryan Davis <ryand-ruby@zenspider.com>
-Date: Sun Jan 6 12:43:14 2008 -0800
-
- Removed redundant Bignum#to_s. Moved private radix_to_s to bottom. Cleaned up to_s spec a bit
-
-commit 48446c40a759d60b7465d82b40f2911d0f7e444b
-Author: Charles Nutter <headius@charles-nutters-computer.local>
-Date: Sun Jan 6 13:45:22 2008 -0600
-
- Add some additional Math.asinh specs from JRuby.
-
-commit 7c81ca307cd01d3752a08487bc3742c8452d61c4
-Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
-Date: Mon Jan 7 00:41:10 2008 +0800
-
- Add failing specs for Time.{local|mktime|utc|gm}
-
-commit 35816e118b327a150a2d26638f289633f5e51f16
-Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
-Date: Sun Jan 6 17:56:23 2008 +0800
-
- Add spec for Time.local to handle string arguments (excluded for now)
-
-commit f9f36f5bb99ddb62e15cb9a9ddd98414e3df93e2
-Author: Eric Hodel <drbrain@segment7.net>
-Date: Sat Jan 5 23:44:33 2008 -0800
-
- Allow Regexp to match nil.
-
-commit e650c39627b81498fc97c51725f2ac1277870e15
-Author: Eric Hodel <drbrain@segment7.net>
-Date: Sat Jan 5 23:38:52 2008 -0800
-
- Add some IO#read specs
-
-commit 20257ecce0d3161fae7ac78454f2b8672f2c1de3
-Merge: bc576b8... e549cc5...
-Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
-Date: Sun Jan 6 14:45:13 2008 +0800
-
- Merge branch 'master' of git@git.rubini.us:code
-
-commit bc576b8e26fdb43d050df4fe3ad5ed974ec85057
-Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
-Date: Sun Jan 6 14:44:44 2008 +0800
-
- Fix handling of string-like second parameter to Time.local
-
-commit e549cc53a4905f21082a97cd6bcb279ace6d9eae
-Author: Eric Hodel <drbrain@segment7.net>
-Date: Sat Jan 5 22:31:42 2008 -0800
-
- Don't shift more bytes than available in the Buffer.
-
-commit 71285a2a9a8d0d3e71c678872ff2a146d5b2dc16
-Author: Chris Shoemaker <chris.shoemaker@cox.net>
-Date: Sat Jan 5 22:53:51 2008 -0500
-
- Fixup the Process specs for setpgrp, getpgrp, setpgid, and getpgid.
-
- They no longer may unwarranted assumptions about the relationship
- between a progress group ids and process ids.
-
-commit 7b57b3ac6df612f81d60d3a31b030ba054b357a6
-Author: Brian Ford <brixen@gmail.com>
-Date: Sat Jan 5 13:22:51 2008 -0800
-
- Patch from Brandon Mitchell for #195, Float#to_s bug.
-
-commit 70ddfd43fd727122f56e8bdfcf3febd1ac1b5479
-Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
-Date: Fri Jan 4 01:01:11 2008 +0800
-
- Fix for Time#yday spec when Time.at might return yday+1 depending on tz
-
- * Wrapped Time.at in a with_timezone("UTC") for consistent results
-
- Signed-off-by: Brian Ford <brixen@gmail.com>
-
-commit 7d4396e4e69fb7b046efdaaf87d1090a02c883a0
-Author: Kamal Fariz Mahyuddin <kamal.fariz@gmail.com>
-Date: Fri Jan 4 02:26:38 2008 +0800
-
- Fixed Array#fill behavior when passed index and negative count
-
- * Added additional spec when negative count is acceptable
- * raise ArgumentError when negative count absolute value exceeds index
-
- Signed-off-by: Brian Ford <brixen@gmail.com>
-
-commit 8af2b55313eb55082df6a71cd3e6bd865f2901fc
-Author: Charles Nutter <headius@charles-nutters-computer.local>
-Date: Sat Jan 5 13:33:26 2008 -0600
-
- Save mtime during file creation to make mtime spec more reliable.
-
-commit 7043933af0475370462984c8d2df2b9301e58cfa
-Author: Brian Ford <brixen@gmail.com>
-Date: Sat Jan 5 00:45:01 2008 -0800
-
- Updated CI excludes after spec description changes.
-
-commit 3d7650100ba1756a4d67be8044e31498ea96d88e
-Author: Brian Ford <brixen@gmail.com>
-Date: Fri Jan 4 21:13:28 2008 -0800
-
- Multitudinous style cleanups in spec description strings.
-
-commit d54ed8791a74661adb87c938e92e037ece924c90
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Sat Jan 5 00:29:22 2008 -0800
-
- A real, working eval and friends.
-
- * Implements binding, eval, etc.
- * Passes all eval and instance_eval specs currently
-
-commit 02ad19ab4132bf5d3ae35c2e11fa1a963d1f1805
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Fri Jan 4 00:25:39 2008 -0800
-
- Fix a few more String specs, fix Integer()
-
-commit d67cfbcf4e7d35641de555ac1edd61b51780def8
-Author: Eric Hodel <drbrain@segment7.net>
-Date: Fri Jan 4 19:16:43 2008 -0800
-
- Make class variables work with inheritance.
-
- Move class_variable* to Module.
-
-commit d79836e04d72796b723cdaab228871c87abe064a
-Author: Eric Hodel <drbrain@segment7.net>
-Date: Fri Jan 4 16:26:21 2008 -0800
-
- Replace Struct with a Struct that can be subclassed
-
-commit 8efb042a9c160af9e9c177ca14aed220dedcc26f
-Author: Ryan Davis <ryand-ruby@zenspider.com>
-Date: Fri Jan 4 15:41:43 2008 -0800
-
- Finished |*args| spec. Fixed MethodDescription and TestGenerator inspect methods
-
-commit 76cc487434f6cd9d60356560f1bbc3fba000397c
-Author: Ryan Davis <ryand-ruby@zenspider.com>
-Date: Thu Jan 3 16:54:56 2008 -0800
-
- Fuck you git. Adds a broken spec to compiler2/masgn for splatted goalpost arg
-
-commit dd2697b602a732e3e00c131f54f9cc557ae0cbe3
-Author: Eric Hodel <drbrain@segment7.net>
-Date: Fri Jan 4 15:40:50 2008 -0800
-
- Failing spec for case when with an empty body
-
-commit 22dcedebd484f655bba51399e38e83c5a14d4053
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Fri Jan 4 18:31:48 2008 +0100
-
- Added Time#local specs with string-like second arg.
-
-commit 43ff733a3097fff44ba8a12334f20a1bf77a965f
-Author: Adam Gardiner <adam.b.gardiner@gmail.com>
-Date: Thu Jan 3 23:54:34 2008 +1100
-
- CompiledMethod#decode now uses local variable names (if avail)
-
- * CompiledMethod#decode now looks in the bonus tuple for the names
- of stack and slot local variables
- * Moved compiledmethod specs to spec/core/compiledmethod
-
- Note: Compiler2 appears not to be setting the bonus tuple, so code
- compiled under it cannot decode local names at present.
-
-commit 06006ec2a053ae49b243fa0aa98fc71c2ea7a524
-Author: Brian Ford <brixen@gmail.com>
-Date: Fri Jan 4 01:24:49 2008 -0800
-
- Updated CI excludes.
-
-commit dff2e75df3c371522b6a3ba4495d269bf793fe97
-Author: Brian Ford <brixen@gmail.com>
-Date: Fri Jan 4 01:01:24 2008 -0800
-
- Updated CI excludes for Bignum.
-
-commit 569fa3b9fc81410ce9fe6568427f0a0bc65b7036
-Author: Brian Ford <brixen@gmail.com>
-Date: Thu Jan 3 19:26:22 2008 -0800
-
- Updated CI excludes for String, Regexp.
-
-commit 7aedec383850eacad5db8248bfcea7615a3d1793
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Thu Jan 3 17:48:32 2008 -0800
-
- Fix up setrlimit/getrlimit on darwin
-
-commit d9aea8bba7276b53ca7c18b8625531be389d2cdc
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Thu Jan 3 16:40:09 2008 -0800
-
- Refactor $~ out as a global, into Regexp.last_match directly
-
- * Uses MethodContext to store $~ now, so it's method local.
-
-commit c19dde305fd751c14a1b4dc798557e0b63c08c8d
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Thu Jan 3 16:25:54 2008 -0800
-
- Clean up compiler2 specs
-
- * For is still broken, needs more love
-
-commit d02603a7e225d3b48ecf7899ea74768880aba7ec
-Author: Gregor Schmidt <ruby@schmidtwisser.de>
-Date: Wed Dec 12 16:56:11 2007 +0100
-
- Add default implementation of Module#method_added
-
-commit 7ba5d1478106e4e0f5fcf21c66029df2f38d7e2f
-Author: Chris Shoemaker <chris.shoemaker@cox.net>
-Date: Sun Dec 30 17:55:21 2007 -0500
-
- Unquarantine Process.kill specs.
-
-commit d68b380bdd2e0a0ec3bd968ffabd02f6e30a3aa1
-Author: Chris Shoemaker <chris.shoemaker@cox.net>
-Date: Tue Jan 1 22:14:59 2008 -0500
-
- Improve kill, wait, detach, and setpriority specs for Process.
-
- Restore any previously installed signal handler after the spec has run.
-
- User IO.read(1) instead of IO.getc since rubinius has it implemented.
-
- Fix a failing Process.detach spec uncovered by the raise_error fix.
-
-commit da7329d094b6ff437d37e6a1fcaf93883ac9172f
-Author: Chris Shoemaker <chris.shoemaker@cox.net>
-Date: Mon Dec 31 16:23:24 2007 -0500
-
- Add specs for Process.setrlimit, Process.getrlimit, and Process.setsid.
-
-commit 42bef2feb46434b0ea67bc3f93d941d587c2d9c9
-Author: Brian Ford <brixen@gmail.com>
-Date: Thu Jan 3 12:46:57 2008 -0800
-
- Updated Process spec excludes.
-
-commit ca98172b8a923cce1691b0fcc5d2418417d82662
-Author: Brian Ford <brixen@gmail.com>
-Date: Thu Jan 3 10:07:55 2008 -0800
-
- Update CI excludes for IO from Evan's fixes.
-
-commit cde20d6c32156e4fc06859f1e84414f81f5af69e
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Wed Jan 2 23:40:59 2008 -0500
-
- Fixed #require specs.
-
-commit 06d99a2ac4be06b50848056b381c91531293a49e
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Thu Jan 3 01:12:29 2008 -0800
-
- Add read buffering to IO, passes 100% of IO specs
-
-commit 86170283715371b5a87c0518f89c2b882a49bc93
-Author: Charles Nutter <headius@charles-nutters-computer.local>
-Date: Thu Jan 3 01:21:52 2008 -0600
-
- Fix off-by-one on a few signal values. Doh!
-
-commit c7a64b10410308cec83077a66cda5859b326f296
-Author: Charles Nutter <headius@charles-nutters-computer.local>
-Date: Thu Jan 3 01:13:27 2008 -0600
-
- Modify Signal.list spec to not depend on hash ordering.
-
-commit f2980d9584c08d873cf1646c281d083946bcbc6c
-Author: Nitay <nitay@powerset.com>
-Date: Wed Jan 2 14:36:56 2008 -0800
-
- Module#autoload:
- * raises a NameError when an invalid constant name is given
- * raises an ArgumentError when an empty filename is given
- * does not autoload when the specified constant was already set
- * registers the given filename to be loaded the first time that the Module
- with the given name is accessed
-
-commit e68bd05defe5ab749110af507c86769c9a036b25
-Author: Charles Nutter <headius@charles-nutters-computer.local>
-Date: Wed Jan 2 19:04:48 2008 -0600
-
- Removing 'Range#initialize can't be called twice' spec.
-
- Evan agreed that these specs aren't useful, and I don't believe they're
- within the bounds of reasonable language specification since they're
- going around visibility and testing behaviors no sane programmer would
- ever be able to see.
-
-commit 1870720bac174feb627654f08c1749e1666c2acc
-Author: Charles Nutter <headius@charles-nutters-computer.local>
-Date: Wed Jan 2 18:54:33 2008 -0600
-
- Fix inspect spec to guarantee the target thread is actually sleeping.
-
- A reminder for folks adding Thread specs: You *CAN NOT* know that a target
- thread is sleeping unless you are polling for status == 'sleep'. No amount
- of channel, lock, or state variable tricks will get around that. Please
- use polling if you want to guarantee a target thread is asleep.
-
-commit df3057a541862bbd1c5c72b8626bb591bb5ae6fd
-Author: Eric Hodel <drbrain@segment7.net>
-Date: Wed Jan 2 16:39:37 2008 -0800
-
- Refactor Module#undef_method spec to #respond_to? and #instance_methods.
-
- Now only method dispatch is tested for #undef_method. #respond_to? and
-
-commit d2ecd4119a152370210ccb6c2a816c9dccb9fe90
-Author: Eric Hodel <drbrain@segment7.net>
-Date: Wed Jan 2 16:00:09 2008 -0800
-
- Fix Rails indenting and whitespace
-
-commit f5b8afee4931bd09b0ce9fb88fc959c2ea0a1743
-Author: Eric Hodel <drbrain@segment7.net>
-Date: Wed Jan 2 15:30:41 2008 -0800
-
- Fix Module#undef_method and Module#instance_methods
-
-commit 82bf31562361a21f85a90d5628a40ff50280c555
-Author: Eric Hodel <drbrain@segment7.net>
-Date: Wed Jan 2 14:10:35 2008 -0800
-
- Rebuild excludes for #eof?
-
-commit b2aa0d56b04d7da5d333ba1449acda7c0b64c0c4
-Author: Eric Hodel <drbrain@segment7.net>
-Date: Wed Jan 2 14:09:21 2008 -0800
-
- Add IO#eof? spec.
-
-commit addeb47d834d1ce60f8146f747defacf1682e6c4
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Wed Jan 2 22:31:30 2008 +0100
-
- Removed JRuby spec excludes.
-
- The JRuby excludes will reside in JRuby repository.
-
-commit 3239661ed5c38b37c966588341a043d6cdd9445b
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Wed Jan 2 21:28:11 2008 +0100
-
- Corrected String#modulo tests after clarifications from ruby-core.
-
-commit a0f3ba6632f8486e8f07a21a8e4720d8727ba4d2
-Author: Brian Ford <brixen@gmail.com>
-Date: Wed Jan 2 11:28:42 2008 -0800
-
- Fix require_spec_recursive on Ubuntu.
-
-commit 857c39564df2d8da480f549fff46ec3ab880066e
-Author: Brian Ford <brixen@gmail.com>
-Date: Wed Jan 2 00:48:53 2008 -0800
-
- A couple fixes. Updated CI excludes for last couple failures.
-
-commit 58c48ed05b493c71ee445062f27d47909e18b395
-Author: Brian Ford <brixen@gmail.com>
-Date: Tue Jan 1 23:49:14 2008 -0800
-
- Updated CI excludes.
-
-commit 426f5a15eaac05ed1e900433837de0b9d0246c8d
-Author: Brian Ford <brixen@gmail.com>
-Date: Tue Jan 1 22:43:47 2008 -0800
-
- Moved CI excludes files from .spec dirs to spec/data/*.
-
-commit a1d6211f3185f23cbc2c929f0352feca05fd079c
-Author: Brian Ford <brixen@gmail.com>
-Date: Tue Jan 1 22:03:43 2008 -0800
-
- Moved ruby specs to spec/ruby/1.8/...
-
-commit af55eefd29c8acaf462efe03d2e0b3d95195cb21
-Author: Brian Ford <brixen@gmail.com>
-Date: Tue Jan 1 21:44:35 2008 -0800
-
- Updates for bin/ci and bin/mspec.
-
- * Removed -2 switch from both because compiler 2 is default.
- * Added CI_EXCLUDES_DIR and -E switch to bin/ci to allow for
- specifying the exclude directories. The default is '.spec'
- in each directory containing spec files. Use a path starting
- with a '/' to create the exclude directories relative to
- that path, otherwise the exclude directories are created
- relative to the directories containing the spec files.
- * Moved spec/excludes.txt to spec/data/critical.txt
-
-commit 0e6645eb74f1f63b84f674dbcdfa991153a3ccd0
-Author: Adam Gardiner <adam.b.gardiner@gmail.com>
-Date: Wed Jan 2 12:10:39 2008 +1100
-
- Couple of Breakpoint changes
-
- * Raise ArgumentError if no block given (spec for this
- existed, but was masked by RaiseErrorMatcher bug)
- * Added line property to Breakpoint
-
-commit 36a7acddfe74ab25895d13dd775741b042ba3b0c
-Author: Adam Gardiner <adam.b.gardiner@gmail.com>
-Date: Tue Jan 1 23:10:13 2008 +1100
-
- Reorganise breakpoint specs to new dir layout
-
-commit 8aa6712dd9e5e870194f77ff74dc8cf11c273805
-Author: Adam Gardiner <adam.b.gardiner@gmail.com>
-Date: Fri Dec 21 16:15:19 2007 +1100
-
- Refactored BreakpointTracker in preparation for debugger
-
- * Moved code from debugger.rb to breakpoint.rb
- * Refactored code extensively to support debugger
- * Added breakpoint specs
-
-commit d16e905a67d64f67d7a24ce113f39b4b059c4139
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Dec 31 17:51:59 2007 -0800
-
- Removed the rubinius dir from specs. It was redundant.
-
-commit 85ed07b6d739f013892a6cbcae5d0bb2c19f6e80
-Author: Brian Ford <brixen@gmail.com>
-Date: Sat Dec 29 15:45:31 2007 -0800
-
- Split Ruby specs proper from Rubinius specs.
-
-commit b8e1466dc1b814bfb2022c1e4319d5ba63f5d762
-Author: Brian Ford <brixen@gmail.com>
-Date: Sat Dec 29 15:02:55 2007 -0800
-
- Updated guards in specs.
-
- * Changed guard names to new, more descriptive names.
- * Removed all #extended_on guards for Rubinius-only specs.
-
-commit 5773ebe9e6f78abec9bfb03f144b5c7a86a27c7e
-Author: Brian Ford <brixen@gmail.com>
-Date: Sat Dec 29 00:50:56 2007 -0800
-
- Changed Float constants specs to compare against precise values.
-
-commit 71874fcdc9eaf45a5adecf57d7609831a2a8e6c2
-Author: Charles Nutter <headius@charles-nutters-computer.local>
-Date: Sat Dec 29 17:26:06 2007 -0600
-
- Fix dump_spec to expect 1 or more write calls, rather than exactly 1.
-
-commit d4bfb39910aa4adf2c0c4e2dee214487bac34093
-Author: Charles Nutter <headius@charles-nutters-computer.local>
-Date: Sat Dec 29 14:51:38 2007 -0600
-
- Add a spec for procs being block-passed and some peculiarities therein.
-
-commit 1b0333479bf6da2c76c8d3c1e1640dc156086d9f
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Fri Dec 28 08:24:30 2007 +0100
-
- Improved ObjectSpace#each_object spec test.
-
- Previously, the test was failing from time to time,
- depending on Garbage Collector behavior.
-
-commit 3d7e628acc6699f9652383317bd416d8c75329d5
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Fri Dec 28 05:27:24 2007 +0100
-
- Updated Time specs to use new :os guard.
-
- The Time specs use this :os guard to properly detect
- which external program with proper parameters to invoke.
-
-commit 7662638e9afa631f0581fc1c2b2b422b1b926f98
-Author: Jeremy Roach <jero_rub@yahoo.com>
-Date: Sat Dec 29 03:06:51 2007 -0600
-
- adds Marshal.dump specs
-
- for nil, true, false, String, Symbol, Fixnum, Bignum
-
-commit 93431a28d687372b95f1a1420a3bd1f24e660117
-Author: Charles Nutter <headius@charles-nutters-computer.local>
-Date: Sat Dec 29 00:15:44 2007 -0600
-
- Guard Continuation specs to not run on JRuby (JRuby does not, will not support continuations)
-
-commit ccf745b9eafe068de6f888de24387bc0a0e68859
-Author: Charles Nutter <headius@charles-nutters-computer.local>
-Date: Sat Dec 29 00:08:04 2007 -0600
-
- Fix for Fixnum size spec to guard "java" platform with 8 byte size
-
-commit 6f448f0dd72b5df2cc69e28db3d5593f897a9dbd
-Author: MenTaLguY <mental@rydia.net>
-Date: Sat Dec 29 00:58:58 2007 -0500
-
- a more modest spec for Thread.pass
-
-commit b32c2d95d044a4979ab92b5881e32fc8b169d931
-Author: Charles Nutter <headius@charles-nutters-computer.local>
-Date: Fri Dec 28 23:51:10 2007 -0600
-
- Adjust Float MAX spec tolerance to work on both JRuby and MRI, since there's a few powers of precision difference.
-
-commit af7bb00beeb359fd6183def039b9a1fcd0ce7c48
-Author: Charles Nutter <headius@charles-nutters-computer.local>
-Date: Fri Dec 28 23:39:15 2007 -0600
-
- Expand Float divmod array equality comparisons to use be_close with a default tolerance.
-
-commit dbdf373751bce2c8a334315c8c5ed21458614c70
-Author: Charles Nutter <headius@charles-nutters-computer.local>
-Date: Fri Dec 28 23:34:09 2007 -0600
-
- Add a tolerance to the Float induced spec around the same scale as the value under test.
-
-commit a713d277e6a8148d4c53b66a3a8fa3aedbd6a108
-Author: Charles Nutter <headius@charles-nutters-computer.local>
-Date: Fri Dec 28 23:31:25 2007 -0600
-
- Modify Float multiply spec to be_close with a TOLERANCE multiplied by a similar scale as the value under test.
-
-commit b82d8af43356de31d16b1c36296d9e819ce70d46
-Author: Charles Nutter <headius@charles-nutters-computer.local>
-Date: Fri Dec 28 23:13:38 2007 -0600
-
- Fix Module class_variables spec to sort the variables before checking if they are all there.
-
-commit 1e60a25b57273dd6fd7e21b0a443da1f5c0be9e5
-Author: Charles Nutter <headius@charles-nutters-computer.local>
-Date: Fri Dec 28 19:44:51 2007 -0600
-
- Mark Process#fork specs as not_compliant_on jruby.
-
-commit 021a6ff317ed826a46ca2168f4ee9c7540a27214
-Author: Charles Nutter <headius@charles-nutters-computer.local>
-Date: Fri Dec 28 19:19:14 2007 -0600
-
- Remove fail and "failure" guard around the require/extension spec, since an unimplemented spec isn't necessarily a failure of any kind.
-
-commit 520c423860ef6553dae34eefd85188ab9b4773f6
-Author: Charles Nutter <headius@charles-nutters-computer.local>
-Date: Fri Dec 28 19:12:52 2007 -0600
-
- Modify previous compliance change to callcc spec to use not_compliant_on instead.
-
-commit ab85bfff2f9fea8e28f9518311aacccd30f380dd
-Author: Charles Nutter <headius@charles-nutters-computer.local>
-Date: Fri Dec 28 17:56:42 2007 -0600
-
- Remove compliance guards on identical spec's link/unlink, since they don't blow up now and JRuby supports them.
-
-commit e79c8af0ad6fb7ddf094b6ba4747932145f9b89b
-Author: Charles Nutter <headius@charles-nutters-computer.local>
-Date: Fri Dec 28 15:19:24 2007 -0600
-
- Removing "fail" and "failure" wrapper from unimplemented "loads extension files" spec; an empty or unimplemented spec is not a failing spec.
-
-commit 0f6b7387bcc8df946ec8d7504cc3935b6d0f9c58
-Author: Charles Nutter <headius@charles-nutters-computer.local>
-Date: Fri Dec 28 15:06:07 2007 -0600
-
- Add compliance to callcc specs, so JRuby doesn't run them (since it never will)
-
-commit ed43292ce58468e31b771eb4926a39dff8d70793
-Author: Charles Nutter <headius@charles-nutters-computer.local>
-Date: Fri Dec 28 14:48:45 2007 -0600
-
- Make umask spec work with different host process starting umasks, clean up literals to be easier to read through.
-
-commit 7e9f96741739e544c547f2898e8b5183dec87323
-Author: Charles Nutter <headius@charles-nutters-computer.local>
-Date: Fri Dec 28 14:43:02 2007 -0600
-
- Fix goofed-up paths in requires for rubinius-specific Integer spec
-
-commit d54fb1e7c3f586a6d8ac200d6de839ebe6cb4c46
-Author: Charles Nutter <headius@charles-nutters-computer.local>
-Date: Fri Dec 28 14:40:50 2007 -0600
-
- Move rubinius-specific spec from core/kernel/Integer_spec to rubinius/core/kernel/Integer_spec.
-
-commit eb561025707736ebe196eab3b4ff2bd1c98f45a4
-Author: Brian Ford <brixen@gmail.com>
-Date: Thu Dec 27 23:51:42 2007 -0800
-
- Fixed language/block specs to guard ruby18 feature.
-
-commit 5659d057d756effe3acba1037d0ad6d638d930dd
-Author: Brian Ford <brixen@gmail.com>
-Date: Thu Dec 27 22:58:17 2007 -0800
-
- Changed Bignum specs to use value suitable for all implementations.
-
-commit 2646b1a17f898f05233622c9251c3c36632e82a7
-Author: Jeremy Roach <jero_rub@yahoo.com>
-Date: Thu Dec 27 23:43:42 2007 -0600
-
- implements m directive for String#unpack
-
- moves a couple misplaced methods from Numeric to Integer
-
-commit 496d6761d7377081ff76b263a51bb39d0e30d80a
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Wed Dec 26 18:07:45 2007 +0100
-
- Marked one Rubinius-specific Kernel spec test as such.
-
- Kernel#compile is not official part of Ruby.
-
-commit 50e35293bd3a117874203a75d214c3435170e5d3
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Wed Dec 26 17:43:03 2007 +0100
-
- Corrected String#pack with 'DEFG' pattern test.
-
- Now, numeric comparison of values is used, with precision,
- not literal string comparison.
-
-commit 0ef00fe14a04ef240fcca17d15271f92f2a44525
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Wed Dec 26 16:00:20 2007 +0100
-
- Added String#inspect test case with malformed UTF-8 string.
-
-commit 5bbde0cda03ea782090586a9afdb620663633456
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Thu Dec 27 13:30:34 2007 -0600
-
- switched ThreadGroup specs to use Channels
-
-commit e3abd8b834b9f923d94ae381e81977feb4a4f6f8
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Thu Dec 27 13:22:20 2007 -0600
-
- added Thread#stop? and fixed Thread#status + specs for Thread#status
-
-commit f8835353bc8be47760f70811616991463e4e681e
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Wed Dec 26 09:18:24 2007 +0100
-
- "Unexcluded" one Struct spec test for JRuby.
-
-commit 8a1b127cb33e43b916b0ccd820c6e16680cd4030
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Wed Dec 26 09:12:23 2007 +0100
-
- "Unexcluded" 6 Hash tests for JRuby.
-
-commit ae4ce805fb7611ea6de12b01b2500f501b54bd6a
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Wed Dec 26 09:01:35 2007 +0100
-
- "Unexcluded" 27 Array tests for JRuby.
-
-commit c84540f96d7e265732a204ed72b3873545624444
-Author: Brian Ford <brixen@gmail.com>
-Date: Thu Dec 27 00:08:06 2007 -0800
-
- Fixed Set#delete? spec to actually call delete?.
-
-commit e137c3279f511b49442ce2cea1b1832c1a0c6ab0
-Author: Brian Ford <brixen@gmail.com>
-Date: Thu Dec 27 00:00:56 2007 -0800
-
- Added some specs for Set.
-
-commit 8054ed86a93a72ad4629d6f52455892d620138b0
-Author: Nitay <nitay@powerset.com>
-Date: Tue Dec 25 17:30:56 2007 -0800
-
- require should prevent recursive includes infinite loop
-
-commit 23fb497a7ba2a853cbdc5e8a38b091df284a377e
-Author: Brian Ford <brixen@gmail.com>
-Date: Wed Dec 26 16:50:22 2007 -0800
-
- Updated status output options for bin/ci and bin/mspec.
-
- * Made dotted the default output format for bin/ci.
- * Added -m MARKER option to ci and mspec.
- * Added "Started" output as requested by autotest folks.
-
-commit 036b073753763afe86330d3f7fa0f61d755ac991
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Wed Dec 26 10:41:01 2007 -0500
-
- Moved class fixture back to spec/fixtures/.
-
-commit 91d46b86a86270bb3174909a2d5cbc343ea138c7
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Tue Dec 25 19:20:18 2007 -0500
-
- Added specs for $~, $&, $`, $', $+ and $1..N.
-
-commit c434614505511b8816548efcf4a4cf56d77220f4
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Tue Dec 25 19:19:11 2007 -0500
-
- Improved language-level class specs, moved fixture.
-
- * Class fixture copied to spec/language/fixtures/.
- * Disabled unnecessary class instance variable check and added
- new ones.
-
-commit 0a49f3485fe7e26cc7d7d5bc3cb800ddf9fd6231
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Tue Dec 25 19:13:22 2007 -0500
-
- Changed strange_block_args_subspec.rb to block_args_subspec_strange.rb
-
- * Name change to improve alphabetical sorting.
-
-commit 2ac50215dd32fd7ad2f2c20c7ae06ed73dc9f856
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Tue Dec 25 13:32:06 2007 +0100
-
- Added tests for Array#pack with "U" pattern.
-
- Note: The tests are exclided for Rubinius.
-
-commit 4c0993fa90010322bb823a9799a8b3ccdd585e2e
-Author: Jeremy Roach <jero_rub@yahoo.com>
-Date: Wed Dec 26 04:07:02 2007 -0600
-
- return excluded spec
-
-commit 0a69d9cd5a7d3a0be9411fa00c4eeebe5d270a0c
-Author: Jeremy Roach <jero_rub@yahoo.com>
-Date: Wed Dec 26 03:55:43 2007 -0600
-
- implements @AM directives for String#unpack
-
- squashes bug in a regexp where an alternation of things
- between begin and end assertions wasn't wrapped in group delimiters
-
-commit ddda4d49f5535577c147d2154ecdae7cb4e32e24
-Author: Brian Ford <brixen@gmail.com>
-Date: Wed Dec 26 01:16:13 2007 -0800
-
- Moved Kernel#load/#require fixtures to spec/fixtures.
-
-commit 0438e9e61c5958c5daf691b025e34bc79e7b2573
-Author: Brian Ford <brixen@gmail.com>
-Date: Wed Dec 26 01:06:12 2007 -0800
-
- Reorganized specs to group all Rubinius specs under spec/rubinius.
-
-commit a4c3e286e44ee3df88395b9b5f44d5804154ed2b
-Author: Brian Ford <brixen@gmail.com>
-Date: Tue Dec 25 19:32:55 2007 -0800
-
- Updated CI excludes.
-
-commit 8535481571712cf8c35f437c42ec53dcbfd44bc0
-Author: Brian Ford <brixen@gmail.com>
-Date: Tue Dec 25 15:52:53 2007 -0800
-
- Enhanced guard for detecting :ruby, :ruby18, :ruby19 engines.
-
- Changed dir specs to create the fixture directories with every
- run to prevent pollution of the directories from causing spurious
- errors.
-
- Added spec/core/dir/fixtures/mock to .gitignore.
-
-commit a6b07ec37da7a59f34f45dfc84a66729b12f63b7
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Dec 24 16:25:16 2007 -0800
-
- Removed Dir specs mock directories from version control.
-
-commit b0e4addbf7c6505c760e143e5fac0dab0109d8ac
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Tue Dec 25 13:17:28 2007 -0500
-
- Updated CI excludes for Dir.
-
-commit 80a9c6c2e2e5cd2acdcb6492c4a06fef258bb49e
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Tue Dec 25 13:17:09 2007 -0500
-
- Moved Rubinius-specific parts of #load/#require specs to extensions.
-
-commit 85f6b6e24518868f39ff39a5014a41a233237671
-Author: Jeremy Roach <jero_rub@yahoo.com>
-Date: Tue Dec 25 02:53:45 2007 -0600
-
- implements U directive for String#unpack
-
- uses only one of the exception messages every time
-
-commit b414c94db1fa1af8e6cd3382c34fc6de5ed3bd1e
-Author: Kevin Clark <kevin.clark@gmail.com>
-Date: Mon Dec 24 16:42:22 2007 -0800
-
- Merge identical specs
-
-commit e0f28c224a2348dbf7c005694971a86f8e6162e1
-Author: Kevin Clark <kevin.clark@gmail.com>
-Date: Mon Dec 24 15:59:24 2007 -0800
-
- Kernel.Integer() shouldn't pass a base to String#to_inum
-
-commit eb93da7c578599469fe209f7b1d30f0f77d148f5
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Sun Dec 23 16:43:33 2007 +0100
-
- Wrapped one String#crypt case into compliant block for JRuby.
-
- "hello".crypt("\x00\x00") is not really defined,
- and heavily platform dependent.
-
-commit 7594c89cf2f017cb1fffad16bac6fcc7c9629422
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Sun Dec 23 10:53:30 2007 +0100
-
- Added JRuby wrapper for String#% test.
-
- Allow "%e" % (0.0/0) in JRuby to return "NaN", and not "nan".
- I think, returning "NaN" is a proper behavior, and
- it seems that MRI 1.9 is also following it.
-
-commit eaf9e328e81f9c1d4e80737a96d0eea6b511fabb
-Author: Jeremy Roach <jero_rub@yahoo.com>
-Date: Mon Dec 24 06:55:30 2007 -0600
-
- implements BbHhIiLlSs directives for String#unpack
-
-commit 701945421d6a656f8b0b183052c4535a895e2afd
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Dec 24 00:44:26 2007 -0800
-
- Converted specs to use the new #platform guard syntax.
-
-commit 238fbbc2331a1926f3d3f447d8433b046e7d34ac
-Author: Tom Mornini <tmornini@engineyard.com>
-Date: Sun Dec 23 15:43:26 2007 -0800
-
- Clean up language on now understood and fixed alias_method e2mmap spec.
- Fixing the alias_method problem has now uncovered something in const_set,
- so I've included a very vague test (require 'e2mmap') to document the
- problem until it's better understood.
-
-commit 69149b261ac13cc1a2b7c80c7b103d397fd96b9b
-Author: Tom Mornini <tmornini@engineyard.com>
-Date: Sun Dec 23 14:13:22 2007 -0800
-
- Add spec for alias usage that breaks e2mmap.rb
-
-commit 71d9a4144811b2c9c74edc55f348637c57b0cb84
-Author: Jeremy Roach <jero_rub@yahoo.com>
-Date: Sun Dec 23 05:25:37 2007 -0600
-
- implements aDdEeFfGgXx directives for String#unpack
-
-commit bebafb1383a5126c959c33a1336f3a2e4b6993f6
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Sat Dec 22 18:16:14 2007 -0500
-
- Saner specs for stream-style Dir access. Passes 1.8.6-p111.
-
- * Dir#read, #tell, #pos, #pos=, #seek and #rewind which are a part
- of the stream interface to Dir no longer rely on platform-specific
- position values, instead opting to just ensure they work as expected.
-
-commit a2e4c318a3406c9532404611f14d2790695c0a7a
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Sat Dec 22 16:29:00 2007 -0500
-
- Enabled Time#at spec to work with BSD `date`.
-
-commit 0e983f2e948ab997834dbc703e9eeb11d86a7022
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Sat Dec 22 16:17:14 2007 -0500
-
- String#to_i spec to check for correctly parsing 0x-1 and the like.
-
- * This was fixed in 1.8.6-p111.
-
-commit 5e635a46f4733bcc2071b52ea076584614fe5655
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Sat Dec 22 15:52:03 2007 -0500
-
- Fixed various String spec issues and added a few. Passes 1.8.6-p111.
-
- * String#% with o for octal numbers is still broken but that seems
- to be due to MRI's sprintf.c.
-
-commit 780f22bde03e280f5af2509bef260585341f4e0b
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Sat Dec 22 15:48:55 2007 -0500
-
- Fixed incorrect use of #should raise_error.
-
-commit 0b239b4f66c20ad5690e429639c4bf11a809ab58
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Sat Dec 22 12:22:20 2007 -0500
-
- Hash specs fixed. Pass under 1.8.6-p111.
-
- * Changed to use HashSpecs#frozen_hash and #empty_frozen_hash
- for clarity and being less error-prone.
- * Fixed various typos causing problems.
-
-commit 9a2450e5c51333474cf012c3a1364e95384af9e0
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Sat Dec 22 12:20:48 2007 -0500
-
- Kernel.caller specs revised. Pass 1.8.6-p111.
-
- * Fuzzier matching of the data in the call stack.
- * Fixed specs for omitting frames.
-
-commit 692f4e8a652e273096c0f77ffe571318c59d2b12
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Sat Dec 22 10:59:19 2007 -0500
-
- File.ftype specs pass on 1.8.6.
-
- * Use `find` to locate specific file types instead of relying on
- predefined paths being correct.
- * Re-enabled character devices.
- * FreeBSD does not implement block devices.
-
-commit f1251ebc602311ec305a4b1b35a765ee45b9c164
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Sat Dec 22 10:11:07 2007 -0500
-
- Bignum#div returns an Integer if evenly divided.
-
-commit b62e1b7a21df1d7736767530f216148b8a93e38a
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Sat Dec 22 09:52:33 2007 -0500
-
- Fixed Array spec failures under 1.8.6-p111.
-
- * Array#fill raises if given a negative count.
- * Array#initialize will always raise if frozen.
-
-commit e3d6a3df6c1dfc37731ff4de5de32dc996bb61bb
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Sat Dec 22 09:37:46 2007 -0500
-
- Silence warnings from removing *.rbc in #load and #require specs.
-
-commit a11171e853b3efb94b4cba03786ea851d81411c6
-Author: Jeremy Roach <jero_rub@yahoo.com>
-Date: Sat Dec 22 07:39:40 2007 -0600
-
- implements CcQqVv directives for String#unpack
-
-commit eea90994f2a1b76ed11b29e05a16c9c299d59235
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Sat Dec 22 00:23:29 2007 -0500
-
- Added __FILE__ specs to #load.
-
-commit 0e04ca49ebdba35a7a293b6de82d9d67c6ff4ac5
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Fri Dec 21 22:59:50 2007 -0500
-
- Correct __FILE__ information from #load and #require.
-
-commit 51c2543fe032b680a6c8f8cf8121196070c61c66
-Author: Brian Ford <brixen@gmail.com>
-Date: Fri Dec 21 23:51:37 2007 -0800
-
- Replaced use of @path1 with equivalent nil in File#fnmatch.
-
-commit b9f979393456dc3c93250e3a50b54b489a25c5d1
-Author: Brian Ford <brixen@gmail.com>
-Date: Fri Dec 21 23:29:51 2007 -0800
-
- Added -w to bin/mspec to emit warnings. Fixed warning in mSpec.
-
-commit 16ce249216f490b9f7921aa69932f9e8bd60ca0e
-Author: Jeremy Roach <jero_rub@yahoo.com>
-Date: Fri Dec 21 22:50:40 2007 -0800
-
- Implements N, n, and Z directives for String#unpack.
-
- Signed-off-by: Brian Ford <brixen@gmail.com>
-
-commit e1d292e28fe409c087f314bb139371a1f248850d
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Thu Dec 20 15:04:12 2007 +0100
-
- Fixed race condition in ThreadGroup#add specs.
-
-commit 469527ddf33484a4a77f3d73c611e9a393bd48ad
-Author: Adam Gardiner <adam.b.gardiner@gmail.com>
-Date: Fri Dec 21 12:02:50 2007 +1100
-
- Added CompiledMethod#decode specs
-
- * Added UnboundMethod#compiled_method accessor
- * Improved robustness of ISeq decode when dealing with junk at
- the end of an iseq
-
-commit 08c2f5c29a2debed90ae1fff817c30e269913609
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Thu Dec 20 23:45:53 2007 -0500
-
- Re-enabled purging .rbc files in require_spec and fixed the masked problem.
-
-commit dd4f3c52e79d01e826918e49fa626d7358f87901
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Thu Dec 20 22:53:48 2007 -0800
-
- Clean up a couple of failures seen in ci. spec/core passes.
-
-commit a5667632ae8d112c0271e00cbba53a274075cd1a
-Author: Brian Ford <brixen@gmail.com>
-Date: Thu Dec 20 22:49:05 2007 -0800
-
- Removed legacy, unused spec/reports/base.txt.
-
-commit 853e100b6f7fff24e4aaa40ed30c6add523f8df2
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Thu Dec 20 17:49:36 2007 -0800
-
- Fix a bunch of String specs (thanks random8r)
-
- * Note: rubinius now has the same behavior as MRI for Nan,
- Infinity and -Infinity when using String#to_f
-
-commit b220f4921fd799ac28c60132ca08cf16df6f713e
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Thu Dec 20 15:37:25 2007 -0600
-
- fixed require specs to work correctly on any run including first
-
-commit 56ac483e3559e1d4913e4c36c9a8f007523fdab0
-Author: Hunter Kelly <retnuh@gmail.com>
-Date: Thu Dec 20 19:36:21 2007 +0000
-
- Fix typo in spec/core/regexp/union_spec.rb
-
-commit 634300eed40ef0ded16ab7cac7865dd783486c2d
-Author: Charles Nutter <headius@charles-nutters-computer.local>
-Date: Thu Dec 20 03:46:59 2007 -0600
-
- Add 'sleep' checks to threadgroup spec to avoid the same race conditions seen in kernel/sleep_spec.
-
-commit 72b7123c9b3d1d266f4ce035b4e99dd0c2dbd88d
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Wed Dec 19 22:46:17 2007 -0500
-
- New compliant (moreso, anyway) #load and #require.
-
- * Improved #load and #require.
- * Specs for the above.
- * File.to_sexp and String#to_sexp allow empty input. They are
- processed as a file containing 'nil'.
- * Archive#get_object_fuzzy allows no extension or .rb instead
- of .rbc only.
-
-commit fe633062095096fe00599cbb89aa4370ab5ccb3e
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Wed Dec 19 23:03:08 2007 -0800
-
- Fix Kernel#puts
-
-commit 364ca08cbbb1848b549d99deb11e2449ad99334a
-Author: Brian Ford <brixen@gmail.com>
-Date: Wed Dec 19 23:10:17 2007 -0800
-
- Updated CI excludes.
-
-commit 5f1c381560a8d4d594749d42b5b2feeec341d4e5
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Wed Dec 19 22:24:10 2007 -0800
-
- Fix Kernel#open
-
-commit 3b3ed6304deab01cb448665c5f4b17d813f04e65
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Wed Dec 19 21:43:58 2007 -0800
-
- Cleanup more method specs, all pass on rubinius now
-
-commit 76bbbf275f4e835444f684b2e688b292f20c1ffe
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Wed Dec 19 18:08:09 2007 -0800
-
- Implement protected methods
-
- * Added a bit more verbose specs to methods_spec.rb, to show
- specific cases.
-
-commit dce06b35481bb1951c587d36f63abaae069d0ae4
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Tue Dec 18 22:28:30 2007 +0100
-
- Wrapped one String#unpack test case into compliant block.
-
- The test case is platform-specific, and not suitable for, say, JRuby.
-
-commit bb4945ea7b9253150f753508e92633b6e355194a
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Tue Dec 18 21:30:24 2007 +0100
-
- Added new String#unpack test to exclude file for CI.
-
-commit 1bd8beb8e0b335f1de309d6320312a1b64af1e4d
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Tue Dec 18 19:51:47 2007 +0100
-
- Added more tests for String#unpack with Z/Z* patterns.
-
- These patterns are known to be tricky, and their
- handling was changed during Ruby's life.
- See [ruby-talk:98364].
-
-commit d26edc2269a77667dbefcfb1ea6212d8ada9ef97
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Wed Dec 19 01:25:27 2007 -0800
-
- Fix a bunch of Task GC problems, better memory management.
-
- * Use ALLOC* macros instead of malloc/calloc directly
- * Also, simple fix for Time
- * A Kernel#loop implementation
-
-commit 4143b92e6112241ff2facd64047491ce579bf0e9
-Author: Brian Ford <brixen@gmail.com>
-Date: Wed Dec 19 00:43:32 2007 -0800
-
- Finished converting Object.new to mock() in specs.
-
-commit 9cae61f827d2eeca0a744e551551efd6bc85a2ae
-Author: Brian Ford <brixen@gmail.com>
-Date: Wed Dec 19 00:02:46 2007 -0800
-
- Spec #it blocks must be inside #describe blocks for RSpec.
-
-commit 7df00ef6d2471d0b37829e0a4d1ef45edf782a44
-Author: Brian Ford <brixen@gmail.com>
-Date: Tue Dec 18 23:28:43 2007 -0800
-
- More conversion of Object.new to mock() in specs.
-
-commit 12463512d0ad48fae3a1843d9d409649551dd13b
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Mon Dec 17 22:53:38 2007 +0100
-
- Corrected String#* test to pick large enough Bignum, even on x64.
-
-commit 79cbff2c9a0cb15e9e5767f94242fa4360a0c4a0
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Mon Dec 17 16:43:16 2007 +0100
-
- Removed race condition from Kernel.sleep spec.
-
- This problem caused JRuby spec runs to hang.
-
-commit 3032e60e10dd1ae61ffb40b351f4f6731395602b
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Mon Dec 17 15:43:42 2007 +0100
-
- Enabled one Hash#rehash test case for JRuby
-
-commit 1808106191856f4f82b948abc5c7e708a747d059
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Mon Dec 17 15:40:49 2007 +0100
-
- Issue #153: Hash#rehash test enforces unspecified impl detail
-
- Wrapped the test so that it won't run with JRuby.
-
-commit efbf30477ea289911d9cafbde89ecbe2c8c65089
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Mon Dec 17 15:25:23 2007 +0100
-
- Corrected :mri --> :ruby
-
-commit 60a3ede3c64b62fb26905ed1c236c0e241b64515
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Mon Dec 17 15:23:42 2007 +0100
-
- Issue #182: String#to_f spec corrections for NaN, Infinity
-
- JRuby AND Rubinius treat "Infinity".to_f, "-Infinity".to_f ,
- "NaN".to_f differently than MRI.
-
- MRI returns 0.0 in all those cases, but JRuby and Rubinius probably
- do something more meaningful, they return Infinity, -Infinity and Nan
- respectively.
-
- It was agreed that JRuby's and Rubinius' behavior is a feature rather
- than a bug, and worth preserving and checking for.
-
-commit 521a82d8c325a33b3409423d61b589c7b8681870
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Mon Dec 17 15:14:28 2007 +0100
-
- Refactored commonly used generators into fixtures.
-
- Thus reducing copy-paste.
-
-commit 86820a339c74e3ca8fc9515e5fdf31ad42780201
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Mon Dec 17 14:12:43 2007 +0100
-
- Initial version of Generator specs.
-
-commit 91353183ace65d8e751db14a829e8f24d043710c
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Tue Dec 18 03:18:19 2007 -0600
-
- updated excludes for Kernel#sleep and Thread
-
-commit 6de193c0819f74717eb2e9eff8480f0d801b0e41
-Author: Brian Ford <brixen@gmail.com>
-Date: Tue Dec 18 01:01:31 2007 -0800
-
- Replaced Object.new with mock() where appropriate.
-
-commit 1217fa030ff26712e9718ebecfe351830c543d7e
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Tue Dec 18 02:16:10 2007 -0600
-
- fixed redo in loop by save/restore condmod around loop context in compiler1
-
-commit df757142c774becfc2cbc4b38e43e31056acbae2
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Tue Dec 18 02:00:27 2007 -0600
-
- spec for using redo,next, and break in one loop
-
-commit 7169fd31b7c22750241212c242bc8aacdafe632f
-Author: Vladimir Sizikov <vsizikov@gmail.com>
-Date: Mon Dec 17 13:08:09 2007 +0100
-
- String#sub specs wrapped to correct JRuby test failures.
-
- JRuby reports Ruby version to be 1.8.5, but in this
- particular case it behaves like Ruby 1.8.6
-
- Differences between Ruby 1.8.5 and Ruby 1.8.6:
- different error raised.
-
-commit 04e228e131d06cd764d69375ddfdf44e4fec2b38
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Tue Dec 18 01:27:00 2007 -0600
-
- spec for Thread.pass and updated :mri to :ruby
-
-commit 11348e25ba30199e3beb05f8c38c18820fbefc3f
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Tue Dec 18 01:11:38 2007 -0600
-
- Some minor fixes in Thread specs
-
-commit 5cb3bcbf8f1d2a2237200ca0a9a9c6408d478ad6
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Tue Dec 18 01:11:05 2007 -0600
-
- spec and basic functionality for Thread.stop
-
-commit 3301fbb3ec43b5252c0aa6d45eb2f0e21581ff0a
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Tue Dec 18 01:09:49 2007 -0600
-
- Thread.sleep doesn't even exist in rubinius
-
-commit bd964f579f84a39097ecee1271664d672b6553a7
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Dec 17 21:40:16 2007 -0800
-
- Replaced :mri with :ruby for spec guards.
-
-commit d21810882621356c35dcd101daca5ee5549f6607
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Tue Dec 18 00:42:32 2007 -0600
-
- Threads should report there status of sleep, aborting, and run
-
-commit 85a6476a236bd1e65d42ca03846c662a10842f37
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Tue Dec 18 00:41:09 2007 -0600
-
- Thread#status should return nil if Thread terminates with an exception
-
-commit ecb4455a75f4af2ae0059ca4960c2282b4ec632a
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Mon Dec 17 23:50:24 2007 -0600
-
- specs for Thread#{key?,keys} and added key type checks for Thread#{[],[]=}
-
-commit c1a5d7e52b33ba6686441c61652bcc41ae0547f8
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Mon Dec 17 22:15:37 2007 -0600
-
- specs for Thread#[]
-
-commit c2c7f0adc6ebbad925adb2471b6064b67528b420
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Mon Dec 17 21:47:52 2007 -0600
-
- ensure LocalThread#current != Thread.current
-
-commit d05dac276f36326e143aa75bb43e4ab07bd8ddc9
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Mon Dec 17 21:28:44 2007 -0800
-
- Fix a bunch more Kernel specs
-
-commit 4ddd0e144b4e4f64c51fc8d64952826d92a5e83f
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Mon Dec 17 19:45:26 2007 -0800
-
- Fix Thread.abort_on_exception and Thread#inspect
-
-commit a12ad6fbc2589a7864a7c784386fb6ce7dae1db1
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Mon Dec 17 21:29:49 2007 -0600
-
- Kernel#sleep and Thread#join specs now use locks to maintain automaticity instead of while th.status == 'run' loops
- added a Channel fixture to Kernel to support the use of locks in Kernel#sleep specs
-
-commit 72e3fb453c266e514b817daa66bf6033f1d19e40
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Mon Dec 17 19:01:18 2007 -0800
-
- Fix callcc specs, revert all locals back to using the locals tuple
-
- * compiler1 now does what compiler2 is going to do, ie, only use the
- locals tuple to store locals. Storing them on the stack has proved
- to be a pain, and wont be used further.
-
-commit 6e35be2ddef8d055e064462c88a8b3f33eb4fe0f
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Mon Dec 17 18:37:16 2007 -0800
-
- Faster Class#new, initialize can be private
-
- * Class#new now uses a bunch of inline assembly to be able
- to call a private initialize
- * Clean up Module#name a little
- * Made machine's rbt a little more robust
-
-commit 47a5bbf34ef8a60a18c1c8c6130d493a299ff852
-Author: Hunter Kelly <retnuh@gmail.com>
-Date: Tue Dec 18 01:10:33 2007 +0000
-
- Make sure files opened with "w" are truncated.
-
-commit 0fdc8c9b7d05cc2e96908b280ac144de0d04f646
-Author: Hunter Kelly <retnuh@gmail.com>
-Date: Tue Dec 18 00:16:27 2007 +0000
-
- Fix excludes for spec/core/stuct/{new,struct}_spec.rb
-
-commit 5b1252e6b2d8f8d70343b06f3520114de2040524
-Author: Hunter Kelly <retnuh@gmail.com>
-Date: Sat Dec 15 17:31:25 2007 +0000
-
- Minor fix to struct_spec to include fixture.
-
-commit 4fd0356ab9e9bb5c2a805b1f863b3177458966fe
-Author: Hunter Kelly <retnuh@gmail.com>
-Date: Sat Dec 15 16:29:49 2007 +0000
-
- Add case to spec/core/class/new_spec for names of nested classes.
-
- * Updated spec
- * Add some comments where this may be fixed
-
-commit 86736d564f34a2f97f7c7bedcab09c2472861b01
-Author: Hunter Kelly <retnuh@gmail.com>
-Date: Sat Dec 15 16:16:26 2007 +0000
-
- Fixes for struct class names.
-
- * Tighten up specs to show what class names should be.
- * Fixes #inspect
- * (Partially) solves the larger issue of an anon class getting a name when
- assigned to a constant - works now when Module.const_set is called.
-
-commit ad0d5ff2396baf43c8b2e37a3132765a074b241d
-Author: Hunter Kelly <retnuh@gmail.com>
-Date: Fri Dec 14 02:33:23 2007 +0000
-
- Fixes related to Struct.new
-
- * Fix to method_table to correctly handle DelegatedMethods
- * Changed spec/core/stuct/new_spec.rb to allow :rbx to call
- to_sym on objects passed to Struct.new to get the symbol
- value.
-
-commit 18f10dc700fe24f3bd230063bc7c1e8a82e8348f
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Dec 17 08:58:22 2007 -0800
-
- Updated spec excludes to run with bin/ci under the new mspec.
-
-commit 678fb90c5c8aa96e10a9f95f520312f12f8fa3f2
-Author: Brian Ford <brixen@gmail.com>
-Date: Sat Dec 15 22:43:44 2007 -0800
-
- Changed true/false/nil specs to not use def in describe block.
-
-commit 9e132474aafb6a0f0c968c2e085b09bfc07e1a0d
-Author: Brian Ford <brixen@gmail.com>
-Date: Sat Dec 15 18:49:31 2007 -0800
-
- Fixes to run the specs under RSpec and mSpec.
-
-commit cd3ecf52645b94921db92393e6e4d295d12bba88
-Author: Brian Ford <brixen@gmail.com>
-Date: Sat Dec 15 00:59:11 2007 -0800
-
- Misc fixes to mspec. bin/mspec -t r spec finally runs!
-
-commit f3b3f70bb47b04e7a67c1dbc3ae38711857b5184
-Author: Brian Ford <brixen@gmail.com>
-Date: Thu Dec 13 22:46:54 2007 -0800
-
- Multitudinous miscellaneous fixups for mspec and mmock.
-
-commit 55ab5b2ee42e4fabcfd8c51d6fac304cdfec31c7
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Dec 10 01:01:58 2007 -0800
-
- Various fixes to mspec to run Rubinius specs.
-
-commit 86c0f131608b4ad7cba93eabd172a48e5b60ca0f
-Author: Brian Ford <brixen@gmail.com>
-Date: Fri Dec 7 15:34:06 2007 -0800
-
- Added runner guards to omit specs that will always fail under RSpec.
-
-commit 75706dbfabbe359b6410f0d3743f0ea682146ac1
-Author: Brian Ford <brixen@gmail.com>
-Date: Fri Dec 7 14:03:46 2007 -0800
-
- Added #runner guards to mspec.
-
-commit 3da390988031bf0066a849934ee758475ebbfa04
-Author: Brian Ford <brixen@gmail.com>
-Date: Fri Dec 7 02:38:13 2007 -0800
-
- More fixes to run the specs under RSpec.
-
-commit 2b0f4e408b733dcd9089a19d78cd8e4cce20b99c
-Author: Brian Ford <brixen@gmail.com>
-Date: Thu Dec 6 18:40:33 2007 -0800
-
- Yet more spec cleanup to run under RSpec.
-
-commit 1e4171d4682f55776e01e42f564714548c1d9bd9
-Author: Brian Ford <brixen@gmail.com>
-Date: Thu Dec 6 02:16:42 2007 -0800
-
- More changes to run specs under RSpec.
-
-commit db020d30374e419792f76077757784008953c0a6
-Author: Brian Ford <brixen@gmail.com>
-Date: Wed Dec 5 02:01:30 2007 -0800
-
- Various changes to get the specs running under RSpec.
-
-commit 968c2daa5345a0cddb8d3d5bd2b6bf2eeb0c1d6f
-Author: Brian Ford <brixen@gmail.com>
-Date: Tue Dec 4 23:51:52 2007 -0800
-
- Convert remaining mocks to RSpec syntax.
-
-commit e5dc3ac814d1cda923131257dfbc9a30bf501b62
-Author: Brian Ford <brixen@gmail.com>
-Date: Tue Dec 4 23:28:17 2007 -0800
-
- Convert remaining 'should_raise' to 'should raise_error'.
-
-commit a7be230ac71ece2bb8dcece72d629bcd0ce6a5e0
-Author: Brian Ford <brixen@gmail.com>
-Date: Tue Dec 4 18:29:26 2007 -0800
-
- Converted specs from mini_mock to RSpec mock syntax.
-
-commit 4136e2fef4a81eb6e9e14070ff5301638f9acf14
-Author: Brian Ford <brixen@gmail.com>
-Date: Tue Dec 4 02:25:31 2007 -0800
-
- Integrated mini mock with mspec. Updated spec_helper for main specs.
-
-commit d71c0c7412af01d6295d8caab43a80d0221ea16d
-Author: Brian Ford <brixen@gmail.com>
-Date: Tue Dec 4 01:49:17 2007 -0800
-
- Added #shared and #it_behaves_like to mspec.
-
-commit da61adc0a079c858385773b12d683e2f5e2cc0e8
-Author: Brian Ford <brixen@gmail.com>
-Date: Tue Dec 4 00:43:15 2007 -0800
-
- Converted 'should_be_ancestor_of' to 'should be_ancestor_of'.
-
-commit 5ed0096aac58fef09fc766d808aea74356aacfa8
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Dec 3 17:57:56 2007 -0800
-
- Replaced dev_null with CaptureOutput.
-
-commit 62282bd5cb5c555e6447dcf2d6d0da355913fe8b
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Dec 3 17:30:01 2007 -0800
-
- Replaced 'should_include' with 'should include'.
-
-commit f990a7c58a7eee6dbbb3c50df7682942048b959f
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Dec 3 17:21:50 2007 -0800
-
- Replaced 'should_be_close' to 'should be_close'.
-
-commit c53601c56bd222dfacf03f134132869eb71c5146
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Dec 3 17:10:41 2007 -0800
-
- Finished converting should_raise to raise_error.
-
-commit 165dd99535b0829d2e2364fac24375068969c6ab
-Author: Brian Ford <brixen@gmail.com>
-Date: Sun Dec 2 23:22:54 2007 -0800
-
- Convert should_raise to should raise_error for RSpec compatibility.
-
-commit c9ff50a4b4be25614cc0ac2ea5540cfe87a939d3
-Author: Brian Ford <brixen@gmail.com>
-Date: Wed Nov 28 23:30:44 2007 -0800
-
- Moved mspec out of spec dir.
-
-commit e9a40a77b6fa7d08969ea195aabbb930b665fe02
-Author: Brian Ford <brixen@gmail.com>
-Date: Wed Nov 28 23:25:59 2007 -0800
-
- MSpec base formatter and specs.
-
-commit 2fc3ac3f8efbaf0861cadfd59bcdf926d2196284
-Author: Brian Ford <brixen@gmail.com>
-Date: Wed Nov 28 20:32:42 2007 -0800
-
- Port fix to ruby engine detection from mainline.
-
-commit 9a52e660536b4723bf24e2717fec757a1bdfa49f
-Author: Brian Ford <brixen@gmail.com>
-Date: Wed Nov 28 01:35:52 2007 -0800
-
- Match RUBY_NAME against /^ruby/ to pick up e.g. ruby1.8.
-
-commit 85536b98862f6abec310bfad03be17652ee65944
-Author: Brian Ford <brixen@gmail.com>
-Date: Wed Nov 28 01:01:46 2007 -0800
-
- Implemented mspec matchers.
-
-commit c953335397c6c8b9d7b27a3d240fde3b3518cb48
-Author: Brian Ford <brixen@gmail.com>
-Date: Tue Nov 27 01:35:07 2007 -0800
-
- The rest of the mspec big picture.
-
-commit 2f598f193eb1b10065c8e1a8d5c2aaa89c689072
-Author: Brian Ford <brixen@gmail.com>
-Date: Tue Nov 27 00:39:59 2007 -0800
-
- Added base operator matchers and specs.
-
-commit 0cc0b5a97661970d4cbb5e46406e7ee06421e637
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Nov 26 21:03:33 2007 -0800
-
- Migrated mspec and ci runners to mspec dir.
-
- Created stubs in bin/ci and bin/mspec that call the respective
- scripts in spec/mspec/scripts.
-
-commit b98d65eaa90d966fc2f7b8f8387266e241c202de
-Author: Brian Ford <brixen@gmail.com>
-Date: Sun Nov 25 01:03:26 2007 -0800
-
- Added specs and guards for mspec.
-
-commit 7bb316d1291c9d0a16904d4a3ee60094a713f215
-Author: Brian Ford <brixen@gmail.com>
-Date: Sat Nov 24 21:40:46 2007 -0800
-
- Prevent MSpec's #should(_not) from overriding RSpec's.
-
-commit c446988257a2104d72abd4a362dc21ca6183aab0
-Author: Brian Ford <brixen@gmail.com>
-Date: Tue Nov 20 22:47:25 2007 -0800
-
- Defines #should and #should_not for mspec.
-
- Specs for #should and #should_not.
- Adds example for using mspec "base" layer.
-
-commit 1aecf8e828dfd3d86f43d8c9c927e7c0ccb16b68
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Nov 12 00:40:04 2007 -0800
-
- The mini rspec big picture.
-
-commit f2979b03f29e7ac810b81f9087ea53923de5a35c
-Author: Charles Lowe <aquasync@gmail.com>
-Date: Mon Dec 17 15:18:24 2007 +0100
-
- Added missing error checks to Dir.chdir block form.
-
-commit 028fee4e6d48514cae53f87c143bb68501bf58e9
-Author: Chris Shoemaker <chris.shoemaker@cox.net>
-Date: Wed Dec 12 20:01:35 2007 -0500
-
- Add further specification of size changes during Hash#delete.
-
- This was actually failing a while ago but now passes after recent
- changes.
-
-commit f757f4359c86f778ac8e5931b8915511fd03506d
-Author: Chris Shoemaker <chris.shoemaker@cox.net>
-Date: Wed Dec 12 19:59:28 2007 -0500
-
- Tighten another spec in core/hash/equal_value_spec.rb
-
- Hash#== compares keys with matching hash codes via eql?
-
- This spec was using hash keys where key.eql?(key) was false.
-
- That's pretty pathological, but there's probably some real
- non-conformance with MRI here. MRI can test for object identity
- without calling eql? so a key is still found even if it doesn't
- eql? itself.
-
- That's not really related to the behavior this spec is specifying,
- though. So, this patch just uses a less pathological implementation
- of eql?
-
-commit 3f73ddf6bec5c704ceb5ed43481971860293353d
-Author: Chris Shoemaker <chris.shoemaker@cox.net>
-Date: Wed Dec 12 19:49:49 2007 -0500
-
- Tighten spec in core/hash/equal_value_spec.rb
-
- "Hash does not compare keys with different hash codes via eql?" was
- failing because it detected that eql? was called on a key. However,
- eql? was not being used to compare keys with different hash codes
- from the two hashes. Instead, eql? is used to compare a key to itself
- during hash element reference, in order to distinguish between two keys
- with equal hash codes that aren't eql?.
-
- The tightened spec only fails if the keys are compared eql? to each other.
-
-commit e355e98a32f34619628a17f5052750da6881cda9
-Author: Chris Shoemaker <chris.shoemaker@cox.net>
-Date: Wed Dec 12 12:26:15 2007 -0500
-
- Add specs for hash stability of various Numeric subclasses.
-
-commit 0d774c99254b2c5992a17ecb2a5a12dcd2cad05e
-Author: Chris Shoemaker <chris.shoemaker@cox.net>
-Date: Tue Dec 11 20:37:45 2007 -0500
-
- Add a Hash#store spec for storing unequal keys w/ same hash.
-
-commit edfff4981285007ecac132f565243150a8a8bd7e
-Author: Curtis Schofield <123@noself.net>
-Date: Tue Nov 27 19:02:45 2007 -0800
-
- Specs created for Process#gid and Process#uid
-
- * both are using the unix system command 'id'
-
-commit 4e269d01238537cc45f4c347b12053616007d94d
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Sun Dec 16 23:46:50 2007 +0100
-
- Excluded evil Thread specs.
-
- This makes bin/ci usable (pass) again on my system, where it was horribly
- broken before.
-
-commit b32c46ba95f2ecdaf646a030b96ee9b3737929a0
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Sun Dec 16 23:37:26 2007 +0100
-
- Excluded failing Kernel#eval specs.
-
-commit 0c56f3a1f84dd94d1f9685af9e9d6e0efd0cfabf
-Author: Hunter Kelly <retnuh@gmail.com>
-Date: Sun Dec 16 20:24:54 2007 +0000
-
- Tighten up specs for what should happen when array shrinks during iteration.
-
-commit bfa8c532605c9e3b3d7f853516de9aae596c611d
-Author: Hunter Kelly <retnuh@gmail.com>
-Date: Sun Dec 16 19:11:25 2007 +0000
-
- Added specs for Array#each when the array is changed during iteration.
-
- Ditto for Array#each_index.
-
-commit b3aa2af4a3467b4eeb8765010286c12bd5adfbf9
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Sat Dec 15 22:53:35 2007 +0100
-
- Sanitized Object#id spec.
-
-commit cce5b7004a774041d78c3b2e55af8063335a9512
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Fri Dec 14 19:02:57 2007 -0800
-
- Fix sleep spec, implement Thread sleep status and death detection
-
-commit c2475838be23ae287075b7e9ea832013f1db77c4
-Merge: 30f20cf... d061b86...
-Author: Charles Nutter <headius@charles-nutters-computer.local>
-Date: Fri Dec 14 10:56:53 2007 +0100
-
- Merge branch 'master' of git@git.rubini.us:code
-
-commit 30f20cfbd67487c426827406890fdb06fac8045c
-Author: Charles Nutter <headius@charles-nutters-computer.local>
-Date: Fri Dec 14 10:56:17 2007 +0100
-
- Fix race conditions in Kernel#sleep spec by ensuring target thread is actually sleeping before continuing.
-
-commit d061b864f636210e40982d961b0aa5afc24543d0
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Thu Dec 13 23:04:27 2007 -0800
-
- Fix require specs to not require checked in .rbc or .rba files
-
-commit 41831976d25a4d5a8e26673199276098cc45b4d3
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Thu Dec 13 22:40:43 2007 -0800
-
- Fixed Thread#run, added corruption detection to rbc files
-
- * Thread#run was confusing the Thread scheduler, cause things the VM
- to quit running.
- * Added corruption detection to .rbc files in the form of a SHA1
- hash placed in the .rbc, just after the header.
-
-commit 77f0f29060d5ba3f33dc45029525acb715eb61c2
-Author: Adam Gardiner <adam.b.gardiner@gmail.com>
-Date: Fri Dec 14 15:10:59 2007 +1100
-
- Compiler2 fix for attrasgn in masgn
-
- An attrasgn node contained within an masgn does not include
- the assigned value in the attrasgn sexp. This was leading
- to the argument count to []= to be understated by 1.
-
-commit faaa1932fe05ee4d506b768f8d9d884af5345547
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Wed Dec 12 19:59:11 2007 -0600
-
- fix non-determinism from Thread.sleep by removing blocking sleep
- add check for duration of 0 or 0.0 to instant return and added more specs
-
-commit e98b2d1f9788c1813bef2d920779c95effbd3d9f
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Tue Dec 11 17:27:43 2007 -0600
-
- spec and fix to allow floating point timeouts to Thread#join
-
-commit 801cb5ef58a6debfd348a33f864737cbce7c3d77
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Tue Dec 11 17:26:58 2007 -0600
-
- added noncompliant spec showing that sleep(nil) is allowed in rubinius
-
-commit 84d280810c840d6699b5c9ad094964fe779235df
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Tue Dec 11 16:30:41 2007 -0600
-
- fixed Thread#sleep to allows floats, and switched Thread::sleep, Kernel::sleep to use Thread#sleep on current thread
-
-commit 3d10a8a10741786ba76a4cc1083934f908d52ec2
-Author: Kevin Clark <kevin.clark@gmail.com>
-Date: Mon Dec 10 17:13:34 2007 -0800
-
- Allow Thread.new to take arguments
-
-commit 4f5258b938a7aacf31e73b5fe6312e3c927d9cf8
-Author: Kevin Clark <kevin.clark@gmail.com>
-Date: Mon Dec 10 00:21:20 2007 -0800
-
- Fix rb_define_alloc_func
-
-commit 7ab0f524de5a6b796ec1000402392cb138150eed
-Author: Kevin Clark <kevin.clark@gmail.com>
-Date: Fri Dec 7 15:06:45 2007 -0800
-
- Initial ThreadGroup implementation
-
-commit 53fff95e300b1b26ed16f12c13684eadf8235d7a
-Author: Kevin Clark <kevin.clark@gmail.com>
-Date: Fri Dec 7 01:30:55 2007 -0800
-
- Add rb_str_substr
-
-commit ec82de9f67e271718b874c0d777765da696bef88
-Author: Kevin Clark <kevin.clark@gmail.com>
-Date: Sat Dec 8 15:26:17 2007 -0800
-
- Add wrapped struct spec
-
-commit 65998d601aae601b3b43878f534362136a01ff17
-Author: Brian Takita & Nathan Sobo <brian.takita@gmail.com>
-Date: Fri Dec 7 17:18:24 2007 -0800
-
- Added specs for Module#undef_method.
-
-commit 97f8c9c32b9400ae42d0dc80aa7e17b22864fce9
-Author: Brian Takita & Nathan Sobo <brian.takita@gmail.com>
-Date: Fri Dec 7 16:13:02 2007 -0800
-
- Moved Object#to_a to Kernel#to_a. Added VM.coerce_to_array.
-
- VM.coerce_to_array will be used for splatting any object.
-
-commit 865ce7d771a101bc8c2c9ae3a82cbc3f37450c4b
-Author: Brian Takita <brian.takita@gmail.com>
-Date: Fri Dec 7 12:47:08 2007 -0800
-
- Merge branch 'array'; commit 'nathan/array' into array
-
-commit b4541a90f84c898e3cd9851ac4b207d559078a59
-Author: Nathan Sobo <nathansobo@gmail.com>
-Date: Thu Dec 6 23:33:10 2007 -0800
-
- Updated language/array_spec.rb for more detail on splat operator.
-
-commit 577b2f1c395dc49165842c405fb47bbb7591158a
-Author: Nathan Sobo <nathansobo@gmail.com>
-Date: Thu Dec 6 18:30:16 2007 -0800
-
- Fixed :many_if for compiler 1.
-
- Before it was translating many_ifs to a flat array of if statements instead
- of nesting them. Also, multiple boolean expressions in the case were not
- expanded to a boolean disjunction.
-
- Signed-off-by: Brian Ford <brixen@gmail.com>
-
-commit 1d555fa07aaed8e59e728cb0013daa10b3b17b25
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Thu Dec 6 21:24:44 2007 -0500
-
- Add some JRuby-inspired eval specs
-
-commit 3131fb81eef380d163d028f5587475bbf170befb
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Thu Dec 6 12:19:49 2007 -0800
-
- Fix minor constant lookup issue and add timing to mspec
-
-commit 26897cd85c693cac10229d7467436717552088c0
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Thu Dec 6 11:42:36 2007 -0800
-
- Fix another constant lookup bug
-
-commit 06a3f07999aeb4f7379ea40205451d326d1ba596
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Thu Dec 6 16:37:15 2007 +0100
-
- Updated CI excludes for IO#each and IO#each_line.
-
-commit b495ab1019e9ee136e9d099faa51cba03c48e947
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Thu Dec 6 16:01:31 2007 +0100
-
- Extended argument checking in IO.read.
-
- We're now checking that offset isn't negative either. This is done
- before the length argument is checked, mirroring MRI's behaviour.
- Also fixed a typo in the length check.
-
-commit 4fa2fbb6b6c27ced5d6cf902e63e3989c2d29b64
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Thu Dec 6 14:56:41 2007 +0100
-
- File.truncate raises Errno::ENOENT if the given file doesn't exist.
-
-commit cb7a0a7315e57f1adff0976bcd6b0c4a1a94d8c5
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Thu Dec 6 14:15:55 2007 +0100
-
- Added support for the length and offset arguments to IO.read.
-
-commit 9fe8f2bd73e28d28b7a9249e629ab7681321e4d5
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Thu Dec 6 14:07:21 2007 +0100
-
- IO.read only accepts file names and uses File to open and read them.
-
-commit 7ab1d9f3434e3f3b021de2f4087f2502e229c7a0
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Thu Dec 6 14:00:19 2007 +0100
-
- IO.new(nil) raises TypeError now.
-
-commit 227f6b4bf45b55eb659d41507d38fe5071ef7424
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Thu Dec 6 13:24:31 2007 +0100
-
- Fixed a typo in File.writable?.
-
-commit 645f30882c9dd39d13f49e45f2f32c43ebe25182
-Author: Kevin Clark <kevin.clark@gmail.com>
-Date: Thu Dec 6 03:51:11 2007 -0800
-
- Update Dir excludes
-
-commit e60ee517013d44c2ec6faf147f7dbd685fa520c2
-Author: Kevin Clark <kevin.clark@gmail.com>
-Date: Thu Dec 6 00:40:17 2007 -0800
-
- Fix flag checking in Dir.glob
-
- Also clean ".", ".." skipping
-
-commit fa681ad7a3c1d0e1b4fb0702c2fc63cd80ec9377
-Author: Kevin Clark <kevin.clark@gmail.com>
-Date: Wed Dec 5 18:08:41 2007 -0800
-
- File.fnmatch? should accept escaped wildcards
-
- Also fixes more Dir.glob specs
-
-commit e6b8ce23729606bf6fa748ea63c0e0a59b48a476
-Author: Kevin Clark <kevin.clark@gmail.com>
-Date: Wed Dec 5 15:35:32 2007 -0800
-
- Don't unescape leading period in File.fnmatch?
-
-commit 1cf054a08b0aeea7c348ff26c71ccaf22c02ce70
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Thu Dec 6 02:36:54 2007 -0500
-
- Rename Array#pretty_inspect to avoid conflict with pp
- Hardcore bikeshed action on the way TestGenerators are inspected
- Change describe.rb to call the renamed pretty_inspect
-
-commit 519d1226027623274766641a256e2a9753257266
-Author: Nitay <nitay@powerset.com>
-Date: Wed Dec 5 16:07:25 2007 -0800
-
- Fix Constant = Class.new setting of name
-
- Signed-off-by: Kevin Clark <kevin.clark@gmail.com>
-
-commit 568c57ca57d4a9183e492024e17aa1352902d1d2
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Wed Dec 5 20:31:43 2007 -0500
-
- Clean up mspec output to prepare for unit_diff support
- Use pretty_inspect to display compiler2 TestGenerator output
-
-commit e250521194380f4c942fd6d53664b746ca63e3e3
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Wed Dec 5 17:27:27 2007 -0800
-
- Fix constants spec to scope the fixtures
-
-commit 7010073617a4fa95ea5491284fef97a083d9d4f3
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Wed Dec 5 14:42:27 2007 -0800
-
- Vastly simplify and fix constant lookup
-
- * New constant lookup specs to test behavior
- * Added StaticScope object and field on CompiledMethod which stores
- a StaticScope instance which indicates the lexical scope of the CM.
-
-commit 163e56646a817301201af843b45c973da058688c
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Wed Dec 5 23:00:16 2007 +0100
-
- The spec for Dir#rewind doesn't pass on Rubinius.
-
- It's not platform specific, but we don't have a working Dir#pos yet
- and the Dir#rewind spec relies on it.
-
-commit 3afe61bd78aa9e850f081b83ca2c478ae297bda1
-Author: Brian Ford <brixen@gmail.com>
-Date: Wed Dec 5 13:51:05 2007 -0800
-
- Changed mini_rspec to show failures unless being run by autotest.
-
- Added dir_entry.rb to .gitignore.
-
-commit 0c661894b54615ee4915d61569e072ffdfa8826d
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Wed Dec 5 09:17:24 2007 -0500
-
- Much-improved tiny option parser lib/options.rb.
-
- * The Options API is much more user-friendly now,
- size is still about 100 LoC
- * Specs for the API.
-
-commit 092e0081c26eeda2ca6561eb19123b468965c84a
-Author: Ryan Davis <ryand-ruby@zenspider.com>
-Date: Wed Dec 5 01:40:31 2007 -0800
-
- Added support for autotest.
- Requires a new release of ZenTest to actually work.
- I'm tired, I'll do that tomorrow
-
-commit 9e3e41d71d1bab8104ae17ff34aaa2311be3b0b1
-Author: Eric Hodel <drbrain@segment7.net>
-Date: Tue Dec 4 22:59:49 2007 -0800
-
- Commit miss for require specs
-
-commit d1a6f0805b739930e54406188e32ac1e0f30a74b
-Author: Eric Hodel <drbrain@segment7.net>
-Date: Tue Dec 4 22:24:49 2007 -0800
-
- Add specs for Kernel#require, never add .rbc files to $LOADED_FEATURES
-
-commit a60e3bf901b62fbbbef59acb2c6c9f164be1fbbc
-Author: Adam Gardiner <adam.b.gardiner@gmail.com>
-Date: Wed Dec 5 14:10:15 2007 +1100
-
- Cleanup case spec, update excludes
-
- * converted case specs to not use should
- * separated out case specs with target expressions from those without
- * updated excludes for two failing specs under compiler1
-
-commit f0de77911ff0b4532a47fb9803685e8d968d51ec
-Author: Adam Gardiner <adam.b.gardiner@gmail.com>
-Date: Tue Dec 4 09:42:49 2007 +1100
-
- Fixes for compiler2 when_spec failures
-
- * Added compiler2 spec for when without an arg
- * Added spec for when without arg with an else to
- spec/language/case_spec.rb
- * Implemented many_if sexp compilation
-
-commit c9c67738ecae341441098993923838a15b64d166
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Tue Dec 4 20:42:27 2007 +0100
-
- Test Etc.getgrnam() with "daemon" instead of "root".
-
- The "root" group seems to be a Linux-ism.
-
-commit 1fd6d97e8eb20ce9908cc0abd09b7c5555ff5720
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Tue Dec 4 19:31:24 2007 +0100
-
- Post-move fix for the Options spec.
-
-commit ead52428d99549b6b53b8897d969e80072395ef6
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Tue Dec 4 19:12:28 2007 +0100
-
- Moved codearchive.rb, options.rb and readline.rb from kernel/core to lib.
-
-commit 0e4568bcc23011957cc250de2a93031648281b21
-Merge: 78fba04... fbc5ad5...
-Author: Charles Nutter <headius@wlan100.headius.com>
-Date: Tue Dec 4 00:50:46 2007 -0600
-
- Merge branch 'master' of git@git.rubini.us:code
-
-commit 78fba04c31e9d97c32862e9e104e3917dcff9137
-Author: Charles Nutter <headius@wlan100.headius.com>
-Date: Tue Dec 4 00:39:05 2007 -0600
-
- Making socket spec more reliable by using nonblocking accept for TCPServer and adding a "ready" flag for UDPServer.
-
-commit 7e925ea53239207f5dd9ac5daddda8e0f1f3b687
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Sun Dec 2 23:33:29 2007 +0100
-
- Implemented Etc.
-
-commit 450778cf5f416f6b9531664d4fff2c159c93cbe7
-Author: Victor Hugo Borja <vic.borja@gmail.com>
-Date: Sun Dec 2 01:39:28 2007 -0600
-
- Shared spec for class_eval.
-
- - removed method-arguments from describe string
- This was causing bin/completeness to report 0 examples for Module#class_eval/module_eval
- - examples checking for TypeErrors test the exception is raised, but don't check
- the exact message as it is not part of the interface.
-
-commit cd0d11c7eb23d881f1dd73701bd3edc12c5bd744
-Author: Brian Ford <brixen@gmail.com>
-Date: Sat Dec 1 15:28:41 2007 -0800
-
- Updated CI excludes for Dir.[].
-
-commit e41e501bcf686937fbd3b8cfc86f325d7e06184d
-Author: Brian Ford <brixen@gmail.com>
-Date: Sat Dec 1 10:54:35 2007 -0800
-
- CI spec excludes updates.
-
- * Fixed rake pristine task to whitelist Kernel#require fixtures.
- * Updated CI excludes for Dir.glob and Dir.[].
-
-commit 8f362a0350238366565a373f1feb9594efe03407
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Sat Dec 1 18:50:55 2007 +0100
-
- Make sure we delete the directories we're creating in the mock dir.
-
-commit dfc1b1cd32f47b48dd358ca50226d614425ef8b2
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Sat Dec 1 18:08:27 2007 +0100
-
- Dir.chdir now always resets the working directory when called with a block.
-
-commit 02f41a92bbafd1a555344e1082970e090cd1f9a5
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Fri Nov 30 23:41:29 2007 +0100
-
- Call StringValue on require's and load's argument.
-
-commit 601fd404ba04f383ee286be015edb7e8c58574d5
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Fri Nov 30 14:27:44 2007 -0800
-
- Refactor Kernel#require
-
- * Refactor a bunch of Kernel#require into Compile#require_feature
- * VM.load_library now detects if the extension is already there
- and doesn't readd it
- * Added specs for #require
-
-commit 9b903cb7c5c6a3bfbaa3a7a91dc7bad830af7294
-Author: Adam Gardiner <adam.b.gardiner@gmail.com>
-Date: Fri Nov 30 10:56:02 2007 +1100
-
- Compiler2 fix for anonymous masgn, e.g. * = 1,2
-
-commit 08bc0a2f14494a30d5956d5bdcca9eb37c921780
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Fri Nov 30 00:16:07 2007 +0100
-
- Made check_argcount work with methods that don't take any arguments.
-
-commit 96108240fead7d764f3ec37d5eb20294f3a9dd97
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Thu Nov 29 21:45:32 2007 +0100
-
- Updated the CI excludes for Method#call.
-
-commit 61805ab7fac6ae9855baa05b42aebe66c3a2b3d3
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Thu Nov 29 21:44:49 2007 +0100
-
- Made Method#[] an alias for Method#call.
-
-commit 219d34dedf6ff0ed083cb5f1e8b6a5c437ad366c
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Thu Nov 29 21:22:05 2007 +0100
-
- Enabled the Kernel#method_missing specs.
-
- They pass now that they specs aren't confused by the Dir spec helper
- methods anymore.
-
-commit de5320efe8095e612e235bea7053084bb61d300d
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Thu Nov 29 21:17:58 2007 +0100
-
- Moved the Dir spec helper methods in their own module.
-
-commit 1ae47b5c091c209597bec7475935bbcff34b50b5
-Author: Brian Ford <brixen@gmail.com>
-Date: Wed Nov 28 23:45:09 2007 -0800
-
- Applied patch from #151.
-
-commit adb5b139afa452869464fe53b710d7cb8b93131b
-Author: Brian Ford <brixen@gmail.com>
-Date: Wed Nov 28 20:29:38 2007 -0800
-
- Better fix for guards to distinguish ruby, ruby1.x from ruby1.9.
-
-commit e53f72172e395c7766dcecadd2ffd6c7caf303e7
-Author: Brian Ford <brixen@gmail.com>
-Date: Wed Nov 28 20:15:27 2007 -0800
-
- Patches (or modified patches) from #157-162.
-
-commit b07eeee79ea5a0c0160c34aec2d690f1b46f7380
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Wed Nov 28 14:43:41 2007 +0100
-
- Fixed Bignum#modulo and Bignum#remainder.
-
-commit 85b05b5103aaeb5d946e0f691f77af2dafa6f30a
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Wed Nov 28 01:00:07 2007 +0100
-
- Unified the File.unlink and File.delete specs.
-
-commit 2ec59a82f279a4ba6b5b781c90a7714aba767ed9
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Tue Nov 27 23:30:43 2007 +0100
-
- Be more specific wrt the expected exception.
-
-commit 54236949e9b974d4c4dcf95b63318c844c62aca4
-Author: Victor Hugo Borja <vic.borja@gmail.com>
-Date: Tue Nov 27 19:58:50 2007 -0600
-
- Module#<=> is working, Updated CI excludes for Module specs.
-
-commit 55c7529f4c8b02eff7e0b594f33b28750877fca2
-Author: Victor Hugo Borja <vic.borja@gmail.com>
-Date: Tue Nov 27 14:53:02 2007 -0600
-
- Specs for Module#private/public/protected
-
-commit 5b693fae3464abb6a5aa05d8236bd8f4610c89d4
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Tue Nov 27 19:36:06 2007 +0100
-
- We cannot use File.exists? to check whether a symlink exists.
-
- Use File.symlink? instead.
-
-commit e7eb6a8e1e1310c08220db0ed7979ec4c721fccb
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Tue Nov 27 19:34:48 2007 +0100
-
- Moved the after(:each) block before the specs, so the block is actually run.
-
-commit 4c284abb32029029ab7002147ef544493c7070f6
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Tue Nov 27 19:00:30 2007 +0100
-
- Added a missing Errno.handle to File.readlink.
-
-commit f163ca7c5e4a03d698a881853d1e0fab8a5be1a4
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Tue Nov 27 18:42:08 2007 +0100
-
- readlink() only works with symbolic links.
-
- This makes the spec pass on MRI.
-
-commit ca1cb21b5f694b3850a838f88d3ac5ded7de3e1f
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Tue Nov 27 18:40:43 2007 +0100
-
- Naming convention fixes.
-
-commit cbf351cb59152a5528f6c6105cee96c67f7f6fcd
-Merge: f70d531... 5452983...
-Author: Marcus Crafter <crafterm@redartisan.com>
-Date: Mon Nov 26 19:48:21 2007 +1100
-
- Merge branch 'master' of git@git.rubini.us:code
-
-commit f70d5314fcc75ef2e32fbd484de58bd5f7ed6cbc
-Author: Marcus Crafter <crafterm@redartisan.com>
-Date: Sat Nov 24 17:29:29 2007 +1100
-
- Implemented File::symlink and spec.
-
- Kudos to the Melbourne Railscamp :)
-
-commit c4a6a804185c18a182206afc1b8d5209d208077e
-Author: Marcus Crafter <crafterm@redartisan.com>
-Date: Sat Nov 24 01:08:41 2007 +1100
-
- Removed trailing whitespace.
-
-commit 9b9820e512f56b2c23c760887251d72c187aa297
-Author: Marcus Crafter <crafterm@redartisan.com>
-Date: Sat Nov 24 00:50:11 2007 +1100
-
- "Added File::readlink spec"
-
-commit 2dd272afe315dae0ad0b9bd49b6dfa9e98e50b1c
-Author: Adam Gardiner <adam.b.gardiner@gmail.com>
-Date: Fri Nov 23 17:11:54 2007 +1100
-
- Spec-ed implementation differences on masgn RHS eval order
-
- Rubinius is (for now) deliberately non-compliant wrt eval
- order of RHS expressions in an masgn.
- * MRI, JRuby eval left-to-right
- * Rubinius evals right-to-left
-
-commit 361a1adcee182cf069352effd0949064b621bddc
-Author: Adam Gardiner <adam.b.gardiner@gmail.com>
-Date: Fri Nov 23 16:16:08 2007 +1100
-
- Additional parallel assignment specs - use of to_ary
-
- * Added spec for when to_ary should be called on the RHS of an masgn
- * Added additional example of a complex masgn (from JRuby tests)
-
-commit 97cb3f5758f102cf8a07262c4c9bef4b22ca88b7
-Author: Victor Hugo Borja <vic.borja@gmail.com>
-Date: Thu Nov 22 22:04:51 2007 -0600
-
- Added specs for metaclasses of true/false/nil on metaclass_spec as suggested by rue.
-
-commit d4f9eb7cd5fb17e3e8ce52db39e95a96362d3ad0
-Author: Brian Ford <brixen@gmail.com>
-Date: Thu Nov 22 13:05:10 2007 -0800
-
- Fixed wording of Rubinius extension Bignum domain specs.
-
-commit 50e1f80ef54d25aaa69d52a3d422547593836ac6
-Author: Jeremy Durham <jeremydurham@gmail.com>
-Date: Thu Nov 22 17:18:54 2007 -0500
-
- Added excludes for Kernel#open and Thread#abort_on_exception
-
- * Excludes Kernel#open raise specs
- * Excludes Thread#abort_on_exception specs
-
-commit 25607d4d884b4597bc69560e9390cd9dc1f4e44d
-Author: Victor Hugo Borja <vic.borja@gmail.com>
-Date: Thu Nov 22 13:47:50 2007 -0600
-
- Specs for Module#alias_method
-
-commit c207618ad4113501aa5df4adb5d5aa3a60f5b9ff
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Thu Nov 22 10:59:34 2007 -0800
-
- Use RUBY_ENGINE first, then pull in rbconfig
-
-commit ed5a46e13b35d6ad48cce1d3eed96c2f78ace049
-Author: Jeremy Durham <jeremydurham@gmail.com>
-Date: Thu Nov 22 11:42:36 2007 -0500
-
- Added basic specs for abort_on_exception
-
- * Added specs for Thread#abort_on_exception ($DEBUG on and off)
- * Added specs for Thread#abort_on_exception=
-
-commit 05ecef9162ba2c4a0da90c966a20a4f45c353d93
-Author: Jeremy Durham <jeremydurham@gmail.com>
-Date: Thu Nov 22 08:39:53 2007 -0500
-
- Added specs for when parameters are missing or invalid parameters are given
-
-commit 25d2c940d561dcac2c06df747762a229dddfbed1
-Author: Adam Gardiner <adam.b.gardiner@gmail.com>
-Date: Thu Nov 22 15:33:17 2007 +1100
-
- Another parallel assignment spec - rhs should evaluate l->r
-
-commit 8e4f8de446b842c13ad45a8e0e2c3c1ebf30bddb
-Author: Brian Ford <brixen@gmail.com>
-Date: Wed Nov 21 17:42:17 2007 -0800
-
- Stop-gap prevention for Kernel#callcc hanging CI specs.
-
-commit a9d7163e4d9e8d4fb79c9769691b232676a44bd8
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Wed Nov 21 15:50:39 2007 -0600
-
- remove compliant(MRI) from callcc specs
-
-commit 812e922c8e7cda728d6b7f32933b75eb009eef11
-Merge: 2e221b9... f24bb1f...
-Author: Nathan Witmer <nwitmer@gmail.com>
-Date: Wed Nov 21 12:32:18 2007 -0700
-
- Merge branch 'callcc_spec'
-
-commit f24bb1ffdf941df78098da262a62e881653b1a99
-Author: Nathan Witmer <nwitmer@gmail.com>
-Date: Wed Nov 21 12:31:28 2007 -0700
-
- Added scope-related callcc specs, compliant(:ruby) only.
-
-commit 2e221b9f1d7ffa41431e5bd51fdd36434e7f838f
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Wed Nov 21 14:41:43 2007 +0100
-
- Spec and fix some more String#slice bugs when given nil, also use Undefined.
-
-commit db338d9d8705fd668a5639d483ff47908aa014ca
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Tue Nov 6 16:53:13 2007 +0100
-
- Fix String#rindex when given nil as offset.
-
-commit 6eab3b692a50c1a37cc39c21d743de1488402f64
-Author: Brian Ford <brixen@gmail.com>
-Date: Wed Nov 21 00:00:24 2007 -0800
-
- Added MRI stdlib Fcntl to lib/ext with build script.
-
- Added lib/fcntl to load extension. This may need a better solution.
- Added INT2FIX to subtend.
-
-commit 5268c0b29c1fb07a911fe601e30b21ffe04f7e81
-Author: Adam Gardiner <adam.b.gardiner@gmail.com>
-Date: Wed Nov 21 17:02:14 2007 +1100
-
- Additional specs for parallel assignment
-
- MRI allows parallel assignment to:
- - assign via object.method=
- - assign via []=
- - use a lhs arg as an arg to another lhs assignment
-
- All three scenarios currently fail in Rubinius, apparently due to
- miscalculating the number of args to an assignment method under
- parallel assignment.
-
-commit 462f68b95a70c24e41cad5a40969c4651c7de181
-Author: Jeremy Durham <jeremydurham@gmail.com>
-Date: Tue Nov 20 02:12:44 2007 -0500
-
- Added specs for Kernel#open when block is given
-
-commit ab9e40600fd2522d4abce86f7b8bdc632f6e9018
-Author: Jeremy Durham <jeremydurham@gmail.com>
-Date: Mon Nov 19 23:42:55 2007 -0500
-
- Added very basic specs for Kernel#open
-
-commit b47efc9f9872ecca68a06f6864f39617e06762b0
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Nov 19 00:24:15 2007 -0800
-
- Updated CI excludes. Runs clean on Leopard.
-
-commit 3ff04e52bc9cb03439567ddb9b3b63b3034b30c3
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Mon Nov 19 00:03:58 2007 -0600
-
- more specs for Kernel.callcc, ensures callcc return value semantics
-
-commit 06d5312c51b09faef87d2deb53f3c472eaa94100
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Sun Nov 18 17:49:44 2007 -0600
-
- basic callcc behavioral specs
-
-commit 53433f0e9ddba2eac876f7a1fb0f9d292ee37286
-Author: Nathan Witmer <nwitmer@gmail.com>
-Date: Fri Nov 16 16:51:18 2007 -0700
-
- Added Kernel#callcc spec and fix for LocalJumpError with no block given
-
-commit d324779b8b5c8dd84438c08ec4f2b2574282f93e
-Author: Victor Hugo Borja <vic.borja@gmail.com>
-Date: Fri Nov 16 15:17:21 2007 -0600
-
- Added Module.nesting
-
- Some specs are failing on rubinius because the parent
- field is not being properly set.
-
-commit cff726c9dc3631b2e0ddc3e12bd3af532f7e1ef4
-Author: Victor Hugo Borja <vic.borja@gmail.com>
-Date: Fri Nov 16 14:49:38 2007 -0600
-
- Added spec for calling Module.nesting on root level
-
-commit 05adb6070889d7021a1e53ab82b855c3554d4f5c
-Author: Victor Hugo Borja <vic.borja@gmail.com>
-Date: Fri Nov 16 14:45:23 2007 -0600
-
- Fixed specs for Module#constants
-
-commit 1f1c857e1d8c37213a91daaad3fc3bfcbf2bef61
-Author: Victor Hugo Borja <vic.borja@gmail.com>
-Date: Fri Nov 16 14:43:55 2007 -0600
-
- Fixed spec description for calling Module.nesting from methods.
-
-commit 242c947c6e4d007685e8aa0c44ac505c7dab4239
-Author: Victor Hugo Borja <vic.borja@gmail.com>
-Date: Fri Nov 16 14:38:32 2007 -0600
-
- More specs for Module.nesting
-
-commit 3560fd7ef0d5a65a9cb055d87fa7103ed3bdb029
-Author: Victor Hugo Borja <vic.borja@gmail.com>
-Date: Fri Nov 16 10:24:45 2007 -0600
-
- private keyword specs reflecting problem described on ticket #133
-
-commit fd31e1e592237832bd5e605f604d15385df0615a
-Author: Victor Hugo Borja <vic.borja@gmail.com>
-Date: Fri Nov 16 04:15:27 2007 -0600
-
- specs for Kernel#block_given? by Francisco Laguna
-
-commit 87ebce4cf2430198578decdb4c7dc1003db37f8e
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Thu Nov 15 22:07:39 2007 -0800
-
- Ticket #121 by Jeremy Durham -- File modes
-
-commit 4a67e0ade233aaaa3a2ff17161b298872f8a5f83
-Author: Victor Hugo Borja <vic.borja@gmail.com>
-Date: Thu Nov 15 14:20:19 2007 -0600
-
- Splitted enumerable_spec.rb into a file per method.
-
- Added some specs by Francisco Laguna.
-
-commit 0b933650330f57e7db1bf8574d0b7eecf0635996
-Author: Bryan Helmkamp <bryan@brynary.com>
-Date: Tue Nov 13 11:34:20 2007 -0500
-
- Added specs for File.mtime.
-
-commit 42a7de27c1a6082fee7b9baaf05b9394ffe90ddd
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Mon Nov 12 19:57:38 2007 +0100
-
- Updated CI excludes for File#atime and File.new.
-
-commit 3d106d6a9b8ce0b34e7b6f9426da51b83fe5f676
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Mon Nov 12 19:54:43 2007 +0100
-
- Added File#path.
-
-commit 247da25a0120d468fe9f189a6235962f9658b65e
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Mon Nov 12 19:23:09 2007 +0100
-
- File now deals with numeric modes and accepts a permission argument, too.
-
-commit 087deaed0dcf4ae2c8dc713eeccfed9a0ebabe6f
-Merge: 4355e96... 1c9d213...
-Author: Kevin Clark <kevin.clark@gmail.com>
-Date: Sun Nov 11 23:15:01 2007 -0800
-
- Merge branch 'master' of git@git.rubini.us:code
-
-commit 4355e96b05de4d4d086dfa86b8fe19bdcecfbe82
-Author: Kevin Clark <kevin.clark@gmail.com>
-Date: Sun Nov 11 23:14:16 2007 -0800
-
- -a
-
-commit 7e975d1aca38a3bfe07fda431aeaba376bce19c1
-Author: Kevin Clark <kevin.clark@gmail.com>
-Date: Sun Nov 11 23:09:47 2007 -0800
-
- Get rid of irrelevant specs
-
-commit 1c9d2133fc294964ce08e9a7020083c379f74ca0
-Author: David Waite <david@alkaline-solutions.com>
-Date: Sun Nov 11 23:46:08 2007 -0700
-
- Remove temp directories within mkdir spec on exception.
-
-commit 2110fc75dc6a7ab521249f259bc6fdc78d565b11
-Author: Kevin Clark <kevin.clark@gmail.com>
-Date: Sun Nov 11 22:36:08 2007 -0800
-
- Update CI Excludes
-
- * Expected failure of "raise an Exception if it has
- the wrong number of argments" due to dispatcher bug
-
-commit 0f2a183a46ba085d9c99ed4767cd18c0482e6d45
-Author: Kevin Clark <kevin.clark@gmail.com>
-Date: Sun Nov 11 22:14:07 2007 -0800
-
- Implement File#atime
-
-commit 671b340f340ab6b8d9c13b27d52a782ce3268b2a
-Author: Kevin Clark <kevin.clark@gmail.com>
-Date: Sun Nov 11 21:24:34 2007 -0800
-
- Update CI excludes
-
-commit f7ba96f6b41de9a3696a03e9efe25c8b037a4f07
-Author: Kevin Clark <kevin.clark@gmail.com>
-Date: Sat Nov 10 11:24:12 2007 -0800
-
- Adds spec for File.open
-
- * In resonse to Lighthouse Ticket #102
- "File.open should throw Errno::EACCES opening non-permitted file"
- * Passes MRI, doesn't yet pass RBX
-
-commit 719329b3f5179766e23a27e427cd0c0846c85ffa
-Author: Marcus Crafter <crafterm@redartisan.com>
-Date: Mon Nov 12 10:38:42 2007 +1100
-
- Added IO#to_i implementation and spec.
-
-commit cc100fc08be101ecdf0daba1966977fb8e39fa6e
-Author: Marcus Crafter <crafterm@redartisan.com>
-Date: Mon Nov 12 10:30:25 2007 +1100
-
- Added IO#fileno implementation and spec.
-
-commit d036f5c16a4836d638be83108be35df532d9221a
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Sun Nov 11 23:17:12 2007 +0100
-
- Made SystemStackError subclass of StandardError.
-
-commit bf1c3dc3e463aeaf4e0cee1cbd46b15e7693a395
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Sun Nov 11 20:36:25 2007 +0100
-
- Removed an old Method#arity spec exclude.
-
-commit 72c3495f3513e54c2488292bcdaca9208b6f0339
-Author: Brian Ford <brixen@gmail.com>
-Date: Sun Nov 11 10:44:53 2007 -0800
-
- Removed transient dirs from Dir specs.
-
-commit 11f0ed51b4bfb3bea2b544a82b3158fd3daf2ad8
-Author: Victor Hugo Borja <vic.borja@gmail.com>
-Date: Fri Nov 2 03:02:28 2007 -0600
-
- Specs for Module#remove_const
-
- Signed-off-by: Brian Ford <brixen@gmail.com>
-
-commit e8158f14f0f02e3b0cdcb4182e1277928324cc0c
-Author: Nathan Witmer <nwitmer@gmail.com>
-Date: Sun Nov 11 08:19:10 2007 -0700
-
- Fixes for UDPSocket spec
-
- * Renamed the description to match what was actually being tested
- * Uncommented the code and wrapped it in an "it" block, to prevent
- conflicts/hangs with bin/completeness runs.
-
- Signed-off-by: Brian Ford <brixen@gmail.com>
-
-commit 9b973a98d2ebddacd50f0fcb58903bb53bdff3f5
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Sun Nov 11 13:30:22 2007 +0100
-
- Ticket #98: Dir includes Enumerable now.
-
-commit 8d957f186cd4d2c5e6b236de4a0878d38b464848
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Sun Nov 11 13:26:00 2007 +0100
-
- Implemented Module#included_modules.
-
-commit 0021b24ba490fe01f96ef17957328feeedfc4c29
-Author: Nathan Witmer <nwitmer@gmail.com>
-Date: Thu Nov 8 21:42:41 2007 -0700
-
- Commented out code in UDPSocket spec so bin/completeness doesn't hang
-
- Signed-off-by: Brian Ford <brixen@gmail.com>
-
-commit 56687aed201fb864587807cca893268a9f1e2050
-Author: Brian Ford <brixen@gmail.com>
-Date: Sun Nov 11 00:10:14 2007 -0800
-
- Method fixture for yield specs.
-
-commit 421aa58f9135807487864adcdcac79f7b6da33c1
-Author: Brian Ford <brixen@gmail.com>
-Date: Sun Nov 11 00:08:35 2007 -0800
-
- Specs for yield keyword based on patch in #114.
-
-commit 5ba0b2030c55474f9d8a096d309678ca24a4699b
-Author: Jeremy Durham <jeremydurham@gmail.com>
-Date: Sun Nov 11 01:35:08 2007 +0100
-
- Ticket #105: Implemented Bignum#eql?.
-
-commit 47356fe39033f8571559a4fef933681fda871efd
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Sun Nov 11 01:14:26 2007 +0100
-
- Made specs for Kernel#respond_to? and Kernel#method pass.
-
- KernelSpecs::Foo#baz is defined in another spec, so these two specs
- may not rely on #baz being undefined. This is a horrible workaround
- for the problem that multiple specs make use of the same module and modify
- it freely.
-
-commit 68b4fc7c0192f537fe9727927ac35c440dbdc03a
-Author: Akshay Rawat <akshay.rawat@gmail.com>
-Date: Thu Nov 8 18:21:03 2007 +0530
-
- Updated CI excludes.
-
-commit a1eee3814a5d054cd00e26b40c063d41880bf6c7
-Author: Chris Pettitt <cpettitt@gmail.com>
-Date: Sat Nov 10 14:10:47 2007 -0800
-
- Refactor IO.gets spec to have less duplication.
-
-commit 56497d27bdb3a82d549f89b9fc9fcf0709f99b3e
-Author: Chris Pettitt <cpettitt@gmail.com>
-Date: Sat Nov 10 14:07:21 2007 -0800
-
- New spec: IO.gets('') should advance the file position to the next non $/ character.
-
-commit 95158f5a4141d5d3e2893304e49bfeb62cc7b226
-Author: Brian Ford <brixen@gmail.com>
-Date: Sat Nov 10 13:35:03 2007 -0800
-
- Added rescue to prevent meltdown until rbx begin/rescue/ensure is fixed.
-
-commit a39155cb029ca3c1e5e5d69e0e269c685c040f6e
-Author: Chen Yufei <cyfdecyf@gmail.com>
-Date: Sat Nov 10 12:24:38 2007 +0000
-
- Fixed IO#gets when separator is empty.
-
-commit f9c31ce1d2a68c15def98aad6c6ff35eb56cd523
-Author: Kevin Clark <kevin.clark@gmail.com>
-Date: Fri Nov 9 20:24:40 2007 -0800
-
- Clean up Enumerable#include? specs
-
-commit f017fad69be5d4034a4c5437acf77ec4749b0d75
-Author: Kevin Clark <kevin.clark@gmail.com>
-Date: Sun Nov 4 20:54:06 2007 -0500
-
- Clean up Enumerable#(collect, entries, find, find_all) specs
-
-commit 81550f082396b4455c3681ae966be1371be0a5db
-Author: Kevin Clark <kevin.clark@gmail.com>
-Date: Sun Nov 4 13:18:52 2007 -0500
-
- Update excludes
-
-commit d5fd2ee893ea608c7e19cb674a4da7b9f49542e6
-Author: Kevin Clark <kevin.clark@gmail.com>
-Date: Sun Nov 4 12:16:58 2007 -0500
-
- Cleanup/rewrite Enumerable#find tests for sanity and clarity
-
-commit 39f21aa76f6ddc45be79e4e4e978b4c1c2beed71
-Merge: 17d2e4c... c1b9f74...
-Author: Kevin Clark <kevin.clark@gmail.com>
-Date: Fri Nov 9 20:25:13 2007 -0800
-
- Merge branch 'master' of http://git.rubini.us/code
-
-commit c1b9f74f88be963e72de763da9130f46869d89fb
-Author: Chris Pettitt <cpettitt@gmail.com>
-Date: Fri Nov 9 12:36:04 2007 -0800
-
- Fix some failing specs for IO#each and IO#each_line.
-
- Also refactor some common code into a helper method.
-
-commit 74af37b849507e504503359a08245effaad7634a
-Author: Chris Pettitt <cpettitt@gmail.com>
-Date: Fri Nov 9 10:58:33 2007 -0800
-
- New specs for IO#each and IO#each_line
-
- This change adds some new specs for IO#each and IO#each_line factored into
- a shared .rb, because one is the alias of the other. Added failing specs to
- excludes.
-
-commit d162a396b566846445328d6c42d3d5f10fcf7ee6
-Author: Matt Pelletier <matt@eastmedia.com>
-Date: Fri Nov 9 02:32:25 2007 -0500
-
- Add and refactor patches from Andrea OK regarding #send
-
-commit 63f0ed010e65549597f6bddb0686ba04157ca478
-Author: Brian Ford <brixen@gmail.com>
-Date: Wed Nov 7 09:52:25 2007 -0800
-
- Fixed Method#call spec failing from renamed fixture method name.
-
-commit 1ef46468d7808c52b07388130069cb2e7854bff8
-Author: Matt Pelletier <matt@eastmedia.com>
-Date: Wed Nov 7 04:48:39 2007 -0500
-
- * Update CompiledMethod#arity to be accurate for cases of required and/or optional arguments, with or without blocks
- * CompiledMethod#arity is still inaccurate when splat argument is present (the presence of splat overrides #required)
- * Add specs for more thorough coverage of various argument use cases
- * Includes known Rubinius-failing specs for splat-related arity
-
-commit b7726f26dae95936aa1c3fdf2c52dd18ef7413cf
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Nov 5 17:48:51 2007 -0800
-
- Updated CI excludes for fixes to public|private_class_method.
-
-commit eb18f898e3ae8e5a1bf3b01291a12516c6a22301
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Nov 5 17:18:22 2007 -0800
-
- Added Module#protected_method_defined?. Updated CI excludes.
-
-commit aa8904cdbd8b4851be4f05cec3000b04cfc9f6c1
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Nov 5 17:14:12 2007 -0800
-
- Added Module#private_method_defined?.
-
- Fixed specs for Module#public_method_defined? and
- private_method_defined?. Updated CI excludes.
-
-commit 063b61759ee86f5def2422d16f1eb854c8b9eb76
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Nov 5 13:39:21 2007 -0800
-
- Updated CI excludes for StringIO.
-
-commit 3c79f871379d2d4b5431138033f723efbf4a795d
-Author: Dr Nic <drnicwilliams@gmail.com>
-Date: Sun Nov 4 16:45:30 2007 -0500
-
- Extended StringIO spec "flattens a nested array before writing it" to ensure deeper test scenario
-
- Signed-off-by: Brian Ford <brixen@gmail.com>
-
-commit 916d617a60cf83ac26c3090310236193f5842ff6
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Nov 5 13:11:54 2007 -0800
-
- Updated CI excludes for String#scan.
-
-commit fee1d904197c369c561ae3b11aaf582f1b87d1b0
-Author: Matt Pelletier <matt@eastmedia.com>
-Date: Sat Nov 3 16:06:16 2007 -0400
-
- Fix test of String#scan. Do not force matches into array using splat.
-
- Signed-off-by: Brian Ford <brixen@gmail.com>
-
-commit cc9182cfcde60a63bf566f73c6004b7e46347e77
-Author: Daniel Lucraft <dan@fluentradical.com>
-Date: Thu Nov 1 17:01:03 2007 +0000
-
- Added File.rename
-
- Signed-off-by: Brian Ford <brixen@gmail.com>
-
-commit fc2b7aa65ab338d8ff543552659046c93659c3ce
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Nov 5 12:06:13 2007 -0800
-
- Commit rework of Carl Drinkwater's patch from #72.
-
-commit 7f6564b96762d7b3deb9f021789182f5c664a766
-Author: Chris Pettitt <cpettitt@gmail.com>
-Date: Sun Nov 4 10:38:04 2007 -0800
-
- Fixes for two IO#gets spec failures.
-
- This patch fixes the following two IO#gets spec failures:
-
- IO#gets assigns the returned line to $_
- IO#gets returns the entire content if the separator is nil
-
- Signed-off-by: Brian Ford <brixen@gmail.com>
-
-commit 705e8e05496167b1af3a1e3ff3446d325ca54e07
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Nov 5 02:10:56 2007 -0800
-
- Added Module#public_method_defined?.
-
- Updated CI specs for #public_method_defined?.
- Small fix to find_method_in_hierarchy to symbolize arg.
- Updated some spec wording and removed spec'ing exception string.
-
-commit 17d2e4c6ae0c40376fe121786a362c8bc8ce951c
-Merge: 2b77ee8... c07472c...
-Author: Kevin Clark <kevin.clark@gmail.com>
-Date: Sun Nov 4 20:58:42 2007 -0500
-
- Merge branch 'master' of http://git.rubini.us/code
-
-commit bd6c27f4724bdc461a7036e6373a0ad23060020a
-Author: Trotter Cashion <cashion@gmail.com>
-Date: Sat Nov 3 15:57:21 2007 -0400
-
- Added operator precedence specs for '&&' and 'and'.
-
-commit 2b77ee8b74373a3251973d96c931422909605e29
-Merge: 30d7618... 76aa72e...
-Author: Kevin Clark <kevin.clark@gmail.com>
-Date: Sun Nov 4 13:43:23 2007 -0500
-
- Merge branch 'master' of http://git.rubini.us/code
-
-commit 2c90ce28cc73e08d9fb74b5c7e815807314ba269
-Author: Brian Ford <brixen@gmail.com>
-Date: Sun Nov 4 07:18:09 2007 -0800
-
- Updated CI excludes from 85d63b676e.
-
-commit 85d63b676e463a2bec9a322bc8eeffd2daee433b
-Author: Chen Yufei <cyfdecyf@gmail.com>
-Date: Sat Nov 3 23:39:23 2007 +0000
-
- Added specs for IO#gets
-
-commit be5b9595f2077080c0c1179ab9689352d8faea3a
-Author: Brian Ford <brixen@gmail.com>
-Date: Sun Nov 4 00:31:12 2007 -0700
-
- Updated CI excludes.
-
-commit d46ad4b63d4a5f77609b0880b7f24e8e27404805
-Author: Brian Ford <brixen@gmail.com>
-Date: Sun Nov 4 00:11:52 2007 -0700
-
- Updated CI excludes.
-
-commit 1f307223c673c6744f8b85fc3e707a3419b1a0e8
-Author: Brian Ford <brixen@gmail.com>
-Date: Sun Nov 4 00:06:48 2007 -0700
-
- Guarded #freeze specs for MRI and JRuby.
-
-commit ca50fd7d979c36f8af306e0e1474aac5408dd66d
-Author: Brian Ford <brixen@gmail.com>
-Date: Sat Nov 3 23:22:31 2007 -0700
-
- Guarded specs for #frozen? for MRI and JRuby.
-
-commit 16b36030a796b877809d5d6ea556266c4b4a6413
-Author: Brian Ford <brixen@gmail.com>
-Date: Sat Nov 3 20:53:26 2007 -0700
-
- Removed NULL characters from language/precedence.
-
- Enhanced rescue output when loading spec files.
-
-commit 10510ece16ebb5e0ba921e0be631a4740f3e4453
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Sat Nov 3 23:09:30 2007 -0400
-
- Fix a method_missing cache error.
-
-commit b313c5632b039c03a448ae3b1046701c8b3243a2
-Author: Brian Ford <brixen@gmail.com>
-Date: Sat Nov 3 14:10:29 2007 -0700
-
- Changed shared spec behavior to be compatible with RSpec.
-
-commit 7b825b89e96b3c8e38f9b8bcc8edf2bc6ec6ff22
-Author: Brian Ford <brixen@gmail.com>
-Date: Sat Nov 3 14:09:47 2007 -0700
-
- Fixed language/class specs.
-
-commit 30d76181b0b3a9c5ac99c9d0e22a6a451346eff4
-Author: Kevin Clark <kevin.clark@gmail.com>
-Date: Sat Nov 3 16:47:49 2007 -0400
-
- Fix Dir#each/Dir#entries/Dir.foreach specs. They weren't updated for fixtures
-
-commit f44a8cceb9a186a7127276db2207dfc79957ee8d
-Author: Brian Ford <brixen@gmail.com>
-Date: Sat Nov 3 13:06:35 2007 -0700
-
- Guard File.(un)link for jruby.
-
-commit 1ec2c3a99ca562c8944aac1f4a60f8e0af0aaf17
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Sat Nov 3 18:20:48 2007 +0100
-
- Properly resize the array in Array#<<.
-
-commit 8dec9918d8a6233ec2cde29d54687a5d950dc8df
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Sat Nov 3 17:13:57 2007 +0100
-
- Fixed Array#unshift for the case when @start > 0 && @start < values.size.
-
- Also extended the Array#unshift specs to cover this case.
-
-commit 50b90918cd5a9a05e475690703c7867b443d191b
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Fri Nov 2 13:47:53 2007 -0500
-
- added IO::foreach, fixed gets to use string separator, and fixed IO::readlines to use File.open
-
-commit 3efc01e110473d003ffb0a1376ec179f30e600de
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Fri Nov 2 13:30:44 2007 -0500
-
- specs for IO::foreach and specs to test IO::readlines,IO.readlines with string separator
-
-commit fad18610b4416dfcfaf35db5029e880dff7e9820
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Mon Oct 29 14:10:11 2007 -0500
-
- basic exec implementation and a single basic spec (not sure how test test exec)
-
-commit 730fc3ed9afc54612d14093148fb8583c9e39fe3
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Fri Nov 2 21:41:25 2007 +0100
-
- Return mkdir()'s return value from Dir.mkdir.
-
-commit f5766696e701a069f908b3b5d5cfbccfee15ef1f
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Fri Nov 2 20:46:11 2007 +0100
-
- Implemented Dir.foreach.
-
-commit c696f1edc50c58b87270811c0c9aa0e49b356fe7
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Fri Nov 2 20:38:36 2007 +0100
-
- Implemented Dir.entries.
-
-commit e8e6188b252172690c1b584e528e3c71035897cd
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Fri Nov 2 18:16:13 2007 +0100
-
- Raise an error if the opendir() call in Dir#initialize fails.
-
-commit 024309b560c6c69f6f331c614df1da221be7054c
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Fri Nov 2 16:15:19 2007 +0100
-
- The Array#[]= spec seems to work now, so enable it.
-
-commit 76f118e62a0784326f5edf1c0fe46f6b6e682eee
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Fri Nov 2 14:28:49 2007 +0100
-
- Made Math.ldexp only accept integers as the second argument.
-
-commit 22bd7369efd1f738835e9c0a6a4624a26dae02d1
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Fri Nov 2 13:30:50 2007 +0100
-
- Implemented some missing File::Stat methods.
-
-commit d6dc42d9085fed5f8bf482d7f84dd9c5fbd4423c
-Author: Brian Ford <brixen@gmail.com>
-Date: Thu Nov 1 12:24:53 2007 -0700
-
- Fixed specs failing MRI for File.stat and File.basename.
-
-commit 46f4de189e987f3071ede57f2bb1f7c892d67bd4
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Thu Nov 1 17:30:47 2007 +0100
-
- Fixed ticket #83: Array#push doesn't die anymore after calling Array#shift.
-
-commit 8debed24e957e48b10d60885d9a43083aab4d923
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Thu Nov 1 11:14:22 2007 +0100
-
- In the Numeric#coerce spec, coercing strings to numerics should work.
-
- We can remove the TypeError checks from this spec, since those
- are included in the specs for the Numeric operators.
-
-commit 28cf656fb25ce38453acb2efdcf2e9ac16bb4460
-Author: Brian Ford <brixen@gmail.com>
-Date: Thu Nov 1 01:33:31 2007 -0700
-
- Removed Hash#fetch definition from fetch spec.
-
- Fixed spelling of Hash#find_unambiguous.
- Updated CI excludes.
-
-commit a6a69b469d94d0912ccbf123fdb9f53cbaf32830
-Author: Akshay Rawat <akshay.rawat@gmail.com>
-Date: Tue Oct 30 21:47:51 2007 +0530
-
- In the Time#isdst spec, don't depend on the system's current time zone.
-
-commit 1be129f98e0d548a023cc32f5ab763361e2a9c6b
-Author: Daniel Lucraft <dan@fluentradical.com>
-Date: Wed Oct 31 21:05:04 2007 +0000
-
- Fixed String#split to not return non-matching captures anymore.
-
-commit 5f7f798ef26fc8ee1e83c5e392c1fb2e60e31382
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Wed Oct 31 21:54:56 2007 +0100
-
- In the Numeric#coerce spec, don't try to coerce strings to numerics.
-
-commit e26b7645af27d5bfc250c2c11f7e72349750f5c7
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Wed Oct 31 10:52:13 2007 +0100
-
- Added a failing spec for Ticket #83.
-
-commit 9144f0c55eb5f40409bec514f08f89bdba61f800
-Author: Daniel Lucraft <dan@fluentradical.com>
-Date: Wed Oct 31 13:57:54 2007 +0100
-
- Fixed math/constants_spec.rb.
-
-commit 4b521cacb667ca5245954bc03ebfec67c0ac235c
-Author: Adam Gardiner <adam.b.gardiner@gmail.com>
-Date: Wed Oct 31 23:26:45 2007 +1100
-
- Modified spec to reflect expected differences in masgn retval behavior
- between rbx (true) and MRI (array of rhs vals).
-
-commit 1f6c50f5c77566e66cb0b842733b7f4f4b24e937
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Tue Oct 30 18:13:47 2007 +0100
-
- Use a fixed timezone for the Time#strftime spec.
-
-commit 60a25e997def085f3ae29773ce70ddc5b7c38d46
-Author: Brian Ford <brixen@gmail.com>
-Date: Tue Oct 30 00:47:38 2007 -0700
-
- Fixed Kernel#raise to not output if $VERBOSE == nil.
-
- Guard Marshal.dump specs to eliminate error output until
- a proper Marshal is implemented.
-
-commit e446f2e329a6dfaacb45b5b86ba43ebd9ec606a3
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Oct 29 23:17:49 2007 -0700
-
- Added IO::SEEK_SET, SEEK_CUR, SEEK_END with FFI.
-
- Fixed IO#close to raise IOError if already closed.
-
-commit fcb1ac4d076c07065878c2e65bf7bb44ddef400c
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Oct 29 22:37:23 2007 -0700
-
- Specs for IO#seek and IO::SEEK_SET, SEEK_CUR, SEEK_END.
-
-commit a3570f6702dabd303fcd10d4cfc0e753cff69bb5
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Mon Oct 29 22:33:34 2007 +0100
-
- Make Module.new actually work.
-
-commit 9709fa96b91afe5140f76726f1f7d4b89f8a6d54
-Author: Brian Donovan <brian.donovan@gmail.com>
-Date: Mon Oct 29 11:30:32 2007 -0700
-
- Ticket #75: Fixed Enumerable#sort_by.
-
- We must not call the comparison proc when the object and pivot are
- identical.
-
-commit 52e97da6bbcd28ec4349abcf25b089648d085652
-Author: Akshay Rawat <akshay.rawat@gmail.com>
-Date: Tue Oct 30 02:18:56 2007 +0530
-
- Enabled Math specs that were fixed by Ticket #59.
-
-commit 0f98800d4ab1db526304f1d26597ca3880c811da
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Mon Oct 29 19:29:16 2007 +0100
-
- Ticket #59: Kernel#send now calls private methods, too.
-
-commit 754e48c223c3464c7d048452585c07b8d0b3d8c7
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Oct 29 00:11:41 2007 -0700
-
- Specs for IO#rewind.
-
-commit 0bfd6bcca8fb287899fadeae81dd7c00b05d07e9
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Sun Oct 28 23:40:37 2007 +0100
-
- Module#public_instance_methods now handles attribute accessor methods.
-
-commit 0a22b36b9bc50a34f1da1d0e994f1a6689195652
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Sun Oct 28 23:26:17 2007 +0100
-
- Added a failing spec for Enumerable#sort_by.
-
-commit 006534b173a186c25c228b653d5ac9d81b20f57e
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Sun Oct 28 21:51:40 2007 +0100
-
- Update Module spec excludes.
-
-commit 496df827eeeb600858fa8c7b26482aa3f653fee1
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Sun Oct 28 21:50:47 2007 +0100
-
- Make Module#ancestors specs pass.
-
-commit 18185cde2b47374c304e2528a084ea1f7b5178d2
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Sun Oct 28 19:46:22 2007 +0100
-
- Added a failing spec for building an array that includes a splatted array.
-
-commit f120a470a5e07a7e53b1e006173942d58956e86b
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Sun Oct 28 19:33:10 2007 +0100
-
- Extended Kernel#` specs.
-
-commit 7e184c5bbc7be16cc8f7be01713543f222edd267
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Sun Oct 28 19:00:52 2007 +0100
-
- Removed Exception message dependencies and extended Kernel.String specs.
-
-commit 2853dc58209b3b8d122cee66c7d83e967d0879de
-Author: Adam Gardiner <adam.b.gardiner@gmail.com>
-Date: Sun Oct 28 23:01:54 2007 +1100
-
- Fix for multi-arg operator assign through [], e.g. x[0,3] += 5
-
-commit 91b88710ddc1e8553e51c404cee4039f4d6abf24
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Sun Oct 28 13:05:08 2007 +0100
-
- Fixed File.ftype specs.
-
-commit 448fdc2def3a9ab249dadf9335568ca30b76f70e
-Author: Brian Ford <brixen@gmail.com>
-Date: Sun Oct 28 00:36:11 2007 -0700
-
- Updated compiler specs.
-
-commit 0fb510c14ee8787b5965d5665e50da92a988faa6
-Author: Brian Ford <brixen@gmail.com>
-Date: Sun Oct 28 00:32:41 2007 -0700
-
- Fixed Bignum#coerce specs.
-
-commit 5e52a259b91e81fe5497f44107dee6ffd613b3be
-Author: Brian Ford <brixen@gmail.com>
-Date: Sun Oct 28 00:22:40 2007 -0700
-
- Fixed wording on Rubinius Bignum#coerce extension specs.
-
-commit 19e0259ca51691afe341b1217ab92862b307fe17
-Author: Brian Ford <brixen@gmail.com>
-Date: Sun Oct 28 00:15:18 2007 -0700
-
- Revert "Remove invalid and failing Bignum#coerce spec."
-
- This reverts commit 2371b920ca3f956213ab9e406a3b5d2afab4f18e.
-
-commit 4986ec283ee5aa9e392065c74d64952d36554b91
-Author: Brian Ford <brixen@gmail.com>
-Date: Sat Oct 27 23:50:05 2007 -0700
-
- Updated CI excludes for Array#pack.
-
-commit 5472f30201d7cddd4465adb246fa32927fe03d91
-Author: Alan Hurdle <alan.hurdle@gmail.com>
-Date: Sat Oct 27 18:38:30 2007 +1000
-
- Bunch of fixes to Array#pack to pass the current set of pack specs
-
-commit 20210a617a3f31c5dc0eda9fa371c49200c11f67
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Sun Oct 28 02:30:02 2007 +0100
-
- Updated spec excludes for Module specs.
-
-commit 712e3cc6a5d8a69834449e1039dfae3e07fcdcc2
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Sun Oct 28 02:18:00 2007 +0100
-
- Removed the dependency on some Exception messages.
-
-commit 2371b920ca3f956213ab9e406a3b5d2afab4f18e
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Sat Oct 27 16:15:33 2007 +0200
-
- Remove invalid and failing Bignum#coerce spec.
-
-commit e1e62e7749d47c838d6b7cd1e95863c0c90d3de0
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Sat Oct 27 20:59:49 2007 +0200
-
- Fixnum#div now always rounds towards negative infinity.
-
-commit 9a4ccbe8381db5b6280c9d1dfcf6fa21a4838c4e
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Sat Oct 27 15:09:57 2007 +0200
-
- Updated Spec excludes for Bignum and Fixnum specs.
-
-commit 889c939a668b9b1a4fd8f5a0cfd8bad85c3a5977
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Sat Oct 27 14:24:27 2007 +0200
-
- Fix Integer#[] when given a Bignum.
-
-commit 45d97332f4ec5a174884024c954ceeb6eb852f5f
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Sat Oct 27 13:46:51 2007 +0200
-
- Partial fix for #68: Fix Hash#fetch to correctly handle yielding with a default value passed.
-
-commit a785ea28f39c71a98007a7fafc23985dd21b596f
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Sat Oct 27 13:39:42 2007 +0200
-
- Updated CI excludes for recent Hash fixes.
-
-commit 6dd909fede466ed813ec7c5d207c5deeb69c9eb7
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Sat Oct 27 11:33:22 2007 +0200
-
- Fix for #67: Enumerable#sort should not depend on #size.
-
-commit 720489aa52bfabd492c307330204772b5eba6755
-Author: Brian Ford <brixen@gmail.com>
-Date: Fri Oct 26 00:21:37 2007 -0700
-
- Updated CI excludes for spec/language.
-
-commit 41e8a07252b2df9c1e858922195a72f9a40c882c
-Author: Akshay Rawat <akshay.rawat@gmail.com>
-Date: Fri Oct 26 02:37:18 2007 +0530
-
- private keyword should mark a Module method private
-
-commit a201e631cbaabcc5964cfa3eb28a9fa8be1bf347
-Author: Brian Ford <brixen@gmail.com>
-Date: Fri Oct 26 00:11:01 2007 -0700
-
- Added spec/language into CI specs.
-
- Updated CI excludes for spec/language.
-
-commit 833fe76de0c0b900ef5255b2abecd19943404c0c
-Author: Brian Ford <brixen@gmail.com>
-Date: Thu Oct 25 23:53:35 2007 -0700
-
- Updated compiler specs and CI excludes.
-
-commit f31e5af358d2b5c3ff4afd3819b3a3e571427f8e
-Author: Brian Ford <brixen@gmail.com>
-Date: Thu Oct 25 23:28:13 2007 -0700
-
- Migrated Adam Gardiner's compiler patch 236d213de8 to stable.
-
- Updated CI excludes for language/variables specs.
-
-commit bd9e47b1b7624df5e2ae0f31a7fd53c787ecc7e4
-Author: Brian Ford <brixen@gmail.com>
-Date: Thu Oct 25 22:50:22 2007 -0700
-
- Fixed language/variables spec to use fixture class.
-
- Added CI exclude file for language/variables specs.
-
-commit 688f03ac452f698105812c28c29dcc7162b7037c
-Author: Adam Gardiner <adam.b.gardiner@gmail.com>
-Date: Thu Oct 25 22:43:20 2007 +1000
-
- Added specs for operator assignment, i.e. +=, *=, ||= etc
-
-commit 982dfee01bedb55e8dbf62d279bc4a375e58ec50
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Thu Oct 25 16:53:45 2007 +0200
-
- Don't hardcode the result of Hash#to_a in the Hash#shift spec.
-
-commit 4bf7c8d2d387c002004da5df9f9c2a06fb65e61e
-Author: Brian Ford <brixen@gmail.com>
-Date: Thu Oct 25 01:42:32 2007 -0700
-
- Commit tilman's language block spec additions with some modifications.
-
-commit ff8f6f5b5f5285b0fcf361d84523bf21320074b2
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Wed Oct 24 20:20:12 2007 +0200
-
- Extended the Hash#[] spec with a test case for ticket #65.
-
-commit dc61b1e771c70e54f98859da3dd31a4ea61384e1
-Author: Brian Ford <brixen@gmail.com>
-Date: Wed Oct 24 07:11:07 2007 -0700
-
- Specs after(:each) MUST come before it blocks.
-
- Updated CI excludes for IO.read specs.
-
-commit 06539bad037e0ef7368ea5cbb5780fce7bbea443
-Author: Marcus Crafter <crafterm@redartisan.com>
-Date: Wed Oct 24 21:26:49 2007 +1000
-
- Initial IO::read specs.
-
-commit a2f26d7a7b1997510edff1792eaec6507ba38208
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Tue Oct 23 19:30:46 2007 +0200
-
- Implemented Numeric#remainder.
-
-commit 2bc5fcee6be4db3e0e0c46aa7c1b8ef5a5c57957
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Tue Oct 23 19:10:54 2007 +0200
-
- Fixed Bignum#modulo(0.0).
-
-commit 68965dc12ea369f6db64c208cb2ce123c1398bb8
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Tue Oct 23 10:20:04 2007 +0200
-
- Extended the Numeric#nonzero? spec a bit.
-
-commit 290ddde29d6c64e9c81f69780b7b0c967b2b4901
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Tue Oct 23 10:15:57 2007 +0200
-
- Added Numeric#nonzero? and killed bad Fixnum#nonzero? in bootstrap.
-
- This fixes the Numeric#nonzero? specs.
-
-commit e9a1b257fc95c181e46c679d301a324134a725d4
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Tue Oct 23 16:07:58 2007 +0200
-
- Enabled the Numeric#step spec now that it works fine.
-
-commit f4016db94eee2ec93a2cc487181c9ec2fa0d59d0
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Wed Oct 17 13:51:04 2007 -0700
-
- A number of fixes found while debugging test/unit and optparse
-
-commit 7c7920c3e7727c3514b493ba299a52c5e5cde8f6
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Mon Oct 22 18:12:42 2007 -0500
-
- Numeric#step is capable of floats and passes all tests
-
-commit ebc6ec5be0239bba544c55ff77fdc88903f4bb28
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Mon Oct 22 20:56:33 2007 +0200
-
- Made the Symbol#inspect spec pass.
-
-commit f0db8c3d1bb5dc444fc72ed5ca222f4cf5df8b35
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Sun Oct 21 14:00:30 2007 +0200
-
- Fixed a bug in process_op_asgn1 and added a simple spec for it.
-
-commit 4fbce6e8a6ab8fbb6b69944677678611db68bcf2
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Sat Oct 20 20:03:50 2007 +0200
-
- Fixed a failure in String#sub specs
-
-commit ca0332f9edb9e01ae216dee90674fb6f9809951c
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Sat Oct 20 22:33:42 2007 +0200
-
- Fixed the Bignum#size spec for Rubinius' implementation.
-
-commit ae9c2ac3fe9dc59a027af7571d6d3083bcccb490
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Sat Oct 20 14:14:49 2007 +0200
-
- Don't rely on #respond_to? calls.
-
-commit 94938622aaf74e1f068c3b7ec8bfeccf763792ba
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Fri Oct 19 20:56:50 2007 +0200
-
- Extended the private spec.
-
-commit bf000a15edcfdd30c43ae6563b5766617f245a60
-Author: Brian Ford <brixen@gmail.com>
-Date: Fri Oct 19 00:49:16 2007 -0700
-
- Updated CI excludes.
-
-commit ad146fc7ae22bfc26a536a40cf8dc4c0338cf25c
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Thu Oct 18 19:45:27 2007 +0200
-
- Added a spec for the 'private' keyword.
-
-commit f15b5a8c818932d0ab5bea46f48a326e468b3511
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Thu Oct 18 19:44:54 2007 +0200
-
- Added Object#should_not_include.
-
-commit 80fdbd626d8ff99dc7ba4cf23a05d44ad98bd0cb
-Author: Yehuda Katz <wycats@gmail.com>
-Date: Thu Oct 18 09:31:51 2007 -0700
-
- Updates Hash so:
- * No longer freezes keys
- * Specs reflect the lack of freezing
- * shift spec doesn't fail purely because to_a is broken
-
-commit 197f36b6626b61203709704db869324a539764d5
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Wed Oct 17 20:11:50 2007 -0500
-
- moved File::expand_path to platform and made several fixes + new specs
-
-commit 7e8506fd510ab4e6f07e6d36456fdfef6e5b080a
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Wed Oct 17 21:07:44 2007 +0200
-
- Make sure that File.dirname doesn't modify its argument.
-
-commit 271bc31ba814e68fb414ebf29cf9648f57fe4cb6
-Author: David Altenburg <david@gensym.org>
-Date: Wed Oct 17 00:39:59 2007 -0500
-
- Added to fork spec: check that fork returns a nil pid for the child process
-
-commit 5d45341c55400a51d8cae3128bba265e7d441fab
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Wed Oct 17 05:19:49 2007 -0500
-
- moved File.basename to platform, added specs, and fixed specs for all but a disputable behavior
-
-commit ae7afd794881a4dedadf876f61369e5e88da695b
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Wed Oct 17 04:47:24 2007 -0500
-
- added platform/file.rb and fixed File.dirname for all and updated specs
-
-commit 71bf9b1c9cd7fb81692186d21b133fde43e8a6b7
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Wed Oct 17 03:44:33 2007 -0500
-
- spec to check if break exits all types of yields and loops correctly
-
-commit 3a546b40271d35bf7c60bb56a68ca49089ac9a34
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Wed Oct 17 03:01:40 2007 -0500
-
- clarified include_spec
-
-commit 40d8ed96fa689daf31039e71f91ed5520a821aa2
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Wed Oct 17 02:38:46 2007 -0500
-
- specs Module#include and Class#include that check to see if constants, public_methods and instance_methods are imported correctly
-
-commit ff462080a58aaa61759830e18f3a5757a883980d
-Merge: 5a2c858... 5cf41ab...
-Author: Jon Guymon <gnarg@kiryo.(none)>
-Date: Wed Oct 17 01:55:33 2007 -0400
-
- Merge branch 'puts_specs'
-
-commit 5cf41abaff9dc04cdba5fe50492d4ebfdde2a274
-Author: Jon Guymon <gnarg@kiryo.(none)>
-Date: Wed Oct 17 01:55:01 2007 -0400
-
- normalized specs for IO#puts StringIO#puts and Kernel#puts
-
-commit 5a2c858086c1b02a54864ff82c12d4bf3a559535
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Wed Oct 17 00:43:24 2007 -0500
-
- fixed posix File.join and added edge cases to specs
-
-commit e7972b8617b8b0ef2a19a1f7ddedd4d93ab80f5c
-Author: Brian Ford <brixen@gmail.com>
-Date: Tue Oct 16 21:17:21 2007 -0700
-
- Commit gnarg's loop specs (#49).
-
-commit 3fcdd60b4c9fc20081987bb13aab37b9419939a3
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Tue Oct 16 19:46:36 2007 +0200
-
- Make this spec usable by loading pathname.
-
-commit 276b6cc5620a5a3629d56b04ade7c397a48c2488
-Author: Brian Ford <brixen@gmail.com>
-Date: Tue Oct 16 00:53:11 2007 -0700
-
- Exclude metaclass instances from Module#ancestors list.
-
-commit e108e7f3f8a6ef7cf2acf4bb7e7a6609900a3ebc
-Author: Brian Ford <brixen@gmail.com>
-Date: Tue Oct 16 00:06:54 2007 -0700
-
- Updated CI excludes.
-
- Updated compiler specs to match recent changes.
- Added compiled core/string.rb from changes in edeffe90517.
-
-commit 1a1410f394b3de23b63560f2a5c1312cc6451d2e
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Mon Oct 15 19:49:40 2007 -0500
-
- spec for __FILE__ added
-
-commit e158c3130f033a1029ae26888b8e7e541f2b388a
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Mon Oct 15 19:46:58 2007 -0500
-
- spec for __LINE__ added
-
-commit d09ad9e6b28c91f5d00db5d0b369c4932eabbe2b
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Mon Oct 15 18:45:48 2007 -0500
-
- spec for throw/catch inside of ensure reverted and clarified
-
-commit 0e5336f1572fc1ad766cff61d8843410d28df9db
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Mon Oct 15 18:33:27 2007 -0500
-
- spec super refactored into fixtures and expanded to test all methods on each class
-
-commit b998ec8e682c3a0f2160066bb84f40b68f748407
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Mon Oct 15 16:26:58 2007 -0700
-
- Implement undef and Module#undef_method
-
-commit fed8486110930cabce64e0421638a867740e4d21
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Mon Oct 15 15:54:44 2007 -0700
-
- A bunch more language spec cleanups.
-
-commit 66086cb333432a29d4c4ce4fec6a01c0ac88c5a5
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Fri Oct 12 19:33:59 2007 -0700
-
- Bunch of compiler fixes to pass more language specs
-
-commit 680e0ca4cafb20fa053f0dd5cd72915da9fbc86f
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Mon Oct 15 17:36:09 2007 -0500
-
- specs for super involving inheritence, modules and metaclasses
-
-commit 167febd232f5cf4696cf8e81a96d1c9d80744e36
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Oct 15 15:32:48 2007 -0700
-
- Update CI excludes on OS X.
-
-commit 948e2573800859931e8c61e72069c21e9a50193b
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Oct 15 14:23:02 2007 -0700
-
- Update compiler specs to match recent changes.
-
-commit a015bac050e1080548bd947c5f59b344175a809d
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Mon Oct 15 23:51:01 2007 +0200
-
- Enabled the remaining Bignum#& spec.
-
-commit 0b37b2946772ea41fe7b14c762be7fdbaa4a6f8d
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Mon Oct 15 18:20:56 2007 +0200
-
- Updated Spec excludes for Bignum.
-
-commit ae613272bcf0c260ad3da00ffd14d4a76422ac46
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Mon Oct 15 08:30:11 2007 +0200
-
- Added the beginnings of a File.stat spec.
-
-commit 81147d2eadb0397c2bcc1b9dd620bb55b6e0e53d
-Author: Brian Ford <brixen@gmail.com>
-Date: Sun Oct 14 11:33:21 2007 -0700
-
- Fixed Float#to_s for numbers of the form "\d+.0".
-
-commit 2f9ba53190ca19ca425126d1319f47b3bbce12f6
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Sun Oct 14 18:57:04 2007 +0200
-
- Updated Bignum excludes.
-
-commit 0c81822cf703da13f6a8783cc6cd4ad453d2ff74
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Sun Oct 14 18:05:45 2007 +0200
-
- Add some OpenStruct specs.
-
-commit add2a900029530cb35b6463525313f432b7f36f4
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Sun Oct 14 17:29:38 2007 +0200
-
- Extended some more Bignum specs.
-
-commit 45cf3a275d390d4ae1d995eca89e10ba82d2288f
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Sun Oct 14 17:29:01 2007 +0200
-
- Extended the Fixnum#to_s specs a bit.
-
-commit d8a42cdd57967ee07cccfa5f3f814d97353c48c9
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Sat Oct 13 23:16:37 2007 +0200
-
- Fixed the bug that broke 'case' blocks with a single 'when' statement.
-
- Acked-by: Wilson Bilkovich <wilson@supremetyrant.com>
-
-commit 5624627fd61378fce65aebf2ffacc39c45ac5ee6
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Sat Oct 13 23:48:32 2007 +0200
-
- Ticket #37: Fixed Bignum#& segfaults when the argument isn't a bignum.
-
-commit 2081e5f53ba80cb9aa2ee272d4e543db1d4e732e
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Sat Oct 13 23:43:08 2007 +0200
-
- Modify and extend Bignum specs a bit.
-
-commit 7917f4f8a538a3251e3cb17d55e4cf2a523af8d5
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Sat Oct 13 23:42:44 2007 +0200
-
- Modify the fixnum specs a bit.
-
- Remove dependencies on Exception messages.
-
-commit 171f25c25865da618c2e2a9a7b221abda613efa4
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Sat Oct 13 02:02:12 2007 +0200
-
- Extended Fixnum#<=> specs a bit.
-
-commit f708429a161c52dd713b4239527247c57fa158af
-Author: Martin Kuehl <martin.kuehl@gmail.com>
-Date: Sat Oct 13 23:30:37 2007 +0200
-
- Guard bin/ci from running the new Bignum#& specs, which segfault (on OS X at least).
-
-commit 19f40e0ae1b60c037d0c38537a0924ad5726902a
-Author: Ben Curren <ben@esomnie.com>
-Date: Sat Oct 13 13:46:35 2007 -0700
-
- Refactored const_name_to_sym to share logic with Class#attr.
-
-commit ee9daad614fa746a3fe2fc1b9123c65dbb0814c7
-Author: Brian Ford <brixen@gmail.com>
-Date: Sat Oct 13 11:52:08 2007 -0700
-
- Identify which ruby platform and version before changing this spec!
-
- Revert "Fix spec to expect correct result."
-
- This reverts commit 8268469c563943cba6c1afce5d84defbc35f1789.
-
-commit 14a7781944491e5a1c3f5c664adcac4e1c383f2f
-Author: Tilman Sauerbeck <tilman@code-monkey.de>
-Date: Sat Oct 13 17:15:24 2007 +0200
-
- Added a failing spec for 'case' with only one 'when' statement.
-
-commit 8268469c563943cba6c1afce5d84defbc35f1789
-Author: Tom Mornini <tmornini@engineyard.com>
-Date: Sat Oct 13 03:22:47 2007 -0700
-
- Fix spec to expect correct result.
-
-commit 671f93c69e74976c3f5886c7fe8eb32402ccd338
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Fri Oct 12 19:06:07 2007 -0500
-
- specs exiting threads using return, raise, and throw
-
-commit 119154a3ea5ecee20e77726b38fb58ee4b536d48
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Fri Oct 12 18:59:47 2007 -0500
-
- spec to ensure throw exits from correct nesting and can return a value
-
-commit f36f68f075b34b5436257aba1ae41c14c04adcae
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Sat Oct 13 01:54:42 2007 +0200
-
- Method#[] specs should include the fixture classes.
-
-commit 22d32a24eb799307e42af55b04752c74ff500080
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Sat Oct 13 01:40:01 2007 +0200
-
- Extend Bignum#coerce, Bignum#&, Bignum#| and Bignum#^ specs.
-
-commit e1f682e27d2486d65297cf2121c354a99954a56e
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Sat Oct 13 01:38:55 2007 +0200
-
- Removed a dependency on an exception message in Fixnum#coerce specs.
-
-commit 9754ed5e74eeb6d62f0015f3615d077aa2e58a6f
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Fri Oct 12 21:41:56 2007 +0200
-
- Fixed File.chmod and File#chmod specs on win32.
-
-commit 5ad3a4b7035bdade48586191c6e26cde1e74976c
-Author: Martin Kuehl <martin.kuehl@gmail.com>
-Date: Sat Oct 13 01:37:46 2007 +0200
-
- Remove wrong spec from Bignum#divmod.
- Update CI excludes.
-
-commit b068c8634b56cd9129f9fc7c309bfa81869209c8
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Fri Oct 12 18:21:52 2007 -0500
-
- specs for behavior of throw/catch and how they interact with ensure
-
-commit 45d4a8be8f20b2b70d32d0fdd340feb8897a1ad7
-Author: Martin Kuehl <martin.kuehl@gmail.com>
-Date: Sat Oct 13 01:21:21 2007 +0200
-
- Add (skeletal) Process::Status.
- Set $? in Kernel#system and Kernel#`.
-
-commit ef1499962a16a7ce85bffe9e61863d2806caf6ec
-Author: Martin Kuehl <martin.kuehl@gmail.com>
-Date: Fri Oct 12 23:52:16 2007 +0200
-
- Regenerate core/dir.rbc and CI excludes for Dir.
-
-commit b999f31ded2a7eccb856d95653a2826a3a190204
-Author: Martin Kuehl <martin.kuehl@gmail.com>
-Date: Fri Oct 12 23:02:39 2007 +0200
-
- Fix typo in Dir.mkdir.
-
-commit de235630aa08df803be0420084b0a61ee35f5448
-Author: Brian Ford <brixen@gmail.com>
-Date: Fri Oct 12 13:56:13 2007 -0700
-
- Added dev_null spec helper for capturing or silencing $stderr, etc.
-
- Fixed failing specs on OS X MRI 1.8.5.
-
-commit 01e27ea5fa0e0f0d170cd88f128adfbb2a2703bd
-Author: Martin Kuehl <martin.kuehl@gmail.com>
-Date: Fri Oct 12 22:01:43 2007 +0200
-
- Add spec for backticks and their setting of $?.
-
-commit f7b18c19e47c15f3ab05f8fa548eff034206b0d8
-Author: Brian Ford <brixen@gmail.com>
-Date: Fri Oct 12 13:21:03 2007 -0700
-
- Added guards to make specs pass on ubuntu feisty MRI 1.8.5.
-
- Fixed rspec_helper should_include to take multiple args.
-
-commit b2d25d4a502dca79ea98f60d937be7dbd8f496d2
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Fri Oct 12 14:19:55 2007 -0500
-
- spec for retry/redo to control order of an enumeration
-
-commit eec535a19dc2b20156349720dc3bb526c9fa4f1e
-Author: Martin Kuehl <martin.kuehl@gmail.com>
-Date: Fri Oct 12 18:53:33 2007 +0200
-
- Revert "Fix Kernel#`: set $? to the subprocesses exit status. Add a spec to check that."
-
- This reverts commit 40da2d5c68196c3c9002c4ca75ead0fefc520bef.
-
-commit 40da2d5c68196c3c9002c4ca75ead0fefc520bef
-Author: Martin Kuehl <martin.kuehl@gmail.com>
-Date: Fri Oct 12 18:43:44 2007 +0200
-
- Fix Kernel#`: set $? to the subprocesses exit status. Add a spec to check that.
-
-commit 5da57253750e854bd9baf5378684222a895e7fd9
-Author: Martin Kuehl <martin.kuehl@gmail.com>
-Date: Fri Oct 12 16:24:18 2007 +0200
-
- Shield "strange block args" spec from being run by mspec.
-
-commit 2a8f7d7dd6b0f7f800320f84d16d5d089357e085
-Author: Martin Kuehl <martin.kuehl@gmail.com>
-Date: Fri Oct 12 14:48:42 2007 +0200
-
- Fix block specs for MRI.
-
-commit ade6c39f6199198e0015558698bc7d0333f7bcd0
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Fri Oct 12 12:07:49 2007 +0200
-
- Fix Array#delete specs.
-
-commit 825af45d5effb6909bb0832f92621b96e51dc380
-Author: Brian Ford <brixen@gmail.com>
-Date: Fri Oct 12 01:15:23 2007 -0700
-
- Updated CI excludes.
-
-commit e1bfb47d3560929512cbdf5c27f56c92435ce29f
-Author: Brian Ford <brixen@gmail.com>
-Date: Fri Oct 12 00:40:53 2007 -0700
-
- Removed printing summary at exit in mini_rspec.
-
- Set $VERBOSE=nil when running the specs.
- Fixed specs failing MRI.
-
-commit 1f1a041d8bcfaeb8dd3cb17f7d31b21281e690a2
-Author: Brian Ford <brixen@gmail.com>
-Date: Thu Oct 11 18:26:14 2007 -0700
-
- Moved shared specs to shared directories.
-
- Rewrote Module#method_missing specs.
-
-commit f9177eb198003b495f485a13910808fe603030ad
-Author: Ben Curren <ben@esomnie.com>
-Date: Thu Oct 11 20:54:22 2007 -0700
-
- Added a failing test for setting and getting constants on an instance of a module.
-
-commit d9cbad87fd4d578e4f637627fa03cab312882a36
-Author: Ben Curren <ben@esomnie.com>
-Date: Thu Oct 11 20:51:27 2007 -0700
-
- Updated the excludes for module tests.
-
-commit 938f034bad41f4fe3391b941e536bce9e1be0af6
-Author: Ben Curren <ben@esomnie.com>
-Date: Thu Oct 11 20:49:57 2007 -0700
-
- Updated const_set_spec to not create a new instance of Module for testing purposes.
-
-commit 550caaf78723b00f95c5f8f38215b15a0940698a
-Author: Ben Curren <ben@esomnie.com>
-Date: Thu Oct 11 18:21:01 2007 -0700
-
- Updated the excludes for the tests that are now passing.
-
-commit 82c51fc652e215f0dc421099329c03a37af8e8f8
-Author: Ben Curren <ben@esomnie.com>
-Date: Thu Oct 11 17:56:48 2007 -0700
-
- Updated const_set and refactored the valid_const_name? further.
-
-commit c6323c74d0ee7b554d2cfbff3bd8d85ea910e0c9
-Author: Ben Curren <ben@esomnie.com>
-Date: Thu Oct 11 12:01:27 2007 -0700
-
- Added logic to remove Object and empty from a recursive string for const_get and const_defined?
-
-commit c108d2a623f5041f46b6efa32d0b331f4f91d669
-Author: Ben Curren <ben@esomnie.com>
-Date: Thu Oct 11 11:58:04 2007 -0700
-
- Added back the recursive case for const_get and const_defined?
-
-commit b976f184d8ade3b5d32d3e7ec11027c21c2bce2a
-Author: Ben Curren <ben@esomnie.com>
-Date: Thu Oct 11 11:33:41 2007 -0700
-
- Refactored const_defined to use const_get.
-
-commit 82c5c14b948cedbf3bed5f7996634b0238e4de55
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Thu Oct 11 17:38:05 2007 -0700
-
- Bunch of compiler fixes, almost have test/unit and optparse running.
-
- * Adds support for /ao#{name}/o (aka dregx_once)
- * Invalid redo's raise an exception at runtime instead of compile time
- * defined?(a.foo) works
- * Lots of work on getting the block arg semantics right, including a new
- instruction, passed_blockarg which is used to detect at runtime how
- many block args were passed in.
- * bug in 'yield 1, 2' versus 'yield [1, 2]' fixed
- * A little better error reporting on compile errors
- * Fixed Class#<, added #>, #<=, and #>=
- * Fixed Hash.new
- * Fixed nested case problem
-
-commit 1369b104a3f966dd4d279362afdc6ccb72f06de3
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Thu Oct 11 22:47:16 2007 +0200
-
- Fix String#eql? specs.
-
-commit b190009707c120edb257a9ad92697145092c5612
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Thu Oct 11 10:57:10 2007 -0700
-
- Shield parse errors in block args properly
-
-commit 0509ecbd6aeb973061866c5e04c590f975174b41
-Author: Ben Curren <ben@esomnie.com>
-Date: Thu Oct 11 10:21:08 2007 -0700
-
- Updated tests to test FixNum being passed to const_defined?
-
-commit 80116298779dc5afd3294cd83d758d76d0dcdf50
-Author: Ben Curren <ben@esomnie.com>
-Date: Thu Oct 11 10:16:46 2007 -0700
-
- Added error checking to const_defined?
-
-commit eed3ae097b1dae17e45cdb959b75d1fa7cf21c1b
-Author: Ben Curren <ben@esomnie.com>
-Date: Thu Oct 11 09:25:53 2007 -0700
-
- Convert paramter to_str if it responds to the method.
-
-commit 348df85a082eee56c301bce594d6c522050e34dd
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Wed Oct 10 18:49:34 2007 -0500
-
- specs for language/retry and updated redo to show differences between them
-
-commit e924e2bb206317e8f5375c979f5e4e1046fccca9
-Author: Tom Mornini <tmornini@engineyard.com>
-Date: Wed Oct 10 00:55:47 2007 -0700
-
- Add Class#attr, refactor Class#attr_reader, Class#attr_writer and
- Class#attr_accessor, pass all specs for Class#attr_*, fix a couple of issues
- with said specs.
-
-commit 21b0bdc67c6a8cc4ad4b9d3942a2608fb45da31d
-Author: Brian Ford <brixen@gmail.com>
-Date: Tue Oct 9 15:10:04 2007 -0700
-
- Commit #198, patch from Will for Module#(private|public)_class_method.
-
-commit 2cf5f0b4683d0a65181c1450d0714c4e165db1cd
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Tue Oct 9 21:00:13 2007 +0200
-
- Moved shared specs.
-
- Moved shared specs into the 'shared'-subdirectory so specs don't depend on each other anymore. Added some more shared specs.
-
-commit e558fab61ce9f7c5211d005aff2c5e8fc1b39931
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Tue Oct 9 19:53:46 2007 +0200
-
- Fixed a failing Array#each spec. Closes #14.
-
-commit 0d77eefd718c826e02376edc8643364eb511773d
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Tue Oct 9 19:09:17 2007 +0200
-
- Removed remaining dependencies on Exception messages in Fixnum specs.
-
-commit dd4063ba46eb313a57957d76dce3608dd8e5c161
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Tue Oct 9 18:58:01 2007 +0200
-
- Fixed String#crypt spec.
-
-commit d5a2bb2b000fae7391e512c5bcab054ce967de3b
-Author: Brian Ford <brixen@gmail.com>
-Date: Tue Oct 9 09:35:51 2007 -0700
-
- Updated CI excludes after applying Akshay's Precision specs patch.
-
-commit 10cd5764bbf51f1defa6815f8b07fcdce0de8875
-Author: Akshay Rawat <akshay.rawat@gmail.com>
-Date: Thu Oct 4 21:48:15 2007 +0530
-
- Specs for the module Precision
-
-commit 2e711c30e4e9ce50d9c20ab14a3b99ea47be32e9
-Author: Martin Kuehl <martin.kuehl@gmail.com>
-Date: Tue Oct 9 13:56:45 2007 +0200
-
- Make IO#puts specs pass in MRI.
-
-commit 13dc28c47c3211f01663d002847badb50277f277
-Author: Martin Kuehl <martin.kuehl@gmail.com>
-Date: Tue Oct 9 13:44:51 2007 +0200
-
- Silence warnings when running Hash specs in MRI.
-
-commit 52f903938f4eacf4465f7a36cacb25aa662aa559
-Author: Martin Kuehl <martin.kuehl@gmail.com>
-Date: Tue Oct 9 13:44:02 2007 +0200
-
- Turn Hash#values_at into a shared spec.
-
-commit 1e02ced5a68f16b8a65809136d954c68c9fdc590
-Author: Martin Kuehl <martin.kuehl@gmail.com>
-Date: Tue Oct 9 12:59:58 2007 +0200
-
- Add a few more specs for Struct#new.
- Regenerate CI excludes for Struct.
-
-commit 94ea8c1f25761384796e9499e0b4b3faeba9da66
-Author: Martin Kuehl <martin.kuehl@gmail.com>
-Date: Tue Oct 9 12:48:03 2007 +0200
-
- Silence warnings when running Struct specs in MRI.
-
-commit 5ea6b219a8465cfad86dae9ae12d6a8d85812532
-Author: Martin Kuehl <martin.kuehl@gmail.com>
-Date: Tue Oct 9 12:42:58 2007 +0200
-
- Apply patch from ticker #23 by Jon Guymon (gnarg).
- Make Struct specs not depend on method argument evaluation order.
-
-commit 8cbf7b94300e6ebcc0ee3cbe0de8123ef3563e96
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Oct 8 22:08:29 2007 -0700
-
- Fixed that including a module includes the whole chain.
-
- Fixed that Module#include only allows modules.
- Simplified some module fixtures.
- Updated CI specs for module.
-
-commit 4e7e2768d50392831a4d26f236d4cff733418225
-Author: Ben Curren <ben@esomnie.com>
-Date: Mon Oct 8 11:54:51 2007 -0700
-
- Added puts spec for io and updated IO implementation to match MRI's. Updated Kernal#puts to delegate to $stdout.puts.
-
-commit edc724086e84725995ed1720d4fa7a781fd9c3c6
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Oct 8 09:24:40 2007 -0700
-
- Updated CI excludes for Module#define_method.
-
-commit a53ddb723a10d692223f05a49679e17f403fa128
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Mon Oct 8 01:05:04 2007 +0200
-
- Fixed some Fixnum specs to not depend on error messages.
-
-commit d6bc4b47f3f395980c92f323cf029da1ccdba709
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Sun Oct 7 23:42:12 2007 +0200
-
- Added another failing spec for Module#define_method.
-
-commit 49435e31289f593a118377b3513ec9e7cdfea06b
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Sun Oct 7 23:37:19 2007 +0200
-
- Added failing specs for Module#define_method when given an UnboundMethod.
-
-commit 821c0114777fb2a77f1c85f216ee54e4c5340943
-Author: Martin Kuehl <martin.kuehl@gmail.com>
-Date: Sun Oct 7 22:29:47 2007 +0200
-
- Apply patch from ticket #15 by Jon Guymon (gnarg).
- Add Struct#eql?.
- Rebuild core/struct.rbc.
- Add more struct specs.
- Update CI excludes for Struct.
-
-commit 1f14c3510d4563930d11155f36717c0fb851c678
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Sun Oct 7 18:13:33 2007 +0200
-
- Added some GetoptLong Specs.
-
-commit f9c8c00649212b924561300abbd0cb037c1d278d
-Author: Brian Ford <brixen@gmail.com>
-Date: Sat Oct 6 23:00:05 2007 -0700
-
- Update CI excludes for File#executable.
-
-commit 6d4427d07fc474e2404cdd2b6f3b925d99d90e67
-Author: Brian Ford <brixen@gmail.com>
-Date: Sat Oct 6 22:50:45 2007 -0700
-
- Updated spec/excludes.txt from 72 items to 17.
-
- Added -V | --verbose flag to bin/mspec.
- Updated CI excludes.
-
-commit d4f5e44a8e2f8e682b779f45d12d060e83eb9fc7
-Merge: a035e9d... 42abc5e...
-Author: Jason Yates <jaywhy@gmail.com>
-Date: Sat Oct 6 15:18:45 2007 -0400
-
- Merge branch 'master' of git@git.rubini.us:code
-
-commit a035e9d3d204cf7e5ddb2fec72ca471ff33c3b9b
-Author: Jason Yates <jaywhy@gmail.com>
-Date: Sat Oct 6 15:13:28 2007 -0400
-
- fix a bug in the File.executable? spec
-
-commit 3c23c945aaf143aa8706b1cd2956908a71940e26
-Author: Jason Yates <jaywhy@gmail.com>
-Date: Sat Oct 6 15:09:55 2007 -0400
-
- fix bug in File.executable? spec
-
-commit 94e59065bf921ae167a6b04edfef40de336978a1
-Author: Jason Yates <jaywhy@gmail.com>
-Date: Sat Oct 6 15:03:14 2007 -0400
-
- Revert "Revert "Add a few more Proc#call specs. And CI excludes.""
-
- This reverts commit 7658362c3882c6be2ef67f6b57d6c6796ff5de98.
-
-commit 42abc5ed6e1ced2fa86e9dc9379c6bed4da4537e
-Author: Brian Ford <brixen@gmail.com>
-Date: Sat Oct 6 11:40:49 2007 -0700
-
- Updated CI excludes for Kernel specs.
-
-commit 7658362c3882c6be2ef67f6b57d6c6796ff5de98
-Author: Jason Yates <jaywhy@gmail.com>
-Date: Sat Oct 6 14:29:28 2007 -0400
-
- Revert "Add a few more Proc#call specs. And CI excludes."
-
- This reverts commit 567659dee34014d037d4797bf0c171597e0ac05d.
-
-commit 567659dee34014d037d4797bf0c171597e0ac05d
-Author: Martin Kuehl <martin.kuehl@gmail.com>
-Date: Sat Oct 6 16:23:54 2007 +0200
-
- Add a few more Proc#call specs. And CI excludes.
-
-commit d8e737b09f8ed984e57b4fbbd5c016a7643aa67d
-Author: Martin Kuehl <martin.kuehl@gmail.com>
-Date: Sat Oct 6 15:56:33 2007 +0200
-
- Fix Array#slice specs. Regenerate CI excludes.
-
-commit c79eeb620296a1802e6d194463063555638911bf
-Author: Martin Kuehl <martin.kuehl@gmail.com>
-Date: Sat Oct 6 14:34:05 2007 +0200
-
- Fix Array specs that depended on respond_to? being called on coercion.
- Regenerate CI excludes for core/array.
-
-commit 8a60522fd8237fdfa36ef5518c9642216c66f8d6
-Author: Martin Kuehl <martin.kuehl@gmail.com>
-Date: Sat Oct 6 14:08:22 2007 +0200
-
- Guard Array specs for #freeze. Fix MRI Array specs for #freeze.
- Regenerate CI excludes.
-
-commit eaaab65c54c3b81397441169761774ef95867297
-Author: Martin Kuehl <martin.kuehl@gmail.com>
-Date: Sat Oct 6 12:47:55 2007 +0200
-
- Add specs for Proc#call. Regenerate CI excludes.
- (Most of these seem to be from e6cf8978.)
-
-commit 19bcb0f6ec1b2247985823492f0c25f0aa5d94ab
-Author: Martin Kuehl <martin.kuehl@gmail.com>
-Date: Sat Oct 6 12:09:29 2007 +0200
-
- Slightly amend the core/hash specs.
- Regenerate CI excludes.
-
-commit 6d1afe325098a73757980bb208fb2c8c64bd016b
-Merge: ac9365e... 0d22ef5...
-Author: Jason Yates <jaywhy@gmail.com>
-Date: Sat Oct 6 01:13:59 2007 -0400
-
- Merge branch 'master' of git@git.rubini.us:code
-
-commit ac9365e384263b6f062353f2afab3e33d8f84f3e
-Author: Jason Yates <jaywhy@gmail.com>
-Date: Sat Oct 6 01:13:23 2007 -0400
-
- added spec for OpenStruct
-
-commit e6cf8978a6dd441d5d4793c48438fab4150ca750
-Author: Jason Yates <jaywhy@gmail.com>
-Date: Sat Oct 6 00:14:01 2007 -0400
-
- added several tests to Proc
- added tests for Kernel#lambda and Kernel#proc
-
-commit 7b69ae066cab2252375d1ad19c6f17b365c47c32
-Author: Brian Ford <brixen@gmail.com>
-Date: Fri Oct 5 18:51:11 2007 -0700
-
- Updated CI excludes for Array.
-
-commit f216e89033d10f3500798561282e48aa0e5b5537
-Author: Jason Yates <jaywhy@gmail.com>
-Date: Fri Oct 5 20:45:41 2007 -0400
-
- really simple spec for the Singleton class.
-
-commit d682b176237a988afa7ebdb3460d64ea41fab919
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Sat Oct 6 01:54:31 2007 +0200
-
- Applied esomnies
-
-commit b3018362c0cad86a5a026eb39b5f6ea4a8af1192
-Author: Martin Kuehl <martin.kuehl@gmail.com>
-Date: Sat Oct 6 01:24:05 2007 +0200
-
- Guard Hash specs for #freeze.
-
-commit a185f463adbab1d6f82126dde9abe88a29e83283
-Author: Martin Kuehl <martin.kuehl@gmail.com>
-Date: Sat Oct 6 01:15:23 2007 +0200
-
- Fix workarounds in core/hash specs.
-
-commit d796eb3d8a5d9a070b105f1fe0e9f46be5bfaaee
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Fri Oct 5 17:09:48 2007 -0500
-
- specs for UDPSocket client/server
-
-commit 46a9c1a0d0610865b659c289293b444f0b3d6ae9
-Author: Brian Ford <brixen@gmail.com>
-Date: Fri Oct 5 15:32:56 2007 -0700
-
- Fixed bin/ci to not load spec/excludes.txt for every file.
-
- Fixed bin/mkspec to not overwrite an existing spec file.
- Updated Fixnum CI excludes.
-
-commit 1099f49c06de5621aff36216179f46c308e60a38
-Author: Brian Ford <brixen@gmail.com>
-Date: Fri Oct 5 14:40:24 2007 -0700
-
- Added basic IO#readlines spec and implementation.
-
-commit edc438039ee503c7b9d1fb83b04bd9bc1664cda5
-Author: Martin Kuehl <martin.kuehl@gmail.com>
-Date: Sat Oct 6 00:09:41 2007 +0200
-
- Regenerate core/hash.rbc, core/hash CI excludes.
-
-commit 2ad7d015a316620a488ed1cdeb45fe696b9d410a
-Author: Martin Kuehl <martin.kuehl@gmail.com>
-Date: Fri Oct 5 23:56:59 2007 +0200
-
- Extend core/hash specs to check for LocalJumpErrors.
-
-commit 42d961f0ab8a7e23a822b41ca82aaed5a48da2bf
-Author: Martin Kuehl <martin.kuehl@gmail.com>
-Date: Fri Oct 5 23:21:20 2007 +0200
-
- Refactor and fix Hash#inspect.
-
-commit b51402d8724478b85789d19857a2a48442470fcb
-Author: Brian Ford <brixen@gmail.com>
-Date: Fri Oct 5 11:29:08 2007 -0700
-
- Fixed bin/mkspec to not create the spec file stub if the file exists.
-
-commit efe79de398db491ce97666a3f4f3b38265c1ab95
-Author: Brian Ford <brixen@gmail.com>
-Date: Fri Oct 5 10:55:52 2007 -0700
-
- Updated CI specs. Guarded String specs for #freeze.
-
-commit 8647951df433d427be31bec060edf5b7efb46e46
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Fri Oct 5 17:04:25 2007 +0200
-
- Replaced all occurrences of Object#coerce_to with Type.coerce_to and removed Object#coerce_to.
-
-commit 778e11d2df647cf91a712bb30df34152c71dbc3f
-Author: Martin Kuehl <martin.kuehl@gmail.com>
-Date: Fri Oct 5 11:42:40 2007 +0200
-
- Don't work around rbx bugs in Hash specs.
-
-commit 4b42923eb2cdebe43f9e9dd80fff98d9ded26e4b
-Author: Martin Kuehl <martin.kuehl@gmail.com>
-Date: Fri Oct 5 11:29:33 2007 +0200
-
- Fix Hash specs to pass in MRI again. (Doh!)
-
-commit 8a4f0b1c0d95b7a87ed99583797cf7d3710fb15a
-Author: Brian Ford <brixen@gmail.com>
-Date: Fri Oct 5 02:24:30 2007 -0700
-
- Updated CI excludes for Hash.
-
-commit cecbf342546f37f4923728e8381e7fafcb039633
-Author: Brian Ford <brixen@gmail.com>
-Date: Fri Oct 5 02:22:41 2007 -0700
-
- Changed bin/ci to run in a single process. Updated CI excludes.
-
-commit ba0f4ef5405665c84af4410d70be5ef911a93195
-Author: Yehuda Katz <wycats@gmail.com>
-Date: Thu Oct 4 22:58:50 2007 -0700
-
- Adds the intern spec from Ticket #8
-
-commit 0721f6ea40f51202ec9d2d421061be92e05a18b9
-Author: Jason Yates <jaywhy@gmail.com>
-Date: Thu Oct 4 22:39:00 2007 -0400
-
- Commit #207 Xavier Shay Enhanced specs for Hash
- fixed Binding#dup spec
-
-commit ce4a1866ef65e041fbed224c3f694ca534d0a0d1
-Author: Yehuda Katz <wycats@gmail.com>
-Date: Thu Oct 4 18:24:21 2007 -0700
-
- makes String#delete faster
-
-commit 7ec0eeadf554150159f0a04468b16de8f06c2e8a
-Author: Martin Kuehl <martin.kuehl@gmail.com>
-Date: Fri Oct 5 00:32:25 2007 +0200
-
- Whoops, two more frozen TypeErrors I forgot.
-
-commit 78a3de42bf0e6f1478b2aac903c25143fd56195a
-Author: Martin Kuehl <martin.kuehl@gmail.com>
-Date: Thu Oct 4 23:17:42 2007 +0200
-
- Regenerate CI excludes and core/hash.rbc after revert.
-
-commit beaa5d022b19cb70213d4fe14e10d7f1a5f90a3a
-Merge: c7ea881... 8cb4b0b...
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Thu Oct 4 16:12:41 2007 -0500
-
- Merge branch 'spec_block_parameters'
-
-commit 8cb4b0b2c3c766618a523a0ef9a83106761ee2f8
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Thu Oct 4 16:11:15 2007 -0500
-
- specs for setting variables in block parameters
-
-commit c7ea8812f74184e6ee33bb236766f32fface2f95
-Author: Martin Kuehl <martin.kuehl@gmail.com>
-Date: Thu Oct 4 22:57:09 2007 +0200
-
- Regenerate CI excludes for spec/core/hash. New hash.rbc.
-
-commit 939e8c533fb70586f8c7c6f3506d6be13f492d78
-Author: Martin Kuehl <martin.kuehl@gmail.com>
-Date: Thu Oct 4 22:11:18 2007 +0200
-
- Fix Hash specs: don't depend on coercion to call respond_to?
-
-commit 422e45f210ec9dc2438ae3b11544823bb6ffdd50
-Author: Jason Yates <jaywhy@gmail.com>
-Date: Thu Oct 4 16:21:27 2007 -0400
-
- added specs for FileTest#exists? and FileTest#exist?
-
-commit e43466b52184a042bd38d33273acf7afa4580a96
-Author: Jason Yates <jaywhy@gmail.com>
-Date: Thu Oct 4 16:12:58 2007 -0400
-
- added spec for File.exists?
-
-commit 9f69c8193d92752a2be7c21d23dfe90fb9765f11
-Author: Jason Yates <jaywhy@gmail.com>
-Date: Thu Oct 4 16:03:33 2007 -0400
-
- fixed grammar error in Method#clone
-
-commit 9321aacf703eaec6d6bc26cce83ed7475cb27d46
-Author: Jason Yates <jaywhy@gmail.com>
-Date: Thu Oct 4 16:00:31 2007 -0400
-
- added several specs for Module
-
-commit a282c1c4c137e1bdeae34f2f9cd58bc73f257809
-Author: Jason Yates <jaywhy@gmail.com>
-Date: Thu Oct 4 14:19:07 2007 -0400
-
- added specs for Kernel#binding and Binding
-
-commit 3e92b4528dbf47b80a25232979554f7e4309460a
-Author: Brian Ford <brixen@gmail.com>
-Date: Thu Oct 4 10:45:10 2007 -0700
-
- Fixed ffi_sprintf_[fd]. Updated String spec CI excludes.
-
-commit 9e9a292a8a4befeb8a928d476119b02ac0df976e
-Author: Martin Kuehl <martin.kuehl@gmail.com>
-Date: Thu Oct 4 18:53:47 2007 +0200
-
- Alias Object#object_id to Object#__id__
- Regenerate CI excludes for spec/core/kernel
-
-commit 8790e93c6d231baf7da07f11d02b91a38d28375e
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Wed Oct 3 18:23:42 2007 -0700
-
- Superclass checking and loop {} fix.
-
-commit 718ae6f28223e94b8ca0f3af7ce321c81a597804
-Author: Martin Kuehl <martin.kuehl@gmail.com>
-Date: Thu Oct 4 15:05:59 2007 +0200
-
- Slightly extend Object#kind_of? specs.
-
-commit 7fa087a7058fe8872bb9743abd6dd472cd2119d7
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Thu Oct 4 08:43:55 2007 +0200
-
- Fixed some String#slice specs.
-
-commit b9be176a9e64669f2a787c9bdebc1ba30e344d97
-Author: Paul Meserve <pmeserve@gmail.com>
-Date: Thu Oct 4 01:37:56 2007 -0400
-
- adding String#each_char
-
-commit c1b17108a78a4dc5d3e224158f8f9d76232003e6
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Wed Oct 3 17:42:06 2007 -0500
-
- basic specs for Kernel#sleep
-
-commit 1fe895518bdccb93991f85a92f53876ed3d4df13
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Wed Oct 3 14:16:14 2007 -0500
-
- added spec for Kernel.local_variables
-
-commit 00417283b36dcb58da82c6fc2e9be7580de945b0
-Author: Charles Comstock <dgtized@gmail.com>
-Date: Wed Oct 3 14:15:25 2007 -0500
-
- added specs for Kernel#global_variables
-
-commit 5b944520099f129462c3b03fa6ee7d1bb0636fc0
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Wed Oct 3 14:07:09 2007 +0200
-
- Fix String#index specs.
-
-commit c9cdef77c7fa8dda92c91cee5a47624b9c9dc9e8
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Wed Oct 3 14:05:34 2007 +0200
-
- Fix String#hex specs
-
-commit 4625a7afe509545f782cd4631632b4d7a58011aa
-Author: Yehuda Katz <wycats@gmail.com>
-Date: Tue Oct 2 23:53:20 2007 -0700
-
- String#% works with a few exceptions:
-
- * %u doesn't work (it's aliased to %d for now, as in 1.9)
- * There's a weird glitch in Float(10_1_0.5_5_5) that I can't track down
-
-commit 54ab6f559093e66f78cfa30db8aa6587061552d6
-Author: Martin Kuehl <martin.kuehl@gmail.com>
-Date: Wed Oct 3 02:05:41 2007 +0200
-
- Extend Kernel#kind_of? specs.
- Regenerate CI excludes.
-
-commit 4583be7e7ed76e5843dcb396f8bae735f341de73
-Author: Martin Kuehl <martin.kuehl@gmail.com>
-Date: Wed Oct 3 02:03:58 2007 +0200
-
- Remove superfluous whitespace from Object#kind_of? specs.
-
-commit 5c237626469f4b0f4d227916752dd2e03510fcf9
-Author: Martin Kuehl <martin.kuehl@gmail.com>
-Date: Wed Oct 3 01:50:33 2007 +0200
-
- Remove superfluous comment from Object#kind_of? specs.
-
-commit 7a2c673d04b0d0506e89073ff231104e21c3304c
-Author: Martin Kuehl <martin.kuehl@gmail.com>
-Date: Wed Oct 3 01:47:56 2007 +0200
-
- Simplify Kernel#freeze specs.
- Move Object#extend vs. frozen? spec to extend_spec.
- Rebuild CI excludes for Object#extend specs.
-
-commit 3f6a27603b0b1f91ce32b9ff2a5fe3222fa7220b
-Author: Brian Ford <brixen@gmail.com>
-Date: Tue Oct 2 17:03:37 2007 -0700
-
- Commit Charles Comstock's language return specs.
-
-commit ad4e7affcbaae4f0e967c97da485313168595a5e
-Author: Martin Kuehl <martin.kuehl@gmail.com>
-Date: Wed Oct 3 01:36:27 2007 +0200
-
- Fix Kernel#caller.
- New core/kernel.rbc.
- Regenerate CI excludes for Kernel#caller.
-
-commit 73b2ef1c889c940d22da6ad6bb8882eef66592fa
-Author: Martin Kuehl <martin.kuehl@gmail.com>
-Date: Wed Oct 3 01:34:10 2007 +0200
-
- Add spec for checking the default argument value for Kernel#caller.
-
-commit 180ecd6a7fa1d32e1932a322b1f8f82efd558e7f
-Author: Martin Kuehl <martin.kuehl@gmail.com>
-Date: Wed Oct 3 01:32:29 2007 +0200
-
- Add spec for checking that Kernel#caller returns nil.
-
-commit 9ad0c1428df70c9fd9e0081651e3b60cf5773267
-Author: Martin Kuehl <martin.kuehl@gmail.com>
-Date: Wed Oct 3 01:30:46 2007 +0200
-
- Add spec for checking the argument handling of Kernel#caller.
-
-commit 7a9483b823115b3122a4e42b21dfcb5b0f369a54
-Author: Martin Kuehl <martin.kuehl@gmail.com>
-Date: Wed Oct 3 01:23:17 2007 +0200
-
- Refactor the tedious part of the Kernel#caller specs.
-
-commit e204755859e4dc147217816ab3bf587db3d51dd6
-Author: Martin Kuehl <martin.kuehl@gmail.com>
-Date: Wed Oct 3 01:22:26 2007 +0200
-
- Cleanup description of Kernel#caller specs.
-
-commit dadbbb7930b62a4a6e47c8c32a4d9f26fcea38b4
-Author: Martin Kuehl <martin.kuehl@gmail.com>
-Date: Tue Oct 2 23:52:49 2007 +0200
-
- Regenerate CI excludes for spec/core/kernel. Again. Because I fixed the typos.
-
-commit 4a3587da37fd27effb30356fdd2e496f8c898be7
-Author: Martin Kuehl <martin.kuehl@gmail.com>
-Date: Tue Oct 2 23:45:33 2007 +0200
-
- Fix CI specs to pass in MRI 1.8.6.
-
-commit a46f5085f3c2a4849fe709044e447e5d6dacda4f
-Author: Martin Kuehl <martin.kuehl@gmail.com>
-Date: Tue Oct 2 23:27:51 2007 +0200
-
- Fix typos in spec/core/kernel specs.
-
-commit cb3d5867ec91a59a2a75136eb5210a10540b0ce0
-Author: Martin Kuehl <martin.kuehl@gmail.com>
-Date: Tue Oct 2 23:27:23 2007 +0200
-
- Regenerate spec/core/kernel excludes.
-
-commit 22e6fe0ef8dbf13aa01124447e09c9dc96f63fe3
-Author: Martin Kuehl <martin.kuehl@gmail.com>
-Date: Tue Oct 2 23:26:51 2007 +0200
-
- Fix Kernel#Array spec: don't depend on the exception message.
-
-commit 7b79130f38925cb48712be617cef5a80c71f0ba4
-Author: Brian Ford <brixen@gmail.com>
-Date: Tue Oct 2 14:29:42 2007 -0700
-
- Commit #5 (LH) Charles Comstock Process.wait2 spec.
-
-commit 859c119a48909030f29a2085fbe0a80ed96d2408
-Author: Martin Kuehl <martin.kuehl@gmail.com>
-Date: Tue Oct 2 20:57:31 2007 +0200
-
- Fix Float#to_i and add a spec to catch the old misbehaviour.
-
-commit f2b5b2304588b4fb0efd9818c79a4b9774b2c850
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Tue Oct 2 19:07:49 2007 +0200
-
- Fix some String#scan specs.
-
-commit 8e0ce11df329181efa440cbd55f29848e12188bf
-Author: Kevin Clark <kevin.clark@gmail.com>
-Date: Tue Oct 2 00:39:15 2007 -0700
-
- Add error handling for Dir.mkdir/rmdir
-
- Add aliases for Dir.delete/unlink
-
-commit 20e66dd965bfceb29e4939090a0fd543d05392a3
-Author: Brian Ford <brixen@gmail.com>
-Date: Tue Oct 2 00:21:49 2007 -0700
-
- Commit #206 Jason Yates' UnboundMethod specs.
-
-commit 00d7d22b7d106c6aac5d9664cb444e14811171b0
-Author: Yehuda Katz <wycats@gmail.com>
-Date: Mon Oct 1 17:57:29 2007 -0700
-
- First pass at actually getting my modulo impl working
-
-commit c90766a09c7e1fe7a2261f8b09d9caa8eaf2214e
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Mon Oct 1 21:21:34 2007 +0200
-
- Fix the String#crypt spec.
-
-commit a0f6f8e51a6f7a65230f8f2ea53587ccb09f9270
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Mon Oct 1 20:18:29 2007 +0200
-
- Changed the String#to_f specs a bit.
-
-commit 21d43e565bb55a31b45dc9fabbefface156ec516
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Mon Oct 1 16:13:28 2007 -0400
-
- Add failing Array#pack spec for use case taken from Mongrel
-
-commit b1d70b4a847fc1c8df3eb4a219c4318420121e82
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Oct 1 09:04:03 2007 -0700
-
- Commit #205 Jason Yates' Method specs.
-
-commit de7e0f0183d072f101e0781635fc2fdb1af1b851
-Author: Martin Kuehl <martin.kuehl@gmail.com>
-Date: Mon Oct 1 00:11:12 2007 +0200
-
- Fix compiler specs to expect sret when appropriate.
- Rewrite compiler specs for multiple assignments.
- Regenerate CI excludes for compiler specs.
-
-commit 1d1e704306fca4453d600259e87175dcdc9de314
-Author: Martin Kuehl <martin.kuehl@gmail.com>
-Date: Sun Sep 30 23:27:12 2007 +0200
-
- Add edge cases for File#extname specs.
-
-commit 108d757e6c24447b89fa785b2bf091b72d29933d
-Author: Martin Kuehl <martin.kuehl@gmail.com>
-Date: Sun Sep 30 22:34:15 2007 +0200
-
- Regenerate CI excludes for Dir specs.
-
-commit 20c6c3cd9b5d59b9782b702ac6afeb828e895d5f
-Author: Martin Kuehl <martin.kuehl@gmail.com>
-Date: Sun Sep 30 21:49:52 2007 +0200
-
- Make Dir specs pass in MRI.
-
-commit dcd172338bce5b70cb367db3c1e6f4653c05f9e8
-Author: Martin Kuehl <martin.kuehl@gmail.com>
-Date: Sun Sep 30 21:10:36 2007 +0200
-
- Fix case comparison with Symbols.
-
-commit 2a45cd71d1eb90a7c11ff62d81371df9479b0d43
-Author: Martin Kuehl <martin.kuehl@gmail.com>
-Date: Sun Sep 30 13:28:32 2007 +0200
-
- Add specs for String#tr! and String#tr_s!.
- Cleanup specs for String#tr! and String#tr_s!.
- Regenerate CI excludes for String#tr! and String#tr_s!.
-
-commit 6418bd672c8ea031d8ac2364c8a98bb631e53deb
-Author: Martin Kuehl <martin.kuehl@gmail.com>
-Date: Sun Sep 30 13:26:19 2007 +0200
-
- Add specs for multiple asignments with splats vs. Array#dup.
-
-commit 10b04881d286acab9dc97147750743e03ee4509f
-Author: Martin Kuehl <martin.kuehl@gmail.com>
-Date: Sun Sep 30 13:25:14 2007 +0200
-
- Fix Class.new to raise TypeError when the superclass is not a class.
-
-commit 0b9debba0672305f8551f5d5f35cdd3aaf16c1f1
-Author: Martin Kuehl <martin.kuehl@gmail.com>
-Date: Sun Sep 30 13:20:49 2007 +0200
-
- Add specs for the names of classes generated with Class.new.
-
-commit e15cef6eb851318838351a4d8717b708bb09d31d
-Author: Martin Kuehl <martin.kuehl@gmail.com>
-Date: Sun Sep 30 13:15:43 2007 +0200
-
- Remove debugging output from spec/core/dir/chdir_spec.rb
-
-commit f3251ba0e8ade79f157bc02dca550481488bf888
-Author: Martin Kuehl <martin.kuehl@gmail.com>
-Date: Sun Sep 30 13:15:17 2007 +0200
-
- Remove debugging output from spec/core/extensions/rubinius/options_spec.rb
-
-commit 5d4d2abaf02aef6caa7e532208da5e5f57bc6373
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Sun Sep 30 20:54:14 2007 -0400
-
- Working Socket implementation and specs. Still needs readpartial to support Mongrel.
-
-commit b514e53f589d509c287516d8dd985f96e66d9a1c
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Sat Sep 29 15:44:06 2007 -0400
-
- Working IPSocket#peername implementation
-
-commit 965ed2d88527ae8aa4ac962e8ca84180f61e6345
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Mon Sep 24 02:34:26 2007 -0400
-
- Yet another interim socket commit
-
-commit ecd54e981a1098c4b3abf14587212e7d1d9049a6
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Thu Sep 20 16:29:21 2007 -0400
-
- Another interim Socket commit
-
-commit 351bbdf08f190e24328328df7b3f995b8dc27a9f
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Wed Sep 19 22:17:52 2007 -0400
-
- Interim commit of Socket work so I can generate a patch
-
-commit 65a73cdfea95c5991f2044bee150e53643216ad3
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Wed Sep 26 13:15:45 2007 +0200
-
- Added some Marshal#load and Marshal#dump specs.
-
-commit 89e1b91c606dfe18581c3ed3923340b952471d8e
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Wed Sep 26 13:15:19 2007 +0200
-
- Extended Specs for Kernel.Float and Kernel.Array
-
-commit 5d46933362b8c54cb5d0370bbf61e063459de514
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Wed Sep 26 13:14:41 2007 +0200
-
- Added specs for Symbol.all_symbols.
-
-commit b3324808584d7b4ee6af58d98eeb7c2162c31208
-Author: Brian Ford <brixen@gmail.com>
-Date: Thu Sep 27 10:57:46 2007 -0700
-
- Commit #180, Jason Barton's specs for Module#undef_method, #remove_method.
-
-commit 2e1219fc03d9cb673074ee34b1f8af4bdffe9c0e
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Thu Sep 27 18:49:26 2007 +0200
-
- Fix Kernel.Integer by making use of String#to_inum. Add some more Kernel.Integer specs.
-
-commit b0d4747cab49f4a17e9899392171087d7b67f687
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Thu Sep 27 18:23:42 2007 +0200
-
- Fixed String#to_i. Added String#to_inum. Extended String#to_i specs.
-
-commit 2799c392b3f5383e9e74745ceb9cf7a52f82918b
-Author: Paul Meserve <pmeserve@gmail.com>
-Date: Thu Sep 27 01:20:00 2007 -0400
-
- fix for Struct#new and a small struct spec changes
-
- (also re-ran bin/ci on struct specs - most of the changes were from previous commits though)
-
-commit 30d9bf1f6ef9dcff067d427d6226bbce985f5e69
-Author: Paul Meserve <pmeserve@gmail.com>
-Date: Wed Sep 26 19:08:37 2007 -0400
-
- raise proper error when passing non-block args to Enumerable#all?
-
-commit 1ef1e0ef65ef3c86558da3d313dee5cada6dd4c5
-Author: Paul Meserve <pmeserve@gmail.com>
-Date: Wed Sep 26 17:25:17 2007 -0400
-
- adding alias for Float#quo to fix a couple number specs, and some modifications to Enumerable#min/#max, along with a couple new spec assertions. fixes failing specs and implementation should be a lot closer to MRI
-
-commit 547dd89791d92f061afcaef7184f054affae871d
-Author: Brian Ford <brixen@gmail.com>
-Date: Wed Sep 26 09:46:50 2007 -0700
-
- Fixed placement of after(:each) block in numerous File specs.
-
-commit fa3dcbfdd623a7a7cdb15bc29b38ae47bb4056d5
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Tue Sep 25 20:25:36 2007 +0200
-
- Added specs for UnboundMethod#arity
-
-commit 33783408b8ce1bdfcd205fd02bc3848119a632cc
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Tue Sep 25 18:00:10 2007 +0200
-
- Added specs for Class.
-
-commit 0edea3c3a7dda5c453c527b2cef3ffba1eef1396
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Tue Sep 25 17:25:40 2007 +0200
-
- Created some specs for Proc.
-
-commit 62c92f1c3aef6c2ff7ab8cbcd49eefb236d5caed
-Merge: b79d04d... 2d9c698...
-Author: Brian Ford <brixen@gmail.com>
-Date: Wed Sep 26 01:09:42 2007 -0700
-
- Merge branch 'dir'
-
-commit 2d9c69848f4ca34685b95b07e17d1b5fe1ec2391
-Author: Brian Ford <brixen@gmail.com>
-Date: Wed Sep 26 01:09:28 2007 -0700
-
- Updated CI spec excludes for Array, Dir, Fixnum, Enumerable, Hash.
-
-commit b79d04db673d9b7b5cc47f2918bccf1b0400bdbd
-Author: Brian Ford <brixen@gmail.com>
-Date: Wed Sep 26 00:56:01 2007 -0700
-
- Commit crayz's patch from #195, #196, #197.
-
-commit ec960578671a327469d9545d6ced827736ceafa0
-Author: Brian Ford <brixen@gmail.com>
-Date: Tue Sep 25 19:40:54 2007 -0700
-
- Fixed Dir specs failing MRI after conversion.
-
-commit 00b398352ed0f4cbcd326d56b7f8a4469056ee0d
-Author: Brian Ford <brixen@gmail.com>
-Date: Tue Sep 25 00:54:06 2007 -0700
-
- Many cleanups of Dir specs.
-
- Added Dir specs fixture directories and files.
-
-commit b75cfa7c0a9871dc34b8b315ca2311e65000b2f3
-Author: Brian Ford <brixen@gmail.com>
-Date: Sun Sep 23 00:41:36 2007 -0700
-
- Converted Dir.glob specs.
-
-commit 3d8ea2a55e67cc6cfb85d2f4f7845a45984f6504
-Author: Martin Kuehl <martin.kuehl@gmail.com>
-Date: Tue Sep 25 21:52:54 2007 +0200
-
- Fix a few Struct specs. Failures are down to 15.
-
-commit a477ff678e9f5f39d3d2b94e559c77b34f0c56c5
-Author: Martin Kuehl <martin.kuehl@gmail.com>
-Date: Tue Sep 25 20:51:38 2007 +0200
-
- Fix compiler warnings in Subtend spec extensions.
-
-commit db3e1be4e25b7e8cc463443d050afe9a5acaa7de
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Mon Sep 24 22:31:03 2007 +0200
-
- Extended Fixnum specs.
-
-commit d136b779736af52d1eac08a40814ab4a47de93b3
-Author: Yehuda Katz <wycats@gmail.com>
-Date: Sun Sep 23 17:47:30 2007 -0700
-
- Array#each explosion spec
-
-commit 8a24a71ff13aac465f7f4a14587981c3c23dc800
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Sun Sep 23 20:06:04 2007 +0200
-
- Extended Comparable specs.
-
-commit ea9ba046ddfe91601d4453972a6d6f8fce96c392
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Sun Sep 23 12:17:17 2007 +0200
-
- Fix Numeric#divmod and Fixnum#divmod.
-
-commit 1c5ecb9d2e9066c66b9f0625d65cc4cefaee1f83
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Sun Sep 23 12:00:16 2007 +0200
-
- Fix Float#to_i for infinite, negative values. Fix Numeric#/ and Numeric#div. Add Numeric#do_coerce.
-
-commit 2d67d024e11e887eb07622963bfc36b0ec377746
-Author: Yehuda Katz <wycats@gmail.com>
-Date: Sat Sep 22 20:08:38 2007 -0700
-
- Added Onig 5 and got rindex working with it
-
-commit adc26eb525447010e28fc884eaa54b9d2228f4d6
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Sun Sep 23 01:35:11 2007 +0200
-
- Fix Kernel.Float specs
-
-commit 9a2ecf258fee3bda410776b3d3b77366590d64fe
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Sat Sep 22 23:18:46 2007 +0200
-
- Extended more Fixnum specs. Removed the spec/fixnum/induced_from_spec.rb.
-
-commit 53b0042824bb1b1c523d790cb3645aec6b789abe
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Sat Sep 22 22:35:53 2007 +0200
-
- Extended many Fixnum specs.
-
-commit 8661cdb78cd2c4afa0fb231aa9cc959e338e097e
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Sat Sep 22 22:35:11 2007 +0200
-
- Extended nil#to_s spec.
-
-commit 4008d8b39032ffa5667e95fb445ff816b1428330
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Sat Sep 22 14:25:27 2007 +0200
-
- Added some more specs and fixed some bugs in Range#initialize, Range#step and Range#each.
-
-commit 254e3d57dc6e859616ca7e0c44058d4b73211f68
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Sat Sep 22 11:31:02 2007 +0200
-
- Some updates to Range specs.
-
-commit b87e28bfc06e81fe5c4c3d6e285947f635f79f61
-Author: Brian Ford <brixen@gmail.com>
-Date: Fri Sep 21 20:12:18 2007 -0700
-
- Commit wycats Regexp.regexp_match_region primitive.
-
-commit eaa56811836b4b5ed09a5e26d00f26eb004f2853
-Author: Brian Ford <brixen@gmail.com>
-Date: Fri Sep 21 18:44:25 2007 -0700
-
- Added StringValue to some File methods.
-
- Upated File CI spec excludes.
-
-commit 83f7b6020dbc881fbd6bd13da6ebb049d6080c2c
-Author: Brian Ford <brixen@gmail.com>
-Date: Fri Sep 21 17:54:53 2007 -0700
-
- Upated spec excludes for Float, Fixnum, and Math.
-
-commit af0b0c8da8357fcae7437f6cdfd7797f03ffd73b
-Author: Yehuda Katz <wycats@gmail.com>
-Date: Thu Sep 20 22:10:54 2007 -0700
-
- Fixed a number of string-related issues:
-
- String#inspect respects $KCODE
- String#inspect returns tainted subclass
- String#dump is no longer a copy of inspect, and does not respect $KCODE
- String#match tries to call #to_str if it can before throwing an error
-
-commit 9409ace6d3e97946d10f9f7fcefa69ebcae43c47
-Author: Yehuda Katz <wycats@gmail.com>
-Date: Thu Sep 20 16:55:11 2007 -0700
-
- String#index works
-
- Tweaked spec because [[x,y], [x,y]].each{|x,y| ... } wasn't working
-
-commit 6a72e4c4defef170f53a31c930c112022934dbc4
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Thu Sep 20 15:22:28 2007 -0400
-
- Correct StringIO#reopen specs and implementation. Submitted patch for 1.8.x stable.
-
-commit 2b10dd99c2de4f97b5faa45060eba929d02052c4
-Author: Marcus Crafter <crafterm@redartisan.com>
-Date: Wed Sep 19 22:20:33 2007 +0200
-
- Implemented File.identical?
-
-commit 2c3c1fc7bd2f6365b28262cae46872eb0925c2e7
-Author: Marcus Crafter <crafterm@redartisan.com>
-Date: Wed Sep 19 21:48:13 2007 +0200
-
- Implemented File.link.
-
- Kudos to the Frankfurt Rails User Group! :)
-
-commit 0330b22006e39b5b173c78800f412831296de59a
-Author: Yehuda Katz <wycats@gmail.com>
-Date: Thu Sep 20 01:32:43 2007 -0700
-
- String#gsub works correctly
-
- There was a weird segfault issue which I tracked down to a use of gsub inside of gsub.
- I got things working by extracting that functionality into a mini-gsub for just that
- use case, but we should fix it.
-
-commit 6c825ce63ca0eb7d6f882a767ee0e6a597219883
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Wed Sep 19 22:14:31 2007 -0400
-
- Discover and fix an edge case in StringIO
-
-commit 6bd7adcfa115f11829a7efe8f526fabbb56d5c4c
-Author: Brian Ford <brixen@gmail.com>
-Date: Tue Sep 18 19:00:20 2007 -0700
-
- File.fnmatch(?) now passes all existing specs.
-
-commit f626f4199b88ca09a2ba75127270c0bec2ec2c86
-Author: Yehuda Katz <wycats@gmail.com>
-Date: Mon Sep 17 15:04:44 2007 -0700
-
- Adds a new match_all primitive
-
- * will be used as the base of regex-related String functions
- * is called match_all instead of scan because it's more primitive than Ruby's scan
-
-commit 0b42d4d2610ec36a4ae5e21c37d5b587f2b9dcf8
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Mon Sep 17 02:06:50 2007 -0400
-
- Avoid using $/ in IO#puts and StringIO#puts
- Additional StringIO specs and fixes for failures
-
-commit 75969031a57bea50e4a6450bbc9ae9e5adf76fa7
-Author: Brian Ford <brixen@gmail.com>
-Date: Sun Sep 16 18:26:29 2007 -0700
-
- Replaced File.fnmatch FFI version with custom version.
-
- The custom version is needed to be as compliant as possible
- with MRI on different platforms.
-
- Lots of fixups to File.fnmatch specs.
-
-commit 18d098062cb1b996a571a946740eea7c52421e12
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Mon Sep 17 01:11:45 2007 -0400
-
- Some failing sprintf specs and then the fixes for said failures
-
-commit 84f94ab41d72012e4ec3d0d236b183fd8a51fbe0
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Mon Sep 17 00:53:30 2007 -0400
-
- Additional StringIO specs and fixes for the failures that arose
-
-commit 9b44df55c682f239f036d46efe45edc2190a7345
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Sun Sep 16 12:55:27 2007 -0400
-
- Add StringIO spec for $/ global handling
-
-commit dfcba62eb69f88d373359c75c3fa7fe827e24c69
-Author: Yehuda Katz <wycats@gmail.com>
-Date: Sun Sep 16 00:43:41 2007 -0700
-
- Fixes string/equal_spec to pass
-
-commit 5026350a166b94fc5fffff70dae510fa2abf2094
-Author: Yehuda Katz <wycats@gmail.com>
-Date: Sun Sep 16 00:20:52 2007 -0700
-
- String#slice works
-
-commit a4f3aa09d3aeb8d2b0a640ca9f659a5945692e04
-Author: Brian Ford <brixen@gmail.com>
-Date: Sat Sep 15 13:49:42 2007 -0700
-
- Added ability to read/write to pointer to int or double in FFI.
-
- * Fixed Math.frexp to use pointer to int to return exponent.
- * Completed Math specs.
-
-commit 1a88ca4def8d7aa566a4254eebee3236a1359fc8
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Fri Sep 14 20:57:01 2007 -0400
-
- mini_rspec.expectation_messages.yak_shave!
-
-commit 64f53c8b40b3a80b41a2c27b4ac7255b7aad5f4d
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Fri Sep 14 02:18:16 2007 -0400
-
- Hopefully full StringIO coverage now
-
-commit 7cf9fe62bc9a5a00ae69ed3cac82e50012f3bb69
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Fri Sep 14 00:54:33 2007 -0400
-
- Yet more StringIO specs
-
-commit 92da0550bd32db984fbb54f105b9701867d4faf9
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Fri Sep 14 00:38:55 2007 -0400
-
- More StringIO specs
-
-commit 29826669197f44850d323910c7e60897e1ef7796
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Fri Sep 14 00:23:45 2007 -0400
-
- Beginnings of StringIO specs
-
-commit 0c19e3557125dd366ddd119a34451715bfe5e7a1
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Wed Sep 12 18:11:49 2007 -0700
-
- Fixed object allocation bug and Bignum spec
-
-commit e42a1b960f530a987527d8795a98b2de18fea824
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Thu Sep 13 19:19:03 2007 -0400
-
- Re-implement Module#define_method. Passes existing specs.
-
-commit a8b1a148e5fbfeb3c91558fd6caccc95006a5617
-Author: Charles Nutter <headius@charles-nutters-computer.local>
-Date: Thu Sep 13 03:55:15 2007 -0500
-
- Adding a non-compiling spec to case_spec and updating core.rba that didn't seem to get updated correctly.
-
-commit bbd682ba2e12ba5907fe2edf2f14f11fb110cac8
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Thu Sep 13 04:04:33 2007 -0400
-
- Fix anonymous 'rest' arguments
- Suppress stray STDOUT traffic from 'defined?'
-
-commit 8f11498019eb49a4dd8bf52c4361432ebb1175d5
-Author: Brian Ford <brixen@gmail.com>
-Date: Wed Sep 12 22:21:30 2007 -0700
-
- Updated CI process.
-
- * Changed bin/ci to generate an exclude file per file put
- in .spec directory.
- * Generated CI spec excludes files.
- * Updated .gitignore to not exclude .spec directory.
- * Moved the critical excludes file to spec/excludes.txt
-
-commit b736263ff325efabb907f300c1c69a2e63bd5620
-Author: Brian Ford <brixen@gmail.com>
-Date: Wed Sep 12 22:21:30 2007 -0700
-
- Updated CI process.
-
- * Changed bin/ci to generate an exclude file per file put
- in .spec directory.
- * Generated CI spec excludes files.
- * Updated .gitignore to not exclude .spec directory.
- * Moved the critical excludes file to spec/excludes.txt
-
-commit 58ff9428a2a20e93e3682f834e32f754ed2c47d4
-Author: Brian Ford <brixen@gmail.com>
-Date: Wed Sep 12 18:39:48 2007 -0700
-
- Fixed specs failing MRI.
-
-commit f54b1dffb9372e5cb1c71d93c67f2407fce0a1d0
-Author: Brian Ford <brixen@gmail.com>
-Date: Wed Sep 12 17:17:46 2007 -0700
-
- Fixes to specs failing MRI for hash, float, fixnum, file, enumerable.
-
-commit e1d359eec451a69deb67ffdedd09b86d00774cc2
-Author: Brian Ford <brixen@gmail.com>
-Date: Wed Sep 12 14:34:50 2007 -0700
-
- Fixes to Hash specs based on Ruby version differences.
-
-commit ee5eec5d32bb42fbf549068905ddebe215fbcf70
-Author: Brian Ford <brixen@gmail.com>
-Date: Wed Sep 12 08:53:47 2007 -0700
-
- Fixed failing specs in kernel, module, numeric, string.
-
-commit 4f0af824f132428762f1e06409ca16c1022867bc
-Author: Brian Ford <brixen@gmail.com>
-Date: Wed Sep 12 06:24:16 2007 -0700
-
- Added #platform and #version guards for specs.
-
-commit 355c602704cd402a1d7cbadc9b4d8fae0b34f1f4
-Author: Brian Ford <brixen@gmail.com>
-Date: Tue Sep 11 00:35:03 2007 -0700
-
- Misc changes to specs to cleanup after the breakup.
-
-commit 85336c6a83736b01d63b645baf0e7e18bb5ce569
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Sep 10 23:21:24 2007 -0700
-
- Converted exception, kernel, struct, object specs.
-
-commit e10bc8cbbaa26123724dad9f97f44d82e8cbf600
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Sep 10 21:48:15 2007 -0700
-
- Converted string and numeric specs.
-
-commit 8ec64d24811a7951756c840c98a66a7c7d2ae7c8
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Sep 10 18:35:18 2007 -0700
-
- Converted array and module specs.
-
-commit 2849f4a41b3fbda6c626d934bbf3d7476ea31848
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Sep 10 15:22:36 2007 -0700
-
- Converted enumerable, file, hash, process, regexp, thread.
-
- Fixed bin/mkspec to remove '=' from string for file name.
-
-commit ffa5328aa8ed7ea079c0cc8b4228ababa5919cf6
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Sep 10 13:16:14 2007 -0700
-
- Converted time and bignum specs.
-
-commit 7798952047471d28a8e12a796092c4df7ae002f2
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Sep 10 01:21:38 2007 -0700
-
- Converted range, math, matchdata, integer, float, fixnum, comparable, io.
-
-commit 423d85f4a7eb4b40d2eea83a462f5c38c4a6aee3
-Author: Brian Ford <brixen@gmail.com>
-Date: Sun Sep 9 23:43:14 2007 -0700
-
- Added dir and files for ENV. Converted true, false, nil, symbol, process.
-
- Added .spec to .gitignore.
-
-commit 8274bdcd0c747c21806065feb743e7794231f48f
-Author: Brian Ford <brixen@gmail.com>
-Date: Sun Sep 9 22:40:37 2007 -0700
-
- Converted kernel specs.
-
-commit bc1917d630d7938b62a866c3825dfa08e5ec99e1
-Author: Brian Ford <brixen@gmail.com>
-Date: Sun Sep 9 21:57:03 2007 -0700
-
- Initial create of spec/core subdirectories and files.
-
- Updated bin/mkspec to exclude Exception subclasses and
- OptionParser (which is in Object.constants because of
- the script requiring it). Also normalize TrueClass etc.
- to directory 'true'.
-
-commit b941eceb681c57d23d35f952b11b2a2d3a1ea4dd
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Thu Sep 13 01:00:22 2007 -0400
-
- Add a minimal spec for the 'undef' keyword
-
-commit 3af389594f3828763a85d8eef65f773b183e1b46
-Author: Charles Nutter <headius@charles-nutters-computer.local>
-Date: Wed Sep 12 19:33:36 2007 -0500
-
- Adding a bunch of default argument specs to language/def_spec.
-
-commit 6b4936e834a2814602be54f01e08dcdc1f9433b5
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Sun Sep 9 16:58:35 2007 +0200
-
- Another fix for multiple mock expectations on the same method.
-
-commit f686ff256289263eb473249dd734cf2214c41cc2
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Sun Sep 9 16:13:53 2007 +0200
-
- Mocks now support multiple expectations of the same method with different arguments.
-
-commit 860e0d08adc8cdee9ac4d9ff3bd0e30d5d3aaa49
-Author: Brian Ford <brixen@gmail.com>
-Date: Sat Sep 8 02:36:19 2007 -0700
-
- Added to critical-excludes and ci-excludes. bin/ci -f s -C runs to completion.
-
- rake build:core compiled string.rb, so checking in core.rba.
-
-commit c9c79c910a57e5628d1743f3b440c0066875500e
-Author: Brian Ford <brixen@gmail.com>
-Date: Fri Sep 7 23:24:44 2007 -0700
-
- Added Math methods using FFI.
-
- Added Kernel.coerce_to and rewrote Float(), Integer(),
- Array(), and String() with it. Float() needs to be fixed
- to raise on strings like rb_cstr_to_dbl does.
-
- Fixed -C options for bin/ci and bin/mspec.
-
-commit b8d8b8c8475fde1ce3519e29788a34780dffae8c
-Author: Yehuda Katz <wycats@gmail.com>
-Date: Fri Sep 7 19:40:02 2007 -0700
-
- Fixes String#<<
-
- * Added taint if other has taint
- * Fixed 10 spec failures
-
-commit b0b85547ab9dd16ba88a75c64a91c3ae0d079b27
-Author: Yehuda Katz <wycats@gmail.com>
-Date: Fri Sep 7 15:36:44 2007 -0700
-
- Added bus error to critical-excludes
-
-commit ed13a10112d0a262a48c8e5db7d1eaaa3e076e55
-Author: Yehuda Katz <wycats@gmail.com>
-Date: Fri Sep 7 15:19:51 2007 -0700
-
- String specs work in 1.8.6 MRI
-
-commit 6fc507c96e990139c311900c73c7e31447879071
-Author: Brian Ford <brixen@gmail.com>
-Date: Fri Sep 7 12:03:09 2007 -0700
-
- Changed VERSION and RUBY_VERSION to shadow MRI (currently 1.8.6).
-
- Added RBX_VERSION (currently 0.8.0). Updated loader -v to display
- RBX_VERSION and RUBY_VERSION and truncated BUILDREV.
-
- Enabled before|after(:all) for mini_rspec.
-
-commit 8ce602f80b35f5859c58730968a9a7053a87bd59
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Fri Sep 7 11:16:16 2007 -0400
-
- Array#uniq, #uniq! simplified. 72 failures.
-
-commit 38f271a1b7d49074d8db9285553756fb75ffe78b
-Author: Yehuda Katz <wycats@gmail.com>
-Date: Fri Sep 7 11:23:36 2007 -0700
-
- define_attr added to subtend
-
-commit 843706d585334c30943c8bbdd3ef6ca22297d42d
-Author: Yehuda Katz <wycats@gmail.com>
-Date: Fri Sep 7 10:48:51 2007 -0700
-
- Added rb_cstr2inum to subtend
-
-commit 97a22e2144b623a62780995333d65986c98c4ba2
-Author: Yehuda Katz <wycats@gmail.com>
-Date: Fri Sep 7 10:42:30 2007 -0700
-
- Added rb_const_defined to subtend
-
- It also seems that my fixture for require didn't make it in; adding that as well
-
-commit 0ac9ec2b0f381bf2fb3a36cd0b6f30748771e818
-Author: Yehuda Katz <wycats@gmail.com>
-Date: Fri Sep 7 10:21:28 2007 -0700
-
- Added check_*_type to subtend
-
- * check_array_type
- * check_string_type
- * check_convert_type
-
-commit b2bf1c44fa7c2663e6fc0b27127aa4f5e38e073f
-Author: Yehuda Katz <wycats@gmail.com>
-Date: Fri Sep 7 09:45:03 2007 -0700
-
- Added rb_attr_get to subtend
-
-commit 81605662ab8acc5a50536f1fc613e7d24e142df1
-Author: Yehuda Katz <wycats@gmail.com>
-Date: Fri Sep 7 00:27:38 2007 -0700
-
- int2inum added to subtend as well as INT2NUM
-
-commit e80084e6b245173c17403891c65d86db1e6b3022
-Author: Yehuda Katz <wycats@gmail.com>
-Date: Fri Sep 7 00:02:06 2007 -0700
-
- rb_str_split added to subtend
-
-commit 90f1fa95825caa8b21e147248d1a7d999579b937
-Author: Yehuda Katz <wycats@gmail.com>
-Date: Thu Sep 6 23:51:56 2007 -0700
-
- rb_require in subtend added
-
-commit 5bb87f516b2a26f77a864a15636331102d6d8499
-Author: Yehuda Katz <wycats@gmail.com>
-Date: Thu Sep 6 22:58:29 2007 -0700
-
- rb_to_id added
-
-commit e0532b3fb62089da7b7362ec2232997878a1221d
-Author: Yehuda Katz <wycats@gmail.com>
-Date: Thu Sep 6 22:31:30 2007 -0700
-
- Added specs
-
-commit 75f7a1d2b37067f55099dd117e8fcd905baa748d
-Author: Yehuda Katz <wycats@gmail.com>
-Date: Thu Sep 6 21:59:12 2007 -0700
-
- string subtend fixes
-
- * rb_str_cmp added
- * rb_str_cat fixed with working spec
-
-commit f058cea3e5291c349f5b2b1cfbdad4d734240f95
-Author: Yehuda Katz <wycats@gmail.com>
-Date: Thu Sep 6 21:34:52 2007 -0700
-
- added rb_define_const
-
-commit ec7ca7f45ef32794afb919851e4bfd5e8d7aa46d
-Author: Yehuda Katz <wycats@gmail.com>
-Date: Thu Sep 6 21:03:44 2007 -0700
-
- rb_include_module added
-
-commit 5b3471544508e973ba6afbd16daf47f5796f8b30
-Author: Yehuda Katz <wycats@gmail.com>
-Date: Thu Sep 6 20:41:09 2007 -0700
-
- float_new added and some functions missing in ruby.h added
-
-commit cd2af0bae996a4addfe23baa0558125a8a5523e7
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Thu Sep 6 17:09:06 2007 -0700
-
- Fixed subtend. Added diagram of the context chain.
-
- NMCs (NativeMethodContext) now use the proper context stack.
- The stack maintenance was all screwed up when calling in and out of
- native methods, which was the source of a few problems.
-
-commit da5f9e6f942c11d906760e952debae4d05b3d872
-Author: Brian Ford <brixen@gmail.com>
-Date: Tue Sep 4 22:26:48 2007 -0700
-
- Added load-order dependency generation to rake build:(core|platform) task.
-
- Added 'depends on:' declarations to kernel/platform and kernel/core files.
-
- Updated ci-excludes.txt to reflect recent spec checkins.
-
-commit 7b1ca6f305e33b34a99e8c9e049843a76cceeca7
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Sun Sep 2 21:29:49 2007 -0400
-
- Add more 'alias' specs. Show singleton methods in 'public_methods' output.
-
-commit 5c0b5fcb2a0c9f47a04e6a5d5027484224d0a942
-Merge: 4896039... 01c2126...
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Sun Sep 2 18:58:53 2007 -0400
-
- Merge branch 'master' of git@git.rubini.us:code
-
-commit 48960394ab7f36ccd1b18609677b40721c30d7a2
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Sun Sep 2 18:57:29 2007 -0400
-
- Add some 'alias' specs that fail on rbx and pass on MRI
-
-commit 01c2126b705327d99aa183d51dc014169e8b4e07
-Merge: 04602c6... b6d92ec...
-Author: Florian Gross <flgr@ccan.de>
-Date: Sun Sep 2 19:45:25 2007 +0200
-
- Merge branch 'master' of git@git.rubini.us:code
-
- Conflicts:
-
- spec/core/string_spec.rb
-
-commit 04602c6756a9199b64e7d909c01dc995b25fa8a7
-Author: Florian Gross <flgr@ccan.de>
-Date: Sun Sep 2 19:32:47 2007 +0200
-
- * New specs for String#tr_s(!) and upcase(!)
- * Improved specs for String#capitalize!, downcase(!) and swapcase
-
-commit c94f83b20f7b11dc48c523c84de59b9ac6f76cce
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Fri Aug 31 23:15:07 2007 -0400
-
- Array#reverse_each, #rindex fixed and cleaned. 80 failures.
-
-commit f531f812f87283b950c62648e3cf08a7400c2779
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Fri Aug 31 22:03:05 2007 -0400
-
- Array#replace fixed, specs. 88 failures. * Disabled specs for #initialize_copy which is private.
-
-commit 1656b8a04a40bc5a43adec88ffd1480d9da6ba28
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Fri Aug 31 11:50:56 2007 -0400
-
- Array#reject, #reject!, specs fixed and cleaned * Added spec to check #reject returning Array and corrected implementation.
-
-commit e1c499c6feafc19788addd098a6da052904cb09c
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Fri Aug 31 11:25:45 2007 -0400
-
- Fixed logic in Array#rassoc, specs. 91 failures.
-
-commit da79b116d3fdc5fd4cd04f5ad1ad44b2c269ad77
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Fri Aug 31 10:38:39 2007 -0400
-
- Array#push checks frozenness, specs. 92 failures.
-
-commit 290aa6fe561453821f59be3fa92695d0b0d77c04
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Fri Aug 31 10:26:25 2007 -0400
-
- Uncommented most of Array#pack specs. * float -> int conversions still hang both C and c and are therefore disabled.
-
-commit 885f2522244c1792f45260194aba085028d5c919
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Fri Aug 31 09:59:30 2007 -0400
-
- Fixed logic errors in Array#assoc, Array#include? * Both, contrary to docs, compare elem == obj, not the other way around.
-
-commit d825038a409f4d931e80736e2de49ff0752857a9
-Author: Brian Ford <brixen@gmail.com>
-Date: Fri Aug 31 00:12:06 2007 -0700
-
- bin/ci supports options for separately running spec files
-
- Use bin/ci -s to separately process each spec file. Use
- bin/ci -m to run all the spec files in a single VM process.
- -s is the default for --create, but -m is the default for
- everything else.
-
- Updated ci-excludes.txt and critical-excludes.txt.
-
-commit 7dfe5cb7936051685a2c79effb6295b9aa179810
-Author: Brian Ford <brixen@gmail.com>
-Date: Thu Aug 30 23:44:28 2007 -0700
-
- Updated ci-excludes.txt to only exclude failing specs.
-
-commit fb09f0a7a6969adffd8d99bf869eb50c91eef097
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Thu Aug 30 20:31:20 2007 -0400
-
- Fix object and array specs that failed under MRI
-
-commit 6fb73244537b61a20538c1f3d5a060a40a358be5
-Author: Yehuda Katz <wycats@gmail.com>
-Date: Thu Aug 30 17:08:12 2007 -0700
-
- Fixed two typos in the subtend string specs
-
-commit 00256f41d4e3ebfcdafdc25e27bfbf4bc7d3de3f
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Thu Aug 30 11:19:09 2007 -0400
-
- Array#last fixed. 48 failures.
-
-commit 887d41c64c6bdff693f6ecd8d3078f8453669648
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Thu Aug 30 11:02:27 2007 -0400
-
- Array#insert, specs corrected. 49 failures.
- * Fixed Array#insert
- * Re-complianced frozenness specs for Array#inspect.
-
-commit 1bc536e1128bc76b1c9efae593340f67bdcb5fb5
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Thu Aug 30 10:42:05 2007 -0400
-
- Array#indexes correct implementation. 51 failures.
- * Array#indexes and #indices is now correct although
- both methods are deprecated in favour of #values_at.
-
-commit 5de09c707b1ce43bf689e8ded9ea19784e77a49e
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Thu Aug 30 10:09:27 2007 -0400
-
- Array#include? implemented. 53 failures.
- * Replaced use of Enumerable#include?
- * Re-complianced to a simpler Array#include? spec to
- avoid implementation-dependedness.
-
-commit 14ca6c2533764eea508b24b0ec89475a7aae5e94
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Thu Aug 30 09:32:40 2007 -0400
-
- Array#hash spec compliance change. 54 failures.
- * Disabled an Array#hash spec for Rubinius because it
- relies too much on implementation details.
-
-commit fc4f392fa7fba88b36bfdec61db3acaa1f1fadc2
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Thu Aug 30 00:42:03 2007 -0400
-
- Array#flatten, #flatten!. Improved Array specs. 384 ex, 55 failures.
- * Array#flatten, #flatten! implementation improved, they
- also work recursively now.
- * Re-enabled Array#flatten, #flatten! specs and the
- recursive test for Array#inspect.
-
-commit efeaa622994e9868b9324247b0ff1fd5743792ac
-Author: Yehuda Katz <wycats@gmail.com>
-Date: Wed Aug 29 23:29:36 2007 -0700
-
- A series of rb_str functions in subtend, plus fixes to some of the tests earlier committed
-
-commit e4f5281148799ed716065c489d384a42d208290d
-Author: Yehuda Katz <wycats@gmail.com>
-Date: Wed Aug 29 19:16:26 2007 -0700
-
- rb_str_append() added
-
-commit a05c376478f7407da4e0aa2a6a7e3de98176a63b
-Author: Yehuda Katz <wycats@gmail.com>
-Date: Wed Aug 29 13:25:17 2007 -0700
-
- Updated subtend array functions
-
- * rb_ary_reverse() added
- * tests added for rb_ary_join() and rb_ary_reverse()
-
-commit 779fb97c35b78b9749cbb118fcb555096957e4c6
-Merge: 2793a99... e17987e...
-Author: Yehuda Katz <wycats@gmail.com>
-Date: Wed Aug 29 12:40:33 2007 -0700
-
- Merge branch 'master' of git@git.rubini.us:code
-
-commit 2793a9917f8f5cc2f0fc14ba605cec499532e680
-Author: Yehuda Katz <wycats@gmail.com>
-Date: Wed Aug 29 12:40:21 2007 -0700
-
- Slightly improved rb_ary_pop() test
-
-commit c196c60b6cd32c85b18bdab31ee000cf097309b5
-Author: Me <rue@meow.kittensoft.org>
-Date: Tue Aug 28 23:49:46 2007 -0400
-
- Array#fill fixed, cleaned up. 375 examples, 59 failures.
-
-commit 7736413f262357479c2f3354a73533fd89b3c9a6
-Author: Yehuda Katz <wycats@gmail.com>
-Date: Tue Aug 28 17:54:28 2007 -0700
-
- added rb_ary_join() to subtend
-
- Trying to get tests working but it's hard to see if I'm correct without the ability to run them.
- I'll take care of making sure there are passing tests as soon as I can.
-
-commit 0effcaf3e948d80ae3ad17b33f0483313d85cdbe
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Tue Aug 28 00:24:41 2007 -0400
-
- Array#fetch, specs, slightly cleaned array.rb. 62 failures.
- * Array#fetch uses to_int.
- * Specs for Array#fetch check for correct block var.
- * Removed extra comments from array.rb.
- * Removed old implementations from array.rb.
-
-commit 51737d35c24f853a23e14f7a227138d4d0f6b457
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Aug 27 21:46:30 2007 -0700
-
- Added failing File specs to ci-excludes
-
-commit a195970e2b2d34fa4388e6a72e91ada13b4b0d32
-Author: Marcus Crafter <crafterm@redartisan.com>
-Date: Tue Aug 28 09:20:33 2007 +1000
-
- Ensure exists? is prefixed by File.
-
-commit 804b6f3358c1bb73492beaa0e978d4df8dbac138
-Author: Marcus Crafter <crafterm@redartisan.com>
-Date: Tue Aug 28 00:18:41 2007 +1000
-
- Minor refactoring work on file spec.
-
- Removed duplicated constant tests.
-
-commit ef18eaaaa1a79b964667900b19f3f10e1b67032b
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Aug 27 14:25:06 2007 -0700
-
- Updates to enable bin/ci to run to completion.
-
- Changed mini_rspec to not use File.open with a block to work
- around IO#read failing to catch EOFError.
-
- Commented out object_spec.rb specs that need to be completely redone.
-
- Updated spec/reports exclude files to enable bin/ci to work.
-
-commit 505617b26829d5f489c4488ed934a6dc720f64f0
-Author: Florian Gross <flgr@ccan.de>
-Date: Sun Aug 26 22:53:42 2007 +0200
-
- A few new specs for String#sum, #to_i, #to_s, #to_str, #tr and #tr!
-
-commit a6a24a97dce2a4072a6ea17e48259b76f0c3681a
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Sun Aug 26 02:52:55 2007 -0400
-
- Array#delete, Array#delete_at, Array#delete_if. 63 failures.
- * Fixed the three delete* methods, they still need clean-up
- * The specs reflect difference in frozen handling for rbx and r18
-
-commit 063f8c25d45e0934bca236ecb8af36dcb517187f
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Sun Aug 26 02:26:15 2007 -0400
-
- Array#concat fixed. 69 failures.
- * Array#concat checks frozenness and cleaned up
- * Improved specs for #concat
-
-commit a9f3593593948cf72d94712765d05bfcc27f2e78
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Sun Aug 26 01:53:05 2007 -0400
-
- Array#dup, Array#compact, Array#compact!. 71 failing.
- * Array#dup properly returns subclass
- * Array#compact(!) improved to pass specs
-
-commit 7be3bc12ea2e5432e442cb44103b4b1c6d981163
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Sat Aug 25 23:57:38 2007 -0400
-
- Array#clear, Array#frozen?. 372 examples, 73 failures. * Array#frozen? checks for sorting freezes * Array#clear fails on frozen Arrays
-
-commit 5c958242fe25f8a18cd8d315f81fb3db80dc7a40
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Sat Aug 25 17:19:23 2007 -0400
-
- Array#==, Array#assoc improvements. 75 failures
- * Cleaned up Array#==
- * Array#assoc processes correctly
-
-commit f82f8a300ee394f9f1038cc84de1cf6b132d7ef5
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Sat Aug 25 16:24:22 2007 -0400
-
- Array#* improved. 371 specs, 81 failures
- * Array#* processes to_int and to_ary correctly and forwards
- to #join when needed.
-
-commit 91e16f06d5b5b16f1fa7ffc1d3673d7f1c681587
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Sat Aug 25 15:54:12 2007 -0400
-
- Array#join can process recursive Arrays.
- * Rubinius cannot create recursive Arrays so this is somewhat moot.
-
-commit 2d7427bb638f1af6d7437beed4beafde5274dbdf
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Sat Aug 25 13:46:45 2007 -0400
-
- Array#|, better Array#&. 371 examples, 86 failures.
- * Array#& explicitly uses #eql? semantics
- * Cleaned up Array#|, uses to_ary
-
-commit 2b8707466f763662d52efaeab71b4789b132bb40
-Merge: c61b1e5... 76be87f...
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Sat Aug 25 12:41:06 2007 -0400
-
- Merge branch 'array'
-
-commit 76be87f74d352d79425e9c46d3df55678257fda9
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Sat Aug 25 12:28:32 2007 -0400
-
- Array#<< improvements. 371 examples, 89 failures.
- * Specced and fixed resizing bug in Array#<<
-
-commit c61b1e54cc11c297b9e9a9eca70cb6a354ed21d9
-Merge: 3618a8b... c6cc98f...
-Author: Pedro Del Gallego Vida <pedro@la-vaca-roja.(none)>
-Date: Sat Aug 25 18:16:45 2007 +0200
-
- Merge branch 'master' of git@git.rubini.us:code
-
-commit 3618a8bc588588ef8fb0dcc4753bc42606b86c13
-Author: Pedro Del Gallego Vida <pedro@la-vaca-roja.(none)>
-Date: Sat Aug 25 18:16:05 2007 +0200
-
- Update object specs
- Update the object_spec.rb file
- * add more specs
- * refactor using it_behave_like
-
-commit 294e5aacda8a74a9d8f57d05bb433f2fadcd08f1
-Author: Eero Saynatkari <rubinius@projects.kittensoft.org>
-Date: Sat Aug 25 12:07:06 2007 -0400
-
- Array#[], modified parts of array_spec. 369 examples, 90 failures.
- * Array#[] passes its specs
- * Disabled some parts of array_spec while fixing Array. These
- will be re-enabled as soon as possible.
-
-commit 1369465aefcd1d50ddd268ba9af968c62137e2b2
-Author: Pedro Del Gallego Vida <pedro@la-vaca-roja.(none)>
-Date: Fri Aug 24 11:14:20 2007 +0200
-
- Array#new correct implementation
-
-commit e321427a52878ef9d9c7c04aa7c3c4f1e3a6c940
-Merge: bff7c05... 69c0407...
-Author: Pedro Del Gallego Vida <pedro@la-vaca-roja.(none)>
-Date: Fri Aug 24 11:14:20 2007 +0200
-
- Merge branch 'master' of git@git.rubini.us:code
-
-commit 07c7f93a64fc37f3cf94a0a2c272468d015a7fb3
-Author: Brian Ford <brixen@gmail.com>
-Date: Thu Aug 23 21:18:13 2007 -0700
-
- Converted Regexp specs to new describe style.
-
- Fixed String specs to be compatible with bin/completeness.
- Fixed bin/completeness to use dotted reporter instead of CI
- reporter since the latter no longer outputs summary info.
-
-commit 6776e1478fa7e78a0944a1ee59c55c3839f51ea4
-Author: Marcus Crafter <crafterm@redartisan.com>
-Date: Fri Aug 24 13:14:47 2007 +1000
-
- Added implementation of File.split and updated specs.
-
-commit 4053b9076b4b996f544095a75317453967723faa
-Author: Marcus Crafter <crafterm@redartisan.com>
-Date: Wed Aug 22 21:58:13 2007 +1000
-
- Added spec for mocking methods on a class
-
-commit 54cae1196db08f6a734c35079db8df62e491f300
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Thu Aug 23 17:38:40 2007 -0700
-
- Added more IO stuff and platform methods.
-
- I'm still a little unhappy with the input buffer situation.
- (ie, there is none.)
-
- Adds IO#sysread and IO#syswrite as well as a bunch of POSIX stuff.
-
-commit 12a755004c0a8a0319212965da61385738166f98
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Tue Aug 21 12:44:48 2007 -0700
-
- Beginnings of ftools spec, fix backtrace generation.
-
- Backtraces were failing to be properly built if the sender was a Block.
-
-commit bff7c05ce12c79ef111422ecf4525f1a65e7a5f0
-Author: Pedro Del Gallego Vida <pedro@la-vaca-roja.(none)>
-Date: Fri Aug 24 01:15:41 2007 +0200
-
- More specs dor enumerable
- * add inject, min, grep, find, detect, find_all, select
-
-commit ed9a8fefcc384bb6548a7f66bbafb97192ec8fd3
-Merge: 4ef0b9f... 8dd800e...
-Author: Arthur Schreiber <schreiber.arthur@gmail.com>
-Date: Thu Aug 23 11:01:25 2007 +0200
-
- Merge branch 'specs'
-
-commit 8dd800e8189f616dc54390c0ebf96c331de41230
-Author: schreiber.arthur@gmail.com <arthur@arthur-desktop.(none)>
-Date: Thu Aug 23 10:45:56 2007 +0200
-
- * Some more Module Specs.
-
-commit 0f414f56f9050d86011df75e7fd23428fe378996
-Author: schreiber.arthur@gmail.com <arthur@arthur-desktop.(none)>
-Date: Thu Aug 23 10:44:59 2007 +0200
-
- * Added :count => :any option to mock expectations
-
-commit 4ef0b9feddfebfd1b6177fce6e3a1a4077f4f098
-Author: Brian Ford <brixen@gmail.com>
-Date: Wed Aug 22 23:10:22 2007 -0700
-
- Updated exclusion list for CI specs.
- Updated rake spec:ci task.
- Changed ci spec run action to execute all specs in one process.
- Added guard on file specs to prevent compilation exception.
-
-commit c3b61b239fa6a02327e5651513986d998d826eaf
-Author: Brian Ford <brixen@gmail.com>
-Date: Wed Aug 22 21:48:08 2007 -0700
-
- Updated CI spec process to exclude specs failing on compilation.
-
- Added critical failures to enable running especially spec/core.
- Added failure guards to struct specs.
-
-commit f339a284c66357bc52749e5fe9c0d59bbbdc7ade
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Aug 20 22:31:56 2007 -0700
-
- Fleshed out bin/ci constructs for running specs.
-
-commit 4f750d59adfff6c1751372c0d2853778dc7ae16d
-Author: Pedro Del Gallego Vida <pedro@la-vaca-roja.(none)>
-Date: Tue Aug 21 22:40:33 2007 +0200
-
- * more enumerable specs
- * refactor to it_behaves_like
-
-commit 3c79d5cf67b40b945602d5c5fa77589e0d7bae2c
-Author: Pedro Del Gallego Vida <pedro@la-vaca-roja.(none)>
-Date: Tue Aug 21 20:52:16 2007 +0200
-
- update file_spec.rb
-
-commit b2a64089bffe5afb9148a665ecb6e70c3bc62b67
-Merge: 6865b97... 1b6a8a1...
-Author: Brian Ford <brixen@gmail.com>
-Date: Sun Aug 19 16:22:53 2007 -0700
-
- merge 1b6a8a157
-
-commit bf54767922eb8d494c683ed8d57c6ffb5164fc29
-Merge: 6c6032e... 37d71c9...
-Author: Brian Ford <brixen@gmail.com>
-Date: Sun Aug 19 15:24:21 2007 -0700
-
- merge from e83bcd022
-
-commit 05db33909c319231ac375812025ea2378710a299
-Author: Marcus Crafter <crafterm@redartisan.com>
-Date: Sun Aug 19 21:26:15 2007 +1000
-
- Add conditional when deleting a file in after(:each) block to prevent an exception if the file is missing.
-
-commit 138ab001175987cd38aff092a850e515745f9292
-Author: Marcus Crafter <crafterm@redartisan.com>
-Date: Sun Aug 19 21:18:22 2007 +1000
-
- Converted remaining context/specify spec's into describe/it, and followed class/method naming convention.
-
-commit 749b883d0260326573c581cc63eab67e1a4bc590
-Author: Marcus Crafter <crafterm@redartisan.com>
-Date: Sun Aug 19 20:23:11 2007 +1000
-
- Added implementation of exists? blockdev? chardev? zero? size size? writable_real? executable_real? readable_real? unlink delete and chmod using ffi where needed. Specs for most of these methods existed already, added specs for those that weren't. Fixed a few typos.
-
-commit ddcb14f9f2311ec843a1f1f8d2b3fa868384ff0d
-Author: Brian Ford <brixen@gmail.com>
-Date: Sat Aug 18 23:19:32 2007 -0700
-
- more misc changes to get ci specs working
- added alias for File.exists? and File.exist?
- added Dir.getcwd
- added empty File.delete
-
-commit afb252fd6170ed051e97f1911e5f1200414ebf98
-Author: Brian Ford <brixen@gmail.com>
-Date: Sat Aug 18 22:20:10 2007 -0700
-
- updated compiler specs.
-
-commit d0e6b658d9065b0fbc9180cd5d19139834f64f59
-Author: Brian Ford <brixen@gmail.com>
-Date: Sat Aug 18 21:04:18 2007 -0700
-
- changes to support better CI specs
- hat mini_rspec will take a filename as an exclude/include argument and read the actual excludes/includes from the file.
- added that mspec will take -o FILE to use an alternate to STDOUT for the spec reporter output.
- updated spec tasks. misc spec changes.
- added naive implementation of IO#each.
-
-commit 541bcb521a8ee589c7d28c095ad7ee1489af42db
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Fri Aug 17 19:30:05 2007 -0700
-
- Complete reorganization of bootstrap. Addition of kernel/platform. FFI fixed.
-
- New restrictions for meta-programming in core bodies (not in methods).
- kernel/platform is now where platform specific code, mainly related to FFI, lives.
- A bunch of FFI bugs have been fixed and it should be working much better now.
-
- FFI Note: you may now only specify :state as your first argument, and you must
- leave it off when you call the method (rather than passing nil like before).
-
-commit af245dfbc80ff942de62408e70db7499a798fb0a
-Author: schreiber.arthur@gmail.com <arthur@arthur-desktop.(none)>
-Date: Tue Aug 14 01:30:09 2007 +0200
-
- Forgot to add the autoloaded file for Module#autoload
-
-commit b946940f463028de067ef2e082c96fe431c94b0a
-Author: schreiber.arthur@gmail.com <arthur@arthur-desktop.(none)>
-Date: Tue Aug 14 01:09:10 2007 +0200
-
- Updated Module Specs
-
-commit 6cd6aa53a5d20c78941442f7e367ef8c7aee17c2
-Author: Brian Ford <brixen@gmail.com>
-Date: Fri Aug 10 00:14:09 2007 +0000
-
- converted array specs with a few edits.
-
-commit c075f7f70da2a029c69f3fff1f9caec419db64d5
-Author: Arthur <arthur@unknown>
-Date: Wed Aug 8 12:47:18 2007 +0000
-
- fix a small typo
-
-commit c7262df9ee1c2544890b001574c8cb0f8ae26a75
-Author: Brian Ford <brixen@gmail.com>
-Date: Wed Aug 8 01:24:25 2007 +0000
-
- converted exception specs. added #should_be_ancestor_of. use ExpectationNotMetError in mini_rspec like rspec does.
-
-commit f591e18978b73c508505db73f274f4bd69c372c5
-Author: Arthur <arthur@unknown>
-Date: Tue Aug 7 08:36:15 2007 +0000
-
- * String#to_str specs should actually use String#to_str
-
-commit 80f69571c5378d6bbb2e7a118ada00db66226797
-Author: Brian Ford <brixen@gmail.com>
-Date: Tue Aug 7 06:47:53 2007 +0000
-
- converted range specs.
-
-commit aca62d253a6b2df891ca4ec4b177ea95b621d636
-Author: Brian Ford <brixen@gmail.com>
-Date: Tue Aug 7 03:52:46 2007 +0000
-
- fixed mini_rspec -e option, allows multiples. converted hash specs.
-
-commit 928c9a392102fa7b7945f332480a7477ec203467
-Author: Florian Gross <florgro@gmail.com>
-Date: Mon Aug 6 22:04:16 2007 +0000
-
- New specs for String#swapcase(!), to_f, to_i, to_str, to_sym
-
-commit 6d0a6b0051a55af32743d9d98d6425489a622ebe
-Author: Pedro Del Gallego <pedro.delgallego@gmail.com>
-Date: Mon Aug 6 21:58:55 2007 +0000
-
- * more specs for File.open. Specs for File.truncate
-
-commit 8b19b683a8593b4dd5024841d8023df827a44875
-Author: Brian Ford <brixen@gmail.com>
-Date: Sun Aug 5 23:39:36 2007 +0000
-
- fixed completeness to not over match methods. converted comparable specs.
-
-commit c6f4d90df72b103884fa5470a433f5513d2c524d
-Author: Pedro Del Gallego <pedro.delgallego@gmail.com>
-Date: Sun Aug 5 22:52:17 2007 +0000
-
- * more specs for File.open. Some of them are plataform dependent
-
-commit 38bfff9d014b90409e272ddf041dc63f53d48f5d
-Author: Brian Ford <brixen@gmail.com>
-Date: Sun Aug 5 22:45:31 2007 +0000
-
- converted bignum specs. misc cleanup.
-
-commit 14890b68c447731417ce53ca2e4310175e39b440
-Author: Florian Gross <florgro@gmail.com>
-Date: Sun Aug 5 22:00:04 2007 +0000
-
- Small spec fix
-
-commit b6c3cfca5cf1b2cb85dc216180ad21a6bf653a10
-Author: Brian Ford <brixen@gmail.com>
-Date: Sun Aug 5 17:20:32 2007 +0000
-
- converted time specs. according to completeness, need to spec 9 more methods.
-
-commit 8829cf7e94ec0434f642fafa7dbf117a860045b9
-Author: Brian Ford <brixen@gmail.com>
-Date: Sun Aug 5 07:53:47 2007 +0000
-
- more converted specs.
-
-commit 5bf174780e893b7ee9b82b6ca3964db7cad84e30
-Author: Brian Ford <brixen@gmail.com>
-Date: Sun Aug 5 07:08:08 2007 +0000
-
- converted fixnum specs to describe per method.
-
-commit 88023701a88c1113e4874c193d26c6bf21fad383
-Author: Brian Ford <brixen@gmail.com>
-Date: Sat Aug 4 22:19:18 2007 +0000
-
- misc noise cleanup in specs. use bin/completeness to find missing specs rather than warns.
-
-commit 3d960a021cb9ac2bdc2a204f94b4f024f3ef60a4
-Author: Brian Ford <brixen@gmail.com>
-Date: Sat Aug 4 22:06:12 2007 +0000
-
- fixed completeness to pass correct spec example string for class methods. changed float specs to describe per method.
-
-commit 8a7abb5996e5bdf8b9d6c5884e0e0d8ae73d060e
-Author: Brian Ford <brixen@gmail.com>
-Date: Sat Aug 4 20:10:38 2007 +0000
-
- beginning of a completeness reporter. use 'bin/completeness -t ruby' to report on the completeness of the specs against MRI. use 'bin/completeness' to report on the completeness of rbx relative to MRI. use -t target for other implementations. updated some specs to the 'describe Class#method' style.
-
-commit 463f13be4462e22bc3f4491a475658624c5832ab
-Author: Pedro Del Gallego <pedro.delgallego@gmail.com>
-Date: Sat Aug 4 17:09:25 2007 +0000
-
- * fix some bugs in bignum_spec
- * changed the File::Foo.shouid == bar assert to defined?(File::Foo).should == "constant". The specific value dependence on OS.
-
-commit 989d72394f1e175b058f55ccf3e60f09a2c76401
-Author: Brian Ford <brixen@gmail.com>
-Date: Sat Aug 4 04:15:01 2007 +0000
-
- fixed mini_rspec specdox reporter to not output describe message until examples are executed. fixed specdox and dotted reporter to distinguish between errors and failures.
-
-commit f98fe7f211e5784a35e99643fb52c9350b20d7ae
-Author: Florian Gross <florgro@gmail.com>
-Date: Sat Aug 4 01:40:52 2007 +0000
-
- More compatibility and a few small fixes
-
-commit c78ba9f96d7d4d229d6b1b1b11cf314fb5a0271d
-Author: Florian Gross <florgro@gmail.com>
-Date: Sat Aug 4 00:40:42 2007 +0000
-
- Compatibility for USE_RSPEC=1, sanity, some clean-up
-
-commit 761d05b5cbd92339f9d02e65d005a65c5155618e
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Fri Aug 3 21:49:26 2007 +0000
-
- * Compiler and Normalizer fixes for method definitions without bodies
-
-commit ad7abe4d61171f9650d08b277d45c7f680f37950
-Author: Brian Ford <brixen@gmail.com>
-Date: Fri Aug 3 17:07:19 2007 +0000
-
- fixed mini_rspec shared behavior to be compatible with rspec.
-
-commit 1e1ccb902d11547e9f67db82c31a5898e6227d67
-Author: Brian Ford <brixen@gmail.com>
-Date: Fri Aug 3 16:39:07 2007 +0000
-
- added an implementation of shared behavior for mini_rspec. altered Array#[] and Array#slice specs to use shared behavior.
-
-commit 7697b2ae3db6ed1d8697010a7e0f52f8e3587c8a
-Author: Brian Ford <brixen@gmail.com>
-Date: Thu Aug 2 20:41:43 2007 +0000
-
- added SpecRunner class to mini_rspec to properly encapsulate behavior. added --example option to specify a regexp to match examples to execute.
-
-commit b80bb3d295d3648988b15a29553189f219d8ac0a
-Author: Pedro Del Gallego <pedro.delgallego@gmail.com>
-Date: Thu Aug 2 15:56:07 2007 +0000
-
- * added specs for file_spec
-
-commit c277fd3de82678f055693422af19c3f45ffc2a88
-Author: Florian Gross <florgro@gmail.com>
-Date: Thu Aug 2 00:46:27 2007 +0000
-
- mspec: Add -x option for excluding specs by RE
-
-commit aa53967c694ed7621aa1a8a8b542d067d9e58925
-Author: Florian Gross <florgro@gmail.com>
-Date: Thu Aug 2 00:05:53 2007 +0000
-
- New specs for String#succ(!)
-
-commit eafa5b0fd43168b4ae649b145f9528f7deae3aa7
-Author: Florian Gross <florgro@gmail.com>
-Date: Wed Aug 1 22:59:38 2007 +0000
-
- New specs for String#sub(!)
-
-commit 3406e64032251a2a9849da3f6c27d872dd339175
-Author: Florian Gross <florgro@gmail.com>
-Date: Wed Aug 1 22:17:18 2007 +0000
-
- New specs for String#squeeze(!) and String#strip(!)
-
-commit fa4d66576528725085ef47cca27c5c85c55b3150
-Author: Brian Ford <brixen@gmail.com>
-Date: Wed Aug 1 21:08:26 2007 +0000
-
- added Object#(public|private|protected)_methods and Module#(public|private|protected)_instance_methods. added Tuple#first, last.
-
-commit 4ca071ba4a48aa984308e0ba9448718a6e214d7a
-Author: Brian Ford <brixen@gmail.com>
-Date: Tue Jul 31 20:56:37 2007 +0000
-
- Some Object#methods et al specs.
-
-commit 67be404ac0714ec01c1c92c77465915d90fd794b
-Author: Florian Gross <florgro@gmail.com>
-Date: Tue Jul 31 18:41:54 2007 +0000
-
- Renamed variables_spec.rb to assignment_spec.rb
-
-commit c0187db3e51297dfffabebe9acb6d6321bd04578
-Author: Florian Gross <florgro@gmail.com>
-Date: Tue Jul 31 18:22:41 2007 +0000
-
- New specs for String#split
-
-commit 06cb5ab7c39866c99bb8d9a5fbb678f2f8a19cf2
-Author: Brian Ford <brixen@gmail.com>
-Date: Sun Jul 22 06:47:54 2007 +0000
-
- Removed the .rbc files from externals dir and set svn:ignore. Added Tuple specs, fixed a couple small problems with Tuple. Modified mspec to pass -I, -r to the target; added -n RUBY_NAME to affect which specs are run. Added hashi dir as an experiment to implement a bootstrap that could be run on e.g. MRI or JRuby to allow the core libs to be run and tested against the specs.
-
-commit 567d4f710bc232fc9223972e22a7d92e4abe940d
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Tue Jul 17 17:49:53 2007 +0000
-
- Stack allocated lvars, GC fixes, compiler changes, oh my!
-
- This is a biggy (too big in fact). It started as a change to allow
- arguments to be accessed directly from the stack, and turned into a
- monster.
-
- Arguments and some lvars can now be accessed directly from the stack,
- making them cheaper to create and use. This turned out to expose
- a large number of bugs in the VM related to stack access, as well
- as some in the GC.
-
- The big GC change here is that the mark/sweep GC is actually run now,
- as opposed to before when it would just allocated more and more memory
- (the source of memory issues I suspect).
-
-commit 564ac024e14a790f4a3d257ddf1d9fa0cb93ee3b
-Author: Florian Gross <florgro@gmail.com>
-Date: Tue Jul 17 00:20:52 2007 +0000
-
- $~ specs all over the place;
- Revised % format string specs (match MRI trunk);
- Revised hex and oct specs (match MRI trunk);
- Merged slice together with [];
- New specs for scan and slice!
-
-commit 2389eb4b36d86732dbb621be1cad3edca0e36aa5
-Author: Pedro Del Gallego <pedro.delgallego@gmail.com>
-Date: Mon Jul 16 09:26:20 2007 +0000
-
- * added specs for file_spec
-
-commit a6453b6184353633d14c271533c2e2af7a6c4b12
-Author: Florian Gross <florgro@gmail.com>
-Date: Sun Jul 15 17:53:58 2007 +0000
-
- A few specs for char numbers outside of 0..255;
- A few specs for modifying strings while iterating;
- New specs for hex, index, initialize(_copy), ljust, lstrip(!), match, next(!), oct, replace, reverse(!), rindex, rjust, rstrip(!);
- Small additions, fixes & refactoring
-
-commit 217dd5dae127c146559dd1512edac23a94565ae9
-Author: Florian Gross <florgro@gmail.com>
-Date: Sat Jul 14 23:52:52 2007 +0000
-
- Taintedness specs all over the place;
- String subclass specs for String#%;
- Range subclass specs for access methods;
- str[idx, count] = str specs (contributed by John Lam);
- New cases for capitalize(!) / center / gsub(!);
- Refactoring
-
-commit b8b0c3dd380335260c3870934ca51dce736ce15d
-Author: Florian Gross <florgro@gmail.com>
-Date: Sat Jul 14 23:39:38 2007 +0000
-
- Added custom range subclass cases for access methods
-
-commit 558552ec549fd605bed2c8f5c384e8c944e780a2
-Author: Pedro Del Gallego <pedro.delgallego@gmail.com>
-Date: Fri Jul 13 14:40:15 2007 +0000
-
- * added cases for file_spec
-
-commit 5218708c630bd8a631522a00aa6cba4e91cbec54
-Author: Pedro Del Gallego <pedro.delgallego@gmail.com>
-Date: Fri Jul 13 13:36:53 2007 +0000
-
- * added cases for file_spec
- * refactoring numeric_spec.rb
-
-commit 3e9dbc15a81950e55a15a7fcca0ab04a5fd5353f
-Author: Florian Gross <florgro@gmail.com>
-Date: Wed Jul 11 22:09:49 2007 +0000
-
- Add specs for to_* calls having correct semantics with method_missing() and respond_to?();
- Small clean up
-
-commit 23961f46af6f74d2d6b9019972e451a5ae12b728
-Author: Florian Gross <florgro@gmail.com>
-Date: Wed Jul 11 22:00:26 2007 +0000
-
- Add specs for to_* calls having correct semantics with method_missing() and respond_to?();
- Removed a few duplicate specs (probably resulting from a mismerge)
-
-commit 639c64ca0965ff79401989ca7dbde862815f13fb
-Author: Florian Gross <florgro@gmail.com>
-Date: Wed Jul 11 21:09:33 2007 +0000
-
- Add specs for to_* calls having correct semantics with method_missing() and respond_to?();
- Fixed String#%'s %E/e/f/G/g and %b/d/i/o/u/X/x specs to verify Kernel#Float / Kernel#Integer semantics instead of to_f / to_i ones
-
-commit e97879670bbc8425810a3c83f15a523066899a89
-Author: Arthur <arthur@unknown>
-Date: Tue Jul 10 20:04:48 2007 +0000
-
- * fix a typo
-
-commit 1e8890613a215c61ef90629b8b6023ac4612c499
-Author: Arthur <arthur@unknown>
-Date: Tue Jul 10 20:03:44 2007 +0000
-
- * Update Symbol Specs to the new format.
- * make Symbol#to_int show a warning as in MRI.
-
-commit 1262f24460463628c7cc4e275b7c814048937b57
-Author: Florian Gross <florgro@gmail.com>
-Date: Tue Jul 10 18:28:06 2007 +0000
-
- New specs for gsub() without block
-
-commit 0ba87f6edc183385551e4cf8c05212fadaf36427
-Author: Florian Gross <florgro@gmail.com>
-Date: Tue Jul 10 16:48:46 2007 +0000
-
- New specs for capitalize, chomp, concat, crypt, eql?;
- Added missing methods chop, chop!, count;
- Small improvements and refactoring
-
-commit 226942caef6bd217a13dc235a89c5ccf4a18f98b
-Author: Florian Gross <florgro@gmail.com>
-Date: Mon Jul 9 21:29:19 2007 +0000
-
- Strings specs for letters c through e
-
-commit e41c027537f1e4f8ea4b8b5b6fe90df9a21e3aff
-Author: Pedro Del Gallego <pedro.delgallego@gmail.com>
-Date: Fri Jul 6 17:13:39 2007 +0000
-
- * added 62 cases for file_spec
- * remove a bug from obejct#method_missing_spec that break the specs
-
-commit 06d2fd71b847e139a39ab3b7a132ab041a8d4c1e
-Author: Pedro Del Gallego <pedro.delgallego@gmail.com>
-Date: Wed Jul 4 16:05:21 2007 +0000
-
- * add 84 cases to the numeric_spec.rb
-
-commit b8d334f575322c65932279346bba61caead61555
-Author: Pedro Del Gallego <pedro.delgallego@gmail.com>
-Date: Wed Jul 4 10:28:27 2007 +0000
-
- * 14 cases for Object.method_missing
- * Add File#atime, File.atime, File#ctime, File.ctime, File.delete, File.executable?, File.executable?
-
-commit f2276130c4bf1894ffb6efb451203dcbfe9322bb
-Author: Charles Nutter <charles.nutter@sun.com>
-Date: Wed Jul 4 08:48:57 2007 +0000
-
- Added a spec for Process::times...it's not great, but it's something.
-
-commit f71bb57b3fc69c35d34abdb9959e27efb71bbdff
-Author: Charles Nutter <charles.nutter@sun.com>
-Date: Wed Jul 4 06:14:06 2007 +0000
-
- Fixes for #150; handle Time - Time correctly, don't assume it's a number of seconds.
-
-commit 895f1abdc0bfcdb213f97067704b1bb87a7e6d17
-Author: Florian Gross <florgro@gmail.com>
-Date: Tue Jul 3 17:01:27 2007 +0000
-
- New specs for casecmp
-
-commit 2aa7cb37925cd92c3b23d4a33a6d7bc7c2b66737
-Author: Florian Gross <florgro@gmail.com>
-Date: Tue Jul 3 14:07:56 2007 +0000
-
- New #[] and #[]=, capitalize and casecmp specs;
- Converted "should work" messages to "works" using a few regular expressions -- I'm still going through the file so bad replacements (if any) will be fixed
-
-commit 719ff3b8959d93d7da8165d6e5b44989afde92d7
-Author: Pedro Del Gallego <pedro.delgallego@gmail.com>
-Date: Tue Jul 3 00:33:59 2007 +0000
-
- * new NoMethodErro_spec.rb
-
-commit 5363324044fdc1457cfbf1b738dd931d3255b191
-Author: Florian Gross <florgro@gmail.com>
-Date: Mon Jul 2 23:58:09 2007 +0000
-
- Some more new specs
-
-commit fa1b3694e366bf087a8d1ac107257c38ce447251
-Author: Pedro Del Gallego <pedro.delgallego@gmail.com>
-Date: Mon Jul 2 20:29:20 2007 +0000
-
- * Add to_s with a base spec
- * Change foo.aMethod.to_s.should == "bar" with foo.aMethod.should_be_close(bar,TOLERANCE) because floats representation are plataform/implementation dependents, but not changed aBignum.to_s.should = ...
-
-commit 2a5c93afd4ddfef7c30de17c531f49849e9bb957
-Author: Pedro Del Gallego <pedro.delgallego@gmail.com>
-Date: Mon Jul 2 00:10:06 2007 +0000
-
- * Add Float::Constant specs
- * Change foo.aMethod.to_s.should == "bar" with foo.aMethod.should_be_close(bar,TOLERANCE) because floats representation are plataform/implementation dependents
-
-commit 7d3dcc24cb72d6548cf44d8519691f4cd7344801
-Author: Florian Gross <florgro@gmail.com>
-Date: Sun Jul 1 21:00:37 2007 +0000
-
- Heavily extended and refactored String#% specs;
- some cleanup
-
-commit 79ce6628df39d20d03efcd715ea42ba70ae9f03e
-Author: Florian Gross <florgro@gmail.com>
-Date: Sun Jul 1 20:59:38 2007 +0000
-
- Add support for MRI as :mri for failure() and similar methods
-
-commit 7e43cd858c0380aaf17dd7bacd8a24cef96bb309
-Author: Florian Gross <florgro@gmail.com>
-Date: Sun Jul 1 17:11:08 2007 +0000
-
- rindex terror specs
-
-commit e5b7cf88092cf59357124e3d8f35bc19f8ee589a
-Author: Florian Gross <florgro@gmail.com>
-Date: Sun Jul 1 01:14:09 2007 +0000
-
- Added a few new format specs (Most of these should probably be moved to Kernel::format later)
-
-commit a533693824608a03ab6a66882b607fecab3a3a75
-Author: Florian Gross <florgro@gmail.com>
-Date: Sat Jun 30 00:29:29 2007 +0000
-
- A few more specs, clean up and compatibility with MRI 1.9 head
-
-commit b9e8936562ec23db63879f9c127dadeadd8adf2e
-Author: Florian Gross <florgro@gmail.com>
-Date: Fri Jun 29 02:41:40 2007 +0000
-
- New specs for [], default(), delete(), shift(), yield argument count semantics and modifying hashes while iterating over them;
- Also removed some warnings and cleaned up the code a bit
-
-commit 72d1b106c1de4b00b9af184eb890e950854a9c77
-Author: Florian Gross <florgro@gmail.com>
-Date: Fri Jun 29 02:37:55 2007 +0000
-
- Adding spec for join passing along separator argument for nested arrays
-
-commit 6e2848b7143cd0ae47a7b9ac632a567df7fd30fc
-Author: Florian Gross <florgro@gmail.com>
-Date: Fri Jun 29 02:35:09 2007 +0000
-
- Adding message argument for should_raise()
-
-commit 31591886dde4bfd9b4e9de34c26960e45566b7ee
-Author: Brian Ford <brixen@gmail.com>
-Date: Wed Jun 27 05:15:15 2007 +0000
-
- Commiting (#147) math specs by pedro (modified for style, structure, and legibility).
-
-commit c7d623ee836363d0f3d443ba1c676ef0f86e34f7
-Author: Brian Ford <brixen@gmail.com>
-Date: Tue Jun 26 04:06:49 2007 +0000
-
- enhanced spec:ci to take a target on the command line, invoke like: SPEC_TARGET=jruby rake spec:ci. removed deprecated #only and #except from spec_helper.
-
-commit c13a588cb7e37c20ce7e8a9430d854cc51be7b00
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Jun 25 08:28:10 2007 +0000
-
- misc cleanups to specs to eliminate interaction effects.
-
-commit 280296208bd699cb574c662f92b585519a739c6b
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Jun 25 02:42:07 2007 +0000
-
- removed extension dir and added README for subtend specs.
-
-commit 7ce8d4addc77ea9da0daf3ea3dc1fc7b00030b29
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Jun 25 02:30:15 2007 +0000
-
- reorganized subtend specs. stragglers from spec/language reorg.
-
-commit d499ebfd98d8fb9bd50c0f7a46b3587aa1f28c8a
-Author: Brian Ford <brixen@gmail.com>
-Date: Sun Jun 24 19:44:12 2007 +0000
-
- significant reorganization of spec/language, added files that correspond to the desired layout of this section. there remains to be done a large amount of cleanup for existing language specs, and especially spec description strings.
-
-commit bc0d0965bb5a6b3966884b63edd37218359aa46d
-Author: Tilman <tilman@unknown>
-Date: Sun Jun 24 14:52:15 2007 +0000
-
- Extended specs for File.join.
-
-commit a4e189f31a8c256821564041c4dbce2a832ba78e
-Author: Tilman <tilman@unknown>
-Date: Sun Jun 24 13:00:33 2007 +0000
-
- Fixed a typo.
-
-commit ecaf1abafeb69994b05463742ca4220797f62ad3
-Author: Eero Saynatkari <eero@kittensoft.org>
-Date: Fri Jun 22 23:25:13 2007 +0000
-
- * Array specs by Josh Susser (hasmanyjosh)
-
-commit 1c8987b6195d356126ebc3cc9c21e473be915240
-Author: Arthur <arthur@unknown>
-Date: Fri Jun 22 21:22:30 2007 +0000
-
- * Heavily extended String specs
-
-commit 663e2cbe0c026aa7e792b6aab682301570ccd766
-Author: Tilman <tilman@unknown>
-Date: Fri Jun 22 08:59:42 2007 +0000
-
- Added specs for Time#dup.
-
-commit f9dd8149bd7d794e8686053e8dca010ea71eacba
-Author: Brian Ford <brixen@gmail.com>
-Date: Thu Jun 21 06:47:57 2007 +0000
-
- added methods #compliant, #noncompliant, #extension, #failure. Please read the comments for them in spec_helper.rb. #only, #except are deprecated but have not yet been removed.
-
-commit 389b3cef5176b0244f78294a3c820cc84797e0df
-Author: Brian Ford <brixen@gmail.com>
-Date: Thu Jun 21 05:22:36 2007 +0000
-
- added -f i (immediate) reporter for mini_rspec.
-
-commit d113f855e32d09abaa74bb0ccafa4a65ffce66b1
-Author: Florian Gross <florgro@gmail.com>
-Date: Wed Jun 20 21:59:27 2007 +0000
-
- A few more hash order consistency specs
-
-commit 8df2a605937c29b0ca4e89fae37b725e7244fbee
-Author: Florian Gross <florgro@gmail.com>
-Date: Wed Jun 20 21:24:01 2007 +0000
-
- Small spec improvements all over the place
-
-commit 5c2472584637b6f5accaaf2450d4c23904b0bbd7
-Author: Florian Gross <florgro@gmail.com>
-Date: Tue Jun 19 23:06:33 2007 +0000
-
- Small tweaks to let us run specs against Ruby 1.9
-
-commit 18b06659146f00f0ecf72846c445b03268305328
-Author: Florian Gross <florgro@gmail.com>
-Date: Tue Jun 19 15:56:02 2007 +0000
-
- More specs, including frozen hash ones
-
-commit 3cc17a6c7d4c4e4d13b67da4e2bd8937160916f0
-Author: Florian Gross <florgro@gmail.com>
-Date: Tue Jun 19 15:02:21 2007 +0000
-
- Specs for methods involving to_hash and more
-
-commit a33e72ba27dc7c80fb7c3947d4fe86521b8987e0
-Author: Florian Gross <florgro@gmail.com>
-Date: Tue Jun 19 13:35:14 2007 +0000
-
- New specs for each, each_key, each_pair, each_value, fetch, has_value?, index, initialize_copy, inspect, invert, key?, keys, length, merge, merge!, rehash, to_a and value?
-
-commit f5ec55b0233fd6b7825b04afc6157caac0c529ce
-Author: Florian Gross <florgro@gmail.com>
-Date: Tue Jun 19 13:18:33 2007 +0000
-
- Using except(:rbx) for "inspect should handle recursive arrays" instead of commenting it out
-
-commit 7fec6cb5534d22dbfa4dd245cf3b0c0776b3b465
-Author: Florian Gross <florgro@gmail.com>
-Date: Tue Jun 19 00:56:35 2007 +0000
-
- New specs for Hash.new, #==, #[], #[]=, #clear, #default=, #delete and #empty?
-
-commit e3085af8e97177f8b7e4ff1c2aad2f306a4f474d
-Author: Florian Gross <florgro@gmail.com>
-Date: Tue Jun 19 00:53:43 2007 +0000
-
- Specs for how Array#uniq should use eql?() and hash()
-
-commit 01799e95c71453e8dff9730dd283bf76989e75e5
-Author: Florian Gross <florgro@gmail.com>
-Date: Mon Jun 18 11:22:47 2007 +0000
-
- Adding new specs from rue plus more. The diff is a bit chaotic, but everything should be OK.
-
-commit 890deed76153d05c6874b46ec29c474eb4e36e41
-Author: Florian Gross <florgro@gmail.com>
-Date: Mon Jun 18 11:12:04 2007 +0000
-
- Moving only() to general spec helpers, adding expect()
-
-commit bf89af6c3b632b88e3cc74bead42f21561da58a7
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Jun 18 07:19:15 2007 +0000
-
- (Jason Toy) added some specs for File (with some modifications) (#130).
-
-commit a7a6d8e336f8d331c60e973fb8f9e0aac1fb61ac
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Jun 18 05:20:29 2007 +0000
-
- (Jason Toy) initial specs for YAML (#123).
-
-commit 4c2f70040050e35da28a8684296f913a3dd4a198
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Jun 18 05:14:41 2007 +0000
-
- (nitay) patch for Bignum#size (#120).
-
-commit b1e57c9c718acfc7f1e61ae1fb60f10b918f8e5c
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Jun 18 01:40:29 2007 +0000
-
- Range specs and code from Ryan Mulligan (#141).
-
-commit 9fa70f392bf83c55d67e682c36d9ebd247cff62c
-Author: Florian Gross <florgro@gmail.com>
-Date: Sun Jun 17 22:02:48 2007 +0000
-
- New specs from Ryan Mulligan (#140)
-
-commit 64c970bddeb754115ed193d2f786c797ea90dab3
-Author: Brian Ford <brixen@gmail.com>
-Date: Sun Jun 17 20:08:40 2007 +0000
-
- reorganized specs to put implementation-specific extensions in a subdirectory within the logical division of the specs into core, library, language.
-
-commit 8d437f0f63d4d3f9eea6e4436a28f437e6e76053
-Author: Florian Gross <florgro@gmail.com>
-Date: Sun Jun 17 19:39:37 2007 +0000
-
- Initial work on hash specs -- a few new cases and a bit of reorganization
-
-commit d8222049004ba0d6ec51db0c962b5200bb180aec
-Author: Brian Ford <brixen@gmail.com>
-Date: Sun Jun 17 03:53:45 2007 +0000
-
- (yipstar) module specs for undef_method, define_method, remove_method. all pass MRI.
-
-commit 0162cfe6a443ded5d6c8e01a866f5a8d1fbce901
-Author: Florian Gross <florgro@gmail.com>
-Date: Sat Jun 16 23:11:31 2007 +0000
-
- Added specs for * / join / to_s with recursive arrays
-
-commit 0744e57d7860b9f6eefcc8e14962d7ee777d2ec4
-Author: Florian Gross <florgro@gmail.com>
-Date: Sat Jun 16 22:05:32 2007 +0000
-
- A few more specs for array sub classes with to_ary [ruby-core:11472]
-
-commit 07e0df5111c8ceeda83e50ef434948ee17e92aae
-Author: Brian Ford <brixen@gmail.com>
-Date: Sat Jun 16 19:09:19 2007 +0000
-
- commented out specs that cause the VM to seriously misbehave allocating memory without bound or causing SIGBUS. currently 434 examples, 130 failures at r1357 on MBP.
-
-commit 2abc6e6dc5df662e8f0587636bd1cf3573e39f28
-Author: Tilman <tilman@unknown>
-Date: Sat Jun 16 16:41:07 2007 +0000
-
- Don't use timezone names that aren't portable.
- Instead, specify timezones by their standard name and the offset from GMT.
- This makes the specs pass on FreeBSD w/ MRI.
-
-commit d4106115c2ca9a4678b7060b6ac0091d66312624
-Author: Brian Ford <brixen@gmail.com>
-Date: Sat Jun 16 08:20:29 2007 +0000
-
- a first, big step to making the entire set of specs more agnostic about the ruby implementation/engine by, paradoxically, qualifying certain specs to only run under certain ruby engines. removed incompatible and rubinius directories. folded in specs where appropriate and moved spec files (e.g. bytearray, tuple, compression) into the appropriate directories. the spec/parser and spec/compiler dividing line is not clearly defined given the range of types of implementations and perhaps should be merged.
-
-commit 3de0340e693e20b5e32c643f1f4dae7e1943e077
-Author: Brian Ford <brixen@gmail.com>
-Date: Sat Jun 16 07:07:41 2007 +0000
-
- migrated more tests from shotgun-tests to specs.
-
-commit 369813306643d98c277841c1e9b400f6b60d3316
-Author: Florian Gross <florgro@gmail.com>
-Date: Fri Jun 15 22:43:05 2007 +0000
-
- Add spec for elements returning odd stuff on <=>
-
-commit d70ab64def5ebdcb0e1946618b06e810270eb2aa
-Author: Florian Gross <florgro@gmail.com>
-Date: Fri Jun 15 22:17:03 2007 +0000
-
- New specs for frozen arrays
-
-commit fda7128521254d2db2668fec55ef7ce9337ecf1a
-Author: Florian Gross <florgro@gmail.com>
-Date: Fri Jun 15 21:55:30 2007 +0000
-
- More specs, mostly for array subclasses
-
-commit 2d57166d2ef2ff63f333b7ee0c196f5c4e10b8cf
-Author: Florian Gross <florgro@gmail.com>
-Date: Fri Jun 15 16:56:25 2007 +0000
-
- More than five bazillion new specs including a ton for the very evil []= method (letters i through s)
-
-commit b905a952af41a96f72499750c4635b1352b237ba
-Author: Florian Gross <florgro@gmail.com>
-Date: Thu Jun 14 23:06:33 2007 +0000
-
- A few more specs.
-
-commit e17aa3690f7dcd2dab346bf7def0dd26b38072f1
-Author: Florian Gross <florgro@gmail.com>
-Date: Thu Jun 14 22:16:54 2007 +0000
-
- A bunch of new specs. Includes highly exotic corner cases.
-
-commit 7845d8928d138353ad03bd496d1800c03e82b538
-Author: Florian Gross <florgro@gmail.com>
-Date: Thu Jun 14 20:52:23 2007 +0000
-
- Fix cleanup to work with symbolic method names like ==
-
-commit c677ac036baa847cef3de6a34b2b56c9fd09213c
-Author: Florian Gross <florgro@gmail.com>
-Date: Thu Jun 14 18:04:43 2007 +0000
-
- Fixed the test for DATA to match MRI (it's only supposed to be defined when the main file contains __END__);
- Added test for TOPLEVEL_BINDING
-
-commit 27b2767cd21b5a69ee10a2a629a68de64fd8ae5a
-Author: Florian Gross <florgro@gmail.com>
-Date: Thu Jun 14 18:03:26 2007 +0000
-
- Introducing RUBY_NAME so we can spawn a new Ruby for things that can't be tested otherwise
-
-commit 4c4a96f51b4c06dd6896f996ae0e87a68152a3bc
-Author: Tilman <tilman@unknown>
-Date: Thu Jun 14 15:15:56 2007 +0000
-
- Don't call Time.now multiple times when comparing their values.
-
-commit cde774be8b188f5870b1ee387b5e5fffd9948163
-Author: Tilman <tilman@unknown>
-Date: Thu Jun 14 15:00:17 2007 +0000
-
- Fixed a typo.
-
-commit 6e51eee65c310255183d81d97a98be313ca68afc
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Jun 11 04:07:03 2007 +0000
-
- put guards on imcompatible specs to prevent ruby, jruby from running them. work around for Dir ** globbing being broken.
-
-commit 03dfae6b896a6b67ac6066e94284d992833afac5
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Jun 11 02:00:25 2007 +0000
-
- Added rake task spec:ci. added svn:executable for bin/mspec. enhanced readability of system command in mspec. added globbing across directories to mspec command.
-
-commit 96425667fbff044333c13c5a88c3b8cad156504f
-Author: Brian Ford <brixen@gmail.com>
-Date: Sun Jun 10 21:45:52 2007 +0000
-
- modified mini_rspec to include proper reporters. converted mspec to use ruby to generate a command line to run specs. mspec usage should be similar to spec: mspec spec/core spec/language/class_spec.rb will execute any spec/core/*_spec.rb plus spec/language/class_spec.rb and output a single summary of exceptions, examples, failures.
-
-commit 1075f2cf34a81c00a1b06d2474c78300ae013161
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Sun Jun 10 06:59:40 2007 +0000
-
- Cleaned up MatchData, added support for accessing named groups.
-
-commit c678d79f125d67328e267001e5fe353f5ef38a2c
-Author: Eero Saynatkari <eero@kittensoft.org>
-Date: Sat Jun 9 04:20:51 2007 +0000
-
- * =~ for regexps to mini_rspec by dean (Ticket #136)
- * Kernel.caller spec relocation for reliability
-
-commit 00eec364dbf3cef03915a68a359ed06b7e501553
-Author: Brian Ford <brixen@gmail.com>
-Date: Fri Jun 8 07:10:56 2007 +0000
-
- reintegrated String specs. all specs in core follow the convention that there is one file named <class>_spec.
-
-commit 9f9817bbb9fea5cc02eb280f01eb50e45ea03118
-Author: Arthur <arthur@unknown>
-Date: Thu Jun 7 23:49:47 2007 +0000
-
- * String#replace, String#chop! and String#chop behave now as in MRI.
- * Specs
-
-commit 129e492fcacf937473bb1c602176b48a352f8572
-Author: Arthur <arthur@unknown>
-Date: Thu Jun 7 23:39:00 2007 +0000
-
- * Fix String#<=> when the given object is not a String.
- * Fix String#to_sym for invalid symbols.
- * String#to_i raises an error when invalid radix is given.
- * More specs.
-
-commit 8d7a9e21874d9e44c63d17dd8f6832b942805707
-Author: Arthur <arthur@unknown>
-Date: Thu Jun 7 23:31:25 2007 +0000
-
- * Make String#capitalize!, String#downcase! and String#upcase! check for the 'frozenness' of self
- * Specs
-
-commit 10087a0c92217d1fbadfede9fdb0099c7eb195e6
-Author: Arthur <arthur@unknown>
-Date: Thu Jun 7 23:25:08 2007 +0000
-
- * Spec for String#==
-
-commit e51ca54f6f4e9e3dabd48895fa2cb746fb0d3c17
-Author: Arthur <arthur@unknown>
-Date: Thu Jun 7 23:23:23 2007 +0000
-
- * Fix String#=~ to work as in MRI.
- * Specs
-
-commit d2c7d6e6bb624c23e994888b6a235022486e0c69
-Author: Arthur <arthur@unknown>
-Date: Thu Jun 7 23:16:35 2007 +0000
-
- * Alias String#size to String#length.
- * String#<< now correctly checks and converts (where applicable) arguments.
- * String#<< raises an error if used on frozen string.
- * Added extended specs for String#<<.
-
-commit c389493556e3394cce846698aa4fc6a67a5f4b40
-Author: Tilman <tilman@unknown>
-Date: Thu Jun 7 18:14:02 2007 +0000
-
- Time#zone_offset and #zone_utc? are also in stdlib already.
-
-commit 7dcd86dca123edaec7edec2853cba2af27ca6d52
-Author: Tilman <tilman@unknown>
-Date: Thu Jun 7 18:07:59 2007 +0000
-
- Moved the specs for Time methods that should be in stdlib rather than in core to spec/lib/time_spec.rb
-
-commit 953dfdfdea395ead465a9e19339d94f8b8c7d684
-Author: Hapk <hapk@unknown>
-Date: Thu Jun 7 17:36:20 2007 +0000
-
- Added more specs for Array#pack: covering %#bB.
-
-commit 7aa84bc102ad6943aed46cbb357f233ac4b6d3f9
-Author: Florian Gross <florgro@gmail.com>
-Date: Thu Jun 7 16:47:03 2007 +0000
-
- Make next with arg match MRI; Fixed typos and a copy&paste error
-
-commit 40c354444d6d7a2fd3aeb940c3bdcf6fd2a28940
-Author: Florian Gross <florgro@gmail.com>
-Date: Thu Jun 7 16:43:17 2007 +0000
-
- Fixed to run on MRI (uses Object.const_get now)
-
-commit 95dd0ca698d0b1f79a11f4a556c171bea33ba176
-Author: Florian Gross <florgro@gmail.com>
-Date: Thu Jun 7 12:52:40 2007 +0000
-
- Make behaviour match MRI, fixed copy&paste errors, did some refactoring
-
-commit 191d4e80406a6e4ffd08594ddeada47fb3219bf0
-Author: Florian Gross <florgro@gmail.com>
-Date: Thu Jun 7 01:41:08 2007 +0000
-
- Fix chaos introduced in rev 1283
-
-commit e0f5184493607f7d9c216146207dc298893a744c
-Author: Florian Gross <florgro@gmail.com>
-Date: Thu Jun 7 01:28:55 2007 +0000
-
- Fix Dir.chdir test on OS X (/tmp is symlinked to /private/tmp)
-
-commit a32062d6099556a93afee61f0b0000a28675fbb6
-Author: Tilman <tilman@unknown>
-Date: Wed Jun 6 21:44:00 2007 +0000
-
- Deleted old specs.
-
-commit de7b3ecaa61c4d3514c8a3534805e9c8d0d1bb2f
-Author: Tilman <tilman@unknown>
-Date: Wed Jun 6 21:09:48 2007 +0000
-
- Made the Time#to_a spec pass with any time zone, too. MRI passes all the specs for me now.
-
-commit ac1e295da36f23184e583f5e62a4909959550dbd
-Author: Tilman <tilman@unknown>
-Date: Wed Jun 6 21:06:32 2007 +0000
-
- Fixed specs for Time#localtime, #gmtime and friends.
-
-commit 064a5967f5550cf4a2e10885ab2c9f22afa59da2
-Author: Tilman <tilman@unknown>
-Date: Wed Jun 6 20:56:41 2007 +0000
-
- Fixed a few more Time specs. Instead of the imaginary time zone "PDT"
- I'm now using Asia/Kuwait for some specs, because those lucky people
- don't have DST, which means we don't have to flip the spec expectations
- every 6 months.
-
-commit 8f6b6a5a5f8e62631a58061b6cdeeaff5654aeb0
-Author: Florian Gross <florgro@gmail.com>
-Date: Wed Jun 6 20:41:32 2007 +0000
-
- module_function specs matched to MRI (module_function makes the instance methods private)
-
-commit 8cc656b95cb71ea476e787ce635df889090f8050
-Author: Tilman <tilman@unknown>
-Date: Wed Jun 6 20:41:02 2007 +0000
-
- Fixed the Time#year spec. Using CET, too, since specc'ing using 1969 just feels wrong.
-
-commit ed7be9eaa73b8b1d85964f5c8fdfc250e2e8f62f
-Author: Tilman <tilman@unknown>
-Date: Wed Jun 6 20:38:43 2007 +0000
-
- Oops, fixed a stupid error in r1281.
-
-commit e81d716092e0c6a8b52775ca2b9e0d44c4e3ef7f
-Author: Florian Gross <florgro@gmail.com>
-Date: Wed Jun 6 20:35:42 2007 +0000
-
- Divmod matched to MRI (Special casing darwin on MRI because it doesn't raise FloatDomainError exceptions in some cases)
-
-commit fc5f461c47b7212f05f8699110e313aeab46d46d
-Author: Tilman <tilman@unknown>
-Date: Wed Jun 6 20:35:34 2007 +0000
-
- Fixed the Time#hour, #min and #day specs.
-
-commit 6847a1e49ff4ad4dfe7c6e9e4d7352f92d72b4cd
-Author: Tilman <tilman@unknown>
-Date: Wed Jun 6 20:26:26 2007 +0000
-
- Don't call Time#seconds as MRI doesn't have it and it doesn't seem to be needed anyway.
-
-commit b9a6ccc89d46ffa910c9bdc0fece9d013440872d
-Author: Tilman <tilman@unknown>
-Date: Wed Jun 6 20:14:15 2007 +0000
-
- Time#asctime needs to use %e to print the day of the month.
-
-commit 7311fdf31481ba7a4373d5b007efb62c1f84c389
-Author: Tilman <tilman@unknown>
-Date: Wed Jun 6 20:03:30 2007 +0000
-
- Hardcode output for Time.gm(...).inspect. This makes utctime superfluous for now.
-
-commit 229e7eefe7944df92ab2f84e553992fc0c868dbd
-Author: Tilman <tilman@unknown>
-Date: Wed Jun 6 19:19:38 2007 +0000
-
- Fixed two more Time specs.
-
-commit 7f490d752ed97bfb9b830d24f4e2c2f44107c141
-Author: Tilman <tilman@unknown>
-Date: Wed Jun 6 18:41:47 2007 +0000
-
- Make sure that with_timezone resets .
-
-commit 9c8d25c4d072510215407209fa52a06b85e95d35
-Author: Tilman <tilman@unknown>
-Date: Wed Jun 6 15:57:32 2007 +0000
-
- Made the wday spec work with any timezone.
-
-commit 4882f8a676d5234339296d6a4489f3a7134cf5fd
-Author: Tilman <tilman@unknown>
-Date: Tue Jun 5 20:08:22 2007 +0000
-
- Fixed a typo.
-
-commit fb63faa2165cafdc7907f173344638609f884833
-Author: Tilman <tilman@unknown>
-Date: Tue Jun 5 20:03:06 2007 +0000
-
- Make sure that a GMT Time object returns true from gmt?
-
-commit deae4911588b555264f529e765dc5baf7a2c6e69
-Author: Tilman <tilman@unknown>
-Date: Tue Jun 5 20:00:45 2007 +0000
-
- Use with_timezone for the gmtoff specs.
-
-commit 625dd8e366f846cf15165e323a719199627ae422
-Author: Tilman <tilman@unknown>
-Date: Tue Jun 5 19:47:29 2007 +0000
-
- Added a helper method to temporarily override the TZ env var and fixed one of the specs by using it.
-
-commit b359eb74d41749919c6177ec2af6b5b516308bd8
-Author: Tilman <tilman@unknown>
-Date: Tue Jun 5 19:33:01 2007 +0000
-
- Provided 'date' calls for coreutils' date program.
- Checking for coreutils using RUBY_PLATFORM isn't the right way,
- but it will do for now.
-
-commit b19c3c8d886885adc08ac69469792b14e47ba265
-Author: Eero Saynatkari <eero@kittensoft.org>
-Date: Mon Jun 4 23:42:20 2007 +0000
-
- * Improved Array#sort with additional spec by wycats (ticket #135)
-
-commit 8513e72a5af7596c8782ee45dff39607489dbf12
-Author: Tilman <tilman@unknown>
-Date: Mon Jun 4 16:39:53 2007 +0000
-
- Ticket #132: Implemented ENV in core and removed read-only ENV from shotgun.
-
-commit 03d75a78855213f6267fb8f80f9c71d0a031641f
-Author: Mojombo <mojombo@unknown>
-Date: Sun Jun 3 20:49:41 2007 +0000
-
- Implemented most of Time, updated time specs accordingly
-
-commit 36975b1b79abbd38de68223cdc8ecbca9ba0feee
-Author: Bremac <bremac@unknown>
-Date: Sun Jun 3 16:20:59 2007 +0000
-
- Add Functions::abort, Functions::printf, and Functions::sprintf, and minimal specs. Closes ticket 87.
-
-commit 9d25d95a4aa3fd22d3f3a340427d40410488a770
-Author: Eero Saynatkari <eero@kittensoft.org>
-Date: Sun Jun 3 12:41:49 2007 +0000
-
- * Lots of new assignment specs by crafterm (Marcus Crafter) (Ticket #133)
- * MatchData#inspect and #to_s now indicate it is an MD object
- * -dc notes which file/method is being compiled
-
-commit ec0fb5beed68155c9e1ff67185cc2c8e4e474c04
-Author: Arthur <arthur@unknown>
-Date: Fri Jun 1 22:23:39 2007 +0000
-
- * Fix String#[] and add some edge cases to the specs
-
-commit 068b48538ec574558ab787d59b14ebd2925f1126
-Author: Tilman <tilman@unknown>
-Date: Fri Jun 1 18:12:10 2007 +0000
-
- Renamed module 'B' to something more meaningful to avoid name clashes.
-
-commit eb3de8af03d070b03216daa4fc0c2216d9d3e2a2
-Author: Arthur <arthur@unknown>
-Date: Fri Jun 1 18:09:52 2007 +0000
-
- * Extend String#slice! specs
-
-commit db4775403d57ea29165165b9cbf0110739d91e2a
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Fri Jun 1 02:26:30 2007 +0000
-
- * Ticket #128 - Patch by Marcus Crafter to enhance assignment specs
-
-commit 6098aa16357ce4261feb51bdf083c02442b1f074
-Author: Tilman <tilman@unknown>
-Date: Thu May 31 19:05:45 2007 +0000
-
- Implemented rb_obj_alloc() and friends in subtend.
- The spec for rb_class_new_instance() is still failing because of strange
- subtend behavior.
-
-commit ae2c3cb4502ba9475111eeef10b2b70780a1b9f4
-Author: Eero Saynatkari <eero@kittensoft.org>
-Date: Thu May 31 13:54:24 2007 +0000
-
- * Fixed shotgun compile failure (possibly r1204)
- * Various casts to avoid warnings
-
-commit d317d336412d0c1778d4c015dfe96287c44e1bd9
-Author: Hapk <hapk@unknown>
-Date: Thu May 31 11:12:02 2007 +0000
-
- Added specs for "break", "next" and "redo" keywords.
-
-commit a33f801f8f142d997a553e41cde9f5b10d75ee65
-Author: Eero Saynatkari <eero@kittensoft.org>
-Date: Thu May 31 04:23:33 2007 +0000
-
- * Kernel.caller spec by jtoy (Ticket #112)
- (kernel_spec is badly broken still)
-
-commit ce15eb69e721820e75b0f7aeae6488701cbe9555
-Author: Eero Saynatkari <eero@kittensoft.org>
-Date: Thu May 31 03:55:27 2007 +0000
-
- * Fixed String#dump spec expectation (Ticket #105)
- * Moved RUBY_ENGINE to rubinius-specific variables_spec (Ticket #109)
-
-commit 7d2c575164dfbbd436d7c6ff400c088a68b29fa8
-Author: Hapk <hapk@unknown>
-Date: Thu May 31 00:42:50 2007 +0000
-
- Added "if" specs for variable scoping.
-
-commit ceb4430f9c713f409f2567a0aa324f19afb09b79
-Author: Hapk <hapk@unknown>
-Date: Thu May 31 00:35:49 2007 +0000
-
- Added specs for while / until condition/block evaluation order.
- Added specs for next and redo statements.
-
-commit 4adeecf9333236800396bd77f928fb902e785692
-Author: Eero Saynatkari <eero@kittensoft.org>
-Date: Wed May 30 22:17:04 2007 +0000
-
- * Fixes to RSpec cleanliness of specs, most patches by zimbatm.
- (Tickets #97 #98 #100 #103, partially #99)
-
-commit bbb0714b6ae60adb0af7445ed56544ceec3bc890
-Author: Eero Saynatkari <eero@kittensoft.org>
-Date: Wed May 30 21:41:03 2007 +0000
-
- * Array specs are RSpec/MRI-clean and pass (Ticket #95)
- * Fix to should_raise for MRI by zimbatm
-
-commit d627ab36d3839745e057d9f5de781269ba7b154a
-Author: Hapk <hapk@unknown>
-Date: Wed May 30 21:15:39 2007 +0000
-
- Added specs for 'while' and 'until' statements.
-
-commit 8a2177c7f23181909c5dcb51dd6df1e5b930fdbe
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Wed May 30 20:32:13 2007 +0000
-
- * Enhanced hatefulness of 'for' specs
-
-commit 9f64f2a1c584420fcabfc73a7c464aa3b1ba2e90
-Author: Hapk <hapk@unknown>
-Date: Wed May 30 19:46:57 2007 +0000
-
- Added specs for postfix "if" form.
-
-commit 9dd8a846adf356d75ceac566612f35d1d30840bf
-Author: Hapk <hapk@unknown>
-Date: Wed May 30 19:34:50 2007 +0000
-
- Moved loop specs from spec/language/expressions into spec/core/kernel_spec.rb.
- Added more specs for Kernel#loop.
-
-commit ddf2e3169c3a8b587f9abfb0ddf196635aec5186
-Author: Hapk <hapk@unknown>
-Date: Wed May 30 18:57:38 2007 +0000
-
- Removed obsolete "elsif" statement spec.
-
-commit 3b6dca92ea810aa7866a2c7aa0b8812e72b6630e
-Author: Hapk <hapk@unknown>
-Date: Wed May 30 18:56:00 2007 +0000
-
- Updated specs for "if" statement to cover more cases.
-
-commit 678f609bfe826538ec16e75f7362bcb3f50c8d6d
-Author: Arthur <arthur@unknown>
-Date: Wed May 30 17:09:09 2007 +0000
-
- * Extend Specs for expressions
- * Break the Specs up
-
-commit df60cc21e4213ac8344b5ed91e802d8cbbfa47a0
-Author: Tilman <tilman@unknown>
-Date: Wed May 30 17:00:17 2007 +0000
-
- Implemented rb_ary_store() in subtend. The last spec still fails, but we'll fix that later.
-
-commit 8e0fea820c1683913625dfe95c7d3210d4548814
-Author: Arthur <arthur@unknown>
-Date: Wed May 30 10:09:55 2007 +0000
-
- * Extend Specs for Class Definitions (nested class definitions, class definitions that extend objects, Multiple Definitions of the same class).
- * Lots of them are failing in rbx.
-
-commit ce16f2b568ea89cb5f13660d3175165b105e4233
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Wed May 30 01:18:39 2007 +0000
-
- * OK, that should really be in 'rubinius', not 'incompatible'
-
-commit 888b777539baa116eedc14191ac85d57aec54349
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Wed May 30 01:15:37 2007 +0000
-
- * 'Options' is a Rubinius-only class, and should therefore be in 'incompatible'. Closes ticket #102
-
-commit 46a58344fa2f03fb4154b78f34239a815b2d9944
-Author: Bremac <bremac@unknown>
-Date: Tue May 29 23:52:52 2007 +0000
-
- Fix typos in specc'ing module_function, and make that spec play nicer with MRI.
-
-commit e0cedb691f76af4554bfc7522a7668ff861492f0
-Author: Bremac <bremac@unknown>
-Date: Tue May 29 20:49:42 2007 +0000
-
- More complete raise implementation and specs: Handle instantiation.
-
-commit 9f3a3bfe9d2610dd7e9e752c86a1b8aba47f7fdf
-Author: Hapk <hapk@unknown>
-Date: Tue May 29 20:39:07 2007 +0000
-
- Added 'case' spec for case with empty 'else' body.
-
-commit 8f888bd3d0a01afc945c45c0502a0b97f3227c48
-Author: Arthur <arthur@unknown>
-Date: Tue May 29 20:34:18 2007 +0000
-
- Extend Class specs. Some specs failing in rbx.
-
-commit f52d9faadc1eac31e7b92c1edb1cf45ca1d42c89
-Author: Tilman <tilman@unknown>
-Date: Tue May 29 20:29:53 2007 +0000
-
- Implemented rb_str_new2() in subtend.
-
-commit d4d5e3d1eb8e5ee44acff6697a29a37b9eca25b2
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Tue May 29 20:00:51 2007 +0000
-
- * Patch by HaPK - Add specs for 'case', and enhance specs for 'for'
-
-commit f3e736731e852dacbf90e8e3e33d840384909354
-Author: Tilman <tilman@unknown>
-Date: Tue May 29 18:56:41 2007 +0000
-
- Actually exercise rb_ary_unshift() in the spec.
-
-commit 69d756ae17fce1fb53be5e7a1b5b7169b69c4aa2
-Author: Tilman <tilman@unknown>
-Date: Tue May 29 18:55:32 2007 +0000
-
- Implemented rb_ary_shift() in subtend.
-
-commit 9f84a5ecddae6c0daf1fd7e46815275c7d7429db
-Author: Eero Saynatkari <eero@kittensoft.org>
-Date: Tue May 29 18:50:41 2007 +0000
-
- * Fix to Array#to_a for subclasses
-
-commit 2bbc87fc1b5261b57927a02f75915829b398b478
-Author: Tilman <tilman@unknown>
-Date: Tue May 29 18:50:33 2007 +0000
-
- Implemented rb_ary_unshift() in subtend.
-
-commit 4e69b95ad7991a57fd3f9b7cbf350cb5b13c6a5c
-Author: Tilman <tilman@unknown>
-Date: Tue May 29 18:46:53 2007 +0000
-
- Implemented rb_ary_dup() in subtend.
-
-commit 122a9cfbe79e872146116c8e045a243fffd333e6
-Author: Tilman <tilman@unknown>
-Date: Tue May 29 18:31:48 2007 +0000
-
- Marked SubtendArray method functions as static.
-
-commit 0e3319c07aa1d536343343fbbe1004c4cdce2df0
-Author: Tilman <tilman@unknown>
-Date: Tue May 29 18:28:05 2007 +0000
-
- Implemented rb_ary_clear() in subtend.
-
-commit 621f0082fca85140791e2c40aabc8ad3fe3318a6
-Author: Tilman <tilman@unknown>
-Date: Tue May 29 17:58:31 2007 +0000
-
- Implemented rb_ary_entry() in subtend.
-
-commit 9c7d05c0bb19e65f57fc6aab778785e2a727c4a4
-Author: Tilman <tilman@unknown>
-Date: Tue May 29 17:42:40 2007 +0000
-
- Ticket #91: Made spec/subtend/rake_helper.rb more portable.
-
-commit 5dba201079bdf8da63364ea760342f3cef85df74
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Tue May 29 15:56:01 2007 +0000
-
- * Add specs for Array#pack, patch by HaPK
-
-commit 2d71e18c6f08144d4fb402904a9226a8500343bd
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Tue May 29 15:28:45 2007 +0000
-
- * Better fix to method argument scoping, to support: def foo(a, b=a.length)
-
-commit f9deebb38b80cdea3dff44d7461404e5f501f566
-Author: Defunkt <defunkt@unknown>
-Date: Tue May 29 09:59:00 2007 +0000
-
- * Add spec for Struct subclasses. Closes ticket #110
- * Add failing specs for Class.new. Closes tickets #89 and #94
-
-commit 3be02f950f32a288fac1cd5cff0ae014057c96fb
-Author: Defunkt <defunkt@unknown>
-Date: Tue May 29 09:12:00 2007 +0000
-
- * Add should_include convenience method to make rspec more compatible with mspec. Closes ticket #106
-
-commit 68e716e1874e7dd4186c7eef2aea5e25157a44fd
-Author: Vagabond <vagabond@unknown>
-Date: Tue May 29 03:46:33 2007 +0000
-
- * Add HaPk's fix to Numeric#== to handle failed coersion with corresponding specs
- * Removed duplicate definition of Numeric#==
-
-commit a63e6fcb08e34c625957d8d23bbe602964863c5b
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Tue May 29 02:59:43 2007 +0000
-
- * Add Kernel#eval. Probably lacks some crazy MRI semantics at the moment
- * Method definitions should properly create a clean scope for locals
- * Support wacky default arguments, such as blah = lambda {|z| z.foo(another_arg) }
- * Optional label prefixes in assembly output, for easier debugging
-
-commit f1295ac58d2b601f539efe0e660dfed9d043d1d7
-Author: Vagabond <vagabond@unknown>
-Date: Tue May 29 01:39:46 2007 +0000
-
- Change Time specs to use ENV['TZ'] instead of `date` in hopes of being more portable
-
-commit 404faeca93c007f3eb9b3df52c2bde7673565113
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Mon May 28 19:20:27 2007 +0000
-
- * Fix some mistakes in method_spec that caused it not to pass under MRI
-
-commit d336078c02e1306acb4b2664a427b63e93b02788
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Sun May 27 06:03:25 2007 +0000
-
- * Fix local scoping to allow for method definitions on local variables
- * Pass all the horrible method definition specs
-
-commit 7759a0f91f794d05a32d48dd2e67d05c0b1dace7
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Sun May 27 05:03:53 2007 +0000
-
- * Rename Thread.yield to Thread.pass
- * Implementation of 'module_function' by bremac, with minor tweaks
-
-commit 55f30c5e59d16ebbf045be93a7d406fed9a4dcbd
-Author: Vagabond <vagabond@unknown>
-Date: Sun May 27 00:34:44 2007 +0000
-
- Added defunkt's implementation of Module#const_set and const_get and associated specs (Ticket #72)
-
-commit 9cebe0c56fda41b83ab14d39275e327daf0bdcc9
-Author: Eero Saynatkari <eero@kittensoft.org>
-Date: Sun May 27 00:31:47 2007 +0000
-
- * Fixes to mini_mock by bremac (Tickets #85 and #86)
-
-commit f33756f22597bd280e453d5c7ad97685fa284579
-Author: Eero Saynatkari <eero@kittensoft.org>
-Date: Sun May 27 00:24:51 2007 +0000
-
- * Fix typos in splat_spec (Ticket #77) by tilman
-
-commit ea13a828e5fc19694fc24da25b2224a75462a88c
-Author: Vagabond <vagabond@unknown>
-Date: Sun May 27 00:11:58 2007 +0000
-
- Add Chris Wanstrath's (defunkt) Struct patches. Tested working against MRI.
-
-commit 3ca0ddcc2c39fec74f10b75df2af5c1581b9eaa3
-Author: Eero Saynatkari <eero@kittensoft.org>
-Date: Sat May 26 23:56:26 2007 +0000
-
- * Array fixes. Only spec failure remaining is #pack
-
-commit 4d91aa707a47189398455eb1c40b341dc3766ccf
-Author: Eero Saynatkari <eero@kittensoft.org>
-Date: Sat May 26 20:05:13 2007 +0000
-
- * Array fixes to pass specs (including HaPK's code).
- All remaining failing Array specs except #pack are
- not Array bugs. Test this heavily.
-
-commit 6793b34a54ab8e24e8a66a8af026a34315ac9f5b
-Author: Vagabond <vagabond@unknown>
-Date: Sat May 26 07:34:12 2007 +0000
-
- Add cdcarter's Enumerator implementation and specs translated from his test/unit tests
-
-commit fd10c39192825aeef68c8843c2813cf50b8137f2
-Author: Vagabond <vagabond@unknown>
-Date: Fri May 25 20:12:22 2007 +0000
-
- Some fixes to rand with associated specs
-
-commit 60d37d28b715854f5186598c90101824665ce715
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Fri May 25 19:43:11 2007 +0000
-
- * Properly normalize default method arguments, to support: def(x, y=puts('hi'))
- * Fix 'for' loops so that they use 'create_block' in the proper way
- * Move all 'for' processing out of compiler.rb
-
-commit 3c04a44e8ff9e84f48fbd2d3afabb886494b5a98
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Fri May 25 06:35:48 2007 +0000
-
- * Patch by HaPK - Fixes String#dump / inspect / upto
-
-commit 9e2442110ec33ff9ca4875407b227f2cf79a606a
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Fri May 25 05:36:31 2007 +0000
-
- * Use a random pivot point for better worst-case Array#sort performance
- * Add 'rake pristine' task to kill all .rbc files
- * More tricky specs for splats and multiple-assignments
-
-commit 7bea77d8d3e8f190dba4f34fead888551fd07730
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Thu May 24 23:50:06 2007 +0000
-
- * HaPK's patch to String#<=>, along with its specs
-
-commit 0e6007e7eb9eee5e3ab1acdf55da00f4ab8c4be0
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Thu May 24 23:29:49 2007 +0000
-
- * Add spec for masgn semantics
- * Fix numerous multiple assignment bugs
-
-commit 6d68d22efd7d2dba75c77cf957edb28dca6df6ef
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Thu May 24 07:05:00 2007 +0000
-
- * New Array#sort implementation, fixes several Array and Hash specs
- * Add a warning comment to bytearray.rb about some incorrect <=> behavior
- * Prevent unimplemented Array specs from crashing the spec run
-
-commit 0ca089c7354ec96103cb637f861751ca7df01136
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Thu May 24 01:15:40 2007 +0000
-
- * Support all kinda crazy splat syntax
- * Updated some compiler specs, though some TODOs remain
- * Added a comment above unshift_tuple, since it really shifts
-
-commit bbe0b73b07a393f94724964941d2fdd717a2d72e
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Wed May 23 19:58:10 2007 +0000
-
- * Add compiler support for: yield(*args)
- * Update some compiler specs to match recent fixes
-
-commit 32a7082205d3d214ad43a477286270a96076b140
-Author: Kev <kev@unknown>
-Date: Wed May 23 17:32:06 2007 +0000
-
- Make spec titles consistent (describing C api behavior)
-
-commit 699c66f8c8304522fbb3589356fe2bcd298277c8
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Wed May 23 06:56:25 2007 +0000
-
- * Use yield instead of &prc.call when initializing a thread.
- * Fixes VM crash / closes ticket #68
- * TODO - Why the HELL does this fix it?
-
-commit f8b6e1ff9e19e786b08fee30988eb874eae748b5
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Wed May 23 03:18:26 2007 +0000
-
- * Implement Thread.main
- * Prevent Object#inspect from crashing the VM when the inspected object has itself as one of its instance variables
-
-commit f24f573608ee5569b29754a017769db0f866cf4c
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Tue May 22 22:35:14 2007 +0000
-
- * Implement 'class_variables' method
- * instance_variables and class_variables now accept an optional argument, causing them to return symbols instead of strings
- * Support defined?(@@class_var)
- * Support defined?(a_vcall)
- * Fix false-positives in defined_spec.rb
-
-commit da540b51c47b2349b0ab8d4ca0bd11124138f9ce
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Tue May 22 20:52:30 2007 +0000
-
- * Add compiler support for begin/rescue/else/end syntax
- * Default rescue clause should be StandardError, not RuntimeError
- * Add specs for 'else' and empty begin sections
- * All Exception specs now pass
-
-commit 82abf73fd99ec45f7cb6d98d19b219a61af59a61
-Author: Vagabond <vagabond@unknown>
-Date: Tue May 22 18:39:59 2007 +0000
-
- * Fix Object#instance_eval to bring it into line with the specs and MRI
- * Fix Object#instance_variable_validate to not accept fixnums as instance variable names
- * Add another Object#send spec that tests exception raising for missing singleton method names
-
-commit 3b624f3f49c0433289224baf656b3d7be78cecd8
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Tue May 22 08:15:48 2007 +0000
-
- Fix the block arg scoping problem, also add a missing file from the compiler specs.
-
-commit 59af7028c060c8e3f9b9c107fb750a71dd37a1d6
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Tue May 22 07:14:54 2007 +0000
-
- A bunch of yummy-ness. Local variables now conform to the 'standard' behavior, ie they're allocated at different depths inside blocks (this is the yarv/jruby behavior).
-
- Cleaned up a couple of subtend things.
-
-commit f8ed63efac6fa661dd39db2c207b66c34d132546
-Author: Vagabond <vagabond@unknown>
-Date: Tue May 22 03:28:17 2007 +0000
-
- Add specs for Object #method, #respond_to? and #__send__. These currently fail with singleton methods on rubinius.
-
-commit 0d6e6b7109014c97d8f8be136166b3279d5a1108
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Tue May 22 02:06:19 2007 +0000
-
- * Handle 'call' nodes containing newlines, e.g. x = [5,6,7,8];p Hash[*x]
- * This is probably the wrong implementation, but it does work
-
-commit 518f7d34112e536d726cecfb2473c7b3db9ec33e
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Tue May 22 00:52:01 2007 +0000
-
- * Fix mini_mock's cleanup process
- * Add the ParseTree sexp test cases as specs. Currently in serious need of auditing
-
-commit 17ad76c162ff0cfe9662c20d418f455581389b42
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Mon May 21 21:50:13 2007 +0000
-
- Add a failing spec
-
-commit 1744773b7f57c766c75d188b04e55540d45e19d0
-Author: Vagabond <vagabond@unknown>
-Date: Mon May 21 20:22:04 2007 +0000
-
- Do some env trickery to make Kernel#at_exit testable
- Improve implementation and specs for Kernel#warn
-
-commit 45733aa44e8daee9e8c5e552ac9312f21163fe39
-Author: Vagabond <vagabond@unknown>
-Date: Mon May 21 20:16:18 2007 +0000
-
- Convert time specs to compare against output of the date command
- Change Time#inspect to use %z (GMT offset) instead of %Z (timezone)
-
-commit e58ef35a05d2a565befeaf3600bc00f21203a84c
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Mon May 21 20:12:34 2007 +0000
-
- Add spec for breakage caused by 1089.
-
-commit a5d54efe9a45f3acc1cdb0183a8c13ce6ed5e327
-Author: Eero Saynatkari <eero@kittensoft.org>
-Date: Mon May 21 04:57:41 2007 +0000
-
- * Options implements a minimal lightweight option parser
-
-commit b28b77af82d99a7a3ec5a78f6ab8b4e138ac577b
-Author: Kev <kev@unknown>
-Date: Mon May 21 03:54:33 2007 +0000
-
- Add missing hash spec
-
-commit 81496352bdc2b6b27e293b7542908c6be54b9b6b
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon May 21 02:08:57 2007 +0000
-
- added specs from ticket #38 (David Anderson), but not patch because implementation was invalid (e.g. [].first(0) => [] not nil) and superceded by recent patches. fixed Array#[i,0] => [] exposed by the added specs.
-
-commit 4ed6afc81262a4197f1ddc646ada94277cd9abe6
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon May 21 01:07:36 2007 +0000
-
- HaPK's patch to Array#[] with specs. Knocks 14 failures down to 6. Ticket #60.
-
-commit b267aee1c10b6092d954c72d5776f4eafc109e51
-Author: Kev <kev@unknown>
-Date: Sun May 20 21:09:49 2007 +0000
-
- rb_raise, rb_const_get, exception definitions. Wooooo exceptions from C
-
-commit 37793ed650e6ce7352a7547cf4bc68f2ceb2f0b4
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Sat May 19 08:42:23 2007 +0000
-
- * Added nastier multiple-assignment-with-splat specs
-
-commit 39c9817fa1932f9fe708a8ba78f43cb39e7cb68b
-Author: Brian Ford <brixen@gmail.com>
-Date: Sat May 19 08:30:06 2007 +0000
-
- twifkak's Kernel.fail patch with slightly modified specs.
-
-commit 264a42e8c11d08afa895b415453d59e1e1efe2e1
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Sat May 19 08:01:47 2007 +0000
-
- * Remove a misleading comment in exception_spec
- * Pre-compile bin/*.rb after a make install
-
-commit 7608e585e02283677275aaf5e5283e397ed2d671
-Author: Brian Ford <brixen@gmail.com>
-Date: Fri May 18 23:57:09 2007 +0000
-
- Vagabond's Kernel.warn.
-
-commit 9a41c5a21bbc822ff9ff758eb2962ba80e2d454b
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Fri May 18 18:52:36 2007 +0000
-
- * Re-enable tr and unpack String specs
- * Change 'Nan' to 'nan' in Sprintf to match MRI
-
-commit fdc7032c6e4823727312cc7e5c33386cf9d91429
-Author: Mental <mental@unknown>
-Date: Fri May 18 06:01:20 2007 +0000
-
- add spec for ensure result elision
-
-commit 37438dc826624c3fee3afc1d30a9f661bbb1ab8d
-Author: Mental <mental@unknown>
-Date: Fri May 18 05:45:28 2007 +0000
-
- basic thread spec
-
-commit d89b7728d148ba8c1ddd74323aa8f9e3dae79691
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Fri May 18 02:37:55 2007 +0000
-
- * Fix 'should_raise' in mspec and rspec helpers
- * Added some new Module specs, and fixed existing failures
-
-commit f63e0cf797158a239f65714918debf7a6c1bb687
-Author: Eero Saynatkari <eero@kittensoft.org>
-Date: Thu May 17 04:12:58 2007 +0000
-
- * First draft of a mock lib for mini_rspec
-
-commit c7fd82a8b4b84088de45463dbc25ae7eea5aabe2
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Wed May 16 22:38:27 2007 +0000
-
- * at_exit handlers should run in reverse order of registration
-
-commit 2fb5c6e46f1682d927be8a9e116a609c75ec8be5
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Wed May 16 22:14:21 2007 +0000
-
- * Fix Kernel.Array(). All core/kernel specs pass now
- * Add Kernel#at_exit specs
- * Fix Kernel#`
- * Move AtExit handler array from Ruby namespace to Rubinius
- * It's spelled 'occurred', not 'occured'
-
-commit 3d1605a3ca731b05b5c03ebd8a6edcf386612930
-Author: Brian Ford <brixen@gmail.com>
-Date: Wed May 16 06:04:16 2007 +0000
-
- added incompatible specs for #instance_methods returning symbols.
-
-commit 8ba8409ae0ab94a33cd082f02a81d4d1eab35b59
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Wed May 16 04:27:22 2007 +0000
-
- * Patch by shadowfiend - Enhance Module specs and implement Module#instance_methods
- * Make sure instance_methods always returns symbols, not strings
-
-commit 1e9b0066d712d4507260be02cf2bf116b2519af2
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Wed May 16 03:24:35 2007 +0000
-
- * MethodTable 'is a' Hash, and does not need its own fields in the bootstrap. Fixes 'Object.methods.keys'
-
-commit 8c57dd0e26cb5468c1b0150c5d9c5d80ae6f2de2
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon May 14 06:18:42 2007 +0000
-
- fixed class specs to pass on MRI. put rbx-specific integer specs in spec/rubinius.
-
-commit 8b43acd25a14f540447a9f958f7671822f836817
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon May 14 05:59:06 2007 +0000
-
- moved rbx-specific proc specs to a new home. made core proc_specs pass MRI.
-
-commit 4feb384d0a02b272bd1a3581dd4070ef475b25af
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon May 14 02:59:22 2007 +0000
-
- added RUBY_ENGINE == 'rbx' to global constants and exposed Rubinius::<const> on Object like MRI. converted sprintf specs.
-
-commit 34ad791d5f60177de7992a24f07992bb0d6c8b09
-Author: Eero Saynatkari <eero@kittensoft.org>
-Date: Mon May 14 02:25:06 2007 +0000
-
- * Disabled Lightning's dissembler on amd64
- * Split specrunner into bin/mspec and a wrapper
-
-commit 8796b1f00501813c62676266508a6f89a82ec48e
-Author: Brian Ford <brixen@gmail.com>
-Date: Sun May 13 22:47:28 2007 +0000
-
- minor reorganization, cleanup of spec dir.
-
-commit 9be73815e2037dcc5347c2ef9876e76316efc504
-Author: Brian Ford <brixen@gmail.com>
-Date: Sun May 13 22:06:54 2007 +0000
-
- specrunner outputs summary with 'examples'. converted language/literals, keywords, straggler method_spec.
-
-commit 647fe38ce5f132b7944cca8550233249d8b3c113
-Author: Brian Ford <brixen@gmail.com>
-Date: Sun May 13 21:21:04 2007 +0000
-
- converted language, parser, library specs.
-
-commit d9e8f1fd3bc70231c89a1bdc17a9af5a46fce819
-Author: Brian Ford <brixen@gmail.com>
-Date: Sun May 13 08:28:21 2007 +0000
-
- converted incompatible specs.
-
-commit 9a07bb52c526ce8883c53d437077d78510b0ac73
-Author: Brian Ford <brixen@gmail.com>
-Date: Sun May 13 08:09:34 2007 +0000
-
- added Object#coerce_string that should act like 1.8.x StringValue function. added String#crypt and a couple other String things.
-
-commit 2bae9b5e3baa33da21c1335e84c2eab062eac3a4
-Author: Kev <kev@unknown>
-Date: Sun May 13 06:21:06 2007 +0000
-
- add rb_hash_delete
-
-commit 0ca1a5baa94b5984b0812365a408688420168d24
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Sun May 13 05:31:24 2007 +0000
-
- Imported GNU Lightning. subtend's rb_define_method_ now generates stub's to pop the args and call the function. Next step, add type conversion to call functions that don't take handles.
-
-commit 141e795d5042cb4ea398c9b8eaa9cd7045f5625e
-Author: Kev <kev@unknown>
-Date: Sun May 13 05:15:33 2007 +0000
-
- Add rb_hash_aset
-
-commit 0988a253d8e23b400a738ad74637e8b3655eae8c
-Author: Brian Ford <brixen@gmail.com>
-Date: Sat May 12 19:40:35 2007 +0000
-
- new .rba's with rue's changes. converted spec/shotgun specs. added specs for Tuple. added aliases size, length for Tuple#fields.
-
-commit abd44484b4b2a28a4c7f0bf7acdf12ff30123729
-Author: Eero Saynatkari <eero@kittensoft.org>
-Date: Sat May 12 19:32:06 2007 +0000
-
- * Fixed class variables, should work everywhere now
- * Specs for cvar behaviour
-
-commit 8ec7dac58577cea314ff0fcd976219b23591bc4d
-Author: Brian Ford <brixen@gmail.com>
-Date: Sat May 12 07:40:42 2007 +0000
-
- reimplemented Object#instance_variable_get|set and #instance_variables. now works with immediate values, and classes with no __ivars__.
-
-commit 30c4dd441243277ec5b814ad9b4d4697e87641d0
-Author: Brian Ford <brixen@gmail.com>
-Date: Fri May 11 07:56:14 2007 +0000
-
- added primitives for instance_variable_get|set so that methods operate identically on objects that do not have an __ivars__ field (e.g. Array, String). this needs more work because an exception occurs when attempting to set|get instance vars on an immediate value.
-
-commit 998a0ab62542f36f9e36bdd497116349421951ce
-Author: Eero Saynatkari <eero@kittensoft.org>
-Date: Wed May 9 23:07:35 2007 +0000
-
- * Converted rest of spec/core/
- * mini_rspec/specrunner improvements
-
-commit 0cac71dd1e4dbb728bd3401e73fda5b3fbe95e38
-Author: Brian Ford <brixen@gmail.com>
-Date: Wed May 9 08:18:59 2007 +0000
-
- updated expectations to be the actual compiler output. these specs should be carefully reviewed.
-
-commit 8d551887fd1fabc7700f9f0a432b728829dcef96
-Author: Kev <kev@unknown>
-Date: Wed May 9 07:42:15 2007 +0000
-
- Pull out bundle that got caught in the commit
-
-commit 736916decc6d9bfd7096079a0118f41a168d735d
-Author: Kev <kev@unknown>
-Date: Wed May 9 07:41:42 2007 +0000
-
- Add hash specs, and impl of rb_hash_new
-
-commit 2352f0a526be0f277f2e5d60f18acddc216045c1
-Author: Brian Ford <brixen@gmail.com>
-Date: Wed May 9 07:06:45 2007 +0000
-
- converted test/bytecode/test_compiler to specs.
-
-commit 1f1d30f9ca690214a61f299a4bb408c2d28ef004
-Author: Eero Saynatkari <eero@kittensoft.org>
-Date: Wed May 9 06:08:41 2007 +0000
-
- * Converted MatchData specs
- * Default warnings for empty spec files
- * Improved specrunner
-
-commit 04c03e648ca83de2c2aee37f9aef9079d0493bd7
-Author: Eero Saynatkari <eero@kittensoft.org>
-Date: Tue May 8 06:24:48 2007 +0000
-
- * Converted Integer and Kernel specs
-
-commit a202ef1dfb21cebf3ee33376775d86b9dc89269d
-Author: Brian Ford <brixen@gmail.com>
-Date: Tue May 8 05:45:33 2007 +0000
-
- added before, after methods to mini_rspec. started adding compiler specs as conversion from test/bytecode/test_compiler. removed all host/target junk. thanks. bye.
-
-commit 692da2d89089bc94c95915c90da756480a057dc1
-Author: Brian Ford <brixen@gmail.com>
-Date: Tue May 8 03:36:51 2007 +0000
-
- converted object specs. these really blow up rubinius.
-
-commit 714f5df86f583158d73eda366e2f2527156c3b8e
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Mon May 7 17:29:56 2007 +0000
-
- The first compiler spec, testing the masgn assembly. Some are commented out because they don't yet work.
-
-commit 8ccfe13ca0eca4ceae6a201905a64666a75dd6ba
-Author: Eero Saynatkari <eero@kittensoft.org>
-Date: Mon May 7 05:52:41 2007 +0000
-
- * Converted and reviewed Hash specs
- * specrunner reports specifications and failures
-
-commit aa32b8e94de5c1ccd49a9d6ddca5836d6303c460
-Author: Brian Ford <brixen@gmail.com>
-Date: Sun May 6 06:50:52 2007 +0000
-
- finished converting fixnum specs.
-
-commit 7c55264dc15ed2b8a1b341a5d605701c6626ad34
-Author: Eero Saynatkari <eero@kittensoft.org>
-Date: Sat May 5 06:22:37 2007 +0000
-
- * Converted Enumerable specs
-
-commit 1c660edd87fa91d8c244289b00eb9252d5654c3d
-Author: Evan Phoenix <evan@fallingsnow.net>
-Date: Fri May 4 23:45:08 2007 +0000
-
- Fix array_append as well as the logic to call the extension function so the arguments are correct.
-
-commit 6b9c27b8f8d12be443d37635e17b23b7f0d76388
-Author: Kev <kev@unknown>
-Date: Fri May 4 07:54:10 2007 +0000
-
- Complete rspec coverage of subtend string compat to date.
-
-commit 32db2e9a157cee24ae883b7b8fd563d98fc2dce5
-Author: Kev <kev@unknown>
-Date: Fri May 4 07:11:21 2007 +0000
-
- Add loading of C extensions via require.
- Stop grammar.c from generating every fricking time
- Cleanup formatting on subtend
- Add proper minispec tests for subtend
- Remove old subtend test extension
-
-commit 851fbe6e587596fd074b4c99e42c43865118ae00
-Author: Brian Ford <brixen@gmail.com>
-Date: Fri May 4 06:58:35 2007 +0000
-
- converted (but not to the new new style) fixnum specs. fixed mini_rspec to rescue backtrace.show on MRI.
-
-commit 3e8deacb57ef80684281b1329778bc52681a8601
-Author: Brian Ford <brixen@gmail.com>
-Date: Fri May 4 06:22:53 2007 +0000
-
- converted module specs. added incompatible spec for const_defined?(Some::Class). made mini_rspec print backtrace on error.
-
-commit 3c1cc4ff4f6bf4fa28f65d9909a74f77f6524aa8
-Author: Brian Ford <brixen@gmail.com>
-Date: Fri May 4 05:45:50 2007 +0000
-
- converted math and exception. added two helper methods: should_be_close, should_include. I think spec_translator should handle converting these to 0.9.x syntax as soon as rspec runs.
-
-commit 28e3cdba63f2853b9e9a084f27ad764437830799
-Author: Brian Ford <brixen@gmail.com>
-Date: Thu May 3 15:26:39 2007 +0000
-
- converted float specs. added ignore for *.rbc on externals/rspec-0.9.1.
-
-commit 69ea5db15fb0562d8a4114d4e8ec54f2e19ad8fd
-Author: Brian Ford <brixen@gmail.com>
-Date: Thu May 3 06:40:17 2007 +0000
-
- converted range, nil, regexp specs. added ignore *.rbc on rspec dirs.
-
-commit 6cc364770406e4e04ef7baf2fdaab7425a7f5a6c
-Author: Eero Saynatkari <eero@kittensoft.org>
-Date: Thu May 3 03:27:04 2007 +0000
-
- * Converted Dir specs
-
-commit 5e39be7f97d5cd131b0cf564746d881245030f7d
-Author: Brian Ford <brixen@gmail.com>
-Date: Thu May 3 03:04:24 2007 +0000
-
- okay, rue insists that we use describe ... it now. (see spec_translator with rspec 0.9.1).
-
-commit 99f05b9d6572600ed0bf6a732048c1c4a2d2bb0b
-Author: Brian Ford <brixen@gmail.com>
-Date: Thu May 3 03:00:06 2007 +0000
-
- converted bignum specs. 100% pass on MRI.
-
-commit f9e4df4bdb721eb32c4ac7e5abd4a646daaf20d2
-Author: Brian Ford <brixen@gmail.com>
-Date: Thu May 3 00:06:19 2007 +0000
-
- fixed mini_rspec aliases for specify, etc. to work around exception: No method 'alias_method' on an instance of Object. (NoMethodError)
-
-commit 89d3ca0681816afd389907cbb52f7e0372dbecef
-Author: Eero Saynatkari <eero@kittensoft.org>
-Date: Wed May 2 07:13:56 2007 +0000
-
- * Converted spec/core/ binding, class and continuation
-
-commit 086f889a9bae2e40dd6a8b1ffa80113070f3ad46
-Author: Eero Saynatkari <eero@kittensoft.org>
-Date: Wed May 2 04:22:12 2007 +0000
-
- * bin/specrunner is a small bash kludge for running mini_rspec over
- a directory (recursively) or a single file
- * Rakefile allows diffing a current spec run against a base run to
- easily see all changes among the thousands of specs as well as
- storing a base run
- * specrunner produces decent output for the minimal spec output
- from mini_rspec
-
-commit ba89b2c015d2754b6470b324a013f018d8202cfe
-Author: Eero Saynatkari <eero@kittensoft.org>
-Date: Tue May 1 22:57:22 2007 +0000
-
- * Converted spec/core/array_spec.rb to mini_rspec
- * Reviewed and fixed some specs for Array
- * Spec-style output to mini_rspec (manual comment/uncomment to switch)
- * should_raise for slightly more natural exception verification
-
-commit 0330bcc23fa1609db291cd382cb13fc168ec5bf3
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Tue May 1 22:44:40 2007 +0000
-
- * Implement correct behavior for String#split when called with a zero-width Regexp
-
-commit c8e806e2dafd237fa8117ead21553a195900613e
-Author: Brian Ford <brixen@gmail.com>
-Date: Tue May 1 02:29:35 2007 +0000
-
- converted symbol_spec. 100% pass.
-
-commit 76e31065df70ebc5790fdb604f1b07d28ffaa81c
-Author: Brian Ford <brixen@gmail.com>
-Date: Tue May 1 02:19:33 2007 +0000
-
- commented out specs that cause rubinius to hang. String#delete and #tr (and methods that are implemented in terms of these).
-
-commit 2ae8aea13161a71c3fb4ca8e0486acd55c897579
-Author: Brian Ford <brixen@gmail.com>
-Date: Tue May 1 01:17:14 2007 +0000
-
- converted core/string_spec to regular syntax. added mspec_helper.
-
-commit ff84053991295b259ca8b1c17adff95f5d471961
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Apr 30 22:31:26 2007 +0000
-
- converted false_spec. added svn:ignore *.rbc on all spec dirs.
-
-commit 3fc864ba235c56118e1db66dbf9537d6ff8c0c5f
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Apr 30 22:00:12 2007 +0000
-
- Let the breakage begin. Converting all specs to use mini_rspec with 100% compatible syntax with rspec proper. usage: 'USE_RSPEC=1 spec spec/core/false_spec.rb' for any specs that use example {} method. spec spec/core/true_spec.rb OR ./shotgun/rubinius spec/core/true_spec.rb for converted specs.
-
-commit 4c6c7f406d0e5504a72c52b1ae5339a9dba36865
-Author: Brian Ford <brixen@gmail.com>
-Date: Sun Apr 29 17:28:11 2007 +0000
-
- added setup method and print to STDERR and STDOUT to support a shell script runner.
-
-commit 958a0e9b1a066cf2d825b960b66788b05c928f36
-Author: Brian Ford <brixen@gmail.com>
-Date: Sun Apr 29 08:26:09 2007 +0000
-
- mini rspec implementation. example {} method is dead.
-
-commit a323b3d424f226322cf20e65e87f8a4e962ed497
-Author: Brian Ford <brixen@gmail.com>
-Date: Sun Apr 29 03:23:17 2007 +0000
-
- Added Array#first, Array#last that take numeric args to core. Added a bunch of failing specs for Array#[]. #first and #last are implemented using #[] so several of the specs for those fail, but the implementation of #first and #last was tested in MRI.
-
-commit 3897c943069582b1e5d1649a097bd77c0c895e0a
-Author: Hurdlea <hurdlea@unknown>
-Date: Thu Mar 29 13:51:13 2007 +0000
-
- * Support for Floats in Sprintf
- - Sprintf is still missing support for unsigned twos complement
- * String#% now implemented
- * Fixed a minor issue in the Rakefile
-
-commit 5ed87ff88793f8d44cfe34b443eb032d27dc2a4c
-Author: Hurdlea <hurdlea@unknown>
-Date: Thu Mar 15 05:08:34 2007 +0000
-
- * Added Sprintf core module and classes for string % and Kernel
- - Still needs some work with floats and requires a couple of
- primitives to achieve this.
- * Fixed a small issue with String#Index(Fixnum, offset)
-
-commit 982c09b15710429fc97d8d43d9f24a3a0badb6d5
-Author: Brian Ford <brixen@gmail.com>
-Date: Sat Mar 10 22:35:18 2007 +0000
-
- Fixed array spec for #sort which improperly depended on the accidental order in which two elements of the array were being compared.
-
-commit 32fe004da7f35e9b7dcc96f8e57e1acb37164748
-Author: Hornbeck <hornbeck@unknown>
-Date: Sat Mar 10 06:38:23 2007 +0000
-
- Two tests in the ObjectSpace spec. It was bare and needed love.
-
-commit e1530bb1999118bf88037dccc27d78f54bdbe5e4
-Author: Tlockney <tlockney@unknown>
-Date: Sat Mar 3 23:28:27 2007 +0000
-
- updated all rspec exceptions. exception specs all pass in MRI. still a few rubinius exception spec issues
-
-commit 2c278533cbfe0efc7076d2c947323640be5f207a
-Author: Brian Ford <brixen@gmail.com>
-Date: Sat Mar 3 21:29:55 2007 +0000
-
- Committing tlockney's additions to core/exception_spec.rb. These pass on MRI but illustrate areas to fix on rubinius.
-
-commit fd8993c0996e4524440a6572c45dad4ab112fb2f
-Author: Hornbeck <hornbeck@unknown>
-Date: Fri Feb 23 15:58:33 2007 +0000
-
- committing Aki Reijonen's Hash patches for hash.rb and the hash_spec.rb. Also included is Thomas Lockney's exception_spec.rb patches.
-
-commit 08e6d924b8c0175242c1c40322ed3e45855a86c2
-Author: Brian Ford <brixen@gmail.com>
-Date: Sun Feb 18 07:48:46 2007 +0000
-
- Altered Object#instance_variable_[get|set] rearranging flow control. Added specs for instance_variable_[get|set] for Array, IO, String.
-
-commit 2a2385413c03f21dfc038e110f46a7a3bd2fc9c7
-Author: Brian Ford <brixen@gmail.com>
-Date: Sun Feb 18 06:05:47 2007 +0000
-
- Increased time out value when running rspec error report. Minor changes to text in class specs.
-
-commit bd0d7fcf72546a0a3a5a6a59b1a6f2aadd8e4262
-Author: Mae <mae@unknown>
-Date: Sun Feb 18 03:53:00 2007 +0000
-
- Integer#bits for future refactoring of shift
- * added Integer#bits which calculates minimum bit storage required for (signed int) form of the Integer
- * spec'd it too
-
-commit 4e6b39d5e69c04d92ceac76ce5a5bd792fb65f39
-Author: Mae <mae@unknown>
-Date: Sun Feb 18 02:55:55 2007 +0000
-
- Object#extend-a-gogo
- *Fixed Small bug in rubinius_target where failures wouldn't be reported
- *Implemented Object#extend and changed math.rb to use it accordingly
-
-commit 5472c10579cef38f9f28c904710246509633a040
-Author: Mae <mae@unknown>
-Date: Sun Feb 18 01:21:11 2007 +0000
-
- A great Time patch from John Hornbeck <hornbeck@gmail.com>:
-
- A more complete Time diff. This includes many of the instance methods for Time and a new primitive for usec. This diff also includes some failing specs as I went ahead and added the specs for the rest of the class methods. Also included is the constants for Time.
-
- Keep the good work coming John!
-
-commit 83ab11e0ab6679b1c9eefc5095d3f20af9a61661
-Author: Mae <mae@unknown>
-Date: Sat Feb 17 23:26:33 2007 +0000
-
- Patch from Aki Reijonen <aki.reijonen@gmail.com> without the Float.induced_from part
-
- Summary of the changes:
-
- ** Added methods **
-
- Numeric#integer?
- Numeric#div
-
- Integer#to_int
- Integer#round
- Integer#truncate
- Integer#next
- Integer#succ
- Integer#integer?
-
- String#slice!
-
- Object#to_a
-
- Kernel#Array
- Kernel#String
-
- ** Fixed methods **
- Float.induced_from
- - Now return the passed object if it's an Float insted of calling #to_f
-
- ** Removed methods **
- Fixnum#div was broken, the end result should be converted to Integer,
- not the number passed as a argument. (superceded by Numeric#div)
-
- --
- Aki Reijonen
-
-commit 243a4e9ba46149b8ba39c7238f8ff3d5f267689e
-Author: Brian Ford <brixen@gmail.com>
-Date: Sat Feb 17 06:17:44 2007 +0000
-
- Ditched all the instance vars in array specs since we've got locals now.
-
-commit be5363e22e04b8baf26cb4abd8a8a67e7dd3cc0c
-Author: Eero Saynatkari <eero@kittensoft.org>
-Date: Wed Feb 14 01:05:49 2007 +0000
-
- Fixed * varargs to work in method definitions. Currently still
- does not work as the single named parameter (foo(*a)). This
- means that lib/bytecode/encoder.rb now compiles under Shotgun.
-
-commit 3bb810688e848c90d5c20929c630f36a32796d2d
-Author: Brian Ford <brixen@gmail.com>
-Date: Tue Feb 13 18:42:09 2007 +0000
-
- Added Object#instance_variable_set and specs.
-
-commit 54392c99dc3db5b58c85799416cc528c60b12533
-Author: Brian Ford <brixen@gmail.com>
-Date: Tue Feb 13 18:25:24 2007 +0000
-
- Added Object#instance_variable_get and specs. Uncommented Math module constants specs.
-
-commit 84267901502ca1e8e8b13afa0e3a16e0cdc8e493
-Author: Mae <mae@unknown>
-Date: Sun Feb 11 10:30:13 2007 +0000
-
- * Primitive Specs
- - Added spec for bignum_div (and fixed a problem where it would always fail)
- - Fixed primitive_spec_helper (because it broke the old specs last time)
- - Removed magic method chaining because it sucks
- - DISCLAIMER: primitive specs atm just test functional things, _NOT_ stateful side-effects
- - We can do this properly once rubinius can run rspec
-
- * SIRB
- - Made it so that => wouldn't get printed before the command prompt if you typed "exit"
- - Made Kernel#p, Kernel#puts, Kernel#print return nil (like MRI)
- - added #!shotgun/rubinius to top of sirb and symlinked it to bin/sirb.rb as well (for convenience)
-
- * Removed unused local from __loader
-
-commit efce7d8a56748ab1831a34d21b8c92ff8b2eb977
-Author: Mae <mae@unknown>
-Date: Sun Feb 11 07:25:51 2007 +0000
-
- Moved math to math_spec; added object_spec for primitives; made primitives_spec_helper maybe too smart? -- they chain methods on to the remote target
-
-commit 087a5e5a6e89e4a53a39e025ffe08d21e96b8f6e
-Author: Mae <mae@unknown>
-Date: Sun Feb 11 05:51:30 2007 +0000
-
- * Made rubinius_target and example much more helpful
- - backtraces are shown on failure now
- - you can do this: example { 1 + nil }.should_raise(TypeError) and it works :) (with bt and all)
- - injected some extra code in example snippets so try(exc) syntax still works
- - Float, Nil, True, False specs all pass 100 %
- - made rubinius_target make use of @src (used in bignum)
-
- * Made Kernel.Float() and Kernel.Integer() behave appropriately like MRI _with_ the exception of Float() also checking for to_i method
- - Integer(nil) => 0 and Float(nil) => 0.0
- - lots of spec coverage
-
- * Numeric#coerce was slightly tweaked to use new Float() and Integer() behavior
- - Specifically complains about other being nil (so 1 == nil doesn't work)
-
- * Made Float.induced_from() more anal retentive (only accepts core Fixnum, Bignum, Float types like mri)
- - specs cover it
-
- * Fixed infinite loop on Bignum#& and moved & out of Numeric into Integer (Float doesn't have &)
-
-commit eadf1ead754d3dbfaf703c205f6f5e8f4dc5c430
-Author: Brian Ford <brixen@gmail.com>
-Date: Sun Feb 11 03:00:25 2007 +0000
-
- Put object flags values into a single include file. Added Object#taint, tainted?, freeze, frozen?. Neither of these states actually effect execution yet. Fixed up Object specs.
-
-commit 38e7f757e67b4ec985835e0e93ba4d32bbee5ca4
-Author: Mae <mae@unknown>
-Date: Sat Feb 10 23:57:37 2007 +0000
-
- - Created specs for math_sqrt primitive (and created spec/primitives/math_spec.rb)
- - Tweaked primitives_spec_helper to properly transport NaN's to testing environment
- - Removed non-needed self parameter from math_sqrt c function
-
-commit a4267a136d7f0bf7f92421fcebd8011600a1d92e
-Author: Mae <mae@unknown>
-Date: Sat Feb 10 22:29:46 2007 +0000
-
- Float.induced_from love
- - made Float.induced_from work for any to_f item (controversial whether this should be done in Kernel.Float() or not)
- - apparently this fixed some float failures
- - made Float.induced_from safer because it now complains if to_f returns a non-float
- - wrote specs for new induced_from behavior
- - try (spec_helper) needs to be investigated, manual running of the premises of 'Float divmod should raise FloatDomainError if other is zero' show this to be a spec that _should_ pass
-
-commit 65a4e8abfc7f690456e4f44e7e4cc38911288516
-Author: Brian Ford <brixen@gmail.com>
-Date: Sat Feb 10 18:54:15 2007 +0000
-
- Added spec files for the rest of the core classes documented in Pickaxe book. Add simple class hierarchy specs for exception classes.
-
-commit c7a2f68c36dd95f51af88e8fa62b24b71d68578a
-Author: Brian Ford <brixen@gmail.com>
-Date: Sat Feb 10 17:29:46 2007 +0000
-
- Commit of scoopr's Math module beginnings. Thanks scoopr.
-
-commit b1e8d150460f2ae9ea2e5ef87d0df3b705c1d0d6
-Author: Mae <mae@unknown>
-Date: Fri Feb 9 08:54:25 2007 +0000
-
- Bignum primitive specs
- - Added spec and changed to metaprogramming style for primitives: bignum_add, bignum_compare, bignum_equal, bignum_and, bignum_divmod
- - fixed bug that bignum_divmod spec found where bignum_divmod would always fail on divide by zero GUARD
-
-commit 0487a39ec9995af8eb5a8dff5ec64492261852e7
-Author: Mae <mae@unknown>
-Date: Fri Feb 9 07:48:56 2007 +0000
-
- Primitive Spec Sexiness
- - Added spec and changed to metaprogramming style for primitive fixnum_to_f
- - Made usage of run_primitive(:add, 1, 5) more sexy i.e. 1.prim.add(5)
- - converted fixnum spes to use sexiness
-
-commit 95fa48f29eaa7e3f10ccd63d385fb3f582f57eea
-Author: Hurdlea <hurdlea@unknown>
-Date: Fri Feb 9 01:36:14 2007 +0000
-
- * Added String#delete, delete!, tr, tr!, tr_s, tr_s!
- - String#count and squeeze to follow ...
- * String#<< now accepts Fixnums
-
-commit 017bdc57602e2e5d55705de070c07edba46a347f
-Author: Mae <mae@unknown>
-Date: Thu Feb 8 09:23:55 2007 +0000
-
- - removed noop from primitives (it does nothing)
- - removed noop primitive spec
- - changed CPU::Primitives.name_to_index to offset by +1 (to leave room for special 0 value)
- - still having same closed parens issue with spec:primitives:
- syntax error, unexpected $end, expecting ')' (SyntaxError)
-
-commit 18a3347bb32d8ac5269438376f0100ecce2c9e73
-Author: Mae <mae@unknown>
-Date: Thu Feb 8 08:20:14 2007 +0000
-
- - made shotgun/lib/primitives.rb have less dependencies
- - fixed bug where if a false was popped of the stack it wouldn't be recognized as an argument in primitives_spec_helper (nil will only do this now)
- - fixed regression in primitives_spec_helper where the proper code wasn't showed when shotgun crashes
- - noop_spec works again
-
-commit 16b08e446b69344da1edbc1f793e0161deac8e6c
-Author: Mae <mae@unknown>
-Date: Wed Feb 7 23:59:14 2007 +0000
-
- More Primitive Goodness, Conform to unified rspec standards
- - Added specs and changed to new metaprogramming style for the following primitives: fixnum_and, fixnum_or, fixnum_xor, fixnum_invert, fixnum_neg
-
-commit cb2ac85b45a41a63100cac673919ad8db1f93f43
-Author: Eero Saynatkari <eero@kittensoft.org>
-Date: Wed Feb 7 23:16:35 2007 +0000
-
- Basic specs for Symbol literals.
-
-commit 3ab7aced51f3a63c8f76706a2f159d0d5753dc64
-Author: Brian Ford <brixen@gmail.com>
-Date: Wed Feb 7 20:35:27 2007 +0000
-
- Changed Fixnum primitives specs to be in a single file, spec/primitives/fixnum_spec.rb. Added back the alternative example of writing specs for others to evaluate or use. Updated the wiki specs page to lay down the law on spec files. Kindly follow it.
-
-commit cf16d691990f43f5bf8807bbef2ba1876892be57
-Author: Mae <mae@unknown>
-Date: Wed Feb 7 18:27:15 2007 +0000
-
- Autotest, C warnings cleanup, and some primitive_spec usage cleanup
- - Added Autotest Facilities for primitive bin/autotest/primitives
- - need to gem install zentest to use this (and some diff gem i can't remember)
- - Removed ugly require statement from cpu/primitives it was causing annoying ruby errors
- - Added missing prototypes to cpu.h and regexp.h (primitives.gen was complaining)
- - Localized bt and bt_size variable declarations to where they would be included by the preprocessor to make more warnings go away
- - Added newlines to the end of numeric.c, numeric.h, float.c
- - Used one of brixens suggestions (injection of primitive spec helper automatically)
- - Removed extraneous primitive helper inclusion in each spec
-
-commit f4bbce9d761d27e1381b95a4ff6076e85577074d
-Author: Brian Ford <brixen@gmail.com>
-Date: Wed Feb 7 16:56:21 2007 +0000
-
- This shows an example to 'fix' mae's rubyesquely-challenged (bluntly, ugly) primitive specs. Also, there should be one spec file for a group of related contexts. In this case, the group is the class Fixnum. So, mae, fixnum_spec.rb, NOT fixnum_xxx_spec.rb. Sorry. Cry tyrany, weep and gnash thy teeth, howl in protest, but please fix it. This is non-negotiable. Thank you and good work on the primitive specs. :)
-
-commit e5f6215824a40beb0ca678575596bd06afa8dd3a
-Author: Mae <mae@unknown>
-Date: Wed Feb 7 09:54:54 2007 +0000
-
- - Added specs for primitives: add, sub, fixnum_mul, fixnum_size, fixnum_div, fixnum_modulo, fixnum_divmod, fixnum_to_s
- - Updated primitives to new metaprogramming style: sub, fixnum_mul, fixnum_size, fixnum_div, fixnum_modulo, fixnum_divmod, fixnum_to_s
- - Changed wording in a couple primitive spec files to be more explicit
- - Made reporting by primitive_spec_helper more helpful when shotgun crashes from injected code
-
-commit 3032c6bd869a04c1517508850f94119975c36e54
-Author: Brian Ford <brixen@gmail.com>
-Date: Wed Feb 7 02:26:47 2007 +0000
-
- Fixed up String#to_i a bit; added a bunch more specs for it.
-
-commit d8a24ffa8d9983a85b0f03784a89bfa667af1615
-Author: Eero Saynatkari <eero@kittensoft.org>
-Date: Wed Feb 7 01:46:30 2007 +0000
-
- Added very basic set of specs for assignment and multiple assignment semantics.
-
-commit edb7c82523b36b26e24437de42fd2638eef1653f
-Author: Brian Ford <brixen@gmail.com>
-Date: Tue Feb 6 19:02:46 2007 +0000
-
- Added specs for and methods CType#isalnum, isdigit.
-
-commit e84ba1b12c51331d00bdd06684dcff96ea229322
-Author: Brian Ford <brixen@gmail.com>
-Date: Tue Feb 6 17:30:55 2007 +0000
-
- Added spec/shotgun/bytearray_spec.rb. Added spec for ByteArray#[], []=. Modified various string methods to use BA#[], []= instead of get_byte, set_byte.
-
-commit be9589cc47cbf35edd94ca22407de4b1527a3fdb
-Author: Mae <mae@unknown>
-Date: Tue Feb 6 11:26:31 2007 +0000
-
- Tweaks to primitive metaprogramming and addition of noop spec
- - Added types 'qnil' 'qtrue' 'qfalse' to be used in primitive metaprogramming
- - Added spec for noop primitive
- - Added run_asm method to primitives_spec_helper for those tricky tests
- - Converted noop primitive to new metaprogramming style
-
-commit e31f1af903dd8dd31427e34a718b30f5c63af8df
-Author: Brian Ford <brixen@gmail.com>
-Date: Tue Feb 6 10:33:00 2007 +0000
-
- Some fixes to String#to_i and additions to specs. Added String#oct and hex.
-
-commit 2a157827bd72b6c7ce8a025928cdd9d7f2f8d00f
-Author: Mae <mae@unknown>
-Date: Tue Feb 6 10:18:16 2007 +0000
-
- moved equal and compare to use new primitive technique
- - also updated equal_spec to ask for ArgumentError instead
- - uploaded new rba *glares at brixen*
-
-commit 771d0fede3086ce58d225ac4001ea0934f3bb0e3
-Author: Mae <mae@unknown>
-Date: Tue Feb 6 09:33:03 2007 +0000
-
- ARITY macro raises ArgumentError directly from the primtive now and made specs pass
- - Made ARITY macro raise an argument error exception instead of just ambiguously failing
- - Made _ret return TRUE on arity failure (exception directly raised)
- - Moved GUARD and POP macros to shotgun/lib/cpu_primitives.c where they belong (localized)
- - Removed side-effect printf in cpu_raise_arg_error since stack trace is fine now
- - Tweaked primitives_spec_helper should_raise to work for all exceptions
- - Made specs for equal/compare pass again (expect ArgumentError instead of PrimitiveFailure)
- - New compiler.rba (update these ppl!)
-
-commit e89190c8fdc4a71c7b8cd9c8b873a63b9d1888c5
-Author: Hurdlea <hurdlea@unknown>
-Date: Tue Feb 6 07:51:08 2007 +0000
-
- * Finished String#[]= for string index
- * found odd bug with spec where string[1,2]="foo" is not interpreted correctly
- changed methods to use send(:[]=, ... and the tests pass
-
-commit c6e1bb68e930a537bd51d77afd37cdc8b5d62d31
-Author: Hurdlea <hurdlea@unknown>
-Date: Tue Feb 6 07:18:15 2007 +0000
-
- * Added String#[]= slice functionality
-
-commit e405d4f5f32fd8192c435b3488f394b2635c7db7
-Author: Brian Ford <brixen@gmail.com>
-Date: Tue Feb 6 06:37:31 2007 +0000
-
- Added String#chomp[(bang)].
-
-commit ff48a6c333f34c1b1882c260db7145facce3d71f
-Author: Brian Ford <brixen@gmail.com>
-Date: Tue Feb 6 06:00:56 2007 +0000
-
- Added String#replace_if that calls replace if self != other else returns nil; Added upcase, downcase.
-
-commit f46d747eba82c215fa07b067a30f2a2e8868d284
-Author: Brian Ford <brixen@gmail.com>
-Date: Tue Feb 6 05:31:13 2007 +0000
-
- Implemented String#reverse directly rather than with String#<<. Modified some string specs for [lr]strip but forgot to commit them earlier.
-
-commit d3b0e71e810a985f3b8f2e5f5c7d5c4619f151f9
-Author: Hurdlea <hurdlea@unknown>
-Date: Tue Feb 6 03:00:28 2007 +0000
-
- * Added NilClass specs to detect NilClass coercion
-
-commit c570ca475cabeb3fcfcca26d4c57b8e57f6606b4
-Author: Brian Ford <brixen@gmail.com>
-Date: Tue Feb 6 02:01:19 2007 +0000
-
- Added module CType mixin for Integer to provide isspace, isupper and friends. Added specs for CType in spec/shotgun. Implemented String#capitalize[(bang)]. Moved ByteArray into it's own file. Updated various string specs and commented out temporarily index spec.
-
-commit 4694d1511e880e43dfccb3e3f5309f0920395ba0
-Author: Hurdlea <hurdlea@unknown>
-Date: Tue Feb 6 00:22:17 2007 +0000
-
- * Fixed operation of Regexp#=~
- * Updated Regexp spec for =~
- * String#== now works correcly for duck typed objects
-
-commit 8e42aa9c789fcc9bc475d460e7158f2adcc8ab64
-Author: Mae <mae@unknown>
-Date: Mon Feb 5 22:46:21 2007 +0000
-
- Added arity checking for primitives
- -for use in primitives: #define ARITY(length) GUARD( (length) == num_args )
- -for instance if i have a primitive that takes one argument (self + arg) i put ARITY(1) at the top
- -changed specs with regard to arity accordingly
- -made block_given conform to the "self rule for primitives" by padding Qtrue where self would be
- -fixed block_given? to pass the right arity (0) in the compiler
- -specs for compare and equal pass now
- -added primitives_spec_helper (forgot last time)
-
- NOTE: Binary .rbc compatibility is broken now since there are arity checks done on block_given?
- -the rba's i uploaded should be fine but if they arent...
- do find -type f | grep .rbc | grep -v .svn | xargs rm
- then rake build:rubinius
-
-commit 2d5c9bc3170bf959390627def10c0208088b48ee
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Feb 5 22:39:08 2007 +0000
-
- Added Integer#isspace and spec in spec/incompatible. Added spec/incompatible/string_spec to describe behavior of stripping runs of whitespace and nulls from end of a string. Added or modified String#lstrip, lstrip(bang), strip, strip(bang), rstrip, rstrip(bang).
-
-commit d4b07b06ca85543423a308f12b82ae4671bdd0c2
-Author: Mae <mae@unknown>
-Date: Mon Feb 5 21:01:59 2007 +0000
-
- -split out common primitive testing functionality to primitives_spec_helper.rb
- -added spec for primitive "equal"
- -again primitive specs are rake spec:primitives
-
-commit c1a7896f24e018df13af7f0d3d60db9f461130a5
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Feb 5 20:58:21 2007 +0000
-
- Added that Module#include passes off to append_features. Added Module#include that takes multiple args later in the bootstrap sequence. Added specs for include and append_features.
-
-commit d407ecab13722599b75fecc20bdebd86c9f76fa6
-Author: Mae <mae@unknown>
-Date: Mon Feb 5 20:48:02 2007 +0000
-
- Misc Changes to Tweak primitive specs
- -Added spec to test arity restrictions of compare
- -Fixed bug where should_raise for primitives was not catching the error condition
- -Changed wording of some specs to be english rather than engrish :)
-
-commit f68ad63065002d4a3c9a0742770da4a112780aa7
-Author: Mae <mae@unknown>
-Date: Mon Feb 5 20:02:24 2007 +0000
-
- - Remove printf from cpu_raise_primitive_failure so that the screen doesn't get littered
- - Created PrimitiveSpecHelper and a "primitives" spec subdirectory
- - Added rake task spec:primitives
- - Added compare_spec as an example
- - New rba's
-
-commit f997d3791099912001d09a427f24252182ba1d6c
-Author: Hurdlea <hurdlea@unknown>
-Date: Sat Feb 3 08:10:48 2007 +0000
-
- * Added MatchData#values_at
- * Fixed implementation of MatchData#select
- * Updated specs for MatchData#values_at, select
-
-commit 4f8301aeb3a5a296a64b887b0f164ca02be2a71f
-Author: Brian Ford <brixen@gmail.com>
-Date: Fri Feb 2 17:00:10 2007 +0000
-
- Added specs for and empty module methods private, protected, public as a first approximation to allow code that uses them to not choke. Added String#match.
-
-commit 15c3678ddcc365891fd92cc9cd33eb22308916e8
-Author: Brian Ford <brixen@gmail.com>
-Date: Fri Feb 2 10:43:58 2007 +0000
-
- Committing Adam Ritter's patch to recognize 'for i in ...' expression, and associated spec. Uncommented line in float_spec.
-
-commit 370d7a955bf6e41c4ea7cf0f9217128ae7a72fd4
-Author: Hurdlea <hurdlea@unknown>
-Date: Fri Feb 2 07:06:22 2007 +0000
-
- * Added MatchData#inspect, select, to_a, size, to_s
- * MatchData#[] is now more compliant - behaves more like Array#[]
- * Added Regexp#hash
- * Added Regexp#hash spec
-
-commit b496d50c0ebf7d5c523efe2ef5383dd8043aa3f0
-Author: Eero Saynatkari <eero@kittensoft.org>
-Date: Fri Feb 2 00:36:37 2007 +0000
-
- Added specs for Dir and modified rubinius_target to allow
- specs to change directories safely.
-
-commit 6ddf4051f3a6be7076e947bf3eccbc5dd9a7803f
-Author: Brian Ford <brixen@gmail.com>
-Date: Thu Feb 1 19:11:14 2007 +0000
-
- Fixed Float#divmod, returning 0 guard on primitive, raising FloatDomainError rather than ZeroDivisionError. Fixed Float#% when other is zero. Spec try helper doesn't yet work with rubinius_target
-
-commit 679f3fbe54960a690f4e41e1403fdc8f50c0f346
-Author: Brian Ford <brixen@gmail.com>
-Date: Thu Feb 1 18:36:44 2007 +0000
-
- Added more zero division behavior specs.
-
-commit b4d739a7cb68d6f82d657b69aee00923e0bfdbb4
-Author: Brian Ford <brixen@gmail.com>
-Date: Thu Feb 1 18:12:02 2007 +0000
-
- oops, damn keystrokes. Previous commit msg should just include Fixnum. This change points out a problem that I'm not sure about: 1.quo(0) => Infinity in irb and run from a file, but in the spec I get zero division error. wth?
-
-commit 4e24fe43a7d6c55a53880a1c347e836f12937ed4
-Author: Brian Ford <brixen@gmail.com>
-Date: Thu Feb 1 18:03:13 2007 +0000
-
- Added more specs around zero division behavior for Float and Fixnum.
-
-commit b8f412ee2bf3701acd211372d28ec596d6858ac8
-Author: Brian Ford <brixen@gmail.com>
-Date: Thu Feb 1 18:01:44 2007 +0000
-
- Added more specs around zero division behavior for Float and Fixnum.
-
-commit 17a17e3008422bab9e91f8464d1ce2823c13ce78
-Author: Brian Ford <brixen@gmail.com>
-Date: Thu Feb 1 17:51:47 2007 +0000
-
- Added try spec helper method for spec'ing things that raise exceptions. Added more Float specs that describe division by 0 behavior.
-
-commit 2c2bfc3663a34fbf4fd70a5787236ec8b9a87024
-Author: Brian Ford <brixen@gmail.com>
-Date: Thu Feb 1 17:22:39 2007 +0000
-
- Added spec for Float#% when other is zero to show current implementation is broken.
-
-commit d1ddd71d5bd45df0c16651ecad2db3c1b75d90f8
-Author: Brian Ford <brixen@gmail.com>
-Date: Thu Feb 1 17:06:56 2007 +0000
-
- Reverted mae's breakage to Float. seriously mae: you did NOT run the float specs and you did NOT write new specs for the behavior you were changing so you did NOT understand what you were doing. As a good CS student, you can negate the above to know what you SHOULD do. ;) Please, WRITE and RUN your specs.
-
-commit b2e08a170d1ab222d67d8767fa880a5e21c5bf74
-Author: Mae <mae@unknown>
-Date: Thu Feb 1 10:53:48 2007 +0000
-
- know when to shoot your baby in the crib -- cleanup outdated unused code
-
-commit aac75dd658c96cf930852d86dbc79b66830bace5
-Author: Eero Saynatkari <eero@kittensoft.org>
-Date: Thu Feb 1 09:12:03 2007 +0000
-
- Improved specs for Hash.[].
-
-commit 40f637f2685e969f097fbbb2ffa3f0173e6f9866
-Author: Mae <mae@unknown>
-Date: Thu Feb 1 02:44:14 2007 +0000
-
- Fixed my pure ruby Numeric#floor and Numeric#ceil methods
- - Please smash your c primitive brix BWAHAHA
- - Also implemented eql? for float and now all 32 float specs pass
- - Added some edge cases for ceil/float that were not previously covered in specs
-
-commit 5cc6f6b6068e945c6f5896370ee20567e57122e7
-Author: Brian Ford <brixen@gmail.com>
-Date: Wed Jan 31 11:24:23 2007 +0000
-
- Added Float#round. We now have 32 of 32 float specs passing. Please confirm on your platform.
-
-commit 9b902a80a008120a86ae18d4abff04d42efefc8f
-Author: Brian Ford <brixen@gmail.com>
-Date: Wed Jan 31 06:22:10 2007 +0000
-
- Folded in coerce specs.
-
-commit 09e61132d5b9e9b08d27f2f51db9580808bb370e
-Author: Brian Ford <brixen@gmail.com>
-Date: Wed Jan 31 03:22:23 2007 +0000
-
- Created spec/incompatible for specs that show where Rubinius is incompatible with other implementations. Added bignum_spec and fixnum_spec to incompatible dir. Under MRI, Bignum.coerce(Fixnum) => [Bignum, Bignum] whereas Fixnum.coerce(Bignum) => [Float, Float]. Since Bignum should be a seamless extension of Fixnum, this behavior in MRI seems less than consistent. Under Rubinius, mixed Fixnum and Bignum promote to Bignum uniformly, and this makes much more sense. There are other places where Rubinius implementation may deviate from MRI, so spec/incompatible is for describing those behaviors. Updated coerce specs.
-
-commit cb52bb9633d0e323d2f7d6c90879fb7decfea7d7
-Author: Brian Ford <brixen@gmail.com>
-Date: Tue Jan 30 10:44:46 2007 +0000
-
- Added Numeric#coerce primitive. Reimplemented a number of primitves and methods on Fixnum, Float, Bignum to use Numeric#coerce rather than implementing knowledge of one another all over the place. Folded in mae's coerce specs. There is currently a (desirable IMHO) incompatibility in Numeric#coerce in that Bignum.coerce(Fixnum) == Fixnum.coerce(Bignum). There are a lot of other methods that need to be reimplemented using Numeric#coerce. Also, bignum_compare needs to be implemented (just returns 0 atm).
-
-commit e1aa382f2d596a73ef20dfde4184af7a721724e9
-Author: Mae <mae@unknown>
-Date: Tue Jan 30 00:26:11 2007 +0000
-
- added specs for coercion of Fixnum, Bignum, and Float
-
-commit bd292d64a511eba51ea1569870bcf0fa365c903d
-Author: Cabo <cabo@unknown>
-Date: Sun Jan 28 21:05:10 2007 +0000
-
- include yesterday's failed cases
-
-commit 7cac7f32e5c80e78aa75dfed7f4822e65d1ab4df
-Author: Brian Ford <brixen@gmail.com>
-Date: Sun Jan 28 08:08:12 2007 +0000
-
- committing rue's continuation specs. doomo arigatoo.
-
-commit f542b93031f8982daa13777d2eada81068e96ad5
-Author: Brian Ford <brixen@gmail.com>
-Date: Sun Jan 28 07:03:46 2007 +0000
-
- committing rue's class specs. thanks rue!
-
-commit 319b6f194d3c699a75de8da2ba3b53b8a4feffb1
-Author: Brian Ford <brixen@gmail.com>
-Date: Sun Jan 28 04:49:01 2007 +0000
-
- Commiting rue's binding specs.
-
-commit d8326b1321cc09c0aa64f441d2a81df6735603fd
-Author: Cabo <cabo@unknown>
-Date: Sat Jan 27 00:02:33 2007 +0000
-
- remove superfluous p from "& should create an array with no
- duplicates" (which now passes)
-
-commit 7d3baf10a79c1500e660fe5566ba8f3107d5a826
-Author: Hurdlea <hurdlea@unknown>
-Date: Thu Jan 25 05:43:50 2007 +0000
-
- * Added MatchData specs
-
-commit 2d9966c9c30e541c18ac77ca646a1af41daf702e
-Author: Hurdlea <hurdlea@unknown>
-Date: Thu Jan 25 05:42:44 2007 +0000
-
- * Added Match2 and correct Match3 in compiler.rb
- * Added alias String#to_str
- * Tweaked a few regexep specs for string return types
- * Fixed MatchData#length so it uses Tuple#fields to get the no. items
-
-commit 0d9f9e21c2a268e0710c963c745f07d494e2ab1f
-Author: Brian Ford <brixen@gmail.com>
-Date: Wed Jan 24 21:43:17 2007 +0000
-
- Commiting zimbatm's update to exception_spec.
-
-commit 037d8b29872f1c4a81108a0713afd78cbdf9b484
-Author: Brian Ford <brixen@gmail.com>
-Date: Sat Jan 20 04:03:20 2007 +0000
-
- a few more tweaks to get string specs to execute with rcompile and shotgun.
-
-commit cfe7a6b4c87ac3ffccaeb7e70b9e6c386054e052
-Author: Brian Ford <brixen@gmail.com>
-Date: Sat Jan 20 03:49:01 2007 +0000
-
- added parser dir under spec. added parser/symbol_spec.rb to capture parsing a complex symbol like :' for one or two', which rcompile and shotgun choke on at the moment. removed this from core/string_spec because it crashes shotgun and makes it impossible to run all the specs.
-
-commit d39040ab1563f063192a3835723cfbae7bf147cb
-Author: Cabo <cabo@unknown>
-Date: Fri Jan 19 23:45:52 2007 +0000
-
- lib/kernel.rbc is no longer a required (or wanted) command line argument
-
-commit 4774788e0ae9b24b3ff0b769aede0ba2de3f00b1
-Author: Brian Ford <brixen@gmail.com>
-Date: Fri Jan 19 21:05:10 2007 +0000
-
- added correct guard on Array#first to return nil when array is empty. added specs for #first and #last to describe this behavior. Thanks to cabo for finding this.
-
-commit baf1453678c9906c65b2f7c82bdb0e179e22d1b8
-Author: Brian Ford <brixen@gmail.com>
-Date: Fri Jan 19 02:49:02 2007 +0000
-
- added some minor changes to structure and wording of language/expression_spec. removed array and defined spec from language directory since they were added to language/literals directory. renamed several spec files to follow naming conventions.
-
-commit 7a24923ab9b79b226b6d8831e834ab509d5d2b76
-Author: Brian Ford <brixen@gmail.com>
-Date: Fri Jan 19 01:27:10 2007 +0000
-
- committing zimbatm's patch to language specs. super nice and thank you. please give zimbatm a commit bit!
-
-commit 9cd8c779a88f48604733afbe4357b7101a487669
-Author: Vic <vic@unknown>
-Date: Thu Jan 18 22:20:34 2007 +0000
-
- Added Proc.given, the analog of MethodContext.current
- Proc.given obtains the proc given to the current MethodContext.
- Later will be able to get a Proc from a given Binding.
-
- Original author: Victor Hugo Borja <vic@rubyforge.org>
- Date: 2007-01-18 16:16:06+00:00
-
-commit 50c42413d33951397a46edb55ca910a2e8fb87e6
-Author: Vic <vic@unknown>
-Date: Thu Jan 18 21:34:29 2007 +0000
-
- No output is available for specs if the returning value is a Numeric or Symbol
- When the :example execution on shotgun evaluates to a Numeric or Symbol, no method
- :stdout is added, because these object do not have singleton-classes on MRI.
- If you really need both, stdout and a Numeric/Symbol, your evaluation may lead to
- an array containing that Numeric/Symbol.
-
- Also saved MRI from getting eval errors in cases like the following:
-
- example do
- class A; end
- A.new
- end
-
- This leads to the following being evaled by MRI: [ #<A:0xb7a69c8c> , stdout]
- which causes an error because of #<A:0xb7a69c8c> being invalid ruby syntax.
- This patch fixes this situation by converting #<A:0xb7a69c8c> into "#<A:0xb7a69c8c>"
-
- Original author: Victor Hugo Borja <vic@rubyforge.org>
- Date: 2007-01-18 15:23:55+00:00
-
-commit ec5bea103b4b96ecde54668e47ab9e10ac8ec4ee
-Author: Hurdlea <hurdlea@unknown>
-Date: Thu Jan 18 21:04:22 2007 +0000
-
- * Added bitwsie operators to Fixnum & | ^ << >> ~
- * Split the fixnum specs into coerced and non-coerced tests
- * Added primitives to support fixnum bitwise ops
- * Fixed a bounds tests in Interger#chr
-
-commit 238d7e0611e9198c28a5e0ebe684bc7f1f03bf0f
-Author: Vic <vic@unknown>
-Date: Thu Jan 18 20:11:58 2007 +0000
-
- [rAdded specs for the new STDOUT support] Empty log message
-
- Original author: Victor Hugo Borja <vic@rubyforge.org>
- Date: 2007-01-18 13:44:19+00:00
-
-commit 859b26f38749f160a706ed9dbb8f2a80886e94ef
-Author: Vic <vic@unknown>
-Date: Thu Jan 18 19:37:03 2007 +0000
-
- Allow to specs to test what is written to STDOUT
-
- also added String#unindent on spec_helper to help make output heredocs more readable.
-
- You can access both the evaluation result and the stdout produced, ej:
-
- context "Rubinius target" do
-
- specify "should allow to get the resulting STDOUT" do
- example do
- puts "hola"
- puts "space is significant in this heredoc"
- puts "unindent removes the first blanks found on the first line"
- puts "on each of these lines"
- puts "adios"
- end.stdout.should == <<-OUT.unindent
- hola
- space is significant in this heredoc
- unindent removes the first blanks found on the first line
- on each of these lines
- adios
- OUT
- end
-
- specify "should allow to get the lines written to STDOUT" do
- example do
- puts "hello"
- end.stdout_lines.length == 1
-
- example do
- print "bye"
- end.stdout_lines.first.should == "bye"
- end
-
- specify "should allow to access the evaluation result along with STDOUT" do
- result = example do
- puts "ok"
- Object.new.class
- end
- result.should == Object
- result.stdout_lines.should == ["ok\n"]
- end
-
- end
-
-commit e17069925d139c93acec00161a7111e6c78d54bb
-Author: Brian Ford <brixen@gmail.com>
-Date: Thu Jan 18 08:44:33 2007 +0000
-
- converted shotgun-test/test_sexp to spec/shotgun/sexp_spec. thanks to Victor Borja's recent additions to rubinius_target, it was a breeze.
-
-commit 46e9a259bc2212dee1fa7efa8ead468e63970731
-Author: Brian Ford <brixen@gmail.com>
-Date: Wed Jan 17 08:02:35 2007 +0000
-
- filled in the rest of the documented String instance methods except #pack.
-
-commit dfd08d6536ea497cf86d06ca503206d54b19479d
-Author: Cabo <cabo@unknown>
-Date: Tue Jan 16 10:24:18 2007 +0000
-
- A bit more array fun (and lots of FIXMEs)
-
-commit b1e50e43d8d79a5dbd82345134ecd4bdffc6d182
-Author: Brian Ford <brixen@gmail.com>
-Date: Tue Jan 16 08:46:48 2007 +0000
-
- and yet a few more string specs. these will asymptotically approach done.
-
-commit 4048d3dfa90a6de54ea2ed0aec2ec6adafb50b0c
-Author: Cabo <cabo@unknown>
-Date: Tue Jan 16 07:02:50 2007 +0000
-
- I want to see what 'Shotgun has crashed' means, beautiful backtrace and all
-
-commit 0387baa914cb35c589c7872f7f98cf9f8ee10711
-Author: Cabo <cabo@unknown>
-Date: Tue Jan 16 02:19:45 2007 +0000
-
- Fix Array#slice! bug workarounds
-
-commit c6b110b47667c5d6750492177492434f4c0446f8
-Author: Cabo <cabo@unknown>
-Date: Tue Jan 16 01:33:18 2007 +0000
-
- add shift spec and fix String#strip so it works
-
-commit 19bcc086b7674f12e01f879a6ca83f3289feb770
-Author: Cabo <cabo@unknown>
-Date: Tue Jan 16 00:06:03 2007 +0000
-
- Integer#chr should return a new string (spec)
-
-commit 5aa81499711ad5e57f5dfc03417f23705eb79b44
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Jan 15 23:48:16 2007 +0000
-
- a few more string specs.
-
-commit 8cd873e183c62b8929305ea54b9a437ca22ddb28
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Jan 15 22:42:24 2007 +0000
-
- committing Victor's define_method patch.
-
-commit cd04f4c570cd95fb869f025c4dac6e9342e2ba2a
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Jan 15 22:02:23 2007 +0000
-
- committing Victor Hugo Borja's instance_eval patch.
-
-commit a481142988d585bb8fa54e0186f5c9cf88ada8d9
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Jan 15 20:13:03 2007 +0000
-
- added a code method to mri_target and jruby_target to parallel the behavior of the code method for rubinius_target. now core/proc_spec.rb is passing with mri target.
-
-commit a4c621e8319349eda766f73ed9ca55f2a9323ac2
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Jan 15 19:08:22 2007 +0000
-
- checked in nicksieger's patch to spec_helper that enables specs to run on jruby, woohoo!
-
-commit 6b02aac6107b01258f85f9d15a77b498ad15e5b0
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Jan 15 18:06:23 2007 +0000
-
- checking in cabo's changes to target specs for jruby and rubinius. modified rubinius_target specs that compared paths to use should_match because a hash is used to generate part of the path.
-
-commit 6aa175d3367d76152476888ff1c52479530c56a2
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Jan 15 17:57:25 2007 +0000
-
- committing cabo's changes to remove heredocs from a number of specs. It is still possible to pass code as a source string to the example method. Use this if the block method is causing rubinius to choke on the ruby2ruby generated source. soon, soon, we'll have rspec running (I hope\!).
-
-commit 6679194f8e6afdbbb71f5213508bb81f12fdb2e7
-Author: Brian Ford <brixen@gmail.com>
-Date: Sun Jan 14 17:28:06 2007 +0000
-
- incorporated nicksieger's changes to mri_target removing needless requires. added jruby_target.rb and spec to parallel mri_target.rb.
-
-commit f573b9c16efccb92eec98d923831deafc7a3c809
-Author: Brian Ford <brixen@gmail.com>
-Date: Sun Jan 14 08:10:24 2007 +0000
-
- converted mri_target to use eval, yield to execute specs. converted some specs to new style. addressed issues with hash specs that implicitly relied on hash ordering, fixed numerous issues that result from loss of floating-point precision by using #inspect where necessary (more of these issues may arise in the specs on different platforms). added spec templates for documented String instance methods (many of which need to be filled in).
-
-commit 917cd03e5bee749d18d8d0c257381bca2362abbd
-Author: Brian Ford <brixen@gmail.com>
-Date: Sun Jan 14 00:11:17 2007 +0000
-
- checking in Alan Hurdles patch to allow running specific files, e.g. COMPILER=rcompile rake spec:core:array .
-
-commit 508eaacf9aaf67465a78ac53284ba6f06c3bcb3d
-Author: Brian Ford <brixen@gmail.com>
-Date: Sat Jan 13 21:09:51 2007 +0000
-
- added integer specs. these should be platform independent but other platforms may have some trouble with spec for 'chr' ;)
-
-commit 21463a87bac2121fa61c1c99927cdb039c724d89
-Author: Brian Ford <brixen@gmail.com>
-Date: Sat Jan 13 20:37:37 2007 +0000
-
- implemented the rest of the hash specs, this should cover the documented class, instance methods.
-
-commit 3656a95a1829b0be1a8b0d968e0a9e433ef9c847
-Author: Frederick <frederick@unknown>
-Date: Sat Jan 13 13:14:41 2007 +0000
-
- Implements Fixnum#size
-
-commit ca38e49022f6bdf41b0e98409d3fec3528e59bfd
-Author: Frederick <frederick@unknown>
-Date: Sat Jan 13 12:54:30 2007 +0000
-
- shotgun/string_spec.rb now follow new spec conventions
-
-commit 1b684385fe970f11a526e280d15c3f147a826886
-Author: Frederick <frederick@unknown>
-Date: Sat Jan 13 12:42:38 2007 +0000
-
- language/expression_spec.rb and language/exception_spec.rb now use new spec style
-
-commit f62c2539a1eef27b356e4d809d76c4f9ddecd2a5
-Author: Brian Ford <brixen@gmail.com>
-Date: Sat Jan 13 08:14:12 2007 +0000
-
- new style specs for hash. numerous of these need to be implemented but there should be templates for all the documented class and instance methods.
-
-commit 28083a6e6dc89502d1c76e2a16f0003a589f01e0
-Author: Brian Ford <brixen@gmail.com>
-Date: Sat Jan 13 08:12:37 2007 +0000
-
- one more, bignum.
-
-commit 076aab00b795ff777c5ac11955130f12f69e1377
-Author: Brian Ford <brixen@gmail.com>
-Date: Sat Jan 13 08:07:30 2007 +0000
-
- new style specs for float, fixnum, symbol, string, object, file, module, regexp, range.
-
-commit 0161ab3527e91674eed4eeaad029eee654325155
-Author: Brian Ford <brixen@gmail.com>
-Date: Sat Jan 13 07:39:26 2007 +0000
-
- true, false, nil, enumerable specs are new style.
-
-commit bb11cce41a472606312eb0a62948c4a339f23dd9
-Author: Brian Ford <brixen@gmail.com>
-Date: Sat Jan 13 07:27:05 2007 +0000
-
- converted existing class and comparable specs to new style.
-
-commit 595b83a75044772136b83eaf84402ed73eb79da5
-Author: Brian Ford <brixen@gmail.com>
-Date: Sat Jan 13 07:08:14 2007 +0000
-
- ladies and gentlemen, a huge round of applause and gratitude to headius for inspiration and help getting specs in a form that will easily run on MRI, JRuby, and Rubinius. Checking in the modified spec/core/array_spec.rb. The rest to follow. The mri_target is still using the sub-process method, but that should be superfluous now.
-
-commit ae75e76915432757be3c9a7126c2ee8c6656652c
-Author: Brian Ford <brixen@gmail.com>
-Date: Fri Jan 12 08:13:29 2007 +0000
-
- added a bunch more specs for array. two still need to be filled out. I think that covers all the documented class and instance methods.
-
-commit 8daf38e0f99eed3e42d654086a98e673d9855bef
-Author: Brian Ford <brixen@gmail.com>
-Date: Fri Jan 12 01:14:35 2007 +0000
-
- checking in more of cabo's changes to kernel/core/array.rb and array specs.
-
-commit 0a349583aba629748d5e85de0ede6f38730512f1
-Author: Brian Ford <brixen@gmail.com>
-Date: Fri Jan 12 00:57:22 2007 +0000
-
- checking in cabo's changes to array and array spec.
-
-commit 052512fea9b74e532ef6b68612c81061ad84e4f2
-Author: Brian Ford <brixen@gmail.com>
-Date: Thu Jan 11 05:16:47 2007 +0000
-
- finished Bignum specs for documented instance methods.
-
-commit 7f4786c85b2e0e95abc2728492ed1a7424d01dbe
-Author: Frederick <frederick@unknown>
-Date: Wed Jan 10 23:44:34 2007 +0000
-
- Added File.mtime, File.atime, File.ctime
- Avoid reusing old .rbc is .rb is newer
- Remove useless CHECK_PTR
-
-commit 70458d6446f0858570571a64b5294c0bb4ac358f
-Author: Brian Ford <brixen@gmail.com>
-Date: Wed Jan 10 17:40:36 2007 +0000
-
- moved exception and expression specs to spec/language. added stub for time_spec in spec/library. updated a string spec that was failing. added specs for all (I think) float and fixnum instance methods. added specs for bignum, but about half need examples.
-
-commit ffe4a7a48dcc116f73b89b9a046d4430ed51975a
-Author: Brian Ford <brixen@gmail.com>
-Date: Tue Jan 9 18:07:31 2007 +0000
-
- removed duplicate bk task from Rakefile. removed shotgun-tests/test-array.rb as all tests have corresponding specs in spec/core. added beginning of specs for bignum separated into spec/core for stuff that should be indendent of mri or rubinius, and spec/shotgun for implementation specific.
-
-commit 946d0b42293ea081666e71e13c4b77d5b5dba886
-Author: Brian Ford <brixen@gmail.com>
-Date: Sun Jan 7 05:38:33 2007 +0000
-
- checking in Alan Hurdles patches to regexp, string, and spec_string.
-
-commit 5f035040c4b3ce842fff4b39d1ca657c97deb7a4
-Author: Brian Ford <brixen@gmail.com>
-Date: Sun Jan 7 03:03:31 2007 +0000
-
- updated mri and rubinius target impl specs. added environment option for running rubinius target using obsolete.rcompile, e.g.: COMPILER=rcompile spec spec/core/symbol_spec -f s. If you don't use the COMPILER env var, rubinius target will use shotgun to compile.
-
-commit 6ea911ae5740508cdbd8feb5cddba5b8bf7fe1c3
-Author: Brian Ford <brixen@gmail.com>
-Date: Sun Jan 7 02:32:35 2007 +0000
-
- changed some Hash specs to use instance vars rather than local vars because some versions of Ruby2Ruby output borked sexp for block local vars. E.g. use @h rather than h.
-
-commit 256fe9a8cada7ed512556e1701a5264670c6c28f
-Author: Mae <mae@unknown>
-Date: Sat Jan 6 07:55:32 2007 +0000
-
- made regression spec for buggy behavior of [1,2,3][2..-1]
-
-commit 0ffe8a3e6cd92bc5cd872cc22919885ea80366a0
-Author: Brian Ford <brixen@gmail.com>
-Date: Fri Jan 5 20:05:03 2007 +0000
-
- added spec for String#reverse! to Laurent Julliard's spec for String#reverse and his implementation of both methods.
-
-commit 170737d2c77a4b2de862380cb87f7705560cca64
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Fri Jan 5 18:24:32 2007 +0000
-
- * Much better implementation of Hash#key?
- * Added working support for default Hash values and procs
- * Added hash_get_undef for situations where nil and undefined hash values need to be differentiated
-
-commit 332378a8900f09009626cb7c4dbf0c8740a657c7
-Author: Brian Ford <brixen@gmail.com>
-Date: Fri Jan 5 07:31:56 2007 +0000
-
- added specs for aliases of Hash#key?
-
-commit 27c3b2aeaa3208a7e0218f051f623b93e2e635d8
-Author: Brian Ford <brixen@gmail.com>
-Date: Fri Jan 5 07:28:29 2007 +0000
-
- added spec for Hash#key?
-
-commit 2e88d941bc1b1ea506396a915e3c3c4e3dfd1601
-Author: Brian Ford <brixen@gmail.com>
-Date: Fri Jan 5 06:35:09 2007 +0000
-
- updated and simplified float and fixnum specs.
-
-commit e4a5b6d8529d60e62875004bb60f33c6452ccf98
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Fri Jan 5 06:28:04 2007 +0000
-
- * defined?() now handles: defined?(Kernel.puts) flavors of arguments.
-
-commit 27660379c09e561590cf1bc48a9459e29fc00e9c
-Author: Mae <mae@unknown>
-Date: Fri Jan 5 06:10:11 2007 +0000
-
- Added spec for cvar declaration in class bodies
-
-commit a9b7b9f7db02ba78514eb869c2c52d4e5067f8d2
-Author: Brian Ford <brixen@gmail.com>
-Date: Thu Jan 4 08:08:59 2007 +0000
-
- added class def source code to specs.
-
-commit cdfa499ee238671c655800a81b51611704383500
-Author: Mae <mae@unknown>
-Date: Thu Jan 4 07:54:20 2007 +0000
-
- fixed typo in spec still 7 failing specs *GLARES AT DEFILER*
-
-commit 03be9ca7da61363f8f0a02ee951bbafaf297c31b
-Author: Brian Ford <brixen@gmail.com>
-Date: Thu Jan 4 07:43:58 2007 +0000
-
- added specs for Module#const_defined?.
-
-commit c511d4c7a75001f2597b13f9fc2e910d2dd4d9a2
-Author: Mae <mae@unknown>
-Date: Thu Jan 4 06:54:07 2007 +0000
-
- changed defined spec to be more dumb and just figure out whether its a true/false evaluation
-
-commit 4d9135f9694e4b692faf6a4c7b8dcd59f79f5069
-Author: Brian Ford <brixen@gmail.com>
-Date: Thu Jan 4 06:38:57 2007 +0000
-
- added library spec (beginning) for enumerator. trivial update for comparable specs. added specs for enumerable.
-
-commit 3de6e339526b1402f8995a5acc38fde707ec0695
-Author: Brian Ford <brixen@gmail.com>
-Date: Thu Jan 4 00:34:50 2007 +0000
-
- added specs for comparable methods.
-
-commit ea25c6b17533c280e640dc97e3fec1207fb4be7b
-Author: Mae <mae@unknown>
-Date: Wed Jan 3 17:47:09 2007 +0000
-
- almost done with defined? spec -- still need 'yield' and 'zsuper' test cases
- from project dir: SPEC_TARGET=mri spec spec/language/defined_spec.rb
- change SPEC_TARGET to rubinius to test on rubinius
-
-commit b795f6c2dc98952e7fa7231cded9156ade962b18
-Author: Mae <mae@unknown>
-Date: Wed Jan 3 17:25:31 2007 +0000
-
- added incomplete specs for defined? behavior -- more work to be done
-
-commit 25e30e4668f1ef814bfb1182e032449263651590
-Author: Brian Ford <brixen@gmail.com>
-Date: Wed Jan 3 17:17:03 2007 +0000
-
- small fix to mri_target to generate reasonable cache soure name. added a couple specs.
-
-commit 3b5bc977ea2a4a3ad42ff83bcab2966459c262c0
-Author: Brian Ford <brixen@gmail.com>
-Date: Wed Jan 3 08:51:18 2007 +0000
-
- added object_spec for methods provided by Object, even mixed in ones. added a few specs for basic class, module, exceptions.
-
-commit c4f4dd722658b2a09ae273092744b76e65ce05b2
-Author: Brian Ford <brixen@gmail.com>
-Date: Wed Jan 3 02:36:58 2007 +0000
-
- renamed flow_control_spec to expression_spec as these are all covered under heading expressions in pickaxe. run expression spec with mri target and then rubinius target to see an interesting rubinius failure. updated an incorrect string splice spec.
-
-commit ef8aa2f74896944134f5a8884ccc723ca9b472c1
-Author: Brian Ford <brixen@gmail.com>
-Date: Tue Jan 2 01:40:16 2007 +0000
-
- separated specs that are shotgun specific methods (e.g. String#prefix?) into spec/shotgun/... fixed wrong specs so that all pass under mri/mir configuration.
-
-commit 8661488b40b9fccccf356889834c6a9162c8bebf
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Jan 1 22:37:41 2007 +0000
-
- very quick n' dirty implementation of example et al to run specs under mri like under rubinius.
-
-commit 0ebfa43e222ca4794243d36f10c2e429e930f527
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Jan 1 20:47:13 2007 +0000
-
- added methods for TrueClass and FalseClass, updated specs for each.
-
-commit e9bb50ced8bf997535f0bc9c6deeeffb86c40879
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Jan 1 20:29:37 2007 +0000
-
- added specs for true, false, nil.
-
-commit c30b0e38b88c686c11c6f7442e027d685d405505
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Jan 1 18:59:59 2007 +0000
-
- added spec templates for true, false, nil, class, module, enumerable, comparable, flow_control, exception. added specs to various others.
-
-commit b26777261970c213506e444b90412543f39b3c59
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Jan 1 18:58:37 2007 +0000
-
- added that rubinius target example method takes a default argument to pass strings of code to allow for creating classes, since classes can't be defined in a method body and for now example puts the block code into a method using ruby2ruby.
-
-commit 560c5a1331c76bce07289f1e5950b816fe7c9c24
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Jan 1 01:17:44 2007 +0000
-
- added more string specs.
-
-commit 807864c76b701f6f976f3f2935599ba875fcc10e
-Author: Brian Ford <brixen@gmail.com>
-Date: Sun Dec 31 23:13:16 2006 +0000
-
- added more core specs (or templates for specs) to cover existing tests in shotgun-tests.
-
-commit 8f83b600b12722d46b9791b2e2c3a399618474a0
-Author: Brian Ford <brixen@gmail.com>
-Date: Sun Dec 31 21:23:07 2006 +0000
-
- removed shotgun/primitives_spec as spec/shotgun should be for shotgun-specific code. created spec/core for ruby core classes. spec/library is now for ruby stdlib classes. added more array specs.
-
-commit 58cc3ce5bd8b84a151b1a6e2334845f268ab894a
-Author: Brian Ford <brixen@gmail.com>
-Date: Sun Dec 31 08:58:50 2006 +0000
-
- added specs for class methods of Regexp. added alias Regexp.compile for Regexp.new.
-
-commit 0a5a31bc6ef539eeda3de951ab633f5152d58153
-Author: Brian Ford <brixen@gmail.com>
-Date: Sun Dec 31 02:01:34 2006 +0000
-
- added specs for symbol methods. added aliases to symbol for to_i, to_int, and id2name.
-
-commit cdfa28e492b8edfa55b950b06ce05ebb04b64643
-Author: Brian Ford <brixen@gmail.com>
-Date: Sat Dec 30 17:27:18 2006 +0000
-
- changed example method for rubinius_target to raise exception if compile fails. added specs for range.
-
-commit 5316e652084b8624828d0a9306f580bfc93184dc
-Author: Brian Ford <brixen@gmail.com>
-Date: Fri Dec 29 20:37:46 2006 +0000
-
- added spec files in spec/library for basic types (according to pickaxe book). added specs for all the methods in Regexp. there are many failing specs for a variety of reasons, but the goal is to get a good overview of where work needs to be done. more specs to follow.
-
-commit 06cd5ad6da819f2894996e42f4da70321767c9c7
-Author: Mae <mae@unknown>
-Date: Thu Dec 28 07:36:21 2006 +0000
-
- Added Array expressions gleaned from spec/library/array_spec.rb as proof of concept for rapid compatibility testing
- - A thought occurred to me that the scope for this type of testing might be limited severely to simple compatibility testing
- - Its not very human understandable as a spec -- it just unravels incompatibilities given no hint as to why things are the way they are.
- - It lets the ruby rval speak for itself
- - Is this useful for rubinius?!
-
-commit 1c1fc9335aee4acbcd692c555b0ca194c5301013
-Author: Frederick <frederick@unknown>
-Date: Wed Dec 27 22:46:43 2006 +0000
-
- Fix a bug in the allocation of a string. The underlying storage (byte array) did not have the correct size, leading to a write in a non allocated memory area.
- The rationale is that, the storage are should be able to store the string plus a terminal \0. As we're allocating per block of 4 bytes (a word) we need to get the nearest multiple of 4.
- This patch adds a spec to highlight the bug, and a fix to .. well, fix it ;)
-
-commit cdfdc272b71bbfca23b4c17e5572ebd2b966615e
-Author: Mae <mae@unknown>
-Date: Tue Dec 26 17:52:24 2006 +0000
-
- Added my idea of a sanity check against MRI for compatibility purposes
- - try it out!
- - rake spec:compatibility
- - example compatibility expressions go in spec/compatibility/expressions/*
- - all the expression files are line-separated ruby expressions that return something basic and eval-able
-
-commit f9887648c7f239f8c862158b39f44b2410377204
-Author: Brian Ford <brixen@gmail.com>
-Date: Fri Dec 22 19:20:58 2006 +0000
-
- added spec file for String methods.
-
-commit 8178e4478977c81940ac4bdcd8bea608be11708b
-Author: Brian Ford <brixen@gmail.com>
-Date: Fri Dec 22 17:14:46 2006 +0000
-
- fixed that ruby2ruby was not generating correct ruby source when a local var was used in a block. changed local var to instance var and it works, converted primitives_spec to new block-style.
-
-commit 8a00080a1edb864af7573e8f9761f65fa1202d07
-Author: Brian Ford <brixen@gmail.com>
-Date: Fri Dec 22 06:58:28 2006 +0000
-
- changed array_spec to not use local variables in blocks where possible because rubytoruby is not converting them to ruby source correctly. Array#uniq! fails at the moment. re-added that compile checks code-cache first so specs run faster.
-
-commit 4a199c559eebe73cd21d0997126b799f5d4e2be5
-Author: Brian Ford <brixen@gmail.com>
-Date: Fri Dec 22 06:00:21 2006 +0000
-
- converted array_spec.rb to block-style specs, but they still depend on strings to be output. rewrote spec_helper based on nicksieger's example code. some specs are failing due to bugs converting to sexp and back to ruby source.
-
-commit 854bbc3617559a2ceac975d79a57ffa825a5cda6
-Author: Brian Ford <brixen@gmail.com>
-Date: Fri Dec 22 03:34:18 2006 +0000
-
- added spec/targets for specs for 'target' part of host/target spec runner configuration. added mri_target and rubinius_target and specs.
-
-commit db81559c9c914413d2064b4202ec8ce43e503af2
-Author: Brian Ford <brixen@gmail.com>
-Date: Thu Dec 21 05:51:55 2006 +0000
-
- added spec:targets task to run specs for target part of host/target spec configuration. added specs for mri_target and rubinius_target.
-
-commit a243a70bd17ec7e9839b69bb18e63d5d943b6095
-Author: Brian Ford <brixen@gmail.com>
-Date: Wed Dec 20 19:02:01 2006 +0000
-
- updated primitives_spec to use example method.
-
-commit 9ce077283dd10c21377add499c5bcc4ea87cfe0f
-Author: Brian Ford <brixen@gmail.com>
-Date: Wed Dec 20 17:11:00 2006 +0000
-
- Changed method from rubinius to example for specs. This is in anticipation of having independent 'host' (system running rspec) and 'target' (system executing spec). Created parallel arrayb_spec that illustrates this with a mri/mri configuration. Also added spec_bhelper that is a *very rough* beginning for having mri/rubinius configuration using block-style specs.
-
-commit a8ad71a0da9e1a866521074743ea1dfcceb596cb
-Author: Wilson Bilkovich <wilson@supremetyrant.com>
-Date: Wed Dec 20 15:39:36 2006 +0000
-
- Applying 'array patch' from Jason Perkins (2006-12-20 8:30 EST)
-
-commit 82b3d880131e7080ebc6b4289b3954d89a988c13
-Author: Brian Ford <brixen@gmail.com>
-Date: Tue Dec 19 17:30:21 2006 +0000
-
- added more specs to array_spec. most of these are failing, so there seems to be a lot of Array that needs implementing.
-
-commit c24f0e83b4d446afd541ffefbcb313f199b684ee
-Author: Brian Ford <brixen@gmail.com>
-Date: Tue Dec 19 08:24:00 2006 +0000
-
- added specs for Array#* and <<, simplified other specs.
-
-commit 62b0737ce69768a8292bd3d9f13401ec8056f6eb
-Author: Brian Ford <brixen@gmail.com>
-Date: Tue Dec 19 07:46:39 2006 +0000
-
- fixed messed up spec for &.
-
-commit 7635389b2abf5c492952a49eb8251d6fb34250c7
-Author: Brian Ford <brixen@gmail.com>
-Date: Tue Dec 19 07:40:01 2006 +0000
-
- added spec for Array#&, which is currently unimplemented. updated spec_helper.
-
-commit 42b5e9fc47bcf6bcd403d25795c9bcf07bb5c007
-Author: Brian Ford <brixen@gmail.com>
-Date: Tue Dec 19 06:13:15 2006 +0000
-
- added spec tasks :only to run only spec, :language for high level language conformance spcs, :library for ruby stdlib implementation specs, and :shotgun for specs related to shotgun. rake spec will run all specs and tests. removed spec/spec_suite.rb because all specs can be run from rake. minor updates to spec_helper.
-
-commit da4c42890f4b8163b8d49de64bdb76c16b0e5d1f
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Dec 18 17:41:44 2006 +0000
-
- added shotgun dir under spec for things that relate to shotgun implementation of VM, like the prmitives_spec, while reserving spec/library for general ruby implementation of the std lib.
-
-commit 925cbf9f84f78a48189f7030c205942d266a6f66
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Dec 18 09:45:25 2006 +0000
-
- added Fixnum#% primitive implementation. changed array_spec to use Fixnum#%. fixed test_primitive test for Fixnum#%.
-
-commit 06e50e48a92e3fa7d1fc4d6b681872d08e5aeba3
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Dec 18 09:10:37 2006 +0000
-
- Added Fixnum#% primitive test, spec, cpu/primitive, stub.
-
-commit e0fbcf29f46dde89f65d13c1b6d7601a470cf223
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Dec 18 07:54:02 2006 +0000
-
- all ports of test_array test to array_spec are now passing.
-
-commit c2330c2ff65cfa964d954340fb0eb2507972efd5
-Author: Brian Ford <brixen@gmail.com>
-Date: Mon Dec 18 07:39:55 2006 +0000
-
- updated spec_helper to ensure code-cache dir exists. fixed several failing specs in array_spec by correcting expected value.
-
-commit 81cc03c6f7ce499da563543f00d273d3a9c3a184
-Author: Brian Ford <brixen@gmail.com>
-Date: Sun Dec 17 06:27:15 2006 +0000
-
- Ported the rest of test_array.rb tests to specs. Several of these specs are not passing but ported them all to illustrate behavior of specs.
-
-commit b4cb073931f403119a5ed9b63a2c915612a9c46f
-Author: Brian Ford <brixen@gmail.com>
-Date: Sun Dec 17 04:42:55 2006 +0000
-
- spec/spec_helper.rb rubinius method is a very naive port of shotgun-tests/helper.rb run_code method. spec/library/array_spec.rb is several ports of the tests in shotgun-tests/test_array.rb, which is testing /kernel/array.rb. In other words, you can now create specs that run under RSpec (which is running under MRI 1.8.x) that exercises the rubinius vm, shotgun, and the stdlib that is being written in ruby. Confused? Read the source, Luke. :)
-
-commit 1b37cd1ee800060fb215a52d2902c3f4b778a656
-Author: Brian Ford <brixen@gmail.com>
-Date: Sat Dec 16 07:55:41 2006 +0000
-
- Added spec dir with spec_suite.rb and spec_helper.rb provided by nullstyle.
diff --git a/spec/ruby/CONTRIBUTING.md b/spec/ruby/CONTRIBUTING.md
index fc88475970..a474e205f0 100644
--- a/spec/ruby/CONTRIBUTING.md
+++ b/spec/ruby/CONTRIBUTING.md
@@ -8,17 +8,19 @@ Spec are grouped in 5 separate top-level groups:
* `command_line`: for the ruby executable command-line flags (`-v`, `-e`, etc)
* `language`: for the language keywords and syntax constructs (`if`, `def`, `A::B`, etc)
-* `core`: for the core methods (`Fixnum#+`, `String#upcase`, no need to require anything)
+* `core`: for the core methods (`Integer#+`, `String#upcase`, no need to require anything)
* `library`: for the standard libraries methods (`CSV.new`, `YAML.parse`, need to require the stdlib)
* `optional/capi`: for functions available to the Ruby C-extension API
The exact file for methods is decided by the `#owner` of a method, for instance for `#group_by`:
+
```ruby
> [].method(:group_by)
=> #<Method: Array(Enumerable)#group_by>
> [].method(:group_by).owner
=> Enumerable
```
+
Which should therefore be specified in `core/enumerable/group_by_spec.rb`.
### MkSpec - a tool to generate the spec structure
@@ -53,12 +55,19 @@ which indicates the file was generated but the method unspecified.
Here is a list of frequently-used matchers, which should be enough for most specs.
There are a few extra specific matchers used in the couple specs that need it.
+The general idea is: add `.should` just before the predicate you expect to be truthy, and done!
+This works for most needs and provides a great error when it fails.
+It's immediately clear which method is used and there no need to remember a mapping like in RSpec between e.g. `eq` and `==`.
+See [this blog post](https://eregon.me/blog/2019/10/07/a-new-should-syntax.html) for the motivation behind that syntax.
+
+#### Comparison matchers
+
```ruby
(1 + 2).should == 3 # Calls #==
(1 + 2).should_not == 5
-File.should equal(File) # Calls #equal? (tests identity)
-(1 + 2).should eql(3) # Calls #eql? (Hash equality)
+File.should.equal?(File) # Calls #equal? (tests identity)
+(1 + 2).should.eql?(3) # Calls #eql? (Hash equality)
1.should < 2
2.should <= 2
@@ -66,32 +75,55 @@ File.should equal(File) # Calls #equal? (tests identity)
4.should > 3
"Hello".should =~ /l{2}/ # Calls #=~ (Regexp match)
+```
+
+#### Predicate matchers
+
+```ruby
+[].should.empty?
+[1,2,3].should.include?(2)
-[].should be_empty # Calls #empty?
-[1,2,3].should include(2) # Calls #include?
+"hello".should.start_with?("h")
+"hello".should.end_with?("o")
(0.1 + 0.2).should be_close(0.3, TOLERANCE) # (0.2-0.1).abs < TOLERANCE
-(0.0/0.0).should be_nan # Calls Float#nan?
-(1.0/0.0).should be_positive_infinity
-(-1.0/0.0).should be_negative_infinity
+(0.0/0.0).should.nan?
-3.14.should be_an_instance_of(Float) # Calls #instance_of?
-3.14.should be_kind_of(Numeric) # Calls #is_a?
-Numeric.should be_ancestor_of(Float) # Float.ancestors.include?(Numeric)
+3.14.should.instance_of?(Float) # Calls #instance_of?
+3.14.should.is_a?(Numeric) # Calls #is_a?
-3.14.should respond_to(:to_i) # Calls #respond_to?
-Fixnum.should have_instance_method(:+)
-Array.should have_method(:new)
-# Also have_constant, have_private_instance_method, have_singleton_method, etc
+3.14.should.respond_to?(:to_i)
+Integer.should.method_defined?(:+, false)
+```
+
+#### Exception matchers
+
+```ruby
+-> {
+ raise "oops"
+}.should.raise(RuntimeError, /oops/)
-> {
raise "oops"
-}.should raise_error(RuntimeError, /oops/)
+}.should.raise(RuntimeError) { |e|
+ # Custom checks on the Exception object
+ e.message.should.include?("oops")
+ e.cause.should == nil
+}
+```
+
+##### `should_not.raise`
-# To avoid! Instead, use an expectation testing what the code in the lambda does.
-# If an exception is raised, it will fail the example anyway.
--> { ... }.should_not raise_error
+**Avoid this!** Instead, use an expectation testing what the code in the lambda does.
+If an exception is raised, it will fail the example anyway.
+```ruby
+-> { ... }.should_not.raise
+```
+
+#### Warning matcher
+
+```ruby
-> {
Fixnum
}.should complain(/constant ::Fixnum is deprecated/) # Expect a warning
@@ -102,15 +134,21 @@ Array.should have_method(:new)
Different guards are available as defined by mspec.
Here is a list of the most commonly-used guards:
+#### Version guards
+
```ruby
-ruby_version_is ""..."2.4" do
- # Specs for RUBY_VERSION < 2.4
+ruby_version_is ""..."3.2" do
+ # Specs for RUBY_VERSION < 3.2
end
-ruby_version_is "2.4" do
- # Specs for RUBY_VERSION >= 2.4
+ruby_version_is "3.2" do
+ # Specs for RUBY_VERSION >= 3.2
end
+```
+
+#### Platform guards
+```ruby
platform_is :windows do
# Specs only valid on Windows
end
@@ -125,39 +163,57 @@ end
platform_is_not :linux, :darwin do # Not Linux and not Darwin
end
-platform_is wordsize: 64 do
+platform_is pointer_size: 64 do
# 64-bit platform
end
big_endian do
# Big-endian platform
end
+```
+
+#### Guard for bug
+
+In case there is a bug in MRI and the fix will be backported to previous versions.
+If it is not backported or not likely, use `ruby_version_is` instead.
+First, file a bug at https://bugs.ruby-lang.org/.
+The problem is `ruby_bug` would make non-MRI implementations fail this spec while MRI itself does not pass it, so it should only be used if the bug is/will be fixed and backported.
+Otherwise, non-MRI implementations would have to choose between being incompatible with the latest release of MRI (which has the bug) to pass the spec, or behave the same as the latest release of MRI (which has the bug) and fail the spec, both which make no sense.
-# In case there is a bug in MRI but the expected behavior is obvious
-# First file a bug at https://bugs.ruby-lang.org/
-# It is better to use a ruby_version_is guard if there was a release with the fix
-ruby_bug '#13669', ''...'2.5' do
+IOW, `ruby_bug '#NN', ''...'X.Y' do` is equivalent to `guard_not { RUBY_ENGINE == "ruby" && ruby_version_is ''...'X.Y' } do`. So it skips tests on MRI on specified versions (where a bug is present) and runs tests on alternative implementations only.
+
+```ruby
+ruby_bug '#13669', ''...'3.2' do
it "works like this" do
# Specify the expected behavior here, not the bug
end
end
+```
+#### Combining guards
-# Combining guards
-guard -> { platform_is :windows and ruby_version_is ""..."2.3" } do
- # Windows and RUBY_VERSION < 2.3
+```ruby
+guard -> { platform_is :windows and ruby_version_is ""..."3.2" } do
+ # Windows and RUBY_VERSION < 3.2
end
-guard_not -> { platform_is :windows and ruby_version_is ""..."2.3" } do
+guard_not -> { platform_is :windows and ruby_version_is ""..."3.2" } do
# The opposite
end
+```
+
+#### Custom guard
-# Custom guard
+```ruby
max_uint = (1 << 32) - 1
guard -> { max_uint <= fixnum_max } do
end
```
+Custom guards are better than a simple `if` as they allow [mspec commands](https://github.com/ruby/mspec/issues/30#issuecomment-312487779) to work properly.
+
+#### Implementation-specific behaviors
+
In general, the usage of guards should be minimized as possible.
There are no guards to define implementation-specific behavior because
@@ -166,6 +222,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/iteration.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/iteration.rb
+describe :hash_iteration_no_block, shared: true do
+ it "returns an Enumerator if called on a non-empty hash without a block" do
+ { 1 => 2 }.send(@method).should.instance_of?(Enumerator)
+ end
+end
+
+# core/hash/select_spec.rb
+describe "Hash#select" do
+ it_behaves_like :hash_iteration_no_block, :select
+end
+
+# core/hash/reject_spec.rb
+describe "Hash#reject" do
+ it_behaves_like :hash_iteration_no_block, :reject
+end
+```
+
+In the example, the first `describe` defines the shared spec `:hash_iteration_no_block`, 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(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/README.md b/spec/ruby/README.md
index 970688a623..b259a97e21 100644
--- a/spec/ruby/README.md
+++ b/spec/ruby/README.md
@@ -1,9 +1,10 @@
# The Ruby Spec Suite
-[![Build Status](https://travis-ci.org/ruby/spec.svg)](https://travis-ci.org/ruby/spec)
-[![Build Status](https://ci.appveyor.com/api/projects/status/1gs6f399320o44b1?svg=true)](https://ci.appveyor.com/project/eregon/spec-x948i)
+[![Actions Build Status](https://github.com/ruby/spec/workflows/CI/badge.svg)](https://github.com/ruby/spec/actions)
-The Ruby Spec Suite is a test suite for the behavior of the Ruby programming language.
+The Ruby Spec Suite, abbreviated `ruby/spec`, is a test suite for the behavior of the Ruby programming language.
+
+### Description and Motivation
It is not a standardized specification like the ISO one, and does not aim to become one.
Instead, it is a practical tool to describe and test the behavior of Ruby with code.
@@ -16,24 +17,54 @@ Every example code has a textual description, which presents several advantages:
The specs are written with syntax similar to RSpec 2.
They are run with MSpec, the purpose-built framework for running the Ruby Spec Suite.
-For more information, see the [MSpec](http://github.com/ruby/mspec) project.
+For more information, see the [MSpec](https://github.com/ruby/mspec) project.
The specs describe the [language syntax](language/), the [core library](core/), the [standard library](library/), the [C API for extensions](optional/capi) and the [command line flags](command_line/).
The language specs are grouped by keyword while the core and standard library specs are grouped by class and method.
ruby/spec is known to be tested in these implementations for every commit:
-* [MRI](http://rubyci.org/) on 30 platforms and 4 versions
-* [JRuby](https://github.com/jruby/jruby/tree/master/spec/ruby) on Travis for both 1.7 and 9.x
-* [TruffleRuby](https://github.com/graalvm/truffleruby) on Travis
-* [Opal](https://github.com/opal/opal/tree/master/spec) on Travis
-ruby/spec describes the behavior of Ruby 2.2 and more recent Ruby versions.
-More precisely, every latest stable MRI release [passes](https://rubyci.org/) all specs of ruby/spec
-(latest 2.2.x, 2.3.x, 2.4.x, etc).
+* [MRI](https://rubyci.org/) on 30 platforms and 4 versions
+* [JRuby](https://github.com/jruby/jruby/tree/master/spec/ruby) for both 1.7 and 9.x
+* [TruffleRuby](https://github.com/truffleruby/truffleruby/tree/master/spec/ruby)
+* [Opal](https://github.com/opal/opal/tree/master/spec)
+* [Artichoke](https://github.com/artichoke/spec/tree/artichoke-vendor)
+
+ruby/spec describes the behavior of Ruby 3.3 and more recent Ruby versions.
+More precisely, every latest stable MRI release should [pass](https://github.com/ruby/spec/actions/workflows/ci.yml) all specs of ruby/spec (3.3.x, 3.4.x, etc), and those are tested in CI.
+
+### Synchronization with Ruby Implementations
+
+The specs are synchronized both ways around once a month by @andrykonchin between ruby/spec, MRI, JRuby and TruffleRuby,
+using [this script](https://github.com/ruby/mspec/blob/master/tool/sync/sync-rubyspec.rb).
+Each of these repositories has a full copy of the specs under `spec/ruby` to ease editing specs.
+Any of these repositories can be used to add or edit specs, use what is most convenient for you.
+
+For *testing* the development version of a Ruby implementation, one should always test against that implementation's copy of the specs under `spec/ruby`, as that's what the Ruby implementation tests against in their CI.
+Also, this repository doesn't always contain the latest spec changes from MRI (it's synchronized monthly), and does not contain tags (specs marked as failing on that Ruby implementation).
+Running specs on a Ruby implementation can be done with:
+
+```console
+$ cd ruby_implementation/spec/ruby
+# Add ../ruby_implementation/bin in PATH, or pass -t /path/to/bin/ruby
+$ ../mspec/bin/mspec
+```
+
+### Specs for old Ruby versions
For older specs try these commits:
+
* Ruby 2.0.0-p647 - [Suite](https://github.com/ruby/spec/commit/245862558761d5abc676843ef74f86c9bcc8ea8d) using [MSpec](https://github.com/ruby/mspec/commit/f90efa068791064f955de7a843e96e2d7d3041c2) (may encounter 2 failures)
* Ruby 2.1.9 - [Suite](https://github.com/ruby/spec/commit/f029e65241374386077ac500add557ae65069b55) using [MSpec](https://github.com/ruby/mspec/commit/55568ea3918c6380e64db8c567d732fa5781efed)
+* Ruby 2.2.10 - [Suite](https://github.com/ruby/spec/commit/cbaa0e412270c944df0c2532fc500c920dba0e92) using [MSpec](https://github.com/ruby/mspec/commit/d84d7668449e96856c5f6bac8cb1526b6d357ce3)
+* Ruby 2.3.8 - [Suite](https://github.com/ruby/spec/commit/dc733114d8ae66a3368ba3a98422c50147a76ba5) using [MSpec](https://github.com/ruby/mspec/commit/4599bc195fb109f2a482a01c32a7d659518369ea)
+* Ruby 2.4.10 - [Suite](https://github.com/ruby/spec/commit/bce4f2b81d6c31db67cf4d023a0625ceadde59bd) using [MSpec](https://github.com/ruby/mspec/commit/e7eb8aa4c26495b7b461e687d950b96eb08b3ff2)
+* Ruby 2.5.9 - [Suite](https://github.com/ruby/spec/commit/c503335d3d9f6ec6ef24de60a0716c34af69b64f) using [MSpec](https://github.com/ruby/mspec/commit/0091e8a62e954717cd54641f935eaf1403692041)
+* Ruby 2.6.10 - [Suite](https://github.com/ruby/spec/commit/aaf998fb8c92c4e63ad423a2e7ca6e6921818c6e) using [MSpec](https://github.com/ruby/mspec/commit/5e36c684e9e2b92b1187589bba1df22c640a8661)
+* Ruby 2.7.8 - [Suite](https://github.com/ruby/spec/commit/93787e6035c925b593a9c0c6fb0e7e07a6f1df1f) using [MSpec](https://github.com/ruby/mspec/commit/1d8cf64722d8a7529f7cd205be5f16a89b7a67fd)
+* Ruby 3.0.7 - [Suite](https://github.com/ruby/spec/commit/affef93d9940f615e4836f64b011da211f570913) using [MSpec](https://github.com/ruby/mspec/commit/0aabb3e548eb5ea6cad0125f8f46cee34542b6b7)
+* Ruby 3.1.6 - [Suite](https://github.com/ruby/spec/commit/ec960f2389d1c2265d32397fa8afa6d462014efc) using [MSpec](https://github.com/ruby/mspec/commit/484310dbed35b84c74484fd674602f88c42d063a)
+* Ruby 3.2.9 - [Suite](https://github.com/ruby/spec/commit/97f076242b7fc6e60703e6a6053365065cd6fc30) using [MSpec](https://github.com/ruby/mspec/commit/54704795e21128a930af2021c72c49cb87065134)
### Running the specs
@@ -45,7 +76,7 @@ Then move to it:
$ cd spec
-Clone [MSpec](http://github.com/ruby/mspec):
+Clone [MSpec](https://github.com/ruby/mspec):
$ git clone https://github.com/ruby/mspec.git ../mspec
@@ -58,7 +89,7 @@ This will execute all the specs using the executable named `ruby` on your curren
### Running Specs with a Specific Ruby Implementation
Use the `-t` option to specify the Ruby implementation with which to run the specs.
-The argument may be a full path to the Ruby binary.
+The argument is either a full path to the Ruby binary, or an executable in `$PATH`.
$ ../mspec/bin/mspec -t /path/to/some/bin/ruby
@@ -83,14 +114,54 @@ In similar fashion, the following commands run the respective specs:
$ ../mspec/bin/mspec :library
$ ../mspec/bin/mspec :capi
-### Contributing
+### Sanity Checks When Running Specs
+
+A number of checks for various kind of "leaks" (file descriptors, temporary files,
+threads, subprocesses, `ENV`, `ARGV`, global encodings, top-level constants) can be
+enabled with `CHECK_LEAKS=true`:
+
+ $ CHECK_LEAKS=true ../mspec/bin/mspec
+
+New top-level constants should only be introduced when needed or follow the
+pattern `<ClassBeingTested>Specs` such as `module StringSpecs`.
+Other constants used for testing should be nested under such a module.
+
+Exceptions to these rules are contained in the file `.mspec.constants`.
+MSpec can automatically add new top-level constants in this file with:
+
+ $ CHECK_LEAKS=save mspec ../mspec/bin/mspec file
+
+### Running Specs on S390x CPU Architecture
+
+Run the specs with `DFLTCC=0` if you see failing specs related to the zlib library on s390x CPU architecture. The failures can happen with the zlib library applying the patch madler/zlib#410 to enable the deflate algorithm producing a different compressed byte stream.
+
+ $ DFLTCC=0 ../mspec/bin/mspec
+
+### Contributing and Writing Specs
+
+See [CONTRIBUTING.md](https://github.com/ruby/spec/blob/master/CONTRIBUTING.md) for documentation about contributing and writing specs (guards, matchers, etc).
+
+### Dependencies
+
+These command-line executables are needed to run the specs.
+
+* `echo`
+* `stat` for `core/file/*time_spec.rb`
+* `find` for `core/file/fixtures/file_types.rb` (package `findutils`, not needed on Windows)
+
+The file `/etc/services` is required for socket specs (package `netbase` on Debian, not needed on Windows).
+
+### Socket specs from rubysl-socket
-See [CONTRIBUTING.md](https://github.com/ruby/spec/blob/master/CONTRIBUTING.md).
+Most specs under `library/socket` were imported from the rubysl-socket project (which is no longer on GitHub).
+The 3 copyright holders of rubysl-socket, Yorick Peterse, Chuck Remes and
+Brian Shirai, agreed to relicense those specs under the MIT license in ruby/spec.
### History and RubySpec
This project was originally born from [Rubinius](https://github.com/rubinius/rubinius) tests being converted to the spec style.
+The revision history of these specs is available [here](https://github.com/ruby/spec/blob/2b886623/CHANGES.before-2008-05-10).
These specs were later extracted to their own project, RubySpec, with a specific vision and principles.
At the end of 2014, Brian Shirai, the creator of RubySpec, decided to [end RubySpec](http://rubinius.com/2014/12/31/matz-s-ruby-developers-don-t-use-rubyspec/).
-A couple months later, the different repositories were merged and [the project was revived](http://eregon.github.io/rubyspec/2015/07/29/rubyspec-is-reborn.html).
+A couple months later, the different repositories were merged and [the project was revived](https://eregon.github.io/rubyspec/2015/07/29/rubyspec-is-reborn.html).
On 12 January 2016, the name was changed to "The Ruby Spec Suite" for clarity and to let the RubySpec ideology rest in peace.
diff --git a/spec/ruby/appveyor.yml b/spec/ruby/appveyor.yml
deleted file mode 100644
index 8ee5abd8b4..0000000000
--- a/spec/ruby/appveyor.yml
+++ /dev/null
@@ -1,30 +0,0 @@
----
-version: "{build}"
-clone_depth: 5
-init:
- # To avoid duplicated executables in PATH, see https://github.com/ruby/spec/pull/468
- - set PATH=C:\ruby%RUBY_VERSION%\bin;C:\Program Files\7-Zip;C:\Program Files\AppVeyor\BuildAgent;C:\Program Files\Git\cmd;C:\Windows\system32;C:\Program Files;C:\Windows
- # Loads trunk build and updates MSYS2 / MinGW to most recent gcc compiler
- - if %ruby_version%==_trunk (
- appveyor DownloadFile https://ci.appveyor.com/api/projects/MSP-Greg/ruby-loco/artifacts/ruby_trunk.7z -FileName C:\ruby_trunk.7z &
- 7z x C:\ruby_trunk.7z -oC:\ruby_trunk & C:\ruby_trunk\trunk_msys2.cmd)
-environment:
- matrix:
- - RUBY_VERSION: 23-x64
- - RUBY_VERSION: 24-x64
- - RUBY_VERSION: _trunk # So the folder name is ruby_trunk
-install:
- - git clone https://github.com/ruby/mspec.git ../mspec
-build: off
-test_script:
- - SET CHECK_LEAKS=true
- - ../mspec/bin/mspec -rdevkit -ff
-on_finish:
- - ruby -v
-matrix:
- allow_failures:
- - ruby_version: _trunk
-branches:
- only:
- - master
- - /^try/
diff --git a/spec/ruby/bin/rubocop b/spec/ruby/bin/rubocop
new file mode 100755
index 0000000000..0937c47906
--- /dev/null
+++ b/spec/ruby/bin/rubocop
@@ -0,0 +1,12 @@
+#!/usr/bin/env ruby
+# frozen_string_literal: true
+
+require 'bundler/inline'
+
+gemfile do
+ source 'https://rubygems.org'
+
+ gem 'rubocop', '1.86.2'
+end
+
+exec(Gem.bin_path('rubocop', 'rubocop'), *ARGV)
diff --git a/spec/ruby/command_line/backtrace_limit_spec.rb b/spec/ruby/command_line/backtrace_limit_spec.rb
new file mode 100644
index 0000000000..4d57bc268b
--- /dev/null
+++ b/spec/ruby/command_line/backtrace_limit_spec.rb
@@ -0,0 +1,93 @@
+require_relative '../spec_helper'
+
+describe "The --backtrace-limit command line option" do
+ ruby_version_is ""..."3.4" do
+ it "limits top-level backtraces to a given number of entries" do
+ file = fixture(__FILE__ , "backtrace.rb")
+ out = ruby_exe(file, options: "--backtrace-limit=2", args: "top 2>&1", exit_status: 1)
+ out = out.gsub(__dir__, '')
+
+ out.should == <<-MSG
+top
+/fixtures/backtrace.rb:2:in `a': oops (RuntimeError)
+\tfrom /fixtures/backtrace.rb:6:in `b'
+\tfrom /fixtures/backtrace.rb:10:in `c'
+\t ... 2 levels...
+ MSG
+ end
+
+ it "affects Exception#full_message" do
+ file = fixture(__FILE__ , "backtrace.rb")
+ out = ruby_exe(file, options: "--backtrace-limit=2", args: "full_message 2>&1")
+ out = out.gsub(__dir__, '')
+
+ out.should == <<-MSG
+full_message
+/fixtures/backtrace.rb:2:in `a': oops (RuntimeError)
+\tfrom /fixtures/backtrace.rb:6:in `b'
+\tfrom /fixtures/backtrace.rb:10:in `c'
+\t ... 2 levels...
+ MSG
+ end
+
+ it "does not affect Exception#backtrace" do
+ file = fixture(__FILE__ , "backtrace.rb")
+ out = ruby_exe(file, options: "--backtrace-limit=2", args: "backtrace 2>&1")
+ out = out.gsub(__dir__, '')
+
+ out.should == <<-MSG
+backtrace
+/fixtures/backtrace.rb:2:in `a'
+/fixtures/backtrace.rb:6:in `b'
+/fixtures/backtrace.rb:10:in `c'
+/fixtures/backtrace.rb:14:in `d'
+/fixtures/backtrace.rb:29:in `<main>'
+ MSG
+ end
+ end
+
+ ruby_version_is "3.4" do
+ it "limits top-level backtraces to a given number of entries" do
+ file = fixture(__FILE__ , "backtrace.rb")
+ out = ruby_exe(file, options: "--backtrace-limit=2", args: "top 2>&1", exit_status: 1)
+ out = out.gsub(__dir__, '')
+
+ out.should == <<-MSG
+top
+/fixtures/backtrace.rb:2:in 'Object#a': oops (RuntimeError)
+\tfrom /fixtures/backtrace.rb:6:in 'Object#b'
+\tfrom /fixtures/backtrace.rb:10:in 'Object#c'
+\t ... 2 levels...
+ MSG
+ end
+
+ it "affects Exception#full_message" do
+ file = fixture(__FILE__ , "backtrace.rb")
+ out = ruby_exe(file, options: "--backtrace-limit=2", args: "full_message 2>&1")
+ out = out.gsub(__dir__, '')
+
+ out.should == <<-MSG
+full_message
+/fixtures/backtrace.rb:2:in 'Object#a': oops (RuntimeError)
+\tfrom /fixtures/backtrace.rb:6:in 'Object#b'
+\tfrom /fixtures/backtrace.rb:10:in 'Object#c'
+\t ... 2 levels...
+ MSG
+ end
+
+ it "does not affect Exception#backtrace" do
+ file = fixture(__FILE__ , "backtrace.rb")
+ out = ruby_exe(file, options: "--backtrace-limit=2", args: "backtrace 2>&1")
+ out = out.gsub(__dir__, '')
+
+ out.should == <<-MSG
+backtrace
+/fixtures/backtrace.rb:2:in 'Object#a'
+/fixtures/backtrace.rb:6:in 'Object#b'
+/fixtures/backtrace.rb:10:in 'Object#c'
+/fixtures/backtrace.rb:14:in 'Object#d'
+/fixtures/backtrace.rb:29:in '<main>'
+ MSG
+ end
+ end
+end
diff --git a/spec/ruby/command_line/dash_0_spec.rb b/spec/ruby/command_line/dash_0_spec.rb
new file mode 100755
index 0000000000..2ce4f49b5e
--- /dev/null
+++ b/spec/ruby/command_line/dash_0_spec.rb
@@ -0,0 +1,13 @@
+require_relative '../spec_helper'
+
+describe "The -0 command line option" do
+ it "sets $/ and $-0" do
+ ruby_exe("puts $/, $-0", options: "-072").should == ":\n:\n"
+ end
+
+ ruby_version_is "4.0" do
+ it "sets $/ and $-0 as a frozen string" do
+ ruby_exe("puts $/.frozen?, $-0.frozen?", options: "-072").should == "true\ntrue\n"
+ end
+ end
+end
diff --git a/spec/ruby/command_line/dash_a_spec.rb b/spec/ruby/command_line/dash_a_spec.rb
index 65f79ec208..43d923ce16 100644
--- a/spec/ruby/command_line/dash_a_spec.rb
+++ b/spec/ruby/command_line/dash_a_spec.rb
@@ -1,16 +1,18 @@
+require_relative '../spec_helper'
+
describe "The -a command line option" do
before :each do
@names = fixture __FILE__, "full_names.txt"
end
it "runs the code in loop conditional on Kernel.gets()" do
- ruby_exe("puts $F.last", options: "-n -a", escape: true,
+ ruby_exe("puts $F.last", options: "-n -a",
args: " < #{@names}").should ==
"jones\nfield\ngrey\n"
end
it "sets $-a" do
- ruby_exe("puts $-a", options: "-n -a", escape: true,
+ ruby_exe("puts $-a", options: "-n -a",
args: " < #{@names}").should ==
"true\ntrue\ntrue\n"
end
diff --git a/spec/ruby/command_line/dash_c_spec.rb b/spec/ruby/command_line/dash_c_spec.rb
index 375d945a07..6b3a5de685 100644
--- a/spec/ruby/command_line/dash_c_spec.rb
+++ b/spec/ruby/command_line/dash_c_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../spec_helper', __FILE__)
+require_relative '../spec_helper'
describe "The -c command line option" do
it "checks syntax in given file" do
diff --git a/spec/ruby/command_line/dash_d_spec.rb b/spec/ruby/command_line/dash_d_spec.rb
index 009a14e16c..26891b4791 100644
--- a/spec/ruby/command_line/dash_d_spec.rb
+++ b/spec/ruby/command_line/dash_d_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../spec_helper', __FILE__)
+require_relative '../spec_helper'
describe "The -d command line option" do
before :each do
diff --git a/spec/ruby/command_line/dash_e_spec.rb b/spec/ruby/command_line/dash_e_spec.rb
index 3435e78e29..24ed34376d 100644
--- a/spec/ruby/command_line/dash_e_spec.rb
+++ b/spec/ruby/command_line/dash_e_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../spec_helper', __FILE__)
+require_relative '../spec_helper'
describe "The -e command line option" do
it "evaluates the given string" do
@@ -23,7 +23,7 @@ describe "The -e command line option" do
#needs to test return => LocalJumpError
- describe "with -n and a Fixnum range" do
+ describe "with -n and an Integer range" do
before :each do
@script = "-ne 'print if %s' #{fixture(__FILE__, "conditional_range.txt")}"
end
diff --git a/spec/ruby/command_line/dash_encoding_spec.rb b/spec/ruby/command_line/dash_encoding_spec.rb
new file mode 100644
index 0000000000..5803d328c1
--- /dev/null
+++ b/spec/ruby/command_line/dash_encoding_spec.rb
@@ -0,0 +1,36 @@
+require_relative '../spec_helper'
+
+describe "The --encoding command line option" do
+ before :each do
+ @test_string = "print [Encoding.default_external.name, Encoding.default_internal&.name].inspect"
+ @enc2 = Encoding::ISO_8859_1
+ end
+
+ describe "sets Encoding.default_external and optionally Encoding.default_internal" do
+ it "if given a single encoding with an =" do
+ ruby_exe(@test_string, options: "--disable-gems --encoding=big5").should == [Encoding::Big5.name, nil].inspect
+ end
+
+ it "if given a single encoding as a separate argument" do
+ ruby_exe(@test_string, options: "--disable-gems --encoding big5").should == [Encoding::Big5.name, nil].inspect
+ end
+
+ it "if given two encodings with an =" do
+ ruby_exe(@test_string, options: "--disable-gems --encoding=big5:#{@enc2}").should == [Encoding::Big5.name, @enc2.name].inspect
+ end
+
+ it "if given two encodings as a separate argument" do
+ ruby_exe(@test_string, options: "--disable-gems --encoding big5:#{@enc2}").should == [Encoding::Big5.name, @enc2.name].inspect
+ end
+ end
+
+ it "does not accept a third encoding" do
+ options = {
+ options: "--disable-gems --encoding big5:#{@enc2}:utf-32le",
+ args: "2>&1",
+ exit_status: 1
+ }
+
+ ruby_exe(@test_string, options).should =~ /extra argument for --encoding: utf-32le/
+ end
+end
diff --git a/spec/ruby/command_line/dash_external_encoding_spec.rb b/spec/ruby/command_line/dash_external_encoding_spec.rb
new file mode 100644
index 0000000000..f052674dc8
--- /dev/null
+++ b/spec/ruby/command_line/dash_external_encoding_spec.rb
@@ -0,0 +1,15 @@
+require_relative '../spec_helper'
+
+describe 'The --external-encoding command line option sets Encoding.default_external' do
+ before :each do
+ @test_string = "print Encoding.default_external.name"
+ end
+
+ it "if given an encoding with an =" do
+ ruby_exe(@test_string, options: '--external-encoding=big5').should == Encoding::Big5.name
+ end
+
+ it "if given an encoding as a separate argument" do
+ ruby_exe(@test_string, options: '--external-encoding big5').should == Encoding::Big5.name
+ end
+end
diff --git a/spec/ruby/command_line/dash_internal_encoding_spec.rb b/spec/ruby/command_line/dash_internal_encoding_spec.rb
new file mode 100644
index 0000000000..3049040bb4
--- /dev/null
+++ b/spec/ruby/command_line/dash_internal_encoding_spec.rb
@@ -0,0 +1,15 @@
+require_relative '../spec_helper'
+
+describe 'The --internal-encoding command line option sets Encoding.default_internal' do
+ before :each do
+ @test_string = "print Encoding.default_internal.name"
+ end
+
+ it "if given an encoding with an =" do
+ ruby_exe(@test_string, options: '--internal-encoding=big5').should == Encoding::Big5.name
+ end
+
+ it "if given an encoding as a separate argument" do
+ ruby_exe(@test_string, options: '--internal-encoding big5').should == Encoding::Big5.name
+ end
+end
diff --git a/spec/ruby/command_line/dash_l_spec.rb b/spec/ruby/command_line/dash_l_spec.rb
new file mode 100644
index 0000000000..44a98445f3
--- /dev/null
+++ b/spec/ruby/command_line/dash_l_spec.rb
@@ -0,0 +1,31 @@
+require_relative '../spec_helper'
+
+describe "The -l command line option" do
+ before :each do
+ @names = fixture __FILE__, "full_names.txt"
+ end
+
+ it "chomps lines with default separator" do
+ ruby_exe('puts $_.end_with?("\n")', options: "-n -l",
+ args: " < #{@names}").should ==
+ "false\nfalse\nfalse\n"
+ end
+
+ it "chomps last line based on $/" do
+ ruby_exe('BEGIN { $/ = "ones\n" }; puts $_', options: "-W0 -n -l",
+ args: " < #{@names}").should ==
+ "alice j\nbob field\njames grey\n"
+ end
+
+ it "sets $\\ to the value of $/" do
+ ruby_exe("puts $\\ == $/", options: "-W0 -n -l",
+ args: " < #{@names}").should ==
+ "true\ntrue\ntrue\n"
+ end
+
+ it "sets $-l" do
+ ruby_exe("puts $-l", options: "-n -l",
+ args: " < #{@names}").should ==
+ "true\ntrue\ntrue\n"
+ end
+end
diff --git a/spec/ruby/command_line/dash_n_spec.rb b/spec/ruby/command_line/dash_n_spec.rb
index f4dd9f1851..1dd9379259 100644
--- a/spec/ruby/command_line/dash_n_spec.rb
+++ b/spec/ruby/command_line/dash_n_spec.rb
@@ -1,22 +1,24 @@
+require_relative '../spec_helper'
+
describe "The -n command line option" do
before :each do
@names = fixture __FILE__, "names.txt"
end
it "runs the code in loop conditional on Kernel.gets()" do
- ruby_exe("puts $_", options: "-n", escape: true,
+ ruby_exe("puts $_", options: "-n",
args: " < #{@names}").should ==
"alice\nbob\njames\n"
end
it "only evaluates BEGIN blocks once" do
- ruby_exe("BEGIN { puts \"hi\" }; puts $_", options: "-n", escape: true,
+ ruby_exe("BEGIN { puts \"hi\" }; puts $_", options: "-n",
args: " < #{@names}").should ==
"hi\nalice\nbob\njames\n"
end
it "only evaluates END blocks once" do
- ruby_exe("puts $_; END {puts \"bye\"}", options: "-n", escape: true,
+ ruby_exe("puts $_; END {puts \"bye\"}", options: "-n",
args: " < #{@names}").should ==
"alice\nbob\njames\nbye\n"
end
@@ -27,7 +29,7 @@ describe "The -n command line option" do
$total += 1
END { puts $total }
script
- ruby_exe(script, options: "-n", escape: true,
+ ruby_exe(script, options: "-n",
args: " < #{@names}").should ==
"3\n"
end
diff --git a/spec/ruby/command_line/dash_p_spec.rb b/spec/ruby/command_line/dash_p_spec.rb
index 67562b5bc3..967e3796de 100644
--- a/spec/ruby/command_line/dash_p_spec.rb
+++ b/spec/ruby/command_line/dash_p_spec.rb
@@ -1,16 +1,18 @@
+require_relative '../spec_helper'
+
describe "The -p command line option" do
before :each do
@names = fixture __FILE__, "names.txt"
end
it "runs the code in loop conditional on Kernel.gets() and prints $_" do
- ruby_exe("$_ = $_.upcase", options: "-p", escape: true,
+ ruby_exe("$_ = $_.upcase", options: "-p",
args: " < #{@names}").should ==
"ALICE\nBOB\nJAMES\n"
end
it "sets $-p" do
- ruby_exe("$_ = $-p", options: "-p", escape: true,
+ ruby_exe("$_ = $-p", options: "-p",
args: " < #{@names}").should ==
"truetruetrue"
end
diff --git a/spec/ruby/command_line/dash_r_spec.rb b/spec/ruby/command_line/dash_r_spec.rb
index 3d3abcf0b7..0de9ba2e24 100644
--- a/spec/ruby/command_line/dash_r_spec.rb
+++ b/spec/ruby/command_line/dash_r_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../spec_helper', __FILE__)
+require_relative '../spec_helper'
describe "The -r command line option" do
before :each do
@@ -7,7 +7,22 @@ describe "The -r command line option" do
end
it "requires the specified file" do
- result = ruby_exe(@script, options: "-r #{@test_file}")
- result.should include(@test_file + ".rb")
+ out = ruby_exe(@script, options: "-r #{@test_file}")
+ out.should.include?("REQUIRED")
+ out.should.include?(@test_file + ".rb")
+ end
+
+ it "requires the file before parsing the main script" do
+ out = ruby_exe(fixture(__FILE__, "bad_syntax.rb"), options: "-r #{@test_file}", args: "2>&1", exit_status: 1)
+ $?.should_not.success?
+ out.should.include?("REQUIRED")
+ out.should.include?("SyntaxError")
+ end
+
+ it "does not require the file if the main script file does not exist" do
+ out = `#{ruby_exe.to_a.join(' ')} -r #{@test_file} #{fixture(__FILE__, "does_not_exist.rb")} 2>&1`
+ $?.should_not.success?
+ out.should_not.include?("REQUIRED")
+ out.should.include?("No such file or directory")
end
end
diff --git a/spec/ruby/command_line/dash_s_spec.rb b/spec/ruby/command_line/dash_s_spec.rb
index 70e41208e0..eaaeea7c96 100644
--- a/spec/ruby/command_line/dash_s_spec.rb
+++ b/spec/ruby/command_line/dash_s_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../spec_helper', __FILE__)
+require_relative '../spec_helper'
describe "The -s command line option" do
describe "when using -- to stop parsing" do
diff --git a/spec/ruby/command_line/dash_upper_c_spec.rb b/spec/ruby/command_line/dash_upper_c_spec.rb
index e8a54b01c1..ece1b32105 100644
--- a/spec/ruby/command_line/dash_upper_c_spec.rb
+++ b/spec/ruby/command_line/dash_upper_c_spec.rb
@@ -1,18 +1,6 @@
-require File.expand_path('../../spec_helper', __FILE__)
+require_relative '../spec_helper'
+require_relative 'shared/change_directory'
-describe 'The -C command line option' do
- before :all do
- @script = fixture(__FILE__, 'dash_upper_c_script.rb')
- @tempdir = File.dirname(@script)
- end
-
- it 'changes the PWD when using a file' do
- output = ruby_exe(@script, options: "-C #{@tempdir}")
- output.should == @tempdir
- end
-
- it 'changes the PWD when using -e' do
- output = ruby_exe(nil, options: "-C #{@tempdir} -e 'print Dir.pwd'")
- output.should == @tempdir
- end
+describe "The -C command line option" do
+ it_behaves_like :command_line_change_directory, "-C"
end
diff --git a/spec/ruby/command_line/dash_upper_e_spec.rb b/spec/ruby/command_line/dash_upper_e_spec.rb
index 716f1304b7..5a83962583 100644
--- a/spec/ruby/command_line/dash_upper_e_spec.rb
+++ b/spec/ruby/command_line/dash_upper_e_spec.rb
@@ -1,7 +1,37 @@
+require_relative '../spec_helper'
+
describe "ruby -E" do
+ it "sets the external encoding with '-E external'" do
+ result = ruby_exe("print Encoding.default_external", options: '-E euc-jp')
+ result.should == "EUC-JP"
+ end
+
+ platform_is_not :windows do
+ it "also sets the filesystem encoding with '-E external'" do
+ result = ruby_exe("print Encoding.find('filesystem')", options: '-E euc-jp')
+ result.should == "EUC-JP"
+ end
+ end
+
+ it "sets the external encoding with '-E external:'" do
+ result = ruby_exe("print Encoding.default_external", options: '-E Shift_JIS:')
+ result.should == "Shift_JIS"
+ end
+
+ it "sets the internal encoding with '-E :internal'" do
+ ruby_exe("print Encoding.default_internal", options: '-E :SHIFT_JIS').
+ should == 'Shift_JIS'
+ end
+
+ it "sets the external and internal encodings with '-E external:internal'" do
+ ruby_exe("puts Encoding.default_external, Encoding.default_internal", options: '-E euc-jp:SHIFT_JIS').
+ should == "EUC-JP\nShift_JIS\n"
+ end
+
it "raises a RuntimeError if used with -U" do
ruby_exe("p 1",
options: '-Eascii:ascii -U',
- args: '2>&1').should =~ /RuntimeError/
+ args: '2>&1',
+ exit_status: 1).should =~ /RuntimeError/
end
end
diff --git a/spec/ruby/command_line/dash_upper_f_spec.rb b/spec/ruby/command_line/dash_upper_f_spec.rb
index 020968b1f9..5c10a7140d 100644
--- a/spec/ruby/command_line/dash_upper_f_spec.rb
+++ b/spec/ruby/command_line/dash_upper_f_spec.rb
@@ -1,10 +1,12 @@
+require_relative '../spec_helper'
+
describe "the -F command line option" do
before :each do
@passwd = fixture __FILE__, "passwd_file.txt"
end
it "specifies the field separator pattern for -a" do
- ruby_exe("puts $F[0]", options: "-naF:", escape: true,
+ ruby_exe("puts $F[0]", options: "-naF:",
args: " < #{@passwd}").should ==
"nobody\nroot\ndaemon\n"
end
diff --git a/spec/ruby/command_line/dash_upper_i_spec.rb b/spec/ruby/command_line/dash_upper_i_spec.rb
index 0a00059949..4005a27d23 100644
--- a/spec/ruby/command_line/dash_upper_i_spec.rb
+++ b/spec/ruby/command_line/dash_upper_i_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../spec_helper', __FILE__)
+require_relative '../spec_helper'
describe "The -I command line option" do
before :each do
@@ -6,6 +6,46 @@ describe "The -I command line option" do
end
it "adds the path to the load path ($:)" do
- ruby_exe(@script, options: "-I fixtures").should include("fixtures")
+ ruby_exe(@script, options: "-I fixtures").should.include?("fixtures")
+ end
+
+ it "adds the path at the front of $LOAD_PATH" do
+ lines = ruby_exe(@script, options: "-I fixtures").lines
+ if PlatformGuard.implementation? :ruby
+ # In a MRI checkout, $PWD ends up as the first entry in $LOAD_PATH.
+ # So just assert that it's at the beginning.
+ idx = lines.index { |l| l.include?("fixtures") }
+ idx.should < 2
+ idx.should < lines.size-1
+ else
+ lines[0].should.include?("fixtures")
+ end
+ end
+
+ it "adds the path expanded from CWD to $LOAD_PATH" do
+ ruby_exe(@script, options: "-I fixtures").lines.should.include? "#{Dir.pwd}/fixtures\n"
+ end
+
+ it "expands a path from CWD even if it does not exist" do
+ ruby_exe(@script, options: "-I not_exist/not_exist").lines.should.include? "#{Dir.pwd}/not_exist/not_exist\n"
+ end
+end
+
+platform_is_not :windows do
+ describe "The -I command line option" do
+ before :each do
+ @script = fixture __FILE__, "loadpath.rb"
+ @fixtures = File.dirname(@script)
+ @symlink = tmp("loadpath_symlink")
+ File.symlink(@fixtures, @symlink)
+ end
+
+ after :each do
+ rm_r @symlink
+ end
+
+ it "does not expand symlinks" do
+ ruby_exe(@script, options: "-I #{@symlink}").lines.should.include? "#{@symlink}\n"
+ end
end
end
diff --git a/spec/ruby/command_line/dash_upper_k_spec.rb b/spec/ruby/command_line/dash_upper_k_spec.rb
index 3c3b9fa4d3..7e71532295 100644
--- a/spec/ruby/command_line/dash_upper_k_spec.rb
+++ b/spec/ruby/command_line/dash_upper_k_spec.rb
@@ -1,33 +1,65 @@
-describe 'The -K command line option sets __ENCODING__' do
- it "to Encoding::ASCII_8BIT with -Ka" do
- ruby_exe("print __ENCODING__", options: '-Ka').should == Encoding::ASCII_8BIT.to_s
- end
+require_relative '../spec_helper'
- it "to Encoding::ASCII_8BIT with -KA" do
- ruby_exe("print __ENCODING__", options: '-KA').should == Encoding::ASCII_8BIT.to_s
+describe 'The -K command line option' do
+ before :each do
+ @test_string = "print [__ENCODING__&.name, Encoding.default_external&.name, Encoding.default_internal&.name].inspect"
end
- it "to Encoding::EUC_JP with -Ke" do
- ruby_exe("print __ENCODING__", options: '-Ke').should == Encoding::EUC_JP.to_s
- end
+ describe 'sets __ENCODING__ and Encoding.default_external' do
+ it "to Encoding::BINARY with -Ka" do
+ ruby_exe(@test_string, options: '-Ka').should ==
+ [Encoding::BINARY.name, Encoding::BINARY.name, nil].inspect
+ end
- it "to Encoding::EUC_JP with -KE" do
- ruby_exe("print __ENCODING__", options: '-KE').should == Encoding::EUC_JP.to_s
- end
+ it "to Encoding::BINARY with -KA" do
+ ruby_exe(@test_string, options: '-KA').should ==
+ [Encoding::BINARY.name, Encoding::BINARY.name, nil].inspect
+ end
- it "to Encoding::UTF_8 with -Ku" do
- ruby_exe("print __ENCODING__", options: '-Ku').should == Encoding::UTF_8.to_s
- end
+ it "to Encoding::BINARY with -Kn" do
+ ruby_exe(@test_string, options: '-Kn').should ==
+ [Encoding::BINARY.name, Encoding::BINARY.name, nil].inspect
+ end
- it "to Encoding::UTF_8 with -KU" do
- ruby_exe("print __ENCODING__", options: '-KU').should == Encoding::UTF_8.to_s
- end
+ it "to Encoding::BINARY with -KN" do
+ ruby_exe(@test_string, options: '-KN').should ==
+ [Encoding::BINARY.name, Encoding::BINARY.name, nil].inspect
+ end
+
+ it "to Encoding::EUC_JP with -Ke" do
+ ruby_exe(@test_string, options: '-Ke').should ==
+ [Encoding::EUC_JP.name, Encoding::EUC_JP.name, nil].inspect
+ end
+
+ it "to Encoding::EUC_JP with -KE" do
+ ruby_exe(@test_string, options: '-KE').should ==
+ [Encoding::EUC_JP.name, Encoding::EUC_JP.name, nil].inspect
+ end
+
+ it "to Encoding::UTF_8 with -Ku" do
+ ruby_exe(@test_string, options: '-Ku').should ==
+ [Encoding::UTF_8.name, Encoding::UTF_8.name, nil].inspect
+ end
+
+ it "to Encoding::UTF_8 with -KU" do
+ ruby_exe(@test_string, options: '-KU').should ==
+ [Encoding::UTF_8.name, Encoding::UTF_8.name, nil].inspect
+ end
+
+ it "to Encoding::Windows_31J with -Ks" do
+ ruby_exe(@test_string, options: '-Ks').should ==
+ [Encoding::Windows_31J.name, Encoding::Windows_31J.name, nil].inspect
+ end
- it "to Encoding::Windows_31J with -Ks" do
- ruby_exe("print __ENCODING__", options: '-Ks').should == Encoding::Windows_31J.to_s
+ it "to Encoding::Windows_31J with -KS" do
+ ruby_exe(@test_string, options: '-KS').should ==
+ [Encoding::Windows_31J.name, Encoding::Windows_31J.name, nil].inspect
+ end
end
- it "to Encoding::Windows_31J with -KS" do
- ruby_exe("print __ENCODING__", options: '-KS').should == Encoding::Windows_31J.to_s
+ it "ignores unknown codes" do
+ external = Encoding.find('external')
+ ruby_exe(@test_string, options: '-KZ').should ==
+ [Encoding::UTF_8.name, external.name, nil].inspect
end
end
diff --git a/spec/ruby/command_line/dash_upper_s_spec.rb b/spec/ruby/command_line/dash_upper_s_spec.rb
index 2e293e9a62..71c6016659 100644
--- a/spec/ruby/command_line/dash_upper_s_spec.rb
+++ b/spec/ruby/command_line/dash_upper_s_spec.rb
@@ -1,8 +1,9 @@
-require File.expand_path('../../spec_helper', __FILE__)
+require_relative '../spec_helper'
describe 'The -S command line option' do
before :each do
- @path = [ENV['PATH'], fixture(__FILE__, "bin")].join(':')
+ @bin = fixture(__FILE__, "bin")
+ @path = [ENV['PATH'], @bin].join(File::PATH_SEPARATOR)
end
platform_is_not :windows do
@@ -10,20 +11,57 @@ describe 'The -S command line option' do
# and MRI shows warning when including world writable path in ENV['PATH'].
# This is why we are using /success$/ matching in the following cases.
+ it "runs launcher found in RUBYPATH, but only code after the first /\#!.*ruby.*/-ish line in target file" do
+ result = ruby_exe(nil, options: '-S hybrid_launcher.sh', env: { 'RUBYPATH' => @bin }, args: '2>&1')
+ result.should =~ /success$/
+ end
+
it "runs launcher found in PATH, but only code after the first /\#!.*ruby.*/-ish line in target file" do
result = ruby_exe(nil, options: '-S hybrid_launcher.sh', env: { 'PATH' => @path }, args: '2>&1')
result.should =~ /success$/
end
+ it "runs launcher found in RUBYPATH" do
+ result = ruby_exe(nil, options: '-S launcher.rb', env: { 'RUBYPATH' => @bin }, args: '2>&1')
+ result.should =~ /success$/
+ end
+
it "runs launcher found in PATH" do
result = ruby_exe(nil, options: '-S launcher.rb', env: { 'PATH' => @path }, args: '2>&1')
result.should =~ /success$/
end
+ it "runs launcher found in RUBYPATH and sets the exit status to 1 if it fails" do
+ result = ruby_exe(nil, options: '-S dash_s_fail', env: { 'RUBYPATH' => @bin }, args: '2>&1', exit_status: 1)
+ result.should =~ /\bdie\b/
+ $?.exitstatus.should == 1
+ end
+
it "runs launcher found in PATH and sets the exit status to 1 if it fails" do
- result = ruby_exe(nil, options: '-S dash_s_fail', env: { 'PATH' => @path }, args: '2>&1')
+ result = ruby_exe(nil, options: '-S dash_s_fail', env: { 'PATH' => @path }, args: '2>&1', exit_status: 1)
result.should =~ /\bdie\b/
$?.exitstatus.should == 1
end
+
+ ruby_version_is "4.1" do
+ describe "if the script name contains separator" do
+ before(:each) do
+ @bin = File.dirname(@bin)
+ @path = [ENV['PATH'], @bin].join(File::PATH_SEPARATOR)
+ end
+
+ it "does not search launcher in RUBYPATH" do
+ result = ruby_exe(nil, options: '-S bin/launcher.rb', env: { 'RUBYPATH' => @bin }, args: '2>&1', exit_status: 1)
+ result.should =~ /LoadError/
+ $?.should_not.success?
+ end
+
+ it "does not search launcher in PATH" do
+ result = ruby_exe(nil, options: '-S bin/launcher.rb', env: { 'PATH' => @path }, args: '2>&1', exit_status: 1)
+ result.should =~ /LoadError/
+ $?.should_not.success?
+ end
+ end
+ end
end
end
diff --git a/spec/ruby/command_line/dash_upper_u_spec.rb b/spec/ruby/command_line/dash_upper_u_spec.rb
index 6cd52a3647..2c210eb603 100644
--- a/spec/ruby/command_line/dash_upper_u_spec.rb
+++ b/spec/ruby/command_line/dash_upper_u_spec.rb
@@ -1,41 +1,52 @@
+require_relative '../spec_helper'
+
describe "ruby -U" do
it "sets Encoding.default_internal to UTF-8" do
- ruby_exe('print Encoding.default_internal.name',
- options: '-U').should == 'UTF-8'
+ ruby_exe('print Encoding.default_internal.name',
+ options: '-U').should == 'UTF-8'
+ end
+
+ it "sets Encoding.default_internal to UTF-8 when RUBYOPT is empty or only spaces" do
+ ruby_exe('p Encoding.default_internal',
+ options: '-U', env: { 'RUBYOPT' => '' }).should == "#<Encoding:UTF-8>\n"
+ ruby_exe('p Encoding.default_internal',
+ options: '-U', env: { 'RUBYOPT' => ' ' }).should == "#<Encoding:UTF-8>\n"
end
it "does nothing different if specified multiple times" do
- ruby_exe('print Encoding.default_internal.name',
- options: '-U -U').should == 'UTF-8'
+ ruby_exe('print Encoding.default_internal.name',
+ options: '-U -U').should == 'UTF-8'
end
it "is overruled by Encoding.default_internal=" do
- ruby_exe('Encoding.default_internal="ascii"; print Encoding.default_internal.name',
- options: '-U').should == 'US-ASCII'
+ ruby_exe('Encoding.default_internal="ascii"; print Encoding.default_internal.name',
+ options: '-U').should == 'US-ASCII'
end
it "does not affect the default external encoding" do
- ruby_exe('Encoding.default_external="ascii"; print Encoding.default_external.name',
- options: '-U').should == 'US-ASCII'
+ ruby_exe('Encoding.default_external="ascii"; print Encoding.default_external.name',
+ options: '-U').should == 'US-ASCII'
end
it "does not affect the source encoding" do
- ruby_exe("print __ENCODING__.name",
- options: '-U -KE').should == 'EUC-JP'
- ruby_exe("print __ENCODING__.name",
- options: '-KE -U').should == 'EUC-JP'
+ ruby_exe("print __ENCODING__.name",
+ options: '-U -KE').should == 'EUC-JP'
+ ruby_exe("print __ENCODING__.name",
+ options: '-KE -U').should == 'EUC-JP'
end
# I assume IO redirection will break on Windows...
it "raises a RuntimeError if used with -Eext:int" do
ruby_exe("p 1",
options: '-U -Eascii:ascii',
- args: '2>&1').should =~ /RuntimeError/
+ args: '2>&1',
+ exit_status: 1).should =~ /RuntimeError/
end
it "raises a RuntimeError if used with -E:int" do
ruby_exe("p 1",
options: '-U -E:ascii',
- args: '2>&1').should =~ /RuntimeError/
+ args: '2>&1',
+ exit_status: 1).should =~ /RuntimeError/
end
end
diff --git a/spec/ruby/command_line/dash_upper_w_spec.rb b/spec/ruby/command_line/dash_upper_w_spec.rb
index 4e517a422a..4019510d42 100644
--- a/spec/ruby/command_line/dash_upper_w_spec.rb
+++ b/spec/ruby/command_line/dash_upper_w_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../spec_helper', __FILE__)
-require File.expand_path('../shared/verbose', __FILE__)
+require_relative '../spec_helper'
+require_relative 'shared/verbose'
describe "The -W command line option" do
before :each do
@@ -18,3 +18,27 @@ end
describe "The -W command line option with 2" do
it_behaves_like :command_line_verbose, "-W2"
end
+
+describe "The -W command line option with :deprecated" do
+ it "enables deprecation warnings" do
+ ruby_exe('p Warning[:deprecated]', options: '-W:deprecated').should == "true\n"
+ end
+end
+
+describe "The -W command line option with :no-deprecated" do
+ it "suppresses deprecation warnings" do
+ ruby_exe('p Warning[:deprecated]', options: '-w -W:no-deprecated').should == "false\n"
+ end
+end
+
+describe "The -W command line option with :experimental" do
+ it "enables experimental warnings" do
+ ruby_exe('p Warning[:experimental]', options: '-W:experimental').should == "true\n"
+ end
+end
+
+describe "The -W command line option with :no-experimental" do
+ it "suppresses experimental warnings" do
+ ruby_exe('p Warning[:experimental]', options: '-w -W:no-experimental').should == "false\n"
+ end
+end
diff --git a/spec/ruby/command_line/dash_upper_x_spec.rb b/spec/ruby/command_line/dash_upper_x_spec.rb
new file mode 100644
index 0000000000..8ef9aae4b1
--- /dev/null
+++ b/spec/ruby/command_line/dash_upper_x_spec.rb
@@ -0,0 +1,6 @@
+require_relative '../spec_helper'
+require_relative 'shared/change_directory'
+
+describe "The -X command line option" do
+ it_behaves_like :command_line_change_directory, "-X"
+end
diff --git a/spec/ruby/command_line/dash_v_spec.rb b/spec/ruby/command_line/dash_v_spec.rb
index 2ee9099419..6a4f7d3a15 100644
--- a/spec/ruby/command_line/dash_v_spec.rb
+++ b/spec/ruby/command_line/dash_v_spec.rb
@@ -1,12 +1,15 @@
-require File.expand_path('../../spec_helper', __FILE__)
-require File.expand_path('../shared/verbose', __FILE__)
+require_relative '../spec_helper'
+require_relative 'shared/verbose'
describe "The -v command line option" do
it_behaves_like :command_line_verbose, "-v"
describe "when used alone" do
it "prints version and ends" do
- ruby_exe(nil, args: '-v').include?(RUBY_DESCRIPTION).should == true
- end
+ ruby_exe(nil, args: '-v').gsub("+PRISM ", "").should.include?(RUBY_DESCRIPTION.gsub("+PRISM ", ""))
+ end unless (defined?(RubyVM::YJIT) && RubyVM::YJIT.enabled?) ||
+ (defined?(RubyVM::RJIT) && RubyVM::RJIT.enabled?) ||
+ (ENV['RUBY_GC_LIBRARY'] && ENV['RUBY_GC_LIBRARY'].length > 0) ||
+ (ENV['RUBY_MN_THREADS'] == '1')
end
end
diff --git a/spec/ruby/command_line/dash_w_spec.rb b/spec/ruby/command_line/dash_w_spec.rb
index bb038cb10c..f310dca3ed 100644
--- a/spec/ruby/command_line/dash_w_spec.rb
+++ b/spec/ruby/command_line/dash_w_spec.rb
@@ -1,6 +1,10 @@
-require File.expand_path('../../spec_helper', __FILE__)
-require File.expand_path('../shared/verbose', __FILE__)
+require_relative '../spec_helper'
+require_relative 'shared/verbose'
describe "The -w command line option" do
it_behaves_like :command_line_verbose, "-w"
+
+ it "enables both deprecated and experimental warnings" do
+ ruby_exe('p Warning[:deprecated]; p Warning[:experimental]', options: '-w').should == "true\ntrue\n"
+ end
end
diff --git a/spec/ruby/command_line/dash_x_spec.rb b/spec/ruby/command_line/dash_x_spec.rb
index a5306b4f75..38f97a5ab1 100644
--- a/spec/ruby/command_line/dash_x_spec.rb
+++ b/spec/ruby/command_line/dash_x_spec.rb
@@ -1,3 +1,5 @@
+require_relative '../spec_helper'
+
describe "The -x command line option" do
it "runs code after the first /\#!.*ruby.*/-ish line in target file" do
embedded_ruby = fixture __FILE__, "bin/embedded_ruby.txt"
@@ -7,8 +9,8 @@ describe "The -x command line option" do
it "fails when /\#!.*ruby.*/-ish line in target file is not found" do
bad_embedded_ruby = fixture __FILE__, "bin/bad_embedded_ruby.txt"
- result = ruby_exe(bad_embedded_ruby, options: '-x', args: '2>&1')
- result.should include "no Ruby script found in input"
+ result = ruby_exe(bad_embedded_ruby, options: '-x', args: '2>&1', exit_status: 1)
+ result.should.include? "no Ruby script found in input"
end
it "behaves as -x was set when non-ruby shebang is encountered on first line" do
@@ -16,6 +18,4 @@ describe "The -x command line option" do
result = ruby_exe(embedded_ruby)
result.should == "success\n"
end
-
- it "needs to be reviewed for spec completeness"
end
diff --git a/spec/ruby/command_line/error_message_spec.rb b/spec/ruby/command_line/error_message_spec.rb
index 6212452739..157cb8969c 100644
--- a/spec/ruby/command_line/error_message_spec.rb
+++ b/spec/ruby/command_line/error_message_spec.rb
@@ -1,11 +1,16 @@
-require File.expand_path('../../spec_helper', __FILE__)
+require_relative '../spec_helper'
describe "The error message caused by an exception" do
it "is not printed to stdout" do
- out = ruby_exe("this_does_not_exist", args: "2> #{File::NULL}")
- out.chomp.empty?.should == true
+ out = ruby_exe("this_does_not_exist", args: "2> #{File::NULL}", exit_status: 1)
+ out.chomp.should.empty?
- out = ruby_exe("end #syntax error", args: "2> #{File::NULL}")
- out.chomp.empty?.should == true
+ out = ruby_exe("end #syntax error", args: "2> #{File::NULL}", exit_status: 1)
+ out.chomp.should.empty?
+ end
+
+ it "is not modified with extra escaping of control characters and backslashes" do
+ out = ruby_exe('raise "\e[31mRed\e[0m error\\\\message"', args: "2>&1", exit_status: 1)
+ out.chomp.should.include?("\e[31mRed\e[0m error\\message")
end
end
diff --git a/spec/ruby/command_line/feature_spec.rb b/spec/ruby/command_line/feature_spec.rb
new file mode 100644
index 0000000000..0a3252b88d
--- /dev/null
+++ b/spec/ruby/command_line/feature_spec.rb
@@ -0,0 +1,71 @@
+require_relative '../spec_helper'
+
+describe "The --enable and --disable flags" do
+ before :all do
+ # Since some specs disable reading RUBYOPT, we instead pass its contents as :options for those specs
+ rubyopt = [ENV["RUBYOPT"]]
+ rubyopt << ENV["#{RUBY_ENGINE.upcase}OPT"] unless RUBY_ENGINE == 'ruby'
+ @rubyopt = RUBY_ENGINE == "ruby" ? "" : rubyopt.compact.join(" ")
+ end
+
+ it "can be used with gems" do
+ ruby_exe("p defined?(Gem)", options: "--enable=gems").chomp.should == "\"constant\""
+ ruby_exe("p defined?(Gem)", options: "--disable=gems").chomp.should == "nil"
+ ruby_exe("p defined?(Gem)", options: "--enable-gems").chomp.should == "\"constant\""
+ ruby_exe("p defined?(Gem)", options: "--disable-gems").chomp.should == "nil"
+ end
+
+ it "can be used with gem" do
+ ruby_exe("p defined?(Gem)", options: "--enable=gem").chomp.should == "\"constant\""
+ ruby_exe("p defined?(Gem)", options: "--disable=gem").chomp.should == "nil"
+ ruby_exe("p defined?(Gem)", options: "--enable-gem").chomp.should == "\"constant\""
+ ruby_exe("p defined?(Gem)", options: "--disable-gem").chomp.should == "nil"
+ end
+
+ it "can be used with did_you_mean" do
+ ruby_exe("p defined?(DidYouMean)", options: "--enable=did_you_mean").chomp.should == "\"constant\""
+ ruby_exe("p defined?(DidYouMean)", options: "--disable=did_you_mean").chomp.should == "nil"
+ ruby_exe("p defined?(DidYouMean)", options: "--enable-did_you_mean").chomp.should == "\"constant\""
+ ruby_exe("p defined?(DidYouMean)", options: "--disable-did_you_mean").chomp.should == "nil"
+ end
+
+ it "can be used with rubyopt" do
+ ruby_exe("p $VERBOSE", options: "--enable=rubyopt", env: {'RUBYOPT' => '-w'}).chomp.should == "true"
+ ruby_exe("p $VERBOSE", options: "#{@rubyopt} --disable=rubyopt", env: {'RUBYOPT' => '-w'}).chomp.should == "false"
+ ruby_exe("p $VERBOSE", options: "--enable-rubyopt", env: {'RUBYOPT' => '-w'}).chomp.should == "true"
+ ruby_exe("p $VERBOSE", options: "#{@rubyopt} --disable-rubyopt", env: {'RUBYOPT' => '-w'}).chomp.should == "false"
+ end
+
+ it "can be used with frozen-string-literal" do
+ ruby_exe("p 'foo'.frozen?", options: "--enable=frozen-string-literal").chomp.should == "true"
+ ruby_exe("p 'foo'.frozen?", options: "--disable=frozen-string-literal").chomp.should == "false"
+ ruby_exe("p 'foo'.frozen?", options: "--enable-frozen-string-literal").chomp.should == "true"
+ ruby_exe("p 'foo'.frozen?", options: "--disable-frozen-string-literal").chomp.should == "false"
+ end
+
+ # frequently hangs for >60s on GitHub Actions macos-latest
+ # MinGW's YJIT support seems broken
+ platform_is_not :darwin, :mingw do
+ it "can be used with all for enable" do
+ e = "p [defined?(Gem), defined?(DidYouMean), $VERBOSE, 'foo'.frozen?]"
+ env = {'RUBYOPT' => '-w'}
+ # Use a single variant here because it can be quite slow as it might enable jit, etc
+ ruby_exe(e, options: "--enable-all", env: env).chomp.should == "[\"constant\", \"constant\", true, true]"
+ end unless defined?(RubyVM::YJIT) && defined?(RubyVM::ZJIT) && RubyVM::ZJIT.enabled? # You're not supposed to enable YJIT with --enable-all when ZJIT options are passed.
+ end
+
+ it "can be used with all for disable" do
+ e = "p [defined?(Gem), defined?(DidYouMean), $VERBOSE, 'foo'.frozen?]"
+ env = {'RUBYOPT' => '-w'}
+ ruby_exe(e, options: "#{@rubyopt} --disable=all", env: env).chomp.should == "[nil, nil, false, false]"
+ ruby_exe(e, options: "#{@rubyopt} --disable-all", env: env).chomp.should == "[nil, nil, false, false]"
+ end
+
+ it "prints a warning for unknown features" do
+ ruby_exe("p 14", options: "--enable=ruby-spec-feature-does-not-exist 2>&1").chomp.should.include?('warning: unknown argument for --enable')
+ ruby_exe("p 14", options: "--disable=ruby-spec-feature-does-not-exist 2>&1").chomp.should.include?('warning: unknown argument for --disable')
+ ruby_exe("p 14", options: "--enable-ruby-spec-feature-does-not-exist 2>&1").chomp.should.include?('warning: unknown argument for --enable')
+ ruby_exe("p 14", options: "--disable-ruby-spec-feature-does-not-exist 2>&1").chomp.should.include?('warning: unknown argument for --disable')
+ end
+
+end
diff --git a/spec/ruby/command_line/fixtures/backtrace.rb b/spec/ruby/command_line/fixtures/backtrace.rb
new file mode 100644
index 0000000000..99acae95c8
--- /dev/null
+++ b/spec/ruby/command_line/fixtures/backtrace.rb
@@ -0,0 +1,35 @@
+def a
+ raise 'oops'
+end
+
+def b
+ a
+end
+
+def c
+ b
+end
+
+def d
+ c
+end
+
+arg = ARGV.first
+$stderr.puts arg
+
+case arg
+when 'full_message'
+ begin
+ d
+ rescue => exc
+ puts exc.full_message
+ end
+when 'backtrace'
+ begin
+ d
+ rescue => exc
+ puts exc.backtrace
+ end
+else
+ d
+end
diff --git a/spec/ruby/command_line/fixtures/bin/bad_embedded_ruby.txt b/spec/ruby/command_line/fixtures/bin/bad_embedded_ruby.txt
index a2b7ad085f..61b946977a 100644
--- a/spec/ruby/command_line/fixtures/bin/bad_embedded_ruby.txt
+++ b/spec/ruby/command_line/fixtures/bin/bad_embedded_ruby.txt
@@ -1,3 +1,3 @@
-@@@This line is not value Ruby
+@@@This line is not valid Ruby
#!rub_y
puts 'success'
diff --git a/spec/ruby/command_line/fixtures/bin/embedded_ruby.txt b/spec/ruby/command_line/fixtures/bin/embedded_ruby.txt
index c556bf0b71..0ec0f358db 100644
--- a/spec/ruby/command_line/fixtures/bin/embedded_ruby.txt
+++ b/spec/ruby/command_line/fixtures/bin/embedded_ruby.txt
@@ -1,3 +1,3 @@
-@@@This line is not value Ruby
+@@@This line is not valid Ruby
#!ruby
-puts 'success' \ No newline at end of file
+puts 'success'
diff --git a/spec/ruby/command_line/fixtures/bin/hybrid_launcher.sh b/spec/ruby/command_line/fixtures/bin/hybrid_launcher.sh
index 0eede2a99f..fd3249f0e5 100644
--- a/spec/ruby/command_line/fixtures/bin/hybrid_launcher.sh
+++ b/spec/ruby/command_line/fixtures/bin/hybrid_launcher.sh
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
-exec somehow this file
+echo 'error' && exit 1
#!ruby
puts 'success'
diff --git a/spec/ruby/command_line/fixtures/bin/launcher.rb b/spec/ruby/command_line/fixtures/bin/launcher.rb
index 92a0ee2b49..92a0ee2b49 100644..100755
--- a/spec/ruby/command_line/fixtures/bin/launcher.rb
+++ b/spec/ruby/command_line/fixtures/bin/launcher.rb
diff --git a/spec/ruby/command_line/fixtures/dash_upper_c_script.rb b/spec/ruby/command_line/fixtures/change_directory_script.rb
index abe244705f..abe244705f 100644
--- a/spec/ruby/command_line/fixtures/dash_upper_c_script.rb
+++ b/spec/ruby/command_line/fixtures/change_directory_script.rb
diff --git a/spec/ruby/command_line/fixtures/debug_info.rb b/spec/ruby/command_line/fixtures/debug_info.rb
index ee607910c0..f02b041920 100644
--- a/spec/ruby/command_line/fixtures/debug_info.rb
+++ b/spec/ruby/command_line/fixtures/debug_info.rb
@@ -1,4 +1,3 @@
-# frozen_string_literal: true
a = 'string'
b = a
c = b
diff --git a/spec/ruby/command_line/fixtures/freeze_flag_required_diff_enc.rb b/spec/ruby/command_line/fixtures/freeze_flag_required_diff_enc.rb
index fa348d59e7..df4b952c46 100644
--- a/spec/ruby/command_line/fixtures/freeze_flag_required_diff_enc.rb
+++ b/spec/ruby/command_line/fixtures/freeze_flag_required_diff_enc.rb
Binary files differ
diff --git a/spec/ruby/command_line/fixtures/freeze_flag_two_literals.rb b/spec/ruby/command_line/fixtures/freeze_flag_two_literals.rb
index 074092c9d9..f5547a5bae 100644
--- a/spec/ruby/command_line/fixtures/freeze_flag_two_literals.rb
+++ b/spec/ruby/command_line/fixtures/freeze_flag_two_literals.rb
@@ -1 +1 @@
-p "abc".object_id == "abc".object_id
+p "abc".equal?("abc")
diff --git a/spec/ruby/command_line/fixtures/string_literal_frozen_comment.rb b/spec/ruby/command_line/fixtures/string_literal_frozen_comment.rb
new file mode 100644
index 0000000000..fb84b546c0
--- /dev/null
+++ b/spec/ruby/command_line/fixtures/string_literal_frozen_comment.rb
@@ -0,0 +1,4 @@
+# frozen_string_literal: true
+frozen = "test".frozen?
+interned = "test".equal?("test")
+puts "frozen:#{frozen} interned:#{interned}"
diff --git a/spec/ruby/command_line/fixtures/string_literal_mutable_comment.rb b/spec/ruby/command_line/fixtures/string_literal_mutable_comment.rb
new file mode 100644
index 0000000000..381a742001
--- /dev/null
+++ b/spec/ruby/command_line/fixtures/string_literal_mutable_comment.rb
@@ -0,0 +1,4 @@
+# frozen_string_literal: false
+frozen = "test".frozen?
+interned = "test".equal?("test")
+puts "frozen:#{frozen} interned:#{interned}"
diff --git a/spec/ruby/command_line/fixtures/string_literal_raw.rb b/spec/ruby/command_line/fixtures/string_literal_raw.rb
new file mode 100644
index 0000000000..56b1841296
--- /dev/null
+++ b/spec/ruby/command_line/fixtures/string_literal_raw.rb
@@ -0,0 +1,3 @@
+frozen = "test".frozen?
+interned = "test".equal?("test")
+puts "frozen:#{frozen} interned:#{interned}"
diff --git a/spec/ruby/command_line/fixtures/test_file.rb b/spec/ruby/command_line/fixtures/test_file.rb
index 961e3c0b0c..30a832299e 100644
--- a/spec/ruby/command_line/fixtures/test_file.rb
+++ b/spec/ruby/command_line/fixtures/test_file.rb
@@ -1 +1 @@
-"test file"
+puts "REQUIRED"
diff --git a/spec/ruby/command_line/frozen_strings_spec.rb b/spec/ruby/command_line/frozen_strings_spec.rb
index f3ee797c78..32ff7d0371 100644
--- a/spec/ruby/command_line/frozen_strings_spec.rb
+++ b/spec/ruby/command_line/frozen_strings_spec.rb
@@ -1,30 +1,94 @@
-require File.expand_path('../../spec_helper', __FILE__)
+require_relative '../spec_helper'
-ruby_version_is "2.3" do
- describe "The --enable-frozen-string-literal flag causes string literals to" do
+describe "The --enable-frozen-string-literal flag causes string literals to" do
- it "produce the same object each time" do
- ruby_exe(fixture(__FILE__, "freeze_flag_one_literal.rb"), options: "--enable-frozen-string-literal").chomp.should == "true"
- end
+ it "produce the same object each time" do
+ ruby_exe(fixture(__FILE__, "freeze_flag_one_literal.rb"), options: "--enable-frozen-string-literal").chomp.should == "true"
+ end
- it "produce the same object for literals with the same content" do
- ruby_exe(fixture(__FILE__, "freeze_flag_two_literals.rb"), options: "--enable-frozen-string-literal").chomp.should == "true"
- end
+ it "produce the same object for literals with the same content" do
+ ruby_exe(fixture(__FILE__, "freeze_flag_two_literals.rb"), options: "--enable-frozen-string-literal").chomp.should == "true"
+ end
+
+ it "produce the same object for literals with the same content in different files" do
+ ruby_exe(fixture(__FILE__, "freeze_flag_across_files.rb"), options: "--enable-frozen-string-literal").chomp.should == "true"
+ end
+
+ it "produce different objects for literals with the same content in different files if they have different encodings" do
+ ruby_exe(fixture(__FILE__, "freeze_flag_across_files_diff_enc.rb"), options: "--enable-frozen-string-literal").chomp.should == "true"
+ end
+end
+
+describe "The --disable-frozen-string-literal flag causes string literals to" do
+
+ it "produce a different object each time" do
+ ruby_exe(fixture(__FILE__, "freeze_flag_one_literal.rb"), options: "--disable-frozen-string-literal").chomp.should == "false"
+ end
+
+end
- it "produce the same object for literals with the same content in different files" do
- ruby_exe(fixture(__FILE__, "freeze_flag_across_files.rb"), options: "--enable-frozen-string-literal").chomp.should == "true"
+describe "With neither --enable-frozen-string-literal nor --disable-frozen-string-literal flag set" do
+ before do
+ # disable --enable-frozen-string-literal and --disable-frozen-string-literal passed in $RUBYOPT
+ @rubyopt = ENV["RUBYOPT"]
+ ENV["RUBYOPT"] = ""
+ end
+
+ after do
+ ENV["RUBYOPT"] = @rubyopt
+ end
+
+ it "produce a different object each time" do
+ ruby_exe(fixture(__FILE__, "freeze_flag_one_literal.rb")).chomp.should == "false"
+ end
+
+ context "if file has no frozen_string_literal comment" do
+ it "produce different mutable strings each time" do
+ ruby_exe(fixture(__FILE__, "string_literal_raw.rb")).chomp.should == "frozen:false interned:false"
end
- it "produce different objects for literals with the same content in different files if they have different encodings" do
- ruby_exe(fixture(__FILE__, "freeze_flag_across_files_diff_enc.rb"), options: "--enable-frozen-string-literal").chomp.should == "true"
+ guard -> { ruby_version_is "3.4" and !"test".frozen? } do
+ it "complain about modification of produced mutable strings" do
+ -> { eval(<<~RUBY) }.should complain(/warning: literal string will be frozen in the future \(run with --debug-frozen-string-literal for more information\)/)
+ "test" << "!"
+ RUBY
+ end
+
+ it "does not complain about modification if Warning[:deprecated] is false" do
+ deprecated = Warning[:deprecated]
+ Warning[:deprecated] = false
+ -> { eval(<<~RUBY) }.should_not complain
+ "test" << "!"
+ RUBY
+ ensure
+ Warning[:deprecated] = deprecated
+ end
end
end
- describe "The --debug flag produces" do
- it "debugging info on attempted frozen string modification" do
- error_str = ruby_exe(fixture(__FILE__, 'debug_info.rb'), options: '--debug', args: "2>&1")
- error_str.should include("can't modify frozen String, created at ")
- error_str.should include("command_line/fixtures/debug_info.rb:2")
+ it "if file has frozen_string_literal:true comment produce same frozen strings each time" do
+ ruby_exe(fixture(__FILE__, "string_literal_frozen_comment.rb")).chomp.should == "frozen:true interned:true"
+ end
+
+ it "if file has frozen_string_literal:false comment produce different mutable strings each time" do
+ ruby_exe(fixture(__FILE__, "string_literal_mutable_comment.rb")).chomp.should == "frozen:false interned:false"
+ end
+end
+
+describe "The --debug flag produces" do
+ it "debugging info on attempted frozen string modification" do
+ error_str = ruby_exe(fixture(__FILE__, 'debug_info.rb'), options: '--enable-frozen-string-literal --debug', args: "2>&1")
+ error_str.should.include?("can't modify frozen String")
+ error_str.should.include?("created at")
+ error_str.should.include?("command_line/fixtures/debug_info.rb:1")
+ end
+
+ guard -> { ruby_version_is "3.4" and !"test".frozen? } do
+ it "debugging info on mutating chilled string" do
+ error_str = ruby_exe(fixture(__FILE__, 'debug_info.rb'), options: '-w --debug', args: "2>&1")
+ error_str.should.include?("literal string will be frozen in the future")
+ error_str.should.include?("the string was created here")
+ error_str.should.include?("command_line/fixtures/debug_info.rb:1")
end
end
end
diff --git a/spec/ruby/command_line/rubylib_spec.rb b/spec/ruby/command_line/rubylib_spec.rb
new file mode 100644
index 0000000000..1bedd146e3
--- /dev/null
+++ b/spec/ruby/command_line/rubylib_spec.rb
@@ -0,0 +1,69 @@
+require_relative '../spec_helper'
+
+describe "The RUBYLIB environment variable" do
+ before :each do
+ @rubylib, ENV["RUBYLIB"] = ENV["RUBYLIB"], nil
+ @pre = @rubylib.nil? ? '' : @rubylib + File::PATH_SEPARATOR
+ end
+
+ after :each do
+ ENV["RUBYLIB"] = @rubylib
+ end
+
+ it "adds a directory to $LOAD_PATH" do
+ dir = tmp("rubylib/incl")
+ ENV["RUBYLIB"] = @pre + dir
+ paths = ruby_exe("puts $LOAD_PATH").lines.map(&:chomp)
+ paths.should.include?(dir)
+ end
+
+ it "adds a File::PATH_SEPARATOR-separated list of directories to $LOAD_PATH" do
+ dir1, dir2 = tmp("rubylib/incl1"), tmp("rubylib/incl2")
+ ENV["RUBYLIB"] = @pre + "#{dir1}#{File::PATH_SEPARATOR}#{dir2}"
+ paths = ruby_exe("puts $LOAD_PATH").lines.map(&:chomp)
+ paths.should.include?(dir1)
+ paths.should.include?(dir2)
+ paths.index(dir1).should < paths.index(dir2)
+ end
+
+ it "adds the directory at the front of $LOAD_PATH" do
+ dir = tmp("rubylib/incl_front")
+ ENV["RUBYLIB"] = @pre + dir
+ paths = ruby_exe("puts $LOAD_PATH").lines.map(&:chomp)
+ paths.shift if paths.first.end_with?('/gem-rehash')
+ if PlatformGuard.implementation? :ruby
+ # In a MRI checkout, $PWD and some extra -I entries end up as
+ # the first entries in $LOAD_PATH. So just assert that it's not last.
+ idx = paths.index(dir)
+ idx.should < paths.size-1
+ else
+ paths[0].should == dir
+ end
+ end
+
+ it "adds the directory after directories added by -I" do
+ dash_i_dir = tmp("dash_I_include")
+ rubylib_dir = tmp("rubylib_include")
+ ENV["RUBYLIB"] = @pre + rubylib_dir
+ paths = ruby_exe("puts $LOAD_PATH", options: "-I #{dash_i_dir}").lines.map(&:chomp)
+ paths.should.include?(dash_i_dir)
+ paths.should.include?(rubylib_dir)
+ paths.index(dash_i_dir).should < paths.index(rubylib_dir)
+ end
+
+ it "adds the directory after directories added by -I within RUBYOPT" do
+ rubyopt_dir = tmp("rubyopt_include")
+ rubylib_dir = tmp("rubylib_include")
+ ENV["RUBYLIB"] = @pre + rubylib_dir
+ paths = ruby_exe("puts $LOAD_PATH", env: { "RUBYOPT" => "-I#{rubyopt_dir}" }).lines.map(&:chomp)
+ paths.should.include?(rubyopt_dir)
+ paths.should.include?(rubylib_dir)
+ paths.index(rubyopt_dir).should < paths.index(rubylib_dir)
+ end
+
+ it "keeps spaces in the value" do
+ ENV["RUBYLIB"] = @pre + " rubylib/incl "
+ out = ruby_exe("puts $LOAD_PATH")
+ out.should.include?(" rubylib/incl ")
+ end
+end
diff --git a/spec/ruby/command_line/rubyopt_spec.rb b/spec/ruby/command_line/rubyopt_spec.rb
index a80cb51a94..eb297cd6fe 100644
--- a/spec/ruby/command_line/rubyopt_spec.rb
+++ b/spec/ruby/command_line/rubyopt_spec.rb
@@ -1,55 +1,80 @@
-require File.expand_path('../../spec_helper', __FILE__)
+require_relative '../spec_helper'
describe "Processing RUBYOPT" do
- before (:each) do
+ before :each do
@rubyopt, ENV["RUBYOPT"] = ENV["RUBYOPT"], nil
end
- after (:each) do
+ after :each do
ENV["RUBYOPT"] = @rubyopt
end
it "adds the -I path to $LOAD_PATH" do
ENV["RUBYOPT"] = "-Ioptrubyspecincl"
- result = ruby_exe("puts $LOAD_PATH.grep(/byspecin/)", escape: true)
+ result = ruby_exe("puts $LOAD_PATH.grep(/byspecin/)")
result.chomp[-15..-1].should == "optrubyspecincl"
end
it "sets $DEBUG to true for '-d'" do
ENV["RUBYOPT"] = '-d'
command = %[puts "value of $DEBUG is \#{$DEBUG}"]
- result = ruby_exe(command, escape: true, args: "2>&1")
+ result = ruby_exe(command, args: "2>&1")
result.should =~ /value of \$DEBUG is true/
end
- it "prints the version number for '-v'" do
- ENV["RUBYOPT"] = '-v'
- ruby_exe("")[/\A.*/].should == RUBY_DESCRIPTION
+ guard -> { RbConfig::CONFIG["CROSS_COMPILING"] != "yes" } do
+ it "prints the version number for '-v'" do
+ ENV["RUBYOPT"] = '-v'
+ ruby_exe("")[/\A.*/].gsub(/\s\+(YJIT( \w+)?|ZJIT( \w+)?|PRISM|GC(\[\w+\])?)(?=\s)/, "").should == RUBY_DESCRIPTION.gsub(/\s\+(YJIT( \w+)?|ZJIT( \w+)?|PRISM|GC(\[\w+\])?)(?=\s)/, "")
+ end
+
+ it "ignores whitespace around the option" do
+ ENV["RUBYOPT"] = ' -v '
+ ruby_exe("")[/\A.*/].gsub(/\s\+(YJIT( \w+)?|ZJIT( \w+)?|PRISM|GC(\[\w+\])?)(?=\s)/, "").should == RUBY_DESCRIPTION.gsub(/\s\+(YJIT( \w+)?|ZJIT( \w+)?|PRISM|GC(\[\w+\])?)(?=\s)/, "")
+ end
end
it "sets $VERBOSE to true for '-w'" do
ENV["RUBYOPT"] = '-w'
- ruby_exe("p $VERBOSE", escape: true).chomp.should == "true"
+ ruby_exe("p $VERBOSE").chomp.should == "true"
end
it "sets $VERBOSE to true for '-W'" do
ENV["RUBYOPT"] = '-W'
- ruby_exe("p $VERBOSE", escape: true).chomp.should == "true"
+ ruby_exe("p $VERBOSE").chomp.should == "true"
end
it "sets $VERBOSE to nil for '-W0'" do
ENV["RUBYOPT"] = '-W0'
- ruby_exe("p $VERBOSE", escape: true).chomp.should == "nil"
+ ruby_exe("p $VERBOSE").chomp.should == "nil"
end
it "sets $VERBOSE to false for '-W1'" do
ENV["RUBYOPT"] = '-W1'
- ruby_exe("p $VERBOSE", escape: true).chomp.should == "false"
+ ruby_exe("p $VERBOSE").chomp.should == "false"
end
it "sets $VERBOSE to true for '-W2'" do
ENV["RUBYOPT"] = '-W2'
- ruby_exe("p $VERBOSE", escape: true).chomp.should == "true"
+ ruby_exe("p $VERBOSE").chomp.should == "true"
+ end
+
+ it "suppresses deprecation warnings for '-W:no-deprecated'" do
+ ENV["RUBYOPT"] = '-W:no-deprecated'
+ result = ruby_exe('$; = ""', args: '2>&1')
+ result.should == ""
+ end
+
+ it "suppresses experimental warnings for '-W:no-experimental'" do
+ ENV["RUBYOPT"] = '-W:no-experimental'
+ result = ruby_exe('case 0; in a; end', args: '2>&1')
+ result.should == ""
+ end
+
+ it "suppresses deprecation and experimental warnings for '-W:no-deprecated -W:no-experimental'" do
+ ENV["RUBYOPT"] = '-W:no-deprecated -W:no-experimental'
+ result = ruby_exe('case ($; = ""); in a; end', args: '2>&1')
+ result.should == ""
end
it "requires the file for '-r'" do
@@ -60,101 +85,101 @@ describe "Processing RUBYOPT" do
it "raises a RuntimeError for '-a'" do
ENV["RUBYOPT"] = '-a'
- ruby_exe("", args: '2>&1').should =~ /RuntimeError/
+ ruby_exe("", args: '2>&1', exit_status: 1).should =~ /RuntimeError/
end
it "raises a RuntimeError for '-p'" do
ENV["RUBYOPT"] = '-p'
- ruby_exe("", args: '2>&1').should =~ /RuntimeError/
+ ruby_exe("", args: '2>&1', exit_status: 1).should =~ /RuntimeError/
end
it "raises a RuntimeError for '-n'" do
ENV["RUBYOPT"] = '-n'
- ruby_exe("", args: '2>&1').should =~ /RuntimeError/
+ ruby_exe("", args: '2>&1', exit_status: 1).should =~ /RuntimeError/
end
it "raises a RuntimeError for '-y'" do
ENV["RUBYOPT"] = '-y'
- ruby_exe("", args: '2>&1').should =~ /RuntimeError/
+ ruby_exe("", args: '2>&1', exit_status: 1).should =~ /RuntimeError/
end
it "raises a RuntimeError for '-c'" do
ENV["RUBYOPT"] = '-c'
- ruby_exe("", args: '2>&1').should =~ /RuntimeError/
+ ruby_exe("", args: '2>&1', exit_status: 1).should =~ /RuntimeError/
end
it "raises a RuntimeError for '-s'" do
ENV["RUBYOPT"] = '-s'
- ruby_exe("", args: '2>&1').should =~ /RuntimeError/
+ ruby_exe("", args: '2>&1', exit_status: 1).should =~ /RuntimeError/
end
it "raises a RuntimeError for '-h'" do
ENV["RUBYOPT"] = '-h'
- ruby_exe("", args: '2>&1').should =~ /RuntimeError/
+ ruby_exe("", args: '2>&1', exit_status: 1).should =~ /RuntimeError/
end
it "raises a RuntimeError for '--help'" do
ENV["RUBYOPT"] = '--help'
- ruby_exe("", args: '2>&1').should =~ /RuntimeError/
+ ruby_exe("", args: '2>&1', exit_status: 1).should =~ /RuntimeError/
end
it "raises a RuntimeError for '-l'" do
ENV["RUBYOPT"] = '-l'
- ruby_exe("", args: '2>&1').should =~ /RuntimeError/
+ ruby_exe("", args: '2>&1', exit_status: 1).should =~ /RuntimeError/
end
it "raises a RuntimeError for '-S'" do
ENV["RUBYOPT"] = '-S irb'
- ruby_exe("", args: '2>&1').should =~ /RuntimeError/
+ ruby_exe("", args: '2>&1', exit_status: 1).should =~ /RuntimeError/
end
it "raises a RuntimeError for '-e'" do
ENV["RUBYOPT"] = '-e0'
- ruby_exe("", args: '2>&1').should =~ /RuntimeError/
+ ruby_exe("", args: '2>&1', exit_status: 1).should =~ /RuntimeError/
end
it "raises a RuntimeError for '-i'" do
ENV["RUBYOPT"] = '-i.bak'
- ruby_exe("", args: '2>&1').should =~ /RuntimeError/
+ ruby_exe("", args: '2>&1', exit_status: 1).should =~ /RuntimeError/
end
it "raises a RuntimeError for '-x'" do
ENV["RUBYOPT"] = '-x'
- ruby_exe("", args: '2>&1').should =~ /RuntimeError/
+ ruby_exe("", args: '2>&1', exit_status: 1).should =~ /RuntimeError/
end
it "raises a RuntimeError for '-C'" do
ENV["RUBYOPT"] = '-C'
- ruby_exe("", args: '2>&1').should =~ /RuntimeError/
+ ruby_exe("", args: '2>&1', exit_status: 1).should =~ /RuntimeError/
end
it "raises a RuntimeError for '-X'" do
ENV["RUBYOPT"] = '-X.'
- ruby_exe("", args: '2>&1').should =~ /RuntimeError/
+ ruby_exe("", args: '2>&1', exit_status: 1).should =~ /RuntimeError/
end
it "raises a RuntimeError for '-F'" do
ENV["RUBYOPT"] = '-F'
- ruby_exe("", args: '2>&1').should =~ /RuntimeError/
+ ruby_exe("", args: '2>&1', exit_status: 1).should =~ /RuntimeError/
end
it "raises a RuntimeError for '-0'" do
ENV["RUBYOPT"] = '-0'
- ruby_exe("", args: '2>&1').should =~ /RuntimeError/
+ ruby_exe("", args: '2>&1', exit_status: 1).should =~ /RuntimeError/
end
it "raises a RuntimeError for '--copyright'" do
ENV["RUBYOPT"] = '--copyright'
- ruby_exe("", args: '2>&1').should =~ /RuntimeError/
+ ruby_exe("", args: '2>&1', exit_status: 1).should =~ /RuntimeError/
end
it "raises a RuntimeError for '--version'" do
ENV["RUBYOPT"] = '--version'
- ruby_exe("", args: '2>&1').should =~ /RuntimeError/
+ ruby_exe("", args: '2>&1', exit_status: 1).should =~ /RuntimeError/
end
it "raises a RuntimeError for '--yydebug'" do
ENV["RUBYOPT"] = '--yydebug'
- ruby_exe("", args: '2>&1').should =~ /RuntimeError/
+ ruby_exe("", args: '2>&1', exit_status: 1).should =~ /RuntimeError/
end
end
diff --git a/spec/ruby/command_line/shared/change_directory.rb b/spec/ruby/command_line/shared/change_directory.rb
new file mode 100644
index 0000000000..9cb6e90ac6
--- /dev/null
+++ b/spec/ruby/command_line/shared/change_directory.rb
@@ -0,0 +1,21 @@
+describe :command_line_change_directory, shared: true do
+ before :all do
+ @script = fixture(__FILE__, 'change_directory_script.rb')
+ @tempdir = File.dirname(@script)
+ end
+
+ it 'changes the PWD when using a file' do
+ output = ruby_exe(@script, options: "#{@method} #{@tempdir}")
+ output.should == @tempdir
+ end
+
+ it 'does not need a space after -C for the argument' do
+ output = ruby_exe(@script, options: "#{@method}#{@tempdir}")
+ output.should == @tempdir
+ end
+
+ it 'changes the PWD when using -e' do
+ output = ruby_exe(nil, options: "#{@method} #{@tempdir} -e 'print Dir.pwd'")
+ output.should == @tempdir
+ end
+end
diff --git a/spec/ruby/command_line/shared/verbose.rb b/spec/ruby/command_line/shared/verbose.rb
index 457fe3006a..c5c44c269e 100644
--- a/spec/ruby/command_line/shared/verbose.rb
+++ b/spec/ruby/command_line/shared/verbose.rb
@@ -4,6 +4,6 @@ describe :command_line_verbose, shared: true do
end
it "sets $VERBOSE to true" do
- ruby_exe(@script, options: @method).chomp.split.last.should == "true"
+ ruby_exe(@script, options: @method).chomp.b.split.last.should == "true"
end
end
diff --git a/spec/ruby/command_line/syntax_error_spec.rb b/spec/ruby/command_line/syntax_error_spec.rb
index 71cee32e23..88864c048e 100644
--- a/spec/ruby/command_line/syntax_error_spec.rb
+++ b/spec/ruby/command_line/syntax_error_spec.rb
@@ -1,13 +1,13 @@
-require File.expand_path('../../spec_helper', __FILE__)
+require_relative '../spec_helper'
describe "The interpreter" do
it "prints an error when given a file with invalid syntax" do
- out = ruby_exe(fixture(__FILE__, "bad_syntax.rb"), args: "2>&1")
- out.should include "syntax error"
+ out = ruby_exe(fixture(__FILE__, "bad_syntax.rb"), args: "2>&1", exit_status: 1)
+ out.should.include?("SyntaxError")
end
it "prints an error when given code via -e with invalid syntax" do
- out = ruby_exe(nil, args: "-e 'a{' 2>&1")
- out.should include "syntax error"
+ out = ruby_exe(nil, args: "-e 'a{' 2>&1", exit_status: 1)
+ out.should.include?("SyntaxError")
end
end
diff --git a/spec/ruby/core/argf/argf_spec.rb b/spec/ruby/core/argf/argf_spec.rb
index b47e77c17f..f9468539bb 100644
--- a/spec/ruby/core/argf/argf_spec.rb
+++ b/spec/ruby/core/argf/argf_spec.rb
@@ -1,11 +1,11 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "ARGF" do
it "is extended by the Enumerable module" do
- ARGF.should be_kind_of(Enumerable)
+ ARGF.should.is_a?(Enumerable)
end
it "is an instance of ARGF.class" do
- ARGF.should be_an_instance_of(ARGF.class)
+ ARGF.should.instance_of?(ARGF.class)
end
end
diff --git a/spec/ruby/core/argf/argv_spec.rb b/spec/ruby/core/argf/argv_spec.rb
index e294b3993f..77dfe78c21 100644
--- a/spec/ruby/core/argf/argv_spec.rb
+++ b/spec/ruby/core/argf/argv_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "ARGF.argv" do
before :each do
@@ -7,7 +7,7 @@ describe "ARGF.argv" do
end
it "returns ARGV for the initial ARGF" do
- ARGF.argv.should equal ARGV
+ ARGF.argv.should.equal? ARGV
end
it "returns the remaining arguments to treat" do
diff --git a/spec/ruby/core/argf/binmode_spec.rb b/spec/ruby/core/argf/binmode_spec.rb
index 62202360e3..5288e3199d 100644
--- a/spec/ruby/core/argf/binmode_spec.rb
+++ b/spec/ruby/core/argf/binmode_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "ARGF.binmode" do
before :each do
@@ -9,7 +9,7 @@ describe "ARGF.binmode" do
it "returns self" do
argf [@bin_file] do
- @argf.binmode.should equal @argf
+ @argf.binmode.should.equal? @argf
end
end
@@ -22,7 +22,7 @@ describe "ARGF.binmode" do
end
end
- it "puts alls subsequent stream reading through ARGF into binmode" do
+ it "puts all subsequent streams reading through ARGF into binmode" do
argf [@bin_file, @bin_file] do
@argf.binmode
@argf.gets.should == "test\r\n"
@@ -31,13 +31,13 @@ describe "ARGF.binmode" do
end
end
- it "sets the file's encoding to ASCII-8BIT" do
+ it "sets the file's encoding to BINARY" do
argf [@bin_file, @file1] do
@argf.binmode
- @argf.binmode?.should == true
- @argf.gets.encoding.should == Encoding::ASCII_8BIT
+ @argf.should.binmode?
+ @argf.gets.encoding.should == Encoding::BINARY
@argf.skip
- @argf.read.encoding.should == Encoding::ASCII_8BIT
+ @argf.read.encoding.should == Encoding::BINARY
end
end
end
diff --git a/spec/ruby/core/argf/bytes_spec.rb b/spec/ruby/core/argf/bytes_spec.rb
deleted file mode 100644
index 01a3a3db0d..0000000000
--- a/spec/ruby/core/argf/bytes_spec.rb
+++ /dev/null
@@ -1,6 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/each_byte', __FILE__)
-
-describe "ARGF.bytes" do
- it_behaves_like :argf_each_byte, :bytes
-end
diff --git a/spec/ruby/core/argf/chars_spec.rb b/spec/ruby/core/argf/chars_spec.rb
deleted file mode 100644
index 8c9e4844c0..0000000000
--- a/spec/ruby/core/argf/chars_spec.rb
+++ /dev/null
@@ -1,6 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/each_char', __FILE__)
-
-describe "ARGF.chars" do
- it_behaves_like :argf_each_char, :chars
-end
diff --git a/spec/ruby/core/argf/close_spec.rb b/spec/ruby/core/argf/close_spec.rb
index b56f7f5564..8ca7d71dc2 100644
--- a/spec/ruby/core/argf/close_spec.rb
+++ b/spec/ruby/core/argf/close_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "ARGF.close" do
before :each do
@@ -10,31 +10,20 @@ describe "ARGF.close" do
argf [@file1_name, @file2_name] do
io = @argf.to_io
@argf.close
- io.closed?.should be_true
+ io.closed?.should == true
end
end
it "returns self" do
argf [@file1_name, @file2_name] do
- @argf.close.should equal(@argf)
+ @argf.close.should.equal?(@argf)
end
end
- ruby_version_is ""..."2.3" do
- it "raises an IOError if called on a closed stream" do
- argf [@file1_name] do
- lambda { @argf.close }.should_not raise_error
- lambda { @argf.close }.should raise_error(IOError)
- end
- end
- end
-
- ruby_version_is "2.3" do
- it "doesn't raise an IOError if called on a closed stream" do
- argf [@file1_name] do
- lambda { @argf.close }.should_not raise_error
- lambda { @argf.close }.should_not raise_error
- end
+ it "doesn't raise an IOError if called on a closed stream" do
+ argf [@file1_name] do
+ -> { @argf.close }.should_not.raise
+ -> { @argf.close }.should_not.raise
end
end
end
diff --git a/spec/ruby/core/argf/closed_spec.rb b/spec/ruby/core/argf/closed_spec.rb
index 745f102484..769381e8c3 100644
--- a/spec/ruby/core/argf/closed_spec.rb
+++ b/spec/ruby/core/argf/closed_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "ARGF.closed?" do
before :each do
@@ -11,7 +11,7 @@ describe "ARGF.closed?" do
stream = @argf.to_io
stream.close
- @argf.closed?.should be_true
+ @argf.closed?.should == true
stream.reopen(@argf.filename, 'r')
end
end
diff --git a/spec/ruby/core/argf/codepoints_spec.rb b/spec/ruby/core/argf/codepoints_spec.rb
deleted file mode 100644
index cd839cbb8c..0000000000
--- a/spec/ruby/core/argf/codepoints_spec.rb
+++ /dev/null
@@ -1,6 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/each_codepoint', __FILE__)
-
-describe "ARGF.codepoints" do
- it_behaves_like :argf_each_codepoint, :codepoints
-end
diff --git a/spec/ruby/core/argf/each_byte_spec.rb b/spec/ruby/core/argf/each_byte_spec.rb
index 8b4a62c2b1..d9e4e7fe5b 100644
--- a/spec/ruby/core/argf/each_byte_spec.rb
+++ b/spec/ruby/core/argf/each_byte_spec.rb
@@ -1,6 +1,60 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/each_byte', __FILE__)
+require_relative '../../spec_helper'
describe "ARGF.each_byte" do
- it_behaves_like :argf_each_byte, :each_byte
+ before :each do
+ @file1_name = fixture __FILE__, "file1.txt"
+ @file2_name = fixture __FILE__, "file2.txt"
+
+ @bytes = []
+ File.read(@file1_name).each_byte { |b| @bytes << b }
+ File.read(@file2_name).each_byte { |b| @bytes << b }
+ end
+
+ it "yields each byte of all streams to the passed block" do
+ argf [@file1_name, @file2_name] do
+ bytes = []
+ @argf.each_byte { |b| bytes << b }
+ bytes.should == @bytes
+ end
+ end
+
+ it "returns self when passed a block" do
+ argf [@file1_name, @file2_name] do
+ @argf.each_byte {}.should.equal?(@argf)
+ end
+ end
+
+ it "returns an Enumerator when passed no block" do
+ argf [@file1_name, @file2_name] do
+ enum = @argf.each_byte
+ enum.should.instance_of?(Enumerator)
+
+ bytes = []
+ enum.each { |b| bytes << b }
+ bytes.should == @bytes
+ end
+ end
+
+ describe "when no block is given" do
+ it "returns an Enumerator" do
+ argf [@file1_name, @file2_name] do
+ enum = @argf.each_byte
+ enum.should.instance_of?(Enumerator)
+
+ bytes = []
+ enum.each { |b| bytes << b }
+ bytes.should == @bytes
+ end
+ end
+
+ describe "returned Enumerator" do
+ describe "size" do
+ it "should return nil" do
+ argf [@file1_name, @file2_name] do
+ @argf.each_byte.size.should == nil
+ end
+ end
+ end
+ end
+ end
end
diff --git a/spec/ruby/core/argf/each_char_spec.rb b/spec/ruby/core/argf/each_char_spec.rb
index 58ac0bf783..62d19b6574 100644
--- a/spec/ruby/core/argf/each_char_spec.rb
+++ b/spec/ruby/core/argf/each_char_spec.rb
@@ -1,6 +1,60 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/each_char', __FILE__)
+require_relative '../../spec_helper'
describe "ARGF.each_char" do
- it_behaves_like :argf_each_char, :each_char
+ before :each do
+ @file1_name = fixture __FILE__, "file1.txt"
+ @file2_name = fixture __FILE__, "file2.txt"
+
+ @chars = []
+ File.read(@file1_name).each_char { |c| @chars << c }
+ File.read(@file2_name).each_char { |c| @chars << c }
+ end
+
+ it "yields each char of all streams to the passed block" do
+ argf [@file1_name, @file2_name] do
+ chars = []
+ @argf.each_char { |c| chars << c }
+ chars.should == @chars
+ end
+ end
+
+ it "returns self when passed a block" do
+ argf [@file1_name, @file2_name] do
+ @argf.each_char {}.should.equal?(@argf)
+ end
+ end
+
+ it "returns an Enumerator when passed no block" do
+ argf [@file1_name, @file2_name] do
+ enum = @argf.each_char
+ enum.should.instance_of?(Enumerator)
+
+ chars = []
+ enum.each { |c| chars << c }
+ chars.should == @chars
+ end
+ end
+
+ describe "when no block is given" do
+ it "returns an Enumerator" do
+ argf [@file1_name, @file2_name] do
+ enum = @argf.each_char
+ enum.should.instance_of?(Enumerator)
+
+ chars = []
+ enum.each { |c| chars << c }
+ chars.should == @chars
+ end
+ end
+
+ describe "returned Enumerator" do
+ describe "size" do
+ it "should return nil" do
+ argf [@file1_name, @file2_name] do
+ @argf.each_char.size.should == nil
+ end
+ end
+ end
+ end
+ end
end
diff --git a/spec/ruby/core/argf/each_codepoint_spec.rb b/spec/ruby/core/argf/each_codepoint_spec.rb
index d0725841a7..ad55785cba 100644
--- a/spec/ruby/core/argf/each_codepoint_spec.rb
+++ b/spec/ruby/core/argf/each_codepoint_spec.rb
@@ -1,6 +1,60 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/each_codepoint', __FILE__)
+require_relative '../../spec_helper'
describe "ARGF.each_codepoint" do
- it_behaves_like :argf_each_codepoint, :each_codepoint
+ before :each do
+ file1_name = fixture __FILE__, "file1.txt"
+ file2_name = fixture __FILE__, "file2.txt"
+ @filenames = [file1_name, file2_name]
+
+ @codepoints = File.read(file1_name).codepoints
+ @codepoints.concat File.read(file2_name).codepoints
+ end
+
+ it "is a public method" do
+ argf @filenames do
+ @argf.public_methods(false).should.include?(:each_codepoint)
+ end
+ end
+
+ it "does not require arguments" do
+ argf @filenames do
+ @argf.method(:each_codepoint).arity.should == 0
+ end
+ end
+
+ it "returns self when passed a block" do
+ argf @filenames do
+ @argf.each_codepoint {}.should.equal?(@argf)
+ end
+ end
+
+ it "returns an Enumerator when passed no block" do
+ argf @filenames do
+ @argf.each_codepoint.should.instance_of?(Enumerator)
+ end
+ end
+
+ it "yields each codepoint of all streams" do
+ argf @filenames do
+ @argf.each_codepoint.to_a.should == @codepoints
+ end
+ end
+
+ describe "when no block is given" do
+ it "returns an Enumerator" do
+ argf @filenames do
+ @argf.each_codepoint.should.instance_of?(Enumerator)
+ end
+ end
+
+ describe "returned Enumerator" do
+ describe "size" do
+ it "should return nil" do
+ argf @filenames do
+ @argf.each_codepoint.size.should == nil
+ end
+ end
+ end
+ end
+ end
end
diff --git a/spec/ruby/core/argf/each_line_spec.rb b/spec/ruby/core/argf/each_line_spec.rb
index d37968af3d..fc4d6433b8 100644
--- a/spec/ruby/core/argf/each_line_spec.rb
+++ b/spec/ruby/core/argf/each_line_spec.rb
@@ -1,6 +1,64 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/each_line', __FILE__)
+require_relative '../../spec_helper'
describe "ARGF.each_line" do
- it_behaves_like :argf_each_line, :each_line
+ before :each do
+ @file1_name = fixture __FILE__, "file1.txt"
+ @file2_name = fixture __FILE__, "file2.txt"
+
+ @lines = File.readlines @file1_name
+ @lines += File.readlines @file2_name
+ end
+
+ it "is a public method" do
+ argf [@file1_name, @file2_name] do
+ @argf.public_methods(false).should.include?(:each_line)
+ end
+ end
+
+ it "requires multiple arguments" do
+ argf [@file1_name, @file2_name] do
+ @argf.method(:each_line).arity.should < 0
+ end
+ end
+
+ it "reads each line of files" do
+ argf [@file1_name, @file2_name] do
+ lines = []
+ @argf.each_line { |b| lines << b }
+ lines.should == @lines
+ end
+ end
+
+ it "returns self when passed a block" do
+ argf [@file1_name, @file2_name] do
+ @argf.each_line {}.should.equal?(@argf)
+ end
+ end
+
+ describe "with a separator" do
+ it "yields each separated section of all streams" do
+ argf [@file1_name, @file2_name] do
+ @argf.send(:each_line, '.').to_a.should ==
+ (File.readlines(@file1_name, '.') + File.readlines(@file2_name, '.'))
+ end
+ end
+ end
+
+ describe "when no block is given" do
+ it "returns an Enumerator" do
+ argf [@file1_name, @file2_name] do
+ @argf.each_line.should.instance_of?(Enumerator)
+ end
+ end
+
+ describe "returned Enumerator" do
+ describe "size" do
+ it "should return nil" do
+ argf [@file1_name, @file2_name] do
+ @argf.each_line.size.should == nil
+ end
+ end
+ end
+ end
+ end
end
diff --git a/spec/ruby/core/argf/each_spec.rb b/spec/ruby/core/argf/each_spec.rb
index 5a1e0dc73c..25f60b31d2 100644
--- a/spec/ruby/core/argf/each_spec.rb
+++ b/spec/ruby/core/argf/each_spec.rb
@@ -1,6 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/each_line', __FILE__)
+require_relative '../../spec_helper'
describe "ARGF.each" do
- it_behaves_like :argf_each_line, :each
+ it "is an alias of ARGF.each_line" do
+ ARGF.method(:each).should == ARGF.method(:each_line)
+ end
end
diff --git a/spec/ruby/core/argf/eof_spec.rb b/spec/ruby/core/argf/eof_spec.rb
index 534bf1f8d8..940d104d69 100644
--- a/spec/ruby/core/argf/eof_spec.rb
+++ b/spec/ruby/core/argf/eof_spec.rb
@@ -1,10 +1,32 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/eof', __FILE__)
+require_relative '../../spec_helper'
describe "ARGF.eof" do
- it_behaves_like :argf_eof, :eof
+ it "is an alias of ARGF.eof?" do
+ ARGF.method(:eof).should == ARGF.method(:eof?)
+ end
end
describe "ARGF.eof?" do
- it_behaves_like :argf_eof, :eof?
+ before :each do
+ @file1 = fixture __FILE__, "file1.txt"
+ @file2 = fixture __FILE__, "file2.txt"
+ end
+
+ # NOTE: this test assumes that fixtures files have two lines each
+ it "returns true when reaching the end of a file" do
+ argf [@file1, @file2] do
+ result = []
+ while @argf.gets
+ result << @argf.eof?
+ end
+ result.should == [false, true, false, true]
+ end
+ end
+
+ it "raises IOError when called on a closed stream" do
+ argf [@file1] do
+ @argf.read
+ -> { @argf.eof? }.should.raise(IOError)
+ end
+ end
end
diff --git a/spec/ruby/core/argf/file_spec.rb b/spec/ruby/core/argf/file_spec.rb
index 248ffeff17..df8552d457 100644
--- a/spec/ruby/core/argf/file_spec.rb
+++ b/spec/ruby/core/argf/file_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "ARGF.file" do
before :each do
diff --git a/spec/ruby/core/argf/filename_spec.rb b/spec/ruby/core/argf/filename_spec.rb
index f7ebafa7c5..f4b6e922c6 100644
--- a/spec/ruby/core/argf/filename_spec.rb
+++ b/spec/ruby/core/argf/filename_spec.rb
@@ -1,6 +1,30 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/filename', __FILE__)
+require_relative '../../spec_helper'
describe "ARGF.filename" do
- it_behaves_like :argf_filename, :filename
+ before :each do
+ @file1 = fixture __FILE__, "file1.txt"
+ @file2 = fixture __FILE__, "file2.txt"
+ end
+
+ # NOTE: this test assumes that fixtures files have two lines each
+ it "returns the current file name on each file" do
+ argf [@file1, @file2] do
+ result = []
+ # returns first current file even when not yet open
+ result << @argf.filename
+ result << @argf.filename while @argf.gets
+ # returns last current file even when closed
+ result << @argf.filename
+
+ result.map! { |f| File.expand_path(f) }
+ result.should == [@file1, @file1, @file1, @file2, @file2, @file2]
+ end
+ end
+
+ # NOTE: this test assumes that fixtures files have two lines each
+ it "sets the $FILENAME global variable with the current file name on each file" do
+ script = fixture __FILE__, "filename.rb"
+ out = ruby_exe(script, args: [@file1, @file2])
+ out.should == "#{@file1}\n#{@file1}\n#{@file2}\n#{@file2}\n#{@file2}\n"
+ end
end
diff --git a/spec/ruby/core/argf/fileno_spec.rb b/spec/ruby/core/argf/fileno_spec.rb
index b35047695c..99245f043c 100644
--- a/spec/ruby/core/argf/fileno_spec.rb
+++ b/spec/ruby/core/argf/fileno_spec.rb
@@ -1,6 +1,26 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/fileno', __FILE__)
+require_relative '../../spec_helper'
describe "ARGF.fileno" do
- it_behaves_like :argf_fileno, :fileno
+ before :each do
+ @file1 = fixture __FILE__, "file1.txt"
+ @file2 = fixture __FILE__, "file2.txt"
+ end
+
+ # NOTE: this test assumes that fixtures files have two lines each
+ it "returns the current file number on each file" do
+ argf [@file1, @file2] do
+ result = []
+ # returns first current file even when not yet open
+ result << @argf.fileno while @argf.gets
+ # returns last current file even when closed
+ result.map { |d| d.class }.should == [Integer, Integer, Integer, Integer]
+ end
+ end
+
+ it "raises an ArgumentError when called on a closed stream" do
+ argf [@file1] do
+ @argf.read
+ -> { @argf.fileno }.should.raise(ArgumentError)
+ end
+ end
end
diff --git a/spec/ruby/core/argf/getc_spec.rb b/spec/ruby/core/argf/getc_spec.rb
index de5e6fa73c..dc5de9b7df 100644
--- a/spec/ruby/core/argf/getc_spec.rb
+++ b/spec/ruby/core/argf/getc_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/getc', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/getc'
describe "ARGF.getc" do
it_behaves_like :argf_getc, :getc
diff --git a/spec/ruby/core/argf/gets_spec.rb b/spec/ruby/core/argf/gets_spec.rb
index b65aa076bd..cc7673b190 100644
--- a/spec/ruby/core/argf/gets_spec.rb
+++ b/spec/ruby/core/argf/gets_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/gets', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/gets'
describe "ARGF.gets" do
it_behaves_like :argf_gets, :gets
@@ -26,25 +26,23 @@ describe "ARGF.gets" do
end
end
- with_feature :encoding do
- before :each do
- @external = Encoding.default_external
- @internal = Encoding.default_internal
+ before :each do
+ @external = Encoding.default_external
+ @internal = Encoding.default_internal
- Encoding.default_external = Encoding::UTF_8
- Encoding.default_internal = nil
- end
+ Encoding.default_external = Encoding::UTF_8
+ Encoding.default_internal = nil
+ end
- after :each do
- Encoding.default_external = @external
- Encoding.default_internal = @internal
- end
+ after :each do
+ Encoding.default_external = @external
+ Encoding.default_internal = @internal
+ end
- it "reads the contents of the file with default encoding" do
- Encoding.default_external = Encoding::US_ASCII
- argf [@file1_name, @file2_name] do
- @argf.gets.encoding.should == Encoding::US_ASCII
- end
+ it "reads the contents of the file with default encoding" do
+ Encoding.default_external = Encoding::US_ASCII
+ argf [@file1_name, @file2_name] do
+ @argf.gets.encoding.should == Encoding::US_ASCII
end
end
diff --git a/spec/ruby/core/argf/inspect_spec.rb b/spec/ruby/core/argf/inspect_spec.rb
new file mode 100644
index 0000000000..df0e3ba8dc
--- /dev/null
+++ b/spec/ruby/core/argf/inspect_spec.rb
@@ -0,0 +1,7 @@
+require_relative '../../spec_helper'
+
+describe "ARGF.inspect" do
+ it "is an alias of ARGF.to_s" do
+ ARGF.method(:inspect).should == ARGF.method(:to_s)
+ end
+end
diff --git a/spec/ruby/core/argf/lineno_spec.rb b/spec/ruby/core/argf/lineno_spec.rb
index 13b1916fb1..72a108c187 100644
--- a/spec/ruby/core/argf/lineno_spec.rb
+++ b/spec/ruby/core/argf/lineno_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "ARGF.lineno" do
before :each do
diff --git a/spec/ruby/core/argf/lines_spec.rb b/spec/ruby/core/argf/lines_spec.rb
deleted file mode 100644
index ea3578e3a2..0000000000
--- a/spec/ruby/core/argf/lines_spec.rb
+++ /dev/null
@@ -1,6 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/each_line', __FILE__)
-
-describe "ARGF.lines" do
- it_behaves_like :argf_each_line, :lines
-end
diff --git a/spec/ruby/core/argf/path_spec.rb b/spec/ruby/core/argf/path_spec.rb
index 098de8693a..2f7b91999f 100644
--- a/spec/ruby/core/argf/path_spec.rb
+++ b/spec/ruby/core/argf/path_spec.rb
@@ -1,6 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/filename', __FILE__)
+require_relative '../../spec_helper'
describe "ARGF.path" do
- it_behaves_like :argf_filename, :path
+ it "is an alias of ARGF.filename" do
+ ARGF.method(:path).should == ARGF.method(:filename)
+ end
end
diff --git a/spec/ruby/core/argf/pos_spec.rb b/spec/ruby/core/argf/pos_spec.rb
index b6e5c3a254..1ff16e4f17 100644
--- a/spec/ruby/core/argf/pos_spec.rb
+++ b/spec/ruby/core/argf/pos_spec.rb
@@ -1,8 +1,35 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/pos', __FILE__)
+require_relative '../../spec_helper'
describe "ARGF.pos" do
- it_behaves_like :argf_pos, :pos
+ before :each do
+ @file1 = fixture __FILE__, "file1.txt"
+ @file2 = fixture __FILE__, "file2.txt"
+ end
+
+ it "gives the correct position for each read operation" do
+ argf [@file1, @file2] do
+ size1 = File.size(@file1)
+ size2 = File.size(@file2)
+
+ @argf.read(2)
+ @argf.pos.should == 2
+ @argf.read(size1-2)
+ @argf.pos.should == size1
+ @argf.read(6)
+ @argf.pos.should == 6
+ @argf.rewind
+ @argf.pos.should == 0
+ @argf.read(size2)
+ @argf.pos.should == size2
+ end
+ end
+
+ it "raises an ArgumentError when called on a closed stream" do
+ argf [@file1] do
+ @argf.read
+ -> { @argf.pos }.should.raise(ArgumentError)
+ end
+ end
end
describe "ARGF.pos=" do
diff --git a/spec/ruby/core/argf/read_nonblock_spec.rb b/spec/ruby/core/argf/read_nonblock_spec.rb
index 8176a206e5..5c6bd52d80 100644
--- a/spec/ruby/core/argf/read_nonblock_spec.rb
+++ b/spec/ruby/core/argf/read_nonblock_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/read', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/read'
platform_is_not :windows do
describe 'ARGF.read_nonblock' do
@@ -64,17 +64,15 @@ platform_is_not :windows do
it 'raises IO::EAGAINWaitReadable when empty' do
argf ['-'] do
- lambda {
+ -> {
@argf.read_nonblock(4)
- }.should raise_error(IO::EAGAINWaitReadable)
+ }.should.raise(IO::EAGAINWaitReadable)
end
end
- ruby_version_is "2.3" do
- it 'returns :wait_readable when the :exception is set to false' do
- argf ['-'] do
- @argf.read_nonblock(4, nil, exception: false).should == :wait_readable
- end
+ it 'returns :wait_readable when the :exception is set to false' do
+ argf ['-'] do
+ @argf.read_nonblock(4, nil, exception: false).should == :wait_readable
end
end
end
diff --git a/spec/ruby/core/argf/read_spec.rb b/spec/ruby/core/argf/read_spec.rb
index 4eaaea46bb..bbeef95456 100644
--- a/spec/ruby/core/argf/read_spec.rb
+++ b/spec/ruby/core/argf/read_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/read', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/read'
describe "ARGF.read" do
it_behaves_like :argf_read, :read
@@ -62,26 +62,24 @@ describe "ARGF.read" do
end
end
- with_feature :encoding do
- before :each do
- @external = Encoding.default_external
- @internal = Encoding.default_internal
+ before :each do
+ @external = Encoding.default_external
+ @internal = Encoding.default_internal
- Encoding.default_external = Encoding::UTF_8
- Encoding.default_internal = nil
- end
+ Encoding.default_external = Encoding::UTF_8
+ Encoding.default_internal = nil
+ end
- after :each do
- Encoding.default_external = @external
- Encoding.default_internal = @internal
- end
+ after :each do
+ Encoding.default_external = @external
+ Encoding.default_internal = @internal
+ end
- it "reads the contents of the file with default encoding" do
- Encoding.default_external = Encoding::US_ASCII
- argf [@file1_name, @file2_name] do
- @argf.read.encoding.should == Encoding::US_ASCII
- end
+ it "reads the contents of the file with default encoding" do
+ Encoding.default_external = Encoding::US_ASCII
+ argf [@file1_name, @file2_name] do
+ @argf.read.encoding.should == Encoding::US_ASCII
end
end
end
diff --git a/spec/ruby/core/argf/readchar_spec.rb b/spec/ruby/core/argf/readchar_spec.rb
index 71e2a6c742..63632721ec 100644
--- a/spec/ruby/core/argf/readchar_spec.rb
+++ b/spec/ruby/core/argf/readchar_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/getc', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/getc'
describe "ARGF.getc" do
it_behaves_like :argf_getc, :readchar
@@ -13,7 +13,7 @@ describe "ARGF.readchar" do
it "raises EOFError when end of stream reached" do
argf [@file1, @file2] do
- lambda { while @argf.readchar; end }.should raise_error(EOFError)
+ -> { while @argf.readchar; end }.should.raise(EOFError)
end
end
end
diff --git a/spec/ruby/core/argf/readline_spec.rb b/spec/ruby/core/argf/readline_spec.rb
index d31cfce415..8c23549b1b 100644
--- a/spec/ruby/core/argf/readline_spec.rb
+++ b/spec/ruby/core/argf/readline_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/gets', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/gets'
describe "ARGF.readline" do
it_behaves_like :argf_gets, :readline
@@ -17,7 +17,7 @@ describe "ARGF.readline" do
it "raises an EOFError when reaching end of files" do
argf [@file1, @file2] do
- lambda { while @argf.readline; end }.should raise_error(EOFError)
+ -> { while @argf.readline; end }.should.raise(EOFError)
end
end
end
diff --git a/spec/ruby/core/argf/readlines_spec.rb b/spec/ruby/core/argf/readlines_spec.rb
index 8e68429aa8..156bb6a33f 100644
--- a/spec/ruby/core/argf/readlines_spec.rb
+++ b/spec/ruby/core/argf/readlines_spec.rb
@@ -1,6 +1,24 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/readlines', __FILE__)
+require_relative '../../spec_helper'
describe "ARGF.readlines" do
- it_behaves_like :argf_readlines, :readlines
+ before :each do
+ @file1 = fixture __FILE__, "file1.txt"
+ @file2 = fixture __FILE__, "file2.txt"
+
+ @lines = File.readlines(@file1)
+ @lines += File.readlines(@file2)
+ end
+
+ it "reads all lines of all files" do
+ argf [@file1, @file2] do
+ @argf.readlines.should == @lines
+ end
+ end
+
+ it "returns an empty Array when end of stream reached" do
+ argf [@file1, @file2] do
+ @argf.read
+ @argf.readlines.should == []
+ end
+ end
end
diff --git a/spec/ruby/core/argf/readpartial_spec.rb b/spec/ruby/core/argf/readpartial_spec.rb
index 61c330182c..9f04e72cc2 100644
--- a/spec/ruby/core/argf/readpartial_spec.rb
+++ b/spec/ruby/core/argf/readpartial_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/read', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/read'
describe "ARGF.readpartial" do
it_behaves_like :argf_read, :readpartial
@@ -16,7 +16,7 @@ describe "ARGF.readpartial" do
it "raises an ArgumentError if called without a maximum read length" do
argf [@file1_name] do
- lambda { @argf.readpartial }.should raise_error(ArgumentError)
+ -> { @argf.readpartial }.should.raise(ArgumentError)
end
end
@@ -29,7 +29,7 @@ describe "ARGF.readpartial" do
it "clears output buffer even if EOFError is raised because @argf is at end" do
begin
- output = "to be cleared"
+ output = +"to be cleared"
argf [@file1_name] do
@argf.read
@@ -54,15 +54,13 @@ describe "ARGF.readpartial" do
end
end
- ruby_version_is "2.3" do
- it "raises an EOFError if the exception was raised while reading the last file" do
- argf [@file1_name, @file2_name] do
- @argf.readpartial(@file1.size)
- @argf.readpartial(1)
- @argf.readpartial(@file2.size)
- lambda { @argf.readpartial(1) }.should raise_error(EOFError)
- lambda { @argf.readpartial(1) }.should raise_error(EOFError)
- end
+ it "raises an EOFError if the exception was raised while reading the last file" do
+ argf [@file1_name, @file2_name] do
+ @argf.readpartial(@file1.size)
+ @argf.readpartial(1)
+ @argf.readpartial(@file2.size)
+ -> { @argf.readpartial(1) }.should.raise(EOFError)
+ -> { @argf.readpartial(1) }.should.raise(EOFError)
end
end
@@ -71,7 +69,7 @@ describe "ARGF.readpartial" do
print ARGF.readpartial(#{@stdin.size})
ARGF.readpartial(1) rescue print $!.class
STR
- stdin = ruby_exe(ruby_str, args: "< #{@stdin_name}", escape: true)
+ stdin = ruby_exe(ruby_str, args: "< #{@stdin_name}")
stdin.should == @stdin + "EOFError"
end
end
diff --git a/spec/ruby/core/argf/rewind_spec.rb b/spec/ruby/core/argf/rewind_spec.rb
index d6abc3a856..9255f790fe 100644
--- a/spec/ruby/core/argf/rewind_spec.rb
+++ b/spec/ruby/core/argf/rewind_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "ARGF.rewind" do
before :each do
@@ -33,7 +33,7 @@ describe "ARGF.rewind" do
it "raises an ArgumentError when end of stream reached" do
argf [@file1_name, @file2_name] do
@argf.read
- lambda { @argf.rewind }.should raise_error(ArgumentError)
+ -> { @argf.rewind }.should.raise(ArgumentError)
end
end
end
diff --git a/spec/ruby/core/argf/seek_spec.rb b/spec/ruby/core/argf/seek_spec.rb
index 97dacb6cfc..c1ea1ea438 100644
--- a/spec/ruby/core/argf/seek_spec.rb
+++ b/spec/ruby/core/argf/seek_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "ARGF.seek" do
before :each do
@@ -57,7 +57,7 @@ describe "ARGF.seek" do
it "takes at least one argument (offset)" do
argf [@file1_name] do
- lambda { @argf.seek }.should raise_error(ArgumentError)
+ -> { @argf.seek }.should.raise(ArgumentError)
end
end
end
diff --git a/spec/ruby/core/argf/set_encoding_spec.rb b/spec/ruby/core/argf/set_encoding_spec.rb
index f6ec74ded1..a871e084b6 100644
--- a/spec/ruby/core/argf/set_encoding_spec.rb
+++ b/spec/ruby/core/argf/set_encoding_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "ARGF.set_encoding" do
before :each do
diff --git a/spec/ruby/core/argf/shared/each_byte.rb b/spec/ruby/core/argf/shared/each_byte.rb
deleted file mode 100644
index 6b1dc1dae2..0000000000
--- a/spec/ruby/core/argf/shared/each_byte.rb
+++ /dev/null
@@ -1,58 +0,0 @@
-describe :argf_each_byte, shared: true do
- before :each do
- @file1_name = fixture __FILE__, "file1.txt"
- @file2_name = fixture __FILE__, "file2.txt"
-
- @bytes = []
- File.read(@file1_name).each_byte { |b| @bytes << b }
- File.read(@file2_name).each_byte { |b| @bytes << b }
- end
-
- it "yields each byte of all streams to the passed block" do
- argf [@file1_name, @file2_name] do
- bytes = []
- @argf.send(@method) { |b| bytes << b }
- bytes.should == @bytes
- end
- end
-
- it "returns self when passed a block" do
- argf [@file1_name, @file2_name] do
- @argf.send(@method) {}.should equal(@argf)
- end
- end
-
- it "returns an Enumerator when passed no block" do
- argf [@file1_name, @file2_name] do
- enum = @argf.send(@method)
- enum.should be_an_instance_of(Enumerator)
-
- bytes = []
- enum.each { |b| bytes << b }
- bytes.should == @bytes
- end
- end
-
- describe "when no block is given" do
- it "returns an Enumerator" do
- argf [@file1_name, @file2_name] do
- enum = @argf.send(@method)
- enum.should be_an_instance_of(Enumerator)
-
- bytes = []
- enum.each { |b| bytes << b }
- bytes.should == @bytes
- end
- end
-
- describe "returned Enumerator" do
- describe "size" do
- it "should return nil" do
- argf [@file1_name, @file2_name] do
- @argf.send(@method).size.should == nil
- end
- end
- end
- end
- end
-end
diff --git a/spec/ruby/core/argf/shared/each_char.rb b/spec/ruby/core/argf/shared/each_char.rb
deleted file mode 100644
index 9e333ecc5b..0000000000
--- a/spec/ruby/core/argf/shared/each_char.rb
+++ /dev/null
@@ -1,58 +0,0 @@
-describe :argf_each_char, shared: true do
- before :each do
- @file1_name = fixture __FILE__, "file1.txt"
- @file2_name = fixture __FILE__, "file2.txt"
-
- @chars = []
- File.read(@file1_name).each_char { |c| @chars << c }
- File.read(@file2_name).each_char { |c| @chars << c }
- end
-
- it "yields each char of all streams to the passed block" do
- argf [@file1_name, @file2_name] do
- chars = []
- @argf.send(@method) { |c| chars << c }
- chars.should == @chars
- end
- end
-
- it "returns self when passed a block" do
- argf [@file1_name, @file2_name] do
- @argf.send(@method) {}.should equal(@argf)
- end
- end
-
- it "returns an Enumerator when passed no block" do
- argf [@file1_name, @file2_name] do
- enum = @argf.send(@method)
- enum.should be_an_instance_of(Enumerator)
-
- chars = []
- enum.each { |c| chars << c }
- chars.should == @chars
- end
- end
-
- describe "when no block is given" do
- it "returns an Enumerator" do
- argf [@file1_name, @file2_name] do
- enum = @argf.send(@method)
- enum.should be_an_instance_of(Enumerator)
-
- chars = []
- enum.each { |c| chars << c }
- chars.should == @chars
- end
- end
-
- describe "returned Enumerator" do
- describe "size" do
- it "should return nil" do
- argf [@file1_name, @file2_name] do
- @argf.send(@method).size.should == nil
- end
- end
- end
- end
- end
-end
diff --git a/spec/ruby/core/argf/shared/each_codepoint.rb b/spec/ruby/core/argf/shared/each_codepoint.rb
deleted file mode 100644
index e2a2dfff46..0000000000
--- a/spec/ruby/core/argf/shared/each_codepoint.rb
+++ /dev/null
@@ -1,58 +0,0 @@
-describe :argf_each_codepoint, shared: true do
- before :each do
- file1_name = fixture __FILE__, "file1.txt"
- file2_name = fixture __FILE__, "file2.txt"
- @filenames = [file1_name, file2_name]
-
- @codepoints = File.read(file1_name).codepoints
- @codepoints.concat File.read(file2_name).codepoints
- end
-
- it "is a public method" do
- argf @filenames do
- @argf.public_methods(false).should include(@method)
- end
- end
-
- it "does not require arguments" do
- argf @filenames do
- @argf.method(@method).arity.should == 0
- end
- end
-
- it "returns self when passed a block" do
- argf @filenames do
- @argf.send(@method) {}.should equal(@argf)
- end
- end
-
- it "returns an Enumerator when passed no block" do
- argf @filenames do
- @argf.send(@method).should be_an_instance_of(Enumerator)
- end
- end
-
- it "yields each codepoint of all streams" do
- argf @filenames do
- @argf.send(@method).to_a.should == @codepoints
- end
- end
-
- describe "when no block is given" do
- it "returns an Enumerator" do
- argf @filenames do
- @argf.send(@method).should be_an_instance_of(Enumerator)
- end
- end
-
- describe "returned Enumerator" do
- describe "size" do
- it "should return nil" do
- argf @filenames do
- @argf.send(@method).size.should == nil
- end
- end
- end
- end
- end
-end
diff --git a/spec/ruby/core/argf/shared/each_line.rb b/spec/ruby/core/argf/shared/each_line.rb
deleted file mode 100644
index c0ef77dc54..0000000000
--- a/spec/ruby/core/argf/shared/each_line.rb
+++ /dev/null
@@ -1,62 +0,0 @@
-describe :argf_each_line, shared: true do
- before :each do
- @file1_name = fixture __FILE__, "file1.txt"
- @file2_name = fixture __FILE__, "file2.txt"
-
- @lines = File.readlines @file1_name
- @lines += File.readlines @file2_name
- end
-
- it "is a public method" do
- argf [@file1_name, @file2_name] do
- @argf.public_methods(false).should include(@method)
- end
- end
-
- it "requires multiple arguments" do
- argf [@file1_name, @file2_name] do
- @argf.method(@method).arity.should < 0
- end
- end
-
- it "reads each line of files" do
- argf [@file1_name, @file2_name] do
- lines = []
- @argf.send(@method) { |b| lines << b }
- lines.should == @lines
- end
- end
-
- it "returns self when passed a block" do
- argf [@file1_name, @file2_name] do
- @argf.send(@method) {}.should equal(@argf)
- end
- end
-
- describe "with a separator" do
- it "yields each separated section of all streams" do
- argf [@file1_name, @file2_name] do
- @argf.send(@method, '.').to_a.should ==
- (File.readlines(@file1_name, '.') + File.readlines(@file2_name, '.'))
- end
- end
- end
-
- describe "when no block is given" do
- it "returns an Enumerator" do
- argf [@file1_name, @file2_name] do
- @argf.send(@method).should be_an_instance_of(Enumerator)
- end
- end
-
- describe "returned Enumerator" do
- describe "size" do
- it "should return nil" do
- argf [@file1_name, @file2_name] do
- @argf.send(@method).size.should == nil
- end
- end
- end
- end
- end
-end
diff --git a/spec/ruby/core/argf/shared/eof.rb b/spec/ruby/core/argf/shared/eof.rb
deleted file mode 100644
index bba18ede50..0000000000
--- a/spec/ruby/core/argf/shared/eof.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-describe :argf_eof, shared: true do
- before :each do
- @file1 = fixture __FILE__, "file1.txt"
- @file2 = fixture __FILE__, "file2.txt"
- end
-
- # NOTE: this test assumes that fixtures files have two lines each
- it "returns true when reaching the end of a file" do
- argf [@file1, @file2] do
- result = []
- while @argf.gets
- result << @argf.send(@method)
- end
- result.should == [false, true, false, true]
- end
- end
-
- it "raises IOError when called on a closed stream" do
- argf [@file1] do
- @argf.read
- lambda { @argf.send(@method) }.should raise_error(IOError)
- end
- end
-end
diff --git a/spec/ruby/core/argf/shared/filename.rb b/spec/ruby/core/argf/shared/filename.rb
deleted file mode 100644
index f47c673dc0..0000000000
--- a/spec/ruby/core/argf/shared/filename.rb
+++ /dev/null
@@ -1,28 +0,0 @@
-describe :argf_filename, shared: true do
- before :each do
- @file1 = fixture __FILE__, "file1.txt"
- @file2 = fixture __FILE__, "file2.txt"
- end
-
- # NOTE: this test assumes that fixtures files have two lines each
- it "returns the current file name on each file" do
- argf [@file1, @file2] do
- result = []
- # returns first current file even when not yet open
- result << @argf.send(@method)
- result << @argf.send(@method) while @argf.gets
- # returns last current file even when closed
- result << @argf.send(@method)
-
- result.map! { |f| File.expand_path(f) }
- result.should == [@file1, @file1, @file1, @file2, @file2, @file2]
- end
- end
-
- # NOTE: this test assumes that fixtures files have two lines each
- it "sets the $FILENAME global variable with the current file name on each file" do
- script = fixture __FILE__, "filename.rb"
- out = ruby_exe(script, args: [@file1, @file2])
- out.should == "#{@file1}\n#{@file1}\n#{@file2}\n#{@file2}\n#{@file2}\n"
- end
-end
diff --git a/spec/ruby/core/argf/shared/fileno.rb b/spec/ruby/core/argf/shared/fileno.rb
deleted file mode 100644
index 891e250ad9..0000000000
--- a/spec/ruby/core/argf/shared/fileno.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-describe :argf_fileno, shared: true do
- before :each do
- @file1 = fixture __FILE__, "file1.txt"
- @file2 = fixture __FILE__, "file2.txt"
- end
-
- # NOTE: this test assumes that fixtures files have two lines each
- it "returns the current file number on each file" do
- argf [@file1, @file2] do
- result = []
- # returns first current file even when not yet open
- result << @argf.send(@method) while @argf.gets
- # returns last current file even when closed
- result.map { |d| d.class }.should == [Fixnum, Fixnum, Fixnum, Fixnum]
- end
- end
-
- it "raises an ArgumentError when called on a closed stream" do
- argf [@file1] do
- @argf.read
- lambda { @argf.send(@method) }.should raise_error(ArgumentError)
- end
- end
-end
diff --git a/spec/ruby/core/argf/shared/getc.rb b/spec/ruby/core/argf/shared/getc.rb
index 8be39c60b6..d63372d9d7 100644
--- a/spec/ruby/core/argf/shared/getc.rb
+++ b/spec/ruby/core/argf/shared/getc.rb
@@ -9,7 +9,7 @@ describe :argf_getc, shared: true do
it "reads each char of files" do
argf [@file1, @file2] do
- chars = ""
+ chars = +""
@chars.size.times { chars << @argf.send(@method) }
chars.should == @chars
end
diff --git a/spec/ruby/core/argf/shared/pos.rb b/spec/ruby/core/argf/shared/pos.rb
deleted file mode 100644
index f7184f3d7c..0000000000
--- a/spec/ruby/core/argf/shared/pos.rb
+++ /dev/null
@@ -1,31 +0,0 @@
-describe :argf_pos, shared: true do
- before :each do
- @file1 = fixture __FILE__, "file1.txt"
- @file2 = fixture __FILE__, "file2.txt"
- end
-
- it "gives the correct position for each read operation" do
- argf [@file1, @file2] do
- size1 = File.size(@file1)
- size2 = File.size(@file2)
-
- @argf.read(2)
- @argf.send(@method).should == 2
- @argf.read(size1-2)
- @argf.send(@method).should == size1
- @argf.read(6)
- @argf.send(@method).should == 6
- @argf.rewind
- @argf.send(@method).should == 0
- @argf.read(size2)
- @argf.send(@method).should == size2
- end
- end
-
- it "raises an ArgumentError when called on a closed stream" do
- argf [@file1] do
- @argf.read
- lambda { @argf.send(@method) }.should raise_error(ArgumentError)
- end
- end
-end
diff --git a/spec/ruby/core/argf/shared/read.rb b/spec/ruby/core/argf/shared/read.rb
index fe903983c0..e76d022139 100644
--- a/spec/ruby/core/argf/shared/read.rb
+++ b/spec/ruby/core/argf/shared/read.rb
@@ -15,7 +15,7 @@ describe :argf_read, shared: true do
it "treats second argument as an output buffer" do
argf [@file1_name] do
- buffer = ""
+ buffer = +""
@argf.send(@method, @file1.size, buffer)
buffer.should == @file1
end
@@ -23,7 +23,7 @@ describe :argf_read, shared: true do
it "clears output buffer before appending to it" do
argf [@file1_name] do
- buffer = "to be cleared"
+ buffer = +"to be cleared"
@argf.send(@method, @file1.size, buffer)
buffer.should == @file1
end
diff --git a/spec/ruby/core/argf/shared/readlines.rb b/spec/ruby/core/argf/shared/readlines.rb
deleted file mode 100644
index 505fa94acb..0000000000
--- a/spec/ruby/core/argf/shared/readlines.rb
+++ /dev/null
@@ -1,22 +0,0 @@
-describe :argf_readlines, shared: true do
- before :each do
- @file1 = fixture __FILE__, "file1.txt"
- @file2 = fixture __FILE__, "file2.txt"
-
- @lines = File.readlines(@file1)
- @lines += File.readlines(@file2)
- end
-
- it "reads all lines of all files" do
- argf [@file1, @file2] do
- @argf.send(@method).should == @lines
- end
- end
-
- it "returns an empty Array when end of stream reached" do
- argf [@file1, @file2] do
- @argf.read
- @argf.send(@method).should == []
- end
- end
-end
diff --git a/spec/ruby/core/argf/skip_spec.rb b/spec/ruby/core/argf/skip_spec.rb
index 5f5e9eb79a..bb1c0ae110 100644
--- a/spec/ruby/core/argf/skip_spec.rb
+++ b/spec/ruby/core/argf/skip_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "ARGF.skip" do
before :each do
@@ -37,6 +37,6 @@ describe "ARGF.skip" do
# which as a side-effect calls argf.file which will initialize
# internals of ARGF enough for this to work.
it "has no effect when nothing has been processed yet" do
- lambda { ARGF.class.new(@file1_name).skip }.should_not raise_error
+ -> { ARGF.class.new(@file1_name).skip }.should_not.raise
end
end
diff --git a/spec/ruby/core/argf/tell_spec.rb b/spec/ruby/core/argf/tell_spec.rb
index bcd824f087..bb28df74a2 100644
--- a/spec/ruby/core/argf/tell_spec.rb
+++ b/spec/ruby/core/argf/tell_spec.rb
@@ -1,6 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/pos', __FILE__)
+require_relative '../../spec_helper'
describe "ARGF.tell" do
- it_behaves_like :argf_pos, :tell
+ it "is an alias of ARGF.pos" do
+ ARGF.method(:tell).should == ARGF.method(:pos)
+ end
end
diff --git a/spec/ruby/core/argf/to_a_spec.rb b/spec/ruby/core/argf/to_a_spec.rb
index 75b5c10c9b..d95dc732ec 100644
--- a/spec/ruby/core/argf/to_a_spec.rb
+++ b/spec/ruby/core/argf/to_a_spec.rb
@@ -1,6 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/readlines', __FILE__)
+require_relative '../../spec_helper'
describe "ARGF.to_a" do
- it_behaves_like :argf_readlines, :to_a
+ it "is an alias of ARGF.readlines" do
+ ARGF.method(:to_a).should == ARGF.method(:readlines)
+ end
end
diff --git a/spec/ruby/core/argf/to_i_spec.rb b/spec/ruby/core/argf/to_i_spec.rb
index 27359014af..e8df378f4e 100644
--- a/spec/ruby/core/argf/to_i_spec.rb
+++ b/spec/ruby/core/argf/to_i_spec.rb
@@ -1,6 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/fileno', __FILE__)
+require_relative '../../spec_helper'
describe "ARGF.to_i" do
- it_behaves_like :argf_fileno, :to_i
+ it "is an alias of ARGF.fileno" do
+ ARGF.method(:to_i).should == ARGF.method(:fileno)
+ end
end
diff --git a/spec/ruby/core/argf/to_io_spec.rb b/spec/ruby/core/argf/to_io_spec.rb
index 0575c35f25..ab5de58bcf 100644
--- a/spec/ruby/core/argf/to_io_spec.rb
+++ b/spec/ruby/core/argf/to_io_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "ARGF.to_io" do
before :each do
@@ -15,7 +15,7 @@ describe "ARGF.to_io" do
result << @argf.to_io
end
- result.each { |io| io.should be_kind_of(IO) }
+ result.each { |io| io.should.is_a?(IO) }
result[0].should == result[1]
result[2].should == result[3]
end
diff --git a/spec/ruby/core/argf/to_s_spec.rb b/spec/ruby/core/argf/to_s_spec.rb
index 0128049c3f..3f505898f4 100644
--- a/spec/ruby/core/argf/to_s_spec.rb
+++ b/spec/ruby/core/argf/to_s_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "ARGF.to_s" do
before :each do
diff --git a/spec/ruby/core/array/all_spec.rb b/spec/ruby/core/array/all_spec.rb
new file mode 100644
index 0000000000..680e8c26fa
--- /dev/null
+++ b/spec/ruby/core/array/all_spec.rb
@@ -0,0 +1,13 @@
+require_relative '../../spec_helper'
+require_relative 'shared/iterable_and_tolerating_size_increasing'
+
+describe "Array#all?" do
+ @value_to_return = -> _ { true }
+ it_behaves_like :array_iterable_and_tolerating_size_increasing, :all?
+
+ it "ignores the block if there is an argument" do
+ -> {
+ ['bar', 'foobar'].all?(/bar/) { false }.should == true
+ }.should complain(/given block not used/)
+ end
+end
diff --git a/spec/ruby/core/array/allocate_spec.rb b/spec/ruby/core/array/allocate_spec.rb
index bb5168cb74..c9eceef590 100644
--- a/spec/ruby/core/array/allocate_spec.rb
+++ b/spec/ruby/core/array/allocate_spec.rb
@@ -1,9 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Array.allocate" do
it "returns an instance of Array" do
ary = Array.allocate
- ary.should be_an_instance_of(Array)
+ ary.should.instance_of?(Array)
end
it "returns a fully-formed instance of Array" do
@@ -14,6 +14,6 @@ describe "Array.allocate" do
end
it "does not accept any arguments" do
- lambda { Array.allocate(1) }.should raise_error(ArgumentError)
+ -> { Array.allocate(1) }.should.raise(ArgumentError)
end
end
diff --git a/spec/ruby/core/array/any_spec.rb b/spec/ruby/core/array/any_spec.rb
index 7e9863420f..b51ce62f0f 100644
--- a/spec/ruby/core/array/any_spec.rb
+++ b/spec/ruby/core/array/any_spec.rb
@@ -1,24 +1,28 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/iterable_and_tolerating_size_increasing'
describe "Array#any?" do
describe 'with no block given (a default block of { |x| x } is implicit)' do
it "is false if the array is empty" do
empty_array = []
- empty_array.any?.should == false
+ empty_array.should_not.any?
end
it "is false if the array is not empty, but all the members of the array are falsy" do
falsy_array = [false, nil, false]
- falsy_array.any?.should == false
+ falsy_array.should_not.any?
end
it "is true if the array has any truthy members" do
not_empty_array = ['anything', nil]
- not_empty_array.any?.should == true
+ not_empty_array.should.any?
end
end
describe 'with a block given' do
+ @value_to_return = -> _ { false }
+ it_behaves_like :array_iterable_and_tolerating_size_increasing, :any?
+
it 'is false if the array is empty' do
empty_array = []
empty_array.any? {|v| 1 == 1 }.should == false
@@ -34,4 +38,12 @@ describe "Array#any?" do
array_with_members.any? {|v| v == 42 }.should == false
end
end
+
+ describe 'when given a pattern argument' do
+ it "ignores the block if there is an argument" do
+ -> {
+ ['bar', 'foobar'].any?(/bar/) { false }.should == true
+ }.should complain(/given block not used/)
+ end
+ end
end
diff --git a/spec/ruby/core/array/append_spec.rb b/spec/ruby/core/array/append_spec.rb
index 4c65004c58..5480d9f65e 100644
--- a/spec/ruby/core/array/append_spec.rb
+++ b/spec/ruby/core/array/append_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Array#<<" do
it "pushes the object onto the end of the array" do
@@ -9,8 +9,8 @@ describe "Array#<<" do
it "returns self to allow chaining" do
a = []
b = a
- (a << 1).should equal(b)
- (a << 2 << 3).should equal(b)
+ (a << 1).should.equal?(b)
+ (a << 2 << 3).should.equal?(b)
end
it "correctly resizes the Array" do
@@ -29,7 +29,13 @@ describe "Array#<<" do
a.should == [:foo]
end
- it "raises a RuntimeError on a frozen array" do
- lambda { ArraySpecs.frozen_array << 5 }.should raise_error(RuntimeError)
+ it "raises a FrozenError on a frozen array" do
+ -> { ArraySpecs.frozen_array << 5 }.should.raise(FrozenError)
+ end
+end
+
+describe "Array#append" do
+ it "is an alias of Array#push" do
+ Array.instance_method(:append).should == Array.instance_method(:push)
end
end
diff --git a/spec/ruby/core/array/array_spec.rb b/spec/ruby/core/array/array_spec.rb
index 186bd40f10..855f17348f 100644
--- a/spec/ruby/core/array/array_spec.rb
+++ b/spec/ruby/core/array/array_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Array" do
it "includes Enumerable" do
diff --git a/spec/ruby/core/array/assoc_spec.rb b/spec/ruby/core/array/assoc_spec.rb
index 37b0357806..a5026cf5d4 100644
--- a/spec/ruby/core/array/assoc_spec.rb
+++ b/spec/ruby/core/array/assoc_spec.rb
@@ -1,23 +1,23 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Array#assoc" do
it "returns the first array whose 1st item is == obj or nil" do
s1 = ["colors", "red", "blue", "green"]
s2 = [:letters, "a", "b", "c"]
s3 = [4]
- s4 = ["colors", "cyan", "yellow", "magenda"]
+ s4 = ["colors", "cyan", "yellow", "magenta"]
s5 = [:letters, "a", "i", "u"]
s_nil = [nil, nil]
a = [s1, s2, s3, s4, s5, s_nil]
- a.assoc(s1.first).should equal(s1)
- a.assoc(s2.first).should equal(s2)
- a.assoc(s3.first).should equal(s3)
- a.assoc(s4.first).should equal(s1)
- a.assoc(s5.first).should equal(s2)
- a.assoc(s_nil.first).should equal(s_nil)
- a.assoc(4).should equal(s3)
- a.assoc("key not in array").should be_nil
+ a.assoc(s1.first).should.equal?(s1)
+ a.assoc(s2.first).should.equal?(s2)
+ a.assoc(s3.first).should.equal?(s3)
+ a.assoc(s4.first).should.equal?(s1)
+ a.assoc(s5.first).should.equal?(s2)
+ a.assoc(s_nil.first).should.equal?(s_nil)
+ a.assoc(4).should.equal?(s3)
+ a.assoc("key not in array").should == nil
end
it "calls == on first element of each array" do
@@ -25,16 +25,28 @@ describe "Array#assoc" do
key2 = mock('key2')
items = [['not it', 1], [ArraySpecs::AssocKey.new, 2], ['na', 3]]
- items.assoc(key1).should equal(items[1])
- items.assoc(key2).should be_nil
+ items.assoc(key1).should.equal?(items[1])
+ items.assoc(key2).should == nil
end
it "ignores any non-Array elements" do
- [1, 2, 3].assoc(2).should be_nil
+ [1, 2, 3].assoc(2).should == nil
s1 = [4]
s2 = [5, 4, 3]
a = ["foo", [], s1, s2, nil, []]
- a.assoc(s1.first).should equal(s1)
- a.assoc(s2.first).should equal(s2)
+ a.assoc(s1.first).should.equal?(s1)
+ a.assoc(s2.first).should.equal?(s2)
+ end
+
+ it "calls to_ary on non-array elements" do
+ s1 = [1, 2]
+ s2 = ArraySpecs::ArrayConvertible.new(2, 3)
+ a = [s1, s2]
+
+ s1.should_not_receive(:to_ary)
+ a.assoc(s1.first).should.equal?(s1)
+
+ a.assoc(2).should == [2, 3]
+ s2.called.should.equal?(:to_ary)
end
end
diff --git a/spec/ruby/core/array/at_spec.rb b/spec/ruby/core/array/at_spec.rb
index f2af0e13a1..3c7c99fdff 100644
--- a/spec/ruby/core/array/at_spec.rb
+++ b/spec/ruby/core/array/at_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Array#at" do
it "returns the (n+1)'th element for the passed index n" do
@@ -47,10 +47,10 @@ describe "Array#at" do
end
it "raises a TypeError when the passed argument can't be coerced to Integer" do
- lambda { [].at("cat") }.should raise_error(TypeError)
+ -> { [].at("cat") }.should.raise(TypeError)
end
it "raises an ArgumentError when 2 or more arguments are passed" do
- lambda { [:a, :b].at(0,1) }.should raise_error(ArgumentError)
+ -> { [:a, :b].at(0,1) }.should.raise(ArgumentError)
end
end
diff --git a/spec/ruby/core/array/bsearch_index_spec.rb b/spec/ruby/core/array/bsearch_index_spec.rb
index 1ed11876b4..e1d5eb66bb 100644
--- a/spec/ruby/core/array/bsearch_index_spec.rb
+++ b/spec/ruby/core/array/bsearch_index_spec.rb
@@ -1,86 +1,80 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../enumerable/shared/enumeratorized', __FILE__)
-
-ruby_version_is "2.3" do
- describe "Array#bsearch_index" do
- context "when not passed a block" do
- before :each do
- @enum = [1, 2, 42, 100, 666].bsearch_index
- end
+require_relative '../../spec_helper'
+require_relative '../enumerable/shared/enumeratorized'
- it "returns an Enumerator" do
- @enum.should be_an_instance_of(Enumerator)
- end
+describe "Array#bsearch_index" do
+ context "when not passed a block" do
+ before :each do
+ @enum = [1, 2, 42, 100, 666].bsearch_index
+ end
- it "returns an Enumerator with unknown size" do
- @enum.size.should be_nil
- end
+ it "returns an Enumerator" do
+ @enum.should.instance_of?(Enumerator)
+ end
- it "returns index of element when block condition is satisfied" do
- @enum.each { |x| x >= 33 }.should == 2
- end
+ it "returns an Enumerator with unknown size" do
+ @enum.size.should == nil
end
- it "raises a TypeError when block returns a String" do
- lambda { [1, 2, 3].bsearch_index { "not ok" } }.should raise_error(TypeError)
+ it "returns index of element when block condition is satisfied" do
+ @enum.each { |x| x >= 33 }.should == 2
end
+ end
- it "returns nil when block is empty" do
- [1, 2, 3].bsearch_index {}.should be_nil
+ it "raises a TypeError when block returns a String" do
+ -> { [1, 2, 3].bsearch_index { "not ok" } }.should.raise(TypeError)
+ end
+
+ it "returns nil when block is empty" do
+ [1, 2, 3].bsearch_index {}.should == nil
+ end
+
+ context "minimum mode" do
+ before :each do
+ @array = [0, 4, 7, 10, 12]
end
- context "minimum mode" do
- before :each do
- @array = [0, 4, 7, 10, 12]
- end
+ it "returns index of first element which satisfies the block" do
+ @array.bsearch_index { |x| x >= 4 }.should == 1
+ @array.bsearch_index { |x| x >= 6 }.should == 2
+ @array.bsearch_index { |x| x >= -1 }.should == 0
+ end
- it "returns index of first element which satisfies the block" do
- @array.bsearch_index { |x| x >= 4 }.should == 1
- @array.bsearch_index { |x| x >= 6 }.should == 2
- @array.bsearch_index { |x| x >= -1 }.should == 0
- end
+ it "returns nil when block condition is never satisfied" do
+ @array.bsearch_index { false }.should == nil
+ @array.bsearch_index { |x| x >= 100 }.should == nil
+ end
+ end
- it "returns nil when block condition is never satisfied" do
- @array.bsearch_index { false }.should be_nil
- @array.bsearch_index { |x| x >= 100 }.should be_nil
- end
+ context "find any mode" do
+ before :each do
+ @array = [0, 4, 7, 10, 12]
end
- context "find any mode" do
- before :each do
- @array = [0, 4, 7, 10, 12]
- end
+ it "returns the index of any matched elements where element is between 4 <= x < 8" do
+ [1, 2].should.include?(@array.bsearch_index { |x| 1 - x / 4 })
+ end
- it "returns the index of any matched elements where element is between 4 <= x < 8" do
- [1, 2].should include(@array.bsearch_index { |x| 1 - x / 4 })
- end
+ it "returns the index of any matched elements where element is between 8 <= x < 10" do
+ @array.bsearch_index { |x| 4 - x / 2 }.should == nil
+ end
- it "returns the index of any matched elements where element is between 8 <= x < 10" do
- @array.bsearch_index { |x| 4 - x / 2 }.should be_nil
- end
+ it "returns nil when block never returns 0" do
+ @array.bsearch_index { |x| 1 }.should == nil
+ @array.bsearch_index { |x| -1 }.should == nil
+ end
- it "returns nil when block never returns 0" do
- @array.bsearch_index { |x| 1 }.should be_nil
- @array.bsearch_index { |x| -1 }.should be_nil
+ context "magnitude does not effect the result" do
+ it "returns the index of any matched elements where element is between 4n <= xn < 8n" do
+ [1, 2].should.include?(@array.bsearch_index { |x| (1 - x / 4) * (2**100) })
end
- it "returns the middle element when block always returns zero" do
- @array.bsearch_index { |x| 0 }.should == 2
+ it "returns nil when block never returns 0" do
+ @array.bsearch_index { |x| 1 * (2**100) }.should == nil
+ @array.bsearch_index { |x| (-1) * (2**100) }.should == nil
end
- context "magnitude does not effect the result" do
- it "returns the index of any matched elements where element is between 4n <= xn < 8n" do
- [1, 2].should include(@array.bsearch_index { |x| (1 - x / 4) * (2**100) })
- end
-
- it "returns nil when block never returns 0" do
- @array.bsearch_index { |x| 1 * (2**100) }.should be_nil
- @array.bsearch_index { |x| (-1) * (2**100) }.should be_nil
- end
-
- it "handles values from Bignum#coerce" do
- [1, 2].should include(@array.bsearch_index { |x| (2**100).coerce((1 - x / 4) * (2**100)).first })
- end
+ it "handles values from Integer#coerce" do
+ [1, 2].should.include?(@array.bsearch_index { |x| (2**100).coerce((1 - x / 4) * (2**100)).first })
end
end
end
diff --git a/spec/ruby/core/array/bsearch_spec.rb b/spec/ruby/core/array/bsearch_spec.rb
index 71e945f390..12aec60654 100644
--- a/spec/ruby/core/array/bsearch_spec.rb
+++ b/spec/ruby/core/array/bsearch_spec.rb
@@ -1,28 +1,28 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../enumerable/shared/enumeratorized', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../enumerable/shared/enumeratorized'
describe "Array#bsearch" do
it "returns an Enumerator when not passed a block" do
- [1].bsearch.should be_an_instance_of(Enumerator)
+ [1].bsearch.should.instance_of?(Enumerator)
end
it_behaves_like :enumeratorized_with_unknown_size, :bsearch, [1,2,3]
it "raises a TypeError if the block returns an Object" do
- lambda { [1].bsearch { Object.new } }.should raise_error(TypeError)
+ -> { [1].bsearch { Object.new } }.should.raise(TypeError)
end
it "raises a TypeError if the block returns a String" do
- lambda { [1].bsearch { "1" } }.should raise_error(TypeError)
+ -> { [1].bsearch { "1" } }.should.raise(TypeError)
end
context "with a block returning true or false" do
it "returns nil if the block returns false for every element" do
- [0, 1, 2, 3].bsearch { |x| x > 3 }.should be_nil
+ [0, 1, 2, 3].bsearch { |x| x > 3 }.should == nil
end
it "returns nil if the block returns nil for every element" do
- [0, 1, 2, 3].bsearch { |x| nil }.should be_nil
+ [0, 1, 2, 3].bsearch { |x| nil }.should == nil
end
it "returns element at zero if the block returns true for every element" do
@@ -38,21 +38,21 @@ describe "Array#bsearch" do
context "with a block returning negative, zero, positive numbers" do
it "returns nil if the block returns less than zero for every element" do
- [0, 1, 2, 3].bsearch { |x| x <=> 5 }.should be_nil
+ [0, 1, 2, 3].bsearch { |x| x <=> 5 }.should == nil
end
it "returns nil if the block returns greater than zero for every element" do
- [0, 1, 2, 3].bsearch { |x| x <=> -1 }.should be_nil
+ [0, 1, 2, 3].bsearch { |x| x <=> -1 }.should == nil
end
it "returns nil if the block never returns zero" do
- [0, 1, 3, 4].bsearch { |x| x <=> 2 }.should be_nil
+ [0, 1, 3, 4].bsearch { |x| x <=> 2 }.should == nil
end
it "accepts (+/-)Float::INFINITY from the block" do
- [0, 1, 3, 4].bsearch { |x| Float::INFINITY }.should be_nil
- [0, 1, 3, 4].bsearch { |x| -Float::INFINITY }.should be_nil
+ [0, 1, 3, 4].bsearch { |x| Float::INFINITY }.should == nil
+ [0, 1, 3, 4].bsearch { |x| -Float::INFINITY }.should == nil
end
it "returns an element at an index for which block returns 0.0" do
@@ -62,17 +62,17 @@ describe "Array#bsearch" do
it "returns an element at an index for which block returns 0" do
result = [0, 1, 2, 3, 4].bsearch { |x| x < 1 ? 1 : x > 3 ? -1 : 0 }
- [1, 2].should include(result)
+ [1, 2].should.include?(result)
end
end
context "with a block that calls break" do
it "returns nil if break is called without a value" do
- ['a', 'b', 'c'].bsearch { |v| break }.should be_nil
+ ['a', 'b', 'c'].bsearch { |v| break }.should == nil
end
it "returns nil if break is called with a nil value" do
- ['a', 'b', 'c'].bsearch { |v| break nil }.should be_nil
+ ['a', 'b', 'c'].bsearch { |v| break nil }.should == nil
end
it "returns object if break is called with an object" do
diff --git a/spec/ruby/core/array/clear_spec.rb b/spec/ruby/core/array/clear_spec.rb
index 851c90d654..15778f864f 100644
--- a/spec/ruby/core/array/clear_spec.rb
+++ b/spec/ruby/core/array/clear_spec.rb
@@ -1,49 +1,32 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Array#clear" do
it "removes all elements" do
a = [1, 2, 3, 4]
- a.clear.should equal(a)
+ a.clear.should.equal?(a)
a.should == []
end
it "returns self" do
a = [1]
- oid = a.object_id
- a.clear.object_id.should == oid
+ a.should.equal? a.clear
end
it "leaves the Array empty" do
a = [1]
a.clear
- a.empty?.should == true
+ a.should.empty?
a.size.should == 0
end
- it "keeps tainted status" do
- a = [1]
- a.taint
- a.tainted?.should be_true
- a.clear
- a.tainted?.should be_true
- end
-
it "does not accept any arguments" do
- lambda { [1].clear(true) }.should raise_error(ArgumentError)
- end
-
- it "keeps untrusted status" do
- a = [1]
- a.untrust
- a.untrusted?.should be_true
- a.clear
- a.untrusted?.should be_true
+ -> { [1].clear(true) }.should.raise(ArgumentError)
end
- it "raises a RuntimeError on a frozen array" do
+ it "raises a FrozenError on a frozen array" do
a = [1]
a.freeze
- lambda { a.clear }.should raise_error(RuntimeError)
+ -> { a.clear }.should.raise(FrozenError)
end
end
diff --git a/spec/ruby/core/array/clone_spec.rb b/spec/ruby/core/array/clone_spec.rb
index c88e10337f..7ce9d40a81 100644
--- a/spec/ruby/core/array/clone_spec.rb
+++ b/spec/ruby/core/array/clone_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/clone', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/clone'
describe "Array#clone" do
it_behaves_like :array_clone, :clone
@@ -12,8 +12,8 @@ describe "Array#clone" do
aa = a.clone
bb = b.clone
- aa.frozen?.should == true
- bb.frozen?.should == false
+ aa.should.frozen?
+ bb.should_not.frozen?
end
it "copies singleton methods" do
@@ -23,9 +23,9 @@ describe "Array#clone" do
aa = a.clone
bb = b.clone
- a.respond_to?(:a_singleton_method).should be_true
- b.respond_to?(:a_singleton_method).should be_false
- aa.respond_to?(:a_singleton_method).should be_true
- bb.respond_to?(:a_singleton_method).should be_false
+ a.respond_to?(:a_singleton_method).should == true
+ b.respond_to?(:a_singleton_method).should == false
+ aa.respond_to?(:a_singleton_method).should == true
+ bb.respond_to?(:a_singleton_method).should == false
end
end
diff --git a/spec/ruby/core/array/collect_spec.rb b/spec/ruby/core/array/collect_spec.rb
index 1c2c28c6bd..bdee5c240a 100644
--- a/spec/ruby/core/array/collect_spec.rb
+++ b/spec/ruby/core/array/collect_spec.rb
@@ -1,11 +1,13 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/collect', __FILE__)
+require_relative '../../spec_helper'
describe "Array#collect" do
- it_behaves_like(:array_collect, :collect)
+ it "is an alias of Array#map" do
+ Array.instance_method(:collect).should == Array.instance_method(:map)
+ end
end
describe "Array#collect!" do
- it_behaves_like(:array_collect_b, :collect!)
+ it "is an alias of Array#map!" do
+ Array.instance_method(:collect!).should == Array.instance_method(:map!)
+ end
end
diff --git a/spec/ruby/core/array/combination_spec.rb b/spec/ruby/core/array/combination_spec.rb
index 7869783d1e..ac570687ca 100644
--- a/spec/ruby/core/array/combination_spec.rb
+++ b/spec/ruby/core/array/combination_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Array#combination" do
before :each do
@@ -6,11 +6,11 @@ describe "Array#combination" do
end
it "returns an enumerator when no block is provided" do
- @array.combination(2).should be_an_instance_of(Enumerator)
+ @array.combination(2).should.instance_of?(Enumerator)
end
it "returns self when a block is given" do
- @array.combination(2){}.should equal(@array)
+ @array.combination(2){}.should.equal?(@array)
end
it "yields nothing for out of bounds length and return self" do
@@ -30,7 +30,7 @@ describe "Array#combination" do
it "yields a copy of self if the argument is the size of the receiver" do
r = @array.combination(4).to_a
r.should == [@array]
- r[0].should_not equal(@array)
+ r[0].should_not.equal?(@array)
end
it "yields [] when length is 0" do
@@ -58,7 +58,7 @@ describe "Array#combination" do
@array.combination(-1).size.should == 0
[].combination(-2).size.should == 0
end
- it "returns the binomial coeficient between the array size the number of combinations" do
+ it "returns the binomial coefficient between the array size the number of combinations" do
@array.combination(5).size.should == 0
@array.combination(4).size.should == 1
@array.combination(3).size.should == 4
diff --git a/spec/ruby/core/array/compact_spec.rb b/spec/ruby/core/array/compact_spec.rb
index b80f0214ec..dbcd16da35 100644
--- a/spec/ruby/core/array/compact_spec.rb
+++ b/spec/ruby/core/array/compact_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Array#compact" do
it "returns a copy of array with all nil elements removed" do
@@ -15,63 +15,37 @@ describe "Array#compact" do
it "does not return self" do
a = [1, 2, 3]
- a.compact.should_not equal(a)
+ a.compact.should_not.equal?(a)
end
it "does not return subclass instance for Array subclasses" do
- ArraySpecs::MyArray[1, 2, 3, nil].compact.should be_an_instance_of(Array)
- end
-
- it "does not keep tainted status even if all elements are removed" do
- a = [nil, nil]
- a.taint
- a.compact.tainted?.should be_false
- end
-
- it "does not keep untrusted status even if all elements are removed" do
- a = [nil, nil]
- a.untrust
- a.compact.untrusted?.should be_false
+ ArraySpecs::MyArray[1, 2, 3, nil].compact.should.instance_of?(Array)
end
end
describe "Array#compact!" do
it "removes all nil elements" do
a = ['a', nil, 'b', false, 'c']
- a.compact!.should equal(a)
+ a.compact!.should.equal?(a)
a.should == ["a", "b", false, "c"]
a = [nil, 'a', 'b', false, 'c']
- a.compact!.should equal(a)
+ a.compact!.should.equal?(a)
a.should == ["a", "b", false, "c"]
a = ['a', 'b', false, 'c', nil]
- a.compact!.should equal(a)
+ a.compact!.should.equal?(a)
a.should == ["a", "b", false, "c"]
end
it "returns self if some nil elements are removed" do
a = ['a', nil, 'b', false, 'c']
- a.compact!.object_id.should == a.object_id
+ a.compact!.should.equal? a
end
it "returns nil if there are no nil elements to remove" do
[1, 2, false, 3].compact!.should == nil
end
- it "keeps tainted status even if all elements are removed" do
- a = [nil, nil]
- a.taint
- a.compact!
- a.tainted?.should be_true
- end
-
- it "keeps untrusted status even if all elements are removed" do
- a = [nil, nil]
- a.untrust
- a.compact!
- a.untrusted?.should be_true
- end
-
- it "raises a RuntimeError on a frozen array" do
- lambda { ArraySpecs.frozen_array.compact! }.should raise_error(RuntimeError)
+ it "raises a FrozenError on a frozen array" do
+ -> { ArraySpecs.frozen_array.compact! }.should.raise(FrozenError)
end
end
diff --git a/spec/ruby/core/array/comparison_spec.rb b/spec/ruby/core/array/comparison_spec.rb
index e5a5f4da10..14e8931e5a 100644
--- a/spec/ruby/core/array/comparison_spec.rb
+++ b/spec/ruby/core/array/comparison_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Array#<=>" do
it "calls <=> left to right and return first non-0 result" do
@@ -92,6 +92,6 @@ describe "Array#<=>" do
end
it "returns nil when the argument is not array-like" do
- ([] <=> false).should be_nil
+ ([] <=> false).should == nil
end
end
diff --git a/spec/ruby/core/array/concat_spec.rb b/spec/ruby/core/array/concat_spec.rb
index 86ec557bde..1e8d20c36c 100644
--- a/spec/ruby/core/array/concat_spec.rb
+++ b/spec/ruby/core/array/concat_spec.rb
@@ -1,15 +1,15 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Array#concat" do
it "returns the array itself" do
ary = [1,2,3]
- ary.concat([4,5,6]).equal?(ary).should be_true
+ ary.concat([4,5,6]).equal?(ary).should == true
end
it "appends the elements in the other array" do
ary = [1, 2, 3]
- ary.concat([9, 10, 11]).should equal(ary)
+ ary.concat([9, 10, 11]).should.equal?(ary)
ary.should == [1, 2, 3, 9, 10, 11]
ary.concat([])
ary.should == [1, 2, 3, 9, 10, 11]
@@ -32,69 +32,13 @@ describe "Array#concat" do
[].concat(obj).should == [5, 6, 7]
end
- it "raises a RuntimeError when Array is frozen and modification occurs" do
- lambda { ArraySpecs.frozen_array.concat [1] }.should raise_error(RuntimeError)
+ it "raises a FrozenError when Array is frozen and modification occurs" do
+ -> { ArraySpecs.frozen_array.concat [1] }.should.raise(FrozenError)
end
# see [ruby-core:23666]
- it "raises a RuntimeError when Array is frozen and no modification occurs" do
- lambda { ArraySpecs.frozen_array.concat([]) }.should raise_error(RuntimeError)
- end
-
- it "keeps tainted status" do
- ary = [1, 2]
- ary.taint
- ary.concat([3])
- ary.tainted?.should be_true
- ary.concat([])
- ary.tainted?.should be_true
- end
-
- it "is not infected by the other" do
- ary = [1,2]
- other = [3]; other.taint
- ary.tainted?.should be_false
- ary.concat(other)
- ary.tainted?.should be_false
- end
-
- it "keeps the tainted status of elements" do
- ary = [ Object.new, Object.new, Object.new ]
- ary.each {|x| x.taint }
-
- ary.concat([ Object.new ])
- ary[0].tainted?.should be_true
- ary[1].tainted?.should be_true
- ary[2].tainted?.should be_true
- ary[3].tainted?.should be_false
- end
-
- it "keeps untrusted status" do
- ary = [1, 2]
- ary.untrust
- ary.concat([3])
- ary.untrusted?.should be_true
- ary.concat([])
- ary.untrusted?.should be_true
- end
-
- it "is not infected untrustedness by the other" do
- ary = [1,2]
- other = [3]; other.untrust
- ary.untrusted?.should be_false
- ary.concat(other)
- ary.untrusted?.should be_false
- end
-
- it "keeps the untrusted status of elements" do
- ary = [ Object.new, Object.new, Object.new ]
- ary.each {|x| x.untrust }
-
- ary.concat([ Object.new ])
- ary[0].untrusted?.should be_true
- ary[1].untrusted?.should be_true
- ary[2].untrusted?.should be_true
- ary[3].untrusted?.should be_false
+ it "raises a FrozenError when Array is frozen and no modification occurs" do
+ -> { ArraySpecs.frozen_array.concat([]) }.should.raise(FrozenError)
end
it "appends elements to an Array with enough capacity that has been shifted" do
@@ -110,23 +54,21 @@ describe "Array#concat" do
ary.concat([5, 6]).should == [4, 5, 6]
end
- ruby_version_is "2.4" do
- it "takes multiple arguments" do
- ary = [1, 2]
- ary.concat [3, 4]
- ary.should == [1, 2, 3, 4]
- end
+ it "takes multiple arguments" do
+ ary = [1, 2]
+ ary.concat [3, 4]
+ ary.should == [1, 2, 3, 4]
+ end
- it "concatenates the initial value when given arguments contain 2 self" do
- ary = [1, 2]
- ary.concat ary, ary
- ary.should == [1, 2, 1, 2, 1, 2]
- end
+ it "concatenates the initial value when given arguments contain 2 self" do
+ ary = [1, 2]
+ ary.concat ary, ary
+ ary.should == [1, 2, 1, 2, 1, 2]
+ end
- it "returns self when given no arguments" do
- ary = [1, 2]
- ary.concat.should equal(ary)
- ary.should == [1, 2]
- end
+ it "returns self when given no arguments" do
+ ary = [1, 2]
+ ary.concat.should.equal?(ary)
+ ary.should == [1, 2]
end
end
diff --git a/spec/ruby/core/array/constructor_spec.rb b/spec/ruby/core/array/constructor_spec.rb
index 8ec2e5de1e..c4398c535d 100644
--- a/spec/ruby/core/array/constructor_spec.rb
+++ b/spec/ruby/core/array/constructor_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Array.[]" do
it "returns a new array populated with the given elements" do
@@ -7,7 +7,7 @@ describe "Array.[]" do
Array.[](5, true, nil, 'a', "Ruby", obj).should == [5, true, nil, "a", "Ruby", obj]
a = ArraySpecs::MyArray.[](5, true, nil, 'a', "Ruby", obj)
- a.should be_an_instance_of(ArraySpecs::MyArray)
+ a.should.instance_of?(ArraySpecs::MyArray)
a.inspect.should == [5, true, nil, "a", "Ruby", obj].inspect
end
end
@@ -18,7 +18,7 @@ describe "Array[]" do
Array[5, true, nil, 'a', "Ruby", obj].should == Array.[](5, true, nil, "a", "Ruby", obj)
a = ArraySpecs::MyArray[5, true, nil, 'a', "Ruby", obj]
- a.should be_an_instance_of(ArraySpecs::MyArray)
+ a.should.instance_of?(ArraySpecs::MyArray)
a.inspect.should == [5, true, nil, "a", "Ruby", obj].inspect
end
end
diff --git a/spec/ruby/core/array/count_spec.rb b/spec/ruby/core/array/count_spec.rb
index 52314d8579..e778233c16 100644
--- a/spec/ruby/core/array/count_spec.rb
+++ b/spec/ruby/core/array/count_spec.rb
@@ -1,4 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/iterable_and_tolerating_size_increasing'
describe "Array#count" do
it "returns the number of elements" do
@@ -12,4 +13,14 @@ describe "Array#count" do
it "returns the number of element for which the block evaluates to true" do
[:a, :b, :c].count { |s| s != :b }.should == 2
end
+
+ it "ignores the block if there is an argument" do
+ -> {
+ [:a, :b, :b, :c].count(:b) { |e| e.size > 10 }.should == 2
+ }.should complain(/given block not used/)
+ end
+
+ context "when a block argument given" do
+ it_behaves_like :array_iterable_and_tolerating_size_increasing, :count
+ end
end
diff --git a/spec/ruby/core/array/cycle_spec.rb b/spec/ruby/core/array/cycle_spec.rb
index 2e60798c8c..29284257e9 100644
--- a/spec/ruby/core/array/cycle_spec.rb
+++ b/spec/ruby/core/array/cycle_spec.rb
@@ -1,26 +1,26 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../enumerable/shared/enumeratorized', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../enumerable/shared/enumeratorized'
describe "Array#cycle" do
before :each do
ScratchPad.record []
@array = [1, 2, 3]
- @prc = lambda { |x| ScratchPad << x }
+ @prc = -> x { ScratchPad << x }
end
it "does not yield and returns nil when the array is empty and passed value is an integer" do
- [].cycle(6, &@prc).should be_nil
+ [].cycle(6, &@prc).should == nil
ScratchPad.recorded.should == []
end
it "does not yield and returns nil when the array is empty and passed value is nil" do
- [].cycle(nil, &@prc).should be_nil
+ [].cycle(nil, &@prc).should == nil
ScratchPad.recorded.should == []
end
it "does not yield and returns nil when passed 0" do
- @array.cycle(0, &@prc).should be_nil
+ @array.cycle(0, &@prc).should == nil
ScratchPad.recorded.should == []
end
@@ -46,15 +46,15 @@ describe "Array#cycle" do
end
it "does not rescue StopIteration when not passed a count" do
- lambda do
+ -> do
@array.cycle { raise StopIteration }
- end.should raise_error(StopIteration)
+ end.should.raise(StopIteration)
end
it "does not rescue StopIteration when passed a count" do
- lambda do
+ -> do
@array.cycle(3) { raise StopIteration }
- end.should raise_error(StopIteration)
+ end.should.raise(StopIteration)
end
it "iterates the array Integer(count) times when passed a Float count" do
@@ -74,23 +74,23 @@ describe "Array#cycle" do
count = mock("cycle count 2")
count.should_receive(:to_int).and_return("2")
- lambda { @array.cycle(count, &@prc) }.should raise_error(TypeError)
+ -> { @array.cycle(count, &@prc) }.should.raise(TypeError)
end
it "raises a TypeError if passed a String" do
- lambda { @array.cycle("4") { } }.should raise_error(TypeError)
+ -> { @array.cycle("4") { } }.should.raise(TypeError)
end
it "raises a TypeError if passed an Object" do
- lambda { @array.cycle(mock("cycle count")) { } }.should raise_error(TypeError)
+ -> { @array.cycle(mock("cycle count")) { } }.should.raise(TypeError)
end
it "raises a TypeError if passed true" do
- lambda { @array.cycle(true) { } }.should raise_error(TypeError)
+ -> { @array.cycle(true) { } }.should.raise(TypeError)
end
it "raises a TypeError if passed false" do
- lambda { @array.cycle(false) { } }.should raise_error(TypeError)
+ -> { @array.cycle(false) { } }.should.raise(TypeError)
end
before :all do
diff --git a/spec/ruby/core/array/deconstruct_spec.rb b/spec/ruby/core/array/deconstruct_spec.rb
new file mode 100644
index 0000000000..11bb8e72c4
--- /dev/null
+++ b/spec/ruby/core/array/deconstruct_spec.rb
@@ -0,0 +1,9 @@
+require_relative '../../spec_helper'
+
+describe "Array#deconstruct" do
+ it "returns self" do
+ array = [1]
+
+ array.deconstruct.should.equal? array
+ end
+end
diff --git a/spec/ruby/core/array/delete_at_spec.rb b/spec/ruby/core/array/delete_at_spec.rb
index 1d73ceb33a..1e298b6730 100644
--- a/spec/ruby/core/array/delete_at_spec.rb
+++ b/spec/ruby/core/array/delete_at_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Array#delete_at" do
it "removes the element at the specified index" do
@@ -35,27 +35,7 @@ describe "Array#delete_at" do
a.delete_at(-2).should == 1
end
- it "raises a RuntimeError on a frozen array" do
- lambda { [1,2,3].freeze.delete_at(0) }.should raise_error(RuntimeError)
- end
-
- it "keeps tainted status" do
- ary = [1, 2]
- ary.taint
- ary.tainted?.should be_true
- ary.delete_at(0)
- ary.tainted?.should be_true
- ary.delete_at(0) # now empty
- ary.tainted?.should be_true
- end
-
- it "keeps untrusted status" do
- ary = [1, 2]
- ary.untrust
- ary.untrusted?.should be_true
- ary.delete_at(0)
- ary.untrusted?.should be_true
- ary.delete_at(0) # now empty
- ary.untrusted?.should be_true
+ it "raises a FrozenError on a frozen array" do
+ -> { [1,2,3].freeze.delete_at(0) }.should.raise(FrozenError)
end
end
diff --git a/spec/ruby/core/array/delete_if_spec.rb b/spec/ruby/core/array/delete_if_spec.rb
index 4276a1fb65..701a612395 100644
--- a/spec/ruby/core/array/delete_if_spec.rb
+++ b/spec/ruby/core/array/delete_if_spec.rb
@@ -1,8 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/enumeratorize', __FILE__)
-require File.expand_path('../shared/delete_if', __FILE__)
-require File.expand_path('../../enumerable/shared/enumeratorized', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/enumeratorize'
+require_relative 'shared/delete_if'
+require_relative 'shared/iterable_and_tolerating_size_increasing'
+require_relative '../enumerable/shared/enumeratorized'
describe "Array#delete_if" do
before do
@@ -16,7 +17,7 @@ describe "Array#delete_if" do
end
it "returns self" do
- @a.delete_if{ true }.equal?(@a).should be_true
+ @a.delete_if{ true }.equal?(@a).should == true
end
it_behaves_like :enumeratorize, :delete_if
@@ -24,43 +25,58 @@ describe "Array#delete_if" do
it "returns self when called on an Array emptied with #shift" do
array = [1]
array.shift
- array.delete_if { |x| true }.should equal(array)
+ array.delete_if { |x| true }.should.equal?(array)
end
it "returns an Enumerator if no block given, and the enumerator can modify the original array" do
enum = @a.delete_if
- enum.should be_an_instance_of(Enumerator)
- @a.should_not be_empty
+ enum.should.instance_of?(Enumerator)
+ @a.should_not.empty?
enum.each { true }
- @a.should be_empty
+ @a.should.empty?
end
it "returns an Enumerator if no block given, and the array is frozen" do
- @a.freeze.delete_if.should be_an_instance_of(Enumerator)
+ @a.freeze.delete_if.should.instance_of?(Enumerator)
end
- it "raises a RuntimeError on a frozen array" do
- lambda { ArraySpecs.frozen_array.delete_if {} }.should raise_error(RuntimeError)
+ it "raises a FrozenError on a frozen array" do
+ -> { ArraySpecs.frozen_array.delete_if {} }.should.raise(FrozenError)
end
- it "raises a RuntimeError on an empty frozen array" do
- lambda { ArraySpecs.empty_frozen_array.delete_if {} }.should raise_error(RuntimeError)
+ it "raises a FrozenError on an empty frozen array" do
+ -> { ArraySpecs.empty_frozen_array.delete_if {} }.should.raise(FrozenError)
end
- it "keeps tainted status" do
- @a.taint
- @a.tainted?.should be_true
- @a.delete_if{ true }
- @a.tainted?.should be_true
+ it "does not truncate the array is the block raises an exception" do
+ a = [1, 2, 3]
+ begin
+ a.delete_if { raise StandardError, 'Oops' }
+ rescue
+ end
+
+ a.should == [1, 2, 3]
end
- it "keeps untrusted status" do
- @a.untrust
- @a.untrusted?.should be_true
- @a.delete_if{ true }
- @a.untrusted?.should be_true
+ it "only removes elements for which the block returns true, keeping the element which raised an error." do
+ a = [1, 2, 3, 4]
+ begin
+ a.delete_if do |e|
+ case e
+ when 2 then true
+ when 3 then raise StandardError, 'Oops'
+ else false
+ end
+ end
+ rescue StandardError
+ end
+
+ a.should == [1, 3, 4]
end
it_behaves_like :enumeratorized_with_origin_size, :delete_if, [1,2,3]
it_behaves_like :delete_if, :delete_if
+
+ @value_to_return = -> _ { false }
+ it_behaves_like :array_iterable_and_tolerating_size_increasing, :delete_if
end
diff --git a/spec/ruby/core/array/delete_spec.rb b/spec/ruby/core/array/delete_spec.rb
index 7b6bf3930c..0d80b2839d 100644
--- a/spec/ruby/core/array/delete_spec.rb
+++ b/spec/ruby/core/array/delete_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Array#delete" do
it "removes elements that are #== to object" do
@@ -40,27 +40,7 @@ describe "Array#delete" do
[1, 2, 3].freeze.delete(0).should == nil
end
- it "raises a RuntimeError on a frozen array" do
- lambda { [1, 2, 3].freeze.delete(1) }.should raise_error(RuntimeError)
- end
-
- it "keeps tainted status" do
- a = [1, 2]
- a.taint
- a.tainted?.should be_true
- a.delete(2)
- a.tainted?.should be_true
- a.delete(1) # now empty
- a.tainted?.should be_true
- end
-
- it "keeps untrusted status" do
- a = [1, 2]
- a.untrust
- a.untrusted?.should be_true
- a.delete(2)
- a.untrusted?.should be_true
- a.delete(1) # now empty
- a.untrusted?.should be_true
+ it "raises a FrozenError on a frozen array" do
+ -> { [1, 2, 3].freeze.delete(1) }.should.raise(FrozenError)
end
end
diff --git a/spec/ruby/core/array/difference_spec.rb b/spec/ruby/core/array/difference_spec.rb
new file mode 100644
index 0000000000..63e32feca0
--- /dev/null
+++ b/spec/ruby/core/array/difference_spec.rb
@@ -0,0 +1,22 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/difference'
+
+describe "Array#difference" do
+ it_behaves_like :array_binary_difference, :difference
+
+ it "returns a copy when called without any parameter" do
+ x = [1, 2, 3, 2]
+ x.difference.should == x
+ x.difference.should_not.equal? x
+ end
+
+ it "does not return subclass instances for Array subclasses" do
+ ArraySpecs::MyArray[1, 2, 3].difference.should.instance_of?(Array)
+ end
+
+ it "accepts multiple arguments" do
+ x = [1, 2, 3, 1]
+ x.difference([], [0, 1], [3, 4], [3]).should == [2]
+ end
+end
diff --git a/spec/ruby/core/array/dig_spec.rb b/spec/ruby/core/array/dig_spec.rb
index 9c20b2d160..4166ff9f1f 100644
--- a/spec/ruby/core/array/dig_spec.rb
+++ b/spec/ruby/core/array/dig_spec.rb
@@ -1,54 +1,52 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-ruby_version_is '2.3' do
- describe "Array#dig" do
-
- it "returns #at with one arg" do
- ['a'].dig(0).should == 'a'
- ['a'].dig(1).should be_nil
- end
-
- it "recurses array elements" do
- a = [ [ 1, [2, '3'] ] ]
- a.dig(0, 0).should == 1
- a.dig(0, 1, 1).should == '3'
- a.dig(0, -1, 0).should == 2
- end
-
- it "returns the nested value specified if the sequence includes a key" do
- a = [42, { foo: :bar }]
- a.dig(1, :foo).should == :bar
- end
-
- it "raises a TypeError for a non-numeric index" do
- lambda {
- ['a'].dig(:first)
- }.should raise_error(TypeError)
- end
-
- it "raises a TypeError if any intermediate step does not respond to #dig" do
- a = [1, 2]
- lambda {
- a.dig(0, 1)
- }.should raise_error(TypeError)
- end
-
- it "raises an ArgumentError if no arguments provided" do
- lambda {
- [10].dig()
- }.should raise_error(ArgumentError)
- end
-
- it "returns nil if any intermediate step is nil" do
- a = [[1, [2, 3]]]
- a.dig(1, 2, 3).should == nil
- end
-
- it "calls #dig on the result of #at with the remaining arguments" do
- h = [[nil, [nil, nil, 42]]]
- h[0].should_receive(:dig).with(1, 2).and_return(42)
- h.dig(0, 1, 2).should == 42
- end
+require_relative '../../spec_helper'
+describe "Array#dig" do
+
+ it "returns #at with one arg" do
+ ['a'].dig(0).should == 'a'
+ ['a'].dig(1).should == nil
+ end
+
+ it "recurses array elements" do
+ a = [ [ 1, [2, '3'] ] ]
+ a.dig(0, 0).should == 1
+ a.dig(0, 1, 1).should == '3'
+ a.dig(0, -1, 0).should == 2
+ end
+
+ it "returns the nested value specified if the sequence includes a key" do
+ a = [42, { foo: :bar }]
+ a.dig(1, :foo).should == :bar
+ end
+
+ it "raises a TypeError for a non-numeric index" do
+ -> {
+ ['a'].dig(:first)
+ }.should.raise(TypeError)
+ end
+
+ it "raises a TypeError if any intermediate step does not respond to #dig" do
+ a = [1, 2]
+ -> {
+ a.dig(0, 1)
+ }.should.raise(TypeError)
+ end
+
+ it "raises an ArgumentError if no arguments provided" do
+ -> {
+ [10].dig()
+ }.should.raise(ArgumentError)
+ end
+
+ it "returns nil if any intermediate step is nil" do
+ a = [[1, [2, 3]]]
+ a.dig(1, 2, 3).should == nil
+ end
+
+ it "calls #dig on the result of #at with the remaining arguments" do
+ h = [[nil, [nil, nil, 42]]]
+ h[0].should_receive(:dig).with(1, 2).and_return(42)
+ h.dig(0, 1, 2).should == 42
end
+
end
diff --git a/spec/ruby/core/array/drop_spec.rb b/spec/ruby/core/array/drop_spec.rb
index 763b45e05a..c0e1c9edce 100644
--- a/spec/ruby/core/array/drop_spec.rb
+++ b/spec/ruby/core/array/drop_spec.rb
@@ -1,4 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Array#drop" do
it "removes the specified number of elements from the start of the array" do
@@ -6,7 +7,7 @@ describe "Array#drop" do
end
it "raises an ArgumentError if the number of elements specified is negative" do
- lambda { [1, 2].drop(-3) }.should raise_error(ArgumentError)
+ -> { [1, 2].drop(-3) }.should.raise(ArgumentError)
end
it "returns an empty Array if all elements are dropped" do
@@ -30,4 +31,26 @@ describe "Array#drop" do
ary.shift
ary.drop(1).should == [2]
end
+
+ it "tries to convert the passed argument to an Integer using #to_int" do
+ obj = mock("to_int")
+ obj.should_receive(:to_int).and_return(2)
+
+ [1, 2, 3].drop(obj).should == [3]
+ end
+
+ it "raises a TypeError when the passed argument can't be coerced to Integer" do
+ -> { [1, 2].drop("cat") }.should.raise(TypeError)
+ end
+
+ it "raises a TypeError when the passed argument isn't an integer and #to_int returns non-Integer" do
+ obj = mock("to_int")
+ obj.should_receive(:to_int).and_return("cat")
+
+ -> { [1, 2].drop(obj) }.should.raise(TypeError)
+ end
+
+ it 'returns a Array instance for Array subclasses' do
+ ArraySpecs::MyArray[1, 2, 3, 4, 5].drop(1).should.instance_of?(Array)
+ end
end
diff --git a/spec/ruby/core/array/drop_while_spec.rb b/spec/ruby/core/array/drop_while_spec.rb
index 40cc29d6b3..4fead3ff06 100644
--- a/spec/ruby/core/array/drop_while_spec.rb
+++ b/spec/ruby/core/array/drop_while_spec.rb
@@ -1,6 +1,11 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/iterable_and_tolerating_size_increasing'
describe "Array#drop_while" do
+ @value_to_return = -> _ { true }
+ it_behaves_like :array_iterable_and_tolerating_size_increasing, :drop_while
+
it "removes elements from the start of the array while the block evaluates to true" do
[1, 2, 3, 4].drop_while { |n| n < 4 }.should == [4]
end
@@ -12,4 +17,8 @@ describe "Array#drop_while" do
it "removes elements from the start of the array until the block returns false" do
[1, 2, 3, false, 5].drop_while { |n| n }.should == [false, 5]
end
+
+ it 'returns a Array instance for Array subclasses' do
+ ArraySpecs::MyArray[1, 2, 3, 4, 5].drop_while { |n| n < 4 }.should.instance_of?(Array)
+ end
end
diff --git a/spec/ruby/core/array/dup_spec.rb b/spec/ruby/core/array/dup_spec.rb
index 01ad12523d..f14aeca3b5 100644
--- a/spec/ruby/core/array/dup_spec.rb
+++ b/spec/ruby/core/array/dup_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/clone', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/clone'
describe "Array#dup" do
it_behaves_like :array_clone, :dup # FIX: no, clone and dup are not alike
@@ -12,8 +12,8 @@ describe "Array#dup" do
aa = a.dup
bb = b.dup
- aa.frozen?.should be_false
- bb.frozen?.should be_false
+ aa.frozen?.should == false
+ bb.frozen?.should == false
end
it "does not copy singleton methods" do
@@ -23,9 +23,9 @@ describe "Array#dup" do
aa = a.dup
bb = b.dup
- a.respond_to?(:a_singleton_method).should be_true
- b.respond_to?(:a_singleton_method).should be_false
- aa.respond_to?(:a_singleton_method).should be_false
- bb.respond_to?(:a_singleton_method).should be_false
+ a.respond_to?(:a_singleton_method).should == true
+ b.respond_to?(:a_singleton_method).should == false
+ aa.respond_to?(:a_singleton_method).should == false
+ bb.respond_to?(:a_singleton_method).should == false
end
end
diff --git a/spec/ruby/core/array/each_index_spec.rb b/spec/ruby/core/array/each_index_spec.rb
index 8872c00f8c..b238a89d8a 100644
--- a/spec/ruby/core/array/each_index_spec.rb
+++ b/spec/ruby/core/array/each_index_spec.rb
@@ -1,11 +1,11 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/enumeratorize', __FILE__)
-require File.expand_path('../../enumerable/shared/enumeratorized', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/enumeratorize'
+require_relative '../enumerable/shared/enumeratorized'
# Modifying a collection while the contents are being iterated
# gives undefined behavior. See
-# http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/23633
+# https://blade.ruby-lang.org/ruby-core/23633
describe "Array#each_index" do
before :each do
@@ -20,7 +20,7 @@ describe "Array#each_index" do
it "returns self" do
a = [:a, :b, :c]
- a.each_index { |i| }.should equal(a)
+ a.each_index { |i| }.should.equal?(a)
end
it "is not confused by removing elements from the front" do
@@ -40,3 +40,19 @@ describe "Array#each_index" do
it_behaves_like :enumeratorize, :each_index
it_behaves_like :enumeratorized_with_origin_size, :each_index, [1,2,3]
end
+
+describe "Array#each_index" do
+ it "tolerates increasing an array size during iteration" do
+ array = [:a, :b, :c]
+ ScratchPad.record []
+ i = 0
+
+ array.each_index do |index|
+ ScratchPad << index
+ array << i if i < 100
+ i += 1
+ end
+
+ ScratchPad.recorded.should == (0..102).to_a # element indices
+ end
+end
diff --git a/spec/ruby/core/array/each_spec.rb b/spec/ruby/core/array/each_spec.rb
index a8bac6442e..73a4c36b17 100644
--- a/spec/ruby/core/array/each_spec.rb
+++ b/spec/ruby/core/array/each_spec.rb
@@ -1,20 +1,50 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/enumeratorize', __FILE__)
-require File.expand_path('../../enumerable/shared/enumeratorized', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/enumeratorize'
+require_relative 'shared/iterable_and_tolerating_size_increasing'
+require_relative '../enumerable/shared/enumeratorized'
-# Modifying a collection while the contents are being iterated
-# gives undefined behavior. See
-# http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/23633
+# Mutating the array while it is being iterated is discouraged as it can result in confusing behavior.
+# Yet a Ruby implementation must not crash in such a case, and following the simple CRuby behavior makes sense.
+# CRuby simply reads the array storage and checks the size for every iteration;
+# like `i = 0; while i < size; yield self[i]; i += 1; end`
describe "Array#each" do
it "yields each element to the block" do
a = []
x = [1, 2, 3]
- x.each { |item| a << item }.should equal(x)
+ x.each { |item| a << item }.should.equal?(x)
a.should == [1, 2, 3]
end
+ it "yields each element to the block even if the array is changed during iteration" do
+ a = [1, 2, 3, 4, 5]
+ iterated = []
+ a.each { |x| iterated << x; a << x+5 if x.even? }
+ iterated.should == [1, 2, 3, 4, 5, 7, 9]
+ end
+
+ it "yields only elements that are still in the array" do
+ a = [0, 1, 2, 3, 4]
+ iterated = []
+ a.each { |x| iterated << x; a.pop if x.even? }
+ iterated.should == [0, 1, 2]
+ end
+
+ it "yields elements based on an internal index" do
+ a = [0, 1, 2, 3, 4]
+ iterated = []
+ a.each { |x| iterated << x; a.shift if x.even? }
+ iterated.should == [0, 2, 4]
+ end
+
+ it "yields the same element multiple times if inserting while iterating" do
+ a = [1, 2]
+ iterated = []
+ a.each { |x| iterated << x; a.unshift(0) if a.size == 2 }
+ iterated.should == [1, 1, 2]
+ end
+
it "yields each element to a block that takes multiple arguments" do
a = [[1, 2], :a, [3, 4]]
b = []
@@ -27,6 +57,26 @@ describe "Array#each" do
b.should == [2, nil, 4]
end
+ it "yields elements added to the end of the array by the block" do
+ a = [2]
+ iterated = []
+ a.each { |x| iterated << x; x.times { a << 0 } }
+
+ iterated.should == [2, 0, 0]
+ end
+
+ it "does not yield elements deleted from the end of the array" do
+ a = [2, 3, 1]
+ iterated = []
+ a.each { |x| iterated << x; a.delete_at(2) if x == 3 }
+
+ iterated.should == [2, 3]
+ end
+
it_behaves_like :enumeratorize, :each
it_behaves_like :enumeratorized_with_origin_size, :each, [1,2,3]
end
+
+describe "Array#each" do
+ it_behaves_like :array_iterable_and_tolerating_size_increasing, :each
+end
diff --git a/spec/ruby/core/array/element_reference_spec.rb b/spec/ruby/core/array/element_reference_spec.rb
index 55b6b73d1e..d5f4b54961 100644
--- a/spec/ruby/core/array/element_reference_spec.rb
+++ b/spec/ruby/core/array/element_reference_spec.rb
@@ -1,9 +1,862 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/slice', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Array#[]" do
- it_behaves_like(:array_slice, :[])
+ it "returns the element at index with [index]" do
+ [ "a", "b", "c", "d", "e" ][1].should == "b"
+
+ a = [1, 2, 3, 4]
+
+ a[0].should == 1
+ a[1].should == 2
+ a[2].should == 3
+ a[3].should == 4
+ a[4].should == nil
+ a[10].should == nil
+
+ a.should == [1, 2, 3, 4]
+ end
+
+ it "returns the element at index from the end of the array with [-index]" do
+ [ "a", "b", "c", "d", "e" ][-2].should == "d"
+
+ a = [1, 2, 3, 4]
+
+ a[-1].should == 4
+ a[-2].should == 3
+ a[-3].should == 2
+ a[-4].should == 1
+ a[-5].should == nil
+ a[-10].should == nil
+
+ a.should == [1, 2, 3, 4]
+ end
+
+ it "returns count elements starting from index with [index, count]" do
+ [ "a", "b", "c", "d", "e" ][2, 3].should == ["c", "d", "e"]
+
+ a = [1, 2, 3, 4]
+
+ a[0, 0].should == []
+ a[0, 1].should == [1]
+ a[0, 2].should == [1, 2]
+ a[0, 4].should == [1, 2, 3, 4]
+ a[0, 6].should == [1, 2, 3, 4]
+ a[0, -1].should == nil
+ a[0, -2].should == nil
+ a[0, -4].should == nil
+
+ a[2, 0].should == []
+ a[2, 1].should == [3]
+ a[2, 2].should == [3, 4]
+ a[2, 4].should == [3, 4]
+ a[2, -1].should == nil
+
+ a[4, 0].should == []
+ a[4, 2].should == []
+ a[4, -1].should == nil
+
+ a[5, 0].should == nil
+ a[5, 2].should == nil
+ a[5, -1].should == nil
+
+ a[6, 0].should == nil
+ a[6, 2].should == nil
+ a[6, -1].should == nil
+
+ a.should == [1, 2, 3, 4]
+ end
+
+ it "returns count elements starting at index from the end of array with [-index, count]" do
+ [ "a", "b", "c", "d", "e" ][-2, 2].should == ["d", "e"]
+
+ a = [1, 2, 3, 4]
+
+ a[-1, 0].should == []
+ a[-1, 1].should == [4]
+ a[-1, 2].should == [4]
+ a[-1, -1].should == nil
+
+ a[-2, 0].should == []
+ a[-2, 1].should == [3]
+ a[-2, 2].should == [3, 4]
+ a[-2, 4].should == [3, 4]
+ a[-2, -1].should == nil
+
+ a[-4, 0].should == []
+ a[-4, 1].should == [1]
+ a[-4, 2].should == [1, 2]
+ a[-4, 4].should == [1, 2, 3, 4]
+ a[-4, 6].should == [1, 2, 3, 4]
+ a[-4, -1].should == nil
+
+ a[-5, 0].should == nil
+ a[-5, 1].should == nil
+ a[-5, 10].should == nil
+ a[-5, -1].should == nil
+
+ a.should == [1, 2, 3, 4]
+ end
+
+ it "returns the first count elements with [0, count]" do
+ [ "a", "b", "c", "d", "e" ][0, 3].should == ["a", "b", "c"]
+ end
+
+ it "returns the subarray which is independent to self with [index,count]" do
+ a = [1, 2, 3]
+ sub = a[1, 2]
+ sub.replace([:a, :b])
+ a.should == [1, 2, 3]
+ end
+
+ it "tries to convert the passed argument to an Integer using #to_int" do
+ obj = mock('to_int')
+ obj.stub!(:to_int).and_return(2)
+
+ a = [1, 2, 3, 4]
+ a[obj].should == 3
+ a[obj, 1].should == [3]
+ a[obj, obj].should == [3, 4]
+ a[0, obj].should == [1, 2]
+ end
+
+ it "raises TypeError if to_int returns non-integer" do
+ from = mock('from')
+ to = mock('to')
+
+ # So we can construct a range out of them...
+ def from.<=>(o) 0 end
+ def to.<=>(o) 0 end
+
+ a = [1, 2, 3, 4, 5]
+
+ def from.to_int() 'cat' end
+ def to.to_int() -2 end
+
+ -> { a[from..to] }.should.raise(TypeError)
+
+ def from.to_int() 1 end
+ def to.to_int() 'cat' end
+
+ -> { a[from..to] }.should.raise(TypeError)
+ end
+
+ it "returns the elements specified by Range indexes with [m..n]" do
+ [ "a", "b", "c", "d", "e" ][1..3].should == ["b", "c", "d"]
+ [ "a", "b", "c", "d", "e" ][4..-1].should == ['e']
+ [ "a", "b", "c", "d", "e" ][3..3].should == ['d']
+ [ "a", "b", "c", "d", "e" ][3..-2].should == ['d']
+ ['a'][0..-1].should == ['a']
+
+ a = [1, 2, 3, 4]
+
+ a[0..-10].should == []
+ a[0..0].should == [1]
+ a[0..1].should == [1, 2]
+ a[0..2].should == [1, 2, 3]
+ a[0..3].should == [1, 2, 3, 4]
+ a[0..4].should == [1, 2, 3, 4]
+ a[0..10].should == [1, 2, 3, 4]
+
+ a[2..-10].should == []
+ a[2..0].should == []
+ a[2..2].should == [3]
+ a[2..3].should == [3, 4]
+ a[2..4].should == [3, 4]
+
+ a[3..0].should == []
+ a[3..3].should == [4]
+ a[3..4].should == [4]
+
+ a[4..0].should == []
+ a[4..4].should == []
+ a[4..5].should == []
+
+ a[5..0].should == nil
+ a[5..5].should == nil
+ a[5..6].should == nil
+
+ a.should == [1, 2, 3, 4]
+ end
+
+ it "returns elements specified by Range indexes except the element at index n with [m...n]" do
+ [ "a", "b", "c", "d", "e" ][1...3].should == ["b", "c"]
+
+ a = [1, 2, 3, 4]
+
+ a[0...-10].should == []
+ a[0...0].should == []
+ a[0...1].should == [1]
+ a[0...2].should == [1, 2]
+ a[0...3].should == [1, 2, 3]
+ a[0...4].should == [1, 2, 3, 4]
+ a[0...10].should == [1, 2, 3, 4]
+
+ a[2...-10].should == []
+ a[2...0].should == []
+ a[2...2].should == []
+ a[2...3].should == [3]
+ a[2...4].should == [3, 4]
+
+ a[3...0].should == []
+ a[3...3].should == []
+ a[3...4].should == [4]
+
+ a[4...0].should == []
+ a[4...4].should == []
+ a[4...5].should == []
+
+ a[5...0].should == nil
+ a[5...5].should == nil
+ a[5...6].should == nil
+
+ a.should == [1, 2, 3, 4]
+ end
+
+ it "returns elements that exist if range start is in the array but range end is not with [m..n]" do
+ [ "a", "b", "c", "d", "e" ][4..7].should == ["e"]
+ end
+
+ it "accepts Range instances having a negative m and both signs for n with [m..n] and [m...n]" do
+ a = [1, 2, 3, 4]
+
+ a[-1..-1].should == [4]
+ a[-1...-1].should == []
+ a[-1..3].should == [4]
+ a[-1...3].should == []
+ a[-1..4].should == [4]
+ a[-1...4].should == [4]
+ a[-1..10].should == [4]
+ a[-1...10].should == [4]
+ a[-1..0].should == []
+ a[-1..-4].should == []
+ a[-1...-4].should == []
+ a[-1..-6].should == []
+ a[-1...-6].should == []
+
+ a[-2..-2].should == [3]
+ a[-2...-2].should == []
+ a[-2..-1].should == [3, 4]
+ a[-2...-1].should == [3]
+ a[-2..10].should == [3, 4]
+ a[-2...10].should == [3, 4]
+
+ a[-4..-4].should == [1]
+ a[-4..-2].should == [1, 2, 3]
+ a[-4...-2].should == [1, 2]
+ a[-4..-1].should == [1, 2, 3, 4]
+ a[-4...-1].should == [1, 2, 3]
+ a[-4..3].should == [1, 2, 3, 4]
+ a[-4...3].should == [1, 2, 3]
+ a[-4..4].should == [1, 2, 3, 4]
+ a[-4...4].should == [1, 2, 3, 4]
+ a[-4...4].should == [1, 2, 3, 4]
+ a[-4..0].should == [1]
+ a[-4...0].should == []
+ a[-4..1].should == [1, 2]
+ a[-4...1].should == [1]
+
+ a[-5..-5].should == nil
+ a[-5...-5].should == nil
+ a[-5..-4].should == nil
+ a[-5..-1].should == nil
+ a[-5..10].should == nil
+
+ a.should == [1, 2, 3, 4]
+ end
+
+ it "returns the subarray which is independent to self with [m..n]" do
+ a = [1, 2, 3]
+ sub = a[1..2]
+ sub.replace([:a, :b])
+ a.should == [1, 2, 3]
+ end
+
+ it "tries to convert Range elements to Integers using #to_int with [m..n] and [m...n]" do
+ from = mock('from')
+ to = mock('to')
+
+ # So we can construct a range out of them...
+ def from.<=>(o) 0 end
+ def to.<=>(o) 0 end
+
+ def from.to_int() 1 end
+ def to.to_int() -2 end
+
+ a = [1, 2, 3, 4]
+
+ a[from..to].should == [2, 3]
+ a[from...to].should == [2]
+ a[1..0].should == []
+ a[1...0].should == []
+
+ -> { a["a" .. "b"] }.should.raise(TypeError)
+ -> { a["a" ... "b"] }.should.raise(TypeError)
+ -> { a[from .. "b"] }.should.raise(TypeError)
+ -> { a[from ... "b"] }.should.raise(TypeError)
+ end
+
+ it "returns the same elements as [m..n] and [m...n] with Range subclasses" do
+ a = [1, 2, 3, 4]
+ range_incl = ArraySpecs::MyRange.new(1, 2)
+ range_excl = ArraySpecs::MyRange.new(-3, -1, true)
+
+ a[range_incl].should == [2, 3]
+ a[range_excl].should == [2, 3]
+ end
+
+ it "returns nil for a requested index not in the array with [index]" do
+ [ "a", "b", "c", "d", "e" ][5].should == nil
+ end
+
+ it "returns [] if the index is valid but length is zero with [index, length]" do
+ [ "a", "b", "c", "d", "e" ][0, 0].should == []
+ [ "a", "b", "c", "d", "e" ][2, 0].should == []
+ end
+
+ it "returns nil if length is zero but index is invalid with [index, length]" do
+ [ "a", "b", "c", "d", "e" ][100, 0].should == nil
+ [ "a", "b", "c", "d", "e" ][-50, 0].should == nil
+ end
+
+ # This is by design. It is in the official documentation.
+ it "returns [] if index == array.size with [index, length]" do
+ %w|a b c d e|[5, 2].should == []
+ end
+
+ it "returns nil if index > array.size with [index, length]" do
+ %w|a b c d e|[6, 2].should == nil
+ end
+
+ it "returns nil if length is negative with [index, length]" do
+ %w|a b c d e|[3, -1].should == nil
+ %w|a b c d e|[2, -2].should == nil
+ %w|a b c d e|[1, -100].should == nil
+ end
+
+ it "returns nil if no requested index is in the array with [m..n]" do
+ [ "a", "b", "c", "d", "e" ][6..10].should == nil
+ end
+
+ it "returns nil if range start is not in the array with [m..n]" do
+ [ "a", "b", "c", "d", "e" ][-10..2].should == nil
+ [ "a", "b", "c", "d", "e" ][10..12].should == nil
+ end
+
+ it "returns an empty array when m == n with [m...n]" do
+ [1, 2, 3, 4, 5][1...1].should == []
+ end
+
+ it "returns an empty array with [0...0]" do
+ [1, 2, 3, 4, 5][0...0].should == []
+ end
+
+ it "returns a subarray where m, n negatives and m < n with [m..n]" do
+ [ "a", "b", "c", "d", "e" ][-3..-2].should == ["c", "d"]
+ end
+
+ it "returns an array containing the first element with [0..0]" do
+ [1, 2, 3, 4, 5][0..0].should == [1]
+ end
+
+ it "returns the entire array with [0..-1]" do
+ [1, 2, 3, 4, 5][0..-1].should == [1, 2, 3, 4, 5]
+ end
+
+ it "returns all but the last element with [0...-1]" do
+ [1, 2, 3, 4, 5][0...-1].should == [1, 2, 3, 4]
+ end
+
+ it "returns [3] for [2..-1] out of [1, 2, 3]" do
+ [1,2,3][2..-1].should == [3]
+ end
+
+ it "returns an empty array when m > n and m, n are positive with [m..n]" do
+ [1, 2, 3, 4, 5][3..2].should == []
+ end
+
+ it "returns an empty array when m > n and m, n are negative with [m..n]" do
+ [1, 2, 3, 4, 5][-2..-3].should == []
+ end
+
+ it "does not expand array when the indices are outside of the array bounds" do
+ a = [1, 2]
+ a[4].should == nil
+ a.should == [1, 2]
+ a[4, 0].should == nil
+ a.should == [1, 2]
+ a[6, 1].should == nil
+ a.should == [1, 2]
+ a[8...8].should == nil
+ a.should == [1, 2]
+ a[10..10].should == nil
+ a.should == [1, 2]
+ end
+
+ describe "with a subclass of Array" do
+ before :each do
+ ScratchPad.clear
+
+ @array = ArraySpecs::MyArray[1, 2, 3, 4, 5]
+ end
+
+ it "returns a Array instance with [n, m]" do
+ @array[0, 2].should.instance_of?(Array)
+ end
+
+ it "returns a Array instance with [-n, m]" do
+ @array[-3, 2].should.instance_of?(Array)
+ end
+
+ it "returns a Array instance with [n..m]" do
+ @array[1..3].should.instance_of?(Array)
+ end
+
+ it "returns a Array instance with [n...m]" do
+ @array[1...3].should.instance_of?(Array)
+ end
+
+ it "returns a Array instance with [-n..-m]" do
+ @array[-3..-1].should.instance_of?(Array)
+ end
+
+ it "returns a Array instance with [-n...-m]" do
+ @array[-3...-1].should.instance_of?(Array)
+ end
+
+ it "returns an empty array when m == n with [m...n]" do
+ @array[1...1].should == []
+ ScratchPad.recorded.should == nil
+ end
+
+ it "returns an empty array with [0...0]" do
+ @array[0...0].should == []
+ ScratchPad.recorded.should == nil
+ end
+
+ it "returns an empty array when m > n and m, n are positive with [m..n]" do
+ @array[3..2].should == []
+ ScratchPad.recorded.should == nil
+ end
+
+ it "returns an empty array when m > n and m, n are negative with [m..n]" do
+ @array[-2..-3].should == []
+ ScratchPad.recorded.should == nil
+ end
+
+ it "returns [] if index == array.size with [index, length]" do
+ @array[5, 2].should == []
+ ScratchPad.recorded.should == nil
+ end
+
+ it "returns [] if the index is valid but length is zero with [index, length]" do
+ @array[0, 0].should == []
+ @array[2, 0].should == []
+ ScratchPad.recorded.should == nil
+ end
+
+ it "does not call #initialize on the subclass instance" do
+ @array[0, 3].should == [1, 2, 3]
+ ScratchPad.recorded.should == nil
+ end
+ end
+
+ it "raises a RangeError when the start index is out of range of Fixnum" do
+ array = [1, 2, 3, 4, 5, 6]
+ obj = mock('large value')
+ obj.should_receive(:to_int).and_return(bignum_value)
+ -> { array[obj] }.should.raise(RangeError)
+
+ obj = 8e19
+ -> { array[obj] }.should.raise(RangeError)
+
+ # boundary value when longs are 64 bits
+ -> { array[2.0**63] }.should.raise(RangeError)
+
+ # just under the boundary value when longs are 64 bits
+ array[max_long.to_f.prev_float].should == nil
+ end
+
+ it "raises a RangeError when the length is out of range of Fixnum" do
+ array = [1, 2, 3, 4, 5, 6]
+ obj = mock('large value')
+ obj.should_receive(:to_int).and_return(bignum_value)
+ -> { array[1, obj] }.should.raise(RangeError)
+
+ obj = 8e19
+ -> { array[1, obj] }.should.raise(RangeError)
+ end
+
+ it "raises a type error if a range is passed with a length" do
+ ->{ [1, 2, 3][1..2, 1] }.should.raise(TypeError)
+ end
+
+ it "raises a RangeError if passed a range with a bound that is too large" do
+ array = [1, 2, 3, 4, 5, 6]
+ -> { array[bignum_value..(bignum_value + 1)] }.should.raise(RangeError)
+ -> { array[0..bignum_value] }.should.raise(RangeError)
+ end
+
+ it "can accept endless ranges" do
+ a = [0, 1, 2, 3, 4, 5]
+ a[eval("(2..)")].should == [2, 3, 4, 5]
+ a[eval("(2...)")].should == [2, 3, 4, 5]
+ a[eval("(-2..)")].should == [4, 5]
+ a[eval("(-2...)")].should == [4, 5]
+ a[eval("(9..)")].should == nil
+ a[eval("(9...)")].should == nil
+ a[eval("(-9..)")].should == nil
+ a[eval("(-9...)")].should == nil
+ end
+
+ describe "can be sliced with Enumerator::ArithmeticSequence" do
+ before :each do
+ @array = [0, 1, 2, 3, 4, 5]
+ end
+
+ it "has endless range and positive steps" do
+ @array[eval("(0..).step(1)")].should == [0, 1, 2, 3, 4, 5]
+ @array[eval("(0..).step(2)")].should == [0, 2, 4]
+ @array[eval("(0..).step(10)")].should == [0]
+
+ @array[eval("(2..).step(1)")].should == [2, 3, 4, 5]
+ @array[eval("(2..).step(2)")].should == [2, 4]
+ @array[eval("(2..).step(10)")].should == [2]
+
+ @array[eval("(-3..).step(1)")].should == [3, 4, 5]
+ @array[eval("(-3..).step(2)")].should == [3, 5]
+ @array[eval("(-3..).step(10)")].should == [3]
+ end
+
+ it "has beginless range and positive steps" do
+ # end with zero index
+ @array[(..0).step(1)].should == [0]
+ @array[(...0).step(1)].should == []
+
+ @array[(..0).step(2)].should == [0]
+ @array[(...0).step(2)].should == []
+
+ @array[(..0).step(10)].should == [0]
+ @array[(...0).step(10)].should == []
+
+ # end with positive index
+ @array[(..3).step(1)].should == [0, 1, 2, 3]
+ @array[(...3).step(1)].should == [0, 1, 2]
+
+ @array[(..3).step(2)].should == [0, 2]
+ @array[(...3).step(2)].should == [0, 2]
+
+ @array[(..3).step(10)].should == [0]
+ @array[(...3).step(10)].should == [0]
+
+ # end with negative index
+ @array[(..-2).step(1)].should == [0, 1, 2, 3, 4,]
+ @array[(...-2).step(1)].should == [0, 1, 2, 3]
+
+ @array[(..-2).step(2)].should == [0, 2, 4]
+ @array[(...-2).step(2)].should == [0, 2]
+
+ @array[(..-2).step(10)].should == [0]
+ @array[(...-2).step(10)].should == [0]
+ end
+
+ it "has endless range and negative steps" do
+ @array[eval("(0..).step(-1)")].should == [0]
+ @array[eval("(0..).step(-2)")].should == [0]
+ @array[eval("(0..).step(-10)")].should == [0]
+
+ @array[eval("(2..).step(-1)")].should == [2, 1, 0]
+ @array[eval("(2..).step(-2)")].should == [2, 0]
+
+ @array[eval("(-3..).step(-1)")].should == [3, 2, 1, 0]
+ @array[eval("(-3..).step(-2)")].should == [3, 1]
+ end
+
+ it "has closed range and positive steps" do
+ # start and end with 0
+ @array[eval("(0..0).step(1)")].should == [0]
+ @array[eval("(0...0).step(1)")].should == []
+
+ @array[eval("(0..0).step(2)")].should == [0]
+ @array[eval("(0...0).step(2)")].should == []
+
+ @array[eval("(0..0).step(10)")].should == [0]
+ @array[eval("(0...0).step(10)")].should == []
+
+ # start and end with positive index
+ @array[eval("(1..3).step(1)")].should == [1, 2, 3]
+ @array[eval("(1...3).step(1)")].should == [1, 2]
+
+ @array[eval("(1..3).step(2)")].should == [1, 3]
+ @array[eval("(1...3).step(2)")].should == [1]
+
+ @array[eval("(1..3).step(10)")].should == [1]
+ @array[eval("(1...3).step(10)")].should == [1]
+
+ # start with positive index, end with negative index
+ @array[eval("(1..-2).step(1)")].should == [1, 2, 3, 4]
+ @array[eval("(1...-2).step(1)")].should == [1, 2, 3]
+
+ @array[eval("(1..-2).step(2)")].should == [1, 3]
+ @array[eval("(1...-2).step(2)")].should == [1, 3]
+
+ @array[eval("(1..-2).step(10)")].should == [1]
+ @array[eval("(1...-2).step(10)")].should == [1]
+
+ # start with negative index, end with positive index
+ @array[eval("(-4..4).step(1)")].should == [2, 3, 4]
+ @array[eval("(-4...4).step(1)")].should == [2, 3]
+
+ @array[eval("(-4..4).step(2)")].should == [2, 4]
+ @array[eval("(-4...4).step(2)")].should == [2]
+
+ @array[eval("(-4..4).step(10)")].should == [2]
+ @array[eval("(-4...4).step(10)")].should == [2]
+
+ # start with negative index, end with negative index
+ @array[eval("(-4..-2).step(1)")].should == [2, 3, 4]
+ @array[eval("(-4...-2).step(1)")].should == [2, 3]
+
+ @array[eval("(-4..-2).step(2)")].should == [2, 4]
+ @array[eval("(-4...-2).step(2)")].should == [2]
+
+ @array[eval("(-4..-2).step(10)")].should == [2]
+ @array[eval("(-4...-2).step(10)")].should == [2]
+ end
+
+ it "has closed range and negative steps" do
+ # start and end with 0
+ @array[eval("(0..0).step(-1)")].should == [0]
+ @array[eval("(0...0).step(-1)")].should == []
+
+ @array[eval("(0..0).step(-2)")].should == [0]
+ @array[eval("(0...0).step(-2)")].should == []
+
+ @array[eval("(0..0).step(-10)")].should == [0]
+ @array[eval("(0...0).step(-10)")].should == []
+
+ # start and end with positive index
+ @array[eval("(1..3).step(-1)")].should == []
+ @array[eval("(1...3).step(-1)")].should == []
+
+ @array[eval("(1..3).step(-2)")].should == []
+ @array[eval("(1...3).step(-2)")].should == []
+
+ @array[eval("(1..3).step(-10)")].should == []
+ @array[eval("(1...3).step(-10)")].should == []
+
+ # start with positive index, end with negative index
+ @array[eval("(1..-2).step(-1)")].should == []
+ @array[eval("(1...-2).step(-1)")].should == []
+
+ @array[eval("(1..-2).step(-2)")].should == []
+ @array[eval("(1...-2).step(-2)")].should == []
+
+ @array[eval("(1..-2).step(-10)")].should == []
+ @array[eval("(1...-2).step(-10)")].should == []
+
+ # start with negative index, end with positive index
+ @array[eval("(-4..4).step(-1)")].should == []
+ @array[eval("(-4...4).step(-1)")].should == []
+
+ @array[eval("(-4..4).step(-2)")].should == []
+ @array[eval("(-4...4).step(-2)")].should == []
+
+ @array[eval("(-4..4).step(-10)")].should == []
+ @array[eval("(-4...4).step(-10)")].should == []
+
+ # start with negative index, end with negative index
+ @array[eval("(-4..-2).step(-1)")].should == []
+ @array[eval("(-4...-2).step(-1)")].should == []
+
+ @array[eval("(-4..-2).step(-2)")].should == []
+ @array[eval("(-4...-2).step(-2)")].should == []
+
+ @array[eval("(-4..-2).step(-10)")].should == []
+ @array[eval("(-4...-2).step(-10)")].should == []
+ end
+
+ it "has inverted closed range and positive steps" do
+ # start and end with positive index
+ @array[eval("(3..1).step(1)")].should == []
+ @array[eval("(3...1).step(1)")].should == []
+
+ @array[eval("(3..1).step(2)")].should == []
+ @array[eval("(3...1).step(2)")].should == []
+
+ @array[eval("(3..1).step(10)")].should == []
+ @array[eval("(3...1).step(10)")].should == []
+
+ # start with negative index, end with positive index
+ @array[eval("(-2..1).step(1)")].should == []
+ @array[eval("(-2...1).step(1)")].should == []
+
+ @array[eval("(-2..1).step(2)")].should == []
+ @array[eval("(-2...1).step(2)")].should == []
+
+ @array[eval("(-2..1).step(10)")].should == []
+ @array[eval("(-2...1).step(10)")].should == []
+
+ # start with positive index, end with negative index
+ @array[eval("(4..-4).step(1)")].should == []
+ @array[eval("(4...-4).step(1)")].should == []
+
+ @array[eval("(4..-4).step(2)")].should == []
+ @array[eval("(4...-4).step(2)")].should == []
+
+ @array[eval("(4..-4).step(10)")].should == []
+ @array[eval("(4...-4).step(10)")].should == []
+
+ # start with negative index, end with negative index
+ @array[eval("(-2..-4).step(1)")].should == []
+ @array[eval("(-2...-4).step(1)")].should == []
+
+ @array[eval("(-2..-4).step(2)")].should == []
+ @array[eval("(-2...-4).step(2)")].should == []
+
+ @array[eval("(-2..-4).step(10)")].should == []
+ @array[eval("(-2...-4).step(10)")].should == []
+ end
+
+ it "has range with bounds outside of array" do
+ # end is equal to array's length
+ @array[(0..6).step(1)].should == [0, 1, 2, 3, 4, 5]
+ -> { @array[(0..6).step(2)] }.should.raise(RangeError)
+
+ # end is greater than length with positive steps
+ @array[(1..6).step(2)].should == [1, 3, 5]
+ @array[(2..7).step(2)].should == [2, 4]
+ -> { @array[(2..8).step(2)] }.should.raise(RangeError)
+
+ # begin is greater than length with negative steps
+ @array[(6..1).step(-2)].should == [5, 3, 1]
+ @array[(7..2).step(-2)].should == [5, 3]
+ -> { @array[(8..2).step(-2)] }.should.raise(RangeError)
+ end
+
+ it "has endless range with start outside of array's bounds" do
+ @array[eval("(6..).step(1)")].should == []
+ @array[eval("(7..).step(1)")].should == nil
+
+ @array[eval("(6..).step(2)")].should == []
+ -> { @array[eval("(7..).step(2)")] }.should.raise(RangeError)
+ end
+ end
+
+ it "can accept beginless ranges" do
+ a = [0, 1, 2, 3, 4, 5]
+ a[(..3)].should == [0, 1, 2, 3]
+ a[(...3)].should == [0, 1, 2]
+ a[(..-3)].should == [0, 1, 2, 3]
+ a[(...-3)].should == [0, 1, 2]
+ a[(..0)].should == [0]
+ a[(...0)].should == []
+ a[(..9)].should == [0, 1, 2, 3, 4, 5]
+ a[(...9)].should == [0, 1, 2, 3, 4, 5]
+ a[(..-9)].should == []
+ a[(...-9)].should == []
+ end
+
+ describe "can be sliced with Enumerator::ArithmeticSequence" do
+ it "with infinite/inverted ranges and negative steps" do
+ array = [0, 1, 2, 3, 4, 5]
+ array[(2..).step(-1)].should == [2, 1, 0]
+ array[(2..).step(-2)].should == [2, 0]
+ array[(2..).step(-3)].should == [2]
+ array[(2..).step(-4)].should == [2]
+
+ array[(-3..).step(-1)].should == [3, 2, 1, 0]
+ array[(-3..).step(-2)].should == [3, 1]
+ array[(-3..).step(-3)].should == [3, 0]
+ array[(-3..).step(-4)].should == [3]
+ array[(-3..).step(-5)].should == [3]
+
+ array[(..0).step(-1)].should == [5, 4, 3, 2, 1, 0]
+ array[(..0).step(-2)].should == [5, 3, 1]
+ array[(..0).step(-3)].should == [5, 2]
+ array[(..0).step(-4)].should == [5, 1]
+ array[(..0).step(-5)].should == [5, 0]
+ array[(..0).step(-6)].should == [5]
+ array[(..0).step(-7)].should == [5]
+
+ array[(...0).step(-1)].should == [5, 4, 3, 2, 1]
+ array[(...0).step(-2)].should == [5, 3, 1]
+ array[(...0).step(-3)].should == [5, 2]
+ array[(...0).step(-4)].should == [5, 1]
+ array[(...0).step(-5)].should == [5]
+ array[(...0).step(-6)].should == [5]
+
+ array[(...1).step(-1)].should == [5, 4, 3, 2]
+ array[(...1).step(-2)].should == [5, 3]
+ array[(...1).step(-3)].should == [5, 2]
+ array[(...1).step(-4)].should == [5]
+ array[(...1).step(-5)].should == [5]
+
+ array[(..-5).step(-1)].should == [5, 4, 3, 2, 1]
+ array[(..-5).step(-2)].should == [5, 3, 1]
+ array[(..-5).step(-3)].should == [5, 2]
+ array[(..-5).step(-4)].should == [5, 1]
+ array[(..-5).step(-5)].should == [5]
+ array[(..-5).step(-6)].should == [5]
+
+ array[(...-5).step(-1)].should == [5, 4, 3, 2]
+ array[(...-5).step(-2)].should == [5, 3]
+ array[(...-5).step(-3)].should == [5, 2]
+ array[(...-5).step(-4)].should == [5]
+ array[(...-5).step(-5)].should == [5]
+
+ array[(4..1).step(-1)].should == [4, 3, 2, 1]
+ array[(4..1).step(-2)].should == [4, 2]
+ array[(4..1).step(-3)].should == [4, 1]
+ array[(4..1).step(-4)].should == [4]
+ array[(4..1).step(-5)].should == [4]
+
+ array[(4...1).step(-1)].should == [4, 3, 2]
+ array[(4...1).step(-2)].should == [4, 2]
+ array[(4...1).step(-3)].should == [4]
+ array[(4...1).step(-4)].should == [4]
+
+ array[(-2..1).step(-1)].should == [4, 3, 2, 1]
+ array[(-2..1).step(-2)].should == [4, 2]
+ array[(-2..1).step(-3)].should == [4, 1]
+ array[(-2..1).step(-4)].should == [4]
+ array[(-2..1).step(-5)].should == [4]
+
+ array[(-2...1).step(-1)].should == [4, 3, 2]
+ array[(-2...1).step(-2)].should == [4, 2]
+ array[(-2...1).step(-3)].should == [4]
+ array[(-2...1).step(-4)].should == [4]
+
+ array[(4..-5).step(-1)].should == [4, 3, 2, 1]
+ array[(4..-5).step(-2)].should == [4, 2]
+ array[(4..-5).step(-3)].should == [4, 1]
+ array[(4..-5).step(-4)].should == [4]
+ array[(4..-5).step(-5)].should == [4]
+
+ array[(4...-5).step(-1)].should == [4, 3, 2]
+ array[(4...-5).step(-2)].should == [4, 2]
+ array[(4...-5).step(-3)].should == [4]
+ array[(4...-5).step(-4)].should == [4]
+
+ array[(-2..-5).step(-1)].should == [4, 3, 2, 1]
+ array[(-2..-5).step(-2)].should == [4, 2]
+ array[(-2..-5).step(-3)].should == [4, 1]
+ array[(-2..-5).step(-4)].should == [4]
+ array[(-2..-5).step(-5)].should == [4]
+
+ array[(-2...-5).step(-1)].should == [4, 3, 2]
+ array[(-2...-5).step(-2)].should == [4, 2]
+ array[(-2...-5).step(-3)].should == [4]
+ array[(-2...-5).step(-4)].should == [4]
+ end
+ end
+
+ it "can accept nil...nil ranges" do
+ a = [0, 1, 2, 3, 4, 5]
+ a[eval("(nil...nil)")].should == a
+ a[(...nil)].should == a
+ a[eval("(nil..)")].should == a
+ end
end
describe "Array.[]" do
@@ -39,12 +892,12 @@ describe "Array.[]" do
end
it "returns an instance of the subclass" do
- ArraySpecs::MyArray[1, 2, 3].should be_an_instance_of(ArraySpecs::MyArray)
+ ArraySpecs::MyArray[1, 2, 3].should.instance_of?(ArraySpecs::MyArray)
end
it "does not call #initialize on the subclass instance" do
ArraySpecs::MyArray[1, 2, 3].should == [1, 2, 3]
- ScratchPad.recorded.should be_nil
+ ScratchPad.recorded.should == nil
end
end
end
diff --git a/spec/ruby/core/array/element_set_spec.rb b/spec/ruby/core/array/element_set_spec.rb
index 6544ad9b6f..671e4338de 100644
--- a/spec/ruby/core/array/element_set_spec.rb
+++ b/spec/ruby/core/array/element_set_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Array#[]=" do
it "sets the value of the element at index" do
@@ -36,6 +36,7 @@ describe "Array#[]=" do
a[3, 2] = ['a', 'b', 'c', 'd']
a.should == [2, 2, 3, "a", "b", "c", "d", 6]
end
+
it "replaces the section defined by [start,length] with the given values" do
a = [1, 2, 3, 4, 5, 6]
a[3, 2] = 'a', 'b', 'c', 'd'
@@ -94,8 +95,8 @@ describe "Array#[]=" do
it "checks frozen before attempting to coerce arguments" do
a = [1,2,3,4].freeze
- lambda {a[:foo] = 1}.should raise_error(RuntimeError)
- lambda {a[:foo, :bar] = 1}.should raise_error(RuntimeError)
+ -> {a[:foo] = 1}.should.raise(FrozenError)
+ -> {a[:foo, :bar] = 1}.should.raise(FrozenError)
end
it "sets elements in the range arguments when passed ranges" do
@@ -169,6 +170,7 @@ describe "Array#[]=" do
ary[1...1] = []
ary.should == [1, 2, 3]
end
+
it "does nothing if the section defined by range has negative width and the rhs is an empty array" do
ary = [1, 2, 3, 4, 5]
ary[1...0] = []
@@ -195,25 +197,25 @@ describe "Array#[]=" do
a[to .. from] = ["x"]
a.should == [1, "a", "b", "x", "c", 4]
- lambda { a["a" .. "b"] = [] }.should raise_error(TypeError)
- lambda { a[from .. "b"] = [] }.should raise_error(TypeError)
+ -> { a["a" .. "b"] = [] }.should.raise(TypeError)
+ -> { a[from .. "b"] = [] }.should.raise(TypeError)
end
it "raises an IndexError when passed indexes out of bounds" do
a = [1, 2, 3, 4]
- lambda { a[-5] = "" }.should raise_error(IndexError)
- lambda { a[-5, -1] = "" }.should raise_error(IndexError)
- lambda { a[-5, 0] = "" }.should raise_error(IndexError)
- lambda { a[-5, 1] = "" }.should raise_error(IndexError)
- lambda { a[-5, 2] = "" }.should raise_error(IndexError)
- lambda { a[-5, 10] = "" }.should raise_error(IndexError)
-
- lambda { a[-5..-5] = "" }.should raise_error(RangeError)
- lambda { a[-5...-5] = "" }.should raise_error(RangeError)
- lambda { a[-5..-4] = "" }.should raise_error(RangeError)
- lambda { a[-5...-4] = "" }.should raise_error(RangeError)
- lambda { a[-5..10] = "" }.should raise_error(RangeError)
- lambda { a[-5...10] = "" }.should raise_error(RangeError)
+ -> { a[-5] = "" }.should.raise(IndexError)
+ -> { a[-5, -1] = "" }.should.raise(IndexError)
+ -> { a[-5, 0] = "" }.should.raise(IndexError)
+ -> { a[-5, 1] = "" }.should.raise(IndexError)
+ -> { a[-5, 2] = "" }.should.raise(IndexError)
+ -> { a[-5, 10] = "" }.should.raise(IndexError)
+
+ -> { a[-5..-5] = "" }.should.raise(RangeError)
+ -> { a[-5...-5] = "" }.should.raise(RangeError)
+ -> { a[-5..-4] = "" }.should.raise(RangeError)
+ -> { a[-5...-4] = "" }.should.raise(RangeError)
+ -> { a[-5..10] = "" }.should.raise(RangeError)
+ -> { a[-5...10] = "" }.should.raise(RangeError)
# ok
a[0..-9] = [1]
@@ -236,8 +238,8 @@ describe "Array#[]=" do
ary.should == [5, 6, 7]
end
- it "raises a RuntimeError on a frozen array" do
- lambda { ArraySpecs.frozen_array[0, 0] = [] }.should raise_error(RuntimeError)
+ it "raises a FrozenError on a frozen array" do
+ -> { ArraySpecs.frozen_array[0, 0] = [] }.should.raise(FrozenError)
end
end
@@ -284,6 +286,12 @@ describe "Array#[]= with [index, count]" do
(a[2, 3] = [4, 5]).should == [4, 5]
end
+ it "accepts a frozen String literal as RHS" do
+ a = ['a', 'b', 'c']
+ a[0, 2] = 'd'.freeze
+ a.should == ['d', 'c']
+ end
+
it "just sets the section defined by [start,length] to nil even if the rhs is nil" do
a = ['a', 'b', 'c', 'd', 'e']
a[1, 3] = nil
@@ -323,6 +331,10 @@ describe "Array#[]= with [index, count]" do
b = [1, 2, 3, 4, 5]
b[10, 0] = [1]
a.should == [1, 2, 3, 4, 5, nil, nil, nil, nil, nil, 1]
+
+ c = [1, 2, 3, 4, 5]
+ c[10, 0] = []
+ c.should == [1, 2, 3, 4, 5, nil, nil, nil, nil, nil]
end
it "inserts other section in place defined by idx" do
@@ -337,12 +349,12 @@ describe "Array#[]= with [index, count]" do
it "raises an IndexError when passed start and negative length" do
a = [1, 2, 3, 4]
- lambda { a[-2, -1] = "" }.should raise_error(IndexError)
- lambda { a[0, -1] = "" }.should raise_error(IndexError)
- lambda { a[2, -1] = "" }.should raise_error(IndexError)
- lambda { a[4, -1] = "" }.should raise_error(IndexError)
- lambda { a[10, -1] = "" }.should raise_error(IndexError)
- lambda { [1, 2, 3, 4, 5][2, -1] = [7, 8] }.should raise_error(IndexError)
+ -> { a[-2, -1] = "" }.should.raise(IndexError)
+ -> { a[0, -1] = "" }.should.raise(IndexError)
+ -> { a[2, -1] = "" }.should.raise(IndexError)
+ -> { a[4, -1] = "" }.should.raise(IndexError)
+ -> { a[10, -1] = "" }.should.raise(IndexError)
+ -> { [1, 2, 3, 4, 5][2, -1] = [7, 8] }.should.raise(IndexError)
end
end
@@ -350,11 +362,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 +408,121 @@ 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)
+ it "inserts at the end if m > the array size" do
+ a = [1, 2, 3]
+ a[3..3] = [4]
+ a.should == [1, 2, 3, 4]
+ a[5..7] = [6]
+ a.should == [1, 2, 3, 4, nil, 6]
+ end
+
+ 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
+
+describe "Array#[]= with [m..]" do
+ it "just sets the section defined by range to nil even if the rhs is nil" do
+ a = [1, 2, 3, 4, 5]
+ a[eval("(2..)")] = nil
+ a.should == [1, 2, nil]
+ end
+
+ it "just sets the section defined by range to nil if m and n < 0 and the rhs is nil" do
+ a = [1, 2, 3, 4, 5]
+ a[eval("(-3..)")] = nil
+ a.should == [1, 2, nil]
+ end
+
+ it "replaces the section defined by range" do
+ a = [6, 5, 4, 3, 2, 1]
+ a[eval("(3...)")] = 9
+ a.should == [6, 5, 4, 9]
+ a[eval("(2..)")] = [7, 7, 7]
+ a.should == [6, 5, 7, 7, 7]
+ end
+
+ it "replaces the section if m and n < 0" do
+ a = [1, 2, 3, 4, 5]
+ a[eval("(-3..)")] = [7, 8, 9]
+ a.should == [1, 2, 7, 8, 9]
+ end
+
+ it "inserts at the end if m > the array size" do
+ a = [1, 2, 3]
+ a[eval("(3..)")] = [4]
+ a.should == [1, 2, 3, 4]
+ a[eval("(5..)")] = [6]
+ a.should == [1, 2, 3, 4, nil, 6]
+ end
+end
+
+describe "Array#[]= with [..n] and [...n]" do
+ it "just sets the section defined by range to nil even if the rhs is nil" do
+ a = [1, 2, 3, 4, 5]
+ a[(..2)] = nil
+ a.should == [nil, 4, 5]
+ a[(...2)] = nil
+ a.should == [nil, 5]
+ end
+
+ it "just sets the section defined by range to nil if n < 0 and the rhs is nil" do
+ a = [1, 2, 3, 4, 5]
+ a[(..-3)] = nil
+ a.should == [nil, 4, 5]
+ a[(...-1)] = [nil, 5]
+ end
+
+ it "replaces the section defined by range" do
+ a = [6, 5, 4, 3, 2, 1]
+ a[(...3)] = 9
+ a.should == [9, 3, 2, 1]
+ a[(..2)] = [7, 7, 7, 7, 7]
+ a.should == [7, 7, 7, 7, 7, 1]
+ end
+
+ it "replaces the section if n < 0" do
+ a = [1, 2, 3, 4, 5]
+ a[(..-2)] = [7, 8, 9]
+ a.should == [7, 8, 9, 5]
+ end
+
+ it "replaces everything if n > the array size" do
+ a = [1, 2, 3]
+ a[(...7)] = [4]
+ a.should == [4]
+ end
+
+ it "inserts at the beginning if n < negative the array size" do
+ a = [1, 2, 3]
+ a[(..-7)] = [4]
+ a.should == [4, 1, 2, 3]
+ a[(...-10)] = [6]
+ a.should == [6, 4, 1, 2, 3]
end
end
diff --git a/spec/ruby/core/array/empty_spec.rb b/spec/ruby/core/array/empty_spec.rb
index d6235114b7..f70b1b6ebe 100644
--- a/spec/ruby/core/array/empty_spec.rb
+++ b/spec/ruby/core/array/empty_spec.rb
@@ -1,10 +1,10 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Array#empty?" do
it "returns true if the array has no elements" do
- [].empty?.should == true
- [1].empty?.should == false
- [1, 2].empty?.should == false
+ [].should.empty?
+ [1].should_not.empty?
+ [1, 2].should_not.empty?
end
end
diff --git a/spec/ruby/core/array/eql_spec.rb b/spec/ruby/core/array/eql_spec.rb
index 7621316e07..9a7447c2e8 100644
--- a/spec/ruby/core/array/eql_spec.rb
+++ b/spec/ruby/core/array/eql_spec.rb
@@ -1,19 +1,19 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/eql', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/eql'
describe "Array#eql?" do
it_behaves_like :array_eql, :eql?
it "returns false if any corresponding elements are not #eql?" do
- [1, 2, 3, 4].send(@method, [1, 2, 3, 4.0]).should be_false
+ [1, 2, 3, 4].should_not.eql?([1, 2, 3, 4.0])
end
it "returns false if other is not a kind of Array" do
obj = mock("array eql?")
obj.should_not_receive(:to_ary)
- obj.should_not_receive(@method)
+ obj.should_not_receive(:eql?)
- [1, 2, 3].send(@method, obj).should be_false
+ [1, 2, 3].should_not.eql?(obj)
end
end
diff --git a/spec/ruby/core/array/equal_value_spec.rb b/spec/ruby/core/array/equal_value_spec.rb
index d923d0e503..4f7c0ce5e3 100644
--- a/spec/ruby/core/array/equal_value_spec.rb
+++ b/spec/ruby/core/array/equal_value_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/eql', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/eql'
describe "Array#==" do
it_behaves_like :array_eql, :==
@@ -10,17 +10,17 @@ describe "Array#==" do
obj.should_receive(:respond_to?).at_least(1).with(:to_ary).and_return(true)
obj.should_receive(:==).with([1]).at_least(1).and_return(true)
- ([1] == obj).should be_true
- ([[1]] == [obj]).should be_true
- ([[[1], 3], 2] == [[obj, 3], 2]).should be_true
+ ([1] == obj).should == true
+ ([[1]] == [obj]).should == true
+ ([[[1], 3], 2] == [[obj, 3], 2]).should == true
# recursive arrays
arr1 = [[1]]
arr1 << arr1
arr2 = [obj]
arr2 << arr2
- (arr1 == arr2).should be_true
- (arr2 == arr1).should be_true
+ (arr1 == arr2).should == true
+ (arr2 == arr1).should == true
end
it "returns false if any corresponding elements are not #==" do
@@ -44,8 +44,8 @@ describe "Array#==" do
[obj].should == [5]
end
- # As per bug #1720
- it "returns false for [NaN] == [NaN]" do
- [nan_value].should_not == [nan_value]
+ # See https://bugs.ruby-lang.org/issues/1720
+ it "returns true for [NaN] == [NaN] because Array#== first checks with #equal? and NaN.equal?(NaN) is true" do
+ [Float::NAN].should == [Float::NAN]
end
end
diff --git a/spec/ruby/core/array/fetch_spec.rb b/spec/ruby/core/array/fetch_spec.rb
index 5adf96fed8..ee94cfcbb2 100644
--- a/spec/ruby/core/array/fetch_spec.rb
+++ b/spec/ruby/core/array/fetch_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Array#fetch" do
it "returns the element at the passed index" do
@@ -12,9 +12,9 @@ describe "Array#fetch" do
end
it "raises an IndexError if there is no element at index" do
- lambda { [1, 2, 3].fetch(3) }.should raise_error(IndexError)
- lambda { [1, 2, 3].fetch(-4) }.should raise_error(IndexError)
- lambda { [].fetch(0) }.should raise_error(IndexError)
+ -> { [1, 2, 3].fetch(3) }.should.raise(IndexError, "index 3 outside of array bounds: -3...3")
+ -> { [1, 2, 3].fetch(-4) }.should.raise(IndexError, "index -4 outside of array bounds: -3...3")
+ -> { [].fetch(0) }.should.raise(IndexError, "index 0 outside of array bounds: 0...0")
end
it "returns default if there is no element at index if passed a default value" do
@@ -33,11 +33,11 @@ describe "Array#fetch" do
o = mock('5')
def o.to_int(); 5; end
- [1, 2, 3].fetch(o) { |i| i }.should equal(o)
+ [1, 2, 3].fetch(o) { |i| i }.should.equal?(o)
end
it "gives precedence to the default block over the default argument" do
- lambda {
+ -> {
@result = [1, 2, 3].fetch(9, :foo) { |i| i * i }
}.should complain(/block supersedes default value argument/)
@result.should == 81
@@ -50,6 +50,6 @@ describe "Array#fetch" do
end
it "raises a TypeError when the passed argument can't be coerced to Integer" do
- lambda { [].fetch("cat") }.should raise_error(TypeError)
+ -> { [].fetch("cat") }.should.raise(TypeError, "no implicit conversion of String into Integer")
end
end
diff --git a/spec/ruby/core/array/fetch_values_spec.rb b/spec/ruby/core/array/fetch_values_spec.rb
new file mode 100644
index 0000000000..237d6ad7f7
--- /dev/null
+++ b/spec/ruby/core/array/fetch_values_spec.rb
@@ -0,0 +1,55 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe "Array#fetch_values" do
+ before :each do
+ @array = [:a, :b, :c]
+ end
+
+ ruby_version_is "3.4" do
+ describe "with matched indexes" do
+ it "returns the values for indexes" do
+ @array.fetch_values(0).should == [:a]
+ @array.fetch_values(0, 2).should == [:a, :c]
+ @array.fetch_values(-1).should == [:c]
+ end
+
+ it "returns the values for indexes ordered in the order of the requested indexes" do
+ @array.fetch_values(2, 0).should == [:c, :a]
+ end
+ end
+
+ describe "with unmatched indexes" do
+ it "raises a index error if no block is provided" do
+ -> { @array.fetch_values(0, 1, 44) }.should.raise(IndexError, "index 44 outside of array bounds: -3...3")
+ end
+
+ it "returns the default value from block" do
+ @array.fetch_values(44) { |index| "`#{index}' is not found" }.should == ["`44' is not found"]
+ @array.fetch_values(0, 44) { |index| "`#{index}' is not found" }.should == [:a, "`44' is not found"]
+ end
+ end
+
+ describe "without keys" do
+ it "returns an empty Array" do
+ @array.fetch_values.should == []
+ end
+ end
+
+ it "tries to convert the passed argument to an Integer using #to_int" do
+ obj = mock('to_int')
+ obj.should_receive(:to_int).and_return(2)
+ @array.fetch_values(obj).should == [:c]
+ end
+
+ it "does not support a Range object as argument" do
+ -> {
+ @array.fetch_values(1..2)
+ }.should.raise(TypeError, "no implicit conversion of Range into Integer")
+ end
+
+ it "raises a TypeError when the passed argument can't be coerced to Integer" do
+ -> { [].fetch_values("cat") }.should.raise(TypeError, "no implicit conversion of String into Integer")
+ end
+ end
+end
diff --git a/spec/ruby/core/array/fill_spec.rb b/spec/ruby/core/array/fill_spec.rb
index 5ff7f8a250..e4d51bd998 100644
--- a/spec/ruby/core/array/fill_spec.rb
+++ b/spec/ruby/core/array/fill_spec.rb
@@ -1,16 +1,16 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Array#fill" do
before :all do
- @never_passed = lambda do |i|
+ @never_passed = -> i do
raise ExpectationNotMetError, "the control path should not pass here"
end
end
it "returns self" do
ary = [1, 2, 3]
- ary.fill(:a).should equal(ary)
+ ary.fill(:a).should.equal?(ary)
end
it "is destructive" do
@@ -21,14 +21,14 @@ describe "Array#fill" do
it "does not replicate the filler" do
ary = [1, 2, 3, 4]
- str = "x"
+ str = +"x"
ary.fill(str).should == [str, str, str, str]
str << "y"
ary.should == [str, str, str, str]
- ary[0].should equal(str)
- ary[1].should equal(str)
- ary[2].should equal(str)
- ary[3].should equal(str)
+ ary[0].should.equal?(str)
+ ary[1].should.equal?(str)
+ ary[2].should.equal?(str)
+ ary[3].should.equal?(str)
end
it "replaces all elements in the array with the filler if not given a index nor a length" do
@@ -43,34 +43,72 @@ describe "Array#fill" do
[nil, nil, nil, nil].fill { |i| i * 2 }.should == [0, 2, 4, 6]
end
- it "raises a RuntimeError on a frozen array" do
- lambda { ArraySpecs.frozen_array.fill('x') }.should raise_error(RuntimeError)
+ it "raises a FrozenError on a frozen array" do
+ -> { ArraySpecs.frozen_array.fill('x') }.should.raise(FrozenError)
end
- it "raises a RuntimeError on an empty frozen array" do
- lambda { ArraySpecs.empty_frozen_array.fill('x') }.should raise_error(RuntimeError)
+ it "raises a FrozenError on an empty frozen array" do
+ -> { ArraySpecs.empty_frozen_array.fill('x') }.should.raise(FrozenError)
end
it "raises an ArgumentError if 4 or more arguments are passed when no block given" do
- lambda { [].fill('a') }.should_not raise_error(ArgumentError)
-
- lambda { [].fill('a', 1) }.should_not raise_error(ArgumentError)
-
- lambda { [].fill('a', 1, 2) }.should_not raise_error(ArgumentError)
- lambda { [].fill('a', 1, 2, true) }.should raise_error(ArgumentError)
+ [].fill('a').should == []
+ [].fill('a', 1).should == []
+ [].fill('a', 1, 2).should == [nil, 'a', 'a']
+ -> { [].fill('a', 1, 2, true) }.should.raise(ArgumentError)
end
it "raises an ArgumentError if no argument passed and no block given" do
- lambda { [].fill }.should raise_error(ArgumentError)
+ -> { [].fill }.should.raise(ArgumentError)
end
it "raises an ArgumentError if 3 or more arguments are passed when a block given" do
- lambda { [].fill() {|i|} }.should_not raise_error(ArgumentError)
+ [].fill() {|i|}.should == []
+ [].fill(1) {|i|}.should == []
+ [].fill(1, 2) {|i|}.should == [nil, nil, nil]
+ -> { [].fill(1, 2, true) {|i|} }.should.raise(ArgumentError)
+ end
+
+ it "does not truncate the array is the block raises an exception" do
+ a = [1, 2, 3]
+ begin
+ a.fill { raise StandardError, 'Oops' }
+ rescue
+ end
- lambda { [].fill(1) {|i|} }.should_not raise_error(ArgumentError)
+ a.should == [1, 2, 3]
+ end
+
+ it "only changes elements before error is raised, keeping the element which raised an error." do
+ a = [1, 2, 3, 4]
+ begin
+ a.fill do |i|
+ case i
+ when 0 then -1
+ when 1 then -2
+ when 2 then raise StandardError, 'Oops'
+ else 0
+ end
+ end
+ rescue StandardError
+ end
- lambda { [].fill(1, 2) {|i|} }.should_not raise_error(ArgumentError)
- lambda { [].fill(1, 2, true) {|i|} }.should raise_error(ArgumentError)
+ a.should == [-1, -2, 3, 4]
+ end
+
+ it "tolerates increasing an array size during iteration" do
+ array = [:a, :b, :c]
+ ScratchPad.record []
+ i = 0
+
+ array.fill do |index|
+ ScratchPad << index
+ array << i if i < 100
+ i++
+ index
+ end
+
+ ScratchPad.recorded.should == [0, 1, 2]
end
end
@@ -169,25 +207,25 @@ describe "Array#fill with (filler, index, length)" do
[1, 2, 3, 4, 5].fill(-2, -2, &@never_passed).should == [1, 2, 3, 4, 5]
end
- # See: http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/17481
+ # See: https://blade.ruby-lang.org/ruby-core/17481
it "does not raise an exception if the given length is negative and its absolute value does not exceed the index" do
- lambda { [1, 2, 3, 4].fill('a', 3, -1)}.should_not raise_error(ArgumentError)
- lambda { [1, 2, 3, 4].fill('a', 3, -2)}.should_not raise_error(ArgumentError)
- lambda { [1, 2, 3, 4].fill('a', 3, -3)}.should_not raise_error(ArgumentError)
+ [1, 2, 3, 4].fill('a', 3, -1).should == [1, 2, 3, 4]
+ [1, 2, 3, 4].fill('a', 3, -2).should == [1, 2, 3, 4]
+ [1, 2, 3, 4].fill('a', 3, -3).should == [1, 2, 3, 4]
- lambda { [1, 2, 3, 4].fill(3, -1, &@never_passed)}.should_not raise_error(ArgumentError)
- lambda { [1, 2, 3, 4].fill(3, -2, &@never_passed)}.should_not raise_error(ArgumentError)
- lambda { [1, 2, 3, 4].fill(3, -3, &@never_passed)}.should_not raise_error(ArgumentError)
+ [1, 2, 3, 4].fill(3, -1, &@never_passed).should == [1, 2, 3, 4]
+ [1, 2, 3, 4].fill(3, -2, &@never_passed).should == [1, 2, 3, 4]
+ [1, 2, 3, 4].fill(3, -3, &@never_passed).should == [1, 2, 3, 4]
end
it "does not raise an exception even if the given length is negative and its absolute value exceeds the index" do
- lambda { [1, 2, 3, 4].fill('a', 3, -4)}.should_not raise_error(ArgumentError)
- lambda { [1, 2, 3, 4].fill('a', 3, -5)}.should_not raise_error(ArgumentError)
- lambda { [1, 2, 3, 4].fill('a', 3, -10000)}.should_not raise_error(ArgumentError)
+ [1, 2, 3, 4].fill('a', 3, -4).should == [1, 2, 3, 4]
+ [1, 2, 3, 4].fill('a', 3, -5).should == [1, 2, 3, 4]
+ [1, 2, 3, 4].fill('a', 3, -10000).should == [1, 2, 3, 4]
- lambda { [1, 2, 3, 4].fill(3, -4, &@never_passed)}.should_not raise_error(ArgumentError)
- lambda { [1, 2, 3, 4].fill(3, -5, &@never_passed)}.should_not raise_error(ArgumentError)
- lambda { [1, 2, 3, 4].fill(3, -10000, &@never_passed)}.should_not raise_error(ArgumentError)
+ [1, 2, 3, 4].fill(3, -4, &@never_passed).should == [1, 2, 3, 4]
+ [1, 2, 3, 4].fill(3, -5, &@never_passed).should == [1, 2, 3, 4]
+ [1, 2, 3, 4].fill(3, -10000, &@never_passed).should == [1, 2, 3, 4]
end
it "tries to convert the second and third arguments to Integers using #to_int" do
@@ -199,17 +237,24 @@ describe "Array#fill with (filler, index, length)" do
end
it "raises a TypeError if the index is not numeric" do
- lambda { [].fill 'a', true }.should raise_error(TypeError)
+ -> { [].fill 'a', true }.should.raise(TypeError)
obj = mock('nonnumeric')
- lambda { [].fill('a', obj) }.should raise_error(TypeError)
+ -> { [].fill('a', obj) }.should.raise(TypeError)
+ end
+
+ it "raises a TypeError when the length is not numeric" do
+ -> { [1, 2, 3].fill("x", 1, "foo") }.should.raise(TypeError, /no implicit conversion of String into Integer/)
+ -> { [1, 2, 3].fill("x", 1, :"foo") }.should.raise(TypeError, /no implicit conversion of Symbol into Integer/)
+ -> { [1, 2, 3].fill("x", 1, Object.new) }.should.raise(TypeError, /no implicit conversion of Object into Integer/)
end
not_supported_on :opal do
it "raises an ArgumentError or RangeError for too-large sizes" do
+ error_types = [RangeError, ArgumentError]
arr = [1, 2, 3]
- lambda { arr.fill(10, 1, fixnum_max) }.should raise_error(ArgumentError)
- lambda { arr.fill(10, 1, bignum_value) }.should raise_error(RangeError)
+ -> { arr.fill(10, 1, fixnum_max) }.should.raise { |err| error_types.should.include?(err.class) }
+ -> { arr.fill(10, 1, bignum_value) }.should.raise(RangeError)
end
end
end
@@ -239,7 +284,7 @@ describe "Array#fill with (filler, range)" do
end
it "raises a TypeError with range and length argument" do
- lambda { [].fill('x', 0 .. 2, 5) }.should raise_error(TypeError)
+ -> { [].fill('x', 0 .. 2, 5) }.should.raise(TypeError)
end
it "replaces elements between the (-m)th to the last and the (n+1)th from the first if given an range m..n where m < 0 and n >= 0" do
@@ -291,13 +336,13 @@ describe "Array#fill with (filler, range)" do
end
it "raises an exception if some of the given range lies before the first of the array" do
- lambda { [1, 2, 3].fill('x', -5..-3) }.should raise_error(RangeError)
- lambda { [1, 2, 3].fill('x', -5...-3) }.should raise_error(RangeError)
- lambda { [1, 2, 3].fill('x', -5..-4) }.should raise_error(RangeError)
+ -> { [1, 2, 3].fill('x', -5..-3) }.should.raise(RangeError)
+ -> { [1, 2, 3].fill('x', -5...-3) }.should.raise(RangeError)
+ -> { [1, 2, 3].fill('x', -5..-4) }.should.raise(RangeError)
- lambda { [1, 2, 3].fill(-5..-3, &@never_passed) }.should raise_error(RangeError)
- lambda { [1, 2, 3].fill(-5...-3, &@never_passed) }.should raise_error(RangeError)
- lambda { [1, 2, 3].fill(-5..-4, &@never_passed) }.should raise_error(RangeError)
+ -> { [1, 2, 3].fill(-5..-3, &@never_passed) }.should.raise(RangeError)
+ -> { [1, 2, 3].fill(-5...-3, &@never_passed) }.should.raise(RangeError)
+ -> { [1, 2, 3].fill(-5..-4, &@never_passed) }.should.raise(RangeError)
end
it "tries to convert the start and end of the passed range to Integers using #to_int" do
@@ -312,6 +357,18 @@ describe "Array#fill with (filler, range)" do
it "raises a TypeError if the start or end of the passed range is not numeric" do
obj = mock('nonnumeric')
def obj.<=>(rhs); rhs == self ? 0 : nil end
- lambda { [].fill('a', obj..obj) }.should raise_error(TypeError)
+ -> { [].fill('a', obj..obj) }.should.raise(TypeError)
+ end
+
+ it "works with endless ranges" do
+ [1, 2, 3, 4].fill('x', eval("(1..)")).should == [1, 'x', 'x', 'x']
+ [1, 2, 3, 4].fill('x', eval("(3...)")).should == [1, 2, 3, 'x']
+ [1, 2, 3, 4].fill(eval("(1..)")) { |x| x + 2 }.should == [1, 3, 4, 5]
+ [1, 2, 3, 4].fill(eval("(3...)")) { |x| x + 2 }.should == [1, 2, 3, 5]
+ end
+
+ it "works with beginless ranges" do
+ [1, 2, 3, 4].fill('x', (..2)).should == ["x", "x", "x", 4]
+ [1, 2, 3, 4].fill((...2)) { |x| x + 2 }.should == [2, 3, 3, 4]
end
end
diff --git a/spec/ruby/core/array/filter_spec.rb b/spec/ruby/core/array/filter_spec.rb
new file mode 100644
index 0000000000..6ebda61069
--- /dev/null
+++ b/spec/ruby/core/array/filter_spec.rb
@@ -0,0 +1,13 @@
+require_relative '../../spec_helper'
+
+describe "Array#filter" do
+ it "is an alias of Array#select" do
+ Array.instance_method(:filter).should == Array.instance_method(:select)
+ end
+end
+
+describe "Array#filter!" do
+ it "is an alias of Array#select!" do
+ Array.instance_method(:filter!).should == Array.instance_method(:select!)
+ end
+end
diff --git a/spec/ruby/core/array/find_index_spec.rb b/spec/ruby/core/array/find_index_spec.rb
index 522b4b31c6..17ff6c04a7 100644
--- a/spec/ruby/core/array/find_index_spec.rb
+++ b/spec/ruby/core/array/find_index_spec.rb
@@ -1,6 +1,42 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/index', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/iterable_and_tolerating_size_increasing'
describe "Array#find_index" do
- it_behaves_like :array_index, :find_index
+ it "returns the index of the first element == to object" do
+ x = mock('3')
+ def x.==(obj) 3 == obj; end
+
+ [2, x, 3, 1, 3, 1].find_index(3).should == 1
+ [2, 3.0, 3, x, 1, 3, 1].find_index(x).should == 1
+ end
+
+ it "returns 0 if first element == to object" do
+ [2, 1, 3, 2, 5].find_index(2).should == 0
+ end
+
+ it "returns size-1 if only last element == to object" do
+ [2, 1, 3, 1, 5].find_index(5).should == 4
+ end
+
+ it "returns nil if no element == to object" do
+ [2, 1, 1, 1, 1].find_index(3).should == nil
+ end
+
+ it "accepts a block instead of an argument" do
+ [4, 2, 1, 5, 1, 3].find_index {|x| x < 2}.should == 2
+ end
+
+ it "ignores the block if there is an argument" do
+ -> {
+ [4, 2, 1, 5, 1, 3].find_index(5) {|x| x < 2}.should == 3
+ }.should complain(/given block not used/)
+ end
+
+ describe "given no argument and no block" do
+ it "produces an Enumerator" do
+ [].find_index.should.instance_of?(Enumerator)
+ end
+ end
+
+ it_behaves_like :array_iterable_and_tolerating_size_increasing, :find_index
end
diff --git a/spec/ruby/core/array/first_spec.rb b/spec/ruby/core/array/first_spec.rb
index 60a0a76594..2c343ac8f6 100644
--- a/spec/ruby/core/array/first_spec.rb
+++ b/spec/ruby/core/array/first_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Array#first" do
it "returns the first element" do
@@ -30,11 +30,11 @@ describe "Array#first" do
end
it "raises an ArgumentError when count is negative" do
- lambda { [1, 2].first(-1) }.should raise_error(ArgumentError)
+ -> { [1, 2].first(-1) }.should.raise(ArgumentError)
end
it "raises a RangeError when count is a Bignum" do
- lambda { [].first(bignum_value) }.should raise_error(RangeError)
+ -> { [].first(bignum_value) }.should.raise(RangeError)
end
it "returns the entire array when count > length" do
@@ -53,10 +53,10 @@ describe "Array#first" do
it "properly handles recursive arrays" do
empty = ArraySpecs.empty_recursive_array
- empty.first.should equal(empty)
+ empty.first.should.equal?(empty)
ary = ArraySpecs.head_recursive_array
- ary.first.should equal(ary)
+ ary.first.should.equal?(ary)
end
it "tries to convert the passed argument to an Integer using #to_int" do
@@ -66,19 +66,19 @@ describe "Array#first" do
end
it "raises a TypeError if the passed argument is not numeric" do
- lambda { [1,2].first(nil) }.should raise_error(TypeError)
- lambda { [1,2].first("a") }.should raise_error(TypeError)
+ -> { [1,2].first(nil) }.should.raise(TypeError)
+ -> { [1,2].first("a") }.should.raise(TypeError)
obj = mock("nonnumeric")
- lambda { [1,2].first(obj) }.should raise_error(TypeError)
+ -> { [1,2].first(obj) }.should.raise(TypeError)
end
it "does not return subclass instance when passed count on Array subclasses" do
- ArraySpecs::MyArray[].first(0).should be_an_instance_of(Array)
- ArraySpecs::MyArray[].first(2).should be_an_instance_of(Array)
- ArraySpecs::MyArray[1, 2, 3].first(0).should be_an_instance_of(Array)
- ArraySpecs::MyArray[1, 2, 3].first(1).should be_an_instance_of(Array)
- ArraySpecs::MyArray[1, 2, 3].first(2).should be_an_instance_of(Array)
+ ArraySpecs::MyArray[].first(0).should.instance_of?(Array)
+ ArraySpecs::MyArray[].first(2).should.instance_of?(Array)
+ ArraySpecs::MyArray[1, 2, 3].first(0).should.instance_of?(Array)
+ ArraySpecs::MyArray[1, 2, 3].first(1).should.instance_of?(Array)
+ ArraySpecs::MyArray[1, 2, 3].first(2).should.instance_of?(Array)
end
it "is not destructive" do
diff --git a/spec/ruby/core/array/fixtures/classes.rb b/spec/ruby/core/array/fixtures/classes.rb
index 4292554724..05283c0f74 100644
--- a/spec/ruby/core/array/fixtures/classes.rb
+++ b/spec/ruby/core/array/fixtures/classes.rb
@@ -2,9 +2,10 @@ class Object
# This helper is defined here rather than in MSpec because
# it is only used in #pack specs.
def pack_format(count=nil, repeat=nil)
- format = "#{instance_variable_get(:@method)}#{count}"
+ format = instance_variable_get(:@method)
+ format += count.to_s unless format == 'P' || format == 'p'
format *= repeat if repeat
- format
+ format.dup # because it may then become tainted
end
end
@@ -13,15 +14,11 @@ module ArraySpecs
SampleCount = 1000
def self.frozen_array
- frozen_array = [1,2,3]
- frozen_array.freeze
- frozen_array
+ [1,2,3].freeze
end
def self.empty_frozen_array
- frozen_array = []
- frozen_array.freeze
- frozen_array
+ [].freeze
end
def self.recursive_array
@@ -43,6 +40,62 @@ module ArraySpecs
a
end
+ # Chi squared critical values for tests with n degrees of freedom at 99% confidence.
+ # Values obtained from NIST Engineering Statistic Handbook at
+ # https://www.itl.nist.gov/div898/handbook/eda/section3/eda3674.htm
+
+ CHI_SQUARED_CRITICAL_VALUES = [
+ 0,
+ 6.635, 9.210, 11.345, 13.277, 15.086, 16.812, 18.475, 20.090, 21.666, 23.209,
+ 24.725, 26.217, 27.688, 29.141, 30.578, 32.000, 33.409, 34.805, 36.191, 37.566,
+ 38.932, 40.289, 41.638, 42.980, 44.314, 45.642, 46.963, 48.278, 49.588, 50.892,
+ 52.191, 53.486, 54.776, 56.061, 57.342, 58.619, 59.893, 61.162, 62.428, 63.691,
+ 64.950, 66.206, 67.459, 68.710, 69.957, 71.201, 72.443, 73.683, 74.919, 76.154,
+ 77.386, 78.616, 79.843, 81.069, 82.292, 83.513, 84.733, 85.950, 87.166, 88.379,
+ 89.591, 90.802, 92.010, 93.217, 94.422, 95.626, 96.828, 98.028, 99.228, 100.425,
+ 101.621, 102.816, 104.010, 105.202, 106.393, 107.583, 108.771, 109.958, 111.144, 112.329,
+ 113.512, 114.695, 115.876, 117.057, 118.236, 119.414, 120.591, 121.767, 122.942, 124.116,
+ 125.289, 126.462, 127.633, 128.803, 129.973, 131.141, 132.309, 133.476, 134.642, 135.807,
+ ]
+
+ def self.measure_sample_fairness(size, samples, iters)
+ ary = Array.new(size) { |x| x }
+ expected = iters.fdiv size
+ (samples).times do |i|
+ chi_results = []
+ 3.times do
+ counts = Array.new(size, 0)
+ iters.times do
+ x = ary.sample(samples)[i]
+ counts[x] += 1
+ end
+ chi_squared = counts.sum {|count| (count - expected) ** 2} / expected
+ chi_results << chi_squared
+ break if chi_squared <= CHI_SQUARED_CRITICAL_VALUES[size]
+ end
+
+ chi_results.min.should <= CHI_SQUARED_CRITICAL_VALUES[size]
+ end
+ end
+
+ def self.measure_sample_fairness_large_sample_size(size, samples, iters)
+ ary = Array.new(size) { |x| x }
+ counts = Array.new(size, 0)
+ expected = (iters * samples).fdiv size
+ iters.times do
+ ary.sample(samples).each do |sample|
+ counts[sample] += 1
+ end
+ end
+ chi_squared = counts.sum {|count| (count - expected) ** 2} / expected
+
+ # Chi squared critical values for tests with 4 degrees of freedom
+ # Values obtained from NIST Engineering Statistic Handbook at
+ # https://www.itl.nist.gov/div898/handbook/eda/section3/eda3674.htm
+
+ chi_squared.should <= CHI_SQUARED_CRITICAL_VALUES[size]
+ end
+
class MyArray < Array
# The #initialize method has a different signature than Array to help
# catch places in the specs that do not assert the #initialize is not
@@ -84,7 +137,7 @@ module ArraySpecs
end
end
- class ArrayConvertable
+ class ArrayConvertible
attr_accessor :called
def initialize(*values, &block)
@values = values;
@@ -101,6 +154,16 @@ module ArraySpecs
end
end
+ class ArrayMethodMissing
+ def initialize(*values, &block)
+ @values = values;
+ end
+
+ def method_missing(name, *args)
+ @values
+ end
+ end
+
class SortSame
def <=>(other); 0; end
def ==(other); true; end
@@ -129,7 +192,7 @@ module ArraySpecs
attr_accessor :order
end
- class ComparableWithFixnum
+ class ComparableWithInteger
include Comparable
def initialize(num)
@num = num
@@ -147,373 +210,377 @@ module ArraySpecs
end
def self.universal_pack_object
- obj = mock("string float int")
+ obj = mock("string float int".freeze)
obj.stub!(:to_int).and_return(1)
obj.stub!(:to_str).and_return("1")
obj.stub!(:to_f).and_return(1.0)
obj
end
- LargeArray = ["test_create_table_with_force_true_does_not_drop_nonexisting_table",
- "test_add_table",
- "assert_difference",
- "assert_operator",
- "instance_variables",
- "class",
- "instance_variable_get",
- "__class__",
- "expects",
- "assert_no_difference",
- "name",
- "assert_blank",
- "assert_not_same",
- "is_a?",
- "test_add_table_with_decimals",
- "test_create_table_with_timestamps_should_create_datetime_columns",
- "assert_present",
- "assert_no_match",
- "__instance_of__",
- "assert_deprecated",
- "assert",
- "assert_throws",
- "kind_of?",
- "try",
- "__instance_variable_get__",
- "object_id",
- "timeout",
- "instance_variable_set",
- "assert_nothing_thrown",
- "__instance_variable_set__",
- "copy_object",
- "test_create_table_with_timestamps_should_create_datetime_columns_with_options",
- "assert_not_deprecated",
- "assert_in_delta",
- "id",
- "copy_metaclass",
- "test_create_table_without_a_block",
- "dup",
- "assert_not_nil",
- "send",
- "__instance_variables__",
- "to_sql",
- "mock",
- "assert_send",
- "instance_variable_defined?",
- "clone",
- "require",
- "test_migrator",
- "__instance_variable_defined_eh__",
- "frozen?",
- "test_add_column_not_null_with_default",
- "freeze",
- "test_migrator_one_up",
- "test_migrator_one_down",
- "singleton_methods",
- "method_exists?",
- "create_fixtures",
- "test_migrator_one_up_one_down",
- "test_native_decimal_insert_manual_vs_automatic",
- "instance_exec",
- "__is_a__",
- "test_migrator_double_up",
- "stub",
- "private_methods",
- "stubs",
- "test_migrator_double_down",
- "fixture_path",
- "private_singleton_methods",
- "stub_everything",
- "test_migrator_one_up_with_exception_and_rollback",
- "sequence",
- "protected_methods",
- "enum_for",
- "test_finds_migrations",
- "run_before_mocha",
- "states",
- "protected_singleton_methods",
- "to_json",
- "instance_values",
- "==",
- "mocha_setup",
- "public_methods",
- "test_finds_pending_migrations",
- "mocha_verify",
- "assert_kind_of",
- "===",
- "=~",
- "test_relative_migrations",
- "mocha_teardown",
- "gem",
- "mocha",
- "test_only_loads_pending_migrations",
- "test_add_column_with_precision_and_scale",
- "require_or_load",
- "eql?",
- "require_dependency",
- "test_native_types",
- "test_target_version_zero_should_run_only_once",
- "extend",
- "to_matcher",
- "unloadable",
- "require_association",
- "hash",
- "__id__",
- "load_dependency",
- "equals",
- "test_migrator_db_has_no_schema_migrations_table",
- "test_migrator_verbosity",
- "kind_of",
- "to_yaml",
- "to_bool",
- "test_migrator_verbosity_off",
- "taint",
- "test_migrator_going_down_due_to_version_target",
- "tainted?",
- "mocha_inspect",
- "test_migrator_rollback",
- "vim",
- "untaint",
- "taguri=",
- "test_migrator_forward",
- "test_schema_migrations_table_name",
- "test_proper_table_name",
- "all_of",
- "test_add_drop_table_with_prefix_and_suffix",
- "_setup_callbacks",
- "setup",
- "Not",
- "test_create_table_with_binary_column",
- "assert_not_equal",
- "enable_warnings",
- "acts_like?",
- "Rational",
- "_removed_setup_callbacks",
- "Table",
- "bind",
- "any_of",
- "__method__",
- "test_migrator_with_duplicates",
- "_teardown_callbacks",
- "method",
- "test_migrator_with_duplicate_names",
- "_removed_teardown_callbacks",
- "any_parameters",
- "test_migrator_with_missing_version_numbers",
- "test_add_remove_single_field_using_string_arguments",
- "test_create_table_with_custom_sequence_name",
- "test_add_remove_single_field_using_symbol_arguments",
- "_one_time_conditions_valid_14?",
- "_one_time_conditions_valid_16?",
- "run_callbacks",
- "anything",
- "silence_warnings",
- "instance_variable_names",
- "_fixture_path",
- "copy_instance_variables_from",
- "fixture_path?",
- "has_entry",
- "__marshal__",
- "_fixture_table_names",
- "__kind_of__",
- "fixture_table_names?",
- "test_add_rename",
- "assert_equal",
- "_fixture_class_names",
- "fixture_class_names?",
- "has_entries",
- "_use_transactional_fixtures",
- "people",
- "test_rename_column_using_symbol_arguments",
- "use_transactional_fixtures?",
- "instance_eval",
- "blank?",
- "with_warnings",
- "__nil__",
- "load",
- "metaclass",
- "_use_instantiated_fixtures",
- "has_key",
- "class_eval",
- "present?",
- "test_rename_column",
- "teardown",
- "use_instantiated_fixtures?",
- "method_name",
- "silence_stderr",
- "presence",
- "test_rename_column_preserves_default_value_not_null",
- "silence_stream",
- "_pre_loaded_fixtures",
- "__metaclass__",
- "__fixnum__",
- "pre_loaded_fixtures?",
- "has_value",
- "suppress",
- "to_yaml_properties",
- "test_rename_nonexistent_column",
- "test_add_index",
- "includes",
- "find_correlate_in",
- "equality_predicate_sql",
- "assert_nothing_raised",
- "let",
- "not_predicate_sql",
- "test_rename_column_with_sql_reserved_word",
- "singleton_class",
- "test_rename_column_with_an_index",
- "display",
- "taguri",
- "to_yaml_style",
- "test_remove_column_with_index",
- "size",
- "current_adapter?",
- "test_remove_column_with_multi_column_index",
- "respond_to?",
- "test_change_type_of_not_null_column",
- "is_a",
- "to_a",
- "test_rename_table_for_sqlite_should_work_with_reserved_words",
- "require_library_or_gem",
- "setup_fixtures",
- "equal?",
- "teardown_fixtures",
- "nil?",
- "fixture_table_names",
- "fixture_class_names",
- "test_create_table_without_id",
- "use_transactional_fixtures",
- "test_add_column_with_primary_key_attribute",
- "repair_validations",
- "use_instantiated_fixtures",
- "instance_of?",
- "test_create_table_adds_id",
- "test_rename_table",
- "pre_loaded_fixtures",
- "to_enum",
- "test_create_table_with_not_null_column",
- "instance_of",
- "test_change_column_nullability",
- "optionally",
- "test_rename_table_with_an_index",
- "run",
- "test_change_column",
- "default_test",
- "assert_raise",
- "test_create_table_with_defaults",
- "assert_nil",
- "flunk",
- "regexp_matches",
- "duplicable?",
- "reset_mocha",
- "stubba_method",
- "filter_backtrace",
- "test_create_table_with_limits",
- "responds_with",
- "stubba_object",
- "test_change_column_with_nil_default",
- "assert_block",
- "__show__",
- "assert_date_from_db",
- "__respond_to_eh__",
- "run_in_transaction?",
- "inspect",
- "assert_sql",
- "test_change_column_with_new_default",
- "yaml_equivalent",
- "build_message",
- "to_s",
- "test_change_column_default",
- "assert_queries",
- "pending",
- "as_json",
- "assert_no_queries",
- "test_change_column_quotes_column_names",
- "assert_match",
- "test_keeping_default_and_notnull_constaint_on_change",
- "methods",
- "connection_allow_concurrency_setup",
- "connection_allow_concurrency_teardown",
- "test_create_table_with_primary_key_prefix_as_table_name_with_underscore",
- "__send__",
- "make_connection",
- "assert_raises",
- "tap",
- "with_kcode",
- "assert_instance_of",
- "test_create_table_with_primary_key_prefix_as_table_name",
- "assert_respond_to",
- "test_change_column_default_to_null",
- "assert_same",
- "__extend__"]
-
- LargeTestArraySorted = ["test_add_column_not_null_with_default",
- "test_add_column_with_precision_and_scale",
- "test_add_column_with_primary_key_attribute",
- "test_add_drop_table_with_prefix_and_suffix",
- "test_add_index",
- "test_add_remove_single_field_using_string_arguments",
- "test_add_remove_single_field_using_symbol_arguments",
- "test_add_rename",
- "test_add_table",
- "test_add_table_with_decimals",
- "test_change_column",
- "test_change_column_default",
- "test_change_column_default_to_null",
- "test_change_column_nullability",
- "test_change_column_quotes_column_names",
- "test_change_column_with_new_default",
- "test_change_column_with_nil_default",
- "test_change_type_of_not_null_column",
- "test_create_table_adds_id",
- "test_create_table_with_binary_column",
- "test_create_table_with_custom_sequence_name",
- "test_create_table_with_defaults",
- "test_create_table_with_force_true_does_not_drop_nonexisting_table",
- "test_create_table_with_limits",
- "test_create_table_with_not_null_column",
- "test_create_table_with_primary_key_prefix_as_table_name",
- "test_create_table_with_primary_key_prefix_as_table_name_with_underscore",
- "test_create_table_with_timestamps_should_create_datetime_columns",
- "test_create_table_with_timestamps_should_create_datetime_columns_with_options",
- "test_create_table_without_a_block",
- "test_create_table_without_id",
- "test_finds_migrations",
- "test_finds_pending_migrations",
- "test_keeping_default_and_notnull_constaint_on_change",
- "test_migrator",
- "test_migrator_db_has_no_schema_migrations_table",
- "test_migrator_double_down",
- "test_migrator_double_up",
- "test_migrator_forward",
- "test_migrator_going_down_due_to_version_target",
- "test_migrator_one_down",
- "test_migrator_one_up",
- "test_migrator_one_up_one_down",
- "test_migrator_one_up_with_exception_and_rollback",
- "test_migrator_rollback",
- "test_migrator_verbosity",
- "test_migrator_verbosity_off",
- "test_migrator_with_duplicate_names",
- "test_migrator_with_duplicates",
- "test_migrator_with_missing_version_numbers",
- "test_native_decimal_insert_manual_vs_automatic",
- "test_native_types",
- "test_only_loads_pending_migrations",
- "test_proper_table_name",
- "test_relative_migrations",
- "test_remove_column_with_index",
- "test_remove_column_with_multi_column_index",
- "test_rename_column",
- "test_rename_column_preserves_default_value_not_null",
- "test_rename_column_using_symbol_arguments",
- "test_rename_column_with_an_index",
- "test_rename_column_with_sql_reserved_word",
- "test_rename_nonexistent_column",
- "test_rename_table",
- "test_rename_table_for_sqlite_should_work_with_reserved_words",
- "test_rename_table_with_an_index",
- "test_schema_migrations_table_name",
- "test_target_version_zero_should_run_only_once"]
+ LargeArray = [
+ "test_create_table_with_force_true_does_not_drop_nonexisting_table",
+ "test_add_table",
+ "assert_difference",
+ "assert_operator",
+ "instance_variables",
+ "class",
+ "instance_variable_get",
+ "__class__",
+ "expects",
+ "assert_no_difference",
+ "name",
+ "assert_blank",
+ "assert_not_same",
+ "is_a?",
+ "test_add_table_with_decimals",
+ "test_create_table_with_timestamps_should_create_datetime_columns",
+ "assert_present",
+ "assert_no_match",
+ "__instance_of__",
+ "assert_deprecated",
+ "assert",
+ "assert_throws",
+ "kind_of?",
+ "try",
+ "__instance_variable_get__",
+ "object_id",
+ "timeout",
+ "instance_variable_set",
+ "assert_nothing_thrown",
+ "__instance_variable_set__",
+ "copy_object",
+ "test_create_table_with_timestamps_should_create_datetime_columns_with_options",
+ "assert_not_deprecated",
+ "assert_in_delta",
+ "id",
+ "copy_metaclass",
+ "test_create_table_without_a_block",
+ "dup",
+ "assert_not_nil",
+ "send",
+ "__instance_variables__",
+ "to_sql",
+ "mock",
+ "assert_send",
+ "instance_variable_defined?",
+ "clone",
+ "require",
+ "test_migrator",
+ "__instance_variable_defined_eh__",
+ "frozen?",
+ "test_add_column_not_null_with_default",
+ "freeze",
+ "test_migrator_one_up",
+ "test_migrator_one_down",
+ "singleton_methods",
+ "method_exists?",
+ "create_fixtures",
+ "test_migrator_one_up_one_down",
+ "test_native_decimal_insert_manual_vs_automatic",
+ "instance_exec",
+ "__is_a__",
+ "test_migrator_double_up",
+ "stub",
+ "private_methods",
+ "stubs",
+ "test_migrator_double_down",
+ "fixture_path",
+ "private_singleton_methods",
+ "stub_everything",
+ "test_migrator_one_up_with_exception_and_rollback",
+ "sequence",
+ "protected_methods",
+ "enum_for",
+ "test_finds_migrations",
+ "run_before_mocha",
+ "states",
+ "protected_singleton_methods",
+ "to_json",
+ "instance_values",
+ "==",
+ "mocha_setup",
+ "public_methods",
+ "test_finds_pending_migrations",
+ "mocha_verify",
+ "assert_kind_of",
+ "===",
+ "=~",
+ "test_relative_migrations",
+ "mocha_teardown",
+ "gem",
+ "mocha",
+ "test_only_loads_pending_migrations",
+ "test_add_column_with_precision_and_scale",
+ "require_or_load",
+ "eql?",
+ "require_dependency",
+ "test_native_types",
+ "test_target_version_zero_should_run_only_once",
+ "extend",
+ "to_matcher",
+ "unloadable",
+ "require_association",
+ "hash",
+ "__id__",
+ "load_dependency",
+ "equals",
+ "test_migrator_db_has_no_schema_migrations_table",
+ "test_migrator_verbosity",
+ "kind_of",
+ "to_yaml",
+ "to_bool",
+ "test_migrator_verbosity_off",
+ "taint",
+ "test_migrator_going_down_due_to_version_target",
+ "tainted?",
+ "mocha_inspect",
+ "test_migrator_rollback",
+ "vim",
+ "untaint",
+ "taguri=",
+ "test_migrator_forward",
+ "test_schema_migrations_table_name",
+ "test_proper_table_name",
+ "all_of",
+ "test_add_drop_table_with_prefix_and_suffix",
+ "_setup_callbacks",
+ "setup",
+ "Not",
+ "test_create_table_with_binary_column",
+ "assert_not_equal",
+ "enable_warnings",
+ "acts_like?",
+ "Rational",
+ "_removed_setup_callbacks",
+ "Table",
+ "bind",
+ "any_of",
+ "__method__",
+ "test_migrator_with_duplicates",
+ "_teardown_callbacks",
+ "method",
+ "test_migrator_with_duplicate_names",
+ "_removed_teardown_callbacks",
+ "any_parameters",
+ "test_migrator_with_missing_version_numbers",
+ "test_add_remove_single_field_using_string_arguments",
+ "test_create_table_with_custom_sequence_name",
+ "test_add_remove_single_field_using_symbol_arguments",
+ "_one_time_conditions_valid_14?",
+ "_one_time_conditions_valid_16?",
+ "run_callbacks",
+ "anything",
+ "silence_warnings",
+ "instance_variable_names",
+ "_fixture_path",
+ "copy_instance_variables_from",
+ "fixture_path?",
+ "has_entry",
+ "__marshal__",
+ "_fixture_table_names",
+ "__kind_of__",
+ "fixture_table_names?",
+ "test_add_rename",
+ "assert_equal",
+ "_fixture_class_names",
+ "fixture_class_names?",
+ "has_entries",
+ "_use_transactional_fixtures",
+ "people",
+ "test_rename_column_using_symbol_arguments",
+ "use_transactional_fixtures?",
+ "instance_eval",
+ "blank?",
+ "with_warnings",
+ "__nil__",
+ "load",
+ "metaclass",
+ "_use_instantiated_fixtures",
+ "has_key",
+ "class_eval",
+ "present?",
+ "test_rename_column",
+ "teardown",
+ "use_instantiated_fixtures?",
+ "method_name",
+ "silence_stderr",
+ "presence",
+ "test_rename_column_preserves_default_value_not_null",
+ "silence_stream",
+ "_pre_loaded_fixtures",
+ "__metaclass__",
+ "__fixnum__",
+ "pre_loaded_fixtures?",
+ "has_value",
+ "suppress",
+ "to_yaml_properties",
+ "test_rename_nonexistent_column",
+ "test_add_index",
+ "includes",
+ "find_correlate_in",
+ "equality_predicate_sql",
+ "assert_nothing_raised",
+ "let",
+ "not_predicate_sql",
+ "test_rename_column_with_sql_reserved_word",
+ "singleton_class",
+ "test_rename_column_with_an_index",
+ "display",
+ "taguri",
+ "to_yaml_style",
+ "test_remove_column_with_index",
+ "size",
+ "current_adapter?",
+ "test_remove_column_with_multi_column_index",
+ "respond_to?",
+ "test_change_type_of_not_null_column",
+ "is_a",
+ "to_a",
+ "test_rename_table_for_sqlite_should_work_with_reserved_words",
+ "require_library_or_gem",
+ "setup_fixtures",
+ "equal?",
+ "teardown_fixtures",
+ "nil?",
+ "fixture_table_names",
+ "fixture_class_names",
+ "test_create_table_without_id",
+ "use_transactional_fixtures",
+ "test_add_column_with_primary_key_attribute",
+ "repair_validations",
+ "use_instantiated_fixtures",
+ "instance_of?",
+ "test_create_table_adds_id",
+ "test_rename_table",
+ "pre_loaded_fixtures",
+ "to_enum",
+ "test_create_table_with_not_null_column",
+ "instance_of",
+ "test_change_column_nullability",
+ "optionally",
+ "test_rename_table_with_an_index",
+ "run",
+ "test_change_column",
+ "default_test",
+ "assert_raise",
+ "test_create_table_with_defaults",
+ "assert_nil",
+ "flunk",
+ "regexp_matches",
+ "duplicable?",
+ "reset_mocha",
+ "stubba_method",
+ "filter_backtrace",
+ "test_create_table_with_limits",
+ "responds_with",
+ "stubba_object",
+ "test_change_column_with_nil_default",
+ "assert_block",
+ "__show__",
+ "assert_date_from_db",
+ "__respond_to_eh__",
+ "run_in_transaction?",
+ "inspect",
+ "assert_sql",
+ "test_change_column_with_new_default",
+ "yaml_equivalent",
+ "build_message",
+ "to_s",
+ "test_change_column_default",
+ "assert_queries",
+ "pending",
+ "as_json",
+ "assert_no_queries",
+ "test_change_column_quotes_column_names",
+ "assert_match",
+ "test_keeping_default_and_notnull_constraint_on_change",
+ "methods",
+ "connection_allow_concurrency_setup",
+ "connection_allow_concurrency_teardown",
+ "test_create_table_with_primary_key_prefix_as_table_name_with_underscore",
+ "__send__",
+ "make_connection",
+ "assert_raises",
+ "tap",
+ "with_kcode",
+ "assert_instance_of",
+ "test_create_table_with_primary_key_prefix_as_table_name",
+ "assert_respond_to",
+ "test_change_column_default_to_null",
+ "assert_same",
+ "__extend__",
+ ]
+
+ LargeTestArraySorted = [
+ "test_add_column_not_null_with_default",
+ "test_add_column_with_precision_and_scale",
+ "test_add_column_with_primary_key_attribute",
+ "test_add_drop_table_with_prefix_and_suffix",
+ "test_add_index",
+ "test_add_remove_single_field_using_string_arguments",
+ "test_add_remove_single_field_using_symbol_arguments",
+ "test_add_rename",
+ "test_add_table",
+ "test_add_table_with_decimals",
+ "test_change_column",
+ "test_change_column_default",
+ "test_change_column_default_to_null",
+ "test_change_column_nullability",
+ "test_change_column_quotes_column_names",
+ "test_change_column_with_new_default",
+ "test_change_column_with_nil_default",
+ "test_change_type_of_not_null_column",
+ "test_create_table_adds_id",
+ "test_create_table_with_binary_column",
+ "test_create_table_with_custom_sequence_name",
+ "test_create_table_with_defaults",
+ "test_create_table_with_force_true_does_not_drop_nonexisting_table",
+ "test_create_table_with_limits",
+ "test_create_table_with_not_null_column",
+ "test_create_table_with_primary_key_prefix_as_table_name",
+ "test_create_table_with_primary_key_prefix_as_table_name_with_underscore",
+ "test_create_table_with_timestamps_should_create_datetime_columns",
+ "test_create_table_with_timestamps_should_create_datetime_columns_with_options",
+ "test_create_table_without_a_block",
+ "test_create_table_without_id",
+ "test_finds_migrations",
+ "test_finds_pending_migrations",
+ "test_keeping_default_and_notnull_constraint_on_change",
+ "test_migrator",
+ "test_migrator_db_has_no_schema_migrations_table",
+ "test_migrator_double_down",
+ "test_migrator_double_up",
+ "test_migrator_forward",
+ "test_migrator_going_down_due_to_version_target",
+ "test_migrator_one_down",
+ "test_migrator_one_up",
+ "test_migrator_one_up_one_down",
+ "test_migrator_one_up_with_exception_and_rollback",
+ "test_migrator_rollback",
+ "test_migrator_verbosity",
+ "test_migrator_verbosity_off",
+ "test_migrator_with_duplicate_names",
+ "test_migrator_with_duplicates",
+ "test_migrator_with_missing_version_numbers",
+ "test_native_decimal_insert_manual_vs_automatic",
+ "test_native_types",
+ "test_only_loads_pending_migrations",
+ "test_proper_table_name",
+ "test_relative_migrations",
+ "test_remove_column_with_index",
+ "test_remove_column_with_multi_column_index",
+ "test_rename_column",
+ "test_rename_column_preserves_default_value_not_null",
+ "test_rename_column_using_symbol_arguments",
+ "test_rename_column_with_an_index",
+ "test_rename_column_with_sql_reserved_word",
+ "test_rename_nonexistent_column",
+ "test_rename_table",
+ "test_rename_table_for_sqlite_should_work_with_reserved_words",
+ "test_rename_table_with_an_index",
+ "test_schema_migrations_table_name",
+ "test_target_version_zero_should_run_only_once",
+ ]
class PrivateToAry
private
diff --git a/spec/ruby/core/array/fixtures/encoded_strings.rb b/spec/ruby/core/array/fixtures/encoded_strings.rb
index e31e247afe..b5888d86ae 100644
--- a/spec/ruby/core/array/fixtures/encoded_strings.rb
+++ b/spec/ruby/core/array/fixtures/encoded_strings.rb
@@ -2,14 +2,14 @@
module ArraySpecs
def self.array_with_usascii_and_7bit_utf8_strings
[
- 'foo'.force_encoding('US-ASCII'),
+ 'foo'.dup.force_encoding('US-ASCII'),
'bar'
]
end
def self.array_with_usascii_and_utf8_strings
[
- 'foo'.force_encoding('US-ASCII'),
+ 'foo'.dup.force_encoding('US-ASCII'),
'báz'
]
end
@@ -17,7 +17,7 @@ module ArraySpecs
def self.array_with_7bit_utf8_and_usascii_strings
[
'bar',
- 'foo'.force_encoding('US-ASCII')
+ 'foo'.dup.force_encoding('US-ASCII')
]
end
@@ -25,45 +25,45 @@ module ArraySpecs
[
'báz',
'bar',
- 'foo'.force_encoding('US-ASCII')
+ 'foo'.dup.force_encoding('US-ASCII')
]
end
def self.array_with_usascii_and_utf8_strings
[
- 'foo'.force_encoding('US-ASCII'),
+ 'foo'.dup.force_encoding('US-ASCII'),
'bar',
'báz'
]
end
- def self.array_with_utf8_and_7bit_ascii8bit_strings
+ def self.array_with_utf8_and_7bit_binary_strings
[
'bar',
'báz',
- 'foo'.force_encoding('ASCII-8BIT')
+ 'foo'.dup.force_encoding('BINARY')
]
end
- def self.array_with_utf8_and_ascii8bit_strings
+ def self.array_with_utf8_and_binary_strings
[
'bar',
'báz',
- [255].pack('C').force_encoding('ASCII-8BIT')
+ [255].pack('C').force_encoding('BINARY')
]
end
- def self.array_with_usascii_and_7bit_ascii8bit_strings
+ def self.array_with_usascii_and_7bit_binary_strings
[
- 'bar'.force_encoding('US-ASCII'),
- 'foo'.force_encoding('ASCII-8BIT')
+ 'bar'.dup.force_encoding('US-ASCII'),
+ 'foo'.dup.force_encoding('BINARY')
]
end
- def self.array_with_usascii_and_ascii8bit_strings
+ def self.array_with_usascii_and_binary_strings
[
- 'bar'.force_encoding('US-ASCII'),
- [255].pack('C').force_encoding('ASCII-8BIT')
+ 'bar'.dup.force_encoding('US-ASCII'),
+ [255].pack('C').force_encoding('BINARY')
]
end
end
diff --git a/spec/ruby/core/array/flatten_spec.rb b/spec/ruby/core/array/flatten_spec.rb
index 3b20e976b6..272406b8f9 100644
--- a/spec/ruby/core/array/flatten_spec.rb
+++ b/spec/ruby/core/array/flatten_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Array#flatten" do
it "returns a one-dimensional flattening recursively" do
@@ -13,7 +13,7 @@ describe "Array#flatten" do
it "returns dup when the level of recursion is 0" do
a = [ 1, 2, [3, [4, 5] ] ]
a.flatten(0).should == a
- a.flatten(0).should_not equal(a)
+ a.flatten(0).should_not.equal?(a)
end
it "ignores negative levels" do
@@ -30,7 +30,7 @@ describe "Array#flatten" do
it "raises a TypeError when the passed Object can't be converted to an Integer" do
obj = mock("Not converted")
- lambda { [ 1, 2, [3, [4, 5] ] ].flatten(obj) }.should raise_error(TypeError)
+ -> { [ 1, 2, [3, [4, 5] ] ].flatten(obj) }.should.raise(TypeError)
end
it "does not call flatten on elements" do
@@ -46,13 +46,13 @@ describe "Array#flatten" do
it "raises an ArgumentError on recursive arrays" do
x = []
x << x
- lambda { x.flatten }.should raise_error(ArgumentError)
+ -> { x.flatten }.should.raise(ArgumentError)
x = []
y = []
x << y
y << x
- lambda { x.flatten }.should raise_error(ArgumentError)
+ -> { x.flatten }.should.raise(ArgumentError)
end
it "flattens any element which responds to #to_ary, using the return value of said method" do
@@ -69,20 +69,18 @@ describe "Array#flatten" do
[1, z, 6].flatten.should == [1, 2, 3, 4, 5, 6]
end
- ruby_version_is "2.3" do
- it "does not call #to_ary on elements beyond the given level" do
- obj = mock("1")
- obj.should_not_receive(:to_ary)
- [[obj]].flatten(1)
- end
+ it "does not call #to_ary on elements beyond the given level" do
+ obj = mock("1")
+ obj.should_not_receive(:to_ary)
+ [[obj]].flatten(1)
end
- it "returns subclass instance for Array subclasses" do
- ArraySpecs::MyArray[].flatten.should be_an_instance_of(ArraySpecs::MyArray)
- ArraySpecs::MyArray[1, 2, 3].flatten.should be_an_instance_of(ArraySpecs::MyArray)
- ArraySpecs::MyArray[1, [2], 3].flatten.should be_an_instance_of(ArraySpecs::MyArray)
- ArraySpecs::MyArray[1, [2, 3], 4].flatten.should == ArraySpecs::MyArray[1, 2, 3, 4]
- [ArraySpecs::MyArray[1, 2, 3]].flatten.should be_an_instance_of(Array)
+ it "returns Array instance for Array subclasses" do
+ ArraySpecs::MyArray[].flatten.should.instance_of?(Array)
+ ArraySpecs::MyArray[1, 2, 3].flatten.should.instance_of?(Array)
+ ArraySpecs::MyArray[1, [2], 3].flatten.should.instance_of?(Array)
+ ArraySpecs::MyArray[1, [2, 3], 4].flatten.should == [1, 2, 3, 4]
+ [ArraySpecs::MyArray[1, 2, 3]].flatten.should.instance_of?(Array)
end
it "is not destructive" do
@@ -108,23 +106,13 @@ describe "Array#flatten" do
it "raises a TypeError if #to_ary does not return an Array" do
@obj.should_receive(:to_ary).and_return(1)
- lambda { [@obj].flatten }.should raise_error(TypeError)
- end
-
- ruby_version_is ""..."2.5" do
- it "calls respond_to_missing?(:to_ary, false) to try coercing" do
- def @obj.respond_to_missing?(*args) ScratchPad << args; false end
- [@obj].flatten.should == [@obj]
- ScratchPad.recorded.should == [[:to_ary, false]]
- end
+ -> { [@obj].flatten }.should.raise(TypeError)
end
- ruby_version_is "2.5" do
- it "calls respond_to_missing?(:to_ary, true) to try coercing" do
- def @obj.respond_to_missing?(*args) ScratchPad << args; false end
- [@obj].flatten.should == [@obj]
- ScratchPad.recorded.should == [[:to_ary, true]]
- end
+ it "calls respond_to_missing?(:to_ary, true) to try coercing" do
+ def @obj.respond_to_missing?(*args) ScratchPad << args; false end
+ [@obj].flatten.should == [@obj]
+ ScratchPad.recorded.should == [[:to_ary, true]]
end
it "does not call #to_ary if not defined when #respond_to_missing? returns false" do
@@ -137,7 +125,7 @@ describe "Array#flatten" do
it "calls #to_ary if not defined when #respond_to_missing? returns true" do
def @obj.respond_to_missing?(name, priv) ScratchPad << name; true end
- lambda { [@obj].flatten }.should raise_error(NoMethodError)
+ -> { [@obj].flatten }.should.raise(NoMethodError)
ScratchPad.recorded.should == [:to_ary]
end
@@ -147,14 +135,6 @@ describe "Array#flatten" do
end
end
- it "returns a tainted array if self is tainted" do
- [].taint.flatten.tainted?.should be_true
- end
-
- it "returns an untrusted array if self is untrusted" do
- [].untrust.flatten.untrusted?.should be_true
- end
-
it "performs respond_to? and method_missing-aware checks when coercing elements to array" do
bo = BasicObject.new
[bo].flatten.should == [bo]
@@ -188,7 +168,7 @@ describe "Array#flatten!" do
it "returns self if made some modifications" do
a = [[[1, [2, 3]],[2, 3, [4, [4, [5, 5]], [1, 2, 3]]], [4]], []]
- a.flatten!.should equal(a)
+ a.flatten!.should.equal?(a)
end
it "returns nil if no modifications took place" do
@@ -228,7 +208,7 @@ describe "Array#flatten!" do
it "raises a TypeError when the passed Object can't be converted to an Integer" do
obj = mock("Not converted")
- lambda { [ 1, 2, [3, [4, 5] ] ].flatten!(obj) }.should raise_error(TypeError)
+ -> { [ 1, 2, [3, [4, 5] ] ].flatten!(obj) }.should.raise(TypeError)
end
it "does not call flatten! on elements" do
@@ -244,13 +224,13 @@ describe "Array#flatten!" do
it "raises an ArgumentError on recursive arrays" do
x = []
x << x
- lambda { x.flatten! }.should raise_error(ArgumentError)
+ -> { x.flatten! }.should.raise(ArgumentError)
x = []
y = []
x << y
y << x
- lambda { x.flatten! }.should raise_error(ArgumentError)
+ -> { x.flatten! }.should.raise(ArgumentError)
end
it "flattens any elements which responds to #to_ary, using the return value of said method" do
@@ -268,19 +248,19 @@ describe "Array#flatten!" do
ary = [ArraySpecs::MyArray[1, 2, 3]]
ary.flatten!
- ary.should be_an_instance_of(Array)
+ ary.should.instance_of?(Array)
ary.should == [1, 2, 3]
end
- it "raises a RuntimeError on frozen arrays when the array is modified" do
+ it "raises a FrozenError on frozen arrays when the array is modified" do
nested_ary = [1, 2, []]
nested_ary.freeze
- lambda { nested_ary.flatten! }.should raise_error(RuntimeError)
+ -> { nested_ary.flatten! }.should.raise(FrozenError)
end
# see [ruby-core:23663]
- it "raises a RuntimeError on frozen arrays when the array would not be modified" do
- lambda { ArraySpecs.frozen_array.flatten! }.should raise_error(RuntimeError)
- lambda { ArraySpecs.empty_frozen_array.flatten! }.should raise_error(RuntimeError)
+ it "raises a FrozenError on frozen arrays when the array would not be modified" do
+ -> { ArraySpecs.frozen_array.flatten! }.should.raise(FrozenError)
+ -> { ArraySpecs.empty_frozen_array.flatten! }.should.raise(FrozenError)
end
end
diff --git a/spec/ruby/core/array/frozen_spec.rb b/spec/ruby/core/array/frozen_spec.rb
index 6c8384f5f7..3ba54be46b 100644
--- a/spec/ruby/core/array/frozen_spec.rb
+++ b/spec/ruby/core/array/frozen_spec.rb
@@ -1,16 +1,16 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Array#frozen?" do
it "returns true if array is frozen" do
a = [1, 2, 3]
- a.frozen?.should == false
+ a.should_not.frozen?
a.freeze
- a.frozen?.should == true
+ a.should.frozen?
end
it "returns false for an array being sorted by #sort" do
a = [1, 2, 3]
- a.sort { |x,y| a.frozen?.should == false; x <=> y }
+ a.sort { |x,y| a.should_not.frozen?; x <=> y }
end
end
diff --git a/spec/ruby/core/array/hash_spec.rb b/spec/ruby/core/array/hash_spec.rb
index b576cbbdc6..3b7b6d5bed 100644
--- a/spec/ruby/core/array/hash_spec.rb
+++ b/spec/ruby/core/array/hash_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Array#hash" do
it "returns the same fixnum for arrays with the same content" do
@@ -7,16 +7,16 @@ describe "Array#hash" do
[[], [1, 2, 3]].each do |ary|
ary.hash.should == ary.dup.hash
- ary.hash.should be_an_instance_of(Fixnum)
+ ary.hash.should.instance_of?(Integer)
end
end
it "properly handles recursive arrays" do
empty = ArraySpecs.empty_recursive_array
- lambda { empty.hash }.should_not raise_error
+ -> { empty.hash }.should_not.raise
array = ArraySpecs.recursive_array
- lambda { array.hash }.should_not raise_error
+ -> { array.hash }.should_not.raise
end
it "returns the same hash for equal recursive arrays" do
@@ -74,7 +74,7 @@ describe "Array#hash" do
a.fill 'a', 0..3
b = %w|a a a a|
a.hash.should == b.hash
- a.should eql(b)
+ a.should.eql?(b)
end
it "produces different hashes for nested arrays with different values and empty terminator" do
diff --git a/spec/ruby/core/array/include_spec.rb b/spec/ruby/core/array/include_spec.rb
index 26d788afeb..227173218f 100644
--- a/spec/ruby/core/array/include_spec.rb
+++ b/spec/ruby/core/array/include_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Array#include?" do
it "returns true if object is present, false otherwise" do
diff --git a/spec/ruby/core/array/index_spec.rb b/spec/ruby/core/array/index_spec.rb
index 55ed7b2a94..b66cb6eb53 100644
--- a/spec/ruby/core/array/index_spec.rb
+++ b/spec/ruby/core/array/index_spec.rb
@@ -1,6 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/index', __FILE__)
+require_relative '../../spec_helper'
describe "Array#index" do
- it_behaves_like(:array_index, :index)
+ it "is an alias of Array#find_index" do
+ Array.instance_method(:index).should == Array.instance_method(:find_index)
+ end
end
diff --git a/spec/ruby/core/array/initialize_spec.rb b/spec/ruby/core/array/initialize_spec.rb
index 0c37c6136d..19ee37825e 100644
--- a/spec/ruby/core/array/initialize_spec.rb
+++ b/spec/ruby/core/array/initialize_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Array#initialize" do
before :each do
@@ -7,7 +7,7 @@ describe "Array#initialize" do
end
it "is private" do
- Array.should have_private_instance_method("initialize")
+ Array.private_instance_methods(false).should.include?(:initialize)
end
it "is called on subclasses" do
@@ -19,26 +19,26 @@ describe "Array#initialize" do
it "preserves the object's identity even when changing its value" do
a = [1, 2, 3]
- a.send(:initialize).should equal(a)
+ a.send(:initialize).should.equal?(a)
a.should_not == [1, 2, 3]
end
it "raises an ArgumentError if passed 3 or more arguments" do
- lambda do
+ -> do
[1, 2].send :initialize, 1, 'x', true
- end.should raise_error(ArgumentError)
- lambda do
+ end.should.raise(ArgumentError)
+ -> do
[1, 2].send(:initialize, 1, 'x', true) {}
- end.should raise_error(ArgumentError)
+ end.should.raise(ArgumentError)
end
- it "raises a RuntimeError on frozen arrays" do
- lambda do
+ it "raises a FrozenError on frozen arrays" do
+ -> do
ArraySpecs.frozen_array.send :initialize
- end.should raise_error(RuntimeError)
- lambda do
+ end.should.raise(FrozenError)
+ -> do
ArraySpecs.frozen_array.send :initialize, ArraySpecs.frozen_array
- end.should raise_error(RuntimeError)
+ end.should.raise(FrozenError)
end
it "calls #to_ary to convert the value to an array, even if it's private" do
@@ -49,11 +49,13 @@ end
describe "Array#initialize with no arguments" do
it "makes the array empty" do
- [1, 2, 3].send(:initialize).should be_empty
+ [1, 2, 3].send(:initialize).should.empty?
end
it "does not use the given block" do
- lambda{ [1, 2, 3].send(:initialize) { raise } }.should_not raise_error
+ -> {
+ -> { [1, 2, 3].send(:initialize) { raise } }.should_not.raise
+ }.should complain(/#{__FILE__}:#{__LINE__-1}: warning: given block not used/, verbose: true)
end
end
@@ -64,7 +66,7 @@ describe "Array#initialize with (array)" do
end
it "does not use the given block" do
- lambda{ [1, 2, 3].send(:initialize) { raise } }.should_not raise_error
+ ->{ [1, 2, 3].send(:initialize) { raise } }.should_not.raise
end
it "calls #to_ary to convert the value to an array" do
@@ -81,7 +83,7 @@ describe "Array#initialize with (array)" do
end
it "raises a TypeError if an Array type argument and a default object" do
- lambda { [].send(:initialize, [1, 2], 1) }.should raise_error(TypeError)
+ -> { [].send(:initialize, [1, 2], 1) }.should.raise(TypeError)
end
end
@@ -90,8 +92,8 @@ describe "Array#initialize with (size, object=nil)" do
a = []
obj = [3]
a.send(:initialize, 2, obj).should == [obj, obj]
- a[0].should equal(obj)
- a[1].should equal(obj)
+ a[0].should.equal?(obj)
+ a[1].should.equal?(obj)
b = []
b.send(:initialize, 3, 14).should == [14, 14, 14]
@@ -103,12 +105,12 @@ describe "Array#initialize with (size, object=nil)" do
end
it "raises an ArgumentError if size is negative" do
- lambda { [].send(:initialize, -1, :a) }.should raise_error(ArgumentError)
- lambda { [].send(:initialize, -1) }.should raise_error(ArgumentError)
+ -> { [].send(:initialize, -1, :a) }.should.raise(ArgumentError)
+ -> { [].send(:initialize, -1) }.should.raise(ArgumentError)
end
it "raises an ArgumentError if size is too large" do
- lambda { [].send(:initialize, fixnum_max+1) }.should raise_error(ArgumentError)
+ -> { [].send(:initialize, fixnum_max+1) }.should.raise(ArgumentError)
end
it "calls #to_int to convert the size argument to an Integer when object is given" do
@@ -126,7 +128,7 @@ describe "Array#initialize with (size, object=nil)" do
it "raises a TypeError if the size argument is not an Integer type" do
obj = mock('nonnumeric')
obj.stub!(:to_ary).and_return([1, 2])
- lambda{ [].send(:initialize, obj, :a) }.should raise_error(TypeError)
+ ->{ [].send(:initialize, obj, :a) }.should.raise(TypeError)
end
it "yields the index of the element and sets the element to the value of the block" do
@@ -134,7 +136,7 @@ describe "Array#initialize with (size, object=nil)" do
end
it "uses the block value instead of using the default value" do
- lambda {
+ -> {
@result = [].send(:initialize, 3, :obj) { |i| i.to_s }
}.should complain(/block supersedes default value argument/)
@result.should == ['0', '1', '2']
diff --git a/spec/ruby/core/array/insert_spec.rb b/spec/ruby/core/array/insert_spec.rb
index cdf870df2a..38e132fd25 100644
--- a/spec/ruby/core/array/insert_spec.rb
+++ b/spec/ruby/core/array/insert_spec.rb
@@ -1,11 +1,11 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Array#insert" do
it "returns self" do
ary = []
- ary.insert(0).should equal(ary)
- ary.insert(0, :a).should equal(ary)
+ ary.insert(0).should.equal?(ary)
+ ary.insert(0, :a).should.equal?(ary)
end
it "inserts objects before the element at index for non-negative index" do
@@ -46,8 +46,8 @@ describe "Array#insert" do
end
it "raises an IndexError if the negative index is out of bounds" do
- lambda { [].insert(-2, 1) }.should raise_error(IndexError)
- lambda { [1].insert(-3, 2) }.should raise_error(IndexError)
+ -> { [].insert(-2, 1) }.should.raise(IndexError)
+ -> { [1].insert(-3, 2) }.should.raise(IndexError)
end
it "does nothing of no object is passed" do
@@ -64,15 +64,15 @@ describe "Array#insert" do
end
it "raises an ArgumentError if no argument passed" do
- lambda { [].insert() }.should raise_error(ArgumentError)
+ -> { [].insert() }.should.raise(ArgumentError)
end
- it "raises a RuntimeError on frozen arrays when the array is modified" do
- lambda { ArraySpecs.frozen_array.insert(0, 'x') }.should raise_error(RuntimeError)
+ it "raises a FrozenError on frozen arrays when the array is modified" do
+ -> { ArraySpecs.frozen_array.insert(0, 'x') }.should.raise(FrozenError)
end
# see [ruby-core:23666]
- it "raises a RuntimeError on frozen arrays when the array would not be modified" do
- lambda { ArraySpecs.frozen_array.insert(0) }.should raise_error(RuntimeError)
+ it "raises a FrozenError on frozen arrays when the array would not be modified" do
+ -> { ArraySpecs.frozen_array.insert(0) }.should.raise(FrozenError)
end
end
diff --git a/spec/ruby/core/array/inspect_spec.rb b/spec/ruby/core/array/inspect_spec.rb
index 9896406fd5..e5dca82889 100644
--- a/spec/ruby/core/array/inspect_spec.rb
+++ b/spec/ruby/core/array/inspect_spec.rb
@@ -1,7 +1,108 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/inspect', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Array#inspect" do
- it_behaves_like :array_inspect, :inspect
+ it "returns a string" do
+ [1, 2, 3].inspect.should.instance_of?(String)
+ end
+
+ it "returns '[]' for an empty Array" do
+ [].inspect.should == "[]"
+ end
+
+ it "calls inspect on its elements and joins the results with commas" do
+ items = Array.new(3) do |i|
+ obj = mock(i.to_s)
+ obj.should_receive(:inspect).and_return(i.to_s)
+ obj
+ end
+ items.inspect.should == "[0, 1, 2]"
+ end
+
+ it "does not call #to_s on a String returned from #inspect" do
+ str = +"abc"
+ str.should_not_receive(:to_s)
+
+ [str].inspect.should == '["abc"]'
+ end
+
+ it "calls #to_s on the object returned from #inspect if the Object isn't a String" do
+ obj = mock("Array#inspect/to_s calls #to_s")
+ obj.should_receive(:inspect).and_return(obj)
+ obj.should_receive(:to_s).and_return("abc")
+
+ [obj].inspect.should == "[abc]"
+ end
+
+ it "does not call #to_str on the object returned from #inspect when it is not a String" do
+ obj = mock("Array#inspect/to_s does not call #to_str")
+ obj.should_receive(:inspect).and_return(obj)
+ obj.should_not_receive(:to_str)
+
+ [obj].inspect.should =~ /^\[#<MockObject:0x[0-9a-f]+>\]$/
+ end
+
+ it "does not call #to_str on the object returned from #to_s when it is not a String" do
+ obj = mock("Array#inspect/to_s does not call #to_str on #to_s result")
+ obj.should_receive(:inspect).and_return(obj)
+ obj.should_receive(:to_s).and_return(obj)
+ obj.should_not_receive(:to_str)
+
+ [obj].inspect.should =~ /^\[#<MockObject:0x[0-9a-f]+>\]$/
+ end
+
+ it "does not swallow exceptions raised by #to_s" do
+ obj = mock("Array#inspect/to_s does not swallow #to_s exceptions")
+ obj.should_receive(:inspect).and_return(obj)
+ obj.should_receive(:to_s).and_raise(Exception)
+
+ -> { [obj].inspect }.should.raise(Exception)
+ end
+
+ it "represents a recursive element with '[...]'" do
+ ArraySpecs.recursive_array.inspect.should == "[1, \"two\", 3.0, [...], [...], [...], [...], [...]]"
+ ArraySpecs.head_recursive_array.inspect.should == "[[...], [...], [...], [...], [...], 1, \"two\", 3.0]"
+ ArraySpecs.empty_recursive_array.inspect.should == "[[...]]"
+ end
+
+ describe "with encoding" do
+ before :each do
+ @default_external_encoding = Encoding.default_external
+ end
+
+ after :each do
+ Encoding.default_external = @default_external_encoding
+ end
+
+ it "returns a US-ASCII string for an empty Array" do
+ [].inspect.encoding.should == Encoding::US_ASCII
+ end
+
+ it "use the default external encoding if it is ascii compatible" do
+ Encoding.default_external = Encoding.find('UTF-8')
+
+ utf8 = "utf8".encode("UTF-8")
+ jp = "jp".encode("EUC-JP")
+ array = [jp, utf8]
+
+ array.inspect.encoding.name.should == "UTF-8"
+ end
+
+ it "use US-ASCII encoding if the default external encoding is not ascii compatible" do
+ Encoding.default_external = Encoding.find('UTF-32')
+
+ utf8 = "utf8".encode("UTF-8")
+ jp = "jp".encode("EUC-JP")
+ array = [jp, utf8]
+
+ array.inspect.encoding.name.should == "US-ASCII"
+ end
+
+ it "does not raise if inspected result is not default external encoding" do
+ utf_16be = mock(+"utf_16be")
+ utf_16be.should_receive(:inspect).and_return(%<"utf_16be \u3042">.encode(Encoding::UTF_16BE))
+
+ [utf_16be].inspect.should == '["utf_16be \u3042"]'
+ end
+ end
end
diff --git a/spec/ruby/core/array/intersect_spec.rb b/spec/ruby/core/array/intersect_spec.rb
new file mode 100644
index 0000000000..456aa26c6e
--- /dev/null
+++ b/spec/ruby/core/array/intersect_spec.rb
@@ -0,0 +1,64 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe 'Array#intersect?' do
+ describe 'when at least one element in two Arrays is the same' do
+ it 'returns true' do
+ [1, 2].intersect?([2, 3, 4]).should == true
+ [2, 3, 4].intersect?([1, 2]).should == true
+ end
+ end
+
+ describe 'when there are no elements in common between two Arrays' do
+ it 'returns false' do
+ [0, 1, 2].intersect?([3, 4]).should == false
+ [3, 4].intersect?([0, 1, 2]).should == false
+ [3, 4].intersect?([]).should == false
+ [].intersect?([0, 1, 2]).should == false
+ end
+ end
+
+ it "tries to convert the passed argument to an Array using #to_ary" do
+ obj = mock('[1,2,3]')
+ obj.should_receive(:to_ary).and_return([1, 2, 3])
+
+ [1, 2].intersect?(obj).should == true
+ end
+
+ it "determines equivalence between elements in the sense of eql?" do
+ obj1 = mock('1')
+ obj2 = mock('2')
+ obj1.stub!(:hash).and_return(0)
+ obj2.stub!(:hash).and_return(0)
+ obj1.stub!(:eql?).and_return(true)
+ obj2.stub!(:eql?).and_return(true)
+
+ [obj1].intersect?([obj2]).should == true
+
+ obj1 = mock('3')
+ obj2 = mock('4')
+ obj1.stub!(:hash).and_return(0)
+ obj2.stub!(:hash).and_return(0)
+ obj1.stub!(:eql?).and_return(false)
+ obj2.stub!(:eql?).and_return(false)
+
+ [obj1].intersect?([obj2]).should == false
+ end
+
+ it "does not call to_ary on array subclasses" do
+ [5, 6].intersect?(ArraySpecs::ToAryArray[1, 2, 5, 6]).should == true
+ end
+
+ it "properly handles an identical item even when its #eql? isn't reflexive" do
+ x = mock('x')
+ x.stub!(:hash).and_return(42)
+ x.stub!(:eql?).and_return(false) # Stubbed for clarity and latitude in implementation; not actually sent by MRI.
+
+ [x].intersect?([x]).should == true
+ end
+
+ it "has semantic of !(a & b).empty?" do
+ [].intersect?([]).should == false
+ [nil].intersect?([nil]).should == true
+ end
+end
diff --git a/spec/ruby/core/array/intersection_spec.rb b/spec/ruby/core/array/intersection_spec.rb
index e399509ea7..e01a68d389 100644
--- a/spec/ruby/core/array/intersection_spec.rb
+++ b/spec/ruby/core/array/intersection_spec.rb
@@ -1,87 +1,19 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/intersection'
describe "Array#&" do
- it "creates an array with elements common to both arrays (intersection)" do
- ([] & []).should == []
- ([1, 2] & []).should == []
- ([] & [1, 2]).should == []
- ([ 1, 3, 5 ] & [ 1, 2, 3 ]).should == [1, 3]
- end
-
- it "creates an array with no duplicates" do
- ([ 1, 1, 3, 5 ] & [ 1, 2, 3 ]).uniq!.should == nil
- end
-
- it "creates an array with elements in order they are first encountered" do
- ([ 1, 2, 3, 2, 5 ] & [ 5, 2, 3, 4 ]).should == [2, 3, 5]
- end
-
- it "does not modify the original Array" do
- a = [1, 1, 3, 5]
- (a & [1, 2, 3]).should == [1, 3]
- a.should == [1, 1, 3, 5]
- end
-
- it "properly handles recursive arrays" do
- empty = ArraySpecs.empty_recursive_array
- (empty & empty).should == empty
-
- (ArraySpecs.recursive_array & []).should == []
- ([] & ArraySpecs.recursive_array).should == []
-
- (ArraySpecs.recursive_array & ArraySpecs.recursive_array).should == [1, 'two', 3.0, ArraySpecs.recursive_array]
- end
-
- it "tries to convert the passed argument to an Array using #to_ary" do
- obj = mock('[1,2,3]')
- obj.should_receive(:to_ary).and_return([1, 2, 3])
- ([1, 2] & obj).should == ([1, 2])
- end
-
- it "determines equivalence between elements in the sense of eql?" do
- not_supported_on :opal do
- ([5.0, 4.0] & [5, 4]).should == []
- end
-
- str = "x"
- ([str] & [str.dup]).should == [str]
-
- obj1 = mock('1')
- obj2 = mock('2')
- obj1.stub!(:hash).and_return(0)
- obj2.stub!(:hash).and_return(0)
- obj1.should_receive(:eql?).at_least(1).and_return(true)
- obj2.stub!(:eql?).and_return(true)
-
- ([obj1] & [obj2]).should == [obj1]
- ([obj1, obj1, obj2, obj2] & [obj2]).should == [obj1]
-
- obj1 = mock('3')
- obj2 = mock('4')
- obj1.stub!(:hash).and_return(0)
- obj2.stub!(:hash).and_return(0)
- obj1.should_receive(:eql?).at_least(1).and_return(false)
+ it_behaves_like :array_intersection, :&
+end
- ([obj1] & [obj2]).should == []
- ([obj1, obj1, obj2, obj2] & [obj2]).should == [obj2]
- end
+describe "Array#intersection" do
+ it_behaves_like :array_intersection, :intersection
- it "does return subclass instances for Array subclasses" do
- (ArraySpecs::MyArray[1, 2, 3] & []).should be_an_instance_of(Array)
- (ArraySpecs::MyArray[1, 2, 3] & ArraySpecs::MyArray[1, 2, 3]).should be_an_instance_of(Array)
- ([] & ArraySpecs::MyArray[1, 2, 3]).should be_an_instance_of(Array)
+ it "accepts multiple arguments" do
+ [1, 2, 3, 4].intersection([1, 2, 3], [2, 3, 4]).should == [2, 3]
end
- it "does not call to_ary on array subclasses" do
- ([5, 6] & ArraySpecs::ToAryArray[1, 2, 5, 6]).should == [5, 6]
- end
-
- it "properly handles an identical item even when its #eql? isn't reflexive" do
- x = mock('x')
- x.stub!(:hash).and_return(42)
- x.stub!(:eql?).and_return(false) # Stubbed for clarity and latitude in implementation; not actually sent by MRI.
-
- ([x] & [x]).should == [x]
+ it "preserves elements order from original array" do
+ [1, 2, 3, 4].intersection([3, 2, 1]).should == [1, 2, 3]
end
end
diff --git a/spec/ruby/core/array/join_spec.rb b/spec/ruby/core/array/join_spec.rb
index c4c6277c87..3b4946a99f 100644
--- a/spec/ruby/core/array/join_spec.rb
+++ b/spec/ruby/core/array/join_spec.rb
@@ -1,10 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/join', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/join'
describe "Array#join" do
it_behaves_like :array_join_with_string_separator, :join
- it_behaves_like :array_join_with_default_separator, :join
it "does not separate elements when the passed separator is nil" do
[1, 2, 3].join(nil).should == '123'
@@ -24,11 +23,108 @@ describe "Array#join" do
it "raises a TypeError if the separator cannot be coerced to a String by calling #to_str" do
obj = mock("not a string")
- lambda { [1, 2].join(obj) }.should raise_error(TypeError)
+ -> { [1, 2].join(obj) }.should.raise(TypeError)
end
it "raises a TypeError if passed false as the separator" do
- lambda { [1, 2].join(false) }.should raise_error(TypeError)
+ -> { [1, 2].join(false) }.should.raise(TypeError)
+ end
+end
+
+describe "Array#join with default separator" do
+ before :each do
+ @separator = $,
+ end
+
+ after :each do
+ $, = @separator
+ end
+
+ it "returns an empty string if the Array is empty" do
+ [].join.should == ''
+ end
+
+ it "returns a US-ASCII string for an empty Array" do
+ [].join.encoding.should == Encoding::US_ASCII
+ end
+
+ it "returns a string formed by concatenating each String element separated by $," do
+ suppress_warning {
+ $, = " | "
+ ["1", "2", "3"].join.should == "1 | 2 | 3"
+ }
+ end
+
+ it "attempts coercion via #to_str first" do
+ obj = mock('foo')
+ obj.should_receive(:to_str).any_number_of_times.and_return("foo")
+ [obj].join.should == "foo"
+ end
+
+ it "attempts coercion via #to_ary second" do
+ obj = mock('foo')
+ obj.should_receive(:to_str).any_number_of_times.and_return(nil)
+ obj.should_receive(:to_ary).any_number_of_times.and_return(["foo"])
+ [obj].join.should == "foo"
+ end
+
+ it "attempts coercion via #to_s third" do
+ obj = mock('foo')
+ obj.should_receive(:to_str).any_number_of_times.and_return(nil)
+ obj.should_receive(:to_ary).any_number_of_times.and_return(nil)
+ obj.should_receive(:to_s).any_number_of_times.and_return("foo")
+ [obj].join.should == "foo"
+ end
+
+ it "raises a NoMethodError if an element does not respond to #to_str, #to_ary, or #to_s" do
+ obj = mock('o')
+ class << obj; undef :to_s; end
+ -> { [1, obj].join }.should.raise(NoMethodError)
+ end
+
+ it "raises an ArgumentError when the Array is recursive" do
+ -> { ArraySpecs.recursive_array.join }.should.raise(ArgumentError)
+ -> { ArraySpecs.head_recursive_array.join }.should.raise(ArgumentError)
+ -> { ArraySpecs.empty_recursive_array.join }.should.raise(ArgumentError)
+ end
+
+ it "uses the first encoding when other strings are compatible" do
+ ary1 = ArraySpecs.array_with_7bit_utf8_and_usascii_strings
+ ary2 = ArraySpecs.array_with_usascii_and_7bit_utf8_strings
+ ary3 = ArraySpecs.array_with_utf8_and_7bit_binary_strings
+ ary4 = ArraySpecs.array_with_usascii_and_7bit_binary_strings
+
+ ary1.join.encoding.should == Encoding::UTF_8
+ ary2.join.encoding.should == Encoding::US_ASCII
+ ary3.join.encoding.should == Encoding::UTF_8
+ ary4.join.encoding.should == Encoding::US_ASCII
+ end
+
+ it "uses the widest common encoding when other strings are incompatible" do
+ ary1 = ArraySpecs.array_with_utf8_and_usascii_strings
+ ary2 = ArraySpecs.array_with_usascii_and_utf8_strings
+
+ ary1.join.encoding.should == Encoding::UTF_8
+ ary2.join.encoding.should == Encoding::UTF_8
+ end
+
+ it "fails for arrays with incompatibly-encoded strings" do
+ ary_utf8_bad_binary = ArraySpecs.array_with_utf8_and_binary_strings
+
+ -> { ary_utf8_bad_binary.join }.should.raise(EncodingError)
+ end
+
+ context "when $, is not nil" do
+ before do
+ suppress_warning do
+ $, = '*'
+ end
+ end
+
+ it "warns" do
+ -> { [].join }.should complain(/warning: \$, is set to non-nil value/)
+ -> { [].join(nil) }.should complain(/warning: \$, is set to non-nil value/)
+ end
end
end
@@ -38,11 +134,13 @@ describe "Array#join with $," do
end
after :each do
- $, = @before_separator
+ suppress_warning {$, = @before_separator}
end
it "separates elements with default separator when the passed separator is nil" do
- $, = "_"
- [1, 2, 3].join(nil).should == '1_2_3'
+ suppress_warning {
+ $, = "_"
+ [1, 2, 3].join(nil).should == '1_2_3'
+ }
end
end
diff --git a/spec/ruby/core/array/keep_if_spec.rb b/spec/ruby/core/array/keep_if_spec.rb
index 2657d5e3b6..62a65a04e8 100644
--- a/spec/ruby/core/array/keep_if_spec.rb
+++ b/spec/ruby/core/array/keep_if_spec.rb
@@ -1,9 +1,10 @@
-require File.expand_path('../shared/keep_if', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/keep_if'
describe "Array#keep_if" do
it "returns the same array if no changes were made" do
array = [1, 2, 3]
- array.keep_if { true }.should equal(array)
+ array.keep_if { true }.should.equal?(array)
end
it_behaves_like :keep_if, :keep_if
diff --git a/spec/ruby/core/array/last_spec.rb b/spec/ruby/core/array/last_spec.rb
index c707e3ff7e..ed417bcd2a 100644
--- a/spec/ruby/core/array/last_spec.rb
+++ b/spec/ruby/core/array/last_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Array#last" do
it "returns the last element" do
@@ -28,7 +28,7 @@ describe "Array#last" do
end
it "raises an ArgumentError when count is negative" do
- lambda { [1, 2].last(-1) }.should raise_error(ArgumentError)
+ -> { [1, 2].last(-1) }.should.raise(ArgumentError)
end
it "returns the entire array when count > length" do
@@ -47,32 +47,32 @@ describe "Array#last" do
it "properly handles recursive arrays" do
empty = ArraySpecs.empty_recursive_array
- empty.last.should equal(empty)
+ empty.last.should.equal?(empty)
array = ArraySpecs.recursive_array
- array.last.should equal(array)
+ array.last.should.equal?(array)
end
- it "tries to convert the passed argument to an Integer usinig #to_int" do
+ it "tries to convert the passed argument to an Integer using #to_int" do
obj = mock('to_int')
obj.should_receive(:to_int).and_return(2)
[1, 2, 3, 4, 5].last(obj).should == [4, 5]
end
it "raises a TypeError if the passed argument is not numeric" do
- lambda { [1,2].last(nil) }.should raise_error(TypeError)
- lambda { [1,2].last("a") }.should raise_error(TypeError)
+ -> { [1,2].last(nil) }.should.raise(TypeError)
+ -> { [1,2].last("a") }.should.raise(TypeError)
obj = mock("nonnumeric")
- lambda { [1,2].last(obj) }.should raise_error(TypeError)
+ -> { [1,2].last(obj) }.should.raise(TypeError)
end
it "does not return subclass instance on Array subclasses" do
- ArraySpecs::MyArray[].last(0).should be_an_instance_of(Array)
- ArraySpecs::MyArray[].last(2).should be_an_instance_of(Array)
- ArraySpecs::MyArray[1, 2, 3].last(0).should be_an_instance_of(Array)
- ArraySpecs::MyArray[1, 2, 3].last(1).should be_an_instance_of(Array)
- ArraySpecs::MyArray[1, 2, 3].last(2).should be_an_instance_of(Array)
+ ArraySpecs::MyArray[].last(0).should.instance_of?(Array)
+ ArraySpecs::MyArray[].last(2).should.instance_of?(Array)
+ ArraySpecs::MyArray[1, 2, 3].last(0).should.instance_of?(Array)
+ ArraySpecs::MyArray[1, 2, 3].last(1).should.instance_of?(Array)
+ ArraySpecs::MyArray[1, 2, 3].last(2).should.instance_of?(Array)
end
it "is not destructive" do
diff --git a/spec/ruby/core/array/length_spec.rb b/spec/ruby/core/array/length_spec.rb
index 6f4469dda5..e45abb2138 100644
--- a/spec/ruby/core/array/length_spec.rb
+++ b/spec/ruby/core/array/length_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/length', __FILE__)
+require_relative '../../spec_helper'
describe "Array#length" do
- it_behaves_like(:array_length, :length)
+ it "is an alias of Array#size" do
+ Array.instance_method(:length).should == Array.instance_method(:size)
+ end
end
diff --git a/spec/ruby/core/array/map_spec.rb b/spec/ruby/core/array/map_spec.rb
index c23bb4241a..0cc394663a 100644
--- a/spec/ruby/core/array/map_spec.rb
+++ b/spec/ruby/core/array/map_spec.rb
@@ -1,11 +1,143 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/collect', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative '../enumerable/shared/enumeratorized'
+require_relative 'shared/iterable_and_tolerating_size_increasing'
describe "Array#map" do
- it_behaves_like(:array_collect, :map)
+ it "returns a copy of array with each element replaced by the value returned by block" do
+ a = ['a', 'b', 'c', 'd']
+ b = a.map { |i| i + '!' }
+ b.should == ["a!", "b!", "c!", "d!"]
+ b.should_not.equal? a
+ end
+
+ it "does not return subclass instance" do
+ ArraySpecs::MyArray[1, 2, 3].map { |x| x + 1 }.should.instance_of?(Array)
+ end
+
+ it "does not change self" do
+ a = ['a', 'b', 'c', 'd']
+ a.map { |i| i + '!' }
+ a.should == ['a', 'b', 'c', 'd']
+ end
+
+ it "returns the evaluated value of block if it broke in the block" do
+ a = ['a', 'b', 'c', 'd']
+ b = a.map {|i|
+ if i == 'c'
+ break 0
+ else
+ i + '!'
+ end
+ }
+ b.should == 0
+ end
+
+ it "returns an Enumerator when no block given" do
+ a = [1, 2, 3]
+ a.map.should.instance_of?(Enumerator)
+ end
+
+ it "raises an ArgumentError when no block and with arguments" do
+ a = [1, 2, 3]
+ -> {
+ a.map(:foo)
+ }.should.raise(ArgumentError)
+ end
+
+ before :each do
+ @object = [1, 2, 3, 4]
+ end
+ it_behaves_like :enumeratorized_with_origin_size, :map
+
+ it_behaves_like :array_iterable_and_tolerating_size_increasing, :map
end
describe "Array#map!" do
- it_behaves_like(:array_collect_b, :map!)
+ it "replaces each element with the value returned by block" do
+ a = [7, 9, 3, 5]
+ a.map! { |i| i - 1 }.should.equal?(a)
+ a.should == [6, 8, 2, 4]
+ end
+
+ it "returns self" do
+ a = [1, 2, 3, 4, 5]
+ b = a.map! {|i| i+1 }
+ a.should.equal? b
+ end
+
+ it "returns the evaluated value of block but its contents is partially modified, if it broke in the block" do
+ a = ['a', 'b', 'c', 'd']
+ b = a.map! {|i|
+ if i == 'c'
+ break 0
+ else
+ i + '!'
+ end
+ }
+ b.should == 0
+ a.should == ['a!', 'b!', 'c', 'd']
+ end
+
+ it "returns an Enumerator when no block given, and the enumerator can modify the original array" do
+ a = [1, 2, 3]
+ enum = a.map!
+ enum.should.instance_of?(Enumerator)
+ enum.each{|i| "#{i}!" }
+ a.should == ["1!", "2!", "3!"]
+ end
+
+ describe "when frozen" do
+ it "raises a FrozenError" do
+ -> { ArraySpecs.frozen_array.map! {} }.should.raise(FrozenError)
+ end
+
+ it "raises a FrozenError when empty" do
+ -> { ArraySpecs.empty_frozen_array.map! {} }.should.raise(FrozenError)
+ end
+
+ it "raises a FrozenError when calling #each on the returned Enumerator" do
+ enumerator = ArraySpecs.frozen_array.map!
+ -> { enumerator.each {|x| x } }.should.raise(FrozenError)
+ end
+
+ it "raises a FrozenError when calling #each on the returned Enumerator when empty" do
+ enumerator = ArraySpecs.empty_frozen_array.map!
+ -> { enumerator.each {|x| x } }.should.raise(FrozenError)
+ end
+ end
+
+ it "does not truncate the array is the block raises an exception" do
+ a = [1, 2, 3]
+ begin
+ a.map! { raise StandardError, 'Oops' }
+ rescue
+ end
+
+ a.should == [1, 2, 3]
+ end
+
+ it "only changes elements before error is raised, keeping the element which raised an error." do
+ a = [1, 2, 3, 4]
+ begin
+ a.map! do |e|
+ case e
+ when 1 then -1
+ when 2 then -2
+ when 3 then raise StandardError, 'Oops'
+ else 0
+ end
+ end
+ rescue StandardError
+ end
+
+ a.should == [-1, -2, 3, 4]
+ end
+
+ before :each do
+ @object = [1, 2, 3, 4]
+ end
+ it_behaves_like :enumeratorized_with_origin_size, :map!
+
+ it_behaves_like :array_iterable_and_tolerating_size_increasing, :map!
end
diff --git a/spec/ruby/core/array/max_spec.rb b/spec/ruby/core/array/max_spec.rb
index db1d755645..868275a748 100644
--- a/spec/ruby/core/array/max_spec.rb
+++ b/spec/ruby/core/array/max_spec.rb
@@ -1,10 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Array#max" do
- ruby_version_is "2.4" do
- it "is defined on Array" do
- [1].method(:max).owner.should equal Array
- end
+ it "is defined on Array" do
+ [1].method(:max).owner.should.equal? Array
end
it "returns nil with no values" do
@@ -70,18 +68,18 @@ describe "Array#max" do
end
it "raises a NoMethodError for elements without #<=>" do
- lambda do
+ -> do
[BasicObject.new, BasicObject.new].max
- end.should raise_error(NoMethodError)
+ end.should.raise(NoMethodError)
end
it "raises an ArgumentError for incomparable elements" do
- lambda do
+ -> do
[11,"22"].max
- end.should raise_error(ArgumentError)
- lambda do
+ end.should.raise(ArgumentError)
+ -> do
[11,12,22,33].max{|a, b| nil}
- end.should raise_error(ArgumentError)
+ end.should.raise(ArgumentError)
end
it "returns the maximum element (with block)" do
diff --git a/spec/ruby/core/array/min_spec.rb b/spec/ruby/core/array/min_spec.rb
index 59f3814da2..5913e08cf8 100644
--- a/spec/ruby/core/array/min_spec.rb
+++ b/spec/ruby/core/array/min_spec.rb
@@ -1,10 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Array#min" do
- ruby_version_is "2.4" do
- it "is defined on Array" do
- [1].method(:max).owner.should equal Array
- end
+ it "is defined on Array" do
+ [1].method(:max).owner.should.equal? Array
end
it "returns nil with no values" do
@@ -66,22 +64,22 @@ describe "Array#min" do
end
it "returns nil for an empty Enumerable" do
- [].min.should be_nil
+ [].min.should == nil
end
it "raises a NoMethodError for elements without #<=>" do
- lambda do
+ -> do
[BasicObject.new, BasicObject.new].min
- end.should raise_error(NoMethodError)
+ end.should.raise(NoMethodError)
end
it "raises an ArgumentError for incomparable elements" do
- lambda do
+ -> do
[11,"22"].min
- end.should raise_error(ArgumentError)
- lambda do
+ end.should.raise(ArgumentError)
+ -> do
[11,12,22,33].min{|a, b| nil}
- end.should raise_error(ArgumentError)
+ end.should.raise(ArgumentError)
end
it "returns the minimum when using a block rule" do
diff --git a/spec/ruby/core/array/minmax_spec.rb b/spec/ruby/core/array/minmax_spec.rb
new file mode 100644
index 0000000000..e11fe63347
--- /dev/null
+++ b/spec/ruby/core/array/minmax_spec.rb
@@ -0,0 +1,14 @@
+require_relative '../../spec_helper'
+require_relative '../../shared/enumerable/minmax'
+
+describe "Array#minmax" do
+ before :each do
+ @enum = [6, 4, 5, 10, 8]
+ @empty_enum = []
+ @incomparable_enum = [BasicObject.new, BasicObject.new]
+ @incompatible_enum = [11, "22"]
+ @strs = ["333", "2", "60", "55555", "1010", "111"]
+ end
+
+ it_behaves_like :enumerable_minmax, :minmax
+end
diff --git a/spec/ruby/core/array/minus_spec.rb b/spec/ruby/core/array/minus_spec.rb
index ffb8d7db06..cb1bf56d76 100644
--- a/spec/ruby/core/array/minus_spec.rb
+++ b/spec/ruby/core/array/minus_spec.rb
@@ -1,87 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/difference'
describe "Array#-" do
- it "creates an array minus any items from other array" do
- ([] - [ 1, 2, 4 ]).should == []
- ([1, 2, 4] - []).should == [1, 2, 4]
- ([ 1, 2, 3, 4, 5 ] - [ 1, 2, 4 ]).should == [3, 5]
- end
-
- it "removes multiple items on the lhs equal to one on the rhs" do
- ([1, 1, 2, 2, 3, 3, 4, 5] - [1, 2, 4]).should == [3, 3, 5]
- end
-
- it "properly handles recursive arrays" do
- empty = ArraySpecs.empty_recursive_array
- (empty - empty).should == []
-
- ([] - ArraySpecs.recursive_array).should == []
-
- array = ArraySpecs.recursive_array
- (array - array).should == []
- end
-
- it "tries to convert the passed arguments to Arrays using #to_ary" do
- obj = mock('[2,3,3,4]')
- obj.should_receive(:to_ary).and_return([2, 3, 3, 4])
- ([1, 1, 2, 2, 3, 4] - obj).should == [1, 1]
- end
-
- it "raises a TypeError if the argument cannot be coerced to an Array by calling #to_ary" do
- obj = mock('not an array')
- lambda { [1, 2, 3] - obj }.should raise_error(TypeError)
- end
-
- it "does not return subclass instance for Array subclasses" do
- (ArraySpecs::MyArray[1, 2, 3] - []).should be_an_instance_of(Array)
- (ArraySpecs::MyArray[1, 2, 3] - ArraySpecs::MyArray[]).should be_an_instance_of(Array)
- ([1, 2, 3] - ArraySpecs::MyArray[]).should be_an_instance_of(Array)
- end
-
- it "does not call to_ary on array subclasses" do
- ([5, 6, 7] - ArraySpecs::ToAryArray[7]).should == [5, 6]
- end
-
- it "removes an item identified as equivalent via #hash and #eql?" do
- obj1 = mock('1')
- obj2 = mock('2')
- obj1.stub!(:hash).and_return(0)
- obj2.stub!(:hash).and_return(0)
- obj1.should_receive(:eql?).at_least(1).and_return(true)
-
- ([obj1] - [obj2]).should == []
- ([obj1, obj1, obj2, obj2] - [obj2]).should == []
- end
-
- it "doesn't remove an item with the same hash but not #eql?" do
- obj1 = mock('1')
- obj2 = mock('2')
- obj1.stub!(:hash).and_return(0)
- obj2.stub!(:hash).and_return(0)
- obj1.should_receive(:eql?).at_least(1).and_return(false)
-
- ([obj1] - [obj2]).should == [obj1]
- ([obj1, obj1, obj2, obj2] - [obj2]).should == [obj1, obj1]
- end
-
- it "removes an identical item even when its #eql? isn't reflexive" do
- x = mock('x')
- x.stub!(:hash).and_return(42)
- x.stub!(:eql?).and_return(false) # Stubbed for clarity and latitude in implementation; not actually sent by MRI.
-
- ([x] - [x]).should == []
- end
-
- it "is not destructive" do
- a = [1, 2, 3]
- a - []
- a.should == [1, 2, 3]
- a - [1]
- a.should == [1, 2, 3]
- a - [1,2,3]
- a.should == [1, 2, 3]
- a - [:a, :b, :c]
- a.should == [1, 2, 3]
- end
+ it_behaves_like :array_binary_difference, :-
end
diff --git a/spec/ruby/core/array/multiply_spec.rb b/spec/ruby/core/array/multiply_spec.rb
index ecd5eba5f7..1ac14e1b09 100644
--- a/spec/ruby/core/array/multiply_spec.rb
+++ b/spec/ruby/core/array/multiply_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/join', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/join'
describe "Array#*" do
it "tries to convert the passed argument to a String using #to_str" do
@@ -17,7 +17,7 @@ describe "Array#*" do
it "raises a TypeError if the argument can neither be converted to a string nor an integer" do
obj = mock('not a string or integer')
- lambda{ [1,2] * obj }.should raise_error(TypeError)
+ ->{ [1,2] * obj }.should.raise(TypeError)
end
it "converts the passed argument to a String rather than an Integer" do
@@ -28,15 +28,15 @@ describe "Array#*" do
end
it "raises a TypeError is the passed argument is nil" do
- lambda{ [1,2] * nil }.should raise_error(TypeError)
+ ->{ [1,2] * nil }.should.raise(TypeError)
end
it "raises an ArgumentError when passed 2 or more arguments" do
- lambda{ [1,2].send(:*, 1, 2) }.should raise_error(ArgumentError)
+ ->{ [1,2].send(:*, 1, 2) }.should.raise(ArgumentError)
end
it "raises an ArgumentError when passed no arguments" do
- lambda{ [1,2].send(:*) }.should raise_error(ArgumentError)
+ ->{ [1,2].send(:*) }.should.raise(ArgumentError)
end
end
@@ -50,7 +50,7 @@ describe "Array#* with an integer" do
it "does not return self even if the passed integer is 1" do
ary = [1, 2, 3]
- (ary * 1).should_not equal(ary)
+ (ary * 1).should_not.equal?(ary)
end
it "properly handles recursive arrays" do
@@ -65,8 +65,8 @@ describe "Array#* with an integer" do
end
it "raises an ArgumentError when passed a negative integer" do
- lambda { [ 1, 2, 3 ] * -1 }.should raise_error(ArgumentError)
- lambda { [] * -1 }.should raise_error(ArgumentError)
+ -> { [ 1, 2, 3 ] * -1 }.should.raise(ArgumentError)
+ -> { [] * -1 }.should.raise(ArgumentError)
end
describe "with a subclass of Array" do
@@ -76,55 +76,17 @@ describe "Array#* with an integer" do
@array = ArraySpecs::MyArray[1, 2, 3, 4, 5]
end
- it "returns a subclass instance" do
- (@array * 0).should be_an_instance_of(ArraySpecs::MyArray)
- (@array * 1).should be_an_instance_of(ArraySpecs::MyArray)
- (@array * 2).should be_an_instance_of(ArraySpecs::MyArray)
+ it "returns an Array instance" do
+ (@array * 0).should.instance_of?(Array)
+ (@array * 1).should.instance_of?(Array)
+ (@array * 2).should.instance_of?(Array)
end
it "does not call #initialize on the subclass instance" do
(@array * 2).should == [1, 2, 3, 4, 5, 1, 2, 3, 4, 5]
- ScratchPad.recorded.should be_nil
+ ScratchPad.recorded.should == nil
end
end
-
- it "copies the taint status of the original array even if the passed count is 0" do
- ary = [1, 2, 3]
- ary.taint
- (ary * 0).tainted?.should == true
- end
-
- it "copies the taint status of the original array even if the array is empty" do
- ary = []
- ary.taint
- (ary * 3).tainted?.should == true
- end
-
- it "copies the taint status of the original array if the passed count is not 0" do
- ary = [1, 2, 3]
- ary.taint
- (ary * 1).tainted?.should == true
- (ary * 2).tainted?.should == true
- end
-
- it "copies the untrusted status of the original array even if the passed count is 0" do
- ary = [1, 2, 3]
- ary.untrust
- (ary * 0).untrusted?.should == true
- end
-
- it "copies the untrusted status of the original array even if the array is empty" do
- ary = []
- ary.untrust
- (ary * 3).untrusted?.should == true
- end
-
- it "copies the untrusted status of the original array if the passed count is not 0" do
- ary = [1, 2, 3]
- ary.untrust
- (ary * 1).untrusted?.should == true
- (ary * 2).untrusted?.should == true
- end
end
describe "Array#* with a string" do
diff --git a/spec/ruby/core/array/new_spec.rb b/spec/ruby/core/array/new_spec.rb
index 4d26024ff2..b2f23e2f6b 100644
--- a/spec/ruby/core/array/new_spec.rb
+++ b/spec/ruby/core/array/new_spec.rb
@@ -1,32 +1,34 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Array.new" do
it "returns an instance of Array" do
- Array.new.should be_an_instance_of(Array)
+ Array.new.should.instance_of?(Array)
end
it "returns an instance of a subclass" do
- ArraySpecs::MyArray.new(1, 2).should be_an_instance_of(ArraySpecs::MyArray)
+ ArraySpecs::MyArray.new(1, 2).should.instance_of?(ArraySpecs::MyArray)
end
it "raises an ArgumentError if passed 3 or more arguments" do
- lambda do
+ -> do
[1, 2].send :initialize, 1, 'x', true
- end.should raise_error(ArgumentError)
- lambda do
+ end.should.raise(ArgumentError)
+ -> do
[1, 2].send(:initialize, 1, 'x', true) {}
- end.should raise_error(ArgumentError)
+ end.should.raise(ArgumentError)
end
end
describe "Array.new with no arguments" do
it "returns an empty array" do
- Array.new.should be_empty
+ Array.new.should.empty?
end
it "does not use the given block" do
- lambda{ Array.new { raise } }.should_not raise_error
+ -> {
+ -> { Array.new { raise } }.should_not.raise
+ }.should complain(/warning: given block not used/, verbose: true)
end
end
@@ -37,7 +39,7 @@ describe "Array.new with (array)" do
end
it "does not use the given block" do
- lambda{ Array.new([1, 2]) { raise } }.should_not raise_error
+ ->{ Array.new([1, 2]) { raise } }.should_not.raise
end
it "calls #to_ary to convert the value to an array" do
@@ -54,7 +56,7 @@ describe "Array.new with (array)" do
end
it "raises a TypeError if an Array type argument and a default object" do
- lambda { Array.new([1, 2], 1) }.should raise_error(TypeError)
+ -> { Array.new([1, 2], 1) }.should.raise(TypeError)
end
end
@@ -63,8 +65,8 @@ describe "Array.new with (size, object=nil)" do
obj = [3]
a = Array.new(2, obj)
a.should == [obj, obj]
- a[0].should equal(obj)
- a[1].should equal(obj)
+ a[0].should.equal?(obj)
+ a[1].should.equal?(obj)
Array.new(3, 14).should == [14, 14, 14]
end
@@ -74,12 +76,12 @@ describe "Array.new with (size, object=nil)" do
end
it "raises an ArgumentError if size is negative" do
- lambda { Array.new(-1, :a) }.should raise_error(ArgumentError)
- lambda { Array.new(-1) }.should raise_error(ArgumentError)
+ -> { Array.new(-1, :a) }.should.raise(ArgumentError)
+ -> { Array.new(-1) }.should.raise(ArgumentError)
end
it "raises an ArgumentError if size is too large" do
- lambda { Array.new(fixnum_max+1) }.should raise_error(ArgumentError)
+ -> { Array.new(fixnum_max+1) }.should.raise(ArgumentError)
end
it "calls #to_int to convert the size argument to an Integer when object is given" do
@@ -97,7 +99,7 @@ describe "Array.new with (size, object=nil)" do
it "raises a TypeError if the size argument is not an Integer type" do
obj = mock('nonnumeric')
obj.stub!(:to_ary).and_return([1, 2])
- lambda{ Array.new(obj, :a) }.should raise_error(TypeError)
+ ->{ Array.new(obj, :a) }.should.raise(TypeError)
end
it "yields the index of the element and sets the element to the value of the block" do
@@ -105,7 +107,7 @@ describe "Array.new with (size, object=nil)" do
end
it "uses the block value instead of using the default value" do
- lambda {
+ -> {
@result = Array.new(3, :obj) { |i| i.to_s }
}.should complain(/block supersedes default value argument/)
@result.should == ['0', '1', '2']
diff --git a/spec/ruby/core/array/none_spec.rb b/spec/ruby/core/array/none_spec.rb
new file mode 100644
index 0000000000..31cd8c46d6
--- /dev/null
+++ b/spec/ruby/core/array/none_spec.rb
@@ -0,0 +1,13 @@
+require_relative '../../spec_helper'
+require_relative 'shared/iterable_and_tolerating_size_increasing'
+
+describe "Array#none?" do
+ @value_to_return = -> _ { false }
+ it_behaves_like :array_iterable_and_tolerating_size_increasing, :none?
+
+ it "ignores the block if there is an argument" do
+ -> {
+ ['bar', 'foobar'].none?(/baz/) { true }.should == true
+ }.should complain(/given block not used/)
+ end
+end
diff --git a/spec/ruby/core/array/one_spec.rb b/spec/ruby/core/array/one_spec.rb
new file mode 100644
index 0000000000..0c61907881
--- /dev/null
+++ b/spec/ruby/core/array/one_spec.rb
@@ -0,0 +1,13 @@
+require_relative '../../spec_helper'
+require_relative 'shared/iterable_and_tolerating_size_increasing'
+
+describe "Array#one?" do
+ @value_to_return = -> _ { false }
+ it_behaves_like :array_iterable_and_tolerating_size_increasing, :one?
+
+ it "ignores the block if there is an argument" do
+ -> {
+ ['bar', 'foobar'].one?(/foo/) { false }.should == true
+ }.should complain(/given block not used/)
+ end
+end
diff --git a/spec/ruby/core/array/pack/a_spec.rb b/spec/ruby/core/array/pack/a_spec.rb
index e7fbdcd179..03bfd8214c 100644
--- a/spec/ruby/core/array/pack/a_spec.rb
+++ b/spec/ruby/core/array/pack/a_spec.rb
@@ -1,20 +1,33 @@
-# -*- encoding: ascii-8bit -*-
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
-require File.expand_path('../shared/basic', __FILE__)
-require File.expand_path('../shared/string', __FILE__)
+# encoding: binary
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
+require_relative 'shared/basic'
+require_relative 'shared/string'
+require_relative 'shared/taint'
describe "Array#pack with format 'A'" do
it_behaves_like :array_pack_basic, 'A'
it_behaves_like :array_pack_basic_non_float, 'A'
it_behaves_like :array_pack_no_platform, 'A'
it_behaves_like :array_pack_string, 'A'
+ it_behaves_like :array_pack_taint, 'A'
+
+ it "calls #to_str to convert an Object to a String" do
+ obj = mock("pack A string")
+ obj.should_receive(:to_str).and_return("``abcdef")
+ [obj].pack("A*").should == "``abcdef"
+ end
+
+ it "will not implicitly convert a number to a string" do
+ -> { [0].pack('A') }.should.raise(TypeError)
+ -> { [0].pack('a') }.should.raise(TypeError)
+ end
it "adds all the bytes to the output when passed the '*' modifier" do
["abc"].pack("A*").should == "abc"
end
- it "padds the output with spaces when the count exceeds the size of the String" do
+ it "pads the output with spaces when the count exceeds the size of the String" do
["abc"].pack("A6").should == "abc "
end
@@ -36,12 +49,13 @@ describe "Array#pack with format 'a'" do
it_behaves_like :array_pack_basic_non_float, 'a'
it_behaves_like :array_pack_no_platform, 'a'
it_behaves_like :array_pack_string, 'a'
+ it_behaves_like :array_pack_taint, 'a'
it "adds all the bytes to the output when passed the '*' modifier" do
["abc"].pack("a*").should == "abc"
end
- it "padds the output with NULL bytes when the count exceeds the size of the String" do
+ it "pads the output with NULL bytes when the count exceeds the size of the String" do
["abc"].pack("a6").should == "abc\x00\x00\x00"
end
diff --git a/spec/ruby/core/array/pack/at_spec.rb b/spec/ruby/core/array/pack/at_spec.rb
index dd538e8951..bb9801440a 100644
--- a/spec/ruby/core/array/pack/at_spec.rb
+++ b/spec/ruby/core/array/pack/at_spec.rb
@@ -1,7 +1,7 @@
-# -*- encoding: ascii-8bit -*-
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
-require File.expand_path('../shared/basic', __FILE__)
+# encoding: binary
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
+require_relative 'shared/basic'
describe "Array#pack with format '@'" do
it_behaves_like :array_pack_basic, '@'
diff --git a/spec/ruby/core/array/pack/b_spec.rb b/spec/ruby/core/array/pack/b_spec.rb
index 62294ab8d1..f7576846ef 100644
--- a/spec/ruby/core/array/pack/b_spec.rb
+++ b/spec/ruby/core/array/pack/b_spec.rb
@@ -1,21 +1,28 @@
-# -*- encoding: ascii-8bit -*-
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
-require File.expand_path('../shared/basic', __FILE__)
-require File.expand_path('../shared/encodings', __FILE__)
+# encoding: binary
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
+require_relative 'shared/basic'
+require_relative 'shared/encodings'
+require_relative 'shared/taint'
describe "Array#pack with format 'B'" do
it_behaves_like :array_pack_basic, 'B'
it_behaves_like :array_pack_basic_non_float, 'B'
it_behaves_like :array_pack_arguments, 'B'
it_behaves_like :array_pack_hex, 'B'
+ it_behaves_like :array_pack_taint, 'B'
it "calls #to_str to convert an Object to a String" do
- obj = mock("pack H string")
+ obj = mock("pack B string")
obj.should_receive(:to_str).and_return("``abcdef")
[obj].pack("B*").should == "\x2a"
end
+ it "will not implicitly convert a number to a string" do
+ -> { [0].pack('B') }.should.raise(TypeError)
+ -> { [0].pack('b') }.should.raise(TypeError)
+ end
+
it "encodes one bit for each character starting with the most significant bit" do
[ [["0"], "\x00"],
[["1"], "\x80"]
@@ -45,8 +52,8 @@ describe "Array#pack with format 'B'" do
].should be_computed_by(:pack, "B*")
end
- it "returns an ASCII-8BIT string" do
- ["1"].pack("B").encoding.should == Encoding::ASCII_8BIT
+ it "returns a binary string" do
+ ["1"].pack("B").encoding.should == Encoding::BINARY
end
it "encodes the string as a sequence of bytes" do
@@ -59,6 +66,7 @@ describe "Array#pack with format 'b'" do
it_behaves_like :array_pack_basic_non_float, 'b'
it_behaves_like :array_pack_arguments, 'b'
it_behaves_like :array_pack_hex, 'b'
+ it_behaves_like :array_pack_taint, 'b'
it "calls #to_str to convert an Object to a String" do
obj = mock("pack H string")
@@ -95,8 +103,8 @@ describe "Array#pack with format 'b'" do
].should be_computed_by(:pack, "b*")
end
- it "returns an ASCII-8BIT string" do
- ["1"].pack("b").encoding.should == Encoding::ASCII_8BIT
+ it "returns a binary string" do
+ ["1"].pack("b").encoding.should == Encoding::BINARY
end
it "encodes the string as a sequence of bytes" do
diff --git a/spec/ruby/core/array/pack/buffer_spec.rb b/spec/ruby/core/array/pack/buffer_spec.rb
index 928f7db731..d104c80186 100644
--- a/spec/ruby/core/array/pack/buffer_spec.rb
+++ b/spec/ruby/core/array/pack/buffer_spec.rb
@@ -1,52 +1,60 @@
-# encoding: ascii-8bit
+# encoding: binary
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
-ruby_version_is '2.4' do
- describe "Aray#pack with `buffer` option" do
- it "returns specified buffer" do
- n = [ 65, 66, 67 ]
- buffer = " "*3
- result = n.pack("ccc", buffer: buffer) #=> "ABC"
- result.should equal(buffer)
- end
+describe "Array#pack with :buffer option" do
+ it "returns specified buffer" do
+ n = [ 65, 66, 67 ]
+ buffer = " "*3
+ result = n.pack("ccc", buffer: buffer) #=> "ABC"
+ result.should.equal?(buffer)
+ end
+
+ it "adds result at the end of buffer content" do
+ n = [ 65, 66, 67 ] # result without buffer is "ABC"
+
+ buffer = +""
+ n.pack("ccc", buffer: buffer).should == "ABC"
+
+ buffer = +"123"
+ n.pack("ccc", buffer: buffer).should == "123ABC"
+
+ buffer = +"12345"
+ n.pack("ccc", buffer: buffer).should == "12345ABC"
+ end
- it "adds result at the end of buffer content" do
- n = [ 65, 66, 67 ] # result without buffer is "ABC"
+ it "raises TypeError exception if buffer is not String" do
+ -> { [65].pack("ccc", buffer: []) }.should.raise(
+ TypeError, "buffer must be String, not Array")
+ end
- buffer = ""
- n.pack("ccc", buffer: buffer).should == "ABC"
+ it "raise FrozenError if buffer is frozen" do
+ -> { [65].pack("c", buffer: "frozen-string".freeze) }.should.raise(FrozenError)
+ end
- buffer = "123"
- n.pack("ccc", buffer: buffer).should == "123ABC"
+ it "preserves the encoding of the given buffer" do
+ buffer = ''.encode(Encoding::ISO_8859_1)
+ [65, 66, 67].pack("ccc", buffer: buffer)
+ buffer.encoding.should == Encoding::ISO_8859_1
+ end
- buffer = "12345"
- n.pack("ccc", buffer: buffer).should == "12345ABC"
+ context "offset (@) is specified" do
+ it 'keeps buffer content if it is longer than offset' do
+ n = [ 65, 66, 67 ]
+ buffer = +"123456"
+ n.pack("@3ccc", buffer: buffer).should == "123ABC"
end
- it "raises TypeError exception if buffer is not String" do
- lambda { [65].pack("ccc", buffer: []) }.should raise_error(
- TypeError, "buffer must be String, not Array")
+ it "fills the gap with \\0 if buffer content is shorter than offset" do
+ n = [ 65, 66, 67 ]
+ buffer = +"123"
+ n.pack("@6ccc", buffer: buffer).should == "123\0\0\0ABC"
end
- context "offset (@) is specified" do
- it 'keeps buffer content if it is longer than offset' do
- n = [ 65, 66, 67 ]
- buffer = "123456"
- n.pack("@3ccc", buffer: buffer).should == "123ABC"
- end
-
- it "fills the gap with \0 if buffer content is shorter than offset" do
- n = [ 65, 66, 67 ]
- buffer = "123"
- n.pack("@6ccc", buffer: buffer).should == "123\0\0\0ABC"
- end
-
- it 'does not keep buffer content if it is longer than offset + result' do
- n = [ 65, 66, 67 ]
- buffer = "1234567890"
- n.pack("@3ccc", buffer: buffer).should == "123ABC"
- end
+ it 'does not keep buffer content if it is longer than offset + result' do
+ n = [ 65, 66, 67 ]
+ buffer = +"1234567890"
+ n.pack("@3ccc", buffer: buffer).should == "123ABC"
end
end
end
diff --git a/spec/ruby/core/array/pack/c_spec.rb b/spec/ruby/core/array/pack/c_spec.rb
index 74afa72f56..de06207a23 100644
--- a/spec/ruby/core/array/pack/c_spec.rb
+++ b/spec/ruby/core/array/pack/c_spec.rb
@@ -1,9 +1,9 @@
-# -*- encoding: ascii-8bit -*-
+# encoding: binary
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
-require File.expand_path('../shared/basic', __FILE__)
-require File.expand_path('../shared/numeric_basic', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
+require_relative 'shared/basic'
+require_relative 'shared/numeric_basic'
describe :array_pack_8bit, shared: true do
it "encodes the least significant eight bits of a positive number" do
@@ -45,8 +45,10 @@ describe :array_pack_8bit, shared: true do
[1, 2, 3, 4, 5].pack(pack_format('*')).should == "\x01\x02\x03\x04\x05"
end
- it "ignores NULL bytes between directives" do
- [1, 2, 3].pack(pack_format("\000", 2)).should == "\x01\x02"
+ it "raise ArgumentError for NULL bytes between directives" do
+ -> {
+ [1, 2, 3].pack(pack_format("\000", 2))
+ }.should.raise(ArgumentError, /unknown pack directive/)
end
it "ignores spaces between directives" do
diff --git a/spec/ruby/core/array/pack/comment_spec.rb b/spec/ruby/core/array/pack/comment_spec.rb
index 00c5fb6ecd..daf1cff06a 100644
--- a/spec/ruby/core/array/pack/comment_spec.rb
+++ b/spec/ruby/core/array/pack/comment_spec.rb
@@ -1,6 +1,6 @@
-# -*- encoding: ascii-8bit -*-
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
+# encoding: binary
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
describe "Array#pack" do
it "ignores directives text from '#' to the first newline" do
diff --git a/spec/ruby/core/array/pack/d_spec.rb b/spec/ruby/core/array/pack/d_spec.rb
index 40f28d1e52..8bb3654633 100644
--- a/spec/ruby/core/array/pack/d_spec.rb
+++ b/spec/ruby/core/array/pack/d_spec.rb
@@ -1,8 +1,8 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
-require File.expand_path('../shared/basic', __FILE__)
-require File.expand_path('../shared/numeric_basic', __FILE__)
-require File.expand_path('../shared/float', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
+require_relative 'shared/basic'
+require_relative 'shared/numeric_basic'
+require_relative 'shared/float'
describe "Array#pack with format 'D'" do
it_behaves_like :array_pack_basic, 'D'
diff --git a/spec/ruby/core/array/pack/e_spec.rb b/spec/ruby/core/array/pack/e_spec.rb
index 9c6a1b5485..ab61ef578f 100644
--- a/spec/ruby/core/array/pack/e_spec.rb
+++ b/spec/ruby/core/array/pack/e_spec.rb
@@ -1,8 +1,8 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
-require File.expand_path('../shared/basic', __FILE__)
-require File.expand_path('../shared/numeric_basic', __FILE__)
-require File.expand_path('../shared/float', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
+require_relative 'shared/basic'
+require_relative 'shared/numeric_basic'
+require_relative 'shared/float'
describe "Array#pack with format 'E'" do
it_behaves_like :array_pack_basic, 'E'
diff --git a/spec/ruby/core/array/pack/empty_spec.rb b/spec/ruby/core/array/pack/empty_spec.rb
index 701e20b0af..d635d6a563 100644
--- a/spec/ruby/core/array/pack/empty_spec.rb
+++ b/spec/ruby/core/array/pack/empty_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "Array#pack with empty format" do
it "returns an empty String" do
diff --git a/spec/ruby/core/array/pack/f_spec.rb b/spec/ruby/core/array/pack/f_spec.rb
index 94ce57f34d..d436e0787c 100644
--- a/spec/ruby/core/array/pack/f_spec.rb
+++ b/spec/ruby/core/array/pack/f_spec.rb
@@ -1,8 +1,8 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
-require File.expand_path('../shared/basic', __FILE__)
-require File.expand_path('../shared/numeric_basic', __FILE__)
-require File.expand_path('../shared/float', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
+require_relative 'shared/basic'
+require_relative 'shared/numeric_basic'
+require_relative 'shared/float'
describe "Array#pack with format 'F'" do
it_behaves_like :array_pack_basic, 'F'
diff --git a/spec/ruby/core/array/pack/g_spec.rb b/spec/ruby/core/array/pack/g_spec.rb
index a0a902ebbe..83b7f81acc 100644
--- a/spec/ruby/core/array/pack/g_spec.rb
+++ b/spec/ruby/core/array/pack/g_spec.rb
@@ -1,8 +1,8 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
-require File.expand_path('../shared/basic', __FILE__)
-require File.expand_path('../shared/numeric_basic', __FILE__)
-require File.expand_path('../shared/float', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
+require_relative 'shared/basic'
+require_relative 'shared/numeric_basic'
+require_relative 'shared/float'
describe "Array#pack with format 'G'" do
it_behaves_like :array_pack_basic, 'G'
diff --git a/spec/ruby/core/array/pack/h_spec.rb b/spec/ruby/core/array/pack/h_spec.rb
index 2412bf57c9..1492d02b1f 100644
--- a/spec/ruby/core/array/pack/h_spec.rb
+++ b/spec/ruby/core/array/pack/h_spec.rb
@@ -1,14 +1,16 @@
-# -*- encoding: ascii-8bit -*-
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
-require File.expand_path('../shared/basic', __FILE__)
-require File.expand_path('../shared/encodings', __FILE__)
+# encoding: binary
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
+require_relative 'shared/basic'
+require_relative 'shared/encodings'
+require_relative 'shared/taint'
describe "Array#pack with format 'H'" do
it_behaves_like :array_pack_basic, 'H'
it_behaves_like :array_pack_basic_non_float, 'H'
it_behaves_like :array_pack_arguments, 'H'
it_behaves_like :array_pack_hex, 'H'
+ it_behaves_like :array_pack_taint, 'H'
it "calls #to_str to convert an Object to a String" do
obj = mock("pack H string")
@@ -16,6 +18,11 @@ describe "Array#pack with format 'H'" do
[obj].pack("H").should == "\xa0"
end
+ it "will not implicitly convert a number to a string" do
+ -> { [0].pack('H') }.should.raise(TypeError)
+ -> { [0].pack('h') }.should.raise(TypeError)
+ end
+
it "encodes the first character as the most significant nibble when passed no count modifier" do
["ab"].pack("H").should == "\xa0"
end
@@ -95,8 +102,8 @@ describe "Array#pack with format 'H'" do
].should be_computed_by(:pack, "H")
end
- it "returns an ASCII-8BIT string" do
- ["41"].pack("H").encoding.should == Encoding::ASCII_8BIT
+ it "returns a binary string" do
+ ["41"].pack("H").encoding.should == Encoding::BINARY
end
end
@@ -105,6 +112,7 @@ describe "Array#pack with format 'h'" do
it_behaves_like :array_pack_basic_non_float, 'h'
it_behaves_like :array_pack_arguments, 'h'
it_behaves_like :array_pack_hex, 'h'
+ it_behaves_like :array_pack_taint, 'h'
it "calls #to_str to convert an Object to a String" do
obj = mock("pack H string")
@@ -191,7 +199,7 @@ describe "Array#pack with format 'h'" do
].should be_computed_by(:pack, "h")
end
- it "returns an ASCII-8BIT string" do
- ["41"].pack("h").encoding.should == Encoding::ASCII_8BIT
+ it "returns a binary string" do
+ ["41"].pack("h").encoding.should == Encoding::BINARY
end
end
diff --git a/spec/ruby/core/array/pack/i_spec.rb b/spec/ruby/core/array/pack/i_spec.rb
index c22f367a65..a237071227 100644
--- a/spec/ruby/core/array/pack/i_spec.rb
+++ b/spec/ruby/core/array/pack/i_spec.rb
@@ -1,8 +1,8 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
-require File.expand_path('../shared/basic', __FILE__)
-require File.expand_path('../shared/numeric_basic', __FILE__)
-require File.expand_path('../shared/integer', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
+require_relative 'shared/basic'
+require_relative 'shared/numeric_basic'
+require_relative 'shared/integer'
describe "Array#pack with format 'I'" do
it_behaves_like :array_pack_basic, 'I'
diff --git a/spec/ruby/core/array/pack/j_spec.rb b/spec/ruby/core/array/pack/j_spec.rb
index 88f074724c..7b62d5efdf 100644
--- a/spec/ruby/core/array/pack/j_spec.rb
+++ b/spec/ruby/core/array/pack/j_spec.rb
@@ -1,222 +1,217 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
-require File.expand_path('../shared/basic', __FILE__)
-require File.expand_path('../shared/numeric_basic', __FILE__)
-require File.expand_path('../shared/integer', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
+require_relative 'shared/basic'
+require_relative 'shared/numeric_basic'
+require_relative 'shared/integer'
+
+platform_is pointer_size: 64 do
+ describe "Array#pack with format 'J'" do
+ it_behaves_like :array_pack_basic, 'J'
+ it_behaves_like :array_pack_basic_non_float, 'J'
+ it_behaves_like :array_pack_arguments, 'J'
+ it_behaves_like :array_pack_numeric_basic, 'J'
+ it_behaves_like :array_pack_integer, 'J'
+ end
-ruby_version_is '2.3' do
- # To handle the special case of x64-mingw32
- pointer_size = RUBY_PLATFORM =~ /\bx64\b/ ? 64 : 1.size * 8
+ describe "Array#pack with format 'j'" do
+ it_behaves_like :array_pack_basic, 'j'
+ it_behaves_like :array_pack_basic_non_float, 'j'
+ it_behaves_like :array_pack_arguments, 'j'
+ it_behaves_like :array_pack_numeric_basic, 'j'
+ it_behaves_like :array_pack_integer, 'j'
+ end
- guard -> { pointer_size == 64 } do
+ little_endian do
describe "Array#pack with format 'J'" do
- it_behaves_like :array_pack_basic, 'J'
- it_behaves_like :array_pack_basic_non_float, 'J'
- it_behaves_like :array_pack_arguments, 'J'
- it_behaves_like :array_pack_numeric_basic, 'J'
- it_behaves_like :array_pack_integer, 'J'
- end
-
- describe "Array#pack with format 'j'" do
- it_behaves_like :array_pack_basic, 'j'
- it_behaves_like :array_pack_basic_non_float, 'j'
- it_behaves_like :array_pack_arguments, 'j'
- it_behaves_like :array_pack_numeric_basic, 'j'
- it_behaves_like :array_pack_integer, 'j'
- end
-
- little_endian do
- describe "Array#pack with format 'J'" do
- describe "with modifier '_'" do
- it_behaves_like :array_pack_64bit_le, 'J_'
- end
-
- describe "with modifier '!'" do
- it_behaves_like :array_pack_64bit_le, 'J!'
- end
+ describe "with modifier '_'" do
+ it_behaves_like :array_pack_64bit_le, 'J_'
end
- describe "Array#pack with format 'j'" do
- describe "with modifier '_'" do
- it_behaves_like :array_pack_64bit_le, 'j_'
- end
-
- describe "with modifier '!'" do
- it_behaves_like :array_pack_64bit_le, 'j!'
- end
+ describe "with modifier '!'" do
+ it_behaves_like :array_pack_64bit_le, 'J!'
end
end
- big_endian do
- describe "Array#pack with format 'J'" do
- describe "with modifier '_'" do
- it_behaves_like :array_pack_64bit_be, 'J_'
- end
-
- describe "with modifier '!'" do
- it_behaves_like :array_pack_64bit_be, 'J!'
- end
+ describe "Array#pack with format 'j'" do
+ describe "with modifier '_'" do
+ it_behaves_like :array_pack_64bit_le, 'j_'
end
- describe "Array#pack with format 'j'" do
- describe "with modifier '_'" do
- it_behaves_like :array_pack_64bit_be, 'j_'
- end
-
- describe "with modifier '!'" do
- it_behaves_like :array_pack_64bit_be, 'j!'
- end
+ describe "with modifier '!'" do
+ it_behaves_like :array_pack_64bit_le, 'j!'
end
end
+ end
+ big_endian do
describe "Array#pack with format 'J'" do
- describe "with modifier '<' and '_'" do
- it_behaves_like :array_pack_64bit_le, 'J<_'
- it_behaves_like :array_pack_64bit_le, 'J_<'
- end
-
- describe "with modifier '<' and '!'" do
- it_behaves_like :array_pack_64bit_le, 'J<!'
- it_behaves_like :array_pack_64bit_le, 'J!<'
+ describe "with modifier '_'" do
+ it_behaves_like :array_pack_64bit_be, 'J_'
end
- describe "with modifier '>' and '_'" do
- it_behaves_like :array_pack_64bit_be, 'J>_'
- it_behaves_like :array_pack_64bit_be, 'J_>'
- end
-
- describe "with modifier '>' and '!'" do
- it_behaves_like :array_pack_64bit_be, 'J>!'
- it_behaves_like :array_pack_64bit_be, 'J!>'
+ describe "with modifier '!'" do
+ it_behaves_like :array_pack_64bit_be, 'J!'
end
end
describe "Array#pack with format 'j'" do
- describe "with modifier '<' and '_'" do
- it_behaves_like :array_pack_64bit_le, 'j<_'
- it_behaves_like :array_pack_64bit_le, 'j_<'
+ describe "with modifier '_'" do
+ it_behaves_like :array_pack_64bit_be, 'j_'
end
- describe "with modifier '<' and '!'" do
- it_behaves_like :array_pack_64bit_le, 'j<!'
- it_behaves_like :array_pack_64bit_le, 'j!<'
+ describe "with modifier '!'" do
+ it_behaves_like :array_pack_64bit_be, 'j!'
end
+ end
+ end
- describe "with modifier '>' and '_'" do
- it_behaves_like :array_pack_64bit_be, 'j>_'
- it_behaves_like :array_pack_64bit_be, 'j_>'
- end
+ describe "Array#pack with format 'J'" do
+ describe "with modifier '<' and '_'" do
+ it_behaves_like :array_pack_64bit_le, 'J<_'
+ it_behaves_like :array_pack_64bit_le, 'J_<'
+ end
- describe "with modifier '>' and '!'" do
- it_behaves_like :array_pack_64bit_be, 'j>!'
- it_behaves_like :array_pack_64bit_be, 'j!>'
- end
+ describe "with modifier '<' and '!'" do
+ it_behaves_like :array_pack_64bit_le, 'J<!'
+ it_behaves_like :array_pack_64bit_le, 'J!<'
end
- end
- guard -> { pointer_size == 32 } do
- describe "Array#pack with format 'J'" do
- it_behaves_like :array_pack_basic, 'J'
- it_behaves_like :array_pack_basic_non_float, 'J'
- it_behaves_like :array_pack_arguments, 'J'
- it_behaves_like :array_pack_numeric_basic, 'J'
- it_behaves_like :array_pack_integer, 'J'
+ describe "with modifier '>' and '_'" do
+ it_behaves_like :array_pack_64bit_be, 'J>_'
+ it_behaves_like :array_pack_64bit_be, 'J_>'
end
- describe "Array#pack with format 'j'" do
- it_behaves_like :array_pack_basic, 'j'
- it_behaves_like :array_pack_basic_non_float, 'j'
- it_behaves_like :array_pack_arguments, 'j'
- it_behaves_like :array_pack_numeric_basic, 'j'
- it_behaves_like :array_pack_integer, 'j'
+ describe "with modifier '>' and '!'" do
+ it_behaves_like :array_pack_64bit_be, 'J>!'
+ it_behaves_like :array_pack_64bit_be, 'J!>'
end
+ end
- big_endian do
- describe "Array#pack with format 'J'" do
- describe "with modifier '_'" do
- it_behaves_like :array_pack_32bit_be, 'J_'
- end
+ describe "Array#pack with format 'j'" do
+ describe "with modifier '<' and '_'" do
+ it_behaves_like :array_pack_64bit_le, 'j<_'
+ it_behaves_like :array_pack_64bit_le, 'j_<'
+ end
- describe "with modifier '!'" do
- it_behaves_like :array_pack_32bit_be, 'J!'
- end
- end
+ describe "with modifier '<' and '!'" do
+ it_behaves_like :array_pack_64bit_le, 'j<!'
+ it_behaves_like :array_pack_64bit_le, 'j!<'
+ end
- describe "Array#pack with format 'j'" do
- describe "with modifier '_'" do
- it_behaves_like :array_pack_32bit_be, 'j_'
- end
+ describe "with modifier '>' and '_'" do
+ it_behaves_like :array_pack_64bit_be, 'j>_'
+ it_behaves_like :array_pack_64bit_be, 'j_>'
+ end
- describe "with modifier '!'" do
- it_behaves_like :array_pack_32bit_be, 'j!'
- end
- end
+ describe "with modifier '>' and '!'" do
+ it_behaves_like :array_pack_64bit_be, 'j>!'
+ it_behaves_like :array_pack_64bit_be, 'j!>'
end
+ end
+end
- little_endian do
- describe "Array#pack with format 'J'" do
- describe "with modifier '_'" do
- it_behaves_like :array_pack_32bit_le, 'J_'
- end
+platform_is pointer_size: 32 do
+ describe "Array#pack with format 'J'" do
+ it_behaves_like :array_pack_basic, 'J'
+ it_behaves_like :array_pack_basic_non_float, 'J'
+ it_behaves_like :array_pack_arguments, 'J'
+ it_behaves_like :array_pack_numeric_basic, 'J'
+ it_behaves_like :array_pack_integer, 'J'
+ end
- describe "with modifier '!'" do
- it_behaves_like :array_pack_32bit_le, 'J!'
- end
- end
+ describe "Array#pack with format 'j'" do
+ it_behaves_like :array_pack_basic, 'j'
+ it_behaves_like :array_pack_basic_non_float, 'j'
+ it_behaves_like :array_pack_arguments, 'j'
+ it_behaves_like :array_pack_numeric_basic, 'j'
+ it_behaves_like :array_pack_integer, 'j'
+ end
- describe "Array#pack with format 'j'" do
- describe "with modifier '_'" do
- it_behaves_like :array_pack_32bit_le, 'j_'
- end
+ big_endian do
+ describe "Array#pack with format 'J'" do
+ describe "with modifier '_'" do
+ it_behaves_like :array_pack_32bit_be, 'J_'
+ end
- describe "with modifier '!'" do
- it_behaves_like :array_pack_32bit_le, 'j!'
- end
+ describe "with modifier '!'" do
+ it_behaves_like :array_pack_32bit_be, 'J!'
end
end
- describe "Array#pack with format 'J'" do
- describe "with modifier '<' and '_'" do
- it_behaves_like :array_pack_32bit_le, 'J<_'
- it_behaves_like :array_pack_32bit_le, 'J_<'
+ describe "Array#pack with format 'j'" do
+ describe "with modifier '_'" do
+ it_behaves_like :array_pack_32bit_be, 'j_'
end
- describe "with modifier '<' and '!'" do
- it_behaves_like :array_pack_32bit_le, 'J<!'
- it_behaves_like :array_pack_32bit_le, 'J!<'
+ describe "with modifier '!'" do
+ it_behaves_like :array_pack_32bit_be, 'j!'
end
+ end
+ end
- describe "with modifier '>' and '_'" do
- it_behaves_like :array_pack_32bit_be, 'J>_'
- it_behaves_like :array_pack_32bit_be, 'J_>'
+ little_endian do
+ describe "Array#pack with format 'J'" do
+ describe "with modifier '_'" do
+ it_behaves_like :array_pack_32bit_le, 'J_'
end
- describe "with modifier '>' and '!'" do
- it_behaves_like :array_pack_32bit_be, 'J>!'
- it_behaves_like :array_pack_32bit_be, 'J!>'
+ describe "with modifier '!'" do
+ it_behaves_like :array_pack_32bit_le, 'J!'
end
end
describe "Array#pack with format 'j'" do
- describe "with modifier '<' and '_'" do
- it_behaves_like :array_pack_32bit_le, 'j<_'
- it_behaves_like :array_pack_32bit_le, 'j_<'
+ describe "with modifier '_'" do
+ it_behaves_like :array_pack_32bit_le, 'j_'
end
- describe "with modifier '<' and '!'" do
- it_behaves_like :array_pack_32bit_le, 'j<!'
- it_behaves_like :array_pack_32bit_le, 'j!<'
+ describe "with modifier '!'" do
+ it_behaves_like :array_pack_32bit_le, 'j!'
end
+ end
+ end
- describe "with modifier '>' and '_'" do
- it_behaves_like :array_pack_32bit_be, 'j>_'
- it_behaves_like :array_pack_32bit_be, 'j_>'
- end
+ describe "Array#pack with format 'J'" do
+ describe "with modifier '<' and '_'" do
+ it_behaves_like :array_pack_32bit_le, 'J<_'
+ it_behaves_like :array_pack_32bit_le, 'J_<'
+ end
- describe "with modifier '>' and '!'" do
- it_behaves_like :array_pack_32bit_be, 'j>!'
- it_behaves_like :array_pack_32bit_be, 'j!>'
- end
+ describe "with modifier '<' and '!'" do
+ it_behaves_like :array_pack_32bit_le, 'J<!'
+ it_behaves_like :array_pack_32bit_le, 'J!<'
+ end
+
+ describe "with modifier '>' and '_'" do
+ it_behaves_like :array_pack_32bit_be, 'J>_'
+ it_behaves_like :array_pack_32bit_be, 'J_>'
+ end
+
+ describe "with modifier '>' and '!'" do
+ it_behaves_like :array_pack_32bit_be, 'J>!'
+ it_behaves_like :array_pack_32bit_be, 'J!>'
+ end
+ end
+
+ describe "Array#pack with format 'j'" do
+ describe "with modifier '<' and '_'" do
+ it_behaves_like :array_pack_32bit_le, 'j<_'
+ it_behaves_like :array_pack_32bit_le, 'j_<'
+ end
+
+ describe "with modifier '<' and '!'" do
+ it_behaves_like :array_pack_32bit_le, 'j<!'
+ it_behaves_like :array_pack_32bit_le, 'j!<'
+ end
+
+ describe "with modifier '>' and '_'" do
+ it_behaves_like :array_pack_32bit_be, 'j>_'
+ it_behaves_like :array_pack_32bit_be, 'j_>'
+ end
+
+ describe "with modifier '>' and '!'" do
+ it_behaves_like :array_pack_32bit_be, 'j>!'
+ it_behaves_like :array_pack_32bit_be, 'j!>'
end
end
end
diff --git a/spec/ruby/core/array/pack/l_spec.rb b/spec/ruby/core/array/pack/l_spec.rb
index 5c1ad21d12..f6dfb1da83 100644
--- a/spec/ruby/core/array/pack/l_spec.rb
+++ b/spec/ruby/core/array/pack/l_spec.rb
@@ -1,8 +1,8 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
-require File.expand_path('../shared/basic', __FILE__)
-require File.expand_path('../shared/numeric_basic', __FILE__)
-require File.expand_path('../shared/integer', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
+require_relative 'shared/basic'
+require_relative 'shared/numeric_basic'
+require_relative 'shared/integer'
describe "Array#pack with format 'L'" do
it_behaves_like :array_pack_basic, 'L'
@@ -29,7 +29,7 @@ describe "Array#pack with format 'L'" do
it_behaves_like :array_pack_32bit_be, 'L>'
end
- guard -> { platform_is wordsize: 32 or platform_is :mingw32 } do
+ platform_is c_long_size: 32 do
describe "with modifier '<' and '_'" do
it_behaves_like :array_pack_32bit_le, 'L<_'
it_behaves_like :array_pack_32bit_le, 'L_<'
@@ -51,7 +51,7 @@ describe "Array#pack with format 'L'" do
end
end
- guard -> { platform_is wordsize: 64 and platform_is_not :mingw32 } do
+ platform_is c_long_size: 64 do
describe "with modifier '<' and '_'" do
it_behaves_like :array_pack_64bit_le, 'L<_'
it_behaves_like :array_pack_64bit_le, 'L_<'
@@ -83,7 +83,7 @@ describe "Array#pack with format 'l'" do
it_behaves_like :array_pack_32bit_be, 'l>'
end
- guard -> { platform_is wordsize: 32 or platform_is :mingw32 } do
+ platform_is c_long_size: 32 do
describe "with modifier '<' and '_'" do
it_behaves_like :array_pack_32bit_le, 'l<_'
it_behaves_like :array_pack_32bit_le, 'l_<'
@@ -105,7 +105,7 @@ describe "Array#pack with format 'l'" do
end
end
- guard -> { platform_is wordsize: 64 and platform_is_not :mingw32 } do
+ platform_is c_long_size: 64 do
describe "with modifier '<' and '_'" do
it_behaves_like :array_pack_64bit_le, 'l<_'
it_behaves_like :array_pack_64bit_le, 'l_<'
@@ -137,7 +137,7 @@ little_endian do
it_behaves_like :array_pack_32bit_le, 'l'
end
- guard -> { platform_is wordsize: 32 or platform_is :mingw32 } do
+ platform_is c_long_size: 32 do
describe "Array#pack with format 'L' with modifier '_'" do
it_behaves_like :array_pack_32bit_le, 'L_'
end
@@ -155,7 +155,7 @@ little_endian do
end
end
- guard -> { platform_is wordsize: 64 and platform_is_not :mingw32 } do
+ platform_is c_long_size: 64 do
describe "Array#pack with format 'L' with modifier '_'" do
it_behaves_like :array_pack_64bit_le, 'L_'
end
@@ -183,7 +183,7 @@ big_endian do
it_behaves_like :array_pack_32bit_be, 'l'
end
- guard -> { platform_is wordsize: 32 or platform_is :mingw32 } do
+ platform_is c_long_size: 32 do
describe "Array#pack with format 'L' with modifier '_'" do
it_behaves_like :array_pack_32bit_be, 'L_'
end
@@ -201,7 +201,7 @@ big_endian do
end
end
- guard -> { platform_is wordsize: 64 and platform_is_not :mingw32 } do
+ platform_is c_long_size: 64 do
describe "Array#pack with format 'L' with modifier '_'" do
it_behaves_like :array_pack_64bit_be, 'L_'
end
diff --git a/spec/ruby/core/array/pack/m_spec.rb b/spec/ruby/core/array/pack/m_spec.rb
index 36d996cba6..fb670d120e 100644
--- a/spec/ruby/core/array/pack/m_spec.rb
+++ b/spec/ruby/core/array/pack/m_spec.rb
@@ -1,12 +1,14 @@
-# -*- encoding: ascii-8bit -*-
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
-require File.expand_path('../shared/basic', __FILE__)
+# encoding: binary
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
+require_relative 'shared/basic'
+require_relative 'shared/taint'
describe "Array#pack with format 'M'" do
it_behaves_like :array_pack_basic, 'M'
it_behaves_like :array_pack_basic_non_float, 'M'
it_behaves_like :array_pack_arguments, 'M'
+ it_behaves_like :array_pack_taint, 'M'
it "encodes an empty string as an empty string" do
[""].pack("M").should == ""
@@ -78,8 +80,16 @@ describe "Array#pack with format 'M'" do
].should be_computed_by(:pack, "M")
end
- it "encodes a tab followed by a newline with an encoded newline" do
+ it "encodes a tab at the end of a line with an encoded newline" do
+ ["\t"].pack("M").should == "\t=\n"
["\t\n"].pack("M").should == "\t=\n\n"
+ ["abc\t\nxyz"].pack("M").should == "abc\t=\n\nxyz=\n"
+ end
+
+ it "encodes a space at the end of a line with an encoded newline" do
+ [" "].pack("M").should == " =\n"
+ [" \n"].pack("M").should == " =\n\n"
+ ["abc \nxyz"].pack("M").should == "abc =\n\nxyz=\n"
end
it "encodes 127..255 in hex format" do
@@ -145,7 +155,7 @@ describe "Array#pack with format 'M'" do
it "encodes a recursive array" do
empty = ArraySpecs.empty_recursive_array
- empty.pack('M').should be_an_instance_of(String)
+ empty.pack('M').should.instance_of?(String)
array = ArraySpecs.recursive_array
array.pack('M').should == "1=\n"
@@ -162,7 +172,7 @@ describe "Array#pack with format 'M'" do
obj = mock("pack M non-string")
obj.should_receive(:to_s).and_return(2)
- [obj].pack("M").should be_an_instance_of(String)
+ [obj].pack("M").should.instance_of?(String)
end
it "encodes a Symbol as a String" do
@@ -192,6 +202,7 @@ describe "Array#pack with format 'm'" do
it_behaves_like :array_pack_basic, 'm'
it_behaves_like :array_pack_basic_non_float, 'm'
it_behaves_like :array_pack_arguments, 'm'
+ it_behaves_like :array_pack_taint, 'm'
it "encodes an empty string as an empty string" do
[""].pack("m").should == ""
@@ -282,16 +293,16 @@ describe "Array#pack with format 'm'" do
it "raises a TypeError if #to_str does not return a String" do
obj = mock("pack m non-string")
- lambda { [obj].pack("m") }.should raise_error(TypeError)
+ -> { [obj].pack("m") }.should.raise(TypeError)
end
it "raises a TypeError if passed nil" do
- lambda { [nil].pack("m") }.should raise_error(TypeError)
+ -> { [nil].pack("m") }.should.raise(TypeError)
end
it "raises a TypeError if passed an Integer" do
- lambda { [0].pack("m") }.should raise_error(TypeError)
- lambda { [bignum_value].pack("m") }.should raise_error(TypeError)
+ -> { [0].pack("m") }.should.raise(TypeError)
+ -> { [bignum_value].pack("m") }.should.raise(TypeError)
end
it "does not emit a newline if passed zero as the count modifier" do
diff --git a/spec/ruby/core/array/pack/n_spec.rb b/spec/ruby/core/array/pack/n_spec.rb
index 72a83e082b..ab9409fc1e 100644
--- a/spec/ruby/core/array/pack/n_spec.rb
+++ b/spec/ruby/core/array/pack/n_spec.rb
@@ -1,8 +1,8 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
-require File.expand_path('../shared/basic', __FILE__)
-require File.expand_path('../shared/numeric_basic', __FILE__)
-require File.expand_path('../shared/integer', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
+require_relative 'shared/basic'
+require_relative 'shared/numeric_basic'
+require_relative 'shared/integer'
describe "Array#pack with format 'N'" do
it_behaves_like :array_pack_basic, 'N'
diff --git a/spec/ruby/core/array/pack/p_spec.rb b/spec/ruby/core/array/pack/p_spec.rb
index 65a08281e2..b023bf9110 100644
--- a/spec/ruby/core/array/pack/p_spec.rb
+++ b/spec/ruby/core/array/pack/p_spec.rb
@@ -1,11 +1,38 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
-require File.expand_path('../shared/basic', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
+require_relative 'shared/basic'
+require_relative 'shared/taint'
describe "Array#pack with format 'P'" do
it_behaves_like :array_pack_basic_non_float, 'P'
+ it_behaves_like :array_pack_taint, 'P'
+
+ it "produces as many bytes as there are in a pointer" do
+ ["hello"].pack("P").size.should == [0].pack("J").size
+ end
+
+ it "round-trips a string through pack and unpack" do
+ ["hello"].pack("P").unpack("P5").should == ["hello"]
+ end
+
+ it "with nil gives a null pointer" do
+ [nil].pack("P").unpack("J").should == [0]
+ end
end
describe "Array#pack with format 'p'" do
it_behaves_like :array_pack_basic_non_float, 'p'
+ it_behaves_like :array_pack_taint, 'p'
+
+ it "produces as many bytes as there are in a pointer" do
+ ["hello"].pack("p").size.should == [0].pack("J").size
+ end
+
+ it "round-trips a string through pack and unpack" do
+ ["hello"].pack("p").unpack("p").should == ["hello"]
+ end
+
+ it "with nil gives a null pointer" do
+ [nil].pack("p").unpack("J").should == [0]
+ end
end
diff --git a/spec/ruby/core/array/pack/percent_spec.rb b/spec/ruby/core/array/pack/percent_spec.rb
index 55d6de3424..29b119732a 100644
--- a/spec/ruby/core/array/pack/percent_spec.rb
+++ b/spec/ruby/core/array/pack/percent_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "Array#pack with format '%'" do
it "raises an Argument Error" do
- lambda { [1].pack("%") }.should raise_error(ArgumentError)
+ -> { [1].pack("%") }.should.raise(ArgumentError)
end
end
diff --git a/spec/ruby/core/array/pack/q_spec.rb b/spec/ruby/core/array/pack/q_spec.rb
index 83e115c54a..bd6b2a4b71 100644
--- a/spec/ruby/core/array/pack/q_spec.rb
+++ b/spec/ruby/core/array/pack/q_spec.rb
@@ -1,8 +1,8 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
-require File.expand_path('../shared/basic', __FILE__)
-require File.expand_path('../shared/numeric_basic', __FILE__)
-require File.expand_path('../shared/integer', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
+require_relative 'shared/basic'
+require_relative 'shared/numeric_basic'
+require_relative 'shared/integer'
describe "Array#pack with format 'Q'" do
it_behaves_like :array_pack_basic, 'Q'
diff --git a/spec/ruby/core/array/pack/r_spec.rb b/spec/ruby/core/array/pack/r_spec.rb
new file mode 100644
index 0000000000..cefe1388d2
--- /dev/null
+++ b/spec/ruby/core/array/pack/r_spec.rb
@@ -0,0 +1,89 @@
+# encoding: binary
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
+require_relative 'shared/basic'
+require_relative 'shared/numeric_basic'
+require_relative 'shared/integer'
+
+ruby_version_is "4.1" do
+ describe "Array#pack with format 'R'" do
+ it_behaves_like :array_pack_basic, 'R'
+ it_behaves_like :array_pack_basic_non_float, 'R'
+ it_behaves_like :array_pack_arguments, 'R'
+ it_behaves_like :array_pack_numeric_basic, 'R'
+ it_behaves_like :array_pack_integer, 'R'
+
+ it "encodes a ULEB128 integer" do
+ [ [[0], "\x00"],
+ [[1], "\x01"],
+ [[127], "\x7f"],
+ [[128], "\x80\x01"],
+ [[0x3fff], "\xff\x7f"],
+ [[0x4000], "\x80\x80\x01"],
+ [[0xffffffff], "\xff\xff\xff\xff\x0f"],
+ [[0x100000000], "\x80\x80\x80\x80\x10"],
+ [[0xffff_ffff_ffff_ffff], "\xff\xff\xff\xff\xff\xff\xff\xff\xff\x01"],
+ [[0xffff_ffff_ffff_ffff_ffff_ffff], "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x1f"],
+ ].should be_computed_by(:pack, "R")
+ end
+
+ it "encodes multiple values with '*' modifier" do
+ [1, 2].pack("R*").should == "\x01\x02"
+ [127, 128].pack("R*").should == "\x7f\x80\x01"
+ end
+
+ it "raises an ArgumentError when passed a negative value" do
+ -> { [-1].pack("R") }.should.raise(ArgumentError)
+ -> { [-100].pack("R") }.should.raise(ArgumentError)
+ end
+
+ it "round-trips values through pack and unpack" do
+ values = [0, 1, 127, 128, 0x3fff, 0x4000, 0xffffffff, 0x100000000]
+ values.pack("R*").unpack("R*").should == values
+ end
+ end
+
+ describe "Array#pack with format 'r'" do
+ it_behaves_like :array_pack_basic, 'r'
+ it_behaves_like :array_pack_basic_non_float, 'r'
+ it_behaves_like :array_pack_arguments, 'r'
+ it_behaves_like :array_pack_numeric_basic, 'r'
+ it_behaves_like :array_pack_integer, 'r'
+
+ it "encodes a SLEB128 integer" do
+ [ [[0], "\x00"],
+ [[1], "\x01"],
+ [[-1], "\x7f"],
+ [[-2], "\x7e"],
+ [[127], "\xff\x00"],
+ [[128], "\x80\x01"],
+ [[-127], "\x81\x7f"],
+ [[-128], "\x80\x7f"],
+ ].should be_computed_by(:pack, "r")
+ end
+
+ it "encodes larger positive numbers" do
+ [0x3fff].pack("r").should == "\xff\xff\x00"
+ [0x4000].pack("r").should == "\x80\x80\x01"
+ end
+
+ it "encodes larger negative numbers" do
+ [-0x3fff].pack("r").should == "\x81\x80\x7f"
+ [-0x4000].pack("r").should == "\x80\x80\x7f"
+ end
+
+ it "encodes very large numbers" do
+ [0xffff_ffff_ffff_ffff_ffff_ffff].pack("r").should == "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x1F"
+ [-0xffff_ffff_ffff_ffff_ffff_ffff].pack("r").should == "\x81\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x80\x60"
+ end
+
+ it "encodes multiple values with '*' modifier" do
+ [0, 1, -1].pack("r*").should == "\x00\x01\x7f"
+ end
+
+ it "round-trips values through pack and unpack" do
+ values = [0, 1, -1, 127, -127, 128, -128, 0x3fff, -0x3fff, 0x4000, -0x4000]
+ values.pack("r*").unpack("r*").should == values
+ end
+ end
+end
diff --git a/spec/ruby/core/array/pack/s_spec.rb b/spec/ruby/core/array/pack/s_spec.rb
index b2f8cb48f8..4212d6a0b1 100644
--- a/spec/ruby/core/array/pack/s_spec.rb
+++ b/spec/ruby/core/array/pack/s_spec.rb
@@ -1,8 +1,8 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
-require File.expand_path('../shared/basic', __FILE__)
-require File.expand_path('../shared/numeric_basic', __FILE__)
-require File.expand_path('../shared/integer', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
+require_relative 'shared/basic'
+require_relative 'shared/numeric_basic'
+require_relative 'shared/integer'
describe "Array#pack with format 'S'" do
it_behaves_like :array_pack_basic, 'S'
diff --git a/spec/ruby/core/array/pack/shared/basic.rb b/spec/ruby/core/array/pack/shared/basic.rb
index 39ab15308d..2894369c71 100644
--- a/spec/ruby/core/array/pack/shared/basic.rb
+++ b/spec/ruby/core/array/pack/shared/basic.rb
@@ -1,6 +1,6 @@
describe :array_pack_arguments, shared: true do
it "raises an ArgumentError if there are fewer elements than the format requires" do
- lambda { [].pack(pack_format(1)) }.should raise_error(ArgumentError)
+ -> { [].pack(pack_format(1)) }.should.raise(ArgumentError)
end
end
@@ -10,11 +10,11 @@ describe :array_pack_basic, shared: true do
end
it "raises a TypeError when passed nil" do
- lambda { [@obj].pack(nil) }.should raise_error(TypeError)
+ -> { [@obj].pack(nil) }.should.raise(TypeError)
end
it "raises a TypeError when passed an Integer" do
- lambda { [@obj].pack(1) }.should raise_error(TypeError)
+ -> { [@obj].pack(1) }.should.raise(TypeError)
end
end
@@ -24,42 +24,50 @@ describe :array_pack_basic_non_float, shared: true do
end
it "ignores whitespace in the format string" do
- [@obj, @obj].pack("a \t\n\v\f\r"+pack_format).should be_an_instance_of(String)
+ [@obj, @obj].pack("a \t\n\v\f\r"+pack_format).should.instance_of?(String)
+ end
+
+ it "ignores comments in the format string" do
+ # 2 additional directives ('a') are required for the X directive
+ [@obj, @obj, @obj, @obj].pack("aa #{pack_format} # some comment \n#{pack_format}").should.instance_of?(String)
+ end
+
+ it "raise ArgumentError when a directive is unknown" do
+ # additional directive ('a') is required for the X directive
+ -> { [@obj, @obj].pack("a K" + pack_format) }.should.raise(ArgumentError, /unknown pack directive 'K'/)
+ -> { [@obj, @obj].pack("a 0" + pack_format) }.should.raise(ArgumentError, /unknown pack directive '0'/)
+ -> { [@obj, @obj].pack("a :" + pack_format) }.should.raise(ArgumentError, /unknown pack directive ':'/)
end
it "calls #to_str to coerce the directives string" do
d = mock("pack directive")
d.should_receive(:to_str).and_return("x"+pack_format)
- [@obj, @obj].pack(d).should be_an_instance_of(String)
- end
-
- it "taints the output string if the format string is tainted" do
- [@obj, @obj].pack("x"+pack_format.taint).tainted?.should be_true
+ [@obj, @obj].pack(d).should.instance_of?(String)
end
end
describe :array_pack_basic_float, shared: true do
it "ignores whitespace in the format string" do
- [9.3, 4.7].pack(" \t\n\v\f\r"+pack_format).should be_an_instance_of(String)
+ [9.3, 4.7].pack(" \t\n\v\f\r"+pack_format).should.instance_of?(String)
+ end
+
+ it "ignores comments in the format string" do
+ [9.3, 4.7].pack(pack_format + "# some comment \n" + pack_format).should.instance_of?(String)
end
it "calls #to_str to coerce the directives string" do
d = mock("pack directive")
d.should_receive(:to_str).and_return("x"+pack_format)
- [1.2, 4.7].pack(d).should be_an_instance_of(String)
- end
-
- it "taints the output string if the format string is tainted" do
- [3.2, 2.8].pack("x"+pack_format.taint).tainted?.should be_true
+ [1.2, 4.7].pack(d).should.instance_of?(String)
end
end
describe :array_pack_no_platform, shared: true do
it "raises ArgumentError when the format modifier is '_'" do
- lambda{ [1].pack(pack_format("_")) }.should raise_error(ArgumentError)
+ ->{ [1].pack(pack_format("_")) }.should.raise(ArgumentError)
end
it "raises ArgumentError when the format modifier is '!'" do
- lambda{ [1].pack(pack_format("!")) }.should raise_error(ArgumentError)
+ ->{ [1].pack(pack_format("!")) }.should.raise(ArgumentError)
end
end
diff --git a/spec/ruby/core/array/pack/shared/encodings.rb b/spec/ruby/core/array/pack/shared/encodings.rb
index 3724a5d859..0b5a5cc8a0 100644
--- a/spec/ruby/core/array/pack/shared/encodings.rb
+++ b/spec/ruby/core/array/pack/shared/encodings.rb
@@ -5,12 +5,12 @@ describe :array_pack_hex, shared: true do
it "raises a TypeError if the object does not respond to #to_str" do
obj = mock("pack hex non-string")
- lambda { [obj].pack(pack_format) }.should raise_error(TypeError)
+ -> { [obj].pack(pack_format) }.should.raise(TypeError)
end
it "raises a TypeError if #to_str does not return a String" do
obj = mock("pack hex non-string")
obj.should_receive(:to_str).and_return(1)
- lambda { [obj].pack(pack_format) }.should raise_error(TypeError)
+ -> { [obj].pack(pack_format) }.should.raise(TypeError)
end
end
diff --git a/spec/ruby/core/array/pack/shared/float.rb b/spec/ruby/core/array/pack/shared/float.rb
index 082de27acd..c1efcd7677 100644
--- a/spec/ruby/core/array/pack/shared/float.rb
+++ b/spec/ruby/core/array/pack/shared/float.rb
@@ -1,4 +1,4 @@
-# -*- encoding: ascii-8bit -*-
+# encoding: binary
describe :array_pack_float_le, shared: true do
it "encodes a positive Float" do
@@ -14,7 +14,7 @@ describe :array_pack_float_le, shared: true do
end
it "raises a TypeError if passed a String representation of a floating point number" do
- lambda { ["13"].pack(pack_format) }.should raise_error(TypeError)
+ -> { ["13"].pack(pack_format) }.should.raise(TypeError)
end
it "encodes the number of array elements specified by the count modifier" do
@@ -25,8 +25,10 @@ describe :array_pack_float_le, shared: true do
[2.9, 1.4, 8.2].pack(pack_format("*")).should == "\x9a\x999@33\xb3?33\x03A"
end
- it "ignores NULL bytes between directives" do
- [5.3, 9.2].pack(pack_format("\000", 2)).should == "\x9a\x99\xa9@33\x13A"
+ it "raise ArgumentError for NULL bytes between directives" do
+ -> {
+ [5.3, 9.2].pack(pack_format("\000", 2))
+ }.should.raise(ArgumentError, /unknown pack directive/)
end
it "ignores spaces between directives" do
@@ -41,16 +43,9 @@ describe :array_pack_float_le, shared: true do
[-infinity_value].pack(pack_format).should == "\x00\x00\x80\xff"
end
- platform_is "86" do # x86 / x86_64
- it "encodes NaN" do
- [nan_value].pack(pack_format).should == "\x00\x00\xc0\xff"
- end
- end
-
- platform_is "powerpc64" do
- it "encodes NaN" do
- [nan_value].pack(pack_format).should == "\x00\x00\xc0\x7f"
- end
+ it "encodes NaN" do
+ nans = ["\x00\x00\xc0\xff", "\x00\x00\xc0\x7f", "\xFF\xFF\xFF\x7F"]
+ nans.should.include?([nan_value].pack(pack_format))
end
it "encodes a positive Float outside the range of a single precision float" do
@@ -60,6 +55,14 @@ describe :array_pack_float_le, shared: true do
it "encodes a negative Float outside the range of a single precision float" do
[-1e150].pack(pack_format).should == "\x00\x00\x80\xff"
end
+
+ it "encodes a bignum as a float" do
+ [2 ** 65].pack(pack_format).should == [(2 ** 65).to_f].pack(pack_format)
+ end
+
+ it "encodes a rational as a float" do
+ [Rational(3, 4)].pack(pack_format).should == [Rational(3, 4).to_f].pack(pack_format)
+ end
end
describe :array_pack_float_be, shared: true do
@@ -73,10 +76,15 @@ describe :array_pack_float_be, shared: true do
it "converts an Integer to a Float" do
[8].pack(pack_format).should == "A\x00\x00\x00"
+ [bignum_value].pack(pack_format).should == "_\x80\x00\x00"
+ end
+
+ it "converts a Rational to a Float" do
+ [Rational(8)].pack(pack_format).should == "A\x00\x00\x00"
end
it "raises a TypeError if passed a String representation of a floating point number" do
- lambda { ["13"].pack(pack_format) }.should raise_error(TypeError)
+ -> { ["13"].pack(pack_format) }.should.raise(TypeError)
end
it "encodes the number of array elements specified by the count modifier" do
@@ -87,8 +95,10 @@ describe :array_pack_float_be, shared: true do
[2.9, 1.4, 8.2].pack(pack_format("*")).should == "@9\x99\x9a?\xb333A\x0333"
end
- it "ignores NULL bytes between directives" do
- [5.3, 9.2].pack(pack_format("\000", 2)).should == "@\xa9\x99\x9aA\x1333"
+ it "raise ArgumentError for NULL bytes between directives" do
+ -> {
+ [5.3, 9.2].pack(pack_format("\000", 2))
+ }.should.raise(ArgumentError, /unknown pack directive/)
end
it "ignores spaces between directives" do
@@ -103,16 +113,9 @@ describe :array_pack_float_be, shared: true do
[-infinity_value].pack(pack_format).should == "\xff\x80\x00\x00"
end
- platform_is "86" do # x86 / x86_64
- it "encodes NaN" do
- [nan_value].pack(pack_format).should == "\xff\xc0\x00\x00"
- end
- end
-
- platform_is "powerpc64" do
- it "encodes NaN" do
- [nan_value].pack(pack_format).should == "\x7f\xc0\x00\x00"
- end
+ it "encodes NaN" do
+ nans = ["\xff\xc0\x00\x00", "\x7f\xc0\x00\x00", "\x7F\xFF\xFF\xFF"]
+ nans.should.include?([nan_value].pack(pack_format))
end
it "encodes a positive Float outside the range of a single precision float" do
@@ -135,10 +138,15 @@ describe :array_pack_double_le, shared: true do
it "converts an Integer to a Float" do
[8].pack(pack_format).should == "\x00\x00\x00\x00\x00\x00\x20@"
+ [bignum_value].pack(pack_format).should == "\x00\x00\x00\x00\x00\x00\xF0C"
+ end
+
+ it "converts a Rational to a Float" do
+ [Rational(8)].pack(pack_format).should == "\x00\x00\x00\x00\x00\x00 @"
end
it "raises a TypeError if passed a String representation of a floating point number" do
- lambda { ["13"].pack(pack_format) }.should raise_error(TypeError)
+ -> { ["13"].pack(pack_format) }.should.raise(TypeError)
end
it "encodes the number of array elements specified by the count modifier" do
@@ -149,8 +157,10 @@ describe :array_pack_double_le, shared: true do
[2.9, 1.4, 8.2].pack(pack_format("*")).should == "333333\x07@ffffff\xf6?ffffff\x20@"
end
- it "ignores NULL bytes between directives" do
- [5.3, 9.2].pack(pack_format("\000", 2)).should == "333333\x15@ffffff\x22@"
+ it "raise ArgumentError for NULL bytes between directives" do
+ -> {
+ [5.3, 9.2].pack(pack_format("\000", 2))
+ }.should.raise(ArgumentError, /unknown pack directive/)
end
it "ignores spaces between directives" do
@@ -165,16 +175,13 @@ describe :array_pack_double_le, shared: true do
[-infinity_value].pack(pack_format).should == "\x00\x00\x00\x00\x00\x00\xf0\xff"
end
- platform_is "86" do # x86 / x86_64
- it "encodes NaN" do
- [nan_value].pack(pack_format).should == "\x00\x00\x00\x00\x00\x00\xf8\xff"
- end
- end
-
- platform_is "powerpc64" do
- it "encodes NaN" do
- [nan_value].pack(pack_format).should == "\x00\x00\x00\x00\x00\x00\xf8\x7f"
- end
+ it "encodes NaN" do
+ nans = [
+ "\x00\x00\x00\x00\x00\x00\xf8\xff",
+ "\x00\x00\x00\x00\x00\x00\xf8\x7f",
+ "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x7F"
+ ]
+ nans.should.include?([nan_value].pack(pack_format))
end
it "encodes a positive Float outside the range of a single precision float" do
@@ -200,7 +207,7 @@ describe :array_pack_double_be, shared: true do
end
it "raises a TypeError if passed a String representation of a floating point number" do
- lambda { ["13"].pack(pack_format) }.should raise_error(TypeError)
+ -> { ["13"].pack(pack_format) }.should.raise(TypeError)
end
it "encodes the number of array elements specified by the count modifier" do
@@ -211,8 +218,10 @@ describe :array_pack_double_be, shared: true do
[2.9, 1.4, 8.2].pack(pack_format("*")).should == "@\x07333333?\xf6ffffff@\x20ffffff"
end
- it "ignores NULL bytes between directives" do
- [5.3, 9.2].pack(pack_format("\000", 2)).should == "@\x15333333@\x22ffffff"
+ it "raise ArgumentError for NULL bytes between directives" do
+ -> {
+ [5.3, 9.2].pack(pack_format("\000", 2))
+ }.should.raise(ArgumentError, /unknown pack directive/)
end
it "ignores spaces between directives" do
@@ -227,16 +236,13 @@ describe :array_pack_double_be, shared: true do
[-infinity_value].pack(pack_format).should == "\xff\xf0\x00\x00\x00\x00\x00\x00"
end
- platform_is "86" do # x86 / x86_64
- it "encodes NaN" do
- [nan_value].pack(pack_format).should == "\xff\xf8\x00\x00\x00\x00\x00\x00"
- end
- end
-
- platform_is "powerpc64" do
- it "encodes NaN" do
- [nan_value].pack(pack_format).should == "\x7f\xf8\x00\x00\x00\x00\x00\x00"
- end
+ it "encodes NaN" do
+ nans = [
+ "\xff\xf8\x00\x00\x00\x00\x00\x00",
+ "\x7f\xf8\x00\x00\x00\x00\x00\x00",
+ "\x7F\xFF\xFF\xFF\xFF\xFF\xFF\xFF"
+ ]
+ nans.should.include?([nan_value].pack(pack_format))
end
it "encodes a positive Float outside the range of a single precision float" do
diff --git a/spec/ruby/core/array/pack/shared/integer.rb b/spec/ruby/core/array/pack/shared/integer.rb
index 0df03bbfd1..1cdd386cc1 100644
--- a/spec/ruby/core/array/pack/shared/integer.rb
+++ b/spec/ruby/core/array/pack/shared/integer.rb
@@ -1,4 +1,4 @@
-# -*- encoding: ascii-8bit -*-
+# encoding: binary
describe :array_pack_16bit_le, shared: true do
it "encodes the least significant 16 bits of a positive number" do
@@ -41,9 +41,10 @@ describe :array_pack_16bit_le, shared: true do
str.should == "\x78\x65\xcd\xab\x21\x43"
end
- it "ignores NULL bytes between directives" do
- str = [0x1243_6578, 0xdef0_abcd].pack(pack_format("\000", 2))
- str.should == "\x78\x65\xcd\xab"
+ it "raise ArgumentError for NULL bytes between directives" do
+ -> {
+ [0x1243_6578, 0xdef0_abcd].pack(pack_format("\000", 2))
+ }.should.raise(ArgumentError, /unknown pack directive/)
end
it "ignores spaces between directives" do
@@ -93,9 +94,10 @@ describe :array_pack_16bit_be, shared: true do
str.should == "\x65\x78\xab\xcd\x43\x21"
end
- it "ignores NULL bytes between directives" do
- str = [0x1243_6578, 0xdef0_abcd].pack(pack_format("\000", 2))
- str.should == "\x65\x78\xab\xcd"
+ it "raise ArgumentError for NULL bytes between directives" do
+ -> {
+ [0x1243_6578, 0xdef0_abcd].pack(pack_format("\000", 2))
+ }.should.raise(ArgumentError, /unknown pack directive/)
end
it "ignores spaces between directives" do
@@ -145,9 +147,10 @@ describe :array_pack_32bit_le, shared: true do
str.should == "\x78\x65\x43\x12\xcd\xab\xf0\xde\x21\x43\x65\x78"
end
- it "ignores NULL bytes between directives" do
- str = [0x1243_6578, 0xdef0_abcd].pack(pack_format("\000", 2))
- str.should == "\x78\x65\x43\x12\xcd\xab\xf0\xde"
+ it "raise ArgumentError for NULL bytes between directives" do
+ -> {
+ [0x1243_6578, 0xdef0_abcd].pack(pack_format("\000", 2))
+ }.should.raise(ArgumentError, /unknown pack directive/)
end
it "ignores spaces between directives" do
@@ -197,9 +200,10 @@ describe :array_pack_32bit_be, shared: true do
str.should == "\x12\x43\x65\x78\xde\xf0\xab\xcd\x78\x65\x43\x21"
end
- it "ignores NULL bytes between directives" do
- str = [0x1243_6578, 0xdef0_abcd].pack(pack_format("\000", 2))
- str.should == "\x12\x43\x65\x78\xde\xf0\xab\xcd"
+ it "raise ArgumentError for NULL bytes between directives" do
+ -> {
+ [0x1243_6578, 0xdef0_abcd].pack(pack_format("\000", 2))
+ }.should.raise(ArgumentError, /unknown pack directive/)
end
it "ignores spaces between directives" do
@@ -225,7 +229,7 @@ describe :array_pack_32bit_le_platform, shared: true do
str.should == "\x78\x65\x43\x12\xcd\xab\xf0\xde\x21\x43\x65\x78"
end
- platform_is wordsize: 64 do
+ platform_is c_long_size: 64 do
it "encodes the least significant 32 bits of a number that is greater than 32 bits" do
[ [[0xff_7865_4321], "\x21\x43\x65\x78"],
[[-0xff_7865_4321], "\xdf\xbc\x9a\x87"]
@@ -251,7 +255,7 @@ describe :array_pack_32bit_be_platform, shared: true do
str.should == "\x12\x43\x65\x78\xde\xf0\xab\xcd\x78\x65\x43\x21"
end
- platform_is wordsize: 64 do
+ platform_is c_long_size: 64 do
it "encodes the least significant 32 bits of a number that is greater than 32 bits" do
[ [[0xff_7865_4321], "\x78\x65\x43\x21"],
[[-0xff_7865_4321], "\x87\x9a\xbc\xdf"]
@@ -309,9 +313,10 @@ describe :array_pack_64bit_le, shared: true do
str.should == "\x56\x78\x12\x34\xcd\xab\xf0\xde\xf0\xde\xba\xdc\x21\x43\x65\x78"
end
- it "ignores NULL bytes between directives" do
- str = [0xdef0_abcd_3412_7856, 0x7865_4321_dcba_def0].pack(pack_format("\000", 2))
- str.should == "\x56\x78\x12\x34\xcd\xab\xf0\xde\xf0\xde\xba\xdc\x21\x43\x65\x78"
+ it "raise ArgumentError for NULL bytes between directives" do
+ -> {
+ [0xdef0_abcd_3412_7856, 0x7865_4321_dcba_def0].pack(pack_format("\000", 2))
+ }.should.raise(ArgumentError, /unknown pack directive/)
end
it "ignores spaces between directives" do
@@ -369,9 +374,10 @@ describe :array_pack_64bit_be, shared: true do
str.should == "\xde\xf0\xab\xcd\x34\x12\x78\x56\x78\x65\x43\x21\xdc\xba\xde\xf0"
end
- it "ignores NULL bytes between directives" do
- str = [0xdef0_abcd_3412_7856, 0x7865_4321_dcba_def0].pack(pack_format("\000", 2))
- str.should == "\xde\xf0\xab\xcd\x34\x12\x78\x56\x78\x65\x43\x21\xdc\xba\xde\xf0"
+ it "raise ArgumentError for NULL bytes between directives" do
+ -> {
+ [0xdef0_abcd_3412_7856, 0x7865_4321_dcba_def0].pack(pack_format("\000", 2))
+ }.should.raise(ArgumentError, /unknown pack directive/)
end
it "ignores spaces between directives" do
diff --git a/spec/ruby/core/array/pack/shared/numeric_basic.rb b/spec/ruby/core/array/pack/shared/numeric_basic.rb
index 9224d6080e..6594914933 100644
--- a/spec/ruby/core/array/pack/shared/numeric_basic.rb
+++ b/spec/ruby/core/array/pack/shared/numeric_basic.rb
@@ -4,41 +4,47 @@ describe :array_pack_numeric_basic, shared: true do
end
it "raises a TypeError when passed nil" do
- lambda { [nil].pack(pack_format) }.should raise_error(TypeError)
+ -> { [nil].pack(pack_format) }.should.raise(TypeError)
end
it "raises a TypeError when passed true" do
- lambda { [true].pack(pack_format) }.should raise_error(TypeError)
+ -> { [true].pack(pack_format) }.should.raise(TypeError)
end
it "raises a TypeError when passed false" do
- lambda { [false].pack(pack_format) }.should raise_error(TypeError)
+ -> { [false].pack(pack_format) }.should.raise(TypeError)
end
- it "returns an ASCII-8BIT string" do
- [0xFF].pack(pack_format).encoding.should == Encoding::ASCII_8BIT
- [0xE3, 0x81, 0x82].pack(pack_format(3)).encoding.should == Encoding::ASCII_8BIT
+ it "returns a binary string" do
+ [0xFF].pack(pack_format).encoding.should == Encoding::BINARY
+ [0xE3, 0x81, 0x82].pack(pack_format(3)).encoding.should == Encoding::BINARY
end
end
describe :array_pack_integer, shared: true do
it "raises a TypeError when the object does not respond to #to_int" do
obj = mock('not an integer')
- lambda { [obj].pack(pack_format) }.should raise_error(TypeError)
+ -> { [obj].pack(pack_format) }.should.raise(TypeError)
end
it "raises a TypeError when passed a String" do
- lambda { ["5"].pack(pack_format) }.should raise_error(TypeError)
+ -> { ["5"].pack(pack_format) }.should.raise(TypeError)
end
end
describe :array_pack_float, shared: true do
it "raises a TypeError if a String does not represent a floating point number" do
- lambda { ["a"].pack(pack_format) }.should raise_error(TypeError)
+ -> { ["a"].pack(pack_format) }.should.raise(TypeError)
end
- it "raises a TypeError when the object does not respond to #to_f" do
- obj = mock('not an float')
- lambda { [obj].pack(pack_format) }.should raise_error(TypeError)
+ it "raises a TypeError when the object is not Numeric" do
+ obj = Object.new
+ -> { [obj].pack(pack_format) }.should.raise(TypeError, /can't convert Object into Float/)
+ end
+
+ it "raises a TypeError when the Numeric object does not respond to #to_f" do
+ klass = Class.new(Numeric)
+ obj = klass.new
+ -> { [obj].pack(pack_format) }.should.raise(TypeError)
end
end
diff --git a/spec/ruby/core/array/pack/shared/string.rb b/spec/ruby/core/array/pack/shared/string.rb
index cedb0886e2..b02257059f 100644
--- a/spec/ruby/core/array/pack/shared/string.rb
+++ b/spec/ruby/core/array/pack/shared/string.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
describe :array_pack_string, shared: true do
it "adds count bytes of a String to the output" do
["abc"].pack(pack_format(2)).should == "ab"
@@ -17,11 +17,11 @@ describe :array_pack_string, shared: true do
end
it "raises an ArgumentError when the Array is empty" do
- lambda { [].pack(pack_format) }.should raise_error(ArgumentError)
+ -> { [].pack(pack_format) }.should.raise(ArgumentError)
end
it "raises an ArgumentError when the Array has too few elements" do
- lambda { ["a"].pack(pack_format(nil, 2)) }.should raise_error(ArgumentError)
+ -> { ["a"].pack(pack_format(nil, 2)) }.should.raise(ArgumentError)
end
it "calls #to_str to convert the element to a String" do
@@ -33,48 +33,16 @@ describe :array_pack_string, shared: true do
it "raises a TypeError when the object does not respond to #to_str" do
obj = mock("not a string")
- lambda { [obj].pack(pack_format) }.should raise_error(TypeError)
- end
-
- it "returns a tainted string when a pack argument is tainted" do
- ["abcd".taint, 0x20].pack(pack_format("3C")).tainted?.should be_true
- end
-
- it "does not return a tainted string when the array is tainted" do
- ["abcd", 0x20].taint.pack(pack_format("3C")).tainted?.should be_false
- end
-
- it "returns a tainted string when the format is tainted" do
- ["abcd", 0x20].pack(pack_format("3C").taint).tainted?.should be_true
- end
-
- it "returns a tainted string when an empty format is tainted" do
- ["abcd", 0x20].pack("".taint).tainted?.should be_true
- end
-
- it "returns a untrusted string when the format is untrusted" do
- ["abcd", 0x20].pack(pack_format("3C").untrust).untrusted?.should be_true
- end
-
- it "returns a untrusted string when the empty format is untrusted" do
- ["abcd", 0x20].pack("".untrust).untrusted?.should be_true
- end
-
- it "returns a untrusted string when a pack argument is untrusted" do
- ["abcd".untrust, 0x20].pack(pack_format("3C")).untrusted?.should be_true
- end
-
- it "returns a trusted string when the array is untrusted" do
- ["abcd", 0x20].untrust.pack(pack_format("3C")).untrusted?.should be_false
+ -> { [obj].pack(pack_format) }.should.raise(TypeError)
end
it "returns a string in encoding of common to the concatenated results" do
f = pack_format("*")
- [ [["\u{3042 3044 3046 3048}", 0x2000B].pack(f+"U"), Encoding::ASCII_8BIT],
- [["abcde\xd1", "\xFF\xFe\x81\x82"].pack(f+"u"), Encoding::ASCII_8BIT],
- [["a".force_encoding("ascii"), "\xFF\xFe\x81\x82"].pack(f+"u"), Encoding::ASCII_8BIT],
+ [ [["\u{3042 3044 3046 3048}", 0x2000B].pack(f+"U"), Encoding::BINARY],
+ [["abcde\xd1", "\xFF\xFe\x81\x82"].pack(f+"u"), Encoding::BINARY],
+ [["a".dup.force_encoding("ascii"), "\xFF\xFe\x81\x82"].pack(f+"u"), Encoding::BINARY],
# under discussion [ruby-dev:37294]
- [["\u{3042 3044 3046 3048}", 1].pack(f+"N"), Encoding::ASCII_8BIT]
+ [["\u{3042 3044 3046 3048}", 1].pack(f+"N"), Encoding::BINARY]
].should be_computed_by(:encoding)
end
end
diff --git a/spec/ruby/core/array/pack/shared/taint.rb b/spec/ruby/core/array/pack/shared/taint.rb
new file mode 100644
index 0000000000..2c2b011c34
--- /dev/null
+++ b/spec/ruby/core/array/pack/shared/taint.rb
@@ -0,0 +1,2 @@
+describe :array_pack_taint, shared: true do
+end
diff --git a/spec/ruby/core/array/pack/shared/unicode.rb b/spec/ruby/core/array/pack/shared/unicode.rb
index e16110c491..58ba8a8b23 100644
--- a/spec/ruby/core/array/pack/shared/unicode.rb
+++ b/spec/ruby/core/array/pack/shared/unicode.rb
@@ -26,7 +26,7 @@ describe :array_pack_unicode, shared: true do
it "constructs strings with valid encodings" do
str = [0x85].pack("U*")
str.should == "\xc2\x85"
- str.valid_encoding?.should be_true
+ str.valid_encoding?.should == true
end
it "encodes values larger than UTF-8 max codepoints" do
@@ -64,11 +64,13 @@ describe :array_pack_unicode, shared: true do
it "raises a TypeError if #to_int does not return an Integer" do
obj = mock('to_int')
obj.should_receive(:to_int).and_return("5")
- lambda { [obj].pack("U") }.should raise_error(TypeError)
+ -> { [obj].pack("U") }.should.raise(TypeError)
end
- it "ignores NULL bytes between directives" do
- [1, 2, 3].pack("U\x00U").should == "\x01\x02"
+ it "raise ArgumentError for NULL bytes between directives" do
+ -> {
+ [1, 2, 3].pack("U\x00U")
+ }.should.raise(ArgumentError, /unknown pack directive/)
end
it "ignores spaces between directives" do
@@ -76,11 +78,11 @@ describe :array_pack_unicode, shared: true do
end
it "raises a RangeError if passed a negative number" do
- lambda { [-1].pack("U") }.should raise_error(RangeError)
+ -> { [-1].pack("U") }.should.raise(RangeError)
end
it "raises a RangeError if passed a number larger than an unsigned 32-bit integer" do
- lambda { [2**32].pack("U") }.should raise_error(RangeError)
+ -> { [2**32].pack("U") }.should.raise(RangeError)
end
it "sets the output string to UTF-8 encoding" do
diff --git a/spec/ruby/core/array/pack/u_spec.rb b/spec/ruby/core/array/pack/u_spec.rb
index 0bc78fcb88..c6a0d77eb2 100644
--- a/spec/ruby/core/array/pack/u_spec.rb
+++ b/spec/ruby/core/array/pack/u_spec.rb
@@ -1,8 +1,9 @@
-# -*- encoding: ascii-8bit -*-
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
-require File.expand_path('../shared/basic', __FILE__)
-require File.expand_path('../shared/unicode', __FILE__)
+# encoding: binary
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
+require_relative 'shared/basic'
+require_relative 'shared/unicode'
+require_relative 'shared/taint'
describe "Array#pack with format 'U'" do
it_behaves_like :array_pack_basic, 'U'
@@ -15,6 +16,17 @@ describe "Array#pack with format 'u'" do
it_behaves_like :array_pack_basic, 'u'
it_behaves_like :array_pack_basic_non_float, 'u'
it_behaves_like :array_pack_arguments, 'u'
+ it_behaves_like :array_pack_taint, 'u'
+
+ it "calls #to_str to convert an Object to a String" do
+ obj = mock("pack u string")
+ obj.should_receive(:to_str).and_return("``abcdef")
+ [obj].pack("u*").should == "(8&!A8F-D968`\n"
+ end
+
+ it "will not implicitly convert a number to a string" do
+ -> { [0].pack('u') }.should.raise(TypeError)
+ end
it "encodes an empty string as an empty string" do
[""].pack("u").should == ""
@@ -110,16 +122,16 @@ describe "Array#pack with format 'u'" do
it "raises a TypeError if #to_str does not return a String" do
obj = mock("pack m non-string")
- lambda { [obj].pack("u") }.should raise_error(TypeError)
+ -> { [obj].pack("u") }.should.raise(TypeError)
end
it "raises a TypeError if passed nil" do
- lambda { [nil].pack("u") }.should raise_error(TypeError)
+ -> { [nil].pack("u") }.should.raise(TypeError)
end
it "raises a TypeError if passed an Integer" do
- lambda { [0].pack("u") }.should raise_error(TypeError)
- lambda { [bignum_value].pack("u") }.should raise_error(TypeError)
+ -> { [0].pack("u") }.should.raise(TypeError)
+ -> { [bignum_value].pack("u") }.should.raise(TypeError)
end
it "sets the output string to US-ASCII encoding" do
diff --git a/spec/ruby/core/array/pack/v_spec.rb b/spec/ruby/core/array/pack/v_spec.rb
index 8ebb863686..d3932c84af 100644
--- a/spec/ruby/core/array/pack/v_spec.rb
+++ b/spec/ruby/core/array/pack/v_spec.rb
@@ -1,8 +1,8 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
-require File.expand_path('../shared/basic', __FILE__)
-require File.expand_path('../shared/numeric_basic', __FILE__)
-require File.expand_path('../shared/integer', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
+require_relative 'shared/basic'
+require_relative 'shared/numeric_basic'
+require_relative 'shared/integer'
describe "Array#pack with format 'V'" do
it_behaves_like :array_pack_basic, 'V'
diff --git a/spec/ruby/core/array/pack/w_spec.rb b/spec/ruby/core/array/pack/w_spec.rb
index 9ada3e84cb..263e2a2288 100644
--- a/spec/ruby/core/array/pack/w_spec.rb
+++ b/spec/ruby/core/array/pack/w_spec.rb
@@ -1,8 +1,8 @@
-# -*- encoding: ascii-8bit -*-
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
-require File.expand_path('../shared/basic', __FILE__)
-require File.expand_path('../shared/numeric_basic', __FILE__)
+# encoding: binary
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
+require_relative 'shared/basic'
+require_relative 'shared/numeric_basic'
describe "Array#pack with format 'w'" do
it_behaves_like :array_pack_basic, 'w'
@@ -24,8 +24,10 @@ describe "Array#pack with format 'w'" do
[obj].pack("w").should == "\x05"
end
- it "ignores NULL bytes between directives" do
- [1, 2, 3].pack("w\x00w").should == "\x01\x02"
+ it "raise ArgumentError for NULL bytes between directives" do
+ -> {
+ [1, 2, 3].pack("w\x00w")
+ }.should.raise(ArgumentError, /unknown pack directive/)
end
it "ignores spaces between directives" do
@@ -33,10 +35,10 @@ describe "Array#pack with format 'w'" do
end
it "raises an ArgumentError when passed a negative value" do
- lambda { [-1].pack("w") }.should raise_error(ArgumentError)
+ -> { [-1].pack("w") }.should.raise(ArgumentError)
end
- it "returns an ASCII-8BIT string" do
- [1].pack('w').encoding.should == Encoding::ASCII_8BIT
+ it "returns a binary string" do
+ [1].pack('w').encoding.should == Encoding::BINARY
end
end
diff --git a/spec/ruby/core/array/pack/x_spec.rb b/spec/ruby/core/array/pack/x_spec.rb
index 8d54ab84ee..7ff587a01e 100644
--- a/spec/ruby/core/array/pack/x_spec.rb
+++ b/spec/ruby/core/array/pack/x_spec.rb
@@ -1,7 +1,7 @@
-# -*- encoding: ascii-8bit -*-
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
-require File.expand_path('../shared/basic', __FILE__)
+# encoding: binary
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
+require_relative 'shared/basic'
describe "Array#pack with format 'x'" do
it_behaves_like :array_pack_basic, 'x'
@@ -30,6 +30,7 @@ describe "Array#pack with format 'x'" do
it "does not add a NULL byte when passed the '*' modifier" do
[].pack("x*").should == ""
+ [1, 2].pack("Cx*C").should == "\x01\x02"
end
end
@@ -55,10 +56,10 @@ describe "Array#pack with format 'X'" do
end
it "raises an ArgumentError if the output string is empty" do
- lambda { [1, 2, 3].pack("XC") }.should raise_error(ArgumentError)
+ -> { [1, 2, 3].pack("XC") }.should.raise(ArgumentError)
end
it "raises an ArgumentError if the count modifier is greater than the bytes in the string" do
- lambda { [1, 2, 3].pack("C2X3") }.should raise_error(ArgumentError)
+ -> { [1, 2, 3].pack("C2X3") }.should.raise(ArgumentError)
end
end
diff --git a/spec/ruby/core/array/pack/z_spec.rb b/spec/ruby/core/array/pack/z_spec.rb
index b28a460a8e..5cd084c825 100644
--- a/spec/ruby/core/array/pack/z_spec.rb
+++ b/spec/ruby/core/array/pack/z_spec.rb
@@ -1,20 +1,32 @@
-# -*- encoding: ascii-8bit -*-
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
-require File.expand_path('../shared/basic', __FILE__)
-require File.expand_path('../shared/string', __FILE__)
+# encoding: binary
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
+require_relative 'shared/basic'
+require_relative 'shared/string'
+require_relative 'shared/taint'
describe "Array#pack with format 'Z'" do
it_behaves_like :array_pack_basic, 'Z'
it_behaves_like :array_pack_basic_non_float, 'Z'
it_behaves_like :array_pack_no_platform, 'Z'
it_behaves_like :array_pack_string, 'Z'
+ it_behaves_like :array_pack_taint, 'Z'
+
+ it "calls #to_str to convert an Object to a String" do
+ obj = mock("pack Z string")
+ obj.should_receive(:to_str).and_return("``abcdef")
+ [obj].pack("Z*").should == "``abcdef\x00"
+ end
+
+ it "will not implicitly convert a number to a string" do
+ -> { [0].pack('Z') }.should.raise(TypeError)
+ end
it "adds all the bytes and appends a NULL byte when passed the '*' modifier" do
["abc"].pack("Z*").should == "abc\x00"
end
- it "padds the output with NULL bytes when the count exceeds the size of the String" do
+ it "pads the output with NULL bytes when the count exceeds the size of the String" do
["abc"].pack("Z6").should == "abc\x00\x00\x00"
end
diff --git a/spec/ruby/core/array/partition_spec.rb b/spec/ruby/core/array/partition_spec.rb
index 787b574c28..bd3f3a6b6f 100644
--- a/spec/ruby/core/array/partition_spec.rb
+++ b/spec/ruby/core/array/partition_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Array#partition" do
it "returns two arrays" do
@@ -36,8 +36,8 @@ describe "Array#partition" do
it "does not return subclass instances on Array subclasses" do
result = ArraySpecs::MyArray[1, 2, 3].partition { |x| x % 2 == 0 }
- result.should be_an_instance_of(Array)
- result[0].should be_an_instance_of(Array)
- result[1].should be_an_instance_of(Array)
+ result.should.instance_of?(Array)
+ result[0].should.instance_of?(Array)
+ result[1].should.instance_of?(Array)
end
end
diff --git a/spec/ruby/core/array/permutation_spec.rb b/spec/ruby/core/array/permutation_spec.rb
index c0eba57a3e..b5df84b52b 100644
--- a/spec/ruby/core/array/permutation_spec.rb
+++ b/spec/ruby/core/array/permutation_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Array#permutation" do
@@ -11,7 +11,7 @@ describe "Array#permutation" do
it "returns an Enumerator of all permutations when called without a block or arguments" do
enum = @numbers.permutation
- enum.should be_an_instance_of(Enumerator)
+ enum.should.instance_of?(Enumerator)
enum.to_a.sort.should == [
[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]
].sort
@@ -19,13 +19,13 @@ describe "Array#permutation" do
it "returns an Enumerator of permutations of given length when called with an argument but no block" do
enum = @numbers.permutation(1)
- enum.should be_an_instance_of(Enumerator)
+ enum.should.instance_of?(Enumerator)
enum.to_a.sort.should == [[1],[2],[3]]
end
it "yields all permutations to the block then returns self when called with block but no arguments" do
array = @numbers.permutation {|n| @yielded << n}
- array.should be_an_instance_of(Array)
+ array.should.instance_of?(Array)
array.sort.should == @numbers.sort
@yielded.sort.should == [
[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]
@@ -34,7 +34,7 @@ describe "Array#permutation" do
it "yields all permutations of given length to the block then returns self when called with block and argument" do
array = @numbers.permutation(2) {|n| @yielded << n}
- array.should be_an_instance_of(Array)
+ array.should.instance_of?(Array)
array.sort.should == @numbers.sort
@yielded.sort.should == [[1,2],[1,3],[2,1],[2,3],[3,1],[3,2]].sort
end
@@ -78,7 +78,7 @@ describe "Array#permutation" do
[3, 1], [3, 2], [3, [4, 5]],
[[4, 5], 1], [[4, 5], 2], [[4, 5], 3]
]
- expected.each {|e| got.include?(e).should be_true}
+ expected.each {|e| got.include?(e).should == true}
got.size.should == expected.size
end
diff --git a/spec/ruby/core/array/plus_spec.rb b/spec/ruby/core/array/plus_spec.rb
index 4517087550..7ead927fc0 100644
--- a/spec/ruby/core/array/plus_spec.rb
+++ b/spec/ruby/core/array/plus_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Array#+" do
it "concatenates two arrays" do
@@ -14,10 +14,23 @@ describe "Array#+" do
(ary + ary).should == [1, 2, 3, 1, 2, 3]
end
- it "tries to convert the passed argument to an Array using #to_ary" do
- obj = mock('["x", "y"]')
- obj.should_receive(:to_ary).and_return(["x", "y"])
- ([1, 2, 3] + obj).should == [1, 2, 3, "x", "y"]
+ describe "converts the passed argument to an Array using #to_ary" do
+ it "successfully concatenates the resulting array from the #to_ary call" do
+ obj = mock('["x", "y"]')
+ obj.should_receive(:to_ary).and_return(["x", "y"])
+ ([1, 2, 3] + obj).should == [1, 2, 3, "x", "y"]
+ end
+
+ it "raises a TypeError if the given argument can't be converted to an array" do
+ -> { [1, 2, 3] + nil }.should.raise(TypeError)
+ -> { [1, 2, 3] + "abc" }.should.raise(TypeError)
+ end
+
+ it "raises a NoMethodError if the given argument raises a NoMethodError during type coercion to an Array" do
+ obj = mock("hello")
+ obj.should_receive(:to_ary).and_raise(NoMethodError)
+ -> { [1, 2, 3] + obj }.should.raise(NoMethodError)
+ end
end
it "properly handles recursive arrays" do
@@ -32,26 +45,12 @@ describe "Array#+" do
end
it "does return subclass instances with Array subclasses" do
- (ArraySpecs::MyArray[1, 2, 3] + []).should be_an_instance_of(Array)
- (ArraySpecs::MyArray[1, 2, 3] + ArraySpecs::MyArray[]).should be_an_instance_of(Array)
- ([1, 2, 3] + ArraySpecs::MyArray[]).should be_an_instance_of(Array)
+ (ArraySpecs::MyArray[1, 2, 3] + []).should.instance_of?(Array)
+ (ArraySpecs::MyArray[1, 2, 3] + ArraySpecs::MyArray[]).should.instance_of?(Array)
+ ([1, 2, 3] + ArraySpecs::MyArray[]).should.instance_of?(Array)
end
it "does not call to_ary on array subclasses" do
([5, 6] + ArraySpecs::ToAryArray[1, 2]).should == [5, 6, 1, 2]
end
-
- it "does not get infected even if an original array is tainted" do
- ([1, 2] + [3, 4]).tainted?.should be_false
- ([1, 2].taint + [3, 4]).tainted?.should be_false
- ([1, 2] + [3, 4].taint).tainted?.should be_false
- ([1, 2].taint + [3, 4].taint).tainted?.should be_false
- end
-
- it "does not infected even if an original array is untrusted" do
- ([1, 2] + [3, 4]).untrusted?.should be_false
- ([1, 2].untrust + [3, 4]).untrusted?.should be_false
- ([1, 2] + [3, 4].untrust).untrusted?.should be_false
- ([1, 2].untrust + [3, 4].untrust).untrusted?.should be_false
- end
end
diff --git a/spec/ruby/core/array/pop_spec.rb b/spec/ruby/core/array/pop_spec.rb
index ea649c6585..069083331c 100644
--- a/spec/ruby/core/array/pop_spec.rb
+++ b/spec/ruby/core/array/pop_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Array#pop" do
it "removes and returns the last element of the array" do
@@ -30,28 +30,12 @@ describe "Array#pop" do
array.pop.should == [1, 'two', 3.0, array, array, array, array]
end
- it "keeps taint status" do
- a = [1, 2].taint
- a.pop
- a.tainted?.should be_true
- a.pop
- a.tainted?.should be_true
+ it "raises a FrozenError on a frozen array" do
+ -> { ArraySpecs.frozen_array.pop }.should.raise(FrozenError)
end
- it "raises a RuntimeError on a frozen array" do
- lambda { ArraySpecs.frozen_array.pop }.should raise_error(RuntimeError)
- end
-
- it "raises a RuntimeError on an empty frozen array" do
- lambda { ArraySpecs.empty_frozen_array.pop }.should raise_error(RuntimeError)
- end
-
- it "keeps untrusted status" do
- a = [1, 2].untrust
- a.pop
- a.untrusted?.should be_true
- a.pop
- a.untrusted?.should be_true
+ it "raises a FrozenError on an empty frozen array" do
+ -> { ArraySpecs.empty_frozen_array.pop }.should.raise(FrozenError)
end
describe "passed a number n as an argument" do
@@ -87,7 +71,7 @@ describe "Array#pop" do
popped2.should == []
a.should == []
- popped1.should_not equal(popped2)
+ popped1.should_not.equal?(popped2)
end
it "returns whole elements if n exceeds size of the array" do
@@ -98,14 +82,14 @@ describe "Array#pop" do
it "does not return self even when it returns whole elements" do
a = [1, 2, 3, 4, 5]
- a.pop(5).should_not equal(a)
+ a.pop(5).should_not.equal?(a)
a = [1, 2, 3, 4, 5]
- a.pop(6).should_not equal(a)
+ a.pop(6).should_not.equal?(a)
end
it "raises an ArgumentError if n is negative" do
- lambda{ [1, 2, 3].pop(-1) }.should raise_error(ArgumentError)
+ ->{ [1, 2, 3].pop(-1) }.should.raise(ArgumentError)
end
it "tries to convert n to an Integer using #to_int" do
@@ -120,49 +104,21 @@ describe "Array#pop" do
end
it "raises a TypeError when the passed n cannot be coerced to Integer" do
- lambda{ [1, 2].pop("cat") }.should raise_error(TypeError)
- lambda{ [1, 2].pop(nil) }.should raise_error(TypeError)
+ ->{ [1, 2].pop("cat") }.should.raise(TypeError)
+ ->{ [1, 2].pop(nil) }.should.raise(TypeError)
end
it "raises an ArgumentError if more arguments are passed" do
- lambda{ [1, 2].pop(1, 2) }.should raise_error(ArgumentError)
+ ->{ [1, 2].pop(1, 2) }.should.raise(ArgumentError)
end
it "does not return subclass instances with Array subclass" do
- ArraySpecs::MyArray[1, 2, 3].pop(2).should be_an_instance_of(Array)
- end
-
- it "returns an untainted array even if the array is tainted" do
- ary = [1, 2].taint
- ary.pop(2).tainted?.should be_false
- ary.pop(0).tainted?.should be_false
- end
-
- it "keeps taint status" do
- a = [1, 2].taint
- a.pop(2)
- a.tainted?.should be_true
- a.pop(2)
- a.tainted?.should be_true
- end
-
- it "returns a trusted array even if the array is untrusted" do
- ary = [1, 2].untrust
- ary.pop(2).untrusted?.should be_false
- ary.pop(0).untrusted?.should be_false
- end
-
- it "raises a RuntimeError on a frozen array" do
- lambda { ArraySpecs.frozen_array.pop(2) }.should raise_error(RuntimeError)
- lambda { ArraySpecs.frozen_array.pop(0) }.should raise_error(RuntimeError)
+ ArraySpecs::MyArray[1, 2, 3].pop(2).should.instance_of?(Array)
end
- it "keeps untrusted status" do
- a = [1, 2].untrust
- a.pop(2)
- a.untrusted?.should be_true
- a.pop(2)
- a.untrusted?.should be_true
+ it "raises a FrozenError on a frozen array" do
+ -> { ArraySpecs.frozen_array.pop(2) }.should.raise(FrozenError)
+ -> { ArraySpecs.frozen_array.pop(0) }.should.raise(FrozenError)
end
end
end
diff --git a/spec/ruby/core/array/prepend_spec.rb b/spec/ruby/core/array/prepend_spec.rb
new file mode 100644
index 0000000000..2d0ce31c71
--- /dev/null
+++ b/spec/ruby/core/array/prepend_spec.rb
@@ -0,0 +1,7 @@
+require_relative '../../spec_helper'
+
+describe "Array#prepend" do
+ it "is an alias of Array#unshift" do
+ Array.instance_method(:prepend).should == Array.instance_method(:unshift)
+ end
+end
diff --git a/spec/ruby/core/array/product_spec.rb b/spec/ruby/core/array/product_spec.rb
index 1ab38e34be..837f0eaf34 100644
--- a/spec/ruby/core/array/product_spec.rb
+++ b/spec/ruby/core/array/product_spec.rb
@@ -1,14 +1,19 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Array#product" do
it "returns converted arguments using :to_ary" do
- lambda{ [1].product(2..3) }.should raise_error(TypeError)
- ar = ArraySpecs::ArrayConvertable.new(2,3)
+ ->{ [1].product(2..3) }.should.raise(TypeError)
+ ar = ArraySpecs::ArrayConvertible.new(2,3)
[1].product(ar).should == [[1,2],[1,3]]
ar.called.should == :to_ary
end
+ it "returns converted arguments using :method_missing" do
+ ar = ArraySpecs::ArrayMethodMissing.new(2,3)
+ [1].product(ar).should == [[1,2],[1,3]]
+ end
+
it "returns the expected result" do
[1,2].product([3,4,5],[6,8]).should == [[1, 3, 6], [1, 3, 8], [1, 4, 6], [1, 4, 8], [1, 5, 6], [1, 5, 8],
[2, 3, 6], [2, 3, 8], [2, 4, 6], [2, 4, 8], [2, 5, 6], [2, 5, 8]]
@@ -24,9 +29,9 @@ describe "Array#product" do
it "does not attempt to produce an unreasonable number of products" do
a = (0..100).to_a
- lambda do
+ -> do
a.product(a, a, a, a, a, a, a, a, a, a)
- end.should raise_error(RangeError)
+ end.should.raise(RangeError)
end
describe "when given a block" do
@@ -38,7 +43,7 @@ describe "Array#product" do
acc = []
[1,2].product([3,4,5],[],[6,8]){|array| acc << array}
- acc.should be_empty
+ acc.should.empty?
end
it "returns self" do
@@ -49,20 +54,20 @@ describe "Array#product" do
it "will ignore unreasonable numbers of products and yield anyway" do
a = (0..100).to_a
- lambda do
+ -> do
a.product(a, a, a, a, a, a, a, a, a, a)
- end.should raise_error(RangeError)
+ end.should.raise(RangeError)
end
end
describe "when given an empty block" do
it "returns self" do
arr = [1,2]
- arr.product([3,4,5],[6,8]){}.should equal(arr)
+ arr.product([3,4,5],[6,8]){}.should.equal?(arr)
arr = []
- arr.product([3,4,5],[6,8]){}.should equal(arr)
+ arr.product([3,4,5],[6,8]){}.should.equal?(arr)
arr = [1,2]
- arr.product([]){}.should equal(arr)
+ arr.product([]){}.should.equal?(arr)
end
end
end
diff --git a/spec/ruby/core/array/push_spec.rb b/spec/ruby/core/array/push_spec.rb
index 562a6888dd..6255a84371 100644
--- a/spec/ruby/core/array/push_spec.rb
+++ b/spec/ruby/core/array/push_spec.rb
@@ -1,11 +1,11 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Array#push" do
it "appends the arguments to the array" do
a = [ "a", "b", "c" ]
- a.push("d", "e", "f").should equal(a)
- a.push().should == ["a", "b", "c", "d", "e", "f"]
+ a.push("d", "e", "f").should.equal?(a)
+ a.push.should == ["a", "b", "c", "d", "e", "f"]
a.push(5)
a.should == ["a", "b", "c", "d", "e", "f", 5]
@@ -29,8 +29,8 @@ describe "Array#push" do
array.push(:last).should == [1, 'two', 3.0, array, array, array, array, array, :last]
end
- it "raises a RuntimeError on a frozen array" do
- lambda { ArraySpecs.frozen_array.push(1) }.should raise_error(RuntimeError)
- lambda { ArraySpecs.frozen_array.push }.should raise_error(RuntimeError)
+ it "raises a FrozenError on a frozen array" do
+ -> { ArraySpecs.frozen_array.push(1) }.should.raise(FrozenError)
+ -> { ArraySpecs.frozen_array.push }.should.raise(FrozenError)
end
end
diff --git a/spec/ruby/core/array/rassoc_spec.rb b/spec/ruby/core/array/rassoc_spec.rb
index cf3daccfc9..95e4ed1892 100644
--- a/spec/ruby/core/array/rassoc_spec.rb
+++ b/spec/ruby/core/array/rassoc_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Array#rassoc" do
it "returns the first contained array whose second element is == object" do
@@ -12,11 +12,11 @@ describe "Array#rassoc" do
it "properly handles recursive arrays" do
empty = ArraySpecs.empty_recursive_array
- empty.rassoc([]).should be_nil
+ empty.rassoc([]).should == nil
[[empty, empty]].rassoc(empty).should == [empty, empty]
array = ArraySpecs.recursive_array
- array.rassoc(array).should be_nil
+ array.rassoc(array).should == nil
[[empty, array]].rassoc(array).should == [empty, array]
end
@@ -28,11 +28,23 @@ describe "Array#rassoc" do
[[1, :foobar], [2, o], [3, mock('foo')]].rassoc(key).should == [2, o]
end
- it "does not check the last element in each contained but speficically the second" do
+ it "does not check the last element in each contained but specifically the second" do
key = 'foobar'
o = mock('foobar')
def o.==(other); other == 'foobar'; end
[[1, :foobar, o], [2, o, 1], [3, mock('foo')]].rassoc(key).should == [2, o, 1]
end
+
+ it "calls to_ary on non-array elements" do
+ s1 = [1, 2]
+ s2 = ArraySpecs::ArrayConvertible.new(2, 3)
+ a = [s1, s2]
+
+ s1.should_not_receive(:to_ary)
+ a.rassoc(2).should.equal?(s1)
+
+ a.rassoc(3).should == [2, 3]
+ s2.called.should.equal?(:to_ary)
+ end
end
diff --git a/spec/ruby/core/array/reject_spec.rb b/spec/ruby/core/array/reject_spec.rb
index 857cbf6a4d..8d237b3a75 100644
--- a/spec/ruby/core/array/reject_spec.rb
+++ b/spec/ruby/core/array/reject_spec.rb
@@ -1,17 +1,18 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/enumeratorize', __FILE__)
-require File.expand_path('../shared/delete_if', __FILE__)
-require File.expand_path('../../enumerable/shared/enumeratorized', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/enumeratorize'
+require_relative 'shared/delete_if'
+require_relative 'shared/iterable_and_tolerating_size_increasing'
+require_relative '../enumerable/shared/enumeratorized'
describe "Array#reject" do
it "returns a new array without elements for which block is true" do
ary = [1, 2, 3, 4, 5]
ary.reject { true }.should == []
ary.reject { false }.should == ary
- ary.reject { false }.object_id.should_not == ary.object_id
+ ary.reject { false }.should_not.equal? ary
ary.reject { nil }.should == ary
- ary.reject { nil }.object_id.should_not == ary.object_id
+ ary.reject { nil }.should_not.equal? ary
ary.reject { 5 }.should == []
ary.reject { |i| i < 3 }.should == [3, 4, 5]
ary.reject { |i| i % 2 == 0 }.should == [1, 3, 5]
@@ -34,7 +35,7 @@ describe "Array#reject" do
end
it "does not return subclass instance on Array subclasses" do
- ArraySpecs::MyArray[1, 2, 3].reject { |x| x % 2 == 0 }.should be_an_instance_of(Array)
+ ArraySpecs::MyArray[1, 2, 3].reject { |x| x % 2 == 0 }.should.instance_of?(Array)
end
it "does not retain instance variables" do
@@ -47,10 +48,14 @@ describe "Array#reject" do
it_behaves_like :enumeratorized_with_origin_size, :reject, [1,2,3]
end
+describe "Array#reject" do
+ it_behaves_like :array_iterable_and_tolerating_size_increasing, :reject
+end
+
describe "Array#reject!" do
it "removes elements for which block is true" do
a = [3, 4, 5, 6, 7, 8, 9, 10, 11]
- a.reject! { |i| i % 2 == 0 }.should equal(a)
+ a.reject! { |i| i % 2 == 0 }.should.equal?(a)
a.should == [3, 5, 7, 9, 11]
a.reject! { |i| i > 8 }
a.should == [3, 5, 7]
@@ -100,18 +105,54 @@ describe "Array#reject!" do
end
it "returns an Enumerator if no block given, and the array is frozen" do
- ArraySpecs.frozen_array.reject!.should be_an_instance_of(Enumerator)
+ ArraySpecs.frozen_array.reject!.should.instance_of?(Enumerator)
+ end
+
+ it "raises a FrozenError on a frozen array" do
+ -> { ArraySpecs.frozen_array.reject! {} }.should.raise(FrozenError)
+ end
+
+ it "raises a FrozenError on an empty frozen array" do
+ -> { ArraySpecs.empty_frozen_array.reject! {} }.should.raise(FrozenError)
end
- it "raises a RuntimeError on a frozen array" do
- lambda { ArraySpecs.frozen_array.reject! {} }.should raise_error(RuntimeError)
+ it "raises a FrozenError on a frozen array only during iteration if called without a block" do
+ enum = ArraySpecs.frozen_array.reject!
+ -> { enum.each {} }.should.raise(FrozenError)
end
- it "raises a RuntimeError on an empty frozen array" do
- lambda { ArraySpecs.empty_frozen_array.reject! {} }.should raise_error(RuntimeError)
+ it "does not truncate the array is the block raises an exception" do
+ a = [1, 2, 3]
+ begin
+ a.reject! { raise StandardError, 'Oops' }
+ rescue
+ end
+
+ a.should == [1, 2, 3]
+ end
+
+ it "only removes elements for which the block returns true, keeping the element which raised an error." do
+ a = [1, 2, 3, 4]
+ begin
+ a.reject! do |x|
+ case x
+ when 2 then true
+ when 3 then raise StandardError, 'Oops'
+ else false
+ end
+ end
+ rescue StandardError
+ end
+
+ a.should == [1, 3, 4]
end
it_behaves_like :enumeratorize, :reject!
it_behaves_like :enumeratorized_with_origin_size, :reject!, [1,2,3]
it_behaves_like :delete_if, :reject!
end
+
+describe "Array#reject!" do
+ @value_to_return = -> _ { false }
+ it_behaves_like :array_iterable_and_tolerating_size_increasing, :reject!
+end
diff --git a/spec/ruby/core/array/repeated_combination_spec.rb b/spec/ruby/core/array/repeated_combination_spec.rb
index e79c34a520..a714f05f54 100644
--- a/spec/ruby/core/array/repeated_combination_spec.rb
+++ b/spec/ruby/core/array/repeated_combination_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Array#repeated_combination" do
before :each do
@@ -6,16 +6,16 @@ describe "Array#repeated_combination" do
end
it "returns an enumerator when no block is provided" do
- @array.repeated_combination(2).should be_an_instance_of(Enumerator)
+ @array.repeated_combination(2).should.instance_of?(Enumerator)
end
it "returns self when a block is given" do
- @array.repeated_combination(2){}.should equal(@array)
+ @array.repeated_combination(2){}.should.equal?(@array)
end
it "yields nothing for negative length and return self" do
- @array.repeated_combination(-1){ fail }.should equal(@array)
- @array.repeated_combination(-10){ fail }.should equal(@array)
+ @array.repeated_combination(-1){ fail }.should.equal?(@array)
+ @array.repeated_combination(-10){ fail }.should.equal?(@array)
end
it "yields the expected repeated_combinations" do
@@ -68,7 +68,7 @@ describe "Array#repeated_combination" do
[].repeated_combination(0).size.should == 1
end
- it "returns the binomial coeficient between combination_size and array size + combination_size -1" do
+ it "returns the binomial coefficient between combination_size and array size + combination_size -1" do
@array.repeated_combination(5).size.should == 21
@array.repeated_combination(4).size.should == 15
@array.repeated_combination(3).size.should == 10
diff --git a/spec/ruby/core/array/repeated_permutation_spec.rb b/spec/ruby/core/array/repeated_permutation_spec.rb
index 9038d49560..c54a8c0c2b 100644
--- a/spec/ruby/core/array/repeated_permutation_spec.rb
+++ b/spec/ruby/core/array/repeated_permutation_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Array#repeated_permutation" do
@@ -10,13 +10,13 @@ describe "Array#repeated_permutation" do
it "returns an Enumerator of all repeated permutations of given length when called without a block" do
enum = @numbers.repeated_permutation(2)
- enum.should be_an_instance_of(Enumerator)
+ enum.should.instance_of?(Enumerator)
enum.to_a.sort.should == @permutations
end
it "yields all repeated_permutations to the block then returns self when called with block but no arguments" do
yielded = []
- @numbers.repeated_permutation(2) {|n| yielded << n}.should equal(@numbers)
+ @numbers.repeated_permutation(2) {|n| yielded << n}.should.equal?(@numbers)
yielded.sort.should == @permutations
end
diff --git a/spec/ruby/core/array/replace_spec.rb b/spec/ruby/core/array/replace_spec.rb
index e8b0d53e04..ee6a98a646 100644
--- a/spec/ruby/core/array/replace_spec.rb
+++ b/spec/ruby/core/array/replace_spec.rb
@@ -1,7 +1,63 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/replace', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Array#replace" do
- it_behaves_like(:array_replace, :replace)
+ it "replaces the elements with elements from other array" do
+ a = [1, 2, 3, 4, 5]
+ b = ['a', 'b', 'c']
+ a.replace(b).should.equal?(a)
+ a.should == b
+ a.should_not.equal?(b)
+
+ a.replace([4] * 10)
+ a.should == [4] * 10
+
+ a.replace([])
+ a.should == []
+ end
+
+ it "properly handles recursive arrays" do
+ orig = [1, 2, 3]
+ empty = ArraySpecs.empty_recursive_array
+ orig.replace(empty)
+ orig.should == empty
+
+ array = ArraySpecs.recursive_array
+ orig.replace(array)
+ orig.should == array
+ end
+
+ it "returns self" do
+ ary = [1, 2, 3]
+ other = [:a, :b, :c]
+ ary.replace(other).should.equal?(ary)
+ end
+
+ it "does not make self dependent to the original array" do
+ ary = [1, 2, 3]
+ other = [:a, :b, :c]
+ ary.replace(other)
+ ary.should == [:a, :b, :c]
+ ary << :d
+ ary.should == [:a, :b, :c, :d]
+ other.should == [:a, :b, :c]
+ end
+
+ it "tries to convert the passed argument to an Array using #to_ary" do
+ obj = mock('to_ary')
+ obj.stub!(:to_ary).and_return([1, 2, 3])
+ [].replace(obj).should == [1, 2, 3]
+ end
+
+ it "does not call #to_ary on Array subclasses" do
+ obj = ArraySpecs::ToAryArray[5, 6, 7]
+ obj.should_not_receive(:to_ary)
+ [].replace(ArraySpecs::ToAryArray[5, 6, 7]).should == [5, 6, 7]
+ end
+
+ it "raises a FrozenError on a frozen array" do
+ -> {
+ ArraySpecs.frozen_array.replace(ArraySpecs.frozen_array)
+ }.should.raise(FrozenError)
+ end
end
diff --git a/spec/ruby/core/array/reverse_each_spec.rb b/spec/ruby/core/array/reverse_each_spec.rb
index 1bc0ed5ac5..8fa5ce6da1 100644
--- a/spec/ruby/core/array/reverse_each_spec.rb
+++ b/spec/ruby/core/array/reverse_each_spec.rb
@@ -1,11 +1,11 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/enumeratorize', __FILE__)
-require File.expand_path('../../enumerable/shared/enumeratorized', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/enumeratorize'
+require_relative '../enumerable/shared/enumeratorized'
# Modifying a collection while the contents are being iterated
# gives undefined behavior. See
-# http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/23633
+# https://blade.ruby-lang.org/ruby-core/23633
describe "Array#reverse_each" do
before :each do
@@ -19,7 +19,7 @@ describe "Array#reverse_each" do
it "returns self" do
a = [:a, :b, :c]
- a.reverse_each { |x| }.should equal(a)
+ a.reverse_each { |x| }.should.equal?(a)
end
it "yields only the top level element of an empty recursive arrays" do
@@ -38,6 +38,20 @@ describe "Array#reverse_each" do
[1, 2, 3].reverse_each.size.should == 3
end
+ it "tolerates increasing an array size during iteration" do
+ array = [:a, :b, :c]
+ ScratchPad.record []
+ i = 0
+
+ array.reverse_each do |e|
+ ScratchPad << e
+ array.prepend i if i < 100
+ i += 1
+ end
+
+ ScratchPad.recorded.should == [:c, :a, 1]
+ end
+
it_behaves_like :enumeratorize, :reverse_each
it_behaves_like :enumeratorized_with_origin_size, :reverse_each, [1,2,3]
end
diff --git a/spec/ruby/core/array/reverse_spec.rb b/spec/ruby/core/array/reverse_spec.rb
index a3a6db9506..f25a484be8 100644
--- a/spec/ruby/core/array/reverse_spec.rb
+++ b/spec/ruby/core/array/reverse_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Array#reverse" do
it "returns a new array with the elements in reverse order" do
@@ -16,14 +16,14 @@ describe "Array#reverse" do
end
it "does not return subclass instance on Array subclasses" do
- ArraySpecs::MyArray[1, 2, 3].reverse.should be_an_instance_of(Array)
+ ArraySpecs::MyArray[1, 2, 3].reverse.should.instance_of?(Array)
end
end
describe "Array#reverse!" do
it "reverses the elements in place" do
a = [6, 3, 4, 2, 1]
- a.reverse!.should equal(a)
+ a.reverse!.should.equal?(a)
a.should == [1, 2, 4, 3, 6]
[].reverse!.should == []
end
@@ -36,7 +36,7 @@ describe "Array#reverse!" do
array.reverse!.should == [array, array, array, array, array, 3.0, 'two', 1]
end
- it "raises a RuntimeError on a frozen array" do
- lambda { ArraySpecs.frozen_array.reverse! }.should raise_error(RuntimeError)
+ it "raises a FrozenError on a frozen array" do
+ -> { ArraySpecs.frozen_array.reverse! }.should.raise(FrozenError)
end
end
diff --git a/spec/ruby/core/array/rindex_spec.rb b/spec/ruby/core/array/rindex_spec.rb
index 19a6f04c85..858c39dc92 100644
--- a/spec/ruby/core/array/rindex_spec.rb
+++ b/spec/ruby/core/array/rindex_spec.rb
@@ -1,10 +1,10 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../../enumerable/shared/enumeratorized', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative '../enumerable/shared/enumeratorized'
# Modifying a collection while the contents are being iterated
# gives undefined behavior. See
-# http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/23633
+# https://blade.ruby-lang.org/ruby-core/23633
describe "Array#rindex" do
it "returns the first index backwards from the end where element == to object" do
@@ -41,7 +41,7 @@ describe "Array#rindex" do
it "properly handles empty recursive arrays" do
empty = ArraySpecs.empty_recursive_array
empty.rindex(empty).should == 0
- empty.rindex(1).should be_nil
+ empty.rindex(1).should == nil
end
it "properly handles recursive arrays" do
@@ -68,10 +68,25 @@ describe "Array#rindex" do
seen.should == [3]
end
+ it "tolerates increasing an array size during iteration" do
+ array = [:a, :b, :c]
+ ScratchPad.record []
+ i = 0
+
+ array.rindex do |e|
+ ScratchPad << e
+ array.prepend i if i < 100
+ i += 1
+ false
+ end
+
+ ScratchPad.recorded.should == [:c, :a, 1]
+ end
+
describe "given no argument and no block" do
it "produces an Enumerator" do
enum = [4, 2, 1, 5, 1, 3].rindex
- enum.should be_an_instance_of(Enumerator)
+ enum.should.instance_of?(Enumerator)
enum.each { |x| x < 2 }.should == 4
end
end
diff --git a/spec/ruby/core/array/rotate_spec.rb b/spec/ruby/core/array/rotate_spec.rb
index 270bfeb446..009ce5ed49 100644
--- a/spec/ruby/core/array/rotate_spec.rb
+++ b/spec/ruby/core/array/rotate_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Array#rotate" do
describe "when passed no argument" do
@@ -27,12 +27,12 @@ describe "Array#rotate" do
end
it "raises a TypeError if not passed an integer-like argument" do
- lambda {
+ -> {
[1, 2].rotate(nil)
- }.should raise_error(TypeError)
- lambda {
+ }.should.raise(TypeError)
+ -> {
[1, 2].rotate("4")
- }.should raise_error(TypeError)
+ }.should.raise(TypeError)
end
end
@@ -46,22 +46,22 @@ describe "Array#rotate" do
end
it "does not mutate the receiver" do
- lambda {
+ -> {
[].freeze.rotate
[2].freeze.rotate(2)
[1,2,3].freeze.rotate(-3)
- }.should_not raise_error
+ }.should_not.raise
end
it "does not return self" do
a = [1, 2, 3]
- a.rotate.should_not equal(a)
+ a.rotate.should_not.equal?(a)
a = []
- a.rotate(0).should_not equal(a)
+ a.rotate(0).should_not.equal?(a)
end
it "does not return subclass instance for Array subclasses" do
- ArraySpecs::MyArray[1, 2, 3].rotate.should be_an_instance_of(Array)
+ ArraySpecs::MyArray[1, 2, 3].rotate.should.instance_of?(Array)
end
end
@@ -69,7 +69,7 @@ describe "Array#rotate!" do
describe "when passed no argument" do
it "moves the first element to the end and returns self" do
a = [1, 2, 3, 4, 5]
- a.rotate!.should equal(a)
+ a.rotate!.should.equal?(a)
a.should == [2, 3, 4, 5, 1]
end
end
@@ -77,11 +77,11 @@ describe "Array#rotate!" do
describe "with an argument n" do
it "moves the first (n % size) elements at the end and returns self" do
a = [1, 2, 3, 4, 5]
- a.rotate!(2).should equal(a)
+ a.rotate!(2).should.equal?(a)
a.should == [3, 4, 5, 1, 2]
- a.rotate!(-12).should equal(a)
+ a.rotate!(-12).should.equal?(a)
a.should == [1, 2, 3, 4, 5]
- a.rotate!(13).should equal(a)
+ a.rotate!(13).should.equal?(a)
a.should == [4, 5, 1, 2, 3]
end
@@ -94,36 +94,36 @@ describe "Array#rotate!" do
end
it "raises a TypeError if not passed an integer-like argument" do
- lambda {
+ -> {
[1, 2].rotate!(nil)
- }.should raise_error(TypeError)
- lambda {
+ }.should.raise(TypeError)
+ -> {
[1, 2].rotate!("4")
- }.should raise_error(TypeError)
+ }.should.raise(TypeError)
end
end
it "does nothing and returns self when the length is zero or one" do
a = [1]
- a.rotate!.should equal(a)
+ a.rotate!.should.equal?(a)
a.should == [1]
- a.rotate!(2).should equal(a)
+ a.rotate!(2).should.equal?(a)
a.should == [1]
- a.rotate!(-21).should equal(a)
+ a.rotate!(-21).should.equal?(a)
a.should == [1]
a = []
- a.rotate!.should equal(a)
+ a.rotate!.should.equal?(a)
a.should == []
- a.rotate!(2).should equal(a)
+ a.rotate!(2).should.equal?(a)
a.should == []
- a.rotate!(-21).should equal(a)
+ a.rotate!(-21).should.equal?(a)
a.should == []
end
- it "raises a RuntimeError on a frozen array" do
- lambda { [1, 2, 3].freeze.rotate!(0) }.should raise_error(RuntimeError)
- lambda { [1].freeze.rotate!(42) }.should raise_error(RuntimeError)
- lambda { [].freeze.rotate! }.should raise_error(RuntimeError)
+ it "raises a FrozenError on a frozen array" do
+ -> { [1, 2, 3].freeze.rotate!(0) }.should.raise(FrozenError)
+ -> { [1].freeze.rotate!(42) }.should.raise(FrozenError)
+ -> { [].freeze.rotate! }.should.raise(FrozenError)
end
end
diff --git a/spec/ruby/core/array/sample_spec.rb b/spec/ruby/core/array/sample_spec.rb
index 53601dd5c4..fd443b47de 100644
--- a/spec/ruby/core/array/sample_spec.rb
+++ b/spec/ruby/core/array/sample_spec.rb
@@ -1,26 +1,36 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Array#sample" do
it "samples evenly" do
- ary = [0, 1, 2, 3]
- 3.times do |i|
- counts = [0, 0, 0, 0]
- 4000.times do
- counts[ary.sample(3)[i]] += 1
- end
- counts.each do |count|
- (800..1200).should include(count)
- end
- end
+ ArraySpecs.measure_sample_fairness(4, 1, 400)
+ ArraySpecs.measure_sample_fairness(4, 2, 400)
+ ArraySpecs.measure_sample_fairness(4, 3, 400)
+ ArraySpecs.measure_sample_fairness(40, 3, 400)
+ ArraySpecs.measure_sample_fairness(40, 4, 400)
+ ArraySpecs.measure_sample_fairness(40, 8, 400)
+ ArraySpecs.measure_sample_fairness(40, 16, 400)
+ ArraySpecs.measure_sample_fairness_large_sample_size(100, 80, 4000)
end
it "returns nil for an empty Array" do
- [].sample.should be_nil
+ [].sample.should == nil
+ end
+
+ it "returns nil for an empty array when called without n and a Random is given" do
+ [].sample(random: Random.new(42)).should == nil
end
it "returns a single value when not passed a count" do
- [4].sample.should equal(4)
+ [4].sample.should.equal?(4)
+ end
+
+ it "returns a single value when not passed a count and a Random is given" do
+ [4].sample(random: Random.new(42)).should.equal?(4)
+ end
+
+ it "returns a single value when not passed a count and a Random class is given" do
+ [4].sample(random: Random).should.equal?(4)
end
it "returns an empty Array when passed zero" do
@@ -28,12 +38,12 @@ describe "Array#sample" do
end
it "returns an Array of elements when passed a count" do
- [1, 2, 3, 4].sample(3).should be_an_instance_of(Array)
+ [1, 2, 3, 4].sample(3).should.instance_of?(Array)
end
it "returns elements from the Array" do
array = [1, 2, 3, 4]
- array.sample(3).all? { |x| array.should include(x) }
+ array.sample(3).all? { |x| array.should.include?(x) }
end
it "returns at most the number of elements in the Array" do
@@ -57,46 +67,29 @@ describe "Array#sample" do
end
it "raises ArgumentError when passed a negative count" do
- lambda { [1, 2].sample(-1) }.should raise_error(ArgumentError)
+ -> { [1, 2].sample(-1) }.should.raise(ArgumentError)
end
it "does not return subclass instances with Array subclass" do
- ArraySpecs::MyArray[1, 2, 3].sample(2).should be_an_instance_of(Array)
+ ArraySpecs::MyArray[1, 2, 3].sample(2).should.instance_of?(Array)
end
describe "with options" do
- it "calls #to_hash to convert the passed Object" do
- obj = mock("array_sample")
- obj.should_receive(:to_hash).and_return({})
- obj.should_not_receive(:to_int)
-
- [1, 2].sample(obj).should be_an_instance_of(Fixnum)
- end
-
- it "calls #to_int on the first argument and #to_hash on the second when passed Objects" do
- count = mock("array_sample_count")
- count.should_receive(:to_int).and_return(2)
- options = mock("array_sample_options")
- options.should_receive(:to_hash).and_return({})
-
- [1, 2].sample(count, options).size.should == 2
- end
-
it "calls #rand on the Object passed by the :random key in the arguments Hash" do
obj = mock("array_sample_random")
obj.should_receive(:rand).and_return(0.5)
- [1, 2].sample(random: obj).should be_an_instance_of(Fixnum)
+ [1, 2].sample(random: obj).should.instance_of?(Integer)
end
it "raises a NoMethodError if an object passed for the RNG does not define #rand" do
obj = BasicObject.new
- lambda { [1, 2].sample(random: obj) }.should raise_error(NoMethodError)
+ -> { [1, 2].sample(random: obj) }.should.raise(NoMethodError)
end
- describe "when the object returned by #rand is a Fixnum" do
- it "uses the fixnum as index" do
+ describe "when the object returned by #rand is an Integer" do
+ it "uses the integer as index" do
random = mock("array_sample_random_ret")
random.should_receive(:rand).and_return(0)
@@ -112,19 +105,26 @@ describe "Array#sample" do
random = mock("array_sample_random")
random.should_receive(:rand).and_return(-1)
- lambda { [1, 2].sample(random: random) }.should raise_error(RangeError)
+ -> { [1, 2].sample(random: random) }.should.raise(RangeError)
end
it "raises a RangeError if the value is equal to the Array size" do
random = mock("array_sample_random")
random.should_receive(:rand).and_return(2)
- lambda { [1, 2].sample(random: random) }.should raise_error(RangeError)
+ -> { [1, 2].sample(random: random) }.should.raise(RangeError)
+ end
+
+ it "raises a RangeError if the value is greater than the Array size" do
+ random = mock("array_sample_random")
+ random.should_receive(:rand).and_return(3)
+
+ -> { [1, 2].sample(random: random) }.should.raise(RangeError)
end
end
end
- describe "when the object returned by #rand is not a Fixnum but responds to #to_int" do
+ describe "when the object returned by #rand is not an Integer but responds to #to_int" do
it "calls #to_int on the Object" do
value = mock("array_sample_random_value")
value.should_receive(:to_int).and_return(1)
@@ -140,7 +140,7 @@ describe "Array#sample" do
random = mock("array_sample_random")
random.should_receive(:rand).and_return(value)
- lambda { [1, 2].sample(random: random) }.should raise_error(RangeError)
+ -> { [1, 2].sample(random: random) }.should.raise(RangeError)
end
it "raises a RangeError if the value is equal to the Array size" do
@@ -149,7 +149,7 @@ describe "Array#sample" do
random = mock("array_sample_random")
random.should_receive(:rand).and_return(value)
- lambda { [1, 2].sample(random: random) }.should raise_error(RangeError)
+ -> { [1, 2].sample(random: random) }.should.raise(RangeError)
end
end
end
diff --git a/spec/ruby/core/array/select_spec.rb b/spec/ruby/core/array/select_spec.rb
index 8b83acaa5f..57ec0b2540 100644
--- a/spec/ruby/core/array/select_spec.rb
+++ b/spec/ruby/core/array/select_spec.rb
@@ -1,19 +1,26 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/enumeratorize', __FILE__)
-require File.expand_path('../shared/keep_if', __FILE__)
-require File.expand_path('../../enumerable/shared/enumeratorized', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../enumerable/shared/enumeratorized'
+require_relative 'fixtures/classes'
+require_relative 'shared/enumeratorize'
+require_relative 'shared/iterable_and_tolerating_size_increasing'
+require_relative 'shared/keep_if'
describe "Array#select" do
it_behaves_like :enumeratorize, :select
- it_behaves_like :enumeratorized_with_origin_size, :select, [1,2,3]
+
+ it_behaves_like :array_iterable_and_tolerating_size_increasing, :select
+
+ before :each do
+ @object = [1,2,3]
+ end
+ it_behaves_like :enumeratorized_with_origin_size, :select
it "returns a new array of elements for which block is true" do
[1, 3, 4, 5, 6, 9].select { |i| i % ((i + 1) / 2) == 0}.should == [1, 4, 6]
end
it "does not return subclass instance on Array subclasses" do
- ArraySpecs::MyArray[1, 2, 3].select { true }.should be_an_instance_of(Array)
+ ArraySpecs::MyArray[1, 2, 3].select { true }.should.instance_of?(Array)
end
it "properly handles recursive arrays" do
@@ -29,7 +36,7 @@ end
describe "Array#select!" do
it "returns nil if no changes were made in the array" do
- [1, 2, 3].select! { true }.should be_nil
+ [1, 2, 3].select! { true }.should == nil
end
it_behaves_like :keep_if, :select!
diff --git a/spec/ruby/core/array/shared/clone.rb b/spec/ruby/core/array/shared/clone.rb
index 6fc7ae31eb..1a45c2fe2c 100644
--- a/spec/ruby/core/array/shared/clone.rb
+++ b/spec/ruby/core/array/shared/clone.rb
@@ -1,14 +1,14 @@
describe :array_clone, shared: true do
it "returns an Array or a subclass instance" do
- [].send(@method).should be_an_instance_of(Array)
- ArraySpecs::MyArray[1, 2].send(@method).should be_an_instance_of(ArraySpecs::MyArray)
+ [].send(@method).should.instance_of?(Array)
+ ArraySpecs::MyArray[1, 2].send(@method).should.instance_of?(ArraySpecs::MyArray)
end
it "produces a shallow copy where the references are directly copied" do
a = [mock('1'), mock('2')]
b = a.send @method
- b.first.object_id.should == a.first.object_id
- b.last.object_id.should == a.last.object_id
+ b.first.should.equal? a.first
+ b.last.should.equal? a.last
end
it "creates a new array containing all elements or the original" do
@@ -17,26 +17,4 @@ describe :array_clone, shared: true do
b.should == a
b.__id__.should_not == a.__id__
end
-
- it "copies taint status from the original" do
- a = [1, 2, 3, 4]
- b = [1, 2, 3, 4]
- a.taint
- aa = a.send @method
- bb = b.send @method
-
- aa.tainted?.should == true
- bb.tainted?.should == false
- end
-
- it "copies untrusted status from the original" do
- a = [1, 2, 3, 4]
- b = [1, 2, 3, 4]
- a.untrust
- aa = a.send @method
- bb = b.send @method
-
- aa.untrusted?.should == true
- bb.untrusted?.should == false
- end
end
diff --git a/spec/ruby/core/array/shared/collect.rb b/spec/ruby/core/array/shared/collect.rb
deleted file mode 100644
index f6bcfd8904..0000000000
--- a/spec/ruby/core/array/shared/collect.rb
+++ /dev/null
@@ -1,136 +0,0 @@
-require File.expand_path('../../../enumerable/shared/enumeratorized', __FILE__)
-
-describe :array_collect, shared: true do
- it "returns a copy of array with each element replaced by the value returned by block" do
- a = ['a', 'b', 'c', 'd']
- b = a.send(@method) { |i| i + '!' }
- b.should == ["a!", "b!", "c!", "d!"]
- b.object_id.should_not == a.object_id
- end
-
- it "does not return subclass instance" do
- ArraySpecs::MyArray[1, 2, 3].send(@method) { |x| x + 1 }.should be_an_instance_of(Array)
- end
-
- it "does not change self" do
- a = ['a', 'b', 'c', 'd']
- a.send(@method) { |i| i + '!' }
- a.should == ['a', 'b', 'c', 'd']
- end
-
- it "returns the evaluated value of block if it broke in the block" do
- a = ['a', 'b', 'c', 'd']
- b = a.send(@method) {|i|
- if i == 'c'
- break 0
- else
- i + '!'
- end
- }
- b.should == 0
- end
-
- it "returns an Enumerator when no block given" do
- a = [1, 2, 3]
- a.send(@method).should be_an_instance_of(Enumerator)
- end
-
- it "raises an ArgumentError when no block and with arguments" do
- a = [1, 2, 3]
- lambda {
- a.send(@method, :foo)
- }.should raise_error(ArgumentError)
- end
-
- it "does not copy tainted status" do
- a = [1, 2, 3]
- a.taint
- a.send(@method){|x| x}.tainted?.should be_false
- end
-
- it "does not copy untrusted status" do
- a = [1, 2, 3]
- a.untrust
- a.send(@method){|x| x}.untrusted?.should be_false
- end
-
- before :all do
- @object = [1, 2, 3, 4]
- end
- it_should_behave_like :enumeratorized_with_origin_size
-end
-
-describe :array_collect_b, shared: true do
- it "replaces each element with the value returned by block" do
- a = [7, 9, 3, 5]
- a.send(@method) { |i| i - 1 }.should equal(a)
- a.should == [6, 8, 2, 4]
- end
-
- it "returns self" do
- a = [1, 2, 3, 4, 5]
- b = a.send(@method) {|i| i+1 }
- a.object_id.should == b.object_id
- end
-
- it "returns the evaluated value of block but its contents is partially modified, if it broke in the block" do
- a = ['a', 'b', 'c', 'd']
- b = a.send(@method) {|i|
- if i == 'c'
- break 0
- else
- i + '!'
- end
- }
- b.should == 0
- a.should == ['a!', 'b!', 'c', 'd']
- end
-
- it "returns an Enumerator when no block given, and the enumerator can modify the original array" do
- a = [1, 2, 3]
- enum = a.send(@method)
- enum.should be_an_instance_of(Enumerator)
- enum.each{|i| "#{i}!" }
- a.should == ["1!", "2!", "3!"]
- end
-
- it "keeps tainted status" do
- a = [1, 2, 3]
- a.taint
- a.tainted?.should be_true
- a.send(@method){|x| x}
- a.tainted?.should be_true
- end
-
- it "keeps untrusted status" do
- a = [1, 2, 3]
- a.untrust
- a.send(@method){|x| x}
- a.untrusted?.should be_true
- end
-
- describe "when frozen" do
- it "raises a RuntimeError" do
- lambda { ArraySpecs.frozen_array.send(@method) {} }.should raise_error(RuntimeError)
- end
-
- it "raises a RuntimeError when empty" do
- lambda { ArraySpecs.empty_frozen_array.send(@method) {} }.should raise_error(RuntimeError)
- end
-
- it "raises a RuntimeError when calling #each on the returned Enumerator" do
- enumerator = ArraySpecs.frozen_array.send(@method)
- lambda { enumerator.each {|x| x } }.should raise_error(RuntimeError)
- end
-
- it "raises a RuntimeError when calling #each on the returned Enumerator when empty" do
- enumerator = ArraySpecs.empty_frozen_array.send(@method)
- lambda { enumerator.each {|x| x } }.should raise_error(RuntimeError)
- end
- end
-
- before :all do
- @object = [1, 2, 3, 4]
- end
- it_should_behave_like :enumeratorized_with_origin_size
-end
diff --git a/spec/ruby/core/array/shared/delete_if.rb b/spec/ruby/core/array/shared/delete_if.rb
index a9fb57e0d9..a3fdcf4fac 100644
--- a/spec/ruby/core/array/shared/delete_if.rb
+++ b/spec/ruby/core/array/shared/delete_if.rb
@@ -3,25 +3,11 @@ describe :delete_if, shared: true do
@object = [1,2,3]
end
- ruby_version_is "2.3" do
- it "updates the receiver after all blocks" do
- @object.send(@method) do |e|
- @object.length.should == 3
- true
- end
- @object.length.should == 0
- end
- end
-
- ruby_version_is ""..."2.3" do
- it "updates the receiver after each true block" do
- count = 0
- @object.send(@method) do |e|
- @object.length.should == (3 - count)
- count += 1
- true
- end
- @object.length.should == 0
+ it "updates the receiver after all blocks" do
+ @object.send(@method) do |e|
+ @object.length.should == 3
+ true
end
+ @object.length.should == 0
end
end
diff --git a/spec/ruby/core/array/shared/difference.rb b/spec/ruby/core/array/shared/difference.rb
new file mode 100644
index 0000000000..3fe22331bd
--- /dev/null
+++ b/spec/ruby/core/array/shared/difference.rb
@@ -0,0 +1,78 @@
+describe :array_binary_difference, shared: true do
+ it "creates an array minus any items from other array" do
+ [].send(@method, [ 1, 2, 4 ]).should == []
+ [1, 2, 4].send(@method, []).should == [1, 2, 4]
+ [ 1, 2, 3, 4, 5 ].send(@method, [ 1, 2, 4 ]).should == [3, 5]
+ end
+
+ it "removes multiple items on the lhs equal to one on the rhs" do
+ [1, 1, 2, 2, 3, 3, 4, 5].send(@method, [1, 2, 4]).should == [3, 3, 5]
+ end
+
+ it "properly handles recursive arrays" do
+ empty = ArraySpecs.empty_recursive_array
+ empty.send(@method, empty).should == []
+
+ [].send(@method, ArraySpecs.recursive_array).should == []
+
+ array = ArraySpecs.recursive_array
+ array.send(@method, array).should == []
+ end
+
+ it "tries to convert the passed arguments to Arrays using #to_ary" do
+ obj = mock('[2,3,3,4]')
+ obj.should_receive(:to_ary).and_return([2, 3, 3, 4])
+ [1, 1, 2, 2, 3, 4].send(@method, obj).should == [1, 1]
+ end
+
+ it "raises a TypeError if the argument cannot be coerced to an Array by calling #to_ary" do
+ obj = mock('not an array')
+ -> { [1, 2, 3].send(@method, obj) }.should.raise(TypeError)
+ end
+
+ it "does not return subclass instance for Array subclasses" do
+ ArraySpecs::MyArray[1, 2, 3].send(@method, []).should.instance_of?(Array)
+ ArraySpecs::MyArray[1, 2, 3].send(@method, ArraySpecs::MyArray[]).should.instance_of?(Array)
+ [1, 2, 3].send(@method, ArraySpecs::MyArray[]).should.instance_of?(Array)
+ end
+
+ it "does not call to_ary on array subclasses" do
+ [5, 6, 7].send(@method, ArraySpecs::ToAryArray[7]).should == [5, 6]
+ end
+
+ it "removes an item identified as equivalent via #hash and #eql?" do
+ obj1 = mock('1')
+ obj2 = mock('2')
+ obj1.stub!(:hash).and_return(0)
+ obj2.stub!(:hash).and_return(0)
+ obj1.should_receive(:eql?).at_least(1).and_return(true)
+
+ [obj1].send(@method, [obj2]).should == []
+ [obj1, obj1, obj2, obj2].send(@method, [obj2]).should == []
+ end
+
+ it "doesn't remove an item with the same hash but not #eql?" do
+ obj1 = mock('1')
+ obj2 = mock('2')
+ obj1.stub!(:hash).and_return(0)
+ obj2.stub!(:hash).and_return(0)
+ obj1.should_receive(:eql?).at_least(1).and_return(false)
+
+ [obj1].send(@method, [obj2]).should == [obj1]
+ [obj1, obj1, obj2, obj2].send(@method, [obj2]).should == [obj1, obj1]
+ end
+
+ it "removes an identical item even when its #eql? isn't reflexive" do
+ x = mock('x')
+ x.stub!(:hash).and_return(42)
+ x.stub!(:eql?).and_return(false) # Stubbed for clarity and latitude in implementation; not actually sent by MRI.
+
+ [x].send(@method, [x]).should == []
+ end
+
+ it "is not destructive" do
+ a = [1, 2, 3]
+ a.send(@method, [1])
+ a.should == [1, 2, 3]
+ end
+end
diff --git a/spec/ruby/core/array/shared/enumeratorize.rb b/spec/ruby/core/array/shared/enumeratorize.rb
index a19a5d3b9b..5beab5c4c4 100644
--- a/spec/ruby/core/array/shared/enumeratorize.rb
+++ b/spec/ruby/core/array/shared/enumeratorize.rb
@@ -1,5 +1,5 @@
describe :enumeratorize, shared: true do
it "returns an Enumerator if no block given" do
- [1,2].send(@method).should be_an_instance_of(Enumerator)
+ [1,2].send(@method).should.instance_of?(Enumerator)
end
end
diff --git a/spec/ruby/core/array/shared/eql.rb b/spec/ruby/core/array/shared/eql.rb
index b5d9128434..5e770bf167 100644
--- a/spec/ruby/core/array/shared/eql.rb
+++ b/spec/ruby/core/array/shared/eql.rb
@@ -1,59 +1,59 @@
describe :array_eql, shared: true do
it "returns true if other is the same array" do
a = [1]
- a.send(@method, a).should be_true
+ a.send(@method, a).should == true
end
it "returns true if corresponding elements are #eql?" do
- [].send(@method, []).should be_true
- [1, 2, 3, 4].send(@method, [1, 2, 3, 4]).should be_true
+ [].send(@method, []).should == true
+ [1, 2, 3, 4].send(@method, [1, 2, 3, 4]).should == true
end
it "returns false if other is shorter than self" do
- [1, 2, 3, 4].send(@method, [1, 2, 3]).should be_false
+ [1, 2, 3, 4].send(@method, [1, 2, 3]).should == false
end
it "returns false if other is longer than self" do
- [1, 2, 3, 4].send(@method, [1, 2, 3, 4, 5]).should be_false
+ [1, 2, 3, 4].send(@method, [1, 2, 3, 4, 5]).should == false
end
it "returns false immediately when sizes of the arrays differ" do
obj = mock('1')
obj.should_not_receive(@method)
- [] .send(@method, [obj] ).should be_false
- [obj] .send(@method, [] ).should be_false
+ [] .send(@method, [obj] ).should == false
+ [obj] .send(@method, [] ).should == false
end
it "handles well recursive arrays" do
a = ArraySpecs.empty_recursive_array
- a .send(@method, [a] ).should be_true
- a .send(@method, [[a]] ).should be_true
- [a] .send(@method, a ).should be_true
- [[a]] .send(@method, a ).should be_true
+ a .send(@method, [a] ).should == true
+ a .send(@method, [[a]] ).should == true
+ [a] .send(@method, a ).should == true
+ [[a]] .send(@method, a ).should == true
# These may be surprising, but no difference can be
# found between these arrays, so they are ==.
# There is no "path" that will lead to a difference
# (contrary to other examples below)
a2 = ArraySpecs.empty_recursive_array
- a .send(@method, a2 ).should be_true
- a .send(@method, [a2] ).should be_true
- a .send(@method, [[a2]] ).should be_true
- [a] .send(@method, a2 ).should be_true
- [[a]] .send(@method, a2 ).should be_true
+ a .send(@method, a2 ).should == true
+ a .send(@method, [a2] ).should == true
+ a .send(@method, [[a2]] ).should == true
+ [a] .send(@method, a2 ).should == true
+ [[a]] .send(@method, a2 ).should == true
back = []
forth = [back]; back << forth;
- back .send(@method, a ).should be_true
+ back .send(@method, a ).should == true
x = []; x << x << x
- x .send(@method, a ).should be_false # since x.size != a.size
- x .send(@method, [a, a] ).should be_false # since x[0].size != [a, a][0].size
- x .send(@method, [x, a] ).should be_false # since x[1].size != [x, a][1].size
- [x, a] .send(@method, [a, x] ).should be_false # etc...
- x .send(@method, [x, x] ).should be_true
- x .send(@method, [[x, x], [x, x]] ).should be_true
+ x .send(@method, a ).should == false # since x.size != a.size
+ x .send(@method, [a, a] ).should == false # since x[0].size != [a, a][0].size
+ x .send(@method, [x, a] ).should == false # since x[1].size != [x, a][1].size
+ [x, a] .send(@method, [a, x] ).should == false # etc...
+ x .send(@method, [x, x] ).should == true
+ x .send(@method, [[x, x], [x, x]] ).should == true
tree = [];
branch = []; branch << tree << tree; tree << branch
@@ -62,31 +62,31 @@ describe :array_eql, shared: true do
forest = [tree, branch, :bird, a]; forest << forest
forest2 = [tree2, branch2, :bird, a2]; forest2 << forest2
- forest .send(@method, forest2 ).should be_true
- forest .send(@method, [tree2, branch, :bird, a, forest2]).should be_true
+ forest .send(@method, forest2 ).should == true
+ forest .send(@method, [tree2, branch, :bird, a, forest2]).should == true
diffforest = [branch2, tree2, :bird, a2]; diffforest << forest2
- forest .send(@method, diffforest ).should be_false # since forest[0].size == 1 != 3 == diffforest[0]
- forest .send(@method, [nil] ).should be_false
- forest .send(@method, [forest] ).should be_false
+ forest .send(@method, diffforest ).should == false # since forest[0].size == 1 != 3 == diffforest[0]
+ forest .send(@method, [nil] ).should == false
+ forest .send(@method, [forest] ).should == false
end
it "does not call #to_ary on its argument" do
obj = mock('to_ary')
obj.should_not_receive(:to_ary)
- [1, 2, 3].send(@method, obj).should be_false
+ [1, 2, 3].send(@method, obj).should == false
end
it "does not call #to_ary on Array subclasses" do
ary = ArraySpecs::ToAryArray[5, 6, 7]
ary.should_not_receive(:to_ary)
- [5, 6, 7].send(@method, ary).should be_true
+ [5, 6, 7].send(@method, ary).should == true
end
it "ignores array class differences" do
- ArraySpecs::MyArray[1, 2, 3].send(@method, [1, 2, 3]).should be_true
- ArraySpecs::MyArray[1, 2, 3].send(@method, ArraySpecs::MyArray[1, 2, 3]).should be_true
- [1, 2, 3].send(@method, ArraySpecs::MyArray[1, 2, 3]).should be_true
+ ArraySpecs::MyArray[1, 2, 3].send(@method, [1, 2, 3]).should == true
+ ArraySpecs::MyArray[1, 2, 3].send(@method, ArraySpecs::MyArray[1, 2, 3]).should == true
+ [1, 2, 3].send(@method, ArraySpecs::MyArray[1, 2, 3]).should == true
end
end
diff --git a/spec/ruby/core/array/shared/index.rb b/spec/ruby/core/array/shared/index.rb
deleted file mode 100644
index a9896554f2..0000000000
--- a/spec/ruby/core/array/shared/index.rb
+++ /dev/null
@@ -1,37 +0,0 @@
-describe :array_index, shared: true do
- it "returns the index of the first element == to object" do
- x = mock('3')
- def x.==(obj) 3 == obj; end
-
- [2, x, 3, 1, 3, 1].send(@method, 3).should == 1
- [2, 3.0, 3, x, 1, 3, 1].send(@method, x).should == 1
- end
-
- it "returns 0 if first element == to object" do
- [2, 1, 3, 2, 5].send(@method, 2).should == 0
- end
-
- it "returns size-1 if only last element == to object" do
- [2, 1, 3, 1, 5].send(@method, 5).should == 4
- end
-
- it "returns nil if no element == to object" do
- [2, 1, 1, 1, 1].send(@method, 3).should == nil
- end
-
- it "accepts a block instead of an argument" do
- [4, 2, 1, 5, 1, 3].send(@method) {|x| x < 2}.should == 2
- end
-
- it "ignores the block if there is an argument" do
- -> {
- [4, 2, 1, 5, 1, 3].send(@method, 5) {|x| x < 2}.should == 3
- }.should complain(/given block not used/)
- end
-
- describe "given no argument and no block" do
- it "produces an Enumerator" do
- [].send(@method).should be_an_instance_of(Enumerator)
- end
- end
-end
diff --git a/spec/ruby/core/array/shared/inspect.rb b/spec/ruby/core/array/shared/inspect.rb
deleted file mode 100644
index 6a60781b45..0000000000
--- a/spec/ruby/core/array/shared/inspect.rb
+++ /dev/null
@@ -1,144 +0,0 @@
-require File.expand_path('../../fixtures/encoded_strings', __FILE__)
-
-describe :array_inspect, shared: true do
- it "returns a string" do
- [1, 2, 3].send(@method).should be_an_instance_of(String)
- end
-
- it "returns '[]' for an empty Array" do
- [].send(@method).should == "[]"
- end
-
- it "calls inspect on its elements and joins the results with commas" do
- items = Array.new(3) do |i|
- obj = mock(i.to_s)
- obj.should_receive(:inspect).and_return(i.to_s)
- obj
- end
- items.send(@method).should == "[0, 1, 2]"
- end
-
- it "does not call #to_s on a String returned from #inspect" do
- str = "abc"
- str.should_not_receive(:to_s)
-
- [str].send(@method).should == '["abc"]'
- end
-
- it "calls #to_s on the object returned from #inspect if the Object isn't a String" do
- obj = mock("Array#inspect/to_s calls #to_s")
- obj.should_receive(:inspect).and_return(obj)
- obj.should_receive(:to_s).and_return("abc")
-
- [obj].send(@method).should == "[abc]"
- end
-
- it "does not call #to_str on the object returned from #inspect when it is not a String" do
- obj = mock("Array#inspect/to_s does not call #to_str")
- obj.should_receive(:inspect).and_return(obj)
- obj.should_not_receive(:to_str)
-
- [obj].send(@method).should =~ /^\[#<MockObject:0x[0-9a-f]+>\]$/
- end
-
- it "does not call #to_str on the object returned from #to_s when it is not a String" do
- obj = mock("Array#inspect/to_s does not call #to_str on #to_s result")
- obj.should_receive(:inspect).and_return(obj)
- obj.should_receive(:to_s).and_return(obj)
- obj.should_not_receive(:to_str)
-
- [obj].send(@method).should =~ /^\[#<MockObject:0x[0-9a-f]+>\]$/
- end
-
- it "does not swallow exceptions raised by #to_s" do
- obj = mock("Array#inspect/to_s does not swallow #to_s exceptions")
- obj.should_receive(:inspect).and_return(obj)
- obj.should_receive(:to_s).and_raise(Exception)
-
- lambda { [obj].send(@method) }.should raise_error(Exception)
- end
-
- it "represents a recursive element with '[...]'" do
- ArraySpecs.recursive_array.send(@method).should == "[1, \"two\", 3.0, [...], [...], [...], [...], [...]]"
- ArraySpecs.head_recursive_array.send(@method).should == "[[...], [...], [...], [...], [...], 1, \"two\", 3.0]"
- ArraySpecs.empty_recursive_array.send(@method).should == "[[...]]"
- end
-
- it "taints the result if the Array is non-empty and tainted" do
- [1, 2].taint.send(@method).tainted?.should be_true
- end
-
- it "does not taint the result if the Array is tainted but empty" do
- [].taint.send(@method).tainted?.should be_false
- end
-
- it "taints the result if an element is tainted" do
- ["str".taint].send(@method).tainted?.should be_true
- end
-
- it "untrusts the result if the Array is untrusted" do
- [1, 2].untrust.send(@method).untrusted?.should be_true
- end
-
- it "does not untrust the result if the Array is untrusted but empty" do
- [].untrust.send(@method).untrusted?.should be_false
- end
-
- it "untrusts the result if an element is untrusted" do
- ["str".untrust].send(@method).untrusted?.should be_true
- end
-
- describe "with encoding" do
- before :each do
- @default_external_encoding = Encoding.default_external
- end
-
- after :each do
- Encoding.default_external = @default_external_encoding
- end
-
- it "returns a US-ASCII string for an empty Array" do
- [].send(@method).encoding.should == Encoding::US_ASCII
- end
-
- it "use the default external encoding if it is ascii compatible" do
- Encoding.default_external = Encoding.find('UTF-8')
-
- utf8 = "utf8".encode("UTF-8")
- jp = "jp".encode("EUC-JP")
- array = [jp, utf8]
-
- array.send(@method).encoding.name.should == "UTF-8"
- end
-
- it "use US-ASCII encoding if the default external encoding is not ascii compatible" do
- Encoding.default_external = Encoding.find('UTF-32')
-
- utf8 = "utf8".encode("UTF-8")
- jp = "jp".encode("EUC-JP")
- array = [jp, utf8]
-
- array.send(@method).encoding.name.should == "US-ASCII"
- end
-
- ruby_version_is ''...'2.3' do
- it "raises if inspected result is not default external encoding" do
- utf_16be = mock("utf_16be")
- utf_16be.should_receive(:inspect).and_return(%<"utf_16be \u3042">.encode!(Encoding::UTF_16BE))
-
- lambda {
- [utf_16be].send(@method)
- }.should raise_error(Encoding::CompatibilityError)
- end
- end
-
- ruby_version_is '2.3' do
- it "does not raise if inspected result is not default external encoding" do
- utf_16be = mock("utf_16be")
- utf_16be.should_receive(:inspect).and_return(%<"utf_16be \u3042">.encode!(Encoding::UTF_16BE))
-
- [utf_16be].send(@method).should == '["utf_16be \u3042"]'
- end
- end
- end
-end
diff --git a/spec/ruby/core/array/shared/intersection.rb b/spec/ruby/core/array/shared/intersection.rb
new file mode 100644
index 0000000000..dda72e8bd7
--- /dev/null
+++ b/spec/ruby/core/array/shared/intersection.rb
@@ -0,0 +1,85 @@
+describe :array_intersection, shared: true do
+ it "creates an array with elements common to both arrays (intersection)" do
+ [].send(@method, []).should == []
+ [1, 2].send(@method, []).should == []
+ [].send(@method, [1, 2]).should == []
+ [ 1, 3, 5 ].send(@method, [ 1, 2, 3 ]).should == [1, 3]
+ end
+
+ it "creates an array with no duplicates" do
+ [ 1, 1, 3, 5 ].send(@method, [ 1, 2, 3 ]).uniq!.should == nil
+ end
+
+ it "creates an array with elements in order they are first encountered" do
+ [ 1, 2, 3, 2, 5, 6, 7, 8 ].send(@method, [ 5, 2, 3, 4 ]).should == [2, 3, 5] # array > other
+ [ 5, 2, 3, 4 ].send(@method, [ 1, 2, 3, 2, 5, 6, 7, 8 ]).should == [5, 2, 3] # array < other
+ end
+
+ it "does not modify the original Array" do
+ a = [1, 1, 3, 5]
+ a.send(@method, [1, 2, 3]).should == [1, 3]
+ a.should == [1, 1, 3, 5]
+ end
+
+ it "properly handles recursive arrays" do
+ empty = ArraySpecs.empty_recursive_array
+ empty.send(@method, empty).should == empty
+
+ ArraySpecs.recursive_array.send(@method, []).should == []
+ [].send(@method, ArraySpecs.recursive_array).should == []
+
+ ArraySpecs.recursive_array.send(@method, ArraySpecs.recursive_array).should == [1, 'two', 3.0, ArraySpecs.recursive_array]
+ end
+
+ it "tries to convert the passed argument to an Array using #to_ary" do
+ obj = mock('[1,2,3]')
+ obj.should_receive(:to_ary).and_return([1, 2, 3])
+ [1, 2].send(@method, obj).should == ([1, 2])
+ end
+
+ it "determines equivalence between elements in the sense of eql?" do
+ not_supported_on :opal do
+ [5.0, 4.0].send(@method, [5, 4]).should == []
+ end
+
+ str = "x"
+ [str].send(@method, [str.dup]).should == [str]
+
+ obj1 = mock('1')
+ obj2 = mock('2')
+ obj1.stub!(:hash).and_return(0)
+ obj2.stub!(:hash).and_return(0)
+ obj1.should_receive(:eql?).at_least(1).and_return(true)
+ obj2.stub!(:eql?).and_return(true)
+
+ [obj1].send(@method, [obj2]).should == [obj1]
+ [obj1, obj1, obj2, obj2].send(@method, [obj2]).should == [obj1]
+
+ obj1 = mock('3')
+ obj2 = mock('4')
+ obj1.stub!(:hash).and_return(0)
+ obj2.stub!(:hash).and_return(0)
+ obj1.should_receive(:eql?).at_least(1).and_return(false)
+
+ [obj1].send(@method, [obj2]).should == []
+ [obj1, obj1, obj2, obj2].send(@method, [obj2]).should == [obj2]
+ end
+
+ it "does return subclass instances for Array subclasses" do
+ ArraySpecs::MyArray[1, 2, 3].send(@method, []).should.instance_of?(Array)
+ ArraySpecs::MyArray[1, 2, 3].send(@method, ArraySpecs::MyArray[1, 2, 3]).should.instance_of?(Array)
+ [].send(@method, ArraySpecs::MyArray[1, 2, 3]).should.instance_of?(Array)
+ end
+
+ it "does not call to_ary on array subclasses" do
+ [5, 6].send(@method, ArraySpecs::ToAryArray[1, 2, 5, 6]).should == [5, 6]
+ end
+
+ it "properly handles an identical item even when its #eql? isn't reflexive" do
+ x = mock('x')
+ x.stub!(:hash).and_return(42)
+ x.stub!(:eql?).and_return(false) # Stubbed for clarity and latitude in implementation; not actually sent by MRI.
+
+ [x].send(@method, [x]).should == [x]
+ end
+end
diff --git a/spec/ruby/core/array/shared/iterable_and_tolerating_size_increasing.rb b/spec/ruby/core/array/shared/iterable_and_tolerating_size_increasing.rb
new file mode 100644
index 0000000000..3e73bad44b
--- /dev/null
+++ b/spec/ruby/core/array/shared/iterable_and_tolerating_size_increasing.rb
@@ -0,0 +1,25 @@
+describe :array_iterable_and_tolerating_size_increasing, shared: true do
+ before do
+ @value_to_return ||= -> _ { nil }
+ end
+
+ it "tolerates increasing an array size during iteration" do
+ # The goal is to trigger potential reallocation of internal array storage, so we:
+ # - use elements of different types, starting with the less generic (Integer)
+ # - add reasonably big number of new elements (~ 100)
+ array = [1, 2, 3] # to test some methods we need several uniq elements
+ array_to_join = [:a, :b, :c] + (4..100).to_a
+
+ ScratchPad.record []
+ i = 0
+
+ array.send(@method) do |e|
+ ScratchPad << e
+ array << array_to_join[i] if i < array_to_join.size
+ i += 1
+ @value_to_return.call(e)
+ end
+
+ ScratchPad.recorded.should == [1, 2, 3] + array_to_join
+ end
+end
diff --git a/spec/ruby/core/array/shared/join.rb b/spec/ruby/core/array/shared/join.rb
index fa66588b47..93d5329ee3 100644
--- a/spec/ruby/core/array/shared/join.rb
+++ b/spec/ruby/core/array/shared/join.rb
@@ -1,115 +1,5 @@
-require File.expand_path('../../fixtures/classes', __FILE__)
-require File.expand_path('../../fixtures/encoded_strings', __FILE__)
-
-describe :array_join_with_default_separator, shared: true do
- before :each do
- @separator = $,
- end
-
- after :each do
- $, = @separator
- end
-
- it "returns an empty string if the Array is empty" do
- [].send(@method).should == ''
- end
-
- it "returns a US-ASCII string for an empty Array" do
- [].send(@method).encoding.should == Encoding::US_ASCII
- end
-
- it "returns a string formed by concatenating each String element separated by $," do
- $, = " | "
- ["1", "2", "3"].send(@method).should == "1 | 2 | 3"
- end
-
- it "attempts coercion via #to_str first" do
- obj = mock('foo')
- obj.should_receive(:to_str).any_number_of_times.and_return("foo")
- [obj].send(@method).should == "foo"
- end
-
- it "attempts coercion via #to_ary second" do
- obj = mock('foo')
- obj.should_receive(:to_str).any_number_of_times.and_return(nil)
- obj.should_receive(:to_ary).any_number_of_times.and_return(["foo"])
- [obj].send(@method).should == "foo"
- end
-
- it "attempts coercion via #to_s third" do
- obj = mock('foo')
- obj.should_receive(:to_str).any_number_of_times.and_return(nil)
- obj.should_receive(:to_ary).any_number_of_times.and_return(nil)
- obj.should_receive(:to_s).any_number_of_times.and_return("foo")
- [obj].send(@method).should == "foo"
- end
-
- it "raises a NoMethodError if an element does not respond to #to_str, #to_ary, or #to_s" do
- obj = mock('o')
- class << obj; undef :to_s; end
- lambda { [1, obj].send(@method) }.should raise_error(NoMethodError)
- end
-
- it "raises an ArgumentError when the Array is recursive" do
- lambda { ArraySpecs.recursive_array.send(@method) }.should raise_error(ArgumentError)
- lambda { ArraySpecs.head_recursive_array.send(@method) }.should raise_error(ArgumentError)
- lambda { ArraySpecs.empty_recursive_array.send(@method) }.should raise_error(ArgumentError)
- end
-
- it "taints the result if the Array is tainted and non-empty" do
- [1, 2].taint.send(@method).tainted?.should be_true
- end
-
- it "does not taint the result if the Array is tainted but empty" do
- [].taint.send(@method).tainted?.should be_false
- end
-
- it "taints the result if the result of coercing an element is tainted" do
- s = mock("taint")
- s.should_receive(:to_s).and_return("str".taint)
- [s].send(@method).tainted?.should be_true
- end
-
- it "untrusts the result if the Array is untrusted and non-empty" do
- [1, 2].untrust.send(@method).untrusted?.should be_true
- end
-
- it "does not untrust the result if the Array is untrusted but empty" do
- [].untrust.send(@method).untrusted?.should be_false
- end
-
- it "untrusts the result if the result of coercing an element is untrusted" do
- s = mock("untrust")
- s.should_receive(:to_s).and_return("str".untrust)
- [s].send(@method).untrusted?.should be_true
- end
-
- it "uses the first encoding when other strings are compatible" do
- ary1 = ArraySpecs.array_with_7bit_utf8_and_usascii_strings
- ary2 = ArraySpecs.array_with_usascii_and_7bit_utf8_strings
- ary3 = ArraySpecs.array_with_utf8_and_7bit_ascii8bit_strings
- ary4 = ArraySpecs.array_with_usascii_and_7bit_ascii8bit_strings
-
- ary1.send(@method).encoding.should == Encoding::UTF_8
- ary2.send(@method).encoding.should == Encoding::US_ASCII
- ary3.send(@method).encoding.should == Encoding::UTF_8
- ary4.send(@method).encoding.should == Encoding::US_ASCII
- end
-
- it "uses the widest common encoding when other strings are incompatible" do
- ary1 = ArraySpecs.array_with_utf8_and_usascii_strings
- ary2 = ArraySpecs.array_with_usascii_and_utf8_strings
-
- ary1.send(@method).encoding.should == Encoding::UTF_8
- ary2.send(@method).encoding.should == Encoding::UTF_8
- end
-
- it "fails for arrays with incompatibly-encoded strings" do
- ary_utf8_bad_ascii8bit = ArraySpecs.array_with_utf8_and_ascii8bit_strings
-
- lambda { ary_utf8_bad_ascii8bit.send(@method) }.should raise_error(EncodingError)
- end
-end
+require_relative '../fixtures/classes'
+require_relative '../fixtures/encoded_strings'
describe :array_join_with_string_separator, shared: true do
it "returns a string formed by concatenating each element.to_str separated by separator" do
@@ -122,40 +12,4 @@ describe :array_join_with_string_separator, shared: true do
[1, [2, [3, 4], 5], 6].send(@method, ":").should == "1:2:3:4:5:6"
[1, [2, ArraySpecs::MyArray[3, 4], 5], 6].send(@method, ":").should == "1:2:3:4:5:6"
end
-
- describe "with a tainted separator" do
- before :each do
- @sep = ":".taint
- end
-
- it "does not taint the result if the array is empty" do
- [].send(@method, @sep).tainted?.should be_false
- end
-
- it "does not taint the result if the array has only one element" do
- [1].send(@method, @sep).tainted?.should be_false
- end
-
- it "taints the result if the array has two or more elements" do
- [1, 2].send(@method, @sep).tainted?.should be_true
- end
- end
-
- describe "with an untrusted separator" do
- before :each do
- @sep = ":".untrust
- end
-
- it "does not untrust the result if the array is empty" do
- [].send(@method, @sep).untrusted?.should be_false
- end
-
- it "does not untrust the result if the array has only one element" do
- [1].send(@method, @sep).untrusted?.should be_false
- end
-
- it "untrusts the result if the array has two or more elements" do
- [1, 2].send(@method, @sep).untrusted?.should be_true
- end
- end
end
diff --git a/spec/ruby/core/array/shared/keep_if.rb b/spec/ruby/core/array/shared/keep_if.rb
index 581ba31d1b..44625eebd1 100644
--- a/spec/ruby/core/array/shared/keep_if.rb
+++ b/spec/ruby/core/array/shared/keep_if.rb
@@ -1,14 +1,15 @@
-require File.expand_path('../../../enumerable/shared/enumeratorized', __FILE__)
+require_relative '../../enumerable/shared/enumeratorized'
+require_relative '../shared/iterable_and_tolerating_size_increasing'
describe :keep_if, shared: true do
it "deletes elements for which the block returns a false value" do
array = [1, 2, 3, 4, 5]
- array.send(@method) {|item| item > 3 }.should equal(array)
+ array.send(@method) {|item| item > 3 }.should.equal?(array)
array.should == [4, 5]
end
it "returns an enumerator if no block is given" do
- [1, 2, 3].send(@method).should be_an_instance_of(Enumerator)
+ [1, 2, 3].send(@method).should.instance_of?(Enumerator)
end
it "updates the receiver after all blocks" do
@@ -32,29 +33,63 @@ describe :keep_if, shared: true do
end
it "returns an Enumerator if no block is given" do
- @frozen.send(@method).should be_an_instance_of(Enumerator)
+ @frozen.send(@method).should.instance_of?(Enumerator)
end
describe "with truthy block" do
it "keeps elements after any exception" do
- lambda { @frozen.send(@method) { true } }.should raise_error(Exception)
+ -> { @frozen.send(@method) { true } }.should.raise(Exception)
@frozen.should == @origin
end
- it "raises a RuntimeError" do
- lambda { @frozen.send(@method) { true } }.should raise_error(RuntimeError)
+ it "raises a FrozenError" do
+ -> { @frozen.send(@method) { true } }.should.raise(FrozenError)
end
end
describe "with falsy block" do
it "keeps elements after any exception" do
- lambda { @frozen.send(@method) { false } }.should raise_error(Exception)
+ -> { @frozen.send(@method) { false } }.should.raise(Exception)
@frozen.should == @origin
end
- it "raises a RuntimeError" do
- lambda { @frozen.send(@method) { false } }.should raise_error(RuntimeError)
+ it "raises a FrozenError" do
+ -> { @frozen.send(@method) { false } }.should.raise(FrozenError)
end
end
+
+ it "raises a FrozenError on a frozen array only during iteration if called without a block" do
+ enum = @frozen.send(@method)
+ -> { enum.each {} }.should.raise(FrozenError)
+ end
+ end
+
+ it "does not truncate the array is the block raises an exception" do
+ a = [1, 2, 3]
+ begin
+ a.send(@method) { raise StandardError, 'Oops' }
+ rescue
+ end
+
+ a.should == [1, 2, 3]
end
+
+ it "only changes elements before error is raised, keeping the element which raised an error." do
+ a = [1, 2, 3, 4]
+ begin
+ a.send(@method) do |e|
+ case e
+ when 2 then false
+ when 3 then raise StandardError, 'Oops'
+ else true
+ end
+ end
+ rescue StandardError
+ end
+
+ a.should == [1, 3, 4]
+ end
+
+ @value_to_return = -> _ { true }
+ it_should_behave_like :array_iterable_and_tolerating_size_increasing
end
diff --git a/spec/ruby/core/array/shared/length.rb b/spec/ruby/core/array/shared/length.rb
deleted file mode 100644
index f84966d0ba..0000000000
--- a/spec/ruby/core/array/shared/length.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-describe :array_length, shared: true do
- it "returns the number of elements" do
- [].send(@method).should == 0
- [1, 2, 3].send(@method).should == 3
- end
-
- it "properly handles recursive arrays" do
- ArraySpecs.empty_recursive_array.send(@method).should == 1
- ArraySpecs.recursive_array.send(@method).should == 8
- end
-end
diff --git a/spec/ruby/core/array/shared/replace.rb b/spec/ruby/core/array/shared/replace.rb
deleted file mode 100644
index 8442d9a841..0000000000
--- a/spec/ruby/core/array/shared/replace.rb
+++ /dev/null
@@ -1,60 +0,0 @@
-describe :array_replace, shared: true do
- it "replaces the elements with elements from other array" do
- a = [1, 2, 3, 4, 5]
- b = ['a', 'b', 'c']
- a.send(@method, b).should equal(a)
- a.should == b
- a.should_not equal(b)
-
- a.send(@method, [4] * 10)
- a.should == [4] * 10
-
- a.send(@method, [])
- a.should == []
- end
-
- it "properly handles recursive arrays" do
- orig = [1, 2, 3]
- empty = ArraySpecs.empty_recursive_array
- orig.send(@method, empty)
- orig.should == empty
-
- array = ArraySpecs.recursive_array
- orig.send(@method, array)
- orig.should == array
- end
-
- it "returns self" do
- ary = [1, 2, 3]
- other = [:a, :b, :c]
- ary.send(@method, other).should equal(ary)
- end
-
- it "does not make self dependent to the original array" do
- ary = [1, 2, 3]
- other = [:a, :b, :c]
- ary.send(@method, other)
- ary.should == [:a, :b, :c]
- ary << :d
- ary.should == [:a, :b, :c, :d]
- other.should == [:a, :b, :c]
- end
-
- it "tries to convert the passed argument to an Array using #to_ary" do
- obj = mock('to_ary')
- obj.stub!(:to_ary).and_return([1, 2, 3])
- [].send(@method, obj).should == [1, 2, 3]
- end
-
- it "does not call #to_ary on Array subclasses" do
- obj = ArraySpecs::ToAryArray[5, 6, 7]
- obj.should_not_receive(:to_ary)
- [].send(@method, ArraySpecs::ToAryArray[5, 6, 7]).should == [5, 6, 7]
- end
-
- it "raises a RuntimeError on a frozen array" do
- lambda {
- ArraySpecs.frozen_array.send(@method, ArraySpecs.frozen_array)
- }.should raise_error(RuntimeError)
- end
-end
diff --git a/spec/ruby/core/array/shared/slice.rb b/spec/ruby/core/array/shared/slice.rb
deleted file mode 100644
index b3f4ccb9a6..0000000000
--- a/spec/ruby/core/array/shared/slice.rb
+++ /dev/null
@@ -1,459 +0,0 @@
-describe :array_slice, shared: true do
- it "returns the element at index with [index]" do
- [ "a", "b", "c", "d", "e" ].send(@method, 1).should == "b"
-
- a = [1, 2, 3, 4]
-
- a.send(@method, 0).should == 1
- a.send(@method, 1).should == 2
- a.send(@method, 2).should == 3
- a.send(@method, 3).should == 4
- a.send(@method, 4).should == nil
- a.send(@method, 10).should == nil
-
- a.should == [1, 2, 3, 4]
- end
-
- it "returns the element at index from the end of the array with [-index]" do
- [ "a", "b", "c", "d", "e" ].send(@method, -2).should == "d"
-
- a = [1, 2, 3, 4]
-
- a.send(@method, -1).should == 4
- a.send(@method, -2).should == 3
- a.send(@method, -3).should == 2
- a.send(@method, -4).should == 1
- a.send(@method, -5).should == nil
- a.send(@method, -10).should == nil
-
- a.should == [1, 2, 3, 4]
- end
-
- it "returns count elements starting from index with [index, count]" do
- [ "a", "b", "c", "d", "e" ].send(@method, 2, 3).should == ["c", "d", "e"]
-
- a = [1, 2, 3, 4]
-
- a.send(@method, 0, 0).should == []
- a.send(@method, 0, 1).should == [1]
- a.send(@method, 0, 2).should == [1, 2]
- a.send(@method, 0, 4).should == [1, 2, 3, 4]
- a.send(@method, 0, 6).should == [1, 2, 3, 4]
- a.send(@method, 0, -1).should == nil
- a.send(@method, 0, -2).should == nil
- a.send(@method, 0, -4).should == nil
-
- a.send(@method, 2, 0).should == []
- a.send(@method, 2, 1).should == [3]
- a.send(@method, 2, 2).should == [3, 4]
- a.send(@method, 2, 4).should == [3, 4]
- a.send(@method, 2, -1).should == nil
-
- a.send(@method, 4, 0).should == []
- a.send(@method, 4, 2).should == []
- a.send(@method, 4, -1).should == nil
-
- a.send(@method, 5, 0).should == nil
- a.send(@method, 5, 2).should == nil
- a.send(@method, 5, -1).should == nil
-
- a.send(@method, 6, 0).should == nil
- a.send(@method, 6, 2).should == nil
- a.send(@method, 6, -1).should == nil
-
- a.should == [1, 2, 3, 4]
- end
-
- it "returns count elements starting at index from the end of array with [-index, count]" do
- [ "a", "b", "c", "d", "e" ].send(@method, -2, 2).should == ["d", "e"]
-
- a = [1, 2, 3, 4]
-
- a.send(@method, -1, 0).should == []
- a.send(@method, -1, 1).should == [4]
- a.send(@method, -1, 2).should == [4]
- a.send(@method, -1, -1).should == nil
-
- a.send(@method, -2, 0).should == []
- a.send(@method, -2, 1).should == [3]
- a.send(@method, -2, 2).should == [3, 4]
- a.send(@method, -2, 4).should == [3, 4]
- a.send(@method, -2, -1).should == nil
-
- a.send(@method, -4, 0).should == []
- a.send(@method, -4, 1).should == [1]
- a.send(@method, -4, 2).should == [1, 2]
- a.send(@method, -4, 4).should == [1, 2, 3, 4]
- a.send(@method, -4, 6).should == [1, 2, 3, 4]
- a.send(@method, -4, -1).should == nil
-
- a.send(@method, -5, 0).should == nil
- a.send(@method, -5, 1).should == nil
- a.send(@method, -5, 10).should == nil
- a.send(@method, -5, -1).should == nil
-
- a.should == [1, 2, 3, 4]
- end
-
- it "returns the first count elements with [0, count]" do
- [ "a", "b", "c", "d", "e" ].send(@method, 0, 3).should == ["a", "b", "c"]
- end
-
- it "returns the subarray which is independent to self with [index,count]" do
- a = [1, 2, 3]
- sub = a.send(@method, 1,2)
- sub.replace([:a, :b])
- a.should == [1, 2, 3]
- end
-
- it "tries to convert the passed argument to an Integer using #to_int" do
- obj = mock('to_int')
- obj.stub!(:to_int).and_return(2)
-
- a = [1, 2, 3, 4]
- a.send(@method, obj).should == 3
- a.send(@method, obj, 1).should == [3]
- a.send(@method, obj, obj).should == [3, 4]
- a.send(@method, 0, obj).should == [1, 2]
- end
-
- it "returns the elements specified by Range indexes with [m..n]" do
- [ "a", "b", "c", "d", "e" ].send(@method, 1..3).should == ["b", "c", "d"]
- [ "a", "b", "c", "d", "e" ].send(@method, 4..-1).should == ['e']
- [ "a", "b", "c", "d", "e" ].send(@method, 3..3).should == ['d']
- [ "a", "b", "c", "d", "e" ].send(@method, 3..-2).should == ['d']
- ['a'].send(@method, 0..-1).should == ['a']
-
- a = [1, 2, 3, 4]
-
- a.send(@method, 0..-10).should == []
- a.send(@method, 0..0).should == [1]
- a.send(@method, 0..1).should == [1, 2]
- a.send(@method, 0..2).should == [1, 2, 3]
- a.send(@method, 0..3).should == [1, 2, 3, 4]
- a.send(@method, 0..4).should == [1, 2, 3, 4]
- a.send(@method, 0..10).should == [1, 2, 3, 4]
-
- a.send(@method, 2..-10).should == []
- a.send(@method, 2..0).should == []
- a.send(@method, 2..2).should == [3]
- a.send(@method, 2..3).should == [3, 4]
- a.send(@method, 2..4).should == [3, 4]
-
- a.send(@method, 3..0).should == []
- a.send(@method, 3..3).should == [4]
- a.send(@method, 3..4).should == [4]
-
- a.send(@method, 4..0).should == []
- a.send(@method, 4..4).should == []
- a.send(@method, 4..5).should == []
-
- a.send(@method, 5..0).should == nil
- a.send(@method, 5..5).should == nil
- a.send(@method, 5..6).should == nil
-
- a.should == [1, 2, 3, 4]
- end
-
- it "returns elements specified by Range indexes except the element at index n with [m...n]" do
- [ "a", "b", "c", "d", "e" ].send(@method, 1...3).should == ["b", "c"]
-
- a = [1, 2, 3, 4]
-
- a.send(@method, 0...-10).should == []
- a.send(@method, 0...0).should == []
- a.send(@method, 0...1).should == [1]
- a.send(@method, 0...2).should == [1, 2]
- a.send(@method, 0...3).should == [1, 2, 3]
- a.send(@method, 0...4).should == [1, 2, 3, 4]
- a.send(@method, 0...10).should == [1, 2, 3, 4]
-
- a.send(@method, 2...-10).should == []
- a.send(@method, 2...0).should == []
- a.send(@method, 2...2).should == []
- a.send(@method, 2...3).should == [3]
- a.send(@method, 2...4).should == [3, 4]
-
- a.send(@method, 3...0).should == []
- a.send(@method, 3...3).should == []
- a.send(@method, 3...4).should == [4]
-
- a.send(@method, 4...0).should == []
- a.send(@method, 4...4).should == []
- a.send(@method, 4...5).should == []
-
- a.send(@method, 5...0).should == nil
- a.send(@method, 5...5).should == nil
- a.send(@method, 5...6).should == nil
-
- a.should == [1, 2, 3, 4]
- end
-
- it "returns elements that exist if range start is in the array but range end is not with [m..n]" do
- [ "a", "b", "c", "d", "e" ].send(@method, 4..7).should == ["e"]
- end
-
- it "accepts Range instances having a negative m and both signs for n with [m..n] and [m...n]" do
- a = [1, 2, 3, 4]
-
- a.send(@method, -1..-1).should == [4]
- a.send(@method, -1...-1).should == []
- a.send(@method, -1..3).should == [4]
- a.send(@method, -1...3).should == []
- a.send(@method, -1..4).should == [4]
- a.send(@method, -1...4).should == [4]
- a.send(@method, -1..10).should == [4]
- a.send(@method, -1...10).should == [4]
- a.send(@method, -1..0).should == []
- a.send(@method, -1..-4).should == []
- a.send(@method, -1...-4).should == []
- a.send(@method, -1..-6).should == []
- a.send(@method, -1...-6).should == []
-
- a.send(@method, -2..-2).should == [3]
- a.send(@method, -2...-2).should == []
- a.send(@method, -2..-1).should == [3, 4]
- a.send(@method, -2...-1).should == [3]
- a.send(@method, -2..10).should == [3, 4]
- a.send(@method, -2...10).should == [3, 4]
-
- a.send(@method, -4..-4).should == [1]
- a.send(@method, -4..-2).should == [1, 2, 3]
- a.send(@method, -4...-2).should == [1, 2]
- a.send(@method, -4..-1).should == [1, 2, 3, 4]
- a.send(@method, -4...-1).should == [1, 2, 3]
- a.send(@method, -4..3).should == [1, 2, 3, 4]
- a.send(@method, -4...3).should == [1, 2, 3]
- a.send(@method, -4..4).should == [1, 2, 3, 4]
- a.send(@method, -4...4).should == [1, 2, 3, 4]
- a.send(@method, -4...4).should == [1, 2, 3, 4]
- a.send(@method, -4..0).should == [1]
- a.send(@method, -4...0).should == []
- a.send(@method, -4..1).should == [1, 2]
- a.send(@method, -4...1).should == [1]
-
- a.send(@method, -5..-5).should == nil
- a.send(@method, -5...-5).should == nil
- a.send(@method, -5..-4).should == nil
- a.send(@method, -5..-1).should == nil
- a.send(@method, -5..10).should == nil
-
- a.should == [1, 2, 3, 4]
- end
-
- it "returns the subarray which is independent to self with [m..n]" do
- a = [1, 2, 3]
- sub = a.send(@method, 1..2)
- sub.replace([:a, :b])
- a.should == [1, 2, 3]
- end
-
- it "tries to convert Range elements to Integers using #to_int with [m..n] and [m...n]" do
- from = mock('from')
- to = mock('to')
-
- # So we can construct a range out of them...
- def from.<=>(o) 0 end
- def to.<=>(o) 0 end
-
- def from.to_int() 1 end
- def to.to_int() -2 end
-
- a = [1, 2, 3, 4]
-
- a.send(@method, from..to).should == [2, 3]
- a.send(@method, from...to).should == [2]
- a.send(@method, 1..0).should == []
- a.send(@method, 1...0).should == []
-
- lambda { a.send(@method, "a" .. "b") }.should raise_error(TypeError)
- lambda { a.send(@method, "a" ... "b") }.should raise_error(TypeError)
- lambda { a.send(@method, from .. "b") }.should raise_error(TypeError)
- lambda { a.send(@method, from ... "b") }.should raise_error(TypeError)
- end
-
- it "returns the same elements as [m..n] and [m...n] with Range subclasses" do
- a = [1, 2, 3, 4]
- range_incl = ArraySpecs::MyRange.new(1, 2)
- range_excl = ArraySpecs::MyRange.new(-3, -1, true)
-
- a.send(@method, range_incl).should == [2, 3]
- a.send(@method, range_excl).should == [2, 3]
- end
-
- it "returns nil for a requested index not in the array with [index]" do
- [ "a", "b", "c", "d", "e" ].send(@method, 5).should == nil
- end
-
- it "returns [] if the index is valid but length is zero with [index, length]" do
- [ "a", "b", "c", "d", "e" ].send(@method, 0, 0).should == []
- [ "a", "b", "c", "d", "e" ].send(@method, 2, 0).should == []
- end
-
- it "returns nil if length is zero but index is invalid with [index, length]" do
- [ "a", "b", "c", "d", "e" ].send(@method, 100, 0).should == nil
- [ "a", "b", "c", "d", "e" ].send(@method, -50, 0).should == nil
- end
-
- # This is by design. It is in the official documentation.
- it "returns [] if index == array.size with [index, length]" do
- %w|a b c d e|.send(@method, 5, 2).should == []
- end
-
- it "returns nil if index > array.size with [index, length]" do
- %w|a b c d e|.send(@method, 6, 2).should == nil
- end
-
- it "returns nil if length is negative with [index, length]" do
- %w|a b c d e|.send(@method, 3, -1).should == nil
- %w|a b c d e|.send(@method, 2, -2).should == nil
- %w|a b c d e|.send(@method, 1, -100).should == nil
- end
-
- it "returns nil if no requested index is in the array with [m..n]" do
- [ "a", "b", "c", "d", "e" ].send(@method, 6..10).should == nil
- end
-
- it "returns nil if range start is not in the array with [m..n]" do
- [ "a", "b", "c", "d", "e" ].send(@method, -10..2).should == nil
- [ "a", "b", "c", "d", "e" ].send(@method, 10..12).should == nil
- end
-
- it "returns an empty array when m == n with [m...n]" do
- [1, 2, 3, 4, 5].send(@method, 1...1).should == []
- end
-
- it "returns an empty array with [0...0]" do
- [1, 2, 3, 4, 5].send(@method, 0...0).should == []
- end
-
- it "returns a subarray where m, n negatives and m < n with [m..n]" do
- [ "a", "b", "c", "d", "e" ].send(@method, -3..-2).should == ["c", "d"]
- end
-
- it "returns an array containing the first element with [0..0]" do
- [1, 2, 3, 4, 5].send(@method, 0..0).should == [1]
- end
-
- it "returns the entire array with [0..-1]" do
- [1, 2, 3, 4, 5].send(@method, 0..-1).should == [1, 2, 3, 4, 5]
- end
-
- it "returns all but the last element with [0...-1]" do
- [1, 2, 3, 4, 5].send(@method, 0...-1).should == [1, 2, 3, 4]
- end
-
- it "returns [3] for [2..-1] out of [1, 2, 3]" do
- [1,2,3].send(@method, 2..-1).should == [3]
- end
-
- it "returns an empty array when m > n and m, n are positive with [m..n]" do
- [1, 2, 3, 4, 5].send(@method, 3..2).should == []
- end
-
- it "returns an empty array when m > n and m, n are negative with [m..n]" do
- [1, 2, 3, 4, 5].send(@method, -2..-3).should == []
- end
-
- it "does not expand array when the indices are outside of the array bounds" do
- a = [1, 2]
- a.send(@method, 4).should == nil
- a.should == [1, 2]
- a.send(@method, 4, 0).should == nil
- a.should == [1, 2]
- a.send(@method, 6, 1).should == nil
- a.should == [1, 2]
- a.send(@method, 8...8).should == nil
- a.should == [1, 2]
- a.send(@method, 10..10).should == nil
- a.should == [1, 2]
- end
-
- describe "with a subclass of Array" do
- before :each do
- ScratchPad.clear
-
- @array = ArraySpecs::MyArray[1, 2, 3, 4, 5]
- end
-
- it "returns a subclass instance with [n, m]" do
- @array.send(@method, 0, 2).should be_an_instance_of(ArraySpecs::MyArray)
- end
-
- it "returns a subclass instance with [-n, m]" do
- @array.send(@method, -3, 2).should be_an_instance_of(ArraySpecs::MyArray)
- end
-
- it "returns a subclass instance with [n..m]" do
- @array.send(@method, 1..3).should be_an_instance_of(ArraySpecs::MyArray)
- end
-
- it "returns a subclass instance with [n...m]" do
- @array.send(@method, 1...3).should be_an_instance_of(ArraySpecs::MyArray)
- end
-
- it "returns a subclass instance with [-n..-m]" do
- @array.send(@method, -3..-1).should be_an_instance_of(ArraySpecs::MyArray)
- end
-
- it "returns a subclass instance with [-n...-m]" do
- @array.send(@method, -3...-1).should be_an_instance_of(ArraySpecs::MyArray)
- end
-
- it "returns an empty array when m == n with [m...n]" do
- @array.send(@method, 1...1).should == []
- ScratchPad.recorded.should be_nil
- end
-
- it "returns an empty array with [0...0]" do
- @array.send(@method, 0...0).should == []
- ScratchPad.recorded.should be_nil
- end
-
- it "returns an empty array when m > n and m, n are positive with [m..n]" do
- @array.send(@method, 3..2).should == []
- ScratchPad.recorded.should be_nil
- end
-
- it "returns an empty array when m > n and m, n are negative with [m..n]" do
- @array.send(@method, -2..-3).should == []
- ScratchPad.recorded.should be_nil
- end
-
- it "returns [] if index == array.size with [index, length]" do
- @array.send(@method, 5, 2).should == []
- ScratchPad.recorded.should be_nil
- end
-
- it "returns [] if the index is valid but length is zero with [index, length]" do
- @array.send(@method, 0, 0).should == []
- @array.send(@method, 2, 0).should == []
- ScratchPad.recorded.should be_nil
- end
-
- it "does not call #initialize on the subclass instance" do
- @array.send(@method, 0, 3).should == [1, 2, 3]
- ScratchPad.recorded.should be_nil
- end
- end
-
- it "raises a RangeError when the start index is out of range of Fixnum" do
- array = [1, 2, 3, 4, 5, 6]
- obj = mock('large value')
- obj.should_receive(:to_int).and_return(0x8000_0000_0000_0000_0000)
- lambda { array.send(@method, obj) }.should raise_error(RangeError)
-
- obj = 8e19
- lambda { array.send(@method, obj) }.should raise_error(RangeError)
- end
-
- it "raises a RangeError when the length is out of range of Fixnum" do
- array = [1, 2, 3, 4, 5, 6]
- obj = mock('large value')
- obj.should_receive(:to_int).and_return(0x8000_0000_0000_0000_0000)
- lambda { array.send(@method, 1, obj) }.should raise_error(RangeError)
-
- obj = 8e19
- lambda { array.send(@method, 1, obj) }.should raise_error(RangeError)
- end
-end
diff --git a/spec/ruby/core/array/shared/union.rb b/spec/ruby/core/array/shared/union.rb
new file mode 100644
index 0000000000..0b225b9a31
--- /dev/null
+++ b/spec/ruby/core/array/shared/union.rb
@@ -0,0 +1,79 @@
+describe :array_binary_union, shared: true do
+ it "returns an array of elements that appear in either array (union)" do
+ [].send(@method, []).should == []
+ [1, 2].send(@method, []).should == [1, 2]
+ [].send(@method, [1, 2]).should == [1, 2]
+ [ 1, 2, 3, 4 ].send(@method, [ 3, 4, 5 ]).should == [1, 2, 3, 4, 5]
+ end
+
+ it "creates an array with no duplicates" do
+ [ 1, 2, 3, 1, 4, 5 ].send(@method, [ 1, 3, 4, 5, 3, 6 ]).should == [1, 2, 3, 4, 5, 6]
+ end
+
+ it "creates an array with elements in order they are first encountered" do
+ [ 1, 2, 3, 1 ].send(@method, [ 1, 3, 4, 5 ]).should == [1, 2, 3, 4, 5]
+ end
+
+ it "properly handles recursive arrays" do
+ empty = ArraySpecs.empty_recursive_array
+ empty.send(@method, empty).should == empty
+
+ array = ArraySpecs.recursive_array
+ array.send(@method, []).should == [1, 'two', 3.0, array]
+ [].send(@method, array).should == [1, 'two', 3.0, array]
+ array.send(@method, array).should == [1, 'two', 3.0, array]
+ array.send(@method, empty).should == [1, 'two', 3.0, array, empty]
+ end
+
+ it "tries to convert the passed argument to an Array using #to_ary" do
+ obj = mock('[1,2,3]')
+ obj.should_receive(:to_ary).and_return([1, 2, 3])
+ [0].send(@method, obj).should == ([0] | [1, 2, 3])
+ end
+
+ # MRI follows hashing semantics here, so doesn't actually call eql?/hash for Integer/Symbol
+ it "acts as if using an intermediate hash to collect values" do
+ not_supported_on :opal do
+ [5.0, 4.0].send(@method, [5, 4]).should == [5.0, 4.0, 5, 4]
+ end
+
+ str = "x"
+ [str].send(@method, [str.dup]).should == [str]
+
+ obj1 = mock('1')
+ obj2 = mock('2')
+ obj1.stub!(:hash).and_return(0)
+ obj2.stub!(:hash).and_return(0)
+ obj2.should_receive(:eql?).at_least(1).and_return(true)
+
+ [obj1].send(@method, [obj2]).should == [obj1]
+ [obj1, obj1, obj2, obj2].send(@method, [obj2]).should == [obj1]
+
+ obj1 = mock('3')
+ obj2 = mock('4')
+ obj1.stub!(:hash).and_return(0)
+ obj2.stub!(:hash).and_return(0)
+ obj2.should_receive(:eql?).at_least(1).and_return(false)
+
+ [obj1].send(@method, [obj2]).should == [obj1, obj2]
+ [obj1, obj1, obj2, obj2].send(@method, [obj2]).should == [obj1, obj2]
+ end
+
+ it "does not return subclass instances for Array subclasses" do
+ ArraySpecs::MyArray[1, 2, 3].send(@method, []).should.instance_of?(Array)
+ ArraySpecs::MyArray[1, 2, 3].send(@method, ArraySpecs::MyArray[1, 2, 3]).should.instance_of?(Array)
+ [].send(@method, ArraySpecs::MyArray[1, 2, 3]).should.instance_of?(Array)
+ end
+
+ it "does not call to_ary on array subclasses" do
+ [1, 2].send(@method, ArraySpecs::ToAryArray[5, 6]).should == [1, 2, 5, 6]
+ end
+
+ it "properly handles an identical item even when its #eql? isn't reflexive" do
+ x = mock('x')
+ x.stub!(:hash).and_return(42)
+ x.stub!(:eql?).and_return(false) # Stubbed for clarity and latitude in implementation; not actually sent by MRI.
+
+ [x].send(@method, [x]).should == [x]
+ end
+end
diff --git a/spec/ruby/core/array/shift_spec.rb b/spec/ruby/core/array/shift_spec.rb
index a7b6f58392..09dfa79c45 100644
--- a/spec/ruby/core/array/shift_spec.rb
+++ b/spec/ruby/core/array/shift_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Array#shift" do
it "removes and returns the first element" do
@@ -30,11 +30,11 @@ describe "Array#shift" do
array[0..2].should == ['two', 3.0, array]
end
- it "raises a RuntimeError on a frozen array" do
- lambda { ArraySpecs.frozen_array.shift }.should raise_error(RuntimeError)
+ it "raises a FrozenError on a frozen array" do
+ -> { ArraySpecs.frozen_array.shift }.should.raise(FrozenError)
end
- it "raises a RuntimeError on an empty frozen array" do
- lambda { ArraySpecs.empty_frozen_array.shift }.should raise_error(RuntimeError)
+ it "raises a FrozenError on an empty frozen array" do
+ -> { ArraySpecs.empty_frozen_array.shift }.should.raise(FrozenError)
end
describe "passed a number n as an argument" do
@@ -72,7 +72,7 @@ describe "Array#shift" do
popped2.should == []
a.should == []
- popped1.should_not equal(popped2)
+ popped1.should_not.equal?(popped2)
end
it "returns whole elements if n exceeds size of the array" do
@@ -83,14 +83,14 @@ describe "Array#shift" do
it "does not return self even when it returns whole elements" do
a = [1, 2, 3, 4, 5]
- a.shift(5).should_not equal(a)
+ a.shift(5).should_not.equal?(a)
a = [1, 2, 3, 4, 5]
- a.shift(6).should_not equal(a)
+ a.shift(6).should_not.equal?(a)
end
it "raises an ArgumentError if n is negative" do
- lambda{ [1, 2, 3].shift(-1) }.should raise_error(ArgumentError)
+ ->{ [1, 2, 3].shift(-1) }.should.raise(ArgumentError)
end
it "tries to convert n to an Integer using #to_int" do
@@ -105,30 +105,16 @@ describe "Array#shift" do
end
it "raises a TypeError when the passed n cannot be coerced to Integer" do
- lambda{ [1, 2].shift("cat") }.should raise_error(TypeError)
- lambda{ [1, 2].shift(nil) }.should raise_error(TypeError)
+ ->{ [1, 2].shift("cat") }.should.raise(TypeError)
+ ->{ [1, 2].shift(nil) }.should.raise(TypeError)
end
it "raises an ArgumentError if more arguments are passed" do
- lambda{ [1, 2].shift(1, 2) }.should raise_error(ArgumentError)
+ ->{ [1, 2].shift(1, 2) }.should.raise(ArgumentError)
end
it "does not return subclass instances with Array subclass" do
- ArraySpecs::MyArray[1, 2, 3].shift(2).should be_an_instance_of(Array)
- end
-
- it "returns an untainted array even if the array is tainted" do
- ary = [1, 2].taint
- ary.shift(2).tainted?.should be_false
- ary.shift(0).tainted?.should be_false
- end
-
- it "keeps taint status" do
- a = [1, 2].taint
- a.shift(2)
- a.tainted?.should be_true
- a.shift(2)
- a.tainted?.should be_true
+ ArraySpecs::MyArray[1, 2, 3].shift(2).should.instance_of?(Array)
end
end
end
diff --git a/spec/ruby/core/array/shuffle_spec.rb b/spec/ruby/core/array/shuffle_spec.rb
index 4c3b820186..9bc9df73ac 100644
--- a/spec/ruby/core/array/shuffle_spec.rb
+++ b/spec/ruby/core/array/shuffle_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Array#shuffle" do
it "returns the same values, in a usually different order" do
@@ -10,7 +10,7 @@ describe "Array#shuffle" do
s.sort.should == a
different ||= (a != s)
end
- different.should be_true # Will fail once in a blue moon (4!^10)
+ different.should == true # Will fail once in a blue moon (4!^10)
end
it "is not destructive" do
@@ -22,13 +22,7 @@ describe "Array#shuffle" do
end
it "does not return subclass instances with Array subclass" do
- ArraySpecs::MyArray[1, 2, 3].shuffle.should be_an_instance_of(Array)
- end
-
- it "attempts coercion via #to_hash" do
- obj = mock('hash')
- obj.should_receive(:to_hash).once.and_return({})
- [2, 3].shuffle(obj)
+ ArraySpecs::MyArray[1, 2, 3].shuffle.should.instance_of?(Array)
end
it "calls #rand on the Object passed by the :random key in the arguments Hash" do
@@ -37,20 +31,24 @@ describe "Array#shuffle" do
result = [1, 2].shuffle(random: obj)
result.size.should == 2
- result.should include(1, 2)
+ result.sort.should == [1, 2]
end
it "raises a NoMethodError if an object passed for the RNG does not define #rand" do
obj = BasicObject.new
- lambda { [1, 2].shuffle(random: obj) }.should raise_error(NoMethodError)
+ -> { [1, 2].shuffle(random: obj) }.should.raise(NoMethodError)
end
it "accepts a Float for the value returned by #rand" do
random = mock("array_shuffle_random")
random.should_receive(:rand).at_least(1).times.and_return(0.3)
- [1, 2].shuffle(random: random).should be_an_instance_of(Array)
+ [1, 2].shuffle(random: random).should.instance_of?(Array)
+ end
+
+ it "accepts a Random class for the value for random: argument" do
+ [1, 2].shuffle(random: Random).should.instance_of?(Array)
end
it "calls #to_int on the Object returned by #rand" do
@@ -59,7 +57,7 @@ describe "Array#shuffle" do
random = mock("array_shuffle_random")
random.should_receive(:rand).at_least(1).times.and_return(value)
- [1, 2].shuffle(random: random).should be_an_instance_of(Array)
+ [1, 2].shuffle(random: random).should.instance_of?(Array)
end
it "raises a RangeError if the value is less than zero" do
@@ -68,16 +66,25 @@ describe "Array#shuffle" do
random = mock("array_shuffle_random")
random.should_receive(:rand).and_return(value)
- lambda { [1, 2].shuffle(random: random) }.should raise_error(RangeError)
+ -> { [1, 2].shuffle(random: random) }.should.raise(RangeError)
+ end
+
+ it "raises a RangeError if the value is equal to the Array size" do
+ value = mock("array_shuffle_random_value")
+ value.should_receive(:to_int).at_least(1).times.and_return(2)
+ random = mock("array_shuffle_random")
+ random.should_receive(:rand).at_least(1).times.and_return(value)
+
+ -> { [1, 2].shuffle(random: random) }.should.raise(RangeError)
end
- it "raises a RangeError if the value is equal to one" do
+ it "raises a RangeError if the value is greater than the Array size" do
value = mock("array_shuffle_random_value")
- value.should_receive(:to_int).at_least(1).times.and_return(1)
+ value.should_receive(:to_int).at_least(1).times.and_return(3)
random = mock("array_shuffle_random")
random.should_receive(:rand).at_least(1).times.and_return(value)
- lambda { [1, 2].shuffle(random: random) }.should raise_error(RangeError)
+ -> { [1, 2].shuffle(random: random) }.should.raise(RangeError)
end
end
@@ -91,12 +98,22 @@ describe "Array#shuffle!" do
a.sort.should == [1, 2, 3, 4]
different ||= (a != [1, 2, 3, 4])
end
- different.should be_true # Will fail once in a blue moon (4!^10)
- a.should equal(original)
+ different.should == true # Will fail once in a blue moon (4!^10)
+ a.should.equal?(original)
+ end
+
+ it "raises a FrozenError on a frozen array" do
+ -> { ArraySpecs.frozen_array.shuffle! }.should.raise(FrozenError)
+ -> { ArraySpecs.empty_frozen_array.shuffle! }.should.raise(FrozenError)
+ end
+
+ it "matches CRuby with random:" do
+ %w[a b c].shuffle(random: Random.new(1)).should == %w[a c b]
+ (0..10).to_a.shuffle(random: Random.new(10)).should == [2, 6, 8, 5, 7, 10, 3, 1, 0, 4, 9]
end
- it "raises a RuntimeError on a frozen array" do
- lambda { ArraySpecs.frozen_array.shuffle! }.should raise_error(RuntimeError)
- lambda { ArraySpecs.empty_frozen_array.shuffle! }.should raise_error(RuntimeError)
+ it "matches CRuby with srand" do
+ srand(123)
+ %w[a b c d e f g h i j k].shuffle.should == %w[a e f h i j d b g k c]
end
end
diff --git a/spec/ruby/core/array/size_spec.rb b/spec/ruby/core/array/size_spec.rb
index 2c8a18ade6..710754ed62 100644
--- a/spec/ruby/core/array/size_spec.rb
+++ b/spec/ruby/core/array/size_spec.rb
@@ -1,7 +1,14 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/length', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Array#size" do
- it_behaves_like(:array_length, :size)
+ it "returns the number of elements" do
+ [].size.should == 0
+ [1, 2, 3].size.should == 3
+ end
+
+ it "properly handles recursive arrays" do
+ ArraySpecs.empty_recursive_array.size.should == 1
+ ArraySpecs.recursive_array.size.should == 8
+ end
end
diff --git a/spec/ruby/core/array/slice_spec.rb b/spec/ruby/core/array/slice_spec.rb
index f6cbd1bcc4..230d1dc5d1 100644
--- a/spec/ruby/core/array/slice_spec.rb
+++ b/spec/ruby/core/array/slice_spec.rb
@@ -1,6 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/slice', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Array#slice!" do
it "removes and return the element at index" do
@@ -116,8 +115,8 @@ describe "Array#slice!" do
a.slice!(from .. to).should == [2, 3, 4]
a.should == [1, 5]
- lambda { a.slice!("a" .. "b") }.should raise_error(TypeError)
- lambda { a.slice!(from .. "b") }.should raise_error(TypeError)
+ -> { a.slice!("a" .. "b") }.should.raise(TypeError)
+ -> { a.slice!(from .. "b") }.should.raise(TypeError)
end
it "returns last element for consecutive calls at zero index" do
@@ -150,11 +149,71 @@ describe "Array#slice!" do
a.should == [1, 2]
end
- it "raises a RuntimeError on a frozen array" do
- lambda { ArraySpecs.frozen_array.slice!(0, 0) }.should raise_error(RuntimeError)
+ it "raises a FrozenError on a frozen array" do
+ -> { ArraySpecs.frozen_array.slice!(0, 0) }.should.raise(FrozenError)
+ end
+
+ it "works with endless ranges" do
+ a = [1, 2, 3]
+ a.slice!(eval("(1..)")).should == [2, 3]
+ a.should == [1]
+
+ a = [1, 2, 3]
+ a.slice!(eval("(2...)")).should == [3]
+ a.should == [1, 2]
+
+ a = [1, 2, 3]
+ a.slice!(eval("(-2..)")).should == [2, 3]
+ a.should == [1]
+
+ a = [1, 2, 3]
+ a.slice!(eval("(-1...)")).should == [3]
+ a.should == [1, 2]
+ end
+
+ it "works with beginless ranges" do
+ a = [0,1,2,3,4]
+ a.slice!((..3)).should == [0, 1, 2, 3]
+ a.should == [4]
+
+ a = [0,1,2,3,4]
+ a.slice!((...-2)).should == [0, 1, 2]
+ a.should == [3, 4]
+ end
+
+ describe "with a subclass of Array" do
+ before :each do
+ @array = ArraySpecs::MyArray[1, 2, 3, 4, 5]
+ end
+
+ it "returns a Array instance with [n, m]" do
+ @array.slice!(0, 2).should.instance_of?(Array)
+ end
+
+ it "returns a Array instance with [-n, m]" do
+ @array.slice!(-3, 2).should.instance_of?(Array)
+ end
+
+ it "returns a Array instance with [n..m]" do
+ @array.slice!(1..3).should.instance_of?(Array)
+ end
+
+ it "returns a Array instance with [n...m]" do
+ @array.slice!(1...3).should.instance_of?(Array)
+ end
+
+ it "returns a Array instance with [-n..-m]" do
+ @array.slice!(-3..-1).should.instance_of?(Array)
+ end
+
+ it "returns a Array instance with [-n...-m]" do
+ @array.slice!(-3...-1).should.instance_of?(Array)
+ end
end
end
describe "Array#slice" do
- it_behaves_like(:array_slice, :slice)
+ it "is an alias of Array#[]" do
+ Array.instance_method(:slice).should == Array.instance_method(:[])
+ end
end
diff --git a/spec/ruby/core/array/sort_by_spec.rb b/spec/ruby/core/array/sort_by_spec.rb
index 9f45f3ef4d..132abb028a 100644
--- a/spec/ruby/core/array/sort_by_spec.rb
+++ b/spec/ruby/core/array/sort_by_spec.rb
@@ -1,6 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../../enumerable/shared/enumeratorized', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/iterable_and_tolerating_size_increasing'
+require_relative '../enumerable/shared/enumeratorized'
describe "Array#sort_by!" do
it "sorts array in place by passing each element to the given block" do
@@ -10,25 +11,30 @@ describe "Array#sort_by!" do
end
it "returns an Enumerator if not given a block" do
- (1..10).to_a.sort_by!.should be_an_instance_of(Enumerator)
+ (1..10).to_a.sort_by!.should.instance_of?(Enumerator)
end
it "completes when supplied a block that always returns the same result" do
a = [2, 3, 5, 1, 4]
a.sort_by!{ 1 }
- a.should be_an_instance_of(Array)
+ a.should.instance_of?(Array)
a.sort_by!{ 0 }
- a.should be_an_instance_of(Array)
+ a.should.instance_of?(Array)
a.sort_by!{ -1 }
- a.should be_an_instance_of(Array)
+ a.should.instance_of?(Array)
end
- it "raises a RuntimeError on a frozen array" do
- lambda { ArraySpecs.frozen_array.sort_by! {}}.should raise_error(RuntimeError)
+ it "raises a FrozenError on a frozen array" do
+ -> { ArraySpecs.frozen_array.sort_by! {}}.should.raise(FrozenError)
end
- it "raises a RuntimeError on an empty frozen array" do
- lambda { ArraySpecs.empty_frozen_array.sort_by! {}}.should raise_error(RuntimeError)
+ it "raises a FrozenError on an empty frozen array" do
+ -> { ArraySpecs.empty_frozen_array.sort_by! {}}.should.raise(FrozenError)
+ end
+
+ it "raises a FrozenError on a frozen array only during iteration if called without a block" do
+ enum = ArraySpecs.frozen_array.sort_by!
+ -> { enum.each {} }.should.raise(FrozenError)
end
it "returns the specified value when it would break in the given block" do
@@ -41,12 +47,39 @@ describe "Array#sort_by!" do
ary.sort_by!{|x,y| break if x==i; x<=>y}
ary
}
- partially_sorted.any?{|ary| ary != [1, 2, 3, 4, 5]}.should be_true
+ partially_sorted.any?{|ary| ary != [1, 2, 3, 4, 5]}.should == true
end
it "changes nothing when called on a single element array" do
[1].sort_by!(&:to_s).should == [1]
end
+ it "does not truncate the array is the block raises an exception" do
+ a = [1, 2, 3]
+ begin
+ a.sort_by! { raise StandardError, 'Oops' }
+ rescue
+ end
+
+ a.should == [1, 2, 3]
+ end
+
+ it "doesn't change array if error is raised" do
+ a = [4, 3, 2, 1]
+ begin
+ a.sort_by! do |e|
+ raise StandardError, 'Oops' if e == 1
+ e
+ end
+ rescue StandardError
+ end
+
+ a.should == [4, 3, 2, 1]
+ end
+
it_behaves_like :enumeratorized_with_origin_size, :sort_by!, [1,2,3]
end
+
+describe "Array#sort_by!" do
+ it_behaves_like :array_iterable_and_tolerating_size_increasing, :sort_by!
+end
diff --git a/spec/ruby/core/array/sort_spec.rb b/spec/ruby/core/array/sort_spec.rb
index 584b818caf..27300c3385 100644
--- a/spec/ruby/core/array/sort_spec.rb
+++ b/spec/ruby/core/array/sort_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Array#sort" do
it "returns a new array sorted based on comparing elements with <=>" do
@@ -42,7 +42,7 @@ describe "Array#sort" do
a = [1, 2, 3]
sorted = a.sort
sorted.should == a
- sorted.should_not equal(a)
+ sorted.should_not.equal?(a)
end
it "properly handles recursive arrays" do
@@ -58,15 +58,17 @@ describe "Array#sort" do
b = ArraySpecs::MockForCompared.new
c = ArraySpecs::MockForCompared.new
- ArraySpecs::MockForCompared.compared?.should == false
+ ArraySpecs::MockForCompared.should_not.compared?
[a, b, c].sort.should == [c, b, a]
- ArraySpecs::MockForCompared.compared?.should == true
+ ArraySpecs::MockForCompared.should.compared?
end
it "does not deal with exceptions raised by unimplemented or incorrect #<=>" do
o = Object.new
- lambda { [o, 1].sort }.should raise_error
+ -> {
+ [o, 1].sort
+ }.should.raise(ArgumentError)
end
it "may take a block which is used to determine the order of objects a and b described as -1, 0 or +1" do
@@ -76,43 +78,43 @@ describe "Array#sort" do
end
it "raises an error when a given block returns nil" do
- lambda { [1, 2].sort {} }.should raise_error(ArgumentError)
+ -> { [1, 2].sort {} }.should.raise(ArgumentError)
end
it "does not call #<=> on contained objects when invoked with a block" do
a = Array.new(25)
(0...25).each {|i| a[i] = ArraySpecs::UFOSceptic.new }
- a.sort { -1 }.should be_an_instance_of(Array)
+ a.sort { -1 }.should.instance_of?(Array)
end
it "does not call #<=> on elements when invoked with a block even if Array is large (Rubinius #412)" do
a = Array.new(1500)
(0...1500).each {|i| a[i] = ArraySpecs::UFOSceptic.new }
- a.sort { -1 }.should be_an_instance_of(Array)
+ a.sort { -1 }.should.instance_of?(Array)
end
it "completes when supplied a block that always returns the same result" do
a = [2, 3, 5, 1, 4]
- a.sort { 1 }.should be_an_instance_of(Array)
- a.sort { 0 }.should be_an_instance_of(Array)
- a.sort { -1 }.should be_an_instance_of(Array)
+ a.sort { 1 }.should.instance_of?(Array)
+ a.sort { 0 }.should.instance_of?(Array)
+ a.sort { -1 }.should.instance_of?(Array)
end
it "does not freezes self during being sorted" do
a = [1, 2, 3]
- a.sort { |x,y| a.frozen?.should == false; x <=> y }
+ a.sort { |x,y| a.should_not.frozen?; x <=> y }
end
it "returns the specified value when it would break in the given block" do
[1, 2, 3].sort{ break :a }.should == :a
end
- it "uses the sign of Bignum block results as the sort result" do
+ it "uses the sign of Integer block results as the sort result" do
a = [1, 2, 5, 10, 7, -4, 12]
begin
- class Bignum;
+ class Integer
alias old_spaceship <=>
def <=>(other)
raise
@@ -120,7 +122,7 @@ describe "Array#sort" do
end
a.sort {|n, m| (n - m) * (2 ** 200)}.should == [-4, 1, 2, 5, 7, 10, 12]
ensure
- class Bignum
+ class Integer
alias <=> old_spaceship
end
end
@@ -130,11 +132,11 @@ describe "Array#sort" do
a = [1, 2, 5, 10, 7, -4, 12]
a.sort { |n, m| n - m }.should == [-4, 1, 2, 5, 7, 10, 12]
a.sort { |n, m|
- ArraySpecs::ComparableWithFixnum.new(n-m)
+ ArraySpecs::ComparableWithInteger.new(n-m)
}.should == [-4, 1, 2, 5, 7, 10, 12]
- lambda {
+ -> {
a.sort { |n, m| (n - m).to_s }
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
end
it "sorts an array that has a value shifted off without a block" do
@@ -153,7 +155,7 @@ describe "Array#sort" do
it "raises an error if objects can't be compared" do
a=[ArraySpecs::Uncomparable.new, ArraySpecs::Uncomparable.new]
- lambda {a.sort}.should raise_error(ArgumentError)
+ -> {a.sort}.should.raise(ArgumentError)
end
# From a strange Rubinius bug
@@ -164,7 +166,7 @@ describe "Array#sort" do
it "does not return subclass instance on Array subclasses" do
ary = ArraySpecs::MyArray[1, 2, 3]
- ary.sort.should be_an_instance_of(Array)
+ ary.sort.should.instance_of?(Array)
end
end
@@ -182,13 +184,13 @@ describe "Array#sort!" do
it "returns self if the order of elements changed" do
a = [6, 7, 2, 3, 7]
- a.sort!.should equal(a)
+ a.sort!.should.equal?(a)
a.should == [2, 3, 6, 7, 7]
end
it "returns self even if makes no modification" do
a = [1, 2, 3, 4, 5]
- a.sort!.should equal(a)
+ a.sort!.should.equal?(a)
a.should == [1, 2, 3, 4, 5]
end
@@ -205,34 +207,34 @@ describe "Array#sort!" do
b = ArraySpecs::MockForCompared.new
c = ArraySpecs::MockForCompared.new
- ArraySpecs::MockForCompared.compared?.should == false
+ ArraySpecs::MockForCompared.should_not.compared?
[a, b, c].sort!.should == [c, b, a]
- ArraySpecs::MockForCompared.compared?.should == true
+ ArraySpecs::MockForCompared.should.compared?
end
it "does not call #<=> on contained objects when invoked with a block" do
a = Array.new(25)
(0...25).each {|i| a[i] = ArraySpecs::UFOSceptic.new }
- a.sort! { -1 }.should be_an_instance_of(Array)
+ a.sort! { -1 }.should.instance_of?(Array)
end
it "does not call #<=> on elements when invoked with a block even if Array is large (Rubinius #412)" do
a = Array.new(1500)
(0...1500).each {|i| a[i] = ArraySpecs::UFOSceptic.new }
- a.sort! { -1 }.should be_an_instance_of(Array)
+ a.sort! { -1 }.should.instance_of?(Array)
end
it "completes when supplied a block that always returns the same result" do
a = [2, 3, 5, 1, 4]
- a.sort!{ 1 }.should be_an_instance_of(Array)
- a.sort!{ 0 }.should be_an_instance_of(Array)
- a.sort!{ -1 }.should be_an_instance_of(Array)
+ a.sort!{ 1 }.should.instance_of?(Array)
+ a.sort!{ 0 }.should.instance_of?(Array)
+ a.sort!{ -1 }.should.instance_of?(Array)
end
- it "raises a RuntimeError on a frozen array" do
- lambda { ArraySpecs.frozen_array.sort! }.should raise_error(RuntimeError)
+ it "raises a FrozenError on a frozen array" do
+ -> { ArraySpecs.frozen_array.sort! }.should.raise(FrozenError)
end
it "returns the specified value when it would break in the given block" do
@@ -245,6 +247,6 @@ describe "Array#sort!" do
ary.sort!{|x,y| break if x==i; x<=>y}
ary
}
- partially_sorted.any?{|ary| ary != [1, 2, 3, 4, 5]}.should be_true
+ partially_sorted.any?{|ary| ary != [1, 2, 3, 4, 5]}.should == true
end
end
diff --git a/spec/ruby/core/array/sum_spec.rb b/spec/ruby/core/array/sum_spec.rb
index 6548655c35..cd4ba4c2d8 100644
--- a/spec/ruby/core/array/sum_spec.rb
+++ b/spec/ruby/core/array/sum_spec.rb
@@ -1,44 +1,88 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/iterable_and_tolerating_size_increasing'
-ruby_version_is '2.4' do
- describe "Array#sum" do
- it "returns the sum of elements" do
- [1, 2, 3].sum.should == 6
- end
+describe "Array#sum" do
+ it "returns the sum of elements" do
+ [1, 2, 3].sum.should == 6
+ end
+
+ it "applies a block to each element before adding if it's given" do
+ [1, 2, 3].sum { |i| i * 10 }.should == 60
+ end
+
+ it "doesn't apply the block init" do
+ [1, 2, 3].sum(1) { |i| i * 10 }.should == 61
+ end
+
+ # https://bugs.ruby-lang.org/issues/12217
+ # https://github.com/ruby/ruby/blob/master/doc/ChangeLog/ChangeLog-2.4.0#L6208-L6214
+ it "uses Kahan's compensated summation algorithm for precise sum of float numbers" do
+ floats = [2.7800000000000002, 5.0, 2.5, 4.44, 3.89, 3.89, 4.44, 7.78, 5.0, 2.7800000000000002, 5.0, 2.5]
+ naive_sum = floats.reduce { |sum, e| sum + e }
+ naive_sum.should == 50.00000000000001
+ floats.sum.should == 50.0
+ end
+
+ it "handles infinite values and NaN" do
+ [1.0, Float::INFINITY].sum.should == Float::INFINITY
+ [1.0, -Float::INFINITY].sum.should == -Float::INFINITY
+ [1.0, Float::NAN].sum.should.nan?
+
+ [Float::INFINITY, 1.0].sum.should == Float::INFINITY
+ [-Float::INFINITY, 1.0].sum.should == -Float::INFINITY
+ [Float::NAN, 1.0].sum.should.nan?
+
+ [Float::NAN, Float::INFINITY].sum.should.nan?
+ [Float::INFINITY, Float::NAN].sum.should.nan?
+
+ [Float::INFINITY, -Float::INFINITY].sum.should.nan?
+ [-Float::INFINITY, Float::INFINITY].sum.should.nan?
- it "applies a block to each element before adding if it's given" do
- [1, 2, 3].sum { |i| i * 10 }.should == 60
- end
+ [Float::INFINITY, Float::INFINITY].sum.should == Float::INFINITY
+ [-Float::INFINITY, -Float::INFINITY].sum.should == -Float::INFINITY
+ [Float::NAN, Float::NAN].sum.should.nan?
+ end
- it "returns init value if array is empty" do
- [].sum(-1).should == -1
- end
+ it "returns init value if array is empty" do
+ [].sum(-1).should == -1
+ end
- it "returns 0 if array is empty and init is omitted" do
- [].sum.should == 0
- end
+ it "returns 0 if array is empty and init is omitted" do
+ [].sum.should == 0
+ end
- it "adds init value to the sum of elemens" do
- [1, 2, 3].sum(10).should == 16
- end
+ it "adds init value to the sum of elements" do
+ [1, 2, 3].sum(10).should == 16
+ end
- it "can be used for non-numeric objects by providing init value" do
- ["a", "b", "c"].sum("").should == "abc"
- end
+ it "can be used for non-numeric objects by providing init value" do
+ ["a", "b", "c"].sum("").should == "abc"
+ end
- it 'raises TypeError if any element are not numeric' do
- lambda { ["a"].sum }.should raise_error(TypeError)
- end
+ it 'raises TypeError if any element are not numeric' do
+ -> { ["a"].sum }.should.raise(TypeError)
+ end
- it 'raises TypeError if any element cannot be added to init value' do
- lambda { [1].sum([]) }.should raise_error(TypeError)
- end
+ it 'raises TypeError if any element cannot be added to init value' do
+ -> { [1].sum([]) }.should.raise(TypeError)
+ end
+
+ it "calls + to sum the elements" do
+ a = mock("a")
+ b = mock("b")
+ a.should_receive(:+).with(b).and_return(42)
+ [b].sum(a).should == 42
+ end
- it "calls + to sum the elements" do
- a = mock("a")
- b = mock("b")
- a.should_receive(:+).with(b).and_return(42)
- [b].sum(a).should == 42
- end
+ it "calls + on the init value" do
+ a = mock("a")
+ b = mock("b")
+ a.should_receive(:+).with(42).and_return(b)
+ [42].sum(a).should == b
end
end
+
+describe "Array#sum" do
+ @value_to_return = -> _ { 1 }
+ it_behaves_like :array_iterable_and_tolerating_size_increasing, :sum
+end
diff --git a/spec/ruby/core/array/take_spec.rb b/spec/ruby/core/array/take_spec.rb
index 6ba87706cf..837c734b77 100644
--- a/spec/ruby/core/array/take_spec.rb
+++ b/spec/ruby/core/array/take_spec.rb
@@ -1,4 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Array#take" do
it "returns the first specified number of elements" do
@@ -22,6 +23,10 @@ describe "Array#take" do
end
it "raises an ArgumentError when the argument is negative" do
- lambda{ [1].take(-3) }.should raise_error(ArgumentError)
+ ->{ [1].take(-3) }.should.raise(ArgumentError)
+ end
+
+ it 'returns a Array instance for Array subclasses' do
+ ArraySpecs::MyArray[1, 2, 3, 4, 5].take(1).should.instance_of?(Array)
end
end
diff --git a/spec/ruby/core/array/take_while_spec.rb b/spec/ruby/core/array/take_while_spec.rb
index a97f304490..7811edab9e 100644
--- a/spec/ruby/core/array/take_while_spec.rb
+++ b/spec/ruby/core/array/take_while_spec.rb
@@ -1,4 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/iterable_and_tolerating_size_increasing'
describe "Array#take_while" do
it "returns all elements until the block returns false" do
@@ -12,4 +14,13 @@ describe "Array#take_while" do
it "returns all elements until the block returns false" do
[1, 2, false, 4].take_while{ |element| element }.should == [1, 2]
end
+
+ it 'returns a Array instance for Array subclasses' do
+ ArraySpecs::MyArray[1, 2, 3, 4, 5].take_while { |n| n < 4 }.should.instance_of?(Array)
+ end
+end
+
+describe "Array#take_while" do
+ @value_to_return = -> _ { true }
+ it_behaves_like :array_iterable_and_tolerating_size_increasing, :take_while
end
diff --git a/spec/ruby/core/array/to_a_spec.rb b/spec/ruby/core/array/to_a_spec.rb
index f3761a275e..078de1638a 100644
--- a/spec/ruby/core/array/to_a_spec.rb
+++ b/spec/ruby/core/array/to_a_spec.rb
@@ -1,16 +1,16 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Array#to_a" do
it "returns self" do
a = [1, 2, 3]
a.to_a.should == [1, 2, 3]
- a.should equal(a.to_a)
+ a.should.equal?(a.to_a)
end
it "does not return subclass instance on Array subclasses" do
e = ArraySpecs::MyArray.new(1, 2)
- e.to_a.should be_an_instance_of(Array)
+ e.to_a.should.instance_of?(Array)
e.to_a.should == [1, 2]
end
diff --git a/spec/ruby/core/array/to_ary_spec.rb b/spec/ruby/core/array/to_ary_spec.rb
index ab4dfdb5ed..dc5193158d 100644
--- a/spec/ruby/core/array/to_ary_spec.rb
+++ b/spec/ruby/core/array/to_ary_spec.rb
@@ -1,12 +1,12 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Array#to_ary" do
it "returns self" do
a = [1, 2, 3]
- a.should equal(a.to_ary)
+ a.should.equal?(a.to_ary)
a = ArraySpecs::MyArray[1, 2, 3]
- a.should equal(a.to_ary)
+ a.should.equal?(a.to_ary)
end
it "properly handles recursive arrays" do
diff --git a/spec/ruby/core/array/to_h_spec.rb b/spec/ruby/core/array/to_h_spec.rb
index 17783914aa..1d626763c2 100644
--- a/spec/ruby/core/array/to_h_spec.rb
+++ b/spec/ruby/core/array/to_h_spec.rb
@@ -1,5 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/iterable_and_tolerating_size_increasing'
describe "Array#to_h" do
it "converts empty array to empty hash" do
@@ -24,14 +25,67 @@ describe "Array#to_h" do
end
it "raises TypeError if an element is not an array" do
- lambda { [:x].to_h }.should raise_error(TypeError)
+ -> { [:x].to_h }.should.raise(TypeError)
end
it "raises ArgumentError if an element is not a [key, value] pair" do
- lambda { [[:x]].to_h }.should raise_error(ArgumentError)
+ -> { [[:x]].to_h }.should.raise(ArgumentError)
end
it "does not accept arguments" do
- lambda { [].to_h(:a, :b) }.should raise_error(ArgumentError)
+ -> { [].to_h(:a, :b) }.should.raise(ArgumentError)
end
+
+ it "produces a hash that returns nil for a missing element" do
+ [[:a, 1], [:b, 2]].to_h[:c].should == nil
+ end
+
+ context "with block" do
+ it "converts [key, value] pairs returned by the block to a Hash" do
+ [:a, :b].to_h { |k| [k, k.to_s] }.should == { a: 'a', b: 'b' }
+ end
+
+ it "passes to a block each element as a single argument" do
+ ScratchPad.record []
+ [[:a, 1], [:b, 2]].to_h { |*args| ScratchPad << args; [args[0], args[1]] }
+ ScratchPad.recorded.sort.should == [[[:a, 1]], [[:b, 2]]]
+ end
+
+ it "raises ArgumentError if block returns longer or shorter array" do
+ -> do
+ [:a, :b].to_h { |k| [k, k.to_s, 1] }
+ end.should.raise(ArgumentError, /wrong array length at 0/)
+
+ -> do
+ [:a, :b].to_h { |k| [k] }
+ end.should.raise(ArgumentError, /wrong array length at 0/)
+ end
+
+ it "raises TypeError if block returns something other than Array" do
+ -> do
+ [:a, :b].to_h { |k| "not-array" }
+ end.should.raise(TypeError, /wrong element type String at 0/)
+ end
+
+ it "coerces returned pair to Array with #to_ary" do
+ x = mock('x')
+ x.stub!(:to_ary).and_return([:b, 'b'])
+
+ [:a].to_h { |k| x }.should == { :b => 'b' }
+ end
+
+ it "does not coerce returned pair to Array with #to_a" do
+ x = mock('x')
+ x.stub!(:to_a).and_return([:b, 'b'])
+
+ -> do
+ [:a].to_h { |k| x }
+ end.should.raise(TypeError, /wrong element type MockObject at 0/)
+ end
+ end
+end
+
+describe "Array#to_h" do
+ @value_to_return = -> e { [e, e.to_s] }
+ it_behaves_like :array_iterable_and_tolerating_size_increasing, :to_h
end
diff --git a/spec/ruby/core/array/to_s_spec.rb b/spec/ruby/core/array/to_s_spec.rb
index 3a34d5ee0e..483e14f902 100644
--- a/spec/ruby/core/array/to_s_spec.rb
+++ b/spec/ruby/core/array/to_s_spec.rb
@@ -1,8 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/join', __FILE__)
-require File.expand_path('../shared/inspect', __FILE__)
+require_relative '../../spec_helper'
describe "Array#to_s" do
- it_behaves_like :array_inspect, :to_s
+ it "is an alias of Array#inspect" do
+ Array.instance_method(:to_s).should == Array.instance_method(:inspect)
+ end
end
diff --git a/spec/ruby/core/array/transpose_spec.rb b/spec/ruby/core/array/transpose_spec.rb
index a8edad7bab..d45e9c351c 100644
--- a/spec/ruby/core/array/transpose_spec.rb
+++ b/spec/ruby/core/array/transpose_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Array#transpose" do
it "assumes an array of arrays and returns the result of transposing rows and columns" do
@@ -32,7 +32,7 @@ describe "Array#transpose" do
end
it "raises a TypeError if the passed Argument does not respond to #to_ary" do
- lambda { [Object.new, [:a, :b]].transpose }.should raise_error(TypeError)
+ -> { [Object.new, [:a, :b]].transpose }.should.raise(TypeError)
end
it "does not call to_ary on array subclass elements" do
@@ -41,13 +41,13 @@ describe "Array#transpose" do
end
it "raises an IndexError if the arrays are not of the same length" do
- lambda { [[1, 2], [:a]].transpose }.should raise_error(IndexError)
+ -> { [[1, 2], [:a]].transpose }.should.raise(IndexError)
end
it "does not return subclass instance on Array subclasses" do
result = ArraySpecs::MyArray[ArraySpecs::MyArray[1, 2, 3], ArraySpecs::MyArray[4, 5, 6]].transpose
- result.should be_an_instance_of(Array)
- result[0].should be_an_instance_of(Array)
- result[1].should be_an_instance_of(Array)
+ result.should.instance_of?(Array)
+ result[0].should.instance_of?(Array)
+ result[1].should.instance_of?(Array)
end
end
diff --git a/spec/ruby/core/array/try_convert_spec.rb b/spec/ruby/core/array/try_convert_spec.rb
index 5d8f9f100f..3eaa0f4b7c 100644
--- a/spec/ruby/core/array/try_convert_spec.rb
+++ b/spec/ruby/core/array/try_convert_spec.rb
@@ -1,50 +1,50 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Array.try_convert" do
it "returns the argument if it's an Array" do
x = Array.new
- Array.try_convert(x).should equal(x)
+ Array.try_convert(x).should.equal?(x)
end
it "returns the argument if it's a kind of Array" do
x = ArraySpecs::MyArray[]
- Array.try_convert(x).should equal(x)
+ Array.try_convert(x).should.equal?(x)
end
it "returns nil when the argument does not respond to #to_ary" do
- Array.try_convert(Object.new).should be_nil
+ Array.try_convert(Object.new).should == nil
end
it "sends #to_ary to the argument and returns the result if it's nil" do
obj = mock("to_ary")
obj.should_receive(:to_ary).and_return(nil)
- Array.try_convert(obj).should be_nil
+ Array.try_convert(obj).should == nil
end
it "sends #to_ary to the argument and returns the result if it's an Array" do
x = Array.new
obj = mock("to_ary")
obj.should_receive(:to_ary).and_return(x)
- Array.try_convert(obj).should equal(x)
+ Array.try_convert(obj).should.equal?(x)
end
it "sends #to_ary to the argument and returns the result if it's a kind of Array" do
x = ArraySpecs::MyArray[]
obj = mock("to_ary")
obj.should_receive(:to_ary).and_return(x)
- Array.try_convert(obj).should equal(x)
+ Array.try_convert(obj).should.equal?(x)
end
it "sends #to_ary to the argument and raises TypeError if it's not a kind of Array" do
obj = mock("to_ary")
obj.should_receive(:to_ary).and_return(Object.new)
- lambda { Array.try_convert obj }.should raise_error(TypeError)
+ -> { Array.try_convert obj }.should raise_consistent_error(TypeError, "can't convert MockObject into Array (MockObject#to_ary gives Object)")
end
it "does not rescue exceptions raised by #to_ary" do
obj = mock("to_ary")
obj.should_receive(:to_ary).and_raise(RuntimeError)
- lambda { Array.try_convert obj }.should raise_error(RuntimeError)
+ -> { Array.try_convert obj }.should.raise(RuntimeError)
end
end
diff --git a/spec/ruby/core/array/union_spec.rb b/spec/ruby/core/array/union_spec.rb
index 58fe23448d..110894e83d 100644
--- a/spec/ruby/core/array/union_spec.rb
+++ b/spec/ruby/core/array/union_spec.rb
@@ -1,82 +1,25 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/union'
describe "Array#|" do
- it "returns an array of elements that appear in either array (union)" do
- ([] | []).should == []
- ([1, 2] | []).should == [1, 2]
- ([] | [1, 2]).should == [1, 2]
- ([ 1, 2, 3, 4 ] | [ 3, 4, 5 ]).should == [1, 2, 3, 4, 5]
- end
-
- it "creates an array with no duplicates" do
- ([ 1, 2, 3, 1, 4, 5 ] | [ 1, 3, 4, 5, 3, 6 ]).should == [1, 2, 3, 4, 5, 6]
- end
-
- it "creates an array with elements in order they are first encountered" do
- ([ 1, 2, 3, 1 ] | [ 1, 3, 4, 5 ]).should == [1, 2, 3, 4, 5]
- end
-
- it "properly handles recursive arrays" do
- empty = ArraySpecs.empty_recursive_array
- (empty | empty).should == empty
-
- array = ArraySpecs.recursive_array
- (array | []).should == [1, 'two', 3.0, array]
- ([] | array).should == [1, 'two', 3.0, array]
- (array | array).should == [1, 'two', 3.0, array]
- (array | empty).should == [1, 'two', 3.0, array, empty]
- end
-
- it "tries to convert the passed argument to an Array using #to_ary" do
- obj = mock('[1,2,3]')
- obj.should_receive(:to_ary).and_return([1, 2, 3])
- ([0] | obj).should == ([0] | [1, 2, 3])
- end
-
- # MRI follows hashing semantics here, so doesn't actually call eql?/hash for Fixnum/Symbol
- it "acts as if using an intermediate hash to collect values" do
- not_supported_on :opal do
- ([5.0, 4.0] | [5, 4]).should == [5.0, 4.0, 5, 4]
- end
-
- str = "x"
- ([str] | [str.dup]).should == [str]
-
- obj1 = mock('1')
- obj2 = mock('2')
- obj1.stub!(:hash).and_return(0)
- obj2.stub!(:hash).and_return(0)
- obj2.should_receive(:eql?).at_least(1).and_return(true)
-
- ([obj1] | [obj2]).should == [obj1]
- ([obj1, obj1, obj2, obj2] | [obj2]).should == [obj1]
+ it_behaves_like :array_binary_union, :|
+end
- obj1 = mock('3')
- obj2 = mock('4')
- obj1.stub!(:hash).and_return(0)
- obj2.stub!(:hash).and_return(0)
- obj2.should_receive(:eql?).at_least(1).and_return(false)
+describe "Array#union" do
+ it_behaves_like :array_binary_union, :union
- ([obj1] | [obj2]).should == [obj1, obj2]
- ([obj1, obj1, obj2, obj2] | [obj2]).should == [obj1, obj2]
+ it "returns unique elements when given no argument" do
+ x = [1, 2, 3, 2]
+ x.union.should == [1, 2, 3]
end
it "does not return subclass instances for Array subclasses" do
- (ArraySpecs::MyArray[1, 2, 3] | []).should be_an_instance_of(Array)
- (ArraySpecs::MyArray[1, 2, 3] | ArraySpecs::MyArray[1, 2, 3]).should be_an_instance_of(Array)
- ([] | ArraySpecs::MyArray[1, 2, 3]).should be_an_instance_of(Array)
- end
-
- it "does not call to_ary on array subclasses" do
- ([1, 2] | ArraySpecs::ToAryArray[5, 6]).should == [1, 2, 5, 6]
+ ArraySpecs::MyArray[1, 2, 3].union.should.instance_of?(Array)
end
- it "properly handles an identical item even when its #eql? isn't reflexive" do
- x = mock('x')
- x.stub!(:hash).and_return(42)
- x.stub!(:eql?).and_return(false) # Stubbed for clarity and latitude in implementation; not actually sent by MRI.
-
- ([x] | [x]).should == [x]
+ it "accepts multiple arguments" do
+ x = [1, 2, 3]
+ x.union(x, x, x, x, [3, 4], x).should == [1, 2, 3, 4]
end
end
diff --git a/spec/ruby/core/array/uniq_spec.rb b/spec/ruby/core/array/uniq_spec.rb
index 199b084376..0289bee7c2 100644
--- a/spec/ruby/core/array/uniq_spec.rb
+++ b/spec/ruby/core/array/uniq_spec.rb
@@ -1,5 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/iterable_and_tolerating_size_increasing'
describe "Array#uniq" do
it "returns an array with no duplicates" do
@@ -45,10 +46,6 @@ describe "Array#uniq" do
obj.should_receive(:hash).at_least(1).and_return(0)
def obj.eql?(o)
- # It's undefined whether the impl does a[0].eql?(a[1]) or
- # a[1].eql?(a[0]) so we taint both.
- taint
- o.taint
false
end
@@ -56,18 +53,12 @@ describe "Array#uniq" do
end
a.uniq.should == a
- a[0].tainted?.should == true
- a[1].tainted?.should == true
a = Array.new(2) do
obj = mock('0')
obj.should_receive(:hash).at_least(1).and_return(0)
def obj.eql?(o)
- # It's undefined whether the impl does a[0].eql?(a[1]) or
- # a[1].eql?(a[0]) so we taint both.
- taint
- o.taint
true
end
@@ -75,8 +66,6 @@ describe "Array#uniq" do
end
a.uniq.size.should == 1
- a[0].tainted?.should == true
- a[1].tainted?.should == true
end
it "compares elements based on the value returned from the block" do
@@ -96,8 +85,8 @@ describe "Array#uniq" do
[false, nil, 42].uniq { :bar }.should == [false]
end
- it "returns subclass instance on Array subclasses" do
- ArraySpecs::MyArray[1, 2, 3].uniq.should be_an_instance_of(ArraySpecs::MyArray)
+ it "returns Array instance on Array subclasses" do
+ ArraySpecs::MyArray[1, 2, 3].uniq.should.instance_of?(Array)
end
it "properly handles an identical item even when its #eql? isn't reflexive" do
@@ -135,6 +124,11 @@ describe "Array#uniq" do
end
end
+describe "Array#uniq" do
+ @value_to_return = -> e { e }
+ it_behaves_like :array_iterable_and_tolerating_size_increasing, :uniq
+end
+
describe "Array#uniq!" do
it "modifies the array in place" do
a = [ "a", "a", "b", "b", "c" ]
@@ -144,7 +138,7 @@ describe "Array#uniq!" do
it "returns self" do
a = [ "a", "a", "b", "b", "c" ]
- a.should equal(a.uniq!)
+ a.should.equal?(a.uniq!)
end
it "properly handles recursive arrays" do
@@ -188,20 +182,20 @@ describe "Array#uniq!" do
[ "a", "b", "c" ].uniq!.should == nil
end
- it "raises a RuntimeError on a frozen array when the array is modified" do
+ it "raises a FrozenError on a frozen array when the array is modified" do
dup_ary = [1, 1, 2]
dup_ary.freeze
- lambda { dup_ary.uniq! }.should raise_error(RuntimeError)
+ -> { dup_ary.uniq! }.should.raise(FrozenError)
end
# see [ruby-core:23666]
- it "raises a RuntimeError on a frozen array when the array would not be modified" do
- lambda { ArraySpecs.frozen_array.uniq!}.should raise_error(RuntimeError)
- lambda { ArraySpecs.empty_frozen_array.uniq!}.should raise_error(RuntimeError)
+ it "raises a FrozenError on a frozen array when the array would not be modified" do
+ -> { ArraySpecs.frozen_array.uniq!}.should.raise(FrozenError)
+ -> { ArraySpecs.empty_frozen_array.uniq!}.should.raise(FrozenError)
end
it "doesn't yield to the block on a frozen array" do
- lambda { ArraySpecs.frozen_array.uniq!{ raise RangeError, "shouldn't yield"}}.should raise_error(RuntimeError)
+ -> { ArraySpecs.frozen_array.uniq!{ raise RangeError, "shouldn't yield"}}.should.raise(FrozenError)
end
it "compares elements based on the value returned from the block" do
@@ -218,4 +212,32 @@ describe "Array#uniq!" do
a.uniq!
a.should == [x]
end
+
+ it "does not truncate the array is the block raises an exception" do
+ a = [1, 2, 3]
+ begin
+ a.send(@method) { raise StandardError, 'Oops' }
+ rescue
+ end
+
+ a.should == [1, 2, 3]
+ end
+
+ it "doesn't change array if error is raised" do
+ a = [1, 1, 2, 2, 3, 3, 4, 4]
+ begin
+ a.send(@method) do |e|
+ raise StandardError, 'Oops' if e == 3
+ e
+ end
+ rescue StandardError
+ end
+
+ a.should == [1, 1, 2, 2, 3, 3, 4, 4]
+ end
+end
+
+describe "Array#uniq!" do
+ @value_to_return = -> e { e }
+ it_behaves_like :array_iterable_and_tolerating_size_increasing, :uniq!
end
diff --git a/spec/ruby/core/array/unshift_spec.rb b/spec/ruby/core/array/unshift_spec.rb
index 9467a1a6df..c190db4d02 100644
--- a/spec/ruby/core/array/unshift_spec.rb
+++ b/spec/ruby/core/array/unshift_spec.rb
@@ -1,12 +1,12 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Array#unshift" do
it "prepends object to the original array" do
a = [1, 2, 3]
- a.unshift("a").should equal(a)
+ a.unshift("a").should.equal?(a)
a.should == ['a', 1, 2, 3]
- a.unshift().should equal(a)
+ a.unshift.should.equal?(a)
a.should == ['a', 1, 2, 3]
a.unshift(5, 4, 3)
a.should == [5, 4, 3, 'a', 1, 2, 3]
@@ -25,9 +25,13 @@ describe "Array#unshift" do
a.should == [3, 4]
end
+ it "returns self" do
+ a = [1, 2, 3]
+ a.unshift("a").should.equal?(a)
+ end
+
it "quietly ignores unshifting nothing" do
- [].unshift().should == []
- [].unshift(*[]).should == []
+ [].unshift.should == []
end
it "properly handles recursive arrays" do
@@ -39,12 +43,25 @@ describe "Array#unshift" do
array[0..5].should == [:new, 1, 'two', 3.0, array, array]
end
- it "raises a RuntimeError on a frozen array when the array is modified" do
- lambda { ArraySpecs.frozen_array.unshift(1) }.should raise_error(RuntimeError)
+ it "raises a FrozenError on a frozen array when the array is modified" do
+ -> { ArraySpecs.frozen_array.unshift(1) }.should.raise(FrozenError)
end
# see [ruby-core:23666]
- it "raises a RuntimeError on a frozen array when the array would not be modified" do
- lambda { ArraySpecs.frozen_array.unshift }.should raise_error(RuntimeError)
+ it "raises a FrozenError on a frozen array when the array would not be modified" do
+ -> { ArraySpecs.frozen_array.unshift }.should.raise(FrozenError)
+ end
+
+ # https://github.com/truffleruby/truffleruby/issues/2772
+ it "doesn't rely on Array#[]= so it can be overridden" do
+ subclass = Class.new(Array) do
+ def []=(*)
+ raise "[]= is called"
+ end
+ end
+
+ array = subclass.new
+ array.unshift(1)
+ array.should == [1]
end
end
diff --git a/spec/ruby/core/array/values_at_spec.rb b/spec/ruby/core/array/values_at_spec.rb
index f36356f0d3..e11e7e4451 100644
--- a/spec/ruby/core/array/values_at_spec.rb
+++ b/spec/ruby/core/array/values_at_spec.rb
@@ -1,6 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+# Should be synchronized with core/struct/values_at_spec.rb
describe "Array#values_at" do
it "returns an array of elements at the indexes when passed indexes" do
[1, 2, 3, 4, 5].values_at().should == []
@@ -58,6 +59,16 @@ describe "Array#values_at" do
end
it "does not return subclass instance on Array subclasses" do
- ArraySpecs::MyArray[1, 2, 3].values_at(0, 1..2, 1).should be_an_instance_of(Array)
+ ArraySpecs::MyArray[1, 2, 3].values_at(0, 1..2, 1).should.instance_of?(Array)
+ end
+
+ it "works when given endless ranges" do
+ [1, 2, 3, 4].values_at(eval("(1..)")).should == [2, 3, 4]
+ [1, 2, 3, 4].values_at(eval("(3...)")).should == [4]
+ end
+
+ it "works when given beginless ranges" do
+ [1, 2, 3, 4].values_at((..2)).should == [1, 2, 3]
+ [1, 2, 3, 4].values_at((...2)).should == [1, 2]
end
end
diff --git a/spec/ruby/core/array/zip_spec.rb b/spec/ruby/core/array/zip_spec.rb
index 7aac13536b..3ccdf143d6 100644
--- a/spec/ruby/core/array/zip_spec.rb
+++ b/spec/ruby/core/array/zip_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Array#zip" do
it "returns an array of arrays containing corresponding elements of each array" do
@@ -42,7 +42,7 @@ describe "Array#zip" do
[1, 2].zip(10.upto(Float::INFINITY)).should == [[1, 10], [2, 11]]
end
- it "fills nil when the given enumereator is shorter than self" do
+ it "fills nil when the given enumerator is shorter than self" do
obj = Object.new
def obj.each
yield 10
@@ -60,6 +60,12 @@ describe "Array#zip" do
end
it "does not return subclass instance on Array subclasses" do
- ArraySpecs::MyArray[1, 2, 3].zip(["a", "b"]).should be_an_instance_of(Array)
+ ArraySpecs::MyArray[1, 2, 3].zip(["a", "b"]).should.instance_of?(Array)
+ end
+
+ it "raises TypeError when some argument isn't Array and doesn't respond to #to_ary and #to_enum" do
+ -> { [1, 2, 3].zip(Object.new) }.should.raise(TypeError, "wrong argument type Object (must respond to :each)")
+ -> { [1, 2, 3].zip(1) }.should.raise(TypeError, "wrong argument type Integer (must respond to :each)")
+ -> { [1, 2, 3].zip(true) }.should.raise(TypeError, "wrong argument type TrueClass (must respond to :each)")
end
end
diff --git a/spec/ruby/core/basicobject/__id__spec.rb b/spec/ruby/core/basicobject/__id__spec.rb
index fba9ed3b34..6766db4e82 100644
--- a/spec/ruby/core/basicobject/__id__spec.rb
+++ b/spec/ruby/core/basicobject/__id__spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/kernel/object_id', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../../shared/kernel/object_id'
describe "BasicObject#__id__" do
it_behaves_like :object_id, :__id__, BasicObject
diff --git a/spec/ruby/core/basicobject/__send___spec.rb b/spec/ruby/core/basicobject/__send___spec.rb
index f25339fac7..2f814e448c 100644
--- a/spec/ruby/core/basicobject/__send___spec.rb
+++ b/spec/ruby/core/basicobject/__send___spec.rb
@@ -1,10 +1,10 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/basicobject/send', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../../shared/basicobject/send'
describe "BasicObject#__send__" do
it "is a public instance method" do
- BasicObject.should have_public_instance_method(:__send__)
+ BasicObject.public_instance_methods(false).should.include?(:__send__)
end
- it_behaves_like(:basicobject_send, :__send__)
+ it_behaves_like :basicobject_send, :__send__
end
diff --git a/spec/ruby/core/basicobject/basicobject_spec.rb b/spec/ruby/core/basicobject/basicobject_spec.rb
index f58c17a0c0..af28de0687 100644
--- a/spec/ruby/core/basicobject/basicobject_spec.rb
+++ b/spec/ruby/core/basicobject/basicobject_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/common', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/common'
describe "BasicObject" do
it "raises NoMethodError for nonexistent methods after #method_missing is removed" do
@@ -8,19 +8,23 @@ describe "BasicObject" do
end
it "raises NameError when referencing built-in constants" do
- lambda { class BasicObjectSpecs::BOSubclass; Kernel; end }.should raise_error(NameError)
+ -> { class BasicObjectSpecs::BOSubclass; Kernel; end }.should.raise(NameError)
end
it "does not define built-in constants (according to const_defined?)" do
- BasicObject.const_defined?(:Kernel).should be_false
+ BasicObject.const_defined?(:Kernel).should == false
end
it "does not define built-in constants (according to defined?)" do
- BasicObjectSpecs::BOSubclass.kernel_defined?.should be_nil
+ BasicObjectSpecs::BOSubclass.kernel_defined?.should == nil
+ end
+
+ it "is included in Object's list of constants" do
+ Object.constants(false).should.include?(:BasicObject)
end
it "includes itself in its list of constants" do
- BasicObject.constants.should include(:BasicObject)
+ BasicObject.constants(false).should.include?(:BasicObject)
end
end
@@ -30,11 +34,11 @@ describe "BasicObject metaclass" do
end
it "is an instance of Class" do
- @meta.should be_an_instance_of(Class)
+ @meta.should.instance_of?(Class)
end
it "has Class as superclass" do
- @meta.superclass.should equal(Class)
+ @meta.superclass.should.equal?(Class)
end
it "contains methods for the BasicObject class" do
@@ -53,11 +57,11 @@ describe "BasicObject instance metaclass" do
end
it "is an instance of Class" do
- @meta.should be_an_instance_of(Class)
+ @meta.should.instance_of?(Class)
end
it "has BasicObject as superclass" do
- @meta.superclass.should equal(BasicObject)
+ @meta.superclass.should.equal?(BasicObject)
end
it "contains methods defined for the BasicObject instance" do
@@ -81,7 +85,7 @@ describe "BasicObject subclass" do
describe "BasicObject references" do
it "can refer to BasicObject from within itself" do
- lambda { BasicObject::BasicObject }.should_not raise_error
+ -> { BasicObject::BasicObject }.should_not.raise
end
end
end
diff --git a/spec/ruby/core/basicobject/equal_spec.rb b/spec/ruby/core/basicobject/equal_spec.rb
index 8120df836f..f27f0d7aca 100644
--- a/spec/ruby/core/basicobject/equal_spec.rb
+++ b/spec/ruby/core/basicobject/equal_spec.rb
@@ -1,52 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/kernel/equal', __FILE__)
+require_relative '../../spec_helper'
describe "BasicObject#equal?" do
- it "is a public instance method" do
- BasicObject.should have_public_instance_method(:equal?)
- end
-
- it_behaves_like :object_equal, :equal?
-
- it "is unaffected by overriding __id__" do
- o1 = mock("object")
- o2 = mock("object")
- def o1.__id__; 10; end
- def o2.__id__; 10; end
- o1.equal?(o2).should be_false
- end
-
- it "is unaffected by overriding object_id" do
- o1 = mock("object")
- o1.stub!(:object_id).and_return(10)
- o2 = mock("object")
- o2.stub!(:object_id).and_return(10)
- o1.equal?(o2).should be_false
- end
-
- it "is unaffected by overriding ==" do
- # different objects, overriding == to return true
- o1 = mock("object")
- o1.stub!(:==).and_return(true)
- o2 = mock("object")
- o1.equal?(o2).should be_false
-
- # same objects, overriding == to return false
- o3 = mock("object")
- o3.stub!(:==).and_return(false)
- o3.equal?(o3).should be_true
- end
-
- it "is unaffected by overriding eql?" do
- # different objects, overriding eql? to return true
- o1 = mock("object")
- o1.stub!(:eql?).and_return(true)
- o2 = mock("object")
- o1.equal?(o2).should be_false
-
- # same objects, overriding eql? to return false
- o3 = mock("object")
- o3.stub!(:eql?).and_return(false)
- o3.equal?(o3).should be_true
+ it "is an alias of BasicObject#==" do
+ BasicObject.instance_method(:equal?).should == BasicObject.instance_method(:==)
end
end
diff --git a/spec/ruby/core/basicobject/equal_value_spec.rb b/spec/ruby/core/basicobject/equal_value_spec.rb
index 7d67634884..15755a44a2 100644
--- a/spec/ruby/core/basicobject/equal_value_spec.rb
+++ b/spec/ruby/core/basicobject/equal_value_spec.rb
@@ -1,10 +1,54 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/kernel/equal', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../../shared/kernel/equal'
describe "BasicObject#==" do
it "is a public instance method" do
- BasicObject.should have_public_instance_method(:==)
+ BasicObject.public_instance_methods(false).should.include?(:==)
end
it_behaves_like :object_equal, :==
+
+ it "is unaffected by overriding __id__" do
+ o1 = mock("object")
+ o2 = mock("object")
+ suppress_warning {
+ def o1.__id__; 10; end
+ def o2.__id__; 10; end
+ }
+ (o1 == o2).should == false
+ end
+
+ it "is unaffected by overriding object_id" do
+ o1 = mock("object")
+ o1.stub!(:object_id).and_return(10)
+ o2 = mock("object")
+ o2.stub!(:object_id).and_return(10)
+ (o1 == o2).should == false
+ end
+
+ it "is unaffected by overriding equal?" do
+ # different objects, overriding equal? to return true
+ o1 = mock("object")
+ o1.stub!(:equal?).and_return(true)
+ o2 = mock("object")
+ (o1 == o2).should == false
+
+ # same objects, overriding equal? to return false
+ o3 = mock("object")
+ o3.stub!(:equal?).and_return(false)
+ (o3 == o3).should == true
+ end
+
+ it "is unaffected by overriding eql?" do
+ # different objects, overriding eql? to return true
+ o1 = mock("object")
+ o1.stub!(:eql?).and_return(true)
+ o2 = mock("object")
+ (o1 == o2).should == false
+
+ # same objects, overriding eql? to return false
+ o3 = mock("object")
+ o3.stub!(:eql?).and_return(false)
+ (o3 == o3).should == true
+ end
end
diff --git a/spec/ruby/core/basicobject/fixtures/classes.rb b/spec/ruby/core/basicobject/fixtures/classes.rb
index d1785afe31..ed5a2dda17 100644
--- a/spec/ruby/core/basicobject/fixtures/classes.rb
+++ b/spec/ruby/core/basicobject/fixtures/classes.rb
@@ -15,8 +15,231 @@ module BasicObjectSpecs
include InstExec
end
- module InstEvalCVar
- instance_eval { @@count = 2 }
+ module InstEval
+ module CVar
+ module Get
+ class ReceiverScope
+ @@cvar = :value_defined_in_receiver_scope
+ end
+
+ class BlockDefinitionScope
+ @@cvar = :value_defined_in_block_definition_scope
+
+ def block
+ -> * { @@cvar }
+ end
+ end
+
+ class CallerScope
+ @@cvar = :value_defined_in_caller_scope
+
+ def get_class_variable_with_string(obj)
+ obj.instance_eval("@@cvar")
+ end
+
+ def get_class_variable_with_block(obj, block)
+ obj.instance_eval(&block)
+ end
+ end
+
+ class CallerWithoutCVarScope
+ def get_class_variable_with_string(obj)
+ obj.instance_eval("@@cvar")
+ end
+ end
+
+ ReceiverWithCVarDefinedInSingletonClass = Class.new.new.tap do |obj|
+ obj.singleton_class.class_variable_set(:@@cvar, :value_defined_in_receiver_singleton_class)
+ end
+ end
+
+ module Set
+ class ReceiverScope
+ end
+
+ class BlockDefinitionScope
+ def self.get_class_variable
+ @@cvar
+ end
+
+ def block_to_assign(value)
+ -> * { @@cvar = value }
+ end
+ end
+
+ class CallerScope
+ def self.get_class_variable
+ @@cvar
+ end
+
+ def set_class_variable_with_string(obj, value)
+ obj.instance_eval("@@cvar=#{value.inspect}")
+ end
+
+ def set_class_variable_with_block(obj, block)
+ obj.instance_eval(&block)
+ end
+ end
+ end
+ end
+ end
+
+ module InstEval
+ module Constants
+ module ConstantInReceiverSingletonClass
+ module ReceiverScope
+ FOO = :ReceiverScope
+
+ class ReceiverParent
+ FOO = :ReceiverParent
+ end
+
+ class Receiver < ReceiverParent
+ FOO = :Receiver
+
+ def initialize
+ self.singleton_class.const_set(:FOO, :singleton_class)
+ end
+ end
+ end
+
+ module CallerScope
+ FOO = :CallerScope
+
+ class CallerParent
+ FOO = :CallerParent
+ end
+
+ class Caller < CallerParent
+ FOO = :Caller
+
+ def get_constant_with_string(receiver)
+ receiver.instance_eval("FOO")
+ end
+ end
+ end
+ end
+
+ module ConstantInReceiverClass
+ module ReceiverScope
+ FOO = :ReceiverScope
+
+ class ReceiverParent
+ FOO = :ReceiverParent
+ end
+
+ class Receiver < ReceiverParent
+ FOO = :Receiver
+ end
+ end
+
+ module CallerScope
+ FOO = :CallerScope
+
+ class CallerParent
+ FOO = :CallerParent
+ end
+
+ class Caller < CallerParent
+ FOO = :Caller
+
+ def get_constant_with_string(receiver)
+ receiver.instance_eval("FOO")
+ end
+ end
+ end
+ end
+
+ module ConstantInCallerClass
+ module ReceiverScope
+ FOO = :ReceiverScope
+
+ class ReceiverParent
+ FOO = :ReceiverParent
+ end
+
+ class Receiver < ReceiverParent
+ # FOO is not declared in a receiver class
+ end
+ end
+
+ module CallerScope
+ FOO = :CallerScope
+
+ class CallerParent
+ FOO = :CallerParent
+ end
+
+ class Caller < CallerParent
+ FOO = :Caller
+
+ def get_constant_with_string(receiver)
+ receiver.instance_eval("FOO")
+ end
+ end
+ end
+ end
+
+ module ConstantInCallerOuterScopes
+ module ReceiverScope
+ FOO = :ReceiverScope
+
+ class ReceiverParent
+ FOO = :ReceiverParent
+ end
+
+ class Receiver < ReceiverParent
+ # FOO is not declared in a receiver class
+ end
+ end
+
+ module CallerScope
+ FOO = :CallerScope
+
+ class CallerParent
+ FOO = :CallerParent
+ end
+
+ class Caller < CallerParent
+ # FOO is not declared in a caller class
+
+ def get_constant_with_string(receiver)
+ receiver.instance_eval("FOO")
+ end
+ end
+ end
+ end
+
+ module ConstantInReceiverParentClass
+ module ReceiverScope
+ FOO = :ReceiverScope
+
+ class ReceiverParent
+ FOO = :ReceiverParent
+ end
+
+ class Receiver < ReceiverParent
+ # FOO is not declared in a receiver class
+ end
+ end
+
+ module CallerScope
+ # FOO is not declared in a caller outer scopes
+
+ class CallerParent
+ FOO = :CallerParent
+ end
+
+ class Caller < CallerParent
+ # FOO is not declared in a caller class
+
+ def get_constant_with_string(receiver)
+ receiver.instance_eval("FOO")
+ end
+ end
+ end
+ end
+ end
end
class InstEvalConst
@@ -26,7 +249,6 @@ module BasicObjectSpecs
module InstEvalOuter
module Inner
obj = InstEvalConst.new
- X_BY_STR = obj.instance_eval("INST_EVAL_CONST_X") rescue nil
X_BY_BLOCK = obj.instance_eval { INST_EVAL_CONST_X } rescue nil
end
end
diff --git a/spec/ruby/core/basicobject/initialize_spec.rb b/spec/ruby/core/basicobject/initialize_spec.rb
index 7e6680df61..09e86676b6 100644
--- a/spec/ruby/core/basicobject/initialize_spec.rb
+++ b/spec/ruby/core/basicobject/initialize_spec.rb
@@ -1,13 +1,13 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "BasicObject#initialize" do
it "is a private instance method" do
- BasicObject.should have_private_instance_method(:initialize)
+ BasicObject.private_instance_methods(false).should.include?(:initialize)
end
it "does not accept arguments" do
- lambda {
+ -> {
BasicObject.new("This", "makes it easier", "to call super", "from other constructors")
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
end
end
diff --git a/spec/ruby/core/basicobject/instance_eval_spec.rb b/spec/ruby/core/basicobject/instance_eval_spec.rb
index 3898e96b8b..124d179b5a 100644
--- a/spec/ruby/core/basicobject/instance_eval_spec.rb
+++ b/spec/ruby/core/basicobject/instance_eval_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "BasicObject#instance_eval" do
before :each do
@@ -7,25 +7,31 @@ describe "BasicObject#instance_eval" do
end
it "is a public instance method" do
- BasicObject.should have_public_instance_method(:instance_eval)
+ BasicObject.public_instance_methods(false).should.include?(:instance_eval)
end
it "sets self to the receiver in the context of the passed block" do
a = BasicObject.new
- a.instance_eval { self }.equal?(a).should be_true
+ a.instance_eval { self }.equal?(a).should == true
end
it "evaluates strings" do
a = BasicObject.new
- a.instance_eval('self').equal?(a).should be_true
+ a.instance_eval('self').equal?(a).should == true
end
- it "expects a block with no arguments" do
- lambda { "hola".instance_eval }.should raise_error(ArgumentError)
+ it "raises an ArgumentError when no arguments and no block are given" do
+ -> { "hola".instance_eval }.should.raise(ArgumentError, "wrong number of arguments (given 0, expected 1..3)")
end
- it "takes no arguments with a block" do
- lambda { "hola".instance_eval(4, 5) {|a,b| a + b } }.should raise_error(ArgumentError)
+ it "raises an ArgumentError when a block and normal arguments are given" do
+ -> { "hola".instance_eval(4, 5) {|a,b| a + b } }.should.raise(ArgumentError, "wrong number of arguments (given 2, expected 0)")
+ end
+
+ it "raises an ArgumentError when more than 3 arguments are given" do
+ -> {
+ "hola".instance_eval("1 + 1", "some file", 0, "bogus")
+ }.should.raise(ArgumentError, "wrong number of arguments (given 4, expected 1..3)")
end
it "yields the object to the block" do
@@ -45,7 +51,7 @@ describe "BasicObject#instance_eval" do
end
end
f.foo.should == 1
- lambda { Object.new.foo }.should raise_error(NoMethodError)
+ -> { Object.new.foo }.should.raise(NoMethodError)
end
it "preserves self in the original block when passed a block argument" do
@@ -65,9 +71,9 @@ describe "BasicObject#instance_eval" do
it "binds self to the receiver" do
s = "hola"
- (s == s.instance_eval { self }).should be_true
+ (s == s.instance_eval { self }).should == true
o = mock('o')
- (o == o.instance_eval("self")).should be_true
+ (o == o.instance_eval("self")).should == true
end
it "executes in the context of the receiver" do
@@ -78,11 +84,28 @@ describe "BasicObject#instance_eval" do
end
+ it "uses the caller location as default location" do
+ f = Object.new
+ f.instance_eval("[__FILE__, __LINE__]").should == ["(eval at #{__FILE__}:#{__LINE__})", 1]
+ end
+
it "has access to receiver's instance variables" do
BasicObjectSpecs::IVars.new.instance_eval { @secret }.should == 99
BasicObjectSpecs::IVars.new.instance_eval("@secret").should == 99
end
+ it "raises TypeError for frozen objects when tries to set receiver's instance variables" do
+ -> { nil.instance_eval { @foo = 42 } }.should.raise(FrozenError, "can't modify frozen NilClass: nil")
+ -> { true.instance_eval { @foo = 42 } }.should.raise(FrozenError, "can't modify frozen TrueClass: true")
+ -> { false.instance_eval { @foo = 42 } }.should.raise(FrozenError, "can't modify frozen FalseClass: false")
+ -> { 1.instance_eval { @foo = 42 } }.should.raise(FrozenError, "can't modify frozen Integer: 1")
+ -> { :symbol.instance_eval { @foo = 42 } }.should.raise(FrozenError, "can't modify frozen Symbol: :symbol")
+
+ obj = Object.new
+ obj.freeze
+ -> { obj.instance_eval { @foo = 42 } }.should.raise(FrozenError)
+ end
+
it "treats block-local variables as local to the block" do
prc = instance_eval <<-CODE
proc do |x, prc|
@@ -99,56 +122,118 @@ describe "BasicObject#instance_eval" do
prc.call(false, prc).should == 1
end
- it "sets class variables in the receiver" do
- BasicObjectSpecs::InstEvalCVar.class_variables.should include(:@@count)
- BasicObjectSpecs::InstEvalCVar.send(:class_variable_get, :@@count).should == 2
- end
-
it "makes the receiver metaclass the scoped class when used with a string" do
obj = Object.new
obj.instance_eval %{
class B; end
B
}
- obj.singleton_class.const_get(:B).should be_an_instance_of(Class)
+ obj.singleton_class.const_get(:B).should.instance_of?(Class)
end
- it "gets constants in the receiver if a string given" do
- BasicObjectSpecs::InstEvalOuter::Inner::X_BY_STR.should == 2
+ describe "constants lookup when a String given" do
+ it "looks in the receiver singleton class first" do
+ receiver = BasicObjectSpecs::InstEval::Constants::ConstantInReceiverSingletonClass::ReceiverScope::Receiver.new
+ caller = BasicObjectSpecs::InstEval::Constants::ConstantInReceiverSingletonClass::CallerScope::Caller.new
+
+ caller.get_constant_with_string(receiver).should == :singleton_class
+ end
+
+ it "looks in the receiver class next" do
+ receiver = BasicObjectSpecs::InstEval::Constants::ConstantInReceiverClass::ReceiverScope::Receiver.new
+ caller = BasicObjectSpecs::InstEval::Constants::ConstantInReceiverClass::CallerScope::Caller.new
+
+ caller.get_constant_with_string(receiver).should == :Receiver
+ end
+
+ it "looks in the caller class next" do
+ receiver = BasicObjectSpecs::InstEval::Constants::ConstantInCallerClass::ReceiverScope::Receiver.new
+ caller = BasicObjectSpecs::InstEval::Constants::ConstantInCallerClass::CallerScope::Caller.new
+
+ caller.get_constant_with_string(receiver).should == :Caller
+ end
+
+ it "looks in the caller outer scopes next" do
+ receiver = BasicObjectSpecs::InstEval::Constants::ConstantInCallerOuterScopes::ReceiverScope::Receiver.new
+ caller = BasicObjectSpecs::InstEval::Constants::ConstantInCallerOuterScopes::CallerScope::Caller.new
+
+ caller.get_constant_with_string(receiver).should == :CallerScope
+ end
+
+ it "looks in the receiver class hierarchy next" do
+ receiver = BasicObjectSpecs::InstEval::Constants::ConstantInReceiverParentClass::ReceiverScope::Receiver.new
+ caller = BasicObjectSpecs::InstEval::Constants::ConstantInReceiverParentClass::CallerScope::Caller.new
+
+ caller.get_constant_with_string(receiver).should == :ReceiverParent
+ end
end
it "doesn't get constants in the receiver if a block given" do
- BasicObjectSpecs::InstEvalOuter::Inner::X_BY_BLOCK.should be_nil
+ BasicObjectSpecs::InstEvalOuter::Inner::X_BY_BLOCK.should == nil
end
it "raises a TypeError when defining methods on an immediate" do
- lambda do
+ -> do
1.instance_eval { def foo; end }
- end.should raise_error(TypeError)
- lambda do
+ end.should.raise(TypeError)
+ -> do
:foo.instance_eval { def foo; end }
- end.should raise_error(TypeError)
+ end.should.raise(TypeError)
end
-quarantine! do # Not clean, leaves cvars lying around to break other specs
- it "scopes class var accesses in the caller when called on a Fixnum" do
- # Fixnum can take instance vars
- Fixnum.class_eval "@@__tmp_instance_eval_spec = 1"
- (defined? @@__tmp_instance_eval_spec).should be_nil
+ describe "class variables lookup" do
+ it "gets class variables in the caller class when called with a String" do
+ receiver = BasicObjectSpecs::InstEval::CVar::Get::ReceiverScope.new
+ caller = BasicObjectSpecs::InstEval::CVar::Get::CallerScope.new
+
+ caller.get_class_variable_with_string(receiver).should == :value_defined_in_caller_scope
+ end
+
+ it "gets class variables in the block definition scope when called with a block" do
+ receiver = BasicObjectSpecs::InstEval::CVar::Get::ReceiverScope.new
+ caller = BasicObjectSpecs::InstEval::CVar::Get::CallerScope.new
+ block = BasicObjectSpecs::InstEval::CVar::Get::BlockDefinitionScope.new.block
+
+ caller.get_class_variable_with_block(receiver, block).should == :value_defined_in_block_definition_scope
+ end
+
+ it "sets class variables in the caller class when called with a String" do
+ receiver = BasicObjectSpecs::InstEval::CVar::Set::ReceiverScope.new
+ caller = BasicObjectSpecs::InstEval::CVar::Set::CallerScope.new
+
+ caller.set_class_variable_with_string(receiver, 1)
+ BasicObjectSpecs::InstEval::CVar::Set::CallerScope.get_class_variable.should == 1
+ end
+
+ it "sets class variables in the block definition scope when called with a block" do
+ receiver = BasicObjectSpecs::InstEval::CVar::Set::ReceiverScope.new
+ caller = BasicObjectSpecs::InstEval::CVar::Set::CallerScope.new
+ block = BasicObjectSpecs::InstEval::CVar::Set::BlockDefinitionScope.new.block_to_assign(1)
+
+ caller.set_class_variable_with_block(receiver, block)
+ BasicObjectSpecs::InstEval::CVar::Set::BlockDefinitionScope.get_class_variable.should == 1
+ end
+
+ it "does not have access to class variables in the receiver class when called with a String" do
+ receiver = BasicObjectSpecs::InstEval::CVar::Get::ReceiverScope.new
+ caller = BasicObjectSpecs::InstEval::CVar::Get::CallerWithoutCVarScope.new
+ -> { caller.get_class_variable_with_string(receiver) }.should.raise(NameError, /uninitialized class variable @@cvar/)
+ end
- @@__tmp_instance_eval_spec = 2
- 1.instance_eval { @@__tmp_instance_eval_spec }.should == 2
- Fixnum.__send__(:remove_class_variable, :@@__tmp_instance_eval_spec)
+ it "does not have access to class variables in the receiver's singleton class when called with a String" do
+ receiver = BasicObjectSpecs::InstEval::CVar::Get::ReceiverWithCVarDefinedInSingletonClass
+ caller = BasicObjectSpecs::InstEval::CVar::Get::CallerWithoutCVarScope.new
+ -> { caller.get_class_variable_with_string(receiver) }.should.raise(NameError, /uninitialized class variable @@cvar/)
+ end
end
-end
it "raises a TypeError when defining methods on numerics" do
- lambda do
+ -> do
(1.0).instance_eval { def foo; end }
- end.should raise_error(TypeError)
- lambda do
+ end.should.raise(TypeError)
+ -> do
(1 << 64).instance_eval { def foo; end }
- end.should raise_error(TypeError)
+ end.should.raise(TypeError)
end
it "evaluates procs originating from methods" do
@@ -177,4 +262,66 @@ end
end
err.backtrace.first.split(":")[0..1].should == ["b_file", "-98"]
end
+
+ it "has access to the caller's local variables" do
+ x = nil
+
+ instance_eval "x = :value"
+
+ x.should == :value
+ end
+
+ it "converts string argument with #to_str method" do
+ source_code = Object.new
+ def source_code.to_str() "1" end
+
+ a = BasicObject.new
+ a.instance_eval(source_code).should == 1
+ end
+
+ it "raises ArgumentError if returned value is not String" do
+ source_code = Object.new
+ def source_code.to_str() :symbol end
+
+ a = BasicObject.new
+ -> { a.instance_eval(source_code) }.should raise_consistent_error(TypeError, /can't convert Object into String/)
+ end
+
+ it "converts filename argument with #to_str method" do
+ filename = Object.new
+ def filename.to_str() "file.rb" end
+
+ err = begin
+ Object.new.instance_eval("raise", filename)
+ rescue => e
+ e
+ end
+ err.backtrace.first.split(":")[0].should == "file.rb"
+ end
+
+ it "raises ArgumentError if returned value is not String" do
+ filename = Object.new
+ def filename.to_str() :symbol end
+
+ -> { Object.new.instance_eval("raise", filename) }.should raise_consistent_error(TypeError, /can't convert Object into String/)
+ end
+
+ it "converts lineno argument with #to_int method" do
+ lineno = Object.new
+ def lineno.to_int() 15 end
+
+ err = begin
+ Object.new.instance_eval("raise", "file.rb", lineno)
+ rescue => e
+ e
+ end
+ err.backtrace.first.split(":")[1].should == "15"
+ end
+
+ it "raises ArgumentError if returned value is not Integer" do
+ lineno = Object.new
+ def lineno.to_int() :symbol end
+
+ -> { Object.new.instance_eval("raise", "file.rb", lineno) }.should raise_consistent_error(TypeError, /can't convert Object into Integer/)
+ end
end
diff --git a/spec/ruby/core/basicobject/instance_exec_spec.rb b/spec/ruby/core/basicobject/instance_exec_spec.rb
index f41af6f64f..cfce9a65ad 100644
--- a/spec/ruby/core/basicobject/instance_exec_spec.rb
+++ b/spec/ruby/core/basicobject/instance_exec_spec.rb
@@ -1,23 +1,23 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "BasicObject#instance_exec" do
it "is a public instance method" do
- BasicObject.should have_public_instance_method(:instance_exec)
+ BasicObject.public_instance_methods(false).should.include?(:instance_exec)
end
it "sets self to the receiver in the context of the passed block" do
a = BasicObject.new
- a.instance_exec { self }.equal?(a).should be_true
+ a.instance_exec { self }.equal?(a).should == true
end
it "passes arguments to the block" do
a = BasicObject.new
- a.instance_exec(1) { |b| b }.should equal(1)
+ a.instance_exec(1) { |b| b }.should.equal?(1)
end
it "raises a LocalJumpError unless given a block" do
- lambda { "hola".instance_exec }.should raise_error(LocalJumpError)
+ -> { "hola".instance_exec }.should.raise(LocalJumpError)
end
it "has an arity of -1" do
@@ -25,17 +25,23 @@ describe "BasicObject#instance_exec" do
end
it "accepts arguments with a block" do
- lambda { "hola".instance_exec(4, 5) { |a,b| a + b } }.should_not raise_error
+ -> { "hola".instance_exec(4, 5) { |a,b| a + b } }.should_not.raise
end
it "doesn't pass self to the block as an argument" do
- "hola".instance_exec { |o| o }.should be_nil
+ "hola".instance_exec { |o| o }.should == nil
end
it "passes any arguments to the block" do
Object.new.instance_exec(1,2) {|one, two| one + two}.should == 3
end
+ describe "with optional argument" do
+ it "does not destructure a single array argument" do
+ Object.new.instance_exec([1, 2, 3]) { |a = 99| a }.should == [1, 2, 3]
+ end
+ end
+
it "only binds the exec to the receiver" do
f = Object.new
f.instance_exec do
@@ -44,7 +50,7 @@ describe "BasicObject#instance_exec" do
end
end
f.foo.should == 1
- lambda { Object.new.foo }.should raise_error(NoMethodError)
+ -> { Object.new.foo }.should.raise(NoMethodError)
end
# TODO: This should probably be replaced with a "should behave like" that uses
@@ -71,37 +77,37 @@ describe "BasicObject#instance_exec" do
end
it "sets class variables in the receiver" do
- BasicObjectSpecs::InstExec.class_variables.should include(:@@count)
+ BasicObjectSpecs::InstExec.class_variables.should.include?(:@@count)
BasicObjectSpecs::InstExec.send(:class_variable_get, :@@count).should == 2
end
it "raises a TypeError when defining methods on an immediate" do
- lambda do
+ -> do
1.instance_exec { def foo; end }
- end.should raise_error(TypeError)
- lambda do
+ end.should.raise(TypeError)
+ -> do
:foo.instance_exec { def foo; end }
- end.should raise_error(TypeError)
+ end.should.raise(TypeError)
end
-quarantine! do # Not clean, leaves cvars lying around to break other specs
- it "scopes class var accesses in the caller when called on a Fixnum" do
- # Fixnum can take instance vars
- Fixnum.class_eval "@@__tmp_instance_exec_spec = 1"
- (defined? @@__tmp_instance_exec_spec).should == nil
+ quarantine! do # Not clean, leaves cvars lying around to break other specs
+ it "scopes class var accesses in the caller when called on an Integer" do
+ # Integer can take instance vars
+ Integer.class_eval "@@__tmp_instance_exec_spec = 1"
+ (defined? @@__tmp_instance_exec_spec).should == nil
- @@__tmp_instance_exec_spec = 2
- 1.instance_exec { @@__tmp_instance_exec_spec }.should == 2
- Fixnum.__send__(:remove_class_variable, :@@__tmp_instance_exec_spec)
+ @@__tmp_instance_exec_spec = 2
+ 1.instance_exec { @@__tmp_instance_exec_spec }.should == 2
+ Integer.__send__(:remove_class_variable, :@@__tmp_instance_exec_spec)
+ end
end
-end
it "raises a TypeError when defining methods on numerics" do
- lambda do
+ -> do
(1.0).instance_exec { def foo; end }
- end.should raise_error(TypeError)
- lambda do
+ end.should.raise(TypeError)
+ -> do
(1 << 64).instance_exec { def foo; end }
- end.should raise_error(TypeError)
+ end.should.raise(TypeError)
end
end
diff --git a/spec/ruby/core/basicobject/method_missing_spec.rb b/spec/ruby/core/basicobject/method_missing_spec.rb
index eea45a8ddc..8785b41b21 100644
--- a/spec/ruby/core/basicobject/method_missing_spec.rb
+++ b/spec/ruby/core/basicobject/method_missing_spec.rb
@@ -1,8 +1,9 @@
-require File.expand_path('../../../shared/basicobject/method_missing', __FILE__)
+require_relative "../../spec_helper"
+require_relative '../../shared/basicobject/method_missing'
describe "BasicObject#method_missing" do
it "is a private method" do
- BasicObject.should have_private_instance_method(:method_missing)
+ BasicObject.private_instance_methods(false).should.include?(:method_missing)
end
end
diff --git a/spec/ruby/core/basicobject/not_equal_spec.rb b/spec/ruby/core/basicobject/not_equal_spec.rb
index 9177380154..29b14b0fff 100644
--- a/spec/ruby/core/basicobject/not_equal_spec.rb
+++ b/spec/ruby/core/basicobject/not_equal_spec.rb
@@ -1,25 +1,25 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "BasicObject#!=" do
it "is a public instance method" do
- BasicObject.should have_public_instance_method(:'!=')
+ BasicObject.public_instance_methods(false).should.include?(:'!=')
end
it "returns true if other is not identical to self" do
a = BasicObject.new
b = BasicObject.new
- (a != b).should be_true
+ (a != b).should == true
end
it "returns true if other is an Object" do
a = BasicObject.new
b = Object.new
- (a != b).should be_true
+ (a != b).should == true
end
it "returns false if other is identical to self" do
a = BasicObject.new
- (a != a).should be_false
+ (a != a).should == false
end
it "dispatches to #==" do
@@ -27,19 +27,19 @@ describe "BasicObject#!=" do
b = BasicObject.new
a.should_receive(:==).and_return(true)
- (a != b).should be_false
+ (a != b).should == false
end
describe "when invoked using Kernel#send" do
it "returns true if other is not identical to self" do
a = Object.new
b = Object.new
- a.send(:!=, b).should be_true
+ a.send(:!=, b).should == true
end
it "returns false if other is identical to self" do
a = Object.new
- a.send(:!=, a).should be_false
+ a.send(:!=, a).should == false
end
it "dispatches to #==" do
@@ -47,7 +47,7 @@ describe "BasicObject#!=" do
b = Object.new
a.should_receive(:==).and_return(true)
- a.send(:!=, b).should be_false
+ a.send(:!=, b).should == false
end
end
end
diff --git a/spec/ruby/core/basicobject/not_spec.rb b/spec/ruby/core/basicobject/not_spec.rb
index f02b31edb2..a6f58ae6f5 100644
--- a/spec/ruby/core/basicobject/not_spec.rb
+++ b/spec/ruby/core/basicobject/not_spec.rb
@@ -1,11 +1,11 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "BasicObject#!" do
it "is a public instance method" do
- BasicObject.should have_public_instance_method(:'!')
+ BasicObject.public_instance_methods(false).should.include?(:'!')
end
it "returns false" do
- (!BasicObject.new).should be_false
+ (!BasicObject.new).should == false
end
end
diff --git a/spec/ruby/core/basicobject/singleton_method_added_spec.rb b/spec/ruby/core/basicobject/singleton_method_added_spec.rb
index 7622798dee..f39b91768c 100644
--- a/spec/ruby/core/basicobject/singleton_method_added_spec.rb
+++ b/spec/ruby/core/basicobject/singleton_method_added_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/singleton_method', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/singleton_method'
describe "BasicObject#singleton_method_added" do
before :each do
@@ -7,7 +7,7 @@ describe "BasicObject#singleton_method_added" do
end
it "is a private method" do
- BasicObject.should have_private_instance_method(:singleton_method_added)
+ BasicObject.private_instance_methods(false).should.include?(:singleton_method_added)
end
it "is called when a singleton method is defined on an object" do
@@ -35,7 +35,7 @@ describe "BasicObject#singleton_method_added" do
end
end
- ScratchPad.recorded.should_not include(:new_instance_method)
+ ScratchPad.recorded.should_not.include?(:new_instance_method)
end
it "is called when a singleton method is defined on a module" do
@@ -83,4 +83,65 @@ describe "BasicObject#singleton_method_added" do
end
ScratchPad.recorded.should == [:singleton_method_added, :new_method_with_define_method]
end
+
+ describe "when singleton_method_added is undefined" do
+ it "raises NoMethodError for a metaclass" do
+ class BasicObjectSpecs::NoSingletonMethodAdded
+ class << self
+ undef_method :singleton_method_added
+ end
+
+ -> {
+ def self.foo
+ end
+ }.should.raise(NoMethodError, /undefined method [`']singleton_method_added' for/)
+ end
+ ensure
+ BasicObjectSpecs.send(:remove_const, :NoSingletonMethodAdded)
+ end
+
+ it "raises NoMethodError for a singleton instance" do
+ object = Object.new
+ class << object
+ undef_method :singleton_method_added
+
+ -> {
+ def foo
+ end
+ }.should.raise(NoMethodError, /undefined method [`']singleton_method_added' for #<Object:/)
+
+ -> {
+ define_method(:bar) {}
+ }.should.raise(NoMethodError, /undefined method [`']singleton_method_added' for #<Object:/)
+ end
+
+ -> {
+ object.define_singleton_method(:baz) {}
+ }.should.raise(NoMethodError, /undefined method [`']singleton_method_added' for #<Object:/)
+ end
+
+ it "calls #method_missing" do
+ ScratchPad.record []
+ object = Object.new
+ class << object
+ def method_missing(*args)
+ ScratchPad << args
+ end
+
+ undef_method :singleton_method_added
+
+ def foo
+ end
+
+ define_method(:bar) {}
+ end
+ object.define_singleton_method(:baz) {}
+
+ ScratchPad.recorded.should == [
+ [:singleton_method_added, :foo],
+ [:singleton_method_added, :bar],
+ [:singleton_method_added, :baz],
+ ]
+ end
+ end
end
diff --git a/spec/ruby/core/basicobject/singleton_method_removed_spec.rb b/spec/ruby/core/basicobject/singleton_method_removed_spec.rb
index 406f4a888e..1831e3c070 100644
--- a/spec/ruby/core/basicobject/singleton_method_removed_spec.rb
+++ b/spec/ruby/core/basicobject/singleton_method_removed_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "BasicObject#singleton_method_removed" do
before :each do
@@ -6,7 +6,7 @@ describe "BasicObject#singleton_method_removed" do
end
it "is a private method" do
- BasicObject.should have_private_instance_method(:singleton_method_removed)
+ BasicObject.private_instance_methods(false).should.include?(:singleton_method_removed)
end
it "is called when a method is removed on self" do
diff --git a/spec/ruby/core/basicobject/singleton_method_undefined_spec.rb b/spec/ruby/core/basicobject/singleton_method_undefined_spec.rb
index 4f33cc5dbe..cc47341878 100644
--- a/spec/ruby/core/basicobject/singleton_method_undefined_spec.rb
+++ b/spec/ruby/core/basicobject/singleton_method_undefined_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "BasicObject#singleton_method_undefined" do
before :each do
@@ -6,7 +6,7 @@ describe "BasicObject#singleton_method_undefined" do
end
it "is a private method" do
- BasicObject.should have_private_instance_method(:singleton_method_undefined)
+ BasicObject.private_instance_methods(false).should.include?(:singleton_method_undefined)
end
it "is called when a method is removed on self" do
diff --git a/spec/ruby/core/bignum/abs_spec.rb b/spec/ruby/core/bignum/abs_spec.rb
deleted file mode 100644
index b551dd95ad..0000000000
--- a/spec/ruby/core/bignum/abs_spec.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/abs', __FILE__)
-
-describe "Bignum#abs" do
- it_behaves_like(:bignum_abs, :abs)
-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 f69da833fd..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
- lambda { @bignum ** "10" }.should raise_error
- lambda { @bignum ** :symbol }.should raise_error
- 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..f1769ac6de 100644
--- a/spec/ruby/core/binding/clone_spec.rb
+++ b/spec/ruby/core/binding/clone_spec.rb
@@ -1,7 +1,13 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/clone', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/clone'
describe "Binding#clone" do
- it_behaves_like(:binding_clone, :clone)
+ it_behaves_like :binding_clone, :clone
+
+ it "preserves frozen status" do
+ bind = binding.freeze
+ bind.frozen?.should == true
+ bind.clone.frozen?.should == true
+ end
end
diff --git a/spec/ruby/core/binding/dup_spec.rb b/spec/ruby/core/binding/dup_spec.rb
index 7f242626d7..f5f0c72d5d 100644
--- a/spec/ruby/core/binding/dup_spec.rb
+++ b/spec/ruby/core/binding/dup_spec.rb
@@ -1,7 +1,30 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/clone', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/clone'
describe "Binding#dup" do
- it_behaves_like(:binding_clone, :dup)
+ it_behaves_like :binding_clone, :dup
+
+ it "resets frozen status" do
+ bind = binding.freeze
+ bind.frozen?.should == true
+ bind.dup.frozen?.should == false
+ end
+
+ it "retains original binding variables but the list is distinct" do
+ bind1 = binding
+ eval "a = 1", bind1
+
+ bind2 = bind1.dup
+ eval("a = 2", bind2)
+ eval("a", bind1).should == 2
+ eval("a", bind2).should == 2
+
+ eval("b = 2", bind2)
+ -> { eval("b", bind1) }.should.raise(NameError)
+ eval("b", bind2).should == 2
+
+ bind1.local_variables.sort.should == [:a, :bind1, :bind2]
+ bind2.local_variables.sort.should == [:a, :b, :bind1, :bind2]
+ end
end
diff --git a/spec/ruby/core/binding/eval_spec.rb b/spec/ruby/core/binding/eval_spec.rb
index 4864b9f61f..f1d8591320 100644
--- a/spec/ruby/core/binding/eval_spec.rb
+++ b/spec/ruby/core/binding/eval_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Binding#eval" do
it "behaves like Kernel.eval(..., self)" do
@@ -7,7 +7,7 @@ describe "Binding#eval" do
bind = obj.get_binding
bind.eval("@secret += square(3)").should == 10
- bind.eval("a").should be_true
+ bind.eval("a").should == true
bind.eval("class Inside; end")
bind.eval("Inside.name").should == "BindingSpecs::Demo::Inside"
@@ -23,15 +23,83 @@ describe "Binding#eval" do
bind2.local_variables.should == []
end
+ it "starts with line 1 if single argument is given" do
+ obj = BindingSpecs::Demo.new(1)
+ bind = obj.get_binding
+ bind.eval("__LINE__").should == 1
+ end
+
+ it "preserves __LINE__ across multiple calls to eval" do
+ obj = BindingSpecs::Demo.new(1)
+ bind = obj.get_binding
+ bind.eval("__LINE__").should == 1
+ bind.eval("__LINE__").should == 1
+ end
+
+ it "increments __LINE__ on each line of a multiline eval" do
+ obj = BindingSpecs::Demo.new(1)
+ bind = obj.get_binding
+ bind.eval("#foo\n__LINE__").should == 2
+ end
+
+ it "starts with line 1 if the Binding is created with #send" do
+ obj = BindingSpecs::Demo.new(1)
+ bind, line = obj.get_binding_with_send_and_line
+ bind.eval("__LINE__").should == 1
+ end
+
+ it "starts with a __LINE__ of 1 if a filename is passed" do
+ bind = BindingSpecs::Demo.new(1).get_binding
+ bind.eval("__LINE__", "(test)").should == 1
+ bind.eval("#foo\n__LINE__", "(test)").should == 2
+ end
+
+ it "starts with a __LINE__ from the third argument if passed" do
+ bind = BindingSpecs::Demo.new(1).get_binding
+ bind.eval("__LINE__", "(test)", 88).should == 88
+ bind.eval("#foo\n__LINE__", "(test)", 88).should == 89
+ end
+
+ it "uses 1 as __LINE__" do
+ obj = BindingSpecs::Demo.new(1)
+ bind = obj.get_binding
+ suppress_warning { bind.eval("__LINE__") }.should == 1
+ end
+
+ it "uses the __FILE__ that is passed in" do
+ bind = BindingSpecs::Demo.new(1).get_binding
+ bind.eval("__FILE__", "(test)").should == "(test)"
+ end
+
describe "with a file given" do
it "does not store the filename permanently" do
obj = BindingSpecs::Demo.new(1)
bind = obj.get_binding
bind.eval("__FILE__", "test.rb").should == "test.rb"
- bind.eval("__FILE__").should_not == "test.rb"
+ suppress_warning {bind.eval("__FILE__")}.should_not == "test.rb"
end
end
- it "needs to be reviewed for spec completeness"
+ it "with __method__ returns the method where the Binding was created" do
+ obj = BindingSpecs::Demo.new(1)
+ bind, meth = obj.get_binding_and_method
+ bind.eval("__method__").should == meth
+ end
+
+ it "with __method__ returns the method where the Binding was created, ignoring #send" do
+ obj = BindingSpecs::Demo.new(1)
+ bind, meth = obj.get_binding_with_send_and_method
+ bind.eval("__method__").should == meth
+ end
+
+ it "reflects refinements activated in the binding scope" do
+ bind = BindingSpecs::Refined.refined_binding
+
+ bind.eval("'bar'.foo").should == "foo"
+ end
+
+ it "uses the caller location as default filename" do
+ binding.eval("[__FILE__, __LINE__]").should == ["(eval at #{__FILE__}:#{__LINE__})", 1]
+ end
end
diff --git a/spec/ruby/core/binding/fixtures/classes.rb b/spec/ruby/core/binding/fixtures/classes.rb
index 05ca2479ba..b5f3ce9008 100644
--- a/spec/ruby/core/binding/fixtures/classes.rb
+++ b/spec/ruby/core/binding/fixtures/classes.rb
@@ -25,6 +25,18 @@ module BindingSpecs
__FILE__
end
+ def get_binding_with_send_and_line
+ [send(:binding), __LINE__]
+ end
+
+ def get_binding_and_method
+ [binding, :get_binding_and_method]
+ end
+
+ def get_binding_with_send_and_method
+ [send(:binding), :get_binding_with_send_and_method]
+ end
+
def get_empty_binding
binding
end
@@ -37,4 +49,18 @@ module BindingSpecs
end
end
end
+
+ module AddFooToString
+ refine(String) do
+ def foo
+ "foo"
+ end
+ end
+ end
+ class Refined
+ using AddFooToString
+ def self.refined_binding
+ binding
+ end
+ end
end
diff --git a/spec/ruby/core/binding/fixtures/location.rb b/spec/ruby/core/binding/fixtures/location.rb
new file mode 100644
index 0000000000..a78ae75731
--- /dev/null
+++ b/spec/ruby/core/binding/fixtures/location.rb
@@ -0,0 +1,6 @@
+module BindingSpecs
+ module LocationMethod
+ FILE_PATH = __FILE__
+ TEST_BINDING = binding
+ end
+end
diff --git a/spec/ruby/core/binding/local_variable_defined_spec.rb b/spec/ruby/core/binding/local_variable_defined_spec.rb
index 5fa79b19e2..2fc6504ee5 100644
--- a/spec/ruby/core/binding/local_variable_defined_spec.rb
+++ b/spec/ruby/core/binding/local_variable_defined_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe 'Binding#local_variable_defined?' do
it 'returns false when a variable is not defined' do
@@ -26,7 +26,7 @@ describe 'Binding#local_variable_defined?' do
it 'returns true when a local variable is defined in a parent scope' do
foo = 10
- lambda {
+ -> {
binding.local_variable_defined?(:foo)
}.call.should == true
end
diff --git a/spec/ruby/core/binding/local_variable_get_spec.rb b/spec/ruby/core/binding/local_variable_get_spec.rb
index e65d08130e..d97100deda 100644
--- a/spec/ruby/core/binding/local_variable_get_spec.rb
+++ b/spec/ruby/core/binding/local_variable_get_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Binding#local_variable_get" do
it "reads local variables captured in the binding" do
@@ -11,17 +11,17 @@ describe "Binding#local_variable_get" do
it "raises a NameError for missing variables" do
bind = BindingSpecs::Demo.new(1).get_empty_binding
- lambda {
+ -> {
bind.local_variable_get(:no_such_variable)
- }.should raise_error(NameError)
+ }.should.raise(NameError)
end
it "reads variables added later to the binding" do
bind = BindingSpecs::Demo.new(1).get_empty_binding
- lambda {
+ -> {
bind.local_variable_get(:a)
- }.should raise_error(NameError)
+ }.should.raise(NameError)
bind.local_variable_set(:a, 42)
@@ -31,7 +31,7 @@ describe "Binding#local_variable_get" do
it 'gets a local variable defined in a parent scope' do
number = 10
- lambda {
+ -> {
binding.local_variable_get(:number)
}.call.should == 10
end
@@ -45,12 +45,12 @@ describe "Binding#local_variable_get" do
it "raises a NameError on global access" do
bind = binding
- lambda { bind.local_variable_get(:$0) }.should raise_error(NameError)
+ -> { bind.local_variable_get(:$0) }.should.raise(NameError)
end
it "raises a NameError on special variable access" do
bind = binding
- lambda { bind.local_variable_get(:$~) }.should raise_error(NameError)
- lambda { bind.local_variable_get(:$_) }.should raise_error(NameError)
+ -> { bind.local_variable_get(:$~) }.should.raise(NameError)
+ -> { bind.local_variable_get(:$_) }.should.raise(NameError)
end
end
diff --git a/spec/ruby/core/binding/local_variable_set_spec.rb b/spec/ruby/core/binding/local_variable_set_spec.rb
index 067dcbd03e..3e4f407fc3 100644
--- a/spec/ruby/core/binding/local_variable_set_spec.rb
+++ b/spec/ruby/core/binding/local_variable_set_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Binding#local_variable_set" do
it "adds nonexistent variables to the binding's eval scope" do
@@ -38,7 +38,7 @@ describe "Binding#local_variable_set" do
bind = binding
bind.local_variable_set(:number, 10)
- lambda { number }.should raise_error(NameError)
+ -> { number }.should.raise(NameError)
end
it 'overwrites an existing local variable defined before a Binding' do
@@ -59,13 +59,13 @@ describe "Binding#local_variable_set" do
it "raises a NameError on global access" do
bind = binding
- lambda { bind.local_variable_set(:$0, "") }.should raise_error(NameError)
+ -> { bind.local_variable_set(:$0, "") }.should.raise(NameError)
end
it "raises a NameError on special variable access" do
bind = binding
- lambda { bind.local_variable_set(:$~, "") }.should raise_error(NameError)
- lambda { bind.local_variable_set(:$_, "") }.should raise_error(NameError)
+ -> { bind.local_variable_set(:$~, "") }.should.raise(NameError)
+ -> { bind.local_variable_set(:$_, "") }.should.raise(NameError)
end
end
diff --git a/spec/ruby/core/binding/local_variables_spec.rb b/spec/ruby/core/binding/local_variables_spec.rb
index bc6ea71f10..0f59681342 100644
--- a/spec/ruby/core/binding/local_variables_spec.rb
+++ b/spec/ruby/core/binding/local_variables_spec.rb
@@ -1,8 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Binding#local_variables" do
it "returns an Array" do
- binding.local_variables.should be_kind_of(Array)
+ binding.local_variables.should.is_a?(Array)
end
it "includes local variables in the current scope" do
diff --git a/spec/ruby/core/binding/location_spec.rb b/spec/ruby/core/binding/location_spec.rb
deleted file mode 100644
index b4a066038d..0000000000
--- a/spec/ruby/core/binding/location_spec.rb
+++ /dev/null
@@ -1,46 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-
-describe "Binding#eval" do
- it "inherits __LINE__ from the enclosing scope" do
- obj = BindingSpecs::Demo.new(1)
- bind = obj.get_binding
- bind.eval("__LINE__").should == obj.get_line_of_binding
- end
-
- it "preserves __LINE__ across multiple calls to eval" do
- obj = BindingSpecs::Demo.new(1)
- bind = obj.get_binding
- bind.eval("__LINE__").should == obj.get_line_of_binding
- bind.eval("__LINE__").should == obj.get_line_of_binding
- end
-
- it "increments __LINE__ on each line of a multiline eval" do
- obj = BindingSpecs::Demo.new(1)
- bind = obj.get_binding
- bind.eval("#foo\n__LINE__").should == obj.get_line_of_binding + 1
- end
-
- it "starts with a __LINE__ of 1 if a filename is passed" do
- bind = BindingSpecs::Demo.new(1).get_binding
- bind.eval("__LINE__", "(test)").should == 1
- bind.eval("#foo\n__LINE__", "(test)").should == 2
- end
-
- it "starts with a __LINE__ from the third argument if passed" do
- bind = BindingSpecs::Demo.new(1).get_binding
- bind.eval("__LINE__", "(test)", 88).should == 88
- bind.eval("#foo\n__LINE__", "(test)", 88).should == 89
- end
-
- it "inherits __FILE__ from the enclosing scope" do
- obj = BindingSpecs::Demo.new(1)
- bind = obj.get_binding
- bind.eval("__FILE__").should == obj.get_file_of_binding
- end
-
- it "uses the __FILE__ that is passed in" do
- bind = BindingSpecs::Demo.new(1).get_binding
- bind.eval("__FILE__", "(test)").should == "(test)"
- end
-end
diff --git a/spec/ruby/core/binding/receiver_spec.rb b/spec/ruby/core/binding/receiver_spec.rb
index 8784ab0e38..4bf5e7a7bd 100644
--- a/spec/ruby/core/binding/receiver_spec.rb
+++ b/spec/ruby/core/binding/receiver_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Binding#receiver" do
it "returns the object to which binding is bound" do
diff --git a/spec/ruby/core/binding/shared/clone.rb b/spec/ruby/core/binding/shared/clone.rb
index 0e934ac1b5..2d854fce96 100644
--- a/spec/ruby/core/binding/shared/clone.rb
+++ b/spec/ruby/core/binding/shared/clone.rb
@@ -31,4 +31,26 @@ describe :binding_clone, shared: true do
b2.local_variable_defined?(:x).should == false
end
end
+
+ ruby_version_is "3.4" do
+ it "copies instance variables" do
+ @b1.instance_variable_set(:@ivar, 1)
+ cl = @b1.send(@method)
+ cl.instance_variables.should == [:@ivar]
+ end
+
+ it "copies the finalizer" do
+ code = <<-'RUBY'
+ obj = binding
+
+ ObjectSpace.define_finalizer(obj, Proc.new { STDOUT.write "finalized\n" })
+
+ obj.clone
+
+ exit 0
+ RUBY
+
+ ruby_exe(code).lines.sort.should == ["finalized\n", "finalized\n"]
+ end
+ end
end
diff --git a/spec/ruby/core/binding/source_location_spec.rb b/spec/ruby/core/binding/source_location_spec.rb
new file mode 100644
index 0000000000..d1c8191ea8
--- /dev/null
+++ b/spec/ruby/core/binding/source_location_spec.rb
@@ -0,0 +1,14 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/location'
+
+describe "Binding#source_location" do
+ it "returns an [file, line] pair" do
+ b = BindingSpecs::LocationMethod::TEST_BINDING
+ b.source_location.should == [BindingSpecs::LocationMethod::FILE_PATH, 4]
+ end
+
+ it "works for eval with a given line" do
+ b = eval('binding', nil, "foo", 100)
+ b.source_location.should == ["foo", 100]
+ end
+end
diff --git a/spec/ruby/core/builtin_constants/builtin_constants_spec.rb b/spec/ruby/core/builtin_constants/builtin_constants_spec.rb
index 9019b127c2..67b3339aa6 100644
--- a/spec/ruby/core/builtin_constants/builtin_constants_spec.rb
+++ b/spec/ruby/core/builtin_constants/builtin_constants_spec.rb
@@ -1,49 +1,149 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "RUBY_VERSION" do
it "is a String" do
- RUBY_VERSION.should be_kind_of(String)
+ RUBY_VERSION.should.is_a?(String)
+ end
+
+ it "is frozen" do
+ RUBY_VERSION.should.frozen?
end
end
describe "RUBY_PATCHLEVEL" do
- it "is a Fixnum" do
- RUBY_PATCHLEVEL.should be_kind_of(Fixnum)
+ it "is an Integer" do
+ RUBY_PATCHLEVEL.should.is_a?(Integer)
end
end
describe "RUBY_COPYRIGHT" do
it "is a String" do
- RUBY_COPYRIGHT.should be_kind_of(String)
+ RUBY_COPYRIGHT.should.is_a?(String)
+ end
+
+ it "is frozen" do
+ RUBY_COPYRIGHT.should.frozen?
end
end
describe "RUBY_DESCRIPTION" do
it "is a String" do
- RUBY_DESCRIPTION.should be_kind_of(String)
+ RUBY_DESCRIPTION.should.is_a?(String)
+ end
+
+ it "is frozen" do
+ RUBY_DESCRIPTION.should.frozen?
end
end
describe "RUBY_ENGINE" do
it "is a String" do
- RUBY_ENGINE.should be_kind_of(String)
+ RUBY_ENGINE.should.is_a?(String)
+ end
+
+ it "is frozen" do
+ RUBY_ENGINE.should.frozen?
+ end
+end
+
+describe "RUBY_ENGINE_VERSION" do
+ it "is a String" do
+ RUBY_ENGINE_VERSION.should.is_a?(String)
+ end
+
+ it "is frozen" do
+ RUBY_ENGINE_VERSION.should.frozen?
end
end
describe "RUBY_PLATFORM" do
it "is a String" do
- RUBY_PLATFORM.should be_kind_of(String)
+ RUBY_PLATFORM.should.is_a?(String)
+ end
+
+ it "is frozen" do
+ RUBY_PLATFORM.should.frozen?
end
end
describe "RUBY_RELEASE_DATE" do
it "is a String" do
- RUBY_RELEASE_DATE.should be_kind_of(String)
+ RUBY_RELEASE_DATE.should.is_a?(String)
+ end
+
+ it "is frozen" do
+ RUBY_RELEASE_DATE.should.frozen?
end
end
describe "RUBY_REVISION" do
- it "is a Fixnum" do
- RUBY_REVISION.should be_kind_of(Fixnum)
+ it "is a String" do
+ RUBY_REVISION.should.is_a?(String)
+ end
+
+ it "is frozen" do
+ RUBY_REVISION.should.frozen?
+ end
+end
+
+ruby_version_is "4.0" do
+ describe "Ruby" do
+ it "is a Module" do
+ Ruby.should.instance_of?(Module)
+ end
+ end
+
+ describe "Ruby::VERSION" do
+ it "is equal to RUBY_VERSION" do
+ Ruby::VERSION.should.equal?(RUBY_VERSION)
+ end
+ end
+
+ describe "RUBY::PATCHLEVEL" do
+ it "is equal to RUBY_PATCHLEVEL" do
+ Ruby::PATCHLEVEL.should.equal?(RUBY_PATCHLEVEL)
+ end
+ end
+
+ describe "Ruby::COPYRIGHT" do
+ it "is equal to RUBY_COPYRIGHT" do
+ Ruby::COPYRIGHT.should.equal?(RUBY_COPYRIGHT)
+ end
+ end
+
+ describe "Ruby::DESCRIPTION" do
+ it "is equal to RUBY_DESCRIPTION" do
+ Ruby::DESCRIPTION.should.equal?(RUBY_DESCRIPTION)
+ end
+ end
+
+ describe "Ruby::ENGINE" do
+ it "is equal to RUBY_ENGINE" do
+ Ruby::ENGINE.should.equal?(RUBY_ENGINE)
+ end
+ end
+
+ describe "Ruby::ENGINE_VERSION" do
+ it "is equal to RUBY_ENGINE_VERSION" do
+ Ruby::ENGINE_VERSION.should.equal?(RUBY_ENGINE_VERSION)
+ end
+ end
+
+ describe "Ruby::PLATFORM" do
+ it "is equal to RUBY_PLATFORM" do
+ Ruby::PLATFORM.should.equal?(RUBY_PLATFORM)
+ end
+ end
+
+ describe "Ruby::RELEASE_DATE" do
+ it "is equal to RUBY_RELEASE_DATE" do
+ Ruby::RELEASE_DATE.should.equal?(RUBY_RELEASE_DATE)
+ end
+ end
+
+ describe "Ruby::REVISION" do
+ it "is equal to RUBY_REVISION" do
+ Ruby::REVISION.should.equal?(RUBY_REVISION)
+ end
end
end
diff --git a/spec/ruby/core/class/allocate_spec.rb b/spec/ruby/core/class/allocate_spec.rb
index 015db292eb..b8950a678e 100644
--- a/spec/ruby/core/class/allocate_spec.rb
+++ b/spec/ruby/core/class/allocate_spec.rb
@@ -1,9 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Class#allocate" do
it "returns an instance of self" do
klass = Class.new
- klass.allocate.should be_an_instance_of(klass)
+ klass.allocate.should.instance_of?(klass)
end
it "returns a fully-formed instance of Module" do
@@ -14,9 +14,9 @@ describe "Class#allocate" do
it "throws an exception when calling a method on a new instance" do
klass = Class.allocate
- lambda do
+ -> do
klass.new
- end.should raise_error(Exception)
+ end.should.raise(Exception)
end
it "does not call initialize on the new instance" do
@@ -30,12 +30,12 @@ describe "Class#allocate" do
end
end
- klass.allocate.initialized?.should == false
+ klass.allocate.should_not.initialized?
end
it "raises TypeError for #superclass" do
- lambda do
+ -> do
Class.allocate.superclass
- end.should raise_error(TypeError)
+ end.should.raise(TypeError)
end
end
diff --git a/spec/ruby/core/class/attached_object_spec.rb b/spec/ruby/core/class/attached_object_spec.rb
new file mode 100644
index 0000000000..b75e61ca07
--- /dev/null
+++ b/spec/ruby/core/class/attached_object_spec.rb
@@ -0,0 +1,29 @@
+require_relative '../../spec_helper'
+
+describe "Class#attached_object" do
+ it "returns the object that is attached to a singleton class" do
+ a = Class.new
+
+ a_obj = a.new
+ a_obj.singleton_class.attached_object.should == a_obj
+ end
+
+ it "returns the class object that is attached to a class's singleton class" do
+ a = Class.new
+ singleton_class = (class << a; self; end)
+
+ singleton_class.attached_object.should == a
+ end
+
+ it "raises TypeError if the class is not a singleton class" do
+ a = Class.new
+
+ -> { a.attached_object }.should.raise(TypeError, /is not a singleton class/)
+ end
+
+ it "raises TypeError for special singleton classes" do
+ -> { nil.singleton_class.attached_object }.should.raise(TypeError, /[`']NilClass' is not a singleton class/)
+ -> { true.singleton_class.attached_object }.should.raise(TypeError, /[`']TrueClass' is not a singleton class/)
+ -> { false.singleton_class.attached_object }.should.raise(TypeError, /[`']FalseClass' is not a singleton class/)
+ end
+end
diff --git a/spec/ruby/core/class/dup_spec.rb b/spec/ruby/core/class/dup_spec.rb
index 0548536bd6..17c0171ceb 100644
--- a/spec/ruby/core/class/dup_spec.rb
+++ b/spec/ruby/core/class/dup_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
# NOTE: This is actually implemented by Module#initialize_copy
describe "Class#dup" do
@@ -53,12 +53,17 @@ describe "Class#dup" do
it "sets the name from the class to nil if not assigned to a constant" do
copy = CoreClassSpecs::Record.dup
- copy.name.should be_nil
+ copy.name.should == nil
end
it "stores the new name if assigned to a constant" do
CoreClassSpecs::RecordCopy = CoreClassSpecs::Record.dup
CoreClassSpecs::RecordCopy.name.should == "CoreClassSpecs::RecordCopy"
+ ensure
+ CoreClassSpecs.send(:remove_const, :RecordCopy)
end
+ it "raises TypeError if called on BasicObject" do
+ -> { BasicObject.dup }.should.raise(TypeError, "can't copy the root class")
+ end
end
diff --git a/spec/ruby/core/class/inherited_spec.rb b/spec/ruby/core/class/inherited_spec.rb
index 356e46be7c..c9acc740a1 100644
--- a/spec/ruby/core/class/inherited_spec.rb
+++ b/spec/ruby/core/class/inherited_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Class.inherited" do
@@ -92,11 +92,27 @@ describe "Class.inherited" do
end
class << top; private :inherited; end
- lambda { Class.new(top) }.should_not raise_error
+ -> { Class.new(top) }.should_not.raise
class << top; protected :inherited; end
- lambda { Class.new(top) }.should_not raise_error
+ -> { Class.new(top) }.should_not.raise
end
-end
+ it "if the subclass is assigned to a constant, it is all set" do
+ ScratchPad.record []
+
+ parent = Class.new do
+ def self.inherited(subclass)
+ ScratchPad << defined?(self::C)
+ ScratchPad << const_defined?(:C)
+ ScratchPad << constants
+ ScratchPad << const_get(:C)
+ ScratchPad << subclass.name.match?(/\A#<Class:0x\w+>::C\z/)
+ end
+ end
+ class parent::C < parent; end
+
+ ScratchPad.recorded.should == ["constant", true, [:C], parent::C, true]
+ end
+end
diff --git a/spec/ruby/core/class/initialize_spec.rb b/spec/ruby/core/class/initialize_spec.rb
index d268596dfe..ab8f0a157e 100644
--- a/spec/ruby/core/class/initialize_spec.rb
+++ b/spec/ruby/core/class/initialize_spec.rb
@@ -1,25 +1,25 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Class#initialize" do
it "is private" do
- Class.should have_private_method(:initialize)
+ Class.private_methods(false).should.include?(:initialize)
end
it "raises a TypeError when called on already initialized classes" do
- lambda{
- Fixnum.send :initialize
- }.should raise_error(TypeError)
+ ->{
+ Integer.send :initialize
+ }.should.raise(TypeError)
- lambda{
+ ->{
Object.send :initialize
- }.should raise_error(TypeError)
+ }.should.raise(TypeError)
end
# See [redmine:2601]
it "raises a TypeError when called on BasicObject" do
- lambda{
+ ->{
BasicObject.send :initialize
- }.should raise_error(TypeError)
+ }.should.raise(TypeError)
end
describe "when given the Class" do
@@ -28,7 +28,7 @@ describe "Class#initialize" do
end
it "raises a TypeError" do
- lambda{@uninitialized.send(:initialize, Class)}.should raise_error(TypeError)
+ ->{@uninitialized.send(:initialize, Class)}.should.raise(TypeError)
end
end
end
diff --git a/spec/ruby/core/class/new_spec.rb b/spec/ruby/core/class/new_spec.rb
index 86323b1575..111e31252e 100644
--- a/spec/ruby/core/class/new_spec.rb
+++ b/spec/ruby/core/class/new_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Class.new with a block given" do
it "yields the new class as self in the block" do
@@ -7,7 +7,7 @@ describe "Class.new with a block given" do
klass = Class.new do
self_in_block = self
end
- self_in_block.should equal klass
+ self_in_block.should.equal? klass
end
it "uses the given block as the class' body" do
@@ -70,11 +70,11 @@ describe "Class.new" do
it "raises a TypeError if passed a metaclass" do
obj = mock("Class.new metaclass")
meta = obj.singleton_class
- lambda { Class.new meta }.should raise_error(TypeError)
+ -> { Class.new meta }.should.raise(TypeError)
end
it "creates a class without a name" do
- Class.new.name.should be_nil
+ Class.new.name.should == nil
end
it "creates a class that can be given a name by assigning it to a constant" do
@@ -83,6 +83,8 @@ describe "Class.new" do
a = Class.new
MyClass::NestedClass = a
MyClass::NestedClass.name.should == "MyClass::NestedClass"
+ ensure
+ Object.send(:remove_const, :MyClass)
end
it "sets the new class' superclass to the given class" do
@@ -95,12 +97,13 @@ describe "Class.new" do
end
it "raises a TypeError when given a non-Class" do
- error_msg = /superclass must be a Class/
- lambda { Class.new("") }.should raise_error(TypeError, error_msg)
- lambda { Class.new(1) }.should raise_error(TypeError, error_msg)
- lambda { Class.new(:symbol) }.should raise_error(TypeError, error_msg)
- lambda { Class.new(mock('o')) }.should raise_error(TypeError, error_msg)
- lambda { Class.new(Module.new) }.should raise_error(TypeError, error_msg)
+ error_msg = /superclass must be a.*Class/
+ -> { Class.new("") }.should.raise(TypeError, error_msg)
+ -> { Class.new(1) }.should.raise(TypeError, error_msg)
+ -> { Class.new(:symbol) }.should.raise(TypeError, error_msg)
+ -> { Class.new(mock('o')) }.should.raise(TypeError, error_msg)
+ -> { Class.new(Module.new) }.should.raise(TypeError, error_msg)
+ -> { Class.new(BasicObject.new) }.should.raise(TypeError, error_msg)
end
end
@@ -126,7 +129,7 @@ describe "Class#new" do
end
end
- klass.new.initialized?.should == true
+ klass.new.should.initialized?
klass.new(1, 2, 3).args.should == [1, 2, 3]
end
@@ -138,8 +141,8 @@ describe "Class#new" do
end
instance = klass.new
- instance.should be_kind_of klass
- instance.class.should equal klass
+ instance.should.is_a? klass
+ instance.class.should.equal? klass
end
it "passes the block to #initialize" do
diff --git a/spec/ruby/core/class/subclasses_spec.rb b/spec/ruby/core/class/subclasses_spec.rb
new file mode 100644
index 0000000000..c3d7b07e12
--- /dev/null
+++ b/spec/ruby/core/class/subclasses_spec.rb
@@ -0,0 +1,85 @@
+require_relative '../../spec_helper'
+require_relative '../module/fixtures/classes'
+
+describe "Class#subclasses" do
+ it "returns a list of classes directly inheriting from self" do
+ assert_subclasses(ModuleSpecs::Parent, [ModuleSpecs::Child, ModuleSpecs::Child2])
+ end
+
+ it "does not return included modules from the parent" do
+ parent = Class.new
+ child = Class.new(parent)
+ mod = Module.new
+ parent.include(mod)
+
+ assert_subclasses(parent, [child])
+ end
+
+ it "does not return included modules from the child" do
+ parent = Class.new
+ child = Class.new(parent)
+ mod = Module.new
+ parent.include(mod)
+
+ assert_subclasses(parent, [child])
+ end
+
+ it "does not return prepended modules from the parent" do
+ parent = Class.new
+ child = Class.new(parent)
+ mod = Module.new
+ parent.prepend(mod)
+
+ assert_subclasses(parent, [child])
+ end
+
+ it "does not return prepended modules from the child" do
+ parent = Class.new
+ child = Class.new(parent)
+ mod = Module.new
+ child.prepend(mod)
+
+ assert_subclasses(parent, [child])
+ end
+
+ it "does not return singleton classes" do
+ a = Class.new
+
+ a_obj = a.new
+ def a_obj.force_singleton_class
+ 42
+ end
+
+ a.subclasses.should_not.include?(a_obj.singleton_class)
+ end
+
+ it "has 1 entry per module or class" do
+ ModuleSpecs::Parent.subclasses.should == ModuleSpecs::Parent.subclasses.uniq
+ end
+
+ it "works when creating subclasses concurrently" do
+ t = 16
+ n = 1000
+ go = false
+ superclass = Class.new
+
+ threads = t.times.map do
+ Thread.new do
+ Thread.pass until go
+ n.times.map do
+ Class.new(superclass)
+ end
+ end
+ end
+
+ go = true
+ classes = threads.map(&:value)
+
+ superclass.subclasses.size.should == t * n
+ superclass.subclasses.each { |c| c.should.is_a?(Class) }
+ end
+
+ def assert_subclasses(mod,subclasses)
+ mod.subclasses.sort_by(&:inspect).should == subclasses.sort_by(&:inspect)
+ end
+end
diff --git a/spec/ruby/core/class/superclass_spec.rb b/spec/ruby/core/class/superclass_spec.rb
index 18b7ce5bde..87d9b20490 100644
--- a/spec/ruby/core/class/superclass_spec.rb
+++ b/spec/ruby/core/class/superclass_spec.rb
@@ -1,14 +1,14 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Class#superclass" do
it "returns the superclass of self" do
- BasicObject.superclass.should be_nil
+ BasicObject.superclass.should == nil
Object.superclass.should == BasicObject
Class.superclass.should == Module
Class.new.superclass.should == Object
Class.new(String).superclass.should == String
- Class.new(Fixnum).superclass.should == Fixnum
+ Class.new(Integer).superclass.should == Integer
end
# redmine:567
diff --git a/spec/ruby/core/class/to_s_spec.rb b/spec/ruby/core/class/to_s_spec.rb
deleted file mode 100644
index 693517f0da..0000000000
--- a/spec/ruby/core/class/to_s_spec.rb
+++ /dev/null
@@ -1,23 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-
-describe "Class#to_s" do
- it 'regular class returns same name as Module#to_s' do
- String.to_s.should == 'String'
- end
-
- describe 'singleton class' do
- it 'for modules includes module name' do
- CoreClassSpecs.singleton_class.to_s.should == '#<Class:CoreClassSpecs>'
- end
-
- it 'for classes includes class name' do
- CoreClassSpecs::Record.singleton_class.to_s.should == '#<Class:CoreClassSpecs::Record>'
- end
-
- it 'for objects includes class name and object ID' do
- obj = CoreClassSpecs::Record.new
- obj.singleton_class.to_s.should =~ /#<Class:#<CoreClassSpecs::Record:0x[0-9a-f]+>>/
- end
- end
-end
diff --git a/spec/ruby/core/comparable/between_spec.rb b/spec/ruby/core/comparable/between_spec.rb
index ebeadb7569..fd79bb9b4c 100644
--- a/spec/ruby/core/comparable/between_spec.rb
+++ b/spec/ruby/core/comparable/between_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Comparable#between?" do
it "returns true if self is greater than or equal to the first and less than or equal to the second argument" do
diff --git a/spec/ruby/core/comparable/clamp_spec.rb b/spec/ruby/core/comparable/clamp_spec.rb
index 75868258b5..eb1dc1ff98 100644
--- a/spec/ruby/core/comparable/clamp_spec.rb
+++ b/spec/ruby/core/comparable/clamp_spec.rb
@@ -1,50 +1,223 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
-ruby_version_is '2.4' do
- describe 'Comparable#clamp' do
- it 'raises an Argument error unless given 2 parameters' do
+describe 'Comparable#clamp' do
+ it 'raises an Argument error unless the 2 parameters are correctly ordered' do
+ one = ComparableSpecs::WithOnlyCompareDefined.new(1)
+ two = ComparableSpecs::WithOnlyCompareDefined.new(2)
+ c = ComparableSpecs::Weird.new(3)
+
+ -> { c.clamp(two, one) }.should.raise(ArgumentError)
+ one.should_receive(:<=>).any_number_of_times.and_return(nil)
+ -> { c.clamp(one, two) }.should.raise(ArgumentError)
+ end
+
+ it 'returns self if within the given parameters' do
+ one = ComparableSpecs::WithOnlyCompareDefined.new(1)
+ two = ComparableSpecs::WithOnlyCompareDefined.new(2)
+ three = ComparableSpecs::WithOnlyCompareDefined.new(3)
+ c = ComparableSpecs::Weird.new(2)
+
+ c.clamp(one, two).should.equal?(c)
+ c.clamp(two, two).should.equal?(c)
+ c.clamp(one, three).should.equal?(c)
+ c.clamp(two, three).should.equal?(c)
+ end
+
+ it 'returns the min parameter if less than it' do
+ one = ComparableSpecs::WithOnlyCompareDefined.new(1)
+ two = ComparableSpecs::WithOnlyCompareDefined.new(2)
+ c = ComparableSpecs::Weird.new(0)
+
+ c.clamp(one, two).should.equal?(one)
+ end
+
+ it 'returns the max parameter if greater than it' do
+ one = ComparableSpecs::WithOnlyCompareDefined.new(1)
+ two = ComparableSpecs::WithOnlyCompareDefined.new(2)
+ c = ComparableSpecs::Weird.new(3)
+
+ c.clamp(one, two).should.equal?(two)
+ end
+
+ context 'max is nil' do
+ it 'returns min if less than it' do
+ one = ComparableSpecs::WithOnlyCompareDefined.new(1)
c = ComparableSpecs::Weird.new(0)
- lambda { c.clamp(c) }.should raise_error(ArgumentError)
- lambda { c.clamp(c, c, c) }.should raise_error(ArgumentError)
+ c.clamp(one, nil).should.equal?(one)
end
- it 'raises an Argument error unless the 2 parameters are correctly ordered' do
+ it 'always returns self if greater than min' do
one = ComparableSpecs::WithOnlyCompareDefined.new(1)
- two = ComparableSpecs::WithOnlyCompareDefined.new(2)
- c = ComparableSpecs::Weird.new(3)
+ c = ComparableSpecs::Weird.new(2)
+ c.clamp(one, nil).should.equal?(c)
+ end
+ end
- lambda { c.clamp(two, one) }.should raise_error(ArgumentError)
- one.should_receive(:<=>).any_number_of_times.and_return(nil)
- lambda { c.clamp(one, two) }.should raise_error(ArgumentError)
+ context 'min is nil' do
+ it 'returns max if greater than it' do
+ one = ComparableSpecs::WithOnlyCompareDefined.new(1)
+ c = ComparableSpecs::Weird.new(2)
+ c.clamp(nil, one).should.equal?(one)
end
- it 'returns self if within the given parameters' do
+ it 'always returns self if less than max' do
+ one = ComparableSpecs::WithOnlyCompareDefined.new(1)
+ c = ComparableSpecs::Weird.new(0)
+ c.clamp(nil, one).should.equal?(c)
+ end
+ end
+
+ it 'always returns self when min is nil and max is nil' do
+ c = ComparableSpecs::Weird.new(1)
+ c.clamp(nil, nil).should.equal?(c)
+ end
+
+ it 'returns self if within the given range parameters' do
+ one = ComparableSpecs::WithOnlyCompareDefined.new(1)
+ two = ComparableSpecs::WithOnlyCompareDefined.new(2)
+ three = ComparableSpecs::WithOnlyCompareDefined.new(3)
+ c = ComparableSpecs::Weird.new(2)
+
+ c.clamp(one..two).should.equal?(c)
+ c.clamp(two..two).should.equal?(c)
+ c.clamp(one..three).should.equal?(c)
+ c.clamp(two..three).should.equal?(c)
+ end
+
+ it 'returns the minimum value of the range parameters if less than it' do
+ one = ComparableSpecs::WithOnlyCompareDefined.new(1)
+ two = ComparableSpecs::WithOnlyCompareDefined.new(2)
+ c = ComparableSpecs::Weird.new(0)
+
+ c.clamp(one..two).should.equal?(one)
+ end
+
+ it 'returns the maximum value of the range parameters if greater than it' do
+ one = ComparableSpecs::WithOnlyCompareDefined.new(1)
+ two = ComparableSpecs::WithOnlyCompareDefined.new(2)
+ c = ComparableSpecs::Weird.new(3)
+
+ c.clamp(one..two).should.equal?(two)
+ end
+
+ it 'raises an Argument error if the range parameter is exclusive' do
+ one = ComparableSpecs::WithOnlyCompareDefined.new(1)
+ two = ComparableSpecs::WithOnlyCompareDefined.new(2)
+ c = ComparableSpecs::Weird.new(3)
+
+ -> { c.clamp(one...two) }.should.raise(ArgumentError)
+ end
+
+ context 'with nil as the max argument' do
+ it 'returns min argument if less than it' do
+ one = ComparableSpecs::WithOnlyCompareDefined.new(1)
+ zero = ComparableSpecs::WithOnlyCompareDefined.new(0)
+ c = ComparableSpecs::Weird.new(0)
+
+ c.clamp(one, nil).should.equal?(one)
+ c.clamp(zero, nil).should.equal?(c)
+ end
+
+ it 'always returns self if greater than min argument' do
one = ComparableSpecs::WithOnlyCompareDefined.new(1)
two = ComparableSpecs::WithOnlyCompareDefined.new(2)
- three = ComparableSpecs::WithOnlyCompareDefined.new(3)
c = ComparableSpecs::Weird.new(2)
- c.clamp(one, two).should equal(c)
- c.clamp(two, two).should equal(c)
- c.clamp(one, three).should equal(c)
- c.clamp(two, three).should equal(c)
+ c.clamp(one, nil).should.equal?(c)
+ c.clamp(two, nil).should.equal?(c)
end
+ end
- it 'returns the min parameter if smaller than it' do
+ context 'with endless range' do
+ it 'returns minimum value of the range parameters if less than it' do
one = ComparableSpecs::WithOnlyCompareDefined.new(1)
- two = ComparableSpecs::WithOnlyCompareDefined.new(2)
+ zero = ComparableSpecs::WithOnlyCompareDefined.new(0)
c = ComparableSpecs::Weird.new(0)
- c.clamp(one, two).should equal(one)
+ c.clamp(one..).should.equal?(one)
+ c.clamp(zero..).should.equal?(c)
end
- it 'returns the max parameter if greater than it' do
+ it 'always returns self if greater than minimum value of the range parameters' do
one = ComparableSpecs::WithOnlyCompareDefined.new(1)
two = ComparableSpecs::WithOnlyCompareDefined.new(2)
- c = ComparableSpecs::Weird.new(3)
+ c = ComparableSpecs::Weird.new(2)
+
+ c.clamp(one..).should.equal?(c)
+ c.clamp(two..).should.equal?(c)
+ end
+
+ it 'works with exclusive range' do
+ one = ComparableSpecs::WithOnlyCompareDefined.new(1)
+ c = ComparableSpecs::Weird.new(2)
+
+ c.clamp(one...).should.equal?(c)
+ end
+ end
+
+ context 'with nil as the min argument' do
+ it 'returns max argument if greater than it' do
+ one = ComparableSpecs::WithOnlyCompareDefined.new(1)
+ c = ComparableSpecs::Weird.new(2)
+
+ c.clamp(nil, one).should.equal?(one)
+ end
+
+ it 'always returns self if less than max argument' do
+ one = ComparableSpecs::WithOnlyCompareDefined.new(1)
+ zero = ComparableSpecs::WithOnlyCompareDefined.new(0)
+ c = ComparableSpecs::Weird.new(0)
+
+ c.clamp(nil, one).should.equal?(c)
+ c.clamp(nil, zero).should.equal?(c)
+ end
+ end
+
+ context 'with beginless range' do
+ it 'returns maximum value of the range parameters if greater than it' do
+ one = ComparableSpecs::WithOnlyCompareDefined.new(1)
+ c = ComparableSpecs::Weird.new(2)
+
+ c.clamp(..one).should.equal?(one)
+ end
+
+ it 'always returns self if less than maximum value of the range parameters' do
+ one = ComparableSpecs::WithOnlyCompareDefined.new(1)
+ zero = ComparableSpecs::WithOnlyCompareDefined.new(0)
+ c = ComparableSpecs::Weird.new(0)
+
+ c.clamp(..one).should.equal?(c)
+ c.clamp(..zero).should.equal?(c)
+ end
+
+ it 'raises an Argument error if the range parameter is exclusive' do
+ one = ComparableSpecs::WithOnlyCompareDefined.new(1)
+ c = ComparableSpecs::Weird.new(0)
+
+ -> { c.clamp(...one) }.should.raise(ArgumentError)
+ end
+ end
+
+ context 'with nil as the min and the max argument' do
+ it 'always returns self' do
+ c = ComparableSpecs::Weird.new(1)
+
+ c.clamp(nil, nil).should.equal?(c)
+ end
+ end
+
+ context 'with beginless-and-endless range' do
+ it 'always returns self' do
+ c = ComparableSpecs::Weird.new(1)
+
+ c.clamp(nil..nil).should.equal?(c)
+ end
+
+ it 'works with exclusive range' do
+ c = ComparableSpecs::Weird.new(2)
- c.clamp(one, two).should equal(two)
+ c.clamp(nil...nil).should.equal?(c)
end
end
end
diff --git a/spec/ruby/core/comparable/equal_value_spec.rb b/spec/ruby/core/comparable/equal_value_spec.rb
index 2bc22771b4..3af40d1c7e 100644
--- a/spec/ruby/core/comparable/equal_value_spec.rb
+++ b/spec/ruby/core/comparable/equal_value_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Comparable#==" do
a = b = nil
@@ -39,7 +39,7 @@ describe "Comparable#==" do
end
it "returns false" do
- (a == b).should be_false
+ (a == b).should == false
end
end
@@ -48,16 +48,8 @@ describe "Comparable#==" do
a.should_receive(:<=>).once.and_return("abc")
end
- ruby_version_is ""..."2.3" do
- it "returns false" do
- (a == b).should be_false
- end
- end
-
- ruby_version_is "2.3" do
- it "raises an ArgumentError" do
- lambda { (a == b) }.should raise_error(ArgumentError)
- end
+ it "raises an ArgumentError" do
+ -> { (a == b) }.should.raise(ArgumentError)
end
end
@@ -67,17 +59,8 @@ describe "Comparable#==" do
a.should_receive(:<=>).once.and_raise(StandardError)
end
- ruby_version_is ""..."2.3" do
- # Behaviour confirmed by MRI test suite
- it "returns false" do
- (a == b).should be_false
- end
- end
-
- ruby_version_is "2.3" do
- it "lets it go through" do
- lambda { (a == b) }.should raise_error(StandardError)
- end
+ it "lets it go through" do
+ -> { (a == b) }.should.raise(StandardError)
end
end
@@ -87,22 +70,14 @@ describe "Comparable#==" do
a.should_receive(:<=>).once.and_raise(TypeError)
end
- ruby_version_is ""..."2.3" do
- it "returns false" do
- (a == b).should be_false
- end
- end
-
- ruby_version_is "2.3" do
- it "lets it go through" do
- lambda { (a == b) }.should raise_error(TypeError)
- end
+ it "lets it go through" do
+ -> { (a == b) }.should.raise(TypeError)
end
end
it "lets it go through if it is not a StandardError" do
a.should_receive(:<=>).once.and_raise(Exception)
- lambda { (a == b) }.should raise_error(Exception)
+ -> { (a == b) }.should.raise(Exception)
end
end
diff --git a/spec/ruby/core/comparable/fixtures/classes.rb b/spec/ruby/core/comparable/fixtures/classes.rb
index 4239a47d2f..2bdabbf014 100644
--- a/spec/ruby/core/comparable/fixtures/classes.rb
+++ b/spec/ruby/core/comparable/fixtures/classes.rb
@@ -7,6 +7,7 @@ module ComparableSpecs
end
def <=>(other)
+ return nil if other.nil?
self.value <=> other.value
end
end
diff --git a/spec/ruby/core/comparable/gt_spec.rb b/spec/ruby/core/comparable/gt_spec.rb
index c4739bcf2a..cebb5464ad 100644
--- a/spec/ruby/core/comparable/gt_spec.rb
+++ b/spec/ruby/core/comparable/gt_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Comparable#>" do
it "calls #<=> on self with other and returns true if #<=> returns any Integer greater than 0" do
@@ -38,6 +38,6 @@ describe "Comparable#>" do
b = ComparableSpecs::Weird.new(20)
a.should_receive(:<=>).any_number_of_times.and_return(nil)
- lambda { (a > b) }.should raise_error(ArgumentError)
+ -> { (a > b) }.should.raise(ArgumentError)
end
end
diff --git a/spec/ruby/core/comparable/gte_spec.rb b/spec/ruby/core/comparable/gte_spec.rb
index c9d8264ee6..16da81b3ea 100644
--- a/spec/ruby/core/comparable/gte_spec.rb
+++ b/spec/ruby/core/comparable/gte_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative 'fixtures/classes'
+require_relative '../../spec_helper'
describe "Comparable#>=" do
it "calls #<=> on self with other and returns true if #<=> returns 0 or any Integer greater than 0" do
@@ -42,6 +42,6 @@ describe "Comparable#>=" do
b = ComparableSpecs::Weird.new(20)
a.should_receive(:<=>).any_number_of_times.and_return(nil)
- lambda { (a >= b) }.should raise_error(ArgumentError)
+ -> { (a >= b) }.should.raise(ArgumentError)
end
end
diff --git a/spec/ruby/core/comparable/lt_spec.rb b/spec/ruby/core/comparable/lt_spec.rb
index e9e76360b9..175646d0d7 100644
--- a/spec/ruby/core/comparable/lt_spec.rb
+++ b/spec/ruby/core/comparable/lt_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Comparable#<" do
it "calls #<=> on self with other and returns true if #<=> returns any Integer less than 0" do
@@ -38,6 +38,12 @@ describe "Comparable#<" do
b = ComparableSpecs::Weird.new(20)
a.should_receive(:<=>).any_number_of_times.and_return(nil)
- lambda { (a < b) }.should raise_error(ArgumentError)
+ -> { (a < b) }.should.raise(ArgumentError)
+ end
+
+ it "raises an argument error with a message containing the value" do
+ -> { ("foo" < 7) }.should.raise(ArgumentError) { |e|
+ e.message.should.include? "String with 7 failed"
+ }
end
end
diff --git a/spec/ruby/core/comparable/lte_spec.rb b/spec/ruby/core/comparable/lte_spec.rb
index 96ed38ecd5..8cbbd5ebb4 100644
--- a/spec/ruby/core/comparable/lte_spec.rb
+++ b/spec/ruby/core/comparable/lte_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Comparable#<=" do
it "calls #<=> on self with other and returns true if #<=> returns 0 or any Integer less than 0" do
@@ -41,6 +41,6 @@ describe "Comparable#<=" do
b = ComparableSpecs::Weird.new(20)
a.should_receive(:<=>).any_number_of_times.and_return(nil)
- lambda { (a <= b) }.should raise_error(ArgumentError)
+ -> { (a <= b) }.should.raise(ArgumentError)
end
end
diff --git a/spec/ruby/core/complex/abs2_spec.rb b/spec/ruby/core/complex/abs2_spec.rb
index debfade075..3e5c5fd225 100644
--- a/spec/ruby/core/complex/abs2_spec.rb
+++ b/spec/ruby/core/complex/abs2_spec.rb
@@ -1,5 +1,9 @@
-require File.expand_path('../../../shared/complex/abs2', __FILE__)
+require_relative '../../spec_helper'
describe "Complex#abs2" do
- it_behaves_like(:complex_abs2, :abs2)
+ it "returns the sum of the squares of the real and imaginary parts" do
+ Complex(1, -2).abs2.should == 1 + 4
+ Complex(-0.1, 0.2).abs2.should be_close(0.01 + 0.04, TOLERANCE)
+ Complex(0).abs2.should == 0
+ end
end
diff --git a/spec/ruby/core/complex/abs_spec.rb b/spec/ruby/core/complex/abs_spec.rb
index a00d161ee9..ed5aebb11d 100644
--- a/spec/ruby/core/complex/abs_spec.rb
+++ b/spec/ruby/core/complex/abs_spec.rb
@@ -1,5 +1,12 @@
-require File.expand_path('../../../shared/complex/abs', __FILE__)
+require_relative '../../spec_helper'
describe "Complex#abs" do
- it_behaves_like(:complex_abs, :abs)
+ it "returns the modulus: |a + bi| = sqrt((a ^ 2) + (b ^ 2))" do
+ Complex(0, 0).abs.should == 0
+ Complex(3, 4).abs.should == 5 # well-known integer case
+ Complex(-3, 4).abs.should == 5
+ Complex(1, -1).abs.should be_close(Math.sqrt(2), TOLERANCE)
+ Complex(6.5, 0).abs.should be_close(6.5, TOLERANCE)
+ Complex(0, -7.2).abs.should be_close(7.2, TOLERANCE)
+ end
end
diff --git a/spec/ruby/core/complex/angle_spec.rb b/spec/ruby/core/complex/angle_spec.rb
index f0c46bfd03..7551214d2b 100644
--- a/spec/ruby/core/complex/angle_spec.rb
+++ b/spec/ruby/core/complex/angle_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-require File.expand_path('../../../shared/complex/arg', __FILE__)
+require_relative '../../spec_helper'
describe "Complex#angle" do
- it_behaves_like(:complex_arg, :angle)
+ it "is an alias of Complex#arg" do
+ Complex.instance_method(:angle).should == Complex.instance_method(:arg)
+ end
end
diff --git a/spec/ruby/core/complex/arg_spec.rb b/spec/ruby/core/complex/arg_spec.rb
index 48f8a94cf5..dd64102d77 100644
--- a/spec/ruby/core/complex/arg_spec.rb
+++ b/spec/ruby/core/complex/arg_spec.rb
@@ -1,7 +1,11 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-require File.expand_path('../../../shared/complex/arg', __FILE__)
+require_relative '../../spec_helper'
describe "Complex#arg" do
- it_behaves_like(:complex_arg, :arg)
+ it "returns the argument -- i.e., the angle from (1, 0) in the complex plane" do
+ two_pi = 2 * Math::PI
+ (Complex(1, 0).arg % two_pi).should be_close(0, TOLERANCE)
+ (Complex(0, 2).arg % two_pi).should be_close(Math::PI * 0.5, TOLERANCE)
+ (Complex(-100, 0).arg % two_pi).should be_close(Math::PI, TOLERANCE)
+ (Complex(0, -75.3).arg % two_pi).should be_close(Math::PI * 1.5, TOLERANCE)
+ end
end
diff --git a/spec/ruby/core/complex/coerce_spec.rb b/spec/ruby/core/complex/coerce_spec.rb
index 7c01170fde..d4ea85a713 100644
--- a/spec/ruby/core/complex/coerce_spec.rb
+++ b/spec/ruby/core/complex/coerce_spec.rb
@@ -1,5 +1,70 @@
-require File.expand_path('../../../shared/complex/coerce', __FILE__)
+require_relative '../../spec_helper'
describe "Complex#coerce" do
- it_behaves_like(:complex_coerce, :coerce)
+ before :each do
+ @one = Complex(1)
+ end
+
+ it "returns an array containing other and self as Complex when other is an Integer" do
+ result = @one.coerce(2)
+ result.should == [2, 1]
+ result.first.should.is_a?(Complex)
+ result.last.should.is_a?(Complex)
+ end
+
+ it "returns an array containing other and self as Complex when other is a Float" do
+ result = @one.coerce(20.5)
+ result.should == [20.5, 1]
+ result.first.should.is_a?(Complex)
+ result.last.should.is_a?(Complex)
+ end
+
+ it "returns an array containing other and self as Complex when other is a Bignum" do
+ result = @one.coerce(4294967296)
+ result.should == [4294967296, 1]
+ result.first.should.is_a?(Complex)
+ result.last.should.is_a?(Complex)
+ end
+
+ it "returns an array containing other and self as Complex when other is a Rational" do
+ result = @one.coerce(Rational(5,6))
+ result.should == [Rational(5,6), 1]
+ result.first.should.is_a?(Complex)
+ result.last.should.is_a?(Complex)
+ end
+
+ it "returns an array containing other and self when other is a Complex" do
+ other = Complex(2)
+ result = @one.coerce(other)
+ result.should == [other, @one]
+ result.first.should.equal?(other)
+ result.last.should.equal?(@one)
+ end
+
+ it "returns an array containing other as Complex and self when other is a Numeric which responds to #real? with true" do
+ other = mock_numeric('other')
+ other.should_receive(:real?).any_number_of_times.and_return(true)
+ result = @one.coerce(other)
+ result.should == [other, @one]
+ result.first.should.eql?(Complex(other))
+ result.last.should.equal?(@one)
+ end
+
+ it "raises TypeError when other is a Numeric which responds to #real? with false" do
+ other = mock_numeric('other')
+ other.should_receive(:real?).any_number_of_times.and_return(false)
+ -> { @one.coerce(other) }.should.raise(TypeError)
+ end
+
+ it "raises a TypeError when other is a String" do
+ -> { @one.coerce("20") }.should.raise(TypeError)
+ end
+
+ it "raises a TypeError when other is nil" do
+ -> { @one.coerce(nil) }.should.raise(TypeError)
+ end
+
+ it "raises a TypeError when other is false" do
+ -> { @one.coerce(false) }.should.raise(TypeError)
+ end
end
diff --git a/spec/ruby/core/complex/comparison_spec.rb b/spec/ruby/core/complex/comparison_spec.rb
new file mode 100644
index 0000000000..3115f4e205
--- /dev/null
+++ b/spec/ruby/core/complex/comparison_spec.rb
@@ -0,0 +1,25 @@
+require_relative '../../spec_helper'
+
+describe "Complex#<=>" do
+ it "returns nil if either self or argument has imaginary part" do
+ (Complex(5, 1) <=> Complex(2)).should == nil
+ (Complex(1) <=> Complex(2, 1)).should == nil
+ (5 <=> Complex(2, 1)).should == nil
+ end
+
+ it "returns nil if argument is not numeric" do
+ (Complex(5, 1) <=> "cmp").should == nil
+ (Complex(1) <=> "cmp").should == nil
+ (Complex(1) <=> Object.new).should == nil
+ end
+
+ it "returns 0, 1, or -1 if self and argument do not have imaginary part" do
+ (Complex(5) <=> Complex(2)).should == 1
+ (Complex(2) <=> Complex(3)).should == -1
+ (Complex(2) <=> Complex(2)).should == 0
+
+ (Complex(5) <=> 2).should == 1
+ (Complex(2) <=> 3).should == -1
+ (Complex(2) <=> 2).should == 0
+ end
+end
diff --git a/spec/ruby/core/complex/conj_spec.rb b/spec/ruby/core/complex/conj_spec.rb
index ad2c885b3b..063c85faec 100644
--- a/spec/ruby/core/complex/conj_spec.rb
+++ b/spec/ruby/core/complex/conj_spec.rb
@@ -1,6 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/complex/conjugate', __FILE__)
+require_relative '../../spec_helper'
describe "Complex#conj" do
- it_behaves_like(:complex_conjugate, :conj)
+ it "is an alias of Complex#conjugate" do
+ Complex.instance_method(:conj).should == Complex.instance_method(:conjugate)
+ end
end
diff --git a/spec/ruby/core/complex/conjugate_spec.rb b/spec/ruby/core/complex/conjugate_spec.rb
index 7fc2ddb430..256fe4b3be 100644
--- a/spec/ruby/core/complex/conjugate_spec.rb
+++ b/spec/ruby/core/complex/conjugate_spec.rb
@@ -1,6 +1,10 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/complex/conjugate', __FILE__)
+require_relative '../../spec_helper'
describe "Complex#conjugate" do
- it_behaves_like(:complex_conjugate, :conjugate)
+ it "returns the complex conjugate: conj a + bi = a - bi" do
+ Complex(3, 5).conjugate.should == Complex(3, -5)
+ Complex(3, -5).conjugate.should == Complex(3, 5)
+ Complex(-3.0, 5.2).conjugate.should be_close(Complex(-3.0, -5.2), TOLERANCE)
+ Complex(3.0, -5.2).conjugate.should be_close(Complex(3.0, 5.2), TOLERANCE)
+ end
end
diff --git a/spec/ruby/core/complex/constants_spec.rb b/spec/ruby/core/complex/constants_spec.rb
index a8fcebbd31..200e97731a 100644
--- a/spec/ruby/core/complex/constants_spec.rb
+++ b/spec/ruby/core/complex/constants_spec.rb
@@ -1,5 +1,7 @@
-require File.expand_path('../../../shared/complex/constants', __FILE__)
+require_relative '../../spec_helper'
describe "Complex::I" do
- it_behaves_like :complex_I, :I
+ it "is Complex(0, 1)" do
+ Complex::I.should.eql?(Complex(0, 1))
+ end
end
diff --git a/spec/ruby/core/complex/denominator_spec.rb b/spec/ruby/core/complex/denominator_spec.rb
index 2568967968..c1a2003820 100644
--- a/spec/ruby/core/complex/denominator_spec.rb
+++ b/spec/ruby/core/complex/denominator_spec.rb
@@ -1,5 +1,13 @@
-require File.expand_path('../../../shared/complex/denominator', __FILE__)
+require_relative '../../spec_helper'
describe "Complex#denominator" do
- it_behaves_like(:complex_denominator, :denominator)
+ it "returns the least common multiple denominator of the real and imaginary parts" do
+ Complex(3, 4).denominator.should == 1
+ Complex(3, bignum_value).denominator.should == 1
+
+ Complex(3, Rational(3,4)).denominator.should == 4
+
+ Complex(Rational(4,8), Rational(3,4)).denominator.should == 4
+ Complex(Rational(3,8), Rational(3,4)).denominator.should == 8
+ end
end
diff --git a/spec/ruby/core/complex/divide_spec.rb b/spec/ruby/core/complex/divide_spec.rb
index 71614c76e1..d5b4aa3885 100644
--- a/spec/ruby/core/complex/divide_spec.rb
+++ b/spec/ruby/core/complex/divide_spec.rb
@@ -1,5 +1,84 @@
-require File.expand_path('../../../shared/complex/divide', __FILE__)
+require_relative '../../spec_helper'
describe "Complex#/" do
- it_behaves_like :complex_divide, :/
+ describe "with Complex" do
+ it "divides according to the usual rule for complex numbers" do
+ a = Complex((1 * 10) - (2 * 20), (1 * 20) + (2 * 10))
+ b = Complex(1, 2)
+ (a / b).should == Complex(10, 20)
+
+ c = Complex((1.5 * 100.2) - (2.1 * -30.3), (1.5 * -30.3) + (2.1 * 100.2))
+ d = Complex(1.5, 2.1)
+ # remember the floating-point arithmetic
+ (c / d).should be_close(Complex(100.2, -30.3), TOLERANCE)
+ end
+ end
+
+ describe "with Fixnum" do
+ it "divides both parts of the Complex number" do
+ (Complex(20, 40) / 2).should == Complex(10, 20)
+ (Complex(30, 30) / 10).should == Complex(3, 3)
+ end
+
+ it "raises a ZeroDivisionError when given zero" do
+ -> { Complex(20, 40) / 0 }.should.raise(ZeroDivisionError)
+ end
+
+ it "produces Rational parts" do
+ (Complex(5, 9) / 2).should.eql?(Complex(Rational(5,2), Rational(9,2)))
+ end
+ end
+
+ describe "with Bignum" do
+ it "divides both parts of the Complex number" do
+ (Complex(20, 40) / 2).should == Complex(10, 20)
+ (Complex(15, 16) / 2.0).should be_close(Complex(7.5, 8), TOLERANCE)
+ end
+ end
+
+ describe "with Float" do
+ it "divides both parts of the Complex number" do
+ (Complex(3, 9) / 1.5).should == Complex(2, 6)
+ (Complex(15, 16) / 2.0).should be_close(Complex(7.5, 8), TOLERANCE)
+ end
+
+ it "returns Complex(Infinity, Infinity) when given zero" do
+ (Complex(20, 40) / 0.0).real.infinite?.should == 1
+ (Complex(20, 40) / 0.0).imag.infinite?.should == 1
+ (Complex(-20, 40) / 0.0).real.infinite?.should == -1
+ (Complex(-20, 40) / 0.0).imag.infinite?.should == 1
+ end
+ end
+
+ describe "with Object" do
+ it "tries to coerce self into other" do
+ value = Complex(3, 9)
+
+ obj = mock("Object")
+ obj.should_receive(:coerce).with(value).and_return([4, 2])
+ (value / obj).should == 2
+ end
+ end
+
+ describe "with a Numeric which responds to #real? with true" do
+ it "returns Complex(real.quo(other), imag.quo(other))" do
+ other = mock_numeric('other')
+ real = mock_numeric('real')
+ imag = mock_numeric('imag')
+ other.should_receive(:real?).and_return(true)
+ real.should_receive(:quo).with(other).and_return(1)
+ imag.should_receive(:quo).with(other).and_return(2)
+ (Complex(real, imag) / other).should == Complex(1, 2)
+ end
+ end
+
+ describe "with a Numeric which responds to #real? with false" do
+ it "coerces the passed argument to Complex and divides the resulting elements" do
+ complex = Complex(3, 0)
+ other = mock_numeric('other')
+ other.should_receive(:real?).any_number_of_times.and_return(false)
+ other.should_receive(:coerce).with(complex).and_return([5, 2])
+ (complex / other).should.eql?(Rational(5, 2))
+ end
+ end
end
diff --git a/spec/ruby/core/complex/eql_spec.rb b/spec/ruby/core/complex/eql_spec.rb
index c8e432029f..2082a22feb 100644
--- a/spec/ruby/core/complex/eql_spec.rb
+++ b/spec/ruby/core/complex/eql_spec.rb
@@ -1,24 +1,24 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Complex#eql?" do
it "returns false if other is not Complex" do
- Complex(1).eql?(1).should be_false
+ Complex(1).eql?(1).should == false
end
it "returns true when the respective parts are of the same classes and self == other" do
- Complex(1, 2).eql?(Complex(1, 2)).should be_true
+ Complex(1, 2).eql?(Complex(1, 2)).should == true
end
it "returns false when the real parts are of different classes" do
- Complex(1).eql?(Complex(1.0)).should be_false
+ Complex(1).eql?(Complex(1.0)).should == false
end
it "returns false when the imaginary parts are of different classes" do
- Complex(1, 2).eql?(Complex(1, 2.0)).should be_false
+ Complex(1, 2).eql?(Complex(1, 2.0)).should == false
end
it "returns false when self == other is false" do
- Complex(1, 2).eql?(Complex(2, 3)).should be_false
+ Complex(1, 2).eql?(Complex(2, 3)).should == false
end
it "does NOT send #eql? to real or imaginary parts" do
@@ -26,6 +26,6 @@ describe "Complex#eql?" do
imag = mock_numeric('imag')
real.should_not_receive(:eql?)
imag.should_not_receive(:eql?)
- Complex(real, imag).eql?(Complex(real, imag)).should be_true
+ Complex(real, imag).eql?(Complex(real, imag)).should == true
end
end
diff --git a/spec/ruby/core/complex/equal_value_spec.rb b/spec/ruby/core/complex/equal_value_spec.rb
index b3d93911bd..b3562ff3fb 100644
--- a/spec/ruby/core/complex/equal_value_spec.rb
+++ b/spec/ruby/core/complex/equal_value_spec.rb
@@ -1,5 +1,93 @@
-require File.expand_path('../../../shared/complex/equal_value', __FILE__)
+require_relative '../../spec_helper'
describe "Complex#==" do
- it_behaves_like :complex_equal_value, :==
+ describe "with Complex" do
+ it "returns true when self and other have numerical equality" do
+ Complex(1, 2).should == Complex(1, 2)
+ Complex(3, 9).should == Complex(3, 9)
+ Complex(-3, -9).should == Complex(-3, -9)
+
+ Complex(1, 2).should_not == Complex(3, 4)
+ Complex(3, 9).should_not == Complex(9, 3)
+
+ Complex(1.0, 2.0).should == Complex(1, 2)
+ Complex(3.0, 9.0).should_not == Complex(9.0, 3.0)
+
+ Complex(1.5, 2.5).should == Complex(1.5, 2.5)
+ Complex(1.5, 2.5).should == Complex(1.5, 2.5)
+ Complex(-1.5, 2.5).should == Complex(-1.5, 2.5)
+
+ Complex(1.5, 2.5).should_not == Complex(2.5, 1.5)
+ Complex(3.75, 2.5).should_not == Complex(1.5, 2.5)
+
+ Complex(bignum_value, 2.5).should == Complex(bignum_value, 2.5)
+ Complex(3.75, bignum_value).should_not == Complex(1.5, bignum_value)
+
+ Complex(nan_value).should_not == Complex(nan_value)
+ end
+ end
+
+ describe "with Numeric" do
+ it "returns true when self's imaginary part is 0 and the real part and other have numerical equality" do
+ Complex(3, 0).should == 3
+ Complex(-3, 0).should == -3
+
+ Complex(3.5, 0).should == 3.5
+ Complex(-3.5, 0).should == -3.5
+
+ Complex(bignum_value, 0).should == bignum_value
+ Complex(-bignum_value, 0).should == -bignum_value
+
+ Complex(3.0, 0).should == 3
+ Complex(-3.0, 0).should == -3
+
+ Complex(3, 0).should_not == 4
+ Complex(-3, 0).should_not == -4
+
+ Complex(3.5, 0).should_not == -4.5
+ Complex(-3.5, 0).should_not == 2.5
+
+ Complex(bignum_value, 0).should_not == bignum_value(10)
+ Complex(-bignum_value, 0).should_not == -bignum_value(20)
+ end
+ end
+
+ describe "with Object" do
+ # Integer#== and Float#== only return booleans - Bug?
+ it "calls other#== with self" do
+ value = Complex(3, 0)
+
+ obj = mock("Object")
+ obj.should_receive(:==).with(value).and_return(:expected)
+
+ (value == obj).should_not == false
+ end
+ end
+
+ describe "with a Numeric which responds to #real? with true" do
+ before do
+ @other = mock_numeric('other')
+ @other.should_receive(:real?).any_number_of_times.and_return(true)
+ end
+
+ it "returns real == other when the imaginary part is zero" do
+ real = mock_numeric('real')
+ real.should_receive(:==).with(@other).and_return(true)
+ (Complex(real, 0) == @other).should == true
+ end
+
+ it "returns false when the imaginary part is not zero" do
+ (Complex(3, 1) == @other).should == false
+ end
+ end
+
+ describe "with a Numeric which responds to #real? with false" do
+ it "returns other == self" do
+ complex = Complex(3, 0)
+ other = mock_numeric('other')
+ other.should_receive(:real?).any_number_of_times.and_return(false)
+ other.should_receive(:==).with(complex).and_return(true)
+ (complex == other).should == true
+ end
+ end
end
diff --git a/spec/ruby/core/complex/exponent_spec.rb b/spec/ruby/core/complex/exponent_spec.rb
index 62f61a2bf3..d0db0a40c2 100644
--- a/spec/ruby/core/complex/exponent_spec.rb
+++ b/spec/ruby/core/complex/exponent_spec.rb
@@ -1,5 +1,61 @@
-require File.expand_path('../../../shared/complex/exponent', __FILE__)
+require_relative '../../spec_helper'
describe "Complex#**" do
- it_behaves_like :complex_exponent, :**
+ describe "with Integer 0" do
+ it "returns Complex(1)" do
+ (Complex(3, 4) ** 0).should.eql?(Complex(1))
+ end
+ end
+
+ describe "with Float 0.0" do
+ it "returns Complex(1.0, 0.0)" do
+ (Complex(3, 4) ** 0.0).should.eql?(Complex(1.0, 0.0))
+ end
+ end
+
+ describe "with Complex" do
+ it "returns self raised to the given power" do
+ (Complex(2, 1) ** Complex(2, 1)).should be_close(Complex(-0.504824688978319, 3.10414407699553), TOLERANCE)
+ (Complex(2, 1) ** Complex(3, 4)).should be_close(Complex(-0.179174656916581, -1.74071656397662), TOLERANCE)
+
+ (Complex(2, 1) ** Complex(-2, -1)).should be_close(Complex(-0.051041070450869, -0.313849223270419), TOLERANCE)
+ (Complex(-2, -1) ** Complex(2, 1)).should be_close(Complex(-11.6819929610857, 71.8320439736158), TOLERANCE)
+ end
+ end
+
+ describe "with Integer" do
+ it "returns self raised to the given power" do
+ (Complex(2, 1) ** 2).should == Complex(3, 4)
+ (Complex(3, 4) ** 2).should == Complex(-7, 24)
+ (Complex(3, 4) ** -2).should be_close(Complex(-0.0112, -0.0384), TOLERANCE)
+
+
+ (Complex(2, 1) ** 2.5).should be_close(Complex(2.99179707178602, 6.85206901006896), TOLERANCE)
+ (Complex(3, 4) ** 2.5).should be_close(Complex(-38.0, 41.0), TOLERANCE)
+ (Complex(3, 4) ** -2.5).should be_close(Complex(-0.01216, -0.01312), TOLERANCE)
+
+ (Complex(1) ** 1).should == Complex(1)
+
+ # NOTE: Takes way too long...
+ #(Complex(2, 1) ** bignum_value)
+ end
+ end
+
+ describe "with Rational" do
+ it "returns self raised to the given power" do
+ (Complex(2, 1) ** Rational(3, 4)).should be_close(Complex(1.71913265276568, 0.623124744394697), TOLERANCE)
+ (Complex(2, 1) ** Rational(4, 3)).should be_close(Complex(2.3828547125173, 1.69466313833091), TOLERANCE)
+ (Complex(2, 1) ** Rational(-4, 3)).should be_close(Complex(0.278700377879388, -0.198209003071003), TOLERANCE)
+ end
+ end
+
+ describe "with Object" do
+ it "tries to coerce self into other" do
+ value = Complex(3, 9)
+
+ obj = mock("Object")
+ obj.should_receive(:coerce).with(value).and_return([2, 5])
+ (value ** obj).should == 2 ** 5
+ end
+ end
end
diff --git a/spec/ruby/core/complex/fdiv_spec.rb b/spec/ruby/core/complex/fdiv_spec.rb
index 8211dfc9de..fdcbc6a95d 100644
--- a/spec/ruby/core/complex/fdiv_spec.rb
+++ b/spec/ruby/core/complex/fdiv_spec.rb
@@ -1,45 +1,45 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Complex#fdiv" do
it "accepts a numeric argument" do
- lambda { Complex(20).fdiv(2) }.should_not raise_error(TypeError)
- lambda { Complex(20).fdiv(2.0) }.should_not raise_error(TypeError)
- lambda { Complex(20).fdiv(bignum_value) }.should_not raise_error(TypeError)
+ -> { Complex(20).fdiv(2) }.should_not.raise(TypeError)
+ -> { Complex(20).fdiv(2.0) }.should_not.raise(TypeError)
+ -> { Complex(20).fdiv(bignum_value) }.should_not.raise(TypeError)
end
it "accepts a negative numeric argument" do
- lambda { Complex(20).fdiv(-2) }.should_not raise_error(TypeError)
- lambda { Complex(20).fdiv(-2.0) }.should_not raise_error(TypeError)
- lambda { Complex(20).fdiv(-bignum_value) }.should_not raise_error(TypeError)
+ -> { Complex(20).fdiv(-2) }.should_not.raise(TypeError)
+ -> { Complex(20).fdiv(-2.0) }.should_not.raise(TypeError)
+ -> { Complex(20).fdiv(-bignum_value) }.should_not.raise(TypeError)
end
it "raises a TypeError if passed a non-numeric argument" do
- lambda { Complex(20).fdiv([]) }.should raise_error(TypeError)
- lambda { Complex(20).fdiv(:sym) }.should raise_error(TypeError)
- lambda { Complex(20).fdiv('s') }.should raise_error(TypeError)
+ -> { Complex(20).fdiv([]) }.should.raise(TypeError)
+ -> { Complex(20).fdiv(:sym) }.should.raise(TypeError)
+ -> { Complex(20).fdiv('s') }.should.raise(TypeError)
end
it "sets the real part to NaN if self's real part is NaN" do
- Complex(nan_value).fdiv(2).real.nan?.should be_true
+ Complex(nan_value).fdiv(2).real.nan?.should == true
end
it "sets the imaginary part to NaN if self's imaginary part is NaN" do
- Complex(2, nan_value).fdiv(2).imag.nan?.should be_true
+ Complex(2, nan_value).fdiv(2).imag.nan?.should == true
end
it "sets the real and imaginary part to NaN if self's real and imaginary parts are NaN" do
- Complex(nan_value, nan_value).fdiv(2).imag.nan?.should be_true
- Complex(nan_value, nan_value).fdiv(2).real.nan?.should be_true
+ Complex(nan_value, nan_value).fdiv(2).imag.nan?.should == true
+ Complex(nan_value, nan_value).fdiv(2).real.nan?.should == true
end
it "sets the real and imaginary part to NaN if self's real part and the argument are both NaN" do
- Complex(nan_value, 2).fdiv(nan_value).imag.nan?.should be_true
- Complex(nan_value, 2).fdiv(nan_value).real.nan?.should be_true
+ Complex(nan_value, 2).fdiv(nan_value).imag.nan?.should == true
+ Complex(nan_value, 2).fdiv(nan_value).real.nan?.should == true
end
it "sets the real and imaginary part to NaN if self's real part, self's imaginary part, and the argument are NaN" do
- Complex(nan_value, nan_value).fdiv(nan_value).imag.nan?.should be_true
- Complex(nan_value, nan_value).fdiv(nan_value).real.nan?.should be_true
+ Complex(nan_value, nan_value).fdiv(nan_value).imag.nan?.should == true
+ Complex(nan_value, nan_value).fdiv(nan_value).real.nan?.should == true
end
it "sets the real part to Infinity if self's real part is Infinity" do
@@ -58,8 +58,8 @@ describe "Complex#fdiv" do
end
it "sets the real part to NaN and the imaginary part to NaN if self's imaginary part, self's real part, and the argument are Infinity" do
- Complex(infinity_value, infinity_value).fdiv(infinity_value).real.nan?.should be_true
- Complex(infinity_value, infinity_value).fdiv(infinity_value).imag.nan?.should be_true
+ Complex(infinity_value, infinity_value).fdiv(infinity_value).real.nan?.should == true
+ Complex(infinity_value, infinity_value).fdiv(infinity_value).imag.nan?.should == true
end
end
@@ -71,7 +71,7 @@ describe "Complex#fdiv with no imaginary part" do
it "returns a Complex number" do
@numbers.each do |real|
@numbers.each do |other|
- Complex(real).fdiv(other).should be_an_instance_of(Complex)
+ Complex(real).fdiv(other).should.instance_of?(Complex)
end
end
end
@@ -103,7 +103,7 @@ describe "Complex#fdiv with an imaginary part" do
@numbers.each_with_index do |other,idx|
Complex(
real,@numbers[idx == 0 ? -1 : idx-1]
- ).fdiv(other).should be_an_instance_of(Complex)
+ ).fdiv(other).should.instance_of?(Complex)
end
end
end
diff --git a/spec/ruby/core/complex/finite_spec.rb b/spec/ruby/core/complex/finite_spec.rb
index e9ee19bef3..7d9f82404e 100644
--- a/spec/ruby/core/complex/finite_spec.rb
+++ b/spec/ruby/core/complex/finite_spec.rb
@@ -1,36 +1,32 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
-ruby_version_is "2.4" do
- describe "Complex#finite?" do
- it "returns true if magnitude is finite" do
- (1+1i).finite?.should == true
- end
+describe "Complex#finite?" do
+ it "returns true if magnitude is finite" do
+ (1+1i).should.finite?
+ end
- it "returns false for positive infinity" do
- value = Complex(Float::INFINITY, 42)
- value.finite?.should == false
- end
+ it "returns false for positive infinity" do
+ value = Complex(Float::INFINITY, 42)
+ value.should_not.finite?
+ end
- it "returns false for positive complex with infinite imaginary" do
- value = Complex(1, Float::INFINITY)
- value.finite?.should == false
- end
+ it "returns false for positive complex with infinite imaginary" do
+ value = Complex(1, Float::INFINITY)
+ value.should_not.finite?
+ end
- it "returns false for negative infinity" do
- value = -Complex(Float::INFINITY, 42)
- value.finite?.should == false
- end
+ it "returns false for negative infinity" do
+ value = -Complex(Float::INFINITY, 42)
+ value.should_not.finite?
+ end
- it "returns false for negative complex with infinite imaginary" do
- value = -Complex(1, Float::INFINITY)
- value.finite?.should == false
- end
+ it "returns false for negative complex with infinite imaginary" do
+ value = -Complex(1, Float::INFINITY)
+ value.should_not.finite?
+ end
- ruby_bug "#14014", "2.4"..."2.5" do
- it "returns false for NaN" do
- value = Complex(Float::NAN, Float::NAN)
- value.finite?.should == false
- end
- end
+ it "returns false for NaN" do
+ value = Complex(Float::NAN, Float::NAN)
+ value.should_not.finite?
end
end
diff --git a/spec/ruby/core/complex/hash_spec.rb b/spec/ruby/core/complex/hash_spec.rb
index db4b3590df..cad283309d 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__)
+require_relative '../../spec_helper'
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..225f168e78 100644
--- a/spec/ruby/core/complex/imag_spec.rb
+++ b/spec/ruby/core/complex/imag_spec.rb
@@ -1,5 +1,7 @@
-require File.expand_path('../../../shared/complex/image', __FILE__)
+require_relative '../../spec_helper'
describe "Complex#imag" do
- it_behaves_like(:complex_image, :imag)
+ it "is an alias of Complex#imaginary" do
+ Complex.instance_method(:imag).should == Complex.instance_method(:imaginary)
+ end
end
diff --git a/spec/ruby/core/complex/imaginary_spec.rb b/spec/ruby/core/complex/imaginary_spec.rb
index ecae19283b..ac9284e934 100644
--- a/spec/ruby/core/complex/imaginary_spec.rb
+++ b/spec/ruby/core/complex/imaginary_spec.rb
@@ -1,5 +1,10 @@
-require File.expand_path('../../../shared/complex/image', __FILE__)
+require_relative '../../spec_helper'
describe "Complex#imaginary" do
- it_behaves_like :complex_image, :imaginary
+ it "returns the imaginary part of self" do
+ Complex(1, 0).imaginary.should == 0
+ Complex(2, 1).imaginary.should == 1
+ Complex(6.7, 8.9).imaginary.should == 8.9
+ Complex(1, bignum_value).imaginary.should == bignum_value
+ end
end
diff --git a/spec/ruby/core/complex/infinite_spec.rb b/spec/ruby/core/complex/infinite_spec.rb
index 79792c3169..9e48860dee 100644
--- a/spec/ruby/core/complex/infinite_spec.rb
+++ b/spec/ruby/core/complex/infinite_spec.rb
@@ -1,34 +1,32 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
-ruby_version_is "2.4" do
- describe "Complex#infinite?" do
- it "returns nil if magnitude is finite" do
- (1+1i).infinite?.should == nil
- end
+describe "Complex#infinite?" do
+ it "returns nil if magnitude is finite" do
+ (1+1i).infinite?.should == nil
+ end
- it "returns 1 for positive infinity" do
- value = Complex(Float::INFINITY, 42).infinite?
- value.should == 1
- end
+ it "returns 1 for positive infinity" do
+ value = Complex(Float::INFINITY, 42).infinite?
+ value.should == 1
+ end
- it "returns 1 for positive complex with infinite imaginary" do
- value = Complex(1, Float::INFINITY).infinite?
- value.should == 1
- end
+ it "returns 1 for positive complex with infinite imaginary" do
+ value = Complex(1, Float::INFINITY).infinite?
+ value.should == 1
+ end
- it "returns -1 for negative infinity" do
- value = -Complex(Float::INFINITY, 42).infinite?
- value.should == -1
- end
+ it "returns -1 for negative infinity" do
+ value = -Complex(Float::INFINITY, 42).infinite?
+ value.should == -1
+ end
- it "returns -1 for negative complex with infinite imaginary" do
- value = -Complex(1, Float::INFINITY).infinite?
- value.should == -1
- end
+ it "returns -1 for negative complex with infinite imaginary" do
+ value = -Complex(1, Float::INFINITY).infinite?
+ value.should == -1
+ end
- it "returns nil for NaN" do
- value = Complex(0, Float::NAN).infinite?
- value.should == nil
- end
+ it "returns nil for NaN" do
+ value = Complex(0, Float::NAN).infinite?
+ value.should == nil
end
end
diff --git a/spec/ruby/core/complex/inspect_spec.rb b/spec/ruby/core/complex/inspect_spec.rb
index b766e7f730..045be94b22 100644
--- a/spec/ruby/core/complex/inspect_spec.rb
+++ b/spec/ruby/core/complex/inspect_spec.rb
@@ -1,5 +1,37 @@
-require File.expand_path('../../../shared/complex/inspect', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../numeric/fixtures/classes'
describe "Complex#inspect" do
- it_behaves_like(:complex_inspect, :inspect)
+ it "returns (${real}+${image}i) for positive imaginary parts" do
+ Complex(1).inspect.should == "(1+0i)"
+ Complex(7).inspect.should == "(7+0i)"
+ Complex(-1, 4).inspect.should == "(-1+4i)"
+ Complex(-7, 6.7).inspect.should == "(-7+6.7i)"
+ end
+
+ it "returns (${real}-${image}i) for negative imaginary parts" do
+ Complex(0, -1).inspect.should == "(0-1i)"
+ Complex(-1, -4).inspect.should == "(-1-4i)"
+ Complex(-7, -6.7).inspect.should == "(-7-6.7i)"
+ end
+
+ it "calls #inspect on real and imaginary" do
+ real = NumericSpecs::Subclass.new
+ # + because of https://bugs.ruby-lang.org/issues/20337
+ real.should_receive(:inspect).and_return(+"1")
+ imaginary = NumericSpecs::Subclass.new
+ imaginary.should_receive(:inspect).and_return("2")
+ imaginary.should_receive(:<).any_number_of_times.and_return(false)
+ Complex(real, imaginary).inspect.should == "(1+2i)"
+ end
+
+ it "adds an `*' before the `i' if the last character of the imaginary part is not numeric" do
+ real = NumericSpecs::Subclass.new
+ # + because of https://bugs.ruby-lang.org/issues/20337
+ real.should_receive(:inspect).and_return(+"(1)")
+ imaginary = NumericSpecs::Subclass.new
+ imaginary.should_receive(:inspect).and_return("(2)")
+ imaginary.should_receive(:<).any_number_of_times.and_return(false)
+ Complex(real, imaginary).inspect.should == "((1)+(2)*i)"
+ end
end
diff --git a/spec/ruby/core/complex/integer_spec.rb b/spec/ruby/core/complex/integer_spec.rb
index 54b420e62c..559bfbccfd 100644
--- a/spec/ruby/core/complex/integer_spec.rb
+++ b/spec/ruby/core/complex/integer_spec.rb
@@ -1,9 +1,11 @@
+require_relative '../../spec_helper'
+
describe "Complex#integer?" do
it "returns false for a Complex with no imaginary part" do
- Complex(20).integer?.should be_false
+ Complex(20).integer?.should == false
end
it "returns false for a Complex with an imaginary part" do
- Complex(20,3).integer?.should be_false
+ Complex(20,3).integer?.should == false
end
end
diff --git a/spec/ruby/core/complex/magnitude_spec.rb b/spec/ruby/core/complex/magnitude_spec.rb
index e9175d763e..6341b4eec8 100644
--- a/spec/ruby/core/complex/magnitude_spec.rb
+++ b/spec/ruby/core/complex/magnitude_spec.rb
@@ -1,5 +1,7 @@
-require File.expand_path('../../../shared/complex/abs', __FILE__)
+require_relative '../../spec_helper'
describe "Complex#magnitude" do
- it_behaves_like(:complex_abs, :magnitude)
+ it "is an alias of Complex#abs" do
+ Complex.instance_method(:magnitude).should == Complex.instance_method(:abs)
+ end
end
diff --git a/spec/ruby/core/complex/marshal_dump_spec.rb b/spec/ruby/core/complex/marshal_dump_spec.rb
index 8d37929f54..201d55e9e5 100644
--- a/spec/ruby/core/complex/marshal_dump_spec.rb
+++ b/spec/ruby/core/complex/marshal_dump_spec.rb
@@ -1,8 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Complex#marshal_dump" do
it "is a private method" do
- Complex.should have_private_instance_method(:marshal_dump, false)
+ Complex.private_instance_methods(false).should.include?(:marshal_dump)
end
it "dumps real and imaginary parts" do
diff --git a/spec/ruby/core/complex/minus_spec.rb b/spec/ruby/core/complex/minus_spec.rb
index 2b7b8bb270..7c104ce784 100644
--- a/spec/ruby/core/complex/minus_spec.rb
+++ b/spec/ruby/core/complex/minus_spec.rb
@@ -1,5 +1,45 @@
-require File.expand_path('../../../shared/complex/minus', __FILE__)
+require_relative '../../spec_helper'
describe "Complex#-" do
- it_behaves_like :complex_minus, :-
+ describe "with Complex" do
+ it "subtracts both the real and imaginary components" do
+ (Complex(1, 2) - Complex(10, 20)).should == Complex(1 - 10, 2 - 20)
+ (Complex(1.5, 2.1) - Complex(100.2, -30.3)).should == Complex(1.5 - 100.2, 2.1 - (-30.3))
+ end
+ end
+
+ describe "with Integer" do
+ it "subtracts the real number from the real component of self" do
+ (Complex(1, 2) - 50).should == Complex(-49, 2)
+ (Complex(1, 2) - 50.5).should == Complex(-49.5, 2)
+ end
+ end
+
+ describe "with Object" do
+ it "tries to coerce self into other" do
+ value = Complex(3, 9)
+
+ obj = mock("Object")
+ obj.should_receive(:coerce).with(value).and_return([2, 5])
+ (value - obj).should == 2 - 5
+ end
+ end
+
+ describe "passed Numeric which responds to #real? with true" do
+ it "coerces the passed argument to the type of the real part and subtracts the resulting elements" do
+ n = mock_numeric('n')
+ n.should_receive(:real?).and_return(true)
+ n.should_receive(:coerce).with(1).and_return([1, 4])
+ (Complex(1, 2) - n).should == Complex(-3, 2)
+ end
+ end
+
+ describe "passed Numeric which responds to #real? with false" do
+ it "coerces the passed argument to Complex and subtracts the resulting elements" do
+ n = mock_numeric('n')
+ n.should_receive(:real?).and_return(false)
+ n.should_receive(:coerce).with(Complex(1, 2)).and_return([Complex(1, 2), Complex(3, 4)])
+ (Complex(1, 2) - n).should == Complex(-2, -2)
+ end
+ end
end
diff --git a/spec/ruby/core/complex/multiply_spec.rb b/spec/ruby/core/complex/multiply_spec.rb
index 7f600fc1ab..35bf7c8455 100644
--- a/spec/ruby/core/complex/multiply_spec.rb
+++ b/spec/ruby/core/complex/multiply_spec.rb
@@ -1,5 +1,49 @@
-require File.expand_path('../../../shared/complex/multiply', __FILE__)
+require_relative '../../spec_helper'
describe "Complex#*" do
- it_behaves_like :complex_multiply, :*
+ describe "with Complex" do
+ it "multiplies according to the usual rule for complex numbers: (a + bi) * (c + di) = ac - bd + (ad + bc)i" do
+ (Complex(1, 2) * Complex(10, 20)).should == Complex((1 * 10) - (2 * 20), (1 * 20) + (2 * 10))
+ (Complex(1.5, 2.1) * Complex(100.2, -30.3)).should == Complex((1.5 * 100.2) - (2.1 * -30.3), (1.5 * -30.3) + (2.1 * 100.2))
+ end
+ end
+
+ describe "with Integer" do
+ it "multiplies both parts of self by the given Integer" do
+ (Complex(3, 2) * 50).should == Complex(150, 100)
+ (Complex(-3, 2) * 50.5).should == Complex(-151.5, 101)
+ end
+ end
+
+ describe "with Object" do
+ it "tries to coerce self into other" do
+ value = Complex(3, 9)
+
+ obj = mock("Object")
+ obj.should_receive(:coerce).with(value).and_return([2, 5])
+ (value * obj).should == 2 * 5
+ end
+ end
+
+ describe "with a Numeric which responds to #real? with true" do
+ it "multiples both parts of self by other" do
+ other = mock_numeric('other')
+ real = mock_numeric('real')
+ imag = mock_numeric('imag')
+ other.should_receive(:real?).and_return(true)
+ real.should_receive(:*).with(other).and_return(1)
+ imag.should_receive(:*).with(other).and_return(2)
+ (Complex(real, imag) * other).should == Complex(1, 2)
+ end
+
+ describe "with a Numeric which responds to #real? with false" do
+ it "coerces the passed argument to Complex and multiplies the resulting elements" do
+ complex = Complex(3, 0)
+ other = mock_numeric('other')
+ other.should_receive(:real?).any_number_of_times.and_return(false)
+ other.should_receive(:coerce).with(complex).and_return([5, 2])
+ (complex * other).should == 10
+ end
+ end
+ end
end
diff --git a/spec/ruby/core/complex/negative_spec.rb b/spec/ruby/core/complex/negative_spec.rb
index 5b51933106..566975b8e1 100644
--- a/spec/ruby/core/complex/negative_spec.rb
+++ b/spec/ruby/core/complex/negative_spec.rb
@@ -1,11 +1,13 @@
+require_relative '../../spec_helper'
+
describe "Complex#negative?" do
it "is undefined" do
c = Complex(1)
- c.methods.should_not include(:negative?)
+ c.methods.should_not.include?(:negative?)
- lambda {
+ -> {
c.negative?
- }.should raise_error(NoMethodError)
+ }.should.raise(NoMethodError)
end
end
diff --git a/spec/ruby/core/complex/numerator_spec.rb b/spec/ruby/core/complex/numerator_spec.rb
index 8c0e8761bd..7ab66e6a61 100644
--- a/spec/ruby/core/complex/numerator_spec.rb
+++ b/spec/ruby/core/complex/numerator_spec.rb
@@ -1,5 +1,19 @@
-require File.expand_path('../../../shared/complex/numerator', __FILE__)
+require_relative '../../spec_helper'
describe "Complex#numerator" do
- it_behaves_like(:complex_numerator, :numerator)
+ it "returns self's numerator" do
+ Complex(2).numerator.should == Complex(2)
+ Complex(3, 4).numerator.should == Complex(3, 4)
+
+ Complex(Rational(3, 4), Rational(3, 4)).numerator.should == Complex(3, 3)
+ Complex(Rational(7, 4), Rational(8, 4)).numerator.should == Complex(7, 8)
+
+ Complex(Rational(7, 8), Rational(8, 4)).numerator.should == Complex(7, 16)
+ Complex(Rational(7, 4), Rational(8, 8)).numerator.should == Complex(7, 4)
+
+ # NOTE:
+ # Bug? - Fails with a MethodMissingError
+ # (undefined method `denominator' for 3.5:Float)
+ # Complex(3.5, 3.7).numerator
+ end
end
diff --git a/spec/ruby/core/complex/phase_spec.rb b/spec/ruby/core/complex/phase_spec.rb
index c17f922c7f..2ab90989e1 100644
--- a/spec/ruby/core/complex/phase_spec.rb
+++ b/spec/ruby/core/complex/phase_spec.rb
@@ -1,6 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/complex/arg', __FILE__)
+require_relative '../../spec_helper'
describe "Complex#phase" do
- it_behaves_like :complex_arg, :phase
+ it "is an alias of Complex#arg" do
+ Complex.instance_method(:phase).should == Complex.instance_method(:arg)
+ end
end
diff --git a/spec/ruby/core/complex/plus_spec.rb b/spec/ruby/core/complex/plus_spec.rb
index 076582681f..2056ca786c 100644
--- a/spec/ruby/core/complex/plus_spec.rb
+++ b/spec/ruby/core/complex/plus_spec.rb
@@ -1,5 +1,45 @@
-require File.expand_path('../../../shared/complex/plus', __FILE__)
+require_relative '../../spec_helper'
describe "Complex#+" do
- it_behaves_like :complex_plus, :+
+ describe "with Complex" do
+ it "adds both the real and imaginary components" do
+ (Complex(1, 2) + Complex(10, 20)).should == Complex(1 + 10, 2 + 20)
+ (Complex(1.5, 2.1) + Complex(100.2, -30.3)).should == Complex(1.5 + 100.2, 2.1 + (-30.3))
+ end
+ end
+
+ describe "with Integer" do
+ it "adds the real number to the real component of self" do
+ (Complex(1, 2) + 50).should == Complex(51, 2)
+ (Complex(1, 2) + 50.5).should == Complex(51.5, 2)
+ end
+ end
+
+ describe "with Object" do
+ it "tries to coerce self into other" do
+ value = Complex(3, 9)
+
+ obj = mock("Object")
+ obj.should_receive(:coerce).with(value).and_return([2, 5])
+ (value + obj).should == 2 + 5
+ end
+ end
+
+ describe "passed Numeric which responds to #real? with true" do
+ it "coerces the passed argument to the type of the real part and adds the resulting elements" do
+ n = mock_numeric('n')
+ n.should_receive(:real?).and_return(true)
+ n.should_receive(:coerce).with(1).and_return([1, 4])
+ (Complex(1, 2) + n).should == Complex(5, 2)
+ end
+ end
+
+ describe "passed Numeric which responds to #real? with false" do
+ it "coerces the passed argument to Complex and adds the resulting elements" do
+ n = mock_numeric('n')
+ n.should_receive(:real?).and_return(false)
+ n.should_receive(:coerce).with(Complex(1, 2)).and_return([Complex(1, 2), Complex(3, 4)])
+ (Complex(1, 2) + n).should == Complex(4, 6)
+ end
+ end
end
diff --git a/spec/ruby/core/complex/polar_spec.rb b/spec/ruby/core/complex/polar_spec.rb
index d847e916ff..824211fcd0 100644
--- a/spec/ruby/core/complex/polar_spec.rb
+++ b/spec/ruby/core/complex/polar_spec.rb
@@ -1,14 +1,41 @@
-require File.expand_path('../../../shared/complex/polar', __FILE__)
+require_relative '../../spec_helper'
describe "Complex.polar" do
- it_behaves_like(:complex_polar_class, :polar)
+ it "returns a complex number in terms of radius and angle" do
+ Complex.polar(50, 60).should be_close(Complex(-47.6206490207578, -15.2405310551108), TOLERANCE)
+ Complex.polar(-10, -20).should be_close(Complex(-4.08082061813392, 9.12945250727628), TOLERANCE)
+ end
it "raises a TypeError when given non real arguments" do
- lambda{ Complex.polar(nil) }.should raise_error(TypeError)
- lambda{ Complex.polar(nil, nil) }.should raise_error(TypeError)
+ ->{ Complex.polar(nil) }.should.raise(TypeError)
+ ->{ Complex.polar(nil, nil) }.should.raise(TypeError)
+ end
+
+ it "computes the real values of the real & imaginary parts from the polar form" do
+ a = Complex.polar(1.0+0.0i, Math::PI/2+0.0i)
+ a.real.should be_close(0.0, TOLERANCE)
+ a.imag.should be_close(1.0, TOLERANCE)
+ a.real.real?.should == true
+ a.imag.real?.should == true
+
+ b = Complex.polar(1+0.0i)
+ b.real.should be_close(1.0, TOLERANCE)
+ b.imag.should be_close(0.0, TOLERANCE)
+ b.real.real?.should == true
+ b.imag.real?.should == true
end
end
describe "Complex#polar" do
- it_behaves_like(:complex_polar, :polar)
+ it "returns the absolute value and the argument" do
+ a = Complex(3, 4)
+ a.polar.size.should == 2
+ a.polar.first.should == 5.0
+ a.polar.last.should be_close(0.927295218001612, TOLERANCE)
+
+ b = Complex(-3.5, 4.7)
+ b.polar.size.should == 2
+ b.polar.first.should be_close(5.86003412959345, TOLERANCE)
+ b.polar.last.should be_close(2.21088447955664, TOLERANCE)
+ end
end
diff --git a/spec/ruby/core/complex/positive_spec.rb b/spec/ruby/core/complex/positive_spec.rb
index 88898d31cf..d2fb256538 100644
--- a/spec/ruby/core/complex/positive_spec.rb
+++ b/spec/ruby/core/complex/positive_spec.rb
@@ -1,11 +1,13 @@
+require_relative '../../spec_helper'
+
describe "Complex#positive?" do
it "is undefined" do
c = Complex(1)
- c.methods.should_not include(:positive?)
+ c.methods.should_not.include?(:positive?)
- lambda {
+ -> {
c.positive?
- }.should raise_error(NoMethodError)
+ }.should.raise(NoMethodError)
end
end
diff --git a/spec/ruby/core/complex/quo_spec.rb b/spec/ruby/core/complex/quo_spec.rb
index cb3f1203b4..be0a44d532 100644
--- a/spec/ruby/core/complex/quo_spec.rb
+++ b/spec/ruby/core/complex/quo_spec.rb
@@ -1,5 +1,7 @@
-require File.expand_path('../../../shared/complex/divide', __FILE__)
+require_relative '../../spec_helper'
describe "Complex#quo" do
- it_behaves_like :complex_divide, :quo
+ it "is an alias of Complex#/" do
+ Complex.instance_method(:quo).should == Complex.instance_method(:/)
+ end
end
diff --git a/spec/ruby/core/complex/rationalize_spec.rb b/spec/ruby/core/complex/rationalize_spec.rb
index 2dd1e9b122..d49bb52def 100644
--- a/spec/ruby/core/complex/rationalize_spec.rb
+++ b/spec/ruby/core/complex/rationalize_spec.rb
@@ -1,10 +1,12 @@
+require_relative '../../spec_helper'
+
describe "Complex#rationalize" do
it "raises RangeError if self has non-zero imaginary part" do
- lambda { Complex(1,5).rationalize }.should raise_error(RangeError)
+ -> { Complex(1,5).rationalize }.should.raise(RangeError)
end
it "raises RangeError if self has 0.0 imaginary part" do
- lambda { Complex(1,0.0).rationalize }.should raise_error(RangeError)
+ -> { Complex(1,0.0).rationalize }.should.raise(RangeError)
end
it "returns a Rational if self has zero imaginary part" do
@@ -23,7 +25,7 @@ describe "Complex#rationalize" do
end
it "raises ArgumentError when passed more than one argument" do
- lambda { Complex(1,0).rationalize(0.1, 0.1) }.should raise_error(ArgumentError)
- lambda { Complex(1,0).rationalize(0.1, 0.1, 2) }.should raise_error(ArgumentError)
+ -> { Complex(1,0).rationalize(0.1, 0.1) }.should.raise(ArgumentError)
+ -> { Complex(1,0).rationalize(0.1, 0.1, 2) }.should.raise(ArgumentError)
end
end
diff --git a/spec/ruby/core/complex/real_spec.rb b/spec/ruby/core/complex/real_spec.rb
index 1293e02d3c..41734b23f0 100644
--- a/spec/ruby/core/complex/real_spec.rb
+++ b/spec/ruby/core/complex/real_spec.rb
@@ -1,23 +1,28 @@
-require File.expand_path('../../../shared/complex/real', __FILE__)
+require_relative '../../spec_helper'
describe "Complex#real" do
- it_behaves_like(:complex_real, :real)
+ it "returns the real part of self" do
+ Complex(1, 0).real.should == 1
+ Complex(2, 1).real.should == 2
+ Complex(6.7, 8.9).real.should == 6.7
+ Complex(bignum_value, 3).real.should == bignum_value
+ end
end
describe "Complex#real?" do
it "returns false if there is an imaginary part" do
- Complex(2,3).real?.should be_false
+ Complex(2,3).real?.should == false
end
it "returns false if there is not an imaginary part" do
- Complex(2).real?.should be_false
+ Complex(2).real?.should == false
end
it "returns false if the real part is Infinity" do
- Complex(infinity_value).real?.should be_false
+ Complex(infinity_value).real?.should == false
end
it "returns false if the real part is NaN" do
- Complex(nan_value).real?.should be_false
+ Complex(nan_value).real?.should == false
end
end
diff --git a/spec/ruby/core/complex/rect_spec.rb b/spec/ruby/core/complex/rect_spec.rb
index cf2ff9e83b..bf3467c611 100644
--- a/spec/ruby/core/complex/rect_spec.rb
+++ b/spec/ruby/core/complex/rect_spec.rb
@@ -1,9 +1,13 @@
-require File.expand_path('../../../shared/complex/rect', __FILE__)
+require_relative '../../spec_helper'
describe "Complex#rect" do
- it_behaves_like(:complex_rect, :rect)
+ it "is an alias of Complex#rectangular" do
+ Complex.instance_method(:rect).should == Complex.instance_method(:rectangular)
+ end
end
describe "Complex.rect" do
- it_behaves_like(:complex_rect_class, :rect)
+ it "is an alias of Complex.rectangular" do
+ Complex.method(:rect).should == Complex.method(:rectangular)
+ end
end
diff --git a/spec/ruby/core/complex/rectangular_spec.rb b/spec/ruby/core/complex/rectangular_spec.rb
index 0eb29c3500..7789bf925e 100644
--- a/spec/ruby/core/complex/rectangular_spec.rb
+++ b/spec/ruby/core/complex/rectangular_spec.rb
@@ -1,9 +1,114 @@
-require File.expand_path('../../../shared/complex/rect', __FILE__)
+require_relative '../../spec_helper'
describe "Complex#rectangular" do
- it_behaves_like(:complex_rect, :rectangular)
+ before :each do
+ @numbers = [
+ Complex(1),
+ Complex(0, 20),
+ Complex(0, 0),
+ Complex(0.0),
+ Complex(9999999**99),
+ Complex(-20),
+ Complex.polar(76, 10)
+ ]
+ end
+
+ it "returns an Array" do
+ @numbers.each do |number|
+ number.rectangular.should.instance_of?(Array)
+ end
+ end
+
+ it "returns a two-element Array" do
+ @numbers.each do |number|
+ number.rectangular.size.should == 2
+ end
+ end
+
+ it "returns the real part of self as the first element" do
+ @numbers.each do |number|
+ number.rectangular.first.should == number.real
+ end
+ end
+
+ it "returns the imaginary part of self as the last element" do
+ @numbers.each do |number|
+ number.rectangular.last.should == number.imaginary
+ end
+ end
+
+ it "raises an ArgumentError if given any arguments" do
+ @numbers.each do |number|
+ -> { number.rectangular(number) }.should.raise(ArgumentError)
+ end
+ end
end
describe "Complex.rectangular" do
- it_behaves_like(:complex_rect_class, :rectangular)
+ describe "passed a Numeric n which responds to #real? with true" do
+ it "returns a Complex with real part n and imaginary part 0" do
+ n = mock_numeric('n')
+ n.should_receive(:real?).any_number_of_times.and_return(true)
+ result = Complex.rectangular(n)
+ result.real.should == n
+ result.imag.should == 0
+ end
+ end
+
+ describe "passed a Numeric which responds to #real? with false" do
+ it "raises TypeError" do
+ n = mock_numeric('n')
+ n.should_receive(:real?).any_number_of_times.and_return(false)
+ -> { Complex.rectangular(n) }.should.raise(TypeError)
+ end
+ end
+
+ describe "passed Numerics n1 and n2 and at least one responds to #real? with false" do
+ [[false, false], [false, true], [true, false]].each do |r1, r2|
+ it "raises TypeError" do
+ n1 = mock_numeric('n1')
+ n2 = mock_numeric('n2')
+ n1.should_receive(:real?).any_number_of_times.and_return(r1)
+ n2.should_receive(:real?).any_number_of_times.and_return(r2)
+ -> { Complex.rectangular(n1, n2) }.should.raise(TypeError)
+ end
+ end
+ end
+
+ describe "passed Numerics n1 and n2 and both respond to #real? with true" do
+ it "returns a Complex with real part n1 and imaginary part n2" do
+ n1 = mock_numeric('n1')
+ n2 = mock_numeric('n2')
+ n1.should_receive(:real?).any_number_of_times.and_return(true)
+ n2.should_receive(:real?).any_number_of_times.and_return(true)
+ result = Complex.rectangular(n1, n2)
+ result.real.should == n1
+ result.imag.should == n2
+ end
+ end
+
+ describe "when passed a Complex" do
+ it "raises a TypeError when the imaginary part is not zero" do
+ -> {
+ Complex.rectangular(1.0+1i, 2)
+ }.should.raise(TypeError)
+
+ -> {
+ Complex.rectangular(1.0, 2i)
+ }.should.raise(TypeError)
+ end
+
+ it "ignores the imaginary part if it is zero" do
+ result = Complex.rectangular(1.0+0i, 2+0.0i)
+ result.real.should == 1.0
+ result.imag.should == 2
+ end
+ end
+
+ describe "passed a non-Numeric" do
+ it "raises TypeError" do
+ -> { Complex.rectangular(:sym) }.should.raise(TypeError)
+ -> { Complex.rectangular(0, :sym) }.should.raise(TypeError)
+ end
+ end
end
diff --git a/spec/ruby/core/complex/to_c_spec.rb b/spec/ruby/core/complex/to_c_spec.rb
new file mode 100644
index 0000000000..cd7195556c
--- /dev/null
+++ b/spec/ruby/core/complex/to_c_spec.rb
@@ -0,0 +1,12 @@
+require_relative '../../spec_helper'
+
+describe "Complex#to_c" do
+ it "returns self" do
+ value = Complex(1, 5)
+ value.to_c.should.equal?(value)
+ end
+
+ it 'returns the same value' do
+ Complex(1, 5).to_c.should == Complex(1, 5)
+ end
+end
diff --git a/spec/ruby/core/complex/to_f_spec.rb b/spec/ruby/core/complex/to_f_spec.rb
index 33342e61cc..9f3265cdb9 100644
--- a/spec/ruby/core/complex/to_f_spec.rb
+++ b/spec/ruby/core/complex/to_f_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Complex#to_f" do
- describe "when the imaginary part is Fixnum 0" do
+ describe "when the imaginary part is Integer 0" do
it "returns the result of sending #to_f to the real part" do
real = mock_numeric('real')
real.should_receive(:to_f).and_return(:f)
@@ -29,13 +29,13 @@ describe "Complex#to_f" do
describe "when the imaginary part is non-zero" do
it "raises RangeError" do
- lambda { Complex(0, 1).to_f }.should raise_error(RangeError)
+ -> { Complex(0, 1).to_f }.should.raise(RangeError)
end
end
describe "when the imaginary part is Float 0.0" do
it "raises RangeError" do
- lambda { Complex(0, 0.0).to_f }.should raise_error(RangeError)
+ -> { Complex(0, 0.0).to_f }.should.raise(RangeError)
end
end
end
diff --git a/spec/ruby/core/complex/to_i_spec.rb b/spec/ruby/core/complex/to_i_spec.rb
index ea8b199b2e..9149ffbbaa 100644
--- a/spec/ruby/core/complex/to_i_spec.rb
+++ b/spec/ruby/core/complex/to_i_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Complex#to_i" do
- describe "when the imaginary part is Fixnum 0" do
+ describe "when the imaginary part is Integer 0" do
it "returns the result of sending #to_i to the real part" do
real = mock_numeric('real')
real.should_receive(:to_i).and_return(:i)
@@ -29,13 +29,13 @@ describe "Complex#to_i" do
describe "when the imaginary part is non-zero" do
it "raises RangeError" do
- lambda { Complex(0, 1).to_i }.should raise_error(RangeError)
+ -> { Complex(0, 1).to_i }.should.raise(RangeError)
end
end
describe "when the imaginary part is Float 0.0" do
it "raises RangeError" do
- lambda { Complex(0, 0.0).to_i }.should raise_error(RangeError)
+ -> { Complex(0, 0.0).to_i }.should.raise(RangeError)
end
end
end
diff --git a/spec/ruby/core/complex/to_r_spec.rb b/spec/ruby/core/complex/to_r_spec.rb
index 92fcdd3862..6587ae9e2e 100644
--- a/spec/ruby/core/complex/to_r_spec.rb
+++ b/spec/ruby/core/complex/to_r_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Complex#to_r" do
- describe "when the imaginary part is Fixnum 0" do
+ describe "when the imaginary part is Integer 0" do
it "returns the result of sending #to_r to the real part" do
real = mock_numeric('real')
real.should_receive(:to_r).and_return(:r)
@@ -29,13 +29,21 @@ describe "Complex#to_r" do
describe "when the imaginary part is non-zero" do
it "raises RangeError" do
- lambda { Complex(0, 1).to_r }.should raise_error(RangeError)
+ -> { Complex(0, 1).to_r }.should.raise(RangeError)
end
end
describe "when the imaginary part is Float 0.0" do
- it "raises RangeError" do
- lambda { Complex(0, 0.0).to_r }.should raise_error(RangeError)
+ ruby_version_is ''...'3.4' do
+ it "raises RangeError" do
+ -> { Complex(0, 0.0).to_r }.should.raise(RangeError)
+ end
+ end
+
+ ruby_version_is '3.4' do
+ it "returns a Rational" do
+ Complex(0, 0.0).to_r.should == 0r
+ end
end
end
end
diff --git a/spec/ruby/core/complex/to_s_spec.rb b/spec/ruby/core/complex/to_s_spec.rb
index c398bb000e..ceccffe470 100644
--- a/spec/ruby/core/complex/to_s_spec.rb
+++ b/spec/ruby/core/complex/to_s_spec.rb
@@ -1,5 +1,55 @@
-require File.expand_path('../../../shared/complex/to_s', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../numeric/fixtures/classes'
describe "Complex#to_s" do
- it_behaves_like(:complex_to_s, :to_s)
+ describe "when self's real component is 0" do
+ it "returns both the real and imaginary component even when the real is 0" do
+ Complex(0, 5).to_s.should == "0+5i"
+ Complex(0, -3.2).to_s.should == "0-3.2i"
+ end
+ end
+
+ it "returns self as String" do
+ Complex(1, 5).to_s.should == "1+5i"
+ Complex(-2.5, 1.5).to_s.should == "-2.5+1.5i"
+
+ Complex(1, -5).to_s.should == "1-5i"
+ Complex(-2.5, -1.5).to_s.should == "-2.5-1.5i"
+
+ # Guard against the Mathn library
+ guard -> { !defined?(Math.rsqrt) } do
+ Complex(1, 0).to_s.should == "1+0i"
+ Complex(1, -0).to_s.should == "1+0i"
+ end
+ end
+
+ it "returns 1+0.0i for Complex(1, 0.0)" do
+ Complex(1, 0.0).to_s.should == "1+0.0i"
+ end
+
+ it "returns 1-0.0i for Complex(1, -0.0)" do
+ Complex(1, -0.0).to_s.should == "1-0.0i"
+ end
+
+ it "returns 1+Infinity*i for Complex(1, Infinity)" do
+ Complex(1, infinity_value).to_s.should == "1+Infinity*i"
+ end
+
+ it "returns 1-Infinity*i for Complex(1, -Infinity)" do
+ Complex(1, -infinity_value).to_s.should == "1-Infinity*i"
+ end
+
+ it "returns 1+NaN*i for Complex(1, NaN)" do
+ Complex(1, nan_value).to_s.should == "1+NaN*i"
+ end
+
+ it "treats real and imaginary parts as strings" do
+ real = NumericSpecs::Subclass.new
+ # + because of https://bugs.ruby-lang.org/issues/20337
+ real.should_receive(:to_s).and_return(+"1")
+ imaginary = NumericSpecs::Subclass.new
+ imaginary.should_receive(:to_s).and_return("2")
+ imaginary.should_receive(:<).any_number_of_times.and_return(false)
+ Complex(real, imaginary).to_s.should == "1+2i"
+ end
end
diff --git a/spec/ruby/core/complex/uminus_spec.rb b/spec/ruby/core/complex/uminus_spec.rb
index 1bf56e770b..c0184e11de 100644
--- a/spec/ruby/core/complex/uminus_spec.rb
+++ b/spec/ruby/core/complex/uminus_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Complex#-@" do
it "sends #-@ to the real and imaginary parts and returns a Complex with the resulting respective parts" do
diff --git a/spec/ruby/core/conditionvariable/broadcast_spec.rb b/spec/ruby/core/conditionvariable/broadcast_spec.rb
new file mode 100644
index 0000000000..16c7b4cc8d
--- /dev/null
+++ b/spec/ruby/core/conditionvariable/broadcast_spec.rb
@@ -0,0 +1,39 @@
+require_relative '../../spec_helper'
+
+describe "ConditionVariable#broadcast" do
+ it "releases all threads waiting in line for this resource" do
+ m = Mutex.new
+ cv = ConditionVariable.new
+ threads = []
+ r1 = []
+ r2 = []
+
+ # large number to attempt to cause race conditions
+ 100.times do |i|
+ threads << Thread.new(i) do |tid|
+ m.synchronize do
+ r1 << tid
+ cv.wait(m)
+ r2 << tid
+ end
+ end
+ end
+
+ # wait for all threads to acquire the mutex the first time
+ Thread.pass until m.synchronize { r1.size == threads.size }
+ # wait until all threads are sleeping (ie waiting)
+ Thread.pass until threads.all?(&:stop?)
+
+ r2.should.empty?
+ m.synchronize do
+ cv.broadcast
+ end
+
+ threads.each {|t| t.join }
+
+ # ensure that all threads that enter cv.wait are released
+ r2.sort.should == r1.sort
+ # note that order is not specified as broadcast results in a race
+ # condition on regaining the lock m
+ end
+end
diff --git a/spec/ruby/core/conditionvariable/marshal_dump_spec.rb b/spec/ruby/core/conditionvariable/marshal_dump_spec.rb
new file mode 100644
index 0000000000..594c178e88
--- /dev/null
+++ b/spec/ruby/core/conditionvariable/marshal_dump_spec.rb
@@ -0,0 +1,8 @@
+require_relative '../../spec_helper'
+
+describe "ConditionVariable#marshal_dump" do
+ it "raises a TypeError" do
+ cv = ConditionVariable.new
+ -> { cv.marshal_dump }.should.raise(TypeError, /can't dump/)
+ end
+end
diff --git a/spec/ruby/core/conditionvariable/signal_spec.rb b/spec/ruby/core/conditionvariable/signal_spec.rb
new file mode 100644
index 0000000000..3b266cf8c6
--- /dev/null
+++ b/spec/ruby/core/conditionvariable/signal_spec.rb
@@ -0,0 +1,76 @@
+require_relative '../../spec_helper'
+
+describe "ConditionVariable#signal" do
+ it "releases the first thread waiting in line for this resource" do
+ m = Mutex.new
+ cv = ConditionVariable.new
+ threads = []
+ r1 = []
+ r2 = []
+
+ # large number to attempt to cause race conditions
+ 100.times do |i|
+ threads << Thread.new(i) do |tid|
+ m.synchronize do
+ r1 << tid
+ cv.wait(m)
+ r2 << tid
+ end
+ end
+ end
+
+ # wait for all threads to acquire the mutex the first time
+ Thread.pass until m.synchronize { r1.size == threads.size }
+ # wait until all threads are sleeping (ie waiting)
+ Thread.pass until threads.all?(&:stop?)
+
+ r2.should.empty?
+ 100.times do |i|
+ m.synchronize do
+ cv.signal
+ end
+ Thread.pass until r2.size == i+1
+ end
+
+ threads.each {|t| t.join }
+
+ # ensure that all the threads that went into the cv.wait are
+ # released in the same order
+ r2.should == r1
+ end
+
+ it "allows control to be passed between a pair of threads" do
+ m = Mutex.new
+ cv = ConditionVariable.new
+ repeats = 100
+ in_synchronize = false
+
+ t1 = Thread.new do
+ m.synchronize do
+ in_synchronize = true
+ repeats.times do
+ cv.wait(m)
+ cv.signal
+ end
+ end
+ end
+
+ # Make sure t1 is waiting for a signal before launching t2.
+ Thread.pass until in_synchronize
+ Thread.pass until t1.stop?
+
+ t2 = Thread.new do
+ m.synchronize do
+ repeats.times do
+ cv.signal
+ cv.wait(m)
+ end
+ end
+ end
+
+ # Check that both threads terminated without exception
+ t1.join
+ t2.join
+ m.should_not.locked?
+ end
+end
diff --git a/spec/ruby/core/conditionvariable/wait_spec.rb b/spec/ruby/core/conditionvariable/wait_spec.rb
new file mode 100644
index 0000000000..1af53a15a2
--- /dev/null
+++ b/spec/ruby/core/conditionvariable/wait_spec.rb
@@ -0,0 +1,174 @@
+require_relative '../../spec_helper'
+
+describe "ConditionVariable#wait" do
+ it "calls #sleep on the given object" do
+ o = Object.new
+ o.should_receive(:sleep).with(1234)
+
+ cv = ConditionVariable.new
+
+ cv.wait(o, 1234)
+ end
+
+ it "can be woken up by ConditionVariable#signal" do
+ m = Mutex.new
+ cv = ConditionVariable.new
+ in_synchronize = false
+
+ th = Thread.new do
+ m.synchronize do
+ in_synchronize = true
+ cv.wait(m)
+ end
+ :success
+ end
+
+ # wait for m to acquire the mutex
+ Thread.pass until in_synchronize
+ # wait until th is sleeping (ie waiting)
+ Thread.pass until th.stop?
+
+ m.synchronize { cv.signal }
+ th.value.should == :success
+ end
+
+ it "can be interrupted by Thread#run" do
+ m = Mutex.new
+ cv = ConditionVariable.new
+ in_synchronize = false
+
+ th = Thread.new do
+ m.synchronize do
+ in_synchronize = true
+ cv.wait(m)
+ end
+ :success
+ end
+
+ # wait for m to acquire the mutex
+ Thread.pass until in_synchronize
+ # wait until th is sleeping (ie waiting)
+ Thread.pass until th.stop?
+
+ th.run
+ th.value.should == :success
+ end
+
+ it "can be interrupted by Thread#wakeup" do
+ m = Mutex.new
+ cv = ConditionVariable.new
+ in_synchronize = false
+
+ th = Thread.new do
+ m.synchronize do
+ in_synchronize = true
+ cv.wait(m)
+ end
+ :success
+ end
+
+ # wait for m to acquire the mutex
+ Thread.pass until in_synchronize
+ # wait until th is sleeping (ie waiting)
+ Thread.pass until th.stop?
+
+ th.wakeup
+ th.value.should == :success
+ end
+
+ it "reacquires the lock even if the thread is killed" do
+ m = Mutex.new
+ cv = ConditionVariable.new
+ in_synchronize = false
+ owned = nil
+
+ th = Thread.new do
+ m.synchronize do
+ in_synchronize = true
+ begin
+ cv.wait(m)
+ ensure
+ owned = m.owned?
+ $stderr.puts "\nThe Thread doesn't own the Mutex!" unless owned
+ end
+ end
+ end
+
+ # wait for m to acquire the mutex
+ Thread.pass until in_synchronize
+ # wait until th is sleeping (ie waiting)
+ Thread.pass until th.stop?
+
+ th.kill
+ th.join
+
+ owned.should == true
+ end
+
+ it "reacquires the lock even if the thread is killed after being signaled" do
+ m = Mutex.new
+ cv = ConditionVariable.new
+ in_synchronize = false
+ owned = nil
+
+ th = Thread.new do
+ m.synchronize do
+ in_synchronize = true
+ begin
+ cv.wait(m)
+ ensure
+ owned = m.owned?
+ $stderr.puts "\nThe Thread doesn't own the Mutex!" unless owned
+ end
+ end
+ end
+
+ # wait for m to acquire the mutex
+ Thread.pass until in_synchronize
+ # wait until th is sleeping (ie waiting)
+ Thread.pass until th.stop?
+
+ m.synchronize {
+ cv.signal
+ # Wait that the thread is blocked on acquiring the Mutex
+ sleep 0.001
+ # Kill the thread, yet the thread should first acquire the Mutex before going on
+ th.kill
+ }
+
+ th.join
+ owned.should == true
+ end
+
+ it "supports multiple Threads waiting on the same ConditionVariable and Mutex" do
+ m = Mutex.new
+ cv = ConditionVariable.new
+ n_threads = 4
+ events = []
+
+ threads = n_threads.times.map {
+ Thread.new {
+ m.synchronize {
+ events << :t_in_synchronize
+ cv.wait(m)
+ }
+ }
+ }
+
+ Thread.pass until m.synchronize { events.size } == n_threads
+ Thread.pass until threads.any?(&:stop?)
+ m.synchronize do
+ threads.each { |t|
+ # Cause interactions with the waiting threads.
+ # On TruffleRuby, this causes a safepoint which has interesting
+ # interactions with the ConditionVariable.
+ bt = t.backtrace
+ bt.should.is_a?(Array)
+ bt.size.should >= 2
+ }
+ end
+
+ cv.broadcast
+ threads.each(&:join)
+ end
+end
diff --git a/spec/ruby/core/data/constants_spec.rb b/spec/ruby/core/data/constants_spec.rb
new file mode 100644
index 0000000000..ad0b1ddea7
--- /dev/null
+++ b/spec/ruby/core/data/constants_spec.rb
@@ -0,0 +1,11 @@
+require_relative '../../spec_helper'
+
+describe "Data" do
+ it "is a new constant" do
+ Data.superclass.should == Object
+ end
+
+ it "is not deprecated" do
+ -> { Data }.should_not complain
+ end
+end
diff --git a/spec/ruby/core/data/deconstruct_keys_spec.rb b/spec/ruby/core/data/deconstruct_keys_spec.rb
new file mode 100644
index 0000000000..7e81f966ea
--- /dev/null
+++ b/spec/ruby/core/data/deconstruct_keys_spec.rb
@@ -0,0 +1,110 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe "Data#deconstruct_keys" do
+ it "returns a hash of attributes" do
+ klass = Data.define(:x, :y)
+ d = klass.new(1, 2)
+
+ d.deconstruct_keys([:x, :y]).should == {x: 1, y: 2}
+ end
+
+ it "requires one argument" do
+ klass = Data.define(:x, :y)
+ d = klass.new(1, 2)
+
+ -> {
+ d.deconstruct_keys
+ }.should.raise(ArgumentError, /wrong number of arguments \(given 0, expected 1\)/)
+ end
+
+ it "returns only specified keys" do
+ klass = Data.define(:x, :y)
+ d = klass.new(1, 2)
+
+ d.deconstruct_keys([:x, :y]).should == {x: 1, y: 2}
+ d.deconstruct_keys([:x] ).should == {x: 1}
+ d.deconstruct_keys([] ).should == {}
+ end
+
+ it "accepts string attribute names" do
+ klass = Data.define(:x, :y)
+ d = klass.new(1, 2)
+
+ d.deconstruct_keys(['x', 'y']).should == {'x' => 1, 'y' => 2}
+ end
+
+ it "returns an empty hash when there are more keys than attributes" do
+ klass = Data.define(:x, :y)
+ d = klass.new(1, 2)
+
+ d.deconstruct_keys([:x, :y, :x]).should == {}
+ end
+
+ it "returns at first not existing attribute name" do
+ klass = Data.define(:x, :y)
+ d = klass.new(1, 2)
+
+ d.deconstruct_keys([:a, :x]).should == {}
+ d.deconstruct_keys([:x, :a]).should == {x: 1}
+ end
+
+ it "accepts nil argument and return all the attributes" do
+ klass = Data.define(:x, :y)
+ d = klass.new(1, 2)
+
+ d.deconstruct_keys(nil).should == {x: 1, y: 2}
+ end
+
+ ruby_version_is "4.0" do # https://bugs.ruby-lang.org/issues/21844
+ it "tries to convert a key with #to_str if index is not a String nor a Symbol, but responds to #to_str" do
+ klass = Data.define(:x, :y)
+ d = klass.new(1, 2)
+
+ key = mock("to_str")
+ key.should_receive(:to_str).and_return("y")
+
+ d.deconstruct_keys([key]).should == { "y" => 2 }
+ end
+
+ it "raise an error on argument position number" do
+ klass = Data.define(:x, :y)
+ d = klass.new(1, 2)
+
+ -> {
+ d.deconstruct_keys([0, 1])
+ }.should.raise(TypeError, "0 is not a symbol nor a string")
+ end
+
+ it "raises a TypeError if the conversion with #to_str does not return a String" do
+ klass = Data.define(:x, :y)
+ d = klass.new(1, 2)
+
+ key = mock("to_str")
+ key.should_receive(:to_str).and_return(0)
+
+ -> {
+ d.deconstruct_keys([key])
+ }.should raise_consistent_error(TypeError, /can't convert MockObject into String/)
+ end
+
+ it "raises TypeError if index is not a Symbol and not convertible to String" do
+ klass = Data.define(:x, :y)
+ d = klass.new(1, 2)
+
+ -> {
+ d.deconstruct_keys([0, []])
+ }.should.raise(TypeError, "0 is not a symbol nor a string")
+ end
+ end
+
+ it "raise TypeError if passed anything except nil or array" do
+ klass = Data.define(:x, :y)
+ d = klass.new(1, 2)
+
+ -> { d.deconstruct_keys('x') }.should.raise(TypeError, /expected Array or nil/)
+ -> { d.deconstruct_keys(1) }.should.raise(TypeError, /expected Array or nil/)
+ -> { d.deconstruct_keys(:x) }.should.raise(TypeError, /expected Array or nil/)
+ -> { d.deconstruct_keys({}) }.should.raise(TypeError, /expected Array or nil/)
+ end
+end
diff --git a/spec/ruby/core/data/deconstruct_spec.rb b/spec/ruby/core/data/deconstruct_spec.rb
new file mode 100644
index 0000000000..4ca0b87039
--- /dev/null
+++ b/spec/ruby/core/data/deconstruct_spec.rb
@@ -0,0 +1,8 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe "Data#deconstruct" do
+ it "returns an array of attribute values" do
+ DataSpecs::Measure.new(42, "km").deconstruct.should == [42, "km"]
+ end
+end
diff --git a/spec/ruby/core/data/define_spec.rb b/spec/ruby/core/data/define_spec.rb
new file mode 100644
index 0000000000..c0b4671e39
--- /dev/null
+++ b/spec/ruby/core/data/define_spec.rb
@@ -0,0 +1,34 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe "Data.define" do
+ it "accepts no arguments" do
+ empty_data = Data.define
+ empty_data.members.should == []
+ end
+
+ it "accepts symbols" do
+ movie = Data.define(:title, :year)
+ movie.members.should == [:title, :year]
+ end
+
+ it "accepts strings" do
+ movie = Data.define("title", "year")
+ movie.members.should == [:title, :year]
+ end
+
+ it "accepts a mix of strings and symbols" do
+ movie = Data.define("title", :year, "genre")
+ movie.members.should == [:title, :year, :genre]
+ end
+
+ it "accepts a block" do
+ movie = Data.define(:title, :year) do
+ def title_with_year
+ "#{title} (#{year})"
+ end
+ end
+ movie.members.should == [:title, :year]
+ movie.new("Matrix", 1999).title_with_year.should == "Matrix (1999)"
+ end
+end
diff --git a/spec/ruby/core/data/eql_spec.rb b/spec/ruby/core/data/eql_spec.rb
new file mode 100644
index 0000000000..6958d5de4a
--- /dev/null
+++ b/spec/ruby/core/data/eql_spec.rb
@@ -0,0 +1,63 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe "Data#eql?" do
+ it "returns true if the other is the same object" do
+ a = DataSpecs::Measure.new(42, "km")
+ a.should.eql?(a)
+ end
+
+ it "returns true if the other has all the same fields" do
+ a = DataSpecs::Measure.new(42, "km")
+ b = DataSpecs::Measure.new(42, "km")
+ a.should.eql?(b)
+ end
+
+ it "returns false if the other is a different object or has different fields" do
+ a = DataSpecs::Measure.new(42, "km")
+ b = DataSpecs::Measure.new(42, "mi")
+ a.should_not.eql?(b)
+ end
+
+ it "returns false if other is of a different class" do
+ a = DataSpecs::Measure.new(42, "km")
+ klass = Data.define(*DataSpecs::Measure.members)
+ b = klass.new(42, "km")
+ a.should_not.eql?(b)
+ end
+
+ it "returns false if any corresponding elements are not equal with #eql?" do
+ a = DataSpecs::Measure.new(42, "km")
+ b = DataSpecs::Measure.new(42.0, "mi")
+ a.should_not.eql?(b)
+ end
+
+ context "recursive structure" do
+ it "returns true the other is the same object" do
+ a = DataSpecs::Measure.allocate
+ a.send(:initialize, amount: 42, unit: a)
+
+ a.should.eql?(a)
+ end
+
+ it "returns true if the other has all the same fields" do
+ a = DataSpecs::Measure.allocate
+ a.send(:initialize, amount: 42, unit: a)
+
+ b = DataSpecs::Measure.allocate
+ b.send(:initialize, amount: 42, unit: b)
+
+ a.should.eql?(b)
+ end
+
+ it "returns false if any corresponding elements are not equal with #eql?" do
+ a = DataSpecs::Measure.allocate
+ a.send(:initialize, amount: a, unit: "km")
+
+ b = DataSpecs::Measure.allocate
+ b.send(:initialize, amount: b, unit: "mi")
+
+ a.should_not.eql?(b)
+ end
+ end
+end
diff --git a/spec/ruby/core/data/equal_value_spec.rb b/spec/ruby/core/data/equal_value_spec.rb
new file mode 100644
index 0000000000..d9a0dcff3e
--- /dev/null
+++ b/spec/ruby/core/data/equal_value_spec.rb
@@ -0,0 +1,63 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe "Data#==" do
+ it "returns true if the other is the same object" do
+ a = DataSpecs::Measure.new(42, "km")
+ a.should == a
+ end
+
+ it "returns true if the other has all the same fields" do
+ a = DataSpecs::Measure.new(42, "km")
+ b = DataSpecs::Measure.new(42, "km")
+ a.should == b
+ end
+
+ it "returns false if the other is a different object or has different fields" do
+ a = DataSpecs::Measure.new(42, "km")
+ b = DataSpecs::Measure.new(42, "mi")
+ a.should_not == b
+ end
+
+ it "returns false if other is of a different class" do
+ a = DataSpecs::Measure.new(42, "km")
+ klass = Data.define(*DataSpecs::Measure.members)
+ b = klass.new(42, "km")
+ a.should_not == b
+ end
+
+ it "returns false if any corresponding elements are not equal with #==" do
+ a = DataSpecs::Measure.new(42, "km")
+ b = DataSpecs::Measure.new(42.0, "mi")
+ a.should_not == b
+ end
+
+ context "recursive structure" do
+ it "returns true the other is the same object" do
+ a = DataSpecs::Measure.allocate
+ a.send(:initialize, amount: 42, unit: a)
+
+ a.should == a
+ end
+
+ it "returns true if the other has all the same fields" do
+ a = DataSpecs::Measure.allocate
+ a.send(:initialize, amount: 42, unit: a)
+
+ b = DataSpecs::Measure.allocate
+ b.send(:initialize, amount: 42, unit: b)
+
+ a.should == b
+ end
+
+ it "returns false if any corresponding elements are not equal with #==" do
+ a = DataSpecs::Measure.allocate
+ a.send(:initialize, amount: a, unit: "km")
+
+ b = DataSpecs::Measure.allocate
+ b.send(:initialize, amount: b, unit: "mi")
+
+ a.should_not == b
+ end
+ end
+end
diff --git a/spec/ruby/core/data/fixtures/classes.rb b/spec/ruby/core/data/fixtures/classes.rb
new file mode 100644
index 0000000000..147293ee45
--- /dev/null
+++ b/spec/ruby/core/data/fixtures/classes.rb
@@ -0,0 +1,41 @@
+module DataSpecs
+ if Data.respond_to?(:define)
+ Measure = Data.define(:amount, :unit)
+ Single = Data.define(:value)
+
+ class MeasureWithOverriddenName < Measure
+ def self.name
+ "A"
+ end
+ end
+
+ class SingleWithOverriddenName < Single
+ def self.name
+ "A"
+ end
+ end
+
+ class DataSubclass < Data; end
+
+ MeasureSubclass = Class.new(Measure) do
+ def initialize(amount:, unit:)
+ super
+ end
+ end
+
+ Empty = Data.define()
+
+ DataWithOverriddenInitialize = Data.define(:amount, :unit) do
+ def initialize(*rest, **kw)
+ super
+ ScratchPad.record [:initialize, rest, kw]
+ end
+ end
+
+ Area = Data.define(:width, :height, :area) do
+ def initialize(width:, height:)
+ super(width: width, height: height, area: width * height)
+ end
+ end
+ end
+end
diff --git a/spec/ruby/core/data/hash_spec.rb b/spec/ruby/core/data/hash_spec.rb
new file mode 100644
index 0000000000..bab146c92e
--- /dev/null
+++ b/spec/ruby/core/data/hash_spec.rb
@@ -0,0 +1,25 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe "Data#hash" do
+ it "returns the same integer for objects with the same content" do
+ a = DataSpecs::Measure.new(42, "km")
+ b = DataSpecs::Measure.new(42, "km")
+ a.hash.should == b.hash
+ a.hash.should.instance_of?(Integer)
+ end
+
+ it "returns different hashes for objects with different values" do
+ a = DataSpecs::Measure.new(42, "km")
+ b = DataSpecs::Measure.new(42, "ml")
+ a.hash.should_not == b.hash
+
+ a = DataSpecs::Measure.new(42, "km")
+ b = DataSpecs::Measure.new(13, "km")
+ a.hash.should_not == b.hash
+ end
+
+ it "returns different hashes for different classes" do
+ Data.define(:x).new(1).hash.should != Data.define(:x).new(1).hash
+ end
+end
diff --git a/spec/ruby/core/data/initialize_spec.rb b/spec/ruby/core/data/initialize_spec.rb
new file mode 100644
index 0000000000..0320ca880c
--- /dev/null
+++ b/spec/ruby/core/data/initialize_spec.rb
@@ -0,0 +1,204 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe "Data#initialize" do
+ context "with no members" do
+ ruby_bug "#21819", ""..."4.0.1" do
+ it "is frozen" do
+ data = Data.define
+
+ data.new.should.frozen?
+ end
+ end
+ end
+
+ it "accepts positional arguments" do
+ data = DataSpecs::Measure.new(42, "km")
+
+ data.amount.should == 42
+ data.unit.should == "km"
+ end
+
+ it "accepts alternative positional arguments" do
+ data = DataSpecs::Measure[42, "km"]
+
+ data.amount.should == 42
+ data.unit.should == "km"
+ end
+
+ it "accepts keyword arguments" do
+ data = DataSpecs::Measure.new(amount: 42, unit: "km")
+
+ data.amount.should == 42
+ data.unit.should == "km"
+ end
+
+ it "accepts alternative keyword arguments" do
+ data = DataSpecs::Measure[amount: 42, unit: "km"]
+
+ data.amount.should == 42
+ data.unit.should == "km"
+ end
+
+ it "accepts String keyword arguments" do
+ data = DataSpecs::Measure.new("amount" => 42, "unit" => "km")
+
+ data.amount.should == 42
+ data.unit.should == "km"
+ end
+
+ it "accepts the last entry when a keyword is given as both String and Symbol" do
+ data = DataSpecs::Single.new("value" => -1, value: 42)
+
+ data.value.should == 42
+ end
+
+ it "accepts positional arguments with empty keyword arguments" do
+ data = DataSpecs::Single.new(42, **{})
+
+ data.value.should == 42
+
+ data = DataSpecs::Measure.new(42, "km", **{})
+
+ data.amount.should == 42
+ data.unit.should == "km"
+ end
+
+ it "raises ArgumentError if no arguments are given" do
+ -> {
+ DataSpecs::Measure.new
+ }.should.raise(ArgumentError) { |e|
+ e.message.should.include?("missing keywords: :amount, :unit")
+ }
+ end
+
+ it "raises ArgumentError if at least one argument is missing" do
+ -> {
+ DataSpecs::Measure.new(unit: "km")
+ }.should.raise(ArgumentError) { |e|
+ e.message.should.include?("missing keyword: :amount")
+ }
+ end
+
+ ruby_version_is "4.0" do # https://bugs.ruby-lang.org/issues/21844
+ it "raises ArgumentError if at least one argument is missing and other is provided as both String and Symbol" do
+ -> {
+ DataSpecs::Measure.new(unit: "km", "unit" => "km")
+ }.should.raise(ArgumentError) { |e|
+ e.message.should.include?("missing keyword: :amount")
+ }
+ end
+ end
+
+ it "raises ArgumentError if unknown keyword is given" do
+ -> {
+ DataSpecs::Measure.new(amount: 42, unit: "km", system: "metric")
+ }.should.raise(ArgumentError) { |e|
+ e.message.should.include?("unknown keyword: :system")
+ }
+ end
+
+ ruby_version_is "4.0" do # https://bugs.ruby-lang.org/issues/21844
+ it "raises ArgumentError if unknown keyword is given which is convertable to String" do
+ key = mock("to_str")
+ key.should_receive(:to_str).and_return("system")
+
+ -> {
+ DataSpecs::Measure.new(amount: 42, unit: "km", key => "metric")
+ }.should.raise(ArgumentError) { |e|
+ e.message.should.include?('unknown keyword: "system"')
+ }
+ end
+
+ it "raises TypeError when the keyword is not convertable to String" do
+ -> {
+ DataSpecs::Measure.new(1 => 2)
+ }.should.raise(TypeError) { |e|
+ e.message.should == "1 is not a symbol nor a string"
+ }
+ end
+
+ it "raises TypeError if the conversion with #to_str does not return a String" do
+ klass = Data.define(:x, :y)
+
+ key = mock("to_str")
+ key.should_receive(:to_str).and_return(0)
+
+ -> {
+ klass.new(key => 2)
+ }.should raise_consistent_error(TypeError, /can't convert MockObject into String/)
+ end
+ end
+
+ it "supports super from a subclass" do
+ ms = DataSpecs::MeasureSubclass.new(amount: 1, unit: "km")
+
+ ms.amount.should == 1
+ ms.unit.should == "km"
+ end
+
+ it "supports Data with no fields" do
+ -> { DataSpecs::Empty.new }.should_not.raise
+ end
+
+ it "can be overridden" do
+ ScratchPad.record []
+
+ measure_class = Data.define(:amount, :unit) do
+ def initialize(*, **)
+ super
+ ScratchPad << :initialize
+ end
+ end
+
+ measure_class.new(42, "m")
+ ScratchPad.recorded.should == [:initialize]
+ end
+
+ context "when it is overridden" do
+ it "is called with keyword arguments when given positional arguments" do
+ ScratchPad.clear
+ DataSpecs::DataWithOverriddenInitialize.new(42, "m")
+ ScratchPad.recorded.should == [:initialize, [], {amount: 42, unit: "m"}]
+ end
+
+ it "is called with keyword arguments when given keyword arguments" do
+ ScratchPad.clear
+ DataSpecs::DataWithOverriddenInitialize.new(amount: 42, unit: "m")
+ ScratchPad.recorded.should == [:initialize, [], {amount: 42, unit: "m"}]
+ end
+
+ it "is called with keyword arguments when given alternative positional arguments" do
+ ScratchPad.clear
+ DataSpecs::DataWithOverriddenInitialize[42, "m"]
+ ScratchPad.recorded.should == [:initialize, [], {amount: 42, unit: "m"}]
+ end
+
+ it "is called with keyword arguments when given alternative keyword arguments" do
+ ScratchPad.clear
+ DataSpecs::DataWithOverriddenInitialize[amount: 42, unit: "m"]
+ ScratchPad.recorded.should == [:initialize, [], {amount: 42, unit: "m"}]
+ end
+
+ it "accepts positional arguments with empty keyword arguments" do
+ data = DataSpecs::SingleWithOverriddenName.new(42, **{})
+
+ data.value.should == 42
+
+ data = DataSpecs::MeasureWithOverriddenName.new(42, "km", **{})
+
+ data.amount.should == 42
+ data.unit.should == "km"
+ end
+
+ # See https://github.com/ruby/psych/pull/765
+ it "can be deserialized by calling Data.instance_method(:initialize)" do
+ d1 = DataSpecs::Area.new(width: 2, height: 3)
+ d1.area.should == 6
+
+ d2 = DataSpecs::Area.allocate
+ Data.instance_method(:initialize).bind_call(d2, **d1.to_h)
+ d2.should == d1
+ end
+ end
+end
diff --git a/spec/ruby/core/data/inspect_spec.rb b/spec/ruby/core/data/inspect_spec.rb
new file mode 100644
index 0000000000..e5b9689ca5
--- /dev/null
+++ b/spec/ruby/core/data/inspect_spec.rb
@@ -0,0 +1,8 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe "Data#inspect" do
+ it "is an alias of Data#to_s" do
+ DataSpecs::Measure.instance_method(:inspect).should == DataSpecs::Measure.instance_method(:to_s)
+ end
+end
diff --git a/spec/ruby/core/data/members_spec.rb b/spec/ruby/core/data/members_spec.rb
new file mode 100644
index 0000000000..457a90a0d6
--- /dev/null
+++ b/spec/ruby/core/data/members_spec.rb
@@ -0,0 +1,21 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe "Data#members" do
+ it "returns an array of attribute names" do
+ measure = DataSpecs::Measure.new(amount: 42, unit: 'km')
+ measure.members.should == [:amount, :unit]
+ end
+end
+
+describe "DataClass#members" do
+ it "returns an array of attribute names" do
+ DataSpecs::Measure.members.should == [:amount, :unit]
+ end
+
+ context "class inheriting Data" do
+ it "isn't available in a subclass" do
+ DataSpecs::DataSubclass.should_not.respond_to?(:members)
+ end
+ end
+end
diff --git a/spec/ruby/core/data/to_h_spec.rb b/spec/ruby/core/data/to_h_spec.rb
new file mode 100644
index 0000000000..41925cf3b2
--- /dev/null
+++ b/spec/ruby/core/data/to_h_spec.rb
@@ -0,0 +1,63 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe "Data#to_h" do
+ it "transforms the data object into a hash" do
+ data = DataSpecs::Measure.new(amount: 42, unit: 'km')
+ data.to_h.should == { amount: 42, unit: 'km' }
+ end
+
+ context "with block" do
+ it "transforms [key, value] pairs returned by the block into a hash" do
+ data = DataSpecs::Measure.new(amount: 42, unit: 'km')
+ data.to_h { |key, value| [value, key] }.should == { 42 => :amount, 'km' => :unit }
+ end
+
+ it "passes to a block each pair's key and value as separate arguments" do
+ ScratchPad.record []
+ data = DataSpecs::Measure.new(amount: 42, unit: 'km')
+ data.to_h { |k, v| ScratchPad << [k, v]; [k, v] }
+ ScratchPad.recorded.sort.should == [[:amount, 42], [:unit, 'km']]
+
+ ScratchPad.record []
+ data.to_h { |*args| ScratchPad << args; [args[0], args[1]] }
+ ScratchPad.recorded.sort.should == [[:amount, 42], [:unit, 'km']]
+ end
+
+ it "raises ArgumentError if block returns longer or shorter array" do
+ data = DataSpecs::Measure.new(amount: 42, unit: 'km')
+ -> do
+ data.to_h { |k, v| [k.to_s, v*v, 1] }
+ end.should.raise(ArgumentError, /element has wrong array length/)
+
+ -> do
+ data.to_h { |k, v| [k] }
+ end.should.raise(ArgumentError, /element has wrong array length/)
+ end
+
+ it "raises TypeError if block returns something other than Array" do
+ data = DataSpecs::Measure.new(amount: 42, unit: 'km')
+ -> do
+ data.to_h { |k, v| "not-array" }
+ end.should.raise(TypeError, /wrong element type String/)
+ end
+
+ it "coerces returned pair to Array with #to_ary" do
+ x = mock('x')
+ x.stub!(:to_ary).and_return([:b, 'b'])
+ data = DataSpecs::Measure.new(amount: 42, unit: 'km')
+
+ data.to_h { |k| x }.should == { :b => 'b' }
+ end
+
+ it "does not coerce returned pair to Array with #to_a" do
+ x = mock('x')
+ x.stub!(:to_a).and_return([:b, 'b'])
+ data = DataSpecs::Measure.new(amount: 42, unit: 'km')
+
+ -> do
+ data.to_h { |k| x }
+ end.should.raise(TypeError, /wrong element type MockObject/)
+ end
+ end
+end
diff --git a/spec/ruby/core/data/to_s_spec.rb b/spec/ruby/core/data/to_s_spec.rb
new file mode 100644
index 0000000000..e436c21109
--- /dev/null
+++ b/spec/ruby/core/data/to_s_spec.rb
@@ -0,0 +1,63 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe "Data#to_s" do
+ it "returns a string representation showing members and values" do
+ a = DataSpecs::Measure.new(42, "km")
+ a.to_s.should == '#<data DataSpecs::Measure amount=42, unit="km">'
+ end
+
+ it "returns a string representation without the class name for anonymous structs" do
+ Data.define(:a).new("").to_s.should == '#<data a="">'
+ end
+
+ it "returns a string representation without the class name for structs nested in anonymous classes" do
+ c = Class.new
+ c.class_eval <<~DOC
+ Foo = Data.define(:a)
+ DOC
+
+ c::Foo.new("").to_s.should == '#<data a="">'
+ end
+
+ it "returns a string representation without the class name for structs nested in anonymous modules" do
+ m = Module.new
+ m.class_eval <<~DOC
+ Foo = Data.define(:a)
+ DOC
+
+ m::Foo.new("").to_s.should == '#<data a="">'
+ end
+
+ it "does not call #name method" do
+ struct = DataSpecs::MeasureWithOverriddenName.new(42, "km")
+ struct.to_s.should == '#<data DataSpecs::MeasureWithOverriddenName amount=42, unit="km">'
+ end
+
+ it "does not call #name method when struct is anonymous" do
+ klass = Class.new(DataSpecs::Measure) do
+ def self.name
+ "A"
+ end
+ end
+ struct = klass.new(42, "km")
+ struct.to_s.should == '#<data amount=42, unit="km">'
+ end
+
+ context "recursive structure" do
+ it "returns string representation with recursive attribute replaced with ..." do
+ a = DataSpecs::Measure.allocate
+ a.send(:initialize, amount: 42, unit: a)
+
+ a.to_s.should == "#<data DataSpecs::Measure amount=42, unit=#<data DataSpecs::Measure:...>>"
+ end
+
+ it "returns string representation with recursive attribute replaced with ... when an anonymous class" do
+ klass = Class.new(DataSpecs::Measure)
+ a = klass.allocate
+ a.send(:initialize, amount: 42, unit: a)
+
+ a.to_s.should =~ /#<data amount=42, unit=#<data #<Class:0x.+?>:\.\.\.>>/
+ end
+ end
+end
diff --git a/spec/ruby/core/data/with_spec.rb b/spec/ruby/core/data/with_spec.rb
new file mode 100644
index 0000000000..b74df185c7
--- /dev/null
+++ b/spec/ruby/core/data/with_spec.rb
@@ -0,0 +1,55 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe "Data#with" do
+ it "returns self if given no arguments" do
+ data = DataSpecs::Measure.new(amount: 42, unit: "km")
+ data = data.with.should.equal?(data)
+ end
+
+ it "accepts keyword arguments" do
+ data = DataSpecs::Measure.new(amount: 42, unit: "km")
+ data = data.with(amount: 4, unit: "m")
+
+ data.amount.should == 4
+ data.unit.should == "m"
+ end
+
+ it "accepts String keyword arguments" do
+ data = DataSpecs::Measure.new(amount: 42, unit: "km")
+ data = data.with("amount" => 4, "unit" => "m")
+
+ data.amount.should == 4
+ data.unit.should == "m"
+ end
+
+ it "raises ArgumentError if no keyword arguments are given" do
+ data = DataSpecs::Measure.new(amount: 42, unit: "km")
+
+ -> {
+ data.with(4, "m")
+ }.should.raise(ArgumentError, "wrong number of arguments (given 2, expected 0)")
+ end
+
+ it "does not depend on the Data.new method" do
+ subclass = Class.new(DataSpecs::Measure)
+ data = subclass.new(amount: 42, unit: "km")
+
+ def subclass.new(*)
+ raise "Data.new is called"
+ end
+
+ data_copy = data.with(unit: "m")
+ data_copy.amount.should == 42
+ data_copy.unit.should == "m"
+ end
+
+ it "calls #initialize" do
+ data = DataSpecs::DataWithOverriddenInitialize.new(42, "m")
+ ScratchPad.clear
+
+ data.with(amount: 0)
+
+ ScratchPad.recorded.should == [:initialize, [], {amount: 0, unit: "m"}]
+ end
+end
diff --git a/spec/ruby/core/dir/chdir_spec.rb b/spec/ruby/core/dir/chdir_spec.rb
index f5b0b80d1c..2dc598e2a9 100644
--- a/spec/ruby/core/dir/chdir_spec.rb
+++ b/spec/ruby/core/dir/chdir_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/common', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/common'
describe "Dir.chdir" do
before :all do
@@ -19,14 +19,14 @@ describe "Dir.chdir" do
end
it "defaults to $HOME with no arguments" do
- if ENV['HOME']
- Dir.chdir
- current_dir = Dir.pwd
+ skip "$HOME not valid directory" unless ENV['HOME'] && File.directory?(ENV['HOME'])
- Dir.chdir(ENV['HOME'])
- home = Dir.pwd
- current_dir.should == home
- end
+ Dir.chdir
+ current_dir = Dir.pwd
+
+ Dir.chdir(ENV['HOME'])
+ home = Dir.pwd
+ current_dir.should == home
end
it "changes to the specified directory" do
@@ -70,6 +70,8 @@ describe "Dir.chdir" do
end
it "defaults to the home directory when given a block but no argument" do
+ skip "$HOME not valid directory" unless ENV['HOME'] && File.directory?(ENV['HOME'])
+
# Windows will return a path with forward slashes for ENV["HOME"] so we have
# to compare the route representations returned by Dir.chdir.
current_dir = ""
@@ -88,26 +90,26 @@ describe "Dir.chdir" do
end
it "raises an Errno::ENOENT if the directory does not exist" do
- lambda { Dir.chdir DirSpecs.nonexistent }.should raise_error(Errno::ENOENT)
- lambda { Dir.chdir(DirSpecs.nonexistent) { } }.should raise_error(Errno::ENOENT)
+ -> { Dir.chdir DirSpecs.nonexistent }.should.raise(Errno::ENOENT)
+ -> { Dir.chdir(DirSpecs.nonexistent) { } }.should.raise(Errno::ENOENT)
end
it "raises an Errno::ENOENT if the original directory no longer exists" do
- dir1 = tmp('/testdir1')
- dir2 = tmp('/testdir2')
- File.exist?(dir1).should == false
- File.exist?(dir2).should == false
+ dir1 = tmp('testdir1')
+ dir2 = tmp('testdir2')
+ Dir.should_not.exist?(dir1)
+ Dir.should_not.exist?(dir2)
Dir.mkdir dir1
Dir.mkdir dir2
begin
- lambda {
+ -> {
Dir.chdir dir1 do
Dir.chdir(dir2) { Dir.unlink dir1 }
end
- }.should raise_error(Errno::ENOENT)
+ }.should.raise(Errno::ENOENT)
ensure
- Dir.unlink dir1 if File.exist?(dir1)
- Dir.unlink dir2 if File.exist?(dir2)
+ Dir.unlink dir1 if Dir.exist?(dir1)
+ Dir.unlink dir2 if Dir.exist?(dir2)
end
end
@@ -122,3 +124,95 @@ describe "Dir.chdir" do
Dir.pwd.should == @original
end
end
+
+describe "Dir#chdir" do
+ before :all do
+ DirSpecs.create_mock_dirs
+ end
+
+ after :all do
+ DirSpecs.delete_mock_dirs
+ end
+
+ before :each do
+ @original = Dir.pwd
+ end
+
+ after :each do
+ Dir.chdir(@original)
+ end
+
+ it "changes the current working directory to self" do
+ dir = Dir.new(DirSpecs.mock_dir)
+ dir.chdir
+ Dir.pwd.should == DirSpecs.mock_dir
+ ensure
+ dir.close
+ end
+
+ it "changes the current working directory to self for duration of the block when a block is given" do
+ dir = Dir.new(DirSpecs.mock_dir)
+ pwd_in_block = nil
+
+ dir.chdir { pwd_in_block = Dir.pwd }
+
+ pwd_in_block.should == DirSpecs.mock_dir
+ Dir.pwd.should == @original
+ ensure
+ dir.close
+ end
+
+ it "returns 0 when successfully changing directory" do
+ dir = Dir.new(DirSpecs.mock_dir)
+ dir.chdir.should == 0
+ ensure
+ dir.close
+ end
+
+ it "returns the value of the block when a block is given" do
+ dir = Dir.new(DirSpecs.mock_dir)
+ dir.chdir { :block_value }.should == :block_value
+ ensure
+ dir.close
+ end
+
+ platform_is_not :windows do
+ it "does not raise an Errno::ENOENT if the original directory no longer exists" do
+ dir_name1 = tmp('testdir1')
+ dir_name2 = tmp('testdir2')
+ Dir.should_not.exist?(dir_name1)
+ Dir.should_not.exist?(dir_name2)
+ Dir.mkdir dir_name1
+ Dir.mkdir dir_name2
+
+ dir2 = Dir.new(dir_name2)
+
+ begin
+ Dir.chdir(dir_name1) do
+ dir2.chdir { Dir.unlink dir_name1 }
+ end
+ Dir.pwd.should == @original
+ ensure
+ Dir.unlink dir_name1 if Dir.exist?(dir_name1)
+ Dir.unlink dir_name2 if Dir.exist?(dir_name2)
+ end
+ ensure
+ dir2.close
+ end
+ end
+
+ it "always returns to the original directory when given a block" do
+ dir = Dir.new(DirSpecs.mock_dir)
+
+ begin
+ dir.chdir do
+ raise StandardError, "something bad happened"
+ end
+ rescue StandardError
+ end
+
+ Dir.pwd.should == @original
+ ensure
+ dir.close
+ end
+end
diff --git a/spec/ruby/core/dir/children_spec.rb b/spec/ruby/core/dir/children_spec.rb
new file mode 100644
index 0000000000..6e6da1dd44
--- /dev/null
+++ b/spec/ruby/core/dir/children_spec.rb
@@ -0,0 +1,147 @@
+# encoding: utf-8
+
+require_relative '../../spec_helper'
+require_relative 'fixtures/common'
+
+describe "Dir.children" do
+ before :all do
+ DirSpecs.create_mock_dirs
+ end
+
+ before :each do
+ @internal = Encoding.default_internal
+ end
+
+ after :all do
+ DirSpecs.delete_mock_dirs
+ end
+
+ after :each do
+ Encoding.default_internal = @internal
+ end
+
+ it "returns an Array of filenames in an existing directory including dotfiles" do
+ a = Dir.children(DirSpecs.mock_dir).sort
+
+ a.should == DirSpecs.expected_paths - %w[. ..]
+
+ a = Dir.children("#{DirSpecs.mock_dir}/deeply/nested").sort
+ a.should == %w|.dotfile.ext directory|
+ end
+
+ it "calls #to_path on non-String arguments" do
+ p = mock('path')
+ p.should_receive(:to_path).and_return(DirSpecs.mock_dir)
+ Dir.children(p)
+ end
+
+ it "accepts an options Hash" do
+ a = Dir.children("#{DirSpecs.mock_dir}/deeply/nested", encoding: "utf-8").sort
+ a.should == %w|.dotfile.ext directory|
+ end
+
+ it "returns children encoded with the filesystem encoding by default" do
+ # This spec depends on the locale not being US-ASCII because if it is, the
+ # children that are not ascii_only? will be BINARY encoded.
+ children = Dir.children(File.join(DirSpecs.mock_dir, 'special')).sort
+ encoding = Encoding.find("filesystem")
+ encoding = Encoding::BINARY if encoding == Encoding::US_ASCII
+ platform_is_not :windows do
+ children.should.include?("ã“ã‚“ã«ã¡ã¯.txt".dup.force_encoding(encoding))
+ end
+ children.first.encoding.should.equal?(Encoding.find("filesystem"))
+ end
+
+ it "returns children encoded with the specified encoding" do
+ dir = File.join(DirSpecs.mock_dir, 'special')
+ children = Dir.children(dir, encoding: "euc-jp").sort
+ children.first.encoding.should.equal?(Encoding::EUC_JP)
+ end
+
+ it "returns children transcoded to the default internal encoding" do
+ Encoding.default_internal = Encoding::EUC_KR
+ children = Dir.children(File.join(DirSpecs.mock_dir, 'special')).sort
+ children.first.encoding.should.equal?(Encoding::EUC_KR)
+ end
+
+ it "raises a SystemCallError if called with a nonexistent directory" do
+ -> { Dir.children DirSpecs.nonexistent }.should.raise(SystemCallError)
+ end
+end
+
+describe "Dir#children" do
+ before :all do
+ DirSpecs.create_mock_dirs
+ end
+
+ before :each do
+ @internal = Encoding.default_internal
+ end
+
+ after :all do
+ DirSpecs.delete_mock_dirs
+ end
+
+ after :each do
+ Encoding.default_internal = @internal
+ @dir.close if @dir
+ end
+
+ it "returns an Array of filenames in an existing directory including dotfiles" do
+ @dir = Dir.new(DirSpecs.mock_dir)
+ a = @dir.children.sort
+ @dir.close
+
+ a.should == DirSpecs.expected_paths - %w[. ..]
+
+ @dir = Dir.new("#{DirSpecs.mock_dir}/deeply/nested")
+ a = @dir.children.sort
+ a.should == %w|.dotfile.ext directory|
+ end
+
+ it "accepts an encoding keyword for the encoding of the entries" do
+ @dir = Dir.new("#{DirSpecs.mock_dir}/deeply/nested", encoding: "utf-8")
+ dirs = @dir.to_a.sort
+ dirs.each { |d| d.encoding.should == Encoding::UTF_8 }
+ end
+
+ it "returns children encoded with the filesystem encoding by default" do
+ # This spec depends on the locale not being US-ASCII because if it is, the
+ # children that are not ascii_only? will be BINARY encoded.
+ @dir = Dir.new(File.join(DirSpecs.mock_dir, 'special'))
+ children = @dir.children.sort
+ encoding = Encoding.find("filesystem")
+ encoding = Encoding::BINARY if encoding == Encoding::US_ASCII
+ platform_is_not :windows do
+ children.should.include?("ã“ã‚“ã«ã¡ã¯.txt".dup.force_encoding(encoding))
+ end
+ children.first.encoding.should.equal?(Encoding.find("filesystem"))
+ end
+
+ it "returns children encoded with the specified encoding" do
+ path = File.join(DirSpecs.mock_dir, 'special')
+ @dir = Dir.new(path, encoding: "euc-jp")
+ children = @dir.children.sort
+ children.first.encoding.should.equal?(Encoding::EUC_JP)
+ end
+
+ it "returns children transcoded to the default internal encoding" do
+ Encoding.default_internal = Encoding::EUC_KR
+ @dir = Dir.new(File.join(DirSpecs.mock_dir, 'special'))
+ children = @dir.children.sort
+ children.first.encoding.should.equal?(Encoding::EUC_KR)
+ end
+
+ it "returns the same result when called repeatedly" do
+ @dir = Dir.open DirSpecs.mock_dir
+
+ a = []
+ @dir.each {|dir| a << dir}
+
+ b = []
+ @dir.each {|dir| b << dir}
+
+ a.sort.should == b.sort
+ a.sort.should == DirSpecs.expected_paths
+ end
+end
diff --git a/spec/ruby/core/dir/chroot_spec.rb b/spec/ruby/core/dir/chroot_spec.rb
index 1afe254957..79ad9759b0 100644
--- a/spec/ruby/core/dir/chroot_spec.rb
+++ b/spec/ruby/core/dir/chroot_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/common', __FILE__)
-require File.expand_path('../shared/chroot', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/common'
+require_relative 'shared/chroot'
platform_is_not :windows do
as_superuser do
@@ -9,7 +9,7 @@ platform_is_not :windows do
end
end
- platform_is_not :cygwin do
+ platform_is_not :cygwin, :android do
as_user do
describe "Dir.chroot as regular user" do
before :all do
@@ -21,17 +21,17 @@ platform_is_not :windows do
end
it "raises an Errno::EPERM exception if the directory exists" do
- lambda { Dir.chroot('.') }.should raise_error(Errno::EPERM)
+ -> { Dir.chroot('.') }.should.raise(Errno::EPERM)
end
it "raises a SystemCallError if the directory doesn't exist" do
- lambda { Dir.chroot('xgwhwhsjai2222jg') }.should raise_error(SystemCallError)
+ -> { Dir.chroot('xgwhwhsjai2222jg') }.should.raise(SystemCallError)
end
it "calls #to_path on non-String argument" do
p = mock('path')
p.should_receive(:to_path).and_return('.')
- lambda { Dir.chroot(p) }.should raise_error
+ -> { Dir.chroot(p) }.should.raise(Errno::EPERM)
end
end
end
diff --git a/spec/ruby/core/dir/close_spec.rb b/spec/ruby/core/dir/close_spec.rb
index 7b08ec5ee8..9902d98934 100644
--- a/spec/ruby/core/dir/close_spec.rb
+++ b/spec/ruby/core/dir/close_spec.rb
@@ -1,9 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/common', __FILE__)
-ruby_version_is ''...'2.3' do
- require File.expand_path('../shared/closed', __FILE__)
-end
-
+require_relative '../../spec_helper'
+require_relative 'fixtures/common'
describe "Dir#close" do
before :all do
DirSpecs.create_mock_dirs
@@ -13,17 +9,45 @@ describe "Dir#close" do
DirSpecs.delete_mock_dirs
end
- ruby_version_is ''...'2.3' do
- it_behaves_like :dir_closed, :close
+ it "does not raise an IOError even if the Dir instance is closed" do
+ dir = Dir.open DirSpecs.mock_dir
+ dir.close.should == nil
+ dir.close.should == nil
+
+ platform_is_not :windows do
+ -> { dir.fileno }.should.raise(IOError, /closed directory/)
+ end
end
- ruby_version_is '2.3' do
- it "does not raise an IOError even if the Dir instance is closed" do
- dir = Dir.open DirSpecs.mock_dir
- dir.close
- lambda {
+ it "returns nil" do
+ dir = Dir.open DirSpecs.mock_dir
+ dir.close.should == nil
+ end
+
+ ruby_version_is ''...'3.4' do
+ platform_is_not :windows do
+ it "does not raise an error even if the file descriptor is closed with another Dir instance" do
+ dir = Dir.open DirSpecs.mock_dir
+ dir_new = Dir.for_fd(dir.fileno)
+
dir.close
- }.should_not raise_error(IOError)
+ dir_new.close
+
+ -> { dir.fileno }.should.raise(IOError, /closed directory/)
+ -> { dir_new.fileno }.should.raise(IOError, /closed directory/)
+ end
+ end
+ end
+
+ ruby_version_is '3.4' do
+ platform_is_not :windows do
+ it "raises an error if the file descriptor is closed with another Dir instance" do
+ dir = Dir.open DirSpecs.mock_dir
+ dir_new = Dir.for_fd(dir.fileno)
+ dir.close
+
+ -> { dir_new.close }.should.raise(Errno::EBADF, 'Bad file descriptor - closedir')
+ end
end
end
end
diff --git a/spec/ruby/core/dir/delete_spec.rb b/spec/ruby/core/dir/delete_spec.rb
index 5f36956839..2dbd461c94 100644
--- a/spec/ruby/core/dir/delete_spec.rb
+++ b/spec/ruby/core/dir/delete_spec.rb
@@ -1,6 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/common', __FILE__)
-require File.expand_path('../shared/delete', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/common'
describe "Dir.delete" do
before :all do
@@ -11,5 +10,55 @@ describe "Dir.delete" do
DirSpecs.delete_mock_dirs
end
- it_behaves_like :dir_delete, :delete
+ before :each do
+ DirSpecs.rmdir_dirs true
+ end
+
+ after :each do
+ DirSpecs.rmdir_dirs false
+ end
+
+ it "removes empty directories" do
+ Dir.delete(DirSpecs.mock_rmdir("empty")).should == 0
+ end
+
+ it "calls #to_path on non-String arguments" do
+ p = mock('path')
+ p.should_receive(:to_path).and_return(DirSpecs.mock_rmdir("empty"))
+ Dir.delete(p)
+ end
+
+ it "raises an Errno::ENOTEMPTY when trying to remove a nonempty directory" do
+ -> do
+ Dir.delete DirSpecs.mock_rmdir("nonempty")
+ end.should.raise(Errno::ENOTEMPTY)
+ end
+
+ it "raises an Errno::ENOENT when trying to remove a non-existing directory" do
+ -> do
+ Dir.delete DirSpecs.nonexistent
+ end.should.raise(Errno::ENOENT)
+ end
+
+ it "raises an Errno::ENOTDIR when trying to remove a non-directory" do
+ file = DirSpecs.mock_rmdir("nonempty/regular")
+ touch(file)
+ -> do
+ Dir.delete file
+ end.should.raise(Errno::ENOTDIR)
+ end
+
+ # this won't work on Windows, since chmod(0000) does not remove all permissions
+ platform_is_not :windows do
+ as_user do
+ it "raises an Errno::EACCES if lacking adequate permissions to remove the directory" do
+ parent = DirSpecs.mock_rmdir("noperm")
+ child = DirSpecs.mock_rmdir("noperm", "child")
+ File.chmod(0000, parent)
+ -> do
+ Dir.delete child
+ end.should.raise(Errno::EACCES)
+ end
+ end
+ end
end
diff --git a/spec/ruby/core/dir/dir_spec.rb b/spec/ruby/core/dir/dir_spec.rb
index 4923445bed..7d55ea26d4 100644
--- a/spec/ruby/core/dir/dir_spec.rb
+++ b/spec/ruby/core/dir/dir_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Dir" do
it "includes Enumerable" do
diff --git a/spec/ruby/core/dir/each_child_spec.rb b/spec/ruby/core/dir/each_child_spec.rb
new file mode 100644
index 0000000000..4d6575df39
--- /dev/null
+++ b/spec/ruby/core/dir/each_child_spec.rb
@@ -0,0 +1,119 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/common'
+
+describe "Dir.each_child" do
+ before :all do
+ DirSpecs.create_mock_dirs
+ end
+
+ after :all do
+ DirSpecs.delete_mock_dirs
+ end
+
+ it "accepts an encoding keyword for the encoding of the entries" do
+ dirs = Dir.each_child("#{DirSpecs.mock_dir}/deeply/nested", encoding: "utf-8").to_a.sort
+ dirs.each {|dir| dir.encoding.should == Encoding::UTF_8}
+ end
+
+ it "yields all names in an existing directory to the provided block" do
+ a, b = [], []
+
+ Dir.each_child(DirSpecs.mock_dir) {|f| a << f}
+ Dir.each_child("#{DirSpecs.mock_dir}/deeply/nested") {|f| b << f}
+
+ a.sort.should == DirSpecs.expected_paths - %w[. ..]
+ b.sort.should == %w|.dotfile.ext directory|
+ end
+
+ it "returns nil when successful" do
+ Dir.each_child(DirSpecs.mock_dir) {|f| f}.should == nil
+ end
+
+ it "calls #to_path on non-String arguments" do
+ p = mock('path')
+ p.should_receive(:to_path).and_return(DirSpecs.mock_dir)
+ Dir.each_child(p).to_a
+ end
+
+ it "raises a SystemCallError if passed a nonexistent directory" do
+ -> { Dir.each_child(DirSpecs.nonexistent) {} }.should.raise(SystemCallError)
+ end
+
+ describe "when no block is given" do
+ it "returns an Enumerator" do
+ Dir.each_child(DirSpecs.mock_dir).should.instance_of?(Enumerator)
+ Dir.each_child(DirSpecs.mock_dir).to_a.sort.should == DirSpecs.expected_paths - %w[. ..]
+ end
+
+ describe "returned Enumerator" do
+ describe "size" do
+ it "should return nil" do
+ Dir.each_child(DirSpecs.mock_dir).size.should == nil
+ end
+ end
+ end
+ end
+end
+
+describe "Dir#each_child" do
+ before :all do
+ DirSpecs.create_mock_dirs
+ end
+
+ after :all do
+ DirSpecs.delete_mock_dirs
+ end
+
+ after :each do
+ @dir.close if @dir
+ end
+
+ it "yields all names in an existing directory to the provided block" do
+ a, b = [], []
+ @dir = Dir.new(DirSpecs.mock_dir)
+ @dir2 = Dir.new("#{DirSpecs.mock_dir}/deeply/nested")
+
+ @dir.each_child { |f| a << f }
+ @dir2.each_child { |f| b << f }
+ @dir2.close
+
+ a.sort.should == DirSpecs.expected_paths - %w|. ..|
+ b.sort.should == %w|.dotfile.ext directory|
+ end
+
+ it "returns self when successful" do
+ @dir = Dir.new(DirSpecs.mock_dir)
+ @dir.each_child { |f| f }.should == @dir
+ end
+
+ it "returns the same result when called repeatedly" do
+ @dir = Dir.open DirSpecs.mock_dir
+
+ a = []
+ @dir.each {|dir| a << dir}
+
+ b = []
+ @dir.each {|dir| b << dir}
+
+ a.sort.should == b.sort
+ a.sort.should == DirSpecs.expected_paths
+ end
+
+ describe "when no block is given" do
+ it "returns an Enumerator" do
+ @dir = Dir.new(DirSpecs.mock_dir)
+
+ @dir.each_child.should.instance_of?(Enumerator)
+ @dir.each_child.to_a.sort.should == DirSpecs.expected_paths - %w|. ..|
+ end
+
+ describe "returned Enumerator" do
+ describe "size" do
+ it "should return nil" do
+ @dir = Dir.new(DirSpecs.mock_dir)
+ @dir.each_child.size.should == nil
+ end
+ end
+ end
+ end
+end
diff --git a/spec/ruby/core/dir/each_spec.rb b/spec/ruby/core/dir/each_spec.rb
index 534691ff58..e997e340b1 100644
--- a/spec/ruby/core/dir/each_spec.rb
+++ b/spec/ruby/core/dir/each_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/common', __FILE__)
-require File.expand_path('../shared/closed', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/common'
+require_relative 'shared/closed'
describe "Dir#each" do
before :all do
@@ -32,12 +32,23 @@ describe "Dir#each" do
@dir.each {}.should == @dir
@dir.read.should == nil
@dir.rewind
- ls.should include(@dir.read)
+ ls.should.include?(@dir.read)
+ end
+
+ it "returns the same result when called repeatedly" do
+ a = []
+ @dir.each {|dir| a << dir}
+
+ b = []
+ @dir.each {|dir| b << dir}
+
+ a.sort.should == b.sort
+ a.sort.should == DirSpecs.expected_paths
end
describe "when no block is given" do
it "returns an Enumerator" do
- @dir.each.should be_an_instance_of(Enumerator)
+ @dir.each.should.instance_of?(Enumerator)
@dir.each.to_a.sort.should == DirSpecs.expected_paths
end
diff --git a/spec/ruby/core/dir/element_reference_spec.rb b/spec/ruby/core/dir/element_reference_spec.rb
index de379d75ac..092114bed4 100644
--- a/spec/ruby/core/dir/element_reference_spec.rb
+++ b/spec/ruby/core/dir/element_reference_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/common', __FILE__)
-require File.expand_path('../shared/glob', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/common'
+require_relative 'shared/glob'
describe "Dir.[]" do
it_behaves_like :dir_glob, :[]
diff --git a/spec/ruby/core/dir/empty_spec.rb b/spec/ruby/core/dir/empty_spec.rb
index 861a538f84..3b6b2bac85 100644
--- a/spec/ruby/core/dir/empty_spec.rb
+++ b/spec/ruby/core/dir/empty_spec.rb
@@ -1,33 +1,31 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
-ruby_version_is "2.4" do
- describe "Dir.empty?" do
- before :all do
- @empty_dir = tmp("empty_dir")
- mkdir_p @empty_dir
- end
+describe "Dir.empty?" do
+ before :all do
+ @empty_dir = tmp("empty_dir")
+ mkdir_p @empty_dir
+ end
- after :all do
- rm_r @empty_dir
- end
+ after :all do
+ rm_r @empty_dir
+ end
- it "returns true for empty directories" do
- result = Dir.empty? @empty_dir
- result.should be_true
- end
+ it "returns true for empty directories" do
+ result = Dir.empty? @empty_dir
+ result.should == true
+ end
- it "returns false for non-empty directories" do
- result = Dir.empty? __dir__
- result.should be_false
- end
+ it "returns false for non-empty directories" do
+ result = Dir.empty? __dir__
+ result.should == false
+ end
- it "returns false for a non-directory" do
- result = Dir.empty? __FILE__
- result.should be_false
- end
+ it "returns false for a non-directory" do
+ result = Dir.empty? __FILE__
+ result.should == false
+ end
- it "raises ENOENT for nonexistent directories" do
- lambda { Dir.empty? tmp("nonexistent") }.should raise_error(Errno::ENOENT)
- end
+ it "raises ENOENT for nonexistent directories" do
+ -> { Dir.empty? tmp("nonexistent") }.should.raise(Errno::ENOENT)
end
end
diff --git a/spec/ruby/core/dir/entries_spec.rb b/spec/ruby/core/dir/entries_spec.rb
index 8a31ab4b4a..f3ca49b26d 100644
--- a/spec/ruby/core/dir/entries_spec.rb
+++ b/spec/ruby/core/dir/entries_spec.rb
@@ -1,7 +1,7 @@
# encoding: utf-8
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/common', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/common'
describe "Dir.entries" do
before :all do
@@ -35,36 +35,36 @@ describe "Dir.entries" do
Dir.entries(p)
end
- it "accepts an options Hash" do
- a = Dir.entries("#{DirSpecs.mock_dir}/deeply/nested", encoding: "utf-8").sort
- a.should == %w|. .. .dotfile.ext directory|
+ it "accepts an encoding keyword for the encoding of the entries" do
+ dirs = Dir.entries("#{DirSpecs.mock_dir}/deeply/nested", encoding: "utf-8").to_a.sort
+ dirs.each {|dir| dir.encoding.should == Encoding::UTF_8}
end
it "returns entries encoded with the filesystem encoding by default" do
# This spec depends on the locale not being US-ASCII because if it is, the
- # entries that are not ascii_only? will be ASCII-8BIT encoded.
+ # entries that are not ascii_only? will be BINARY encoded.
entries = Dir.entries(File.join(DirSpecs.mock_dir, 'special')).sort
encoding = Encoding.find("filesystem")
- encoding = Encoding::ASCII_8BIT if encoding == Encoding::US_ASCII
+ encoding = Encoding::BINARY if encoding == Encoding::US_ASCII
platform_is_not :windows do
- entries.should include("ã“ã‚“ã«ã¡ã¯.txt".force_encoding(encoding))
+ entries.should.include?("ã“ã‚“ã«ã¡ã¯.txt".dup.force_encoding(encoding))
end
- entries.first.encoding.should equal(Encoding.find("filesystem"))
+ entries.first.encoding.should.equal?(Encoding.find("filesystem"))
end
it "returns entries encoded with the specified encoding" do
dir = File.join(DirSpecs.mock_dir, 'special')
entries = Dir.entries(dir, encoding: "euc-jp").sort
- entries.first.encoding.should equal(Encoding::EUC_JP)
+ entries.first.encoding.should.equal?(Encoding::EUC_JP)
end
it "returns entries transcoded to the default internal encoding" do
Encoding.default_internal = Encoding::EUC_KR
entries = Dir.entries(File.join(DirSpecs.mock_dir, 'special')).sort
- entries.first.encoding.should equal(Encoding::EUC_KR)
+ entries.first.encoding.should.equal?(Encoding::EUC_KR)
end
- it "raises a SystemCallError if called with a nonexistent diretory" do
- lambda { Dir.entries DirSpecs.nonexistent }.should raise_error(SystemCallError)
+ it "raises a SystemCallError if called with a nonexistent directory" do
+ -> { Dir.entries DirSpecs.nonexistent }.should.raise(SystemCallError)
end
end
diff --git a/spec/ruby/core/dir/exist_spec.rb b/spec/ruby/core/dir/exist_spec.rb
index 194284b5a0..05ad67dd03 100644
--- a/spec/ruby/core/dir/exist_spec.rb
+++ b/spec/ruby/core/dir/exist_spec.rb
@@ -1,6 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/common', __FILE__)
-require File.expand_path('../shared/exist', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/common'
describe "Dir.exist?" do
before :all do
@@ -11,5 +10,65 @@ describe "Dir.exist?" do
DirSpecs.delete_mock_dirs
end
- it_behaves_like(:dir_exist, :exist?)
+ it "returns true if the given directory exists" do
+ Dir.exist?(__dir__).should == true
+ end
+
+ it "returns true for '.'" do
+ Dir.exist?('.').should == true
+ end
+
+ it "returns true for '..'" do
+ Dir.exist?('..').should == true
+ end
+
+ it "understands non-ASCII paths" do
+ subdir = File.join(tmp("\u{9876}\u{665}"))
+ Dir.exist?(subdir).should == false
+ Dir.mkdir(subdir)
+ Dir.exist?(subdir).should == true
+ Dir.rmdir(subdir)
+ end
+
+ it "understands relative paths" do
+ Dir.exist?(__dir__ + '/../').should == true
+ end
+
+ it "returns false if the given directory doesn't exist" do
+ Dir.exist?('y26dg27n2nwjs8a/').should == false
+ end
+
+ it "doesn't require the name to have a trailing slash" do
+ dir = __dir__
+ dir.sub!(/\/$/,'')
+ Dir.exist?(dir).should == true
+ end
+
+ it "doesn't expand paths" do
+ skip "$HOME not valid directory" unless ENV['HOME'] && File.directory?(ENV['HOME'])
+ Dir.exist?(File.expand_path('~')).should == true
+ Dir.exist?('~').should == false
+ end
+
+ it "returns false if the argument exists but is a file" do
+ File.should.exist?(__FILE__)
+ Dir.exist?(__FILE__).should == false
+ end
+
+ it "doesn't set $! when file doesn't exist" do
+ Dir.exist?("/path/to/non/existent/dir")
+ $!.should == nil
+ end
+
+ it "calls #to_path on non String arguments" do
+ p = mock('path')
+ p.should_receive(:to_path).and_return(__dir__)
+ Dir.exist?(p)
+ end
+end
+
+describe "Dir.exists?" do
+ it "has been removed" do
+ Dir.should_not.respond_to?(:exists?)
+ end
end
diff --git a/spec/ruby/core/dir/exists_spec.rb b/spec/ruby/core/dir/exists_spec.rb
deleted file mode 100644
index 002506a22f..0000000000
--- a/spec/ruby/core/dir/exists_spec.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/common', __FILE__)
-require File.expand_path('../shared/exist', __FILE__)
-
-describe "Dir.exists?" do
- before :all do
- DirSpecs.create_mock_dirs
- end
-
- after :all do
- DirSpecs.delete_mock_dirs
- end
-
- it_behaves_like(:dir_exist, :exists?)
-end
diff --git a/spec/ruby/core/dir/fchdir_spec.rb b/spec/ruby/core/dir/fchdir_spec.rb
new file mode 100644
index 0000000000..bd1a92b05e
--- /dev/null
+++ b/spec/ruby/core/dir/fchdir_spec.rb
@@ -0,0 +1,71 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/common'
+
+platform_is_not :windows do
+ describe "Dir.fchdir" do
+ before :all do
+ DirSpecs.create_mock_dirs
+ end
+
+ after :all do
+ DirSpecs.delete_mock_dirs
+ end
+
+ before :each do
+ @original = Dir.pwd
+ end
+
+ after :each do
+ Dir.chdir(@original)
+ end
+
+ it "changes the current working directory to the directory specified by the integer file descriptor" do
+ dir = Dir.new(DirSpecs.mock_dir)
+ Dir.fchdir dir.fileno
+ Dir.pwd.should == DirSpecs.mock_dir
+ ensure
+ dir.close
+ end
+
+ it "returns 0 when successfully changing directory" do
+ dir = Dir.new(DirSpecs.mock_dir)
+ Dir.fchdir(dir.fileno).should == 0
+ ensure
+ dir.close
+ end
+
+ it "returns the value of the block when a block is given" do
+ dir = Dir.new(DirSpecs.mock_dir)
+ Dir.fchdir(dir.fileno) { :block_value }.should == :block_value
+ ensure
+ dir.close
+ end
+
+ it "changes to the specified directory for the duration of the block" do
+ dir = Dir.new(DirSpecs.mock_dir)
+ Dir.fchdir(dir.fileno) { Dir.pwd }.should == DirSpecs.mock_dir
+ Dir.pwd.should == @original
+ ensure
+ dir.close
+ end
+
+ it "raises a SystemCallError if the file descriptor given is not valid" do
+ -> { Dir.fchdir(-1) }.should.raise(SystemCallError, "Bad file descriptor - fchdir")
+ -> { Dir.fchdir(-1) { } }.should.raise(SystemCallError, "Bad file descriptor - fchdir")
+ end
+
+ it "raises a SystemCallError if the file descriptor given is not for a directory" do
+ -> { Dir.fchdir $stdout.fileno }.should.raise(SystemCallError, /(Not a directory|Invalid argument) - fchdir/)
+ -> { Dir.fchdir($stdout.fileno) { } }.should.raise(SystemCallError, /(Not a directory|Invalid argument) - fchdir/)
+ end
+ end
+end
+
+platform_is :windows do
+ describe "Dir.fchdir" do
+ it "raises NotImplementedError" do
+ -> { Dir.fchdir 1 }.should.raise(NotImplementedError)
+ -> { Dir.fchdir(1) { } }.should.raise(NotImplementedError)
+ end
+ end
+end
diff --git a/spec/ruby/core/dir/fileno_spec.rb b/spec/ruby/core/dir/fileno_spec.rb
index cf8b811e3b..3b563eb18f 100644
--- a/spec/ruby/core/dir/fileno_spec.rb
+++ b/spec/ruby/core/dir/fileno_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/common', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/common'
has_dir_fileno = begin
dir = Dir.new('.')
@@ -27,11 +27,11 @@ describe "Dir#fileno" do
if has_dir_fileno
it "returns the file descriptor of the dir" do
- @dir.fileno.should be_kind_of(Fixnum)
+ @dir.fileno.should.is_a?(Integer)
end
else
it "raises an error when not implemented on the platform" do
- lambda { @dir.fileno }.should raise_error(NotImplementedError)
+ -> { @dir.fileno }.should.raise(NotImplementedError)
end
end
end
diff --git a/spec/ruby/core/dir/fixtures/common.rb b/spec/ruby/core/dir/fixtures/common.rb
index f6708b04f7..cfec91f68f 100644
--- a/spec/ruby/core/dir/fixtures/common.rb
+++ b/spec/ruby/core/dir/fixtures/common.rb
@@ -22,7 +22,7 @@ module DirSpecs
[0xe9].pack('U')
].each do |dir|
begin
- Dir.rmdir dir
+ Dir.rmdir mock_dir(dir)
rescue
end
end
@@ -36,6 +36,8 @@ module DirSpecs
.dotfile
.dotsubdir/.dotfile
.dotsubdir/nondotfile
+ nested/.dotsubir/.dotfile
+ nested/.dotsubir/nondotfile
deeply/.dotfile
deeply/nested/.dotfile.ext
@@ -79,6 +81,8 @@ module DirSpecs
special/}
special/test{1}/file[1]
+ special/{}/special
+ special/test\ +()[]{}/hello_world.erb
]
platform_is_not :windows do
@@ -89,19 +93,40 @@ module DirSpecs
special/|
special/ã“ã‚“ã«ã¡ã¯.txt
+ special/\a
]
+ @mock_dir_files << "special/_\u{1f60e}.erb"
end
end
@mock_dir_files
end
+ def self.mock_dir_links
+ unless @mock_dir_links
+ @mock_dir_links = []
+ platform_is_not :windows do
+ @mock_dir_links += [
+ ['special/ln', 'subdir_one']
+ ]
+ end
+ end
+ @mock_dir_links
+ end
+
def self.create_mock_dirs
+ delete_mock_dirs
mock_dir_files.each do |name|
file = File.join mock_dir, name
mkdir_p File.dirname(file)
touch file
end
+ mock_dir_links.each do |link, target|
+ full_link = File.join mock_dir, link
+ full_target = File.join mock_dir, target
+
+ File.symlink full_target, full_link
+ end
end
def self.delete_mock_dirs
@@ -148,22 +173,31 @@ module DirSpecs
end
end
+ def self.expected_paths_with_type
+ [
+ [".", :directory],
+ ["..", :directory],
+ [".dotfile", :file],
+ [".dotsubdir", :directory],
+ ["brace", :directory],
+ ["deeply", :directory],
+ ["dir", :directory],
+ ["dir_filename_ordering", :file],
+ ["file_one.ext", :file],
+ ["file_two.ext", :file],
+ ["nested", :directory],
+ ["nondotfile", :file],
+ ["special", :directory],
+ ["subdir_one", :directory],
+ ["subdir_two", :directory],
+ ]
+ end
+
def self.expected_paths
- %w[
- .
- ..
- .dotfile
- .dotsubdir
- brace
- deeply
- dir
- dir_filename_ordering
- file_one.ext
- file_two.ext
- nondotfile
- special
- subdir_one
- subdir_two
- ]
+ expected_paths_with_type.map(&:first)
+ end
+
+ def self.expected_glob_paths
+ expected_paths - ['..']
end
end
diff --git a/spec/ruby/core/dir/for_fd_spec.rb b/spec/ruby/core/dir/for_fd_spec.rb
new file mode 100644
index 0000000000..bbc75e0f8f
--- /dev/null
+++ b/spec/ruby/core/dir/for_fd_spec.rb
@@ -0,0 +1,77 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/common'
+
+quarantine! do # leads to "Errno::EBADF: Bad file descriptor - closedir" in DirSpecs.delete_mock_dirs
+platform_is_not :windows do
+ describe "Dir.for_fd" do
+ before :all do
+ DirSpecs.create_mock_dirs
+ end
+
+ after :all do
+ DirSpecs.delete_mock_dirs
+ end
+
+ before :each do
+ @original = Dir.pwd
+ end
+
+ after :each do
+ Dir.chdir(@original)
+ end
+
+ it "returns a new Dir object representing the directory specified by the given integer directory file descriptor" do
+ dir = Dir.new(DirSpecs.mock_dir)
+ dir_new = Dir.for_fd(dir.fileno)
+
+ dir_new.should.instance_of?(Dir)
+ dir_new.children.should == dir.children
+ dir_new.fileno.should == dir.fileno
+ ensure
+ dir.close
+ end
+
+ it "returns a new Dir object without associated path" do
+ dir = Dir.new(DirSpecs.mock_dir)
+ dir_new = Dir.for_fd(dir.fileno)
+
+ dir_new.path.should == nil
+ ensure
+ dir.close
+ end
+
+ it "calls #to_int to convert a value to an Integer" do
+ dir = Dir.new(DirSpecs.mock_dir)
+ obj = mock("fd")
+ obj.should_receive(:to_int).and_return(dir.fileno)
+
+ dir_new = Dir.for_fd(obj)
+ dir_new.fileno.should == dir.fileno
+ ensure
+ dir.close
+ end
+
+ it "raises TypeError when value cannot be converted to Integer" do
+ -> {
+ Dir.for_fd(nil)
+ }.should raise_consistent_error(TypeError, "no implicit conversion of nil into Integer")
+ end
+
+ it "raises a SystemCallError if the file descriptor given is not valid" do
+ -> { Dir.for_fd(-1) }.should.raise(SystemCallError, "Bad file descriptor - fdopendir")
+ end
+
+ it "raises a SystemCallError if the file descriptor given is not for a directory" do
+ -> { Dir.for_fd $stdout.fileno }.should.raise(SystemCallError, "Not a directory - fdopendir")
+ end
+ end
+end
+
+platform_is :windows do
+ describe "Dir.for_fd" do
+ it "raises NotImplementedError" do
+ -> { Dir.for_fd 1 }.should.raise(NotImplementedError)
+ end
+ end
+end
+end
diff --git a/spec/ruby/core/dir/foreach_spec.rb b/spec/ruby/core/dir/foreach_spec.rb
index e606b4f65c..2a2265a029 100644
--- a/spec/ruby/core/dir/foreach_spec.rb
+++ b/spec/ruby/core/dir/foreach_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/common', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/common'
describe "Dir.foreach" do
before :all do
@@ -31,17 +31,29 @@ describe "Dir.foreach" do
end
it "raises a SystemCallError if passed a nonexistent directory" do
- lambda { Dir.foreach(DirSpecs.nonexistent) {} }.should raise_error(SystemCallError)
+ -> { Dir.foreach(DirSpecs.nonexistent) {} }.should.raise(SystemCallError)
end
it "returns an Enumerator if no block given" do
- Dir.foreach(DirSpecs.mock_dir).should be_an_instance_of(Enumerator)
+ Dir.foreach(DirSpecs.mock_dir).should.instance_of?(Enumerator)
Dir.foreach(DirSpecs.mock_dir).to_a.sort.should == DirSpecs.expected_paths
end
+ it "accepts an encoding keyword for the encoding of the entries" do
+ dirs = Dir.foreach("#{DirSpecs.mock_dir}/deeply/nested", encoding: "utf-8").to_a.sort
+ dirs.each { |dir| dir.encoding.should == Encoding::UTF_8 }
+
+ dirs = Dir.foreach("#{DirSpecs.mock_dir}/deeply/nested", encoding: Encoding::ISO_8859_1).to_a.sort
+ dirs.each { |dir| dir.encoding.should == Encoding::ISO_8859_1 }
+
+ Dir.foreach("#{DirSpecs.mock_dir}/deeply/nested", encoding: Encoding::ISO_8859_1) do |f|
+ f.encoding.should == Encoding::ISO_8859_1
+ end
+ end
+
describe "when no block is given" do
it "returns an Enumerator" do
- Dir.foreach(DirSpecs.mock_dir).should be_an_instance_of(Enumerator)
+ Dir.foreach(DirSpecs.mock_dir).should.instance_of?(Enumerator)
Dir.foreach(DirSpecs.mock_dir).to_a.sort.should == DirSpecs.expected_paths
end
diff --git a/spec/ruby/core/dir/getwd_spec.rb b/spec/ruby/core/dir/getwd_spec.rb
index 26659ddec7..138481821f 100644
--- a/spec/ruby/core/dir/getwd_spec.rb
+++ b/spec/ruby/core/dir/getwd_spec.rb
@@ -1,15 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/common', __FILE__)
-require File.expand_path('../shared/pwd', __FILE__)
+require_relative '../../spec_helper'
describe "Dir.getwd" do
- before :all do
- DirSpecs.create_mock_dirs
+ it "is an alias of Dir.pwd" do
+ Dir.method(:getwd).should == Dir.method(:pwd)
end
-
- after :all do
- DirSpecs.delete_mock_dirs
- end
-
- it_behaves_like :dir_pwd, :getwd
end
diff --git a/spec/ruby/core/dir/glob_spec.rb b/spec/ruby/core/dir/glob_spec.rb
index 4a9230f8b3..9e81feb15f 100644
--- a/spec/ruby/core/dir/glob_spec.rb
+++ b/spec/ruby/core/dir/glob_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/common', __FILE__)
-require File.expand_path('../shared/glob', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/common'
+require_relative 'shared/glob'
describe "Dir.glob" do
it_behaves_like :dir_glob, :glob
@@ -29,6 +29,23 @@ describe "Dir.glob" do
%w!file_one.ext file_two.ext!
end
+ it 'returns matching file paths when supplied :base keyword argument' do
+ dir = tmp('dir_glob_base')
+ file_1 = "#{dir}/lib/bloop.rb"
+ file_2 = "#{dir}/lib/soup.rb"
+ file_3 = "#{dir}/lib/mismatched_file_type.txt"
+ file_4 = "#{dir}/mismatched_directory.rb"
+
+ touch file_1
+ touch file_2
+ touch file_3
+ touch file_4
+
+ Dir.glob('**/*.rb', base: "#{dir}/lib").sort.should == ["bloop.rb", "soup.rb"].sort
+ ensure
+ rm_r dir
+ end
+
it "calls #to_path to convert multiple patterns" do
pat1 = mock('file_one.ext')
pat1.should_receive(:to_path).and_return('file_one.ext')
@@ -39,7 +56,7 @@ describe "Dir.glob" do
end
it "matches both dot and non-dotfiles with '*' and option File::FNM_DOTMATCH" do
- Dir.glob('*', File::FNM_DOTMATCH).sort.should == DirSpecs.expected_paths
+ Dir.glob('*', File::FNM_DOTMATCH).sort.should == DirSpecs.expected_glob_paths
end
it "matches files with any beginning with '*<non-special characters>' and option File::FNM_DOTMATCH" do
@@ -47,7 +64,7 @@ describe "Dir.glob" do
end
it "matches any files in the current directory with '**' and option File::FNM_DOTMATCH" do
- Dir.glob('**', File::FNM_DOTMATCH).sort.should == DirSpecs.expected_paths
+ Dir.glob('**', File::FNM_DOTMATCH).sort.should == DirSpecs.expected_glob_paths
end
it "recursively matches any subdirectories except './' or '../' with '**/' from the current directory and option File::FNM_DOTMATCH" do
@@ -59,8 +76,12 @@ describe "Dir.glob" do
deeply/nested/directory/
deeply/nested/directory/structure/
dir/
+ nested/
+ nested/.dotsubir/
special/
+ special/test\ +()[]{}/
special/test{1}/
+ special/{}/
subdir_one/
subdir_two/
]
@@ -68,6 +89,17 @@ describe "Dir.glob" do
Dir.glob('**/', File::FNM_DOTMATCH).sort.should == expected
end
+ it "recursively matches files and directories in nested dot subdirectory except . with 'nested/**/*' from the current directory and option File::FNM_DOTMATCH" do
+ expected = %w[
+ nested/.
+ nested/.dotsubir
+ nested/.dotsubir/.dotfile
+ nested/.dotsubir/nondotfile
+ ]
+
+ Dir.glob('nested/**/*', File::FNM_DOTMATCH).sort.should == expected.sort
+ end
+
# This is a separate case to check **/ coming after a constant
# directory as well.
it "recursively matches any subdirectories except './' or '../' with '**/' and option File::FNM_DOTMATCH" do
@@ -80,8 +112,12 @@ describe "Dir.glob" do
./deeply/nested/directory/
./deeply/nested/directory/structure/
./dir/
+ ./nested/
+ ./nested/.dotsubir/
./special/
+ ./special/test\ +()[]{}/
./special/test{1}/
+ ./special/{}/
./subdir_one/
./subdir_two/
]
@@ -102,10 +138,18 @@ describe "Dir.glob" do
Dir.glob('{deeply/**/,subdir_two/*}').sort.should == expected
end
+ it "preserves multiple /s before a **" do
+ expected = %w[
+ deeply//nested/directory/structure
+ ]
+
+ Dir.glob('{deeply//**/structure}').sort.should == expected
+ end
+
it "accepts a block and yields it with each elements" do
ary = []
ret = Dir.glob(["file_o*", "file_t*"]) { |t| ary << t }
- ret.should be_nil
+ ret.should == nil
ary.should == %w!file_one.ext file_two.ext!
end
@@ -119,7 +163,144 @@ describe "Dir.glob" do
end
it "handles infinite directory wildcards" do
- Dir.glob('**/**/**').empty?.should == false
+ Dir.glob('**/**/**').should_not.empty?
+ end
+
+ it "handles **/** with base keyword argument" do
+ Dir.glob('**/**', base: "dir").should == ["filename_ordering"]
+
+ expected = %w[
+ nested
+ nested/directory
+ nested/directory/structure
+ nested/directory/structure/bar
+ nested/directory/structure/baz
+ nested/directory/structure/file_one
+ nested/directory/structure/file_one.ext
+ nested/directory/structure/foo
+ nondotfile
+ ].sort
+
+ Dir.glob('**/**', base: "deeply").sort.should == expected
+ end
+
+ it "handles **/ with base keyword argument" do
+ expected = %w[
+ /
+ directory/
+ directory/structure/
+ ]
+ Dir.glob('**/', base: "deeply/nested").sort.should == expected
+ end
+
+ it "handles **/nondotfile with base keyword argument" do
+ expected = %w[
+ deeply/nondotfile
+ nondotfile
+ subdir_one/nondotfile
+ subdir_two/nondotfile
+ ]
+ Dir.glob('**/nondotfile', base: ".").sort.should == expected
+ end
+
+ it "handles **/nondotfile with base keyword argument and FNM_DOTMATCH" do
+ expected = %w[
+ .dotsubdir/nondotfile
+ deeply/nondotfile
+ nested/.dotsubir/nondotfile
+ nondotfile
+ subdir_one/nondotfile
+ subdir_two/nondotfile
+ ]
+ Dir.glob('**/nondotfile', File::FNM_DOTMATCH, base: ".").sort.should == expected
+ end
+
+ it "handles **/.dotfile with base keyword argument" do
+ expected = %w[
+ .dotfile
+ deeply/.dotfile
+ subdir_one/.dotfile
+ ]
+ Dir.glob('**/.dotfile', base: ".").sort.should == expected
+ end
+
+ it "handles **/.dotfile with base keyword argument and FNM_DOTMATCH" do
+ expected = %w[
+ .dotfile
+ .dotsubdir/.dotfile
+ deeply/.dotfile
+ nested/.dotsubir/.dotfile
+ subdir_one/.dotfile
+ ]
+ Dir.glob('**/.dotfile', File::FNM_DOTMATCH, base: ".").sort.should == expected
+ end
+
+ it "handles **/.* with base keyword argument" do
+ expected = %w[
+ .dotfile.ext
+ directory/structure/.ext
+ ].sort
+
+ Dir.glob('**/.*', base: "deeply/nested").sort.should == expected
+ end
+
+ it "handles **/.* with base keyword argument and FNM_DOTMATCH" do
+ expected = %w[
+ .
+ .dotfile.ext
+ directory/structure/.ext
+ ].sort
+
+ Dir.glob('**/.*', File::FNM_DOTMATCH, base: "deeply/nested").sort.should == expected
+ end
+
+ it "handles **/** with base keyword argument and FNM_DOTMATCH" do
+ expected = %w[
+ .
+ .dotfile.ext
+ directory
+ directory/structure
+ directory/structure/.ext
+ directory/structure/bar
+ directory/structure/baz
+ directory/structure/file_one
+ directory/structure/file_one.ext
+ directory/structure/foo
+ ].sort
+
+ Dir.glob('**/**', File::FNM_DOTMATCH, base: "deeply/nested").sort.should == expected
+ end
+
+ it "handles **/*pattern* with base keyword argument and FNM_DOTMATCH" do
+ expected = %w[
+ .dotfile.ext
+ directory/structure/file_one
+ directory/structure/file_one.ext
+ ]
+
+ Dir.glob('**/*file*', File::FNM_DOTMATCH, base: "deeply/nested").sort.should == expected
+ end
+
+ it "handles **/glob with base keyword argument and FNM_EXTGLOB" do
+ expected = %w[
+ directory/structure/bar
+ directory/structure/file_one
+ directory/structure/file_one.ext
+ ]
+
+ Dir.glob('**/*{file,bar}*', File::FNM_EXTGLOB, base: "deeply/nested").sort.should == expected
+ end
+
+ it "handles simple filename patterns" do
+ Dir.glob('.dotfile').should == ['.dotfile']
+ end
+
+ it "handles simple directory patterns" do
+ Dir.glob('.dotsubdir/').should == ['.dotsubdir/']
+ end
+
+ it "handles simple directory patterns applied to non-directories" do
+ Dir.glob('nondotfile/').should == []
end
platform_is_not(:windows) do
@@ -152,5 +333,30 @@ describe "Dir.glob" do
Dir.rmdir('no_permission')
end
end
+
+ it "will follow symlinks when processing a `*/` pattern." do
+ expected = ['special/ln/nondotfile']
+ Dir.glob('special/*/nondotfile').should == expected
+ end
+
+ it "will not follow symlinks when recursively traversing directories" do
+ expected = %w[
+ deeply/nondotfile
+ nondotfile
+ subdir_one/nondotfile
+ subdir_two/nondotfile
+ ]
+ Dir.glob('**/nondotfile').sort.should == expected
+ end
+
+ it "will follow symlinks when testing directory after recursive directory in pattern" do
+ expected = %w[
+ deeply/nondotfile
+ special/ln/nondotfile
+ subdir_one/nondotfile
+ subdir_two/nondotfile
+ ]
+ Dir.glob('**/*/nondotfile').sort.should == expected
+ end
end
end
diff --git a/spec/ruby/core/dir/home_spec.rb b/spec/ruby/core/dir/home_spec.rb
index 6d99678034..f0b20e0687 100644
--- a/spec/ruby/core/dir/home_spec.rb
+++ b/spec/ruby/core/dir/home_spec.rb
@@ -1,26 +1,85 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/common', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/common'
describe "Dir.home" do
- it "returns the current user's home directory as a string if called without arguments" do
- home_directory = ENV['HOME']
- platform_is :windows do
- unless home_directory
- home_directory = ENV['HOMEDRIVE'] + ENV['HOMEPATH']
+ before :each do
+ @home = ENV['HOME']
+ ENV['HOME'] = "/rubyspec_home"
+ end
+
+ after :each do
+ ENV['HOME'] = @home
+ end
+
+ describe "when called without arguments" do
+ it "returns the current user's home directory, reading $HOME first" do
+ Dir.home.should == "/rubyspec_home"
+ end
+
+ it "returns a non-frozen string" do
+ Dir.home.should_not.frozen?
+ end
+
+ it "returns a string with the filesystem encoding" do
+ Dir.home.encoding.should == Encoding.find("filesystem")
+ end
+
+ platform_is_not :windows do
+ it "works even if HOME is unset" do
+ ENV.delete('HOME')
+ Dir.home.should.start_with?('/')
+ Dir.home.encoding.should == Encoding.find("filesystem")
end
- home_directory = home_directory.tr('\\', '/').chomp('/')
end
- Dir.home.should == home_directory
+ platform_is :windows do
+ it "returns the home directory with forward slashs and as UTF-8" do
+ ENV['HOME'] = "C:\\rubyspäc\\home"
+ home = Dir.home
+ home.should == "C:/rubyspäc/home"
+ home.encoding.should == Encoding::UTF_8
+ end
+
+ it "retrieves the directory from HOME, USERPROFILE, HOMEDRIVE/HOMEPATH and the WinAPI in that order" do
+ old_dirs = [ENV.delete('HOME'), ENV.delete('USERPROFILE'), ENV.delete('HOMEDRIVE'), ENV.delete('HOMEPATH')]
+
+ Dir.home.should == old_dirs[1].gsub("\\", "/")
+ ENV['HOMEDRIVE'] = "C:"
+ ENV['HOMEPATH'] = "\\rubyspec\\home1"
+ Dir.home.should == "C:/rubyspec/home1"
+ ENV['USERPROFILE'] = "C:\\rubyspec\\home2"
+ Dir.home.should == "C:/rubyspec/home2"
+ ENV['HOME'] = "C:\\rubyspec\\home3"
+ Dir.home.should == "C:/rubyspec/home3"
+ ensure
+ ENV['HOME'], ENV['USERPROFILE'], ENV['HOMEDRIVE'], ENV['HOMEPATH'] = *old_dirs
+ end
+ end
end
- platform_is_not :windows do
- it "returns the named user's home directory as a string if called with an argument" do
- Dir.home(ENV['USER']).should == ENV['HOME']
+ describe "when called with the current user name" do
+ platform_is_not :windows, :android, :wasi do
+ it "returns the named user's home directory, from the user database" do
+ Dir.home(ENV['USER']).should == `echo ~#{ENV['USER']}`.chomp
+ end
+ end
+
+ it "returns a non-frozen string" do
+ Dir.home(ENV['USER']).should_not.frozen?
+ end
+
+ it "returns a string with the filesystem encoding" do
+ Dir.home(ENV['USER']).encoding.should == Encoding.find("filesystem")
end
end
it "raises an ArgumentError if the named user doesn't exist" do
- lambda { Dir.home('geuw2n288dh2k') }.should raise_error(ArgumentError)
+ -> { Dir.home('geuw2n288dh2k') }.should.raise(ArgumentError)
+ end
+
+ describe "when called with a nil user name" do
+ it "returns the current user's home directory, reading $HOME first" do
+ Dir.home(nil).should == "/rubyspec_home"
+ end
end
end
diff --git a/spec/ruby/core/dir/initialize_spec.rb b/spec/ruby/core/dir/initialize_spec.rb
index b9420647d1..547b7dc18e 100644
--- a/spec/ruby/core/dir/initialize_spec.rb
+++ b/spec/ruby/core/dir/initialize_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/common', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/common'
describe "Dir#initialize" do
before :each do
diff --git a/spec/ruby/core/dir/inspect_spec.rb b/spec/ruby/core/dir/inspect_spec.rb
index 01bde8a862..eabaa54ce0 100644
--- a/spec/ruby/core/dir/inspect_spec.rb
+++ b/spec/ruby/core/dir/inspect_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/common', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/common'
describe "Dir#inspect" do
before :each do
@@ -11,7 +11,7 @@ describe "Dir#inspect" do
end
it "returns a String" do
- @dir.inspect.should be_an_instance_of(String)
+ @dir.inspect.should.instance_of?(String)
end
it "includes the class name" do
@@ -19,6 +19,6 @@ describe "Dir#inspect" do
end
it "includes the directory name" do
- @dir.inspect.should include(Dir.getwd)
+ @dir.inspect.should.include?(Dir.getwd)
end
end
diff --git a/spec/ruby/core/dir/mkdir_spec.rb b/spec/ruby/core/dir/mkdir_spec.rb
index 7eb8a8fe6c..37513e417a 100644
--- a/spec/ruby/core/dir/mkdir_spec.rb
+++ b/spec/ruby/core/dir/mkdir_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/common', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/common'
describe "Dir.mkdir" do
before :all do
@@ -13,73 +13,95 @@ describe "Dir.mkdir" do
it "creates the named directory with the given permissions" do
DirSpecs.clear_dirs
+ nonexisting = DirSpecs.mock_dir('nonexisting')
+ default_perms = DirSpecs.mock_dir('default_perms')
+ reduced = DirSpecs.mock_dir('reduced')
begin
- File.exist?('nonexisting').should == false
- Dir.mkdir 'nonexisting'
- File.exist?('nonexisting').should == true
+ File.should_not.exist?(nonexisting)
+ Dir.mkdir nonexisting
+ File.should.exist?(nonexisting)
platform_is_not :windows do
- Dir.mkdir 'default_perms'
- a = File.stat('default_perms').mode
- Dir.mkdir 'reduced', (a - 1)
- File.stat('reduced').mode.should_not == a
+ Dir.mkdir default_perms
+ a = File.stat(default_perms).mode
+ Dir.mkdir reduced, (a - 1)
+ File.stat(reduced).mode.should_not == a
end
platform_is :windows do
- Dir.mkdir 'default_perms', 0666
- a = File.stat('default_perms').mode
- Dir.mkdir 'reduced', 0444
- File.stat('reduced').mode.should_not == a
+ Dir.mkdir default_perms, 0666
+ a = File.stat(default_perms).mode
+ Dir.mkdir reduced, 0444
+ File.stat(reduced).mode.should_not == a
end
- Dir.mkdir('always_returns_0').should == 0
+ always_returns_0 = DirSpecs.mock_dir('always_returns_0')
+ Dir.mkdir(always_returns_0).should == 0
platform_is_not(:windows) do
- File.chmod(0777, "nonexisting","default_perms","reduced","always_returns_0")
+ File.chmod(0777, nonexisting, default_perms, reduced, always_returns_0)
end
platform_is_not(:windows) do
- File.chmod(0644, "nonexisting","default_perms","reduced","always_returns_0")
+ File.chmod(0644, nonexisting, default_perms, reduced, always_returns_0)
end
ensure
DirSpecs.clear_dirs
end
end
- it "calls #to_path on non-String arguments" do
+ it "calls #to_path on non-String path arguments" do
DirSpecs.clear_dirs
p = mock('path')
- p.should_receive(:to_path).and_return('nonexisting')
+ p.should_receive(:to_path).and_return(DirSpecs.mock_dir('nonexisting'))
Dir.mkdir(p)
DirSpecs.clear_dirs
end
+ it "calls #to_int on non-Integer permissions argument" do
+ DirSpecs.clear_dirs
+ path = DirSpecs.mock_dir('nonexisting')
+ permissions = mock('permissions')
+ permissions.should_receive(:to_int).and_return(0666)
+ Dir.mkdir(path, permissions)
+ DirSpecs.clear_dirs
+ end
+
+ it "raises TypeError if non-Integer permissions argument does not have #to_int method" do
+ path = DirSpecs.mock_dir('nonexisting')
+ permissions = Object.new
+
+ -> { Dir.mkdir(path, permissions) }.should.raise(TypeError, 'no implicit conversion of Object into Integer')
+ end
+
it "raises a SystemCallError if any of the directories in the path before the last does not exist" do
- lambda { Dir.mkdir "#{DirSpecs.nonexistent}/subdir" }.should raise_error(SystemCallError)
+ -> { Dir.mkdir "#{DirSpecs.nonexistent}/subdir" }.should.raise(SystemCallError)
end
it "raises Errno::EEXIST if the specified directory already exists" do
- lambda { Dir.mkdir("#{DirSpecs.mock_dir}/dir") }.should raise_error(Errno::EEXIST)
+ -> { Dir.mkdir("#{DirSpecs.mock_dir}/dir") }.should.raise(Errno::EEXIST)
end
it "raises Errno::EEXIST if the argument points to the existing file" do
- lambda { Dir.mkdir("#{DirSpecs.mock_dir}/file_one.ext") }.should raise_error(Errno::EEXIST)
+ -> { Dir.mkdir("#{DirSpecs.mock_dir}/file_one.ext") }.should.raise(Errno::EEXIST)
end
end
# The permissions flag are not supported on Windows as stated in documentation:
# The permissions may be modified by the value of File.umask, and are ignored on NT.
platform_is_not :windows do
- describe "Dir.mkdir" do
- before :each do
- @dir = tmp "noperms"
- end
+ as_user do
+ describe "Dir.mkdir" do
+ before :each do
+ @dir = tmp "noperms"
+ end
- after :each do
- File.chmod 0777, @dir
- rm_r @dir
- end
+ after :each do
+ File.chmod 0777, @dir
+ rm_r @dir
+ end
- it "raises a SystemCallError when lacking adequate permissions in the parent dir" do
- Dir.mkdir @dir, 0000
+ it "raises a SystemCallError when lacking adequate permissions in the parent dir" do
+ Dir.mkdir @dir, 0000
- lambda { Dir.mkdir "#{@dir}/subdir" }.should raise_error(SystemCallError)
+ -> { Dir.mkdir "#{@dir}/subdir" }.should.raise(SystemCallError)
+ end
end
end
end
diff --git a/spec/ruby/core/dir/open_spec.rb b/spec/ruby/core/dir/open_spec.rb
index b3deed47b7..be01638fbc 100644
--- a/spec/ruby/core/dir/open_spec.rb
+++ b/spec/ruby/core/dir/open_spec.rb
@@ -1,6 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/common', __FILE__)
-require File.expand_path('../shared/open', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/common'
describe "Dir.open" do
before :all do
@@ -11,5 +10,75 @@ describe "Dir.open" do
DirSpecs.delete_mock_dirs
end
- it_behaves_like :dir_open, :open
+ it "returns a Dir instance representing the specified directory" do
+ dir = Dir.open(DirSpecs.mock_dir)
+ dir.should.is_a?(Dir)
+ dir.close
+ end
+
+ it "raises a SystemCallError if the directory does not exist" do
+ -> do
+ Dir.open(DirSpecs.nonexistent)
+ end.should.raise(SystemCallError)
+ end
+
+ it "may take a block which is yielded to with the Dir instance" do
+ Dir.open(DirSpecs.mock_dir) {|dir| dir.should.is_a?(Dir)}
+ end
+
+ it "returns the value of the block if a block is given" do
+ Dir.open(DirSpecs.mock_dir) {|dir| :value }.should == :value
+ end
+
+ it "closes the Dir instance when the block exits if given a block" do
+ closed_dir = Dir.open(DirSpecs.mock_dir) { |dir| dir }
+ -> { closed_dir.read }.should.raise(IOError)
+ end
+
+ it "closes the Dir instance when the block exits the block even due to an exception" do
+ closed_dir = nil
+
+ -> do
+ Dir.open(DirSpecs.mock_dir) do |dir|
+ closed_dir = dir
+ raise "dir specs"
+ end
+ end.should.raise(RuntimeError, "dir specs")
+
+ -> { closed_dir.read }.should.raise(IOError)
+ end
+
+ it "calls #to_path on non-String arguments" do
+ p = mock('path')
+ p.should_receive(:to_path).and_return(DirSpecs.mock_dir)
+ Dir.open(p) { true }
+ end
+
+ it "accepts an options Hash" do
+ dir = Dir.open(DirSpecs.mock_dir, encoding: "utf-8") {|d| d }
+ dir.should.is_a?(Dir)
+ end
+
+ it "calls #to_hash to convert the options object" do
+ options = mock("dir_open")
+ options.should_receive(:to_hash).and_return({ encoding: Encoding::UTF_8 })
+
+ dir = Dir.open(DirSpecs.mock_dir, **options) {|d| d }
+ dir.should.is_a?(Dir)
+ end
+
+ it "ignores the :encoding option if it is nil" do
+ dir = Dir.open(DirSpecs.mock_dir, encoding: nil) {|d| d }
+ dir.should.is_a?(Dir)
+ end
+
+ platform_is_not :windows do
+ it 'sets the close-on-exec flag for the directory file descriptor' do
+ Dir.open(DirSpecs.mock_dir) do |dir|
+ io = IO.for_fd(dir.fileno)
+ io.autoclose = false
+ io.should.close_on_exec?
+ end
+ end
+ end
end
diff --git a/spec/ruby/core/dir/path_spec.rb b/spec/ruby/core/dir/path_spec.rb
index 1601220636..e506db1222 100644
--- a/spec/ruby/core/dir/path_spec.rb
+++ b/spec/ruby/core/dir/path_spec.rb
@@ -1,15 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/common', __FILE__)
-require File.expand_path('../shared/path', __FILE__)
+require_relative '../../spec_helper'
describe "Dir#path" do
- before :all do
- DirSpecs.create_mock_dirs
+ it "is an alias of Dir#to_path" do
+ Dir.instance_method(:path).should == Dir.instance_method(:to_path)
end
-
- after :all do
- DirSpecs.delete_mock_dirs
- end
-
- it_behaves_like(:dir_path, :path)
end
diff --git a/spec/ruby/core/dir/pos_spec.rb b/spec/ruby/core/dir/pos_spec.rb
index 9f05fab250..1e364fbe3c 100644
--- a/spec/ruby/core/dir/pos_spec.rb
+++ b/spec/ruby/core/dir/pos_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/common', __FILE__)
-require File.expand_path('../shared/closed', __FILE__)
-require File.expand_path('../shared/pos', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/common'
+require_relative 'shared/closed'
+require_relative 'shared/pos'
describe "Dir#pos" do
before :all do
@@ -12,19 +12,32 @@ describe "Dir#pos" do
DirSpecs.delete_mock_dirs
end
- it_behaves_like :dir_pos, :pos
-end
+ it_behaves_like :dir_closed, :pos
-describe "Dir#pos" do
- before :all do
- DirSpecs.create_mock_dirs
+ before :each do
+ @dir = Dir.open DirSpecs.mock_dir
end
- after :all do
- DirSpecs.delete_mock_dirs
+ after :each do
+ @dir.close rescue nil
end
- it_behaves_like :dir_closed, :pos
+ it "returns an Integer representing the current position in the directory" do
+ @dir.pos.should.is_a?(Integer)
+ @dir.pos.should.is_a?(Integer)
+ @dir.pos.should.is_a?(Integer)
+ end
+
+ it "returns a different Integer if moved from previous position" do
+ a = @dir.pos
+ @dir.read
+ b = @dir.pos
+
+ a.should.is_a?(Integer)
+ b.should.is_a?(Integer)
+
+ a.should_not == b
+ end
end
describe "Dir#pos=" do
diff --git a/spec/ruby/core/dir/pwd_spec.rb b/spec/ruby/core/dir/pwd_spec.rb
index 4fa86dd6b9..70208b03d6 100644
--- a/spec/ruby/core/dir/pwd_spec.rb
+++ b/spec/ruby/core/dir/pwd_spec.rb
@@ -1,7 +1,6 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/common', __FILE__)
-require File.expand_path('../shared/pwd', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/common'
describe "Dir.pwd" do
before :all do
@@ -12,7 +11,49 @@ describe "Dir.pwd" do
DirSpecs.delete_mock_dirs
end
- it_behaves_like :dir_pwd, :pwd
+ before :each do
+ @fs_encoding = Encoding.find('filesystem')
+ end
+
+ it "returns the current working directory" do
+ pwd = Dir.pwd
+
+ File.directory?(pwd).should == true
+
+ # On ubuntu gutsy, for example, /bin/pwd does not
+ # understand -P. With just `pwd -P`, /bin/pwd is run.
+
+ # The following uses inode rather than file names to account for
+ # case insensitive file systems like default OS/X file systems
+ platform_is_not :windows do
+ File.stat(pwd).ino.should == File.stat(`/bin/sh -c "pwd -P"`.chomp).ino
+ end
+ platform_is :windows do
+ File.stat(pwd).ino.should == File.stat(File.expand_path(`cd`.chomp)).ino
+ end
+ end
+
+ it "returns an absolute path" do
+ pwd = Dir.pwd
+ pwd.should == File.expand_path(pwd)
+ end
+
+ it "returns an absolute path even when chdir to a relative path" do
+ Dir.chdir(".") do
+ pwd = Dir.pwd
+ File.directory?(pwd).should == true
+ pwd.should == File.expand_path(pwd)
+ end
+ end
+
+ it "returns a String with the filesystem encoding" do
+ enc = Dir.pwd.encoding
+ if @fs_encoding == Encoding::US_ASCII
+ [Encoding::US_ASCII, Encoding::BINARY].should.include?(enc)
+ else
+ enc.should.equal?(@fs_encoding)
+ end
+ end
end
describe "Dir.pwd" do
diff --git a/spec/ruby/core/dir/read_spec.rb b/spec/ruby/core/dir/read_spec.rb
index 79ed9b8058..3f842457f4 100644
--- a/spec/ruby/core/dir/read_spec.rb
+++ b/spec/ruby/core/dir/read_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/common', __FILE__)
-require File.expand_path('../shared/closed', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/common'
+require_relative 'shared/closed'
describe "Dir#read" do
before :all do
@@ -15,7 +15,7 @@ describe "Dir#read" do
# an FS does not necessarily impose order
ls = Dir.entries DirSpecs.mock_dir
dir = Dir.open DirSpecs.mock_dir
- ls.should include(dir.read)
+ ls.should.include?(dir.read)
dir.close
end
@@ -39,5 +39,38 @@ describe "Dir#read" do
entries.sort.should == DirSpecs.expected_paths
end
+ platform_is_not :windows do
+ it "returns all directory entries even when encoding conversion will fail" do
+ dir = Dir.open(File.join(DirSpecs.mock_dir, 'special'))
+ utf8_entries = []
+ begin
+ while entry = dir.read
+ utf8_entries << entry
+ end
+ ensure
+ dir.close
+ end
+ old_internal_encoding = Encoding::default_internal
+ old_external_encoding = Encoding::default_external
+ Encoding.default_internal = Encoding::UTF_8
+ Encoding.default_external = Encoding::SHIFT_JIS
+ shift_jis_entries = []
+ begin
+ Dir.open(File.join(DirSpecs.mock_dir, 'special')) do |d|
+ -> {
+ while entry = d.read
+ shift_jis_entries << entry
+ end
+ }.should_not.raise
+ end
+ ensure
+ Encoding.default_internal = old_internal_encoding
+ Encoding.default_external = old_external_encoding
+ end
+ shift_jis_entries.size.should == utf8_entries.size
+ shift_jis_entries.filter { |f| f.encoding == Encoding::SHIFT_JIS }.size.should == 1
+ end
+ end
+
it_behaves_like :dir_closed, :read
end
diff --git a/spec/ruby/core/dir/rewind_spec.rb b/spec/ruby/core/dir/rewind_spec.rb
index 65ffcdf1c3..220d7f5372 100644
--- a/spec/ruby/core/dir/rewind_spec.rb
+++ b/spec/ruby/core/dir/rewind_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/common', __FILE__)
-require File.expand_path('../shared/closed', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/common'
+require_relative 'shared/closed'
describe "Dir#rewind" do
before :all do
diff --git a/spec/ruby/core/dir/rmdir_spec.rb b/spec/ruby/core/dir/rmdir_spec.rb
index 09499572c0..c31067ca29 100644
--- a/spec/ruby/core/dir/rmdir_spec.rb
+++ b/spec/ruby/core/dir/rmdir_spec.rb
@@ -1,15 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/common', __FILE__)
-require File.expand_path('../shared/delete', __FILE__)
+require_relative '../../spec_helper'
describe "Dir.rmdir" do
- before :all do
- DirSpecs.create_mock_dirs
+ it "is an alias of Dir.delete" do
+ Dir.method(:rmdir).should == Dir.method(:delete)
end
-
- after :all do
- DirSpecs.delete_mock_dirs
- end
-
- it_behaves_like :dir_delete, :rmdir
end
diff --git a/spec/ruby/core/dir/scan_spec.rb b/spec/ruby/core/dir/scan_spec.rb
new file mode 100644
index 0000000000..3aa071337b
--- /dev/null
+++ b/spec/ruby/core/dir/scan_spec.rb
@@ -0,0 +1,224 @@
+# encoding: utf-8
+
+require_relative '../../spec_helper'
+require_relative 'fixtures/common'
+require_relative '../file/fixtures/file_types'
+
+ruby_version_is "4.1" do
+ describe "Dir.scan" do
+ before :all do
+ FileSpecs.configure_types
+ end
+
+ before :all do
+ DirSpecs.create_mock_dirs
+ end
+
+ after :all do
+ DirSpecs.delete_mock_dirs
+ end
+
+ before :each do
+ @internal = Encoding.default_internal
+ end
+
+ after :each do
+ Encoding.default_internal = @internal
+ end
+
+ it "returns an Array of filename and type pairs in an existing directory including dotfiles" do
+ a = Dir.scan(DirSpecs.mock_dir).sort
+
+ a.should == DirSpecs.expected_paths_with_type - [[".", :directory], ["..", :directory]]
+
+ a = Dir.scan("#{DirSpecs.mock_dir}/deeply/nested").sort
+ a.should == [[".dotfile.ext", :file], ["directory", :directory]]
+ end
+
+ it "yields filename and type in an existing directory including dotfiles" do
+ a = []
+ Dir.scan(DirSpecs.mock_dir) do |n, t|
+ a << [n, t]
+ end
+ a.sort!
+ a.should == DirSpecs.expected_paths_with_type - [[".", :directory], ["..", :directory]]
+
+ a = []
+ Dir.scan("#{DirSpecs.mock_dir}/deeply/nested") do |n, t|
+ a << [n, t]
+ end
+ a.sort!
+ a.should == [[".dotfile.ext", :file], ["directory", :directory]]
+ end
+
+ it "calls #to_path on non-String arguments" do
+ p = mock('path')
+ p.should_receive(:to_path).and_return(DirSpecs.mock_dir)
+ Dir.scan(p)
+ end
+
+ it "accepts an options Hash" do
+ a = Dir.scan("#{DirSpecs.mock_dir}/deeply/nested", encoding: "utf-8").sort
+ a.should == [[".dotfile.ext", :file], ["directory", :directory]]
+ end
+
+ it "returns children names encoded with the filesystem encoding by default" do
+ # This spec depends on the locale not being US-ASCII because if it is, the
+ # children that are not ascii_only? will be BINARY encoded.
+ children = Dir.scan(File.join(DirSpecs.mock_dir, 'special')).sort
+ encoding = Encoding.find("filesystem")
+ encoding = Encoding::BINARY if encoding == Encoding::US_ASCII
+ platform_is_not :windows do
+ children.should.include?(["ã“ã‚“ã«ã¡ã¯.txt".dup.force_encoding(encoding), :file])
+ end
+ children.first.first.encoding.should.equal?(Encoding.find("filesystem"))
+ end
+
+ it "returns children names encoded with the specified encoding" do
+ dir = File.join(DirSpecs.mock_dir, 'special')
+ children = Dir.scan(dir, encoding: "euc-jp").sort
+ children.first.first.encoding.should.equal?(Encoding::EUC_JP)
+ end
+
+ it "returns children names transcoded to the default internal encoding" do
+ Encoding.default_internal = Encoding::EUC_KR
+ children = Dir.scan(File.join(DirSpecs.mock_dir, 'special')).sort
+ children.first.first.encoding.should.equal?(Encoding::EUC_KR)
+ end
+
+ it "raises a SystemCallError if called with a nonexistent directory" do
+ -> { Dir.scan DirSpecs.nonexistent }.should.raise(SystemCallError)
+ end
+
+ it "handles symlink" do
+ FileSpecs.symlink do |path|
+ Dir.scan(File.dirname(path)).map(&:last).should.include?(:link)
+ end
+ end
+
+ platform_is_not :windows do
+ it "handles socket" do
+ FileSpecs.socket do |path|
+ Dir.scan(File.dirname(path)).map(&:last).should.include?(:socket)
+ end
+ end
+
+ it "handles FIFO" do
+ FileSpecs.fifo do |path|
+ Dir.scan(File.dirname(path)).map(&:last).should.include?(:fifo)
+ end
+ end
+
+ it "handles character devices" do
+ FileSpecs.character_device do |path|
+ Dir.scan(File.dirname(path)).map(&:last).should.include?(:characterSpecial)
+ end
+ end
+ end
+
+ platform_is_not :freebsd, :windows do
+ with_block_device do
+ it "handles block devices" do
+ FileSpecs.block_device do |path|
+ Dir.scan(File.dirname(path)).map(&:last).should.include?(:blockSpecial)
+ end
+ end
+ end
+ end
+ end
+
+ describe "Dir#scan" do
+ before :all do
+ DirSpecs.create_mock_dirs
+ end
+
+ after :all do
+ DirSpecs.delete_mock_dirs
+ end
+
+ before :each do
+ @internal = Encoding.default_internal
+ end
+
+ after :each do
+ Encoding.default_internal = @internal
+ @dir.close if @dir
+ end
+
+ it "returns an Array of filenames in an existing directory including dotfiles" do
+ @dir = Dir.new(DirSpecs.mock_dir)
+ a = @dir.scan.sort
+ @dir.close
+
+ a.should == DirSpecs.expected_paths_with_type - [[".", :directory], ["..", :directory]]
+
+ @dir = Dir.new("#{DirSpecs.mock_dir}/deeply/nested")
+ a = @dir.scan.sort
+ a.should == [[".dotfile.ext", :file], ["directory", :directory]]
+ end
+
+ it "yields filename and type in an existing directory including dotfiles" do
+ @dir = Dir.new(DirSpecs.mock_dir)
+ a = []
+ @dir.scan do |n, t|
+ a << [n, t]
+ end
+ a.sort!
+ a.should == DirSpecs.expected_paths_with_type - [[".", :directory], ["..", :directory]]
+
+ @dir = Dir.new("#{DirSpecs.mock_dir}/deeply/nested")
+ a = []
+ @dir.scan do |n, t|
+ a << [n, t]
+ end
+ a.sort!
+ a.should == [[".dotfile.ext", :file], ["directory", :directory]]
+ end
+
+ it "accepts an encoding keyword for the encoding of the entries" do
+ @dir = Dir.new("#{DirSpecs.mock_dir}/deeply/nested", encoding: "utf-8")
+ dirs = @dir.to_a.sort
+ dirs.each { |d| d.encoding.should == Encoding::UTF_8 }
+ end
+
+ it "returns children names encoded with the filesystem encoding by default" do
+ # This spec depends on the locale not being US-ASCII because if it is, the
+ # children that are not ascii_only? will be BINARY encoded.
+ @dir = Dir.new(File.join(DirSpecs.mock_dir, 'special'))
+ children = @dir.scan.sort
+ encoding = Encoding.find("filesystem")
+ encoding = Encoding::BINARY if encoding == Encoding::US_ASCII
+ platform_is_not :windows do
+ children.should.include?(["ã“ã‚“ã«ã¡ã¯.txt".dup.force_encoding(encoding), :file])
+ end
+ children.first.first.encoding.should.equal?(Encoding.find("filesystem"))
+ end
+
+ it "returns children names encoded with the specified encoding" do
+ path = File.join(DirSpecs.mock_dir, 'special')
+ @dir = Dir.new(path, encoding: "euc-jp")
+ children = @dir.children.sort
+ children.first.encoding.should.equal?(Encoding::EUC_JP)
+ end
+
+ it "returns children names transcoded to the default internal encoding" do
+ Encoding.default_internal = Encoding::EUC_KR
+ @dir = Dir.new(File.join(DirSpecs.mock_dir, 'special'))
+ children = @dir.scan.sort
+ children.first.first.encoding.should.equal?(Encoding::EUC_KR)
+ end
+
+ it "returns the same result when called repeatedly" do
+ @dir = Dir.open DirSpecs.mock_dir
+
+ a = []
+ @dir.each {|dir| a << dir}
+
+ b = []
+ @dir.each {|dir| b << dir}
+
+ a.sort.should == b.sort
+ a.sort.should == DirSpecs.expected_paths
+ end
+ end
+end
diff --git a/spec/ruby/core/dir/seek_spec.rb b/spec/ruby/core/dir/seek_spec.rb
index b51e554441..ed409897cd 100644
--- a/spec/ruby/core/dir/seek_spec.rb
+++ b/spec/ruby/core/dir/seek_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/common', __FILE__)
-require File.expand_path('../shared/pos', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/common'
+require_relative 'shared/pos'
describe "Dir#seek" do
before :all do
diff --git a/spec/ruby/core/dir/shared/chroot.rb b/spec/ruby/core/dir/shared/chroot.rb
index 2ed033dfed..e4e6103799 100644
--- a/spec/ruby/core/dir/shared/chroot.rb
+++ b/spec/ruby/core/dir/shared/chroot.rb
@@ -2,8 +2,8 @@ describe :dir_chroot_as_root, shared: true do
before :all do
DirSpecs.create_mock_dirs
- @real_root = "../" * (File.dirname(__FILE__).count('/') - 1)
- @ref_dir = File.join("/", Dir.new('/').entries.first)
+ @real_root = "../" * (__dir__.count('/') - 1)
+ @ref_dir = File.join("/", File.basename(Dir["/*"].first))
end
after :all do
@@ -14,24 +14,27 @@ describe :dir_chroot_as_root, shared: true do
DirSpecs.delete_mock_dirs
end
+ # Pending until https://github.com/ruby/ruby/runs/8075149420 is fixed
+ compilations_ci = ENV["GITHUB_WORKFLOW"] == "Compilations"
+
it "can be used to change the process' root directory" do
- lambda { Dir.send(@method, File.dirname(__FILE__)) }.should_not raise_error
- File.exist?("/#{File.basename(__FILE__)}").should be_true
- end
+ -> { Dir.send(@method, __dir__) }.should_not.raise
+ File.should.exist?("/#{File.basename(__FILE__)}")
+ end unless compilations_ci
it "returns 0 if successful" do
Dir.send(@method, '/').should == 0
end
it "raises an Errno::ENOENT exception if the directory doesn't exist" do
- lambda { Dir.send(@method, 'xgwhwhsjai2222jg') }.should raise_error(Errno::ENOENT)
+ -> { Dir.send(@method, 'xgwhwhsjai2222jg') }.should.raise(Errno::ENOENT)
end
it "can be escaped from with ../" do
Dir.send(@method, @real_root)
- File.exist?(@ref_dir).should be_true
- File.exist?("/#{File.basename(__FILE__)}").should be_false
- end
+ File.should.exist?(@ref_dir)
+ File.should_not.exist?("/#{File.basename(__FILE__)}")
+ end unless compilations_ci
it "calls #to_path on non-String argument" do
p = mock('path')
diff --git a/spec/ruby/core/dir/shared/closed.rb b/spec/ruby/core/dir/shared/closed.rb
index a1bce06a08..c868fd6e6d 100644
--- a/spec/ruby/core/dir/shared/closed.rb
+++ b/spec/ruby/core/dir/shared/closed.rb
@@ -1,9 +1,9 @@
describe :dir_closed, shared: true do
it "raises an IOError when called on a closed Dir instance" do
- lambda {
+ -> {
dir = Dir.open DirSpecs.mock_dir
dir.close
dir.send(@method) {}
- }.should raise_error(IOError)
+ }.should.raise(IOError)
end
end
diff --git a/spec/ruby/core/dir/shared/delete.rb b/spec/ruby/core/dir/shared/delete.rb
deleted file mode 100644
index 8db17d985f..0000000000
--- a/spec/ruby/core/dir/shared/delete.rb
+++ /dev/null
@@ -1,61 +0,0 @@
-describe :dir_delete, shared: true do
- before :each do
- DirSpecs.rmdir_dirs true
- end
-
- after :each do
- DirSpecs.rmdir_dirs false
- end
-
- it "removes empty directories" do
- Dir.send(@method, DirSpecs.mock_rmdir("empty")).should == 0
- end
-
- it "calls #to_path on non-String arguments" do
- p = mock('path')
- p.should_receive(:to_path).and_return(DirSpecs.mock_rmdir("empty"))
- Dir.send(@method, p)
- end
-
- platform_is_not :solaris do
- it "raises an Errno::ENOTEMPTY when trying to remove a nonempty directory" do
- lambda do
- Dir.send @method, DirSpecs.mock_rmdir("nonempty")
- end.should raise_error(Errno::ENOTEMPTY)
- end
- end
-
- platform_is :solaris do
- it "raises an Errno::EEXIST when trying to remove a nonempty directory" do
- lambda do
- Dir.send @method, DirSpecs.mock_rmdir("nonempty")
- end.should raise_error(Errno::EEXIST)
- end
- end
-
- it "raises an Errno::ENOENT when trying to remove a non-existing directory" do
- lambda do
- Dir.send @method, DirSpecs.nonexistent
- end.should raise_error(Errno::ENOENT)
- end
-
- it "raises an Errno::ENOTDIR when trying to remove a non-directory" do
- file = DirSpecs.mock_rmdir("nonempty/regular")
- touch(file)
- lambda do
- Dir.send @method, file
- end.should raise_error(Errno::ENOTDIR)
- end
-
- # this won't work on Windows, since chmod(0000) does not remove all permissions
- platform_is_not :windows do
- it "raises an Errno::EACCES if lacking adequate permissions to remove the directory" do
- parent = DirSpecs.mock_rmdir("noperm")
- child = DirSpecs.mock_rmdir("noperm", "child")
- File.chmod(0000, parent)
- lambda do
- Dir.send @method, child
- end.should raise_error(Errno::EACCES)
- end
- end
-end
diff --git a/spec/ruby/core/dir/shared/exist.rb b/spec/ruby/core/dir/shared/exist.rb
deleted file mode 100644
index fbd2c9862d..0000000000
--- a/spec/ruby/core/dir/shared/exist.rb
+++ /dev/null
@@ -1,56 +0,0 @@
-describe :dir_exist, shared: true do
- it "returns true if the given directory exists" do
- Dir.send(@method, File.dirname(__FILE__)).should be_true
- end
-
- it "returns true for '.'" do
- Dir.send(@method, '.').should be_true
- end
-
- it "returns true for '..'" do
- Dir.send(@method, '..').should be_true
- end
-
- it "understands non-ASCII paths" do
- subdir = File.join(tmp("\u{9876}\u{665}"))
- Dir.send(@method, subdir).should be_false
- Dir.mkdir(subdir)
- Dir.send(@method, subdir).should be_true
- Dir.rmdir(subdir)
- end
-
- it "understands relative paths" do
- Dir.send(@method, File.dirname(__FILE__) + '/../').should be_true
- end
-
- it "returns false if the given directory doesn't exist" do
- Dir.send(@method, 'y26dg27n2nwjs8a/').should be_false
- end
-
- it "doesn't require the name to have a trailing slash" do
- dir = File.dirname(__FILE__)
- dir.sub!(/\/$/,'')
- Dir.send(@method, dir).should be_true
- end
-
- it "doesn't expand paths" do
- Dir.send(@method, File.expand_path('~')).should be_true
- Dir.send(@method, '~').should be_false
- end
-
- it "returns false if the argument exists but is a file" do
- File.exist?(__FILE__).should be_true
- Dir.send(@method, __FILE__).should be_false
- end
-
- it "doesn't set $! when file doesn't exist" do
- Dir.send(@method, "/path/to/non/existent/dir")
- $!.should be_nil
- end
-
- it "calls #to_path on non String arguments" do
- p = mock('path')
- p.should_receive(:to_path).and_return(File.dirname(__FILE__))
- Dir.send(@method, p)
- end
-end
diff --git a/spec/ruby/core/dir/shared/glob.rb b/spec/ruby/core/dir/shared/glob.rb
index d2201cd6cd..86aa105259 100644
--- a/spec/ruby/core/dir/shared/glob.rb
+++ b/spec/ruby/core/dir/shared/glob.rb
@@ -11,11 +11,9 @@ describe :dir_glob, shared: true do
DirSpecs.delete_mock_dirs
end
- with_feature :encoding do
- it "raises an Encoding::CompatibilityError if the argument encoding is not compatible with US-ASCII" do
- pattern = "file*".force_encoding Encoding::UTF_16BE
- lambda { Dir.send(@method, pattern) }.should raise_error(Encoding::CompatibilityError)
- end
+ it "raises an Encoding::CompatibilityError if the argument encoding is not compatible with US-ASCII" do
+ pattern = "files*".dup.force_encoding Encoding::UTF_16BE
+ -> { Dir.send(@method, pattern) }.should.raise(Encoding::CompatibilityError)
end
it "calls #to_path to convert a pattern" do
@@ -25,9 +23,29 @@ describe :dir_glob, shared: true do
Dir.send(@method, obj).should == %w[file_one.ext]
end
- it "splits the string on \\0 if there is only one string given" do
- Dir.send(@method, "file_o*\0file_t*").should ==
- %w!file_one.ext file_two.ext!
+ it "raises an ArgumentError if the string contains \\0" do
+ -> {Dir.send(@method, "file_o*\0file_t*")}.should.raise ArgumentError, /nul-separated/
+ end
+
+ it "result is sorted by default" do
+ result = Dir.send(@method, '*')
+ result.should == result.sort
+ end
+
+ it "result is sorted with sort: true" do
+ result = Dir.send(@method, '*', sort: true)
+ result.should == result.sort
+ end
+
+ it "sort: false returns same files" do
+ result = Dir.send(@method,'*', sort: false)
+ result.sort.should == Dir.send(@method, '*').sort
+ end
+
+ it "raises an ArgumentError if sort: is not true or false" do
+ -> { Dir.send(@method, '*', sort: 0) }.should.raise ArgumentError, /expected true or false/
+ -> { Dir.send(@method, '*', sort: nil) }.should.raise ArgumentError, /expected true or false/
+ -> { Dir.send(@method, '*', sort: 'false') }.should.raise ArgumentError, /expected true or false/
end
it "matches non-dotfiles with '*'" do
@@ -38,6 +56,7 @@ describe :dir_glob, shared: true do
dir_filename_ordering
file_one.ext
file_two.ext
+ nested
nondotfile
special
subdir_one
@@ -55,6 +74,10 @@ describe :dir_glob, shared: true do
Dir.send(@method, 'special/+').should == ['special/+']
end
+ it "matches directories with special characters when escaped" do
+ Dir.send(@method, 'special/\{}/special').should == ["special/{}/special"]
+ end
+
platform_is_not :windows do
it "matches regexp special *" do
Dir.send(@method, 'special/\*').should == ['special/*']
@@ -67,6 +90,14 @@ describe :dir_glob, shared: true do
it "matches regexp special |" do
Dir.send(@method, 'special/|').should == ['special/|']
end
+
+ it "matches files with backslashes in their name" do
+ Dir.glob('special/\\\\{a,b}').should == ['special/\a']
+ end
+
+ it "matches directory with special characters in their name in complex patterns" do
+ Dir.glob("special/test +()\\[\\]\\{\\}/hello_world{.{en},}{.{html},}{+{phone},}{.{erb},}").should == ['special/test +()[]{}/hello_world.erb']
+ end
end
it "matches regexp special ^" do
@@ -105,8 +136,8 @@ describe :dir_glob, shared: true do
Dir.send(@method, 'special/test\{1\}/*').should == ['special/test{1}/file[1]']
end
- it "matches dotfiles with '.*'" do
- Dir.send(@method, '.*').sort.should == %w|. .. .dotfile .dotsubdir|.sort
+ it "matches dotfiles except .. with '.*'" do
+ Dir.send(@method, '.*').sort.should == %w|. .dotfile .dotsubdir|.sort
end
it "matches non-dotfiles with '*<non-special characters>'" do
@@ -141,6 +172,7 @@ describe :dir_glob, shared: true do
dir_filename_ordering
file_one.ext
file_two.ext
+ nested
nondotfile
special
subdir_one
@@ -150,8 +182,8 @@ describe :dir_glob, shared: true do
Dir.send(@method, '**').sort.should == expected
end
- it "matches dotfiles in the current directory with '.**'" do
- Dir.send(@method, '.**').sort.should == %w|. .. .dotsubdir .dotfile|.sort
+ it "matches dotfiles in the current directory except .. with '.**'" do
+ Dir.send(@method, '.**').sort.should == %w|. .dotsubdir .dotfile|.sort
end
it "recursively matches any nondot subdirectories with '**/'" do
@@ -162,8 +194,11 @@ describe :dir_glob, shared: true do
deeply/nested/directory/
deeply/nested/directory/structure/
dir/
+ nested/
special/
+ special/test\ +()[]{}/
special/test{1}/
+ special/{}/
subdir_one/
subdir_two/
]
@@ -171,9 +206,17 @@ describe :dir_glob, shared: true do
Dir.send(@method, '**/').sort.should == expected
end
- it "recursively matches any subdirectories including ./ and ../ with '.**/'" do
+ it "recursively matches any subdirectories except './' or '../' with '**/' from the base directory if that is specified" do
+ expected = %w[
+ nested/directory
+ ]
+
+ Dir.send(@method, '**/*ory', base: 'deeply').sort.should == expected
+ end
+
+ it "recursively matches any subdirectories including ./ with '.**/'" do
Dir.chdir("#{DirSpecs.mock_dir}/subdir_one") do
- Dir.send(@method, '.**/').sort.should == %w|./ ../|.sort
+ Dir.send(@method, '.**/').should == ['./']
end
end
@@ -216,7 +259,7 @@ describe :dir_glob, shared: true do
end
it "matches dot or non-dotfiles with '{,.}*'" do
- Dir.send(@method, '{,.}*').sort.should == DirSpecs.expected_paths
+ Dir.send(@method, '{,.}*').sort.should == DirSpecs.expected_glob_paths
end
it "respects the order of {} expressions, expanding left most first" do
@@ -262,11 +305,11 @@ describe :dir_glob, shared: true do
subdir_two/nondotfile.ext]
end
- it "ignores matching through directories that doen't exist" do
+ it "ignores matching through directories that doesn't exist" do
Dir.send(@method, "deeply/notthere/blah*/whatever").should == []
end
- it "ignores matching only directories under an nonexistant path" do
+ it "ignores matching only directories under an nonexistent path" do
Dir.send(@method, "deeply/notthere/blah/").should == []
end
@@ -275,6 +318,76 @@ describe :dir_glob, shared: true do
Dir.send(@method, "special/ã“ã‚“ã«ã¡ã¯{,.txt}").should == ["special/ã“ã‚“ã«ã¡ã¯.txt"]
end
end
+
+ context ":base option passed" do
+ before :each do
+ @mock_dir = File.expand_path tmp('dir_glob_mock')
+
+ %w[
+ a/b/x
+ a/b/c/y
+ a/b/c/d/z
+ ].each do |path|
+ file = File.join @mock_dir, path
+ mkdir_p File.dirname(file)
+ touch file
+ end
+ end
+
+ after :each do
+ rm_r @mock_dir
+ end
+
+ it "matches entries only from within the specified directory" do
+ path = File.join(@mock_dir, "a/b/c")
+ Dir.send(@method, "*", base: path).sort.should == %w( d y )
+ end
+
+ it "accepts both relative and absolute paths" do
+ require 'pathname'
+
+ path_abs = File.join(@mock_dir, "a/b/c")
+ path_rel = Pathname.new(path_abs).relative_path_from(Pathname.new(Dir.pwd))
+
+ result_abs = Dir.send(@method, "*", base: path_abs).sort
+ result_rel = Dir.send(@method, "*", base: path_rel).sort
+
+ result_abs.should == %w( d y )
+ result_rel.should == %w( d y )
+ end
+
+ it "returns [] if specified path does not exist" do
+ path = File.join(@mock_dir, "fake-name")
+ File.should_not.exist?(path)
+
+ Dir.send(@method, "*", base: path).should == []
+ end
+
+ it "returns [] if specified path is a file" do
+ path = File.join(@mock_dir, "a/b/x")
+ File.should.exist?(path)
+
+ Dir.send(@method, "*", base: path).should == []
+ end
+
+ it "raises TypeError when cannot convert value to string" do
+ -> {
+ Dir.send(@method, "*", base: [])
+ }.should.raise(TypeError)
+ end
+
+ it "handles '' as current directory path" do
+ Dir.chdir @mock_dir do
+ Dir.send(@method, "*", base: "").should == %w( a )
+ end
+ end
+
+ it "handles nil as current directory path" do
+ Dir.chdir @mock_dir do
+ Dir.send(@method, "*", base: nil).should == %w( a )
+ end
+ end
+ end
end
describe :dir_glob_recursive, shared: true do
diff --git a/spec/ruby/core/dir/shared/open.rb b/spec/ruby/core/dir/shared/open.rb
deleted file mode 100644
index 3c2b63b6fa..0000000000
--- a/spec/ruby/core/dir/shared/open.rb
+++ /dev/null
@@ -1,63 +0,0 @@
-describe :dir_open, shared: true do
- it "returns a Dir instance representing the specified directory" do
- dir = Dir.send(@method, DirSpecs.mock_dir)
- dir.should be_kind_of(Dir)
- dir.close
- end
-
- it "raises a SystemCallError if the directory does not exist" do
- lambda do
- Dir.send @method, DirSpecs.nonexistent
- end.should raise_error(SystemCallError)
- end
-
- it "may take a block which is yielded to with the Dir instance" do
- Dir.send(@method, DirSpecs.mock_dir) {|dir| dir.should be_kind_of(Dir)}
- end
-
- it "returns the value of the block if a block is given" do
- Dir.send(@method, DirSpecs.mock_dir) {|dir| :value }.should == :value
- end
-
- it "closes the Dir instance when the block exits if given a block" do
- closed_dir = Dir.send(@method, DirSpecs.mock_dir) { |dir| dir }
- lambda { closed_dir.read }.should raise_error(IOError)
- end
-
- it "closes the Dir instance when the block exits the block even due to an exception" do
- closed_dir = nil
-
- lambda do
- Dir.send(@method, DirSpecs.mock_dir) do |dir|
- closed_dir = dir
- raise
- end
- end.should raise_error
-
- lambda { closed_dir.read }.should raise_error(IOError)
- end
-
- it "calls #to_path on non-String arguments" do
- p = mock('path')
- p.should_receive(:to_path).and_return(DirSpecs.mock_dir)
- Dir.send(@method, p) { true }
- end
-
- it "accepts an options Hash" do
- dir = Dir.send(@method, DirSpecs.mock_dir, encoding: "utf-8") {|d| d }
- dir.should be_kind_of(Dir)
- end
-
- it "calls #to_hash to convert the options object" do
- options = mock("dir_open")
- options.should_receive(:to_hash).and_return({ encoding: Encoding::UTF_8 })
-
- dir = Dir.send(@method, DirSpecs.mock_dir, options) {|d| d }
- dir.should be_kind_of(Dir)
- end
-
- it "ignores the :encoding option if it is nil" do
- dir = Dir.send(@method, DirSpecs.mock_dir, encoding: nil) {|d| d }
- dir.should be_kind_of(Dir)
- end
-end
diff --git a/spec/ruby/core/dir/shared/path.rb b/spec/ruby/core/dir/shared/path.rb
deleted file mode 100644
index 829eeb04c2..0000000000
--- a/spec/ruby/core/dir/shared/path.rb
+++ /dev/null
@@ -1,32 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/common', __FILE__)
-require File.expand_path('../closed', __FILE__)
-
-describe :dir_path, shared: true do
- it "returns the path that was supplied to .new or .open" do
- dir = Dir.open DirSpecs.mock_dir
- begin
- dir.send(@method).should == DirSpecs.mock_dir
- ensure
- dir.close rescue nil
- end
- end
-
- it "returns the path even when called on a closed Dir instance" do
- dir = Dir.open DirSpecs.mock_dir
- dir.close
- dir.send(@method).should == DirSpecs.mock_dir
- end
-
- with_feature :encoding do
- it "returns a String with the same encoding as the argument to .open" do
- path = DirSpecs.mock_dir.force_encoding Encoding::IBM866
- dir = Dir.open path
- begin
- dir.send(@method).encoding.should equal(Encoding::IBM866)
- ensure
- dir.close
- end
- end
- end
-end
diff --git a/spec/ruby/core/dir/shared/pos.rb b/spec/ruby/core/dir/shared/pos.rb
index 2165932d99..741de8918c 100644
--- a/spec/ruby/core/dir/shared/pos.rb
+++ b/spec/ruby/core/dir/shared/pos.rb
@@ -1,30 +1,3 @@
-describe :dir_pos, shared: true do
- before :each do
- @dir = Dir.open DirSpecs.mock_dir
- end
-
- after :each do
- @dir.close rescue nil
- end
-
- it "returns an Integer representing the current position in the directory" do
- @dir.send(@method).should be_kind_of(Integer)
- @dir.send(@method).should be_kind_of(Integer)
- @dir.send(@method).should be_kind_of(Integer)
- end
-
- it "returns a different Integer if moved from previous position" do
- a = @dir.send(@method)
- @dir.read
- b = @dir.send(@method)
-
- a.should be_kind_of(Integer)
- b.should be_kind_of(Integer)
-
- a.should_not == b
- end
-end
-
describe :dir_pos_set, shared: true do
before :each do
@dir = Dir.open DirSpecs.mock_dir
diff --git a/spec/ruby/core/dir/shared/pwd.rb b/spec/ruby/core/dir/shared/pwd.rb
deleted file mode 100644
index 5f041a9d41..0000000000
--- a/spec/ruby/core/dir/shared/pwd.rb
+++ /dev/null
@@ -1,49 +0,0 @@
-describe :dir_pwd, shared: true do
- with_feature :encoding do
- before :each do
- @fs_encoding = Encoding.find('filesystem')
- end
- end
-
- it "returns the current working directory" do
- pwd = Dir.send(@method)
-
- File.directory?(pwd).should == true
-
- # On ubuntu gutsy, for example, /bin/pwd does not
- # understand -P. With just `pwd -P`, /bin/pwd is run.
-
- # The following uses inode rather than file names to account for
- # case insensitive file systems like default OS/X file systems
- platform_is_not :windows do
- File.stat(pwd).ino.should == File.stat(`/bin/sh -c "pwd -P"`.chomp).ino
- end
- platform_is :windows do
- File.stat(pwd).ino.should == File.stat(File.expand_path(`cd`.chomp)).ino
- end
- end
-
- it "returns an absolute path" do
- pwd = Dir.send(@method)
- pwd.should == File.expand_path(pwd)
- end
-
- it "returns an absolute path even when chdir to a relative path" do
- Dir.chdir(".") do
- pwd = Dir.send(@method)
- File.directory?(pwd).should == true
- pwd.should == File.expand_path(pwd)
- end
- end
-
- with_feature :encoding do
- it "returns a String with the filesystem encoding" do
- enc = Dir.send(@method).encoding
- if @fs_encoding == Encoding::US_ASCII
- [Encoding::US_ASCII, Encoding::ASCII_8BIT].should include(enc)
- else
- enc.should equal(@fs_encoding)
- end
- end
- end
-end
diff --git a/spec/ruby/core/dir/tell_spec.rb b/spec/ruby/core/dir/tell_spec.rb
index fb9848153d..04f92a8ade 100644
--- a/spec/ruby/core/dir/tell_spec.rb
+++ b/spec/ruby/core/dir/tell_spec.rb
@@ -1,18 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/common', __FILE__)
-require File.expand_path('../shared/closed', __FILE__)
-require File.expand_path('../shared/pos', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/common'
+require_relative 'shared/pos'
describe "Dir#tell" do
- before :all do
- DirSpecs.create_mock_dirs
+ it "is an alias of Dir#pos" do
+ Dir.instance_method(:tell).should == Dir.instance_method(:pos)
end
-
- after :all do
- DirSpecs.delete_mock_dirs
- end
-
- it_behaves_like :dir_pos, :tell
-
- it_behaves_like :dir_closed, :tell
end
diff --git a/spec/ruby/core/dir/to_path_spec.rb b/spec/ruby/core/dir/to_path_spec.rb
index 85609fbfff..43e349c50e 100644
--- a/spec/ruby/core/dir/to_path_spec.rb
+++ b/spec/ruby/core/dir/to_path_spec.rb
@@ -1,6 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/common', __FILE__)
-require File.expand_path('../shared/path', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/common'
describe "Dir#to_path" do
before :all do
@@ -11,5 +10,28 @@ describe "Dir#to_path" do
DirSpecs.delete_mock_dirs
end
- it_behaves_like(:dir_path, :to_path)
+ it "returns the to_path that was supplied to .new or .open" do
+ dir = Dir.open DirSpecs.mock_dir
+ begin
+ dir.to_path.should == DirSpecs.mock_dir
+ ensure
+ dir.close rescue nil
+ end
+ end
+
+ it "returns the to_path even when called on a closed Dir instance" do
+ dir = Dir.open DirSpecs.mock_dir
+ dir.close
+ dir.to_path.should == DirSpecs.mock_dir
+ end
+
+ it "returns a String with the same encoding as the argument to .open" do
+ to_path = DirSpecs.mock_dir.force_encoding Encoding::IBM866
+ dir = Dir.open to_path
+ begin
+ dir.to_path.encoding.should.equal?(Encoding::IBM866)
+ ensure
+ dir.close
+ end
+ end
end
diff --git a/spec/ruby/core/dir/unlink_spec.rb b/spec/ruby/core/dir/unlink_spec.rb
index 4459bef56c..d9cd1b1a87 100644
--- a/spec/ruby/core/dir/unlink_spec.rb
+++ b/spec/ruby/core/dir/unlink_spec.rb
@@ -1,15 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/common', __FILE__)
-require File.expand_path('../shared/delete', __FILE__)
+require_relative '../../spec_helper'
describe "Dir.unlink" do
- before :all do
- DirSpecs.create_mock_dirs
+ it "is an alias of Dir.delete" do
+ Dir.method(:unlink).should == Dir.method(:delete)
end
-
- after :all do
- DirSpecs.delete_mock_dirs
- end
-
- it_behaves_like :dir_delete, :unlink
end
diff --git a/spec/ruby/core/encoding/_dump_spec.rb b/spec/ruby/core/encoding/_dump_spec.rb
index 4e8305712e..623fe88ec9 100644
--- a/spec/ruby/core/encoding/_dump_spec.rb
+++ b/spec/ruby/core/encoding/_dump_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Encoding#_dump" do
it "needs to be reviewed for spec completeness"
diff --git a/spec/ruby/core/encoding/_load_spec.rb b/spec/ruby/core/encoding/_load_spec.rb
index b8cdbaa32b..608098d34b 100644
--- a/spec/ruby/core/encoding/_load_spec.rb
+++ b/spec/ruby/core/encoding/_load_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Encoding._load" do
it "needs to be reviewed for spec completeness"
diff --git a/spec/ruby/core/encoding/aliases_spec.rb b/spec/ruby/core/encoding/aliases_spec.rb
index 327c8fa641..12c6c6cf85 100644
--- a/spec/ruby/core/encoding/aliases_spec.rb
+++ b/spec/ruby/core/encoding/aliases_spec.rb
@@ -1,45 +1,43 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
-with_feature :encoding do
- describe "Encoding.aliases" do
- it "returns a Hash" do
- Encoding.aliases.should be_an_instance_of(Hash)
- end
+describe "Encoding.aliases" do
+ it "returns a Hash" do
+ Encoding.aliases.should.instance_of?(Hash)
+ end
- it "has Strings as keys" do
- Encoding.aliases.keys.each do |key|
- key.should be_an_instance_of(String)
- end
+ it "has Strings as keys" do
+ Encoding.aliases.keys.each do |key|
+ key.should.instance_of?(String)
end
+ end
- it "has Strings as values" do
- Encoding.aliases.values.each do |value|
- value.should be_an_instance_of(String)
- end
+ it "has Strings as values" do
+ Encoding.aliases.values.each do |value|
+ value.should.instance_of?(String)
end
+ end
- it "has alias names as its keys" do
- Encoding.aliases.key?('BINARY').should be_true
- Encoding.aliases.key?('ASCII').should be_true
- end
+ it "has alias names as its keys" do
+ Encoding.aliases.key?('BINARY').should == true
+ Encoding.aliases.key?('ASCII').should == true
+ end
- it "has the names of the aliased encoding as its values" do
- Encoding.aliases['BINARY'].should == 'ASCII-8BIT'
- Encoding.aliases['ASCII'].should == 'US-ASCII'
- end
+ it "has the names of the aliased encoding as its values" do
+ Encoding.aliases['BINARY'].should == 'ASCII-8BIT'
+ Encoding.aliases['ASCII'].should == 'US-ASCII'
+ end
- it "has an 'external' key with the external default encoding as its value" do
- Encoding.aliases['external'].should == Encoding.default_external.name
- end
+ it "has an 'external' key with the external default encoding as its value" do
+ Encoding.aliases['external'].should == Encoding.default_external.name
+ end
- it "has a 'locale' key and its value equals to the name of the encoding finded by the locale charmap" do
- Encoding.aliases['locale'].should == Encoding.find(Encoding.locale_charmap).name
- end
+ it "has a 'locale' key and its value equals the name of the encoding found by the locale charmap" do
+ Encoding.aliases['locale'].should == Encoding.find(Encoding.locale_charmap).name
+ end
- it "only contains valid aliased encodings" do
- Encoding.aliases.each do |aliased, original|
- Encoding.find(aliased).should == Encoding.find(original)
- end
+ it "only contains valid aliased encodings" do
+ Encoding.aliases.each do |aliased, original|
+ Encoding.find(aliased).should == Encoding.find(original)
end
end
end
diff --git a/spec/ruby/core/encoding/ascii_compatible_spec.rb b/spec/ruby/core/encoding/ascii_compatible_spec.rb
index db3c31c9fb..04fc159bb8 100644
--- a/spec/ruby/core/encoding/ascii_compatible_spec.rb
+++ b/spec/ruby/core/encoding/ascii_compatible_spec.rb
@@ -1,13 +1,22 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
-with_feature :encoding do
- describe "Encoding#ascii_compatible?" do
- it "returns true if self represents an ASCII-compatible encoding" do
- Encoding::UTF_8.ascii_compatible?.should be_true
- end
+describe "Encoding#ascii_compatible?" do
+ it "returns true if self represents an ASCII-compatible encoding" do
+ Encoding::UTF_8.ascii_compatible?.should == true
+ end
+
+ it "returns false if self does not represent an ASCII-compatible encoding" do
+ Encoding::UTF_16LE.ascii_compatible?.should == false
+ end
+
+ it "returns false for UTF_16 and UTF_32" do
+ Encoding::UTF_16.should_not.ascii_compatible?
+ Encoding::UTF_32.should_not.ascii_compatible?
+ end
- it "returns false if self does not represent an ASCII-compatible encoding" do
- Encoding::UTF_16LE.ascii_compatible?.should be_false
+ it "is always false for dummy encodings" do
+ Encoding.list.select(&:dummy?).each do |encoding|
+ encoding.should_not.ascii_compatible?
end
end
end
diff --git a/spec/ruby/core/encoding/compatible_spec.rb b/spec/ruby/core/encoding/compatible_spec.rb
index 55e3d0fb4d..0d620e5bf3 100644
--- a/spec/ruby/core/encoding/compatible_spec.rb
+++ b/spec/ruby/core/encoding/compatible_spec.rb
@@ -1,381 +1,772 @@
-# -*- encoding: ascii-8bit -*-
+# encoding: binary
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
-with_feature :encoding do
- # TODO: add IO
+# TODO: add IO
- describe "Encoding.compatible? String, String" do
- describe "when the first's Encoding is valid US-ASCII" do
- before :each do
- @str = "abc".force_encoding Encoding::US_ASCII
- end
-
- it "returns US-ASCII when the second's is US-ASCII" do
- Encoding.compatible?(@str, "def".encode("us-ascii")).should == Encoding::US_ASCII
- end
-
- it "returns US-ASCII if the second String is ASCII-8BIT and ASCII only" do
- Encoding.compatible?(@str, "\x7f").should == Encoding::US_ASCII
- end
+describe "Encoding.compatible? String, String" do
+ describe "when the first's Encoding is valid US-ASCII" do
+ before :each do
+ @str = "abc".dup.force_encoding Encoding::US_ASCII
+ end
- it "returns ASCII-8BIT if the second String is ASCII-8BIT but not ASCII only" do
- Encoding.compatible?(@str, "\xff").should == Encoding::ASCII_8BIT
- end
+ it "returns US-ASCII when the second's is US-ASCII" do
+ Encoding.compatible?(@str, "def".encode("us-ascii")).should == Encoding::US_ASCII
+ end
- it "returns US-ASCII if the second String is UTF-8 and ASCII only" do
- Encoding.compatible?(@str, "\x7f".encode("utf-8")).should == Encoding::US_ASCII
- end
+ it "returns US-ASCII if the second String is BINARY and ASCII only" do
+ Encoding.compatible?(@str, "\x7f").should == Encoding::US_ASCII
+ end
- it "returns UTF-8 if the second String is UTF-8 but not ASCII only" do
- Encoding.compatible?(@str, "\u3042".encode("utf-8")).should == Encoding::UTF_8
- end
+ it "returns BINARY if the second String is BINARY but not ASCII only" do
+ Encoding.compatible?(@str, "\xff").should == Encoding::BINARY
end
- describe "when the first's Encoding is ASCII compatible and ASCII only" do
- it "returns the first's Encoding if the second is ASCII compatible and ASCII only" do
- [ [Encoding, "abc".force_encoding("UTF-8"), "123".force_encoding("Shift_JIS"), Encoding::UTF_8],
- [Encoding, "123".force_encoding("Shift_JIS"), "abc".force_encoding("UTF-8"), Encoding::Shift_JIS]
- ].should be_computed_by(:compatible?)
- end
+ it "returns US-ASCII if the second String is UTF-8 and ASCII only" do
+ Encoding.compatible?(@str, "\x7f".encode("utf-8")).should == Encoding::US_ASCII
+ end
- it "returns the first's Encoding if the second is ASCII compatible and ASCII only" do
- [ [Encoding, "abc".force_encoding("ASCII-8BIT"), "123".force_encoding("US-ASCII"), Encoding::ASCII_8BIT],
- [Encoding, "123".force_encoding("US-ASCII"), "abc".force_encoding("ASCII-8BIT"), Encoding::US_ASCII]
- ].should be_computed_by(:compatible?)
- end
+ it "returns UTF-8 if the second String is UTF-8 but not ASCII only" do
+ Encoding.compatible?(@str, "\u3042".encode("utf-8")).should == Encoding::UTF_8
+ end
+ end
- it "returns the second's Encoding if the second is ASCII compatible but not ASCII only" do
- [ [Encoding, "abc".force_encoding("UTF-8"), "\xff".force_encoding("Shift_JIS"), Encoding::Shift_JIS],
- [Encoding, "123".force_encoding("Shift_JIS"), "\xff".force_encoding("UTF-8"), Encoding::UTF_8],
- [Encoding, "abc".force_encoding("ASCII-8BIT"), "\xff".force_encoding("US-ASCII"), Encoding::US_ASCII],
- [Encoding, "123".force_encoding("US-ASCII"), "\xff".force_encoding("ASCII-8BIT"), Encoding::ASCII_8BIT],
- ].should be_computed_by(:compatible?)
- end
+ describe "when the first's Encoding is ASCII compatible and ASCII only" do
+ it "returns the first's Encoding if the second is ASCII compatible and ASCII only" do
+ [ [Encoding, "abc".dup.force_encoding("UTF-8"), "123".dup.force_encoding("Shift_JIS"), Encoding::UTF_8],
+ [Encoding, "123".dup.force_encoding("Shift_JIS"), "abc".dup.force_encoding("UTF-8"), Encoding::Shift_JIS]
+ ].should be_computed_by(:compatible?)
+ end
- it "returns nil if the second's Encoding is not ASCII compatible" do
- a = "abc".force_encoding("UTF-8")
- b = "123".force_encoding("UTF-16LE")
- Encoding.compatible?(a, b).should be_nil
- end
+ it "returns the first's Encoding if the second is ASCII compatible and ASCII only" do
+ [ [Encoding, "abc".dup.force_encoding("BINARY"), "123".dup.force_encoding("US-ASCII"), Encoding::BINARY],
+ [Encoding, "123".dup.force_encoding("US-ASCII"), "abc".dup.force_encoding("BINARY"), Encoding::US_ASCII]
+ ].should be_computed_by(:compatible?)
end
- describe "when the first's Encoding is ASCII compatible but not ASCII only" do
- it "returns the first's Encoding if the second's is valid US-ASCII" do
- Encoding.compatible?("\xff", "def".encode("us-ascii")).should == Encoding::ASCII_8BIT
- end
+ it "returns the second's Encoding if the second is ASCII compatible but not ASCII only" do
+ [ [Encoding, "abc".dup.force_encoding("UTF-8"), "\xff".dup.force_encoding("Shift_JIS"), Encoding::Shift_JIS],
+ [Encoding, "123".dup.force_encoding("Shift_JIS"), "\xff".dup.force_encoding("UTF-8"), Encoding::UTF_8],
+ [Encoding, "abc".dup.force_encoding("BINARY"), "\xff".dup.force_encoding("US-ASCII"), Encoding::US_ASCII],
+ [Encoding, "123".dup.force_encoding("US-ASCII"), "\xff".dup.force_encoding("BINARY"), Encoding::BINARY],
+ ].should be_computed_by(:compatible?)
+ end
- it "returns the first's Encoding if the second's is UTF-8 and ASCII only" do
- Encoding.compatible?("\xff", "\u{7f}".encode("utf-8")).should == Encoding::ASCII_8BIT
- end
+ it "returns nil if the second's Encoding is not ASCII compatible" do
+ a = "abc".dup.force_encoding("UTF-8")
+ b = "1234".dup.force_encoding("UTF-16LE")
+ Encoding.compatible?(a, b).should == nil
+ end
+ end
- it "returns nil if the second encoding is ASCII compatible but neither String's encoding is ASCII only" do
- Encoding.compatible?("\xff", "\u3042".encode("utf-8")).should be_nil
- end
+ describe "when the first's Encoding is ASCII compatible but not ASCII only" do
+ it "returns the first's Encoding if the second's is valid US-ASCII" do
+ Encoding.compatible?("\xff", "def".encode("us-ascii")).should == Encoding::BINARY
end
- describe "when the first's Encoding is not ASCII compatible" do
- before :each do
- @str = "abc".force_encoding Encoding::UTF_7
- end
+ it "returns the first's Encoding if the second's is UTF-8 and ASCII only" do
+ Encoding.compatible?("\xff", "\u{7f}".encode("utf-8")).should == Encoding::BINARY
+ end
- it "returns nil when the second String is US-ASCII" do
- Encoding.compatible?(@str, "def".encode("us-ascii")).should be_nil
- end
+ it "returns nil if the second encoding is ASCII compatible but neither String's encoding is ASCII only" do
+ Encoding.compatible?("\xff", "\u3042".encode("utf-8")).should == nil
+ end
+ end
- it "returns nil when the second String is ASCII-8BIT and ASCII only" do
- Encoding.compatible?(@str, "\x7f").should be_nil
- end
+ describe "when the first's Encoding is not ASCII compatible" do
+ before :each do
+ @str = "abc".dup.force_encoding Encoding::UTF_7
+ end
- it "returns nil when the second String is ASCII-8BIT but not ASCII only" do
- Encoding.compatible?(@str, "\xff").should be_nil
- end
+ it "returns nil when the second String is US-ASCII" do
+ Encoding.compatible?(@str, "def".encode("us-ascii")).should == nil
+ end
- it "returns the Encoding when the second's Encoding is not ASCII compatible but the same as the first's Encoding" do
- encoding = Encoding.compatible?(@str, "def".force_encoding("utf-7"))
- encoding.should == Encoding::UTF_7
- end
+ it "returns nil when the second String is BINARY and ASCII only" do
+ Encoding.compatible?(@str, "\x7f").should == nil
end
- describe "when the first's Encoding is invalid" do
- before :each do
- @str = "\xff".force_encoding Encoding::UTF_8
- end
+ it "returns nil when the second String is BINARY but not ASCII only" do
+ Encoding.compatible?(@str, "\xff").should == nil
+ end
- it "returns the first's Encoding when the second's Encoding is US-ASCII" do
- Encoding.compatible?(@str, "def".encode("us-ascii")).should == Encoding::UTF_8
- end
+ it "returns the Encoding when the second's Encoding is not ASCII compatible but the same as the first's Encoding" do
+ encoding = Encoding.compatible?(@str, "def".dup.force_encoding("utf-7"))
+ encoding.should == Encoding::UTF_7
+ end
+ end
- it "returns the first's Encoding when the second String is ASCII only" do
- Encoding.compatible?(@str, "\x7f").should == Encoding::UTF_8
- end
+ describe "when the first's Encoding is invalid" do
+ before :each do
+ @str = "\xff".dup.force_encoding Encoding::UTF_8
+ end
- it "returns nil when the second's Encoding is ASCII-8BIT but not ASCII only" do
- Encoding.compatible?(@str, "\xff").should be_nil
- end
+ it "returns the first's Encoding when the second's Encoding is US-ASCII" do
+ Encoding.compatible?(@str, "def".encode("us-ascii")).should == Encoding::UTF_8
+ end
- it "returns nil when the second's Encoding is invalid and ASCII only" do
- Encoding.compatible?(@str, "\x7f".force_encoding("utf-16be")).should be_nil
- end
+ it "returns the first's Encoding when the second String is ASCII only" do
+ Encoding.compatible?(@str, "\x7f").should == Encoding::UTF_8
+ end
- it "returns nil when the second's Encoding is invalid and not ASCII only" do
- Encoding.compatible?(@str, "\xff".force_encoding("utf-16be")).should be_nil
- end
+ it "returns nil when the second's Encoding is BINARY but not ASCII only" do
+ Encoding.compatible?(@str, "\xff").should == nil
+ end
- it "returns the Encoding when the second's Encoding is invalid but the same as the first" do
- Encoding.compatible?(@str, @str).should == Encoding::UTF_8
- end
+ it "returns nil when the second's Encoding is invalid and ASCII only" do
+ Encoding.compatible?(@str, "\x7f\x7f".dup.force_encoding("utf-16be")).should == nil
end
- describe "when the first String is empty and the second is not" do
- describe "and the first's Encoding is ASCII compatible" do
- before :each do
- @str = "".force_encoding("utf-8")
- end
+ it "returns nil when the second's Encoding is invalid and not ASCII only" do
+ Encoding.compatible?(@str, "\xff\xff".dup.force_encoding("utf-16be")).should == nil
+ end
- it "returns the first's encoding when the second String is ASCII only" do
- Encoding.compatible?(@str, "def".encode("us-ascii")).should == Encoding::UTF_8
- end
+ it "returns the Encoding when the second's Encoding is invalid but the same as the first" do
+ Encoding.compatible?(@str, @str).should == Encoding::UTF_8
+ end
+ end
- it "returns the second's encoding when the second String is not ASCII only" do
- Encoding.compatible?(@str, "def".encode("utf-32le")).should == Encoding::UTF_32LE
- end
+ describe "when the first String is empty and the second is not" do
+ describe "and the first's Encoding is ASCII compatible" do
+ before :each do
+ @str = "".dup.force_encoding("utf-8")
end
- describe "when the first's Encoding is not ASCII compatible" do
- before :each do
- @str = "".force_encoding Encoding::UTF_7
- end
+ it "returns the first's encoding when the second String is ASCII only" do
+ Encoding.compatible?(@str, "def".encode("us-ascii")).should == Encoding::UTF_8
+ end
- it "returns the second string's encoding" do
- Encoding.compatible?(@str, "def".encode("us-ascii")).should == Encoding::US_ASCII
- end
+ it "returns the second's encoding when the second String is not ASCII only" do
+ Encoding.compatible?(@str, "def".encode("utf-32le")).should == Encoding::UTF_32LE
end
end
- describe "when the second String is empty" do
+ describe "when the first's Encoding is not ASCII compatible" do
before :each do
- @str = "abc".force_encoding("utf-7")
+ @str = "".dup.force_encoding Encoding::UTF_7
end
- it "returns the first Encoding" do
- Encoding.compatible?(@str, "").should == Encoding::UTF_7
+ it "returns the second string's encoding" do
+ Encoding.compatible?(@str, "def".encode("us-ascii")).should == Encoding::US_ASCII
end
end
end
- describe "Encoding.compatible? String, Regexp" do
- it "returns US-ASCII if both are US-ASCII" do
- str = "abc".force_encoding("us-ascii")
- Encoding.compatible?(str, /abc/).should == Encoding::US_ASCII
+ describe "when the second String is empty" do
+ before :each do
+ @str = "abc".dup.force_encoding("utf-7")
end
- it "returns the String's Encoding if it is not US-ASCII but both are ASCII only" do
- [ [Encoding, "abc", Encoding::ASCII_8BIT],
- [Encoding, "abc".encode("utf-8"), Encoding::UTF_8],
- [Encoding, "abc".encode("euc-jp"), Encoding::EUC_JP],
- [Encoding, "abc".encode("shift_jis"), Encoding::Shift_JIS],
- ].should be_computed_by(:compatible?, /abc/)
+ it "returns the first Encoding" do
+ Encoding.compatible?(@str, "").should == Encoding::UTF_7
end
+ end
- it "returns the String's Encoding if the String is not ASCII only" do
- [ [Encoding, "\xff", Encoding::ASCII_8BIT],
- [Encoding, "\u3042".encode("utf-8"), Encoding::UTF_8],
- [Encoding, "\xa4\xa2".force_encoding("euc-jp"), Encoding::EUC_JP],
- [Encoding, "\x82\xa0".force_encoding("shift_jis"), Encoding::Shift_JIS],
- ].should be_computed_by(:compatible?, /abc/)
+ # Encoding negotiation depends on whether encodings are ASCII-compatible, empty
+ # and contain only ASCII characters (that take 7 bits). Check US-ASCII, UTF-8 and
+ # BINARY encodings (as most common) as well as an ASCII-compatible, a non-ASCII-compatible and a dummy
+ # encodings in all possible combinations.
+ describe "compatibility matrix" do
+
+# Use the following script to regenerate the matrix:
+#
+# ```
+# # encoding: binary
+#
+# ENCODINGS = [
+# "US-ASCII",
+# "UTF-8",
+# "ASCII-8BIT",
+# "ISO-8859-1", # ASCII-compatible
+# "UTF-16BE", # non-ASCII-compatible
+# "ISO-2022-JP" # dummy
+# ]
+#
+# TYPES = [:empty, :"7bits", :non7bits]
+#
+# VALUES = {
+# empty: "",
+# :"7bits" => "\x01\x01",
+# non7bits: "\x01\x81"
+# }
+#
+# ENCODINGS.product(TYPES, ENCODINGS, TYPES).each do |encoding1, type1, encoding2, type2|
+# value1 = VALUES[type1].dup.force_encoding(encoding1)
+# value2 = VALUES[type2].dup.force_encoding(encoding2)
+#
+# result_encoding = Encoding.compatible?(value1, value2)
+#
+# puts "[#{encoding1.inspect}, #{value1.inspect}, #{encoding2.inspect}, #{value2.inspect}, #{result_encoding&.name.inspect}],"
+# end
+# ```
+
+ matrix = [
+ ["US-ASCII", "", "US-ASCII", "", "US-ASCII"],
+ ["US-ASCII", "", "US-ASCII", "\x01\x01", "US-ASCII"],
+ ["US-ASCII", "", "US-ASCII", "\x01\x81", "US-ASCII"],
+ ["US-ASCII", "", "UTF-8", "", "US-ASCII"],
+ ["US-ASCII", "", "UTF-8", "\u0001\u0001", "US-ASCII"],
+ ["US-ASCII", "", "UTF-8", "\u0001\x81", "UTF-8"],
+ ["US-ASCII", "", "ASCII-8BIT", "", "US-ASCII"],
+ ["US-ASCII", "", "ASCII-8BIT", "\x01\x01", "US-ASCII"],
+ ["US-ASCII", "", "ASCII-8BIT", "\x01\x81", "ASCII-8BIT"],
+ ["US-ASCII", "", "ISO-8859-1", "", "US-ASCII"],
+ ["US-ASCII", "", "ISO-8859-1", "\x01\x01", "US-ASCII"],
+ ["US-ASCII", "", "ISO-8859-1", "\x01\x81", "ISO-8859-1"],
+ ["US-ASCII", "", "UTF-16BE", "", "US-ASCII"],
+ ["US-ASCII", "", "UTF-16BE", "\u0101", "UTF-16BE"],
+ ["US-ASCII", "", "UTF-16BE", "\u0181", "UTF-16BE"],
+ ["US-ASCII", "", "ISO-2022-JP", "", "US-ASCII"],
+ ["US-ASCII", "", "ISO-2022-JP", "\x01\x01", "ISO-2022-JP"],
+ ["US-ASCII", "", "ISO-2022-JP", "\x01\x81", "ISO-2022-JP"],
+ ["US-ASCII", "\x01\x01", "US-ASCII", "", "US-ASCII"],
+ ["US-ASCII", "\x01\x01", "US-ASCII", "\x01\x01", "US-ASCII"],
+ ["US-ASCII", "\x01\x01", "US-ASCII", "\x01\x81", "US-ASCII"],
+ ["US-ASCII", "\x01\x01", "UTF-8", "", "US-ASCII"],
+ ["US-ASCII", "\x01\x01", "UTF-8", "\u0001\u0001", "US-ASCII"],
+ ["US-ASCII", "\x01\x01", "UTF-8", "\u0001\x81", "UTF-8"],
+ ["US-ASCII", "\x01\x01", "ASCII-8BIT", "", "US-ASCII"],
+ ["US-ASCII", "\x01\x01", "ASCII-8BIT", "\x01\x01", "US-ASCII"],
+ ["US-ASCII", "\x01\x01", "ASCII-8BIT", "\x01\x81", "ASCII-8BIT"],
+ ["US-ASCII", "\x01\x01", "ISO-8859-1", "", "US-ASCII"],
+ ["US-ASCII", "\x01\x01", "ISO-8859-1", "\x01\x01", "US-ASCII"],
+ ["US-ASCII", "\x01\x01", "ISO-8859-1", "\x01\x81", "ISO-8859-1"],
+ ["US-ASCII", "\x01\x01", "UTF-16BE", "", "US-ASCII"],
+ ["US-ASCII", "\x01\x01", "UTF-16BE", "\u0101", nil],
+ ["US-ASCII", "\x01\x01", "UTF-16BE", "\u0181", nil],
+ ["US-ASCII", "\x01\x01", "ISO-2022-JP", "", "US-ASCII"],
+ ["US-ASCII", "\x01\x01", "ISO-2022-JP", "\x01\x01", nil],
+ ["US-ASCII", "\x01\x01", "ISO-2022-JP", "\x01\x81", nil],
+ ["US-ASCII", "\x01\x81", "US-ASCII", "", "US-ASCII"],
+ ["US-ASCII", "\x01\x81", "US-ASCII", "\x01\x01", "US-ASCII"],
+ ["US-ASCII", "\x01\x81", "US-ASCII", "\x01\x81", "US-ASCII"],
+ ["US-ASCII", "\x01\x81", "UTF-8", "", "US-ASCII"],
+ ["US-ASCII", "\x01\x81", "UTF-8", "\u0001\u0001", "US-ASCII"],
+ ["US-ASCII", "\x01\x81", "UTF-8", "\u0001\x81", nil],
+ ["US-ASCII", "\x01\x81", "ASCII-8BIT", "", "US-ASCII"],
+ ["US-ASCII", "\x01\x81", "ASCII-8BIT", "\x01\x01", "US-ASCII"],
+ ["US-ASCII", "\x01\x81", "ASCII-8BIT", "\x01\x81", nil],
+ ["US-ASCII", "\x01\x81", "ISO-8859-1", "", "US-ASCII"],
+ ["US-ASCII", "\x01\x81", "ISO-8859-1", "\x01\x01", "US-ASCII"],
+ ["US-ASCII", "\x01\x81", "ISO-8859-1", "\x01\x81", nil],
+ ["US-ASCII", "\x01\x81", "UTF-16BE", "", "US-ASCII"],
+ ["US-ASCII", "\x01\x81", "UTF-16BE", "\u0101", nil],
+ ["US-ASCII", "\x01\x81", "UTF-16BE", "\u0181", nil],
+ ["US-ASCII", "\x01\x81", "ISO-2022-JP", "", "US-ASCII"],
+ ["US-ASCII", "\x01\x81", "ISO-2022-JP", "\x01\x01", nil],
+ ["US-ASCII", "\x01\x81", "ISO-2022-JP", "\x01\x81", nil],
+ ["UTF-8", "", "US-ASCII", "", "UTF-8"],
+ ["UTF-8", "", "US-ASCII", "\x01\x01", "UTF-8"],
+ ["UTF-8", "", "US-ASCII", "\x01\x81", "US-ASCII"],
+ ["UTF-8", "", "UTF-8", "", "UTF-8"],
+ ["UTF-8", "", "UTF-8", "\u0001\u0001", "UTF-8"],
+ ["UTF-8", "", "UTF-8", "\u0001\x81", "UTF-8"],
+ ["UTF-8", "", "ASCII-8BIT", "", "UTF-8"],
+ ["UTF-8", "", "ASCII-8BIT", "\x01\x01", "UTF-8"],
+ ["UTF-8", "", "ASCII-8BIT", "\x01\x81", "ASCII-8BIT"],
+ ["UTF-8", "", "ISO-8859-1", "", "UTF-8"],
+ ["UTF-8", "", "ISO-8859-1", "\x01\x01", "UTF-8"],
+ ["UTF-8", "", "ISO-8859-1", "\x01\x81", "ISO-8859-1"],
+ ["UTF-8", "", "UTF-16BE", "", "UTF-8"],
+ ["UTF-8", "", "UTF-16BE", "\u0101", "UTF-16BE"],
+ ["UTF-8", "", "UTF-16BE", "\u0181", "UTF-16BE"],
+ ["UTF-8", "", "ISO-2022-JP", "", "UTF-8"],
+ ["UTF-8", "", "ISO-2022-JP", "\x01\x01", "ISO-2022-JP"],
+ ["UTF-8", "", "ISO-2022-JP", "\x01\x81", "ISO-2022-JP"],
+ ["UTF-8", "\u0001\u0001", "US-ASCII", "", "UTF-8"],
+ ["UTF-8", "\u0001\u0001", "US-ASCII", "\x01\x01", "UTF-8"],
+ ["UTF-8", "\u0001\u0001", "US-ASCII", "\x01\x81", "US-ASCII"],
+ ["UTF-8", "\u0001\u0001", "UTF-8", "", "UTF-8"],
+ ["UTF-8", "\u0001\u0001", "UTF-8", "\u0001\u0001", "UTF-8"],
+ ["UTF-8", "\u0001\u0001", "UTF-8", "\u0001\x81", "UTF-8"],
+ ["UTF-8", "\u0001\u0001", "ASCII-8BIT", "", "UTF-8"],
+ ["UTF-8", "\u0001\u0001", "ASCII-8BIT", "\x01\x01", "UTF-8"],
+ ["UTF-8", "\u0001\u0001", "ASCII-8BIT", "\x01\x81", "ASCII-8BIT"],
+ ["UTF-8", "\u0001\u0001", "ISO-8859-1", "", "UTF-8"],
+ ["UTF-8", "\u0001\u0001", "ISO-8859-1", "\x01\x01", "UTF-8"],
+ ["UTF-8", "\u0001\u0001", "ISO-8859-1", "\x01\x81", "ISO-8859-1"],
+ ["UTF-8", "\u0001\u0001", "UTF-16BE", "", "UTF-8"],
+ ["UTF-8", "\u0001\u0001", "UTF-16BE", "\u0101", nil],
+ ["UTF-8", "\u0001\u0001", "UTF-16BE", "\u0181", nil],
+ ["UTF-8", "\u0001\u0001", "ISO-2022-JP", "", "UTF-8"],
+ ["UTF-8", "\u0001\u0001", "ISO-2022-JP", "\x01\x01", nil],
+ ["UTF-8", "\u0001\u0001", "ISO-2022-JP", "\x01\x81", nil],
+ ["UTF-8", "\u0001\x81", "US-ASCII", "", "UTF-8"],
+ ["UTF-8", "\u0001\x81", "US-ASCII", "\x01\x01", "UTF-8"],
+ ["UTF-8", "\u0001\x81", "US-ASCII", "\x01\x81", nil],
+ ["UTF-8", "\u0001\x81", "UTF-8", "", "UTF-8"],
+ ["UTF-8", "\u0001\x81", "UTF-8", "\u0001\u0001", "UTF-8"],
+ ["UTF-8", "\u0001\x81", "UTF-8", "\u0001\x81", "UTF-8"],
+ ["UTF-8", "\u0001\x81", "ASCII-8BIT", "", "UTF-8"],
+ ["UTF-8", "\u0001\x81", "ASCII-8BIT", "\x01\x01", "UTF-8"],
+ ["UTF-8", "\u0001\x81", "ASCII-8BIT", "\x01\x81", nil],
+ ["UTF-8", "\u0001\x81", "ISO-8859-1", "", "UTF-8"],
+ ["UTF-8", "\u0001\x81", "ISO-8859-1", "\x01\x01", "UTF-8"],
+ ["UTF-8", "\u0001\x81", "ISO-8859-1", "\x01\x81", nil],
+ ["UTF-8", "\u0001\x81", "UTF-16BE", "", "UTF-8"],
+ ["UTF-8", "\u0001\x81", "UTF-16BE", "\u0101", nil],
+ ["UTF-8", "\u0001\x81", "UTF-16BE", "\u0181", nil],
+ ["UTF-8", "\u0001\x81", "ISO-2022-JP", "", "UTF-8"],
+ ["UTF-8", "\u0001\x81", "ISO-2022-JP", "\x01\x01", nil],
+ ["UTF-8", "\u0001\x81", "ISO-2022-JP", "\x01\x81", nil],
+ ["ASCII-8BIT", "", "US-ASCII", "", "ASCII-8BIT"],
+ ["ASCII-8BIT", "", "US-ASCII", "\x01\x01", "ASCII-8BIT"],
+ ["ASCII-8BIT", "", "US-ASCII", "\x01\x81", "US-ASCII"],
+ ["ASCII-8BIT", "", "UTF-8", "", "ASCII-8BIT"],
+ ["ASCII-8BIT", "", "UTF-8", "\u0001\u0001", "ASCII-8BIT"],
+ ["ASCII-8BIT", "", "UTF-8", "\u0001\x81", "UTF-8"],
+ ["ASCII-8BIT", "", "ASCII-8BIT", "", "ASCII-8BIT"],
+ ["ASCII-8BIT", "", "ASCII-8BIT", "\x01\x01", "ASCII-8BIT"],
+ ["ASCII-8BIT", "", "ASCII-8BIT", "\x01\x81", "ASCII-8BIT"],
+ ["ASCII-8BIT", "", "ISO-8859-1", "", "ASCII-8BIT"],
+ ["ASCII-8BIT", "", "ISO-8859-1", "\x01\x01", "ASCII-8BIT"],
+ ["ASCII-8BIT", "", "ISO-8859-1", "\x01\x81", "ISO-8859-1"],
+ ["ASCII-8BIT", "", "UTF-16BE", "", "ASCII-8BIT"],
+ ["ASCII-8BIT", "", "UTF-16BE", "\u0101", "UTF-16BE"],
+ ["ASCII-8BIT", "", "UTF-16BE", "\u0181", "UTF-16BE"],
+ ["ASCII-8BIT", "", "ISO-2022-JP", "", "ASCII-8BIT"],
+ ["ASCII-8BIT", "", "ISO-2022-JP", "\x01\x01", "ISO-2022-JP"],
+ ["ASCII-8BIT", "", "ISO-2022-JP", "\x01\x81", "ISO-2022-JP"],
+ ["ASCII-8BIT", "\x01\x01", "US-ASCII", "", "ASCII-8BIT"],
+ ["ASCII-8BIT", "\x01\x01", "US-ASCII", "\x01\x01", "ASCII-8BIT"],
+ ["ASCII-8BIT", "\x01\x01", "US-ASCII", "\x01\x81", "US-ASCII"],
+ ["ASCII-8BIT", "\x01\x01", "UTF-8", "", "ASCII-8BIT"],
+ ["ASCII-8BIT", "\x01\x01", "UTF-8", "\u0001\u0001", "ASCII-8BIT"],
+ ["ASCII-8BIT", "\x01\x01", "UTF-8", "\u0001\x81", "UTF-8"],
+ ["ASCII-8BIT", "\x01\x01", "ASCII-8BIT", "", "ASCII-8BIT"],
+ ["ASCII-8BIT", "\x01\x01", "ASCII-8BIT", "\x01\x01", "ASCII-8BIT"],
+ ["ASCII-8BIT", "\x01\x01", "ASCII-8BIT", "\x01\x81", "ASCII-8BIT"],
+ ["ASCII-8BIT", "\x01\x01", "ISO-8859-1", "", "ASCII-8BIT"],
+ ["ASCII-8BIT", "\x01\x01", "ISO-8859-1", "\x01\x01", "ASCII-8BIT"],
+ ["ASCII-8BIT", "\x01\x01", "ISO-8859-1", "\x01\x81", "ISO-8859-1"],
+ ["ASCII-8BIT", "\x01\x01", "UTF-16BE", "", "ASCII-8BIT"],
+ ["ASCII-8BIT", "\x01\x01", "UTF-16BE", "\u0101", nil],
+ ["ASCII-8BIT", "\x01\x01", "UTF-16BE", "\u0181", nil],
+ ["ASCII-8BIT", "\x01\x01", "ISO-2022-JP", "", "ASCII-8BIT"],
+ ["ASCII-8BIT", "\x01\x01", "ISO-2022-JP", "\x01\x01", nil],
+ ["ASCII-8BIT", "\x01\x01", "ISO-2022-JP", "\x01\x81", nil],
+ ["ASCII-8BIT", "\x01\x81", "US-ASCII", "", "ASCII-8BIT"],
+ ["ASCII-8BIT", "\x01\x81", "US-ASCII", "\x01\x01", "ASCII-8BIT"],
+ ["ASCII-8BIT", "\x01\x81", "US-ASCII", "\x01\x81", nil],
+ ["ASCII-8BIT", "\x01\x81", "UTF-8", "", "ASCII-8BIT"],
+ ["ASCII-8BIT", "\x01\x81", "UTF-8", "\u0001\u0001", "ASCII-8BIT"],
+ ["ASCII-8BIT", "\x01\x81", "UTF-8", "\u0001\x81", nil],
+ ["ASCII-8BIT", "\x01\x81", "ASCII-8BIT", "", "ASCII-8BIT"],
+ ["ASCII-8BIT", "\x01\x81", "ASCII-8BIT", "\x01\x01", "ASCII-8BIT"],
+ ["ASCII-8BIT", "\x01\x81", "ASCII-8BIT", "\x01\x81", "ASCII-8BIT"],
+ ["ASCII-8BIT", "\x01\x81", "ISO-8859-1", "", "ASCII-8BIT"],
+ ["ASCII-8BIT", "\x01\x81", "ISO-8859-1", "\x01\x01", "ASCII-8BIT"],
+ ["ASCII-8BIT", "\x01\x81", "ISO-8859-1", "\x01\x81", nil],
+ ["ASCII-8BIT", "\x01\x81", "UTF-16BE", "", "ASCII-8BIT"],
+ ["ASCII-8BIT", "\x01\x81", "UTF-16BE", "\u0101", nil],
+ ["ASCII-8BIT", "\x01\x81", "UTF-16BE", "\u0181", nil],
+ ["ASCII-8BIT", "\x01\x81", "ISO-2022-JP", "", "ASCII-8BIT"],
+ ["ASCII-8BIT", "\x01\x81", "ISO-2022-JP", "\x01\x01", nil],
+ ["ASCII-8BIT", "\x01\x81", "ISO-2022-JP", "\x01\x81", nil],
+ ["ISO-8859-1", "", "US-ASCII", "", "ISO-8859-1"],
+ ["ISO-8859-1", "", "US-ASCII", "\x01\x01", "ISO-8859-1"],
+ ["ISO-8859-1", "", "US-ASCII", "\x01\x81", "US-ASCII"],
+ ["ISO-8859-1", "", "UTF-8", "", "ISO-8859-1"],
+ ["ISO-8859-1", "", "UTF-8", "\u0001\u0001", "ISO-8859-1"],
+ ["ISO-8859-1", "", "UTF-8", "\u0001\x81", "UTF-8"],
+ ["ISO-8859-1", "", "ASCII-8BIT", "", "ISO-8859-1"],
+ ["ISO-8859-1", "", "ASCII-8BIT", "\x01\x01", "ISO-8859-1"],
+ ["ISO-8859-1", "", "ASCII-8BIT", "\x01\x81", "ASCII-8BIT"],
+ ["ISO-8859-1", "", "ISO-8859-1", "", "ISO-8859-1"],
+ ["ISO-8859-1", "", "ISO-8859-1", "\x01\x01", "ISO-8859-1"],
+ ["ISO-8859-1", "", "ISO-8859-1", "\x01\x81", "ISO-8859-1"],
+ ["ISO-8859-1", "", "UTF-16BE", "", "ISO-8859-1"],
+ ["ISO-8859-1", "", "UTF-16BE", "\u0101", "UTF-16BE"],
+ ["ISO-8859-1", "", "UTF-16BE", "\u0181", "UTF-16BE"],
+ ["ISO-8859-1", "", "ISO-2022-JP", "", "ISO-8859-1"],
+ ["ISO-8859-1", "", "ISO-2022-JP", "\x01\x01", "ISO-2022-JP"],
+ ["ISO-8859-1", "", "ISO-2022-JP", "\x01\x81", "ISO-2022-JP"],
+ ["ISO-8859-1", "\x01\x01", "US-ASCII", "", "ISO-8859-1"],
+ ["ISO-8859-1", "\x01\x01", "US-ASCII", "\x01\x01", "ISO-8859-1"],
+ ["ISO-8859-1", "\x01\x01", "US-ASCII", "\x01\x81", "US-ASCII"],
+ ["ISO-8859-1", "\x01\x01", "UTF-8", "", "ISO-8859-1"],
+ ["ISO-8859-1", "\x01\x01", "UTF-8", "\u0001\u0001", "ISO-8859-1"],
+ ["ISO-8859-1", "\x01\x01", "UTF-8", "\u0001\x81", "UTF-8"],
+ ["ISO-8859-1", "\x01\x01", "ASCII-8BIT", "", "ISO-8859-1"],
+ ["ISO-8859-1", "\x01\x01", "ASCII-8BIT", "\x01\x01", "ISO-8859-1"],
+ ["ISO-8859-1", "\x01\x01", "ASCII-8BIT", "\x01\x81", "ASCII-8BIT"],
+ ["ISO-8859-1", "\x01\x01", "ISO-8859-1", "", "ISO-8859-1"],
+ ["ISO-8859-1", "\x01\x01", "ISO-8859-1", "\x01\x01", "ISO-8859-1"],
+ ["ISO-8859-1", "\x01\x01", "ISO-8859-1", "\x01\x81", "ISO-8859-1"],
+ ["ISO-8859-1", "\x01\x01", "UTF-16BE", "", "ISO-8859-1"],
+ ["ISO-8859-1", "\x01\x01", "UTF-16BE", "\u0101", nil],
+ ["ISO-8859-1", "\x01\x01", "UTF-16BE", "\u0181", nil],
+ ["ISO-8859-1", "\x01\x01", "ISO-2022-JP", "", "ISO-8859-1"],
+ ["ISO-8859-1", "\x01\x01", "ISO-2022-JP", "\x01\x01", nil],
+ ["ISO-8859-1", "\x01\x01", "ISO-2022-JP", "\x01\x81", nil],
+ ["ISO-8859-1", "\x01\x81", "US-ASCII", "", "ISO-8859-1"],
+ ["ISO-8859-1", "\x01\x81", "US-ASCII", "\x01\x01", "ISO-8859-1"],
+ ["ISO-8859-1", "\x01\x81", "US-ASCII", "\x01\x81", nil],
+ ["ISO-8859-1", "\x01\x81", "UTF-8", "", "ISO-8859-1"],
+ ["ISO-8859-1", "\x01\x81", "UTF-8", "\u0001\u0001", "ISO-8859-1"],
+ ["ISO-8859-1", "\x01\x81", "UTF-8", "\u0001\x81", nil],
+ ["ISO-8859-1", "\x01\x81", "ASCII-8BIT", "", "ISO-8859-1"],
+ ["ISO-8859-1", "\x01\x81", "ASCII-8BIT", "\x01\x01", "ISO-8859-1"],
+ ["ISO-8859-1", "\x01\x81", "ASCII-8BIT", "\x01\x81", nil],
+ ["ISO-8859-1", "\x01\x81", "ISO-8859-1", "", "ISO-8859-1"],
+ ["ISO-8859-1", "\x01\x81", "ISO-8859-1", "\x01\x01", "ISO-8859-1"],
+ ["ISO-8859-1", "\x01\x81", "ISO-8859-1", "\x01\x81", "ISO-8859-1"],
+ ["ISO-8859-1", "\x01\x81", "UTF-16BE", "", "ISO-8859-1"],
+ ["ISO-8859-1", "\x01\x81", "UTF-16BE", "\u0101", nil],
+ ["ISO-8859-1", "\x01\x81", "UTF-16BE", "\u0181", nil],
+ ["ISO-8859-1", "\x01\x81", "ISO-2022-JP", "", "ISO-8859-1"],
+ ["ISO-8859-1", "\x01\x81", "ISO-2022-JP", "\x01\x01", nil],
+ ["ISO-8859-1", "\x01\x81", "ISO-2022-JP", "\x01\x81", nil],
+ ["UTF-16BE", "", "US-ASCII", "", "UTF-16BE"],
+ ["UTF-16BE", "", "US-ASCII", "\x01\x01", "US-ASCII"],
+ ["UTF-16BE", "", "US-ASCII", "\x01\x81", "US-ASCII"],
+ ["UTF-16BE", "", "UTF-8", "", "UTF-16BE"],
+ ["UTF-16BE", "", "UTF-8", "\u0001\u0001", "UTF-8"],
+ ["UTF-16BE", "", "UTF-8", "\u0001\x81", "UTF-8"],
+ ["UTF-16BE", "", "ASCII-8BIT", "", "UTF-16BE"],
+ ["UTF-16BE", "", "ASCII-8BIT", "\x01\x01", "ASCII-8BIT"],
+ ["UTF-16BE", "", "ASCII-8BIT", "\x01\x81", "ASCII-8BIT"],
+ ["UTF-16BE", "", "ISO-8859-1", "", "UTF-16BE"],
+ ["UTF-16BE", "", "ISO-8859-1", "\x01\x01", "ISO-8859-1"],
+ ["UTF-16BE", "", "ISO-8859-1", "\x01\x81", "ISO-8859-1"],
+ ["UTF-16BE", "", "UTF-16BE", "", "UTF-16BE"],
+ ["UTF-16BE", "", "UTF-16BE", "\u0101", "UTF-16BE"],
+ ["UTF-16BE", "", "UTF-16BE", "\u0181", "UTF-16BE"],
+ ["UTF-16BE", "", "ISO-2022-JP", "", "UTF-16BE"],
+ ["UTF-16BE", "", "ISO-2022-JP", "\x01\x01", "ISO-2022-JP"],
+ ["UTF-16BE", "", "ISO-2022-JP", "\x01\x81", "ISO-2022-JP"],
+ ["UTF-16BE", "\u0101", "US-ASCII", "", "UTF-16BE"],
+ ["UTF-16BE", "\u0101", "US-ASCII", "\x01\x01", nil],
+ ["UTF-16BE", "\u0101", "US-ASCII", "\x01\x81", nil],
+ ["UTF-16BE", "\u0101", "UTF-8", "", "UTF-16BE"],
+ ["UTF-16BE", "\u0101", "UTF-8", "\u0001\u0001", nil],
+ ["UTF-16BE", "\u0101", "UTF-8", "\u0001\x81", nil],
+ ["UTF-16BE", "\u0101", "ASCII-8BIT", "", "UTF-16BE"],
+ ["UTF-16BE", "\u0101", "ASCII-8BIT", "\x01\x01", nil],
+ ["UTF-16BE", "\u0101", "ASCII-8BIT", "\x01\x81", nil],
+ ["UTF-16BE", "\u0101", "ISO-8859-1", "", "UTF-16BE"],
+ ["UTF-16BE", "\u0101", "ISO-8859-1", "\x01\x01", nil],
+ ["UTF-16BE", "\u0101", "ISO-8859-1", "\x01\x81", nil],
+ ["UTF-16BE", "\u0101", "UTF-16BE", "", "UTF-16BE"],
+ ["UTF-16BE", "\u0101", "UTF-16BE", "\u0101", "UTF-16BE"],
+ ["UTF-16BE", "\u0101", "UTF-16BE", "\u0181", "UTF-16BE"],
+ ["UTF-16BE", "\u0101", "ISO-2022-JP", "", "UTF-16BE"],
+ ["UTF-16BE", "\u0101", "ISO-2022-JP", "\x01\x01", nil],
+ ["UTF-16BE", "\u0101", "ISO-2022-JP", "\x01\x81", nil],
+ ["UTF-16BE", "\u0181", "US-ASCII", "", "UTF-16BE"],
+ ["UTF-16BE", "\u0181", "US-ASCII", "\x01\x01", nil],
+ ["UTF-16BE", "\u0181", "US-ASCII", "\x01\x81", nil],
+ ["UTF-16BE", "\u0181", "UTF-8", "", "UTF-16BE"],
+ ["UTF-16BE", "\u0181", "UTF-8", "\u0001\u0001", nil],
+ ["UTF-16BE", "\u0181", "UTF-8", "\u0001\x81", nil],
+ ["UTF-16BE", "\u0181", "ASCII-8BIT", "", "UTF-16BE"],
+ ["UTF-16BE", "\u0181", "ASCII-8BIT", "\x01\x01", nil],
+ ["UTF-16BE", "\u0181", "ASCII-8BIT", "\x01\x81", nil],
+ ["UTF-16BE", "\u0181", "ISO-8859-1", "", "UTF-16BE"],
+ ["UTF-16BE", "\u0181", "ISO-8859-1", "\x01\x01", nil],
+ ["UTF-16BE", "\u0181", "ISO-8859-1", "\x01\x81", nil],
+ ["UTF-16BE", "\u0181", "UTF-16BE", "", "UTF-16BE"],
+ ["UTF-16BE", "\u0181", "UTF-16BE", "\u0101", "UTF-16BE"],
+ ["UTF-16BE", "\u0181", "UTF-16BE", "\u0181", "UTF-16BE"],
+ ["UTF-16BE", "\u0181", "ISO-2022-JP", "", "UTF-16BE"],
+ ["UTF-16BE", "\u0181", "ISO-2022-JP", "\x01\x01", nil],
+ ["UTF-16BE", "\u0181", "ISO-2022-JP", "\x01\x81", nil],
+ ["ISO-2022-JP", "", "US-ASCII", "", "ISO-2022-JP"],
+ ["ISO-2022-JP", "", "US-ASCII", "\x01\x01", "US-ASCII"],
+ ["ISO-2022-JP", "", "US-ASCII", "\x01\x81", "US-ASCII"],
+ ["ISO-2022-JP", "", "UTF-8", "", "ISO-2022-JP"],
+ ["ISO-2022-JP", "", "UTF-8", "\u0001\u0001", "UTF-8"],
+ ["ISO-2022-JP", "", "UTF-8", "\u0001\x81", "UTF-8"],
+ ["ISO-2022-JP", "", "ASCII-8BIT", "", "ISO-2022-JP"],
+ ["ISO-2022-JP", "", "ASCII-8BIT", "\x01\x01", "ASCII-8BIT"],
+ ["ISO-2022-JP", "", "ASCII-8BIT", "\x01\x81", "ASCII-8BIT"],
+ ["ISO-2022-JP", "", "ISO-8859-1", "", "ISO-2022-JP"],
+ ["ISO-2022-JP", "", "ISO-8859-1", "\x01\x01", "ISO-8859-1"],
+ ["ISO-2022-JP", "", "ISO-8859-1", "\x01\x81", "ISO-8859-1"],
+ ["ISO-2022-JP", "", "UTF-16BE", "", "ISO-2022-JP"],
+ ["ISO-2022-JP", "", "UTF-16BE", "\u0101", "UTF-16BE"],
+ ["ISO-2022-JP", "", "UTF-16BE", "\u0181", "UTF-16BE"],
+ ["ISO-2022-JP", "", "ISO-2022-JP", "", "ISO-2022-JP"],
+ ["ISO-2022-JP", "", "ISO-2022-JP", "\x01\x01", "ISO-2022-JP"],
+ ["ISO-2022-JP", "", "ISO-2022-JP", "\x01\x81", "ISO-2022-JP"],
+ ["ISO-2022-JP", "\x01\x01", "US-ASCII", "", "ISO-2022-JP"],
+ ["ISO-2022-JP", "\x01\x01", "US-ASCII", "\x01\x01", nil],
+ ["ISO-2022-JP", "\x01\x01", "US-ASCII", "\x01\x81", nil],
+ ["ISO-2022-JP", "\x01\x01", "UTF-8", "", "ISO-2022-JP"],
+ ["ISO-2022-JP", "\x01\x01", "UTF-8", "\u0001\u0001", nil],
+ ["ISO-2022-JP", "\x01\x01", "UTF-8", "\u0001\x81", nil],
+ ["ISO-2022-JP", "\x01\x01", "ASCII-8BIT", "", "ISO-2022-JP"],
+ ["ISO-2022-JP", "\x01\x01", "ASCII-8BIT", "\x01\x01", nil],
+ ["ISO-2022-JP", "\x01\x01", "ASCII-8BIT", "\x01\x81", nil],
+ ["ISO-2022-JP", "\x01\x01", "ISO-8859-1", "", "ISO-2022-JP"],
+ ["ISO-2022-JP", "\x01\x01", "ISO-8859-1", "\x01\x01", nil],
+ ["ISO-2022-JP", "\x01\x01", "ISO-8859-1", "\x01\x81", nil],
+ ["ISO-2022-JP", "\x01\x01", "UTF-16BE", "", "ISO-2022-JP"],
+ ["ISO-2022-JP", "\x01\x01", "UTF-16BE", "\u0101", nil],
+ ["ISO-2022-JP", "\x01\x01", "UTF-16BE", "\u0181", nil],
+ ["ISO-2022-JP", "\x01\x01", "ISO-2022-JP", "", "ISO-2022-JP"],
+ ["ISO-2022-JP", "\x01\x01", "ISO-2022-JP", "\x01\x01", "ISO-2022-JP"],
+ ["ISO-2022-JP", "\x01\x01", "ISO-2022-JP", "\x01\x81", "ISO-2022-JP"],
+ ["ISO-2022-JP", "\x01\x81", "US-ASCII", "", "ISO-2022-JP"],
+ ["ISO-2022-JP", "\x01\x81", "US-ASCII", "\x01\x01", nil],
+ ["ISO-2022-JP", "\x01\x81", "US-ASCII", "\x01\x81", nil],
+ ["ISO-2022-JP", "\x01\x81", "UTF-8", "", "ISO-2022-JP"],
+ ["ISO-2022-JP", "\x01\x81", "UTF-8", "\u0001\u0001", nil],
+ ["ISO-2022-JP", "\x01\x81", "UTF-8", "\u0001\x81", nil],
+ ["ISO-2022-JP", "\x01\x81", "ASCII-8BIT", "", "ISO-2022-JP"],
+ ["ISO-2022-JP", "\x01\x81", "ASCII-8BIT", "\x01\x01", nil],
+ ["ISO-2022-JP", "\x01\x81", "ASCII-8BIT", "\x01\x81", nil],
+ ["ISO-2022-JP", "\x01\x81", "ISO-8859-1", "", "ISO-2022-JP"],
+ ["ISO-2022-JP", "\x01\x81", "ISO-8859-1", "\x01\x01", nil],
+ ["ISO-2022-JP", "\x01\x81", "ISO-8859-1", "\x01\x81", nil],
+ ["ISO-2022-JP", "\x01\x81", "UTF-16BE", "", "ISO-2022-JP"],
+ ["ISO-2022-JP", "\x01\x81", "UTF-16BE", "\u0101", nil],
+ ["ISO-2022-JP", "\x01\x81", "UTF-16BE", "\u0181", nil],
+ ["ISO-2022-JP", "\x01\x81", "ISO-2022-JP", "", "ISO-2022-JP"],
+ ["ISO-2022-JP", "\x01\x81", "ISO-2022-JP", "\x01\x01", "ISO-2022-JP"],
+ ["ISO-2022-JP", "\x01\x81", "ISO-2022-JP", "\x01\x81", "ISO-2022-JP"],
+ ]
+
+ matrix.each do |encoding1, value1, encoding2, value2, compatible_encoding|
+ it "returns #{compatible_encoding} for #{value1.inspect} in #{encoding1} and #{value2.inspect} in #{encoding2}" do
+ actual_encoding = Encoding.compatible?(value1.dup.force_encoding(encoding1), value2.dup.force_encoding(encoding2))
+ actual_encoding&.name.should == compatible_encoding
+ end
end
end
+end
- describe "Encoding.compatible? String, Symbol" do
- it "returns US-ASCII if both are ASCII only" do
- str = "abc".force_encoding("us-ascii")
- Encoding.compatible?(str, :abc).should == Encoding::US_ASCII
- end
+describe "Encoding.compatible? String, Regexp" do
+ it "returns US-ASCII if both are US-ASCII" do
+ str = "abc".dup.force_encoding("us-ascii")
+ Encoding.compatible?(str, /abc/).should == Encoding::US_ASCII
+ end
- it "returns the String's Encoding if it is not US-ASCII but both are ASCII only" do
- [ [Encoding, "abc", Encoding::ASCII_8BIT],
- [Encoding, "abc".encode("utf-8"), Encoding::UTF_8],
- [Encoding, "abc".encode("euc-jp"), Encoding::EUC_JP],
- [Encoding, "abc".encode("shift_jis"), Encoding::Shift_JIS],
- ].should be_computed_by(:compatible?, :abc)
- end
+ it "returns the String's Encoding if it is not US-ASCII but both are ASCII only" do
+ [ [Encoding, "abc", Encoding::BINARY],
+ [Encoding, "abc".encode("utf-8"), Encoding::UTF_8],
+ [Encoding, "abc".encode("euc-jp"), Encoding::EUC_JP],
+ [Encoding, "abc".encode("shift_jis"), Encoding::Shift_JIS],
+ ].should be_computed_by(:compatible?, /abc/)
+ end
- it "returns the String's Encoding if the String is not ASCII only" do
- [ [Encoding, "\xff", Encoding::ASCII_8BIT],
- [Encoding, "\u3042".encode("utf-8"), Encoding::UTF_8],
- [Encoding, "\xa4\xa2".force_encoding("euc-jp"), Encoding::EUC_JP],
- [Encoding, "\x82\xa0".force_encoding("shift_jis"), Encoding::Shift_JIS],
- ].should be_computed_by(:compatible?, :abc)
- end
+ it "returns the String's Encoding if the String is not ASCII only" do
+ [ [Encoding, "\xff", Encoding::BINARY],
+ [Encoding, "\u3042".encode("utf-8"), Encoding::UTF_8],
+ [Encoding, "\xa4\xa2".dup.force_encoding("euc-jp"), Encoding::EUC_JP],
+ [Encoding, "\x82\xa0".dup.force_encoding("shift_jis"), Encoding::Shift_JIS],
+ ].should be_computed_by(:compatible?, /abc/)
end
- describe "Encoding.compatible? String, Encoding" do
- it "returns nil if the String's encoding is not ASCII compatible" do
- Encoding.compatible?("abc".encode("utf-32le"), Encoding::US_ASCII).should be_nil
- end
+ it "returns the Regexp's Encoding if the String is ASCII only and the Regexp is not" do
+ r = Regexp.new("\xa4\xa2".dup.force_encoding("euc-jp"))
+ Encoding.compatible?("hello".dup.force_encoding("utf-8"), r).should == Encoding::EUC_JP
+ end
+end
- it "returns nil if the Encoding is not ASCII compatible" do
- Encoding.compatible?("abc".encode("us-ascii"), Encoding::UTF_32LE).should be_nil
- end
+describe "Encoding.compatible? String, Symbol" do
+ it "returns US-ASCII if both are ASCII only" do
+ str = "abc".dup.force_encoding("us-ascii")
+ Encoding.compatible?(str, :abc).should == Encoding::US_ASCII
+ end
- it "returns the String's encoding if the Encoding is US-ASCII" do
- [ [Encoding, "\xff", Encoding::ASCII_8BIT],
- [Encoding, "\u3042".encode("utf-8"), Encoding::UTF_8],
- [Encoding, "\xa4\xa2".force_encoding("euc-jp"), Encoding::EUC_JP],
- [Encoding, "\x82\xa0".force_encoding("shift_jis"), Encoding::Shift_JIS],
- ].should be_computed_by(:compatible?, Encoding::US_ASCII)
- end
+ it "returns the String's Encoding if it is not US-ASCII but both are ASCII only" do
+ [ [Encoding, "abc", Encoding::BINARY],
+ [Encoding, "abc".encode("utf-8"), Encoding::UTF_8],
+ [Encoding, "abc".encode("euc-jp"), Encoding::EUC_JP],
+ [Encoding, "abc".encode("shift_jis"), Encoding::Shift_JIS],
+ ].should be_computed_by(:compatible?, :abc)
+ end
- it "returns the Encoding if the String's encoding is ASCII compatible and the String is ASCII only" do
- str = "abc".encode("utf-8")
+ it "returns the String's Encoding if the String is not ASCII only" do
+ [ [Encoding, "\xff", Encoding::BINARY],
+ [Encoding, "\u3042".encode("utf-8"), Encoding::UTF_8],
+ [Encoding, "\xa4\xa2".dup.force_encoding("euc-jp"), Encoding::EUC_JP],
+ [Encoding, "\x82\xa0".dup.force_encoding("shift_jis"), Encoding::Shift_JIS],
+ ].should be_computed_by(:compatible?, :abc)
+ end
+end
- Encoding.compatible?(str, Encoding::ASCII_8BIT).should == Encoding::ASCII_8BIT
- Encoding.compatible?(str, Encoding::UTF_8).should == Encoding::UTF_8
- Encoding.compatible?(str, Encoding::EUC_JP).should == Encoding::EUC_JP
- Encoding.compatible?(str, Encoding::Shift_JIS).should == Encoding::Shift_JIS
- end
+describe "Encoding.compatible? String, Encoding" do
+ it "returns nil if the String's encoding is not ASCII compatible" do
+ Encoding.compatible?("abc".encode("utf-32le"), Encoding::US_ASCII).should == nil
+ end
- it "returns nil if the String's encoding is ASCII compatible but the string is not ASCII only" do
- Encoding.compatible?("\u3042".encode("utf-8"), Encoding::ASCII_8BIT).should be_nil
- end
+ it "returns nil if the Encoding is not ASCII compatible" do
+ Encoding.compatible?("abc".encode("us-ascii"), Encoding::UTF_32LE).should == nil
end
- describe "Encoding.compatible? Regexp, String" do
- it "returns US-ASCII if both are US-ASCII" do
- str = "abc".force_encoding("us-ascii")
- Encoding.compatible?(/abc/, str).should == Encoding::US_ASCII
- end
+ it "returns the String's encoding if the Encoding is US-ASCII" do
+ [ [Encoding, "\xff", Encoding::BINARY],
+ [Encoding, "\u3042".encode("utf-8"), Encoding::UTF_8],
+ [Encoding, "\xa4\xa2".dup.force_encoding("euc-jp"), Encoding::EUC_JP],
+ [Encoding, "\x82\xa0".dup.force_encoding("shift_jis"), Encoding::Shift_JIS],
+ ].should be_computed_by(:compatible?, Encoding::US_ASCII)
+ end
+ it "returns the Encoding if the String's encoding is ASCII compatible and the String is ASCII only" do
+ str = "abc".encode("utf-8")
+
+ Encoding.compatible?(str, Encoding::BINARY).should == Encoding::BINARY
+ Encoding.compatible?(str, Encoding::UTF_8).should == Encoding::UTF_8
+ Encoding.compatible?(str, Encoding::EUC_JP).should == Encoding::EUC_JP
+ Encoding.compatible?(str, Encoding::Shift_JIS).should == Encoding::Shift_JIS
end
- describe "Encoding.compatible? Regexp, Regexp" do
- it "returns US-ASCII if both are US-ASCII" do
- Encoding.compatible?(/abc/, /def/).should == Encoding::US_ASCII
- end
+ it "returns nil if the String's encoding is ASCII compatible but the string is not ASCII only" do
+ Encoding.compatible?("\u3042".encode("utf-8"), Encoding::BINARY).should == nil
+ end
+end
- it "returns the first's Encoding if it is not US-ASCII and not ASCII only" do
- [ [Encoding, Regexp.new("\xff"), Encoding::ASCII_8BIT],
- [Encoding, Regexp.new("\u3042".encode("utf-8")), Encoding::UTF_8],
- [Encoding, Regexp.new("\xa4\xa2".force_encoding("euc-jp")), Encoding::EUC_JP],
- [Encoding, Regexp.new("\x82\xa0".force_encoding("shift_jis")), Encoding::Shift_JIS],
- ].should be_computed_by(:compatible?, /abc/)
- end
+describe "Encoding.compatible? Regexp, String" do
+ it "returns US-ASCII if both are US-ASCII" do
+ str = "abc".dup.force_encoding("us-ascii")
+ Encoding.compatible?(/abc/, str).should == Encoding::US_ASCII
end
- describe "Encoding.compatible? Regexp, Symbol" do
- it "returns US-ASCII if both are US-ASCII" do
- Encoding.compatible?(/abc/, :def).should == Encoding::US_ASCII
- end
+ it "returns the String's Encoding when the String is ASCII only with a different encoding" do
+ r = Regexp.new("\xa4\xa2".dup.force_encoding("euc-jp"))
+ Encoding.compatible?(r, "hello".dup.force_encoding("utf-8")).should == Encoding::UTF_8
+ end
- it "returns the first's Encoding if it is not US-ASCII and not ASCII only" do
- [ [Encoding, Regexp.new("\xff"), Encoding::ASCII_8BIT],
- [Encoding, Regexp.new("\u3042".encode("utf-8")), Encoding::UTF_8],
- [Encoding, Regexp.new("\xa4\xa2".force_encoding("euc-jp")), Encoding::EUC_JP],
- [Encoding, Regexp.new("\x82\xa0".force_encoding("shift_jis")), Encoding::Shift_JIS],
- ].should be_computed_by(:compatible?, /abc/)
- end
+ it "returns the Regexp's Encoding if the String has the same non-ASCII encoding" do
+ r = Regexp.new("\xa4\xa2".dup.force_encoding("euc-jp"))
+ Encoding.compatible?(r, "hello".dup.force_encoding("euc-jp")).should == Encoding::EUC_JP
end
+end
- describe "Encoding.compatible? Symbol, String" do
- it "returns US-ASCII if both are ASCII only" do
- str = "abc".force_encoding("us-ascii")
- Encoding.compatible?(str, :abc).should == Encoding::US_ASCII
- end
+describe "Encoding.compatible? Regexp, Regexp" do
+ it "returns US-ASCII if both are US-ASCII" do
+ Encoding.compatible?(/abc/, /def/).should == Encoding::US_ASCII
end
- describe "Encoding.compatible? Symbol, Regexp" do
- it "returns US-ASCII if both are US-ASCII" do
- Encoding.compatible?(:abc, /def/).should == Encoding::US_ASCII
- end
+ it "returns the first's Encoding if it is not US-ASCII and not ASCII only" do
+ [ [Encoding, Regexp.new("\xff"), Encoding::BINARY],
+ [Encoding, Regexp.new("\u3042".encode("utf-8")), Encoding::UTF_8],
+ [Encoding, Regexp.new("\xa4\xa2".dup.force_encoding("euc-jp")), Encoding::EUC_JP],
+ [Encoding, Regexp.new("\x82\xa0".dup.force_encoding("shift_jis")), Encoding::Shift_JIS],
+ ].should be_computed_by(:compatible?, /abc/)
+ end
+end
- it "returns the Regexp's Encoding if it is not US-ASCII and not ASCII only" do
- a = Regexp.new("\xff")
- b = Regexp.new("\u3042".encode("utf-8"))
- c = Regexp.new("\xa4\xa2".force_encoding("euc-jp"))
- d = Regexp.new("\x82\xa0".force_encoding("shift_jis"))
+describe "Encoding.compatible? Regexp, Symbol" do
+ it "returns US-ASCII if both are US-ASCII" do
+ Encoding.compatible?(/abc/, :def).should == Encoding::US_ASCII
+ end
- [ [Encoding, :abc, a, Encoding::ASCII_8BIT],
- [Encoding, :abc, b, Encoding::UTF_8],
- [Encoding, :abc, c, Encoding::EUC_JP],
- [Encoding, :abc, d, Encoding::Shift_JIS],
- ].should be_computed_by(:compatible?)
- end
+ it "returns the first's Encoding if it is not US-ASCII and not ASCII only" do
+ [ [Encoding, Regexp.new("\xff"), Encoding::BINARY],
+ [Encoding, Regexp.new("\u3042".encode("utf-8")), Encoding::UTF_8],
+ [Encoding, Regexp.new("\xa4\xa2".dup.force_encoding("euc-jp")), Encoding::EUC_JP],
+ [Encoding, Regexp.new("\x82\xa0".dup.force_encoding("shift_jis")), Encoding::Shift_JIS],
+ ].should be_computed_by(:compatible?, /abc/)
end
+end
- describe "Encoding.compatible? Symbol, Symbol" do
- it "returns US-ASCII if both are US-ASCII" do
- Encoding.compatible?(:abc, :def).should == Encoding::US_ASCII
- end
+describe "Encoding.compatible? Symbol, String" do
+ it "returns US-ASCII if both are ASCII only" do
+ str = "abc".dup.force_encoding("us-ascii")
+ Encoding.compatible?(str, :abc).should == Encoding::US_ASCII
+ end
+end
- it "returns the first's Encoding if it is not ASCII only" do
- [ [Encoding, "\xff".to_sym, Encoding::ASCII_8BIT],
- [Encoding, "\u3042".encode("utf-8").to_sym, Encoding::UTF_8],
- [Encoding, "\xa4\xa2".force_encoding("euc-jp").to_sym, Encoding::EUC_JP],
- [Encoding, "\x82\xa0".force_encoding("shift_jis").to_sym, Encoding::Shift_JIS],
- ].should be_computed_by(:compatible?, :abc)
- end
+describe "Encoding.compatible? Symbol, Regexp" do
+ it "returns US-ASCII if both are US-ASCII" do
+ Encoding.compatible?(:abc, /def/).should == Encoding::US_ASCII
end
- describe "Encoding.compatible? Encoding, Encoding" do
- it "returns nil if one of the encodings is a dummy encoding" do
- [ [Encoding, Encoding::UTF_7, Encoding::US_ASCII, nil],
- [Encoding, Encoding::US_ASCII, Encoding::UTF_7, nil],
- [Encoding, Encoding::EUC_JP, Encoding::UTF_7, nil],
- [Encoding, Encoding::UTF_7, Encoding::EUC_JP, nil],
- [Encoding, Encoding::UTF_7, Encoding::ASCII_8BIT, nil],
- [Encoding, Encoding::ASCII_8BIT, Encoding::UTF_7, nil],
- ].should be_computed_by(:compatible?)
- end
+ it "returns the Regexp's Encoding if it is not US-ASCII and not ASCII only" do
+ a = Regexp.new("\xff")
+ b = Regexp.new("\u3042".encode("utf-8"))
+ c = Regexp.new("\xa4\xa2".dup.force_encoding("euc-jp"))
+ d = Regexp.new("\x82\xa0".dup.force_encoding("shift_jis"))
+
+ [ [Encoding, :abc, a, Encoding::BINARY],
+ [Encoding, :abc, b, Encoding::UTF_8],
+ [Encoding, :abc, c, Encoding::EUC_JP],
+ [Encoding, :abc, d, Encoding::Shift_JIS],
+ ].should be_computed_by(:compatible?)
+ end
+end
- it "returns nil if one of the encodings is not US-ASCII" do
- [ [Encoding, Encoding::UTF_8, Encoding::ASCII_8BIT, nil],
- [Encoding, Encoding::ASCII_8BIT, Encoding::UTF_8, nil],
- [Encoding, Encoding::ASCII_8BIT, Encoding::EUC_JP, nil],
- [Encoding, Encoding::Shift_JIS, Encoding::EUC_JP, nil],
- ].should be_computed_by(:compatible?)
- end
+describe "Encoding.compatible? Symbol, Symbol" do
+ it "returns US-ASCII if both are US-ASCII" do
+ Encoding.compatible?(:abc, :def).should == Encoding::US_ASCII
+ end
- it "returns the first if the second is US-ASCII" do
- [ [Encoding, Encoding::UTF_8, Encoding::US_ASCII, Encoding::UTF_8],
- [Encoding, Encoding::EUC_JP, Encoding::US_ASCII, Encoding::EUC_JP],
- [Encoding, Encoding::Shift_JIS, Encoding::US_ASCII, Encoding::Shift_JIS],
- [Encoding, Encoding::ASCII_8BIT, Encoding::US_ASCII, Encoding::ASCII_8BIT],
- ].should be_computed_by(:compatible?)
- end
+ it "returns the first's Encoding if it is not ASCII only" do
+ [ [Encoding, "\xff".to_sym, Encoding::BINARY],
+ [Encoding, "\u3042".encode("utf-8").to_sym, Encoding::UTF_8],
+ [Encoding, "\xa4\xa2".dup.force_encoding("euc-jp").to_sym, Encoding::EUC_JP],
+ [Encoding, "\x82\xa0".dup.force_encoding("shift_jis").to_sym, Encoding::Shift_JIS],
+ ].should be_computed_by(:compatible?, :abc)
+ end
+end
- it "returns the Encoding if both are the same" do
- [ [Encoding, Encoding::UTF_8, Encoding::UTF_8, Encoding::UTF_8],
- [Encoding, Encoding::US_ASCII, Encoding::US_ASCII, Encoding::US_ASCII],
- [Encoding, Encoding::ASCII_8BIT, Encoding::ASCII_8BIT, Encoding::ASCII_8BIT],
- [Encoding, Encoding::UTF_7, Encoding::UTF_7, Encoding::UTF_7],
- ].should be_computed_by(:compatible?)
- end
+describe "Encoding.compatible? Encoding, Encoding" do
+ it "returns nil if one of the encodings is a dummy encoding" do
+ [ [Encoding, Encoding::UTF_7, Encoding::US_ASCII, nil],
+ [Encoding, Encoding::US_ASCII, Encoding::UTF_7, nil],
+ [Encoding, Encoding::EUC_JP, Encoding::UTF_7, nil],
+ [Encoding, Encoding::UTF_7, Encoding::EUC_JP, nil],
+ [Encoding, Encoding::UTF_7, Encoding::BINARY, nil],
+ [Encoding, Encoding::BINARY, Encoding::UTF_7, nil],
+ ].should be_computed_by(:compatible?)
end
- describe "Encoding.compatible? Object, Object" do
- it "returns nil for Object, String" do
- Encoding.compatible?(Object.new, "abc").should be_nil
- end
+ it "returns nil if one of the encodings is not US-ASCII" do
+ [ [Encoding, Encoding::UTF_8, Encoding::BINARY, nil],
+ [Encoding, Encoding::BINARY, Encoding::UTF_8, nil],
+ [Encoding, Encoding::BINARY, Encoding::EUC_JP, nil],
+ [Encoding, Encoding::Shift_JIS, Encoding::EUC_JP, nil],
+ ].should be_computed_by(:compatible?)
+ end
- it "returns nil for Object, Regexp" do
- Encoding.compatible?(Object.new, /./).should be_nil
- end
+ it "returns the first if the second is US-ASCII" do
+ [ [Encoding, Encoding::UTF_8, Encoding::US_ASCII, Encoding::UTF_8],
+ [Encoding, Encoding::EUC_JP, Encoding::US_ASCII, Encoding::EUC_JP],
+ [Encoding, Encoding::Shift_JIS, Encoding::US_ASCII, Encoding::Shift_JIS],
+ [Encoding, Encoding::BINARY, Encoding::US_ASCII, Encoding::BINARY],
+ ].should be_computed_by(:compatible?)
+ end
- it "returns nil for Object, Symbol" do
- Encoding.compatible?(Object.new, :sym).should be_nil
- end
+ it "returns the Encoding if both are the same" do
+ [ [Encoding, Encoding::UTF_8, Encoding::UTF_8, Encoding::UTF_8],
+ [Encoding, Encoding::US_ASCII, Encoding::US_ASCII, Encoding::US_ASCII],
+ [Encoding, Encoding::BINARY, Encoding::BINARY, Encoding::BINARY],
+ [Encoding, Encoding::UTF_7, Encoding::UTF_7, Encoding::UTF_7],
+ ].should be_computed_by(:compatible?)
+ end
+end
- it "returns nil for String, Object" do
- Encoding.compatible?("abc", Object.new).should be_nil
- end
+describe "Encoding.compatible? Object, Object" do
+ it "returns nil for Object, String" do
+ Encoding.compatible?(Object.new, "abc").should == nil
+ end
- it "returns nil for Regexp, Object" do
- Encoding.compatible?(/./, Object.new).should be_nil
- end
+ it "returns nil for Object, Regexp" do
+ Encoding.compatible?(Object.new, /./).should == nil
+ end
- it "returns nil for Symbol, Object" do
- Encoding.compatible?(:sym, Object.new).should be_nil
- end
+ it "returns nil for Object, Symbol" do
+ Encoding.compatible?(Object.new, :sym).should == nil
+ end
+
+ it "returns nil for String, Object" do
+ Encoding.compatible?("abc", Object.new).should == nil
+ end
+
+ it "returns nil for Regexp, Object" do
+ Encoding.compatible?(/./, Object.new).should == nil
+ end
+
+ it "returns nil for Symbol, Object" do
+ Encoding.compatible?(:sym, Object.new).should == nil
+ end
+end
+
+describe "Encoding.compatible? nil, nil" do
+ it "returns nil" do
+ Encoding.compatible?(nil, nil).should == nil
end
end
diff --git a/spec/ruby/core/encoding/converter/asciicompat_encoding_spec.rb b/spec/ruby/core/encoding/converter/asciicompat_encoding_spec.rb
index 329e09cade..7fa867a57e 100644
--- a/spec/ruby/core/encoding/converter/asciicompat_encoding_spec.rb
+++ b/spec/ruby/core/encoding/converter/asciicompat_encoding_spec.rb
@@ -1,39 +1,31 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
-with_feature :encoding do
- describe "Encoding::Converter.asciicompat_encoding" do
- it "accepts an encoding name as a String argument" do
- lambda { Encoding::Converter.asciicompat_encoding('UTF-8') }.
- should_not raise_error
- end
-
- it "coerces non-String/Encoding objects with #to_str" do
- str = mock('string')
- str.should_receive(:to_str).at_least(1).times.and_return('string')
- Encoding::Converter.asciicompat_encoding(str)
- end
+describe "Encoding::Converter.asciicompat_encoding" do
+ it "coerces non-String/Encoding objects with #to_str" do
+ str = mock('string')
+ str.should_receive(:to_str).at_least(1).times.and_return('string')
+ Encoding::Converter.asciicompat_encoding(str)
+ end
- it "accepts an Encoding object as an argument" do
- Encoding::Converter.
- asciicompat_encoding(Encoding.find("ISO-2022-JP")).
- should == Encoding::Converter.asciicompat_encoding("ISO-2022-JP")
- end
+ it "accepts an Encoding object as an argument" do
+ Encoding::Converter.asciicompat_encoding(Encoding.find("ISO-2022-JP")).should ==
+ Encoding::Converter.asciicompat_encoding("ISO-2022-JP")
+ end
- it "returns a corresponding ASCII compatible encoding for ASCII-incompatible encodings" do
- Encoding::Converter.asciicompat_encoding('UTF-16BE').should == Encoding::UTF_8
- Encoding::Converter.asciicompat_encoding("ISO-2022-JP").should == Encoding.find("stateless-ISO-2022-JP")
- end
+ it "returns a corresponding ASCII compatible encoding for ASCII-incompatible encodings" do
+ Encoding::Converter.asciicompat_encoding('UTF-16BE').should == Encoding::UTF_8
+ Encoding::Converter.asciicompat_encoding("ISO-2022-JP").should == Encoding.find("stateless-ISO-2022-JP")
+ end
- it "returns nil when the given encoding is ASCII compatible" do
- Encoding::Converter.asciicompat_encoding('ASCII').should be_nil
- Encoding::Converter.asciicompat_encoding('UTF-8').should be_nil
- end
+ it "returns nil when the given encoding is ASCII compatible" do
+ Encoding::Converter.asciicompat_encoding('ASCII').should == nil
+ Encoding::Converter.asciicompat_encoding('UTF-8').should == nil
+ end
- it "handles encoding names who resolve to nil encodings" do
- internal = Encoding.default_internal
- Encoding.default_internal = nil
- Encoding::Converter.asciicompat_encoding('internal').should be_nil
- Encoding.default_internal = internal
- end
+ it "handles encoding names who resolve to nil encodings" do
+ internal = Encoding.default_internal
+ Encoding.default_internal = nil
+ Encoding::Converter.asciicompat_encoding('internal').should == nil
+ Encoding.default_internal = internal
end
end
diff --git a/spec/ruby/core/encoding/converter/constants_spec.rb b/spec/ruby/core/encoding/converter/constants_spec.rb
index 16eb60b4ab..e2d21b5429 100644
--- a/spec/ruby/core/encoding/converter/constants_spec.rb
+++ b/spec/ruby/core/encoding/converter/constants_spec.rb
@@ -1,133 +1,131 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
-with_feature :encoding do
- describe "Encoding::Converter::INVALID_MASK" do
- it "exists" do
- Encoding::Converter.should have_constant(:INVALID_MASK)
- end
+describe "Encoding::Converter::INVALID_MASK" do
+ it "exists" do
+ Encoding::Converter.should.const_defined?(:INVALID_MASK, false)
+ end
- it "has a Fixnum value" do
- Encoding::Converter::INVALID_MASK.should be_an_instance_of(Fixnum)
- end
+ it "has an Integer value" do
+ Encoding::Converter::INVALID_MASK.should.instance_of?(Integer)
end
+end
- describe "Encoding::Converter::INVALID_REPLACE" do
- it "exists" do
- Encoding::Converter.should have_constant(:INVALID_REPLACE)
- end
+describe "Encoding::Converter::INVALID_REPLACE" do
+ it "exists" do
+ Encoding::Converter.should.const_defined?(:INVALID_REPLACE, false)
+ end
- it "has a Fixnum value" do
- Encoding::Converter::INVALID_REPLACE.should be_an_instance_of(Fixnum)
- end
+ it "has an Integer value" do
+ Encoding::Converter::INVALID_REPLACE.should.instance_of?(Integer)
end
+end
- describe "Encoding::Converter::UNDEF_MASK" do
- it "exists" do
- Encoding::Converter.should have_constant(:UNDEF_MASK)
- end
+describe "Encoding::Converter::UNDEF_MASK" do
+ it "exists" do
+ Encoding::Converter.should.const_defined?(:UNDEF_MASK, false)
+ end
- it "has a Fixnum value" do
- Encoding::Converter::UNDEF_MASK.should be_an_instance_of(Fixnum)
- end
+ it "has an Integer value" do
+ Encoding::Converter::UNDEF_MASK.should.instance_of?(Integer)
end
+end
- describe "Encoding::Converter::UNDEF_REPLACE" do
- it "exists" do
- Encoding::Converter.should have_constant(:UNDEF_REPLACE)
- end
+describe "Encoding::Converter::UNDEF_REPLACE" do
+ it "exists" do
+ Encoding::Converter.should.const_defined?(:UNDEF_REPLACE, false)
+ end
- it "has a Fixnum value" do
- Encoding::Converter::UNDEF_REPLACE.should be_an_instance_of(Fixnum)
- end
+ it "has an Integer value" do
+ Encoding::Converter::UNDEF_REPLACE.should.instance_of?(Integer)
end
+end
- describe "Encoding::Converter::UNDEF_HEX_CHARREF" do
- it "exists" do
- Encoding::Converter.should have_constant(:UNDEF_HEX_CHARREF)
- end
+describe "Encoding::Converter::UNDEF_HEX_CHARREF" do
+ it "exists" do
+ Encoding::Converter.should.const_defined?(:UNDEF_HEX_CHARREF, false)
+ end
- it "has a Fixnum value" do
- Encoding::Converter::UNDEF_HEX_CHARREF.should be_an_instance_of(Fixnum)
- end
+ it "has an Integer value" do
+ Encoding::Converter::UNDEF_HEX_CHARREF.should.instance_of?(Integer)
end
+end
- describe "Encoding::Converter::PARTIAL_INPUT" do
- it "exists" do
- Encoding::Converter.should have_constant(:PARTIAL_INPUT)
- end
+describe "Encoding::Converter::PARTIAL_INPUT" do
+ it "exists" do
+ Encoding::Converter.should.const_defined?(:PARTIAL_INPUT, false)
+ end
- it "has a Fixnum value" do
- Encoding::Converter::PARTIAL_INPUT.should be_an_instance_of(Fixnum)
- end
+ it "has an Integer value" do
+ Encoding::Converter::PARTIAL_INPUT.should.instance_of?(Integer)
end
+end
- describe "Encoding::Converter::AFTER_OUTPUT" do
- it "exists" do
- Encoding::Converter.should have_constant(:AFTER_OUTPUT)
- end
+describe "Encoding::Converter::AFTER_OUTPUT" do
+ it "exists" do
+ Encoding::Converter.should.const_defined?(:AFTER_OUTPUT, false)
+ end
- it "has a Fixnum value" do
- Encoding::Converter::AFTER_OUTPUT.should be_an_instance_of(Fixnum)
- end
+ it "has an Integer value" do
+ Encoding::Converter::AFTER_OUTPUT.should.instance_of?(Integer)
end
+end
- describe "Encoding::Converter::UNIVERSAL_NEWLINE_DECORATOR" do
- it "exists" do
- Encoding::Converter.should have_constant(:UNIVERSAL_NEWLINE_DECORATOR)
- end
+describe "Encoding::Converter::UNIVERSAL_NEWLINE_DECORATOR" do
+ it "exists" do
+ Encoding::Converter.should.const_defined?(:UNIVERSAL_NEWLINE_DECORATOR, false)
+ end
- it "has a Fixnum value" do
- Encoding::Converter::UNIVERSAL_NEWLINE_DECORATOR.should be_an_instance_of(Fixnum)
- end
+ it "has an Integer value" do
+ Encoding::Converter::UNIVERSAL_NEWLINE_DECORATOR.should.instance_of?(Integer)
end
+end
- describe "Encoding::Converter::CRLF_NEWLINE_DECORATOR" do
- it "exists" do
- Encoding::Converter.should have_constant(:CRLF_NEWLINE_DECORATOR)
- end
+describe "Encoding::Converter::CRLF_NEWLINE_DECORATOR" do
+ it "exists" do
+ Encoding::Converter.should.const_defined?(:CRLF_NEWLINE_DECORATOR, false)
+ end
- it "has a Fixnum value" do
- Encoding::Converter::CRLF_NEWLINE_DECORATOR.should be_an_instance_of(Fixnum)
- end
+ it "has an Integer value" do
+ Encoding::Converter::CRLF_NEWLINE_DECORATOR.should.instance_of?(Integer)
end
+end
- describe "Encoding::Converter::CR_NEWLINE_DECORATOR" do
- it "exists" do
- Encoding::Converter.should have_constant(:CR_NEWLINE_DECORATOR)
- end
+describe "Encoding::Converter::CR_NEWLINE_DECORATOR" do
+ it "exists" do
+ Encoding::Converter.should.const_defined?(:CR_NEWLINE_DECORATOR, false)
+ end
- it "has a Fixnum value" do
- Encoding::Converter::CR_NEWLINE_DECORATOR.should be_an_instance_of(Fixnum)
- end
+ it "has an Integer value" do
+ Encoding::Converter::CR_NEWLINE_DECORATOR.should.instance_of?(Integer)
end
+end
- describe "Encoding::Converter::XML_TEXT_DECORATOR" do
- it "exists" do
- Encoding::Converter.should have_constant(:XML_TEXT_DECORATOR)
- end
+describe "Encoding::Converter::XML_TEXT_DECORATOR" do
+ it "exists" do
+ Encoding::Converter.should.const_defined?(:XML_TEXT_DECORATOR, false)
+ end
- it "has a Fixnum value" do
- Encoding::Converter::XML_TEXT_DECORATOR.should be_an_instance_of(Fixnum)
- end
+ it "has an Integer value" do
+ Encoding::Converter::XML_TEXT_DECORATOR.should.instance_of?(Integer)
end
+end
- describe "Encoding::Converter::XML_ATTR_CONTENT_DECORATOR" do
- it "exists" do
- Encoding::Converter.should have_constant(:XML_ATTR_CONTENT_DECORATOR)
- end
+describe "Encoding::Converter::XML_ATTR_CONTENT_DECORATOR" do
+ it "exists" do
+ Encoding::Converter.should.const_defined?(:XML_ATTR_CONTENT_DECORATOR, false)
+ end
- it "has a Fixnum value" do
- Encoding::Converter::XML_ATTR_CONTENT_DECORATOR.should be_an_instance_of(Fixnum)
- end
+ it "has an Integer value" do
+ Encoding::Converter::XML_ATTR_CONTENT_DECORATOR.should.instance_of?(Integer)
end
+end
- describe "Encoding::Converter::XML_ATTR_QUOTE_DECORATOR" do
- it "exists" do
- Encoding::Converter.should have_constant(:XML_ATTR_QUOTE_DECORATOR)
- end
+describe "Encoding::Converter::XML_ATTR_QUOTE_DECORATOR" do
+ it "exists" do
+ Encoding::Converter.should.const_defined?(:XML_ATTR_QUOTE_DECORATOR, false)
+ end
- it "has a Fixnum value" do
- Encoding::Converter::XML_ATTR_QUOTE_DECORATOR.should be_an_instance_of(Fixnum)
- end
+ it "has an Integer value" do
+ Encoding::Converter::XML_ATTR_QUOTE_DECORATOR.should.instance_of?(Integer)
end
end
diff --git a/spec/ruby/core/encoding/converter/convert_spec.rb b/spec/ruby/core/encoding/converter/convert_spec.rb
index 588d659ceb..c95e88a491 100644
--- a/spec/ruby/core/encoding/converter/convert_spec.rb
+++ b/spec/ruby/core/encoding/converter/convert_spec.rb
@@ -1,47 +1,45 @@
-# -*- encoding: binary -*-
-require File.expand_path('../../../../spec_helper', __FILE__)
+# encoding: binary
+# frozen_string_literal: true
+require_relative '../../../spec_helper'
-with_feature :encoding do
- describe "Encoding::Converter#convert" do
- it "returns a String" do
- ec = Encoding::Converter.new('ascii', 'utf-8')
- ec.convert('glark').should be_an_instance_of(String)
- end
+describe "Encoding::Converter#convert" do
+ it "returns a String" do
+ ec = Encoding::Converter.new('ascii', 'utf-8')
+ ec.convert('glark').should.instance_of?(String)
+ end
- it "sets the encoding of the result to the target encoding" do
- ec = Encoding::Converter.new('ascii', 'utf-8')
- str = 'glark'.force_encoding('ascii')
- ec.convert(str).encoding.should == Encoding::UTF_8
- end
+ it "sets the encoding of the result to the target encoding" do
+ ec = Encoding::Converter.new('ascii', 'utf-8')
+ str = 'glark'.dup.force_encoding('ascii')
+ ec.convert(str).encoding.should == Encoding::UTF_8
+ end
- it "transcodes the given String to the target encoding" do
- ec = Encoding::Converter.new("utf-8", "euc-jp")
- ec.convert("\u3042".force_encoding('UTF-8')).should == \
- "\xA4\xA2".force_encoding('EUC-JP')
- end
+ it "transcodes the given String to the target encoding" do
+ ec = Encoding::Converter.new("utf-8", "euc-jp")
+ ec.convert("\u3042".dup.force_encoding('UTF-8')).should == \
+ "\xA4\xA2".dup.force_encoding('EUC-JP')
+ end
- it "allows Strings of different encodings to the source encoding" do
- ec = Encoding::Converter.new('ascii', 'utf-8')
- str = 'glark'.force_encoding('SJIS')
- ec.convert(str).encoding.should == Encoding::UTF_8
- end
+ it "allows Strings of different encodings to the source encoding" do
+ ec = Encoding::Converter.new('ascii', 'utf-8')
+ str = 'glark'.dup.force_encoding('SJIS')
+ ec.convert(str).encoding.should == Encoding::UTF_8
+ end
- it "reuses the given encoding pair if called multiple times" do
- ec = Encoding::Converter.new('ascii', 'SJIS')
- ec.convert('a'.force_encoding('ASCII')).should == 'a'.force_encoding('SJIS')
- ec.convert('b'.force_encoding('ASCII')).should == 'b'.force_encoding('SJIS')
- end
+ it "reuses the given encoding pair if called multiple times" do
+ ec = Encoding::Converter.new('ascii', 'SJIS')
+ ec.convert('a'.dup.force_encoding('ASCII')).should == 'a'.dup.force_encoding('SJIS')
+ ec.convert('b'.dup.force_encoding('ASCII')).should == 'b'.dup.force_encoding('SJIS')
+ end
- it "raises UndefinedConversionError if the String contains characters invalid for the target encoding" do
- ec = Encoding::Converter.new('UTF-8', Encoding.find('macCyrillic'))
- lambda { ec.convert("\u{6543}".force_encoding('UTF-8')) }.should \
- raise_error(Encoding::UndefinedConversionError)
- end
+ it "raises UndefinedConversionError if the String contains characters invalid for the target encoding" do
+ ec = Encoding::Converter.new('UTF-8', Encoding.find('macCyrillic'))
+ -> { ec.convert("\u{6543}".dup.force_encoding('UTF-8')) }.should.raise(Encoding::UndefinedConversionError)
+ end
- it "raises an ArgumentError if called on a finished stream" do
- ec = Encoding::Converter.new('UTF-8', Encoding.find('macCyrillic'))
- ec.finish
- lambda { ec.convert("\u{65}") }.should raise_error(ArgumentError)
- end
+ it "raises an ArgumentError if called on a finished stream" do
+ ec = Encoding::Converter.new('UTF-8', Encoding.find('macCyrillic'))
+ ec.finish
+ -> { ec.convert("\u{65}") }.should.raise(ArgumentError)
end
end
diff --git a/spec/ruby/core/encoding/converter/convpath_spec.rb b/spec/ruby/core/encoding/converter/convpath_spec.rb
index 679b894f58..23f1e5dc33 100644
--- a/spec/ruby/core/encoding/converter/convpath_spec.rb
+++ b/spec/ruby/core/encoding/converter/convpath_spec.rb
@@ -1,65 +1,24 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
-with_feature :encoding do
- describe "Encoding::Converter#convpath" do
- before :all do
- @perms = Encoding.name_list.permutation(2).map do |pair|
- Encoding::Converter.new(pair.first, pair.last) rescue nil
- end.compact.map{|ec| ec.convpath}
- end
-
- it "returns an Array" do
- ec = Encoding::Converter.new('ASCII', 'EUC-JP')
- ec.convpath.should be_an_instance_of(Array)
- end
-
- it "returns each encoding pair as a sub-Array" do
- ec = Encoding::Converter.new('ASCII', 'EUC-JP')
- ec.convpath.first.should be_an_instance_of(Array)
- ec.convpath.first.size.should == 2
- end
-
- it "returns each encoding as an Encoding object" do
- ec = Encoding::Converter.new('ASCII', 'EUC-JP')
- ec.convpath.first.first.should be_an_instance_of(Encoding)
- ec.convpath.first.last.should be_an_instance_of(Encoding)
- end
-
- it "returns multiple encoding pairs when direct conversion is impossible" do
- ec = Encoding::Converter.new('ascii','Big5')
- ec.convpath.size.should == 2
- ec.convpath.first.first.should == Encoding::US_ASCII
- ec.convpath.first.last.should == ec.convpath.last.first
- ec.convpath.last.last.should == Encoding::Big5
- end
-
- it "sets the last element of each pair to the first element of the next" do
- @perms.each do |convpath|
- next if convpath.size == 1
- convpath.each_with_index do |pair, idx|
- break if idx == convpath.size - 1
- pair.last.should == convpath[idx+1].first
- end
- end
- end
+describe "Encoding::Converter#convpath" do
+ it "returns an Array with a single element if there is a direct converter" do
+ cp = Encoding::Converter.new('ASCII', 'UTF-8').convpath
+ cp.should == [[Encoding::US_ASCII, Encoding::UTF_8]]
+ end
- it "only lists a source encoding once" do
- @perms.each do |convpath|
- next if convpath.size < 2
- seen = Hash.new(false)
- convpath.each_with_index do |pair, idx|
- seen.key?(pair.first).should be_false if idx > 0
- seen[pair.first] = true
- end
- end
- end
+ it "returns multiple encoding pairs when direct conversion is impossible" do
+ cp = Encoding::Converter.new('ascii','Big5').convpath
+ cp.should == [
+ [Encoding::US_ASCII, Encoding::UTF_8],
+ [Encoding::UTF_8, Encoding::Big5]
+ ]
+ end
- it "indicates if crlf_newline conversion would occur" do
- ec = Encoding::Converter.new("ISo-8859-1", "EUC-JP", {crlf_newline: true})
- ec.convpath.last.should == "crlf_newline"
+ it "indicates if crlf_newline conversion would occur" do
+ ec = Encoding::Converter.new("ISo-8859-1", "EUC-JP", crlf_newline: true)
+ ec.convpath.last.should == "crlf_newline"
- ec = Encoding::Converter.new("ASCII", "UTF-8", {crlf_newline: false})
- ec.convpath.last.should_not == "crlf_newline"
- end
+ ec = Encoding::Converter.new("ASCII", "UTF-8", crlf_newline: false)
+ ec.convpath.last.should_not == "crlf_newline"
end
end
diff --git a/spec/ruby/core/encoding/converter/destination_encoding_spec.rb b/spec/ruby/core/encoding/converter/destination_encoding_spec.rb
index 830e6d2178..481a857909 100644
--- a/spec/ruby/core/encoding/converter/destination_encoding_spec.rb
+++ b/spec/ruby/core/encoding/converter/destination_encoding_spec.rb
@@ -1,13 +1,11 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
-with_feature :encoding do
- describe "Encoding::Converter#destination_encoding" do
- it "returns the destination encoding as an Encoding object" do
- ec = Encoding::Converter.new('ASCII','Big5')
- ec.destination_encoding.should == Encoding::BIG5
+describe "Encoding::Converter#destination_encoding" do
+ it "returns the destination encoding as an Encoding object" do
+ ec = Encoding::Converter.new('ASCII','Big5')
+ ec.destination_encoding.should == Encoding::BIG5
- ec = Encoding::Converter.new('SJIS','EUC-JP')
- ec.destination_encoding.should == Encoding::EUC_JP
- end
+ ec = Encoding::Converter.new('SJIS','EUC-JP')
+ ec.destination_encoding.should == Encoding::EUC_JP
end
end
diff --git a/spec/ruby/core/encoding/converter/finish_spec.rb b/spec/ruby/core/encoding/converter/finish_spec.rb
index 86097357f4..e13b7415f8 100644
--- a/spec/ruby/core/encoding/converter/finish_spec.rb
+++ b/spec/ruby/core/encoding/converter/finish_spec.rb
@@ -1,38 +1,36 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
-with_feature :encoding do
- describe "Encoding::Converter#finish" do
- before :each do
- @ec = Encoding::Converter.new("utf-8", "iso-2022-jp")
- end
+describe "Encoding::Converter#finish" do
+ before :each do
+ @ec = Encoding::Converter.new("utf-8", "iso-2022-jp")
+ end
- it "returns a String" do
- @ec.convert('foo')
- @ec.finish.should be_an_instance_of(String)
- end
+ it "returns a String" do
+ @ec.convert('foo')
+ @ec.finish.should.instance_of?(String)
+ end
- it "returns an empty String if there is nothing more to convert" do
- @ec.convert("glark")
- @ec.finish.should == ""
- end
+ it "returns an empty String if there is nothing more to convert" do
+ @ec.convert("glark")
+ @ec.finish.should == ""
+ end
- it "returns the last part of the converted String if it hasn't already" do
- @ec.convert("\u{9999}").should == "\e$B9a".force_encoding('iso-2022-jp')
- @ec.finish.should == "\e(B".force_encoding('iso-2022-jp')
- end
+ it "returns the last part of the converted String if it hasn't already" do
+ @ec.convert("\u{9999}").should == "\e$B9a".dup.force_encoding('iso-2022-jp')
+ @ec.finish.should == "\e(B".dup.force_encoding('iso-2022-jp')
+ end
- it "returns a String in the destination encoding" do
- @ec.convert("glark")
- @ec.finish.encoding.should == Encoding::ISO2022_JP
- end
+ it "returns a String in the destination encoding" do
+ @ec.convert("glark")
+ @ec.finish.encoding.should == Encoding::ISO2022_JP
+ end
- it "returns an empty String if self was not given anything to convert" do
- @ec.finish.should == ""
- end
+ it "returns an empty String if self was not given anything to convert" do
+ @ec.finish.should == ""
+ end
- it "returns an empty String on subsequent invocations" do
- @ec.finish.should == ""
- @ec.finish.should == ""
- end
+ it "returns an empty String on subsequent invocations" do
+ @ec.finish.should == ""
+ @ec.finish.should == ""
end
end
diff --git a/spec/ruby/core/encoding/converter/insert_output_spec.rb b/spec/ruby/core/encoding/converter/insert_output_spec.rb
index bc9a56ba45..1346adde1e 100644
--- a/spec/ruby/core/encoding/converter/insert_output_spec.rb
+++ b/spec/ruby/core/encoding/converter/insert_output_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "Encoding::Converter#insert_output" do
it "needs to be reviewed for spec completeness"
diff --git a/spec/ruby/core/encoding/converter/inspect_spec.rb b/spec/ruby/core/encoding/converter/inspect_spec.rb
index b8216176cf..3170ee451f 100644
--- a/spec/ruby/core/encoding/converter/inspect_spec.rb
+++ b/spec/ruby/core/encoding/converter/inspect_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "Encoding::Converter#inspect" do
it "includes the source and destination encodings in the return value" do
diff --git a/spec/ruby/core/encoding/converter/last_error_spec.rb b/spec/ruby/core/encoding/converter/last_error_spec.rb
index 8465935368..3984a628f5 100644
--- a/spec/ruby/core/encoding/converter/last_error_spec.rb
+++ b/spec/ruby/core/encoding/converter/last_error_spec.rb
@@ -1,85 +1,91 @@
-# -*- encoding: binary -*-
-require File.expand_path('../../../../spec_helper', __FILE__)
+# encoding: binary
+require_relative '../../../spec_helper'
-with_feature :encoding do
- describe "Encoding::Converter#last_error" do
- it "returns nil when the no conversion has been attempted" do
- ec = Encoding::Converter.new('ascii','utf-8')
- ec.last_error.should be_nil
- end
+describe "Encoding::Converter#last_error" do
+ it "returns nil when the no conversion has been attempted" do
+ ec = Encoding::Converter.new('ascii','utf-8')
+ ec.last_error.should == nil
+ end
- it "returns nil when the last conversion did not produce an error" do
- ec = Encoding::Converter.new('ascii','utf-8')
- ec.convert('a'.force_encoding('ascii'))
- ec.last_error.should be_nil
- end
+ it "returns nil when the last conversion did not produce an error" do
+ ec = Encoding::Converter.new('ascii','utf-8')
+ ec.convert('a'.dup.force_encoding('ascii'))
+ ec.last_error.should == nil
+ end
- it "returns nil when #primitive_convert last returned :destination_buffer_full" do
- ec = Encoding::Converter.new("utf-8", "iso-2022-jp")
- ec.primitive_convert("\u{9999}", "", 0, 0, partial_input: false) \
- .should == :destination_buffer_full
- ec.last_error.should be_nil
- end
+ it "returns nil when #primitive_convert last returned :destination_buffer_full" do
+ ec = Encoding::Converter.new("utf-8", "iso-2022-jp")
+ ec.primitive_convert(+"\u{9999}", +"", 0, 0, partial_input: false) \
+ .should == :destination_buffer_full
+ ec.last_error.should == nil
+ end
- it "returns nil when #primitive_convert last returned :finished" do
- ec = Encoding::Converter.new("utf-8", "iso-8859-1")
- ec.primitive_convert("glark".force_encoding('utf-8'),"").should == :finished
- ec.last_error.should be_nil
- end
+ it "returns nil when #primitive_convert last returned :finished" do
+ ec = Encoding::Converter.new("utf-8", "iso-8859-1")
+ ec.primitive_convert("glark".dup.force_encoding('utf-8'), +"").should == :finished
+ ec.last_error.should == nil
+ end
- it "returns nil if the last conversion succeeded but the penultimate failed" do
- ec = Encoding::Converter.new("utf-8", "iso-8859-1")
- ec.primitive_convert("\xf1abcd","").should == :invalid_byte_sequence
- ec.primitive_convert("glark".force_encoding('utf-8'),"").should == :finished
- ec.last_error.should be_nil
- end
+ it "returns nil if the last conversion succeeded but the penultimate failed" do
+ ec = Encoding::Converter.new("utf-8", "iso-8859-1")
+ ec.primitive_convert(+"\xf1abcd", +"").should == :invalid_byte_sequence
+ ec.primitive_convert("glark".dup.force_encoding('utf-8'), +"").should == :finished
+ ec.last_error.should == nil
+ end
- it "returns an Encoding::InvalidByteSequenceError when #primitive_convert last returned :invalid_byte_sequence" do
- ec = Encoding::Converter.new("utf-8", "iso-8859-1")
- ec.primitive_convert("\xf1abcd","").should == :invalid_byte_sequence
- ec.last_error.should be_an_instance_of(Encoding::InvalidByteSequenceError)
- end
+ it "returns an Encoding::InvalidByteSequenceError when #primitive_convert last returned :invalid_byte_sequence" do
+ ec = Encoding::Converter.new("utf-8", "iso-8859-1")
+ ec.primitive_convert(+"\xf1abcd", +"").should == :invalid_byte_sequence
+ ec.last_error.should.instance_of?(Encoding::InvalidByteSequenceError)
+ end
- it "returns an Encoding::UndefinedConversionError when #primitive_convert last returned :undefined_conversion" do
- ec = Encoding::Converter.new("utf-8", "iso-8859-1")
- ec.primitive_convert("\u{9876}","").should == :undefined_conversion
- ec.last_error.should be_an_instance_of(Encoding::UndefinedConversionError)
- end
+ it "returns an Encoding::UndefinedConversionError when #primitive_convert last returned :undefined_conversion" do
+ ec = Encoding::Converter.new("utf-8", "iso-8859-1")
+ ec.primitive_convert(+"\u{9876}", +"").should == :undefined_conversion
+ ec.last_error.should.instance_of?(Encoding::UndefinedConversionError)
+ end
- it "returns an Encoding::InvalidByteSequenceError when #primitive_convert last returned :incomplete_input" do
- ec = Encoding::Converter.new("EUC-JP", "ISO-8859-1")
- ec.primitive_convert("\xa4", "", nil, 10).should == :incomplete_input
- ec.last_error.should be_an_instance_of(Encoding::InvalidByteSequenceError)
- end
+ it "returns an Encoding::InvalidByteSequenceError when #primitive_convert last returned :incomplete_input" do
+ ec = Encoding::Converter.new("EUC-JP", "ISO-8859-1")
+ ec.primitive_convert(+"\xa4", +"", nil, 10).should == :incomplete_input
+ ec.last_error.should.instance_of?(Encoding::InvalidByteSequenceError)
+ end
- it "returns an Encoding::InvalidByteSequenceError when the last call to #convert produced one" do
- ec = Encoding::Converter.new("utf-8", "iso-8859-1")
- exception = nil
- lambda do
- begin
- ec.convert("\xf1abcd")
- rescue Encoding::InvalidByteSequenceError => e
- exception = e
- raise e
- end
- end.should raise_error(Encoding::InvalidByteSequenceError)
- ec.last_error.should be_an_instance_of(Encoding::InvalidByteSequenceError)
- ec.last_error.message.should == exception.message
- end
+ it "returns an Encoding::InvalidByteSequenceError when the last call to #convert produced one" do
+ ec = Encoding::Converter.new("utf-8", "iso-8859-1")
+ exception = nil
+ -> {
+ ec.convert("\xf1abcd")
+ }.should.raise(Encoding::InvalidByteSequenceError) { |e|
+ exception = e
+ }
+ ec.last_error.should.instance_of?(Encoding::InvalidByteSequenceError)
+ ec.last_error.message.should == exception.message
+ end
+
+ it "returns an Encoding::UndefinedConversionError when the last call to #convert produced one" do
+ ec = Encoding::Converter.new("utf-8", "iso-8859-1")
+ exception = nil
+ -> {
+ ec.convert("\u{9899}")
+ }.should.raise(Encoding::UndefinedConversionError) { |e|
+ exception = e
+ }
+ ec.last_error.should.instance_of?(Encoding::UndefinedConversionError)
+ ec.last_error.message.should == exception.message
+ ec.last_error.message.should.include? "from UTF-8 to ISO-8859-1"
+ end
- it "returns an Encoding::UndefinedConversionError when the last call to #convert produced one" do
- ec = Encoding::Converter.new("utf-8", "iso-8859-1")
- exception = nil
- lambda do
- begin
- ec.convert("\u{9899}")
- rescue Encoding::UndefinedConversionError => e
- exception = e
- raise e
- end
- end.should raise_error(Encoding::UndefinedConversionError)
- ec.last_error.should be_an_instance_of(Encoding::UndefinedConversionError)
- ec.last_error.message.should == exception.message
- end
+ it "returns the last error of #convert with a message showing the transcoding path" do
+ ec = Encoding::Converter.new("iso-8859-1", "Big5")
+ exception = nil
+ -> {
+ ec.convert("\xE9") # é in ISO-8859-1
+ }.should.raise(Encoding::UndefinedConversionError) { |e|
+ exception = e
+ }
+ ec.last_error.should.instance_of?(Encoding::UndefinedConversionError)
+ ec.last_error.message.should == exception.message
+ ec.last_error.message.should.include? "from ISO-8859-1 to UTF-8 to Big5"
end
end
diff --git a/spec/ruby/core/encoding/converter/new_spec.rb b/spec/ruby/core/encoding/converter/new_spec.rb
index d228c80a18..bbdfb48bce 100644
--- a/spec/ruby/core/encoding/converter/new_spec.rb
+++ b/spec/ruby/core/encoding/converter/new_spec.rb
@@ -1,120 +1,118 @@
-# -*- encoding: ascii-8bit -*-
-require File.expand_path('../../../../spec_helper', __FILE__)
-
-with_feature :encoding do
- describe "Encoding::Converter.new" do
- it "accepts a String for the source encoding" do
- conv = Encoding::Converter.new("us-ascii", "utf-8")
- conv.source_encoding.should == Encoding::US_ASCII
- end
+# encoding: binary
+require_relative '../../../spec_helper'
- it "accepts a String for the destination encoding" do
- conv = Encoding::Converter.new("us-ascii", "utf-8")
- conv.destination_encoding.should == Encoding::UTF_8
- end
+describe "Encoding::Converter.new" do
+ it "accepts a String for the source encoding" do
+ conv = Encoding::Converter.new("us-ascii", "utf-8")
+ conv.source_encoding.should == Encoding::US_ASCII
+ end
- it "accepts an Encoding object for the source encoding" do
- conv = Encoding::Converter.new(Encoding::US_ASCII, "utf-8")
- conv.source_encoding.should == Encoding::US_ASCII
- end
+ it "accepts a String for the destination encoding" do
+ conv = Encoding::Converter.new("us-ascii", "utf-8")
+ conv.destination_encoding.should == Encoding::UTF_8
+ end
- it "accepts an Encoding object for the destination encoding" do
- conv = Encoding::Converter.new("us-ascii", Encoding::UTF_8)
- conv.destination_encoding.should == Encoding::UTF_8
- end
+ it "accepts an Encoding object for the source encoding" do
+ conv = Encoding::Converter.new(Encoding::US_ASCII, "utf-8")
+ conv.source_encoding.should == Encoding::US_ASCII
+ end
- it "raises an Encoding::ConverterNotFoundError if both encodings are the same" do
- lambda do
- Encoding::Converter.new "utf-8", "utf-8"
- end.should raise_error(Encoding::ConverterNotFoundError)
- end
+ it "accepts an Encoding object for the destination encoding" do
+ conv = Encoding::Converter.new("us-ascii", Encoding::UTF_8)
+ conv.destination_encoding.should == Encoding::UTF_8
+ end
- it "calls #to_str to convert the source encoding argument to an encoding name" do
- enc = mock("us-ascii")
- enc.should_receive(:to_str).and_return("us-ascii")
- conv = Encoding::Converter.new(enc, "utf-8")
- conv.source_encoding.should == Encoding::US_ASCII
- end
+ it "raises an Encoding::ConverterNotFoundError if both encodings are the same" do
+ -> do
+ Encoding::Converter.new "utf-8", "utf-8"
+ end.should.raise(Encoding::ConverterNotFoundError)
+ end
- it "calls #to_str to convert the destination encoding argument to an encoding name" do
- enc = mock("utf-8")
- enc.should_receive(:to_str).and_return("utf-8")
- conv = Encoding::Converter.new("us-ascii", enc)
- conv.destination_encoding.should == Encoding::UTF_8
- end
+ it "calls #to_str to convert the source encoding argument to an encoding name" do
+ enc = mock("us-ascii")
+ enc.should_receive(:to_str).and_return("us-ascii")
+ conv = Encoding::Converter.new(enc, "utf-8")
+ conv.source_encoding.should == Encoding::US_ASCII
+ end
- it "sets replacement from the options Hash" do
- conv = Encoding::Converter.new("us-ascii", "utf-8", replace: "fubar")
- conv.replacement.should == "fubar"
- end
+ it "calls #to_str to convert the destination encoding argument to an encoding name" do
+ enc = mock("utf-8")
+ enc.should_receive(:to_str).and_return("utf-8")
+ conv = Encoding::Converter.new("us-ascii", enc)
+ conv.destination_encoding.should == Encoding::UTF_8
+ end
- it "calls #to_hash to convert the options argument to a Hash if not a Fixnum" do
- opts = mock("encoding converter options")
- opts.should_receive(:to_hash).and_return({ replace: "fubar" })
- conv = Encoding::Converter.new("us-ascii", "utf-8", opts)
- conv.replacement.should == "fubar"
- end
+ it "sets replacement from the options Hash" do
+ conv = Encoding::Converter.new("us-ascii", "utf-8", replace: "fubar")
+ conv.replacement.should == "fubar"
+ end
- it "calls #to_str to convert the replacement object to a String" do
- obj = mock("encoding converter replacement")
- obj.should_receive(:to_str).and_return("fubar")
- conv = Encoding::Converter.new("us-ascii", "utf-8", replace: obj)
- conv.replacement.should == "fubar"
- end
+ it "calls #to_hash to convert the options argument to a Hash if not an Integer" do
+ opts = mock("encoding converter options")
+ opts.should_receive(:to_hash).and_return({ replace: "fubar" })
+ conv = Encoding::Converter.new("us-ascii", "utf-8", **opts)
+ conv.replacement.should == "fubar"
+ end
- it "raises a TypeError if #to_str does not return a String" do
- obj = mock("encoding converter replacement")
- obj.should_receive(:to_str).and_return(1)
+ it "calls #to_str to convert the replacement object to a String" do
+ obj = mock("encoding converter replacement")
+ obj.should_receive(:to_str).and_return("fubar")
+ conv = Encoding::Converter.new("us-ascii", "utf-8", replace: obj)
+ conv.replacement.should == "fubar"
+ end
- lambda do
- Encoding::Converter.new("us-ascii", "utf-8", replace: obj)
- end.should raise_error(TypeError)
- end
+ it "raises a TypeError if #to_str does not return a String" do
+ obj = mock("encoding converter replacement")
+ obj.should_receive(:to_str).and_return(1)
- it "raises a TypeError if passed true for the replacement object" do
- lambda do
- Encoding::Converter.new("us-ascii", "utf-8", replace: true)
- end.should raise_error(TypeError)
- end
+ -> do
+ Encoding::Converter.new("us-ascii", "utf-8", replace: obj)
+ end.should.raise(TypeError)
+ end
- it "raises a TypeError if passed false for the replacement object" do
- lambda do
- Encoding::Converter.new("us-ascii", "utf-8", replace: false)
- end.should raise_error(TypeError)
- end
+ it "raises a TypeError if passed true for the replacement object" do
+ -> do
+ Encoding::Converter.new("us-ascii", "utf-8", replace: true)
+ end.should.raise(TypeError)
+ end
- it "raises a TypeError if passed a Fixnum for the replacement object" do
- lambda do
- Encoding::Converter.new("us-ascii", "utf-8", replace: 1)
- end.should raise_error(TypeError)
- end
+ it "raises a TypeError if passed false for the replacement object" do
+ -> do
+ Encoding::Converter.new("us-ascii", "utf-8", replace: false)
+ end.should.raise(TypeError)
+ end
- it "accepts an empty String for the replacement object" do
- conv = Encoding::Converter.new("us-ascii", "utf-8", replace: "")
- conv.replacement.should == ""
- end
+ it "raises a TypeError if passed an Integer for the replacement object" do
+ -> do
+ Encoding::Converter.new("us-ascii", "utf-8", replace: 1)
+ end.should.raise(TypeError)
+ end
+
+ it "accepts an empty String for the replacement object" do
+ conv = Encoding::Converter.new("us-ascii", "utf-8", replace: "")
+ conv.replacement.should == ""
+ end
+
+ describe "when passed nil for the replacement object" do
+ describe "when the destination encoding is not UTF-8" do
+ it "sets the replacement String to '?'" do
+ conv = Encoding::Converter.new("us-ascii", "binary", replace: nil)
+ conv.replacement.should == "?"
+ end
+
+ it "sets the replacement String encoding to US-ASCII" do
+ conv = Encoding::Converter.new("us-ascii", "binary", replace: nil)
+ conv.replacement.encoding.should == Encoding::US_ASCII
+ end
+
+ it "sets the replacement String to '\\uFFFD'" do
+ conv = Encoding::Converter.new("us-ascii", "utf-8", replace: nil)
+ conv.replacement.should == "\u{fffd}".dup.force_encoding("utf-8")
+ end
- describe "when passed nil for the replacement object" do
- describe "when the destination encoding is not UTF-8" do
- it "sets the replacement String to '?'" do
- conv = Encoding::Converter.new("us-ascii", "ascii-8bit", replace: nil)
- conv.replacement.should == "?"
- end
-
- it "sets the replacement String encoding to US-ASCII" do
- conv = Encoding::Converter.new("us-ascii", "ascii-8bit", replace: nil)
- conv.replacement.encoding.should == Encoding::US_ASCII
- end
-
- it "sets the replacement String to '\\uFFFD'" do
- conv = Encoding::Converter.new("us-ascii", "utf-8", replace: nil)
- conv.replacement.should == "\u{fffd}".force_encoding("utf-8")
- end
-
- it "sets the replacement String encoding to UTF-8" do
- conv = Encoding::Converter.new("us-ascii", "utf-8", replace: nil)
- conv.replacement.encoding.should == Encoding::UTF_8
- end
+ it "sets the replacement String encoding to UTF-8" do
+ conv = Encoding::Converter.new("us-ascii", "utf-8", replace: nil)
+ conv.replacement.encoding.should == Encoding::UTF_8
end
end
end
diff --git a/spec/ruby/core/encoding/converter/primitive_convert_spec.rb b/spec/ruby/core/encoding/converter/primitive_convert_spec.rb
index ed479c6b13..ab9ce6a992 100644
--- a/spec/ruby/core/encoding/converter/primitive_convert_spec.rb
+++ b/spec/ruby/core/encoding/converter/primitive_convert_spec.rb
@@ -1,213 +1,216 @@
-# -*- encoding: binary -*-
-require File.expand_path('../../../../spec_helper', __FILE__)
-
-with_feature :encoding do
- describe "Encoding::Converter#primitive_convert" do
- before :each do
- @ec = Encoding::Converter.new("utf-8", "iso-8859-1")
- end
-
- it "accepts a nil source buffer" do
- lambda { @ec.primitive_convert(nil,"") }.should_not raise_error
- end
-
- it "accepts a String as the source buffer" do
- lambda { @ec.primitive_convert("","") }.should_not raise_error
- end
-
- it "accepts nil for the destination byte offset" do
- lambda { @ec.primitive_convert("","", nil) }.should_not raise_error
- end
-
- it "accepts an integer for the destination byte offset" do
- lambda { @ec.primitive_convert("","a", 1) }.should_not raise_error
- end
-
- it "calls #to_int to convert the destination byte offset" do
- offset = mock("encoding primitive_convert destination byte offset")
- offset.should_receive(:to_int).and_return(2)
- @ec.primitive_convert("abc", result = " ", offset).should == :finished
- result.should == " abc"
- end
-
- it "raises an ArgumentError if the destination byte offset is greater than the bytesize of the destination buffer" do
- lambda { @ec.primitive_convert("","am", 0) }.should_not raise_error
- lambda { @ec.primitive_convert("","am", 1) }.should_not raise_error
- lambda { @ec.primitive_convert("","am", 2) }.should_not raise_error
- lambda { @ec.primitive_convert("","am", 3) }.should raise_error(ArgumentError)
- end
-
- it "uses the destination byte offset to determine where to write the result in the destination buffer" do
- dest = "aa"
- @ec.primitive_convert("b",dest, nil, 0)
- dest.should == "aa"
-
- @ec.primitive_convert("b",dest, nil, 1)
- dest.should == "aab"
-
- @ec.primitive_convert("b",dest, nil, 2)
- dest.should == "aabbb"
- end
-
- it "accepts nil for the destination bytesize" do
- lambda { @ec.primitive_convert("","", nil, nil) }.should_not raise_error
- end
-
- it "accepts an integer for the destination bytesize" do
- lambda { @ec.primitive_convert("","", nil, 0) }.should_not raise_error
- end
-
- it "allows a destination bytesize value greater than the bytesize of the source buffer" do
- lambda { @ec.primitive_convert("am","", nil, 3) }.should_not raise_error
- end
-
- it "allows a destination bytesize value less than the bytesize of the source buffer" do
- lambda { @ec.primitive_convert("am","", nil, 1) }.should_not raise_error
- end
-
- it "calls #to_int to convert the destination byte size" do
- size = mock("encoding primitive_convert destination byte size")
- size.should_receive(:to_int).and_return(2)
- @ec.primitive_convert("abc", result = " ", 0, size).should == :destination_buffer_full
- result.should == "ab"
- end
-
- it "uses destination bytesize as the maximum bytesize of the destination buffer" do
- dest = ""
- @ec.primitive_convert("glark", dest, nil, 1)
- dest.bytesize.should == 1
- end
-
- it "allows a destination buffer of unlimited size if destination bytesize is nil" do
- source = "glark".force_encoding('utf-8')
- dest = ""
- @ec.primitive_convert("glark", dest, nil, nil)
- dest.bytesize.should == source.bytesize
- end
-
- it "accepts an options hash" do
- @ec.primitive_convert("","",nil,nil, {after_output: true}).should == :finished
- end
-
- it "sets the destination buffer's encoding to the destination encoding if the conversion succeeded" do
- dest = "".force_encoding('utf-8')
- dest.encoding.should == Encoding::UTF_8
- @ec.primitive_convert("\u{98}",dest).should == :finished
- dest.encoding.should == Encoding::ISO_8859_1
- end
-
- it "sets the destination buffer's encoding to the destination encoding if the conversion failed" do
- dest = "".force_encoding('utf-8')
- dest.encoding.should == Encoding::UTF_8
- @ec.primitive_convert("\u{9878}",dest).should == :undefined_conversion
- dest.encoding.should == Encoding::ISO_8859_1
- end
-
- it "removes the undefined part from the source buffer when returning :undefined_conversion" do
- dest = "".force_encoding('utf-8')
- s = "\u{9878}abcd"
- @ec.primitive_convert(s, dest).should == :undefined_conversion
-
- s.should == "abcd"
- end
-
- it "returns :incomplete_input when source buffer ends unexpectedly and :partial_input isn't specified" do
- ec = Encoding::Converter.new("EUC-JP", "ISO-8859-1")
- ec.primitive_convert("\xa4", "", nil, nil, partial_input: false).should == :incomplete_input
- end
-
- it "clears the source buffer when returning :incomplete_input" do
- ec = Encoding::Converter.new("EUC-JP", "ISO-8859-1")
- s = "\xa4"
- ec.primitive_convert(s, "").should == :incomplete_input
-
- s.should == ""
- end
-
- it "returns :source_buffer_empty when source buffer ends unexpectedly and :partial_input is true" do
- ec = Encoding::Converter.new("EUC-JP", "ISO-8859-1")
- ec.primitive_convert("\xa4", "", nil, nil, partial_input: true).should == :source_buffer_empty
- end
-
- it "clears the source buffer when returning :source_buffer_empty" do
- ec = Encoding::Converter.new("EUC-JP", "ISO-8859-1")
- s = "\xa4"
- ec.primitive_convert(s, "", nil, nil, partial_input: true).should == :source_buffer_empty
-
- s.should == ""
- end
-
- it "returns :undefined_conversion when a character in the source buffer is not representable in the output encoding" do
- @ec.primitive_convert("\u{9876}","").should == :undefined_conversion
- end
-
- it "returns :invalid_byte_sequence when an invalid byte sequence was found in the source buffer" do
- @ec.primitive_convert("\xf1abcd","").should == :invalid_byte_sequence
- end
-
- it "removes consumed and erroneous bytes from the source buffer when returning :invalid_byte_sequence" do
- ec = Encoding::Converter.new(Encoding::UTF_8, Encoding::UTF_8_MAC)
- s = "\xC3\xA1\x80\x80\xC3\xA1".force_encoding("utf-8")
- dest = "".force_encoding("utf-8")
- ec.primitive_convert(s, dest)
-
- s.should == "\x80\xC3\xA1".force_encoding("utf-8")
- end
-
- it "returns :finished when the conversion succeeded" do
- @ec.primitive_convert("glark".force_encoding('utf-8'),"").should == :finished
- end
-
- it "clears the source buffer when returning :finished" do
- s = "glark".force_encoding('utf-8')
- @ec.primitive_convert(s, "").should == :finished
-
- s.should == ""
- end
-
- it "returns :destination_buffer_full when the destination buffer is too small" do
- ec = Encoding::Converter.new("utf-8", "iso-2022-jp")
- source = "\u{9999}"
- destination_bytesize = source.bytesize - 1
- ec.primitive_convert(source, "", 0, destination_bytesize) \
- .should == :destination_buffer_full
- source.should == ""
- end
-
- it "clears the source buffer when returning :destination_buffer_full" do
- ec = Encoding::Converter.new("utf-8", "iso-2022-jp")
- s = "\u{9999}"
- destination_bytesize = s.bytesize - 1
- ec.primitive_convert(s, "", 0, destination_bytesize).should == :destination_buffer_full
-
- s.should == ""
- end
-
- it "keeps removing invalid bytes from the source buffer" do
- ec = Encoding::Converter.new(Encoding::UTF_8, Encoding::UTF_8_MAC)
- s = "\x80\x80\x80"
- dest = "".force_encoding(Encoding::UTF_8_MAC)
-
- ec.primitive_convert(s, dest)
- s.should == "\x80\x80"
- ec.primitive_convert(s, dest)
- s.should == "\x80"
- ec.primitive_convert(s, dest)
- s.should == ""
- end
-
- it "reuses read-again bytes after the first error" do
- s = "\xf1abcd"
- dest = ""
-
- @ec.primitive_convert(s, dest).should == :invalid_byte_sequence
- s.should == "bcd"
- @ec.primitive_errinfo[4].should == "a"
-
- @ec.primitive_convert(s, dest).should == :finished
- s.should == ""
-
- dest.should == "abcd"
- end
+# encoding: binary
+# frozen_string_literal: false
+require_relative '../../../spec_helper'
+
+describe "Encoding::Converter#primitive_convert" do
+ before :each do
+ @ec = Encoding::Converter.new("utf-8", "iso-8859-1")
+ end
+
+ it "accepts a nil source buffer" do
+ -> { @ec.primitive_convert(nil,"") }.should_not.raise
+ end
+
+ it "accepts a String as the source buffer" do
+ -> { @ec.primitive_convert("","") }.should_not.raise
+ end
+
+ it "raises FrozenError when the destination buffer is a frozen String" do
+ -> { @ec.primitive_convert("", "".freeze) }.should.raise(FrozenError)
+ end
+
+ it "accepts nil for the destination byte offset" do
+ -> { @ec.primitive_convert("","", nil) }.should_not.raise
+ end
+
+ it "accepts an integer for the destination byte offset" do
+ -> { @ec.primitive_convert("","a", 1) }.should_not.raise
+ end
+
+ it "calls #to_int to convert the destination byte offset" do
+ offset = mock("encoding primitive_convert destination byte offset")
+ offset.should_receive(:to_int).and_return(2)
+ @ec.primitive_convert("abc", result = " ", offset).should == :finished
+ result.should == " abc"
+ end
+
+ it "raises an ArgumentError if the destination byte offset is greater than the bytesize of the destination buffer" do
+ -> { @ec.primitive_convert("","am", 0) }.should_not.raise
+ -> { @ec.primitive_convert("","am", 1) }.should_not.raise
+ -> { @ec.primitive_convert("","am", 2) }.should_not.raise
+ -> { @ec.primitive_convert("","am", 3) }.should.raise(ArgumentError)
+ end
+
+ it "uses the destination byte offset to determine where to write the result in the destination buffer" do
+ dest = "aa"
+ @ec.primitive_convert("b",dest, nil, 0)
+ dest.should == "aa"
+
+ @ec.primitive_convert("b",dest, nil, 1)
+ dest.should == "aab"
+
+ @ec.primitive_convert("b",dest, nil, 2)
+ dest.should == "aabbb"
+ end
+
+ it "accepts nil for the destination bytesize" do
+ -> { @ec.primitive_convert("","", nil, nil) }.should_not.raise
+ end
+
+ it "accepts an integer for the destination bytesize" do
+ -> { @ec.primitive_convert("","", nil, 0) }.should_not.raise
+ end
+
+ it "allows a destination bytesize value greater than the bytesize of the source buffer" do
+ -> { @ec.primitive_convert("am","", nil, 3) }.should_not.raise
+ end
+
+ it "allows a destination bytesize value less than the bytesize of the source buffer" do
+ -> { @ec.primitive_convert("am","", nil, 1) }.should_not.raise
+ end
+
+ it "calls #to_int to convert the destination byte size" do
+ size = mock("encoding primitive_convert destination byte size")
+ size.should_receive(:to_int).and_return(2)
+ @ec.primitive_convert("abc", result = " ", 0, size).should == :destination_buffer_full
+ result.should == "ab"
+ end
+
+ it "uses destination bytesize as the maximum bytesize of the destination buffer" do
+ dest = ""
+ @ec.primitive_convert("glark", dest, nil, 1)
+ dest.bytesize.should == 1
+ end
+
+ it "allows a destination buffer of unlimited size if destination bytesize is nil" do
+ source = "glark".force_encoding('utf-8')
+ dest = ""
+ @ec.primitive_convert("glark", dest, nil, nil)
+ dest.bytesize.should == source.bytesize
+ end
+
+ it "accepts an options hash" do
+ @ec.primitive_convert("","",nil,nil, after_output: true).should == :finished
+ end
+
+ it "sets the destination buffer's encoding to the destination encoding if the conversion succeeded" do
+ dest = "".force_encoding('utf-8')
+ dest.encoding.should == Encoding::UTF_8
+ @ec.primitive_convert("\u{98}",dest).should == :finished
+ dest.encoding.should == Encoding::ISO_8859_1
+ end
+
+ it "sets the destination buffer's encoding to the destination encoding if the conversion failed" do
+ dest = "".force_encoding('utf-8')
+ dest.encoding.should == Encoding::UTF_8
+ @ec.primitive_convert("\u{9878}",dest).should == :undefined_conversion
+ dest.encoding.should == Encoding::ISO_8859_1
+ end
+
+ it "removes the undefined part from the source buffer when returning :undefined_conversion" do
+ dest = "".force_encoding('utf-8')
+ s = "\u{9878}abcd"
+ @ec.primitive_convert(s, dest).should == :undefined_conversion
+
+ s.should == "abcd"
+ end
+
+ it "returns :incomplete_input when source buffer ends unexpectedly and :partial_input isn't specified" do
+ ec = Encoding::Converter.new("EUC-JP", "ISO-8859-1")
+ ec.primitive_convert("\xa4", "", nil, nil, partial_input: false).should == :incomplete_input
+ end
+
+ it "clears the source buffer when returning :incomplete_input" do
+ ec = Encoding::Converter.new("EUC-JP", "ISO-8859-1")
+ s = "\xa4"
+ ec.primitive_convert(s, "").should == :incomplete_input
+
+ s.should == ""
+ end
+
+ it "returns :source_buffer_empty when source buffer ends unexpectedly and :partial_input is true" do
+ ec = Encoding::Converter.new("EUC-JP", "ISO-8859-1")
+ ec.primitive_convert("\xa4", "", nil, nil, partial_input: true).should == :source_buffer_empty
+ end
+
+ it "clears the source buffer when returning :source_buffer_empty" do
+ ec = Encoding::Converter.new("EUC-JP", "ISO-8859-1")
+ s = "\xa4"
+ ec.primitive_convert(s, "", nil, nil, partial_input: true).should == :source_buffer_empty
+
+ s.should == ""
+ end
+
+ it "returns :undefined_conversion when a character in the source buffer is not representable in the output encoding" do
+ @ec.primitive_convert("\u{9876}","").should == :undefined_conversion
+ end
+
+ it "returns :invalid_byte_sequence when an invalid byte sequence was found in the source buffer" do
+ @ec.primitive_convert("\xf1abcd","").should == :invalid_byte_sequence
+ end
+
+ it "removes consumed and erroneous bytes from the source buffer when returning :invalid_byte_sequence" do
+ ec = Encoding::Converter.new(Encoding::UTF_8, Encoding::UTF_8_MAC)
+ s = "\xC3\xA1\x80\x80\xC3\xA1".force_encoding("utf-8")
+ dest = "".force_encoding("utf-8")
+ ec.primitive_convert(s, dest)
+
+ s.should == "\x80\xC3\xA1".force_encoding("utf-8")
+ end
+
+ it "returns :finished when the conversion succeeded" do
+ @ec.primitive_convert("glark".force_encoding('utf-8'),"").should == :finished
+ end
+
+ it "clears the source buffer when returning :finished" do
+ s = "glark".force_encoding('utf-8')
+ @ec.primitive_convert(s, "").should == :finished
+
+ s.should == ""
+ end
+
+ it "returns :destination_buffer_full when the destination buffer is too small" do
+ ec = Encoding::Converter.new("utf-8", "iso-2022-jp")
+ source = "\u{9999}"
+ destination_bytesize = source.bytesize - 1
+ ec.primitive_convert(source, "", 0, destination_bytesize) \
+ .should == :destination_buffer_full
+ source.should == ""
+ end
+
+ it "clears the source buffer when returning :destination_buffer_full" do
+ ec = Encoding::Converter.new("utf-8", "iso-2022-jp")
+ s = "\u{9999}"
+ destination_bytesize = s.bytesize - 1
+ ec.primitive_convert(s, "", 0, destination_bytesize).should == :destination_buffer_full
+
+ s.should == ""
+ end
+
+ it "keeps removing invalid bytes from the source buffer" do
+ ec = Encoding::Converter.new(Encoding::UTF_8, Encoding::UTF_8_MAC)
+ s = "\x80\x80\x80"
+ dest = "".force_encoding(Encoding::UTF_8_MAC)
+
+ ec.primitive_convert(s, dest)
+ s.should == "\x80\x80"
+ ec.primitive_convert(s, dest)
+ s.should == "\x80"
+ ec.primitive_convert(s, dest)
+ s.should == ""
+ end
+
+ it "reuses read-again bytes after the first error" do
+ s = "\xf1abcd"
+ dest = ""
+
+ @ec.primitive_convert(s, dest).should == :invalid_byte_sequence
+ s.should == "bcd"
+ @ec.primitive_errinfo[4].should == "a"
+
+ @ec.primitive_convert(s, dest).should == :finished
+ s.should == ""
+
+ dest.should == "abcd"
end
end
diff --git a/spec/ruby/core/encoding/converter/primitive_errinfo_spec.rb b/spec/ruby/core/encoding/converter/primitive_errinfo_spec.rb
index cba654b9fe..580e2e37e1 100644
--- a/spec/ruby/core/encoding/converter/primitive_errinfo_spec.rb
+++ b/spec/ruby/core/encoding/converter/primitive_errinfo_spec.rb
@@ -1,70 +1,69 @@
-# -*- encoding: binary -*-
-require File.expand_path('../../../../spec_helper', __FILE__)
+# encoding: binary
+# frozen_string_literal: false
+require_relative '../../../spec_helper'
-with_feature :encoding do
- describe "Encoding::Converter#primitive_errinfo" do
- it "returns [:source_buffer_empty,nil,nil,nil,nil] when no conversion has been attempted" do
- ec = Encoding::Converter.new('ascii','utf-8')
- ec.primitive_errinfo.should == [:source_buffer_empty, nil, nil, nil, nil]
- end
+describe "Encoding::Converter#primitive_errinfo" do
+ it "returns [:source_buffer_empty,nil,nil,nil,nil] when no conversion has been attempted" do
+ ec = Encoding::Converter.new('ascii','utf-8')
+ ec.primitive_errinfo.should == [:source_buffer_empty, nil, nil, nil, nil]
+ end
- it "returns [:finished,nil,nil,nil,nil] when #primitive_convert last returned :finished" do
- ec = Encoding::Converter.new('ascii','utf-8')
- ec.primitive_convert("a","").should == :finished
- ec.primitive_errinfo.should == [:finished, nil, nil, nil, nil]
- end
+ it "returns [:finished,nil,nil,nil,nil] when #primitive_convert last returned :finished" do
+ ec = Encoding::Converter.new('ascii','utf-8')
+ ec.primitive_convert("a","").should == :finished
+ ec.primitive_errinfo.should == [:finished, nil, nil, nil, nil]
+ end
- it "returns [:source_buffer_empty,nil,nil,nil, nil] when #convert last succeeded" do
- ec = Encoding::Converter.new('ascii','utf-8')
- ec.convert("a".force_encoding('ascii')).should == "a".force_encoding('utf-8')
- ec.primitive_errinfo.should == [:source_buffer_empty, nil, nil, nil, nil]
- end
+ it "returns [:source_buffer_empty,nil,nil,nil, nil] when #convert last succeeded" do
+ ec = Encoding::Converter.new('ascii','utf-8')
+ ec.convert("a".force_encoding('ascii')).should == "a".force_encoding('utf-8')
+ ec.primitive_errinfo.should == [:source_buffer_empty, nil, nil, nil, nil]
+ end
- it "returns [:destination_buffer_full,nil,nil,nil,nil] when #primitive_convert last returned :destination_buffer_full" do
- ec = Encoding::Converter.new("utf-8", "iso-2022-jp")
- ec.primitive_convert("\u{9999}", "", 0, 0, partial_input: false).should == :destination_buffer_full
- ec.primitive_errinfo.should == [:destination_buffer_full, nil, nil, nil, nil]
- end
+ it "returns [:destination_buffer_full,nil,nil,nil,nil] when #primitive_convert last returned :destination_buffer_full" do
+ ec = Encoding::Converter.new("utf-8", "iso-2022-jp")
+ ec.primitive_convert("\u{9999}", "", 0, 0, partial_input: false).should == :destination_buffer_full
+ ec.primitive_errinfo.should == [:destination_buffer_full, nil, nil, nil, nil]
+ end
- it "returns the status of the last primitive conversion, even if it was successful and the previous one wasn't" do
- ec = Encoding::Converter.new("utf-8", "iso-8859-1")
- ec.primitive_convert("\xf1abcd","").should == :invalid_byte_sequence
- ec.primitive_convert("glark".force_encoding('utf-8'),"").should == :finished
- ec.primitive_errinfo.should == [:finished, nil, nil, nil, nil]
- end
+ it "returns the status of the last primitive conversion, even if it was successful and the previous one wasn't" do
+ ec = Encoding::Converter.new("utf-8", "iso-8859-1")
+ ec.primitive_convert("\xf1abcd","").should == :invalid_byte_sequence
+ ec.primitive_convert("glark".force_encoding('utf-8'),"").should == :finished
+ ec.primitive_errinfo.should == [:finished, nil, nil, nil, nil]
+ end
- it "returns the state, source encoding, target encoding, and the erroneous bytes when #primitive_convert last returned :undefined_conversion" do
- ec = Encoding::Converter.new("utf-8", "iso-8859-1")
- ec.primitive_convert("\u{9876}","").should == :undefined_conversion
- ec.primitive_errinfo.should ==
- [:undefined_conversion, "UTF-8", "ISO-8859-1", "\xE9\xA1\xB6", ""]
- end
+ it "returns the state, source encoding, target encoding, and the erroneous bytes when #primitive_convert last returned :undefined_conversion" do
+ ec = Encoding::Converter.new("utf-8", "iso-8859-1")
+ ec.primitive_convert("\u{9876}","").should == :undefined_conversion
+ ec.primitive_errinfo.should ==
+ [:undefined_conversion, "UTF-8", "ISO-8859-1", "\xE9\xA1\xB6", ""]
+ end
- it "returns the state, source encoding, target encoding, and erroneous bytes when #primitive_convert last returned :incomplete_input" do
- ec = Encoding::Converter.new("EUC-JP", "ISO-8859-1")
- ec.primitive_convert("\xa4", "", nil, 10).should == :incomplete_input
- ec.primitive_errinfo.should == [:incomplete_input, "EUC-JP", "UTF-8", "\xA4", ""]
- end
+ it "returns the state, source encoding, target encoding, and erroneous bytes when #primitive_convert last returned :incomplete_input" do
+ ec = Encoding::Converter.new("EUC-JP", "ISO-8859-1")
+ ec.primitive_convert("\xa4", "", nil, 10).should == :incomplete_input
+ ec.primitive_errinfo.should == [:incomplete_input, "EUC-JP", "UTF-8", "\xA4", ""]
+ end
- it "returns the state, source encoding, target encoding, erroneous bytes, and the read-again bytes when #primitive_convert last returned :invalid_byte_sequence" do
- ec = Encoding::Converter.new("utf-8", "iso-8859-1")
- ec.primitive_convert("\xf1abcd","").should == :invalid_byte_sequence
- ec.primitive_errinfo.should ==
- [:invalid_byte_sequence, "UTF-8", "ISO-8859-1", "\xF1", "a"]
- end
+ it "returns the state, source encoding, target encoding, erroneous bytes, and the read-again bytes when #primitive_convert last returned :invalid_byte_sequence" do
+ ec = Encoding::Converter.new("utf-8", "iso-8859-1")
+ ec.primitive_convert("\xf1abcd","").should == :invalid_byte_sequence
+ ec.primitive_errinfo.should ==
+ [:invalid_byte_sequence, "UTF-8", "ISO-8859-1", "\xF1", "a"]
+ end
- it "returns the state, source encoding, target encoding, erroneous bytes, and the read-again bytes when #convert last raised InvalidByteSequenceError" do
- ec = Encoding::Converter.new("utf-8", "iso-8859-1")
- lambda { ec.convert("\xf1abcd") }.should raise_error(Encoding::InvalidByteSequenceError)
- ec.primitive_errinfo.should ==
- [:invalid_byte_sequence, "UTF-8", "ISO-8859-1", "\xF1", "a"]
- end
+ it "returns the state, source encoding, target encoding, erroneous bytes, and the read-again bytes when #convert last raised InvalidByteSequenceError" do
+ ec = Encoding::Converter.new("utf-8", "iso-8859-1")
+ -> { ec.convert("\xf1abcd") }.should.raise(Encoding::InvalidByteSequenceError)
+ ec.primitive_errinfo.should ==
+ [:invalid_byte_sequence, "UTF-8", "ISO-8859-1", "\xF1", "a"]
+ end
- it "returns the state, source encoding, target encoding, erroneous bytes, and the read-again bytes when #finish last raised InvalidByteSequenceError" do
- ec = Encoding::Converter.new("EUC-JP", "ISO-8859-1")
- ec.convert("\xa4")
- lambda { ec.finish }.should raise_error(Encoding::InvalidByteSequenceError)
- ec.primitive_errinfo.should == [:incomplete_input, "EUC-JP", "UTF-8", "\xA4", ""]
- end
+ it "returns the state, source encoding, target encoding, erroneous bytes, and the read-again bytes when #finish last raised InvalidByteSequenceError" do
+ ec = Encoding::Converter.new("EUC-JP", "ISO-8859-1")
+ ec.convert("\xa4")
+ -> { ec.finish }.should.raise(Encoding::InvalidByteSequenceError)
+ ec.primitive_errinfo.should == [:incomplete_input, "EUC-JP", "UTF-8", "\xA4", ""]
end
end
diff --git a/spec/ruby/core/encoding/converter/putback_spec.rb b/spec/ruby/core/encoding/converter/putback_spec.rb
index 3ed1ad9956..a85cec5145 100644
--- a/spec/ruby/core/encoding/converter/putback_spec.rb
+++ b/spec/ruby/core/encoding/converter/putback_spec.rb
@@ -1,49 +1,56 @@
-# -*- encoding: binary -*-
-require File.expand_path('../../../../spec_helper', __FILE__)
-
-with_feature :encoding do
- describe "Encoding::Converter#putback" do
- before :each do
- @ec = Encoding::Converter.new("EUC-JP", "ISO-8859-1")
- @ret = @ec.primitive_convert(@src="abc\xa1def", @dst="", nil, 10)
- end
-
- it "returns a String" do
- @ec.putback.should be_an_instance_of(String)
- end
-
- it "returns a String in the source encoding" do
- @ec.putback.encoding.should == Encoding::EUC_JP
- end
-
- it "returns the bytes buffered due to an :invalid_byte_sequence error" do
- @ret.should == :invalid_byte_sequence
- @ec.putback.should == 'd'
- @ec.primitive_errinfo.last.should == 'd'
- end
-
- it "allows conversion to be resumed after an :invalid_byte_sequence" do
- @src = @ec.putback + @src
- @ret = @ec.primitive_convert(@src, @dst, nil, 10)
- @ret.should == :finished
- @dst.should == "abcdef"
- @src.should == ""
- end
-
- it "returns an empty String when there are no more bytes to put back" do
- @ec.putback
- @ec.putback.should == ""
- end
-
- it "accepts an integer argument corresponding to the number of bytes to be put back" do
- ec = Encoding::Converter.new("utf-16le", "iso-8859-1")
- src = "\x00\xd8\x61\x00"
- dst = ""
- ec.primitive_convert(src, dst).should == :invalid_byte_sequence
- ec.primitive_errinfo.should == [:invalid_byte_sequence, "UTF-16LE", "UTF-8", "\x00\xD8", "a\x00"]
- ec.putback(1).should == "\x00".force_encoding("utf-16le")
- ec.putback.should == "a".force_encoding("utf-16le")
- ec.putback.should == ""
- end
+# encoding: binary
+require_relative '../../../spec_helper'
+
+describe "Encoding::Converter#putback" do
+ before :each do
+ @ec = Encoding::Converter.new("EUC-JP", "ISO-8859-1")
+ @ret = @ec.primitive_convert(@src=+"abc\xa1def", @dst=+"", nil, 10)
+ end
+
+ it "returns a String" do
+ @ec.putback.should.instance_of?(String)
+ end
+
+ it "returns a String in the source encoding" do
+ @ec.putback.encoding.should == Encoding::EUC_JP
+ end
+
+ it "returns the bytes buffered due to an :invalid_byte_sequence error" do
+ @ret.should == :invalid_byte_sequence
+ @ec.putback.should == 'd'
+ @ec.primitive_errinfo.last.should == 'd'
+ end
+
+ it "allows conversion to be resumed after an :invalid_byte_sequence" do
+ @src = @ec.putback + @src
+ @ret = @ec.primitive_convert(@src, @dst, nil, 10)
+ @ret.should == :finished
+ @dst.should == "abcdef"
+ @src.should == ""
+ end
+
+ it "returns an empty String when there are no more bytes to put back" do
+ @ec.putback
+ @ec.putback.should == ""
+ end
+
+ it "returns the problematic bytes for UTF-16LE" do
+ ec = Encoding::Converter.new("utf-16le", "iso-8859-1")
+ src = +"\x00\xd8\x61\x00"
+ dst = +""
+ ec.primitive_convert(src, dst).should == :invalid_byte_sequence
+ ec.primitive_errinfo.should == [:invalid_byte_sequence, "UTF-16LE", "UTF-8", "\x00\xD8", "a\x00"]
+ ec.putback.should == "a\x00".dup.force_encoding("utf-16le")
+ ec.putback.should == ""
+ end
+
+ it "accepts an integer argument corresponding to the number of bytes to be put back" do
+ ec = Encoding::Converter.new("utf-16le", "iso-8859-1")
+ src = +"\x00\xd8\x61\x00"
+ dst = +""
+ ec.primitive_convert(src, dst).should == :invalid_byte_sequence
+ ec.primitive_errinfo.should == [:invalid_byte_sequence, "UTF-16LE", "UTF-8", "\x00\xD8", "a\x00"]
+ ec.putback(2).should == "a\x00".dup.force_encoding("utf-16le")
+ ec.putback.should == ""
end
end
diff --git a/spec/ruby/core/encoding/converter/replacement_spec.rb b/spec/ruby/core/encoding/converter/replacement_spec.rb
index 9c25887cd7..c25ec36517 100644
--- a/spec/ruby/core/encoding/converter/replacement_spec.rb
+++ b/spec/ruby/core/encoding/converter/replacement_spec.rb
@@ -1,74 +1,70 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
-with_feature :encoding do
- describe "Encoding::Converter#replacement" do
- it "returns '?' in US-ASCII when the destination encoding is not UTF-8" do
- ec = Encoding::Converter.new("utf-8", "us-ascii")
- ec.replacement.should == "?"
- ec.replacement.encoding.should == Encoding::US_ASCII
+describe "Encoding::Converter#replacement" do
+ it "returns '?' in US-ASCII when the destination encoding is not UTF-8" do
+ ec = Encoding::Converter.new("utf-8", "us-ascii")
+ ec.replacement.should == "?"
+ ec.replacement.encoding.should == Encoding::US_ASCII
- ec = Encoding::Converter.new("utf-8", "sjis")
- ec.replacement.should == "?"
- ec.replacement.encoding.should == Encoding::US_ASCII
- end
+ ec = Encoding::Converter.new("utf-8", "sjis")
+ ec.replacement.should == "?"
+ ec.replacement.encoding.should == Encoding::US_ASCII
+ end
- it "returns \\uFFFD when the destination encoding is UTF-8" do
- ec = Encoding::Converter.new("us-ascii", "utf-8")
- ec.replacement.should == "\u{fffd}".force_encoding('utf-8')
- ec.replacement.encoding.should == Encoding::UTF_8
- end
+ it "returns \\uFFFD when the destination encoding is UTF-8" do
+ ec = Encoding::Converter.new("us-ascii", "utf-8")
+ ec.replacement.should == "\u{fffd}".dup.force_encoding('utf-8')
+ ec.replacement.encoding.should == Encoding::UTF_8
end
+end
- describe "Encoding::Converter#replacement=" do
- it "accepts a String argument" do
- ec = Encoding::Converter.new("utf-8", "us-ascii")
- ec.replacement = "!"
- ec.replacement.should == "!"
- end
+describe "Encoding::Converter#replacement=" do
+ it "accepts a String argument" do
+ ec = Encoding::Converter.new("utf-8", "us-ascii")
+ ec.replacement = "!"
+ ec.replacement.should == "!"
+ end
- it "accepts a String argument of arbitrary length" do
- ec = Encoding::Converter.new("utf-8", "us-ascii")
- ec.replacement = "?!?" * 9999
- ec.replacement.should == "?!?" * 9999
- end
+ it "accepts a String argument of arbitrary length" do
+ ec = Encoding::Converter.new("utf-8", "us-ascii")
+ ec.replacement = "?!?" * 9999
+ ec.replacement.should == "?!?" * 9999
+ end
- it "raises a TypeError if assigned a non-String argument" do
- ec = Encoding::Converter.new("utf-8", "us-ascii")
- lambda { ec.replacement = nil }.should raise_error(TypeError)
- end
+ it "raises a TypeError if assigned a non-String argument" do
+ ec = Encoding::Converter.new("utf-8", "us-ascii")
+ -> { ec.replacement = nil }.should.raise(TypeError)
+ end
- it "sets #replacement" do
- ec = Encoding::Converter.new("us-ascii", "utf-8")
- ec.replacement.should == "\u{fffd}".force_encoding('utf-8')
- ec.replacement = '?'.encode('utf-8')
- ec.replacement.should == '?'.force_encoding('utf-8')
- end
+ it "sets #replacement" do
+ ec = Encoding::Converter.new("us-ascii", "utf-8")
+ ec.replacement.should == "\u{fffd}".dup.force_encoding('utf-8')
+ ec.replacement = '?'.encode('utf-8')
+ ec.replacement.should == '?'.dup.force_encoding('utf-8')
+ end
- it "raises an UndefinedConversionError is the argument cannot be converted into the destination encoding" do
- ec = Encoding::Converter.new("sjis", "ascii")
- utf8_q = "\u{986}".force_encoding('utf-8')
- ec.primitive_convert(utf8_q.dup, "").should == :undefined_conversion
- lambda { ec.replacement = utf8_q }.should \
- raise_error(Encoding::UndefinedConversionError)
- end
+ it "raises an UndefinedConversionError is the argument cannot be converted into the destination encoding" do
+ ec = Encoding::Converter.new("sjis", "ascii")
+ utf8_q = "\u{986}".dup.force_encoding('utf-8')
+ ec.primitive_convert(utf8_q.dup, +"").should == :undefined_conversion
+ -> { ec.replacement = utf8_q }.should.raise(Encoding::UndefinedConversionError)
+ end
- it "does not change the replacement character if the argument cannot be converted into the destination encoding" do
- ec = Encoding::Converter.new("sjis", "ascii")
- utf8_q = "\u{986}".force_encoding('utf-8')
- ec.primitive_convert(utf8_q.dup, "").should == :undefined_conversion
- lambda { ec.replacement = utf8_q }.should \
- raise_error(Encoding::UndefinedConversionError)
- ec.replacement.should == "?".force_encoding('us-ascii')
- end
+ it "does not change the replacement character if the argument cannot be converted into the destination encoding" do
+ ec = Encoding::Converter.new("sjis", "ascii")
+ utf8_q = "\u{986}".dup.force_encoding('utf-8')
+ ec.primitive_convert(utf8_q.dup, +"").should == :undefined_conversion
+ -> { ec.replacement = utf8_q }.should.raise(Encoding::UndefinedConversionError)
+ ec.replacement.should == "?".dup.force_encoding('us-ascii')
+ end
- it "uses the replacement character" do
- ec = Encoding::Converter.new("utf-8", "us-ascii", :invalid => :replace, :undef => :replace)
- ec.replacement = "!"
- dest = ""
- status = ec.primitive_convert "中文123", dest
+ it "uses the replacement character" do
+ ec = Encoding::Converter.new("utf-8", "us-ascii", :invalid => :replace, :undef => :replace)
+ ec.replacement = "!"
+ dest = +""
+ status = ec.primitive_convert(+"中文123", dest)
- status.should == :finished
- dest.should == "!!123"
- end
+ status.should == :finished
+ dest.should == "!!123"
end
end
diff --git a/spec/ruby/core/encoding/converter/search_convpath_spec.rb b/spec/ruby/core/encoding/converter/search_convpath_spec.rb
index c04eeb98ad..cac44765f8 100644
--- a/spec/ruby/core/encoding/converter/search_convpath_spec.rb
+++ b/spec/ruby/core/encoding/converter/search_convpath_spec.rb
@@ -1,73 +1,30 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
-with_feature :encoding do
- describe "Encoding::Converter.search_convpath" do
- before :all do
- @perms = Encoding.name_list.permutation(2).map do |pair|
- Encoding::Converter.search_convpath(pair.first, pair.last) rescue []
- end
- end
-
- it "returns an Array" do
- Encoding::Converter.search_convpath('ASCII', 'EUC-JP').\
- should be_an_instance_of(Array)
- end
-
- it "returns each encoding pair as a sub-Array" do
- cp = Encoding::Converter.search_convpath('ASCII', 'EUC-JP')
- cp.first.should be_an_instance_of(Array)
- cp.first.size.should == 2
- end
-
- it "returns each encoding as an Encoding object" do
- cp = Encoding::Converter.search_convpath('ASCII', 'EUC-JP')
- cp.first.first.should be_an_instance_of(Encoding)
- cp.first.last.should be_an_instance_of(Encoding)
- end
-
- it "returns multiple encoding pairs when direct conversion is impossible" do
- cp = Encoding::Converter.search_convpath('ascii','Big5')
- cp.size.should == 2
- cp.first.should == [Encoding::US_ASCII, Encoding::UTF_8]
- cp.last.should == [Encoding::UTF_8, Encoding::Big5]
- end
-
- it "sets the last element of each pair to the first element of the next" do
- @perms.each do |convpath|
- next if convpath.size == 1
- convpath.each_with_index do |pair, idx|
- break if idx == convpath.size - 1
- pair.last.should == convpath[idx+1].first
- end
- end
- end
+describe "Encoding::Converter.search_convpath" do
+ it "returns an Array with a single element if there is a direct converter" do
+ cp = Encoding::Converter.search_convpath('ASCII', 'UTF-8')
+ cp.should == [[Encoding::US_ASCII, Encoding::UTF_8]]
+ end
- it "only lists a source encoding once" do
- @perms.each do |convpath|
- next if convpath.size < 2
- seen = Hash.new(false)
- convpath.each_with_index do |pair, idx|
- seen.key?(pair.first).should be_false if idx > 0
- seen[pair.first] = true
- end
- end
- end
+ it "returns multiple encoding pairs when direct conversion is impossible" do
+ cp = Encoding::Converter.search_convpath('ascii','Big5')
+ cp.should == [
+ [Encoding::US_ASCII, Encoding::UTF_8],
+ [Encoding::UTF_8, Encoding::Big5]
+ ]
+ end
- it "indicates if crlf_newline conversion would occur" do
- cp = Encoding::Converter.search_convpath(
- "ISo-8859-1", "EUC-JP", {crlf_newline: true})
- cp.last.should == "crlf_newline"
+ it "indicates if crlf_newline conversion would occur" do
+ cp = Encoding::Converter.search_convpath("ISO-8859-1", "EUC-JP", crlf_newline: true)
+ cp.last.should == "crlf_newline"
- cp = Encoding::Converter.search_convpath(
- "ASCII", "UTF-8", {crlf_newline: false})
- cp.last.should_not == "crlf_newline"
- end
+ cp = Encoding::Converter.search_convpath("ASCII", "UTF-8", crlf_newline: false)
+ cp.last.should_not == "crlf_newline"
+ end
- it "raises an Encoding::ConverterNotFoundError if no conversion path exists" do
- lambda do
- Encoding::Converter.search_convpath(
- Encoding::ASCII_8BIT, Encoding::Emacs_Mule)
- end.should raise_error(Encoding::ConverterNotFoundError)
- end
+ it "raises an Encoding::ConverterNotFoundError if no conversion path exists" do
+ -> do
+ Encoding::Converter.search_convpath(Encoding::BINARY, Encoding::Emacs_Mule)
+ end.should.raise(Encoding::ConverterNotFoundError)
end
end
diff --git a/spec/ruby/core/encoding/converter/source_encoding_spec.rb b/spec/ruby/core/encoding/converter/source_encoding_spec.rb
index acec01502d..6196f717bd 100644
--- a/spec/ruby/core/encoding/converter/source_encoding_spec.rb
+++ b/spec/ruby/core/encoding/converter/source_encoding_spec.rb
@@ -1,13 +1,11 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
-with_feature :encoding do
- describe "Encoding::Converter#source_encoding" do
- it "returns the source encoding as an Encoding object" do
- ec = Encoding::Converter.new('ASCII','Big5')
- ec.source_encoding.should == Encoding::US_ASCII
+describe "Encoding::Converter#source_encoding" do
+ it "returns the source encoding as an Encoding object" do
+ ec = Encoding::Converter.new('ASCII','Big5')
+ ec.source_encoding.should == Encoding::US_ASCII
- ec = Encoding::Converter.new('Shift_JIS','EUC-JP')
- ec.source_encoding.should == Encoding::SHIFT_JIS
- end
+ ec = Encoding::Converter.new('Shift_JIS','EUC-JP')
+ ec.source_encoding.should == Encoding::SHIFT_JIS
end
end
diff --git a/spec/ruby/core/encoding/default_external_spec.rb b/spec/ruby/core/encoding/default_external_spec.rb
index 2b026c793f..2a2bd7f6ae 100644
--- a/spec/ruby/core/encoding/default_external_spec.rb
+++ b/spec/ruby/core/encoding/default_external_spec.rb
@@ -1,74 +1,69 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
-with_feature :encoding do
- describe "Encoding.default_external" do
- before :each do
- @original_encoding = Encoding.default_external
- end
+describe "Encoding.default_external" do
+ before :each do
+ @original_encoding = Encoding.default_external
+ end
- after :each do
- Encoding.default_external = @original_encoding
- end
+ after :each do
+ Encoding.default_external = @original_encoding
+ end
- it "returns an Encoding object" do
- Encoding.default_external.should be_an_instance_of(Encoding)
- end
+ it "returns an Encoding object" do
+ Encoding.default_external.should.instance_of?(Encoding)
+ end
- it "returns the default external encoding" do
- Encoding.default_external = Encoding::UTF_8
+ it "returns the default external encoding" do
+ Encoding.default_external = Encoding::SHIFT_JIS
+ Encoding.default_external.should == Encoding::SHIFT_JIS
+ end
+
+ platform_is :windows do
+ it 'is UTF-8 by default on Windows' do
Encoding.default_external.should == Encoding::UTF_8
end
+ end
+end
- describe "with command line options" do
- it "is not changed by the -U option" do
- result = ruby_exe("print Encoding.default_external", options: '-U')
- result.should == Encoding.default_external.name
- end
-
- it "returns the encoding specified by '-E external'" do
- result = ruby_exe("print Encoding.default_external", options: '-E euc-jp')
- result.should == "EUC-JP"
- end
-
- it "returns the encoding specified by '-E external:'" do
- result = ruby_exe("print Encoding.default_external", options: '-E Shift_JIS:')
- result.should == "Shift_JIS"
- end
- end
+describe "Encoding.default_external=" do
+ before :each do
+ @original_encoding = Encoding.default_external
end
- describe "Encoding.default_external=" do
- before :each do
- @original_encoding = Encoding.default_external
- end
+ after :each do
+ Encoding.default_external = @original_encoding
+ end
- after :each do
- Encoding.default_external = @original_encoding
- end
+ it "sets the default external encoding" do
+ Encoding.default_external = Encoding::SHIFT_JIS
+ Encoding.default_external.should == Encoding::SHIFT_JIS
+ Encoding.find('external').should == Encoding::SHIFT_JIS
+ end
- it "sets the default external encoding" do
- Encoding.default_external = Encoding::UTF_8
- Encoding.default_external.should == Encoding::UTF_8
+ platform_is_not :windows do
+ it "also sets the filesystem encoding" do
+ Encoding.default_external = Encoding::SHIFT_JIS
+ Encoding.find('filesystem').should == Encoding::SHIFT_JIS
end
+ end
- it "can accept a name of an encoding as a String" do
- Encoding.default_external = 'Shift_JIS'
- Encoding.default_external.should == Encoding::SHIFT_JIS
- end
+ it "can accept a name of an encoding as a String" do
+ Encoding.default_external = 'Shift_JIS'
+ Encoding.default_external.should == Encoding::SHIFT_JIS
+ end
- it "calls #to_s on arguments that are neither Strings nor Encodings" do
- string = mock('string')
- string.should_receive(:to_str).at_least(1).and_return('US-ASCII')
- Encoding.default_external = string
- Encoding.default_external.should == Encoding::ASCII
- end
+ it "calls #to_s on arguments that are neither Strings nor Encodings" do
+ string = mock('string')
+ string.should_receive(:to_str).at_least(1).and_return('US-ASCII')
+ Encoding.default_external = string
+ Encoding.default_external.should == Encoding::ASCII
+ end
- it "raises a TypeError unless the argument is an Encoding or convertible to a String" do
- lambda { Encoding.default_external = [] }.should raise_error(TypeError)
- end
+ it "raises a TypeError unless the argument is an Encoding or convertible to a String" do
+ -> { Encoding.default_external = [] }.should.raise(TypeError)
+ end
- it "raises an ArgumentError if the argument is nil" do
- lambda { Encoding.default_external = nil }.should raise_error(ArgumentError)
- end
+ it "raises an ArgumentError if the argument is nil" do
+ -> { Encoding.default_external = nil }.should.raise(ArgumentError)
end
end
diff --git a/spec/ruby/core/encoding/default_internal_spec.rb b/spec/ruby/core/encoding/default_internal_spec.rb
index 3234929eec..38aef9dce9 100644
--- a/spec/ruby/core/encoding/default_internal_spec.rb
+++ b/spec/ruby/core/encoding/default_internal_spec.rb
@@ -1,93 +1,74 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-with_feature :encoding do
- describe "Encoding.default_internal" do
- before :each do
- @original_encoding = Encoding.default_internal
- end
-
- after :each do
- Encoding.default_internal = @original_encoding
- end
-
- it "is nil by default" do
- Encoding.default_internal.should be_nil
- end
-
- it "returns an Encoding object if a default internal encoding is set" do
- Encoding.default_internal = Encoding::ASCII
- Encoding.default_internal.should be_an_instance_of(Encoding)
- end
-
- it "returns nil if no default internal encoding is set" do
- Encoding.default_internal = nil
- Encoding.default_internal.should be_nil
- end
-
- it "returns the default internal encoding" do
- Encoding.default_internal = Encoding::ASCII_8BIT
- Encoding.default_internal.should == Encoding::ASCII_8BIT
- end
-
- describe "with command line options" do
- it "returns Encoding::UTF_8 if ruby was invoked with -U" do
- ruby_exe("print Encoding.default_internal", options: '-U').
- should == 'UTF-8'
- end
-
- it "uses the encoding specified when ruby is invoked with an '-E :internal' argument" do
- ruby_exe("print Encoding.default_internal", options: '-E :SHIFT_JIS').
- should == 'Shift_JIS'
- end
-
- it "uses the encoding specified when ruby is invoked with an '-E external:internal' argument" do
- ruby_exe("print Encoding.default_internal", options: '-E UTF-8:SHIFT_JIS').
- should == 'Shift_JIS'
- end
- end
+require_relative '../../spec_helper'
+
+describe "Encoding.default_internal" do
+ before :each do
+ @original_encoding = Encoding.default_internal
end
- describe "Encoding.default_internal=" do
- before :each do
- @original_encoding = Encoding.default_internal
- end
+ after :each do
+ Encoding.default_internal = @original_encoding
+ end
- after :each do
- Encoding.default_internal = @original_encoding
- end
+ it "is nil by default" do
+ Encoding.default_internal.should == nil
+ end
- it "sets the default internal encoding" do
- Encoding.default_internal = Encoding::SHIFT_JIS
- Encoding.default_internal.should == Encoding::SHIFT_JIS
- end
+ it "returns an Encoding object if a default internal encoding is set" do
+ Encoding.default_internal = Encoding::ASCII
+ Encoding.default_internal.should.instance_of?(Encoding)
+ end
- it "can accept a name of an encoding as a String" do
- Encoding.default_internal = 'Shift_JIS'
- Encoding.default_internal.should == Encoding::SHIFT_JIS
- end
+ it "returns nil if no default internal encoding is set" do
+ Encoding.default_internal = nil
+ Encoding.default_internal.should == nil
+ end
- it "calls #to_str to convert an object to a String" do
- obj = mock('string')
- obj.should_receive(:to_str).at_least(1).times.and_return('ascii')
+ it "returns the default internal encoding" do
+ Encoding.default_internal = Encoding::BINARY
+ Encoding.default_internal.should == Encoding::BINARY
+ end
+end
- Encoding.default_internal = obj
- Encoding.default_internal.should == Encoding::ASCII
- end
+describe "Encoding.default_internal=" do
+ before :each do
+ @original_encoding = Encoding.default_internal
+ end
- it "raises a TypeError if #to_str does not return a String" do
- obj = mock('string')
- obj.should_receive(:to_str).at_least(1).times.and_return(1)
+ after :each do
+ Encoding.default_internal = @original_encoding
+ end
- lambda { Encoding.default_internal = obj }.should raise_error(TypeError)
- end
+ it "sets the default internal encoding" do
+ Encoding.default_internal = Encoding::SHIFT_JIS
+ Encoding.default_internal.should == Encoding::SHIFT_JIS
+ end
- it "raises a TypeError when passed an object not providing #to_str" do
- lambda { Encoding.default_internal = mock("encoding") }.should raise_error(TypeError)
- end
+ it "can accept a name of an encoding as a String" do
+ Encoding.default_internal = 'Shift_JIS'
+ Encoding.default_internal.should == Encoding::SHIFT_JIS
+ end
+
+ it "calls #to_str to convert an object to a String" do
+ obj = mock('string')
+ obj.should_receive(:to_str).at_least(1).times.and_return('ascii')
+
+ Encoding.default_internal = obj
+ Encoding.default_internal.should == Encoding::ASCII
+ end
+
+ it "raises a TypeError if #to_str does not return a String" do
+ obj = mock('string')
+ obj.should_receive(:to_str).at_least(1).times.and_return(1)
+
+ -> { Encoding.default_internal = obj }.should.raise(TypeError)
+ end
+
+ it "raises a TypeError when passed an object not providing #to_str" do
+ -> { Encoding.default_internal = mock("encoding") }.should.raise(TypeError)
+ end
- it "accepts an argument of nil to unset the default internal encoding" do
- Encoding.default_internal = nil
- Encoding.default_internal.should be_nil
- end
+ it "accepts an argument of nil to unset the default internal encoding" do
+ Encoding.default_internal = nil
+ Encoding.default_internal.should == nil
end
end
diff --git a/spec/ruby/core/encoding/dummy_spec.rb b/spec/ruby/core/encoding/dummy_spec.rb
index 7917c71e47..05530a8186 100644
--- a/spec/ruby/core/encoding/dummy_spec.rb
+++ b/spec/ruby/core/encoding/dummy_spec.rb
@@ -1,16 +1,25 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
-with_feature :encoding do
- describe "Encoding#dummy?" do
- it "returns false for proper encodings" do
- Encoding::UTF_8.dummy?.should be_false
- Encoding::ASCII.dummy?.should be_false
- end
+describe "Encoding#dummy?" do
+ it "returns false for proper encodings" do
+ Encoding::UTF_8.dummy?.should == false
+ Encoding::ASCII.dummy?.should == false
+ end
+
+ it "returns true for dummy encodings" do
+ Encoding::ISO_2022_JP.dummy?.should == true
+ Encoding::CP50221.dummy?.should == true
+ Encoding::UTF_7.dummy?.should == true
+ end
+
+ it "returns true for UTF_16 and UTF_32" do
+ Encoding::UTF_16.should.dummy?
+ Encoding::UTF_32.should.dummy?
+ end
- it "returns true for dummy encodings" do
- Encoding::ISO_2022_JP.dummy?.should be_true
- Encoding::CP50221.dummy?.should be_true
- Encoding::UTF_7.dummy?.should be_true
+ it "implies not #ascii_compatible?" do
+ Encoding.list.select(&:dummy?).each do |encoding|
+ encoding.should_not.ascii_compatible?
end
end
end
diff --git a/spec/ruby/core/encoding/find_spec.rb b/spec/ruby/core/encoding/find_spec.rb
index bd195f6a1a..c5356560eb 100644
--- a/spec/ruby/core/encoding/find_spec.rb
+++ b/spec/ruby/core/encoding/find_spec.rb
@@ -1,84 +1,82 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
-with_feature :encoding do
- describe "Encoding.find" do
- before :all do
- @encodings = Encoding.aliases.to_a.flatten.uniq
- end
+describe "Encoding.find" do
+ before :all do
+ @encodings = Encoding.aliases.to_a.flatten.uniq
+ end
- it "returns the corresponding Encoding object if given a valid encoding name" do
- @encodings.each do |enc|
- Encoding.find(enc).should be_an_instance_of(Encoding)
- end
+ it "returns the corresponding Encoding object if given a valid encoding name" do
+ @encodings.each do |enc|
+ Encoding.find(enc).should.instance_of?(Encoding)
end
+ end
- it "returns the corresponding Encoding object if given a valid alias name" do
- Encoding.aliases.keys.each do |enc_alias|
- Encoding.find(enc_alias).should be_an_instance_of(Encoding)
- end
+ it "returns the corresponding Encoding object if given a valid alias name" do
+ Encoding.aliases.keys.each do |enc_alias|
+ Encoding.find(enc_alias).should.instance_of?(Encoding)
end
+ end
- it "raises a TypeError if passed a Symbol" do
- lambda { Encoding.find(:"utf-8") }.should raise_error(TypeError)
- end
+ it "raises a TypeError if passed a Symbol" do
+ -> { Encoding.find(:"utf-8") }.should.raise(TypeError)
+ end
- it "returns the passed Encoding object" do
- Encoding.find(Encoding::UTF_8).should == Encoding::UTF_8
- end
+ it "returns the passed Encoding object" do
+ Encoding.find(Encoding::UTF_8).should == Encoding::UTF_8
+ end
- it "accepts encoding names as Strings" do
- Encoding.list.each do |enc|
- Encoding.find(enc.name).should == enc
- end
+ it "accepts encoding names as Strings" do
+ Encoding.list.each do |enc|
+ Encoding.find(enc.name).should == enc
end
+ end
- it "accepts any object as encoding name, if it responds to #to_str" do
- obj = Class.new do
- attr_writer :encoding_name
- def to_str; @encoding_name; end
- end.new
+ it "accepts any object as encoding name, if it responds to #to_str" do
+ obj = Class.new do
+ attr_writer :encoding_name
+ def to_str; @encoding_name; end
+ end.new
- Encoding.list.each do |enc|
- obj.encoding_name = enc.name
- Encoding.find(obj).should == enc
- end
+ Encoding.list.each do |enc|
+ obj.encoding_name = enc.name
+ Encoding.find(obj).should == enc
end
+ end
- it "is case insensitive" do
- @encodings.each do |enc|
- Encoding.find(enc.upcase).should == Encoding.find(enc)
- end
+ it "is case insensitive" do
+ @encodings.each do |enc|
+ Encoding.find(enc.upcase).should == Encoding.find(enc)
end
+ end
- it "raises an ArgumentError if the given encoding does not exist" do
- lambda { Encoding.find('dh2dh278d') }.should raise_error(ArgumentError)
- end
+ it "raises an ArgumentError if the given encoding does not exist" do
+ -> { Encoding.find('dh2dh278d') }.should.raise(ArgumentError, 'unknown encoding name - dh2dh278d')
+ end
- # Not sure how to do a better test, since locale depends on weird platform-specific stuff
- it "supports the 'locale' encoding alias" do
- enc = Encoding.find('locale')
- enc.should_not == nil
- end
+ # Not sure how to do a better test, since locale depends on weird platform-specific stuff
+ it "supports the 'locale' encoding alias" do
+ enc = Encoding.find('locale')
+ enc.should_not == nil
+ end
- it "returns default external encoding for the 'external' encoding alias" do
- enc = Encoding.find('external')
- enc.should == Encoding.default_external
- end
+ it "returns default external encoding for the 'external' encoding alias" do
+ enc = Encoding.find('external')
+ enc.should == Encoding.default_external
+ end
- it "returns default internal encoding for the 'internal' encoding alias" do
- enc = Encoding.find('internal')
- enc.should == Encoding.default_internal
- end
+ it "returns default internal encoding for the 'internal' encoding alias" do
+ enc = Encoding.find('internal')
+ enc.should == Encoding.default_internal
+ end
- platform_is_not :windows do
- it "uses default external encoding for the 'filesystem' encoding alias" do
- enc = Encoding.find('filesystem')
- enc.should == Encoding.default_external
- end
+ platform_is_not :windows do
+ it "uses default external encoding for the 'filesystem' encoding alias" do
+ enc = Encoding.find('filesystem')
+ enc.should == Encoding.default_external
end
+ end
- platform_is :windows do
- it "needs to be reviewed for spec completeness"
- end
+ platform_is :windows do
+ it "needs to be reviewed for spec completeness"
end
end
diff --git a/spec/ruby/core/encoding/fixtures/classes.rb b/spec/ruby/core/encoding/fixtures/classes.rb
index 12e9a4f348..943865e8d8 100644
--- a/spec/ruby/core/encoding/fixtures/classes.rb
+++ b/spec/ruby/core/encoding/fixtures/classes.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
module EncodingSpecs
class UndefinedConversionError
def self.exception
diff --git a/spec/ruby/core/encoding/inspect_spec.rb b/spec/ruby/core/encoding/inspect_spec.rb
index 771232e433..ab7f8cf9fc 100644
--- a/spec/ruby/core/encoding/inspect_spec.rb
+++ b/spec/ruby/core/encoding/inspect_spec.rb
@@ -1,21 +1,33 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
-with_feature :encoding do
- describe "Encoding#inspect" do
- it "returns a String" do
- Encoding::UTF_8.inspect.should be_an_instance_of(String)
- end
+describe "Encoding#inspect" do
+ it "returns a String" do
+ Encoding::UTF_8.inspect.should.instance_of?(String)
+ end
+ ruby_version_is ""..."3.4" do
it "returns #<Encoding:name> for a non-dummy encoding named 'name'" do
Encoding.list.to_a.reject {|e| e.dummy? }.each do |enc|
enc.inspect.should =~ /#<Encoding:#{enc.name}>/
end
end
+ end
- it "returns #<Encoding:name (dummy)> for a dummy encoding named 'name'" do
- Encoding.list.to_a.select {|e| e.dummy? }.each do |enc|
- enc.inspect.should =~ /#<Encoding:#{enc.name} \(dummy\)>/
+ ruby_version_is "3.4" do
+ it "returns #<Encoding:name> for a non-dummy encoding named 'name'" do
+ Encoding.list.to_a.reject {|e| e.dummy? }.each do |enc|
+ if enc.name == "ASCII-8BIT"
+ enc.inspect.should == "#<Encoding:BINARY (ASCII-8BIT)>"
+ else
+ enc.inspect.should =~ /#<Encoding:#{enc.name}>/
+ end
end
end
end
+
+ it "returns #<Encoding:name (dummy)> for a dummy encoding named 'name'" do
+ Encoding.list.to_a.select {|e| e.dummy? }.each do |enc|
+ enc.inspect.should =~ /#<Encoding:#{enc.name} \(dummy\)>/
+ end
+ end
end
diff --git a/spec/ruby/core/encoding/invalid_byte_sequence_error/destination_encoding_name_spec.rb b/spec/ruby/core/encoding/invalid_byte_sequence_error/destination_encoding_name_spec.rb
index 790dd18655..7d3cc77c0b 100644
--- a/spec/ruby/core/encoding/invalid_byte_sequence_error/destination_encoding_name_spec.rb
+++ b/spec/ruby/core/encoding/invalid_byte_sequence_error/destination_encoding_name_spec.rb
@@ -1,20 +1,19 @@
-require File.expand_path('../../fixtures/classes', __FILE__)
+require_relative "../../../spec_helper"
+require_relative '../fixtures/classes'
-with_feature :encoding do
- describe "Encoding::InvalidByteSequenceError#destination_encoding_name" do
- before :each do
- @exception, = EncodingSpecs::InvalidByteSequenceError.exception
- @exception2, = EncodingSpecs::InvalidByteSequenceErrorIndirect.exception
- end
+describe "Encoding::InvalidByteSequenceError#destination_encoding_name" do
+ before :each do
+ @exception, = EncodingSpecs::InvalidByteSequenceError.exception
+ @exception2, = EncodingSpecs::InvalidByteSequenceErrorIndirect.exception
+ end
- it "returns a String" do
- @exception.destination_encoding_name.should be_an_instance_of(String)
- @exception2.destination_encoding_name.should be_an_instance_of(String)
- end
+ it "returns a String" do
+ @exception.destination_encoding_name.should.instance_of?(String)
+ @exception2.destination_encoding_name.should.instance_of?(String)
+ end
- it "is equal to the destination encoding name of the object that raised it" do
- @exception.destination_encoding_name.should == "ISO-8859-1"
- @exception2.destination_encoding_name.should == "UTF-8"
- end
+ it "is equal to the destination encoding name of the object that raised it" do
+ @exception.destination_encoding_name.should == "ISO-8859-1"
+ @exception2.destination_encoding_name.should == "UTF-8"
end
end
diff --git a/spec/ruby/core/encoding/invalid_byte_sequence_error/destination_encoding_spec.rb b/spec/ruby/core/encoding/invalid_byte_sequence_error/destination_encoding_spec.rb
index 981a62424e..264c409b1c 100644
--- a/spec/ruby/core/encoding/invalid_byte_sequence_error/destination_encoding_spec.rb
+++ b/spec/ruby/core/encoding/invalid_byte_sequence_error/destination_encoding_spec.rb
@@ -1,20 +1,19 @@
-require File.expand_path('../../fixtures/classes', __FILE__)
+require_relative "../../../spec_helper"
+require_relative '../fixtures/classes'
-with_feature :encoding do
- describe "Encoding::InvalidByteSequenceError#destination_encoding" do
- before :each do
- @exception, = EncodingSpecs::InvalidByteSequenceError.exception
- @exception2, = EncodingSpecs::InvalidByteSequenceErrorIndirect.exception
- end
+describe "Encoding::InvalidByteSequenceError#destination_encoding" do
+ before :each do
+ @exception, = EncodingSpecs::InvalidByteSequenceError.exception
+ @exception2, = EncodingSpecs::InvalidByteSequenceErrorIndirect.exception
+ end
- it "returns an Encoding object" do
- @exception.destination_encoding.should be_an_instance_of(Encoding)
- @exception2.destination_encoding.should be_an_instance_of(Encoding)
- end
+ it "returns an Encoding object" do
+ @exception.destination_encoding.should.instance_of?(Encoding)
+ @exception2.destination_encoding.should.instance_of?(Encoding)
+ end
- it "is equal to the destination encoding of the object that raised it" do
- @exception.destination_encoding.should == Encoding::ISO_8859_1
- @exception2.destination_encoding.should == Encoding::UTF_8
- end
+ it "is equal to the destination encoding of the object that raised it" do
+ @exception.destination_encoding.should == Encoding::ISO_8859_1
+ @exception2.destination_encoding.should == Encoding::UTF_8
end
end
diff --git a/spec/ruby/core/encoding/invalid_byte_sequence_error/error_bytes_spec.rb b/spec/ruby/core/encoding/invalid_byte_sequence_error/error_bytes_spec.rb
index 633ad2e1f7..40a9a35caf 100644
--- a/spec/ruby/core/encoding/invalid_byte_sequence_error/error_bytes_spec.rb
+++ b/spec/ruby/core/encoding/invalid_byte_sequence_error/error_bytes_spec.rb
@@ -1,32 +1,31 @@
-# -*- encoding: binary -*-
-require File.expand_path('../../fixtures/classes', __FILE__)
+# encoding: binary
+require_relative "../../../spec_helper"
+require_relative '../fixtures/classes'
-with_feature :encoding do
- describe "Encoding::InvalidByteSequenceError#error_bytes" do
- before :each do
- @exception, @errinfo = EncodingSpecs::InvalidByteSequenceError.exception
- @exception2, @errinfo2 = EncodingSpecs::InvalidByteSequenceErrorIndirect.exception
- end
+describe "Encoding::InvalidByteSequenceError#error_bytes" do
+ before :each do
+ @exception, @errinfo = EncodingSpecs::InvalidByteSequenceError.exception
+ @exception2, @errinfo2 = EncodingSpecs::InvalidByteSequenceErrorIndirect.exception
+ end
- it "returns a String" do
- @exception.error_bytes.should be_an_instance_of(String)
- @exception2.error_bytes.should be_an_instance_of(String)
- end
+ it "returns a String" do
+ @exception.error_bytes.should.instance_of?(String)
+ @exception2.error_bytes.should.instance_of?(String)
+ end
- it "returns the bytes that caused the exception" do
- @exception.error_bytes.size.should == 1
- @exception.error_bytes.should == "\xF1"
- @exception.error_bytes.should == @errinfo[-2]
+ it "returns the bytes that caused the exception" do
+ @exception.error_bytes.size.should == 1
+ @exception.error_bytes.should == "\xF1"
+ @exception.error_bytes.should == @errinfo[-2]
- @exception2.error_bytes.size.should == 1
- @exception2.error_bytes.should == "\xA1"
- @exception2.error_bytes.should == @errinfo2[-2]
- end
+ @exception2.error_bytes.size.should == 1
+ @exception2.error_bytes.should == "\xA1"
+ @exception2.error_bytes.should == @errinfo2[-2]
+ end
- it "uses ASCII-8BIT as the encoding" do
- @exception.error_bytes.encoding.should == Encoding::ASCII_8BIT
+ it "uses BINARY as the encoding" do
+ @exception.error_bytes.encoding.should == Encoding::BINARY
- @exception2.error_bytes.encoding.should == Encoding::ASCII_8BIT
- end
+ @exception2.error_bytes.encoding.should == Encoding::BINARY
end
end
diff --git a/spec/ruby/core/encoding/invalid_byte_sequence_error/incomplete_input_spec.rb b/spec/ruby/core/encoding/invalid_byte_sequence_error/incomplete_input_spec.rb
index c79a6663e2..143db7b6da 100644
--- a/spec/ruby/core/encoding/invalid_byte_sequence_error/incomplete_input_spec.rb
+++ b/spec/ruby/core/encoding/invalid_byte_sequence_error/incomplete_input_spec.rb
@@ -1,31 +1,28 @@
-# -*- encoding: binary -*-
-require File.expand_path('../../../../spec_helper', __FILE__)
+# encoding: binary
+require_relative '../../../spec_helper'
-with_feature :encoding do
- describe "Encoding::InvalidByteSequenceError#incomplete_input?" do
-
- it "returns nil by default" do
- Encoding::InvalidByteSequenceError.new.incomplete_input?.should be_nil
- end
+describe "Encoding::InvalidByteSequenceError#incomplete_input?" do
+ it "returns nil by default" do
+ Encoding::InvalidByteSequenceError.new.incomplete_input?.should == nil
+ end
- it "returns true if #primitive_convert returned :incomplete_input for the same data" do
- ec = Encoding::Converter.new("EUC-JP", "ISO-8859-1")
- ec.primitive_convert("\xA1",'').should == :incomplete_input
- begin
- ec.convert("\xA1")
- rescue Encoding::InvalidByteSequenceError => e
- e.incomplete_input?.should be_true
- end
+ it "returns true if #primitive_convert returned :incomplete_input for the same data" do
+ ec = Encoding::Converter.new("EUC-JP", "ISO-8859-1")
+ ec.primitive_convert(+"\xA1", +'').should == :incomplete_input
+ begin
+ ec.convert("\xA1")
+ rescue Encoding::InvalidByteSequenceError => e
+ e.incomplete_input?.should == true
end
+ end
- it "returns false if #primitive_convert returned :invalid_byte_sequence for the same data" do
- ec = Encoding::Converter.new("ascii", "utf-8")
- ec.primitive_convert("\xfffffffff",'').should == :invalid_byte_sequence
- begin
- ec.convert("\xfffffffff")
- rescue Encoding::InvalidByteSequenceError => e
- e.incomplete_input?.should be_false
- end
+ it "returns false if #primitive_convert returned :invalid_byte_sequence for the same data" do
+ ec = Encoding::Converter.new("ascii", "utf-8")
+ ec.primitive_convert(+"\xfffffffff", +'').should == :invalid_byte_sequence
+ begin
+ ec.convert("\xfffffffff")
+ rescue Encoding::InvalidByteSequenceError => e
+ e.incomplete_input?.should == false
end
end
end
diff --git a/spec/ruby/core/encoding/invalid_byte_sequence_error/readagain_bytes_spec.rb b/spec/ruby/core/encoding/invalid_byte_sequence_error/readagain_bytes_spec.rb
index 31408a4320..e4fc81aac6 100644
--- a/spec/ruby/core/encoding/invalid_byte_sequence_error/readagain_bytes_spec.rb
+++ b/spec/ruby/core/encoding/invalid_byte_sequence_error/readagain_bytes_spec.rb
@@ -1,32 +1,31 @@
-# -*- encoding: binary -*-
-require File.expand_path('../../fixtures/classes', __FILE__)
+# encoding: binary
+require_relative "../../../spec_helper"
+require_relative '../fixtures/classes'
-with_feature :encoding do
- describe "Encoding::InvalidByteSequenceError#readagain_bytes" do
- before :each do
- @exception, @errinfo = EncodingSpecs::InvalidByteSequenceError.exception
- @exception2, @errinfo2 = EncodingSpecs::InvalidByteSequenceErrorIndirect.exception
- end
+describe "Encoding::InvalidByteSequenceError#readagain_bytes" do
+ before :each do
+ @exception, @errinfo = EncodingSpecs::InvalidByteSequenceError.exception
+ @exception2, @errinfo2 = EncodingSpecs::InvalidByteSequenceErrorIndirect.exception
+ end
- it "returns a String" do
- @exception.readagain_bytes.should be_an_instance_of(String)
- @exception2.readagain_bytes.should be_an_instance_of(String)
- end
+ it "returns a String" do
+ @exception.readagain_bytes.should.instance_of?(String)
+ @exception2.readagain_bytes.should.instance_of?(String)
+ end
- it "returns the bytes to be read again" do
- @exception.readagain_bytes.size.should == 1
- @exception.readagain_bytes.should == "a".force_encoding('binary')
- @exception.readagain_bytes.should == @errinfo[-1]
+ it "returns the bytes to be read again" do
+ @exception.readagain_bytes.size.should == 1
+ @exception.readagain_bytes.should == "a".dup.force_encoding('binary')
+ @exception.readagain_bytes.should == @errinfo[-1]
- @exception2.readagain_bytes.size.should == 1
- @exception2.readagain_bytes.should == "\xFF".force_encoding('binary')
- @exception2.readagain_bytes.should == @errinfo2[-1]
- end
+ @exception2.readagain_bytes.size.should == 1
+ @exception2.readagain_bytes.should == "\xFF".dup.force_encoding('binary')
+ @exception2.readagain_bytes.should == @errinfo2[-1]
+ end
- it "uses ASCII-8BIT as the encoding" do
- @exception.readagain_bytes.encoding.should == Encoding::ASCII_8BIT
+ it "uses BINARY as the encoding" do
+ @exception.readagain_bytes.encoding.should == Encoding::BINARY
- @exception2.readagain_bytes.encoding.should == Encoding::ASCII_8BIT
- end
+ @exception2.readagain_bytes.encoding.should == Encoding::BINARY
end
end
diff --git a/spec/ruby/core/encoding/invalid_byte_sequence_error/source_encoding_name_spec.rb b/spec/ruby/core/encoding/invalid_byte_sequence_error/source_encoding_name_spec.rb
index 428b292c68..b00e1ad4e8 100644
--- a/spec/ruby/core/encoding/invalid_byte_sequence_error/source_encoding_name_spec.rb
+++ b/spec/ruby/core/encoding/invalid_byte_sequence_error/source_encoding_name_spec.rb
@@ -1,30 +1,29 @@
-require File.expand_path('../../fixtures/classes', __FILE__)
+require_relative "../../../spec_helper"
+require_relative '../fixtures/classes'
-with_feature :encoding do
- describe "Encoding::UndefinedConversionError#source_encoding_name" do
- before :each do
- @exception, = EncodingSpecs::UndefinedConversionError.exception
- @exception2, = EncodingSpecs::UndefinedConversionErrorIndirect.exception
- end
+describe "Encoding::UndefinedConversionError#source_encoding_name" do
+ before :each do
+ @exception, = EncodingSpecs::UndefinedConversionError.exception
+ @exception2, = EncodingSpecs::UndefinedConversionErrorIndirect.exception
+ end
- it "returns a String" do
- @exception.source_encoding_name.should be_an_instance_of(String)
- end
+ it "returns a String" do
+ @exception.source_encoding_name.should.instance_of?(String)
+ end
- it "is equal to the source encoding name of the object that raised it" do
- @exception.source_encoding_name.should == "UTF-8"
- end
+ it "is equal to the source encoding name of the object that raised it" do
+ @exception.source_encoding_name.should == "UTF-8"
+ end
- # The source encoding specified in the Encoding::Converter constructor may
- # differ from the source encoding returned here. What seems to happen is
- # that when transcoding along a path with multiple pairs of encodings, the
- # last one encountered when the error occurred is returned. So in this
- # case, the conversion path is ISO-8859-1 -> UTF-8 -> EUC-JP. The
- # conversion from ISO-8859-1 -> UTF-8 succeeded, but the conversion from
- # UTF-8 to EUC-JP failed. IOW, it failed when the source encoding was
- # UTF-8, so UTF-8 is regarded as the source encoding.
- it "is equal to the source encoding at the stage of the conversion path where the error occurred" do
- @exception2.source_encoding_name.should == 'UTF-8'
- end
+ # The source encoding specified in the Encoding::Converter constructor may
+ # differ from the source encoding returned here. What seems to happen is
+ # that when transcoding along a path with multiple pairs of encodings, the
+ # last one encountered when the error occurred is returned. So in this
+ # case, the conversion path is ISO-8859-1 -> UTF-8 -> EUC-JP. The
+ # conversion from ISO-8859-1 -> UTF-8 succeeded, but the conversion from
+ # UTF-8 to EUC-JP failed. IOW, it failed when the source encoding was
+ # UTF-8, so UTF-8 is regarded as the source encoding.
+ it "is equal to the source encoding at the stage of the conversion path where the error occurred" do
+ @exception2.source_encoding_name.should == 'UTF-8'
end
end
diff --git a/spec/ruby/core/encoding/invalid_byte_sequence_error/source_encoding_spec.rb b/spec/ruby/core/encoding/invalid_byte_sequence_error/source_encoding_spec.rb
index 09379acc5d..32ad25dbb5 100644
--- a/spec/ruby/core/encoding/invalid_byte_sequence_error/source_encoding_spec.rb
+++ b/spec/ruby/core/encoding/invalid_byte_sequence_error/source_encoding_spec.rb
@@ -1,35 +1,34 @@
-require File.expand_path('../../fixtures/classes', __FILE__)
+require_relative "../../../spec_helper"
+require_relative '../fixtures/classes'
-with_feature :encoding do
- describe "Encoding::InvalidByteSequenceError#source_encoding" do
- before :each do
- @exception, = EncodingSpecs::InvalidByteSequenceError.exception
- @exception2, = EncodingSpecs::InvalidByteSequenceErrorIndirect.exception
- end
+describe "Encoding::InvalidByteSequenceError#source_encoding" do
+ before :each do
+ @exception, = EncodingSpecs::InvalidByteSequenceError.exception
+ @exception2, = EncodingSpecs::InvalidByteSequenceErrorIndirect.exception
+ end
- it "returns an Encoding object" do
- @exception.source_encoding.should be_an_instance_of(Encoding)
- @exception2.source_encoding.should be_an_instance_of(Encoding)
- end
+ it "returns an Encoding object" do
+ @exception.source_encoding.should.instance_of?(Encoding)
+ @exception2.source_encoding.should.instance_of?(Encoding)
+ end
- it "is equal to the source encoding of the object that raised it" do
- @exception.source_encoding.should == Encoding::UTF_8
- end
+ it "is equal to the source encoding of the object that raised it" do
+ @exception.source_encoding.should == Encoding::UTF_8
+ end
- # The source encoding specified in the Encoding::Converter constructor may
- # differ from the source encoding returned here. What seems to happen is
- # that when transcoding along a path with multiple pairs of encodings, the
- # last one encountered when the error occurred is returned. So in this
- # case, the conversion path is EUC-JP -> UTF-8 -> ISO-8859-1. The
- # conversions failed with the first pair of encodings (i.e. transcoding
- # from EUC-JP to UTF-8, so UTF-8 is regarded as the source encoding; if
- # the error had occurred when converting from UTF-8 to ISO-8859-1, UTF-8
- # would have been the source encoding.
+ # The source encoding specified in the Encoding::Converter constructor may
+ # differ from the source encoding returned here. What seems to happen is
+ # that when transcoding along a path with multiple pairs of encodings, the
+ # last one encountered when the error occurred is returned. So in this
+ # case, the conversion path is EUC-JP -> UTF-8 -> ISO-8859-1. The
+ # conversions failed with the first pair of encodings (i.e. transcoding
+ # from EUC-JP to UTF-8, so UTF-8 is regarded as the source encoding; if
+ # the error had occurred when converting from UTF-8 to ISO-8859-1, UTF-8
+ # would have been the source encoding.
- # FIXME: Derive example where the failure occurs at the UTF-8 ->
- # ISO-8859-1 case so as to better illustrate the issue
- it "is equal to the source encoding at the stage of the conversion path where the error occurred" do
- @exception2.source_encoding.should == Encoding::EUC_JP
- end
+ # FIXME: Derive example where the failure occurs at the UTF-8 ->
+ # ISO-8859-1 case so as to better illustrate the issue
+ it "is equal to the source encoding at the stage of the conversion path where the error occurred" do
+ @exception2.source_encoding.should == Encoding::EUC_JP
end
end
diff --git a/spec/ruby/core/encoding/list_spec.rb b/spec/ruby/core/encoding/list_spec.rb
index 18488607e5..9fe336c608 100644
--- a/spec/ruby/core/encoding/list_spec.rb
+++ b/spec/ruby/core/encoding/list_spec.rb
@@ -1,43 +1,49 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
-with_feature :encoding do
- describe "Encoding.list" do
- it "returns an Array" do
- Encoding.list.should be_an_instance_of(Array)
- end
+describe "Encoding.list" do
+ it "returns an Array" do
+ Encoding.list.should.instance_of?(Array)
+ end
- it "returns an Array of Encoding objects" do
- Encoding.list.each do |enc|
- enc.should be_an_instance_of(Encoding)
- end
+ it "returns an Array of Encoding objects" do
+ Encoding.list.each do |enc|
+ enc.should.instance_of?(Encoding)
end
+ end
- it "returns each encoding only once" do
- orig = Encoding.list.map {|e| e.name}
- orig.should == orig.uniq
- end
+ it "returns each encoding only once" do
+ orig = Encoding.list.map { |e| e.name }
+ orig.should == orig.uniq
+ end
- it "includes the default external encoding" do
- Encoding.list.include?(Encoding.default_external).should be_true
- end
+ it "includes the default external encoding" do
+ Encoding.list.include?(Encoding.default_external).should == true
+ end
- it "does not include any alias names" do
- Encoding.aliases.keys.each do |enc_alias|
- Encoding.list.include?(enc_alias).should be_false
- end
+ it "does not include any alias names" do
+ Encoding.aliases.keys.each do |enc_alias|
+ Encoding.list.include?(enc_alias).should == false
end
+ end
- it "includes all aliased encodings" do
- Encoding.aliases.values.each do |enc_alias|
- Encoding.list.include?(Encoding.find(enc_alias)).should be_true
- end
+ it "includes all aliased encodings" do
+ Encoding.aliases.values.each do |enc_alias|
+ Encoding.list.include?(Encoding.find(enc_alias)).should == true
end
+ end
- it "includes dummy encodings" do
- Encoding.list.select {|e| e.dummy?}.should_not == []
- end
+ it "includes dummy encodings" do
+ Encoding.list.select { |e| e.dummy? }.should_not == []
+ end
- # TODO: Find example that illustrates this
- it "updates the list when #find is used to load a new encoding"
+ it 'includes UTF-8 encoding' do
+ Encoding.list.should.include?(Encoding::UTF_8)
end
+
+ it 'includes CESU-8 encoding' do
+ Encoding.list.should.include?(Encoding::CESU_8)
+ end
+
+ # TODO: Find example that illustrates this
+ it "updates the list when #find is used to load a new encoding"
end
diff --git a/spec/ruby/core/encoding/locale_charmap_spec.rb b/spec/ruby/core/encoding/locale_charmap_spec.rb
index 12b93c2562..0d77bf227b 100644
--- a/spec/ruby/core/encoding/locale_charmap_spec.rb
+++ b/spec/ruby/core/encoding/locale_charmap_spec.rb
@@ -1,46 +1,55 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
-with_feature :encoding do
- describe "Encoding.locale_charmap" do
- it "returns a String" do
- Encoding.locale_charmap.should be_an_instance_of(String)
+describe "Encoding.locale_charmap" do
+ it "returns a String" do
+ Encoding.locale_charmap.should.instance_of?(String)
+ end
+
+ describe "when setting LC_ALL=C" do
+ before :each do
+ @old_lc_all = ENV['LC_ALL']
+ end
+
+ after :each do
+ ENV['LC_ALL'] = @old_lc_all
end
# FIXME: Get this working on Windows
platform_is :linux do
- it "returns a value based on the LC_ALL environment variable" do
- old_lc_all = ENV['LC_ALL']
- ENV['LC_ALL'] = 'C'
- ruby_exe("print Encoding.locale_charmap").should == 'ANSI_X3.4-1968'
- ENV['LC_ALL'] = old_lc_all
+ platform_is_not :android do
+ it "returns a value based on the LC_ALL environment variable" do
+ ENV['LC_ALL'] = 'C'
+ ruby_exe("print Encoding.locale_charmap").should == 'ANSI_X3.4-1968'
+ end
end
end
- platform_is :freebsd, :darwin do
+ platform_is :freebsd, :openbsd, :darwin do
it "returns a value based on the LC_ALL environment variable" do
- old_lc_all = ENV['LC_ALL']
ENV['LC_ALL'] = 'C'
ruby_exe("print Encoding.locale_charmap").should == 'US-ASCII'
- ENV['LC_ALL'] = old_lc_all
end
end
- platform_is :netbsd, :openbsd do
+ platform_is :netbsd do
it "returns a value based on the LC_ALL environment variable" do
- old_lc_all = ENV['LC_ALL']
ENV['LC_ALL'] = 'C'
ruby_exe("print Encoding.locale_charmap").should == '646'
- ENV['LC_ALL'] = old_lc_all
+ end
+ end
+
+ platform_is :android do
+ it "always returns UTF-8" do
+ ENV['LC_ALL'] = 'C'
+ ruby_exe("print Encoding.locale_charmap").should == 'UTF-8'
end
end
platform_is :bsd, :darwin, :linux do
it "is unaffected by assigning to ENV['LC_ALL'] in the same process" do
old_charmap = Encoding.locale_charmap
- old_lc_all = ENV['LC_ALL']
ENV['LC_ALL'] = 'C'
Encoding.locale_charmap.should == old_charmap
- ENV['LC_ALL'] = old_lc_all
end
end
end
diff --git a/spec/ruby/core/encoding/name_list_spec.rb b/spec/ruby/core/encoding/name_list_spec.rb
index c06ec410ec..1ba8d383bc 100644
--- a/spec/ruby/core/encoding/name_list_spec.rb
+++ b/spec/ruby/core/encoding/name_list_spec.rb
@@ -1,25 +1,23 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
-with_feature :encoding do
- describe "Encoding.name_list" do
- it "returns an Array" do
- Encoding.name_list.should be_an_instance_of(Array)
- end
+describe "Encoding.name_list" do
+ it "returns an Array" do
+ Encoding.name_list.should.instance_of?(Array)
+ end
- it "returns encoding names as Strings" do
- Encoding.name_list.each {|e| e.should be_an_instance_of(String) }
- end
+ it "returns encoding names as Strings" do
+ Encoding.name_list.each {|e| e.should.instance_of?(String) }
+ end
- it "includes all aliases" do
- Encoding.aliases.keys.each do |enc_alias|
- Encoding.name_list.include?(enc_alias).should be_true
- end
+ it "includes all aliases" do
+ Encoding.aliases.keys.each do |enc_alias|
+ Encoding.name_list.include?(enc_alias).should == true
end
+ end
- it "includes all non-dummy encodings" do
- Encoding.list.each do |enc|
- Encoding.name_list.include?(enc.name).should be_true
- end
+ it "includes all non-dummy encodings" do
+ Encoding.list.each do |enc|
+ Encoding.name_list.include?(enc.name).should == true
end
end
end
diff --git a/spec/ruby/core/encoding/name_spec.rb b/spec/ruby/core/encoding/name_spec.rb
index 4ea89a563a..1d625c9379 100644
--- a/spec/ruby/core/encoding/name_spec.rb
+++ b/spec/ruby/core/encoding/name_spec.rb
@@ -1,7 +1,15 @@
-require File.expand_path('../shared/name', __FILE__)
+require_relative "../../spec_helper"
-with_feature :encoding do
- describe "Encoding#name" do
- it_behaves_like(:encoding_name, :name)
+describe "Encoding#name" do
+ it "returns a String" do
+ Encoding.list.each do |e|
+ e.name.should.instance_of?(String)
+ end
+ end
+
+ it "uniquely identifies an encoding" do
+ Encoding.list.each do |e|
+ e.should == Encoding.find(e.name)
+ end
end
end
diff --git a/spec/ruby/core/encoding/names_spec.rb b/spec/ruby/core/encoding/names_spec.rb
index 3cd741e513..e6bcbf474a 100644
--- a/spec/ruby/core/encoding/names_spec.rb
+++ b/spec/ruby/core/encoding/names_spec.rb
@@ -1,37 +1,35 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
-with_feature :encoding do
- describe "Encoding#names" do
- it "returns an Array" do
- Encoding.name_list.each do |name|
- e = Encoding.find(name) or next
- e.names.should be_an_instance_of(Array)
- end
+describe "Encoding#names" do
+ it "returns an Array" do
+ Encoding.name_list.each do |name|
+ e = Encoding.find(name) or next
+ e.names.should.instance_of?(Array)
end
+ end
- it "returns names as Strings" do
- Encoding.name_list.each do |name|
- e = Encoding.find(name) or next
- e.names.each do |this_name|
- this_name.should be_an_instance_of(String)
- end
+ it "returns names as Strings" do
+ Encoding.name_list.each do |name|
+ e = Encoding.find(name) or next
+ e.names.each do |this_name|
+ this_name.should.instance_of?(String)
end
end
+ end
- it "returns #name as the first value" do
- Encoding.name_list.each do |name|
- e = Encoding.find(name) or next
- e.names.first.should == e.name
- end
+ it "returns #name as the first value" do
+ Encoding.name_list.each do |name|
+ e = Encoding.find(name) or next
+ e.names.first.should == e.name
end
+ end
- it "includes any aliases the encoding has" do
- Encoding.name_list.each do |name|
- e = Encoding.find(name) or next
- aliases = Encoding.aliases.select{|a,n| n == name}.keys
- names = e.names
- aliases.each {|a| names.include?(a).should be_true}
- end
+ it "includes any aliases the encoding has" do
+ Encoding.name_list.each do |name|
+ e = Encoding.find(name) or next
+ aliases = Encoding.aliases.select{|a,n| n == name}.keys
+ names = e.names
+ aliases.each {|a| names.include?(a).should == true}
end
end
end
diff --git a/spec/ruby/core/encoding/replicate_spec.rb b/spec/ruby/core/encoding/replicate_spec.rb
index 5d007dd827..9fe0ba8747 100644
--- a/spec/ruby/core/encoding/replicate_spec.rb
+++ b/spec/ruby/core/encoding/replicate_spec.rb
@@ -1,48 +1,8 @@
-# -*- encoding: binary -*-
-require File.expand_path('../../../spec_helper', __FILE__)
+# encoding: binary
+require_relative '../../spec_helper'
-with_feature :encoding do
- describe "Encoding#replicate" do
- before :all do
- @i = 0
- end
-
- before :each do
- @i += 1
- @prefix = "RS#{@i}"
- end
-
- it "returns a replica of ASCII" do
- name = @prefix + '-ASCII'
- e = Encoding::ASCII.replicate(name)
- e.name.should == name
- "a".force_encoding(e).valid_encoding?.should be_true
- "\x80".force_encoding(e).valid_encoding?.should be_false
- end
-
- it "returns a replica of UTF-8" do
- name = @prefix + 'UTF-8'
- e = Encoding::UTF_8.replicate(name)
- e.name.should == name
- "a".force_encoding(e).valid_encoding?.should be_true
- "\u3042".force_encoding(e).valid_encoding?.should be_true
- "\x80".force_encoding(e).valid_encoding?.should be_false
- end
-
- it "returns a replica of UTF-16BE" do
- name = @prefix + 'UTF-16-BE'
- e = Encoding::UTF_16BE.replicate(name)
- e.name.should == name
- "a".force_encoding(e).valid_encoding?.should be_false
- "\x30\x42".force_encoding(e).valid_encoding?.should be_true
- "\x80".force_encoding(e).valid_encoding?.should be_false
- end
-
- it "returns a replica of ISO-2022-JP" do
- name = @prefix + 'ISO-2022-JP'
- e = Encoding::ISO_2022_JP.replicate(name)
- e.name.should == name
- e.dummy?.should be_true
- end
+describe "Encoding#replicate" do
+ it "has been removed" do
+ Encoding::US_ASCII.should_not.respond_to?(:replicate, true)
end
end
diff --git a/spec/ruby/core/encoding/shared/name.rb b/spec/ruby/core/encoding/shared/name.rb
deleted file mode 100644
index 7f85c46764..0000000000
--- a/spec/ruby/core/encoding/shared/name.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-
-describe :encoding_name, shared: true do
- it "returns a String" do
- Encoding.list.each do |e|
- e.send(@method).should be_an_instance_of(String)
- end
- end
-
- it "uniquely identifies an encoding" do
- Encoding.list.each do |e|
- e.should == Encoding.find(e.send(@method))
- end
- end
-end
diff --git a/spec/ruby/core/encoding/to_s_spec.rb b/spec/ruby/core/encoding/to_s_spec.rb
index ddc57e321e..ee5e3b4abe 100644
--- a/spec/ruby/core/encoding/to_s_spec.rb
+++ b/spec/ruby/core/encoding/to_s_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../shared/name', __FILE__)
+require_relative "../../spec_helper"
-with_feature :encoding do
- describe "Encoding#to_s" do
- it_behaves_like(:encoding_name, :to_s)
+describe "Encoding#to_s" do
+ it "is an alias of Encoding#name" do
+ Encoding.instance_method(:to_s).should == Encoding.instance_method(:name)
end
end
diff --git a/spec/ruby/core/encoding/undefined_conversion_error/destination_encoding_name_spec.rb b/spec/ruby/core/encoding/undefined_conversion_error/destination_encoding_name_spec.rb
index 2f7f33e45e..bc36695ca7 100644
--- a/spec/ruby/core/encoding/undefined_conversion_error/destination_encoding_name_spec.rb
+++ b/spec/ruby/core/encoding/undefined_conversion_error/destination_encoding_name_spec.rb
@@ -1,17 +1,16 @@
-require File.expand_path('../../fixtures/classes', __FILE__)
+require_relative "../../../spec_helper"
+require_relative '../fixtures/classes'
-with_feature :encoding do
- describe "Encoding::UndefinedConversionError#destination_encoding_name" do
- before :each do
- @exception = EncodingSpecs::UndefinedConversionError.exception
- end
+describe "Encoding::UndefinedConversionError#destination_encoding_name" do
+ before :each do
+ @exception = EncodingSpecs::UndefinedConversionError.exception
+ end
- it "returns a String" do
- @exception.destination_encoding_name.should be_an_instance_of(String)
- end
+ it "returns a String" do
+ @exception.destination_encoding_name.should.instance_of?(String)
+ end
- it "is equal to the destination encoding name of the object that raised it" do
- @exception.destination_encoding_name.should == "US-ASCII"
- end
+ it "is equal to the destination encoding name of the object that raised it" do
+ @exception.destination_encoding_name.should == "US-ASCII"
end
end
diff --git a/spec/ruby/core/encoding/undefined_conversion_error/destination_encoding_spec.rb b/spec/ruby/core/encoding/undefined_conversion_error/destination_encoding_spec.rb
index 6d4f42c0d8..c0fcf8de58 100644
--- a/spec/ruby/core/encoding/undefined_conversion_error/destination_encoding_spec.rb
+++ b/spec/ruby/core/encoding/undefined_conversion_error/destination_encoding_spec.rb
@@ -1,17 +1,16 @@
-require File.expand_path('../../fixtures/classes', __FILE__)
+require_relative "../../../spec_helper"
+require_relative '../fixtures/classes'
-with_feature :encoding do
- describe "Encoding::UndefinedConversionError#destination_encoding" do
- before :each do
- @exception = EncodingSpecs::UndefinedConversionError.exception
- end
+describe "Encoding::UndefinedConversionError#destination_encoding" do
+ before :each do
+ @exception = EncodingSpecs::UndefinedConversionError.exception
+ end
- it "returns an Encoding object" do
- @exception.destination_encoding.should be_an_instance_of(Encoding)
- end
+ it "returns an Encoding object" do
+ @exception.destination_encoding.should.instance_of?(Encoding)
+ end
- it "is equal to the destination encoding of the object that raised it" do
- @exception.destination_encoding.should == Encoding::US_ASCII
- end
+ it "is equal to the destination encoding of the object that raised it" do
+ @exception.destination_encoding.should == Encoding::US_ASCII
end
end
diff --git a/spec/ruby/core/encoding/undefined_conversion_error/error_char_spec.rb b/spec/ruby/core/encoding/undefined_conversion_error/error_char_spec.rb
index 7f538a60d6..333acf5ee6 100644
--- a/spec/ruby/core/encoding/undefined_conversion_error/error_char_spec.rb
+++ b/spec/ruby/core/encoding/undefined_conversion_error/error_char_spec.rb
@@ -1,29 +1,28 @@
-require File.expand_path('../../fixtures/classes', __FILE__)
+require_relative "../../../spec_helper"
+require_relative '../fixtures/classes'
-with_feature :encoding do
- describe "Encoding::UndefinedConversionError#error_char" do
- before :each do
- @exception = EncodingSpecs::UndefinedConversionError.exception
- @exception2 = EncodingSpecs::UndefinedConversionErrorIndirect.exception
- end
+describe "Encoding::UndefinedConversionError#error_char" do
+ before :each do
+ @exception = EncodingSpecs::UndefinedConversionError.exception
+ @exception2 = EncodingSpecs::UndefinedConversionErrorIndirect.exception
+ end
- it "returns a String" do
- @exception.error_char.should be_an_instance_of(String)
- @exception2.error_char.should be_an_instance_of(String)
- end
+ it "returns a String" do
+ @exception.error_char.should.instance_of?(String)
+ @exception2.error_char.should.instance_of?(String)
+ end
- it "returns the one-character String that caused the exception" do
- @exception.error_char.size.should == 1
- @exception.error_char.should == "\u{8765}"
+ it "returns the one-character String that caused the exception" do
+ @exception.error_char.size.should == 1
+ @exception.error_char.should == "\u{8765}"
- @exception2.error_char.size.should == 1
- @exception2.error_char.should == "\u{A0}"
- end
+ @exception2.error_char.size.should == 1
+ @exception2.error_char.should == "\u{A0}"
+ end
- it "uses the source encoding" do
- @exception.error_char.encoding.should == @exception.source_encoding
+ it "uses the source encoding" do
+ @exception.error_char.encoding.should == @exception.source_encoding
- @exception2.error_char.encoding.should == @exception2.source_encoding
- end
+ @exception2.error_char.encoding.should == @exception2.source_encoding
end
end
diff --git a/spec/ruby/core/encoding/undefined_conversion_error/source_encoding_name_spec.rb b/spec/ruby/core/encoding/undefined_conversion_error/source_encoding_name_spec.rb
index 742184250f..4932a25ed7 100644
--- a/spec/ruby/core/encoding/undefined_conversion_error/source_encoding_name_spec.rb
+++ b/spec/ruby/core/encoding/undefined_conversion_error/source_encoding_name_spec.rb
@@ -1,30 +1,29 @@
-require File.expand_path('../../fixtures/classes', __FILE__)
+require_relative "../../../spec_helper"
+require_relative '../fixtures/classes'
-with_feature :encoding do
- describe "Encoding::UndefinedConversionError#source_encoding_name" do
- before :each do
- @exception = EncodingSpecs::UndefinedConversionError.exception
- @exception2 = EncodingSpecs::UndefinedConversionErrorIndirect.exception
- end
+describe "Encoding::UndefinedConversionError#source_encoding_name" do
+ before :each do
+ @exception = EncodingSpecs::UndefinedConversionError.exception
+ @exception2 = EncodingSpecs::UndefinedConversionErrorIndirect.exception
+ end
- it "returns a String" do
- @exception.source_encoding_name.should be_an_instance_of(String)
- end
+ it "returns a String" do
+ @exception.source_encoding_name.should.instance_of?(String)
+ end
- it "is equal to the source encoding name of the object that raised it" do
- @exception.source_encoding_name.should == "UTF-8"
- end
+ it "is equal to the source encoding name of the object that raised it" do
+ @exception.source_encoding_name.should == "UTF-8"
+ end
- # The source encoding specified in the Encoding::Converter constructor may
- # differ from the source encoding returned here. What seems to happen is
- # that when transcoding along a path with multiple pairs of encodings, the
- # last one encountered when the error occurred is returned. So in this
- # case, the conversion path is ISO-8859-1 -> UTF-8 -> EUC-JP. The
- # conversion from ISO-8859-1 -> UTF-8 succeeded, but the conversion from
- # UTF-8 to EUC-JP failed. IOW, it failed when the source encoding was
- # UTF-8, so UTF-8 is regarded as the source encoding.
- it "is equal to the source encoding at the stage of the conversion path where the error occurred" do
- @exception2.source_encoding_name.should == 'UTF-8'
- end
+ # The source encoding specified in the Encoding::Converter constructor may
+ # differ from the source encoding returned here. What seems to happen is
+ # that when transcoding along a path with multiple pairs of encodings, the
+ # last one encountered when the error occurred is returned. So in this
+ # case, the conversion path is ISO-8859-1 -> UTF-8 -> EUC-JP. The
+ # conversion from ISO-8859-1 -> UTF-8 succeeded, but the conversion from
+ # UTF-8 to EUC-JP failed. IOW, it failed when the source encoding was
+ # UTF-8, so UTF-8 is regarded as the source encoding.
+ it "is equal to the source encoding at the stage of the conversion path where the error occurred" do
+ @exception2.source_encoding_name.should == 'UTF-8'
end
end
diff --git a/spec/ruby/core/encoding/undefined_conversion_error/source_encoding_spec.rb b/spec/ruby/core/encoding/undefined_conversion_error/source_encoding_spec.rb
index 0489ad82bf..cf12020ad2 100644
--- a/spec/ruby/core/encoding/undefined_conversion_error/source_encoding_spec.rb
+++ b/spec/ruby/core/encoding/undefined_conversion_error/source_encoding_spec.rb
@@ -1,31 +1,30 @@
-require File.expand_path('../../fixtures/classes', __FILE__)
+require_relative "../../../spec_helper"
+require_relative '../fixtures/classes'
-with_feature :encoding do
- describe "Encoding::UndefinedConversionError#source_encoding" do
- before :each do
- @exception = EncodingSpecs::UndefinedConversionError.exception
- @exception2 = EncodingSpecs::UndefinedConversionErrorIndirect.exception
- end
+describe "Encoding::UndefinedConversionError#source_encoding" do
+ before :each do
+ @exception = EncodingSpecs::UndefinedConversionError.exception
+ @exception2 = EncodingSpecs::UndefinedConversionErrorIndirect.exception
+ end
- it "returns an Encoding object" do
- @exception.source_encoding.should be_an_instance_of(Encoding)
- @exception2.source_encoding.should be_an_instance_of(Encoding)
- end
+ it "returns an Encoding object" do
+ @exception.source_encoding.should.instance_of?(Encoding)
+ @exception2.source_encoding.should.instance_of?(Encoding)
+ end
- it "is equal to the source encoding of the object that raised it" do
- @exception.source_encoding.should == Encoding::UTF_8
- end
+ it "is equal to the source encoding of the object that raised it" do
+ @exception.source_encoding.should == Encoding::UTF_8
+ end
- # The source encoding specified in the Encoding::Converter constructor may
- # differ from the source encoding returned here. What seems to happen is
- # that when transcoding along a path with multiple pairs of encodings, the
- # last one encountered when the error occurred is returned. So in this
- # case, the conversion path is ISO-8859-1 -> UTF-8 -> EUC-JP. The
- # conversion from ISO-8859-1 -> UTF-8 succeeded, but the conversion from
- # UTF-8 to EUC-JP failed. IOW, it failed when the source encoding was
- # UTF-8, so UTF-8 is regarded as the source encoding.
- it "is equal to the source encoding at the stage of the conversion path where the error occurred" do
- @exception2.source_encoding.should == Encoding::UTF_8
- end
+ # The source encoding specified in the Encoding::Converter constructor may
+ # differ from the source encoding returned here. What seems to happen is
+ # that when transcoding along a path with multiple pairs of encodings, the
+ # last one encountered when the error occurred is returned. So in this
+ # case, the conversion path is ISO-8859-1 -> UTF-8 -> EUC-JP. The
+ # conversion from ISO-8859-1 -> UTF-8 succeeded, but the conversion from
+ # UTF-8 to EUC-JP failed. IOW, it failed when the source encoding was
+ # UTF-8, so UTF-8 is regarded as the source encoding.
+ it "is equal to the source encoding at the stage of the conversion path where the error occurred" do
+ @exception2.source_encoding.should == Encoding::UTF_8
end
end
diff --git a/spec/ruby/core/enumerable/all_spec.rb b/spec/ruby/core/enumerable/all_spec.rb
index bfde584260..cbdd63f86a 100644
--- a/spec/ruby/core/enumerable/all_spec.rb
+++ b/spec/ruby/core/enumerable/all_spec.rb
@@ -1,63 +1,67 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Enumerable#all?" do
-
before :each do
@enum = EnumerableSpecs::Numerous.new
@empty = EnumerableSpecs::Empty.new()
- @enum1 = [0, 1, 2, -1]
- @enum2 = [nil, false, true]
+ @enum1 = EnumerableSpecs::Numerous.new(0, 1, 2, -1)
+ @enum2 = EnumerableSpecs::Numerous.new(nil, false, true)
end
it "always returns true on empty enumeration" do
- @empty.all?.should == true
+ @empty.should.all?
@empty.all? { nil }.should == true
- [].all?.should == true
+ [].should.all?
[].all? { false }.should == true
- {}.all?.should == true
+ {}.should.all?
{}.all? { nil }.should == true
end
+ it "raises an ArgumentError when more than 1 argument is provided" do
+ -> { @enum.all?(1, 2, 3) }.should.raise(ArgumentError)
+ -> { [].all?(1, 2, 3) }.should.raise(ArgumentError)
+ -> { {}.all?(1, 2, 3) }.should.raise(ArgumentError)
+ end
+
it "does not hide exceptions out of #each" do
- lambda {
+ -> {
EnumerableSpecs::ThrowingEach.new.all?
- }.should raise_error(RuntimeError)
+ }.should.raise(RuntimeError)
- lambda {
+ -> {
EnumerableSpecs::ThrowingEach.new.all? { false }
- }.should raise_error(RuntimeError)
+ }.should.raise(RuntimeError)
end
describe "with no block" do
it "returns true if no elements are false or nil" do
- @enum.all?.should == true
- @enum1.all?.should == true
- @enum2.all?.should == false
+ @enum.should.all?
+ @enum1.should.all?
+ @enum2.should_not.all?
- EnumerableSpecs::Numerous.new('a','b','c').all?.should == true
- EnumerableSpecs::Numerous.new(0, "x", true).all?.should == true
+ EnumerableSpecs::Numerous.new('a','b','c').should.all?
+ EnumerableSpecs::Numerous.new(0, "x", true).should.all?
end
it "returns false if there are false or nil elements" do
- EnumerableSpecs::Numerous.new(false).all?.should == false
- EnumerableSpecs::Numerous.new(false, false).all?.should == false
+ EnumerableSpecs::Numerous.new(false).should_not.all?
+ EnumerableSpecs::Numerous.new(false, false).should_not.all?
- EnumerableSpecs::Numerous.new(nil).all?.should == false
- EnumerableSpecs::Numerous.new(nil, nil).all?.should == false
+ EnumerableSpecs::Numerous.new(nil).should_not.all?
+ EnumerableSpecs::Numerous.new(nil, nil).should_not.all?
- EnumerableSpecs::Numerous.new(1, nil, 2).all?.should == false
- EnumerableSpecs::Numerous.new(0, "x", false, true).all?.should == false
- @enum2.all?.should == false
+ EnumerableSpecs::Numerous.new(1, nil, 2).should_not.all?
+ EnumerableSpecs::Numerous.new(0, "x", false, true).should_not.all?
+ @enum2.should_not.all?
end
it "gathers whole arrays as elements when each yields multiple" do
multi = EnumerableSpecs::YieldsMultiWithFalse.new
- multi.all?.should be_true
+ multi.all?.should == true
end
-
end
describe "with block" do
@@ -100,22 +104,84 @@ describe "Enumerable#all?" do
end
it "does not hide exceptions out of the block" do
- lambda {
+ -> {
@enum.all? { raise "from block" }
- }.should raise_error(RuntimeError)
+ }.should.raise(RuntimeError)
end
it "gathers initial args as elements when each yields multiple" do
multi = EnumerableSpecs::YieldsMulti.new
- multi.all? {|e| !(Array === e) }.should be_true
+ yielded = []
+ multi.all? { |e| yielded << e }.should == true
+ yielded.should == [1, 3, 6]
end
it "yields multiple arguments when each yields multiple" do
multi = EnumerableSpecs::YieldsMulti.new
yielded = []
- multi.all? {|e, i| yielded << [e, i] }
- yielded.should == [[1, 2], [3, 4], [6, 7]]
+ multi.all? { |*args| yielded << args }.should == true
+ yielded.should == [[1, 2], [3, 4, 5], [6, 7, 8, 9]]
+ end
+ end
+
+ describe 'when given a pattern argument' do
+ it "calls `===` on the pattern the return value" do
+ pattern = EnumerableSpecs::Pattern.new { |x| x >= 0 }
+ @enum1.all?(pattern).should == false
+ pattern.yielded.should == [[0], [1], [2], [-1]]
+ end
+
+ it "always returns true on empty enumeration" do
+ @empty.all?(Integer).should == true
+ [].all?(Integer).should == true
+ {}.all?(NilClass).should == true
+ end
+
+ it "does not hide exceptions out of #each" do
+ -> {
+ EnumerableSpecs::ThrowingEach.new.all?(Integer)
+ }.should.raise(RuntimeError)
+ end
+
+ it "returns true if the pattern never returns false or nil" do
+ pattern = EnumerableSpecs::Pattern.new { |x| 42 }
+ @enum.all?(pattern).should == true
+
+ [1, 42, 3].all?(pattern).should == true
+
+ pattern = EnumerableSpecs::Pattern.new { |x| Array === x }
+ {a: 1, b: 2}.all?(pattern).should == true
+ end
+
+ it "returns false if the pattern ever returns false or nil" do
+ pattern = EnumerableSpecs::Pattern.new { |x| x >= 0 }
+ @enum1.all?(pattern).should == false
+ pattern.yielded.should == [[0], [1], [2], [-1]]
+
+ [1, 2, 3, -1].all?(pattern).should == false
+
+ pattern = EnumerableSpecs::Pattern.new { |x| x[1] >= 0 }
+ {a: 1, b: -1}.all?(pattern).should == false
end
+ it "does not hide exceptions out of pattern#===" do
+ pattern = EnumerableSpecs::Pattern.new { raise "from pattern" }
+ -> {
+ @enum.all?(pattern)
+ }.should.raise(RuntimeError)
+ end
+
+ it "calls the pattern with gathered array when yielded with multiple arguments" do
+ multi = EnumerableSpecs::YieldsMulti.new
+ pattern = EnumerableSpecs::Pattern.new { true }
+ multi.all?(pattern).should == true
+ pattern.yielded.should == [[[1, 2]], [[3, 4, 5]], [[6, 7, 8, 9]]]
+ end
+
+ it "ignores the block if there is an argument" do
+ -> {
+ EnumerableSpecs::Numerous.new(1, 2, 3, 4, 5).all?(String) { true }.should == false
+ }.should complain(/given block not used/)
+ end
end
end
diff --git a/spec/ruby/core/enumerable/any_spec.rb b/spec/ruby/core/enumerable/any_spec.rb
index 4a7511f649..4405d4740a 100644
--- a/spec/ruby/core/enumerable/any_spec.rb
+++ b/spec/ruby/core/enumerable/any_spec.rb
@@ -1,68 +1,66 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Enumerable#any?" do
before :each do
@enum = EnumerableSpecs::Numerous.new
- @empty = EnumerableSpecs::Empty.new()
- @enum1 = [0, 1, 2, -1]
- @enum2 = [nil, false, true]
+ @empty = EnumerableSpecs::Empty.new
+ @enum1 = EnumerableSpecs::Numerous.new(0, 1, 2, -1)
+ @enum2 = EnumerableSpecs::Numerous.new(nil, false, true)
end
it "always returns false on empty enumeration" do
- @empty.any?.should == false
+ @empty.should_not.any?
@empty.any? { nil }.should == false
- [].any?.should == false
+ [].should_not.any?
[].any? { false }.should == false
- {}.any?.should == false
+ {}.should_not.any?
{}.any? { nil }.should == false
end
- it "raises an ArgumentError when any arguments provided" do
- lambda { @enum.any?(Proc.new {}) }.should raise_error(ArgumentError)
- lambda { @enum.any?(nil) }.should raise_error(ArgumentError)
- lambda { @empty.any?(1) }.should raise_error(ArgumentError)
- lambda { @enum1.any?(1) {} }.should raise_error(ArgumentError)
- lambda { @enum2.any?(1, 2, 3) {} }.should raise_error(ArgumentError)
+ it "raises an ArgumentError when more than 1 argument is provided" do
+ -> { @enum.any?(1, 2, 3) }.should.raise(ArgumentError)
+ -> { [].any?(1, 2, 3) }.should.raise(ArgumentError)
+ -> { {}.any?(1, 2, 3) }.should.raise(ArgumentError)
end
it "does not hide exceptions out of #each" do
- lambda {
+ -> {
EnumerableSpecs::ThrowingEach.new.any?
- }.should raise_error(RuntimeError)
+ }.should.raise(RuntimeError)
- lambda {
+ -> {
EnumerableSpecs::ThrowingEach.new.any? { false }
- }.should raise_error(RuntimeError)
+ }.should.raise(RuntimeError)
end
describe "with no block" do
it "returns true if any element is not false or nil" do
- @enum.any?.should == true
- @enum1.any?.should == true
- @enum2.any?.should == true
- EnumerableSpecs::Numerous.new(true).any?.should == true
- EnumerableSpecs::Numerous.new('a','b','c').any?.should == true
- EnumerableSpecs::Numerous.new('a','b','c', nil).any?.should == true
- EnumerableSpecs::Numerous.new(1, nil, 2).any?.should == true
- EnumerableSpecs::Numerous.new(1, false).any?.should == true
- EnumerableSpecs::Numerous.new(false, nil, 1, false).any?.should == true
- EnumerableSpecs::Numerous.new(false, 0, nil).any?.should == true
+ @enum.should.any?
+ @enum1.should.any?
+ @enum2.should.any?
+ EnumerableSpecs::Numerous.new(true).should.any?
+ EnumerableSpecs::Numerous.new('a','b','c').should.any?
+ EnumerableSpecs::Numerous.new('a','b','c', nil).should.any?
+ EnumerableSpecs::Numerous.new(1, nil, 2).should.any?
+ EnumerableSpecs::Numerous.new(1, false).should.any?
+ EnumerableSpecs::Numerous.new(false, nil, 1, false).should.any?
+ EnumerableSpecs::Numerous.new(false, 0, nil).should.any?
end
it "returns false if all elements are false or nil" do
- EnumerableSpecs::Numerous.new(false).any?.should == false
- EnumerableSpecs::Numerous.new(false, false).any?.should == false
- EnumerableSpecs::Numerous.new(nil).any?.should == false
- EnumerableSpecs::Numerous.new(nil, nil).any?.should == false
- EnumerableSpecs::Numerous.new(nil, false, nil).any?.should == false
+ EnumerableSpecs::Numerous.new(false).should_not.any?
+ EnumerableSpecs::Numerous.new(false, false).should_not.any?
+ EnumerableSpecs::Numerous.new(nil).should_not.any?
+ EnumerableSpecs::Numerous.new(nil, nil).should_not.any?
+ EnumerableSpecs::Numerous.new(nil, false, nil).should_not.any?
end
it "gathers whole arrays as elements when each yields multiple" do
multi = EnumerableSpecs::YieldsMultiWithFalse.new
- multi.any?.should be_true
+ multi.any?.should == true
end
end
@@ -79,7 +77,7 @@ describe "Enumerable#any?" do
@enum2.any? { |i| i == nil }.should == true
end
- it "any? should return false if the block never returns other than false or nil" do
+ it "returns false if the block never returns other than false or nil" do
@enum.any? { false }.should == false
@enum.any? { nil }.should == false
@@ -120,22 +118,83 @@ describe "Enumerable#any?" do
end
it "does not hide exceptions out of the block" do
- lambda {
+ -> {
@enum.any? { raise "from block" }
- }.should raise_error(RuntimeError)
+ }.should.raise(RuntimeError)
end
it "gathers initial args as elements when each yields multiple" do
multi = EnumerableSpecs::YieldsMulti.new
- multi.any? {|e| e == 1 }.should be_true
+ yielded = []
+ multi.any? { |e| yielded << e; false }.should == false
+ yielded.should == [1, 3, 6]
end
it "yields multiple arguments when each yields multiple" do
multi = EnumerableSpecs::YieldsMulti.new
yielded = []
- multi.any? {|e, i| yielded << [e, i] }
- yielded.should == [[1, 2]]
+ multi.any? { |*args| yielded << args; false }.should == false
+ yielded.should == [[1, 2], [3, 4, 5], [6, 7, 8, 9]]
+ end
+ end
+
+ describe 'when given a pattern argument' do
+ it "calls `===` on the pattern the return value" do
+ pattern = EnumerableSpecs::Pattern.new { |x| x == 2 }
+ @enum1.any?(pattern).should == true
+ pattern.yielded.should == [[0], [1], [2]]
+ end
+
+ it "always returns false on empty enumeration" do
+ @empty.any?(Integer).should == false
+ [].any?(Integer).should == false
+ {}.any?(NilClass).should == false
end
+ it "does not hide exceptions out of #each" do
+ -> {
+ EnumerableSpecs::ThrowingEach.new.any?(Integer)
+ }.should.raise(RuntimeError)
+ end
+
+ it "returns true if the pattern ever returns a truthy value" do
+ @enum2.any?(NilClass).should == true
+ pattern = EnumerableSpecs::Pattern.new { |x| 42 }
+ @enum.any?(pattern).should == true
+
+ [1, 42, 3].any?(pattern).should == true
+
+ pattern = EnumerableSpecs::Pattern.new { |x| x == [:b, 2] }
+ {a: 1, b: 2}.any?(pattern).should == true
+ end
+
+ it "returns false if the block never returns other than false or nil" do
+ pattern = EnumerableSpecs::Pattern.new { |x| nil }
+ @enum1.any?(pattern).should == false
+ pattern.yielded.should == [[0], [1], [2], [-1]]
+
+ [1, 2, 3].any?(pattern).should == false
+ {a: 1}.any?(pattern).should == false
+ end
+
+ it "does not hide exceptions out of pattern#===" do
+ pattern = EnumerableSpecs::Pattern.new { raise "from pattern" }
+ -> {
+ @enum.any?(pattern)
+ }.should.raise(RuntimeError)
+ end
+
+ it "calls the pattern with gathered array when yielded with multiple arguments" do
+ multi = EnumerableSpecs::YieldsMulti.new
+ pattern = EnumerableSpecs::Pattern.new { false }
+ multi.any?(pattern).should == false
+ pattern.yielded.should == [[[1, 2]], [[3, 4, 5]], [[6, 7, 8, 9]]]
+ end
+
+ it "ignores the block if there is an argument" do
+ -> {
+ EnumerableSpecs::Numerous.new(1, 2, 3, 4, 5).any?(String) { true }.should == false
+ }.should complain(/given block not used/)
+ end
end
end
diff --git a/spec/ruby/core/enumerable/chain_spec.rb b/spec/ruby/core/enumerable/chain_spec.rb
new file mode 100644
index 0000000000..a0597e46a1
--- /dev/null
+++ b/spec/ruby/core/enumerable/chain_spec.rb
@@ -0,0 +1,23 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe "Enumerable#chain" do
+ before :each do
+ ScratchPad.record []
+ end
+
+ it "returns a chain of self and provided enumerables" do
+ one = EnumerableSpecs::Numerous.new(1)
+ two = EnumerableSpecs::Numerous.new(2, 3)
+ three = EnumerableSpecs::Numerous.new(4, 5, 6)
+
+ chain = one.chain(two, three)
+
+ chain.each { |item| ScratchPad << item }
+ ScratchPad.recorded.should == [1, 2, 3, 4, 5, 6]
+ end
+
+ it "returns an Enumerator::Chain if given a block" do
+ EnumerableSpecs::Numerous.new.chain.should.instance_of?(Enumerator::Chain)
+ end
+end
diff --git a/spec/ruby/core/enumerable/chunk_spec.rb b/spec/ruby/core/enumerable/chunk_spec.rb
index 9d658010e1..7c9b31c991 100644
--- a/spec/ruby/core/enumerable/chunk_spec.rb
+++ b/spec/ruby/core/enumerable/chunk_spec.rb
@@ -1,30 +1,20 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Enumerable#chunk" do
before do
ScratchPad.record []
end
- ruby_version_is ""..."2.4" do
- it "raises an ArgumentError if called without a block" do
- lambda do
- EnumerableSpecs::Numerous.new.chunk
- end.should raise_error(ArgumentError)
- end
- end
-
- ruby_version_is "2.4" do
- it "returns an Enumerator if called without a block" do
- chunk = EnumerableSpecs::Numerous.new(1, 2, 3, 1, 2).chunk
- chunk.should be_an_instance_of(Enumerator)
- result = chunk.with_index {|elt, i| elt - i }.to_a
- result.should == [[1, [1, 2, 3]], [-2, [1, 2]]]
- end
+ it "returns an Enumerator if called without a block" do
+ chunk = EnumerableSpecs::Numerous.new(1, 2, 3, 1, 2).chunk
+ chunk.should.instance_of?(Enumerator)
+ result = chunk.with_index {|elt, i| elt - i }.to_a
+ result.should == [[1, [1, 2, 3]], [-2, [1, 2]]]
end
it "returns an Enumerator if given a block" do
- EnumerableSpecs::Numerous.new.chunk {}.should be_an_instance_of(Enumerator)
+ EnumerableSpecs::Numerous.new.chunk {}.should.instance_of?(Enumerator)
end
it "yields the current element and the current chunk to the block" do
@@ -39,12 +29,22 @@ describe "Enumerable#chunk" do
result.should == [[1, [1, 2]], [0, [3]], [1, [2]], [0, [3]], [1, [2, 1]]]
end
+ it "returns a partitioned Array of values" do
+ e = EnumerableSpecs::Numerous.new(1,2,3)
+ e.chunk { |x| x > 2 }.map(&:last).should == [[1, 2], [3]]
+ end
+
it "returns elements for which the block returns :_alone in separate Arrays" do
e = EnumerableSpecs::Numerous.new(1, 2, 3, 2, 1)
result = e.chunk { |x| x < 2 && :_alone }.to_a
result.should == [[:_alone, [1]], [false, [2, 3, 2]], [:_alone, [1]]]
end
+ it "yields Arrays as a single argument to a rest argument" do
+ e = EnumerableSpecs::Numerous.new([1, 2])
+ result = e.chunk { |*x| x.should == [[1,2]] }.to_a
+ end
+
it "does not return elements for which the block returns :_separator" do
e = EnumerableSpecs::Numerous.new(1, 2, 3, 3, 2, 1)
result = e.chunk { |x| x == 2 ? :_separator : 1 }.to_a
@@ -59,37 +59,14 @@ describe "Enumerable#chunk" do
it "raises a RuntimeError if the block returns a Symbol starting with an underscore other than :_alone or :_separator" do
e = EnumerableSpecs::Numerous.new(1, 2, 3, 2, 1)
- lambda { e.chunk { |x| :_arbitrary }.to_a }.should raise_error(RuntimeError)
+ -> { e.chunk { |x| :_arbitrary }.to_a }.should.raise(RuntimeError)
end
- ruby_version_is ""..."2.3" do
- describe "with [initial_state]" do
- it "yields an element and an object value-equal but not identical to the object passed to #chunk" do
- e = EnumerableSpecs::Numerous.new(1)
- value = "value"
-
- e.chunk(value) do |x, v|
- x.should == 1
- v.should == value
- v.should_not equal(value)
- end.to_a
- end
-
- it "does not yield the object passed to #chunk if it is nil" do
- e = EnumerableSpecs::Numerous.new(1)
- e.chunk(nil) { |*x| ScratchPad << x }.to_a
- ScratchPad.recorded.should == [[1]]
- end
- end
- end
-
- ruby_version_is "2.3" do
- it "does not accept arguments" do
- e = EnumerableSpecs::Numerous.new(1, 2, 3)
- lambda {
- e.chunk(1) {}
- }.should raise_error(ArgumentError)
- end
+ it "does not accept arguments" do
+ e = EnumerableSpecs::Numerous.new(1, 2, 3)
+ -> {
+ e.chunk(1) {}
+ }.should.raise(ArgumentError)
end
it 'returned Enumerator size returns nil' do
diff --git a/spec/ruby/core/enumerable/chunk_while_spec.rb b/spec/ruby/core/enumerable/chunk_while_spec.rb
index a5cbdc3348..286f717442 100644
--- a/spec/ruby/core/enumerable/chunk_while_spec.rb
+++ b/spec/ruby/core/enumerable/chunk_while_spec.rb
@@ -1,44 +1,42 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
-ruby_version_is "2.3" do
- describe "Enumerable#chunk_while" do
- before :each do
- ary = [10, 9, 7, 6, 4, 3, 2, 1]
- @enum = EnumerableSpecs::Numerous.new(*ary)
- @result = @enum.chunk_while { |i, j| i - 1 == j }
- @enum_length = ary.length
- end
+describe "Enumerable#chunk_while" do
+ before :each do
+ ary = [10, 9, 7, 6, 4, 3, 2, 1]
+ @enum = EnumerableSpecs::Numerous.new(*ary)
+ @result = @enum.chunk_while { |i, j| i - 1 == j }
+ @enum_length = ary.length
+ end
- context "when given a block" do
- it "returns an enumerator" do
- @result.should be_an_instance_of(Enumerator)
- end
+ context "when given a block" do
+ it "returns an enumerator" do
+ @result.should.instance_of?(Enumerator)
+ end
- it "splits chunks between adjacent elements i and j where the block returns false" do
- @result.to_a.should == [[10, 9], [7, 6], [4, 3, 2, 1]]
- end
+ it "splits chunks between adjacent elements i and j where the block returns false" do
+ @result.to_a.should == [[10, 9], [7, 6], [4, 3, 2, 1]]
+ end
- it "calls the block for length of the receiver enumerable minus one times" do
- times_called = 0
- @enum.chunk_while do |i, j|
- times_called += 1
- i - 1 == j
- end.to_a
- times_called.should == (@enum_length - 1)
- end
+ it "calls the block for length of the receiver enumerable minus one times" do
+ times_called = 0
+ @enum.chunk_while do |i, j|
+ times_called += 1
+ i - 1 == j
+ end.to_a
+ times_called.should == (@enum_length - 1)
end
+ end
- context "when not given a block" do
- it "raises an ArgumentError" do
- lambda { @enum.chunk_while }.should raise_error(ArgumentError)
- end
+ context "when not given a block" do
+ it "raises an ArgumentError" do
+ -> { @enum.chunk_while }.should.raise(ArgumentError)
end
+ end
- context "on a single-element array" do
- it "ignores the block and returns an enumerator that yields [element]" do
- [1].chunk_while {|x| x.even?}.to_a.should == [[1]]
- end
+ context "on a single-element array" do
+ it "ignores the block and returns an enumerator that yields [element]" do
+ [1].chunk_while {|x| x.even?}.to_a.should == [[1]]
end
end
end
diff --git a/spec/ruby/core/enumerable/collect_concat_spec.rb b/spec/ruby/core/enumerable/collect_concat_spec.rb
index 6f21012060..5024aaddab 100644
--- a/spec/ruby/core/enumerable/collect_concat_spec.rb
+++ b/spec/ruby/core/enumerable/collect_concat_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/collect_concat', __FILE__)
+require_relative '../../spec_helper'
describe "Enumerable#collect_concat" do
- it_behaves_like(:enumerable_collect_concat , :collect_concat)
+ it "is an alias of Enumerable#flat_map" do
+ Enumerable.instance_method(:collect_concat).should == Enumerable.instance_method(:flat_map)
+ end
end
diff --git a/spec/ruby/core/enumerable/collect_spec.rb b/spec/ruby/core/enumerable/collect_spec.rb
index a830eef9f7..319b1b263d 100644
--- a/spec/ruby/core/enumerable/collect_spec.rb
+++ b/spec/ruby/core/enumerable/collect_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/collect', __FILE__)
+require_relative '../../spec_helper'
describe "Enumerable#collect" do
- it_behaves_like(:enumerable_collect , :collect)
+ it "is an alias of Enumerable#map" do
+ Enumerable.instance_method(:collect).should == Enumerable.instance_method(:map)
+ end
end
diff --git a/spec/ruby/core/enumerable/compact_spec.rb b/spec/ruby/core/enumerable/compact_spec.rb
new file mode 100644
index 0000000000..1895430c4e
--- /dev/null
+++ b/spec/ruby/core/enumerable/compact_spec.rb
@@ -0,0 +1,9 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe "Enumerable#compact" do
+ it 'returns array without nil elements' do
+ arr = EnumerableSpecs::Numerous.new(nil, 1, 2, nil, true)
+ arr.compact.should == [1, 2, true]
+ end
+end
diff --git a/spec/ruby/core/enumerable/count_spec.rb b/spec/ruby/core/enumerable/count_spec.rb
index 9d1e08f3a9..50a1c8e1a4 100644
--- a/spec/ruby/core/enumerable/count_spec.rb
+++ b/spec/ruby/core/enumerable/count_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Enumerable#count" do
before :each do
diff --git a/spec/ruby/core/enumerable/cycle_spec.rb b/spec/ruby/core/enumerable/cycle_spec.rb
index 9089a94963..1fb3cc3d41 100644
--- a/spec/ruby/core/enumerable/cycle_spec.rb
+++ b/spec/ruby/core/enumerable/cycle_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/enumeratorized', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/enumeratorized'
describe "Enumerable#cycle" do
describe "passed no argument or nil" do
@@ -17,7 +17,7 @@ describe "Enumerable#cycle" do
it "returns nil if there are no elements" do
out = EnumerableSpecs::Empty.new.cycle { break :nope }
- out.should be_nil
+ out.should == nil
end
it "yields successive elements of the array repeatedly" do
@@ -44,8 +44,8 @@ describe "Enumerable#cycle" do
describe "passed a number n as an argument" do
it "returns nil and does nothing for non positive n" do
- EnumerableSpecs::ThrowingEach.new.cycle(0) {}.should be_nil
- EnumerableSpecs::NoEach.new.cycle(-22) {}.should be_nil
+ EnumerableSpecs::ThrowingEach.new.cycle(0) {}.should == nil
+ EnumerableSpecs::NoEach.new.cycle(-22) {}.should == nil
end
it "calls each at most once" do
@@ -71,12 +71,12 @@ describe "Enumerable#cycle" do
it "raises a TypeError when the passed n cannot be coerced to Integer" do
enum = EnumerableSpecs::Numerous.new
- lambda{ enum.cycle("cat"){} }.should raise_error(TypeError)
+ ->{ enum.cycle("cat"){} }.should.raise(TypeError)
end
it "raises an ArgumentError if more arguments are passed" do
enum = EnumerableSpecs::Numerous.new
- lambda{ enum.cycle(1, 2) {} }.should raise_error(ArgumentError)
+ ->{ enum.cycle(1, 2) {} }.should.raise(ArgumentError)
end
it "gathers whole arrays as elements when each yields multiple" do
diff --git a/spec/ruby/core/enumerable/detect_spec.rb b/spec/ruby/core/enumerable/detect_spec.rb
index f69e456052..0669c50c58 100644
--- a/spec/ruby/core/enumerable/detect_spec.rb
+++ b/spec/ruby/core/enumerable/detect_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/find', __FILE__)
+require_relative '../../spec_helper'
describe "Enumerable#detect" do
- it_behaves_like(:enumerable_find , :detect)
+ it "is an alias of Enumerable#find" do
+ Enumerable.instance_method(:detect).should == Enumerable.instance_method(:find)
+ end
end
diff --git a/spec/ruby/core/enumerable/drop_spec.rb b/spec/ruby/core/enumerable/drop_spec.rb
index 4013a639ce..8d95f464b3 100644
--- a/spec/ruby/core/enumerable/drop_spec.rb
+++ b/spec/ruby/core/enumerable/drop_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Enumerable#drop" do
before :each do
@@ -7,13 +7,13 @@ describe "Enumerable#drop" do
end
it "requires exactly one argument" do
- lambda{ @enum.drop{} }.should raise_error(ArgumentError)
- lambda{ @enum.drop(1, 2){} }.should raise_error(ArgumentError)
+ ->{ @enum.drop{} }.should.raise(ArgumentError)
+ ->{ @enum.drop(1, 2){} }.should.raise(ArgumentError)
end
describe "passed a number n as an argument" do
it "raises ArgumentError if n < 0" do
- lambda{ @enum.drop(-1) }.should raise_error(ArgumentError)
+ ->{ @enum.drop(-1) }.should.raise(ArgumentError)
end
it "tries to convert n to an Integer using #to_int" do
@@ -35,8 +35,8 @@ describe "Enumerable#drop" do
end
it "raises a TypeError when the passed n cannot be coerced to Integer" do
- lambda{ @enum.drop("hat") }.should raise_error(TypeError)
- lambda{ @enum.drop(nil) }.should raise_error(TypeError)
+ ->{ @enum.drop("hat") }.should.raise(TypeError)
+ ->{ @enum.drop(nil) }.should.raise(TypeError)
end
end
diff --git a/spec/ruby/core/enumerable/drop_while_spec.rb b/spec/ruby/core/enumerable/drop_while_spec.rb
index 731b9588e4..4b4fdf2d4f 100644
--- a/spec/ruby/core/enumerable/drop_while_spec.rb
+++ b/spec/ruby/core/enumerable/drop_while_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/enumerable_enumeratorized', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/enumerable_enumeratorized'
describe "Enumerable#drop_while" do
before :each do
@@ -8,7 +8,7 @@ describe "Enumerable#drop_while" do
end
it "returns an Enumerator if no block given" do
- @enum.drop_while.should be_an_instance_of(Enumerator)
+ @enum.drop_while.should.instance_of?(Enumerator)
end
it "returns no/all elements for {true/false} block" do
@@ -38,7 +38,7 @@ describe "Enumerable#drop_while" do
it "doesn't return self when it could" do
a = [1,2,3]
- a.drop_while{false}.should_not equal(a)
+ a.drop_while{false}.should_not.equal?(a)
end
it "gathers whole arrays as elements when each yields multiple" do
diff --git a/spec/ruby/core/enumerable/each_cons_spec.rb b/spec/ruby/core/enumerable/each_cons_spec.rb
index 6720199bc3..c5e299fd00 100644
--- a/spec/ruby/core/enumerable/each_cons_spec.rb
+++ b/spec/ruby/core/enumerable/each_cons_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/enumeratorized', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/enumeratorized'
describe "Enumerable#each_cons" do
before :each do
@@ -10,24 +10,24 @@ describe "Enumerable#each_cons" do
it "passes element groups to the block" do
acc = []
- @enum.each_cons(3){|g| acc << g}.should be_nil
+ @enum.each_cons(3){|g| acc << g}
acc.should == @in_threes
end
it "raises an ArgumentError if there is not a single parameter > 0" do
- lambda{ @enum.each_cons(0){} }.should raise_error(ArgumentError)
- lambda{ @enum.each_cons(-2){} }.should raise_error(ArgumentError)
- lambda{ @enum.each_cons{} }.should raise_error(ArgumentError)
- lambda{ @enum.each_cons(2,2){} }.should raise_error(ArgumentError)
- lambda{ @enum.each_cons(0) }.should raise_error(ArgumentError)
- lambda{ @enum.each_cons(-2) }.should raise_error(ArgumentError)
- lambda{ @enum.each_cons }.should raise_error(ArgumentError)
- lambda{ @enum.each_cons(2,2) }.should raise_error(ArgumentError)
+ ->{ @enum.each_cons(0){} }.should.raise(ArgumentError)
+ ->{ @enum.each_cons(-2){} }.should.raise(ArgumentError)
+ ->{ @enum.each_cons{} }.should.raise(ArgumentError)
+ ->{ @enum.each_cons(2,2){} }.should.raise(ArgumentError)
+ ->{ @enum.each_cons(0) }.should.raise(ArgumentError)
+ ->{ @enum.each_cons(-2) }.should.raise(ArgumentError)
+ ->{ @enum.each_cons }.should.raise(ArgumentError)
+ ->{ @enum.each_cons(2,2) }.should.raise(ArgumentError)
end
it "tries to convert n to an Integer using #to_int" do
acc = []
- @enum.each_cons(3.3){|g| acc << g}.should == nil
+ @enum.each_cons(3.3){|g| acc << g}
acc.should == @in_threes
obj = mock('to_int')
@@ -56,10 +56,14 @@ describe "Enumerable#each_cons" do
multi.each_cons(2).to_a.should == [[[1, 2], [3, 4, 5]], [[3, 4, 5], [6, 7, 8, 9]]]
end
+ it "returns self when a block is given" do
+ @enum.each_cons(3){}.should == @enum
+ end
+
describe "when no block is given" do
it "returns an enumerator" do
e = @enum.each_cons(3)
- e.should be_an_instance_of(Enumerator)
+ e.should.instance_of?(Enumerator)
e.to_a.should == @in_threes
end
diff --git a/spec/ruby/core/enumerable/each_entry_spec.rb b/spec/ruby/core/enumerable/each_entry_spec.rb
index 05d181a998..9dc89ec28e 100644
--- a/spec/ruby/core/enumerable/each_entry_spec.rb
+++ b/spec/ruby/core/enumerable/each_entry_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/enumerable_enumeratorized', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/enumerable_enumeratorized'
describe "Enumerable#each_entry" do
before :each do
@@ -11,13 +11,13 @@ describe "Enumerable#each_entry" do
it "yields multiple arguments as an array" do
acc = []
- @enum.each_entry {|g| acc << g}.should equal(@enum)
+ @enum.each_entry {|g| acc << g}.should.equal?(@enum)
acc.should == @entries
end
it "returns an enumerator if no block" do
e = @enum.each_entry
- e.should be_an_instance_of(Enumerator)
+ e.should.instance_of?(Enumerator)
e.to_a.should == @entries
end
@@ -27,8 +27,8 @@ describe "Enumerable#each_entry" do
end
it "raises an ArgumentError when extra arguments" do
- lambda { @enum.each_entry("one").to_a }.should raise_error(ArgumentError)
- lambda { @enum.each_entry("one"){}.to_a }.should raise_error(ArgumentError)
+ -> { @enum.each_entry("one").to_a }.should.raise(ArgumentError)
+ -> { @enum.each_entry("one"){}.to_a }.should.raise(ArgumentError)
end
it "passes extra arguments to #each" do
diff --git a/spec/ruby/core/enumerable/each_slice_spec.rb b/spec/ruby/core/enumerable/each_slice_spec.rb
index 62503fe206..d05abad1e9 100644
--- a/spec/ruby/core/enumerable/each_slice_spec.rb
+++ b/spec/ruby/core/enumerable/each_slice_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/enumeratorized', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/enumeratorized'
describe "Enumerable#each_slice" do
before :each do
@@ -10,24 +10,24 @@ describe "Enumerable#each_slice" do
it "passes element groups to the block" do
acc = []
- @enum.each_slice(3){|g| acc << g}.should be_nil
+ @enum.each_slice(3){|g| acc << g}
acc.should == @sliced
end
it "raises an ArgumentError if there is not a single parameter > 0" do
- lambda{ @enum.each_slice(0){} }.should raise_error(ArgumentError)
- lambda{ @enum.each_slice(-2){} }.should raise_error(ArgumentError)
- lambda{ @enum.each_slice{} }.should raise_error(ArgumentError)
- lambda{ @enum.each_slice(2,2){} }.should raise_error(ArgumentError)
- lambda{ @enum.each_slice(0) }.should raise_error(ArgumentError)
- lambda{ @enum.each_slice(-2) }.should raise_error(ArgumentError)
- lambda{ @enum.each_slice }.should raise_error(ArgumentError)
- lambda{ @enum.each_slice(2,2) }.should raise_error(ArgumentError)
+ ->{ @enum.each_slice(0){} }.should.raise(ArgumentError)
+ ->{ @enum.each_slice(-2){} }.should.raise(ArgumentError)
+ ->{ @enum.each_slice{} }.should.raise(ArgumentError)
+ ->{ @enum.each_slice(2,2){} }.should.raise(ArgumentError)
+ ->{ @enum.each_slice(0) }.should.raise(ArgumentError)
+ ->{ @enum.each_slice(-2) }.should.raise(ArgumentError)
+ ->{ @enum.each_slice }.should.raise(ArgumentError)
+ ->{ @enum.each_slice(2,2) }.should.raise(ArgumentError)
end
it "tries to convert n to an Integer using #to_int" do
acc = []
- @enum.each_slice(3.3){|g| acc << g}.should == nil
+ @enum.each_slice(3.3){|g| acc << g}
acc.should == @sliced
obj = mock('to_int')
@@ -53,10 +53,14 @@ describe "Enumerable#each_slice" do
it "returns an enumerator if no block" do
e = @enum.each_slice(3)
- e.should be_an_instance_of(Enumerator)
+ e.should.instance_of?(Enumerator)
e.to_a.should == @sliced
end
+ it "returns self when a block is given" do
+ @enum.each_slice(3){}.should == @enum
+ end
+
it "gathers whole arrays as elements when each yields multiple" do
multi = EnumerableSpecs::YieldsMulti.new
multi.each_slice(2).to_a.should == [[[1, 2], [3, 4, 5]], [[6, 7, 8, 9]]]
@@ -65,7 +69,7 @@ describe "Enumerable#each_slice" do
describe "when no block is given" do
it "returns an enumerator" do
e = @enum.each_slice(3)
- e.should be_an_instance_of(Enumerator)
+ e.should.instance_of?(Enumerator)
e.to_a.should == @sliced
end
diff --git a/spec/ruby/core/enumerable/each_with_index_spec.rb b/spec/ruby/core/enumerable/each_with_index_spec.rb
index 9884e71167..fcb2f82f84 100644
--- a/spec/ruby/core/enumerable/each_with_index_spec.rb
+++ b/spec/ruby/core/enumerable/each_with_index_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/enumerable_enumeratorized', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/enumerable_enumeratorized'
describe "Enumerable#each_with_index" do
@@ -26,19 +26,19 @@ describe "Enumerable#each_with_index" do
acc = []
res = @b.each_with_index {|a,i| acc << [a,i]}
[[2, 0], [5, 1], [3, 2], [6, 3], [1, 4], [4, 5]].should == acc
- res.should eql(@b)
+ res.should.eql?(@b)
end
it "binds splat arguments properly" do
acc = []
res = @b.each_with_index { |*b| c,d = b; acc << c; acc << d }
[2, 0, 5, 1, 3, 2, 6, 3, 1, 4, 4, 5].should == acc
- res.should eql(@b)
+ res.should.eql?(@b)
end
it "returns an enumerator if no block" do
e = @b.each_with_index
- e.should be_an_instance_of(Enumerator)
+ e.should.instance_of?(Enumerator)
e.to_a.should == [[2, 0], [5, 1], [3, 2], [6, 3], [1, 4], [4, 5]]
end
diff --git a/spec/ruby/core/enumerable/each_with_object_spec.rb b/spec/ruby/core/enumerable/each_with_object_spec.rb
index 13a7c1c66d..1760d3b267 100644
--- a/spec/ruby/core/enumerable/each_with_object_spec.rb
+++ b/spec/ruby/core/enumerable/each_with_object_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/enumerable_enumeratorized', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/enumerable_enumeratorized'
describe "Enumerable#each_with_object" do
before :each do
@@ -12,10 +12,10 @@ describe "Enumerable#each_with_object" do
it "passes each element and its argument to the block" do
acc = []
@enum.each_with_object(@initial) do |elem, obj|
- obj.should equal(@initial)
+ obj.should.equal?(@initial)
obj = 42
acc << elem
- end.should equal(@initial)
+ end.should.equal?(@initial)
acc.should == @values
end
@@ -23,10 +23,10 @@ describe "Enumerable#each_with_object" do
acc = []
e = @enum.each_with_object(@initial)
e.each do |elem, obj|
- obj.should equal(@initial)
+ obj.should.equal?(@initial)
obj = 42
acc << elem
- end.should equal(@initial)
+ end.should.equal?(@initial)
acc.should == @values
end
diff --git a/spec/ruby/core/enumerable/entries_spec.rb b/spec/ruby/core/enumerable/entries_spec.rb
index 94eceee713..8cb29b7b47 100644
--- a/spec/ruby/core/enumerable/entries_spec.rb
+++ b/spec/ruby/core/enumerable/entries_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/entries', __FILE__)
+require_relative '../../spec_helper'
describe "Enumerable#entries" do
- it_behaves_like(:enumerable_entries , :entries)
+ it "is an alias of Enumerable#to_a" do
+ Enumerable.instance_method(:entries).should == Enumerable.instance_method(:to_a)
+ end
end
diff --git a/spec/ruby/core/enumerable/filter_map_spec.rb b/spec/ruby/core/enumerable/filter_map_spec.rb
new file mode 100644
index 0000000000..1ed131a960
--- /dev/null
+++ b/spec/ruby/core/enumerable/filter_map_spec.rb
@@ -0,0 +1,24 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe 'Enumerable#filter_map' do
+ before :each do
+ @numerous = EnumerableSpecs::Numerous.new(*(1..8).to_a)
+ end
+
+ it 'returns an empty array if there are no elements' do
+ EnumerableSpecs::Empty.new.filter_map { true }.should == []
+ end
+
+ it 'returns an array with truthy results of passing each element to block' do
+ @numerous.filter_map { |i| i * 2 if i.even? }.should == [4, 8, 12, 16]
+ @numerous.filter_map { |i| i * 2 }.should == [2, 4, 6, 8, 10, 12, 14, 16]
+ @numerous.filter_map { 0 }.should == [0, 0, 0, 0, 0, 0, 0, 0]
+ @numerous.filter_map { false }.should == []
+ @numerous.filter_map { nil }.should == []
+ end
+
+ it 'returns an enumerator when no block given' do
+ @numerous.filter_map.should.instance_of?(Enumerator)
+ end
+end
diff --git a/spec/ruby/core/enumerable/filter_spec.rb b/spec/ruby/core/enumerable/filter_spec.rb
new file mode 100644
index 0000000000..d075b39396
--- /dev/null
+++ b/spec/ruby/core/enumerable/filter_spec.rb
@@ -0,0 +1,7 @@
+require_relative '../../spec_helper'
+
+describe "Enumerable#filter" do
+ it "is an alias of Enumerable#select" do
+ Enumerable.instance_method(:filter).should == Enumerable.instance_method(:select)
+ end
+end
diff --git a/spec/ruby/core/enumerable/find_all_spec.rb b/spec/ruby/core/enumerable/find_all_spec.rb
index 3d587d7709..1095a19569 100644
--- a/spec/ruby/core/enumerable/find_all_spec.rb
+++ b/spec/ruby/core/enumerable/find_all_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/find_all', __FILE__)
+require_relative '../../spec_helper'
describe "Enumerable#find_all" do
- it_behaves_like(:enumerable_find_all , :find_all)
+ it "is an alias of Enumerable#select" do
+ Enumerable.instance_method(:find_all).should == Enumerable.instance_method(:select)
+ end
end
diff --git a/spec/ruby/core/enumerable/find_index_spec.rb b/spec/ruby/core/enumerable/find_index_spec.rb
index c118a61fcf..2e714367ba 100644
--- a/spec/ruby/core/enumerable/find_index_spec.rb
+++ b/spec/ruby/core/enumerable/find_index_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/enumerable_enumeratorized', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/enumerable_enumeratorized'
describe "Enumerable#find_index" do
before :each do
@@ -47,7 +47,7 @@ describe "Enumerable#find_index" do
end
it "returns an Enumerator if no block given" do
- @numerous.find_index.should be_an_instance_of(Enumerator)
+ @numerous.find_index.should.instance_of?(Enumerator)
end
it "uses #== for testing equality" do
diff --git a/spec/ruby/core/enumerable/find_spec.rb b/spec/ruby/core/enumerable/find_spec.rb
index 62e1194537..4ac4b75c47 100644
--- a/spec/ruby/core/enumerable/find_spec.rb
+++ b/spec/ruby/core/enumerable/find_spec.rb
@@ -1,7 +1,78 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/find', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/enumerable_enumeratorized'
describe "Enumerable#find" do
- it_behaves_like(:enumerable_find , :find)
+ before :each do
+ ScratchPad.record []
+ @elements = [2, 4, 6, 8, 10]
+ @numerous = EnumerableSpecs::Numerous.new(*@elements)
+ @empty = []
+ end
+
+ it "passes each entry in enum to block while block when block is false" do
+ visited_elements = []
+ @numerous.find do |element|
+ visited_elements << element
+ false
+ end
+ visited_elements.should == @elements
+ end
+
+ it "returns nil when the block is false and there is no ifnone proc given" do
+ @numerous.find {|e| false }.should == nil
+ end
+
+ it "returns the first element for which the block is not false" do
+ @elements.each do |element|
+ @numerous.find {|e| e > element - 1 }.should == element
+ end
+ end
+
+ it "returns the value of the ifnone proc if the block is false" do
+ fail_proc = -> { "cheeseburgers" }
+ @numerous.find(fail_proc) {|e| false }.should == "cheeseburgers"
+ end
+
+ it "doesn't call the ifnone proc if an element is found" do
+ fail_proc = -> { raise "This shouldn't have been called" }
+ @numerous.find(fail_proc) {|e| e == @elements.first }.should == 2
+ end
+
+ it "calls the ifnone proc only once when the block is false" do
+ times = 0
+ fail_proc = -> { times += 1; raise if times > 1; "cheeseburgers" }
+ @numerous.find(fail_proc) {|e| false }.should == "cheeseburgers"
+ end
+
+ it "calls the ifnone proc when there are no elements" do
+ fail_proc = -> { "yay" }
+ @empty.find(fail_proc) {|e| true}.should == "yay"
+ end
+
+ it "ignores the ifnone argument when nil" do
+ @numerous.find(nil) {|e| false }.should == nil
+ end
+
+ it "passes through the values yielded by #each_with_index" do
+ [:a, :b].each_with_index.find { |x, i| ScratchPad << [x, i]; nil }
+ ScratchPad.recorded.should == [[:a, 0], [:b, 1]]
+ end
+
+ it "returns an enumerator when no block given" do
+ @numerous.find.should.instance_of?(Enumerator)
+ end
+
+ it "passes the ifnone proc to the enumerator" do
+ times = 0
+ fail_proc = -> { times += 1; raise if times > 1; "cheeseburgers" }
+ @numerous.find(fail_proc).each {|e| false }.should == "cheeseburgers"
+ end
+
+ it "gathers whole arrays as elements when each yields multiple" do
+ multi = EnumerableSpecs::YieldsMulti.new
+ multi.find {|e| e == [1, 2] }.should == [1, 2]
+ end
+
+ it_behaves_like :enumerable_enumeratorized_with_unknown_size, :find
end
diff --git a/spec/ruby/core/enumerable/first_spec.rb b/spec/ruby/core/enumerable/first_spec.rb
index a85550ee3b..592dff1ebc 100644
--- a/spec/ruby/core/enumerable/first_spec.rb
+++ b/spec/ruby/core/enumerable/first_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/take', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/take'
describe "Enumerable#first" do
it "returns the first element" do
@@ -19,7 +19,7 @@ describe "Enumerable#first" do
it "raises a RangeError when passed a Bignum" do
enum = EnumerableSpecs::Empty.new
- lambda { enum.first(bignum_value) }.should raise_error(RangeError)
+ -> { enum.first(bignum_value) }.should.raise(RangeError)
end
describe "when passed an argument" do
diff --git a/spec/ruby/core/enumerable/fixtures/classes.rb b/spec/ruby/core/enumerable/fixtures/classes.rb
index 26a8aff8e2..b5feafcfb7 100644
--- a/spec/ruby/core/enumerable/fixtures/classes.rb
+++ b/spec/ruby/core/enumerable/fixtures/classes.rb
@@ -38,12 +38,14 @@ module EnumerableSpecs
class Empty
include Enumerable
def each
+ self
end
end
class EmptyWithSize
include Enumerable
def each
+ self
end
def size
0
@@ -118,7 +120,7 @@ module EnumerableSpecs
end
end
- class ArrayConvertable
+ class ArrayConvertible
attr_accessor :called
def initialize(*values)
@values = values
@@ -135,7 +137,7 @@ module EnumerableSpecs
end
end
- class EnumConvertable
+ class EnumConvertible
attr_accessor :called
attr_accessor :sym
def initialize(delegate)
@@ -251,7 +253,7 @@ module EnumerableSpecs
end
end
- class ComparableWithFixnum
+ class ComparableWithInteger
include Comparable
def initialize(num)
@num = num
@@ -328,4 +330,21 @@ module EnumerableSpecs
EnumerableMapping.new(self, block)
end
end
+
+ class Pattern
+ attr_reader :yielded
+
+ def initialize(&block)
+ @block = block
+ @yielded = []
+ end
+
+ def ===(*args)
+ @yielded << args
+ @block.call(*args)
+ end
+ end
+
+ class SetSubclass < Set
+ end
end # EnumerableSpecs utility classes
diff --git a/spec/ruby/core/enumerable/flat_map_spec.rb b/spec/ruby/core/enumerable/flat_map_spec.rb
index aaddeed05d..ef50cb2696 100644
--- a/spec/ruby/core/enumerable/flat_map_spec.rb
+++ b/spec/ruby/core/enumerable/flat_map_spec.rb
@@ -1,7 +1,56 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/collect_concat', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/enumerable_enumeratorized'
describe "Enumerable#flat_map" do
- it_behaves_like(:enumerable_collect_concat , :flat_map)
+ it "yields elements to the block and flattens one level" do
+ numerous = EnumerableSpecs::Numerous.new(1, [2, 3], [4, [5, 6]], {foo: :bar})
+ numerous.flat_map { |i| i }.should == [1, 2, 3, 4, [5, 6], {foo: :bar}]
+ end
+
+ it "appends non-Array elements that do not define #to_ary" do
+ obj = mock("to_ary undefined")
+
+ numerous = EnumerableSpecs::Numerous.new(1, obj, 2)
+ numerous.flat_map { |i| i }.should == [1, obj, 2]
+ end
+
+ it "concatenates the result of calling #to_ary if it returns an Array" do
+ obj = mock("to_ary defined")
+ obj.should_receive(:to_ary).and_return([:a, :b])
+
+ numerous = EnumerableSpecs::Numerous.new(1, obj, 2)
+ numerous.flat_map { |i| i }.should == [1, :a, :b, 2]
+ end
+
+ it "does not call #to_a" do
+ obj = mock("to_ary undefined")
+ obj.should_not_receive(:to_a)
+
+ numerous = EnumerableSpecs::Numerous.new(1, obj, 2)
+ numerous.flat_map { |i| i }.should == [1, obj, 2]
+ end
+
+ it "appends an element that defines #to_ary that returns nil" do
+ obj = mock("to_ary defined")
+ obj.should_receive(:to_ary).and_return(nil)
+
+ numerous = EnumerableSpecs::Numerous.new(1, obj, 2)
+ numerous.flat_map { |i| i }.should == [1, obj, 2]
+ end
+
+ it "raises a TypeError if an element defining #to_ary does not return an Array or nil" do
+ obj = mock("to_ary defined")
+ obj.should_receive(:to_ary).and_return("array")
+
+ -> { [1, obj, 3].flat_map { |i| i } }.should.raise(TypeError)
+ end
+
+ it "returns an enumerator when no block given" do
+ enum = EnumerableSpecs::Numerous.new(1, 2).flat_map
+ enum.should.instance_of?(Enumerator)
+ enum.each{ |i| [i] * i }.should == [1, 2, 2]
+ end
+
+ it_behaves_like :enumerable_enumeratorized_with_origin_size, :flat_map
end
diff --git a/spec/ruby/core/enumerable/grep_spec.rb b/spec/ruby/core/enumerable/grep_spec.rb
index 777d5e538e..965e183766 100644
--- a/spec/ruby/core/enumerable/grep_spec.rb
+++ b/spec/ruby/core/enumerable/grep_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Enumerable#grep" do
before :each do
@@ -29,6 +29,41 @@ describe "Enumerable#grep" do
ary.grep(/a(b)a/) { $1 }.should == ["b", "b"]
end
+ it "sets $~ in the block" do
+ "z" =~ /z/ # Reset $~
+ ["abc", "def"].grep(/b/) { |e|
+ e.should == "abc"
+ $&.should == "b"
+ }
+
+ # Set by the failed match of "def"
+ $~.should == nil
+ end
+
+ it "does not set $~ when given no block" do
+ "z" =~ /z/ # Reset $~
+ ["abc", "def"].grep(/b/).should == ["abc"]
+ $&.should == "z"
+ end
+
+ it "does not modify Regexp.last_match without block" do
+ "z" =~ /z/ # Reset last match
+ ["abc", "def"].grep(/b/).should == ["abc"]
+ Regexp.last_match[0].should == "z"
+ end
+
+ it "correctly handles non-string elements" do
+ 'set last match' =~ /set last (.*)/
+ [:a, 'b', 'z', :c, 42, nil].grep(/[a-d]/).should == [:a, 'b', :c]
+ $1.should == 'match'
+
+ o = Object.new
+ def o.to_str
+ 'hello'
+ end
+ [o].grep(/ll/).first.should.equal?(o)
+ end
+
describe "with a block" do
before :each do
@numerous = EnumerableSpecs::Numerous.new(*(0..9).to_a)
@@ -46,7 +81,7 @@ describe "Enumerable#grep" do
end
it "raises an ArgumentError when not given a pattern" do
- -> { @numerous.grep { |e| e } }.should raise_error(ArgumentError)
+ -> { @numerous.grep { |e| e } }.should.raise(ArgumentError)
end
end
end
diff --git a/spec/ruby/core/enumerable/grep_v_spec.rb b/spec/ruby/core/enumerable/grep_v_spec.rb
index 05c43a43ef..ee99a77ac1 100644
--- a/spec/ruby/core/enumerable/grep_v_spec.rb
+++ b/spec/ruby/core/enumerable/grep_v_spec.rb
@@ -1,43 +1,76 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-
-ruby_version_is "2.3" do
- describe "Enumerable#grep_v" do
- before :each do
- @numerous = EnumerableSpecs::Numerous.new(*(0..9).to_a)
- def (@odd_matcher = BasicObject.new).===(obj)
- obj.odd?
- end
- end
-
- describe "without block" do
- it "returns an Array of matched elements" do
- @numerous.grep_v(@odd_matcher).should == [0, 2, 4, 6, 8]
- end
-
- it "compares pattern with gathered array when yielded with multiple arguments" do
- (unmatcher = Object.new).stub!(:===).and_return(false)
- EnumerableSpecs::YieldsMixed2.new.grep_v(unmatcher).should == EnumerableSpecs::YieldsMixed2.gathered_yields
- end
-
- it "raises an ArgumentError when not given a pattern" do
- -> { @numerous.grep_v }.should raise_error(ArgumentError)
- end
- end
-
- describe "with block" do
- it "returns an Array of matched elements that mapped by the block" do
- @numerous.grep_v(@odd_matcher) { |n| n * 2 }.should == [0, 4, 8, 12, 16]
- end
-
- it "calls the block with gathered array when yielded with multiple arguments" do
- (unmatcher = Object.new).stub!(:===).and_return(false)
- EnumerableSpecs::YieldsMixed2.new.grep_v(unmatcher){ |e| e }.should == EnumerableSpecs::YieldsMixed2.gathered_yields
- end
-
- it "raises an ArgumentError when not given a pattern" do
- -> { @numerous.grep_v { |e| e } }.should raise_error(ArgumentError)
- end
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe "Enumerable#grep_v" do
+ before :each do
+ @numerous = EnumerableSpecs::Numerous.new(*(0..9).to_a)
+ def (@odd_matcher = BasicObject.new).===(obj)
+ obj.odd?
+ end
+ end
+
+ it "sets $~ in the block" do
+ "z" =~ /z/ # Reset $~
+ ["abc", "def"].grep_v(/e/) { |e|
+ e.should == "abc"
+ $~.should == nil
+ }
+
+ # Set by the match of "def"
+ $&.should == "e"
+ end
+
+ it "does not set $~ when given no block" do
+ "z" =~ /z/ # Reset $~
+ ["abc", "def"].grep_v(/e/).should == ["abc"]
+ $&.should == "z"
+ end
+
+ it "does not modify Regexp.last_match without block" do
+ "z" =~ /z/ # Reset last match
+ ["abc", "def"].grep_v(/e/).should == ["abc"]
+ Regexp.last_match[0].should == "z"
+ end
+
+ it "correctly handles non-string elements" do
+ 'set last match' =~ /set last (.*)/
+ [:a, 'b', 'z', :c, 42, nil].grep_v(/[a-d]/).should == ['z', 42, nil]
+ $1.should == 'match'
+
+ o = Object.new
+ def o.to_str
+ 'hello'
+ end
+ [o].grep_v(/mm/).first.should.equal?(o)
+ end
+
+ describe "without block" do
+ it "returns an Array of matched elements" do
+ @numerous.grep_v(@odd_matcher).should == [0, 2, 4, 6, 8]
+ end
+
+ it "compares pattern with gathered array when yielded with multiple arguments" do
+ (unmatcher = Object.new).stub!(:===).and_return(false)
+ EnumerableSpecs::YieldsMixed2.new.grep_v(unmatcher).should == EnumerableSpecs::YieldsMixed2.gathered_yields
+ end
+
+ it "raises an ArgumentError when not given a pattern" do
+ -> { @numerous.grep_v }.should.raise(ArgumentError)
+ end
+ end
+
+ describe "with block" do
+ it "returns an Array of matched elements that mapped by the block" do
+ @numerous.grep_v(@odd_matcher) { |n| n * 2 }.should == [0, 4, 8, 12, 16]
+ end
+
+ it "calls the block with gathered array when yielded with multiple arguments" do
+ (unmatcher = Object.new).stub!(:===).and_return(false)
+ EnumerableSpecs::YieldsMixed2.new.grep_v(unmatcher){ |e| e }.should == EnumerableSpecs::YieldsMixed2.gathered_yields
+ end
+
+ it "raises an ArgumentError when not given a pattern" do
+ -> { @numerous.grep_v { |e| e } }.should.raise(ArgumentError)
end
end
end
diff --git a/spec/ruby/core/enumerable/group_by_spec.rb b/spec/ruby/core/enumerable/group_by_spec.rb
index 3513512ebf..904e5d6c68 100644
--- a/spec/ruby/core/enumerable/group_by_spec.rb
+++ b/spec/ruby/core/enumerable/group_by_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/enumerable_enumeratorized', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/enumerable_enumeratorized'
describe "Enumerable#group_by" do
it "returns a hash with values grouped according to the block" do
@@ -16,13 +16,13 @@ describe "Enumerable#group_by" do
it "returns a hash without default_proc" do
e = EnumerableSpecs::Numerous.new("foo", "bar", "baz")
h = e.group_by { |word| word[0..0].to_sym }
- h[:some].should be_nil
- h.default_proc.should be_nil
- h.default.should be_nil
+ h[:some].should == nil
+ h.default_proc.should == nil
+ h.default.should == nil
end
it "returns an Enumerator if called without a block" do
- EnumerableSpecs::Numerous.new.group_by.should be_an_instance_of(Enumerator)
+ EnumerableSpecs::Numerous.new.group_by.should.instance_of?(Enumerator)
end
it "gathers whole arrays as elements when each yields multiple" do
@@ -33,13 +33,5 @@ describe "Enumerable#group_by" do
[3, 4, 5] => [[3, 4, 5]] }
end
- it "returns a tainted hash if self is tainted" do
- EnumerableSpecs::Empty.new.taint.group_by {}.tainted?.should be_true
- end
-
- it "returns an untrusted hash if self is untrusted" do
- EnumerableSpecs::Empty.new.untrust.group_by {}.untrusted?.should be_true
- end
-
it_behaves_like :enumerable_enumeratorized_with_origin_size, :group_by
end
diff --git a/spec/ruby/core/enumerable/include_spec.rb b/spec/ruby/core/enumerable/include_spec.rb
index 2cc0b6e83a..d59b351486 100644
--- a/spec/ruby/core/enumerable/include_spec.rb
+++ b/spec/ruby/core/enumerable/include_spec.rb
@@ -1,7 +1,36 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/include', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Enumerable#include?" do
- it_behaves_like(:enumerable_include, :include?)
+ it "returns true if any element == argument for numbers" do
+ class EnumerableSpecIncludeP; def ==(obj) obj == 5; end; end
+
+ elements = (0..5).to_a
+ EnumerableSpecs::Numerous.new(*elements).include?(5).should == true
+ EnumerableSpecs::Numerous.new(*elements).include?(10).should == false
+ EnumerableSpecs::Numerous.new(*elements).include?(EnumerableSpecIncludeP.new).should == true
+ end
+
+ it "returns true if any element == argument for other objects" do
+ class EnumerableSpecIncludeP11; def ==(obj); obj == '11'; end; end
+
+ elements = ('0'..'5').to_a + [EnumerableSpecIncludeP11.new]
+ EnumerableSpecs::Numerous.new(*elements).include?('5').should == true
+ EnumerableSpecs::Numerous.new(*elements).include?('10').should == false
+ EnumerableSpecs::Numerous.new(*elements).include?(EnumerableSpecIncludeP11.new).should == true
+ EnumerableSpecs::Numerous.new(*elements).include?('11').should == true
+ end
+
+
+ it "returns true if any member of enum equals obj when == compare different classes (legacy rubycon)" do
+ # equality is tested with ==
+ EnumerableSpecs::Numerous.new(2,4,6,8,10).include?(2.0).should == true
+ EnumerableSpecs::Numerous.new(2,4,[6,8],10).include?([6, 8]).should == true
+ EnumerableSpecs::Numerous.new(2,4,[6,8],10).include?([6.0, 8.0]).should == true
+ end
+
+ it "gathers whole arrays as elements when each yields multiple" do
+ multi = EnumerableSpecs::YieldsMulti.new
+ multi.include?([1,2]).should == true
+ end
end
diff --git a/spec/ruby/core/enumerable/inject_spec.rb b/spec/ruby/core/enumerable/inject_spec.rb
index 289a451552..10de321395 100644
--- a/spec/ruby/core/enumerable/inject_spec.rb
+++ b/spec/ruby/core/enumerable/inject_spec.rb
@@ -1,7 +1,144 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/inject', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../array/shared/iterable_and_tolerating_size_increasing'
+require_relative 'fixtures/classes'
describe "Enumerable#inject" do
- it_behaves_like :enumerable_inject, :inject
+ it "with argument takes a block with an accumulator (with argument as initial value) and the current element. Value of block becomes new accumulator" do
+ a = []
+ EnumerableSpecs::Numerous.new.inject(0) { |memo, i| a << [memo, i]; i }
+ a.should == [[0, 2], [2, 5], [5, 3], [3, 6], [6, 1], [1, 4]]
+ EnumerableSpecs::EachDefiner.new(true, true, true).inject(nil) {|result, i| i && result}.should == nil
+ end
+
+ it "produces an array of the accumulator and the argument when given a block with a *arg" do
+ a = []
+ [1,2].inject(0) {|*args| a << args; args[0] + args[1]}
+ a.should == [[0, 1], [1, 2]]
+ end
+
+ it "can take two argument" do
+ EnumerableSpecs::Numerous.new(1, 2, 3).inject(10, :-).should == 4
+ EnumerableSpecs::Numerous.new(1, 2, 3).inject(10, "-").should == 4
+
+ [1, 2, 3].inject(10, :-).should == 4
+ [1, 2, 3].inject(10, "-").should == 4
+ end
+
+ it "converts non-Symbol method name argument to String with #to_str if two arguments" do
+ name = Object.new
+ def name.to_str; "-"; end
+
+ EnumerableSpecs::Numerous.new(1, 2, 3).inject(10, name).should == 4
+ [1, 2, 3].inject(10, name).should == 4
+ end
+
+ it "raises TypeError when the second argument is not Symbol or String and it cannot be converted to String if two arguments" do
+ -> { EnumerableSpecs::Numerous.new(1, 2, 3).inject(10, Object.new) }.should.raise(TypeError, /is not a symbol nor a string/)
+ -> { [1, 2, 3].inject(10, Object.new) }.should.raise(TypeError, /is not a symbol nor a string/)
+ end
+
+ it "ignores the block if two arguments" do
+ -> {
+ EnumerableSpecs::Numerous.new(1, 2, 3).inject(10, :-) { raise "we never get here"}.should == 4
+ }.should complain(/#{__FILE__}:#{__LINE__-1}: warning: given block not used/, verbose: true)
+
+ -> {
+ [1, 2, 3].inject(10, :-) { raise "we never get here"}.should == 4
+ }.should complain(/#{__FILE__}:#{__LINE__-1}: warning: given block not used/, verbose: true)
+ end
+
+ it "does not warn when given a Symbol with $VERBOSE true" do
+ -> {
+ [1, 2].inject(0, :+)
+ [1, 2].inject(:+)
+ EnumerableSpecs::Numerous.new(1, 2).inject(0, :+)
+ EnumerableSpecs::Numerous.new(1, 2).inject(:+)
+ }.should_not complain(verbose: true)
+ end
+
+ it "can take a symbol argument" do
+ EnumerableSpecs::Numerous.new(10, 1, 2, 3).inject(:-).should == 4
+ [10, 1, 2, 3].inject(:-).should == 4
+ end
+
+ it "can take a String argument" do
+ EnumerableSpecs::Numerous.new(10, 1, 2, 3).inject("-").should == 4
+ [10, 1, 2, 3].inject("-").should == 4
+ end
+
+ it "converts non-Symbol method name argument to String with #to_str" do
+ name = Object.new
+ def name.to_str; "-"; end
+
+ EnumerableSpecs::Numerous.new(10, 1, 2, 3).inject(name).should == 4
+ [10, 1, 2, 3].inject(name).should == 4
+ end
+
+ it "raises TypeError when passed not Symbol or String method name argument and it cannot be converted to String" do
+ -> { EnumerableSpecs::Numerous.new(10, 1, 2, 3).inject(Object.new) }.should.raise(TypeError, /is not a symbol nor a string/)
+ -> { [10, 1, 2, 3].inject(Object.new) }.should.raise(TypeError, /is not a symbol nor a string/)
+ end
+
+ it "without argument takes a block with an accumulator (with first element as initial value) and the current element. Value of block becomes new accumulator" do
+ a = []
+ EnumerableSpecs::Numerous.new.inject { |memo, i| a << [memo, i]; i }
+ a.should == [[2, 5], [5, 3], [3, 6], [6, 1], [1, 4]]
+ end
+
+ it "gathers whole arrays as elements when each yields multiple" do
+ multi = EnumerableSpecs::YieldsMulti.new
+ multi.inject([]) {|acc, e| acc << e }.should == [[1, 2], [3, 4, 5], [6, 7, 8, 9]]
+ end
+
+ it "with inject arguments(legacy rubycon)" do
+ # with inject argument
+ EnumerableSpecs::EachDefiner.new().inject(1) {|acc,x| 999 }.should == 1
+ EnumerableSpecs::EachDefiner.new(2).inject(1) {|acc,x| 999 }.should == 999
+ EnumerableSpecs::EachDefiner.new(2).inject(1) {|acc,x| acc }.should == 1
+ EnumerableSpecs::EachDefiner.new(2).inject(1) {|acc,x| x }.should == 2
+
+ EnumerableSpecs::EachDefiner.new(1,2,3,4).inject(100) {|acc,x| acc + x }.should == 110
+ EnumerableSpecs::EachDefiner.new(1,2,3,4).inject(100) {|acc,x| acc * x }.should == 2400
+
+ EnumerableSpecs::EachDefiner.new('a','b','c').inject("z") {|result, i| i+result}.should == "cbaz"
+ end
+
+ it "without inject arguments(legacy rubycon)" do
+ # no inject argument
+ EnumerableSpecs::EachDefiner.new(2).inject {|acc,x| 999 }.should == 2
+ EnumerableSpecs::EachDefiner.new(2).inject {|acc,x| acc }.should == 2
+ EnumerableSpecs::EachDefiner.new(2).inject {|acc,x| x }.should == 2
+
+ EnumerableSpecs::EachDefiner.new(1,2,3,4).inject {|acc,x| acc + x }.should == 10
+ EnumerableSpecs::EachDefiner.new(1,2,3,4).inject {|acc,x| acc * x }.should == 24
+
+ EnumerableSpecs::EachDefiner.new('a','b','c').inject {|result, i| i+result}.should == "cba"
+ EnumerableSpecs::EachDefiner.new(3, 4, 5).inject {|result, i| result*i}.should == 60
+ EnumerableSpecs::EachDefiner.new([1], 2, 'a','b').inject {|r,i| r<<i}.should == [1, 2, 'a', 'b']
+ end
+
+ it "returns nil when fails(legacy rubycon)" do
+ EnumerableSpecs::EachDefiner.new().inject {|acc,x| 999 }.should == nil
+ end
+
+ it "tolerates increasing a collection size during iterating Array" do
+ array = [:a, :b, :c]
+ ScratchPad.record []
+ i = 0
+
+ array.inject(nil) do |_, e|
+ ScratchPad << e
+ array << i if i < 100
+ i += 1
+ end
+
+ actual = ScratchPad.recorded
+ expected = [:a, :b, :c] + (0..99).to_a
+ actual.sort_by(&:to_s).should == expected.sort_by(&:to_s)
+ end
+
+ it "raises an ArgumentError when no parameters or block is given" do
+ -> { [1,2].inject }.should.raise(ArgumentError)
+ -> { {one: 1, two: 2}.inject }.should.raise(ArgumentError)
+ end
end
diff --git a/spec/ruby/core/enumerable/lazy_spec.rb b/spec/ruby/core/enumerable/lazy_spec.rb
index f989fb947e..935e574067 100644
--- a/spec/ruby/core/enumerable/lazy_spec.rb
+++ b/spec/ruby/core/enumerable/lazy_spec.rb
@@ -1,10 +1,10 @@
# -*- encoding: us-ascii -*-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Enumerable#lazy" do
it "returns an instance of Enumerator::Lazy" do
- EnumerableSpecs::Numerous.new.lazy.should be_an_instance_of(Enumerator::Lazy)
+ EnumerableSpecs::Numerous.new.lazy.should.instance_of?(Enumerator::Lazy)
end
end
diff --git a/spec/ruby/core/enumerable/map_spec.rb b/spec/ruby/core/enumerable/map_spec.rb
index b2ddf1eb9d..e6447f5c23 100644
--- a/spec/ruby/core/enumerable/map_spec.rb
+++ b/spec/ruby/core/enumerable/map_spec.rb
@@ -1,7 +1,109 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/collect', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/enumerable_enumeratorized'
describe "Enumerable#map" do
- it_behaves_like(:enumerable_collect , :map)
+ before :each do
+ ScratchPad.record []
+ end
+
+ it "returns a new array with the results of passing each element to block" do
+ entries = [0, 1, 3, 4, 5, 6]
+ numerous = EnumerableSpecs::Numerous.new(*entries)
+ numerous.map { |i| i % 2 }.should == [0, 1, 1, 0, 1, 0]
+ numerous.map { |i| i }.should == entries
+ end
+
+ it "passes through the values yielded by #each_with_index" do
+ [:a, :b].each_with_index.map { |x, i| ScratchPad << [x, i]; nil }
+ ScratchPad.recorded.should == [[:a, 0], [:b, 1]]
+ end
+
+ it "gathers initial args as elements when each yields multiple" do
+ multi = EnumerableSpecs::YieldsMulti.new
+ multi.map {|e| e}.should == [1,3,6]
+ end
+
+ it "only yields increasing values for a Range" do
+ (1..0).map { |x| x }.should == []
+ (1..1).map { |x| x }.should == [1]
+ (1..2).map { |x| x }.should == [1, 2]
+ end
+
+ it "returns an enumerator when no block given" do
+ enum = EnumerableSpecs::Numerous.new.map
+ enum.should.instance_of?(Enumerator)
+ enum.each { |i| -i }.should == [-2, -5, -3, -6, -1, -4]
+ end
+
+ it "reports the same arity as the given block" do
+ entries = [0, 1, 3, 4, 5, 6]
+ numerous = EnumerableSpecs::Numerous.new(*entries)
+
+ def numerous.each(&block)
+ ScratchPad << block.arity
+ super
+ end
+
+ numerous.map { |a, b| a % 2 }.should == [0, 1, 1, 0, 1, 0]
+ ScratchPad.recorded.should == [2]
+ ScratchPad.clear
+ ScratchPad.record []
+ numerous.map { |i| i }.should == entries
+ ScratchPad.recorded.should == [1]
+ end
+
+ it "yields an Array of 2 elements for a Hash when block arity is 1" do
+ c = Class.new do
+ def register(a)
+ ScratchPad << a
+ end
+ end
+ m = c.new.method(:register)
+
+ ScratchPad.record []
+ { 1 => 'a', 2 => 'b' }.map(&m)
+ ScratchPad.recorded.should == [[1, 'a'], [2, 'b']]
+ end
+
+ it "yields 2 arguments for a Hash when block arity is 2" do
+ c = Class.new do
+ def register(a, b)
+ ScratchPad << [a, b]
+ end
+ end
+ m = c.new.method(:register)
+
+ ScratchPad.record []
+ { 1 => 'a', 2 => 'b' }.map(&m)
+ ScratchPad.recorded.should == [[1, 'a'], [2, 'b']]
+ end
+
+ it "raises an error for a Hash when an arity enforcing block of arity >2 is passed in" do
+ c = Class.new do
+ def register(a, b, c)
+ end
+ end
+ m = c.new.method(:register)
+
+ -> do
+ { 1 => 'a', 2 => 'b' }.map(&m)
+ end.should.raise(ArgumentError)
+ end
+
+ it "calls the each method on sub-classes" do
+ c = Class.new(Hash) do
+ def each
+ ScratchPad << 'in each'
+ super
+ end
+ end
+ h = c.new
+ h[1] = 'a'
+ ScratchPad.record []
+ h.map { |k,v| v }
+ ScratchPad.recorded.should == ['in each']
+ end
+
+ it_behaves_like :enumerable_enumeratorized_with_origin_size, :map
end
diff --git a/spec/ruby/core/enumerable/max_by_spec.rb b/spec/ruby/core/enumerable/max_by_spec.rb
index 4058cf0a40..f67b5d15ea 100644
--- a/spec/ruby/core/enumerable/max_by_spec.rb
+++ b/spec/ruby/core/enumerable/max_by_spec.rb
@@ -1,10 +1,10 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/enumerable_enumeratorized', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/enumerable_enumeratorized'
describe "Enumerable#max_by" do
it "returns an enumerator if no block" do
- EnumerableSpecs::Numerous.new(42).max_by.should be_an_instance_of(Enumerator)
+ EnumerableSpecs::Numerous.new(42).max_by.should.instance_of?(Enumerator)
end
it "returns nil if #each yields no objects" do
@@ -18,7 +18,7 @@ describe "Enumerable#max_by" do
it "returns the object that appears first in #each in case of a tie" do
a, b, c = '1', '2', '2'
- EnumerableSpecs::Numerous.new(a, b, c).max_by {|obj| obj.to_i }.should equal(b)
+ EnumerableSpecs::Numerous.new(a, b, c).max_by {|obj| obj.to_i }.should.equal?(b)
end
it "uses max.<=>(current) to determine order" do
@@ -48,7 +48,7 @@ describe "Enumerable#max_by" do
context "without a block" do
it "returns an enumerator" do
- @enum.max_by(2).should be_an_instance_of(Enumerator)
+ @enum.max_by(2).should.instance_of?(Enumerator)
end
end
@@ -67,7 +67,7 @@ describe "Enumerable#max_by" do
context "when n is negative" do
it "raises an ArgumentError" do
- lambda { @enum.max_by(-1) { |i| i.to_s } }.should raise_error(ArgumentError)
+ -> { @enum.max_by(-1) { |i| i.to_s } }.should.raise(ArgumentError)
end
end
end
diff --git a/spec/ruby/core/enumerable/max_spec.rb b/spec/ruby/core/enumerable/max_spec.rb
index e283a5d0e2..d92700258b 100644
--- a/spec/ruby/core/enumerable/max_spec.rb
+++ b/spec/ruby/core/enumerable/max_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Enumerable#max" do
before :each do
@@ -36,18 +36,18 @@ describe "Enumerable#max" do
end
it "raises a NoMethodError for elements without #<=>" do
- lambda do
+ -> do
EnumerableSpecs::EachDefiner.new(BasicObject.new, BasicObject.new).max
- end.should raise_error(NoMethodError)
+ end.should.raise(NoMethodError)
end
it "raises an ArgumentError for incomparable elements" do
- lambda do
+ -> do
EnumerableSpecs::EachDefiner.new(11,"22").max
- end.should raise_error(ArgumentError)
- lambda do
+ end.should.raise(ArgumentError)
+ -> do
EnumerableSpecs::EachDefiner.new(11,12,22,33).max{|a, b| nil}
- end.should raise_error(ArgumentError)
+ end.should.raise(ArgumentError)
end
context "when passed a block" do
@@ -106,7 +106,7 @@ describe "Enumerable#max" do
context "that is negative" do
it "raises an ArgumentError" do
- lambda { @e_ints.max(-1) }.should raise_error(ArgumentError)
+ -> { @e_ints.max(-1) }.should.raise(ArgumentError)
end
end
end
diff --git a/spec/ruby/core/enumerable/member_spec.rb b/spec/ruby/core/enumerable/member_spec.rb
index 862c949817..be06880ebb 100644
--- a/spec/ruby/core/enumerable/member_spec.rb
+++ b/spec/ruby/core/enumerable/member_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/include', __FILE__)
+require_relative '../../spec_helper'
describe "Enumerable#member?" do
- it_behaves_like(:enumerable_include, :member?)
+ it "is an alias of Enumerable#include?" do
+ Enumerable.instance_method(:member?).should == Enumerable.instance_method(:include?)
+ end
end
diff --git a/spec/ruby/core/enumerable/min_by_spec.rb b/spec/ruby/core/enumerable/min_by_spec.rb
index 24fe995f09..4f949e2130 100644
--- a/spec/ruby/core/enumerable/min_by_spec.rb
+++ b/spec/ruby/core/enumerable/min_by_spec.rb
@@ -1,10 +1,10 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/enumerable_enumeratorized', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/enumerable_enumeratorized'
describe "Enumerable#min_by" do
it "returns an enumerator if no block" do
- EnumerableSpecs::Numerous.new(42).min_by.should be_an_instance_of(Enumerator)
+ EnumerableSpecs::Numerous.new(42).min_by.should.instance_of?(Enumerator)
end
it "returns nil if #each yields no objects" do
@@ -18,7 +18,7 @@ describe "Enumerable#min_by" do
it "returns the object that appears first in #each in case of a tie" do
a, b, c = '2', '1', '1'
- EnumerableSpecs::Numerous.new(a, b, c).min_by {|obj| obj.to_i }.should equal(b)
+ EnumerableSpecs::Numerous.new(a, b, c).min_by {|obj| obj.to_i }.should.equal?(b)
end
it "uses min.<=>(current) to determine order" do
@@ -48,7 +48,7 @@ describe "Enumerable#min_by" do
context "without a block" do
it "returns an enumerator" do
- @enum.min_by(2).should be_an_instance_of(Enumerator)
+ @enum.min_by(2).should.instance_of?(Enumerator)
end
end
@@ -67,7 +67,7 @@ describe "Enumerable#min_by" do
context "when n is negative" do
it "raises an ArgumentError" do
- lambda { @enum.min_by(-1) { |i| i.to_s } }.should raise_error(ArgumentError)
+ -> { @enum.min_by(-1) { |i| i.to_s } }.should.raise(ArgumentError)
end
end
end
diff --git a/spec/ruby/core/enumerable/min_spec.rb b/spec/ruby/core/enumerable/min_spec.rb
index f56d0420c9..f05d59c2c9 100644
--- a/spec/ruby/core/enumerable/min_spec.rb
+++ b/spec/ruby/core/enumerable/min_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Enumerable#min" do
before :each do
@@ -32,22 +32,22 @@ describe "Enumerable#min" do
end
it "returns nil for an empty Enumerable" do
- EnumerableSpecs::EachDefiner.new.min.should be_nil
+ EnumerableSpecs::EachDefiner.new.min.should == nil
end
it "raises a NoMethodError for elements without #<=>" do
- lambda do
+ -> do
EnumerableSpecs::EachDefiner.new(BasicObject.new, BasicObject.new).min
- end.should raise_error(NoMethodError)
+ end.should.raise(NoMethodError)
end
it "raises an ArgumentError for incomparable elements" do
- lambda do
+ -> do
EnumerableSpecs::EachDefiner.new(11,"22").min
- end.should raise_error(ArgumentError)
- lambda do
+ end.should.raise(ArgumentError)
+ -> do
EnumerableSpecs::EachDefiner.new(11,12,22,33).min{|a, b| nil}
- end.should raise_error(ArgumentError)
+ end.should.raise(ArgumentError)
end
it "returns the minimum when using a block rule" do
@@ -110,7 +110,7 @@ describe "Enumerable#min" do
context "that is negative" do
it "raises an ArgumentError" do
- lambda { @e_ints.min(-1) }.should raise_error(ArgumentError)
+ -> { @e_ints.min(-1) }.should.raise(ArgumentError)
end
end
end
diff --git a/spec/ruby/core/enumerable/minmax_by_spec.rb b/spec/ruby/core/enumerable/minmax_by_spec.rb
index c92eb381a4..30c88cfcfb 100644
--- a/spec/ruby/core/enumerable/minmax_by_spec.rb
+++ b/spec/ruby/core/enumerable/minmax_by_spec.rb
@@ -1,10 +1,10 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/enumerable_enumeratorized', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/enumerable_enumeratorized'
describe "Enumerable#minmax_by" do
it "returns an enumerator if no block" do
- EnumerableSpecs::Numerous.new(42).minmax_by.should be_an_instance_of(Enumerator)
+ EnumerableSpecs::Numerous.new(42).minmax_by.should.instance_of?(Enumerator)
end
it "returns nil if #each yields no objects" do
@@ -19,8 +19,8 @@ describe "Enumerable#minmax_by" do
it "returns the object that appears first in #each in case of a tie" do
a, b, c, d = '1', '1', '2', '2'
mm = EnumerableSpecs::Numerous.new(a, b, c, d).minmax_by {|obj| obj.to_i }
- mm[0].should equal(a)
- mm[1].should equal(c)
+ mm[0].should.equal?(a)
+ mm[1].should.equal?(c)
end
it "uses min/max.<=>(current) to determine order" do
diff --git a/spec/ruby/core/enumerable/minmax_spec.rb b/spec/ruby/core/enumerable/minmax_spec.rb
index 10bc9b68e4..f5f17ef079 100644
--- a/spec/ruby/core/enumerable/minmax_spec.rb
+++ b/spec/ruby/core/enumerable/minmax_spec.rb
@@ -1,41 +1,17 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative '../../shared/enumerable/minmax'
describe "Enumerable#minmax" do
before :each do
@enum = EnumerableSpecs::Numerous.new(6, 4, 5, 10, 8)
-
+ @empty_enum = EnumerableSpecs::Empty.new
+ @incomparable_enum = EnumerableSpecs::Numerous.new(BasicObject.new, BasicObject.new)
+ @incompatible_enum = EnumerableSpecs::Numerous.new(11,"22")
@strs = EnumerableSpecs::Numerous.new("333", "2", "60", "55555", "1010", "111")
end
- it "min should return the minimum element" do
- @enum.minmax.should == [4, 10]
- @strs.minmax.should == ["1010", "60" ]
- end
-
- it "returns [nil, nil] for an empty Enumerable" do
- EnumerableSpecs::Empty.new.minmax.should == [nil, nil]
- end
-
- it "raises an ArgumentError when elements are incomparable" do
- lambda do
- EnumerableSpecs::Numerous.new(11,"22").minmax
- end.should raise_error(ArgumentError)
- lambda do
- EnumerableSpecs::Numerous.new(11,12,22,33).minmax{|a, b| nil}
- end.should raise_error(ArgumentError)
- end
-
- it "raises a NoMethodError for elements without #<=>" do
- lambda do
- EnumerableSpecs::Numerous.new(BasicObject.new, BasicObject.new).minmax
- end.should raise_error(NoMethodError)
- end
-
- it "returns the minimum when using a block rule" do
- @enum.minmax {|a,b| b <=> a }.should == [10, 4]
- @strs.minmax {|a,b| a.length <=> b.length }.should == ["2", "55555"]
- end
+ it_behaves_like :enumerable_minmax, :minmax
it "gathers whole arrays as elements when each yields multiple" do
multi = EnumerableSpecs::YieldsMulti.new
diff --git a/spec/ruby/core/enumerable/none_spec.rb b/spec/ruby/core/enumerable/none_spec.rb
index 0646c13b34..d9ee0b441e 100644
--- a/spec/ruby/core/enumerable/none_spec.rb
+++ b/spec/ruby/core/enumerable/none_spec.rb
@@ -1,57 +1,153 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Enumerable#none?" do
- it "returns true if none of the elements in self are true" do
- e = EnumerableSpecs::Numerous.new(false, nil, false)
- e.none?.should be_true
+ before :each do
+ @empty = EnumerableSpecs::Empty.new
+ @enum = EnumerableSpecs::Numerous.new
+ @enum1 = EnumerableSpecs::Numerous.new(0, 1, 2, -1)
+ @enum2 = EnumerableSpecs::Numerous.new(nil, false, true)
end
- it "returns false if at least one of the elements in self are true" do
- e = EnumerableSpecs::Numerous.new(false, nil, true, false)
- e.none?.should be_false
+ it "always returns true on empty enumeration" do
+ @empty.should.none?
+ @empty.none? { true }.should == true
end
- it "gathers whole arrays as elements when each yields multiple" do
- multi = EnumerableSpecs::YieldsMultiWithFalse.new
- multi.none?.should be_false
+ it "raises an ArgumentError when more than 1 argument is provided" do
+ -> { @enum.none?(1, 2, 3) }.should.raise(ArgumentError)
+ -> { [].none?(1, 2, 3) }.should.raise(ArgumentError)
+ -> { {}.none?(1, 2, 3) }.should.raise(ArgumentError)
end
-end
-describe "Enumerable#none? with a block" do
- before :each do
- @e = EnumerableSpecs::Numerous.new(1,1,2,3,4)
- end
+ it "does not hide exceptions out of #each" do
+ -> {
+ EnumerableSpecs::ThrowingEach.new.none?
+ }.should.raise(RuntimeError)
- it "passes each element to the block in turn until it returns true" do
- acc = []
- @e.none? {|e| acc << e; false }
- acc.should == [1,1,2,3,4]
+ -> {
+ EnumerableSpecs::ThrowingEach.new.none? { false }
+ }.should.raise(RuntimeError)
end
- it "stops passing elements to the block when it returns true" do
- acc = []
- @e.none? {|e| acc << e; e == 3 ? true : false }
- acc.should == [1,1,2,3]
- end
+ describe "with no block" do
+ it "returns true if none of the elements in self are true" do
+ e = EnumerableSpecs::Numerous.new(false, nil, false)
+ e.none?.should == true
+ end
- it "returns true if the block never returns true" do
- @e.none? {|e| false }.should be_true
- end
+ it "returns false if at least one of the elements in self are true" do
+ e = EnumerableSpecs::Numerous.new(false, nil, true, false)
+ e.none?.should == false
+ end
- it "returns false if the block ever returns true" do
- @e.none? {|e| e == 3 ? true : false }.should be_false
+ it "gathers whole arrays as elements when each yields multiple" do
+ multi = EnumerableSpecs::YieldsMultiWithFalse.new
+ multi.none?.should == false
+ end
end
- it "gathers initial args as elements when each yields multiple" do
- multi = EnumerableSpecs::YieldsMulti.new
- multi.none? {|e| e == [1, 2] }.should be_true
+ describe "with a block" do
+ before :each do
+ @e = EnumerableSpecs::Numerous.new(1,1,2,3,4)
+ end
+
+ it "passes each element to the block in turn until it returns true" do
+ acc = []
+ @e.none? {|e| acc << e; false }
+ acc.should == [1,1,2,3,4]
+ end
+
+ it "stops passing elements to the block when it returns true" do
+ acc = []
+ @e.none? {|e| acc << e; e == 3 ? true : false }
+ acc.should == [1,1,2,3]
+ end
+
+ it "returns true if the block never returns true" do
+ @e.none? {|e| false }.should == true
+ end
+
+ it "returns false if the block ever returns true" do
+ @e.none? {|e| e == 3 ? true : false }.should == false
+ end
+
+ it "does not hide exceptions out of the block" do
+ -> {
+ @enum.none? { raise "from block" }
+ }.should.raise(RuntimeError)
+ end
+
+ it "gathers initial args as elements when each yields multiple" do
+ multi = EnumerableSpecs::YieldsMulti.new
+ yielded = []
+ multi.none? { |e| yielded << e; false }
+ yielded.should == [1, 3, 6]
+ end
+
+ it "yields multiple arguments when each yields multiple" do
+ multi = EnumerableSpecs::YieldsMulti.new
+ yielded = []
+ multi.none? { |*args| yielded << args; false }
+ yielded.should == [[1, 2], [3, 4, 5], [6, 7, 8, 9]]
+ end
end
- it "yields multiple arguments when each yields multiple" do
- multi = EnumerableSpecs::YieldsMulti.new
- yielded = []
- multi.none? {|e, i| yielded << [e, i] }
- yielded.should == [[1, 2]]
+ describe 'when given a pattern argument' do
+ it "calls `===` on the pattern the return value" do
+ pattern = EnumerableSpecs::Pattern.new { |x| x == 3 }
+ @enum1.none?(pattern).should == true
+ pattern.yielded.should == [[0], [1], [2], [-1]]
+ end
+
+ it "always returns true on empty enumeration" do
+ @empty.none?(Integer).should == true
+ [].none?(Integer).should == true
+ {}.none?(NilClass).should == true
+ end
+
+ it "does not hide exceptions out of #each" do
+ -> {
+ EnumerableSpecs::ThrowingEach.new.none?(Integer)
+ }.should.raise(RuntimeError)
+ end
+
+ it "returns true if the pattern never returns a truthy value" do
+ @enum2.none?(Integer).should == true
+ pattern = EnumerableSpecs::Pattern.new { |x| nil }
+ @enum.none?(pattern).should == true
+
+ [1, 42, 3].none?(pattern).should == true
+ {a: 1, b: 2}.none?(pattern).should == true
+ end
+
+ it "returns false if the pattern ever returns other than false or nil" do
+ pattern = EnumerableSpecs::Pattern.new { |x| x < 0 }
+ @enum1.none?(pattern).should == false
+ pattern.yielded.should == [[0], [1], [2], [-1]]
+
+ [1, 2, 3, -1].none?(pattern).should == false
+ {a: 1}.none?(Array).should == false
+ end
+
+ it "does not hide exceptions out of pattern#===" do
+ pattern = EnumerableSpecs::Pattern.new { raise "from pattern" }
+ -> {
+ @enum.none?(pattern)
+ }.should.raise(RuntimeError)
+ end
+
+ it "calls the pattern with gathered array when yielded with multiple arguments" do
+ multi = EnumerableSpecs::YieldsMulti.new
+ pattern = EnumerableSpecs::Pattern.new { false }
+ multi.none?(pattern).should == true
+ pattern.yielded.should == [[[1, 2]], [[3, 4, 5]], [[6, 7, 8, 9]]]
+ end
+
+ it "ignores the block if there is an argument" do
+ -> {
+ EnumerableSpecs::Numerous.new(1, 2, 3, 4, 5).none?(String) { true }.should == true
+ }.should complain(/given block not used/)
+ end
end
end
diff --git a/spec/ruby/core/enumerable/one_spec.rb b/spec/ruby/core/enumerable/one_spec.rb
index 818d4663a4..cf966d4a9b 100644
--- a/spec/ruby/core/enumerable/one_spec.rb
+++ b/spec/ruby/core/enumerable/one_spec.rb
@@ -1,49 +1,154 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Enumerable#one?" do
- describe "when passed a block" do
+ before :each do
+ @empty = EnumerableSpecs::Empty.new
+ @enum = EnumerableSpecs::Numerous.new
+ @enum1 = EnumerableSpecs::Numerous.new(0, 1, 2, -1)
+ @enum2 = EnumerableSpecs::Numerous.new(nil, false, true)
+ end
+
+ it "always returns false on empty enumeration" do
+ @empty.should_not.one?
+ @empty.one? { true }.should == false
+ end
+
+ it "raises an ArgumentError when more than 1 argument is provided" do
+ -> { @enum.one?(1, 2, 3) }.should.raise(ArgumentError)
+ -> { [].one?(1, 2, 3) }.should.raise(ArgumentError)
+ -> { {}.one?(1, 2, 3) }.should.raise(ArgumentError)
+ end
+
+ it "does not hide exceptions out of #each" do
+ -> {
+ EnumerableSpecs::ThrowingEach.new.one?
+ }.should.raise(RuntimeError)
+
+ -> {
+ EnumerableSpecs::ThrowingEach.new.one? { false }
+ }.should.raise(RuntimeError)
+ end
+
+ describe "with no block" do
+ it "returns true if only one element evaluates to true" do
+ [false, nil, true].one?.should == true
+ end
+
+ it "returns false if two elements evaluate to true" do
+ [false, :value, nil, true].one?.should == false
+ end
+
+ it "returns false if all elements evaluate to false" do
+ [false, nil, false].one?.should == false
+ end
+
+ it "gathers whole arrays as elements when each yields multiple" do
+ multi = EnumerableSpecs::YieldsMultiWithSingleTrue.new
+ multi.one?.should == false
+ end
+ end
+
+ describe "with a block" do
it "returns true if block returns true once" do
- [:a, :b, :c].one? { |s| s == :a }.should be_true
+ [:a, :b, :c].one? { |s| s == :a }.should == true
end
it "returns false if the block returns true more than once" do
- [:a, :b, :c].one? { |s| s == :a || s == :b }.should be_false
+ [:a, :b, :c].one? { |s| s == :a || s == :b }.should == false
end
it "returns false if the block only returns false" do
- [:a, :b, :c].one? { |s| s == :d }.should be_false
+ [:a, :b, :c].one? { |s| s == :d }.should == false
+ end
+
+ it "does not hide exceptions out of the block" do
+ -> {
+ @enum.one? { raise "from block" }
+ }.should.raise(RuntimeError)
end
it "gathers initial args as elements when each yields multiple" do
multi = EnumerableSpecs::YieldsMulti.new
- multi.one? {|e| e == 1 }.should be_true
+ yielded = []
+ multi.one? { |e| yielded << e; false }.should == false
+ yielded.should == [1, 3, 6]
end
it "yields multiple arguments when each yields multiple" do
multi = EnumerableSpecs::YieldsMulti.new
yielded = []
- multi.one? {|e, i| yielded << [e, i] }
- yielded.should == [[1, 2], [3, 4]]
+ multi.one? { |*args| yielded << args; false }.should == false
+ yielded.should == [[1, 2], [3, 4, 5], [6, 7, 8, 9]]
end
end
- describe "when not passed a block" do
- it "returns true if only one element evaluates to true" do
- [false, nil, true].one?.should be_true
+ describe 'when given a pattern argument' do
+ it "calls `===` on the pattern the return value" do
+ pattern = EnumerableSpecs::Pattern.new { |x| x == 1 }
+ @enum1.one?(pattern).should == true
+ pattern.yielded.should == [[0], [1], [2], [-1]]
end
- it "returns false if two elements evaluate to true" do
- [false, :value, nil, true].one?.should be_false
+ it "always returns false on empty enumeration" do
+ @empty.one?(Integer).should == false
+ [].one?(Integer).should == false
+ {}.one?(NilClass).should == false
end
- it "returns false if all elements evaluate to false" do
- [false, nil, false].one?.should be_false
+ it "does not hide exceptions out of #each" do
+ -> {
+ EnumerableSpecs::ThrowingEach.new.one?(Integer)
+ }.should.raise(RuntimeError)
end
- it "gathers whole arrays as elements when each yields multiple" do
- multi = EnumerableSpecs::YieldsMultiWithSingleTrue.new
- multi.one?.should be_false
+ it "returns true if the pattern returns a truthy value only once" do
+ @enum2.one?(NilClass).should == true
+ pattern = EnumerableSpecs::Pattern.new { |x| x == 2 }
+ @enum1.one?(pattern).should == true
+
+ [1, 2, 42, 3].one?(pattern).should == true
+
+ pattern = EnumerableSpecs::Pattern.new { |x| x == [:b, 2] }
+ {a: 1, b: 2}.one?(pattern).should == true
+ end
+
+ it "returns false if the pattern returns a truthy value more than once" do
+ pattern = EnumerableSpecs::Pattern.new { |x| !x }
+ @enum2.one?(pattern).should == false
+ pattern.yielded.should == [[nil], [false]]
+
+ [1, 2, 3].one?(Integer).should == false
+ {a: 1, b: 2}.one?(Array).should == false
+ end
+
+ it "returns false if the pattern never returns a truthy value" do
+ pattern = EnumerableSpecs::Pattern.new { |x| nil }
+ @enum1.one?(pattern).should == false
+ pattern.yielded.should == [[0], [1], [2], [-1]]
+
+ [1, 2, 3].one?(pattern).should == false
+ {a: 1}.one?(pattern).should == false
+ end
+
+ it "does not hide exceptions out of pattern#===" do
+ pattern = EnumerableSpecs::Pattern.new { raise "from pattern" }
+ -> {
+ @enum.one?(pattern)
+ }.should.raise(RuntimeError)
+ end
+
+ it "calls the pattern with gathered array when yielded with multiple arguments" do
+ multi = EnumerableSpecs::YieldsMulti.new
+ pattern = EnumerableSpecs::Pattern.new { false }
+ multi.one?(pattern).should == false
+ pattern.yielded.should == [[[1, 2]], [[3, 4, 5]], [[6, 7, 8, 9]]]
+ end
+
+ it "ignores the block if there is an argument" do
+ -> {
+ EnumerableSpecs::Numerous.new(1, 2, 3, 4, "5").one?(String) { false }.should == true
+ }.should complain(/given block not used/)
end
end
end
diff --git a/spec/ruby/core/enumerable/partition_spec.rb b/spec/ruby/core/enumerable/partition_spec.rb
index 4319a9328f..8272ee189e 100644
--- a/spec/ruby/core/enumerable/partition_spec.rb
+++ b/spec/ruby/core/enumerable/partition_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/enumerable_enumeratorized', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/enumerable_enumeratorized'
describe "Enumerable#partition" do
it "returns two arrays, the first containing elements for which the block is true, the second containing the rest" do
@@ -8,7 +8,7 @@ describe "Enumerable#partition" do
end
it "returns an Enumerator if called without a block" do
- EnumerableSpecs::Numerous.new.partition.should be_an_instance_of(Enumerator)
+ EnumerableSpecs::Numerous.new.partition.should.instance_of?(Enumerator)
end
it "gathers whole arrays as elements when each yields multiple" do
diff --git a/spec/ruby/core/enumerable/reduce_spec.rb b/spec/ruby/core/enumerable/reduce_spec.rb
index 8afecb2a8e..40452b66a1 100644
--- a/spec/ruby/core/enumerable/reduce_spec.rb
+++ b/spec/ruby/core/enumerable/reduce_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/inject', __FILE__)
+require_relative '../../spec_helper'
describe "Enumerable#reduce" do
- it_behaves_like :enumerable_inject, :reduce
+ it "is an alias of Enumerable#inject" do
+ Enumerable.instance_method(:reduce).should == Enumerable.instance_method(:inject)
+ end
end
diff --git a/spec/ruby/core/enumerable/reject_spec.rb b/spec/ruby/core/enumerable/reject_spec.rb
index 3dbfb07067..31e89f5b0e 100644
--- a/spec/ruby/core/enumerable/reject_spec.rb
+++ b/spec/ruby/core/enumerable/reject_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/enumerable_enumeratorized', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/enumerable_enumeratorized'
describe "Enumerable#reject" do
it "returns an array of the elements for which block is false" do
@@ -13,7 +13,7 @@ describe "Enumerable#reject" do
end
it "returns an Enumerator if called without a block" do
- EnumerableSpecs::Numerous.new.reject.should be_an_instance_of(Enumerator)
+ EnumerableSpecs::Numerous.new.reject.should.instance_of?(Enumerator)
end
it "gathers whole arrays as elements when each yields multiple" do
diff --git a/spec/ruby/core/enumerable/reverse_each_spec.rb b/spec/ruby/core/enumerable/reverse_each_spec.rb
index 62c3c0daef..4753956724 100644
--- a/spec/ruby/core/enumerable/reverse_each_spec.rb
+++ b/spec/ruby/core/enumerable/reverse_each_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/enumerable_enumeratorized', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/enumerable_enumeratorized'
describe "Enumerable#reverse_each" do
it "traverses enum in reverse order and pass each element to block" do
@@ -11,7 +11,7 @@ describe "Enumerable#reverse_each" do
it "returns an Enumerator if no block given" do
enum = EnumerableSpecs::Numerous.new.reverse_each
- enum.should be_an_instance_of(Enumerator)
+ enum.should.instance_of?(Enumerator)
enum.to_a.should == [4, 1, 6, 3, 5, 2]
end
diff --git a/spec/ruby/core/enumerable/select_spec.rb b/spec/ruby/core/enumerable/select_spec.rb
index b4da35c754..a53c228a44 100644
--- a/spec/ruby/core/enumerable/select_spec.rb
+++ b/spec/ruby/core/enumerable/select_spec.rb
@@ -1,7 +1,33 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/find_all', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/enumerable_enumeratorized'
describe "Enumerable#select" do
- it_behaves_like(:enumerable_find_all , :select)
+ before :each do
+ ScratchPad.record []
+ @elements = (1..10).to_a
+ @numerous = EnumerableSpecs::Numerous.new(*@elements)
+ end
+
+ it "returns all elements for which the block is not false" do
+ @numerous.select {|i| i % 3 == 0 }.should == [3, 6, 9]
+ @numerous.select {|i| true }.should == @elements
+ @numerous.select {|i| false }.should == []
+ end
+
+ it "returns an enumerator when no block given" do
+ @numerous.select.should.instance_of?(Enumerator)
+ end
+
+ it "passes through the values yielded by #each_with_index" do
+ [:a, :b].each_with_index.select { |x, i| ScratchPad << [x, i] }
+ ScratchPad.recorded.should == [[:a, 0], [:b, 1]]
+ end
+
+ it "gathers whole arrays as elements when each yields multiple" do
+ multi = EnumerableSpecs::YieldsMulti.new
+ multi.select {|e| e == [3, 4, 5] }.should == [[3, 4, 5]]
+ end
+
+ it_behaves_like :enumerable_enumeratorized_with_origin_size, :select
end
diff --git a/spec/ruby/core/enumerable/shared/collect.rb b/spec/ruby/core/enumerable/shared/collect.rb
deleted file mode 100644
index f66c539904..0000000000
--- a/spec/ruby/core/enumerable/shared/collect.rb
+++ /dev/null
@@ -1,32 +0,0 @@
-require File.expand_path('../enumerable_enumeratorized', __FILE__)
-
-describe :enumerable_collect, shared: true do
- before :each do
- ScratchPad.record []
- end
-
- it "returns a new array with the results of passing each element to block" do
- entries = [0, 1, 3, 4, 5, 6]
- numerous = EnumerableSpecs::Numerous.new(*entries)
- numerous.send(@method) { |i| i % 2 }.should == [0, 1, 1, 0, 1, 0]
- numerous.send(@method) { |i| i }.should == entries
- end
-
- it "passes through the values yielded by #each_with_index" do
- [:a, :b].each_with_index.send(@method) { |x, i| ScratchPad << [x, i]; nil }
- ScratchPad.recorded.should == [[:a, 0], [:b, 1]]
- end
-
- it "gathers initial args as elements when each yields multiple" do
- multi = EnumerableSpecs::YieldsMulti.new
- multi.send(@method) {|e| e}.should == [1,3,6]
- end
-
- it "returns an enumerator when no block given" do
- enum = EnumerableSpecs::Numerous.new.send(@method)
- enum.should be_an_instance_of(Enumerator)
- enum.each { |i| -i }.should == [-2, -5, -3, -6, -1, -4]
- end
-
- it_should_behave_like :enumerable_enumeratorized_with_origin_size
-end
diff --git a/spec/ruby/core/enumerable/shared/collect_concat.rb b/spec/ruby/core/enumerable/shared/collect_concat.rb
deleted file mode 100644
index 54e10692eb..0000000000
--- a/spec/ruby/core/enumerable/shared/collect_concat.rb
+++ /dev/null
@@ -1,54 +0,0 @@
-require File.expand_path('../enumerable_enumeratorized', __FILE__)
-
-describe :enumerable_collect_concat, shared: true do
- it "yields elements to the block and flattens one level" do
- numerous = EnumerableSpecs::Numerous.new(1, [2, 3], [4, [5, 6]], {foo: :bar})
- numerous.send(@method) { |i| i }.should == [1, 2, 3, 4, [5, 6], {foo: :bar}]
- end
-
- it "appends non-Array elements that do not define #to_ary" do
- obj = mock("to_ary undefined")
-
- numerous = EnumerableSpecs::Numerous.new(1, obj, 2)
- numerous.send(@method) { |i| i }.should == [1, obj, 2]
- end
-
- it "concatenates the result of calling #to_ary if it returns an Array" do
- obj = mock("to_ary defined")
- obj.should_receive(:to_ary).and_return([:a, :b])
-
- numerous = EnumerableSpecs::Numerous.new(1, obj, 2)
- numerous.send(@method) { |i| i }.should == [1, :a, :b, 2]
- end
-
- it "does not call #to_a" do
- obj = mock("to_ary undefined")
- obj.should_not_receive(:to_a)
-
- numerous = EnumerableSpecs::Numerous.new(1, obj, 2)
- numerous.send(@method) { |i| i }.should == [1, obj, 2]
- end
-
- it "appends an element that defines #to_ary that returns nil" do
- obj = mock("to_ary defined")
- obj.should_receive(:to_ary).and_return(nil)
-
- numerous = EnumerableSpecs::Numerous.new(1, obj, 2)
- numerous.send(@method) { |i| i }.should == [1, obj, 2]
- end
-
- it "raises a TypeError if an element defining #to_ary does not return an Array or nil" do
- obj = mock("to_ary defined")
- obj.should_receive(:to_ary).and_return("array")
-
- lambda { [1, obj, 3].send(@method) { |i| i } }.should raise_error(TypeError)
- end
-
- it "returns an enumerator when no block given" do
- enum = EnumerableSpecs::Numerous.new(1, 2).send(@method)
- enum.should be_an_instance_of(Enumerator)
- enum.each{ |i| [i] * i }.should == [1, 2, 2]
- end
-
- it_should_behave_like :enumerable_enumeratorized_with_origin_size
-end
diff --git a/spec/ruby/core/enumerable/shared/entries.rb b/spec/ruby/core/enumerable/shared/entries.rb
deleted file mode 100644
index f52844cb45..0000000000
--- a/spec/ruby/core/enumerable/shared/entries.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-describe :enumerable_entries, shared: true do
- it "returns an array containing the elements" do
- numerous = EnumerableSpecs::Numerous.new(1, nil, 'a', 2, false, true)
- numerous.send(@method).should == [1, nil, "a", 2, false, true]
- end
-
- it "passes through the values yielded by #each_with_index" do
- [:a, :b].each_with_index.send(@method).should == [[:a, 0], [:b, 1]]
- end
-
- it "passes arguments to each" do
- count = EnumerableSpecs::EachCounter.new(1, 2, 3)
- count.send(@method, :hello, "world").should == [1, 2, 3]
- count.arguments_passed.should == [:hello, "world"]
- end
-
- it "returns a tainted array if self is tainted" do
- EnumerableSpecs::Empty.new.taint.send(@method).tainted?.should be_true
- end
-
- it "returns an untrusted array if self is untrusted" do
- EnumerableSpecs::Empty.new.untrust.send(@method).untrusted?.should be_true
- end
-end
diff --git a/spec/ruby/core/enumerable/shared/enumerable_enumeratorized.rb b/spec/ruby/core/enumerable/shared/enumerable_enumeratorized.rb
index b03ce9ed4e..e2bbe18eda 100644
--- a/spec/ruby/core/enumerable/shared/enumerable_enumeratorized.rb
+++ b/spec/ruby/core/enumerable/shared/enumerable_enumeratorized.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../enumeratorized', __FILE__)
+require_relative 'enumeratorized'
describe :enumerable_enumeratorized_with_unknown_size, shared: true do
describe "Enumerable with size" do
diff --git a/spec/ruby/core/enumerable/shared/find.rb b/spec/ruby/core/enumerable/shared/find.rb
deleted file mode 100644
index 4cbbf07be0..0000000000
--- a/spec/ruby/core/enumerable/shared/find.rb
+++ /dev/null
@@ -1,73 +0,0 @@
-require File.expand_path('../enumerable_enumeratorized', __FILE__)
-
-describe :enumerable_find, shared: true do
- # #detect and #find are aliases, so we only need one function
- before :each do
- ScratchPad.record []
- @elements = [2, 4, 6, 8, 10]
- @numerous = EnumerableSpecs::Numerous.new(*@elements)
- @empty = []
- end
-
- it "passes each entry in enum to block while block when block is false" do
- visited_elements = []
- @numerous.send(@method) do |element|
- visited_elements << element
- false
- end
- visited_elements.should == @elements
- end
-
- it "returns nil when the block is false and there is no ifnone proc given" do
- @numerous.send(@method) {|e| false }.should == nil
- end
-
- it "returns the first element for which the block is not false" do
- @elements.each do |element|
- @numerous.send(@method) {|e| e > element - 1 }.should == element
- end
- end
-
- it "returns the value of the ifnone proc if the block is false" do
- fail_proc = lambda { "cheeseburgers" }
- @numerous.send(@method, fail_proc) {|e| false }.should == "cheeseburgers"
- end
-
- it "doesn't call the ifnone proc if an element is found" do
- fail_proc = lambda { raise "This shouldn't have been called" }
- @numerous.send(@method, fail_proc) {|e| e == @elements.first }.should == 2
- end
-
- it "calls the ifnone proc only once when the block is false" do
- times = 0
- fail_proc = lambda { times += 1; raise if times > 1; "cheeseburgers" }
- @numerous.send(@method, fail_proc) {|e| false }.should == "cheeseburgers"
- end
-
- it "calls the ifnone proc when there are no elements" do
- fail_proc = lambda { "yay" }
- @empty.send(@method, fail_proc) {|e| true}.should == "yay"
- end
-
- it "passes through the values yielded by #each_with_index" do
- [:a, :b].each_with_index.send(@method) { |x, i| ScratchPad << [x, i]; nil }
- ScratchPad.recorded.should == [[:a, 0], [:b, 1]]
- end
-
- it "returns an enumerator when no block given" do
- @numerous.send(@method).should be_an_instance_of(Enumerator)
- end
-
- it "passes the ifnone proc to the enumerator" do
- times = 0
- fail_proc = lambda { times += 1; raise if times > 1; "cheeseburgers" }
- @numerous.send(@method, fail_proc).each {|e| false }.should == "cheeseburgers"
- end
-
- it "gathers whole arrays as elements when each yields multiple" do
- multi = EnumerableSpecs::YieldsMulti.new
- multi.send(@method) {|e| e == [1, 2] }.should == [1, 2]
- end
-
- it_should_behave_like :enumerable_enumeratorized_with_unknown_size
-end
diff --git a/spec/ruby/core/enumerable/shared/find_all.rb b/spec/ruby/core/enumerable/shared/find_all.rb
deleted file mode 100644
index 3e15c68e9f..0000000000
--- a/spec/ruby/core/enumerable/shared/find_all.rb
+++ /dev/null
@@ -1,31 +0,0 @@
-require File.expand_path('../enumerable_enumeratorized', __FILE__)
-
-describe :enumerable_find_all, shared: true do
- before :each do
- ScratchPad.record []
- @elements = (1..10).to_a
- @numerous = EnumerableSpecs::Numerous.new(*@elements)
- end
-
- it "returns all elements for which the block is not false" do
- @numerous.send(@method) {|i| i % 3 == 0 }.should == [3, 6, 9]
- @numerous.send(@method) {|i| true }.should == @elements
- @numerous.send(@method) {|i| false }.should == []
- end
-
- it "returns an enumerator when no block given" do
- @numerous.send(@method).should be_an_instance_of(Enumerator)
- end
-
- it "passes through the values yielded by #each_with_index" do
- [:a, :b].each_with_index.send(@method) { |x, i| ScratchPad << [x, i] }
- ScratchPad.recorded.should == [[:a, 0], [:b, 1]]
- end
-
- it "gathers whole arrays as elements when each yields multiple" do
- multi = EnumerableSpecs::YieldsMulti.new
- multi.send(@method) {|e| e == [3, 4, 5] }.should == [[3, 4, 5]]
- end
-
- it_should_behave_like :enumerable_enumeratorized_with_origin_size
-end
diff --git a/spec/ruby/core/enumerable/shared/include.rb b/spec/ruby/core/enumerable/shared/include.rb
deleted file mode 100644
index 569f350fd5..0000000000
--- a/spec/ruby/core/enumerable/shared/include.rb
+++ /dev/null
@@ -1,34 +0,0 @@
-describe :enumerable_include, shared: true do
- it "returns true if any element == argument for numbers" do
- class EnumerableSpecIncludeP; def ==(obj) obj == 5; end; end
-
- elements = (0..5).to_a
- EnumerableSpecs::Numerous.new(*elements).send(@method,5).should == true
- EnumerableSpecs::Numerous.new(*elements).send(@method,10).should == false
- EnumerableSpecs::Numerous.new(*elements).send(@method,EnumerableSpecIncludeP.new).should == true
- end
-
- it "returns true if any element == argument for other objects" do
- class EnumerableSpecIncludeP11; def ==(obj); obj == '11'; end; end
-
- elements = ('0'..'5').to_a + [EnumerableSpecIncludeP11.new]
- EnumerableSpecs::Numerous.new(*elements).send(@method,'5').should == true
- EnumerableSpecs::Numerous.new(*elements).send(@method,'10').should == false
- EnumerableSpecs::Numerous.new(*elements).send(@method,EnumerableSpecIncludeP11.new).should == true
- EnumerableSpecs::Numerous.new(*elements).send(@method,'11').should == true
- end
-
-
- it "returns true if any member of enum equals obj when == compare different classes (legacy rubycon)" do
- # equality is tested with ==
- EnumerableSpecs::Numerous.new(2,4,6,8,10).send(@method, 2.0).should == true
- EnumerableSpecs::Numerous.new(2,4,[6,8],10).send(@method, [6, 8]).should == true
- EnumerableSpecs::Numerous.new(2,4,[6,8],10).send(@method, [6.0, 8.0]).should == true
- end
-
- it "gathers whole arrays as elements when each yields multiple" do
- multi = EnumerableSpecs::YieldsMulti.new
- multi.send(@method, [1,2]).should be_true
- end
-
-end
diff --git a/spec/ruby/core/enumerable/shared/inject.rb b/spec/ruby/core/enumerable/shared/inject.rb
deleted file mode 100644
index 12e0665dda..0000000000
--- a/spec/ruby/core/enumerable/shared/inject.rb
+++ /dev/null
@@ -1,69 +0,0 @@
-describe :enumerable_inject, shared: true do
- it "with argument takes a block with an accumulator (with argument as initial value) and the current element. Value of block becomes new accumulator" do
- a = []
- EnumerableSpecs::Numerous.new.send(@method, 0) { |memo, i| a << [memo, i]; i }
- a.should == [[0, 2], [2, 5], [5, 3], [3, 6], [6, 1], [1, 4]]
- EnumerableSpecs::EachDefiner.new(true, true, true).send(@method, nil) {|result, i| i && result}.should == nil
- end
-
- it "produces an array of the accumulator and the argument when given a block with a *arg" do
- a = []
- [1,2].send(@method, 0) {|*args| a << args; args[0] + args[1]}
- a.should == [[0, 1], [1, 2]]
- end
-
- it "can take two argument" do
- EnumerableSpecs::Numerous.new(1, 2, 3).send(@method, 10, :-).should == 4
- end
-
- it "ignores the block if two arguments" do
- EnumerableSpecs::Numerous.new(1, 2, 3).send(@method, 10, :-){ raise "we never get here"}.should == 4
- end
-
- it "can take a symbol argument" do
- EnumerableSpecs::Numerous.new(10, 1, 2, 3).send(@method, :-).should == 4
- end
-
- it "without argument takes a block with an accumulator (with first element as initial value) and the current element. Value of block becomes new accumulator" do
- a = []
- EnumerableSpecs::Numerous.new.send(@method) { |memo, i| a << [memo, i]; i }
- a.should == [[2, 5], [5, 3], [3, 6], [6, 1], [1, 4]]
- end
-
- it "gathers whole arrays as elements when each yields multiple" do
- multi = EnumerableSpecs::YieldsMulti.new
- multi.send(@method, []) {|acc, e| acc << e }.should == [[1, 2], [3, 4, 5], [6, 7, 8, 9]]
- end
-
- it "with inject arguments(legacy rubycon)" do
- # with inject argument
- EnumerableSpecs::EachDefiner.new().send(@method, 1) {|acc,x| 999 }.should == 1
- EnumerableSpecs::EachDefiner.new(2).send(@method, 1) {|acc,x| 999 }.should == 999
- EnumerableSpecs::EachDefiner.new(2).send(@method, 1) {|acc,x| acc }.should == 1
- EnumerableSpecs::EachDefiner.new(2).send(@method, 1) {|acc,x| x }.should == 2
-
- EnumerableSpecs::EachDefiner.new(1,2,3,4).send(@method, 100) {|acc,x| acc + x }.should == 110
- EnumerableSpecs::EachDefiner.new(1,2,3,4).send(@method, 100) {|acc,x| acc * x }.should == 2400
-
- EnumerableSpecs::EachDefiner.new('a','b','c').send(@method, "z") {|result, i| i+result}.should == "cbaz"
- end
-
- it "without inject arguments(legacy rubycon)" do
- # no inject argument
- EnumerableSpecs::EachDefiner.new(2).send(@method) {|acc,x| 999 } .should == 2
- EnumerableSpecs::EachDefiner.new(2).send(@method) {|acc,x| acc }.should == 2
- EnumerableSpecs::EachDefiner.new(2).send(@method) {|acc,x| x }.should == 2
-
- EnumerableSpecs::EachDefiner.new(1,2,3,4).send(@method) {|acc,x| acc + x }.should == 10
- EnumerableSpecs::EachDefiner.new(1,2,3,4).send(@method) {|acc,x| acc * x }.should == 24
-
- EnumerableSpecs::EachDefiner.new('a','b','c').send(@method) {|result, i| i+result}.should == "cba"
- EnumerableSpecs::EachDefiner.new(3, 4, 5).send(@method) {|result, i| result*i}.should == 60
- EnumerableSpecs::EachDefiner.new([1], 2, 'a','b').send(@method){|r,i| r<<i}.should == [1, 2, 'a', 'b']
-
- end
-
- it "returns nil when fails(legacy rubycon)" do
- EnumerableSpecs::EachDefiner.new().send(@method) {|acc,x| 999 }.should == nil
- end
-end
diff --git a/spec/ruby/core/enumerable/shared/take.rb b/spec/ruby/core/enumerable/shared/take.rb
index bf2536acda..a6da06325f 100644
--- a/spec/ruby/core/enumerable/shared/take.rb
+++ b/spec/ruby/core/enumerable/shared/take.rb
@@ -25,7 +25,7 @@ describe :enumerable_take, shared: true do
end
it "raises an ArgumentError when count is negative" do
- lambda { @enum.send(@method, -1) }.should raise_error(ArgumentError)
+ -> { @enum.send(@method, -1) }.should.raise(ArgumentError)
end
it "returns the entire array when count > length" do
@@ -40,11 +40,11 @@ describe :enumerable_take, shared: true do
end
it "raises a TypeError if the passed argument is not numeric" do
- lambda { @enum.send(@method, nil) }.should raise_error(TypeError)
- lambda { @enum.send(@method, "a") }.should raise_error(TypeError)
+ -> { @enum.send(@method, nil) }.should.raise(TypeError)
+ -> { @enum.send(@method, "a") }.should.raise(TypeError)
obj = mock("nonnumeric")
- lambda { @enum.send(@method, obj) }.should raise_error(TypeError)
+ -> { @enum.send(@method, obj) }.should.raise(TypeError)
end
it "gathers whole arrays as elements when each yields multiple" do
diff --git a/spec/ruby/core/enumerable/shared/value_packing.rb b/spec/ruby/core/enumerable/shared/value_packing.rb
new file mode 100644
index 0000000000..ff77f45cdf
--- /dev/null
+++ b/spec/ruby/core/enumerable/shared/value_packing.rb
@@ -0,0 +1,26 @@
+# This is the behavior of rb_enum_values_pack() in CRuby
+describe :enumerable_value_packing, shared: true do
+ # @take must be set to a Proc that returns the take-result whose #each
+ # yields packed values (e.g. -> e { e.take(1) } or -> e { e.lazy.take(1) }).
+
+ it "yields a single nil for a zero-argument source yield" do
+ e = Enumerator.new { |y| y.yield }
+ args = nil
+ @take.call(e).each { |*a| args = a }
+ args.should == [nil]
+ end
+
+ it "yields the value for a single-argument source yield" do
+ e = Enumerator.new { |y| y.yield :v }
+ args = nil
+ @take.call(e).each { |*a| args = a }
+ args.should == [:v]
+ end
+
+ it "yields a packed Array for a multi-argument source yield" do
+ e = Enumerator.new { |y| y.yield 1, 2 }
+ args = nil
+ @take.call(e).each { |*a| args = a }
+ args.should == [[1, 2]]
+ end
+end
diff --git a/spec/ruby/core/enumerable/slice_after_spec.rb b/spec/ruby/core/enumerable/slice_after_spec.rb
index a199b9f1ed..1ef37195e5 100644
--- a/spec/ruby/core/enumerable/slice_after_spec.rb
+++ b/spec/ruby/core/enumerable/slice_after_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Enumerable#slice_after" do
before :each do
@@ -11,7 +11,7 @@ describe "Enumerable#slice_after" do
arg = mock("filter")
arg.should_receive(:===).and_return(false, true, false, false, false, true, false)
e = @enum.slice_after(arg)
- e.should be_an_instance_of(Enumerator)
+ e.should.instance_of?(Enumerator)
e.to_a.should == [[7, 6], [5, 4, 3, 2], [1]]
end
@@ -34,21 +34,21 @@ describe "Enumerable#slice_after" do
describe "and no argument" do
it "calls the block to determine when to yield" do
e = @enum.slice_after{ |i| i == 6 || i == 2 }
- e.should be_an_instance_of(Enumerator)
+ e.should.instance_of?(Enumerator)
e.to_a.should == [[7, 6], [5, 4, 3, 2], [1]]
end
end
describe "and an argument" do
it "raises an ArgumentError" do
- lambda { @enum.slice_after(42) { |i| i == 6 } }.should raise_error(ArgumentError)
+ -> { @enum.slice_after(42) { |i| i == 6 } }.should.raise(ArgumentError)
end
end
end
it "raises an ArgumentError when given an incorrect number of arguments" do
- lambda { @enum.slice_after("one", "two") }.should raise_error(ArgumentError)
- lambda { @enum.slice_after }.should raise_error(ArgumentError)
+ -> { @enum.slice_after("one", "two") }.should.raise(ArgumentError)
+ -> { @enum.slice_after }.should.raise(ArgumentError)
end
end
diff --git a/spec/ruby/core/enumerable/slice_before_spec.rb b/spec/ruby/core/enumerable/slice_before_spec.rb
index 1594372d32..7eb4410a25 100644
--- a/spec/ruby/core/enumerable/slice_before_spec.rb
+++ b/spec/ruby/core/enumerable/slice_before_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/enumerable_enumeratorized', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/enumerable_enumeratorized'
describe "Enumerable#slice_before" do
before :each do
@@ -12,7 +12,7 @@ describe "Enumerable#slice_before" do
arg = mock "filter"
arg.should_receive(:===).and_return(false, true, false, false, false, true, false)
e = @enum.slice_before(arg)
- e.should be_an_instance_of(Enumerator)
+ e.should.instance_of?(Enumerator)
e.to_a.should == [[7], [6, 5, 4, 3], [2, 1]]
end
@@ -35,44 +35,21 @@ describe "Enumerable#slice_before" do
describe "and no argument" do
it "calls the block to determine when to yield" do
e = @enum.slice_before{|i| i == 6 || i == 2}
- e.should be_an_instance_of(Enumerator)
+ e.should.instance_of?(Enumerator)
e.to_a.should == [[7], [6, 5, 4, 3], [2, 1]]
end
end
- ruby_version_is ""..."2.3" do
- describe "and an argument" do
- it "calls the block with a copy of that argument" do
- arg = [:foo]
- first = nil
- e = @enum.slice_before(arg) do |i, init|
- init.should == arg
- init.should_not equal(arg)
- first = init
- i == 6 || i == 2
- end
- e.should be_an_instance_of(Enumerator)
- e.to_a.should == [[7], [6, 5, 4, 3], [2, 1]]
- e = @enum.slice_before(arg) do |i, init|
- init.should_not equal(first)
- end
- e.to_a
- end
- end
- end
-
- ruby_version_is "2.3" do
- it "does not accept arguments" do
- lambda {
- @enum.slice_before(1) {}
- }.should raise_error(ArgumentError)
- end
+ it "does not accept arguments" do
+ -> {
+ @enum.slice_before(1) {}
+ }.should.raise(ArgumentError)
end
end
it "raises an ArgumentError when given an incorrect number of arguments" do
- lambda { @enum.slice_before("one", "two") }.should raise_error(ArgumentError)
- lambda { @enum.slice_before }.should raise_error(ArgumentError)
+ -> { @enum.slice_before("one", "two") }.should.raise(ArgumentError)
+ -> { @enum.slice_before }.should.raise(ArgumentError)
end
describe "when an iterator method yields more than one value" do
diff --git a/spec/ruby/core/enumerable/slice_when_spec.rb b/spec/ruby/core/enumerable/slice_when_spec.rb
index 593e623b1b..fe1ecd31e2 100644
--- a/spec/ruby/core/enumerable/slice_when_spec.rb
+++ b/spec/ruby/core/enumerable/slice_when_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Enumerable#slice_when" do
before :each do
@@ -11,7 +11,7 @@ describe "Enumerable#slice_when" do
context "when given a block" do
it "returns an enumerator" do
- @result.should be_an_instance_of(Enumerator)
+ @result.should.instance_of?(Enumerator)
end
it "splits chunks between adjacent elements i and j where the block returns true" do
@@ -39,7 +39,7 @@ describe "Enumerable#slice_when" do
context "when not given a block" do
it "raises an ArgumentError" do
- lambda { @enum.slice_when }.should raise_error(ArgumentError)
+ -> { @enum.slice_when }.should.raise(ArgumentError)
end
end
diff --git a/spec/ruby/core/enumerable/sort_by_spec.rb b/spec/ruby/core/enumerable/sort_by_spec.rb
index f7df8659a8..62cf38ce3e 100644
--- a/spec/ruby/core/enumerable/sort_by_spec.rb
+++ b/spec/ruby/core/enumerable/sort_by_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/enumerable_enumeratorized', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/enumerable_enumeratorized'
describe "Enumerable#sort_by" do
it "returns an array of elements ordered by the result of block" do
@@ -18,7 +18,7 @@ describe "Enumerable#sort_by" do
it "returns an Enumerator when a block is not supplied" do
a = EnumerableSpecs::Numerous.new("a","b")
- a.sort_by.should be_an_instance_of(Enumerator)
+ a.sort_by.should.instance_of?(Enumerator)
a.to_a.should == ["a", "b"]
end
@@ -32,5 +32,12 @@ describe "Enumerable#sort_by" do
b.sort_by{ |x| -x }.should == [3, 2, 1]
end
+ it "calls #each to iterate over the elements to be sorted" do
+ b = EnumerableSpecs::Numerous.new( 1, 2, 3 )
+ b.should_receive(:each).once.and_yield(1).and_yield(2).and_yield(3)
+ b.should_not_receive :map
+ b.sort_by { |x| -x }.should == [3, 2, 1]
+ end
+
it_behaves_like :enumerable_enumeratorized_with_origin_size, :sort_by
end
diff --git a/spec/ruby/core/enumerable/sort_spec.rb b/spec/ruby/core/enumerable/sort_spec.rb
index a39fa7ed34..427b1cd8f1 100644
--- a/spec/ruby/core/enumerable/sort_spec.rb
+++ b/spec/ruby/core/enumerable/sort_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Enumerable#sort" do
it "sorts by the natural order as defined by <=>" do
@@ -14,9 +14,9 @@ describe "Enumerable#sort" do
end
it "raises a NoMethodError if elements do not define <=>" do
- lambda do
+ -> do
EnumerableSpecs::Numerous.new(BasicObject.new, BasicObject.new, BasicObject.new).sort
- end.should raise_error(NoMethodError)
+ end.should.raise(NoMethodError)
end
it "sorts enumerables that contain nils" do
@@ -31,16 +31,16 @@ describe "Enumerable#sort" do
it "compare values returned by block with 0" do
EnumerableSpecs::Numerous.new.sort { |n, m| -(n+m) * (n <=> m) }.should == [6, 5, 4, 3, 2, 1]
EnumerableSpecs::Numerous.new.sort { |n, m|
- EnumerableSpecs::ComparableWithFixnum.new(-(n+m) * (n <=> m))
+ EnumerableSpecs::ComparableWithInteger.new(-(n+m) * (n <=> m))
}.should == [6, 5, 4, 3, 2, 1]
- lambda {
+ -> {
EnumerableSpecs::Numerous.new.sort { |n, m| (n <=> m).to_s }
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
end
it "raises an error if objects can't be compared" do
a=EnumerableSpecs::Numerous.new(EnumerableSpecs::Uncomparable.new, EnumerableSpecs::Uncomparable.new)
- lambda {a.sort}.should raise_error(ArgumentError)
+ -> {a.sort}.should.raise(ArgumentError)
end
it "gathers whole arrays as elements when each yields multiple" do
diff --git a/spec/ruby/core/enumerable/sum_spec.rb b/spec/ruby/core/enumerable/sum_spec.rb
index 4881039a8d..2eb74db6ac 100644
--- a/spec/ruby/core/enumerable/sum_spec.rb
+++ b/spec/ruby/core/enumerable/sum_spec.rb
@@ -1,30 +1,50 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
-ruby_version_is '2.4' do
- describe 'Enumerable#sum' do
- before :each do
- @enum = Object.new.to_enum
- class << @enum
- def each
- yield 0
- yield(-1)
- yield 2
- yield 2/3r
- end
+describe 'Enumerable#sum' do
+ before :each do
+ @enum = Object.new.to_enum
+ class << @enum
+ def each
+ yield 0
+ yield(-1)
+ yield 2
+ yield 2/3r
end
end
+ end
- it 'returns amount of the elements with taking an argument as the initial value' do
- @enum.sum(10).should == 35/3r
- end
+ it 'returns amount of the elements with taking an argument as the initial value' do
+ @enum.sum(10).should == 35/3r
+ end
- it 'gives 0 as a default argument' do
- @enum.sum.should == 5/3r
- end
+ it 'gives 0 as a default argument' do
+ @enum.sum.should == 5/3r
+ end
- it 'takes a block to transform the elements' do
+ context 'with a block' do
+ it 'transforms the elements' do
@enum.sum { |element| element * 2 }.should == 10/3r
end
+
+ it 'does not destructure array elements' do
+ class << @enum
+ def each
+ yield [1,2]
+ yield [3]
+ end
+ end
+
+ @enum.sum(&:last).should == 5
+ end
+ end
+
+ # https://bugs.ruby-lang.org/issues/12217
+ # https://github.com/ruby/ruby/blob/master/doc/ChangeLog/ChangeLog-2.4.0#L6208-L6214
+ it "uses Kahan's compensated summation algorithm for precise sum of float numbers" do
+ floats = [2.7800000000000002, 5.0, 2.5, 4.44, 3.89, 3.89, 4.44, 7.78, 5.0, 2.7800000000000002, 5.0, 2.5].to_enum
+ naive_sum = floats.reduce { |sum, e| sum + e }
+ naive_sum.should == 50.00000000000001
+ floats.sum.should == 50.0
end
end
diff --git a/spec/ruby/core/enumerable/take_spec.rb b/spec/ruby/core/enumerable/take_spec.rb
index 71bf77050c..ca439b750d 100644
--- a/spec/ruby/core/enumerable/take_spec.rb
+++ b/spec/ruby/core/enumerable/take_spec.rb
@@ -1,13 +1,21 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/take', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/take'
+require_relative 'shared/value_packing'
describe "Enumerable#take" do
it "requires an argument" do
- lambda{ EnumerableSpecs::Numerous.new.take}.should raise_error(ArgumentError)
+ ->{ EnumerableSpecs::Numerous.new.take}.should.raise(ArgumentError)
end
describe "when passed an argument" do
it_behaves_like :enumerable_take, :take
end
+
+ describe "value packing of source yields" do
+ before :each do
+ @take = -> e { e.take(1) }
+ end
+ it_behaves_like :enumerable_value_packing, nil
+ end
end
diff --git a/spec/ruby/core/enumerable/take_while_spec.rb b/spec/ruby/core/enumerable/take_while_spec.rb
index 990d16209a..918bfc897d 100644
--- a/spec/ruby/core/enumerable/take_while_spec.rb
+++ b/spec/ruby/core/enumerable/take_while_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/enumerable_enumeratorized', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/enumerable_enumeratorized'
describe "Enumerable#take_while" do
before :each do
@@ -8,7 +8,7 @@ describe "Enumerable#take_while" do
end
it "returns an Enumerator if no block given" do
- @enum.take_while.should be_an_instance_of(Enumerator)
+ @enum.take_while.should.instance_of?(Enumerator)
end
it "returns no/all elements for {true/false} block" do
@@ -38,7 +38,7 @@ describe "Enumerable#take_while" do
it "doesn't return self when it could" do
a = [1,2,3]
- a.take_while{true}.should_not equal(a)
+ a.take_while{true}.should_not.equal?(a)
end
it "calls the block with initial args when yielded with multiple arguments" do
diff --git a/spec/ruby/core/enumerable/tally_spec.rb b/spec/ruby/core/enumerable/tally_spec.rb
new file mode 100644
index 0000000000..deef741407
--- /dev/null
+++ b/spec/ruby/core/enumerable/tally_spec.rb
@@ -0,0 +1,91 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe "Enumerable#tally" do
+ before :each do
+ ScratchPad.record []
+ end
+
+ it "returns a hash with counts according to the value" do
+ enum = EnumerableSpecs::Numerous.new('foo', 'bar', 'foo', 'baz')
+ enum.tally.should == { 'foo' => 2, 'bar' => 1, 'baz' => 1}
+ end
+
+ it "returns a hash without default" do
+ hash = EnumerableSpecs::Numerous.new('foo', 'bar', 'foo', 'baz').tally
+ hash.default_proc.should == nil
+ hash.default.should == nil
+ end
+
+ it "returns an empty hash for empty enumerables" do
+ EnumerableSpecs::Empty.new.tally.should == {}
+ end
+
+ it "counts values as gathered array when yielded with multiple arguments" do
+ EnumerableSpecs::YieldsMixed2.new.tally.should == EnumerableSpecs::YieldsMixed2.gathered_yields.group_by(&:itself).transform_values(&:size)
+ end
+
+ it "does not call given block" do
+ enum = EnumerableSpecs::Numerous.new('foo', 'bar', 'foo', 'baz')
+ enum.tally { |v| ScratchPad << v }
+ ScratchPad.recorded.should == []
+ end
+end
+
+describe "Enumerable#tally with a hash" do
+ before :each do
+ ScratchPad.record []
+ end
+
+ it "returns a hash with counts according to the value" do
+ enum = EnumerableSpecs::Numerous.new('foo', 'bar', 'foo', 'baz')
+ enum.tally({ 'foo' => 1 }).should == { 'foo' => 3, 'bar' => 1, 'baz' => 1}
+ end
+
+ it "returns the given hash" do
+ enum = EnumerableSpecs::Numerous.new('foo', 'bar', 'foo', 'baz')
+ hash = { 'foo' => 1 }
+ enum.tally(hash).should.equal?(hash)
+ end
+
+ it "calls #to_hash to convert argument to Hash implicitly if passed not a Hash" do
+ enum = EnumerableSpecs::Numerous.new('foo', 'bar', 'foo', 'baz')
+ object = Object.new
+ def object.to_hash; { 'foo' => 1 }; end
+ enum.tally(object).should == { 'foo' => 3, 'bar' => 1, 'baz' => 1}
+ end
+
+ it "raises a FrozenError and does not update the given hash when the hash is frozen" do
+ enum = EnumerableSpecs::Numerous.new('foo', 'bar', 'foo', 'baz')
+ hash = { 'foo' => 1 }.freeze
+ -> { enum.tally(hash) }.should.raise(FrozenError)
+ hash.should == { 'foo' => 1 }
+ end
+
+ it "raises a FrozenError even if enumerable is empty" do
+ enum = EnumerableSpecs::Numerous.new()
+ hash = { 'foo' => 1 }.freeze
+ -> { enum.tally(hash) }.should.raise(FrozenError)
+ end
+
+ it "does not call given block" do
+ enum = EnumerableSpecs::Numerous.new('foo', 'bar', 'foo', 'baz')
+ enum.tally({ 'foo' => 1 }) { |v| ScratchPad << v }
+ ScratchPad.recorded.should == []
+ end
+
+ it "ignores the default value" do
+ enum = EnumerableSpecs::Numerous.new('foo', 'bar', 'foo', 'baz')
+ enum.tally(Hash.new(100)).should == { 'foo' => 2, 'bar' => 1, 'baz' => 1}
+ end
+
+ it "ignores the default proc" do
+ enum = EnumerableSpecs::Numerous.new('foo', 'bar', 'foo', 'baz')
+ enum.tally(Hash.new {100}).should == { 'foo' => 2, 'bar' => 1, 'baz' => 1}
+ end
+
+ it "needs the values counting each elements to be an integer" do
+ enum = EnumerableSpecs::Numerous.new('foo')
+ -> { enum.tally({ 'foo' => 'bar' }) }.should.raise(TypeError)
+ end
+end
diff --git a/spec/ruby/core/enumerable/to_a_spec.rb b/spec/ruby/core/enumerable/to_a_spec.rb
index b14a3c7a1a..f1796070f0 100644
--- a/spec/ruby/core/enumerable/to_a_spec.rb
+++ b/spec/ruby/core/enumerable/to_a_spec.rb
@@ -1,7 +1,19 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/entries', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Enumerable#to_a" do
- it_behaves_like(:enumerable_entries , :to_a)
+ it "returns an array containing the elements" do
+ numerous = EnumerableSpecs::Numerous.new(1, nil, 'a', 2, false, true)
+ numerous.to_a.should == [1, nil, "a", 2, false, true]
+ end
+
+ it "passes through the values yielded by #each_with_index" do
+ [:a, :b].each_with_index.to_a.should == [[:a, 0], [:b, 1]]
+ end
+
+ it "passes arguments to each" do
+ count = EnumerableSpecs::EachCounter.new(1, 2, 3)
+ count.to_a(:hello, "world").should == [1, 2, 3]
+ count.arguments_passed.should == [:hello, "world"]
+ end
end
diff --git a/spec/ruby/core/enumerable/to_h_spec.rb b/spec/ruby/core/enumerable/to_h_spec.rb
index b5b301b882..38847eccfb 100644
--- a/spec/ruby/core/enumerable/to_h_spec.rb
+++ b/spec/ruby/core/enumerable/to_h_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Enumerable#to_h" do
it "converts empty enumerable to empty hash" do
@@ -36,11 +36,61 @@ describe "Enumerable#to_h" do
it "raises TypeError if an element is not an array" do
enum = EnumerableSpecs::EachDefiner.new(:x)
- lambda { enum.to_h }.should raise_error(TypeError)
+ -> { enum.to_h }.should.raise(TypeError)
end
it "raises ArgumentError if an element is not a [key, value] pair" do
enum = EnumerableSpecs::EachDefiner.new([:x])
- lambda { enum.to_h }.should raise_error(ArgumentError)
+ -> { enum.to_h }.should.raise(ArgumentError)
+ end
+
+ context "with block" do
+ before do
+ @enum = EnumerableSpecs::EachDefiner.new(:a, :b)
+ end
+
+ it "converts [key, value] pairs returned by the block to a hash" do
+ @enum.to_h { |k| [k, k.to_s] }.should == { a: 'a', b: 'b' }
+ end
+
+ it "passes to a block each element as a single argument" do
+ enum_of_arrays = EnumerableSpecs::EachDefiner.new([:a, 1], [:b, 2])
+
+ ScratchPad.record []
+ enum_of_arrays.to_h { |*args| ScratchPad << args; [args[0], args[1]] }
+ ScratchPad.recorded.sort.should == [[[:a, 1]], [[:b, 2]]]
+ end
+
+ it "raises ArgumentError if block returns longer or shorter array" do
+ -> do
+ @enum.to_h { |k| [k, k.to_s, 1] }
+ end.should.raise(ArgumentError, /element has wrong array length/)
+
+ -> do
+ @enum.to_h { |k| [k] }
+ end.should.raise(ArgumentError, /element has wrong array length/)
+ end
+
+ it "raises TypeError if block returns something other than Array" do
+ -> do
+ @enum.to_h { |k| "not-array" }
+ end.should.raise(TypeError, /wrong element type String/)
+ end
+
+ it "coerces returned pair to Array with #to_ary" do
+ x = mock('x')
+ x.stub!(:to_ary).and_return([:b, 'b'])
+
+ @enum.to_h { |k| x }.should == { :b => 'b' }
+ end
+
+ it "does not coerce returned pair to Array with #to_a" do
+ x = mock('x')
+ x.stub!(:to_a).and_return([:b, 'b'])
+
+ -> do
+ @enum.to_h { |k| x }
+ end.should.raise(TypeError, /wrong element type MockObject/)
+ end
end
end
diff --git a/spec/ruby/core/enumerable/to_set_spec.rb b/spec/ruby/core/enumerable/to_set_spec.rb
new file mode 100644
index 0000000000..7b04c72bce
--- /dev/null
+++ b/spec/ruby/core/enumerable/to_set_spec.rb
@@ -0,0 +1,30 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe "Enumerable#to_set" do
+ it "returns a new Set created from self" do
+ [1, 2, 3].to_set.should == Set[1, 2, 3]
+ {a: 1, b: 2}.to_set.should == Set[[:b, 2], [:a, 1]]
+ end
+
+ it "passes down passed blocks" do
+ [1, 2, 3].to_set { |x| x * x }.should == Set[1, 4, 9]
+ end
+
+ ruby_version_is "4.0"..."4.1" do
+ it "instantiates an object of provided as the first argument set class" do
+ set = nil
+ proc{set = [1, 2, 3].to_set(EnumerableSpecs::SetSubclass)}.should complain(/Enumerable#to_set/)
+ set.should.is_a?(EnumerableSpecs::SetSubclass)
+ set.to_a.sort.should == [1, 2, 3]
+ end
+ end
+
+ ruby_version_is ""..."4.0" do
+ it "instantiates an object of provided as the first argument set class" do
+ set = [1, 2, 3].to_set(EnumerableSpecs::SetSubclass)
+ set.should.is_a?(EnumerableSpecs::SetSubclass)
+ set.to_a.sort.should == [1, 2, 3]
+ end
+ end
+end
diff --git a/spec/ruby/core/enumerable/uniq_spec.rb b/spec/ruby/core/enumerable/uniq_spec.rb
index 5ca7556aed..a1ed44796f 100644
--- a/spec/ruby/core/enumerable/uniq_spec.rb
+++ b/spec/ruby/core/enumerable/uniq_spec.rb
@@ -1,94 +1,78 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
-ruby_version_is '2.4' do
- describe 'Enumerable#uniq' do
- it 'returns an array that contains only unique elements' do
- [0, 1, 2, 3].to_enum.uniq { |n| n.even? }.should == [0, 1]
- end
+describe 'Enumerable#uniq' do
+ it 'returns an array that contains only unique elements' do
+ [0, 1, 2, 3].to_enum.uniq { |n| n.even? }.should == [0, 1]
+ end
- it "uses eql? semantics" do
- [1.0, 1].to_enum.uniq.should == [1.0, 1]
- end
+ it "uses eql? semantics" do
+ [1.0, 1].to_enum.uniq.should == [1.0, 1]
+ end
- it "compares elements first with hash" do
- x = mock('0')
- x.should_receive(:hash).at_least(1).and_return(0)
- y = mock('0')
- y.should_receive(:hash).at_least(1).and_return(0)
+ it "compares elements first with hash" do
+ x = mock('0')
+ x.should_receive(:hash).at_least(1).and_return(0)
+ y = mock('0')
+ y.should_receive(:hash).at_least(1).and_return(0)
- [x, y].to_enum.uniq.should == [x, y]
- end
+ [x, y].to_enum.uniq.should == [x, y]
+ end
- it "does not compare elements with different hash codes via eql?" do
- x = mock('0')
- x.should_not_receive(:eql?)
- y = mock('1')
- y.should_not_receive(:eql?)
+ it "does not compare elements with different hash codes via eql?" do
+ x = mock('0')
+ x.should_not_receive(:eql?)
+ y = mock('1')
+ y.should_not_receive(:eql?)
- x.should_receive(:hash).at_least(1).and_return(0)
- y.should_receive(:hash).at_least(1).and_return(1)
+ x.should_receive(:hash).at_least(1).and_return(0)
+ y.should_receive(:hash).at_least(1).and_return(1)
- [x, y].to_enum.uniq.should == [x, y]
- end
+ [x, y].to_enum.uniq.should == [x, y]
+ end
- it "compares elements with matching hash codes with #eql?" do
- a = Array.new(2) do
- obj = mock('0')
- obj.should_receive(:hash).at_least(1).and_return(0)
-
- def obj.eql?(o)
- # It's undefined whether the impl does a[0].eql?(a[1]) or
- # a[1].eql?(a[0]) so we taint both.
- taint
- o.taint
- false
- end
+ it "compares elements with matching hash codes with #eql?" do
+ a = Array.new(2) do
+ obj = mock('0')
+ obj.should_receive(:hash).at_least(1).and_return(0)
- obj
+ def obj.eql?(o)
+ false
end
- a.uniq.should == a
- a[0].tainted?.should == true
- a[1].tainted?.should == true
+ obj
+ end
- a = Array.new(2) do
- obj = mock('0')
- obj.should_receive(:hash).at_least(1).and_return(0)
+ a.uniq.should == a
- def obj.eql?(o)
- # It's undefined whether the impl does a[0].eql?(a[1]) or
- # a[1].eql?(a[0]) so we taint both.
- taint
- o.taint
- true
- end
+ a = Array.new(2) do
+ obj = mock('0')
+ obj.should_receive(:hash).at_least(1).and_return(0)
- obj
+ def obj.eql?(o)
+ true
end
- a.to_enum.uniq.size.should == 1
- a[0].tainted?.should == true
- a[1].tainted?.should == true
+ obj
end
- context 'when yielded with multiple arguments' do
- before :each do
- @enum = Object.new.to_enum
- class << @enum
- def each
- yield 0, 'foo'
- yield 1, 'FOO'
- yield 2, 'bar'
- end
- end
- end
+ a.to_enum.uniq.size.should == 1
+ end
- ruby_bug '#13669', ''...'2.5' do
- it 'returns all yield arguments as an array' do
- @enum.uniq { |_, label| label.downcase }.should == [[0, 'foo'], [2, 'bar']]
+ context 'when yielded with multiple arguments' do
+ before :each do
+ @enum = Object.new.to_enum
+ class << @enum
+ def each
+ yield 0, 'foo'
+ yield 1, 'FOO'
+ yield 2, 'bar'
end
end
end
+
+ it 'returns all yield arguments as an array' do
+ @enum.uniq { |_, label| label.downcase }.should == [[0, 'foo'], [2, 'bar']]
+ end
end
end
diff --git a/spec/ruby/core/enumerable/zip_spec.rb b/spec/ruby/core/enumerable/zip_spec.rb
index 2d090f335c..c5f9a3e4d4 100644
--- a/spec/ruby/core/enumerable/zip_spec.rb
+++ b/spec/ruby/core/enumerable/zip_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Enumerable#zip" do
@@ -21,16 +21,16 @@ describe "Enumerable#zip" do
end
it "converts arguments to arrays using #to_ary" do
- convertable = EnumerableSpecs::ArrayConvertable.new(4,5,6)
- EnumerableSpecs::Numerous.new(1,2,3).zip(convertable).should == [[1,4],[2,5],[3,6]]
- convertable.called.should == :to_ary
+ convertible = EnumerableSpecs::ArrayConvertible.new(4,5,6)
+ EnumerableSpecs::Numerous.new(1,2,3).zip(convertible).should == [[1,4],[2,5],[3,6]]
+ convertible.called.should == :to_ary
end
it "converts arguments to enums using #to_enum" do
- convertable = EnumerableSpecs::EnumConvertable.new(4..6)
- EnumerableSpecs::Numerous.new(1,2,3).zip(convertable).should == [[1,4],[2,5],[3,6]]
- convertable.called.should == :to_enum
- convertable.sym.should == :each
+ convertible = EnumerableSpecs::EnumConvertible.new(4..6)
+ EnumerableSpecs::Numerous.new(1,2,3).zip(convertible).should == [[1,4],[2,5],[3,6]]
+ convertible.called.should == :to_enum
+ convertible.sym.should == :each
end
it "gathers whole arrays as elements when each yields multiple" do
@@ -38,5 +38,9 @@ describe "Enumerable#zip" do
multi.zip(multi).should == [[[1, 2], [1, 2]], [[3, 4, 5], [3, 4, 5]], [[6, 7, 8, 9], [6, 7, 8, 9]]]
end
+ it "raises TypeError when some argument isn't Array and doesn't respond to #to_ary and #to_enum" do
+ -> { EnumerableSpecs::Numerous.new(1,2,3).zip(Object.new) }.should.raise(TypeError, "wrong argument type Object (must respond to :each)")
+ -> { EnumerableSpecs::Numerous.new(1,2,3).zip(1) }.should.raise(TypeError, "wrong argument type Integer (must respond to :each)")
+ -> { EnumerableSpecs::Numerous.new(1,2,3).zip(true) }.should.raise(TypeError, "wrong argument type TrueClass (must respond to :each)")
+ end
end
-
diff --git a/spec/ruby/core/enumerator/arithmetic_sequence/begin_spec.rb b/spec/ruby/core/enumerator/arithmetic_sequence/begin_spec.rb
new file mode 100644
index 0000000000..bd243fa0b5
--- /dev/null
+++ b/spec/ruby/core/enumerator/arithmetic_sequence/begin_spec.rb
@@ -0,0 +1,16 @@
+require_relative '../../../spec_helper'
+
+describe "Enumerator::ArithmeticSequence#begin" do
+ it "returns the begin of the sequence" do
+ 1.step(10).begin.should == 1
+ (1..10).step.begin.should == 1
+ (1...10).step.begin.should == 1
+ end
+
+ context "with beginless" do
+ it "returns nil as begin of the sequence" do
+ (..10).step(1).begin.should == nil
+ (...10).step(1).begin.should == nil
+ end
+ end
+end
diff --git a/spec/ruby/core/enumerator/arithmetic_sequence/each_spec.rb b/spec/ruby/core/enumerator/arithmetic_sequence/each_spec.rb
new file mode 100644
index 0000000000..0a83019d49
--- /dev/null
+++ b/spec/ruby/core/enumerator/arithmetic_sequence/each_spec.rb
@@ -0,0 +1,17 @@
+require_relative '../../../spec_helper'
+
+describe "Enumerator::ArithmeticSequence#each" do
+ before :each do
+ ScratchPad.record []
+ @seq = 1.step(10, 4)
+ end
+
+ it "calls given block on each item of the sequence" do
+ @seq.each { |item| ScratchPad << item }
+ ScratchPad.recorded.should == [1, 5, 9]
+ end
+
+ it "returns self" do
+ @seq.each { |item| }.should.equal?(@seq)
+ end
+end
diff --git a/spec/ruby/core/enumerator/arithmetic_sequence/end_spec.rb b/spec/ruby/core/enumerator/arithmetic_sequence/end_spec.rb
new file mode 100644
index 0000000000..05429cac3e
--- /dev/null
+++ b/spec/ruby/core/enumerator/arithmetic_sequence/end_spec.rb
@@ -0,0 +1,16 @@
+require_relative '../../../spec_helper'
+
+describe "Enumerator::ArithmeticSequence#end" do
+ it "returns the end of the sequence" do
+ 1.step(10).end.should == 10
+ (1..10).step.end.should == 10
+ (1...10).step(17).end.should == 10
+ end
+
+ context "with endless" do
+ it "returns nil as end of the sequence" do
+ (1..).step(1).end.should == nil
+ (1...).step(1).end.should == nil
+ end
+ end
+end
diff --git a/spec/ruby/core/enumerator/arithmetic_sequence/eq_spec.rb b/spec/ruby/core/enumerator/arithmetic_sequence/eq_spec.rb
new file mode 100644
index 0000000000..77eed02d8b
--- /dev/null
+++ b/spec/ruby/core/enumerator/arithmetic_sequence/eq_spec.rb
@@ -0,0 +1,18 @@
+require_relative '../../../spec_helper'
+
+describe "Enumerator::ArithmeticSequence#==" do
+ it "returns true if begin, end, step and exclude_end? are equal" do
+ 1.step(10).should == 1.step(10)
+ 1.step(10, 5).should == 1.step(10, 5)
+
+ (1..10).step.should == (1..10).step
+ (1...10).step(8).should == (1...10).step(8)
+
+ # both have exclude_end? == false
+ (1..10).step(100).should == 1.step(10, 100)
+
+ ((1..10).step == (1..11).step).should == false
+ ((1..10).step == (1...10).step).should == false
+ ((1..10).step == (1..10).step(2)).should == false
+ end
+end
diff --git a/spec/ruby/core/enumerator/arithmetic_sequence/exclude_end_spec.rb b/spec/ruby/core/enumerator/arithmetic_sequence/exclude_end_spec.rb
new file mode 100644
index 0000000000..021fe7d90f
--- /dev/null
+++ b/spec/ruby/core/enumerator/arithmetic_sequence/exclude_end_spec.rb
@@ -0,0 +1,17 @@
+require_relative '../../../spec_helper'
+
+describe "Enumerator::ArithmeticSequence#exclude_end?" do
+ context "when created using Numeric#step" do
+ it "always returns false" do
+ 1.step(10).should_not.exclude_end?
+ 10.step(1).should_not.exclude_end?
+ end
+ end
+
+ context "when created using Range#step" do
+ it "mirrors range.exclude_end?" do
+ (1...10).step.should.exclude_end?
+ (1..10).step.should_not.exclude_end?
+ end
+ end
+end
diff --git a/spec/ruby/core/enumerator/arithmetic_sequence/first_spec.rb b/spec/ruby/core/enumerator/arithmetic_sequence/first_spec.rb
new file mode 100644
index 0000000000..ccd02be020
--- /dev/null
+++ b/spec/ruby/core/enumerator/arithmetic_sequence/first_spec.rb
@@ -0,0 +1,9 @@
+require_relative '../../../spec_helper'
+
+describe "Enumerator::ArithmeticSequence#first" do
+ it "returns the first element of the sequence" do
+ 1.step(10).first.should == 1
+ (1..10).step.first.should == 1
+ (1...10).step.first.should == 1
+ end
+end
diff --git a/spec/ruby/core/enumerator/arithmetic_sequence/hash_spec.rb b/spec/ruby/core/enumerator/arithmetic_sequence/hash_spec.rb
new file mode 100644
index 0000000000..a18c554fb3
--- /dev/null
+++ b/spec/ruby/core/enumerator/arithmetic_sequence/hash_spec.rb
@@ -0,0 +1,20 @@
+require_relative '../../../spec_helper'
+
+describe "Enumerator::ArithmeticSequence#hash" do
+ it "is based on begin, end, step and exclude_end?" do
+ 1.step(10).hash.should.instance_of?(Integer)
+
+ 1.step(10).hash.should == 1.step(10).hash
+ 1.step(10, 5).hash.should == 1.step(10, 5).hash
+
+ (1..10).step.hash.should == (1..10).step.hash
+ (1...10).step(8).hash.should == (1...10).step(8).hash
+
+ # both have exclude_end? == false
+ (1..10).step(100).hash.should == 1.step(10, 100).hash
+
+ ((1..10).step.hash == (1..11).step.hash).should == false
+ ((1..10).step.hash == (1...10).step.hash).should == false
+ ((1..10).step.hash == (1..10).step(2).hash).should == false
+ end
+end
diff --git a/spec/ruby/core/enumerator/arithmetic_sequence/inspect_spec.rb b/spec/ruby/core/enumerator/arithmetic_sequence/inspect_spec.rb
new file mode 100644
index 0000000000..b73b49d272
--- /dev/null
+++ b/spec/ruby/core/enumerator/arithmetic_sequence/inspect_spec.rb
@@ -0,0 +1,20 @@
+require_relative '../../../spec_helper'
+
+describe "Enumerator::ArithmeticSequence#inspect" do
+ context 'when Numeric#step is used' do
+ it "returns '(begin.step(end{, step}))'" do
+ 1.step(10).inspect.should == "(1.step(10))"
+ 1.step(10, 3).inspect.should == "(1.step(10, 3))"
+ end
+ end
+
+ context 'when Range#step is used' do
+ it "returns '((range).step{(step)})'" do
+ (1..10).step.inspect.should == "((1..10).step)"
+ (1..10).step(3).inspect.should == "((1..10).step(3))"
+
+ (1...10).step.inspect.should == "((1...10).step)"
+ (1...10).step(3).inspect.should == "((1...10).step(3))"
+ end
+ end
+end
diff --git a/spec/ruby/core/enumerator/arithmetic_sequence/last_spec.rb b/spec/ruby/core/enumerator/arithmetic_sequence/last_spec.rb
new file mode 100644
index 0000000000..31f982b7c4
--- /dev/null
+++ b/spec/ruby/core/enumerator/arithmetic_sequence/last_spec.rb
@@ -0,0 +1,9 @@
+require_relative '../../../spec_helper'
+
+describe "Enumerator::ArithmeticSequence#last" do
+ it "returns the last element of the sequence" do
+ 1.step(10).last.should == 10
+ (1..10).step.last.should == 10
+ (1...10).step(4).last.should == 9
+ end
+end
diff --git a/spec/ruby/core/enumerator/arithmetic_sequence/new_spec.rb b/spec/ruby/core/enumerator/arithmetic_sequence/new_spec.rb
new file mode 100644
index 0000000000..1bd2f7f0f7
--- /dev/null
+++ b/spec/ruby/core/enumerator/arithmetic_sequence/new_spec.rb
@@ -0,0 +1,17 @@
+require_relative '../../../spec_helper'
+
+describe "Enumerator::ArithmeticSequence.new" do
+ it "is not defined" do
+ -> {
+ Enumerator::ArithmeticSequence.new
+ }.should.raise(NoMethodError)
+ end
+end
+
+describe "Enumerator::ArithmeticSequence.allocate" do
+ it "is not defined" do
+ -> {
+ Enumerator::ArithmeticSequence.allocate
+ }.should.raise(TypeError, 'allocator undefined for Enumerator::ArithmeticSequence')
+ end
+end
diff --git a/spec/ruby/core/enumerator/arithmetic_sequence/size_spec.rb b/spec/ruby/core/enumerator/arithmetic_sequence/size_spec.rb
new file mode 100644
index 0000000000..7e03edd961
--- /dev/null
+++ b/spec/ruby/core/enumerator/arithmetic_sequence/size_spec.rb
@@ -0,0 +1,17 @@
+require_relative '../../../spec_helper'
+
+describe "Enumerator::ArithmeticSequence#size" do
+ context "for finite sequence" do
+ it "returns the number of elements in this arithmetic sequence" do
+ 1.step(10).size.should == 10
+ (1...10).step.size.should == 9
+ end
+ end
+
+ context "for infinite sequence" do
+ it "returns Infinity" do
+ 1.step(Float::INFINITY).size.should == Float::INFINITY
+ (1..Float::INFINITY).step.size.should == Float::INFINITY
+ end
+ end
+end
diff --git a/spec/ruby/core/enumerator/arithmetic_sequence/step_spec.rb b/spec/ruby/core/enumerator/arithmetic_sequence/step_spec.rb
new file mode 100644
index 0000000000..c1f2d9173f
--- /dev/null
+++ b/spec/ruby/core/enumerator/arithmetic_sequence/step_spec.rb
@@ -0,0 +1,11 @@
+require_relative '../../../spec_helper'
+
+describe "Enumerator::ArithmeticSequence#step" do
+ it "returns the original value given to step method" do
+ (1..10).step.step.should == 1
+ (1..10).step(3).step.should == 3
+
+ 1.step(10).step.should == 1
+ 1.step(10, 3).step.should == 3
+ end
+end
diff --git a/spec/ruby/core/enumerator/chain/each_spec.rb b/spec/ruby/core/enumerator/chain/each_spec.rb
new file mode 100644
index 0000000000..cc93cbac60
--- /dev/null
+++ b/spec/ruby/core/enumerator/chain/each_spec.rb
@@ -0,0 +1,15 @@
+require_relative '../../../spec_helper'
+require_relative '../../enumerable/fixtures/classes'
+
+describe "Enumerator::Chain#each" do
+ it "calls each on its constituents as needed" do
+ a = EnumerableSpecs::EachCounter.new(:a, :b)
+ b = EnumerableSpecs::EachCounter.new(:c, :d)
+
+ ScratchPad.record []
+ Enumerator::Chain.new(a, b).each do |elem|
+ ScratchPad << elem << b.times_yielded
+ end
+ ScratchPad.recorded.should == [:a, 0, :b, 0, :c, 1, :d, 2]
+ end
+end
diff --git a/spec/ruby/core/enumerator/chain/initialize_spec.rb b/spec/ruby/core/enumerator/chain/initialize_spec.rb
new file mode 100644
index 0000000000..1df1dec5f8
--- /dev/null
+++ b/spec/ruby/core/enumerator/chain/initialize_spec.rb
@@ -0,0 +1,31 @@
+require_relative '../../../spec_helper'
+
+describe "Enumerator::Chain#initialize" do
+ before :each do
+ @uninitialized = Enumerator::Chain.allocate
+ end
+
+ it "is a private method" do
+ Enumerator::Chain.private_instance_methods(false).should.include?(:initialize)
+ end
+
+ it "returns self" do
+ @uninitialized.send(:initialize).should.equal?(@uninitialized)
+ end
+
+ it "accepts many arguments" do
+ @uninitialized.send(:initialize, 0..1, 2..3, 4..5).should.equal?(@uninitialized)
+ end
+
+ it "accepts arguments that are not Enumerable nor responding to :each" do
+ @uninitialized.send(:initialize, Object.new).should.equal?(@uninitialized)
+ end
+
+ describe "on frozen instance" do
+ it "raises a FrozenError" do
+ -> {
+ @uninitialized.freeze.send(:initialize)
+ }.should.raise(FrozenError)
+ end
+ end
+end
diff --git a/spec/ruby/core/enumerator/chain/inspect_spec.rb b/spec/ruby/core/enumerator/chain/inspect_spec.rb
new file mode 100644
index 0000000000..9b5a442b75
--- /dev/null
+++ b/spec/ruby/core/enumerator/chain/inspect_spec.rb
@@ -0,0 +1,18 @@
+require_relative '../../../spec_helper'
+
+describe "Enumerator::Chain#inspect" do
+ it "shows a representation of the Enumerator" do
+ Enumerator::Chain.new.inspect.should == "#<Enumerator::Chain: []>"
+ Enumerator::Chain.new(1..2, 3..4).inspect.should == "#<Enumerator::Chain: [1..2, 3..4]>"
+ end
+
+ it "calls inspect on its chain elements" do
+ obj = mock('inspect')
+ obj.should_receive(:inspect).and_return('some desc')
+ Enumerator::Chain.new(obj).inspect.should == "#<Enumerator::Chain: [some desc]>"
+ end
+
+ it "returns a not initialized representation if #initialized is not called yet" do
+ Enumerator::Chain.allocate.inspect.should == "#<Enumerator::Chain: uninitialized>"
+ end
+end
diff --git a/spec/ruby/core/enumerator/chain/rewind_spec.rb b/spec/ruby/core/enumerator/chain/rewind_spec.rb
new file mode 100644
index 0000000000..4525b82f7b
--- /dev/null
+++ b/spec/ruby/core/enumerator/chain/rewind_spec.rb
@@ -0,0 +1,51 @@
+require_relative '../../../spec_helper'
+
+describe "Enumerator::Chain#rewind" do
+ before(:each) do
+ @obj = mock('obj')
+ @obj.should_receive(:each).any_number_of_times.and_yield
+ @second = mock('obj')
+ @second.should_receive(:each).any_number_of_times.and_yield
+ @enum = Enumerator::Chain.new(@obj, @second)
+ end
+
+ it "returns self" do
+ @enum.rewind.should.equal? @enum
+ end
+
+ it "does nothing if receiver has not been iterated" do
+ @obj.should_not_receive(:rewind)
+ @obj.respond_to?(:rewind).should == true # sanity check
+ @enum.rewind
+ end
+
+ it "does nothing on objects that don't respond_to rewind" do
+ @obj.respond_to?(:rewind).should == false # sanity check
+ @enum.each {}
+ @enum.rewind
+ end
+
+ it "calls_rewind its objects" do
+ @obj.should_receive(:rewind)
+ @enum.each {}
+ @enum.rewind
+ end
+
+ it "calls_rewind in reverse order" do
+ @obj.should_not_receive(:rewind)
+ @second.should_receive(:rewind).and_raise(RuntimeError)
+ @enum.each {}
+ -> { @enum.rewind }.should.raise(RuntimeError)
+ end
+
+ it "calls rewind only for objects that have actually been iterated on" do
+ @obj = mock('obj')
+ @obj.should_receive(:each).any_number_of_times.and_raise(RuntimeError)
+ @enum = Enumerator::Chain.new(@obj, @second)
+
+ @obj.should_receive(:rewind)
+ @second.should_not_receive(:rewind)
+ -> { @enum.each {} }.should.raise(RuntimeError)
+ @enum.rewind
+ end
+end
diff --git a/spec/ruby/core/enumerator/chain/size_spec.rb b/spec/ruby/core/enumerator/chain/size_spec.rb
new file mode 100644
index 0000000000..d85b88ee8b
--- /dev/null
+++ b/spec/ruby/core/enumerator/chain/size_spec.rb
@@ -0,0 +1,22 @@
+require_relative '../../../spec_helper'
+require_relative '../../enumerable/fixtures/classes'
+
+describe "Enumerator::Chain#size" do
+ it "returns the sum of the sizes of the elements" do
+ a = mock('size')
+ a.should_receive(:size).and_return(40)
+ Enumerator::Chain.new(a, [:a, :b]).size.should == 42
+ end
+
+ it "returns nil or Infinity for the first element of such a size" do
+ [nil, Float::INFINITY].each do |special|
+ a = mock('size')
+ a.should_receive(:size).and_return(40)
+ b = mock('special')
+ b.should_receive(:size).and_return(special)
+ c = mock('not called')
+ c.should_not_receive(:size)
+ Enumerator::Chain.new(a, b, c).size.should == special
+ end
+ end
+end
diff --git a/spec/ruby/core/enumerator/each_spec.rb b/spec/ruby/core/enumerator/each_spec.rb
index a6ecf2af2d..64912b98b6 100644
--- a/spec/ruby/core/enumerator/each_spec.rb
+++ b/spec/ruby/core/enumerator/each_spec.rb
@@ -1,5 +1,119 @@
-require File.expand_path('../../../shared/enumerator/each', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/each'
describe "Enumerator#each" do
- it_behaves_like(:enum_each, :each)
+ describe "passing source-yielded arguments to the block" do
+ before :each do
+ @object = -> e { e }
+ end
+ it_behaves_like :enum_each, nil
+ end
+
+ describe "passing source-yielded arguments to the block (lazy)" do
+ before :each do
+ @object = -> e { e.lazy }
+ end
+ it_behaves_like :enum_each, nil
+ end
+
+ before :each do
+ object_each_with_arguments = Object.new
+ def object_each_with_arguments.each_with_arguments(arg, *args)
+ yield arg, *args
+ :method_returned
+ end
+
+ @enum_with_arguments = object_each_with_arguments.to_enum(:each_with_arguments, :arg0, :arg1, :arg2)
+
+ @enum_with_yielder = Enumerator.new { |y| y.yield :ok }
+ end
+
+ it "yields each element of self to the given block" do
+ acc = []
+ [1, 2, 3].to_enum.each { |e| acc << e }
+ acc.should == [1, 2, 3]
+ end
+
+ it "calls #each on the object given in the constructor by default" do
+ each = mock('each')
+ each.should_receive(:each)
+ each.to_enum.each { |e| e }
+ end
+
+ it "calls #each on the underlying object until it's exhausted" do
+ each = mock('each')
+ each.should_receive(:each).and_yield(1).and_yield(2).and_yield(3)
+ acc = []
+ each.to_enum.each { |e| acc << e }
+ acc.should == [1, 2, 3]
+ end
+
+ it "calls the method given in the constructor instead of #each" do
+ each = mock('peach')
+ each.should_receive(:peach)
+ each.to_enum(:peach).each { |e| e }
+ end
+
+ it "calls the method given in the constructor until it's exhausted" do
+ each = mock('peach')
+ each.should_receive(:peach).and_yield(1).and_yield(2).and_yield(3)
+ acc = []
+ each.to_enum(:peach).each { |e| acc << e }
+ acc.should == [1, 2, 3]
+ end
+
+ it "raises a NoMethodError if the object doesn't respond to #each" do
+ enum = Object.new.to_enum
+ -> do
+ enum.each { |e| e }
+ end.should.raise(NoMethodError)
+ end
+
+ it "returns self if not given arguments and not given a block" do
+ @enum_with_arguments.each.should.equal?(@enum_with_arguments)
+
+ @enum_with_yielder.each.should.equal?(@enum_with_yielder)
+ end
+
+ it "returns the same value from receiver.each if block is given" do
+ @enum_with_arguments.each {}.should.equal?(:method_returned)
+ end
+
+ it "passes given arguments at initialized to receiver.each" do
+ @enum_with_arguments.each.to_a.should == [[:arg0, :arg1, :arg2]]
+ end
+
+ it "requires multiple arguments" do
+ Enumerator.instance_method(:each).arity.should < 0
+ end
+
+ it "appends given arguments to receiver.each" do
+ @enum_with_arguments.each(:each0, :each1).to_a.should == [[:arg0, :arg1, :arg2, :each0, :each1]]
+ @enum_with_arguments.each(:each2, :each3).to_a.should == [[:arg0, :arg1, :arg2, :each2, :each3]]
+ end
+
+ it "returns the same value from receiver.each if block and arguments are given" do
+ @enum_with_arguments.each(:each1, :each2) {}.should.equal?(:method_returned)
+ end
+
+ it "returns new Enumerator if given arguments but not given a block" do
+ ret = @enum_with_arguments.each 1
+ ret.should.instance_of?(Enumerator)
+ ret.should_not.equal?(@enum_with_arguments)
+ end
+
+ it "does not destructure yielded array values when chaining each.map" do
+ result = [[[1]]].each.map { |a, b| [a, b] }
+ result.should == [[[1], nil]]
+ end
+
+ it "preserves array values yielded from the enumerator" do
+ result = [[1, 2]].each.map { |a| a }
+ result.should == [[1, 2]]
+ end
+
+ it "allows destructuring to occur in the block, not the enumerator" do
+ result = [[1, 2]].each.map { |a, b| a }
+ result.should == [1]
+ end
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..0630b7045e 100644
--- a/spec/ruby/core/enumerator/each_with_index_spec.rb
+++ b/spec/ruby/core/enumerator/each_with_index_spec.rb
@@ -1,38 +1,36 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/enumerator/with_index', __FILE__)
-require File.expand_path('../../enumerable/shared/enumeratorized', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/with_index'
+require_relative '../enumerable/shared/enumeratorized'
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
enum2 = enum1.each_with_index
- enum2.should be_an_instance_of(Enumerator)
- enum1.should_not === enum2
+ enum2.should.instance_of?(Enumerator)
+ enum1.should_not == enum2
end
it "raises an ArgumentError if passed extra arguments" do
- lambda do
+ -> do
[1].to_enum.each_with_index(:glark)
- end.should raise_error(ArgumentError)
+ end.should.raise(ArgumentError)
end
it "passes on the given block's return value" do
arr = [1,2,3]
- arr.delete_if.with_index { |a,b| false }
+ arr.delete_if.each_with_index { |a,b| false }
arr.should == [1,2,3]
end
it "returns the iterator's return value" do
- [1,2,3].select.with_index { |a,b| false }.should == []
+ [1,2,3].select.each_with_index { |a,b| false }.should == []
+ [1,2,3].select.each_with_index { |a,b| true }.should == [1,2,3]
end
-end
-describe "Enumerator#each_with_index" do
it "returns the correct value if chained with itself" do
[:a].each_with_index.each_with_index.to_a.should == [[[:a,0],0]]
- [:a].each.with_index.with_index.to_a.should == [[[:a,0],0]]
end
end
diff --git a/spec/ruby/core/enumerator/each_with_object_spec.rb b/spec/ruby/core/enumerator/each_with_object_spec.rb
index ec461e2425..0e0a4496f4 100644
--- a/spec/ruby/core/enumerator/each_with_object_spec.rb
+++ b/spec/ruby/core/enumerator/each_with_object_spec.rb
@@ -1,6 +1,42 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/enumerator/with_object', __FILE__)
+require_relative '../../spec_helper'
describe "Enumerator#each_with_object" do
- it_behaves_like :enum_with_object, :each_with_object
+ before :each do
+ @enum = [:a, :b].to_enum
+ @memo = ''
+ @block_params = @enum.each_with_object(@memo).to_a
+ end
+
+ it "receives an argument" do
+ @enum.method(:each_with_object).arity.should == 1
+ end
+
+ context "with block" do
+ it "returns the given object" do
+ ret = @enum.each_with_object(@memo) do |elm, memo|
+ # nothing
+ end
+ ret.should.equal?(@memo)
+ end
+
+ context "the block parameter" do
+ it "passes each element to first parameter" do
+ @block_params[0][0].should.equal?(:a)
+ @block_params[1][0].should.equal?(:b)
+ end
+
+ it "passes the given object to last parameter" do
+ @block_params[0][1].should.equal?(@memo)
+ @block_params[1][1].should.equal?(@memo)
+ end
+ end
+ end
+
+ context "without block" do
+ it "returns new Enumerator" do
+ ret = @enum.each_with_object(@memo)
+ ret.should.instance_of?(Enumerator)
+ ret.should_not.equal?(@enum)
+ end
+ end
end
diff --git a/spec/ruby/core/enumerator/enum_for_spec.rb b/spec/ruby/core/enumerator/enum_for_spec.rb
deleted file mode 100644
index 43c11e5a39..0000000000
--- a/spec/ruby/core/enumerator/enum_for_spec.rb
+++ /dev/null
@@ -1,6 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/enumerator/enum_for', __FILE__)
-
-describe "Enumerator#enum_for" do
- it_behaves_like :enum_for, :enum_for
-end
diff --git a/spec/ruby/core/enumerator/enumerator_spec.rb b/spec/ruby/core/enumerator/enumerator_spec.rb
index 2d5213edd9..7a263336cb 100644
--- a/spec/ruby/core/enumerator/enumerator_spec.rb
+++ b/spec/ruby/core/enumerator/enumerator_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Enumerator" do
it "includes Enumerable" do
diff --git a/spec/ruby/core/enumerator/feed_spec.rb b/spec/ruby/core/enumerator/feed_spec.rb
index 32ea77a30d..781947a8c7 100644
--- a/spec/ruby/core/enumerator/feed_spec.rb
+++ b/spec/ruby/core/enumerator/feed_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/common', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/common'
describe "Enumerator#feed" do
before :each do
@@ -33,20 +33,20 @@ describe "Enumerator#feed" do
end
it "returns nil" do
- @enum.feed(:a).should be_nil
+ @enum.feed(:a).should == nil
end
it "raises a TypeError if called more than once without advancing the enumerator" do
@enum.feed :a
@enum.next
- lambda { @enum.feed :b }.should raise_error(TypeError)
+ -> { @enum.feed :b }.should.raise(TypeError)
end
it "sets the return value of Yielder#yield" do
enum = Enumerator.new { |y| ScratchPad << y.yield }
enum.next
enum.feed :a
- lambda { enum.next }.should raise_error(StopIteration)
+ -> { enum.next }.should.raise(StopIteration)
ScratchPad.recorded.should == [:a]
end
end
diff --git a/spec/ruby/core/enumerator/first_spec.rb b/spec/ruby/core/enumerator/first_spec.rb
index ba3b0df492..458080bb31 100644
--- a/spec/ruby/core/enumerator/first_spec.rb
+++ b/spec/ruby/core/enumerator/first_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Enumerator#first" do
it "returns arrays correctly when calling #first (2376)" do
diff --git a/spec/ruby/fixtures/enumerator/classes.rb b/spec/ruby/core/enumerator/fixtures/classes.rb
index 6f285b8efa..6f285b8efa 100644
--- a/spec/ruby/fixtures/enumerator/classes.rb
+++ b/spec/ruby/core/enumerator/fixtures/classes.rb
diff --git a/spec/ruby/core/enumerator/generator/each_spec.rb b/spec/ruby/core/enumerator/generator/each_spec.rb
deleted file mode 100644
index 06395d0aa0..0000000000
--- a/spec/ruby/core/enumerator/generator/each_spec.rb
+++ /dev/null
@@ -1,40 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-
-describe "Enumerator::Generator#each" do
- before :each do
- @generator = Enumerator::Generator.new do |y, *args|
- y << 3 << 2 << 1
- y << args unless args.empty?
- :block_returned
- end
- end
-
- it "is an enumerable" do
- @generator.should be_kind_of(Enumerable)
- end
-
- it "supports enumeration with a block" do
- r = []
- @generator.each { |v| r << v }
-
- r.should == [3, 2, 1]
- end
-
- it "raises a LocalJumpError if no block given" do
- lambda { @generator.each }.should raise_error(LocalJumpError)
- end
-
- it "returns the block returned value" do
- @generator.each {}.should equal(:block_returned)
- end
-
- it "requires multiple arguments" do
- Enumerator::Generator.instance_method(:each).arity.should < 0
- end
-
- it "appends given arguments to receiver.each" do
- yields = []
- @generator.each(:each0, :each1) { |yielded| yields << yielded }
- yields.should == [3, 2, 1, [:each0, :each1]]
- end
-end
diff --git a/spec/ruby/core/enumerator/generator/initialize_spec.rb b/spec/ruby/core/enumerator/generator/initialize_spec.rb
deleted file mode 100644
index 85b0e04354..0000000000
--- a/spec/ruby/core/enumerator/generator/initialize_spec.rb
+++ /dev/null
@@ -1,26 +0,0 @@
-# -*- encoding: us-ascii -*-
-
-require File.expand_path('../../../../spec_helper', __FILE__)
-
-describe "Enumerator::Generator#initialize" do
- before :each do
- @class = Enumerator::Generator
- @uninitialized = @class.allocate
- end
-
- it "is a private method" do
- @class.should have_private_instance_method(:initialize, false)
- end
-
- it "returns self when given a block" do
- @uninitialized.send(:initialize) {}.should equal(@uninitialized)
- end
-
- describe "on frozen instance" do
- it "raises a RuntimeError" do
- lambda {
- @uninitialized.freeze.send(:initialize) {}
- }.should raise_error(RuntimeError)
- end
- end
-end
diff --git a/spec/ruby/core/enumerator/initialize_spec.rb b/spec/ruby/core/enumerator/initialize_spec.rb
index 58f8a5e865..9929494b5a 100644
--- a/spec/ruby/core/enumerator/initialize_spec.rb
+++ b/spec/ruby/core/enumerator/initialize_spec.rb
@@ -1,6 +1,6 @@
# -*- encoding: us-ascii -*-
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Enumerator#initialize" do
before :each do
@@ -8,15 +8,11 @@ describe "Enumerator#initialize" do
end
it "is a private method" do
- Enumerator.should have_private_instance_method(:initialize, false)
- end
-
- it "returns self when given an object" do
- @uninitialized.send(:initialize, Object.new).should equal(@uninitialized)
+ Enumerator.private_instance_methods(false).should.include?(:initialize)
end
it "returns self when given a block" do
- @uninitialized.send(:initialize) {}.should equal(@uninitialized)
+ @uninitialized.send(:initialize) {}.should.equal?(@uninitialized)
end
# Maybe spec should be broken up?
@@ -25,37 +21,37 @@ describe "Enumerator#initialize" do
r = yielder.yield 3
yielder << r << 2 << 1
end
- @uninitialized.should be_an_instance_of(Enumerator)
+ @uninitialized.should.instance_of?(Enumerator)
r = []
@uninitialized.each{|x| r << x; x * 2}
r.should == [3, 6, 2, 1]
end
it "sets size to nil if size is not given" do
- @uninitialized.send(:initialize) {}.size.should be_nil
+ @uninitialized.send(:initialize) {}.size.should == nil
end
it "sets size to nil if the given size is nil" do
- @uninitialized.send(:initialize, nil) {}.size.should be_nil
+ @uninitialized.send(:initialize, nil) {}.size.should == nil
end
it "sets size to the given size if the given size is Float::INFINITY" do
- @uninitialized.send(:initialize, Float::INFINITY) {}.size.should equal(Float::INFINITY)
+ @uninitialized.send(:initialize, Float::INFINITY) {}.size.should.equal?(Float::INFINITY)
end
- it "sets size to the given size if the given size is a Fixnum" do
+ it "sets size to the given size if the given size is an Integer" do
@uninitialized.send(:initialize, 100) {}.size.should == 100
end
it "sets size to the given size if the given size is a Proc" do
- @uninitialized.send(:initialize, lambda { 200 }) {}.size.should == 200
+ @uninitialized.send(:initialize, -> { 200 }) {}.size.should == 200
end
describe "on frozen instance" do
- it "raises a RuntimeError" do
- lambda {
+ it "raises a FrozenError" do
+ -> {
@uninitialized.freeze.send(:initialize) {}
- }.should raise_error(RuntimeError)
+ }.should.raise(FrozenError)
end
end
end
diff --git a/spec/ruby/core/enumerator/inject_spec.rb b/spec/ruby/core/enumerator/inject_spec.rb
deleted file mode 100644
index 64085a03c5..0000000000
--- a/spec/ruby/core/enumerator/inject_spec.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-require File.expand_path('../../../shared/enumerator/each', __FILE__)
-
-describe "Enumerator#inject" do
- it_behaves_like(:enum_each, :each)
-
- it "works when chained against each_with_index" do
- passed_values = []
- [:a].each_with_index.inject(0) do |accumulator,value|
- passed_values << value
- accumulator + 1
- end.should == 1
- passed_values.should == [[:a,0]]
- end
-
-end
diff --git a/spec/ruby/core/enumerator/inspect_spec.rb b/spec/ruby/core/enumerator/inspect_spec.rb
index b708256247..7e97864246 100644
--- a/spec/ruby/core/enumerator/inspect_spec.rb
+++ b/spec/ruby/core/enumerator/inspect_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Enumerator#inspect" do
describe "shows a representation of the Enumerator" do
@@ -14,4 +14,9 @@ describe "Enumerator#inspect" do
(1..3).each.each_slice(2).inspect.should == "#<Enumerator: #<Enumerator: 1..3:each>:each_slice(2)>"
end
end
+
+ it "returns a not initialized representation if #initialized is not called yet" do
+ Enumerator.allocate.inspect.should == "#<Enumerator: uninitialized>"
+ Enumerator::Lazy.allocate.inspect.should == "#<Enumerator::Lazy: uninitialized>"
+ end
end
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..d0179d32b6
--- /dev/null
+++ b/spec/ruby/core/enumerator/lazy/chunk_spec.rb
@@ -0,0 +1,67 @@
+# -*- encoding: us-ascii -*-
+
+require_relative '../../../spec_helper'
+require_relative 'fixtures/classes'
+
+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.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
+
+ it "returns an Enumerator if called without a block" do
+ chunk = @yieldsmixed.chunk
+ chunk.should.instance_of?(Enumerator::Lazy)
+
+ res = chunk.each { |v| true }.force
+ res.should == [[true, EnumeratorLazySpecs::YieldsMixed.gathered_yields]]
+ end
+
+ describe "when the returned lazy enumerator is evaluated by Enumerable#first" do
+ 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
+
+ it "works with an infinite enumerable" do
+ s = 0..Float::INFINITY
+ s.lazy.chunk { |n| n.even? }.first(100).should ==
+ s.first(100).chunk { |n| n.even? }.to_a
+ end
+end
diff --git a/spec/ruby/core/enumerator/lazy/chunk_while_spec.rb b/spec/ruby/core/enumerator/lazy/chunk_while_spec.rb
new file mode 100644
index 0000000000..edba8e1363
--- /dev/null
+++ b/spec/ruby/core/enumerator/lazy/chunk_while_spec.rb
@@ -0,0 +1,14 @@
+require_relative '../../../spec_helper'
+
+describe "Enumerator::Lazy#chunk_while" do
+ it "works with an infinite enumerable" do
+ s = 0..Float::INFINITY
+ s.lazy.chunk_while { |a, b| false }.first(100).should ==
+ s.first(100).chunk_while { |a, b| false }.to_a
+ end
+
+ it "should return a lazy enumerator" do
+ s = 0..Float::INFINITY
+ s.lazy.chunk_while { |a, b| false }.should.is_a?(Enumerator::Lazy)
+ end
+end
diff --git a/spec/ruby/core/enumerator/lazy/collect_concat_spec.rb b/spec/ruby/core/enumerator/lazy/collect_concat_spec.rb
index 8c19dcbbf9..d9fd576e43 100644
--- a/spec/ruby/core/enumerator/lazy/collect_concat_spec.rb
+++ b/spec/ruby/core/enumerator/lazy/collect_concat_spec.rb
@@ -1,8 +1,8 @@
-# -*- encoding: us-ascii -*-
-
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/collect_concat', __FILE__)
+require_relative '../../../spec_helper'
describe "Enumerator::Lazy#collect_concat" do
- it_behaves_like :enumerator_lazy_collect_concat, :collect_concat
+ it "is an alias of Enumerator::Lazy#flat_map" do
+ Enumerator::Lazy.instance_method(:collect_concat).should ==
+ Enumerator::Lazy.instance_method(:flat_map)
+ end
end
diff --git a/spec/ruby/core/enumerator/lazy/collect_spec.rb b/spec/ruby/core/enumerator/lazy/collect_spec.rb
index 764b8af36d..53a477e053 100644
--- a/spec/ruby/core/enumerator/lazy/collect_spec.rb
+++ b/spec/ruby/core/enumerator/lazy/collect_spec.rb
@@ -1,8 +1,8 @@
-# -*- encoding: us-ascii -*-
-
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/collect', __FILE__)
+require_relative '../../../spec_helper'
describe "Enumerator::Lazy#collect" do
- it_behaves_like :enumerator_lazy_collect, :collect
+ it "is an alias of Enumerator::Lazy#map" do
+ Enumerator::Lazy.instance_method(:collect).should ==
+ Enumerator::Lazy.instance_method(:map)
+ end
end
diff --git a/spec/ruby/core/enumerator/lazy/compact_spec.rb b/spec/ruby/core/enumerator/lazy/compact_spec.rb
new file mode 100644
index 0000000000..7305e1c9c4
--- /dev/null
+++ b/spec/ruby/core/enumerator/lazy/compact_spec.rb
@@ -0,0 +1,14 @@
+require_relative '../../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe "Enumerator::Lazy#compact" do
+ it 'returns array without nil elements' do
+ arr = [1, nil, 3, false, 5].to_enum.lazy.compact
+ arr.should.instance_of?(Enumerator::Lazy)
+ arr.force.should == [1, 3, false, 5]
+ end
+
+ it "sets #size to nil" do
+ Enumerator::Lazy.new(Object.new, 100) {}.compact.size.should == nil
+ end
+end
diff --git a/spec/ruby/core/enumerator/lazy/drop_spec.rb b/spec/ruby/core/enumerator/lazy/drop_spec.rb
index eb65bb246b..95ac7e9ecc 100644
--- a/spec/ruby/core/enumerator/lazy/drop_spec.rb
+++ b/spec/ruby/core/enumerator/lazy/drop_spec.rb
@@ -1,7 +1,7 @@
# -*- encoding: us-ascii -*-
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'fixtures/classes'
describe "Enumerator::Lazy#drop" do
before :each do
@@ -16,8 +16,8 @@ describe "Enumerator::Lazy#drop" do
it "returns a new instance of Enumerator::Lazy" do
ret = @yieldsmixed.drop(1)
- ret.should be_an_instance_of(Enumerator::Lazy)
- ret.should_not equal(@yieldsmixed)
+ ret.should.instance_of?(Enumerator::Lazy)
+ ret.should_not.equal?(@yieldsmixed)
end
it "sets difference of given count with old size to new size" do
@@ -49,4 +49,10 @@ describe "Enumerator::Lazy#drop" do
end
end
end
+
+ it "works with an infinite enumerable" do
+ s = 0..Float::INFINITY
+ s.lazy.drop(100).first(100).should ==
+ s.first(200).drop(100)
+ end
end
diff --git a/spec/ruby/core/enumerator/lazy/drop_while_spec.rb b/spec/ruby/core/enumerator/lazy/drop_while_spec.rb
index a08644a20c..65f3007dec 100644
--- a/spec/ruby/core/enumerator/lazy/drop_while_spec.rb
+++ b/spec/ruby/core/enumerator/lazy/drop_while_spec.rb
@@ -1,7 +1,7 @@
# -*- encoding: us-ascii -*-
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'fixtures/classes'
describe "Enumerator::Lazy#drop_while" do
before :each do
@@ -16,8 +16,8 @@ describe "Enumerator::Lazy#drop_while" do
it "returns a new instance of Enumerator::Lazy" do
ret = @yieldsmixed.drop_while {}
- ret.should be_an_instance_of(Enumerator::Lazy)
- ret.should_not equal(@yieldsmixed)
+ ret.should.instance_of?(Enumerator::Lazy)
+ ret.should_not.equal?(@yieldsmixed)
end
it "sets #size to nil" do
@@ -40,7 +40,7 @@ describe "Enumerator::Lazy#drop_while" do
end
it "raises an ArgumentError when not given a block" do
- lambda { @yieldsmixed.drop_while }.should raise_error(ArgumentError)
+ -> { @yieldsmixed.drop_while }.should.raise(ArgumentError)
end
describe "on a nested Lazy" do
@@ -57,4 +57,10 @@ describe "Enumerator::Lazy#drop_while" do
end
end
end
+
+ it "works with an infinite enumerable" do
+ s = 0..Float::INFINITY
+ s.lazy.drop_while { |n| n < 100 }.first(100).should ==
+ s.first(200).drop_while { |n| n < 100 }
+ end
end
diff --git a/spec/ruby/core/enumerator/lazy/eager_spec.rb b/spec/ruby/core/enumerator/lazy/eager_spec.rb
new file mode 100644
index 0000000000..592da4fd8c
--- /dev/null
+++ b/spec/ruby/core/enumerator/lazy/eager_spec.rb
@@ -0,0 +1,27 @@
+require_relative '../../../spec_helper'
+
+describe "Enumerator::Lazy#eager" do
+ it "returns a non-lazy Enumerator converted from the lazy enumerator" do
+ enum = [1, 2, 3].lazy
+
+ enum.class.should == Enumerator::Lazy
+ enum.eager.class.should == Enumerator
+ end
+
+ it "does not enumerate an enumerator" do
+ ScratchPad.record []
+
+ sequence = [1, 2, 3]
+ enum_lazy = Enumerator::Lazy.new(sequence) do |yielder, value|
+ yielder << value
+ ScratchPad << value
+ end
+
+ ScratchPad.recorded.should == []
+ enum = enum_lazy.eager
+ ScratchPad.recorded.should == []
+
+ enum.map { |i| i }.should == [1, 2, 3]
+ ScratchPad.recorded.should == [1, 2, 3]
+ end
+end
diff --git a/spec/ruby/core/enumerator/lazy/enum_for_spec.rb b/spec/ruby/core/enumerator/lazy/enum_for_spec.rb
index b2ef2c881e..b40c5d9915 100644
--- a/spec/ruby/core/enumerator/lazy/enum_for_spec.rb
+++ b/spec/ruby/core/enumerator/lazy/enum_for_spec.rb
@@ -1,8 +1,8 @@
-# -*- encoding: us-ascii -*-
-
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/to_enum', __FILE__)
+require_relative '../../../spec_helper'
describe "Enumerator::Lazy#enum_for" do
- it_behaves_like :enumerator_lazy_to_enum, :enum_for
+ it "is an alias of Enumerator::Lazy#to_enum" do
+ Enumerator::Lazy.instance_method(:enum_for).should ==
+ Enumerator::Lazy.instance_method(:to_enum)
+ end
end
diff --git a/spec/ruby/core/enumerator/lazy/filter_map_spec.rb b/spec/ruby/core/enumerator/lazy/filter_map_spec.rb
new file mode 100644
index 0000000000..99dd59cebe
--- /dev/null
+++ b/spec/ruby/core/enumerator/lazy/filter_map_spec.rb
@@ -0,0 +1,14 @@
+# -*- encoding: us-ascii -*-
+
+require_relative '../../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe "Enumerator::Lazy#filter_map" do
+ it "maps only truthy results" do
+ (1..Float::INFINITY).lazy.filter_map { |i| i if i.odd? }.first(4).should == [1, 3, 5, 7]
+ end
+
+ it "does not map false results" do
+ (1..Float::INFINITY).lazy.filter_map { |i| i.odd? ? i : false }.first(4).should == [1, 3, 5, 7]
+ end
+end
diff --git a/spec/ruby/core/enumerator/lazy/filter_spec.rb b/spec/ruby/core/enumerator/lazy/filter_spec.rb
new file mode 100644
index 0000000000..3ca5376faa
--- /dev/null
+++ b/spec/ruby/core/enumerator/lazy/filter_spec.rb
@@ -0,0 +1,8 @@
+require_relative '../../../spec_helper'
+
+describe "Enumerator::Lazy#filter" do
+ it "is an alias of Enumerator::Lazy#select" do
+ Enumerator::Lazy.instance_method(:filter).should ==
+ Enumerator::Lazy.instance_method(:select)
+ end
+end
diff --git a/spec/ruby/core/enumerator/lazy/find_all_spec.rb b/spec/ruby/core/enumerator/lazy/find_all_spec.rb
index ab2e69c857..64930dc61b 100644
--- a/spec/ruby/core/enumerator/lazy/find_all_spec.rb
+++ b/spec/ruby/core/enumerator/lazy/find_all_spec.rb
@@ -1,8 +1,8 @@
-# -*- encoding: us-ascii -*-
-
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/select', __FILE__)
+require_relative '../../../spec_helper'
describe "Enumerator::Lazy#find_all" do
- it_behaves_like :enumerator_lazy_select, :find_all
+ it "is an alias of Enumerator::Lazy#select" do
+ Enumerator::Lazy.instance_method(:find_all).should ==
+ Enumerator::Lazy.instance_method(:select)
+ end
end
diff --git a/spec/ruby/core/enumerator/lazy/flat_map_spec.rb b/spec/ruby/core/enumerator/lazy/flat_map_spec.rb
index b7fba5e81c..609bf95b9e 100644
--- a/spec/ruby/core/enumerator/lazy/flat_map_spec.rb
+++ b/spec/ruby/core/enumerator/lazy/flat_map_spec.rb
@@ -1,8 +1,84 @@
-# -*- encoding: us-ascii -*-
-
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/collect_concat', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'fixtures/classes'
describe "Enumerator::Lazy#flat_map" do
- it_behaves_like :enumerator_lazy_collect_concat, :flat_map
+ 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.flat_map {}
+ ret.should.instance_of?(Enumerator::Lazy)
+ ret.should_not.equal?(@yieldsmixed)
+ end
+
+ it "sets #size to nil" do
+ Enumerator::Lazy.new(Object.new, 100) {}.flat_map { true }.size.should == nil
+ end
+
+ describe "when the returned lazy enumerator is evaluated by Enumerable#first" do
+ it "stops after specified times" do
+ (0..Float::INFINITY).lazy.flat_map { |n| (n * 10).to_s }.first(6).should == %w[0 10 20 30 40 50]
+
+ @eventsmixed.flat_map {}.first(1)
+ ScratchPad.recorded.should == [:before_yield]
+ end
+
+ it "flattens elements when the given block returned an array or responding to .each and .force" do
+ (0..Float::INFINITY).lazy.flat_map { |n| (n * 10).to_s.chars }.first(6).should == %w[0 1 0 2 0 3]
+ (0..Float::INFINITY).lazy.flat_map { |n| (n * 10).to_s.each_char }.first(6).all? { |o| o.instance_of? Enumerator }.should == true
+ (0..Float::INFINITY).lazy.flat_map { |n| (n * 10).to_s.each_char.lazy }.first(6).should == %w[0 1 0 2 0 3]
+ end
+ end
+
+ it "calls the block with initial values when yield with multiple arguments" do
+ yields = []
+ @yieldsmixed.flat_map { |v| yields << v }.force
+ yields.should == EnumeratorLazySpecs::YieldsMixed.initial_yields
+ end
+
+ it "raises an ArgumentError when not given a block" do
+ -> { @yieldsmixed.flat_map }.should.raise(ArgumentError)
+ end
+
+ describe "on a nested Lazy" do
+ it "sets #size to nil" do
+ Enumerator::Lazy.new(Object.new, 100) {}.take(50) {}.flat_map {}.size.should == nil
+ end
+
+ describe "when the returned lazy enumerator is evaluated by Enumerable#first" do
+ it "stops after specified times" do
+ (0..Float::INFINITY).lazy.map {|n| n * 10 }.flat_map { |n| n.to_s }.first(6).should == %w[0 10 20 30 40 50]
+
+ @eventsmixed.flat_map {}.flat_map {}.first(1)
+ ScratchPad.recorded.should == [:before_yield]
+ end
+
+ it "flattens elements when the given block returned an array or responding to .each and .force" do
+ (0..Float::INFINITY).lazy.map {|n| n * 10 }.flat_map { |n| n.to_s.chars }.first(6).should == %w[0 1 0 2 0 3]
+ (0..Float::INFINITY).lazy.map {|n| n * 10 }.flat_map { |n| n.to_s.each_char }.first(6).all? { |o| o.instance_of? Enumerator }.should == true
+ (0..Float::INFINITY).lazy.map {|n| n * 10 }.flat_map { |n| n.to_s.each_char.lazy }.first(6).should == %w[0 1 0 2 0 3]
+ end
+ end
+ end
+
+ it "works with an infinite enumerable" do
+ s = 0..Float::INFINITY
+ s.lazy.flat_map { |n| [-n, +n] }.first(200).should ==
+ s.first(100).flat_map { |n| [-n, +n] }.to_a
+ end
+
+ it "properly unwraps nested yields" do
+ s = Enumerator.new do |y| loop do y << [1, 2] end end
+
+ expected = s.take(3).flat_map { |x| x }.to_a
+ actual = s.lazy.take(3).flat_map{ |x| x }.force
+ actual.should == expected
+ end
end
diff --git a/spec/ruby/core/enumerator/lazy/force_spec.rb b/spec/ruby/core/enumerator/lazy/force_spec.rb
index 1a218c1b0f..a7fa029135 100644
--- a/spec/ruby/core/enumerator/lazy/force_spec.rb
+++ b/spec/ruby/core/enumerator/lazy/force_spec.rb
@@ -1,7 +1,7 @@
# -*- encoding: us-ascii -*-
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'fixtures/classes'
describe "Enumerator::Lazy#force" do
before :each do
@@ -27,4 +27,10 @@ describe "Enumerator::Lazy#force" do
ScratchPad.recorded.should == [:before_yield]
end
end
+
+ it "works with an infinite enumerable" do
+ s = 0..Float::INFINITY
+ s.lazy.take(100).force.should ==
+ s.take(100)
+ end
end
diff --git a/spec/ruby/core/enumerator/lazy/grep_spec.rb b/spec/ruby/core/enumerator/lazy/grep_spec.rb
index 372be80d61..383f80a918 100644
--- a/spec/ruby/core/enumerator/lazy/grep_spec.rb
+++ b/spec/ruby/core/enumerator/lazy/grep_spec.rb
@@ -1,7 +1,7 @@
# -*- encoding: us-ascii -*-
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'fixtures/classes'
describe "Enumerator::Lazy#grep" do
before :each do
@@ -20,12 +20,12 @@ describe "Enumerator::Lazy#grep" do
it "returns a new instance of Enumerator::Lazy" do
ret = @yieldsmixed.grep(Object) {}
- ret.should be_an_instance_of(Enumerator::Lazy)
- ret.should_not equal(@yieldsmixed)
+ ret.should.instance_of?(Enumerator::Lazy)
+ ret.should_not.equal?(@yieldsmixed)
ret = @yieldsmixed.grep(Object)
- ret.should be_an_instance_of(Enumerator::Lazy)
- ret.should_not equal(@yieldsmixed)
+ ret.should.instance_of?(Enumerator::Lazy)
+ ret.should_not.equal?(@yieldsmixed)
end
it "sets #size to nil" do
@@ -33,6 +33,39 @@ describe "Enumerator::Lazy#grep" do
Enumerator::Lazy.new(Object.new, 100) {}.grep(Object).size.should == nil
end
+ it "sets $~ in the block" do
+ "z" =~ /z/ # Reset $~
+ ["abc", "def"].lazy.grep(/b/) { |e|
+ e.should == "abc"
+ $&.should == "b"
+ }.force
+
+ # Set by the failed match of "def"
+ $~.should == nil
+ end
+
+ it "sets $~ in the next block with each" do
+ "z" =~ /z/ # Reset $~
+ ["abc", "def"].lazy.grep(/b/).each { |e|
+ e.should == "abc"
+ $&.should == "b"
+ }
+
+ # Set by the failed match of "def"
+ $~.should == nil
+ end
+
+ it "sets $~ in the next block with map" do
+ "z" =~ /z/ # Reset $~
+ ["abc", "def"].lazy.grep(/b/).map { |e|
+ e.should == "abc"
+ $&.should == "b"
+ }.force
+
+ # Set by the failed match of "def"
+ $~.should == nil
+ end
+
describe "when the returned lazy enumerator is evaluated by Enumerable#first" do
it "stops after specified times when not given a block" do
(0..Float::INFINITY).lazy.grep(Integer).first(3).should == [0, 1, 2]
@@ -79,4 +112,10 @@ describe "Enumerator::Lazy#grep" do
end
end
end
+
+ it "works with an infinite enumerable" do
+ s = 0..Float::INFINITY
+ s.lazy.grep(Numeric).first(100).should ==
+ s.first(100).grep(Numeric)
+ end
end
diff --git a/spec/ruby/core/enumerator/lazy/grep_v_spec.rb b/spec/ruby/core/enumerator/lazy/grep_v_spec.rb
index 123cbae58c..19c917f254 100644
--- a/spec/ruby/core/enumerator/lazy/grep_v_spec.rb
+++ b/spec/ruby/core/enumerator/lazy/grep_v_spec.rb
@@ -1,86 +1,123 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-
-ruby_version_is "2.3" do
- describe "Enumerator::Lazy#grep_v" do
- before(:each) do
- @yieldsmixed = EnumeratorLazySpecs::YieldsMixed.new.to_enum.lazy
- @eventsmixed = EnumeratorLazySpecs::EventsMixed.new.to_enum.lazy
- ScratchPad.record []
- end
+require_relative '../../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe "Enumerator::Lazy#grep_v" 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
+ after(:each) do
+ ScratchPad.clear
+ end
+
+ it "requires an argument" do
+ Enumerator::Lazy.instance_method(:grep_v).arity.should == 1
+ end
+
+ it "returns a new instance of Enumerator::Lazy" do
+ ret = @yieldsmixed.grep_v(Object) {}
+ ret.should.instance_of?(Enumerator::Lazy)
+ ret.should_not.equal?(@yieldsmixed)
+
+ ret = @yieldsmixed.grep_v(Object)
+ ret.should.instance_of?(Enumerator::Lazy)
+ ret.should_not.equal?(@yieldsmixed)
+ end
+
+ it "sets #size to nil" do
+ Enumerator::Lazy.new(Object.new, 100) {}.grep_v(Object) {}.size.should == nil
+ Enumerator::Lazy.new(Object.new, 100) {}.grep_v(Object).size.should == nil
+ end
+
+ it "sets $~ in the block" do
+ "z" =~ /z/ # Reset $~
+ ["abc", "def"].lazy.grep_v(/e/) { |e|
+ e.should == "abc"
+ $~.should == nil
+ }.force
+
+ # Set by the match of "def"
+ $&.should == "e"
+ end
+
+ it "sets $~ in the next block with each" do
+ "z" =~ /z/ # Reset $~
+ ["abc", "def"].lazy.grep_v(/e/).each { |e|
+ e.should == "abc"
+ $~.should == nil
+ }
+
+ # Set by the match of "def"
+ $&.should == "e"
+ end
+
+ it "sets $~ in the next block with map" do
+ "z" =~ /z/ # Reset $~
+ ["abc", "def"].lazy.grep_v(/e/).map { |e|
+ e.should == "abc"
+ $~.should == nil
+ }.force
- it "requires an argument" do
- Enumerator::Lazy.instance_method(:grep_v).arity.should == 1
+ # Set by the match of "def"
+ $&.should == "e"
+ end
+
+ describe "when the returned lazy enumerator is evaluated by Enumerable#first" do
+ it "stops after specified times when not given a block" do
+ (0..Float::INFINITY).lazy.grep_v(3..5).first(3).should == [0, 1, 2]
+
+ @eventsmixed.grep_v(Symbol).first(1)
+ ScratchPad.recorded.should == [:before_yield]
end
- it "returns a new instance of Enumerator::Lazy" do
- ret = @yieldsmixed.grep_v(Object) {}
- ret.should be_an_instance_of(Enumerator::Lazy)
- ret.should_not equal(@yieldsmixed)
+ it "stops after specified times when given a block" do
+ (0..Float::INFINITY).lazy.grep_v(4..8, &:succ).first(3).should == [1, 2, 3]
- ret = @yieldsmixed.grep_v(Object)
- ret.should be_an_instance_of(Enumerator::Lazy)
- ret.should_not equal(@yieldsmixed)
+ @eventsmixed.grep_v(Symbol) {}.first(1)
+ ScratchPad.recorded.should == [:before_yield]
end
+ end
+
+ it "calls the block with a gathered array when yield with multiple arguments" do
+ yields = []
+ @yieldsmixed.grep_v(Array) { |v| yields << v }.force
+ yields.should == EnumeratorLazySpecs::YieldsMixed.gathered_non_array_yields
+ @yieldsmixed.grep_v(Array).force.should == yields
+ end
+
+ describe "on a nested Lazy" do
it "sets #size to nil" do
- Enumerator::Lazy.new(Object.new, 100) {}.grep_v(Object) {}.size.should == nil
- Enumerator::Lazy.new(Object.new, 100) {}.grep_v(Object).size.should == nil
+ Enumerator::Lazy.new(Object.new, 100) {}.grep_v(Object).grep_v(Object) {}.size.should == nil
+ Enumerator::Lazy.new(Object.new, 100) {}.grep_v(Object).grep_v(Object).size.should == nil
end
describe "when the returned lazy enumerator is evaluated by Enumerable#first" do
it "stops after specified times when not given a block" do
- (0..Float::INFINITY).lazy.grep_v(3..5).first(3).should == [0, 1, 2]
+ (0..Float::INFINITY).lazy.grep_v(3..5).grep_v(6..10).first(3).should == [0, 1, 2]
- @eventsmixed.grep_v(Symbol).first(1)
+ @eventsmixed.grep_v(Symbol).grep_v(String).first(1)
ScratchPad.recorded.should == [:before_yield]
end
it "stops after specified times when given a block" do
- (0..Float::INFINITY).lazy.grep_v(4..8, &:succ).first(3).should == [1, 2, 3]
+ (0..Float::INFINITY).lazy
+ .grep_v(1..2) { |n| n > 3 ? n : false }
+ .grep_v(false) { |n| n.even? ? n : false }
+ .first(3)
+ .should == [4, false, 6]
- @eventsmixed.grep_v(Symbol) {}.first(1)
+ @eventsmixed.grep_v(Symbol) {}.grep_v(String) {}.first(1)
ScratchPad.recorded.should == [:before_yield]
end
end
+ end
- it "calls the block with a gathered array when yield with multiple arguments" do
- yields = []
- @yieldsmixed.grep_v(Array) { |v| yields << v }.force
- yields.should == EnumeratorLazySpecs::YieldsMixed.gathered_non_array_yields
-
- @yieldsmixed.grep_v(Array).force.should == yields
- end
-
- describe "on a nested Lazy" do
- it "sets #size to nil" do
- Enumerator::Lazy.new(Object.new, 100) {}.grep_v(Object).grep_v(Object) {}.size.should == nil
- Enumerator::Lazy.new(Object.new, 100) {}.grep_v(Object).grep_v(Object).size.should == nil
- end
-
- describe "when the returned lazy enumerator is evaluated by Enumerable#first" do
- it "stops after specified times when not given a block" do
- (0..Float::INFINITY).lazy.grep_v(3..5).grep_v(6..10).first(3).should == [0, 1, 2]
-
- @eventsmixed.grep_v(Symbol).grep_v(String).first(1)
- ScratchPad.recorded.should == [:before_yield]
- end
-
- it "stops after specified times when given a block" do
- (0..Float::INFINITY).lazy
- .grep_v(1..2) { |n| n > 3 ? n : false }
- .grep_v(false) { |n| n.even? ? n : false }
- .first(3)
- .should == [4, false, 6]
-
- @eventsmixed.grep_v(Symbol) {}.grep_v(String) {}.first(1)
- ScratchPad.recorded.should == [:before_yield]
- end
- end
- end
+ it "works with an infinite enumerable" do
+ s = 0..Float::INFINITY
+ s.lazy.grep_v(String).first(100).should ==
+ s.first(100).grep_v(String)
end
end
diff --git a/spec/ruby/core/enumerator/lazy/initialize_spec.rb b/spec/ruby/core/enumerator/lazy/initialize_spec.rb
index 47eeafb5cf..47765d32c3 100644
--- a/spec/ruby/core/enumerator/lazy/initialize_spec.rb
+++ b/spec/ruby/core/enumerator/lazy/initialize_spec.rb
@@ -1,6 +1,6 @@
# -*- encoding: us-ascii -*-
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "Enumerator::Lazy#initialize" do
before :each do
@@ -16,11 +16,11 @@ describe "Enumerator::Lazy#initialize" do
end
it "is a private method" do
- Enumerator::Lazy.should have_private_instance_method(:initialize, false)
+ Enumerator::Lazy.private_instance_methods(false).should.include?(:initialize)
end
it "returns self" do
- @uninitialized.send(:initialize, @receiver) {}.should equal(@uninitialized)
+ @uninitialized.send(:initialize, @receiver) {}.should.equal?(@uninitialized)
end
describe "when the returned lazy enumerator is evaluated by Enumerable#first" do
@@ -32,32 +32,32 @@ describe "Enumerator::Lazy#initialize" do
end
it "sets #size to nil if not given a size" do
- @uninitialized.send(:initialize, @receiver) {}.size.should be_nil
+ @uninitialized.send(:initialize, @receiver) {}.size.should == nil
end
it "sets #size to nil if given size is nil" do
- @uninitialized.send(:initialize, @receiver, nil) {}.size.should be_nil
+ @uninitialized.send(:initialize, @receiver, nil) {}.size.should == nil
end
it "sets given size to own size if the given size is Float::INFINITY" do
- @uninitialized.send(:initialize, @receiver, Float::INFINITY) {}.size.should equal(Float::INFINITY)
+ @uninitialized.send(:initialize, @receiver, Float::INFINITY) {}.size.should.equal?(Float::INFINITY)
end
- it "sets given size to own size if the given size is a Fixnum" do
+ it "sets given size to own size if the given size is an Integer" do
@uninitialized.send(:initialize, @receiver, 100) {}.size.should == 100
end
it "sets given size to own size if the given size is a Proc" do
- @uninitialized.send(:initialize, @receiver, lambda { 200 }) {}.size.should == 200
+ @uninitialized.send(:initialize, @receiver, -> { 200 }) {}.size.should == 200
end
it "raises an ArgumentError when block is not given" do
- lambda { @uninitialized.send :initialize, @receiver }.should raise_error(ArgumentError)
+ -> { @uninitialized.send :initialize, @receiver }.should.raise(ArgumentError)
end
describe "on frozen instance" do
- it "raises a RuntimeError" do
- lambda { @uninitialized.freeze.send(:initialize, @receiver) {} }.should raise_error(RuntimeError)
+ it "raises a FrozenError" do
+ -> { @uninitialized.freeze.send(:initialize, @receiver) {} }.should.raise(FrozenError)
end
end
end
diff --git a/spec/ruby/core/enumerator/lazy/lazy_spec.rb b/spec/ruby/core/enumerator/lazy/lazy_spec.rb
index a82a1af271..12107383d6 100644
--- a/spec/ruby/core/enumerator/lazy/lazy_spec.rb
+++ b/spec/ruby/core/enumerator/lazy/lazy_spec.rb
@@ -1,16 +1,27 @@
# -*- encoding: us-ascii -*-
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "Enumerator::Lazy" do
it "is a subclass of Enumerator" do
- Enumerator::Lazy.superclass.should equal(Enumerator)
+ Enumerator::Lazy.superclass.should.equal?(Enumerator)
+ end
+
+ it "defines lazy versions of a whitelist of Enumerator methods" do
+ lazy_methods = Set[
+ :chunk, :chunk_while, :collect, :collect_concat, :compact, :drop, :drop_while, :enum_for,
+ :find_all, :flat_map, :force, :grep, :grep_v, :lazy, :map, :reject,
+ :select, :slice_after, :slice_before, :slice_when, :take, :take_while,
+ :to_enum, :uniq, :zip
+ ]
+
+ Enumerator::Lazy.instance_methods(false).to_set.should >= lazy_methods
end
end
describe "Enumerator::Lazy#lazy" do
it "returns self" do
lazy = (1..3).to_enum.lazy
- lazy.lazy.should equal(lazy)
+ lazy.lazy.should.equal?(lazy)
end
end
diff --git a/spec/ruby/core/enumerator/lazy/map_spec.rb b/spec/ruby/core/enumerator/lazy/map_spec.rb
index 8ff2573fe5..2c7f8efab8 100644
--- a/spec/ruby/core/enumerator/lazy/map_spec.rb
+++ b/spec/ruby/core/enumerator/lazy/map_spec.rb
@@ -1,10 +1,62 @@
-# -*- encoding: us-ascii -*-
-
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/collect', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'fixtures/classes'
describe "Enumerator::Lazy#map" do
- it_behaves_like :enumerator_lazy_collect, :map
+ 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.map {}
+ ret.should.instance_of?(Enumerator::Lazy)
+ ret.should_not.equal?(@yieldsmixed)
+ end
+
+ it "keeps size" do
+ Enumerator::Lazy.new(Object.new, 100) {}.map {}.size.should == 100
+ end
+
+ describe "when the returned lazy enumerator is evaluated by Enumerable#first" do
+ it "stops after specified times" do
+ (0..Float::INFINITY).lazy.map(&:succ).first(3).should == [1, 2, 3]
+
+ @eventsmixed.map {}.first(1)
+ ScratchPad.recorded.should == [:before_yield]
+ end
+ end
+
+ it "calls the block with initial values when yield with multiple arguments" do
+ yields = []
+ @yieldsmixed.map { |v| yields << v }.force
+ yields.should == EnumeratorLazySpecs::YieldsMixed.initial_yields
+ end
+
+ describe "on a nested Lazy" do
+ it "keeps size" do
+ Enumerator::Lazy.new(Object.new, 100) {}.map {}.map {}.size.should == 100
+ end
+
+ describe "when the returned lazy enumerator is evaluated by Enumerable#first" do
+ it "stops after specified times" do
+ (0..Float::INFINITY).lazy.map(&:succ).map(&:succ).first(3).should == [2, 3, 4]
+
+ @eventsmixed.map {}.map {}.first(1)
+ ScratchPad.recorded.should == [:before_yield]
+ end
+ end
+ end
+
+ it "works with an infinite enumerable" do
+ s = 0..Float::INFINITY
+ s.lazy.map { |n| n }.first(100).should ==
+ s.first(100).map { |n| n }.to_a
+ end
it "doesn't unwrap Arrays" do
Enumerator.new {|y| y.yield([1])}.lazy.to_a.should == [[1]]
diff --git a/spec/ruby/core/enumerator/lazy/reject_spec.rb b/spec/ruby/core/enumerator/lazy/reject_spec.rb
index 317e927f02..374d4df14e 100644
--- a/spec/ruby/core/enumerator/lazy/reject_spec.rb
+++ b/spec/ruby/core/enumerator/lazy/reject_spec.rb
@@ -1,7 +1,7 @@
# -*- encoding: us-ascii -*-
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'fixtures/classes'
describe "Enumerator::Lazy#reject" do
before :each do
@@ -16,8 +16,8 @@ describe "Enumerator::Lazy#reject" do
it "returns a new instance of Enumerator::Lazy" do
ret = @yieldsmixed.reject {}
- ret.should be_an_instance_of(Enumerator::Lazy)
- ret.should_not equal(@yieldsmixed)
+ ret.should.instance_of?(Enumerator::Lazy)
+ ret.should_not.equal?(@yieldsmixed)
end
it "sets #size to nil" do
@@ -33,6 +33,18 @@ describe "Enumerator::Lazy#reject" do
end
end
+ it "lets exceptions raised in the block go through" do
+ lazy = 10.times.lazy.map do |i|
+ raise "foo"
+ end
+
+ lazy = lazy.reject(&:nil?)
+
+ -> {
+ lazy.first
+ }.should.raise(RuntimeError, "foo")
+ end
+
it "calls the block with a gathered array when yield with multiple arguments" do
yields = []
@yieldsmixed.reject { |v| yields << v }.force
@@ -40,7 +52,7 @@ describe "Enumerator::Lazy#reject" do
end
it "raises an ArgumentError when not given a block" do
- lambda { @yieldsmixed.reject }.should raise_error(ArgumentError)
+ -> { @yieldsmixed.reject }.should.raise(ArgumentError)
end
describe "on a nested Lazy" do
@@ -57,4 +69,10 @@ describe "Enumerator::Lazy#reject" do
end
end
end
+
+ it "works with an infinite enumerable" do
+ s = 0..Float::INFINITY
+ s.lazy.reject { |n| false }.first(100).should ==
+ s.first(100).reject { |n| false }
+ end
end
diff --git a/spec/ruby/core/enumerator/lazy/select_spec.rb b/spec/ruby/core/enumerator/lazy/select_spec.rb
index ba5823c7ad..29c8f1bd80 100644
--- a/spec/ruby/core/enumerator/lazy/select_spec.rb
+++ b/spec/ruby/core/enumerator/lazy/select_spec.rb
@@ -1,8 +1,103 @@
-# -*- encoding: us-ascii -*-
-
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/select', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'fixtures/classes'
describe "Enumerator::Lazy#select" do
- it_behaves_like :enumerator_lazy_select, :select
+ 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.select {}
+ ret.should.instance_of?(Enumerator::Lazy)
+ ret.should_not.equal?(@yieldsmixed)
+ end
+
+ it "sets #size to nil" do
+ Enumerator::Lazy.new(Object.new, 100) {}.select { true }.size.should == nil
+ end
+
+ describe "when the returned lazy enumerator is evaluated by Enumerable#first" do
+ it "stops after specified times" do
+ (0..Float::INFINITY).lazy.select(&:even?).first(3).should == [0, 2, 4]
+
+ @eventsmixed.select { true }.first(1)
+ ScratchPad.recorded.should == [:before_yield]
+ end
+ end
+
+ it "calls the block with a gathered array when yield with multiple arguments" do
+ yields = []
+ @yieldsmixed.select { |v| yields << v }.force
+ yields.should == EnumeratorLazySpecs::YieldsMixed.gathered_yields
+ end
+
+ it "raises an ArgumentError when not given a block" do
+ -> { @yieldsmixed.select }.should.raise(ArgumentError)
+ end
+
+ describe "on a nested Lazy" do
+ it "sets #size to nil" do
+ Enumerator::Lazy.new(Object.new, 100) {}.take(50) {}.select { true }.size.should == nil
+ end
+
+ describe "when the returned lazy enumerator is evaluated by Enumerable#first" do
+ it "stops after specified times" do
+ (0..Float::INFINITY).lazy.select { |n| n > 5 }.select(&:even?).first(3).should == [6, 8, 10]
+
+ @eventsmixed.select { true }.select { true }.first(1)
+ ScratchPad.recorded.should == [:before_yield]
+ end
+ end
+ end
+
+ it "works with an infinite enumerable" do
+ s = 0..Float::INFINITY
+ s.lazy.select { |n| true }.first(100).should ==
+ s.first(100).select { |n| true }
+ end
+
+ it "doesn't pre-evaluate the next element" do
+ eval_count = 0
+ enum = %w[Text1 Text2 Text3].lazy.select do
+ eval_count += 1
+ true
+ end
+
+ eval_count.should == 0
+ enum.next
+ eval_count.should == 1
+ end
+
+ it "doesn't over-evaluate when peeked" do
+ eval_count = 0
+ enum = %w[Text1 Text2 Text3].lazy.select do
+ eval_count += 1
+ true
+ end
+
+ eval_count.should == 0
+ enum.peek
+ enum.peek
+ eval_count.should == 1
+ end
+
+ it "doesn't re-evaluate after peek" do
+ eval_count = 0
+ enum = %w[Text1 Text2 Text3].lazy.select do
+ eval_count += 1
+ true
+ end
+
+ eval_count.should == 0
+ enum.peek
+ eval_count.should == 1
+ enum.next
+ eval_count.should == 1
+ end
end
diff --git a/spec/ruby/core/enumerator/lazy/shared/collect.rb b/spec/ruby/core/enumerator/lazy/shared/collect.rb
deleted file mode 100644
index c892784bc2..0000000000
--- a/spec/ruby/core/enumerator/lazy/shared/collect.rb
+++ /dev/null
@@ -1,56 +0,0 @@
-# -*- encoding: us-ascii -*-
-
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
-
-describe :enumerator_lazy_collect, shared: true 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.send(@method) {}
- ret.should be_an_instance_of(Enumerator::Lazy)
- ret.should_not equal(@yieldsmixed)
- end
-
- it "keeps size" do
- Enumerator::Lazy.new(Object.new, 100) {}.send(@method) {}.size.should == 100
- end
-
- describe "when the returned lazy enumerator is evaluated by Enumerable#first" do
- it "stops after specified times" do
- (0..Float::INFINITY).lazy.send(@method, &:succ).first(3).should == [1, 2, 3]
-
- @eventsmixed.send(@method) {}.first(1)
- ScratchPad.recorded.should == [:before_yield]
- end
- end
-
- it "calls the block with initial values when yield with multiple arguments" do
- yields = []
- @yieldsmixed.send(@method) { |v| yields << v }.force
- yields.should == EnumeratorLazySpecs::YieldsMixed.initial_yields
- end
-
- describe "on a nested Lazy" do
- it "keeps size" do
- Enumerator::Lazy.new(Object.new, 100) {}.send(@method) {}.send(@method) {}.size.should == 100
- end
-
- describe "when the returned lazy enumerator is evaluated by Enumerable#first" do
- it "stops after specified times" do
- (0..Float::INFINITY).lazy.send(@method, &:succ).send(@method, &:succ).first(3).should == [2, 3, 4]
-
- @eventsmixed.send(@method) {}.send(@method) {}.first(1)
- ScratchPad.recorded.should == [:before_yield]
- end
- end
- end
-end
diff --git a/spec/ruby/core/enumerator/lazy/shared/collect_concat.rb b/spec/ruby/core/enumerator/lazy/shared/collect_concat.rb
deleted file mode 100644
index 69bc10c1a4..0000000000
--- a/spec/ruby/core/enumerator/lazy/shared/collect_concat.rb
+++ /dev/null
@@ -1,72 +0,0 @@
-# -*- encoding: us-ascii -*-
-
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
-
-describe :enumerator_lazy_collect_concat, shared: true 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.send(@method) {}
- 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) {}.send(@method) { true }.size.should == nil
- end
-
- describe "when the returned lazy enumerator is evaluated by Enumerable#first" do
- it "stops after specified times" do
- (0..Float::INFINITY).lazy.send(@method) { |n| (n * 10).to_s }.first(6).should == %w[0 10 20 30 40 50]
-
- @eventsmixed.send(@method) {}.first(1)
- ScratchPad.recorded.should == [:before_yield]
- end
-
- it "flattens elements when the given block returned an array or responding to .each and .force" do
- (0..Float::INFINITY).lazy.send(@method) { |n| (n * 10).to_s.chars }.first(6).should == %w[0 1 0 2 0 3]
- (0..Float::INFINITY).lazy.send(@method) { |n| (n * 10).to_s.each_char }.first(6).all? { |o| o.instance_of? Enumerator }.should be_true
- (0..Float::INFINITY).lazy.send(@method) { |n| (n * 10).to_s.each_char.lazy }.first(6).should == %w[0 1 0 2 0 3]
- end
- end
-
- it "calls the block with initial values when yield with multiple arguments" do
- yields = []
- @yieldsmixed.send(@method) { |v| yields << v }.force
- yields.should == EnumeratorLazySpecs::YieldsMixed.initial_yields
- end
-
- it "raises an ArgumentError when not given a block" do
- lambda { @yieldsmixed.send(@method) }.should raise_error(ArgumentError)
- end
-
- describe "on a nested Lazy" do
- it "sets #size to nil" do
- Enumerator::Lazy.new(Object.new, 100) {}.take(50) {}.send(@method) {}.size.should == nil
- end
-
- describe "when the returned lazy enumerator is evaluated by Enumerable#first" do
- it "stops after specified times" do
- (0..Float::INFINITY).lazy.map {|n| n * 10 }.send(@method) { |n| n.to_s }.first(6).should == %w[0 10 20 30 40 50]
-
- @eventsmixed.send(@method) {}.send(@method) {}.first(1)
- ScratchPad.recorded.should == [:before_yield]
- end
-
- it "flattens elements when the given block returned an array or responding to .each and .force" do
- (0..Float::INFINITY).lazy.map {|n| n * 10 }.send(@method) { |n| n.to_s.chars }.first(6).should == %w[0 1 0 2 0 3]
- (0..Float::INFINITY).lazy.map {|n| n * 10 }.send(@method) { |n| n.to_s.each_char }.first(6).all? { |o| o.instance_of? Enumerator }.should be_true
- (0..Float::INFINITY).lazy.map {|n| n * 10 }.send(@method) { |n| n.to_s.each_char.lazy }.first(6).should == %w[0 1 0 2 0 3]
- end
- end
- end
-end
diff --git a/spec/ruby/core/enumerator/lazy/shared/select.rb b/spec/ruby/core/enumerator/lazy/shared/select.rb
deleted file mode 100644
index 546256360e..0000000000
--- a/spec/ruby/core/enumerator/lazy/shared/select.rb
+++ /dev/null
@@ -1,60 +0,0 @@
-# -*- encoding: us-ascii -*-
-
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
-
-describe :enumerator_lazy_select, shared: true 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.send(@method) {}
- 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) {}.send(@method) { true }.size.should == nil
- end
-
- describe "when the returned lazy enumerator is evaluated by Enumerable#first" do
- it "stops after specified times" do
- (0..Float::INFINITY).lazy.send(@method, &:even?).first(3).should == [0, 2, 4]
-
- @eventsmixed.send(@method) { true }.first(1)
- ScratchPad.recorded.should == [:before_yield]
- end
- end
-
- it "calls the block with a gathered array when yield with multiple arguments" do
- yields = []
- @yieldsmixed.send(@method) { |v| yields << v }.force
- yields.should == EnumeratorLazySpecs::YieldsMixed.gathered_yields
- end
-
- it "raises an ArgumentError when not given a block" do
- lambda { @yieldsmixed.send(@method) }.should raise_error(ArgumentError)
- end
-
- describe "on a nested Lazy" do
- it "sets #size to nil" do
- Enumerator::Lazy.new(Object.new, 100) {}.take(50) {}.send(@method) { true }.size.should == nil
- end
-
- describe "when the returned lazy enumerator is evaluated by Enumerable#first" do
- it "stops after specified times" do
- (0..Float::INFINITY).lazy.send(@method) { |n| n > 5 }.send(@method, &:even?).first(3).should == [6, 8, 10]
-
- @eventsmixed.send(@method) { true }.send(@method) { true }.first(1)
- ScratchPad.recorded.should == [:before_yield]
- end
- end
- end
-end
diff --git a/spec/ruby/core/enumerator/lazy/shared/to_enum.rb b/spec/ruby/core/enumerator/lazy/shared/to_enum.rb
deleted file mode 100644
index 5e6935b45a..0000000000
--- a/spec/ruby/core/enumerator/lazy/shared/to_enum.rb
+++ /dev/null
@@ -1,50 +0,0 @@
-# -*- encoding: us-ascii -*-
-
-require File.expand_path('../../../../../spec_helper', __FILE__)
-
-describe :enumerator_lazy_to_enum, shared: true do
- before :each do
- @infinite = (0..Float::INFINITY).lazy
- end
-
- it "requires multiple arguments" do
- Enumerator::Lazy.instance_method(@method).arity.should < 0
- end
-
- it "returns a new instance of Enumerator::Lazy" do
- ret = @infinite.send @method
- ret.should be_an_instance_of(Enumerator::Lazy)
- ret.should_not equal(@infinite)
- end
-
- it "sets #size to nil when not given a block" do
- Enumerator::Lazy.new(Object.new, 100) {}.send(@method).size.should == nil
- end
-
- it "sets given block to size when given a block" do
- Enumerator::Lazy.new(Object.new, 100) {}.send(@method) { 30 }.size.should == 30
- end
-
- it "generates a lazy enumerator from the given name" do
- @infinite.send(@method, :with_index, 10).first(3).should == [[0, 10], [1, 11], [2, 12]]
- end
-
- it "passes given arguments to wrapped method" do
- @infinite.send(@method, :each_slice, 2).map { |assoc| assoc.first * assoc.last }.first(4).should == [0, 6, 20, 42]
- end
-
- it "used by some parent's methods though returning Lazy" do
- { each_with_index: [],
- with_index: [],
- cycle: [1],
- each_with_object: [Object.new],
- with_object: [Object.new],
- each_slice: [2],
- each_entry: [],
- each_cons: [2]
- }.each_pair do |method, args|
- @infinite.method(method).owner.should_not equal(Enumerator::Lazy)
- @infinite.send(method, *args).should be_an_instance_of(Enumerator::Lazy)
- end
- end
-end
diff --git a/spec/ruby/core/enumerator/lazy/slice_after_spec.rb b/spec/ruby/core/enumerator/lazy/slice_after_spec.rb
new file mode 100644
index 0000000000..f8cd97178f
--- /dev/null
+++ b/spec/ruby/core/enumerator/lazy/slice_after_spec.rb
@@ -0,0 +1,14 @@
+require_relative '../../../spec_helper'
+
+describe "Enumerator::Lazy#slice_after" do
+ it "works with an infinite enumerable" do
+ s = 0..Float::INFINITY
+ s.lazy.slice_after { |n| true }.first(100).should ==
+ s.first(100).slice_after { |n| true }.to_a
+ end
+
+ it "should return a lazy enumerator" do
+ s = 0..Float::INFINITY
+ s.lazy.slice_after { |n| true }.should.is_a?(Enumerator::Lazy)
+ end
+end
diff --git a/spec/ruby/core/enumerator/lazy/slice_before_spec.rb b/spec/ruby/core/enumerator/lazy/slice_before_spec.rb
new file mode 100644
index 0000000000..192e853343
--- /dev/null
+++ b/spec/ruby/core/enumerator/lazy/slice_before_spec.rb
@@ -0,0 +1,14 @@
+require_relative '../../../spec_helper'
+
+describe "Enumerator::Lazy#slice_before" do
+ it "works with an infinite enumerable" do
+ s = 0..Float::INFINITY
+ s.lazy.slice_before { |n| true }.first(100).should ==
+ s.first(100).slice_before { |n| true }.to_a
+ end
+
+ it "should return a lazy enumerator" do
+ s = 0..Float::INFINITY
+ s.lazy.slice_before { |n| true }.should.is_a?(Enumerator::Lazy)
+ end
+end
diff --git a/spec/ruby/core/enumerator/lazy/slice_when_spec.rb b/spec/ruby/core/enumerator/lazy/slice_when_spec.rb
new file mode 100644
index 0000000000..fc9d5f5069
--- /dev/null
+++ b/spec/ruby/core/enumerator/lazy/slice_when_spec.rb
@@ -0,0 +1,14 @@
+require_relative '../../../spec_helper'
+
+describe "Enumerator::Lazy#slice_when" do
+ it "works with an infinite enumerable" do
+ s = 0..Float::INFINITY
+ s.lazy.slice_when { |a, b| true }.first(100).should ==
+ s.first(100).slice_when { |a, b| true }.to_a
+ end
+
+ it "should return a lazy enumerator" do
+ s = 0..Float::INFINITY
+ s.lazy.slice_when { |a, b| true }.should.is_a?(Enumerator::Lazy)
+ end
+end
diff --git a/spec/ruby/core/enumerator/lazy/take_spec.rb b/spec/ruby/core/enumerator/lazy/take_spec.rb
index 5ef732237d..2dd5b939e2 100644
--- a/spec/ruby/core/enumerator/lazy/take_spec.rb
+++ b/spec/ruby/core/enumerator/lazy/take_spec.rb
@@ -1,9 +1,17 @@
# -*- encoding: us-ascii -*-
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative '../../enumerable/shared/value_packing'
describe "Enumerator::Lazy#take" do
+ describe "value packing of source yields (matches Enumerable#take)" do
+ before :each do
+ @take = -> e { e.lazy.take(1) }
+ end
+ it_behaves_like :enumerable_value_packing, nil
+ end
+
before :each do
@yieldsmixed = EnumeratorLazySpecs::YieldsMixed.new.to_enum.lazy
@eventsmixed = EnumeratorLazySpecs::EventsMixed.new.to_enum.lazy
@@ -16,8 +24,8 @@ describe "Enumerator::Lazy#take" do
it "returns a new instance of Enumerator::Lazy" do
ret = @yieldsmixed.take(1)
- ret.should be_an_instance_of(Enumerator::Lazy)
- ret.should_not equal(@yieldsmixed)
+ ret.should.instance_of?(Enumerator::Lazy)
+ ret.should_not.equal?(@yieldsmixed)
end
it "sets given count to size if the given count is less than old size" do
diff --git a/spec/ruby/core/enumerator/lazy/take_while_spec.rb b/spec/ruby/core/enumerator/lazy/take_while_spec.rb
index 8647dfcaf0..c369712c56 100644
--- a/spec/ruby/core/enumerator/lazy/take_while_spec.rb
+++ b/spec/ruby/core/enumerator/lazy/take_while_spec.rb
@@ -1,7 +1,7 @@
# -*- encoding: us-ascii -*-
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'fixtures/classes'
describe "Enumerator::Lazy#take_while" do
before :each do
@@ -16,8 +16,8 @@ describe "Enumerator::Lazy#take_while" do
it "returns a new instance of Enumerator::Lazy" do
ret = @yieldsmixed.take_while {}
- ret.should be_an_instance_of(Enumerator::Lazy)
- ret.should_not equal(@yieldsmixed)
+ ret.should.instance_of?(Enumerator::Lazy)
+ ret.should_not.equal?(@yieldsmixed)
end
it "sets #size to nil" do
@@ -40,7 +40,7 @@ describe "Enumerator::Lazy#take_while" do
end
it "raises an ArgumentError when not given a block" do
- lambda { @yieldsmixed.take_while }.should raise_error(ArgumentError)
+ -> { @yieldsmixed.take_while }.should.raise(ArgumentError)
end
describe "on a nested Lazy" do
diff --git a/spec/ruby/core/enumerator/lazy/to_enum_spec.rb b/spec/ruby/core/enumerator/lazy/to_enum_spec.rb
index e0966037ab..c0233d60fa 100644
--- a/spec/ruby/core/enumerator/lazy/to_enum_spec.rb
+++ b/spec/ruby/core/enumerator/lazy/to_enum_spec.rb
@@ -1,8 +1,54 @@
-# -*- encoding: us-ascii -*-
-
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/to_enum', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'fixtures/classes'
describe "Enumerator::Lazy#to_enum" do
- it_behaves_like :enumerator_lazy_to_enum, :to_enum
+ before :each do
+ @infinite = (0..Float::INFINITY).lazy
+ end
+
+ it "requires multiple arguments" do
+ Enumerator::Lazy.instance_method(:to_enum).arity.should < 0
+ end
+
+ it "returns a new instance of Enumerator::Lazy" do
+ ret = @infinite.to_enum
+ ret.should.instance_of?(Enumerator::Lazy)
+ ret.should_not.equal?(@infinite)
+ end
+
+ it "sets #size to nil when not given a block" do
+ Enumerator::Lazy.new(Object.new, 100) {}.to_enum.size.should == nil
+ end
+
+ it "sets given block to size when given a block" do
+ Enumerator::Lazy.new(Object.new, 100) {}.to_enum { 30 }.size.should == 30
+ end
+
+ it "generates a lazy enumerator from the given name" do
+ @infinite.to_enum(:with_index, 10).first(3).should == [[0, 10], [1, 11], [2, 12]]
+ end
+
+ it "passes given arguments to wrapped method" do
+ @infinite.to_enum(:each_slice, 2).map { |assoc| assoc.first * assoc.last }.first(4).should == [0, 6, 20, 42]
+ end
+
+ it "used by some parent's methods though returning Lazy" do
+ { each_with_index: [],
+ with_index: [],
+ cycle: [1],
+ each_with_object: [Object.new],
+ with_object: [Object.new],
+ each_slice: [2],
+ each_entry: [],
+ each_cons: [2]
+ }.each_pair do |method, args|
+ @infinite.send(method, *args).should.instance_of?(Enumerator::Lazy)
+ end
+ end
+
+ it "works with an infinite enumerable" do
+ s = 0..Float::INFINITY
+ s.lazy.to_enum(:with_index).first(100).should ==
+ s.first(100).to_enum.to_enum(:with_index).to_a
+ end
end
diff --git a/spec/ruby/core/enumerator/lazy/uniq_spec.rb b/spec/ruby/core/enumerator/lazy/uniq_spec.rb
index 6220c7ba34..d30ed8df2f 100644
--- a/spec/ruby/core/enumerator/lazy/uniq_spec.rb
+++ b/spec/ruby/core/enumerator/lazy/uniq_spec.rb
@@ -1,39 +1,74 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-
-ruby_version_is '2.4' do
- describe 'Enumerator::Lazy#uniq' do
- context 'when yielded with an argument' do
- before :each do
- @lazy = [0, 1, 2, 3].to_enum.lazy.uniq(&:even?)
- end
+require_relative '../../../spec_helper'
+require_relative 'fixtures/classes'
- it 'returns a lazy enumerator' do
- @lazy.should be_an_instance_of(Enumerator::Lazy)
- @lazy.force.should == [0, 1]
- end
+describe 'Enumerator::Lazy#uniq' do
+ context 'without block' do
+ before :each do
+ @lazy = [0, 1, 0, 1].to_enum.lazy.uniq
+ end
- it 'sets the size to nil' do
- @lazy.size.should == nil
- end
+ it 'returns a lazy enumerator' do
+ @lazy.should.instance_of?(Enumerator::Lazy)
+ @lazy.force.should == [0, 1]
+ end
+
+ it 'return same value after rewind' do
+ @lazy.force.should == [0, 1]
+ @lazy.force.should == [0, 1]
+ end
+
+ it 'sets the size to nil' do
+ @lazy.size.should == nil
+ end
+ end
+
+ context 'when yielded with an argument' do
+ before :each do
+ @lazy = [0, 1, 2, 3].to_enum.lazy.uniq(&:even?)
+ end
+
+ it 'returns a lazy enumerator' do
+ @lazy.should.instance_of?(Enumerator::Lazy)
+ @lazy.force.should == [0, 1]
+ end
+
+ it 'return same value after rewind' do
+ @lazy.force.should == [0, 1]
+ @lazy.force.should == [0, 1]
end
- context 'when yielded with multiple arguments' do
- before :each do
- enum = Object.new.to_enum
- class << enum
- def each
- yield 0, 'foo'
- yield 1, 'FOO'
- yield 2, 'bar'
- end
+ it 'sets the size to nil' do
+ @lazy.size.should == nil
+ end
+ end
+
+ context 'when yielded with multiple arguments' do
+ before :each do
+ enum = Object.new.to_enum
+ class << enum
+ def each
+ yield 0, 'foo'
+ yield 1, 'FOO'
+ yield 2, 'bar'
end
- @lazy = enum.lazy
end
+ @lazy = enum.lazy
+ end
- it 'returns all yield arguments as an array' do
- @lazy.uniq { |_, label| label.downcase }.force.should == [[0, 'foo'], [2, 'bar']]
- end
+ it 'return same value after rewind' do
+ enum = @lazy.uniq { |_, label| label.downcase }
+ enum.force.should == [[0, 'foo'], [2, 'bar']]
+ enum.force.should == [[0, 'foo'], [2, 'bar']]
+ end
+
+ it 'returns all yield arguments as an array' do
+ @lazy.uniq { |_, label| label.downcase }.force.should == [[0, 'foo'], [2, 'bar']]
end
end
+
+ it "works with an infinite enumerable" do
+ s = 0..Float::INFINITY
+ s.lazy.uniq.first(100).should ==
+ s.first(100).uniq
+ end
end
diff --git a/spec/ruby/core/enumerator/lazy/with_index_spec.rb b/spec/ruby/core/enumerator/lazy/with_index_spec.rb
new file mode 100644
index 0000000000..2e983fd3b1
--- /dev/null
+++ b/spec/ruby/core/enumerator/lazy/with_index_spec.rb
@@ -0,0 +1,36 @@
+# -*- encoding: us-ascii -*-
+
+require_relative '../../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe "Enumerator::Lazy#with_index" do
+ it "enumerates with an index" do
+ (0..Float::INFINITY).lazy.with_index.map { |i, idx| [i, idx] }.first(3).should == [[0, 0], [1, 1], [2, 2]]
+ end
+
+ it "enumerates with an index starting at a given offset" do
+ (0..Float::INFINITY).lazy.with_index(3).map { |i, idx| [i, idx] }.first(3).should == [[0, 3], [1, 4], [2, 5]]
+ end
+
+ it "enumerates with an index starting at 0 when offset is nil" do
+ (0..Float::INFINITY).lazy.with_index(nil).map { |i, idx| [i, idx] }.first(3).should == [[0, 0], [1, 1], [2, 2]]
+ end
+
+ it "raises TypeError when offset does not convert to Integer" do
+ -> { (0..Float::INFINITY).lazy.with_index(false).map { |i, idx| i }.first(3) }.should.raise(TypeError)
+ end
+
+ it "enumerates with a given block" do
+ result = []
+ (0..Float::INFINITY).lazy.with_index { |i, idx| result << [i * 2, idx] }.first(3)
+ result.should == [[0,0],[2,1],[4,2]]
+ end
+
+ it "resets after a new call to each" do
+ enum = (0..2).lazy.with_index.map { |i, idx| [i, idx] }
+ result = []
+ enum.each { |i, idx| result << [i, idx] }
+ enum.each { |i, idx| result << [i, idx] }
+ result.should == [[0,0], [1,1], [2,2], [0,0], [1,1], [2,2]]
+ end
+end
diff --git a/spec/ruby/core/enumerator/lazy/zip_spec.rb b/spec/ruby/core/enumerator/lazy/zip_spec.rb
index 9c728364ce..9f612542d7 100644
--- a/spec/ruby/core/enumerator/lazy/zip_spec.rb
+++ b/spec/ruby/core/enumerator/lazy/zip_spec.rb
@@ -1,7 +1,7 @@
# -*- encoding: us-ascii -*-
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'fixtures/classes'
describe "Enumerator::Lazy#zip" do
before :each do
@@ -16,8 +16,8 @@ describe "Enumerator::Lazy#zip" do
it "returns a new instance of Enumerator::Lazy" do
ret = @yieldsmixed.zip []
- ret.should be_an_instance_of(Enumerator::Lazy)
- ret.should_not equal(@yieldsmixed)
+ ret.should.instance_of?(Enumerator::Lazy)
+ ret.should_not.equal?(@yieldsmixed)
end
it "keeps size" do
@@ -40,11 +40,11 @@ describe "Enumerator::Lazy#zip" do
end
it "returns a Lazy when no arguments given" do
- @yieldsmixed.zip.should be_an_instance_of(Enumerator::Lazy)
+ @yieldsmixed.zip.should.instance_of?(Enumerator::Lazy)
end
it "raises a TypeError if arguments contain non-list object" do
- lambda { @yieldsmixed.zip [], Object.new, [] }.should raise_error(TypeError)
+ -> { @yieldsmixed.zip [], Object.new, [] }.should.raise(TypeError)
end
describe "on a nested Lazy" do
@@ -71,4 +71,16 @@ describe "Enumerator::Lazy#zip" do
end
end
end
+
+ it "works with an infinite enumerable and an array" do
+ s = 0..Float::INFINITY
+ s.lazy.zip(0..1000).first(100).should ==
+ s.first(100).zip(0..100)
+ end
+
+ it "works with two infinite enumerables" do
+ s = 0..Float::INFINITY
+ s.lazy.zip(s).first(100).should ==
+ s.first(100).zip(s)
+ end
end
diff --git a/spec/ruby/core/enumerator/new_spec.rb b/spec/ruby/core/enumerator/new_spec.rb
index e8e0572a40..eb6c13759e 100644
--- a/spec/ruby/core/enumerator/new_spec.rb
+++ b/spec/ruby/core/enumerator/new_spec.rb
@@ -1,6 +1,115 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/enumerator/new', __FILE__)
+require_relative '../../spec_helper'
describe "Enumerator.new" do
- it_behaves_like(:enum_new, :new)
+ context "no block given" do
+ it "raises" do
+ -> { Enumerator.new(1, :upto, 3) }.should.raise(ArgumentError)
+ end
+ end
+
+ context "when passed a block" do
+ it "defines iteration with block, yielder argument and calling << method" do
+ enum = Enumerator.new do |yielder|
+ a = 1
+
+ loop do
+ yielder << a
+ a = a + 1
+ end
+ end
+
+ enum.take(3).should == [1, 2, 3]
+ end
+
+ it "defines iteration with block, yielder argument and calling yield method" do
+ enum = Enumerator.new do |yielder|
+ a = 1
+
+ loop do
+ yielder.yield(a)
+ a = a + 1
+ end
+ end
+
+ enum.take(3).should == [1, 2, 3]
+ end
+
+ it "defines iteration with block, yielder argument and treating it as a proc" do
+ enum = Enumerator.new do |yielder|
+ "a\nb\nc".each_line(&yielder)
+ end
+
+ enum.to_a.should == ["a\n", "b\n", "c"]
+ end
+
+ describe '#yield' do
+ it 'accepts a single argument' do
+ Enumerator.new { |y| y.yield(1) }.to_a.should == [1]
+ Enumerator.new { |y| y.yield(1) }.first.should == 1
+ end
+
+ it 'accepts multiple arguments' do
+ Enumerator.new { |y| y.yield(1, 2) }.to_a.should == [[1, 2]]
+ Enumerator.new { |y| y.yield(1, 2) }.first.should == [1, 2]
+ end
+
+ it "doesn't double-wrap arrays" do
+ Enumerator.new { |y| y.yield([1]) }.to_a.should == [[1]]
+ Enumerator.new { |y| y.yield([1]) }.first.should == [1]
+
+ Enumerator.new { |y| y.yield([1, 2]) }.to_a.should == [[1, 2]]
+ Enumerator.new { |y| y.yield([1, 2]) }.first.should == [1, 2]
+ end
+
+ it 'returns nil' do
+ ScratchPad.record []
+ Enumerator.new do |y|
+ ScratchPad << y.yield(1)
+ end.to_a
+
+ ScratchPad.recorded.should == [nil]
+ end
+
+ it 'accepts keyword arguments and treats them as a positional hash' do
+ Enumerator.new { |y| y.yield(foo: 42) }.to_a.should == [{ foo: 42 }]
+ Enumerator.new { |y| y.yield(foo: 42) }.first.should == { foo: 42 }
+
+ Enumerator.new { |y| y.yield(123, foo: 42) }.to_a.should == [[123, { foo: 42 }]]
+ Enumerator.new { |y| y.yield(123, foo: 42) }.first.should == [123, { foo: 42 }]
+ end
+ end
+
+ describe '#<<' do
+ it 'accepts a single argument' do
+ Enumerator.new { |y| y.<<(1) }.to_a.should == [1]
+ Enumerator.new { |y| y.<<(1) }.first.should == 1
+ end
+
+ it "doesn't double-wrap arrays" do
+ Enumerator.new { |y| y.<<([1]) }.to_a.should == [[1]]
+ Enumerator.new { |y| y.<<([1]) }.first.should == [1]
+
+ Enumerator.new { |y| y.<<([1, 2]) }.to_a.should == [[1, 2]]
+ Enumerator.new { |y| y.<<([1, 2]) }.first.should == [1, 2]
+ end
+
+ it 'accepts keyword arguments and treats them as a positional hash' do
+ Enumerator.new { |y| y.<<(foo: 42) }.to_a.should == [{ foo: 42 }]
+ Enumerator.new { |y| y.<<(foo: 42) }.first.should == { foo: 42 }
+ end
+
+ it 'can be chained' do
+ enum = Enumerator.new do |y|
+ y << 1 << 2
+ end
+ enum.to_a.should == [1, 2]
+ end
+
+ it 'raises ArgumentError when given more than one argument' do
+ -> {
+ Enumerator.new { |y| y.<<(1, 2) }.to_a
+ }.should.raise(ArgumentError, "wrong number of arguments (given 2, expected 1)")
+ end
+ end
+ end
end
diff --git a/spec/ruby/core/enumerator/next_spec.rb b/spec/ruby/core/enumerator/next_spec.rb
index 6b3309a2bc..77e79185a9 100644
--- a/spec/ruby/core/enumerator/next_spec.rb
+++ b/spec/ruby/core/enumerator/next_spec.rb
@@ -1,6 +1,38 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/enumerator/next', __FILE__)
+require_relative '../../spec_helper'
describe "Enumerator#next" do
- it_behaves_like(:enum_next,:next)
+ before :each do
+ @enum = 1.upto(3)
+ end
+
+ it "returns the next element of the enumeration" do
+ @enum.next.should == 1
+ @enum.next.should == 2
+ @enum.next.should == 3
+ end
+
+ it "raises a StopIteration exception at the end of the stream" do
+ 3.times { @enum.next }
+ -> { @enum.next }.should.raise(StopIteration)
+ end
+
+ it "cannot be called again until the enumerator is rewound" do
+ 3.times { @enum.next }
+ -> { @enum.next }.should.raise(StopIteration)
+ -> { @enum.next }.should.raise(StopIteration)
+ -> { @enum.next }.should.raise(StopIteration)
+ @enum.rewind
+ @enum.next.should == 1
+ end
+
+ it "restarts the enumerator if an exception terminated a previous iteration" do
+ exception = StandardError.new
+ enum = Enumerator.new do
+ raise exception
+ end
+
+ result = 2.times.map { enum.next rescue $! }
+
+ result.should == [exception, exception]
+ end
end
diff --git a/spec/ruby/core/enumerator/next_values_spec.rb b/spec/ruby/core/enumerator/next_values_spec.rb
index 2c4b23dc8d..63e024e2b4 100644
--- a/spec/ruby/core/enumerator/next_values_spec.rb
+++ b/spec/ruby/core/enumerator/next_values_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Enumerator#next_values" do
before :each do
@@ -11,6 +11,7 @@ describe "Enumerator#next_values" do
yield :e1, :e2, :e3
yield nil
yield
+ yield [:f1, :f2]
end
@e = o.to_enum
@@ -48,8 +49,13 @@ describe "Enumerator#next_values" do
@e.next_values.should == []
end
- it "raises StopIteration if called on a finished enumerator" do
+ it "returns an array of array if yield is called with an array" do
7.times { @e.next }
- lambda { @e.next_values }.should raise_error(StopIteration)
+ @e.next_values.should == [[:f1, :f2]]
+ end
+
+ it "raises StopIteration if called on a finished enumerator" do
+ 8.times { @e.next }
+ -> { @e.next_values }.should.raise(StopIteration)
end
end
diff --git a/spec/ruby/core/enumerator/peek_spec.rb b/spec/ruby/core/enumerator/peek_spec.rb
index 26ac85161b..096fd2b10c 100644
--- a/spec/ruby/core/enumerator/peek_spec.rb
+++ b/spec/ruby/core/enumerator/peek_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Enumerator#peek" do
before :each do
@@ -31,6 +31,6 @@ describe "Enumerator#peek" do
it "raises StopIteration if called on a finished enumerator" do
5.times { @e.next }
- lambda { @e.peek }.should raise_error(StopIteration)
+ -> { @e.peek }.should.raise(StopIteration)
end
end
diff --git a/spec/ruby/core/enumerator/peek_values_spec.rb b/spec/ruby/core/enumerator/peek_values_spec.rb
index ecc4758854..63f7988bcd 100644
--- a/spec/ruby/core/enumerator/peek_values_spec.rb
+++ b/spec/ruby/core/enumerator/peek_values_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Enumerator#peek_values" do
before :each do
@@ -11,6 +11,7 @@ describe "Enumerator#peek_values" do
yield :e1, :e2, :e3
yield nil
yield
+ yield [:f1, :f2]
end
@e = o.to_enum
@@ -50,8 +51,13 @@ describe "Enumerator#peek_values" do
@e.peek_values.should == []
end
- it "raises StopIteration if called on a finished enumerator" do
+ it "returns an array of array if yield is called with an array" do
7.times { @e.next }
- lambda { @e.peek_values }.should raise_error(StopIteration)
+ @e.peek_values.should == [[:f1, :f2]]
+ end
+
+ it "raises StopIteration if called on a finished enumerator" do
+ 8.times { @e.next }
+ -> { @e.peek_values }.should.raise(StopIteration)
end
end
diff --git a/spec/ruby/core/enumerator/plus_spec.rb b/spec/ruby/core/enumerator/plus_spec.rb
new file mode 100644
index 0000000000..d6c0fa93ac
--- /dev/null
+++ b/spec/ruby/core/enumerator/plus_spec.rb
@@ -0,0 +1,33 @@
+require_relative '../../spec_helper'
+
+describe "Enumerator#+" do
+ before :each do
+ ScratchPad.record []
+ end
+
+ it "returns a chain of self and provided enumerators" do
+ one = Enumerator.new { |y| y << 1 }
+ two = Enumerator.new { |y| y << 2 }
+ three = Enumerator.new { |y| y << 3 }
+
+ chain = one + two + three
+
+ chain.should.instance_of?(Enumerator::Chain)
+ chain.each { |item| ScratchPad << item }
+ ScratchPad.recorded.should == [1, 2, 3]
+ end
+
+ it "calls #each on each argument" do
+ enum = Enumerator.new { |y| y << "one" }
+
+ obj1 = mock("obj1")
+ obj1.should_receive(:each).once.and_yield("two")
+
+ obj2 = mock("obj2")
+ obj2.should_receive(:each).once.and_yield("three")
+
+ chain = enum + obj1 + obj2
+ chain.each { |item| ScratchPad << item }
+ ScratchPad.recorded.should == ["one", "two", "three"]
+ end
+end
diff --git a/spec/ruby/core/enumerator/produce_spec.rb b/spec/ruby/core/enumerator/produce_spec.rb
new file mode 100644
index 0000000000..eb1b09294e
--- /dev/null
+++ b/spec/ruby/core/enumerator/produce_spec.rb
@@ -0,0 +1,78 @@
+require_relative '../../spec_helper'
+
+describe "Enumerator.produce" do
+ it "creates an infinite enumerator" do
+ enum = Enumerator.produce(0) { |prev| prev + 1 }
+
+ enum.size.should == Float::INFINITY
+ enum.take(5).should == [0, 1, 2, 3, 4]
+ end
+
+ it "terminates iteration when block raises StopIteration exception" do
+ enum = Enumerator.produce(0) do | prev|
+ raise StopIteration if prev >= 2
+ prev + 1
+ end
+
+ enum.to_a.should == [0, 1, 2]
+ end
+
+ context "when initial value skipped" do
+ it "uses nil instead" do
+ ScratchPad.record []
+ enum = Enumerator.produce { |prev| ScratchPad << prev; (prev || 0) + 1 }
+
+ enum.take(3).should == [1, 2, 3]
+ ScratchPad.recorded.should == [nil, 1, 2]
+ end
+
+ it "starts enumerable from result of first block call" do
+ array = "a\nb\nc\nd".lines
+ lines = Enumerator.produce { array.shift }.take_while { |s| s }
+
+ lines.should == ["a\n", "b\n", "c\n", "d"]
+ end
+ end
+
+ it "raises ArgumentError when no block is given" do
+ -> { Enumerator.produce }.should.raise(ArgumentError, "no block given")
+ end
+
+ ruby_version_is ""..."4.0" do
+ it "accepts keyword arguments as the initial value" do
+ enum = Enumerator.produce(a: 1, b: 1) {}
+ enum.take(1).should == [{a: 1, b: 1}]
+ end
+ end
+
+ ruby_version_is "4.0" do
+ it "raises ArgumentError for unknown keyword arguments" do
+ -> { Enumerator.produce(a: 1, b: 1) {} }.should.raise(ArgumentError, /unknown keywords/)
+ end
+ end
+
+ ruby_version_is "4.0" do
+ context "with size keyword argument" do
+ it "sets the size of the enumerator" do
+ enum = Enumerator.produce(0, size: 10) { |n| n + 1 }
+
+ enum.size.should == 10
+ enum.take(5).should == [0, 1, 2, 3, 4]
+ end
+
+ it "accepts a callable" do
+ enum = Enumerator.produce(0, size: -> { 5 * 5 }) { |n| n + 1 }
+
+ enum.size.should == 25
+ enum.take(5).should == [0, 1, 2, 3, 4]
+ end
+
+ it "accepts nil" do
+ enum = Enumerator.produce(0, size: nil) { |n| n + 1 }
+
+ enum.size.should == nil
+ enum.take(5).should == [0, 1, 2, 3, 4]
+ end
+ end
+ end
+end
diff --git a/spec/ruby/core/enumerator/product/each_spec.rb b/spec/ruby/core/enumerator/product/each_spec.rb
new file mode 100644
index 0000000000..a5dced4db1
--- /dev/null
+++ b/spec/ruby/core/enumerator/product/each_spec.rb
@@ -0,0 +1,85 @@
+require_relative '../../../spec_helper'
+require_relative '../../enumerable/shared/enumeratorized'
+
+describe "Enumerator::Product#each" do
+ it_behaves_like :enumeratorized_with_origin_size, :each, Enumerator::Product.new([1, 2], [:a, :b])
+
+ it "yields each element of Cartesian product of enumerators" do
+ enum = Enumerator::Product.new([1, 2], [:a, :b])
+ acc = []
+ enum.each { |e| acc << e }
+ acc.should == [[1, :a], [1, :b], [2, :a], [2, :b]]
+ end
+
+ it "calls #each_entry method on enumerators" do
+ object1 = Object.new
+ def object1.each_entry
+ yield 1
+ yield 2
+ end
+
+ object2 = Object.new
+ def object2.each_entry
+ yield :a
+ yield :b
+ end
+
+ enum = Enumerator::Product.new(object1, object2)
+ acc = []
+ enum.each { |e| acc << e }
+ acc.should == [[1, :a], [1, :b], [2, :a], [2, :b]]
+ end
+
+ it "raises a NoMethodError if the object doesn't respond to #each_entry" do
+ -> {
+ Enumerator::Product.new(Object.new).each {}
+ }.should.raise(NoMethodError, /undefined method [`']each_entry' for/)
+ end
+
+ it "returns enumerator if not given a block" do
+ enum = Enumerator::Product.new([1, 2], [:a, :b])
+ enum.each.should.kind_of?(Enumerator)
+
+ enum = Enumerator::Product.new([1, 2], [:a, :b])
+ enum.each.to_a.should == [[1, :a], [1, :b], [2, :a], [2, :b]]
+ end
+
+ it "returns self if given a block" do
+ enum = Enumerator::Product.new([1, 2], [:a, :b])
+ enum.each {}.should.equal?(enum)
+ end
+
+ it "doesn't accept arguments" do
+ Enumerator::Product.instance_method(:each).arity.should == 0
+ end
+
+ it "yields each element to a block that takes multiple arguments" do
+ enum = Enumerator::Product.new([1, 2], [:a, :b])
+
+ acc = []
+ enum.each { |x, y| acc << x }
+ acc.should == [1, 1, 2, 2]
+
+ acc = []
+ enum.each { |x, y| acc << y }
+ acc.should == [:a, :b, :a, :b]
+
+ acc = []
+ enum.each { |x, y, z| acc << z }
+ acc.should == [nil, nil, nil, nil]
+ end
+
+ it "yields no element when any enumerable is empty" do
+ enum = Enumerator::Product.new([], [1])
+
+ acc = []
+ enum.each { |x| acc << x }
+ acc.should == []
+
+ enum = Enumerator::Product.new([1], [])
+
+ acc = []
+ enum.each { |x| acc << x }
+ acc.should == []
+ end
+end
diff --git a/spec/ruby/core/enumerator/product/initialize_copy_spec.rb b/spec/ruby/core/enumerator/product/initialize_copy_spec.rb
new file mode 100644
index 0000000000..b5d2b345a9
--- /dev/null
+++ b/spec/ruby/core/enumerator/product/initialize_copy_spec.rb
@@ -0,0 +1,52 @@
+require_relative '../../../spec_helper'
+
+describe "Enumerator::Product#initialize_copy" do
+ it "replaces content of the receiver with content of the other object" do
+ enum = Enumerator::Product.new([true, false])
+ enum2 = Enumerator::Product.new([1, 2], [:a, :b])
+
+ enum.send(:initialize_copy, enum2)
+ enum.each.to_a.should == [[1, :a], [1, :b], [2, :a], [2, :b]]
+ end
+
+ it "returns self" do
+ enum = Enumerator::Product.new([true, false])
+ enum2 = Enumerator::Product.new([1, 2], [:a, :b])
+
+ enum.send(:initialize_copy, enum2).should.equal?(enum)
+ end
+
+ it "is a private method" do
+ Enumerator::Product.private_instance_methods(false).should.include?(:initialize_copy)
+ end
+
+ it "does nothing if the argument is the same as the receiver" do
+ enum = Enumerator::Product.new(1..2)
+ enum.send(:initialize_copy, enum).should.equal?(enum)
+
+ enum.freeze
+ enum.send(:initialize_copy, enum).should.equal?(enum)
+ end
+
+ it "raises FrozenError if the receiver is frozen" do
+ enum = Enumerator::Product.new(1..2)
+ enum2 = Enumerator::Product.new(3..4)
+
+ -> { enum.freeze.send(:initialize_copy, enum2) }.should.raise(FrozenError)
+ end
+
+ it "raises TypeError if the objects are of different class" do
+ enum = Enumerator::Product.new(1..2)
+ enum2 = Class.new(Enumerator::Product).new(3..4)
+
+ -> { enum.send(:initialize_copy, enum2) }.should.raise(TypeError, 'initialize_copy should take same class object')
+ -> { enum2.send(:initialize_copy, enum) }.should.raise(TypeError, 'initialize_copy should take same class object')
+ end
+
+ it "raises ArgumentError if the argument is not initialized yet" do
+ enum = Enumerator::Product.new(1..2)
+ enum2 = Enumerator::Product.allocate
+
+ -> { enum.send(:initialize_copy, enum2) }.should.raise(ArgumentError, 'uninitialized product')
+ end
+end
diff --git a/spec/ruby/core/enumerator/product/initialize_spec.rb b/spec/ruby/core/enumerator/product/initialize_spec.rb
new file mode 100644
index 0000000000..8814f9d3c7
--- /dev/null
+++ b/spec/ruby/core/enumerator/product/initialize_spec.rb
@@ -0,0 +1,31 @@
+require_relative '../../../spec_helper'
+
+describe "Enumerator::Product#initialize" do
+ before :each do
+ @uninitialized = Enumerator::Product.allocate
+ end
+
+ it "is a private method" do
+ Enumerator::Product.private_instance_methods(false).should.include?(:initialize)
+ end
+
+ it "returns self" do
+ @uninitialized.send(:initialize).should.equal?(@uninitialized)
+ end
+
+ it "accepts many arguments" do
+ @uninitialized.send(:initialize, 0..1, 2..3, 4..5).should.equal?(@uninitialized)
+ end
+
+ it "accepts arguments that are not Enumerable nor responding to :each_entry" do
+ @uninitialized.send(:initialize, Object.new).should.equal?(@uninitialized)
+ end
+
+ describe "on frozen instance" do
+ it "raises a FrozenError" do
+ -> {
+ @uninitialized.freeze.send(:initialize, 0..1)
+ }.should.raise(FrozenError)
+ end
+ end
+end
diff --git a/spec/ruby/core/enumerator/product/inspect_spec.rb b/spec/ruby/core/enumerator/product/inspect_spec.rb
new file mode 100644
index 0000000000..e0d7441f26
--- /dev/null
+++ b/spec/ruby/core/enumerator/product/inspect_spec.rb
@@ -0,0 +1,20 @@
+require_relative '../../../spec_helper'
+
+describe "Enumerator::Product#inspect" do
+ it "returns a String including enumerators" do
+ enum = Enumerator::Product.new([1, 2], [:a, :b])
+ enum.inspect.should == "#<Enumerator::Product: [[1, 2], [:a, :b]]>"
+ end
+
+ it "represents a recursive element with '[...]'" do
+ enum = [1, 2]
+ enum_recursive = Enumerator::Product.new(enum)
+
+ enum << enum_recursive
+ enum_recursive.inspect.should == "#<Enumerator::Product: [[1, 2, #<Enumerator::Product: ...>]]>"
+ end
+
+ it "returns a not initialized representation if #initialized is not called yet" do
+ Enumerator::Product.allocate.inspect.should == "#<Enumerator::Product: uninitialized>"
+ end
+end
diff --git a/spec/ruby/core/enumerator/product/rewind_spec.rb b/spec/ruby/core/enumerator/product/rewind_spec.rb
new file mode 100644
index 0000000000..2beffaf5c1
--- /dev/null
+++ b/spec/ruby/core/enumerator/product/rewind_spec.rb
@@ -0,0 +1,62 @@
+require_relative '../../../spec_helper'
+
+describe "Enumerator::Product#rewind" do
+ before :each do
+ @enum = Enumerator::Product.new([1, 2].each.to_enum, [:a, :b].each.to_enum)
+ end
+
+ it "resets the enumerator to its initial state" do
+ @enum.each.to_a.should == [[1, :a], [1, :b], [2, :a], [2, :b]]
+ @enum.rewind
+ @enum.each.to_a.should == [[1, :a], [1, :b], [2, :a], [2, :b]]
+ end
+
+ it "returns self" do
+ @enum.rewind.should.equal? @enum
+ end
+
+ it "has no effect on a new enumerator" do
+ @enum.rewind
+ @enum.each.to_a.should == [[1, :a], [1, :b], [2, :a], [2, :b]]
+ end
+
+ it "has no effect if called multiple, consecutive times" do
+ @enum.each.to_a.should == [[1, :a], [1, :b], [2, :a], [2, :b]]
+ @enum.rewind
+ @enum.rewind
+ @enum.each.to_a.should == [[1, :a], [1, :b], [2, :a], [2, :b]]
+ end
+
+ it "calls the enclosed object's rewind method if one exists" do
+ obj = mock('rewinder')
+ enum = Enumerator::Product.new(obj.to_enum)
+
+ obj.should_receive(:rewind)
+ enum.rewind
+ end
+
+ it "does nothing if the object doesn't have a #rewind method" do
+ obj = mock('rewinder')
+ enum = Enumerator::Product.new(obj.to_enum)
+
+ enum.rewind.should == enum
+ end
+
+ it "calls a rewind method on each enumerable in direct order" do
+ ScratchPad.record []
+
+ object1 = Object.new
+ def object1.rewind; ScratchPad << :object1; end
+
+ object2 = Object.new
+ def object2.rewind; ScratchPad << :object2; end
+
+ object3 = Object.new
+ def object3.rewind; ScratchPad << :object3; end
+
+ enum = Enumerator::Product.new(object1, object2, object3)
+ enum.rewind
+
+ ScratchPad.recorded.should == [:object1, :object2, :object3]
+ end
+end
diff --git a/spec/ruby/core/enumerator/product/size_spec.rb b/spec/ruby/core/enumerator/product/size_spec.rb
new file mode 100644
index 0000000000..0ba427af9a
--- /dev/null
+++ b/spec/ruby/core/enumerator/product/size_spec.rb
@@ -0,0 +1,64 @@
+require_relative '../../../spec_helper'
+
+describe "Enumerator::Product#size" do
+ it "returns the total size of the enumerator product calculated by multiplying the sizes of enumerables in the product" do
+ product = Enumerator::Product.new(1..2, 1..3, 1..4)
+ product.size.should == 24 # 2 * 3 * 4
+ end
+
+ it "returns nil if any enumerable reports its size as nil" do
+ enum = Object.new
+ def enum.size; nil; end
+
+ product = Enumerator::Product.new(1..2, enum)
+ product.size.should == nil
+ end
+
+ it "returns Float::INFINITY if any enumerable reports its size as Float::INFINITY" do
+ enum = Object.new
+ def enum.size; Float::INFINITY; end
+
+ product = Enumerator::Product.new(1..2, enum)
+ product.size.should == Float::INFINITY
+ end
+
+ it "returns nil if any enumerable reports its size as Float::NAN" do
+ enum = Object.new
+ def enum.size; Float::NAN; end
+
+ product = Enumerator::Product.new(1..2, enum)
+ product.size.should == nil
+ end
+
+ it "returns nil if any enumerable doesn't respond to #size" do
+ enum = Object.new
+ product = Enumerator::Product.new(1..2, enum)
+ product.size.should == nil
+ end
+
+ it "returns nil if any enumerable reports a not-convertible to Integer" do
+ enum = Object.new
+ def enum.size; :symbol; end
+
+ product = Enumerator::Product.new(1..2, enum)
+ product.size.should == nil
+ end
+
+ it "returns nil if any enumerable reports a non-Integer but convertible to Integer size" do
+ enum = Object.new
+ def enum.size; 1.0; end
+
+ product = Enumerator::Product.new(1..2, enum)
+ product.size.should == nil
+ end
+
+ ruby_version_is "3.4" do
+ it "returns zero when any enumerable reports zero" do
+ enum = Enumerator::Product.new(1...1, ["A", "B"])
+ enum.size.should == 0
+
+ enum = Enumerator::Product.new(["A", "B"], 1...1)
+ enum.size.should == 0
+ end
+ end
+end
diff --git a/spec/ruby/core/enumerator/product_spec.rb b/spec/ruby/core/enumerator/product_spec.rb
new file mode 100644
index 0000000000..0f37ef76e7
--- /dev/null
+++ b/spec/ruby/core/enumerator/product_spec.rb
@@ -0,0 +1,91 @@
+require_relative '../../spec_helper'
+
+describe "Enumerator.product" do
+ it "returns a Cartesian product of enumerators" do
+ enum = Enumerator.product(1..2, ["A", "B"])
+ enum.to_a.should == [[1, "A"], [1, "B"], [2, "A"], [2, "B"]]
+ end
+
+ it "accepts a list of enumerators of any length" do
+ enum = Enumerator.product(1..2)
+ enum.to_a.should == [[1], [2]]
+
+ enum = Enumerator.product(1..2, ["A"])
+ enum.to_a.should == [[1, "A"], [2, "A"]]
+
+ enum = Enumerator.product(1..2, ["A"], ["B"])
+ enum.to_a.should == [[1, "A", "B"], [2, "A", "B"]]
+
+ enum = Enumerator.product(2..3, ["A"], ["B"], ["C"])
+ enum.to_a.should == [[2, "A", "B", "C"], [3, "A", "B", "C"]]
+ end
+
+ it "returns an enumerator with an empty array when no arguments passed" do
+ enum = Enumerator.product
+ enum.to_a.should == [[]]
+ end
+
+ it "returns an instance of Enumerator::Product" do
+ enum = Enumerator.product
+ enum.class.should == Enumerator::Product
+ end
+
+ it "accepts infinite enumerators and returns infinite enumerator" do
+ enum = Enumerator.product(1.., ["A", "B"])
+ enum.take(5).should == [[1, "A"], [1, "B"], [2, "A"], [2, "B"], [3, "A"]]
+ enum.size.should == Float::INFINITY
+ end
+
+ it "accepts a block" do
+ elems = []
+ enum = Enumerator.product(1..2, ["X", "Y"]) { elems << _1 }
+
+ elems.should == [[1, "X"], [1, "Y"], [2, "X"], [2, "Y"]]
+ end
+
+ it "returns nil when a block passed" do
+ Enumerator.product(1..2) {}.should == nil
+ end
+
+ # https://bugs.ruby-lang.org/issues/19829
+ it "reject keyword arguments" do
+ -> {
+ Enumerator.product(1..3, foo: 1, bar: 2)
+ }.should.raise(ArgumentError, "unknown keywords: :foo, :bar")
+ end
+
+ it "calls only #each_entry method on arguments" do
+ object = Object.new
+ def object.each_entry
+ yield 1
+ yield 2
+ end
+
+ enum = Enumerator.product(object, ["A", "B"])
+ enum.to_a.should == [[1, "A"], [1, "B"], [2, "A"], [2, "B"]]
+ end
+
+ it "raises NoMethodError when argument doesn't respond to #each_entry" do
+ -> {
+ Enumerator.product(Object.new).to_a
+ }.should.raise(NoMethodError, /undefined method [`']each_entry' for/)
+ end
+
+ it "calls #each_entry lazily" do
+ Enumerator.product(Object.new).should.is_a?(Enumerator)
+ end
+
+ it "iterates through consuming enumerator elements only once" do
+ a = [1, 2, 3]
+ i = 0
+
+ enum = Enumerator.new do |y|
+ while i < a.size
+ y << a[i]
+ i += 1
+ end
+ end
+
+ Enumerator.product(['a', 'b'], enum).to_a.should == [["a", 1], ["a", 2], ["a", 3]]
+ end
+end
diff --git a/spec/ruby/core/enumerator/rewind_spec.rb b/spec/ruby/core/enumerator/rewind_spec.rb
index 666136d74a..6ba0edf174 100644
--- a/spec/ruby/core/enumerator/rewind_spec.rb
+++ b/spec/ruby/core/enumerator/rewind_spec.rb
@@ -1,9 +1,41 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/enumerator/rewind', __FILE__)
-require File.expand_path('../fixtures/common', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/common'
describe "Enumerator#rewind" do
- it_behaves_like(:enum_rewind, :rewind)
+ before :each do
+ @enum = 1.upto(3)
+ end
+
+ it "resets the enumerator to its initial state" do
+ @enum.next.should == 1
+ @enum.next.should == 2
+ @enum.rewind
+ @enum.next.should == 1
+ end
+
+ it "returns self" do
+ @enum.rewind.should.equal? @enum
+ end
+
+ it "has no effect on a new enumerator" do
+ @enum.rewind
+ @enum.next.should == 1
+ end
+
+ it "has no effect if called multiple, consecutive times" do
+ @enum.next.should == 1
+ @enum.rewind
+ @enum.rewind
+ @enum.next.should == 1
+ end
+
+ it "works with peek to reset the position" do
+ @enum.next
+ @enum.next
+ @enum.rewind
+ @enum.next
+ @enum.peek.should == 2
+ end
it "calls the enclosed object's rewind method if one exists" do
obj = mock('rewinder')
@@ -17,7 +49,7 @@ describe "Enumerator#rewind" do
obj = mock('rewinder')
enum = obj.to_enum
obj.should_receive(:each).at_most(1)
- lambda { enum.rewind.should == enum }.should_not raise_error
+ enum.rewind.should == enum
end
end
diff --git a/spec/ruby/core/enumerator/shared/each.rb b/spec/ruby/core/enumerator/shared/each.rb
new file mode 100644
index 0000000000..18ca773207
--- /dev/null
+++ b/spec/ruby/core/enumerator/shared/each.rb
@@ -0,0 +1,46 @@
+# #each passes source-yielded values to the block by ordinary block arity
+# (rb_yield_values2 semantics in CRuby), unlike the Enumerable collection methods
+# which pack them via rb_enum_values_pack() (see enumerable/shared/value_packing.rb).
+describe :enum_each, shared: true do
+ # @object must be set to a Proc that wraps an Enumerator into the receiver
+ # under test (e.g. -> e { e } for Enumerator#each, -> e { e.lazy } for Lazy#each).
+ describe "with a source that yields multiple values" do
+ before :each do
+ @enum = @object.call(Enumerator.new { |y| y.yield 1, 2; y.yield 3, 4 })
+ end
+
+ it "yields the first value to a single-argument block" do
+ collected = []
+ @enum.each { |x| collected << x }
+ collected.should == [1, 3]
+ end
+
+ it "yields each value to a multi-argument block" do
+ collected = []
+ @enum.each { |x, y| collected << [x, y] }
+ collected.should == [[1, 2], [3, 4]]
+ end
+
+ it "gathers the values for a splat block" do
+ collected = []
+ @enum.each { |*args| collected << args }
+ collected.should == [[1, 2], [3, 4]]
+ end
+ end
+
+ describe "with a source that yields a single value" do
+ it "yields the value to a single-argument block" do
+ collected = []
+ @object.call(Enumerator.new { |y| y.yield 7; y.yield 8 }).each { |x| collected << x }
+ collected.should == [7, 8]
+ end
+ end
+
+ describe "with a source that yields no value" do
+ it "yields nil to a single-argument block" do
+ collected = []
+ @object.call(Enumerator.new { |y| y.yield; y.yield }).each { |x| collected << x }
+ collected.should == [nil, nil]
+ end
+ end
+end
diff --git a/spec/ruby/core/enumerator/shared/with_index.rb b/spec/ruby/core/enumerator/shared/with_index.rb
new file mode 100644
index 0000000000..0992397e95
--- /dev/null
+++ b/spec/ruby/core/enumerator/shared/with_index.rb
@@ -0,0 +1,33 @@
+require_relative '../../../spec_helper'
+
+describe :enum_with_index, shared: true do
+
+ require_relative '../fixtures/classes'
+
+ before :each do
+ @origin = [1, 2, 3, 4]
+ @enum = @origin.to_enum
+ end
+
+ it "passes each element and its index to block" do
+ a = []
+ @enum.send(@method) { |o, i| a << [o, i] }
+ a.should == [[1, 0], [2, 1], [3, 2], [4, 3]]
+ end
+
+ it "returns the object being enumerated when given a block" do
+ @enum.send(@method) { |o, i| :glark }.should.equal?(@origin)
+ end
+
+ it "binds splat arguments properly" do
+ acc = []
+ @enum.send(@method) { |*b| c,d = b; acc << c; acc << d }
+ [1, 0, 2, 1, 3, 2, 4, 3].should == acc
+ end
+
+ it "returns an enumerator if no block is supplied" do
+ ewi = @enum.send(@method)
+ ewi.should.instance_of?(Enumerator)
+ ewi.to_a.should == [[1, 0], [2, 1], [3, 2], [4, 3]]
+ end
+end
diff --git a/spec/ruby/core/enumerator/size_spec.rb b/spec/ruby/core/enumerator/size_spec.rb
index ef7940dc16..4b2beffbbe 100644
--- a/spec/ruby/core/enumerator/size_spec.rb
+++ b/spec/ruby/core/enumerator/size_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Enumerator#size" do
it "returns same value if set size is an Integer" do
@@ -6,12 +6,12 @@ describe "Enumerator#size" do
end
it "returns nil if set size is nil" do
- Enumerator.new(nil) {}.size.should be_nil
+ Enumerator.new(nil) {}.size.should == nil
end
it "returns returning value from size.call if set size is a Proc" do
base_size = 100
- enum = Enumerator.new(lambda { base_size + 1 }) {}
+ enum = Enumerator.new(-> { base_size + 1 }) {}
base_size = 200
enum.size.should == 201
base_size = 300
diff --git a/spec/ruby/core/enumerator/to_enum_spec.rb b/spec/ruby/core/enumerator/to_enum_spec.rb
deleted file mode 100644
index a719e62212..0000000000
--- a/spec/ruby/core/enumerator/to_enum_spec.rb
+++ /dev/null
@@ -1,6 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/enumerator/enum_for', __FILE__)
-
-describe "Enumerator#to_enum" do
- it_behaves_like :enum_for, :enum_for
-end
diff --git a/spec/ruby/core/enumerator/with_index_spec.rb b/spec/ruby/core/enumerator/with_index_spec.rb
index 3d0ec0a298..ca90fd18f7 100644
--- a/spec/ruby/core/enumerator/with_index_spec.rb
+++ b/spec/ruby/core/enumerator/with_index_spec.rb
@@ -1,28 +1,28 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/enumerator/with_index', __FILE__)
-require File.expand_path('../../enumerable/shared/enumeratorized', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/with_index'
+require_relative '../enumerable/shared/enumeratorized'
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
enum2 = enum1.with_index
- enum2.should be_an_instance_of(Enumerator)
+ enum2.should.instance_of?(Enumerator)
enum1.should_not === enum2
end
it "accepts an optional argument when given a block" do
- lambda do
+ -> do
@enum.with_index(1) { |f| f}
- end.should_not raise_error(ArgumentError)
+ end.should_not.raise(ArgumentError)
end
it "accepts an optional argument when not given a block" do
- lambda do
+ -> do
@enum.with_index(1)
- end.should_not raise_error(ArgumentError)
+ end.should_not.raise(ArgumentError)
end
it "numbers indices from the given index when given an offset but no block" do
@@ -36,9 +36,9 @@ describe "Enumerator#with_index" do
end
it "raises a TypeError when the argument cannot be converted to numeric" do
- lambda do
+ -> do
@enum.with_index('1') {|*i| i}
- end.should raise_error(TypeError)
+ end.should.raise(TypeError)
end
it "converts non-numeric arguments to Integer via #to_int" do
@@ -69,4 +69,21 @@ describe "Enumerator#with_index" do
@enum.with_index(-1) { |*x| res << x}
res.should == [[1,-1], [2,0], [3,1], [4,2]]
end
+
+ it "passes on the given block's return value" do
+ arr = [1,2,3]
+ arr.delete_if.with_index { |a,b| false }
+ arr.should == [1,2,3]
+
+ arr.delete_if.with_index { |a,b| true }
+ arr.should == []
+ end
+
+ it "returns the iterator's return value" do
+ @enum.select.with_index { |a,b| false }.should == []
+ end
+
+ it "returns the correct value if chained with itself" do
+ [:a].each.with_index.with_index.to_a.should == [[[:a,0],0]]
+ end
end
diff --git a/spec/ruby/core/enumerator/with_object_spec.rb b/spec/ruby/core/enumerator/with_object_spec.rb
index a7bd74220c..790be66a11 100644
--- a/spec/ruby/core/enumerator/with_object_spec.rb
+++ b/spec/ruby/core/enumerator/with_object_spec.rb
@@ -1,6 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/enumerator/with_object', __FILE__)
+require_relative '../../spec_helper'
describe "Enumerator#with_object" do
- it_behaves_like :enum_with_object, :with_object
+ it "is an alias of Enumerator#each_with_object" do
+ Enumerator.instance_method(:with_object).should == Enumerator.instance_method(:each_with_object)
+ end
end
diff --git a/spec/ruby/core/enumerator/yielder/append_spec.rb b/spec/ruby/core/enumerator/yielder/append_spec.rb
deleted file mode 100644
index d2313b01f4..0000000000
--- a/spec/ruby/core/enumerator/yielder/append_spec.rb
+++ /dev/null
@@ -1,35 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-
-describe "Enumerator::Yielder#<<" do
- # TODO: There's some common behavior between yield and <<; move to a shared spec
- it "yields the value to the block" do
- ary = []
- y = Enumerator::Yielder.new {|x| ary << x}
- y << 1
-
- ary.should == [1]
- end
-
- it "doesn't double-wrap Arrays" do
- yields = []
- y = Enumerator::Yielder.new {|args| yields << args }
- y << [1]
- yields.should == [[1]]
- end
-
- it "returns self" do
- y = Enumerator::Yielder.new {|x| x + 1}
- (y << 1).should equal(y)
- end
-
- it "requires multiple arguments" do
- Enumerator::Yielder.instance_method(:<<).arity.should < 0
- end
-
- it "yields with passed arguments" do
- yields = []
- y = Enumerator::Yielder.new {|*args| yields << args }
- y.<<(1, 2)
- yields.should == [[1, 2]]
- end
-end
diff --git a/spec/ruby/core/enumerator/yielder/initialize_spec.rb b/spec/ruby/core/enumerator/yielder/initialize_spec.rb
deleted file mode 100644
index 095b6a64c6..0000000000
--- a/spec/ruby/core/enumerator/yielder/initialize_spec.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-# -*- encoding: us-ascii -*-
-
-require File.expand_path('../../../../spec_helper', __FILE__)
-
-describe "Enumerator::Yielder#initialize" do
- before :each do
- @class = Enumerator::Yielder
- @uninitialized = @class.allocate
- end
-
- it "is a private method" do
- @class.should have_private_instance_method(:initialize, false)
- end
-
- it "returns self when given a block" do
- @uninitialized.send(:initialize) {}.should equal(@uninitialized)
- end
-end
diff --git a/spec/ruby/core/enumerator/yielder/yield_spec.rb b/spec/ruby/core/enumerator/yielder/yield_spec.rb
deleted file mode 100644
index be904afef1..0000000000
--- a/spec/ruby/core/enumerator/yielder/yield_spec.rb
+++ /dev/null
@@ -1,16 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-
-describe "Enumerator::Yielder#yield" do
- it "yields the value to the block" do
- ary = []
- y = Enumerator::Yielder.new {|x| ary << x}
- y.yield 1
-
- ary.should == [1]
- end
-
- it "returns the result of the block for the given value" do
- y = Enumerator::Yielder.new {|x| x + 1}
- y.yield(1).should == 2
- end
-end
diff --git a/spec/ruby/core/env/assoc_spec.rb b/spec/ruby/core/env/assoc_spec.rb
index fb10a52b3c..b81be7ddf2 100644
--- a/spec/ruby/core/env/assoc_spec.rb
+++ b/spec/ruby/core/env/assoc_spec.rb
@@ -1,8 +1,12 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "ENV.assoc" do
+ before :each do
+ @foo = ENV["foo"]
+ end
+
after :each do
- ENV.delete("foo")
+ ENV["foo"] = @foo
end
it "returns an array of the key and value of the environment variable with the given key" do
@@ -20,4 +24,8 @@ describe "ENV.assoc" do
k.should_receive(:to_str).and_return("foo")
ENV.assoc(k).should == ["foo", "bar"]
end
+
+ it "raises TypeError if the argument is not a String and does not respond to #to_str" do
+ -> { ENV.assoc(Object.new) }.should.raise(TypeError, "no implicit conversion of Object into String")
+ end
end
diff --git a/spec/ruby/core/env/clear_spec.rb b/spec/ruby/core/env/clear_spec.rb
index c184926cc2..c0d20193ad 100644
--- a/spec/ruby/core/env/clear_spec.rb
+++ b/spec/ruby/core/env/clear_spec.rb
@@ -1,10 +1,10 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "ENV.clear" do
it "deletes all environment variables" do
orig = ENV.to_hash
begin
- ENV.clear
+ ENV.clear.should.equal?(ENV)
# This used 'env' the helper before. That shells out to 'env' which
# itself sets up certain environment variables before it runs, because
diff --git a/spec/ruby/core/env/clone_spec.rb b/spec/ruby/core/env/clone_spec.rb
new file mode 100644
index 0000000000..bb3c7ff2f8
--- /dev/null
+++ b/spec/ruby/core/env/clone_spec.rb
@@ -0,0 +1,21 @@
+require_relative '../../spec_helper'
+
+describe "ENV#clone" do
+ it "raises ArgumentError when keyword argument 'freeze' is neither nil nor boolean" do
+ -> {
+ ENV.clone(freeze: 1)
+ }.should.raise(ArgumentError)
+ end
+
+ it "raises ArgumentError when keyword argument is not 'freeze'" do
+ -> {
+ ENV.clone(foo: nil)
+ }.should.raise(ArgumentError)
+ end
+
+ it "raises TypeError" do
+ -> {
+ ENV.clone
+ }.should.raise(TypeError, /Cannot clone ENV, use ENV.to_h to get a copy of ENV as a hash/)
+ end
+end
diff --git a/spec/ruby/core/env/delete_if_spec.rb b/spec/ruby/core/env/delete_if_spec.rb
index 9a8220ae7d..4b05064eba 100644
--- a/spec/ruby/core/env/delete_if_spec.rb
+++ b/spec/ruby/core/env/delete_if_spec.rb
@@ -1,26 +1,53 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../enumerable/shared/enumeratorized', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../enumerable/shared/enumeratorized'
describe "ENV.delete_if" do
+ before :each do
+ @foo = ENV["foo"]
+ @bar = ENV["bar"]
+
+ ENV["foo"] = "0"
+ ENV["bar"] = "1"
+ end
+
+ after :each do
+ ENV["foo"] = @foo
+ ENV["bar"] = @bar
+ end
+
it "deletes pairs if the block returns true" do
- ENV["foo"] = "bar"
- ENV.delete_if { |k, v| k == "foo" }
+ ENV.delete_if { |k, v| ["foo", "bar"].include?(k) }
ENV["foo"].should == nil
+ ENV["bar"].should == nil
+ end
+
+ it "returns ENV when block given" do
+ ENV.delete_if { |k, v| ["foo", "bar"].include?(k) }.should.equal?(ENV)
end
it "returns ENV even if nothing deleted" do
- ENV.delete_if { false }.should_not == nil
+ ENV.delete_if { false }.should.equal?(ENV)
end
it "returns an Enumerator if no block given" do
- ENV.delete_if.should be_an_instance_of(Enumerator)
+ ENV.delete_if.should.instance_of?(Enumerator)
end
it "deletes pairs through enumerator" do
- ENV["foo"] = "bar"
enum = ENV.delete_if
- enum.each { |k, v| k == "foo" }
+ enum.each { |k, v| ["foo", "bar"].include?(k) }
ENV["foo"].should == nil
+ ENV["bar"].should == nil
+ end
+
+ it "returns ENV from enumerator" do
+ enum = ENV.delete_if
+ enum.each { |k, v| ["foo", "bar"].include?(k) }.should.equal?(ENV)
+ end
+
+ it "returns ENV from enumerator even if nothing deleted" do
+ enum = ENV.delete_if
+ enum.each { false }.should.equal?(ENV)
end
it_behaves_like :enumeratorized_with_origin_size, :delete_if, ENV
diff --git a/spec/ruby/core/env/delete_spec.rb b/spec/ruby/core/env/delete_spec.rb
index e02adf963f..db6d07b057 100644
--- a/spec/ruby/core/env/delete_spec.rb
+++ b/spec/ruby/core/env/delete_spec.rb
@@ -1,8 +1,11 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "ENV.delete" do
+ before :each do
+ @saved_foo = ENV["foo"]
+ end
after :each do
- ENV.delete("foo")
+ ENV["foo"] = @saved_foo
end
it "removes the variable from the environment" do
@@ -16,9 +19,37 @@ describe "ENV.delete" do
ENV.delete("foo").should == "bar"
end
+ it "returns nil if the named environment variable does not exist and no block given" do
+ ENV.delete("foo")
+ ENV.delete("foo").should == nil
+ end
+
it "yields the name to the given block if the named environment variable does not exist" do
ENV.delete("foo")
ENV.delete("foo") { |name| ScratchPad.record name }
ScratchPad.recorded.should == "foo"
end
+
+ it "returns the result of given block if the named environment variable does not exist" do
+ ENV.delete("foo")
+ ENV.delete("foo") { |name| "bar" }.should == "bar"
+ end
+
+ it "does not evaluate the block if the environment variable exists" do
+ ENV["foo"] = "bar"
+ ENV.delete("foo") { |name| fail "Should not happen" }
+ ENV["foo"].should == nil
+ end
+
+ it "removes the variable coerced with #to_str" do
+ ENV["foo"] = "bar"
+ k = mock('key')
+ k.should_receive(:to_str).and_return("foo")
+ ENV.delete(k)
+ ENV["foo"].should == nil
+ end
+
+ it "raises TypeError if the argument is not a String and does not respond to #to_str" do
+ -> { ENV.delete(Object.new) }.should.raise(TypeError, "no implicit conversion of Object into String")
+ end
end
diff --git a/spec/ruby/core/env/dup_spec.rb b/spec/ruby/core/env/dup_spec.rb
new file mode 100644
index 0000000000..d8cfac891d
--- /dev/null
+++ b/spec/ruby/core/env/dup_spec.rb
@@ -0,0 +1,9 @@
+require_relative '../../spec_helper'
+
+describe "ENV#dup" do
+ it "raises TypeError" do
+ -> {
+ ENV.dup
+ }.should.raise(TypeError, /Cannot dup ENV, use ENV.to_h to get a copy of ENV as a hash/)
+ end
+end
diff --git a/spec/ruby/core/env/each_key_spec.rb b/spec/ruby/core/env/each_key_spec.rb
index 82721cdb96..ad2cb560a0 100644
--- a/spec/ruby/core/env/each_key_spec.rb
+++ b/spec/ruby/core/env/each_key_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../enumerable/shared/enumeratorized', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../enumerable/shared/enumeratorized'
describe "ENV.each_key" do
@@ -10,16 +10,18 @@ describe "ENV.each_key" do
ENV.clear
ENV["1"] = "3"
ENV["2"] = "4"
- ENV.each_key { |k| e << k }
- e.should include("1")
- e.should include("2")
+ ENV.each_key { |k| e << k }.should.equal?(ENV)
+ e.should.include?("1")
+ e.should.include?("2")
ensure
ENV.replace orig
end
end
it "returns an Enumerator if called without a block" do
- ENV.each_key.should be_an_instance_of(Enumerator)
+ enum = ENV.each_key
+ enum.should.instance_of?(Enumerator)
+ enum.to_a.should == ENV.keys
end
it "returns keys in the locale encoding" do
diff --git a/spec/ruby/core/env/each_pair_spec.rb b/spec/ruby/core/env/each_pair_spec.rb
index 255ccd86c5..1acd2fbb00 100644
--- a/spec/ruby/core/env/each_pair_spec.rb
+++ b/spec/ruby/core/env/each_pair_spec.rb
@@ -1,6 +1,63 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/each.rb', __FILE__)
+require_relative 'spec_helper'
+require_relative '../enumerable/shared/enumeratorized'
describe "ENV.each_pair" do
- it_behaves_like(:env_each, :each_pair)
+ it "returns each pair" do
+ orig = ENV.to_hash
+ e = []
+ begin
+ ENV.clear
+ ENV["foo"] = "bar"
+ ENV["baz"] = "boo"
+ ENV.each_pair { |k, v| e << [k, v] }.should.equal?(ENV)
+ e.should.include?(["foo", "bar"])
+ e.should.include?(["baz", "boo"])
+ ensure
+ ENV.replace orig
+ end
+ end
+
+ it "returns an Enumerator if called without a block" do
+ enum = ENV.each_pair
+ enum.should.instance_of?(Enumerator)
+ enum.each do |name, value|
+ ENV[name].should == value
+ end
+ end
+
+ it_behaves_like :enumeratorized_with_origin_size, :each_pair, ENV
+
+ describe "with encoding" do
+ before :each do
+ @external = Encoding.default_external
+ @internal = Encoding.default_internal
+
+ Encoding.default_external = Encoding::BINARY
+ end
+
+ after :each do
+ Encoding.default_external = @external
+ Encoding.default_internal = @internal
+ end
+
+ it "uses the locale encoding when Encoding.default_internal is nil" do
+ Encoding.default_internal = nil
+
+ ENV.each_pair do |key, value|
+ key.should.be_locale_env
+ value.should.be_locale_env
+ end
+ end
+
+ it "transcodes from the locale encoding to Encoding.default_internal if set" do
+ Encoding.default_internal = internal = Encoding::IBM437
+
+ ENV.each_pair do |key, value|
+ key.encoding.should.equal?(internal)
+ if value.ascii_only?
+ value.encoding.should.equal?(internal)
+ end
+ end
+ end
+ end
end
diff --git a/spec/ruby/core/env/each_spec.rb b/spec/ruby/core/env/each_spec.rb
index 2424c5e4e0..166a0b4fc8 100644
--- a/spec/ruby/core/env/each_spec.rb
+++ b/spec/ruby/core/env/each_spec.rb
@@ -1,6 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/each.rb', __FILE__)
+require_relative 'spec_helper'
describe "ENV.each" do
- it_behaves_like(:env_each, :each)
+ it "is an alias of ENV.each_pair" do
+ ENV.method(:each).should == ENV.method(:each_pair)
+ end
end
diff --git a/spec/ruby/core/env/each_value_spec.rb b/spec/ruby/core/env/each_value_spec.rb
index 070a1d2cb9..6f65e923e6 100644
--- a/spec/ruby/core/env/each_value_spec.rb
+++ b/spec/ruby/core/env/each_value_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../enumerable/shared/enumeratorized', __FILE__)
+require_relative 'spec_helper'
+require_relative '../enumerable/shared/enumeratorized'
describe "ENV.each_value" do
@@ -10,21 +10,23 @@ describe "ENV.each_value" do
ENV.clear
ENV["1"] = "3"
ENV["2"] = "4"
- ENV.each_value { |v| e << v }
- e.should include("3")
- e.should include("4")
+ ENV.each_value { |v| e << v }.should.equal?(ENV)
+ e.should.include?("3")
+ e.should.include?("4")
ensure
ENV.replace orig
end
end
it "returns an Enumerator if called without a block" do
- ENV.each_value.should be_an_instance_of(Enumerator)
+ enum = ENV.each_value
+ enum.should.instance_of?(Enumerator)
+ enum.to_a.should == ENV.values
end
it "uses the locale encoding" do
ENV.each_value do |value|
- value.encoding.should == Encoding.find('locale')
+ value.should.be_locale_env
end
end
diff --git a/spec/ruby/core/env/element_reference_spec.rb b/spec/ruby/core/env/element_reference_spec.rb
index 2e6402dd28..e3ac979418 100644
--- a/spec/ruby/core/env/element_reference_spec.rb
+++ b/spec/ruby/core/env/element_reference_spec.rb
@@ -1,5 +1,6 @@
-# -*- encoding: ascii-8bit -*-
-require File.expand_path('../../../spec_helper', __FILE__)
+# encoding: binary
+require_relative '../../spec_helper'
+require_relative 'fixtures/common'
describe "ENV.[]" do
before :each do
@@ -16,7 +17,18 @@ describe "ENV.[]" do
it "returns only frozen values" do
ENV[@variable] = "a non-frozen string"
- ENV[@variable].frozen?.should == true
+ ENV[@variable].should.frozen?
+ end
+
+ it "coerces a non-string name with #to_str" do
+ ENV[@variable] = "bar"
+ k = mock('key')
+ k.should_receive(:to_str).and_return(@variable)
+ ENV[k].should == "bar"
+ end
+
+ it "raises TypeError if the argument is not a String and does not respond to #to_str" do
+ -> { ENV[Object.new] }.should.raise(TypeError, "no implicit conversion of Object into String")
end
platform_is :windows do
@@ -27,40 +39,38 @@ describe "ENV.[]" do
end
end
-with_feature :encoding do
- describe "ENV.[]" do
- before :each do
- @variable = "env_element_reference_encoding_specs"
+describe "ENV.[]" do
+ before :each do
+ @variable = "env_element_reference_encoding_specs"
- @external = Encoding.default_external
- @internal = Encoding.default_internal
+ @external = Encoding.default_external
+ @internal = Encoding.default_internal
- Encoding.default_external = Encoding::ASCII_8BIT
- end
+ Encoding.default_external = Encoding::BINARY
+ end
- after :each do
- Encoding.default_external = @external
- Encoding.default_internal = @internal
+ after :each do
+ Encoding.default_external = @external
+ Encoding.default_internal = @internal
- ENV.delete @variable
- end
+ ENV.delete @variable
+ end
- it "uses the locale encoding if Encoding.default_internal is nil" do
- Encoding.default_internal = nil
+ it "uses the locale encoding if Encoding.default_internal is nil" do
+ Encoding.default_internal = nil
- locale = Encoding.find('locale')
- locale = Encoding::ASCII_8BIT if locale == Encoding::US_ASCII
- ENV[@variable] = "\xC3\xB8"
- ENV[@variable].encoding.should == locale
- end
+ locale = ENVSpecs.encoding
+ locale = Encoding::BINARY if locale == Encoding::US_ASCII
+ ENV[@variable] = "\xC3\xB8"
+ ENV[@variable].encoding.should == locale
+ end
- it "transcodes from the locale encoding to Encoding.default_internal if set" do
- # We cannot reliably know the locale encoding, so we merely check that
- # the result string has the expected encoding.
- ENV[@variable] = ""
- Encoding.default_internal = Encoding::IBM437
+ it "transcodes from the locale encoding to Encoding.default_internal if set" do
+ # We cannot reliably know the locale encoding, so we merely check that
+ # the result string has the expected encoding.
+ ENV[@variable] = ""
+ Encoding.default_internal = Encoding::IBM437
- ENV[@variable].encoding.should equal(Encoding::IBM437)
- end
+ ENV[@variable].encoding.should.equal?(Encoding::IBM437)
end
end
diff --git a/spec/ruby/core/env/element_set_spec.rb b/spec/ruby/core/env/element_set_spec.rb
index a80cd0c51e..ca5d468009 100644
--- a/spec/ruby/core/env/element_set_spec.rb
+++ b/spec/ruby/core/env/element_set_spec.rb
@@ -1,6 +1,62 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/store.rb', __FILE__)
+require_relative '../../spec_helper'
describe "ENV.[]=" do
- it_behaves_like(:env_store, :[]=)
+ before :each do
+ @saved_foo = ENV["foo"]
+ end
+
+ after :each do
+ ENV["foo"] = @saved_foo
+ end
+
+ it "sets the environment variable to the given value" do
+ ENV["foo"] = "bar"
+ ENV["foo"].should == "bar"
+ end
+
+ it "returns the value" do
+ value = "bar"
+ ENV.send(:[]=, "foo", value).should.equal?(value)
+ end
+
+ it "deletes the environment variable when the value is nil" do
+ ENV["foo"] = "bar"
+ ENV["foo"] = nil
+ ENV.key?("foo").should == false
+ end
+
+ it "coerces the key argument with #to_str" do
+ k = mock("key")
+ k.should_receive(:to_str).and_return("foo")
+ ENV[k] = "bar"
+ ENV["foo"].should == "bar"
+ end
+
+ it "coerces the value argument with #to_str" do
+ v = mock("value")
+ v.should_receive(:to_str).and_return("bar")
+ ENV["foo"] = v
+ ENV["foo"].should == "bar"
+ end
+
+ it "raises TypeError when the key is not coercible to String" do
+ -> { ENV[Object.new] = "bar" }.should.raise(TypeError, "no implicit conversion of Object into String")
+ end
+
+ it "raises TypeError when the value is not coercible to String" do
+ -> { ENV["foo"] = Object.new }.should.raise(TypeError, "no implicit conversion of Object into String")
+ end
+
+ it "raises Errno::EINVAL when the key contains the '=' character" do
+ -> { ENV["foo="] = "bar" }.should.raise(Errno::EINVAL)
+ end
+
+ it "raises Errno::EINVAL when the key is an empty string" do
+ -> { ENV[""] = "bar" }.should.raise(Errno::EINVAL)
+ end
+
+ it "does nothing when the key is not a valid environment variable key and the value is nil" do
+ ENV["foo="] = nil
+ ENV.key?("foo=").should == false
+ end
end
diff --git a/spec/ruby/core/env/empty_spec.rb b/spec/ruby/core/env/empty_spec.rb
index fa02985a6e..afeb406a9e 100644
--- a/spec/ruby/core/env/empty_spec.rb
+++ b/spec/ruby/core/env/empty_spec.rb
@@ -1,15 +1,15 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "ENV.empty?" do
it "returns true if the Environment is empty" do
if ENV.keys.size > 0
- ENV.empty?.should == false
+ ENV.should_not.empty?
end
orig = ENV.to_hash
begin
ENV.clear
- ENV.empty?.should == true
+ ENV.should.empty?
ensure
ENV.replace orig
end
@@ -17,7 +17,7 @@ describe "ENV.empty?" do
it "returns false if not empty" do
if ENV.keys.size > 0
- ENV.empty?.should == false
+ ENV.should_not.empty?
end
end
end
diff --git a/spec/ruby/core/env/except_spec.rb b/spec/ruby/core/env/except_spec.rb
new file mode 100644
index 0000000000..fb8f3b7536
--- /dev/null
+++ b/spec/ruby/core/env/except_spec.rb
@@ -0,0 +1,34 @@
+require_relative 'spec_helper'
+require_relative 'shared/to_hash'
+
+describe "ENV.except" do
+ before do
+ @orig_hash = ENV.to_hash
+ end
+
+ after do
+ ENV.replace @orig_hash
+ end
+
+ # Testing the method without arguments is covered via
+ it_behaves_like :env_to_hash, :except
+
+ it "returns a hash without the requested subset" do
+ ENV.clear
+
+ ENV['one'] = '1'
+ ENV['two'] = '2'
+ ENV['three'] = '3'
+
+ ENV.except('one', 'three').should == { 'two' => '2' }
+ end
+
+ it "ignores keys not present in the original hash" do
+ ENV.clear
+
+ ENV['one'] = '1'
+ ENV['two'] = '2'
+
+ ENV.except('one', 'three').should == { 'two' => '2' }
+ end
+end
diff --git a/spec/ruby/core/env/fetch_spec.rb b/spec/ruby/core/env/fetch_spec.rb
index 708ee91c39..a2ec79c62b 100644
--- a/spec/ruby/core/env/fetch_spec.rb
+++ b/spec/ruby/core/env/fetch_spec.rb
@@ -1,35 +1,63 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../../shared/hash/key_error'
+require_relative 'fixtures/common'
describe "ENV.fetch" do
+ before :each do
+ @foo_saved = ENV.delete("foo")
+ end
+ after :each do
+ ENV["foo"] = @saved_foo
+ end
+
it "returns a value" do
ENV["foo"] = "bar"
ENV.fetch("foo").should == "bar"
- ENV.delete "foo"
end
it "raises a TypeError if the key is not a String" do
- lambda { ENV.fetch :should_never_be_set }.should raise_error(TypeError)
+ -> { ENV.fetch Object.new }.should.raise(TypeError, "no implicit conversion of Object into String")
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
+
+ it "formats the object with #inspect in the KeyError message" do
+ -> {
+ ENV.fetch('foo')
+ }.should.raise(KeyError, 'key not found: "foo"')
+ end
end
it "provides the given default parameter" do
- ENV.fetch("should_never_be_set", "default").should == "default"
+ ENV.fetch("foo", "default").should == "default"
+ end
+
+ it "does not insist that the default be a String" do
+ ENV.fetch("foo", :default).should == :default
end
it "provides a default value from a block" do
- ENV.fetch("should_never_be_set") { |k| "wanted #{k}" }.should == "wanted should_never_be_set"
+ ENV.fetch("foo") { |k| "wanted #{k}" }.should == "wanted foo"
+ end
+
+ it "does not insist that the block return a String" do
+ ENV.fetch("foo") { |k| k.to_sym }.should == :foo
end
it "warns on block and default parameter given" do
- lambda do
- ENV.fetch("should_never_be_set", "default") { 1 }.should == 1
+ -> do
+ ENV.fetch("foo", "default") { "bar" }.should == "bar"
end.should complain(/block supersedes default value argument/)
end
+ it "does not evaluate the block when key found" do
+ ENV["foo"] = "bar"
+ ENV.fetch("foo") { fail "should not get here"}.should == "bar"
+ end
+
it "uses the locale encoding" do
- ENV.fetch(ENV.keys.first).encoding.should == Encoding.find('locale')
+ ENV["foo"] = "bar"
+ ENV.fetch("foo").encoding.should == ENVSpecs.encoding
end
end
diff --git a/spec/ruby/core/env/fetch_values_spec.rb b/spec/ruby/core/env/fetch_values_spec.rb
new file mode 100644
index 0000000000..302cde2fd1
--- /dev/null
+++ b/spec/ruby/core/env/fetch_values_spec.rb
@@ -0,0 +1,51 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/common'
+
+ruby_version_is "4.1" do
+ describe "ENV.fetch_values" do
+ before :each do
+ @saved_foo = ENV["foo"]
+ @saved_bar = ENV["bar"]
+ ENV.delete("foo")
+ ENV.delete("bar")
+ end
+
+ after :each do
+ ENV["foo"] = @saved_foo
+ ENV["bar"] = @saved_bar
+ end
+
+ it "returns an array of the values corresponding to the given keys" do
+ ENV["foo"] = "oof"
+ ENV["bar"] = "rab"
+ ENV.fetch_values("bar", "foo").should == ["rab", "oof"]
+ end
+
+ it "returns the default value from block" do
+ ENV["foo"] = "oof"
+ ENV.fetch_values("bar") { |key| "`#{key}' is not found" }.should == ["`bar' is not found"]
+ ENV.fetch_values("bar", "foo") { |key| "`#{key}' is not found" }.should == ["`bar' is not found", "oof"]
+ end
+
+ it "returns an empty array if no keys specified" do
+ ENV.fetch_values.should == []
+ end
+
+ it "raises KeyError when there is no matching key" do
+ ENV["foo"] = "oof"
+ ENV["bar"] = "rab"
+ -> {
+ ENV.fetch_values("bar", "y", "foo", "z")
+ }.should.raise(KeyError, 'key not found: "y"')
+ end
+
+ it "uses the locale encoding" do
+ ENV.fetch_values(ENV.keys.first).first.encoding.should == ENVSpecs.encoding
+ end
+
+ it "raises TypeError when a key is not coercible to String" do
+ ENV["foo"] = "oof"
+ -> { ENV.fetch_values("foo", Object.new) }.should.raise(TypeError, "no implicit conversion of Object into String")
+ end
+ end
+end
diff --git a/spec/ruby/core/env/filter_spec.rb b/spec/ruby/core/env/filter_spec.rb
new file mode 100644
index 0000000000..54997bfda1
--- /dev/null
+++ b/spec/ruby/core/env/filter_spec.rb
@@ -0,0 +1,13 @@
+require_relative '../../spec_helper'
+
+describe "ENV.filter!" do
+ it "is an alias of ENV.select!" do
+ ENV.method(:filter!).should == ENV.method(:select!)
+ end
+end
+
+describe "ENV.filter" do
+ it "is an alias of ENV.select" do
+ ENV.method(:filter).should == ENV.method(:select)
+ end
+end
diff --git a/spec/ruby/core/env/fixtures/common.rb b/spec/ruby/core/env/fixtures/common.rb
new file mode 100644
index 0000000000..8d5057614d
--- /dev/null
+++ b/spec/ruby/core/env/fixtures/common.rb
@@ -0,0 +1,9 @@
+module ENVSpecs
+ def self.encoding
+ locale = Encoding.find('locale')
+ if ruby_version_is '3' and platform_is :windows
+ locale = Encoding::UTF_8
+ end
+ locale
+ end
+end
diff --git a/spec/ruby/core/env/has_key_spec.rb b/spec/ruby/core/env/has_key_spec.rb
index 8da2d94265..7feeec8dfa 100644
--- a/spec/ruby/core/env/has_key_spec.rb
+++ b/spec/ruby/core/env/has_key_spec.rb
@@ -1,6 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/include.rb', __FILE__)
+require_relative '../../spec_helper'
describe "ENV.has_key?" do
- it_behaves_like(:env_include, :has_key?)
+ it "is an alias of ENV.include?" do
+ ENV.method(:has_key?).should == ENV.method(:include?)
+ end
end
diff --git a/spec/ruby/core/env/has_value_spec.rb b/spec/ruby/core/env/has_value_spec.rb
index 76980a8df4..b76ec0dc5d 100644
--- a/spec/ruby/core/env/has_value_spec.rb
+++ b/spec/ruby/core/env/has_value_spec.rb
@@ -1,6 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/value.rb', __FILE__)
+require_relative '../../spec_helper'
describe "ENV.has_value?" do
- it_behaves_like(:env_value, :has_value?)
+ it "is an alias of ENV.value?" do
+ ENV.method(:has_value?).should == ENV.method(:value?)
+ end
end
diff --git a/spec/ruby/core/env/include_spec.rb b/spec/ruby/core/env/include_spec.rb
index 4a716fee85..8e68aa3bfd 100644
--- a/spec/ruby/core/env/include_spec.rb
+++ b/spec/ruby/core/env/include_spec.rb
@@ -1,6 +1,32 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/include.rb', __FILE__)
+require_relative '../../spec_helper'
describe "ENV.include?" do
- it_behaves_like(:env_include, :include?)
+ before :each do
+ @saved_foo = ENV["foo"]
+ end
+
+ after :each do
+ ENV["foo"] = @saved_foo
+ end
+
+ it "returns true if ENV has the key" do
+ ENV["foo"] = "bar"
+ ENV.include?( "foo").should == true
+ end
+
+ it "returns false if ENV doesn't include the key" do
+ ENV.delete("foo")
+ ENV.include?( "foo").should == false
+ end
+
+ it "coerces the key with #to_str" do
+ ENV["foo"] = "bar"
+ k = mock('key')
+ k.should_receive(:to_str).and_return("foo")
+ ENV.include?( k).should == true
+ end
+
+ it "raises TypeError if the argument is not a String and does not respond to #to_str" do
+ -> { ENV.include?( Object.new) }.should.raise(TypeError, "no implicit conversion of Object into String")
+ end
end
diff --git a/spec/ruby/core/env/index_spec.rb b/spec/ruby/core/env/index_spec.rb
deleted file mode 100644
index 95009b3558..0000000000
--- a/spec/ruby/core/env/index_spec.rb
+++ /dev/null
@@ -1,6 +0,0 @@
-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)
-end
diff --git a/spec/ruby/core/env/indexes_spec.rb b/spec/ruby/core/env/indexes_spec.rb
deleted file mode 100644
index 14fb93ef07..0000000000
--- a/spec/ruby/core/env/indexes_spec.rb
+++ /dev/null
@@ -1 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
diff --git a/spec/ruby/core/env/indices_spec.rb b/spec/ruby/core/env/indices_spec.rb
deleted file mode 100644
index 14fb93ef07..0000000000
--- a/spec/ruby/core/env/indices_spec.rb
+++ /dev/null
@@ -1 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
diff --git a/spec/ruby/core/env/inspect_spec.rb b/spec/ruby/core/env/inspect_spec.rb
index 9c4273e188..7dd92b120f 100644
--- a/spec/ruby/core/env/inspect_spec.rb
+++ b/spec/ruby/core/env/inspect_spec.rb
@@ -1,10 +1,10 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "ENV.inspect" do
it "returns a String that looks like a Hash with real data" do
ENV["foo"] = "bar"
- ENV.inspect.should =~ /\{.*"foo"=>"bar".*\}/
+ ENV.inspect.should =~ /\{.*"foo" *=> *"bar".*\}/
ENV.delete "foo"
end
diff --git a/spec/ruby/core/env/invert_spec.rb b/spec/ruby/core/env/invert_spec.rb
index 42170230db..c095374d95 100644
--- a/spec/ruby/core/env/invert_spec.rb
+++ b/spec/ruby/core/env/invert_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "ENV.invert" do
before :each do
diff --git a/spec/ruby/core/env/keep_if_spec.rb b/spec/ruby/core/env/keep_if_spec.rb
index c5bbc3dc05..f24981e216 100644
--- a/spec/ruby/core/env/keep_if_spec.rb
+++ b/spec/ruby/core/env/keep_if_spec.rb
@@ -1,32 +1,53 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../enumerable/shared/enumeratorized', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../enumerable/shared/enumeratorized'
describe "ENV.keep_if" do
before :each do
- ENV["foo"] = "bar"
+ @foo = ENV["foo"]
+ @bar = ENV["bar"]
+
+ ENV["foo"] = "0"
+ ENV["bar"] = "1"
end
after :each do
- ENV.delete "foo"
+ ENV["foo"] = @foo
+ ENV["bar"] = @bar
end
it "deletes pairs if the block returns false" do
- ENV.keep_if { |k, v| k != "foo" }
+ ENV.keep_if { |k, v| !["foo", "bar"].include?(k) }
ENV["foo"].should == nil
+ ENV["bar"].should == nil
+ end
+
+ it "returns ENV when block given" do
+ ENV.keep_if { |k, v| !["foo", "bar"].include?(k) }.should.equal?(ENV)
end
it "returns ENV even if nothing deleted" do
- ENV.keep_if { true }.should_not == nil
+ ENV.keep_if { true }.should.equal?(ENV)
end
it "returns an Enumerator if no block given" do
- ENV.keep_if.should be_an_instance_of(Enumerator)
+ ENV.keep_if.should.instance_of?(Enumerator)
end
it "deletes pairs through enumerator" do
enum = ENV.keep_if
- enum.each { |k, v| k != "foo" }
+ enum.each { |k, v| !["foo", "bar"].include?(k) }
ENV["foo"].should == nil
+ ENV["bar"].should == nil
+ end
+
+ it "returns ENV from enumerator" do
+ enum = ENV.keep_if
+ enum.each { |k, v| !["foo", "bar"].include?(k) }.should.equal?(ENV)
+ end
+
+ it "returns ENV from enumerator even if nothing deleted" do
+ enum = ENV.keep_if
+ enum.each { true }.should.equal?(ENV)
end
it_behaves_like :enumeratorized_with_origin_size, :keep_if, ENV
diff --git a/spec/ruby/core/env/key_spec.rb b/spec/ruby/core/env/key_spec.rb
index b653b1b1a5..56f5f609a7 100644
--- a/spec/ruby/core/env/key_spec.rb
+++ b/spec/ruby/core/env/key_spec.rb
@@ -1,11 +1,40 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/include.rb', __FILE__)
-require File.expand_path('../shared/key.rb', __FILE__)
+require_relative '../../spec_helper'
describe "ENV.key?" do
- it_behaves_like(:env_include, :key?)
+ it "is an alias of ENV.include?" do
+ ENV.method(:key?).should == ENV.method(:include?)
+ end
end
describe "ENV.key" do
- it_behaves_like(:env_key, :key)
+ before :each do
+ @saved_foo = ENV["foo"]
+ end
+
+ after :each do
+ ENV["foo"] = @saved_foo
+ end
+
+ it "returns the index associated with the passed value" do
+ ENV["foo"] = "bar"
+ ENV.key("bar").should == "foo"
+ end
+
+ it "returns nil if the passed value is not found" do
+ ENV.delete("foo")
+ ENV.key("foo").should == nil
+ end
+
+ it "coerces the key element with #to_str" do
+ ENV["foo"] = "bar"
+ k = mock('key')
+ k.should_receive(:to_str).and_return("bar")
+ ENV.key(k).should == "foo"
+ end
+
+ it "raises TypeError if the argument is not a String and does not respond to #to_str" do
+ -> {
+ ENV.key(Object.new)
+ }.should.raise(TypeError, "no implicit conversion of Object into String")
+ end
end
diff --git a/spec/ruby/core/env/keys_spec.rb b/spec/ruby/core/env/keys_spec.rb
index d79919b79d..b074a8f7c7 100644
--- a/spec/ruby/core/env/keys_spec.rb
+++ b/spec/ruby/core/env/keys_spec.rb
@@ -1,9 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "ENV.keys" do
- it "returns all the keys" do
- ENV.keys.sort.should == ENV.to_hash.keys.sort
+ it "returns an array of the keys" do
+ ENV.keys.should == ENV.to_hash.keys
end
it "returns the keys in the locale encoding" do
diff --git a/spec/ruby/core/env/length_spec.rb b/spec/ruby/core/env/length_spec.rb
index 83d1b58c74..6baac6f7a4 100644
--- a/spec/ruby/core/env/length_spec.rb
+++ b/spec/ruby/core/env/length_spec.rb
@@ -1,6 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/length.rb', __FILE__)
+require_relative '../../spec_helper'
describe "ENV.length" do
- it_behaves_like(:env_length, :length)
+ it "is an alias of ENV.size" do
+ ENV.method(:length).should == ENV.method(:size)
+ end
end
diff --git a/spec/ruby/core/env/member_spec.rb b/spec/ruby/core/env/member_spec.rb
index 25aa71e973..f062d41190 100644
--- a/spec/ruby/core/env/member_spec.rb
+++ b/spec/ruby/core/env/member_spec.rb
@@ -1,6 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/include.rb', __FILE__)
+require_relative '../../spec_helper'
describe "ENV.member?" do
- it_behaves_like(:env_include, :member?)
+ it "is an alias of ENV.include?" do
+ ENV.method(:member?).should == ENV.method(:include?)
+ end
end
diff --git a/spec/ruby/core/env/merge_spec.rb b/spec/ruby/core/env/merge_spec.rb
new file mode 100644
index 0000000000..78231afbb2
--- /dev/null
+++ b/spec/ruby/core/env/merge_spec.rb
@@ -0,0 +1,106 @@
+require_relative '../../spec_helper'
+
+describe "ENV.merge!" do
+ before :each do
+ @saved_foo = ENV["foo"]
+ @saved_bar = ENV["bar"]
+ end
+
+ after :each do
+ ENV["foo"] = @saved_foo
+ ENV["bar"] = @saved_bar
+ end
+
+ it "adds the parameter hash to ENV, returning ENV" do
+ ENV.merge!("foo" => "0", "bar" => "1").should.equal?(ENV)
+ ENV["foo"].should == "0"
+ ENV["bar"].should == "1"
+ end
+
+ it "adds the multiple parameter hashes to ENV, returning ENV" do
+ ENV.merge!({"foo" => "multi1"}, {"bar" => "multi2"}).should.equal?(ENV)
+ ENV["foo"].should == "multi1"
+ ENV["bar"].should == "multi2"
+ end
+
+ it "returns ENV when no block given" do
+ ENV.merge!({"foo" => "0", "bar" => "1"}).should.equal?(ENV)
+ end
+
+ it "yields key, the old value and the new value when replacing an entry" do
+ ENV.merge!({"foo" => "0", "bar" => "3"})
+ a = []
+ ENV.merge!({"foo" => "1", "bar" => "4"}) do |key, old, new|
+ a << [key, old, new]
+ new
+ end
+ a[0].should == ["foo", "0", "1"]
+ a[1].should == ["bar", "3", "4"]
+ end
+
+ it "yields key, the old value and the new value when replacing an entry" do
+ ENV.merge!({"foo" => "0", "bar" => "3"})
+ ENV.merge!({"foo" => "1", "bar" => "4"}) do |key, old, new|
+ (new.to_i + 1).to_s
+ end
+ ENV["foo"].should == "2"
+ ENV["bar"].should == "5"
+ end
+
+ # BUG: https://bugs.ruby-lang.org/issues/16192
+ it "does not evaluate the block when the name is new" do
+ ENV.delete("bar")
+ ENV.merge!({"foo" => "0"})
+ ENV.merge!("bar" => "1") { |key, old, new| fail "Should not get here" }
+ ENV["bar"].should == "1"
+ end
+
+ # BUG: https://bugs.ruby-lang.org/issues/16192
+ it "does not use the block's return value as the value when the name is new" do
+ ENV.delete("bar")
+ ENV.merge!({"foo" => "0"})
+ ENV.merge!("bar" => "1") { |key, old, new| "Should not use this value" }
+ ENV["foo"].should == "0"
+ ENV["bar"].should == "1"
+ end
+
+ it "returns ENV when block given" do
+ ENV.merge!({"foo" => "0", "bar" => "1"}){}.should.equal?(ENV)
+ end
+
+ it "raises TypeError when a name is not coercible to String" do
+ -> { ENV.merge!(Object.new => "0") }.should.raise(TypeError, "no implicit conversion of Object into String")
+ end
+
+ it "raises TypeError when a value is not coercible to String" do
+ -> { ENV.merge!("foo" => Object.new) }.should.raise(TypeError, "no implicit conversion of Object into String")
+ end
+
+ it "raises Errno::EINVAL when a name contains the '=' character" do
+ -> { ENV.merge!("foo=" => "bar") }.should.raise(Errno::EINVAL)
+ end
+
+ it "raises Errno::EINVAL when a name is an empty string" do
+ -> { ENV.merge!("" => "bar") }.should.raise(Errno::EINVAL)
+ end
+
+ it "updates good data preceding an error" do
+ ENV["foo"] = "0"
+ begin
+ ENV.merge!({"foo" => "2", Object.new => "1"})
+ rescue TypeError
+ ensure
+ ENV["foo"].should == "2"
+ end
+ end
+
+ it "does not update good data following an error" do
+ ENV["foo"] = "0"
+ begin
+ ENV.merge!({Object.new => "1", "foo" => "2"})
+ rescue TypeError
+ ensure
+ ENV["foo"].should == "0"
+ end
+ end
+end
diff --git a/spec/ruby/core/env/rassoc_spec.rb b/spec/ruby/core/env/rassoc_spec.rb
index 3a86e7e158..e4ac5ce5e2 100644
--- a/spec/ruby/core/env/rassoc_spec.rb
+++ b/spec/ruby/core/env/rassoc_spec.rb
@@ -1,8 +1,14 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "ENV.rassoc" do
+ before :each do
+ @foo = ENV["foo"]
+ @baz = ENV["baz"]
+ end
+
after :each do
- ENV.delete("foo")
+ ENV["foo"] = @foo
+ ENV["baz"] = @baz
end
it "returns an array of the key and value of the environment variable with the given value" do
@@ -10,6 +16,15 @@ describe "ENV.rassoc" do
ENV.rassoc("bar").should == ["foo", "bar"]
end
+ it "returns a single array even if there are multiple such environment variables" do
+ ENV["foo"] = "bar"
+ ENV["baz"] = "bar"
+ [
+ ["foo", "bar"],
+ ["baz", "bar"],
+ ].should.include?(ENV.rassoc("bar"))
+ end
+
it "returns nil if no environment variable with the given value exists" do
ENV.rassoc("bar").should == nil
end
@@ -20,4 +35,8 @@ describe "ENV.rassoc" do
v.should_receive(:to_str).and_return("bar")
ENV.rassoc(v).should == ["foo", "bar"]
end
+
+ it "returns nil if the argument is not a String and does not respond to #to_str" do
+ ENV.rassoc(Object.new).should == nil
+ end
end
diff --git a/spec/ruby/core/env/rehash_spec.rb b/spec/ruby/core/env/rehash_spec.rb
index 14fb93ef07..3782e4b727 100644
--- a/spec/ruby/core/env/rehash_spec.rb
+++ b/spec/ruby/core/env/rehash_spec.rb
@@ -1 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
+
+describe "ENV.rehash" do
+ it "returns nil" do
+ ENV.rehash.should == nil
+ end
+end
diff --git a/spec/ruby/core/env/reject_spec.rb b/spec/ruby/core/env/reject_spec.rb
index 0da84425b6..4df864493d 100644
--- a/spec/ruby/core/env/reject_spec.rb
+++ b/spec/ruby/core/env/reject_spec.rb
@@ -1,7 +1,15 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../enumerable/shared/enumeratorized', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../enumerable/shared/enumeratorized'
describe "ENV.reject!" do
+ before :each do
+ @foo = ENV["foo"]
+ end
+
+ after :each do
+ ENV["foo"] = @foo
+ end
+
it "rejects entries based on key" do
ENV["foo"] = "bar"
ENV.reject! { |k, v| k == "foo" }
@@ -17,19 +25,23 @@ describe "ENV.reject!" do
it "returns itself or nil" do
ENV.reject! { false }.should == nil
ENV["foo"] = "bar"
- ENV.reject! { |k, v| k == "foo" }.should == ENV
+ ENV.reject! { |k, v| k == "foo" }.should.equal?(ENV)
ENV["foo"].should == nil
end
it "returns an Enumerator if called without a block" do
- ENV.reject!.should be_an_instance_of(Enumerator)
+ ENV["foo"] = "bar"
+ enum = ENV.reject!
+ enum.should.instance_of?(Enumerator)
+ enum.each { |k, v| k == "foo" }.should.equal?(ENV)
+ ENV["foo"].should == nil
end
it "doesn't raise if empty" do
orig = ENV.to_hash
begin
ENV.clear
- lambda { ENV.reject! }.should_not raise_error(LocalJumpError)
+ -> { ENV.reject! }.should_not.raise(LocalJumpError)
ensure
ENV.replace orig
end
@@ -39,6 +51,14 @@ describe "ENV.reject!" do
end
describe "ENV.reject" do
+ before :each do
+ @foo = ENV["foo"]
+ end
+
+ after :each do
+ ENV["foo"] = @foo
+ end
+
it "rejects entries based on key" do
ENV["foo"] = "bar"
e = ENV.reject { |k, v| k == "foo" }
@@ -56,18 +76,22 @@ describe "ENV.reject" do
end
it "returns a Hash" do
- ENV.reject { false }.should be_kind_of(Hash)
+ ENV.reject { false }.should.is_a?(Hash)
end
it "returns an Enumerator if called without a block" do
- ENV.reject.should be_an_instance_of(Enumerator)
+ ENV["foo"] = "bar"
+ enum = ENV.reject
+ enum.should.instance_of?(Enumerator)
+ enum.each { |k, v| k == "foo"}
+ ENV["foo"] = nil
end
it "doesn't raise if empty" do
orig = ENV.to_hash
begin
ENV.clear
- lambda { ENV.reject }.should_not raise_error(LocalJumpError)
+ -> { ENV.reject }.should_not.raise(LocalJumpError)
ensure
ENV.replace orig
end
diff --git a/spec/ruby/core/env/replace_spec.rb b/spec/ruby/core/env/replace_spec.rb
index 0c11e173ac..27eb3e45dd 100644
--- a/spec/ruby/core/env/replace_spec.rb
+++ b/spec/ruby/core/env/replace_spec.rb
@@ -1,15 +1,51 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "ENV.replace" do
+ before :each do
+ @orig = ENV.to_hash
+ ENV.delete("foo")
+ end
+
+ after :each do
+ ENV.replace(@orig)
+ end
it "replaces ENV with a Hash" do
- ENV["foo"] = "bar"
- e = ENV.reject { |k, v| k == "foo" }
- e["baz"] = "bam"
- ENV.replace e
- ENV["foo"].should == nil
- ENV["baz"].should == "bam"
- ENV.delete "baz"
+ ENV.replace("foo" => "0", "bar" => "1").should.equal?(ENV)
+ ENV.size.should == 2
+ ENV["foo"].should == "0"
+ ENV["bar"].should == "1"
+ end
+
+ it "raises TypeError if the argument is not a Hash" do
+ -> { ENV.replace(Object.new) }.should.raise(TypeError, "no implicit conversion of Object into Hash")
+ ENV.to_hash.should == @orig
+ end
+
+ it "raises TypeError if a key is not a String" do
+ -> { ENV.replace(Object.new => "0") }.should.raise(TypeError, "no implicit conversion of Object into String")
+ ENV.to_hash.should == @orig
+ end
+
+ it "raises TypeError if a value is not a String" do
+ -> { ENV.replace("foo" => Object.new) }.should.raise(TypeError, "no implicit conversion of Object into String")
+ ENV.to_hash.should == @orig
+ end
+
+ it "raises Errno::EINVAL when the key contains the '=' character" do
+ -> { ENV.replace("foo=" =>"bar") }.should.raise(Errno::EINVAL)
+ end
+
+ it "raises Errno::EINVAL when the key is an empty string" do
+ -> { ENV.replace("" => "bar") }.should.raise(Errno::EINVAL)
+ end
+
+ it "does not accept good data preceding an error" do
+ -> { ENV.replace("foo" => "1", Object.new => Object.new) }.should.raise(TypeError, "no implicit conversion of Object into String")
end
+ it "does not accept good data following an error" do
+ -> { ENV.replace(Object.new => Object.new, "foo" => "0") }.should.raise(TypeError, "no implicit conversion of Object into String")
+ ENV.to_hash.should == @orig
+ end
end
diff --git a/spec/ruby/core/env/select_spec.rb b/spec/ruby/core/env/select_spec.rb
index 8261ff593a..2b92d61551 100644
--- a/spec/ruby/core/env/select_spec.rb
+++ b/spec/ruby/core/env/select_spec.rb
@@ -1,8 +1,18 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../enumerable/shared/enumeratorized', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../enumerable/shared/enumeratorized'
describe "ENV.select!" do
- it "removes environment variables for which the block returns true" do
+ it_behaves_like :enumeratorized_with_origin_size, :select!, ENV
+
+ before :each do
+ @saved_foo = ENV["foo"]
+ end
+
+ after :each do
+ ENV["foo"] = @saved_foo
+ end
+
+ it "removes environment variables for which the block returns false" do
ENV["foo"] = "bar"
ENV.select! { |k, v| k != "foo" }
ENV["foo"].should == nil
@@ -10,30 +20,49 @@ describe "ENV.select!" do
it "returns self if any changes were made" do
ENV["foo"] = "bar"
- ENV.select! { |k, v| k != "foo" }.should == ENV
+ (ENV.select! { |k, v| k != "foo" }).should == ENV
end
it "returns nil if no changes were made" do
- ENV.select! { true }.should == nil
+ (ENV.select! { true }).should == nil
end
it "returns an Enumerator if called without a block" do
- ENV.select!.should be_an_instance_of(Enumerator)
+ ENV.select!.should.instance_of?(Enumerator)
end
- it_behaves_like :enumeratorized_with_origin_size, :select!, ENV
+ it "selects via the enumerator" do
+ enum = ENV.select!
+ ENV["foo"] = "bar"
+ enum.each { |k, v| k != "foo" }
+ ENV["foo"].should == nil
+ end
end
describe "ENV.select" do
- it "returns a Hash of names and values for which block return true" do
+ it_behaves_like :enumeratorized_with_origin_size, :select, ENV
+
+ before :each do
+ @saved_foo = ENV["foo"]
+ end
+
+ after :each do
+ ENV["foo"] = @saved_foo
+ end
+
+ it "returns a Hash of names and values for which block returns true" do
ENV["foo"] = "bar"
- ENV.select { |k, v| k == "foo" }.should == {"foo" => "bar"}
- ENV.delete "foo"
+ (ENV.select { |k, v| k == "foo" }).should == { "foo" => "bar" }
end
it "returns an Enumerator when no block is given" do
- ENV.select.should be_an_instance_of(Enumerator)
+ enum = ENV.select
+ enum.should.instance_of?(Enumerator)
end
- it_behaves_like :enumeratorized_with_origin_size, :select, ENV
+ it "selects via the enumerator" do
+ enum = ENV.select
+ ENV["foo"] = "bar"
+ enum.each { |k, v| k == "foo" }.should == { "foo" => "bar"}
+ end
end
diff --git a/spec/ruby/core/env/shared/each.rb b/spec/ruby/core/env/shared/each.rb
deleted file mode 100644
index 494fd5cee1..0000000000
--- a/spec/ruby/core/env/shared/each.rb
+++ /dev/null
@@ -1,65 +0,0 @@
-require File.expand_path('../../../enumerable/shared/enumeratorized', __FILE__)
-
-describe :env_each, shared: true do
- it "returns each pair" do
- orig = ENV.to_hash
- e = []
- begin
- ENV.clear
- ENV["foo"] = "bar"
- ENV["baz"] = "boo"
- ENV.send(@method) { |k, v| e << [k, v] }
- e.should include(["foo", "bar"])
- e.should include(["baz", "boo"])
- ensure
- ENV.replace orig
- end
- end
-
- it "returns an Enumerator if called without a block" do
- ENV.send(@method).should be_an_instance_of(Enumerator)
- end
-
- before :all do
- @object = ENV
- end
- it_should_behave_like :enumeratorized_with_origin_size
-
- with_feature :encoding do
- describe "with encoding" do
- before :each do
- @external = Encoding.default_external
- @internal = Encoding.default_internal
-
- Encoding.default_external = Encoding::ASCII_8BIT
-
- @locale_encoding = Encoding.find "locale"
- end
-
- after :each do
- Encoding.default_external = @external
- Encoding.default_internal = @internal
- end
-
- it "uses the locale encoding when Encoding.default_internal is nil" do
- Encoding.default_internal = nil
-
- ENV.send(@method) do |key, value|
- key.encoding.should equal(@locale_encoding)
- value.encoding.should equal(@locale_encoding)
- end
- end
-
- it "transcodes from the locale encoding to Encoding.default_internal if set" do
- Encoding.default_internal = internal = Encoding::IBM437
-
- ENV.send(@method) do |key, value|
- key.encoding.should equal(internal)
- if value.ascii_only?
- value.encoding.should equal(internal)
- end
- end
- end
- end
- end
-end
diff --git a/spec/ruby/core/env/shared/include.rb b/spec/ruby/core/env/shared/include.rb
deleted file mode 100644
index 8d8311dcf2..0000000000
--- a/spec/ruby/core/env/shared/include.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-describe :env_include, shared: true do
- it "returns true if ENV has the key" do
- ENV["foo"] = "bar"
- ENV.send(@method, "foo").should == true
- ENV.delete "foo"
- end
-
- it "returns false if ENV doesn't include the key" do
- ENV.send(@method, "should_never_be_set").should == false
- end
-end
diff --git a/spec/ruby/core/env/shared/key.rb b/spec/ruby/core/env/shared/key.rb
deleted file mode 100644
index 5e6c21840f..0000000000
--- a/spec/ruby/core/env/shared/key.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-describe :env_key, shared: true do
- it "needs to be reviewed for completeness"
-
- it "returns the index associated with the passed value" do
- ENV["foo"] = "bar"
- ENV.send(@method, "bar").should == "foo"
- ENV.delete "foo"
- end
-
- it "returns nil if the passed value is not found" do
- ENV.send(@method, "should_never_be_set").should be_nil
- end
-end
-
-
diff --git a/spec/ruby/core/env/shared/length.rb b/spec/ruby/core/env/shared/length.rb
deleted file mode 100644
index 6d788a3f4a..0000000000
--- a/spec/ruby/core/env/shared/length.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-describe :env_length, shared: true do
- it "returns the number of ENV entries" do
- orig = ENV.to_hash
- begin
- ENV.clear
- ENV["foo"] = "bar"
- ENV["baz"] = "boo"
- ENV.send(@method).should == 2
- ensure
- ENV.replace orig
- end
- end
-end
diff --git a/spec/ruby/core/env/shared/store.rb b/spec/ruby/core/env/shared/store.rb
deleted file mode 100644
index 4949ca8c73..0000000000
--- a/spec/ruby/core/env/shared/store.rb
+++ /dev/null
@@ -1,56 +0,0 @@
-describe :env_store, shared: true do
- after :each do
- ENV.delete("foo")
- end
-
- it "sets the environment variable to the given value" do
- ENV.send(@method, "foo", "bar")
- ENV["foo"].should == "bar"
- end
-
- it "returns the value" do
- value = "bar"
- ENV.send(@method, "foo", value).should equal(value)
- end
-
- it "deletes the environment variable when the value is nil" do
- ENV["foo"] = "bar"
- ENV.send(@method, "foo", nil)
- ENV.key?("foo").should be_false
- end
-
- it "coerces the key argument with #to_str" do
- k = mock("key")
- k.should_receive(:to_str).and_return("foo")
- ENV.send(@method, k, "bar")
- ENV["foo"].should == "bar"
- end
-
- it "coerces the value argument with #to_str" do
- v = mock("value")
- v.should_receive(:to_str).and_return("bar")
- ENV.send(@method, "foo", v)
- ENV["foo"].should == "bar"
- end
-
- it "raises TypeError when the key is not coercible to String" do
- lambda { ENV.send(@method, Object.new, "bar") }.should raise_error(TypeError)
- end
-
- it "raises TypeError when the value is not coercible to String" do
- lambda { ENV.send(@method, "foo", Object.new) }.should raise_error(TypeError)
- end
-
- it "raises Errno::EINVAL when the key contains the '=' character" do
- lambda { ENV.send(@method, "foo=", "bar") }.should raise_error(Errno::EINVAL)
- end
-
- it "raises Errno::EINVAL when the key is an empty string" do
- lambda { ENV.send(@method, "", "bar") }.should raise_error(Errno::EINVAL)
- end
-
- it "does nothing when the key is not a valid environment variable key and the value is nil" do
- ENV.send(@method, "foo=", nil)
- ENV.key?("foo=").should be_false
- end
-end
diff --git a/spec/ruby/core/env/shared/to_hash.rb b/spec/ruby/core/env/shared/to_hash.rb
index 3bfbc415f7..7868690c38 100644
--- a/spec/ruby/core/env/shared/to_hash.rb
+++ b/spec/ruby/core/env/shared/to_hash.rb
@@ -1,22 +1,33 @@
describe :env_to_hash, shared: true do
+ before :each do
+ @saved_foo = ENV["foo"]
+ end
+
+ after :each do
+ ENV["foo"]= @saved_foo
+ end
+
it "returns the ENV as a hash" do
ENV["foo"] = "bar"
h = ENV.send(@method)
- h.should be_an_instance_of(Hash)
+ h.should.instance_of?(Hash)
h["foo"].should == "bar"
- ENV.delete "foo"
end
it "uses the locale encoding for keys" do
- ENV.send(@method).keys.all? {|k| k.encoding == Encoding.find('locale') }.should be_true
+ ENV.send(@method).keys.each {|k| k.should.be_locale_env }
end
it "uses the locale encoding for values" do
- ENV.send(@method).values.all? {|v| v.encoding == Encoding.find('locale') }.should be_true
+ ENV.send(@method).values.each {|k| k.should.be_locale_env }
end
it "duplicates the ENV when converting to a Hash" do
h = ENV.send(@method)
- h.object_id.should_not == ENV.object_id
+ h.should_not.equal? ENV
+ h.size.should == ENV.size
+ h.each_pair do |k, v|
+ ENV[k].should == v
+ end
end
end
diff --git a/spec/ruby/core/env/shared/value.rb b/spec/ruby/core/env/shared/value.rb
deleted file mode 100644
index d9ee90f12d..0000000000
--- a/spec/ruby/core/env/shared/value.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-describe :env_value, shared: true do
- it "returns true if ENV has the value" do
- ENV["foo"] = "bar"
- ENV.send(@method, "bar").should == true
- ENV["foo"] = nil
- end
-
- it "returns false if ENV doesn't have the value" do
- ENV.send(@method, "this_value_should_never_exist").should == false
- end
-end
diff --git a/spec/ruby/core/env/shift_spec.rb b/spec/ruby/core/env/shift_spec.rb
index bae6a17ba0..52bd0f9139 100644
--- a/spec/ruby/core/env/shift_spec.rb
+++ b/spec/ruby/core/env/shift_spec.rb
@@ -1,59 +1,47 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/common'
describe "ENV.shift" do
+ before :each do
+ @orig = ENV.to_hash
+ @external = Encoding.default_external
+ @internal = Encoding.default_internal
+
+ Encoding.default_external = Encoding::BINARY
+ ENV.replace({"FOO"=>"BAR"})
+ end
+
+ after :each do
+ Encoding.default_external = @external
+ Encoding.default_internal = @internal
+ ENV.replace @orig
+ end
+
it "returns a pair and deletes it" do
- ENV.empty?.should == false
- orig = ENV.to_hash
- begin
- pair = ENV.shift
- ENV.has_key?(pair.first).should == false
- ensure
- ENV.replace orig
- end
- ENV.has_key?(pair.first).should == true
+ ENV.should.has_key?("FOO")
+ pair = ENV.shift
+ pair.should == ["FOO", "BAR"]
+ ENV.should_not.has_key?("FOO")
end
it "returns nil if ENV.empty?" do
- orig = ENV.to_hash
- begin
- ENV.clear
- ENV.shift.should == nil
- ensure
- ENV.replace orig
- end
+ ENV.clear
+ ENV.shift.should == nil
end
-end
-with_feature :encoding do
- describe "ENV.shift" do
- before :each do
- @orig = ENV.to_hash
- @external = Encoding.default_external
- @internal = Encoding.default_internal
-
- Encoding.default_external = Encoding::ASCII_8BIT
- end
-
- after :each do
- Encoding.default_external = @external
- Encoding.default_internal = @internal
- ENV.replace @orig
- end
-
- it "uses the locale encoding if Encoding.default_internal is nil" do
- Encoding.default_internal = nil
-
- pair = ENV.shift
- pair.first.encoding.should equal(Encoding.find("locale"))
- pair.last.encoding.should equal(Encoding.find("locale"))
- end
-
- it "transcodes from the locale encoding to Encoding.default_internal if set" do
- Encoding.default_internal = Encoding::IBM437
-
- pair = ENV.shift
- pair.first.encoding.should equal(Encoding::IBM437)
- pair.last.encoding.should equal(Encoding::IBM437)
- end
+ it "uses the locale encoding if Encoding.default_internal is nil" do
+ Encoding.default_internal = nil
+
+ pair = ENV.shift
+ pair.first.encoding.should.equal?(ENVSpecs.encoding)
+ pair.last.encoding.should.equal?(ENVSpecs.encoding)
+ end
+
+ it "transcodes from the locale encoding to Encoding.default_internal if set" do
+ Encoding.default_internal = Encoding::IBM437
+
+ pair = ENV.shift
+ pair.first.encoding.should.equal?(Encoding::IBM437)
+ pair.last.encoding.should.equal?(Encoding::IBM437)
end
end
diff --git a/spec/ruby/core/env/size_spec.rb b/spec/ruby/core/env/size_spec.rb
index 882ceac485..9c6de20df6 100644
--- a/spec/ruby/core/env/size_spec.rb
+++ b/spec/ruby/core/env/size_spec.rb
@@ -1,6 +1,15 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/length.rb', __FILE__)
+require_relative '../../spec_helper'
describe "ENV.size" do
- it_behaves_like(:env_length, :size)
+ it "returns the number of ENV entries" do
+ orig = ENV.to_hash
+ begin
+ ENV.clear
+ ENV["foo"] = "bar"
+ ENV["baz"] = "boo"
+ ENV.size.should == 2
+ ensure
+ ENV.replace orig
+ end
+ end
end
diff --git a/spec/ruby/core/env/slice_spec.rb b/spec/ruby/core/env/slice_spec.rb
new file mode 100644
index 0000000000..4c0416547d
--- /dev/null
+++ b/spec/ruby/core/env/slice_spec.rb
@@ -0,0 +1,37 @@
+require_relative '../../spec_helper'
+
+describe "ENV.slice" do
+ before :each do
+ @saved_foo = ENV["foo"]
+ @saved_bar = ENV["bar"]
+ ENV["foo"] = "0"
+ ENV["bar"] = "1"
+ end
+
+ after :each do
+ ENV["foo"] = @saved_foo
+ ENV["bar"] = @saved_bar
+ end
+
+ it "returns a hash of the given environment variable names and their values" do
+ ENV.slice("foo", "bar").should == {"foo" => "0", "bar" => "1"}
+ end
+
+ it "ignores each String that is not an environment variable name" do
+ ENV.slice("foo", "boo", "bar").should == {"foo" => "0", "bar" => "1"}
+ end
+
+ it "returns the values for the keys coerced with #to_str, but keeps the original objects as result keys" do
+ foo = mock('key 1')
+ foo.should_receive(:to_str).and_return("foo")
+ boo = mock('key 2')
+ boo.should_receive(:to_str).and_return("boo")
+ bar = mock('key 3')
+ bar.should_receive(:to_str).and_return("bar")
+ ENV.slice(foo, boo, bar).should == {foo => "0", bar => "1"}
+ end
+
+ it "raises TypeError if any argument is not a String and does not respond to #to_str" do
+ -> { ENV.slice(Object.new) }.should.raise(TypeError, "no implicit conversion of Object into String")
+ end
+end
diff --git a/spec/ruby/core/env/spec_helper.rb b/spec/ruby/core/env/spec_helper.rb
new file mode 100644
index 0000000000..470ffa58bc
--- /dev/null
+++ b/spec/ruby/core/env/spec_helper.rb
@@ -0,0 +1,26 @@
+require_relative '../../spec_helper'
+
+locale_env_matcher = Class.new do
+ def initialize(name = 'locale')
+ encoding = Encoding.find(name)
+ @encodings = (encoding = Encoding::US_ASCII) ?
+ [encoding, Encoding::ASCII_8BIT] : [encoding]
+ end
+
+ def matches?(actual)
+ @actual = actual = actual.encoding
+ @encodings.include?(actual)
+ end
+
+ def failure_message
+ ["Expected #{@actual} to be #{@encodings.join(' or ')}"]
+ end
+
+ def negative_failure_message
+ ["Expected #{@actual} not to be #{@encodings.join(' or ')}"]
+ end
+end
+
+String.__send__(:define_method, :be_locale_env) do |expected = 'locale'|
+ locale_env_matcher.new(expected)
+end
diff --git a/spec/ruby/core/env/store_spec.rb b/spec/ruby/core/env/store_spec.rb
index 1ee5ce020e..a5fd7e1e26 100644
--- a/spec/ruby/core/env/store_spec.rb
+++ b/spec/ruby/core/env/store_spec.rb
@@ -1,6 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/store.rb', __FILE__)
+require_relative '../../spec_helper'
describe "ENV.store" do
- it_behaves_like(:env_store, :store)
+ it "is an alias of ENV.[]=" do
+ ENV.method(:store).should == ENV.method(:[]=)
+ end
end
diff --git a/spec/ruby/core/env/to_a_spec.rb b/spec/ruby/core/env/to_a_spec.rb
index ffb66b8767..2b1649281f 100644
--- a/spec/ruby/core/env/to_a_spec.rb
+++ b/spec/ruby/core/env/to_a_spec.rb
@@ -1,19 +1,21 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative 'spec_helper'
describe "ENV.to_a" do
it "returns the ENV as an array" do
- ENV["foo"] = "bar"
a = ENV.to_a
a.is_a?(Array).should == true
- a.find { |e| e.first == "foo" }.should == ["foo", "bar"]
- ENV.delete "foo"
+ a.size.should == ENV.size
+ a.each { |k,v| ENV[k].should == v }
+
+ a.first.should.is_a?(Array)
+ a.first.size.should == 2
end
it "returns the entries in the locale encoding" do
ENV.to_a.each do |key, value|
- key.encoding.should == Encoding.find('locale')
- value.encoding.should == Encoding.find('locale')
+ key.should.be_locale_env
+ value.should.be_locale_env
end
end
end
diff --git a/spec/ruby/core/env/to_h_spec.rb b/spec/ruby/core/env/to_h_spec.rb
index d0fef5382b..7e0fef2120 100644
--- a/spec/ruby/core/env/to_h_spec.rb
+++ b/spec/ruby/core/env/to_h_spec.rb
@@ -1,6 +1,70 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/to_hash.rb', __FILE__)
+require_relative 'spec_helper'
+require_relative 'shared/to_hash'
-describe "ENV.to_hash" do
- it_behaves_like(:env_to_hash, :to_h)
+describe "ENV.to_h" do
+ it_behaves_like :env_to_hash, :to_h
+
+ context "with block" do
+ before do
+ @orig_hash = ENV.to_hash
+ end
+
+ after do
+ ENV.replace @orig_hash
+ end
+
+ it "converts [key, value] pairs returned by the block to a hash" do
+ ENV.replace("a" => "b", "c" => "d")
+ ENV.to_h { |k, v| [k, v.upcase] }.should == { 'a' => "B", 'c' => "D" }
+ end
+
+ it "passes to a block each pair's key and value as separate arguments" do
+ ENV.replace("a" => "b", "c" => "d")
+
+ ScratchPad.record []
+ ENV.to_h { |k, v| ScratchPad << [k, v]; [k, v] }
+ ScratchPad.recorded.sort.should == [["a", "b"], ["c", "d"]]
+
+ ScratchPad.record []
+ ENV.to_h { |*args| ScratchPad << args; [args[0], args[1]] }
+ ScratchPad.recorded.sort.should == [["a", "b"], ["c", "d"]]
+ end
+
+ it "does not require the array elements to be strings" do
+ ENV.replace("a" => "b", "c" => "d")
+ ENV.to_h { |k, v| [k.to_sym, v.to_sym] }.should == { :a => :b, :c => :d }
+ end
+
+ it "raises ArgumentError if block returns longer or shorter array" do
+ -> do
+ ENV.to_h { |k, v| [k, v.upcase, 1] }
+ end.should.raise(ArgumentError, /element has wrong array length/)
+
+ -> do
+ ENV.to_h { |k, v| [k] }
+ end.should.raise(ArgumentError, /element has wrong array length/)
+ end
+
+ it "raises TypeError if block returns something other than Array" do
+ -> do
+ ENV.to_h { |k, v| "not-array" }
+ end.should.raise(TypeError, /wrong element type String/)
+ end
+
+ it "coerces returned pair to Array with #to_ary" do
+ x = mock('x')
+ x.stub!(:to_ary).and_return([:b, 'b'])
+
+ ENV.to_h { |k| x }.should == { :b => 'b' }
+ end
+
+ it "does not coerce returned pair to Array with #to_a" do
+ x = mock('x')
+ x.stub!(:to_a).and_return([:b, 'b'])
+
+ -> do
+ ENV.to_h { |k| x }
+ end.should.raise(TypeError, /wrong element type MockObject/)
+ end
+ end
end
diff --git a/spec/ruby/core/env/to_hash_spec.rb b/spec/ruby/core/env/to_hash_spec.rb
index 3362fa9307..306572c353 100644
--- a/spec/ruby/core/env/to_hash_spec.rb
+++ b/spec/ruby/core/env/to_hash_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/to_hash.rb', __FILE__)
+require_relative 'spec_helper'
+require_relative 'shared/to_hash'
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/to_s_spec.rb b/spec/ruby/core/env/to_s_spec.rb
index 10aca09723..0bd92cf217 100644
--- a/spec/ruby/core/env/to_s_spec.rb
+++ b/spec/ruby/core/env/to_s_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "ENV.to_s" do
it "returns \"ENV\"" do
diff --git a/spec/ruby/core/env/update_spec.rb b/spec/ruby/core/env/update_spec.rb
index 7ebfbb313d..44d05d617f 100644
--- a/spec/ruby/core/env/update_spec.rb
+++ b/spec/ruby/core/env/update_spec.rb
@@ -1,25 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "ENV.update" do
-
- it "adds the parameter hash to ENV" do
- ENV["foo"].should == nil
- ENV.update "foo" => "bar"
- ENV["foo"].should == "bar"
- ENV.delete "foo"
- end
-
- it "yields key, the old value and the new value when replacing entries" do
- ENV.update "foo" => "bar"
- ENV["foo"].should == "bar"
- ENV.update("foo" => "boo") do |key, old, new|
- key.should == "foo"
- old.should == "bar"
- new.should == "boo"
- "rab"
- end
- ENV["foo"].should == "rab"
- ENV.delete "foo"
+ it "is an alias of ENV.merge!" do
+ ENV.method(:update).should == ENV.method(:merge!)
end
-
end
diff --git a/spec/ruby/core/env/value_spec.rb b/spec/ruby/core/env/value_spec.rb
index c7eb7c5376..c732cfbd15 100644
--- a/spec/ruby/core/env/value_spec.rb
+++ b/spec/ruby/core/env/value_spec.rb
@@ -1,6 +1,31 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/value.rb', __FILE__)
+require_relative '../../spec_helper'
describe "ENV.value?" do
- it_behaves_like(:env_value, :value?)
+ before :each do
+ @saved_foo = ENV["foo"]
+ end
+
+ after :each do
+ ENV["foo"] = @saved_foo
+ end
+
+ it "returns true if ENV has the value" do
+ ENV["foo"] = "bar"
+ ENV.value?("bar").should == true
+ end
+
+ it "returns false if ENV doesn't have the value" do
+ ENV.value?("foo").should == false
+ end
+
+ it "coerces the value element with #to_str" do
+ ENV["foo"] = "bar"
+ v = mock('value')
+ v.should_receive(:to_str).and_return("bar")
+ ENV.value?(v).should == true
+ end
+
+ it "returns nil if the argument is not a String and does not respond to #to_str" do
+ ENV.value?(Object.new).should == nil
+ end
end
diff --git a/spec/ruby/core/env/values_at_spec.rb b/spec/ruby/core/env/values_at_spec.rb
index efc7de2a05..4a733f4ed5 100644
--- a/spec/ruby/core/env/values_at_spec.rb
+++ b/spec/ruby/core/env/values_at_spec.rb
@@ -1,17 +1,38 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/common'
describe "ENV.values_at" do
+ before :each do
+ @saved_foo = ENV["foo"]
+ @saved_bar = ENV["bar"]
+ end
+
+ after :each do
+ ENV["foo"] = @saved_foo
+ ENV["bar"] = @saved_bar
+ end
- it "returns an array of the values referenced by the parameters as keys" do
+ it "returns an array of the values corresponding to the given keys" do
ENV["foo"] = "oof"
ENV["bar"] = "rab"
- ENV.values_at.should == []
ENV.values_at("bar", "foo").should == ["rab", "oof"]
- ENV.delete "foo"
- ENV.delete "bar"
+ end
+
+ it "returns an empty array if no keys specified" do
+ ENV.values_at.should == []
+ end
+
+ it "returns nil for each key that is not a name" do
+ ENV["foo"] = "oof"
+ ENV["bar"] = "rab"
+ ENV.values_at("x", "bar", "y", "foo", "z").should == [nil, "rab", nil, "oof", nil]
end
it "uses the locale encoding" do
- ENV.values_at(ENV.keys.first).first.encoding.should == Encoding.find('locale')
+ ENV.values_at(ENV.keys.first).first.encoding.should == ENVSpecs.encoding
+ end
+
+ it "raises TypeError when a key is not coercible to String" do
+ -> { ENV.values_at("foo", Object.new) }.should.raise(TypeError, "no implicit conversion of Object into String")
end
end
diff --git a/spec/ruby/core/env/values_spec.rb b/spec/ruby/core/env/values_spec.rb
index 3a620bdb8b..71bc877d31 100644
--- a/spec/ruby/core/env/values_spec.rb
+++ b/spec/ruby/core/env/values_spec.rb
@@ -1,21 +1,14 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative 'spec_helper'
describe "ENV.values" do
it "returns an array of the values" do
- orig = ENV.to_hash
- begin
- ENV.replace "a" => "b", "c" => "d"
- a = ENV.values
- a.sort.should == ["b", "d"]
- ensure
- ENV.replace orig
- end
+ ENV.values.should == ENV.to_hash.values
end
it "uses the locale encoding" do
ENV.values.each do |value|
- value.encoding.should == Encoding.find('locale')
+ value.should.be_locale_env
end
end
end
diff --git a/spec/ruby/core/exception/args_spec.rb b/spec/ruby/core/exception/args_spec.rb
deleted file mode 100644
index 410e21edfb..0000000000
--- a/spec/ruby/core/exception/args_spec.rb
+++ /dev/null
@@ -1,5 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "NoMethodError#args" do
- it "needs to be reviewed for spec completeness"
-end
diff --git a/spec/ruby/core/exception/arguments_spec.rb b/spec/ruby/core/exception/arguments_spec.rb
deleted file mode 100644
index 47c4339e2d..0000000000
--- a/spec/ruby/core/exception/arguments_spec.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "ArgumentError" do
- it "is a subclass of StandardError" do
- StandardError.should be_ancestor_of(ArgumentError)
- end
-
- it "gives its own class name as message if it has no message" do
- ArgumentError.new.message.should == "ArgumentError"
- end
-end
diff --git a/spec/ruby/core/exception/backtrace_locations_spec.rb b/spec/ruby/core/exception/backtrace_locations_spec.rb
new file mode 100644
index 0000000000..62eab8a0f3
--- /dev/null
+++ b/spec/ruby/core/exception/backtrace_locations_spec.rb
@@ -0,0 +1,39 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/common'
+
+describe "Exception#backtrace_locations" do
+ before :each do
+ @backtrace = ExceptionSpecs::Backtrace.backtrace_locations
+ end
+
+ it "returns nil if no backtrace was set" do
+ Exception.new.backtrace_locations.should == nil
+ end
+
+ it "returns an Array" do
+ @backtrace.should.instance_of?(Array)
+ end
+
+ it "sets each element to a Thread::Backtrace::Location" do
+ @backtrace.each {|l| l.should.instance_of?(Thread::Backtrace::Location)}
+ end
+
+ it "produces a backtrace for an exception captured using $!" do
+ exception = begin
+ raise
+ rescue RuntimeError
+ $!
+ end
+
+ exception.backtrace_locations.first.path.should =~ /backtrace_locations_spec/
+ end
+
+ it "returns an Array that can be updated" do
+ begin
+ raise
+ rescue RuntimeError => e
+ e.backtrace_locations.unshift "backtrace first"
+ e.backtrace_locations[0].should == "backtrace first"
+ end
+ end
+end
diff --git a/spec/ruby/core/exception/backtrace_spec.rb b/spec/ruby/core/exception/backtrace_spec.rb
index 2d115e9b2f..a4a8272030 100644
--- a/spec/ruby/core/exception/backtrace_spec.rb
+++ b/spec/ruby/core/exception/backtrace_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/common', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/common'
describe "Exception#backtrace" do
before :each do
@@ -7,15 +7,15 @@ describe "Exception#backtrace" do
end
it "returns nil if no backtrace was set" do
- Exception.new.backtrace.should be_nil
+ Exception.new.backtrace.should == nil
end
it "returns an Array" do
- @backtrace.should be_an_instance_of(Array)
+ @backtrace.should.instance_of?(Array)
end
it "sets each element to a String" do
- @backtrace.each {|l| l.should be_an_instance_of(String)}
+ @backtrace.each {|l| l.should.instance_of?(String)}
end
it "includes the filename of the location where self raised in the first element" do
@@ -27,7 +27,7 @@ describe "Exception#backtrace" do
end
it "includes the name of the method from where self raised in the first element" do
- @backtrace.first.should =~ /in `backtrace'/
+ @backtrace.first.should =~ /in [`'](?:ExceptionSpecs::Backtrace\.)?backtrace'/
end
it "includes the filename of the location immediately prior to where self raised in the second element" do
@@ -38,16 +38,29 @@ describe "Exception#backtrace" do
@backtrace[1].should =~ /:6(:in )?/
end
- it "contains lines of the same format for each prior position in the stack" do
- @backtrace[2..-1].each do |line|
- # This regexp is deliberately imprecise to account for the need to abstract out
- # the paths of the included mspec files and the desire to avoid specifying in any
- # detail what the in `...' portion looks like.
- line.should =~ /^[^ ]+\:\d+(:in `[^`]+')?$/
+ ruby_version_is ""..."3.4" do
+ it "contains lines of the same format for each prior position in the stack" do
+ @backtrace[2..-1].each do |line|
+ # This regexp is deliberately imprecise to account for the need to abstract out
+ # the paths of the included mspec files and the desire to avoid specifying in any
+ # detail what the in `...' portion looks like.
+ line.should =~ /^.+:\d+:in `[^`]+'$/
+ end
end
end
- it "produces a backtrace for an exception captured using $!" do
+ ruby_version_is "3.4" do
+ it "contains lines of the same format for each prior position in the stack" do
+ @backtrace[2..-1].each do |line|
+ # This regexp is deliberately imprecise to account for the need to abstract out
+ # the paths of the included mspec files and the desire to avoid specifying in any
+ # detail what the in '...' portion looks like.
+ line.should =~ /^.+:\d+:in '[^`]+'$/
+ end
+ end
+ end
+
+ it "captures the backtrace for an exception into $!" do
exception = begin
raise
rescue RuntimeError
@@ -57,6 +70,16 @@ describe "Exception#backtrace" do
exception.backtrace.first.should =~ /backtrace_spec/
end
+ it "captures the backtrace for an exception into $@" do
+ backtrace = begin
+ raise
+ rescue RuntimeError
+ $@
+ end
+
+ backtrace.first.should =~ /backtrace_spec/
+ end
+
it "returns an Array that can be updated" do
begin
raise
@@ -65,4 +88,19 @@ describe "Exception#backtrace" do
e.backtrace[0].should == "backtrace first"
end
end
+
+ it "returns the same array after duping" do
+ begin
+ raise
+ rescue RuntimeError => err
+ bt = err.backtrace
+ err.dup.backtrace.should.equal?(bt)
+
+ new_bt = ['hi']
+ err.set_backtrace new_bt
+
+ err.backtrace.should == new_bt
+ err.dup.backtrace.should.equal?(new_bt)
+ end
+ end
end
diff --git a/spec/ruby/core/exception/case_compare_spec.rb b/spec/ruby/core/exception/case_compare_spec.rb
index 7592564855..5fd11ae741 100644
--- a/spec/ruby/core/exception/case_compare_spec.rb
+++ b/spec/ruby/core/exception/case_compare_spec.rb
@@ -1,5 +1,37 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "SystemCallError.===" do
- it "needs to be reviewed for spec completeness"
+ before :all do
+ @example_errno_class = Errno::EINVAL
+ @example_errno = @example_errno_class::Errno
+ end
+
+ it "returns true for an instance of the same class" do
+ Errno::EINVAL.should === Errno::EINVAL.new
+ end
+
+ it "returns true if errnos same" do
+ e = SystemCallError.new('foo', @example_errno)
+ @example_errno_class.===(e).should == true
+ end
+
+ it "returns false if errnos different" do
+ e = SystemCallError.new('foo', @example_errno + 1)
+ @example_errno_class.===(e).should == false
+ end
+
+ it "returns false if arg is not kind of SystemCallError" do
+ e = Object.new
+ @example_errno_class.===(e).should == false
+ end
+
+ it "returns true if receiver is generic and arg is kind of SystemCallError" do
+ e = SystemCallError.new('foo', @example_errno)
+ SystemCallError.===(e).should == true
+ end
+
+ it "returns false if receiver is generic and arg is not kind of SystemCallError" do
+ e = Object.new
+ SystemCallError.===(e).should == false
+ end
end
diff --git a/spec/ruby/core/exception/cause_spec.rb b/spec/ruby/core/exception/cause_spec.rb
index a1aa39ae34..cfc15bdda3 100644
--- a/spec/ruby/core/exception/cause_spec.rb
+++ b/spec/ruby/core/exception/cause_spec.rb
@@ -1,19 +1,38 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Exception#cause" do
it "returns the active exception when an exception is raised" do
begin
raise Exception, "the cause"
- rescue Exception
- begin
+ rescue Exception => cause
+ -> {
raise RuntimeError, "the consequence"
- rescue RuntimeError => e
- e.should be_an_instance_of(RuntimeError)
- e.message.should == "the consequence"
+ }.should.raise(RuntimeError, "the consequence", cause:)
+ end
+ end
+
+ it "is set for user errors caused by internal errors" do
+ begin
+ 1 / 0
+ rescue => cause
+ -> { raise "foo" }.should.raise(RuntimeError, cause:)
+ end
+ end
- e.cause.should be_an_instance_of(Exception)
- e.cause.message.should == "the cause"
- end
+ it "is set for internal errors caused by user errors" do
+ cause = RuntimeError.new "cause"
+ begin
+ raise cause
+ rescue
+ -> { 1 / 0 }.should.raise(ZeroDivisionError, cause:)
+ end
+ end
+
+ it "is not set to the exception itself when it is re-raised" do
+ begin
+ raise RuntimeError
+ rescue RuntimeError => e
+ -> { raise e }.should.raise(RuntimeError, cause: nil)
end
end
end
diff --git a/spec/ruby/core/exception/destination_encoding_name_spec.rb b/spec/ruby/core/exception/destination_encoding_name_spec.rb
deleted file mode 100644
index d6a01c3220..0000000000
--- a/spec/ruby/core/exception/destination_encoding_name_spec.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Encoding::UndefinedConversionError#destination_encoding_name" do
- it "needs to be reviewed for spec completeness"
-end
-
-describe "Encoding::InvalidByteSequenceError#destination_encoding_name" do
- it "needs to be reviewed for spec completeness"
-end
diff --git a/spec/ruby/core/exception/destination_encoding_spec.rb b/spec/ruby/core/exception/destination_encoding_spec.rb
deleted file mode 100644
index 09064a01f3..0000000000
--- a/spec/ruby/core/exception/destination_encoding_spec.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Encoding::UndefinedConversionError#destination_encoding" do
- it "needs to be reviewed for spec completeness"
-end
-
-describe "Encoding::InvalidByteSequenceError#destination_encoding" do
- it "needs to be reviewed for spec completeness"
-end
diff --git a/spec/ruby/core/exception/detailed_message_spec.rb b/spec/ruby/core/exception/detailed_message_spec.rb
new file mode 100644
index 0000000000..9df164a1cf
--- /dev/null
+++ b/spec/ruby/core/exception/detailed_message_spec.rb
@@ -0,0 +1,50 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/common'
+
+describe "Exception#detailed_message" do
+ it "returns decorated message" do
+ RuntimeError.new("new error").detailed_message.should == "new error (RuntimeError)"
+ end
+
+ it "is called by #full_message to allow message customization" do
+ exception = Exception.new("new error")
+ def exception.detailed_message(**)
+ "<prefix>#{message}<suffix>"
+ end
+ exception.full_message(highlight: false).should.include? "<prefix>new error<suffix>"
+ end
+
+ it "returns just a message if exception class is anonymous" do
+ Class.new(RuntimeError).new("message").detailed_message.should == "message"
+ end
+
+ it "returns 'unhandled exception' for an instance of RuntimeError with empty message" do
+ RuntimeError.new("").detailed_message.should == "unhandled exception"
+ end
+
+ it "returns just class name for an instance other than RuntimeError with empty message" do
+ DetailedMessageSpec::C.new("").detailed_message.should == "DetailedMessageSpec::C"
+ StandardError.new("").detailed_message.should == "StandardError"
+ end
+
+ it "returns a generated class name for an instance of RuntimeError anonymous subclass with empty message" do
+ klass = Class.new(RuntimeError)
+ klass.new("").detailed_message.should =~ /\A#<Class:0x\h+>\z/
+ end
+
+ it "accepts highlight keyword argument and adds escape control sequences" do
+ RuntimeError.new("new error").detailed_message(highlight: true).should == "\e[1mnew error (\e[1;4mRuntimeError\e[m\e[1m)\e[m"
+ end
+
+ it "accepts highlight keyword argument and adds escape control sequences for an instance of RuntimeError with empty message" do
+ RuntimeError.new("").detailed_message(highlight: true).should == "\e[1;4munhandled exception\e[m"
+ end
+
+ it "accepts highlight keyword argument and adds escape control sequences for an instance other than RuntimeError with empty message" do
+ StandardError.new("").detailed_message(highlight: true).should == "\e[1;4mStandardError\e[m"
+ end
+
+ it "allows and ignores other keyword arguments" do
+ RuntimeError.new("new error").detailed_message(foo: true).should == "new error (RuntimeError)"
+ end
+end
diff --git a/spec/ruby/core/exception/dup_spec.rb b/spec/ruby/core/exception/dup_spec.rb
new file mode 100644
index 0000000000..b53ad79bf3
--- /dev/null
+++ b/spec/ruby/core/exception/dup_spec.rb
@@ -0,0 +1,74 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/common'
+
+describe "Exception#dup" do
+ before :each do
+ @obj = ExceptionSpecs::InitializeException.new("my exception")
+ end
+
+ it "calls #initialize_copy on the new instance" do
+ dup = @obj.dup
+ ScratchPad.recorded.should_not == @obj.object_id
+ ScratchPad.recorded.should == dup.object_id
+ end
+
+ it "copies instance variables" do
+ dup = @obj.dup
+ dup.ivar.should == 1
+ end
+
+ it "does not copy singleton methods" do
+ def @obj.special() :the_one end
+ dup = @obj.dup
+ -> { dup.special }.should.raise(NameError)
+ end
+
+ it "does not copy modules included in the singleton class" do
+ class << @obj
+ include ExceptionSpecs::ExceptionModule
+ end
+
+ dup = @obj.dup
+ -> { dup.repr }.should.raise(NameError)
+ end
+
+ it "does not copy constants defined in the singleton class" do
+ class << @obj
+ CLONE = :clone
+ end
+
+ dup = @obj.dup
+ -> { class << dup; CLONE; end }.should.raise(NameError)
+ end
+
+ it "does copy the message" do
+ @obj.dup.message.should == @obj.message
+ end
+
+ it "does copy the backtrace" do
+ begin
+ # Explicitly raise so a backtrace is associated with the exception.
+ # It's tempting to call `set_backtrace` instead, but that complicates
+ # the test because it might affect other state (e.g., instance variables)
+ # on some implementations.
+ raise ExceptionSpecs::InitializeException.new("my exception")
+ rescue => e
+ @obj = e
+ end
+
+ @obj.dup.backtrace.should == @obj.backtrace
+ end
+
+ it "does copy the cause" do
+ begin
+ raise StandardError
+ rescue StandardError => cause
+ begin
+ raise RuntimeError
+ rescue RuntimeError => e
+ e.cause.should.equal?(cause)
+ e.dup.cause.should.equal?(cause)
+ end
+ end
+ end
+end
diff --git a/spec/ruby/core/exception/equal_value_spec.rb b/spec/ruby/core/exception/equal_value_spec.rb
index 3aad809377..b76b3bcd4a 100644
--- a/spec/ruby/core/exception/equal_value_spec.rb
+++ b/spec/ruby/core/exception/equal_value_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/common', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/common'
describe "Exception#==" do
it "returns true if both exceptions are the same object" do
@@ -22,19 +22,19 @@ describe "Exception#==" do
it "returns true if both exceptions have the same class, the same message, and the same backtrace" do
one = TypeError.new("message")
- one.set_backtrace [File.dirname(__FILE__)]
+ one.set_backtrace [__dir__]
two = TypeError.new("message")
- two.set_backtrace [File.dirname(__FILE__)]
+ two.set_backtrace [__dir__]
one.should == two
end
it "returns false if the two exceptions inherit from Exception but have different classes" do
one = RuntimeError.new("message")
- one.set_backtrace [File.dirname(__FILE__)]
- one.should be_kind_of(Exception)
+ one.set_backtrace [__dir__]
+ one.should.is_a?(Exception)
two = TypeError.new("message")
- two.set_backtrace [File.dirname(__FILE__)]
- two.should be_kind_of(Exception)
+ two.set_backtrace [__dir__]
+ two.should.is_a?(Exception)
one.should_not == two
end
@@ -52,7 +52,7 @@ describe "Exception#==" do
it "returns false if the two exceptions differ only in their backtrace" do
one = RuntimeError.new("message")
- one.set_backtrace [File.dirname(__FILE__)]
+ one.set_backtrace [__dir__]
two = RuntimeError.new("message")
two.set_backtrace nil
one.should_not == two
@@ -60,9 +60,9 @@ describe "Exception#==" do
it "returns false if the two exceptions differ only in their message" do
one = RuntimeError.new("message")
- one.set_backtrace [File.dirname(__FILE__)]
+ one.set_backtrace [__dir__]
two = RuntimeError.new("message2")
- two.set_backtrace [File.dirname(__FILE__)]
+ two.set_backtrace [__dir__]
one.should_not == two
end
end
diff --git a/spec/ruby/core/exception/errno_spec.rb b/spec/ruby/core/exception/errno_spec.rb
index f7f5b45d8a..36beae9976 100644
--- a/spec/ruby/core/exception/errno_spec.rb
+++ b/spec/ruby/core/exception/errno_spec.rb
@@ -1,28 +1,24 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/common', __FILE__)
-
-describe "SystemCallError#errno" do
- it "needs to be reviewed for spec completeness"
-end
+require_relative '../../spec_helper'
+require_relative 'fixtures/common'
describe "Errno::EINVAL.new" do
it "can be called with no arguments" do
exc = Errno::EINVAL.new
- exc.should be_an_instance_of(Errno::EINVAL)
+ exc.should.instance_of?(Errno::EINVAL)
exc.errno.should == Errno::EINVAL::Errno
exc.message.should == "Invalid argument"
end
it "accepts an optional custom message" do
exc = Errno::EINVAL.new('custom message')
- exc.should be_an_instance_of(Errno::EINVAL)
+ exc.should.instance_of?(Errno::EINVAL)
exc.errno.should == Errno::EINVAL::Errno
exc.message.should == "Invalid argument - custom message"
end
it "accepts an optional custom message and location" do
exc = Errno::EINVAL.new('custom message', 'location')
- exc.should be_an_instance_of(Errno::EINVAL)
+ exc.should.instance_of?(Errno::EINVAL)
exc.errno.should == Errno::EINVAL::Errno
exc.message.should == "Invalid argument @ location - custom message"
end
@@ -32,7 +28,9 @@ describe "Errno::EMFILE" do
it "can be subclassed" do
ExceptionSpecs::EMFILESub = Class.new(Errno::EMFILE)
exc = ExceptionSpecs::EMFILESub.new
- exc.should be_an_instance_of(ExceptionSpecs::EMFILESub)
+ exc.should.instance_of?(ExceptionSpecs::EMFILESub)
+ ensure
+ ExceptionSpecs.send(:remove_const, :EMFILESub)
end
end
@@ -46,3 +44,26 @@ describe "Errno::EAGAIN" do
end
end
end
+
+describe "Errno::ENOTSUP" do
+ it "is defined" do
+ Errno.should.const_defined?(:ENOTSUP, false)
+ end
+
+ it "is the same class as Errno::EOPNOTSUPP if they represent the same errno value" do
+ if Errno::ENOTSUP::Errno == Errno::EOPNOTSUPP::Errno
+ Errno::ENOTSUP.should == Errno::EOPNOTSUPP
+ else
+ Errno::ENOTSUP.should_not == Errno::EOPNOTSUPP
+ end
+ end
+end
+
+describe "Errno::ENOENT" do
+ it "lets subclasses inherit the default error message" do
+ c = Class.new(Errno::ENOENT)
+ raise c, "custom message"
+ rescue => e
+ e.message.should == "No such file or directory - custom message"
+ end
+end
diff --git a/spec/ruby/core/exception/error_bytes_spec.rb b/spec/ruby/core/exception/error_bytes_spec.rb
deleted file mode 100644
index e5027d0cf3..0000000000
--- a/spec/ruby/core/exception/error_bytes_spec.rb
+++ /dev/null
@@ -1,5 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Encoding::InvalidByteSequenceError#error_bytes" do
- it "needs to be reviewed for spec completeness"
-end
diff --git a/spec/ruby/core/exception/error_char_spec.rb b/spec/ruby/core/exception/error_char_spec.rb
deleted file mode 100644
index 8842424e90..0000000000
--- a/spec/ruby/core/exception/error_char_spec.rb
+++ /dev/null
@@ -1,5 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Encoding::UndefinedConversionError#error_char" do
- it "needs to be reviewed for spec completeness"
-end
diff --git a/spec/ruby/core/exception/exception_spec.rb b/spec/ruby/core/exception/exception_spec.rb
index afa482b9d7..f5424cdabd 100644
--- a/spec/ruby/core/exception/exception_spec.rb
+++ b/spec/ruby/core/exception/exception_spec.rb
@@ -1,51 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/common', __FILE__)
-require File.expand_path('../shared/new', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/common'
+require_relative 'shared/new'
describe "Exception.exception" do
- it_behaves_like(:exception_new, :exception)
-end
-
-describe "Exception" do
- it "is a Class" do
- Exception.should be_kind_of(Class)
- end
-
- it "is a superclass of NoMemoryError" do
- Exception.should be_ancestor_of(NoMemoryError)
- end
-
- it "is a superclass of ScriptError" do
- Exception.should be_ancestor_of(ScriptError)
- end
-
- it "is a superclass of SignalException" do
- Exception.should be_ancestor_of(SignalException)
- end
-
- it "is a superclass of Interrupt" do
- SignalException.should be_ancestor_of(Interrupt)
- end
-
- it "is a superclass of StandardError" do
- Exception.should be_ancestor_of(StandardError)
- end
-
- it "is a superclass of SystemExit" do
- Exception.should be_ancestor_of(SystemExit)
- end
-
- it "is a superclass of SystemStackError" do
- Exception.should be_ancestor_of(SystemStackError)
- end
-
- it "is a superclass of SecurityError" do
- Exception.should be_ancestor_of(SecurityError)
- end
-
- it "is a superclass of EncodingError" do
- Exception.should be_ancestor_of(EncodingError)
- end
+ it_behaves_like :exception_new, :exception
end
describe "Exception#exception" do
@@ -62,10 +20,38 @@ describe "Exception#exception" do
it "returns an exception of the same class as self with the message given as argument" do
e = RuntimeError.new
e2 = e.exception("message")
- e2.should be_an_instance_of(RuntimeError)
+ e2.should.instance_of?(RuntimeError)
e2.message.should == "message"
end
+ it "when raised will be rescued as the new exception" do
+ begin
+ begin
+ raised_first = StandardError.new('first')
+ raise raised_first
+ rescue => caught_first
+ raised_second = raised_first.exception('second')
+ raise raised_second
+ end
+ rescue => caught_second
+ end
+
+ raised_first.should == caught_first
+ raised_second.should == caught_second
+ end
+
+ it "captures an exception into $!" do
+ exception = begin
+ raise
+ rescue RuntimeError
+ $!
+ end
+
+ exception.class.should == RuntimeError
+ exception.message.should == ""
+ exception.backtrace.first.should =~ /exception_spec/
+ end
+
class CustomArgumentError < StandardError
attr_reader :val
def initialize(val)
@@ -76,7 +62,7 @@ describe "Exception#exception" do
it "returns an exception of the same class as self with the message given as argument, but without reinitializing" do
e = CustomArgumentError.new(:boom)
e2 = e.exception("message")
- e2.should be_an_instance_of(CustomArgumentError)
+ e2.should.instance_of?(CustomArgumentError)
e2.val.should == :boom
e2.message.should == "message"
end
diff --git a/spec/ruby/core/exception/exit_value_spec.rb b/spec/ruby/core/exception/exit_value_spec.rb
index daa5eb0b94..bb6cff1831 100644
--- a/spec/ruby/core/exception/exit_value_spec.rb
+++ b/spec/ruby/core/exception/exit_value_spec.rb
@@ -1,5 +1,13 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "LocalJumpError#exit_value" do
- it "needs to be reviewed for spec completeness"
+ def get_me_a_return
+ Proc.new { return 42 }
+ end
+
+ it "returns the value given to return" do
+ -> { get_me_a_return.call }.should.raise(LocalJumpError) { |e|
+ e.exit_value.should == 42
+ }
+ end
end
diff --git a/spec/ruby/core/exception/fixtures/common.rb b/spec/ruby/core/exception/fixtures/common.rb
index 51dd0bf9ed..3d8a3c3430 100644
--- a/spec/ruby/core/exception/fixtures/common.rb
+++ b/spec/ruby/core/exception/fixtures/common.rb
@@ -4,11 +4,19 @@ module ExceptionSpecs
class Backtrace
def self.backtrace
begin
- raise # Do not move this line or update backtrace_spec.rb
+ raise # If you move this line, update backtrace_spec.rb
rescue RuntimeError => e
e.backtrace
end
end
+
+ def self.backtrace_locations
+ begin
+ raise
+ rescue RuntimeError => e
+ e.backtrace_locations
+ end
+ end
end
class UnExceptional < Exception
@@ -38,6 +46,26 @@ module ExceptionSpecs
""
end
end
+
+ class InitializeException < StandardError
+ attr_reader :ivar
+
+ def initialize(message = nil)
+ super
+ @ivar = 1
+ end
+
+ def initialize_copy(other)
+ super
+ ScratchPad.record object_id
+ end
+ end
+
+ module ExceptionModule
+ def repr
+ 1
+ end
+ end
end
module NoMethodErrorSpecs
@@ -53,6 +81,12 @@ module NoMethodErrorSpecs
end
class NoMethodErrorD; end
+
+ class InstanceException < Exception
+ end
+
+ class AClass; end
+ module AModule; end
end
class NameErrorSpecs
@@ -62,3 +96,7 @@ class NameErrorSpecs
end
end
end
+
+module DetailedMessageSpec
+ C = Class.new(RuntimeError)
+end
diff --git a/spec/ruby/core/exception/fixtures/syntax_error.rb b/spec/ruby/core/exception/fixtures/syntax_error.rb
new file mode 100644
index 0000000000..ccec62f7a1
--- /dev/null
+++ b/spec/ruby/core/exception/fixtures/syntax_error.rb
@@ -0,0 +1,3 @@
+# rubocop:disable Lint/Syntax
+1+1=2
+# rubocop:enable Lint/Syntax
diff --git a/spec/ruby/core/exception/fixtures/thread_fiber_ensure.rb b/spec/ruby/core/exception/fixtures/thread_fiber_ensure.rb
new file mode 100644
index 0000000000..c109ec6247
--- /dev/null
+++ b/spec/ruby/core/exception/fixtures/thread_fiber_ensure.rb
@@ -0,0 +1,22 @@
+ready = false
+t = Thread.new do
+ f = Fiber.new do
+ begin
+ Fiber.yield
+ ensure
+ STDERR.puts "suspended fiber ensure"
+ end
+ end
+ f.resume
+
+ begin
+ ready = true
+ sleep
+ ensure
+ STDERR.puts "current fiber ensure"
+ end
+end
+
+Thread.pass until ready && t.stop?
+
+# let the program end, it's the same as #exit or an exception for this behavior
diff --git a/spec/ruby/core/exception/fixtures/thread_fiber_ensure_non_root_fiber.rb b/spec/ruby/core/exception/fixtures/thread_fiber_ensure_non_root_fiber.rb
new file mode 100644
index 0000000000..3364ed06d0
--- /dev/null
+++ b/spec/ruby/core/exception/fixtures/thread_fiber_ensure_non_root_fiber.rb
@@ -0,0 +1,25 @@
+ready = false
+t = Thread.new do
+ f = Fiber.new do
+ begin
+ Fiber.yield
+ ensure
+ STDERR.puts "suspended fiber ensure"
+ end
+ end
+ f.resume
+
+ f2 = Fiber.new do
+ begin
+ ready = true
+ sleep
+ ensure
+ STDERR.puts "current fiber ensure"
+ end
+ end
+ f2.resume
+end
+
+Thread.pass until ready && t.stop?
+
+# let the program end, it's the same as #exit or an exception for this behavior
diff --git a/spec/ruby/core/exception/frozen_error_spec.rb b/spec/ruby/core/exception/frozen_error_spec.rb
new file mode 100644
index 0000000000..a28f524b54
--- /dev/null
+++ b/spec/ruby/core/exception/frozen_error_spec.rb
@@ -0,0 +1,54 @@
+require_relative '../../spec_helper'
+
+describe "FrozenError.new" do
+ it "should take optional receiver argument" do
+ o = Object.new
+ FrozenError.new("msg", receiver: o).receiver.should.equal?(o)
+ end
+end
+
+describe "FrozenError#receiver" do
+ it "should return frozen object that modification was attempted on" do
+ o = Object.new.freeze
+ begin
+ def o.x; end
+ rescue => e
+ e.should.is_a?(FrozenError)
+ e.receiver.should.equal?(o)
+ else
+ raise
+ end
+ end
+end
+
+describe "FrozenError#message" do
+ it "includes a receiver" do
+ object = Object.new
+ object.freeze
+
+ msg_class = ruby_version_is("4.0") ? "Object" : "object"
+
+ -> {
+ def object.x; end
+ }.should.raise(FrozenError, "can't modify frozen #{msg_class}: #{object}")
+
+ object = [].freeze
+ -> { object << nil }.should.raise(FrozenError, "can't modify frozen Array: []")
+ end
+end
+
+describe "Modifying a frozen object" do
+ context "#inspect is redefined and modifies the object" do
+ it "returns ... instead of String representation of object" do
+ object = Object.new
+ def object.inspect; @a = 1 end
+ def object.modify; @a = 2 end
+
+ object.freeze
+
+ # CRuby's message contains multiple whitespaces before '...'.
+ # So handle both multiple and single whitespace.
+ -> { object.modify }.should.raise(FrozenError, /can't modify frozen .*?: \s*.../)
+ end
+ end
+end
diff --git a/spec/ruby/core/exception/full_message_spec.rb b/spec/ruby/core/exception/full_message_spec.rb
new file mode 100644
index 0000000000..5a5e0a2b3a
--- /dev/null
+++ b/spec/ruby/core/exception/full_message_spec.rb
@@ -0,0 +1,226 @@
+require_relative '../../spec_helper'
+
+describe "Exception#full_message" do
+ it "returns formatted string of exception using the same format that is used to print an uncaught exceptions to stderr" do
+ e = RuntimeError.new("Some runtime error")
+ e.set_backtrace(["a.rb:1", "b.rb:2"])
+
+ full_message = e.full_message
+ full_message.should.include? "RuntimeError"
+ full_message.should.include? "Some runtime error"
+ full_message.should.include? "a.rb:1"
+ full_message.should.include? "b.rb:2"
+ end
+
+ it "supports :highlight option and adds escape sequences to highlight some strings" do
+ e = RuntimeError.new("Some runtime error")
+
+ full_message = e.full_message(highlight: true, order: :top).lines
+ full_message[0].should.end_with? "\e[1mSome runtime error (\e[1;4mRuntimeError\e[m\e[1m)\e[m\n"
+
+ full_message = e.full_message(highlight: true, order: :bottom).lines
+ full_message[0].should == "\e[1mTraceback\e[m (most recent call last):\n"
+ full_message[-1].should.end_with? "\e[1mSome runtime error (\e[1;4mRuntimeError\e[m\e[1m)\e[m\n"
+
+ full_message = e.full_message(highlight: false, order: :top).lines
+ full_message[0].should.end_with? "Some runtime error (RuntimeError)\n"
+
+ full_message = e.full_message(highlight: false, order: :bottom).lines
+ full_message[0].should == "Traceback (most recent call last):\n"
+ full_message[-1].should.end_with? "Some runtime error (RuntimeError)\n"
+ end
+
+ it "supports :order option and places the error message and the backtrace at the top or the bottom" do
+ e = RuntimeError.new("Some runtime error")
+ e.set_backtrace(["a.rb:1", "b.rb:2"])
+
+ e.full_message(order: :top, highlight: false).should =~ /a.rb:1.*b.rb:2/m
+ e.full_message(order: :bottom, highlight: false).should =~ /b.rb:2.*a.rb:1/m
+ end
+
+ it "shows the caller if the exception has no backtrace" do
+ e = RuntimeError.new("Some runtime error")
+ e.backtrace.should == nil
+ full_message = e.full_message(highlight: false, order: :top).lines
+ full_message[0].should.start_with?("#{__FILE__}:#{__LINE__-1}:in ")
+ full_message[0].should.end_with?("': Some runtime error (RuntimeError)\n")
+ end
+
+ describe "includes details about whether an exception was handled" do
+ describe "RuntimeError" do
+ it "should report as unhandled if message is empty" do
+ err = RuntimeError.new("")
+
+ err.full_message.should =~ /unhandled exception/
+ err.full_message(highlight: true).should =~ /unhandled exception/
+ err.full_message(highlight: false).should =~ /unhandled exception/
+ end
+
+ it "should not report as unhandled if the message is not empty" do
+ err = RuntimeError.new("non-empty")
+
+ err.full_message.should !~ /unhandled exception/
+ err.full_message(highlight: true).should !~ /unhandled exception/
+ err.full_message(highlight: false).should !~ /unhandled exception/
+ end
+
+ it "should not report as unhandled if the message is nil" do
+ err = RuntimeError.new(nil)
+
+ err.full_message.should !~ /unhandled exception/
+ err.full_message(highlight: true).should !~ /unhandled exception/
+ err.full_message(highlight: false).should !~ /unhandled exception/
+ end
+
+ it "should not report as unhandled if the message is not specified" do
+ err = RuntimeError.new()
+
+ err.full_message.should !~ /unhandled exception/
+ err.full_message(highlight: true).should !~ /unhandled exception/
+ err.full_message(highlight: false).should !~ /unhandled exception/
+ end
+
+ it "adds escape sequences to highlight some strings if the message is not specified and :highlight option is specified" do
+ e = RuntimeError.new("")
+
+ full_message = e.full_message(highlight: true, order: :top).lines
+ full_message[0].should.end_with? "\e[1;4munhandled exception\e[m\n"
+
+ full_message = e.full_message(highlight: true, order: :bottom).lines
+ full_message[0].should == "\e[1mTraceback\e[m (most recent call last):\n"
+ full_message[-1].should.end_with? "\e[1;4munhandled exception\e[m\n"
+
+ full_message = e.full_message(highlight: false, order: :top).lines
+ full_message[0].should.end_with? "unhandled exception\n"
+
+ full_message = e.full_message(highlight: false, order: :bottom).lines
+ full_message[0].should == "Traceback (most recent call last):\n"
+ full_message[-1].should.end_with? "unhandled exception\n"
+ end
+ end
+
+ describe "generic Error" do
+ it "should not report as unhandled in any event" do
+ StandardError.new("").full_message.should !~ /unhandled exception/
+ StandardError.new("non-empty").full_message.should !~ /unhandled exception/
+ end
+ end
+ end
+
+ it "shows the exception class at the end of the first line of the message when the message contains multiple lines" do
+ begin
+ line = __LINE__; raise "first line\nsecond line"
+ rescue => e
+ full_message = e.full_message(highlight: false, order: :top).lines
+ full_message[0].should.start_with?("#{__FILE__}:#{line}:in ")
+ full_message[0].should.end_with?(": first line (RuntimeError)\n")
+ full_message[1].should == "second line\n"
+ end
+ end
+
+ it "highlights the entire message when the message contains multiple lines" do
+ begin
+ line = __LINE__; raise "first line\nsecond line\nthird line"
+ rescue => e
+ full_message = e.full_message(highlight: true, order: :top).lines
+ full_message[0].should.start_with?("#{__FILE__}:#{line}:in ")
+ full_message[0].should.end_with?(": \e[1mfirst line (\e[1;4mRuntimeError\e[m\e[1m)\e[m\n")
+ full_message[1].should == "\e[1msecond line\e[m\n"
+ full_message[2].should == "\e[1mthird line\e[m\n"
+ end
+ end
+
+ it "contains cause of exception" do
+ begin
+ begin
+ raise 'the cause'
+ rescue
+ raise 'main exception'
+ end
+ rescue => e
+ exception = e
+ end
+
+ exception.full_message.should.include? "main exception"
+ exception.full_message.should.include? "the cause"
+ end
+
+ it 'contains all the chain of exceptions' do
+ begin
+ begin
+ begin
+ raise 'origin exception'
+ rescue
+ raise 'intermediate exception'
+ end
+ rescue
+ raise 'last exception'
+ end
+ rescue => e
+ exception = e
+ end
+
+ exception.full_message.should.include? "last exception"
+ exception.full_message.should.include? "intermediate exception"
+ exception.full_message.should.include? "origin exception"
+ end
+
+ it "relies on #detailed_message" do
+ e = RuntimeError.new("new error")
+ e.define_singleton_method(:detailed_message) { |**| "DETAILED MESSAGE" }
+
+ e.full_message.lines.first.should =~ /DETAILED MESSAGE/
+ end
+
+ it "passes all its own keyword arguments (with :highlight default value and without :order default value) to #detailed_message" do
+ e = RuntimeError.new("new error")
+ options_passed = nil
+ e.define_singleton_method(:detailed_message) do |**options|
+ options_passed = options
+ "DETAILED MESSAGE"
+ end
+
+ e.full_message(foo: "bar")
+ options_passed.should == { foo: "bar", highlight: Exception.to_tty? }
+ end
+
+ it "converts #detailed_message returned value to String if it isn't a String" do
+ message = Object.new
+ def message.to_str; "DETAILED MESSAGE"; end
+
+ e = RuntimeError.new("new error")
+ e.define_singleton_method(:detailed_message) { |**| message }
+
+ e.full_message.lines.first.should =~ /DETAILED MESSAGE/
+ end
+
+ it "uses class name if #detailed_message returns nil" do
+ e = RuntimeError.new("new error")
+ e.define_singleton_method(:detailed_message) { |**| nil }
+
+ e.full_message(highlight: false).lines.first.should =~ /RuntimeError/
+ e.full_message(highlight: true).lines.first.should =~ /#{Regexp.escape("\e[1;4mRuntimeError\e[m")}/
+ end
+
+ it "uses class name if exception object doesn't respond to #detailed_message" do
+ e = RuntimeError.new("new error")
+ class << e
+ undef :detailed_message
+ end
+
+ e.full_message(highlight: false).lines.first.should =~ /RuntimeError/
+ e.full_message(highlight: true).lines.first.should =~ /#{Regexp.escape("\e[1;4mRuntimeError\e[m")}/
+ end
+
+ it "allows cause with empty backtrace" do
+ begin
+ raise RuntimeError.new("Some runtime error"), cause: RuntimeError.new("Some other runtime error")
+ rescue => e
+ end
+
+ full_message = e.full_message
+ full_message.should.include? "RuntimeError"
+ full_message.should.include? "Some runtime error"
+ full_message.should.include? "Some other runtime error"
+ end
+end
diff --git a/spec/ruby/core/exception/hierarchy_spec.rb b/spec/ruby/core/exception/hierarchy_spec.rb
new file mode 100644
index 0000000000..6514eb1994
--- /dev/null
+++ b/spec/ruby/core/exception/hierarchy_spec.rb
@@ -0,0 +1,62 @@
+require_relative '../../spec_helper'
+
+describe "Exception" do
+ it "has the right class hierarchy" do
+ hierarchy = {
+ Exception => {
+ NoMemoryError => nil,
+ ScriptError => {
+ LoadError => nil,
+ NotImplementedError => nil,
+ SyntaxError => nil,
+ },
+ SecurityError => nil,
+ SignalException => {
+ Interrupt => nil,
+ },
+ StandardError => {
+ ArgumentError => {
+ UncaughtThrowError => nil,
+ },
+ EncodingError => nil,
+ FiberError => nil,
+ IOError => {
+ EOFError => nil,
+ },
+ IndexError => {
+ KeyError => nil,
+ StopIteration => {
+ ClosedQueueError => nil,
+ },
+ },
+ LocalJumpError => nil,
+ NameError => {
+ NoMethodError => nil,
+ },
+ RangeError => {
+ FloatDomainError => nil,
+ },
+ RegexpError => nil,
+ RuntimeError => {
+ FrozenError => nil,
+ },
+ SystemCallError => nil,
+ ThreadError => nil,
+ TypeError => nil,
+ ZeroDivisionError => nil,
+ },
+ SystemExit => nil,
+ SystemStackError => nil,
+ },
+ }
+
+ traverse = -> parent_class, parent_subclass_hash {
+ parent_subclass_hash.each do |child_class, child_subclass_hash|
+ child_class.class.should == Class
+ child_class.superclass.should == parent_class
+ traverse.call(child_class, child_subclass_hash) if child_subclass_hash
+ end
+ }
+ traverse.call(Object, hierarchy)
+ end
+end
diff --git a/spec/ruby/core/exception/incomplete_input_spec.rb b/spec/ruby/core/exception/incomplete_input_spec.rb
deleted file mode 100644
index a64d4be3f3..0000000000
--- a/spec/ruby/core/exception/incomplete_input_spec.rb
+++ /dev/null
@@ -1,5 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Encoding::InvalidByteSequenceError#incomplete_input?" do
- it "needs to be reviewed for spec completeness"
-end
diff --git a/spec/ruby/core/exception/initialize_spec.rb b/spec/ruby/core/exception/initialize_spec.rb
deleted file mode 100644
index 14fb93ef07..0000000000
--- a/spec/ruby/core/exception/initialize_spec.rb
+++ /dev/null
@@ -1 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
diff --git a/spec/ruby/core/exception/inspect_spec.rb b/spec/ruby/core/exception/inspect_spec.rb
index 5b06ffee71..6f380a36c7 100644
--- a/spec/ruby/core/exception/inspect_spec.rb
+++ b/spec/ruby/core/exception/inspect_spec.rb
@@ -1,11 +1,15 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/common', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/common'
describe "Exception#inspect" do
it "returns '#<Exception: Exception>' when no message given" do
Exception.new.inspect.should == "#<Exception: Exception>"
end
+ it "keeps message encoding" do
+ Exception.new('å').inspect.should == "#<Exception: å>"
+ end
+
it "includes #to_s when the result is non-empty" do
ExceptionSpecs::OverrideToS.new.inspect.should == "#<ExceptionSpecs::OverrideToS: this is from #to_s>"
end
diff --git a/spec/ruby/core/exception/interrupt_spec.rb b/spec/ruby/core/exception/interrupt_spec.rb
index ef24743936..90d261e470 100644
--- a/spec/ruby/core/exception/interrupt_spec.rb
+++ b/spec/ruby/core/exception/interrupt_spec.rb
@@ -1,10 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Interrupt" do
- it "is a subclass of SignalException" do
- Interrupt.superclass.should == SignalException
- end
-end
+require_relative '../../spec_helper'
describe "Interrupt.new" do
it "returns an instance of interrupt with no message given" do
@@ -20,7 +14,7 @@ describe "Interrupt.new" do
end
end
-describe "rescueing Interrupt" do
+describe "rescuing Interrupt" do
before do
@original_sigint_proc = Signal.trap(:INT, :SIG_DFL)
end
@@ -35,7 +29,32 @@ describe "rescueing Interrupt" do
sleep
rescue Interrupt => e
e.signo.should == Signal.list["INT"]
- e.signm.should == ""
+ ["", "Interrupt"].should.include?(e.message)
+ end
+ end
+end
+
+describe "Interrupt" do
+ # This spec is basically the same as above,
+ # but it does not rely on Signal.trap(:INT, :SIG_DFL) which can be tricky
+ it "is raised on the main Thread by the default SIGINT handler" do
+ out = ruby_exe(<<-'RUBY', args: "2>&1")
+ begin
+ Process.kill :INT, Process.pid
+ sleep
+ rescue Interrupt => e
+ puts "Interrupt: #{e.signo}"
+ end
+ RUBY
+ out.should == "Interrupt: #{Signal.list["INT"]}\n"
+ end
+
+ platform_is_not :windows do
+ it "shows the backtrace and has a signaled exit status" do
+ err = IO.popen([*ruby_exe, '-e', 'Process.kill :INT, Process.pid; sleep'], err: [:child, :out], &:read)
+ $?.termsig.should == Signal.list.fetch('INT')
+ err.should.include? ': Interrupt'
+ err.should =~ /from -e:1:in [`']<main>'/
end
end
end
diff --git a/spec/ruby/core/exception/io_error_spec.rb b/spec/ruby/core/exception/io_error_spec.rb
index 0971be332f..940d5be876 100644
--- a/spec/ruby/core/exception/io_error_spec.rb
+++ b/spec/ruby/core/exception/io_error_spec.rb
@@ -1,22 +1,16 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "IOError" do
- it "is a superclass of EOFError" do
- IOError.should be_ancestor_of(EOFError)
- end
-end
+require_relative '../../spec_helper'
describe "IO::EAGAINWaitReadable" do
it "combines Errno::EAGAIN and IO::WaitReadable" do
IO::EAGAINWaitReadable.superclass.should == Errno::EAGAIN
- IO::EAGAINWaitReadable.ancestors.should include IO::WaitReadable
+ IO::EAGAINWaitReadable.ancestors.should.include? IO::WaitReadable
end
it "is the same as IO::EWOULDBLOCKWaitReadable if Errno::EAGAIN is the same as Errno::EWOULDBLOCK" do
if Errno::EAGAIN.equal? Errno::EWOULDBLOCK
- IO::EAGAINWaitReadable.should equal IO::EWOULDBLOCKWaitReadable
+ IO::EAGAINWaitReadable.should.equal? IO::EWOULDBLOCKWaitReadable
else
- IO::EAGAINWaitReadable.should_not equal IO::EWOULDBLOCKWaitReadable
+ IO::EAGAINWaitReadable.should_not.equal? IO::EWOULDBLOCKWaitReadable
end
end
end
@@ -24,21 +18,21 @@ end
describe "IO::EWOULDBLOCKWaitReadable" do
it "combines Errno::EWOULDBLOCK and IO::WaitReadable" do
IO::EWOULDBLOCKWaitReadable.superclass.should == Errno::EWOULDBLOCK
- IO::EAGAINWaitReadable.ancestors.should include IO::WaitReadable
+ IO::EAGAINWaitReadable.ancestors.should.include? IO::WaitReadable
end
end
describe "IO::EAGAINWaitWritable" do
it "combines Errno::EAGAIN and IO::WaitWritable" do
IO::EAGAINWaitWritable.superclass.should == Errno::EAGAIN
- IO::EAGAINWaitWritable.ancestors.should include IO::WaitWritable
+ IO::EAGAINWaitWritable.ancestors.should.include? IO::WaitWritable
end
it "is the same as IO::EWOULDBLOCKWaitWritable if Errno::EAGAIN is the same as Errno::EWOULDBLOCK" do
if Errno::EAGAIN.equal? Errno::EWOULDBLOCK
- IO::EAGAINWaitWritable.should equal IO::EWOULDBLOCKWaitWritable
+ IO::EAGAINWaitWritable.should.equal? IO::EWOULDBLOCKWaitWritable
else
- IO::EAGAINWaitWritable.should_not equal IO::EWOULDBLOCKWaitWritable
+ IO::EAGAINWaitWritable.should_not.equal? IO::EWOULDBLOCKWaitWritable
end
end
end
@@ -46,6 +40,6 @@ end
describe "IO::EWOULDBLOCKWaitWritable" do
it "combines Errno::EWOULDBLOCK and IO::WaitWritable" do
IO::EWOULDBLOCKWaitWritable.superclass.should == Errno::EWOULDBLOCK
- IO::EAGAINWaitWritable.ancestors.should include IO::WaitWritable
+ IO::EAGAINWaitWritable.ancestors.should.include? IO::WaitWritable
end
end
diff --git a/spec/ruby/core/exception/key_error_spec.rb b/spec/ruby/core/exception/key_error_spec.rb
new file mode 100644
index 0000000000..c5e2b1efbc
--- /dev/null
+++ b/spec/ruby/core/exception/key_error_spec.rb
@@ -0,0 +1,19 @@
+require_relative '../../spec_helper'
+
+describe "KeyError" do
+ it "accepts :receiver and :key options" do
+ receiver = mock("receiver")
+ key = mock("key")
+
+ error = KeyError.new(receiver: receiver, key: key)
+
+ error.receiver.should == receiver
+ error.key.should == key
+
+ error = KeyError.new("message", receiver: receiver, key: key)
+
+ error.message.should == "message"
+ error.receiver.should == receiver
+ error.key.should == key
+ end
+end
diff --git a/spec/ruby/core/exception/load_error_spec.rb b/spec/ruby/core/exception/load_error_spec.rb
index 2999c66117..0056403e58 100644
--- a/spec/ruby/core/exception/load_error_spec.rb
+++ b/spec/ruby/core/exception/load_error_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "LoadError#path" do
before :each do
diff --git a/spec/ruby/core/exception/message_spec.rb b/spec/ruby/core/exception/message_spec.rb
index 7eee6d99de..8d7476126e 100644
--- a/spec/ruby/core/exception/message_spec.rb
+++ b/spec/ruby/core/exception/message_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/common', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/common'
describe "Exception#message" do
it "returns the class name if there is no message" do
diff --git a/spec/ruby/core/exception/name_error_spec.rb b/spec/ruby/core/exception/name_error_spec.rb
index e5b19d6219..ddd51a92e5 100644
--- a/spec/ruby/core/exception/name_error_spec.rb
+++ b/spec/ruby/core/exception/name_error_spec.rb
@@ -1,13 +1,28 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "NameError" do
- it "is a superclass of NoMethodError" do
- NameError.should be_ancestor_of(NoMethodError)
- end
-end
+require_relative '../../spec_helper'
describe "NameError.new" do
it "should take optional name argument" do
NameError.new("msg","name").name.should == "name"
end
+
+ it "accepts a :receiver keyword argument" do
+ receiver = mock("receiver")
+
+ error = NameError.new("msg", :name, receiver: receiver)
+
+ error.receiver.should == receiver
+ error.name.should == :name
+ end
+end
+
+describe "NameError#dup" do
+ it "copies the name and receiver" do
+ begin
+ foo
+ rescue NameError => ne
+ name_error_dup = ne.dup
+ name_error_dup.name.should == :foo
+ name_error_dup.receiver.should == self
+ end
+ end
end
diff --git a/spec/ruby/core/exception/name_spec.rb b/spec/ruby/core/exception/name_spec.rb
index e8a3c011d2..6e0e99d194 100644
--- a/spec/ruby/core/exception/name_spec.rb
+++ b/spec/ruby/core/exception/name_spec.rb
@@ -1,61 +1,43 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "NameError#name" do
it "returns a method name as a symbol" do
-> {
doesnt_exist
- }.should raise_error(NameError) {|e| e.name.should == :doesnt_exist }
+ }.should.raise(NameError) {|e| e.name.should == :doesnt_exist }
end
it "returns a constant name as a symbol" do
-> {
DoesntExist
- }.should raise_error(NameError) {|e| e.name.should == :DoesntExist }
+ }.should.raise(NameError) {|e| e.name.should == :DoesntExist }
end
it "returns a constant name without namespace as a symbol" do
-> {
Object::DoesntExist
- }.should raise_error(NameError) {|e| e.name.should == :DoesntExist }
+ }.should.raise(NameError) {|e| e.name.should == :DoesntExist }
end
it "returns a class variable name as a symbol" do
-> {
- -> {
- @@doesnt_exist
- }.should complain(/class variable access from toplevel/)
- }.should raise_error(NameError) { |e| e.name.should == :@@doesnt_exist }
+ eval("class singleton_class::A; @@doesnt_exist end", binding, __FILE__, __LINE__)
+ }.should.raise(NameError) { |e| e.name.should == :@@doesnt_exist }
end
- ruby_version_is ""..."2.3" do
- it "always returns a symbol when a NameError is raised from #instance_variable_get" do
- -> {
- Object.new.instance_variable_get("invalid_ivar_name")
- }.should raise_error(NameError) { |e| e.name.should == :invalid_ivar_name }
- end
-
- it "always returns a symbol when a NameError is raised from #class_variable_get" do
- -> {
- Object.class_variable_get("invalid_cvar_name")
- }.should raise_error(NameError) { |e| e.name.should == :invalid_cvar_name }
- end
- end
-
- ruby_version_is "2.3" do
- it "returns the first argument passed to the method when a NameError is raised from #instance_variable_get" do
- invalid_ivar_name = "invalid_ivar_name"
+ it "returns the first argument passed to the method when a NameError is raised from #instance_variable_get" do
+ invalid_ivar_name = "invalid_ivar_name"
- -> {
- Object.new.instance_variable_get(invalid_ivar_name)
- }.should raise_error(NameError) {|e| e.name.should equal(invalid_ivar_name) }
- end
+ -> {
+ Object.new.instance_variable_get(invalid_ivar_name)
+ }.should.raise(NameError) {|e| e.name.should.equal?(invalid_ivar_name) }
+ end
- it "returns the first argument passed to the method when a NameError is raised from #class_variable_get" do
- invalid_cvar_name = "invalid_cvar_name"
+ it "returns the first argument passed to the method when a NameError is raised from #class_variable_get" do
+ invalid_cvar_name = "invalid_cvar_name"
- -> {
- Object.class_variable_get(invalid_cvar_name)
- }.should raise_error(NameError) {|e| e.name.should equal(invalid_cvar_name) }
- end
+ -> {
+ Object.class_variable_get(invalid_cvar_name)
+ }.should.raise(NameError) {|e| e.name.should.equal?(invalid_cvar_name) }
end
end
diff --git a/spec/ruby/core/exception/new_spec.rb b/spec/ruby/core/exception/new_spec.rb
index 61d35a1dfa..100dbb0a24 100644
--- a/spec/ruby/core/exception/new_spec.rb
+++ b/spec/ruby/core/exception/new_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/common', __FILE__)
-require File.expand_path('../shared/new', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/common'
+require_relative 'shared/new'
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..9f92104082 100644
--- a/spec/ruby/core/exception/no_method_error_spec.rb
+++ b/spec/ruby/core/exception/no_method_error_spec.rb
@@ -1,14 +1,23 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/common', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/common'
describe "NoMethodError.new" do
it "allows passing method args" do
- NoMethodError.new("msg","name","args").args.should == "args"
+ NoMethodError.new("msg", "name", ["args"]).args.should == ["args"]
end
it "does not require a name" do
NoMethodError.new("msg").message.should == "msg"
end
+
+ it "accepts a :receiver keyword argument" do
+ receiver = mock("receiver")
+
+ error = NoMethodError.new("msg", :name, receiver: receiver)
+
+ error.receiver.should == receiver
+ error.name.should == :name
+ end
end
describe "NoMethodError#args" do
@@ -26,7 +35,7 @@ describe "NoMethodError#args" do
NoMethodErrorSpecs::NoMethodErrorB.new.foo(1,a)
rescue Exception => e
e.args.should == [1,a]
- e.args[1].object_id.should == a.object_id
+ e.args[1].should.equal? a
end
end
end
@@ -36,7 +45,7 @@ describe "NoMethodError#message" do
begin
NoMethodErrorSpecs::NoMethodErrorD.new.foo
rescue Exception => e
- e.should be_kind_of(NoMethodError)
+ e.should.is_a?(NoMethodError)
end
end
@@ -44,7 +53,7 @@ describe "NoMethodError#message" do
begin
NoMethodErrorSpecs::NoMethodErrorC.new.a_protected_method
rescue Exception => e
- e.should be_kind_of(NoMethodError)
+ e.should.is_a?(NoMethodError)
end
end
@@ -52,8 +61,164 @@ describe "NoMethodError#message" do
begin
NoMethodErrorSpecs::NoMethodErrorC.new.a_private_method
rescue Exception => e
- e.should be_kind_of(NoMethodError)
- e.message.match(/private method/).should_not == nil
+ e.should.is_a?(NoMethodError)
+ e.message.lines[0].should =~ /private method [`']a_private_method' called for /
+ end
+ end
+
+ it "uses a literal name when receiver is nil" do
+ begin
+ nil.foo
+ rescue NoMethodError => error
+ error.message.should =~ /\Aundefined method [`']foo' for nil\Z/
+ end
+ end
+
+ it "uses a literal name when receiver is true" do
+ begin
+ true.foo
+ rescue NoMethodError => error
+ error.message.should =~ /\Aundefined method [`']foo' for true\Z/
+ end
+ end
+
+ it "uses a literal name when receiver is false" do
+ begin
+ false.foo
+ rescue NoMethodError => error
+ error.message.should =~ /\Aundefined method [`']foo' for false\Z/
+ end
+ end
+
+ it "uses #name when receiver is a class" do
+ klass = Class.new { def self.name; "MyClass"; end }
+
+ begin
+ klass.foo
+ rescue NoMethodError => error
+ error.message.should =~ /\Aundefined method [`']foo' for class MyClass\Z/
+ end
+ end
+
+ it "uses class' string representation when receiver is an anonymous class" do
+ klass = Class.new
+
+ begin
+ klass.foo
+ rescue NoMethodError => error
+ error.message.should =~ /\Aundefined method [`']foo' for class #<Class:0x\h+>\Z/
+ end
+ end
+
+ it "uses class' string representation when receiver is a singleton class" do
+ obj = Object.new
+ singleton_class = obj.singleton_class
+
+ begin
+ singleton_class.foo
+ rescue NoMethodError => error
+ error.message.should =~ /\Aundefined method [`']foo' for class #<Class:#<Object:0x\h+>>\Z/
+ end
+ end
+
+ it "uses #name when receiver is a module" do
+ mod = Module.new { def self.name; "MyModule"; end }
+
+ begin
+ mod.foo
+ rescue NoMethodError => error
+ error.message.should =~ /\Aundefined method [`']foo' for module MyModule\Z/
+ end
+ end
+
+ it "uses module's string representation when receiver is an anonymous module" do
+ m = Module.new
+
+ begin
+ m.foo
+ rescue NoMethodError => error
+ error.message.should =~ /\Aundefined method [`']foo' for module #<Module:0x\h+>\Z/
+ end
+ end
+
+ it "uses class #name when receiver is an ordinary object" do
+ klass = Class.new { def self.name; "MyClass"; end }
+ instance = klass.new
+
+ begin
+ instance.bar
+ rescue NoMethodError => error
+ error.message.should =~ /\Aundefined method [`']bar' for an instance of MyClass\Z/
+ end
+ end
+
+ it "uses class string representation when receiver is an instance of anonymous class" do
+ klass = Class.new
+ instance = klass.new
+
+ begin
+ instance.bar
+ rescue NoMethodError => error
+ error.message.should =~ /\Aundefined method [`']bar' for an instance of #<Class:0x\h+>\Z/
+ end
+ end
+
+ it "uses class name when receiver has a singleton class" do
+ instance = NoMethodErrorSpecs::NoMethodErrorA.new
+ def instance.foo; end
+
+ begin
+ instance.bar
+ rescue NoMethodError => error
+ error.message.should =~ /\Aundefined method [`']bar' for #<NoMethodErrorSpecs::NoMethodErrorA:0x\h+>\Z/
+ end
+ end
+
+ it "does not call #inspect 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 NoMethodError => error
+ error.message.should =~ /\Aundefined method [`']bar' for an instance of #<Class:0x\h+>\Z/
+ ScratchPad.recorded.should == []
+ end
+ end
+
+ it "does not truncate long class names" do
+ class_name = 'ExceptionSpecs::A' + 'a'*100
+
+ begin
+ eval <<~RUBY
+ class #{class_name}
+ end
+
+ obj = #{class_name}.new
+ obj.foo
+ RUBY
+ rescue NoMethodError => error
+ error.message.should =~ /\Aundefined method [`']foo' for an instance of #{class_name}\Z/
+ end
+ end
+end
+
+describe "NoMethodError#dup" do
+ it "copies the name, arguments and receiver" do
+ begin
+ receiver = Object.new
+ receiver.foo(:one, :two)
+ rescue NoMethodError => nme
+ no_method_error_dup = nme.dup
+ no_method_error_dup.name.should == :foo
+ no_method_error_dup.receiver.should == receiver
+ no_method_error_dup.args.should == [:one, :two]
end
end
end
diff --git a/spec/ruby/core/exception/range_error_spec.rb b/spec/ruby/core/exception/range_error_spec.rb
deleted file mode 100644
index 9c0462bbf7..0000000000
--- a/spec/ruby/core/exception/range_error_spec.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "RangeError" do
- it "is a superclass of FloatDomainError" do
- RangeError.should be_ancestor_of(FloatDomainError)
- end
-end
diff --git a/spec/ruby/core/exception/readagain_bytes_spec.rb b/spec/ruby/core/exception/readagain_bytes_spec.rb
deleted file mode 100644
index 30efb67686..0000000000
--- a/spec/ruby/core/exception/readagain_bytes_spec.rb
+++ /dev/null
@@ -1,5 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Encoding::InvalidByteSequenceError#readagain_bytes" do
- it "needs to be reviewed for spec completeness"
-end
diff --git a/spec/ruby/core/exception/reason_spec.rb b/spec/ruby/core/exception/reason_spec.rb
index fad4d47c64..d7022768b6 100644
--- a/spec/ruby/core/exception/reason_spec.rb
+++ b/spec/ruby/core/exception/reason_spec.rb
@@ -1,5 +1,13 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "LocalJumpError#reason" do
- it "needs to be reviewed for spec completeness"
+ def get_me_a_return
+ Proc.new { return 42 }
+ end
+
+ it "returns 'return' for a return" do
+ -> { get_me_a_return.call }.should.raise(LocalJumpError) { |e|
+ e.reason.should == :return
+ }
+ end
end
diff --git a/spec/ruby/core/exception/receiver_spec.rb b/spec/ruby/core/exception/receiver_spec.rb
index 83f8d5927c..6ecf640ad8 100644
--- a/spec/ruby/core/exception/receiver_spec.rb
+++ b/spec/ruby/core/exception/receiver_spec.rb
@@ -1,62 +1,58 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/common', __FILE__)
-
-ruby_version_is "2.3" do
- describe "NameError#receiver" do
- class ::ReceiverClass
- def call_undefined_class_variable; @@doesnt_exist end
- end
-
- it "returns the object that raised the exception" do
- receiver = Object.new
-
- -> {
- receiver.doesnt_exist
- }.should raise_error(NameError) {|e| e.receiver.should equal(receiver) }
- end
-
- it "returns the Object class when an undefined constant is called without namespace" do
- -> {
- DoesntExist
- }.should raise_error(NameError) {|e| e.receiver.should equal(Object) }
- end
-
- it "returns a class when an undefined constant is called" do
- -> {
- NameErrorSpecs::ReceiverClass::DoesntExist
- }.should raise_error(NameError) {|e| e.receiver.should equal(NameErrorSpecs::ReceiverClass) }
- end
-
- it "returns the Object class when an undefined class variable is called" do
- -> {
- -> {
- @@doesnt_exist
- }.should complain(/class variable access from toplevel/)
- }.should raise_error(NameError) {|e| e.receiver.should equal(Object) }
- end
-
- it "returns a class when an undefined class variable is called in a subclass' namespace" do
- -> {
- NameErrorSpecs::ReceiverClass.new.call_undefined_class_variable
- }.should raise_error(NameError) {|e| e.receiver.should equal(NameErrorSpecs::ReceiverClass) }
- end
-
- it "returns the receiver when raised from #instance_variable_get" do
- receiver = Object.new
-
- -> {
- receiver.instance_variable_get("invalid_ivar_name")
- }.should raise_error(NameError) {|e| e.receiver.should equal(receiver) }
- end
-
- it "returns the receiver when raised from #class_variable_get" do
- -> {
- Object.class_variable_get("invalid_cvar_name")
- }.should raise_error(NameError) {|e| e.receiver.should equal(Object) }
- end
-
- it "raises an ArgumentError when the receiver is none" do
- -> { NameError.new.receiver }.should raise_error(ArgumentError)
- end
+require_relative '../../spec_helper'
+require_relative 'fixtures/common'
+
+describe "NameError#receiver" do
+ class ::ReceiverClass
+ def call_undefined_class_variable; @@doesnt_exist end
+ end
+
+ it "returns the object that raised the exception" do
+ receiver = Object.new
+
+ -> {
+ receiver.doesnt_exist
+ }.should.raise(NameError) {|e| e.receiver.should.equal?(receiver) }
+ end
+
+ it "returns the Object class when an undefined constant is called without namespace" do
+ -> {
+ DoesntExist
+ }.should.raise(NameError) {|e| e.receiver.should.equal?(Object) }
+ end
+
+ it "returns a class when an undefined constant is called" do
+ -> {
+ NameErrorSpecs::ReceiverClass::DoesntExist
+ }.should.raise(NameError) {|e| e.receiver.should.equal?(NameErrorSpecs::ReceiverClass) }
+ end
+
+ it "returns the Object class when an undefined class variable is called" do
+ -> {
+ eval("class singleton_class::A; @@doesnt_exist end", binding, __FILE__, __LINE__)
+ }.should.raise(NameError) {|e| e.receiver.should.equal?(singleton_class::A) }
+ end
+
+ it "returns a class when an undefined class variable is called in a subclass' namespace" do
+ -> {
+ NameErrorSpecs::ReceiverClass.new.call_undefined_class_variable
+ }.should.raise(NameError) {|e| e.receiver.should.equal?(NameErrorSpecs::ReceiverClass) }
+ end
+
+ it "returns the receiver when raised from #instance_variable_get" do
+ receiver = Object.new
+
+ -> {
+ receiver.instance_variable_get("invalid_ivar_name")
+ }.should.raise(NameError) {|e| e.receiver.should.equal?(receiver) }
+ end
+
+ it "returns the receiver when raised from #class_variable_get" do
+ -> {
+ Object.class_variable_get("invalid_cvar_name")
+ }.should.raise(NameError) {|e| e.receiver.should.equal?(Object) }
+ end
+
+ it "raises an ArgumentError when the receiver is none" do
+ -> { NameError.new.receiver }.should.raise(ArgumentError)
end
end
diff --git a/spec/ruby/core/exception/result_spec.rb b/spec/ruby/core/exception/result_spec.rb
index 350c071f60..451ff43af5 100644
--- a/spec/ruby/core/exception/result_spec.rb
+++ b/spec/ruby/core/exception/result_spec.rb
@@ -1,10 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "StopIteration" do
- it "is a subclass of IndexError" do
- StopIteration.superclass.should equal(IndexError)
- end
-end
+require_relative '../../spec_helper'
describe "StopIteration#result" do
before :each do
@@ -20,10 +14,8 @@ describe "StopIteration#result" do
it "returns the method-returned-object from an Enumerator" do
@enum.next
@enum.next
- lambda { @enum.next }.should(
- raise_error(StopIteration) do |error|
- error.result.should equal(:method_returned)
- end
- )
+ -> { @enum.next }.should.raise(StopIteration) { |error|
+ error.result.should.equal?(:method_returned)
+ }
end
end
diff --git a/spec/ruby/core/exception/script_error_spec.rb b/spec/ruby/core/exception/script_error_spec.rb
deleted file mode 100644
index 5ca0333261..0000000000
--- a/spec/ruby/core/exception/script_error_spec.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "ScriptError" do
- it "is a superclass of LoadError" do
- ScriptError.should be_ancestor_of(LoadError)
- end
-
- it "is a superclass of NotImplementedError" do
- ScriptError.should be_ancestor_of(NotImplementedError)
- end
-
- it "is a superclass of SyntaxError" do
- ScriptError.should be_ancestor_of(SyntaxError)
- end
-end
diff --git a/spec/ruby/core/exception/set_backtrace_spec.rb b/spec/ruby/core/exception/set_backtrace_spec.rb
index db58a193ef..2cd93326ec 100644
--- a/spec/ruby/core/exception/set_backtrace_spec.rb
+++ b/spec/ruby/core/exception/set_backtrace_spec.rb
@@ -1,56 +1,23 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/common', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/common'
+require_relative 'shared/set_backtrace'
describe "Exception#set_backtrace" do
- it "accepts an Array of Strings" do
- err = RuntimeError.new
- err.set_backtrace ["unhappy"]
- err.backtrace.should == ["unhappy"]
- end
-
it "allows the user to set the backtrace from a rescued exception" do
bt = ExceptionSpecs::Backtrace.backtrace
err = RuntimeError.new
+ err.backtrace.should == nil
+ err.backtrace_locations.should == nil
err.set_backtrace bt
- err.backtrace.should == bt
- end
-
- it "accepts an empty Array" do
- err = RuntimeError.new
- err.set_backtrace []
- err.backtrace.should == []
- end
-
- it "accepts a String" do
- err = RuntimeError.new
- err.set_backtrace "unhappy"
- err.backtrace.should == ["unhappy"]
- end
- it "accepts nil" do
- err = RuntimeError.new
- err.set_backtrace nil
- err.backtrace.should be_nil
- end
-
- it "raises a TypeError when passed a Symbol" do
- err = RuntimeError.new
- lambda { err.set_backtrace :unhappy }.should raise_error(TypeError)
+ err.backtrace.should == bt
+ err.backtrace_locations.should == nil
end
- it "raises a TypeError when the Array contains a Symbol" do
+ it_behaves_like :exception_set_backtrace, -> backtrace {
err = RuntimeError.new
- lambda { err.set_backtrace ["String", :unhappy] }.should raise_error(TypeError)
- end
-
- it "raises a TypeError when the array contains nil" do
- err = Exception.new
- lambda { err.set_backtrace ["String", nil] }.should raise_error(TypeError)
- end
-
- it "raises a TypeError when the argument is a nested array" do
- err = Exception.new
- lambda { err.set_backtrace ["String", ["String"]] }.should raise_error(TypeError)
- end
+ err.set_backtrace(backtrace)
+ err
+ }
end
diff --git a/spec/ruby/core/exception/shared/new.rb b/spec/ruby/core/exception/shared/new.rb
index bcde8ee4b2..048fd14dd2 100644
--- a/spec/ruby/core/exception/shared/new.rb
+++ b/spec/ruby/core/exception/shared/new.rb
@@ -1,6 +1,6 @@
describe :exception_new, shared: true do
it "creates a new instance of Exception" do
- Exception.should be_ancestor_of(Exception.send(@method).class)
+ Exception.send(@method).class.ancestors.should.include?(Exception)
end
it "sets the message of the Exception when passes a message" do
@@ -12,7 +12,7 @@ describe :exception_new, shared: true do
end
it "returns the exception when it has a custom constructor" do
- ExceptionSpecs::ConstructorException.send(@method).should be_kind_of(ExceptionSpecs::ConstructorException)
+ ExceptionSpecs::ConstructorException.send(@method).should.is_a?(ExceptionSpecs::ConstructorException)
end
end
diff --git a/spec/ruby/core/exception/shared/set_backtrace.rb b/spec/ruby/core/exception/shared/set_backtrace.rb
new file mode 100644
index 0000000000..934bf3dc5f
--- /dev/null
+++ b/spec/ruby/core/exception/shared/set_backtrace.rb
@@ -0,0 +1,64 @@
+require_relative '../fixtures/common'
+
+describe :exception_set_backtrace, shared: true do
+ it "accepts an Array of Strings" do
+ err = @method.call(["unhappy"])
+ err.backtrace.should == ["unhappy"]
+ end
+
+ it "allows the user to set the backtrace from a rescued exception" do
+ bt = ExceptionSpecs::Backtrace.backtrace
+ err = @method.call(bt)
+ err.backtrace.should == bt
+ end
+
+ ruby_version_is "3.4" do
+ it "allows the user to set backtrace locations from a rescued exception" do
+ bt_locations = ExceptionSpecs::Backtrace.backtrace_locations
+ err = @method.call(bt_locations)
+ err.backtrace_locations.size.should == bt_locations.size
+ err.backtrace_locations.each_with_index do |loc, index|
+ other_loc = bt_locations[index]
+
+ loc.path.should == other_loc.path
+ loc.label.should == other_loc.label
+ loc.base_label.should == other_loc.base_label
+ loc.lineno.should == other_loc.lineno
+ loc.absolute_path.should == other_loc.absolute_path
+ loc.to_s.should == other_loc.to_s
+ end
+ err.backtrace.size.should == err.backtrace_locations.size
+ end
+ end
+
+ it "accepts an empty Array" do
+ err = @method.call([])
+ err.backtrace.should == []
+ end
+
+ it "accepts a String" do
+ err = @method.call("unhappy")
+ err.backtrace.should == ["unhappy"]
+ end
+
+ it "accepts nil" do
+ err = @method.call(nil)
+ err.backtrace.should == nil
+ end
+
+ it "raises a TypeError when passed a Symbol" do
+ -> { @method.call(:unhappy) }.should.raise(TypeError)
+ end
+
+ it "raises a TypeError when the Array contains a Symbol" do
+ -> { @method.call(["String", :unhappy]) }.should.raise(TypeError)
+ end
+
+ it "raises a TypeError when the array contains nil" do
+ -> { @method.call(["String", nil]) }.should.raise(TypeError)
+ end
+
+ it "raises a TypeError when the argument is a nested array" do
+ -> { @method.call(["String", ["String"]]) }.should.raise(TypeError)
+ end
+end
diff --git a/spec/ruby/core/exception/signal_exception_spec.rb b/spec/ruby/core/exception/signal_exception_spec.rb
index 3b2d1aad61..010181bc55 100644
--- a/spec/ruby/core/exception/signal_exception_spec.rb
+++ b/spec/ruby/core/exception/signal_exception_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "SignalException.new" do
it "takes a signal number as the first argument" do
@@ -9,7 +9,7 @@ describe "SignalException.new" do
end
it "raises an exception with an invalid signal number" do
- lambda { SignalException.new(100000) }.should raise_error(ArgumentError)
+ -> { SignalException.new(100000) }.should.raise(ArgumentError)
end
it "takes a signal name without SIG prefix as the first argument" do
@@ -27,7 +27,11 @@ describe "SignalException.new" do
end
it "raises an exception with an invalid signal name" do
- lambda { SignalException.new("NONEXISTANT") }.should raise_error(ArgumentError)
+ -> { SignalException.new("NONEXISTENT") }.should.raise(ArgumentError)
+ end
+
+ it "raises an exception with an invalid first argument type" do
+ -> { SignalException.new(Object.new) }.should.raise(ArgumentError)
end
it "takes a signal symbol without SIG prefix as the first argument" do
@@ -45,7 +49,7 @@ describe "SignalException.new" do
end
it "raises an exception with an invalid signal name" do
- lambda { SignalException.new(:NONEXISTANT) }.should raise_error(ArgumentError)
+ -> { SignalException.new(:NONEXISTENT) }.should.raise(ArgumentError)
end
it "takes an optional message argument with a signal number" do
@@ -56,11 +60,11 @@ describe "SignalException.new" do
end
it "raises an exception for an optional argument with a signal name" do
- lambda { SignalException.new("INT","name") }.should raise_error(ArgumentError)
+ -> { SignalException.new("INT","name") }.should.raise(ArgumentError)
end
end
-describe "rescueing SignalException" do
+describe "rescuing SignalException" do
it "raises a SignalException when sent a signal" do
begin
Process.kill :TERM, Process.pid
@@ -72,3 +76,48 @@ describe "rescueing SignalException" do
end
end
end
+
+describe "SignalException" do
+ it "can be rescued" do
+ ruby_exe(<<-RUBY)
+ begin
+ raise SignalException, 'SIGKILL'
+ rescue SignalException
+ exit(0)
+ end
+ exit(1)
+ RUBY
+
+ $?.exitstatus.should == 0
+ end
+
+ platform_is_not :windows do
+ it "runs after at_exit" do
+ output = ruby_exe(<<-RUBY, exit_status: :SIGKILL)
+ at_exit do
+ puts "hello"
+ $stdout.flush
+ end
+
+ raise SignalException, 'SIGKILL'
+ RUBY
+
+ $?.termsig.should == Signal.list.fetch("KILL")
+ output.should == "hello\n"
+ end
+
+ it "cannot be trapped with Signal.trap" do
+ ruby_exe(<<-RUBY, exit_status: :SIGPROF)
+ Signal.trap("PROF") {}
+ raise(SignalException, "PROF")
+ RUBY
+
+ $?.termsig.should == Signal.list.fetch("PROF")
+ end
+
+ it "self-signals for USR1" do
+ ruby_exe("raise(SignalException, 'USR1')", exit_status: :SIGUSR1)
+ $?.termsig.should == Signal.list.fetch('USR1')
+ end
+ end
+end
diff --git a/spec/ruby/core/exception/signm_spec.rb b/spec/ruby/core/exception/signm_spec.rb
index e205b79e19..cabcc7ad58 100644
--- a/spec/ruby/core/exception/signm_spec.rb
+++ b/spec/ruby/core/exception/signm_spec.rb
@@ -1,5 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "SignalException#signm" do
- it "needs to be reviewed for spec completeness"
+ it "returns the signal name" do
+ -> { Process.kill(:TERM, Process.pid) }.should.raise(SignalException) { |e|
+ e.signm.should == 'SIGTERM'
+ }
+ end
end
diff --git a/spec/ruby/core/exception/signo_spec.rb b/spec/ruby/core/exception/signo_spec.rb
index 08c85274ca..46e79a8daf 100644
--- a/spec/ruby/core/exception/signo_spec.rb
+++ b/spec/ruby/core/exception/signo_spec.rb
@@ -1,5 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "SignalException#signo" do
- it "needs to be reviewed for spec completeness"
+ it "returns the signal number" do
+ -> { Process.kill(:TERM, Process.pid) }.should.raise(SignalException) { |e|
+ e.signo.should == Signal.list['TERM']
+ }
+ end
end
diff --git a/spec/ruby/core/exception/source_encoding_name_spec.rb b/spec/ruby/core/exception/source_encoding_name_spec.rb
deleted file mode 100644
index 5796072121..0000000000
--- a/spec/ruby/core/exception/source_encoding_name_spec.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Encoding::UndefinedConversionError#source_encoding_name" do
- it "needs to be reviewed for spec completeness"
-end
-
-describe "Encoding::InvalidByteSequenceError#source_encoding_name" do
- it "needs to be reviewed for spec completeness"
-end
diff --git a/spec/ruby/core/exception/source_encoding_spec.rb b/spec/ruby/core/exception/source_encoding_spec.rb
deleted file mode 100644
index 796bec88f6..0000000000
--- a/spec/ruby/core/exception/source_encoding_spec.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Encoding::UndefinedConversionError#source_encoding" do
- it "needs to be reviewed for spec completeness"
-end
-
-describe "Encoding::InvalidByteSequenceError#source_encoding" do
- it "needs to be reviewed for spec completeness"
-end
diff --git a/spec/ruby/core/exception/standard_error_spec.rb b/spec/ruby/core/exception/standard_error_spec.rb
index 9b3af4b322..b05d247f67 100644
--- a/spec/ruby/core/exception/standard_error_spec.rb
+++ b/spec/ruby/core/exception/standard_error_spec.rb
@@ -1,50 +1,23 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "StandardError" do
- it "is a superclass of ArgumentError" do
- StandardError.should be_ancestor_of(ArgumentError)
+ it "rescues StandardError" do
+ begin
+ raise StandardError
+ rescue => exception
+ exception.class.should == StandardError
+ end
end
- it "is a superclass of IOError" do
- StandardError.should be_ancestor_of(IOError)
+ it "rescues subclass of StandardError" do
+ begin
+ raise RuntimeError
+ rescue => exception
+ exception.class.should == RuntimeError
+ end
end
- it "is a superclass of IndexError" do
- StandardError.should be_ancestor_of(IndexError)
- end
-
- it "is a superclass of LocalJumpError" do
- StandardError.should be_ancestor_of(LocalJumpError)
- end
-
- it "is a superclass of NameError" do
- StandardError.should be_ancestor_of(NameError)
- end
-
- it "is a superclass of RangeError" do
- StandardError.should be_ancestor_of(RangeError)
- end
-
- it "is a superclass of RegexpError" do
- StandardError.should be_ancestor_of(RegexpError)
- end
-
- it "is a superclass of RuntimeError" do
- StandardError.should be_ancestor_of(RuntimeError)
- end
-
- it "is a superclass of SystemCallError" do
- StandardError.should be_ancestor_of(SystemCallError.new("").class)
- end
- it "is a superclass of ThreadError" do
- StandardError.should be_ancestor_of(ThreadError)
- end
-
- it "is a superclass of TypeError" do
- StandardError.should be_ancestor_of(TypeError)
- end
-
- it "is a superclass of ZeroDivisionError" do
- StandardError.should be_ancestor_of(ZeroDivisionError)
+ it "does not rescue superclass of StandardError" do
+ -> { begin; raise Exception; rescue; end }.should.raise(Exception)
end
end
diff --git a/spec/ruby/core/exception/status_spec.rb b/spec/ruby/core/exception/status_spec.rb
index e648dc0adc..7369b0815d 100644
--- a/spec/ruby/core/exception/status_spec.rb
+++ b/spec/ruby/core/exception/status_spec.rb
@@ -1,5 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "SystemExit#status" do
- it "needs to be reviewed for spec completeness"
+ it "returns the exit status" do
+ -> { exit 42 }.should.raise(SystemExit) { |e|
+ e.status.should == 42
+ }
+ end
end
diff --git a/spec/ruby/core/exception/success_spec.rb b/spec/ruby/core/exception/success_spec.rb
index d9b69b4f45..5ab8f94454 100644
--- a/spec/ruby/core/exception/success_spec.rb
+++ b/spec/ruby/core/exception/success_spec.rb
@@ -1,5 +1,15 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "SystemExit#success?" do
- it "needs to be reviewed for spec completeness"
+ it "returns true if the process exited successfully" do
+ -> { exit 0 }.should.raise(SystemExit) { |e|
+ e.should.success?
+ }
+ end
+
+ it "returns false if the process exited unsuccessfully" do
+ -> { exit(-1) }.should.raise(SystemExit) { |e|
+ e.should_not.success?
+ }
+ end
end
diff --git a/spec/ruby/core/exception/syntax_error_spec.rb b/spec/ruby/core/exception/syntax_error_spec.rb
new file mode 100644
index 0000000000..66eb5649aa
--- /dev/null
+++ b/spec/ruby/core/exception/syntax_error_spec.rb
@@ -0,0 +1,25 @@
+require_relative '../../spec_helper'
+
+describe "SyntaxError#path" do
+ it "returns the file path provided to eval" do
+ filename = "speccing.rb"
+
+ -> {
+ eval("if true", TOPLEVEL_BINDING, filename)
+ }.should.raise(SyntaxError) { |e|
+ e.path.should == filename
+ }
+ end
+
+ it "returns the file path that raised an exception" do
+ expected_path = fixture(__FILE__, "syntax_error.rb")
+
+ -> {
+ require_relative "fixtures/syntax_error"
+ }.should.raise(SyntaxError) { |e| e.path.should == expected_path }
+ end
+
+ it "returns nil when constructed directly" do
+ SyntaxError.new.path.should == nil
+ end
+end
diff --git a/spec/ruby/core/exception/system_call_error_spec.rb b/spec/ruby/core/exception/system_call_error_spec.rb
index edcc8d3734..da01c5b6b0 100644
--- a/spec/ruby/core/exception/system_call_error_spec.rb
+++ b/spec/ruby/core/exception/system_call_error_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/common', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/common'
describe "SystemCallError" do
before :each do
@@ -14,47 +14,113 @@ describe "SystemCallError" do
end
exc = ExceptionSpecs::SCESub.new
- ScratchPad.recorded.should equal(:initialize)
- exc.should be_an_instance_of(ExceptionSpecs::SCESub)
+ ScratchPad.recorded.should.equal?(:initialize)
+ exc.should.instance_of?(ExceptionSpecs::SCESub)
+ ensure
+ ExceptionSpecs.send(:remove_const, :SCESub)
end
end
describe "SystemCallError.new" do
+ before :all do
+ @example_errno = Errno::EINVAL::Errno
+ @example_errno_class = Errno::EINVAL
+ @last_known_errno = Errno.constants.size - 1
+ @unknown_errno = Errno.constants.size
+ @some_human_readable = /[[:graph:]]+/
+ end
+
it "requires at least one argument" do
- lambda { SystemCallError.new }.should raise_error(ArgumentError)
+ -> { SystemCallError.new }.should.raise(ArgumentError)
end
- it "accepts single Fixnum argument as errno" do
+ it "accepts single Integer argument as errno" do
SystemCallError.new(-2**24).errno.should == -2**24
- SystemCallError.new(42).errno.should == 42
+ SystemCallError.new(-1).errno.should == -1
+ SystemCallError.new(0).errno.should == 0
+ SystemCallError.new(@last_known_errno).errno.should == @last_known_errno
+ SystemCallError.new(@unknown_errno).errno.should == @unknown_errno
SystemCallError.new(2**24).errno.should == 2**24
end
+ it "constructs a SystemCallError for an unknown error number" do
+ SystemCallError.new(-2**24).should.instance_of?(SystemCallError)
+ SystemCallError.new(-1).should.instance_of?(SystemCallError)
+ SystemCallError.new(@unknown_errno).should.instance_of?(SystemCallError)
+ SystemCallError.new(2**24).should.instance_of?(SystemCallError)
+ end
+
it "constructs the appropriate Errno class" do
- # EINVAL should be more or less mortable across the platforms,
- # so let's use it then.
- SystemCallError.new(22).should be_kind_of(SystemCallError)
- SystemCallError.new(22).should be_an_instance_of(Errno::EINVAL)
- SystemCallError.new(2**28).should be_an_instance_of(SystemCallError)
+ e = SystemCallError.new(@example_errno)
+ e.should.is_a?(SystemCallError)
+ e.should.instance_of?(@example_errno_class)
+ end
+
+ it "sets an error message corresponding to an appropriate Errno class" do
+ e = SystemCallError.new(@example_errno)
+ e.message.should == 'Invalid argument'
end
it "accepts an optional custom message preceding the errno" do
- exc = SystemCallError.new("custom message", 22)
- exc.should be_an_instance_of(Errno::EINVAL)
- exc.errno.should == 22
- exc.message.should == "Invalid argument - custom message"
+ exc = SystemCallError.new("custom message", @example_errno)
+ exc.should.instance_of?(@example_errno_class)
+ exc.errno.should == @example_errno
+ exc.message.should == 'Invalid argument - custom message'
end
it "accepts an optional third argument specifying the location" do
- exc = SystemCallError.new("custom message", 22, "location")
- exc.should be_an_instance_of(Errno::EINVAL)
- exc.errno.should == 22
- exc.message.should == "Invalid argument @ location - custom message"
+ exc = SystemCallError.new("custom message", @example_errno, "location")
+ exc.should.instance_of?(@example_errno_class)
+ exc.errno.should == @example_errno
+ exc.message.should == 'Invalid argument @ location - custom message'
+ end
+
+ it "coerces location if it is not a String" do
+ e = SystemCallError.new('foo', 1, :not_a_string)
+ e.message.should =~ /@ not_a_string - foo/
end
it "returns an arity of -1 for the initialize method" do
SystemCallError.instance_method(:initialize).arity.should == -1
end
+
+ it "converts to Integer if errno is a Float" do
+ SystemCallError.new('foo', 2.0).should == SystemCallError.new('foo', 2)
+ SystemCallError.new('foo', 2.9).should == SystemCallError.new('foo', 2)
+ end
+
+ it "treats nil errno as unknown error value" do
+ SystemCallError.new(nil).should.instance_of?(SystemCallError)
+ end
+
+ it "treats nil custom message as if it is not passed at all" do
+ exc = SystemCallError.new(nil, @example_errno)
+ exc.message.should == 'Invalid argument'
+ end
+
+ it "sets an 'unknown error' message when an unknown error number" do
+ SystemCallError.new(-1).message.should =~ @some_human_readable
+ end
+
+ it "adds a custom error message to an 'unknown error' message when an unknown error number and a custom message specified" do
+ SystemCallError.new("custom message", -1).message.should =~ /#{@some_human_readable}.* - custom message/
+ end
+
+ it "converts to Integer if errno is a Complex convertible to Integer" do
+ SystemCallError.new('foo', Complex(2.9, 0)).should == SystemCallError.new('foo', 2)
+ end
+
+ it "raises TypeError if message is not a String" do
+ -> { SystemCallError.new(:foo, 1) }.should.raise(TypeError, /no implicit conversion of Symbol into String/)
+ end
+
+ it "raises TypeError if errno is not an Integer" do
+ -> { SystemCallError.new('foo', 'bar') }.should.raise(TypeError, /no implicit conversion of String into Integer/)
+ end
+
+ it "raises RangeError if errno is a Complex not convertible to Integer" do
+ -> { SystemCallError.new('foo', Complex(2.9, 1)) }.should.raise(RangeError, /can't convert/)
+ end
end
describe "SystemCallError#errno" do
@@ -74,12 +140,7 @@ end
describe "SystemCallError#message" do
it "returns the default message when no message is given" do
- platform_is :aix do
- SystemCallError.new(2**28).message.should =~ /Error .*occurred/i
- end
- platform_is_not :aix do
- SystemCallError.new(2**28).message.should =~ /Unknown error/i
- end
+ SystemCallError.new(2**28).message.should =~ @some_human_readable
end
it "returns the message given as an argument to new" do
@@ -87,3 +148,16 @@ describe "SystemCallError#message" do
SystemCallError.new("XXX").message.should =~ /XXX/
end
end
+
+describe "SystemCallError#dup" do
+ it "copies the errno" do
+ dup_sce = SystemCallError.new("message", 42).dup
+ dup_sce.errno.should == 42
+ end
+end
+
+describe "SystemCallError#backtrace" do
+ it "is nil if not raised" do
+ SystemCallError.new("message", 42).backtrace.should == nil
+ end
+end
diff --git a/spec/ruby/core/exception/system_exit_spec.rb b/spec/ruby/core/exception/system_exit_spec.rb
new file mode 100644
index 0000000000..d899844c4e
--- /dev/null
+++ b/spec/ruby/core/exception/system_exit_spec.rb
@@ -0,0 +1,59 @@
+require_relative '../../spec_helper'
+
+describe "SystemExit" do
+ describe "#initialize" do
+ it "accepts a status and message" do
+ exc = SystemExit.new(42, "message")
+ exc.status.should == 42
+ exc.message.should == "message"
+
+ exc = SystemExit.new(true, "message")
+ exc.status.should == 0
+ exc.message.should == "message"
+
+ exc = SystemExit.new(false, "message")
+ exc.status.should == 1
+ exc.message.should == "message"
+ end
+
+ it "accepts a status only" do
+ exc = SystemExit.new(42)
+ exc.status.should == 42
+ exc.message.should == "SystemExit"
+
+ exc = SystemExit.new(true)
+ exc.status.should == 0
+ exc.message.should == "SystemExit"
+
+ exc = SystemExit.new(false)
+ exc.status.should == 1
+ exc.message.should == "SystemExit"
+ end
+
+ it "accepts a message only" do
+ exc = SystemExit.new("message")
+ exc.status.should == 0
+ exc.message.should == "message"
+ end
+
+ it "accepts no arguments" do
+ exc = SystemExit.new
+ exc.status.should == 0
+ exc.message.should == "SystemExit"
+ end
+ end
+
+ it "sets the exit status and exits silently when raised" do
+ code = 'raise SystemExit.new(7)'
+ result = ruby_exe(code, args: "2>&1", exit_status: 7)
+ result.should == ""
+ $?.exitstatus.should == 7
+ end
+
+ it "sets the exit status and exits silently when raised when subclassed" do
+ code = 'class CustomExit < SystemExit; end; raise CustomExit.new(8)'
+ result = ruby_exe(code, args: "2>&1", exit_status: 8)
+ result.should == ""
+ $?.exitstatus.should == 8
+ end
+end
diff --git a/spec/ruby/core/exception/system_stack_error_spec.rb b/spec/ruby/core/exception/system_stack_error_spec.rb
deleted file mode 100644
index acd56c0a0f..0000000000
--- a/spec/ruby/core/exception/system_stack_error_spec.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "SystemStackError" do
- it "is a subclass of Exception" do
- SystemStackError.superclass.should == Exception
- end
-end
diff --git a/spec/ruby/core/exception/to_s_spec.rb b/spec/ruby/core/exception/to_s_spec.rb
index 83234bfe23..65c0d73a98 100644
--- a/spec/ruby/core/exception/to_s_spec.rb
+++ b/spec/ruby/core/exception/to_s_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/common', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/common'
describe "Exception#to_s" do
it "returns the self's name if no message is set" do
@@ -19,5 +19,19 @@ describe "Exception#to_s" do
end
describe "NameError#to_s" do
- it "needs to be reviewed for spec completeness"
+ it "raises its own message for an undefined variable" do
+ begin
+ puts not_defined
+ rescue => exception
+ exception.message.should =~ /undefined local variable or method [`']not_defined'/
+ end
+ end
+
+ it "raises its own message for an undefined constant" do
+ begin
+ puts NotDefined
+ rescue => exception
+ exception.message.should =~ /uninitialized constant NotDefined/
+ end
+ end
end
diff --git a/spec/ruby/core/exception/top_level_spec.rb b/spec/ruby/core/exception/top_level_spec.rb
new file mode 100644
index 0000000000..cc961d06d5
--- /dev/null
+++ b/spec/ruby/core/exception/top_level_spec.rb
@@ -0,0 +1,65 @@
+require_relative '../../spec_helper'
+
+describe "An Exception reaching the top level" do
+ it "is printed on STDERR" do
+ ruby_exe('raise "foo"', args: "2>&1", exit_status: 1).should =~ /in [`']<main>': foo \(RuntimeError\)/
+ end
+
+ it "the Exception#cause is printed to STDERR with backtraces" do
+ code = <<-RUBY
+ def raise_cause
+ raise "the cause" # 2
+ end
+ def raise_wrapped
+ raise "wrapped" # 5
+ end
+ begin
+ raise_cause # 8
+ rescue
+ raise_wrapped # 10
+ end
+ RUBY
+ lines = ruby_exe(code, args: "2>&1", exit_status: 1).lines
+
+ lines.map! { |l| l.chomp[/:(\d+:in.+)/, 1] }
+ lines[0].should =~ /\A5:in [`'](?:Object#)?raise_wrapped': wrapped \(RuntimeError\)\z/
+ if lines[1].include? 'rescue in'
+ # CRuby < 3.4 has an extra 'rescue in' backtrace entry
+ lines[1].should =~ /\A10:in [`']rescue in <main>'\z/
+ lines.delete_at 1
+ lines[1].should =~ /\A7:in [`']<main>'\z/
+ else
+ lines[1].should =~ /\A10:in [`']<main>'\z/
+ end
+ lines[2].should =~ /\A2:in [`'](?:Object#)?raise_cause': the cause \(RuntimeError\)\z/
+ lines[3].should =~ /\A8:in [`']<main>'\z/
+ lines.size.should == 4
+ end
+
+ describe "with a custom backtrace" do
+ it "is printed on STDERR" do
+ code = <<-RUBY
+ raise RuntimeError, "foo", [
+ "/dir/foo.rb:10:in `raising'",
+ "/dir/bar.rb:20:in `caller'",
+ ]
+ RUBY
+ ruby_exe(code, args: "2>&1", exit_status: 1).should == <<-EOS
+/dir/foo.rb:10:in `raising': foo (RuntimeError)
+\tfrom /dir/bar.rb:20:in `caller'
+ EOS
+ end
+ end
+
+ describe "kills all threads and fibers, ensure clauses are only run for threads current fibers, not for suspended fibers" do
+ it "with ensure on the root fiber" do
+ file = fixture(__FILE__, "thread_fiber_ensure.rb")
+ ruby_exe(file, args: "2>&1", exit_status: 0).should == "current fiber ensure\n"
+ end
+
+ it "with ensure on non-root fiber" do
+ file = fixture(__FILE__, "thread_fiber_ensure_non_root_fiber.rb")
+ ruby_exe(file, args: "2>&1", exit_status: 0).should == "current fiber ensure\n"
+ end
+ end
+end
diff --git a/spec/ruby/core/exception/uncaught_throw_error_spec.rb b/spec/ruby/core/exception/uncaught_throw_error_spec.rb
index 3ed166af5b..9267df6670 100644
--- a/spec/ruby/core/exception/uncaught_throw_error_spec.rb
+++ b/spec/ruby/core/exception/uncaught_throw_error_spec.rb
@@ -1,10 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "UncaughtThrowError" do
- it "is a subclass of ArgumentError" do
- ArgumentError.should be_ancestor_of(UncaughtThrowError)
- end
-end
+require_relative '../../spec_helper'
describe "UncaughtThrowError#tag" do
it "returns the object thrown" do
@@ -16,4 +10,3 @@ describe "UncaughtThrowError#tag" do
end
end
end
-
diff --git a/spec/ruby/core/false/and_spec.rb b/spec/ruby/core/false/and_spec.rb
index a949c02503..0b02ae62c5 100644
--- a/spec/ruby/core/false/and_spec.rb
+++ b/spec/ruby/core/false/and_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "FalseClass#&" do
it "returns false" do
diff --git a/spec/ruby/core/false/case_compare_spec.rb b/spec/ruby/core/false/case_compare_spec.rb
new file mode 100644
index 0000000000..0bd0ab44ae
--- /dev/null
+++ b/spec/ruby/core/false/case_compare_spec.rb
@@ -0,0 +1,14 @@
+require_relative '../../spec_helper'
+
+describe "FalseClass#===" do
+ it "returns true for false" do
+ (false === false).should == true
+ end
+
+ it "returns false for non-false object" do
+ (false === 0).should == false
+ (false === "").should == false
+ (false === Object).should == false
+ (false === nil).should == false
+ end
+end
diff --git a/spec/ruby/core/false/dup_spec.rb b/spec/ruby/core/false/dup_spec.rb
index b04e641a41..b0eb85529e 100644
--- a/spec/ruby/core/false/dup_spec.rb
+++ b/spec/ruby/core/false/dup_spec.rb
@@ -1,9 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
-ruby_version_is '2.4' do
- describe "FalseClass#dup" do
- it "returns self" do
- false.dup.should equal(false)
- end
+describe "FalseClass#dup" do
+ it "returns self" do
+ false.dup.should.equal?(false)
end
end
diff --git a/spec/ruby/core/false/falseclass_spec.rb b/spec/ruby/core/false/falseclass_spec.rb
index e91682c94c..8dfe5ae891 100644
--- a/spec/ruby/core/false/falseclass_spec.rb
+++ b/spec/ruby/core/false/falseclass_spec.rb
@@ -1,15 +1,15 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "FalseClass" do
it ".allocate raises a TypeError" do
- lambda do
+ -> do
FalseClass.allocate
- end.should raise_error(TypeError)
+ end.should.raise(TypeError)
end
it ".new is undefined" do
- lambda do
+ -> do
FalseClass.new
- end.should raise_error(NoMethodError)
+ end.should.raise(NoMethodError)
end
end
diff --git a/spec/ruby/core/false/inspect_spec.rb b/spec/ruby/core/false/inspect_spec.rb
index f3bb6645bf..70f4aa0159 100644
--- a/spec/ruby/core/false/inspect_spec.rb
+++ b/spec/ruby/core/false/inspect_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "FalseClass#inspect" do
- it "returns the string 'false'" do
- false.inspect.should == "false"
+ it "is an alias of FalseClass#to_s" do
+ false.method(:inspect).should == false.method(:to_s)
end
end
diff --git a/spec/ruby/core/false/or_spec.rb b/spec/ruby/core/false/or_spec.rb
index e2f4dbd90b..f3ee1a3439 100644
--- a/spec/ruby/core/false/or_spec.rb
+++ b/spec/ruby/core/false/or_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "FalseClass#|" do
it "returns false if other is nil or false, otherwise true" do
diff --git a/spec/ruby/core/false/singleton_method_spec.rb b/spec/ruby/core/false/singleton_method_spec.rb
new file mode 100644
index 0000000000..72aee8609a
--- /dev/null
+++ b/spec/ruby/core/false/singleton_method_spec.rb
@@ -0,0 +1,13 @@
+require_relative '../../spec_helper'
+
+describe "FalseClass#singleton_method" do
+ it "raises regardless of whether FalseClass defines the method" do
+ -> { false.singleton_method(:foo) }.should.raise(NameError)
+ begin
+ def (false).foo; end
+ -> { false.singleton_method(:foo) }.should.raise(NameError)
+ ensure
+ FalseClass.send(:remove_method, :foo)
+ end
+ end
+end
diff --git a/spec/ruby/core/false/to_s_spec.rb b/spec/ruby/core/false/to_s_spec.rb
index bb2bdb65af..9e24be26a2 100644
--- a/spec/ruby/core/false/to_s_spec.rb
+++ b/spec/ruby/core/false/to_s_spec.rb
@@ -1,7 +1,15 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "FalseClass#to_s" do
it "returns the string 'false'" do
false.to_s.should == "false"
end
+
+ it "returns a frozen string" do
+ false.to_s.should.frozen?
+ end
+
+ it "always returns the same string" do
+ false.to_s.should.equal?(false.to_s)
+ end
end
diff --git a/spec/ruby/core/false/xor_spec.rb b/spec/ruby/core/false/xor_spec.rb
index 3e5c452f9b..d8432ca326 100644
--- a/spec/ruby/core/false/xor_spec.rb
+++ b/spec/ruby/core/false/xor_spec.rb
@@ -1,11 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "FalseClass#^" do
- it "returns false if other is nil or false, otherwise true" do
- (false ^ false).should == false
- (false ^ true).should == true
- (false ^ nil).should == false
- (false ^ "").should == true
- (false ^ mock('x')).should == true
+ it "is an alias of FalseClass#|" do
+ false.method(:^).should == false.method(:|)
end
end
diff --git a/spec/ruby/core/fiber/alive_spec.rb b/spec/ruby/core/fiber/alive_spec.rb
new file mode 100644
index 0000000000..6fb1229d95
--- /dev/null
+++ b/spec/ruby/core/fiber/alive_spec.rb
@@ -0,0 +1,44 @@
+require_relative '../../spec_helper'
+
+describe "Fiber#alive?" do
+ it "returns true for a Fiber that hasn't had #resume called" do
+ fiber = Fiber.new { true }
+ fiber.alive?.should == true
+ end
+
+ # FIXME: Better description?
+ it "returns true for a Fiber that's yielded to the caller" do
+ fiber = Fiber.new { Fiber.yield }
+ fiber.resume
+ fiber.alive?.should == true
+ end
+
+ it "returns true when called from its Fiber" do
+ fiber = Fiber.new { fiber.alive?.should == true }
+ fiber.resume
+ end
+
+ it "doesn't invoke the block associated with the Fiber" do
+ offthehook = mock('do not call')
+ offthehook.should_not_receive(:ring)
+ fiber = Fiber.new { offthehook.ring }
+ fiber.alive?
+ end
+
+ it "returns false for a Fiber that's dead" do
+ fiber = Fiber.new { true }
+ fiber.resume
+ -> { fiber.resume }.should.raise(FiberError)
+ fiber.alive?.should == false
+ end
+
+ it "always returns false for a dead Fiber" do
+ fiber = Fiber.new { true }
+ fiber.resume
+ -> { fiber.resume }.should.raise(FiberError)
+ fiber.alive?.should == false
+ -> { fiber.resume }.should.raise(FiberError)
+ fiber.alive?.should == false
+ fiber.alive?.should == false
+ end
+end
diff --git a/spec/ruby/core/fiber/blocking_spec.rb b/spec/ruby/core/fiber/blocking_spec.rb
new file mode 100644
index 0000000000..d5caf81fbe
--- /dev/null
+++ b/spec/ruby/core/fiber/blocking_spec.rb
@@ -0,0 +1,73 @@
+require_relative '../../spec_helper'
+require_relative 'shared/blocking'
+
+describe "Fiber.blocking?" do
+ it_behaves_like :non_blocking_fiber, -> { Fiber.blocking? }
+
+ context "when fiber is blocking" do
+ context "root Fiber of the main thread" do
+ it "returns 1 for blocking: true" do
+ fiber = Fiber.new(blocking: true) { Fiber.blocking? }
+ blocking = fiber.resume
+
+ blocking.should == 1
+ end
+ end
+
+ context "root Fiber of a new thread" do
+ it "returns 1 for blocking: true" do
+ thread = Thread.new do
+ fiber = Fiber.new(blocking: true) { Fiber.blocking? }
+ blocking = fiber.resume
+
+ blocking.should == 1
+ end
+
+ thread.join
+ end
+ end
+ end
+end
+
+describe "Fiber#blocking?" do
+ it_behaves_like :non_blocking_fiber, -> { Fiber.current.blocking? }
+
+ context "when fiber is blocking" do
+ context "root Fiber of the main thread" do
+ it "returns true for blocking: true" do
+ fiber = Fiber.new(blocking: true) { Fiber.current.blocking? }
+ blocking = fiber.resume
+
+ blocking.should == true
+ end
+ end
+
+ context "root Fiber of a new thread" do
+ it "returns true for blocking: true" do
+ thread = Thread.new do
+ fiber = Fiber.new(blocking: true) { Fiber.current.blocking? }
+ blocking = fiber.resume
+
+ blocking.should == true
+ end
+
+ thread.join
+ end
+ end
+ end
+end
+
+describe "Fiber.blocking" do
+ context "when fiber is non-blocking" do
+ it "can become blocking" do
+ fiber = Fiber.new(blocking: false) do
+ Fiber.blocking do |f|
+ f.blocking? ? :blocking : :non_blocking
+ end
+ end
+
+ blocking = fiber.resume
+ blocking.should == :blocking
+ end
+ end
+end
diff --git a/spec/ruby/core/fiber/current_spec.rb b/spec/ruby/core/fiber/current_spec.rb
new file mode 100644
index 0000000000..cc5c9117b6
--- /dev/null
+++ b/spec/ruby/core/fiber/current_spec.rb
@@ -0,0 +1,50 @@
+require_relative '../../spec_helper'
+
+describe "Fiber.current" do
+ it "returns the root Fiber when called outside of a Fiber" do
+ root = Fiber.current
+ root.should.instance_of?(Fiber)
+ # We can always transfer to the root Fiber; it will never die
+ 5.times do
+ root.transfer.should == nil
+ root.alive?.should == true
+ end
+ end
+
+ it "returns the current Fiber when called from a Fiber" do
+ fiber = Fiber.new do
+ this = Fiber.current
+ this.should.instance_of?(Fiber)
+ this.should == fiber
+ this.alive?.should == true
+ end
+ fiber.resume
+ end
+
+ it "returns the current Fiber when called from a Fiber that transferred to another" do
+ states = []
+ fiber = Fiber.new do
+ states << :fiber
+ this = Fiber.current
+ this.should.instance_of?(Fiber)
+ this.should == fiber
+ this.alive?.should == true
+ end
+
+ fiber2 = Fiber.new do
+ states << :fiber2
+ fiber.transfer
+ flunk
+ end
+
+ fiber3 = Fiber.new do
+ states << :fiber3
+ fiber2.transfer
+ states << :fiber3_terminated
+ end
+
+ fiber3.resume
+
+ states.should == [:fiber3, :fiber2, :fiber, :fiber3_terminated]
+ end
+end
diff --git a/spec/ruby/core/fiber/fixtures/classes.rb b/spec/ruby/core/fiber/fixtures/classes.rb
new file mode 100644
index 0000000000..6b0e0fbc42
--- /dev/null
+++ b/spec/ruby/core/fiber/fixtures/classes.rb
@@ -0,0 +1,22 @@
+module FiberSpecs
+
+ class NewFiberToRaise
+ def self.raise(*args, **kwargs, &block)
+ fiber = Fiber.new do
+ if block_given?
+ block.call do
+ Fiber.yield
+ end
+ else
+ Fiber.yield
+ end
+ end
+
+ fiber.resume
+
+ fiber.raise(*args, **kwargs)
+ end
+ end
+
+ class CustomError < StandardError; end
+end
diff --git a/spec/ruby/core/fiber/fixtures/scheduler.rb b/spec/ruby/core/fiber/fixtures/scheduler.rb
new file mode 100644
index 0000000000..16bd2f6b44
--- /dev/null
+++ b/spec/ruby/core/fiber/fixtures/scheduler.rb
@@ -0,0 +1,35 @@
+module FiberSpecs
+
+ class LoggingScheduler
+ attr_reader :events
+ def initialize
+ @events = []
+ end
+
+ def block(*args)
+ @events << { event: :block, fiber: Fiber.current, args: args }
+ Fiber.yield
+ end
+
+ def io_wait(*args)
+ @events << { event: :io_wait, fiber: Fiber.current, args: args }
+ Fiber.yield
+ end
+
+ def kernel_sleep(*args)
+ @events << { event: :kernel_sleep, fiber: Fiber.current, args: args }
+ Fiber.yield
+ end
+
+ def unblock(*args)
+ @events << { event: :unblock, fiber: Fiber.current, args: args }
+ Fiber.yield
+ end
+
+ def fiber_interrupt(*args)
+ @events << { event: :fiber_interrupt, fiber: Fiber.current, args: args }
+ Fiber.yield
+ end
+ end
+
+end
diff --git a/spec/ruby/core/fiber/inspect_spec.rb b/spec/ruby/core/fiber/inspect_spec.rb
new file mode 100644
index 0000000000..fcfef20716
--- /dev/null
+++ b/spec/ruby/core/fiber/inspect_spec.rb
@@ -0,0 +1,35 @@
+require_relative '../../spec_helper'
+
+describe "Fiber#inspect" do
+ describe "status" do
+ it "is resumed for the root Fiber of a Thread" do
+ inspected = Thread.new { Fiber.current.inspect }.value
+ inspected.should =~ /\A#<Fiber:0x\h+ .*\(resumed\)>\z/
+ end
+
+ it "is created for a Fiber which did not run yet" do
+ inspected = Fiber.new {}.inspect
+ inspected.should =~ /\A#<Fiber:0x\h+ .+ \(created\)>\z/
+ end
+
+ it "is resumed for a Fiber which was resumed" do
+ inspected = Fiber.new { Fiber.current.inspect }.resume
+ inspected.should =~ /\A#<Fiber:0x\h+ .+ \(resumed\)>\z/
+ end
+
+ it "is resumed for a Fiber which was transferred" do
+ inspected = Fiber.new { Fiber.current.inspect }.transfer
+ inspected.should =~ /\A#<Fiber:0x\h+ .+ \(resumed\)>\z/
+ end
+
+ it "is suspended for a Fiber which was resumed and yielded" do
+ inspected = Fiber.new { Fiber.yield }.tap(&:resume).inspect
+ inspected.should =~ /\A#<Fiber:0x\h+ .+ \(suspended\)>\z/
+ end
+
+ it "is terminated for a Fiber which has terminated" do
+ inspected = Fiber.new {}.tap(&:resume).inspect
+ inspected.should =~ /\A#<Fiber:0x\h+ .+ \(terminated\)>\z/
+ end
+ end
+end
diff --git a/spec/ruby/core/fiber/kill_spec.rb b/spec/ruby/core/fiber/kill_spec.rb
new file mode 100644
index 0000000000..abf23ff176
--- /dev/null
+++ b/spec/ruby/core/fiber/kill_spec.rb
@@ -0,0 +1,88 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative '../../shared/kernel/raise'
+
+describe "Fiber#kill" do
+ it "kills a non-resumed fiber" do
+ fiber = Fiber.new{}
+
+ fiber.alive?.should == true
+
+ fiber.kill
+ fiber.alive?.should == false
+ end
+
+ it "kills a resumed fiber" do
+ fiber = Fiber.new{while true; Fiber.yield; end}
+ fiber.resume
+
+ fiber.alive?.should == true
+
+ fiber.kill
+ fiber.alive?.should == false
+ end
+
+ it "can kill itself" do
+ fiber = Fiber.new do
+ Fiber.current.kill
+ end
+
+ fiber.alive?.should == true
+
+ fiber.resume
+ fiber.alive?.should == false
+ end
+
+ it "kills a resumed fiber from a child" do
+ parent = Fiber.new do
+ child = Fiber.new do
+ parent.kill
+ parent.alive?.should == true
+ end
+
+ child.resume
+ end
+
+ parent.resume
+ parent.alive?.should == false
+ end
+
+ it "executes the ensure block" do
+ ensure_executed = false
+
+ fiber = Fiber.new do
+ while true; Fiber.yield; end
+ ensure
+ ensure_executed = true
+ end
+
+ fiber.resume
+ fiber.kill
+ ensure_executed.should == true
+ end
+
+ it "does not execute rescue block" do
+ rescue_executed = false
+
+ fiber = Fiber.new do
+ while true; Fiber.yield; end
+ rescue Exception
+ rescue_executed = true
+ end
+
+ fiber.resume
+ fiber.kill
+ rescue_executed.should == false
+ end
+
+ it "repeatedly kills a fiber" do
+ fiber = Fiber.new do
+ while true; Fiber.yield; end
+ ensure
+ while true; Fiber.yield; end
+ end
+
+ fiber.kill
+ fiber.alive?.should == false
+ end
+end
diff --git a/spec/ruby/core/fiber/new_spec.rb b/spec/ruby/core/fiber/new_spec.rb
index a3361acc65..d31167496d 100644
--- a/spec/ruby/core/fiber/new_spec.rb
+++ b/spec/ruby/core/fiber/new_spec.rb
@@ -1,41 +1,39 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
-with_feature :fiber do
- describe "Fiber.new" do
- it "creates a fiber from the given block" do
- fiber = Fiber.new {}
- fiber.resume
- fiber.should be_an_instance_of(Fiber)
- end
+describe "Fiber.new" do
+ it "creates a fiber from the given block" do
+ fiber = Fiber.new {}
+ fiber.resume
+ fiber.should.instance_of?(Fiber)
+ end
- it "creates a fiber from a subclass" do
- class MyFiber < Fiber
- end
- fiber = MyFiber.new {}
- fiber.resume
- fiber.should be_an_instance_of(MyFiber)
+ it "creates a fiber from a subclass" do
+ class MyFiber < Fiber
end
+ fiber = MyFiber.new {}
+ fiber.resume
+ fiber.should.instance_of?(MyFiber)
+ end
- it "raises an ArgumentError if called without a block" do
- lambda { Fiber.new }.should raise_error(ArgumentError)
- end
+ it "raises an ArgumentError if called without a block" do
+ -> { Fiber.new }.should.raise(ArgumentError)
+ end
- it "does not invoke the block" do
- invoked = false
- fiber = Fiber.new { invoked = true }
- invoked.should be_false
- fiber.resume
- end
+ it "does not invoke the block" do
+ invoked = false
+ fiber = Fiber.new { invoked = true }
+ invoked.should == false
+ fiber.resume
+ end
- it "closes over lexical environments" do
- o = Object.new
- def o.f
- a = 1
- f = Fiber.new { a = 2 }
- f.resume
- a
- end
- o.f.should == 2
+ it "closes over lexical environments" do
+ o = Object.new
+ def o.f
+ a = 1
+ f = Fiber.new { a = 2 }
+ f.resume
+ a
end
+ o.f.should == 2
end
end
diff --git a/spec/ruby/core/fiber/raise_spec.rb b/spec/ruby/core/fiber/raise_spec.rb
new file mode 100644
index 0000000000..107e5bd4ce
--- /dev/null
+++ b/spec/ruby/core/fiber/raise_spec.rb
@@ -0,0 +1,141 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative '../../shared/kernel/raise'
+
+describe "Fiber#raise" do
+ it "is a public method" do
+ Fiber.public_instance_methods.should.include?(:raise)
+ end
+
+ it_behaves_like :kernel_raise, :raise, FiberSpecs::NewFiberToRaise
+ it_behaves_like :kernel_raise_across_contexts, :raise, FiberSpecs::NewFiberToRaise
+ ruby_version_is "4.0" do
+ it_behaves_like :kernel_raise_with_cause, :raise, FiberSpecs::NewFiberToRaise
+ end
+
+ it 'raises RuntimeError by default' do
+ -> { FiberSpecs::NewFiberToRaise.raise }.should.raise(RuntimeError)
+ end
+
+ it "raises FiberError if Fiber is not born" do
+ fiber = Fiber.new { true }
+ -> { fiber.raise }.should.raise(FiberError, "cannot raise exception on unborn fiber")
+ end
+
+ it "raises FiberError if Fiber is dead" do
+ fiber = Fiber.new { true }
+ fiber.resume
+ -> { fiber.raise }.should.raise(FiberError, /dead fiber called|attempt to resume a terminated fiber/)
+ end
+
+ it 'accepts error class' do
+ -> { FiberSpecs::NewFiberToRaise.raise FiberSpecs::CustomError }.should.raise(FiberSpecs::CustomError)
+ end
+
+ it 'accepts error message' do
+ -> { FiberSpecs::NewFiberToRaise.raise "error message" }.should.raise(RuntimeError, "error message")
+ end
+
+ it 'does not accept array of backtrace information only' do
+ -> { FiberSpecs::NewFiberToRaise.raise ['foo'] }.should.raise(TypeError)
+ end
+
+ it 'does not accept integer' do
+ -> { FiberSpecs::NewFiberToRaise.raise 100 }.should.raise(TypeError)
+ end
+
+ it 'accepts error class with error message' do
+ -> { FiberSpecs::NewFiberToRaise.raise FiberSpecs::CustomError, 'test error' }.should.raise(FiberSpecs::CustomError, 'test error')
+ end
+
+ it 'accepts error class with error message and backtrace information' do
+ -> {
+ FiberSpecs::NewFiberToRaise.raise FiberSpecs::CustomError, 'test error', ['foo', 'boo']
+ }.should.raise(FiberSpecs::CustomError) { |e|
+ e.message.should == 'test error'
+ e.backtrace.should == ['foo', 'boo']
+ }
+ end
+
+ it 'does not accept only error message and backtrace information' do
+ -> { FiberSpecs::NewFiberToRaise.raise 'test error', ['foo', 'boo'] }.should.raise(TypeError)
+ end
+
+ it "raises a FiberError if invoked from a different Thread" do
+ fiber = Fiber.new { Fiber.yield }
+ fiber.resume
+ Thread.new do
+ -> {
+ fiber.raise
+ }.should.raise(FiberError, "fiber called across threads")
+ end.join
+ end
+
+ it "kills Fiber" do
+ fiber = Fiber.new { Fiber.yield :first; :second }
+ fiber.resume
+ -> { fiber.raise }.should.raise
+ -> { fiber.resume }.should.raise(FiberError, /dead fiber called|attempt to resume a terminated fiber/)
+ end
+
+ it "returns to calling fiber after raise" do
+ fiber_one = Fiber.new do
+ Fiber.yield :yield_one
+ :unreachable
+ end
+
+ fiber_two = Fiber.new do
+ results = []
+ results << fiber_one.resume
+ begin
+ fiber_one.raise
+ rescue
+ results << :rescued
+ end
+ results
+ end
+
+ fiber_two.resume.should == [:yield_one, :rescued]
+ end
+
+ ruby_version_is "3.4" do
+ it "raises on the resumed fiber" do
+ root_fiber = Fiber.current
+ f1 = Fiber.new { root_fiber.transfer }
+ f2 = Fiber.new { f1.resume }
+ f2.transfer
+
+ -> do
+ f2.raise(RuntimeError, "Expected error")
+ end.should.raise(RuntimeError, "Expected error")
+ end
+
+ it "raises on itself" do
+ -> do
+ Fiber.current.raise(RuntimeError, "Expected error")
+ end.should.raise(RuntimeError, "Expected error")
+ end
+
+ it "should raise on parent fiber" do
+ f2 = nil
+ f1 = Fiber.new do
+ # This is equivalent to Kernel#raise:
+ f2.raise(RuntimeError, "Expected error")
+ end
+ f2 = Fiber.new do
+ f1.resume
+ end
+
+ -> do
+ f2.resume
+ end.should.raise(RuntimeError, "Expected error")
+ end
+ end
+
+ it "transfers and raises on a transferring fiber" do
+ root = Fiber.current
+ fiber = Fiber.new { root.transfer }
+ fiber.transfer
+ -> { fiber.raise "msg" }.should.raise(RuntimeError, "msg")
+ end
+end
diff --git a/spec/ruby/core/fiber/resume_spec.rb b/spec/ruby/core/fiber/resume_spec.rb
index 3fd3aed8fa..e183cc10d9 100644
--- a/spec/ruby/core/fiber/resume_spec.rb
+++ b/spec/ruby/core/fiber/resume_spec.rb
@@ -1,54 +1,83 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/fiber/resume', __FILE__)
-
-with_feature :fiber do
- describe "Fiber#resume" do
- it_behaves_like :fiber_resume, :resume
- end
-
- describe "Fiber#resume" do
- it "returns control to the calling Fiber if called from one" do
- fiber1 = Fiber.new { :fiber1 }
- fiber2 = Fiber.new { fiber1.resume; :fiber2 }
- fiber2.resume.should == :fiber2
- end
-
- with_feature :fork do
- # Redmine #595
- it "executes the ensure clause" do
- rd, wr = IO.pipe
-
- pid = Kernel::fork do
- rd.close
- f = Fiber.new do
- begin
- Fiber.yield
- ensure
- wr.write "executed"
- end
- end
-
- # The apparent issue is that when Fiber.yield executes, control
- # "leaves" the "ensure block" and so the ensure clause should run. But
- # control really does NOT leave the ensure block when Fiber.yield
- # executes. It merely pauses there. To require ensure to run when a
- # Fiber is suspended then makes ensure-in-a-Fiber-context different
- # than ensure-in-a-Thread-context and this would be very confusing.
- f.resume
-
- # When we execute the second #resume call, the ensure block DOES exit,
- # the ensure clause runs. This is Ruby behavior as of 2.3.1.
- f.resume
-
- exit 0
- end
+require_relative '../../spec_helper'
+require_relative 'shared/resume'
+
+describe "Fiber#resume" do
+ it_behaves_like :fiber_resume, :resume
+end
+
+describe "Fiber#resume" do
+ it "runs until Fiber.yield" do
+ obj = mock('obj')
+ obj.should_not_receive(:do)
+ fiber = Fiber.new { 1 + 2; Fiber.yield; obj.do }
+ fiber.resume
+ end
+
+ it "resumes from the last call to Fiber.yield on subsequent invocations" do
+ fiber = Fiber.new { Fiber.yield :first; :second }
+ fiber.resume.should == :first
+ fiber.resume.should == :second
+ end
+
+ it "sets the block parameters to its arguments on the first invocation" do
+ first = mock('first')
+ first.should_receive(:arg).with(:first).twice
+
+ fiber = Fiber.new { |arg| first.arg arg; Fiber.yield; first.arg arg; }
+ fiber.resume :first
+ fiber.resume :second
+ end
+
+ it "raises a FiberError if the Fiber tries to resume itself" do
+ fiber = Fiber.new { fiber.resume }
+ -> { fiber.resume }.should.raise(FiberError, /current fiber/)
+ end
- wr.close
- Process.waitpid pid
+ it "returns control to the calling Fiber if called from one" do
+ fiber1 = Fiber.new { :fiber1 }
+ fiber2 = Fiber.new { fiber1.resume; :fiber2 }
+ fiber2.resume.should == :fiber2
+ end
- rd.read.should == "executed"
- rd.close
+ # Redmine #595
+ it "executes the ensure clause" do
+ code = <<-RUBY
+ f = Fiber.new do
+ begin
+ Fiber.yield
+ ensure
+ puts "ensure executed"
+ end
end
- end
+
+ # The apparent issue is that when Fiber.yield executes, control
+ # "leaves" the "ensure block" and so the ensure clause should run. But
+ # control really does NOT leave the ensure block when Fiber.yield
+ # executes. It merely pauses there. To require ensure to run when a
+ # Fiber is suspended then makes ensure-in-a-Fiber-context different
+ # than ensure-in-a-Thread-context and this would be very confusing.
+ f.resume
+
+ # When we execute the second #resume call, the ensure block DOES exit,
+ # the ensure clause runs.
+ f.resume
+
+ exit 0
+ RUBY
+
+ ruby_exe(code).should == "ensure executed\n"
+ end
+
+ it "can work with Fiber#transfer" do
+ fiber1 = Fiber.new { true }
+ fiber2 = Fiber.new { fiber1.transfer; Fiber.yield 10 ; Fiber.yield 20; raise }
+ fiber2.resume.should == 10
+ fiber2.resume.should == 20
+ end
+
+ it "raises a FiberError if the Fiber attempts to resume a resuming fiber" do
+ root_fiber = Fiber.current
+ fiber1 = Fiber.new { root_fiber.resume }
+ -> { fiber1.resume }.should.raise(FiberError, /attempt to resume a resuming fiber/)
end
end
diff --git a/spec/ruby/core/fiber/scheduler_spec.rb b/spec/ruby/core/fiber/scheduler_spec.rb
new file mode 100644
index 0000000000..2a517ba93b
--- /dev/null
+++ b/spec/ruby/core/fiber/scheduler_spec.rb
@@ -0,0 +1,5 @@
+require_relative '../../spec_helper'
+
+describe "Fiber.scheduler" do
+ it "is already tested in Fiber.set_scheduler"
+end
diff --git a/spec/ruby/core/fiber/set_scheduler_spec.rb b/spec/ruby/core/fiber/set_scheduler_spec.rb
new file mode 100644
index 0000000000..b34aff8734
--- /dev/null
+++ b/spec/ruby/core/fiber/set_scheduler_spec.rb
@@ -0,0 +1,55 @@
+require_relative '../../spec_helper'
+
+require "fiber"
+
+describe "Fiber.scheduler" do
+ it "validates the scheduler for required methods" do
+ required_methods = [:block, :unblock, :kernel_sleep, :io_wait]
+ required_methods.each do |missing_method|
+ scheduler = Object.new
+ required_methods.difference([missing_method]).each do |method|
+ scheduler.define_singleton_method(method) {}
+ end
+ -> {
+ suppress_warning { Fiber.set_scheduler(scheduler) }
+ }.should.raise(ArgumentError, /Scheduler must implement ##{missing_method}/)
+ end
+ end
+
+ it "can set and get the scheduler" do
+ required_methods = [:block, :unblock, :kernel_sleep, :io_wait]
+ scheduler = Object.new
+ required_methods.each do |method|
+ scheduler.define_singleton_method(method) {}
+ end
+ suppress_warning { Fiber.set_scheduler(scheduler) }
+ Fiber.scheduler.should == scheduler
+ end
+
+ it "returns the scheduler after setting it" do
+ required_methods = [:block, :unblock, :kernel_sleep, :io_wait]
+ scheduler = Object.new
+ required_methods.each do |method|
+ scheduler.define_singleton_method(method) {}
+ end
+ result = suppress_warning { Fiber.set_scheduler(scheduler) }
+ result.should == scheduler
+ end
+
+ it "can remove the scheduler" do
+ required_methods = [:block, :unblock, :kernel_sleep, :io_wait]
+ scheduler = Object.new
+ required_methods.each do |method|
+ scheduler.define_singleton_method(method) {}
+ end
+ suppress_warning { Fiber.set_scheduler(scheduler) }
+ Fiber.set_scheduler(nil)
+ Fiber.scheduler.should == nil
+ end
+
+ it "can assign a nil scheduler multiple times" do
+ Fiber.set_scheduler(nil)
+ Fiber.set_scheduler(nil)
+ Fiber.scheduler.should == nil
+ end
+end
diff --git a/spec/ruby/core/fiber/shared/blocking.rb b/spec/ruby/core/fiber/shared/blocking.rb
new file mode 100644
index 0000000000..21707e1ea7
--- /dev/null
+++ b/spec/ruby/core/fiber/shared/blocking.rb
@@ -0,0 +1,41 @@
+describe :non_blocking_fiber, shared: true do
+ context "root Fiber of the main thread" do
+ it "returns false" do
+ fiber = Fiber.new { @method.call }
+ blocking = fiber.resume
+
+ blocking.should == false
+ end
+
+ it "returns false for blocking: false" do
+ fiber = Fiber.new(blocking: false) { @method.call }
+ blocking = fiber.resume
+
+ blocking.should == false
+ end
+ end
+
+ context "root Fiber of a new thread" do
+ it "returns false" do
+ thread = Thread.new do
+ fiber = Fiber.new { @method.call }
+ blocking = fiber.resume
+
+ blocking.should == false
+ end
+
+ thread.join
+ end
+
+ it "returns false for blocking: false" do
+ thread = Thread.new do
+ fiber = Fiber.new(blocking: false) { @method.call }
+ blocking = fiber.resume
+
+ blocking.should == false
+ end
+
+ thread.join
+ end
+ end
+end
diff --git a/spec/ruby/core/fiber/shared/resume.rb b/spec/ruby/core/fiber/shared/resume.rb
new file mode 100644
index 0000000000..ff4bb72c73
--- /dev/null
+++ b/spec/ruby/core/fiber/shared/resume.rb
@@ -0,0 +1,58 @@
+describe :fiber_resume, shared: true do
+ it "can be invoked from the root Fiber" do
+ fiber = Fiber.new { :fiber }
+ fiber.send(@method).should == :fiber
+ end
+
+ it "raises a FiberError if invoked from a different Thread" do
+ fiber = Fiber.new { 42 }
+ Thread.new do
+ -> {
+ fiber.send(@method)
+ }.should.raise(FiberError)
+ end.join
+
+ # 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
+ invoked = false
+ fiber = Fiber.new { invoked = true }
+ fiber.send(@method)
+ invoked.should == true
+ end
+
+ it "returns the last value encountered on first invocation" do
+ fiber = Fiber.new { 1+1; true }
+ fiber.send(@method).should == true
+ end
+
+ it "runs until the end of the block" do
+ obj = mock('obj')
+ obj.should_receive(:do).once
+ fiber = Fiber.new { 1 + 2; a = "glark"; obj.do }
+ fiber.send(@method)
+ end
+
+ it "accepts any number of arguments" do
+ fiber = Fiber.new { |a| }
+ -> { fiber.send(@method, *(1..10).to_a) }.should_not.raise
+ end
+
+ it "raises a FiberError if the Fiber is dead" do
+ fiber = Fiber.new { true }
+ fiber.send(@method)
+ -> { fiber.send(@method) }.should.raise(FiberError)
+ end
+
+ it "raises a LocalJumpError if the block includes a return statement" do
+ fiber = Fiber.new { return; }
+ -> { fiber.send(@method) }.should.raise(LocalJumpError)
+ end
+
+ it "raises a LocalJumpError if the block includes a break statement" do
+ fiber = Fiber.new { break; }
+ -> { fiber.send(@method) }.should.raise(LocalJumpError)
+ end
+end
diff --git a/spec/ruby/core/fiber/storage_spec.rb b/spec/ruby/core/fiber/storage_spec.rb
new file mode 100644
index 0000000000..a3f6bf9cad
--- /dev/null
+++ b/spec/ruby/core/fiber/storage_spec.rb
@@ -0,0 +1,177 @@
+require_relative '../../spec_helper'
+
+describe "Fiber.new(storage:)" do
+ it "creates a Fiber with the given storage" do
+ storage = {life: 42}
+ fiber = Fiber.new(storage: storage) { Fiber.current.storage }
+ fiber.resume.should == storage
+ end
+
+ it "creates a fiber with lazily initialized storage" do
+ Fiber.new(storage: nil) { Fiber[:x] = 10; Fiber.current.storage }.resume.should == {x: 10}
+ end
+
+ it "creates a fiber by inheriting the storage of the parent fiber" do
+ fiber = Fiber.new(storage: {life: 42}) do
+ Fiber.new { Fiber.current.storage }.resume
+ end
+ fiber.resume.should == {life: 42}
+ end
+
+ it "cannot create a fiber with non-hash storage" do
+ -> { Fiber.new(storage: 42) {} }.should.raise(TypeError)
+ end
+
+ it "cannot create a fiber with a frozen hash as storage" do
+ -> { Fiber.new(storage: {life: 43}.freeze) {} }.should.raise(FrozenError)
+ end
+
+ it "cannot create a fiber with a storage hash with non-symbol keys" do
+ -> { Fiber.new(storage: {life: 43, Object.new => 44}) {} }.should.raise(TypeError)
+ end
+end
+
+describe "Fiber#storage" do
+ it "cannot be accessed from a different fiber" do
+ f = Fiber.new(storage: {life: 42}) { nil }
+ -> {
+ f.storage
+ }.should.raise(ArgumentError, /Fiber storage can only be accessed from the Fiber it belongs to/)
+ end
+end
+
+describe "Fiber#storage=" do
+ it "can clear the storage of the fiber" do
+ fiber = Fiber.new(storage: {life: 42}) do
+ Fiber.current.storage = nil
+ Fiber[:x] = 10
+ Fiber.current.storage
+ end
+ fiber.resume.should == {x: 10}
+ end
+
+ it "can set the storage of the fiber" do
+ fiber = Fiber.new(storage: {life: 42}) do
+ Fiber.current.storage = {life: 43}
+ Fiber.current.storage
+ end
+ fiber.resume.should == {life: 43}
+ end
+
+ it "can't set the storage of the fiber to non-hash" do
+ -> { Fiber.current.storage = 42 }.should.raise(TypeError)
+ end
+
+ it "can't set the storage of the fiber to a frozen hash" do
+ -> { Fiber.current.storage = {life: 43}.freeze }.should.raise(FrozenError)
+ end
+
+ it "can't set the storage of the fiber to a hash with non-symbol keys" do
+ -> { Fiber.current.storage = {life: 43, Object.new => 44} }.should.raise(TypeError)
+ end
+end
+
+describe "Fiber.[]" do
+ it "returns the value of the given key in the storage of the current fiber" do
+ Fiber.new(storage: {life: 42}) { Fiber[:life] }.resume.should == 42
+ end
+
+ it "returns nil if the key is not present in the storage of the current fiber" do
+ Fiber.new(storage: {life: 42}) { Fiber[:death] }.resume.should == nil
+ end
+
+ it "returns nil if the current fiber has no storage" do
+ Fiber.new { Fiber[:life] }.resume.should == nil
+ end
+
+ it "can use dynamically defined keys" do
+ key = :"#{self.class.name}#.#{self.object_id}"
+ Fiber.new { Fiber[key] = 42; Fiber[key] }.resume.should == 42
+ end
+
+ it "can't use invalid keys" do
+ invalid_keys = [Object.new, 12]
+ invalid_keys.each do |key|
+ -> { Fiber[key] }.should.raise(TypeError)
+ end
+ end
+
+ ruby_bug "#20978", ""..."3.4" do
+ it "can use keys as strings" do
+ key = Object.new
+ def key.to_str; "Foo"; end
+ Fiber.new { Fiber[key] = 42; Fiber["Foo"] }.resume.should == 42
+ end
+
+ it "converts a String key into a Symbol" do
+ Fiber.new { Fiber["key"] = 42; Fiber[:key] }.resume.should == 42
+ Fiber.new { Fiber[:key] = 42; Fiber["key"] }.resume.should == 42
+ end
+
+ it "can use any object that responds to #to_str as a key" do
+ key = mock("key")
+ key.should_receive(:to_str).twice.and_return("key")
+ Fiber.new { Fiber[key] = 42; Fiber[key] }.resume.should == 42
+ end
+ end
+
+ it "does not call #to_sym on the key" do
+ key = mock("key")
+ key.should_not_receive(:to_sym)
+ -> { Fiber[key] }.should.raise(TypeError)
+ end
+
+ it "can access the storage of the parent fiber" do
+ f = Fiber.new(storage: {life: 42}) do
+ Fiber.new { Fiber[:life] }.resume
+ end
+ f.resume.should == 42
+ end
+
+ it "can't access the storage of the fiber with non-symbol keys" do
+ -> { Fiber[Object.new] }.should.raise(TypeError)
+ end
+end
+
+describe "Fiber.[]=" do
+ it "sets the value of the given key in the storage of the current fiber" do
+ Fiber.new(storage: {life: 42}) { Fiber[:life] = 43; Fiber[:life] }.resume.should == 43
+ end
+
+ it "sets the value of the given key in the storage of the current fiber" do
+ Fiber.new(storage: {life: 42}) { Fiber[:death] = 43; Fiber[:death] }.resume.should == 43
+ end
+
+ it "sets the value of the given key in the storage of the current fiber" do
+ Fiber.new { Fiber[:life] = 43; Fiber[:life] }.resume.should == 43
+ end
+
+ it "does not overwrite the storage of the parent fiber" do
+ f = Fiber.new(storage: {life: 42}) do
+ Fiber.yield Fiber.new { Fiber[:life] = 43; Fiber[:life] }.resume
+ Fiber[:life]
+ end
+ f.resume.should == 43 # Value of the inner fiber
+ f.resume.should == 42 # Value of the outer fiber
+ end
+
+ it "can't access the storage of the fiber with non-symbol keys" do
+ -> { Fiber[Object.new] = 44 }.should.raise(TypeError)
+ end
+
+ it "deletes the fiber storage key when assigning nil" do
+ Fiber.new(storage: {life: 42}) {
+ Fiber[:life] = nil
+ Fiber.current.storage
+ }.resume.should == {}
+ end
+end
+
+describe "Thread.new" do
+ it "creates a thread with the storage of the current fiber" do
+ fiber = Fiber.new(storage: {life: 42}) do
+ Thread.new { Fiber.current.storage }.value
+ end
+ fiber.resume.should == {life: 42}
+ end
+end
diff --git a/spec/ruby/core/fiber/transfer_spec.rb b/spec/ruby/core/fiber/transfer_spec.rb
new file mode 100644
index 0000000000..d8737aeeb3
--- /dev/null
+++ b/spec/ruby/core/fiber/transfer_spec.rb
@@ -0,0 +1,84 @@
+require_relative '../../spec_helper'
+require_relative 'shared/resume'
+
+describe "Fiber#transfer" do
+ it_behaves_like :fiber_resume, :transfer
+end
+
+describe "Fiber#transfer" do
+ it "transfers control from one Fiber to another when called from a Fiber" do
+ fiber1 = Fiber.new { :fiber1 }
+ fiber2 = Fiber.new { fiber1.transfer; :fiber2 }
+ fiber2.resume.should == :fiber2
+ end
+
+ it "returns to the root Fiber when finished" do
+ f1 = Fiber.new { :fiber_1 }
+ f2 = Fiber.new { f1.transfer; :fiber_2 }
+
+ f2.transfer.should == :fiber_1
+ f2.transfer.should == :fiber_2
+ end
+
+ it "can be invoked from the same Fiber it transfers control to" do
+ states = []
+ fiber = Fiber.new { states << :start; fiber.transfer; states << :end }
+ fiber.transfer
+ states.should == [:start, :end]
+
+ states = []
+ fiber = Fiber.new { states << :start; fiber.transfer; states << :end }
+ fiber.resume
+ states.should == [:start, :end]
+ end
+
+ it "can not transfer control to a Fiber that has suspended by Fiber.yield" do
+ states = []
+ fiber1 = Fiber.new { states << :fiber1 }
+ fiber2 = Fiber.new { states << :fiber2_start; Fiber.yield fiber1.transfer; states << :fiber2_end}
+ fiber2.resume.should == [:fiber2_start, :fiber1]
+ -> { fiber2.transfer }.should.raise(FiberError)
+ end
+
+ it "raises a FiberError when transferring to a Fiber which resumes itself" do
+ fiber = Fiber.new { fiber.resume }
+ -> { fiber.transfer }.should.raise(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
diff --git a/spec/ruby/core/fiber/yield_spec.rb b/spec/ruby/core/fiber/yield_spec.rb
index e433da0aa9..12ec6ebcef 100644
--- a/spec/ruby/core/fiber/yield_spec.rb
+++ b/spec/ruby/core/fiber/yield_spec.rb
@@ -1,51 +1,49 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-with_feature :fiber do
- describe "Fiber.yield" do
- it "passes control to the Fiber's caller" do
- step = 0
- fiber = Fiber.new { step = 1; Fiber.yield; step = 2; Fiber.yield; step = 3 }
- fiber.resume
- step.should == 1
- fiber.resume
- step.should == 2
- end
-
- it "returns its arguments to the caller" do
- fiber = Fiber.new { true; Fiber.yield :glark; true }
- fiber.resume.should == :glark
- fiber.resume
- end
+require_relative '../../spec_helper'
+
+describe "Fiber.yield" do
+ it "passes control to the Fiber's caller" do
+ step = 0
+ fiber = Fiber.new { step = 1; Fiber.yield; step = 2; Fiber.yield; step = 3 }
+ fiber.resume
+ step.should == 1
+ fiber.resume
+ step.should == 2
+ end
- it "returns nil to the caller if given no arguments" do
- fiber = Fiber.new { true; Fiber.yield; true }
- fiber.resume.should be_nil
- fiber.resume
- end
+ it "returns its arguments to the caller" do
+ fiber = Fiber.new { true; Fiber.yield :glark; true }
+ fiber.resume.should == :glark
+ fiber.resume
+ end
- it "returns to the Fiber the value of the #resume call that invoked it" do
- fiber = Fiber.new { Fiber.yield.should == :caller }
- fiber.resume
- fiber.resume :caller
- end
+ it "returns nil to the caller if given no arguments" do
+ fiber = Fiber.new { true; Fiber.yield; true }
+ fiber.resume.should == nil
+ fiber.resume
+ end
- it "does not propagate or reraise a rescued exception" do
- fiber = Fiber.new do
- begin
- raise "an error in a Fiber"
- rescue
- Fiber.yield :first
- end
+ it "returns to the Fiber the value of the #resume call that invoked it" do
+ fiber = Fiber.new { Fiber.yield.should == :caller }
+ fiber.resume
+ fiber.resume :caller
+ end
- :second
+ it "does not propagate or reraise a rescued exception" do
+ fiber = Fiber.new do
+ begin
+ raise "an error in a Fiber"
+ rescue
+ Fiber.yield :first
end
- fiber.resume.should == :first
- fiber.resume.should == :second
+ :second
end
- it "raises a FiberError if called from the root Fiber" do
- lambda{ Fiber.yield }.should raise_error(FiberError)
- end
+ fiber.resume.should == :first
+ fiber.resume.should == :second
+ end
+
+ it "raises a FiberError if called from the root Fiber" do
+ ->{ Fiber.yield }.should.raise(FiberError)
end
end
diff --git a/spec/ruby/core/file/absolute_path_spec.rb b/spec/ruby/core/file/absolute_path_spec.rb
index b1f4f05aee..fc12985a75 100644
--- a/spec/ruby/core/file/absolute_path_spec.rb
+++ b/spec/ruby/core/file/absolute_path_spec.rb
@@ -1,4 +1,55 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
+
+describe "File.absolute_path?" do
+ before :each do
+ @abs = File.expand_path(__FILE__)
+ end
+
+ it "returns true if it's an absolute pathname" do
+ File.absolute_path?(@abs).should == true
+ end
+
+ it "returns false if it's a relative path" do
+ File.absolute_path?(File.basename(__FILE__)).should == false
+ end
+
+ it "returns false if it's a tricky relative path" do
+ File.absolute_path?("C:foo\\bar").should == false
+ end
+
+ it "does not expand '~' to a home directory." do
+ File.absolute_path?('~').should == false
+ end
+
+ it "does not expand '~user' to a home directory." do
+ path = File.dirname(@abs)
+ Dir.chdir(path) do
+ File.absolute_path?('~user').should == false
+ end
+ end
+
+ it "calls #to_path on its argument" do
+ mock = mock_to_path(File.expand_path(__FILE__))
+
+ File.absolute_path?(mock).should == true
+ end
+
+ platform_is_not :windows do
+ it "takes into consideration the platform's root" do
+ File.absolute_path?("C:\\foo\\bar").should == false
+ File.absolute_path?("C:/foo/bar").should == false
+ File.absolute_path?("/foo/bar\\baz").should == true
+ end
+ end
+
+ platform_is :windows do
+ it "takes into consideration the platform path separator(s)" do
+ File.absolute_path?("C:\\foo\\bar").should == true
+ File.absolute_path?("C:/foo/bar").should == true
+ File.absolute_path?("/foo/bar\\baz").should == false
+ end
+ end
+end
describe "File.absolute_path" do
before :each do
@@ -20,6 +71,12 @@ describe "File.absolute_path" do
File.absolute_path('~').should_not == File.expand_path('~')
end
+ platform_is_not :windows do
+ it "does not expand '~' when given dir argument" do
+ File.absolute_path('~', '/').should == '/~'
+ end
+ end
+
it "does not expand '~user' to a home directory." do
path = File.dirname(@abs)
Dir.chdir(path) do
@@ -28,7 +85,7 @@ describe "File.absolute_path" do
end
it "accepts a second argument of a directory from which to resolve the path" do
- File.absolute_path(__FILE__, File.dirname(__FILE__)).should == @abs
+ File.absolute_path(__FILE__, __dir__).should == @abs
end
it "calls #to_path on its argument" do
diff --git a/spec/ruby/core/file/atime_spec.rb b/spec/ruby/core/file/atime_spec.rb
index 76e7fbd62a..5c6c110eec 100644
--- a/spec/ruby/core/file/atime_spec.rb
+++ b/spec/ruby/core/file/atime_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "File.atime" do
before :each do
@@ -12,25 +12,30 @@ describe "File.atime" do
it "returns the last access time for the named file as a Time object" do
File.atime(@file)
- File.atime(@file).should be_kind_of(Time)
- end
-
- platform_is :linux do
- ## NOTE also that some Linux systems disable atime (e.g. via mount params) for better filesystem speed.
- it "returns the last access time for the named file with microseconds" do
- supports_subseconds = Integer(`stat -c%x '#{__FILE__}'`[/\.(\d+)/, 1], 10)
- if supports_subseconds != 0
- expected_time = Time.at(Time.now.to_i + 0.123456)
- File.utime expected_time, 0, @file
- File.atime(@file).usec.should == expected_time.usec
- else
- File.atime(__FILE__).usec.should == 0
+ File.atime(@file).should.is_a?(Time)
+ end
+
+ platform_is :linux, :windows do
+ unless ENV.key?('TRAVIS') # https://bugs.ruby-lang.org/issues/17926
+ ## NOTE also that some Linux systems disable atime (e.g. via mount params) for better filesystem speed.
+ it "returns the last access time for the named file with microseconds" do
+ supports_subseconds = Integer(`stat -c%x '#{__FILE__}'`[/\.(\d{1,6})/, 1], 10)
+ if supports_subseconds != 0
+ expected_time = Time.at(Time.now.to_i + 0.123456)
+ File.utime expected_time, 0, @file
+ File.atime(@file).usec.should == expected_time.usec
+ else
+ File.atime(__FILE__).usec.should == 0
+ end
+ rescue Errno::ENOENT => e
+ # Native Windows don't have stat command.
+ skip e.message
end
end
end
it "raises an Errno::ENOENT exception if the file is not found" do
- lambda { File.atime('a_fake_file') }.should raise_error(Errno::ENOENT)
+ -> { File.atime('a_fake_file') }.should.raise(Errno::ENOENT)
end
it "accepts an object that has a #to_path method" do
@@ -50,6 +55,6 @@ describe "File#atime" do
it "returns the last access time to self" do
@file.atime
- @file.atime.should be_kind_of(Time)
+ @file.atime.should.is_a?(Time)
end
end
diff --git a/spec/ruby/core/file/basename_spec.rb b/spec/ruby/core/file/basename_spec.rb
index 4cf26062d3..77afe5c22f 100644
--- a/spec/ruby/core/file/basename_spec.rb
+++ b/spec/ruby/core/file/basename_spec.rb
@@ -1,5 +1,5 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
# TODO: Fix these
describe "File.basename" do
@@ -42,7 +42,7 @@ describe "File.basename" do
end
it "returns an string" do
- File.basename("foo").should be_kind_of(String)
+ File.basename("foo").should.is_a?(String)
end
it "returns the basename for unix format" do
@@ -105,10 +105,10 @@ describe "File.basename" do
end
it "raises a TypeError if the arguments are not String types" do
- lambda { File.basename(nil) }.should raise_error(TypeError)
- lambda { File.basename(1) }.should raise_error(TypeError)
- lambda { File.basename("bar.txt", 1) }.should raise_error(TypeError)
- lambda { File.basename(true) }.should raise_error(TypeError)
+ -> { File.basename(nil) }.should.raise(TypeError)
+ -> { File.basename(1) }.should.raise(TypeError)
+ -> { File.basename("bar.txt", 1) }.should.raise(TypeError)
+ -> { File.basename(true) }.should.raise(TypeError)
end
it "accepts an object that has a #to_path method" do
@@ -116,7 +116,7 @@ describe "File.basename" do
end
it "raises an ArgumentError if passed more than two arguments" do
- lambda { File.basename('bar.txt', '.txt', '.txt') }.should raise_error(ArgumentError)
+ -> { File.basename('bar.txt', '.txt', '.txt') }.should.raise(ArgumentError)
end
# specific to MS Windows
@@ -151,20 +151,55 @@ describe "File.basename" do
File.basename("c:\\bar.txt", ".*").should == "bar"
File.basename("c:\\bar.txt.exe", ".*").should == "bar.txt"
end
+
+ it "handles Shift JIS 0x5C (\\) as second byte of a multi-byte sequence" do
+ # dir\fileソname.txt
+ path = "dir\\file\x83\x5cname.txt".b.force_encoding(Encoding::SHIFT_JIS)
+ path.valid_encoding?.should == true
+ File.basename(path).should == "file\x83\x5cname.txt".b.force_encoding(Encoding::SHIFT_JIS)
+ end
end
- with_feature :encoding do
+ it "rejects strings encoded with non ASCII-compatible encodings" do
+ Encoding.list.reject(&:ascii_compatible?).reject(&:dummy?).each do |enc|
+ path = "/foo/bar".encode(enc)
- it "returns the extension for a multibyte filename" do
- File.basename('/path/ОфиÑ.m4a').should == "ОфиÑ.m4a"
+ -> {
+ File.basename(path)
+ }.should.raise(Encoding::CompatibilityError)
end
+ end
- it "returns the basename with the same encoding as the original" do
- basename = File.basename('C:/Users/Scuby Pagrubý'.encode(Encoding::Windows_1250))
- basename.should == 'Scuby Pagrubý'.encode(Encoding::Windows_1250)
- basename.encoding.should == Encoding::Windows_1250
+ it "works with all ASCII-compatible encodings" do
+ Encoding.list.select(&:ascii_compatible?).each do |enc|
+ File.basename("/foo/bar".encode(enc)).should == "bar".encode(enc)
end
+ end
+ it "returns the extension for a multibyte filename" do
+ File.basename('/path/ОфиÑ.m4a').should == "ОфиÑ.m4a"
+ end
+
+ it "returns the basename with the same encoding as the original" do
+ basename = File.basename('C:/Users/Scuby Pagrubý'.encode(Encoding::Windows_1250))
+ basename.should == 'Scuby Pagrubý'.encode(Encoding::Windows_1250)
+ basename.encoding.should == Encoding::Windows_1250
+ end
+
+ it "returns a new unfrozen String" do
+ exts = [nil, '.rb', '.*', '.txt']
+ ['foo.rb','//', '/test/', 'test'].each do |example|
+ exts.each do |ext|
+ original = example.freeze
+ result = if ext
+ File.basename(original, ext)
+ else
+ File.basename(original)
+ end
+ result.should_not.equal?(original)
+ result.frozen?.should == false
+ end
+ end
end
end
diff --git a/spec/ruby/core/file/birthtime_spec.rb b/spec/ruby/core/file/birthtime_spec.rb
index 9720ede834..039fd7572c 100644
--- a/spec/ruby/core/file/birthtime_spec.rb
+++ b/spec/ruby/core/file/birthtime_spec.rb
@@ -1,56 +1,56 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
-describe "File.birthtime" do
- before :each do
- @file = __FILE__
- end
+platform_is :windows, :darwin, :freebsd, :netbsd, :linux do
+ not_implemented_messages = [
+ "birthtime() function is unimplemented", # unsupported OS/version
+ "birthtime is unimplemented", # unsupported filesystem
+ ]
- after :each do
- @file = nil
- end
+ describe "File.birthtime" do
+ before :each do
+ @file = __FILE__
+ end
+
+ after :each do
+ @file = nil
+ end
- platform_is :windows, :darwin, :freebsd, :netbsd do
it "returns the birth time for the named file as a Time object" do
File.birthtime(@file)
- File.birthtime(@file).should be_kind_of(Time)
+ File.birthtime(@file).should.is_a?(Time)
+ rescue NotImplementedError => e
+ e.message.should.start_with?(*not_implemented_messages)
end
it "accepts an object that has a #to_path method" do
+ File.birthtime(@file) # Avoid to failure of mock object with old Kernel and glibc
File.birthtime(mock_to_path(@file))
+ rescue NotImplementedError => e
+ e.message.should.start_with?(*not_implemented_messages)
end
it "raises an Errno::ENOENT exception if the file is not found" do
- lambda { File.birthtime('bogus') }.should raise_error(Errno::ENOENT)
+ -> { File.birthtime('bogus') }.should.raise(Errno::ENOENT)
+ rescue NotImplementedError => e
+ e.message.should.start_with?(*not_implemented_messages)
end
end
- platform_is :linux, :openbsd do
- it "raises an NotImplementedError" do
- lambda { File.birthtime(@file) }.should raise_error(NotImplementedError)
+ describe "File#birthtime" do
+ before :each do
+ @file = File.open(__FILE__)
end
- end
-end
-describe "File#birthtime" do
- before :each do
- @file = File.open(__FILE__)
- end
-
- after :each do
- @file.close
- @file = nil
- end
+ after :each do
+ @file.close
+ @file = nil
+ end
- platform_is :windows, :darwin, :freebsd, :netbsd do
it "returns the birth time for self" do
@file.birthtime
- @file.birthtime.should be_kind_of(Time)
- end
- end
-
- platform_is :linux, :openbsd do
- it "raises an NotImplementedError" do
- lambda { @file.birthtime }.should raise_error(NotImplementedError)
+ @file.birthtime.should.is_a?(Time)
+ rescue NotImplementedError => e
+ e.message.should.start_with?(*not_implemented_messages)
end
end
end
diff --git a/spec/ruby/core/file/blockdev_spec.rb b/spec/ruby/core/file/blockdev_spec.rb
index f5e03d1ade..9ba9afc251 100644
--- a/spec/ruby/core/file/blockdev_spec.rb
+++ b/spec/ruby/core/file/blockdev_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/file/blockdev', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../../shared/file/blockdev'
describe "File.blockdev?" do
it_behaves_like :file_blockdev, :blockdev?, File
diff --git a/spec/ruby/core/file/chardev_spec.rb b/spec/ruby/core/file/chardev_spec.rb
index 963823a206..1fc932ee4e 100644
--- a/spec/ruby/core/file/chardev_spec.rb
+++ b/spec/ruby/core/file/chardev_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/file/chardev', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../../shared/file/chardev'
describe "File.chardev?" do
it_behaves_like :file_chardev, :chardev?, File
diff --git a/spec/ruby/core/file/chmod_spec.rb b/spec/ruby/core/file/chmod_spec.rb
index 8590f3008d..e0fd10ceb1 100644
--- a/spec/ruby/core/file/chmod_spec.rb
+++ b/spec/ruby/core/file/chmod_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "File#chmod" do
before :each do
@@ -15,38 +15,11 @@ describe "File#chmod" do
@file.chmod(0755).should == 0
end
- platform_is_not :freebsd, :netbsd, :openbsd do
- it "always succeeds with any numeric values" do
- vals = [-2**30, -2**16, -2**8, -2, -1,
- -0.5, 0, 1, 2, 5.555575, 16, 32, 64, 2**8, 2**16, 2**30]
- vals.each { |v|
- lambda { @file.chmod(v) }.should_not raise_error
- }
- end
- end
-
- # -256, -2 and -1 raise Errno::E079 on FreeBSD
- # -256, -2 and -1 raise Errno::EFTYPE on NetBSD
- platform_is :freebsd, :netbsd do
- it "always succeeds with any numeric values" do
- vals = [-2**30, -2**16, #-2**8, -2, -1,
- -0.5, 0, 1, 2, 5.555575, 16, 32, 64, 2**8, 2**16, 2**30]
- vals.each { |v|
- lambda { @file.chmod(v) }.should_not raise_error
- }
- end
+ it "raises RangeError with too large values" do
+ -> { @file.chmod(2**64) }.should.raise(RangeError)
+ -> { @file.chmod(-2**63 - 1) }.should.raise(RangeError)
end
- # -256, -2 and -1 raise Errno::EINVAL on OpenBSD
- platform_is :openbsd do
- it "always succeeds with any numeric values" do
- vals = [#-2**30, -2**16, -2**8, -2, -1,
- -0.5, 0, 1, 2, 5.555575, 16, 32, 64, 2**8]#, 2**16, 2**30
- vals.each { |v|
- lambda { @file.chmod(v) }.should_not raise_error
- }
- end
- end
it "invokes to_int on non-integer argument" do
mode = File.stat(@filename).mode
(obj = mock('mode')).should_receive(:to_int).and_return(mode)
@@ -71,37 +44,39 @@ describe "File#chmod" do
end
platform_is_not :windows do
- it "with '0222' makes file writable but not readable or executable" do
- @file.chmod(0222)
- File.readable?(@filename).should == false
- File.writable?(@filename).should == true
- File.executable?(@filename).should == false
- end
-
- it "with '0444' makes file readable but not writable or executable" do
- @file.chmod(0444)
- File.readable?(@filename).should == true
- File.writable?(@filename).should == false
- File.executable?(@filename).should == false
- end
-
- it "with '0666' makes file readable and writable but not executable" do
- @file.chmod(0666)
- File.readable?(@filename).should == true
- File.writable?(@filename).should == true
- File.executable?(@filename).should == false
- end
-
- it "with '0111' makes file executable but not readable or writable" do
- @file.chmod(0111)
- File.readable?(@filename).should == false
- File.writable?(@filename).should == false
- File.executable?(@filename).should == true
- end
-
- it "modifies the permission bits of the files specified" do
- @file.chmod(0755)
- File.stat(@filename).mode.should == 33261
+ as_user do
+ it "with '0222' makes file writable but not readable or executable" do
+ @file.chmod(0222)
+ File.readable?(@filename).should == false
+ File.writable?(@filename).should == true
+ File.executable?(@filename).should == false
+ end
+
+ it "with '0444' makes file readable but not writable or executable" do
+ @file.chmod(0444)
+ File.readable?(@filename).should == true
+ File.writable?(@filename).should == false
+ File.executable?(@filename).should == false
+ end
+
+ it "with '0666' makes file readable and writable but not executable" do
+ @file.chmod(0666)
+ File.readable?(@filename).should == true
+ File.writable?(@filename).should == true
+ File.executable?(@filename).should == false
+ end
+
+ it "with '0111' makes file executable but not readable or writable" do
+ @file.chmod(0111)
+ File.readable?(@filename).should == false
+ File.writable?(@filename).should == false
+ File.executable?(@filename).should == true
+ end
+
+ it "modifies the permission bits of the files specified" do
+ @file.chmod(0755)
+ File.stat(@filename).mode.should == 33261
+ end
end
end
end
@@ -121,56 +96,23 @@ describe "File.chmod" do
@count.should == 1
end
- platform_is_not :freebsd, :netbsd, :openbsd do
- it "always succeeds with any numeric values" do
- vals = [-2**30, -2**16, -2**8, -2, -1,
- -0.5, 0, 1, 2, 5.555575, 16, 32, 64, 2**8, 2**16, 2**30]
- vals.each { |v|
- lambda { File.chmod(v, @file) }.should_not raise_error
- }
- end
- end
-
- # -256, -2 and -1 raise Errno::E079 on FreeBSD
- # -256, -2 and -1 raise Errno::EFTYPE on NetBSD
- platform_is :freebsd, :netbsd do
- it "always succeeds with any numeric values" do
- vals = [-2**30, -2**16, #-2**8, -2, -1,
- -0.5, 0, 1, 2, 5.555575, 16, 32, 64, 2**8, 2**16, 2**30]
- vals.each { |v|
- lambda { File.chmod(v, @file) }.should_not raise_error
- }
- end
- end
-
- platform_is :openbsd do
- it "succeeds with valid values" do
- vals = [-0.5, 0, 1, 2, 5.555575, 16, 32, 64, 2**8]
- vals.each { |v|
- lambda { File.chmod(v, @file) }.should_not raise_error
- }
- end
-
- it "fails with invalid values" do
- vals = [-2**30, -2**16, -2**8, -2, -1, 2**16, 2**30]
- vals.each { |v|
- lambda { File.chmod(v, @file) }.should raise_error(Errno::EINVAL)
- }
- end
+ it "raises RangeError with too large values" do
+ -> { File.chmod(2**64, @file) }.should.raise(RangeError)
+ -> { File.chmod(-2**63 - 1, @file) }.should.raise(RangeError)
end
it "accepts an object that has a #to_path method" do
File.chmod(0, mock_to_path(@file))
end
- it "throws a TypeError if the given path is not coercable into a string" do
- lambda { File.chmod(0, []) }.should raise_error(TypeError)
+ it "throws a TypeError if the given path is not coercible into a string" do
+ -> { File.chmod(0, []) }.should.raise(TypeError)
end
it "raises an error for a non existent path" do
- lambda {
+ -> {
File.chmod(0644, "#{@file}.not.existing")
- }.should raise_error(Errno::ENOENT)
+ }.should.raise(Errno::ENOENT)
end
it "invokes to_int on non-integer argument" do
@@ -204,18 +146,20 @@ describe "File.chmod" do
end
platform_is_not :windows do
- it "with '0222' makes file writable but not readable or executable" do
- File.chmod(0222, @file)
- File.readable?(@file).should == false
- File.writable?(@file).should == true
- File.executable?(@file).should == false
- end
-
- it "with '0444' makes file readable but not writable or executable" do
- File.chmod(0444, @file)
- File.readable?(@file).should == true
- File.writable?(@file).should == false
- File.executable?(@file).should == false
+ as_user do
+ it "with '0222' makes file writable but not readable or executable" do
+ File.chmod(0222, @file)
+ File.readable?(@file).should == false
+ File.writable?(@file).should == true
+ File.executable?(@file).should == false
+ end
+
+ it "with '0444' makes file readable but not writable or executable" do
+ File.chmod(0444, @file)
+ File.readable?(@file).should == true
+ File.writable?(@file).should == false
+ File.executable?(@file).should == false
+ end
end
it "with '0666' makes file readable and writable but not executable" do
@@ -225,11 +169,13 @@ describe "File.chmod" do
File.executable?(@file).should == false
end
- it "with '0111' makes file executable but not readable or writable" do
- File.chmod(0111, @file)
- File.readable?(@file).should == false
- File.writable?(@file).should == false
- File.executable?(@file).should == true
+ as_user do
+ it "with '0111' makes file executable but not readable or writable" do
+ File.chmod(0111, @file)
+ File.readable?(@file).should == false
+ File.writable?(@file).should == false
+ File.executable?(@file).should == true
+ end
end
it "modifies the permission bits of the files specified" do
diff --git a/spec/ruby/core/file/chown_spec.rb b/spec/ruby/core/file/chown_spec.rb
index a0b46e9e39..3353aafc70 100644
--- a/spec/ruby/core/file/chown_spec.rb
+++ b/spec/ruby/core/file/chown_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "File.chown" do
before :each do
@@ -66,9 +66,9 @@ describe "File.chown" do
platform_is_not :windows do
it "raises an error for a non existent path" do
- lambda {
+ -> {
File.chown(nil, nil, "#{@fname}_not_existing")
- }.should raise_error(Errno::ENOENT)
+ }.should.raise(Errno::ENOENT)
end
end
@@ -78,30 +78,30 @@ describe "File.chown" do
end
describe "File#chown" do
- before :each do
- @fname = tmp('file_chown_test')
- @file = File.open(@fname, 'w')
- end
+ before :each do
+ @fname = tmp('file_chown_test')
+ @file = File.open(@fname, 'w')
+ end
- after :each do
- @file.close unless @file.closed?
- rm_r @fname
- end
+ after :each do
+ @file.close unless @file.closed?
+ rm_r @fname
+ end
as_superuser do
platform_is :windows do
it "does not modify the owner id of the file" do
- File.chown 0, nil, @fname
- File.stat(@fname).uid.should == 0
- File.chown 501, nil, @fname
- File.stat(@fname).uid.should == 0
+ @file.chown 0, nil
+ @file.stat.uid.should == 0
+ @file.chown 501, nil
+ @file.stat.uid.should == 0
end
it "does not modify the group id of the file" do
- File.chown nil, 0, @fname
- File.stat(@fname).gid.should == 0
- File.chown nil, 501, @fname
- File.stat(@fname).gid.should == 0
+ @file.chown nil, 0
+ @file.stat.gid.should == 0
+ @file.chown nil, 501
+ @file.stat.gid.should == 0
end
end
@@ -142,11 +142,3 @@ describe "File#chown" do
@file.chown(nil, nil).should == 0
end
end
-
-describe "File.chown" do
- it "needs to be reviewed for spec completeness"
-end
-
-describe "File#chown" do
- it "needs to be reviewed for spec completeness"
-end
diff --git a/spec/ruby/core/file/constants/constants_spec.rb b/spec/ruby/core/file/constants/constants_spec.rb
index 3b2f67cc30..9d9c1c3b25 100644
--- a/spec/ruby/core/file/constants/constants_spec.rb
+++ b/spec/ruby/core/file/constants/constants_spec.rb
@@ -1,13 +1,13 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
["APPEND", "CREAT", "EXCL", "FNM_CASEFOLD",
"FNM_DOTMATCH", "FNM_EXTGLOB", "FNM_NOESCAPE", "FNM_PATHNAME",
"FNM_SYSCASE", "LOCK_EX", "LOCK_NB", "LOCK_SH",
"LOCK_UN", "NONBLOCK", "RDONLY",
- "RDWR", "TRUNC", "WRONLY"].each do |const|
+ "RDWR", "TRUNC", "WRONLY", "SHARE_DELETE"].each do |const|
describe "File::Constants::#{const}" do
it "is defined" do
- File::Constants.const_defined?(const).should be_true
+ File::Constants.const_defined?(const).should == true
end
end
end
@@ -15,7 +15,7 @@ end
platform_is :windows do
describe "File::Constants::BINARY" do
it "is defined" do
- File::Constants.const_defined?(:BINARY).should be_true
+ File::Constants.const_defined?(:BINARY).should == true
end
end
end
@@ -24,7 +24,7 @@ platform_is_not :windows do
["NOCTTY", "SYNC"].each do |const|
describe "File::Constants::#{const}" do
it "is defined" do
- File::Constants.const_defined?(const).should be_true
+ File::Constants.const_defined?(const).should == true
end
end
end
diff --git a/spec/ruby/core/file/constants_spec.rb b/spec/ruby/core/file/constants_spec.rb
index 0379149a18..5f058a7f40 100644
--- a/spec/ruby/core/file/constants_spec.rb
+++ b/spec/ruby/core/file/constants_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
# TODO: migrate these to constants/constants_spec.rb
diff --git a/spec/ruby/core/file/ctime_spec.rb b/spec/ruby/core/file/ctime_spec.rb
index c39775fcdd..cf37d1f4ee 100644
--- a/spec/ruby/core/file/ctime_spec.rb
+++ b/spec/ruby/core/file/ctime_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "File.ctime" do
before :each do
@@ -11,17 +11,20 @@ describe "File.ctime" do
it "returns the change time for the named file (the time at which directory information about the file was changed, not the file itself)." do
File.ctime(@file)
- File.ctime(@file).should be_kind_of(Time)
+ File.ctime(@file).should.is_a?(Time)
end
- platform_is :linux do
+ platform_is :linux, :windows do
it "returns the change time for the named file (the time at which directory information about the file was changed, not the file itself) with microseconds." do
- supports_subseconds = Integer(`stat -c%z '#{__FILE__}'`[/\.(\d+)/, 1], 10)
+ supports_subseconds = Integer(`stat -c%z '#{__FILE__}'`[/\.(\d{1,6})/, 1], 10)
if supports_subseconds != 0
File.ctime(__FILE__).usec.should > 0
else
File.ctime(__FILE__).usec.should == 0
end
+ rescue Errno::ENOENT => e
+ # Windows don't have stat command.
+ skip e.message
end
end
@@ -30,7 +33,7 @@ describe "File.ctime" do
end
it "raises an Errno::ENOENT exception if the file is not found" do
- lambda { File.ctime('bogus') }.should raise_error(Errno::ENOENT)
+ -> { File.ctime('bogus') }.should.raise(Errno::ENOENT)
end
end
@@ -46,6 +49,6 @@ describe "File#ctime" do
it "returns the change time for the named file (the time at which directory information about the file was changed, not the file itself)." do
@file.ctime
- @file.ctime.should be_kind_of(Time)
+ @file.ctime.should.is_a?(Time)
end
end
diff --git a/spec/ruby/core/file/delete_spec.rb b/spec/ruby/core/file/delete_spec.rb
index 2e903806d7..7149b8a37d 100644
--- a/spec/ruby/core/file/delete_spec.rb
+++ b/spec/ruby/core/file/delete_spec.rb
@@ -1,6 +1,63 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/unlink', __FILE__)
+require_relative '../../spec_helper'
describe "File.delete" do
- it_behaves_like(:file_unlink, :delete)
+ before :each do
+ @file1 = tmp('test.txt')
+ @file2 = tmp('test2.txt')
+
+ touch @file1
+ touch @file2
+ end
+
+ after :each do
+ File.delete(@file1) if File.exist?(@file1)
+ File.delete(@file2) if File.exist?(@file2)
+
+ @file1 = nil
+ @file2 = nil
+ end
+
+ it "returns 0 when called without arguments" do
+ File.delete.should == 0
+ end
+
+ it "deletes a single file" do
+ File.delete(@file1).should == 1
+ File.should_not.exist?(@file1)
+ end
+
+ it "deletes multiple files" do
+ File.delete(@file1, @file2).should == 2
+ File.should_not.exist?(@file1)
+ File.should_not.exist?(@file2)
+ end
+
+ it "raises a TypeError if not passed a String type" do
+ -> { File.delete(1) }.should.raise(TypeError)
+ end
+
+ it "raises an Errno::ENOENT when the given file doesn't exist" do
+ -> { File.delete('bogus') }.should.raise(Errno::ENOENT)
+ end
+
+ it "coerces a given parameter into a string if possible" do
+ mock = mock("to_str")
+ mock.should_receive(:to_str).and_return(@file1)
+ File.delete(mock).should == 1
+ end
+
+ it "accepts an object that has a #to_path method" do
+ File.delete(mock_to_path(@file1)).should == 1
+ end
+
+ platform_is :windows do
+ it "allows deleting an open file with File::SHARE_DELETE" do
+ path = tmp("share_delete.txt")
+ File.open(path, mode: File::CREAT | File::WRONLY | File::BINARY | File::SHARE_DELETE) do |f|
+ File.should.exist?(path)
+ File.delete(path)
+ end
+ File.should_not.exist?(path)
+ end
+ end
end
diff --git a/spec/ruby/core/file/directory_spec.rb b/spec/ruby/core/file/directory_spec.rb
index d8e8b25121..8014a7a03d 100644
--- a/spec/ruby/core/file/directory_spec.rb
+++ b/spec/ruby/core/file/directory_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/file/directory', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../../shared/file/directory'
describe "File.directory?" do
it_behaves_like :file_directory, :directory?, File
diff --git a/spec/ruby/core/file/dirname_spec.rb b/spec/ruby/core/file/dirname_spec.rb
index f56f0806df..855148a684 100644
--- a/spec/ruby/core/file/dirname_spec.rb
+++ b/spec/ruby/core/file/dirname_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "File.dirname" do
it "returns all the components of filename except the last one" do
@@ -11,8 +11,37 @@ describe "File.dirname" do
File.dirname('/foo/foo').should == '/foo'
end
+ context "when level is passed" do
+ it "returns all the components of filename except the last parts by the level" do
+ File.dirname('/home/jason', 2).should == '/'
+ File.dirname('/home/jason/poot.txt', 2).should == '/home'
+ end
+
+ it "returns the same String if the level is 0" do
+ File.dirname('poot.txt', 0).should == 'poot.txt'
+ File.dirname('/', 0).should == '/'
+ end
+
+ it "raises ArgumentError if the level is negative" do
+ -> {
+ File.dirname('/home/jason', -1)
+ }.should.raise(ArgumentError, "negative level: -1")
+ end
+
+ it "returns '/' when level exceeds the number of segments in the path" do
+ File.dirname("/home/jason", 100).should == '/'
+ end
+
+ it "calls #to_int if passed not numeric value" do
+ object = Object.new
+ def object.to_int; 2; end
+
+ File.dirname("/a/b/c/d", object).should == '/a/b'
+ end
+ end
+
it "returns a String" do
- File.dirname("foo").should be_kind_of(String)
+ File.dirname("foo").should.is_a?(String)
end
it "does not modify its argument" do
@@ -34,22 +63,48 @@ describe "File.dirname" do
end
it "returns all the components of filename except the last one (edge cases on all platforms)" do
- File.dirname("").should == "."
- File.dirname(".").should == "."
- File.dirname("./").should == "."
- File.dirname("./b/./").should == "./b"
- File.dirname("..").should == "."
- File.dirname("../").should == "."
- File.dirname("/").should == "/"
- File.dirname("/.").should == "/"
- File.dirname("/foo/").should == "/"
- File.dirname("/foo/.").should == "/foo"
- File.dirname("/foo/./").should == "/foo"
- File.dirname("/foo/../.").should == "/foo/.."
- File.dirname("foo/../").should == "foo"
+ File.dirname("").should == "."
+ File.dirname(".").should == "."
+ File.dirname("./").should == "."
+ File.dirname("./b/./").should == "./b"
+ File.dirname("..").should == "."
+ File.dirname("../").should == "."
+ File.dirname("/").should == "/"
+ File.dirname("/.").should == "/"
+ File.dirname("/foo/").should == "/"
+ File.dirname("/foo/.").should == "/foo"
+ File.dirname("/foo/./").should == "/foo"
+ File.dirname("/foo/../.").should == "/foo/.."
+ File.dirname("foo/../").should == "foo"
+ end
+
+ it "rejects strings encoded with non ASCII-compatible encodings" do
+ Encoding.list.reject(&:ascii_compatible?).reject(&:dummy?).each do |enc|
+ path = "/foo/bar".encode(enc)
+ -> {
+ File.dirname(path)
+ }.should.raise(Encoding::CompatibilityError)
+ end
+ end
+
+ it "works with all ASCII-compatible encodings" do
+ Encoding.list.select(&:ascii_compatible?).each do |enc|
+ File.dirname("/foo/bar".encode(enc)).should == "/foo".encode(enc)
+ end
+ end
+
+ it "handles Shift JIS 0x5C (\\) as second byte of a multi-byte sequence" do
+ # dir/fileソname.txt
+ path = "dir/file\x83\x5cname.txt".b.force_encoding(Encoding::SHIFT_JIS)
+ path.valid_encoding?.should == true
+ File.dirname(path).should == "dir"
end
platform_is_not :windows do
+ it "ignores repeated leading / (edge cases on non-windows)" do
+ File.dirname("/////foo/bar/").should == "/foo"
+ end
+
it "returns all the components of filename except the last one (edge cases on non-windows)" do
File.dirname('/////').should == '/'
File.dirname("//foo//").should == "/"
@@ -65,6 +120,13 @@ describe "File.dirname" do
File.dirname("//foo//").should == "//foo"
File.dirname('/////').should == '//'
end
+
+ it "handles Shift JIS 0x5C (\\) as second byte of a multi-byte sequence (windows)" do
+ # dir\fileソname.txt
+ path = "dir\\file\x83\x5cname.txt".b.force_encoding(Encoding::SHIFT_JIS)
+ path.valid_encoding?.should == true
+ File.dirname(path).should == "dir"
+ end
end
it "accepts an object that has a #to_path method" do
@@ -72,10 +134,10 @@ describe "File.dirname" do
end
it "raises a TypeError if not passed a String type" do
- lambda { File.dirname(nil) }.should raise_error(TypeError)
- lambda { File.dirname(0) }.should raise_error(TypeError)
- lambda { File.dirname(true) }.should raise_error(TypeError)
- lambda { File.dirname(false) }.should raise_error(TypeError)
+ -> { File.dirname(nil) }.should.raise(TypeError)
+ -> { File.dirname(0) }.should.raise(TypeError)
+ -> { File.dirname(true) }.should.raise(TypeError)
+ -> { File.dirname(false) }.should.raise(TypeError)
end
# Windows specific tests
diff --git a/spec/ruby/core/file/empty_spec.rb b/spec/ruby/core/file/empty_spec.rb
index 766aa95e46..e8c9941676 100644
--- a/spec/ruby/core/file/empty_spec.rb
+++ b/spec/ruby/core/file/empty_spec.rb
@@ -1,15 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/file/zero', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../../shared/file/zero'
describe "File.empty?" do
- ruby_version_is "2.4" do
- it_behaves_like :file_zero, :empty?, File
- it_behaves_like :file_zero_missing, :empty?, File
-
- platform_is :solaris do
- it "returns false for /dev/null" do
- File.empty?('/dev/null').should == true
- end
- end
- end
+ it_behaves_like :file_zero, :empty?, File
+ it_behaves_like :file_zero_missing, :empty?, File
end
diff --git a/spec/ruby/core/file/executable_real_spec.rb b/spec/ruby/core/file/executable_real_spec.rb
index 24d6824169..0cb848b201 100644
--- a/spec/ruby/core/file/executable_real_spec.rb
+++ b/spec/ruby/core/file/executable_real_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/file/executable_real', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../../shared/file/executable_real'
describe "File.executable_real?" do
it_behaves_like :file_executable_real, :executable_real?, File
diff --git a/spec/ruby/core/file/executable_spec.rb b/spec/ruby/core/file/executable_spec.rb
index 82d6a81a0d..1dbb3b233d 100644
--- a/spec/ruby/core/file/executable_spec.rb
+++ b/spec/ruby/core/file/executable_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/file/executable', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../../shared/file/executable'
describe "File.executable?" do
it_behaves_like :file_executable, :executable?, File
diff --git a/spec/ruby/core/file/exist_spec.rb b/spec/ruby/core/file/exist_spec.rb
index 29a410c125..b5600e5b07 100644
--- a/spec/ruby/core/file/exist_spec.rb
+++ b/spec/ruby/core/file/exist_spec.rb
@@ -1,6 +1,12 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/file/exist', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../../shared/file/exist'
describe "File.exist?" do
- it_behaves_like(:file_exist, :exist?, File)
+ it_behaves_like :file_exist, :exist?, File
+end
+
+describe "File.exists?" do
+ it "has been removed" do
+ File.should_not.respond_to?(:exists?)
+ end
end
diff --git a/spec/ruby/core/file/exists_spec.rb b/spec/ruby/core/file/exists_spec.rb
deleted file mode 100644
index 70ebd12d86..0000000000
--- a/spec/ruby/core/file/exists_spec.rb
+++ /dev/null
@@ -1,6 +0,0 @@
-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)
-end
diff --git a/spec/ruby/core/file/expand_path_spec.rb b/spec/ruby/core/file/expand_path_spec.rb
index c57f323c4c..160494f145 100644
--- a/spec/ruby/core/file/expand_path_spec.rb
+++ b/spec/ruby/core/file/expand_path_spec.rb
@@ -1,7 +1,8 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/common', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/common'
+require 'etc'
describe "File.expand_path" do
before :each do
@@ -18,14 +19,12 @@ describe "File.expand_path" do
end
end
- with_feature :encoding do
- before :each do
- @external = Encoding.default_external
- end
+ before :each do
+ @external = Encoding.default_external
+ end
- after :each do
- Encoding.default_external = @external
- end
+ after :each do
+ Encoding.default_external = @external
end
it "converts a pathname to an absolute pathname" do
@@ -56,39 +55,10 @@ describe "File.expand_path" do
File.expand_path(".", "#{@rootdir}").should == "#{@rootdir}"
end
- # FIXME: do not use conditionals like this around #it blocks
- unless not home = ENV['HOME']
- platform_is_not :windows do
- it "converts a pathname to an absolute pathname, using ~ (home) as base" do
- File.expand_path('~').should == home
- File.expand_path('~', '/tmp/gumby/ddd').should == home
- File.expand_path('~/a', '/tmp/gumby/ddd').should == File.join(home, 'a')
- end
-
- it "does not return a frozen string" do
- File.expand_path('~').frozen?.should == false
- File.expand_path('~', '/tmp/gumby/ddd').frozen?.should == false
- File.expand_path('~/a', '/tmp/gumby/ddd').frozen?.should == false
- end
- end
- platform_is :windows do
- it "converts a pathname to an absolute pathname, using ~ (home) as base" do
- File.expand_path('~').should == home.tr("\\", '/')
- File.expand_path('~', '/tmp/gumby/ddd').should == home.tr("\\", '/')
- File.expand_path('~/a', '/tmp/gumby/ddd').should == File.join(home.tr("\\", '/'), 'a')
- end
-
- it "does not return a frozen string" do
- File.expand_path('~').frozen?.should == false
- File.expand_path('~', '/tmp/gumby/ddd').frozen?.should == false
- File.expand_path('~/a', '/tmp/gumby/ddd').frozen?.should == false
- end
- end
- end
-
platform_is_not :windows do
before do
- @home = ENV['HOME'].chomp('/')
+ @var_home = ENV['HOME'].chomp('/')
+ @db_home = Dir.home(ENV['USER'])
end
# FIXME: these are insane!
@@ -100,17 +70,17 @@ describe "File.expand_path" do
File.expand_path("../bin", "x/../tmp").should == File.join(@base, 'bin')
end
- it "expand_path for commoms unix path give a full path" do
+ it "expand_path for common unix path gives a full path" do
File.expand_path('/tmp/').should =='/tmp'
File.expand_path('/tmp/../../../tmp').should == '/tmp'
File.expand_path('').should == Dir.pwd
File.expand_path('./////').should == Dir.pwd
File.expand_path('.').should == Dir.pwd
File.expand_path(Dir.pwd).should == Dir.pwd
- File.expand_path('~/').should == @home
- File.expand_path('~/..badfilename').should == "#{@home}/..badfilename"
- File.expand_path('..').should == Dir.pwd.split('/')[0...-1].join("/")
- File.expand_path('~/a','~/b').should == "#{@home}/a"
+ File.expand_path('~/').should == @var_home
+ File.expand_path('~/..badfilename').should == "#{@var_home}/..badfilename"
+ File.expand_path('~/a','~/b').should == "#{@var_home}/a"
+ File.expand_path('..').should == File.dirname(Dir.pwd)
end
it "does not replace multiple '/' at the beginning of the path" do
@@ -122,12 +92,15 @@ describe "File.expand_path" do
end
it "raises an ArgumentError if the path is not valid" do
- lambda { File.expand_path("~a_not_existing_user") }.should raise_error(ArgumentError)
+ -> { File.expand_path("~a_not_existing_user") }.should.raise(ArgumentError)
end
it "expands ~ENV['USER'] to the user's home directory" do
- File.expand_path("~#{ENV['USER']}").should == @home
- File.expand_path("~#{ENV['USER']}/a").should == "#{@home}/a"
+ File.expand_path("~#{ENV['USER']}").should == @db_home
+ end
+
+ it "expands ~ENV['USER']/a to a in the user's home directory" do
+ File.expand_path("~#{ENV['USER']}/a").should == "#{@db_home}/a"
end
it "does not expand ~ENV['USER'] when it's not at the start" do
@@ -135,7 +108,7 @@ describe "File.expand_path" do
end
it "expands ../foo with ~/dir as base dir to /path/to/user/home/foo" do
- File.expand_path('../foo', '~/dir').should == "#{@home}/foo"
+ File.expand_path('../foo', '~/dir').should == "#{@var_home}/foo"
end
end
@@ -144,9 +117,9 @@ describe "File.expand_path" do
end
it "raises a TypeError if not passed a String type" do
- lambda { File.expand_path(1) }.should raise_error(TypeError)
- lambda { File.expand_path(nil) }.should raise_error(TypeError)
- lambda { File.expand_path(true) }.should raise_error(TypeError)
+ -> { File.expand_path(1) }.should.raise(TypeError)
+ -> { File.expand_path(nil) }.should.raise(TypeError)
+ -> { File.expand_path(true) }.should.raise(TypeError)
end
platform_is_not :windows do
@@ -161,34 +134,32 @@ describe "File.expand_path" do
end
end
- with_feature :encoding do
- it "returns a String in the same encoding as the argument" do
- Encoding.default_external = Encoding::SHIFT_JIS
+ it "returns a String in the same encoding as the argument" do
+ Encoding.default_external = Encoding::SHIFT_JIS
- path = "./a".force_encoding Encoding::CP1251
- File.expand_path(path).encoding.should equal(Encoding::CP1251)
+ path = "./a".dup.force_encoding Encoding::CP1251
+ File.expand_path(path).encoding.should.equal?(Encoding::CP1251)
- weird_path = [222, 173, 190, 175].pack('C*')
- File.expand_path(weird_path).encoding.should equal(Encoding::ASCII_8BIT)
- end
+ weird_path = [222, 173, 190, 175].pack('C*')
+ File.expand_path(weird_path).encoding.should.equal?(Encoding::BINARY)
+ end
- platform_is_not :windows do
- it "expands a path when the default external encoding is ASCII-8BIT" do
- Encoding.default_external = Encoding::ASCII_8BIT
- path_8bit = [222, 173, 190, 175].pack('C*')
- File.expand_path( path_8bit, @rootdir).should == "#{@rootdir}" + path_8bit
- end
+ platform_is_not :windows do
+ it "expands a path when the default external encoding is BINARY" do
+ Encoding.default_external = Encoding::BINARY
+ path_8bit = [222, 173, 190, 175].pack('C*')
+ File.expand_path( path_8bit, @rootdir).should == "#{@rootdir}" + path_8bit
end
+ end
- it "expands a path with multi-byte characters" do
- File.expand_path("Ångström").should == "#{@base}/Ångström"
- end
+ it "expands a path with multi-byte characters" do
+ File.expand_path("Ångström").should == "#{@base}/Ångström"
+ end
- platform_is_not :windows do
- it "raises an Encoding::CompatibilityError if the external encoding is not compatible" do
- Encoding.default_external = Encoding::UTF_16BE
- lambda { File.expand_path("./a") }.should raise_error(Encoding::CompatibilityError)
- end
+ platform_is_not :windows do
+ it "raises an Encoding::CompatibilityError if the external encoding is not compatible" do
+ Encoding.default_external = Encoding::UTF_16BE
+ -> { File.expand_path("./a") }.should.raise(Encoding::CompatibilityError)
end
end
@@ -208,11 +179,37 @@ describe "File.expand_path" do
str = FileSpecs::SubString.new "./a/b/../c"
path = File.expand_path(str, @base)
path.should == "#{@base}/a/c"
- path.should be_an_instance_of(String)
+ path.should.instance_of?(String)
end
end
platform_is_not :windows do
+ describe "File.expand_path when HOME is set" do
+ before :each do
+ @home = ENV["HOME"]
+ ENV["HOME"] = "/rubyspec_home"
+ end
+
+ after :each do
+ ENV["HOME"] = @home
+ end
+
+ it "converts a pathname to an absolute pathname, using ~ (home) as base" do
+ home = "/rubyspec_home"
+ File.expand_path('~').should == home
+ File.expand_path('~', '/tmp/gumby/ddd').should == home
+ File.expand_path('~/a', '/tmp/gumby/ddd').should == File.join(home, 'a')
+ end
+
+ it "does not return a frozen string" do
+ home = "/rubyspec_home"
+ File.expand_path('~').should_not.frozen?
+ File.expand_path('~', '/tmp/gumby/ddd').should_not.frozen?
+ File.expand_path('~/a', '/tmp/gumby/ddd').should_not.frozen?
+ end
+ end
+
+
describe "File.expand_path when HOME is not set" do
before :each do
@home = ENV["HOME"]
@@ -222,21 +219,47 @@ platform_is_not :windows do
ENV["HOME"] = @home
end
- ruby_version_is ''...'2.4' do
- it "raises an ArgumentError when passed '~' if HOME is nil" do
+ guard -> {
+ # We need to check if getlogin(3) returns non-NULL,
+ # as MRI only checks getlogin(3) for expanding '~' if $HOME is not set.
+ user = ENV.delete("USER")
+ begin
+ Etc.getlogin != nil
+ rescue
+ false
+ ensure
+ ENV["USER"] = user
+ end
+ } do
+ it "uses the user database when passed '~' if HOME is nil" do
ENV.delete "HOME"
- lambda { File.expand_path("~") }.should raise_error(ArgumentError)
+ File.directory?(File.expand_path("~")).should == true
end
- it "raises an ArgumentError when passed '~/' if HOME is nil" do
+ it "uses the user database when passed '~/' if HOME is nil" do
ENV.delete "HOME"
- lambda { File.expand_path("~/") }.should raise_error(ArgumentError)
+ File.directory?(File.expand_path("~/")).should == true
end
end
it "raises an ArgumentError when passed '~' if HOME == ''" do
ENV["HOME"] = ""
- lambda { File.expand_path("~") }.should raise_error(ArgumentError)
+ -> { File.expand_path("~") }.should.raise(ArgumentError)
+ end
+ end
+
+ describe "File.expand_path with a non-absolute HOME" do
+ before :each do
+ @home = ENV["HOME"]
+ end
+
+ after :each do
+ ENV["HOME"] = @home
+ end
+
+ it "raises an ArgumentError" do
+ ENV["HOME"] = "non-absolute"
+ -> { File.expand_path("~") }.should.raise(ArgumentError, 'non-absolute home')
end
end
end
diff --git a/spec/ruby/core/file/extname_spec.rb b/spec/ruby/core/file/extname_spec.rb
index fedd4fc89f..995d0ea31a 100644
--- a/spec/ruby/core/file/extname_spec.rb
+++ b/spec/ruby/core/file/extname_spec.rb
@@ -1,8 +1,8 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "File.extname" do
- it "returns the extension (the portion of file name in path after the period)." do
+ it "returns the extension (the portion of file name in path after the period)" do
File.extname("foo.rb").should == ".rb"
File.extname("/foo/bar.rb").should == ".rb"
File.extname("/foo.rb/bar.c").should == ".c"
@@ -12,7 +12,17 @@ describe "File.extname" do
File.extname(".app.conf").should == ".conf"
end
- it "returns the extension (the portion of file name in path after the period).(edge cases)" do
+ it "returns unfrozen strings" do
+ File.extname("foo.rb").frozen?.should == false
+ File.extname("/foo/bar.rb").frozen?.should == false
+ File.extname("/foo.rb/bar.c").frozen?.should == false
+ File.extname("bar").frozen?.should == false
+ File.extname(".bashrc").frozen?.should == false
+ File.extname("/foo.bar/baz").frozen?.should == false
+ File.extname(".app.conf").frozen?.should == false
+ end
+
+ it "returns the extension for edge cases" do
File.extname("").should == ""
File.extname(".").should == ""
File.extname("/").should == ""
@@ -20,8 +30,22 @@ describe "File.extname" do
File.extname("..").should == ""
File.extname("...").should == ""
File.extname("....").should == ""
- File.extname(".foo.").should == ""
- File.extname("foo.").should == ""
+ end
+
+ describe "for a filename ending with a dot" do
+ platform_is :windows do
+ it "returns ''" do
+ File.extname(".foo.").should == ""
+ File.extname("foo.").should == ""
+ end
+ end
+
+ platform_is_not :windows do
+ it "returns '.'" do
+ File.extname(".foo.").should == "."
+ File.extname("foo.").should == "."
+ end
+ end
end
it "returns only the last extension of a file with several dots" do
@@ -33,22 +57,20 @@ describe "File.extname" do
end
it "raises a TypeError if not passed a String type" do
- lambda { File.extname(nil) }.should raise_error(TypeError)
- lambda { File.extname(0) }.should raise_error(TypeError)
- lambda { File.extname(true) }.should raise_error(TypeError)
- lambda { File.extname(false) }.should raise_error(TypeError)
+ -> { File.extname(nil) }.should.raise(TypeError)
+ -> { File.extname(0) }.should.raise(TypeError)
+ -> { File.extname(true) }.should.raise(TypeError)
+ -> { File.extname(false) }.should.raise(TypeError)
end
it "raises an ArgumentError if not passed one argument" do
- lambda { File.extname }.should raise_error(ArgumentError)
- lambda { File.extname("foo.bar", "foo.baz") }.should raise_error(ArgumentError)
+ -> { File.extname }.should.raise(ArgumentError)
+ -> { File.extname("foo.bar", "foo.baz") }.should.raise(ArgumentError)
end
- with_feature :encoding do
-
- it "returns the extension for a multibyte filename" do
- File.extname('ИмÑ.m4a').should == ".m4a"
- end
+ it "returns the extension for a multibyte filename" do
+ File.extname('ИмÑ.m4a').should == ".m4a"
end
+
end
diff --git a/spec/ruby/core/file/file_spec.rb b/spec/ruby/core/file/file_spec.rb
index 99eaacd086..8a9dfd5fe2 100644
--- a/spec/ruby/core/file/file_spec.rb
+++ b/spec/ruby/core/file/file_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/file/file', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../../shared/file/file'
describe "File" do
it "includes Enumerable" do
diff --git a/spec/ruby/core/file/fixtures/file_types.rb b/spec/ruby/core/file/fixtures/file_types.rb
index 36a5ff1a95..109bcfe42e 100644
--- a/spec/ruby/core/file/fixtures/file_types.rb
+++ b/spec/ruby/core/file/fixtures/file_types.rb
@@ -5,17 +5,11 @@ module FileSpecs
@file = tmp("test.txt")
@dir = Dir.pwd
@fifo = tmp("test_fifo")
+ @link = tmp("test_link")
platform_is_not :windows do
- @block = `find /dev /devices -type b 2> /dev/null`.split("\n").first
- @char = `find /dev /devices -type c 2> /dev/null`.split("\n").last
-
- %w[/dev /usr/bin /usr/local/bin].each do |dir|
- links = `find #{dir} -type l 2> /dev/null`.split("\n")
- next if links.empty?
- @link = links.first
- break
- end
+ @block = `find /dev /devices -type b 2>/dev/null`.split("\n").first
+ @char = `{ tty || find /dev /devices -type c; } 2>/dev/null`.split("\n").last
end
@configured = true
@@ -32,33 +26,41 @@ module FileSpecs
yield @dir
end
- # TODO: need a platform-independent helper here
def self.fifo
- system "mkfifo #{@fifo} 2> /dev/null"
+ File.mkfifo(@fifo)
yield @fifo
ensure
rm_r @fifo
end
def self.block_device
+ raise "Could not find a block device" unless @block
yield @block
end
def self.character_device
+ raise "Could not find a character device" unless @char
yield @char
end
def self.symlink
+ touch(@file)
+ File.symlink(@file, @link)
yield @link
+ ensure
+ rm_r @file, @link
end
def self.socket
- require 'socket'
- name = tmp("ftype_socket.socket")
- rm_r name
+ require_relative '../../../library/socket/fixtures/classes.rb'
+
+ name = SocketSpecs.socket_path
socket = UNIXServer.new name
- yield name
- socket.close
- rm_r name
+ begin
+ yield name
+ ensure
+ socket.close
+ rm_r name
+ end
end
end
diff --git a/spec/ruby/core/file/flock_spec.rb b/spec/ruby/core/file/flock_spec.rb
index e14d4252d4..23ddf89ed8 100644
--- a/spec/ruby/core/file/flock_spec.rb
+++ b/spec/ruby/core/file/flock_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "File#flock" do
before :each do
@@ -30,7 +30,7 @@ describe "File#flock" do
it "returns false if trying to lock an exclusively locked file" do
@file.flock File::LOCK_EX
- ruby_exe(<<-END_OF_CODE, escape: true).should == "false"
+ ruby_exe(<<-END_OF_CODE).should == "false"
File.open('#{@name}', "w") do |f2|
print f2.flock(File::LOCK_EX | File::LOCK_NB).to_s
end
@@ -40,7 +40,7 @@ describe "File#flock" do
it "blocks if trying to lock an exclusively locked file" do
@file.flock File::LOCK_EX
- out = ruby_exe(<<-END_OF_CODE, escape: true)
+ out = ruby_exe(<<-END_OF_CODE)
running = false
t = Thread.new do
@@ -72,35 +72,3 @@ describe "File#flock" do
end
end
end
-
-platform_is :solaris do
- describe "File#flock on Solaris" do
- before :each do
- @name = tmp("flock_test")
- touch(@name)
-
- @read_file = File.open @name, "r"
- @write_file = File.open @name, "w"
- end
-
- after :each do
- @read_file.flock File::LOCK_UN
- @read_file.close
- @write_file.flock File::LOCK_UN
- @write_file.close
- rm_r @name
- end
-
- it "fails with EBADF acquiring exclusive lock on read-only File" do
- lambda do
- @read_file.flock File::LOCK_EX
- end.should raise_error(Errno::EBADF)
- end
-
- it "fails with EBADF acquiring shared lock on read-only File" do
- lambda do
- @write_file.flock File::LOCK_SH
- end.should raise_error(Errno::EBADF)
- end
- end
-end
diff --git a/spec/ruby/core/file/fnmatch_spec.rb b/spec/ruby/core/file/fnmatch_spec.rb
index 8a4caacfb8..44a143bddc 100644
--- a/spec/ruby/core/file/fnmatch_spec.rb
+++ b/spec/ruby/core/file/fnmatch_spec.rb
@@ -1,10 +1,302 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/fnmatch', __FILE__)
+require_relative '../../spec_helper'
describe "File.fnmatch" do
- it_behaves_like(:file_fnmatch, :fnmatch)
+ it "matches entire strings" do
+ File.fnmatch('cat', 'cat').should == true
+ end
+
+ it "does not match partial strings" do
+ File.fnmatch('cat', 'category').should == false
+ end
+
+ it "does not support { } patterns by default" do
+ File.fnmatch('c{at,ub}s', 'cats').should == false
+ File.fnmatch('c{at,ub}s', 'c{at,ub}s').should == true
+ end
+
+ it "supports some { } patterns when File::FNM_EXTGLOB is passed" do
+ File.fnmatch("{a,b}", "a", File::FNM_EXTGLOB).should == true
+ File.fnmatch("{a,b}", "b", File::FNM_EXTGLOB).should == true
+ File.fnmatch("c{at,ub}s", "cats", File::FNM_EXTGLOB).should == true
+ File.fnmatch("c{at,ub}s", "cubs", File::FNM_EXTGLOB).should == true
+ File.fnmatch("-c{at,ub}s-", "-cats-", File::FNM_EXTGLOB).should == true
+ File.fnmatch("-c{at,ub}s-", "-cubs-", File::FNM_EXTGLOB).should == true
+ File.fnmatch("{a,b,c}{d,e,f}{g,h}", "adg", File::FNM_EXTGLOB).should == true
+ File.fnmatch("{a,b,c}{d,e,f}{g,h}", "bdg", File::FNM_EXTGLOB).should == true
+ File.fnmatch("{a,b,c}{d,e,f}{g,h}", "ceh", File::FNM_EXTGLOB).should == true
+ File.fnmatch("{aa,bb,cc,dd}", "aa", File::FNM_EXTGLOB).should == true
+ File.fnmatch("{aa,bb,cc,dd}", "bb", File::FNM_EXTGLOB).should == true
+ File.fnmatch("{aa,bb,cc,dd}", "cc", File::FNM_EXTGLOB).should == true
+ File.fnmatch("{aa,bb,cc,dd}", "dd", File::FNM_EXTGLOB).should == true
+ File.fnmatch("{1,5{a,b{c,d}}}", "1", File::FNM_EXTGLOB).should == true
+ File.fnmatch("{1,5{a,b{c,d}}}", "5a", File::FNM_EXTGLOB).should == true
+ File.fnmatch("{1,5{a,b{c,d}}}", "5bc", File::FNM_EXTGLOB).should == true
+ File.fnmatch("{1,5{a,b{c,d}}}", "5bd", File::FNM_EXTGLOB).should == true
+ File.fnmatch("\\\\{a\\,b,b\\}c}", "\\a,b", File::FNM_EXTGLOB).should == true
+ File.fnmatch("\\\\{a\\,b,b\\}c}", "\\b}c", File::FNM_EXTGLOB).should == true
+ end
+
+ it "doesn't support some { } patterns even when File::FNM_EXTGLOB is passed" do
+ File.fnmatch("a{0..3}b", "a0b", File::FNM_EXTGLOB).should == false
+ File.fnmatch("a{0..3}b", "a1b", File::FNM_EXTGLOB).should == false
+ File.fnmatch("a{0..3}b", "a2b", File::FNM_EXTGLOB).should == false
+ File.fnmatch("a{0..3}b", "a3b", File::FNM_EXTGLOB).should == false
+ File.fnmatch("{0..12}", "0", File::FNM_EXTGLOB).should == false
+ File.fnmatch("{0..12}", "6", File::FNM_EXTGLOB).should == false
+ File.fnmatch("{0..12}", "12", File::FNM_EXTGLOB).should == false
+ File.fnmatch("{3..-2}", "3", File::FNM_EXTGLOB).should == false
+ File.fnmatch("{3..-2}", "0", File::FNM_EXTGLOB).should == false
+ File.fnmatch("{3..-2}", "-2", File::FNM_EXTGLOB).should == false
+ File.fnmatch("{a..g}", "a", File::FNM_EXTGLOB).should == false
+ File.fnmatch("{a..g}", "d", File::FNM_EXTGLOB).should == false
+ File.fnmatch("{a..g}", "g", File::FNM_EXTGLOB).should == false
+ File.fnmatch("{g..a}", "a", File::FNM_EXTGLOB).should == false
+ File.fnmatch("{g..a}", "d", File::FNM_EXTGLOB).should == false
+ File.fnmatch("{g..a}", "g", File::FNM_EXTGLOB).should == false
+ File.fnmatch("escaping: {{,\\,,\\},\\{}", "escaping: {", File::FNM_EXTGLOB).should == false
+ File.fnmatch("escaping: {{,\\,,\\},\\{}", "escaping: ,", File::FNM_EXTGLOB).should == false
+ File.fnmatch("escaping: {{,\\,,\\},\\{}", "escaping: }", File::FNM_EXTGLOB).should == false
+ File.fnmatch("escaping: {{,\\,,\\},\\{}", "escaping: {", File::FNM_EXTGLOB).should == false
+ end
+
+ it "doesn't match an extra } when File::FNM_EXTGLOB is passed" do
+ File.fnmatch('c{at,ub}}s', 'cats', File::FNM_EXTGLOB).should == false
+ end
+
+ it "matches when both FNM_EXTGLOB and FNM_PATHNAME are passed" do
+ File.fnmatch("?.md", "a.md", File::FNM_EXTGLOB | File::FNM_PATHNAME).should == true
+ end
+
+ it "matches a single character for each ? character" do
+ File.fnmatch('c?t', 'cat').should == true
+ File.fnmatch('c??t', 'cat').should == false
+ end
+
+ it "matches zero or more characters for each * character" do
+ File.fnmatch('c*', 'cats').should == true
+ File.fnmatch('c*t', 'c/a/b/t').should == true
+ end
+
+ it "does not match unterminated range of characters" do
+ File.fnmatch('abc[de', 'abcd').should == false
+ end
+
+ it "does not match unterminated range of characters as a literal" do
+ File.fnmatch('abc[de', 'abc[de').should == false
+ end
+
+ it "matches ranges of characters using bracket expression (e.g. [a-z])" do
+ File.fnmatch('ca[a-z]', 'cat').should == true
+ end
+
+ it "matches ranges of characters using bracket expression, taking case into account" do
+ File.fnmatch('[a-z]', 'D').should == false
+ File.fnmatch('[^a-z]', 'D').should == true
+ File.fnmatch('[A-Z]', 'd').should == false
+ File.fnmatch('[^A-Z]', 'd').should == true
+ File.fnmatch('[a-z]', 'D', File::FNM_CASEFOLD).should == true
+ end
+
+ it "does not match characters outside of the range of the bracket expression" do
+ File.fnmatch('ca[x-z]', 'cat').should == false
+ File.fnmatch('/ca[s][s-t]/rul[a-b]/[z]he/[x-Z]orld', '/cats/rule/the/World').should == false
+ end
+
+ it "matches ranges of characters using exclusive bracket expression (e.g. [^t] or [!t])" do
+ File.fnmatch('ca[^t]', 'cat').should == false
+ File.fnmatch('ca[^t]', 'cas').should == true
+ File.fnmatch('ca[!t]', 'cat').should == false
+ end
+
+ it "matches characters with a case sensitive comparison" do
+ File.fnmatch('cat', 'CAT').should == false
+ end
+
+ it "matches characters with case insensitive comparison when flags includes FNM_CASEFOLD" do
+ File.fnmatch('cat', 'CAT', File::FNM_CASEFOLD).should == true
+ end
+
+ platform_is_not :windows do
+ it "doesn't match case sensitive characters on platforms with case sensitive paths, when flags include FNM_SYSCASE" do
+ File.fnmatch('cat', 'CAT', File::FNM_SYSCASE).should == false
+ end
+ end
+
+ platform_is :windows do
+ it "matches case sensitive characters on platforms with case insensitive paths, when flags include FNM_SYSCASE" do
+ File.fnmatch('cat', 'CAT', File::FNM_SYSCASE).should == true
+ end
+ end
+
+ it "matches wildcard with characters when flags includes FNM_PATHNAME" do
+ File.fnmatch('*a', 'aa', File::FNM_PATHNAME).should == true
+ File.fnmatch('a*', 'aa', File::FNM_PATHNAME).should == true
+ File.fnmatch('a*', 'aaa', File::FNM_PATHNAME).should == true
+ File.fnmatch('*a', 'aaa', File::FNM_PATHNAME).should == true
+ end
+
+ it "does not match '/' characters with ? or * when flags includes FNM_PATHNAME" do
+ File.fnmatch('?', '/', File::FNM_PATHNAME).should == false
+ File.fnmatch('*', '/', File::FNM_PATHNAME).should == false
+ end
+
+ it "does not match '/' characters inside bracket expressions when flags includes FNM_PATHNAME" do
+ File.fnmatch('[/]', '/', File::FNM_PATHNAME).should == false
+ end
+
+ it "matches literal ? or * in path when pattern includes \\? or \\*" do
+ File.fnmatch('\?', '?').should == true
+ File.fnmatch('\?', 'a').should == false
+
+ File.fnmatch('\*', '*').should == true
+ File.fnmatch('\*', 'a').should == false
+ end
+
+ it "matches literal character (e.g. 'a') in path when pattern includes escaped character (e.g. \\a)" do
+ File.fnmatch('\a', 'a').should == true
+ File.fnmatch('this\b', 'thisb').should == true
+ end
+
+ it "matches '\\' characters in path when flags includes FNM_NOESCAPE" do
+ File.fnmatch('\a', '\a', File::FNM_NOESCAPE).should == true
+ File.fnmatch('\a', 'a', File::FNM_NOESCAPE).should == false
+ File.fnmatch('\[foo\]\[bar\]', '[foo][bar]', File::FNM_NOESCAPE).should == false
+ end
+
+ it "escapes special characters inside bracket expression" do
+ File.fnmatch('[\?]', '?').should == true
+ File.fnmatch('[\*]', '*').should == true
+ end
+
+ it "does not match leading periods in filenames with wildcards by default" do
+ File.should_not.fnmatch('*', '.profile')
+ File.should.fnmatch('*', 'home/.profile')
+ File.should.fnmatch('*/*', 'home/.profile')
+ File.should_not.fnmatch('*/*', 'dave/.profile', File::FNM_PATHNAME)
+ end
+
+ it "matches patterns with leading periods to dotfiles" do
+ File.fnmatch('.*', '.profile').should == true
+ File.fnmatch('.*', '.profile', File::FNM_PATHNAME).should == true
+ File.fnmatch(".*file", "nondotfile").should == false
+ File.fnmatch(".*file", "nondotfile", File::FNM_PATHNAME).should == false
+ end
+
+ it "does not match directories with leading periods by default with FNM_PATHNAME" do
+ File.fnmatch('.*', '.directory/nondotfile', File::FNM_PATHNAME).should == false
+ File.fnmatch('.*', '.directory/.profile', File::FNM_PATHNAME).should == false
+ File.fnmatch('.*', 'foo/.directory/nondotfile', File::FNM_PATHNAME).should == false
+ File.fnmatch('.*', 'foo/.directory/.profile', File::FNM_PATHNAME).should == false
+ File.fnmatch('**/.dotfile', '.dotsubdir/.dotfile', File::FNM_PATHNAME).should == false
+ end
+
+ it "matches leading periods in filenames when flags includes FNM_DOTMATCH" do
+ File.fnmatch('*', '.profile', File::FNM_DOTMATCH).should == true
+ File.fnmatch('*', 'home/.profile', File::FNM_DOTMATCH).should == true
+ end
+
+ it "matches multiple directories with ** and *" do
+ files = '**/*.rb'
+ File.fnmatch(files, 'main.rb').should == false
+ File.fnmatch(files, './main.rb').should == false
+ File.fnmatch(files, 'lib/song.rb').should == true
+ File.fnmatch('**.rb', 'main.rb').should == true
+ File.fnmatch('**.rb', './main.rb').should == false
+ File.fnmatch('**.rb', 'lib/song.rb').should == true
+ File.fnmatch('*', 'dave/.profile').should == true
+ end
+
+ it "matches multiple directories with ** when flags includes File::FNM_PATHNAME" do
+ files = '**/*.rb'
+ flags = File::FNM_PATHNAME
+
+ File.fnmatch(files, 'main.rb', flags).should == true
+ File.fnmatch(files, 'one/two/three/main.rb', flags).should == true
+ File.fnmatch(files, './main.rb', flags).should == false
+
+ flags = File::FNM_PATHNAME | File::FNM_DOTMATCH
+
+ File.fnmatch(files, './main.rb', flags).should == true
+ File.fnmatch(files, 'one/two/.main.rb', flags).should == true
+
+ File.fnmatch("**/best/*", 'lib/my/best/song.rb').should == true
+ end
+
+ it "returns false if '/' in pattern do not match '/' in path when flags includes FNM_PATHNAME" do
+ pattern = '*/*'
+ File.fnmatch(pattern, 'dave/.profile', File::FNM_PATHNAME).should == false
+
+ pattern = '**/foo'
+ File.fnmatch(pattern, 'a/.b/c/foo', File::FNM_PATHNAME).should == false
+ end
+
+ it "returns true if '/' in pattern match '/' in path when flags includes FNM_PATHNAME" do
+ pattern = '*/*'
+ File.fnmatch(pattern, 'dave/.profile', File::FNM_PATHNAME | File::FNM_DOTMATCH).should == true
+
+ pattern = '**/foo'
+ File.fnmatch(pattern, 'a/b/c/foo', File::FNM_PATHNAME).should == true
+ File.fnmatch(pattern, '/a/b/c/foo', File::FNM_PATHNAME).should == true
+ File.fnmatch(pattern, 'c:/a/b/c/foo', File::FNM_PATHNAME).should == true
+ File.fnmatch(pattern, 'a/.b/c/foo', File::FNM_PATHNAME | File::FNM_DOTMATCH).should == true
+ end
+
+ it "has special handling for ./ when using * and FNM_PATHNAME" do
+ File.fnmatch('./*', '.', File::FNM_PATHNAME).should == false
+ File.fnmatch('./*', './', File::FNM_PATHNAME).should == true
+ File.fnmatch('./*/', './', File::FNM_PATHNAME).should == false
+ File.fnmatch('./**', './', File::FNM_PATHNAME).should == true
+ File.fnmatch('./**/', './', File::FNM_PATHNAME).should == true
+ File.fnmatch('./*', '.', File::FNM_PATHNAME | File::FNM_DOTMATCH).should == false
+ File.fnmatch('./*', './', File::FNM_PATHNAME | File::FNM_DOTMATCH).should == true
+ File.fnmatch('./*/', './', File::FNM_PATHNAME | File::FNM_DOTMATCH).should == false
+ File.fnmatch('./**', './', File::FNM_PATHNAME | File::FNM_DOTMATCH).should == true
+ File.fnmatch('./**/', './', File::FNM_PATHNAME | File::FNM_DOTMATCH).should == true
+ end
+
+ it "matches **/* with FNM_PATHNAME to recurse directories" do
+ File.fnmatch('nested/**/*', 'nested/subdir', File::FNM_PATHNAME).should == true
+ File.fnmatch('nested/**/*', 'nested/subdir/file', File::FNM_PATHNAME).should == true
+ File.fnmatch('nested/**/*', 'nested/.dotsubdir', File::FNM_PATHNAME | File::FNM_DOTMATCH).should == true
+ File.fnmatch('nested/**/*', 'nested/.dotsubir/.dotfile', File::FNM_PATHNAME | File::FNM_DOTMATCH).should == true
+ end
+
+ it "matches ** with FNM_PATHNAME only in current directory" do
+ File.fnmatch('nested/**', 'nested/subdir', File::FNM_PATHNAME).should == true
+ File.fnmatch('nested/**', 'nested/subdir/file', File::FNM_PATHNAME).should == false
+ File.fnmatch('nested/**', 'nested/.dotsubdir', File::FNM_PATHNAME | File::FNM_DOTMATCH).should == true
+ File.fnmatch('nested/**', 'nested/.dotsubir/.dotfile', File::FNM_PATHNAME | File::FNM_DOTMATCH).should == false
+ end
+
+ it "accepts an object that has a #to_path method" do
+ File.fnmatch('\*', mock_to_path('a')).should == false
+ end
+
+ it "raises a TypeError if the first and second arguments are not string-like" do
+ -> { File.fnmatch(nil, nil, 0, 0) }.should.raise(ArgumentError)
+ -> { File.fnmatch(1, 'some/thing') }.should.raise(TypeError)
+ -> { File.fnmatch('some/thing', 1) }.should.raise(TypeError)
+ -> { File.fnmatch(1, 1) }.should.raise(TypeError)
+ end
+
+ it "raises a TypeError if the third argument is not an Integer" do
+ -> { File.fnmatch("*/place", "path/to/file", "flags") }.should.raise(TypeError)
+ -> { File.fnmatch("*/place", "path/to/file", nil) }.should.raise(TypeError)
+ end
+
+ it "does not raise a TypeError if the third argument can be coerced to an Integer" do
+ flags = mock("flags")
+ flags.should_receive(:to_int).and_return(10)
+ -> { File.fnmatch("*/place", "path/to/file", flags) }.should_not.raise
+ end
+
+ it "matches multibyte characters" do
+ File.fnmatch("*/ä/ø/ñ", "a/ä/ø/ñ").should == true
+ end
end
describe "File.fnmatch?" do
- it_behaves_like(:file_fnmatch, :fnmatch?)
+ it "is an alias of File.fnmatch" do
+ File.method(:fnmatch?).should == File.method(:fnmatch)
+ end
end
diff --git a/spec/ruby/core/file/ftype_spec.rb b/spec/ruby/core/file/ftype_spec.rb
index 7c010b3e9c..ab9f76b79b 100644
--- a/spec/ruby/core/file/ftype_spec.rb
+++ b/spec/ruby/core/file/ftype_spec.rb
@@ -1,5 +1,5 @@
-require "#{File.dirname(__FILE__)}/../../spec_helper"
-require "#{File.dirname(__FILE__)}/fixtures/file_types"
+require_relative '../../spec_helper'
+require_relative 'fixtures/file_types'
describe "File.ftype" do
before :all do
@@ -7,18 +7,19 @@ describe "File.ftype" do
end
it "raises ArgumentError if not given exactly one filename" do
- lambda { File.ftype }.should raise_error(ArgumentError)
- lambda { File.ftype('blah', 'bleh') }.should raise_error(ArgumentError)
+ -> { File.ftype }.should.raise(ArgumentError)
+ -> { File.ftype('blah', 'bleh') }.should.raise(ArgumentError)
end
it "raises Errno::ENOENT if the file is not valid" do
- l = lambda { File.ftype("/#{$$}#{Time.now.to_f}") }
- l.should raise_error(Errno::ENOENT)
+ -> {
+ File.ftype("/#{$$}#{Time.now.to_f}")
+ }.should.raise(Errno::ENOENT)
end
it "returns a String" do
FileSpecs.normal_file do |file|
- File.ftype(file).should be_kind_of(String)
+ File.ftype(file).should.is_a?(String)
end
end
@@ -34,6 +35,14 @@ describe "File.ftype" do
end
end
+ it "uses to_path to convert arguments" do
+ FileSpecs.normal_file do |file|
+ obj = mock('path')
+ obj.should_receive(:to_path).and_return(file)
+ File.ftype(obj).should == 'file'
+ end
+ end
+
# Both FreeBSD and Windows does not have block devices
platform_is_not :freebsd, :windows do
with_block_device do
diff --git a/spec/ruby/core/file/grpowned_spec.rb b/spec/ruby/core/file/grpowned_spec.rb
index 0b5514d7ca..8ddac5237c 100644
--- a/spec/ruby/core/file/grpowned_spec.rb
+++ b/spec/ruby/core/file/grpowned_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/file/grpowned', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../../shared/file/grpowned'
describe "File.grpowned?" do
it_behaves_like :file_grpowned, :grpowned?, File
diff --git a/spec/ruby/core/file/identical_spec.rb b/spec/ruby/core/file/identical_spec.rb
index 303337b62d..bbeaef24d2 100644
--- a/spec/ruby/core/file/identical_spec.rb
+++ b/spec/ruby/core/file/identical_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/file/identical', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../../shared/file/identical'
describe "File.identical?" do
it_behaves_like :file_identical, :identical?, File
diff --git a/spec/ruby/core/file/initialize_spec.rb b/spec/ruby/core/file/initialize_spec.rb
index 269e13b3ca..9a76a95260 100644
--- a/spec/ruby/core/file/initialize_spec.rb
+++ b/spec/ruby/core/file/initialize_spec.rb
@@ -1,8 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "File#initialize" do
- it "needs to be reviewed for spec completeness"
-end
+require_relative '../../spec_helper'
describe "File#initialize" do
after :each do
diff --git a/spec/ruby/core/file/inspect_spec.rb b/spec/ruby/core/file/inspect_spec.rb
index a059fa2c48..fe87429e8d 100644
--- a/spec/ruby/core/file/inspect_spec.rb
+++ b/spec/ruby/core/file/inspect_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "File#inspect" do
before :each do
@@ -12,6 +12,6 @@ describe "File#inspect" do
end
it "returns a String" do
- @file.inspect.should be_an_instance_of(String)
+ @file.inspect.should.instance_of?(String)
end
end
diff --git a/spec/ruby/core/file/join_spec.rb b/spec/ruby/core/file/join_spec.rb
index 7c5955d03b..0f0911ea31 100644
--- a/spec/ruby/core/file/join_spec.rb
+++ b/spec/ruby/core/file/join_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "File.join" do
# see [ruby-core:46804] for the 4 following rules
@@ -52,7 +52,7 @@ describe "File.join" do
it "returns a duplicate string when given a single argument" do
str = "usr"
File.join(str).should == str
- File.join(str).should_not equal(str)
+ File.join(str).should_not.equal?(str)
end
it "supports any number of arguments" do
@@ -104,15 +104,15 @@ describe "File.join" do
it "raises an ArgumentError if passed a recursive array" do
a = ["a"]
a << a
- lambda { File.join a }.should raise_error(ArgumentError)
+ -> { File.join a }.should.raise(ArgumentError)
end
it "raises a TypeError exception when args are nil" do
- lambda { File.join nil }.should raise_error(TypeError)
+ -> { File.join nil }.should.raise(TypeError)
end
it "calls #to_str" do
- lambda { File.join(mock('x')) }.should raise_error(TypeError)
+ -> { File.join(mock('x')) }.should.raise(TypeError)
bin = mock("bin")
bin.should_receive(:to_str).exactly(:twice).and_return("bin")
@@ -129,11 +129,20 @@ describe "File.join" do
end
it "calls #to_path" do
- lambda { File.join(mock('x')) }.should raise_error(TypeError)
+ -> { File.join(mock('x')) }.should.raise(TypeError)
bin = mock("bin")
bin.should_receive(:to_path).exactly(:twice).and_return("bin")
File.join(bin).should == "bin"
File.join("usr", bin).should == "usr/bin"
end
+
+ it "raises errors for null bytes" do
+ -> { File.join("\x00x", "metadata.gz") }.should.raise(ArgumentError) { |e|
+ e.message.should == 'string contains null byte'
+ }
+ -> { File.join("metadata.gz", "\x00x") }.should.raise(ArgumentError) { |e|
+ e.message.should == 'string contains null byte'
+ }
+ end
end
diff --git a/spec/ruby/core/file/lchmod_spec.rb b/spec/ruby/core/file/lchmod_spec.rb
index 2ce265841e..3c44374983 100644
--- a/spec/ruby/core/file/lchmod_spec.rb
+++ b/spec/ruby/core/file/lchmod_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "File.lchmod" do
- platform_is_not :linux, :windows, :openbsd, :solaris, :aix do
+ platform_is_not :linux, :windows, :openbsd, :aix do
before :each do
@fname = tmp('file_chmod_test')
@lname = @fname + '.lnk'
@@ -20,23 +20,13 @@ describe "File.lchmod" do
File.chmod(0222, @lname).should == 1
File.lchmod(0755, @lname).should == 1
- File.lstat(@lname).executable?.should == true
- File.lstat(@lname).readable?.should == true
- File.lstat(@lname).writable?.should == true
+ File.lstat(@lname).should.executable?
+ File.lstat(@lname).should.readable?
+ File.lstat(@lname).should.writable?
- File.stat(@lname).executable?.should == false
- File.stat(@lname).readable?.should == false
- File.stat(@lname).writable?.should == true
- end
- end
-
- platform_is :linux, :openbsd, :aix do
- it "returns false from #respond_to?" do
- File.respond_to?(:lchmod).should be_false
- end
-
- it "raises a NotImplementedError when called" do
- lambda { File.lchmod 0 }.should raise_error(NotImplementedError)
+ File.stat(@lname).should_not.executable?
+ File.stat(@lname).should_not.readable?
+ File.stat(@lname).should.writable?
end
end
end
diff --git a/spec/ruby/core/file/lchown_spec.rb b/spec/ruby/core/file/lchown_spec.rb
index 814b0bf534..8d95d287ba 100644
--- a/spec/ruby/core/file/lchown_spec.rb
+++ b/spec/ruby/core/file/lchown_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
as_superuser do
describe "File.lchown" do
@@ -57,7 +57,3 @@ as_superuser do
end
end
end
-
-describe "File.lchown" do
- it "needs to be reviewed for spec completeness"
-end
diff --git a/spec/ruby/core/file/link_spec.rb b/spec/ruby/core/file/link_spec.rb
index 69d1459672..768ee4b0fa 100644
--- a/spec/ruby/core/file/link_spec.rb
+++ b/spec/ruby/core/file/link_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "File.link" do
before :each do
@@ -13,27 +13,27 @@ describe "File.link" do
rm_r @link, @file
end
- platform_is_not :windows do
+ platform_is_not :windows, :android do
it "link a file with another" do
File.link(@file, @link).should == 0
- File.exist?(@link).should == true
+ File.should.exist?(@link)
File.identical?(@file, @link).should == true
end
it "raises an Errno::EEXIST if the target already exists" do
File.link(@file, @link)
- lambda { File.link(@file, @link) }.should raise_error(Errno::EEXIST)
+ -> { File.link(@file, @link) }.should.raise(Errno::EEXIST)
end
it "raises an ArgumentError if not passed two arguments" do
- lambda { File.link }.should raise_error(ArgumentError)
- lambda { File.link(@file) }.should raise_error(ArgumentError)
- lambda { File.link(@file, @link, @file) }.should raise_error(ArgumentError)
+ -> { File.link }.should.raise(ArgumentError)
+ -> { File.link(@file) }.should.raise(ArgumentError)
+ -> { File.link(@file, @link, @file) }.should.raise(ArgumentError)
end
it "raises a TypeError if not passed String types" do
- lambda { File.link(@file, nil) }.should raise_error(TypeError)
- lambda { File.link(@file, 1) }.should raise_error(TypeError)
+ -> { File.link(@file, nil) }.should.raise(TypeError)
+ -> { File.link(@file, 1) }.should.raise(TypeError)
end
end
end
diff --git a/spec/ruby/core/file/lstat_spec.rb b/spec/ruby/core/file/lstat_spec.rb
index 6657bfa00e..a5ea9d15a5 100644
--- a/spec/ruby/core/file/lstat_spec.rb
+++ b/spec/ruby/core/file/lstat_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/stat', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/stat'
describe "File.lstat" do
it_behaves_like :file_stat, :lstat
@@ -22,8 +22,8 @@ describe "File.lstat" do
it "returns a File::Stat object with symlink properties for a symlink" do
st = File.lstat(@link)
- st.symlink?.should == true
- st.file?.should == false
+ st.should.symlink?
+ st.should_not.file?
end
end
end
diff --git a/spec/ruby/core/file/lutime_spec.rb b/spec/ruby/core/file/lutime_spec.rb
new file mode 100644
index 0000000000..0f6df42ea3
--- /dev/null
+++ b/spec/ruby/core/file/lutime_spec.rb
@@ -0,0 +1,43 @@
+require_relative '../../spec_helper'
+require_relative 'shared/update_time'
+
+platform_is_not :windows do
+ describe "File.lutime" do
+ it_behaves_like :update_time, :lutime
+ end
+
+ describe "File.lutime" do
+ before :each do
+ @atime = Time.utc(2000)
+ @mtime = Time.utc(2001)
+ @file = tmp("specs_lutime_file")
+ @symlink = tmp("specs_lutime_symlink")
+ touch @file
+ File.symlink(@file, @symlink)
+ end
+
+ after :each do
+ rm_r @file, @symlink
+ end
+
+ it "sets the access and modification time for a regular file" do
+ File.lutime(@atime, @mtime, @file)
+ stat = File.stat(@file)
+ stat.atime.should == @atime
+ stat.mtime.should === @mtime
+ end
+
+ it "sets the access and modification time for a symlink" do
+ original = File.stat(@file)
+
+ File.lutime(@atime, @mtime, @symlink)
+ stat = File.lstat(@symlink)
+ stat.atime.should == @atime
+ stat.mtime.should === @mtime
+
+ file = File.stat(@file)
+ file.atime.should == original.atime
+ file.mtime.should == original.mtime
+ end
+ end
+end
diff --git a/spec/ruby/core/file/mkfifo_spec.rb b/spec/ruby/core/file/mkfifo_spec.rb
index ad6e804b99..ce4a67fe31 100644
--- a/spec/ruby/core/file/mkfifo_spec.rb
+++ b/spec/ruby/core/file/mkfifo_spec.rb
@@ -1,53 +1,51 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
-ruby_version_is "2.3" do
- describe "File.mkfifo" do
- platform_is_not :windows do
- before do
- @path = tmp('fifo')
- end
+describe "File.mkfifo" do
+ platform_is_not :windows do
+ before do
+ @path = tmp('fifo')
+ end
- after do
- rm_r(@path)
- end
+ after do
+ rm_r(@path)
+ end
- context "when path passed responds to :to_path" do
- it "creates a FIFO file at the path specified" do
- File.mkfifo(@path)
- File.ftype(@path).should == "fifo"
- end
+ context "when path passed responds to :to_path" do
+ it "creates a FIFO file at the path specified" do
+ File.mkfifo(@path)
+ File.ftype(@path).should == "fifo"
end
+ end
- context "when path passed is not a String value" do
- it "raises a TypeError" do
- lambda { File.mkfifo(:"/tmp/fifo") }.should raise_error(TypeError)
- end
+ context "when path passed is not a String value" do
+ it "raises a TypeError" do
+ -> { File.mkfifo(:"/tmp/fifo") }.should.raise(TypeError)
end
+ end
- context "when path does not exist" do
- it "raises an Errno::ENOENT exception" do
- lambda { File.mkfifo("/bogus/path") }.should raise_error(Errno::ENOENT)
- end
+ context "when path does not exist" do
+ it "raises an Errno::ENOENT exception" do
+ -> { File.mkfifo("/bogus/path") }.should.raise(Errno::ENOENT)
end
+ end
- it "creates a FIFO file at the passed path" do
- File.mkfifo(@path.to_s)
- File.ftype(@path).should == "fifo"
- end
+ it "creates a FIFO file at the passed path" do
+ File.mkfifo(@path.to_s)
+ File.ftype(@path).should == "fifo"
+ end
- it "creates a FIFO file with passed mode & ~umask" do
- File.mkfifo(@path, 0755)
- File.stat(@path).mode.should == 010755 & ~File.umask
- end
+ it "creates a FIFO file with passed mode & ~umask" do
+ File.mkfifo(@path, 0755)
+ File.stat(@path).mode.should == 010755 & ~File.umask
+ end
- it "creates a FIFO file with a default mode of 0666 & ~umask" do
- File.mkfifo(@path)
- File.stat(@path).mode.should == 010666 & ~File.umask
- end
+ it "creates a FIFO file with a default mode of 0666 & ~umask" do
+ File.mkfifo(@path)
+ File.stat(@path).mode.should == 010666 & ~File.umask
+ end
- it "returns 0 after creating the FIFO file" do
- File.mkfifo(@path).should == 0
- end
+ it "returns 0 after creating the FIFO file" do
+ File.mkfifo(@path).should == 0
end
end
end
diff --git a/spec/ruby/core/file/mtime_spec.rb b/spec/ruby/core/file/mtime_spec.rb
index 56b7e4464e..d83725e25d 100644
--- a/spec/ruby/core/file/mtime_spec.rb
+++ b/spec/ruby/core/file/mtime_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "File.mtime" do
before :each do
@@ -11,25 +11,30 @@ describe "File.mtime" do
end
it "returns the modification Time of the file" do
- File.mtime(@filename).should be_kind_of(Time)
- File.mtime(@filename).should be_close(@mtime, 2.0)
- end
-
- platform_is :linux do
- it "returns the modification Time of the file with microseconds" do
- supports_subseconds = Integer(`stat -c%y '#{__FILE__}'`[/\.(\d+)/, 1], 10)
- if supports_subseconds != 0
- expected_time = Time.at(Time.now.to_i + 0.123456)
- File.utime 0, expected_time, @filename
- File.mtime(@filename).usec.should == expected_time.usec
- else
- File.mtime(__FILE__).usec.should == 0
+ File.mtime(@filename).should.is_a?(Time)
+ File.mtime(@filename).should be_close(@mtime, TIME_TOLERANCE)
+ end
+
+ platform_is :linux, :windows do
+ unless ENV.key?('TRAVIS') # https://bugs.ruby-lang.org/issues/17926
+ it "returns the modification Time of the file with microseconds" do
+ supports_subseconds = Integer(`stat -c%y '#{__FILE__}'`[/\.(\d{1,6})/, 1], 10)
+ if supports_subseconds != 0
+ expected_time = Time.at(Time.now.to_i + 0.123456)
+ File.utime 0, expected_time, @filename
+ File.mtime(@filename).usec.should == expected_time.usec
+ else
+ File.mtime(__FILE__).usec.should == 0
+ end
+ rescue Errno::ENOENT => e
+ # Windows don't have stat command.
+ skip e.message
end
end
end
it "raises an Errno::ENOENT exception if the file is not found" do
- lambda { File.mtime('bogus') }.should raise_error(Errno::ENOENT)
+ -> { File.mtime('bogus') }.should.raise(Errno::ENOENT)
end
end
@@ -45,7 +50,7 @@ describe "File#mtime" do
end
it "returns the modification Time of the file" do
- @f.mtime.should be_kind_of(Time)
+ @f.mtime.should.is_a?(Time)
end
end
diff --git a/spec/ruby/core/file/new_spec.rb b/spec/ruby/core/file/new_spec.rb
index 3c72ac48e5..4cd2cb5dcb 100644
--- a/spec/ruby/core/file/new_spec.rb
+++ b/spec/ruby/core/file/new_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/open', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/open'
describe "File.new" do
before :each do
@@ -16,39 +16,39 @@ describe "File.new" do
it "returns a new File with mode string" do
@fh = File.new(@file, 'w')
- @fh.should be_kind_of(File)
- File.exist?(@file).should == true
+ @fh.should.is_a?(File)
+ File.should.exist?(@file)
end
it "returns a new File with mode num" do
@fh = File.new(@file, @flags)
- @fh.should be_kind_of(File)
- File.exist?(@file).should == true
+ @fh.should.is_a?(File)
+ File.should.exist?(@file)
end
it "returns a new File with modus num and permissions" do
rm_r @file
File.umask(0011)
@fh = File.new(@file, @flags, 0755)
- @fh.should be_kind_of(File)
+ @fh.should.is_a?(File)
platform_is_not :windows do
File.stat(@file).mode.to_s(8).should == "100744"
end
- File.exist?(@file).should == true
+ File.should.exist?(@file)
end
it "creates the file and returns writable descriptor when called with 'w' mode and r-o permissions" do
- # it should be possible to write to such a file via returned descriptior,
+ # it should be possible to write to such a file via returned descriptor,
# even though the file permissions are r-r-r.
rm_r @file
begin
f = File.new(@file, "w", 0444)
- lambda { f.puts("test") }.should_not raise_error(IOError)
+ -> { f.puts("test") }.should_not.raise(IOError)
ensure
f.close
end
- File.exist?(@file).should == true
+ File.should.exist?(@file)
File.read(@file).should == "test\n"
end
@@ -74,85 +74,146 @@ describe "File.new" do
@fh = File.new(@file)
fh_copy = File.new(@fh.fileno)
fh_copy.autoclose = false
- fh_copy.should be_kind_of(File)
- File.exist?(@file).should == true
+ fh_copy.should.is_a?(File)
+ File.should.exist?(@file)
+ end
+
+ it "returns a new read-only File when mode is not specified" do
+ @fh = File.new(@file)
+
+ -> { @fh.puts("test") }.should.raise(IOError)
+ @fh.read.should == ""
+ File.should.exist?(@file)
+ end
+
+ it "returns a new read-only File when mode is not specified but flags option is present" do
+ @fh = File.new(@file, flags: File::CREAT)
+
+ -> { @fh.puts("test") }.should.raise(IOError)
+ @fh.read.should == ""
+ File.should.exist?(@file)
end
it "creates a new file when use File::EXCL mode" do
@fh = File.new(@file, File::EXCL)
- @fh.should be_kind_of(File)
- File.exist?(@file).should == true
+ @fh.should.is_a?(File)
+ File.should.exist?(@file)
end
- it "raises an Errorno::EEXIST if the file exists when create a new file with File::CREAT|File::EXCL" do
- lambda { @fh = File.new(@file, File::CREAT|File::EXCL) }.should raise_error(Errno::EEXIST)
+ it "raises an Errno::EEXIST if the file exists when create a new file with File::CREAT|File::EXCL" do
+ -> { @fh = File.new(@file, File::CREAT|File::EXCL) }.should.raise(Errno::EEXIST)
end
it "creates a new file when use File::WRONLY|File::APPEND mode" do
@fh = File.new(@file, File::WRONLY|File::APPEND)
- @fh.should be_kind_of(File)
- File.exist?(@file).should == true
+ @fh.should.is_a?(File)
+ File.should.exist?(@file)
end
it "returns a new File when use File::APPEND mode" do
@fh = File.new(@file, File::APPEND)
- @fh.should be_kind_of(File)
- File.exist?(@file).should == true
+ @fh.should.is_a?(File)
+ File.should.exist?(@file)
end
it "returns a new File when use File::RDONLY|File::APPEND mode" do
@fh = File.new(@file, File::RDONLY|File::APPEND)
- @fh.should be_kind_of(File)
- File.exist?(@file).should == true
+ @fh.should.is_a?(File)
+ File.should.exist?(@file)
end
it "returns a new File when use File::RDONLY|File::WRONLY mode" do
@fh = File.new(@file, File::RDONLY|File::WRONLY)
- @fh.should be_kind_of(File)
- File.exist?(@file).should == true
+ @fh.should.is_a?(File)
+ File.should.exist?(@file)
end
-
it "creates a new file when use File::WRONLY|File::TRUNC mode" do
@fh = File.new(@file, File::WRONLY|File::TRUNC)
- @fh.should be_kind_of(File)
- File.exist?(@file).should == true
+ @fh.should.is_a?(File)
+ File.should.exist?(@file)
+ end
+
+ it "returns a new read-only File when use File::RDONLY|File::CREAT mode" do
+ @fh = File.new(@file, File::RDONLY|File::CREAT)
+ @fh.should.is_a?(File)
+ File.should.exist?(@file)
+
+ # it's read-only
+ -> { @fh.puts("test") }.should.raise(IOError)
+ @fh.read.should == ""
+ end
+
+ it "returns a new read-only File when use File::CREAT mode" do
+ @fh = File.new(@file, File::CREAT)
+ @fh.should.is_a?(File)
+ File.should.exist?(@file)
+
+ # it's read-only
+ -> { @fh.puts("test") }.should.raise(IOError)
+ @fh.read.should == ""
end
it "coerces filename using to_str" do
name = mock("file")
name.should_receive(:to_str).and_return(@file)
@fh = File.new(name, "w")
- File.exist?(@file).should == true
+ File.should.exist?(@file)
end
it "coerces filename using #to_path" do
name = mock("file")
name.should_receive(:to_path).and_return(@file)
@fh = File.new(name, "w")
- File.exist?(@file).should == true
+ File.should.exist?(@file)
+ end
+
+ it "accepts options as a keyword argument" do
+ @fh = File.new(@file, 'w', 0755, flags: @flags)
+ @fh.should.is_a?(File)
+ @fh.close
+
+ -> {
+ @fh = File.new(@file, 'w', 0755, {flags: @flags})
+ }.should.raise(ArgumentError, "wrong number of arguments (given 4, expected 1..3)")
+ end
+
+ it "bitwise-ORs mode and flags option" do
+ -> {
+ @fh = File.new(@file, 'w', flags: File::EXCL)
+ }.should.raise(Errno::EEXIST, /File exists/)
+
+ -> {
+ @fh = File.new(@file, mode: 'w', flags: File::EXCL)
+ }.should.raise(Errno::EEXIST, /File exists/)
+ end
+
+ it "does not use the given block and warns to use File::open" do
+ -> {
+ @fh = File.new(@file) { raise }
+ }.should complain(/warning: File::new\(\) does not take block; use File::open\(\) instead/)
end
it "raises a TypeError if the first parameter can't be coerced to a string" do
- lambda { File.new(true) }.should raise_error(TypeError)
- lambda { File.new(false) }.should raise_error(TypeError)
+ -> { File.new(true) }.should.raise(TypeError)
+ -> { File.new(false) }.should.raise(TypeError)
end
it "raises a TypeError if the first parameter is nil" do
- lambda { File.new(nil) }.should raise_error(TypeError)
+ -> { File.new(nil) }.should.raise(TypeError)
end
it "raises an Errno::EBADF if the first parameter is an invalid file descriptor" do
- lambda { File.new(-1) }.should raise_error(Errno::EBADF)
+ -> { File.new(-1) }.should.raise(Errno::EBADF)
end
platform_is_not :windows do
it "can't alter mode or permissions when opening a file" do
@fh = File.new(@file)
- lambda {
+ -> {
f = File.new(@fh.fileno, @flags)
f.autoclose = false
- }.should raise_error(Errno::EINVAL)
+ }.should.raise(Errno::EINVAL)
end
end
diff --git a/spec/ruby/core/file/null_spec.rb b/spec/ruby/core/file/null_spec.rb
index b9dd6b658b..355b72b799 100644
--- a/spec/ruby/core/file/null_spec.rb
+++ b/spec/ruby/core/file/null_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "File::NULL" do
platform_is :windows do
diff --git a/spec/ruby/core/file/open_spec.rb b/spec/ruby/core/file/open_spec.rb
index 440921a796..7318c31636 100644
--- a/spec/ruby/core/file/open_spec.rb
+++ b/spec/ruby/core/file/open_spec.rb
@@ -1,8 +1,8 @@
# encoding: utf-8
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/common', __FILE__)
-require File.expand_path('../shared/open', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/common'
+require_relative 'shared/open'
describe "File.open" do
before :all do
@@ -28,7 +28,7 @@ describe "File.open" do
describe "with a block" do
it "does not raise error when file is closed inside the block" do
@fh = File.open(@file) { |fh| fh.close; fh }
- @fh.closed?.should == true
+ @fh.should.closed?
end
it "invokes close on an opened file when exiting the block" do
@@ -38,17 +38,17 @@ describe "File.open" do
end
it "propagates non-StandardErrors produced by close" do
- lambda {
+ -> {
File.open(@file, 'r') { |f| FileSpecs.make_closer f, Exception }
- }.should raise_error(Exception)
+ }.should.raise(Exception)
ScratchPad.recorded.should == [:file_opened, :file_closed]
end
it "propagates StandardErrors produced by close" do
- lambda {
+ -> {
File.open(@file, 'r') { |f| FileSpecs.make_closer f, StandardError }
- }.should raise_error(StandardError)
+ }.should.raise(StandardError)
ScratchPad.recorded.should == [:file_opened, :file_closed]
end
@@ -62,46 +62,46 @@ describe "File.open" do
it "opens the file (basic case)" do
@fh = File.open(@file)
- @fh.should be_kind_of(File)
- File.exist?(@file).should == true
+ @fh.should.is_a?(File)
+ File.should.exist?(@file)
end
it "opens the file with unicode characters" do
@fh = File.open(@unicode_path, "w")
- @fh.should be_kind_of(File)
- File.exist?(@unicode_path).should == true
+ @fh.should.is_a?(File)
+ File.should.exist?(@unicode_path)
end
it "opens a file when called with a block" do
File.open(@file) { |fh| }
- File.exist?(@file).should == true
+ File.should.exist?(@file)
end
it "opens with mode string" do
@fh = File.open(@file, 'w')
- @fh.should be_kind_of(File)
- File.exist?(@file).should == true
+ @fh.should.is_a?(File)
+ File.should.exist?(@file)
end
it "opens a file with mode string and block" do
File.open(@file, 'w') { |fh| }
- File.exist?(@file).should == true
+ File.should.exist?(@file)
end
it "opens a file with mode num" do
@fh = File.open(@file, @flags)
- @fh.should be_kind_of(File)
- File.exist?(@file).should == true
+ @fh.should.is_a?(File)
+ File.should.exist?(@file)
end
it "opens a file with mode num and block" do
File.open(@file, 'w') { |fh| }
- File.exist?(@file).should == true
+ File.should.exist?(@file)
end
it "opens a file with mode and permission as nil" do
@fh = File.open(@file, nil, nil)
- @fh.should be_kind_of(File)
+ @fh.should.is_a?(File)
end
# For this test we delete the file first to reset the perms
@@ -109,11 +109,11 @@ describe "File.open" do
rm_r @file
File.umask(0011)
@fh = File.open(@file, @flags, 0755)
- @fh.should be_kind_of(File)
+ @fh.should.is_a?(File)
platform_is_not :windows do
@fh.lstat.mode.to_s(8).should == "100744"
end
- File.exist?(@file).should == true
+ File.should.exist?(@file)
end
# For this test we delete the file first to reset the perms
@@ -124,11 +124,11 @@ describe "File.open" do
platform_is_not :windows do
File.stat(@file).mode.to_s(8).should == "100755"
end
- File.exist?(@file).should == true
+ File.should.exist?(@file)
end
it "creates the file and returns writable descriptor when called with 'w' mode and r-o permissions" do
- # it should be possible to write to such a file via returned descriptior,
+ # it should be possible to write to such a file via returned descriptor,
# even though the file permissions are r-r-r.
File.open(@file, "w", 0444) { |f| f.write("test") }
@@ -147,11 +147,13 @@ describe "File.open" do
end
platform_is_not :windows do
- it "creates a new write-only file when invoked with 'w' and '0222'" do
- rm_r @file
- File.open(@file, 'w', 0222) {}
- File.readable?(@file).should == false
- File.writable?(@file).should == true
+ as_user do
+ it "creates a new write-only file when invoked with 'w' and '0222'" do
+ rm_r @file
+ File.open(@file, 'w', 0222) {}
+ File.readable?(@file).should == false
+ File.writable?(@file).should == true
+ end
end
end
@@ -159,84 +161,69 @@ describe "File.open" do
@fh = File.open(@file)
fh_copy = File.open(@fh.fileno)
fh_copy.autoclose = false
- fh_copy.should be_kind_of(File)
- File.exist?(@file).should == true
- end
-
- it "opens a file with a file descriptor d and a block" do
- @fh = File.open(@file)
- @fh.should be_kind_of(File)
-
- lambda {
- File.open(@fh.fileno) do |fh|
- @fd = fh.fileno
- @fh.close
- end
- }.should raise_error(Errno::EBADF)
- lambda { File.open(@fd) }.should raise_error(Errno::EBADF)
-
- File.exist?(@file).should == true
+ fh_copy.should.is_a?(File)
+ File.should.exist?(@file)
end
it "opens a file that no exists when use File::WRONLY mode" do
- lambda { File.open(@nonexistent, File::WRONLY) }.should raise_error(Errno::ENOENT)
+ -> { File.open(@nonexistent, File::WRONLY) }.should.raise(Errno::ENOENT)
end
it "opens a file that no exists when use File::RDONLY mode" do
- lambda { File.open(@nonexistent, File::RDONLY) }.should raise_error(Errno::ENOENT)
+ -> { File.open(@nonexistent, File::RDONLY) }.should.raise(Errno::ENOENT)
end
it "opens a file that no exists when use 'r' mode" do
- lambda { File.open(@nonexistent, 'r') }.should raise_error(Errno::ENOENT)
+ -> { File.open(@nonexistent, 'r') }.should.raise(Errno::ENOENT)
end
it "opens a file that no exists when use File::EXCL mode" do
- lambda { File.open(@nonexistent, File::EXCL) }.should raise_error(Errno::ENOENT)
+ -> { File.open(@nonexistent, File::EXCL) }.should.raise(Errno::ENOENT)
end
it "opens a file that no exists when use File::NONBLOCK mode" do
- lambda { File.open(@nonexistent, File::NONBLOCK) }.should raise_error(Errno::ENOENT)
+ -> { File.open(@nonexistent, File::NONBLOCK) }.should.raise(Errno::ENOENT)
end
platform_is_not :openbsd, :windows do
it "opens a file that no exists when use File::TRUNC mode" do
- lambda { File.open(@nonexistent, File::TRUNC) }.should raise_error(Errno::ENOENT)
+ -> { File.open(@nonexistent, File::TRUNC) }.should.raise(Errno::ENOENT)
end
end
platform_is :openbsd, :windows do
it "does not open a file that does no exists when using File::TRUNC mode" do
- lambda { File.open(@nonexistent, File::TRUNC) }.should raise_error(Errno::EINVAL)
+ -> { File.open(@nonexistent, File::TRUNC) }.should.raise(Errno::EINVAL)
end
end
platform_is_not :windows do
it "opens a file that no exists when use File::NOCTTY mode" do
- lambda { File.open(@nonexistent, File::NOCTTY) }.should raise_error(Errno::ENOENT)
+ -> { File.open(@nonexistent, File::NOCTTY) }.should.raise(Errno::ENOENT)
end
end
it "opens a file that no exists when use File::CREAT mode" do
@fh = File.open(@nonexistent, File::CREAT) { |f| f }
- @fh.should be_kind_of(File)
- File.exist?(@file).should == true
+ @fh.should.is_a?(File)
+ File.should.exist?(@file)
end
it "opens a file that no exists when use 'a' mode" do
@fh = File.open(@nonexistent, 'a') { |f| f }
- @fh.should be_kind_of(File)
- File.exist?(@file).should == true
+ @fh.should.is_a?(File)
+ File.should.exist?(@file)
end
it "opens a file that no exists when use 'w' mode" do
@fh = File.open(@nonexistent, 'w') { |f| f }
- @fh.should be_kind_of(File)
- File.exist?(@file).should == true
+ @fh.should.is_a?(File)
+ File.should.exist?(@file)
end
- # Check the grants associated to the differents open modes combinations.
+ # Check the grants associated to the different open modes combinations.
it "raises an ArgumentError exception when call with an unknown mode" do
- lambda { File.open(@file, "q") }.should raise_error(ArgumentError)
+ -> { File.open(@file, "q") }.should.raise(ArgumentError)
end
it "can read in a block when call open with RDONLY mode" do
@@ -253,13 +240,13 @@ describe "File.open" do
it "raises an IO exception when write in a block opened with RDONLY mode" do
File.open(@file, File::RDONLY) do |f|
- lambda { f.puts "writing ..." }.should raise_error(IOError)
+ -> { f.puts "writing ..." }.should.raise(IOError)
end
end
it "raises an IO exception when write in a block opened with 'r' mode" do
File.open(@file, "r") do |f|
- lambda { f.puts "writing ..." }.should raise_error(IOError)
+ -> { f.puts "writing ..." }.should.raise(IOError)
end
end
@@ -270,11 +257,11 @@ describe "File.open" do
end
it "can't read in a block when call open with File::WRONLY||File::RDONLY mode" do
- lambda {
+ -> {
File.open(@file, File::WRONLY|File::RDONLY ) do |f|
f.gets.should == nil
end
- }.should raise_error(IOError)
+ }.should.raise(IOError)
end
it "can write in a block when call open with WRONLY mode" do
@@ -291,48 +278,48 @@ describe "File.open" do
it "raises an IOError when read in a block opened with WRONLY mode" do
File.open(@file, File::WRONLY) do |f|
- lambda { f.gets }.should raise_error(IOError)
+ -> { f.gets }.should.raise(IOError)
end
end
it "raises an IOError when read in a block opened with 'w' mode" do
File.open(@file, "w") do |f|
- lambda { f.gets }.should raise_error(IOError)
+ -> { f.gets }.should.raise(IOError)
end
end
it "raises an IOError when read in a block opened with 'a' mode" do
File.open(@file, "a") do |f|
- lambda { f.gets }.should raise_error(IOError)
+ -> { f.gets }.should.raise(IOError)
end
end
it "raises an IOError when read in a block opened with 'a' mode" do
File.open(@file, "a") do |f|
f.puts("writing").should == nil
- lambda { f.gets }.should raise_error(IOError)
+ -> { f.gets }.should.raise(IOError)
end
end
it "raises an IOError when read in a block opened with 'a' mode" do
File.open(@file, File::WRONLY|File::APPEND ) do |f|
- lambda { f.gets }.should raise_error(IOError)
+ -> { f.gets }.should.raise(IOError)
end
end
it "raises an IOError when read in a block opened with File::WRONLY|File::APPEND mode" do
File.open(@file, File::WRONLY|File::APPEND ) do |f|
f.puts("writing").should == nil
- lambda { f.gets }.should raise_error(IOError)
+ -> { f.gets }.should.raise(IOError)
end
end
- it "raises an IOError when read in a block opened with File::RDONLY|File::APPEND mode" do
- lambda {
+ it "raises an IOError when write in a block opened with File::RDONLY|File::APPEND mode" do
+ -> {
File.open(@file, File::RDONLY|File::APPEND ) do |f|
f.puts("writing")
end
- }.should raise_error(IOError)
+ }.should.raise(IOError)
end
it "can read and write in a block when call open with RDWR mode" do
@@ -345,11 +332,11 @@ describe "File.open" do
end
it "can't read in a block when call open with File::EXCL mode" do
- lambda {
+ -> {
File.open(@file, File::EXCL) do |f|
f.puts("writing").should == nil
end
- }.should raise_error(IOError)
+ }.should.raise(IOError)
end
it "can read in a block when call open with File::EXCL mode" do
@@ -367,18 +354,18 @@ describe "File.open" do
end
end
- it "raises an Errorno::EEXIST if the file exists when open with File::CREAT|File::EXCL" do
- lambda {
+ it "raises an Errno::EEXIST if the file exists when open with File::CREAT|File::EXCL" do
+ -> {
File.open(@file, File::CREAT|File::EXCL) do |f|
f.puts("writing")
end
- }.should raise_error(Errno::EEXIST)
+ }.should.raise(Errno::EEXIST)
end
it "creates a new file when use File::WRONLY|File::APPEND mode" do
@fh = File.open(@file, File::WRONLY|File::APPEND)
- @fh.should be_kind_of(File)
- File.exist?(@file).should == true
+ @fh.should.is_a?(File)
+ File.should.exist?(@file)
end
it "opens a file when use File::WRONLY|File::APPEND mode" do
@@ -395,11 +382,11 @@ describe "File.open" do
end
it "raises an IOError if the file exists when open with File::RDONLY|File::APPEND" do
- lambda {
+ -> {
File.open(@file, File::RDONLY|File::APPEND) do |f|
f.puts("writing").should == nil
end
- }.should raise_error(IOError)
+ }.should.raise(IOError)
end
platform_is_not :openbsd, :windows do
@@ -420,8 +407,8 @@ describe "File.open" do
fh1 = File.open(@file, "w")
begin
@fh = File.open(@file, File::WRONLY|File::TRUNC)
- @fh.should be_kind_of(File)
- File.exist?(@file).should == true
+ @fh.should.is_a?(File)
+ File.should.exist?(@file)
ensure
fh1.close
end
@@ -429,64 +416,68 @@ describe "File.open" do
platform_is_not :openbsd, :windows do
it "can't write in a block when call open with File::TRUNC mode" do
- lambda {
+ -> {
File.open(@file, File::TRUNC) do |f|
f.puts("writing")
end
- }.should raise_error(IOError)
+ }.should.raise(IOError)
end
- it "raises an Errorno::EEXIST if the file exists when open with File::RDONLY|File::TRUNC" do
- lambda {
+ it "raises an Errno::EEXIST if the file exists when open with File::RDONLY|File::TRUNC" do
+ -> {
File.open(@file, File::RDONLY|File::TRUNC) do |f|
f.puts("writing").should == nil
end
- }.should raise_error(IOError)
+ }.should.raise(IOError)
end
end
platform_is :openbsd, :windows do
it "can't write in a block when call open with File::TRUNC mode" do
- lambda {
+ -> {
File.open(@file, File::TRUNC) do |f|
f.puts("writing")
end
- }.should raise_error(Errno::EINVAL)
+ }.should.raise(Errno::EINVAL)
end
- it "raises an Errorno::EEXIST if the file exists when open with File::RDONLY|File::TRUNC" do
- lambda {
+ it "raises an Errno::EEXIST if the file exists when open with File::RDONLY|File::TRUNC" do
+ -> {
File.open(@file, File::RDONLY|File::TRUNC) do |f|
f.puts("writing").should == nil
end
- }.should raise_error(Errno::EINVAL)
+ }.should.raise(Errno::EINVAL)
end
end
platform_is_not :windows do
- it "raises an Errno::EACCES when opening non-permitted file" do
- @fh = File.open(@file, "w")
- @fh.chmod(000)
- lambda { fh1 = File.open(@file); fh1.close }.should raise_error(Errno::EACCES)
+ as_user do
+ it "raises an Errno::EACCES when opening non-permitted file" do
+ @fh = File.open(@file, "w")
+ @fh.chmod(000)
+ -> { fh1 = File.open(@file); fh1.close }.should.raise(Errno::EACCES)
+ end
end
end
- it "raises an Errno::EACCES when opening read-only file" do
- @fh = File.open(@file, "w")
- @fh.chmod(0444)
- lambda { File.open(@file, "w") }.should raise_error(Errno::EACCES)
+ as_user do
+ it "raises an Errno::EACCES when opening read-only file" do
+ @fh = File.open(@file, "w")
+ @fh.chmod(0444)
+ -> { File.open(@file, "w") }.should.raise(Errno::EACCES)
+ end
end
it "opens a file for binary read" do
@fh = File.open(@file, "rb")
- @fh.should be_kind_of(File)
- File.exist?(@file).should == true
+ @fh.should.is_a?(File)
+ File.should.exist?(@file)
end
it "opens a file for binary write" do
@fh = File.open(@file, "wb")
- @fh.should be_kind_of(File)
- File.exist?(@file).should == true
+ @fh.should.is_a?(File)
+ File.should.exist?(@file)
end
it "opens a file for read-write and truncate the file" do
@@ -494,7 +485,7 @@ describe "File.open" do
File.size(@file).should > 0
File.open(@file, "w+") do |f|
f.pos.should == 0
- f.eof?.should == true
+ f.should.eof?
end
File.size(@file).should == 0
end
@@ -503,8 +494,16 @@ describe "File.open" do
File.open(@file, "w") { |f| f.puts "testing" }
File.size(@file).should > 0
File.open(@file, "rb+") do |f|
+ f.binmode?.should == true
+ f.external_encoding.should == Encoding::ASCII_8BIT
+ f.pos.should == 0
+ f.should_not.eof?
+ end
+ File.open(@file, "r+b") do |f|
+ f.binmode?.should == true
+ f.external_encoding.should == Encoding::ASCII_8BIT
f.pos.should == 0
- f.eof?.should == false
+ f.should_not.eof?
end
end
@@ -513,96 +512,101 @@ describe "File.open" do
File.size(@file).should > 0
File.open(@file, "wb+") do |f|
f.pos.should == 0
- f.eof?.should == true
+ f.should.eof?
end
File.size(@file).should == 0
end
- ruby_version_is "2.3" do
- platform_is :linux do
- if defined?(File::TMPFILE)
- it "creates an unnamed temporary file with File::TMPFILE" do
- dir = tmp("tmpfilespec")
- mkdir_p dir
- begin
+ platform_is :linux do
+ guard -> { defined?(File::TMPFILE) } do
+ it "creates an unnamed temporary file with File::TMPFILE" do
+ dir = tmp("tmpfilespec")
+ mkdir_p dir
+ begin
+ Dir["#{dir}/*"].should == []
+ File.open(dir, "r+", flags: File::TMPFILE) do |io|
+ io.write("ruby")
+ io.flush
+ io.rewind
+ io.read.should == "ruby"
Dir["#{dir}/*"].should == []
- File.open(dir, "r+", flags: File::TMPFILE) do |io|
- io.write("ruby")
- io.flush
- io.rewind
- io.read.should == "ruby"
- Dir["#{dir}/*"].should == []
- end
- rescue Errno::EOPNOTSUPP, Errno::EINVAL
- # EOPNOTSUPP: no support from the filesystem
- # EINVAL: presumably bug in glibc
- 1.should == 1
- ensure
- rm_r dir
end
+ rescue Errno::EOPNOTSUPP
+ skip "no support from the filesystem"
+ rescue Errno::EINVAL, Errno::EISDIR
+ skip "presumably bug in glibc"
+ ensure
+ rm_r dir
end
end
end
end
it "raises a TypeError if passed a filename that is not a String or Integer type" do
- lambda { File.open(true) }.should raise_error(TypeError)
- lambda { File.open(false) }.should raise_error(TypeError)
- lambda { File.open(nil) }.should raise_error(TypeError)
+ -> { File.open(true) }.should.raise(TypeError)
+ -> { File.open(false) }.should.raise(TypeError)
+ -> { File.open(nil) }.should.raise(TypeError)
end
it "raises a SystemCallError if passed an invalid Integer type" do
- lambda { File.open(-1) }.should raise_error(SystemCallError)
+ -> { File.open(-1) }.should.raise(SystemCallError)
end
it "raises an ArgumentError if passed the wrong number of arguments" do
- lambda { File.open(@file, File::CREAT, 0755, 'test') }.should raise_error(ArgumentError)
+ -> { File.open(@file, File::CREAT, 0755, 'test') }.should.raise(ArgumentError)
end
it "raises an ArgumentError if passed an invalid string for mode" do
- lambda { File.open(@file, 'fake') }.should raise_error(ArgumentError)
+ -> { File.open(@file, 'fake') }.should.raise(ArgumentError)
end
- it "defaults external_encoding to ASCII-8BIT for binary modes" do
- File.open(@file, 'rb') {|f| f.external_encoding.should == Encoding::ASCII_8BIT}
- File.open(@file, 'wb+') {|f| f.external_encoding.should == Encoding::ASCII_8BIT}
+ it "defaults external_encoding to BINARY for binary modes" do
+ File.open(@file, 'rb') {|f| f.external_encoding.should == Encoding::BINARY}
+ File.open(@file, 'wb+') {|f| f.external_encoding.should == Encoding::BINARY}
+ end
+
+ it "accepts options as a keyword argument" do
+ @fh = File.open(@file, 'w', 0755, flags: File::CREAT)
+ @fh.should.instance_of?(File)
+
+ -> {
+ File.open(@file, 'w', 0755, {flags: File::CREAT})
+ }.should.raise(ArgumentError, "wrong number of arguments (given 4, expected 1..3)")
end
it "uses the second argument as an options Hash" do
@fh = File.open(@file, mode: "r")
- @fh.should be_an_instance_of(File)
+ @fh.should.instance_of?(File)
end
it "calls #to_hash to convert the second argument to a Hash" do
options = mock("file open options")
options.should_receive(:to_hash).and_return({ mode: "r" })
- @fh = File.open(@file, options)
+ @fh = File.open(@file, **options)
end
- ruby_version_is "2.3" do
- it "accepts extra flags as a keyword argument and combine with a string mode" do
- lambda {
- File.open(@file, "w", flags: File::EXCL) { }
- }.should raise_error(Errno::EEXIST)
+ it "accepts extra flags as a keyword argument and combine with a string mode" do
+ -> {
+ File.open(@file, "w", flags: File::EXCL) { }
+ }.should.raise(Errno::EEXIST)
- lambda {
- File.open(@file, mode: "w", flags: File::EXCL) { }
- }.should raise_error(Errno::EEXIST)
- end
+ -> {
+ File.open(@file, mode: "w", flags: File::EXCL) { }
+ }.should.raise(Errno::EEXIST)
+ end
- it "accepts extra flags as a keyword argument and combine with an integer mode" do
- lambda {
- File.open(@file, File::WRONLY | File::CREAT, flags: File::EXCL) { }
- }.should raise_error(Errno::EEXIST)
- end
+ it "accepts extra flags as a keyword argument and combine with an integer mode" do
+ -> {
+ File.open(@file, File::WRONLY | File::CREAT, flags: File::EXCL) { }
+ }.should.raise(Errno::EEXIST)
end
platform_is_not :windows do
describe "on a FIFO" do
before :each do
@fifo = tmp("File_open_fifo")
- system "mkfifo #{@fifo}"
+ File.mkfifo(@fifo)
end
after :each do
@@ -636,13 +640,44 @@ describe "File.open" do
end
end
+ it "raises ArgumentError if mixing :newline and binary mode" do
+ -> {
+ File.open(@file, "rb", newline: :universal) {}
+ }.should.raise(ArgumentError, "newline decorator with binary mode")
+ end
+
+ context "'x' flag" do
+ before :each do
+ @xfile = tmp("x-flag")
+ rm_r @xfile
+ end
+
+ after :each do
+ rm_r @xfile
+ end
+
+ it "does nothing if the file doesn't exist" do
+ File.open(@xfile, "wx") { |f| f.write("content") }
+ File.read(@xfile).should == "content"
+ end
+
+ it "throws a Errno::EEXIST error if the file exists" do
+ touch @xfile
+ -> { File.open(@xfile, "wx") }.should.raise(Errno::EEXIST)
+ end
+
+ it "can't be used with 'r' and 'a' flags" do
+ -> { File.open(@xfile, "rx") }.should.raise(ArgumentError, 'invalid access mode rx')
+ -> { File.open(@xfile, "ax") }.should.raise(ArgumentError, 'invalid access mode ax')
+ end
+ end
end
describe "File.open when passed a file descriptor" do
before do
@content = "File#open when passed a file descriptor"
@name = tmp("file_open_with_fd.txt")
- @fd = new_fd @name, fmode("w:utf-8")
+ @fd = new_fd @name, "w:utf-8"
@file = nil
end
@@ -653,8 +688,8 @@ describe "File.open when passed a file descriptor" do
it "opens a file" do
@file = File.open(@fd, "w")
- @file.should be_an_instance_of(File)
- @file.fileno.should equal(@fd)
+ @file.should.instance_of?(File)
+ @file.fileno.should.equal?(@fd)
@file.write @content
@file.flush
File.read(@name).should == @content
@@ -662,8 +697,8 @@ describe "File.open when passed a file descriptor" do
it "opens a file when passed a block" do
@file = File.open(@fd, "w") do |f|
- f.should be_an_instance_of(File)
- f.fileno.should equal(@fd)
+ f.should.instance_of?(File)
+ f.fileno.should.equal?(@fd)
f.write @content
f
end
diff --git a/spec/ruby/core/file/owned_spec.rb b/spec/ruby/core/file/owned_spec.rb
index d19e9cb278..06d6796da9 100644
--- a/spec/ruby/core/file/owned_spec.rb
+++ b/spec/ruby/core/file/owned_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/file/owned', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../../shared/file/owned'
describe "File.owned?" do
it_behaves_like :file_owned, :owned?, File
@@ -24,9 +24,11 @@ describe "File.owned?" do
end
platform_is_not :windows do
- it "returns false when the file is not owned by the user" do
- system_file = '/etc/passwd'
- File.owned?(system_file).should == false
+ as_user do
+ it "returns false when the file is not owned by the user" do
+ system_file = '/etc/passwd'
+ File.owned?(system_file).should == false
+ end
end
end
diff --git a/spec/ruby/core/file/path_spec.rb b/spec/ruby/core/file/path_spec.rb
index 5004e128cd..f3b9b56dbe 100644
--- a/spec/ruby/core/file/path_spec.rb
+++ b/spec/ruby/core/file/path_spec.rb
@@ -1,6 +1,12 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "File#path" do
+ it "is an alias of File#to_path" do
+ File.instance_method(:path).should == File.instance_method(:to_path)
+ end
+end
+
+describe "File.path" do
before :each do
@name = tmp("file_path")
end
@@ -9,21 +15,68 @@ 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 "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
+
+ it "raises TypeError when #to_path result is not a string" do
+ path = mock("path")
+ path.should_receive(:to_path).and_return(nil)
+ -> { File.path(path) }.should.raise TypeError
+
+ path = mock("path")
+ path.should_receive(:to_path).and_return(42)
+ -> { File.path(path) }.should.raise TypeError
+ end
+
+ it "raises ArgumentError for string argument contains NUL character" do
+ -> { File.path("\0") }.should.raise ArgumentError
+ -> { File.path("a\0") }.should.raise ArgumentError
+ -> { File.path("a\0c") }.should.raise ArgumentError
+ end
+
+ it "raises ArgumentError when #to_path result contains NUL character" do
+ path = mock("path")
+ path.should_receive(:to_path).and_return("\0")
+ -> { File.path(path) }.should.raise ArgumentError
+
+ path = mock("path")
+ path.should_receive(:to_path).and_return("a\0")
+ -> { File.path(path) }.should.raise ArgumentError
+
+ path = mock("path")
+ path.should_receive(:to_path).and_return("a\0c")
+ -> { File.path(path) }.should.raise ArgumentError
+ end
+
+ it "raises Encoding::CompatibilityError for ASCII-incompatible string argument" do
+ path = "abc".encode(Encoding::UTF_32BE)
+ -> { File.path(path) }.should.raise Encoding::CompatibilityError
end
- it "returns the full path for the given file" do
- File.path(@name).should == @name
+ it "raises Encoding::CompatibilityError when #to_path result is ASCII-incompatible" do
+ path = mock("path")
+ path.should_receive(:to_path).and_return("abc".encode(Encoding::UTF_32BE))
+ -> { File.path(path) }.should.raise Encoding::CompatibilityError
end
end
diff --git a/spec/ruby/core/file/pipe_spec.rb b/spec/ruby/core/file/pipe_spec.rb
index ca7392b8ee..01d72dbe85 100644
--- a/spec/ruby/core/file/pipe_spec.rb
+++ b/spec/ruby/core/file/pipe_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/file/pipe', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../../shared/file/pipe'
describe "File.pipe?" do
it_behaves_like :file_pipe, :pipe?, File
@@ -22,7 +22,7 @@ describe "File.pipe?" do
platform_is_not :windows do
it "returns true if the file is a pipe" do
filename = tmp("i_am_a_pipe")
- system "mkfifo #{filename}"
+ File.mkfifo(filename)
File.pipe?(filename).should == true
diff --git a/spec/ruby/core/file/printf_spec.rb b/spec/ruby/core/file/printf_spec.rb
new file mode 100644
index 0000000000..2530419fc7
--- /dev/null
+++ b/spec/ruby/core/file/printf_spec.rb
@@ -0,0 +1,18 @@
+require_relative '../../spec_helper'
+require_relative '../kernel/shared/sprintf'
+
+describe "File#printf" do
+ it_behaves_like :kernel_sprintf, -> format, *args {
+ begin
+ @filename = tmp("printf.txt")
+
+ File.open(@filename, "w", encoding: "utf-8") do |f|
+ f.printf(format, *args)
+ end
+
+ File.read(@filename, encoding: "utf-8")
+ ensure
+ rm_r @filename
+ end
+ }
+end
diff --git a/spec/ruby/core/file/read_spec.rb b/spec/ruby/core/file/read_spec.rb
index fdbbf58a1c..67a3325cbd 100644
--- a/spec/ruby/core/file/read_spec.rb
+++ b/spec/ruby/core/file/read_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/read', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/read'
describe "File.read" do
it_behaves_like :file_read_directory, :read, File
diff --git a/spec/ruby/core/file/readable_real_spec.rb b/spec/ruby/core/file/readable_real_spec.rb
index 5fca968611..524466cd96 100644
--- a/spec/ruby/core/file/readable_real_spec.rb
+++ b/spec/ruby/core/file/readable_real_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/file/readable_real', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../../shared/file/readable_real'
describe "File.readable_real?" do
it_behaves_like :file_readable_real, :readable_real?, File
diff --git a/spec/ruby/core/file/readable_spec.rb b/spec/ruby/core/file/readable_spec.rb
index 3307e5e30f..ed75a23f39 100644
--- a/spec/ruby/core/file/readable_spec.rb
+++ b/spec/ruby/core/file/readable_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/file/readable', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../../shared/file/readable'
describe "File.readable?" do
it_behaves_like :file_readable, :readable?, File
diff --git a/spec/ruby/core/file/readlink_spec.rb b/spec/ruby/core/file/readlink_spec.rb
index b529cd1355..568692b9b6 100644
--- a/spec/ruby/core/file/readlink_spec.rb
+++ b/spec/ruby/core/file/readlink_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "File.readlink" do
# symlink/readlink are not supported on Windows
@@ -26,12 +26,12 @@ describe "File.readlink" do
it "raises an Errno::ENOENT if there is no such file" do
# TODO: missing_file
- lambda { File.readlink("/this/surely/doesnt/exist") }.should raise_error(Errno::ENOENT)
+ -> { File.readlink("/this/surely/does/not/exist") }.should.raise(Errno::ENOENT)
end
it "raises an Errno::EINVAL if called with a normal file" do
touch @file
- lambda { File.readlink(@file) }.should raise_error(Errno::EINVAL)
+ -> { File.readlink(@file) }.should.raise(Errno::EINVAL)
end
end
@@ -49,7 +49,7 @@ describe "File.readlink" do
it "returns the name of the file referenced by the given link" do
touch @file
result = File.readlink(@link)
- result.encoding.should equal Encoding.find('filesystem')
+ result.encoding.should.equal? Encoding.find('filesystem')
result.should == @file.dup.force_encoding(Encoding.find('filesystem'))
end
end
diff --git a/spec/ruby/core/file/realdirpath_spec.rb b/spec/ruby/core/file/realdirpath_spec.rb
index 06900ad461..ecf1e0c6d9 100644
--- a/spec/ruby/core/file/realdirpath_spec.rb
+++ b/spec/ruby/core/file/realdirpath_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
platform_is_not :windows do
describe "File.realdirpath" do
@@ -61,7 +61,7 @@ platform_is_not :windows do
it "raises an Errno::ELOOP if the symlink points to itself" do
File.unlink @link
File.symlink(@link, @link)
- lambda { File.realdirpath(@link) }.should raise_error(Errno::ELOOP)
+ -> { File.realdirpath(@link) }.should.raise(Errno::ELOOP)
end
it "returns the real (absolute) pathname if the file is absent" do
@@ -69,7 +69,7 @@ platform_is_not :windows do
end
it "raises Errno::ENOENT if the directory is absent" do
- lambda { File.realdirpath(@fake_file_in_fake_dir) }.should raise_error(Errno::ENOENT)
+ -> { File.realdirpath(@fake_file_in_fake_dir) }.should.raise(Errno::ENOENT)
end
it "returns the real (absolute) pathname if the symlink points to an absent file" do
@@ -77,7 +77,7 @@ platform_is_not :windows do
end
it "raises Errno::ENOENT if the symlink points to an absent directory" do
- lambda { File.realdirpath(@fake_link_to_fake_dir) }.should raise_error(Errno::ENOENT)
+ -> { File.realdirpath(@fake_link_to_fake_dir) }.should.raise(Errno::ENOENT)
end
end
end
diff --git a/spec/ruby/core/file/realpath_spec.rb b/spec/ruby/core/file/realpath_spec.rb
index 49aed7b88c..ccb981eff1 100644
--- a/spec/ruby/core/file/realpath_spec.rb
+++ b/spec/ruby/core/file/realpath_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
platform_is_not :windows do
describe "File.realpath" do
@@ -54,18 +54,28 @@ platform_is_not :windows do
File.realpath(@relative_symlink).should == @file
end
+ it "removes the file element when going one level up" do
+ File.realpath('../', @file).should == @real_dir
+ end
+
it "raises an Errno::ELOOP if the symlink points to itself" do
File.unlink @link
File.symlink(@link, @link)
- lambda { File.realpath(@link) }.should raise_error(Errno::ELOOP)
+ -> { File.realpath(@link) }.should.raise(Errno::ELOOP)
end
it "raises Errno::ENOENT if the file is absent" do
- lambda { File.realpath(@fake_file) }.should raise_error(Errno::ENOENT)
+ -> { File.realpath(@fake_file) }.should.raise(Errno::ENOENT)
end
it "raises Errno::ENOENT if the symlink points to an absent file" do
- lambda { File.realpath(@fake_link) }.should raise_error(Errno::ENOENT)
+ -> { File.realpath(@fake_link) }.should.raise(Errno::ENOENT)
+ end
+
+ it "converts the argument with #to_path" do
+ path = mock("path")
+ path.should_receive(:to_path).and_return(__FILE__)
+ File.realpath(path).should == File.realpath(__FILE__ )
end
end
end
diff --git a/spec/ruby/core/file/rename_spec.rb b/spec/ruby/core/file/rename_spec.rb
index a62ba809bd..70ea669a68 100644
--- a/spec/ruby/core/file/rename_spec.rb
+++ b/spec/ruby/core/file/rename_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "File.rename" do
before :each do
@@ -14,24 +14,24 @@ describe "File.rename" do
end
it "renames a file" do
- File.exist?(@old).should == true
- File.exist?(@new).should == false
+ File.should.exist?(@old)
+ File.should_not.exist?(@new)
File.rename(@old, @new)
- File.exist?(@old).should == false
- File.exist?(@new).should == true
+ File.should_not.exist?(@old)
+ File.should.exist?(@new)
end
it "raises an Errno::ENOENT if the source does not exist" do
rm_r @old
- lambda { File.rename(@old, @new) }.should raise_error(Errno::ENOENT)
+ -> { File.rename(@old, @new) }.should.raise(Errno::ENOENT)
end
it "raises an ArgumentError if not passed two arguments" do
- lambda { File.rename }.should raise_error(ArgumentError)
- lambda { File.rename(@file) }.should raise_error(ArgumentError)
+ -> { File.rename }.should.raise(ArgumentError)
+ -> { File.rename(@file) }.should.raise(ArgumentError)
end
it "raises a TypeError if not passed String types" do
- lambda { File.rename(1, 2) }.should raise_error(TypeError)
+ -> { File.rename(1, 2) }.should.raise(TypeError)
end
end
diff --git a/spec/ruby/core/file/reopen_spec.rb b/spec/ruby/core/file/reopen_spec.rb
index 2493829740..858d424c67 100644
--- a/spec/ruby/core/file/reopen_spec.rb
+++ b/spec/ruby/core/file/reopen_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "File#reopen" do
before :each do
@@ -25,7 +25,7 @@ describe "File#reopen" do
@file.read.should == @content_b
end
- it "calls #to_path to convern an Object" do
+ it "calls #to_path to convert an Object" do
@file = File.new(@name_a).reopen(mock_to_path(@name_b), "r")
@file.read.should == @content_b
end
diff --git a/spec/ruby/core/file/setgid_spec.rb b/spec/ruby/core/file/setgid_spec.rb
index dc63329cc3..f5df5390f5 100644
--- a/spec/ruby/core/file/setgid_spec.rb
+++ b/spec/ruby/core/file/setgid_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/file/setgid', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../../shared/file/setgid'
describe "File.setgid?" do
it_behaves_like :file_setgid, :setgid?, File
diff --git a/spec/ruby/core/file/setuid_spec.rb b/spec/ruby/core/file/setuid_spec.rb
index dcd1d3aed1..9e5e86df61 100644
--- a/spec/ruby/core/file/setuid_spec.rb
+++ b/spec/ruby/core/file/setuid_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/file/setuid', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../../shared/file/setuid'
describe "File.setuid?" do
it_behaves_like :file_setuid, :setuid?, File
@@ -26,10 +26,6 @@ describe "File.setuid?" do
platform_is_not :windows do
it "returns true when the gid bit is set" do
- platform_is :solaris do
- # Solaris requires execute bit before setting suid
- system "chmod u+x #{@name}"
- end
system "chmod u+s #{@name}"
File.setuid?(@name).should == true
diff --git a/spec/ruby/core/file/shared/fnmatch.rb b/spec/ruby/core/file/shared/fnmatch.rb
deleted file mode 100644
index 9b423ae47e..0000000000
--- a/spec/ruby/core/file/shared/fnmatch.rb
+++ /dev/null
@@ -1,241 +0,0 @@
-describe :file_fnmatch, shared: true do
- it "matches entire strings" do
- File.send(@method, 'cat', 'cat').should == true
- end
-
- it "does not match partial strings" do
- File.send(@method, 'cat', 'category').should == false
- end
-
- it "does not support { } patterns by default" do
- File.send(@method, 'c{at,ub}s', 'cats').should == false
- File.send(@method, 'c{at,ub}s', 'c{at,ub}s').should == true
- end
-
- it "supports some { } patterns when File::FNM_EXTGLOB is passed" do
- File.send(@method, "{a,b}", "a", File::FNM_EXTGLOB).should == true
- File.send(@method, "{a,b}", "b", File::FNM_EXTGLOB).should == true
- File.send(@method, "c{at,ub}s", "cats", File::FNM_EXTGLOB).should == true
- File.send(@method, "c{at,ub}s", "cubs", File::FNM_EXTGLOB).should == true
- File.send(@method, "-c{at,ub}s-", "-cats-", File::FNM_EXTGLOB).should == true
- File.send(@method, "-c{at,ub}s-", "-cubs-", File::FNM_EXTGLOB).should == true
- File.send(@method, "{a,b,c}{d,e,f}{g,h}", "adg", File::FNM_EXTGLOB).should == true
- File.send(@method, "{a,b,c}{d,e,f}{g,h}", "bdg", File::FNM_EXTGLOB).should == true
- File.send(@method, "{a,b,c}{d,e,f}{g,h}", "ceh", File::FNM_EXTGLOB).should == true
- File.send(@method, "{aa,bb,cc,dd}", "aa", File::FNM_EXTGLOB).should == true
- File.send(@method, "{aa,bb,cc,dd}", "bb", File::FNM_EXTGLOB).should == true
- File.send(@method, "{aa,bb,cc,dd}", "cc", File::FNM_EXTGLOB).should == true
- File.send(@method, "{aa,bb,cc,dd}", "dd", File::FNM_EXTGLOB).should == true
- File.send(@method, "{1,5{a,b{c,d}}}", "1", File::FNM_EXTGLOB).should == true
- File.send(@method, "{1,5{a,b{c,d}}}", "5a", File::FNM_EXTGLOB).should == true
- File.send(@method, "{1,5{a,b{c,d}}}", "5bc", File::FNM_EXTGLOB).should == true
- File.send(@method, "{1,5{a,b{c,d}}}", "5bd", File::FNM_EXTGLOB).should == true
- File.send(@method, "\\\\{a\\,b,b\\}c}", "\\a,b", File::FNM_EXTGLOB).should == true
- File.send(@method, "\\\\{a\\,b,b\\}c}", "\\b}c", File::FNM_EXTGLOB).should == true
- end
-
- it "doesn't support some { } patterns even when File::FNM_EXTGLOB is passed" do
- File.send(@method, "a{0..3}b", "a0b", File::FNM_EXTGLOB).should == false
- File.send(@method, "a{0..3}b", "a1b", File::FNM_EXTGLOB).should == false
- File.send(@method, "a{0..3}b", "a2b", File::FNM_EXTGLOB).should == false
- File.send(@method, "a{0..3}b", "a3b", File::FNM_EXTGLOB).should == false
- File.send(@method, "{0..12}", "0", File::FNM_EXTGLOB).should == false
- File.send(@method, "{0..12}", "6", File::FNM_EXTGLOB).should == false
- File.send(@method, "{0..12}", "12", File::FNM_EXTGLOB).should == false
- File.send(@method, "{3..-2}", "3", File::FNM_EXTGLOB).should == false
- File.send(@method, "{3..-2}", "0", File::FNM_EXTGLOB).should == false
- File.send(@method, "{3..-2}", "-2", File::FNM_EXTGLOB).should == false
- File.send(@method, "{a..g}", "a", File::FNM_EXTGLOB).should == false
- File.send(@method, "{a..g}", "d", File::FNM_EXTGLOB).should == false
- File.send(@method, "{a..g}", "g", File::FNM_EXTGLOB).should == false
- File.send(@method, "{g..a}", "a", File::FNM_EXTGLOB).should == false
- File.send(@method, "{g..a}", "d", File::FNM_EXTGLOB).should == false
- File.send(@method, "{g..a}", "g", File::FNM_EXTGLOB).should == false
- File.send(@method, "escaping: {{,\\,,\\},\\{}", "escaping: {", File::FNM_EXTGLOB).should == false
- File.send(@method, "escaping: {{,\\,,\\},\\{}", "escaping: ,", File::FNM_EXTGLOB).should == false
- File.send(@method, "escaping: {{,\\,,\\},\\{}", "escaping: }", File::FNM_EXTGLOB).should == false
- File.send(@method, "escaping: {{,\\,,\\},\\{}", "escaping: {", File::FNM_EXTGLOB).should == false
- end
-
- it "doesn't match an extra } when File::FNM_EXTGLOB is passed" do
- File.send(@method, 'c{at,ub}}s', 'cats', File::FNM_EXTGLOB).should == false
- end
-
- it "matches when both FNM_EXTGLOB and FNM_PATHNAME are passed" do
- File.send(@method, "?.md", "a.md", File::FNM_EXTGLOB | File::FNM_PATHNAME).should == true
- end
-
- it "matches a single character for each ? character" do
- File.send(@method, 'c?t', 'cat').should == true
- File.send(@method, 'c??t', 'cat').should == false
- end
-
- it "matches zero or more characters for each * character" do
- File.send(@method, 'c*', 'cats').should == true
- File.send(@method, 'c*t', 'c/a/b/t').should == true
- end
-
- it "matches ranges of characters using bracket expression (e.g. [a-z])" do
- File.send(@method, 'ca[a-z]', 'cat').should == true
- end
-
- it "matches ranges of characters using bracket expression, taking case into account" do
- File.send(@method, '[a-z]', 'D').should == false
- File.send(@method, '[^a-z]', 'D').should == true
- File.send(@method, '[A-Z]', 'd').should == false
- File.send(@method, '[^A-Z]', 'd').should == true
- File.send(@method, '[a-z]', 'D', File::FNM_CASEFOLD).should == true
- end
-
- it "does not match characters outside of the range of the bracket expresion" do
- File.send(@method, 'ca[x-z]', 'cat').should == false
- File.send(@method, '/ca[s][s-t]/rul[a-b]/[z]he/[x-Z]orld', '/cats/rule/the/World').should == false
- end
-
- it "matches ranges of characters using exclusive bracket expression (e.g. [^t] or [!t])" do
- File.send(@method, 'ca[^t]', 'cat').should == false
- File.send(@method, 'ca[!t]', 'cat').should == false
- end
-
- it "matches characters with a case sensitive comparison" do
- File.send(@method, 'cat', 'CAT').should == false
- end
-
- it "matches characters with case insensitive comparison when flags includes FNM_CASEFOLD" do
- File.send(@method, 'cat', 'CAT', File::FNM_CASEFOLD).should == true
- end
-
- platform_is_not :windows do
- it "doesn't match case sensitive characters on platforms with case sensitive paths, when flags include FNM_SYSCASE" do
- File.send(@method, 'cat', 'CAT', File::FNM_SYSCASE).should == false
- end
- end
-
- platform_is :windows do
- it "matches case sensitive characters on platforms with case insensitive paths, when flags include FNM_SYSCASE" do
- File.send(@method, 'cat', 'CAT', File::FNM_SYSCASE).should == true
- end
- end
-
- it "does not match '/' characters with ? or * when flags includes FNM_PATHNAME" do
- File.send(@method, '?', '/', File::FNM_PATHNAME).should == false
- File.send(@method, '*', '/', File::FNM_PATHNAME).should == false
- end
-
- it "does not match '/' characters inside bracket expressions when flags includes FNM_PATHNAME" do
- File.send(@method, '[/]', '/', File::FNM_PATHNAME).should == false
- end
-
- it "matches literal ? or * in path when pattern includes \\? or \\*" do
- File.send(@method, '\?', '?').should == true
- File.send(@method, '\?', 'a').should == false
-
- File.send(@method, '\*', '*').should == true
- File.send(@method, '\*', 'a').should == false
- end
-
- it "matches literal character (e.g. 'a') in path when pattern includes escaped character (e.g. \\a)" do
- File.send(@method, '\a', 'a').should == true
- File.send(@method, 'this\b', 'thisb').should == true
- end
-
- it "matches '\\' characters in path when flags includes FNM_NOESACPE" do
- File.send(@method, '\a', '\a', File::FNM_NOESCAPE).should == true
- File.send(@method, '\a', 'a', File::FNM_NOESCAPE).should == false
- File.send(@method, '\[foo\]\[bar\]', '[foo][bar]', File::FNM_NOESCAPE).should == false
- end
-
- it "escapes special characters inside bracket expression" do
- File.send(@method, '[\?]', '?').should == true
- File.send(@method, '[\*]', '*').should == true
- end
-
- it "does not match leading periods in filenames with wildcards by default" do
- File.send(@method, '*', '.profile').should == false
- File.send(@method, '*', 'home/.profile').should == true
- File.send(@method, '*/*', 'home/.profile').should == true
- File.send(@method, '*/*', 'dave/.profile', File::FNM_PATHNAME).should == false
- end
-
- it "matches patterns with leading periods to dotfiles by default" do
- File.send(@method, '.*', '.profile').should == true
- File.send(@method, ".*file", "nondotfile").should == false
- end
-
- it "matches leading periods in filenames when flags includes FNM_DOTMATCH" do
- File.send(@method, '*', '.profile', File::FNM_DOTMATCH).should == true
- File.send(@method, '*', 'home/.profile', File::FNM_DOTMATCH).should == true
- end
-
- it "matches multiple directories with ** and *" do
- files = '**/*.rb'
- File.send(@method, files, 'main.rb').should == false
- File.send(@method, files, './main.rb').should == false
- File.send(@method, files, 'lib/song.rb').should == true
- File.send(@method, '**.rb', 'main.rb').should == true
- File.send(@method, '**.rb', './main.rb').should == false
- File.send(@method, '**.rb', 'lib/song.rb').should == true
- File.send(@method, '*', 'dave/.profile').should == true
- end
-
- it "matches multiple directories with ** when flags includes File::FNM_PATHNAME" do
- files = '**/*.rb'
- flags = File::FNM_PATHNAME
-
- File.send(@method, files, 'main.rb', flags).should == true
- File.send(@method, files, 'one/two/three/main.rb', flags).should == true
- File.send(@method, files, './main.rb', flags).should == false
-
- flags = File::FNM_PATHNAME | File::FNM_DOTMATCH
-
- File.send(@method, files, './main.rb', flags).should == true
- File.send(@method, files, 'one/two/.main.rb', flags).should == true
-
- File.send(@method, "**/best/*", 'lib/my/best/song.rb').should == true
- end
-
- it "returns false if '/' in pattern do not match '/' in path when flags includes FNM_PATHNAME" do
- pattern = '*/*'
- File.send(@method, pattern, 'dave/.profile', File::FNM_PATHNAME).should be_false
-
- pattern = '**/foo'
- File.send(@method, pattern, 'a/.b/c/foo', File::FNM_PATHNAME).should be_false
- end
-
- it "returns true if '/' in pattern match '/' in path when flags includes FNM_PATHNAME" do
- pattern = '*/*'
- File.send(@method, pattern, 'dave/.profile', File::FNM_PATHNAME | File::FNM_DOTMATCH).should be_true
-
- pattern = '**/foo'
- File.send(@method, pattern, 'a/b/c/foo', File::FNM_PATHNAME).should be_true
- File.send(@method, pattern, '/a/b/c/foo', File::FNM_PATHNAME).should be_true
- File.send(@method, pattern, 'c:/a/b/c/foo', File::FNM_PATHNAME).should be_true
- File.send(@method, pattern, 'a/.b/c/foo', File::FNM_PATHNAME | File::FNM_DOTMATCH).should be_true
- end
-
- it "accepts an object that has a #to_path method" do
- File.send(@method, '\*', mock_to_path('a')).should == false
- end
-
- it "raises a TypeError if the first and second arguments are not string-like" do
- lambda { File.send(@method, nil, nil, 0, 0) }.should raise_error(ArgumentError)
- lambda { File.send(@method, 1, 'some/thing') }.should raise_error(TypeError)
- lambda { File.send(@method, 'some/thing', 1) }.should raise_error(TypeError)
- lambda { File.send(@method, 1, 1) }.should raise_error(TypeError)
- end
-
- it "raises a TypeError if the third argument is not an Integer" do
- lambda { File.send(@method, "*/place", "path/to/file", "flags") }.should raise_error(TypeError)
- lambda { File.send(@method, "*/place", "path/to/file", nil) }.should raise_error(TypeError)
- end
-
- it "does not raise a TypeError if the third argument can be coerced to an Integer" do
- flags = mock("flags")
- flags.should_receive(:to_int).and_return(10)
- lambda { File.send(@method, "*/place", "path/to/file", flags) }.should_not raise_error
- end
-
- it "matches multibyte characters" do
- File.fnmatch("*/ä/ø/ñ", "a/ä/ø/ñ").should == true
- end
-end
diff --git a/spec/ruby/core/file/shared/open.rb b/spec/ruby/core/file/shared/open.rb
index 0ca1bc74db..67149235ca 100644
--- a/spec/ruby/core/file/shared/open.rb
+++ b/spec/ruby/core/file/shared/open.rb
@@ -1,10 +1,10 @@
-require File.expand_path('../../../dir/fixtures/common', __FILE__)
+require_relative '../../dir/fixtures/common'
describe :open_directory, shared: true do
it "opens directories" do
file = File.send(@method, tmp(""))
begin
- file.should be_kind_of(File)
+ file.should.is_a?(File)
ensure
file.close
end
diff --git a/spec/ruby/core/file/shared/read.rb b/spec/ruby/core/file/shared/read.rb
index 916a6222bf..f60800bb2f 100644
--- a/spec/ruby/core/file/shared/read.rb
+++ b/spec/ruby/core/file/shared/read.rb
@@ -1,15 +1,15 @@
-require File.expand_path('../../../dir/fixtures/common', __FILE__)
+require_relative '../../dir/fixtures/common'
describe :file_read_directory, shared: true do
- platform_is :darwin, :linux, :windows do
+ platform_is :darwin, :linux, :freebsd, :openbsd, :windows do
it "raises an Errno::EISDIR when passed a path that is a directory" do
- lambda { @object.send(@method, ".") }.should raise_error(Errno::EISDIR)
+ -> { @object.send(@method, ".") }.should.raise(Errno::EISDIR)
end
end
- platform_is :bsd do
+ platform_is :netbsd do
it "does not raises any exception when passed a path that is a directory" do
- lambda { @object.send(@method, ".") }.should_not raise_error
+ -> { @object.send(@method, ".") }.should_not.raise
end
end
end
diff --git a/spec/ruby/core/file/shared/stat.rb b/spec/ruby/core/file/shared/stat.rb
index aac710dd2f..879a7f11ff 100644
--- a/spec/ruby/core/file/shared/stat.rb
+++ b/spec/ruby/core/file/shared/stat.rb
@@ -10,13 +10,13 @@ describe :file_stat, shared: true do
it "returns a File::Stat object if the given file exists" do
st = File.send(@method, @file)
- st.should be_an_instance_of(File::Stat)
+ st.should.instance_of?(File::Stat)
end
it "returns a File::Stat object when called on an instance of File" do
File.open(@file) do |f|
st = f.send(@method)
- st.should be_an_instance_of(File::Stat)
+ st.should.instance_of?(File::Stat)
end
end
@@ -25,8 +25,8 @@ describe :file_stat, shared: true do
end
it "raises an Errno::ENOENT if the file does not exist" do
- lambda {
+ -> {
File.send(@method, "fake_file")
- }.should raise_error(Errno::ENOENT)
+ }.should.raise(Errno::ENOENT)
end
end
diff --git a/spec/ruby/core/file/shared/unlink.rb b/spec/ruby/core/file/shared/unlink.rb
deleted file mode 100644
index 7b0413b76b..0000000000
--- a/spec/ruby/core/file/shared/unlink.rb
+++ /dev/null
@@ -1,63 +0,0 @@
-describe :file_unlink, shared: true do
- before :each do
- @file1 = tmp('test.txt')
- @file2 = tmp('test2.txt')
-
- touch @file1
- touch @file2
- end
-
- after :each do
- File.send(@method, @file1) if File.exist?(@file1)
- File.send(@method, @file2) if File.exist?(@file2)
-
- @file1 = nil
- @file2 = nil
- end
-
- it "returns 0 when called without arguments" do
- File.send(@method).should == 0
- end
-
- it "deletes a single file" do
- File.send(@method, @file1).should == 1
- File.exist?(@file1).should == false
- end
-
- it "deletes multiple files" do
- File.send(@method, @file1, @file2).should == 2
- File.exist?(@file1).should == false
- File.exist?(@file2).should == false
- end
-
- it "raises a TypeError if not passed a String type" do
- lambda { File.send(@method, 1) }.should raise_error(TypeError)
- end
-
- it "raises an Errno::ENOENT when the given file doesn't exist" do
- lambda { File.send(@method, 'bogus') }.should raise_error(Errno::ENOENT)
- end
-
- it "coerces a given parameter into a string if possible" do
- mock = mock("to_str")
- mock.should_receive(:to_str).and_return(@file1)
- File.send(@method, mock).should == 1
- end
-
- it "accepts an object that has a #to_path method" do
- File.send(@method, mock_to_path(@file1)).should == 1
- end
-
- ruby_version_is "2.3" do
- platform_is :windows do
- it "allows deleting an open file with File::SHARE_DELETE" do
- path = tmp("share_delete.txt")
- File.open(path, mode: File::CREAT | File::WRONLY | File::BINARY | File::SHARE_DELETE) do |f|
- File.exist?(path).should be_true
- File.send(@method, path)
- end
- File.exist?(path).should be_false
- end
- end
- end
-end
diff --git a/spec/ruby/core/file/shared/update_time.rb b/spec/ruby/core/file/shared/update_time.rb
new file mode 100644
index 0000000000..3fe7266a00
--- /dev/null
+++ b/spec/ruby/core/file/shared/update_time.rb
@@ -0,0 +1,105 @@
+describe :update_time, shared: true do
+ before :all do
+ @time_is_float = platform_is :windows
+ end
+
+ before :each do
+ @atime = Time.now
+ @mtime = Time.now
+ @file1 = tmp("specs_file_utime1")
+ @file2 = tmp("specs_file_utime2")
+ touch @file1
+ touch @file2
+ end
+
+ after :each do
+ rm_r @file1, @file2
+ end
+
+ it "sets the access and modification time of each file" do
+ File.send(@method, @atime, @mtime, @file1, @file2)
+
+ if @time_is_float
+ File.atime(@file1).should be_close(@atime, 0.0001)
+ File.mtime(@file1).should be_close(@mtime, 0.0001)
+ File.atime(@file2).should be_close(@atime, 0.0001)
+ File.mtime(@file2).should be_close(@mtime, 0.0001)
+ else
+ File.atime(@file1).to_i.should be_close(@atime.to_i, TIME_TOLERANCE)
+ File.mtime(@file1).to_i.should be_close(@mtime.to_i, TIME_TOLERANCE)
+ File.atime(@file2).to_i.should be_close(@atime.to_i, TIME_TOLERANCE)
+ File.mtime(@file2).to_i.should be_close(@mtime.to_i, TIME_TOLERANCE)
+ end
+ end
+
+ it "uses the current times if two nil values are passed" do
+ tn = Time.now
+ File.send(@method, nil, nil, @file1, @file2)
+
+ if @time_is_float
+ File.atime(@file1).should be_close(tn, 0.050)
+ File.mtime(@file1).should be_close(tn, 0.050)
+ File.atime(@file2).should be_close(tn, 0.050)
+ File.mtime(@file2).should be_close(tn, 0.050)
+ else
+ File.atime(@file1).to_i.should be_close(Time.now.to_i, TIME_TOLERANCE)
+ File.mtime(@file1).to_i.should be_close(Time.now.to_i, TIME_TOLERANCE)
+ File.atime(@file2).to_i.should be_close(Time.now.to_i, TIME_TOLERANCE)
+ File.mtime(@file2).to_i.should be_close(Time.now.to_i, TIME_TOLERANCE)
+ end
+ end
+
+ it "accepts an object that has a #to_path method" do
+ File.send(@method, @atime, @mtime, mock_to_path(@file1), mock_to_path(@file2))
+ end
+
+ it "accepts numeric atime and mtime arguments" do
+ if @time_is_float
+ File.send(@method, @atime.to_f, @mtime.to_f, @file1, @file2)
+
+ File.atime(@file1).should be_close(@atime, 0.0001)
+ File.mtime(@file1).should be_close(@mtime, 0.0001)
+ File.atime(@file2).should be_close(@atime, 0.0001)
+ File.mtime(@file2).should be_close(@mtime, 0.0001)
+ else
+ File.send(@method, @atime.to_i, @mtime.to_i, @file1, @file2)
+
+ File.atime(@file1).to_i.should be_close(@atime.to_i, TIME_TOLERANCE)
+ File.mtime(@file1).to_i.should be_close(@mtime.to_i, TIME_TOLERANCE)
+ File.atime(@file2).to_i.should be_close(@atime.to_i, TIME_TOLERANCE)
+ File.mtime(@file2).to_i.should be_close(@mtime.to_i, TIME_TOLERANCE)
+ end
+ end
+
+ it "may set nanosecond precision" do
+ t = Time.utc(2007, 11, 1, 15, 25, 0, 123456.789r)
+ File.send(@method, t, t, @file1)
+
+ File.atime(@file1).nsec.should.between?(0, 123500000)
+ File.mtime(@file1).nsec.should.between?(0, 123500000)
+ end
+
+ it "returns the number of filenames in the arguments" do
+ File.send(@method, @atime.to_f, @mtime.to_f, @file1, @file2).should == 2
+ end
+
+ platform_is :linux do
+ platform_is pointer_size: 64 do
+ it "allows Time instances in the far future to set mtime and atime (but some filesystems limit it up to 2446-05-10 or 2038-01-19 or 2486-07-02)" do
+ # https://ext4.wiki.kernel.org/index.php/Ext4_Disk_Layout#Inode_Timestamps
+ # "Therefore, timestamps should not overflow until May 2446."
+ # https://lwn.net/Articles/804382/
+ # "On-disk timestamps hitting the y2038 limit..."
+ # The problem seems to be being improved, but currently it actually fails on XFS on RHEL8
+ # https://rubyci.org/logs/rubyci.s3.amazonaws.com/rhel8/ruby-master/log/20201112T123004Z.fail.html.gz
+ # Amazon Linux 2023 returns 2486-07-02 in this example
+ # http://rubyci.s3.amazonaws.com/amazon2023/ruby-master/log/20230322T063004Z.fail.html.gz
+ time = Time.at(1<<44)
+ File.send(@method, time, time, @file1)
+
+ [559444, 2486, 2446, 2038].should.include? File.atime(@file1).year
+ [559444, 2486, 2446, 2038].should.include? File.mtime(@file1).year
+ end
+ end
+ end
+end
diff --git a/spec/ruby/core/file/size_spec.rb b/spec/ruby/core/file/size_spec.rb
index 73c8192b18..784c18c26e 100644
--- a/spec/ruby/core/file/size_spec.rb
+++ b/spec/ruby/core/file/size_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/file/size', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../../shared/file/size'
describe "File.size?" do
it_behaves_like :file_size, :size?, File
@@ -56,11 +56,11 @@ describe "File#size" do
end
it "is an instance method" do
- @file.respond_to?(:size).should be_true
+ @file.respond_to?(:size).should == true
end
- it "returns the file's size as a Fixnum" do
- @file.size.should be_an_instance_of(Fixnum)
+ it "returns the file's size as an Integer" do
+ @file.size.should.instance_of?(Integer)
end
it "returns the file's size in bytes" do
@@ -81,7 +81,7 @@ describe "File#size" do
it "raises an IOError on a closed file" do
@file.close
- lambda { @file.size }.should raise_error(IOError)
+ -> { @file.size }.should.raise(IOError)
end
platform_is_not :windows do
diff --git a/spec/ruby/core/file/socket_spec.rb b/spec/ruby/core/file/socket_spec.rb
index 80f33f4b19..d3f4eb013a 100644
--- a/spec/ruby/core/file/socket_spec.rb
+++ b/spec/ruby/core/file/socket_spec.rb
@@ -1,42 +1,10 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/file/socket', __FILE__)
-require 'socket'
+require_relative '../../spec_helper'
+require_relative '../../shared/file/socket'
describe "File.socket?" do
it_behaves_like :file_socket, :socket?, File
-end
-describe "File.socket?" do
it "returns false if file does not exist" do
File.socket?("I_am_a_bogus_file").should == false
end
-
- it "returns false if the file is not a socket" do
- filename = tmp("i_exist")
- touch(filename)
-
- File.socket?(filename).should == false
-
- rm_r filename
- end
-end
-
-platform_is_not :windows do
- describe "File.socket?" do
- before :each do
- # We need a really short name here.
- # On Linux the path length is limited to 107, see unix(7).
- @name = tmp("s")
- @server = UNIXServer.new @name
- end
-
- after :each do
- @server.close
- rm_r @name
- end
-
- it "returns true if the file is a socket" do
- File.socket?(@name).should == true
- end
- end
end
diff --git a/spec/ruby/core/file/split_spec.rb b/spec/ruby/core/file/split_spec.rb
index 2479d4b949..e989a6b86e 100644
--- a/spec/ruby/core/file/split_spec.rb
+++ b/spec/ruby/core/file/split_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "File.split" do
before :each do
@@ -44,17 +44,18 @@ describe "File.split" do
end
it "raises an ArgumentError when not passed a single argument" do
- lambda { File.split }.should raise_error(ArgumentError)
- lambda { File.split('string', 'another string') }.should raise_error(ArgumentError)
+ -> { File.split }.should.raise(ArgumentError)
+ -> { File.split('string', 'another string') }.should.raise(ArgumentError)
end
it "raises a TypeError if the argument is not a String type" do
- lambda { File.split(1) }.should raise_error(TypeError)
+ -> { File.split(1) }.should.raise(TypeError)
end
it "coerces the argument with to_str if it is not a String type" do
- class C; def to_str; "/rubinius/better/than/ruby"; end; end
- File.split(C.new).should == ["/rubinius/better/than", "ruby"]
+ obj = mock("str")
+ obj.should_receive(:to_str).and_return("/one/two/three")
+ File.split(obj).should == ["/one/two", "three"]
end
it "accepts an object that has a #to_path method" do
diff --git a/spec/ruby/core/file/stat/atime_spec.rb b/spec/ruby/core/file/stat/atime_spec.rb
index 575c98ce44..2fecaed300 100644
--- a/spec/ruby/core/file/stat/atime_spec.rb
+++ b/spec/ruby/core/file/stat/atime_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "File::Stat#atime" do
before :each do
@@ -12,7 +12,7 @@ describe "File::Stat#atime" do
it "returns the atime of a File::Stat object" do
st = File.stat(@file)
- st.atime.should be_kind_of(Time)
+ st.atime.should.is_a?(Time)
st.atime.should <= Time.now
end
end
diff --git a/spec/ruby/core/file/stat/birthtime_spec.rb b/spec/ruby/core/file/stat/birthtime_spec.rb
index c2ccc319f1..728f635397 100644
--- a/spec/ruby/core/file/stat/birthtime_spec.rb
+++ b/spec/ruby/core/file/stat/birthtime_spec.rb
@@ -1,27 +1,29 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
-describe "File::Stat#birthtime" do
- before :each do
- @file = tmp('i_exist')
- touch(@file) { |f| f.write "rubinius" }
- end
+platform_is(:windows, :darwin, :freebsd, :netbsd,
+ *ruby_version_is("4.0") { :linux },
+ ) do
+ not_implemented_messages = [
+ "birthtime() function is unimplemented", # unsupported OS/version
+ "birthtime is unimplemented", # unsupported filesystem
+ ]
- after :each do
- rm_r @file
- end
+ describe "File::Stat#birthtime" do
+ before :each do
+ @file = tmp('i_exist')
+ touch(@file) { |f| f.write "rubinius" }
+ end
- platform_is :windows, :darwin, :freebsd, :netbsd do
- it "returns the birthtime of a File::Stat object" do
- st = File.stat(@file)
- st.birthtime.should be_kind_of(Time)
- st.birthtime.should <= Time.now
+ after :each do
+ rm_r @file
end
- end
- platform_is :linux, :openbsd do
- it "raises an NotImplementedError" do
+ it "returns the birthtime of a File::Stat object" do
st = File.stat(@file)
- lambda { st.birthtime }.should raise_error(NotImplementedError)
+ st.birthtime.should.is_a?(Time)
+ st.birthtime.should <= Time.now
+ rescue NotImplementedError => e
+ e.message.should.start_with?(*not_implemented_messages)
end
end
end
diff --git a/spec/ruby/core/file/stat/blksize_spec.rb b/spec/ruby/core/file/stat/blksize_spec.rb
index 4399e6b4bb..4d85b05e4d 100644
--- a/spec/ruby/core/file/stat/blksize_spec.rb
+++ b/spec/ruby/core/file/stat/blksize_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "File::Stat#blksize" do
before :each do
diff --git a/spec/ruby/core/file/stat/blockdev_spec.rb b/spec/ruby/core/file/stat/blockdev_spec.rb
index 440291f130..f986c18125 100644
--- a/spec/ruby/core/file/stat/blockdev_spec.rb
+++ b/spec/ruby/core/file/stat/blockdev_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../../../shared/file/blockdev', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../../../shared/file/blockdev'
+require_relative 'fixtures/classes'
describe "File::Stat#blockdev?" do
it_behaves_like :file_blockdev, :blockdev?, FileStat
diff --git a/spec/ruby/core/file/stat/blocks_spec.rb b/spec/ruby/core/file/stat/blocks_spec.rb
index ca0fd2c8a6..5e0efc8bc2 100644
--- a/spec/ruby/core/file/stat/blocks_spec.rb
+++ b/spec/ruby/core/file/stat/blocks_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "File::Stat#blocks" do
before :each do
@@ -11,17 +11,17 @@ describe "File::Stat#blocks" do
end
platform_is_not :windows do
- it "returns the blocks of a File::Stat object" do
+ it "returns a non-negative integer" do
st = File.stat(@file)
st.blocks.is_a?(Integer).should == true
- st.blocks.should > 0
+ st.blocks.should >= 0
end
end
platform_is :windows do
it "returns nil" do
st = File.stat(@file)
- st.blocks.should be_nil
+ st.blocks.should == nil
end
end
end
diff --git a/spec/ruby/core/file/stat/chardev_spec.rb b/spec/ruby/core/file/stat/chardev_spec.rb
index 25c8c877f7..622fb2052d 100644
--- a/spec/ruby/core/file/stat/chardev_spec.rb
+++ b/spec/ruby/core/file/stat/chardev_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../../../shared/file/chardev', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../../../shared/file/chardev'
+require_relative 'fixtures/classes'
describe "File::Stat#chardev?" do
it_behaves_like :file_chardev, :chardev?, FileStat
diff --git a/spec/ruby/core/file/stat/comparison_spec.rb b/spec/ruby/core/file/stat/comparison_spec.rb
index a70a083ab2..faa3b6bf62 100644
--- a/spec/ruby/core/file/stat/comparison_spec.rb
+++ b/spec/ruby/core/file/stat/comparison_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "File::Stat#<=>" do
before :each do
diff --git a/spec/ruby/core/file/stat/ctime_spec.rb b/spec/ruby/core/file/stat/ctime_spec.rb
index 2f82dfdab6..dbf43a7453 100644
--- a/spec/ruby/core/file/stat/ctime_spec.rb
+++ b/spec/ruby/core/file/stat/ctime_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "File::Stat#ctime" do
before :each do
@@ -12,7 +12,7 @@ describe "File::Stat#ctime" do
it "returns the ctime of a File::Stat object" do
st = File.stat(@file)
- st.ctime.should be_kind_of(Time)
+ st.ctime.should.is_a?(Time)
st.ctime.should <= Time.now
end
end
diff --git a/spec/ruby/core/file/stat/dev_major_spec.rb b/spec/ruby/core/file/stat/dev_major_spec.rb
index 0b00fc4d36..a199eaaa11 100644
--- a/spec/ruby/core/file/stat/dev_major_spec.rb
+++ b/spec/ruby/core/file/stat/dev_major_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "File::Stat#dev_major" do
before :each do
@@ -11,13 +11,13 @@ describe "File::Stat#dev_major" do
platform_is_not :windows do
it "returns the major part of File::Stat#dev" do
- File.stat(@name).dev_major.should be_kind_of(Integer)
+ File.stat(@name).dev_major.should.is_a?(Integer)
end
end
platform_is :windows do
it "returns nil" do
- File.stat(@name).dev_major.should be_nil
+ File.stat(@name).dev_major.should == nil
end
end
end
diff --git a/spec/ruby/core/file/stat/dev_minor_spec.rb b/spec/ruby/core/file/stat/dev_minor_spec.rb
index 0475e3be81..8ce94778ca 100644
--- a/spec/ruby/core/file/stat/dev_minor_spec.rb
+++ b/spec/ruby/core/file/stat/dev_minor_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "File::Stat#dev_minor" do
before :each do
@@ -11,13 +11,13 @@ describe "File::Stat#dev_minor" do
platform_is_not :windows do
it "returns the minor part of File::Stat#dev" do
- File.stat(@name).dev_minor.should be_kind_of(Integer)
+ File.stat(@name).dev_minor.should.is_a?(Integer)
end
end
platform_is :windows do
it "returns nil" do
- File.stat(@name).dev_minor.should be_nil
+ File.stat(@name).dev_minor.should == nil
end
end
end
diff --git a/spec/ruby/core/file/stat/dev_spec.rb b/spec/ruby/core/file/stat/dev_spec.rb
index 3cdc704fd7..cd5e3d175e 100644
--- a/spec/ruby/core/file/stat/dev_spec.rb
+++ b/spec/ruby/core/file/stat/dev_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "File::Stat#dev" do
before :each do
@@ -10,6 +10,6 @@ describe "File::Stat#dev" do
end
it "returns the number of the device on which the file exists" do
- File.stat(@name).dev.should be_kind_of(Integer)
+ File.stat(@name).dev.should.is_a?(Integer)
end
end
diff --git a/spec/ruby/core/file/stat/directory_spec.rb b/spec/ruby/core/file/stat/directory_spec.rb
index 5ead2dca49..c03610388b 100644
--- a/spec/ruby/core/file/stat/directory_spec.rb
+++ b/spec/ruby/core/file/stat/directory_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../../../shared/file/directory', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../../../shared/file/directory'
+require_relative 'fixtures/classes'
describe "File::Stat#directory?" do
it_behaves_like :file_directory, :directory?, FileStat
diff --git a/spec/ruby/core/file/stat/executable_real_spec.rb b/spec/ruby/core/file/stat/executable_real_spec.rb
index 11de0a5b39..23bffe89c5 100644
--- a/spec/ruby/core/file/stat/executable_real_spec.rb
+++ b/spec/ruby/core/file/stat/executable_real_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../../../shared/file/executable_real', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../../../shared/file/executable_real'
+require_relative 'fixtures/classes'
describe "File::Stat#executable_real?" do
it_behaves_like :file_executable_real, :executable_real?, FileStat
diff --git a/spec/ruby/core/file/stat/executable_spec.rb b/spec/ruby/core/file/stat/executable_spec.rb
index e3b1093056..422975d14b 100644
--- a/spec/ruby/core/file/stat/executable_spec.rb
+++ b/spec/ruby/core/file/stat/executable_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../../../shared/file/executable', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../../../shared/file/executable'
+require_relative 'fixtures/classes'
describe "File::Stat#executable?" do
it_behaves_like :file_executable, :executable?, FileStat
diff --git a/spec/ruby/core/file/stat/file_spec.rb b/spec/ruby/core/file/stat/file_spec.rb
index da79dddb00..d141536b4b 100644
--- a/spec/ruby/core/file/stat/file_spec.rb
+++ b/spec/ruby/core/file/stat/file_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../../../shared/file/file', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../../../shared/file/file'
+require_relative 'fixtures/classes'
describe "File::Stat#file?" do
it_behaves_like :file_file, :file?, FileStat
diff --git a/spec/ruby/core/file/stat/ftype_spec.rb b/spec/ruby/core/file/stat/ftype_spec.rb
index 588c371c39..df2e3ada1e 100644
--- a/spec/ruby/core/file/stat/ftype_spec.rb
+++ b/spec/ruby/core/file/stat/ftype_spec.rb
@@ -1,5 +1,5 @@
-require "#{File.dirname(__FILE__)}/../../../spec_helper"
-require "#{File.dirname(__FILE__)}/../fixtures/file_types"
+require_relative '../../../spec_helper'
+require_relative '../fixtures/file_types'
describe "File::Stat#ftype" do
before :all do
@@ -8,7 +8,7 @@ describe "File::Stat#ftype" do
it "returns a String" do
FileSpecs.normal_file do |file|
- File.lstat(file).ftype.should be_kind_of(String)
+ File.lstat(file).ftype.should.is_a?(String)
end
end
@@ -55,10 +55,6 @@ describe "File::Stat#ftype" do
end
end
- # This will silently not execute the block if no socket
- # can be found. However, if you are running X, there is
- # a good chance that if nothing else, at least the X
- # Server socket exists.
it "returns 'socket' when the file is a socket" do
FileSpecs.socket do |socket|
File.lstat(socket).ftype.should == 'socket'
diff --git a/spec/ruby/core/file/stat/gid_spec.rb b/spec/ruby/core/file/stat/gid_spec.rb
index 27356b6401..3bba65bc82 100644
--- a/spec/ruby/core/file/stat/gid_spec.rb
+++ b/spec/ruby/core/file/stat/gid_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "File::Stat#gid" do
before :each do
diff --git a/spec/ruby/core/file/stat/grpowned_spec.rb b/spec/ruby/core/file/stat/grpowned_spec.rb
index 07a52876d0..e7278e229b 100644
--- a/spec/ruby/core/file/stat/grpowned_spec.rb
+++ b/spec/ruby/core/file/stat/grpowned_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../../../shared/file/grpowned', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../../../shared/file/grpowned'
+require_relative 'fixtures/classes'
describe "File::Stat#grpowned?" do
it_behaves_like :file_grpowned, :grpowned?, FileStat
diff --git a/spec/ruby/core/file/stat/ino_spec.rb b/spec/ruby/core/file/stat/ino_spec.rb
index 0339dee54f..c09b6448c7 100644
--- a/spec/ruby/core/file/stat/ino_spec.rb
+++ b/spec/ruby/core/file/stat/ino_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "File::Stat#ino" do
before :each do
@@ -13,26 +13,16 @@ describe "File::Stat#ino" do
platform_is_not :windows do
it "returns the ino of a File::Stat object" do
st = File.stat(@file)
- st.ino.should be_kind_of(Integer)
+ st.ino.should.is_a?(Integer)
st.ino.should > 0
end
end
platform_is :windows do
- ruby_version_is ""..."2.3" do
- it "returns 0" do
- st = File.stat(@file)
- st.ino.should be_kind_of(Integer)
- st.ino.should == 0
- end
- end
-
- ruby_version_is "2.3" do
- it "returns BY_HANDLE_FILE_INFORMATION.nFileIndexHigh/Low of a File::Stat object" do
- st = File.stat(@file)
- st.ino.should be_kind_of(Integer)
- st.ino.should > 0
- end
+ it "returns BY_HANDLE_FILE_INFORMATION.nFileIndexHigh/Low of a File::Stat object" do
+ st = File.stat(@file)
+ st.ino.should.is_a?(Integer)
+ st.ino.should > 0
end
end
end
diff --git a/spec/ruby/core/file/stat/inspect_spec.rb b/spec/ruby/core/file/stat/inspect_spec.rb
index dd2ad21da3..1613b427d0 100644
--- a/spec/ruby/core/file/stat/inspect_spec.rb
+++ b/spec/ruby/core/file/stat/inspect_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "File::Stat#inspect" do
@@ -15,10 +15,10 @@ describe "File::Stat#inspect" do
st = File.stat(@file)
expected = "#<File::Stat dev=0x#{st.dev.to_s(16)}, ino=#{st.ino}, mode=#{sprintf("%07o", st.mode)}, nlink=#{st.nlink}"
expected << ", uid=#{st.uid}, gid=#{st.gid}, rdev=0x#{st.rdev.to_s(16)}, size=#{st.size}, blksize=#{st.blksize.inspect}"
- expected << ", blocks=#{st.blocks.inspect}, atime=#{st.atime}, mtime=#{st.mtime}, ctime=#{st.ctime}"
- platform_is :bsd, :darwin do
+ expected << ", blocks=#{st.blocks.inspect}, atime=#{st.atime.inspect}, mtime=#{st.mtime.inspect}, ctime=#{st.ctime.inspect}"
+ platform_is :netbsd, :freebsd, :darwin do
# Windows has File.birthtime but it's not here since already shown by ctime.
- expected << ", birthtime=#{st.birthtime}"
+ expected << ", birthtime=#{st.birthtime.inspect}"
end
expected << ">"
st.inspect.should == expected
diff --git a/spec/ruby/core/file/stat/mode_spec.rb b/spec/ruby/core/file/stat/mode_spec.rb
index 1c895bf0ce..c85fb85a58 100644
--- a/spec/ruby/core/file/stat/mode_spec.rb
+++ b/spec/ruby/core/file/stat/mode_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "File::Stat#mode" do
before :each do
diff --git a/spec/ruby/core/file/stat/mtime_spec.rb b/spec/ruby/core/file/stat/mtime_spec.rb
index 9dd20dfd65..7844491212 100644
--- a/spec/ruby/core/file/stat/mtime_spec.rb
+++ b/spec/ruby/core/file/stat/mtime_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "File::Stat#mtime" do
before :each do
@@ -12,7 +12,7 @@ describe "File::Stat#mtime" do
it "returns the mtime of a File::Stat object" do
st = File.stat(@file)
- st.mtime.should be_kind_of(Time)
+ st.mtime.should.is_a?(Time)
st.mtime.should <= Time.now
end
end
diff --git a/spec/ruby/core/file/stat/new_spec.rb b/spec/ruby/core/file/stat/new_spec.rb
index ec7d81362f..b8c3600028 100644
--- a/spec/ruby/core/file/stat/new_spec.rb
+++ b/spec/ruby/core/file/stat/new_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "File::Stat#initialize" do
@@ -13,12 +13,14 @@ describe "File::Stat#initialize" do
end
it "raises an exception if the file doesn't exist" do
- lambda { File::Stat.new(tmp("i_am_a_dummy_file_that_doesnt_exist")) }.should raise_error
+ -> {
+ File::Stat.new(tmp("i_am_a_dummy_file_that_doesnt_exist"))
+ }.should.raise(Errno::ENOENT)
end
it "creates a File::Stat object for the given file" do
st = File::Stat.new(@file)
- st.should be_kind_of(File::Stat)
+ st.should.is_a?(File::Stat)
st.ftype.should == 'file'
end
diff --git a/spec/ruby/core/file/stat/nlink_spec.rb b/spec/ruby/core/file/stat/nlink_spec.rb
index e857b07fd1..7143923cfc 100644
--- a/spec/ruby/core/file/stat/nlink_spec.rb
+++ b/spec/ruby/core/file/stat/nlink_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "File::Stat#nlink" do
before :each do
@@ -11,7 +11,7 @@ describe "File::Stat#nlink" do
rm_r @link, @file
end
- platform_is_not :windows do
+ platform_is_not :windows, :android do
it "returns the number of links to a file" do
File::Stat.new(@file).nlink.should == 1
File.link(@file, @link)
diff --git a/spec/ruby/core/file/stat/owned_spec.rb b/spec/ruby/core/file/stat/owned_spec.rb
index 4c4d843bbe..a23ad850c5 100644
--- a/spec/ruby/core/file/stat/owned_spec.rb
+++ b/spec/ruby/core/file/stat/owned_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../../../shared/file/owned', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../../../shared/file/owned'
+require_relative 'fixtures/classes'
describe "File::Stat#owned?" do
it_behaves_like :file_owned, :owned?, FileStat
@@ -18,14 +18,16 @@ describe "File::Stat#owned?" do
it "returns true if the file is owned by the user" do
st = File.stat(@file)
- st.owned?.should == true
+ st.should.owned?
end
- platform_is_not :windows do
- it "returns false if the file is not owned by the user" do
- system_file = '/etc/passwd'
- st = File.stat(system_file)
- st.owned?.should == false
+ platform_is_not :windows, :android do
+ as_user do
+ it "returns false if the file is not owned by the user" do
+ system_file = '/etc/passwd'
+ st = File.stat(system_file)
+ st.should_not.owned?
+ end
end
end
end
diff --git a/spec/ruby/core/file/stat/pipe_spec.rb b/spec/ruby/core/file/stat/pipe_spec.rb
index e4c0b559bb..692dfbf42a 100644
--- a/spec/ruby/core/file/stat/pipe_spec.rb
+++ b/spec/ruby/core/file/stat/pipe_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../../../shared/file/pipe', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../../../shared/file/pipe'
+require_relative 'fixtures/classes'
describe "File::Stat#pipe?" do
it_behaves_like :file_pipe, :pipe?, FileStat
@@ -12,7 +12,7 @@ describe "File::Stat#pipe?" do
touch(filename)
st = File.stat(filename)
- st.pipe?.should == false
+ st.should_not.pipe?
rm_r filename
end
@@ -20,10 +20,10 @@ describe "File::Stat#pipe?" do
platform_is_not :windows do
it "returns true if the file is a pipe" do
filename = tmp("i_am_a_pipe")
- system "mkfifo #{filename}"
+ File.mkfifo(filename)
st = File.stat(filename)
- st.pipe?.should == true
+ st.should.pipe?
rm_r filename
end
diff --git a/spec/ruby/core/file/stat/rdev_major_spec.rb b/spec/ruby/core/file/stat/rdev_major_spec.rb
index f9d514fbc0..e1b44fc2d0 100644
--- a/spec/ruby/core/file/stat/rdev_major_spec.rb
+++ b/spec/ruby/core/file/stat/rdev_major_spec.rb
@@ -1,31 +1,24 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "File::Stat#rdev_major" do
before :each do
- platform_is :solaris do
- @name = "/dev/zfs"
- end
- platform_is_not :solaris do
- @name = tmp("file.txt")
- touch(@name)
- end
+ @name = tmp("file.txt")
+ touch(@name)
end
after :each do
- platform_is_not :solaris do
- rm_r @name
- end
+ rm_r @name
end
platform_is_not :windows do
it "returns the major part of File::Stat#rdev" do
- File.stat(@name).rdev_major.should be_kind_of(Integer)
+ File.stat(@name).rdev_major.should.is_a?(Integer)
end
end
platform_is :windows do
it "returns nil" do
- File.stat(@name).rdev_major.should be_nil
+ File.stat(@name).rdev_major.should == nil
end
end
end
diff --git a/spec/ruby/core/file/stat/rdev_minor_spec.rb b/spec/ruby/core/file/stat/rdev_minor_spec.rb
index 67399c5e68..8af3b9f587 100644
--- a/spec/ruby/core/file/stat/rdev_minor_spec.rb
+++ b/spec/ruby/core/file/stat/rdev_minor_spec.rb
@@ -1,31 +1,24 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "File::Stat#rdev_minor" do
before :each do
- platform_is :solaris do
- @name = "/dev/zfs"
- end
- platform_is_not :solaris do
- @name = tmp("file.txt")
- touch(@name)
- end
+ @name = tmp("file.txt")
+ touch(@name)
end
after :each do
- platform_is_not :solaris do
- rm_r @name
- end
+ rm_r @name
end
platform_is_not :windows do
it "returns the minor part of File::Stat#rdev" do
- File.stat(@name).rdev_minor.should be_kind_of(Integer)
+ File.stat(@name).rdev_minor.should.is_a?(Integer)
end
end
platform_is :windows do
it "returns nil" do
- File.stat(@name).rdev_minor.should be_nil
+ File.stat(@name).rdev_minor.should == nil
end
end
end
diff --git a/spec/ruby/core/file/stat/rdev_spec.rb b/spec/ruby/core/file/stat/rdev_spec.rb
index 12f97fb044..7e4252fcc6 100644
--- a/spec/ruby/core/file/stat/rdev_spec.rb
+++ b/spec/ruby/core/file/stat/rdev_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "File::Stat#rdev" do
before :each do
@@ -10,6 +10,6 @@ describe "File::Stat#rdev" do
end
it "returns the number of the device this file represents which the file exists" do
- File.stat(@name).rdev.should be_kind_of(Integer)
+ File.stat(@name).rdev.should.is_a?(Integer)
end
end
diff --git a/spec/ruby/core/file/stat/readable_real_spec.rb b/spec/ruby/core/file/stat/readable_real_spec.rb
index 49412f1df2..f138fd7b00 100644
--- a/spec/ruby/core/file/stat/readable_real_spec.rb
+++ b/spec/ruby/core/file/stat/readable_real_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../../../shared/file/readable_real', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../../../shared/file/readable_real'
+require_relative 'fixtures/classes'
describe "File::Stat#readable_real?" do
it_behaves_like :file_readable_real, :readable_real?, FileStat
diff --git a/spec/ruby/core/file/stat/readable_spec.rb b/spec/ruby/core/file/stat/readable_spec.rb
index 3d81975309..e99e48feed 100644
--- a/spec/ruby/core/file/stat/readable_spec.rb
+++ b/spec/ruby/core/file/stat/readable_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../../../shared/file/readable', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../../../shared/file/readable'
+require_relative 'fixtures/classes'
describe "File::Stat#readable?" do
it_behaves_like :file_readable, :readable?, FileStat
diff --git a/spec/ruby/core/file/stat/setgid_spec.rb b/spec/ruby/core/file/stat/setgid_spec.rb
index 318a72b437..c0748ede57 100644
--- a/spec/ruby/core/file/stat/setgid_spec.rb
+++ b/spec/ruby/core/file/stat/setgid_spec.rb
@@ -1,11 +1,7 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../../../shared/file/setgid', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../../../shared/file/setgid'
+require_relative 'fixtures/classes'
describe "File::Stat#setgid?" do
it_behaves_like :file_setgid, :setgid?, FileStat
end
-
-describe "File::Stat#setgid?" do
- it "needs to be reviewed for spec completeness"
-end
diff --git a/spec/ruby/core/file/stat/setuid_spec.rb b/spec/ruby/core/file/stat/setuid_spec.rb
index 5057af0ccc..6408120fc4 100644
--- a/spec/ruby/core/file/stat/setuid_spec.rb
+++ b/spec/ruby/core/file/stat/setuid_spec.rb
@@ -1,11 +1,7 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../../../shared/file/setuid', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../../../shared/file/setuid'
+require_relative 'fixtures/classes'
describe "File::Stat#setuid?" do
it_behaves_like :file_setuid, :setuid?, FileStat
end
-
-describe "File::Stat#setuid?" do
- it "needs to be reviewed for spec completeness"
-end
diff --git a/spec/ruby/core/file/stat/size_spec.rb b/spec/ruby/core/file/stat/size_spec.rb
index 84db12d591..4b4f57f8c8 100644
--- a/spec/ruby/core/file/stat/size_spec.rb
+++ b/spec/ruby/core/file/stat/size_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../../../shared/file/size', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../../../shared/file/size'
+require_relative 'fixtures/classes'
describe "File::Stat.size?" do
it_behaves_like :file_size, :size?, FileStat
diff --git a/spec/ruby/core/file/stat/socket_spec.rb b/spec/ruby/core/file/stat/socket_spec.rb
index b25d9314f9..09740be110 100644
--- a/spec/ruby/core/file/stat/socket_spec.rb
+++ b/spec/ruby/core/file/stat/socket_spec.rb
@@ -1,11 +1,7 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../../../shared/file/socket', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../../../shared/file/socket'
+require_relative 'fixtures/classes'
describe "File::Stat#socket?" do
it_behaves_like :file_socket, :socket?, FileStat
end
-
-describe "File::Stat#socket?" do
- it "needs to be reviewed for spec completeness"
-end
diff --git a/spec/ruby/core/file/stat/sticky_spec.rb b/spec/ruby/core/file/stat/sticky_spec.rb
index c2fefbe106..7083e644e9 100644
--- a/spec/ruby/core/file/stat/sticky_spec.rb
+++ b/spec/ruby/core/file/stat/sticky_spec.rb
@@ -1,11 +1,7 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../../../shared/file/sticky', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../../../shared/file/sticky'
+require_relative 'fixtures/classes'
describe "File::Stat#sticky?" do
it_behaves_like :file_sticky, :sticky?, FileStat
end
-
-describe "File::Stat#sticky?" do
- it "needs to be reviewed for spec completeness"
-end
diff --git a/spec/ruby/core/file/stat/symlink_spec.rb b/spec/ruby/core/file/stat/symlink_spec.rb
index 579c1de0ad..0def832a4c 100644
--- a/spec/ruby/core/file/stat/symlink_spec.rb
+++ b/spec/ruby/core/file/stat/symlink_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../../../shared/file/symlink', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../../../shared/file/symlink'
+require_relative 'fixtures/classes'
describe "File::Stat#symlink?" do
it_behaves_like :file_symlink, :symlink?, FileStat
diff --git a/spec/ruby/core/file/stat/uid_spec.rb b/spec/ruby/core/file/stat/uid_spec.rb
index 75be97c234..b97147db21 100644
--- a/spec/ruby/core/file/stat/uid_spec.rb
+++ b/spec/ruby/core/file/stat/uid_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "File::Stat#uid" do
before :each do
diff --git a/spec/ruby/core/file/stat/world_readable_spec.rb b/spec/ruby/core/file/stat/world_readable_spec.rb
index 178e39a1ea..d94a02205e 100644
--- a/spec/ruby/core/file/stat/world_readable_spec.rb
+++ b/spec/ruby/core/file/stat/world_readable_spec.rb
@@ -1,9 +1,9 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../../../shared/file/world_readable', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../../../shared/file/world_readable'
+require_relative 'fixtures/classes'
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..8100008344 100644
--- a/spec/ruby/core/file/stat/world_writable_spec.rb
+++ b/spec/ruby/core/file/stat/world_writable_spec.rb
@@ -1,9 +1,9 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../../../shared/file/world_writable', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../../../shared/file/world_writable'
+require_relative 'fixtures/classes'
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/stat/writable_real_spec.rb b/spec/ruby/core/file/stat/writable_real_spec.rb
index e069db507b..4c9e78eb70 100644
--- a/spec/ruby/core/file/stat/writable_real_spec.rb
+++ b/spec/ruby/core/file/stat/writable_real_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../../../shared/file/writable_real', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../../../shared/file/writable_real'
+require_relative 'fixtures/classes'
describe "File::Stat#writable_real?" do
it_behaves_like :file_writable_real, :writable_real?, FileStat
diff --git a/spec/ruby/core/file/stat/writable_spec.rb b/spec/ruby/core/file/stat/writable_spec.rb
index b720e59f81..551268751f 100644
--- a/spec/ruby/core/file/stat/writable_spec.rb
+++ b/spec/ruby/core/file/stat/writable_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../../../shared/file/writable', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../../../shared/file/writable'
+require_relative 'fixtures/classes'
describe "File::Stat#writable?" do
it_behaves_like :file_writable, :writable?, FileStat
diff --git a/spec/ruby/core/file/stat/zero_spec.rb b/spec/ruby/core/file/stat/zero_spec.rb
index 127c706b90..74facac66a 100644
--- a/spec/ruby/core/file/stat/zero_spec.rb
+++ b/spec/ruby/core/file/stat/zero_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../../../shared/file/zero', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../../../shared/file/zero'
+require_relative 'fixtures/classes'
describe "File::Stat#zero?" do
it_behaves_like :file_zero, :zero?, FileStat
diff --git a/spec/ruby/core/file/stat_spec.rb b/spec/ruby/core/file/stat_spec.rb
index 1ea003142e..d5238b6331 100644
--- a/spec/ruby/core/file/stat_spec.rb
+++ b/spec/ruby/core/file/stat_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/stat', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/stat'
describe "File.stat" do
it_behaves_like :file_stat, :stat
@@ -23,14 +23,14 @@ platform_is_not :windows do
st = f.stat
- st.file?.should == true
- st.zero?.should == false
+ st.should.file?
+ st.should_not.zero?
st.size.should == 8
st.size?.should == 8
st.blksize.should >= 0
- st.atime.should be_kind_of(Time)
- st.ctime.should be_kind_of(Time)
- st.mtime.should be_kind_of(Time)
+ st.atime.should.is_a?(Time)
+ st.ctime.should.is_a?(Time)
+ st.mtime.should.is_a?(Time)
end
end
@@ -38,8 +38,18 @@ platform_is_not :windows do
File.symlink(@file, @link)
st = File.stat(@link)
- st.file?.should == true
- st.symlink?.should == false
+ st.should.file?
+ st.should_not.symlink?
+ end
+
+ it "returns an error when given missing non-ASCII path" do
+ missing_path = "/missingfilepath\xE3E4".b
+ -> {
+ File.stat(missing_path)
+ }.should.raise(SystemCallError) { |e|
+ [Errno::ENOENT, Errno::EILSEQ].should.include?(e.class)
+ e.message.should.include?(missing_path)
+ }
end
end
end
diff --git a/spec/ruby/core/file/sticky_spec.rb b/spec/ruby/core/file/sticky_spec.rb
index d01e2b6818..782541abf3 100644
--- a/spec/ruby/core/file/sticky_spec.rb
+++ b/spec/ruby/core/file/sticky_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/file/sticky', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../../shared/file/sticky'
describe "File.sticky?" do
it_behaves_like :file_sticky, :sticky?, File
@@ -35,13 +35,13 @@ describe "File.sticky?" do
end
platform_is :bsd do
- # FreeBSD and NetBSD can't set stiky bit to a normal file
+ # FreeBSD and NetBSD can't set sticky bit to a normal file
it "cannot set sticky bit to a normal file" do
filename = tmp("i_exist")
touch(filename)
stat = File.stat(filename)
mode = stat.mode
- raise_error(Errno::EFTYPE){File.chmod(mode|01000, filename)}
+ -> { File.chmod(mode|01000, filename) }.should.raise(Errno::EFTYPE)
File.sticky?(filename).should == false
rm_r filename
diff --git a/spec/ruby/core/file/symlink_spec.rb b/spec/ruby/core/file/symlink_spec.rb
index 2426b8c9a7..4ceeb28c84 100644
--- a/spec/ruby/core/file/symlink_spec.rb
+++ b/spec/ruby/core/file/symlink_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/file/symlink', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../../shared/file/symlink'
describe "File.symlink" do
before :each do
@@ -32,18 +32,18 @@ describe "File.symlink" do
it "raises an Errno::EEXIST if the target already exists" do
File.symlink(@file, @link)
- lambda { File.symlink(@file, @link) }.should raise_error(Errno::EEXIST)
+ -> { File.symlink(@file, @link) }.should.raise(Errno::EEXIST)
end
it "raises an ArgumentError if not called with two arguments" do
- lambda { File.symlink }.should raise_error(ArgumentError)
- lambda { File.symlink(@file) }.should raise_error(ArgumentError)
+ -> { File.symlink }.should.raise(ArgumentError)
+ -> { File.symlink(@file) }.should.raise(ArgumentError)
end
it "raises a TypeError if not called with String types" do
- lambda { File.symlink(@file, nil) }.should raise_error(TypeError)
- lambda { File.symlink(@file, 1) }.should raise_error(TypeError)
- lambda { File.symlink(1, 1) }.should raise_error(TypeError)
+ -> { File.symlink(@file, nil) }.should.raise(TypeError)
+ -> { File.symlink(@file, 1) }.should.raise(TypeError)
+ -> { File.symlink(1, 1) }.should.raise(TypeError)
end
end
end
diff --git a/spec/ruby/core/file/to_path_spec.rb b/spec/ruby/core/file/to_path_spec.rb
index 3dc801cc27..b968d3b2b9 100644
--- a/spec/ruby/core/file/to_path_spec.rb
+++ b/spec/ruby/core/file/to_path_spec.rb
@@ -1,9 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "File#to_path" do
before :each do
- @name = "file_to_path"
- @path = tmp(@name)
+ @path = tmp("file_to_path")
+ @name = File.basename(@path)
touch @path
end
@@ -14,7 +14,31 @@ describe "File#to_path" do
it "returns a String" do
@file = File.new @path
- @file.to_path.should be_an_instance_of(String)
+ @file.to_path.should.instance_of?(String)
+ end
+
+ it "returns a different String on every call" do
+ @file = File.new @path
+ path1 = @file.to_path
+ path2 = @file.to_path
+ path1.should == path2
+ path1.should_not.equal?(path2)
+ end
+
+ it "returns a mutable String" do
+ @file = File.new @path.dup.freeze
+ path = @file.to_path
+ path.should == @path
+ path.should_not.frozen?
+ path << "test"
+ @file.to_path.should == @path
+ 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.to_path.should == @path
end
it "does not normalise the path it returns" do
@@ -39,11 +63,22 @@ describe "File#to_path" do
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")
+ 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
+
+ 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
end
end
end
diff --git a/spec/ruby/core/file/truncate_spec.rb b/spec/ruby/core/file/truncate_spec.rb
index a120c610b8..5f37f34155 100644
--- a/spec/ruby/core/file/truncate_spec.rb
+++ b/spec/ruby/core/file/truncate_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "File.truncate" do
before :each do
@@ -18,7 +18,7 @@ describe "File.truncate" do
File.open(@name, "r") do |f|
f.read(99).should == "12345"
- f.eof?.should == true
+ f.should.eof?
end
end
@@ -54,29 +54,29 @@ describe "File.truncate" do
rm_r not_existing_file
begin
- lambda { File.truncate(not_existing_file, 5) }.should raise_error(Errno::ENOENT)
+ -> { File.truncate(not_existing_file, 5) }.should.raise(Errno::ENOENT)
ensure
rm_r not_existing_file
end
end
it "raises an ArgumentError if not passed two arguments" do
- lambda { File.truncate }.should raise_error(ArgumentError)
- lambda { File.truncate(@name) }.should raise_error(ArgumentError)
+ -> { File.truncate }.should.raise(ArgumentError)
+ -> { File.truncate(@name) }.should.raise(ArgumentError)
end
platform_is_not :netbsd, :openbsd do
it "raises an Errno::EINVAL if the length argument is not valid" do
- lambda { File.truncate(@name, -1) }.should raise_error(Errno::EINVAL) # May fail
+ -> { File.truncate(@name, -1) }.should.raise(Errno::EINVAL) # May fail
end
end
it "raises a TypeError if not passed a String type for the first argument" do
- lambda { File.truncate(1, 1) }.should raise_error(TypeError)
+ -> { File.truncate(1, 1) }.should.raise(TypeError)
end
it "raises a TypeError if not passed an Integer type for the second argument" do
- lambda { File.truncate(@name, nil) }.should raise_error(TypeError)
+ -> { File.truncate(@name, nil) }.should.raise(TypeError)
end
it "accepts an object that has a #to_path method" do
@@ -120,7 +120,7 @@ describe "File#truncate" do
File.size(@name).should == 5
File.open(@name, "r") do |f|
f.read(99).should == "12345"
- f.eof?.should == true
+ f.should.eof?
end
end
@@ -149,29 +149,29 @@ describe "File#truncate" do
end
it "raises an ArgumentError if not passed one argument" do
- lambda { @file.truncate }.should raise_error(ArgumentError)
- lambda { @file.truncate(1) }.should_not raise_error(ArgumentError)
+ -> { @file.truncate }.should.raise(ArgumentError)
+ -> { @file.truncate(1) }.should_not.raise(ArgumentError)
end
platform_is_not :netbsd do
it "raises an Errno::EINVAL if the length argument is not valid" do
- lambda { @file.truncate(-1) }.should raise_error(Errno::EINVAL) # May fail
+ -> { @file.truncate(-1) }.should.raise(Errno::EINVAL) # May fail
end
end
it "raises an IOError if file is closed" do
@file.close
- @file.closed?.should == true
- lambda { @file.truncate(42) }.should raise_error(IOError)
+ @file.should.closed?
+ -> { @file.truncate(42) }.should.raise(IOError)
end
it "raises an IOError if file is not opened for writing" do
File.open(@name, 'r') do |file|
- lambda { file.truncate(42) }.should raise_error(IOError)
+ -> { file.truncate(42) }.should.raise(IOError)
end
end
it "raises a TypeError if not passed an Integer type for the for the argument" do
- lambda { @file.truncate(nil) }.should raise_error(TypeError)
+ -> { @file.truncate(nil) }.should.raise(TypeError)
end
end
diff --git a/spec/ruby/core/file/umask_spec.rb b/spec/ruby/core/file/umask_spec.rb
index 2286bf064f..fea8cf7633 100644
--- a/spec/ruby/core/file/umask_spec.rb
+++ b/spec/ruby/core/file/umask_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "File.umask" do
before :each do
@@ -12,8 +12,8 @@ describe "File.umask" do
File.umask(@orig_umask)
end
- it "returns a Fixnum" do
- File.umask.should be_kind_of(Fixnum)
+ it "returns an Integer" do
+ File.umask.should.is_a?(Integer)
end
platform_is_not :windows do
@@ -30,18 +30,6 @@ describe "File.umask" do
end
end
- it "always succeeds with any integer values" do
- vals = [-2**30, -2**16, -2**8, -2,
- -1.5, -1, 0.5, 0, 1, 2, 7.77777, 16, 32, 64, 2**8, 2**16, 2**30]
- vals.each { |v|
- lambda { File.umask(v) }.should_not raise_error
- }
- end
-
- it "raises ArgumentError when more than one argument is provided" do
- lambda { File.umask(022, 022) }.should raise_error(ArgumentError)
- end
-
platform_is :windows do
it "returns the current umask value for this process (basic)" do
File.umask.should == 0
@@ -57,4 +45,13 @@ describe "File.umask" do
File.umask.should == 0
end
end
+
+ it "raises RangeError with too large values" do
+ -> { File.umask(2**64) }.should.raise(RangeError)
+ -> { File.umask(-2**63 - 1) }.should.raise(RangeError)
+ end
+
+ it "raises ArgumentError when more than one argument is provided" do
+ -> { File.umask(022, 022) }.should.raise(ArgumentError)
+ end
end
diff --git a/spec/ruby/core/file/unlink_spec.rb b/spec/ruby/core/file/unlink_spec.rb
index a1e96aef6a..db0c08f3ae 100644
--- a/spec/ruby/core/file/unlink_spec.rb
+++ b/spec/ruby/core/file/unlink_spec.rb
@@ -1,6 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/unlink', __FILE__)
+require_relative '../../spec_helper'
describe "File.unlink" do
- it_behaves_like(:file_unlink, :unlink)
+ it "is an alias of File.delete" do
+ File.method(:unlink).should == File.method(:delete)
+ end
end
diff --git a/spec/ruby/core/file/utime_spec.rb b/spec/ruby/core/file/utime_spec.rb
index 73112420d1..d87626be50 100644
--- a/spec/ruby/core/file/utime_spec.rb
+++ b/spec/ruby/core/file/utime_spec.rb
@@ -1,36 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/update_time'
describe "File.utime" do
- before :each do
- @atime = Time.now
- @mtime = Time.now
- @file1 = tmp("specs_file_utime1")
- @file2 = tmp("specs_file_utime2")
- touch @file1
- touch @file2
- end
-
- after :each do
- rm_r @file1, @file2
- end
-
- it "sets the access and modification time of each file" do
- File.utime(@atime, @mtime, @file1, @file2)
- File.atime(@file1).to_i.should be_close(@atime.to_i, 2)
- File.mtime(@file1).to_i.should be_close(@mtime.to_i, 2)
- File.atime(@file2).to_i.should be_close(@atime.to_i, 2)
- File.mtime(@file2).to_i.should be_close(@mtime.to_i, 2)
- end
-
- it "uses the current times if two nil values are passed" do
- File.utime(nil, nil, @file1, @file2)
- File.atime(@file1).to_i.should be_close(Time.now.to_i, 2)
- File.mtime(@file1).to_i.should be_close(Time.now.to_i, 2)
- File.atime(@file2).to_i.should be_close(Time.now.to_i, 2)
- File.mtime(@file2).to_i.should be_close(Time.now.to_i, 2)
- end
-
- it "accepts an object that has a #to_path method" do
- File.utime(@atime, @mtime, mock_to_path(@file1), mock_to_path(@file2))
- end
+ it_behaves_like :update_time, :utime
end
diff --git a/spec/ruby/core/file/world_readable_spec.rb b/spec/ruby/core/file/world_readable_spec.rb
index a130f0d115..0f5e0b13d7 100644
--- a/spec/ruby/core/file/world_readable_spec.rb
+++ b/spec/ruby/core/file/world_readable_spec.rb
@@ -1,12 +1,12 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/file/world_readable', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../../shared/file/world_readable'
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
- File.exist?(file).should be_false
- File.world_readable?(file).should be_nil
+ File.should_not.exist?(file)
+ File.world_readable?(file).should == nil
end
end
diff --git a/spec/ruby/core/file/world_writable_spec.rb b/spec/ruby/core/file/world_writable_spec.rb
index 5a39643ef9..46ba6832f9 100644
--- a/spec/ruby/core/file/world_writable_spec.rb
+++ b/spec/ruby/core/file/world_writable_spec.rb
@@ -1,12 +1,12 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/file/world_writable', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../../shared/file/world_writable'
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
- File.exist?(file).should be_false
- File.world_writable?(file).should be_nil
+ File.should_not.exist?(file)
+ File.world_writable?(file).should == nil
end
end
diff --git a/spec/ruby/core/file/writable_real_spec.rb b/spec/ruby/core/file/writable_real_spec.rb
index 36f576e222..bea4c4c262 100644
--- a/spec/ruby/core/file/writable_real_spec.rb
+++ b/spec/ruby/core/file/writable_real_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/file/writable_real', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../../shared/file/writable_real'
describe "File.writable_real?" do
it_behaves_like :file_writable_real, :writable_real?, File
diff --git a/spec/ruby/core/file/writable_spec.rb b/spec/ruby/core/file/writable_spec.rb
index 4f6213ec77..519837b0d1 100644
--- a/spec/ruby/core/file/writable_spec.rb
+++ b/spec/ruby/core/file/writable_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/file/writable', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../../shared/file/writable'
describe "File.writable?" do
it_behaves_like :file_writable, :writable?, File
diff --git a/spec/ruby/core/file/zero_spec.rb b/spec/ruby/core/file/zero_spec.rb
index 0fc087faff..09b0decf48 100644
--- a/spec/ruby/core/file/zero_spec.rb
+++ b/spec/ruby/core/file/zero_spec.rb
@@ -1,13 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/file/zero', __FILE__)
+require_relative '../../spec_helper'
describe "File.zero?" do
- it_behaves_like :file_zero, :zero?, File
- it_behaves_like :file_zero_missing, :zero?, File
-
- platform_is :solaris do
- it "returns false for /dev/null" do
- File.zero?('/dev/null').should == true
- end
+ it "is an alias of File.empty?" do
+ File.method(:zero?).should == File.method(:empty?)
end
end
diff --git a/spec/ruby/core/filetest/blockdev_spec.rb b/spec/ruby/core/filetest/blockdev_spec.rb
index 13bc98b483..4f32991c4a 100644
--- a/spec/ruby/core/filetest/blockdev_spec.rb
+++ b/spec/ruby/core/filetest/blockdev_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/file/blockdev', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../../shared/file/blockdev'
describe "FileTest.blockdev?" do
it_behaves_like :file_blockdev, :blockdev?, FileTest
diff --git a/spec/ruby/core/filetest/chardev_spec.rb b/spec/ruby/core/filetest/chardev_spec.rb
index c126c81658..59c48bb2d5 100644
--- a/spec/ruby/core/filetest/chardev_spec.rb
+++ b/spec/ruby/core/filetest/chardev_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/file/chardev', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../../shared/file/chardev'
describe "FileTest.chardev?" do
it_behaves_like :file_chardev, :chardev?, FileTest
diff --git a/spec/ruby/core/filetest/directory_spec.rb b/spec/ruby/core/filetest/directory_spec.rb
index e6f1ae51d2..8f9d0e3901 100644
--- a/spec/ruby/core/filetest/directory_spec.rb
+++ b/spec/ruby/core/filetest/directory_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/file/directory', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../../shared/file/directory'
describe "FileTest.directory?" do
it_behaves_like :file_directory, :directory?, FileTest
diff --git a/spec/ruby/core/filetest/empty_spec.rb b/spec/ruby/core/filetest/empty_spec.rb
new file mode 100644
index 0000000000..2c7fbe0dcd
--- /dev/null
+++ b/spec/ruby/core/filetest/empty_spec.rb
@@ -0,0 +1,7 @@
+require_relative '../../spec_helper'
+require_relative '../../shared/file/zero'
+
+describe "FileTest.empty?" do
+ it_behaves_like :file_zero, :empty?, FileTest
+ it_behaves_like :file_zero_missing, :empty?, FileTest
+end
diff --git a/spec/ruby/core/filetest/executable_real_spec.rb b/spec/ruby/core/filetest/executable_real_spec.rb
index 37511e6c88..da65245785 100644
--- a/spec/ruby/core/filetest/executable_real_spec.rb
+++ b/spec/ruby/core/filetest/executable_real_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/file/executable_real', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../../shared/file/executable_real'
describe "FileTest.executable_real?" do
it_behaves_like :file_executable_real, :executable_real?, FileTest
diff --git a/spec/ruby/core/filetest/executable_spec.rb b/spec/ruby/core/filetest/executable_spec.rb
index 477e989423..03056669f6 100644
--- a/spec/ruby/core/filetest/executable_spec.rb
+++ b/spec/ruby/core/filetest/executable_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/file/executable', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../../shared/file/executable'
describe "FileTest.executable?" do
it_behaves_like :file_executable, :executable?, FileTest
diff --git a/spec/ruby/core/filetest/exist_spec.rb b/spec/ruby/core/filetest/exist_spec.rb
index b375d3a4b1..612ffa9fcb 100644
--- a/spec/ruby/core/filetest/exist_spec.rb
+++ b/spec/ruby/core/filetest/exist_spec.rb
@@ -1,6 +1,12 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/file/exist', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../../shared/file/exist'
describe "FileTest.exist?" do
it_behaves_like :file_exist, :exist?, FileTest
end
+
+describe "FileTest.exists?" do
+ it "has been removed" do
+ FileTest.should_not.respond_to?(:exists?)
+ end
+end
diff --git a/spec/ruby/core/filetest/exists_spec.rb b/spec/ruby/core/filetest/exists_spec.rb
deleted file mode 100644
index 09d4ca1a83..0000000000
--- a/spec/ruby/core/filetest/exists_spec.rb
+++ /dev/null
@@ -1,6 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/file/exist', __FILE__)
-
-describe "FileTest.exists?" do
- it_behaves_like :file_exist, :exists?, FileTest
-end
diff --git a/spec/ruby/core/filetest/file_spec.rb b/spec/ruby/core/filetest/file_spec.rb
index 887dc1da88..0c0cb82f96 100644
--- a/spec/ruby/core/filetest/file_spec.rb
+++ b/spec/ruby/core/filetest/file_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/file/file', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../../shared/file/file'
describe "File.file?" do
it_behaves_like :file_file, :file?, File
diff --git a/spec/ruby/core/filetest/grpowned_spec.rb b/spec/ruby/core/filetest/grpowned_spec.rb
index 950671aae9..d6bd6abd71 100644
--- a/spec/ruby/core/filetest/grpowned_spec.rb
+++ b/spec/ruby/core/filetest/grpowned_spec.rb
@@ -1,10 +1,10 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/file/grpowned', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../../shared/file/grpowned'
describe "FileTest.grpowned?" do
it_behaves_like :file_grpowned, :grpowned?, FileTest
it "returns false if the file doesn't exist" do
- FileTest.grpowned?("xxx-tmp-doesnt_exist-blah").should be_false
+ FileTest.grpowned?("xxx-tmp-doesnt_exist-blah").should == false
end
end
diff --git a/spec/ruby/core/filetest/identical_spec.rb b/spec/ruby/core/filetest/identical_spec.rb
index cb4bc82873..b00c5b75e8 100644
--- a/spec/ruby/core/filetest/identical_spec.rb
+++ b/spec/ruby/core/filetest/identical_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/file/identical', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../../shared/file/identical'
describe "FileTest.identical?" do
it_behaves_like :file_identical, :identical?, FileTest
diff --git a/spec/ruby/core/filetest/owned_spec.rb b/spec/ruby/core/filetest/owned_spec.rb
index 8483f2af21..b26165f98d 100644
--- a/spec/ruby/core/filetest/owned_spec.rb
+++ b/spec/ruby/core/filetest/owned_spec.rb
@@ -1,10 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/file/owned', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../../shared/file/owned'
describe "FileTest.owned?" do
it_behaves_like :file_owned, :owned?, FileTest
end
-
-describe "FileTest.owned?" do
- it "needs to be reviewed for spec completeness"
-end
diff --git a/spec/ruby/core/filetest/pipe_spec.rb b/spec/ruby/core/filetest/pipe_spec.rb
index 0147dae820..8ce67568fb 100644
--- a/spec/ruby/core/filetest/pipe_spec.rb
+++ b/spec/ruby/core/filetest/pipe_spec.rb
@@ -1,10 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/file/pipe', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../../shared/file/pipe'
describe "FileTest.pipe?" do
it_behaves_like :file_pipe, :pipe?, FileTest
end
-
-describe "FileTest.pipe?" do
- it "needs to be reviewed for spec completeness"
-end
diff --git a/spec/ruby/core/filetest/readable_real_spec.rb b/spec/ruby/core/filetest/readable_real_spec.rb
index 62ac972834..82c62fe8f0 100644
--- a/spec/ruby/core/filetest/readable_real_spec.rb
+++ b/spec/ruby/core/filetest/readable_real_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/file/readable_real', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../../shared/file/readable_real'
describe "FileTest.readable_real?" do
it_behaves_like :file_readable_real, :readable_real?, FileTest
diff --git a/spec/ruby/core/filetest/readable_spec.rb b/spec/ruby/core/filetest/readable_spec.rb
index 086a9e5819..039ca56ca3 100644
--- a/spec/ruby/core/filetest/readable_spec.rb
+++ b/spec/ruby/core/filetest/readable_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/file/readable', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../../shared/file/readable'
describe "FileTest.readable?" do
it_behaves_like :file_readable, :readable?, FileTest
diff --git a/spec/ruby/core/filetest/setgid_spec.rb b/spec/ruby/core/filetest/setgid_spec.rb
index f6e3f5b979..c83ffccb2a 100644
--- a/spec/ruby/core/filetest/setgid_spec.rb
+++ b/spec/ruby/core/filetest/setgid_spec.rb
@@ -1,10 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/file/setgid', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../../shared/file/setgid'
describe "FileTest.setgid?" do
it_behaves_like :file_setgid, :setgid?, FileTest
end
-
-describe "FileTest.setgid?" do
- it "needs to be reviewed for spec completeness"
-end
diff --git a/spec/ruby/core/filetest/setuid_spec.rb b/spec/ruby/core/filetest/setuid_spec.rb
index f077ec5b65..1c1fd2efe4 100644
--- a/spec/ruby/core/filetest/setuid_spec.rb
+++ b/spec/ruby/core/filetest/setuid_spec.rb
@@ -1,10 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/file/setuid', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../../shared/file/setuid'
describe "FileTest.setuid?" do
it_behaves_like :file_setuid, :setuid?, FileTest
end
-
-describe "FileTest.setuid?" do
- it "needs to be reviewed for spec completeness"
-end
diff --git a/spec/ruby/core/filetest/size_spec.rb b/spec/ruby/core/filetest/size_spec.rb
index 398a8e69b8..dc3ddb127f 100644
--- a/spec/ruby/core/filetest/size_spec.rb
+++ b/spec/ruby/core/filetest/size_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/file/size', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../../shared/file/size'
describe "FileTest.size?" do
it_behaves_like :file_size, :size?, FileTest
diff --git a/spec/ruby/core/filetest/socket_spec.rb b/spec/ruby/core/filetest/socket_spec.rb
index debe032ada..f274be6318 100644
--- a/spec/ruby/core/filetest/socket_spec.rb
+++ b/spec/ruby/core/filetest/socket_spec.rb
@@ -1,10 +1,10 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/file/socket', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../../shared/file/socket'
describe "FileTest.socket?" do
it_behaves_like :file_socket, :socket?, FileTest
-end
-describe "FileTest.socket?" do
- it "needs to be reviewed for spec completeness"
+ it "returns false if file does not exist" do
+ FileTest.socket?("I_am_a_bogus_file").should == false
+ end
end
diff --git a/spec/ruby/core/filetest/sticky_spec.rb b/spec/ruby/core/filetest/sticky_spec.rb
index ca38a45c9d..8b776b6672 100644
--- a/spec/ruby/core/filetest/sticky_spec.rb
+++ b/spec/ruby/core/filetest/sticky_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/file/sticky', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../../shared/file/sticky'
describe "FileTest.sticky?" do
it_behaves_like :file_sticky, :sticky?, FileTest
diff --git a/spec/ruby/core/filetest/symlink_spec.rb b/spec/ruby/core/filetest/symlink_spec.rb
index 0812b09f5a..41c924dc1a 100644
--- a/spec/ruby/core/filetest/symlink_spec.rb
+++ b/spec/ruby/core/filetest/symlink_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/file/symlink', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../../shared/file/symlink'
describe "FileTest.symlink?" do
it_behaves_like :file_symlink, :symlink?, FileTest
diff --git a/spec/ruby/core/filetest/world_readable_spec.rb b/spec/ruby/core/filetest/world_readable_spec.rb
index ef84c1ad01..72abdd9e03 100644
--- a/spec/ruby/core/filetest/world_readable_spec.rb
+++ b/spec/ruby/core/filetest/world_readable_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "FileTest.world_readable?" do
it "needs to be reviewed for spec completeness"
diff --git a/spec/ruby/core/filetest/world_writable_spec.rb b/spec/ruby/core/filetest/world_writable_spec.rb
index 2803f3576a..533f698fd3 100644
--- a/spec/ruby/core/filetest/world_writable_spec.rb
+++ b/spec/ruby/core/filetest/world_writable_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "FileTest.world_writable?" do
it "needs to be reviewed for spec completeness"
diff --git a/spec/ruby/core/filetest/writable_real_spec.rb b/spec/ruby/core/filetest/writable_real_spec.rb
index 83194f8173..64abe4cd3f 100644
--- a/spec/ruby/core/filetest/writable_real_spec.rb
+++ b/spec/ruby/core/filetest/writable_real_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/file/writable_real', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../../shared/file/writable_real'
describe "FileTest.writable_real?" do
it_behaves_like :file_writable_real, :writable_real?, FileTest
diff --git a/spec/ruby/core/filetest/writable_spec.rb b/spec/ruby/core/filetest/writable_spec.rb
index 9064f1b16d..e921a5887b 100644
--- a/spec/ruby/core/filetest/writable_spec.rb
+++ b/spec/ruby/core/filetest/writable_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/file/writable', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../../shared/file/writable'
describe "FileTest.writable?" do
it_behaves_like :file_writable, :writable?, FileTest
diff --git a/spec/ruby/core/filetest/zero_spec.rb b/spec/ruby/core/filetest/zero_spec.rb
index 46b1842d55..de024c25ff 100644
--- a/spec/ruby/core/filetest/zero_spec.rb
+++ b/spec/ruby/core/filetest/zero_spec.rb
@@ -1,13 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/file/zero', __FILE__)
+require_relative '../../spec_helper'
describe "FileTest.zero?" do
- it_behaves_like :file_zero, :zero?, FileTest
- it_behaves_like :file_zero_missing, :zero?, FileTest
-
- platform_is :solaris do
- it "returns false for /dev/null" do
- File.zero?('/dev/null').should == true
- end
+ it "is an alias of FileTest.empty?" do
+ FileTest.method(:zero?).should == FileTest.method(:empty?)
end
end
diff --git a/spec/ruby/core/fixnum/abs_spec.rb b/spec/ruby/core/fixnum/abs_spec.rb
deleted file mode 100644
index 5e6a7de891..0000000000
--- a/spec/ruby/core/fixnum/abs_spec.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/abs', __FILE__)
-
-describe "Fixnum#abs" do
- it_behaves_like :fixnum_abs, :abs
-end
-
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/case_compare_spec.rb b/spec/ruby/core/fixnum/case_compare_spec.rb
deleted file mode 100644
index 53bfc38eb8..0000000000
--- a/spec/ruby/core/fixnum/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 "Fixnum#===" do
- it_behaves_like :fixnum_equal, :===
-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/equal_value_spec.rb b/spec/ruby/core/fixnum/equal_value_spec.rb
deleted file mode 100644
index 3a9ef93d24..0000000000
--- a/spec/ruby/core/fixnum/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 "Fixnum#==" do
- it_behaves_like :fixnum_equal, :==
-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/fdiv_spec.rb b/spec/ruby/core/fixnum/fdiv_spec.rb
deleted file mode 100644
index bb5f09c333..0000000000
--- a/spec/ruby/core/fixnum/fdiv_spec.rb
+++ /dev/null
@@ -1,49 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Fixnum#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
- 8.fdiv(bignum_value).should be_close(8.673617379884035e-19, TOLERANCE)
- end
-
- it "performs floating-point division between self and a Float" do
- 8.fdiv(9.0).should be_close(0.888888888888889, TOLERANCE)
- end
-
- it "returns NaN when the argument is NaN" do
- -1.fdiv(nan_value).nan?.should be_true
- 1.fdiv(nan_value).nan?.should be_true
- end
-
- it "returns Infinity when the argument is 0" do
- 1.fdiv(0).infinite?.should == 1
- end
-
- it "returns -Infinity when the argument is 0 and self is negative" do
- -1.fdiv(0).infinite?.should == -1
- end
-
- it "returns Infinity when the argument is 0.0" do
- 1.fdiv(0.0).infinite?.should == 1
- end
-
- it "returns -Infinity when the argument is 0.0 and self is negative" do
- -1.fdiv(0.0).infinite?.should == -1
- end
-
- it "raises a TypeError when argument isn't numeric" do
- lambda { 1.fdiv(mock('non-numeric')) }.should raise_error(TypeError)
- end
-
- it "raises an ArgumentError when passed multiple arguments" do
- lambda { 1.fdiv(6,0.2) }.should raise_error(ArgumentError)
- end
-
- it "follows the coercion protocol" do
- (obj = mock('10')).should_receive(:coerce).with(1).and_return([1, 10])
- 1.fdiv(obj).should == 0.1
- 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..a08601926d 100644
--- a/spec/ruby/core/float/abs_spec.rb
+++ b/spec/ruby/core/float/abs_spec.rb
@@ -1,5 +1,6 @@
-require File.expand_path('../shared/abs', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/abs'
describe "Float#abs" do
- it_behaves_like(:float_abs, :abs)
+ it_behaves_like :float_abs, :abs
end
diff --git a/spec/ruby/core/float/angle_spec.rb b/spec/ruby/core/float/angle_spec.rb
index 2a5d40ad30..ac182c5b73 100644
--- a/spec/ruby/core/float/angle_spec.rb
+++ b/spec/ruby/core/float/angle_spec.rb
@@ -1,5 +1,7 @@
-require File.expand_path('../../../shared/complex/float/arg', __FILE__)
+require_relative '../../spec_helper'
describe "Float#angle" do
- it_behaves_like :float_arg, :angle
+ it "is an alias of Float#arg" do
+ Float.instance_method(:angle).should == Float.instance_method(:arg)
+ end
end
diff --git a/spec/ruby/core/float/arg_spec.rb b/spec/ruby/core/float/arg_spec.rb
index 20a8ac0a63..c9c602bbf6 100644
--- a/spec/ruby/core/float/arg_spec.rb
+++ b/spec/ruby/core/float/arg_spec.rb
@@ -1,5 +1,38 @@
-require File.expand_path('../../../shared/complex/float/arg', __FILE__)
+require_relative '../../spec_helper'
describe "Float#arg" do
- it_behaves_like :float_arg, :arg
+ it "returns NaN if NaN" do
+ f = nan_value
+ f.arg.nan?.should == true
+ end
+
+ it "returns self if NaN" do
+ f = nan_value
+ f.arg.should.equal?(f)
+ end
+
+ it "returns 0 if positive" do
+ 1.0.arg.should == 0
+ end
+
+ it "returns 0 if +0.0" do
+ 0.0.arg.should == 0
+ end
+
+ it "returns 0 if +Infinity" do
+ infinity_value.arg.should == 0
+ end
+
+ it "returns Pi if negative" do
+ (-1.0).arg.should == Math::PI
+ end
+
+ # This was established in r23960
+ it "returns Pi if -0.0" do
+ (-0.0).arg.should == Math::PI
+ end
+
+ it "returns Pi if -Infinity" do
+ (-infinity_value).arg.should == Math::PI
+ end
end
diff --git a/spec/ruby/core/float/case_compare_spec.rb b/spec/ruby/core/float/case_compare_spec.rb
index c2ad2941e0..c82803642d 100644
--- a/spec/ruby/core/float/case_compare_spec.rb
+++ b/spec/ruby/core/float/case_compare_spec.rb
@@ -1,6 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/equal', __FILE__)
+require_relative '../../spec_helper'
describe "Float#===" do
- it_behaves_like :float_equal, :===
+ it "is an alias of Float#==" do
+ Float.instance_method(:===).should == Float.instance_method(:==)
+ end
end
diff --git a/spec/ruby/core/float/ceil_spec.rb b/spec/ruby/core/float/ceil_spec.rb
index f1d9dcd823..efd1e6feb2 100644
--- a/spec/ruby/core/float/ceil_spec.rb
+++ b/spec/ruby/core/float/ceil_spec.rb
@@ -1,23 +1,28 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../integer/shared/integer_ceil_precision'
describe "Float#ceil" do
+ context "with values equal to integers" do
+ it_behaves_like :integer_ceil_precision, :Float
+ end
+
it "returns the smallest Integer greater than or equal to self" do
- -1.2.ceil.should eql( -1)
- -1.0.ceil.should eql( -1)
- 0.0.ceil.should eql( 0 )
- 1.3.ceil.should eql( 2 )
- 3.0.ceil.should eql( 3 )
- -9223372036854775808.1.ceil.should eql(-9223372036854775808)
- +9223372036854775808.1.ceil.should eql(+9223372036854775808)
+ -1.2.ceil.should.eql?( -1)
+ -1.0.ceil.should.eql?( -1)
+ 0.0.ceil.should.eql?( 0 )
+ 1.3.ceil.should.eql?( 2 )
+ 3.0.ceil.should.eql?( 3 )
+ -9223372036854775808.1.ceil.should.eql?(-9223372036854775808)
+ +9223372036854775808.1.ceil.should.eql?(+9223372036854775808)
end
- ruby_version_is "2.4" do
- it "returns the smallest number greater than or equal to self with an optionally given precision" do
- 2.1679.ceil(0).should eql(3)
- 214.94.ceil(-1).should eql(220)
- 7.0.ceil(1).should eql(7.0)
- -1.234.ceil(2).should eql(-1.23)
- 5.123812.ceil(4).should eql(5.1239)
- end
+ it "returns the smallest number greater than or equal to self with an optionally given precision" do
+ 2.1679.ceil(0).should.eql?(3)
+ 214.94.ceil(-1).should.eql?(220)
+ 7.0.ceil(1).should.eql?(7.0)
+ 200.0.ceil(-2).should.eql?(200)
+ -1.234.ceil(2).should.eql?(-1.23)
+ 5.123812.ceil(4).should.eql?(5.1239)
+ 10.00001.ceil(5).should.eql?(10.00001)
end
end
diff --git a/spec/ruby/core/float/coerce_spec.rb b/spec/ruby/core/float/coerce_spec.rb
index 90475f2680..baa831dcf6 100644
--- a/spec/ruby/core/float/coerce_spec.rb
+++ b/spec/ruby/core/float/coerce_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Float#coerce" do
it "returns [other, self] both as Floats" do
@@ -9,10 +9,10 @@ describe "Float#coerce" do
1.0.coerce(3.14).should == [3.14, 1.0]
a, b = -0.0.coerce(bignum_value)
- a.should be_close(9223372036854775808.0, TOLERANCE)
+ a.should be_close(18446744073709551616.0, TOLERANCE)
b.should be_close(-0.0, TOLERANCE)
a, b = 1.0.coerce(bignum_value)
- a.should be_close(9223372036854775808.0, TOLERANCE)
+ a.should be_close(18446744073709551616.0, TOLERANCE)
b.should be_close(1.0, TOLERANCE)
end
end
diff --git a/spec/ruby/core/float/comparison_spec.rb b/spec/ruby/core/float/comparison_spec.rb
index 49c3debbe1..e9adf2fd6a 100644
--- a/spec/ruby/core/float/comparison_spec.rb
+++ b/spec/ruby/core/float/comparison_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Float#<=>" do
it "returns -1, 0, 1 when self is less than, equal, or greater than other" do
@@ -7,30 +7,107 @@ describe "Float#<=>" do
((bignum_value*1.1) <=> bignum_value).should == 1
end
- it "returns nil when either argument is NaN" do
- (nan_value <=> 71.2).should be_nil
- (1771.176 <=> nan_value).should be_nil
+ it "returns nil if one side is NaN" do
+ [1.0, 42, bignum_value].each { |n|
+ (nan_value <=> n).should == nil
+ (n <=> nan_value).should == nil
+ }
+ end
+
+ it "handles positive infinity" do
+ [1.0, 42, bignum_value].each { |n|
+ (infinity_value <=> n).should == 1
+ (n <=> infinity_value).should == -1
+ }
+ end
+
+ it "handles negative infinity" do
+ [1.0, 42, bignum_value].each { |n|
+ (-infinity_value <=> n).should == -1
+ (n <=> -infinity_value).should == 1
+ }
end
it "returns nil when the given argument is not a Float" do
- (1.0 <=> "1").should be_nil
+ (1.0 <=> "1").should == nil
+ (1.0 <=> "1".freeze).should == nil
+ (1.0 <=> :one).should == nil
+ (1.0 <=> true).should == nil
end
- # The 4 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
+ it "compares using #coerce when argument is not a Float" do
+ klass = Class.new do
+ attr_reader :call_count
+ def coerce(other)
+ @call_count ||= 0
+ @call_count += 1
+ [other, 42.0]
+ end
+ end
+
+ coercible = klass.new
+ (2.33 <=> coercible).should == -1
+ (42.0 <=> coercible).should == 0
+ (43.0 <=> coercible).should == 1
+ coercible.call_count.should == 3
end
- it "returns -1 when self is negative and other is Infinty" do
- (-Float::MAX.to_i*2 <=> infinity_value).should == -1
+ it "raises TypeError when #coerce misbehaves" do
+ klass = Class.new do
+ def coerce(other)
+ :incorrect
+ end
+ end
+
+ bad_coercible = klass.new
+ -> {
+ 4.2 <=> bad_coercible
+ }.should.raise(TypeError, "coerce must return [x, y]")
end
- it "returns -1 when self is -Infinity and other is negative" do
+ it "returns the correct result when one side is infinite" do
+ (infinity_value <=> Float::MAX.to_i*2).should == 1
+ (-Float::MAX.to_i*2 <=> infinity_value).should == -1
(-infinity_value <=> -Float::MAX.to_i*2).should == -1
+ (-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
+ it "returns 0 when self is Infinity and other is infinite?=1" do
+ obj = Object.new
+ def obj.infinite?
+ 1
+ end
+ (infinity_value <=> obj).should == 0
+ end
+
+ it "returns 1 when self is Infinity and other is infinite?=-1" do
+ obj = Object.new
+ def obj.infinite?
+ -1
+ end
+ (infinity_value <=> obj).should == 1
+ end
+
+ it "returns 1 when self is Infinity and other is infinite?=nil (which means finite)" do
+ obj = Object.new
+ def obj.infinite?
+ nil
+ end
+ (infinity_value <=> obj).should == 1
+ end
+
+ it "returns 0 for -0.0 and 0.0" do
+ (-0.0 <=> 0.0).should == 0
+ (0.0 <=> -0.0).should == 0
+ end
+
+ it "returns 0 for -0.0 and 0" do
+ (-0.0 <=> 0).should == 0
+ (0 <=> -0.0).should == 0
+ end
+
+ it "returns 0 for 0.0 and 0" do
+ (0.0 <=> 0).should == 0
+ (0 <=> 0.0).should == 0
end
end
diff --git a/spec/ruby/core/float/constants_spec.rb b/spec/ruby/core/float/constants_spec.rb
index 31930b125a..1b71ee8adf 100644
--- a/spec/ruby/core/float/constants_spec.rb
+++ b/spec/ruby/core/float/constants_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Float constant" do
it "DIG is 15" do
@@ -50,6 +50,6 @@ describe "Float constant" do
end
it "NAN is 'not a number'" do
- Float::NAN.nan?.should be_true
+ Float::NAN.nan?.should == true
end
end
diff --git a/spec/ruby/core/float/denominator_spec.rb b/spec/ruby/core/float/denominator_spec.rb
index 56f5d288cf..85beaa98cd 100644
--- a/spec/ruby/core/float/denominator_spec.rb
+++ b/spec/ruby/core/float/denominator_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Float#denominator" do
before :each do
@@ -12,7 +12,7 @@ describe "Float#denominator" do
it "returns an Integer" do
@numbers.each do |number|
- number.denominator.should be_kind_of(Integer)
+ number.denominator.should.is_a?(Integer)
end
end
diff --git a/spec/ruby/core/float/divide_spec.rb b/spec/ruby/core/float/divide_spec.rb
index 0acd7b20b4..68a2c550a7 100644
--- a/spec/ruby/core/float/divide_spec.rb
+++ b/spec/ruby/core/float/divide_spec.rb
@@ -1,7 +1,10 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/coerce.rb', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/coerce'
+require_relative 'shared/arithmetic_exception_in_coerce'
describe "Float#/" do
+ it_behaves_like :float_arithmetic_exception_in_coerce, :/
+
it "returns self divided by other" do
(5.75 / -2).should be_close(-2.875,TOLERANCE)
(451.0 / 9.3).should be_close(48.494623655914,TOLERANCE)
@@ -13,24 +16,28 @@ describe "Float#/" do
end
it "returns +Infinity when dividing non-zero by zero of the same sign" do
- (1.0 / 0.0).should be_positive_infinity
- (-1.0 / -0.0).should be_positive_infinity
+ (1.0 / 0.0).should.infinite? == 1
+ (-1.0 / -0.0).should.infinite? == 1
end
it "returns -Infinity when dividing non-zero by zero of opposite sign" do
- (-1.0 / 0.0).should be_negative_infinity
- (1.0 / -0.0).should be_negative_infinity
+ (-1.0 / 0.0).should.infinite? == -1
+ (1.0 / -0.0).should.infinite? == -1
end
it "returns NaN when dividing zero by zero" do
- (0.0 / 0.0).should be_nan
- (-0.0 / 0.0).should be_nan
- (0.0 / -0.0).should be_nan
- (-0.0 / -0.0).should be_nan
+ (0.0 / 0.0).should.nan?
+ (-0.0 / 0.0).should.nan?
+ (0.0 / -0.0).should.nan?
+ (-0.0 / -0.0).should.nan?
end
it "raises a TypeError when given a non-Numeric" do
- lambda { 13.0 / "10" }.should raise_error(TypeError)
- lambda { 13.0 / :symbol }.should raise_error(TypeError)
+ -> { 13.0 / "10" }.should.raise(TypeError)
+ -> { 13.0 / :symbol }.should.raise(TypeError)
+ end
+
+ it "divides correctly by Rational numbers" do
+ (1.2345678901234567 / Rational(1, 10000000000000000000)).should == 1.2345678901234567e+19
end
end
diff --git a/spec/ruby/core/float/divmod_spec.rb b/spec/ruby/core/float/divmod_spec.rb
index 174f142c86..7ed6cd3487 100644
--- a/spec/ruby/core/float/divmod_spec.rb
+++ b/spec/ruby/core/float/divmod_spec.rb
@@ -1,43 +1,43 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Float#divmod" do
it "returns an [quotient, modulus] from dividing self by other" do
values = 3.14.divmod(2)
- values[0].should eql(1)
+ values[0].should.eql?(1)
values[1].should be_close(1.14, TOLERANCE)
values = 2.8284.divmod(3.1415)
- values[0].should eql(0)
+ values[0].should.eql?(0)
values[1].should be_close(2.8284, TOLERANCE)
values = -1.0.divmod(bignum_value)
- values[0].should eql(-1)
- values[1].should be_close(9223372036854775808.000, TOLERANCE)
+ values[0].should.eql?(-1)
+ values[1].should be_close(18446744073709551616.0, TOLERANCE)
values = -1.0.divmod(1)
- values[0].should eql(-1)
- values[1].should eql(0.0)
+ values[0].should.eql?(-1)
+ values[1].should.eql?(0.0)
end
# Behaviour established as correct in r23953
it "raises a FloatDomainError if self is NaN" do
- lambda { nan_value.divmod(1) }.should raise_error(FloatDomainError)
+ -> { nan_value.divmod(1) }.should.raise(FloatDomainError)
end
# Behaviour established as correct in r23953
it "raises a FloatDomainError if other is NaN" do
- lambda { 1.divmod(nan_value) }.should raise_error(FloatDomainError)
+ -> { 1.0.divmod(nan_value) }.should.raise(FloatDomainError)
end
# Behaviour established as correct in r23953
it "raises a FloatDomainError if self is Infinity" do
- lambda { infinity_value.divmod(1) }.should raise_error(FloatDomainError)
+ -> { infinity_value.divmod(1) }.should.raise(FloatDomainError)
end
it "raises a ZeroDivisionError if other is zero" do
- lambda { 1.0.divmod(0) }.should raise_error(ZeroDivisionError)
- lambda { 1.0.divmod(0.0) }.should raise_error(ZeroDivisionError)
+ -> { 1.0.divmod(0) }.should.raise(ZeroDivisionError)
+ -> { 1.0.divmod(0.0) }.should.raise(ZeroDivisionError)
end
# redmine #5276"
it "returns the correct [quotient, modulus] even for large quotient" do
- 0.59.divmod(7.761021455128987e-11).first.should eql(7602092113)
+ 0.59.divmod(7.761021455128987e-11).first.should.eql?(7602092113)
end
end
diff --git a/spec/ruby/core/float/dup_spec.rb b/spec/ruby/core/float/dup_spec.rb
index 775dc2913c..b474e21325 100644
--- a/spec/ruby/core/float/dup_spec.rb
+++ b/spec/ruby/core/float/dup_spec.rb
@@ -1,10 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
-ruby_version_is '2.4' do
- describe "Float#dup" do
- it "returns self" do
- float = 2.4
- float.dup.should equal(float)
- end
+describe "Float#dup" do
+ it "returns self" do
+ float = 2.4
+ float.dup.should.equal?(float)
end
end
diff --git a/spec/ruby/core/float/eql_spec.rb b/spec/ruby/core/float/eql_spec.rb
index 7c4eef8523..cf1ad8416f 100644
--- a/spec/ruby/core/float/eql_spec.rb
+++ b/spec/ruby/core/float/eql_spec.rb
@@ -1,16 +1,16 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Float#eql?" do
it "returns true if other is a Float equal to self" do
- 0.0.eql?(0.0).should be_true
+ 0.0.eql?(0.0).should == true
end
it "returns false if other is a Float not equal to self" do
- 1.0.eql?(1.1).should be_false
+ 1.0.eql?(1.1).should == false
end
it "returns false if other is not a Float" do
- 1.0.eql?(1).should be_false
- 1.0.eql?(:one).should be_false
+ 1.0.eql?(1).should == false
+ 1.0.eql?(:one).should == false
end
end
diff --git a/spec/ruby/core/float/equal_value_spec.rb b/spec/ruby/core/float/equal_value_spec.rb
index 19ef01fc1c..37d0e162d3 100644
--- a/spec/ruby/core/float/equal_value_spec.rb
+++ b/spec/ruby/core/float/equal_value_spec.rb
@@ -1,6 +1,40 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/equal', __FILE__)
+require_relative '../../spec_helper'
describe "Float#==" do
- it_behaves_like :float_equal, :==
+ it "returns true if self has the same value as other" do
+ (1.0 == 1).should == true
+ (2.71828 == 1.428).should == false
+ (-4.2 == 4.2).should == false
+ end
+
+ it "calls 'other == self' if coercion fails" do
+ x = mock('other')
+ def x.==(other)
+ 2.0 == other
+ end
+
+ (1.0 == x).should == false
+ (2.0 == x).should == true
+ end
+
+ it "returns false if one side is NaN" do
+ [1.0, 42, bignum_value].each { |n|
+ (nan_value == n).should == false
+ (n == nan_value).should == false
+ }
+ end
+
+ it "handles positive infinity" do
+ [1.0, 42, bignum_value].each { |n|
+ (infinity_value == n).should == false
+ (n == infinity_value).should == false
+ }
+ end
+
+ it "handles negative infinity" do
+ [1.0, 42, bignum_value].each { |n|
+ ((-infinity_value) == n).should == false
+ (n == -infinity_value).should == false
+ }
+ end
end
diff --git a/spec/ruby/core/float/exponent_spec.rb b/spec/ruby/core/float/exponent_spec.rb
index 5cbba43a27..a4c03469a7 100644
--- a/spec/ruby/core/float/exponent_spec.rb
+++ b/spec/ruby/core/float/exponent_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Float#**" do
it "returns self raise to the other power" do
diff --git a/spec/ruby/core/float/fdiv_spec.rb b/spec/ruby/core/float/fdiv_spec.rb
index 632dd0f293..8a3ead4880 100644
--- a/spec/ruby/core/float/fdiv_spec.rb
+++ b/spec/ruby/core/float/fdiv_spec.rb
@@ -1,6 +1,61 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/quo', __FILE__)
+require_relative '../../spec_helper'
describe "Float#fdiv" do
- it_behaves_like :float_quo, :fdiv
+ it "performs floating-point division between self and an Integer" do
+ 8.9.fdiv(7).should == 1.2714285714285716
+ end
+
+ it "performs floating-point division between self and an Integer" do
+ 8.9.fdiv(9999999999999**9).should == 8.900000000008011e-117
+ end
+
+ it "performs floating-point division between self and a Float" do
+ 2827.22.fdiv(872.111111).should == 3.2418116961704433
+ end
+
+ it "returns NaN when the argument is NaN" do
+ -1819.999999.fdiv(nan_value).nan?.should == true
+ 11109.1981271.fdiv(nan_value).nan?.should == true
+ end
+
+ it "returns Infinity when the argument is 0.0" do
+ 2827.22.fdiv(0.0).infinite?.should == 1
+ end
+
+ it "returns -Infinity when the argument is 0.0 and self is negative" do
+ -48229.282.fdiv(0.0).infinite?.should == -1
+ end
+
+ it "returns Infinity when the argument is 0" do
+ 2827.22.fdiv(0).infinite?.should == 1
+ end
+
+ it "returns -Infinity when the argument is 0 and self is negative" do
+ -48229.282.fdiv(0).infinite?.should == -1
+ end
+
+ it "returns 0.0 when the argument is Infinity" do
+ 47292.2821.fdiv(infinity_value).should == 0.0
+ end
+
+ it "returns -0.0 when the argument is -Infinity" do
+ 1.9999918.fdiv(-infinity_value).should == -0.0
+ end
+
+ it "performs floating-point division between self and a Rational" do
+ 74620.09.fdiv(Rational(2,3)).should == 111930.135
+ end
+
+ it "performs floating-point division between self and a Complex" do
+ 74620.09.fdiv(Complex(8,2)).should == Complex(
+ 8778.834117647059, -2194.7085294117646)
+ end
+
+ it "raises a TypeError when argument isn't numeric" do
+ -> { 27292.2.fdiv(mock('non-numeric')) }.should.raise(TypeError)
+ end
+
+ it "raises an ArgumentError when passed multiple arguments" do
+ -> { 272.221.fdiv(6,0.2) }.should.raise(ArgumentError)
+ end
end
diff --git a/spec/ruby/core/float/finite_spec.rb b/spec/ruby/core/float/finite_spec.rb
index d6a161d4e3..d839b30e32 100644
--- a/spec/ruby/core/float/finite_spec.rb
+++ b/spec/ruby/core/float/finite_spec.rb
@@ -1,19 +1,19 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Float#finite?" do
it "returns true for finite values" do
- 3.14159.finite?.should == true
+ 3.14159.should.finite?
end
it "returns false for positive infinity" do
- infinity_value.finite?.should == false
+ infinity_value.should_not.finite?
end
it "returns false for negative infinity" do
- (-infinity_value).finite?.should == false
+ (-infinity_value).should_not.finite?
end
it "returns false for NaN" do
- nan_value.finite?.should == false
+ nan_value.should_not.finite?
end
end
diff --git a/spec/ruby/core/float/fixtures/classes.rb b/spec/ruby/core/float/fixtures/classes.rb
new file mode 100644
index 0000000000..2d80184e7d
--- /dev/null
+++ b/spec/ruby/core/float/fixtures/classes.rb
@@ -0,0 +1,4 @@
+module FloatSpecs
+ class CoerceError < StandardError
+ end
+end
diff --git a/spec/ruby/core/float/float_spec.rb b/spec/ruby/core/float/float_spec.rb
index f2931d184c..46b2eff372 100644
--- a/spec/ruby/core/float/float_spec.rb
+++ b/spec/ruby/core/float/float_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Float" do
it "includes Comparable" do
@@ -6,14 +6,14 @@ describe "Float" do
end
it ".allocate raises a TypeError" do
- lambda do
+ -> do
Float.allocate
- end.should raise_error(TypeError)
+ end.should.raise(TypeError)
end
it ".new is undefined" do
- lambda do
+ -> do
Float.new
- end.should raise_error(NoMethodError)
+ end.should.raise(NoMethodError)
end
end
diff --git a/spec/ruby/core/float/floor_spec.rb b/spec/ruby/core/float/floor_spec.rb
index 6da5d5c5ee..f77300eb04 100644
--- a/spec/ruby/core/float/floor_spec.rb
+++ b/spec/ruby/core/float/floor_spec.rb
@@ -1,23 +1,28 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../integer/shared/integer_floor_precision'
describe "Float#floor" do
+ context "with values equal to integers" do
+ it_behaves_like :integer_floor_precision, :Float
+ end
+
it "returns the largest Integer less than or equal to self" do
- -1.2.floor.should eql( -2)
- -1.0.floor.should eql( -1)
- 0.0.floor.should eql( 0 )
- 1.0.floor.should eql( 1 )
- 5.9.floor.should eql( 5 )
- -9223372036854775808.1.floor.should eql(-9223372036854775808)
- +9223372036854775808.1.floor.should eql(+9223372036854775808)
+ -1.2.floor.should.eql?( -2)
+ -1.0.floor.should.eql?( -1)
+ 0.0.floor.should.eql?( 0 )
+ 1.0.floor.should.eql?( 1 )
+ 5.9.floor.should.eql?( 5 )
+ -9223372036854775808.1.floor.should.eql?(-9223372036854775808)
+ +9223372036854775808.1.floor.should.eql?(+9223372036854775808)
end
- ruby_version_is "2.4" do
- it "returns the largest number less than or equal to self with an optionally given precision" do
- 2.1679.floor(0).should eql(2)
- 214.94.floor(-1).should eql(210)
- 7.0.floor(1).should eql(7.0)
- -1.234.floor(2).should eql(-1.24)
- 5.123812.floor(4).should eql(5.1238)
- end
+ it "returns the largest number less than or equal to self with an optionally given precision" do
+ 2.1679.floor(0).should.eql?(2)
+ 214.94.floor(-1).should.eql?(210)
+ 7.0.floor(1).should.eql?(7.0)
+ 200.0.floor(-2).should.eql?(200)
+ -1.234.floor(2).should.eql?(-1.24)
+ 5.123812.floor(4).should.eql?(5.1238)
+ 10.00001.floor(5).should.eql?(10.00001)
end
end
diff --git a/spec/ruby/core/float/gt_spec.rb b/spec/ruby/core/float/gt_spec.rb
index 9725c6acd7..5194796b46 100644
--- a/spec/ruby/core/float/gt_spec.rb
+++ b/spec/ruby/core/float/gt_spec.rb
@@ -1,6 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/comparison_exception_in_coerce'
describe "Float#>" do
+ it_behaves_like :float_comparison_exception_in_coerce, :>
+
it "returns true if self is greater than other" do
(1.5 > 1).should == true
(2.5 > 3).should == false
@@ -8,7 +11,28 @@ describe "Float#>" do
end
it "raises an ArgumentError when given a non-Numeric" do
- lambda { 5.0 > "4" }.should raise_error(ArgumentError)
- lambda { 5.0 > mock('x') }.should raise_error(ArgumentError)
+ -> { 5.0 > "4" }.should.raise(ArgumentError)
+ -> { 5.0 > mock('x') }.should.raise(ArgumentError)
+ end
+
+ it "returns false if one side is NaN" do
+ [1.0, 42, bignum_value].each { |n|
+ (nan_value > n).should == false
+ (n > nan_value).should == false
+ }
+ end
+
+ it "handles positive infinity" do
+ [1.0, 42, bignum_value].each { |n|
+ (infinity_value > n).should == true
+ (n > infinity_value).should == false
+ }
+ end
+
+ it "handles negative infinity" do
+ [1.0, 42, bignum_value].each { |n|
+ (-infinity_value > n).should == false
+ (n > -infinity_value).should == true
+ }
end
end
diff --git a/spec/ruby/core/float/gte_spec.rb b/spec/ruby/core/float/gte_spec.rb
index 2c14651dd7..4a62725d53 100644
--- a/spec/ruby/core/float/gte_spec.rb
+++ b/spec/ruby/core/float/gte_spec.rb
@@ -1,6 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/comparison_exception_in_coerce'
describe "Float#>=" do
+ it_behaves_like :float_comparison_exception_in_coerce, :>=
+
it "returns true if self is greater than or equal to other" do
(5.2 >= 5.2).should == true
(9.71 >= 1).should == true
@@ -8,7 +11,28 @@ describe "Float#>=" do
end
it "raises an ArgumentError when given a non-Numeric" do
- lambda { 5.0 >= "4" }.should raise_error(ArgumentError)
- lambda { 5.0 >= mock('x') }.should raise_error(ArgumentError)
+ -> { 5.0 >= "4" }.should.raise(ArgumentError)
+ -> { 5.0 >= mock('x') }.should.raise(ArgumentError)
+ end
+
+ it "returns false if one side is NaN" do
+ [1.0, 42, bignum_value].each { |n|
+ (nan_value >= n).should == false
+ (n >= nan_value).should == false
+ }
+ end
+
+ it "handles positive infinity" do
+ [1.0, 42, bignum_value].each { |n|
+ (infinity_value >= n).should == true
+ (n >= infinity_value).should == false
+ }
+ end
+
+ it "handles negative infinity" do
+ [1.0, 42, bignum_value].each { |n|
+ (-infinity_value >= n).should == false
+ (n >= -infinity_value).should == true
+ }
end
end
diff --git a/spec/ruby/core/float/hash_spec.rb b/spec/ruby/core/float/hash_spec.rb
index c638e99347..5f77e3b4a1 100644
--- a/spec/ruby/core/float/hash_spec.rb
+++ b/spec/ruby/core/float/hash_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Float#hash" do
it "is provided" do
diff --git a/spec/ruby/core/float/infinite_spec.rb b/spec/ruby/core/float/infinite_spec.rb
index 4e31effab7..901c2738aa 100644
--- a/spec/ruby/core/float/infinite_spec.rb
+++ b/spec/ruby/core/float/infinite_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Float#infinite?" do
it "returns nil for finite values" do
diff --git a/spec/ruby/core/float/inspect_spec.rb b/spec/ruby/core/float/inspect_spec.rb
new file mode 100644
index 0000000000..3827167c17
--- /dev/null
+++ b/spec/ruby/core/float/inspect_spec.rb
@@ -0,0 +1,7 @@
+require_relative '../../spec_helper'
+
+describe "Float#inspect" do
+ it "is an alias of Float#to_s" do
+ Float.instance_method(:inspect).should == Float.instance_method(:to_s)
+ end
+end
diff --git a/spec/ruby/core/float/lt_spec.rb b/spec/ruby/core/float/lt_spec.rb
index e2e43b0fb7..0f0e1752bd 100644
--- a/spec/ruby/core/float/lt_spec.rb
+++ b/spec/ruby/core/float/lt_spec.rb
@@ -1,6 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/comparison_exception_in_coerce'
describe "Float#<" do
+ it_behaves_like :float_comparison_exception_in_coerce, :<
+
it "returns true if self is less than other" do
(71.3 < 91.8).should == true
(192.6 < -500).should == false
@@ -8,7 +11,28 @@ describe "Float#<" do
end
it "raises an ArgumentError when given a non-Numeric" do
- lambda { 5.0 < "4" }.should raise_error(ArgumentError)
- lambda { 5.0 < mock('x') }.should raise_error(ArgumentError)
+ -> { 5.0 < "4" }.should.raise(ArgumentError)
+ -> { 5.0 < mock('x') }.should.raise(ArgumentError)
+ end
+
+ it "returns false if one side is NaN" do
+ [1.0, 42, bignum_value].each { |n|
+ (nan_value < n).should == false
+ (n < nan_value).should == false
+ }
+ end
+
+ it "handles positive infinity" do
+ [1.0, 42, bignum_value].each { |n|
+ (infinity_value < n).should == false
+ (n < infinity_value).should == true
+ }
+ end
+
+ it "handles negative infinity" do
+ [1.0, 42, bignum_value].each { |n|
+ (-infinity_value < n).should == true
+ (n < -infinity_value).should == false
+ }
end
end
diff --git a/spec/ruby/core/float/lte_spec.rb b/spec/ruby/core/float/lte_spec.rb
index e2e44b2257..afb64ade09 100644
--- a/spec/ruby/core/float/lte_spec.rb
+++ b/spec/ruby/core/float/lte_spec.rb
@@ -1,6 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/comparison_exception_in_coerce'
describe "Float#<=" do
+ it_behaves_like :float_comparison_exception_in_coerce, :>=
+
it "returns true if self is less than or equal to other" do
(2.0 <= 3.14159).should == true
(-2.7183 <= -24).should == false
@@ -9,7 +12,28 @@ describe "Float#<=" do
end
it "raises an ArgumentError when given a non-Numeric" do
- lambda { 5.0 <= "4" }.should raise_error(ArgumentError)
- lambda { 5.0 <= mock('x') }.should raise_error(ArgumentError)
+ -> { 5.0 <= "4" }.should.raise(ArgumentError)
+ -> { 5.0 <= mock('x') }.should.raise(ArgumentError)
+ end
+
+ it "returns false if one side is NaN" do
+ [1.0, 42, bignum_value].each { |n|
+ (nan_value <= n).should == false
+ (n <= nan_value).should == false
+ }
+ end
+
+ it "handles positive infinity" do
+ [1.0, 42, bignum_value].each { |n|
+ (infinity_value <= n).should == false
+ (n <= infinity_value).should == true
+ }
+ end
+
+ it "handles negative infinity" do
+ [1.0, 42, bignum_value].each { |n|
+ (-infinity_value <= n).should == true
+ (n <= -infinity_value).should == false
+ }
end
end
diff --git a/spec/ruby/core/float/magnitude_spec.rb b/spec/ruby/core/float/magnitude_spec.rb
index 042356f4c4..4a753267e0 100644
--- a/spec/ruby/core/float/magnitude_spec.rb
+++ b/spec/ruby/core/float/magnitude_spec.rb
@@ -1,5 +1,14 @@
-require File.expand_path('../shared/abs', __FILE__)
+require_relative "../../spec_helper"
+require_relative 'shared/abs'
describe "Float#magnitude" do
- it_behaves_like(:float_abs, :magnitude)
+ ruby_version_is ""..."3.4" do
+ it_behaves_like :float_abs, :magnitude
+ end
+
+ ruby_version_is "3.4" do
+ it "is an alias of Float#abs" do
+ Float.instance_method(:magnitude).should == Float.instance_method(:abs)
+ end
+ end
end
diff --git a/spec/ruby/core/float/minus_spec.rb b/spec/ruby/core/float/minus_spec.rb
index d5c0d863ed..a4281a397b 100644
--- a/spec/ruby/core/float/minus_spec.rb
+++ b/spec/ruby/core/float/minus_spec.rb
@@ -1,9 +1,12 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/arithmetic_exception_in_coerce'
describe "Float#-" do
+ it_behaves_like :float_arithmetic_exception_in_coerce, :-
+
it "returns self minus other" do
(9_237_212.5280 - 5_280).should be_close(9231932.528, TOLERANCE)
- (2_560_496.1691 - bignum_value).should be_close(-9223372036852215808.000, TOLERANCE)
+ (2_560_496.1691 - bignum_value).should be_close(-18446744073706991616.0, TOLERANCE)
(5.5 - 5.5).should be_close(0.0,TOLERANCE)
end
end
diff --git a/spec/ruby/core/float/modulo_spec.rb b/spec/ruby/core/float/modulo_spec.rb
index f29e3870da..8b7aedf822 100644
--- a/spec/ruby/core/float/modulo_spec.rb
+++ b/spec/ruby/core/float/modulo_spec.rb
@@ -1,10 +1,56 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/modulo', __FILE__)
+require_relative '../../spec_helper'
describe "Float#%" do
- it_behaves_like(:float_modulo, :%)
+ it "returns self modulo other" do
+ (6543.21 % 137).should be_close(104.21, TOLERANCE)
+ (5667.19 % bignum_value).should be_close(5667.19, TOLERANCE)
+ (6543.21 % 137.24).should be_close(92.9299999999996, TOLERANCE)
+
+ (-1.0 % 1).should == 0
+ end
+
+ it "returns self when modulus is +Infinity" do
+ (4.2 % Float::INFINITY).should == 4.2
+ end
+
+ it "returns -Infinity when modulus is -Infinity" do
+ (4.2 % -Float::INFINITY).should == -Float::INFINITY
+ end
+
+ it "returns NaN when called on NaN or Infinities" do
+ (Float::NAN % 42).should.nan?
+ (Float::INFINITY % 42).should.nan?
+ (-Float::INFINITY % 42).should.nan?
+ end
+
+ it "returns NaN when modulus is NaN" do
+ (4.2 % Float::NAN).should.nan?
+ end
+
+ it "returns -0.0 when called on -0.0 with a non zero modulus" do
+ r = -0.0 % 42
+ r.should == 0
+ (1/r).should < 0
+
+ r = -0.0 % Float::INFINITY
+ r.should == 0
+ (1/r).should < 0
+ end
+
+ it "tries to coerce the modulus" do
+ obj = mock("modulus")
+ obj.should_receive(:coerce).with(1.25).and_return([1.25, 0.5])
+ (1.25 % obj).should == 0.25
+ end
+
+ it "raises a ZeroDivisionError if other is zero" do
+ -> { 1.0 % 0 }.should.raise(ZeroDivisionError)
+ -> { 1.0 % 0.0 }.should.raise(ZeroDivisionError)
+ end
end
describe "Float#modulo" do
- it_behaves_like(:float_modulo, :modulo)
+ it "is an alias of Float#%" do
+ Float.instance_method(:modulo).should == Float.instance_method(:%)
+ end
end
diff --git a/spec/ruby/core/float/multiply_spec.rb b/spec/ruby/core/float/multiply_spec.rb
index 14680534c4..edaaba7e61 100644
--- a/spec/ruby/core/float/multiply_spec.rb
+++ b/spec/ruby/core/float/multiply_spec.rb
@@ -1,14 +1,17 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/arithmetic_exception_in_coerce'
describe "Float#*" do
+ it_behaves_like :float_arithmetic_exception_in_coerce, :*
+
it "returns self multiplied by other" do
(4923.98221 * 2).should be_close(9847.96442, TOLERANCE)
(6712.5 * 0.25).should be_close(1678.125, TOLERANCE)
- (256.4096 * bignum_value).should be_close(2364961134621118431232.000, TOLERANCE)
+ (256.4096 * bignum_value).should be_close(4729922269242236862464.0, TOLERANCE)
end
it "raises a TypeError when given a non-Numeric" do
- lambda { 13.0 * "10" }.should raise_error(TypeError)
- lambda { 13.0 * :symbol }.should raise_error(TypeError)
+ -> { 13.0 * "10" }.should.raise(TypeError)
+ -> { 13.0 * :symbol }.should.raise(TypeError)
end
end
diff --git a/spec/ruby/core/float/nan_spec.rb b/spec/ruby/core/float/nan_spec.rb
index 95a61d8872..c1043ef21b 100644
--- a/spec/ruby/core/float/nan_spec.rb
+++ b/spec/ruby/core/float/nan_spec.rb
@@ -1,9 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Float#nan?" do
it "returns true if self is not a valid IEEE floating-point number" do
- 0.0.nan?.should == false
- -1.5.nan?.should == false
- nan_value.nan?.should == true
+ 0.0.should_not.nan?
+ -1.5.should_not.nan?
+ nan_value.should.nan?
end
end
diff --git a/spec/ruby/core/float/negative_spec.rb b/spec/ruby/core/float/negative_spec.rb
new file mode 100644
index 0000000000..484e636adb
--- /dev/null
+++ b/spec/ruby/core/float/negative_spec.rb
@@ -0,0 +1,33 @@
+require_relative '../../spec_helper'
+
+describe "Float#negative?" do
+ describe "on positive numbers" do
+ it "returns false" do
+ 0.1.negative?.should == false
+ end
+ end
+
+ describe "on zero" do
+ it "returns false" do
+ 0.0.negative?.should == false
+ end
+ end
+
+ describe "on negative zero" do
+ it "returns false" do
+ -0.0.negative?.should == false
+ end
+ end
+
+ describe "on negative numbers" do
+ it "returns true" do
+ -0.1.negative?.should == true
+ end
+ end
+
+ describe "on NaN" do
+ it "returns false" do
+ nan_value.negative?.should == false
+ end
+ end
+end
diff --git a/spec/ruby/core/float/next_float_spec.rb b/spec/ruby/core/float/next_float_spec.rb
index d5a7748a06..59892be343 100644
--- a/spec/ruby/core/float/next_float_spec.rb
+++ b/spec/ruby/core/float/next_float_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Float#next_float" do
it "returns a float the smallest possible step greater than the receiver" do
@@ -9,7 +9,7 @@ describe "Float#next_float" do
barely_positive.should < barely_positive.next_float
midpoint = barely_positive / 2
- [0.0, barely_positive].should include midpoint
+ [0.0, barely_positive].should.include? midpoint
end
it "returns Float::INFINITY for Float::INFINITY" do
@@ -44,6 +44,6 @@ describe "Float#next_float" do
end
it "returns NAN if NAN was the receiver" do
- Float::NAN.next_float.nan?.should == true
+ Float::NAN.next_float.should.nan?
end
end
diff --git a/spec/ruby/core/float/numerator_spec.rb b/spec/ruby/core/float/numerator_spec.rb
index 9644d01c23..53b32fdd3d 100644
--- a/spec/ruby/core/float/numerator_spec.rb
+++ b/spec/ruby/core/float/numerator_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Float#numerator" do
before :all do
@@ -15,7 +15,7 @@ describe "Float#numerator" do
it "converts self to a Rational object then returns its numerator" do
@numbers.each do |number|
- number.infinite?.should be_nil
+ number.infinite?.should == nil
number.numerator.should == Rational(number).numerator
end
end
@@ -25,7 +25,7 @@ describe "Float#numerator" do
end
it "returns NaN for NaN" do
- nan_value.numerator.nan?.should be_true
+ nan_value.numerator.nan?.should == true
end
it "returns Infinity for Infinity" do
diff --git a/spec/ruby/core/float/phase_spec.rb b/spec/ruby/core/float/phase_spec.rb
index 95d0053816..ad112ac9fe 100644
--- a/spec/ruby/core/float/phase_spec.rb
+++ b/spec/ruby/core/float/phase_spec.rb
@@ -1,5 +1,7 @@
-require File.expand_path('../../../shared/complex/float/arg', __FILE__)
+require_relative '../../spec_helper'
describe "Float#phase" do
- it_behaves_like :float_arg, :phase
+ it "is an alias of Float#arg" do
+ Float.instance_method(:phase).should == Float.instance_method(:arg)
+ end
end
diff --git a/spec/ruby/core/float/plus_spec.rb b/spec/ruby/core/float/plus_spec.rb
index a49124d303..e3e19d7f39 100644
--- a/spec/ruby/core/float/plus_spec.rb
+++ b/spec/ruby/core/float/plus_spec.rb
@@ -1,9 +1,12 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/arithmetic_exception_in_coerce'
describe "Float#+" do
+ it_behaves_like :float_arithmetic_exception_in_coerce, :+
+
it "returns self plus other" do
(491.213 + 2).should be_close(493.213, TOLERANCE)
- (9.99 + bignum_value).should be_close(9223372036854775808.000, TOLERANCE)
+ (9.99 + bignum_value).should be_close(18446744073709551616.0, TOLERANCE)
(1001.99 + 5.219).should be_close(1007.209, TOLERANCE)
end
end
diff --git a/spec/ruby/core/float/positive_spec.rb b/spec/ruby/core/float/positive_spec.rb
new file mode 100644
index 0000000000..aa87c03151
--- /dev/null
+++ b/spec/ruby/core/float/positive_spec.rb
@@ -0,0 +1,33 @@
+require_relative '../../spec_helper'
+
+describe "Float#positive?" do
+ describe "on positive numbers" do
+ it "returns true" do
+ 0.1.positive?.should == true
+ end
+ end
+
+ describe "on zero" do
+ it "returns false" do
+ 0.0.positive?.should == false
+ end
+ end
+
+ describe "on negative zero" do
+ it "returns false" do
+ -0.0.positive?.should == false
+ end
+ end
+
+ describe "on negative numbers" do
+ it "returns false" do
+ -0.1.positive?.should == false
+ end
+ end
+
+ describe "on NaN" do
+ it "returns false" do
+ nan_value.positive?.should == false
+ end
+ end
+end
diff --git a/spec/ruby/core/float/prev_float_spec.rb b/spec/ruby/core/float/prev_float_spec.rb
index e07d78c44c..2d1f136254 100644
--- a/spec/ruby/core/float/prev_float_spec.rb
+++ b/spec/ruby/core/float/prev_float_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Float#prev_float" do
it "returns a float the smallest possible step smaller than the receiver" do
@@ -9,7 +9,7 @@ describe "Float#prev_float" do
barely_negative.should > barely_negative.prev_float
midpoint = barely_negative / 2
- [0.0, barely_negative].should include midpoint
+ [0.0, barely_negative].should.include? midpoint
end
it "returns -Float::INFINITY for -Float::INFINITY" do
@@ -44,6 +44,6 @@ describe "Float#prev_float" do
end
it "returns NAN if NAN was the receiver" do
- Float::NAN.prev_float.nan?.should == true
+ Float::NAN.prev_float.should.nan?
end
end
diff --git a/spec/ruby/core/float/quo_spec.rb b/spec/ruby/core/float/quo_spec.rb
index dcda8f5f3b..0e9a7a0a0c 100644
--- a/spec/ruby/core/float/quo_spec.rb
+++ b/spec/ruby/core/float/quo_spec.rb
@@ -1,6 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/quo', __FILE__)
+require_relative '../../spec_helper'
describe "Float#quo" do
- it_behaves_like :float_quo, :quo
+ it "is an alias of Float#fdiv" do
+ Float.instance_method(:quo).should == Float.instance_method(:fdiv)
+ end
end
diff --git a/spec/ruby/core/float/rationalize_spec.rb b/spec/ruby/core/float/rationalize_spec.rb
index 541080c48b..fa8fb5c841 100644
--- a/spec/ruby/core/float/rationalize_spec.rb
+++ b/spec/ruby/core/float/rationalize_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Float#rationalize" do
it "returns self as a simplified Rational with no argument" do
@@ -29,15 +29,15 @@ describe "Float#rationalize" do
end
it "raises a FloatDomainError for Infinity" do
- lambda {infinity_value.rationalize}.should raise_error(FloatDomainError)
+ -> {infinity_value.rationalize}.should.raise(FloatDomainError)
end
it "raises a FloatDomainError for NaN" do
- lambda { nan_value.rationalize }.should raise_error(FloatDomainError)
+ -> { nan_value.rationalize }.should.raise(FloatDomainError)
end
it "raises ArgumentError when passed more than one argument" do
- lambda { 0.3.rationalize(0.1, 0.1) }.should raise_error(ArgumentError)
- lambda { 0.3.rationalize(0.1, 0.1, 2) }.should raise_error(ArgumentError)
+ -> { 0.3.rationalize(0.1, 0.1) }.should.raise(ArgumentError)
+ -> { 0.3.rationalize(0.1, 0.1, 2) }.should.raise(ArgumentError)
end
end
diff --git a/spec/ruby/core/float/round_spec.rb b/spec/ruby/core/float/round_spec.rb
index 56668d5856..63c1d5689c 100644
--- a/spec/ruby/core/float/round_spec.rb
+++ b/spec/ruby/core/float/round_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Float#round" do
it "returns the nearest Integer" do
@@ -10,59 +10,63 @@ describe "Float#round" do
0.0.round.should == 0
end
- platform_is_not :mingw32 do
- it "returns the nearest Integer for Float near the limit" do
- 0.49999999999999994.round.should == 0
- -0.49999999999999994.round.should == 0
- end
+ it "returns the nearest Integer for Float near the limit" do
+ 0.49999999999999994.round.should == 0
+ -0.49999999999999994.round.should == 0
end
it "raises FloatDomainError for exceptional values" do
- lambda { (+infinity_value).round }.should raise_error(FloatDomainError)
- lambda { (-infinity_value).round }.should raise_error(FloatDomainError)
- lambda { nan_value.round }.should raise_error(FloatDomainError)
+ -> { (+infinity_value).round }.should.raise(FloatDomainError)
+ -> { (-infinity_value).round }.should.raise(FloatDomainError)
+ -> { nan_value.round }.should.raise(FloatDomainError)
end
it "rounds self to an optionally given precision" do
- 5.5.round(0).should eql(6)
- 5.7.round(1).should eql(5.7)
+ 5.5.round(0).should.eql?(6)
+ 5.7.round(1).should.eql?(5.7)
1.2345678.round(2).should == 1.23
- 123456.78.round(-2).should eql(123500) # rounded up
- -123456.78.round(-2).should eql(-123500)
+ 123456.78.round(-2).should.eql?(123500) # rounded up
+ -123456.78.round(-2).should.eql?(-123500)
12.345678.round(3.999).should == 12.346
end
- it "returns zero when passed a negative argument with magitude greater the magitude of the whole number portion of the Float" do
- 0.8346268.round(-1).should eql(0)
+ it "correctly rounds exact floats with a numerous digits in a fraction part" do
+ 0.8241000000000004.round(10).should == 0.8241
+ 0.8241000000000002.round(10).should == 0.8241
+ end
+
+ it "returns zero when passed a negative argument with magnitude greater than magnitude of the whole number portion of the Float" do
+ 0.8346268.round(-1).should.eql?(0)
end
it "raises a TypeError when its argument can not be converted to an Integer" do
- lambda { 1.0.round("4") }.should raise_error(TypeError)
- lambda { 1.0.round(nil) }.should raise_error(TypeError)
+ -> { 1.0.round("4") }.should.raise(TypeError)
+ -> { 1.0.round(nil) }.should.raise(TypeError)
end
it "raises FloatDomainError for exceptional values when passed a non-positive precision" do
- lambda { Float::INFINITY.round( 0) }.should raise_error(FloatDomainError)
- lambda { Float::INFINITY.round(-2) }.should raise_error(FloatDomainError)
- lambda { (-Float::INFINITY).round( 0) }.should raise_error(FloatDomainError)
- lambda { (-Float::INFINITY).round(-2) }.should raise_error(FloatDomainError)
+ -> { Float::INFINITY.round( 0) }.should.raise(FloatDomainError)
+ -> { Float::INFINITY.round(-2) }.should.raise(FloatDomainError)
+ -> { (-Float::INFINITY).round( 0) }.should.raise(FloatDomainError)
+ -> { (-Float::INFINITY).round(-2) }.should.raise(FloatDomainError)
end
it "raises RangeError for NAN when passed a non-positive precision" do
- lambda { Float::NAN.round(0) }.should raise_error(RangeError)
- lambda { Float::NAN.round(-2) }.should raise_error(RangeError)
+ -> { Float::NAN.round(0) }.should.raise(RangeError)
+ -> { Float::NAN.round(-2) }.should.raise(RangeError)
end
it "returns self for exceptional values when passed a non-negative precision" do
Float::INFINITY.round(2).should == Float::INFINITY
(-Float::INFINITY).round(2).should == -Float::INFINITY
- Float::NAN.round(2).should be_nan
+ Float::NAN.round(2).should.nan?
end
# redmine:5227
it "works for corner cases" do
- 42.0.round(308).should eql(42.0)
- 1.0e307.round(2).should eql(1.0e307)
+ 42.0.round(308).should.eql?(42.0)
+ 1.0e307.round(2).should.eql?(1.0e307)
+ 120.0.round(-1).should.eql?(120)
end
# redmine:5271
@@ -70,32 +74,135 @@ describe "Float#round" do
0.42.round(2.0**30).should == 0.42
end
+ it "returns rounded values for not so big argument" do
+ 0.42.round(2.0**23).should == 0.42
+ end
+
it "returns big values rounded to nearest" do
- +2.5e20.round(-20).should eql( +3 * 10 ** 20 )
- -2.5e20.round(-20).should eql( -3 * 10 ** 20 )
+ +2.5e20.round(-20).should.eql?( +3 * 10 ** 20 )
+ -2.5e20.round(-20).should.eql?( -3 * 10 ** 20 )
end
# redmine #5272
it "returns rounded values for big values" do
- +2.4e20.round(-20).should eql( +2 * 10 ** 20 )
- -2.4e20.round(-20).should eql( -2 * 10 ** 20 )
- +2.5e200.round(-200).should eql( +3 * 10 ** 200 )
- +2.4e200.round(-200).should eql( +2 * 10 ** 200 )
- -2.5e200.round(-200).should eql( -3 * 10 ** 200 )
- -2.4e200.round(-200).should eql( -2 * 10 ** 200 )
- end
-
- ruby_version_is "2.4" do
- it "returns different rounded values depending on the half option" do
- 2.5.round(half: :up).should eql(3)
- 2.5.round(half: :down).should eql(2)
- 2.5.round(half: :even).should eql(2)
- 3.5.round(half: :up).should eql(4)
- 3.5.round(half: :down).should eql(3)
- 3.5.round(half: :even).should eql(4)
- (-2.5).round(half: :up).should eql(-3)
- (-2.5).round(half: :down).should eql(-2)
- (-2.5).round(half: :even).should eql(-2)
+ +2.4e20.round(-20).should.eql?( +2 * 10 ** 20 )
+ -2.4e20.round(-20).should.eql?( -2 * 10 ** 20 )
+ +2.5e200.round(-200).should.eql?( +3 * 10 ** 200 )
+ +2.4e200.round(-200).should.eql?( +2 * 10 ** 200 )
+ -2.5e200.round(-200).should.eql?( -3 * 10 ** 200 )
+ -2.4e200.round(-200).should.eql?( -2 * 10 ** 200 )
+ end
+
+ it "returns different rounded values depending on the half option" do
+ 2.5.round(half: nil).should.eql?(3)
+ 2.5.round(half: :up).should.eql?(3)
+ 2.5.round(half: :down).should.eql?(2)
+ 2.5.round(half: :even).should.eql?(2)
+ 3.5.round(half: nil).should.eql?(4)
+ 3.5.round(half: :up).should.eql?(4)
+ 3.5.round(half: :down).should.eql?(3)
+ 3.5.round(half: :even).should.eql?(4)
+ (-2.5).round(half: nil).should.eql?(-3)
+ (-2.5).round(half: :up).should.eql?(-3)
+ (-2.5).round(half: :down).should.eql?(-2)
+ (-2.5).round(half: :even).should.eql?(-2)
+ end
+
+ it "rounds self to an optionally given precision with a half option" do
+ 5.55.round(1, half: nil).should.eql?(5.6)
+ 5.55.round(1, half: :up).should.eql?(5.6)
+ 5.55.round(1, half: :down).should.eql?(5.5)
+ 5.55.round(1, half: :even).should.eql?(5.6)
+ -5.55.round(1, half: nil).should.eql?(-5.6)
+ -5.55.round(1, half: :up).should.eql?(-5.6)
+ -5.55.round(1, half: :down).should.eql?(-5.5)
+ -5.55.round(1, half: :even).should.eql?(-5.6)
+ end
+
+ it "preserves cases where neighbouring floating pointer number increase the decimal places" do
+ 4.8100000000000005.round(5, half: nil).should.eql?(4.81)
+ 4.8100000000000005.round(5, half: :up).should.eql?(4.81)
+ 4.8100000000000005.round(5, half: :down).should.eql?(4.81)
+ 4.8100000000000005.round(5, half: :even).should.eql?(4.81)
+ -4.8100000000000005.round(5, half: nil).should.eql?(-4.81)
+ -4.8100000000000005.round(5, half: :up).should.eql?(-4.81)
+ -4.8100000000000005.round(5, half: :down).should.eql?(-4.81)
+ -4.8100000000000005.round(5, half: :even).should.eql?(-4.81)
+ 4.81.round(5, half: nil).should.eql?(4.81)
+ 4.81.round(5, half: :up).should.eql?(4.81)
+ 4.81.round(5, half: :down).should.eql?(4.81)
+ 4.81.round(5, half: :even).should.eql?(4.81)
+ -4.81.round(5, half: nil).should.eql?(-4.81)
+ -4.81.round(5, half: :up).should.eql?(-4.81)
+ -4.81.round(5, half: :down).should.eql?(-4.81)
+ -4.81.round(5, half: :even).should.eql?(-4.81)
+ 4.809999999999999.round(5, half: nil).should.eql?(4.81)
+ 4.809999999999999.round(5, half: :up).should.eql?(4.81)
+ 4.809999999999999.round(5, half: :down).should.eql?(4.81)
+ 4.809999999999999.round(5, half: :even).should.eql?(4.81)
+ -4.809999999999999.round(5, half: nil).should.eql?(-4.81)
+ -4.809999999999999.round(5, half: :up).should.eql?(-4.81)
+ -4.809999999999999.round(5, half: :down).should.eql?(-4.81)
+ -4.809999999999999.round(5, half: :even).should.eql?(-4.81)
+ end
+
+ # These numbers are neighbouring floating point numbers round a
+ # precise value. They test that the rounding modes work correctly
+ # round that value and precision is not lost which might cause
+ # incorrect results.
+ it "does not lose precision during the rounding process" do
+ 767573.1875850001.round(5, half: nil).should.eql?(767573.18759)
+ 767573.1875850001.round(5, half: :up).should.eql?(767573.18759)
+ 767573.1875850001.round(5, half: :down).should.eql?(767573.18759)
+ 767573.1875850001.round(5, half: :even).should.eql?(767573.18759)
+ -767573.1875850001.round(5, half: nil).should.eql?(-767573.18759)
+ -767573.1875850001.round(5, half: :up).should.eql?(-767573.18759)
+ -767573.1875850001.round(5, half: :down).should.eql?(-767573.18759)
+ -767573.1875850001.round(5, half: :even).should.eql?(-767573.18759)
+ 767573.187585.round(5, half: nil).should.eql?(767573.18759)
+ 767573.187585.round(5, half: :up).should.eql?(767573.18759)
+ 767573.187585.round(5, half: :down).should.eql?(767573.18758)
+ 767573.187585.round(5, half: :even).should.eql?(767573.18758)
+ -767573.187585.round(5, half: nil).should.eql?(-767573.18759)
+ -767573.187585.round(5, half: :up).should.eql?(-767573.18759)
+ -767573.187585.round(5, half: :down).should.eql?(-767573.18758)
+ -767573.187585.round(5, half: :even).should.eql?(-767573.18758)
+ 767573.1875849998.round(5, half: nil).should.eql?(767573.18758)
+ 767573.1875849998.round(5, half: :up).should.eql?(767573.18758)
+ 767573.1875849998.round(5, half: :down).should.eql?(767573.18758)
+ 767573.1875849998.round(5, half: :even).should.eql?(767573.18758)
+ -767573.1875849998.round(5, half: nil).should.eql?(-767573.18758)
+ -767573.1875849998.round(5, half: :up).should.eql?(-767573.18758)
+ -767573.1875849998.round(5, half: :down).should.eql?(-767573.18758)
+ -767573.1875849998.round(5, half: :even).should.eql?(-767573.18758)
+ end
+
+ it "raises FloatDomainError for exceptional values with a half option" do
+ -> { (+infinity_value).round(half: :up) }.should.raise(FloatDomainError)
+ -> { (-infinity_value).round(half: :down) }.should.raise(FloatDomainError)
+ -> { nan_value.round(half: :even) }.should.raise(FloatDomainError)
+ end
+
+ it "raise for a non-existent round mode" do
+ -> { 14.2.round(half: :nonsense) }.should.raise(ArgumentError, "invalid rounding mode: nonsense")
+ end
+
+ describe "when 0.0 is given" do
+ it "returns self for positive ndigits" do
+ (0.0).round(5).inspect.should == "0.0"
+ (-0.0).round(1).inspect.should == "-0.0"
+ end
+
+ it "returns 0 for 0 or undefined ndigits" do
+ (0.0).round.should == 0
+ (-0.0).round(0).should == 0
+ (0.0).round(half: :up).should == 0
+ end
+
+ it "returns 0 for negative ndigits" do
+ (0.0).round(-1).should == 0
+ (-0.0).round(-1).should == 0
+ (0.0).round(-1, half: :up).should == 0
end
end
end
diff --git a/spec/ruby/core/float/shared/abs.rb b/spec/ruby/core/float/shared/abs.rb
index c59198bfe2..ab21480e24 100644
--- a/spec/ruby/core/float/shared/abs.rb
+++ b/spec/ruby/core/float/shared/abs.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe :float_abs, shared: true do
it "returns the absolute value" do
@@ -16,6 +16,6 @@ describe :float_abs, shared: true do
end
it "returns NaN if NaN" do
- nan_value.send(@method).nan?.should be_true
+ nan_value.send(@method).nan?.should == true
end
end
diff --git a/spec/ruby/core/float/shared/arithmetic_exception_in_coerce.rb b/spec/ruby/core/float/shared/arithmetic_exception_in_coerce.rb
new file mode 100644
index 0000000000..bd3bf9019f
--- /dev/null
+++ b/spec/ruby/core/float/shared/arithmetic_exception_in_coerce.rb
@@ -0,0 +1,11 @@
+require_relative '../fixtures/classes'
+
+describe :float_arithmetic_exception_in_coerce, 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(FloatSpecs::CoerceError)
+
+ # e.g. 1.0 > b
+ -> { 1.0.send(@method, b) }.should.raise(FloatSpecs::CoerceError)
+ end
+end
diff --git a/spec/ruby/core/float/shared/comparison_exception_in_coerce.rb b/spec/ruby/core/float/shared/comparison_exception_in_coerce.rb
new file mode 100644
index 0000000000..eec5d8daf9
--- /dev/null
+++ b/spec/ruby/core/float/shared/comparison_exception_in_coerce.rb
@@ -0,0 +1,11 @@
+require_relative '../fixtures/classes'
+
+describe :float_comparison_exception_in_coerce, 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(FloatSpecs::CoerceError)
+
+ # e.g. 1.0 > b
+ -> { 1.0.send(@method, b) }.should.raise(FloatSpecs::CoerceError)
+ end
+end
diff --git a/spec/ruby/core/float/shared/equal.rb b/spec/ruby/core/float/shared/equal.rb
deleted file mode 100644
index 668aa069b5..0000000000
--- a/spec/ruby/core/float/shared/equal.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-describe :float_equal, shared: true do
- it "returns true if self has the same value as other" do
- 1.0.send(@method, 1).should == true
- 2.71828.send(@method, 1.428).should == false
- -4.2.send(@method, 4.2).should == false
- end
-
- it "calls 'other == self' if coercion fails" do
- x = mock('other')
- def x.==(other)
- 2.0 == other
- end
-
- 1.0.send(@method, x).should == false
- 2.0.send(@method, x).should == true
- end
-end
diff --git a/spec/ruby/core/float/shared/modulo.rb b/spec/ruby/core/float/shared/modulo.rb
deleted file mode 100644
index 6c423a3a28..0000000000
--- a/spec/ruby/core/float/shared/modulo.rb
+++ /dev/null
@@ -1,48 +0,0 @@
-describe :float_modulo, shared: true do
- it "returns self modulo other" do
- 6543.21.send(@method, 137).should be_close(104.21, TOLERANCE)
- 5667.19.send(@method, bignum_value).should be_close(5667.19, TOLERANCE)
- 6543.21.send(@method, 137.24).should be_close(92.9299999999996, TOLERANCE)
-
- -1.0.send(@method, 1).should == 0
- end
-
- it "returns self when modulus is +Infinity" do
- 4.2.send(@method, Float::INFINITY).should == 4.2
- end
-
- it "returns -Infinity when modulus is -Infinity" do
- 4.2.send(@method, -Float::INFINITY).should == -Float::INFINITY
- end
-
- it "returns NaN when called on NaN or Infinities" do
- Float::NAN.send(@method, 42).should be_nan
- Float::INFINITY.send(@method, 42).should be_nan
- (-Float::INFINITY).send(@method, 42).should be_nan
- end
-
- it "returns NaN when modulus is NaN" do
- 4.2.send(@method, Float::NAN).should be_nan
- end
-
- it "returns -0.0 when called on -0.0 with a non zero modulus" do
- r = (-0.0).send(@method, 42)
- r.should == 0
- (1/r).should < 0
-
- r = (-0.0).send(@method, Float::INFINITY)
- r.should == 0
- (1/r).should < 0
- end
-
- it "tries to coerce the modulus" do
- obj = mock("modulus")
- obj.should_receive(:coerce).with(1.25).and_return([1.25, 0.5])
- (1.25 % obj).should == 0.25
- end
-
- it "raises a ZeroDivisionError if other is zero" do
- lambda { 1.0.send(@method, 0) }.should raise_error(ZeroDivisionError)
- lambda { 1.0.send(@method, 0.0) }.should raise_error(ZeroDivisionError)
- end
-end
diff --git a/spec/ruby/core/float/shared/quo.rb b/spec/ruby/core/float/shared/quo.rb
deleted file mode 100644
index afc921a2c1..0000000000
--- a/spec/ruby/core/float/shared/quo.rb
+++ /dev/null
@@ -1,59 +0,0 @@
-describe :float_quo, shared: true do
- it "performs floating-point division between self and a Fixnum" do
- 8.9.send(@method, 7).should == 1.2714285714285716
- end
-
- it "performs floating-point division between self and a Bignum" do
- 8.9.send(@method, 9999999999999**9).should == 8.900000000008011e-117
- end
-
- it "performs floating-point division between self and a Float" do
- 2827.22.send(@method, 872.111111).should == 3.2418116961704433
- end
-
- it "returns NaN when the argument is NaN" do
- -1819.999999.send(@method, nan_value).nan?.should be_true
- 11109.1981271.send(@method, nan_value).nan?.should be_true
- end
-
- it "returns Infinity when the argument is 0.0" do
- 2827.22.send(@method, 0.0).infinite?.should == 1
- end
-
- it "returns -Infinity when the argument is 0.0 and self is negative" do
- -48229.282.send(@method, 0.0).infinite?.should == -1
- end
-
- it "returns Infinity when the argument is 0" do
- 2827.22.send(@method, 0).infinite?.should == 1
- end
-
- it "returns -Infinity when the argument is 0 and self is negative" do
- -48229.282.send(@method, 0).infinite?.should == -1
- end
-
- it "returns 0.0 when the argument is Infinity" do
- 47292.2821.send(@method, infinity_value).should == 0.0
- end
-
- it "returns -0.0 when the argument is -Infinity" do
- 1.9999918.send(@method, -infinity_value).should == -0.0
- end
-
- it "performs floating-point division between self and a Rational" do
- 74620.09.send(@method, Rational(2,3)).should == 111930.135
- end
-
- it "performs floating-point division between self and a Complex" do
- 74620.09.send(@method, Complex(8,2)).should == Complex(
- 8778.834117647059, -2194.7085294117646)
- end
-
- it "raises a TypeError when argument isn't numeric" do
- lambda { 27292.2.send(@method, mock('non-numeric')) }.should raise_error(TypeError)
- end
-
- it "raises an ArgumentError when passed multiple arguments" do
- lambda { 272.221.send(@method, 6,0.2) }.should raise_error(ArgumentError)
- end
-end
diff --git a/spec/ruby/core/float/shared/to_i.rb b/spec/ruby/core/float/shared/to_i.rb
index 960295f095..1e6f941467 100644
--- a/spec/ruby/core/float/shared/to_i.rb
+++ b/spec/ruby/core/float/shared/to_i.rb
@@ -1,10 +1,14 @@
describe :float_to_i, shared: true do
it "returns self truncated to an Integer" do
- 899.2.send(@method).should eql(899)
- -1.122256e-45.send(@method).should eql(0)
- 5_213_451.9201.send(@method).should eql(5213451)
- 1.233450999123389e+12.send(@method).should eql(1233450999123)
- -9223372036854775808.1.send(@method).should eql(-9223372036854775808)
- 9223372036854775808.1.send(@method).should eql(9223372036854775808)
+ 899.2.send(@method).should.eql?(899)
+ -1.122256e-45.send(@method).should.eql?(0)
+ 5_213_451.9201.send(@method).should.eql?(5213451)
+ 1.233450999123389e+12.send(@method).should.eql?(1233450999123)
+ -9223372036854775808.1.send(@method).should.eql?(-9223372036854775808)
+ 9223372036854775808.1.send(@method).should.eql?(9223372036854775808)
+ end
+
+ it "raises a FloatDomainError for NaN" do
+ -> { nan_value.send(@method) }.should.raise(FloatDomainError)
end
end
diff --git a/spec/ruby/core/float/to_f_spec.rb b/spec/ruby/core/float/to_f_spec.rb
index 02666ae7d7..6677556cd9 100644
--- a/spec/ruby/core/float/to_f_spec.rb
+++ b/spec/ruby/core/float/to_f_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Float#to_f" do
it "returns self" do
diff --git a/spec/ruby/core/float/to_i_spec.rb b/spec/ruby/core/float/to_i_spec.rb
index 5bf5a1b42a..91d84c5fa3 100644
--- a/spec/ruby/core/float/to_i_spec.rb
+++ b/spec/ruby/core/float/to_i_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/to_i', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/to_i'
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..ff70d508ff 100644
--- a/spec/ruby/core/float/to_int_spec.rb
+++ b/spec/ruby/core/float/to_int_spec.rb
@@ -1,6 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/to_i', __FILE__)
+require_relative '../../spec_helper'
describe "Float#to_int" do
- it_behaves_like(:float_to_i, :to_int)
+ it "is an alias of Float#to_i" do
+ Float.instance_method(:to_int).should == Float.instance_method(:to_i)
+ end
end
diff --git a/spec/ruby/core/float/to_r_spec.rb b/spec/ruby/core/float/to_r_spec.rb
index a0f5cd9700..907ff08f27 100644
--- a/spec/ruby/core/float/to_r_spec.rb
+++ b/spec/ruby/core/float/to_r_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Float#to_r" do
it "needs to be reviewed for spec completeness"
diff --git a/spec/ruby/core/float/to_s_spec.rb b/spec/ruby/core/float/to_s_spec.rb
index e76cfc1b7e..3fd64581c2 100644
--- a/spec/ruby/core/float/to_s_spec.rb
+++ b/spec/ruby/core/float/to_s_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Float#to_s" do
it "returns 'NaN' for NaN" do
@@ -75,11 +75,11 @@ describe "Float#to_s" do
-10000000000000000.0.to_s.should == "-1.0e+16"
end
- it "uses non-e format for a positive value with whole part having 17 significant figures" do
+ it "uses e format for a positive value with whole part having 17 significant figures" do
1000000000000000.0.to_s.should == "1.0e+15"
end
- it "uses non-e format for a negative value with whole part having 17 significant figures" do
+ it "uses e format for a negative value with whole part having 17 significant figures" do
-1000000000000000.0.to_s.should == "-1.0e+15"
end
@@ -95,10 +95,200 @@ describe "Float#to_s" do
it "outputs the minimal, unique form to represent the value" do
0.56.to_s.should == "0.56"
end
-end
-with_feature :encoding do
- describe "Float#to_s" do
+ describe "matches" do
+ it "random examples in all ranges" do
+ # 50.times do
+ # bytes = (0...8).map { rand(256) }
+ # string = bytes.pack('C8')
+ # float = string.unpack('D').first
+ # puts "#{'%.20g' % float}.to_s.should == #{float.to_s.inspect}"
+ # end
+
+ 2.5540217314354050325e+163.to_s.should == "2.554021731435405e+163"
+ 2.5492588360356597544e-172.to_s.should == "2.5492588360356598e-172"
+ 1.742770260934704852e-82.to_s.should == "1.7427702609347049e-82"
+ 6.2108093676180883209e-104.to_s.should == "6.210809367618088e-104"
+ -3.3448803488331067402e-143.to_s.should == "-3.3448803488331067e-143"
+ -2.2740074343500832557e-168.to_s.should == "-2.2740074343500833e-168"
+ 7.0587971678048535732e+191.to_s.should == "7.058797167804854e+191"
+ -284438.88327586348169.to_s.should == "-284438.8832758635"
+ 3.953272468476091301e+105.to_s.should == "3.9532724684760913e+105"
+ -3.6361359552959847853e+100.to_s.should == "-3.636135955295985e+100"
+ -1.3222325865575206185e-31.to_s.should == "-1.3222325865575206e-31"
+ 1.1440138916932761366e+130.to_s.should == "1.1440138916932761e+130"
+ 4.8750891560387561157e-286.to_s.should == "4.875089156038756e-286"
+ 5.6101113356591453525e-257.to_s.should == "5.610111335659145e-257"
+ -3.829644279545809575e-100.to_s.should == "-3.8296442795458096e-100"
+ 1.5342839401396406117e-194.to_s.should == "1.5342839401396406e-194"
+ 2.2284972755169921402e-144.to_s.should == "2.228497275516992e-144"
+ 2.1825655917065601737e-61.to_s.should == "2.1825655917065602e-61"
+ -2.6672271363524338322e-62.to_s.should == "-2.667227136352434e-62"
+ -1.9257995160119059415e+21.to_s.should == "-1.925799516011906e+21"
+ -8.9096732962887121718e-198.to_s.should == "-8.909673296288712e-198"
+ 2.0202075376548644959e-90.to_s.should == "2.0202075376548645e-90"
+ -7.7341602581786258961e-266.to_s.should == "-7.734160258178626e-266"
+ 3.5134482598733635046e+98.to_s.should == "3.5134482598733635e+98"
+ -2.124411722371029134e+154.to_s.should == "-2.124411722371029e+154"
+ -4.573908787355718687e+110.to_s.should == "-4.573908787355719e+110"
+ -1.9344425934170969879e-232.to_s.should == "-1.934442593417097e-232"
+ -1.3274227399979271095e+171.to_s.should == "-1.3274227399979271e+171"
+ 9.3495270482104442383e-283.to_s.should == "9.349527048210444e-283"
+ -4.2046059371986483233e+307.to_s.should == "-4.2046059371986483e+307"
+ 3.6133547278583543004e-117.to_s.should == "3.613354727858354e-117"
+ 4.9247416523566613499e-08.to_s.should == "4.9247416523566613e-08"
+ 1.6936145488250064007e-71.to_s.should == "1.6936145488250064e-71"
+ 2.4455483206829433098e+96.to_s.should == "2.4455483206829433e+96"
+ 7.9797449851436455384e+124.to_s.should == "7.979744985143646e+124"
+ -1.3873689634457876774e-129.to_s.should == "-1.3873689634457877e-129"
+ 3.9761102037533483075e+284.to_s.should == "3.976110203753348e+284"
+ -4.2819791952139402486e-303.to_s.should == "-4.28197919521394e-303"
+ -5.7981017546689831298e-116.to_s.should == "-5.798101754668983e-116"
+ -3.953266497860534199e-28.to_s.should == "-3.953266497860534e-28"
+ -2.0659852720290440959e-243.to_s.should == "-2.065985272029044e-243"
+ 8.9670488995878688018e-05.to_s.should == "8.967048899587869e-05"
+ -1.2317943708113061768e-98.to_s.should == "-1.2317943708113062e-98"
+ -3.8930768307633080463e+248.to_s.should == "-3.893076830763308e+248"
+ 6.5854032671803925627e-239.to_s.should == "6.5854032671803926e-239"
+ 4.6257022188980878952e+177.to_s.should == "4.625702218898088e+177"
+ -1.9397155125507235603e-187.to_s.should == "-1.9397155125507236e-187"
+ 8.5752156951245705056e+117.to_s.should == "8.57521569512457e+117"
+ -2.4784875958162501671e-132.to_s.should == "-2.4784875958162502e-132"
+ -4.4125691841230058457e-203.to_s.should == "-4.412569184123006e-203"
+ end
+
+ it "random examples in human ranges" do
+ # 50.times do
+ # formatted = ''
+ # rand(1..3).times do
+ # formatted << rand(10).to_s
+ # end
+ # formatted << '.'
+ # rand(1..9).times do
+ # formatted << rand(10).to_s
+ # end
+ # float = formatted.to_f
+ # puts "#{'%.20f' % float}.to_s.should == #{float.to_s.inspect}"
+ # end
+
+ 5.17869899999999994122.to_s.should == "5.178699"
+ 905.62695729999995819526.to_s.should == "905.6269573"
+ 62.75999999999999801048.to_s.should == "62.76"
+ 6.93856795800000014651.to_s.should == "6.938567958"
+ 4.95999999999999996447.to_s.should == "4.96"
+ 32.77993899999999882766.to_s.should == "32.779939"
+ 544.12756779999995160324.to_s.should == "544.1275678"
+ 66.25801119999999855281.to_s.should == "66.2580112"
+ 7.90000000000000035527.to_s.should == "7.9"
+ 5.93100000000000004974.to_s.should == "5.931"
+ 5.21229313600000043749.to_s.should == "5.212293136"
+ 503.44173809000000119340.to_s.should == "503.44173809"
+ 79.26000000000000511591.to_s.should == "79.26"
+ 8.51524999999999998579.to_s.should == "8.51525"
+ 174.00000000000000000000.to_s.should == "174.0"
+ 50.39580000000000126192.to_s.should == "50.3958"
+ 35.28999999999999914735.to_s.should == "35.29"
+ 5.43136675399999990788.to_s.should == "5.431366754"
+ 654.07680000000004838512.to_s.should == "654.0768"
+ 6.07423700000000010846.to_s.should == "6.074237"
+ 102.25779799999999397642.to_s.should == "102.257798"
+ 5.08129999999999970584.to_s.should == "5.0813"
+ 6.00000000000000000000.to_s.should == "6.0"
+ 8.30000000000000071054.to_s.should == "8.3"
+ 32.68345999999999662577.to_s.should == "32.68346"
+ 581.11170000000004165486.to_s.should == "581.1117"
+ 76.31342999999999676675.to_s.should == "76.31343"
+ 438.30826000000001840817.to_s.should == "438.30826"
+ 482.06631994000002805478.to_s.should == "482.06631994"
+ 55.92721026899999969828.to_s.should == "55.927210269"
+ 4.00000000000000000000.to_s.should == "4.0"
+ 55.86693999999999959982.to_s.should == "55.86694"
+ 787.98299999999994724931.to_s.should == "787.983"
+ 5.73810511000000023074.to_s.should == "5.73810511"
+ 74.51926810000000500622.to_s.should == "74.5192681"
+ 892.89999999999997726263.to_s.should == "892.9"
+ 68.27299999999999613465.to_s.should == "68.273"
+ 904.10000000000002273737.to_s.should == "904.1"
+ 5.23200000000000020606.to_s.should == "5.232"
+ 4.09628000000000014325.to_s.should == "4.09628"
+ 46.05152633699999853434.to_s.should == "46.051526337"
+ 142.12884990599999923688.to_s.should == "142.128849906"
+ 3.83057023500000015659.to_s.should == "3.830570235"
+ 11.81684594699999912848.to_s.should == "11.816845947"
+ 80.50000000000000000000.to_s.should == "80.5"
+ 382.18215010000000120272.to_s.should == "382.1821501"
+ 55.38444606899999911320.to_s.should == "55.384446069"
+ 5.78000000000000024869.to_s.should == "5.78"
+ 2.88244999999999995666.to_s.should == "2.88245"
+ 43.27709999999999723741.to_s.should == "43.2771"
+ end
+
+ it "random values from divisions" do
+ (1.0 / 7).to_s.should == "0.14285714285714285"
+
+ # 50.times do
+ # a = rand(10)
+ # b = rand(10)
+ # c = rand(10)
+ # d = rand(10)
+ # expression = "#{a}.#{b} / #{c}.#{d}"
+ # puts " (#{expression}).to_s.should == #{eval(expression).to_s.inspect}"
+ # end
+
+ (1.1 / 7.1).to_s.should == "0.15492957746478875"
+ (6.5 / 8.8).to_s.should == "0.7386363636363635"
+ (4.8 / 4.3).to_s.should == "1.1162790697674418"
+ (4.0 / 1.9).to_s.should == "2.1052631578947367"
+ (9.1 / 0.8).to_s.should == "11.374999999999998"
+ (5.3 / 7.5).to_s.should == "0.7066666666666667"
+ (2.8 / 1.8).to_s.should == "1.5555555555555554"
+ (2.1 / 2.5).to_s.should == "0.8400000000000001"
+ (3.5 / 6.0).to_s.should == "0.5833333333333334"
+ (4.6 / 0.3).to_s.should == "15.333333333333332"
+ (0.6 / 2.4).to_s.should == "0.25"
+ (1.3 / 9.1).to_s.should == "0.14285714285714288"
+ (0.3 / 5.0).to_s.should == "0.06"
+ (5.0 / 4.2).to_s.should == "1.1904761904761905"
+ (3.0 / 2.0).to_s.should == "1.5"
+ (6.3 / 2.0).to_s.should == "3.15"
+ (5.4 / 6.0).to_s.should == "0.9"
+ (9.6 / 8.1).to_s.should == "1.1851851851851851"
+ (8.7 / 1.6).to_s.should == "5.437499999999999"
+ (1.9 / 7.8).to_s.should == "0.24358974358974358"
+ (0.5 / 2.1).to_s.should == "0.23809523809523808"
+ (9.3 / 5.8).to_s.should == "1.6034482758620692"
+ (2.7 / 8.0).to_s.should == "0.3375"
+ (9.7 / 7.8).to_s.should == "1.2435897435897436"
+ (8.1 / 2.4).to_s.should == "3.375"
+ (7.7 / 2.7).to_s.should == "2.8518518518518516"
+ (7.9 / 1.7).to_s.should == "4.647058823529412"
+ (6.5 / 8.2).to_s.should == "0.7926829268292683"
+ (7.8 / 9.6).to_s.should == "0.8125"
+ (2.2 / 4.6).to_s.should == "0.47826086956521746"
+ (0.0 / 1.0).to_s.should == "0.0"
+ (8.3 / 2.9).to_s.should == "2.8620689655172415"
+ (3.1 / 6.1).to_s.should == "0.5081967213114754"
+ (2.8 / 7.8).to_s.should == "0.358974358974359"
+ (8.0 / 0.1).to_s.should == "80.0"
+ (1.7 / 6.4).to_s.should == "0.265625"
+ (1.8 / 5.4).to_s.should == "0.3333333333333333"
+ (8.0 / 5.8).to_s.should == "1.3793103448275863"
+ (5.2 / 4.1).to_s.should == "1.2682926829268295"
+ (9.8 / 5.8).to_s.should == "1.6896551724137934"
+ (5.4 / 9.5).to_s.should == "0.5684210526315789"
+ (8.4 / 4.9).to_s.should == "1.7142857142857142"
+ (1.7 / 3.5).to_s.should == "0.4857142857142857"
+ (1.2 / 5.1).to_s.should == "0.23529411764705882"
+ (1.4 / 2.0).to_s.should == "0.7"
+ (4.8 / 8.0).to_s.should == "0.6"
+ (9.0 / 2.5).to_s.should == "3.6"
+ (0.2 / 0.6).to_s.should == "0.33333333333333337"
+ (7.8 / 5.2).to_s.should == "1.5"
+ (9.5 / 5.5).to_s.should == "1.7272727272727273"
+ end
+ end
+
+ describe 'encoding' do
before :each do
@internal = Encoding.default_internal
end
@@ -109,12 +299,12 @@ with_feature :encoding do
it "returns a String in US-ASCII encoding when Encoding.default_internal is nil" do
Encoding.default_internal = nil
- 1.23.to_s.encoding.should equal(Encoding::US_ASCII)
+ 1.23.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
- 5.47.to_s.encoding.should equal(Encoding::US_ASCII)
+ 5.47.to_s.encoding.should.equal?(Encoding::US_ASCII)
end
end
end
diff --git a/spec/ruby/core/float/truncate_spec.rb b/spec/ruby/core/float/truncate_spec.rb
index 7feeb81735..1750e3fdbc 100644
--- a/spec/ruby/core/float/truncate_spec.rb
+++ b/spec/ruby/core/float/truncate_spec.rb
@@ -1,16 +1,14 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/to_i', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/to_i'
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
- 2.1679.truncate(0).should eql(2)
- 7.1.truncate(1).should eql(7.1)
- 214.94.truncate(-1).should eql(210)
- -1.234.truncate(2).should eql(-1.23)
- 5.123812.truncate(4).should eql(5.1238)
- end
+ it "returns self truncated to an optionally given precision" do
+ 2.1679.truncate(0).should.eql?(2)
+ 7.1.truncate(1).should.eql?(7.1)
+ 214.94.truncate(-1).should.eql?(210)
+ -1.234.truncate(2).should.eql?(-1.23)
+ 5.123812.truncate(4).should.eql?(5.1238)
end
end
diff --git a/spec/ruby/core/float/uminus_spec.rb b/spec/ruby/core/float/uminus_spec.rb
index 70e2ff0580..57bae0fb4b 100644
--- a/spec/ruby/core/float/uminus_spec.rb
+++ b/spec/ruby/core/float/uminus_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Float#-@" do
it "negates self" do
@@ -23,6 +23,6 @@ describe "Float#-@" do
end
it "returns NaN for NaN" do
- nan_value.send(:-@).nan?.should == true
+ nan_value.send(:-@).should.nan?
end
end
diff --git a/spec/ruby/core/float/uplus_spec.rb b/spec/ruby/core/float/uplus_spec.rb
index 75f18191dd..b979b2717a 100644
--- a/spec/ruby/core/float/uplus_spec.rb
+++ b/spec/ruby/core/float/uplus_spec.rb
@@ -1,9 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Float#+@" do
it "returns the same value with same sign (twos complement)" do
34.56.send(:+@).should == 34.56
-34.56.send(:+@).should == -34.56
- 0.0.send(:+@).should eql(0.0)
+ 0.0.send(:+@).should.eql?(0.0)
end
end
diff --git a/spec/ruby/core/float/zero_spec.rb b/spec/ruby/core/float/zero_spec.rb
index 3a67551a07..1f3de27793 100644
--- a/spec/ruby/core/float/zero_spec.rb
+++ b/spec/ruby/core/float/zero_spec.rb
@@ -1,9 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Float#zero?" do
it "returns true if self is 0.0" do
- 0.0.zero?.should == true
- 1.0.zero?.should == false
- -1.0.zero?.should == false
+ 0.0.should.zero?
+ 1.0.should_not.zero?
+ -1.0.should_not.zero?
end
end
diff --git a/spec/ruby/core/gc/auto_compact_spec.rb b/spec/ruby/core/gc/auto_compact_spec.rb
new file mode 100644
index 0000000000..33ad1cb56c
--- /dev/null
+++ b/spec/ruby/core/gc/auto_compact_spec.rb
@@ -0,0 +1,24 @@
+require_relative '../../spec_helper'
+
+describe "GC.auto_compact" do
+ it "can set and get a boolean value" do
+ begin
+ GC.auto_compact = GC.auto_compact
+ rescue NotImplementedError # platform does not support autocompact
+ skip
+ end
+
+ original = GC.auto_compact
+ begin
+ GC.auto_compact = !original
+ rescue NotImplementedError # platform does not support autocompact
+ skip
+ end
+
+ begin
+ GC.auto_compact.should == !original
+ ensure
+ GC.auto_compact = original
+ end
+ end
+end
diff --git a/spec/ruby/core/gc/config_spec.rb b/spec/ruby/core/gc/config_spec.rb
new file mode 100644
index 0000000000..57160f122c
--- /dev/null
+++ b/spec/ruby/core/gc/config_spec.rb
@@ -0,0 +1,97 @@
+require_relative '../../spec_helper'
+
+ruby_version_is "3.4" do
+ describe "GC.config" do
+ context "without arguments" do
+ it "returns a hash of current settings" do
+ GC.config.should.is_a?(Hash)
+ end
+
+ it "includes the name of currently loaded GC implementation as a global key" do
+ GC.config.should.include?(:implementation)
+ GC.config[:implementation].should.is_a?(String)
+ end
+ end
+
+ context "with a hash of options" do
+ it "allows to set GC implementation's options, returning the new config" do
+ config = GC.config({})
+ # Try to find a boolean setting to reliably test changing it.
+ key, _value = config.find { |_k, v| v == true }
+ skip unless key
+
+ GC.config(key => false).should == config.merge(key => false)
+ GC.config[key].should == false
+ GC.config(key => true).should == config
+ GC.config[key].should == true
+ ensure
+ GC.config(config.except(:implementation))
+ end
+
+ it "does not change settings that aren't present in the hash" do
+ previous = GC.config
+ GC.config({})
+ GC.config.should == previous
+ end
+
+ it "ignores unknown keys" do
+ previous = GC.config
+ GC.config(foo: "bar")
+ GC.config.should == previous
+ end
+
+ ruby_version_is ""..."4.0" do
+ it "returns the same as GC.config but without the :implementation key" do
+ previous = GC.config
+ GC.config({}).should == previous.except(:implementation)
+ end
+ end
+
+ ruby_version_is "4.0" do
+ it "returns the same as GC.config, including the :implementation key" do
+ previous = GC.config
+ GC.config({}).should == previous
+ end
+ end
+
+ it "raises an ArgumentError if options include global keys" do
+ -> { GC.config(implementation: "default") }.should.raise(ArgumentError, 'Attempting to set read-only key "Implementation"')
+ end
+ end
+
+ context "with a non-hash argument" do
+ it "returns current settings if argument is nil" do
+ GC.config(nil).should == GC.config
+ end
+
+ it "raises ArgumentError for all other arguments" do
+ -> { GC.config([]) }.should.raise(ArgumentError)
+ -> { GC.config("default") }.should.raise(ArgumentError)
+ -> { GC.config(1) }.should.raise(ArgumentError)
+ end
+ end
+
+ guard -> { PlatformGuard.standard? && GC.config[:implementation] == "default" } do
+ context "with default GC implementation on MRI" do
+ before do
+ @default_config = GC.config({})
+ end
+
+ after do
+ GC.config(@default_config.except(:implementation))
+ end
+
+ it "includes :rgengc_allow_full_mark option, true by default" do
+ GC.config.should.include?(:rgengc_allow_full_mark)
+ GC.config[:rgengc_allow_full_mark].should == true
+ end
+
+ it "allows to set :rgengc_allow_full_mark" do
+ # This key maps truthy and falsey values to true and false.
+ GC.config(rgengc_allow_full_mark: nil).should == @default_config.merge(rgengc_allow_full_mark: false)
+ GC.config(rgengc_allow_full_mark: 1.23).should == @default_config.merge(rgengc_allow_full_mark: true)
+ end
+ end
+ end
+ end
+end
diff --git a/spec/ruby/core/gc/count_spec.rb b/spec/ruby/core/gc/count_spec.rb
index 3caa2c9aac..fe20c4ed2b 100644
--- a/spec/ruby/core/gc/count_spec.rb
+++ b/spec/ruby/core/gc/count_spec.rb
@@ -1,7 +1,17 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "GC.count" do
it "returns an integer" do
- GC.count.should be_kind_of(Integer)
+ GC.count.should.is_a?(Integer)
+ end
+
+ it "increases as collections are run" do
+ count_before = GC.count
+ i = 0
+ while GC.count <= count_before and i < 10
+ GC.start
+ i += 1
+ end
+ GC.count.should > count_before
end
end
diff --git a/spec/ruby/core/gc/disable_spec.rb b/spec/ruby/core/gc/disable_spec.rb
index 9a8a8f23e9..f89a9d2768 100644
--- a/spec/ruby/core/gc/disable_spec.rb
+++ b/spec/ruby/core/gc/disable_spec.rb
@@ -1,11 +1,11 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "GC.disable" do
after :each do
GC.enable
end
- it "returns true iff the garbage collection was previously disabled" do
+ it "returns true if and only if the garbage collection was previously disabled" do
GC.enable
GC.disable.should == false
GC.disable.should == true
diff --git a/spec/ruby/core/gc/enable_spec.rb b/spec/ruby/core/gc/enable_spec.rb
index d3581ad4d8..ca4488547a 100644
--- a/spec/ruby/core/gc/enable_spec.rb
+++ b/spec/ruby/core/gc/enable_spec.rb
@@ -1,8 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "GC.enable" do
- it "returns true iff the garbage collection was already disabled" do
+ it "returns true if and only if the garbage collection was already disabled" do
GC.enable
GC.enable.should == false
GC.disable
diff --git a/spec/ruby/core/gc/garbage_collect_spec.rb b/spec/ruby/core/gc/garbage_collect_spec.rb
index 2b47fdf927..f67f0486c8 100644
--- a/spec/ruby/core/gc/garbage_collect_spec.rb
+++ b/spec/ruby/core/gc/garbage_collect_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "GC#garbage_collect" do
diff --git a/spec/ruby/core/gc/measure_total_time_spec.rb b/spec/ruby/core/gc/measure_total_time_spec.rb
new file mode 100644
index 0000000000..f5377c18fd
--- /dev/null
+++ b/spec/ruby/core/gc/measure_total_time_spec.rb
@@ -0,0 +1,17 @@
+require_relative '../../spec_helper'
+
+describe "GC.measure_total_time" do
+ before :each do
+ @default = GC.measure_total_time
+ end
+
+ after :each do
+ GC.measure_total_time = @default
+ end
+
+ it "can set and get a boolean value" do
+ original = GC.measure_total_time
+ GC.measure_total_time = !original
+ GC.measure_total_time.should == !original
+ end
+end
diff --git a/spec/ruby/core/gc/profiler/clear_spec.rb b/spec/ruby/core/gc/profiler/clear_spec.rb
index 47a52a5800..95c3d4ed65 100644
--- a/spec/ruby/core/gc/profiler/clear_spec.rb
+++ b/spec/ruby/core/gc/profiler/clear_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "GC::Profiler.clear" do
it "needs to be reviewed for spec completeness"
diff --git a/spec/ruby/core/gc/profiler/disable_spec.rb b/spec/ruby/core/gc/profiler/disable_spec.rb
index 9b8cedb1d5..74089693eb 100644
--- a/spec/ruby/core/gc/profiler/disable_spec.rb
+++ b/spec/ruby/core/gc/profiler/disable_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "GC::Profiler.disable" do
before do
@@ -11,6 +11,6 @@ describe "GC::Profiler.disable" do
it "disables the profiler" do
GC::Profiler.disable
- GC::Profiler.enabled?.should == false
+ GC::Profiler.should_not.enabled?
end
end
diff --git a/spec/ruby/core/gc/profiler/enable_spec.rb b/spec/ruby/core/gc/profiler/enable_spec.rb
index 49e6fc09e0..313ca3d949 100644
--- a/spec/ruby/core/gc/profiler/enable_spec.rb
+++ b/spec/ruby/core/gc/profiler/enable_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "GC::Profiler.enable" do
@@ -12,6 +12,6 @@ describe "GC::Profiler.enable" do
it "enables the profiler" do
GC::Profiler.enable
- GC::Profiler.enabled?.should == true
+ GC::Profiler.should.enabled?
end
end
diff --git a/spec/ruby/core/gc/profiler/enabled_spec.rb b/spec/ruby/core/gc/profiler/enabled_spec.rb
index 12cf3173f4..cfcd0951f0 100644
--- a/spec/ruby/core/gc/profiler/enabled_spec.rb
+++ b/spec/ruby/core/gc/profiler/enabled_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "GC::Profiler.enabled?" do
before do
@@ -11,11 +11,11 @@ describe "GC::Profiler.enabled?" do
it "reports as enabled when enabled" do
GC::Profiler.enable
- GC::Profiler.enabled?.should be_true
+ GC::Profiler.enabled?.should == true
end
it "reports as disabled when disabled" do
GC::Profiler.disable
- GC::Profiler.enabled?.should be_false
+ GC::Profiler.enabled?.should == false
end
end
diff --git a/spec/ruby/core/gc/profiler/report_spec.rb b/spec/ruby/core/gc/profiler/report_spec.rb
index 52e5e154ce..732b1d0f51 100644
--- a/spec/ruby/core/gc/profiler/report_spec.rb
+++ b/spec/ruby/core/gc/profiler/report_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "GC::Profiler.report" do
it "needs to be reviewed for spec completeness"
diff --git a/spec/ruby/core/gc/profiler/result_spec.rb b/spec/ruby/core/gc/profiler/result_spec.rb
index 395cf18400..e888f975dc 100644
--- a/spec/ruby/core/gc/profiler/result_spec.rb
+++ b/spec/ruby/core/gc/profiler/result_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "GC::Profiler.result" do
it "returns a string" do
- GC::Profiler.result.should be_kind_of(String)
+ GC::Profiler.result.should.is_a?(String)
end
end
diff --git a/spec/ruby/core/gc/profiler/total_time_spec.rb b/spec/ruby/core/gc/profiler/total_time_spec.rb
index 60fe8f182e..a351e922af 100644
--- a/spec/ruby/core/gc/profiler/total_time_spec.rb
+++ b/spec/ruby/core/gc/profiler/total_time_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "GC::Profiler.total_time" do
it "returns an float" do
- GC::Profiler.total_time.should be_kind_of(Float)
+ GC::Profiler.total_time.should.is_a?(Float)
end
end
diff --git a/spec/ruby/core/gc/start_spec.rb b/spec/ruby/core/gc/start_spec.rb
index dd24b5d6c6..c941058969 100644
--- a/spec/ruby/core/gc/start_spec.rb
+++ b/spec/ruby/core/gc/start_spec.rb
@@ -1,8 +1,12 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "GC.start" do
it "always returns nil" do
GC.start.should == nil
GC.start.should == nil
end
+
+ it "accepts keyword arguments" do
+ GC.start(full_mark: true, immediate_sweep: true).should == nil
+ end
end
diff --git a/spec/ruby/core/gc/stat_spec.rb b/spec/ruby/core/gc/stat_spec.rb
new file mode 100644
index 0000000000..6e4800b3e3
--- /dev/null
+++ b/spec/ruby/core/gc/stat_spec.rb
@@ -0,0 +1,62 @@
+require_relative '../../spec_helper'
+
+describe "GC.stat" do
+ it "returns hash of values" do
+ stat = GC.stat
+ stat.should.is_a?(Hash)
+ stat.keys.should.include?(:count)
+ end
+
+ it "updates the given hash values" do
+ hash = { count: "hello", __other__: "world" }
+ stat = GC.stat(hash)
+
+ stat.should.is_a?(Hash)
+ stat.should.equal? hash
+ stat[:count].should.is_a?(Integer)
+ stat[:__other__].should == "world"
+ end
+
+ it "the values are all Integer since rb_gc_stat() returns size_t" do
+ GC.stat.values.each { |value| value.should.is_a?(Integer) }
+ end
+
+ it "can return a single value" do
+ GC.stat(:count).should.is_a?(Integer)
+ end
+
+ it "increases count after GC is run" do
+ count = GC.stat(:count)
+ GC.start
+ GC.stat(:count).should > count
+ end
+
+ it "increases major_gc_count after GC is run" do
+ count = GC.stat(:major_gc_count)
+ GC.start
+ GC.stat(:major_gc_count).should > count
+ end
+
+ it "provides some number for count" do
+ GC.stat(:count).should.is_a?(Integer)
+ GC.stat[:count].should.is_a?(Integer)
+ end
+
+ it "provides some number for heap_free_slots" do
+ GC.stat(:heap_free_slots).should.is_a?(Integer)
+ GC.stat[:heap_free_slots].should.is_a?(Integer)
+ end
+
+ it "provides some number for total_allocated_objects" do
+ GC.stat(:total_allocated_objects).should.is_a?(Integer)
+ GC.stat[:total_allocated_objects].should.is_a?(Integer)
+ end
+
+ it "raises an error if argument is not nil, a symbol, or a hash" do
+ -> { GC.stat(7) }.should.raise(TypeError, "non-hash or symbol given")
+ end
+
+ it "raises an error if an unknown key is given" do
+ -> { GC.stat(:foo) }.should.raise(ArgumentError, "unknown key: foo")
+ end
+end
diff --git a/spec/ruby/core/gc/stress_spec.rb b/spec/ruby/core/gc/stress_spec.rb
index 5730848895..227a795e7f 100644
--- a/spec/ruby/core/gc/stress_spec.rb
+++ b/spec/ruby/core/gc/stress_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "GC.stress" do
after :each do
@@ -7,11 +7,11 @@ describe "GC.stress" do
end
it "returns current status of GC stress mode" do
- GC.stress.should be_false
+ GC.stress.should == false
GC.stress = true
- GC.stress.should be_true
+ GC.stress.should == true
GC.stress = false
- GC.stress.should be_false
+ GC.stress.should == false
end
end
@@ -22,6 +22,6 @@ describe "GC.stress=" do
it "sets the stress mode" do
GC.stress = true
- GC.stress.should be_true
+ GC.stress.should == true
end
end
diff --git a/spec/ruby/core/gc/total_time_spec.rb b/spec/ruby/core/gc/total_time_spec.rb
new file mode 100644
index 0000000000..f10e0ad742
--- /dev/null
+++ b/spec/ruby/core/gc/total_time_spec.rb
@@ -0,0 +1,13 @@
+require_relative '../../spec_helper'
+
+describe "GC.total_time" do
+ it "returns an Integer" do
+ GC.total_time.should.is_a?(Integer)
+ end
+
+ it "increases as collections are run" do
+ time_before = GC.total_time
+ GC.start
+ GC.total_time.should >= time_before
+ end
+end
diff --git a/spec/ruby/core/hash/allocate_spec.rb b/spec/ruby/core/hash/allocate_spec.rb
index d607f235bd..a92accc161 100644
--- a/spec/ruby/core/hash/allocate_spec.rb
+++ b/spec/ruby/core/hash/allocate_spec.rb
@@ -1,9 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Hash.allocate" do
it "returns an instance of Hash" do
hsh = Hash.allocate
- hsh.should be_an_instance_of(Hash)
+ hsh.should.instance_of?(Hash)
end
it "returns a fully-formed instance of Hash" do
diff --git a/spec/ruby/core/hash/any_spec.rb b/spec/ruby/core/hash/any_spec.rb
index ab8d320c18..c26dfabde6 100644
--- a/spec/ruby/core/hash/any_spec.rb
+++ b/spec/ruby/core/hash/any_spec.rb
@@ -1,13 +1,13 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Hash#any?" do
describe 'with no block given' do
it "checks if there are any members of a Hash" do
empty_hash = {}
- empty_hash.any?.should == false
+ empty_hash.should_not.any?
hash_with_members = { 'key' => 'value' }
- hash_with_members.any?.should == true
+ hash_with_members.should.any?
end
end
diff --git a/spec/ruby/core/hash/assoc_spec.rb b/spec/ruby/core/hash/assoc_spec.rb
index 0b10720b6f..51af51a20f 100644
--- a/spec/ruby/core/hash/assoc_spec.rb
+++ b/spec/ruby/core/hash/assoc_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Hash#assoc" do
before :each do
@@ -6,7 +6,7 @@ describe "Hash#assoc" do
end
it "returns an Array if the argument is == to a key of the Hash" do
- @h.assoc(:apple).should be_an_instance_of(Array)
+ @h.assoc(:apple).should.instance_of?(Array)
end
it "returns a 2-element Array if the argument is == to a key of the Hash" do
@@ -22,11 +22,11 @@ describe "Hash#assoc" do
end
it "only returns the first matching key-value pair for identity hashes" do
- # Avoid literal String keys in Hash#[]= due to https://bugs.ruby-lang.org/issues/12855
+ # Avoid literal String keys since string literals can be frozen and interned e.g. with --enable-frozen-string-literal
h = {}.compare_by_identity
- k1 = 'pear'
+ k1 = 'pear'.dup
h[k1] = :red
- k2 = 'pear'
+ k2 = 'pear'.dup
h[k2] = :green
h.size.should == 2
h.keys.grep(/pear/).size.should == 2
@@ -40,11 +40,11 @@ describe "Hash#assoc" do
end
it "returns nil if the argument is not a key of the Hash" do
- @h.assoc(:green).should be_nil
+ @h.assoc(:green).should == nil
end
it "returns nil if the argument is not a key of the Hash even when there is a default" do
- Hash.new(42).merge!( foo: :bar ).assoc(42).should be_nil
- Hash.new{|h, k| h[k] = 42}.merge!( foo: :bar ).assoc(42).should be_nil
+ Hash.new(42).merge!( foo: :bar ).assoc(42).should == nil
+ Hash.new{|h, k| h[k] = 42}.merge!( foo: :bar ).assoc(42).should == nil
end
end
diff --git a/spec/ruby/core/hash/clear_spec.rb b/spec/ruby/core/hash/clear_spec.rb
index ea8235451a..beff925a63 100644
--- a/spec/ruby/core/hash/clear_spec.rb
+++ b/spec/ruby/core/hash/clear_spec.rb
@@ -1,10 +1,10 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Hash#clear" do
it "removes all key, value pairs" do
h = { 1 => 2, 3 => 4 }
- h.clear.should equal(h)
+ h.clear.should.equal?(h)
h.should == {}
end
@@ -25,8 +25,8 @@ describe "Hash#clear" do
h.default_proc.should_not == nil
end
- it "raises a RuntimeError if called on a frozen instance" do
- lambda { HashSpecs.frozen_hash.clear }.should raise_error(RuntimeError)
- lambda { HashSpecs.empty_frozen_hash.clear }.should raise_error(RuntimeError)
+ it "raises a FrozenError if called on a frozen instance" do
+ -> { HashSpecs.frozen_hash.clear }.should.raise(FrozenError)
+ -> { HashSpecs.empty_frozen_hash.clear }.should.raise(FrozenError)
end
end
diff --git a/spec/ruby/core/hash/clone_spec.rb b/spec/ruby/core/hash/clone_spec.rb
index 188ae1c807..d135a84453 100644
--- a/spec/ruby/core/hash/clone_spec.rb
+++ b/spec/ruby/core/hash/clone_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Hash#clone" do
it "copies instance variable but not the objects they refer to" do
@@ -7,7 +7,6 @@ describe "Hash#clone" do
clone = hash.clone
clone.should == hash
- clone.object_id.should_not == hash.object_id
+ clone.should_not.equal? hash
end
end
-
diff --git a/spec/ruby/core/hash/compact_spec.rb b/spec/ruby/core/hash/compact_spec.rb
index d9ef8a2987..de83dabed3 100644
--- a/spec/ruby/core/hash/compact_spec.rb
+++ b/spec/ruby/core/hash/compact_spec.rb
@@ -1,61 +1,81 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
-ruby_version_is "2.4" do
- describe "Hash#compact" do
- before :each do
- @hash = { truthy: true, false: false, nil: nil, nil => true }
- @initial_pairs = @hash.dup
- @compact = { truthy: true, false: false, nil => true }
- end
+describe "Hash#compact" do
+ before :each do
+ @hash = { truthy: true, false: false, nil: nil, nil => true }
+ @initial_pairs = @hash.dup
+ @compact = { truthy: true, false: false, nil => true }
+ end
- it "returns new object that rejects pair has nil value" do
- ret = @hash.compact
- ret.should_not equal(@hash)
- ret.should == @compact
- end
+ it "returns new object that rejects pair has nil value" do
+ ret = @hash.compact
+ ret.should_not.equal?(@hash)
+ ret.should == @compact
+ end
- it "keeps own pairs" do
- @hash.compact
- @hash.should == @initial_pairs
- end
+ it "keeps own pairs" do
+ @hash.compact
+ @hash.should == @initial_pairs
end
- describe "Hash#compact!" do
- before :each do
- @hash = { truthy: true, false: false, nil: nil, nil => true }
- @initial_pairs = @hash.dup
- @compact = { truthy: true, false: false, nil => true }
- end
+ it "retains the default value" do
+ hash = Hash.new(1)
+ hash.compact.default.should == 1
+ hash[:a] = 1
+ hash.compact.default.should == 1
+ end
- it "returns self" do
- @hash.compact!.should equal(@hash)
- end
+ it "retains the default_proc" do
+ pr = proc { |h, k| h[k] = [] }
+ hash = Hash.new(&pr)
+ hash.compact.default_proc.should == pr
+ hash[:a] = 1
+ hash.compact.default_proc.should == pr
+ end
- it "rejects own pair has nil value" do
+ it "retains compare_by_identity flag" do
+ hash = {}.compare_by_identity
+ hash.compact.compare_by_identity?.should == true
+ hash[:a] = 1
+ hash.compact.compare_by_identity?.should == true
+ end
+end
+
+describe "Hash#compact!" do
+ before :each do
+ @hash = { truthy: true, false: false, nil: nil, nil => true }
+ @initial_pairs = @hash.dup
+ @compact = { truthy: true, false: false, nil => true }
+ end
+
+ it "returns self" do
+ @hash.compact!.should.equal?(@hash)
+ end
+
+ it "rejects own pair has nil value" do
+ @hash.compact!
+ @hash.should == @compact
+ end
+
+ context "when each pair does not have nil value" do
+ before :each do
@hash.compact!
- @hash.should == @compact
end
- context "when each pair does not have nil value" do
- before :each do
- @hash.compact!
- end
-
- it "returns nil" do
- @hash.compact!.should be_nil
- end
+ it "returns nil" do
+ @hash.compact!.should == nil
end
+ end
- describe "on frozen instance" do
- before :each do
- @hash.freeze
- end
+ describe "on frozen instance" do
+ before :each do
+ @hash.freeze
+ end
- it "keeps pairs and raises a RuntimeError" do
- ->{ @hash.compact! }.should raise_error(RuntimeError)
- @hash.should == @initial_pairs
- end
+ it "keeps pairs and raises a FrozenError" do
+ ->{ @hash.compact! }.should.raise(FrozenError)
+ @hash.should == @initial_pairs
end
end
end
diff --git a/spec/ruby/core/hash/compare_by_identity_spec.rb b/spec/ruby/core/hash/compare_by_identity_spec.rb
index a518e0cdb3..1abf9d5666 100644
--- a/spec/ruby/core/hash/compare_by_identity_spec.rb
+++ b/spec/ruby/core/hash/compare_by_identity_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Hash#compare_by_identity" do
before :each do
@@ -11,7 +11,7 @@ describe "Hash#compare_by_identity" do
@h[[1]] = :a
@h[[1]].should == :a
@h.compare_by_identity
- @h[[1].dup].should be_nil
+ @h[[1].dup].should == nil
end
it "rehashes internally so that old keys can be looked up" do
@@ -27,21 +27,21 @@ describe "Hash#compare_by_identity" do
it "returns self" do
h = {}
h[:foo] = :bar
- h.compare_by_identity.should equal h
+ h.compare_by_identity.should.equal? h
end
it "has no effect on an already compare_by_identity hash" do
@idh[:foo] = :bar
- @idh.compare_by_identity.should equal @idh
- @idh.compare_by_identity?.should == true
+ @idh.compare_by_identity.should.equal? @idh
+ @idh.should.compare_by_identity?
@idh[:foo].should == :bar
end
it "uses the semantics of BasicObject#equal? to determine key identity" do
- [1].should_not equal([1])
+ [1].should_not.equal?([1])
@idh[[1]] = :c
@idh[[1]] = :d
- :bar.should equal(:bar)
+ :bar.should.equal?(:bar)
@idh[:bar] = :e
@idh[:bar] = :f
@idh.values.should == [:c, :d, :f]
@@ -64,13 +64,13 @@ describe "Hash#compare_by_identity" do
it "regards #dup'd objects as having different identities" do
key = ['foo']
@idh[key.dup] = :str
- @idh[key].should be_nil
+ @idh[key].should == nil
end
it "regards #clone'd objects as having different identities" do
key = ['foo']
@idh[key.clone] = :str
- @idh[key].should be_nil
+ @idh[key].should == nil
end
it "regards references to the same object as having the same identity" do
@@ -80,24 +80,26 @@ describe "Hash#compare_by_identity" do
@h[o].should == :o
end
- it "raises a RuntimeError on frozen hashes" do
+ it "raises a FrozenError on frozen hashes" do
@h = @h.freeze
- lambda { @h.compare_by_identity }.should raise_error(RuntimeError)
+ -> { @h.compare_by_identity }.should.raise(FrozenError)
end
- # Behaviour confirmed in bug #1871
+ # Behaviour confirmed in https://bugs.ruby-lang.org/issues/1871
it "persists over #dups" do
- @idh['foo'] = :bar
- @idh['foo'] = :glark
+ @idh['foo'.dup] = :bar
+ @idh['foo'.dup] = :glark
@idh.dup.should == @idh
@idh.dup.size.should == @idh.size
+ @idh.dup.should.compare_by_identity?
end
it "persists over #clones" do
- @idh['foo'] = :bar
- @idh['foo'] = :glark
+ @idh['foo'.dup] = :bar
+ @idh['foo'.dup] = :glark
@idh.clone.should == @idh
@idh.clone.size.should == @idh.size
+ @idh.dup.should.compare_by_identity?
end
it "does not copy string keys" do
@@ -105,36 +107,41 @@ describe "Hash#compare_by_identity" do
@idh[foo] = true
@idh[foo] = true
@idh.size.should == 1
- @idh.keys.first.object_id.should == foo.object_id
- end
-
- ruby_bug "#12855", "2.2.0"..."2.4.1" do
- it "gives different identity for string literals" do
- @idh['foo'] = 1
- @idh['foo'] = 2
- @idh.values.should == [1, 2]
- @idh.size.should == 2
- end
+ @idh.keys.first.should.equal? foo
+ end
+
+ # Check `#[]=` call with a String literal.
+ # Don't use `#+` because with `#+` it's no longer a String literal.
+ #
+ # See https://bugs.ruby-lang.org/issues/12855
+ it "gives different identity for string literals" do
+ eval <<~RUBY
+ # frozen_string_literal: false
+ @idh['foo'] = 1
+ @idh['foo'] = 2
+ RUBY
+ @idh.values.should == [1, 2]
+ @idh.size.should == 2
end
end
describe "Hash#compare_by_identity?" do
it "returns false by default" do
h = {}
- h.compare_by_identity?.should be_false
+ h.compare_by_identity?.should == false
end
it "returns true once #compare_by_identity has been invoked on self" do
h = {}
h.compare_by_identity
- h.compare_by_identity?.should be_true
+ h.compare_by_identity?.should == true
end
it "returns true when called multiple times on the same ident hash" do
h = {}
h.compare_by_identity
- h.compare_by_identity?.should be_true
- h.compare_by_identity?.should be_true
- h.compare_by_identity?.should be_true
+ h.compare_by_identity?.should == true
+ h.compare_by_identity?.should == true
+ h.compare_by_identity?.should == true
end
end
diff --git a/spec/ruby/core/hash/constructor_spec.rb b/spec/ruby/core/hash/constructor_spec.rb
index 0f582d91de..c16f373160 100644
--- a/spec/ruby/core/hash/constructor_spec.rb
+++ b/spec/ruby/core/hash/constructor_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Hash.[]" do
describe "passed zero arguments" do
@@ -42,25 +42,25 @@ describe "Hash.[]" do
Hash[ary].should == { a: :b }
end
- it "ignores elements that are not arrays" do
+ it "raises for elements that are not arrays" do
-> {
- Hash[[:a]].should == {}
- }.should complain(/ignoring wrong elements/)
+ Hash[[:a]]
+ }.should.raise(ArgumentError, "wrong element type Symbol at 0 (expected array)")
-> {
- Hash[[:nil]].should == {}
- }.should complain(/ignoring wrong elements/)
+ Hash[[nil]]
+ }.should.raise(ArgumentError, "wrong element type nil at 0 (expected array)")
end
it "raises an ArgumentError for arrays of more than 2 elements" do
- lambda{ Hash[[[:a, :b, :c]]].should == {} }.should raise_error(ArgumentError)
+ ->{
+ Hash[[[:a, :b, :c]]]
+ }.should.raise(ArgumentError, "invalid number of elements (3 for 1..2)")
end
it "raises an ArgumentError when passed a list of value-invalid-pairs in an array" do
-> {
- -> {
- Hash[[[:a, 1], [:b], 42, [:d, 2], [:e, 2, 3], []]]
- }.should complain(/ignoring wrong elements/)
- }.should raise_error(ArgumentError)
+ Hash[[[:a, 1], [:b], 42, [:d, 2], [:e, 2, 3], []]]
+ }.should.raise(ArgumentError, "wrong element type Integer at 2 (expected array)")
end
describe "passed a single argument which responds to #to_hash" do
@@ -71,13 +71,13 @@ describe "Hash.[]" do
result = Hash[to_hash]
result.should == h
- result.should_not equal(h)
+ result.should_not.equal?(h)
end
end
it "raises an ArgumentError when passed an odd number of arguments" do
- lambda { Hash[1, 2, 3] }.should raise_error(ArgumentError)
- lambda { Hash[1, 2, { 3 => 4 }] }.should raise_error(ArgumentError)
+ -> { Hash[1, 2, 3] }.should.raise(ArgumentError)
+ -> { Hash[1, 2, { 3 => 4 }] }.should.raise(ArgumentError)
end
it "calls to_hash" do
@@ -87,24 +87,41 @@ describe "Hash.[]" do
end
it "returns an instance of a subclass when passed an Array" do
- HashSpecs::MyHash[1,2,3,4].should be_an_instance_of(HashSpecs::MyHash)
+ HashSpecs::MyHash[1,2,3,4].should.instance_of?(HashSpecs::MyHash)
end
it "returns instances of subclasses" do
- HashSpecs::MyHash[].should be_an_instance_of(HashSpecs::MyHash)
+ HashSpecs::MyHash[].should.instance_of?(HashSpecs::MyHash)
end
it "returns an instance of the class it's called on" do
Hash[HashSpecs::MyHash[1, 2]].class.should == Hash
- HashSpecs::MyHash[Hash[1, 2]].should be_an_instance_of(HashSpecs::MyHash)
+ HashSpecs::MyHash[Hash[1, 2]].should.instance_of?(HashSpecs::MyHash)
end
it "does not call #initialize on the subclass instance" do
- HashSpecs::MyInitializerHash[Hash[1, 2]].should be_an_instance_of(HashSpecs::MyInitializerHash)
+ HashSpecs::MyInitializerHash[Hash[1, 2]].should.instance_of?(HashSpecs::MyInitializerHash)
end
- it "removes the default_proc" do
+ it "does not retain the default value" do
+ hash = Hash.new(1)
+ Hash[hash].default.should == nil
+ hash[:a] = 1
+ Hash[hash].default.should == nil
+ end
+
+ it "does not retain the default_proc" do
hash = Hash.new { |h, k| h[k] = [] }
- Hash[hash].default_proc.should be_nil
+ Hash[hash].default_proc.should == nil
+ hash[:a] = 1
+ Hash[hash].default_proc.should == nil
+ end
+
+ it "does not retain compare_by_identity flag" do
+ hash = { a: 1 }.compare_by_identity
+ Hash[hash].compare_by_identity?.should == false
+
+ hash = {}.compare_by_identity
+ Hash[hash].compare_by_identity?.should == false
end
end
diff --git a/spec/ruby/core/hash/deconstruct_keys_spec.rb b/spec/ruby/core/hash/deconstruct_keys_spec.rb
new file mode 100644
index 0000000000..f6ff3a2818
--- /dev/null
+++ b/spec/ruby/core/hash/deconstruct_keys_spec.rb
@@ -0,0 +1,23 @@
+require_relative '../../spec_helper'
+
+describe "Hash#deconstruct_keys" do
+ it "returns self" do
+ hash = {a: 1, b: 2}
+
+ hash.deconstruct_keys([:a, :b]).should.equal? hash
+ end
+
+ it "requires one argument" do
+ -> {
+ {a: 1}.deconstruct_keys
+ }.should.raise(ArgumentError, /wrong number of arguments \(given 0, expected 1\)/)
+ end
+
+ it "ignores argument" do
+ hash = {a: 1, b: 2}
+
+ hash.deconstruct_keys([:a]).should == {a: 1, b: 2}
+ hash.deconstruct_keys(0 ).should == {a: 1, b: 2}
+ hash.deconstruct_keys('' ).should == {a: 1, b: 2}
+ end
+end
diff --git a/spec/ruby/core/hash/default_proc_spec.rb b/spec/ruby/core/hash/default_proc_spec.rb
index 0bd20d43af..4830e02acd 100644
--- a/spec/ruby/core/hash/default_proc_spec.rb
+++ b/spec/ruby/core/hash/default_proc_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Hash#default_proc" do
it "returns the block passed to Hash.new" do
@@ -25,24 +25,24 @@ describe "Hash#default_proc=" do
h = Hash.new { 'Paris' }
obj = mock('to_proc')
obj.should_receive(:to_proc).and_return(Proc.new { 'Montreal' })
- (h.default_proc = obj).should equal(obj)
+ (h.default_proc = obj).should.equal?(obj)
h[:cool_city].should == 'Montreal'
end
it "overrides the static default" do
h = Hash.new(42)
h.default_proc = Proc.new { 6 }
- h.default.should be_nil
+ h.default.should == nil
h.default_proc.call.should == 6
end
it "raises an error if passed stuff not convertible to procs" do
- lambda{{}.default_proc = 42}.should raise_error(TypeError)
+ ->{{}.default_proc = 42}.should.raise(TypeError)
end
it "returns the passed Proc" do
new_proc = Proc.new {}
- ({}.default_proc = new_proc).should equal(new_proc)
+ ({}.default_proc = new_proc).should.equal?(new_proc)
end
it "clears the default proc if passed nil" do
@@ -53,28 +53,28 @@ describe "Hash#default_proc=" do
end
it "returns nil if passed nil" do
- ({}.default_proc = nil).should be_nil
+ ({}.default_proc = nil).should == nil
end
it "accepts a lambda with an arity of 2" do
h = {}
- lambda do
- h.default_proc = lambda {|a,b| }
- end.should_not raise_error(TypeError)
+ -> do
+ h.default_proc = -> a, b { }
+ end.should_not.raise(TypeError)
end
it "raises a TypeError if passed a lambda with an arity other than 2" do
h = {}
- lambda do
- h.default_proc = lambda {|a| }
- end.should raise_error(TypeError)
- lambda do
- h.default_proc = lambda {|a,b,c| }
- end.should raise_error(TypeError)
+ -> do
+ h.default_proc = -> a { }
+ end.should.raise(TypeError)
+ -> do
+ h.default_proc = -> a, b, c { }
+ end.should.raise(TypeError)
end
- it "raises a RuntimeError if self is frozen" do
- lambda { {}.freeze.default_proc = Proc.new {} }.should raise_error(RuntimeError)
- lambda { {}.freeze.default_proc = nil }.should raise_error(RuntimeError)
+ it "raises a FrozenError if self is frozen" do
+ -> { {}.freeze.default_proc = Proc.new {} }.should.raise(FrozenError)
+ -> { {}.freeze.default_proc = nil }.should.raise(FrozenError)
end
end
diff --git a/spec/ruby/core/hash/default_spec.rb b/spec/ruby/core/hash/default_spec.rb
index 6c1c7377b7..17ee032e2b 100644
--- a/spec/ruby/core/hash/default_spec.rb
+++ b/spec/ruby/core/hash/default_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Hash#default" do
it "returns the default value" do
@@ -30,7 +30,7 @@ describe "Hash#default=" do
end
it "unsets the default proc" do
- [99, nil, lambda { 6 }].each do |default|
+ [99, nil, -> { 6 }].each do |default|
h = Hash.new { 5 }
h.default_proc.should_not == nil
h.default = default
@@ -39,8 +39,8 @@ describe "Hash#default=" do
end
end
- it "raises a RuntimeError if called on a frozen instance" do
- lambda { HashSpecs.frozen_hash.default = nil }.should raise_error(RuntimeError)
- lambda { HashSpecs.empty_frozen_hash.default = nil }.should raise_error(RuntimeError)
+ it "raises a FrozenError if called on a frozen instance" do
+ -> { HashSpecs.frozen_hash.default = nil }.should.raise(FrozenError)
+ -> { HashSpecs.empty_frozen_hash.default = nil }.should.raise(FrozenError)
end
end
diff --git a/spec/ruby/core/hash/delete_if_spec.rb b/spec/ruby/core/hash/delete_if_spec.rb
index d739e4fbab..3090633d88 100644
--- a/spec/ruby/core/hash/delete_if_spec.rb
+++ b/spec/ruby/core/hash/delete_if_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/iteration', __FILE__)
-require File.expand_path('../../enumerable/shared/enumeratorized', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/iteration'
+require_relative '../enumerable/shared/enumeratorized'
describe "Hash#delete_if" do
it "yields two arguments: key and value" do
@@ -12,13 +12,13 @@ describe "Hash#delete_if" do
it "removes every entry for which block is true and returns self" do
h = { a: 1, b: 2, c: 3, d: 4 }
- h.delete_if { |k,v| v % 2 == 1 }.should equal(h)
+ h.delete_if { |k,v| v % 2 == 1 }.should.equal?(h)
h.should == { b: 2, d: 4 }
end
it "removes all entries if the block is true" do
h = { a: 1, b: 2, c: 3 }
- h.delete_if { |k,v| true }.should equal(h)
+ h.delete_if { |k,v| true }.should.equal?(h)
h.should == {}
end
@@ -34,11 +34,11 @@ describe "Hash#delete_if" do
each_pairs.should == delete_pairs
end
- it "raises a RuntimeError if called on a frozen instance" do
- lambda { HashSpecs.frozen_hash.delete_if { false } }.should raise_error(RuntimeError)
- lambda { HashSpecs.empty_frozen_hash.delete_if { true } }.should raise_error(RuntimeError)
+ it "raises a FrozenError if called on a frozen instance" do
+ -> { HashSpecs.frozen_hash.delete_if { false } }.should.raise(FrozenError)
+ -> { HashSpecs.empty_frozen_hash.delete_if { true } }.should.raise(FrozenError)
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/delete_spec.rb b/spec/ruby/core/hash/delete_spec.rb
index a41fad3586..33ff01bf36 100644
--- a/spec/ruby/core/hash/delete_spec.rb
+++ b/spec/ruby/core/hash/delete_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Hash#delete" do
it "removes the entry and returns the deleted value" do
@@ -24,7 +24,7 @@ describe "Hash#delete" do
it "allows removing a key while iterating" do
h = { a: 1, b: 2 }
visited = []
- h.each_pair { |k,v|
+ h.each_pair { |k, v|
visited << k
h.delete(k)
}
@@ -32,13 +32,27 @@ describe "Hash#delete" do
h.should == {}
end
+ it "allows removing a key while iterating for big hashes" do
+ h = { a: 1, b: 2, c: 3, d: 4, e: 5, f: 6, g: 7, h: 8, i: 9, j: 10,
+ k: 11, l: 12, m: 13, n: 14, o: 15, p: 16, q: 17, r: 18, s: 19, t: 20,
+ u: 21, v: 22, w: 23, x: 24, y: 25, z: 26 }
+ visited = []
+ h.each_pair { |k, v|
+ visited << k
+ h.delete(k)
+ }
+ visited.should == [:a, :b, :c, :d, :e, :f, :g, :h, :i, :j, :k, :l, :m,
+ :n, :o, :p, :q, :r, :s, :t, :u, :v, :w, :x, :y, :z]
+ h.should == {}
+ end
+
it "accepts keys with private #hash method" do
key = HashSpecs::KeyWithPrivateHash.new
{ key => 5 }.delete(key).should == 5
end
- it "raises a RuntimeError if called on a frozen instance" do
- lambda { HashSpecs.frozen_hash.delete("foo") }.should raise_error(RuntimeError)
- lambda { HashSpecs.empty_frozen_hash.delete("foo") }.should raise_error(RuntimeError)
+ it "raises a FrozenError if called on a frozen instance" do
+ -> { HashSpecs.frozen_hash.delete("foo") }.should.raise(FrozenError)
+ -> { HashSpecs.empty_frozen_hash.delete("foo") }.should.raise(FrozenError)
end
end
diff --git a/spec/ruby/core/hash/dig_spec.rb b/spec/ruby/core/hash/dig_spec.rb
index 237c407e91..94ac94e850 100644
--- a/spec/ruby/core/hash/dig_spec.rb
+++ b/spec/ruby/core/hash/dig_spec.rb
@@ -1,68 +1,66 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
-ruby_version_is '2.3' do
- describe "Hash#dig" do
+describe "Hash#dig" do
- it "returns #[] with one arg" do
- h = { 0 => false, a: 1 }
- h.dig(:a).should == 1
- h.dig(0).should be_false
- h.dig(1).should be_nil
- end
+ it "returns #[] with one arg" do
+ h = { 0 => false, a: 1 }
+ h.dig(:a).should == 1
+ h.dig(0).should == false
+ h.dig(1).should == nil
+ end
- it "returns the nested value specified by the sequence of keys" do
- h = { foo: { bar: { baz: 1 } } }
- h.dig(:foo, :bar, :baz).should == 1
- h.dig(:foo, :bar, :nope).should be_nil
- h.dig(:foo, :baz).should be_nil
- h.dig(:bar, :baz, :foo).should be_nil
- end
+ it "returns the nested value specified by the sequence of keys" do
+ h = { foo: { bar: { baz: 1 } } }
+ h.dig(:foo, :bar, :baz).should == 1
+ h.dig(:foo, :bar, :nope).should == nil
+ h.dig(:foo, :baz).should == nil
+ h.dig(:bar, :baz, :foo).should == nil
+ end
- it "returns the nested value specified if the sequence includes an index" do
- h = { foo: [1, 2, 3] }
- h.dig(:foo, 2).should == 3
- end
+ it "returns the nested value specified if the sequence includes an index" do
+ h = { foo: [1, 2, 3] }
+ h.dig(:foo, 2).should == 3
+ end
- it "returns nil if any intermediate step is nil" do
- h = { foo: { bar: { baz: 1 } } }
- h.dig(:foo, :zot, :xyz).should == nil
- end
+ it "returns nil if any intermediate step is nil" do
+ h = { foo: { bar: { baz: 1 } } }
+ h.dig(:foo, :zot, :xyz).should == nil
+ end
- it "raises an ArgumentError if no arguments provided" do
- lambda { { the: 'borg' }.dig() }.should raise_error(ArgumentError)
- end
+ it "raises an ArgumentError if no arguments provided" do
+ -> { { the: 'borg' }.dig() }.should.raise(ArgumentError)
+ end
- it "handles type-mixed deep digging" do
- h = {}
- h[:foo] = [ { bar: [ 1 ] }, [ obj = Object.new, 'str' ] ]
- def obj.dig(*args); [ 42 ] end
+ it "handles type-mixed deep digging" do
+ h = {}
+ h[:foo] = [ { bar: [ 1 ] }, [ obj = Object.new, 'str' ] ]
+ def obj.dig(*args); [ 42 ] end
- h.dig(:foo, 0, :bar).should == [ 1 ]
- h.dig(:foo, 0, :bar, 0).should == 1
- h.dig(:foo, 1, 1).should == 'str'
- # MRI does not recurse values returned from `obj.dig`
- h.dig(:foo, 1, 0, 0).should == [ 42 ]
- h.dig(:foo, 1, 0, 0, 10).should == [ 42 ]
- end
+ h.dig(:foo, 0, :bar).should == [ 1 ]
+ h.dig(:foo, 0, :bar, 0).should == 1
+ h.dig(:foo, 1, 1).should == 'str'
+ # MRI does not recurse values returned from `obj.dig`
+ h.dig(:foo, 1, 0, 0).should == [ 42 ]
+ h.dig(:foo, 1, 0, 0, 10).should == [ 42 ]
+ end
- it "raises TypeError if an intermediate element does not respond to #dig" do
- h = {}
- h[:foo] = [ { bar: [ 1 ] }, [ nil, 'str' ] ]
- lambda { h.dig(:foo, 0, :bar, 0, 0) }.should raise_error(TypeError)
- lambda { h.dig(:foo, 1, 1, 0) }.should raise_error(TypeError)
- end
+ it "raises TypeError if an intermediate element does not respond to #dig" do
+ h = {}
+ h[:foo] = [ { bar: [ 1 ] }, [ nil, 'str' ] ]
+ -> { h.dig(:foo, 0, :bar, 0, 0) }.should.raise(TypeError)
+ -> { h.dig(:foo, 1, 1, 0) }.should.raise(TypeError)
+ end
- it "calls #dig on the result of #[] with the remaining arguments" do
- h = { foo: { bar: { baz: 42 } } }
- h[:foo].should_receive(:dig).with(:bar, :baz).and_return(42)
- h.dig(:foo, :bar, :baz).should == 42
- end
+ it "calls #dig on the result of #[] with the remaining arguments" do
+ h = { foo: { bar: { baz: 42 } } }
+ h[:foo].should_receive(:dig).with(:bar, :baz).and_return(42)
+ h.dig(:foo, :bar, :baz).should == 42
+ end
- it "respects Hash's default" do
- default = {bar: 42}
- h = Hash.new(default)
- h.dig(:foo).should equal default
- h.dig(:foo, :bar).should == 42
- end
+ it "respects Hash's default" do
+ default = {bar: 42}
+ h = Hash.new(default)
+ h.dig(:foo).should.equal? default
+ h.dig(:foo, :bar).should == 42
end
end
diff --git a/spec/ruby/core/hash/each_key_spec.rb b/spec/ruby/core/hash/each_key_spec.rb
index 4a4078a594..5b2e9deb63 100644
--- a/spec/ruby/core/hash/each_key_spec.rb
+++ b/spec/ruby/core/hash/each_key_spec.rb
@@ -1,13 +1,13 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/iteration', __FILE__)
-require File.expand_path('../../enumerable/shared/enumeratorized', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/iteration'
+require_relative '../enumerable/shared/enumeratorized'
describe "Hash#each_key" do
it "calls block once for each key, passing key" do
r = {}
h = { 1 => -1, 2 => -2, 3 => -3, 4 => -4 }
- h.each_key { |k| r[k] = k }.should equal(h)
+ h.each_key { |k| r[k] = k }.should.equal?(h)
r.should == { 1 => 1, 2 => 2, 3 => 3, 4 => 4 }
end
@@ -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..01810c130c 100644
--- a/spec/ruby/core/hash/each_pair_spec.rb
+++ b/spec/ruby/core/hash/each_pair_spec.rb
@@ -1,11 +1,111 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/iteration', __FILE__)
-require File.expand_path('../shared/each', __FILE__)
-require File.expand_path('../../enumerable/shared/enumeratorized', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/iteration'
+require_relative '../enumerable/shared/enumeratorized'
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_iteration_no_block, :each_pair
+ it_behaves_like :enumeratorized_with_origin_size, :each_pair, { 1 => 2, 3 => 4, 5 => 6 }
+
+ # This is inconsistent with below, MRI checks the block arity in rb_hash_each_pair()
+ it "yields a [[key, value]] Array for each pair to a block expecting |*args|" do
+ all_args = []
+ { 1 => 2, 3 => 4 }.each_pair { |*args| all_args << args }
+ all_args.sort.should == [[[1, 2]], [[3, 4]]]
+ end
+
+ it "yields the key and value of each pair to a block expecting |key, value|" do
+ r = {}
+ h = { a: 1, b: 2, c: 3, d: 5 }
+ h.each_pair { |k,v| r[k.to_s] = v.to_s }.should.equal?(h)
+ r.should == { "a" => "1", "b" => "2", "c" => "3", "d" => "5" }
+ end
+
+ it "yields the key only to a block expecting |key,|" do
+ ary = []
+ h = { "a" => 1, "b" => 2, "c" => 3 }
+ h.each_pair { |k,| ary << k }
+ ary.sort.should == ["a", "b", "c"]
+ end
+
+ it "always yields an Array of 2 elements, even when given a callable of arity 2" do
+ obj = Object.new
+ def obj.foo(key, value)
+ end
+
+ -> {
+ { "a" => 1 }.each_pair(&obj.method(:foo))
+ }.should.raise(ArgumentError)
+
+ -> {
+ { "a" => 1 }.each_pair(&-> key, value { })
+ }.should.raise(ArgumentError)
+ end
+
+ it "yields an Array of 2 elements when given a callable of arity 1" do
+ obj = Object.new
+ def obj.foo(key_value)
+ ScratchPad << key_value
+ end
+
+ ScratchPad.record([])
+ { "a" => 1 }.each_pair(&obj.method(:foo))
+ ScratchPad.recorded.should == [["a", 1]]
+ end
+
+ it "raises an error for a Hash when an arity enforcing callable of arity >2 is passed in" do
+ obj = Object.new
+ def obj.foo(key, value, extra)
+ end
+
+ -> {
+ { "a" => 1 }.each_pair(&obj.method(:foo))
+ }.should.raise(ArgumentError)
+ end
+
+ it "uses the same order as keys() and values()" do
+ h = { a: 1, b: 2, c: 3, d: 5 }
+ keys = []
+ values = []
+
+ h.each_pair do |k, v|
+ keys << k
+ values << v
+ end
+
+ keys.should == h.keys
+ values.should == h.values
+ end
+
+ # Confirming the argument-splatting works from child class for both k, v and [k, v]
+ it "properly expands (or not) child class's 'each'-yielded args" do
+ cls1 = Class.new(Hash) do
+ attr_accessor :k_v
+ def each
+ super do |k, v|
+ @k_v = [k, v]
+ yield k, v
+ end
+ end
+ end
+
+ cls2 = Class.new(Hash) do
+ attr_accessor :k_v
+ def each
+ super do |k, v|
+ @k_v = [k, v]
+ yield([k, v])
+ end
+ end
+ end
+
+ obj1 = cls1.new
+ obj1['a'] = 'b'
+ obj1.map {|k, v| [k, v]}.should == [['a', 'b']]
+ obj1.k_v.should == ['a', 'b']
+
+ obj2 = cls2.new
+ obj2['a'] = 'b'
+ obj2.map {|k, v| [k, v]}.should == [['a', 'b']]
+ obj2.k_v.should == ['a', 'b']
+ end
end
diff --git a/spec/ruby/core/hash/each_spec.rb b/spec/ruby/core/hash/each_spec.rb
index 676fd284b9..1644b63216 100644
--- a/spec/ruby/core/hash/each_spec.rb
+++ b/spec/ruby/core/hash/each_spec.rb
@@ -1,11 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/iteration', __FILE__)
-require File.expand_path('../shared/each', __FILE__)
-require File.expand_path('../../enumerable/shared/enumeratorized', __FILE__)
+require_relative '../../spec_helper'
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 "is an alias of Hash#each_pair" do
+ Hash.instance_method(:each).should == Hash.instance_method(:each_pair)
+ end
end
diff --git a/spec/ruby/core/hash/each_value_spec.rb b/spec/ruby/core/hash/each_value_spec.rb
index d3b2b8692e..2df95a8789 100644
--- a/spec/ruby/core/hash/each_value_spec.rb
+++ b/spec/ruby/core/hash/each_value_spec.rb
@@ -1,13 +1,13 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/iteration', __FILE__)
-require File.expand_path('../../enumerable/shared/enumeratorized', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/iteration'
+require_relative '../enumerable/shared/enumeratorized'
describe "Hash#each_value" do
it "calls block once for each key, passing value" do
r = []
h = { a: -5, b: -3, c: -2, d: -1, e: -1 }
- h.each_value { |v| r << v }.should equal(h)
+ h.each_value { |v| r << v }.should.equal?(h)
r.sort.should == [-5, -3, -2, -1, -1]
end
@@ -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_reference_spec.rb b/spec/ruby/core/hash/element_reference_spec.rb
index b5ca56e84b..3d074b346d 100644
--- a/spec/ruby/core/hash/element_reference_spec.rb
+++ b/spec/ruby/core/hash/element_reference_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Hash#[]" do
it "returns the value for key" do
@@ -12,7 +12,7 @@ describe "Hash#[]" do
h[[]].should == "baz"
end
- it "returns nil as default default value" do
+ it "returns nil as default value" do
{ 0 => 0 }[5].should == nil
end
@@ -30,13 +30,13 @@ describe "Hash#[]" do
end
it "does not create copies of the immediate default value" do
- str = "foo"
+ str = +"foo"
h = Hash.new(str)
a = h[:a]
b = h[:b]
a << "bar"
- a.should equal(b)
+ a.should.equal?(b)
a.should == "foobar"
b.should == "foobar"
end
@@ -117,4 +117,18 @@ describe "Hash#[]" do
key = HashSpecs::KeyWithPrivateHash.new
{ key => 42 }[key].should == 42
end
+
+ it "does not dispatch to hash for Boolean, Integer, Float, String, or Symbol" do
+ code = <<-EOC
+ load '#{fixture __FILE__, "name.rb"}'
+ hash = { true => 42, false => 42, 1 => 42, 2.0 => 42, "hello" => 42, :ok => 42 }
+ [true, false, 1, 2.0, "hello", :ok].each do |value|
+ raise "incorrect value" unless hash[value] == 42
+ end
+ puts "Ok."
+ EOC
+ result = ruby_exe(code, args: "2>&1")
+ result.should == "Ok.\n"
+ end
+
end
diff --git a/spec/ruby/core/hash/element_set_spec.rb b/spec/ruby/core/hash/element_set_spec.rb
index a2d67c7f22..bb805477ca 100644
--- a/spec/ruby/core/hash/element_set_spec.rb
+++ b/spec/ruby/core/hash/element_set_spec.rb
@@ -1,7 +1,121 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/store', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Hash#[]=" do
- it_behaves_like(:hash_store, :[]=)
+ it "associates the key with the value" do
+ h = { a: 1 }
+ h[:b] = 2
+ h.should == { b:2, a:1 }
+ end
+
+ it "returns the assigned value" do
+ h = {}
+ h.send(:[]=, 1, 2).should == 2
+ end
+
+ it "duplicates string keys using dup semantics" do
+ # dup doesn't copy singleton methods
+ key = +"foo"
+ def key.reverse() "bar" end
+ h = {}
+ h[key] = 0
+ h.keys[0].reverse.should == "oof"
+ end
+
+ it "stores unequal keys that hash to the same value" do
+ h = {}
+ k1 = ["x"]
+ k2 = ["y"]
+ # So they end up in the same bucket
+ k1.should_receive(:hash).and_return(0)
+ k2.should_receive(:hash).and_return(0)
+
+ h[k1] = 1
+ h[k2] = 2
+ h.size.should == 2
+ end
+
+ it "accepts keys with private #hash method" do
+ key = HashSpecs::KeyWithPrivateHash.new
+ h = {}
+ h[key] = "foo"
+ h[key].should == "foo"
+ end
+
+ it " accepts keys with an Integer hash" do
+ o = mock(hash: 1 << 100)
+ h = {}
+ h[o] = 1
+ h[o].should == 1
+ end
+
+ it "duplicates and freezes string keys" do
+ key = +"foo"
+ h = {}
+ h[key] = 0
+ key << "bar"
+
+ h.should == { "foo" => 0 }
+ h.keys[0].should.frozen?
+ end
+
+ it "doesn't duplicate and freeze already frozen string keys" do
+ key = "foo".freeze
+ h = {}
+ h[key] = 0
+ h.keys[0].should.equal?(key)
+ end
+
+ it "keeps the existing key in the hash if there is a matching one" do
+ h = { "a" => 1, "b" => 2, "c" => 3, "d" => 4 }
+ key1 = HashSpecs::ByValueKey.new(13)
+ key2 = HashSpecs::ByValueKey.new(13)
+ h[key1] = 41
+ key_in_hash = h.keys.last
+ key_in_hash.should.equal?(key1)
+ h[key2] = 42
+ last_key = h.keys.last
+ last_key.should.equal?(key_in_hash)
+ last_key.should_not.equal?(key2)
+ end
+
+ it "keeps the existing String key in the hash if there is a matching one" do
+ h = { "a" => 1, "b" => 2, "c" => 3, "d" => 4 }
+ key1 = "foo".dup
+ key2 = "foo".dup
+ key1.should_not.equal?(key2)
+ h[key1] = 41
+ frozen_key = h.keys.last
+ frozen_key.should_not.equal?(key1)
+ h[key2] = 42
+ h.keys.last.should.equal?(frozen_key)
+ h.keys.last.should_not.equal?(key2)
+ end
+
+ it "raises a FrozenError if called on a frozen instance" do
+ -> { HashSpecs.frozen_hash[1] = 2 }.should.raise(FrozenError)
+ end
+
+ it "does not raise an exception if changing the value of an existing key during iteration" do
+ hash = {1 => 2, 3 => 4, 5 => 6}
+ hash.each { hash[1] = :foo }
+ hash.should == {1 => :foo, 3 => 4, 5 => 6}
+ end
+
+ it "does not dispatch to hash for Boolean, Integer, Float, String, or Symbol" do
+ code = <<-EOC
+ load '#{fixture __FILE__, "name.rb"}'
+ hash = {}
+ [true, false, 1, 2.0, "hello", :ok].each do |value|
+ hash[value] = 42
+ raise "incorrect value" unless hash[value] == 42
+ hash[value] = 43
+ raise "incorrect value" unless hash[value] == 43
+ end
+ puts "OK"
+ puts hash.size
+ EOC
+ result = ruby_exe(code, args: "2>&1")
+ result.should == "OK\n6\n"
+ end
end
diff --git a/spec/ruby/core/hash/empty_spec.rb b/spec/ruby/core/hash/empty_spec.rb
index 84464f34e1..881e1cc34b 100644
--- a/spec/ruby/core/hash/empty_spec.rb
+++ b/spec/ruby/core/hash/empty_spec.rb
@@ -1,15 +1,15 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Hash#empty?" do
it "returns true if the hash has no entries" do
- {}.empty?.should == true
- { 1 => 1 }.empty?.should == false
+ {}.should.empty?
+ { 1 => 1 }.should_not.empty?
end
it "returns true if the hash has no entries and has a default value" do
- Hash.new(5).empty?.should == true
- Hash.new { 5 }.empty?.should == true
- Hash.new { |hsh, k| hsh[k] = k }.empty?.should == true
+ Hash.new(5).should.empty?
+ Hash.new { 5 }.should.empty?
+ Hash.new { |hsh, k| hsh[k] = k }.should.empty?
end
end
diff --git a/spec/ruby/core/hash/eql_spec.rb b/spec/ruby/core/hash/eql_spec.rb
index 3e22bf1c67..9013e12ffd 100644
--- a/spec/ruby/core/hash/eql_spec.rb
+++ b/spec/ruby/core/hash/eql_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/eql', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/eql'
describe "Hash#eql?" do
it_behaves_like :hash_eql, :eql?
diff --git a/spec/ruby/core/hash/equal_value_spec.rb b/spec/ruby/core/hash/equal_value_spec.rb
index 76e4d796aa..ab14f81489 100644
--- a/spec/ruby/core/hash/equal_value_spec.rb
+++ b/spec/ruby/core/hash/equal_value_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/eql', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/eql'
describe "Hash#==" do
it_behaves_like :hash_eql, :==
@@ -13,6 +13,6 @@ describe "Hash#==" do
l_val.should_receive(:==).with(r_val).and_return(true)
- ({ 1 => l_val } == { 1 => r_val }).should be_true
+ ({ 1 => l_val } == { 1 => r_val }).should == true
end
end
diff --git a/spec/ruby/core/hash/except_spec.rb b/spec/ruby/core/hash/except_spec.rb
new file mode 100644
index 0000000000..77a020e9b7
--- /dev/null
+++ b/spec/ruby/core/hash/except_spec.rb
@@ -0,0 +1,42 @@
+require_relative '../../spec_helper'
+
+describe "Hash#except" do
+ before :each do
+ @hash = { a: 1, b: 2, c: 3 }
+ end
+
+ it "returns a new duplicate hash without arguments" do
+ ret = @hash.except
+ ret.should_not.equal?(@hash)
+ ret.should == @hash
+ end
+
+ it "returns a hash without the requested subset" do
+ @hash.except(:c, :a).should == { b: 2 }
+ end
+
+ it "ignores keys not present in the original hash" do
+ @hash.except(:a, :chunky_bacon).should == { b: 2, c: 3 }
+ end
+
+ it "does not retain the default value" do
+ h = Hash.new(1)
+ h.except(:a).default.should == nil
+ h[:a] = 1
+ h.except(:a).default.should == nil
+ end
+
+ it "does not retain the default_proc" do
+ pr = proc { |h, k| h[k] = [] }
+ h = Hash.new(&pr)
+ h.except(:a).default_proc.should == nil
+ h[:a] = 1
+ h.except(:a).default_proc.should == nil
+ end
+
+ it "retains compare_by_identity flag" do
+ h = { a: 9, c: 4 }.compare_by_identity
+ h2 = h.except(:a)
+ h2.compare_by_identity?.should == true
+ end
+end
diff --git a/spec/ruby/core/hash/fetch_spec.rb b/spec/ruby/core/hash/fetch_spec.rb
index 5e701b1162..f9b80b6c49 100644
--- a/spec/ruby/core/hash/fetch_spec.rb
+++ b/spec/ruby/core/hash/fetch_spec.rb
@@ -1,15 +1,23 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative '../../shared/hash/key_error'
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)
+
+ it "formats the object with #inspect in the KeyError message" do
+ -> {
+ {}.fetch('foo')
+ }.should.raise(KeyError, 'key not found: "foo"')
+ end
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
@@ -23,14 +31,14 @@ describe "Hash#fetch" do
end
it "gives precedence to the default block over the default argument when passed both" do
- lambda {
+ -> {
@result = {}.fetch(9, :foo) { |i| i * i }
}.should complain(/block supersedes default value argument/)
@result.should == 81
end
it "raises an ArgumentError when not passed one or two arguments" do
- lambda { {}.fetch() }.should raise_error(ArgumentError)
- lambda { {}.fetch(1, 2, 3) }.should raise_error(ArgumentError)
+ -> { {}.fetch() }.should.raise(ArgumentError)
+ -> { {}.fetch(1, 2, 3) }.should.raise(ArgumentError)
end
end
diff --git a/spec/ruby/core/hash/fetch_values_spec.rb b/spec/ruby/core/hash/fetch_values_spec.rb
index d6e47d5885..0cd48565af 100644
--- a/spec/ruby/core/hash/fetch_values_spec.rb
+++ b/spec/ruby/core/hash/fetch_values_spec.rb
@@ -1,35 +1,35 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative '../../shared/hash/key_error'
-ruby_version_is "2.3" do
- describe "Hash#fetch_values" do
- before :each do
- @hash = { a: 1, b: 2, c: 3 }
+describe "Hash#fetch_values" do
+ before :each do
+ @hash = { a: 1, b: 2, c: 3 }
+ end
+
+ describe "with matched keys" do
+ it "returns the values for keys" do
+ @hash.fetch_values(:a).should == [1]
+ @hash.fetch_values(:a, :c).should == [1, 3]
end
- describe "with matched keys" do
- it "returns the values for keys" do
- @hash.fetch_values(:a).should == [1]
- @hash.fetch_values(:a, :c).should == [1, 3]
- end
+ it "returns the values for keys ordered in the order of the requested keys" do
+ @hash.fetch_values(:c, :a).should == [3, 1]
end
+ 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
+ describe "with unmatched keys" do
+ 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"]
- @hash.fetch_values(:a, :z) { |key| "`#{key}' is not found" }.should == [1, "`z' is not found"]
- end
+ it "returns the default value from block" do
+ @hash.fetch_values(:z) { |key| "`#{key}' is not found" }.should == ["`z' is not found"]
+ @hash.fetch_values(:a, :z) { |key| "`#{key}' is not found" }.should == [1, "`z' is not found"]
end
+ end
- describe "without keys" do
- it "returns an empty Array" do
- @hash.fetch_values.should == []
- end
+ describe "without keys" do
+ it "returns an empty Array" do
+ @hash.fetch_values.should == []
end
end
end
diff --git a/spec/ruby/core/hash/filter_spec.rb b/spec/ruby/core/hash/filter_spec.rb
new file mode 100644
index 0000000000..625a7feb90
--- /dev/null
+++ b/spec/ruby/core/hash/filter_spec.rb
@@ -0,0 +1,13 @@
+require_relative '../../spec_helper'
+
+describe "Hash#filter" do
+ it "is an alias of Hash#select" do
+ Hash.instance_method(:filter).should == Hash.instance_method(:select)
+ end
+end
+
+describe "Hash#filter!" do
+ it "is an alias of Hash#select!" do
+ Hash.instance_method(:filter!).should == Hash.instance_method(:select!)
+ end
+end
diff --git a/spec/ruby/core/hash/fixtures/classes.rb b/spec/ruby/core/hash/fixtures/classes.rb
index 3d3df576cf..ae907aaff6 100644
--- a/spec/ruby/core/hash/fixtures/classes.rb
+++ b/spec/ruby/core/hash/fixtures/classes.rb
@@ -17,6 +17,13 @@ module HashSpecs
end
end
+ class SubHashSettingInInitialize < Hash
+ def initialize(*args, &block)
+ self[:foo] = :bar
+ super(*args, &block)
+ end
+ end
+
class DefaultHash < Hash
def default(key)
100
diff --git a/spec/ruby/core/hash/fixtures/name.rb b/spec/ruby/core/hash/fixtures/name.rb
new file mode 100644
index 0000000000..b203bf6ae4
--- /dev/null
+++ b/spec/ruby/core/hash/fixtures/name.rb
@@ -0,0 +1,30 @@
+class TrueClass
+ def hash
+ raise "TrueClass#hash should not be called"
+ end
+end
+class FalseClass
+ def hash
+ raise "FalseClass#hash should not be called"
+ end
+end
+class Integer
+ def hash
+ raise "Integer#hash should not be called"
+ end
+end
+class Float
+ def hash
+ raise "Float#hash should not be called"
+ end
+end
+class String
+ def hash
+ raise "String#hash should not be called"
+ end
+end
+class Symbol
+ def hash
+ raise "Symbol#hash should not be called"
+ end
+end
diff --git a/spec/ruby/core/hash/flatten_spec.rb b/spec/ruby/core/hash/flatten_spec.rb
index 60762f864d..18e9a7b56a 100644
--- a/spec/ruby/core/hash/flatten_spec.rb
+++ b/spec/ruby/core/hash/flatten_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Hash#flatten" do
@@ -9,7 +9,7 @@ describe "Hash#flatten" do
end
it "returns an Array" do
- {}.flatten.should be_an_instance_of(Array)
+ {}.flatten.should.instance_of?(Array)
end
it "returns an empty Array for an empty Hash" do
@@ -55,8 +55,8 @@ describe "Hash#flatten" do
end
it "raises a TypeError if given a non-Integer argument" do
- lambda do
+ -> do
@h.flatten(Object.new)
- end.should raise_error(TypeError)
+ end.should.raise(TypeError)
end
end
diff --git a/spec/ruby/core/hash/gt_spec.rb b/spec/ruby/core/hash/gt_spec.rb
index 35bf52bf64..69d23b7d29 100644
--- a/spec/ruby/core/hash/gt_spec.rb
+++ b/spec/ruby/core/hash/gt_spec.rb
@@ -1,44 +1,42 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/comparison', __FILE__)
-require File.expand_path('../shared/greater_than', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/comparison'
+require_relative 'shared/greater_than'
-ruby_version_is "2.3" do
- describe "Hash#>" do
- it_behaves_like :hash_comparison, :>
- it_behaves_like :hash_greater_than, :>
+describe "Hash#>" do
+ it_behaves_like :hash_comparison, :>
+ it_behaves_like :hash_greater_than, :>
- it "returns false if both hashes are identical" do
- h = { a: 1, b: 2 }
- (h > h).should be_false
- end
+ it "returns false if both hashes are identical" do
+ h = { a: 1, b: 2 }
+ (h > h).should == false
end
+end
- describe "Hash#>" do
- before :each do
- @hash = {a:1, b:2}
- @bigger = {a:1, b:2, c:3}
- @unrelated = {c:3, d:4}
- @similar = {a:2, b:3}
- end
+describe "Hash#>" do
+ before :each do
+ @hash = {a:1, b:2}
+ @bigger = {a:1, b:2, c:3}
+ @unrelated = {c:3, d:4}
+ @similar = {a:2, b:3}
+ end
- it "returns false when receiver size is smaller than argument" do
- (@hash > @bigger).should == false
- (@unrelated > @bigger).should == false
- end
+ it "returns false when receiver size is smaller than argument" do
+ (@hash > @bigger).should == false
+ (@unrelated > @bigger).should == false
+ end
- it "returns false when receiver size is the same as argument" do
- (@hash > @hash).should == false
- (@hash > @unrelated).should == false
- (@unrelated > @hash).should == false
- end
+ it "returns false when receiver size is the same as argument" do
+ (@hash > @hash).should == false
+ (@hash > @unrelated).should == false
+ (@unrelated > @hash).should == false
+ end
- it "returns true when argument is a subset of receiver" do
- (@bigger > @hash).should == true
- end
+ it "returns true when argument is a subset of receiver" do
+ (@bigger > @hash).should == true
+ end
- it "returns false when keys match but values don't" do
- (@hash > @similar).should == false
- (@similar > @hash).should == false
- end
+ it "returns false when keys match but values don't" do
+ (@hash > @similar).should == false
+ (@similar > @hash).should == false
end
end
diff --git a/spec/ruby/core/hash/gte_spec.rb b/spec/ruby/core/hash/gte_spec.rb
index 5453440ed6..be5060ea4f 100644
--- a/spec/ruby/core/hash/gte_spec.rb
+++ b/spec/ruby/core/hash/gte_spec.rb
@@ -1,44 +1,42 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/comparison', __FILE__)
-require File.expand_path('../shared/greater_than', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/comparison'
+require_relative 'shared/greater_than'
-ruby_version_is "2.3" do
- describe "Hash#>=" do
- it_behaves_like :hash_comparison, :>=
- it_behaves_like :hash_greater_than, :>=
+describe "Hash#>=" do
+ it_behaves_like :hash_comparison, :>=
+ it_behaves_like :hash_greater_than, :>=
- it "returns true if both hashes are identical" do
- h = { a: 1, b: 2 }
- (h >= h).should be_true
- end
+ it "returns true if both hashes are identical" do
+ h = { a: 1, b: 2 }
+ (h >= h).should == true
end
+end
- describe "Hash#>=" do
- before :each do
- @hash = {a:1, b:2}
- @bigger = {a:1, b:2, c:3}
- @unrelated = {c:3, d:4}
- @similar = {a:2, b:3}
- end
+describe "Hash#>=" do
+ before :each do
+ @hash = {a:1, b:2}
+ @bigger = {a:1, b:2, c:3}
+ @unrelated = {c:3, d:4}
+ @similar = {a:2, b:3}
+ end
- it "returns false when receiver size is smaller than argument" do
- (@hash >= @bigger).should == false
- (@unrelated >= @bigger).should == false
- end
+ it "returns false when receiver size is smaller than argument" do
+ (@hash >= @bigger).should == false
+ (@unrelated >= @bigger).should == false
+ end
- it "returns false when argument is not a subset or not equals to receiver" do
- (@hash >= @unrelated).should == false
- (@unrelated >= @hash).should == false
- end
+ it "returns false when argument is not a subset or not equals to receiver" do
+ (@hash >= @unrelated).should == false
+ (@unrelated >= @hash).should == false
+ end
- it "returns true when argument is a subset of receiver or equals to receiver" do
- (@bigger >= @hash).should == true
- (@hash >= @hash).should == true
- end
+ it "returns true when argument is a subset of receiver or equals to receiver" do
+ (@bigger >= @hash).should == true
+ (@hash >= @hash).should == true
+ end
- it "returns false when keys match but values don't" do
- (@hash >= @similar).should == false
- (@similar >= @hash).should == false
- end
+ it "returns false when keys match but values don't" do
+ (@hash >= @similar).should == false
+ (@similar >= @hash).should == false
end
end
diff --git a/spec/ruby/core/hash/has_key_spec.rb b/spec/ruby/core/hash/has_key_spec.rb
index 1d2aa279f1..9a6244c6f6 100644
--- a/spec/ruby/core/hash/has_key_spec.rb
+++ b/spec/ruby/core/hash/has_key_spec.rb
@@ -1,8 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/key', __FILE__)
+require_relative '../../spec_helper'
describe "Hash#has_key?" do
- it_behaves_like(:hash_key_p, :has_key?)
+ it "is an alias of Hash#include?" do
+ Hash.instance_method(:has_key?).should == Hash.instance_method(:include?)
+ end
end
-
diff --git a/spec/ruby/core/hash/has_value_spec.rb b/spec/ruby/core/hash/has_value_spec.rb
index dc8fdf9b69..95b8390a66 100644
--- a/spec/ruby/core/hash/has_value_spec.rb
+++ b/spec/ruby/core/hash/has_value_spec.rb
@@ -1,8 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/value', __FILE__)
+require_relative '../../spec_helper'
describe "Hash#has_value?" do
- it_behaves_like(:hash_value_p, :has_value?)
+ it "is an alias of Hash#value?" do
+ Hash.instance_method(:has_value?).should == Hash.instance_method(:value?)
+ end
end
-
diff --git a/spec/ruby/core/hash/hash_spec.rb b/spec/ruby/core/hash/hash_spec.rb
index 9d1e984c60..cd67f7a652 100644
--- a/spec/ruby/core/hash/hash_spec.rb
+++ b/spec/ruby/core/hash/hash_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Hash" do
it "includes Enumerable" do
@@ -11,6 +11,14 @@ describe "Hash#hash" do
{ 0=>2, 11=>1 }.hash.should == { 11=>1, 0=>2 }.hash
end
+ it "returns a value in which element values do not cancel each other out" do
+ { a: 2, b: 2 }.hash.should_not == { a: 7, b: 7 }.hash
+ end
+
+ it "returns a value in which element keys and values do not cancel each other out" do
+ { :a => :a }.hash.should_not == { :b => :b }.hash
+ end
+
it "generates a hash for recursive hash structures" do
h = {}
h[:a] = h
@@ -33,4 +41,11 @@ describe "Hash#hash" do
h.hash.should == {x: [h]}.hash
# Like above, because h.eql?(x: [h])
end
+
+ it "allows omitting values" do
+ a = 1
+ b = 2
+
+ {a:, b:}.should == { a: 1, b: 2 }
+ end
end
diff --git a/spec/ruby/core/hash/include_spec.rb b/spec/ruby/core/hash/include_spec.rb
index 8731673c19..1c32e9fb23 100644
--- a/spec/ruby/core/hash/include_spec.rb
+++ b/spec/ruby/core/hash/include_spec.rb
@@ -1,7 +1,40 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/key', __FILE__)
+require_relative '../../spec_helper'
describe "Hash#include?" do
- it_behaves_like(:hash_key_p, :include?)
+ it "returns true if argument is a key" do
+ h = { a: 1, b: 2, c: 3, 4 => 0 }
+ h.include?(:a).should == true
+ h.include?(:b).should == true
+ h.include?(2).should == false
+ h.include?(4).should == true
+
+ not_supported_on :opal do
+ h.include?('b').should == false
+ h.include?(4.0).should == false
+ end
+ end
+
+ it "returns true if the key's matching value was nil" do
+ { xyz: nil }.include?(:xyz).should == true
+ end
+
+ it "returns true if the key's matching value was false" do
+ { xyz: false }.include?(:xyz).should == true
+ end
+
+ it "returns true if the key is nil" do
+ { nil => 'b' }.include?(nil).should == true
+ { nil => nil }.include?(nil).should == true
+ end
+
+ it "compares keys with the same #hash value via #eql?" do
+ x = mock('x')
+ x.stub!(:hash).and_return(42)
+
+ y = mock('y')
+ y.stub!(:hash).and_return(42)
+ y.should_receive(:eql?).and_return(false)
+
+ { x => nil }.include?(y).should == false
+ end
end
diff --git a/spec/ruby/core/hash/index_spec.rb b/spec/ruby/core/hash/index_spec.rb
deleted file mode 100644
index 28e64f4eb8..0000000000
--- a/spec/ruby/core/hash/index_spec.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/index', __FILE__)
-
-describe "Hash#index" do
- it_behaves_like :hash_index, :index
-end
diff --git a/spec/ruby/core/hash/initialize_spec.rb b/spec/ruby/core/hash/initialize_spec.rb
index aa943d333d..cdba598813 100644
--- a/spec/ruby/core/hash/initialize_spec.rb
+++ b/spec/ruby/core/hash/initialize_spec.rb
@@ -1,40 +1,61 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Hash#initialize" do
it "is private" do
- Hash.should have_private_instance_method("initialize")
+ Hash.private_instance_methods(false).should.include?(:initialize)
end
it "can be used to reset default_proc" do
h = { "foo" => 1, "bar" => 2 }
h.default_proc.should == nil
- h.instance_eval { initialize { |_, k| k * 2 } }
+ h.send(:initialize) { |_, k| k * 2 }
h.default_proc.should_not == nil
h["a"].should == "aa"
end
+ it "can be used to reset the default value" do
+ h = {}
+ h.default = 42
+ h.default.should == 42
+ h.send(:initialize, 1)
+ h.default.should == 1
+ h.send(:initialize)
+ h.default.should == nil
+ end
+
it "receives the arguments passed to Hash#new" do
HashSpecs::NewHash.new(:one, :two)[0].should == :one
HashSpecs::NewHash.new(:one, :two)[1].should == :two
end
+ it "does not change the storage, only the default value or proc" do
+ h = HashSpecs::SubHashSettingInInitialize.new
+ h.to_a.should == [[:foo, :bar]]
+
+ h = HashSpecs::SubHashSettingInInitialize.new(:default)
+ h.to_a.should == [[:foo, :bar]]
+
+ h = HashSpecs::SubHashSettingInInitialize.new { :default_block }
+ h.to_a.should == [[:foo, :bar]]
+ end
+
it "returns self" do
h = Hash.new
- h.send(:initialize).should equal(h)
+ h.send(:initialize).should.equal?(h)
end
- it "raises a RuntimeError if called on a frozen instance" do
- block = lambda { HashSpecs.frozen_hash.instance_eval { initialize() }}
- block.should raise_error(RuntimeError)
+ it "raises a FrozenError if called on a frozen instance" do
+ block = -> { HashSpecs.frozen_hash.instance_eval { initialize() }}
+ block.should.raise(FrozenError)
- block = lambda { HashSpecs.frozen_hash.instance_eval { initialize(nil) } }
- block.should raise_error(RuntimeError)
+ block = -> { HashSpecs.frozen_hash.instance_eval { initialize(nil) } }
+ block.should.raise(FrozenError)
- block = lambda { HashSpecs.frozen_hash.instance_eval { initialize(5) } }
- block.should raise_error(RuntimeError)
+ block = -> { HashSpecs.frozen_hash.instance_eval { initialize(5) } }
+ block.should.raise(FrozenError)
- block = lambda { HashSpecs.frozen_hash.instance_eval { initialize { 5 } } }
- block.should raise_error(RuntimeError)
+ block = -> { HashSpecs.frozen_hash.instance_eval { initialize { 5 } } }
+ block.should.raise(FrozenError)
end
end
diff --git a/spec/ruby/core/hash/inspect_spec.rb b/spec/ruby/core/hash/inspect_spec.rb
index b8c42cf269..359b13360f 100644
--- a/spec/ruby/core/hash/inspect_spec.rb
+++ b/spec/ruby/core/hash/inspect_spec.rb
@@ -1,7 +1,123 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/to_s', __FILE__)
+require_relative '../../spec_helper'
describe "Hash#inspect" do
- it_behaves_like :hash_to_s, :inspect
+ it "returns a string representation with same order as each()" do
+ h = { a: [1, 2], b: -2, d: -6, nil => nil }
+ expected = ruby_version_is("3.4") ? "{a: [1, 2], b: -2, d: -6, nil => nil}" : "{:a=>[1, 2], :b=>-2, :d=>-6, nil=>nil}"
+ h.inspect.should == expected
+ end
+
+ it "calls #inspect on keys and values" do
+ key = mock('key')
+ val = mock('val')
+ key.should_receive(:inspect).and_return('key')
+ val.should_receive(:inspect).and_return('val')
+ expected = ruby_version_is("3.4") ? "{key => val}" : "{key=>val}"
+ { key => val }.inspect.should == expected
+ end
+
+ it "does not call #to_s on a String returned from #inspect" do
+ str = +"abc"
+ str.should_not_receive(:to_s)
+ expected = ruby_version_is("3.4") ? '{a: "abc"}' : '{:a=>"abc"}'
+ { a: str }.inspect.should == expected
+ end
+
+ it "calls #to_s on the object returned from #inspect if the Object isn't a String" do
+ obj = mock("Hash#inspect/to_s calls #to_s")
+ obj.should_receive(:inspect).and_return(obj)
+ obj.should_receive(:to_s).and_return("abc")
+ expected = ruby_version_is("3.4") ? "{a: abc}" : "{:a=>abc}"
+ { a: obj }.inspect.should == expected
+ end
+
+ it "does not call #to_str on the object returned from #inspect when it is not a String" do
+ obj = mock("Hash#inspect/to_s does not call #to_str")
+ obj.should_receive(:inspect).and_return(obj)
+ obj.should_not_receive(:to_str)
+ expected_pattern = ruby_version_is("3.4") ? /^\{a: #<MockObject:0x[0-9a-f]+>\}$/ : /^\{:a=>#<MockObject:0x[0-9a-f]+>\}$/
+ { a: obj }.inspect.should =~ expected_pattern
+ end
+
+ it "does not call #to_str on the object returned from #to_s when it is not a String" do
+ obj = mock("Hash#inspect/to_s does not call #to_str on #to_s result")
+ obj.should_receive(:inspect).and_return(obj)
+ obj.should_receive(:to_s).and_return(obj)
+ obj.should_not_receive(:to_str)
+ expected_pattern = ruby_version_is("3.4") ? /^\{a: #<MockObject:0x[0-9a-f]+>\}$/ : /^\{:a=>#<MockObject:0x[0-9a-f]+>\}$/
+ { a: obj }.inspect.should =~ expected_pattern
+ end
+
+ it "does not swallow exceptions raised by #to_s" do
+ obj = mock("Hash#inspect/to_s does not swallow #to_s exceptions")
+ obj.should_receive(:inspect).and_return(obj)
+ obj.should_receive(:to_s).and_raise(Exception)
+
+ -> { { a: obj }.inspect }.should.raise(Exception)
+ end
+
+ it "handles hashes with recursive values" do
+ x = {}
+ x[0] = x
+ expected = ruby_version_is("3.4") ? '{0 => {...}}' : '{0=>{...}}'
+ x.inspect.should == expected
+
+ x = {}
+ y = {}
+ x[0] = y
+ y[1] = x
+ expected_x = ruby_version_is("3.4") ? '{0 => {1 => {...}}}' : '{0=>{1=>{...}}}'
+ expected_y = ruby_version_is("3.4") ? '{1 => {0 => {...}}}' : '{1=>{0=>{...}}}'
+ x.inspect.should == expected_x
+ y.inspect.should == expected_y
+ end
+
+ it "does not raise if inspected result is not default external encoding" do
+ utf_16be = mock("utf_16be")
+ utf_16be.should_receive(:inspect).and_return(%<"utf_16be \u3042">.encode(Encoding::UTF_16BE))
+ expected = ruby_version_is("3.4") ? '{a: "utf_16be \u3042"}' : '{:a=>"utf_16be \u3042"}'
+ {a: utf_16be}.inspect.should == expected
+ end
+
+ it "works for keys and values whose #inspect return a frozen String" do
+ expected = ruby_version_is("3.4") ? "{true => false}" : "{true=>false}"
+ { true => false }.inspect.should == expected
+ end
+
+ ruby_version_is "3.4" do
+ it "adds quotes to symbol keys that are not valid symbol literals" do
+ { "needs-quotes": 1 }.inspect.should == '{"needs-quotes": 1}'
+ end
+
+ it "can be evaled" do
+ no_quote = '{a: 1, a!: 1, a?: 1}'
+ eval(no_quote).inspect.should == no_quote
+ [
+ '{"": 1}',
+ '{"0": 1, "!": 1, "%": 1, "&": 1, "*": 1, "+": 1, "-": 1, "/": 1, "<": 1, ">": 1, "^": 1, "`": 1, "|": 1, "~": 1}',
+ '{"@a": 1, "$a": 1, "+@": 1, "a=": 1, "[]": 1}',
+ '{"a\"b": 1, "@@a": 1, "<=>": 1, "===": 1, "[]=": 1}',
+ ].each do |quote|
+ eval(quote).inspect.should == quote
+ end
+ end
+
+ it "can be evaled when Encoding.default_external is changed" do
+ external = Encoding.default_external
+
+ Encoding.default_external = Encoding::ASCII
+ utf8_ascii_hash = '{"\\u3042": 1}'
+ eval(utf8_ascii_hash).inspect.should == utf8_ascii_hash
+
+ Encoding.default_external = Encoding::UTF_8
+ utf8_hash = "{\u3042: 1}"
+ eval(utf8_hash).inspect.should == utf8_hash
+
+ Encoding.default_external = Encoding::Windows_31J
+ sjis_hash = "{\x87]: 1}".dup.force_encoding('sjis')
+ eval(sjis_hash).inspect.should == sjis_hash
+ ensure
+ Encoding.default_external = external
+ end
+ end
end
diff --git a/spec/ruby/core/hash/invert_spec.rb b/spec/ruby/core/hash/invert_spec.rb
index bc2bf711f7..ea441751f2 100644
--- a/spec/ruby/core/hash/invert_spec.rb
+++ b/spec/ruby/core/hash/invert_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Hash#invert" do
it "returns a new hash where keys are values and vice versa" do
@@ -24,4 +24,25 @@ describe "Hash#invert" do
HashSpecs::MyHash[1 => 2, 3 => 4].invert.class.should == Hash
HashSpecs::MyHash[].invert.class.should == Hash
end
+
+ it "does not retain the default value" do
+ h = Hash.new(1)
+ h.invert.default.should == nil
+ h[:a] = 1
+ h.invert.default.should == nil
+ end
+
+ it "does not retain the default_proc" do
+ pr = proc { |h, k| h[k] = [] }
+ h = Hash.new(&pr)
+ h.invert.default_proc.should == nil
+ h[:a] = 1
+ h.invert.default_proc.should == nil
+ end
+
+ it "does not retain compare_by_identity flag" do
+ h = { a: 9, c: 4 }.compare_by_identity
+ h2 = h.invert
+ h2.compare_by_identity?.should == false
+ end
end
diff --git a/spec/ruby/core/hash/keep_if_spec.rb b/spec/ruby/core/hash/keep_if_spec.rb
index 6b3a1925d3..c975efc5f8 100644
--- a/spec/ruby/core/hash/keep_if_spec.rb
+++ b/spec/ruby/core/hash/keep_if_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/iteration', __FILE__)
-require File.expand_path('../../enumerable/shared/enumeratorized', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/iteration'
+require_relative '../enumerable/shared/enumeratorized'
describe "Hash#keep_if" do
it "yields two arguments: key and value" do
@@ -12,26 +12,26 @@ describe "Hash#keep_if" do
it "keeps every entry for which block is true and returns self" do
h = { a: 1, b: 2, c: 3, d: 4 }
- h.keep_if { |k,v| v % 2 == 0 }.should equal(h)
+ h.keep_if { |k,v| v % 2 == 0 }.should.equal?(h)
h.should == { b: 2, d: 4 }
end
it "removes all entries if the block is false" do
h = { a: 1, b: 2, c: 3 }
- h.keep_if { |k,v| false }.should equal(h)
+ h.keep_if { |k,v| false }.should.equal?(h)
h.should == {}
end
it "returns self even if unmodified" do
h = { 1 => 2, 3 => 4 }
- h.keep_if { true }.should equal(h)
+ h.keep_if { true }.should.equal?(h)
end
- it "raises a RuntimeError if called on a frozen instance" do
- lambda { HashSpecs.frozen_hash.keep_if { true } }.should raise_error(RuntimeError)
- lambda { HashSpecs.empty_frozen_hash.keep_if { false } }.should raise_error(RuntimeError)
+ it "raises a FrozenError if called on a frozen instance" do
+ -> { HashSpecs.frozen_hash.keep_if { true } }.should.raise(FrozenError)
+ -> { HashSpecs.empty_frozen_hash.keep_if { false } }.should.raise(FrozenError)
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..c2d7049aed 100644
--- a/spec/ruby/core/hash/key_spec.rb
+++ b/spec/ruby/core/hash/key_spec.rb
@@ -1,12 +1,32 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/key', __FILE__)
-require File.expand_path('../shared/index', __FILE__)
+require_relative '../../spec_helper'
describe "Hash#key?" do
- it_behaves_like(:hash_key_p, :key?)
+ it "is an alias of Hash#include?" do
+ Hash.instance_method(:key?).should == Hash.instance_method(:include?)
+ end
end
describe "Hash#key" do
- it_behaves_like(:hash_index, :key)
+ it "returns the corresponding key for value" do
+ { 2 => 'a', 1 => 'b' }.key('b').should == 1
+ end
+
+ it "returns nil if the value is not found" do
+ { a: -1, b: 3.14, c: 2.718 }.key(1).should == nil
+ end
+
+ it "doesn't return default value if the value is not found" do
+ Hash.new(5).key(5).should == nil
+ end
+
+ it "compares values using ==" do
+ { 1 => 0 }.key(0.0).should == 1
+ { 1 => 0.0 }.key(0).should == 1
+
+ needle = mock('needle')
+ inhash = mock('inhash')
+ inhash.should_receive(:==).with(needle).and_return(true)
+
+ { 1 => inhash }.key(needle).should == 1
+ end
end
diff --git a/spec/ruby/core/hash/keys_spec.rb b/spec/ruby/core/hash/keys_spec.rb
index bc7855f73b..789c413bee 100644
--- a/spec/ruby/core/hash/keys_spec.rb
+++ b/spec/ruby/core/hash/keys_spec.rb
@@ -1,15 +1,15 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Hash#keys" do
it "returns an array with the keys in the order they were inserted" do
{}.keys.should == []
- {}.keys.should be_kind_of(Array)
+ {}.keys.should.is_a?(Array)
Hash.new(5).keys.should == []
Hash.new { 5 }.keys.should == []
{ 1 => 2, 4 => 8, 2 => 4 }.keys.should == [1, 4, 2]
- { 1 => 2, 2 => 4, 4 => 8 }.keys.should be_kind_of(Array)
+ { 1 => 2, 2 => 4, 4 => 8 }.keys.should.is_a?(Array)
{ nil => nil }.keys.should == [nil]
end
diff --git a/spec/ruby/core/hash/length_spec.rb b/spec/ruby/core/hash/length_spec.rb
index 90751402eb..325973306f 100644
--- a/spec/ruby/core/hash/length_spec.rb
+++ b/spec/ruby/core/hash/length_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/length', __FILE__)
+require_relative '../../spec_helper'
describe "Hash#length" do
- it_behaves_like(:hash_length, :length)
+ it "is an alias of Hash#size" do
+ Hash.instance_method(:size).should == Hash.instance_method(:length)
+ end
end
diff --git a/spec/ruby/core/hash/lt_spec.rb b/spec/ruby/core/hash/lt_spec.rb
index c32af32017..4ca326d077 100644
--- a/spec/ruby/core/hash/lt_spec.rb
+++ b/spec/ruby/core/hash/lt_spec.rb
@@ -1,44 +1,42 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/comparison', __FILE__)
-require File.expand_path('../shared/less_than', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/comparison'
+require_relative 'shared/less_than'
-ruby_version_is "2.3" do
- describe "Hash#<" do
- it_behaves_like :hash_comparison, :<
- it_behaves_like :hash_less_than, :<
+describe "Hash#<" do
+ it_behaves_like :hash_comparison, :<
+ it_behaves_like :hash_less_than, :<
- it "returns false if both hashes are identical" do
- h = { a: 1, b: 2 }
- (h < h).should be_false
- end
+ it "returns false if both hashes are identical" do
+ h = { a: 1, b: 2 }
+ (h < h).should == false
end
+end
- describe "Hash#<" do
- before :each do
- @hash = {a:1, b:2}
- @bigger = {a:1, b:2, c:3}
- @unrelated = {c:3, d:4}
- @similar = {a:2, b:3}
- end
+describe "Hash#<" do
+ before :each do
+ @hash = {a:1, b:2}
+ @bigger = {a:1, b:2, c:3}
+ @unrelated = {c:3, d:4}
+ @similar = {a:2, b:3}
+ end
- it "returns false when receiver size is larger than argument" do
- (@bigger < @hash).should == false
- (@bigger < @unrelated).should == false
- end
+ it "returns false when receiver size is larger than argument" do
+ (@bigger < @hash).should == false
+ (@bigger < @unrelated).should == false
+ end
- it "returns false when receiver size is the same as argument" do
- (@hash < @hash).should == false
- (@hash < @unrelated).should == false
- (@unrelated < @hash).should == false
- end
+ it "returns false when receiver size is the same as argument" do
+ (@hash < @hash).should == false
+ (@hash < @unrelated).should == false
+ (@unrelated < @hash).should == false
+ end
- it "returns true when receiver is a subset of argument" do
- (@hash < @bigger).should == true
- end
+ it "returns true when receiver is a subset of argument" do
+ (@hash < @bigger).should == true
+ end
- it "returns false when keys match but values don't" do
- (@hash < @similar).should == false
- (@similar < @hash).should == false
- end
+ it "returns false when keys match but values don't" do
+ (@hash < @similar).should == false
+ (@similar < @hash).should == false
end
end
diff --git a/spec/ruby/core/hash/lte_spec.rb b/spec/ruby/core/hash/lte_spec.rb
index 1a6926a44a..29e60273d1 100644
--- a/spec/ruby/core/hash/lte_spec.rb
+++ b/spec/ruby/core/hash/lte_spec.rb
@@ -1,44 +1,42 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/comparison', __FILE__)
-require File.expand_path('../shared/less_than', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/comparison'
+require_relative 'shared/less_than'
-ruby_version_is "2.3" do
- describe "Hash#<=" do
- it_behaves_like :hash_comparison, :<=
- it_behaves_like :hash_less_than, :<=
+describe "Hash#<=" do
+ it_behaves_like :hash_comparison, :<=
+ it_behaves_like :hash_less_than, :<=
- it "returns true if both hashes are identical" do
- h = { a: 1, b: 2 }
- (h <= h).should be_true
- end
+ it "returns true if both hashes are identical" do
+ h = { a: 1, b: 2 }
+ (h <= h).should == true
end
+end
- describe "Hash#<=" do
- before :each do
- @hash = {a:1, b:2}
- @bigger = {a:1, b:2, c:3}
- @unrelated = {c:3, d:4}
- @similar = {a:2, b:3}
- end
+describe "Hash#<=" do
+ before :each do
+ @hash = {a:1, b:2}
+ @bigger = {a:1, b:2, c:3}
+ @unrelated = {c:3, d:4}
+ @similar = {a:2, b:3}
+ end
- it "returns false when receiver size is larger than argument" do
- (@bigger <= @hash).should == false
- (@bigger <= @unrelated).should == false
- end
+ it "returns false when receiver size is larger than argument" do
+ (@bigger <= @hash).should == false
+ (@bigger <= @unrelated).should == false
+ end
- it "returns false when receiver size is the same as argument" do
- (@hash <= @unrelated).should == false
- (@unrelated <= @hash).should == false
- end
+ it "returns false when receiver size is the same as argument" do
+ (@hash <= @unrelated).should == false
+ (@unrelated <= @hash).should == false
+ end
- it "returns true when receiver is a subset of argument or equals to argument" do
- (@hash <= @bigger).should == true
- (@hash <= @hash).should == true
- end
+ it "returns true when receiver is a subset of argument or equals to argument" do
+ (@hash <= @bigger).should == true
+ (@hash <= @hash).should == true
+ end
- it "returns false when keys match but values don't" do
- (@hash <= @similar).should == false
- (@similar <= @hash).should == false
- end
+ it "returns false when keys match but values don't" do
+ (@hash <= @similar).should == false
+ (@similar <= @hash).should == false
end
end
diff --git a/spec/ruby/core/hash/member_spec.rb b/spec/ruby/core/hash/member_spec.rb
index 376bb4c006..e7309c3f7d 100644
--- a/spec/ruby/core/hash/member_spec.rb
+++ b/spec/ruby/core/hash/member_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/key', __FILE__)
+require_relative '../../spec_helper'
describe "Hash#member?" do
- it_behaves_like(:hash_key_p, :member?)
+ it "is an alias of Hash#include?" do
+ Hash.instance_method(:member?).should == Hash.instance_method(:include?)
+ end
end
diff --git a/spec/ruby/core/hash/merge_spec.rb b/spec/ruby/core/hash/merge_spec.rb
index 21401ffd08..7a444f7f25 100644
--- a/spec/ruby/core/hash/merge_spec.rb
+++ b/spec/ruby/core/hash/merge_spec.rb
@@ -1,7 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/iteration', __FILE__)
-require File.expand_path('../shared/update', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Hash#merge" do
it "returns a new hash by combining self with the contents of other" do
@@ -28,9 +26,9 @@ describe "Hash#merge" do
r = h1.merge(h2) { |k,x,y| "#{k}:#{x+2*y}" }
r.should == { a: "a:-2", b: "b:9", c: -3, d: 5 }
- lambda {
+ -> {
h1.merge(h2) { |k, x, y| raise(IndexError) }
- }.should raise_error(IndexError)
+ }.should.raise(IndexError)
r = h1.merge(h1) { |k,x,y| :x }
r.should == { a: :x, b: :x, d: :x }
@@ -47,8 +45,8 @@ describe "Hash#merge" do
end
it "returns subclass instance for subclasses" do
- HashSpecs::MyHash[1 => 2, 3 => 4].merge({ 1 => 2 }).should be_an_instance_of(HashSpecs::MyHash)
- HashSpecs::MyHash[].merge({ 1 => 2 }).should be_an_instance_of(HashSpecs::MyHash)
+ HashSpecs::MyHash[1 => 2, 3 => 4].merge({ 1 => 2 }).should.instance_of?(HashSpecs::MyHash)
+ HashSpecs::MyHash[].merge({ 1 => 2 }).should.instance_of?(HashSpecs::MyHash)
{ 1 => 2, 3 => 4 }.merge(HashSpecs::MyHash[1 => 2]).class.should == Hash
{}.merge(HashSpecs::MyHash[1 => 2]).class.should == Hash
@@ -63,15 +61,134 @@ describe "Hash#merge" do
merge_pairs.should == each_pairs
end
+ it "preserves the order of merged elements" do
+ h1 = { 1 => 2, 3 => 4, 5 => 6 }
+ h2 = { 1 => 7 }
+ merge_pairs = []
+ h1.merge(h2).each_pair { |k, v| merge_pairs << [k, v] }
+ merge_pairs.should == [[1,7], [3, 4], [5, 6]]
+ end
+
+ it "preserves the order of merged elements for large hashes" do
+ h1 = {}
+ h2 = {}
+ merge_pairs = []
+ expected_pairs = []
+ (1..100).each { |x| h1[x] = x; h2[101 - x] = x; expected_pairs << [x, 101 - x] }
+ h1.merge(h2).each_pair { |k, v| merge_pairs << [k, v] }
+ merge_pairs.should == expected_pairs
+ end
+
+ it "accepts multiple hashes" do
+ result = { a: 1 }.merge({ b: 2 }, { c: 3 }, { d: 4 })
+ result.should == { a: 1, b: 2, c: 3, d: 4 }
+ end
+
+ it "accepts zero arguments and returns a copy of self" do
+ hash = { a: 1 }
+ merged = hash.merge
+
+ merged.should.eql?(hash)
+ merged.should_not.equal?(hash)
+ end
+
+ it "retains the default value" do
+ h = Hash.new(1)
+ h.merge(b: 1, d: 2).default.should == 1
+ end
+
+ it "retains the default_proc" do
+ pr = proc { |h, k| h[k] = [] }
+ h = Hash.new(&pr)
+ h.merge(b: 1, d: 2).default_proc.should == pr
+ end
+
+ it "retains compare_by_identity flag" do
+ h = { a: 9, c: 4 }.compare_by_identity
+ h2 = h.merge(b: 1, d: 2)
+ h2.compare_by_identity?.should == true
+ end
+
+ it "ignores compare_by_identity flag of an argument" do
+ h = { a: 9, c: 4 }.compare_by_identity
+ h2 = { b: 1, d: 2 }.merge(h)
+ h2.compare_by_identity?.should == false
+ end
end
describe "Hash#merge!" do
- it_behaves_like(:hash_update, :merge!)
+ it "adds the entries from other, overwriting duplicate keys. Returns self" do
+ h = { _1: 'a', _2: '3' }
+ h.merge!(_1: '9', _9: 2).should.equal?(h)
+ h.should == { _1: "9", _2: "3", _9: 2 }
+ end
+
+ it "sets any duplicate key to the value of block if passed a block" do
+ h1 = { a: 2, b: -1 }
+ h2 = { a: -2, c: 1 }
+ h1.merge!(h2) { |k,x,y| 3.14 }.should.equal?(h1)
+ h1.should == { c: 1, b: -1, a: 3.14 }
+
+ h1.merge!(h1) { nil }
+ h1.should == { a: nil, b: nil, c: nil }
+ end
+
+ it "tries to convert the passed argument to a hash using #to_hash" do
+ obj = mock('{1=>2}')
+ obj.should_receive(:to_hash).and_return({ 1 => 2 })
+ { 3 => 4 }.merge!(obj).should == { 1 => 2, 3 => 4 }
+ end
+
+ it "does not call to_hash on hash subclasses" do
+ { 3 => 4 }.merge!(HashSpecs::ToHashHash[1 => 2]).should == { 1 => 2, 3 => 4 }
+ end
+
+ it "processes entries with same order as merge()" do
+ h = { 1 => 2, 3 => 4, 5 => 6, "x" => nil, nil => 5, [] => [] }
+ merge_bang_pairs = []
+ merge_pairs = []
+ h.merge(h) { |*arg| merge_pairs << arg }
+ h.merge!(h) { |*arg| merge_bang_pairs << arg }
+ merge_bang_pairs.should == merge_pairs
+ end
+
+ it "raises a FrozenError on a frozen instance that is modified" do
+ -> do
+ HashSpecs.frozen_hash.merge!(1 => 2)
+ end.should.raise(FrozenError)
+ end
+
+ it "checks frozen status before coercing an object with #to_hash" do
+ obj = mock("to_hash frozen")
+ # This is necessary because mock cleanup code cannot run on the frozen
+ # object.
+ def obj.to_hash() raise Exception, "should not receive #to_hash" end
+ obj.freeze
+
+ -> { HashSpecs.frozen_hash.merge!(obj) }.should.raise(FrozenError)
+ end
+
+ # see redmine #1571
+ it "raises a FrozenError on a frozen instance that would not be modified" do
+ -> do
+ HashSpecs.frozen_hash.merge!(HashSpecs.empty_frozen_hash)
+ end.should.raise(FrozenError)
+ end
it "does not raise an exception if changing the value of an existing key during iteration" do
- hash = {1 => 2, 3 => 4, 5 => 6}
- hash2 = {1 => :foo, 3 => :bar}
- hash.each { hash.merge!(hash2) }
- hash.should == {1 => :foo, 3 => :bar, 5 => 6}
+ hash = {1 => 2, 3 => 4, 5 => 6}
+ hash2 = {1 => :foo, 3 => :bar}
+ hash.each { hash.merge!(hash2) }
+ hash.should == {1 => :foo, 3 => :bar, 5 => 6}
+ end
+
+ it "accepts multiple hashes" do
+ result = { a: 1 }.merge!({ b: 2 }, { c: 3 }, { d: 4 })
+ result.should == { a: 1, b: 2, c: 3, d: 4 }
+ end
+
+ it "accepts zero arguments" do
+ hash = { a: 1 }
+ hash.merge!.should.eql?(hash)
end
end
diff --git a/spec/ruby/core/hash/new_spec.rb b/spec/ruby/core/hash/new_spec.rb
index c31cc2abf4..207fc2931f 100644
--- a/spec/ruby/core/hash/new_spec.rb
+++ b/spec/ruby/core/hash/new_spec.rb
@@ -1,6 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+# Actually these are specs of Hash#initialize, there is no Hash.new it's just Class.new.
describe "Hash.new" do
it "creates an empty Hash if passed no arguments" do
Hash.new.should == {}
@@ -14,7 +15,7 @@ describe "Hash.new" do
it "does not create a copy of the default argument" do
str = "foo"
- Hash.new(str).default.should equal(str)
+ Hash.new(str).default.should.equal?(str)
end
it "creates a Hash with a default_proc if passed a block" do
@@ -26,11 +27,42 @@ describe "Hash.new" do
end
it "raises an ArgumentError if more than one argument is passed" do
- lambda { Hash.new(5,6) }.should raise_error(ArgumentError)
+ -> { Hash.new(5,6) }.should.raise(ArgumentError)
end
it "raises an ArgumentError if passed both default argument and default block" do
- lambda { Hash.new(5) { 0 } }.should raise_error(ArgumentError)
- lambda { Hash.new(nil) { 0 } }.should raise_error(ArgumentError)
+ -> { Hash.new(5) { 0 } }.should.raise(ArgumentError)
+ -> { Hash.new(nil) { 0 } }.should.raise(ArgumentError)
+ end
+
+ ruby_version_is ""..."3.4" do
+ it "emits a deprecation warning if keyword arguments are passed" do
+ -> { Hash.new(unknown: true) }.should complain(
+ Regexp.new(Regexp.escape("Calling Hash.new with keyword arguments is deprecated and will be removed in Ruby 3.4; use Hash.new({ key: value }) instead"))
+ )
+
+ -> { Hash.new(1, unknown: true) }.should.raise(ArgumentError)
+ -> { Hash.new(unknown: true) { 0 } }.should.raise(ArgumentError)
+
+ Hash.new({ unknown: true }).default.should == { unknown: true }
+ end
+ end
+
+ ruby_version_is "3.4" do
+ it "accepts a capacity: argument" do
+ Hash.new(5, capacity: 42).default.should == 5
+ Hash.new(capacity: 42).default.should == nil
+ (Hash.new(capacity: 42) { 1 }).default_proc.should_not == nil
+ end
+
+ it "ignores negative capacity" do
+ -> { Hash.new(capacity: -42) }.should_not.raise
+ end
+
+ it "raises an error if unknown keyword arguments are passed" do
+ -> { Hash.new(unknown: true) }.should.raise(ArgumentError)
+ -> { Hash.new(1, unknown: true) }.should.raise(ArgumentError)
+ -> { Hash.new(unknown: true) { 0 } }.should.raise(ArgumentError)
+ end
end
end
diff --git a/spec/ruby/core/hash/rassoc_spec.rb b/spec/ruby/core/hash/rassoc_spec.rb
index 79c633f95e..73379f6867 100644
--- a/spec/ruby/core/hash/rassoc_spec.rb
+++ b/spec/ruby/core/hash/rassoc_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Hash#rassoc" do
before :each do
@@ -6,7 +6,7 @@ describe "Hash#rassoc" do
end
it "returns an Array if the argument is a value of the Hash" do
- @h.rassoc(:green).should be_an_instance_of(Array)
+ @h.rassoc(:green).should.instance_of?(Array)
end
it "returns a 2-element Array if the argument is a value of the Hash" do
@@ -28,15 +28,15 @@ describe "Hash#rassoc" do
it "uses #== to compare the argument to the values" do
@h[:key] = 1.0
1.should == 1.0
- @h.rassoc(1).should eql [:key, 1.0]
+ @h.rassoc(1).should.eql? [:key, 1.0]
end
it "returns nil if the argument is not a value of the Hash" do
- @h.rassoc(:banana).should be_nil
+ @h.rassoc(:banana).should == nil
end
it "returns nil if the argument is not a value of the Hash even when there is a default" do
- Hash.new(42).merge!( foo: :bar ).rassoc(42).should be_nil
- Hash.new{|h, k| h[k] = 42}.merge!( foo: :bar ).rassoc(42).should be_nil
+ Hash.new(42).merge!( foo: :bar ).rassoc(42).should == nil
+ Hash.new{|h, k| h[k] = 42}.merge!( foo: :bar ).rassoc(42).should == nil
end
end
diff --git a/spec/ruby/core/hash/rehash_spec.rb b/spec/ruby/core/hash/rehash_spec.rb
index 09315737b6..fcd5a037bd 100644
--- a/spec/ruby/core/hash/rehash_spec.rb
+++ b/spec/ruby/core/hash/rehash_spec.rb
@@ -1,22 +1,31 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Hash#rehash" do
- it "reorganizes the hash by recomputing all key hash codes" do
- k1 = [1]
- k2 = [2]
+ it "reorganizes the Hash by recomputing all key hash codes" do
+ k1 = Object.new
+ k2 = Object.new
+ def k1.hash; 0; end
+ def k2.hash; 1; end
+
h = {}
- h[k1] = 0
- h[k2] = 1
+ h[k1] = :v1
+ h[k2] = :v2
+
+ def k1.hash; 1; end
- k1 << 2
+ # The key should no longer be found as the #hash changed.
+ # Hash values 0 and 1 should not conflict, even with 1-bit stored hash.
h.key?(k1).should == false
+
h.keys.include?(k1).should == true
- h.rehash.should equal(h)
+ h.rehash.should.equal?(h)
h.key?(k1).should == true
- h[k1].should == 0
+ h[k1].should == :v1
+ end
+ it "calls #hash for each key" do
k1 = mock('k1')
k2 = mock('k2')
v1 = mock('v1')
@@ -35,8 +44,71 @@ describe "Hash#rehash" do
h[k2].should == v2
end
- it "raises a RuntimeError if called on a frozen instance" do
- lambda { HashSpecs.frozen_hash.rehash }.should raise_error(RuntimeError)
- lambda { HashSpecs.empty_frozen_hash.rehash }.should raise_error(RuntimeError)
+ 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 "removes duplicate keys for large hashes" do
+ a = [1,2]
+ b = [1]
+
+ h = {}
+ h[a] = true
+ h[b] = true
+ 100.times { |n| h[n] = true }
+ b << 2
+ h.size.should == 102
+ h.keys.should.include? a
+ h.keys.should.include? b
+ h.rehash
+ h.size.should == 101
+ h.keys.should.include? a
+ h.keys.should_not.include? [1]
+ end
+
+ it "iterates keys in insertion order" do
+ key = Class.new do
+ attr_reader :name
+
+ def initialize(name)
+ @name = name
+ end
+
+ def hash
+ 123
+ end
+ end
+
+ a, b, c, d = key.new('a'), key.new('b'), key.new('c'), key.new('d')
+ h = { a => 1, b => 2, c => 3, d => 4 }
+ h.size.should == 4
+
+ key.class_exec do
+ def eql?(other)
+ true
+ end
+ end
+
+ h.rehash
+ h.size.should == 1
+ k, v = h.first
+ k.name.should == 'a'
+ v.should == 4
+ end
+
+ it "raises a FrozenError if called on a frozen instance" do
+ -> { HashSpecs.frozen_hash.rehash }.should.raise(FrozenError)
+ -> { HashSpecs.empty_frozen_hash.rehash }.should.raise(FrozenError)
end
end
diff --git a/spec/ruby/core/hash/reject_spec.rb b/spec/ruby/core/hash/reject_spec.rb
index 21dd7425aa..aa1a074897 100644
--- a/spec/ruby/core/hash/reject_spec.rb
+++ b/spec/ruby/core/hash/reject_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/iteration', __FILE__)
-require File.expand_path('../../enumerable/shared/enumeratorized', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/iteration'
+require_relative '../enumerable/shared/enumeratorized'
describe "Hash#reject" do
it "returns a new hash removing keys for which the block yields true" do
@@ -28,13 +28,8 @@ describe "Hash#reject" do
context "with extra state" do
it "returns Hash instance for subclasses" do
- HashSpecs::MyHash[1 => 2, 3 => 4].reject { false }.should be_kind_of(Hash)
- HashSpecs::MyHash[1 => 2, 3 => 4].reject { true }.should be_kind_of(Hash)
- end
-
- it "does not taint the resulting hash" do
- h = { a: 1 }.taint
- h.reject {false}.tainted?.should == false
+ HashSpecs::MyHash[1 => 2, 3 => 4].reject { false }.should.is_a?(Hash)
+ HashSpecs::MyHash[1 => 2, 3 => 4].reject { true }.should.is_a?(Hash)
end
end
@@ -49,8 +44,29 @@ 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 "does not retain the default value" do
+ h = Hash.new(1)
+ h.reject { false }.default.should == nil
+ h[:a] = 1
+ h.reject { false }.default.should == nil
+ end
+
+ it "does not retain the default_proc" do
+ pr = proc { |h, k| h[k] = [] }
+ h = Hash.new(&pr)
+ h.reject { false }.default_proc.should == nil
+ h[:a] = 1
+ h.reject { false }.default_proc.should == nil
+ end
+
+ it "retains compare_by_identity flag" do
+ h = { a: 9, c: 4 }.compare_by_identity
+ h2 = h.reject { |k, _| k == :a }
+ h2.compare_by_identity?.should == true
+ end
+
+ it_behaves_like :hash_iteration_no_block, :reject
+ it_behaves_like :enumeratorized_with_origin_size, :reject, { 1 => 2, 3 => 4, 5 => 6 }
end
describe "Hash#reject!" do
@@ -63,7 +79,7 @@ describe "Hash#reject!" do
it "removes all entries if the block is true" do
h = { a: 1, b: 2, c: 3 }
- h.reject! { |k,v| true }.should equal(h)
+ h.reject! { |k,v| true }.should.equal?(h)
h.should == {}
end
@@ -87,14 +103,14 @@ describe "Hash#reject!" do
reject_bang_pairs.should == delete_if_pairs
end
- it "raises a RuntimeError if called on a frozen instance that is modified" do
- lambda { HashSpecs.empty_frozen_hash.reject! { true } }.should raise_error(RuntimeError)
+ it "raises a FrozenError if called on a frozen instance that is modified" do
+ -> { HashSpecs.empty_frozen_hash.reject! { true } }.should.raise(FrozenError)
end
- it "raises a RuntimeError if called on a frozen instance that would not be modified" do
- lambda { HashSpecs.frozen_hash.reject! { false } }.should raise_error(RuntimeError)
+ it "raises a FrozenError if called on a frozen instance that would not be modified" do
+ -> { HashSpecs.frozen_hash.reject! { false } }.should.raise(FrozenError)
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..4dacbf9779 100644
--- a/spec/ruby/core/hash/replace_spec.rb
+++ b/spec/ruby/core/hash/replace_spec.rb
@@ -1,7 +1,79 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/replace', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Hash#replace" do
- it_behaves_like(:hash_replace, :replace)
+ it "replaces the contents of self with other" do
+ h = { a: 1, b: 2 }
+ h.replace(c: -1, d: -2).should.equal?(h)
+ h.should == { c: -1, d: -2 }
+ end
+
+ it "tries to convert the passed argument to a hash using #to_hash" do
+ obj = mock('{1=>2,3=>4}')
+ obj.should_receive(:to_hash).and_return({ 1 => 2, 3 => 4 })
+
+ h = {}
+ h.replace(obj)
+ h.should == { 1 => 2, 3 => 4 }
+ end
+
+ it "calls to_hash on hash subclasses" do
+ h = {}
+ h.replace(HashSpecs::ToHashHash[1 => 2])
+ h.should == { 1 => 2 }
+ end
+
+ it "does not retain the default value" do
+ hash = Hash.new(1)
+ hash.replace(b: 2).default.should == nil
+ end
+
+ it "transfers the default value of an argument" do
+ hash = Hash.new(1)
+ { a: 1 }.replace(hash).default.should == 1
+ end
+
+ it "does not retain the default_proc" do
+ pr = proc { |h, k| h[k] = [] }
+ hash = Hash.new(&pr)
+ hash.replace(b: 2).default_proc.should == nil
+ end
+
+ it "transfers the default_proc of an argument" do
+ pr = proc { |h, k| h[k] = [] }
+ hash = Hash.new(&pr)
+ { a: 1 }.replace(hash).default_proc.should == pr
+ end
+
+ it "does not call the default_proc of an argument" do
+ hash_a = Hash.new { |h, k| k * 5 }
+ hash_b = Hash.new(-> { raise "Should not invoke lambda" })
+ hash_a.replace(hash_b)
+ hash_a.default.should == hash_b.default
+ end
+
+ it "transfers compare_by_identity flag of an argument" do
+ h = { a: 1, c: 3 }
+ h2 = { b: 2, d: 4 }.compare_by_identity
+ h.replace(h2)
+ h.compare_by_identity?.should == true
+ end
+
+ it "does not retain compare_by_identity flag" do
+ h = { a: 1, c: 3 }.compare_by_identity
+ h.replace(b: 2, d: 4)
+ h.compare_by_identity?.should == false
+ end
+
+ it "raises a FrozenError if called on a frozen instance that would not be modified" do
+ -> do
+ HashSpecs.frozen_hash.replace(HashSpecs.frozen_hash)
+ end.should.raise(FrozenError)
+ end
+
+ it "raises a FrozenError if called on a frozen instance that is modified" do
+ -> do
+ HashSpecs.frozen_hash.replace(HashSpecs.empty_frozen_hash)
+ end.should.raise(FrozenError)
+ end
end
diff --git a/spec/ruby/core/hash/ruby2_keywords_hash_spec.rb b/spec/ruby/core/hash/ruby2_keywords_hash_spec.rb
new file mode 100644
index 0000000000..609a53f81f
--- /dev/null
+++ b/spec/ruby/core/hash/ruby2_keywords_hash_spec.rb
@@ -0,0 +1,81 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe "Hash.ruby2_keywords_hash?" do
+ it "returns false if the Hash is not a keywords Hash" do
+ Hash.ruby2_keywords_hash?({}).should == false
+ end
+
+ it "returns true if the Hash is a keywords Hash marked by Module#ruby2_keywords" do
+ obj = Class.new {
+ ruby2_keywords def m(*args)
+ args.last
+ end
+ }.new
+ Hash.ruby2_keywords_hash?(obj.m(a: 1)).should == true
+ end
+
+ it "raises TypeError for non-Hash" do
+ -> { Hash.ruby2_keywords_hash?(nil) }.should.raise(TypeError)
+ end
+end
+
+describe "Hash.ruby2_keywords_hash" do
+ it "returns a copy of a Hash and marks the copy as a keywords Hash" do
+ h = {a: 1}.freeze
+ kw = Hash.ruby2_keywords_hash(h)
+ Hash.ruby2_keywords_hash?(h).should == false
+ Hash.ruby2_keywords_hash?(kw).should == true
+ kw.should == h
+ end
+
+ it "returns an instance of the subclass if called on an instance of a subclass of Hash" do
+ h = HashSpecs::MyHash.new
+ h[:a] = 1
+ kw = Hash.ruby2_keywords_hash(h)
+ kw.class.should == HashSpecs::MyHash
+ Hash.ruby2_keywords_hash?(h).should == false
+ Hash.ruby2_keywords_hash?(kw).should == true
+ kw.should == h
+ end
+
+ it "copies instance variables" do
+ h = {a: 1}
+ h.instance_variable_set(:@foo, 42)
+ kw = Hash.ruby2_keywords_hash(h)
+ kw.instance_variable_get(:@foo).should == 42
+ end
+
+ it "copies the hash internals" do
+ h = {a: 1}
+ kw = Hash.ruby2_keywords_hash(h)
+ h[:a] = 2
+ kw[:a].should == 1
+ end
+
+ it "raises TypeError for non-Hash" do
+ -> { Hash.ruby2_keywords_hash(nil) }.should.raise(TypeError)
+ end
+
+ it "retains the default value" do
+ hash = Hash.new(1)
+ Hash.ruby2_keywords_hash(hash).default.should == 1
+ hash[:a] = 1
+ Hash.ruby2_keywords_hash(hash).default.should == 1
+ end
+
+ it "retains the default_proc" do
+ pr = proc { |h, k| h[k] = [] }
+ hash = Hash.new(&pr)
+ Hash.ruby2_keywords_hash(hash).default_proc.should == pr
+ hash[:a] = 1
+ Hash.ruby2_keywords_hash(hash).default_proc.should == pr
+ end
+
+ it "retains compare_by_identity_flag" do
+ hash = {}.compare_by_identity
+ Hash.ruby2_keywords_hash(hash).compare_by_identity?.should == true
+ hash[:a] = 1
+ Hash.ruby2_keywords_hash(hash).compare_by_identity?.should == true
+ end
+end
diff --git a/spec/ruby/core/hash/select_spec.rb b/spec/ruby/core/hash/select_spec.rb
index 449607b606..60b2ce67c1 100644
--- a/spec/ruby/core/hash/select_spec.rb
+++ b/spec/ruby/core/hash/select_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/iteration', __FILE__)
-require File.expand_path('../../enumerable/shared/enumeratorized', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../enumerable/shared/enumeratorized'
+require_relative 'fixtures/classes'
+require_relative 'shared/iteration'
describe "Hash#select" do
before :each do
@@ -17,7 +17,7 @@ describe "Hash#select" do
it "returns a Hash of entries for which block is true" do
a_pairs = { 'a' => 9, 'c' => 4, 'b' => 5, 'd' => 2 }.select { |k,v| v % 2 == 0 }
- a_pairs.should be_an_instance_of(Hash)
+ a_pairs.should.instance_of?(Hash)
a_pairs.sort.should == [['c', 4], ['d', 2]]
end
@@ -26,22 +26,47 @@ describe "Hash#select" do
select_pairs = []
reject_pairs = []
- h.dup.select { |*pair| select_pairs << pair }
+ h.dup.select{ |*pair| select_pairs << pair }
h.reject { |*pair| reject_pairs << pair }
select_pairs.should == reject_pairs
end
it "returns an Enumerator when called on a non-empty hash without a block" do
- @hsh.select.should be_an_instance_of(Enumerator)
+ @hsh.select.should.instance_of?(Enumerator)
end
it "returns an Enumerator when called on an empty hash without a block" do
- @empty.select.should be_an_instance_of(Enumerator)
+ @empty.select.should.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 "does not retain the default value" do
+ h = Hash.new(1)
+ h.select { true }.default.should == nil
+ h[:a] = 1
+ h.select { true }.default.should == nil
+ end
+
+ it "does not retain the default_proc" do
+ pr = proc { |h, k| h[k] = [] }
+ h = Hash.new(&pr)
+ h.select { true }.default_proc.should == nil
+ h[:a] = 1
+ h.select { true }.default_proc.should == nil
+ end
+
+ it "retains compare_by_identity flag" do
+ h = { a: 9, c: 4 }.compare_by_identity
+ h2 = h.select { |k, _| k == :a }
+ h2.compare_by_identity?.should == true
+ end
+
+ it_behaves_like :hash_iteration_no_block, :select
+
+ before :each do
+ @object = { 1 => 2, 3 => 4, 5 => 6 }
+ end
+ it_behaves_like :enumeratorized_with_origin_size, :select
end
describe "Hash#select!" do
@@ -52,7 +77,7 @@ describe "Hash#select!" do
it "is equivalent to keep_if if changes are made" do
h = { a: 2 }
- h.select! { |k,v| v <= 1 }.should equal h
+ h.select! { |k,v| v <= 1 }.should.equal? h
h = { 1 => 2, 3 => 4 }
all_args_select = []
@@ -62,7 +87,7 @@ describe "Hash#select!" do
it "removes all entries if the block is false" do
h = { a: 1, b: 2, c: 3 }
- h.select! { |k,v| false }.should equal(h)
+ h.select! { |k,v| false }.should.equal?(h)
h.should == {}
end
@@ -70,14 +95,18 @@ describe "Hash#select!" do
{ a: 1 }.select! { |k,v| v <= 1 }.should == nil
end
- it "raises a RuntimeError if called on an empty frozen instance" do
- lambda { HashSpecs.empty_frozen_hash.select! { false } }.should raise_error(RuntimeError)
+ it "raises a FrozenError if called on an empty frozen instance" do
+ -> { HashSpecs.empty_frozen_hash.select! { false } }.should.raise(FrozenError)
end
- it "raises a RuntimeError if called on a frozen instance that would not be modified" do
- lambda { HashSpecs.frozen_hash.select! { true } }.should raise_error(RuntimeError)
+ it "raises a FrozenError if called on a frozen instance that would not be modified" do
+ -> { HashSpecs.frozen_hash.select! { true } }.should.raise(FrozenError)
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!
+
+ before :each do
+ @object = { 1 => 2, 3 => 4, 5 => 6 }
+ end
+ it_behaves_like :enumeratorized_with_origin_size, :select!
end
diff --git a/spec/ruby/core/hash/shared/comparison.rb b/spec/ruby/core/hash/shared/comparison.rb
index bbb9bfd6ad..2b62837232 100644
--- a/spec/ruby/core/hash/shared/comparison.rb
+++ b/spec/ruby/core/hash/shared/comparison.rb
@@ -1,15 +1,15 @@
describe :hash_comparison, shared: true do
it "raises a TypeError if the right operand is not a hash" do
- lambda { { a: 1 }.send(@method, 1) }.should raise_error(TypeError)
- lambda { { a: 1 }.send(@method, nil) }.should raise_error(TypeError)
- lambda { { a: 1 }.send(@method, []) }.should raise_error(TypeError)
+ -> { { a: 1 }.send(@method, 1) }.should.raise(TypeError)
+ -> { { a: 1 }.send(@method, nil) }.should.raise(TypeError)
+ -> { { a: 1 }.send(@method, []) }.should.raise(TypeError)
end
it "returns false if both hashes have the same keys but different values" do
h1 = { a: 1 }
h2 = { a: 2 }
- h1.send(@method, h2).should be_false
- h2.send(@method, h1).should be_false
+ h1.send(@method, h2).should == false
+ h2.send(@method, h1).should == false
end
end
diff --git a/spec/ruby/core/hash/shared/each.rb b/spec/ruby/core/hash/shared/each.rb
deleted file mode 100644
index bf4c569cfc..0000000000
--- a/spec/ruby/core/hash/shared/each.rb
+++ /dev/null
@@ -1,68 +0,0 @@
-describe :hash_each, shared: true do
- it "yields a [[key, value]] Array for each pair to a block expecting |*args|" do
- all_args = []
- { 1 => 2, 3 => 4 }.send(@method) { |*args| all_args << args }
- all_args.sort.should == [[[1, 2]], [[3, 4]]]
- end
-
- it "yields the key and value of each pair to a block expecting |key, value|" do
- r = {}
- h = { a: 1, b: 2, c: 3, d: 5 }
- h.send(@method) { |k,v| r[k.to_s] = v.to_s }.should equal(h)
- r.should == { "a" => "1", "b" => "2", "c" => "3", "d" => "5" }
- end
-
- it "yields the key only to a block expecting |key,|" do
- ary = []
- h = { "a" => 1, "b" => 2, "c" => 3 }
- h.send(@method) { |k,| ary << k }
- ary.sort.should == ["a", "b", "c"]
- end
-
- it "uses the same order as keys() and values()" do
- h = { a: 1, b: 2, c: 3, d: 5 }
- keys = []
- values = []
-
- h.send(@method) do |k, v|
- keys << k
- values << v
- end
-
- keys.should == h.keys
- values.should == h.values
- end
-
- # Confirming the argument-splatting works from child class for both k, v and [k, v]
- it "properly expands (or not) child class's 'each'-yielded args" do
- cls1 = Class.new(Hash) do
- attr_accessor :k_v
- def each
- super do |k, v|
- @k_v = [k, v]
- yield k, v
- end
- end
- end
-
- cls2 = Class.new(Hash) do
- attr_accessor :k_v
- def each
- super do |k, v|
- @k_v = [k, v]
- yield([k, v])
- end
- end
- end
-
- obj1 = cls1.new
- obj1['a'] = 'b'
- obj1.map {|k, v| [k, v]}.should == [['a', 'b']]
- obj1.k_v.should == ['a', 'b']
-
- obj2 = cls2.new
- obj2['a'] = 'b'
- obj2.map {|k, v| [k, v]}.should == [['a', 'b']]
- obj2.k_v.should == ['a', 'b']
- end
-end
diff --git a/spec/ruby/core/hash/shared/eql.rb b/spec/ruby/core/hash/shared/eql.rb
index 1aed5f51fb..512e1ad016 100644
--- a/spec/ruby/core/hash/shared/eql.rb
+++ b/spec/ruby/core/hash/shared/eql.rb
@@ -3,7 +3,7 @@ describe :hash_eql, shared: true do
value = mock('x')
value.should_not_receive(:==)
value.should_not_receive(:eql?)
- { 1 => value }.send(@method, { 2 => value }).should be_false
+ { 1 => value }.send(@method, { 2 => value }).should == false
end
it "returns false when the numbers of keys differ without comparing any elements" do
@@ -13,8 +13,8 @@ describe :hash_eql, shared: true do
obj.should_not_receive(:==)
obj.should_not_receive(:eql?)
- {}.send(@method, h).should be_false
- h.send(@method, {}).should be_false
+ {}.send(@method, h).should == false
+ h.send(@method, {}).should == false
end
it "first compares keys via hash" do
@@ -23,7 +23,7 @@ describe :hash_eql, shared: true do
y = mock('y')
y.should_receive(:hash).any_number_of_times.and_return(0)
- { x => 1 }.send(@method, { y => 1 }).should be_false
+ { x => 1 }.send(@method, { y => 1 }).should == false
end
it "does not compare keys with different hash codes via eql?" do
@@ -35,39 +35,39 @@ describe :hash_eql, shared: true do
x.should_receive(:hash).any_number_of_times.and_return(0)
y.should_receive(:hash).any_number_of_times.and_return(1)
- { x => 1 }.send(@method, { y => 1 }).should be_false
+ { x => 1 }.send(@method, { y => 1 }).should == false
end
it "computes equality for recursive hashes" do
h = {}
h[:a] = h
- h.send(@method, h[:a]).should be_true
- (h == h[:a]).should be_true
+ h.send(@method, h[:a]).should == true
+ (h == h[:a]).should == true
end
it "doesn't call to_hash on objects" do
mock_hash = mock("fake hash")
def mock_hash.to_hash() {} end
- {}.send(@method, mock_hash).should be_false
+ {}.send(@method, mock_hash).should == false
end
it "computes equality for complex recursive hashes" do
a, b = {}, {}
a.merge! self: a, other: b
b.merge! self: b, other: a
- a.send(@method, b).should be_true # they both have the same structure!
+ a.send(@method, b).should == true # they both have the same structure!
c = {}
c.merge! other: c, self: c
- c.send(@method, a).should be_true # subtle, but they both have the same structure!
+ c.send(@method, a).should == true # subtle, but they both have the same structure!
a[:delta] = c[:delta] = a
- c.send(@method, a).should be_false # not quite the same structure, as a[:other][:delta] = nil
+ c.send(@method, a).should == false # not quite the same structure, as a[:other][:delta] = nil
c[:delta] = 42
- c.send(@method, a).should be_false
+ c.send(@method, a).should == false
a[:delta] = 42
- c.send(@method, a).should be_false
+ c.send(@method, a).should == false
b[:delta] = 42
- c.send(@method, a).should be_true
+ c.send(@method, a).should == true
end
it "computes equality for recursive hashes & arrays" do
@@ -76,19 +76,19 @@ describe :hash_eql, shared: true do
x << a
y << c
z << b
- b.send(@method, c).should be_true # they clearly have the same structure!
- y.send(@method, z).should be_true
- a.send(@method, b).should be_true # subtle, but they both have the same structure!
- x.send(@method, y).should be_true
+ b.send(@method, c).should == true # they clearly have the same structure!
+ y.send(@method, z).should == true
+ a.send(@method, b).should == true # subtle, but they both have the same structure!
+ x.send(@method, y).should == true
y << x
- y.send(@method, z).should be_false
+ y.send(@method, z).should == false
z << x
- y.send(@method, z).should be_true
+ y.send(@method, z).should == true
a[:foo], a[:bar] = a[:bar], a[:foo]
- a.send(@method, b).should be_false
+ a.send(@method, b).should == false
b[:bar] = b[:foo]
- b.send(@method, c).should be_false
+ b.send(@method, c).should == false
end
end
@@ -100,7 +100,7 @@ describe :hash_eql_additional, shared: true do
def y.==(o) false end
def x.eql?(o) false end
def y.eql?(o) false end
- { 1 => x }.send(@method, { 1 => y }).should be_false
+ { 1 => x }.send(@method, { 1 => y }).should == false
x = mock('x')
y = mock('y')
@@ -108,45 +108,45 @@ describe :hash_eql_additional, shared: true do
def y.==(o) true end
def x.eql?(o) true end
def y.eql?(o) true end
- { 1 => x }.send(@method, { 1 => y }).should be_true
+ { 1 => x }.send(@method, { 1 => y }).should == true
end
it "compares keys with eql? semantics" do
- { 1.0 => "x" }.send(@method, { 1.0 => "x" }).should be_true
- { 1.0 => "x" }.send(@method, { 1.0 => "x" }).should be_true
- { 1 => "x" }.send(@method, { 1.0 => "x" }).should be_false
- { 1.0 => "x" }.send(@method, { 1 => "x" }).should be_false
+ { 1.0 => "x" }.send(@method, { 1.0 => "x" }).should == true
+ { 1.0 => "x" }.send(@method, { 1.0 => "x" }).should == true
+ { 1 => "x" }.send(@method, { 1.0 => "x" }).should == false
+ { 1.0 => "x" }.send(@method, { 1 => "x" }).should == false
end
- it "returns true iff other Hash has the same number of keys and each key-value pair matches" do
+ it "returns true if and only if other Hash has the same number of keys and each key-value pair matches" do
a = { a: 5 }
b = {}
- a.send(@method, b).should be_false
+ a.send(@method, b).should == false
b[:a] = 5
- a.send(@method, b).should be_true
+ a.send(@method, b).should == true
not_supported_on :opal do
c = { "a" => 5 }
- a.send(@method, c).should be_false
+ a.send(@method, c).should == false
end
c = { "A" => 5 }
- a.send(@method, c).should be_false
+ a.send(@method, c).should == false
c = { a: 6 }
- a.send(@method, c).should be_false
+ a.send(@method, c).should == false
end
it "does not call to_hash on hash subclasses" do
- { 5 => 6 }.send(@method, HashSpecs::ToHashHash[5 => 6]).should be_true
+ { 5 => 6 }.send(@method, HashSpecs::ToHashHash[5 => 6]).should == true
end
it "ignores hash class differences" do
h = { 1 => 2, 3 => 4 }
- HashSpecs::MyHash[h].send(@method, h).should be_true
- HashSpecs::MyHash[h].send(@method, HashSpecs::MyHash[h]).should be_true
- h.send(@method, HashSpecs::MyHash[h]).should be_true
+ HashSpecs::MyHash[h].send(@method, h).should == true
+ HashSpecs::MyHash[h].send(@method, HashSpecs::MyHash[h]).should == true
+ h.send(@method, HashSpecs::MyHash[h]).should == true
end
# Why isn't this true of eql? too ?
@@ -155,40 +155,28 @@ describe :hash_eql_additional, shared: true do
obj = mock('0')
obj.should_receive(:hash).at_least(1).and_return(0)
- # It's undefined whether the impl does a[0].eql?(a[1]) or
- # a[1].eql?(a[0]) so we taint both.
def obj.eql?(o)
return true if self.equal?(o)
- taint
- o.taint
false
end
obj
end
- { a[0] => 1 }.send(@method, { a[1] => 1 }).should be_false
- a[0].tainted?.should be_true
- a[1].tainted?.should be_true
+ { a[0] => 1 }.send(@method, { a[1] => 1 }).should == false
a = Array.new(2) do
obj = mock('0')
obj.should_receive(:hash).at_least(1).and_return(0)
def obj.eql?(o)
- # It's undefined whether the impl does a[0].send(@method, a[1]) or
- # a[1].send(@method, a[0]) so we taint both.
- taint
- o.taint
true
end
obj
end
- { a[0] => 1 }.send(@method, { a[1] => 1 }).should be_true
- a[0].tainted?.should be_true
- a[1].tainted?.should be_true
+ { a[0] => 1 }.send(@method, { a[1] => 1 }).should == true
end
it "compares the values in self to values in other hash" do
@@ -197,20 +185,20 @@ describe :hash_eql_additional, shared: true do
l_val.should_receive(:eql?).with(r_val).and_return(true)
- { 1 => l_val }.eql?({ 1 => r_val }).should be_true
+ { 1 => l_val }.eql?({ 1 => r_val }).should == true
end
end
describe :hash_eql_additional_more, shared: true do
it "returns true if other Hash has the same number of keys and each key-value pair matches, even though the default-value are not same" do
- Hash.new(5).send(@method, Hash.new(1)).should be_true
- Hash.new {|h, k| 1}.send(@method, Hash.new {}).should be_true
- Hash.new {|h, k| 1}.send(@method, Hash.new(2)).should be_true
+ Hash.new(5).send(@method, Hash.new(1)).should == true
+ Hash.new {|h, k| 1}.send(@method, Hash.new {}).should == true
+ Hash.new {|h, k| 1}.send(@method, Hash.new(2)).should == true
d = Hash.new {|h, k| 1}
e = Hash.new {}
d[1] = 2
e[1] = 2
- d.send(@method, e).should be_true
+ d.send(@method, e).should == true
end
end
diff --git a/spec/ruby/core/hash/shared/equal.rb b/spec/ruby/core/hash/shared/equal.rb
deleted file mode 100644
index 43606437fe..0000000000
--- a/spec/ruby/core/hash/shared/equal.rb
+++ /dev/null
@@ -1,90 +0,0 @@
-describe :hash_equal, shared: true do
- it "does not compare values when keys don't match" do
- value = mock('x')
- value.should_not_receive(:==)
- value.should_not_receive(:eql?)
- { 1 => value }.send(@method, { 2 => value }).should be_false
- end
-
- it "returns false when the numbers of keys differ without comparing any elements" do
- obj = mock('x')
- h = { obj => obj }
-
- obj.should_not_receive(:==)
- obj.should_not_receive(:eql?)
-
- {}.send(@method, h).should be_false
- h.send(@method, {}).should be_false
- end
-
- it "first compares keys via hash" do
- x = mock('x')
- x.should_receive(:hash).and_return(0)
- y = mock('y')
- y.should_receive(:hash).and_return(0)
-
- { x => 1 }.send(@method, { y => 1 }).should be_false
- end
-
- it "does not compare keys with different hash codes via eql?" do
- x = mock('x')
- y = mock('y')
- x.should_not_receive(:eql?)
- y.should_not_receive(:eql?)
-
- x.should_receive(:hash).and_return(0)
- y.should_receive(:hash).and_return(1)
-
- def x.hash() 0 end
- def y.hash() 1 end
-
- { x => 1 }.send(@method, { y => 1 }).should be_false
- end
-
- it "computes equality for recursive hashes" do
- h = {}
- h[:a] = h
- h.send(@method, h[:a]).should be_true
- (h == h[:a]).should be_true
- end
-
- it "computes equality for complex recursive hashes" do
- a, b = {}, {}
- a.merge! self: a, other: b
- b.merge! self: b, other: a
- a.send(@method, b).should be_true # they both have the same structure!
-
- c = {}
- c.merge! other: c, self: c
- c.send(@method, a).should be_true # subtle, but they both have the same structure!
- a[:delta] = c[:delta] = a
- c.send(@method, a).should be_false # not quite the same structure, as a[:other][:delta] = nil
- c[:delta] = 42
- c.send(@method, a).should be_false
- a[:delta] = 42
- c.send(@method, a).should be_false
- b[:delta] = 42
- c.send(@method, a).should be_true
- end
-
- it "computes equality for recursive hashes & arrays" do
- x, y, z = [], [], []
- a, b, c = {foo: x, bar: 42}, {foo: y, bar: 42}, {foo: z, bar: 42}
- x << a
- y << c
- z << b
- b.send(@method, c).should be_true # they clearly have the same structure!
- y.send(@method, z).should be_true
- a.send(@method, b).should be_true # subtle, but they both have the same structure!
- x.send(@method, y).should be_true
- y << x
- y.send(@method, z).should be_false
- z << x
- y.send(@method, z).should be_true
-
- a[:foo], a[:bar] = a[:bar], a[:foo]
- a.send(@method, b).should be_false
- b[:bar] = b[:foo]
- b.send(@method, c).should be_false
- end
-end
diff --git a/spec/ruby/core/hash/shared/greater_than.rb b/spec/ruby/core/hash/shared/greater_than.rb
index 1f8b9fcfb7..dfe0b80250 100644
--- a/spec/ruby/core/hash/shared/greater_than.rb
+++ b/spec/ruby/core/hash/shared/greater_than.rb
@@ -5,11 +5,11 @@ describe :hash_greater_than, shared: true do
end
it "returns true if the other hash is a subset of self" do
- @h1.send(@method, @h2).should be_true
+ @h1.send(@method, @h2).should == true
end
it "returns false if the other hash is not a subset of self" do
- @h2.send(@method, @h1).should be_false
+ @h2.send(@method, @h1).should == false
end
it "converts the right operand to a hash before comparing" do
@@ -18,6 +18,6 @@ describe :hash_greater_than, shared: true do
{ a: 1, b: 2 }
end
- @h1.send(@method, o).should be_true
+ @h1.send(@method, o).should == true
end
end
diff --git a/spec/ruby/core/hash/shared/index.rb b/spec/ruby/core/hash/shared/index.rb
deleted file mode 100644
index 9aa1b2a46f..0000000000
--- a/spec/ruby/core/hash/shared/index.rb
+++ /dev/null
@@ -1,27 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
-
-describe :hash_index, shared: true do
- it "returns the corresponding key for value" do
- { 2 => 'a', 1 => 'b' }.send(@method, 'b').should == 1
- end
-
- it "returns nil if the value is not found" do
- { a: -1, b: 3.14, c: 2.718 }.send(@method, 1).should be_nil
- end
-
- it "doesn't return default value if the value is not found" do
- Hash.new(5).send(@method, 5).should be_nil
- end
-
- it "compares values using ==" do
- { 1 => 0 }.send(@method, 0.0).should == 1
- { 1 => 0.0 }.send(@method, 0).should == 1
-
- needle = mock('needle')
- inhash = mock('inhash')
- inhash.should_receive(:==).with(needle).and_return(true)
-
- { 1 => inhash }.send(@method, needle).should == 1
- end
-end
diff --git a/spec/ruby/core/hash/shared/iteration.rb b/spec/ruby/core/hash/shared/iteration.rb
index d27c2443f8..322e4b9a2f 100644
--- a/spec/ruby/core/hash/shared/iteration.rb
+++ b/spec/ruby/core/hash/shared/iteration.rb
@@ -5,15 +5,15 @@ describe :hash_iteration_no_block, shared: true do
end
it "returns an Enumerator if called on a non-empty hash without a block" do
- @hsh.send(@method).should be_an_instance_of(Enumerator)
+ @hsh.send(@method).should.instance_of?(Enumerator)
end
it "returns an Enumerator if called on an empty hash without a block" do
- @empty.send(@method).should be_an_instance_of(Enumerator)
+ @empty.send(@method).should.instance_of?(Enumerator)
end
it "returns an Enumerator if called on a frozen instance" do
@hsh.freeze
- @hsh.send(@method).should be_an_instance_of(Enumerator)
+ @hsh.send(@method).should.instance_of?(Enumerator)
end
end
diff --git a/spec/ruby/core/hash/shared/key.rb b/spec/ruby/core/hash/shared/key.rb
deleted file mode 100644
index 17f9f81457..0000000000
--- a/spec/ruby/core/hash/shared/key.rb
+++ /dev/null
@@ -1,38 +0,0 @@
-describe :hash_key_p, shared: true do
- it "returns true if argument is a key" do
- h = { a: 1, b: 2, c: 3, 4 => 0 }
- h.send(@method, :a).should == true
- h.send(@method, :b).should == true
- h.send(@method, 2).should == false
- h.send(@method, 4).should == true
-
- not_supported_on :opal do
- h.send(@method, 'b').should == false
- h.send(@method, 4.0).should == false
- end
- end
-
- it "returns true if the key's matching value was nil" do
- { xyz: nil }.send(@method, :xyz).should == true
- end
-
- it "returns true if the key's matching value was false" do
- { xyz: false }.send(@method, :xyz).should == true
- end
-
- it "returns true if the key is nil" do
- { nil => 'b' }.send(@method, nil).should == true
- { nil => nil }.send(@method, nil).should == true
- end
-
- it "compares keys with the same #hash value via #eql?" do
- x = mock('x')
- x.stub!(:hash).and_return(42)
-
- y = mock('y')
- y.stub!(:hash).and_return(42)
- y.should_receive(:eql?).and_return(false)
-
- { x => nil }.send(@method, y).should == false
- end
-end
diff --git a/spec/ruby/core/hash/shared/length.rb b/spec/ruby/core/hash/shared/length.rb
deleted file mode 100644
index 24f5563759..0000000000
--- a/spec/ruby/core/hash/shared/length.rb
+++ /dev/null
@@ -1,12 +0,0 @@
-describe :hash_length, shared: true do
- it "returns the number of entries" do
- { a: 1, b: 'c' }.send(@method).should == 2
- h = { a: 1, b: 2 }
- h[:a] = 2
- h.send(@method).should == 2
- { a: 1, b: 1, c: 1 }.send(@method).should == 3
- {}.send(@method).should == 0
- Hash.new(5).send(@method).should == 0
- Hash.new { 5 }.send(@method).should == 0
- end
-end
diff --git a/spec/ruby/core/hash/shared/less_than.rb b/spec/ruby/core/hash/shared/less_than.rb
index cdc6f14546..071b3e97bb 100644
--- a/spec/ruby/core/hash/shared/less_than.rb
+++ b/spec/ruby/core/hash/shared/less_than.rb
@@ -5,11 +5,11 @@ describe :hash_less_than, shared: true do
end
it "returns true if self is a subset of the other hash" do
- @h1.send(@method, @h2).should be_true
+ @h1.send(@method, @h2).should == true
end
it "returns false if self is not a subset of the other hash" do
- @h2.send(@method, @h1).should be_false
+ @h2.send(@method, @h1).should == false
end
it "converts the right operand to a hash before comparing" do
@@ -18,6 +18,6 @@ describe :hash_less_than, shared: true do
{ a: 1, b: 2, c: 3 }
end
- @h1.send(@method, o).should be_true
+ @h1.send(@method, o).should == true
end
end
diff --git a/spec/ruby/core/hash/shared/replace.rb b/spec/ruby/core/hash/shared/replace.rb
deleted file mode 100644
index 463c861395..0000000000
--- a/spec/ruby/core/hash/shared/replace.rb
+++ /dev/null
@@ -1,51 +0,0 @@
-describe :hash_replace, shared: true do
- it "replaces the contents of self with other" do
- h = { a: 1, b: 2 }
- h.send(@method, c: -1, d: -2).should equal(h)
- h.should == { c: -1, d: -2 }
- end
-
- it "tries to convert the passed argument to a hash using #to_hash" do
- obj = mock('{1=>2,3=>4}')
- obj.should_receive(:to_hash).and_return({ 1 => 2, 3 => 4 })
-
- h = {}
- h.send(@method, obj)
- h.should == { 1 => 2, 3 => 4 }
- end
-
- it "calls to_hash on hash subclasses" do
- h = {}
- h.send(@method, HashSpecs::ToHashHash[1 => 2])
- h.should == { 1 => 2 }
- end
-
- it "does not transfer default values" do
- hash_a = {}
- hash_b = Hash.new(5)
- hash_a.send(@method, hash_b)
- hash_a.default.should == 5
-
- hash_a = {}
- hash_b = Hash.new { |h, k| k * 2 }
- hash_a.send(@method, hash_b)
- hash_a.default(5).should == 10
-
- hash_a = Hash.new { |h, k| k * 5 }
- hash_b = Hash.new(lambda { raise "Should not invoke lambda" })
- hash_a.send(@method, hash_b)
- hash_a.default.should == hash_b.default
- end
-
- it "raises a RuntimeError if called on a frozen instance that would not be modified" do
- lambda do
- HashSpecs.frozen_hash.send(@method, HashSpecs.frozen_hash)
- end.should raise_error(RuntimeError)
- end
-
- it "raises a RuntimeError if called on a frozen instance that is modified" do
- lambda do
- HashSpecs.frozen_hash.send(@method, HashSpecs.empty_frozen_hash)
- end.should raise_error(RuntimeError)
- end
-end
diff --git a/spec/ruby/core/hash/shared/store.rb b/spec/ruby/core/hash/shared/store.rb
deleted file mode 100644
index b43dcbc93e..0000000000
--- a/spec/ruby/core/hash/shared/store.rb
+++ /dev/null
@@ -1,98 +0,0 @@
-require File.expand_path('../../fixtures/classes', __FILE__)
-
-describe :hash_store, shared: true do
- it "associates the key with the value and return the value" do
- h = { a: 1 }
- h.send(@method, :b, 2).should == 2
- h.should == { b:2, a:1 }
- end
-
- it "duplicates string keys using dup semantics" do
- # dup doesn't copy singleton methods
- key = "foo"
- def key.reverse() "bar" end
- h = {}
- h.send(@method, key, 0)
- h.keys[0].reverse.should == "oof"
- end
-
- it "stores unequal keys that hash to the same value" do
- h = {}
- k1 = ["x"]
- k2 = ["y"]
- # So they end up in the same bucket
- k1.should_receive(:hash).and_return(0)
- k2.should_receive(:hash).and_return(0)
-
- h.send(@method, k1, 1)
- h.send(@method, k2, 2)
- h.size.should == 2
- end
-
- it "accepts keys with private #hash method" do
- key = HashSpecs::KeyWithPrivateHash.new
- h = {}
- h.send(@method, key, "foo")
- h[key].should == "foo"
- end
-
- it " accepts keys with a Bignum hash" do
- o = mock(hash: 1 << 100)
- h = {}
- h[o] = 1
- h[o].should == 1
- end
-
- it "duplicates and freezes string keys" do
- key = "foo"
- h = {}
- h.send(@method, key, 0)
- key << "bar"
-
- h.should == { "foo" => 0 }
- h.keys[0].frozen?.should == true
- end
-
- it "doesn't duplicate and freeze already frozen string keys" do
- key = "foo".freeze
- h = {}
- h.send(@method, key, 0)
- h.keys[0].should equal(key)
- end
-
- it "keeps the existing key in the hash if there is a matching one" do
- h = { "a" => 1, "b" => 2, "c" => 3, "d" => 4 }
- key1 = HashSpecs::ByValueKey.new(13)
- key2 = HashSpecs::ByValueKey.new(13)
- h[key1] = 41
- key_in_hash = h.keys.last
- key_in_hash.should equal(key1)
- h[key2] = 42
- last_key = h.keys.last
- last_key.should equal(key_in_hash)
- last_key.should_not equal(key2)
- end
-
- it "keeps the existing String key in the hash if there is a matching one" do
- h = { "a" => 1, "b" => 2, "c" => 3, "d" => 4 }
- key1 = "foo"
- key2 = "foo"
- key1.should_not equal(key2)
- h[key1] = 41
- frozen_key = h.keys.last
- frozen_key.should_not equal(key1)
- h[key2] = 42
- h.keys.last.should equal(frozen_key)
- h.keys.last.should_not equal(key2)
- end
-
- it "raises a RuntimeError if called on a frozen instance" do
- lambda { HashSpecs.frozen_hash.send(@method, 1, 2) }.should raise_error(RuntimeError)
- end
-
- it "does not raise an exception if changing the value of an existing key during iteration" do
- hash = {1 => 2, 3 => 4, 5 => 6}
- hash.each { hash.send(@method, 1, :foo) }
- hash.should == {1 => :foo, 3 => 4, 5 => 6}
- end
-end
diff --git a/spec/ruby/core/hash/shared/to_s.rb b/spec/ruby/core/hash/shared/to_s.rb
deleted file mode 100644
index 0afe605826..0000000000
--- a/spec/ruby/core/hash/shared/to_s.rb
+++ /dev/null
@@ -1,109 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
-
-describe :hash_to_s, shared: true do
-
- it "returns a string representation with same order as each()" do
- h = { a: [1, 2], b: -2, d: -6, nil => nil }
-
- pairs = []
- h.each do |key, value|
- pairs << key.inspect + '=>' + value.inspect
- end
-
- str = '{' + pairs.join(', ') + '}'
- h.send(@method).should == str
- end
-
- it "calls #inspect on keys and values" do
- key = mock('key')
- val = mock('val')
- key.should_receive(:inspect).and_return('key')
- val.should_receive(:inspect).and_return('val')
-
- { key => val }.send(@method).should == '{key=>val}'
- end
-
- it "does not call #to_s on a String returned from #inspect" do
- str = "abc"
- str.should_not_receive(:to_s)
-
- { a: str }.send(@method).should == '{:a=>"abc"}'
- end
-
- it "calls #to_s on the object returned from #inspect if the Object isn't a String" do
- obj = mock("Hash#inspect/to_s calls #to_s")
- obj.should_receive(:inspect).and_return(obj)
- obj.should_receive(:to_s).and_return("abc")
-
- { a: obj }.send(@method).should == "{:a=>abc}"
- end
-
- it "does not call #to_str on the object returned from #inspect when it is not a String" do
- obj = mock("Hash#inspect/to_s does not call #to_str")
- obj.should_receive(:inspect).and_return(obj)
- obj.should_not_receive(:to_str)
-
- { a: obj }.send(@method).should =~ /^\{:a=>#<MockObject:0x[0-9a-f]+>\}$/
- end
-
- it "does not call #to_str on the object returned from #to_s when it is not a String" do
- obj = mock("Hash#inspect/to_s does not call #to_str on #to_s result")
- obj.should_receive(:inspect).and_return(obj)
- obj.should_receive(:to_s).and_return(obj)
- obj.should_not_receive(:to_str)
-
- { a: obj }.send(@method).should =~ /^\{:a=>#<MockObject:0x[0-9a-f]+>\}$/
- end
-
- it "does not swallow exceptions raised by #to_s" do
- obj = mock("Hash#inspect/to_s does not swallow #to_s exceptions")
- obj.should_receive(:inspect).and_return(obj)
- obj.should_receive(:to_s).and_raise(Exception)
-
- lambda { { a: obj }.send(@method) }.should raise_error(Exception)
- end
-
- it "handles hashes with recursive values" do
- x = {}
- x[0] = x
- x.send(@method).should == '{0=>{...}}'
-
- x = {}
- y = {}
- x[0] = y
- y[1] = x
- x.send(@method).should == "{0=>{1=>{...}}}"
- y.send(@method).should == "{1=>{0=>{...}}}"
- end
-
- it "returns a tainted string if self is tainted and not empty" do
- {}.taint.send(@method).tainted?.should be_false
- { nil => nil }.taint.send(@method).tainted?.should be_true
- end
-
- it "returns an untrusted string if self is untrusted and not empty" do
- {}.untrust.send(@method).untrusted?.should be_false
- { nil => nil }.untrust.send(@method).untrusted?.should be_true
- end
-
- ruby_version_is ''...'2.3' do
- it "raises if inspected result is not default external encoding" do
- utf_16be = mock("utf_16be")
- utf_16be.should_receive(:inspect).and_return(%<"utf_16be \u3042">.encode!(Encoding::UTF_16BE))
-
- lambda {
- {a: utf_16be}.send(@method)
- }.should raise_error(Encoding::CompatibilityError)
- end
- end
-
- ruby_version_is '2.3' do
- it "does not raise if inspected result is not default external encoding" do
- utf_16be = mock("utf_16be")
- utf_16be.should_receive(:inspect).and_return(%<"utf_16be \u3042">.encode!(Encoding::UTF_16BE))
-
- {a: utf_16be}.send(@method).should == '{:a=>"utf_16be \u3042"}'
- end
- end
-end
diff --git a/spec/ruby/core/hash/shared/update.rb b/spec/ruby/core/hash/shared/update.rb
deleted file mode 100644
index b1e3793028..0000000000
--- a/spec/ruby/core/hash/shared/update.rb
+++ /dev/null
@@ -1,59 +0,0 @@
-describe :hash_update, shared: true do
- it "adds the entries from other, overwriting duplicate keys. Returns self" do
- h = { _1: 'a', _2: '3' }
- h.send(@method, _1: '9', _9: 2).should equal(h)
- h.should == { _1: "9", _2: "3", _9: 2 }
- end
-
- it "sets any duplicate key to the value of block if passed a block" do
- h1 = { a: 2, b: -1 }
- h2 = { a: -2, c: 1 }
- h1.send(@method, h2) { |k,x,y| 3.14 }.should equal(h1)
- h1.should == { c: 1, b: -1, a: 3.14 }
-
- h1.send(@method, h1) { nil }
- h1.should == { a: nil, b: nil, c: nil }
- end
-
- it "tries to convert the passed argument to a hash using #to_hash" do
- obj = mock('{1=>2}')
- obj.should_receive(:to_hash).and_return({ 1 => 2 })
- { 3 => 4 }.send(@method, obj).should == { 1 => 2, 3 => 4 }
- end
-
- it "does not call to_hash on hash subclasses" do
- { 3 => 4 }.send(@method, HashSpecs::ToHashHash[1 => 2]).should == { 1 => 2, 3 => 4 }
- end
-
- it "processes entries with same order as merge()" do
- h = { 1 => 2, 3 => 4, 5 => 6, "x" => nil, nil => 5, [] => [] }
- merge_bang_pairs = []
- merge_pairs = []
- h.merge(h) { |*arg| merge_pairs << arg }
- h.send(@method, h) { |*arg| merge_bang_pairs << arg }
- merge_bang_pairs.should == merge_pairs
- end
-
- it "raises a RuntimeError on a frozen instance that is modified" do
- lambda do
- HashSpecs.frozen_hash.send(@method, 1 => 2)
- end.should raise_error(RuntimeError)
- end
-
- it "checks frozen status before coercing an object with #to_hash" do
- obj = mock("to_hash frozen")
- # This is necessary because mock cleanup code cannot run on the frozen
- # object.
- def obj.to_hash() raise Exception, "should not receive #to_hash" end
- obj.freeze
-
- lambda { HashSpecs.frozen_hash.send(@method, obj) }.should raise_error(RuntimeError)
- end
-
- # see redmine #1571
- it "raises a RuntimeError on a frozen instance that would not be modified" do
- lambda do
- HashSpecs.frozen_hash.send(@method, HashSpecs.empty_frozen_hash)
- end.should raise_error(RuntimeError)
- end
-end
diff --git a/spec/ruby/core/hash/shared/value.rb b/spec/ruby/core/hash/shared/value.rb
deleted file mode 100644
index aac76c253e..0000000000
--- a/spec/ruby/core/hash/shared/value.rb
+++ /dev/null
@@ -1,14 +0,0 @@
-describe :hash_value_p, shared: true do
- it "returns true if the value exists in the hash" do
- { a: :b }.send(@method, :a).should == false
- { 1 => 2 }.send(@method, 2).should == true
- h = Hash.new(5)
- h.send(@method, 5).should == false
- h = Hash.new { 5 }
- h.send(@method, 5).should == false
- end
-
- it "uses == semantics for comparing values" do
- { 5 => 2.0 }.send(@method, 2).should == true
- end
-end
diff --git a/spec/ruby/core/hash/shared/values_at.rb b/spec/ruby/core/hash/shared/values_at.rb
deleted file mode 100644
index ef3b0e8ba0..0000000000
--- a/spec/ruby/core/hash/shared/values_at.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-describe :hash_values_at, shared: true do
- it "returns an array of values for the given keys" do
- h = { a: 9, b: 'a', c: -10, d: nil }
- h.send(@method).should be_kind_of(Array)
- h.send(@method).should == []
- h.send(@method, :a, :d, :b).should be_kind_of(Array)
- h.send(@method, :a, :d, :b).should == [9, nil, 'a']
- end
-end
diff --git a/spec/ruby/core/hash/shift_spec.rb b/spec/ruby/core/hash/shift_spec.rb
index 3991da9656..6095d2e55f 100644
--- a/spec/ruby/core/hash/shift_spec.rb
+++ b/spec/ruby/core/hash/shift_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Hash#shift" do
it "removes a pair from hash and return it" do
@@ -8,7 +8,7 @@ describe "Hash#shift" do
h.size.times do |i|
r = h.shift
- r.should be_kind_of(Array)
+ r.should.is_a?(Array)
h2[r.first].should == r.last
h.size.should == h2.size - i - 1
end
@@ -30,23 +30,22 @@ describe "Hash#shift" do
h.should == {}
end
- it "calls #default with nil if the Hash is empty" do
+ it "returns nil if the Hash is empty" do
h = {}
def h.default(key)
- key.should == nil
- :foo
+ raise
end
- h.shift.should == :foo
+ h.shift.should == nil
end
it "returns nil from an empty hash" do
{}.shift.should == nil
end
- it "returns (computed) default for empty hashes" do
- Hash.new(5).shift.should == 5
+ it "returns nil for empty hashes with defaults and default procs" do
+ Hash.new(5).shift.should == nil
h = Hash.new { |*args| args }
- h.shift.should == [h, nil]
+ h.shift.should == nil
end
it "preserves Hash invariants when removing the last item" do
@@ -57,8 +56,23 @@ describe "Hash#shift" do
h.should == {:c => 3}
end
- it "raises a RuntimeError if called on a frozen instance" do
- lambda { HashSpecs.frozen_hash.shift }.should raise_error(RuntimeError)
- lambda { HashSpecs.empty_frozen_hash.shift }.should raise_error(RuntimeError)
+ it "raises a FrozenError if called on a frozen instance" do
+ -> { HashSpecs.frozen_hash.shift }.should.raise(FrozenError)
+ -> { HashSpecs.empty_frozen_hash.shift }.should.raise(FrozenError)
+ end
+
+ it "works when the hash is at capacity" do
+ # We try a wide range of sizes in hopes that this will cover all implementations' base Hash size.
+ results = []
+ 1.upto(100) do |n|
+ h = {}
+ n.times do |i|
+ h[i] = i
+ end
+ h.shift
+ results << h.size
+ end
+
+ results.should == 0.upto(99).to_a
end
end
diff --git a/spec/ruby/core/hash/size_spec.rb b/spec/ruby/core/hash/size_spec.rb
index 71660af038..5e5008a5dc 100644
--- a/spec/ruby/core/hash/size_spec.rb
+++ b/spec/ruby/core/hash/size_spec.rb
@@ -1,7 +1,14 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/length', __FILE__)
+require_relative '../../spec_helper'
describe "Hash#size" do
- it_behaves_like(:hash_length, :size)
+ it "returns the number of entries" do
+ { a: 1, b: 'c' }.size.should == 2
+ h = { a: 1, b: 2 }
+ h[:a] = 2
+ h.size.should == 2
+ { a: 1, b: 1, c: 1 }.size.should == 3
+ {}.size.should == 0
+ Hash.new(5).size.should == 0
+ Hash.new { 5 }.size.should == 0
+ end
end
diff --git a/spec/ruby/core/hash/slice_spec.rb b/spec/ruby/core/hash/slice_spec.rb
new file mode 100644
index 0000000000..fd93254517
--- /dev/null
+++ b/spec/ruby/core/hash/slice_spec.rb
@@ -0,0 +1,74 @@
+require_relative '../../spec_helper'
+
+describe "Hash#slice" do
+ before :each do
+ @hash = { a: 1, b: 2, c: 3 }
+ end
+
+ it "returns a new empty hash without arguments" do
+ ret = @hash.slice
+ ret.should_not.equal?(@hash)
+ ret.should.instance_of?(Hash)
+ ret.should == {}
+ end
+
+ it "returns the requested subset" do
+ @hash.slice(:c, :a).should == { c: 3, a: 1 }
+ end
+
+ it "returns a hash ordered in the order of the requested keys" do
+ @hash.slice(:c, :a).keys.should == [:c, :a]
+ end
+
+ it "returns only the keys of the original hash" do
+ @hash.slice(:a, :chunky_bacon).should == { a: 1 }
+ end
+
+ it "returns a Hash instance, even on subclasses" do
+ klass = Class.new(Hash)
+ h = klass.new
+ h[:bar] = 12
+ h[:foo] = 42
+ r = h.slice(:foo)
+ r.should == {foo: 42}
+ r.class.should == Hash
+ end
+
+ it "uses the regular Hash#[] method, even on subclasses that override it" do
+ ScratchPad.record []
+ klass = Class.new(Hash) do
+ def [](value)
+ ScratchPad << :used_subclassed_operator
+ super
+ end
+ end
+
+ h = klass.new
+ h[:bar] = 12
+ h[:foo] = 42
+ h.slice(:foo)
+
+ ScratchPad.recorded.should == []
+ end
+
+ it "does not retain the default value" do
+ h = Hash.new(1)
+ h.slice(:a).default.should == nil
+ h[:a] = 1
+ h.slice(:a).default.should == nil
+ end
+
+ it "does not retain the default_proc" do
+ pr = proc { |h, k| h[k] = [] }
+ h = Hash.new(&pr)
+ h.slice(:a).default_proc.should == nil
+ h[:a] = 1
+ h.slice(:a).default_proc.should == nil
+ end
+
+ it "retains compare_by_identity flag" do
+ h = { a: 9, c: 4 }.compare_by_identity
+ h2 = h.slice(:a)
+ h2.compare_by_identity?.should == true
+ end
+end
diff --git a/spec/ruby/core/hash/sort_spec.rb b/spec/ruby/core/hash/sort_spec.rb
index 06235f7609..26058c845e 100644
--- a/spec/ruby/core/hash/sort_spec.rb
+++ b/spec/ruby/core/hash/sort_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Hash#sort" do
it "converts self to a nested array of [key, value] arrays and sort with Array#sort" do
diff --git a/spec/ruby/core/hash/store_spec.rb b/spec/ruby/core/hash/store_spec.rb
index 45ea8da896..7017d8ba2b 100644
--- a/spec/ruby/core/hash/store_spec.rb
+++ b/spec/ruby/core/hash/store_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/store', __FILE__)
+require_relative '../../spec_helper'
describe "Hash#store" do
- it_behaves_like(:hash_store, :store)
+ it "is an alias of Hash#[]=" do
+ Hash.instance_method(:store).should == Hash.instance_method(:[]=)
+ end
end
diff --git a/spec/ruby/core/hash/to_a_spec.rb b/spec/ruby/core/hash/to_a_spec.rb
index 76ca721038..8c638db6c3 100644
--- a/spec/ruby/core/hash/to_a_spec.rb
+++ b/spec/ruby/core/hash/to_a_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Hash#to_a" do
it "returns a list of [key, value] pairs with same order as each()" do
@@ -10,7 +10,7 @@ describe "Hash#to_a" do
pairs << [key, value]
end
- h.to_a.should be_kind_of(Array)
+ h.to_a.should.is_a?(Array)
h.to_a.should == pairs
end
@@ -23,15 +23,7 @@ describe "Hash#to_a" do
end
ent = h.entries
- ent.should be_kind_of(Array)
+ ent.should.is_a?(Array)
ent.should == pairs
end
-
- it "returns a tainted array if self is tainted" do
- {}.taint.to_a.tainted?.should be_true
- end
-
- it "returns an untrusted array if self is untrusted" do
- {}.untrust.to_a.untrusted?.should be_true
- end
end
diff --git a/spec/ruby/core/hash/to_h_spec.rb b/spec/ruby/core/hash/to_h_spec.rb
index 366fd58e8a..5d5a280dac 100644
--- a/spec/ruby/core/hash/to_h_spec.rb
+++ b/spec/ruby/core/hash/to_h_spec.rb
@@ -1,10 +1,10 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Hash#to_h" do
it "returns self for Hash instances" do
h = {}
- h.to_h.should equal(h)
+ h.to_h.should.equal?(h)
end
describe "when called on a subclass of Hash" do
@@ -14,21 +14,93 @@ describe "Hash#to_h" do
end
it "returns a new Hash instance" do
- @h.to_h.should be_an_instance_of(Hash)
+ @h.to_h.should.instance_of?(Hash)
@h.to_h.should == @h
@h[:foo].should == :bar
end
- it "copies the default" do
+ it "retains the default" do
@h.default = 42
@h.to_h.default.should == 42
@h[:hello].should == 42
end
- it "copies the default_proc" do
+ it "retains the default_proc" do
@h.default_proc = prc = Proc.new{ |h, k| h[k] = 2 * k }
@h.to_h.default_proc.should == prc
@h[42].should == 84
end
+
+ it "retains compare_by_identity flag" do
+ @h.compare_by_identity
+ @h.to_h.compare_by_identity?.should == true
+ end
+ end
+
+ context "with block" do
+ it "converts [key, value] pairs returned by the block to a hash" do
+ { a: 1, b: 2 }.to_h { |k, v| [k.to_s, v*v]}.should == { "a" => 1, "b" => 4 }
+ end
+
+ it "passes to a block each pair's key and value as separate arguments" do
+ ScratchPad.record []
+ { a: 1, b: 2 }.to_h { |k, v| ScratchPad << [k, v]; [k, v] }
+ ScratchPad.recorded.sort.should == [[:a, 1], [:b, 2]]
+
+ ScratchPad.record []
+ { a: 1, b: 2 }.to_h { |*args| ScratchPad << args; [args[0], args[1]] }
+ ScratchPad.recorded.sort.should == [[:a, 1], [:b, 2]]
+ end
+
+ it "raises ArgumentError if block returns longer or shorter array" do
+ -> do
+ { a: 1, b: 2 }.to_h { |k, v| [k.to_s, v*v, 1] }
+ end.should.raise(ArgumentError, /element has wrong array length/)
+
+ -> do
+ { a: 1, b: 2 }.to_h { |k, v| [k] }
+ end.should.raise(ArgumentError, /element has wrong array length/)
+ end
+
+ it "raises TypeError if block returns something other than Array" do
+ -> do
+ { a: 1, b: 2 }.to_h { |k, v| "not-array" }
+ end.should.raise(TypeError, /wrong element type String/)
+ end
+
+ it "coerces returned pair to Array with #to_ary" do
+ x = mock('x')
+ x.stub!(:to_ary).and_return([:b, 'b'])
+
+ { a: 1 }.to_h { |k| x }.should == { :b => 'b' }
+ end
+
+ it "does not coerce returned pair to Array with #to_a" do
+ x = mock('x')
+ x.stub!(:to_a).and_return([:b, 'b'])
+
+ -> do
+ { a: 1 }.to_h { |k| x }
+ end.should.raise(TypeError, /wrong element type MockObject/)
+ end
+
+ it "does not retain the default value" do
+ h = Hash.new(1)
+ h2 = h.to_h { |k, v| [k.to_s, v*v]}
+ h2.default.should == nil
+ end
+
+ it "does not retain the default_proc" do
+ pr = proc { |h, k| h[k] = [] }
+ h = Hash.new(&pr)
+ h2 = h.to_h { |k, v| [k.to_s, v*v]}
+ h2.default_proc.should == nil
+ end
+
+ it "does not retain compare_by_identity flag" do
+ h = { a: 9, c: 4 }.compare_by_identity
+ h2 = h.to_h { |k, v| [k.to_s, v*v]}
+ h2.compare_by_identity?.should == false
+ end
end
end
diff --git a/spec/ruby/core/hash/to_hash_spec.rb b/spec/ruby/core/hash/to_hash_spec.rb
index 5a173c2ab5..f5622b3d9c 100644
--- a/spec/ruby/core/hash/to_hash_spec.rb
+++ b/spec/ruby/core/hash/to_hash_spec.rb
@@ -1,14 +1,14 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Hash#to_hash" do
it "returns self for Hash instances" do
h = {}
- h.to_hash.should equal(h)
+ h.to_hash.should.equal?(h)
end
it "returns self for instances of subclasses of Hash" do
h = HashSpecs::MyHash.new
- h.to_hash.should equal(h)
+ h.to_hash.should.equal?(h)
end
end
diff --git a/spec/ruby/core/hash/to_proc_spec.rb b/spec/ruby/core/hash/to_proc_spec.rb
index b486d188b7..bc4756600d 100644
--- a/spec/ruby/core/hash/to_proc_spec.rb
+++ b/spec/ruby/core/hash/to_proc_spec.rb
@@ -1,89 +1,91 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe "Hash#to_proc" do
+ before :each do
+ @key = Object.new
+ @value = Object.new
+ @hash = { @key => @value }
+ @default = Object.new
+ @unstored = Object.new
+ end
+
+ it "returns an instance of Proc" do
+ @hash.to_proc.should.instance_of? Proc
+ end
-ruby_version_is "2.3" do
- describe "Hash#to_proc" do
+ describe "the returned proc" do
before :each do
- @key = Object.new
- @value = Object.new
- @hash = { @key => @value }
- @default = Object.new
- @unstored = Object.new
+ @proc = @hash.to_proc
end
- it "returns an instance of Proc" do
- @hash.to_proc.should be_an_instance_of Proc
+ it "is a lambda" do
+ @proc.should.lambda?
end
- describe "the returned proc" do
- before :each do
- @proc = @hash.to_proc
- end
+ it "has an arity of 1" do
+ @proc.arity.should == 1
+ end
- it "is not a lambda" do
- @proc.lambda?.should == false
- end
+ it "raises ArgumentError if not passed exactly one argument" do
+ -> {
+ @proc.call
+ }.should.raise(ArgumentError)
- it "raises ArgumentError if not passed exactly one argument" do
- lambda {
- @proc.call
- }.should raise_error(ArgumentError)
+ -> {
+ @proc.call 1, 2
+ }.should.raise(ArgumentError)
+ end
- lambda {
- @proc.call 1, 2
- }.should raise_error(ArgumentError)
+ context "with a stored key" do
+ it "returns the paired value" do
+ @proc.call(@key).should.equal?(@value)
end
+ end
- context "with a stored key" do
- it "returns the paired value" do
- @proc.call(@key).should equal(@value)
- end
+ context "passed as a block" do
+ it "retrieves the hash's values" do
+ [@key].map(&@proc)[0].should.equal?(@value)
end
- context "passed as a block" do
- it "retrieves the hash's values" do
- [@key].map(&@proc)[0].should equal(@value)
- end
-
- context "to instance_exec" do
- it "always retrieves the original hash's values" do
- hash = {foo: 1, bar: 2}
- proc = hash.to_proc
+ context "to instance_exec" do
+ it "always retrieves the original hash's values" do
+ hash = {foo: 1, bar: 2}
+ proc = hash.to_proc
- hash.instance_exec(:foo, &proc).should == 1
+ hash.instance_exec(:foo, &proc).should == 1
- hash2 = {quux: 1}
- hash2.instance_exec(:foo, &proc).should == 1
- end
+ hash2 = {quux: 1}
+ hash2.instance_exec(:foo, &proc).should == 1
end
end
+ end
- context "with no stored key" do
- it "returns nil" do
- @proc.call(@unstored).should be_nil
- end
-
- context "when the hash has a default value" do
- before :each do
- @hash.default = @default
- end
+ context "with no stored key" do
+ it "returns nil" do
+ @proc.call(@unstored).should == nil
+ end
- it "returns the default value" do
- @proc.call(@unstored).should equal(@default)
- end
+ context "when the hash has a default value" do
+ before :each do
+ @hash.default = @default
end
- context "when the hash has a default proc" do
- it "returns an evaluated value from the default proc" do
- @hash.default_proc = -> hash, called_with { [hash.keys, called_with] }
- @proc.call(@unstored).should == [[@key], @unstored]
- end
+ it "returns the default value" do
+ @proc.call(@unstored).should.equal?(@default)
end
end
- it "raises an ArgumentError when calling #call on the Proc with no arguments" do
- lambda { @hash.to_proc.call }.should raise_error(ArgumentError)
+ context "when the hash has a default proc" do
+ it "returns an evaluated value from the default proc" do
+ @hash.default_proc = -> hash, called_with { [hash.keys, called_with] }
+ @proc.call(@unstored).should == [[@key], @unstored]
+ end
end
end
+
+ it "raises an ArgumentError when calling #call on the Proc with no arguments" do
+ -> { @hash.to_proc.call }.should.raise(ArgumentError)
+ end
end
end
diff --git a/spec/ruby/core/hash/to_s_spec.rb b/spec/ruby/core/hash/to_s_spec.rb
index 803b1d6236..2915db6ef8 100644
--- a/spec/ruby/core/hash/to_s_spec.rb
+++ b/spec/ruby/core/hash/to_s_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/to_s', __FILE__)
+require_relative '../../spec_helper'
describe "Hash#to_s" do
- it_behaves_like :hash_to_s, :to_s
+ it "is an alias of Hash#inspect" do
+ Hash.instance_method(:to_s).should == Hash.instance_method(:inspect)
+ end
end
diff --git a/spec/ruby/core/hash/transform_keys_spec.rb b/spec/ruby/core/hash/transform_keys_spec.rb
new file mode 100644
index 0000000000..d37a2b8616
--- /dev/null
+++ b/spec/ruby/core/hash/transform_keys_spec.rb
@@ -0,0 +1,150 @@
+require_relative '../../spec_helper'
+
+describe "Hash#transform_keys" do
+ before :each do
+ @hash = { a: 1, b: 2, c: 3 }
+ end
+
+ it "returns new hash" do
+ ret = @hash.transform_keys(&:succ)
+ ret.should_not.equal?(@hash)
+ ret.should.instance_of?(Hash)
+ end
+
+ it "sets the result as transformed keys with the given block" do
+ @hash.transform_keys(&:succ).should == { b: 1, c: 2, d: 3 }
+ end
+
+ it "keeps last pair if new keys conflict" do
+ @hash.transform_keys { |_| :a }.should == { a: 3 }
+ end
+
+ it "makes both hashes to share values" do
+ value = [1, 2, 3]
+ new_hash = { a: value }.transform_keys(&:upcase)
+ new_hash[:A].should.equal?(value)
+ end
+
+ context "when no block is given" do
+ it "returns a sized Enumerator" do
+ enumerator = @hash.transform_keys
+ enumerator.should.instance_of?(Enumerator)
+ enumerator.size.should == @hash.size
+ enumerator.each(&:succ).should == { b: 1, c: 2, d: 3 }
+ end
+ end
+
+ it "returns a Hash instance, even on subclasses" do
+ klass = Class.new(Hash)
+ h = klass.new
+ h[:foo] = 42
+ r = h.transform_keys{|v| :"x#{v}"}
+ r.keys.should == [:xfoo]
+ r.class.should == Hash
+ end
+
+ it "allows a hash argument" do
+ @hash.transform_keys({ a: :A, b: :B, c: :C }).should == { A: 1, B: 2, C: 3 }
+ end
+
+ it "allows a partial transformation of keys when using a hash argument" do
+ @hash.transform_keys({ a: :A, c: :C }).should == { A: 1, b: 2, C: 3 }
+ end
+
+ it "allows a combination of hash and block argument" do
+ @hash.transform_keys({ a: :A }, &:to_s).should == { A: 1, 'b' => 2, 'c' => 3 }
+ end
+
+ it "does not retain the default value" do
+ h = Hash.new(1)
+ h.transform_keys(&:succ).default.should == nil
+ h[:a] = 1
+ h.transform_keys(&:succ).default.should == nil
+ end
+
+ it "does not retain the default_proc" do
+ pr = proc { |h, k| h[k] = [] }
+ h = Hash.new(&pr)
+ h.transform_values(&:succ).default_proc.should == nil
+ h[:a] = 1
+ h.transform_values(&:succ).default_proc.should == nil
+ end
+
+ it "does not retain compare_by_identity flag" do
+ h = { a: 9, c: 4 }.compare_by_identity
+ h2 = h.transform_keys(&:succ)
+ h2.compare_by_identity?.should == false
+ end
+end
+
+describe "Hash#transform_keys!" do
+ before :each do
+ @hash = { a: 1, b: 2, c: 3, d: 4 }
+ @initial_pairs = @hash.dup
+ end
+
+ it "returns self" do
+ @hash.transform_keys!(&:succ).should.equal?(@hash)
+ end
+
+ it "updates self as transformed values with the given block" do
+ @hash.transform_keys!(&:to_s)
+ @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 }
+ end
+
+ it "returns the processed keys and non evaluated keys if we break from the block" do
+ @hash.transform_keys! do |v|
+ break if v == :c
+ v.succ
+ end
+ @hash.should == { b: 1, c: 2, d: 4 }
+ end
+
+ it "keeps later pair if new keys conflict" do
+ @hash.transform_keys! { |_| :a }.should == { a: 4 }
+ end
+
+ context "when no block is given" do
+ it "returns a sized Enumerator" do
+ enumerator = @hash.transform_keys!
+ enumerator.should.instance_of?(Enumerator)
+ enumerator.size.should == @hash.size
+ enumerator.each(&:upcase).should == { A: 1, B: 2, C: 3, D: 4 }
+ end
+ end
+
+ it "allows a hash argument" do
+ @hash.transform_keys!({ a: :A, b: :B, c: :C, d: :D })
+ @hash.should == { A: 1, B: 2, C: 3, D: 4 }
+ end
+
+ describe "on frozen instance" do
+ before :each do
+ @hash.freeze
+ end
+
+ it "raises a FrozenError on an empty hash" do
+ ->{ {}.freeze.transform_keys!(&:upcase) }.should.raise(FrozenError)
+ end
+
+ it "keeps pairs and raises a FrozenError" do
+ ->{ @hash.transform_keys!(&:upcase) }.should.raise(FrozenError)
+ @hash.should == @initial_pairs
+ end
+
+ it "raises a FrozenError on hash argument" do
+ ->{ @hash.transform_keys!({ a: :A, b: :B, c: :C }) }.should.raise(FrozenError)
+ end
+
+ context "when no block is given" do
+ it "does not raise an exception" do
+ @hash.transform_keys!.should.instance_of?(Enumerator)
+ end
+ end
+ end
+end
diff --git a/spec/ruby/core/hash/transform_values_spec.rb b/spec/ruby/core/hash/transform_values_spec.rb
index 0c9e43d621..b19543a9f4 100644
--- a/spec/ruby/core/hash/transform_values_spec.rb
+++ b/spec/ruby/core/hash/transform_values_spec.rb
@@ -1,91 +1,117 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
-ruby_version_is "2.4" do
- describe "Hash#transform_values" do
- before :each do
- @hash = { a: 1, b: 2, c: 3 }
- end
+describe "Hash#transform_values" do
+ before :each do
+ @hash = { a: 1, b: 2, c: 3 }
+ end
- it "returns new hash" do
- ret = @hash.transform_values(&:succ)
- ret.should_not equal(@hash)
- ret.should be_an_instance_of(Hash)
- end
+ it "returns new hash" do
+ ret = @hash.transform_values(&:succ)
+ ret.should_not.equal?(@hash)
+ ret.should.instance_of?(Hash)
+ end
- it "sets the result as transformed values with the given block" do
- @hash.transform_values(&:succ).should == { a: 2, b: 3, c: 4 }
- end
+ it "sets the result as transformed values with the given block" do
+ @hash.transform_values(&:succ).should == { a: 2, b: 3, c: 4 }
+ end
- context "when no block is given" do
- it "returns a sized Enumerator" do
- enumerator = @hash.transform_values
- enumerator.should be_an_instance_of(Enumerator)
- enumerator.size.should == @hash.size
- enumerator.each(&:succ).should == { a: 2, b: 3, c: 4 }
- end
- end
+ it "makes both hashes to share keys" do
+ key = [1, 2, 3]
+ new_hash = { key => 1 }.transform_values(&:succ)
+ new_hash[key].should == 2
+ new_hash.keys[0].should.equal?(key)
+ end
- it "returns a Hash instance, even on subclasses" do
- klass = Class.new(Hash)
- h = klass.new
- h[:foo] = 42
- r = h.transform_values{|v| 2 * v}
- r[:foo].should == 84
- r.class.should == Hash
+ context "when no block is given" do
+ it "returns a sized Enumerator" do
+ enumerator = @hash.transform_values
+ enumerator.should.instance_of?(Enumerator)
+ enumerator.size.should == @hash.size
+ enumerator.each(&:succ).should == { a: 2, b: 3, c: 4 }
end
end
- describe "Hash#transform_values!" do
- before :each do
- @hash = { a: 1, b: 2, c: 3 }
- @initial_pairs = @hash.dup
- end
+ it "returns a Hash instance, even on subclasses" do
+ klass = Class.new(Hash)
+ h = klass.new
+ h[:foo] = 42
+ r = h.transform_values{|v| 2 * v}
+ r[:foo].should == 84
+ r.class.should == Hash
+ end
- it "returns self" do
- @hash.transform_values!(&:succ).should equal(@hash)
- end
+ it "does not retain the default value" do
+ h = Hash.new(1)
+ h.transform_values(&:succ).default.should == nil
+ h[:a] = 1
+ h.transform_values(&:succ).default.should == nil
+ end
- it "updates self as transformed values with the given block" do
- @hash.transform_values!(&:succ)
- @hash.should == { a: 2, b: 3, c: 4 }
- end
+ it "does not retain the default_proc" do
+ pr = proc { |h, k| h[k] = [] }
+ h = Hash.new(&pr)
+ h.transform_values(&:succ).default_proc.should == nil
+ h[:a] = 1
+ h.transform_values(&:succ).default_proc.should == nil
+ end
- it "partially modifies the contents if we broke from the block" do
- @hash.transform_values! do |v|
- break if v == 3
- 100 + v
- end
- @hash.should == { a: 101, b: 102, c: 3}
+ it "retains compare_by_identity flag" do
+ h = { a: 9, c: 4 }.compare_by_identity
+ h2 = h.transform_values(&:succ)
+ h2.compare_by_identity?.should == true
+ end
+end
+
+describe "Hash#transform_values!" do
+ before :each do
+ @hash = { a: 1, b: 2, c: 3 }
+ @initial_pairs = @hash.dup
+ end
+
+ it "returns self" do
+ @hash.transform_values!(&:succ).should.equal?(@hash)
+ end
+
+ it "updates self as transformed values with the given block" do
+ @hash.transform_values!(&:succ)
+ @hash.should == { a: 2, b: 3, c: 4 }
+ end
+
+ it "partially modifies the contents if we broke from the block" do
+ @hash.transform_values! do |v|
+ break if v == 3
+ 100 + v
end
+ @hash.should == { a: 101, b: 102, c: 3}
+ end
- context "when no block is given" do
- it "returns a sized Enumerator" do
- enumerator = @hash.transform_values!
- enumerator.should be_an_instance_of(Enumerator)
- enumerator.size.should == @hash.size
- enumerator.each(&:succ)
- @hash.should == { a: 2, b: 3, c: 4 }
- end
+ context "when no block is given" do
+ it "returns a sized Enumerator" do
+ enumerator = @hash.transform_values!
+ enumerator.should.instance_of?(Enumerator)
+ enumerator.size.should == @hash.size
+ enumerator.each(&:succ)
+ @hash.should == { a: 2, b: 3, c: 4 }
end
+ end
- describe "on frozen instance" do
- before :each do
- @hash.freeze
- end
+ describe "on frozen instance" do
+ before :each do
+ @hash.freeze
+ end
- it "raises a RuntimeError on an empty hash" do
- ->{ {}.freeze.transform_values!(&:succ) }.should raise_error(RuntimeError)
- end
+ it "raises a FrozenError on an empty hash" do
+ ->{ {}.freeze.transform_values!(&:succ) }.should.raise(FrozenError)
+ end
- it "keeps pairs and raises a RuntimeError" do
- ->{ @hash.transform_values!(&:succ) }.should raise_error(RuntimeError)
- @hash.should == @initial_pairs
- end
+ it "keeps pairs and raises a FrozenError" do
+ ->{ @hash.transform_values!(&:succ) }.should.raise(FrozenError)
+ @hash.should == @initial_pairs
+ end
- context "when no block is given" do
- it "does not raise an exception" do
- @hash.transform_values!.should be_an_instance_of(Enumerator)
- end
+ context "when no block is given" do
+ it "does not raise an exception" do
+ @hash.transform_values!.should.instance_of?(Enumerator)
end
end
end
diff --git a/spec/ruby/core/hash/try_convert_spec.rb b/spec/ruby/core/hash/try_convert_spec.rb
index 818b08fb32..c321183356 100644
--- a/spec/ruby/core/hash/try_convert_spec.rb
+++ b/spec/ruby/core/hash/try_convert_spec.rb
@@ -1,50 +1,50 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Hash.try_convert" do
it "returns the argument if it's a Hash" do
x = Hash.new
- Hash.try_convert(x).should equal(x)
+ Hash.try_convert(x).should.equal?(x)
end
it "returns the argument if it's a kind of Hash" do
x = HashSpecs::MyHash.new
- Hash.try_convert(x).should equal(x)
+ Hash.try_convert(x).should.equal?(x)
end
it "returns nil when the argument does not respond to #to_hash" do
- Hash.try_convert(Object.new).should be_nil
+ Hash.try_convert(Object.new).should == nil
end
it "sends #to_hash to the argument and returns the result if it's nil" do
obj = mock("to_hash")
obj.should_receive(:to_hash).and_return(nil)
- Hash.try_convert(obj).should be_nil
+ Hash.try_convert(obj).should == nil
end
it "sends #to_hash to the argument and returns the result if it's a Hash" do
x = Hash.new
obj = mock("to_hash")
obj.should_receive(:to_hash).and_return(x)
- Hash.try_convert(obj).should equal(x)
+ Hash.try_convert(obj).should.equal?(x)
end
it "sends #to_hash to the argument and returns the result if it's a kind of Hash" do
x = HashSpecs::MyHash.new
obj = mock("to_hash")
obj.should_receive(:to_hash).and_return(x)
- Hash.try_convert(obj).should equal(x)
+ Hash.try_convert(obj).should.equal?(x)
end
it "sends #to_hash to the argument and raises TypeError if it's not a kind of Hash" do
obj = mock("to_hash")
obj.should_receive(:to_hash).and_return(Object.new)
- lambda { Hash.try_convert obj }.should raise_error(TypeError)
+ -> { Hash.try_convert obj }.should raise_consistent_error(TypeError, "can't convert MockObject into Hash (MockObject#to_hash gives Object)")
end
it "does not rescue exceptions raised by #to_hash" do
obj = mock("to_hash")
obj.should_receive(:to_hash).and_raise(RuntimeError)
- lambda { Hash.try_convert obj }.should raise_error(RuntimeError)
+ -> { Hash.try_convert obj }.should.raise(RuntimeError)
end
end
diff --git a/spec/ruby/core/hash/update_spec.rb b/spec/ruby/core/hash/update_spec.rb
index 6cfedea271..04070baad8 100644
--- a/spec/ruby/core/hash/update_spec.rb
+++ b/spec/ruby/core/hash/update_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/update', __FILE__)
+require_relative '../../spec_helper'
describe "Hash#update" do
- it_behaves_like(:hash_update, :update)
+ it "is an alias of Hash#merge!" do
+ Hash.instance_method(:update).should == Hash.instance_method(:merge!)
+ end
end
diff --git a/spec/ruby/core/hash/value_spec.rb b/spec/ruby/core/hash/value_spec.rb
index acfe1968d5..8e4732480f 100644
--- a/spec/ruby/core/hash/value_spec.rb
+++ b/spec/ruby/core/hash/value_spec.rb
@@ -1,8 +1,16 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/value', __FILE__)
+require_relative '../../spec_helper'
describe "Hash#value?" do
- it_behaves_like(:hash_value_p, :value?)
-end
+ it "returns true if the value exists in the hash" do
+ { a: :b }.value?(:a).should == false
+ { 1 => 2 }.value?(2).should == true
+ h = Hash.new(5)
+ h.value?(5).should == false
+ h = Hash.new { 5 }
+ h.value?(5).should == false
+ end
+ it "uses == semantics for comparing values" do
+ { 5 => 2.0 }.value?(2).should == true
+ end
+end
diff --git a/spec/ruby/core/hash/values_at_spec.rb b/spec/ruby/core/hash/values_at_spec.rb
index 7c39e9b573..78dcd8df6a 100644
--- a/spec/ruby/core/hash/values_at_spec.rb
+++ b/spec/ruby/core/hash/values_at_spec.rb
@@ -1,7 +1,11 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/values_at', __FILE__)
+require_relative '../../spec_helper'
describe "Hash#values_at" do
- it_behaves_like(:hash_values_at, :values_at)
+ it "returns an array of values for the given keys" do
+ h = { a: 9, b: 'a', c: -10, d: nil }
+ h.values_at.should.is_a?(Array)
+ h.values_at.should == []
+ h.values_at(:a, :d, :b).should.is_a?(Array)
+ h.values_at(:a, :d, :b).should == [9, nil, 'a']
+ end
end
diff --git a/spec/ruby/core/hash/values_spec.rb b/spec/ruby/core/hash/values_spec.rb
index 4ce2f3f5f0..1fe5f48ad6 100644
--- a/spec/ruby/core/hash/values_spec.rb
+++ b/spec/ruby/core/hash/values_spec.rb
@@ -1,10 +1,10 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Hash#values" do
it "returns an array of values" do
h = { 1 => :a, 'a' => :a, 'the' => 'lang' }
- h.values.should be_kind_of(Array)
+ h.values.should.is_a?(Array)
h.values.sort {|a, b| a.to_s <=> b.to_s}.should == [:a, :a, 'lang']
end
end
diff --git a/spec/ruby/core/integer/abs_spec.rb b/spec/ruby/core/integer/abs_spec.rb
new file mode 100644
index 0000000000..768eebdce2
--- /dev/null
+++ b/spec/ruby/core/integer/abs_spec.rb
@@ -0,0 +1,20 @@
+require_relative '../../spec_helper'
+
+describe "Integer#abs" 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.abs.should == key
+ end
+ end
+ end
+ end
+
+ context "bignum" do
+ it "returns the absolute bignum value" do
+ bignum_value(39).abs.should == 18446744073709551655
+ (-bignum_value(18)).abs.should == 18446744073709551634
+ end
+ end
+end
diff --git a/spec/ruby/core/integer/allbits_spec.rb b/spec/ruby/core/integer/allbits_spec.rb
new file mode 100644
index 0000000000..6023cc32bf
--- /dev/null
+++ b/spec/ruby/core/integer/allbits_spec.rb
@@ -0,0 +1,37 @@
+require_relative '../../spec_helper'
+
+describe "Integer#allbits?" do
+ it "returns true if and only if all the bits of the argument are set in the receiver" do
+ 42.allbits?(42).should == true
+ 0b1010_1010.allbits?(0b1000_0010).should == true
+ 0b1010_1010.allbits?(0b1000_0001).should == false
+ 0b1000_0010.allbits?(0b1010_1010).should == false
+ (0b1010_1010 | bignum_value).allbits?(0b1000_0010 | bignum_value).should == true
+ (0b1010_1010 | bignum_value).allbits?(0b1000_0001 | bignum_value).should == false
+ (0b1000_0010 | bignum_value).allbits?(0b1010_1010 | bignum_value).should == false
+ end
+
+ it "handles negative values using two's complement notation" do
+ (~0b1).allbits?(42).should == true
+ (-42).allbits?(-42).should == true
+ (~0b1010_1010).allbits?(~0b1110_1011).should == true
+ (~0b1010_1010).allbits?(~0b1000_0010).should == false
+ (~(0b1010_1010 | bignum_value)).allbits?(~(0b1110_1011 | bignum_value)).should == true
+ (~(0b1010_1010 | bignum_value)).allbits?(~(0b1000_0010 | bignum_value)).should == false
+ end
+
+ it "coerces the rhs using to_int" do
+ obj = mock("the int 0b10")
+ obj.should_receive(:to_int).and_return(0b10)
+ 0b110.allbits?(obj).should == true
+ end
+
+ it "raises a TypeError when given a non-Integer" do
+ -> {
+ (obj = mock('10')).should_receive(:coerce).any_number_of_times.and_return([42,10])
+ 13.allbits?(obj)
+ }.should.raise(TypeError)
+ -> { 13.allbits?("10") }.should.raise(TypeError)
+ -> { 13.allbits?(:symbol) }.should.raise(TypeError)
+ end
+end
diff --git a/spec/ruby/core/integer/anybits_spec.rb b/spec/ruby/core/integer/anybits_spec.rb
new file mode 100644
index 0000000000..1ea47b76dc
--- /dev/null
+++ b/spec/ruby/core/integer/anybits_spec.rb
@@ -0,0 +1,36 @@
+require_relative '../../spec_helper'
+
+describe "Integer#anybits?" do
+ it "returns true if and only if all the bits of the argument are set in the receiver" do
+ 42.anybits?(42).should == true
+ 0b1010_1010.anybits?(0b1000_0010).should == true
+ 0b1010_1010.anybits?(0b1000_0001).should == true
+ 0b1000_0010.anybits?(0b0010_1100).should == false
+ different_bignum = (2 * bignum_value) & (~bignum_value)
+ (0b1010_1010 | different_bignum).anybits?(0b1000_0010 | bignum_value).should == true
+ (0b1010_1010 | different_bignum).anybits?(0b0010_1100 | bignum_value).should == true
+ (0b1000_0010 | different_bignum).anybits?(0b0010_1100 | bignum_value).should == false
+ end
+
+ it "handles negative values using two's complement notation" do
+ (~42).anybits?(42).should == false
+ (-42).anybits?(-42).should == true
+ (~0b100).anybits?(~0b1).should == true
+ (~(0b100 | bignum_value)).anybits?(~(0b1 | bignum_value)).should == true
+ end
+
+ it "coerces the rhs using to_int" do
+ obj = mock("the int 0b10")
+ obj.should_receive(:to_int).and_return(0b10)
+ 0b110.anybits?(obj).should == true
+ end
+
+ it "raises a TypeError when given a non-Integer" do
+ -> {
+ (obj = mock('10')).should_receive(:coerce).any_number_of_times.and_return([42,10])
+ 13.anybits?(obj)
+ }.should.raise(TypeError)
+ -> { 13.anybits?("10") }.should.raise(TypeError)
+ -> { 13.anybits?(:symbol) }.should.raise(TypeError)
+ end
+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..4098ad7c7b
--- /dev/null
+++ b/spec/ruby/core/integer/bit_and_spec.rb
@@ -0,0 +1,97 @@
+require_relative '../../spec_helper'
+
+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([6, 3])
+ (6 & obj).should == 2
+ end
+
+ it "raises a TypeError when passed a Float" do
+ -> { (3 & 3.4) }.should.raise(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)
+
+ -> { 3 & obj }.should.raise(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 == 18446744073709551617
+
+ ((2*bignum_value) & 1).should == 0
+ ((2*bignum_value) & (2*bignum_value)).should == 36893488147419103232
+ 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 == 18446744073709551617
+ (@bignum & -@bignum).should == 1
+ (@bignum & -0x8000000000000000).should == 18446744073709551616
+ end
+
+ it "returns self bitwise AND other when both operands are negative" do
+ (-@bignum & -0x4000000000000005).should == -23058430092136939525
+ (-@bignum & -@bignum).should == -18446744073709551621
+ (-@bignum & -0x4000000000000000).should == -23058430092136939520
+ 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
+ -> { (@bignum & 3.4) }.should.raise(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)
+
+ -> { @bignum & obj }.should.raise(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..827007b7e0
--- /dev/null
+++ b/spec/ruby/core/integer/bit_length_spec.rb
@@ -0,0 +1,76 @@
+require_relative '../../spec_helper'
+
+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..c380cd729e
--- /dev/null
+++ b/spec/ruby/core/integer/bit_or_spec.rb
@@ -0,0 +1,89 @@
+require_relative '../../spec_helper'
+
+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 == 0x1_0000_0000_0000_ffff
+ end
+
+ it "returns self bitwise OR other when one operand is negative" do
+ ((1 << 33) | -1).should == -1
+ (-1 | (1 << 33)).should == -1
+
+ ((-(1<<33)-1) | 5).should == -8589934593
+ (5 | (-(1<<33)-1)).should == -8589934593
+ end
+
+ it "returns self bitwise OR other when both operands are negative" do
+ (-5 | -1).should == -1
+ (-3 | -4).should == -3
+ (-12 | -13).should == -9
+ (-13 | -12).should == -9
+ end
+
+ it "returns self bitwise OR a bignum" do
+ (-1 | 2**64).should == -1
+ end
+
+ it "coerces the rhs and calls #coerce" do
+ obj = mock("fixnum bit or")
+ obj.should_receive(:coerce).with(6).and_return([6, 3])
+ (6 | obj).should == 7
+ end
+
+ it "raises a TypeError when passed a Float" do
+ -> { (3 | 3.4) }.should.raise(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)
+
+ -> { 3 | obj }.should.raise(TypeError)
+ end
+ end
+
+ context "bignum" do
+ before :each do
+ @bignum = bignum_value(11)
+ end
+
+ it "returns self bitwise OR other" do
+ (@bignum | 2).should == 18446744073709551627
+ (@bignum | 9).should == 18446744073709551627
+ (@bignum | bignum_value).should == 18446744073709551627
+ end
+
+ it "returns self bitwise OR other when one operand is negative" do
+ (@bignum | -0x40000000000000000).should == -55340232221128654837
+ (@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 == -18446744073709551627
+ (-@bignum | -0x4000000000000000).should == -11
+ end
+
+ it "raises a TypeError when passed a Float" do
+ not_supported_on :opal do
+ -> {
+ bignum_value | bignum_value(0xffff).to_f
+ }.should.raise(TypeError)
+ end
+ -> { @bignum | 9.9 }.should.raise(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)
+
+ -> { @bignum | obj }.should.raise(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..c0cf8405f7
--- /dev/null
+++ b/spec/ruby/core/integer/bit_xor_spec.rb
@@ -0,0 +1,93 @@
+require_relative '../../spec_helper'
+
+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 == 0x1_0000_0000_ffff_fffa
+ end
+
+ it "returns self bitwise XOR other when one operand is negative" do
+ ((1 << 33) ^ -1).should == -8589934593
+ (-1 ^ (1 << 33)).should == -8589934593
+
+ ((-(1<<33)-1) ^ 5).should == -8589934598
+ (5 ^ (-(1<<33)-1)).should == -8589934598
+ end
+
+ it "returns self bitwise XOR other when both operands are negative" do
+ (-5 ^ -1).should == 4
+ (-3 ^ -4).should == 1
+ (-12 ^ -13).should == 7
+ (-13 ^ -12).should == 7
+ end
+
+ it "returns self bitwise EXCLUSIVE OR a bignum" do
+ (-1 ^ 2**64).should == -18446744073709551617
+ end
+
+ it "coerces the rhs and calls #coerce" do
+ obj = mock("fixnum bit xor")
+ obj.should_receive(:coerce).with(6).and_return([6, 3])
+ (6 ^ obj).should == 5
+ end
+
+ it "raises a TypeError when passed a Float" do
+ -> { (3 ^ 3.4) }.should.raise(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)
+
+ -> { 3 ^ obj }.should.raise(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 == 18446744073709551632
+ (@bignum ^ @bignum).should == 0
+ (@bignum ^ 14).should == 18446744073709551644
+ end
+
+ it "returns self bitwise EXCLUSIVE OR other when one operand is negative" do
+ (@bignum ^ -0x40000000000000000).should == -55340232221128654830
+ (@bignum ^ -@bignum).should == -4
+ (@bignum ^ -0x8000000000000000).should == -27670116110564327406
+ end
+
+ it "returns self bitwise EXCLUSIVE OR other when both operands are negative" do
+ (-@bignum ^ -0x40000000000000000).should == 55340232221128654830
+ (-@bignum ^ -@bignum).should == 0
+ (-@bignum ^ -0x4000000000000000).should == 23058430092136939502
+ 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
+ -> {
+ bignum_value ^ bignum_value(0xffff).to_f
+ }.should.raise(TypeError)
+ end
+ -> { @bignum ^ 14.5 }.should.raise(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)
+
+ -> { @bignum ^ obj }.should.raise(TypeError)
+ end
+ end
+end
diff --git a/spec/ruby/core/integer/case_compare_spec.rb b/spec/ruby/core/integer/case_compare_spec.rb
new file mode 100644
index 0000000000..1e0c6cb411
--- /dev/null
+++ b/spec/ruby/core/integer/case_compare_spec.rb
@@ -0,0 +1,7 @@
+require_relative '../../spec_helper'
+
+describe "Integer#===" do
+ it "is an alias of Integer#==" do
+ Integer.instance_method(:===).should == Integer.instance_method(:==)
+ end
+end
diff --git a/spec/ruby/core/integer/ceil_spec.rb b/spec/ruby/core/integer/ceil_spec.rb
index 31c56f378d..395be58fbd 100644
--- a/spec/ruby/core/integer/ceil_spec.rb
+++ b/spec/ruby/core/integer/ceil_spec.rb
@@ -1,21 +1,13 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/to_i', __FILE__)
-require File.expand_path('../shared/integer_rounding', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/to_i'
+require_relative 'shared/integer_rounding'
+require_relative 'shared/integer_ceil_precision'
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
- it "returns the smallest integer greater than self with at least precision.abs trailing zeros" do
- 18.ceil(-1).should eql(20)
- 18.ceil(-2).should eql(100)
- 18.ceil(-3).should eql(1000)
- -1832.ceil(-1).should eql(-1830)
- -1832.ceil(-2).should eql(-1800)
- -1832.ceil(-3).should eql(-1000)
- end
- end
+ context "with precision" do
+ it_behaves_like :integer_ceil_precision, :Integer
end
end
diff --git a/spec/ruby/core/integer/ceildiv_spec.rb b/spec/ruby/core/integer/ceildiv_spec.rb
new file mode 100644
index 0000000000..91f63832f8
--- /dev/null
+++ b/spec/ruby/core/integer/ceildiv_spec.rb
@@ -0,0 +1,20 @@
+require_relative '../../spec_helper'
+
+describe "Integer#ceildiv" do
+ it "returns a quotient of division which is rounded up to the nearest integer" do
+ 0.ceildiv(3).should.eql?(0)
+ 1.ceildiv(3).should.eql?(1)
+ 3.ceildiv(3).should.eql?(1)
+ 4.ceildiv(3).should.eql?(2)
+
+ 4.ceildiv(-3).should.eql?(-1)
+ -4.ceildiv(3).should.eql?(-1)
+ -4.ceildiv(-3).should.eql?(2)
+
+ 3.ceildiv(1.2).should.eql?(3)
+ 3.ceildiv(6/5r).should.eql?(3)
+
+ (10**100-11).ceildiv(10**99-1).should.eql?(10)
+ (10**100-9).ceildiv(10**99-1).should.eql?(11)
+ end
+end
diff --git a/spec/ruby/core/integer/chr_spec.rb b/spec/ruby/core/integer/chr_spec.rb
index 50a678608e..72784e1833 100644
--- a/spec/ruby/core/integer/chr_spec.rb
+++ b/spec/ruby/core/integer/chr_spec.rb
@@ -1,17 +1,21 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Integer#chr without argument" do
it "returns a String" do
- 17.chr.should be_an_instance_of(String)
+ 17.chr.should.instance_of?(String)
end
it "returns a new String for each call" do
- 82.chr.should_not equal(82.chr)
+ 82.chr.should_not.equal?(82.chr)
end
it "raises a RangeError is self is less than 0" do
- lambda { -1.chr }.should raise_error(RangeError)
- lambda { -bignum_value.chr }.should raise_error(RangeError)
+ -> { -1.chr }.should.raise(RangeError, /-1 out of char range/)
+ -> { (-bignum_value).chr }.should.raise(RangeError, /bignum out of char range/)
+ end
+
+ it "raises a RangeError if self is too large" do
+ -> { 2206368128.chr(Encoding::UTF_8) }.should.raise(RangeError, /2206368128 out of char range/)
end
describe "when Encoding.default_internal is nil" do
@@ -30,9 +34,9 @@ describe "Integer#chr without argument" do
end
describe "and self is between 128 and 255 (inclusive)" do
- it "returns an ASCII-8BIT String" do
+ it "returns a binary String" do
(128..255).each do |c|
- c.chr.encoding.should == Encoding::ASCII_8BIT
+ c.chr.encoding.should == Encoding::BINARY
end
end
@@ -44,8 +48,8 @@ describe "Integer#chr without argument" do
end
it "raises a RangeError is self is greater than 255" do
- lambda { 256.chr }.should raise_error(RangeError)
- lambda { bignum_value.chr }.should raise_error(RangeError)
+ -> { 256.chr }.should.raise(RangeError, /256 out of char range/)
+ -> { bignum_value.chr }.should.raise(RangeError, /bignum out of char range/)
end
end
@@ -81,13 +85,13 @@ describe "Integer#chr without argument" do
end
describe "and self is between 128 and 255 (inclusive)" do
- it "returns an ASCII-8BIT String" do
+ it "returns a binary String" do
(128..255).each do |c|
Encoding.default_internal = Encoding::UTF_8
- c.chr.encoding.should == Encoding::ASCII_8BIT
+ c.chr.encoding.should == Encoding::BINARY
Encoding.default_internal = Encoding::SHIFT_JIS
- c.chr.encoding.should == Encoding::ASCII_8BIT
+ c.chr.encoding.should == Encoding::BINARY
end
end
@@ -126,14 +130,14 @@ describe "Integer#chr without argument" do
# #5864
it "raises RangeError if self is invalid as a codepoint in the default internal encoding" do
[ [0x0100, "US-ASCII"],
- [0x0100, "ASCII-8BIT"],
+ [0x0100, "BINARY"],
[0x0100, "EUC-JP"],
[0xA1A0, "EUC-JP"],
[0x0100, "ISO-8859-9"],
[620, "TIS-620"]
].each do |integer, encoding_name|
Encoding.default_internal = Encoding.find(encoding_name)
- lambda { integer.chr }.should raise_error(RangeError)
+ -> { integer.chr }.should.raise(RangeError, /(invalid codepoint|out of char range)/)
end
end
end
@@ -142,15 +146,15 @@ end
describe "Integer#chr with an encoding argument" do
it "returns a String" do
- 900.chr(Encoding::UTF_8).should be_an_instance_of(String)
+ 900.chr(Encoding::UTF_8).should.instance_of?(String)
end
it "returns a new String for each call" do
- 8287.chr(Encoding::UTF_8).should_not equal(8287.chr(Encoding::UTF_8))
+ 8287.chr(Encoding::UTF_8).should_not.equal?(8287.chr(Encoding::UTF_8))
end
it "accepts a String as an argument" do
- lambda { 0xA4A2.chr('euc-jp') }.should_not raise_error
+ -> { 0xA4A2.chr('euc-jp') }.should_not.raise
end
it "converts a String to an Encoding as Encoding.find does" do
@@ -161,18 +165,22 @@ describe "Integer#chr with an encoding argument" do
# http://redmine.ruby-lang.org/issues/4869
it "raises a RangeError is self is less than 0" do
- lambda { -1.chr(Encoding::UTF_8) }.should raise_error(RangeError)
- lambda { -bignum_value.chr(Encoding::EUC_JP) }.should raise_error(RangeError)
+ -> { -1.chr(Encoding::UTF_8) }.should.raise(RangeError, /-1 out of char range/)
+ -> { (-bignum_value).chr(Encoding::EUC_JP) }.should.raise(RangeError, /bignum out of char range/)
+ end
+
+ it "raises a RangeError if self is too large" do
+ -> { 2206368128.chr(Encoding::UTF_8) }.should.raise(RangeError, /2206368128 out of char range/)
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
- 0x0000.chr(Encoding::ASCII_8BIT).encoding.should == Encoding::ASCII_8BIT
- 0x007F.chr(Encoding::ASCII_8BIT).encoding.should == Encoding::ASCII_8BIT
- 0x0080.chr(Encoding::ASCII_8BIT).encoding.should == Encoding::ASCII_8BIT
- 0x00FF.chr(Encoding::ASCII_8BIT).encoding.should == Encoding::ASCII_8BIT
+ 0x0000.chr(Encoding::BINARY).encoding.should == Encoding::BINARY
+ 0x007F.chr(Encoding::BINARY).encoding.should == Encoding::BINARY
+ 0x0080.chr(Encoding::BINARY).encoding.should == Encoding::BINARY
+ 0x00FF.chr(Encoding::BINARY).encoding.should == Encoding::BINARY
0x0000.chr(Encoding::UTF_8).encoding.should == Encoding::UTF_8
0x007F.chr(Encoding::UTF_8).encoding.should == Encoding::UTF_8
@@ -193,10 +201,10 @@ describe "Integer#chr with an encoding argument" do
0x0000.chr(Encoding::US_ASCII).bytes.to_a.should == [0x00]
0x007F.chr(Encoding::US_ASCII).bytes.to_a.should == [0x7F]
- 0x0000.chr(Encoding::ASCII_8BIT).bytes.to_a.should == [0x00]
- 0x007F.chr(Encoding::ASCII_8BIT).bytes.to_a.should == [0x7F]
- 0x0080.chr(Encoding::ASCII_8BIT).bytes.to_a.should == [0x80]
- 0x00FF.chr(Encoding::ASCII_8BIT).bytes.to_a.should == [0xFF]
+ 0x0000.chr(Encoding::BINARY).bytes.to_a.should == [0x00]
+ 0x007F.chr(Encoding::BINARY).bytes.to_a.should == [0x7F]
+ 0x0080.chr(Encoding::BINARY).bytes.to_a.should == [0x80]
+ 0x00FF.chr(Encoding::BINARY).bytes.to_a.should == [0xFF]
0x0000.chr(Encoding::UTF_8).bytes.to_a.should == [0x00]
0x007F.chr(Encoding::UTF_8).bytes.to_a.should == [0x7F]
@@ -215,25 +223,35 @@ describe "Integer#chr with an encoding argument" do
# #5864
it "raises RangeError if self is invalid as a codepoint in the specified encoding" do
- [ [0x80, "US-ASCII"],
- [0x0100, "ASCII-8BIT"],
- [0x0100, "EUC-JP"],
- [0xA1A0, "EUC-JP"],
- [0xA1, "EUC-JP"],
- [0x80, "SHIFT_JIS"],
- [0xE0, "SHIFT_JIS"],
- [0x0100, "ISO-8859-9"],
- [620, "TIS-620"],
- [0xD800, "UTF-8"],
- [0xDBFF, "UTF-8"],
- [0xDC00, "UTF-8"],
- [0xDFFF, "UTF-8"],
- [0xD800, "UTF-16"],
- [0xDBFF, "UTF-16"],
- [0xDC00, "UTF-16"],
- [0xDFFF, "UTF-16"],
- ].each do |integer, encoding_name|
- lambda { integer.chr(encoding_name) }.should raise_error(RangeError)
- end
+ -> { 0x80.chr("US-ASCII") }.should.raise(RangeError)
+ -> { 0x0100.chr("BINARY") }.should.raise(RangeError)
+ -> { 0x0100.chr("EUC-JP") }.should.raise(RangeError)
+ -> { 0xA1A0.chr("EUC-JP") }.should.raise(RangeError)
+ -> { 0xA1.chr("EUC-JP") }.should.raise(RangeError)
+ -> { 0x80.chr("SHIFT_JIS") }.should.raise(RangeError)
+ -> { 0xE0.chr("SHIFT_JIS") }.should.raise(RangeError)
+ -> { 0x0100.chr("ISO-8859-9") }.should.raise(RangeError)
+ -> { 620.chr("TIS-620") }.should.raise(RangeError)
+ # UTF-16 surrogate range
+ -> { 0xD800.chr("UTF-8") }.should.raise(RangeError)
+ -> { 0xDBFF.chr("UTF-8") }.should.raise(RangeError)
+ -> { 0xDC00.chr("UTF-8") }.should.raise(RangeError)
+ -> { 0xDFFF.chr("UTF-8") }.should.raise(RangeError)
+ # UTF-16 surrogate range
+ -> { 0xD800.chr("UTF-16") }.should.raise(RangeError)
+ -> { 0xDBFF.chr("UTF-16") }.should.raise(RangeError)
+ -> { 0xDC00.chr("UTF-16") }.should.raise(RangeError)
+ -> { 0xDFFF.chr("UTF-16") }.should.raise(RangeError)
+ end
+
+ it 'returns a String encoding self interpreted as a codepoint in the CESU-8 encoding' do
+ # see more details here https://en.wikipedia.org/wiki/CESU-8
+ # code points from U+0000 to U+FFFF is encoded in the same way as in UTF-8
+ 0x0045.chr(Encoding::CESU_8).bytes.should == 0x0045.chr(Encoding::UTF_8).bytes
+
+ # code points in range from U+10000 to U+10FFFF is CESU-8 data containing a 6-byte surrogate pair,
+ # which decodes to a 4-byte UTF-8 string
+ 0x10400.chr(Encoding::CESU_8).bytes.should != 0x10400.chr(Encoding::UTF_8).bytes
+ 0x10400.chr(Encoding::CESU_8).bytes.to_a.should == [0xED, 0xA0, 0x81, 0xED, 0xB0, 0x80]
end
end
diff --git a/spec/ruby/core/integer/coerce_spec.rb b/spec/ruby/core/integer/coerce_spec.rb
new file mode 100644
index 0000000000..c0e642da03
--- /dev/null
+++ b/spec/ruby/core/integer/coerce_spec.rb
@@ -0,0 +1,91 @@
+require_relative '../../spec_helper'
+
+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 == [Integer, Integer]
+ end
+ end
+
+ describe "when given a String" do
+ it "raises an ArgumentError when trying to coerce with a non-number String" do
+ -> { 1.coerce(":)") }.should.raise(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
+ -> { 1.coerce(nil) }.should.raise(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')
+ -> { 2.coerce(obj).should == [1.0, 2.0] }.should.raise(TypeError)
+ end
+
+ it "raises a TypeError when given an Object that does not respond to #to_f" do
+ -> { 1.coerce(mock('x')) }.should.raise(TypeError)
+ -> { 1.coerce(1..4) }.should.raise(TypeError)
+ -> { 1.coerce(:test) }.should.raise(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.is_a?(Integer)
+ ary[1].should.is_a?(Integer)
+ 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.is_a?(Integer)
+ ary[1].should.is_a?(Integer)
+ ary.should == [b, a]
+ end
+
+ it "raises a TypeError when not passed a Fixnum or Bignum" do
+ a = bignum_value
+
+ -> { a.coerce(nil) }.should.raise(TypeError)
+ -> { a.coerce(mock('str')) }.should.raise(TypeError)
+ -> { a.coerce(1..4) }.should.raise(TypeError)
+ -> { a.coerce(:test) }.should.raise(TypeError)
+ end
+
+ it "coerces both values to Floats and returns [other, self] when passed a Float" do
+ a = bignum_value
+ a.coerce(1.2).should == [1.2, a.to_f]
+ end
+
+ 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/integer/comparison_spec.rb b/spec/ruby/core/integer/comparison_spec.rb
new file mode 100644
index 0000000000..cc5cbe2506
--- /dev/null
+++ b/spec/ruby/core/integer/comparison_spec.rb
@@ -0,0 +1,185 @@
+require_relative '../../spec_helper'
+
+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 Integer#<=>")
+ end
+
+ it "calls #coerce on other" do
+ @num.should_receive(:coerce).with(@big).and_return([@big.to_f, 2.5])
+ @big <=> @num
+ end
+
+ it "lets the exception go through if #coerce raises an exception" do
+ @num.should_receive(:coerce).with(@big).and_raise(RuntimeError.new("my error"))
+ -> {
+ @big <=> @num
+ }.should.raise(RuntimeError, "my error")
+ end
+
+ it "raises an exception if #coerce raises a non-StandardError exception" do
+ @num.should_receive(:coerce).with(@big).and_raise(Exception)
+ -> { @big <=> @num }.should.raise(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 == 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
+
+ describe "with a Float" do
+ it "does not lose precision for values that don't fit in a double" do
+ (bignum_value(1) <=> bignum_value.to_f).should == 1
+ (bignum_value <=> bignum_value.to_f).should == 0
+ ((bignum_value - 1) <=> bignum_value.to_f).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 Infinity" 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..baf5e6c457
--- /dev/null
+++ b/spec/ruby/core/integer/complement_spec.rb
@@ -0,0 +1,20 @@
+require_relative '../../spec_helper'
+
+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 == -18446744073709551665
+ (~(-bignum_value(21))).should == 18446744073709551636
+ (~bignum_value(1)).should == -18446744073709551618
+ end
+ end
+end
diff --git a/spec/ruby/core/integer/constants_spec.rb b/spec/ruby/core/integer/constants_spec.rb
new file mode 100644
index 0000000000..937806c72f
--- /dev/null
+++ b/spec/ruby/core/integer/constants_spec.rb
@@ -0,0 +1,13 @@
+require_relative '../../spec_helper'
+
+describe "Fixnum" do
+ it "is no longer defined" do
+ Object.should_not.const_defined?(:Fixnum)
+ end
+end
+
+describe "Bignum" do
+ it "is no longer defined" do
+ Object.should_not.const_defined?(:Bignum)
+ end
+end
diff --git a/spec/ruby/core/integer/denominator_spec.rb b/spec/ruby/core/integer/denominator_spec.rb
index 6d080ac81f..c1477d0757 100644
--- a/spec/ruby/core/integer/denominator_spec.rb
+++ b/spec/ruby/core/integer/denominator_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Integer#denominator" do
# The Numeric child classes override this method, so their behaviour is
diff --git a/spec/ruby/core/integer/digits_spec.rb b/spec/ruby/core/integer/digits_spec.rb
index 3546a654eb..c4ebf2cd88 100644
--- a/spec/ruby/core/integer/digits_spec.rb
+++ b/spec/ruby/core/integer/digits_spec.rb
@@ -1,34 +1,41 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-ruby_version_is "2.4" do
- describe "Integer#digits" do
- it "returns an array of place values in base-10 by default" do
- 12345.digits.should == [5,4,3,2,1]
- end
-
- it "returns digits by place value of a given radix" do
- 12345.digits(7).should == [4,6,6,0,5]
- end
-
- it "converts the radix with #to_int" do
- 12345.digits(mock_int(2)).should == [1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1]
- end
-
- it "returns [0] when called on 0, regardless of base" do
- 0.digits.should == [0]
- 0.digits(7).should == [0]
- end
-
- it "raises ArgumentError when calling with a radix less than 2" do
- lambda { 12345.digits(1) }.should raise_error(ArgumentError)
- end
-
- it "raises ArgumentError when calling with a negative radix" do
- lambda { 12345.digits(-2) }.should raise_error(ArgumentError)
- end
-
- it "raises Math::DomainError when calling digits on a negative number" do
- lambda { -12345.digits(7) }.should raise_error(Math::DomainError)
- end
+require_relative '../../spec_helper'
+
+describe "Integer#digits" do
+ it "returns an array of place values in base-10 by default" do
+ 12345.digits.should == [5,4,3,2,1]
+ end
+
+ it "returns digits by place value of a given radix" do
+ 12345.digits(7).should == [4,6,6,0,5]
+ end
+
+ it "converts the radix with #to_int" do
+ 12345.digits(mock_int(2)).should == [1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1]
+ end
+
+ it "returns [0] when called on 0, regardless of base" do
+ 0.digits.should == [0]
+ 0.digits(7).should == [0]
+ end
+
+ it "raises ArgumentError when calling with a radix less than 2" do
+ -> { 12345.digits(1) }.should.raise(ArgumentError)
+ end
+
+ it "raises ArgumentError when calling with a negative radix" do
+ -> { 12345.digits(-2) }.should.raise(ArgumentError)
+ end
+
+ it "raises Math::DomainError when calling digits on a negative number" do
+ -> { -12345.digits(7) }.should.raise(Math::DomainError)
+ end
+
+ it "returns integer values > 9 when base is above 10" do
+ 1234.digits(16).should == [2, 13, 4]
+ end
+
+ it "can be used with base > 37" do
+ 1234.digits(100).should == [34, 12]
+ 980099.digits(100).should == [99, 0, 98]
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..220ca4a73e
--- /dev/null
+++ b/spec/ruby/core/integer/div_spec.rb
@@ -0,0 +1,154 @@
+require_relative '../../spec_helper'
+
+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 Integer" 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
+ -> { 0.div(0.0) }.should.raise(ZeroDivisionError)
+ -> { 10.div(0.0) }.should.raise(ZeroDivisionError)
+ -> { -10.div(0.0) }.should.raise(ZeroDivisionError)
+ end
+
+ it "raises a ZeroDivisionError when the given argument is 0 and not a Float" do
+ -> { 13.div(0) }.should.raise(ZeroDivisionError)
+ -> { 13.div(-0) }.should.raise(ZeroDivisionError)
+ end
+
+ it "raises a TypeError when given a non-numeric argument" do
+ -> { 13.div(mock('10')) }.should.raise(TypeError)
+ -> { 5.div("2") }.should.raise(TypeError)
+ -> { 5.div(:"2") }.should.raise(TypeError)
+ -> { 5.div([]) }.should.raise(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 == 4611686018427387926
+ @bignum.div(Rational(4, 1)).should == 4611686018427387926
+ @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 "handles fixnum_min / -1" do
+ (fixnum_min / -1).should == -fixnum_min
+ (fixnum_min / -1).should > 0
+
+ int_min = -2147483648
+ (int_min / -1).should == 2147483648
+ 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
+ -> { @bignum.div(mock("10")) }.should.raise(TypeError)
+ -> { @bignum.div("2") }.should.raise(TypeError)
+ -> { @bignum.div(:symbol) }.should.raise(TypeError)
+ end
+
+ it "returns a result of integer division of self by a float argument" do
+ @bignum.div(4294967295.5).should.eql?(4294967296)
+ not_supported_on :opal do
+ @bignum.div(4294967295.0).should.eql?(4294967297)
+ @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
+ -> { @bignum.div(0.0) }.should.raise(ZeroDivisionError)
+ -> { @bignum.div(-0.0) }.should.raise(ZeroDivisionError)
+ end
+
+ it "raises ZeroDivisionError if the argument is 0 and is not a Float" do
+ -> { @bignum.div(0) }.should.raise(ZeroDivisionError)
+ -> { @bignum.div(-0) }.should.raise(ZeroDivisionError)
+ end
+ end
+
+ context "rational" do
+ it "returns self divided by the given argument as an Integer" do
+ 2.div(6/5r).should == 1
+ 1.div(6/5r).should == 0
+ 5.div(6/5r).should == 4
+ end
+ end
+end
diff --git a/spec/ruby/core/integer/divide_spec.rb b/spec/ruby/core/integer/divide_spec.rb
new file mode 100644
index 0000000000..e75432fd83
--- /dev/null
+++ b/spec/ruby/core/integer/divide_spec.rb
@@ -0,0 +1,126 @@
+require_relative '../../spec_helper'
+require_relative 'shared/arithmetic_coerce'
+
+describe "Integer#/" do
+ it_behaves_like :integer_arithmetic_coerce_not_rescue, :/
+
+ 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
+ (-1 / 10**10).should == -1
+ (-1 / 10**20).should == -1
+ end
+
+ it "preservers sign correctly" do
+ (4 / 3).should == 1
+ (4 / -3).should == -2
+ (-4 / 3).should == -2
+ (-4 / -3).should == 1
+ (0 / -3).should == 0
+ (0 / 3).should == 0
+ 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
+ -> { 1 / 0 }.should.raise(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
+ -> { 13 / mock('10') }.should.raise(TypeError)
+ -> { 13 / "10" }.should.raise(TypeError)
+ -> { 13 / :symbol }.should.raise(TypeError)
+ end
+ end
+
+ context "bignum" do
+ before :each do
+ @bignum = bignum_value(88)
+ end
+
+ it "returns self divided by other" do
+ (@bignum / 4).should == 4611686018427387926
+
+ (@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 "preservers sign correctly" do
+ (4 / bignum_value).should == 0
+ (4 / -bignum_value).should == -1
+ (-4 / bignum_value).should == -1
+ (-4 / -bignum_value).should == 0
+ (0 / bignum_value).should == 0
+ (0 / -bignum_value).should == 0
+ end
+
+ it "returns self divided by Float" do
+ not_supported_on :opal do
+ (bignum_value(88) / 4294967295.0).should be_close(4294967297.0, TOLERANCE)
+ end
+ (bignum_value(88) / 4294967295.5).should be_close(4294967296.5, TOLERANCE)
+ end
+
+ it "returns result the same class as the argument" do
+ (@bignum / 4).should == 4611686018427387926
+ (@bignum / 4.0).should be_close(4611686018427387926, TOLERANCE)
+ (@bignum / Rational(4, 1)).should == Rational(4611686018427387926, 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
+ -> { @bignum / 0 }.should.raise(ZeroDivisionError)
+ end
+
+ it "raises a TypeError when given a non-numeric" do
+ -> { @bignum / mock('10') }.should.raise(TypeError)
+ -> { @bignum / "2" }.should.raise(TypeError)
+ -> { @bignum / :symbol }.should.raise(TypeError)
+ end
+ end
+
+ it "coerces the RHS and calls #coerce" do
+ obj = mock("integer plus")
+ obj.should_receive(:coerce).with(6).and_return([6, 3])
+ (6 / obj).should == 2
+ end
+
+ it "coerces the RHS and calls #coerce even if it's private" do
+ obj = Object.new
+ class << obj
+ private def coerce(n)
+ [n, 3]
+ end
+ end
+
+ (6 / obj).should == 2
+ end
+end
diff --git a/spec/ruby/core/integer/divmod_spec.rb b/spec/ruby/core/integer/divmod_spec.rb
new file mode 100644
index 0000000000..db470c5731
--- /dev/null
+++ b/spec/ruby/core/integer/divmod_spec.rb
@@ -0,0 +1,117 @@
+require_relative '../../spec_helper'
+
+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
+ -> { 13.divmod(0) }.should.raise(ZeroDivisionError)
+ -> { 0.divmod(0) }.should.raise(ZeroDivisionError)
+ -> { -10.divmod(0) }.should.raise(ZeroDivisionError)
+ end
+
+ it "raises a ZeroDivisionError when the given argument is 0 and a Float" do
+ -> { 0.divmod(0.0) }.should.raise(ZeroDivisionError)
+ -> { 10.divmod(0.0) }.should.raise(ZeroDivisionError)
+ -> { -10.divmod(0.0) }.should.raise(ZeroDivisionError)
+ end
+
+ it "raises a TypeError when given a non-Integer" do
+ -> {
+ (obj = mock('10')).should_receive(:to_int).any_number_of_times.and_return(10)
+ 13.divmod(obj)
+ }.should.raise(TypeError)
+ -> { 13.divmod("10") }.should.raise(TypeError)
+ -> { 13.divmod(:symbol) }.should.raise(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 == [4611686018427387917, 3]
+ @bignum.divmod(13).should == [1418980313362273205, 6]
+
+ @bignum.divmod(4.5).should == [4099276460824344576, 2.5]
+
+ not_supported_on :opal do
+ @bignum.divmod(4.0).should == [4611686018427387904, 0.0]
+ @bignum.divmod(13.0).should == [1418980313362273280, 3.0]
+
+ @bignum.divmod(2.0).should == [9223372036854775808, 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
+ -> { @bignum.divmod(0) }.should.raise(ZeroDivisionError)
+ -> { (-@bignum).divmod(0) }.should.raise(ZeroDivisionError)
+ end
+
+ # Behaviour established as correct in r23953
+ it "raises a FloatDomainError if other is NaN" do
+ -> { @bignum.divmod(nan_value) }.should.raise(FloatDomainError)
+ end
+
+ it "raises a ZeroDivisionError when the given argument is 0 and a Float" do
+ -> { @bignum.divmod(0.0) }.should.raise(ZeroDivisionError)
+ -> { (-@bignum).divmod(0.0) }.should.raise(ZeroDivisionError)
+ end
+
+ it "raises a TypeError when the given argument is not an Integer" do
+ -> { @bignum.divmod(mock('10')) }.should.raise(TypeError)
+ -> { @bignum.divmod("10") }.should.raise(TypeError)
+ -> { @bignum.divmod(:symbol) }.should.raise(TypeError)
+ end
+ end
+end
diff --git a/spec/ruby/core/integer/downto_spec.rb b/spec/ruby/core/integer/downto_spec.rb
index 6b7b353760..a244d3df55 100644
--- a/spec/ruby/core/integer/downto_spec.rb
+++ b/spec/ruby/core/integer/downto_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
-describe "Integer#downto [stop] when self and stop are Fixnums" do
+describe "Integer#downto [stop] when self and stop are Integers" do
it "does not yield when stop is greater than self" do
result = []
5.downto(6) { |x| result << x }
@@ -27,8 +27,8 @@ describe "Integer#downto [stop] when self and stop are Fixnums" do
end
it "raises an ArgumentError for invalid endpoints" do
- lambda {1.downto("A") {|x| p x } }.should raise_error(ArgumentError)
- lambda {1.downto(nil) {|x| p x } }.should raise_error(ArgumentError)
+ -> {1.downto("A") {|x| p x } }.should.raise(ArgumentError)
+ -> {1.downto(nil) {|x| p x } }.should.raise(ArgumentError)
end
describe "when no block is given" do
@@ -45,9 +45,9 @@ describe "Integer#downto [stop] when self and stop are Fixnums" do
describe "size" do
it "raises an ArgumentError for invalid endpoints" do
enum = 1.downto("A")
- lambda { enum.size }.should raise_error(ArgumentError)
+ -> { enum.size }.should.raise(ArgumentError)
enum = 1.downto(nil)
- lambda { enum.size }.should raise_error(ArgumentError)
+ -> { enum.size }.should.raise(ArgumentError)
end
it "returns self - stop + 1" do
diff --git a/spec/ruby/core/integer/dup_spec.rb b/spec/ruby/core/integer/dup_spec.rb
index f46bdf89bd..3e5739ad37 100644
--- a/spec/ruby/core/integer/dup_spec.rb
+++ b/spec/ruby/core/integer/dup_spec.rb
@@ -1,10 +1,13 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
-ruby_version_is '2.4' do
- describe "Integer#dup" do
- it "returns self" do
- int = 2
- int.dup.should equal(int)
- end
+describe "Integer#dup" do
+ it "returns self for small integers" do
+ integer = 1_000
+ integer.dup.should.equal?(integer)
+ end
+
+ it "returns self for large integers" do
+ integer = 4_611_686_018_427_387_905
+ integer.dup.should.equal?(integer)
end
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..c69ec2315d
--- /dev/null
+++ b/spec/ruby/core/integer/element_reference_spec.rb
@@ -0,0 +1,188 @@
+require_relative '../../spec_helper'
+
+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
+ -> { 3["3"] }.should.raise(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")
+ -> { 3[obj] }.should.raise(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
+
+ context "when index and length passed" do
+ it "returns specified number of bits from specified position" do
+ 0b101001101[2, 4].should == 0b0011
+ 0b101001101[2, 5].should == 0b10011
+ 0b101001101[2, 7].should == 0b1010011
+ end
+
+ it "ensures n[i, len] equals to (n >> i) & ((1 << len) - 1)" do
+ n = 0b101001101; i = 2; len = 4
+ n[i, len].should == (n >> i) & ((1 << len) - 1)
+ end
+
+ it "moves start position to the most significant bits when negative index passed" do
+ 0b000001[-1, 4].should == 0b10
+ 0b000001[-2, 4].should == 0b100
+ 0b000001[-3, 4].should == 0b1000
+ end
+
+ it "ignores negative length" do
+ 0b101001101[1, -1].should == 0b10100110
+ 0b101001101[2, -1].should == 0b1010011
+ 0b101001101[3, -1].should == 0b101001
+
+ 0b101001101[3, -5].should == 0b101001
+ 0b101001101[3, -15].should == 0b101001
+ 0b101001101[3, -125].should == 0b101001
+ end
+ end
+
+ context "when range passed" do
+ it "returns bits specified by range" do
+ 0b101001101[2..5].should == 0b0011
+ 0b101001101[2..6].should == 0b10011
+ 0b101001101[2..8].should == 0b1010011
+ end
+
+ it "ensures n[i..j] equals to (n >> i) & ((1 << (j - i + 1)) - 1)" do
+ n = 0b101001101; i = 2; j = 5
+ n[i..j].should == (n >> i) & ((1 << (j - i + 1)) - 1)
+ end
+
+ it "ensures n[i..] equals to (n >> i)" do
+ eval("0b101001101[3..]").should == 0b101001101 >> 3
+ end
+
+ it "moves lower boundary to the most significant bits when negative value passed" do
+ 0b000001[-1, 4].should == 0b10
+ 0b000001[-2, 4].should == 0b100
+ 0b000001[-3, 4].should == 0b1000
+ end
+
+ it "ignores upper boundary smaller than lower boundary" do
+ 0b101001101[4..1].should == 0b10100
+ 0b101001101[4..2].should == 0b10100
+ 0b101001101[-4..-5].should == 0b1010011010000
+ end
+
+ it "raises FloatDomainError if any boundary is infinity" do
+ -> { 0x0001[3..Float::INFINITY] }.should.raise(FloatDomainError, /Infinity/)
+ -> { 0x0001[-Float::INFINITY..3] }.should.raise(FloatDomainError, /-Infinity/)
+ end
+
+ context "when passed (..i)" do
+ it "returns 0 if all i bits equal 0" do
+ eval("0b10000[..1]").should == 0
+ eval("0b10000[..2]").should == 0
+ eval("0b10000[..3]").should == 0
+ end
+
+ it "raises ArgumentError if any of i bit equals 1" do
+ -> {
+ eval("0b111110[..3]")
+ }.should.raise(ArgumentError, /The beginless range for Integer#\[\] results in infinity/)
+ end
+ end
+ 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')
+ -> { @bignum[obj] }.should.raise(TypeError)
+
+ obj.should_receive(:to_int).and_return("asdf")
+ -> { @bignum[obj] }.should.raise(TypeError)
+ end
+ end
+end
diff --git a/spec/ruby/core/integer/eql_spec.rb b/spec/ruby/core/integer/eql_spec.rb
new file mode 100644
index 0000000000..9c80173206
--- /dev/null
+++ b/spec/ruby/core/integer/eql_spec.rb
@@ -0,0 +1,25 @@
+require_relative '../../spec_helper'
+
+describe "Integer#eql?" do
+ context "bignum" do
+ it "returns true for the same value" do
+ bignum_value.eql?(bignum_value).should == true
+ end
+
+ it "returns false for a different Integer value" do
+ bignum_value.eql?(bignum_value(1)).should == false
+ end
+
+ it "returns false for a Float with the same numeric value" do
+ bignum_value.eql?(bignum_value.to_f).should == false
+ end
+
+ it "returns false for a Rational with the same numeric value" do
+ bignum_value.eql?(Rational(bignum_value)).should == false
+ end
+
+ it "returns false for a Fixnum-range Integer" do
+ bignum_value.eql?(42).should == false
+ end
+ end
+end
diff --git a/spec/ruby/core/integer/equal_value_spec.rb b/spec/ruby/core/integer/equal_value_spec.rb
new file mode 100644
index 0000000000..dc73552267
--- /dev/null
+++ b/spec/ruby/core/integer/equal_value_spec.rb
@@ -0,0 +1,65 @@
+require_relative '../../spec_helper'
+
+describe "Integer#==" do
+ context "fixnum" do
+ it "returns true if self has the same value as other" do
+ (1 == 1).should == true
+ (9 == 5).should == false
+
+ # Actually, these call Float#==, Integer#== etc.
+ (9 == 9.0).should == true
+ (9 == 9.01).should == false
+
+ (10 == bignum_value).should == false
+ end
+
+ it "calls 'other == self' if the given argument is not an Integer" do
+ (1 == '*').should == false
+
+ obj = mock('one other')
+ obj.should_receive(:==).any_number_of_times.and_return(false)
+ (1 == obj).should == false
+
+ obj = mock('another')
+ obj.should_receive(:==).any_number_of_times.and_return(true)
+ (2 == 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 == @bignum).should == true
+ (@bignum == @bignum.to_f).should == true
+
+ (@bignum == @bignum + 1).should == false
+ ((@bignum + 1) == @bignum).should == false
+
+ (@bignum == 9).should == false
+ (@bignum == 9.01).should == false
+
+ (@bignum == 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 == 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 == obj).should == true
+ (@bignum == obj).should == false
+ end
+
+ it "does not lose precision when comparing with a Float" do
+ ((bignum_value(1) == bignum_value.to_f)).should == false
+ ((bignum_value == bignum_value.to_f)).should == true
+ end
+ end
+end
diff --git a/spec/ruby/core/integer/even_spec.rb b/spec/ruby/core/integer/even_spec.rb
index c14cf84947..578979320e 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__)
+require_relative '../../spec_helper'
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 == true
+ (-1).even?.should == false
- 0.even?.should be_true
- 1.even?.should be_false
- 2.even?.should be_true
+ 0.even?.should == true
+ 1.even?.should == false
+ 2.even?.should == true
+ end
+
+ it "returns true for a Bignum when it is an even number" do
+ bignum_value(0).even?.should == true
+ bignum_value(1).even?.should == false
+
+ (-bignum_value(0)).even?.should == true
+ (-bignum_value(1)).even?.should == 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 == true
+ end
+
+ it "returns true if self is even and negative" do
+ (-10000**10).even?.should == true
+ end
+
+ it "returns false if self is odd and positive" do
+ (9879**976).even?.should == 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 == 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..c610661aff
--- /dev/null
+++ b/spec/ruby/core/integer/exponent_spec.rb
@@ -0,0 +1,7 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/exponent'
+
+describe "Integer#**" do
+ it_behaves_like :integer_exponent, :**
+end
diff --git a/spec/ruby/core/integer/fdiv_spec.rb b/spec/ruby/core/integer/fdiv_spec.rb
new file mode 100644
index 0000000000..7854d66dec
--- /dev/null
+++ b/spec/ruby/core/integer/fdiv_spec.rb
@@ -0,0 +1,100 @@
+require_relative '../../spec_helper'
+
+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
+ 8.fdiv(bignum_value).should be_close(8.673617379884035e-19, TOLERANCE)
+ end
+
+ it "performs floating-point division between self bignum and a bignum" do
+ num = 1000000000000000000000000000000000048148248609680896326399448564623182963452541226153892315137780403285956264146010000000000000000000000000000000000048148248609680896326399448564623182963452541226153892315137780403285956264146010000000000000000000000000000000000048148248609680896326399448564623182963452541226153892315137780403285956264146009
+ den = 2000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+ num.fdiv(den).should == 500.0
+ end
+
+ it "rounds to the correct value for bignums" do
+ den = 9 * 10**342
+
+ num = 1 * 10**344
+ num.fdiv(den).should == 11.11111111111111
+
+ num = 1 * 10**343
+ num.fdiv(den).should == 1.1111111111111112
+
+ num = 1 * 10**342
+ num.fdiv(den).should == 0.1111111111111111
+
+ num = 2 * 10**342
+ num.fdiv(den).should == 0.2222222222222222
+
+ num = 3 * 10**342
+ num.fdiv(den).should == 0.3333333333333333
+
+ num = 4 * 10**342
+ num.fdiv(den).should == 0.4444444444444444
+
+ num = 5 * 10**342
+ num.fdiv(den).should == 0.5555555555555556
+
+ num = 6 * 10**342
+ num.fdiv(den).should == 0.6666666666666666
+
+ num = 7 * 10**342
+ num.fdiv(den).should == 0.7777777777777778
+
+ num = 8 * 10**342
+ num.fdiv(den).should == 0.8888888888888888
+
+ num = 9 * 10**342
+ num.fdiv(den).should == 1.0
+
+ num = -5 * 10**342
+ num.fdiv(den).should == -0.5555555555555556
+ end
+
+ it "rounds to the correct float for bignum denominators" do
+ 1.fdiv(10**324).should == 0.0
+ 1.fdiv(10**323).should == 1.0e-323
+ end
+
+ it "performs floating-point division between self and a Float" do
+ 8.fdiv(9.0).should be_close(0.888888888888889, TOLERANCE)
+ end
+
+ it "returns NaN when the argument is NaN" do
+ -1.fdiv(nan_value).nan?.should == true
+ 1.fdiv(nan_value).nan?.should == true
+ end
+
+ it "returns Infinity when the argument is 0" do
+ 1.fdiv(0).infinite?.should == 1
+ end
+
+ it "returns -Infinity when the argument is 0 and self is negative" do
+ -1.fdiv(0).infinite?.should == -1
+ end
+
+ it "returns Infinity when the argument is 0.0" do
+ 1.fdiv(0.0).infinite?.should == 1
+ end
+
+ it "returns -Infinity when the argument is 0.0 and self is negative" do
+ -1.fdiv(0.0).infinite?.should == -1
+ end
+
+ it "raises a TypeError when argument isn't numeric" do
+ -> { 1.fdiv(mock('non-numeric')) }.should.raise(TypeError)
+ end
+
+ it "raises an ArgumentError when passed multiple arguments" do
+ -> { 1.fdiv(6,0.2) }.should.raise(ArgumentError)
+ end
+
+ it "follows the coercion protocol" do
+ (obj = mock('10')).should_receive(:coerce).with(1).and_return([1, 10])
+ 1.fdiv(obj).should == 0.1
+ end
+end
diff --git a/spec/ruby/core/integer/fixtures/classes.rb b/spec/ruby/core/integer/fixtures/classes.rb
new file mode 100644
index 0000000000..65948efb9f
--- /dev/null
+++ b/spec/ruby/core/integer/fixtures/classes.rb
@@ -0,0 +1,14 @@
+module IntegerSpecs
+ class CoerceError < StandardError
+ end
+
+ class CoercibleNumeric
+ def initialize(v) @v = v end
+ def coerce(other) [self.class.new(other), self] end
+ def >(other) @v.to_i > other.to_i end
+ def >=(other) @v.to_i >= other.to_i end
+ def <(other) @v.to_i < other.to_i end
+ def <=(other) @v.to_i <= other.to_i end
+ def to_i() @v.to_i end
+ end
+end
diff --git a/spec/ruby/core/integer/floor_spec.rb b/spec/ruby/core/integer/floor_spec.rb
index 9babcd9a3e..8fb84d58cb 100644
--- a/spec/ruby/core/integer/floor_spec.rb
+++ b/spec/ruby/core/integer/floor_spec.rb
@@ -1,21 +1,13 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/to_i', __FILE__)
-require File.expand_path('../shared/integer_rounding', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/to_i'
+require_relative 'shared/integer_rounding'
+require_relative 'shared/integer_floor_precision'
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
- it "returns the largest integer less than self with at least precision.abs trailing zeros" do
- 1832.floor(-1).should eql(1830)
- 1832.floor(-2).should eql(1800)
- 1832.floor(-3).should eql(1000)
- -1832.floor(-1).should eql(-1840)
- -1832.floor(-2).should eql(-1900)
- -1832.floor(-3).should eql(-2000)
- end
- end
+ context "with precision" do
+ it_behaves_like :integer_floor_precision, :Integer
end
end
diff --git a/spec/ruby/core/integer/gcd_spec.rb b/spec/ruby/core/integer/gcd_spec.rb
index 5428c94ad1..1fff785927 100644
--- a/spec/ruby/core/integer/gcd_spec.rb
+++ b/spec/ruby/core/integer/gcd_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Integer#gcd" do
it "returns self if equal to the argument" do
@@ -7,8 +7,8 @@ describe "Integer#gcd" do
end
it "returns an Integer" do
- 36.gcd(6).should be_kind_of(Integer)
- 4.gcd(20981).should be_kind_of(Integer)
+ 36.gcd(6).should.is_a?(Integer)
+ 4.gcd(20981).should.is_a?(Integer)
end
it "returns the greatest common divisor of self and argument" do
@@ -33,26 +33,37 @@ describe "Integer#gcd" do
it "accepts a Bignum argument" do
bignum = 9999**99
- bignum.should be_kind_of(Bignum)
+ bignum.should.is_a?(Integer)
99.gcd(bignum).should == 99
end
it "works if self is a Bignum" do
bignum = 9999**99
- bignum.should be_kind_of(Bignum)
+ bignum.should.is_a?(Integer)
bignum.gcd(99).should == 99
end
+ it "doesn't cause an integer overflow" do
+ [2 ** (1.size * 8 - 2), 0x8000000000000000].each do |max|
+ [max - 1, max, max + 1].each do |num|
+ num.gcd(num).should == num
+ (-num).gcd(num).should == num
+ (-num).gcd(-num).should == num
+ num.gcd(-num).should == num
+ end
+ end
+ end
+
it "raises an ArgumentError if not given an argument" do
- lambda { 12.gcd }.should raise_error(ArgumentError)
+ -> { 12.gcd }.should.raise(ArgumentError)
end
it "raises an ArgumentError if given more than one argument" do
- lambda { 12.gcd(30, 20) }.should raise_error(ArgumentError)
+ -> { 12.gcd(30, 20) }.should.raise(ArgumentError)
end
it "raises a TypeError unless the argument is an Integer" do
- lambda { 39.gcd(3.8) }.should raise_error(TypeError)
- lambda { 45872.gcd([]) }.should raise_error(TypeError)
+ -> { 39.gcd(3.8) }.should.raise(TypeError)
+ -> { 45872.gcd([]) }.should.raise(TypeError)
end
end
diff --git a/spec/ruby/core/integer/gcdlcm_spec.rb b/spec/ruby/core/integer/gcdlcm_spec.rb
index 86968499b0..419bf9f275 100644
--- a/spec/ruby/core/integer/gcdlcm_spec.rb
+++ b/spec/ruby/core/integer/gcdlcm_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Integer#gcdlcm" do
it "returns [self, self] if self is equal to the argument" do
@@ -7,8 +7,8 @@ describe "Integer#gcdlcm" do
end
it "returns an Array" do
- 36.gcdlcm(6).should be_kind_of(Array)
- 4.gcdlcm(20981).should be_kind_of(Array)
+ 36.gcdlcm(6).should.is_a?(Array)
+ 4.gcdlcm(20981).should.is_a?(Array)
end
it "returns a two-element Array" do
@@ -28,26 +28,26 @@ describe "Integer#gcdlcm" do
it "accepts a Bignum argument" do
bignum = 91999**99
- bignum.should be_kind_of(Bignum)
+ bignum.should.is_a?(Integer)
99.gcdlcm(bignum).should == [99.gcd(bignum), 99.lcm(bignum)]
end
it "works if self is a Bignum" do
bignum = 9999**89
- bignum.should be_kind_of(Bignum)
+ bignum.should.is_a?(Integer)
bignum.gcdlcm(99).should == [bignum.gcd(99), bignum.lcm(99)]
end
it "raises an ArgumentError if not given an argument" do
- lambda { 12.gcdlcm }.should raise_error(ArgumentError)
+ -> { 12.gcdlcm }.should.raise(ArgumentError)
end
it "raises an ArgumentError if given more than one argument" do
- lambda { 12.gcdlcm(30, 20) }.should raise_error(ArgumentError)
+ -> { 12.gcdlcm(30, 20) }.should.raise(ArgumentError)
end
it "raises a TypeError unless the argument is an Integer" do
- lambda { 39.gcdlcm(3.8) }.should raise_error(TypeError)
- lambda { 45872.gcdlcm([]) }.should raise_error(TypeError)
+ -> { 39.gcdlcm(3.8) }.should.raise(TypeError)
+ -> { 45872.gcdlcm([]) }.should.raise(TypeError)
end
end
diff --git a/spec/ruby/core/integer/gt_spec.rb b/spec/ruby/core/integer/gt_spec.rb
new file mode 100644
index 0000000000..75436144cf
--- /dev/null
+++ b/spec/ruby/core/integer/gt_spec.rb
@@ -0,0 +1,48 @@
+require_relative '../../spec_helper'
+require_relative 'shared/comparison_coerce'
+
+describe "Integer#>" do
+ it_behaves_like :integer_comparison_coerce_not_rescue, :>
+
+ 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
+ -> { 5 > "4" }.should.raise(ArgumentError)
+ -> { 5 > mock('x') }.should.raise(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
+ -> { @bignum > "4" }.should.raise(ArgumentError)
+ -> { @bignum > mock('str') }.should.raise(ArgumentError)
+ end
+
+ it "dispatches the correct operator after coercion" do
+ (bignum_value > IntegerSpecs::CoercibleNumeric.new(1)).should == true
+ (bignum_value > IntegerSpecs::CoercibleNumeric.new(bignum_value * 2)).should == false
+ end
+ end
+end
diff --git a/spec/ruby/core/integer/gte_spec.rb b/spec/ruby/core/integer/gte_spec.rb
new file mode 100644
index 0000000000..e5cb892efd
--- /dev/null
+++ b/spec/ruby/core/integer/gte_spec.rb
@@ -0,0 +1,48 @@
+require_relative '../../spec_helper'
+require_relative 'shared/comparison_coerce'
+
+describe "Integer#>=" do
+ it_behaves_like :integer_comparison_coerce_not_rescue, :>=
+
+ 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
+ -> { 5 >= "4" }.should.raise(ArgumentError)
+ -> { 5 >= mock('x') }.should.raise(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
+ -> { @bignum >= "4" }.should.raise(ArgumentError)
+ -> { @bignum >= mock('str') }.should.raise(ArgumentError)
+ end
+
+ it "dispatches the correct operator after coercion" do
+ (bignum_value >= IntegerSpecs::CoercibleNumeric.new(1)).should == true
+ (bignum_value >= IntegerSpecs::CoercibleNumeric.new(bignum_value * 2)).should == false
+ end
+ end
+end
diff --git a/spec/ruby/core/integer/inspect_spec.rb b/spec/ruby/core/integer/inspect_spec.rb
new file mode 100644
index 0000000000..0b0d5cc7a9
--- /dev/null
+++ b/spec/ruby/core/integer/inspect_spec.rb
@@ -0,0 +1,7 @@
+require_relative '../../spec_helper'
+
+describe "Integer#inspect" do
+ it "is an alias of Integer#to_s" do
+ Integer.instance_method(:inspect).should == Integer.instance_method(:to_s)
+ end
+end
diff --git a/spec/ruby/core/integer/integer_spec.rb b/spec/ruby/core/integer/integer_spec.rb
index 393f072563..19a962d548 100644
--- a/spec/ruby/core/integer/integer_spec.rb
+++ b/spec/ruby/core/integer/integer_spec.rb
@@ -1,22 +1,20 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Integer" do
it "includes Comparable" do
Integer.include?(Comparable).should == true
end
- ruby_version_is "2.4" do
- it "is the class of both small and large integers" do
- 42.class.should equal(Integer)
- bignum_value.class.should equal(Integer)
- end
+ it "is the class of both small and large integers" do
+ 42.class.should.equal?(Integer)
+ bignum_value.class.should.equal?(Integer)
end
end
describe "Integer#integer?" do
it "returns true for Integers" do
- 0.integer?.should == true
- -1.integer?.should == true
- bignum_value.integer?.should == true
+ 0.should.integer?
+ -1.should.integer?
+ bignum_value.should.integer?
end
end
diff --git a/spec/ruby/core/integer/lcm_spec.rb b/spec/ruby/core/integer/lcm_spec.rb
index ddf25d3853..6659247d1e 100644
--- a/spec/ruby/core/integer/lcm_spec.rb
+++ b/spec/ruby/core/integer/lcm_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Integer#lcm" do
it "returns self if equal to the argument" do
@@ -7,8 +7,8 @@ describe "Integer#lcm" do
end
it "returns an Integer" do
- 36.lcm(6).should be_kind_of(Integer)
- 4.lcm(20981).should be_kind_of(Integer)
+ 36.lcm(6).should.is_a?(Integer)
+ 4.lcm(20981).should.is_a?(Integer)
end
it "returns the least common multiple of self and argument" do
@@ -33,26 +33,26 @@ describe "Integer#lcm" do
it "accepts a Bignum argument" do
bignum = 9999**99
- bignum.should be_kind_of(Bignum)
+ bignum.should.is_a?(Integer)
99.lcm(bignum).should == bignum
end
it "works if self is a Bignum" do
bignum = 9999**99
- bignum.should be_kind_of(Bignum)
+ bignum.should.is_a?(Integer)
bignum.lcm(99).should == bignum
end
it "raises an ArgumentError if not given an argument" do
- lambda { 12.lcm }.should raise_error(ArgumentError)
+ -> { 12.lcm }.should.raise(ArgumentError)
end
it "raises an ArgumentError if given more than one argument" do
- lambda { 12.lcm(30, 20) }.should raise_error(ArgumentError)
+ -> { 12.lcm(30, 20) }.should.raise(ArgumentError)
end
it "raises a TypeError unless the argument is an Integer" do
- lambda { 39.lcm(3.8) }.should raise_error(TypeError)
- lambda { 45872.lcm([]) }.should raise_error(TypeError)
+ -> { 39.lcm(3.8) }.should.raise(TypeError)
+ -> { 45872.lcm([]) }.should.raise(TypeError)
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..7eedb91228
--- /dev/null
+++ b/spec/ruby/core/integer/left_shift_spec.rb
@@ -0,0 +1,211 @@
+require_relative '../../spec_helper'
+
+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 a Bignum == fixnum_max * 2 when fixnum_max << 1 and n > 0" do
+ result = fixnum_max << 1
+ result.should.instance_of?(Integer)
+ 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.instance_of?(Integer)
+ 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
+
+ obj = mock("to_int_neg_bignum")
+ obj.should_receive(:to_int).and_return(-bignum_value)
+ (3 << obj).should == 0
+ 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")
+
+ -> { 3 << obj }.should.raise(TypeError)
+ end
+
+ it "raises a TypeError when passed nil" do
+ -> { 3 << nil }.should.raise(TypeError)
+ end
+
+ it "raises a TypeError when passed a String" do
+ -> { 3 << "4" }.should.raise(TypeError)
+ end
+ end
+
+ context "bignum" do
+ before :each do
+ @bignum = bignum_value * 8 # 2 ** 67
+ 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 a Fixnum == fixnum_max when (fixnum_max * 2) << -1 and n > 0" do
+ result = (fixnum_max * 2) << -1
+ result.should.instance_of?(Integer)
+ 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.instance_of?(Integer)
+ 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")
+
+ -> { @bignum << obj }.should.raise(TypeError)
+ end
+
+ it "raises a TypeError when passed nil" do
+ -> { @bignum << nil }.should.raise(TypeError)
+ end
+
+ it "raises a TypeError when passed a String" do
+ -> { @bignum << "4" }.should.raise(TypeError)
+ end
+ end
+
+ context "when m is a bignum or larger than int" do
+ it "returns -1 when m < 0 and n < 0" do
+ (-1 << -bignum_value).should == -1
+ (-1 << -(2**40)).should == -1
+
+ (-bignum_value << -bignum_value).should == -1
+ (-bignum_value << -(2**40)).should == -1
+ end
+
+ it "returns 0 when m < 0 and n >= 0" do
+ (0 << -bignum_value).should == 0
+ (1 << -bignum_value).should == 0
+ (bignum_value << -bignum_value).should == 0
+
+ (0 << -(2**40)).should == 0
+ (1 << -(2**40)).should == 0
+ (bignum_value << -(2**40)).should == 0
+ end
+
+ it "returns 0 when m > 0 long and n == 0" do
+ (0 << (2**40)).should == 0
+ end
+
+ it "returns 0 when m > 0 bignum and n == 0" do
+ (0 << bignum_value).should == 0
+ end
+
+ it "raises RangeError when m > 0 and n != 0" do
+ # https://bugs.ruby-lang.org/issues/18518#note-9
+ limit = RUBY_ENGINE == 'ruby' ? 2**67 : 2**32
+
+ coerce_long = mock("long")
+ coerce_long.stub!(:to_int).and_return(limit)
+ coerce_bignum = mock("bignum")
+ coerce_bignum.stub!(:to_int).and_return(bignum_value)
+ exps = [limit, coerce_long]
+ exps << bignum_value << coerce_bignum if bignum_value >= limit
+
+ exps.each { |exp|
+ -> { (1 << exp) }.should.raise(RangeError, 'shift width too big')
+ -> { (-1 << exp) }.should.raise(RangeError, 'shift width too big')
+ -> { (bignum_value << exp) }.should.raise(RangeError, 'shift width too big')
+ -> { (-bignum_value << exp) }.should.raise(RangeError, 'shift width too big')
+ }
+ end
+ end
+end
diff --git a/spec/ruby/core/integer/lt_spec.rb b/spec/ruby/core/integer/lt_spec.rb
new file mode 100644
index 0000000000..dd1391d093
--- /dev/null
+++ b/spec/ruby/core/integer/lt_spec.rb
@@ -0,0 +1,50 @@
+require_relative '../../spec_helper'
+require_relative 'shared/comparison_coerce'
+
+describe "Integer#<" do
+ it_behaves_like :integer_comparison_coerce_not_rescue, :<
+
+ 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
+ -> { 5 < "4" }.should.raise(ArgumentError)
+ -> { 5 < mock('x') }.should.raise(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
+ -> { @bignum < "4" }.should.raise(ArgumentError)
+ -> { @bignum < mock('str') }.should.raise(ArgumentError)
+ end
+
+ it "dispatches the correct operator after coercion" do
+ (bignum_value < IntegerSpecs::CoercibleNumeric.new(bignum_value * 2)).should == true
+ (bignum_value < IntegerSpecs::CoercibleNumeric.new(1)).should == false
+ end
+ end
+end
diff --git a/spec/ruby/core/integer/lte_spec.rb b/spec/ruby/core/integer/lte_spec.rb
new file mode 100644
index 0000000000..9ef1c9f604
--- /dev/null
+++ b/spec/ruby/core/integer/lte_spec.rb
@@ -0,0 +1,58 @@
+require_relative '../../spec_helper'
+require_relative 'shared/comparison_coerce'
+
+describe "Integer#<=" do
+ it_behaves_like :integer_comparison_coerce_not_rescue, :<=
+
+ 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
+ -> { 5 <= "4" }.should.raise(ArgumentError)
+ -> { 5 <= mock('x') }.should.raise(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 "returns true for bignums compare to a bigger float" do
+ (18446744073709551616 <= 1.8446744073709552e+19).should == true
+ (@bignum <= (@bignum + 9999.0)).should == true
+ end
+
+ it "raises an ArgumentError when given a non-Integer" do
+ -> { @bignum <= "4" }.should.raise(ArgumentError)
+ -> { @bignum <= mock('str') }.should.raise(ArgumentError)
+ end
+
+ it "dispatches the correct operator after coercion" do
+ (bignum_value <= IntegerSpecs::CoercibleNumeric.new(bignum_value * 2)).should == true
+ (bignum_value <= IntegerSpecs::CoercibleNumeric.new(1)).should == false
+ end
+ end
+end
diff --git a/spec/ruby/core/integer/magnitude_spec.rb b/spec/ruby/core/integer/magnitude_spec.rb
new file mode 100644
index 0000000000..000e5be7f7
--- /dev/null
+++ b/spec/ruby/core/integer/magnitude_spec.rb
@@ -0,0 +1,7 @@
+require_relative '../../spec_helper'
+
+describe "Integer#magnitude" do
+ it "is an alias of Integer#abs" do
+ Integer.instance_method(:magnitude).should == Integer.instance_method(:abs)
+ end
+end
diff --git a/spec/ruby/core/integer/minus_spec.rb b/spec/ruby/core/integer/minus_spec.rb
new file mode 100644
index 0000000000..5fd3a81a72
--- /dev/null
+++ b/spec/ruby/core/integer/minus_spec.rb
@@ -0,0 +1,60 @@
+require_relative '../../spec_helper'
+require_relative 'shared/arithmetic_coerce'
+
+describe "Integer#-" do
+ it_behaves_like :integer_arithmetic_coerce_not_rescue, :-
+
+ 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 == -18446744073706991120
+ end
+
+ it "raises a TypeError when given a non-Integer" do
+ -> {
+ (obj = mock('10')).should_receive(:to_int).any_number_of_times.and_return(10)
+ 13 - obj
+ }.should.raise(TypeError)
+ -> { 13 - "10" }.should.raise(TypeError)
+ -> { 13 - :symbol }.should.raise(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 == 18446744073709551921
+ (@bignum - 12.57).should be_close(18446744073709551917.43, TOLERANCE)
+ (@bignum - bignum_value(42)).should == 272
+ end
+
+ it "raises a TypeError when given a non-Integer" do
+ -> { @bignum - mock('10') }.should.raise(TypeError)
+ -> { @bignum - "10" }.should.raise(TypeError)
+ -> { @bignum - :symbol }.should.raise(TypeError)
+ end
+ end
+
+ it "coerces the RHS and calls #coerce" do
+ obj = mock("integer plus")
+ obj.should_receive(:coerce).with(5).and_return([5, 10])
+ (5 - obj).should == -5
+ end
+
+ it "coerces the RHS and calls #coerce even if it's private" do
+ obj = Object.new
+ class << obj
+ private def coerce(n)
+ [n, 10]
+ end
+ end
+
+ (5 - obj).should == -5
+ end
+end
diff --git a/spec/ruby/core/integer/modulo_spec.rb b/spec/ruby/core/integer/modulo_spec.rb
new file mode 100644
index 0000000000..2680f49510
--- /dev/null
+++ b/spec/ruby/core/integer/modulo_spec.rb
@@ -0,0 +1,122 @@
+require_relative '../../spec_helper'
+
+describe "Integer#%" do
+ context "fixnum" do
+ it "returns the modulus obtained from dividing self by the given argument" do
+ # test all possible combinations:
+ # - integer/double/bignum argument
+ # - positive/negative argument
+ # - positive/negative self
+ # - self greater/smaller than argument
+
+ (13 % 4).should == 1
+ (4 % 13).should == 4
+
+ (13 % 4.0).should == 1
+ (4 % 13.0).should == 4
+
+ (-200 % 256).should == 56
+ (-1000 % 512).should == 24
+
+ (-200 % -256).should == -200
+ (-1000 % -512).should == -488
+
+ (200 % -256).should == -56
+ (1000 % -512).should == -24
+
+ (13 % -4.0).should == -3.0
+ (4 % -13.0).should == -9.0
+
+ (-13 % -4.0).should == -1.0
+ (-4 % -13.0).should == -4.0
+
+ (-13 % 4.0).should == 3.0
+ (-4 % 13.0).should == 9.0
+
+ (1 % 2.0).should == 1.0
+ (200 % bignum_value).should == 200
+
+ (4 % bignum_value(10)).should == 4
+ (4 % -bignum_value(10)).should == -18446744073709551622
+ (-4 % bignum_value(10)).should == 18446744073709551622
+ (-4 % -bignum_value(10)).should == -4
+ end
+
+ it "raises a ZeroDivisionError when the given argument is 0" do
+ -> { 13 % 0 }.should.raise(ZeroDivisionError)
+ -> { 0 % 0 }.should.raise(ZeroDivisionError)
+ -> { -10 % 0 }.should.raise(ZeroDivisionError)
+ end
+
+ it "raises a ZeroDivisionError when the given argument is 0 and a Float" do
+ -> { 0 % 0.0 }.should.raise(ZeroDivisionError)
+ -> { 10 % 0.0 }.should.raise(ZeroDivisionError)
+ -> { -10 % 0.0 }.should.raise(ZeroDivisionError)
+ end
+
+ it "raises a TypeError when given a non-Integer" do
+ -> {
+ (obj = mock('10')).should_receive(:to_int).any_number_of_times.and_return(10)
+ 13 % obj
+ }.should.raise(TypeError)
+ -> { 13 % "10" }.should.raise(TypeError)
+ -> { 13 % :symbol }.should.raise(TypeError)
+ end
+ end
+
+ context "bignum" do
+ before :each do
+ @bignum = bignum_value(10)
+ end
+
+ it "returns the modulus obtained from dividing self by the given argument" do
+ # test all possible combinations:
+ # - integer/double/bignum argument
+ # - positive/negative argument
+ # - positive/negative self
+ # - self greater/smaller than argument
+
+ (@bignum % 5).should == 1
+ (@bignum % -5).should == -4
+ (-@bignum % 5).should == 4
+ (-@bignum % -5).should == -1
+
+ (@bignum % 2.22).should be_close(1.5603603603605034, TOLERANCE)
+ (@bignum % -2.22).should be_close(-0.6596396396394968, TOLERANCE)
+ (-@bignum % 2.22).should be_close(0.6596396396394968, TOLERANCE)
+ (-@bignum % -2.22).should be_close(-1.5603603603605034, TOLERANCE)
+
+ (@bignum % (@bignum + 10)).should == 18446744073709551626
+ (@bignum % -(@bignum + 10)).should == -10
+ (-@bignum % (@bignum + 10)).should == 10
+ (-@bignum % -(@bignum + 10)).should == -18446744073709551626
+
+ ((@bignum + 10) % @bignum).should == 10
+ ((@bignum + 10) % -@bignum).should == -18446744073709551616
+ (-(@bignum + 10) % @bignum).should == 18446744073709551616
+ (-(@bignum + 10) % -@bignum).should == -10
+ end
+
+ it "raises a ZeroDivisionError when the given argument is 0" do
+ -> { @bignum % 0 }.should.raise(ZeroDivisionError)
+ -> { -@bignum % 0 }.should.raise(ZeroDivisionError)
+ end
+
+ it "raises a ZeroDivisionError when the given argument is 0 and a Float" do
+ -> { @bignum % 0.0 }.should.raise(ZeroDivisionError)
+ -> { -@bignum % 0.0 }.should.raise(ZeroDivisionError)
+ end
+
+ it "raises a TypeError when given a non-Integer" do
+ -> { @bignum % mock('10') }.should.raise(TypeError)
+ -> { @bignum % "10" }.should.raise(TypeError)
+ -> { @bignum % :symbol }.should.raise(TypeError)
+ end
+ end
+end
+
+describe "Integer#modulo" do
+ it "is an alias of Integer#%" do
+ Integer.instance_method(:modulo).should == Integer.instance_method(:%)
+ end
+end
diff --git a/spec/ruby/core/integer/multiply_spec.rb b/spec/ruby/core/integer/multiply_spec.rb
new file mode 100644
index 0000000000..7f30eebaa5
--- /dev/null
+++ b/spec/ruby/core/integer/multiply_spec.rb
@@ -0,0 +1,45 @@
+require_relative '../../spec_helper'
+require_relative 'shared/arithmetic_coerce'
+
+describe "Integer#*" do
+ it_behaves_like :integer_arithmetic_coerce_not_rescue, :*
+
+ 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 == 4722366482869645213696
+ (6712 * 0.25).should == 1678.0
+ end
+
+ it "raises a TypeError when given a non-Integer" do
+ -> {
+ (obj = mock('10')).should_receive(:to_int).any_number_of_times.and_return(10)
+ 13 * obj
+ }.should.raise(TypeError)
+ -> { 13 * "10" }.should.raise(TypeError)
+ -> { 13 * :symbol }.should.raise(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 == 184467440737095523880
+ (@bignum * (@bignum - 40)).should == 340282366920938491207277694290934407024
+ end
+
+ it "raises a TypeError when given a non-Integer" do
+ -> { @bignum * mock('10') }.should.raise(TypeError)
+ -> { @bignum * "10" }.should.raise(TypeError)
+ -> { @bignum * :symbol }.should.raise(TypeError)
+ end
+ end
+end
diff --git a/spec/ruby/core/integer/next_spec.rb b/spec/ruby/core/integer/next_spec.rb
index a34db0a6f6..da54dec454 100644
--- a/spec/ruby/core/integer/next_spec.rb
+++ b/spec/ruby/core/integer/next_spec.rb
@@ -1,6 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/next', __FILE__)
+require_relative '../../spec_helper'
describe "Integer#next" do
- it_behaves_like(:integer_next, :next)
+ it "is an alias of Integer#succ" do
+ Integer.instance_method(:next).should == Integer.instance_method(:succ)
+ end
end
diff --git a/spec/ruby/core/integer/nobits_spec.rb b/spec/ruby/core/integer/nobits_spec.rb
new file mode 100644
index 0000000000..f1a3aca9d5
--- /dev/null
+++ b/spec/ruby/core/integer/nobits_spec.rb
@@ -0,0 +1,36 @@
+require_relative '../../spec_helper'
+
+describe "Integer#nobits?" do
+ it "returns true if and only if all no bits of the argument are set in the receiver" do
+ 42.nobits?(42).should == false
+ 0b1010_1010.nobits?(0b1000_0010).should == false
+ 0b1010_1010.nobits?(0b1000_0001).should == false
+ 0b0100_0101.nobits?(0b1010_1010).should == true
+ different_bignum = (2 * bignum_value) & (~bignum_value)
+ (0b1010_1010 | different_bignum).nobits?(0b1000_0010 | bignum_value).should == false
+ (0b1010_1010 | different_bignum).nobits?(0b1000_0001 | bignum_value).should == false
+ (0b0100_0101 | different_bignum).nobits?(0b1010_1010 | bignum_value).should == true
+ end
+
+ it "handles negative values using two's complement notation" do
+ (~0b1101).nobits?(0b1101).should == true
+ (-42).nobits?(-42).should == false
+ (~0b1101).nobits?(~0b10).should == false
+ (~(0b1101 | bignum_value)).nobits?(~(0b10 | bignum_value)).should == false
+ end
+
+ it "coerces the rhs using to_int" do
+ obj = mock("the int 0b10")
+ obj.should_receive(:to_int).and_return(0b10)
+ 0b110.nobits?(obj).should == false
+ end
+
+ it "raises a TypeError when given a non-Integer" do
+ -> {
+ (obj = mock('10')).should_receive(:coerce).any_number_of_times.and_return([42,10])
+ 13.nobits?(obj)
+ }.should.raise(TypeError)
+ -> { 13.nobits?("10") }.should.raise(TypeError)
+ -> { 13.nobits?(:symbol) }.should.raise(TypeError)
+ end
+end
diff --git a/spec/ruby/core/integer/numerator_spec.rb b/spec/ruby/core/integer/numerator_spec.rb
index 12550b9a31..f4149d770e 100644
--- a/spec/ruby/core/integer/numerator_spec.rb
+++ b/spec/ruby/core/integer/numerator_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Integer#numerator" do
before :all do
diff --git a/spec/ruby/core/integer/odd_spec.rb b/spec/ruby/core/integer/odd_spec.rb
index 2aa76d054a..f9e50ec790 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__)
+require_relative '../../spec_helper'
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 == false
+ (-1).odd?.should == true
- 0.odd?.should be_false
- 1.odd?.should be_true
- 2.odd?.should be_false
+ 0.odd?.should == false
+ 1.odd?.should == true
+ 2.odd?.should == false
- bignum_value(0).odd?.should be_false
- bignum_value(1).odd?.should be_true
+ bignum_value(0).odd?.should == false
+ bignum_value(1).odd?.should == true
- (-bignum_value(0)).odd?.should be_false
- (-bignum_value(1)).odd?.should be_true
+ (-bignum_value(0)).odd?.should == false
+ (-bignum_value(1)).odd?.should == true
+ end
+ end
+
+ context "bignum" do
+ it "returns true if self is odd and positive" do
+ (987279**19).odd?.should == true
+ end
+
+ it "returns true if self is odd and negative" do
+ (-9873389**97).odd?.should == true
+ end
+
+ it "returns false if self is even and positive" do
+ (10000000**10).odd?.should == false
+ end
+
+ it "returns false if self is even and negative" do
+ (-1000000**100).odd?.should == false
+ end
end
end
diff --git a/spec/ruby/core/integer/ord_spec.rb b/spec/ruby/core/integer/ord_spec.rb
index 5941f513fd..8b7dfe460d 100644
--- a/spec/ruby/core/integer/ord_spec.rb
+++ b/spec/ruby/core/integer/ord_spec.rb
@@ -1,17 +1,17 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Integer#ord" do
it "returns self" do
- 20.ord.should eql(20)
- 40.ord.should eql(40)
+ 20.ord.should.eql?(20)
+ 40.ord.should.eql?(40)
- 0.ord.should eql(0)
- (-10).ord.should eql(-10)
+ 0.ord.should.eql?(0)
+ (-10).ord.should.eql?(-10)
- ?a.ord.should eql(97)
- ?Z.ord.should eql(90)
+ ?a.ord.should.eql?(97)
+ ?Z.ord.should.eql?(90)
- bignum_value.ord.should eql(bignum_value)
- (-bignum_value).ord.should eql(-bignum_value)
+ bignum_value.ord.should.eql?(bignum_value)
+ (-bignum_value).ord.should.eql?(-bignum_value)
end
end
diff --git a/spec/ruby/core/integer/plus_spec.rb b/spec/ruby/core/integer/plus_spec.rb
new file mode 100644
index 0000000000..b684377bd5
--- /dev/null
+++ b/spec/ruby/core/integer/plus_spec.rb
@@ -0,0 +1,75 @@
+require_relative '../../spec_helper'
+require_relative 'shared/arithmetic_coerce'
+
+describe "Integer#+" do
+ it_behaves_like :integer_arithmetic_coerce_not_rescue, :+
+
+ context "fixnum" do
+ it "returns self plus the given Integer" do
+ (491 + 2).should == 493
+ (90210 + 10).should == 90220
+
+ (9 + bignum_value).should == 18446744073709551625
+ (1001 + 5.219).should == 1006.219
+ end
+
+ it "raises a TypeError when given a non-Integer" do
+ -> {
+ (obj = mock('10')).should_receive(:to_int).any_number_of_times.and_return(10)
+ 13 + obj
+ }.should.raise(TypeError)
+ -> { 13 + "10" }.should.raise(TypeError)
+ -> { 13 + :symbol }.should.raise(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 == 18446744073709551696
+ (@bignum + 4.2).should be_close(18446744073709551696.2, TOLERANCE)
+ (@bignum + bignum_value(3)).should == 36893488147419103311
+ end
+
+ it "raises a TypeError when given a non-Integer" do
+ -> { @bignum + mock('10') }.should.raise(TypeError)
+ -> { @bignum + "10" }.should.raise(TypeError)
+ -> { @bignum + :symbol}.should.raise(TypeError)
+ end
+ end
+
+ it "can be redefined" do
+ code = <<~RUBY
+ class Integer
+ alias_method :old_plus, :+
+ def +(other)
+ self - other
+ end
+ end
+ result = 1 + 2
+ Integer.alias_method :+, :old_plus
+ print result
+ RUBY
+ ruby_exe(code).should == "-1"
+ end
+
+ it "coerces the RHS and calls #coerce" do
+ obj = mock("integer plus")
+ obj.should_receive(:coerce).with(6).and_return([6, 3])
+ (6 + obj).should == 9
+ end
+
+ it "coerces the RHS and calls #coerce even if it's private" do
+ obj = Object.new
+ class << obj
+ private def coerce(n)
+ [n, 3]
+ end
+ end
+
+ (6 + obj).should == 9
+ end
+end
diff --git a/spec/ruby/core/integer/pow_spec.rb b/spec/ruby/core/integer/pow_spec.rb
new file mode 100644
index 0000000000..12a3839c40
--- /dev/null
+++ b/spec/ruby/core/integer/pow_spec.rb
@@ -0,0 +1,51 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/exponent'
+
+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
+
+ it "works well with bignums" do
+ 2.pow(61, 5843009213693951).should.eql? 3697379018277258
+ 2.pow(62, 5843009213693952).should.eql? 1551748822859776
+ 2.pow(63, 5843009213693953).should.eql? 3103497645717974
+ 2.pow(64, 5843009213693954).should.eql? 363986077738838
+ end
+
+ it "handles sign like #divmod does" do
+ 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(TypeError, /2nd argument not allowed unless all arguments are integers/)
+ -> { 2.pow(5, Rational(12, 1)) }.should.raise(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(TypeError)
+ -> { 2.pow(5, []) }.should.raise(TypeError)
+ -> { 2.pow(5, nil) }.should.raise(TypeError)
+ end
+
+ it "raises a ZeroDivisionError when the given argument is 0" do
+ -> { 2.pow(5, 0) }.should.raise(ZeroDivisionError)
+ end
+
+ it "raises a RangeError when the first argument is negative and the second argument is present" do
+ -> { 2.pow(-5, 1) }.should.raise(RangeError)
+ end
+ end
+end
diff --git a/spec/ruby/core/integer/pred_spec.rb b/spec/ruby/core/integer/pred_spec.rb
index 8b16a7ae03..fce536b5a2 100644
--- a/spec/ruby/core/integer/pred_spec.rb
+++ b/spec/ruby/core/integer/pred_spec.rb
@@ -1,11 +1,11 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Integer#pred" do
it "returns the Integer equal to self - 1" do
- 0.pred.should eql(-1)
- -1.pred.should eql(-2)
- bignum_value.pred.should eql(bignum_value(-1))
- fixnum_min.pred.should eql(fixnum_min - 1)
- 20.pred.should eql(19)
+ 0.pred.should.eql?(-1)
+ -1.pred.should.eql?(-2)
+ bignum_value.pred.should.eql?(bignum_value(-1))
+ fixnum_min.pred.should.eql?(fixnum_min - 1)
+ 20.pred.should.eql?(19)
end
end
diff --git a/spec/ruby/core/integer/rationalize_spec.rb b/spec/ruby/core/integer/rationalize_spec.rb
index 1ff4cfa454..272eca6911 100644
--- a/spec/ruby/core/integer/rationalize_spec.rb
+++ b/spec/ruby/core/integer/rationalize_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Integer#rationalize" do
before :all do
@@ -12,7 +12,7 @@ describe "Integer#rationalize" do
it "returns a Rational object" do
@numbers.each do |number|
- number.rationalize.should be_an_instance_of(Rational)
+ number.rationalize.should.instance_of?(Rational)
end
end
@@ -33,7 +33,7 @@ describe "Integer#rationalize" do
end
it "raises ArgumentError when passed more than one argument" do
- lambda { 1.rationalize(0.1, 0.1) }.should raise_error(ArgumentError)
- lambda { 1.rationalize(0.1, 0.1, 2) }.should raise_error(ArgumentError)
+ -> { 1.rationalize(0.1, 0.1) }.should.raise(ArgumentError)
+ -> { 1.rationalize(0.1, 0.1, 2) }.should.raise(ArgumentError)
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..deb81fb2a5
--- /dev/null
+++ b/spec/ruby/core/integer/remainder_spec.rb
@@ -0,0 +1,51 @@
+require_relative '../../spec_helper'
+
+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(TypeError)
+ -> { 5.remainder(:"3") }.should.raise(TypeError)
+ -> { 5.remainder([]) }.should.raise(TypeError)
+ -> { 5.remainder(nil) }.should.raise(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(93.1349992295444, TOLERANCE)
+ a.remainder(bignum_value).should == 79
+ end
+
+ it "raises a ZeroDivisionError if other is zero and not a Float" do
+ -> { bignum_value(66).remainder(0) }.should.raise(ZeroDivisionError)
+ end
+
+ it "does raises ZeroDivisionError if other is zero and a Float" do
+ a = bignum_value(7)
+ b = bignum_value(32)
+ -> { a.remainder(0.0) }.should.raise(ZeroDivisionError)
+ -> { b.remainder(-0.0) }.should.raise(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..4281d3b7ab
--- /dev/null
+++ b/spec/ruby/core/integer/right_shift_spec.rb
@@ -0,0 +1,233 @@
+require_relative '../../spec_helper'
+
+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 a Bignum == fixnum_max * 2 when fixnum_max >> -1 and n > 0" do
+ result = fixnum_max >> -1
+ result.should.instance_of?(Integer)
+ 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.instance_of?(Integer)
+ 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
+
+ obj = mock("to_int_bignum")
+ obj.should_receive(:to_int).and_return(bignum_value)
+ (8 >> obj).should == 0
+ 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")
+
+ -> { 3 >> obj }.should.raise(TypeError)
+ end
+
+ it "raises a TypeError when passed nil" do
+ -> { 3 >> nil }.should.raise(TypeError)
+ end
+
+ it "raises a TypeError when passed a String" do
+ -> { 3 >> "4" }.should.raise(TypeError)
+ end
+ end
+
+ context "bignum" do
+ before :each do
+ @bignum = bignum_value * 8 # 2 ** 67
+ 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 a Fixnum == fixnum_max when (fixnum_max * 2) >> 1 and n > 0" do
+ result = (fixnum_max * 2) >> 1
+ result.should.instance_of?(Integer)
+ 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.instance_of?(Integer)
+ 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")
+
+ -> { @bignum >> obj }.should.raise(TypeError)
+ end
+
+ it "raises a TypeError when passed nil" do
+ -> { @bignum >> nil }.should.raise(TypeError)
+ end
+
+ it "raises a TypeError when passed a String" do
+ -> { @bignum >> "4" }.should.raise(TypeError)
+ end
+ end
+
+ context "when m is a bignum or larger than int" do
+ it "returns -1 when m > 0 and n < 0" do
+ (-1 >> bignum_value).should == -1
+ (-1 >> (2**40)).should == -1
+
+ (-bignum_value >> bignum_value).should == -1
+ (-bignum_value >> (2**40)).should == -1
+ end
+
+ it "returns 0 when m > 0 and n >= 0" do
+ (0 >> bignum_value).should == 0
+ (1 >> bignum_value).should == 0
+ (bignum_value >> bignum_value).should == 0
+
+ (0 >> (2**40)).should == 0
+ (1 >> (2**40)).should == 0
+ (bignum_value >> (2**40)).should == 0
+ end
+
+ it "returns 0 when m < 0 long and n == 0" do
+ (0 >> -(2**40)).should == 0
+ end
+
+ it "returns 0 when m < 0 bignum and n == 0" do
+ (0 >> -bignum_value).should == 0
+ end
+
+ it "raises RangeError when m < 0 and n != 0" do
+ # https://bugs.ruby-lang.org/issues/18518#note-9
+ limit = RUBY_ENGINE == 'ruby' ? 2**67 : 2**32
+
+ coerce_long = mock("long")
+ coerce_long.stub!(:to_int).and_return(-limit)
+ coerce_bignum = mock("bignum")
+ coerce_bignum.stub!(:to_int).and_return(-bignum_value)
+ exps = [-limit, coerce_long]
+ exps << -bignum_value << coerce_bignum if bignum_value >= limit
+
+ exps.each { |exp|
+ -> { (1 >> exp) }.should.raise(RangeError, 'shift width too big')
+ -> { (-1 >> exp) }.should.raise(RangeError, 'shift width too big')
+ -> { (bignum_value >> exp) }.should.raise(RangeError, 'shift width too big')
+ -> { (-bignum_value >> exp) }.should.raise(RangeError, 'shift width too big')
+ }
+ end
+ end
+end
diff --git a/spec/ruby/core/integer/round_spec.rb b/spec/ruby/core/integer/round_spec.rb
index 5a46e6cba6..a3f11e7a76 100644
--- a/spec/ruby/core/integer/round_spec.rb
+++ b/spec/ruby/core/integer/round_spec.rb
@@ -1,54 +1,44 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/to_i', __FILE__)
-require File.expand_path('../shared/integer_rounding', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/to_i'
+require_relative 'shared/integer_rounding'
describe "Integer#round" do
- 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
- [2, -4, 10**70, -10**100].each do |v|
- v.round(42).should eql(v.to_f)
- end
- end
- end
+ it_behaves_like :integer_to_i, :round
+ it_behaves_like :integer_rounding_positive_precision, :round
# redmine:5228
it "returns itself rounded if passed a negative value" do
- +249.round(-2).should eql(+200)
- -249.round(-2).should eql(-200)
- (+25 * 10**70 - 1).round(-71).should eql(+20 * 10**70)
- (-25 * 10**70 + 1).round(-71).should eql(-20 * 10**70)
+ +249.round(-2).should.eql?(+200)
+ -249.round(-2).should.eql?(-200)
+ (+25 * 10**70 - 1).round(-71).should.eql?(+20 * 10**70)
+ (-25 * 10**70 + 1).round(-71).should.eql?(-20 * 10**70)
end
it "returns itself rounded to nearest if passed a negative value" do
- +250.round(-2).should eql(+300)
- -250.round(-2).should eql(-300)
- (+25 * 10**70).round(-71).should eql(+30 * 10**70)
- (-25 * 10**70).round(-71).should eql(-30 * 10**70)
+ +250.round(-2).should.eql?(+300)
+ -250.round(-2).should.eql?(-300)
+ (+25 * 10**70).round(-71).should.eql?(+30 * 10**70)
+ (-25 * 10**70).round(-71).should.eql?(-30 * 10**70)
end
- platform_is_not wordsize: 32 do
- it "raises a RangeError when passed a big negative value" do
- lambda { 42.round(fixnum_min) }.should raise_error(RangeError)
- end
+ it "raises a RangeError when passed a big negative value" do
+ -> { 42.round(min_long - 1) }.should.raise(RangeError)
end
it "raises a RangeError when passed Float::INFINITY" do
- lambda { 42.round(Float::INFINITY) }.should raise_error(RangeError)
+ -> { 42.round(Float::INFINITY) }.should.raise(RangeError)
end
it "raises a RangeError when passed a beyond signed int" do
- lambda { 42.round(1<<31) }.should raise_error(RangeError)
+ -> { 42.round(1<<31) }.should.raise(RangeError)
end
it "raises a TypeError when passed a String" do
- lambda { 42.round("4") }.should raise_error(TypeError)
+ -> { 42.round("4") }.should.raise(TypeError)
end
it "raises a TypeError when its argument cannot be converted to an Integer" do
- lambda { 42.round(nil) }.should raise_error(TypeError)
+ -> { 42.round(nil) }.should.raise(TypeError)
end
it "calls #to_int on the argument to convert it to an Integer" do
@@ -60,36 +50,32 @@ describe "Integer#round" do
it "raises a TypeError when #to_int does not return an Integer" do
obj = mock("Object")
obj.stub!(:to_int).and_return([])
- lambda { 42.round(obj) }.should raise_error(TypeError)
+ -> { 42.round(obj) }.should.raise(TypeError)
end
- ruby_version_is "2.4" do
- it "returns different rounded values depending on the half option" do
- 25.round(-1, half: :up).should eql(30)
- 25.round(-1, half: :down).should eql(20)
- 25.round(-1, half: :even).should eql(20)
- 35.round(-1, half: :up).should eql(40)
- 35.round(-1, half: :down).should eql(30)
- 35.round(-1, half: :even).should eql(40)
- (-25).round(-1, half: :up).should eql(-30)
- (-25).round(-1, half: :down).should eql(-20)
- (-25).round(-1, half: :even).should eql(-20)
- end
+ it "returns different rounded values depending on the half option" do
+ 25.round(-1, half: :up).should.eql?(30)
+ 25.round(-1, half: :down).should.eql?(20)
+ 25.round(-1, half: :even).should.eql?(20)
+ 25.round(-1, half: nil).should.eql?(30)
+ 35.round(-1, half: :up).should.eql?(40)
+ 35.round(-1, half: :down).should.eql?(30)
+ 35.round(-1, half: :even).should.eql?(40)
+ 35.round(-1, half: nil).should.eql?(40)
+ (-25).round(-1, half: :up).should.eql?(-30)
+ (-25).round(-1, half: :down).should.eql?(-20)
+ (-25).round(-1, half: :even).should.eql?(-20)
+ (-25).round(-1, half: nil).should.eql?(-30)
end
- ruby_version_is "2.4"..."2.5" do
- it "returns itself as a float if passed a positive precision and the half option" do
- 35.round(1, half: :up).should eql(35.0)
- 35.round(1, half: :down).should eql(35.0)
- 35.round(1, half: :even).should eql(35.0)
- end
+ it "returns itself if passed a positive precision and the half option" do
+ 35.round(1, half: :up).should.eql?(35)
+ 35.round(1, half: :down).should.eql?(35)
+ 35.round(1, half: :even).should.eql?(35)
end
- ruby_version_is "2.5" do
- it "returns itself if passed a positive precision and the half option" do
- 35.round(1, half: :up).should eql(35)
- 35.round(1, half: :down).should eql(35)
- 35.round(1, half: :even).should eql(35)
- end
+ it "raises ArgumentError for an unknown rounding mode" do
+ -> { 42.round(-1, half: :foo) }.should.raise(ArgumentError, /invalid rounding mode: foo/)
+ -> { 42.round(1, half: :foo) }.should.raise(ArgumentError, /invalid rounding mode: foo/)
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..561b18fe52
--- /dev/null
+++ b/spec/ruby/core/integer/shared/arithmetic_coerce.rb
@@ -0,0 +1,11 @@
+require_relative '../fixtures/classes'
+
+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(IntegerSpecs::CoerceError)
+ 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..4bb7404183
--- /dev/null
+++ b/spec/ruby/core/integer/shared/comparison_coerce.rb
@@ -0,0 +1,11 @@
+require_relative '../fixtures/classes'
+
+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(IntegerSpecs::CoerceError)
+ 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..0be13859f9
--- /dev/null
+++ b/spec/ruby/core/integer/shared/exponent.rb
@@ -0,0 +1,162 @@
+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, 33).should.eql?(-8589934592)
+
+ (-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)
+ (-2).send(@method, 65).should.eql?(-36893488147419103232)
+ 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
+
+ ruby_version_is ""..."3.4" do
+ it "returns Float::INFINITY when the number is too big" do
+ -> {
+ 2.send(@method, 427387904).should == Float::INFINITY
+ }.should complain(/warning: in a\*\*b, b may be too big/)
+ end
+ end
+
+ ruby_version_is "3.4" do
+ it "returns an Integer for results larger than the old 32MB limit" do
+ # 2 ** 40000000 requires 40000001 bits
+ # This exceeds the old 32MB limit but is within the new 16GB limit
+ result = 2.send(@method, 40000000)
+ result.should.is_a?(Integer)
+ result.bit_length.should == 40000001
+ end
+
+ it "raises an ArgumentError when the result size exceeds the limit" do
+ -> { 100000000.send(@method, 1000000000) }.should.raise(ArgumentError)
+ end
+ end
+
+ it "raises a ZeroDivisionError for 0 ** -1" do
+ -> { 0.send(@method, -1) }.should.raise(ZeroDivisionError)
+ -> { 0.send(@method, Rational(-1, 1)) }.should.raise(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(TypeError)
+ -> { 13.send(@method, :symbol) }.should.raise(TypeError)
+ -> { 13.send(@method, nil) }.should.raise(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 == 115792089237316196603666111261383895964500887398800252671052694326794607293761
+ (@bignum.send(@method, 1.3)).should be_close(11109528802438156839288832.0, TOLERANCE)
+ end
+
+ it "raises a TypeError when given a non-Integer" do
+ -> { @bignum.send(@method, mock('10')) }.should.raise(TypeError)
+ -> { @bignum.send(@method, "10") }.should.raise(TypeError)
+ -> { @bignum.send(@method, :symbol) }.should.raise(TypeError)
+ end
+
+ ruby_version_is ""..."3.4" do
+ it "switch to a Float when the values is too big" do
+ flt = nil
+ -> {
+ flt = @bignum.send(@method, @bignum)
+ }.should complain(/warning: in a\*\*b, b may be too big/)
+ flt.should.is_a?(Float)
+ flt.infinite?.should == 1
+ end
+ end
+
+ ruby_version_is "3.4" do
+ it "returns an Integer for large Bignum results exceeding the old limit" do
+ # (2 ** 70) ** 500000 requires 35000001 bits
+ # This exceeds the old 32MB limit but is within the new 16GB limit
+ bignum_base = 2 ** 70
+ result = bignum_base.send(@method, 500000)
+ result.should.is_a?(Integer)
+ result.bit_length.should == 35000001
+ end
+
+ it "raises an ArgumentError when Bignum result exceeds the limit" do
+ # @bignum ** @bignum would require enormous memory
+ -> {
+ @bignum.send(@method, @bignum)
+ }.should.raise(ArgumentError)
+ end
+ end
+
+ it "returns a complex number when negative and raised to a fractional power" do
+ (-bignum_value).send(@method, (1.0/2)).should be_close(Complex(0.0, 4294967296.0), TOLERANCE)
+ (-@bignum).send(@method, (1.0/3)) .should be_close(Complex(1321122.9748145656, 2288252.1154253655), TOLERANCE)
+ (-@bignum).send(@method, Rational(1,3)).should be_close(Complex(1321122.9748145656, 2288252.1154253655), TOLERANCE)
+ end
+ end
+end
diff --git a/spec/ruby/core/integer/shared/integer_ceil_precision.rb b/spec/ruby/core/integer/shared/integer_ceil_precision.rb
new file mode 100644
index 0000000000..b23c17937f
--- /dev/null
+++ b/spec/ruby/core/integer/shared/integer_ceil_precision.rb
@@ -0,0 +1,54 @@
+describe :integer_ceil_precision, shared: true do
+ context "precision is zero" do
+ it "returns Integer equal to self" do
+ send(@method, 0).ceil(0).should.eql?(0)
+ send(@method, 123).ceil(0).should.eql?(123)
+ send(@method, -123).ceil(0).should.eql?(-123)
+ end
+ end
+
+ context "precision is positive" do
+ it "returns self" do
+ send(@method, 0).ceil(1).should.eql?(send(@method, 0))
+ send(@method, 0).ceil(10).should.eql?(send(@method, 0))
+
+ send(@method, 123).ceil(10).should.eql?(send(@method, 123))
+ send(@method, -123).ceil(10).should.eql?(send(@method, -123))
+ end
+ end
+
+ context "precision is negative" do
+ it "always returns 0 when self is 0" do
+ send(@method, 0).ceil(-1).should.eql?(0)
+ send(@method, 0).ceil(-10).should.eql?(0)
+ end
+
+ it "returns Integer equal to self if there are already at least precision.abs trailing zeros" do
+ send(@method, 10).ceil(-1).should.eql?(10)
+ send(@method, 100).ceil(-1).should.eql?(100)
+ send(@method, 100).ceil(-2).should.eql?(100)
+ send(@method, -10).ceil(-1).should.eql?(-10)
+ send(@method, -100).ceil(-1).should.eql?(-100)
+ send(@method, -100).ceil(-2).should.eql?(-100)
+ end
+
+ it "returns smallest Integer greater than self with at least precision.abs trailing zeros" do
+ send(@method, 123).ceil(-1).should.eql?(130)
+ send(@method, 123).ceil(-2).should.eql?(200)
+ send(@method, 123).ceil(-3).should.eql?(1000)
+
+ send(@method, -123).ceil(-1).should.eql?(-120)
+ send(@method, -123).ceil(-2).should.eql?(-100)
+ send(@method, -123).ceil(-3).should.eql?(0)
+
+ send(@method, 100).ceil(-3).should.eql?(1000)
+ send(@method, -100).ceil(-3).should.eql?(0)
+ end
+
+ # Bug #20654
+ it "returns 10**precision.abs when precision.abs has more digits than self" do
+ send(@method, 123).ceil(-20).should.eql?(100000000000000000000)
+ send(@method, 123).ceil(-50).should.eql?(100000000000000000000000000000000000000000000000000)
+ end
+ end
+end
diff --git a/spec/ruby/core/integer/shared/integer_floor_precision.rb b/spec/ruby/core/integer/shared/integer_floor_precision.rb
new file mode 100644
index 0000000000..6247907d4c
--- /dev/null
+++ b/spec/ruby/core/integer/shared/integer_floor_precision.rb
@@ -0,0 +1,42 @@
+describe :integer_floor_precision, shared: true do
+ context "precision is zero" do
+ it "returns integer self" do
+ send(@method, 0).floor(0).should.eql?(0)
+ send(@method, 123).floor(0).should.eql?(123)
+ send(@method, -123).floor(0).should.eql?(-123)
+ end
+ end
+
+ context "precision is positive" do
+ it "returns self" do
+ send(@method, 0).floor(1).should.eql?(send(@method, 0))
+ send(@method, 0).floor(10).should.eql?(send(@method, 0))
+
+ send(@method, 123).floor(10).should.eql?(send(@method, 123))
+ send(@method, -123).floor(10).should.eql?(send(@method, -123))
+ end
+ end
+
+ context "precision is negative" do
+ it "always returns 0 when self is 0" do
+ send(@method, 0).floor(-1).should.eql?(0)
+ send(@method, 0).floor(-10).should.eql?(0)
+ end
+
+ it "returns largest integer less than self with at least precision.abs trailing zeros" do
+ send(@method, 123).floor(-1).should.eql?(120)
+ send(@method, 123).floor(-2).should.eql?(100)
+ send(@method, 123).floor(-3).should.eql?(0)
+
+ send(@method, -123).floor(-1).should.eql?(-130)
+ send(@method, -123).floor(-2).should.eql?(-200)
+ send(@method, -123).floor(-3).should.eql?(-1000)
+ end
+
+ # Bug #20654
+ it "returns -(10**precision.abs) when self is negative and precision.abs is larger than the number digits of self" do
+ send(@method, -123).floor(-20).should.eql?(-100000000000000000000)
+ send(@method, -123).floor(-50).should.eql?(-100000000000000000000000000000000000000000000000000)
+ end
+ end
+end
diff --git a/spec/ruby/core/integer/shared/integer_rounding.rb b/spec/ruby/core/integer/shared/integer_rounding.rb
index ecbda1bb4a..92f2a2327c 100644
--- a/spec/ruby/core/integer/shared/integer_rounding.rb
+++ b/spec/ruby/core/integer/shared/integer_rounding.rb
@@ -1,31 +1,19 @@
describe :integer_rounding_positive_precision, shared: true do
it "returns self if not passed a precision" do
[2, -4, 10**70, -10**100].each do |v|
- v.send(@method).should eql(v)
+ v.send(@method).should.eql?(v)
end
end
- ruby_version_is "2.4" do
- it "returns self if passed a precision of zero" do
- [2, -4, 10**70, -10**100].each do |v|
- v.send(@method, 0).should eql(v)
- end
- end
- end
-
- ruby_version_is "2.4"..."2.5" do
- it "returns itself as a float if passed a positive precision" do
- [2, -4, 10**70, -10**100].each do |v|
- v.send(@method, 42).should eql(v.to_f)
- end
+ it "returns self if passed a precision of zero" do
+ [2, -4, 10**70, -10**100].each do |v|
+ v.send(@method, 0).should.eql?(v)
end
end
- ruby_version_is "2.5" do
- it "returns itself if passed a positive precision" do
- [2, -4, 10**70, -10**100].each do |v|
- v.send(@method, 42).should eql(v)
- end
+ it "returns itself if passed a positive precision" do
+ [2, -4, 10**70, -10**100].each do |v|
+ v.send(@method, 42).should.eql?(v)
end
end
end
diff --git a/spec/ruby/core/integer/shared/next.rb b/spec/ruby/core/integer/shared/next.rb
deleted file mode 100644
index 85b83d6965..0000000000
--- a/spec/ruby/core/integer/shared/next.rb
+++ /dev/null
@@ -1,25 +0,0 @@
-describe :integer_next, shared: true do
- it "returns the next larger positive Fixnum" do
- 2.send(@method).should == 3
- end
-
- it "returns the next larger negative Fixnum" do
- (-2).send(@method).should == -1
- end
-
- it "returns the next larger positive Bignum" do
- bignum_value.send(@method).should == bignum_value(1)
- end
-
- it "returns the next larger negative Bignum" do
- (-bignum_value(1)).send(@method).should == -bignum_value
- end
-
- it "overflows a Fixnum to a Bignum" do
- fixnum_max.send(@method).should == fixnum_max + 1
- end
-
- it "underflows a Bignum to a Fixnum" do
- (fixnum_min - 1).send(@method).should == fixnum_min
- end
-end
diff --git a/spec/ruby/core/integer/shared/to_i.rb b/spec/ruby/core/integer/shared/to_i.rb
index 7b974cd3a7..2b6a50484a 100644
--- a/spec/ruby/core/integer/shared/to_i.rb
+++ b/spec/ruby/core/integer/shared/to_i.rb
@@ -1,8 +1,8 @@
describe :integer_to_i, shared: true do
it "returns self" do
- 10.send(@method).should eql(10)
- (-15).send(@method).should eql(-15)
- bignum_value.send(@method).should eql(bignum_value)
- (-bignum_value).send(@method).should eql(-bignum_value)
+ 10.send(@method).should.eql?(10)
+ (-15).send(@method).should.eql?(-15)
+ bignum_value.send(@method).should.eql?(bignum_value)
+ (-bignum_value).send(@method).should.eql?(-bignum_value)
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..725e9eb062
--- /dev/null
+++ b/spec/ruby/core/integer/size_spec.rb
@@ -0,0 +1,34 @@
+require_relative '../../spec_helper'
+
+describe "Integer#size" do
+ platform_is c_long_size: 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 c_long_size: 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/sqrt_spec.rb b/spec/ruby/core/integer/sqrt_spec.rb
index b7d9ef441b..bf90ea747e 100644
--- a/spec/ruby/core/integer/sqrt_spec.rb
+++ b/spec/ruby/core/integer/sqrt_spec.rb
@@ -1,33 +1,31 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
-ruby_version_is "2.5" do
- describe "Integer.sqrt" do
- it "returns an integer" do
- Integer.sqrt(10).should be_kind_of(Integer)
- end
+describe "Integer.sqrt" do
+ it "returns an integer" do
+ Integer.sqrt(10).should.is_a?(Integer)
+ end
- it "returns the integer square root of the argument" do
- Integer.sqrt(0).should == 0
- Integer.sqrt(1).should == 1
- Integer.sqrt(24).should == 4
- Integer.sqrt(25).should == 5
- Integer.sqrt(10**400).should == 10**200
- end
+ it "returns the integer square root of the argument" do
+ Integer.sqrt(0).should == 0
+ Integer.sqrt(1).should == 1
+ Integer.sqrt(24).should == 4
+ Integer.sqrt(25).should == 5
+ Integer.sqrt(10**400).should == 10**200
+ end
- it "raises a Math::DomainError if the argument is negative" do
- lambda { Integer.sqrt(-4) }.should raise_error(Math::DomainError)
- end
+ it "raises a Math::DomainError if the argument is negative" do
+ -> { Integer.sqrt(-4) }.should.raise(Math::DomainError)
+ end
- it "accepts any argument that can be coerced to Integer" do
- Integer.sqrt(10.0).should == 3
- end
+ it "accepts any argument that can be coerced to Integer" do
+ Integer.sqrt(10.0).should == 3
+ end
- it "converts the argument with #to_int" do
- Integer.sqrt(mock_int(10)).should == 3
- end
+ it "converts the argument with #to_int" do
+ Integer.sqrt(mock_int(10)).should == 3
+ end
- it "raises a TypeError if the argument cannot be coerced to Integer" do
- lambda { Integer.sqrt("test") }.should raise_error(TypeError)
- end
+ it "raises a TypeError if the argument cannot be coerced to Integer" do
+ -> { Integer.sqrt("test") }.should.raise(TypeError)
end
end
diff --git a/spec/ruby/core/integer/succ_spec.rb b/spec/ruby/core/integer/succ_spec.rb
index a1405684fc..2201a4c76d 100644
--- a/spec/ruby/core/integer/succ_spec.rb
+++ b/spec/ruby/core/integer/succ_spec.rb
@@ -1,6 +1,27 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/next', __FILE__)
+require_relative '../../spec_helper'
describe "Integer#succ" do
- it_behaves_like(:integer_next, :succ)
+ 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 "returns the next larger positive Bignum" do
+ bignum_value.succ.should == bignum_value(1)
+ end
+
+ it "returns the next larger negative Bignum" do
+ (-bignum_value(1)).succ.should == -bignum_value
+ end
+
+ it "overflows a Fixnum to a Bignum" do
+ fixnum_max.succ.should == fixnum_max + 1
+ end
+
+ it "underflows a Bignum to a Fixnum" do
+ (fixnum_min - 1).succ.should == fixnum_min
+ end
end
diff --git a/spec/ruby/core/integer/times_spec.rb b/spec/ruby/core/integer/times_spec.rb
index d426bc008c..356340592b 100644
--- a/spec/ruby/core/integer/times_spec.rb
+++ b/spec/ruby/core/integer/times_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Integer#times" do
it "returns self" do
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..0681236095
--- /dev/null
+++ b/spec/ruby/core/integer/to_f_spec.rb
@@ -0,0 +1,23 @@
+require_relative '../../spec_helper'
+
+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?(23_058_441_774_644_068_352.0)
+ bignum_value(0x8000_0000_0000_0ccc).to_f.should.eql?(27_670_116_110_564_330_700.0)
+ (-bignum_value(99)).to_f.should.eql?(-18_446_744_073_709_551_715.0)
+ 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..1a8e477b3c 100644
--- a/spec/ruby/core/integer/to_i_spec.rb
+++ b/spec/ruby/core/integer/to_i_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/to_i', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/to_i'
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..4b7eccad3a 100644
--- a/spec/ruby/core/integer/to_int_spec.rb
+++ b/spec/ruby/core/integer/to_int_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/to_i', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/to_i'
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_r_spec.rb b/spec/ruby/core/integer/to_r_spec.rb
index 0eb158b100..2649c7c78d 100644
--- a/spec/ruby/core/integer/to_r_spec.rb
+++ b/spec/ruby/core/integer/to_r_spec.rb
@@ -1,8 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Integer#to_r" do
it "returns a Rational object" do
- 309.to_r.should be_an_instance_of(Rational)
+ 309.to_r.should.instance_of?(Rational)
end
it "constructs a rational number with self as the numerator" do
@@ -15,12 +15,12 @@ describe "Integer#to_r" do
it "works even if self is a Bignum" do
bignum = 99999**999
- bignum.should be_an_instance_of(Bignum)
+ bignum.should.instance_of?(Integer)
bignum.to_r.should == Rational(bignum, 1)
end
it "raises an ArgumentError if given any arguments" do
- lambda { 287.to_r(2) }.should raise_error(ArgumentError)
- lambda { 9102826.to_r(309, [], 71) }.should raise_error(ArgumentError)
+ -> { 287.to_r(2) }.should.raise(ArgumentError)
+ -> { 9102826.to_r(309, [], 71) }.should.raise(ArgumentError)
end
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..4970a2a12f
--- /dev/null
+++ b/spec/ruby/core/integer/to_s_spec.rb
@@ -0,0 +1,95 @@
+require_relative '../../spec_helper'
+
+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
+ -> { 123.to_s(-1) }.should.raise(ArgumentError)
+ -> { 123.to_s(0) }.should.raise(ArgumentError)
+ -> { 123.to_s(1) }.should.raise(ArgumentError)
+ -> { 123.to_s(37) }.should.raise(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
+
+ 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
+
+ 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
+ -> { 123.to_s(-1) }.should.raise(ArgumentError)
+ -> { 123.to_s(0) }.should.raise(ArgumentError)
+ -> { 123.to_s(1) }.should.raise(ArgumentError)
+ -> { 123.to_s(37) }.should.raise(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 == "18446744073709551625"
+ bignum_value.to_s.should == "18446744073709551616"
+ (-bignum_value(675)).to_s.should == "-18446744073709552291"
+ end
+ end
+
+ 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/integer/truncate_spec.rb b/spec/ruby/core/integer/truncate_spec.rb
index 429ab1a312..b95c183cf3 100644
--- a/spec/ruby/core/integer/truncate_spec.rb
+++ b/spec/ruby/core/integer/truncate_spec.rb
@@ -1,21 +1,19 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/to_i', __FILE__)
-require File.expand_path('../shared/integer_rounding', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/to_i'
+require_relative 'shared/integer_rounding'
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
- it "returns an integer with at least precision.abs trailing zeros" do
- 1832.truncate(-1).should eql(1830)
- 1832.truncate(-2).should eql(1800)
- 1832.truncate(-3).should eql(1000)
- -1832.truncate(-1).should eql(-1830)
- -1832.truncate(-2).should eql(-1800)
- -1832.truncate(-3).should eql(-1000)
- end
+ context "precision argument specified as part of the truncate method is negative" do
+ it "returns an integer with at least precision.abs trailing zeros" do
+ 1832.truncate(-1).should.eql?(1830)
+ 1832.truncate(-2).should.eql?(1800)
+ 1832.truncate(-3).should.eql?(1000)
+ -1832.truncate(-1).should.eql?(-1830)
+ -1832.truncate(-2).should.eql?(-1800)
+ -1832.truncate(-3).should.eql?(-1000)
end
end
end
diff --git a/spec/ruby/core/integer/try_convert_spec.rb b/spec/ruby/core/integer/try_convert_spec.rb
new file mode 100644
index 0000000000..8c9b4276b9
--- /dev/null
+++ b/spec/ruby/core/integer/try_convert_spec.rb
@@ -0,0 +1,48 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe "Integer.try_convert" do
+ it "returns the argument if it's an Integer" do
+ x = 42
+ Integer.try_convert(x).should.equal?(x)
+ end
+
+ it "returns nil when the argument does not respond to #to_int" do
+ Integer.try_convert(Object.new).should == nil
+ end
+
+ it "sends #to_int to the argument and returns the result if it's nil" do
+ obj = mock("to_int")
+ obj.should_receive(:to_int).and_return(nil)
+ Integer.try_convert(obj).should == nil
+ end
+
+ it "sends #to_int to the argument and returns the result if it's an Integer" do
+ x = 234
+ obj = mock("to_int")
+ obj.should_receive(:to_int).and_return(x)
+ Integer.try_convert(obj).should.equal?(x)
+ end
+
+ it "sends #to_int to the argument and raises TypeError if it's not a kind of Integer" do
+ obj = mock("to_int")
+ obj.should_receive(:to_int).and_return(Object.new)
+ -> {
+ Integer.try_convert obj
+ }.should raise_consistent_error(TypeError, "can't convert MockObject into Integer (MockObject#to_int gives Object)")
+ end
+
+ it "responds with a different error message when it raises a TypeError, depending on the type of the non-Integer object :to_int returns" do
+ obj = mock("to_int")
+ obj.should_receive(:to_int).and_return("A String")
+ -> {
+ Integer.try_convert obj
+ }.should raise_consistent_error(TypeError, "can't convert MockObject into Integer (MockObject#to_int gives String)")
+ end
+
+ it "does not rescue exceptions raised by #to_int" do
+ obj = mock("to_int")
+ obj.should_receive(:to_int).and_raise(RuntimeError)
+ -> { Integer.try_convert obj }.should.raise(RuntimeError)
+ end
+end
diff --git a/spec/ruby/core/integer/uminus_spec.rb b/spec/ruby/core/integer/uminus_spec.rb
new file mode 100644
index 0000000000..7a9cfe89bf
--- /dev/null
+++ b/spec/ruby/core/integer/uminus_spec.rb
@@ -0,0 +1,30 @@
+require_relative '../../spec_helper'
+
+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).should == (0 - fixnum_max)
+ (-fixnum_max).should < 0
+ (-fixnum_min).should == (0 - fixnum_min)
+ (-fixnum_min).should > 0
+ end
+ end
+
+ context "bignum" do
+ it "returns self as a negative value" do
+ bignum_value.send(:-@).should == -18446744073709551616
+ (-bignum_value).send(:-@).should == 18446744073709551616
+
+ bignum_value(921).send(:-@).should == -18446744073709552537
+ (-bignum_value(921).send(:-@)).should == 18446744073709552537
+ end
+ end
+end
diff --git a/spec/ruby/core/integer/upto_spec.rb b/spec/ruby/core/integer/upto_spec.rb
index 405f8e4817..ba63dcc9ea 100644
--- a/spec/ruby/core/integer/upto_spec.rb
+++ b/spec/ruby/core/integer/upto_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
-describe "Integer#upto [stop] when self and stop are Fixnums" do
+describe "Integer#upto [stop] when self and stop are Integers" do
it "does not yield when stop is less than self" do
result = []
5.upto(4) { |x| result << x }
@@ -27,8 +27,8 @@ describe "Integer#upto [stop] when self and stop are Fixnums" do
end
it "raises an ArgumentError for non-numeric endpoints" do
- lambda { 1.upto("A") {|x| p x} }.should raise_error(ArgumentError)
- lambda { 1.upto(nil) {|x| p x} }.should raise_error(ArgumentError)
+ -> { 1.upto("A") {|x| p x} }.should.raise(ArgumentError)
+ -> { 1.upto(nil) {|x| p x} }.should.raise(ArgumentError)
end
describe "when no block is given" do
@@ -45,9 +45,9 @@ describe "Integer#upto [stop] when self and stop are Fixnums" do
describe "size" do
it "raises an ArgumentError for non-numeric endpoints" do
enum = 1.upto("A")
- lambda { enum.size }.should raise_error(ArgumentError)
+ -> { enum.size }.should.raise(ArgumentError)
enum = 1.upto(nil)
- lambda { enum.size }.should raise_error(ArgumentError)
+ -> { enum.size }.should.raise(ArgumentError)
end
it "returns stop - self + 1" do
diff --git a/spec/ruby/core/integer/zero_spec.rb b/spec/ruby/core/integer/zero_spec.rb
new file mode 100644
index 0000000000..bd362c4181
--- /dev/null
+++ b/spec/ruby/core/integer/zero_spec.rb
@@ -0,0 +1,13 @@
+require_relative '../../spec_helper'
+
+describe "Integer#zero?" do
+ it "returns true if self is 0" do
+ 0.should.zero?
+ 1.should_not.zero?
+ -1.should_not.zero?
+ end
+
+ it "Integer#zero? overrides Numeric#zero?" do
+ 42.method(:zero?).owner.should == Integer
+ end
+end
diff --git a/spec/ruby/core/io/advise_spec.rb b/spec/ruby/core/io/advise_spec.rb
index 44cd32df94..b77ed53ad4 100644
--- a/spec/ruby/core/io/advise_spec.rb
+++ b/spec/ruby/core/io/advise_spec.rb
@@ -1,6 +1,6 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "IO#advise" do
before :each do
@@ -12,86 +12,75 @@ describe "IO#advise" do
end
it "raises a TypeError if advise is not a Symbol" do
- lambda {
+ -> {
@io.advise("normal")
- }.should raise_error(TypeError)
+ }.should.raise(TypeError)
end
it "raises a TypeError if offset cannot be coerced to an Integer" do
- lambda {
+ -> {
@io.advise(:normal, "wat")
- }.should raise_error(TypeError)
+ }.should.raise(TypeError)
end
it "raises a TypeError if len cannot be coerced to an Integer" do
- lambda {
+ -> {
@io.advise(:normal, 0, "wat")
- }.should raise_error(TypeError)
+ }.should.raise(TypeError)
end
it "raises a RangeError if offset is too big" do
- lambda {
+ -> {
@io.advise(:normal, 10 ** 32)
- }.should raise_error(RangeError)
+ }.should.raise(RangeError)
end
it "raises a RangeError if len is too big" do
- lambda {
+ -> {
@io.advise(:normal, 0, 10 ** 32)
- }.should raise_error(RangeError)
+ }.should.raise(RangeError)
end
it "raises a NotImplementedError if advise is not recognized" do
- lambda{
+ ->{
@io.advise(:foo)
- }.should raise_error(NotImplementedError)
+ }.should.raise(NotImplementedError)
end
it "supports the normal advice type" do
- @io.advise(:normal).should be_nil
+ @io.advise(:normal).should == nil
end
it "supports the sequential advice type" do
- @io.advise(:sequential).should be_nil
+ @io.advise(:sequential).should == nil
end
it "supports the random advice type" do
- @io.advise(:random).should be_nil
+ @io.advise(:random).should == nil
end
it "supports the dontneed advice type" do
- @io.advise(:dontneed).should be_nil
+ @io.advise(:dontneed).should == nil
end
it "supports the noreuse advice type" do
- @io.advise(:noreuse).should be_nil
+ @io.advise(:noreuse).should == nil
end
platform_is_not :linux do
it "supports the willneed advice type" do
- @io.advise(:willneed).should be_nil
+ @io.advise(:willneed).should == nil
end
end
- platform_is :linux do
+ guard -> { platform_is :linux and kernel_version_is '3.6' } do # [ruby-core:65355] tmpfs is not supported
it "supports the willneed advice type" do
- require 'etc'
- uname = if Etc.respond_to?(:uname)
- Etc.uname[:release]
- else
- `uname -r`.chomp
- end
- if (uname.split('.').map(&:to_i) <=> [3,6]) < 0
- # [ruby-core:65355] tmpfs is not supported
- 1.should == 1
- else
- @io.advise(:willneed).should be_nil
- end
+ @io.advise(:willneed).should == nil
end
end
it "raises an IOError if the stream is closed" do
@io.close
- lambda { @io.advise(:normal) }.should raise_error(IOError)
+ -> { @io.advise(:normal) }.should.raise(IOError)
end
end
diff --git a/spec/ruby/core/io/autoclose_spec.rb b/spec/ruby/core/io/autoclose_spec.rb
new file mode 100644
index 0000000000..596f3d6934
--- /dev/null
+++ b/spec/ruby/core/io/autoclose_spec.rb
@@ -0,0 +1,77 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe "IO#autoclose?" do
+ before :each do
+ @io = IOSpecs.io_fixture "lines.txt"
+ end
+
+ after :each do
+ @io.autoclose = true unless @io.closed?
+ @io.close unless @io.closed?
+ end
+
+ it "is set to true by default" do
+ @io.should.autoclose?
+ end
+
+ it "cannot be queried on a closed IO object" do
+ @io.close
+ -> { @io.autoclose? }.should.raise(IOError, /closed stream/)
+ end
+end
+
+describe "IO#autoclose=" do
+ before :each do
+ @io = IOSpecs.io_fixture "lines.txt"
+ end
+
+ after :each do
+ @io.autoclose = true unless @io.closed?
+ @io.close unless @io.closed?
+ end
+
+ it "can be set to true" do
+ @io.autoclose = false
+ @io.autoclose = true
+ @io.should.autoclose?
+ end
+
+ it "can be set to false" do
+ @io.autoclose = true
+ @io.autoclose = false
+ @io.should_not.autoclose?
+ end
+
+ it "can be set to any truthy value" do
+ @io.autoclose = false
+ @io.autoclose = 42
+ @io.should.autoclose?
+
+ @io.autoclose = false
+ @io.autoclose = Object.new
+ @io.should.autoclose?
+ end
+
+ it "can be set to any falsy value" do
+ @io.autoclose = true
+ @io.autoclose = nil
+ @io.should_not.autoclose?
+ end
+
+ it "can be set multiple times" do
+ @io.autoclose = true
+ @io.should.autoclose?
+
+ @io.autoclose = false
+ @io.should_not.autoclose?
+
+ @io.autoclose = true
+ @io.should.autoclose?
+ end
+
+ it "cannot be set on a closed IO object" do
+ @io.close
+ -> { @io.autoclose = false }.should.raise(IOError, /closed stream/)
+ end
+end
diff --git a/spec/ruby/core/io/binmode_spec.rb b/spec/ruby/core/io/binmode_spec.rb
index f437c8a4a4..8117229c91 100644
--- a/spec/ruby/core/io/binmode_spec.rb
+++ b/spec/ruby/core/io/binmode_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "IO#binmode" do
before :each do
@@ -13,11 +13,11 @@ describe "IO#binmode" do
it "returns self" do
@io = new_io(@name)
- @io.binmode.should equal(@io)
+ @io.binmode.should.equal?(@io)
end
it "raises an IOError on closed stream" do
- lambda { IOSpecs.closed_io.binmode }.should raise_error(IOError)
+ -> { IOSpecs.closed_io.binmode }.should.raise(IOError)
end
it "sets external encoding to binary" do
@@ -47,9 +47,9 @@ describe "IO#binmode?" do
end
it "is true after a call to IO#binmode" do
- @file.binmode?.should be_false
+ @file.binmode?.should == false
@file.binmode
- @file.binmode?.should be_true
+ @file.binmode?.should == true
end
it "propagates to dup'ed IO objects" do
@@ -57,4 +57,8 @@ describe "IO#binmode?" do
@duped = @file.dup
@duped.binmode?.should == @file.binmode?
end
+
+ it "raises an IOError on closed stream" do
+ -> { IOSpecs.closed_io.binmode? }.should.raise(IOError)
+ end
end
diff --git a/spec/ruby/core/io/binread_spec.rb b/spec/ruby/core/io/binread_spec.rb
index b592639f9d..3023c7f177 100644
--- a/spec/ruby/core/io/binread_spec.rb
+++ b/spec/ruby/core/io/binread_spec.rb
@@ -1,6 +1,6 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "IO.binread" do
before :each do
@@ -28,22 +28,30 @@ describe "IO.binread" do
IO.binread(@fname, 5, 3).should == @contents.slice(3, 5)
end
- it "returns a String in ASCII-8BIT encoding" do
- IO.binread(@fname).encoding.should == Encoding::ASCII_8BIT
+ it "returns a String in BINARY encoding" do
+ IO.binread(@fname).encoding.should == Encoding::BINARY
end
- it "returns a String in ASCII-8BIT encoding regardless of Encoding.default_internal" do
+ it "returns a String in BINARY encoding regardless of Encoding.default_internal" do
Encoding.default_internal = Encoding::EUC_JP
- IO.binread(@fname).encoding.should == Encoding::ASCII_8BIT
+ IO.binread(@fname).encoding.should == Encoding::BINARY
end
it "raises an ArgumentError when not passed a valid length" do
- lambda { IO.binread @fname, -1 }.should raise_error(ArgumentError)
+ -> { IO.binread @fname, -1 }.should.raise(ArgumentError)
end
- ruby_version_is "2.3" do # MRI leaks the fd on older versions
- it "raises an Errno::EINVAL when not passed a valid offset" do
- lambda { IO.binread @fname, 0, -1 }.should raise_error(Errno::EINVAL)
+ it "raises an Errno::EINVAL when not passed a valid offset" do
+ -> { IO.binread @fname, 0, -1 }.should.raise(Errno::EINVAL)
+ end
+
+ ruby_version_is ""..."4.0" do
+ # https://bugs.ruby-lang.org/issues/19630
+ it "warns about deprecation given a path with a pipe" do
+ cmd = "|echo ok"
+ -> {
+ IO.binread(cmd)
+ }.should complain(/IO process creation with a leading '\|'/)
end
end
end
diff --git a/spec/ruby/core/io/binwrite_spec.rb b/spec/ruby/core/io/binwrite_spec.rb
index ec964d07a8..8ebc86a52e 100644
--- a/spec/ruby/core/io/binwrite_spec.rb
+++ b/spec/ruby/core/io/binwrite_spec.rb
@@ -1,8 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/binwrite', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/binwrite'
describe "IO.binwrite" do
it_behaves_like :io_binwrite, :binwrite
-
- it "needs to be reviewed for spec completeness"
end
diff --git a/spec/ruby/core/io/buffer/and_spec.rb b/spec/ruby/core/io/buffer/and_spec.rb
new file mode 100644
index 0000000000..3cea163b0e
--- /dev/null
+++ b/spec/ruby/core/io/buffer/and_spec.rb
@@ -0,0 +1,62 @@
+require_relative '../../../spec_helper'
+
+describe :io_buffer_and, shared: true do
+ it "applies the argument buffer as an AND bit mask across the whole buffer" do
+ IO::Buffer.for(+"12345") do |buffer|
+ IO::Buffer.for(+"\xF8\x8F") do |mask|
+ result = buffer.send(@method, mask)
+ result.get_string.should == "\x30\x02\x30\x04\x30".b
+ result.free
+ end
+ end
+ end
+
+ it "ignores extra parts of mask if it is longer than source buffer" do
+ IO::Buffer.for(+"12345") do |buffer|
+ IO::Buffer.for(+"\xF8\x8F\x00\x00\x00\xFF\xFF") do |mask|
+ result = buffer.send(@method, mask)
+ result.get_string.should == "\x30\x02\x00\x00\x00".b
+ result.free
+ end
+ end
+ end
+
+ it "raises TypeError if mask is not an IO::Buffer" do
+ IO::Buffer.for(+"12345") do |buffer|
+ -> { buffer.send(@method, "\xF8\x8F") }.should.raise(TypeError, "wrong argument type String (expected IO::Buffer)")
+ -> { buffer.send(@method, 0xF8) }.should.raise(TypeError, "wrong argument type Integer (expected IO::Buffer)")
+ -> { buffer.send(@method, nil) }.should.raise(TypeError, "wrong argument type nil (expected IO::Buffer)")
+ end
+ end
+end
+
+describe "IO::Buffer#&" do
+ it_behaves_like :io_buffer_and, :&
+
+ it "creates a new internal buffer of the same size" do
+ IO::Buffer.for(+"12345") do |buffer|
+ IO::Buffer.for(+"\xF8\x8F") do |mask|
+ result = buffer & mask
+ result.should_not.equal? buffer
+ result.should.internal?
+ result.size.should == buffer.size
+ result.free
+ buffer.get_string.should == "12345".b
+ end
+ end
+ end
+end
+
+describe "IO::Buffer#and!" do
+ it_behaves_like :io_buffer_and, :and!
+
+ it "modifies the buffer in place" do
+ IO::Buffer.for(+"12345") do |buffer|
+ IO::Buffer.for(+"\xF8\x8F") do |mask|
+ result = buffer.and!(mask)
+ result.should.equal? buffer
+ result.should.external?
+ end
+ end
+ end
+end
diff --git a/spec/ruby/core/io/buffer/bit_count_spec.rb b/spec/ruby/core/io/buffer/bit_count_spec.rb
new file mode 100644
index 0000000000..62f56f5b98
--- /dev/null
+++ b/spec/ruby/core/io/buffer/bit_count_spec.rb
@@ -0,0 +1,64 @@
+require_relative '../../../spec_helper'
+
+ruby_version_is "4.1" do
+ describe "IO::Buffer#bit_count" do
+ it "counts all set bits in the whole buffer" do
+ IO::Buffer.for(+"\xFF\x00\x0F") do |buffer|
+ buffer.bit_count.should == 12
+ end
+ end
+
+ it "returns 0 for a buffer of all zero bytes" do
+ IO::Buffer.for(+"\x00\x00\x00") do |buffer|
+ buffer.bit_count.should == 0
+ end
+ end
+
+ it "returns 8 * size for a buffer of all 0xFF bytes" do
+ IO::Buffer.for(+"\xFF" * 9) do |buffer|
+ buffer.bit_count.should == 72
+ end
+ end
+
+ it "returns 0 for an empty buffer" do
+ IO::Buffer.new(0).bit_count.should == 0
+ end
+
+ it "accepts an offset to start counting from (length defaults to remaining bytes)" do
+ IO::Buffer.for(+"\xFF\x00\x0F") do |buffer|
+ buffer.bit_count(0).should == 12 # offset=0 => entire buffer
+ buffer.bit_count(1).should == 4 # offset=1 => 0x00 + 0x0F
+ buffer.bit_count(2).should == 4 # offset=2 => 0x0F only
+ end
+ end
+
+ it "accepts an offset and length to restrict the counted region" do
+ IO::Buffer.for(+"\xFF\x00\x0F") do |buffer|
+ buffer.bit_count(0, 1).should == 8 # just 0xFF
+ buffer.bit_count(1, 1).should == 0 # just 0x00
+ buffer.bit_count(2, 1).should == 4 # just 0x0F
+ buffer.bit_count(1, 2).should == 4 # 0x00 + 0x0F
+ end
+ end
+
+ it "handles 8-byte aligned buffers efficiently" do
+ IO::Buffer.for(+"\xAA" * 8) do |buffer|
+ # 0xAA = 10101010 => 4 bits per byte => 32 total
+ buffer.bit_count.should == 32
+ end
+ end
+
+ it "raises ArgumentError when offset + length exceeds buffer size" do
+ IO::Buffer.for(+"\xFF") do |buffer|
+ -> { buffer.bit_count(0, 2) }.should.raise(ArgumentError)
+ -> { buffer.bit_count(1, 1) }.should.raise(ArgumentError)
+ end
+ end
+
+ it "returns an Integer" do
+ IO::Buffer.for(+"\xFF") do |buffer|
+ buffer.bit_count.should.is_a?(Integer)
+ end
+ end
+ end
+end
diff --git a/spec/ruby/core/io/buffer/empty_spec.rb b/spec/ruby/core/io/buffer/empty_spec.rb
new file mode 100644
index 0000000000..4cceb4dc0d
--- /dev/null
+++ b/spec/ruby/core/io/buffer/empty_spec.rb
@@ -0,0 +1,27 @@
+require_relative '../../../spec_helper'
+require_relative 'shared/null_and_empty'
+
+describe "IO::Buffer#empty?" do
+ after :each do
+ @buffer&.free
+ @buffer = nil
+ end
+
+ it_behaves_like :io_buffer_null_and_empty, :empty?
+
+ it "is true for a 0-length String-backed buffer created with .for" do
+ @buffer = IO::Buffer.for("")
+ @buffer.empty?.should == true
+ end
+
+ it "is true for a 0-length String-backed buffer created with .string" do
+ IO::Buffer.string(0) do |buffer|
+ buffer.empty?.should == true
+ end
+ end
+
+ it "is true for a 0-length slice of a buffer with size > 0" do
+ @buffer = IO::Buffer.new(4)
+ @buffer.slice(3, 0).empty?.should == true
+ end
+end
diff --git a/spec/ruby/core/io/buffer/external_spec.rb b/spec/ruby/core/io/buffer/external_spec.rb
new file mode 100644
index 0000000000..18b2ee0d06
--- /dev/null
+++ b/spec/ruby/core/io/buffer/external_spec.rb
@@ -0,0 +1,23 @@
+require_relative '../../../spec_helper'
+
+describe "IO::Buffer#external?" do
+ after :each do
+ @buffer&.free
+ @buffer = nil
+ end
+
+ it "is true for a buffer with externally-managed memory" do
+ @buffer = IO::Buffer.for("string")
+ @buffer.external?.should == true
+ end
+
+ it "is false for a buffer with self-managed memory" do
+ @buffer = IO::Buffer.new(12, IO::Buffer::MAPPED)
+ @buffer.external?.should == false
+ end
+
+ it "is false for a null buffer" do
+ @buffer = IO::Buffer.new(0)
+ @buffer.external?.should == false
+ end
+end
diff --git a/spec/ruby/core/io/buffer/for_spec.rb b/spec/ruby/core/io/buffer/for_spec.rb
new file mode 100644
index 0000000000..4c614f74b0
--- /dev/null
+++ b/spec/ruby/core/io/buffer/for_spec.rb
@@ -0,0 +1,95 @@
+require_relative '../../../spec_helper'
+
+describe "IO::Buffer.for" do
+ before :each do
+ @string = +"för striñg"
+ end
+
+ after :each do
+ @buffer&.free
+ @buffer = nil
+ end
+
+ context "without a block" do
+ it "copies string's contents, creating a separate read-only buffer" do
+ @buffer = IO::Buffer.for(@string)
+
+ @buffer.size.should == @string.bytesize
+ @buffer.get_string.should == @string.b
+
+ @string[0] = "d"
+ @buffer.get_string(0, 1).should == "f".b
+
+ -> { @buffer.set_string("d") }.should.raise(IO::Buffer::AccessError, "Buffer is not writable!")
+ end
+
+ it "creates an external, read-only buffer" do
+ @buffer = IO::Buffer.for(@string)
+
+ @buffer.should_not.internal?
+ @buffer.should_not.mapped?
+ @buffer.should.external?
+
+ @buffer.should_not.empty?
+ @buffer.should_not.null?
+
+ @buffer.should_not.shared?
+ @buffer.should_not.private?
+ @buffer.should.readonly?
+
+ @buffer.should_not.locked?
+ @buffer.should.valid?
+ end
+ end
+
+ context "with a block" do
+ it "returns the last value in the block" do
+ value =
+ IO::Buffer.for(@string) do |buffer|
+ buffer.size * 3
+ end
+ value.should == @string.bytesize * 3
+ end
+
+ it "frees the buffer at the end of the block" do
+ IO::Buffer.for(@string) do |buffer|
+ @buffer = buffer
+ @buffer.should_not.null?
+ end
+ @buffer.should.null?
+ end
+
+ context "if string is not frozen" do
+ it "creates a modifiable string-backed buffer" do
+ IO::Buffer.for(@string) do |buffer|
+ buffer.size.should == @string.bytesize
+ buffer.get_string.should == @string.b
+
+ buffer.should_not.readonly?
+ buffer.should_not.locked?
+
+ buffer.set_string("ghost shell")
+ @string.should == "ghost shellg"
+ end
+ end
+
+ it "locks the original string to prevent modification" do
+ IO::Buffer.for(@string) do |_buffer|
+ -> { @string[0] = "t" }.should.raise(RuntimeError, "can't modify string; temporarily locked")
+ end
+ @string[1] = "u"
+ @string.should == "fur striñg"
+ end
+ end
+
+ context "if string is frozen" do
+ it "creates a read-only string-backed buffer" do
+ IO::Buffer.for(@string.freeze) do |buffer|
+ buffer.should.readonly?
+
+ -> { buffer.set_string("ghost shell") }.should.raise(IO::Buffer::AccessError, "Buffer is not writable!")
+ end
+ end
+ end
+ end
+end
diff --git a/spec/ruby/core/io/buffer/free_spec.rb b/spec/ruby/core/io/buffer/free_spec.rb
new file mode 100644
index 0000000000..20fb7b901f
--- /dev/null
+++ b/spec/ruby/core/io/buffer/free_spec.rb
@@ -0,0 +1,102 @@
+require_relative '../../../spec_helper'
+
+describe "IO::Buffer#free" do
+ context "with a buffer created with .new" do
+ it "frees internal memory and nullifies the buffer" do
+ buffer = IO::Buffer.new(4)
+ buffer.free
+ buffer.null?.should == true
+ end
+
+ it "frees mapped memory and nullifies the buffer" do
+ buffer = IO::Buffer.new(4, IO::Buffer::MAPPED)
+ buffer.free
+ buffer.null?.should == true
+ end
+ end
+
+ context "with a file-backed buffer created with .map" do
+ it "frees mapped memory and nullifies the buffer" do
+ File.open(__FILE__, "r") do |file|
+ buffer = IO::Buffer.map(file, nil, 0, IO::Buffer::READONLY)
+ buffer.free
+ buffer.null?.should == true
+ end
+ end
+ end
+
+ context "with a String-backed buffer created with .for" do
+ context "without a block" do
+ it "disassociates the buffer from the string and nullifies the buffer" do
+ string = +"test"
+ buffer = IO::Buffer.for(string)
+ # Read-only buffer, can't modify the string.
+ buffer.free
+ buffer.null?.should == true
+ end
+ end
+
+ context "with a block" do
+ it "disassociates the buffer from the string and nullifies the buffer" do
+ string = +"test"
+ IO::Buffer.for(string) do |buffer|
+ buffer.set_string("meat")
+ buffer.free
+ buffer.null?.should == true
+ end
+ string.should == "meat"
+ end
+ end
+ end
+
+ context "with a String-backed buffer created with .string" do
+ it "disassociates the buffer from the string and nullifies the buffer" do
+ string =
+ IO::Buffer.string(4) do |buffer|
+ buffer.set_string("meat")
+ buffer.free
+ buffer.null?.should == true
+ end
+ string.should == "meat"
+ end
+ end
+
+ it "can be called repeatedly without an error" do
+ buffer = IO::Buffer.new(4)
+ buffer.free
+ buffer.null?.should == true
+ buffer.free
+ buffer.null?.should == true
+ end
+
+ it "is disallowed while locked, raising IO::Buffer::LockedError" do
+ buffer = IO::Buffer.new(4)
+ buffer.locked do
+ -> { buffer.free }.should.raise(IO::Buffer::LockedError, "Buffer is locked!")
+ end
+ buffer.free
+ buffer.null?.should == true
+ end
+
+ context "with a slice of a buffer" do
+ it "nullifies the slice, not touching the buffer" do
+ buffer = IO::Buffer.new(4)
+ slice = buffer.slice(0, 2)
+
+ slice.free
+ slice.null?.should == true
+ buffer.null?.should == false
+
+ buffer.free
+ end
+
+ it "nullifies buffer, invalidating the slice" do
+ buffer = IO::Buffer.new(4)
+ slice = buffer.slice(0, 2)
+
+ buffer.free
+ slice.null?.should == false
+ slice.valid?.should == false
+ end
+ end
+end
diff --git a/spec/ruby/core/io/buffer/initialize_spec.rb b/spec/ruby/core/io/buffer/initialize_spec.rb
new file mode 100644
index 0000000000..dba6fddc79
--- /dev/null
+++ b/spec/ruby/core/io/buffer/initialize_spec.rb
@@ -0,0 +1,119 @@
+require_relative '../../../spec_helper'
+
+describe "IO::Buffer#initialize" do
+ after :each do
+ @buffer&.free
+ @buffer = nil
+ end
+
+ it "creates a new zero-filled buffer with default size" do
+ @buffer = IO::Buffer.new
+ @buffer.size.should == IO::Buffer::DEFAULT_SIZE
+ @buffer.each(:U8).should.all? { |_offset, value| value.eql?(0) }
+ end
+
+ it "creates a buffer with default state" do
+ @buffer = IO::Buffer.new
+
+ @buffer.should_not.external?
+
+ @buffer.should_not.shared?
+ @buffer.should_not.private?
+ @buffer.should_not.readonly?
+
+ @buffer.should_not.empty?
+ @buffer.should_not.null?
+
+ @buffer.should_not.locked?
+ @buffer.should.valid?
+ end
+
+ context "with size argument" do
+ it "creates a new internal buffer if size is less than IO::Buffer::PAGE_SIZE" do
+ size = IO::Buffer::PAGE_SIZE - 1
+ @buffer = IO::Buffer.new(size)
+ @buffer.size.should == size
+ @buffer.should_not.empty?
+
+ @buffer.should.internal?
+ @buffer.should_not.mapped?
+ end
+
+ it "creates a new mapped buffer if size is greater than or equal to IO::Buffer::PAGE_SIZE" do
+ size = IO::Buffer::PAGE_SIZE
+ @buffer = IO::Buffer.new(size)
+ @buffer.size.should == size
+ @buffer.should_not.empty?
+
+ @buffer.should_not.internal?
+ @buffer.should.mapped?
+ end
+
+ it "creates a null buffer if size is 0" do
+ @buffer = IO::Buffer.new(0)
+ @buffer.should.null?
+ @buffer.should.empty?
+ end
+
+ it "raises TypeError if size is not an Integer" do
+ -> { IO::Buffer.new(nil) }.should.raise(TypeError, "not an Integer")
+ -> { IO::Buffer.new(10.0) }.should.raise(TypeError, "not an Integer")
+ end
+
+ it "raises ArgumentError if size is negative" do
+ -> { IO::Buffer.new(-1) }.should.raise(ArgumentError, "Size can't be negative!")
+ end
+ end
+
+ context "with size and flags arguments" do
+ it "forces mapped buffer with IO::Buffer::MAPPED flag" do
+ @buffer = IO::Buffer.new(IO::Buffer::PAGE_SIZE - 1, IO::Buffer::MAPPED)
+ @buffer.should.mapped?
+ @buffer.should_not.internal?
+ @buffer.should_not.empty?
+ end
+
+ it "forces internal buffer with IO::Buffer::INTERNAL flag" do
+ @buffer = IO::Buffer.new(IO::Buffer::PAGE_SIZE, IO::Buffer::INTERNAL)
+ @buffer.should.internal?
+ @buffer.should_not.mapped?
+ @buffer.should_not.empty?
+ end
+
+ it "allows extra flags" do
+ @buffer = IO::Buffer.new(10, IO::Buffer::INTERNAL | IO::Buffer::SHARED | IO::Buffer::READONLY)
+ @buffer.should.internal?
+ @buffer.should.shared?
+ @buffer.should.readonly?
+ end
+
+ it "ignores flags if size is 0" do
+ @buffer = IO::Buffer.new(0, 0xffff)
+ @buffer.should.null?
+ @buffer.should.empty?
+
+ @buffer.should_not.internal?
+ @buffer.should_not.mapped?
+ @buffer.should_not.external?
+
+ @buffer.should_not.shared?
+ @buffer.should_not.readonly?
+
+ @buffer.should_not.locked?
+ @buffer.should.valid?
+ end
+
+ it "raises IO::Buffer::AllocationError if neither IO::Buffer::MAPPED nor IO::Buffer::INTERNAL is given" do
+ -> { IO::Buffer.new(10, IO::Buffer::READONLY) }.should.raise(IO::Buffer::AllocationError, "Could not allocate buffer!")
+ -> { IO::Buffer.new(10, 0) }.should.raise(IO::Buffer::AllocationError, "Could not allocate buffer!")
+ end
+
+ it "raises ArgumentError if flags is negative" do
+ -> { IO::Buffer.new(10, -1) }.should.raise(ArgumentError, "Flags can't be negative!")
+ end
+
+ it "raises TypeError with non-Integer flags" do
+ -> { IO::Buffer.new(10, 0.0) }.should.raise(TypeError, "not an Integer")
+ end
+ end
+end
diff --git a/spec/ruby/core/io/buffer/internal_spec.rb b/spec/ruby/core/io/buffer/internal_spec.rb
new file mode 100644
index 0000000000..73e19eb85e
--- /dev/null
+++ b/spec/ruby/core/io/buffer/internal_spec.rb
@@ -0,0 +1,23 @@
+require_relative '../../../spec_helper'
+
+describe "IO::Buffer#internal?" do
+ after :each do
+ @buffer&.free
+ @buffer = nil
+ end
+
+ it "is true for an internally-allocated buffer" do
+ @buffer = IO::Buffer.new(12)
+ @buffer.internal?.should == true
+ end
+
+ it "is false for an externally-allocated buffer" do
+ @buffer = IO::Buffer.new(12, IO::Buffer::MAPPED)
+ @buffer.internal?.should == false
+ end
+
+ it "is false for a null buffer" do
+ @buffer = IO::Buffer.new(0)
+ @buffer.internal?.should == false
+ end
+end
diff --git a/spec/ruby/core/io/buffer/locked_spec.rb b/spec/ruby/core/io/buffer/locked_spec.rb
new file mode 100644
index 0000000000..249026aa8a
--- /dev/null
+++ b/spec/ruby/core/io/buffer/locked_spec.rb
@@ -0,0 +1,75 @@
+require_relative '../../../spec_helper'
+
+describe "IO::Buffer#locked" do
+ after :each do
+ @buffer&.free
+ @buffer = nil
+ end
+
+ context "when buffer is locked" do
+ it "allows reading and writing operations on the buffer" do
+ @buffer = IO::Buffer.new(4)
+ @buffer.set_string("test")
+ @buffer.locked do
+ @buffer.get_string.should == "test"
+ @buffer.set_string("meat")
+ end
+ @buffer.get_string.should == "meat"
+ end
+
+ it "disallows operations changing buffer itself, raising IO::Buffer::LockedError" do
+ @buffer = IO::Buffer.new(4)
+ @buffer.locked do
+ # Just an example, each method is responsible for checking the lock state.
+ -> { @buffer.resize(8) }.should.raise(IO::Buffer::LockedError)
+ end
+ end
+ end
+
+ it "disallows reentrant locking, raising IO::Buffer::LockedError" do
+ @buffer = IO::Buffer.new(4)
+ @buffer.locked do
+ -> { @buffer.locked {} }.should.raise(IO::Buffer::LockedError, "Buffer already locked!")
+ end
+ end
+
+ it "does not propagate to buffer's slices" do
+ @buffer = IO::Buffer.new(4)
+ slice = @buffer.slice(0, 2)
+ @buffer.locked do
+ @buffer.locked?.should == true
+ slice.locked?.should == false
+ slice.locked { slice.locked?.should == true }
+ end
+ end
+
+ it "does not propagate backwards from buffer's slices" do
+ @buffer = IO::Buffer.new(4)
+ slice = @buffer.slice(0, 2)
+ slice.locked do
+ slice.locked?.should == true
+ @buffer.locked?.should == false
+ @buffer.locked { @buffer.locked?.should == true }
+ end
+ end
+end
+
+describe "IO::Buffer#locked?" do
+ after :each do
+ @buffer&.free
+ @buffer = nil
+ end
+
+ it "is false by default" do
+ @buffer = IO::Buffer.new(4)
+ @buffer.locked?.should == false
+ end
+
+ it "is true only inside of #locked block" do
+ @buffer = IO::Buffer.new(4)
+ @buffer.locked do
+ @buffer.locked?.should == true
+ end
+ @buffer.locked?.should == false
+ end
+end
diff --git a/spec/ruby/core/io/buffer/map_spec.rb b/spec/ruby/core/io/buffer/map_spec.rb
new file mode 100644
index 0000000000..97764c2dd7
--- /dev/null
+++ b/spec/ruby/core/io/buffer/map_spec.rb
@@ -0,0 +1,347 @@
+require_relative '../../../spec_helper'
+
+describe "IO::Buffer.map" do
+ before :all do
+ @tmp_files = []
+
+ @big_file_name = nil
+ @small_file_name = nil
+ end
+
+ after :all do
+ @tmp_files.each {|file| File.delete(file)}
+ end
+
+ def open_fixture
+ unless @small_file_name
+ @small_file_name = tmp("read_text.txt")
+ File.copy_stream(fixture(__dir__, "read_text.txt"), @small_file_name)
+ @tmp_files << @small_file_name
+ end
+ File.open(@small_file_name, "rb+")
+ end
+
+ def open_big_file_fixture
+ unless @big_file_name
+ @big_file_name = tmp("big_file")
+ # Usually 4 kibibytes + 16 bytes
+ File.write(@big_file_name, "12345678" * (IO::Buffer::PAGE_SIZE / 8 + 2))
+ @tmp_files << @big_file_name
+ end
+ File.open(@big_file_name, "rb+")
+ end
+
+ after :each do
+ @buffer&.free
+ @buffer = nil
+ @file&.close
+ @file = nil
+ end
+
+ it "creates a new buffer mapped from a file" do
+ @file = open_fixture
+ @buffer = IO::Buffer.map(@file)
+
+ @buffer.size.should == 9
+ @buffer.get_string.should == "abcâdef\n".b
+ end
+
+ it "allows to close the file after creating buffer, retaining mapping" do
+ file = open_fixture
+ @buffer = IO::Buffer.map(file)
+ file.close
+
+ @buffer.get_string.should == "abcâdef\n".b
+ end
+
+ it "creates a mapped, external, shared buffer" do
+ @file = open_fixture
+ @buffer = IO::Buffer.map(@file)
+
+ @buffer.should_not.internal?
+ @buffer.should.mapped?
+ @buffer.should.external?
+
+ @buffer.should_not.empty?
+ @buffer.should_not.null?
+
+ @buffer.should.shared?
+ @buffer.should_not.private?
+ @buffer.should_not.readonly?
+
+ @buffer.should_not.locked?
+ @buffer.should.valid?
+ end
+
+ # IO::Buffer.map seems not shareable across processes on OpenBSD.
+ # See https://rubyci.s3.amazonaws.com/openbsd-current/ruby-master/log/20260129T163005Z.fail.html.gz
+ platform_is_not :openbsd do
+ guard -> { Process.respond_to?(:fork) } do
+ it "is shareable across processes" do
+ file_name = tmp("shared_buffer")
+ @file = File.open(file_name, "w+")
+ @file << "I'm private"
+ @file.rewind
+ @buffer = IO::Buffer.map(@file)
+
+ IO.popen("-") do |child_pipe|
+ if child_pipe
+ # Synchronize on child's output.
+ child_pipe.readlines.first.chomp.should == @buffer.to_s
+ @buffer.get_string.should == "I'm shared!"
+
+ @file.read.should == "I'm shared!"
+ else
+ @buffer.set_string("I'm shared!")
+ puts @buffer
+ end
+ ensure
+ child_pipe&.close
+ end
+ ensure
+ File.unlink(file_name)
+ end
+ end
+ end
+
+ context "with an empty file" do
+ ruby_version_is "4.0" do
+ it "raises ArgumentError" do
+ file_name = tmp("empty.txt")
+ @file = File.open(file_name, "wb+")
+ @tmp_files << file_name
+ -> { IO::Buffer.map(@file) }.should.raise(ArgumentError, "Invalid negative or zero file size!")
+ end
+ end
+ end
+
+ context "with a file opened only for reading" do
+ it "raises a SystemCallError unless read-only" do
+ @file = File.open(fixture(__dir__, "read_text.txt"), "rb")
+ -> { IO::Buffer.map(@file) }.should.raise(SystemCallError)
+ end
+ end
+
+ context "with size argument" do
+ it "limits the buffer to the specified size in bytes, starting from the start of the file" do
+ @file = open_fixture
+ @buffer = IO::Buffer.map(@file, 4)
+
+ @buffer.size.should == 4
+ @buffer.get_string.should == "abc\xC3".b
+ end
+
+ it "maps the whole file if size is nil" do
+ @file = open_fixture
+ @buffer = IO::Buffer.map(@file, nil)
+
+ @buffer.size.should == 9
+ end
+
+ context "if size is 0" do
+ ruby_version_is "4.0" do
+ it "raises ArgumentError" do
+ @file = open_fixture
+ -> { IO::Buffer.map(@file, 0) }.should.raise(ArgumentError, "Size can't be zero!")
+ end
+ end
+ end
+
+ it "raises TypeError if size is not an Integer or nil" do
+ @file = open_fixture
+ -> { IO::Buffer.map(@file, "10") }.should.raise(TypeError, "not an Integer")
+ -> { IO::Buffer.map(@file, 10.0) }.should.raise(TypeError, "not an Integer")
+ end
+
+ it "raises ArgumentError if size is negative" do
+ @file = open_fixture
+ -> { IO::Buffer.map(@file, -1) }.should.raise(ArgumentError, "Size can't be negative!")
+ end
+
+ ruby_version_is ""..."4.0" do
+ # May or may not cause a crash on access.
+ it "is undefined behavior if size is larger than file size"
+ end
+
+ ruby_version_is "4.0" do
+ it "raises ArgumentError if size is larger than file size" do
+ @file = open_fixture
+ -> { IO::Buffer.map(@file, 8192) }.should.raise(ArgumentError, "Size can't be larger than file size!")
+ end
+ end
+ end
+
+ context "with size and offset arguments" do
+ # Neither Windows nor macOS have clear, stable behavior with non-zero offset.
+ # https://bugs.ruby-lang.org/issues/21700
+ platform_is :linux do
+ context "if offset is an allowed value for system call" do
+ it "maps the span specified by size starting from the offset" do
+ @file = open_big_file_fixture
+ @buffer = IO::Buffer.map(@file, 14, IO::Buffer::PAGE_SIZE)
+
+ @buffer.size.should == 14
+ @buffer.get_string(0, 14).should == "12345678123456"
+ end
+
+ context "if size is nil" do
+ ruby_version_is ""..."4.0" do
+ it "maps the rest of the file" do
+ @file = open_big_file_fixture
+ @buffer = IO::Buffer.map(@file, nil, IO::Buffer::PAGE_SIZE)
+
+ @buffer.get_string(0, 1).should == "1"
+ end
+
+ it "incorrectly sets buffer's size to file's full size" do
+ @file = open_big_file_fixture
+ @buffer = IO::Buffer.map(@file, nil, IO::Buffer::PAGE_SIZE)
+
+ @buffer.size.should == @file.size
+ end
+ end
+
+ ruby_version_is "4.0" do
+ it "maps the rest of the file" do
+ @file = open_big_file_fixture
+ @buffer = IO::Buffer.map(@file, nil, IO::Buffer::PAGE_SIZE)
+
+ @buffer.get_string(0, 1).should == "1"
+ end
+
+ it "sets buffer's size to file's remaining size" do
+ @file = open_big_file_fixture
+ @buffer = IO::Buffer.map(@file, nil, IO::Buffer::PAGE_SIZE)
+
+ @buffer.size.should == (@file.size - IO::Buffer::PAGE_SIZE)
+ end
+ end
+ end
+ end
+ end
+
+ it "maps the file from the start if offset is 0" do
+ @file = open_fixture
+ @buffer = IO::Buffer.map(@file, 4, 0)
+
+ @buffer.size.should == 4
+ @buffer.get_string.should == "abc\xC3".b
+ end
+
+ ruby_version_is ""..."4.0" do
+ # May or may not cause a crash on access.
+ it "is undefined behavior if offset+size is larger than file size"
+ end
+
+ ruby_version_is "4.0" do
+ it "raises ArgumentError if offset+size is larger than file size" do
+ @file = open_big_file_fixture
+ -> { IO::Buffer.map(@file, 17, IO::Buffer::PAGE_SIZE) }.should.raise(ArgumentError, "Offset too large!")
+ ensure
+ # Windows requires the file to be closed before deletion.
+ @file.close unless @file.closed?
+ end
+ end
+
+ it "raises TypeError if offset is not convertible to Integer" do
+ @file = open_fixture
+ -> { IO::Buffer.map(@file, 4, "4096") }.should.raise(TypeError, /no implicit conversion/)
+ -> { IO::Buffer.map(@file, 4, nil) }.should.raise(TypeError, /no implicit conversion/)
+ end
+
+ ruby_version_is "4.0" do
+ it "raises ArgumentError if offset is negative" do
+ @file = open_fixture
+ -> { IO::Buffer.map(@file, 4, -1) }.should.raise(ArgumentError, "Offset can't be negative!")
+ end
+ end
+ end
+
+ context "with flags argument" do
+ context "when READONLY flag is specified" do
+ it "sets readonly flag on the buffer, allowing only reads" do
+ @file = open_fixture
+ @buffer = IO::Buffer.map(@file, nil, 0, IO::Buffer::READONLY)
+
+ @buffer.should.readonly?
+
+ @buffer.get_string.should == "abc\xC3\xA2def\n".b
+ end
+
+ it "allows mapping read-only files" do
+ @file = File.open(fixture(__dir__, "read_text.txt"), "rb")
+ @buffer = IO::Buffer.map(@file, nil, 0, IO::Buffer::READONLY)
+
+ @buffer.should.readonly?
+
+ @buffer.get_string.should == "abc\xC3\xA2def\n".b
+ end
+
+ it "causes IO::Buffer::AccessError on write" do
+ @file = open_fixture
+ @buffer = IO::Buffer.map(@file, nil, 0, IO::Buffer::READONLY)
+
+ -> { @buffer.set_string("test") }.should.raise(IO::Buffer::AccessError, "Buffer is not writable!")
+ end
+ end
+
+ context "when PRIVATE is specified" do
+ it "sets private flag on the buffer, making it freely modifiable" do
+ @file = open_fixture
+ @buffer = IO::Buffer.map(@file, nil, 0, IO::Buffer::PRIVATE)
+
+ @buffer.should.private?
+ @buffer.should_not.shared?
+ @buffer.should_not.external?
+
+ @buffer.get_string.should == "abc\xC3\xA2def\n".b
+ @buffer.set_string("test12345")
+ @buffer.get_string.should == "test12345".b
+
+ @file.read.should == "abcâdef\n".b
+ end
+
+ it "allows mapping read-only files and modifying the buffer" do
+ @file = File.open(fixture(__dir__, "read_text.txt"), "rb")
+ @buffer = IO::Buffer.map(@file, nil, 0, IO::Buffer::PRIVATE)
+
+ @buffer.should.private?
+ @buffer.should_not.shared?
+ @buffer.should_not.external?
+
+ @buffer.get_string.should == "abc\xC3\xA2def\n".b
+ @buffer.set_string("test12345")
+ @buffer.get_string.should == "test12345".b
+
+ @file.read.should == "abcâdef\n".b
+ end
+
+ guard -> { Process.respond_to?(:fork) } do
+ it "is not shared across processes" do
+ file_name = tmp("shared_buffer")
+ @file = File.open(file_name, "w+")
+ @file << "I'm private"
+ @file.rewind
+ @buffer = IO::Buffer.map(@file, nil, 0, IO::Buffer::PRIVATE)
+
+ IO.popen("-") do |child_pipe|
+ if child_pipe
+ # Synchronize on child's output.
+ child_pipe.readlines.first.chomp.should == @buffer.to_s
+ @buffer.get_string.should == "I'm private"
+
+ @file.read.should == "I'm private"
+ else
+ @buffer.set_string("I'm shared!")
+ puts @buffer
+ end
+ ensure
+ child_pipe&.close
+ end
+ ensure
+ File.unlink(file_name)
+ end
+ end
+ end
+ end
+end
diff --git a/spec/ruby/core/io/buffer/mapped_spec.rb b/spec/ruby/core/io/buffer/mapped_spec.rb
new file mode 100644
index 0000000000..0decb97704
--- /dev/null
+++ b/spec/ruby/core/io/buffer/mapped_spec.rb
@@ -0,0 +1,23 @@
+require_relative '../../../spec_helper'
+
+describe "IO::Buffer#mapped?" do
+ after :each do
+ @buffer&.free
+ @buffer = nil
+ end
+
+ it "is true for a buffer with mapped memory" do
+ @buffer = IO::Buffer.new(12, IO::Buffer::MAPPED)
+ @buffer.mapped?.should == true
+ end
+
+ it "is false for a buffer with non-mapped memory" do
+ @buffer = IO::Buffer.for("string")
+ @buffer.mapped?.should == false
+ end
+
+ it "is false for a null buffer" do
+ @buffer = IO::Buffer.new(0)
+ @buffer.mapped?.should == false
+ end
+end
diff --git a/spec/ruby/core/io/buffer/not_spec.rb b/spec/ruby/core/io/buffer/not_spec.rb
new file mode 100644
index 0000000000..4737a30bde
--- /dev/null
+++ b/spec/ruby/core/io/buffer/not_spec.rb
@@ -0,0 +1,37 @@
+require_relative '../../../spec_helper'
+
+describe :io_buffer_not, shared: true do
+ it "inverts every bit of the buffer" do
+ IO::Buffer.for(+"12345") do |buffer|
+ result = buffer.send(@method)
+ result.get_string.should == "\xCE\xCD\xCC\xCB\xCA".b
+ result.free
+ end
+ end
+end
+
+describe "IO::Buffer#~" do
+ it_behaves_like :io_buffer_not, :~
+
+ it "creates a new internal buffer of the same size" do
+ IO::Buffer.for(+"12345") do |buffer|
+ result = ~buffer
+ result.should_not.equal? buffer
+ result.should.internal?
+ result.size.should == buffer.size
+ result.free
+ end
+ end
+end
+
+describe "IO::Buffer#not!" do
+ it_behaves_like :io_buffer_not, :not!
+
+ it "modifies the buffer in place" do
+ IO::Buffer.for(+"12345") do |buffer|
+ result = buffer.not!
+ result.should.equal? buffer
+ result.should.external?
+ end
+ end
+end
diff --git a/spec/ruby/core/io/buffer/null_spec.rb b/spec/ruby/core/io/buffer/null_spec.rb
new file mode 100644
index 0000000000..380a98bde1
--- /dev/null
+++ b/spec/ruby/core/io/buffer/null_spec.rb
@@ -0,0 +1,27 @@
+require_relative '../../../spec_helper'
+require_relative 'shared/null_and_empty'
+
+describe "IO::Buffer#null?" do
+ after :each do
+ @buffer&.free
+ @buffer = nil
+ end
+
+ it_behaves_like :io_buffer_null_and_empty, :null?
+
+ it "is false for a 0-length String-backed buffer created with .for" do
+ @buffer = IO::Buffer.for("")
+ @buffer.null?.should == false
+ end
+
+ it "is false for a 0-length String-backed buffer created with .string" do
+ IO::Buffer.string(0) do |buffer|
+ buffer.null?.should == false
+ end
+ end
+
+ it "is false for a 0-length slice of a buffer with size > 0" do
+ @buffer = IO::Buffer.new(4)
+ @buffer.slice(3, 0).null?.should == false
+ end
+end
diff --git a/spec/ruby/core/io/buffer/or_spec.rb b/spec/ruby/core/io/buffer/or_spec.rb
new file mode 100644
index 0000000000..3e627c216c
--- /dev/null
+++ b/spec/ruby/core/io/buffer/or_spec.rb
@@ -0,0 +1,62 @@
+require_relative '../../../spec_helper'
+
+describe :io_buffer_or, shared: true do
+ it "applies the argument buffer as an OR bit mask across the whole buffer" do
+ IO::Buffer.for(+"12345") do |buffer|
+ IO::Buffer.for(+"\xF8\x8F") do |mask|
+ result = buffer.send(@method, mask)
+ result.get_string.should == "\xF9\xBF\xFB\xBF\xFD".b
+ result.free
+ end
+ end
+ end
+
+ it "ignores extra parts of mask if it is longer than source buffer" do
+ IO::Buffer.for(+"12345") do |buffer|
+ IO::Buffer.for(+"\xF8\x8F\x00\x00\x00\xFF\xFF") do |mask|
+ result = buffer.send(@method, mask)
+ result.get_string.should == "\xF9\xBF345".b
+ result.free
+ end
+ end
+ end
+
+ it "raises TypeError if mask is not an IO::Buffer" do
+ IO::Buffer.for(+"12345") do |buffer|
+ -> { buffer.send(@method, "\xF8\x8F") }.should.raise(TypeError, "wrong argument type String (expected IO::Buffer)")
+ -> { buffer.send(@method, 0xF8) }.should.raise(TypeError, "wrong argument type Integer (expected IO::Buffer)")
+ -> { buffer.send(@method, nil) }.should.raise(TypeError, "wrong argument type nil (expected IO::Buffer)")
+ end
+ end
+end
+
+describe "IO::Buffer#|" do
+ it_behaves_like :io_buffer_or, :|
+
+ it "creates a new internal buffer of the same size" do
+ IO::Buffer.for(+"12345") do |buffer|
+ IO::Buffer.for(+"\xF8\x8F") do |mask|
+ result = buffer | mask
+ result.should_not.equal? buffer
+ result.should.internal?
+ result.size.should == buffer.size
+ result.free
+ buffer.get_string.should == "12345".b
+ end
+ end
+ end
+end
+
+describe "IO::Buffer#or!" do
+ it_behaves_like :io_buffer_or, :or!
+
+ it "modifies the buffer in place" do
+ IO::Buffer.for(+"12345") do |buffer|
+ IO::Buffer.for(+"\xF8\x8F") do |mask|
+ result = buffer.or!(mask)
+ result.should.equal? buffer
+ result.should.external?
+ end
+ end
+ end
+end
diff --git a/spec/ruby/core/io/buffer/private_spec.rb b/spec/ruby/core/io/buffer/private_spec.rb
new file mode 100644
index 0000000000..6e6afee34c
--- /dev/null
+++ b/spec/ruby/core/io/buffer/private_spec.rb
@@ -0,0 +1,23 @@
+require_relative '../../../spec_helper'
+
+describe "IO::Buffer#private?" do
+ after :each do
+ @buffer&.free
+ @buffer = nil
+ end
+
+ it "is true for a buffer created with PRIVATE flag" do
+ @buffer = IO::Buffer.new(12, IO::Buffer::INTERNAL | IO::Buffer::PRIVATE)
+ @buffer.private?.should == true
+ end
+
+ it "is false for a buffer created without PRIVATE flag" do
+ @buffer = IO::Buffer.new(12, IO::Buffer::INTERNAL)
+ @buffer.private?.should == false
+ end
+
+ it "is false for a null buffer" do
+ @buffer = IO::Buffer.new(0)
+ @buffer.private?.should == false
+ end
+end
diff --git a/spec/ruby/core/io/buffer/readonly_spec.rb b/spec/ruby/core/io/buffer/readonly_spec.rb
new file mode 100644
index 0000000000..4eefc9f29f
--- /dev/null
+++ b/spec/ruby/core/io/buffer/readonly_spec.rb
@@ -0,0 +1,28 @@
+require_relative '../../../spec_helper'
+
+describe "IO::Buffer#readonly?" do
+ after :each do
+ @buffer&.free
+ @buffer = nil
+ end
+
+ it "is true for a buffer created with READONLY flag" do
+ @buffer = IO::Buffer.new(12, IO::Buffer::INTERNAL | IO::Buffer::READONLY)
+ @buffer.readonly?.should == true
+ end
+
+ it "is true for a buffer that is non-writable" do
+ @buffer = IO::Buffer.for("string")
+ @buffer.readonly?.should == true
+ end
+
+ it "is false for a modifiable buffer" do
+ @buffer = IO::Buffer.new(12)
+ @buffer.readonly?.should == false
+ end
+
+ it "is false for a null buffer" do
+ @buffer = IO::Buffer.new(0)
+ @buffer.readonly?.should == false
+ end
+end
diff --git a/spec/ruby/core/io/buffer/resize_spec.rb b/spec/ruby/core/io/buffer/resize_spec.rb
new file mode 100644
index 0000000000..6e684475f3
--- /dev/null
+++ b/spec/ruby/core/io/buffer/resize_spec.rb
@@ -0,0 +1,151 @@
+require_relative '../../../spec_helper'
+
+describe "IO::Buffer#resize" do
+ after :each do
+ @buffer&.free
+ @buffer = nil
+ end
+
+ context "with a buffer created with .new" do
+ it "resizes internal buffer, preserving type" do
+ @buffer = IO::Buffer.new(4)
+ @buffer.resize(IO::Buffer::PAGE_SIZE)
+ @buffer.size.should == IO::Buffer::PAGE_SIZE
+ @buffer.internal?.should == true
+ @buffer.mapped?.should == false
+ end
+
+ platform_is :linux do
+ it "resizes mapped buffer, preserving type" do
+ @buffer = IO::Buffer.new(IO::Buffer::PAGE_SIZE, IO::Buffer::MAPPED)
+ @buffer.resize(4)
+ @buffer.size.should == 4
+ @buffer.internal?.should == false
+ @buffer.mapped?.should == true
+ end
+ end
+
+ platform_is_not :linux do
+ it "resizes mapped buffer, changing type to internal" do
+ @buffer = IO::Buffer.new(IO::Buffer::PAGE_SIZE, IO::Buffer::MAPPED)
+ @buffer.resize(4)
+ @buffer.size.should == 4
+ @buffer.internal?.should == true
+ @buffer.mapped?.should == false
+ end
+ end
+ end
+
+ context "with a file-backed buffer created with .map" do
+ it "disallows resizing shared buffer, raising IO::Buffer::AccessError" do
+ File.open(__FILE__, "r+") do |file|
+ @buffer = IO::Buffer.map(file)
+ -> { @buffer.resize(10) }.should.raise(IO::Buffer::AccessError, "Cannot resize external buffer!")
+ end
+ end
+
+ it "resizes private buffer, discarding excess contents" do
+ File.open(__FILE__, "r") do |file|
+ @buffer = IO::Buffer.map(file, nil, 0, IO::Buffer::PRIVATE)
+ @buffer.resize(10)
+ @buffer.size.should == 10
+ @buffer.get_string.should == "require_re"
+ @buffer.resize(12)
+ @buffer.size.should == 12
+ @buffer.get_string.should == "require_re\0\0"
+ end
+ end
+ end
+
+ context "with a String-backed buffer created with .for" do
+ context "without a block" do
+ it "disallows resizing, raising IO::Buffer::AccessError" do
+ @buffer = IO::Buffer.for(+"test")
+ -> { @buffer.resize(10) }.should.raise(IO::Buffer::AccessError, "Cannot resize external buffer!")
+ end
+ end
+
+ context "with a block" do
+ it "disallows resizing, raising IO::Buffer::AccessError" do
+ IO::Buffer.for(+'test') do |buffer|
+ -> { buffer.resize(10) }.should.raise(IO::Buffer::AccessError, "Cannot resize external buffer!")
+ end
+ end
+ end
+ end
+
+ context "with a String-backed buffer created with .string" do
+ it "disallows resizing, raising IO::Buffer::AccessError" do
+ IO::Buffer.string(4) do |buffer|
+ -> { buffer.resize(10) }.should.raise(IO::Buffer::AccessError, "Cannot resize external buffer!")
+ end
+ end
+ end
+
+ context "with a null buffer" do
+ it "allows resizing a 0-sized buffer, creating a regular buffer according to new size" do
+ @buffer = IO::Buffer.new(0)
+ @buffer.resize(IO::Buffer::PAGE_SIZE)
+ @buffer.size.should == IO::Buffer::PAGE_SIZE
+ @buffer.internal?.should == false
+ @buffer.mapped?.should == true
+ end
+
+ it "allows resizing after a free, creating a regular buffer according to new size" do
+ @buffer = IO::Buffer.for("test")
+ @buffer.free
+ @buffer.resize(10)
+ @buffer.size.should == 10
+ @buffer.internal?.should == true
+ @buffer.mapped?.should == false
+ end
+ end
+
+ it "allows resizing to 0, freeing memory" do
+ @buffer = IO::Buffer.new(4)
+ @buffer.resize(0)
+ @buffer.null?.should == true
+ end
+
+ it "can be called repeatedly" do
+ @buffer = IO::Buffer.new(4)
+ @buffer.resize(10)
+ @buffer.resize(27)
+ @buffer.resize(1)
+ @buffer.size.should == 1
+ end
+
+ it "always clears extra memory" do
+ @buffer = IO::Buffer.new(4)
+ @buffer.set_string("test")
+ # This should not cause a re-allocation, just a technical resizing,
+ # even with very aggressive memory allocation.
+ @buffer.resize(2)
+ @buffer.resize(4)
+ @buffer.get_string.should == "te\0\0"
+ end
+
+ it "is disallowed while locked, raising IO::Buffer::LockedError" do
+ @buffer = IO::Buffer.new(4)
+ @buffer.locked do
+ -> { @buffer.resize(10) }.should.raise(IO::Buffer::LockedError, "Cannot resize locked buffer!")
+ end
+ end
+
+ it "raises ArgumentError if size is negative" do
+ @buffer = IO::Buffer.new(4)
+ -> { @buffer.resize(-1) }.should.raise(ArgumentError, "Size can't be negative!")
+ end
+
+ it "raises TypeError if size is not an Integer" do
+ @buffer = IO::Buffer.new(4)
+ -> { @buffer.resize(nil) }.should.raise(TypeError, "not an Integer")
+ -> { @buffer.resize(10.0) }.should.raise(TypeError, "not an Integer")
+ end
+
+ context "with a slice of a buffer" do
+ # Current behavior of slice resizing seems unintended (it's undocumented, too).
+ # It either creates a completely new buffer, or breaks the slice on size 0.
+ it "needs to be reviewed for spec completeness"
+ end
+end
diff --git a/spec/ruby/core/io/buffer/shared/null_and_empty.rb b/spec/ruby/core/io/buffer/shared/null_and_empty.rb
new file mode 100644
index 0000000000..f8abc5f0fc
--- /dev/null
+++ b/spec/ruby/core/io/buffer/shared/null_and_empty.rb
@@ -0,0 +1,57 @@
+describe :io_buffer_null_and_empty, shared: true do
+ it "is false for a buffer with size > 0" do
+ @buffer = IO::Buffer.new(1)
+ @buffer.send(@method).should == false
+ end
+
+ it "is false for a slice with length > 0" do
+ @buffer = IO::Buffer.new(4)
+ @buffer.slice(1, 2).send(@method).should == false
+ end
+
+ it "is false for a file-mapped buffer" do
+ File.open(__FILE__, "rb") do |file|
+ @buffer = IO::Buffer.map(file, nil, 0, IO::Buffer::READONLY)
+ @buffer.send(@method).should == false
+ end
+ end
+
+ it "is false for a non-empty String-backed buffer created with .for" do
+ @buffer = IO::Buffer.for("test")
+ @buffer.send(@method).should == false
+ end
+
+ it "is false for a non-empty String-backed buffer created with .string" do
+ IO::Buffer.string(4) do |buffer|
+ buffer.send(@method).should == false
+ end
+ end
+
+ it "is true for a 0-sized buffer" do
+ @buffer = IO::Buffer.new(0)
+ @buffer.send(@method).should == true
+ end
+
+ it "is true for a slice of a 0-sized buffer" do
+ @buffer = IO::Buffer.new(0)
+ @buffer.slice(0, 0).send(@method).should == true
+ end
+
+ it "is true for a freed buffer" do
+ @buffer = IO::Buffer.new(1)
+ @buffer.free
+ @buffer.send(@method).should == true
+ end
+
+ it "is true for a buffer resized to 0" do
+ @buffer = IO::Buffer.new(1)
+ @buffer.resize(0)
+ @buffer.send(@method).should == true
+ end
+
+ it "is true for a buffer whose memory was transferred" do
+ buffer = IO::Buffer.new(1)
+ @buffer = buffer.transfer
+ buffer.send(@method).should == true
+ end
+end
diff --git a/spec/ruby/core/io/buffer/shared_spec.rb b/spec/ruby/core/io/buffer/shared_spec.rb
new file mode 100644
index 0000000000..2cc93e6d08
--- /dev/null
+++ b/spec/ruby/core/io/buffer/shared_spec.rb
@@ -0,0 +1,33 @@
+require_relative '../../../spec_helper'
+
+describe "IO::Buffer#shared?" do
+ after :each do
+ @buffer&.free
+ @buffer = nil
+ end
+
+ it "is true for a buffer created with SHARED flag" do
+ @buffer = IO::Buffer.new(12, IO::Buffer::INTERNAL | IO::Buffer::SHARED)
+ @buffer.shared?.should == true
+ end
+
+ it "is true for a non-private buffer created with .map" do
+ path = fixture(__dir__, "read_text.txt")
+ file = File.open(path, "r+")
+ @buffer = IO::Buffer.map(file)
+ @buffer.shared?.should == true
+ ensure
+ @buffer.free
+ file.close
+ end
+
+ it "is false for an unshared buffer" do
+ @buffer = IO::Buffer.new(12)
+ @buffer.shared?.should == false
+ end
+
+ it "is false for a null buffer" do
+ @buffer = IO::Buffer.new(0)
+ @buffer.shared?.should == false
+ end
+end
diff --git a/spec/ruby/core/io/buffer/string_spec.rb b/spec/ruby/core/io/buffer/string_spec.rb
new file mode 100644
index 0000000000..4c73ba5e1e
--- /dev/null
+++ b/spec/ruby/core/io/buffer/string_spec.rb
@@ -0,0 +1,62 @@
+require_relative '../../../spec_helper'
+
+describe "IO::Buffer.string" do
+ it "creates a modifiable buffer for the duration of the block" do
+ IO::Buffer.string(7) do |buffer|
+ @buffer = buffer
+
+ buffer.size.should == 7
+ buffer.get_string.should == "\0\0\0\0\0\0\0".b
+
+ buffer.set_string("test")
+ buffer.get_string.should == "test\0\0\0"
+ end
+ @buffer.should.null?
+ end
+
+ it "returns contents of the buffer as a binary string" do
+ string =
+ IO::Buffer.string(7) do |buffer|
+ buffer.set_string("ä test")
+ end
+ string.should == "\xC3\xA4 test".b
+ end
+
+ it "creates an external buffer" do
+ IO::Buffer.string(8) do |buffer|
+ buffer.should_not.internal?
+ buffer.should_not.mapped?
+ buffer.should.external?
+
+ buffer.should_not.empty?
+ buffer.should_not.null?
+
+ buffer.should_not.shared?
+ buffer.should_not.private?
+ buffer.should_not.readonly?
+
+ buffer.should_not.locked?
+ buffer.should.valid?
+ end
+ end
+
+ it "returns an empty string if size is 0" do
+ string =
+ IO::Buffer.string(0) do |buffer|
+ buffer.size.should == 0
+ end
+ string.should == ""
+ end
+
+ it "raises ArgumentError if size is negative" do
+ -> { IO::Buffer.string(-1) {} }.should.raise(ArgumentError, "negative string size (or size too big)")
+ end
+
+ it "raises RangeError if size is too large" do
+ -> { IO::Buffer.string(2 ** 232) {} }.should.raise(RangeError, /\Abignum too big to convert into [`']long'\z/)
+ end
+
+ it "raises LocalJumpError if no block is given" do
+ -> { IO::Buffer.string(7) }.should.raise(LocalJumpError, "no block given")
+ end
+end
diff --git a/spec/ruby/core/io/buffer/transfer_spec.rb b/spec/ruby/core/io/buffer/transfer_spec.rb
new file mode 100644
index 0000000000..3bc08998dd
--- /dev/null
+++ b/spec/ruby/core/io/buffer/transfer_spec.rb
@@ -0,0 +1,117 @@
+require_relative '../../../spec_helper'
+
+describe "IO::Buffer#transfer" do
+ after :each do
+ @buffer&.free
+ @buffer = nil
+ end
+
+ context "with a buffer created with .new" do
+ it "transfers internal memory to a new buffer, nullifying the original" do
+ buffer = IO::Buffer.new(4)
+ info = buffer.to_s
+ @buffer = buffer.transfer
+ @buffer.to_s.should == info
+ buffer.null?.should == true
+ end
+
+ it "transfers mapped memory to a new buffer, nullifying the original" do
+ buffer = IO::Buffer.new(4, IO::Buffer::MAPPED)
+ info = buffer.to_s
+ @buffer = buffer.transfer
+ @buffer.to_s.should == info
+ buffer.null?.should == true
+ end
+ end
+
+ context "with a file-backed buffer created with .map" do
+ it "transfers mapped memory to a new buffer, nullifying the original" do
+ File.open(__FILE__, "r") do |file|
+ buffer = IO::Buffer.map(file, nil, 0, IO::Buffer::READONLY)
+ info = buffer.to_s
+ @buffer = buffer.transfer
+ @buffer.to_s.should == info
+ buffer.null?.should == true
+ end
+ end
+ end
+
+ context "with a String-backed buffer created with .for" do
+ context "without a block" do
+ it "transfers memory to a new buffer, nullifying the original" do
+ buffer = IO::Buffer.for("test")
+ info = buffer.to_s
+ @buffer = buffer.transfer
+ @buffer.to_s.should == info
+ buffer.null?.should == true
+ end
+ end
+
+ context "with a block" do
+ it "transfers memory to a new buffer, breaking the transaction by nullifying the original" do
+ IO::Buffer.for(+"test") do |buffer|
+ info = buffer.to_s
+ @buffer = buffer.transfer
+ @buffer.to_s.should == info
+ buffer.null?.should == true
+ end
+ @buffer.null?.should == false
+ end
+ end
+ end
+
+ context "with a String-backed buffer created with .string" do
+ it "transfers memory to a new buffer, breaking the transaction by nullifying the original" do
+ IO::Buffer.string(4) do |buffer|
+ info = buffer.to_s
+ @buffer = buffer.transfer
+ @buffer.to_s.should == info
+ buffer.null?.should == true
+ end
+ @buffer.null?.should == false
+ end
+ end
+
+ it "allows multiple transfers" do
+ buffer_1 = IO::Buffer.new(4)
+ buffer_2 = buffer_1.transfer
+ @buffer = buffer_2.transfer
+ buffer_1.null?.should == true
+ buffer_2.null?.should == true
+ @buffer.null?.should == false
+ end
+
+ it "is disallowed while locked, raising IO::Buffer::LockedError" do
+ @buffer = IO::Buffer.new(4)
+ @buffer.locked do
+ -> { @buffer.transfer }.should.raise(IO::Buffer::LockedError, "Cannot transfer ownership of locked buffer!")
+ end
+ end
+
+ context "with a slice of a buffer" do
+ it "transfers source to a new slice, not touching the buffer" do
+ @buffer = IO::Buffer.new(4)
+ @buffer.set_string("test")
+ slice = @buffer.slice(0, 2)
+ slice.get_string.should == "te"
+
+ new_slice = slice.transfer
+ slice.null?.should == true
+ new_slice.null?.should == false
+ @buffer.null?.should == false
+
+ new_slice.set_string("ea")
+ @buffer.get_string.should == "east"
+ end
+
+ it "nullifies buffer, invalidating the slice" do
+ buffer = IO::Buffer.new(4)
+ slice = buffer.slice(0, 2)
+ @buffer = buffer.transfer
+
+ slice.null?.should == false
+ slice.valid?.should == false
+ -> { slice.get_string }.should.raise(IO::Buffer::InvalidatedError, "Buffer has been invalidated!")
+ end
+ end
+end
diff --git a/spec/ruby/core/io/buffer/valid_spec.rb b/spec/ruby/core/io/buffer/valid_spec.rb
new file mode 100644
index 0000000000..b84bdd0cfd
--- /dev/null
+++ b/spec/ruby/core/io/buffer/valid_spec.rb
@@ -0,0 +1,99 @@
+require_relative '../../../spec_helper'
+
+describe "IO::Buffer#valid?" do
+ after :each do
+ @buffer&.free
+ @buffer = nil
+ end
+
+ # Non-slices are always valid
+ context "with a non-slice buffer" do
+ it "is true for a regular buffer" do
+ @buffer = IO::Buffer.new(4)
+ @buffer.valid?.should == true
+ end
+
+ it "is true for a 0-size buffer" do
+ @buffer = IO::Buffer.new(0)
+ @buffer.valid?.should == true
+ end
+
+ it "is true for a freed buffer" do
+ @buffer = IO::Buffer.new(4)
+ @buffer.free
+ @buffer.valid?.should == true
+ end
+
+ it "is true for a freed file-backed buffer" do
+ File.open(__FILE__, "r") do |file|
+ @buffer = IO::Buffer.map(file, nil, 0, IO::Buffer::READONLY)
+ @buffer.valid?.should == true
+ @buffer.free
+ @buffer.valid?.should == true
+ end
+ end
+
+ it "is true for a freed string-backed buffer" do
+ @buffer = IO::Buffer.for("hello")
+ @buffer.valid?.should == true
+ @buffer.free
+ @buffer.valid?.should == true
+ end
+ end
+
+ # "A buffer becomes invalid if it is a slice of another buffer (or string)
+ # which has been freed or re-allocated at a different address."
+ context "with a slice" do
+ it "is true for a slice of a live buffer" do
+ @buffer = IO::Buffer.new(4)
+ slice = @buffer.slice(0, 2)
+ slice.valid?.should == true
+ end
+
+ context "when buffer is resized" do
+ it "is false when slice becomes outside the buffer" do
+ @buffer = IO::Buffer.new(4)
+ slice = @buffer.slice(2, 2)
+ @buffer.resize(3)
+ slice.valid?.should == false
+ end
+ end
+
+ it "is false for a slice of a transferred buffer" do
+ buffer = IO::Buffer.new(4)
+ slice = buffer.slice(0, 2)
+ @buffer = buffer.transfer
+ slice.valid?.should == false
+ end
+
+ it "is false for a slice of a freed buffer" do
+ @buffer = IO::Buffer.new(4)
+ slice = @buffer.slice(0, 2)
+ @buffer.free
+ slice.valid?.should == false
+ end
+
+ it "is false for a slice of a freed file-backed buffer" do
+ File.open(__FILE__, "r") do |file|
+ @buffer = IO::Buffer.map(file, nil, 0, IO::Buffer::READONLY)
+ slice = @buffer.slice(0, 2)
+ slice.valid?.should == true
+ @buffer.free
+ slice.valid?.should == false
+ end
+ end
+
+ it "is true for a slice of a freed string-backed buffer while string is alive" do
+ @buffer = IO::Buffer.for("alive")
+ slice = @buffer.slice(0, 2)
+ slice.valid?.should == true
+ @buffer.free
+ slice.valid?.should == true
+ end
+
+ # There probably should be a test with a garbage-collected string,
+ # but it's not clear how to force that.
+
+ it "needs to be reviewed for spec completeness"
+ end
+end
diff --git a/spec/ruby/core/io/buffer/xor_spec.rb b/spec/ruby/core/io/buffer/xor_spec.rb
new file mode 100644
index 0000000000..9287611f7f
--- /dev/null
+++ b/spec/ruby/core/io/buffer/xor_spec.rb
@@ -0,0 +1,62 @@
+require_relative '../../../spec_helper'
+
+describe :io_buffer_xor, shared: true do
+ it "applies the argument buffer as an XOR bit mask across the whole buffer" do
+ IO::Buffer.for(+"12345") do |buffer|
+ IO::Buffer.for(+"\xF8\x8F") do |mask|
+ result = buffer.send(@method, mask)
+ result.get_string.should == "\xC9\xBD\xCB\xBB\xCD".b
+ result.free
+ end
+ end
+ end
+
+ it "ignores extra parts of mask if it is longer than source buffer" do
+ IO::Buffer.for(+"12345") do |buffer|
+ IO::Buffer.for(+"\xF8\x8F\x00\x00\x00\xFF\xFF") do |mask|
+ result = buffer.send(@method, mask)
+ result.get_string.should == "\xC9\xBD345".b
+ result.free
+ end
+ end
+ end
+
+ it "raises TypeError if mask is not an IO::Buffer" do
+ IO::Buffer.for(+"12345") do |buffer|
+ -> { buffer.send(@method, "\xF8\x8F") }.should.raise(TypeError, "wrong argument type String (expected IO::Buffer)")
+ -> { buffer.send(@method, 0xF8) }.should.raise(TypeError, "wrong argument type Integer (expected IO::Buffer)")
+ -> { buffer.send(@method, nil) }.should.raise(TypeError, "wrong argument type nil (expected IO::Buffer)")
+ end
+ end
+end
+
+describe "IO::Buffer#^" do
+ it_behaves_like :io_buffer_xor, :^
+
+ it "creates a new internal buffer of the same size" do
+ IO::Buffer.for(+"12345") do |buffer|
+ IO::Buffer.for(+"\xF8\x8F") do |mask|
+ result = buffer ^ mask
+ result.should_not.equal? buffer
+ result.should.internal?
+ result.size.should == buffer.size
+ result.free
+ buffer.get_string.should == "12345".b
+ end
+ end
+ end
+end
+
+describe "IO::Buffer#xor!" do
+ it_behaves_like :io_buffer_xor, :xor!
+
+ it "modifies the buffer in place" do
+ IO::Buffer.for(+"12345") do |buffer|
+ IO::Buffer.for(+"\xF8\x8F") do |mask|
+ result = buffer.xor!(mask)
+ result.should.equal? buffer
+ result.should.external?
+ end
+ end
+ end
+end
diff --git a/spec/ruby/core/io/bytes_spec.rb b/spec/ruby/core/io/bytes_spec.rb
deleted file mode 100644
index 3eb51883c4..0000000000
--- a/spec/ruby/core/io/bytes_spec.rb
+++ /dev/null
@@ -1,43 +0,0 @@
-# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-
-describe "IO#bytes" do
- before :each do
- @io = IOSpecs.io_fixture "lines.txt"
- end
-
- after :each do
- @io.close unless @io.closed?
- end
-
- it "returns an enumerator of the next bytes from the stream" do
- enum = @io.bytes
- enum.should be_an_instance_of(Enumerator)
- @io.readline.should == "Voici la ligne une.\n"
- enum.first(5).should == [81, 117, 105, 32, 195]
- end
-
- it "yields each byte" do
- count = 0
- ScratchPad.record []
- @io.each_byte do |byte|
- ScratchPad << byte
- break if 4 < count += 1
- end
-
- ScratchPad.recorded.should == [86, 111, 105, 99, 105]
- end
-
- it "raises an IOError on closed stream" do
- enum = IOSpecs.closed_io.bytes
- lambda { enum.first }.should raise_error(IOError)
- end
-
- it "raises an IOError on an enumerator for a stream that has been closed" do
- enum = @io.bytes
- enum.first.should == 86
- @io.close
- lambda { enum.first }.should raise_error(IOError)
- end
-end
diff --git a/spec/ruby/core/io/chars_spec.rb b/spec/ruby/core/io/chars_spec.rb
deleted file mode 100644
index e38160274f..0000000000
--- a/spec/ruby/core/io/chars_spec.rb
+++ /dev/null
@@ -1,12 +0,0 @@
-# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/chars', __FILE__)
-
-describe "IO#chars" do
- it_behaves_like :io_chars, :chars
-end
-
-describe "IO#chars" do
- it_behaves_like :io_chars_empty, :chars
-end
diff --git a/spec/ruby/core/io/close_on_exec_spec.rb b/spec/ruby/core/io/close_on_exec_spec.rb
index 057a9a1c20..28cdb967b9 100644
--- a/spec/ruby/core/io/close_on_exec_spec.rb
+++ b/spec/ruby/core/io/close_on_exec_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "IO#close_on_exec=" do
before :each do
@@ -11,37 +11,27 @@ describe "IO#close_on_exec=" do
rm_r @name
end
- guard -> { platform_is :windows and ruby_version_is ""..."2.3" } do
- it "returns false from #respond_to?" do
- @io.respond_to?(:close_on_exec=).should be_false
- end
-
- it "raises a NotImplementedError when called" do
- lambda { @io.close_on_exec = true }.should raise_error(NotImplementedError)
- end
- end
-
- guard -> { platform_is_not :windows or ruby_version_is "2.3" } do
+ guard -> { platform_is_not :windows } do
it "sets the close-on-exec flag if true" do
@io.close_on_exec = true
- @io.close_on_exec?.should == true
+ @io.should.close_on_exec?
end
it "sets the close-on-exec flag if non-false" do
@io.close_on_exec = :true
- @io.close_on_exec?.should == true
+ @io.should.close_on_exec?
end
it "unsets the close-on-exec flag if false" do
@io.close_on_exec = true
@io.close_on_exec = false
- @io.close_on_exec?.should == false
+ @io.should_not.close_on_exec?
end
it "unsets the close-on-exec flag if nil" do
@io.close_on_exec = true
@io.close_on_exec = nil
- @io.close_on_exec?.should == false
+ @io.should_not.close_on_exec?
end
it "ensures the IO's file descriptor is closed in exec'ed processes" do
@@ -52,11 +42,7 @@ describe "IO#close_on_exec=" do
it "raises IOError if called on a closed IO" do
@io.close
- lambda { @io.close_on_exec = true }.should raise_error(IOError)
- end
-
- it "returns nil" do
- @io.send(:close_on_exec=, true).should be_nil
+ -> { @io.close_on_exec = true }.should.raise(IOError)
end
end
end
@@ -72,29 +58,19 @@ describe "IO#close_on_exec?" do
rm_r @name
end
- guard -> { platform_is :windows and ruby_version_is ""..."2.3" } do
- it "returns false from #respond_to?" do
- @io.respond_to?(:close_on_exec?).should be_false
- end
-
- it "raises a NotImplementedError when called" do
- lambda { @io.close_on_exec? }.should raise_error(NotImplementedError)
- end
- end
-
- guard -> { platform_is_not :windows or ruby_version_is "2.3" } do
+ guard -> { platform_is_not :windows } do
it "returns true by default" do
- @io.close_on_exec?.should == true
+ @io.should.close_on_exec?
end
it "returns true if set" do
@io.close_on_exec = true
- @io.close_on_exec?.should == true
+ @io.should.close_on_exec?
end
it "raises IOError if called on a closed IO" do
@io.close
- lambda { @io.close_on_exec? }.should raise_error(IOError)
+ -> { @io.close_on_exec? }.should.raise(IOError)
end
end
end
diff --git a/spec/ruby/core/io/close_read_spec.rb b/spec/ruby/core/io/close_read_spec.rb
index b5aba57795..c505289d72 100644
--- a/spec/ruby/core/io/close_read_spec.rb
+++ b/spec/ruby/core/io/close_read_spec.rb
@@ -1,10 +1,11 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "IO#close_read" do
before :each do
- @io = IO.popen 'cat', "r+"
+ cmd = platform_is(:windows) ? 'rem' : 'cat'
+ @io = IO.popen cmd, "r+"
@path = tmp('io.close.txt')
end
@@ -16,36 +17,26 @@ describe "IO#close_read" do
it "closes the read end of a duplex I/O stream" do
@io.close_read
- lambda { @io.read }.should raise_error(IOError)
+ -> { @io.read }.should.raise(IOError)
end
- ruby_version_is ''...'2.3' do
- it "raises an IOError on subsequent invocations" do
- @io.close_read
-
- lambda { @io.close_read }.should raise_error(IOError)
- end
- end
-
- ruby_version_is '2.3' do
- it "does nothing on subsequent invocations" do
- @io.close_read
+ it "does nothing on subsequent invocations" do
+ @io.close_read
- @io.close_read.should be_nil
- end
+ @io.close_read.should == nil
end
it "allows subsequent invocation of close" do
@io.close_read
- lambda { @io.close }.should_not raise_error
+ -> { @io.close }.should_not.raise
end
it "raises an IOError if the stream is writable and not duplexed" do
io = File.open @path, 'w'
begin
- lambda { io.close_read }.should raise_error(IOError)
+ -> { io.close_read }.should.raise(IOError)
ensure
io.close unless io.closed?
end
@@ -59,22 +50,12 @@ describe "IO#close_read" do
io.close_read
- io.closed?.should == true
+ io.should.closed?
end
- ruby_version_is ''...'2.3' do
- it "raises IOError on closed stream" do
- @io.close
+ it "does nothing on closed stream" do
+ @io.close
- lambda { @io.close_read }.should raise_error(IOError)
- end
- end
-
- ruby_version_is '2.3' do
- it "does nothing on closed stream" do
- @io.close
-
- @io.close_read.should be_nil
- end
+ @io.close_read.should == nil
end
end
diff --git a/spec/ruby/core/io/close_spec.rb b/spec/ruby/core/io/close_spec.rb
index 0e51ec23d2..afd84ba101 100644
--- a/spec/ruby/core/io/close_spec.rb
+++ b/spec/ruby/core/io/close_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "IO#close" do
before :each do
@@ -14,7 +14,7 @@ describe "IO#close" do
it "closes the stream" do
@io.close
- @io.closed?.should == true
+ @io.should.closed?
end
it "returns nil" do
@@ -23,27 +23,64 @@ describe "IO#close" do
it "raises an IOError reading from a closed IO" do
@io.close
- lambda { @io.read }.should raise_error(IOError)
+ -> { @io.read }.should.raise(IOError)
end
it "raises an IOError writing to a closed IO" do
@io.close
- lambda { @io.write "data" }.should raise_error(IOError)
+ -> { @io.write "data" }.should.raise(IOError)
end
- ruby_version_is ''...'2.3' do
- it "raises an IOError if closed" do
- @io.close
- lambda { @io.close }.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
+ -> { @io.write "data" }.should_not.raise(IOError)
end
- ruby_version_is "2.3" do
- it "does nothing if already closed" do
- @io.close
+ it "does nothing if already closed" do
+ @io.close
+
+ @io.close.should == nil
+ end
- @io.close.should be_nil
- end
+ it "does not call the #flush method but flushes the stream internally" do
+ @io.should_not_receive(:flush)
+ @io.close
+ @io.should.closed?
+ end
+
+ it 'raises an IOError with a clear message' do
+ matching_exception = nil
+
+ -> do
+ IOSpecs::THREAD_CLOSE_RETRIES.times do
+ read_io, write_io = IO.pipe
+ going_to_read = false
+
+ thread = Thread.new do
+ begin
+ going_to_read = true
+ read_io.read
+ rescue IOError => ioe
+ if ioe.message == IOSpecs::THREAD_CLOSE_ERROR_MESSAGE
+ matching_exception = ioe
+ end
+ # try again
+ end
+ end
+
+ # best attempt to ensure the thread is actually blocked on read
+ Thread.pass until going_to_read && thread.stop?
+ sleep(0.001)
+
+ read_io.close
+ thread.join
+ write_io.close
+
+ matching_exception&.tap {|ex| raise ex}
+ end
+ end.should.raise(IOError, IOSpecs::THREAD_CLOSE_ERROR_MESSAGE)
end
end
@@ -56,7 +93,7 @@ describe "IO#close on an IO.popen stream" do
io.close
- lambda { io.pid }.should raise_error(IOError)
+ -> { io.pid }.should.raise(IOError)
end
it "sets $?" do
@@ -79,4 +116,3 @@ describe "IO#close on an IO.popen stream" do
end
end
-
diff --git a/spec/ruby/core/io/close_write_spec.rb b/spec/ruby/core/io/close_write_spec.rb
index c901aac499..60b41505c3 100644
--- a/spec/ruby/core/io/close_write_spec.rb
+++ b/spec/ruby/core/io/close_write_spec.rb
@@ -1,9 +1,10 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "IO#close_write" do
before :each do
- @io = IO.popen 'cat', 'r+'
+ cmd = platform_is(:windows) ? 'rem' : 'cat'
+ @io = IO.popen cmd, 'r+'
@path = tmp('io.close.txt')
end
@@ -15,36 +16,26 @@ describe "IO#close_write" do
it "closes the write end of a duplex I/O stream" do
@io.close_write
- lambda { @io.write "attempt to write" }.should raise_error(IOError)
+ -> { @io.write "attempt to write" }.should.raise(IOError)
end
- ruby_version_is ''...'2.3' do
- it "raises an IOError on subsequent invocations" do
- @io.close_write
-
- lambda { @io.close_write }.should raise_error(IOError)
- end
- end
-
- ruby_version_is '2.3' do
- it "does nothing on subsequent invocations" do
- @io.close_write
+ it "does nothing on subsequent invocations" do
+ @io.close_write
- @io.close_write.should be_nil
- end
+ @io.close_write.should == nil
end
it "allows subsequent invocation of close" do
@io.close_write
- lambda { @io.close }.should_not raise_error
+ -> { @io.close }.should_not.raise
end
it "raises an IOError if the stream is readable and not duplexed" do
io = File.open @path, 'w+'
begin
- lambda { io.close_write }.should raise_error(IOError)
+ -> { io.close_write }.should.raise(IOError)
ensure
io.close unless io.closed?
end
@@ -55,30 +46,23 @@ describe "IO#close_write" do
io.close_write
- io.closed?.should == true
+ io.should.closed?
end
- it "flushes and closes the write stream" do
- @io.puts '12345'
-
- @io.close_write
+ # Windows didn't have command like cat
+ platform_is_not :windows do
+ it "flushes and closes the write stream" do
+ @io.puts '12345'
- @io.read.should == "12345\n"
- end
-
- ruby_version_is ''...'2.3' do
- it "raises IOError on closed stream" do
- @io.close
+ @io.close_write
- lambda { @io.close_write }.should raise_error(IOError)
+ @io.read.should == "12345\n"
end
end
- ruby_version_is '2.3' do
- it "does nothing on closed stream" do
- @io.close
+ it "does nothing on closed stream" do
+ @io.close
- @io.close_write.should be_nil
- end
+ @io.close_write.should == nil
end
end
diff --git a/spec/ruby/core/io/closed_spec.rb b/spec/ruby/core/io/closed_spec.rb
index 80562885a7..1f10858e28 100644
--- a/spec/ruby/core/io/closed_spec.rb
+++ b/spec/ruby/core/io/closed_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "IO#closed?" do
before :each do
@@ -11,10 +11,10 @@ describe "IO#closed?" do
end
it "returns true on closed stream" do
- IOSpecs.closed_io.closed?.should be_true
+ IOSpecs.closed_io.closed?.should == true
end
it "returns false on open stream" do
- @io.closed?.should be_false
+ @io.closed?.should == false
end
end
diff --git a/spec/ruby/core/io/codepoints_spec.rb b/spec/ruby/core/io/codepoints_spec.rb
deleted file mode 100644
index 6e6b9613b5..0000000000
--- a/spec/ruby/core/io/codepoints_spec.rb
+++ /dev/null
@@ -1,25 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/codepoints', __FILE__)
-
-# See redmine #1667
-describe "IO#codepoints" do
- it_behaves_like(:io_codepoints, :codepoints)
-end
-
-describe "IO#codepoints" do
- before :each do
- @io = IOSpecs.io_fixture "lines.txt"
- end
-
- after :each do
- @io.close unless @io.closed?
- end
-
- it "calls the given block" do
- r = []
- @io.codepoints { |c| r << c }
- r[24].should == 232
- r.last.should == 10
- end
-end
diff --git a/spec/ruby/core/io/constants_spec.rb b/spec/ruby/core/io/constants_spec.rb
index 0a2ea70560..f9dccd08b9 100644
--- a/spec/ruby/core/io/constants_spec.rb
+++ b/spec/ruby/core/io/constants_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "IO::SEEK_SET" do
it "is defined" do
diff --git a/spec/ruby/core/io/copy_stream_spec.rb b/spec/ruby/core/io/copy_stream_spec.rb
index 344746fac3..31383f9b0f 100644
--- a/spec/ruby/core/io/copy_stream_spec.rb
+++ b/spec/ruby/core/io/copy_stream_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe :io_copy_stream_to_file, shared: true do
it "copies the entire IO contents to the file" do
@@ -31,7 +31,7 @@ describe :io_copy_stream_to_file, shared: true do
obj = mock("io_copy_stream_to")
obj.should_receive(:to_path).and_return(1)
- lambda { IO.copy_stream(@object.from, obj) }.should raise_error(TypeError)
+ -> { IO.copy_stream(@object.from, obj) }.should.raise(TypeError)
end
end
@@ -69,14 +69,17 @@ describe :io_copy_stream_to_io, shared: true do
end
it "raises an IOError if the destination IO is not open for writing" do
- @to_io.close
- @to_io = new_io @to_name, "r"
- lambda { IO.copy_stream @object.from, @to_io }.should raise_error(IOError)
+ to_io = new_io __FILE__, "r"
+ begin
+ -> { IO.copy_stream @object.from, to_io }.should.raise(IOError)
+ ensure
+ to_io.close
+ end
end
it "does not close the destination IO" do
IO.copy_stream(@object.from, @to_io)
- @to_io.closed?.should be_false
+ @to_io.closed?.should == false
end
it "copies only length bytes when specified" do
@@ -109,7 +112,8 @@ describe "IO.copy_stream" do
end
after :each do
- rm_r @to_name, @from_bigfile
+ rm_r @to_name if @to_name
+ rm_r @from_bigfile
end
describe "from an IO" do
@@ -125,12 +129,12 @@ describe "IO.copy_stream" do
it "raises an IOError if the source IO is not open for reading" do
@from_io.close
@from_io = new_io @from_bigfile, "a"
- lambda { IO.copy_stream @from_io, @to_name }.should raise_error(IOError)
+ -> { IO.copy_stream @from_io, @to_name }.should.raise(IOError)
end
it "does not close the source IO" do
IO.copy_stream(@from_io, @to_name)
- @from_io.closed?.should be_false
+ @from_io.closed?.should == false
end
platform_is_not :windows do
@@ -164,6 +168,25 @@ describe "IO.copy_stream" do
it_behaves_like :io_copy_stream_to_io, nil, IOSpecs::CopyStream
it_behaves_like :io_copy_stream_to_io_with_offset, nil, IOSpecs::CopyStream
end
+
+ describe "to a Tempfile" do
+ before :all do
+ require 'tempfile'
+ end
+
+ before :each do
+ @to_io = Tempfile.new("rubyspec_copy_stream", encoding: Encoding::BINARY, mode: File::RDONLY)
+ @to_name = @to_io.path
+ end
+
+ after :each do
+ @to_io.close!
+ @to_name = nil # do not rm_r it, already done by Tempfile#close!
+ end
+
+ it_behaves_like :io_copy_stream_to_io, nil, IOSpecs::CopyStream
+ it_behaves_like :io_copy_stream_to_io_with_offset, nil, IOSpecs::CopyStream
+ end
end
describe "from a file name" do
@@ -183,7 +206,7 @@ describe "IO.copy_stream" do
obj = mock("io_copy_stream_from")
obj.should_receive(:to_path).and_return(1)
- lambda { IO.copy_stream(obj, @to_name) }.should raise_error(TypeError)
+ -> { IO.copy_stream(obj, @to_name) }.should.raise(TypeError)
end
describe "to a file name" do
@@ -217,12 +240,12 @@ describe "IO.copy_stream" do
it "does not close the source IO" do
IO.copy_stream(@from_io, @to_name)
- @from_io.closed?.should be_false
+ @from_io.closed?.should == false
end
platform_is_not :windows do
it "raises an error when an offset is specified" do
- lambda { IO.copy_stream(@from_io, @to_name, 8, 4) }.should raise_error(Errno::ESPIPE)
+ -> { IO.copy_stream(@from_io, @to_name, 8, 4) }.should.raise(Errno::ESPIPE)
end
end
@@ -278,5 +301,51 @@ describe "IO.copy_stream" do
IO.copy_stream(@io, @to_name)
end
+ it "does not call #read on the source or #write on the destination if zero length is given" do
+ from = mock("io_copy_stream_to_object_zero_length_read")
+ to = mock("io_copy_stream_to_object_zero_length_write")
+ from.should_not_receive(:read)
+ to.should_not_receive(:write)
+ IO.copy_stream(from, to, 0)
+ end
+ end
+
+ describe "with a destination that does partial reads" do
+ before do
+ @from_out, @from_in = IO.pipe
+ @to_out, @to_in = IO.pipe
+ end
+
+ after do
+ [@from_out, @from_in, @to_out, @to_in].each {|io| io.close rescue nil}
+ end
+
+ it "calls #write repeatedly on the destination Object" do
+ @from_in.write "1234"
+ @from_in.close
+
+ th = Thread.new do
+ IO.copy_stream(@from_out, @to_in)
+ end
+
+ copied = ""
+ 4.times do
+ copied += @to_out.read(1)
+ end
+
+ th.join
+
+ copied.should == "1234"
+ end
+
+ end
+end
+
+describe "IO.copy_stream" do
+ it "does not use buffering when writing to STDOUT" do
+ IO.popen([*ruby_exe, fixture(__FILE__ , "copy_in_out.rb")], "r+") do |io|
+ io.write("bar")
+ io.read(3).should == "bar"
+ end
end
end
diff --git a/spec/ruby/core/io/dup_spec.rb b/spec/ruby/core/io/dup_spec.rb
index a90b04aa5d..db4e9fe641 100644
--- a/spec/ruby/core/io/dup_spec.rb
+++ b/spec/ruby/core/io/dup_spec.rb
@@ -1,9 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "IO#dup" do
before :each do
- @file = tmp("rubinius_spec_io_dup_#{$$}_#{Time.now.to_f}")
+ @file = tmp("spec_io_dup")
@f = File.open @file, 'w+'
@i = @f.dup
@@ -25,45 +25,82 @@ describe "IO#dup" do
@i.fileno.should_not == @f.fileno
end
-quarantine! do # This does not appear to be consistent across platforms
- it "shares the original stream between the two IOs" do
- start = @f.pos
- @i.pos.should == start
+ quarantine! do # This does not appear to be consistent across platforms
+ it "shares the original stream between the two IOs" do
+ start = @f.pos
+ @i.pos.should == start
- s = "Hello, wo.. wait, where am I?\n"
- s2 = "<evil voice> Muhahahaa!"
+ s = "Hello, wo.. wait, where am I?\n"
+ s2 = "<evil voice> Muhahahaa!"
- @f.write s
- @i.pos.should == @f.pos
+ @f.write s
+ @i.pos.should == @f.pos
- @i.rewind
- @i.gets.should == s
+ @i.rewind
+ @i.gets.should == s
- @i.rewind
- @i.write s2
+ @i.rewind
+ @i.write s2
- @f.rewind
- @f.gets.should == "#{s2}\n"
+ @f.rewind
+ @f.gets.should == "#{s2}\n"
+ end
end
-end
it "allows closing the new IO without affecting the original" do
@i.close
- lambda { @f.gets }.should_not raise_error(Exception)
+ -> { @f.gets }.should_not.raise(Exception)
- @i.closed?.should == true
- @f.closed?.should == false
+ @i.should.closed?
+ @f.should_not.closed?
end
it "allows closing the original IO without affecting the new one" do
@f.close
- lambda { @i.gets }.should_not raise_error(Exception)
+ -> { @i.gets }.should_not.raise(Exception)
- @i.closed?.should == false
- @f.closed?.should == true
+ @i.should_not.closed?
+ @f.should.closed?
end
it "raises IOError on closed stream" do
- lambda { IOSpecs.closed_io.dup }.should raise_error(IOError)
+ -> { IOSpecs.closed_io.dup }.should.raise(IOError)
+ end
+
+ it "always sets the close-on-exec flag for the new IO object" do
+ @f.close_on_exec = true
+ dup = @f.dup
+ begin
+ dup.should.close_on_exec?
+ ensure
+ dup.close
+ end
+
+ @f.close_on_exec = false
+ dup = @f.dup
+ begin
+ dup.should.close_on_exec?
+ ensure
+ dup.close
+ end
+ end
+
+ it "always sets the autoclose flag for the new IO object" do
+ @f.autoclose = true
+ dup = @f.dup
+ begin
+ dup.should.autoclose?
+ ensure
+ dup.close
+ end
+
+ @f.autoclose = false
+ dup = @f.dup
+ begin
+ dup.should.autoclose?
+ ensure
+ dup.close
+ @f.autoclose = true
+ end
end
end
diff --git a/spec/ruby/core/io/each_byte_spec.rb b/spec/ruby/core/io/each_byte_spec.rb
index 0dc535a159..fe299f0fba 100644
--- a/spec/ruby/core/io/each_byte_spec.rb
+++ b/spec/ruby/core/io/each_byte_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "IO#each_byte" do
before :each do
@@ -12,7 +12,7 @@ describe "IO#each_byte" do
end
it "raises IOError on closed stream" do
- lambda { IOSpecs.closed_io.each_byte {} }.should raise_error(IOError)
+ -> { IOSpecs.closed_io.each_byte {} }.should.raise(IOError)
end
it "yields each byte" do
@@ -28,7 +28,7 @@ describe "IO#each_byte" do
describe "when no block is given" do
it "returns an Enumerator" do
enum = @io.each_byte
- enum.should be_an_instance_of(Enumerator)
+ enum.should.instance_of?(Enumerator)
enum.first(5).should == [86, 111, 105, 99, 105]
end
@@ -52,6 +52,6 @@ describe "IO#each_byte" do
end
it "returns self on an empty stream" do
- @io.each_byte { |b| }.should equal(@io)
+ @io.each_byte { |b| }.should.equal?(@io)
end
end
diff --git a/spec/ruby/core/io/each_char_spec.rb b/spec/ruby/core/io/each_char_spec.rb
index 69c6739920..7c1ca4f069 100644
--- a/spec/ruby/core/io/each_char_spec.rb
+++ b/spec/ruby/core/io/each_char_spec.rb
@@ -1,12 +1,75 @@
-# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/chars', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "IO#each_char" do
- it_behaves_like :io_chars, :each_char
+ before :each do
+ @io = IOSpecs.io_fixture "lines.txt"
+ ScratchPad.record []
+ end
+
+ after :each do
+ @io.close unless @io.closed?
+ end
+
+ it "yields each character" do
+ @io.readline.should == "Voici la ligne une.\n"
+
+ count = 0
+ @io.each_char do |c|
+ ScratchPad << c
+ break if 4 < count += 1
+ end
+
+ ScratchPad.recorded.should == ["Q", "u", "i", " ", "è"]
+ end
+
+ describe "when no block is given" do
+ it "returns an Enumerator" do
+ enum = @io.each_char
+ enum.should.instance_of?(Enumerator)
+ enum.first(5).should == ["V", "o", "i", "c", "i"]
+ end
+
+ describe "returned Enumerator" do
+ describe "size" do
+ it "should return nil" do
+ @io.each_char.size.should == nil
+ end
+ end
+ end
+ end
+
+ it "returns itself" do
+ @io.each_char { |c| }.should.equal?(@io)
+ end
+
+ it "returns an enumerator for a closed stream" do
+ IOSpecs.closed_io.each_char.should.instance_of?(Enumerator)
+ end
+
+ it "raises an IOError when an enumerator created on a closed stream is accessed" do
+ -> { IOSpecs.closed_io.each_char.first }.should.raise(IOError)
+ end
+
+ it "raises IOError on closed stream" do
+ -> { IOSpecs.closed_io.each_char {} }.should.raise(IOError)
+ end
end
describe "IO#each_char" do
- it_behaves_like :io_chars_empty, :each_char
+ before :each do
+ @name = tmp("io_each_char")
+ @io = new_io @name, "w+:utf-8"
+ ScratchPad.record []
+ end
+
+ after :each do
+ @io.close unless @io.closed?
+ rm_r @name
+ end
+
+ it "does not yield any characters on an empty stream" do
+ @io.each_char { |c| ScratchPad << c }
+ ScratchPad.recorded.should == []
+ end
end
diff --git a/spec/ruby/core/io/each_codepoint_spec.rb b/spec/ruby/core/io/each_codepoint_spec.rb
index eb16e004fa..758a524986 100644
--- a/spec/ruby/core/io/each_codepoint_spec.rb
+++ b/spec/ruby/core/io/each_codepoint_spec.rb
@@ -1,10 +1,57 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/codepoints', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
# See redmine #1667
describe "IO#each_codepoint" do
- it_behaves_like(:io_codepoints, :codepoints)
+ before :each do
+ @io = IOSpecs.io_fixture "lines.txt"
+ @enum = @io.each_codepoint
+ end
+
+ after :each do
+ @io.close
+ end
+
+ describe "when no block is given" do
+ it "returns an Enumerator" do
+ @enum.should.instance_of?(Enumerator)
+ end
+
+ describe "returned Enumerator" do
+ describe "size" do
+ it "should return nil" do
+ @enum.size.should == nil
+ end
+ end
+ end
+ end
+
+ it "yields each codepoint" do
+ @enum.first(25).should == [
+ 86, 111, 105, 99, 105, 32, 108, 97, 32, 108, 105, 103, 110,
+ 101, 32, 117, 110, 101, 46, 10, 81, 117, 105, 32, 232
+ ]
+ end
+
+ it "yields each codepoint starting from the current position" do
+ @io.pos = 130
+ @enum.to_a.should == [101, 32, 115, 105, 120, 46, 10]
+ end
+
+ it "raises an error if reading invalid sequence" do
+ @io.pos = 60 # inside of a multibyte sequence
+ -> { @enum.first }.should.raise(ArgumentError)
+ end
+
+ it "does not change $_" do
+ $_ = "test"
+ @enum.to_a
+ $_.should == "test"
+ end
+
+ it "raises an IOError when self is not readable" do
+ -> { IOSpecs.closed_io.each_codepoint.to_a }.should.raise(IOError)
+ end
end
describe "IO#each_codepoint" do
@@ -24,7 +71,7 @@ describe "IO#each_codepoint" do
end
it "returns self" do
- @io.each_codepoint { |l| l }.should equal(@io)
+ @io.each_codepoint { |l| l }.should.equal?(@io)
end
end
@@ -37,9 +84,7 @@ describe "IO#each_codepoint" do
@io.close if @io
end
- ruby_version_is "2.3" do # earlier versions stay blocked
- it "raises an exception at incomplete character before EOF when conversion takes place" do
- lambda { @io.each_codepoint {} }.should raise_error(ArgumentError)
- end
+ it "raises an exception at incomplete character before EOF when conversion takes place" do
+ -> { @io.each_codepoint {} }.should.raise(ArgumentError)
end
end
diff --git a/spec/ruby/core/io/each_line_spec.rb b/spec/ruby/core/io/each_line_spec.rb
index d4d8af7902..bcda4040b8 100644
--- a/spec/ruby/core/io/each_line_spec.rb
+++ b/spec/ruby/core/io/each_line_spec.rb
@@ -1,11 +1,251 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/each', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "IO#each_line" do
- it_behaves_like :io_each, :each_line
+ before :each do
+ @io = IOSpecs.io_fixture "lines.txt"
+ ScratchPad.record []
+ end
+
+ after :each do
+ @io.close if @io
+ end
+
+ describe "with no separator" do
+ it "yields each line to the passed block" do
+ @io.each_line { |s| ScratchPad << s }
+ ScratchPad.recorded.should == IOSpecs.lines
+ end
+
+ it "yields each line starting from the current position" do
+ @io.pos = 41
+ @io.each_line { |s| ScratchPad << s }
+ ScratchPad.recorded.should == IOSpecs.lines[2..-1]
+ end
+
+ it "returns self" do
+ @io.each_line { |l| l }.should.equal?(@io)
+ end
+
+ it "does not change $_" do
+ $_ = "test"
+ @io.each_line { |s| s }
+ $_.should == "test"
+ end
+
+ it "raises an IOError when self is not readable" do
+ -> { IOSpecs.closed_io.each_line {} }.should.raise(IOError)
+ end
+
+ it "makes line count accessible via lineno" do
+ @io.each_line { ScratchPad << @io.lineno }
+ ScratchPad.recorded.should == [ 1,2,3,4,5,6,7,8,9 ]
+ end
+
+ it "makes line count accessible via $." do
+ @io.each_line { ScratchPad << $. }
+ ScratchPad.recorded.should == [ 1,2,3,4,5,6,7,8,9 ]
+ end
+
+ describe "when no block is given" do
+ it "returns an Enumerator" do
+ enum = @io.each_line
+ enum.should.instance_of?(Enumerator)
+
+ enum.each { |l| ScratchPad << l }
+ ScratchPad.recorded.should == IOSpecs.lines
+ end
+
+ describe "returned Enumerator" do
+ describe "size" do
+ it "should return nil" do
+ @io.each_line.size.should == nil
+ end
+ end
+ end
+ end
+ end
+
+ describe "with limit" do
+ describe "when limit is 0" do
+ it "raises an ArgumentError" do
+ # must pass block so Enumerator is evaluated and raises
+ -> { @io.each_line(0){} }.should.raise(ArgumentError)
+ end
+ end
+
+ it "does not accept Integers that don't fit in a C off_t" do
+ -> { @io.each_line(2**128){} }.should.raise(RangeError)
+ end
+ end
+
+ describe "when passed a String containing one space as a separator" do
+ it "uses the passed argument as the line separator" do
+ @io.each_line(" ") { |s| ScratchPad << s }
+ ScratchPad.recorded.should == IOSpecs.lines_space_separator
+ end
+
+ it "does not change $_" do
+ $_ = "test"
+ @io.each_line(" ") { |s| }
+ $_.should == "test"
+ end
+
+ it "tries to convert the passed separator to a String using #to_str" do
+ obj = mock("to_str")
+ obj.stub!(:to_str).and_return(" ")
+
+ @io.each_line(obj) { |l| ScratchPad << l }
+ ScratchPad.recorded.should == IOSpecs.lines_space_separator
+ end
+ end
+
+ describe "when passed nil as a separator" do
+ it "yields self's content starting from the current position when the passed separator is nil" do
+ @io.pos = 100
+ @io.each_line(nil) { |s| ScratchPad << s }
+ ScratchPad.recorded.should == ["qui a linha cinco.\nHere is line six.\n"]
+ end
+ end
+
+ describe "when passed an empty String as a separator" do
+ it "yields each paragraph" do
+ @io.each_line("") { |s| ScratchPad << s }
+ ScratchPad.recorded.should == IOSpecs.paragraphs
+ end
+
+ it "discards leading newlines" do
+ @io.readline
+ @io.readline
+ @io.each_line("") { |s| ScratchPad << s }
+ ScratchPad.recorded.should == IOSpecs.paragraphs[1..-1]
+ end
+ end
+
+ describe "with both separator and limit" do
+ describe "when no block is given" do
+ it "returns an Enumerator" do
+ enum = @io.each_line(nil, 1024)
+ enum.should.instance_of?(Enumerator)
+
+ enum.each { |l| ScratchPad << l }
+ ScratchPad.recorded.should == [IOSpecs.lines.join]
+ end
+
+ describe "returned Enumerator" do
+ describe "size" do
+ it "should return nil" do
+ @io.each_line(nil, 1024).size.should == nil
+ end
+ end
+ end
+ end
+
+ describe "when a block is given" do
+ it "accepts an empty block" do
+ @io.each_line(nil, 1024) {}.should.equal?(@io)
+ end
+
+ describe "when passed nil as a separator" do
+ it "yields self's content starting from the current position when the passed separator is nil" do
+ @io.pos = 100
+ @io.each_line(nil, 1024) { |s| ScratchPad << s }
+ ScratchPad.recorded.should == ["qui a linha cinco.\nHere is line six.\n"]
+ end
+ end
+
+ describe "when passed an empty String as a separator" do
+ it "yields each paragraph" do
+ @io.each_line("", 1024) { |s| ScratchPad << s }
+ ScratchPad.recorded.should == IOSpecs.paragraphs
+ end
+
+ it "discards leading newlines" do
+ @io.readline
+ @io.readline
+ @io.each_line("", 1024) { |s| ScratchPad << s }
+ ScratchPad.recorded.should == IOSpecs.paragraphs[1..-1]
+ end
+ end
+ end
+ end
+
+ describe "when passed chomp" do
+ it "yields each line without trailing newline characters to the passed block" do
+ @io.each_line(chomp: true) { |s| ScratchPad << s }
+ ScratchPad.recorded.should == IOSpecs.lines_without_newline_characters
+ end
+
+ it "raises exception when options passed as Hash" do
+ -> {
+ @io.each_line({ chomp: true }) { |s| }
+ }.should.raise(TypeError)
+
+ -> {
+ @io.each_line("\n", 1, { chomp: true }) { |s| }
+ }.should.raise(ArgumentError, "wrong number of arguments (given 3, expected 0..2)")
+ end
+ end
+
+ describe "when passed chomp and a separator" do
+ it "yields each line without separator to the passed block" do
+ @io.each_line(" ", chomp: true) { |s| ScratchPad << s }
+ ScratchPad.recorded.should == IOSpecs.lines_space_separator_without_trailing_spaces
+ end
+ end
+
+ describe "when passed chomp and empty line as a separator" do
+ it "yields each paragraph without trailing new line characters" do
+ @io.each_line("", 1024, chomp: true) { |s| ScratchPad << s }
+ ScratchPad.recorded.should == IOSpecs.paragraphs_without_trailing_new_line_characters
+ end
+ end
+
+ describe "when passed chomp and nil as a separator" do
+ it "yields self's content" do
+ @io.pos = 100
+ @io.each_line(nil, chomp: true) { |s| ScratchPad << s }
+ ScratchPad.recorded.should == ["qui a linha cinco.\nHere is line six.\n"]
+ end
+ end
+
+ describe "when passed chomp, nil as a separator, and a limit" do
+ it "yields each line of limit size without truncating trailing new line character" do
+ # 43 - is a size of the 1st paragraph in the file
+ @io.each_line(nil, 43, chomp: true) { |s| ScratchPad << s }
+
+ ScratchPad.recorded.should == [
+ "Voici la ligne une.\nQui è la linea due.\n\n\n",
+ "Aquí está la línea tres.\n" + "Hier ist Zeile ",
+ "vier.\n\nEstá aqui a linha cinco.\nHere is li",
+ "ne six.\n"
+ ]
+ end
+ end
+
+ describe "when passed too many arguments" do
+ it "raises ArgumentError" do
+ -> {
+ @io.each_line("", 1, "excess argument", chomp: true) {}
+ }.should.raise(ArgumentError)
+ end
+ end
end
describe "IO#each_line" do
- it_behaves_like :io_each_default_separator, :each_line
+ before :each do
+ @io = IOSpecs.io_fixture "lines.txt"
+ ScratchPad.record []
+ suppress_warning {@sep, $/ = $/, " "}
+ end
+
+ after :each do
+ @io.close if @io
+ suppress_warning {$/ = @sep}
+ end
+
+ it "uses $/ as the default line separator" do
+ @io.each_line { |s| ScratchPad << s }
+ ScratchPad.recorded.should == IOSpecs.lines_space_separator
+ end
end
diff --git a/spec/ruby/core/io/each_spec.rb b/spec/ruby/core/io/each_spec.rb
index 4d6aa50fb2..594052256e 100644
--- a/spec/ruby/core/io/each_spec.rb
+++ b/spec/ruby/core/io/each_spec.rb
@@ -1,11 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/each', __FILE__)
+require_relative '../../spec_helper'
describe "IO#each" do
- it_behaves_like :io_each, :each
-end
-
-describe "IO#each" do
- it_behaves_like :io_each_default_separator, :each
+ it "is an alias of IO#each_line" do
+ IO.instance_method(:each).should == IO.instance_method(:each_line)
+ end
end
diff --git a/spec/ruby/core/io/eof_spec.rb b/spec/ruby/core/io/eof_spec.rb
index a2c5e563f0..561daa4ec3 100644
--- a/spec/ruby/core/io/eof_spec.rb
+++ b/spec/ruby/core/io/eof_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "IO#eof?" do
before :each do
@@ -12,13 +12,13 @@ describe "IO#eof?" do
end
it "returns true on an empty stream that has just been opened" do
- File.open(@name) { |empty| empty.eof?.should == true }
+ File.open(@name) { |empty| empty.should.eof? }
end
it "raises IOError on stream not opened for reading" do
- lambda do
+ -> do
File.open(@name, "w") { |f| f.eof? }
- end.should raise_error(IOError)
+ end.should.raise(IOError)
end
end
@@ -34,51 +34,51 @@ describe "IO#eof?" do
it "returns false when not at end of file" do
@io.read 1
- @io.eof?.should == false
+ @io.should_not.eof?
end
it "returns true after reading with read with no parameters" do
@io.read()
- @io.eof?.should == true
+ @io.should.eof?
end
it "returns true after reading with read" do
@io.read(File.size(@name))
- @io.eof?.should == true
+ @io.should.eof?
end
it "returns true after reading with sysread" do
@io.sysread(File.size(@name))
- @io.eof?.should == true
+ @io.should.eof?
end
it "returns true after reading with readlines" do
@io.readlines
- @io.eof?.should == true
+ @io.should.eof?
end
it "returns false on just opened non-empty stream" do
- @io.eof?.should == false
+ @io.should_not.eof?
end
it "does not consume the data from the stream" do
- @io.eof?.should == false
+ @io.should_not.eof?
@io.getc.should == 'V'
end
it "raises IOError on closed stream" do
- lambda { IOSpecs.closed_io.eof? }.should raise_error(IOError)
+ -> { IOSpecs.closed_io.eof? }.should.raise(IOError)
end
it "raises IOError on stream closed for reading by close_read" do
@io.close_read
- lambda { @io.eof? }.should raise_error(IOError)
+ -> { @io.eof? }.should.raise(IOError)
end
it "returns true on one-byte stream after single-byte read" do
- File.open(File.dirname(__FILE__) + '/fixtures/one_byte.txt') { |one_byte|
+ File.open(__dir__ + '/fixtures/one_byte.txt') { |one_byte|
one_byte.read(1)
- one_byte.eof?.should == true
+ one_byte.should.eof?
}
end
end
@@ -92,16 +92,22 @@ describe "IO#eof?" do
it "returns true on receiving side of Pipe when writing side is closed" do
@r, @w = IO.pipe
@w.close
- @r.eof?.should == true
+ @r.should.eof?
end
it "returns false on receiving side of Pipe when writing side wrote some data" do
@r, @w = IO.pipe
@w.puts "hello"
- @r.eof?.should == false
+ @r.should_not.eof?
@w.close
- @r.eof?.should == false
+ @r.should_not.eof?
@r.read
- @r.eof?.should == true
+ @r.should.eof?
+ end
+end
+
+describe "IO#eof" do
+ it "is an alias of IO#eof?" do
+ IO.instance_method(:eof).should == IO.instance_method(:eof?)
end
end
diff --git a/spec/ruby/core/io/external_encoding_spec.rb b/spec/ruby/core/io/external_encoding_spec.rb
index ec85eba2ee..72d246cc2b 100644
--- a/spec/ruby/core/io/external_encoding_spec.rb
+++ b/spec/ruby/core/io/external_encoding_spec.rb
@@ -1,218 +1,223 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
-with_feature :encoding do
- describe :io_external_encoding_write, shared: true do
+describe :io_external_encoding_write, shared: true do
+ describe "when Encoding.default_internal is nil" do
+ before :each do
+ Encoding.default_internal = nil
+ end
+
+ it "returns nil" do
+ @io = new_io @name, @object
+ Encoding.default_external = Encoding::IBM437
+ @io.external_encoding.should == nil
+ end
+
+ it "returns the external encoding specified when the instance was created" do
+ @io = new_io @name, "#{@object}:ibm866"
+ Encoding.default_external = Encoding::IBM437
+ @io.external_encoding.should.equal?(Encoding::IBM866)
+ end
+
+ it "returns the encoding set by #set_encoding" do
+ @io = new_io @name, "#{@object}:ibm866"
+ @io.set_encoding Encoding::EUC_JP, nil
+ @io.external_encoding.should.equal?(Encoding::EUC_JP)
+ end
+ end
+
+ describe "when Encoding.default_external != Encoding.default_internal" do
+ before :each do
+ Encoding.default_external = Encoding::IBM437
+ Encoding.default_internal = Encoding::IBM866
+ end
+
+ it "returns the value of Encoding.default_external when the instance was created" do
+ @io = new_io @name, @object
+ Encoding.default_external = Encoding::UTF_8
+ @io.external_encoding.should.equal?(Encoding::IBM437)
+ end
+
+ it "returns the external encoding specified when the instance was created" do
+ @io = new_io @name, "#{@object}:ibm866"
+ Encoding.default_external = Encoding::IBM437
+ @io.external_encoding.should.equal?(Encoding::IBM866)
+ end
+
+ it "returns the encoding set by #set_encoding" do
+ @io = new_io @name, "#{@object}:ibm866"
+ @io.set_encoding Encoding::EUC_JP, nil
+ @io.external_encoding.should.equal?(Encoding::EUC_JP)
+ end
+ end
+
+ describe "when Encoding.default_external == Encoding.default_internal" do
+ before :each do
+ Encoding.default_external = Encoding::IBM866
+ Encoding.default_internal = Encoding::IBM866
+ end
+
+ it "returns the value of Encoding.default_external when the instance was created" do
+ @io = new_io @name, @object
+ Encoding.default_external = Encoding::UTF_8
+ @io.external_encoding.should.equal?(Encoding::IBM866)
+ end
+
+ it "returns the external encoding specified when the instance was created" do
+ @io = new_io @name, "#{@object}:ibm866"
+ Encoding.default_external = Encoding::IBM437
+ @io.external_encoding.should.equal?(Encoding::IBM866)
+ end
+
+ it "returns the encoding set by #set_encoding" do
+ @io = new_io @name, "#{@object}:ibm866"
+ @io.set_encoding Encoding::EUC_JP, nil
+ @io.external_encoding.should.equal?(Encoding::EUC_JP)
+ end
+ end
+end
+
+describe "IO#external_encoding" do
+ before :each do
+ @external = Encoding.default_external
+ @internal = Encoding.default_internal
+
+ @name = tmp("io_external_encoding")
+ touch(@name)
+ end
+
+ after :each do
+ Encoding.default_external = @external
+ Encoding.default_internal = @internal
+
+ @io.close if @io
+ rm_r @name
+ end
+
+ it "can be retrieved from a closed stream" do
+ io = IOSpecs.io_fixture("lines.txt", "r")
+ io.close
+ io.external_encoding.should.equal?(Encoding.default_external)
+ end
+
+ describe "with 'r' mode" do
describe "when Encoding.default_internal is nil" do
before :each do
Encoding.default_internal = nil
+ Encoding.default_external = Encoding::IBM866
end
- it "returns nil" do
- @io = new_io @name, @object
+ it "returns Encoding.default_external if the external encoding is not set" do
+ @io = new_io @name, "r"
+ @io.external_encoding.should.equal?(Encoding::IBM866)
+ end
+
+ it "returns Encoding.default_external when that encoding is changed after the instance is created" do
+ @io = new_io @name, "r"
Encoding.default_external = Encoding::IBM437
- @io.external_encoding.should be_nil
+ @io.external_encoding.should.equal?(Encoding::IBM437)
end
it "returns the external encoding specified when the instance was created" do
- @io = new_io @name, "#{@object}:ibm866"
+ @io = new_io @name, "r:utf-8"
Encoding.default_external = Encoding::IBM437
- @io.external_encoding.should equal(Encoding::IBM866)
+ @io.external_encoding.should.equal?(Encoding::UTF_8)
end
it "returns the encoding set by #set_encoding" do
- @io = new_io @name, "#{@object}:ibm866"
+ @io = new_io @name, "r:utf-8"
@io.set_encoding Encoding::EUC_JP, nil
- @io.external_encoding.should equal(Encoding::EUC_JP)
+ @io.external_encoding.should.equal?(Encoding::EUC_JP)
end
end
- describe "when Encoding.default_external != Encoding.default_internal" do
+ describe "when Encoding.default_external == Encoding.default_internal" do
before :each do
- Encoding.default_external = Encoding::IBM437
+ Encoding.default_external = Encoding::IBM866
Encoding.default_internal = Encoding::IBM866
end
it "returns the value of Encoding.default_external when the instance was created" do
- @io = new_io @name, @object
- Encoding.default_external = Encoding::UTF_8
- @io.external_encoding.should equal(Encoding::IBM437)
+ @io = new_io @name, "r"
+ Encoding.default_external = Encoding::IBM437
+ @io.external_encoding.should.equal?(Encoding::IBM866)
end
it "returns the external encoding specified when the instance was created" do
- @io = new_io @name, "#{@object}:ibm866"
+ @io = new_io @name, "r:utf-8"
Encoding.default_external = Encoding::IBM437
- @io.external_encoding.should equal(Encoding::IBM866)
+ @io.external_encoding.should.equal?(Encoding::UTF_8)
end
it "returns the encoding set by #set_encoding" do
- @io = new_io @name, "#{@object}:ibm866"
+ @io = new_io @name, "r:utf-8"
@io.set_encoding Encoding::EUC_JP, nil
- @io.external_encoding.should equal(Encoding::EUC_JP)
+ @io.external_encoding.should.equal?(Encoding::EUC_JP)
end
end
- describe "when Encoding.default_external == Encoding.default_internal" do
+ describe "when Encoding.default_external != Encoding.default_internal" do
before :each do
- Encoding.default_external = Encoding::IBM866
+ Encoding.default_external = Encoding::IBM437
Encoding.default_internal = Encoding::IBM866
end
- it "returns the value of Encoding.default_external when the instance was created" do
- @io = new_io @name, @object
- Encoding.default_external = Encoding::UTF_8
- @io.external_encoding.should equal(Encoding::IBM866)
- end
it "returns the external encoding specified when the instance was created" do
- @io = new_io @name, "#{@object}:ibm866"
+ @io = new_io @name, "r:utf-8"
Encoding.default_external = Encoding::IBM437
- @io.external_encoding.should equal(Encoding::IBM866)
+ @io.external_encoding.should.equal?(Encoding::UTF_8)
end
it "returns the encoding set by #set_encoding" do
- @io = new_io @name, "#{@object}:ibm866"
+ @io = new_io @name, "r:utf-8"
@io.set_encoding Encoding::EUC_JP, nil
- @io.external_encoding.should equal(Encoding::EUC_JP)
+ @io.external_encoding.should.equal?(Encoding::EUC_JP)
end
end
end
- describe "IO#external_encoding" do
- before :each do
- @external = Encoding.default_external
- @internal = Encoding.default_internal
-
- @name = tmp("io_external_encoding")
- touch(@name)
- end
-
- after :each do
- Encoding.default_external = @external
- Encoding.default_internal = @internal
-
- @io.close if @io
- rm_r @name
- end
-
- describe "with 'r' mode" do
- describe "when Encoding.default_internal is nil" do
- before :each do
- Encoding.default_internal = nil
- Encoding.default_external = Encoding::IBM866
- end
-
- it "returns Encoding.default_external if the external encoding is not set" do
- @io = new_io @name, "r"
- @io.external_encoding.should equal(Encoding::IBM866)
- end
-
- it "returns Encoding.default_external when that encoding is changed after the instance is created" do
- @io = new_io @name, "r"
- Encoding.default_external = Encoding::IBM437
- @io.external_encoding.should equal(Encoding::IBM437)
- end
-
- it "returns the external encoding specified when the instance was created" do
- @io = new_io @name, "r:utf-8"
- Encoding.default_external = Encoding::IBM437
- @io.external_encoding.should equal(Encoding::UTF_8)
- end
-
- it "returns the encoding set by #set_encoding" do
- @io = new_io @name, "r:utf-8"
- @io.set_encoding Encoding::EUC_JP, nil
- @io.external_encoding.should equal(Encoding::EUC_JP)
- end
- end
-
- describe "when Encoding.default_external == Encoding.default_internal" do
- before :each do
- Encoding.default_external = Encoding::IBM866
- Encoding.default_internal = Encoding::IBM866
- end
-
- it "returns the value of Encoding.default_external when the instance was created" do
- @io = new_io @name, "r"
- Encoding.default_external = Encoding::IBM437
- @io.external_encoding.should equal(Encoding::IBM866)
- end
-
- it "returns the external encoding specified when the instance was created" do
- @io = new_io @name, "r:utf-8"
- Encoding.default_external = Encoding::IBM437
- @io.external_encoding.should equal(Encoding::UTF_8)
- end
-
- it "returns the encoding set by #set_encoding" do
- @io = new_io @name, "r:utf-8"
- @io.set_encoding Encoding::EUC_JP, nil
- @io.external_encoding.should equal(Encoding::EUC_JP)
- end
- end
-
- describe "when Encoding.default_external != Encoding.default_internal" do
- before :each do
- Encoding.default_external = Encoding::IBM437
- Encoding.default_internal = Encoding::IBM866
- end
-
-
- it "returns the external encoding specified when the instance was created" do
- @io = new_io @name, "r:utf-8"
- Encoding.default_external = Encoding::IBM437
- @io.external_encoding.should equal(Encoding::UTF_8)
- end
-
- it "returns the encoding set by #set_encoding" do
- @io = new_io @name, "r:utf-8"
- @io.set_encoding Encoding::EUC_JP, nil
- @io.external_encoding.should equal(Encoding::EUC_JP)
- end
- end
- end
-
- describe "with 'rb' mode" do
- it "returns Encoding::ASCII_8BIT" do
- @io = new_io @name, "rb"
- @io.external_encoding.should equal(Encoding::ASCII_8BIT)
- end
-
- it "returns the external encoding specified by the mode argument" do
- @io = new_io @name, "rb:ibm437"
- @io.external_encoding.should equal(Encoding::IBM437)
- end
+ describe "with 'rb' mode" do
+ it "returns Encoding::BINARY" do
+ @io = new_io @name, "rb"
+ @io.external_encoding.should.equal?(Encoding::BINARY)
end
- describe "with 'r+' mode" do
- it_behaves_like :io_external_encoding_write, nil, "r+"
+ it "returns the external encoding specified by the mode argument" do
+ @io = new_io @name, "rb:ibm437"
+ @io.external_encoding.should.equal?(Encoding::IBM437)
end
+ end
- describe "with 'w' mode" do
- it_behaves_like :io_external_encoding_write, nil, "w"
- end
+ describe "with 'r+' mode" do
+ it_behaves_like :io_external_encoding_write, nil, "r+"
+ end
- describe "with 'wb' mode" do
- it "returns Encoding::ASCII_8BIT" do
- @io = new_io @name, "wb"
- @io.external_encoding.should equal(Encoding::ASCII_8BIT)
- end
+ describe "with 'w' mode" do
+ it_behaves_like :io_external_encoding_write, nil, "w"
+ end
- it "returns the external encoding specified by the mode argument" do
- @io = new_io @name, "wb:ibm437"
- @io.external_encoding.should equal(Encoding::IBM437)
- end
+ describe "with 'wb' mode" do
+ it "returns Encoding::BINARY" do
+ @io = new_io @name, "wb"
+ @io.external_encoding.should.equal?(Encoding::BINARY)
end
- describe "with 'w+' mode" do
- it_behaves_like :io_external_encoding_write, nil, "w+"
+ it "returns the external encoding specified by the mode argument" do
+ @io = new_io @name, "wb:ibm437"
+ @io.external_encoding.should.equal?(Encoding::IBM437)
end
+ end
- describe "with 'a' mode" do
- it_behaves_like :io_external_encoding_write, nil, "a"
- end
+ describe "with 'w+' mode" do
+ it_behaves_like :io_external_encoding_write, nil, "w+"
+ end
- describe "with 'a+' mode" do
- it_behaves_like :io_external_encoding_write, nil, "a+"
- end
+ describe "with 'a' mode" do
+ it_behaves_like :io_external_encoding_write, nil, "a"
+ end
+
+ describe "with 'a+' mode" do
+ it_behaves_like :io_external_encoding_write, nil, "a+"
end
end
diff --git a/spec/ruby/core/io/fcntl_spec.rb b/spec/ruby/core/io/fcntl_spec.rb
index 0e20f50f60..be6d06c672 100644
--- a/spec/ruby/core/io/fcntl_spec.rb
+++ b/spec/ruby/core/io/fcntl_spec.rb
@@ -1,8 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "IO#fcntl" do
it "raises IOError on closed stream" do
- lambda { IOSpecs.closed_io.fcntl(5, 5) }.should raise_error(IOError)
+ -> { IOSpecs.closed_io.fcntl(5, 5) }.should.raise(IOError)
end
end
diff --git a/spec/ruby/core/io/fdatasync_spec.rb b/spec/ruby/core/io/fdatasync_spec.rb
index 9bcbbda336..6242258ea0 100644
--- a/spec/ruby/core/io/fdatasync_spec.rb
+++ b/spec/ruby/core/io/fdatasync_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "IO#fdatasync" do
it "needs to be reviewed for spec completeness"
diff --git a/spec/ruby/core/io/fileno_spec.rb b/spec/ruby/core/io/fileno_spec.rb
index 259ac38073..22fd68d166 100644
--- a/spec/ruby/core/io/fileno_spec.rb
+++ b/spec/ruby/core/io/fileno_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "IO#fileno" do
it "returns the numeric file descriptor of the given IO object" do
@@ -7,6 +7,6 @@ describe "IO#fileno" do
end
it "raises IOError on closed stream" do
- lambda { IOSpecs.closed_io.fileno }.should raise_error(IOError)
+ -> { IOSpecs.closed_io.fileno }.should.raise(IOError)
end
end
diff --git a/spec/ruby/core/io/fixtures/classes.rb b/spec/ruby/core/io/fixtures/classes.rb
index a771e3d929..204a2a101b 100644
--- a/spec/ruby/core/io/fixtures/classes.rb
+++ b/spec/ruby/core/io/fixtures/classes.rb
@@ -1,9 +1,24 @@
# -*- encoding: utf-8 -*-
module IOSpecs
+ THREAD_CLOSE_RETRIES = 10
+ THREAD_CLOSE_ERROR_MESSAGE = 'stream closed in another thread'
+
class SubIO < IO
end
+ class SubIOWithRedefinedNew < IO
+ def self.new(...)
+ ScratchPad << :redefined_new_called
+ super
+ end
+
+ def initialize(...)
+ ScratchPad << :call_original_initialize
+ super
+ end
+ end
+
def self.collector
Proc.new { |x| ScratchPad << x }
end
@@ -105,6 +120,14 @@ module IOSpecs
"linha ", "cinco.\nHere ", "is ", "line ", "six.\n" ]
end
+ def self.lines_space_separator_without_trailing_spaces
+ [ "Voici", "la", "ligne", "une.\nQui",
+ "\303\250", "la", "linea", "due.\n\n\nAqu\303\255",
+ "est\303\241", "la", "l\303\255nea", "tres.\nHier",
+ "ist", "Zeile", "vier.\n\nEst\303\241", "aqui", "a",
+ "linha", "cinco.\nHere", "is", "line", "six.\n" ]
+ end
+
def self.lines_arbitrary_separator
[ "Voici la ligne une.\nQui \303\250",
" la linea due.\n\n\nAqu\303\255 est\303\241 la l\303\255nea tres.\nHier ist Zeile vier.\n\nEst\303\241 aqui a linha cinco.\nHere is line six.\n" ]
@@ -116,12 +139,18 @@ module IOSpecs
"Est\303\241 aqui a linha cinco.\nHere is line six.\n" ]
end
+ def self.paragraphs_without_trailing_new_line_characters
+ [ "Voici la ligne une.\nQui \303\250 la linea due.",
+ "Aqu\303\255 est\303\241 la l\303\255nea tres.\nHier ist Zeile vier.",
+ "Est\303\241 aqui a linha cinco.\nHere is line six.\n" ]
+ end
+
# Creates an IO instance for an existing fixture file. The
# file should obviously not be deleted.
- def self.io_fixture(name, options_or_mode="r:utf-8")
+ def self.io_fixture(name, mode = "r:utf-8")
path = fixture __FILE__, name
name = path if File.exist? path
- new_io name, options_or_mode
+ new_io(name, mode)
end
# Returns a closed instance of IO that was opened to reference
@@ -164,7 +193,7 @@ module IOSpecs
@io = io
end
- def read(size, buf=nil)
+ def read(size, buf)
@io.read size, buf
end
@@ -178,7 +207,7 @@ module IOSpecs
@io = io
end
- def readpartial(size, buf=nil)
+ def readpartial(size, buf)
@io.readpartial size, buf
end
diff --git a/spec/ruby/core/io/fixtures/copy_in_out.rb b/spec/ruby/core/io/fixtures/copy_in_out.rb
new file mode 100644
index 0000000000..b9d4085a47
--- /dev/null
+++ b/spec/ruby/core/io/fixtures/copy_in_out.rb
@@ -0,0 +1,2 @@
+STDOUT.sync = false
+IO.copy_stream(STDIN, STDOUT)
diff --git a/spec/ruby/core/io/flush_spec.rb b/spec/ruby/core/io/flush_spec.rb
index c877650ecd..4c3e8d12af 100644
--- a/spec/ruby/core/io/flush_spec.rb
+++ b/spec/ruby/core/io/flush_spec.rb
@@ -1,8 +1,37 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "IO#flush" do
it "raises IOError on closed stream" do
- lambda { IOSpecs.closed_io.flush }.should raise_error(IOError)
+ -> { IOSpecs.closed_io.flush }.should.raise(IOError)
+ end
+
+ describe "on a pipe" do
+ before :each do
+ @r, @w = IO.pipe
+ end
+
+ after :each do
+ @r.close
+ begin
+ @w.close
+ rescue Errno::EPIPE
+ end
+ end
+
+ # [ruby-core:90895] RJIT worker may leave fd open in a forked child.
+ # For instance, RJIT creates a worker before @r.close with fork(), @r.close happens,
+ # and the RJIT worker keeps the pipe open until the worker execve().
+ # TODO: consider acquiring GVL from RJIT worker.
+ guard_not -> { defined?(RubyVM::RJIT) && RubyVM::RJIT.enabled? } do
+ it "raises Errno::EPIPE if sync=false and the read end is closed" do
+ @w.sync = false
+ @w.write "foo"
+ @r.close
+
+ -> { @w.flush }.should.raise(Errno::EPIPE, /Broken pipe/)
+ -> { @w.close }.should.raise(Errno::EPIPE, /Broken pipe/)
+ end
+ end
end
end
diff --git a/spec/ruby/core/io/for_fd_spec.rb b/spec/ruby/core/io/for_fd_spec.rb
index b4abc1f87c..2d86361b73 100644
--- a/spec/ruby/core/io/for_fd_spec.rb
+++ b/spec/ruby/core/io/for_fd_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/new', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/new'
describe "IO.for_fd" do
it_behaves_like :io_new, :for_fd
diff --git a/spec/ruby/core/io/foreach_spec.rb b/spec/ruby/core/io/foreach_spec.rb
index f5fa1459e9..ccd2f25517 100644
--- a/spec/ruby/core/io/foreach_spec.rb
+++ b/spec/ruby/core/io/foreach_spec.rb
@@ -1,7 +1,7 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/readlines', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/readlines'
describe "IO.foreach" do
before :each do
@@ -14,31 +14,46 @@ describe "IO.foreach" do
IO.foreach(@name) { $..should == @count += 1 }
end
- describe "when the filename starts with |" do
- it "gets data from the standard out of the subprocess" do
- cmd = "|sh -c 'echo hello;echo line2'"
- platform_is :windows do
- cmd = "|cmd.exe /C echo hello&echo line2"
+ ruby_version_is ""..."4.0" do
+ describe "when the filename starts with |" do
+ it "gets data from the standard out of the subprocess" do
+ cmd = "|sh -c 'echo hello;echo line2'"
+ platform_is :windows do
+ cmd = "|cmd.exe /C echo hello&echo line2"
+ end
+
+ suppress_warning do # https://bugs.ruby-lang.org/issues/19630
+ IO.foreach(cmd) { |l| ScratchPad << l }
+ end
+ ScratchPad.recorded.should == ["hello\n", "line2\n"]
end
- IO.foreach(cmd) { |l| ScratchPad << l }
- ScratchPad.recorded.should == ["hello\n", "line2\n"]
- end
- with_feature :fork do
- it "gets data from a fork when passed -" do
- parent_pid = $$
+ guard -> { Process.respond_to?(:fork) } do
+ it "gets data from a fork when passed -" do
+ parent_pid = $$
- IO.foreach("|-") { |l| ScratchPad << l }
+ suppress_warning do # https://bugs.ruby-lang.org/issues/19630
+ IO.foreach("|-") { |l| ScratchPad << l }
+ end
- if $$ == parent_pid
- ScratchPad.recorded.should == ["hello\n", "from a fork\n"]
- else # child
- puts "hello"
- puts "from a fork"
- exit!
+ if $$ == parent_pid
+ ScratchPad.recorded.should == ["hello\n", "from a fork\n"]
+ else # child
+ puts "hello"
+ puts "from a fork"
+ exit!
+ end
end
end
end
+
+ # https://bugs.ruby-lang.org/issues/19630
+ it "warns about deprecation given a path with a pipe" do
+ cmd = "|echo ok"
+ -> {
+ IO.foreach(cmd).to_a
+ }.should complain(/IO process creation with a leading '\|'/)
+ end
end
end
@@ -58,12 +73,12 @@ describe "IO.foreach" do
it "sets $_ to nil" do
$_ = "test"
IO.foreach(@name) { }
- $_.should be_nil
+ $_.should == nil
end
describe "when no block is given" do
it "returns an Enumerator" do
- IO.foreach(@name).should be_an_instance_of(Enumerator)
+ IO.foreach(@name).should.instance_of?(Enumerator)
IO.foreach(@name).to_a.should == IOSpecs.lines
end
diff --git a/spec/ruby/core/io/fsync_spec.rb b/spec/ruby/core/io/fsync_spec.rb
index 7816ecc42b..0317cbc805 100644
--- a/spec/ruby/core/io/fsync_spec.rb
+++ b/spec/ruby/core/io/fsync_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "IO#fsync" do
before :each do
@@ -12,7 +12,7 @@ describe "IO#fsync" do
end
it "raises an IOError on closed stream" do
- lambda { IOSpecs.closed_io.fsync }.should raise_error(IOError)
+ -> { IOSpecs.closed_io.fsync }.should.raise(IOError)
end
it "writes the buffered data to permanent storage" do
diff --git a/spec/ruby/core/io/getbyte_spec.rb b/spec/ruby/core/io/getbyte_spec.rb
index cb8929890f..668d81519c 100644
--- a/spec/ruby/core/io/getbyte_spec.rb
+++ b/spec/ruby/core/io/getbyte_spec.rb
@@ -1,6 +1,6 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "IO#getbyte" do
before :each do
@@ -23,7 +23,7 @@ describe "IO#getbyte" do
end
it "raises an IOError on closed stream" do
- lambda { IOSpecs.closed_io.getbyte }.should raise_error(IOError)
+ -> { IOSpecs.closed_io.getbyte }.should.raise(IOError)
end
end
@@ -40,3 +40,19 @@ describe "IO#getbyte" do
@io.getbyte.should == nil
end
end
+
+describe "IO#getbyte" do
+ before :each do
+ @name = tmp("io_getbyte.txt")
+ @io = new_io(@name, 'w')
+ end
+
+ after :each do
+ @io.close if @io
+ rm_r @name if @name
+ end
+
+ it "raises an IOError if the stream is not readable" do
+ -> { @io.getbyte }.should.raise(IOError)
+ end
+end
diff --git a/spec/ruby/core/io/getc_spec.rb b/spec/ruby/core/io/getc_spec.rb
index dfff1a9583..3be86203c0 100644
--- a/spec/ruby/core/io/getc_spec.rb
+++ b/spec/ruby/core/io/getc_spec.rb
@@ -1,6 +1,6 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "IO#getc" do
before :each do
@@ -19,11 +19,11 @@ describe "IO#getc" do
it "returns nil when invoked at the end of the stream" do
@io.read
- @io.getc.should be_nil
+ @io.getc.should == nil
end
it "raises IOError on closed stream" do
- lambda { IOSpecs.closed_io.getc }.should raise_error(IOError)
+ -> { IOSpecs.closed_io.getc }.should.raise(IOError)
end
end
@@ -37,6 +37,6 @@ describe "IO#getc" do
end
it "returns nil on empty stream" do
- @io.getc.should be_nil
+ @io.getc.should == nil
end
end
diff --git a/spec/ruby/core/io/gets_spec.rb b/spec/ruby/core/io/gets_spec.rb
index 6e0518b512..ce3ee73b94 100644
--- a/spec/ruby/core/io/gets_spec.rb
+++ b/spec/ruby/core/io/gets_spec.rb
@@ -1,7 +1,7 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/gets_ascii', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/gets_ascii'
describe "IO#gets" do
it_behaves_like :io_gets_ascii, :gets
@@ -24,13 +24,19 @@ describe "IO#gets" do
end
end
+ it "sets $_ to nil after the last line has been read" do
+ while @io.gets
+ end
+ $_.should == nil
+ end
+
it "returns nil if called at the end of the stream" do
IOSpecs.lines.length.times { @io.gets }
@io.gets.should == nil
end
it "raises IOError on closed stream" do
- lambda { IOSpecs.closed_io.gets }.should raise_error(IOError)
+ -> { IOSpecs.closed_io.gets }.should.raise(IOError)
end
describe "with no separator" do
@@ -38,12 +44,6 @@ describe "IO#gets" do
IOSpecs.lines.each { |line| line.should == @io.gets }
end
- it "returns tainted strings" do
- while line = @io.gets
- line.tainted?.should == true
- end
- end
-
it "updates lineno with each invocation" do
while @io.gets
@io.lineno.should == @count += 1
@@ -62,12 +62,6 @@ describe "IO#gets" do
@io.gets(nil).should == IOSpecs.lines.join("")
end
- it "returns tainted strings" do
- while line = @io.gets(nil)
- line.tainted?.should == true
- end
- end
-
it "updates lineno with each invocation" do
while @io.gets(nil)
@io.lineno.should == @count += 1
@@ -96,12 +90,6 @@ describe "IO#gets" do
@io.gets.should == IOSpecs.lines[4]
end
- it "returns tainted strings" do
- while line = @io.gets("")
- line.tainted?.should == true
- end
- end
-
it "updates lineno with each invocation" do
while @io.gets("")
@io.lineno.should == @count += 1
@@ -120,12 +108,6 @@ describe "IO#gets" do
@io.gets("la linea").should == "Voici la ligne une.\nQui \303\250 la linea"
end
- it "returns tainted strings" do
- while line = @io.gets("la")
- line.tainted?.should == true
- end
- end
-
it "updates lineno with each invocation" do
while (@io.gets("la"))
@io.lineno.should == @count += 1
@@ -137,15 +119,50 @@ describe "IO#gets" do
$..should == @count += 1
end
end
- end
- ruby_version_is "2.4" do
- describe "when passed chomp" do
- it "returns the first line without a trailing newline character" do
- @io.gets(chomp: true).should == IOSpecs.lines_without_newline_characters[0]
+ describe "that consists of multiple bytes" do
+ platform_is_not :windows do
+ it "should match the separator even if the buffer is filled over successive reads" do
+ IO.pipe do |read, write|
+
+ # Write part of the string with the separator split between two write calls. We want
+ # the read to intertwine such that when the read starts the full data isn't yet
+ # available in the buffer.
+ write.write("Aquí está la línea tres\r\n")
+
+ t = Thread.new do
+ # Continue reading until the separator is encountered or the pipe is closed.
+ read.gets("\r\n\r\n")
+ end
+
+ # Write the other half of the separator, which should cause the `gets` call to now
+ # match. Explicitly close the pipe for good measure so a bug in `gets` doesn't block forever.
+ Thread.pass until t.stop?
+
+ write.write("\r\nelse\r\n\r\n")
+ write.close
+
+ t.value.bytes.should == "Aquí está la línea tres\r\n\r\n".bytes
+ read.read(8).bytes.should == "else\r\n\r\n".bytes
+ end
+ end
end
end
end
+
+ describe "when passed chomp" do
+ it "returns the first line without a trailing newline character" do
+ @io.gets(chomp: true).should == IOSpecs.lines_without_newline_characters[0]
+ end
+
+ it "raises exception when options passed as Hash" do
+ -> { @io.gets({ chomp: true }) }.should.raise(TypeError)
+
+ -> {
+ @io.gets("\n", 1, { chomp: true })
+ }.should.raise(ArgumentError, "wrong number of arguments (given 3, expected 0..2)")
+ end
+ end
end
describe "IO#gets" do
@@ -158,11 +175,11 @@ describe "IO#gets" do
end
it "raises an IOError if the stream is opened for append only" do
- lambda { File.open(@name, fmode("a:utf-8")) { |f| f.gets } }.should raise_error(IOError)
+ -> { File.open(@name, "a:utf-8") { |f| f.gets } }.should.raise(IOError)
end
it "raises an IOError if the stream is opened for writing only" do
- lambda { File.open(@name, fmode("w:utf-8")) { |f| f.gets } }.should raise_error(IOError)
+ -> { File.open(@name, "w:utf-8") { |f| f.gets } }.should.raise(IOError)
end
end
@@ -170,7 +187,7 @@ describe "IO#gets" do
before :each do
@name = tmp("io_gets")
touch(@name) { |f| f.write "one\n\ntwo\n\nthree\nfour\n" }
- @io = new_io @name, fmode("r:utf-8")
+ @io = new_io @name, "r:utf-8"
end
after :each do
@@ -226,6 +243,16 @@ describe "IO#gets" do
it "reads all bytes when pass a separator and reading more than all bytes" do
@io.gets("\t", 100).should == "one\n\ntwo\n\nthree\nfour\n"
end
+
+ it "returns empty string when 0 passed as a limit" do
+ @io.gets(0).should == ""
+ @io.gets(nil, 0).should == ""
+ @io.gets("", 0).should == ""
+ end
+
+ it "does not accept limit that doesn't fit in a C off_t" do
+ -> { @io.gets(2**128) }.should.raise(RangeError)
+ end
end
describe "IO#gets" do
@@ -234,7 +261,7 @@ describe "IO#gets" do
# create data "æœæ—¥" + "\xE3\x81" * 100 to avoid utf-8 conflicts
data = "æœæ—¥" + ([227,129].pack('C*') * 100).force_encoding('utf-8')
touch(@name) { |f| f.write data }
- @io = new_io @name, fmode("r:utf-8")
+ @io = new_io @name, "r:utf-8"
end
after :each do
@@ -297,25 +324,25 @@ describe "IO#gets" do
end
it "overwrites the default external encoding with the IO object's own external encoding" do
- Encoding.default_external = Encoding::ASCII_8BIT
+ Encoding.default_external = Encoding::BINARY
Encoding.default_internal = Encoding::UTF_8
@io = new_io @name, 'r'
@io.set_encoding Encoding::IBM866
@io.gets.encoding.should == Encoding::UTF_8
end
- it "ignores the internal encoding if the default external encoding is ASCII-8BIT" do
- Encoding.default_external = Encoding::ASCII_8BIT
+ it "ignores the internal encoding if the default external encoding is BINARY" do
+ Encoding.default_external = Encoding::BINARY
Encoding.default_internal = Encoding::UTF_8
@io = new_io @name, 'r'
- @io.gets.encoding.should == Encoding::ASCII_8BIT
+ @io.gets.encoding.should == Encoding::BINARY
end
- it "transcodes to internal encoding if the IO object's external encoding is ASCII-8BIT" do
- Encoding.default_external = Encoding::ASCII_8BIT
+ it "ignores the internal encoding if the IO object's external encoding is BINARY" do
+ Encoding.default_external = Encoding::BINARY
Encoding.default_internal = Encoding::UTF_8
@io = new_io @name, 'r'
- @io.set_encoding Encoding::ASCII_8BIT, Encoding::UTF_8
- @io.gets.encoding.should == Encoding::UTF_8
+ @io.set_encoding Encoding::BINARY, Encoding::UTF_8
+ @io.gets.encoding.should == Encoding::BINARY
end
end
diff --git a/spec/ruby/core/io/initialize_spec.rb b/spec/ruby/core/io/initialize_spec.rb
index 4731257625..3425e5ac37 100644
--- a/spec/ruby/core/io/initialize_spec.rb
+++ b/spec/ruby/core/io/initialize_spec.rb
@@ -1,10 +1,10 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "IO#initialize" do
before :each do
@name = tmp("io_initialize.txt")
- @io = new_io @name
+ @io = IO.new(new_fd(@name))
@fd = @io.fileno
end
@@ -13,12 +13,10 @@ describe "IO#initialize" do
rm_r @name
end
- it "reassociates the IO instance with the new descriptor when passed a Fixnum" do
+ it "reassociates the IO instance with the new descriptor when passed an Integer" do
fd = new_fd @name, "r:utf-8"
@io.send :initialize, fd, 'r'
@io.fileno.should == fd
- # initialize has closed the old descriptor
- lambda { IO.for_fd(@fd).close }.should raise_error(Errno::EBADF)
end
it "calls #to_int to coerce the object passed as an fd" do
@@ -27,27 +25,36 @@ describe "IO#initialize" do
obj.should_receive(:to_int).and_return(fd)
@io.send :initialize, obj, 'r'
@io.fileno.should == fd
- # initialize has closed the old descriptor
- lambda { IO.for_fd(@fd).close }.should raise_error(Errno::EBADF)
+ end
+
+ it "accepts options as keyword arguments" do
+ fd = new_fd @name, "w:utf-8"
+
+ @io.send(:initialize, fd, "w", flags: File::CREAT)
+ @io.fileno.should == fd
+
+ -> {
+ @io.send(:initialize, fd, "w", {flags: File::CREAT})
+ }.should.raise(ArgumentError, "wrong number of arguments (given 3, expected 1..2)")
end
it "raises a TypeError when passed an IO" do
- lambda { @io.send :initialize, STDOUT, 'w' }.should raise_error(TypeError)
+ -> { @io.send :initialize, STDOUT, 'w' }.should.raise(TypeError)
end
it "raises a TypeError when passed nil" do
- lambda { @io.send :initialize, nil, 'w' }.should raise_error(TypeError)
+ -> { @io.send :initialize, nil, 'w' }.should.raise(TypeError)
end
it "raises a TypeError when passed a String" do
- lambda { @io.send :initialize, "4", 'w' }.should raise_error(TypeError)
+ -> { @io.send :initialize, "4", 'w' }.should.raise(TypeError)
end
it "raises IOError on closed stream" do
- lambda { @io.send :initialize, IOSpecs.closed_io.fileno }.should raise_error(IOError)
+ -> { @io.send :initialize, IOSpecs.closed_io.fileno }.should.raise(IOError)
end
it "raises an Errno::EBADF when given an invalid file descriptor" do
- lambda { @io.send :initialize, -1, 'w' }.should raise_error(Errno::EBADF)
+ -> { @io.send :initialize, -1, 'w' }.should.raise(Errno::EBADF)
end
end
diff --git a/spec/ruby/core/io/inspect_spec.rb b/spec/ruby/core/io/inspect_spec.rb
index 1c6bf99b44..37dc459f22 100644
--- a/spec/ruby/core/io/inspect_spec.rb
+++ b/spec/ruby/core/io/inspect_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "IO#inspect" do
after :each do
@@ -8,13 +8,13 @@ describe "IO#inspect" do
it "contains the file descriptor number" do
@r, @w = IO.pipe
- @r.inspect.should include("fd #{@r.fileno}")
+ @r.inspect.should.include?("fd #{@r.fileno}")
end
it "contains \"(closed)\" if the stream is closed" do
@r, @w = IO.pipe
@r.close
- @r.inspect.should include("(closed)")
+ @r.inspect.should.include?("(closed)")
end
it "reports IO as its Method object's owner" do
diff --git a/spec/ruby/core/io/internal_encoding_spec.rb b/spec/ruby/core/io/internal_encoding_spec.rb
index 7578559838..9963a93f33 100644
--- a/spec/ruby/core/io/internal_encoding_spec.rb
+++ b/spec/ruby/core/io/internal_encoding_spec.rb
@@ -1,140 +1,145 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-with_feature :encoding do
- describe :io_internal_encoding, shared: true do
- describe "when Encoding.default_internal is not set" do
- before :each do
- Encoding.default_internal = nil
- end
-
- it "returns nil if the internal encoding is not set" do
- @io = new_io @name, @object
- @io.internal_encoding.should be_nil
- end
-
- it "returns nil if Encoding.default_internal is changed after the instance is created" do
- @io = new_io @name, @object
- Encoding.default_internal = Encoding::IBM437
- @io.internal_encoding.should be_nil
- end
-
- it "returns the value set when the instance was created" do
- @io = new_io @name, "#{@object}:utf-8:euc-jp"
- Encoding.default_internal = Encoding::IBM437
- @io.internal_encoding.should equal(Encoding::EUC_JP)
- end
-
- it "returns the value set by #set_encoding" do
- @io = new_io @name, @object
- @io.set_encoding(Encoding::US_ASCII, Encoding::IBM437)
- @io.internal_encoding.should equal(Encoding::IBM437)
- end
- end
-
- describe "when Encoding.default_internal == Encoding.default_external" do
- before :each do
- Encoding.default_external = Encoding::IBM866
- Encoding.default_internal = Encoding::IBM866
- end
-
- it "returns nil" do
- @io = new_io @name, @object
- @io.internal_encoding.should be_nil
- end
-
- it "returns nil regardless of Encoding.default_internal changes" do
- @io = new_io @name, @object
- Encoding.default_internal = Encoding::IBM437
- @io.internal_encoding.should be_nil
- end
- end
-
- describe "when Encoding.default_internal != Encoding.default_external" do
- before :each do
- Encoding.default_external = Encoding::IBM437
- Encoding.default_internal = Encoding::IBM866
- end
-
- it "returns the value of Encoding.default_internal when the instance was created if the internal encoding is not set" do
- @io = new_io @name, @object
- @io.internal_encoding.should equal(Encoding::IBM866)
- end
-
- it "does not change when Encoding.default_internal is changed" do
- @io = new_io @name, @object
- Encoding.default_internal = Encoding::IBM437
- @io.internal_encoding.should equal(Encoding::IBM866)
- end
-
- it "returns the internal encoding set when the instance was created" do
- @io = new_io @name, "#{@object}:utf-8:euc-jp"
- @io.internal_encoding.should equal(Encoding::EUC_JP)
- end
-
- it "does not change when set and Encoding.default_internal is changed" do
- @io = new_io @name, "#{@object}:utf-8:euc-jp"
- Encoding.default_internal = Encoding::IBM437
- @io.internal_encoding.should equal(Encoding::EUC_JP)
- end
-
- it "returns the value set by #set_encoding" do
- @io = new_io @name, @object
- @io.set_encoding(Encoding::US_ASCII, Encoding::IBM437)
- @io.internal_encoding.should equal(Encoding::IBM437)
- end
-
- it "returns nil when Encoding.default_external is ASCII-8BIT and the internal encoding is not set" do
- Encoding.default_external = Encoding::ASCII_8BIT
- @io = new_io @name, @object
- @io.internal_encoding.should be_nil
- end
-
- it "returns nil when the external encoding is ASCII-8BIT and the internal encoding is not set" do
- @io = new_io @name, "#{@object}:ascii-8bit"
- @io.internal_encoding.should be_nil
- end
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe :io_internal_encoding, shared: true do
+ describe "when Encoding.default_internal is not set" do
+ before :each do
+ Encoding.default_internal = nil
+ end
+
+ it "returns nil if the internal encoding is not set" do
+ @io = new_io @name, @object
+ @io.internal_encoding.should == nil
+ end
+
+ it "returns nil if Encoding.default_internal is changed after the instance is created" do
+ @io = new_io @name, @object
+ Encoding.default_internal = Encoding::IBM437
+ @io.internal_encoding.should == nil
+ end
+
+ it "returns the value set when the instance was created" do
+ @io = new_io @name, "#{@object}:utf-8:euc-jp"
+ Encoding.default_internal = Encoding::IBM437
+ @io.internal_encoding.should.equal?(Encoding::EUC_JP)
+ end
+
+ it "returns the value set by #set_encoding" do
+ @io = new_io @name, @object
+ @io.set_encoding(Encoding::US_ASCII, Encoding::IBM437)
+ @io.internal_encoding.should.equal?(Encoding::IBM437)
end
end
- describe "IO#internal_encoding" do
+ describe "when Encoding.default_internal == Encoding.default_external" do
before :each do
- @external = Encoding.default_external
- @internal = Encoding.default_internal
+ Encoding.default_external = Encoding::IBM866
+ Encoding.default_internal = Encoding::IBM866
+ end
- @name = tmp("io_internal_encoding")
- touch(@name)
+ it "returns nil" do
+ @io = new_io @name, @object
+ @io.internal_encoding.should == nil
end
- after :each do
- @io.close if @io
- rm_r @name
+ it "returns nil regardless of Encoding.default_internal changes" do
+ @io = new_io @name, @object
+ Encoding.default_internal = Encoding::IBM437
+ @io.internal_encoding.should == nil
+ end
+ end
- Encoding.default_external = @external
- Encoding.default_internal = @internal
+ describe "when Encoding.default_internal != Encoding.default_external" do
+ before :each do
+ Encoding.default_external = Encoding::IBM437
+ Encoding.default_internal = Encoding::IBM866
end
- describe "with 'r' mode" do
- it_behaves_like :io_internal_encoding, nil, "r"
+ it "returns the value of Encoding.default_internal when the instance was created if the internal encoding is not set" do
+ @io = new_io @name, @object
+ @io.internal_encoding.should.equal?(Encoding::IBM866)
end
- describe "with 'r+' mode" do
- it_behaves_like :io_internal_encoding, nil, "r+"
+ it "does not change when Encoding.default_internal is changed" do
+ @io = new_io @name, @object
+ Encoding.default_internal = Encoding::IBM437
+ @io.internal_encoding.should.equal?(Encoding::IBM866)
end
- describe "with 'w' mode" do
- it_behaves_like :io_internal_encoding, nil, "w"
+ it "returns the internal encoding set when the instance was created" do
+ @io = new_io @name, "#{@object}:utf-8:euc-jp"
+ @io.internal_encoding.should.equal?(Encoding::EUC_JP)
end
- describe "with 'w+' mode" do
- it_behaves_like :io_internal_encoding, nil, "w+"
+ it "does not change when set and Encoding.default_internal is changed" do
+ @io = new_io @name, "#{@object}:utf-8:euc-jp"
+ Encoding.default_internal = Encoding::IBM437
+ @io.internal_encoding.should.equal?(Encoding::EUC_JP)
end
- describe "with 'a' mode" do
- it_behaves_like :io_internal_encoding, nil, "a"
+ it "returns the value set by #set_encoding" do
+ @io = new_io @name, @object
+ @io.set_encoding(Encoding::US_ASCII, Encoding::IBM437)
+ @io.internal_encoding.should.equal?(Encoding::IBM437)
end
- describe "with 'a+' mode" do
- it_behaves_like :io_internal_encoding, nil, "a+"
+ it "returns nil when Encoding.default_external is BINARY and the internal encoding is not set" do
+ Encoding.default_external = Encoding::BINARY
+ @io = new_io @name, @object
+ @io.internal_encoding.should == nil
end
+
+ it "returns nil when the external encoding is BINARY and the internal encoding is not set" do
+ @io = new_io @name, "#{@object}:binary"
+ @io.internal_encoding.should == nil
+ end
+ end
+end
+
+describe "IO#internal_encoding" do
+ before :each do
+ @external = Encoding.default_external
+ @internal = Encoding.default_internal
+
+ @name = tmp("io_internal_encoding")
+ touch(@name)
+ end
+
+ after :each do
+ @io.close if @io
+ rm_r @name
+
+ Encoding.default_external = @external
+ Encoding.default_internal = @internal
+ end
+
+ it "can be retrieved from a closed stream" do
+ io = IOSpecs.io_fixture("lines.txt", "r")
+ io.close
+ io.internal_encoding.should.equal?(Encoding.default_internal)
+ end
+
+ describe "with 'r' mode" do
+ it_behaves_like :io_internal_encoding, nil, "r"
+ end
+
+ describe "with 'r+' mode" do
+ it_behaves_like :io_internal_encoding, nil, "r+"
+ end
+
+ describe "with 'w' mode" do
+ it_behaves_like :io_internal_encoding, nil, "w"
+ end
+
+ describe "with 'w+' mode" do
+ it_behaves_like :io_internal_encoding, nil, "w+"
+ end
+
+ describe "with 'a' mode" do
+ it_behaves_like :io_internal_encoding, nil, "a"
+ end
+
+ describe "with 'a+' mode" do
+ it_behaves_like :io_internal_encoding, nil, "a+"
end
end
diff --git a/spec/ruby/core/io/io_spec.rb b/spec/ruby/core/io/io_spec.rb
index e196628ef0..0feb1a8774 100644
--- a/spec/ruby/core/io/io_spec.rb
+++ b/spec/ruby/core/io/io_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "IO" do
it "includes File::Constants" do
diff --git a/spec/ruby/core/io/ioctl_spec.rb b/spec/ruby/core/io/ioctl_spec.rb
index 3b2d271c0c..15a5d6ec22 100644
--- a/spec/ruby/core/io/ioctl_spec.rb
+++ b/spec/ruby/core/io/ioctl_spec.rb
@@ -1,31 +1,31 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "IO#ioctl" do
platform_is_not :windows do
it "raises IOError on closed stream" do
- lambda { IOSpecs.closed_io.ioctl(5, 5) }.should raise_error(IOError)
+ -> { IOSpecs.closed_io.ioctl(5, 5) }.should.raise(IOError)
end
end
platform_is :linux do
- platform_is "86" do # x86 / x86_64
+ guard -> { RUBY_PLATFORM.include?("86") } do # x86 / x86_64
it "resizes an empty String to match the output size" do
File.open(__FILE__, 'r') do |f|
- buffer = ''
+ buffer = +''
# FIONREAD in /usr/include/asm-generic/ioctls.h
f.ioctl 0x541B, buffer
- buffer.unpack('I').first.should be_kind_of(Integer)
+ buffer.unpack('I').first.should.is_a?(Integer)
end
end
end
- it "raises an Errno error when ioctl fails" do
+ it "raises a system call error when ioctl fails" do
File.open(__FILE__, 'r') do |f|
- lambda {
+ -> {
# TIOCGWINSZ in /usr/include/asm-generic/ioctls.h
f.ioctl 0x5413, nil
- }.should raise_error(Errno::ENOTTY)
+ }.should.raise(SystemCallError)
end
end
end
diff --git a/spec/ruby/core/io/isatty_spec.rb b/spec/ruby/core/io/isatty_spec.rb
index 87172dddd7..60b97d21be 100644
--- a/spec/ruby/core/io/isatty_spec.rb
+++ b/spec/ruby/core/io/isatty_spec.rb
@@ -1,6 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/tty', __FILE__)
+require_relative '../../spec_helper'
describe "IO#isatty" do
- it_behaves_like :io_tty, :isatty
+ it "is an alias of IO#tty?" do
+ IO.instance_method(:isatty).should == IO.instance_method(:tty?)
+ end
end
diff --git a/spec/ruby/core/io/lineno_spec.rb b/spec/ruby/core/io/lineno_spec.rb
index 4fddbf135c..93b505652a 100644
--- a/spec/ruby/core/io/lineno_spec.rb
+++ b/spec/ruby/core/io/lineno_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "IO#lineno" do
before :each do
@@ -11,7 +11,26 @@ describe "IO#lineno" do
end
it "raises an IOError on a closed stream" do
- lambda { IOSpecs.closed_io.lineno }.should raise_error(IOError)
+ -> { IOSpecs.closed_io.lineno }.should.raise(IOError)
+ end
+
+ it "raises an IOError on a write-only stream" do
+ name = tmp("io_lineno.txt")
+ begin
+ File.open(name, 'w') do |f|
+ -> { f.lineno }.should.raise(IOError)
+ end
+ ensure
+ rm_r name
+ end
+ end
+
+ it "raises an IOError on a duplexed stream with the read side closed" do
+ cmd = platform_is(:windows) ? 'rem' : 'cat'
+ IO.popen(cmd, 'r+') do |p|
+ p.close_read
+ -> { p.lineno }.should.raise(IOError)
+ end
end
it "returns the current line number" do
@@ -37,7 +56,26 @@ describe "IO#lineno=" do
end
it "raises an IOError on a closed stream" do
- lambda { IOSpecs.closed_io.lineno = 5 }.should raise_error(IOError)
+ -> { IOSpecs.closed_io.lineno = 5 }.should.raise(IOError)
+ end
+
+ it "raises an IOError on a write-only stream" do
+ name = tmp("io_lineno.txt")
+ begin
+ File.open(name, 'w') do |f|
+ -> { f.lineno = 0 }.should.raise(IOError)
+ end
+ ensure
+ rm_r name
+ end
+ end
+
+ it "raises an IOError on a duplexed stream with the read side closed" do
+ cmd = platform_is(:windows) ? 'rem' : 'cat'
+ IO.popen(cmd, 'r+') do |p|
+ p.close_read
+ -> { p.lineno = 0 }.should.raise(IOError)
+ end
end
it "calls #to_int on a non-numeric argument" do
@@ -56,8 +94,13 @@ describe "IO#lineno=" do
@io.lineno.should == 92233
end
- it "raises TypeError on nil argument" do
- lambda { @io.lineno = nil }.should raise_error(TypeError)
+ it "raises TypeError if cannot convert argument to Integer implicitly" do
+ -> { @io.lineno = "1" }.should.raise(TypeError, 'no implicit conversion of String into Integer')
+ -> { @io.lineno = nil }.should raise_consistent_error(TypeError, 'no implicit conversion of nil into Integer')
+ end
+
+ it "does not accept Integers that don't fit in a C int" do
+ -> { @io.lineno = 2**32 }.should.raise(RangeError)
end
it "sets the current line number to the given value" do
diff --git a/spec/ruby/core/io/lines_spec.rb b/spec/ruby/core/io/lines_spec.rb
deleted file mode 100644
index 90ddc4e4cf..0000000000
--- a/spec/ruby/core/io/lines_spec.rb
+++ /dev/null
@@ -1,42 +0,0 @@
-# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-
-describe "IO#lines" do
- before :each do
- @io = IOSpecs.io_fixture "lines.txt"
- end
-
- after :each do
- @io.close if @io
- end
-
- it "returns an Enumerator" do
- @io.lines.should be_an_instance_of(Enumerator)
- end
-
- describe "when no block is given" do
- it "returns an Enumerator" do
- @io.lines.should be_an_instance_of(Enumerator)
- end
-
- describe "returned Enumerator" do
- describe "size" do
- it "should return nil" do
- @io.lines.size.should == nil
- end
- end
- end
- end
-
- it "returns a line when accessed" do
- enum = @io.lines
- enum.first.should == IOSpecs.lines[0]
- end
-
- it "yields each line to the passed block" do
- ScratchPad.record []
- @io.lines { |s| ScratchPad << s }
- ScratchPad.recorded.should == IOSpecs.lines
- end
-end
diff --git a/spec/ruby/core/io/new_spec.rb b/spec/ruby/core/io/new_spec.rb
index ce922a4856..979ac0efcb 100644
--- a/spec/ruby/core/io/new_spec.rb
+++ b/spec/ruby/core/io/new_spec.rb
@@ -1,8 +1,16 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/new', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/new'
+
+# NOTE: should be synchronized with library/stringio/initialize_spec.rb
describe "IO.new" do
it_behaves_like :io_new, :new
+
+ it "does not use the given block and warns to use IO::open" do
+ -> {
+ @io = IO.send(@method, @fd) { raise }
+ }.should complain(/warning: IO::new\(\) does not take block; use IO::open\(\) instead/)
+ end
end
describe "IO.new" do
diff --git a/spec/ruby/core/io/nonblock_spec.rb b/spec/ruby/core/io/nonblock_spec.rb
new file mode 100644
index 0000000000..99dc0cafd0
--- /dev/null
+++ b/spec/ruby/core/io/nonblock_spec.rb
@@ -0,0 +1,48 @@
+require_relative '../../spec_helper'
+
+platform_is_not :windows do
+ describe "IO#nonblock?" do
+ before :all do
+ require 'io/nonblock'
+ end
+
+ it "returns false for a file by default" do
+ File.open(__FILE__) do |f|
+ f.nonblock?.should == false
+ end
+ end
+
+ it "returns true for pipe by default" do
+ r, w = IO.pipe
+ begin
+ r.nonblock?.should == true
+ w.nonblock?.should == true
+ ensure
+ r.close
+ w.close
+ end
+ end
+
+ it "returns true for socket by default" do
+ require 'socket'
+ TCPServer.open(0) do |socket|
+ socket.nonblock?.should == true
+ end
+ end
+ end
+
+ describe "IO#nonblock=" do
+ before :all do
+ require 'io/nonblock'
+ end
+
+ it "changes the IO to non-blocking mode" do
+ File.open(__FILE__) do |f|
+ f.nonblock = true
+ f.nonblock?.should == true
+ f.nonblock = false
+ f.nonblock?.should == false
+ end
+ end
+ end
+end
diff --git a/spec/ruby/core/io/open_spec.rb b/spec/ruby/core/io/open_spec.rb
index f87ee6c7c2..ff22d14685 100644
--- a/spec/ruby/core/io/open_spec.rb
+++ b/spec/ruby/core/io/open_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/new', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/new'
describe "IO.open" do
it_behaves_like :io_new, :open
@@ -32,13 +32,26 @@ describe "IO.open" do
super()
ScratchPad.record :called
end
- io.closed?.should be_false
+ io.closed?.should == false
end
ScratchPad.recorded.should == :called
end
+ it "propagate an exception in the block after calling #close" do
+ -> do
+ IO.open(@fd, "w") do |io|
+ IOSpecs.io_mock(io, :close) do
+ super()
+ ScratchPad.record :called
+ end
+ raise Exception
+ end
+ end.should.raise(Exception)
+ ScratchPad.recorded.should == :called
+ end
+
it "propagates an exception raised by #close that is not a StandardError" do
- lambda do
+ -> do
IO.open(@fd, "w") do |io|
IOSpecs.io_mock(io, :close) do
super()
@@ -46,12 +59,12 @@ describe "IO.open" do
raise Exception
end
end
- end.should raise_error(Exception)
+ end.should.raise(Exception)
ScratchPad.recorded.should == :called
end
it "propagates an exception raised by #close that is a StandardError" do
- lambda do
+ -> do
IO.open(@fd, "w") do |io|
IOSpecs.io_mock(io, :close) do
super()
@@ -59,11 +72,11 @@ describe "IO.open" do
raise StandardError
end
end
- end.should raise_error(StandardError)
+ end.should.raise(StandardError)
ScratchPad.recorded.should == :called
end
- it "does not propagate a IOError with 'closed stream' message raised by #close" do
+ it "does not propagate an IOError with 'closed stream' message raised by #close" do
IO.open(@fd, "w") do |io|
IOSpecs.io_mock(io, :close) do
super()
@@ -74,7 +87,7 @@ describe "IO.open" do
ScratchPad.recorded.should == :called
end
- it "does not set last error when a IOError with 'closed stream' raised by #close" do
+ it "does not set last error when an IOError with 'closed stream' raised by #close" do
IO.open(@fd, "w") do |io|
IOSpecs.io_mock(io, :close) do
super()
diff --git a/spec/ruby/core/io/output_spec.rb b/spec/ruby/core/io/output_spec.rb
index 2d52315430..0decf8c95b 100644
--- a/spec/ruby/core/io/output_spec.rb
+++ b/spec/ruby/core/io/output_spec.rb
@@ -1,26 +1,26 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "IO#<<" do
it "writes an object to the IO stream" do
- lambda {
+ -> {
$stderr << "Oh noes, an error!"
}.should output_to_fd("Oh noes, an error!", $stderr)
end
it "calls #to_s on the object to print it" do
- lambda {
+ -> {
$stderr << 1337
}.should output_to_fd("1337", $stderr)
end
it "raises an error if the stream is closed" do
io = IOSpecs.closed_io
- lambda { io << "test" }.should raise_error(IOError)
+ -> { io << "test" }.should.raise(IOError)
end
it "returns self" do
- lambda {
+ -> {
($stderr << "to_stderr").should == $stderr
}.should output(nil, "to_stderr")
end
diff --git a/spec/ruby/core/io/path_spec.rb b/spec/ruby/core/io/path_spec.rb
new file mode 100644
index 0000000000..798adb2163
--- /dev/null
+++ b/spec/ruby/core/io/path_spec.rb
@@ -0,0 +1,12 @@
+require_relative '../../spec_helper'
+
+describe "IO#path" do
+ it "returns the path of the file associated with the IO object" do
+ path = tmp("io_path.txt")
+ File.open(path, "w") do |file|
+ IO.new(file.fileno, path: file.path, autoclose: false).path.should == file.path
+ end
+ ensure
+ File.unlink(path)
+ end
+end
diff --git a/spec/ruby/core/io/pid_spec.rb b/spec/ruby/core/io/pid_spec.rb
index a4f6bbfcf8..04956887ff 100644
--- a/spec/ruby/core/io/pid_spec.rb
+++ b/spec/ruby/core/io/pid_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes.rb', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "IO#pid" do
before :each do
@@ -25,11 +25,11 @@ describe "IO#pid" do
end
it "returns the ID of a process associated with stream" do
- @io.pid.should_not be_nil
+ @io.pid.should_not == nil
end
it "raises an IOError on closed stream" do
@io.close
- lambda { @io.pid }.should raise_error(IOError)
+ -> { @io.pid }.should.raise(IOError)
end
end
diff --git a/spec/ruby/core/io/pipe_spec.rb b/spec/ruby/core/io/pipe_spec.rb
index b4984fdeb7..9f1b01a5cd 100644
--- a/spec/ruby/core/io/pipe_spec.rb
+++ b/spec/ruby/core/io/pipe_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "IO.pipe" do
after :each do
@@ -16,14 +16,25 @@ describe "IO.pipe" do
it "returns two IO objects" do
@r, @w = IO.pipe
- @r.should be_kind_of(IO)
- @w.should be_kind_of(IO)
+ @r.should.is_a?(IO)
+ @w.should.is_a?(IO)
end
it "returns instances of a subclass when called on a subclass" do
@r, @w = IOSpecs::SubIO.pipe
- @r.should be_an_instance_of(IOSpecs::SubIO)
- @w.should be_an_instance_of(IOSpecs::SubIO)
+ @r.should.instance_of?(IOSpecs::SubIO)
+ @w.should.instance_of?(IOSpecs::SubIO)
+ end
+
+ it "does not use IO.new method to create pipes and allows its overriding" do
+ ScratchPad.record []
+
+ # so redefined .new is not called, but original #initialize is
+ @r, @w = IOSpecs::SubIOWithRedefinedNew.pipe
+ ScratchPad.recorded.should == [:call_original_initialize, :call_original_initialize] # called 2 times - for each pipe (r and w)
+
+ @r.should.instance_of?(IOSpecs::SubIOWithRedefinedNew)
+ @w.should.instance_of?(IOSpecs::SubIOWithRedefinedNew)
end
end
@@ -31,8 +42,8 @@ describe "IO.pipe" do
describe "passed a block" do
it "yields two IO objects" do
IO.pipe do |r, w|
- r.should be_kind_of(IO)
- w.should be_kind_of(IO)
+ r.should.is_a?(IO)
+ w.should.is_a?(IO)
end
end
@@ -44,21 +55,21 @@ describe "IO.pipe" do
r, w = IO.pipe do |_r, _w|
[_r, _w]
end
- r.closed?.should == true
- w.closed?.should == true
+ r.should.closed?
+ w.should.closed?
end
it "closes both IO objects when the block raises" do
r = w = nil
- lambda do
+ -> do
IO.pipe do |_r, _w|
r = _r
w = _w
raise RuntimeError
end
- end.should raise_error(RuntimeError)
- r.closed?.should == true
- w.closed?.should == true
+ end.should.raise(RuntimeError)
+ r.should.closed?
+ w.should.closed?
end
it "allows IO objects to be closed within the block" do
@@ -67,8 +78,8 @@ describe "IO.pipe" do
_w.close
[_r, _w]
end
- r.closed?.should == true
- w.closed?.should == true
+ r.should.closed?
+ w.should.closed?
end
end
end
@@ -89,7 +100,7 @@ describe "IO.pipe" do
IO.pipe do |r, w|
r.external_encoding.should == Encoding::ISO_8859_1
- r.internal_encoding.should be_nil
+ r.internal_encoding.should == nil
end
end
@@ -109,14 +120,14 @@ describe "IO.pipe" do
IO.pipe do |r, w|
r.external_encoding.should == Encoding::UTF_8
- r.internal_encoding.should be_nil
+ r.internal_encoding.should == nil
end
end
it "sets the external encoding of the read end when passed an Encoding argument" do
IO.pipe(Encoding::UTF_8) do |r, w|
r.external_encoding.should == Encoding::UTF_8
- r.internal_encoding.should be_nil
+ r.internal_encoding.should == nil
end
end
@@ -130,14 +141,14 @@ describe "IO.pipe" do
it "sets the external encoding of the read end when passed the name of an Encoding" do
IO.pipe("UTF-8") do |r, w|
r.external_encoding.should == Encoding::UTF_8
- r.internal_encoding.should be_nil
+ r.internal_encoding.should == nil
end
end
it "accepts 'bom|' prefix for external encoding" do
IO.pipe("BOM|UTF-8") do |r, w|
r.external_encoding.should == Encoding::UTF_8
- r.internal_encoding.should be_nil
+ r.internal_encoding.should == nil
end
end
@@ -179,7 +190,7 @@ describe "IO.pipe" do
it "calls #to_hash to convert an options argument" do
options = mock("io pipe encoding options")
options.should_receive(:to_hash).and_return({ invalid: :replace })
- IO.pipe("UTF-8", "ISO-8859-1", options) { |r, w| }
+ IO.pipe("UTF-8", "ISO-8859-1", **options) { |r, w| }
end
it "calls #to_str to convert the first argument to a String" do
@@ -202,13 +213,13 @@ describe "IO.pipe" do
it "sets no external encoding for the write end" do
IO.pipe(Encoding::UTF_8) do |r, w|
- w.external_encoding.should be_nil
+ w.external_encoding.should == nil
end
end
it "sets no internal encoding for the write end" do
IO.pipe(Encoding::UTF_8) do |r, w|
- w.external_encoding.should be_nil
+ w.external_encoding.should == nil
end
end
end
diff --git a/spec/ruby/core/io/popen_spec.rb b/spec/ruby/core/io/popen_spec.rb
index 808dff7260..b5747bf255 100644
--- a/spec/ruby/core/io/popen_spec.rb
+++ b/spec/ruby/core/io/popen_spec.rb
@@ -1,42 +1,39 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative '../process/fixtures/common'
describe "IO.popen" do
+ ProcessSpecs.use_system_ruby(self)
+
before :each do
+ @fname = tmp("IO_popen_spec")
@io = nil
+ @var = "$FOO"
+ platform_is :windows do
+ @var = "%FOO%"
+ end
end
after :each do
- @io.close if @io
+ @io.close if @io and !@io.closed?
+ rm_r @fname
end
it "returns an open IO" do
@io = IO.popen(ruby_cmd('exit'), "r")
- @io.closed?.should be_false
+ @io.closed?.should == false
end
it "reads a read-only pipe" do
- @io = IO.popen(ruby_cmd('puts "foo"'), "r")
+ @io = IO.popen('echo foo', "r")
@io.read.should == "foo\n"
end
it "raises IOError when writing a read-only pipe" do
- @io = IO.popen(ruby_cmd('puts "foo"'), "r")
- lambda { @io.write('bar') }.should raise_error(IOError)
+ @io = IO.popen('echo foo', "r")
+ -> { @io.write('bar') }.should.raise(IOError)
@io.read.should == "foo\n"
end
-end
-
-describe "IO.popen" do
- before :each do
- @fname = tmp("IO_popen_spec")
- @io = nil
- end
-
- after :each do
- @io.close if @io and !@io.closed?
- rm_r @fname
- end
it "sees an infinitely looping subprocess exit when read pipe is closed" do
io = IO.popen ruby_cmd('r = loop{puts "y"; 0} rescue 1; exit r'), 'r'
@@ -55,7 +52,7 @@ describe "IO.popen" do
it "raises IOError when reading a write-only pipe" do
@io = IO.popen(ruby_cmd('IO.copy_stream(STDIN,STDOUT)'), "w")
- lambda { @io.read }.should raise_error(IOError)
+ -> { @io.read }.should.raise(IOError)
end
it "reads and writes a read/write pipe" do
@@ -80,16 +77,16 @@ describe "IO.popen" do
Process.kill "KILL", pid
@io.close
platform_is_not :windows do
- $?.signaled?.should == true
+ $?.should.signaled?
end
platform_is :windows do
- $?.exited?.should == true
+ $?.should.exited?
end
end
it "returns an instance of a subclass when called on a subclass" do
@io = IOSpecs::SubIO.popen(ruby_cmd('exit'), "r")
- @io.should be_an_instance_of(IOSpecs::SubIO)
+ @io.should.instance_of?(IOSpecs::SubIO)
end
it "coerces mode argument with #to_str" do
@@ -97,38 +94,44 @@ describe "IO.popen" do
mode.should_receive(:to_str).and_return("r")
@io = IO.popen(ruby_cmd('exit 0'), mode)
end
-end
-describe "IO.popen" do
- before :each do
- @io = nil
+ it "accepts a path using the chdir: keyword argument" do
+ path = File.dirname(@fname)
+
+ @io = IO.popen(ruby_cmd("puts Dir.pwd"), "r", chdir: path)
+ @io.read.chomp.should == path
end
- after :each do
- @io.close if @io
+ it "accepts a path using the chdir: keyword argument and a coercible path" do
+ path = File.dirname(@fname)
+ object = mock("path")
+ object.should_receive(:to_path).and_return(path)
+
+ @io = IO.popen(ruby_cmd("puts Dir.pwd"), "r", chdir: object)
+ @io.read.chomp.should == path
end
describe "with a block" do
it "yields an open IO to the block" do
IO.popen(ruby_cmd('exit'), "r") do |io|
- io.closed?.should be_false
+ io.closed?.should == false
end
end
it "yields an instance of a subclass when called on a subclass" do
IOSpecs::SubIO.popen(ruby_cmd('exit'), "r") do |io|
- io.should be_an_instance_of(IOSpecs::SubIO)
+ io.should.instance_of?(IOSpecs::SubIO)
end
end
it "closes the IO after yielding" do
io = IO.popen(ruby_cmd('exit'), "r") { |_io| _io }
- io.closed?.should be_true
+ io.closed?.should == true
end
it "allows the IO to be closed inside the block" do
io = IO.popen(ruby_cmd('exit'), 'r') { |_io| _io.close; _io }
- io.closed?.should be_true
+ io.closed?.should == true
end
it "returns the value of the block" do
@@ -136,7 +139,7 @@ describe "IO.popen" do
end
end
- with_feature :fork do
+ platform_is_not :windows do
it "starts returns a forked process if the command is -" do
io = IO.popen("-")
@@ -153,33 +156,31 @@ describe "IO.popen" do
end
end
- with_feature :encoding do
- it "has the given external encoding" do
- @io = IO.popen(ruby_cmd('exit'), external_encoding: Encoding::EUC_JP)
- @io.external_encoding.should == Encoding::EUC_JP
- end
+ it "has the given external encoding" do
+ @io = IO.popen(ruby_cmd('exit'), external_encoding: Encoding::EUC_JP)
+ @io.external_encoding.should == Encoding::EUC_JP
+ end
- it "has the given internal encoding" do
- @io = IO.popen(ruby_cmd('exit'), internal_encoding: Encoding::EUC_JP)
- @io.internal_encoding.should == Encoding::EUC_JP
- end
+ it "has the given internal encoding" do
+ @io = IO.popen(ruby_cmd('exit'), internal_encoding: Encoding::EUC_JP)
+ @io.internal_encoding.should == Encoding::EUC_JP
+ end
- it "sets the internal encoding to nil if it's the same as the external encoding" do
- @io = IO.popen(ruby_cmd('exit'), external_encoding: Encoding::EUC_JP,
- internal_encoding: Encoding::EUC_JP)
- @io.internal_encoding.should be_nil
- end
+ it "sets the internal encoding to nil if it's the same as the external encoding" do
+ @io = IO.popen(ruby_cmd('exit'), external_encoding: Encoding::EUC_JP,
+ internal_encoding: Encoding::EUC_JP)
+ @io.internal_encoding.should == nil
end
context "with a leading ENV Hash" do
it "accepts a single String command" do
- IO.popen({"FOO" => "bar"}, ruby_cmd('puts ENV["FOO"]')) do |io|
+ IO.popen({"FOO" => "bar"}, "echo #{@var}") do |io|
io.read.should == "bar\n"
end
end
it "accepts a single String command, and an IO mode" do
- IO.popen({"FOO" => "bar"}, ruby_cmd('puts ENV["FOO"]'), "r") do |io|
+ IO.popen({"FOO" => "bar"}, "echo #{@var}", "r") do |io|
io.read.should == "bar\n"
end
end
diff --git a/spec/ruby/core/io/pos_spec.rb b/spec/ruby/core/io/pos_spec.rb
index 300925a284..bbe25ce97b 100644
--- a/spec/ruby/core/io/pos_spec.rb
+++ b/spec/ruby/core/io/pos_spec.rb
@@ -1,12 +1,41 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/pos', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/pos'
describe "IO#pos" do
- it_behaves_like :io_pos, :pos
+ before :each do
+ @fname = tmp('test.txt')
+ File.open(@fname, 'w') { |f| f.write "123" }
+ end
+
+ after :each do
+ rm_r @fname
+ end
+
+ it "gets the offset" do
+ File.open @fname do |f|
+ f.pos.should == 0
+ f.read 1
+ f.pos.should == 1
+ f.read 2
+ f.pos.should == 3
+ end
+ end
+
+ it "raises IOError on closed stream" do
+ -> { IOSpecs.closed_io.pos }.should.raise(IOError)
+ end
+
+ it "resets #eof?" do
+ open @fname do |io|
+ io.read 1
+ io.read 1
+ io.pos
+ io.should_not.eof?
+ end
+ end
end
describe "IO#pos=" do
it_behaves_like :io_set_pos, :pos=
end
-
diff --git a/spec/ruby/core/io/pread_spec.rb b/spec/ruby/core/io/pread_spec.rb
new file mode 100644
index 0000000000..cfb8dc4c68
--- /dev/null
+++ b/spec/ruby/core/io/pread_spec.rb
@@ -0,0 +1,138 @@
+# -*- encoding: utf-8 -*-
+require_relative '../../spec_helper'
+
+describe "IO#pread" do
+ before :each do
+ @fname = tmp("io_pread.txt")
+ @contents = "1234567890"
+ touch(@fname) { |f| f.write @contents }
+ @file = File.open(@fname, "r+")
+ end
+
+ after :each do
+ @file.close
+ rm_r @fname
+ end
+
+ it "accepts a length, and an offset" do
+ @file.pread(4, 0).should == "1234"
+ @file.pread(3, 4).should == "567"
+ end
+
+ it "accepts a length, an offset, and an output buffer" do
+ buffer = +"foo"
+ @file.pread(3, 4, buffer).should.equal?(buffer)
+ buffer.should == "567"
+ end
+
+ it "shrinks the buffer in case of less bytes read" do
+ buffer = +"foo"
+ @file.pread(1, 0, buffer)
+ buffer.should == "1"
+ end
+
+ it "grows the buffer in case of more bytes read" do
+ buffer = +"foo"
+ @file.pread(5, 0, buffer)
+ buffer.should == "12345"
+ end
+
+ it "preserves the encoding of the given buffer" do
+ buffer = ''.encode(Encoding::ISO_8859_1)
+ @file.pread(10, 0, buffer)
+
+ buffer.encoding.should == Encoding::ISO_8859_1
+ end
+
+ it "does not advance the file pointer" do
+ @file.pread(4, 0).should == "1234"
+ @file.read.should == "1234567890"
+ end
+
+ it "ignores the current offset" do
+ @file.pos = 3
+ @file.pread(4, 0).should == "1234"
+ end
+
+ it "returns an empty string for maxlen = 0" do
+ @file.pread(0, 4).should == ""
+ end
+
+ it "returns a buffer for maxlen = 0 when buffer specified" do
+ buffer = +"foo"
+ @file.pread(0, 4, buffer).should.equal?(buffer)
+ buffer.should == "foo"
+ end
+
+ it "ignores the offset for maxlen = 0, even if it is out of file bounds" do
+ @file.pread(0, 400).should == ""
+ end
+
+ it "does not reset the buffer when reading with maxlen = 0" do
+ buffer = +"foo"
+ @file.pread(0, 4, buffer)
+ buffer.should == "foo"
+
+ @file.pread(0, 400, buffer)
+ buffer.should == "foo"
+ end
+
+ it "converts maxlen to Integer using #to_int" do
+ maxlen = mock('maxlen')
+ maxlen.should_receive(:to_int).and_return(4)
+ @file.pread(maxlen, 0).should == "1234"
+ end
+
+ it "converts offset to Integer using #to_int" do
+ offset = mock('offset')
+ offset.should_receive(:to_int).and_return(0)
+ @file.pread(4, offset).should == "1234"
+ end
+
+ it "converts a buffer to String using to_str" do
+ buffer = mock('buffer')
+ buffer.should_receive(:to_str).at_least(1).and_return(+"foo")
+ @file.pread(4, 0, buffer)
+ buffer.should_not.is_a?(String)
+ buffer.to_str.should == "1234"
+ end
+
+ it "raises TypeError if maxlen is not an Integer and cannot be coerced into Integer" do
+ maxlen = Object.new
+ -> { @file.pread(maxlen, 0) }.should.raise(TypeError, 'no implicit conversion of Object into Integer')
+ end
+
+ it "raises TypeError if offset is not an Integer and cannot be coerced into Integer" do
+ offset = Object.new
+ -> { @file.pread(4, offset) }.should.raise(TypeError, 'no implicit conversion of Object into Integer')
+ end
+
+ it "raises ArgumentError for negative values of maxlen" do
+ -> { @file.pread(-4, 0) }.should.raise(ArgumentError, 'negative string size (or size too big)')
+ end
+
+ it "raised Errno::EINVAL for negative values of offset" do
+ -> { @file.pread(4, -1) }.should.raise(Errno::EINVAL, /Invalid argument/)
+ end
+
+ it "raises TypeError if the buffer is not a String and cannot be coerced into String" do
+ buffer = Object.new
+ -> { @file.pread(4, 0, buffer) }.should.raise(TypeError, 'no implicit conversion of Object into String')
+ end
+
+ it "raises EOFError if end-of-file is reached" do
+ -> { @file.pread(1, 10) }.should.raise(EOFError)
+ end
+
+ it "raises IOError when file is not open in read mode" do
+ File.open(@fname, "w") do |file|
+ -> { file.pread(1, 1) }.should.raise(IOError)
+ end
+ end
+
+ it "raises IOError when file is closed" do
+ file = File.open(@fname, "r+")
+ file.close
+ -> { file.pread(1, 1) }.should.raise(IOError)
+ end
+end
diff --git a/spec/ruby/core/io/print_spec.rb b/spec/ruby/core/io/print_spec.rb
index e852757385..065cb3b8cb 100644
--- a/spec/ruby/core/io/print_spec.rb
+++ b/spec/ruby/core/io/print_spec.rb
@@ -1,18 +1,29 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
-describe IO, "#print" do
+describe "IO#print" do
before :each do
- @old_separator = $\
- $\ = '->'
+ @old_record_separator = $\
+ @old_field_separator = $,
+ suppress_warning {
+ $\ = '->'
+ $, = '^^'
+ }
@name = tmp("io_print")
end
after :each do
- $\ = @old_separator
+ suppress_warning {
+ $\ = @old_record_separator
+ $, = @old_field_separator
+ }
rm_r @name
end
+ it "returns nil" do
+ touch(@name) { |f| f.print.should == nil }
+ end
+
it "writes $_.to_s followed by $\\ (if any) to the stream if no arguments given" do
o = mock('o')
o.should_receive(:to_s).and_return("mockmockmock")
@@ -38,17 +49,18 @@ describe IO, "#print" do
IO.read(@name).should == "hello#{$\}"
end
- it "writes each obj.to_s to the stream and appends $\\ (if any) given multiple objects" do
+ it "writes each obj.to_s to the stream separated by $, (if any) and appends $\\ (if any) given multiple objects" do
o, o2 = Object.new, Object.new
def o.to_s(); 'o'; end
def o2.to_s(); 'o2'; end
- touch(@name) { |f| f.print(o, o2) }
- IO.read(@name).should == "#{o.to_s}#{o2.to_s}#{$\}"
+ suppress_warning {
+ touch(@name) { |f| f.print(o, o2) }
+ }
+ IO.read(@name).should == "#{o.to_s}#{$,}#{o2.to_s}#{$\}"
end
it "raises IOError on closed stream" do
- lambda { IOSpecs.closed_io.print("stuff") }.should raise_error(IOError)
+ -> { IOSpecs.closed_io.print("stuff") }.should.raise(IOError)
end
end
-
diff --git a/spec/ruby/core/io/printf_spec.rb b/spec/ruby/core/io/printf_spec.rb
index 34be4c8e79..d5519bdaa3 100644
--- a/spec/ruby/core/io/printf_spec.rb
+++ b/spec/ruby/core/io/printf_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "IO#printf" do
before :each do
@@ -27,6 +27,6 @@ describe "IO#printf" do
end
it "raises IOError on closed stream" do
- lambda { IOSpecs.closed_io.printf("stuff") }.should raise_error(IOError)
+ -> { IOSpecs.closed_io.printf("stuff") }.should.raise(IOError)
end
end
diff --git a/spec/ruby/core/io/putc_spec.rb b/spec/ruby/core/io/putc_spec.rb
index 9803d0c1a1..73473ad821 100644
--- a/spec/ruby/core/io/putc_spec.rb
+++ b/spec/ruby/core/io/putc_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/io/putc', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../../shared/io/putc'
describe "IO#putc" do
before :each do
diff --git a/spec/ruby/core/io/puts_spec.rb b/spec/ruby/core/io/puts_spec.rb
index 51240eed73..df526ea56a 100644
--- a/spec/ruby/core/io/puts_spec.rb
+++ b/spec/ruby/core/io/puts_spec.rb
@@ -1,12 +1,12 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "IO#puts" do
before :each do
@before_separator = $/
@name = tmp("io_puts.txt")
@io = new_io @name
- ScratchPad.record ""
+ ScratchPad.record(+"")
def @io.write(str)
ScratchPad << str
end
@@ -16,7 +16,7 @@ describe "IO#puts" do
ScratchPad.clear
@io.close if @io
rm_r @name
- $/ = @before_separator
+ suppress_warning {$/ = @before_separator}
end
it "writes just a newline when given no args" do
@@ -25,7 +25,7 @@ describe "IO#puts" do
end
it "writes just a newline when given just a newline" do
- lambda { $stdout.puts "\n" }.should output_to_fd("\n", STDOUT)
+ -> { $stdout.puts "\n" }.should output_to_fd("\n", $stdout)
end
it "writes empty string with a newline when given nil as an arg" do
@@ -33,7 +33,7 @@ describe "IO#puts" do
ScratchPad.recorded.should == "\n"
end
- it "writes empty string with a newline when when given nil as multiple args" do
+ it "writes empty string with a newline when given nil as multiple args" do
@io.puts(nil, nil).should == nil
ScratchPad.recorded.should == "\n\n"
end
@@ -105,37 +105,35 @@ describe "IO#puts" do
end
it "ignores the $/ separator global" do
- $/ = ":"
+ suppress_warning {$/ = ":"}
@io.puts(5).should == nil
ScratchPad.recorded.should == "5\n"
end
it "raises IOError on closed stream" do
- lambda { IOSpecs.closed_io.puts("stuff") }.should raise_error(IOError)
+ -> { IOSpecs.closed_io.puts("stuff") }.should.raise(IOError)
end
- with_feature :encoding do
- it "writes crlf when IO is opened with newline: :crlf" do
- File.open(@name, 'wt', newline: :crlf) do |file|
- file.puts
- end
- File.binread(@name).should == "\r\n"
+ it "writes crlf when IO is opened with newline: :crlf" do
+ File.open(@name, 'wt', newline: :crlf) do |file|
+ file.puts
end
+ File.binread(@name).should == "\r\n"
+ end
- it "writes cr when IO is opened with newline: :cr" do
- File.open(@name, 'wt', newline: :cr) do |file|
- file.puts
- end
- File.binread(@name).should == "\r"
+ it "writes cr when IO is opened with newline: :cr" do
+ File.open(@name, 'wt', newline: :cr) do |file|
+ file.puts
end
+ File.binread(@name).should == "\r"
+ end
- platform_is_not :windows do # https://bugs.ruby-lang.org/issues/12436
- it "writes lf when IO is opened with newline: :lf" do
- File.open(@name, 'wt', newline: :lf) do |file|
- file.puts
- end
- File.binread(@name).should == "\n"
+ platform_is_not :windows do # https://bugs.ruby-lang.org/issues/12436
+ it "writes lf when IO is opened with newline: :lf" do
+ File.open(@name, 'wt', newline: :lf) do |file|
+ file.puts
end
+ File.binread(@name).should == "\n"
end
end
end
diff --git a/spec/ruby/core/io/pwrite_spec.rb b/spec/ruby/core/io/pwrite_spec.rb
new file mode 100644
index 0000000000..c318d551bc
--- /dev/null
+++ b/spec/ruby/core/io/pwrite_spec.rb
@@ -0,0 +1,67 @@
+# -*- encoding: utf-8 -*-
+require_relative '../../spec_helper'
+
+describe "IO#pwrite" do
+ before :each do
+ @fname = tmp("io_pwrite.txt")
+ @file = File.open(@fname, "w+")
+ end
+
+ after :each do
+ @file.close
+ rm_r @fname
+ end
+
+ it "returns the number of bytes written" do
+ @file.pwrite("foo", 0).should == 3
+ end
+
+ it "accepts a string and an offset" do
+ @file.pwrite("foo", 2)
+ @file.pread(3, 2).should == "foo"
+ end
+
+ it "does not advance the pointer in the file" do
+ @file.pwrite("bar", 3)
+ @file.write("foo")
+ @file.pread(6, 0).should == "foobar"
+ end
+
+ it "calls #to_s on the object to be written" do
+ object = mock("to_s")
+ object.should_receive(:to_s).and_return("foo")
+ @file.pwrite(object, 0)
+ @file.pread(3, 0).should == "foo"
+ end
+
+ it "calls #to_int on the offset" do
+ offset = mock("to_int")
+ offset.should_receive(:to_int).and_return(2)
+ @file.pwrite("foo", offset)
+ @file.pread(3, 2).should == "foo"
+ end
+
+ it "raises IOError when file is not open in write mode" do
+ File.open(@fname, "r") do |file|
+ -> { file.pwrite("foo", 1) }.should.raise(IOError, "not opened for writing")
+ end
+ end
+
+ it "raises IOError when file is closed" do
+ file = File.open(@fname, "w+")
+ file.close
+ -> { file.pwrite("foo", 1) }.should.raise(IOError, "closed stream")
+ end
+
+ it "raises a NoMethodError if object does not respond to #to_s" do
+ -> {
+ @file.pwrite(BasicObject.new, 0)
+ }.should.raise(NoMethodError, /undefined method [`']to_s'/)
+ end
+
+ it "raises a TypeError if the offset cannot be converted to an Integer" do
+ -> {
+ @file.pwrite("foo", Object.new)
+ }.should.raise(TypeError, "no implicit conversion of Object into Integer")
+ end
+end
diff --git a/spec/ruby/core/io/read_nonblock_spec.rb b/spec/ruby/core/io/read_nonblock_spec.rb
index 2b314987bc..511cf03263 100644
--- a/spec/ruby/core/io/read_nonblock_spec.rb
+++ b/spec/ruby/core/io/read_nonblock_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "IO#read_nonblock" do
before :each do
@@ -12,42 +12,70 @@ describe "IO#read_nonblock" do
end
it "raises an exception extending IO::WaitReadable when there is no data" do
- lambda { @read.read_nonblock(5) }.should raise_error(IO::WaitReadable) { |e|
+ -> { @read.read_nonblock(5) }.should.raise(IO::WaitReadable) { |e|
platform_is_not :windows do
- e.should be_kind_of(Errno::EAGAIN)
+ e.should.is_a?(Errno::EAGAIN)
end
platform_is :windows do
- e.should be_kind_of(Errno::EWOULDBLOCK)
+ e.should.is_a?(Errno::EWOULDBLOCK)
end
}
end
- ruby_version_is "2.3" do
- context "when exception option is set to false" do
- context "when there is no data" do
- it "returns :wait_readable" do
- @read.read_nonblock(5, exception: false).should == :wait_readable
- end
+ context "when exception option is set to false" do
+ context "when there is no data" do
+ it "returns :wait_readable" do
+ @read.read_nonblock(5, exception: false).should == :wait_readable
end
+ end
- context "when the end is reached" do
- it "returns nil" do
- @write << "hello"
- @write.close
+ context "when the end is reached" do
+ it "returns nil" do
+ @write << "hello"
+ @write.close
- @read.read_nonblock(5)
+ @read.read_nonblock(5)
- @read.read_nonblock(5, exception: false).should be_nil
- end
+ @read.read_nonblock(5, exception: false).should == nil
end
end
end
+ platform_is_not :windows do
+ it 'sets the IO in nonblock mode' do
+ require 'io/nonblock'
+ @write.write "abc"
+ @read.read_nonblock(1).should == "a"
+ @read.should.nonblock?
+ end
+ end
+
it "returns at most the number of bytes requested" do
@write << "hello"
@read.read_nonblock(4).should == "hell"
end
+ it "reads after ungetc with data in the buffer" do
+ @write.write("foobar")
+ @read.set_encoding(
+ 'utf-8', universal_newline: false
+ )
+ c = @read.getc
+ @read.ungetc(c)
+ @read.read_nonblock(3).should == "foo"
+ @read.read_nonblock(3).should == "bar"
+ end
+
+ it "raises an exception after ungetc with data in the buffer and character conversion enabled" do
+ @write.write("foobar")
+ @read.set_encoding(
+ 'utf-8', universal_newline: true
+ )
+ c = @read.getc
+ @read.ungetc(c)
+ -> { @read.read_nonblock(3).should == "foo" }.should.raise(IOError)
+ end
+
it "returns less data if that is all that is available" do
@write << "hello"
@read.read_nonblock(10).should == "hello"
@@ -63,15 +91,41 @@ describe "IO#read_nonblock" do
@read.read_nonblock(1).should == "1"
end
+ it "raises ArgumentError when length is less than 0" do
+ -> { @read.read_nonblock(-1) }.should.raise(ArgumentError)
+ end
+
it "reads into the passed buffer" do
- buffer = ""
+ buffer = +""
@write.write("1")
@read.read_nonblock(1, buffer)
buffer.should == "1"
end
+ it "returns the passed buffer" do
+ buffer = +""
+ @write.write("1")
+ output = @read.read_nonblock(1, buffer)
+ output.should.equal?(buffer)
+ end
+
+ it "discards the existing buffer content upon successful read" do
+ buffer = +"existing content"
+ @write.write("hello world")
+ @write.close
+ @read.read_nonblock(11, buffer)
+ buffer.should == "hello world"
+ end
+
+ it "discards the existing buffer content upon error" do
+ buffer = +"existing content"
+ @write.close
+ -> { @read.read_nonblock(1, buffer) }.should.raise(EOFError)
+ buffer.should.empty?
+ end
+
it "raises IOError on closed stream" do
- lambda { IOSpecs.closed_io.read_nonblock(5) }.should raise_error(IOError)
+ -> { IOSpecs.closed_io.read_nonblock(5) }.should.raise(IOError)
end
it "raises EOFError when the end is reached" do
@@ -80,6 +134,15 @@ describe "IO#read_nonblock" do
@read.read_nonblock(5)
- lambda { @read.read_nonblock(5) }.should raise_error(EOFError)
+ -> { @read.read_nonblock(5) }.should.raise(EOFError)
+ end
+
+ it "preserves the encoding of the given buffer" do
+ buffer = ''.encode(Encoding::ISO_8859_1)
+ @write.write("abc")
+ @write.close
+ @read.read_nonblock(10, buffer)
+
+ buffer.encoding.should == Encoding::ISO_8859_1
end
end
diff --git a/spec/ruby/core/io/read_spec.rb b/spec/ruby/core/io/read_spec.rb
index 223e3cde06..5be969e280 100644
--- a/spec/ruby/core/io/read_spec.rb
+++ b/spec/ruby/core/io/read_spec.rb
@@ -1,6 +1,6 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "IO.read" do
before :each do
@@ -23,32 +23,63 @@ describe "IO.read" do
IO.read(p)
end
+ # https://bugs.ruby-lang.org/issues/19354
+ it "accepts options as keyword arguments" do
+ IO.read(@fname, 3, 0, mode: "r+").should == @contents[0, 3]
+
+ -> {
+ IO.read(@fname, 3, 0, {mode: "r+"})
+ }.should.raise(ArgumentError, /wrong number of arguments/)
+ end
+
it "accepts an empty options Hash" do
- IO.read(@fname, {}).should == @contents
+ IO.read(@fname, **{}).should == @contents
+ end
+
+ it "accepts a length, and empty options Hash" do
+ IO.read(@fname, 3, **{}).should == @contents[0, 3]
end
it "accepts a length, offset, and empty options Hash" do
- IO.read(@fname, 3, 0, {}).should == @contents[0, 3]
+ IO.read(@fname, 3, 0, **{}).should == @contents[0, 3]
end
it "raises an IOError if the options Hash specifies write mode" do
- lambda { IO.read(@fname, 3, 0, {mode: "w"}) }.should raise_error(IOError)
+ -> { IO.read(@fname, 3, 0, mode: "w") }.should.raise(IOError)
end
it "raises an IOError if the options Hash specifies append only mode" do
- lambda { IO.read(@fname, {mode: "a"}) }.should raise_error(IOError)
+ -> { IO.read(@fname, mode: "a") }.should.raise(IOError)
end
it "reads the file if the options Hash includes read mode" do
- IO.read(@fname, {mode: "r"}).should == @contents
+ IO.read(@fname, mode: "r").should == @contents
end
it "reads the file if the options Hash includes read/write mode" do
- IO.read(@fname, {mode: "r+"}).should == @contents
+ IO.read(@fname, mode: "r+").should == @contents
end
it "reads the file if the options Hash includes read/write append mode" do
- IO.read(@fname, {mode: "a+"}).should == @contents
+ IO.read(@fname, mode: "a+").should == @contents
+ end
+
+ platform_is_not :windows do
+ end
+
+ it "disregards other options if :open_args is given" do
+ string = IO.read(@fname,mode: "w", encoding: Encoding::UTF_32LE, open_args: ["r", encoding: Encoding::UTF_8])
+ string.encoding.should == Encoding::UTF_8
+ end
+
+ it "doesn't require mode to be specified in :open_args" do
+ string = IO.read(@fname, nil, 0, open_args: [{encoding: Encoding::US_ASCII}])
+ string.encoding.should == Encoding::US_ASCII
+ end
+
+ it "doesn't require mode to be specified in :open_args even if flags option passed" do
+ string = IO.read(@fname, nil, 0, open_args: [{encoding: Encoding::US_ASCII, flags: File::CREAT}])
+ string.encoding.should == Encoding::US_ASCII
end
it "treats second nil argument as no length limit" do
@@ -73,86 +104,125 @@ describe "IO.read" do
IO.read(@fname, 1, 10).should == nil
end
+ it "returns an empty string when reading zero bytes" do
+ IO.read(@fname, 0).should == ''
+ end
+
+ it "returns a String in BINARY when passed a size" do
+ IO.read(@fname, 1).encoding.should == Encoding::BINARY
+ IO.read(@fname, 0).encoding.should == Encoding::BINARY
+ end
+
it "raises an Errno::ENOENT when the requested file does not exist" do
rm_r @fname
- lambda { IO.read @fname }.should raise_error(Errno::ENOENT)
+ -> { IO.read @fname }.should.raise(Errno::ENOENT)
end
it "raises a TypeError when not passed a String type" do
- lambda { IO.read nil }.should raise_error(TypeError)
+ -> { IO.read nil }.should.raise(TypeError)
end
it "raises an ArgumentError when not passed a valid length" do
- lambda { IO.read @fname, -1 }.should raise_error(ArgumentError)
+ -> { IO.read @fname, -1 }.should.raise(ArgumentError)
end
- it "raises an Errno::EINVAL when not passed a valid offset" do
- lambda { IO.read @fname, 0, -1 }.should raise_error(Errno::EINVAL)
- lambda { IO.read @fname, -1, -1 }.should raise_error(Errno::EINVAL)
+ it "raises an ArgumentError when not passed a valid offset" do
+ -> { IO.read @fname, 0, -1 }.should.raise(ArgumentError)
+ -> { IO.read @fname, -1, -1 }.should.raise(ArgumentError)
end
- with_feature :encoding do
- it "uses the external encoding specified via the :external_encoding option" do
- str = IO.read(@fname, external_encoding: Encoding::ISO_8859_1)
- str.encoding.should == Encoding::ISO_8859_1
- end
+ it "uses the external encoding specified via the :external_encoding option" do
+ str = IO.read(@fname, external_encoding: Encoding::ISO_8859_1)
+ str.encoding.should == Encoding::ISO_8859_1
+ end
- it "uses the external encoding specified via the :encoding option" do
- str = IO.read(@fname, encoding: Encoding::ISO_8859_1)
- str.encoding.should == Encoding::ISO_8859_1
+ it "uses the external encoding specified via the :encoding option" do
+ str = IO.read(@fname, encoding: Encoding::ISO_8859_1)
+ str.encoding.should == Encoding::ISO_8859_1
+ end
+
+ platform_is :windows do
+ it "reads the file in text mode" do
+ # 0x1A is CTRL+Z and is EOF in Windows text mode.
+ File.binwrite(@fname, "\x1Abbb")
+ IO.read(@fname).should.empty?
end
end
end
-describe "IO.read from a pipe" do
- it "runs the rest as a subprocess and returns the standard output" do
- cmd = "|sh -c 'echo hello'"
- platform_is :windows do
- cmd = "|cmd.exe /C echo hello"
+ruby_version_is ""..."4.0" do
+ describe "IO.read from a pipe" do
+ it "runs the rest as a subprocess and returns the standard output" do
+ cmd = "|sh -c 'echo hello'"
+ platform_is :windows do
+ cmd = "|cmd.exe /C echo hello"
+ end
+
+ suppress_warning do # https://bugs.ruby-lang.org/issues/19630
+ IO.read(cmd).should == "hello\n"
+ end
end
- IO.read(cmd).should == "hello\n"
- end
- with_feature :fork do
- it "opens a pipe to a fork if the rest is -" do
- str = IO.read("|-")
- if str # parent
- str.should == "hello from child\n"
- else #child
- puts "hello from child"
- exit!
+ guard -> { Process.respond_to?(:fork) } do
+ it "opens a pipe to a fork if the rest is -" do
+ str = nil
+ suppress_warning do # https://bugs.ruby-lang.org/issues/19630
+ str = IO.read("|-")
+ end
+
+ if str # parent
+ str.should == "hello from child\n"
+ else #child
+ puts "hello from child"
+ exit!
+ end
end
end
- end
- it "reads only the specified number of bytes requested" do
- cmd = "|sh -c 'echo hello'"
- platform_is :windows do
- cmd = "|cmd.exe /C echo hello"
+ it "reads only the specified number of bytes requested" do
+ cmd = "|sh -c 'echo hello'"
+ platform_is :windows do
+ cmd = "|cmd.exe /C echo hello"
+ end
+
+ suppress_warning do # https://bugs.ruby-lang.org/issues/19630
+ IO.read(cmd, 1).should == "h"
+ end
end
- IO.read(cmd, 1).should == "h"
- end
- platform_is_not :windows do
- it "raises Errno::ESPIPE if passed an offset" do
- lambda {
- IO.read("|sh -c 'echo hello'", 1, 1)
- }.should raise_error(Errno::ESPIPE)
+ platform_is_not :windows do
+ it "raises Errno::ESPIPE if passed an offset" do
+ -> {
+ suppress_warning do # https://bugs.ruby-lang.org/issues/19630
+ IO.read("|sh -c 'echo hello'", 1, 1)
+ end
+ }.should.raise(Errno::ESPIPE)
+ end
end
- end
-quarantine! do # The process tried to write to a nonexistent pipe.
- platform_is :windows do
- # TODO: It should raise Errno::ESPIPE on Windows as well
- # once https://bugs.ruby-lang.org/issues/12230 is fixed.
- it "raises Errno::EINVAL if passed an offset" do
- lambda {
- IO.read("|cmd.exe /C echo hello", 1, 1)
- }.should raise_error(Errno::EINVAL)
+ quarantine! do # The process tried to write to a nonexistent pipe.
+ platform_is :windows do
+ # TODO: It should raise Errno::ESPIPE on Windows as well
+ # once https://bugs.ruby-lang.org/issues/12230 is fixed.
+ it "raises Errno::EINVAL if passed an offset" do
+ -> {
+ suppress_warning do # https://bugs.ruby-lang.org/issues/19630
+ IO.read("|cmd.exe /C echo hello", 1, 1)
+ end
+ }.should.raise(Errno::EINVAL)
+ end
+ end
+ end
+
+ # https://bugs.ruby-lang.org/issues/19630
+ it "warns about deprecation" do
+ cmd = "|echo ok"
+ -> {
+ IO.read(cmd)
+ }.should complain(/IO process creation with a leading '\|'/)
end
end
end
-end
describe "IO.read on an empty file" do
before :each do
@@ -195,26 +265,58 @@ describe "IO#read" do
@io.read(4).should == '7890'
end
+ it "treats first nil argument as no length limit" do
+ @io.read(nil).should == @contents
+ end
+
+ it "raises an ArgumentError when not passed a valid length" do
+ -> { @io.read(-1) }.should.raise(ArgumentError)
+ end
+
it "clears the output buffer if there is nothing to read" do
@io.pos = 10
- buf = 'non-empty string'
+ buf = +'non-empty string'
@io.read(10, buf).should == nil
buf.should == ''
+
+ buf = +'non-empty string'
+
+ @io.read(nil, buf).should == ""
+
+ buf.should == ''
+
+ buf = +'non-empty string'
+
+ @io.read(0, buf).should == ""
+
+ buf.should == ''
+ end
+
+ it "raise FrozenError if the output buffer is frozen" do
+ @io.read
+ -> { @io.read(0, 'frozen-string'.freeze) }.should.raise(FrozenError)
+ -> { @io.read(1, 'frozen-string'.freeze) }.should.raise(FrozenError)
+ -> { @io.read(nil, 'frozen-string'.freeze) }.should.raise(FrozenError)
+ end
+
+ it "raise FrozenError if the output buffer is frozen (2)" do
+ @io.read
+ -> { @io.read(1, ''.freeze) }.should.raise(FrozenError)
end
it "consumes zero bytes when reading zero bytes" do
@io.read(0).should == ''
@io.pos.should == 0
- @io.getc.chr.should == '1'
+ @io.getc.should == '1'
end
it "is at end-of-file when everything has been read" do
@io.read
- @io.eof?.should == true
+ @io.should.eof?
end
it "reads the contents of a file" do
@@ -222,50 +324,72 @@ describe "IO#read" do
end
it "places the specified number of bytes in the buffer" do
- buf = ""
+ buf = +""
@io.read 5, buf
buf.should == "12345"
end
it "expands the buffer when too small" do
- buf = "ABCDE"
+ buf = +"ABCDE"
@io.read nil, buf
buf.should == @contents
end
it "overwrites the buffer" do
- buf = "ABCDEFGHIJ"
+ buf = +"ABCDEFGHIJ"
@io.read nil, buf
buf.should == @contents
end
it "truncates the buffer when too big" do
- buf = "ABCDEFGHIJKLMNO"
+ buf = +"ABCDEFGHIJKLMNO"
@io.read nil, buf
buf.should == @contents
@io.rewind
- buf = "ABCDEFGHIJKLMNO"
+ buf = +"ABCDEFGHIJKLMNO"
@io.read 5, buf
buf.should == @contents[0..4]
end
+ it "preserves the encoding of the given buffer" do
+ buffer = ''.encode(Encoding::ISO_8859_1)
+ @io.read(10, buffer)
+
+ buffer.encoding.should == Encoding::ISO_8859_1
+ end
+
+ # https://bugs.ruby-lang.org/issues/20416
+ it "does not preserve the encoding of the given buffer when max length is not provided" do
+ buffer = ''.encode(Encoding::ISO_8859_1)
+ @io.read(nil, buffer)
+
+ buffer.encoding.should_not == Encoding::ISO_8859_1
+ end
+
it "returns the given buffer" do
- buf = ""
+ buf = +""
+
+ @io.read(nil, buf).should.equal? buf
+ end
- @io.read(nil, buf).object_id.should == buf.object_id
+ it "returns the given buffer when there is nothing to read" do
+ buf = +""
+
+ @io.read
+ @io.read(nil, buf).should.equal? buf
end
it "coerces the second argument to string and uses it as a buffer" do
- buf = "ABCDE"
+ buf = +"ABCDE"
obj = mock("buff")
obj.should_receive(:to_str).any_number_of_times.and_return(buf)
- @io.read(15, obj).object_id.should_not == obj.object_id
+ @io.read(15, obj).should_not.equal? obj
buf.should == @contents
end
@@ -299,9 +423,12 @@ describe "IO#read" do
end
it "raises IOError on closed stream" do
- lambda { IOSpecs.closed_io.read }.should raise_error(IOError)
+ -> { IOSpecs.closed_io.read }.should.raise(IOError)
end
+ it "raises ArgumentError when length is less than 0" do
+ -> { @io.read(-1) }.should.raise(ArgumentError)
+ end
platform_is_not :windows do
it "raises IOError when stream is closed by another thread" do
@@ -317,7 +444,7 @@ describe "IO#read" do
Thread.pass until t.stop?
r.close
t.join
- t.value.should be_kind_of(IOError)
+ t.value.should.is_a?(IOError)
w.close
end
end
@@ -378,16 +505,9 @@ describe "IO#read in binary mode" do
result = File.open(@name, "rb") { |f| f.read }.chomp
- result.encoding.should == Encoding::ASCII_8BIT
- xE2 = [226].pack('C*')
- result.should == ("abc" + xE2 + "def").force_encoding(Encoding::ASCII_8BIT)
- end
-
- it "does not transcode file contents when an internal encoding is specified" do
- result = File.open(@name, "r:binary:utf-8") { |f| f.read }.chomp
- result.encoding.should == Encoding::ASCII_8BIT
+ result.encoding.should == Encoding::BINARY
xE2 = [226].pack('C*')
- result.should == ("abc" + xE2 + "def").force_encoding(Encoding::ASCII_8BIT)
+ result.should == ("abc" + xE2 + "def").force_encoding(Encoding::BINARY)
end
end
@@ -418,169 +538,168 @@ describe "IO.read with BOM" do
it "reads a file without a bom" do
name = fixture __FILE__, "no_bom_UTF-8.txt"
result = File.read(name, mode: "rb:BOM|utf-8")
- result.force_encoding("ascii-8bit").should == "UTF-8\n"
+ result.force_encoding("binary").should == "UTF-8\n"
end
it "reads a file with a utf-8 bom" do
name = fixture __FILE__, "bom_UTF-8.txt"
result = File.read(name, mode: "rb:BOM|utf-16le")
- result.force_encoding("ascii-8bit").should == "UTF-8\n"
+ result.force_encoding("binary").should == "UTF-8\n"
end
it "reads a file with a utf-16le bom" do
name = fixture __FILE__, "bom_UTF-16LE.txt"
result = File.read(name, mode: "rb:BOM|utf-8")
- result.force_encoding("ascii-8bit").should == "U\x00T\x00F\x00-\x001\x006\x00L\x00E\x00\n\x00"
+ result.force_encoding("binary").should == "U\x00T\x00F\x00-\x001\x006\x00L\x00E\x00\n\x00"
end
it "reads a file with a utf-16be bom" do
name = fixture __FILE__, "bom_UTF-16BE.txt"
result = File.read(name, mode: "rb:BOM|utf-8")
- result.force_encoding("ascii-8bit").should == "\x00U\x00T\x00F\x00-\x001\x006\x00B\x00E\x00\n"
+ result.force_encoding("binary").should == "\x00U\x00T\x00F\x00-\x001\x006\x00B\x00E\x00\n"
end
it "reads a file with a utf-32le bom" do
name = fixture __FILE__, "bom_UTF-32LE.txt"
result = File.read(name, mode: "rb:BOM|utf-8")
- result.force_encoding("ascii-8bit").should == "U\x00\x00\x00T\x00\x00\x00F\x00\x00\x00-\x00\x00\x003\x00\x00\x002\x00\x00\x00L\x00\x00\x00E\x00\x00\x00\n\x00\x00\x00"
+ result.force_encoding("binary").should == "U\x00\x00\x00T\x00\x00\x00F\x00\x00\x00-\x00\x00\x003\x00\x00\x002\x00\x00\x00L\x00\x00\x00E\x00\x00\x00\n\x00\x00\x00"
end
it "reads a file with a utf-32be bom" do
name = fixture __FILE__, "bom_UTF-32BE.txt"
result = File.read(name, mode: "rb:BOM|utf-8")
- result.force_encoding("ascii-8bit").should == "\x00\x00\x00U\x00\x00\x00T\x00\x00\x00F\x00\x00\x00-\x00\x00\x003\x00\x00\x002\x00\x00\x00B\x00\x00\x00E\x00\x00\x00\n"
+ result.force_encoding("binary").should == "\x00\x00\x00U\x00\x00\x00T\x00\x00\x00F\x00\x00\x00-\x00\x00\x003\x00\x00\x002\x00\x00\x00B\x00\x00\x00E\x00\x00\x00\n"
end
end
-with_feature :encoding do
- describe :io_read_internal_encoding, shared: true do
- it "returns a transcoded String" do
- @io.read.should == "ã‚りãŒã¨ã†\n"
+describe :io_read_internal_encoding, shared: true do
+ it "returns a transcoded String" do
+ @io.read.should == "ã‚りãŒã¨ã†\n"
+ end
+
+ it "sets the String encoding to the internal encoding" do
+ @io.read.encoding.should.equal?(Encoding::UTF_8)
+ end
+
+ describe "when passed nil for limit" do
+ it "sets the buffer to a transcoded String" do
+ result = @io.read(nil, buf = +"")
+ buf.should.equal?(result)
+ buf.should == "ã‚りãŒã¨ã†\n"
end
- it "sets the String encoding to the internal encoding" do
- @io.read.encoding.should equal(Encoding::UTF_8)
+ it "sets the buffer's encoding to the internal encoding" do
+ buf = "".dup.force_encoding Encoding::ISO_8859_1
+ @io.read(nil, buf)
+ buf.encoding.should.equal?(Encoding::UTF_8)
end
+ end
+end
- describe "when passed nil for limit" do
- it "sets the buffer to a transcoded String" do
- result = @io.read(nil, buf = "")
- buf.should equal(result)
- buf.should == "ã‚りãŒã¨ã†\n"
- end
+describe :io_read_size_internal_encoding, shared: true do
+ it "reads bytes when passed a size" do
+ @io.read(2).should == [164, 162].pack('C*').force_encoding(Encoding::BINARY)
+ end
- it "sets the buffer's encoding to the internal encoding" do
- buf = "".force_encoding Encoding::ISO_8859_1
- @io.read(nil, buf)
- buf.encoding.should equal(Encoding::UTF_8)
- end
- end
+ it "returns a String in BINARY when passed a size" do
+ @io.read(4).encoding.should.equal?(Encoding::BINARY)
+ @io.read(0).encoding.should.equal?(Encoding::BINARY)
end
- describe :io_read_size_internal_encoding, shared: true do
- it "reads bytes when passed a size" do
- @io.read(2).should == [164, 162].pack('C*').force_encoding(Encoding::ASCII_8BIT)
- end
+ it "does not change the buffer's encoding when passed a limit" do
+ buf = "".dup.force_encoding Encoding::ISO_8859_1
+ @io.read(4, buf)
+ buf.should == [164, 162, 164, 234].pack('C*').force_encoding(Encoding::ISO_8859_1)
+ buf.encoding.should.equal?(Encoding::ISO_8859_1)
+ end
- it "returns a String in ASCII-8BIT when passed a size" do
- @io.read(4).encoding.should equal(Encoding::ASCII_8BIT)
- end
+ it "truncates the buffer but does not change the buffer's encoding when no data remains" do
+ buf = "abc".dup.force_encoding Encoding::ISO_8859_1
+ @io.read
+
+ @io.read(1, buf).should == nil
+ buf.size.should == 0
+ buf.encoding.should.equal?(Encoding::ISO_8859_1)
+ end
+end
- it "does not change the buffer's encoding when passed a limit" do
- buf = "".force_encoding Encoding::ISO_8859_1
- @io.read(4, buf)
- buf.should == [164, 162, 164, 234].pack('C*').force_encoding(Encoding::ISO_8859_1)
- buf.encoding.should equal(Encoding::ISO_8859_1)
+describe "IO#read" do
+ describe "when IO#external_encoding and IO#internal_encoding are nil" do
+ before :each do
+ @name = tmp("io_read.txt")
+ touch(@name) { |f| f.write "\x00\x01\x02" }
+ @io = new_io @name, "r+"
end
- it "trucates the buffer but does not change the buffer's encoding when no data remains" do
- buf = "abc".force_encoding Encoding::ISO_8859_1
- @io.read
+ after :each do
+ @io.close if @io
+ rm_r @name
+ end
- @io.read(1, buf).should be_nil
- buf.size.should == 0
- buf.encoding.should equal(Encoding::ISO_8859_1)
+ it "sets the String encoding to Encoding.default_external" do
+ @io.read.encoding.should.equal?(Encoding.default_external)
end
end
- describe "IO#read" do
- describe "when IO#external_encoding and IO#internal_encoding are nil" do
- before :each do
- @name = tmp("io_read.txt")
- touch(@name) { |f| f.write "\x00\x01\x02" }
- @io = new_io @name, "r+"
- end
+ describe "with internal encoding" do
+ after :each do
+ @io.close if @io
+ end
- after :each do
- @io.close if @io
- rm_r @name
+ describe "not specified" do
+ before :each do
+ @io = IOSpecs.io_fixture "read_euc_jp.txt", "r:euc-jp"
end
- it "sets the String encoding to Encoding.default_external" do
- @io.read.encoding.should equal(Encoding.default_external)
+ it "does not transcode the String" do
+ @io.read.should == ("ã‚りãŒã¨ã†\n").encode(Encoding::EUC_JP)
end
- end
- describe "with internal encoding" do
- after :each do
- @io.close if @io
+ it "sets the String encoding to the external encoding" do
+ @io.read.encoding.should.equal?(Encoding::EUC_JP)
end
- describe "not specified" do
- before :each do
- @io = IOSpecs.io_fixture "read_euc_jp.txt", "r:euc-jp"
- end
-
- it "does not transcode the String" do
- @io.read.should == ("ã‚りãŒã¨ã†\n").encode(Encoding::EUC_JP)
- end
-
- it "sets the String encoding to the external encoding" do
- @io.read.encoding.should equal(Encoding::EUC_JP)
- end
+ it_behaves_like :io_read_size_internal_encoding, nil
+ end
- it_behaves_like :io_read_size_internal_encoding, nil
+ describe "specified by open mode" do
+ before :each do
+ @io = IOSpecs.io_fixture "read_euc_jp.txt", "r:euc-jp:utf-8"
end
- describe "specified by open mode" do
- before :each do
- @io = IOSpecs.io_fixture "read_euc_jp.txt", "r:euc-jp:utf-8"
- end
+ it_behaves_like :io_read_internal_encoding, nil
+ it_behaves_like :io_read_size_internal_encoding, nil
+ end
- it_behaves_like :io_read_internal_encoding, nil
- it_behaves_like :io_read_size_internal_encoding, nil
+ describe "specified by mode: option" do
+ before :each do
+ @io = IOSpecs.io_fixture "read_euc_jp.txt", mode: "r:euc-jp:utf-8"
end
- describe "specified by mode: option" do
- before :each do
- @io = IOSpecs.io_fixture "read_euc_jp.txt", mode: "r:euc-jp:utf-8"
- end
+ it_behaves_like :io_read_internal_encoding, nil
+ it_behaves_like :io_read_size_internal_encoding, nil
+ end
- it_behaves_like :io_read_internal_encoding, nil
- it_behaves_like :io_read_size_internal_encoding, nil
+ describe "specified by internal_encoding: option" do
+ before :each do
+ options = { mode: "r",
+ internal_encoding: "utf-8",
+ external_encoding: "euc-jp" }
+ @io = IOSpecs.io_fixture "read_euc_jp.txt", options
end
- describe "specified by internal_encoding: option" do
- before :each do
- options = { mode: "r",
- internal_encoding: "utf-8",
- external_encoding: "euc-jp" }
- @io = IOSpecs.io_fixture "read_euc_jp.txt", options
- end
+ it_behaves_like :io_read_internal_encoding, nil
+ it_behaves_like :io_read_size_internal_encoding, nil
+ end
- it_behaves_like :io_read_internal_encoding, nil
- it_behaves_like :io_read_size_internal_encoding, nil
+ describe "specified by encoding: option" do
+ before :each do
+ options = { mode: "r", encoding: "euc-jp:utf-8" }
+ @io = IOSpecs.io_fixture "read_euc_jp.txt", options
end
- describe "specified by encoding: option" do
- before :each do
- options = { mode: "r", encoding: "euc-jp:utf-8" }
- @io = IOSpecs.io_fixture "read_euc_jp.txt", options
- end
-
- it_behaves_like :io_read_internal_encoding, nil
- it_behaves_like :io_read_size_internal_encoding, nil
- end
+ it_behaves_like :io_read_internal_encoding, nil
+ it_behaves_like :io_read_size_internal_encoding, nil
end
end
end
diff --git a/spec/ruby/core/io/readbyte_spec.rb b/spec/ruby/core/io/readbyte_spec.rb
index 1cc588eea5..07da1da919 100644
--- a/spec/ruby/core/io/readbyte_spec.rb
+++ b/spec/ruby/core/io/readbyte_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "IO#readbyte" do
before :each do
@@ -17,10 +17,8 @@ describe "IO#readbyte" do
it "raises EOFError on EOF" do
@io.seek(999999)
- lambda do
+ -> do
@io.readbyte
- end.should raise_error EOFError
+ end.should.raise EOFError
end
-
- it "needs to be reviewed for spec completeness"
end
diff --git a/spec/ruby/core/io/readchar_spec.rb b/spec/ruby/core/io/readchar_spec.rb
index 6771fcab59..29d14880ff 100644
--- a/spec/ruby/core/io/readchar_spec.rb
+++ b/spec/ruby/core/io/readchar_spec.rb
@@ -1,5 +1,15 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe :io_readchar_internal_encoding, shared: true do
+ it "returns a transcoded String" do
+ @io.readchar.should == "ã‚"
+ end
+
+ it "sets the String encoding to the internal encoding" do
+ @io.readchar.encoding.should.equal?(Encoding::UTF_8)
+ end
+end
describe "IO#readchar" do
before :each do
@@ -21,11 +31,67 @@ describe "IO#readchar" do
it "raises an EOFError when invoked at the end of the stream" do
@io.read
- lambda { @io.readchar }.should raise_error(EOFError)
+ -> { @io.readchar }.should.raise(EOFError)
end
it "raises IOError on closed stream" do
- lambda { IOSpecs.closed_io.readchar }.should raise_error(IOError)
+ -> { IOSpecs.closed_io.readchar }.should.raise(IOError)
+ end
+end
+
+describe "IO#readchar with internal encoding" do
+ after :each do
+ @io.close if @io
+ end
+
+ describe "not specified" do
+ before :each do
+ @io = IOSpecs.io_fixture "read_euc_jp.txt", "r:euc-jp"
+ end
+
+ it "does not transcode the String" do
+ @io.readchar.should == ("ã‚").encode(Encoding::EUC_JP)
+ end
+
+ it "sets the String encoding to the external encoding" do
+ @io.readchar.encoding.should.equal?(Encoding::EUC_JP)
+ end
+ end
+
+ describe "specified by open mode" do
+ before :each do
+ @io = IOSpecs.io_fixture "read_euc_jp.txt", "r:euc-jp:utf-8"
+ end
+
+ it_behaves_like :io_readchar_internal_encoding, nil
+ end
+
+ describe "specified by mode: option" do
+ before :each do
+ @io = IOSpecs.io_fixture "read_euc_jp.txt", mode: "r:euc-jp:utf-8"
+ end
+
+ it_behaves_like :io_readchar_internal_encoding, nil
+ end
+
+ describe "specified by internal_encoding: option" do
+ before :each do
+ options = { mode: "r",
+ internal_encoding: "utf-8",
+ external_encoding: "euc-jp" }
+ @io = IOSpecs.io_fixture "read_euc_jp.txt", options
+ end
+
+ it_behaves_like :io_readchar_internal_encoding, nil
+ end
+
+ describe "specified by encoding: option" do
+ before :each do
+ options = { mode: "r", encoding: "euc-jp:utf-8" }
+ @io = IOSpecs.io_fixture "read_euc_jp.txt", options
+ end
+
+ it_behaves_like :io_readchar_internal_encoding, nil
end
end
@@ -39,6 +105,6 @@ describe "IO#readchar" do
end
it "raises EOFError on empty stream" do
- lambda { @io.readchar }.should raise_error(EOFError)
+ -> { @io.readchar }.should.raise(EOFError)
end
end
diff --git a/spec/ruby/core/io/readline_spec.rb b/spec/ruby/core/io/readline_spec.rb
index a1cddafe5c..009687710a 100644
--- a/spec/ruby/core/io/readline_spec.rb
+++ b/spec/ruby/core/io/readline_spec.rb
@@ -1,6 +1,6 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "IO#readline" do
before :each do
@@ -29,11 +29,11 @@ describe "IO#readline" do
it "raises EOFError on end of stream" do
IOSpecs.lines.length.times { @io.readline }
- lambda { @io.readline }.should raise_error(EOFError)
+ -> { @io.readline }.should.raise(EOFError)
end
it "raises IOError on closed stream" do
- lambda { IOSpecs.closed_io.readline }.should raise_error(IOError)
+ -> { IOSpecs.closed_io.readline }.should.raise(IOError)
end
it "assigns the returned line to $_" do
@@ -43,11 +43,42 @@ describe "IO#readline" do
end
end
- ruby_version_is "2.4" do
- describe "when passed chomp" do
- it "returns the first line without a trailing newline character" do
- @io.readline(chomp: true).should == IOSpecs.lines_without_newline_characters[0]
- end
+ describe "when passed limit" do
+ it "reads limit bytes" do
+ @io.readline(3).should == "Voi"
+ end
+
+ it "returns an empty string when passed 0 as a limit" do
+ @io.readline(0).should == ""
+ end
+
+ it "does not accept Integers that don't fit in a C off_t" do
+ -> { @io.readline(2**128) }.should.raise(RangeError)
+ end
+ end
+
+ describe "when passed separator and limit" do
+ it "reads limit bytes till the separator" do
+ # Voici la ligne une.\
+ @io.readline(" ", 4).should == "Voic"
+ @io.readline(" ", 4).should == "i "
+ @io.readline(" ", 4).should == "la "
+ @io.readline(" ", 4).should == "lign"
+ @io.readline(" ", 4).should == "e "
+ end
+ end
+
+ describe "when passed chomp" do
+ it "returns the first line without a trailing newline character" do
+ @io.readline(chomp: true).should == IOSpecs.lines_without_newline_characters[0]
+ end
+
+ it "raises exception when options passed as Hash" do
+ -> { @io.readline({ chomp: true }) }.should.raise(TypeError)
+
+ -> {
+ @io.readline("\n", 1, { chomp: true })
+ }.should.raise(ArgumentError, "wrong number of arguments (given 3, expected 0..2)")
end
end
end
diff --git a/spec/ruby/core/io/readlines_spec.rb b/spec/ruby/core/io/readlines_spec.rb
index 22ba844b52..d41d24d7d1 100644
--- a/spec/ruby/core/io/readlines_spec.rb
+++ b/spec/ruby/core/io/readlines_spec.rb
@@ -1,32 +1,32 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/readlines', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/readlines'
describe "IO#readlines" do
before :each do
@io = IOSpecs.io_fixture "lines.txt"
- @orig_exteenc = Encoding.default_external
+ @orig_extenc = Encoding.default_external
Encoding.default_external = Encoding::UTF_8
end
after :each do
@io.close unless @io.closed?
- Encoding.default_external = @orig_exteenc
+ Encoding.default_external = @orig_extenc
end
it "raises an IOError if the stream is closed" do
@io.close
- lambda { @io.readlines }.should raise_error(IOError)
+ -> { @io.readlines }.should.raise(IOError)
end
describe "when passed no arguments" do
before :each do
- @sep, $/ = $/, " "
+ suppress_warning {@sep, $/ = $/, " "}
end
after :each do
- $/ = @sep
+ suppress_warning {$/ = @sep}
end
it "returns an Array containing lines based on $/" do
@@ -37,12 +37,12 @@ describe "IO#readlines" do
describe "when passed no arguments" do
it "updates self's position" do
@io.readlines
- @io.pos.should eql(137)
+ @io.pos.should.eql?(137)
end
it "updates self's lineno based on the number of lines read" do
@io.readlines
- @io.lineno.should eql(9)
+ @io.lineno.should.eql?(9)
end
it "does not change $_" do
@@ -81,12 +81,12 @@ describe "IO#readlines" do
it "updates self's lineno based on the number of lines read" do
@io.readlines("r")
- @io.lineno.should eql(5)
+ @io.lineno.should.eql?(5)
end
it "updates self's position based on the number of characters read" do
@io.readlines("r")
- @io.pos.should eql(137)
+ @io.pos.should.eql?(137)
end
it "does not change $_" do
@@ -102,28 +102,33 @@ describe "IO#readlines" do
end
end
- describe "when passed a string that starts with a |" do
- it "gets data from the standard out of the subprocess" do
- cmd = "|sh -c 'echo hello;echo line2'"
- platform_is :windows do
- cmd = "|cmd.exe /C echo hello&echo line2"
- end
- lines = IO.readlines(cmd)
- lines.should == ["hello\n", "line2\n"]
+ describe "when passed limit" do
+ it "raises ArgumentError when passed 0 as a limit" do
+ -> { @io.readlines(0) }.should.raise(ArgumentError)
end
- with_feature :fork do
- it "gets data from a fork when passed -" do
- lines = IO.readlines("|-")
+ it "does not accept Integers that don't fit in a C off_t" do
+ -> { @io.readlines(2**128) }.should.raise(RangeError)
+ end
+ end
- if lines # parent
- lines.should == ["hello\n", "from a fork\n"]
- else
- puts "hello"
- puts "from a fork"
- exit!
- end
- end
+ describe "when passed chomp" do
+ it "returns the first line without a trailing newline character" do
+ @io.readlines(chomp: true).should == IOSpecs.lines_without_newline_characters
+ end
+
+ it "raises exception when options passed as Hash" do
+ -> { @io.readlines({ chomp: true }) }.should.raise(TypeError)
+
+ -> {
+ @io.readlines("\n", 1, { chomp: true })
+ }.should.raise(ArgumentError, "wrong number of arguments (given 3, expected 0..2)")
+ end
+ end
+
+ describe "when passed arbitrary keyword argument" do
+ it "tolerates it" do
+ @io.readlines(chomp: true, foo: :bar).should == IOSpecs.lines_without_newline_characters
end
end
end
@@ -138,15 +143,15 @@ describe "IO#readlines" do
end
it "raises an IOError if the stream is opened for append only" do
- lambda do
- File.open(@name, fmode("a:utf-8")) { |f| f.readlines }
- end.should raise_error(IOError)
+ -> do
+ File.open(@name, "a:utf-8") { |f| f.readlines }
+ end.should.raise(IOError)
end
it "raises an IOError if the stream is opened for write only" do
- lambda do
- File.open(@name, fmode("w:utf-8")) { |f| f.readlines }
- end.should raise_error(IOError)
+ -> do
+ File.open(@name, "w:utf-8") { |f| f.readlines }
+ end.should.raise(IOError)
end
end
@@ -169,6 +174,48 @@ describe "IO.readlines" do
$_.should == "test"
end
+ ruby_version_is ""..."4.0" do
+ describe "when passed a string that starts with a |" do
+ it "gets data from the standard out of the subprocess" do
+ cmd = "|sh -c 'echo hello;echo line2'"
+ platform_is :windows do
+ cmd = "|cmd.exe /C echo hello&echo line2"
+ end
+
+ lines = nil
+ suppress_warning do # https://bugs.ruby-lang.org/issues/19630
+ lines = IO.readlines(cmd)
+ end
+ lines.should == ["hello\n", "line2\n"]
+ end
+
+ guard -> { Process.respond_to?(:fork) } do
+ it "gets data from a fork when passed -" do
+ lines = nil
+ suppress_warning do # https://bugs.ruby-lang.org/issues/19630
+ lines = IO.readlines("|-")
+ end
+
+ if lines # parent
+ lines.should == ["hello\n", "from a fork\n"]
+ else
+ puts "hello"
+ puts "from a fork"
+ exit!
+ end
+ end
+ end
+ end
+
+ # https://bugs.ruby-lang.org/issues/19630
+ it "warns about deprecation given a path with a pipe" do
+ cmd = "|echo ok"
+ -> {
+ IO.readlines(cmd)
+ }.should complain(/IO process creation with a leading '\|'/)
+ end
+ end
+
it_behaves_like :io_readlines, :readlines
it_behaves_like :io_readlines_options_19, :readlines
end
@@ -184,27 +231,27 @@ describe "IO.readlines" do
after :each do
Encoding.default_external = @external
Encoding.default_internal = @internal
- $/ = @dollar_slash
+ suppress_warning {$/ = @dollar_slash}
end
it "encodes lines using the default external encoding" do
Encoding.default_external = Encoding::UTF_8
lines = IO.readlines(@name)
- lines.all? { |s| s.encoding == Encoding::UTF_8 }.should be_true
+ lines.all? { |s| s.encoding == Encoding::UTF_8 }.should == true
end
it "encodes lines using the default internal encoding, when set" do
Encoding.default_external = Encoding::UTF_8
Encoding.default_internal = Encoding::UTF_16
- $/ = $/.encode Encoding::UTF_16
+ suppress_warning {$/ = $/.encode Encoding::UTF_16}
lines = IO.readlines(@name)
- lines.all? { |s| s.encoding == Encoding::UTF_16 }.should be_true
+ lines.all? { |s| s.encoding == Encoding::UTF_16 }.should == true
end
- it "ignores the default internal encoding if the external encoding is ASCII-8BIT" do
- Encoding.default_external = Encoding::ASCII_8BIT
+ it "ignores the default internal encoding if the external encoding is BINARY" do
+ Encoding.default_external = Encoding::BINARY
Encoding.default_internal = Encoding::UTF_8
lines = IO.readlines(@name)
- lines.all? { |s| s.encoding == Encoding::ASCII_8BIT }.should be_true
+ lines.all? { |s| s.encoding == Encoding::BINARY }.should == true
end
end
diff --git a/spec/ruby/core/io/readpartial_spec.rb b/spec/ruby/core/io/readpartial_spec.rb
index 16cb08dada..d3f5545c8f 100644
--- a/spec/ruby/core/io/readpartial_spec.rb
+++ b/spec/ruby/core/io/readpartial_spec.rb
@@ -1,6 +1,6 @@
-# -*- encoding: ascii-8bit -*-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+# encoding: binary
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "IO#readpartial" do
before :each do
@@ -15,10 +15,10 @@ describe "IO#readpartial" do
end
it "raises IOError on closed stream" do
- lambda { IOSpecs.closed_io.readpartial(10) }.should raise_error(IOError)
+ -> { IOSpecs.closed_io.readpartial(10) }.should.raise(IOError)
@rd.close
- lambda { @rd.readpartial(10) }.should raise_error(IOError)
+ -> { @rd.readpartial(10) }.should.raise(IOError)
end
it "reads at most the specified number of bytes" do
@@ -59,10 +59,10 @@ describe "IO#readpartial" do
end
it "discards the existing buffer content upon successful read" do
- buffer = "existing"
+ buffer = +"existing content"
@wr.write("hello world")
@wr.close
- @rd.readpartial(11, buffer)
+ @rd.readpartial(11, buffer).should.equal?(buffer)
buffer.should == "hello world"
end
@@ -70,27 +70,46 @@ describe "IO#readpartial" do
@wr.write("abc")
@wr.close
@rd.readpartial(10).should == 'abc'
- lambda { @rd.readpartial(10) }.should raise_error(EOFError)
+ -> { @rd.readpartial(10) }.should.raise(EOFError)
end
it "discards the existing buffer content upon error" do
- buffer = 'hello'
+ buffer = +'hello'
@wr.close
- lambda { @rd.readpartial(1, buffer) }.should raise_error(EOFError)
- buffer.should be_empty
+ -> { @rd.readpartial(1, buffer) }.should.raise(EOFError)
+ buffer.should.empty?
end
it "raises IOError if the stream is closed" do
@wr.close
- lambda { @rd.readpartial(1) }.should raise_error(IOError)
+ -> { @rd.readpartial(1) }.should.raise(IOError)
end
it "raises ArgumentError if the negative argument is provided" do
- lambda { @rd.readpartial(-1) }.should raise_error(ArgumentError)
+ -> { @rd.readpartial(-1) }.should.raise(ArgumentError)
end
it "immediately returns an empty string if the length argument is 0" do
@rd.readpartial(0).should == ""
end
+ it "raises IOError if the stream is closed and the length argument is 0" do
+ @rd.close
+ -> { @rd.readpartial(0) }.should.raise(IOError, "closed stream")
+ end
+
+ it "clears and returns the given buffer if the length argument is 0" do
+ buffer = +"existing content"
+ @rd.readpartial(0, buffer).should == buffer
+ buffer.should == ""
+ end
+
+ it "preserves the encoding of the given buffer" do
+ buffer = ''.encode(Encoding::ISO_8859_1)
+ @wr.write("abc")
+ @wr.close
+ @rd.readpartial(10, buffer)
+
+ buffer.encoding.should == Encoding::ISO_8859_1
+ end
end
diff --git a/spec/ruby/core/io/reopen_spec.rb b/spec/ruby/core/io/reopen_spec.rb
index 63020d5f3e..3b972d8978 100644
--- a/spec/ruby/core/io/reopen_spec.rb
+++ b/spec/ruby/core/io/reopen_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
require 'fcntl'
@@ -27,35 +27,35 @@ describe "IO#reopen" do
it "changes the class of the instance to the class of the object returned by #to_io" do
obj = mock("io")
obj.should_receive(:to_io).and_return(@other_io)
- @io.reopen(obj).should be_an_instance_of(File)
+ @io.reopen(obj).should.instance_of?(File)
end
it "raises an IOError if the object returned by #to_io is closed" do
obj = mock("io")
obj.should_receive(:to_io).and_return(IOSpecs.closed_io)
- lambda { @io.reopen obj }.should raise_error(IOError)
+ -> { @io.reopen obj }.should.raise(IOError)
end
it "raises a TypeError if #to_io does not return an IO instance" do
obj = mock("io")
obj.should_receive(:to_io).and_return("something else")
- lambda { @io.reopen obj }.should raise_error(TypeError)
+ -> { @io.reopen obj }.should.raise(TypeError)
end
it "raises an IOError when called on a closed stream with an object" do
@io.close
obj = mock("io")
obj.should_not_receive(:to_io)
- lambda { @io.reopen(STDOUT) }.should raise_error(IOError)
+ -> { @io.reopen(STDOUT) }.should.raise(IOError)
end
it "raises an IOError if the IO argument is closed" do
- lambda { @io.reopen(IOSpecs.closed_io) }.should raise_error(IOError)
+ -> { @io.reopen(IOSpecs.closed_io) }.should.raise(IOError)
end
it "raises an IOError when called on a closed stream with an IO" do
@io.close
- lambda { @io.reopen(STDOUT) }.should raise_error(IOError)
+ -> { @io.reopen(STDOUT) }.should.raise(IOError)
end
end
@@ -77,12 +77,12 @@ describe "IO#reopen with a String" do
it "does not raise an exception when called on a closed stream with a path" do
@io.close
@io.reopen @name, "r"
- @io.closed?.should be_false
+ @io.closed?.should == false
@io.gets.should == "Line 1: One\n"
end
it "returns self" do
- @io.reopen(@name).should equal(@io)
+ @io.reopen(@name).should.equal?(@io)
end
it "positions a newly created instance at the beginning of the new stream" do
@@ -145,31 +145,30 @@ describe "IO#reopen with a String" do
File.read(@other_name).should == "new data"
end
- it "closes the file descriptor obtained by opening the new file" do
+ it "always resets the close-on-exec flag to true on non-STDIO objects" do
@io = new_io @name, "w"
- @other_io = File.open @other_name, "w"
- max = @other_io.fileno
- @other_io.close
-
+ @io.close_on_exec = true
@io.reopen @other_name
+ @io.should.close_on_exec?
- @other_io = File.open @other_name, "w"
- @other_io.fileno.should == max
+ @io.close_on_exec = false
+ @io.reopen @other_name
+ @io.should.close_on_exec?
end
it "creates the file if it doesn't exist if the IO is opened in write mode" do
@io = new_io @name, "w"
@io.reopen(@other_name)
- File.exist?(@other_name).should be_true
+ File.should.exist?(@other_name)
end
it "creates the file if it doesn't exist if the IO is opened in write mode" do
@io = new_io @name, "a"
@io.reopen(@other_name)
- File.exist?(@other_name).should be_true
+ File.should.exist?(@other_name)
end
end
@@ -189,7 +188,7 @@ describe "IO#reopen with a String" do
it "raises an Errno::ENOENT if the file does not exist and the IO is not opened in write mode" do
@io = new_io @name, "r"
- lambda { @io.reopen(@other_name) }.should raise_error(Errno::ENOENT)
+ -> { @io.reopen(@other_name) }.should.raise(Errno::ENOENT)
end
end
@@ -215,9 +214,9 @@ describe "IO#reopen with an IO at EOF" do
end
it "resets the EOF status to false" do
- @io.eof?.should be_true
+ @io.eof?.should == true
@io.reopen @other_io
- @io.eof?.should be_false
+ @io.eof?.should == false
end
end
@@ -231,7 +230,7 @@ describe "IO#reopen with an IO" do
end
@io = new_io @name
- @other_io = new_io @other_name, "r"
+ @other_io = IO.new(new_fd(@other_name, "r"), "r")
end
after :each do
@@ -245,7 +244,7 @@ describe "IO#reopen with an IO" do
# MRI actually changes the class of @io in the call to #reopen
# but does not preserve the existing singleton class of @io.
def @io.to_io; flunk; end
- @io.reopen(@other_io).should be_an_instance_of(IO)
+ @io.reopen(@other_io).should.instance_of?(IO)
end
it "does not change the object_id" do
@@ -290,9 +289,21 @@ describe "IO#reopen with an IO" do
File.read(@other_name).should == "io data"
end
+ it "always resets the close-on-exec flag to true on non-STDIO objects" do
+ @other_io.close_on_exec = true
+ @io.close_on_exec = true
+ @io.reopen @other_io
+ @io.should.close_on_exec?
+
+ @other_io.close_on_exec = false
+ @io.close_on_exec = false
+ @io.reopen @other_io
+ @io.should.close_on_exec?
+ end
+
it "may change the class of the instance" do
@io.reopen @other_io
- @io.should be_an_instance_of(File)
+ @io.should.instance_of?(File)
end
it "sets path equals to the other IO's path if other IO is File" do
diff --git a/spec/ruby/core/io/rewind_spec.rb b/spec/ruby/core/io/rewind_spec.rb
index ecf8a71891..43834ef307 100644
--- a/spec/ruby/core/io/rewind_spec.rb
+++ b/spec/ruby/core/io/rewind_spec.rb
@@ -1,6 +1,6 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "IO#rewind" do
before :each do
@@ -18,10 +18,21 @@ describe "IO#rewind" do
@io.readline.should == "Voici la ligne une.\n"
end
+ it "positions the instance to the beginning of output for write-only IO" do
+ name = tmp("io_rewind_spec")
+ io = File.open(name, "w")
+ io.write("Voici la ligne une.\n")
+ io.rewind
+ io.pos.should == 0
+ ensure
+ io.close
+ rm_r name
+ end
+
it "positions the instance to the beginning of input and clears EOF" do
value = @io.read
@io.rewind
- @io.eof?.should == false
+ @io.should_not.eof?
value.should == @io.read
end
@@ -32,7 +43,11 @@ describe "IO#rewind" do
@io.lineno.should == 0
end
+ it "returns 0" do
+ @io.rewind.should == 0
+ end
+
it "raises IOError on closed stream" do
- lambda { IOSpecs.closed_io.rewind }.should raise_error(IOError)
+ -> { IOSpecs.closed_io.rewind }.should.raise(IOError)
end
end
diff --git a/spec/ruby/core/io/seek_spec.rb b/spec/ruby/core/io/seek_spec.rb
index f7e138cbe9..d26629fb89 100644
--- a/spec/ruby/core/io/seek_spec.rb
+++ b/spec/ruby/core/io/seek_spec.rb
@@ -1,7 +1,7 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/pos', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/pos'
describe "IO#seek" do
it_behaves_like :io_set_pos, :seek
@@ -17,7 +17,7 @@ describe "IO#seek" do
end
it "moves the read position relative to the current position with SEEK_CUR" do
- lambda { @io.seek(-1) }.should raise_error(Errno::EINVAL)
+ -> { @io.seek(-1) }.should.raise(Errno::EINVAL)
@io.seek(10, IO::SEEK_CUR)
@io.readline.should == "igne une.\n"
@io.seek(-5, IO::SEEK_CUR)
@@ -44,21 +44,21 @@ describe "IO#seek" do
it "moves the read position and clears EOF with SEEK_SET" do
value = @io.read
@io.seek(0, IO::SEEK_SET)
- @io.eof?.should == false
+ @io.should_not.eof?
value.should == @io.read
end
it "moves the read position and clears EOF with SEEK_CUR" do
value = @io.read
@io.seek(-1, IO::SEEK_CUR)
- @io.eof?.should == false
+ @io.should_not.eof?
value[-1].should == @io.read[0]
end
it "moves the read position and clears EOF with SEEK_END" do
value = @io.read
@io.seek(-1, IO::SEEK_END)
- @io.eof?.should == false
+ @io.should_not.eof?
value[-1].should == @io.read[0]
end
diff --git a/spec/ruby/core/io/select_spec.rb b/spec/ruby/core/io/select_spec.rb
index eba8519e5b..0a43fc6f5f 100644
--- a/spec/ruby/core/io/select_spec.rb
+++ b/spec/ruby/core/io/select_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "IO.select" do
before :each do
@@ -15,9 +15,15 @@ describe "IO.select" do
end
it "returns immediately all objects that are ready for I/O when timeout is 0" do
- @wr.write("be ready")
- result = IO.select [@rd], [@wr], nil, 0
- result.should == [[@rd], [@wr], []]
+ @wr.syswrite("be ready")
+ IO.pipe do |_, wr|
+ result = IO.select [@rd], [wr], nil, 0
+ unless result
+ # On some platforms (e.g., Windows), pipe readiness may not be immediate
+ result = IO.select [@rd], [wr], nil, 2
+ end
+ result.should == [[@rd], [wr], []]
+ end
end
it "returns nil after timeout if there are no objects ready for I/O" do
@@ -53,8 +59,8 @@ describe "IO.select" do
end
end
- it "returns supplied objects correctly even when monitoring the same object in different arrays" do
- filename = tmp("IO_select_pipe_file") + $$.to_s
+ it "returns supplied objects correctly when monitoring the same object in different arrays" do
+ filename = tmp("IO_select_pipe_file")
io = File.open(filename, 'w+')
result = IO.select [io], [io], nil, 0
result.should == [[io], [io], []]
@@ -62,6 +68,17 @@ describe "IO.select" do
rm_r filename
end
+ it "returns the pipe read end in read set if the pipe write end is closed concurrently" do
+ main = Thread.current
+ t = Thread.new {
+ Thread.pass until main.stop?
+ @wr.close
+ }
+ IO.select([@rd]).should == [[@rd], [], []]
+ ensure
+ t.join
+ end
+
it "invokes to_io on supplied objects that are not IO and returns the supplied objects" do
# make some data available
@wr.write("foobar")
@@ -70,47 +87,104 @@ describe "IO.select" do
obj.should_receive(:to_io).at_least(1).and_return(@rd)
IO.select([obj]).should == [[obj], [], []]
- obj = mock("write_io")
- obj.should_receive(:to_io).at_least(1).and_return(@wr)
- IO.select(nil, [obj]).should == [[], [obj], []]
+ IO.pipe do |_, wr|
+ obj = mock("write_io")
+ obj.should_receive(:to_io).at_least(1).and_return(wr)
+ IO.select(nil, [obj]).should == [[], [obj], []]
+ end
end
it "raises TypeError if supplied objects are not IO" do
- lambda { IO.select([Object.new]) }.should raise_error(TypeError)
- lambda { IO.select(nil, [Object.new]) }.should raise_error(TypeError)
+ -> { IO.select([Object.new]) }.should.raise(TypeError)
+ -> { IO.select(nil, [Object.new]) }.should.raise(TypeError)
obj = mock("io")
obj.should_receive(:to_io).any_number_of_times.and_return(nil)
- lambda { IO.select([obj]) }.should raise_error(TypeError)
- lambda { IO.select(nil, [obj]) }.should raise_error(TypeError)
+ -> { IO.select([obj]) }.should.raise(TypeError)
+ -> { IO.select(nil, [obj]) }.should.raise(TypeError)
end
it "raises a TypeError if the specified timeout value is not Numeric" do
- lambda { IO.select([@rd], nil, nil, Object.new) }.should raise_error(TypeError)
+ -> { IO.select([@rd], nil, nil, Object.new) }.should.raise(TypeError)
end
it "raises TypeError if the first three arguments are not Arrays" do
- lambda { IO.select(Object.new)}.should raise_error(TypeError)
- lambda { IO.select(nil, Object.new)}.should raise_error(TypeError)
- lambda { IO.select(nil, nil, Object.new)}.should raise_error(TypeError)
+ -> { IO.select(Object.new)}.should.raise(TypeError)
+ -> { IO.select(nil, Object.new)}.should.raise(TypeError)
+ -> { IO.select(nil, nil, Object.new)}.should.raise(TypeError)
end
it "raises an ArgumentError when passed a negative timeout" do
- lambda { IO.select(nil, nil, nil, -5)}.should raise_error(ArgumentError)
+ -> { IO.select(nil, nil, nil, -5)}.should.raise(ArgumentError, "time interval must not be negative")
+ end
+
+ ruby_version_is "4.0" do
+ it "raises an ArgumentError when passed negative infinity as timeout" do
+ -> { IO.select(nil, nil, nil, -Float::INFINITY)}.should.raise(ArgumentError, "time interval must not be negative")
+ end
+ end
+
+ it "raises an RangeError when passed NaN as timeout" do
+ -> { IO.select(nil, nil, nil, Float::NAN)}.should.raise(RangeError, "NaN out of Time range")
+ end
+
+ describe "returns the available descriptors when the file descriptor" do
+ it "is in both read and error arrays" do
+ @wr.write("foobar")
+ result = IO.select([@rd], nil, [@rd])
+ result.should == [[@rd], [], []]
+ end
+
+ it "is in both write and error arrays" do
+ result = IO.select(nil, [@wr], [@wr])
+ result.should == [[], [@wr], []]
+ end
+
+ it "is in both read and write arrays" do
+ filename = tmp("IO_select_read_write_file")
+ w = File.open(filename, 'w+')
+ begin
+ IO.select([w], [w], []).should == [[w], [w], []]
+ ensure
+ w.close
+ rm_r filename
+ end
+
+ IO.select([@wr], [@wr], []).should == [[], [@wr], []]
+
+ @wr.write("foobar")
+ # CRuby on macOS returns [[@rd], [@rd], []], weird but we accept it here, probably only for pipe read-end
+ [
+ [[@rd], [], []],
+ [[@rd], [@rd], []]
+ ].should.include? IO.select([@rd], [@rd], [])
+ end
end
end
-describe "IO.select when passed nil for timeout" do
- it "sleeps forever and sets the thread status to 'sleep'" do
- t = Thread.new do
- IO.select(nil, nil, nil, nil)
+describe "IO.select with infinite timeout" do
+ describe :io_select_infinite_timeout, shared: true do
+ it "sleeps forever and sets the thread status to 'sleep'" do
+ t = Thread.new do
+ IO.select(nil, nil, nil, @method)
+ end
+
+ Thread.pass while t.status && t.status != "sleep"
+ t.join unless t.status
+ t.status.should == "sleep"
+ t.kill
+ t.join
end
+ end
- Thread.pass while t.status && t.status != "sleep"
- t.join unless t.status
- t.status.should == "sleep"
- t.kill
- t.join
+ describe "IO.select when passed nil for timeout" do
+ it_behaves_like :io_select_infinite_timeout, nil
+ end
+
+ ruby_version_is "4.0" do
+ describe "IO.select when passed Float::INFINITY for timeout" do
+ it_behaves_like :io_select_infinite_timeout, Float::INFINITY
+ end
end
end
diff --git a/spec/ruby/core/io/set_encoding_by_bom_spec.rb b/spec/ruby/core/io/set_encoding_by_bom_spec.rb
new file mode 100644
index 0000000000..5436879f11
--- /dev/null
+++ b/spec/ruby/core/io/set_encoding_by_bom_spec.rb
@@ -0,0 +1,262 @@
+require_relative '../../spec_helper'
+
+describe "IO#set_encoding_by_bom" do
+ before :each do
+ @name = tmp('io_set_encoding_by_bom.txt')
+ touch(@name)
+ @io = new_io(@name, 'rb')
+ end
+
+ after :each do
+ @io.close unless @io.closed?
+ rm_r @name
+ end
+
+ it "returns nil if not readable" do
+ not_readable_io = new_io(@name, 'wb')
+
+ not_readable_io.set_encoding_by_bom.should == nil
+ not_readable_io.external_encoding.should == Encoding::ASCII_8BIT
+ ensure
+ not_readable_io.close
+ end
+
+ it "returns the result encoding if found BOM UTF-8 sequence" do
+ File.binwrite(@name, "\u{FEFF}")
+
+ @io.set_encoding_by_bom.should == Encoding::UTF_8
+ @io.external_encoding.should == Encoding::UTF_8
+ @io.read.b.should == "".b
+ @io.rewind
+ @io.set_encoding(Encoding::ASCII_8BIT)
+
+ File.binwrite(@name, "\u{FEFF}abc")
+
+ @io.set_encoding_by_bom.should == Encoding::UTF_8
+ @io.external_encoding.should == Encoding::UTF_8
+ @io.read.b.should == "abc".b
+ end
+
+ it "returns the result encoding if found BOM UTF_16LE sequence" do
+ File.binwrite(@name, "\xFF\xFE")
+
+ @io.set_encoding_by_bom.should == Encoding::UTF_16LE
+ @io.external_encoding.should == Encoding::UTF_16LE
+ @io.read.b.should == "".b
+ @io.rewind
+ @io.set_encoding(Encoding::ASCII_8BIT)
+
+ File.binwrite(@name, "\xFF\xFEabc")
+
+ @io.set_encoding_by_bom.should == Encoding::UTF_16LE
+ @io.external_encoding.should == Encoding::UTF_16LE
+ @io.read.b.should == "abc".b
+ end
+
+ it "returns the result encoding if found BOM UTF_16BE sequence" do
+ File.binwrite(@name, "\xFE\xFF")
+
+ @io.set_encoding_by_bom.should == Encoding::UTF_16BE
+ @io.external_encoding.should == Encoding::UTF_16BE
+ @io.read.b.should == "".b
+ @io.rewind
+ @io.set_encoding(Encoding::ASCII_8BIT)
+
+ File.binwrite(@name, "\xFE\xFFabcd")
+
+ @io.set_encoding_by_bom.should == Encoding::UTF_16BE
+ @io.external_encoding.should == Encoding::UTF_16BE
+ @io.read.b.should == "abcd".b
+ end
+
+ it "returns the result encoding if found BOM UTF_32LE sequence" do
+ File.binwrite(@name, "\xFF\xFE\x00\x00")
+
+ @io.set_encoding_by_bom.should == Encoding::UTF_32LE
+ @io.external_encoding.should == Encoding::UTF_32LE
+ @io.read.b.should == "".b
+ @io.rewind
+ @io.set_encoding(Encoding::ASCII_8BIT)
+
+ File.binwrite(@name, "\xFF\xFE\x00\x00abc")
+
+ @io.set_encoding_by_bom.should == Encoding::UTF_32LE
+ @io.external_encoding.should == Encoding::UTF_32LE
+ @io.read.b.should == "abc".b
+ end
+
+ it "returns the result encoding if found BOM UTF_32BE sequence" do
+ File.binwrite(@name, "\x00\x00\xFE\xFF")
+
+ @io.set_encoding_by_bom.should == Encoding::UTF_32BE
+ @io.external_encoding.should == Encoding::UTF_32BE
+ @io.read.b.should == "".b
+ @io.rewind
+ @io.set_encoding(Encoding::ASCII_8BIT)
+
+ File.binwrite(@name, "\x00\x00\xFE\xFFabcd")
+
+ @io.set_encoding_by_bom.should == Encoding::UTF_32BE
+ @io.external_encoding.should == Encoding::UTF_32BE
+ @io.read.b.should == "abcd".b
+ end
+
+ it "returns nil if io is empty" do
+ @io.set_encoding_by_bom.should == nil
+ @io.external_encoding.should == Encoding::ASCII_8BIT
+ end
+
+ it "returns nil if UTF-8 BOM sequence is incomplete" do
+ File.write(@name, "\xEF")
+
+ @io.set_encoding_by_bom.should == nil
+ @io.external_encoding.should == Encoding::ASCII_8BIT
+ @io.read.b.should == "\xEF".b
+ @io.rewind
+
+ File.write(@name, "\xEFa")
+
+ @io.set_encoding_by_bom.should == nil
+ @io.external_encoding.should == Encoding::ASCII_8BIT
+ @io.read.b.should == "\xEFa".b
+ @io.rewind
+
+ File.write(@name, "\xEF\xBB")
+
+ @io.set_encoding_by_bom.should == nil
+ @io.external_encoding.should == Encoding::ASCII_8BIT
+ @io.read.b.should == "\xEF\xBB".b
+ @io.rewind
+
+ File.write(@name, "\xEF\xBBa")
+
+ @io.set_encoding_by_bom.should == nil
+ @io.external_encoding.should == Encoding::ASCII_8BIT
+ @io.read.b.should == "\xEF\xBBa".b
+ end
+
+ it "returns nil if UTF-16BE BOM sequence is incomplete" do
+ File.write(@name, "\xFE")
+
+ @io.set_encoding_by_bom.should == nil
+ @io.external_encoding.should == Encoding::ASCII_8BIT
+ @io.read.b.should == "\xFE".b
+ @io.rewind
+
+ File.write(@name, "\xFEa")
+
+ @io.set_encoding_by_bom.should == nil
+ @io.external_encoding.should == Encoding::ASCII_8BIT
+ @io.read.b.should == "\xFEa".b
+ end
+
+ it "returns nil if UTF-16LE/UTF-32LE BOM sequence is incomplete" do
+ File.write(@name, "\xFF")
+
+ @io.set_encoding_by_bom.should == nil
+ @io.external_encoding.should == Encoding::ASCII_8BIT
+ @io.read.b.should == "\xFF".b
+ @io.rewind
+
+ File.write(@name, "\xFFa")
+
+ @io.set_encoding_by_bom.should == nil
+ @io.external_encoding.should == Encoding::ASCII_8BIT
+ @io.read.b.should == "\xFFa".b
+ end
+
+ it "returns UTF-16LE if UTF-32LE BOM sequence is incomplete" do
+ File.write(@name, "\xFF\xFE")
+
+ @io.set_encoding_by_bom.should == Encoding::UTF_16LE
+ @io.external_encoding.should == Encoding::UTF_16LE
+ @io.read.b.should == "".b
+ @io.rewind
+ @io.set_encoding(Encoding::ASCII_8BIT)
+
+ File.write(@name, "\xFF\xFE\x00")
+
+ @io.set_encoding_by_bom.should == Encoding::UTF_16LE
+ @io.external_encoding.should == Encoding::UTF_16LE
+ @io.read.b.should == "\x00".b
+ @io.rewind
+ @io.set_encoding(Encoding::ASCII_8BIT)
+
+ File.write(@name, "\xFF\xFE\x00a")
+
+ @io.set_encoding_by_bom.should == Encoding::UTF_16LE
+ @io.external_encoding.should == Encoding::UTF_16LE
+ @io.read.b.should == "\x00a".b
+ end
+
+ it "returns nil if UTF-32BE BOM sequence is incomplete" do
+ File.write(@name, "\x00")
+
+ @io.set_encoding_by_bom.should == nil
+ @io.external_encoding.should == Encoding::ASCII_8BIT
+ @io.read.b.should == "\x00".b
+ @io.rewind
+
+ File.write(@name, "\x00a")
+
+ @io.set_encoding_by_bom.should == nil
+ @io.external_encoding.should == Encoding::ASCII_8BIT
+ @io.read.b.should == "\x00a".b
+ @io.rewind
+
+ File.write(@name, "\x00\x00")
+
+ @io.set_encoding_by_bom.should == nil
+ @io.external_encoding.should == Encoding::ASCII_8BIT
+ @io.read.b.should == "\x00\x00".b
+ @io.rewind
+
+ File.write(@name, "\x00\x00a")
+
+ @io.set_encoding_by_bom.should == nil
+ @io.external_encoding.should == Encoding::ASCII_8BIT
+ @io.read.b.should == "\x00\x00a".b
+ @io.rewind
+
+ File.write(@name, "\x00\x00\xFE")
+
+ @io.set_encoding_by_bom.should == nil
+ @io.external_encoding.should == Encoding::ASCII_8BIT
+ @io.read.b.should == "\x00\x00\xFE".b
+ @io.rewind
+
+ File.write(@name, "\x00\x00\xFEa")
+
+ @io.set_encoding_by_bom.should == nil
+ @io.external_encoding.should == Encoding::ASCII_8BIT
+ @io.read.b.should == "\x00\x00\xFEa".b
+ end
+
+ it "returns nil if found BOM sequence not provided" do
+ File.write(@name, "abc")
+
+ @io.set_encoding_by_bom.should == nil
+ @io.external_encoding.should == Encoding::ASCII_8BIT
+ @io.read(3).should == "abc".b
+ end
+
+ it 'returns exception if io not in binary mode' do
+ not_binary_io = new_io(@name, 'r')
+
+ -> { not_binary_io.set_encoding_by_bom }.should.raise(ArgumentError, 'ASCII incompatible encoding needs binmode')
+ ensure
+ not_binary_io.close
+ end
+
+ it 'returns exception if encoding already set' do
+ @io.set_encoding("utf-8")
+
+ -> { @io.set_encoding_by_bom }.should.raise(ArgumentError, 'encoding is set to UTF-8 already')
+ end
+
+ it 'returns exception if encoding conversion is already set' do
+ @io.set_encoding(Encoding::UTF_8, Encoding::UTF_16BE)
+
+ -> { @io.set_encoding_by_bom }.should.raise(ArgumentError, 'encoding conversion is set')
+ end
+end
diff --git a/spec/ruby/core/io/set_encoding_spec.rb b/spec/ruby/core/io/set_encoding_spec.rb
index 1d6e2a8f3b..237251de5b 100644
--- a/spec/ruby/core/io/set_encoding_spec.rb
+++ b/spec/ruby/core/io/set_encoding_spec.rb
@@ -1,193 +1,238 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
-with_feature :encoding do
- describe :io_set_encoding_write, shared: true do
- it "sets the encodings to nil" do
- @io = new_io @name, "#{@object}:ibm437:ibm866"
- @io.set_encoding nil, nil
+describe :io_set_encoding_write, shared: true do
+ it "sets the encodings to nil when they were set previously" do
+ @io = new_io @name, "#{@object}:ibm437:ibm866"
+ @io.set_encoding nil, nil
- @io.external_encoding.should be_nil
- @io.internal_encoding.should be_nil
- end
+ @io.external_encoding.should == nil
+ @io.internal_encoding.should == nil
+ end
- it "prevents the encodings from changing when Encoding defaults are changed" do
- @io = new_io @name, "#{@object}:utf-8:us-ascii"
- @io.set_encoding nil, nil
+ it "sets the encodings to nil when the IO is built with no explicit encoding" do
+ @io = new_io @name, @object
- Encoding.default_external = Encoding::IBM437
- Encoding.default_internal = Encoding::IBM866
+ # Checking our assumptions first
+ @io.external_encoding.should == nil
+ @io.internal_encoding.should == nil
- @io.external_encoding.should be_nil
- @io.internal_encoding.should be_nil
- end
+ @io.set_encoding nil, nil
- it "sets the encodings to the current Encoding defaults" do
- @io = new_io @name, @object
+ @io.external_encoding.should == nil
+ @io.internal_encoding.should == nil
+ end
- Encoding.default_external = Encoding::IBM437
- Encoding.default_internal = Encoding::IBM866
+ it "prevents the encodings from changing when Encoding defaults are changed" do
+ @io = new_io @name, "#{@object}:utf-8:us-ascii"
+ @io.set_encoding nil, nil
- @io.set_encoding nil, nil
+ Encoding.default_external = Encoding::IBM437
+ Encoding.default_internal = Encoding::IBM866
- @io.external_encoding.should == Encoding::IBM437
- @io.internal_encoding.should == Encoding::IBM866
- end
+ @io.external_encoding.should == nil
+ @io.internal_encoding.should == nil
end
- describe "IO#set_encoding when passed nil, nil" do
- before :each do
- @external = Encoding.default_external
- @internal = Encoding.default_internal
+ it "sets the encodings to the current Encoding defaults" do
+ @io = new_io @name, @object
- Encoding.default_external = Encoding::UTF_8
- Encoding.default_internal = nil
+ Encoding.default_external = Encoding::IBM437
+ Encoding.default_internal = Encoding::IBM866
- @name = tmp('io_set_encoding.txt')
- touch(@name)
- end
+ @io.set_encoding nil, nil
+
+ @io.external_encoding.should == Encoding::IBM437
+ @io.internal_encoding.should == Encoding::IBM866
+ end
+end
- after :each do
- Encoding.default_external = @external
- Encoding.default_internal = @internal
+describe "IO#set_encoding when passed nil, nil" do
+ before :each do
+ @external = Encoding.default_external
+ @internal = Encoding.default_internal
- @io.close if @io and not @io.closed?
- rm_r @name
- end
+ # The defaults
+ Encoding.default_external = Encoding::UTF_8
+ Encoding.default_internal = nil
- describe "with 'r' mode" do
- it "sets the encodings to the current Encoding defaults" do
- @io = new_io @name, "r"
+ @name = tmp('io_set_encoding.txt')
+ touch(@name)
+ end
- Encoding.default_external = Encoding::IBM437
- Encoding.default_internal = Encoding::IBM866
+ after :each do
+ Encoding.default_external = @external
+ Encoding.default_internal = @internal
- @io.set_encoding nil, nil
- @io.external_encoding.should equal(Encoding::IBM437)
- @io.internal_encoding.should equal(Encoding::IBM866)
- end
+ @io.close if @io and not @io.closed?
+ rm_r @name
+ end
- it "prevents the #internal_encoding from changing when Encoding.default_internal is changed" do
- @io = new_io @name, "r"
- @io.set_encoding nil, nil
+ describe "with 'r' mode" do
+ it "sets the encodings to the current Encoding defaults" do
+ @io = new_io @name, "r"
- Encoding.default_internal = Encoding::IBM437
+ Encoding.default_external = Encoding::IBM437
+ Encoding.default_internal = Encoding::IBM866
- @io.internal_encoding.should be_nil
- end
+ @io.set_encoding nil, nil
+ @io.external_encoding.should.equal?(Encoding::IBM437)
+ @io.internal_encoding.should.equal?(Encoding::IBM866)
+ end
- it "allows the #external_encoding to change when Encoding.default_external is changed" do
- @io = new_io @name, "r"
- @io.set_encoding nil, nil
+ it "prevents the #internal_encoding from changing when Encoding.default_internal is changed" do
+ @io = new_io @name, "r"
+ @io.set_encoding nil, nil
- Encoding.default_external = Encoding::IBM437
+ Encoding.default_internal = Encoding::IBM437
- @io.external_encoding.should equal(Encoding::IBM437)
- end
+ @io.internal_encoding.should == nil
end
- describe "with 'rb' mode" do
- it "returns Encoding.default_external" do
- @io = new_io @name, "rb"
- @io.external_encoding.should equal(Encoding::ASCII_8BIT)
+ it "allows the #external_encoding to change when Encoding.default_external is changed" do
+ @io = new_io @name, "r"
+ @io.set_encoding nil, nil
- @io.set_encoding nil, nil
- @io.external_encoding.should equal(Encoding.default_external)
- end
- end
+ Encoding.default_external = Encoding::IBM437
- describe "with 'r+' mode" do
- it_behaves_like :io_set_encoding_write, nil, "r+"
+ @io.external_encoding.should.equal?(Encoding::IBM437)
end
+ end
- describe "with 'w' mode" do
- it_behaves_like :io_set_encoding_write, nil, "w"
- end
+ describe "with 'rb' mode" do
+ it "returns Encoding.default_external" do
+ @io = new_io @name, "rb"
+ @io.external_encoding.should.equal?(Encoding::BINARY)
- describe "with 'w+' mode" do
- it_behaves_like :io_set_encoding_write, nil, "w+"
+ @io.set_encoding nil, nil
+ @io.external_encoding.should.equal?(Encoding.default_external)
end
+ end
- describe "with 'a' mode" do
- it_behaves_like :io_set_encoding_write, nil, "a"
- end
+ describe "with 'r+' mode" do
+ it_behaves_like :io_set_encoding_write, nil, "r+"
+ end
- describe "with 'a+' mode" do
- it_behaves_like :io_set_encoding_write, nil, "a+"
- end
+ describe "with 'w' mode" do
+ it_behaves_like :io_set_encoding_write, nil, "w"
end
- describe "IO#set_encoding" do
- before :each do
- @name = tmp('io_set_encoding.txt')
- touch(@name)
- @io = new_io @name
- end
+ describe "with 'w+' mode" do
+ it_behaves_like :io_set_encoding_write, nil, "w+"
+ end
- after :each do
- @io.close unless @io.closed?
- rm_r @name
- end
+ describe "with 'a' mode" do
+ it_behaves_like :io_set_encoding_write, nil, "a"
+ end
- it "returns self" do
- @io.set_encoding(Encoding::UTF_8).should equal(@io)
- end
+ describe "with 'a+' mode" do
+ it_behaves_like :io_set_encoding_write, nil, "a+"
+ end
- it "sets the external encoding when passed an Encoding argument" do
- @io.set_encoding(Encoding::UTF_8)
- @io.external_encoding.should == Encoding::UTF_8
- @io.internal_encoding.should be_nil
- end
+ describe "with standard IOs" do
+ it "correctly resets them" do
+ STDOUT.external_encoding.should == nil
+ STDOUT.internal_encoding.should == nil
- it "sets the external and internal encoding when passed two Encoding arguments" do
- @io.set_encoding(Encoding::UTF_8, Encoding::UTF_16BE)
- @io.external_encoding.should == Encoding::UTF_8
- @io.internal_encoding.should == Encoding::UTF_16BE
- end
+ begin
+ STDOUT.set_encoding(Encoding::US_ASCII, Encoding::ISO_8859_1)
+ ensure
+ STDOUT.set_encoding(nil, nil)
+ end
- it "sets the external encoding when passed the name of an Encoding" do
- @io.set_encoding("utf-8")
- @io.external_encoding.should == Encoding::UTF_8
- @io.internal_encoding.should be_nil
+ STDOUT.external_encoding.should == nil
+ STDOUT.internal_encoding.should == nil
end
+ end
+end
- it "ignores the internal encoding if the same as external when passed Encoding objects" do
- @io.set_encoding(Encoding::UTF_8, Encoding::UTF_8)
- @io.external_encoding.should == Encoding::UTF_8
- @io.internal_encoding.should be_nil
- end
+describe "IO#set_encoding" do
+ before :each do
+ @name = tmp('io_set_encoding.txt')
+ touch(@name)
+ @io = new_io @name
+ end
- it "ignores the internal encoding if the same as external when passed encoding names separanted by ':'" do
- @io.set_encoding("utf-8:utf-8")
- @io.external_encoding.should == Encoding::UTF_8
- @io.internal_encoding.should be_nil
- end
+ after :each do
+ @io.close unless @io.closed?
+ rm_r @name
+ end
- it "sets the external and internal encoding when passed the names of Encodings separated by ':'" do
- @io.set_encoding("utf-8:utf-16be")
- @io.external_encoding.should == Encoding::UTF_8
- @io.internal_encoding.should == Encoding::UTF_16BE
- end
+ it "returns self" do
+ @io.set_encoding(Encoding::UTF_8).should.equal?(@io)
+ end
- it "sets the external and internal encoding when passed two String arguments" do
- @io.set_encoding("utf-8", "utf-16be")
- @io.external_encoding.should == Encoding::UTF_8
- @io.internal_encoding.should == Encoding::UTF_16BE
- end
+ it "sets the external encoding when passed an Encoding argument" do
+ @io.set_encoding(Encoding::UTF_8)
+ @io.external_encoding.should == Encoding::UTF_8
+ @io.internal_encoding.should == nil
+ end
- it "calls #to_str to convert an abject to a String" do
- obj = mock("io_set_encoding")
- obj.should_receive(:to_str).and_return("utf-8:utf-16be")
- @io.set_encoding(obj)
- @io.external_encoding.should == Encoding::UTF_8
- @io.internal_encoding.should == Encoding::UTF_16BE
- end
+ it "sets the external and internal encoding when passed two Encoding arguments" do
+ @io.set_encoding(Encoding::UTF_8, Encoding::UTF_16BE)
+ @io.external_encoding.should == Encoding::UTF_8
+ @io.internal_encoding.should == Encoding::UTF_16BE
+ end
- it "calls #to_str to convert the second argument to a String" do
- obj = mock("io_set_encoding")
- obj.should_receive(:to_str).at_least(1).times.and_return("utf-16be")
- @io.set_encoding(Encoding::UTF_8, obj)
- @io.external_encoding.should == Encoding::UTF_8
- @io.internal_encoding.should == Encoding::UTF_16BE
- end
+ it "sets the external encoding when passed the name of an Encoding" do
+ @io.set_encoding("utf-8")
+ @io.external_encoding.should == Encoding::UTF_8
+ @io.internal_encoding.should == nil
+ end
+
+ it "ignores the internal encoding if the same as external when passed Encoding objects" do
+ @io.set_encoding(Encoding::UTF_8, Encoding::UTF_8)
+ @io.external_encoding.should == Encoding::UTF_8
+ @io.internal_encoding.should == nil
+ end
+
+ it "ignores the internal encoding if the same as external when passed encoding names separated by ':'" do
+ @io.set_encoding("utf-8:utf-8")
+ @io.external_encoding.should == Encoding::UTF_8
+ @io.internal_encoding.should == nil
+ end
+
+ it "sets the external and internal encoding when passed the names of Encodings separated by ':'" do
+ @io.set_encoding("utf-8:utf-16be")
+ @io.external_encoding.should == Encoding::UTF_8
+ @io.internal_encoding.should == Encoding::UTF_16BE
+ end
+
+ it "sets the external and internal encoding when passed two String arguments" do
+ @io.set_encoding("utf-8", "utf-16be")
+ @io.external_encoding.should == Encoding::UTF_8
+ @io.internal_encoding.should == Encoding::UTF_16BE
+ end
+
+ it "calls #to_str to convert an abject to a String" do
+ obj = mock("io_set_encoding")
+ obj.should_receive(:to_str).and_return("utf-8:utf-16be")
+ @io.set_encoding(obj)
+ @io.external_encoding.should == Encoding::UTF_8
+ @io.internal_encoding.should == Encoding::UTF_16BE
+ end
+
+ it "calls #to_str to convert the second argument to a String" do
+ obj = mock("io_set_encoding")
+ obj.should_receive(:to_str).at_least(1).times.and_return("utf-16be")
+ @io.set_encoding(Encoding::UTF_8, obj)
+ @io.external_encoding.should == Encoding::UTF_8
+ @io.internal_encoding.should == Encoding::UTF_16BE
+ end
+
+ it "saves encoding options passed as a hash in the last argument" do
+ File.write(@name, "\xff")
+ io = File.open(@name)
+ io.set_encoding(Encoding::EUC_JP, Encoding::SHIFT_JIS, invalid: :replace, replace: ".")
+ io.read.should == "."
+ ensure
+ io.close
+ end
+
+ it "raises ArgumentError when no arguments are given" do
+ -> { @io.set_encoding() }.should.raise(ArgumentError)
+ end
+
+ it "raises ArgumentError when too many arguments are given" do
+ -> { @io.set_encoding(1, 2, 3) }.should.raise(ArgumentError)
end
end
diff --git a/spec/ruby/core/io/shared/binwrite.rb b/spec/ruby/core/io/shared/binwrite.rb
index 67f0fd5c86..64793b1936 100644
--- a/spec/ruby/core/io/shared/binwrite.rb
+++ b/spec/ruby/core/io/shared/binwrite.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../fixtures/classes', __FILE__)
+require_relative '../fixtures/classes'
describe :io_binwrite, shared: true do
before :each do
@@ -21,12 +21,20 @@ describe :io_binwrite, shared: true do
IO.send(@method, @filename, "abcde").should == 5
end
+ it "accepts options as a keyword argument" do
+ IO.send(@method, @filename, "hi", 0, flags: File::CREAT).should == 2
+
+ -> {
+ IO.send(@method, @filename, "hi", 0, {flags: File::CREAT})
+ }.should.raise(ArgumentError, "wrong number of arguments (given 4, expected 2..3)")
+ end
+
it "creates a file if missing" do
fn = @filename + "xxx"
begin
- File.exist?(fn).should be_false
+ File.should_not.exist?(fn)
IO.send(@method, fn, "test")
- File.exist?(fn).should be_true
+ File.should.exist?(fn)
ensure
rm_r fn
end
@@ -35,9 +43,9 @@ describe :io_binwrite, shared: true do
it "creates file if missing even if offset given" do
fn = @filename + "xxx"
begin
- File.exist?(fn).should be_false
+ File.should_not.exist?(fn)
IO.send(@method, fn, "test", 0)
- File.exist?(fn).should be_true
+ File.should.exist?(fn)
ensure
rm_r fn
end
@@ -56,7 +64,7 @@ describe :io_binwrite, shared: true do
end
it "doesn't truncate and writes at the given offset after passing empty opts" do
- IO.send(@method, @filename, "hello world!", 1, {})
+ IO.send(@method, @filename, "hello world!", 1, **{})
File.read(@filename).should == "0hello world!34567890123456789"
end
@@ -67,12 +75,17 @@ describe :io_binwrite, shared: true do
File.read(@filename).should == "\0\0foo"
end
+ it "accepts a :flags option without :mode one" do
+ IO.send(@method, @filename, "hello, world!", flags: File::CREAT)
+ File.read(@filename).should == "hello, world!"
+ end
+
it "raises an error if readonly mode is specified" do
- lambda { IO.send(@method, @filename, "abcde", mode: "r") }.should raise_error(IOError)
+ -> { IO.send(@method, @filename, "abcde", mode: "r") }.should.raise(IOError)
end
it "truncates if empty :opts provided and offset skipped" do
- IO.send(@method, @filename, "hello, world!", {})
+ IO.send(@method, @filename, "hello, world!", **{})
File.read(@filename).should == "hello, world!"
end
end
diff --git a/spec/ruby/core/io/shared/chars.rb b/spec/ruby/core/io/shared/chars.rb
deleted file mode 100644
index 7f2edd2b6d..0000000000
--- a/spec/ruby/core/io/shared/chars.rb
+++ /dev/null
@@ -1,73 +0,0 @@
-# -*- encoding: utf-8 -*-
-describe :io_chars, shared: true do
- before :each do
- @io = IOSpecs.io_fixture "lines.txt"
- ScratchPad.record []
- end
-
- after :each do
- @io.close unless @io.closed?
- end
-
- it "yields each character" do
- @io.readline.should == "Voici la ligne une.\n"
-
- count = 0
- @io.send(@method) do |c|
- ScratchPad << c
- break if 4 < count += 1
- end
-
- ScratchPad.recorded.should == ["Q", "u", "i", " ", "è"]
- end
-
- describe "when no block is given" do
- it "returns an Enumerator" do
- enum = @io.send(@method)
- enum.should be_an_instance_of(Enumerator)
- enum.first(5).should == ["V", "o", "i", "c", "i"]
- end
-
- describe "returned Enumerator" do
- describe "size" do
- it "should return nil" do
- @io.send(@method).size.should == nil
- end
- end
- end
- end
-
- it "returns itself" do
- @io.send(@method) { |c| }.should equal(@io)
- end
-
- it "returns an enumerator for a closed stream" do
- IOSpecs.closed_io.send(@method).should be_an_instance_of(Enumerator)
- end
-
- it "raises an IOError when an enumerator created on a closed stream is accessed" do
- lambda { IOSpecs.closed_io.send(@method).first }.should raise_error(IOError)
- end
-
- it "raises IOError on closed stream" do
- lambda { IOSpecs.closed_io.send(@method) {} }.should raise_error(IOError)
- end
-end
-
-describe :io_chars_empty, shared: true do
- before :each do
- @name = tmp("io_each_char")
- @io = new_io @name, "w+:utf-8"
- ScratchPad.record []
- end
-
- after :each do
- @io.close unless @io.closed?
- rm_r @name
- end
-
- it "does not yield any characters on an empty stream" do
- @io.send(@method) { |c| ScratchPad << c }
- ScratchPad.recorded.should == []
- end
-end
diff --git a/spec/ruby/core/io/shared/codepoints.rb b/spec/ruby/core/io/shared/codepoints.rb
deleted file mode 100644
index 3bb3dce939..0000000000
--- a/spec/ruby/core/io/shared/codepoints.rb
+++ /dev/null
@@ -1,54 +0,0 @@
-# -*- encoding: utf-8 -*-
-require File.expand_path('../../fixtures/classes', __FILE__)
-
-describe :io_codepoints, shared: true do
- before :each do
- @io = IOSpecs.io_fixture "lines.txt"
- @enum = @io.send(@method)
- end
-
- after :each do
- @io.close
- end
-
- describe "when no block is given" do
- it "returns an Enumerator" do
- @enum.should be_an_instance_of(Enumerator)
- end
-
- describe "returned Enumerator" do
- describe "size" do
- it "should return nil" do
- @enum.size.should == nil
- end
- end
- end
- end
-
- it "yields each codepoint" do
- @enum.first(25).should == [
- 86, 111, 105, 99, 105, 32, 108, 97, 32, 108, 105, 103, 110,
- 101, 32, 117, 110, 101, 46, 10, 81, 117, 105, 32, 232
- ]
- end
-
- it "yields each codepoint starting from the current position" do
- @io.pos = 130
- @enum.to_a.should == [101, 32, 115, 105, 120, 46, 10]
- end
-
- it "raises an error if reading invalid sequence" do
- @io.pos = 60 # inside of a multibyte sequence
- lambda { @enum.first }.should raise_error(ArgumentError)
- end
-
- it "does not change $_" do
- $_ = "test"
- @enum.to_a
- $_.should == "test"
- end
-
- it "raises an IOError when self is not readable" do
- lambda { IOSpecs.closed_io.send(@method).to_a }.should raise_error(IOError)
- end
-end
diff --git a/spec/ruby/core/io/shared/each.rb b/spec/ruby/core/io/shared/each.rb
deleted file mode 100644
index d87303b54a..0000000000
--- a/spec/ruby/core/io/shared/each.rb
+++ /dev/null
@@ -1,144 +0,0 @@
-# -*- encoding: utf-8 -*-
-require File.expand_path('../../fixtures/classes', __FILE__)
-
-describe :io_each, shared: true do
- before :each do
- @io = IOSpecs.io_fixture "lines.txt"
- ScratchPad.record []
- end
-
- after :each do
- @io.close if @io
- end
-
- describe "with no separator" do
- it "yields each line to the passed block" do
- @io.send(@method) { |s| ScratchPad << s }
- ScratchPad.recorded.should == IOSpecs.lines
- end
-
- it "yields each line starting from the current position" do
- @io.pos = 41
- @io.send(@method) { |s| ScratchPad << s }
- ScratchPad.recorded.should == IOSpecs.lines[2..-1]
- end
-
- it "returns self" do
- @io.send(@method) { |l| l }.should equal(@io)
- end
-
- it "does not change $_" do
- $_ = "test"
- @io.send(@method) { |s| s }
- $_.should == "test"
- end
-
- it "returns self" do
- @io.send(@method) { |l| l }.should equal(@io)
- end
-
- it "raises an IOError when self is not readable" do
- lambda { IOSpecs.closed_io.send(@method) {} }.should raise_error(IOError)
- end
-
- it "makes line count accessible via lineno" do
- @io.send(@method) { ScratchPad << @io.lineno }
- ScratchPad.recorded.should == [ 1,2,3,4,5,6,7,8,9 ]
- end
-
- it "makes line count accessible via $." do
- @io.send(@method) { ScratchPad << $. }
- ScratchPad.recorded.should == [ 1,2,3,4,5,6,7,8,9 ]
- end
-
- describe "when no block is given" do
- it "returns an Enumerator" do
- enum = @io.send(@method)
- enum.should be_an_instance_of(Enumerator)
-
- enum.each { |l| ScratchPad << l }
- ScratchPad.recorded.should == IOSpecs.lines
- end
-
- describe "returned Enumerator" do
- describe "size" do
- it "should return nil" do
- @io.send(@method).size.should == nil
- end
- end
- end
- end
- end
-
- describe "with limit" do
- describe "when limit is 0" do
- it "raises an ArgumentError" do
- # must pass block so Enumerator is evaluated and raises
- lambda { @io.send(@method, 0){} }.should raise_error(ArgumentError)
- end
- end
- end
-
- describe "when passed a String containing one space as a separator" do
- it "uses the passed argument as the line separator" do
- @io.send(@method, " ") { |s| ScratchPad << s }
- ScratchPad.recorded.should == IOSpecs.lines_space_separator
- end
-
- it "does not change $_" do
- $_ = "test"
- @io.send(@method, " ") { |s| }
- $_.should == "test"
- end
-
- it "tries to convert the passed separator to a String using #to_str" do
- obj = mock("to_str")
- obj.stub!(:to_str).and_return(" ")
-
- @io.send(@method, obj) { |l| ScratchPad << l }
- ScratchPad.recorded.should == IOSpecs.lines_space_separator
- end
- end
-
- describe "when passed nil as a separator" do
- it "yields self's content starting from the current position when the passed separator is nil" do
- @io.pos = 100
- @io.send(@method, nil) { |s| ScratchPad << s }
- ScratchPad.recorded.should == ["qui a linha cinco.\nHere is line six.\n"]
- end
- end
-
- describe "when passed an empty String as a separator" do
- it "yields each paragraph" do
- @io.send(@method, "") { |s| ScratchPad << s }
- ScratchPad.recorded.should == IOSpecs.paragraphs
- end
- end
-
- ruby_version_is "2.4" do
- describe "when passed chomp" do
- it "yields each line without trailing newline characters to the passed block" do
- @io.send(@method, chomp: true) { |s| ScratchPad << s }
- ScratchPad.recorded.should == IOSpecs.lines_without_newline_characters
- end
- end
- end
-end
-
-describe :io_each_default_separator, shared: true do
- before :each do
- @io = IOSpecs.io_fixture "lines.txt"
- ScratchPad.record []
- @sep, $/ = $/, " "
- end
-
- after :each do
- @io.close if @io
- $/ = @sep
- end
-
- it "uses $/ as the default line separator" do
- @io.send(@method) { |s| ScratchPad << s }
- ScratchPad.recorded.should == IOSpecs.lines_space_separator
- end
-end
diff --git a/spec/ruby/core/io/shared/gets_ascii.rb b/spec/ruby/core/io/shared/gets_ascii.rb
index 2a8fe3c9a5..2bd5470d99 100644
--- a/spec/ruby/core/io/shared/gets_ascii.rb
+++ b/spec/ruby/core/io/shared/gets_ascii.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
describe :io_gets_ascii, shared: true do
describe "with ASCII separator" do
before :each do
diff --git a/spec/ruby/core/io/shared/new.rb b/spec/ruby/core/io/shared/new.rb
index 12f889f646..6f318ddee5 100644
--- a/spec/ruby/core/io/shared/new.rb
+++ b/spec/ruby/core/io/shared/new.rb
@@ -1,4 +1,6 @@
-require File.expand_path('../../fixtures/classes', __FILE__)
+require_relative '../fixtures/classes'
+
+# NOTE: should be synchronized with library/stringio/initialize_spec.rb
# This group of specs may ONLY contain specs that do successfully create
# an IO instance from the file descriptor returned by #new_fd helper.
@@ -18,48 +20,57 @@ describe :io_new, shared: true do
rm_r @name
end
- it "creates an IO instance from a Fixnum argument" do
+ it "creates an IO instance from an Integer argument" do
@io = IO.send(@method, @fd, "w")
- @io.should be_an_instance_of(IO)
+ @io.should.instance_of?(IO)
end
it "creates an IO instance when STDOUT is closed" do
- verbose, $VERBOSE = $VERBOSE, nil
- stdout = STDOUT
- stdout_file = tmp("stdout.txt")
-
- begin
- @io = IO.send(@method, @fd, "w")
- @io.should be_an_instance_of(IO)
- ensure
- STDOUT = stdout
- $VERBOSE = verbose
- rm_r stdout_file
+ suppress_warning do
+ stdout = STDOUT
+ stdout_file = tmp("stdout.txt")
+
+ begin
+ @io = IO.send(@method, @fd, "w")
+ @io.should.instance_of?(IO)
+ ensure
+ STDOUT = stdout
+ rm_r stdout_file
+ end
end
end
it "creates an IO instance when STDERR is closed" do
- verbose, $VERBOSE = $VERBOSE, nil
- stderr = STDERR
- stderr_file = tmp("stderr.txt")
- STDERR = new_io stderr_file
- STDERR.close
-
- begin
- @io = IO.send(@method, @fd, "w")
- @io.should be_an_instance_of(IO)
- ensure
- STDERR = stderr
- $VERBOSE = verbose
- rm_r stderr_file
+ suppress_warning do
+ stderr = STDERR
+ stderr_file = tmp("stderr.txt")
+ STDERR = new_io stderr_file
+ STDERR.close
+
+ begin
+ @io = IO.send(@method, @fd, "w")
+ @io.should.instance_of?(IO)
+ ensure
+ STDERR = stderr
+ rm_r stderr_file
+ end
end
end
- it "calls #to_int on an object to convert to a Fixnum" do
+ it "calls #to_int on an object to convert to an Integer" do
obj = mock("file descriptor")
obj.should_receive(:to_int).and_return(@fd)
@io = IO.send(@method, obj, "w")
- @io.should be_an_instance_of(IO)
+ @io.should.instance_of?(IO)
+ end
+
+ it "accepts options as keyword arguments" do
+ @io = IO.send(@method, @fd, "w", flags: File::CREAT)
+ @io.write("foo").should == 3
+
+ -> {
+ IO.send(@method, @fd, "w", {flags: File::CREAT})
+ }.should.raise(ArgumentError, "wrong number of arguments (given 3, expected 1..2)")
end
it "accepts a :mode option" do
@@ -89,92 +100,92 @@ describe :io_new, shared: true do
end
it "uses the external encoding specified via the :external_encoding option" do
- @io = IO.send(@method, @fd, 'w', {external_encoding: 'utf-8'})
+ @io = IO.send(@method, @fd, 'w', external_encoding: 'utf-8')
@io.external_encoding.to_s.should == 'UTF-8'
end
it "uses the internal encoding specified via the :internal_encoding option" do
- @io = IO.send(@method, @fd, 'w', {internal_encoding: 'ibm866'})
+ @io = IO.send(@method, @fd, 'w', internal_encoding: 'ibm866')
@io.internal_encoding.to_s.should == 'IBM866'
end
it "uses the colon-separated encodings specified via the :encoding option" do
- @io = IO.send(@method, @fd, 'w', {encoding: 'utf-8:ISO-8859-1'})
+ @io = IO.send(@method, @fd, 'w', encoding: 'utf-8:ISO-8859-1')
@io.external_encoding.to_s.should == 'UTF-8'
@io.internal_encoding.to_s.should == 'ISO-8859-1'
end
it "uses the :encoding option as the external encoding when only one is given" do
- @io = IO.send(@method, @fd, 'w', {encoding: 'ISO-8859-1'})
+ @io = IO.send(@method, @fd, 'w', encoding: 'ISO-8859-1')
@io.external_encoding.to_s.should == 'ISO-8859-1'
end
it "uses the :encoding options as the external encoding when it's an Encoding object" do
- @io = IO.send(@method, @fd, 'w', {encoding: Encoding::ISO_8859_1})
+ @io = IO.send(@method, @fd, 'w', encoding: Encoding::ISO_8859_1)
@io.external_encoding.should == Encoding::ISO_8859_1
end
it "ignores the :encoding option when the :external_encoding option is present" do
- lambda {
- @io = IO.send(@method, @fd, 'w', {external_encoding: 'utf-8', encoding: 'iso-8859-1:iso-8859-1'})
+ -> {
+ @io = IO.send(@method, @fd, 'w', external_encoding: 'utf-8', encoding: 'iso-8859-1:iso-8859-1')
}.should complain(/Ignoring encoding parameter/)
@io.external_encoding.to_s.should == 'UTF-8'
end
it "ignores the :encoding option when the :internal_encoding option is present" do
- lambda {
- @io = IO.send(@method, @fd, 'w', {internal_encoding: 'ibm866', encoding: 'iso-8859-1:iso-8859-1'})
+ -> {
+ @io = IO.send(@method, @fd, 'w', internal_encoding: 'ibm866', encoding: 'iso-8859-1:iso-8859-1')
}.should complain(/Ignoring encoding parameter/)
@io.internal_encoding.to_s.should == 'IBM866'
end
it "uses the encoding specified via the :mode option hash" do
- @io = IO.send(@method, @fd, {mode: 'w:utf-8:ISO-8859-1'})
+ @io = IO.send(@method, @fd, mode: 'w:utf-8:ISO-8859-1')
@io.external_encoding.to_s.should == 'UTF-8'
@io.internal_encoding.to_s.should == 'ISO-8859-1'
end
it "ignores the :internal_encoding option when the same as the external encoding" do
- @io = IO.send(@method, @fd, 'w', {external_encoding: 'utf-8', internal_encoding: 'utf-8'})
+ @io = IO.send(@method, @fd, 'w', external_encoding: 'utf-8', internal_encoding: 'utf-8')
@io.external_encoding.to_s.should == 'UTF-8'
@io.internal_encoding.to_s.should == ''
end
it "sets internal encoding to nil when passed '-'" do
- @io = IO.send(@method, @fd, 'w', {external_encoding: 'utf-8', internal_encoding: '-'})
+ @io = IO.send(@method, @fd, 'w', external_encoding: 'utf-8', internal_encoding: '-')
@io.external_encoding.to_s.should == 'UTF-8'
@io.internal_encoding.to_s.should == ''
end
it "sets binmode from mode string" do
@io = IO.send(@method, @fd, 'wb')
- @io.binmode?.should == true
+ @io.should.binmode?
end
it "does not set binmode without being asked" do
@io = IO.send(@method, @fd, 'w')
- @io.binmode?.should == false
+ @io.should_not.binmode?
end
it "sets binmode from :binmode option" do
- @io = IO.send(@method, @fd, 'w', {binmode: true})
- @io.binmode?.should == true
+ @io = IO.send(@method, @fd, 'w', binmode: true)
+ @io.should.binmode?
end
it "does not set binmode from false :binmode" do
- @io = IO.send(@method, @fd, 'w', {binmode: false})
- @io.binmode?.should == false
+ @io = IO.send(@method, @fd, 'w', binmode: false)
+ @io.should_not.binmode?
end
it "sets external encoding to binary with binmode in mode string" do
@io = IO.send(@method, @fd, 'wb')
- @io.external_encoding.to_s.should == 'ASCII-8BIT'
+ @io.external_encoding.should == Encoding::BINARY
end
# #5917
it "sets external encoding to binary with :binmode option" do
- @io = IO.send(@method, @fd, 'w', {binmode: true})
- @io.external_encoding.to_s.should == 'ASCII-8BIT'
+ @io = IO.send(@method, @fd, 'w', binmode: true)
+ @io.external_encoding.should == Encoding::BINARY
end
it "does not use binary encoding when mode encoding is specified" do
@@ -197,9 +208,30 @@ describe :io_new, shared: true do
@io.internal_encoding.to_s.should == 'IBM866'
end
- it "accepts nil options" do
- @io = IO.send(@method, @fd, 'w', nil)
- @io.write("foo").should == 3
+ it "does not use binary encoding when mode encoding is specified along with binmode: true option" do
+ @io = IO.send(@method, @fd, 'w:iso-8859-1', binmode: true)
+ @io.external_encoding.to_s.should == 'ISO-8859-1'
+ end
+
+ it "does not use textmode argument when mode encoding is specified" do
+ @io = IO.send(@method, @fd, 'w:ascii-8bit', textmode: true)
+ @io.external_encoding.to_s.should == 'ASCII-8BIT'
+ end
+
+ it "does not use binmode argument when external encoding is specified via the :external_encoding option" do
+ @io = IO.send(@method, @fd, 'w', binmode: true, external_encoding: 'iso-8859-1')
+ @io.external_encoding.to_s.should == 'ISO-8859-1'
+ end
+
+ it "does not use textmode argument when external encoding is specified via the :external_encoding option" do
+ @io = IO.send(@method, @fd, 'w', textmode: true, external_encoding: 'ascii-8bit')
+ @io.external_encoding.to_s.should == 'ASCII-8BIT'
+ end
+
+ it "raises ArgumentError for nil options" do
+ -> {
+ IO.send(@method, @fd, 'w', nil)
+ }.should.raise(ArgumentError)
end
it "coerces mode with #to_str" do
@@ -247,24 +279,24 @@ describe :io_new, shared: true do
it "coerces options as third argument with #to_hash" do
options = mock("options")
options.should_receive(:to_hash).and_return({})
- @io = IO.send(@method, @fd, 'w', options)
+ @io = IO.send(@method, @fd, 'w', **options)
end
it "coerces options as second argument with #to_hash" do
options = mock("options")
options.should_receive(:to_hash).and_return({})
- @io = IO.send(@method, @fd, options)
+ @io = IO.send(@method, @fd, **options)
end
it "accepts an :autoclose option" do
@io = IO.send(@method, @fd, 'w', autoclose: false)
- @io.autoclose?.should == false
+ @io.should_not.autoclose?
@io.autoclose = true
end
it "accepts any truthy option :autoclose" do
@io = IO.send(@method, @fd, 'w', autoclose: 42)
- @io.autoclose?.should == true
+ @io.should.autoclose?
end
end
@@ -282,97 +314,100 @@ describe :io_new_errors, shared: true do
end
it "raises an Errno::EBADF if the file descriptor is not valid" do
- lambda { IO.send(@method, -1, "w") }.should raise_error(Errno::EBADF)
+ -> { IO.send(@method, -1, "w") }.should.raise(Errno::EBADF)
end
it "raises an IOError if passed a closed stream" do
- lambda { IO.send(@method, IOSpecs.closed_io.fileno, 'w') }.should raise_error(IOError)
+ -> { IO.send(@method, IOSpecs.closed_io.fileno, 'w') }.should.raise(IOError)
end
platform_is_not :windows do
it "raises an Errno::EINVAL if the new mode is not compatible with the descriptor's current mode" do
- lambda { IO.send(@method, @fd, "r") }.should raise_error(Errno::EINVAL)
+ -> { IO.send(@method, @fd, "r") }.should.raise(Errno::EINVAL)
end
end
it "raises ArgumentError if passed an empty mode string" do
- lambda { IO.send(@method, @fd, "") }.should raise_error(ArgumentError)
+ -> { IO.send(@method, @fd, "") }.should.raise(ArgumentError)
end
it "raises an error if passed modes two ways" do
- lambda {
+ -> {
IO.send(@method, @fd, "w", mode: "w")
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
end
it "raises an error if passed encodings two ways" do
- lambda {
- @io = IO.send(@method, @fd, 'w:ISO-8859-1', {encoding: 'ISO-8859-1'})
- }.should raise_error(ArgumentError)
- lambda {
- @io = IO.send(@method, @fd, 'w:ISO-8859-1', {external_encoding: 'ISO-8859-1'})
- }.should raise_error(ArgumentError)
- lambda {
- @io = IO.send(@method, @fd, 'w:ISO-8859-1:UTF-8', {internal_encoding: 'ISO-8859-1'})
- }.should raise_error(ArgumentError)
+ -> {
+ @io = IO.send(@method, @fd, 'w:ISO-8859-1', encoding: 'ISO-8859-1')
+ }.should.raise(ArgumentError)
+ -> {
+ @io = IO.send(@method, @fd, 'w:ISO-8859-1', external_encoding: 'ISO-8859-1')
+ }.should.raise(ArgumentError)
+ -> {
+ @io = IO.send(@method, @fd, 'w:ISO-8859-1', internal_encoding: 'ISO-8859-1')
+ }.should.raise(ArgumentError)
+ -> {
+ @io = IO.send(@method, @fd, 'w:ISO-8859-1:UTF-8', internal_encoding: 'ISO-8859-1')
+ }.should.raise(ArgumentError)
end
it "raises an error if passed matching binary/text mode two ways" do
- lambda {
+ -> {
@io = IO.send(@method, @fd, "wb", binmode: true)
- }.should raise_error(ArgumentError)
- lambda {
+ }.should.raise(ArgumentError)
+ -> {
@io = IO.send(@method, @fd, "wt", textmode: true)
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
- lambda {
+ -> {
@io = IO.send(@method, @fd, "wb", textmode: false)
- }.should raise_error(ArgumentError)
- lambda {
+ }.should.raise(ArgumentError)
+ -> {
@io = IO.send(@method, @fd, "wt", binmode: false)
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
end
it "raises an error if passed conflicting binary/text mode two ways" do
- lambda {
+ -> {
@io = IO.send(@method, @fd, "wb", binmode: false)
- }.should raise_error(ArgumentError)
- lambda {
+ }.should.raise(ArgumentError)
+ -> {
@io = IO.send(@method, @fd, "wt", textmode: false)
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
- lambda {
+ -> {
@io = IO.send(@method, @fd, "wb", textmode: true)
- }.should raise_error(ArgumentError)
- lambda {
+ }.should.raise(ArgumentError)
+ -> {
@io = IO.send(@method, @fd, "wt", binmode: true)
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
end
it "raises an error when trying to set both binmode and textmode" do
- lambda {
+ -> {
@io = IO.send(@method, @fd, "w", textmode: true, binmode: true)
- }.should raise_error(ArgumentError)
- lambda {
+ }.should.raise(ArgumentError)
+ -> {
@io = IO.send(@method, @fd, File::Constants::WRONLY, textmode: true, binmode: true)
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
end
it "raises ArgumentError if not passed a hash or nil for options" do
- lambda {
+ -> {
@io = IO.send(@method, @fd, 'w', false)
- }.should raise_error(ArgumentError)
- lambda {
+ }.should.raise(ArgumentError)
+ -> {
@io = IO.send(@method, @fd, false, false)
- }.should raise_error(ArgumentError)
- lambda {
+ }.should.raise(ArgumentError)
+ -> {
@io = IO.send(@method, @fd, nil, false)
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
end
- it "raises TypeError if passed a hash for mode and nil for options" do
- lambda {
+ it "raises ArgumentError if passed a hash for mode and nil for options" do
+ -> {
@io = IO.send(@method, @fd, {mode: 'w'}, nil)
- }.should raise_error(TypeError)
+ }.should.raise(ArgumentError)
end
end
diff --git a/spec/ruby/core/io/shared/pos.rb b/spec/ruby/core/io/shared/pos.rb
index fef7ab2bf7..450058e159 100644
--- a/spec/ruby/core/io/shared/pos.rb
+++ b/spec/ruby/core/io/shared/pos.rb
@@ -1,37 +1,3 @@
-describe :io_pos, shared: true do
- before :each do
- @fname = tmp('test.txt')
- File.open(@fname, 'w') { |f| f.write "123" }
- end
-
- after :each do
- rm_r @fname
- end
-
- it "gets the offset" do
- File.open @fname do |f|
- f.send(@method).should == 0
- f.read 1
- f.send(@method).should == 1
- f.read 2
- f.send(@method).should == 3
- end
- end
-
- it "raises IOError on closed stream" do
- lambda { IOSpecs.closed_io.send(@method) }.should raise_error(IOError)
- end
-
- it "resets #eof?" do
- open @fname do |io|
- io.read 1
- io.read 1
- io.send(@method)
- io.eof?.should == false
- end
- end
-end
-
describe :io_set_pos, shared: true do
before :each do
@fname = tmp('test.txt')
@@ -60,13 +26,19 @@ describe :io_set_pos, shared: true do
end
end
- it "does not accept Bignums that don't fit in a C long" do
+ it "raises TypeError when cannot convert implicitly argument to Integer" do
+ File.open @fname do |io|
+ -> { io.send @method, Object.new }.should.raise(TypeError, "no implicit conversion of Object into Integer")
+ end
+ end
+
+ it "does not accept Integers that don't fit in a C off_t" do
File.open @fname do |io|
- lambda { io.send @method, 2**128 }.should raise_error(RangeError)
+ -> { io.send @method, 2**128 }.should.raise(RangeError)
end
end
it "raises IOError on closed stream" do
- lambda { IOSpecs.closed_io.send @method, 0 }.should raise_error(IOError)
+ -> { IOSpecs.closed_io.send @method, 0 }.should.raise(IOError)
end
end
diff --git a/spec/ruby/core/io/shared/readlines.rb b/spec/ruby/core/io/shared/readlines.rb
index f545d8876a..f54fccc2e3 100644
--- a/spec/ruby/core/io/shared/readlines.rb
+++ b/spec/ruby/core/io/shared/readlines.rb
@@ -1,11 +1,11 @@
describe :io_readlines, shared: true do
it "raises TypeError if the first parameter is nil" do
- lambda { IO.send(@method, nil, &@object) }.should raise_error(TypeError)
+ -> { IO.send(@method, nil, &@object) }.should.raise(TypeError)
end
it "raises an Errno::ENOENT if the file does not exist" do
name = tmp("nonexistent.txt")
- lambda { IO.send(@method, name, &@object) }.should raise_error(Errno::ENOENT)
+ -> { IO.send(@method, name, &@object) }.should.raise(Errno::ENOENT)
end
it "yields a single string with entire content when the separator is nil" do
@@ -18,11 +18,9 @@ describe :io_readlines, shared: true do
(result ? result : ScratchPad.recorded).should == IOSpecs.lines_empty_separator
end
- ruby_version_is "2.4" do
- it "yields a sequence of lines without trailing newline characters when chomp is passed" do
- result = IO.send(@method, @name, chomp: true, &@object)
- (result ? result : ScratchPad.recorded).should == IOSpecs.lines_without_newline_characters
- end
+ it "yields a sequence of lines without trailing newline characters when chomp is passed" do
+ result = IO.send(@method, @name, chomp: true, &@object)
+ (result ? result : ScratchPad.recorded).should == IOSpecs.lines_without_newline_characters
end
end
@@ -56,25 +54,40 @@ describe :io_readlines_options_19, shared: true do
(result ? result : ScratchPad.recorded).should == IOSpecs.lines_space_separator
end
- describe "when the object is a Fixnum" do
+ describe "when the object is an Integer" do
before :each do
@sep = $/
end
after :each do
- $/ = @sep
+ suppress_warning {$/ = @sep}
end
it "defaults to $/ as the separator" do
- $/ = " "
+ suppress_warning {$/ = " "}
result = IO.send(@method, @name, 10, &@object)
(result ? result : ScratchPad.recorded).should == IOSpecs.lines_space_separator_limit
end
- it "uses the object as a limit if it is a Fixnum" do
+ it "uses the object as a limit if it is an Integer" do
result = IO.send(@method, @name, 10, &@object)
(result ? result : ScratchPad.recorded).should == IOSpecs.lines_limit
end
+
+ it "ignores the object as a limit if it is negative" do
+ result = IO.send(@method, @name, -2, &@object)
+ (result ? result : ScratchPad.recorded).should == IOSpecs.lines
+ end
+
+ it "does not accept Integers that don't fit in a C off_t" do
+ -> { IO.send(@method, @name, 2**128, &@object) }.should.raise(RangeError)
+ end
+
+ describe "when passed limit" do
+ it "raises ArgumentError when passed 0 as a limit" do
+ -> { IO.send(@method, @name, 0, &@object) }.should.raise(ArgumentError)
+ end
+ end
end
describe "when the object is a String" do
@@ -84,38 +97,40 @@ describe :io_readlines_options_19, shared: true do
end
it "accepts non-ASCII data as separator" do
- result = IO.send(@method, @name, "\303\250".force_encoding("utf-8"), &@object)
+ result = IO.send(@method, @name, "\303\250".dup.force_encoding("utf-8"), &@object)
(result ? result : ScratchPad.recorded).should == IOSpecs.lines_arbitrary_separator
end
end
- describe "when the object is a Hash" do
- it "uses the value as the options hash" do
- result = IO.send(@method, @name, mode: "r", &@object)
- (result ? result : ScratchPad.recorded).should == IOSpecs.lines
+ describe "when the object is an options Hash" do
+ it "raises TypeError exception" do
+ -> {
+ IO.send(@method, @name, { chomp: true }, &@object)
+ }.should.raise(TypeError)
end
end
- end
- describe "when passed name, object, object" do
- describe "when the first object is a Fixnum" do
- it "uses the second object as an options Hash" do
- lambda do
- IO.send(@method, @filename, 10, mode: "w", &@object)
- end.should raise_error(IOError)
- end
+ describe "when the object is neither Integer nor String" do
+ it "raises TypeError exception" do
+ obj = mock("not io readlines limit")
- it "calls #to_hash to convert the second object to a Hash" do
- options = mock("io readlines options Hash")
- options.should_receive(:to_hash).and_return({ mode: "w" })
- lambda do
- IO.send(@method, @filename, 10, options, &@object)
- end.should raise_error(IOError)
+ -> {
+ IO.send(@method, @name, obj, &@object)
+ }.should.raise(TypeError)
end
end
+ end
+
+ describe "when passed name, keyword arguments" do
+ it "uses the keyword arguments as options" do
+ result = IO.send(@method, @name, mode: "r", &@object)
+ (result ? result : ScratchPad.recorded).should == IOSpecs.lines
+ end
+ end
+ describe "when passed name, object, object" do
describe "when the first object is a String" do
- it "uses the second object as a limit if it is a Fixnum" do
+ it "uses the second object as a limit if it is an Integer" do
result = IO.send(@method, @name, " ", 10, &@object)
(result ? result : ScratchPad.recorded).should == IOSpecs.lines_space_separator_limit
end
@@ -126,32 +141,18 @@ describe :io_readlines_options_19, shared: true do
result = IO.send(@method, @name, " ", limit, &@object)
(result ? result : ScratchPad.recorded).should == IOSpecs.lines_space_separator_limit
end
-
- it "uses the second object as an options Hash" do
- lambda do
- IO.send(@method, @filename, " ", mode: "w", &@object)
- end.should raise_error(IOError)
- end
-
- it "calls #to_hash to convert the second object to a Hash" do
- options = mock("io readlines options Hash")
- options.should_receive(:to_hash).and_return({ mode: "w" })
- lambda do
- IO.send(@method, @filename, " ", options, &@object)
- end.should raise_error(IOError)
- end
end
- describe "when the first object is not a String or Fixnum" do
+ describe "when the first object is not a String or Integer" do
it "calls #to_str to convert the object to a String" do
sep = mock("io readlines separator")
sep.should_receive(:to_str).at_least(1).and_return(" ")
- result = IO.send(@method, @name, sep, 10, mode: "r", &@object)
+ result = IO.send(@method, @name, sep, 10, &@object)
(result ? result : ScratchPad.recorded).should == IOSpecs.lines_space_separator_limit
end
- it "uses the second object as a limit if it is a Fixnum" do
- result = IO.send(@method, @name, " ", 10, mode: "r", &@object)
+ it "uses the second object as a limit if it is an Integer" do
+ result = IO.send(@method, @name, " ", 10, &@object)
(result ? result : ScratchPad.recorded).should == IOSpecs.lines_space_separator_limit
end
@@ -161,24 +162,57 @@ describe :io_readlines_options_19, shared: true do
result = IO.send(@method, @name, " ", limit, &@object)
(result ? result : ScratchPad.recorded).should == IOSpecs.lines_space_separator_limit
end
+ end
+
+ describe "when the second object is neither Integer nor String" do
+ it "raises TypeError exception" do
+ obj = mock("not io readlines limit")
+
+ -> {
+ IO.send(@method, @name, " ", obj, &@object)
+ }.should.raise(TypeError)
+ end
+ end
+
+ describe "when the second object is an options Hash" do
+ it "raises TypeError exception" do
+ -> {
+ IO.send(@method, @name, "", { chomp: true }, &@object)
+ }.should.raise(TypeError)
+ end
+ end
+ end
- it "uses the second object as an options Hash" do
- lambda do
+ describe "when passed name, object, keyword arguments" do
+ describe "when the first object is an Integer" do
+ it "uses the keyword arguments as options" do
+ -> do
+ IO.send(@method, @filename, 10, mode: "w", &@object)
+ end.should.raise(IOError)
+ end
+ end
+
+ describe "when the first object is a String" do
+ it "uses the keyword arguments as options" do
+ -> do
IO.send(@method, @filename, " ", mode: "w", &@object)
- end.should raise_error(IOError)
+ end.should.raise(IOError)
end
+ end
- it "calls #to_hash to convert the second object to a Hash" do
- options = mock("io readlines options Hash")
- options.should_receive(:to_hash).and_return({ mode: "w" })
- lambda do
- IO.send(@method, @filename, " ", options, &@object)
- end.should raise_error(IOError)
+ describe "when the first object is not a String or Integer" do
+ it "uses the keyword arguments as options" do
+ sep = mock("io readlines separator")
+ sep.should_receive(:to_str).at_least(1).and_return(" ")
+
+ -> do
+ IO.send(@method, @filename, sep, mode: "w", &@object)
+ end.should.raise(IOError)
end
end
end
- describe "when passed name, separator, limit, options" do
+ describe "when passed name, separator, limit, keyword arguments" do
it "calls #to_path to convert the name object" do
name = mock("io name to_path")
name.should_receive(:to_path).and_return(@name)
@@ -200,12 +234,24 @@ describe :io_readlines_options_19, shared: true do
(result ? result : ScratchPad.recorded).should == IOSpecs.lines_space_separator_limit
end
- it "calls #to_hash to convert the options object" do
- options = mock("io readlines options Hash")
- options.should_receive(:to_hash).and_return({ mode: "w" })
- lambda do
- IO.send(@method, @filename, " ", 10, options, &@object)
- end.should raise_error(IOError)
+ it "uses the keyword arguments as options" do
+ -> do
+ IO.send(@method, @filename, " ", 10, mode: "w", &@object)
+ end.should.raise(IOError)
+ end
+
+ describe "when passed chomp, nil as a separator, and a limit" do
+ it "yields each line of limit size without truncating trailing new line character" do
+ # 43 - is a size of the 1st paragraph in the file
+ result = IO.send(@method, @name, nil, 43, chomp: true, &@object)
+
+ (result ? result : ScratchPad.recorded).should == [
+ "Voici la ligne une.\nQui è la linea due.\n\n\n",
+ "Aquí está la línea tres.\n" + "Hier ist Zeile ",
+ "vier.\n\nEstá aqui a linha cinco.\nHere is li",
+ "ne six.\n"
+ ]
+ end
end
end
end
diff --git a/spec/ruby/core/io/shared/tty.rb b/spec/ruby/core/io/shared/tty.rb
deleted file mode 100644
index eddc5d15af..0000000000
--- a/spec/ruby/core/io/shared/tty.rb
+++ /dev/null
@@ -1,25 +0,0 @@
-require File.expand_path('../../fixtures/classes', __FILE__)
-
-describe :io_tty, shared: true do
- platform_is_not :windows do
- it "returns true if this stream is a terminal device (TTY)" do
- begin
- # check to enabled tty
- File.open('/dev/tty') {}
- rescue Errno::ENXIO
- # workaround for not configured environment like OS X
- 1.should == 1
- else
- File.open('/dev/tty') { |f| f.send(@method) }.should == true
- end
- end
- end
-
- it "returns false if this stream is not a terminal device (TTY)" do
- File.open(__FILE__) { |f| f.send(@method) }.should == false
- end
-
- it "raises IOError on closed stream" do
- lambda { IOSpecs.closed_io.send @method }.should raise_error(IOError)
- end
-end
diff --git a/spec/ruby/core/io/shared/write.rb b/spec/ruby/core/io/shared/write.rb
index fd4b0af30e..5de9fe4335 100644
--- a/spec/ruby/core/io/shared/write.rb
+++ b/spec/ruby/core/io/shared/write.rb
@@ -1,5 +1,5 @@
# encoding: utf-8
-require File.expand_path('../../fixtures/classes', __FILE__)
+require_relative '../fixtures/classes'
describe :io_write, shared: true do
before :each do
@@ -23,7 +23,7 @@ describe :io_write, shared: true do
end
it "checks if the file is writable if writing more than zero bytes" do
- lambda { @readonly_file.send(@method, "abcde") }.should raise_error(IOError)
+ -> { @readonly_file.send(@method, "abcde") }.should.raise(IOError)
end
it "returns the number of bytes written" do
@@ -50,7 +50,7 @@ describe :io_write, shared: true do
it "does not warn if called after IO#read" do
@file.read(5)
- lambda { @file.send(@method, "fghij") }.should_not complain
+ -> { @file.send(@method, "fghij") }.should_not complain
end
it "writes to the current position after IO#read" do
@@ -66,7 +66,89 @@ describe :io_write, shared: true do
end
it "raises IOError on closed stream" do
- lambda { IOSpecs.closed_io.send(@method, "hello") }.should raise_error(IOError)
+ -> { IOSpecs.closed_io.send(@method, "hello") }.should.raise(IOError)
end
+ describe "on a pipe" do
+ before :each do
+ @r, @w = IO.pipe
+ end
+
+ after :each do
+ @r.close
+ @w.close
+ end
+
+ it "writes the given String to the pipe" do
+ @w.send(@method, "foo")
+ @w.close
+ @r.read.should == "foo"
+ end
+
+ # [ruby-core:90895] RJIT worker may leave fd open in a forked child.
+ # For instance, RJIT creates a worker before @r.close with fork(), @r.close happens,
+ # and the RJIT worker keeps the pipe open until the worker execve().
+ # TODO: consider acquiring GVL from RJIT worker.
+ guard_not -> { defined?(RubyVM::RJIT) && RubyVM::RJIT.enabled? } do
+ it "raises Errno::EPIPE if the read end is closed and does not die from SIGPIPE" do
+ @r.close
+ -> { @w.send(@method, "foo") }.should.raise(Errno::EPIPE, /Broken pipe/)
+ end
+ end
+ end
+end
+
+describe :io_write_transcode, shared: true do
+ before :each do
+ @transcode_filename = tmp("io_write_transcode")
+ end
+
+ after :each do
+ rm_r @transcode_filename
+ end
+
+ it "transcodes the given string when the external encoding is set and neither is BINARY" do
+ utf8_str = "hello"
+
+ File.open(@transcode_filename, "w", external_encoding: Encoding::UTF_16BE) do |file|
+ file.external_encoding.should == Encoding::UTF_16BE
+ file.send(@method, utf8_str)
+ end
+
+ result = File.binread(@transcode_filename)
+ expected = [0, 104, 0, 101, 0, 108, 0, 108, 0, 111] # UTF-16BE bytes for "hello"
+
+ result.bytes.should == expected
+ end
+
+ it "transcodes the given string when the external encoding is set and the string encoding is BINARY" do
+ str = "été".b
+
+ File.open(@transcode_filename, "w", external_encoding: Encoding::UTF_16BE) do |file|
+ file.external_encoding.should == Encoding::UTF_16BE
+ -> { file.send(@method, str) }.should.raise(Encoding::UndefinedConversionError)
+ end
+ end
+end
+
+describe :io_write_no_transcode, shared: true do
+ before :each do
+ @transcode_filename = tmp("io_write_no_transcode")
+ end
+
+ after :each do
+ rm_r @transcode_filename
+ end
+
+ it "does not transcode the given string even when the external encoding is set" do
+ utf8_str = "hello"
+
+ File.open(@transcode_filename, "w", external_encoding: Encoding::UTF_16BE) do |file|
+ file.external_encoding.should == Encoding::UTF_16BE
+ file.send(@method, utf8_str)
+ end
+
+ result = File.binread(@transcode_filename)
+ result.bytes.should == utf8_str.bytes
+ end
end
diff --git a/spec/ruby/core/io/stat_spec.rb b/spec/ruby/core/io/stat_spec.rb
index d59535843a..f9fc232ee0 100644
--- a/spec/ruby/core/io/stat_spec.rb
+++ b/spec/ruby/core/io/stat_spec.rb
@@ -1,9 +1,10 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "IO#stat" do
before :each do
- @io = IO.popen 'cat', "r+"
+ cmd = platform_is(:windows) ? 'rem' : 'cat'
+ @io = IO.popen cmd, "r+"
end
after :each do
@@ -11,14 +12,14 @@ describe "IO#stat" do
end
it "raises IOError on closed stream" do
- lambda { IOSpecs.closed_io.stat }.should raise_error(IOError)
+ -> { IOSpecs.closed_io.stat }.should.raise(IOError)
end
it "returns a File::Stat object for the stream" do
- STDOUT.stat.should be_an_instance_of(File::Stat)
+ STDOUT.stat.should.instance_of?(File::Stat)
end
it "can stat pipes" do
- @io.stat.should be_an_instance_of(File::Stat)
+ @io.stat.should.instance_of?(File::Stat)
end
end
diff --git a/spec/ruby/core/io/sync_spec.rb b/spec/ruby/core/io/sync_spec.rb
index 5cd873d799..b537db335b 100644
--- a/spec/ruby/core/io/sync_spec.rb
+++ b/spec/ruby/core/io/sync_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "IO#sync=" do
before :each do
@@ -27,7 +27,7 @@ describe "IO#sync=" do
end
it "raises an IOError on closed stream" do
- lambda { IOSpecs.closed_io.sync = true }.should raise_error(IOError)
+ -> { IOSpecs.closed_io.sync = true }.should.raise(IOError)
end
end
@@ -45,7 +45,7 @@ describe "IO#sync" do
end
it "raises an IOError on closed stream" do
- lambda { IOSpecs.closed_io.sync }.should raise_error(IOError)
+ -> { IOSpecs.closed_io.sync }.should.raise(IOError)
end
end
diff --git a/spec/ruby/core/io/sysopen_spec.rb b/spec/ruby/core/io/sysopen_spec.rb
index f6d37de364..325d51ed23 100644
--- a/spec/ruby/core/io/sysopen_spec.rb
+++ b/spec/ruby/core/io/sysopen_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "IO.sysopen" do
before :each do
@@ -13,16 +13,16 @@ describe "IO.sysopen" do
it "returns the file descriptor for a given path" do
@fd = IO.sysopen(@filename, "w")
- @fd.should be_kind_of(Fixnum)
- @fd.should_not equal(0)
+ @fd.should.is_a?(Integer)
+ @fd.should_not.equal?(0)
end
# opening a directory is not supported on Windows
platform_is_not :windows do
it "works on directories" do
@fd = IO.sysopen(tmp("")) # /tmp
- @fd.should be_kind_of(Fixnum)
- @fd.should_not equal(0)
+ @fd.should.is_a?(Integer)
+ @fd.should_not.equal?(0)
end
end
@@ -33,18 +33,18 @@ describe "IO.sysopen" do
end
it "accepts a mode as second argument" do
- lambda { @fd = IO.sysopen(@filename, "w") }.should_not raise_error
- @fd.should_not equal(0)
+ -> { @fd = IO.sysopen(@filename, "w") }.should_not.raise
+ @fd.should_not.equal?(0)
end
it "accepts permissions as third argument" do
@fd = IO.sysopen(@filename, "w", 777)
- @fd.should_not equal(0)
+ @fd.should_not.equal?(0)
end
it "accepts mode & permission that are nil" do
touch @filename # create the file
@fd = IO.sysopen(@filename, nil, nil)
- @fd.should_not equal(0)
+ @fd.should_not.equal?(0)
end
end
diff --git a/spec/ruby/core/io/sysread_spec.rb b/spec/ruby/core/io/sysread_spec.rb
index 1993653df9..2d58db2250 100644
--- a/spec/ruby/core/io/sysread_spec.rb
+++ b/spec/ruby/core/io/sysread_spec.rb
@@ -1,12 +1,12 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "IO#sysread on a file" do
before :each do
@file_name = tmp("IO_sysread_file") + $$.to_s
File.open(@file_name, "w") do |f|
# write some stuff
- f.write("012345678901234567890123456789")
+ f.write("012345678901234567890123456789\nabcdef")
end
@file = File.open(@file_name, "r+")
end
@@ -21,25 +21,25 @@ describe "IO#sysread on a file" do
end
it "reads the specified number of bytes from the file to the buffer" do
- buf = "" # empty buffer
+ buf = +"" # empty buffer
@file.sysread(15, buf).should == buf
buf.should == "012345678901234"
@file.rewind
- buf = "ABCDE" # small buffer
+ buf = +"ABCDE" # small buffer
@file.sysread(15, buf).should == buf
buf.should == "012345678901234"
@file.rewind
- buf = "ABCDE" * 5 # large buffer
+ buf = +"ABCDE" * 5 # large buffer
@file.sysread(15, buf).should == buf
buf.should == "012345678901234"
end
it "coerces the second argument to string and uses it as a buffer" do
- buf = "ABCDE"
+ buf = +"ABCDE"
(obj = mock("buff")).should_receive(:to_str).any_number_of_times.and_return(buf)
@file.sysread(15, obj).should == buf
buf.should == "012345678901234"
@@ -50,6 +50,11 @@ describe "IO#sysread on a file" do
@file.sysread(5).should == "56789"
end
+ it "raises an error when called after buffered reads" do
+ @file.readline
+ -> { @file.sysread(5) }.should.raise(IOError)
+ end
+
it "reads normally even when called immediately after a buffered IO#read" do
@file.read(15)
@file.sysread(5).should == "56789"
@@ -58,13 +63,13 @@ describe "IO#sysread on a file" do
it "does not raise error if called after IO#read followed by IO#write" do
@file.read(5)
@file.write("abcde")
- lambda { @file.sysread(5) }.should_not raise_error(IOError)
+ -> { @file.sysread(5) }.should_not.raise(IOError)
end
it "does not raise error if called after IO#read followed by IO#syswrite" do
@file.read(5)
@file.syswrite("abcde")
- lambda { @file.sysread(5) }.should_not raise_error(IOError)
+ -> { @file.sysread(5) }.should_not.raise(IOError)
end
it "reads updated content after the flushed buffered IO#write" do
@@ -77,6 +82,56 @@ describe "IO#sysread on a file" do
end
it "raises IOError on closed stream" do
- lambda { IOSpecs.closed_io.sysread(5) }.should raise_error(IOError)
+ -> { IOSpecs.closed_io.sysread(5) }.should.raise(IOError)
+ end
+
+ it "immediately returns an empty string if the length argument is 0" do
+ @file.sysread(0).should == ""
+ end
+
+ it "immediately returns the given buffer if the length argument is 0" do
+ buffer = +"existing content"
+ @file.sysread(0, buffer).should == buffer
+ buffer.should == "existing content"
+ end
+
+ it "discards the existing buffer content upon successful read" do
+ buffer = +"existing content"
+ @file.sysread(11, buffer).should.equal?(buffer)
+ buffer.should == "01234567890"
+ end
+
+ it "discards the existing buffer content upon error" do
+ buffer = +"existing content"
+ @file.seek(0, :END)
+ -> { @file.sysread(1, buffer) }.should.raise(EOFError)
+ buffer.should.empty?
+ end
+
+ it "preserves the encoding of the given buffer" do
+ buffer = ''.encode(Encoding::ISO_8859_1)
+ string = @file.sysread(10, buffer)
+
+ buffer.encoding.should == Encoding::ISO_8859_1
+ end
+end
+
+describe "IO#sysread" do
+ before do
+ @read, @write = IO.pipe
+ end
+
+ after do
+ @read.close
+ @write.close
+ end
+
+ it "returns a smaller string if less than size bytes are available" do
+ @write.syswrite "ab"
+ @read.sysread(3).should == "ab"
+ end
+
+ it "raises ArgumentError when length is less than 0" do
+ -> { @read.sysread(-1) }.should.raise(ArgumentError)
end
end
diff --git a/spec/ruby/core/io/sysseek_spec.rb b/spec/ruby/core/io/sysseek_spec.rb
index bcce968c7d..2384895dc5 100644
--- a/spec/ruby/core/io/sysseek_spec.rb
+++ b/spec/ruby/core/io/sysseek_spec.rb
@@ -1,10 +1,10 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/pos', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/pos'
describe "IO#sysseek" do
- it_behaves_like :io_set_pos, :seek
+ it_behaves_like :io_set_pos, :sysseek
end
describe "IO#sysseek" do
@@ -23,7 +23,12 @@ describe "IO#sysseek" do
it "raises an error when called after buffered reads" do
@io.readline
- lambda { @io.sysseek(-5, IO::SEEK_CUR) }.should raise_error(IOError)
+ -> { @io.sysseek(-5, IO::SEEK_CUR) }.should.raise(IOError)
+ end
+
+ it "seeks normally even when called immediately after a buffered IO#read" do
+ @io.read(15)
+ @io.sysseek(-5, IO::SEEK_CUR).should == 10
end
it "moves the read position relative to the start with SEEK_SET" do
@@ -36,7 +41,7 @@ describe "IO#sysseek" do
# this is the safest way of checking the EOF when
# sys-* methods are invoked
- lambda { @io.sysread(1) }.should raise_error(EOFError)
+ -> { @io.sysread(1) }.should.raise(EOFError)
@io.sysseek(-25, IO::SEEK_END)
@io.sysread(7).should == "cinco.\n"
diff --git a/spec/ruby/core/io/syswrite_spec.rb b/spec/ruby/core/io/syswrite_spec.rb
index 879423de2e..8bf61a27c3 100644
--- a/spec/ruby/core/io/syswrite_spec.rb
+++ b/spec/ruby/core/io/syswrite_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/write', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/write'
describe "IO#syswrite on a file" do
before :each do
@@ -29,15 +29,25 @@ describe "IO#syswrite on a file" do
end
end
+ it "does not modify the passed argument" do
+ File.open(@filename, "w") do |f|
+ f.set_encoding(Encoding::IBM437)
+ # A character whose codepoint differs between UTF-8 and IBM437
+ f.syswrite("Æ’".freeze)
+ end
+
+ File.binread(@filename).bytes.should == [198, 146]
+ end
+
it "warns if called immediately after a buffered IO#write" do
@file.write("abcde")
- lambda { @file.syswrite("fghij") }.should complain(/syswrite/)
+ -> { @file.syswrite("fghij") }.should complain(/syswrite/)
end
it "does not warn if called after IO#write with intervening IO#sysread" do
@file.syswrite("abcde")
@file.sysread(5)
- lambda { @file.syswrite("fghij") }.should_not complain
+ -> { @file.syswrite("fghij") }.should_not complain
end
it "writes to the actual file position when called after buffered IO#read" do
@@ -49,6 +59,24 @@ describe "IO#syswrite on a file" do
end
end
+describe "IO#syswrite on a pipe" do
+ it "returns the written bytes if the fd is in nonblock mode and write would block" do
+ require 'io/nonblock'
+ r, w = IO.pipe
+ begin
+ w.nonblock = true
+ larger_than_pipe_capacity = 2 * 1024 * 1024
+ written = w.syswrite("a"*larger_than_pipe_capacity)
+ written.should > 0
+ written.should < larger_than_pipe_capacity
+ ensure
+ w.close
+ r.close
+ end
+ end
+end
+
describe "IO#syswrite" do
it_behaves_like :io_write, :syswrite
+ it_behaves_like :io_write_no_transcode, :syswrite
end
diff --git a/spec/ruby/core/io/tell_spec.rb b/spec/ruby/core/io/tell_spec.rb
index d2f523cf10..a6b51adc17 100644
--- a/spec/ruby/core/io/tell_spec.rb
+++ b/spec/ruby/core/io/tell_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/pos', __FILE__)
+require_relative '../../spec_helper'
describe "IO#tell" do
- it_behaves_like(:io_pos, :tell)
+ it "is an alias of IO#pos" do
+ IO.instance_method(:tell).should == IO.instance_method(:pos)
+ end
end
diff --git a/spec/ruby/core/io/to_i_spec.rb b/spec/ruby/core/io/to_i_spec.rb
index bbe656cdcc..b271112a81 100644
--- a/spec/ruby/core/io/to_i_spec.rb
+++ b/spec/ruby/core/io/to_i_spec.rb
@@ -1,12 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
describe "IO#to_i" do
- it "returns the numeric file descriptor of the given IO object" do
- $stdout.to_i.should == 1
- end
-
- it "raises IOError on closed stream" do
- lambda { IOSpecs.closed_io.to_i }.should raise_error(IOError)
+ it "is an alias of IO#fileno" do
+ IO.instance_method(:to_i).should == IO.instance_method(:fileno)
end
end
diff --git a/spec/ruby/core/io/to_io_spec.rb b/spec/ruby/core/io/to_io_spec.rb
index 76ebefb38f..0b1809dffa 100644
--- a/spec/ruby/core/io/to_io_spec.rb
+++ b/spec/ruby/core/io/to_io_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "IO#to_io" do
before :each do
@@ -11,11 +11,11 @@ describe "IO#to_io" do
end
it "returns self for open stream" do
- @io.to_io.should equal(@io)
+ @io.to_io.should.equal?(@io)
end
it "returns self for closed stream" do
io = IOSpecs.closed_io
- io.to_io.should equal(io)
+ io.to_io.should.equal?(io)
end
end
diff --git a/spec/ruby/core/io/to_path_spec.rb b/spec/ruby/core/io/to_path_spec.rb
new file mode 100644
index 0000000000..ec6dffc115
--- /dev/null
+++ b/spec/ruby/core/io/to_path_spec.rb
@@ -0,0 +1,7 @@
+require_relative '../../spec_helper'
+
+describe "IO#to_path" do
+ it "is an alias of IO#path" do
+ IO.instance_method(:to_path).should == IO.instance_method(:path)
+ end
+end
diff --git a/spec/ruby/core/io/try_convert_spec.rb b/spec/ruby/core/io/try_convert_spec.rb
index 0326982ff1..7600b01b75 100644
--- a/spec/ruby/core/io/try_convert_spec.rb
+++ b/spec/ruby/core/io/try_convert_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "IO.try_convert" do
before :each do
@@ -13,7 +13,7 @@ describe "IO.try_convert" do
end
it "returns the passed IO object" do
- IO.try_convert(@io).should equal(@io)
+ IO.try_convert(@io).should.equal?(@io)
end
it "does not call #to_io on an IO instance" do
@@ -24,26 +24,26 @@ describe "IO.try_convert" do
it "calls #to_io to coerce an object" do
obj = mock("io")
obj.should_receive(:to_io).and_return(@io)
- IO.try_convert(obj).should equal(@io)
+ IO.try_convert(obj).should.equal?(@io)
end
it "returns nil when the passed object does not respond to #to_io" do
- IO.try_convert(mock("io")).should be_nil
+ IO.try_convert(mock("io")).should == nil
end
it "return nil when BasicObject is passed" do
- IO.try_convert(BasicObject.new).should be_nil
+ IO.try_convert(BasicObject.new).should == nil
end
it "raises a TypeError if the object does not return an IO from #to_io" do
obj = mock("io")
obj.should_receive(:to_io).and_return("io")
- lambda { IO.try_convert(obj) }.should raise_error(TypeError)
+ -> { IO.try_convert(obj) }.should raise_consistent_error(TypeError, "can't convert MockObject into IO (MockObject#to_io gives String)")
end
it "propagates an exception raised by #to_io" do
obj = mock("io")
obj.should_receive(:to_io).and_raise(TypeError.new)
- lambda{ IO.try_convert(obj) }.should raise_error(TypeError)
+ ->{ IO.try_convert(obj) }.should.raise(TypeError)
end
end
diff --git a/spec/ruby/core/io/tty_spec.rb b/spec/ruby/core/io/tty_spec.rb
index 3c1449b030..e1848a1760 100644
--- a/spec/ruby/core/io/tty_spec.rb
+++ b/spec/ruby/core/io/tty_spec.rb
@@ -1,6 +1,25 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/tty', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "IO#tty?" do
- it_behaves_like :io_tty, :tty?
+ platform_is_not :windows do
+ it "returns true if this stream is a terminal device (TTY)" do
+ begin
+ # check to enabled tty
+ File.open('/dev/tty') {}
+ rescue Errno::ENXIO
+ skip "workaround for not configured environment like OS X"
+ else
+ File.open('/dev/tty') { |f| f.tty? }.should == true
+ end
+ end
+ end
+
+ it "returns false if this stream is not a terminal device (TTY)" do
+ File.open(__FILE__) { |f| f.tty? }.should == false
+ end
+
+ it "raises IOError on closed stream" do
+ -> { IOSpecs.closed_io.tty? }.should.raise(IOError)
+ end
end
diff --git a/spec/ruby/core/io/ungetbyte_spec.rb b/spec/ruby/core/io/ungetbyte_spec.rb
index ee334b469b..e0615cd76c 100644
--- a/spec/ruby/core/io/ungetbyte_spec.rb
+++ b/spec/ruby/core/io/ungetbyte_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "IO#ungetbyte" do
before :each do
@@ -13,12 +13,12 @@ describe "IO#ungetbyte" do
end
it "does nothing when passed nil" do
- @io.ungetbyte(nil).should be_nil
+ @io.ungetbyte(nil).should == nil
@io.getbyte.should == 97
end
it "puts back each byte in a String argument" do
- @io.ungetbyte("cat").should be_nil
+ @io.ungetbyte("cat").should == nil
@io.getbyte.should == 99
@io.getbyte.should == 97
@io.getbyte.should == 116
@@ -29,20 +29,26 @@ describe "IO#ungetbyte" do
str = mock("io ungetbyte")
str.should_receive(:to_str).and_return("dog")
- @io.ungetbyte(str).should be_nil
+ @io.ungetbyte(str).should == nil
@io.getbyte.should == 100
@io.getbyte.should == 111
@io.getbyte.should == 103
@io.getbyte.should == 97
end
- it "puts back one byte for an Integer argument" do
- @io.ungetbyte(4095).should be_nil
- @io.getbyte.should == 255
+ it "never raises RangeError" do
+ for i in [4095, 0x4f7574206f6620636861722072616e67ff] do
+ @io.ungetbyte(i).should == nil
+ @io.getbyte.should == 255
+ end
+ end
+
+ it "raises IOError on stream not opened for reading" do
+ -> { STDOUT.ungetbyte(42) }.should.raise(IOError, "not opened for reading")
end
it "raises an IOError if the IO is closed" do
@io.close
- lambda { @io.ungetbyte(42) }.should raise_error(IOError)
+ -> { @io.ungetbyte(42) }.should.raise(IOError)
end
end
diff --git a/spec/ruby/core/io/ungetc_spec.rb b/spec/ruby/core/io/ungetc_spec.rb
index ce4cc9d346..4a9e67f126 100644
--- a/spec/ruby/core/io/ungetc_spec.rb
+++ b/spec/ruby/core/io/ungetc_spec.rb
@@ -1,6 +1,6 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "IO#ungetc" do
before :each do
@@ -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
@@ -58,10 +74,10 @@ describe "IO#ungetc" do
touch(@empty)
File.open(@empty) { |empty|
- empty.eof?.should == true
+ empty.should.eof?
empty.getc.should == nil
empty.ungetc(100)
- empty.eof?.should == false
+ empty.should_not.eof?
}
end
@@ -84,18 +100,17 @@ describe "IO#ungetc" do
it "makes subsequent unbuffered operations to raise IOError" do
@io.getc
@io.ungetc(100)
- lambda { @io.sysread(1) }.should raise_error(IOError)
+ -> { @io.sysread(1) }.should.raise(IOError)
end
- it "does not affect the stream and returns nil when passed nil" do
+ it "raises TypeError if passed nil" do
@io.getc.should == ?V
- @io.ungetc(nil)
- @io.getc.should == ?o
+ proc{@io.ungetc(nil)}.should.raise(TypeError)
end
it "puts one or more characters back in the stream" do
@io.gets
- @io.ungetc("Aquí ").should be_nil
+ @io.ungetc("Aquí ").should == nil
@io.gets.chomp.should == "Aquí Qui è la linea due."
end
@@ -103,17 +118,21 @@ describe "IO#ungetc" do
chars = mock("io ungetc")
chars.should_receive(:to_str).and_return("Aquí ")
- @io.ungetc(chars).should be_nil
+ @io.ungetc(chars).should == nil
@io.gets.chomp.should == "Aquí Voici la ligne une."
end
it "returns nil when invoked on stream that was not yet read" do
- @io.ungetc(100).should be_nil
+ @io.ungetc(100).should == nil
+ end
+
+ it "raises IOError on stream not opened for reading" do
+ -> { STDOUT.ungetc(100) }.should.raise(IOError, "not opened for reading")
end
it "raises IOError on closed stream" do
@io.getc
@io.close
- lambda { @io.ungetc(100) }.should raise_error(IOError)
+ -> { @io.ungetc(100) }.should.raise(IOError)
end
end
diff --git a/spec/ruby/core/io/write_nonblock_spec.rb b/spec/ruby/core/io/write_nonblock_spec.rb
index a6a263e931..a6bd43c058 100644
--- a/spec/ruby/core/io/write_nonblock_spec.rb
+++ b/spec/ruby/core/io/write_nonblock_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/write', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/write'
# See https://bugs.ruby-lang.org/issues/5954#note-5
platform_is_not :windows do
@@ -31,13 +31,26 @@ platform_is_not :windows do
end
end
+ it "does not modify the passed argument" do
+ File.open(@filename, "w") do |f|
+ f.set_encoding(Encoding::IBM437)
+ # A character whose codepoint differs between UTF-8 and IBM437
+ f.write_nonblock("Æ’".freeze)
+ end
+
+ File.binread(@filename).bytes.should == [198, 146]
+ end
+
it "checks if the file is writable if writing zero bytes" do
- lambda { @readonly_file.write_nonblock("") }.should raise_error
+ -> {
+ @readonly_file.write_nonblock("")
+ }.should.raise(IOError)
end
end
describe "IO#write_nonblock" do
it_behaves_like :io_write, :write_nonblock
+ it_behaves_like :io_write_no_transcode, :write_nonblock
end
end
@@ -52,25 +65,32 @@ describe 'IO#write_nonblock' do
end
it "raises an exception extending IO::WaitWritable when the write would block" do
- lambda {
+ -> {
loop { @write.write_nonblock('a' * 10_000) }
- }.should raise_error(IO::WaitWritable) { |e|
+ }.should.raise(IO::WaitWritable) { |e|
platform_is_not :windows do
- e.should be_kind_of(Errno::EAGAIN)
+ e.should.is_a?(Errno::EAGAIN)
end
platform_is :windows do
- e.should be_kind_of(Errno::EWOULDBLOCK)
+ e.should.is_a?(Errno::EWOULDBLOCK)
end
}
end
- ruby_version_is "2.3" do
- context "when exception option is set to false" do
- it "returns :wait_writable when the operation would block" do
- loop { break if @write.write_nonblock("a" * 10_000, exception: false) == :wait_writable }
- 1.should == 1
- end
+ context "when exception option is set to false" do
+ it "returns :wait_writable when the operation would block" do
+ loop {
+ break if @write.write_nonblock("a" * 10_000, exception: false) == :wait_writable
+ }
+ @write.write_nonblock("a" * 10_000, exception: false).should == :wait_writable
end
end
+ platform_is_not :windows do
+ it 'sets the IO in nonblock mode' do
+ require 'io/nonblock'
+ @write.write_nonblock('a')
+ @write.should.nonblock?
+ end
+ end
end
diff --git a/spec/ruby/core/io/write_spec.rb b/spec/ruby/core/io/write_spec.rb
index 1011efe8d5..1a745ba012 100644
--- a/spec/ruby/core/io/write_spec.rb
+++ b/spec/ruby/core/io/write_spec.rb
@@ -1,8 +1,8 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/write', __FILE__)
-require File.expand_path('../shared/binwrite', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/write'
+require_relative 'shared/binwrite'
describe "IO#write on a file" do
before :each do
@@ -21,57 +21,123 @@ describe "IO#write on a file" do
end
it "does not check if the file is writable if writing zero bytes" do
- lambda { @readonly_file.write("") }.should_not raise_error
+ -> { @readonly_file.write("") }.should_not.raise
+ end
+
+ before :each do
+ @external = Encoding.default_external
+ @internal = Encoding.default_internal
+
+ Encoding.default_external = Encoding::UTF_8
+ end
+
+ after :each do
+ Encoding.default_external = @external
+ Encoding.default_internal = @internal
end
it "returns a length of 0 when writing a blank string" do
@file.write('').should == 0
end
- with_feature :encoding do
- before :each do
- @external = Encoding.default_external
- @internal = Encoding.default_internal
+ it "returns a length of 0 when writing blank strings" do
+ @file.write('', '', '').should == 0
+ end
- Encoding.default_external = Encoding::UTF_8
+ it "returns a length of 0 when passed no arguments" do
+ @file.write().should == 0
+ end
+
+ it "returns the number of bytes written" do
+ @file.write("hellø").should == 6
+ end
+
+ it "does not modify the passed argument" do
+ File.open(@filename, "w") do |f|
+ f.set_encoding(Encoding::IBM437)
+ # A character whose codepoint differs between UTF-8 and IBM437
+ f.write("Æ’".freeze)
end
- after :each do
- Encoding.default_external = @external
- Encoding.default_internal = @internal
+ File.binread(@filename).bytes.should == [159]
+ end
+
+ it "does not modify arguments when passed multiple arguments and external encoding not set" do
+ a, b = "a".freeze, "b".freeze
+
+ File.open(@filename, "w") do |f|
+ f.write(a, b)
end
- it "returns the number of bytes written" do
- @file.write("hellø").should == 6
+ File.binread(@filename).bytes.should == [97, 98]
+ a.encoding.should == Encoding::UTF_8
+ b.encoding.should == Encoding::UTF_8
+ end
+
+ it "uses the encoding from the given option for non-ascii encoding" do
+ File.open(@filename, "w", encoding: Encoding::UTF_32LE) do |file|
+ file.write("hi").should == 8
end
+ File.binread(@filename).should == "h\u0000\u0000\u0000i\u0000\u0000\u0000"
+ end
- it "uses the encoding from the given option for non-ascii encoding" do
- File.open(@filename, "w", encoding: Encoding::UTF_32LE) do |file|
- file.write("hi").should == 8
- end
- File.binread(@filename).should == "h\u0000\u0000\u0000i\u0000\u0000\u0000"
+ it "uses the encoding from the given option for non-ascii encoding even if in binary mode" do
+ File.open(@filename, "w", encoding: Encoding::UTF_32LE, binmode: true) do |file|
+ file.should.binmode?
+ file.write("hi").should == 8
end
+ File.binread(@filename).should == "h\u0000\u0000\u0000i\u0000\u0000\u0000"
- it "uses an :open_args option" do
- IO.write(@filename, 'hi', open_args: ["w", nil, {encoding: Encoding::UTF_32LE}]).should == 8
+ File.open(@filename, "wb", encoding: Encoding::UTF_32LE) do |file|
+ file.should.binmode?
+ file.write("hi").should == 8
end
+ File.binread(@filename).should == "h\u0000\u0000\u0000i\u0000\u0000\u0000"
+ end
- it "raises a invalid byte sequence error if invalid bytes are being written" do
- # pack "\xFEhi" to avoid utf-8 conflict
- xFEhi = ([254].pack('C*') + 'hi').force_encoding('utf-8')
- File.open(@filename, "w", encoding: Encoding::US_ASCII) do |file|
- lambda { file.write(xFEhi) }.should raise_error(Encoding::InvalidByteSequenceError)
- end
+ it "uses the encoding from the given option for non-ascii encoding when multiple arguments passes" do
+ File.open(@filename, "w", encoding: Encoding::UTF_32LE) do |file|
+ file.write("h", "i").should == 8
+ end
+ File.binread(@filename).should == "h\u0000\u0000\u0000i\u0000\u0000\u0000"
+ end
+
+ it "ignores the 'bom|' prefix" do
+ File.open(@filename, "w", encoding: 'bom|utf-8') do |file|
+ file.write("hi")
+ end
+ File.binread(@filename).should == "hi"
+ end
+
+ it "raises a invalid byte sequence error if invalid bytes are being written" do
+ # pack "\xFEhi" to avoid utf-8 conflict
+ xFEhi = ([254].pack('C*') + 'hi').force_encoding('utf-8')
+ File.open(@filename, "w", encoding: Encoding::US_ASCII) do |file|
+ -> { file.write(xFEhi) }.should.raise(Encoding::InvalidByteSequenceError)
+ end
+ end
+
+ it "writes binary data if no encoding is given" do
+ File.open(@filename, "w") do |file|
+ file.write('Hëllö'.encode('ISO-8859-1'))
end
+ ë = ([235].pack('U')).encode('ISO-8859-1')
+ ö = ([246].pack('U')).encode('ISO-8859-1')
+ res = "H#{ë}ll#{ö}"
+ File.binread(@filename).should == res.force_encoding(Encoding::BINARY)
+ end
- it "writes binary data if no encoding is given" do
+ platform_is_not :windows do
+ it "writes binary data if no encoding is given and multiple arguments passed" do
File.open(@filename, "w") do |file|
- file.write('Hëllö'.encode('ISO-8859-1'))
+ file.write("\x87".b, "Ä…") # 0x87 isn't a valid UTF-8 binary representation of a character
end
- ë = ([235].pack('U')).encode('ISO-8859-1')
- ö = ([246].pack('U')).encode('ISO-8859-1')
- res = "H#{ë}ll#{ö}"
- File.binread(@filename).should == res.force_encoding(Encoding::ASCII_8BIT)
+ File.binread(@filename).bytes.should == [0x87, 0xC4, 0x85]
+
+ File.open(@filename, "w") do |file|
+ file.write("\x61".encode("utf-32le"), "Ä…")
+ end
+ File.binread(@filename).bytes.should == [0x61, 0x00, 0x00, 0x00, 0xC4, 0x85]
end
end
end
@@ -88,45 +154,104 @@ describe "IO.write" do
File.read(@filename).should == "\0\0hi"
end
+ it "requires mode to be specified in :open_args" do
+ -> {
+ IO.write(@filename, 'hi', open_args: [{encoding: Encoding::UTF_32LE, binmode: true}])
+ }.should.raise(IOError, "not opened for writing")
+
+ IO.write(@filename, 'hi', open_args: ["w", {encoding: Encoding::UTF_32LE, binmode: true}]).should == 8
+ IO.write(@filename, 'hi', open_args: [{encoding: Encoding::UTF_32LE, binmode: true, mode: "w"}]).should == 8
+ end
+
+ it "requires mode to be specified in :open_args even if flags option passed" do
+ -> {
+ IO.write(@filename, 'hi', open_args: [{encoding: Encoding::UTF_32LE, binmode: true, flags: File::CREAT}])
+ }.should.raise(IOError, "not opened for writing")
+
+ IO.write(@filename, 'hi', open_args: ["w", {encoding: Encoding::UTF_32LE, binmode: true, flags: File::CREAT}]).should == 8
+ IO.write(@filename, 'hi', open_args: [{encoding: Encoding::UTF_32LE, binmode: true, flags: File::CREAT, mode: "w"}]).should == 8
+ end
+
it "uses the given encoding and returns the number of bytes written" do
IO.write(@filename, 'hi', mode: "w", encoding: Encoding::UTF_32LE).should == 8
end
+ it "raises ArgumentError if encoding is specified in mode parameter and is given as :encoding option" do
+ -> {
+ IO.write(@filename, 'hi', mode: "w:UTF-16LE:UTF-16BE", encoding: Encoding::UTF_32LE)
+ }.should.raise(ArgumentError, "encoding specified twice")
+
+ -> {
+ IO.write(@filename, 'hi', mode: "w:UTF-16BE", encoding: Encoding::UTF_32LE)
+ }.should.raise(ArgumentError, "encoding specified twice")
+ end
+
+ it "writes the file with the permissions in the :perm parameter" do
+ rm_r @filename
+ IO.write(@filename, 'write :perm spec', mode: "w", perm: 0o755).should == 16
+ (File.stat(@filename).mode & 0o777) == 0o755
+ end
+
it "writes binary data if no encoding is given" do
IO.write(@filename, 'Hëllö'.encode('ISO-8859-1'))
xEB = [235].pack('C*')
xF6 = [246].pack('C*')
- File.binread(@filename).should == ("H" + xEB + "ll" + xF6).force_encoding(Encoding::ASCII_8BIT)
+ File.binread(@filename).should == ("H" + xEB + "ll" + xF6).force_encoding(Encoding::BINARY)
end
platform_is_not :windows do
describe "on a FIFO" do
before :each do
@fifo = tmp("File_open_fifo")
- system "mkfifo #{@fifo}"
+ File.mkfifo(@fifo)
end
after :each do
rm_r @fifo
end
- it "writes correctly" do
- thr = Thread.new do
- IO.read(@fifo)
- end
- begin
- string = "hi"
- IO.write(@fifo, string).should == string.length
- ensure
- thr.join
+ # rb_cloexec_open() is currently missing a retry on EINTR.
+ # @ioquatix is looking into fixing it. Quarantined until it's done.
+ quarantine! do
+ it "writes correctly" do
+ thr = Thread.new do
+ IO.read(@fifo)
+ end
+ begin
+ string = "hi"
+ IO.write(@fifo, string).should == string.length
+ ensure
+ thr.join
+ end
end
end
end
+
+ ruby_version_is ""..."4.0" do
+ # https://bugs.ruby-lang.org/issues/19630
+ it "warns about deprecation given a path with a pipe" do
+ -> {
+ -> {
+ IO.write("|cat", "xxx")
+ }.should output_to_fd("xxx")
+ }.should complain(/IO process creation with a leading '\|'/)
+ end
+ end
end
end
describe "IO#write" do
it_behaves_like :io_write, :write
+ it_behaves_like :io_write_transcode, :write
+
+ it "accepts multiple arguments" do
+ IO.pipe do |r, w|
+ w.write("foo", "bar")
+ w.close
+
+ r.read.should == "foobar"
+ end
+ end
end
platform_is :windows do
@@ -155,3 +280,25 @@ platform_is :windows do
end
end
end
+
+describe "IO#write on STDOUT" do
+ # https://bugs.ruby-lang.org/issues/14413
+ platform_is_not :windows do
+ it "raises SignalException SIGPIPE if the stream is closed instead of Errno::EPIPE like other IOs" do
+ stderr_file = tmp("stderr")
+ begin
+ IO.popen([*ruby_exe, "-e", "loop { puts :ok }"], "r", err: stderr_file) do |io|
+ io.gets.should == "ok\n"
+ io.close
+ end
+ status = $?
+ status.should_not.success?
+ status.should.signaled?
+ Signal.signame(status.termsig).should == 'PIPE'
+ File.read(stderr_file).should.empty?
+ ensure
+ rm_r stderr_file
+ end
+ end
+ end
+end
diff --git a/spec/ruby/core/kernel/Array_spec.rb b/spec/ruby/core/kernel/Array_spec.rb
index 6031a828f6..063faf7097 100644
--- a/spec/ruby/core/kernel/Array_spec.rb
+++ b/spec/ruby/core/kernel/Array_spec.rb
@@ -1,9 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Kernel" do
it "has private instance method Array()" do
- Kernel.should have_private_instance_method(:Array)
+ Kernel.private_instance_methods(false).should.include?(:Array)
end
end
@@ -77,14 +77,14 @@ describe :kernel_Array, shared: true do
obj = mock("Array() string")
obj.should_receive(:to_ary).and_return("string")
- lambda { @object.send(@method, obj) }.should raise_error(TypeError)
+ -> { @object.send(@method, obj) }.should.raise(TypeError)
end
it "raises a TypeError if #to_a does not return an Array" do
obj = mock("Array() string")
obj.should_receive(:to_a).and_return("string")
- lambda { @object.send(@method, obj) }.should raise_error(TypeError)
+ -> { @object.send(@method, obj) }.should.raise(TypeError)
end
end
diff --git a/spec/ruby/core/kernel/Complex_spec.rb b/spec/ruby/core/kernel/Complex_spec.rb
index b156cc4549..92ce183cc8 100644
--- a/spec/ruby/core/kernel/Complex_spec.rb
+++ b/spec/ruby/core/kernel/Complex_spec.rb
@@ -1,6 +1,276 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/complex/Complex', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../../shared/kernel/complex'
+require_relative 'fixtures/Complex'
describe "Kernel.Complex()" do
- it_behaves_like :kernel_Complex, :Complex
+ describe "when passed [Complex, Complex]" do
+ it "returns a new Complex number based on the two given numbers" do
+ Complex(Complex(3, 4), Complex(5, 6)).should == Complex(3 - 6, 4 + 5)
+ Complex(Complex(1.5, 2), Complex(-5, 6.3)).should == Complex(1.5 - 6.3, 2 - 5)
+ end
+ end
+
+ describe "when passed [Complex]" do
+ it "returns the passed Complex number" do
+ Complex(Complex(1, 2)).should == Complex(1, 2)
+ Complex(Complex(-3.4, bignum_value)).should == Complex(-3.4, bignum_value)
+ end
+ end
+
+ describe "when passed [Integer, Integer]" do
+ it "returns a new Complex number" do
+ Complex(1, 2).should.instance_of?(Complex)
+ Complex(1, 2).real.should == 1
+ Complex(1, 2).imag.should == 2
+
+ Complex(-3, -5).should.instance_of?(Complex)
+ Complex(-3, -5).real.should == -3
+ Complex(-3, -5).imag.should == -5
+
+ Complex(3.5, -4.5).should.instance_of?(Complex)
+ Complex(3.5, -4.5).real.should == 3.5
+ Complex(3.5, -4.5).imag.should == -4.5
+
+ Complex(bignum_value, 30).should.instance_of?(Complex)
+ Complex(bignum_value, 30).real.should == bignum_value
+ Complex(bignum_value, 30).imag.should == 30
+ end
+ end
+
+ describe "when passed [Integer/Float]" do
+ it "returns a new Complex number with 0 as the imaginary component" do
+ # Guard against the Mathn library
+ guard -> { !defined?(Math.rsqrt) } do
+ Complex(1).should.instance_of?(Complex)
+ Complex(1).imag.should == 0
+ Complex(1).real.should == 1
+
+ Complex(-3).should.instance_of?(Complex)
+ Complex(-3).imag.should == 0
+ Complex(-3).real.should == -3
+
+ Complex(-4.5).should.instance_of?(Complex)
+ Complex(-4.5).imag.should == 0
+ Complex(-4.5).real.should == -4.5
+
+ Complex(bignum_value).should.instance_of?(Complex)
+ Complex(bignum_value).imag.should == 0
+ Complex(bignum_value).real.should == bignum_value
+ end
+ end
+ end
+
+ describe "when passed [String]" do
+ it_behaves_like :kernel_complex, :Complex_method, KernelSpecs
+
+ context "invalid argument" do
+ it "raises Encoding::CompatibilityError if String is in not ASCII-compatible encoding" do
+ -> {
+ Complex("79+4i".encode("UTF-16"))
+ }.should.raise(Encoding::CompatibilityError, "ASCII incompatible encoding: UTF-16")
+ end
+
+ it "raises ArgumentError for unrecognised Strings" do
+ -> {
+ Complex("ruby")
+ }.should.raise(ArgumentError, 'invalid value for convert(): "ruby"')
+ end
+
+ it "raises ArgumentError for trailing garbage" do
+ -> {
+ Complex("79+4iruby")
+ }.should.raise(ArgumentError, 'invalid value for convert(): "79+4iruby"')
+ end
+
+ it "does not understand Float::INFINITY" do
+ -> {
+ Complex("Infinity")
+ }.should.raise(ArgumentError, 'invalid value for convert(): "Infinity"')
+
+ -> {
+ Complex("-Infinity")
+ }.should.raise(ArgumentError, 'invalid value for convert(): "-Infinity"')
+ end
+
+ it "does not understand Float::NAN" do
+ -> {
+ Complex("NaN")
+ }.should.raise(ArgumentError, 'invalid value for convert(): "NaN"')
+ end
+
+ it "does not understand a sequence of _" do
+ -> {
+ Complex("7__9+4__0i")
+ }.should.raise(ArgumentError, 'invalid value for convert(): "7__9+4__0i"')
+ end
+
+ it "does not allow null-byte" do
+ -> {
+ Complex("1-2i\0")
+ }.should.raise(ArgumentError, "string contains null byte")
+ end
+ end
+
+ context "invalid argument and exception: false passed" do
+ it "raises Encoding::CompatibilityError if String is in not ASCII-compatible encoding" do
+ -> {
+ Complex("79+4i".encode("UTF-16"), exception: false)
+ }.should.raise(Encoding::CompatibilityError, "ASCII incompatible encoding: UTF-16")
+ end
+
+ it "returns nil for unrecognised Strings" do
+ Complex("ruby", exception: false).should == nil
+ end
+
+ it "returns nil when trailing garbage" do
+ Complex("79+4iruby", exception: false).should == nil
+ end
+
+ it "returns nil for Float::INFINITY" do
+ Complex("Infinity", exception: false).should == nil
+ Complex("-Infinity", exception: false).should == nil
+ end
+
+ it "returns nil for Float::NAN" do
+ Complex("NaN", exception: false).should == nil
+ end
+
+ it "returns nil when there is a sequence of _" do
+ Complex("7__9+4__0i", exception: false).should == nil
+ end
+
+ it "returns nil when String contains null-byte" do
+ Complex("1-2i\0", exception: false).should == nil
+ end
+ end
+ end
+
+ describe "when passes [String, String]" do
+ it "needs to be reviewed for spec completeness"
+ end
+
+ 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)
+ end
+ end
+
+ describe "when passed a Numeric which responds to #real? with false" do
+ it "returns the passed argument" do
+ n = mock_numeric("unreal")
+ n.should_receive(:real?).any_number_of_times.and_return(false)
+ Complex(n).should.equal?(n)
+ end
+ end
+
+ describe "when passed a Numeric which responds to #real? with true" do
+ it "returns a Complex with the passed argument as the real component and 0 as the imaginary component" do
+ n = mock_numeric("real")
+ n.should_receive(:real?).any_number_of_times.and_return(true)
+ result = Complex(n)
+ result.real.should.equal?(n)
+ result.imag.should.equal?(0)
+ end
+ end
+
+ describe "when passed Numerics n1 and n2 and at least one responds to #real? with false" do
+ [[false, false], [false, true], [true, false]].each do |r1, r2|
+ it "returns n1 + n2 * Complex(0, 1)" do
+ n1 = mock_numeric("n1")
+ n2 = mock_numeric("n2")
+ n3 = mock_numeric("n3")
+ n4 = mock_numeric("n4")
+ n1.should_receive(:real?).any_number_of_times.and_return(r1)
+ n2.should_receive(:real?).any_number_of_times.and_return(r2)
+ n2.should_receive(:*).with(Complex(0, 1)).and_return(n3)
+ n1.should_receive(:+).with(n3).and_return(n4)
+ Complex(n1, n2).should.equal?(n4)
+ end
+ end
+ end
+
+ describe "when passed two Numerics and both respond to #real? with true" do
+ it "returns a Complex with the passed arguments as real and imaginary components respectively" do
+ n1 = mock_numeric("n1")
+ n2 = mock_numeric("n2")
+ n1.should_receive(:real?).any_number_of_times.and_return(true)
+ n2.should_receive(:real?).any_number_of_times.and_return(true)
+ result = Complex(n1, n2)
+ result.real.should.equal?(n1)
+ result.imag.should.equal?(n2)
+ end
+ end
+
+ describe "when passed a single non-Numeric" do
+ it "coerces the passed argument using #to_c" do
+ n = mock("n")
+ c = Complex(0, 0)
+ n.should_receive(:to_c).and_return(c)
+ Complex(n).should.equal?(c)
+ end
+ end
+
+ describe "when passed a non-Numeric second argument" do
+ it "raises TypeError" do
+ -> { Complex(:sym, :sym) }.should.raise(TypeError)
+ -> { Complex(0, :sym) }.should.raise(TypeError)
+ end
+ end
+
+ describe "when passed nil" do
+ it "raises TypeError" do
+ -> { Complex(nil) }.should.raise(TypeError, "can't convert nil into Complex")
+ -> { Complex(0, nil) }.should.raise(TypeError, "can't convert nil into Complex")
+ -> { Complex(nil, 0) }.should.raise(TypeError, "can't convert nil into Complex")
+ end
+ end
+
+ describe "when passed exception: false" do
+ describe "and [Numeric]" do
+ it "returns a complex number" do
+ Complex("123", exception: false).should == Complex(123)
+ end
+ end
+
+ describe "and [non-Numeric]" do
+ it "swallows an error" do
+ Complex(:sym, exception: false).should == nil
+ end
+ end
+
+ describe "and [non-Numeric, Numeric] argument" do
+ it "throws a TypeError" do
+ -> { Complex(:sym, 0, exception: false) }.should.raise(TypeError, "not a real")
+ end
+ end
+
+ describe "and [anything, non-Numeric] argument" do
+ it "swallows an error" do
+ Complex("a", :sym, exception: false).should == nil
+ Complex(:sym, :sym, exception: false).should == nil
+ Complex(0, :sym, exception: false).should == nil
+ end
+ end
+
+ describe "and non-numeric String arguments" do
+ it "swallows an error" do
+ Complex("a", "b", exception: false).should == nil
+ Complex("a", 0, exception: false).should == nil
+ Complex(0, "b", exception: false).should == nil
+ end
+ end
+
+ describe "and nil arguments" do
+ it "swallows an error" do
+ Complex(nil, exception: false).should == nil
+ Complex(0, nil, exception: false).should == nil
+ Complex(nil, 0, exception: false).should == nil
+ end
+ end
+ end
+
+ it "freezes its result" do
+ Complex(1).frozen?.should == true
+ end
end
diff --git a/spec/ruby/core/kernel/Float_spec.rb b/spec/ruby/core/kernel/Float_spec.rb
index ee20190094..f5566067ba 100644
--- a/spec/ruby/core/kernel/Float_spec.rb
+++ b/spec/ruby/core/kernel/Float_spec.rb
@@ -1,12 +1,12 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe :kernel_float, shared: true do
it "returns the identical Float for numeric Floats" do
float = 1.12
float2 = @object.send(:Float, float)
float2.should == float
- float2.object_id.should == float.object_id
+ float2.should.equal? float
end
it "returns a Float for Fixnums" do
@@ -22,26 +22,26 @@ describe :kernel_float, shared: true do
end
it "raises an ArgumentError for nil" do
- lambda { @object.send(:Float, nil) }.should raise_error(TypeError)
+ -> { @object.send(:Float, nil) }.should.raise(TypeError)
end
it "returns the identical NaN for NaN" do
nan = nan_value
- nan.nan?.should be_true
+ nan.nan?.should == true
nan2 = @object.send(:Float, nan)
- nan2.nan?.should be_true
- nan2.should equal(nan)
+ nan2.nan?.should == true
+ nan2.should.equal?(nan)
end
it "returns the same Infinity for Infinity" do
infinity = infinity_value
infinity2 = @object.send(:Float, infinity)
infinity2.should == infinity_value
- infinity.should equal(infinity2)
+ infinity.should.equal?(infinity2)
end
it "converts Strings to floats without calling #to_f" do
- string = "10"
+ string = +"10"
string.should_not_receive(:to_f)
@object.send(:Float, string).should == 10.0
end
@@ -51,24 +51,30 @@ describe :kernel_float, shared: true do
end
it "raises an ArgumentError for a String of word characters" do
- lambda { @object.send(:Float, "float") }.should raise_error(ArgumentError)
+ -> { @object.send(:Float, "float") }.should.raise(ArgumentError)
+ end
+
+ it "raises an ArgumentError for a String with string in error message" do
+ -> { @object.send(:Float, "foo") }.should.raise(ArgumentError) { |e|
+ e.message.should == 'invalid value for Float(): "foo"'
+ }
end
it "raises an ArgumentError if there are two decimal points in the String" do
- lambda { @object.send(:Float, "10.0.0") }.should raise_error(ArgumentError)
+ -> { @object.send(:Float, "10.0.0") }.should.raise(ArgumentError)
end
it "raises an ArgumentError for a String of numbers followed by word characters" do
- lambda { @object.send(:Float, "10D") }.should raise_error(ArgumentError)
+ -> { @object.send(:Float, "10D") }.should.raise(ArgumentError)
end
it "raises an ArgumentError for a String of word characters followed by numbers" do
- lambda { @object.send(:Float, "D10") }.should raise_error(ArgumentError)
+ -> { @object.send(:Float, "D10") }.should.raise(ArgumentError)
end
it "is strict about the string form even across newlines" do
- lambda { @object.send(:Float, "not a number\n10") }.should raise_error(ArgumentError)
- lambda { @object.send(:Float, "10\nnot a number") }.should raise_error(ArgumentError)
+ -> { @object.send(:Float, "not a number\n10") }.should.raise(ArgumentError)
+ -> { @object.send(:Float, "10\nnot a number") }.should.raise(ArgumentError)
end
it "converts String subclasses to floats without calling #to_f" do
@@ -90,17 +96,17 @@ describe :kernel_float, shared: true do
end
it "raises an ArgumentError if a + or - is embedded in a String" do
- lambda { @object.send(:Float, "1+1") }.should raise_error(ArgumentError)
- lambda { @object.send(:Float, "1-1") }.should raise_error(ArgumentError)
+ -> { @object.send(:Float, "1+1") }.should.raise(ArgumentError)
+ -> { @object.send(:Float, "1-1") }.should.raise(ArgumentError)
end
it "raises an ArgumentError if a String has a trailing + or -" do
- lambda { @object.send(:Float, "11+") }.should raise_error(ArgumentError)
- lambda { @object.send(:Float, "11-") }.should raise_error(ArgumentError)
+ -> { @object.send(:Float, "11+") }.should.raise(ArgumentError)
+ -> { @object.send(:Float, "11-") }.should.raise(ArgumentError)
end
it "raises an ArgumentError for a String with a leading _" do
- lambda { @object.send(:Float, "_1") }.should raise_error(ArgumentError)
+ -> { @object.send(:Float, "_1") }.should.raise(ArgumentError)
end
it "returns a value for a String with an embedded _" do
@@ -108,31 +114,31 @@ describe :kernel_float, shared: true do
end
it "raises an ArgumentError for a String with a trailing _" do
- lambda { @object.send(:Float, "10_") }.should raise_error(ArgumentError)
+ -> { @object.send(:Float, "10_") }.should.raise(ArgumentError)
end
it "raises an ArgumentError for a String of \\0" do
- lambda { @object.send(:Float, "\0") }.should raise_error(ArgumentError)
+ -> { @object.send(:Float, "\0") }.should.raise(ArgumentError)
end
it "raises an ArgumentError for a String with a leading \\0" do
- lambda { @object.send(:Float, "\01") }.should raise_error(ArgumentError)
+ -> { @object.send(:Float, "\01") }.should.raise(ArgumentError)
end
it "raises an ArgumentError for a String with an embedded \\0" do
- lambda { @object.send(:Float, "1\01") }.should raise_error(ArgumentError)
+ -> { @object.send(:Float, "1\01") }.should.raise(ArgumentError)
end
it "raises an ArgumentError for a String with a trailing \\0" do
- lambda { @object.send(:Float, "1\0") }.should raise_error(ArgumentError)
+ -> { @object.send(:Float, "1\0") }.should.raise(ArgumentError)
end
it "raises an ArgumentError for a String that is just an empty space" do
- lambda { @object.send(:Float, " ") }.should raise_error(ArgumentError)
+ -> { @object.send(:Float, " ") }.should.raise(ArgumentError)
end
it "raises an ArgumentError for a String that with an embedded space" do
- lambda { @object.send(:Float, "1 2") }.should raise_error(ArgumentError)
+ -> { @object.send(:Float, "1 2") }.should.raise(ArgumentError)
end
it "returns a value for a String with a leading space" do
@@ -151,13 +157,33 @@ describe :kernel_float, shared: true do
@object.send(:Float, "1\t\n").should == 1.0
end
+ ruby_version_is ""..."3.4" do
+ it "raises ArgumentError if a fractional part is missing" do
+ -> { @object.send(:Float, "1.") }.should.raise(ArgumentError)
+ -> { @object.send(:Float, "+1.") }.should.raise(ArgumentError)
+ -> { @object.send(:Float, "-1.") }.should.raise(ArgumentError)
+ -> { @object.send(:Float, "1.e+0") }.should.raise(ArgumentError)
+ -> { @object.send(:Float, "1.e-2") }.should.raise(ArgumentError)
+ end
+ end
+
+ ruby_version_is "3.4" do
+ it "allows String representation without a fractional part" do
+ @object.send(:Float, "1.").should == 1.0
+ @object.send(:Float, "+1.").should == 1.0
+ @object.send(:Float, "-1.").should == -1.0
+ @object.send(:Float, "1.e+0").should == 1.0
+ @object.send(:Float, "1.e-2").should be_close(0.01, TOLERANCE)
+ end
+ end
+
%w(e E).each do |e|
it "raises an ArgumentError if #{e} is the trailing character" do
- lambda { @object.send(:Float, "2#{e}") }.should raise_error(ArgumentError)
+ -> { @object.send(:Float, "2#{e}") }.should.raise(ArgumentError)
end
it "raises an ArgumentError if #{e} is the leading character" do
- lambda { @object.send(:Float, "#{e}2") }.should raise_error(ArgumentError)
+ -> { @object.send(:Float, "#{e}2") }.should.raise(ArgumentError)
end
it "returns Infinity for '2#{e}1000'" do
@@ -175,18 +201,18 @@ describe :kernel_float, shared: true do
end
it "raises an exception if a space is embedded on either side of the '#{e}'" do
- lambda { @object.send(:Float, "2 0#{e}100") }.should raise_error(ArgumentError)
- lambda { @object.send(:Float, "20#{e}1 00") }.should raise_error(ArgumentError)
+ -> { @object.send(:Float, "2 0#{e}100") }.should.raise(ArgumentError)
+ -> { @object.send(:Float, "20#{e}1 00") }.should.raise(ArgumentError)
end
it "raises an exception if there's a leading _ on either side of the '#{e}'" do
- lambda { @object.send(:Float, "_20#{e}100") }.should raise_error(ArgumentError)
- lambda { @object.send(:Float, "20#{e}_100") }.should raise_error(ArgumentError)
+ -> { @object.send(:Float, "_20#{e}100") }.should.raise(ArgumentError)
+ -> { @object.send(:Float, "20#{e}_100") }.should.raise(ArgumentError)
end
it "raises an exception if there's a trailing _ on either side of the '#{e}'" do
- lambda { @object.send(:Float, "20_#{e}100") }.should raise_error(ArgumentError)
- lambda { @object.send(:Float, "20#{e}100_") }.should raise_error(ArgumentError)
+ -> { @object.send(:Float, "20_#{e}100") }.should.raise(ArgumentError)
+ -> { @object.send(:Float, "20#{e}100_") }.should.raise(ArgumentError)
end
it "allows decimal points on the left side of the '#{e}'" do
@@ -194,63 +220,111 @@ describe :kernel_float, shared: true do
end
it "raises an ArgumentError if there's a decimal point on the right side of the '#{e}'" do
- lambda { @object.send(:Float, "20#{e}2.0") }.should raise_error(ArgumentError)
+ -> { @object.send(:Float, "20#{e}2.0") }.should.raise(ArgumentError)
end
end
- describe "for hexadecimal literals with binary exponent" do
- %w(p P).each do |p|
- it "interprets the fractional part (on the left side of '#{p}') in hexadecimal" do
- @object.send(:Float, "0x10#{p}0").should == 16.0
- end
-
- it "interprets the exponent (on the right of '#{p}') in decimal" do
- @object.send(:Float, "0x1#{p}10").should == 1024.0
- end
-
- it "raises an ArgumentError if #{p} is the trailing character" do
- lambda { @object.send(:Float, "0x1#{p}") }.should raise_error(ArgumentError)
- end
-
- it "raises an ArgumentError if #{p} is the leading character" do
- lambda { @object.send(:Float, "0x#{p}1") }.should raise_error(ArgumentError)
- end
+ context "for hexadecimal literals" do
+ it "interprets the 0x prefix as hexadecimal" do
+ @object.send(:Float, "0x10").should == 16.0
+ @object.send(:Float, "0x0F").should == 15.0
+ @object.send(:Float, "0x0f").should == 15.0
+ end
- it "returns Infinity for '0x1#{p}10000'" do
- @object.send(:Float, "0x1#{p}10000").should == Float::INFINITY
- end
+ it "interprets negative hex value" do
+ @object.send(:Float, "-0x10").should == -16.0
+ end
- it "returns 0 for '0x1#{p}-10000'" do
- @object.send(:Float, "0x1#{p}-10000").should == 0
- end
+ it "accepts embedded _ if the number does not contain a-f" do
+ @object.send(:Float, "0x1_0").should == 16.0
+ end
- it "allows embedded _ in a number on either side of the #{p}" do
- @object.send(:Float, "0x1_0#{p}10").should == 16384.0
- @object.send(:Float, "0x10#{p}1_0").should == 16384.0
- @object.send(:Float, "0x1_0#{p}1_0").should == 16384.0
+ ruby_version_is ""..."3.4.3" do
+ it "does not accept embedded _ if the number contains a-f" do
+ -> { @object.send(:Float, "0x1_0a") }.should.raise(ArgumentError)
+ @object.send(:Float, "0x1_0a", exception: false).should == nil
end
+ end
- it "raises an exception if a space is embedded on either side of the '#{p}'" do
- lambda { @object.send(:Float, "0x1 0#{p}10") }.should raise_error(ArgumentError)
- lambda { @object.send(:Float, "0x10#{p}1 0") }.should raise_error(ArgumentError)
+ ruby_version_is "3.4.3" do
+ it "accepts embedded _ if the number contains a-f" do
+ @object.send(:Float, "0x1_0a").should == 0x10a.to_f
end
+ end
- it "raises an exception if there's a leading _ on either side of the '#{p}'" do
- lambda { @object.send(:Float, "0x_10#{p}10") }.should raise_error(ArgumentError)
- lambda { @object.send(:Float, "0x10#{p}_10") }.should raise_error(ArgumentError)
- end
+ it "does not accept _ before, after or inside the 0x prefix" do
+ -> { @object.send(:Float, "_0x10") }.should.raise(ArgumentError)
+ -> { @object.send(:Float, "0_x10") }.should.raise(ArgumentError)
+ -> { @object.send(:Float, "0x_10") }.should.raise(ArgumentError)
+ @object.send(:Float, "_0x10", exception: false).should == nil
+ @object.send(:Float, "0_x10", exception: false).should == nil
+ @object.send(:Float, "0x_10", exception: false).should == nil
+ end
- it "raises an exception if there's a trailing _ on either side of the '#{p}'" do
- lambda { @object.send(:Float, "0x10_#{p}10") }.should raise_error(ArgumentError)
- lambda { @object.send(:Float, "0x10#{p}10_") }.should raise_error(ArgumentError)
- end
+ it "parses negative hexadecimal string as negative float" do
+ @object.send(:Float, "-0x7b").should == -123.0
+ end
- it "allows hexadecimal points on the left side of the '#{p}'" do
- @object.send(:Float, "0x1.8#{p}0").should == 1.5
+ ruby_version_is "3.4" do
+ it "accepts a fractional part" do
+ @object.send(:Float, "0x0.8").should == 0.5
end
+ end
- it "raises an ArgumentError if there's a decimal point on the right side of the '#{p}'" do
- lambda { @object.send(:Float, "0x1#{p}1.0") }.should raise_error(ArgumentError)
+ describe "with binary exponent" do
+ %w(p P).each do |p|
+ it "interprets the fractional part (on the left side of '#{p}') in hexadecimal" do
+ @object.send(:Float, "0x10#{p}0").should == 16.0
+ end
+
+ it "interprets the exponent (on the right of '#{p}') in decimal" do
+ @object.send(:Float, "0x1#{p}10").should == 1024.0
+ end
+
+ it "raises an ArgumentError if #{p} is the trailing character" do
+ -> { @object.send(:Float, "0x1#{p}") }.should.raise(ArgumentError)
+ end
+
+ it "raises an ArgumentError if #{p} is the leading character" do
+ -> { @object.send(:Float, "0x#{p}1") }.should.raise(ArgumentError)
+ end
+
+ it "returns Infinity for '0x1#{p}10000'" do
+ @object.send(:Float, "0x1#{p}10000").should == Float::INFINITY
+ end
+
+ it "returns 0 for '0x1#{p}-10000'" do
+ @object.send(:Float, "0x1#{p}-10000").should == 0
+ end
+
+ it "allows embedded _ in a number on either side of the #{p}" do
+ @object.send(:Float, "0x1_0#{p}10").should == 16384.0
+ @object.send(:Float, "0x10#{p}1_0").should == 16384.0
+ @object.send(:Float, "0x1_0#{p}1_0").should == 16384.0
+ end
+
+ it "raises an exception if a space is embedded on either side of the '#{p}'" do
+ -> { @object.send(:Float, "0x1 0#{p}10") }.should.raise(ArgumentError)
+ -> { @object.send(:Float, "0x10#{p}1 0") }.should.raise(ArgumentError)
+ end
+
+ it "raises an exception if there's a leading _ on either side of the '#{p}'" do
+ -> { @object.send(:Float, "0x_10#{p}10") }.should.raise(ArgumentError)
+ -> { @object.send(:Float, "0x10#{p}_10") }.should.raise(ArgumentError)
+ end
+
+ it "raises an exception if there's a trailing _ on either side of the '#{p}'" do
+ -> { @object.send(:Float, "0x10_#{p}10") }.should.raise(ArgumentError)
+ -> { @object.send(:Float, "0x10#{p}10_") }.should.raise(ArgumentError)
+ end
+
+ it "allows hexadecimal points on the left side of the '#{p}'" do
+ @object.send(:Float, "0x1.8#{p}0").should == 1.5
+ end
+
+ it "raises an ArgumentError if there's a decimal point on the right side of the '#{p}'" do
+ -> { @object.send(:Float, "0x1#{p}1.0") }.should.raise(ArgumentError)
+ end
end
end
end
@@ -270,34 +344,57 @@ describe :kernel_float, shared: true do
nan = nan_value
(nan_to_f = mock('NaN')).should_receive(:to_f).once.and_return(nan)
nan2 = @object.send(:Float, nan_to_f)
- nan2.nan?.should be_true
- nan2.should equal(nan)
+ nan2.nan?.should == true
+ nan2.should.equal?(nan)
end
- it "returns the identical Infinity if to_f is called and it returns Infinity" do
+ it "returns the identical Infinity if #to_f is called and it returns Infinity" do
infinity = infinity_value
(infinity_to_f = mock('Infinity')).should_receive(:to_f).once.and_return(infinity)
infinity2 = @object.send(:Float, infinity_to_f)
- infinity2.should equal(infinity)
+ infinity2.should.equal?(infinity)
end
it "raises a TypeError if #to_f is not provided" do
- lambda { @object.send(:Float, mock('x')) }.should raise_error(TypeError)
+ -> { @object.send(:Float, mock('x')) }.should.raise(TypeError)
end
it "raises a TypeError if #to_f returns a String" do
(obj = mock('ha!')).should_receive(:to_f).once.and_return('ha!')
- lambda { @object.send(:Float, obj) }.should raise_error(TypeError)
+ -> { @object.send(:Float, obj) }.should.raise(TypeError)
end
it "raises a TypeError if #to_f returns an Integer" do
(obj = mock('123')).should_receive(:to_f).once.and_return(123)
- lambda { @object.send(:Float, obj) }.should raise_error(TypeError)
+ -> { @object.send(:Float, obj) }.should.raise(TypeError)
end
it "raises a RangeError when passed a Complex argument" do
c = Complex(2, 3)
- lambda { @object.send(:Float, c) }.should raise_error(RangeError)
+ -> { @object.send(:Float, c) }.should.raise(RangeError)
+ end
+
+ describe "when passed exception: false" do
+ describe "and valid input" do
+ it "returns a Float number" do
+ @object.send(:Float, 1, exception: false).should == 1.0
+ @object.send(:Float, "1", exception: false).should == 1.0
+ @object.send(:Float, "1.23", exception: false).should == 1.23
+ end
+ end
+
+ describe "and invalid input" do
+ it "swallows an error" do
+ @object.send(:Float, "abc", exception: false).should == nil
+ @object.send(:Float, :sym, exception: false).should == nil
+ end
+ end
+
+ describe "and nil" do
+ it "swallows it" do
+ @object.send(:Float, nil, exception: false).should == nil
+ end
+ end
end
end
@@ -311,6 +408,6 @@ end
describe "Kernel#Float" do
it "is a private method" do
- Kernel.should have_private_instance_method(:Float)
+ Kernel.private_instance_methods(false).should.include?(:Float)
end
end
diff --git a/spec/ruby/core/kernel/Hash_spec.rb b/spec/ruby/core/kernel/Hash_spec.rb
index 8d51316c75..ee16f56a90 100644
--- a/spec/ruby/core/kernel/Hash_spec.rb
+++ b/spec/ruby/core/kernel/Hash_spec.rb
@@ -1,13 +1,19 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
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
it "has private instance method Hash()" do
- Kernel.should have_private_instance_method(:Hash)
+ Kernel.private_instance_methods(false).should.include?(:Hash)
end
end
@@ -37,14 +43,14 @@ describe :kernel_Hash, shared: true do
end
it "raises a TypeError if it doesn't respond to #to_hash" do
- lambda { @object.send(@method, mock("")) }.should raise_error(TypeError)
+ -> { @object.send(@method, mock("")) }.should.raise(TypeError)
end
it "raises a TypeError if #to_hash does not return an Hash" do
obj = mock("Hash() string")
obj.should_receive(:to_hash).and_return("string")
- lambda { @object.send(@method, obj) }.should raise_error(TypeError)
+ -> { @object.send(@method, obj) }.should.raise(TypeError)
end
end
diff --git a/spec/ruby/core/kernel/Integer_spec.rb b/spec/ruby/core/kernel/Integer_spec.rb
index 1e95fc9151..978fd8ef08 100644
--- a/spec/ruby/core/kernel/Integer_spec.rb
+++ b/spec/ruby/core/kernel/Integer_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe :kernel_integer, shared: true do
it "returns a Bignum for a Bignum" do
@@ -10,20 +10,52 @@ describe :kernel_integer, shared: true do
Integer(100).should == 100
end
- it "uncritically return the value of to_int even if it is not an Integer" do
+ it "raises a TypeError when to_int returns not-an-Integer object and to_i returns nil" do
obj = mock("object")
obj.should_receive(:to_int).and_return("1")
+ obj.should_receive(:to_i).and_return(nil)
+ -> {
+ Integer(obj)
+ }.should raise_consistent_error(TypeError, "can't convert MockObject into Integer (MockObject#to_i gives nil)")
+ end
+
+ it "return a result of to_i when to_int does not return an Integer" do
+ obj = mock("object")
+ obj.should_receive(:to_int).and_return("1")
+ obj.should_receive(:to_i).and_return(42)
+ Integer(obj).should == 42
+ end
+
+ it "returns a result of to_str" do
+ obj = mock("obj")
+ obj.should_receive(:to_str).and_return("1")
+
+ Integer(obj).should == 1
+ end
+
+ it "returns a result of to_int when both to_int and to_str are defined" do
+ obj = mock("obj")
+ obj.should_receive(:to_int).and_return(1)
+ obj.should_not_receive(:to_str)
+
+ Integer(obj).should == 1
+ end
+
+ it "returns a result of to_str when both to_str and to_i are defined" do
+ obj = mock("obj")
+ obj.should_receive(:to_str).and_return("1")
obj.should_not_receive(:to_i)
- Integer(obj).should == "1"
+
+ Integer(obj).should == 1
end
it "raises a TypeError when passed nil" do
- lambda { Integer(nil) }.should raise_error(TypeError)
+ -> { Integer(nil) }.should.raise(TypeError, "can't convert nil into Integer")
end
- it "returns a Fixnum or Bignum object" do
- Integer(2).should be_an_instance_of(Fixnum)
- Integer(9**99).should be_an_instance_of(Bignum)
+ it "returns an Integer object" do
+ Integer(2).should.instance_of?(Integer)
+ Integer(9**99).should.instance_of?(Integer)
end
it "truncates Floats" do
@@ -45,9 +77,9 @@ describe :kernel_integer, shared: true do
it "returns the value of to_int if the result is a Bignum" do
obj = mock("object")
- obj.should_receive(:to_int).and_return(2e100)
+ obj.should_receive(:to_int).and_return(2 * 10**100)
obj.should_not_receive(:to_i)
- Integer(obj).should == 2e100
+ Integer(obj).should == 2 * 10**100
end
it "calls to_i on an object whose to_int returns nil" do
@@ -60,44 +92,105 @@ describe :kernel_integer, shared: true do
it "raises a TypeError if to_i returns a value that is not an Integer" do
obj = mock("object")
obj.should_receive(:to_i).and_return("1")
- lambda { Integer(obj) }.should raise_error(TypeError)
+ -> {
+ Integer(obj)
+ }.should raise_consistent_error(TypeError, "can't convert MockObject into Integer (MockObject#to_i gives String)")
end
it "raises a TypeError if no to_int or to_i methods exist" do
obj = mock("object")
- lambda { Integer(obj) }.should raise_error(TypeError)
+ -> {
+ Integer(obj)
+ }.should.raise(TypeError, "can't convert MockObject into Integer")
end
it "raises a TypeError if to_int returns nil and no to_i exists" do
obj = mock("object")
obj.should_receive(:to_i).and_return(nil)
- lambda { Integer(obj) }.should raise_error(TypeError)
+ -> {
+ Integer(obj)
+ }.should raise_consistent_error(TypeError, "can't convert MockObject into Integer (MockObject#to_i gives nil)")
end
it "raises a FloatDomainError when passed NaN" do
- lambda { Integer(nan_value) }.should raise_error(FloatDomainError)
+ -> { Integer(nan_value) }.should.raise(FloatDomainError)
end
it "raises a FloatDomainError when passed Infinity" do
- lambda { Integer(infinity_value) }.should raise_error(FloatDomainError)
+ -> { Integer(infinity_value) }.should.raise(FloatDomainError)
+ end
+
+ describe "when passed exception: false" do
+ describe "and to_i returns a value that is not an Integer" do
+ it "swallows an error" do
+ obj = mock("object")
+ obj.should_receive(:to_i).and_return("1")
+ Integer(obj, exception: false).should == nil
+ end
+ end
+
+ describe "and no to_int or to_i methods exist" do
+ it "swallows an error" do
+ obj = mock("object")
+ Integer(obj, exception: false).should == nil
+ end
+ end
+
+ describe "and to_int returns nil and no to_i exists" do
+ it "swallows an error" do
+ obj = mock("object")
+ obj.should_receive(:to_i).and_return(nil)
+ Integer(obj, exception: false).should == nil
+ end
+ end
+
+ describe "and passed NaN" do
+ it "swallows an error" do
+ Integer(nan_value, exception: false).should == nil
+ end
+ end
+
+ describe "and passed Infinity" do
+ it "swallows an error" do
+ Integer(infinity_value, exception: false).should == nil
+ end
+ end
+
+ describe "and passed nil" do
+ it "swallows an error" do
+ Integer(nil, exception: false).should == nil
+ end
+ end
+
+ describe "and passed a String that contains numbers" do
+ it "normally parses it and returns an Integer" do
+ Integer("42", exception: false).should == 42
+ end
+ end
+
+ describe "and passed a String that can't be converted to an Integer" do
+ it "swallows an error" do
+ Integer("abc", exception: false).should == nil
+ end
+ end
end
end
-describe "Integer() given a String", shared: true do
+describe :kernel_integer_string, shared: true do
it "raises an ArgumentError if the String is a null byte" do
- lambda { Integer("\0") }.should raise_error(ArgumentError)
+ -> { Integer("\0") }.should.raise(ArgumentError)
end
it "raises an ArgumentError if the String starts with a null byte" do
- lambda { Integer("\01") }.should raise_error(ArgumentError)
+ -> { Integer("\01") }.should.raise(ArgumentError)
end
it "raises an ArgumentError if the String ends with a null byte" do
- lambda { Integer("1\0") }.should raise_error(ArgumentError)
+ -> { Integer("1\0") }.should.raise(ArgumentError)
end
it "raises an ArgumentError if the String contains a null byte" do
- lambda { Integer("1\01") }.should raise_error(ArgumentError)
+ -> { Integer("1\01") }.should.raise(ArgumentError)
end
it "ignores leading whitespace" do
@@ -113,13 +206,13 @@ describe "Integer() given a String", shared: true do
end
it "raises an ArgumentError if there are leading _s" do
- lambda { Integer("_1") }.should raise_error(ArgumentError)
- lambda { Integer("___1") }.should raise_error(ArgumentError)
+ -> { Integer("_1") }.should.raise(ArgumentError)
+ -> { Integer("___1") }.should.raise(ArgumentError)
end
it "raises an ArgumentError if there are trailing _s" do
- lambda { Integer("1_") }.should raise_error(ArgumentError)
- lambda { Integer("1___") }.should raise_error(ArgumentError)
+ -> { Integer("1_") }.should.raise(ArgumentError)
+ -> { Integer("1___") }.should.raise(ArgumentError)
end
it "ignores an embedded _" do
@@ -127,8 +220,8 @@ describe "Integer() given a String", shared: true do
end
it "raises an ArgumentError if there are multiple embedded _s" do
- lambda { Integer("1__1") }.should raise_error(ArgumentError)
- lambda { Integer("1___1") }.should raise_error(ArgumentError)
+ -> { Integer("1__1") }.should.raise(ArgumentError)
+ -> { Integer("1___1") }.should.raise(ArgumentError)
end
it "ignores a single leading +" do
@@ -136,17 +229,17 @@ describe "Integer() given a String", shared: true do
end
it "raises an ArgumentError if there is a space between the + and number" do
- lambda { Integer("+ 1") }.should raise_error(ArgumentError)
+ -> { Integer("+ 1") }.should.raise(ArgumentError)
end
it "raises an ArgumentError if there are multiple leading +s" do
- lambda { Integer("++1") }.should raise_error(ArgumentError)
- lambda { Integer("+++1") }.should raise_error(ArgumentError)
+ -> { Integer("++1") }.should.raise(ArgumentError)
+ -> { Integer("+++1") }.should.raise(ArgumentError)
end
it "raises an ArgumentError if there are trailing +s" do
- lambda { Integer("1+") }.should raise_error(ArgumentError)
- lambda { Integer("1+++") }.should raise_error(ArgumentError)
+ -> { Integer("1+") }.should.raise(ArgumentError)
+ -> { Integer("1+++") }.should.raise(ArgumentError)
end
it "makes the number negative if there's a leading -" do
@@ -154,21 +247,47 @@ describe "Integer() given a String", shared: true do
end
it "raises an ArgumentError if there are multiple leading -s" do
- lambda { Integer("--1") }.should raise_error(ArgumentError)
- lambda { Integer("---1") }.should raise_error(ArgumentError)
+ -> { Integer("--1") }.should.raise(ArgumentError)
+ -> { Integer("---1") }.should.raise(ArgumentError)
end
it "raises an ArgumentError if there are trailing -s" do
- lambda { Integer("1-") }.should raise_error(ArgumentError)
- lambda { Integer("1---") }.should raise_error(ArgumentError)
+ -> { Integer("1-") }.should.raise(ArgumentError)
+ -> { Integer("1---") }.should.raise(ArgumentError)
end
it "raises an ArgumentError if there is a period" do
- lambda { Integer("0.0") }.should raise_error(ArgumentError)
+ -> { Integer("0.0") }.should.raise(ArgumentError)
end
it "raises an ArgumentError for an empty String" do
- lambda { Integer("") }.should raise_error(ArgumentError)
+ -> { Integer("") }.should.raise(ArgumentError)
+ end
+
+ describe "when passed exception: false" do
+ describe "and multiple leading -s" do
+ it "swallows an error" do
+ Integer("---1", exception: false).should == nil
+ end
+ end
+
+ describe "and multiple trailing -s" do
+ it "swallows an error" do
+ Integer("1---", exception: false).should == nil
+ end
+ end
+
+ describe "and an argument that contains a period" do
+ it "swallows an error" do
+ Integer("0.0", exception: false).should == nil
+ end
+ end
+
+ describe "and an empty string" do
+ it "swallows an error" do
+ Integer("", exception: false).should == nil
+ end
+ end
end
it "parses the value as 0 if the string consists of a single zero character" do
@@ -192,7 +311,7 @@ describe "Integer() given a String", shared: true do
end
it "raises an ArgumentError if the number cannot be parsed as hex" do
- lambda { Integer("0#{x}g") }.should raise_error(ArgumentError)
+ -> { Integer("0#{x}g") }.should.raise(ArgumentError)
end
end
@@ -213,7 +332,7 @@ describe "Integer() given a String", shared: true do
end
it "raises an ArgumentError if the number cannot be parsed as binary" do
- lambda { Integer("0#{b}2") }.should raise_error(ArgumentError)
+ -> { Integer("0#{b}2") }.should.raise(ArgumentError)
end
end
@@ -234,7 +353,7 @@ describe "Integer() given a String", shared: true do
end
it "raises an ArgumentError if the number cannot be parsed as octal" do
- lambda { Integer("0#{o}9") }.should raise_error(ArgumentError)
+ -> { Integer("0#{o}9") }.should.raise(ArgumentError)
end
end
@@ -255,26 +374,26 @@ describe "Integer() given a String", shared: true do
end
it "raises an ArgumentError if the number cannot be parsed as decimal" do
- lambda { Integer("0#{d}a") }.should raise_error(ArgumentError)
+ -> { Integer("0#{d}a") }.should.raise(ArgumentError)
end
end
end
-describe "Integer() given a String and base", shared: true do
+describe :kernel_integer_string_base, shared: true do
it "raises an ArgumentError if the String is a null byte" do
- lambda { Integer("\0", 2) }.should raise_error(ArgumentError)
+ -> { Integer("\0", 2) }.should.raise(ArgumentError)
end
it "raises an ArgumentError if the String starts with a null byte" do
- lambda { Integer("\01", 3) }.should raise_error(ArgumentError)
+ -> { Integer("\01", 3) }.should.raise(ArgumentError)
end
it "raises an ArgumentError if the String ends with a null byte" do
- lambda { Integer("1\0", 4) }.should raise_error(ArgumentError)
+ -> { Integer("1\0", 4) }.should.raise(ArgumentError)
end
it "raises an ArgumentError if the String contains a null byte" do
- lambda { Integer("1\01", 5) }.should raise_error(ArgumentError)
+ -> { Integer("1\01", 5) }.should.raise(ArgumentError)
end
it "ignores leading whitespace" do
@@ -290,13 +409,13 @@ describe "Integer() given a String and base", shared: true do
end
it "raises an ArgumentError if there are leading _s" do
- lambda { Integer("_1", 7) }.should raise_error(ArgumentError)
- lambda { Integer("___1", 7) }.should raise_error(ArgumentError)
+ -> { Integer("_1", 7) }.should.raise(ArgumentError)
+ -> { Integer("___1", 7) }.should.raise(ArgumentError)
end
it "raises an ArgumentError if there are trailing _s" do
- lambda { Integer("1_", 12) }.should raise_error(ArgumentError)
- lambda { Integer("1___", 12) }.should raise_error(ArgumentError)
+ -> { Integer("1_", 12) }.should.raise(ArgumentError)
+ -> { Integer("1___", 12) }.should.raise(ArgumentError)
end
it "ignores an embedded _" do
@@ -304,8 +423,8 @@ describe "Integer() given a String and base", shared: true do
end
it "raises an ArgumentError if there are multiple embedded _s" do
- lambda { Integer("1__1", 4) }.should raise_error(ArgumentError)
- lambda { Integer("1___1", 4) }.should raise_error(ArgumentError)
+ -> { Integer("1__1", 4) }.should.raise(ArgumentError)
+ -> { Integer("1___1", 4) }.should.raise(ArgumentError)
end
it "ignores a single leading +" do
@@ -313,17 +432,17 @@ describe "Integer() given a String and base", shared: true do
end
it "raises an ArgumentError if there is a space between the + and number" do
- lambda { Integer("+ 1", 3) }.should raise_error(ArgumentError)
+ -> { Integer("+ 1", 3) }.should.raise(ArgumentError)
end
it "raises an ArgumentError if there are multiple leading +s" do
- lambda { Integer("++1", 3) }.should raise_error(ArgumentError)
- lambda { Integer("+++1", 3) }.should raise_error(ArgumentError)
+ -> { Integer("++1", 3) }.should.raise(ArgumentError)
+ -> { Integer("+++1", 3) }.should.raise(ArgumentError)
end
it "raises an ArgumentError if there are trailing +s" do
- lambda { Integer("1+", 3) }.should raise_error(ArgumentError)
- lambda { Integer("1+++", 12) }.should raise_error(ArgumentError)
+ -> { Integer("1+", 3) }.should.raise(ArgumentError)
+ -> { Integer("1+++", 12) }.should.raise(ArgumentError)
end
it "makes the number negative if there's a leading -" do
@@ -331,29 +450,29 @@ describe "Integer() given a String and base", shared: true do
end
it "raises an ArgumentError if there are multiple leading -s" do
- lambda { Integer("--1", 9) }.should raise_error(ArgumentError)
- lambda { Integer("---1", 9) }.should raise_error(ArgumentError)
+ -> { Integer("--1", 9) }.should.raise(ArgumentError)
+ -> { Integer("---1", 9) }.should.raise(ArgumentError)
end
it "raises an ArgumentError if there are trailing -s" do
- lambda { Integer("1-", 12) }.should raise_error(ArgumentError)
- lambda { Integer("1---", 12) }.should raise_error(ArgumentError)
+ -> { Integer("1-", 12) }.should.raise(ArgumentError)
+ -> { Integer("1---", 12) }.should.raise(ArgumentError)
end
it "raises an ArgumentError if there is a period" do
- lambda { Integer("0.0", 3) }.should raise_error(ArgumentError)
+ -> { Integer("0.0", 3) }.should.raise(ArgumentError)
end
it "raises an ArgumentError for an empty String" do
- lambda { Integer("", 12) }.should raise_error(ArgumentError)
+ -> { Integer("", 12) }.should.raise(ArgumentError)
end
it "raises an ArgumentError for a base of 1" do
- lambda { Integer("1", 1) }.should raise_error(ArgumentError)
+ -> { Integer("1", 1) }.should.raise(ArgumentError)
end
it "raises an ArgumentError for a base of 37" do
- lambda { Integer("1", 37) }.should raise_error(ArgumentError)
+ -> { Integer("1", 37) }.should.raise(ArgumentError)
end
it "accepts wholly lowercase alphabetic strings for bases > 10" do
@@ -381,8 +500,8 @@ describe "Integer() given a String and base", shared: true do
end
it "raises an ArgumentError for letters invalid in the given base" do
- lambda { Integer('z',19) }.should raise_error(ArgumentError)
- lambda { Integer('c00o',2) }.should raise_error(ArgumentError)
+ -> { Integer('z',19) }.should.raise(ArgumentError)
+ -> { Integer('c00o',2) }.should.raise(ArgumentError)
end
%w(x X).each do |x|
@@ -403,12 +522,12 @@ describe "Integer() given a String and base", shared: true do
2.upto(15) do |base|
it "raises an ArgumentError if the number begins with 0#{x} and the base is #{base}" do
- lambda { Integer("0#{x}1", base) }.should raise_error(ArgumentError)
+ -> { Integer("0#{x}1", base) }.should.raise(ArgumentError)
end
end
it "raises an ArgumentError if the number cannot be parsed as hex and the base is 16" do
- lambda { Integer("0#{x}g", 16) }.should raise_error(ArgumentError)
+ -> { Integer("0#{x}g", 16) }.should.raise(ArgumentError)
end
end
@@ -429,7 +548,7 @@ describe "Integer() given a String and base", shared: true do
end
it "raises an ArgumentError if the number cannot be parsed as binary and the base is 2" do
- lambda { Integer("0#{b}2", 2) }.should raise_error(ArgumentError)
+ -> { Integer("0#{b}2", 2) }.should.raise(ArgumentError)
end
end
@@ -450,12 +569,12 @@ describe "Integer() given a String and base", shared: true do
end
it "raises an ArgumentError if the number cannot be parsed as octal and the base is 8" do
- lambda { Integer("0#{o}9", 8) }.should raise_error(ArgumentError)
+ -> { Integer("0#{o}9", 8) }.should.raise(ArgumentError)
end
2.upto(7) do |base|
it "raises an ArgumentError if the number begins with 0#{o} and the base is #{base}" do
- lambda { Integer("0#{o}1", base) }.should raise_error(ArgumentError)
+ -> { Integer("0#{o}1", base) }.should.raise(ArgumentError)
end
end
end
@@ -477,17 +596,46 @@ describe "Integer() given a String and base", shared: true do
end
it "raises an ArgumentError if the number cannot be parsed as decimal and the base is 10" do
- lambda { Integer("0#{d}a", 10) }.should raise_error(ArgumentError)
+ -> { Integer("0#{d}a", 10) }.should.raise(ArgumentError)
end
2.upto(9) do |base|
it "raises an ArgumentError if the number begins with 0#{d} and the base is #{base}" do
- lambda { Integer("0#{d}1", base) }.should raise_error(ArgumentError)
+ -> { Integer("0#{d}1", base) }.should.raise(ArgumentError)
end
end
+ end
+
+ it "raises an ArgumentError if a base is given for a non-String value" do
+ -> { Integer(98, 15) }.should.raise(ArgumentError, "base specified for non string value")
+ end
+
+ it "tries to convert the base to an integer using to_int" do
+ obj = mock('8')
+ obj.should_receive(:to_int).and_return(8)
- it "raises an ArgumentError if a base is given for a non-String value" do
- lambda { Integer(98, 15) }.should raise_error(ArgumentError)
+ Integer("777", obj).should == 0777
+ end
+
+ it "raises a TypeError if it is not an integer and does not respond to #to_i" do
+ -> {
+ Integer("777", "8")
+ }.should.raise(TypeError, "no implicit conversion of String into Integer")
+ end
+
+ describe "when passed exception: false" do
+ describe "and valid argument" do
+ it "returns an Integer number" do
+ Integer("100", 10, exception: false).should == 100
+ Integer("100", 2, exception: false).should == 4
+ end
+ end
+
+ describe "and invalid argument" do
+ it "swallows an error" do
+ Integer("999", 2, exception: false).should == nil
+ Integer("abc", 10, exception: false).should == nil
+ end
end
end
end
@@ -495,176 +643,176 @@ end
describe :kernel_Integer, shared: true do
it "raises an ArgumentError when the String contains digits out of range of radix 2" do
str = "23456789abcdefghijklmnopqrstuvwxyz"
- lambda { @object.send(@method, str, 2) }.should raise_error(ArgumentError)
+ -> { @object.send(@method, str, 2) }.should.raise(ArgumentError)
end
it "raises an ArgumentError when the String contains digits out of range of radix 3" do
str = "3456789abcdefghijklmnopqrstuvwxyz"
- lambda { @object.send(@method, str, 3) }.should raise_error(ArgumentError)
+ -> { @object.send(@method, str, 3) }.should.raise(ArgumentError)
end
it "raises an ArgumentError when the String contains digits out of range of radix 4" do
str = "456789abcdefghijklmnopqrstuvwxyz"
- lambda { @object.send(@method, str, 4) }.should raise_error(ArgumentError)
+ -> { @object.send(@method, str, 4) }.should.raise(ArgumentError)
end
it "raises an ArgumentError when the String contains digits out of range of radix 5" do
str = "56789abcdefghijklmnopqrstuvwxyz"
- lambda { @object.send(@method, str, 5) }.should raise_error(ArgumentError)
+ -> { @object.send(@method, str, 5) }.should.raise(ArgumentError)
end
it "raises an ArgumentError when the String contains digits out of range of radix 6" do
str = "6789abcdefghijklmnopqrstuvwxyz"
- lambda { @object.send(@method, str, 6) }.should raise_error(ArgumentError)
+ -> { @object.send(@method, str, 6) }.should.raise(ArgumentError)
end
it "raises an ArgumentError when the String contains digits out of range of radix 7" do
str = "789abcdefghijklmnopqrstuvwxyz"
- lambda { @object.send(@method, str, 7) }.should raise_error(ArgumentError)
+ -> { @object.send(@method, str, 7) }.should.raise(ArgumentError)
end
it "raises an ArgumentError when the String contains digits out of range of radix 8" do
str = "89abcdefghijklmnopqrstuvwxyz"
- lambda { @object.send(@method, str, 8) }.should raise_error(ArgumentError)
+ -> { @object.send(@method, str, 8) }.should.raise(ArgumentError)
end
it "raises an ArgumentError when the String contains digits out of range of radix 9" do
str = "9abcdefghijklmnopqrstuvwxyz"
- lambda { @object.send(@method, str, 9) }.should raise_error(ArgumentError)
+ -> { @object.send(@method, str, 9) }.should.raise(ArgumentError)
end
it "raises an ArgumentError when the String contains digits out of range of radix 10" do
str = "abcdefghijklmnopqrstuvwxyz"
- lambda { @object.send(@method, str, 10) }.should raise_error(ArgumentError)
+ -> { @object.send(@method, str, 10) }.should.raise(ArgumentError)
end
it "raises an ArgumentError when the String contains digits out of range of radix 11" do
str = "bcdefghijklmnopqrstuvwxyz"
- lambda { @object.send(@method, str, 11) }.should raise_error(ArgumentError)
+ -> { @object.send(@method, str, 11) }.should.raise(ArgumentError)
end
it "raises an ArgumentError when the String contains digits out of range of radix 12" do
str = "cdefghijklmnopqrstuvwxyz"
- lambda { @object.send(@method, str, 12) }.should raise_error(ArgumentError)
+ -> { @object.send(@method, str, 12) }.should.raise(ArgumentError)
end
it "raises an ArgumentError when the String contains digits out of range of radix 13" do
str = "defghijklmnopqrstuvwxyz"
- lambda { @object.send(@method, str, 13) }.should raise_error(ArgumentError)
+ -> { @object.send(@method, str, 13) }.should.raise(ArgumentError)
end
it "raises an ArgumentError when the String contains digits out of range of radix 14" do
str = "efghijklmnopqrstuvwxyz"
- lambda { @object.send(@method, str, 14) }.should raise_error(ArgumentError)
+ -> { @object.send(@method, str, 14) }.should.raise(ArgumentError)
end
it "raises an ArgumentError when the String contains digits out of range of radix 15" do
str = "fghijklmnopqrstuvwxyz"
- lambda { @object.send(@method, str, 15) }.should raise_error(ArgumentError)
+ -> { @object.send(@method, str, 15) }.should.raise(ArgumentError)
end
it "raises an ArgumentError when the String contains digits out of range of radix 16" do
str = "ghijklmnopqrstuvwxyz"
- lambda { @object.send(@method, str, 16) }.should raise_error(ArgumentError)
+ -> { @object.send(@method, str, 16) }.should.raise(ArgumentError)
end
it "raises an ArgumentError when the String contains digits out of range of radix 17" do
str = "hijklmnopqrstuvwxyz"
- lambda { @object.send(@method, str, 17) }.should raise_error(ArgumentError)
+ -> { @object.send(@method, str, 17) }.should.raise(ArgumentError)
end
it "raises an ArgumentError when the String contains digits out of range of radix 18" do
str = "ijklmnopqrstuvwxyz"
- lambda { @object.send(@method, str, 18) }.should raise_error(ArgumentError)
+ -> { @object.send(@method, str, 18) }.should.raise(ArgumentError)
end
it "raises an ArgumentError when the String contains digits out of range of radix 19" do
str = "jklmnopqrstuvwxyz"
- lambda { @object.send(@method, str, 19) }.should raise_error(ArgumentError)
+ -> { @object.send(@method, str, 19) }.should.raise(ArgumentError)
end
it "raises an ArgumentError when the String contains digits out of range of radix 20" do
str = "klmnopqrstuvwxyz"
- lambda { @object.send(@method, str, 20) }.should raise_error(ArgumentError)
+ -> { @object.send(@method, str, 20) }.should.raise(ArgumentError)
end
it "raises an ArgumentError when the String contains digits out of range of radix 21" do
str = "lmnopqrstuvwxyz"
- lambda { @object.send(@method, str, 21) }.should raise_error(ArgumentError)
+ -> { @object.send(@method, str, 21) }.should.raise(ArgumentError)
end
it "raises an ArgumentError when the String contains digits out of range of radix 22" do
str = "mnopqrstuvwxyz"
- lambda { @object.send(@method, str, 22) }.should raise_error(ArgumentError)
+ -> { @object.send(@method, str, 22) }.should.raise(ArgumentError)
end
it "raises an ArgumentError when the String contains digits out of range of radix 23" do
str = "nopqrstuvwxyz"
- lambda { @object.send(@method, str, 23) }.should raise_error(ArgumentError)
+ -> { @object.send(@method, str, 23) }.should.raise(ArgumentError)
end
it "raises an ArgumentError when the String contains digits out of range of radix 24" do
str = "opqrstuvwxyz"
- lambda { @object.send(@method, str, 24) }.should raise_error(ArgumentError)
+ -> { @object.send(@method, str, 24) }.should.raise(ArgumentError)
end
it "raises an ArgumentError when the String contains digits out of range of radix 25" do
str = "pqrstuvwxyz"
- lambda { @object.send(@method, str, 25) }.should raise_error(ArgumentError)
+ -> { @object.send(@method, str, 25) }.should.raise(ArgumentError)
end
it "raises an ArgumentError when the String contains digits out of range of radix 26" do
str = "qrstuvwxyz"
- lambda { @object.send(@method, str, 26) }.should raise_error(ArgumentError)
+ -> { @object.send(@method, str, 26) }.should.raise(ArgumentError)
end
it "raises an ArgumentError when the String contains digits out of range of radix 27" do
str = "rstuvwxyz"
- lambda { @object.send(@method, str, 27) }.should raise_error(ArgumentError)
+ -> { @object.send(@method, str, 27) }.should.raise(ArgumentError)
end
it "raises an ArgumentError when the String contains digits out of range of radix 28" do
str = "stuvwxyz"
- lambda { @object.send(@method, str, 28) }.should raise_error(ArgumentError)
+ -> { @object.send(@method, str, 28) }.should.raise(ArgumentError)
end
it "raises an ArgumentError when the String contains digits out of range of radix 29" do
str = "tuvwxyz"
- lambda { @object.send(@method, str, 29) }.should raise_error(ArgumentError)
+ -> { @object.send(@method, str, 29) }.should.raise(ArgumentError)
end
it "raises an ArgumentError when the String contains digits out of range of radix 30" do
str = "uvwxyz"
- lambda { @object.send(@method, str, 30) }.should raise_error(ArgumentError)
+ -> { @object.send(@method, str, 30) }.should.raise(ArgumentError)
end
it "raises an ArgumentError when the String contains digits out of range of radix 31" do
str = "vwxyz"
- lambda { @object.send(@method, str, 31) }.should raise_error(ArgumentError)
+ -> { @object.send(@method, str, 31) }.should.raise(ArgumentError)
end
it "raises an ArgumentError when the String contains digits out of range of radix 32" do
str = "wxyz"
- lambda { @object.send(@method, str, 32) }.should raise_error(ArgumentError)
+ -> { @object.send(@method, str, 32) }.should.raise(ArgumentError)
end
it "raises an ArgumentError when the String contains digits out of range of radix 33" do
str = "xyz"
- lambda { @object.send(@method, str, 33) }.should raise_error(ArgumentError)
+ -> { @object.send(@method, str, 33) }.should.raise(ArgumentError)
end
it "raises an ArgumentError when the String contains digits out of range of radix 34" do
str = "yz"
- lambda { @object.send(@method, str, 34) }.should raise_error(ArgumentError)
+ -> { @object.send(@method, str, 34) }.should.raise(ArgumentError)
end
it "raises an ArgumentError when the String contains digits out of range of radix 35" do
str = "z"
- lambda { @object.send(@method, str, 35) }.should raise_error(ArgumentError)
+ -> { @object.send(@method, str, 35) }.should.raise(ArgumentError)
end
it "raises an ArgumentError when the String contains digits out of range of radix 36" do
- lambda { @object.send(@method, "{", 36) }.should raise_error(ArgumentError)
+ -> { @object.send(@method, "{", 36) }.should.raise(ArgumentError)
end
end
@@ -673,9 +821,9 @@ describe "Kernel.Integer" do
# TODO: fix these specs
it_behaves_like :kernel_integer, :Integer, Kernel
- it_behaves_like "Integer() given a String", :Integer
+ it_behaves_like :kernel_integer_string, :Integer
- it_behaves_like "Integer() given a String and base", :Integer
+ it_behaves_like :kernel_integer_string_base, :Integer
it "is a public method" do
Kernel.Integer(10).should == 10
@@ -687,11 +835,11 @@ describe "Kernel#Integer" do
# TODO: fix these specs
it_behaves_like :kernel_integer, :Integer, Object.new
- it_behaves_like "Integer() given a String", :Integer
+ it_behaves_like :kernel_integer_string, :Integer
- it_behaves_like "Integer() given a String and base", :Integer
+ it_behaves_like :kernel_integer_string_base, :Integer
it "is a private method" do
- Kernel.should have_private_instance_method(:Integer)
+ Kernel.private_instance_methods(false).should.include?(:Integer)
end
end
diff --git a/spec/ruby/core/kernel/Rational_spec.rb b/spec/ruby/core/kernel/Rational_spec.rb
index 38f1da6333..b13ab4cf55 100644
--- a/spec/ruby/core/kernel/Rational_spec.rb
+++ b/spec/ruby/core/kernel/Rational_spec.rb
@@ -1,6 +1,236 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/rational/Rational', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../rational/fixtures/rational'
describe "Kernel.Rational" do
- it_behaves_like :kernel_Rational, :Rational
+ describe "passed Integer" do
+ # Guard against the Mathn library
+ guard -> { !defined?(Math.rsqrt) } do
+ it "returns a new Rational number with 1 as the denominator" do
+ Rational(1).should.eql?(Rational(1, 1))
+ Rational(-3).should.eql?(Rational(-3, 1))
+ Rational(bignum_value).should.eql?(Rational(bignum_value, 1))
+ end
+ end
+ end
+
+ describe "passed two integers" do
+ it "returns a new Rational number" do
+ rat = Rational(1, 2)
+ rat.numerator.should == 1
+ rat.denominator.should == 2
+ rat.should.instance_of?(Rational)
+
+ rat = Rational(-3, -5)
+ rat.numerator.should == 3
+ rat.denominator.should == 5
+ rat.should.instance_of?(Rational)
+
+ rat = Rational(bignum_value, 3)
+ rat.numerator.should == bignum_value
+ rat.denominator.should == 3
+ rat.should.instance_of?(Rational)
+ end
+
+ it "reduces the Rational" do
+ rat = Rational(2, 4)
+ rat.numerator.should == 1
+ rat.denominator.should == 2
+
+ rat = Rational(3, 9)
+ rat.numerator.should == 1
+ rat.denominator.should == 3
+ end
+ end
+
+ describe "when passed a String" do
+ it "converts the String to a Rational using the same method as String#to_r" do
+ r = Rational(13, 25)
+ s_r = ".52".to_r
+ r_s = Rational(".52")
+
+ r_s.should == r
+ r_s.should == s_r
+ end
+
+ it "scales the Rational value of the first argument by the Rational value of the second" do
+ Rational(".52", ".6").should == Rational(13, 15)
+ Rational(".52", "1.6").should == Rational(13, 40)
+ end
+
+ it "does not use the same method as Float#to_r" do
+ r = Rational(3, 5)
+ f_r = 0.6.to_r
+ r_s = Rational("0.6")
+
+ r_s.should == r
+ r_s.should_not == f_r
+ end
+ end
+
+ describe "when passed a Numeric" do
+ it "calls #to_r to convert the first argument to a Rational" do
+ num = RationalSpecs::SubNumeric.new(2)
+
+ Rational(num).should == Rational(2)
+ end
+ end
+
+ describe "when passed a Complex" do
+ context "[Complex]" do
+ it "returns a Rational from the real part if the imaginary part is 0" do
+ Rational(Complex(1, 0)).should == Rational(1)
+ end
+
+ it "raises a RangeError if the imaginary part is not 0" do
+ -> { Rational(Complex(1, 2)) }.should.raise(RangeError, "can't convert 1+2i into Rational")
+ end
+ end
+
+ context "[Numeric, Complex]" do
+ it "uses the real part if the imaginary part is 0" do
+ Rational(1, Complex(2, 0)).should == Rational(1, 2)
+ end
+
+ it "divides a numerator by the Complex denominator if the imaginary part is not 0" do
+ Rational(1, Complex(2, 1)).should == Complex(2/5r, -1/5r)
+ end
+ end
+ end
+
+ context "when passed neither a Numeric nor a String" do
+ it "converts to Rational with #to_r method" do
+ obj = Object.new
+ def obj.to_r; 1/2r; end
+
+ Rational(obj).should == 1/2r
+ end
+
+ it "tries to convert to Integer with #to_int method if it does not respond to #to_r" do
+ obj = Object.new
+ def obj.to_int; 1; end
+
+ Rational(obj).should == 1r
+ end
+
+ it "raises TypeError if it neither responds to #to_r nor #to_int method" do
+ -> { Rational([]) }.should.raise(TypeError, "can't convert Array into Rational")
+ -> { Rational({}) }.should.raise(TypeError, "can't convert Hash into Rational")
+ -> { Rational(nil) }.should.raise(TypeError, "can't convert nil into Rational")
+ end
+
+ it "swallows exception raised in #to_int method" do
+ object = Object.new
+ def object.to_int() raise NoMethodError; end
+
+ -> { Rational(object) }.should.raise(TypeError)
+ -> { Rational(object, 1) }.should.raise(TypeError)
+ -> { Rational(1, object) }.should.raise(TypeError)
+ end
+
+ it "raises TypeError if #to_r does not return Rational" do
+ obj = Object.new
+ def obj.to_r; []; end
+
+ -> { Rational(obj) }.should raise_consistent_error(TypeError, "can't convert Object into Rational (Object#to_r gives Array)")
+ end
+ end
+
+ it "raises a ZeroDivisionError if the second argument is 0" do
+ -> { Rational(1, 0) }.should.raise(ZeroDivisionError, "divided by 0")
+ -> { Rational(1, 0.0) }.should.raise(ZeroDivisionError, "divided by 0")
+ end
+
+ it "raises a TypeError if the first argument is nil" do
+ -> { Rational(nil) }.should.raise(TypeError, "can't convert nil into Rational")
+ end
+
+ it "raises a TypeError if the second argument is nil" do
+ -> { Rational(1, nil) }.should.raise(TypeError, "can't convert nil into Rational")
+ end
+
+ it "raises a TypeError if the first argument is a Symbol" do
+ -> { Rational(:sym) }.should.raise(TypeError)
+ end
+
+ it "raises a TypeError if the second argument is a Symbol" do
+ -> { Rational(1, :sym) }.should.raise(TypeError)
+ end
+
+ describe "when passed exception: false" do
+ describe "and [non-Numeric]" do
+ it "swallows an error" do
+ Rational(:sym, exception: false).should == nil
+ Rational("abc", exception: false).should == nil
+ end
+
+ it "swallows an exception raised in #to_r" do
+ obj = Object.new
+ def obj.to_r; raise; end
+ Rational(obj, exception: false).should == nil
+ end
+
+ it "swallows an exception raised in #to_int" do
+ obj = Object.new
+ def obj.to_int; raise; end
+ Rational(obj, exception: false).should == nil
+ end
+ end
+
+ describe "and [non-Numeric, Numeric]" do
+ it "swallows an error" do
+ Rational(:sym, 1, exception: false).should == nil
+ Rational("abc", 1, exception: false).should == nil
+ end
+
+ it "swallows an exception raised in #to_r" do
+ obj = Object.new
+ def obj.to_r; raise; end
+ Rational(obj, 1, exception: false).should == nil
+ end
+
+ it "swallows an exception raised in #to_int" do
+ obj = Object.new
+ def obj.to_int; raise; end
+ Rational(obj, 1, exception: false).should == nil
+ end
+ end
+
+ describe "and [anything, non-Numeric]" do
+ it "swallows an error" do
+ Rational(:sym, :sym, exception: false).should == nil
+ Rational("abc", :sym, exception: false).should == nil
+ end
+
+ it "swallows an exception raised in #to_r" do
+ obj = Object.new
+ def obj.to_r; raise; end
+ Rational(obj, obj, exception: false).should == nil
+ end
+
+ it "swallows an exception raised in #to_int" do
+ obj = Object.new
+ def obj.to_int; raise; end
+ Rational(obj, obj, exception: false).should == nil
+ end
+ end
+
+ describe "and non-Numeric String arguments" do
+ it "swallows an error" do
+ Rational("a", "b", exception: false).should == nil
+ Rational("a", 0, exception: false).should == nil
+ Rational(0, "b", exception: false).should == nil
+ end
+ end
+
+ describe "and nil arguments" do
+ it "swallows an error" do
+ Rational(nil, exception: false).should == nil
+ Rational(nil, nil, exception: false).should == nil
+ end
+ end
+ end
+
+ it "freezes its result" do
+ Rational(1).frozen?.should == true
+ end
end
diff --git a/spec/ruby/core/kernel/String_spec.rb b/spec/ruby/core/kernel/String_spec.rb
index b24bc798e5..a9b0758ad7 100644
--- a/spec/ruby/core/kernel/String_spec.rb
+++ b/spec/ruby/core/kernel/String_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe :kernel_String, shared: true do
it "converts nil to a String" do
@@ -32,7 +32,7 @@ describe :kernel_String, shared: true do
undef_method :to_s
end
- lambda { @object.send(@method, obj) }.should raise_error(TypeError)
+ -> { @object.send(@method, obj) }.should.raise(TypeError)
end
# #5158
@@ -44,7 +44,7 @@ describe :kernel_String, shared: true do
end
end
- lambda { @object.send(@method, obj) }.should raise_error(TypeError)
+ -> { @object.send(@method, obj) }.should.raise(TypeError)
end
it "raises a TypeError if #to_s is not defined, even though #respond_to?(:to_s) returns true" do
@@ -57,7 +57,7 @@ describe :kernel_String, shared: true do
end
end
- lambda { @object.send(@method, obj) }.should raise_error(TypeError)
+ -> { @object.send(@method, obj) }.should.raise(TypeError)
end
it "calls #to_s if #respond_to?(:to_s) returns true" do
@@ -74,14 +74,14 @@ describe :kernel_String, shared: true do
it "raises a TypeError if #to_s does not return a String" do
(obj = mock('123')).should_receive(:to_s).and_return(123)
- lambda { @object.send(@method, obj) }.should raise_error(TypeError)
+ -> { @object.send(@method, obj) }.should.raise(TypeError)
end
it "returns the same object if it is already a String" do
- string = "Hello"
+ string = +"Hello"
string.should_not_receive(:to_s)
string2 = @object.send(@method, string)
- string.should equal(string2)
+ string.should.equal?(string2)
end
it "returns the same object if it is an instance of a String subclass" do
@@ -89,7 +89,7 @@ describe :kernel_String, shared: true do
string = subklass.new("Hello")
string.should_not_receive(:to_s)
string2 = @object.send(@method, string)
- string.should equal(string2)
+ string.should.equal?(string2)
end
end
@@ -101,6 +101,6 @@ describe "Kernel#String" do
it_behaves_like :kernel_String, :String, Object.new
it "is a private method" do
- Kernel.should have_private_instance_method(:String)
+ Kernel.private_instance_methods(false).should.include?(:String)
end
end
diff --git a/spec/ruby/core/kernel/__callee___spec.rb b/spec/ruby/core/kernel/__callee___spec.rb
index 91cc4cdafa..3059ea8b57 100644
--- a/spec/ruby/core/kernel/__callee___spec.rb
+++ b/spec/ruby/core/kernel/__callee___spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/__callee__', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/__callee__'
describe "Kernel.__callee__" do
it "returns the current method, even when aliased" do
diff --git a/spec/ruby/core/kernel/__dir___spec.rb b/spec/ruby/core/kernel/__dir___spec.rb
index 395d30f494..242adbf48b 100644
--- a/spec/ruby/core/kernel/__dir___spec.rb
+++ b/spec/ruby/core/kernel/__dir___spec.rb
@@ -1,13 +1,27 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Kernel#__dir__" do
it "returns the real name of the directory containing the currently-executing file" do
__dir__.should == File.realpath(File.dirname(__FILE__))
end
+ it "returns the expanded path of the directory when used in the main script" do
+ fixtures_dir = File.dirname(fixture(__FILE__, '__dir__.rb'))
+ Dir.chdir(fixtures_dir) do
+ ruby_exe("__dir__.rb").should == "__dir__.rb\n#{fixtures_dir}\n"
+ end
+ end
+
+ context "when used in eval with a given filename" do
+ it "returns File.dirname(filename)" do
+ eval("__dir__", nil, "foo.rb").should == "."
+ eval("__dir__", nil, "foo/bar.rb").should == "foo"
+ end
+ end
+
context "when used in eval with top level binding" do
- it "returns the real name of the directory containing the currently-executing file" do
- eval("__dir__", binding).should == File.realpath(File.dirname(__FILE__))
+ it "returns nil" do
+ eval("__dir__", binding).should == nil
end
end
end
diff --git a/spec/ruby/core/kernel/__method___spec.rb b/spec/ruby/core/kernel/__method___spec.rb
index 936a6b2f00..578d25640d 100644
--- a/spec/ruby/core/kernel/__method___spec.rb
+++ b/spec/ruby/core/kernel/__method___spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/__method__', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/__method__'
describe "Kernel.__method__" do
it "returns the current method, even when aliased" do
diff --git a/spec/ruby/core/kernel/abort_spec.rb b/spec/ruby/core/kernel/abort_spec.rb
index eb9c1c30c7..b75138182d 100644
--- a/spec/ruby/core/kernel/abort_spec.rb
+++ b/spec/ruby/core/kernel/abort_spec.rb
@@ -1,10 +1,10 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../../../shared/process/abort', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative '../../shared/process/abort'
describe "Kernel#abort" do
it "is a private method" do
- Kernel.should have_private_instance_method(:abort)
+ Kernel.private_instance_methods(false).should.include?(:abort)
end
it_behaves_like :process_abort, :abort, KernelSpecs::Method.new
diff --git a/spec/ruby/core/kernel/at_exit_spec.rb b/spec/ruby/core/kernel/at_exit_spec.rb
index 9fcb99148c..fdb0eaf34c 100644
--- a/spec/ruby/core/kernel/at_exit_spec.rb
+++ b/spec/ruby/core/kernel/at_exit_spec.rb
@@ -1,42 +1,17 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative '../../shared/kernel/at_exit'
describe "Kernel.at_exit" do
- it "is a private method" do
- Kernel.should have_private_instance_method(:at_exit)
- end
-
- it "runs after all other code" do
- ruby_exe("at_exit {print 5}; print 6").should == "65"
- end
-
- it "runs in reverse order of registration" do
- code = "at_exit {print 4};at_exit {print 5}; print 6; at_exit {print 7}"
- ruby_exe(code).should == "6754"
- end
+ it_behaves_like :kernel_at_exit, :at_exit
- it "allows calling exit inside at_exit handler" do
- code = "at_exit {print 3}; at_exit {print 4; exit; print 5}; at_exit {print 6}"
- ruby_exe(code).should == "643"
+ it "is a private method" do
+ Kernel.private_instance_methods(false).should.include?(:at_exit)
end
- it "gives access to the last raised exception" do
- code = <<-EOC
- at_exit do
- puts "The exception matches: \#{$! == $exception}"
- end
-
- begin
- raise "foo"
- rescue => $exception
- raise
- end
- EOC
-
- result = ruby_exe(code, args: "2>&1", escape: true)
- result.should =~ /The exception matches: true/
+ it "raises ArgumentError if called without a block" do
+ -> { at_exit }.should.raise(ArgumentError, "called without a block")
end
-
end
describe "Kernel#at_exit" do
diff --git a/spec/ruby/core/kernel/autoload_relative_spec.rb b/spec/ruby/core/kernel/autoload_relative_spec.rb
new file mode 100644
index 0000000000..7d03da8a40
--- /dev/null
+++ b/spec/ruby/core/kernel/autoload_relative_spec.rb
@@ -0,0 +1,114 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+# Specs for Kernel#autoload_relative
+
+ruby_version_is "4.1" do
+ describe "Kernel#autoload_relative" do
+ before :each do
+ @loaded_features = $".dup
+ end
+
+ after :each do
+ $".replace @loaded_features
+ # Clean up constants defined by these tests
+ [:KSAutoloadRelativeA, :KSAutoloadRelativeB, :KSAutoloadRelativeC,
+ :KSAutoloadRelativeE, :KSAutoloadRelativeF, :KSAutoloadRelativeG,
+ :KSAutoloadRelativeH, :KSAutoloadRelativeI].each do |const|
+ KernelSpecs.send(:remove_const, const) if KernelSpecs.const_defined?(const, false)
+ end
+ [:KSAutoloadRelativeD, :NestedTest].each do |const|
+ Object.send(:remove_const, const) if Object.const_defined?(const, false)
+ end
+ end
+
+ it "is a private method" do
+ Kernel.private_instance_methods(false).should.include?(:autoload_relative)
+ end
+
+ it "registers a file to load relative to the current file" do
+ KernelSpecs.autoload_relative :KSAutoloadRelativeA, "fixtures/autoload_relative_b.rb"
+ path = KernelSpecs.autoload?(:KSAutoloadRelativeA)
+ path.should_not == nil
+ path.should.end_with?("autoload_relative_b.rb")
+ File.exist?(path).should == true
+ end
+
+ it "loads the file when the constant is accessed" do
+ KernelSpecs.autoload_relative :KSAutoloadRelativeB, "fixtures/autoload_relative_b.rb"
+ KernelSpecs::KSAutoloadRelativeB.loaded.should == :ksautoload_b
+ end
+
+ it "sets the autoload constant in the constant table" do
+ KernelSpecs.autoload_relative :KSAutoloadRelativeC, "fixtures/autoload_relative_b.rb"
+ KernelSpecs.should.const_defined?(:KSAutoloadRelativeC, false)
+ end
+
+ it "can autoload in instance_eval with a file context" do
+ result = Object.new.instance_eval(<<-CODE, __FILE__, __LINE__)
+ autoload_relative :KSAutoloadRelativeD, "fixtures/autoload_relative_d.rb"
+ KSAutoloadRelativeD.loaded
+ CODE
+ result.should == :ksautoload_d
+ end
+
+ it "raises LoadError if called from eval without file context" do
+ -> {
+ eval('autoload_relative :Foo, "foo.rb"')
+ }.should.raise(LoadError, /autoload_relative called without file context/)
+ end
+
+ it "accepts both string and symbol for constant name" do
+ KernelSpecs.autoload_relative :KSAutoloadRelativeE, "fixtures/autoload_relative_b.rb"
+ KernelSpecs.autoload_relative "KSAutoloadRelativeF", "fixtures/autoload_relative_b.rb"
+
+ KernelSpecs.should.const_defined?(:KSAutoloadRelativeE, false)
+ KernelSpecs.should.const_defined?(:KSAutoloadRelativeF, false)
+ end
+
+ it "returns nil" do
+ KernelSpecs.autoload_relative(:KSAutoloadRelativeG, "fixtures/autoload_relative_b.rb").should == nil
+ end
+
+ it "resolves nested directory paths correctly" do
+ -> {
+ autoload_relative :NestedTest, "../kernel/fixtures/autoload_relative_b.rb"
+ autoload?(:NestedTest)
+ }.should_not.raise
+ end
+
+ it "resolves paths starting with ./" do
+ KernelSpecs.autoload_relative :KSAutoloadRelativeH, "./fixtures/autoload_relative_b.rb"
+ path = KernelSpecs.autoload?(:KSAutoloadRelativeH)
+ path.should_not == nil
+ path.should.end_with?("autoload_relative_b.rb")
+ end
+
+ it "ignores $LOAD_PATH and uses only relative path resolution" do
+ original_load_path = $LOAD_PATH.dup
+ $LOAD_PATH.clear
+ begin
+ KernelSpecs.autoload_relative :KSAutoloadRelativeI, "fixtures/autoload_relative_b.rb"
+ path = KernelSpecs.autoload?(:KSAutoloadRelativeI)
+ path.should_not == nil
+ # Should still resolve even with empty $LOAD_PATH
+ File.exist?(path).should == true
+ ensure
+ $LOAD_PATH.replace(original_load_path)
+ end
+ end
+
+ describe "when Object is frozen" do
+ it "raises a FrozenError before defining the constant" do
+ ruby_exe(<<-RUBY).should.include?("FrozenError")
+ Object.freeze
+ begin
+ autoload_relative :Foo, "autoload_b.rb"
+ rescue => e
+ puts e.class
+ end
+ RUBY
+ end
+ end
+ end
+end
diff --git a/spec/ruby/core/kernel/autoload_spec.rb b/spec/ruby/core/kernel/autoload_spec.rb
index e2741de74c..46783734c4 100644
--- a/spec/ruby/core/kernel/autoload_spec.rb
+++ b/spec/ruby/core/kernel/autoload_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
# These specs only illustrate the basic autoload cases
# and where toplevel autoload behaves differently from
@@ -7,7 +7,9 @@ require File.expand_path('../fixtures/classes', __FILE__)
autoload :KSAutoloadA, "autoload_a.rb"
autoload :KSAutoloadB, fixture(__FILE__, "autoload_b.rb")
-autoload :KSAutoloadC, fixture(__FILE__, "autoload_c.rb")
+define_autoload_KSAutoloadCallsRequire = -> {
+ autoload :KSAutoloadCallsRequire, "main_autoload_not_exist.rb"
+}
def check_autoload(const)
autoload? const
@@ -23,7 +25,7 @@ describe "Kernel#autoload" do
end
it "is a private method" do
- Kernel.should have_private_instance_method(:autoload)
+ Kernel.private_instance_methods(false).should.include?(:autoload)
end
it "registers a file to load the first time the named constant is accessed" do
@@ -35,17 +37,19 @@ describe "Kernel#autoload" do
end
it "sets the autoload constant in Object's constant table" do
- Object.should have_constant(:KSAutoloadA)
+ Object.should.const_defined?(:KSAutoloadA, false)
end
it "loads the file when the constant is accessed" do
KSAutoloadB.loaded.should == :ksautoload_b
end
- it "does not call Kernel.require or Kernel.load to load the file" do
- Kernel.should_not_receive(:require)
- Kernel.should_not_receive(:load)
- KSAutoloadC.loaded.should == :ksautoload_c
+ it "calls main.require(path) to load the file" do
+ define_autoload_KSAutoloadCallsRequire.call
+ main = TOPLEVEL_BINDING.eval("self")
+ main.should_receive(:require).with("main_autoload_not_exist.rb")
+ # The constant won't be defined since require is mocked to do nothing
+ -> { KSAutoloadCallsRequire }.should.raise(NameError)
end
it "can autoload in instance_eval" do
@@ -55,16 +59,50 @@ describe "Kernel#autoload" do
end
end
+ describe "inside a Class.new method body" do
+ # NOTE: this spec is being discussed in https://github.com/ruby/spec/pull/839
+ it "should define on the new anonymous class" do
+ cls = Class.new do
+ def go
+ autoload :Object, 'bogus'
+ autoload? :Object
+ end
+ end
+
+ cls.new.go.should == 'bogus'
+ cls.autoload?(:Object).should == 'bogus'
+ end
+ end
+
describe "when Object is frozen" do
- it "raises a RuntimeError before defining the constant" do
- ruby_exe(fixture(__FILE__, "autoload_frozen.rb")).should == "RuntimeError - nil"
+ it "raises a FrozenError before defining the constant" do
+ ruby_exe(fixture(__FILE__, "autoload_frozen.rb")).should == "FrozenError - nil"
+ end
+ end
+
+ describe "when called from included module's method" do
+ before :all do
+ @path = fixture(__FILE__, "autoload_from_included_module.rb")
+ KernelSpecs::AutoloadMethodIncluder.new.setup_autoload(@path)
+ end
+
+ it "setups the autoload on the included module" do
+ KernelSpecs::AutoloadMethod.autoload?(:AutoloadFromIncludedModule).should == @path
+ end
+
+ it "the autoload is reachable from the class too" do
+ KernelSpecs::AutoloadMethodIncluder.autoload?(:AutoloadFromIncludedModule).should == @path
+ end
+
+ it "the autoload relative to the included module works" do
+ KernelSpecs::AutoloadMethod::AutoloadFromIncludedModule.loaded.should == :autoload_from_included_module
end
end
end
describe "Kernel#autoload?" do
it "is a private method" do
- Kernel.should have_private_instance_method(:autoload?)
+ Kernel.private_instance_methods(false).should.include?(:autoload?)
end
it "returns the name of the file that will be autoloaded" do
@@ -72,7 +110,7 @@ describe "Kernel#autoload?" do
end
it "returns nil if no file has been registered for a constant" do
- check_autoload(:Manualload).should be_nil
+ check_autoload(:Manualload).should == nil
end
end
@@ -99,7 +137,7 @@ describe "Kernel.autoload" do
end
it "sets the autoload constant in Object's constant table" do
- Object.should have_constant(:KSAutoloadBB)
+ Object.should.const_defined?(:KSAutoloadBB, false)
end
it "calls #to_path on non-String filenames" do
@@ -107,6 +145,25 @@ describe "Kernel.autoload" do
p.should_receive(:to_path).and_return @non_existent
Kernel.autoload :KSAutoloadAA, p
end
+
+ describe "when called from included module's method" do
+ before :all do
+ @path = fixture(__FILE__, "autoload_from_included_module2.rb")
+ KernelSpecs::AutoloadMethodIncluder2.new.setup_autoload(@path)
+ end
+
+ it "setups the autoload on the included module" do
+ KernelSpecs::AutoloadMethod2.autoload?(:AutoloadFromIncludedModule2).should == @path
+ end
+
+ it "the autoload is reachable from the class too" do
+ KernelSpecs::AutoloadMethodIncluder2.autoload?(:AutoloadFromIncludedModule2).should == @path
+ end
+
+ it "the autoload relative to the included module works" do
+ KernelSpecs::AutoloadMethod2::AutoloadFromIncludedModule2.loaded.should == :autoload_from_included_module2
+ end
+ end
end
describe "Kernel.autoload?" do
@@ -116,6 +173,6 @@ describe "Kernel.autoload?" do
end
it "returns nil if no file has been registered for a constant" do
- Kernel.autoload?(:Manualload).should be_nil
+ Kernel.autoload?(:Manualload).should == nil
end
end
diff --git a/spec/ruby/core/kernel/backtick_spec.rb b/spec/ruby/core/kernel/backtick_spec.rb
index eb25750bc2..42e0f975f5 100644
--- a/spec/ruby/core/kernel/backtick_spec.rb
+++ b/spec/ruby/core/kernel/backtick_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Kernel#`" do
before :each do
@@ -11,7 +11,7 @@ describe "Kernel#`" do
end
it "is a private method" do
- Kernel.should have_private_instance_method(:`)
+ Kernel.private_instance_methods(false).should.include?(:`)
end
it "returns the standard output of the executed sub-process" do
@@ -21,35 +21,39 @@ describe "Kernel#`" do
it "lets the standard error stream pass through to the inherited stderr" do
cmd = ruby_cmd('STDERR.print "error stream"')
- lambda {
+ -> {
`#{cmd}`.should == ""
}.should output_to_fd("error stream", STDERR)
end
it "produces a String in the default external encoding" do
Encoding.default_external = Encoding::SHIFT_JIS
- `echo disc`.encoding.should equal(Encoding::SHIFT_JIS)
+ `echo disc`.encoding.should.equal?(Encoding::SHIFT_JIS)
end
it "raises an Errno::ENOENT if the command is not executable" do
- lambda { `nonexistent_command` }.should raise_error(Errno::ENOENT)
+ -> { `nonexistent_command` }.should.raise(Errno::ENOENT)
end
platform_is_not :windows do
+ it "handles invalid UTF-8 bytes in command" do
+ `echo "testing\xC2 a non UTF-8 string"`.b.should == "testing\xC2 a non UTF-8 string\n".b
+ end
+
it "sets $? to the exit status of the executed sub-process" do
ip = 'world'
`echo disc #{ip}`
- $?.should be_kind_of(Process::Status)
- $?.stopped?.should == false
- $?.exited?.should == true
+ $?.should.is_a?(Process::Status)
+ $?.should_not.stopped?
+ $?.should.exited?
$?.exitstatus.should == 0
- $?.success?.should == true
+ $?.should.success?
`echo disc #{ip}; exit 99`
- $?.should be_kind_of(Process::Status)
- $?.stopped?.should == false
- $?.exited?.should == true
+ $?.should.is_a?(Process::Status)
+ $?.should_not.stopped?
+ $?.should.exited?
$?.exitstatus.should == 99
- $?.success?.should == false
+ $?.should_not.success?
end
end
@@ -57,17 +61,17 @@ describe "Kernel#`" do
it "sets $? to the exit status of the executed sub-process" do
ip = 'world'
`echo disc #{ip}`
- $?.should be_kind_of(Process::Status)
- $?.stopped?.should == false
- $?.exited?.should == true
+ $?.should.is_a?(Process::Status)
+ $?.should_not.stopped?
+ $?.should.exited?
$?.exitstatus.should == 0
- $?.success?.should == true
+ $?.should.success?
`echo disc #{ip}& exit 99`
- $?.should be_kind_of(Process::Status)
- $?.stopped?.should == false
- $?.exited?.should == true
+ $?.should.is_a?(Process::Status)
+ $?.should_not.stopped?
+ $?.should.exited?
$?.exitstatus.should == 99
- $?.success?.should == false
+ $?.should_not.success?
end
end
end
diff --git a/spec/ruby/core/kernel/binding_spec.rb b/spec/ruby/core/kernel/binding_spec.rb
index 0b33c86d3c..6f27b26f37 100644
--- a/spec/ruby/core/kernel/binding_spec.rb
+++ b/spec/ruby/core/kernel/binding_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Kernel.binding" do
it "returns a binding for the caller" do
@@ -9,7 +9,7 @@ end
describe "Kernel#binding" do
it "is a private method" do
- Kernel.should have_private_instance_method(:binding)
+ Kernel.private_instance_methods(false).should.include?(:binding)
end
before :each do
@@ -35,7 +35,7 @@ describe "Kernel#binding" do
end
it "raises a NameError on undefined variable" do
- lambda { eval("a_fake_variable", @b1) }.should raise_error(NameError)
+ -> { eval("a_fake_variable", @b1) }.should.raise(NameError)
end
it "uses the closure's self as self in the binding" do
diff --git a/spec/ruby/core/kernel/block_given_spec.rb b/spec/ruby/core/kernel/block_given_spec.rb
index 9454c938ae..20bb90ae96 100644
--- a/spec/ruby/core/kernel/block_given_spec.rb
+++ b/spec/ruby/core/kernel/block_given_spec.rb
@@ -1,19 +1,24 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe :kernel_block_given, shared: true do
it "returns true if and only if a block is supplied" do
@object.accept_block {}.should == true
@object.accept_block_as_argument {}.should == true
+ @object.accept_block_inside_block {}.should == true
+ @object.accept_block_as_argument_inside_block {}.should == true
@object.accept_block.should == false
@object.accept_block_as_argument.should == false
+ @object.accept_block_inside_block.should == false
+ @object.accept_block_as_argument_inside_block.should == false
end
# Clarify: Based on http://www.ruby-forum.com/topic/137822 it appears
# that Matz wanted this to be true in 1.9.
it "returns false when a method defined by define_method is called with a block" do
@object.defined_block {}.should == false
+ @object.defined_block_inside_block {}.should == false
end
end
@@ -25,7 +30,7 @@ describe "Kernel#block_given?" do
end
it "is a private method" do
- Kernel.should have_private_instance_method(:block_given?)
+ Kernel.private_instance_methods(false).should.include?(:block_given?)
end
end
diff --git a/spec/ruby/core/kernel/caller_locations_spec.rb b/spec/ruby/core/kernel/caller_locations_spec.rb
index 69993c3ec0..04cf806ef4 100644
--- a/spec/ruby/core/kernel/caller_locations_spec.rb
+++ b/spec/ruby/core/kernel/caller_locations_spec.rb
@@ -1,19 +1,19 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/caller_locations', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/caller_locations'
describe 'Kernel#caller_locations' do
it 'is a private method' do
- Kernel.should have_private_instance_method(:caller_locations)
+ Kernel.private_instance_methods(false).should.include?(:caller_locations)
end
it 'returns an Array of caller locations' do
- KernelSpecs::CallerLocationsTest.locations.empty?.should == false
+ KernelSpecs::CallerLocationsTest.locations.should_not.empty?
end
it 'returns an Array of caller locations using a custom offset' do
locations = KernelSpecs::CallerLocationsTest.locations(2)
- locations[0].absolute_path.end_with?('mspec.rb').should == true
+ locations[0].absolute_path.should.end_with?('mspec.rb')
end
it 'returns an Array of caller locations using a custom limit' do
@@ -22,6 +22,42 @@ describe 'Kernel#caller_locations' do
locations.length.should == 1
end
+ it "can be called with a range" do
+ locations1 = caller_locations(0)
+ locations2 = caller_locations(2..4)
+ locations1[2..4].map(&:to_s).should == locations2.map(&:to_s)
+ end
+
+ it "works with endless ranges" do
+ locations1 = caller_locations(0)
+ locations2 = caller_locations(eval("(2..)"))
+ locations2.map(&:to_s).should == locations1[2..-1].map(&:to_s)
+ end
+
+ it "works with beginless ranges" do
+ locations1 = caller_locations(0)
+ locations2 = caller_locations((...5))
+ locations2.map(&:to_s)[eval("(2..)")].should == locations1[(...5)].map(&:to_s)[eval("(2..)")]
+ end
+
+ it "can be called with a range whose end is negative" do
+ locations1 = caller_locations(0)
+ locations2 = caller_locations(2..-1)
+ locations3 = caller_locations(2..-2)
+ locations1[2..-1].map(&:to_s).should == locations2.map(&:to_s)
+ locations1[2..-2].map(&:to_s).should == locations3.map(&:to_s)
+ end
+
+ it "must return nil if omitting more locations than available" do
+ caller_locations(100).should == nil
+ caller_locations(100..-1).should == nil
+ end
+
+ it "must return [] if omitting exactly the number of locations available" do
+ omit = caller_locations(0).length
+ caller_locations(omit).should == []
+ end
+
it 'returns the locations as Thread::Backtrace::Location instances' do
locations = KernelSpecs::CallerLocationsTest.locations
@@ -29,4 +65,49 @@ describe 'Kernel#caller_locations' do
location.kind_of?(Thread::Backtrace::Location).should == true
end
end
+
+ it "must return the same locations when called with 1..-1 and when called with no arguments" do
+ caller_locations.map(&:to_s).should == caller_locations(1..-1).map(&:to_s)
+ end
+
+ guard -> { Kernel.instance_method(:tap).source_location } do
+ ruby_version_is ""..."3.4" do
+ it "includes core library methods defined in Ruby" do
+ file, line = Kernel.instance_method(:tap).source_location
+ file.should.start_with?('<internal:')
+
+ loc = nil
+ tap { loc = caller_locations(1, 1)[0] }
+ loc.label.should == "tap"
+ loc.path.should.start_with? "<internal:"
+ end
+ end
+
+ ruby_version_is "3.4"..."4.0" do
+ it "includes core library methods defined in Ruby" do
+ file, line = Kernel.instance_method(:tap).source_location
+ file.should.start_with?('<internal:')
+
+ loc = nil
+ tap { loc = caller_locations(1, 1)[0] }
+ loc.label.should == "Kernel#tap"
+ loc.path.should.start_with? "<internal:"
+ end
+ end
+
+ ruby_version_is "4.0" do
+ it "does not include core library methods defined in Ruby" do
+ file, line = Kernel.instance_method(:tap).source_location
+ file.should.start_with?('<internal:')
+
+ loc = nil
+ tap { loc = caller_locations(1, 1)[0] }
+ loc.label.should == "Kernel#tap"
+ # CRuby hides the file which defines the method: https://bugs.ruby-lang.org/issues/20968
+ unless loc.path == __FILE__
+ loc.path.should.start_with? "<internal:"
+ end
+ end
+ end
+ end
end
diff --git a/spec/ruby/core/kernel/caller_spec.rb b/spec/ruby/core/kernel/caller_spec.rb
index d9be29a8db..225f6fc458 100644
--- a/spec/ruby/core/kernel/caller_spec.rb
+++ b/spec/ruby/core/kernel/caller_spec.rb
@@ -1,13 +1,13 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/caller', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/caller'
describe 'Kernel#caller' do
it 'is a private method' do
- Kernel.should have_private_instance_method(:caller)
+ Kernel.private_instance_methods(false).should.include?(:caller)
end
it 'returns an Array of caller locations' do
- KernelSpecs::CallerTest.locations.empty?.should == false
+ KernelSpecs::CallerTest.locations.should_not.empty?
end
it 'returns an Array of caller locations using a custom offset' do
@@ -32,6 +32,90 @@ describe 'Kernel#caller' do
locations = KernelSpecs::CallerTest.locations
line = __LINE__ - 1
- locations[0].should include("#{__FILE__}:#{line}:in")
+ locations[0].should.include?("#{__FILE__}:#{line}:in")
+ end
+
+ it "returns an Array with the block given to #at_exit at the base of the stack" do
+ path = fixture(__FILE__, "caller_at_exit.rb")
+ lines = ruby_exe(path).lines
+ lines.size.should == 2
+ lines[0].should =~ /\A#{path}:6:in [`'](?:Object#)?foo'\n\z/
+ lines[1].should =~ /\A#{path}:2:in [`']block in <main>'\n\z/
+ end
+
+ it "can be called with a range" do
+ locations1 = caller(0)
+ locations2 = caller(2..4)
+ locations1[2..4].should == locations2
+ end
+
+ it "works with endless ranges" do
+ locations1 = KernelSpecs::CallerTest.locations(0)
+ locations2 = KernelSpecs::CallerTest.locations(eval("(2..)"))
+ locations2.should == locations1[2..-1]
+ end
+
+ it "works with beginless ranges" do
+ locations1 = KernelSpecs::CallerTest.locations(0)
+ locations2 = KernelSpecs::CallerTest.locations((..5))
+ locations2[eval("(2..)")].should == locations1[(..5)][eval("(2..)")]
+ end
+
+ it "can be called with a range whose end is negative" do
+ locations1 = caller(0)
+ locations2 = caller(2..-1)
+ locations3 = caller(2..-2)
+ locations1[2..-1].should == locations2
+ locations1[2..-2].should == locations3
+ end
+
+ it "must return nil if omitting more locations than available" do
+ caller(100).should == nil
+ caller(100..-1).should == nil
+ end
+
+ it "must return [] if omitting exactly the number of locations available" do
+ omit = caller(0).length
+ caller(omit).should == []
+ end
+
+ it "must return the same locations when called with 1..-1 and when called with no arguments" do
+ caller.should == caller(1..-1)
+ end
+
+ guard -> { Kernel.instance_method(:tap).source_location } do
+ ruby_version_is ""..."3.4" do
+ it "includes core library methods defined in Ruby" do
+ file, line = Kernel.instance_method(:tap).source_location
+ file.should.start_with?('<internal:')
+
+ loc = nil
+ tap { loc = caller(1, 1)[0] }
+ loc.should =~ /\A<internal:.*in `tap'\z/
+ end
+ end
+
+ ruby_version_is "3.4"..."4.0" do
+ it "includes core library methods defined in Ruby" do
+ file, line = Kernel.instance_method(:tap).source_location
+ file.should.start_with?('<internal:')
+
+ loc = nil
+ tap { loc = caller(1, 1)[0] }
+ loc.should =~ /\A<internal:.*in 'Kernel#tap'\z/
+ end
+ end
+
+ ruby_version_is "4.0" do
+ it "does not include core library methods defined in Ruby" do
+ file, line = Kernel.instance_method(:tap).source_location
+ file.should.start_with?('<internal:')
+
+ loc = nil
+ tap { loc = caller(1, 1)[0] }
+ # CRuby hides the file which defines the method: https://bugs.ruby-lang.org/issues/20968
+ loc.should =~ /\A(<internal:|#{__FILE__}:).*in 'Kernel#tap'\z/
+ end
+ end
end
end
diff --git a/spec/ruby/core/kernel/case_compare_spec.rb b/spec/ruby/core/kernel/case_compare_spec.rb
index 5332aa7647..c74bbf63b9 100644
--- a/spec/ruby/core/kernel/case_compare_spec.rb
+++ b/spec/ruby/core/kernel/case_compare_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
module Specs
@@ -58,18 +58,18 @@ describe "Kernel#=== for a class with #== overridden to consider other object's
end
it "returns true if #== returns true even if #equal? is false" do
- @o1.should_not equal(@o2)
+ @o1.should_not.equal?(@o2)
(@o1 == @o2).should == true
(@o1 === @o2).should == true
end
it "returns true if #equal? returns true" do
- @o1.should equal(@o1)
+ @o1.should.equal?(@o1)
(@o1 === @o1).should == true
end
it "returns false if neither #== nor #equal? returns true" do
- @o1.should_not equal(@o)
+ @o1.should_not.equal?(@o)
(@o1 == @o).should == false
(@o1 === @o).should == false
end
@@ -83,13 +83,13 @@ describe "Kernel#=== for a class with #equal? overridden to always be false" do
end
it "returns true if #== returns true even if #equal? is false" do
- @o1.should_not equal(@o1)
+ @o1.should_not.equal?(@o1)
(@o1 == @o1).should == true
(@o1 === @o1).should == true
end
it "returns false if neither #== nor #equal? returns true" do
- @o1.should_not equal(@o)
+ @o1.should_not.equal?(@o)
(@o1 == @o).should == false
(@o1 === @o).should == false
end
@@ -105,7 +105,7 @@ describe "Kernel#=== for a class with #== and #equal? overridden to always be fa
it "returns true if the object id is the same even if both #== and #equal? return false" do
@o1.object_id.should == @o1.object_id
- @o1.should_not equal(@o1)
+ @o1.should_not.equal?(@o1)
(@o1 == @o1).should == false
(@o1 === @o1).should == true
@@ -114,7 +114,7 @@ describe "Kernel#=== for a class with #== and #equal? overridden to always be fa
it "returns false if the object id is not the same and both #== and #equal? return false" do
@o1.object_id.should_not == @o2.object_id
- @o1.should_not equal(@o2)
+ @o1.should_not.equal?(@o2)
(@o1 == @o2).should == false
(@o1 === @o2).should == false
diff --git a/spec/ruby/core/kernel/catch_spec.rb b/spec/ruby/core/kernel/catch_spec.rb
index 35a4860f38..9f02303678 100644
--- a/spec/ruby/core/kernel/catch_spec.rb
+++ b/spec/ruby/core/kernel/catch_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Kernel.catch" do
before :each do
@@ -31,11 +31,11 @@ describe "Kernel.catch" do
end
it "raises an ArgumentError if a Symbol is thrown for a String catch value" do
- lambda { catch("exit") { throw :exit } }.should raise_error(ArgumentError)
+ -> { catch("exit") { throw :exit } }.should.raise(ArgumentError)
end
it "raises an ArgumentError if a String with different identity is thrown" do
- lambda { catch("exit") { throw "exit" } }.should raise_error(ArgumentError)
+ -> { catch("exit".dup) { throw "exit".dup } }.should.raise(ArgumentError)
end
it "catches a Symbol when thrown a matching Symbol" do
@@ -60,7 +60,7 @@ describe "Kernel.catch" do
end
it "yields an object when called without arguments" do
- catch { |tag| tag }.should be_an_instance_of(Object)
+ catch { |tag| tag }.should.instance_of?(Object)
end
it "can be used even in a method different from where throw is called" do
@@ -116,12 +116,12 @@ describe "Kernel.catch" do
end
it "raises LocalJumpError if no block is given" do
- lambda { catch :blah }.should raise_error(LocalJumpError)
+ -> { catch :blah }.should.raise(LocalJumpError)
end
end
describe "Kernel#catch" do
it "is a private method" do
- Kernel.should have_private_instance_method(:catch)
+ Kernel.private_instance_methods(false).should.include?(:catch)
end
end
diff --git a/spec/ruby/core/kernel/chomp_spec.rb b/spec/ruby/core/kernel/chomp_spec.rb
index 524a4c8b1d..434bf652f9 100644
--- a/spec/ruby/core/kernel/chomp_spec.rb
+++ b/spec/ruby/core/kernel/chomp_spec.rb
@@ -1,6 +1,6 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe :kernel_chomp, shared: true do
it "removes the final newline of $_" do
@@ -26,7 +26,7 @@ end
describe :kernel_chomp_private, shared: true do
it "is a private method" do
- KernelSpecs.has_private_method(@method).should be_true
+ KernelSpecs.has_private_method(@method).should == true
end
end
@@ -40,28 +40,26 @@ describe "Kernel#chomp" do
it_behaves_like :kernel_chomp_private, :chomp
end
-with_feature :encoding do
- describe :kernel_chomp_encoded, shared: true do
- before :each do
- @external = Encoding.default_external
- Encoding.default_external = Encoding::UTF_8
- end
-
- after :each do
- Encoding.default_external = @external
- end
-
- it "removes the final carriage return, newline from a multi-byte $_" do
- script = fixture __FILE__, "#{@method}.rb"
- KernelSpecs.run_with_dash_n(script).should == "ã‚れ"
- end
+describe :kernel_chomp_encoded, shared: true do
+ before :each do
+ @external = Encoding.default_external
+ Encoding.default_external = Encoding::UTF_8
end
- describe "Kernel.chomp" do
- it_behaves_like :kernel_chomp_encoded, "chomp"
+ after :each do
+ Encoding.default_external = @external
end
- describe "Kernel#chomp" do
- it_behaves_like :kernel_chomp_encoded, "chomp_f"
+ it "removes the final carriage return, newline from a multi-byte $_" do
+ script = fixture __FILE__, "#{@method}.rb"
+ KernelSpecs.run_with_dash_n(script).should == "ã‚れ"
end
end
+
+describe "Kernel.chomp" do
+ it_behaves_like :kernel_chomp_encoded, "chomp"
+end
+
+describe "Kernel#chomp" do
+ it_behaves_like :kernel_chomp_encoded, "chomp_f"
+end
diff --git a/spec/ruby/core/kernel/chop_spec.rb b/spec/ruby/core/kernel/chop_spec.rb
index 5106fefee8..bbf3c3f724 100644
--- a/spec/ruby/core/kernel/chop_spec.rb
+++ b/spec/ruby/core/kernel/chop_spec.rb
@@ -1,6 +1,6 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe :kernel_chop, shared: true do
it "removes the final character of $_" do
@@ -14,7 +14,7 @@ end
describe :kernel_chop_private, shared: true do
it "is a private method" do
- KernelSpecs.has_private_method(@method).should be_true
+ KernelSpecs.has_private_method(@method).should == true
end
end
@@ -28,28 +28,26 @@ describe "Kernel#chop" do
it_behaves_like :kernel_chop, "chop"
end
-with_feature :encoding do
- describe :kernel_chop_encoded, shared: true do
- before :each do
- @external = Encoding.default_external
- Encoding.default_external = Encoding::UTF_8
- end
-
- after :each do
- Encoding.default_external = @external
- end
-
- it "removes the final multi-byte character from $_" do
- script = fixture __FILE__, "#{@method}.rb"
- KernelSpecs.run_with_dash_n(script).should == "ã‚"
- end
+describe :kernel_chop_encoded, shared: true do
+ before :each do
+ @external = Encoding.default_external
+ Encoding.default_external = Encoding::UTF_8
end
- describe "Kernel.chop" do
- it_behaves_like :kernel_chop_encoded, "chop"
+ after :each do
+ Encoding.default_external = @external
end
- describe "Kernel#chop" do
- it_behaves_like :kernel_chop_encoded, "chop_f"
+ it "removes the final multi-byte character from $_" do
+ script = fixture __FILE__, "#{@method}.rb"
+ KernelSpecs.run_with_dash_n(script).should == "ã‚"
end
end
+
+describe "Kernel.chop" do
+ it_behaves_like :kernel_chop_encoded, "chop"
+end
+
+describe "Kernel#chop" do
+ it_behaves_like :kernel_chop_encoded, "chop_f"
+end
diff --git a/spec/ruby/core/kernel/class_spec.rb b/spec/ruby/core/kernel/class_spec.rb
index 0d7b40c366..0a7f774d14 100644
--- a/spec/ruby/core/kernel/class_spec.rb
+++ b/spec/ruby/core/kernel/class_spec.rb
@@ -1,26 +1,26 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Kernel#class" do
it "returns the class of the object" do
- Object.new.class.should equal(Object)
+ Object.new.class.should.equal?(Object)
- 1.class.should equal(Fixnum)
- 3.14.class.should equal(Float)
- :hello.class.should equal(Symbol)
- "hello".class.should equal(String)
- [1, 2].class.should equal(Array)
- { 1 => 2 }.class.should equal(Hash)
+ 1.class.should.equal?(Integer)
+ 3.14.class.should.equal?(Float)
+ :hello.class.should.equal?(Symbol)
+ "hello".class.should.equal?(String)
+ [1, 2].class.should.equal?(Array)
+ { 1 => 2 }.class.should.equal?(Hash)
end
it "returns Class for a class" do
- BasicObject.class.should equal(Class)
- String.class.should equal(Class)
+ BasicObject.class.should.equal?(Class)
+ String.class.should.equal?(Class)
end
it "returns the first non-singleton class" do
- a = "hello"
+ a = +"hello"
def a.my_singleton_method; end
- a.class.should equal(String)
+ a.class.should.equal?(String)
end
end
diff --git a/spec/ruby/core/kernel/clone_spec.rb b/spec/ruby/core/kernel/clone_spec.rb
index 48b3c24c7f..80e7a78abb 100644
--- a/spec/ruby/core/kernel/clone_spec.rb
+++ b/spec/ruby/core/kernel/clone_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/dup_clone', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/dup_clone'
describe "Kernel#clone" do
it_behaves_like :kernel_dup_clone, :clone
@@ -10,12 +10,6 @@ describe "Kernel#clone" do
@obj = KernelSpecs::Duplicate.new 1, :a
end
- it "calls #initialize_copy on the new instance" do
- clone = @obj.clone
- ScratchPad.recorded.should_not == @obj.object_id
- ScratchPad.recorded.should == clone.object_id
- end
-
it "uses the internal allocator and does not call #allocate" do
klass = Class.new
instance = klass.new
@@ -25,25 +19,90 @@ describe "Kernel#clone" do
end
clone = instance.clone
- clone.class.should equal klass
+ clone.class.should.equal? klass
end
- it "copies frozen state from the original" do
- o2 = @obj.clone
- @obj.freeze
- o3 = @obj.clone
+ describe "with no arguments" do
+ it "copies frozen state from the original" do
+ o2 = @obj.clone
+ o2.should_not.frozen?
- o2.frozen?.should == false
- o3.frozen?.should == true
+ @obj.freeze
+ o3 = @obj.clone
+ o3.should.frozen?
+ end
+
+ it 'copies frozen?' do
+ o = ''.freeze.clone
+ o.frozen?.should == true
+ end
end
- ruby_version_is '2.4' do
- it 'takes an option to copy freeze state or not' do
- @obj.clone(freeze: true).frozen?.should == false
- @obj.clone(freeze: false).frozen?.should == false
+ describe "with freeze: nil" do
+ it "copies frozen state from the original, like #clone without arguments" do
+ o2 = @obj.clone(freeze: nil)
+ o2.should_not.frozen?
+
@obj.freeze
- @obj.clone(freeze: true).frozen?.should == true
- @obj.clone(freeze: false).frozen?.should == false
+ o3 = @obj.clone(freeze: nil)
+ o3.should.frozen?
+ end
+
+ it "copies frozen?" do
+ o = "".freeze.clone(freeze: nil)
+ o.frozen?.should == true
+ end
+ end
+
+ describe "with freeze: true" do
+ it 'makes a frozen copy if the original is frozen' do
+ @obj.freeze
+ @obj.clone(freeze: true).should.frozen?
+ end
+
+ it 'freezes the copy even if the original was not frozen' do
+ @obj.clone(freeze: true).should.frozen?
+ end
+
+ it "calls #initialize_clone with kwargs freeze: true" do
+ obj = KernelSpecs::CloneFreeze.new
+ obj.clone(freeze: true)
+ ScratchPad.recorded.should == [obj, { freeze: true }]
+ end
+
+ it "calls #initialize_clone with kwargs freeze: true even if #initialize_clone only takes a single argument" do
+ obj = KernelSpecs::Clone.new
+ -> { obj.clone(freeze: true) }.should.raise(ArgumentError, 'wrong number of arguments (given 2, expected 1)')
+ end
+ end
+
+ describe "with freeze: false" do
+ it 'does not freeze the copy if the original is frozen' do
+ @obj.freeze
+ @obj.clone(freeze: false).should_not.frozen?
+ end
+
+ it 'does not freeze the copy if the original is not frozen' do
+ @obj.clone(freeze: false).should_not.frozen?
+ end
+
+ it "calls #initialize_clone with kwargs freeze: false" do
+ obj = KernelSpecs::CloneFreeze.new
+ obj.clone(freeze: false)
+ ScratchPad.recorded.should == [obj, { freeze: false }]
+ end
+
+ it "calls #initialize_clone with kwargs freeze: false even if #initialize_clone only takes a single argument" do
+ obj = KernelSpecs::Clone.new
+ -> { obj.clone(freeze: false) }.should.raise(ArgumentError, 'wrong number of arguments (given 2, expected 1)')
+ end
+ end
+
+ describe "with freeze: anything else" do
+ it 'raises ArgumentError when passed not true/false/nil' do
+ -> { @obj.clone(freeze: 1) }.should.raise(ArgumentError, /unexpected value for freeze: Integer/)
+ -> { @obj.clone(freeze: "") }.should.raise(ArgumentError, /unexpected value for freeze: String/)
+ -> { @obj.clone(freeze: Object.new) }.should.raise(ArgumentError, /unexpected value for freeze: Object/)
end
end
@@ -109,10 +168,4 @@ describe "Kernel#clone" do
cloned.bar.should == ['a']
end
-
- it 'copies frozen? and tainted?' do
- o = ''.taint.freeze.clone
- o.frozen?.should be_true
- o.tainted?.should be_true
- end
end
diff --git a/spec/ruby/core/kernel/comparison_spec.rb b/spec/ruby/core/kernel/comparison_spec.rb
index 2aa4358600..48f17e1172 100644
--- a/spec/ruby/core/kernel/comparison_spec.rb
+++ b/spec/ruby/core/kernel/comparison_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Kernel#<=>" do
it "returns 0 if self" do
@@ -15,17 +15,17 @@ describe "Kernel#<=>" do
it "returns nil if self is eql? but not == to the argument" do
obj = mock('has eql?')
obj.should_not_receive(:eql?)
- obj.<=>(Object.new).should be_nil
+ obj.<=>(Object.new).should == nil
end
it "returns nil if self.==(arg) returns nil" do
obj = mock('wrong ==')
obj.should_receive(:==).and_return(nil)
- obj.<=>(Object.new).should be_nil
+ obj.<=>(Object.new).should == nil
end
it "returns nil if self is not == to the argument" do
obj = Object.new
- obj.<=>(3.14).should be_nil
+ obj.<=>(3.14).should == nil
end
end
diff --git a/spec/ruby/core/kernel/define_singleton_method_spec.rb b/spec/ruby/core/kernel/define_singleton_method_spec.rb
index de6f7fc286..ec48581db8 100644
--- a/spec/ruby/core/kernel/define_singleton_method_spec.rb
+++ b/spec/ruby/core/kernel/define_singleton_method_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Kernel#define_singleton_method" do
describe "when given an UnboundMethod" do
@@ -14,14 +14,14 @@ describe "Kernel#define_singleton_method" do
end
it "adds the new method to the methods list" do
- DefineSingletonMethodSpecClass.should have_method(:another_test_method)
+ DefineSingletonMethodSpecClass.should.respond_to?(:another_test_method)
end
it "defines any Child class method from any Parent's class methods" do
um = KernelSpecs::Parent.method(:parent_class_method).unbind
KernelSpecs::Child.send :define_singleton_method, :child_class_method, um
KernelSpecs::Child.child_class_method.should == :foo
- lambda{KernelSpecs::Parent.child_class_method}.should raise_error(NoMethodError)
+ ->{KernelSpecs::Parent.child_class_method}.should.raise(NoMethodError)
end
it "will raise when attempting to define an object's singleton method from another object's singleton method" do
@@ -33,7 +33,7 @@ describe "Kernel#define_singleton_method" do
end
end
um = p.method(:singleton_method).unbind
- lambda{ other.send :define_singleton_method, :other_singleton_method, um }.should raise_error(TypeError)
+ ->{ other.send :define_singleton_method, :other_singleton_method, um }.should.raise(TypeError)
end
end
@@ -41,7 +41,7 @@ describe "Kernel#define_singleton_method" do
it "defines a new method with the given name and the given block as body in self" do
class DefineSingletonMethodSpecClass
define_singleton_method(:block_test1) { self }
- define_singleton_method(:block_test2, &lambda { self })
+ define_singleton_method(:block_test2, &-> { self })
end
o = DefineSingletonMethodSpecClass
@@ -50,22 +50,22 @@ describe "Kernel#define_singleton_method" do
end
it "raises a TypeError when the given method is no Method/Proc" do
- lambda {
+ -> {
Class.new { define_singleton_method(:test, "self") }
- }.should raise_error(TypeError)
+ }.should.raise(TypeError)
- lambda {
+ -> {
Class.new { define_singleton_method(:test, 1234) }
- }.should raise_error(TypeError)
+ }.should.raise(TypeError)
end
it "defines a new singleton method for objects" do
obj = Object.new
obj.define_singleton_method(:test) { "world!" }
obj.test.should == "world!"
- lambda {
+ -> {
Object.new.test
- }.should raise_error(NoMethodError)
+ }.should.raise(NoMethodError)
end
it "maintains the Proc's scope" do
@@ -81,21 +81,40 @@ describe "Kernel#define_singleton_method" do
it "raises an ArgumentError when no block is given" do
obj = Object.new
- lambda {
+ -> {
obj.define_singleton_method(:test)
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
end
- ruby_version_is "2.3" do
- it "does not use the caller block when no block is given" do
- o = Object.new
- def o.define(name)
- define_singleton_method(name)
- end
+ it "does not use the caller block when no block is given" do
+ o = Object.new
+ def o.define(name)
+ define_singleton_method(name)
+ end
+
+ -> {
+ o.define(:foo) { raise "not used" }
+ }.should.raise(ArgumentError)
+ end
- lambda {
- o.define(:foo) { raise "not used" }
- }.should raise_error(ArgumentError)
+ it "always defines the method with public visibility" do
+ cls = Class.new
+ def cls.define(name, &block)
+ private
+ define_singleton_method(name, &block)
end
+
+ -> {
+ suppress_warning do
+ cls.define(:foo) { :ok }
+ end
+ cls.foo.should == :ok
+ }.should_not.raise(NoMethodError)
+ end
+
+ it "cannot define a singleton method with a frozen singleton class" do
+ o = Object.new
+ o.freeze
+ -> { o.define_singleton_method(:foo) { 1 } }.should.raise(FrozenError)
end
end
diff --git a/spec/ruby/core/kernel/display_spec.rb b/spec/ruby/core/kernel/display_spec.rb
index e771e14cdb..9d429a9fac 100644
--- a/spec/ruby/core/kernel/display_spec.rb
+++ b/spec/ruby/core/kernel/display_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Kernel#display" do
it "needs to be reviewed for spec completeness"
diff --git a/spec/ruby/core/kernel/dup_spec.rb b/spec/ruby/core/kernel/dup_spec.rb
index af7e924a66..fa4ca71476 100644
--- a/spec/ruby/core/kernel/dup_spec.rb
+++ b/spec/ruby/core/kernel/dup_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/dup_clone', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/dup_clone'
describe "Kernel#dup" do
it_behaves_like :kernel_dup_clone, :dup
@@ -10,12 +10,6 @@ describe "Kernel#dup" do
@obj = KernelSpecs::Duplicate.new 1, :a
end
- it "calls #initialize_copy on the new instance" do
- dup = @obj.dup
- ScratchPad.recorded.should_not == @obj.object_id
- ScratchPad.recorded.should == dup.object_id
- end
-
it "uses the internal allocator and does not call #allocate" do
klass = Class.new
instance = klass.new
@@ -25,14 +19,14 @@ describe "Kernel#dup" do
end
dup = instance.dup
- dup.class.should equal klass
+ dup.class.should.equal? klass
end
it "does not copy frozen state from the original" do
@obj.freeze
dup = @obj.dup
- dup.frozen?.should == false
+ dup.should_not.frozen?
end
it "copies instance variables" do
@@ -44,7 +38,7 @@ describe "Kernel#dup" do
it "does not copy singleton methods" do
def @obj.special() :the_one end
dup = @obj.dup
- lambda { dup.special }.should raise_error(NameError)
+ -> { dup.special }.should.raise(NameError)
end
it "does not copy modules included in the singleton class" do
@@ -53,7 +47,7 @@ describe "Kernel#dup" do
end
dup = @obj.dup
- lambda { dup.repr }.should raise_error(NameError)
+ -> { dup.repr }.should.raise(NameError)
end
it "does not copy constants defined in the singleton class" do
@@ -62,6 +56,6 @@ describe "Kernel#dup" do
end
dup = @obj.dup
- lambda { class << dup; CLONE; end }.should raise_error(NameError)
+ -> { class << dup; CLONE; end }.should.raise(NameError)
end
end
diff --git a/spec/ruby/core/kernel/enum_for_spec.rb b/spec/ruby/core/kernel/enum_for_spec.rb
index 819140e0e4..ef0fb64e63 100644
--- a/spec/ruby/core/kernel/enum_for_spec.rb
+++ b/spec/ruby/core/kernel/enum_for_spec.rb
@@ -1,5 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Kernel#enum_for" do
- it "needs to be reviewed for spec completeness"
+ it "is an alias of Kernel#to_enum" do
+ Kernel.instance_method(:enum_for).should == Kernel.instance_method(:to_enum)
+ end
end
diff --git a/spec/ruby/core/kernel/eql_spec.rb b/spec/ruby/core/kernel/eql_spec.rb
index 39c9fea7eb..b3289090e5 100644
--- a/spec/ruby/core/kernel/eql_spec.rb
+++ b/spec/ruby/core/kernel/eql_spec.rb
@@ -1,11 +1,10 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/kernel/equal', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../../shared/kernel/equal'
describe "Kernel#eql?" do
it "is a public instance method" do
- Kernel.should have_public_instance_method(:eql?)
+ Kernel.public_instance_methods(false).should.include?(:eql?)
end
it_behaves_like :object_equal, :eql?
end
-
diff --git a/spec/ruby/core/kernel/equal_value_spec.rb b/spec/ruby/core/kernel/equal_value_spec.rb
index a66493f283..2be151263d 100644
--- a/spec/ruby/core/kernel/equal_value_spec.rb
+++ b/spec/ruby/core/kernel/equal_value_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Kernel#==" do
it "returns true only if obj and other are the same object" do
diff --git a/spec/ruby/core/kernel/eval_spec.rb b/spec/ruby/core/kernel/eval_spec.rb
index 96fc0f5b71..f9ca47866e 100644
--- a/spec/ruby/core/kernel/eval_spec.rb
+++ b/spec/ruby/core/kernel/eval_spec.rb
@@ -1,11 +1,11 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
EvalSpecs::A.new.c
describe "Kernel#eval" do
it "is a private method" do
- Kernel.should have_private_instance_method(:eval)
+ Kernel.private_instance_methods(false).should.include?(:eval)
end
it "is a module function" do
@@ -24,7 +24,7 @@ describe "Kernel#eval" do
EvalSpecs::A::B.name.should == "EvalSpecs::A::B"
end
- it "evaluates such that consts are scoped to the class of the eval" do
+ it "evaluates such that constants are scoped to the class of the eval" do
EvalSpecs::A::C.name.should == "EvalSpecs::A::C"
end
@@ -76,12 +76,12 @@ describe "Kernel#eval" do
x = 1
bind = proc {}
- lambda { eval("x", bind) }.should raise_error(TypeError)
+ -> { eval("x", bind) }.should.raise(TypeError)
end
it "does not make Proc locals visible to evaluated code" do
bind = proc { inner = 4 }
- lambda { eval("inner", bind.binding) }.should raise_error(NameError)
+ -> { eval("inner", bind.binding) }.should.raise(NameError)
end
# REWRITE ME: This obscures the real behavior of where locals are stored
@@ -119,7 +119,7 @@ describe "Kernel#eval" do
outer_binding = binding
eval("if false; a = 1; end", outer_binding)
- eval("a", outer_binding).should be_nil
+ eval("a", outer_binding).should == nil
end
it "allows creating a new class in a binding" do
@@ -134,18 +134,18 @@ describe "Kernel#eval" do
it "includes file and line information in syntax error" do
expected = 'speccing.rb'
- lambda {
- eval('if true',TOPLEVEL_BINDING, expected)
- }.should raise_error(SyntaxError) { |e|
+ -> {
+ eval('if true', TOPLEVEL_BINDING, expected)
+ }.should.raise(SyntaxError) { |e|
e.message.should =~ /#{expected}:1:.+/
}
end
it "evaluates string with given filename and negative linenumber" do
expected_file = 'speccing.rb'
- lambda {
- eval('if true',TOPLEVEL_BINDING, expected_file, -100)
- }.should raise_error(SyntaxError) { |e|
+ -> {
+ eval('if true', TOPLEVEL_BINDING, expected_file, -100)
+ }.should.raise(SyntaxError) { |e|
e.message.should =~ /#{expected_file}:-100:.+/
}
end
@@ -159,15 +159,88 @@ describe "Kernel#eval" do
end
end
- it "uses the filename of the binding if none is provided" do
- eval("__FILE__").should == "(eval)"
- eval("__FILE__", binding).should == __FILE__
+ context "parameter forwarding" do
+ it "allows anonymous rest parameter forwarding" do
+ object = Object.new
+ def object.foo(a, b, c)
+ [a, b, c]
+ end
+ def object.bar(*)
+ eval "foo(*)"
+ end
+
+ object.bar(1, 2, 3).should == [1, 2, 3]
+ end
+
+ it "allows anonymous keyword parameters forwarding" do
+ object = Object.new
+ def object.foo(a:, b:, c:)
+ [a, b, c]
+ end
+ def object.bar(**)
+ eval "foo(**)"
+ end
+
+ object.bar(a: 1, b: 2, c: 3).should == [1, 2, 3]
+ end
+
+ it "allows anonymous block parameter forwarding" do
+ object = Object.new
+ def object.foo(&block)
+ block.call
+ end
+ def object.bar(&)
+ eval "foo(&)"
+ end
+
+ object.bar { :foobar }.should == :foobar
+ end
+
+ it "allows ... forwarding" do
+ object = Object.new
+ def object.foo(a, b:, &block)
+ [a, b, block.call]
+ end
+ def object.bar(...)
+ eval "foo(...)"
+ end
+
+ object.bar(1, b: 2) { 3 }.should == [1, 2, 3]
+ end
+
+ it "allows parameter forwarding to super" do
+ m = Module.new do
+ def foo(a, b:, &block)
+ [a, b, block.call]
+ end
+ end
+
+ c = Class.new do
+ include m
+
+ def foo(a, b:, &block)
+ eval "super"
+ end
+ end
+
+ object = c.new
+ object.foo(1, b: 2) { 3 }.should == [1, 2, 3]
+ end
+ end
+
+ it "uses (eval at __FILE__:__LINE__) if none is provided" do
+ eval("__FILE__").should == "(eval at #{__FILE__}:#{__LINE__})"
+ eval("__FILE__", binding).should == "(eval at #{__FILE__}:#{__LINE__})"
eval("__FILE__", binding, "success").should == "success"
- eval("eval '__FILE__', binding").should == "(eval)"
- eval("eval '__FILE__', binding", binding).should == __FILE__
- eval("eval '__FILE__', binding", binding, 'success').should == 'success'
+ eval("eval '__FILE__', binding").should == "(eval at (eval at #{__FILE__}:#{__LINE__}):1)"
+ eval("eval '__FILE__', binding", binding).should == "(eval at (eval at #{__FILE__}:#{__LINE__}):1)"
+ eval("eval '__FILE__', binding", binding, 'success').should == "(eval at success:1)"
+ eval("eval '__FILE__', binding, 'success'", binding).should == 'success'
end
+ it 'uses (eval at __FILE__:__LINE__) for __FILE__ and 1 for __LINE__ with a binding argument' do
+ eval("[__FILE__, __LINE__]", binding).should == ["(eval at #{__FILE__}:#{__LINE__})", 1]
+ end
# Found via Rubinius bug github:#149
it "does not alter the value of __FILE__ in the binding" do
first_time = EvalSpecs.call_eval
@@ -190,18 +263,32 @@ describe "Kernel#eval" do
# See http://jira.codehaus.org/browse/JRUBY-5163
it "uses the receiver as self inside the eval" do
- eval("self").should equal(self)
- Kernel.eval("self").should equal(Kernel)
+ eval("self").should.equal?(self)
+ Kernel.eval("self").should.equal?(Kernel)
end
it "does not pass the block to the method being eval'ed" do
- lambda {
+ -> {
eval('KernelSpecs::EvalTest.call_yield') { "content" }
- }.should raise_error(LocalJumpError)
+ }.should.raise(LocalJumpError)
end
it "returns from the scope calling #eval when evaluating 'return'" do
- lambda { eval("return :eval") }.call.should == :eval
+ -> { eval("return :eval") }.call.should == :eval
+ end
+
+ it "returns from the method calling #eval when evaluating 'return'" do
+ def eval_return(n)
+ eval("return n*2")
+ end
+ -> { eval_return(3) }.call.should == 6
+ end
+
+ it "returns from the method calling #eval when evaluating 'return' in BEGIN" do
+ def eval_return(n)
+ eval("BEGIN {return n*3}")
+ end
+ -> { eval_return(4) }.call.should == 12
end
it "unwinds through a Proc-style closure and returns from a lambda-style closure in the closure chain" do
@@ -213,4 +300,253 @@ describe "Kernel#eval" do
code = fixture __FILE__, "eval_return_without_lambda.rb"
ruby_exe(code).chomp.should == "a,b,c,e,LocalJumpError,f"
end
+
+ it "can be called with Method#call" do
+ method(:eval).call("2 * 3").should == 6
+ end
+
+ it "has the correct default definee when called through Method#call" do
+ class EvalSpecs
+ method(:eval).call("def eval_spec_method_call; end")
+ EvalSpecs.should.method_defined?(:eval_spec_method_call, false)
+ end
+ end
+
+ it "makes flip-flop operator work correctly" do
+ ScratchPad.record []
+
+ eval "10.times { |i| ScratchPad << i if (i == 4)...(i == 4) }"
+ ScratchPad.recorded.should == [4, 5, 6, 7, 8, 9]
+
+ ScratchPad.clear
+ end
+
+ it "returns nil if given an empty string" do
+ eval("").should == nil
+ end
+
+ context "with shebang" do
+ it "ignores shebang with ruby interpreter" do
+ pid = eval(<<~CODE.b)
+ #!/usr/bin/env ruby
+ Process.pid
+ CODE
+
+ pid.should == Process.pid
+ end
+
+ it "ignores shebang with non-ruby interpreter" do
+ pid = eval(<<~CODE.b)
+ #!/usr/bin/env puma
+ Process.pid
+ CODE
+
+ pid.should == Process.pid
+ end
+ end
+
+ # See language/magic_comment_spec.rb for more magic comments specs
+ describe "with a magic encoding comment" do
+ it "uses the magic comment encoding for the encoding of literal strings" do
+ code = "# encoding: UTF-8\n'é'.encoding".b
+ code.encoding.should == Encoding::BINARY
+ eval(code).should == Encoding::UTF_8
+ end
+
+ it "uses the magic comment encoding for parsing constants" do
+ code = <<CODE.b
+# encoding: UTF-8
+class EvalSpecs
+ VÏ€ = 3.14
+end
+CODE
+ code.encoding.should == Encoding::BINARY
+ eval(code)
+ EvalSpecs.constants(false).should.include?(:"VÏ€")
+ EvalSpecs::VÏ€.should == 3.14
+ ensure
+ EvalSpecs.send(:remove_const, :VÏ€)
+ end
+
+ it "allows an emacs-style magic comment encoding" do
+ code = <<CODE.b
+# -*- encoding: UTF-8 -*-
+class EvalSpecs
+VÏ€emacs = 3.14
+end
+CODE
+ code.encoding.should == Encoding::BINARY
+ eval(code)
+ EvalSpecs.constants(false).should.include?(:"VÏ€emacs")
+ EvalSpecs::VÏ€emacs.should == 3.14
+ ensure
+ EvalSpecs.send(:remove_const, :VÏ€emacs)
+ end
+
+ it "allows spaces before the magic encoding comment" do
+ code = <<CODE.b
+\t \t # encoding: UTF-8
+class EvalSpecs
+ VÏ€spaces = 3.14
+end
+CODE
+ code.encoding.should == Encoding::BINARY
+ eval(code)
+ EvalSpecs.constants(false).should.include?(:"VÏ€spaces")
+ EvalSpecs::VÏ€spaces.should == 3.14
+ ensure
+ EvalSpecs.send(:remove_const, :VÏ€spaces)
+ end
+
+ it "allows a shebang line before the magic encoding comment" do
+ code = <<CODE.b
+#!/usr/bin/env ruby
+# encoding: UTF-8
+class EvalSpecs
+ VÏ€shebang = 3.14
+end
+CODE
+ code.encoding.should == Encoding::BINARY
+ eval(code)
+ EvalSpecs.constants(false).should.include?(:"VÏ€shebang")
+ EvalSpecs::VÏ€shebang.should == 3.14
+ ensure
+ EvalSpecs.send(:remove_const, :VÏ€shebang)
+ end
+
+ it "allows a shebang line and some spaces before the magic encoding comment" do
+ code = <<CODE.b
+#!/usr/bin/env ruby
+ # encoding: UTF-8
+class EvalSpecs
+ VÏ€shebang_spaces = 3.14
+end
+CODE
+ code.encoding.should == Encoding::BINARY
+ eval(code)
+ EvalSpecs.constants(false).should.include?(:"VÏ€shebang_spaces")
+ EvalSpecs::VÏ€shebang_spaces.should == 3.14
+ ensure
+ EvalSpecs.send(:remove_const, :VÏ€shebang_spaces)
+ end
+
+ it "allows a magic encoding comment and a subsequent frozen_string_literal magic comment" do
+ frozen_string_default = "test".frozen?
+
+ code = <<CODE.b
+# encoding: UTF-8
+# frozen_string_literal: #{!frozen_string_default}
+class EvalSpecs
+ VÏ€string = "frozen"
+end
+CODE
+ code.encoding.should == Encoding::BINARY
+ eval(code)
+ EvalSpecs.constants(false).should.include?(:"VÏ€string")
+ EvalSpecs::VÏ€string.should == "frozen"
+ EvalSpecs::VÏ€string.encoding.should == Encoding::UTF_8
+ EvalSpecs::VÏ€string.frozen?.should == !frozen_string_default
+ ensure
+ EvalSpecs.send(:remove_const, :VÏ€string)
+ end
+
+ it "allows a magic encoding comment and a frozen_string_literal magic comment on the same line in emacs style" do
+ code = <<CODE.b
+# -*- encoding: UTF-8; frozen_string_literal: true -*-
+class EvalSpecs
+VÏ€same_line = "frozen"
+end
+CODE
+ code.encoding.should == Encoding::BINARY
+ eval(code)
+ EvalSpecs.constants(false).should.include?(:"VÏ€same_line")
+ EvalSpecs::VÏ€same_line.should == "frozen"
+ EvalSpecs::VÏ€same_line.encoding.should == Encoding::UTF_8
+ EvalSpecs::VÏ€same_line.frozen?.should == true
+ ensure
+ EvalSpecs.send(:remove_const, :VÏ€same_line)
+ end
+
+ it "ignores the magic encoding comment if it is after a frozen_string_literal magic comment" do
+ frozen_string_default = "test".frozen?
+ code = <<CODE.b
+# frozen_string_literal: #{!frozen_string_default}
+# encoding: UTF-8
+class EvalSpecs
+ VÏ€frozen_first = "frozen"
+end
+CODE
+ code.encoding.should == Encoding::BINARY
+ eval(code)
+ EvalSpecs.constants(false).should_not.include?(:"VÏ€frozen_first")
+ binary_constant = "VÏ€frozen_first".b.to_sym
+ EvalSpecs.constants(false).should.include?(binary_constant)
+ value = EvalSpecs.const_get(binary_constant)
+ value.should == "frozen"
+ value.encoding.should == Encoding::BINARY
+ value.frozen?.should == !frozen_string_default
+ ensure
+ EvalSpecs.send(:remove_const, binary_constant)
+ end
+
+ it "ignores the frozen_string_literal magic comment if it appears after a token and warns if $VERBOSE is true" do
+ frozen_string_default = "test".frozen?
+ code = <<CODE
+some_token_before_magic_comment = :anything
+# frozen_string_literal: #{!frozen_string_default}
+class EvalSpecs
+ VÏ€string_not_frozen = "not frozen"
+end
+CODE
+ -> { eval(code) }.should complain(/warning: [`']frozen_string_literal' is ignored after any tokens/, verbose: true)
+ EvalSpecs::VÏ€string_not_frozen.frozen?.should == frozen_string_default
+ EvalSpecs.send :remove_const, :VÏ€string_not_frozen
+
+ -> { eval(code) }.should_not complain(verbose: false)
+ EvalSpecs::VÏ€string_not_frozen.frozen?.should == frozen_string_default
+ EvalSpecs.send :remove_const, :VÏ€string_not_frozen
+ end
+ end
+
+ describe 'with refinements' do
+ it "activates refinements from the eval scope" do
+ refinery = Module.new do
+ refine EvalSpecs::A do
+ def foo
+ "bar"
+ end
+ end
+ end
+
+ result = nil
+
+ Module.new do
+ using refinery
+
+ result = eval "EvalSpecs::A.new.foo"
+ end
+
+ result.should == "bar"
+ end
+
+ it "activates refinements from the binding" do
+ refinery = Module.new do
+ refine EvalSpecs::A do
+ def foo
+ "bar"
+ end
+ end
+ end
+
+ b = nil
+ m = Module.new do
+ using refinery
+ b = binding
+ end
+
+ result = eval "EvalSpecs::A.new.foo", b
+
+ result.should == "bar"
+ end
+ end
end
diff --git a/spec/ruby/core/kernel/exec_spec.rb b/spec/ruby/core/kernel/exec_spec.rb
index 3a7b656914..fd8485791a 100644
--- a/spec/ruby/core/kernel/exec_spec.rb
+++ b/spec/ruby/core/kernel/exec_spec.rb
@@ -1,18 +1,18 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Kernel#exec" do
it "is a private method" do
- Kernel.should have_private_instance_method(:exec)
+ Kernel.private_instance_methods(false).should.include?(:exec)
end
it "runs the specified command, replacing current process" do
- ruby_exe('exec "echo hello"; puts "fail"', escape: true).should == "hello\n"
+ ruby_exe('exec "echo hello"; puts "fail"').should == "hello\n"
end
end
describe "Kernel.exec" do
it "runs the specified command, replacing current process" do
- ruby_exe('Kernel.exec "echo hello"; puts "fail"', escape: true).should == "hello\n"
+ ruby_exe('Kernel.exec "echo hello"; puts "fail"').should == "hello\n"
end
end
diff --git a/spec/ruby/core/kernel/exit_spec.rb b/spec/ruby/core/kernel/exit_spec.rb
index 61a6670cfd..864ff84449 100644
--- a/spec/ruby/core/kernel/exit_spec.rb
+++ b/spec/ruby/core/kernel/exit_spec.rb
@@ -1,27 +1,27 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../../../shared/process/exit', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative '../../shared/process/exit'
describe "Kernel#exit" do
it "is a private method" do
- Kernel.should have_private_instance_method(:exit)
+ Kernel.private_instance_methods(false).should.include?(:exit)
end
it_behaves_like :process_exit, :exit, KernelSpecs::Method.new
end
+describe "Kernel.exit" do
+ it_behaves_like :process_exit, :exit, Kernel
+end
+
describe "Kernel#exit!" do
it "is a private method" do
- Kernel.should have_private_instance_method(:exit!)
+ Kernel.private_instance_methods(false).should.include?(:exit!)
end
it_behaves_like :process_exit!, :exit!, "self"
end
-describe "Kernel.exit" do
- it_behaves_like :process_exit, :exit, Kernel
-end
-
describe "Kernel.exit!" do
- it_behaves_like :process_exit!, :exit!, Kernel
+ it_behaves_like :process_exit!, :exit!, "Kernel"
end
diff --git a/spec/ruby/core/kernel/extend_spec.rb b/spec/ruby/core/kernel/extend_spec.rb
index 482eef32e9..a344c7b5ca 100644
--- a/spec/ruby/core/kernel/extend_spec.rb
+++ b/spec/ruby/core/kernel/extend_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
module KernelSpecs::M
def self.extend_object(o)
@@ -46,20 +46,20 @@ describe "Kernel#extend" do
end
it "makes the class a kind_of? the argument" do
- class C
+ c = Class.new do
extend KernelSpecs::M
end
- (C.kind_of? KernelSpecs::M).should == true
+ (c.kind_of? KernelSpecs::M).should == true
end
it "raises an ArgumentError when no arguments given" do
- lambda { Object.new.extend }.should raise_error(ArgumentError)
+ -> { Object.new.extend }.should.raise(ArgumentError)
end
it "raises a TypeError when the argument is not a Module" do
o = mock('o')
klass = Class.new
- lambda { o.extend(klass) }.should raise_error(TypeError)
+ -> { o.extend(klass) }.should.raise(TypeError)
end
describe "on frozen instance" do
@@ -69,11 +69,23 @@ describe "Kernel#extend" do
end
it "raises an ArgumentError when no arguments given" do
- lambda { @frozen.extend }.should raise_error(ArgumentError)
+ -> { @frozen.extend }.should.raise(ArgumentError)
end
- it "raises a RuntimeError" do
- lambda { @frozen.extend @module }.should raise_error(RuntimeError)
+ it "raises a FrozenError" do
+ -> { @frozen.extend @module }.should.raise(FrozenError)
end
end
+
+ it "updated class methods of a module when it extends self and includes another module" do
+ a = Module.new do
+ extend self
+ end
+ b = Module.new do
+ def foo; :foo; end
+ end
+
+ a.include b
+ a.foo.should == :foo
+ end
end
diff --git a/spec/ruby/core/kernel/fail_spec.rb b/spec/ruby/core/kernel/fail_spec.rb
index 9f3601c233..2d117d26cd 100644
--- a/spec/ruby/core/kernel/fail_spec.rb
+++ b/spec/ruby/core/kernel/fail_spec.rb
@@ -1,43 +1,13 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
-describe "Kernel.fail" do
- it "is a private method" do
- Kernel.should have_private_instance_method(:fail)
- end
-
- it "raises a RuntimeError" do
- lambda { fail }.should raise_error(RuntimeError)
- end
-
- it "accepts an Object with an exception method returning an Exception" do
- class Boring
- def self.exception(msg)
- StandardError.new msg
- end
- end
- lambda { fail Boring, "..." }.should raise_error(StandardError)
- end
-
- it "instantiates the specified exception class" do
- class LittleBunnyFooFoo < RuntimeError; end
- lambda { fail LittleBunnyFooFoo }.should raise_error(LittleBunnyFooFoo)
- end
-
- it "uses the specified message" do
- lambda {
- begin
- fail "the duck is not irish."
- rescue => e
- e.message.should == "the duck is not irish."
- raise
- else
- raise Exception
- end
- }.should raise_error(RuntimeError)
+describe "Kernel#fail" do
+ it "is an alias of Kernel#raise" do
+ Kernel.instance_method(:fail).should == Kernel.instance_method(:raise)
end
end
-describe "Kernel#fail" do
- it "needs to be reviewed for spec completeness"
+describe "Kernel.fail" do
+ it "is an alias of Kernel.raise" do
+ Kernel.method(:fail).should == Kernel.method(:raise)
+ end
end
diff --git a/spec/ruby/core/kernel/fixtures/Complex.rb b/spec/ruby/core/kernel/fixtures/Complex.rb
new file mode 100644
index 0000000000..bf14d55ad5
--- /dev/null
+++ b/spec/ruby/core/kernel/fixtures/Complex.rb
@@ -0,0 +1,5 @@
+module KernelSpecs
+ def self.Complex_method(string)
+ Complex(string)
+ end
+end
diff --git a/spec/ruby/core/kernel/fixtures/__dir__.rb b/spec/ruby/core/kernel/fixtures/__dir__.rb
new file mode 100644
index 0000000000..bf9a15e3c8
--- /dev/null
+++ b/spec/ruby/core/kernel/fixtures/__dir__.rb
@@ -0,0 +1,2 @@
+puts __FILE__
+puts __dir__
diff --git a/spec/ruby/core/kernel/fixtures/autoload_c.rb b/spec/ruby/core/kernel/fixtures/autoload_c.rb
deleted file mode 100644
index 4569b23669..0000000000
--- a/spec/ruby/core/kernel/fixtures/autoload_c.rb
+++ /dev/null
@@ -1,5 +0,0 @@
-module KSAutoloadC
- def self.loaded
- :ksautoload_c
- end
-end
diff --git a/spec/ruby/core/kernel/fixtures/autoload_from_included_module.rb b/spec/ruby/core/kernel/fixtures/autoload_from_included_module.rb
new file mode 100644
index 0000000000..f5bedc6992
--- /dev/null
+++ b/spec/ruby/core/kernel/fixtures/autoload_from_included_module.rb
@@ -0,0 +1,9 @@
+module KernelSpecs
+ module AutoloadMethod
+ module AutoloadFromIncludedModule
+ def self.loaded
+ :autoload_from_included_module
+ end
+ end
+ end
+end
diff --git a/spec/ruby/core/kernel/fixtures/autoload_from_included_module2.rb b/spec/ruby/core/kernel/fixtures/autoload_from_included_module2.rb
new file mode 100644
index 0000000000..f4f1cfbf7c
--- /dev/null
+++ b/spec/ruby/core/kernel/fixtures/autoload_from_included_module2.rb
@@ -0,0 +1,9 @@
+module KernelSpecs
+ module AutoloadMethod2
+ module AutoloadFromIncludedModule2
+ def self.loaded
+ :autoload_from_included_module2
+ end
+ end
+ end
+end
diff --git a/spec/ruby/core/kernel/fixtures/autoload_relative_b.rb b/spec/ruby/core/kernel/fixtures/autoload_relative_b.rb
new file mode 100644
index 0000000000..6de6f5091d
--- /dev/null
+++ b/spec/ruby/core/kernel/fixtures/autoload_relative_b.rb
@@ -0,0 +1,7 @@
+module KernelSpecs
+ module KSAutoloadRelativeB
+ def self.loaded
+ :ksautoload_b
+ end
+ end
+end
diff --git a/spec/ruby/core/kernel/fixtures/autoload_relative_d.rb b/spec/ruby/core/kernel/fixtures/autoload_relative_d.rb
new file mode 100644
index 0000000000..5b6b5e1fa2
--- /dev/null
+++ b/spec/ruby/core/kernel/fixtures/autoload_relative_d.rb
@@ -0,0 +1,5 @@
+module KSAutoloadRelativeD
+ def self.loaded
+ :ksautoload_d
+ end
+end
diff --git a/spec/ruby/core/kernel/fixtures/caller_at_exit.rb b/spec/ruby/core/kernel/fixtures/caller_at_exit.rb
new file mode 100644
index 0000000000..ca9d808597
--- /dev/null
+++ b/spec/ruby/core/kernel/fixtures/caller_at_exit.rb
@@ -0,0 +1,7 @@
+at_exit {
+ foo
+}
+
+def foo
+ puts caller(0)
+end
diff --git a/spec/ruby/core/kernel/fixtures/classes.rb b/spec/ruby/core/kernel/fixtures/classes.rb
index afa2bec12f..ad82f3cef5 100644
--- a/spec/ruby/core/kernel/fixtures/classes.rb
+++ b/spec/ruby/core/kernel/fixtures/classes.rb
@@ -49,7 +49,7 @@ module KernelSpecs
def self.chomp(str, method, sep="\n")
code = "$_ = #{str.inspect}; $/ = #{sep.inspect}; #{method}; print $_"
- IO.popen([*ruby_exe, "-n", "-e", code], "r+") do |io|
+ IO.popen([*ruby_exe, "-W0", "-n", "-e", code], "r+") do |io|
io.puts
io.close_write
io.read
@@ -68,6 +68,7 @@ module KernelSpecs
module SomeOtherModule; end
module AncestorModule; end
module MyModule; end
+ module MyPrependedModule; end
module MyExtensionModule; end
class AncestorClass < String
@@ -80,6 +81,8 @@ module KernelSpecs
class KindaClass < AncestorClass
include MyModule
+ prepend MyPrependedModule
+
def initialize
self.extend MyExtensionModule
end
@@ -177,6 +180,25 @@ module KernelSpecs
alias aliased_pub_method pub_method
end
+ class BasicA < BasicObject
+ define_method(:respond_to?, ::Kernel.instance_method(:respond_to?))
+
+ def pub_method; :public_method; end
+
+ def undefed_method; :undefed_method; end
+ undef_method :undefed_method
+
+ protected
+ def protected_method; :protected_method; end
+
+ private
+ def private_method; :private_method; end
+ end
+
+ class MissingA < A
+ undef :respond_to_missing?
+ end
+
class VisibilityChange
class << self
private :new
@@ -216,10 +238,28 @@ module KernelSpecs
block_given?
end
+ def self.accept_block_inside_block()
+ yield_self {
+ block_given?
+ }
+ end
+
+ def self.accept_block_as_argument_inside_block(&block)
+ yield_self {
+ block_given?
+ }
+ end
+
class << self
define_method(:defined_block) do
block_given?
end
+
+ define_method(:defined_block_inside_block) do
+ yield_self {
+ block_given?
+ }
+ end
end
end
@@ -232,10 +272,28 @@ module KernelSpecs
self.send(:block_given?)
end
+ def self.accept_block_inside_block
+ yield_self {
+ self.send(:block_given?)
+ }
+ end
+
+ def self.accept_block_as_argument_inside_block(&block)
+ yield_self {
+ self.send(:block_given?)
+ }
+ end
+
class << self
define_method(:defined_block) do
self.send(:block_given?)
end
+
+ define_method(:defined_block_inside_block) do
+ yield_self {
+ self.send(:block_given?)
+ }
+ end
end
end
@@ -248,10 +306,28 @@ module KernelSpecs
Kernel.block_given?
end
+ def self.accept_block_inside_block
+ yield_self {
+ Kernel.block_given?
+ }
+ end
+
+ def self.accept_block_as_argument_inside_block(&block)
+ yield_self {
+ Kernel.block_given?
+ }
+ end
+
class << self
define_method(:defined_block) do
Kernel.block_given?
end
+
+ define_method(:defined_block_inside_block) do
+ yield_self {
+ Kernel.block_given?
+ }
+ end
end
end
@@ -278,14 +354,25 @@ module KernelSpecs
@two = two
end
- def initialize_copy(other)
+ def initialize_copy(other, **kw)
ScratchPad.record object_id
end
+
+ # define to support calling #clone with optional :freeze keyword argument
+ def initialize_clone(other, **kw)
+ super(other) # to call #initialize_copy
+ end
end
class Clone
def initialize_clone(other)
- ScratchPad.record other.object_id
+ ScratchPad.record other
+ end
+ end
+
+ class CloneFreeze
+ def initialize_clone(other, **kwargs)
+ ScratchPad.record([other, kwargs])
end
end
@@ -325,7 +412,7 @@ module KernelSpecs
def inner
b = mp { return :good }
- pr = lambda { |x| x.call }
+ pr = -> x { x.call }
pr.call(b)
@@ -334,21 +421,44 @@ module KernelSpecs
end
end
+ module LambdaSpecs
+ module ZSuper
+ def lambda
+ super
+ end
+ end
+
+ class ForwardBlockWithZSuper
+ prepend(ZSuper)
+ end
+
+ module Ampersand
+ def lambda(&block)
+ suppress_warning {super(&block)}
+ end
+ end
+
+ class SuperAmpersand
+ prepend(Ampersand)
+ end
+ end
+
class RespondViaMissing
def respond_to_missing?(method, priv=false)
case method
- when :handled_publicly
- true
- when :handled_privately
- priv
- when :not_handled
- false
- else
- raise "Typo in method name"
+ when :handled_publicly
+ true
+ when :handled_privately
+ priv
+ when :not_handled
+ false
+ else
+ raise "Typo in method name: #{method.inspect}"
end
end
def method_missing(method, *args)
+ raise "the method name should be a Symbol" unless Symbol === method
"Done #{method}(#{args})"
end
end
@@ -378,6 +488,63 @@ module KernelSpecs
[3, 4]
end
end
+
+ module AutoloadMethod
+ def setup_autoload(file)
+ autoload :AutoloadFromIncludedModule, file
+ end
+ end
+
+ class AutoloadMethodIncluder
+ include AutoloadMethod
+ end
+
+ module AutoloadMethod2
+ def setup_autoload(file)
+ Kernel.autoload :AutoloadFromIncludedModule2, file
+ end
+ end
+
+ class AutoloadMethodIncluder2
+ include AutoloadMethod2
+ end
+
+ class WarnInNestedCall
+ def f4(s = "", n)
+ f3(s, n)
+ end
+
+ def f3(s, n)
+ f2(s, n)
+ end
+
+ def f2(s, n)
+ f1(s, n)
+ end
+
+ def f1(s, n)
+ warn(s, uplevel: n)
+ end
+
+ def warn_call_lineno; method(:f1).source_location[1] + 1; end
+ def f1_call_lineno; method(:f2).source_location[1] + 1; end
+ def f2_call_lineno; method(:f3).source_location[1] + 1; end
+ def f3_call_lineno; method(:f4).source_location[1] + 1; end
+ end
+
+ CustomRangeInteger = Struct.new(:value) do
+ def to_int; value; end
+ def <=>(other); to_int <=> other.to_int; end
+ def -(other); self.class.new(to_int - other.to_int); end
+ def +(other); self.class.new(to_int + other.to_int); end
+ end
+
+ CustomRangeFloat = Struct.new(:value) do
+ def to_f; value; end
+ def <=>(other); to_f <=> other.to_f; end
+ def -(other); to_f - other.to_f; end
+ def +(other); self.class.new(to_f + other.to_f); end
+ end
end
class EvalSpecs
@@ -408,12 +575,3 @@ class EvalSpecs
return f
end
end
-
-# for Kernel#sleep to have Channel in it's specs
-# TODO: switch directly to queue for both Kernel#sleep and Thread specs?
-unless defined? Channel
- require 'thread'
- class Channel < Queue
- alias receive shift
- end
-end
diff --git a/spec/ruby/core/kernel/fixtures/eval_return_with_lambda.rb b/spec/ruby/core/kernel/fixtures/eval_return_with_lambda.rb
index a48b5685f3..9e2d045bf3 100644
--- a/spec/ruby/core/kernel/fixtures/eval_return_with_lambda.rb
+++ b/spec/ruby/core/kernel/fixtures/eval_return_with_lambda.rb
@@ -1,5 +1,5 @@
print "a,"
-x = lambda do
+x = -> do
print "b,"
Proc.new do
print "c,"
diff --git a/spec/ruby/core/kernel/fixtures/singleton_methods.rb b/spec/ruby/core/kernel/fixtures/singleton_methods.rb
new file mode 100644
index 0000000000..32ea0adf89
--- /dev/null
+++ b/spec/ruby/core/kernel/fixtures/singleton_methods.rb
@@ -0,0 +1,13 @@
+module SingletonMethodsSpecs
+ module Prepended
+ def mspec_test_kernel_singleton_methods
+ end
+ public :mspec_test_kernel_singleton_methods
+ end
+
+ ::Module.prepend Prepended
+
+ module SelfExtending
+ extend self
+ end
+end
diff --git a/spec/ruby/core/kernel/fixtures/warn_core_method.rb b/spec/ruby/core/kernel/fixtures/warn_core_method.rb
new file mode 100644
index 0000000000..fd82562404
--- /dev/null
+++ b/spec/ruby/core/kernel/fixtures/warn_core_method.rb
@@ -0,0 +1,14 @@
+raise 'should be run without RubyGems' if defined?(Gem)
+
+public def deprecated(n=1)
+ # puts nil, caller(0), nil
+ warn "use X instead", uplevel: n
+end
+
+1.times do # to test with a non-empty stack above the reported locations
+ deprecated
+ tap(&:deprecated)
+ tap { deprecated(2) }
+ # eval sources with a <internal: file are also ignored
+ eval "tap(&:deprecated)", nil, "<internal:should-be-skipped-by-warn-uplevel>"
+end
diff --git a/spec/ruby/core/kernel/fixtures/warn_require.rb b/spec/ruby/core/kernel/fixtures/warn_require.rb
new file mode 100644
index 0000000000..c4b0733233
--- /dev/null
+++ b/spec/ruby/core/kernel/fixtures/warn_require.rb
@@ -0,0 +1 @@
+warn 'warn-require-warning', uplevel: 1
diff --git a/spec/ruby/core/kernel/fixtures/warn_require_caller.rb b/spec/ruby/core/kernel/fixtures/warn_require_caller.rb
new file mode 100644
index 0000000000..35a0f969f9
--- /dev/null
+++ b/spec/ruby/core/kernel/fixtures/warn_require_caller.rb
@@ -0,0 +1,2 @@
+# Use a different line than just 1
+require "#{__dir__}/warn_require"
diff --git a/spec/ruby/core/kernel/fork_spec.rb b/spec/ruby/core/kernel/fork_spec.rb
index 8919d0914d..4a2c848202 100644
--- a/spec/ruby/core/kernel/fork_spec.rb
+++ b/spec/ruby/core/kernel/fork_spec.rb
@@ -1,10 +1,10 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../../../shared/process/fork', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative '../../shared/process/fork'
describe "Kernel#fork" do
it "is a private method" do
- Kernel.should have_private_instance_method(:fork)
+ Kernel.private_instance_methods(false).should.include?(:fork)
end
it_behaves_like :process_fork, :fork, KernelSpecs::Method.new
diff --git a/spec/ruby/core/kernel/format_spec.rb b/spec/ruby/core/kernel/format_spec.rb
index c73d5f0efb..a311f3c3d7 100644
--- a/spec/ruby/core/kernel/format_spec.rb
+++ b/spec/ruby/core/kernel/format_spec.rb
@@ -1,14 +1,13 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
describe "Kernel#format" do
- it "is a private method" do
- Kernel.should have_private_instance_method(:format)
+ it "is an alias of Kernel#sprintf" do
+ Kernel.instance_method(:format).should == Kernel.instance_method(:sprintf)
end
end
describe "Kernel.format" do
- it "is accessible as a module function" do
- Kernel.format("%s", "hello").should == "hello"
+ it "is an alias of Kernel.sprintf" do
+ Kernel.method(:format).should == Kernel.method(:sprintf)
end
end
diff --git a/spec/ruby/core/kernel/freeze_spec.rb b/spec/ruby/core/kernel/freeze_spec.rb
index cf16512094..079617dce4 100644
--- a/spec/ruby/core/kernel/freeze_spec.rb
+++ b/spec/ruby/core/kernel/freeze_spec.rb
@@ -1,49 +1,49 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Kernel#freeze" do
it "prevents self from being further modified" do
o = mock('o')
- o.frozen?.should be_false
+ o.frozen?.should == false
o.freeze
- o.frozen?.should be_true
+ o.frozen?.should == true
end
it "returns self" do
o = Object.new
- o.freeze.should equal(o)
+ o.freeze.should.equal?(o)
end
describe "on integers" do
it "has no effect since they are already frozen" do
- 1.frozen?.should be_true
+ 1.frozen?.should == true
1.freeze
bignum = bignum_value
- bignum.frozen?.should be_true
+ bignum.frozen?.should == true
bignum.freeze
end
end
describe "on a Float" do
it "has no effect since it is already frozen" do
- 1.2.frozen?.should be_true
+ 1.2.frozen?.should == true
1.2.freeze
end
end
describe "on a Symbol" do
it "has no effect since it is already frozen" do
- :sym.frozen?.should be_true
+ :sym.frozen?.should == true
:sym.freeze
end
end
describe "on true, false and nil" do
it "has no effect since they are already frozen" do
- nil.frozen?.should be_true
- true.frozen?.should be_true
- false.frozen?.should be_true
+ nil.frozen?.should == true
+ true.frozen?.should == true
+ false.frozen?.should == true
nil.freeze
true.freeze
@@ -51,21 +51,19 @@ describe "Kernel#freeze" do
end
end
- ruby_version_is "2.5" do
- describe "on a Complex" do
- it "has no effect since it is already frozen" do
- c = Complex(1.3, 3.1)
- c.frozen?.should be_true
- c.freeze
- end
+ describe "on a Complex" do
+ it "has no effect since it is already frozen" do
+ c = Complex(1.3, 3.1)
+ c.frozen?.should == true
+ c.freeze
end
+ end
- describe "on a Rational" do
- it "has no effect since it is already frozen" do
- r = Rational(1, 3)
- r.frozen?.should be_true
- r.freeze
- end
+ describe "on a Rational" do
+ it "has no effect since it is already frozen" do
+ r = Rational(1, 3)
+ r.frozen?.should == true
+ r.freeze
end
end
@@ -74,12 +72,20 @@ describe "Kernel#freeze" do
def mutate; @foo = 1; end
end.new
o.freeze
- lambda {o.mutate}.should raise_error(RuntimeError)
+ -> {o.mutate}.should.raise(RuntimeError)
end
it "causes instance_variable_set to raise RuntimeError" do
o = Object.new
o.freeze
- lambda {o.instance_variable_set(:@foo, 1)}.should raise_error(RuntimeError)
+ -> {o.instance_variable_set(:@foo, 1)}.should.raise(RuntimeError)
+ end
+
+ it "freezes an object's singleton class" do
+ o = Object.new
+ c = o.singleton_class
+ c.frozen?.should == false
+ o.freeze
+ c.frozen?.should == true
end
end
diff --git a/spec/ruby/core/kernel/frozen_spec.rb b/spec/ruby/core/kernel/frozen_spec.rb
index fad1971985..8b8fad3de7 100644
--- a/spec/ruby/core/kernel/frozen_spec.rb
+++ b/spec/ruby/core/kernel/frozen_spec.rb
@@ -1,20 +1,20 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Kernel#frozen?" do
it "returns true if self is frozen" do
o = mock('o')
p = mock('p')
p.freeze
- o.frozen?.should == false
- p.frozen?.should == true
+ o.should_not.frozen?
+ p.should.frozen?
end
describe "on true, false and nil" do
it "returns true" do
- true.frozen?.should be_true
- false.frozen?.should be_true
- nil.frozen?.should be_true
+ true.frozen?.should == true
+ false.frozen?.should == true
+ nil.frozen?.should == true
end
end
@@ -25,8 +25,8 @@ describe "Kernel#frozen?" do
end
it "returns true" do
- @fixnum.frozen?.should be_true
- @bignum.frozen?.should be_true
+ @fixnum.frozen?.should == true
+ @bignum.frozen?.should == true
end
end
@@ -36,7 +36,7 @@ describe "Kernel#frozen?" do
end
it "returns true" do
- @float.frozen?.should be_true
+ @float.frozen?.should == true
end
end
@@ -46,33 +46,31 @@ describe "Kernel#frozen?" do
end
it "returns true" do
- @symbol.frozen?.should be_true
+ @symbol.frozen?.should == true
end
end
- ruby_version_is "2.5" do
- describe "on a Complex" do
- it "returns true" do
- c = Complex(1.3, 3.1)
- c.frozen?.should be_true
- end
+ describe "on a Complex" do
+ it "returns true" do
+ c = Complex(1.3, 3.1)
+ c.frozen?.should == true
+ end
- it "literal returns true" do
- c = eval "1.3i"
- c.frozen?.should be_true
- end
+ it "literal returns true" do
+ c = eval "1.3i"
+ c.frozen?.should == true
end
+ end
- describe "on a Rational" do
- it "returns true" do
- r = Rational(1, 3)
- r.frozen?.should be_true
- end
+ describe "on a Rational" do
+ it "returns true" do
+ r = Rational(1, 3)
+ r.frozen?.should == true
+ end
- it "literal returns true" do
- r = eval "1/3r"
- r.frozen?.should be_true
- end
+ it "literal returns true" do
+ r = eval "1/3r"
+ r.frozen?.should == true
end
end
end
diff --git a/spec/ruby/core/kernel/gets_spec.rb b/spec/ruby/core/kernel/gets_spec.rb
index c775b2b7a4..1b2b36fbb9 100644
--- a/spec/ruby/core/kernel/gets_spec.rb
+++ b/spec/ruby/core/kernel/gets_spec.rb
@@ -1,9 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Kernel#gets" do
it "is a private method" do
- Kernel.should have_private_instance_method(:gets)
+ Kernel.private_instance_methods(false).should.include?(:gets)
end
it "calls ARGF.gets" do
diff --git a/spec/ruby/core/kernel/global_variables_spec.rb b/spec/ruby/core/kernel/global_variables_spec.rb
index 739b800938..d41bdff49a 100644
--- a/spec/ruby/core/kernel/global_variables_spec.rb
+++ b/spec/ruby/core/kernel/global_variables_spec.rb
@@ -1,9 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Kernel.global_variables" do
it "is a private method" do
- Kernel.should have_private_instance_method(:global_variables)
+ Kernel.private_instance_methods(false).should.include?(:global_variables)
end
before :all do
@@ -11,13 +11,13 @@ describe "Kernel.global_variables" do
end
it "finds subset starting with std" do
- global_variables.grep(/std/).should include(:$stderr, :$stdin, :$stdout)
+ global_variables.grep(/std/).to_set.should >= Set[:$stderr, :$stdin, :$stdout]
a = global_variables.size
gvar_name = "$foolish_global_var#{@i += 1}"
global_variables.include?(gvar_name.to_sym).should == false
eval("#{gvar_name} = 1")
global_variables.size.should == a+1
- global_variables.should include(gvar_name.to_sym)
+ global_variables.should.include?(gvar_name.to_sym)
end
end
diff --git a/spec/ruby/core/kernel/gsub_spec.rb b/spec/ruby/core/kernel/gsub_spec.rb
index 005ed0063d..e05349e2b5 100644
--- a/spec/ruby/core/kernel/gsub_spec.rb
+++ b/spec/ruby/core/kernel/gsub_spec.rb
@@ -1,25 +1,25 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
# FIXME: These methods exist only when the -n or -p option is passed to
# ruby, but we currently don't have a way of specifying that.
ruby_version_is ""..."1.9" do
describe "Kernel#gsub" do
it "is a private method" do
- Kernel.should have_private_instance_method(:gsub)
+ Kernel.private_instance_methods(false).should.include?(:gsub)
end
it "raises a TypeError if $_ is not a String" do
- lambda {
+ -> {
$_ = 123
gsub(/./, "!")
- }.should raise_error(TypeError)
+ }.should.raise(TypeError)
end
it "when matches sets $_ to a new string, leaving the former value unaltered" do
orig_value = $_ = "hello"
gsub("ello", "ola")
- $_.should_not equal(orig_value)
+ $_.should_not.equal?(orig_value)
$_.should == "hola"
orig_value.should == "hello"
end
@@ -86,7 +86,7 @@ ruby_version_is ""..."1.9" do
describe "Kernel#gsub!" do
it "is a private method" do
- Kernel.should have_private_instance_method(:gsub!)
+ Kernel.private_instance_methods(false).should.include?(:gsub!)
end
end
diff --git a/spec/ruby/core/kernel/initialize_clone_spec.rb b/spec/ruby/core/kernel/initialize_clone_spec.rb
new file mode 100644
index 0000000000..0033eadffb
--- /dev/null
+++ b/spec/ruby/core/kernel/initialize_clone_spec.rb
@@ -0,0 +1,26 @@
+require_relative '../../spec_helper'
+
+describe "Kernel#initialize_clone" do
+ it "is a private instance method" do
+ Kernel.private_instance_methods(false).should.include?(:initialize_clone)
+ end
+
+ it "returns the receiver" do
+ a = Object.new
+ b = Object.new
+ a.send(:initialize_clone, b).should == a
+ end
+
+ it "calls #initialize_copy" do
+ a = Object.new
+ b = Object.new
+ a.should_receive(:initialize_copy).with(b)
+ a.send(:initialize_clone, b)
+ end
+
+ it "accepts a :freeze keyword argument for obj.clone(freeze: value)" do
+ a = Object.new
+ b = Object.new
+ a.send(:initialize_clone, b, freeze: true).should == a
+ end
+end
diff --git a/spec/ruby/core/kernel/initialize_copy_spec.rb b/spec/ruby/core/kernel/initialize_copy_spec.rb
new file mode 100644
index 0000000000..ebac0c14de
--- /dev/null
+++ b/spec/ruby/core/kernel/initialize_copy_spec.rb
@@ -0,0 +1,36 @@
+require_relative '../../spec_helper'
+
+describe "Kernel#initialize_copy" do
+ it "returns self" do
+ obj = Object.new
+ obj.send(:initialize_copy, obj).should.equal?(obj)
+ end
+
+ it "does nothing if the argument is the same as the receiver" do
+ obj = Object.new
+ obj.send(:initialize_copy, obj).should.equal?(obj)
+
+ obj = Object.new.freeze
+ obj.send(:initialize_copy, obj).should.equal?(obj)
+
+ 1.send(:initialize_copy, 1).should.equal?(1)
+ end
+
+ it "raises FrozenError if the receiver is frozen" do
+ -> { Object.new.freeze.send(:initialize_copy, Object.new) }.should.raise(FrozenError)
+ -> { 1.send(:initialize_copy, Object.new) }.should.raise(FrozenError)
+ end
+
+ it "raises TypeError if the objects are of different class" do
+ klass = Class.new
+ sub = Class.new(klass)
+ a = klass.new
+ b = sub.new
+ message = 'initialize_copy should take same class object'
+ -> { a.send(:initialize_copy, b) }.should.raise(TypeError, message)
+ -> { b.send(:initialize_copy, a) }.should.raise(TypeError, message)
+
+ -> { a.send(:initialize_copy, 1) }.should.raise(TypeError, message)
+ -> { a.send(:initialize_copy, 1.0) }.should.raise(TypeError, message)
+ end
+end
diff --git a/spec/ruby/core/kernel/initialize_dup_spec.rb b/spec/ruby/core/kernel/initialize_dup_spec.rb
new file mode 100644
index 0000000000..f144647eb8
--- /dev/null
+++ b/spec/ruby/core/kernel/initialize_dup_spec.rb
@@ -0,0 +1,20 @@
+require_relative '../../spec_helper'
+
+describe "Kernel#initialize_dup" do
+ it "is a private instance method" do
+ Kernel.private_instance_methods(false).should.include?(:initialize_dup)
+ end
+
+ it "returns the receiver" do
+ a = Object.new
+ b = Object.new
+ a.send(:initialize_dup, b).should == a
+ end
+
+ it "calls #initialize_copy" do
+ a = Object.new
+ b = Object.new
+ a.should_receive(:initialize_copy).with(b)
+ a.send(:initialize_dup, b)
+ end
+end
diff --git a/spec/ruby/core/kernel/inspect_spec.rb b/spec/ruby/core/kernel/inspect_spec.rb
index 92129ebbc5..8fc3ab51cd 100644
--- a/spec/ruby/core/kernel/inspect_spec.rb
+++ b/spec/ruby/core/kernel/inspect_spec.rb
@@ -1,17 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Kernel#inspect" do
it "returns a String" do
- Object.new.inspect.should be_an_instance_of(String)
- end
-
- it "returns a tainted string if self is tainted" do
- Object.new.taint.inspect.tainted?.should be_true
- end
-
- it "returns an untrusted string if self is untrusted" do
- Object.new.untrust.inspect.untrusted?.should be_true
+ Object.new.inspect.should.instance_of?(String)
end
it "does not call #to_s if it is defined" do
@@ -28,4 +20,84 @@ describe "Kernel#inspect" do
obj = Object.new
obj.inspect.should =~ /^#<Object:0x[0-9a-f]+>$/
end
+
+ it "returns a String for an object without #class method" do
+ obj = Object.new
+ class << obj
+ undef_method :class
+ end
+ obj.inspect.should.is_a?(String)
+ end
+
+ ruby_version_is "4.0" do
+ it "calls #instance_variables_to_inspect private method to know which variables to display" do
+ obj = Object.new
+ obj.instance_eval do
+ @host = "localhost"
+ @user = "root"
+ @password = "hunter2"
+ end
+ obj.singleton_class.class_eval do
+ private def instance_variables_to_inspect = %i[@host @user @does_not_exist]
+ end
+
+ inspected = obj.inspect.sub(/^#<Object:0x[0-9a-f]+/, '#<Object:0x00')
+ inspected.should == '#<Object:0x00 @host="localhost", @user="root">'
+
+ obj = Object.new
+ obj.instance_eval do
+ @host = "localhost"
+ @user = "root"
+ @password = "hunter2"
+ end
+ obj.singleton_class.class_eval do
+ private def instance_variables_to_inspect = []
+ end
+
+ inspected = obj.inspect.sub(/^#<Object:0x[0-9a-f]+/, '#<Object:0x00')
+ inspected.should == "#<Object:0x00>"
+ end
+
+ it "displays all instance variables if #instance_variables_to_inspect returns nil" do
+ obj = Object.new
+ obj.instance_eval do
+ @host = "localhost"
+ @user = "root"
+ @password = "hunter2"
+ end
+ obj.singleton_class.class_eval do
+ private def instance_variables_to_inspect = nil
+ end
+
+ inspected = obj.inspect.sub(/^#<Object:0x[0-9a-f]+/, '#<Object:0x00')
+ inspected.should == %{#<Object:0x00 @host="localhost", @user="root", @password="hunter2">}
+ end
+
+ it "displays all instance variables if #instance_variables_to_inspect is not defined" do
+ obj = BasicObject.new
+ obj.instance_eval do
+ @host = "localhost"
+ @user = "root"
+ @password = "hunter2"
+ end
+ method_inspect = Kernel.instance_method(:inspect)
+
+ inspected = method_inspect.bind(obj).call.sub(/^#<BasicObject:0x[0-9a-f]+/, '#<BasicObject:0x00')
+ inspected.should == %{#<BasicObject:0x00 @host="localhost", @user="root", @password="hunter2">}
+ end
+
+ it "raises an error if #instance_variables_to_inspect returns an invalid value" do
+ obj = Object.new
+ obj.instance_eval do
+ @host = "localhost"
+ @user = "root"
+ @password = "hunter2"
+ end
+ obj.singleton_class.class_eval do
+ private def instance_variables_to_inspect = {}
+ end
+
+ ->{ obj.inspect }.should.raise(TypeError, "Expected #instance_variables_to_inspect to return an Array or nil, but it returned Hash")
+ end
+ end
end
diff --git a/spec/ruby/core/kernel/instance_of_spec.rb b/spec/ruby/core/kernel/instance_of_spec.rb
index 4801a1ff96..8d19974aa3 100644
--- a/spec/ruby/core/kernel/instance_of_spec.rb
+++ b/spec/ruby/core/kernel/instance_of_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
-describe Kernel, "#instance_of?" do
+describe "Kernel#instance_of?" do
before :each do
@o = KernelSpecs::InstanceClass.new
end
@@ -33,8 +33,8 @@ describe Kernel, "#instance_of?" do
end
it "raises a TypeError if given an object that is not a Class nor a Module" do
- lambda { @o.instance_of?(Object.new) }.should raise_error(TypeError)
- lambda { @o.instance_of?('KernelSpecs::InstanceClass') }.should raise_error(TypeError)
- lambda { @o.instance_of?(1) }.should raise_error(TypeError)
+ -> { @o.instance_of?(Object.new) }.should.raise(TypeError)
+ -> { @o.instance_of?('KernelSpecs::InstanceClass') }.should.raise(TypeError)
+ -> { @o.instance_of?(1) }.should.raise(TypeError)
end
end
diff --git a/spec/ruby/core/kernel/instance_variable_defined_spec.rb b/spec/ruby/core/kernel/instance_variable_defined_spec.rb
index 969d36c731..512f811393 100644
--- a/spec/ruby/core/kernel/instance_variable_defined_spec.rb
+++ b/spec/ruby/core/kernel/instance_variable_defined_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Kernel#instance_variable_defined?" do
before do
@@ -8,34 +8,34 @@ describe "Kernel#instance_variable_defined?" do
describe "when passed a String" do
it "returns false if the instance variable is not defined" do
- @instance.instance_variable_defined?("@goodbye").should be_false
+ @instance.instance_variable_defined?("@goodbye").should == false
end
it "returns true if the instance variable is defined" do
- @instance.instance_variable_defined?("@greeting").should be_true
+ @instance.instance_variable_defined?("@greeting").should == true
end
end
describe "when passed a Symbol" do
it "returns false if the instance variable is not defined" do
- @instance.instance_variable_defined?(:@goodbye).should be_false
+ @instance.instance_variable_defined?(:@goodbye).should == false
end
it "returns true if the instance variable is defined" do
- @instance.instance_variable_defined?(:@greeting).should be_true
+ @instance.instance_variable_defined?(:@greeting).should == true
end
end
it "raises a TypeError if passed an Object not defining #to_str" do
- lambda do
+ -> do
obj = mock("kernel instance_variable_defined?")
@instance.instance_variable_defined? obj
- end.should raise_error(TypeError)
+ end.should.raise(TypeError)
end
it "returns false if the instance variable is not defined for different types" do
[nil, false, true, 1, 2.0, :test, "test"].each do |obj|
- obj.instance_variable_defined?("@goodbye").should be_false
+ obj.instance_variable_defined?("@goodbye").should == false
end
end
end
diff --git a/spec/ruby/core/kernel/instance_variable_get_spec.rb b/spec/ruby/core/kernel/instance_variable_get_spec.rb
index 0c564f11b6..8404c94192 100644
--- a/spec/ruby/core/kernel/instance_variable_get_spec.rb
+++ b/spec/ruby/core/kernel/instance_variable_get_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Kernel#instance_variable_get" do
before :each do
@@ -20,29 +20,29 @@ describe "Kernel#instance_variable_get" do
end
it "returns nil when the referred instance variable does not exist" do
- @obj.instance_variable_get(:@does_not_exist).should be_nil
+ @obj.instance_variable_get(:@does_not_exist).should == nil
end
it "raises a TypeError when the passed argument does not respond to #to_str" do
- lambda { @obj.instance_variable_get(Object.new) }.should raise_error(TypeError)
+ -> { @obj.instance_variable_get(Object.new) }.should.raise(TypeError)
end
it "raises a TypeError when the passed argument can't be converted to a String" do
obj = mock("to_str")
obj.stub!(:to_str).and_return(123)
- lambda { @obj.instance_variable_get(obj) }.should raise_error(TypeError)
+ -> { @obj.instance_variable_get(obj) }.should.raise(TypeError)
end
it "raises a NameError when the conversion result does not start with an '@'" do
obj = mock("to_str")
obj.stub!(:to_str).and_return("test")
- lambda { @obj.instance_variable_get(obj) }.should raise_error(NameError)
+ -> { @obj.instance_variable_get(obj) }.should.raise(NameError)
end
it "raises a NameError when passed just '@'" do
obj = mock("to_str")
obj.stub!(:to_str).and_return('@')
- lambda { @obj.instance_variable_get(obj) }.should raise_error(NameError)
+ -> { @obj.instance_variable_get(obj) }.should.raise(NameError)
end
end
@@ -57,15 +57,21 @@ describe "Kernel#instance_variable_get when passed Symbol" do
end
it "raises a NameError when passed :@ as an instance variable name" do
- lambda { @obj.instance_variable_get(:"@") }.should raise_error(NameError)
+ -> { @obj.instance_variable_get(:"@") }.should.raise(NameError)
end
it "raises a NameError when the passed Symbol does not start with an '@'" do
- lambda { @obj.instance_variable_get(:test) }.should raise_error(NameError)
+ -> { @obj.instance_variable_get(:test) }.should.raise(NameError)
end
it "raises a NameError when the passed Symbol is an invalid instance variable name" do
- lambda { @obj.instance_variable_get(:"@0") }.should raise_error(NameError)
+ -> { @obj.instance_variable_get(:"@0") }.should.raise(NameError)
+ end
+
+ it "returns nil or raises for frozen objects" do
+ nil.instance_variable_get(:@foo).should == nil
+ -> { nil.instance_variable_get(:foo) }.should.raise(NameError)
+ :foo.instance_variable_get(:@foo).should == nil
end
end
@@ -80,26 +86,26 @@ describe "Kernel#instance_variable_get when passed String" do
end
it "raises a NameError when the passed String does not start with an '@'" do
- lambda { @obj.instance_variable_get("test") }.should raise_error(NameError)
+ -> { @obj.instance_variable_get("test") }.should.raise(NameError)
end
it "raises a NameError when the passed String is an invalid instance variable name" do
- lambda { @obj.instance_variable_get("@0") }.should raise_error(NameError)
+ -> { @obj.instance_variable_get("@0") }.should.raise(NameError)
end
it "raises a NameError when passed '@' as an instance variable name" do
- lambda { @obj.instance_variable_get("@") }.should raise_error(NameError)
+ -> { @obj.instance_variable_get("@") }.should.raise(NameError)
end
end
-describe "Kernel#instance_variable_get when passed Fixnum" do
+describe "Kernel#instance_variable_get when passed Integer" do
before :each do
@obj = Object.new
@obj.instance_variable_set("@test", :test)
end
it "raises a TypeError" do
- lambda { @obj.instance_variable_get(10) }.should raise_error(TypeError)
- lambda { @obj.instance_variable_get(-10) }.should raise_error(TypeError)
+ -> { @obj.instance_variable_get(10) }.should.raise(TypeError)
+ -> { @obj.instance_variable_get(-10) }.should.raise(TypeError)
end
end
diff --git a/spec/ruby/core/kernel/instance_variable_set_spec.rb b/spec/ruby/core/kernel/instance_variable_set_spec.rb
index bac1bb5f99..bf165a824e 100644
--- a/spec/ruby/core/kernel/instance_variable_set_spec.rb
+++ b/spec/ruby/core/kernel/instance_variable_set_spec.rb
@@ -1,43 +1,43 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Kernel#instance_variable_set" do
it "sets the value of the specified instance variable" do
- class Dog
+ dog = Class.new do
def initialize(p1, p2)
@a, @b = p1, p2
end
end
- Dog.new('cat', 99).instance_variable_set(:@a, 'dog').should == "dog"
+ dog.new('cat', 99).instance_variable_set(:@a, 'dog').should == "dog"
end
it "sets the value of the instance variable when no instance variables exist yet" do
- class NoVariables; end
- NoVariables.new.instance_variable_set(:@a, "new").should == "new"
+ no_variables = Class.new
+ no_variables.new.instance_variable_set(:@a, "new").should == "new"
end
it "raises a NameError exception if the argument is not of form '@x'" do
- class NoDog; end
- lambda { NoDog.new.instance_variable_set(:c, "cat") }.should raise_error(NameError)
+ no_dog = Class.new
+ -> { no_dog.new.instance_variable_set(:c, "cat") }.should.raise(NameError)
end
it "raises a NameError exception if the argument is an invalid instance variable name" do
- class DigitDog; end
- lambda { DigitDog.new.instance_variable_set(:"@0", "cat") }.should raise_error(NameError)
+ digit_dog = Class.new
+ -> { digit_dog.new.instance_variable_set(:"@0", "cat") }.should.raise(NameError)
end
it "raises a NameError when the argument is '@'" do
- class DogAt; end
- lambda { DogAt.new.instance_variable_set(:"@", "cat") }.should raise_error(NameError)
+ dog_at = Class.new
+ -> { dog_at.new.instance_variable_set(:"@", "cat") }.should.raise(NameError)
end
- it "raises a TypeError if the instance variable name is a Fixnum" do
- lambda { "".instance_variable_set(1, 2) }.should raise_error(TypeError)
+ it "raises a TypeError if the instance variable name is an Integer" do
+ -> { "".instance_variable_set(1, 2) }.should.raise(TypeError)
end
it "raises a TypeError if the instance variable name is an object that does not respond to to_str" do
class KernelSpecs::A; end
- lambda { "".instance_variable_set(KernelSpecs::A.new, 3) }.should raise_error(TypeError)
+ -> { "".instance_variable_set(KernelSpecs::A.new, 3) }.should.raise(TypeError)
end
it "raises a NameError if the passed object, when coerced with to_str, does not start with @" do
@@ -46,11 +46,11 @@ describe "Kernel#instance_variable_set" do
":c"
end
end
- lambda { "".instance_variable_set(KernelSpecs::B.new, 4) }.should raise_error(NameError)
+ -> { "".instance_variable_set(KernelSpecs::B.new, 4) }.should.raise(NameError)
end
it "raises a NameError if pass an object that cannot be a symbol" do
- lambda { "".instance_variable_set(:c, 1) }.should raise_error(NameError)
+ -> { "".instance_variable_set(:c, 1) }.should.raise(NameError)
end
it "accepts as instance variable name any instance of a class that responds to to_str" do
@@ -78,16 +78,28 @@ describe "Kernel#instance_variable_set" do
end
it "keeps stored object after any exceptions" do
- lambda { @frozen.instance_variable_set(:@ivar, :replacement) }.should raise_error(Exception)
- @frozen.ivar.should equal(:origin)
+ -> { @frozen.instance_variable_set(:@ivar, :replacement) }.should.raise(Exception)
+ @frozen.ivar.should.equal?(:origin)
end
- it "raises a RuntimeError when passed replacement is identical to stored object" do
- lambda { @frozen.instance_variable_set(:@ivar, :origin) }.should raise_error(RuntimeError)
+ it "raises a FrozenError when passed replacement is identical to stored object" do
+ -> { @frozen.instance_variable_set(:@ivar, :origin) }.should.raise(FrozenError)
end
- it "raises a RuntimeError when passed replacement is different from stored object" do
- lambda { @frozen.instance_variable_set(:@ivar, :replacement) }.should raise_error(RuntimeError)
+ it "raises a FrozenError when passed replacement is different from stored object" do
+ -> { @frozen.instance_variable_set(:@ivar, :replacement) }.should.raise(FrozenError)
+ end
+
+ it "accepts unicode instance variable names" do
+ o = Object.new
+ o.instance_variable_set(:@💙, 42)
+ o.instance_variable_get(:@💙).should == 42
+ end
+
+ it "raises for frozen objects" do
+ -> { nil.instance_variable_set(:@foo, 42) }.should.raise(FrozenError)
+ -> { nil.instance_variable_set(:foo, 42) }.should.raise(NameError)
+ -> { :foo.instance_variable_set(:@foo, 42) }.should.raise(FrozenError)
end
end
end
diff --git a/spec/ruby/core/kernel/instance_variables_spec.rb b/spec/ruby/core/kernel/instance_variables_spec.rb
index f744ee3c7a..75c1d8f752 100644
--- a/spec/ruby/core/kernel/instance_variables_spec.rb
+++ b/spec/ruby/core/kernel/instance_variables_spec.rb
@@ -1,15 +1,17 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Kernel#instance_variables" do
describe "immediate values" do
it "returns an empty array if no instance variables are defined" do
- 0.instance_variables.should == []
+ [0, 0.5, true, false, nil].each do |value|
+ value.instance_variables.should == []
+ end
end
it "returns the correct array if an instance variable is added" do
a = 0
- lambda{ a.instance_variable_set("@test", 1) }.should raise_error(RuntimeError)
+ ->{ a.instance_variable_set("@test", 1) }.should.raise(RuntimeError)
end
end
@@ -23,5 +25,16 @@ describe "Kernel#instance_variables" do
a.instance_variable_set("@test", 1)
a.instance_variables.should == [:@test]
end
+
+ it "returns the instances variables in the order declared" do
+ c = Class.new do
+ def initialize
+ @c = 1
+ @a = 2
+ @b = 3
+ end
+ end
+ c.new.instance_variables.should == [:@c, :@a, :@b]
+ end
end
end
diff --git a/spec/ruby/core/kernel/is_a_spec.rb b/spec/ruby/core/kernel/is_a_spec.rb
index c67c6552a0..ff36a769c7 100644
--- a/spec/ruby/core/kernel/is_a_spec.rb
+++ b/spec/ruby/core/kernel/is_a_spec.rb
@@ -1,6 +1,56 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/kind_of', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Kernel#is_a?" do
- it_behaves_like(:kernel_kind_of , :is_a?)
+ before :each do
+ @o = KernelSpecs::KindaClass.new
+ end
+
+ it "returns true if given class is the object's class" do
+ @o.is_a?(KernelSpecs::KindaClass).should == true
+ end
+
+ it "returns true if given class is an ancestor of the object's class" do
+ @o.is_a?(KernelSpecs::AncestorClass).should == true
+ @o.is_a?(String).should == true
+ @o.is_a?(Object).should == true
+ end
+
+ it "returns false if the given class is not object's class nor an ancestor" do
+ @o.is_a?(Array).should == false
+ end
+
+ it "returns true if given a Module that is included in object's class" do
+ @o.is_a?(KernelSpecs::MyModule).should == true
+ end
+
+ it "returns true if given a Module that is included one of object's ancestors only" do
+ @o.is_a?(KernelSpecs::AncestorModule).should == true
+ end
+
+ it "returns true if given a Module that object has been extended with" do
+ @o.is_a?(KernelSpecs::MyExtensionModule).should == true
+ end
+
+ it "returns true if given a Module that object has been prepended with" do
+ @o.is_a?(KernelSpecs::MyPrependedModule).should == true
+ end
+
+ it "returns false if given a Module not included nor prepended in object's class nor ancestors" do
+ @o.is_a?(KernelSpecs::SomeOtherModule).should == false
+ end
+
+ it "raises a TypeError if given an object that is not a Class nor a Module" do
+ -> { @o.is_a?(1) }.should.raise(TypeError)
+ -> { @o.is_a?('KindaClass') }.should.raise(TypeError)
+ -> { @o.is_a?(:KindaClass) }.should.raise(TypeError)
+ -> { @o.is_a?(Object.new) }.should.raise(TypeError)
+ end
+
+ it "does not take into account `class` method overriding" do
+ def @o.class; Integer; end
+
+ @o.is_a?(Integer).should == false
+ @o.is_a?(KernelSpecs::KindaClass).should == true
+ end
end
diff --git a/spec/ruby/core/kernel/iterator_spec.rb b/spec/ruby/core/kernel/iterator_spec.rb
deleted file mode 100644
index e85f0dc612..0000000000
--- a/spec/ruby/core/kernel/iterator_spec.rb
+++ /dev/null
@@ -1,12 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-
-describe "Kernel#iterator?" do
- it "is a private method" do
- Kernel.should have_private_instance_method(:iterator?)
- end
-end
-
-describe "Kernel.iterator?" do
- it "needs to be reviewed for spec completeness"
-end
diff --git a/spec/ruby/core/kernel/itself_spec.rb b/spec/ruby/core/kernel/itself_spec.rb
index 722d75d718..c1f01fdc5e 100644
--- a/spec/ruby/core/kernel/itself_spec.rb
+++ b/spec/ruby/core/kernel/itself_spec.rb
@@ -1,9 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Kernel#itself" do
it "returns the receiver itself" do
foo = Object.new
- foo.itself.should equal foo
+ foo.itself.should.equal? foo
end
end
diff --git a/spec/ruby/core/kernel/kind_of_spec.rb b/spec/ruby/core/kernel/kind_of_spec.rb
index 56a54ec859..7fcc72543d 100644
--- a/spec/ruby/core/kernel/kind_of_spec.rb
+++ b/spec/ruby/core/kernel/kind_of_spec.rb
@@ -1,6 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/kind_of', __FILE__)
+require_relative '../../spec_helper'
describe "Kernel#kind_of?" do
- it_behaves_like(:kernel_kind_of , :kind_of?)
+ it "is an alias of Kernel#is_a?" do
+ Kernel.instance_method(:kind_of?).should == Kernel.instance_method(:is_a?)
+ end
end
diff --git a/spec/ruby/core/kernel/lambda_spec.rb b/spec/ruby/core/kernel/lambda_spec.rb
index 8fa0075675..6ab89c2bbb 100644
--- a/spec/ruby/core/kernel/lambda_spec.rb
+++ b/spec/ruby/core/kernel/lambda_spec.rb
@@ -1,56 +1,59 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/lambda', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/lambda'
# 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)
+ Kernel.private_instance_methods(false).should.include?(:lambda)
end
it "creates a lambda-style Proc if given a literal block" do
l = lambda { 42 }
- l.lambda?.should be_true
+ l.lambda?.should == true
end
- it "returned the passed Proc if given an existing Proc" do
- some_proc = proc {}
- l = lambda(&some_proc)
- l.should equal(some_proc)
- l.lambda?.should be_false
+ it "creates a lambda-style Proc if given a literal block via #send" do
+ l = send(:lambda) { 42 }
+ l.lambda?.should == true
+ end
+
+ it "creates a lambda-style Proc if given a literal block via #__send__" do
+ l = __send__(:lambda) { 42 }
+ l.lambda?.should == true
end
it "checks the arity of the call when no args are specified" do
l = lambda { :called }
l.call.should == :called
- lambda { l.call(1) }.should raise_error(ArgumentError)
- lambda { l.call(1, 2) }.should raise_error(ArgumentError)
+ lambda { l.call(1) }.should.raise(ArgumentError)
+ lambda { l.call(1, 2) }.should.raise(ArgumentError)
end
it "checks the arity when 1 arg is specified" do
l = lambda { |a| :called }
l.call(1).should == :called
- lambda { l.call }.should raise_error(ArgumentError)
- lambda { l.call(1, 2) }.should raise_error(ArgumentError)
+ lambda { l.call }.should.raise(ArgumentError)
+ lambda { l.call(1, 2) }.should.raise(ArgumentError)
end
it "does not check the arity when passing a Proc with &" do
l = lambda { || :called }
p = proc { || :called }
- lambda { l.call(1) }.should raise_error(ArgumentError)
+ lambda { l.call(1) }.should.raise(ArgumentError)
p.call(1).should == :called
end
it "accepts 0 arguments when used with ||" do
lambda {
lambda { || }.call(1)
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
end
it "strictly checks the arity when 0 or 2..inf args are specified" do
@@ -58,15 +61,15 @@ describe "Kernel.lambda" do
lambda {
l.call
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
lambda {
l.call(1)
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
lambda {
l.call(1,2)
- }.should_not raise_error(ArgumentError)
+ }.should_not.raise(ArgumentError)
end
it "returns from the lambda itself, not the creation site of the lambda" do
@@ -76,11 +79,32 @@ describe "Kernel.lambda" do
@reached_end_of_method = true
end
test
- @reached_end_of_method.should be_true
+ @reached_end_of_method.should == true
end
it "allows long returns to flow through it" do
KernelSpecs::Lambda.new.outer.should == :good
end
-end
+ it "treats the block as a Proc when lambda is re-defined" do
+ klass = Class.new do
+ def lambda (&block); block; end
+ def ret
+ lambda { return 1 }.call
+ 2
+ end
+ end
+ klass.new.lambda { 42 }.should.instance_of? Proc
+ klass.new.ret.should == 1
+ end
+
+ context "when called without a literal block" do
+ it "raises when proc isn't a lambda" do
+ -> { lambda(&proc{}) }.should.raise(ArgumentError, /the lambda method requires a literal block/)
+ end
+
+ it "doesn't warn when proc is lambda" do
+ -> { lambda(&lambda{}) }.should_not complain(verbose: true)
+ end
+ end
+end
diff --git a/spec/ruby/core/kernel/load_spec.rb b/spec/ruby/core/kernel/load_spec.rb
index 36cc07e38a..890aab8c27 100644
--- a/spec/ruby/core/kernel/load_spec.rb
+++ b/spec/ruby/core/kernel/load_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../fixtures/code_loading', __FILE__)
-require File.expand_path('../shared/load', __FILE__)
-require File.expand_path('../shared/require', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../../fixtures/code_loading'
+require_relative 'shared/load'
+require_relative 'shared/require'
describe "Kernel#load" do
before :each do
@@ -13,7 +13,7 @@ describe "Kernel#load" do
end
it "is a private method" do
- Kernel.should have_private_instance_method(:load)
+ Kernel.private_instance_methods(false).should.include?(:load)
end
it_behaves_like :kernel_require_basic, :load, CodeLoadingSpecs::Method.new
diff --git a/spec/ruby/core/kernel/local_variables_spec.rb b/spec/ruby/core/kernel/local_variables_spec.rb
index 7e8b364b4f..40c343f7e4 100644
--- a/spec/ruby/core/kernel/local_variables_spec.rb
+++ b/spec/ruby/core/kernel/local_variables_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Kernel#local_variables" do
after :each do
@@ -7,14 +7,13 @@ describe "Kernel#local_variables" do
end
it "is a private method" do
- Kernel.should have_private_instance_method(:local_variables)
+ Kernel.private_instance_methods(false).should.include?(:local_variables)
end
it "contains locals as they are added" do
a = 1
b = 2
- local_variables.should include(:a, :b)
- local_variables.length.should == 2
+ local_variables.sort.should == [:a, :b]
end
it "is accessible from bindings" do
@@ -25,13 +24,22 @@ describe "Kernel#local_variables" do
end
foo_binding = local_var_foo()
res = eval("local_variables",foo_binding)
- res.should include(:a, :b)
- res.length.should == 2
+ res.sort.should == [:a, :b]
end
it "is accessible in eval" do
eval "a=1; b=2; ScratchPad.record local_variables"
- ScratchPad.recorded.should include(:a, :b)
- ScratchPad.recorded.length.should == 2
+ ScratchPad.recorded.sort.should == [:a, :b]
+ end
+
+ it "includes only unique variable names" do
+ def local_var_method
+ a = 1
+ 1.times do |;a|
+ return local_variables
+ end
+ end
+
+ local_var_method.should == [:a]
end
end
diff --git a/spec/ruby/core/kernel/loop_spec.rb b/spec/ruby/core/kernel/loop_spec.rb
index f23e3afb02..c2976e5cc5 100644
--- a/spec/ruby/core/kernel/loop_spec.rb
+++ b/spec/ruby/core/kernel/loop_spec.rb
@@ -1,9 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Kernel.loop" do
it "is a private method" do
- Kernel.should have_private_instance_method(:loop)
+ Kernel.private_instance_methods(false).should.include?(:loop)
end
it "calls block until it is terminated by a break" do
@@ -30,7 +30,7 @@ describe "Kernel.loop" do
it "returns an enumerator if no block given" do
enum = loop
- enum.instance_of?(Enumerator).should be_true
+ enum.instance_of?(Enumerator).should == true
cnt = 0
enum.each do |*args|
raise "Args should be empty #{args.inspect}" unless args.empty?
@@ -55,18 +55,16 @@ describe "Kernel.loop" do
end
it "does not rescue other errors" do
- lambda{ loop do raise StandardError end }.should raise_error( StandardError )
+ ->{ loop do raise StandardError end }.should.raise( StandardError )
end
- ruby_version_is "2.3" do
- it "returns StopIteration#result, the result value of a finished iterator" do
- e = Enumerator.new { |y|
- y << 1
- y << 2
- :stopped
- }
- loop { e.next }.should == :stopped
- end
+ it "returns StopIteration#result, the result value of a finished iterator" do
+ e = Enumerator.new { |y|
+ y << 1
+ y << 2
+ :stopped
+ }
+ loop { e.next }.should == :stopped
end
describe "when no block is given" do
diff --git a/spec/ruby/core/kernel/match_spec.rb b/spec/ruby/core/kernel/match_spec.rb
index 8a117ed497..cd6330fe91 100644
--- a/spec/ruby/core/kernel/match_spec.rb
+++ b/spec/ruby/core/kernel/match_spec.rb
@@ -1,14 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Kernel#=~" do
- it "returns nil matching any object" do
- o = Object.new
-
- (o =~ /Object/).should be_nil
- (o =~ 'Object').should be_nil
- (o =~ Object).should be_nil
- (o =~ Object.new).should be_nil
- (o =~ nil).should be_nil
- (o =~ true).should be_nil
+ it "is no longer defined" do
+ Object.new.should_not.respond_to?(:=~)
end
end
diff --git a/spec/ruby/core/kernel/method_spec.rb b/spec/ruby/core/kernel/method_spec.rb
index 09a3f940ca..9187b8c7e7 100644
--- a/spec/ruby/core/kernel/method_spec.rb
+++ b/spec/ruby/core/kernel/method_spec.rb
@@ -1,9 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/method', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/method'
+require_relative 'fixtures/classes'
describe "Kernel#method" do
- it_behaves_like(:kernel_method, :method)
+ it_behaves_like :kernel_method, :method
before :each do
@obj = KernelSpecs::A.new
@@ -11,12 +11,12 @@ describe "Kernel#method" do
it "can be called on a private method" do
@obj.send(:private_method).should == :private_method
- @obj.method(:private_method).should be_an_instance_of(Method)
+ @obj.method(:private_method).should.instance_of?(Method)
end
it "can be called on a protected method" do
@obj.send(:protected_method).should == :protected_method
- @obj.method(:protected_method).should be_an_instance_of(Method)
+ @obj.method(:protected_method).should.instance_of?(Method)
end
it "will see an alias of the original method as == when in a derived class" do
@@ -29,9 +29,60 @@ describe "Kernel#method" do
m.call.should == :defined
end
- it "can be called even if we only repond_to_missing? method, true" do
+ it "can be called even if we only respond_to_missing? method, true" do
m = KernelSpecs::RespondViaMissing.new.method(:handled_privately)
- m.should be_an_instance_of(Method)
+ m.should.instance_of?(Method)
m.call(1, 2, 3).should == "Done handled_privately([1, 2, 3])"
end
+
+ it "can call a #method_missing accepting zero or one arguments" do
+ cls = Class.new do
+ def respond_to_missing?(name, *)
+ name == :foo or super
+ end
+ def method_missing
+ :no_args
+ end
+ end
+ m = cls.new.method(:foo)
+ -> { m.call }.should.raise(ArgumentError)
+
+ cls = Class.new do
+ def respond_to_missing?(name, *)
+ name == :bar or super
+ end
+ def method_missing(m)
+ m
+ end
+ end
+ m = cls.new.method(:bar)
+ m.call.should == :bar
+ end
+
+ describe "converts the given name to a String using #to_str" do
+ it "calls #to_str to convert the given name to a String" do
+ name = mock("method-name")
+ name.should_receive(:to_str).and_return("hash")
+ Object.method(name).should == Object.method(:hash)
+ end
+
+ it "raises a TypeError if the given name can't be converted to a String" do
+ -> { Object.method(nil) }.should.raise(TypeError)
+ -> { Object.method([]) }.should.raise(TypeError)
+ end
+
+ it "raises a NoMethodError if the given argument raises a NoMethodError during type coercion to a String" do
+ name = mock("method-name")
+ name.should_receive(:to_str).and_raise(NoMethodError)
+ -> { Object.method(name) }.should.raise(NoMethodError)
+
+ name = mock("method-name")
+ name.should_receive(:to_str).and_raise(NoMethodError)
+ begin
+ raise RuntimeError.new
+ rescue => cause
+ -> { Object.method(name) }.should.raise(NoMethodError, cause:)
+ end
+ end
+ end
end
diff --git a/spec/ruby/core/kernel/methods_spec.rb b/spec/ruby/core/kernel/methods_spec.rb
index 5dfb17d4cb..cfa22aa05a 100644
--- a/spec/ruby/core/kernel/methods_spec.rb
+++ b/spec/ruby/core/kernel/methods_spec.rb
@@ -1,71 +1,71 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../../../fixtures/reflection', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative '../../fixtures/reflection'
# TODO: rewrite
describe "Kernel#methods" do
it "returns singleton methods defined by obj.meth" do
- KernelSpecs::Methods.methods(false).should include(:ichi)
+ KernelSpecs::Methods.methods(false).should.include?(:ichi)
end
it "returns singleton methods defined in 'class << self'" do
- KernelSpecs::Methods.methods(false).should include(:san)
+ KernelSpecs::Methods.methods(false).should.include?(:san)
end
it "returns private singleton methods defined by obj.meth" do
- KernelSpecs::Methods.methods(false).should include(:shi)
+ KernelSpecs::Methods.methods(false).should.include?(:shi)
end
it "returns singleton methods defined in 'class << self' when it follows 'private'" do
- KernelSpecs::Methods.methods(false).should include(:roku)
+ KernelSpecs::Methods.methods(false).should.include?(:roku)
end
it "does not return private singleton methods defined in 'class << self'" do
- KernelSpecs::Methods.methods(false).should_not include(:shichi)
+ KernelSpecs::Methods.methods(false).should_not.include?(:shichi)
end
it "returns the publicly accessible methods of the object" do
meths = KernelSpecs::Methods.methods(false)
- meths.should include(:hachi, :ichi, :juu, :juu_ichi,
- :juu_ni, :roku, :san, :shi)
+ meths.to_set.should >= Set[:hachi, :ichi, :juu, :juu_ichi,
+ :juu_ni, :roku, :san, :shi]
KernelSpecs::Methods.new.methods(false).should == []
end
it "returns the publicly accessible methods in the object, its ancestors and mixed-in modules" do
meths = KernelSpecs::Methods.methods(false) & KernelSpecs::Methods.methods
- meths.should include(:hachi, :ichi, :juu, :juu_ichi,
- :juu_ni, :roku, :san, :shi)
+ meths.to_set.should >= Set[:hachi, :ichi, :juu, :juu_ichi,
+ :juu_ni, :roku, :san, :shi]
- KernelSpecs::Methods.new.methods.should include(:ku, :ni, :juu_san)
+ KernelSpecs::Methods.new.methods.to_set.should >= Set[:ku, :ni, :juu_san]
end
it "returns methods added to the metaclass through extend" do
meth = KernelSpecs::Methods.new
- meth.methods.should_not include(:peekaboo)
+ meth.methods.should_not.include?(:peekaboo)
meth.extend(KernelSpecs::Methods::MetaclassMethods)
- meth.methods.should include(:peekaboo)
+ meth.methods.should.include?(:peekaboo)
end
it "does not return undefined singleton methods defined by obj.meth" do
o = KernelSpecs::Child.new
def o.single; end
- o.methods.should include(:single)
+ o.methods.should.include?(:single)
class << o; self; end.send :undef_method, :single
- o.methods.should_not include(:single)
+ o.methods.should_not.include?(:single)
end
it "does not return superclass methods undefined in the object's class" do
- KernelSpecs::Child.new.methods.should_not include(:parent_method)
+ KernelSpecs::Child.new.methods.should_not.include?(:parent_method)
end
it "does not return superclass methods undefined in a superclass" do
- KernelSpecs::Grandchild.new.methods.should_not include(:parent_method)
+ KernelSpecs::Grandchild.new.methods.should_not.include?(:parent_method)
end
it "does not return included module methods undefined in the object's class" do
- KernelSpecs::Grandchild.new.methods.should_not include(:parent_mixin_method)
+ KernelSpecs::Grandchild.new.methods.should_not.include?(:parent_mixin_method)
end
end
diff --git a/spec/ruby/core/kernel/nil_spec.rb b/spec/ruby/core/kernel/nil_spec.rb
index 0b5e34f7f1..7418245f26 100644
--- a/spec/ruby/core/kernel/nil_spec.rb
+++ b/spec/ruby/core/kernel/nil_spec.rb
@@ -1,6 +1,12 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
-describe "Kernel#nil?" do
- it "needs to be reviewed for spec completeness"
+describe 'Kernel#nil?' do
+ it 'returns false' do
+ Object.should_not.nil?
+ Object.new.should_not.nil?
+ ''.should_not.nil?
+ [].should_not.nil?
+ {}.should_not.nil?
+ end
end
diff --git a/spec/ruby/core/kernel/not_match_spec.rb b/spec/ruby/core/kernel/not_match_spec.rb
index 42bd45c106..4ed7ea7b42 100644
--- a/spec/ruby/core/kernel/not_match_spec.rb
+++ b/spec/ruby/core/kernel/not_match_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Kernel#!~" do
class KernelSpecs::NotMatch
@@ -14,6 +14,10 @@ describe "Kernel#!~" do
(obj !~ :foo).should == false
end
+ it "raises NoMethodError if self does not respond to #=~" do
+ -> { Object.new !~ :foo }.should.raise(NoMethodError)
+ end
+
it 'can be overridden in subclasses' do
obj = KernelSpecs::NotMatch.new
(obj !~ :bar).should == :foo
diff --git a/spec/ruby/core/kernel/object_id_spec.rb b/spec/ruby/core/kernel/object_id_spec.rb
index 0a12415a40..ef9e80c831 100644
--- a/spec/ruby/core/kernel/object_id_spec.rb
+++ b/spec/ruby/core/kernel/object_id_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/kernel/object_id', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../../shared/kernel/object_id'
describe "Kernel#object_id" do
it_behaves_like :object_id, :object_id, Object
diff --git a/spec/ruby/core/kernel/open_spec.rb b/spec/ruby/core/kernel/open_spec.rb
index 4e99061219..14a3c43cad 100644
--- a/spec/ruby/core/kernel/open_spec.rb
+++ b/spec/ruby/core/kernel/open_spec.rb
@@ -1,8 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Kernel#open" do
-
before :each do
@name = tmp("kernel_open.txt")
@content = "This is a test"
@@ -16,58 +15,90 @@ describe "Kernel#open" do
end
it "is a private method" do
- Kernel.should have_private_instance_method(:open)
+ Kernel.private_instance_methods(false).should.include?(:open)
end
it "opens a file when given a valid filename" do
@file = open(@name)
- @file.should be_kind_of(File)
+ @file.should.is_a?(File)
end
it "opens a file when called with a block" do
open(@name, "r") { |f| f.gets }.should == @content
end
- platform_is_not :windows do
- it "opens an io when path starts with a pipe" do
- @io = open("|date")
- begin
- @io.should be_kind_of(IO)
- ensure
- @io.close
+ ruby_version_is ""..."4.0" do
+ platform_is_not :windows, :wasi do
+ it "opens an io when path starts with a pipe" do
+ suppress_warning do # https://bugs.ruby-lang.org/issues/19630
+ @io = open("|date")
+ end
+ begin
+ @io.should.is_a?(IO)
+ @io.read
+ ensure
+ @io.close
+ end
end
- end
- it "opens an io when called with a block" do
- @output = open("|date") { |f| f.gets }
- @output.should_not == ''
- end
+ it "opens an io when called with a block" do
+ suppress_warning do # https://bugs.ruby-lang.org/issues/19630
+ @output = open("|date") { |f| f.read }
+ end
+ @output.should_not == ''
+ end
- it "opens an io for writing" do
- bytes = open("|cat", "w") { |io| io.write(".") }
- bytes.should == 1
+ it "opens an io for writing" do
+ suppress_warning do # https://bugs.ruby-lang.org/issues/19630
+ -> {
+ bytes = open("|cat", "w") { |io| io.write(".") }
+ bytes.should == 1
+ }.should output_to_fd(".")
+ end
+ end
end
- end
- platform_is :windows do
- it "opens an io when path starts with a pipe" do
- @io = open("|date /t")
- begin
- @io.should be_kind_of(IO)
- @io.read
- ensure
- @io.close
+ platform_is :windows do
+ it "opens an io when path starts with a pipe" do
+ suppress_warning do # https://bugs.ruby-lang.org/issues/19630
+ @io = open("|date /t")
+ end
+ begin
+ @io.should.is_a?(IO)
+ @io.read
+ ensure
+ @io.close
+ end
+ end
+
+ it "opens an io when called with a block" do
+ suppress_warning do # https://bugs.ruby-lang.org/issues/19630
+ @output = open("|date /t") { |f| f.read }
+ end
+ @output.should_not == ''
end
end
- it "opens an io when called with a block" do
- @output = open("|date /t") { |f| f.gets }
- @output.should_not == ''
+ # https://bugs.ruby-lang.org/issues/19630
+ it "warns about deprecation given a path with a pipe" do
+ cmd = "|echo ok"
+ -> {
+ open(cmd) { |f| f.read }
+ }.should complain(/Kernel#open with a leading '\|'/)
end
end
it "raises an ArgumentError if not passed one argument" do
- lambda { open }.should raise_error(ArgumentError)
+ -> { open }.should.raise(ArgumentError)
+ end
+
+ it "accepts options as keyword arguments" do
+ @file = open(@name, "r", 0666, flags: File::CREAT)
+ @file.should.is_a?(File)
+
+ -> {
+ open(@name, "r", 0666, {flags: File::CREAT})
+ }.should.raise(ArgumentError, "wrong number of arguments (given 4, expected 1..3)")
end
describe "when given an object that responds to to_open" do
@@ -75,7 +106,7 @@ describe "Kernel#open" do
ScratchPad.clear
end
- it "calls #to_path to covert the argument to a String before calling #to_str" do
+ it "calls #to_path to convert the argument to a String before calling #to_str" do
obj = mock("open to_path")
obj.should_receive(:to_path).at_least(1).times.and_return(@name)
obj.should_not_receive(:to_str)
@@ -95,7 +126,7 @@ describe "Kernel#open" do
@file = File.open(@name)
obj.should_receive(:to_open).and_return(@file)
@file = open(obj)
- @file.should be_kind_of(File)
+ @file.should.is_a?(File)
end
it "returns the value from #to_open" do
@@ -107,11 +138,21 @@ describe "Kernel#open" do
it "passes its arguments onto #to_open" do
obj = mock('to_open')
- obj.should_receive(:to_open).with(1,2,3)
-
+ obj.should_receive(:to_open).with(1, 2, 3)
open(obj, 1, 2, 3)
end
+ it "passes keyword arguments onto #to_open as keyword arguments if to_open accepts them" do
+ obj = Object.new
+ def obj.to_open(*args, **kw)
+ ScratchPad << {args: args, kw: kw}
+ end
+
+ ScratchPad.record []
+ open(obj, 1, 2, 3, a: "b")
+ ScratchPad.recorded.should == [args: [1, 2, 3], kw: {a: "b"}]
+ end
+
it "passes the return value from #to_open to a block" do
obj = mock('to_open')
obj.should_receive(:to_open).and_return(:value)
@@ -126,14 +167,24 @@ describe "Kernel#open" do
it "raises a TypeError if passed a non-String that does not respond to #to_open" do
obj = mock('non-fileish')
- lambda { open(obj) }.should raise_error(TypeError)
- lambda { open(nil) }.should raise_error(TypeError)
- lambda { open(7) }.should raise_error(TypeError)
+ -> { open(obj) }.should.raise(TypeError)
+ -> { open(nil) }.should.raise(TypeError)
+ -> { open(7) }.should.raise(TypeError)
end
it "accepts nil for mode and permission" do
open(@name, nil, nil) { |f| f.gets }.should == @content
end
+
+ it "is not redefined by open-uri" do
+ code = <<~RUBY
+ before = Kernel.instance_method(:open)
+ require 'open-uri'
+ after = Kernel.instance_method(:open)
+ p before == after
+ RUBY
+ ruby_exe(code, args: "2>&1").should == "true\n"
+ end
end
describe "Kernel.open" do
diff --git a/spec/ruby/core/kernel/p_spec.rb b/spec/ruby/core/kernel/p_spec.rb
index c451f5952a..f89716899a 100644
--- a/spec/ruby/core/kernel/p_spec.rb
+++ b/spec/ruby/core/kernel/p_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Kernel#p" do
before :all do
@@ -7,11 +7,13 @@ describe "Kernel#p" do
end
after :each do
- $/, $\, $, = @rs_f, @rs_b, @rs_c
+ suppress_warning {
+ $/, $\, $, = @rs_f, @rs_b, @rs_c
+ }
end
it "is a private method" do
- Kernel.should have_private_instance_method(:p)
+ Kernel.private_instance_methods(false).should.include?(:p)
end
# TODO: fix
@@ -40,38 +42,42 @@ describe "Kernel#p" do
o = mock("Inspector Gadget")
o.should_receive(:inspect).any_number_of_times.and_return "Next time, Gadget, NEXT TIME!"
- lambda { p(o) }.should output("Next time, Gadget, NEXT TIME!\n")
- lambda { p(*[o]) }.should output("Next time, Gadget, NEXT TIME!\n")
- lambda { p(*[o, o]) }.should output("Next time, Gadget, NEXT TIME!\nNext time, Gadget, NEXT TIME!\n")
- lambda { p([o])}.should output("[#{o.inspect}]\n")
+ -> { p(o) }.should output("Next time, Gadget, NEXT TIME!\n")
+ -> { p(*[o]) }.should output("Next time, Gadget, NEXT TIME!\n")
+ -> { p(*[o, o]) }.should output("Next time, Gadget, NEXT TIME!\nNext time, Gadget, NEXT TIME!\n")
+ -> { p([o])}.should output("[#{o.inspect}]\n")
end
it "is not affected by setting $\\, $/ or $," do
o = mock("Inspector Gadget")
o.should_receive(:inspect).any_number_of_times.and_return "Next time, Gadget, NEXT TIME!"
- $, = " *helicopter sound*\n"
- lambda { p(o) }.should output_to_fd("Next time, Gadget, NEXT TIME!\n")
+ suppress_warning {
+ $, = " *helicopter sound*\n"
+ }
+ -> { p(o) }.should output_to_fd("Next time, Gadget, NEXT TIME!\n")
- $\ = " *helicopter sound*\n"
- lambda { p(o) }.should output_to_fd("Next time, Gadget, NEXT TIME!\n")
+ suppress_warning {
+ $\ = " *helicopter sound*\n"
+ }
+ -> { p(o) }.should output_to_fd("Next time, Gadget, NEXT TIME!\n")
- $/ = " *helicopter sound*\n"
- lambda { p(o) }.should output_to_fd("Next time, Gadget, NEXT TIME!\n")
+ suppress_warning {
+ $/ = " *helicopter sound*\n"
+ }
+ -> { p(o) }.should output_to_fd("Next time, Gadget, NEXT TIME!\n")
end
it "prints nothing if no argument is given" do
- lambda { p }.should output("")
+ -> { p }.should output("")
end
it "prints nothing if called splatting an empty Array" do
- lambda { p(*[]) }.should output("")
+ -> { p(*[]) }.should output("")
end
-=begin Not sure how to spec this, but wanted to note the behavior here
- it "does not flush if receiver is not a TTY or a File" do
- end
-=end
+ # Not sure how to spec this, but wanted to note the behavior here
+ it "does not flush if receiver is not a TTY or a File"
end
describe "Kernel.p" do
diff --git a/spec/ruby/core/kernel/pp_spec.rb b/spec/ruby/core/kernel/pp_spec.rb
new file mode 100644
index 0000000000..b5b1c98d38
--- /dev/null
+++ b/spec/ruby/core/kernel/pp_spec.rb
@@ -0,0 +1,9 @@
+require_relative '../../spec_helper'
+
+describe "Kernel#pp" do
+ it "lazily loads the 'pp' library and delegates the call to that library" do
+ # Run in child process to ensure 'pp' hasn't been loaded yet.
+ output = ruby_exe("pp [1, 2, 3]")
+ output.should == "[1, 2, 3]\n"
+ end
+end
diff --git a/spec/ruby/core/kernel/print_spec.rb b/spec/ruby/core/kernel/print_spec.rb
index 3b642538cb..5473d22f71 100644
--- a/spec/ruby/core/kernel/print_spec.rb
+++ b/spec/ruby/core/kernel/print_spec.rb
@@ -1,9 +1,21 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Kernel#print" do
it "is a private method" do
- Kernel.should have_private_instance_method(:print)
+ Kernel.private_instance_methods(false).should.include?(:print)
+ end
+
+ it "delegates to $stdout" do
+ -> { print :arg }.should output("arg")
+ end
+
+ it "prints $_ when no arguments are given" do
+ orig_value = $_
+ $_ = 'foo'
+ -> { print }.should output("foo")
+ ensure
+ $_ = orig_value
end
end
diff --git a/spec/ruby/core/kernel/printf_spec.rb b/spec/ruby/core/kernel/printf_spec.rb
index b4c68fa449..50939b3794 100644
--- a/spec/ruby/core/kernel/printf_spec.rb
+++ b/spec/ruby/core/kernel/printf_spec.rb
@@ -1,14 +1,14 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/sprintf'
describe "Kernel#printf" do
it "is a private method" do
- Kernel.should have_private_instance_method(:printf)
+ Kernel.private_instance_methods(false).should.include?(:printf)
end
end
describe "Kernel.printf" do
-
before :each do
@stdout = $stdout
@name = tmp("kernel_puts.txt")
@@ -31,4 +31,40 @@ describe "Kernel.printf" do
object.should_receive(:write).with("string")
Kernel.printf(object, "%s", "string")
end
+
+ it "calls #to_str to convert the format object to a String" do
+ object = mock('format string')
+ object.should_receive(:to_str).and_return("to_str: %i")
+ $stdout.should_receive(:write).with("to_str: 42")
+ Kernel.printf($stdout, object, 42)
+ end
+end
+
+describe "Kernel.printf" do
+ describe "formatting" do
+ before :each do
+ require "stringio"
+ end
+
+ context "io is specified" do
+ it_behaves_like :kernel_sprintf, -> format, *args {
+ io = StringIO.new(+"")
+ Kernel.printf(io, format, *args)
+ io.string
+ }
+ end
+
+ context "io is not specified" do
+ it_behaves_like :kernel_sprintf, -> format, *args {
+ stdout = $stdout
+ begin
+ $stdout = io = StringIO.new(+"")
+ Kernel.printf(format, *args)
+ io.string
+ ensure
+ $stdout = stdout
+ end
+ }
+ end
+ end
end
diff --git a/spec/ruby/core/kernel/private_methods_spec.rb b/spec/ruby/core/kernel/private_methods_spec.rb
index d0603c72b8..b0e6d042a9 100644
--- a/spec/ruby/core/kernel/private_methods_spec.rb
+++ b/spec/ruby/core/kernel/private_methods_spec.rb
@@ -1,28 +1,28 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../../../fixtures/reflection', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative '../../fixtures/reflection'
# TODO: rewrite
describe "Kernel#private_methods" do
it "returns a list of the names of privately accessible methods in the object" do
m = KernelSpecs::Methods.private_methods(false)
- m.should include(:shichi)
+ m.should.include?(:shichi)
m = KernelSpecs::Methods.new.private_methods(false)
- m.should include(:juu_shi)
+ m.should.include?(:juu_shi)
end
it "returns a list of the names of privately accessible methods in the object and its ancestors and mixed-in modules" do
m = (KernelSpecs::Methods.private_methods(false) & KernelSpecs::Methods.private_methods)
- m.should include(:shichi)
+ m.should.include?(:shichi)
m = KernelSpecs::Methods.new.private_methods
- m.should include(:juu_shi)
+ m.should.include?(:juu_shi)
end
it "returns private methods mixed in to the metaclass" do
m = KernelSpecs::Methods.new
m.extend(KernelSpecs::Methods::MetaclassMethods)
- m.private_methods.should include(:shoo)
+ m.private_methods.should.include?(:shoo)
end
end
diff --git a/spec/ruby/core/kernel/proc_spec.rb b/spec/ruby/core/kernel/proc_spec.rb
index 4e4854f97d..1ba662177b 100644
--- a/spec/ruby/core/kernel/proc_spec.rb
+++ b/spec/ruby/core/kernel/proc_spec.rb
@@ -1,28 +1,28 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/lambda', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/lambda'
# The functionality of Proc objects is specified in core/proc
describe "Kernel.proc" do
it "is a private method" do
- Kernel.should have_private_instance_method(:proc)
+ Kernel.private_instance_methods(false).should.include?(:proc)
end
it "creates a proc-style Proc if given a literal block" do
l = proc { 42 }
- l.lambda?.should be_false
+ l.lambda?.should == false
end
it "returned the passed Proc if given an existing Proc" do
- some_lambda = lambda {}
- some_lambda.lambda?.should be_true
+ some_lambda = -> {}
+ some_lambda.lambda?.should == true
l = proc(&some_lambda)
- l.should equal(some_lambda)
- l.lambda?.should be_true
+ l.should.equal?(some_lambda)
+ l.lambda?.should == 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
@@ -31,20 +31,18 @@ describe "Kernel.proc" do
@reached_end_of_method = true
end
test
- @reached_end_of_method.should be_nil
+ @reached_end_of_method.should == nil
end
end
describe "Kernel#proc" do
- it "uses the implicit block from an enclosing method" do
- def some_method
- proc
- end
-
- prc = some_method { "hello" }
-
- prc.call.should == "hello"
+ def some_method
+ proc
end
- it "needs to be reviewed for spec completeness"
+ it "raises an ArgumentError when passed no block" do
+ -> {
+ some_method { "hello" }
+ }.should.raise(ArgumentError, 'tried to create Proc object without a block')
+ end
end
diff --git a/spec/ruby/core/kernel/protected_methods_spec.rb b/spec/ruby/core/kernel/protected_methods_spec.rb
index 2e09cead53..aecb9f5ffb 100644
--- a/spec/ruby/core/kernel/protected_methods_spec.rb
+++ b/spec/ruby/core/kernel/protected_methods_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../../../fixtures/reflection', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative '../../fixtures/reflection'
# TODO: rewrite
@@ -8,21 +8,21 @@ require File.expand_path('../../../fixtures/reflection', __FILE__)
# You should use have_protected_method() with the exception of this spec.
describe "Kernel#protected_methods" do
it "returns a list of the names of protected methods accessible in the object" do
- KernelSpecs::Methods.protected_methods(false).sort.should include(:juu_ichi)
- KernelSpecs::Methods.new.protected_methods(false).should include(:ku)
+ KernelSpecs::Methods.protected_methods(false).sort.should.include?(:juu_ichi)
+ KernelSpecs::Methods.new.protected_methods(false).should.include?(:ku)
end
it "returns a list of the names of protected methods accessible in the object and from its ancestors and mixed-in modules" do
l1 = KernelSpecs::Methods.protected_methods(false)
l2 = KernelSpecs::Methods.protected_methods
- (l1 & l2).should include(:juu_ichi)
- KernelSpecs::Methods.new.protected_methods.should include(:ku)
+ (l1 & l2).should.include?(:juu_ichi)
+ KernelSpecs::Methods.new.protected_methods.should.include?(:ku)
end
it "returns methods mixed in to the metaclass" do
m = KernelSpecs::Methods.new
m.extend(KernelSpecs::Methods::MetaclassMethods)
- m.protected_methods.should include(:nopeeking)
+ m.protected_methods.should.include?(:nopeeking)
end
end
diff --git a/spec/ruby/core/kernel/public_method_spec.rb b/spec/ruby/core/kernel/public_method_spec.rb
index f1cc168420..42b8f797d3 100644
--- a/spec/ruby/core/kernel/public_method_spec.rb
+++ b/spec/ruby/core/kernel/public_method_spec.rb
@@ -1,9 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/method', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/method'
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
@@ -11,22 +11,22 @@ describe "Kernel#public_method" do
it "raises a NameError when called on a private method" do
@obj.send(:private_method).should == :private_method
- lambda do
+ -> do
@obj.public_method(:private_method)
- end.should raise_error(NameError)
+ end.should.raise(NameError)
end
it "raises a NameError when called on a protected method" do
@obj.send(:protected_method).should == :protected_method
- lambda {
+ -> {
@obj.public_method(:protected_method)
- }.should raise_error(NameError)
+ }.should.raise(NameError)
end
it "raises a NameError if we only repond_to_missing? method, true" do
obj = KernelSpecs::RespondViaMissing.new
- lambda do
+ -> do
obj.public_method(:handled_privately)
- end.should raise_error(NameError)
+ end.should.raise(NameError)
end
end
diff --git a/spec/ruby/core/kernel/public_methods_spec.rb b/spec/ruby/core/kernel/public_methods_spec.rb
index b72775483c..e334ac9a55 100644
--- a/spec/ruby/core/kernel/public_methods_spec.rb
+++ b/spec/ruby/core/kernel/public_methods_spec.rb
@@ -1,35 +1,34 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../../../fixtures/reflection', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative '../../fixtures/reflection'
# TODO: rewrite
describe "Kernel#public_methods" do
it "returns a list of the names of publicly accessible methods in the object" do
- KernelSpecs::Methods.public_methods(false).sort.should include(:hachi,
- :ichi, :juu, :juu_ni, :roku, :san, :shi)
- KernelSpecs::Methods.new.public_methods(false).sort.should include(:juu_san, :ni)
+ KernelSpecs::Methods.public_methods(false).to_set.should >= Set[:hachi, :ichi, :juu, :juu_ni, :roku, :san, :shi]
+ KernelSpecs::Methods.new.public_methods(false).to_set.should >= Set[:juu_san, :ni]
end
it "returns a list of names without protected accessible methods in the object" do
- KernelSpecs::Methods.public_methods(false).sort.should_not include(:juu_ichi)
- KernelSpecs::Methods.new.public_methods(false).sort.should_not include(:ku)
+ KernelSpecs::Methods.public_methods(false).sort.should_not.include?(:juu_ichi)
+ KernelSpecs::Methods.new.public_methods(false).sort.should_not.include?(:ku)
end
it "returns a list of the names of publicly accessible methods in the object and its ancestors and mixed-in modules" do
- (KernelSpecs::Methods.public_methods(false) & KernelSpecs::Methods.public_methods).sort.should include(
- :hachi, :ichi, :juu, :juu_ni, :roku, :san, :shi)
+ (KernelSpecs::Methods.public_methods(false) & KernelSpecs::Methods.public_methods).to_set.should >= Set[
+ :hachi, :ichi, :juu, :juu_ni, :roku, :san, :shi]
m = KernelSpecs::Methods.new.public_methods
- m.should include(:ni, :juu_san)
+ m.to_set.should >= Set[:ni, :juu_san]
end
it "returns methods mixed in to the metaclass" do
m = KernelSpecs::Methods.new
m.extend(KernelSpecs::Methods::MetaclassMethods)
- m.public_methods.should include(:peekaboo)
+ m.public_methods.should.include?(:peekaboo)
end
it "returns public methods for immediates" do
- 10.public_methods.should include(:divmod)
+ 10.public_methods.should.include?(:divmod)
end
end
diff --git a/spec/ruby/core/kernel/public_send_spec.rb b/spec/ruby/core/kernel/public_send_spec.rb
index 2eabbc7dc9..6a4a969c77 100644
--- a/spec/ruby/core/kernel/public_send_spec.rb
+++ b/spec/ruby/core/kernel/public_send_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../../../shared/basicobject/send', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative '../../shared/basicobject/send'
describe "Kernel#public_send" do
it "invokes the named public method" do
@@ -29,7 +29,7 @@ describe "Kernel#public_send" do
'done'
end
end
- lambda { KernelSpecs::Foo.new.public_send(:bar)}.should raise_error(NoMethodError)
+ -> { KernelSpecs::Foo.new.public_send(:bar)}.should.raise(NoMethodError)
end
it "raises a NoMethodError if the named method is private" do
@@ -39,9 +39,9 @@ describe "Kernel#public_send" do
'done2'
end
end
- lambda {
+ -> {
KernelSpecs::Foo.new.public_send(:bar)
- }.should raise_error(NoMethodError)
+ }.should.raise(NoMethodError)
end
context 'called from own public method' do
@@ -70,11 +70,11 @@ describe "Kernel#public_send" do
end
it "raises a NoMethodError if the method is protected" do
- lambda { @receiver.call_protected_method }.should raise_error(NoMethodError)
+ -> { @receiver.call_protected_method }.should.raise(NoMethodError)
end
it "raises a NoMethodError if the method is private" do
- lambda { @receiver.call_private_method }.should raise_error(NoMethodError)
+ -> { @receiver.call_private_method }.should.raise(NoMethodError)
end
end
@@ -86,9 +86,9 @@ describe "Kernel#public_send" do
end
alias :aka :bar
end
- lambda {
+ -> {
KernelSpecs::Foo.new.public_send(:aka)
- }.should raise_error(NoMethodError)
+ }.should.raise(NoMethodError)
end
it "raises a NoMethodError if the named method is an alias of a protected method" do
@@ -99,10 +99,18 @@ describe "Kernel#public_send" do
end
alias :aka :bar
end
- lambda {
+ -> {
KernelSpecs::Foo.new.public_send(:aka)
- }.should raise_error(NoMethodError)
+ }.should.raise(NoMethodError)
end
- it_behaves_like(:basicobject_send, :public_send)
+ it "includes `public_send` in the backtrace when passed not enough arguments" do
+ -> { public_send() }.should.raise(ArgumentError) { |e| e.backtrace[0].should =~ /[`'](?:Kernel#)?public_send'/ }
+ end
+
+ it "includes `public_send` in the backtrace when passed a single incorrect argument" do
+ -> { public_send(Object.new) }.should.raise(TypeError) { |e| e.backtrace[0].should =~ /[`'](?:Kernel#)?public_send'/ }
+ end
+
+ it_behaves_like :basicobject_send, :public_send
end
diff --git a/spec/ruby/core/kernel/putc_spec.rb b/spec/ruby/core/kernel/putc_spec.rb
index 1f5e9b6d63..e6a20a9af1 100644
--- a/spec/ruby/core/kernel/putc_spec.rb
+++ b/spec/ruby/core/kernel/putc_spec.rb
@@ -1,10 +1,10 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../../../shared/io/putc', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative '../../shared/io/putc'
describe "Kernel#putc" do
it "is a private instance method" do
- Kernel.should have_private_instance_method(:putc)
+ Kernel.private_instance_methods(false).should.include?(:putc)
end
end
diff --git a/spec/ruby/core/kernel/puts_spec.rb b/spec/ruby/core/kernel/puts_spec.rb
index c5297f1cb2..eed18fcd50 100644
--- a/spec/ruby/core/kernel/puts_spec.rb
+++ b/spec/ruby/core/kernel/puts_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Kernel#puts" do
before :each do
@@ -15,7 +15,7 @@ describe "Kernel#puts" do
end
it "is a private method" do
- Kernel.should have_private_instance_method(:puts)
+ Kernel.private_instance_methods(false).should.include?(:puts)
end
it "delegates to $stdout.puts" do
diff --git a/spec/ruby/core/kernel/raise_spec.rb b/spec/ruby/core/kernel/raise_spec.rb
index 6efffd9366..6162677e17 100644
--- a/spec/ruby/core/kernel/raise_spec.rb
+++ b/spec/ruby/core/kernel/raise_spec.rb
@@ -1,17 +1,222 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../../../shared/kernel/raise', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative '../../shared/kernel/raise'
describe "Kernel#raise" do
it "is a private method" do
- Kernel.should have_private_instance_method(:raise)
+ Kernel.private_instance_methods.should.include?(:raise)
end
+
+ # Shared specs expect a public #raise method.
+ public_raiser = Object.new
+ class << public_raiser
+ public :raise
+ end
+ it_behaves_like :kernel_raise, :raise, public_raiser
+ it_behaves_like :kernel_raise_with_cause, :raise, public_raiser
end
-describe "Kernel#raise" do
- it_behaves_like :kernel_raise, :raise, Kernel
+describe "Kernel#raise with previously rescued exception" do
+ it "re-raises the previously rescued exception if no exception is specified" do
+ ScratchPad.record nil
+
+ -> do
+ begin
+ raise Exception, "outer"
+ ScratchPad.record :no_abort
+ rescue Exception
+ begin
+ raise StandardError, "inner"
+ rescue StandardError
+ end
+
+ raise
+ ScratchPad.record :no_reraise
+ end
+ end.should.raise(Exception, "outer")
+
+ ScratchPad.recorded.should == nil
+ end
+
+ it "re-raises a previously rescued exception without overwriting the cause" do
+ begin
+ begin
+ begin
+ begin
+ raise "Error 1"
+ rescue => e1
+ raise "Error 2"
+ end
+ rescue => e2
+ raise "Error 3"
+ end
+ rescue
+ e2.cause.should == e1
+ raise e2
+ end
+ rescue => e
+ e.cause.should == e1
+ end
+ end
+
+ it "re-raises a previously rescued exception with overwriting the cause when it's explicitly specified with :cause option" do
+ e4 = RuntimeError.new("Error 4")
+
+ begin
+ begin
+ begin
+ begin
+ raise "Error 1"
+ rescue => e1
+ raise "Error 2"
+ end
+ rescue => e2
+ raise "Error 3"
+ end
+ rescue
+ e2.cause.should == e1
+ raise e2, cause: e4
+ end
+ rescue => e
+ e.cause.should == e4
+ end
+ end
+
+ it "re-raises a previously rescued exception without overwriting the cause when it's explicitly specified with :cause option and has nil value" do
+ begin
+ begin
+ begin
+ begin
+ raise "Error 1"
+ rescue => e1
+ raise "Error 2"
+ end
+ rescue => e2
+ raise "Error 3"
+ end
+ rescue
+ e2.cause.should == e1
+ raise e2, cause: nil
+ end
+ rescue => e
+ e.cause.should == e1
+ end
+ end
+
+ it "re-raises a previously rescued exception without setting a cause implicitly" do
+ begin
+ begin
+ raise "Error 1"
+ rescue => e1
+ raise
+ end
+ rescue => e
+ e.should == e1
+ e.cause.should == nil
+ end
+ end
+
+ it "re-raises a previously rescued exception that has a cause without setting a cause implicitly" do
+ begin
+ begin
+ raise "Error 1"
+ rescue => e1
+ begin
+ raise "Error 2"
+ rescue => e2
+ raise
+ end
+ end
+ rescue => e
+ e.should == e2
+ e.cause.should == e1
+ end
+ end
+
+ it "re-raises a previously rescued exception that doesn't have a cause and isn't a cause of any other exception with setting a cause implicitly" do
+ begin
+ begin
+ raise "Error 1"
+ rescue => e1
+ begin
+ raise "Error 2"
+ rescue => e2
+ raise "Error 3"
+ end
+ end
+ rescue => e
+ e.message.should == "Error 3"
+ e.cause.should == e2
+ end
+ end
+
+ it "re-raises a previously rescued exception that doesn't have a cause and is a cause of other exception without setting a cause implicitly" do
+ begin
+ begin
+ raise "Error 1"
+ rescue => e1
+ begin
+ raise "Error 2"
+ rescue => e2
+ e1.cause.should == nil
+ e2.cause.should == e1
+ raise e1
+ end
+ end
+ rescue => e
+ e.should == e1
+ e.cause.should == nil
+ end
+ end
+
+ it "re-raises a previously rescued exception that doesn't have a cause and is a cause of other exception (that wasn't raised explicitly) without setting a cause implicitly" do
+ begin
+ begin
+ raise "Error 1"
+ rescue => e1
+ begin
+ foo # raises NameError
+ rescue => e2
+ e1.cause.should == nil
+ e2.cause.should == e1
+ raise e1
+ end
+ end
+ rescue => e
+ e.should == e1
+ e.cause.should == nil
+ end
+ end
+
+ it "re-raises a previously rescued exception that has a cause but isn't a cause of any other exception without setting a cause implicitly" do
+ begin
+ begin
+ raise "Error 1"
+ rescue => e1
+ begin
+ raise "Error 2"
+ rescue => e2
+ begin
+ raise "Error 3", cause: RuntimeError.new("Error 4")
+ rescue => e3
+ e2.cause.should == e1
+ e3.cause.should_not == e2
+ raise e2
+ end
+ end
+ end
+ rescue => e
+ e.should == e2
+ e.cause.should == e1
+ end
+ end
end
describe "Kernel.raise" do
- it "needs to be reviewed for spec completeness"
+ it "is a public method" do
+ Kernel.singleton_class.should.public_method_defined?(:raise)
+ end
+
+ it_behaves_like :kernel_raise, :raise, Kernel
+ it_behaves_like :kernel_raise_with_cause, :raise, Kernel
end
diff --git a/spec/ruby/core/kernel/rand_spec.rb b/spec/ruby/core/kernel/rand_spec.rb
index f52b5f75b5..1bf5e225d9 100644
--- a/spec/ruby/core/kernel/rand_spec.rb
+++ b/spec/ruby/core/kernel/rand_spec.rb
@@ -1,44 +1,44 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
-describe "Kernel.rand" do
+describe "Kernel#rand" do
it "is a private method" do
- Kernel.should have_private_instance_method(:rand)
+ Kernel.private_instance_methods(false).should.include?(:rand)
end
it "returns a float if no argument is passed" do
- rand.should be_kind_of(Float)
+ rand.should.is_a?(Float)
end
it "returns an integer for an integer argument" do
- rand(77).should be_kind_of(Integer)
+ rand(77).should.is_a?(Integer)
end
it "returns an integer for a float argument greater than 1" do
- rand(1.3).should be_kind_of(Integer)
+ rand(1.3).should.is_a?(Integer)
end
it "returns a float for an argument between -1 and 1" do
- rand(-0.999).should be_kind_of(Float)
- rand(-0.01).should be_kind_of(Float)
- rand(0).should be_kind_of(Float)
- rand(0.01).should be_kind_of(Float)
- rand(0.999).should be_kind_of(Float)
+ rand(-0.999).should.is_a?(Float)
+ rand(-0.01).should.is_a?(Float)
+ rand(0).should.is_a?(Float)
+ rand(0.01).should.is_a?(Float)
+ rand(0.999).should.is_a?(Float)
end
it "ignores the sign of the argument" do
- [0, 1, 2, 3].should include(rand(-4))
+ [0, 1, 2, 3].should.include?(rand(-4))
end
it "never returns a value greater or equal to 1.0 with no arguments" do
1000.times do
- (0...1.0).should include(rand)
+ (0...1.0).should.include?(rand)
end
end
it "never returns a value greater or equal to any passed in max argument" do
1000.times do
- (0...100).to_a.should include(rand(100))
+ (0...100).to_a.should.include?(rand(100))
end
end
@@ -53,32 +53,32 @@ describe "Kernel.rand" do
it "returns an Integer between the two Integers" do
1000.times do
x = rand(4...6)
- x.should be_kind_of(Integer)
- (4...6).should include(x)
+ x.should.is_a?(Integer)
+ (4...6).should.include?(x)
end
end
it "returns a Float between the given Integer and Float" do
1000.times do
x = rand(4...6.5)
- x.should be_kind_of(Float)
- (4...6.5).should include(x)
+ x.should.is_a?(Float)
+ (4...6.5).should.include?(x)
end
end
it "returns a Float between the given Float and Integer" do
1000.times do
x = rand(3.5...6)
- x.should be_kind_of(Float)
- (3.5...6).should include(x)
+ x.should.is_a?(Float)
+ (3.5...6).should.include?(x)
end
end
it "returns a Float between the two given Floats" do
1000.times do
x = rand(3.5...6.5)
- x.should be_kind_of(Float)
- (3.5...6.5).should include(x)
+ x.should.is_a?(Float)
+ (3.5...6.5).should.include?(x)
end
end
end
@@ -87,53 +87,111 @@ describe "Kernel.rand" do
it "returns an Integer between the two Integers" do
1000.times do
x = rand(4..6)
- x.should be_kind_of(Integer)
- (4..6).should include(x)
+ x.should.is_a?(Integer)
+ (4..6).should.include?(x)
end
end
it "returns a Float between the given Integer and Float" do
1000.times do
x = rand(4..6.5)
- x.should be_kind_of(Float)
- (4..6.5).should include(x)
+ x.should.is_a?(Float)
+ (4..6.5).should.include?(x)
end
end
it "returns a Float between the given Float and Integer" do
1000.times do
x = rand(3.5..6)
- x.should be_kind_of(Float)
- (3.5..6).should include(x)
+ x.should.is_a?(Float)
+ (3.5..6).should.include?(x)
end
end
it "returns a Float between the two given Floats" do
1000.times do
x = rand(3.5..6.5)
- x.should be_kind_of(Float)
- (3.5..6.5).should include(x)
+ x.should.is_a?(Float)
+ (3.5..6.5).should.include?(x)
end
end
end
+ context "given an inclusive range between 0 and 1" do
+ it "returns an Integer between the two Integers" do
+ x = rand(0..1)
+ x.should.is_a?(Integer)
+ (0..1).should.include?(x)
+ end
+
+ it "returns a Float if at least one side is Float" do
+ seed = 42
+ x1 = Random.new(seed).rand(0..1.0)
+ x2 = Random.new(seed).rand(0.0..1.0)
+ x3 = Random.new(seed).rand(0.0..1)
+
+ x3.should.is_a?(Float)
+ x1.should.eql?(x3)
+ x2.should.eql?(x3)
+
+ (0.0..1.0).should.include?(x3)
+ end
+ end
+
+ context "given an exclusive range between 0 and 1" do
+ it "returns zero as an Integer" do
+ x = rand(0...1)
+ x.should.is_a?(Integer)
+ x.should.eql?(0)
+ end
+
+ it "returns a Float if at least one side is Float" do
+ seed = 42
+ x1 = Random.new(seed).rand(0...1.0)
+ x2 = Random.new(seed).rand(0.0...1.0)
+ x3 = Random.new(seed).rand(0.0...1)
+
+ x3.should.is_a?(Float)
+ x1.should.eql?(x3)
+ x2.should.eql?(x3)
+
+ (0.0...1.0).should.include?(x3)
+ end
+ end
+
it "returns a numeric for an range argument where max is < 1" do
- rand(0.25..0.75).should be_kind_of(Numeric)
+ rand(0.25..0.75).should.is_a?(Numeric)
end
it "returns nil when range is backwards" do
- rand(1..0).should be_nil
+ rand(1..0).should == nil
end
it "returns the range start/end when Float range is 0" do
- rand(1.0..1.0).should eql(1.0)
+ rand(1.0..1.0).should.eql?(1.0)
end
it "returns the range start/end when Integer range is 0" do
- rand(42..42).should eql(42)
+ rand(42..42).should.eql?(42)
+ end
+
+ it "supports custom object types" do
+ rand(KernelSpecs::CustomRangeInteger.new(1)..KernelSpecs::CustomRangeInteger.new(42)).should.instance_of?(KernelSpecs::CustomRangeInteger)
+ rand(KernelSpecs::CustomRangeFloat.new(1.0)..KernelSpecs::CustomRangeFloat.new(42.0)).should.instance_of?(KernelSpecs::CustomRangeFloat)
+ rand(Time.now..Time.now).should.instance_of?(Time)
+ end
+
+ it "is random on boot" do
+ results = 2.times.map {
+ out = ruby_exe('p rand', options: '--disable-gems')
+ Float(out)
+ }
+ results.size.should == 2
+ # this is technically flaky, but very unlikely in a good distribution
+ results[0].should_not == results[1]
end
end
-describe "Kernel#rand" do
+describe "Kernel.rand" do
it "needs to be reviewed for spec completeness"
end
diff --git a/spec/ruby/core/kernel/readline_spec.rb b/spec/ruby/core/kernel/readline_spec.rb
index c69eee0726..86899d78d2 100644
--- a/spec/ruby/core/kernel/readline_spec.rb
+++ b/spec/ruby/core/kernel/readline_spec.rb
@@ -1,9 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Kernel#readline" do
it "is a private method" do
- Kernel.should have_private_instance_method(:readline)
+ Kernel.private_instance_methods(false).should.include?(:readline)
end
end
diff --git a/spec/ruby/core/kernel/readlines_spec.rb b/spec/ruby/core/kernel/readlines_spec.rb
index d5e07f8f75..c758014aab 100644
--- a/spec/ruby/core/kernel/readlines_spec.rb
+++ b/spec/ruby/core/kernel/readlines_spec.rb
@@ -1,9 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Kernel#readlines" do
it "is a private method" do
- Kernel.should have_private_instance_method(:readlines)
+ Kernel.private_instance_methods(false).should.include?(:readlines)
end
end
diff --git a/spec/ruby/core/kernel/remove_instance_variable_spec.rb b/spec/ruby/core/kernel/remove_instance_variable_spec.rb
index 6a9f78b9bc..114536064f 100644
--- a/spec/ruby/core/kernel/remove_instance_variable_spec.rb
+++ b/spec/ruby/core/kernel/remove_instance_variable_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe :kernel_remove_instance_variable, shared: true do
it "returns the instance variable's value" do
@@ -9,7 +9,7 @@ describe :kernel_remove_instance_variable, shared: true do
it "removes the instance variable" do
@instance.send :remove_instance_variable, @object
- @instance.instance_variable_defined?(@object).should be_false
+ @instance.instance_variable_defined?(@object).should == false
end
end
@@ -19,26 +19,39 @@ describe "Kernel#remove_instance_variable" do
end
it "is a public method" do
- Kernel.should have_public_instance_method(:remove_instance_variable, false)
+ Kernel.public_instance_methods(false).should.include?(:remove_instance_variable)
end
it "raises a NameError if the instance variable is not defined" do
- lambda do
+ -> do
@instance.send :remove_instance_variable, :@unknown
- end.should raise_error(NameError)
+ end.should.raise(NameError)
end
it "raises a NameError if the argument is not a valid instance variable name" do
- lambda do
+ -> do
@instance.send :remove_instance_variable, :"@0"
- end.should raise_error(NameError)
+ end.should.raise(NameError)
end
it "raises a TypeError if passed an Object not defining #to_str" do
- lambda do
+ -> do
obj = mock("kernel remove_instance_variable")
@instance.send :remove_instance_variable, obj
- end.should raise_error(TypeError)
+ end.should.raise(TypeError)
+ end
+
+ it "raises a FrozenError if self is frozen" do
+ o = Object.new
+ o.freeze
+ -> { o.remove_instance_variable(:@foo) }.should.raise(FrozenError)
+ -> { o.remove_instance_variable(:foo) }.should.raise(NameError)
+ end
+
+ it "raises for frozen objects" do
+ -> { nil.remove_instance_variable(:@foo) }.should.raise(FrozenError)
+ -> { nil.remove_instance_variable(:foo) }.should.raise(NameError)
+ -> { :foo.remove_instance_variable(:@foo) }.should.raise(FrozenError)
end
describe "when passed a String" do
diff --git a/spec/ruby/core/kernel/require_relative_spec.rb b/spec/ruby/core/kernel/require_relative_spec.rb
index 04cf5444d2..b3ac1fc64c 100644
--- a/spec/ruby/core/kernel/require_relative_spec.rb
+++ b/spec/ruby/core/kernel/require_relative_spec.rb
@@ -1,15 +1,13 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../fixtures/code_loading', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../../fixtures/code_loading'
describe "Kernel#require_relative with a relative path" do
- it "needs to be reviewed for spec completeness"
-
before :each do
CodeLoadingSpecs.spec_setup
@dir = "../../fixtures/code"
- @abs_dir = File.realpath(@dir, File.dirname(__FILE__))
+ @abs_dir = File.realpath(@dir, __dir__)
@path = "#{@dir}/load_fixture.rb"
- @abs_path = File.realpath(@path, File.dirname(__FILE__))
+ @abs_path = File.realpath(@path, __dir__)
end
after :each do
@@ -29,72 +27,124 @@ describe "Kernel#require_relative with a relative path" do
end
it "loads a path relative to current file" do
- require_relative(@link).should be_true
+ require_relative(@link).should == true
ScratchPad.recorded.should == [:loaded]
end
end
end
it "loads a path relative to the current file" do
- require_relative(@path).should be_true
+ require_relative(@path).should == true
ScratchPad.recorded.should == [:loaded]
end
+ describe "in an #instance_eval with a" do
+
+ it "synthetic file base name loads a file base name relative to the working directory" do
+ Dir.chdir @abs_dir do
+ Object.new.instance_eval("require_relative(#{File.basename(@path).inspect})", "foo.rb").should == true
+ end
+ ScratchPad.recorded.should == [:loaded]
+ end
+
+ it "synthetic file path loads a relative path relative to the working directory plus the directory of the synthetic path" do
+ Dir.chdir @abs_dir do
+ Object.new.instance_eval("require_relative(File.join('..', #{File.basename(@path).inspect}))", "bar/foo.rb").should == true
+ end
+ ScratchPad.recorded.should == [:loaded]
+ end
+
+ platform_is_not :windows do
+ it "synthetic relative file path with a Windows path separator specified loads a relative path relative to the working directory" do
+ Dir.chdir @abs_dir do
+ Object.new.instance_eval("require_relative(#{File.basename(@path).inspect})", "bar\\foo.rb").should == true
+ end
+ ScratchPad.recorded.should == [:loaded]
+ end
+ end
+
+ it "absolute file path loads a path relative to the absolute path" do
+ Object.new.instance_eval("require_relative(#{@path.inspect})", __FILE__).should == true
+ ScratchPad.recorded.should == [:loaded]
+ end
+
+ it "absolute file path loads a path relative to the root directory" do
+ root = @abs_path
+ until File.dirname(root) == root
+ root = File.dirname(root)
+ end
+ root_relative = @abs_path[root.size..-1]
+ Object.new.instance_eval("require_relative(#{root_relative.inspect})", "/").should == true
+ ScratchPad.recorded.should == [:loaded]
+ end
+
+ end
+
it "loads a file defining many methods" do
- require_relative("#{@dir}/methods_fixture.rb").should be_true
+ require_relative("#{@dir}/methods_fixture.rb").should == true
ScratchPad.recorded.should == [:loaded]
end
it "raises a LoadError if the file does not exist" do
- lambda { require_relative("#{@dir}/nonexistent.rb") }.should raise_error(LoadError)
+ -> { require_relative("#{@dir}/nonexistent.rb") }.should.raise(LoadError)
+ ScratchPad.recorded.should == []
+ end
+
+ it "raises a LoadError that includes the missing path" do
+ missing_path = "#{@dir}/nonexistent.rb"
+ expanded_missing_path = File.expand_path(missing_path, __dir__)
+ -> { require_relative(missing_path) }.should.raise(LoadError) { |e|
+ e.message.should.include?(expanded_missing_path)
+ e.path.should == expanded_missing_path
+ }
ScratchPad.recorded.should == []
end
it "raises a LoadError if basepath does not exist" do
- lambda { eval("require_relative('#{@dir}/nonexistent.rb')") }.should raise_error(LoadError)
+ -> { eval("require_relative('#{@dir}/nonexistent.rb')") }.should.raise(LoadError)
end
it "stores the missing path in a LoadError object" do
path = "#{@dir}/nonexistent.rb"
- lambda {
+ -> {
require_relative(path)
- }.should(raise_error(LoadError) { |e|
+ }.should.raise(LoadError) { |e|
e.path.should == File.expand_path(path, @abs_dir)
- })
+ }
end
it "calls #to_str on non-String objects" do
name = mock("load_fixture.rb mock")
name.should_receive(:to_str).and_return(@path)
- require_relative(name).should be_true
+ require_relative(name).should == true
ScratchPad.recorded.should == [:loaded]
end
it "raises a TypeError if argument does not respond to #to_str" do
- lambda { require_relative(nil) }.should raise_error(TypeError)
- lambda { require_relative(42) }.should raise_error(TypeError)
- lambda {
+ -> { require_relative(nil) }.should.raise(TypeError)
+ -> { require_relative(42) }.should.raise(TypeError)
+ -> {
require_relative([@path,@path])
- }.should raise_error(TypeError)
+ }.should.raise(TypeError)
end
it "raises a TypeError if passed an object that has #to_s but not #to_str" do
name = mock("load_fixture.rb mock")
name.stub!(:to_s).and_return(@path)
- lambda { require_relative(name) }.should raise_error(TypeError)
+ -> { require_relative(name) }.should.raise(TypeError)
end
it "raises a TypeError if #to_str does not return a String" do
name = mock("#to_str returns nil")
name.should_receive(:to_str).at_least(1).times.and_return(nil)
- lambda { require_relative(name) }.should raise_error(TypeError)
+ -> { require_relative(name) }.should.raise(TypeError)
end
it "calls #to_path on non-String objects" do
name = mock("load_fixture.rb mock")
name.should_receive(:to_path).and_return(@path)
- require_relative(name).should be_true
+ require_relative(name).should == true
ScratchPad.recorded.should == [:loaded]
end
@@ -103,13 +153,13 @@ describe "Kernel#require_relative with a relative path" do
to_path = mock("load_fixture_rb #to_path mock")
name.should_receive(:to_path).and_return(to_path)
to_path.should_receive(:to_str).and_return(@path)
- require_relative(name).should be_true
+ require_relative(name).should == true
ScratchPad.recorded.should == [:loaded]
end
describe "(file extensions)" do
it "loads a .rb extensioned file when passed a non-extensioned path" do
- require_relative("#{@dir}/load_fixture").should be_true
+ require_relative("#{@dir}/load_fixture").should == true
ScratchPad.recorded.should == [:loaded]
end
@@ -118,20 +168,20 @@ describe "Kernel#require_relative with a relative path" do
$LOADED_FEATURES << "#{@abs_dir}/load_fixture.dylib"
$LOADED_FEATURES << "#{@abs_dir}/load_fixture.so"
$LOADED_FEATURES << "#{@abs_dir}/load_fixture.dll"
- require_relative(@path).should be_true
+ require_relative(@path).should == true
ScratchPad.recorded.should == [:loaded]
end
it "does not load a C-extension file if a .rb extensioned file is already loaded" do
$LOADED_FEATURES << "#{@abs_dir}/load_fixture.rb"
- require_relative("#{@dir}/load_fixture").should be_false
+ require_relative("#{@dir}/load_fixture").should == false
ScratchPad.recorded.should == []
end
it "loads a .rb extensioned file when passed a non-.rb extensioned path" do
- require_relative("#{@dir}/load_fixture.ext").should be_true
+ require_relative("#{@dir}/load_fixture.ext").should == true
ScratchPad.recorded.should == [:loaded]
- $LOADED_FEATURES.should include "#{@abs_dir}/load_fixture.ext.rb"
+ $LOADED_FEATURES.should.include? "#{@abs_dir}/load_fixture.ext.rb"
end
it "loads a .rb extensioned file when a complex-extensioned C-extension file of the same name is loaded" do
@@ -139,57 +189,95 @@ describe "Kernel#require_relative with a relative path" do
$LOADED_FEATURES << "#{@abs_dir}/load_fixture.ext.dylib"
$LOADED_FEATURES << "#{@abs_dir}/load_fixture.ext.so"
$LOADED_FEATURES << "#{@abs_dir}/load_fixture.ext.dll"
- require_relative("#{@dir}/load_fixture.ext").should be_true
+ require_relative("#{@dir}/load_fixture.ext").should == true
ScratchPad.recorded.should == [:loaded]
- $LOADED_FEATURES.should include "#{@abs_dir}/load_fixture.ext.rb"
+ $LOADED_FEATURES.should.include? "#{@abs_dir}/load_fixture.ext.rb"
end
it "does not load a C-extension file if a complex-extensioned .rb file is already loaded" do
$LOADED_FEATURES << "#{@abs_dir}/load_fixture.ext.rb"
- require_relative("#{@dir}/load_fixture.ext").should be_false
+ require_relative("#{@dir}/load_fixture.ext").should == false
ScratchPad.recorded.should == []
end
end
describe "($LOADED_FEATURES)" do
it "stores an absolute path" do
- require_relative(@path).should be_true
- $LOADED_FEATURES.should include(@abs_path)
+ require_relative(@path).should == true
+ $LOADED_FEATURES.should.include?(@abs_path)
+ end
+
+ platform_is_not :windows, :wasi do
+ describe "with symlinks" do
+ before :each do
+ @symlink_to_code_dir = tmp("codesymlink")
+ File.symlink(CODE_LOADING_DIR, @symlink_to_code_dir)
+ @symlink_basename = File.basename(@symlink_to_code_dir)
+ @requiring_file = tmp("requiring")
+ end
+
+ after :each do
+ rm_r @symlink_to_code_dir, @requiring_file
+ end
+
+ it "does not canonicalize the path and stores a path with symlinks" do
+ symlink_path = "#{@symlink_basename}/load_fixture.rb"
+ absolute_path = "#{tmp("")}#{symlink_path}"
+ canonical_path = "#{CODE_LOADING_DIR}/load_fixture.rb"
+ touch(@requiring_file) { |f|
+ f.puts "require_relative #{symlink_path.inspect}"
+ }
+ load(@requiring_file)
+ ScratchPad.recorded.should == [:loaded]
+
+ features = $LOADED_FEATURES.select { |path| path.end_with?('load_fixture.rb') }
+ features.should.include?(absolute_path)
+ features.should_not.include?(canonical_path)
+ end
+
+ it "stores the same path that __FILE__ returns in the required file" do
+ symlink_path = "#{@symlink_basename}/load_fixture_and__FILE__.rb"
+ touch(@requiring_file) { |f|
+ f.puts "require_relative #{symlink_path.inspect}"
+ }
+ load(@requiring_file)
+ loaded_feature = $LOADED_FEATURES.last
+ ScratchPad.recorded.should == [loaded_feature]
+ end
+ end
end
it "does not store the path if the load fails" do
saved_loaded_features = $LOADED_FEATURES.dup
- lambda { require_relative("#{@dir}/raise_fixture.rb") }.should raise_error(RuntimeError)
+ -> { require_relative("#{@dir}/raise_fixture.rb") }.should.raise(RuntimeError)
$LOADED_FEATURES.should == saved_loaded_features
end
it "does not load an absolute path that is already stored" do
$LOADED_FEATURES << @abs_path
- require_relative(@path).should be_false
+ require_relative(@path).should == false
ScratchPad.recorded.should == []
end
it "adds the suffix of the resolved filename" do
- require_relative("#{@dir}/load_fixture").should be_true
- $LOADED_FEATURES.should include("#{@abs_dir}/load_fixture.rb")
+ require_relative("#{@dir}/load_fixture").should == true
+ $LOADED_FEATURES.should.include?("#{@abs_dir}/load_fixture.rb")
end
it "loads a path for a file already loaded with a relative path" do
$LOAD_PATH << File.expand_path(@dir)
$LOADED_FEATURES << "load_fixture.rb" << "load_fixture"
- require_relative(@path).should be_true
- $LOADED_FEATURES.should include(@abs_path)
+ require_relative(@path).should == true
+ $LOADED_FEATURES.should.include?(@abs_path)
ScratchPad.recorded.should == [:loaded]
end
end
end
describe "Kernel#require_relative with an absolute path" do
- it "needs to be reviewed for spec completeness"
-
before :each do
CodeLoadingSpecs.spec_setup
- @dir = File.expand_path "../../fixtures/code", File.dirname(__FILE__)
+ @dir = File.expand_path "../../fixtures/code", __dir__
@abs_dir = @dir
@path = File.join @dir, "load_fixture.rb"
@abs_path = @path
@@ -200,65 +288,65 @@ describe "Kernel#require_relative with an absolute path" do
end
it "loads a path relative to the current file" do
- require_relative(@path).should be_true
+ require_relative(@path).should == true
ScratchPad.recorded.should == [:loaded]
end
it "loads a file defining many methods" do
- require_relative("#{@dir}/methods_fixture.rb").should be_true
+ require_relative("#{@dir}/methods_fixture.rb").should == true
ScratchPad.recorded.should == [:loaded]
end
it "raises a LoadError if the file does not exist" do
- lambda { require_relative("#{@dir}/nonexistent.rb") }.should raise_error(LoadError)
+ -> { require_relative("#{@dir}/nonexistent.rb") }.should.raise(LoadError)
ScratchPad.recorded.should == []
end
it "raises a LoadError if basepath does not exist" do
- lambda { eval("require_relative('#{@dir}/nonexistent.rb')") }.should raise_error(LoadError)
+ -> { eval("require_relative('#{@dir}/nonexistent.rb')") }.should.raise(LoadError)
end
it "stores the missing path in a LoadError object" do
path = "#{@dir}/nonexistent.rb"
- lambda {
+ -> {
require_relative(path)
- }.should(raise_error(LoadError) { |e|
+ }.should.raise(LoadError) { |e|
e.path.should == File.expand_path(path, @abs_dir)
- })
+ }
end
it "calls #to_str on non-String objects" do
name = mock("load_fixture.rb mock")
name.should_receive(:to_str).and_return(@path)
- require_relative(name).should be_true
+ require_relative(name).should == true
ScratchPad.recorded.should == [:loaded]
end
it "raises a TypeError if argument does not respond to #to_str" do
- lambda { require_relative(nil) }.should raise_error(TypeError)
- lambda { require_relative(42) }.should raise_error(TypeError)
- lambda {
+ -> { require_relative(nil) }.should.raise(TypeError)
+ -> { require_relative(42) }.should.raise(TypeError)
+ -> {
require_relative([@path,@path])
- }.should raise_error(TypeError)
+ }.should.raise(TypeError)
end
it "raises a TypeError if passed an object that has #to_s but not #to_str" do
name = mock("load_fixture.rb mock")
name.stub!(:to_s).and_return(@path)
- lambda { require_relative(name) }.should raise_error(TypeError)
+ -> { require_relative(name) }.should.raise(TypeError)
end
it "raises a TypeError if #to_str does not return a String" do
name = mock("#to_str returns nil")
name.should_receive(:to_str).at_least(1).times.and_return(nil)
- lambda { require_relative(name) }.should raise_error(TypeError)
+ -> { require_relative(name) }.should.raise(TypeError)
end
it "calls #to_path on non-String objects" do
name = mock("load_fixture.rb mock")
name.should_receive(:to_path).and_return(@path)
- require_relative(name).should be_true
+ require_relative(name).should == true
ScratchPad.recorded.should == [:loaded]
end
@@ -267,13 +355,13 @@ describe "Kernel#require_relative with an absolute path" do
to_path = mock("load_fixture_rb #to_path mock")
name.should_receive(:to_path).and_return(to_path)
to_path.should_receive(:to_str).and_return(@path)
- require_relative(name).should be_true
+ require_relative(name).should == true
ScratchPad.recorded.should == [:loaded]
end
describe "(file extensions)" do
it "loads a .rb extensioned file when passed a non-extensioned path" do
- require_relative("#{@dir}/load_fixture").should be_true
+ require_relative("#{@dir}/load_fixture").should == true
ScratchPad.recorded.should == [:loaded]
end
@@ -282,20 +370,20 @@ describe "Kernel#require_relative with an absolute path" do
$LOADED_FEATURES << "#{@abs_dir}/load_fixture.dylib"
$LOADED_FEATURES << "#{@abs_dir}/load_fixture.so"
$LOADED_FEATURES << "#{@abs_dir}/load_fixture.dll"
- require_relative(@path).should be_true
+ require_relative(@path).should == true
ScratchPad.recorded.should == [:loaded]
end
it "does not load a C-extension file if a .rb extensioned file is already loaded" do
$LOADED_FEATURES << "#{@abs_dir}/load_fixture.rb"
- require_relative("#{@dir}/load_fixture").should be_false
+ require_relative("#{@dir}/load_fixture").should == false
ScratchPad.recorded.should == []
end
it "loads a .rb extensioned file when passed a non-.rb extensioned path" do
- require_relative("#{@dir}/load_fixture.ext").should be_true
+ require_relative("#{@dir}/load_fixture.ext").should == true
ScratchPad.recorded.should == [:loaded]
- $LOADED_FEATURES.should include "#{@abs_dir}/load_fixture.ext.rb"
+ $LOADED_FEATURES.should.include? "#{@abs_dir}/load_fixture.ext.rb"
end
it "loads a .rb extensioned file when a complex-extensioned C-extension file of the same name is loaded" do
@@ -303,46 +391,46 @@ describe "Kernel#require_relative with an absolute path" do
$LOADED_FEATURES << "#{@abs_dir}/load_fixture.ext.dylib"
$LOADED_FEATURES << "#{@abs_dir}/load_fixture.ext.so"
$LOADED_FEATURES << "#{@abs_dir}/load_fixture.ext.dll"
- require_relative("#{@dir}/load_fixture.ext").should be_true
+ require_relative("#{@dir}/load_fixture.ext").should == true
ScratchPad.recorded.should == [:loaded]
- $LOADED_FEATURES.should include "#{@abs_dir}/load_fixture.ext.rb"
+ $LOADED_FEATURES.should.include? "#{@abs_dir}/load_fixture.ext.rb"
end
it "does not load a C-extension file if a complex-extensioned .rb file is already loaded" do
$LOADED_FEATURES << "#{@abs_dir}/load_fixture.ext.rb"
- require_relative("#{@dir}/load_fixture.ext").should be_false
+ require_relative("#{@dir}/load_fixture.ext").should == false
ScratchPad.recorded.should == []
end
end
describe "($LOAD_FEATURES)" do
it "stores an absolute path" do
- require_relative(@path).should be_true
- $LOADED_FEATURES.should include(@abs_path)
+ require_relative(@path).should == true
+ $LOADED_FEATURES.should.include?(@abs_path)
end
it "does not store the path if the load fails" do
saved_loaded_features = $LOADED_FEATURES.dup
- lambda { require_relative("#{@dir}/raise_fixture.rb") }.should raise_error(RuntimeError)
+ -> { require_relative("#{@dir}/raise_fixture.rb") }.should.raise(RuntimeError)
$LOADED_FEATURES.should == saved_loaded_features
end
it "does not load an absolute path that is already stored" do
$LOADED_FEATURES << @abs_path
- require_relative(@path).should be_false
+ require_relative(@path).should == false
ScratchPad.recorded.should == []
end
it "adds the suffix of the resolved filename" do
- require_relative("#{@dir}/load_fixture").should be_true
- $LOADED_FEATURES.should include("#{@abs_dir}/load_fixture.rb")
+ require_relative("#{@dir}/load_fixture").should == true
+ $LOADED_FEATURES.should.include?("#{@abs_dir}/load_fixture.rb")
end
it "loads a path for a file already loaded with a relative path" do
$LOAD_PATH << File.expand_path(@dir)
$LOADED_FEATURES << "load_fixture.rb" << "load_fixture"
- require_relative(@path).should be_true
- $LOADED_FEATURES.should include(@abs_path)
+ require_relative(@path).should == true
+ $LOADED_FEATURES.should.include?(@abs_path)
ScratchPad.recorded.should == [:loaded]
end
end
diff --git a/spec/ruby/core/kernel/require_spec.rb b/spec/ruby/core/kernel/require_spec.rb
index 75cea7565e..62d954c2bf 100644
--- a/spec/ruby/core/kernel/require_spec.rb
+++ b/spec/ruby/core/kernel/require_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../fixtures/code_loading', __FILE__)
-require File.expand_path('../shared/require', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../../fixtures/code_loading'
+require_relative 'shared/require'
describe "Kernel#require" do
before :each do
@@ -13,11 +13,43 @@ describe "Kernel#require" do
# if this fails, update your rubygems
it "is a private method" do
- Kernel.should have_private_instance_method(:require)
+ Kernel.private_instance_methods(false).should.include?(:require)
end
- it_behaves_like :kernel_require_basic, :require, CodeLoadingSpecs::Method.new
+ it "provided features are already required" do
+ provided = %w[complex enumerator fiber rational thread ruby2_keywords]
+ ruby_version_is "4.0" do
+ provided += %w[set pathname]
+ end
+ ruby_version_is "4.1" do
+ provided += %w[monitor]
+ end
+
+ out = ruby_exe("puts $LOADED_FEATURES", options: '--disable-gems --disable-did-you-mean')
+ features = out.lines.map(&:chomp)
+
+ # Ignore engine-specific internals
+ case RUBY_ENGINE
+ when "jruby"
+ features -= %w[java.rb jruby/util.rb]
+ when "ruby"
+ so = RbConfig::CONFIG['DLEXT']
+ features -= ["windows_1252.#{so}", "windows_31.#{so}"]
+ features.reject! { |feature| feature.end_with? "encdb.#{so}" }
+ features.reject! { |feature| feature.end_with? "transdb.#{so}" }
+ features.reject! { |feature| feature.include?('-fake') }
+ end
+
+ features_no_ext = features.map { |path| File.basename(path, '.*') }
+ features_no_ext.sort.should == provided.sort
+ requires = features
+ code = requires.map { |f| "puts require #{f.inspect}\n" }.join
+ required = ruby_exe(code, options: '--disable-gems')
+ required.should == "false\n" * requires.size
+ end
+
+ it_behaves_like :kernel_require_basic, :require, CodeLoadingSpecs::Method.new
it_behaves_like :kernel_require, :require, CodeLoadingSpecs::Method.new
end
@@ -31,6 +63,5 @@ describe "Kernel.require" do
end
it_behaves_like :kernel_require_basic, :require, Kernel
-
it_behaves_like :kernel_require, :require, Kernel
end
diff --git a/spec/ruby/core/kernel/respond_to_missing_spec.rb b/spec/ruby/core/kernel/respond_to_missing_spec.rb
index f116f19dbd..08c9184fb4 100644
--- a/spec/ruby/core/kernel/respond_to_missing_spec.rb
+++ b/spec/ruby/core/kernel/respond_to_missing_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Kernel#respond_to_missing?" do
before :each do
@@ -7,7 +7,7 @@ describe "Kernel#respond_to_missing?" do
end
it "is a private method" do
- Kernel.should have_private_instance_method(:respond_to_missing?, false)
+ Kernel.private_instance_methods(false).should.include?(:respond_to_missing?)
end
it "is only an instance method" do
@@ -18,7 +18,7 @@ describe "Kernel#respond_to_missing?" do
obj = mock('object')
obj.stub!(:glark)
obj.should_not_receive(:respond_to_missing?)
- obj.respond_to?(:glark).should be_true
+ obj.respond_to?(:glark).should == true
end
it "is called with a 2nd argument of false when #respond_to? is" do
@@ -48,39 +48,39 @@ describe "Kernel#respond_to_missing?" do
it "causes #respond_to? to return true if called and not returning false" do
obj = mock('object')
obj.should_receive(:respond_to_missing?).with(:undefined_method, false).and_return(:glark)
- obj.respond_to?(:undefined_method).should be_true
+ obj.respond_to?(:undefined_method).should == true
end
it "causes #respond_to? to return false if called and returning false" do
obj = mock('object')
obj.should_receive(:respond_to_missing?).with(:undefined_method, false).and_return(false)
- obj.respond_to?(:undefined_method).should be_false
+ obj.respond_to?(:undefined_method).should == false
end
it "causes #respond_to? to return false if called and returning nil" do
obj = mock('object')
obj.should_receive(:respond_to_missing?).with(:undefined_method, false).and_return(nil)
- obj.respond_to?(:undefined_method).should be_false
+ obj.respond_to?(:undefined_method).should == false
end
it "isn't called when obj responds to the given public method" do
@a.should_not_receive(:respond_to_missing?)
- @a.respond_to?(:pub_method).should be_true
+ @a.respond_to?(:pub_method).should == true
end
it "isn't called when obj responds to the given public method, include_private = true" do
@a.should_not_receive(:respond_to_missing?)
- @a.respond_to?(:pub_method, true).should be_true
+ @a.respond_to?(:pub_method, true).should == true
end
it "is called when obj responds to the given protected method, include_private = false" do
@a.should_receive(:respond_to_missing?)
- @a.respond_to?(:protected_method, false).should be_false
+ @a.respond_to?(:protected_method, false).should == false
end
it "isn't called when obj responds to the given protected method, include_private = true" do
@a.should_not_receive(:respond_to_missing?)
- @a.respond_to?(:protected_method, true).should be_true
+ @a.respond_to?(:protected_method, true).should == true
end
it "is called when obj responds to the given private method, include_private = false" do
@@ -90,7 +90,7 @@ describe "Kernel#respond_to_missing?" do
it "isn't called when obj responds to the given private method, include_private = true" do
@a.should_not_receive(:respond_to_missing?)
- @a.respond_to?(:private_method, true).should be_true
+ @a.respond_to?(:private_method, true).should == true
end
it "is called for missing class methods" do
diff --git a/spec/ruby/core/kernel/respond_to_spec.rb b/spec/ruby/core/kernel/respond_to_spec.rb
index aa4379277b..72ab4eebe1 100644
--- a/spec/ruby/core/kernel/respond_to_spec.rb
+++ b/spec/ruby/core/kernel/respond_to_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Kernel#respond_to?" do
before :each do
@@ -7,7 +7,7 @@ describe "Kernel#respond_to?" do
end
it "is a public method" do
- Kernel.should have_public_instance_method(:respond_to?, false)
+ Kernel.public_instance_methods(false).should.include?(:respond_to?)
end
it "is only an instance method" do
@@ -25,7 +25,7 @@ describe "Kernel#respond_to?" do
end
it "throws a type error if argument can't be coerced into a Symbol" do
- lambda { @a.respond_to?(Object.new) }.should raise_error(TypeError)
+ -> { @a.respond_to?(Object.new) }.should.raise(TypeError, /is not a symbol nor a string/)
end
it "returns false if obj responds to the given protected method" do
@@ -61,7 +61,7 @@ describe "Kernel#respond_to?" do
it "does not change method visibility when finding private method" do
KernelSpecs::VisibilityChange.respond_to?(:new, false).should == false
KernelSpecs::VisibilityChange.respond_to?(:new, true).should == true
- lambda { KernelSpecs::VisibilityChange.new }.should raise_error(NoMethodError)
+ -> { KernelSpecs::VisibilityChange.new }.should.raise(NoMethodError)
end
it "indicates if an object responds to a particular message" do
@@ -70,4 +70,30 @@ describe "Kernel#respond_to?" do
KernelSpecs::Foo.new.respond_to?(:invalid_and_silly_method_name).should == false
end
+ context "if object does not have #respond_to_missing?" do
+ it "returns true if object responds to the given public method" do
+ KernelSpecs::BasicA.new.respond_to?(:pub_method).should == true
+ KernelSpecs::MissingA.new.respond_to?(:pub_method).should == true
+ end
+
+ it "returns false if object responds to the given protected method" do
+ KernelSpecs::BasicA.new.respond_to?(:protected_method).should == false
+ KernelSpecs::MissingA.new.respond_to?(:protected_method).should == false
+ end
+
+ it "returns false if object responds to the given private method" do
+ KernelSpecs::BasicA.new.respond_to?(:private_method).should == false
+ KernelSpecs::MissingA.new.respond_to?(:private_method).should == false
+ end
+
+ it "returns false if the given method was undefined" do
+ KernelSpecs::BasicA.new.respond_to?(:undefed_method).should == false
+ KernelSpecs::MissingA.new.respond_to?(:undefed_method).should == false
+ end
+
+ it "returns false if the given method never existed" do
+ KernelSpecs::BasicA.new.respond_to?(:invalid_and_silly_method_name).should == false
+ KernelSpecs::MissingA.new.respond_to?(:invalid_and_silly_method_name).should == false
+ end
+ end
end
diff --git a/spec/ruby/core/kernel/select_spec.rb b/spec/ruby/core/kernel/select_spec.rb
index c37c621ae7..58c963c1a4 100644
--- a/spec/ruby/core/kernel/select_spec.rb
+++ b/spec/ruby/core/kernel/select_spec.rb
@@ -1,20 +1,18 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Kernel#select" do
it "is a private method" do
- Kernel.should have_private_instance_method(:select)
+ Kernel.private_instance_methods(false).should.include?(:select)
end
end
describe "Kernel.select" do
- it "needs to be reviewed for spec completeness"
-
it 'does not block when timeout is 0' do
IO.pipe do |read, write|
- IO.select([read], [], [], 0).should == nil
+ select([read], [], [], 0).should == nil
write.write 'data'
- IO.select([read], [], [], 0).should == [[read], [], []]
+ select([read], [], [], 0).should == [[read], [], []]
end
end
end
diff --git a/spec/ruby/core/kernel/send_spec.rb b/spec/ruby/core/kernel/send_spec.rb
index 8afd16e97c..9a4d261964 100644
--- a/spec/ruby/core/kernel/send_spec.rb
+++ b/spec/ruby/core/kernel/send_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../../../shared/basicobject/send', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative '../../shared/basicobject/send'
describe "Kernel#send" do
it "invokes the named public method" do
@@ -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/set_trace_func_spec.rb b/spec/ruby/core/kernel/set_trace_func_spec.rb
index 5dafa8b5d3..5201812f2f 100644
--- a/spec/ruby/core/kernel/set_trace_func_spec.rb
+++ b/spec/ruby/core/kernel/set_trace_func_spec.rb
@@ -1,9 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Kernel#set_trace_func" do
it "is a private method" do
- Kernel.should have_private_instance_method(:set_trace_func)
+ Kernel.private_instance_methods(false).should.include?(:set_trace_func)
end
end
diff --git a/spec/ruby/core/kernel/shared/dup_clone.rb b/spec/ruby/core/kernel/shared/dup_clone.rb
index 116989958b..3fbf918283 100644
--- a/spec/ruby/core/kernel/shared/dup_clone.rb
+++ b/spec/ruby/core/kernel/shared/dup_clone.rb
@@ -40,7 +40,7 @@ describe :kernel_dup_clone, shared: true do
o.obj = array
o2 = o.send(@method)
- o2.obj.should equal(o.obj)
+ o2.obj.should.equal?(o.obj)
end
it "calls #initialize_copy on the NEW object if available, passing in original object" do
@@ -49,17 +49,7 @@ describe :kernel_dup_clone, shared: true do
o.obj.should == :original
o2.obj.should == :init_copy
- o2.original.should equal(o)
- end
-
- it "preserves tainted state from the original" do
- o = ObjectSpecDupInitCopy.new
- o2 = o.send(@method)
- o.taint
- o3 = o.send(@method)
-
- o2.tainted?.should == false
- o3.tainted?.should == true
+ o2.original.should.equal?(o)
end
it "does not preserve the object_id" do
@@ -69,81 +59,33 @@ describe :kernel_dup_clone, shared: true do
o2.object_id.should_not == old_object_id
end
- it "preserves untrusted state from the original" do
- o = ObjectSpecDupInitCopy.new
- o2 = o.send(@method)
- o.untrust
- o3 = o.send(@method)
-
- o2.untrusted?.should == false
- o3.untrusted?.should == true
+ it "returns nil for NilClass" do
+ nil.send(@method).should == nil
end
- ruby_version_is ''...'2.4' do
- it "raises a TypeError for NilClass" do
- lambda { nil.send(@method) }.should raise_error(TypeError)
- end
-
- it "raises a TypeError for TrueClass" do
- lambda { true.send(@method) }.should raise_error(TypeError)
- end
-
- it "raises a TypeError for FalseClass" do
- lambda { false.send(@method) }.should raise_error(TypeError)
- end
-
- it "raises a TypeError for Fixnum" do
- lambda { 1.send(@method) }.should raise_error(TypeError)
- end
-
- it "raises a TypeError for Symbol" do
- lambda { :my_symbol.send(@method) }.should raise_error(TypeError)
- end
+ it "returns true for TrueClass" do
+ true.send(@method).should == true
end
- ruby_version_is '2.4' do
- it "returns nil for NilClass" do
- nil.send(@method).should == nil
- end
-
- it "returns true for TrueClass" do
- true.send(@method).should == true
- end
-
- it "returns false for FalseClass" do
- false.send(@method).should == false
- end
-
- it "returns the same Integer for Integer" do
- 1.send(@method).should == 1
- end
-
- it "returns the same Symbol for Symbol" do
- :my_symbol.send(@method).should == :my_symbol
- end
+ it "returns false for FalseClass" do
+ false.send(@method).should == false
end
- ruby_version_is ''...'2.5' do
- it "raises a TypeError for Complex" do
- c = Complex(1.3, 3.1)
- lambda { c.send(@method) }.should raise_error(TypeError)
- end
+ it "returns the same Integer for Integer" do
+ 1.send(@method).should == 1
+ end
- it "raises a TypeError for Rational" do
- r = Rational(1, 3)
- lambda { r.send(@method) }.should raise_error(TypeError)
- end
+ it "returns the same Symbol for Symbol" do
+ :my_symbol.send(@method).should == :my_symbol
end
- ruby_version_is '2.5' do
- it "returns self for Complex" do
- c = Complex(1.3, 3.1)
- c.send(@method).should equal c
- end
+ it "returns self for Complex" do
+ c = Complex(1.3, 3.1)
+ c.send(@method).should.equal? c
+ end
- it "returns self for Rational" do
- r = Rational(1, 3)
- r.send(@method).should equal r
- end
+ it "returns self for Rational" do
+ r = Rational(1, 3)
+ r.send(@method).should.equal? r
end
end
diff --git a/spec/ruby/core/kernel/shared/kind_of.rb b/spec/ruby/core/kernel/shared/kind_of.rb
deleted file mode 100644
index e99f46aa14..0000000000
--- a/spec/ruby/core/kernel/shared/kind_of.rb
+++ /dev/null
@@ -1,44 +0,0 @@
-require File.expand_path('../../fixtures/classes', __FILE__)
-
-describe :kernel_kind_of, shared: true do
- before :each do
- @o = KernelSpecs::KindaClass.new
- end
-
- it "returns true if given class is the object's class" do
- @o.send(@method, KernelSpecs::KindaClass).should == true
- end
-
- it "returns true if given class is an ancestor of the object's class" do
- @o.send(@method, KernelSpecs::AncestorClass).should == true
- @o.send(@method, String).should == true
- @o.send(@method, Object).should == true
- end
-
- it "returns false if the given class is not object's class nor an ancestor" do
- @o.send(@method, Array).should == false
- end
-
- it "returns true if given a Module that is included in object's class" do
- @o.send(@method, KernelSpecs::MyModule).should == true
- end
-
- it "returns true if given a Module that is included one of object's ancestors only" do
- @o.send(@method, KernelSpecs::AncestorModule).should == true
- end
-
- it "returns true if given a Module that object has been extended with" do
- @o.send(@method, KernelSpecs::MyExtensionModule).should == true
- end
-
- it "returns false if given a Module not included in object's class nor ancestors" do
- @o.send(@method, KernelSpecs::SomeOtherModule).should == false
- end
-
- it "raises a TypeError if given an object that is not a Class nor a Module" do
- lambda { @o.send(@method, 1) }.should raise_error(TypeError)
- lambda { @o.send(@method, 'KindaClass') }.should raise_error(TypeError)
- lambda { @o.send(@method, :KindaClass) }.should raise_error(TypeError)
- lambda { @o.send(@method, Object.new) }.should raise_error(TypeError)
- end
-end
diff --git a/spec/ruby/core/kernel/shared/lambda.rb b/spec/ruby/core/kernel/shared/lambda.rb
index bebb111c43..83de06bb41 100644
--- a/spec/ruby/core/kernel/shared/lambda.rb
+++ b/spec/ruby/core/kernel/shared/lambda.rb
@@ -4,6 +4,8 @@ describe :kernel_lambda, shared: true do
end
it "raises an ArgumentError when no block is given" do
- lambda { send(@method) }.should raise_error(ArgumentError)
+ suppress_warning do
+ -> { send(@method) }.should.raise(ArgumentError)
+ end
end
end
diff --git a/spec/ruby/core/kernel/shared/load.rb b/spec/ruby/core/kernel/shared/load.rb
index 0ce7d58d2c..20d23a623e 100644
--- a/spec/ruby/core/kernel/shared/load.rb
+++ b/spec/ruby/core/kernel/shared/load.rb
@@ -1,3 +1,6 @@
+main = self
+
+# The big difference is Kernel#load does not attempt to add an extension to the passed path, unlike Kernel#require
describe :kernel_load, shared: true do
before :each do
CodeLoadingSpecs.spec_setup
@@ -8,101 +11,141 @@ describe :kernel_load, shared: true do
CodeLoadingSpecs.spec_cleanup
end
- it "loads a non-extensioned file as a Ruby source file" do
- path = File.expand_path "load_fixture", CODE_LOADING_DIR
- @object.load(path).should be_true
- ScratchPad.recorded.should == [:no_ext]
- end
+ describe "(path resolution)" do
+ # This behavior is specific to Kernel#load, it differs for Kernel#require
+ it "loads a non-extensioned file as a Ruby source file" do
+ path = File.expand_path "load_fixture", CODE_LOADING_DIR
+ @object.load(path).should == true
+ ScratchPad.recorded.should == [:no_ext]
+ end
- it "loads a non .rb extensioned file as a Ruby source file" do
- path = File.expand_path "load_fixture.ext", CODE_LOADING_DIR
- @object.load(path).should be_true
- ScratchPad.recorded.should == [:no_rb_ext]
- end
+ it "loads a non .rb extensioned file as a Ruby source file" do
+ path = File.expand_path "load_fixture.ext", CODE_LOADING_DIR
+ @object.load(path).should == true
+ ScratchPad.recorded.should == [:no_rb_ext]
+ end
- it "loads from the current working directory" do
- Dir.chdir CODE_LOADING_DIR do
- @object.load("load_fixture.rb").should be_true
- ScratchPad.recorded.should == [:loaded]
+ it "loads from the current working directory" do
+ Dir.chdir CODE_LOADING_DIR do
+ @object.load("load_fixture.rb").should == true
+ ScratchPad.recorded.should == [:loaded]
+ end
+ end
+
+ # This behavior is specific to Kernel#load, it differs for Kernel#require
+ it "does not look for a c-extension file when passed a path without extension (when no .rb is present)" do
+ path = File.join CODE_LOADING_DIR, "a", "load_fixture"
+ -> { @object.send(@method, path) }.should.raise(LoadError)
end
end
it "loads a file that recursively requires itself" do
path = File.expand_path "recursive_require_fixture.rb", CODE_LOADING_DIR
-> {
- $VERBOSE = true
- @object.load(path).should be_true
- }.should complain(/circular require considered harmful/)
+ @object.load(path).should == true
+ }.should complain(/circular require considered harmful/, verbose: true)
ScratchPad.recorded.should == [:loaded, :loaded]
end
it "loads a file that recursively loads itself" do
path = File.expand_path "recursive_load_fixture.rb", CODE_LOADING_DIR
- @object.load(path).should be_true
+ @object.load(path).should == true
ScratchPad.recorded.should == [:loaded, :loaded]
end
it "loads a file each time the method is called" do
- @object.load(@path).should be_true
- @object.load(@path).should be_true
+ @object.load(@path).should == true
+ @object.load(@path).should == true
ScratchPad.recorded.should == [:loaded, :loaded]
end
it "loads a file even when the name appears in $LOADED_FEATURES" do
$LOADED_FEATURES << @path
- @object.load(@path).should be_true
+ @object.load(@path).should == true
ScratchPad.recorded.should == [:loaded]
end
it "loads a file that has been loaded by #require" do
- @object.require(@path).should be_true
- @object.load(@path).should be_true
+ @object.require(@path).should == true
+ @object.load(@path).should == true
ScratchPad.recorded.should == [:loaded, :loaded]
end
it "loads file even after $LOAD_PATH change" do
$LOAD_PATH << CODE_LOADING_DIR
- @object.load("load_fixture.rb").should be_true
+ @object.load("load_fixture.rb").should == true
$LOAD_PATH.unshift CODE_LOADING_DIR + "/gem"
- @object.load("load_fixture.rb").should be_true
+ @object.load("load_fixture.rb").should == true
ScratchPad.recorded.should == [:loaded, :loaded_gem]
end
it "does not cause #require with the same path to fail" do
- @object.load(@path).should be_true
- @object.require(@path).should be_true
+ @object.load(@path).should == true
+ @object.require(@path).should == true
ScratchPad.recorded.should == [:loaded, :loaded]
end
it "does not add the loaded path to $LOADED_FEATURES" do
saved_loaded_features = $LOADED_FEATURES.dup
- @object.load(@path).should be_true
+ @object.load(@path).should == true
$LOADED_FEATURES.should == saved_loaded_features
end
it "raises a LoadError if passed a non-extensioned path that does not exist but a .rb extensioned path does exist" do
path = File.expand_path "load_ext_fixture", CODE_LOADING_DIR
- lambda { @object.load(path) }.should raise_error(LoadError)
+ -> { @object.load(path) }.should.raise(LoadError)
end
describe "when passed true for 'wrap'" do
it "loads from an existing path" do
- path = File.expand_path "wrap_fixture.rb", CODE_LOADING_DIR
- @object.load(path, true).should be_true
+ path = File.expand_path "load_wrap_fixture.rb", CODE_LOADING_DIR
+ @object.load(path, true).should == true
end
it "sets the enclosing scope to an anonymous module" do
- path = File.expand_path "wrap_fixture.rb", CODE_LOADING_DIR
+ path = File.expand_path "load_wrap_fixture.rb", CODE_LOADING_DIR
@object.load(path, true)
- Object.const_defined?(:LoadSpecWrap).should be_false
+ Object.const_defined?(:LoadSpecWrap).should == false
+
+ wrap_module = ScratchPad.recorded[1]
+ wrap_module.should.instance_of?(Module)
end
it "allows referencing outside namespaces" do
- path = File.expand_path "wrap_fixture.rb", CODE_LOADING_DIR
+ path = File.expand_path "load_wrap_fixture.rb", CODE_LOADING_DIR
+ @object.load(path, true)
+
+ ScratchPad.recorded[0].should.equal?(String)
+ end
+
+ it "sets self as a copy of the top-level main" do
+ path = File.expand_path "load_wrap_fixture.rb", CODE_LOADING_DIR
+ @object.load(path, true)
+
+ top_level = ScratchPad.recorded[2]
+ top_level.to_s.should == "main"
+ top_level.method(:to_s).owner.should == top_level.singleton_class
+ top_level.should_not.equal?(main)
+ top_level.should.instance_of?(Object)
+ end
+
+ it "includes modules included in main's singleton class in self's class" do
+ mod = Module.new
+ main.extend(mod)
+
+ main_ancestors = main.singleton_class.ancestors[1..-1]
+ main_ancestors.first.should == mod
+
+ path = File.expand_path "load_wrap_fixture.rb", CODE_LOADING_DIR
@object.load(path, true)
- ScratchPad.recorded.first.should be_an_instance_of(Class)
+ top_level = ScratchPad.recorded[2]
+ top_level_ancestors = top_level.singleton_class.ancestors[-main_ancestors.size..-1]
+ top_level_ancestors.should == main_ancestors
+
+ wrap_module = ScratchPad.recorded[1]
+ top_level.singleton_class.ancestors.should == [top_level.singleton_class, wrap_module, *main_ancestors]
end
describe "with top-level methods" do
@@ -116,11 +159,44 @@ describe :kernel_load, shared: true do
end
it "does not pollute the receiver" do
- lambda { @object.send(:top_level_method) }.should raise_error(NameError)
+ -> { @object.send(:top_level_method) }.should.raise(NameError)
end
end
end
+ describe "when passed a module for 'wrap'" do
+ it "sets the enclosing scope to the supplied module" do
+ path = File.expand_path "load_wrap_fixture.rb", CODE_LOADING_DIR
+ mod = Module.new
+ @object.load(path, mod)
+
+ Object.const_defined?(:LoadSpecWrap).should == false
+ mod.const_defined?(:LoadSpecWrap).should == true
+
+ wrap_module = ScratchPad.recorded[1]
+ wrap_module.should == mod
+ end
+
+ it "makes constants and instance methods in the source file reachable with the supplied module" do
+ path = File.expand_path "load_wrap_fixture.rb", CODE_LOADING_DIR
+ mod = Module.new
+ @object.load(path, mod)
+
+ mod::LOAD_WRAP_SPECS_TOP_LEVEL_CONSTANT.should == 1
+ obj = Object.new
+ obj.extend(mod)
+ obj.send(:load_wrap_specs_top_level_method).should == :load_wrap_specs_top_level_method
+ end
+
+ it "makes instance methods in the source file private" do
+ path = File.expand_path "load_wrap_fixture.rb", CODE_LOADING_DIR
+ mod = Module.new
+ @object.load(path, mod)
+
+ mod.private_instance_methods.include?(:load_wrap_specs_top_level_method).should == true
+ end
+ end
+
describe "(shell expansion)" do
before :each do
@env_home = ENV["HOME"]
@@ -132,7 +208,7 @@ describe :kernel_load, shared: true do
end
it "expands a tilde to the HOME environment variable as the path to load" do
- @object.require("~/load_fixture.rb").should be_true
+ @object.require("~/load_fixture.rb").should == true
ScratchPad.recorded.should == [:loaded]
end
end
diff --git a/spec/ruby/core/kernel/shared/method.rb b/spec/ruby/core/kernel/shared/method.rb
index 1566c6ab09..82abc287d1 100644
--- a/spec/ruby/core/kernel/shared/method.rb
+++ b/spec/ruby/core/kernel/shared/method.rb
@@ -1,36 +1,42 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe :kernel_method, shared: true do
it "returns a method object for a valid method" do
class KernelSpecs::Foo; def bar; 'done'; end; end
m = KernelSpecs::Foo.new.send(@method, :bar)
- m.should be_an_instance_of Method
+ m.should.instance_of? Method
m.call.should == 'done'
end
it "returns a method object for a valid singleton method" do
class KernelSpecs::Foo; def self.bar; 'class done'; end; end
m = KernelSpecs::Foo.send(@method, :bar)
- m.should be_an_instance_of Method
+ m.should.instance_of? Method
m.call.should == 'class done'
end
- it "returns a method object if we repond_to_missing? method" do
+ it "returns a method object if respond_to_missing?(method) is true" do
m = KernelSpecs::RespondViaMissing.new.send(@method, :handled_publicly)
- m.should be_an_instance_of Method
+ m.should.instance_of? Method
+ m.call(42).should == "Done handled_publicly([42])"
+ end
+
+ it "the returned method object if respond_to_missing?(method) calls #method_missing with a Symbol name" do
+ m = KernelSpecs::RespondViaMissing.new.send(@method, "handled_publicly")
+ m.should.instance_of? Method
m.call(42).should == "Done handled_publicly([42])"
end
it "raises a NameError for an invalid method name" do
class KernelSpecs::Foo; def bar; 'done'; end; end
- lambda {
+ -> {
KernelSpecs::Foo.new.send(@method, :invalid_and_silly_method_name)
- }.should raise_error(NameError)
+ }.should.raise(NameError)
end
it "raises a NameError for an invalid singleton method name" do
class KernelSpecs::Foo; def self.bar; 'done'; end; end
- lambda { KernelSpecs::Foo.send(@method, :baz) }.should raise_error(NameError)
+ -> { KernelSpecs::Foo.send(@method, :baz) }.should.raise(NameError)
end
it "changes the method called for super on a target aliased method" do
diff --git a/spec/ruby/core/kernel/shared/require.rb b/spec/ruby/core/kernel/shared/require.rb
index 3296c7f42a..6272b00665 100644
--- a/spec/ruby/core/kernel/shared/require.rb
+++ b/spec/ruby/core/kernel/shared/require.rb
@@ -2,46 +2,48 @@ describe :kernel_require_basic, shared: true do
describe "(path resolution)" do
it "loads an absolute path" do
path = File.expand_path "load_fixture.rb", CODE_LOADING_DIR
- @object.send(@method, path).should be_true
+ @object.send(@method, path).should == true
ScratchPad.recorded.should == [:loaded]
end
it "loads a non-canonical absolute path" do
path = File.join CODE_LOADING_DIR, "..", "code", "load_fixture.rb"
- @object.send(@method, path).should be_true
+ @object.send(@method, path).should == true
ScratchPad.recorded.should == [:loaded]
end
it "loads a file defining many methods" do
path = File.expand_path "methods_fixture.rb", CODE_LOADING_DIR
- @object.send(@method, path).should be_true
+ @object.send(@method, path).should == true
ScratchPad.recorded.should == [:loaded]
end
it "raises a LoadError if the file does not exist" do
path = File.expand_path "nonexistent.rb", CODE_LOADING_DIR
- File.exist?(path).should be_false
- lambda { @object.send(@method, path) }.should raise_error(LoadError)
+ File.should_not.exist?(path)
+ -> { @object.send(@method, path) }.should.raise(LoadError)
ScratchPad.recorded.should == []
end
# Can't make a file unreadable on these platforms
platform_is_not :windows, :cygwin do
- describe "with an unreadable file" do
- before :each do
- @path = tmp("unreadable_file.rb")
- touch @path
- File.chmod 0000, @path
- end
-
- after :each do
- File.chmod 0666, @path
- rm_r @path
- end
-
- it "raises a LoadError" do
- File.exist?(@path).should be_true
- lambda { @object.send(@method, @path) }.should raise_error(LoadError)
+ as_user do
+ describe "with an unreadable file" do
+ before :each do
+ @path = tmp("unreadable_file.rb")
+ touch @path
+ File.chmod 0000, @path
+ end
+
+ after :each do
+ File.chmod 0666, @path
+ rm_r @path
+ end
+
+ it "raises a LoadError" do
+ File.should.exist?(@path)
+ -> { @object.send(@method, @path) }.should.raise(LoadError)
+ end
end
end
end
@@ -50,24 +52,24 @@ describe :kernel_require_basic, shared: true do
path = File.expand_path "load_fixture.rb", CODE_LOADING_DIR
name = mock("load_fixture.rb mock")
name.should_receive(:to_str).and_return(path)
- @object.send(@method, name).should be_true
+ @object.send(@method, name).should == true
ScratchPad.recorded.should == [:loaded]
end
it "raises a TypeError if passed nil" do
- lambda { @object.send(@method, nil) }.should raise_error(TypeError)
+ -> { @object.send(@method, nil) }.should.raise(TypeError)
end
- it "raises a TypeError if passed a Fixnum" do
- lambda { @object.send(@method, 42) }.should raise_error(TypeError)
+ it "raises a TypeError if passed an Integer" do
+ -> { @object.send(@method, 42) }.should.raise(TypeError)
end
it "raises a TypeError if passed an Array" do
- lambda { @object.send(@method, []) }.should raise_error(TypeError)
+ -> { @object.send(@method, []) }.should.raise(TypeError)
end
it "raises a TypeError if passed an object that does not provide #to_str" do
- lambda { @object.send(@method, mock("not a filename")) }.should raise_error(TypeError)
+ -> { @object.send(@method, mock("not a filename")) }.should.raise(TypeError)
end
it "raises a TypeError if passed an object that has #to_s but not #to_str" do
@@ -75,14 +77,14 @@ describe :kernel_require_basic, shared: true do
name.stub!(:to_s).and_return("load_fixture.rb")
$LOAD_PATH << "."
Dir.chdir CODE_LOADING_DIR do
- lambda { @object.send(@method, name) }.should raise_error(TypeError)
+ -> { @object.send(@method, name) }.should.raise(TypeError)
end
end
it "raises a TypeError if #to_str does not return a String" do
name = mock("#to_str returns nil")
name.should_receive(:to_str).at_least(1).times.and_return(nil)
- lambda { @object.send(@method, name) }.should raise_error(TypeError)
+ -> { @object.send(@method, name) }.should.raise(TypeError)
end
it "calls #to_path on non-String objects" do
@@ -90,7 +92,7 @@ describe :kernel_require_basic, shared: true do
name.stub!(:to_path).and_return("load_fixture.rb")
$LOAD_PATH << "."
Dir.chdir CODE_LOADING_DIR do
- @object.send(@method, name).should be_true
+ @object.send(@method, name).should == true
end
ScratchPad.recorded.should == [:loaded]
end
@@ -99,7 +101,7 @@ describe :kernel_require_basic, shared: true do
path = File.expand_path "load_fixture.rb", CODE_LOADING_DIR
str = mock("load_fixture.rb mock")
str.should_receive(:to_path).and_return(path)
- @object.send(@method, str).should be_true
+ @object.send(@method, str).should == true
ScratchPad.recorded.should == [:loaded]
end
@@ -109,21 +111,21 @@ describe :kernel_require_basic, shared: true do
to_path = mock("load_fixture_rb #to_path mock")
name.should_receive(:to_path).and_return(to_path)
to_path.should_receive(:to_str).and_return(path)
- @object.send(@method, name).should be_true
+ @object.send(@method, name).should == true
ScratchPad.recorded.should == [:loaded]
end
# "http://redmine.ruby-lang.org/issues/show/2578"
it "loads a ./ relative path from the current working directory with empty $LOAD_PATH" do
Dir.chdir CODE_LOADING_DIR do
- @object.send(@method, "./load_fixture.rb").should be_true
+ @object.send(@method, "./load_fixture.rb").should == true
end
ScratchPad.recorded.should == [:loaded]
end
it "loads a ../ relative path from the current working directory with empty $LOAD_PATH" do
Dir.chdir CODE_LOADING_DIR do
- @object.send(@method, "../code/load_fixture.rb").should be_true
+ @object.send(@method, "../code/load_fixture.rb").should == true
end
ScratchPad.recorded.should == [:loaded]
end
@@ -131,7 +133,7 @@ describe :kernel_require_basic, shared: true do
it "loads a ./ relative path from the current working directory with non-empty $LOAD_PATH" do
$LOAD_PATH << "an_irrelevant_dir"
Dir.chdir CODE_LOADING_DIR do
- @object.send(@method, "./load_fixture.rb").should be_true
+ @object.send(@method, "./load_fixture.rb").should == true
end
ScratchPad.recorded.should == [:loaded]
end
@@ -139,7 +141,7 @@ describe :kernel_require_basic, shared: true do
it "loads a ../ relative path from the current working directory with non-empty $LOAD_PATH" do
$LOAD_PATH << "an_irrelevant_dir"
Dir.chdir CODE_LOADING_DIR do
- @object.send(@method, "../code/load_fixture.rb").should be_true
+ @object.send(@method, "../code/load_fixture.rb").should == true
end
ScratchPad.recorded.should == [:loaded]
end
@@ -147,44 +149,52 @@ describe :kernel_require_basic, shared: true do
it "loads a non-canonical path from the current working directory with non-empty $LOAD_PATH" do
$LOAD_PATH << "an_irrelevant_dir"
Dir.chdir CODE_LOADING_DIR do
- @object.send(@method, "../code/../code/load_fixture.rb").should be_true
+ @object.send(@method, "../code/../code/load_fixture.rb").should == true
end
ScratchPad.recorded.should == [:loaded]
end
it "resolves a filename against $LOAD_PATH entries" do
$LOAD_PATH << CODE_LOADING_DIR
- @object.send(@method, "load_fixture.rb").should be_true
+ @object.send(@method, "load_fixture.rb").should == true
+ ScratchPad.recorded.should == [:loaded]
+ end
+
+ it "accepts an Object with #to_path in $LOAD_PATH" do
+ obj = mock("to_path")
+ obj.should_receive(:to_path).at_least(:once).and_return(CODE_LOADING_DIR)
+ $LOAD_PATH << obj
+ @object.send(@method, "load_fixture.rb").should == true
ScratchPad.recorded.should == [:loaded]
end
it "does not require file twice after $LOAD_PATH change" do
$LOAD_PATH << CODE_LOADING_DIR
- @object.require("load_fixture.rb").should be_true
- $LOAD_PATH.unshift CODE_LOADING_DIR + "/gem"
- @object.require("load_fixture.rb").should be_false
+ @object.require("load_fixture.rb").should == true
+ $LOAD_PATH.push CODE_LOADING_DIR + "/gem"
+ @object.require("load_fixture.rb").should == false
ScratchPad.recorded.should == [:loaded]
end
it "does not resolve a ./ relative path against $LOAD_PATH entries" do
$LOAD_PATH << CODE_LOADING_DIR
- lambda do
+ -> do
@object.send(@method, "./load_fixture.rb")
- end.should raise_error(LoadError)
+ end.should.raise(LoadError)
ScratchPad.recorded.should == []
end
it "does not resolve a ../ relative path against $LOAD_PATH entries" do
$LOAD_PATH << CODE_LOADING_DIR
- lambda do
+ -> do
@object.send(@method, "../code/load_fixture.rb")
- end.should raise_error(LoadError)
+ end.should.raise(LoadError)
ScratchPad.recorded.should == []
end
it "resolves a non-canonical path against $LOAD_PATH entries" do
$LOAD_PATH << File.dirname(CODE_LOADING_DIR)
- @object.send(@method, "code/../code/load_fixture.rb").should be_true
+ @object.send(@method, "code/../code/load_fixture.rb").should == true
ScratchPad.recorded.should == [:loaded]
end
@@ -193,7 +203,7 @@ describe :kernel_require_basic, shared: true do
sep = File::Separator + File::Separator
path = ["..", "code", "load_fixture.rb"].join(sep)
Dir.chdir CODE_LOADING_DIR do
- @object.send(@method, path).should be_true
+ @object.send(@method, path).should == true
end
ScratchPad.recorded.should == [:loaded]
end
@@ -202,20 +212,48 @@ end
describe :kernel_require, shared: true do
describe "(path resolution)" do
+ it "loads .rb file when passed absolute path without extension" do
+ path = File.expand_path "load_fixture", CODE_LOADING_DIR
+ @object.send(@method, path).should == true
+ # This should _not_ be [:no_ext]
+ ScratchPad.recorded.should == [:loaded]
+ end
+
+ platform_is :linux, :darwin do
+ it "loads c-extension file when passed absolute path without extension when no .rb is present" do
+ # the error message is specific to what dlerror() returns
+ path = File.join CODE_LOADING_DIR, "a", "load_fixture"
+ -> { @object.send(@method, path) }.should.raise(LoadError)
+ end
+ end
+
+ platform_is :darwin do
+ it "loads .bundle file when passed absolute path with .so" do
+ # the error message is specific to what dlerror() returns
+ path = File.join CODE_LOADING_DIR, "a", "load_fixture.so"
+ -> { @object.send(@method, path) }.should.raise(LoadError)
+ end
+ end
+
+ it "does not try an extra .rb if the path already ends in .rb" do
+ path = File.join CODE_LOADING_DIR, "d", "load_fixture.rb"
+ -> { @object.send(@method, path) }.should.raise(LoadError)
+ end
+
# For reference see [ruby-core:24155] in which matz confirms this feature is
# intentional for security reasons.
it "does not load a bare filename unless the current working directory is in $LOAD_PATH" do
Dir.chdir CODE_LOADING_DIR do
- lambda { @object.require("load_fixture.rb") }.should raise_error(LoadError)
+ -> { @object.require("load_fixture.rb") }.should.raise(LoadError)
ScratchPad.recorded.should == []
end
end
it "does not load a relative path unless the current working directory is in $LOAD_PATH" do
Dir.chdir File.dirname(CODE_LOADING_DIR) do
- lambda do
+ -> do
@object.require("code/load_fixture.rb")
- end.should raise_error(LoadError)
+ end.should.raise(LoadError)
ScratchPad.recorded.should == []
end
end
@@ -223,11 +261,19 @@ describe :kernel_require, shared: true do
it "loads a file that recursively requires itself" do
path = File.expand_path "recursive_require_fixture.rb", CODE_LOADING_DIR
-> {
- $VERBOSE = true
- @object.require(path).should be_true
- }.should complain(/circular require considered harmful/)
+ @object.require(path).should == true
+ }.should complain(/circular require considered harmful/, verbose: true)
ScratchPad.recorded.should == [:loaded]
end
+
+ it "loads a file concurrently" do
+ path = File.expand_path "concurrent_require_fixture.rb", CODE_LOADING_DIR
+ ScratchPad.record(@object)
+ -> {
+ @object.require(path)
+ }.should_not complain(/circular require considered harmful/, verbose: true)
+ ScratchPad.recorded.join
+ end
end
describe "(non-extensioned path)" do
@@ -238,16 +284,33 @@ describe :kernel_require, shared: true do
end
it "loads a .rb extensioned file when a C-extension file exists on an earlier load path" do
- @object.require("load_fixture").should be_true
+ @object.require("load_fixture").should == true
ScratchPad.recorded.should == [:loaded]
end
+
+ it "does not load a feature twice when $LOAD_PATH has been modified" do
+ $LOAD_PATH.replace [CODE_LOADING_DIR]
+ @object.require("load_fixture").should == true
+ $LOAD_PATH.replace [File.expand_path("b", CODE_LOADING_DIR), CODE_LOADING_DIR]
+ @object.require("load_fixture").should == false
+ end
+
+ it "stores the missing path in a LoadError object" do
+ path = "abcd1234"
+
+ -> {
+ @object.send(@method, path)
+ }.should.raise(LoadError) { |e|
+ e.path.should == path
+ }
+ end
end
describe "(file extensions)" do
it "loads a .rb extensioned file when passed a non-extensioned path" do
path = File.expand_path "load_fixture", CODE_LOADING_DIR
- File.exist?(path).should be_true
- @object.require(path).should be_true
+ File.should.exist?(path)
+ @object.require(path).should == true
ScratchPad.recorded.should == [:loaded]
end
@@ -257,21 +320,21 @@ describe :kernel_require, shared: true do
$LOADED_FEATURES << File.expand_path("load_fixture.so", CODE_LOADING_DIR)
$LOADED_FEATURES << File.expand_path("load_fixture.dll", CODE_LOADING_DIR)
path = File.expand_path "load_fixture", CODE_LOADING_DIR
- @object.require(path).should be_true
+ @object.require(path).should == true
ScratchPad.recorded.should == [:loaded]
end
it "does not load a C-extension file if a .rb extensioned file is already loaded" do
$LOADED_FEATURES << File.expand_path("load_fixture.rb", CODE_LOADING_DIR)
path = File.expand_path "load_fixture", CODE_LOADING_DIR
- @object.require(path).should be_false
+ @object.require(path).should == false
ScratchPad.recorded.should == []
end
it "loads a .rb extensioned file when passed a non-.rb extensioned path" do
path = File.expand_path "load_fixture.ext", CODE_LOADING_DIR
- File.exist?(path).should be_true
- @object.require(path).should be_true
+ File.should.exist?(path)
+ @object.require(path).should == true
ScratchPad.recorded.should == [:loaded]
end
@@ -281,14 +344,14 @@ describe :kernel_require, shared: true do
$LOADED_FEATURES << File.expand_path("load_fixture.ext.so", CODE_LOADING_DIR)
$LOADED_FEATURES << File.expand_path("load_fixture.ext.dll", CODE_LOADING_DIR)
path = File.expand_path "load_fixture.ext", CODE_LOADING_DIR
- @object.require(path).should be_true
+ @object.require(path).should == true
ScratchPad.recorded.should == [:loaded]
end
it "does not load a C-extension file if a complex-extensioned .rb file is already loaded" do
$LOADED_FEATURES << File.expand_path("load_fixture.ext.rb", CODE_LOADING_DIR)
path = File.expand_path "load_fixture.ext", CODE_LOADING_DIR
- @object.require(path).should be_false
+ @object.require(path).should == false
ScratchPad.recorded.should == []
end
end
@@ -299,27 +362,103 @@ describe :kernel_require, shared: true do
end
it "stores an absolute path" do
- @object.require(@path).should be_true
- $LOADED_FEATURES.should include(@path)
+ @object.require(@path).should == true
+ $LOADED_FEATURES.should.include?(@path)
+ end
+
+ platform_is_not :windows do
+ describe "with symlinks" do
+ before :each do
+ @symlink_to_code_dir = tmp("codesymlink")
+ File.symlink(CODE_LOADING_DIR, @symlink_to_code_dir)
+
+ $LOAD_PATH.delete(CODE_LOADING_DIR)
+ $LOAD_PATH.unshift(@symlink_to_code_dir)
+ end
+
+ after :each do
+ rm_r @symlink_to_code_dir
+ end
+
+ it "does not canonicalize the path and stores a path with symlinks" do
+ symlink_path = "#{@symlink_to_code_dir}/load_fixture.rb"
+ canonical_path = "#{CODE_LOADING_DIR}/load_fixture.rb"
+ @object.require(symlink_path).should == true
+ ScratchPad.recorded.should == [:loaded]
+
+ features = $LOADED_FEATURES.select { |path| path.end_with?('load_fixture.rb') }
+ features.should.include?(symlink_path)
+ features.should_not.include?(canonical_path)
+ end
+
+ it "stores the same path that __FILE__ returns in the required file" do
+ symlink_path = "#{@symlink_to_code_dir}/load_fixture_and__FILE__.rb"
+ @object.require(symlink_path).should == true
+ loaded_feature = $LOADED_FEATURES.last
+ ScratchPad.recorded.should == [loaded_feature]
+ end
+
+ it "requires only once when a new matching file added to path" do
+ @object.require('load_fixture').should == true
+ ScratchPad.recorded.should == [:loaded]
+
+ symlink_to_code_dir_two = tmp("codesymlinktwo")
+ File.symlink("#{CODE_LOADING_DIR}/b", symlink_to_code_dir_two)
+ begin
+ $LOAD_PATH.unshift(symlink_to_code_dir_two)
+
+ @object.require('load_fixture').should == false
+ ensure
+ rm_r symlink_to_code_dir_two
+ end
+ end
+ end
+
+ describe "with symlinks in the required feature and $LOAD_PATH" do
+ before :each do
+ @dir = tmp("realdir")
+ mkdir_p @dir
+ @file = "#{@dir}/realfile.rb"
+ touch(@file) { |f| f.puts 'ScratchPad << __FILE__' }
+
+ @symlink_to_dir = tmp("symdir").freeze
+ File.symlink(@dir, @symlink_to_dir)
+ @symlink_to_file = "#{@dir}/symfile.rb"
+ File.symlink("realfile.rb", @symlink_to_file)
+ end
+
+ after :each do
+ rm_r @dir, @symlink_to_dir
+ end
+
+ it "canonicalizes the entry in $LOAD_PATH but not the filename passed to #require" do
+ $LOAD_PATH.unshift(@symlink_to_dir)
+ @object.require("symfile").should == true
+ loaded_feature = "#{@dir}/symfile.rb"
+ ScratchPad.recorded.should == [loaded_feature]
+ $".last.should == loaded_feature
+ $LOAD_PATH[0].should == @symlink_to_dir
+ end
+ end
end
it "does not store the path if the load fails" do
$LOAD_PATH << CODE_LOADING_DIR
saved_loaded_features = $LOADED_FEATURES.dup
- lambda { @object.require("raise_fixture.rb") }.should raise_error(RuntimeError)
+ -> { @object.require("raise_fixture.rb") }.should.raise(RuntimeError)
$LOADED_FEATURES.should == saved_loaded_features
end
it "does not load an absolute path that is already stored" do
$LOADED_FEATURES << @path
- @object.require(@path).should be_false
+ @object.require(@path).should == false
ScratchPad.recorded.should == []
end
it "does not load a ./ relative path that is already stored" do
$LOADED_FEATURES << "./load_fixture.rb"
Dir.chdir CODE_LOADING_DIR do
- @object.require("./load_fixture.rb").should be_false
+ @object.require("./load_fixture.rb").should == false
end
ScratchPad.recorded.should == []
end
@@ -327,7 +466,7 @@ describe :kernel_require, shared: true do
it "does not load a ../ relative path that is already stored" do
$LOADED_FEATURES << "../load_fixture.rb"
Dir.chdir CODE_LOADING_DIR do
- @object.require("../load_fixture.rb").should be_false
+ @object.require("../load_fixture.rb").should == false
end
ScratchPad.recorded.should == []
end
@@ -335,27 +474,27 @@ describe :kernel_require, shared: true do
it "does not load a non-canonical path that is already stored" do
$LOADED_FEATURES << "code/../code/load_fixture.rb"
$LOAD_PATH << File.dirname(CODE_LOADING_DIR)
- @object.require("code/../code/load_fixture.rb").should be_false
+ @object.require("code/../code/load_fixture.rb").should == false
ScratchPad.recorded.should == []
end
it "respects being replaced with a new array" do
prev = $LOADED_FEATURES.dup
- @object.require(@path).should be_true
- $LOADED_FEATURES.should include(@path)
+ @object.require(@path).should == true
+ $LOADED_FEATURES.should.include?(@path)
$LOADED_FEATURES.replace(prev)
- $LOADED_FEATURES.should_not include(@path)
- @object.require(@path).should be_true
- $LOADED_FEATURES.should include(@path)
+ $LOADED_FEATURES.should_not.include?(@path)
+ @object.require(@path).should == true
+ $LOADED_FEATURES.should.include?(@path)
end
it "does not load twice the same file with and without extension" do
$LOAD_PATH << CODE_LOADING_DIR
- @object.require("load_fixture.rb").should be_true
- @object.require("load_fixture").should be_false
+ @object.require("load_fixture.rb").should == true
+ @object.require("load_fixture").should == false
end
describe "when a non-extensioned file is in $LOADED_FEATURES" do
@@ -365,19 +504,19 @@ describe :kernel_require, shared: true do
it "loads a .rb extensioned file when a non extensioned file is in $LOADED_FEATURES" do
$LOAD_PATH << CODE_LOADING_DIR
- @object.require("load_fixture").should be_true
+ @object.require("load_fixture").should == true
ScratchPad.recorded.should == [:loaded]
end
it "loads a .rb extensioned file from a subdirectory" do
$LOAD_PATH << File.dirname(CODE_LOADING_DIR)
- @object.require("code/load_fixture").should be_true
+ @object.require("code/load_fixture").should == true
ScratchPad.recorded.should == [:loaded]
end
it "returns false if the file is not found" do
Dir.chdir File.dirname(CODE_LOADING_DIR) do
- @object.require("load_fixture").should be_false
+ @object.require("load_fixture").should == false
ScratchPad.recorded.should == []
end
end
@@ -385,7 +524,7 @@ describe :kernel_require, shared: true do
it "returns false when passed a path and the file is not found" do
$LOADED_FEATURES << "code/load_fixture"
Dir.chdir CODE_LOADING_DIR do
- @object.require("code/load_fixture").should be_false
+ @object.require("code/load_fixture").should == false
ScratchPad.recorded.should == []
end
end
@@ -393,16 +532,16 @@ describe :kernel_require, shared: true do
it "stores ../ relative paths as absolute paths" do
Dir.chdir CODE_LOADING_DIR do
- @object.require("../code/load_fixture.rb").should be_true
+ @object.require("../code/load_fixture.rb").should == true
end
- $LOADED_FEATURES.should include(@path)
+ $LOADED_FEATURES.should.include?(@path)
end
it "stores ./ relative paths as absolute paths" do
Dir.chdir CODE_LOADING_DIR do
- @object.require("./load_fixture.rb").should be_true
+ @object.require("./load_fixture.rb").should == true
end
- $LOADED_FEATURES.should include(@path)
+ $LOADED_FEATURES.should.include?(@path)
end
it "collapses duplicate path separators" do
@@ -410,27 +549,27 @@ describe :kernel_require, shared: true do
sep = File::Separator + File::Separator
path = ["..", "code", "load_fixture.rb"].join(sep)
Dir.chdir CODE_LOADING_DIR do
- @object.require(path).should be_true
+ @object.require(path).should == true
end
- $LOADED_FEATURES.should include(@path)
+ $LOADED_FEATURES.should.include?(@path)
end
- it "canonicalizes non-unique absolute paths" do
+ it "expands absolute paths containing .." do
path = File.join CODE_LOADING_DIR, "..", "code", "load_fixture.rb"
- @object.require(path).should be_true
- $LOADED_FEATURES.should include(@path)
+ @object.require(path).should == true
+ $LOADED_FEATURES.should.include?(@path)
end
it "adds the suffix of the resolved filename" do
$LOAD_PATH << CODE_LOADING_DIR
- @object.require("load_fixture").should be_true
- $LOADED_FEATURES.should include(@path)
+ @object.require("load_fixture").should == true
+ $LOADED_FEATURES.should.include?(@path)
end
it "does not load a non-canonical path for a file already loaded" do
$LOADED_FEATURES << @path
$LOAD_PATH << File.dirname(CODE_LOADING_DIR)
- @object.require("code/../code/load_fixture.rb").should be_false
+ @object.require("code/../code/load_fixture.rb").should == false
ScratchPad.recorded.should == []
end
@@ -438,7 +577,7 @@ describe :kernel_require, shared: true do
$LOADED_FEATURES << @path
$LOAD_PATH << "an_irrelevant_dir"
Dir.chdir CODE_LOADING_DIR do
- @object.require("./load_fixture.rb").should be_false
+ @object.require("./load_fixture.rb").should == false
end
ScratchPad.recorded.should == []
end
@@ -447,51 +586,35 @@ describe :kernel_require, shared: true do
$LOADED_FEATURES << @path
$LOAD_PATH << "an_irrelevant_dir"
Dir.chdir CODE_LOADING_DIR do
- @object.require("../code/load_fixture.rb").should be_false
+ @object.require("../code/load_fixture.rb").should == false
end
ScratchPad.recorded.should == []
end
- ruby_version_is "2.2"..."2.3" do
- it "complex, enumerator, rational and unicode_normalize are already required" do
- provided = %w[complex enumerator rational unicode_normalize]
- features = ruby_exe("puts $LOADED_FEATURES", options: '--disable-gems')
- provided.each { |feature|
- features.should =~ /\b#{feature}\.(rb|so)$/
- }
+ it "unicode_normalize is part of core and not $LOADED_FEATURES" do
+ features = ruby_exe("puts $LOADED_FEATURES", options: '--disable-gems')
+ features.lines.each { |feature|
+ feature.should_not.include?("unicode_normalize")
+ }
- code = provided.map { |f| "puts require #{f.inspect}\n" }.join
- required = ruby_exe(code, options: '--disable-gems')
- required.should == "false\n" * provided.size
- end
+ -> { @object.require("unicode_normalize") }.should.raise(LoadError)
end
- ruby_version_is "2.3"..."2.5" do
- it "complex, enumerator, rational, thread and unicode_normalize are already required" do
- provided = %w[complex enumerator rational thread unicode_normalize]
- features = ruby_exe("puts $LOADED_FEATURES", options: '--disable-gems')
- provided.each { |feature|
- features.should =~ /\b#{feature}\.(rb|so|jar)$/
- }
-
- code = provided.map { |f| "puts require #{f.inspect}\n" }.join
- required = ruby_exe(code, options: '--disable-gems')
- required.should == "false\n" * provided.size
+ it "does not load a file earlier on the $LOAD_PATH when other similar features were already loaded" do
+ Dir.chdir CODE_LOADING_DIR do
+ @object.send(@method, "../code/load_fixture").should == true
end
- end
+ ScratchPad.recorded.should == [:loaded]
- ruby_version_is "2.5" do
- it "complex, enumerator, rational and thread are already required" do
- provided = %w[complex enumerator rational thread]
- features = ruby_exe("puts $LOADED_FEATURES", options: '--disable-gems')
- provided.each { |feature|
- features.should =~ /\b#{feature}\.(rb|so|jar)$/
- }
+ $LOAD_PATH.unshift "#{CODE_LOADING_DIR}/b"
+ # This loads because the above load was not on the $LOAD_PATH
+ @object.send(@method, "load_fixture").should == true
+ ScratchPad.recorded.should == [:loaded, :loaded]
- code = provided.map { |f| "puts require #{f.inspect}\n" }.join
- required = ruby_exe(code, options: '--disable-gems')
- required.should == "false\n" * provided.size
- end
+ $LOAD_PATH.unshift "#{CODE_LOADING_DIR}/c"
+ # This does not load because the above load was on the $LOAD_PATH
+ @object.send(@method, "load_fixture").should == false
+ ScratchPad.recorded.should == [:loaded, :loaded]
end
end
@@ -508,13 +631,13 @@ describe :kernel_require, shared: true do
# "#3171"
it "performs tilde expansion on a .rb file before storing paths in $LOADED_FEATURES" do
- @object.require("~/load_fixture.rb").should be_true
- $LOADED_FEATURES.should include(@path)
+ @object.require("~/load_fixture.rb").should == true
+ $LOADED_FEATURES.should.include?(@path)
end
it "performs tilde expansion on a non-extensioned file before storing paths in $LOADED_FEATURES" do
- @object.require("~/load_fixture").should be_true
- $LOADED_FEATURES.should include(@path)
+ @object.require("~/load_fixture").should == true
+ $LOADED_FEATURES.should.include?(@path)
end
end
@@ -571,8 +694,8 @@ describe :kernel_require, shared: true do
t1.join
t2.join
- t1_res.should be_true
- t2_res.should be_false
+ t1_res.should == true
+ t2_res.should == false
ScratchPad.recorded.should == [:con_pre, :con_post, :t2_post, :t1_post]
end
@@ -596,8 +719,8 @@ describe :kernel_require, shared: true do
t1.join
t2.join
- t1_res.should be_true
- t2_res.should be_true
+ t1_res.should == true
+ t2_res.should == true
ScratchPad.recorded.should == [:con2_pre, :con3, :con2_post]
end
@@ -613,9 +736,9 @@ describe :kernel_require, shared: true do
Thread.current[:wait_for] = t2
Thread.current[:con_raise] = true
- lambda {
+ -> {
@object.require(@path)
- }.should raise_error(RuntimeError)
+ }.should.raise(RuntimeError)
Thread.pass until fin
ScratchPad.recorded << :t1_post
@@ -636,7 +759,7 @@ describe :kernel_require, shared: true do
t1.join
t2.join
- t2_res.should be_true
+ t2_res.should == true
ScratchPad.recorded.should == [:con_pre, :con_pre, :con_post, :t2_post, :t1_post]
end
@@ -654,9 +777,9 @@ describe :kernel_require, shared: true do
t1 = Thread.new do
Thread.current[:con_raise] = true
- lambda {
+ -> {
@object.require(@path)
- }.should raise_error(RuntimeError)
+ }.should.raise(RuntimeError)
raised = true
@@ -684,8 +807,8 @@ describe :kernel_require, shared: true do
t1.join
t2.join
- t1_res.should be_false
- t2_res.should be_true
+ t1_res.should == false
+ t2_res.should == true
ScratchPad.recorded.should == [:con_pre, :con_pre, :con_post, :t2_post, :t1_post]
end
@@ -694,10 +817,30 @@ describe :kernel_require, shared: true do
it "stores the missing path in a LoadError object" do
path = "abcd1234"
- lambda {
+ -> {
@object.send(@method, path)
- }.should raise_error(LoadError) { |e|
+ }.should.raise(LoadError) { |e|
e.path.should == path
}
end
+
+ platform_is :linux, :darwin do
+ it "does not store the missing path in a LoadError object when c-extension file exists but loading fails and passed absolute path without extension" do
+ # the error message is specific to what dlerror() returns
+ path = File.join CODE_LOADING_DIR, "a", "load_fixture"
+ -> { @object.send(@method, path) }.should.raise(LoadError) { |e|
+ e.path.should == nil
+ }
+ end
+ end
+
+ platform_is :darwin do
+ it "does not store the missing path in a LoadError object when c-extension file exists but loading fails and passed absolute path with extension" do
+ # the error message is specific to what dlerror() returns
+ path = File.join CODE_LOADING_DIR, "a", "load_fixture.bundle"
+ -> { @object.send(@method, path) }.should.raise(LoadError) { |e|
+ e.path.should == nil
+ }
+ end
+ end
end
diff --git a/spec/ruby/core/kernel/shared/sprintf.rb b/spec/ruby/core/kernel/shared/sprintf.rb
new file mode 100644
index 0000000000..e57334c5ab
--- /dev/null
+++ b/spec/ruby/core/kernel/shared/sprintf.rb
@@ -0,0 +1,1057 @@
+describe :kernel_sprintf, shared: true do
+ describe "integer formats" do
+ it "converts argument into Integer with to_int" do
+ obj = Object.new
+ def obj.to_i; 10; end
+ def obj.to_int; 10; end
+
+ obj.should_receive(:to_int).and_return(10)
+ @method.call("%b", obj).should == "1010"
+ end
+
+ it "converts argument into Integer with to_i if to_int isn't available" do
+ obj = Object.new
+ def obj.to_i; 10; end
+
+ obj.should_receive(:to_i).and_return(10)
+ @method.call("%b", obj).should == "1010"
+ end
+
+ it "converts String argument with Kernel#Integer" do
+ @method.call("%d", "0b1010").should == "10"
+ @method.call("%d", "112").should == "112"
+ @method.call("%d", "0127").should == "87"
+ @method.call("%d", "0xc4").should == "196"
+ @method.call("%d", "0").should == "0"
+ end
+
+ it "raises TypeError exception if cannot convert to Integer" do
+ -> {
+ @method.call("%b", Object.new)
+ }.should.raise(TypeError)
+ end
+
+ ["b", "B"].each do |f|
+ describe f do
+ it "converts argument as a binary number" do
+ @method.call("%#{f}", 10).should == "1010"
+ end
+
+ it "displays negative number as a two's complement prefixed with '..1'" do
+ @method.call("%#{f}", -10).should == "..1" + "0110"
+ end
+
+ it "collapse negative number representation if it equals 1" do
+ @method.call("%#{f}", -1).should_not == "..11"
+ @method.call("%#{f}", -1).should == "..1"
+ end
+ end
+ end
+
+ ["d", "i", "u"].each do |f|
+ describe f do
+ it "converts argument as a decimal number" do
+ @method.call("%#{f}", 112).should == "112"
+ @method.call("%#{f}", -112).should == "-112"
+ end
+
+ it "works well with large numbers" do
+ @method.call("%#{f}", 1234567890987654321).should == "1234567890987654321"
+ end
+ end
+ end
+
+ describe "o" do
+ it "converts argument as an octal number" do
+ @method.call("%o", 87).should == "127"
+ end
+
+ it "displays negative number as a two's complement prefixed with '..7'" do
+ @method.call("%o", -87).should == "..7" + "651"
+ end
+
+ it "collapse negative number representation if it equals 7" do
+ @method.call("%o", -1).should_not == "..77"
+ @method.call("%o", -1).should == "..7"
+ end
+ end
+
+ describe "x" do
+ it "converts argument as a hexadecimal number" do
+ @method.call("%x", 196).should == "c4"
+ end
+
+ it "displays negative number as a two's complement prefixed with '..f'" do
+ @method.call("%x", -196).should == "..f" + "3c"
+ end
+
+ it "collapse negative number representation if it equals f" do
+ @method.call("%x", -1).should_not == "..ff"
+ @method.call("%x", -1).should == "..f"
+ end
+ end
+
+ describe "X" do
+ it "converts argument as a hexadecimal number with uppercase letters" do
+ @method.call("%X", 196).should == "C4"
+ end
+
+ it "displays negative number as a two's complement prefixed with '..f'" do
+ @method.call("%X", -196).should == "..F" + "3C"
+ end
+
+ it "collapse negative number representation if it equals F" do
+ @method.call("%X", -1).should_not == "..FF"
+ @method.call("%X", -1).should == "..F"
+ end
+ end
+
+ %w[b B d i u o x X].each do |f|
+ describe f do
+ it "converts to the empty string if precision is 0 and value is 0" do
+ @method.call("%.#{f}", 0).should == ""
+ @method.call("%.0#{f}", 0).should == ""
+ end
+
+ it "pads the empty string if precision is 0 and value is 0" do
+ @method.call("%2.#{f}", 0).should == " "
+ @method.call("%2.0#{f}", 0).should == " "
+ end
+ end
+ end
+ end
+
+ describe "float formats" do
+ it "converts argument into Float" do
+ obj = mock("float")
+ obj.should_receive(:to_f).and_return(9.6)
+ @method.call("%f", obj).should == "9.600000"
+ end
+
+ it "raises TypeError exception if cannot convert to Float" do
+ -> {
+ @method.call("%f", Object.new)
+ }.should.raise(TypeError)
+ end
+
+ {"e" => "e", "E" => "E"}.each_pair do |f, exp|
+ describe f do
+ it "converts argument into exponential notation [-]d.dddddde[+-]dd" do
+ @method.call("%#{f}", 109.52).should == "1.095200#{exp}+02"
+ @method.call("%#{f}", -109.52).should == "-1.095200#{exp}+02"
+ @method.call("%#{f}", 0.10952).should == "1.095200#{exp}-01"
+ @method.call("%#{f}", -0.10952).should == "-1.095200#{exp}-01"
+ end
+
+ it "cuts excessive digits and keeps only 6 ones" do
+ @method.call("%#{f}", 1.123456789).should == "1.123457#{exp}+00"
+ end
+
+ it "rounds the last significant digit to the closest one" do
+ @method.call("%#{f}", 1.555555555).should == "1.555556#{exp}+00"
+ @method.call("%#{f}", -1.555555555).should == "-1.555556#{exp}+00"
+ @method.call("%#{f}", 1.444444444).should == "1.444444#{exp}+00"
+ end
+
+ it "displays Float::INFINITY as Inf" do
+ @method.call("%#{f}", Float::INFINITY).should == "Inf"
+ @method.call("%#{f}", -Float::INFINITY).should == "-Inf"
+ end
+
+ it "displays Float::NAN as NaN" do
+ @method.call("%#{f}", Float::NAN).should == "NaN"
+ @method.call("%#{f}", -Float::NAN).should == "NaN"
+ end
+ end
+ end
+
+ describe "f" do
+ it "converts floating point argument as [-]ddd.dddddd" do
+ @method.call("%f", 10.952).should == "10.952000"
+ @method.call("%f", -10.952).should == "-10.952000"
+ end
+
+ it "cuts excessive digits and keeps only 6 ones" do
+ @method.call("%f", 1.123456789).should == "1.123457"
+ end
+
+ it "rounds the last significant digit to the closest one" do
+ @method.call("%f", 1.555555555).should == "1.555556"
+ @method.call("%f", -1.555555555).should == "-1.555556"
+ @method.call("%f", 1.444444444).should == "1.444444"
+ end
+
+ it "displays Float::INFINITY as Inf" do
+ @method.call("%f", Float::INFINITY).should == "Inf"
+ @method.call("%f", -Float::INFINITY).should == "-Inf"
+ end
+
+ it "displays Float::NAN as NaN" do
+ @method.call("%f", Float::NAN).should == "NaN"
+ @method.call("%f", -Float::NAN).should == "NaN"
+ end
+ end
+
+ {"g" => "e", "G" => "E"}.each_pair do |f, exp|
+ describe f do
+ context "the exponent is less than -4" do
+ it "converts a floating point number using exponential form" do
+ @method.call("%#{f}", 0.0000123456).should == "1.23456#{exp}-05"
+ @method.call("%#{f}", -0.0000123456).should == "-1.23456#{exp}-05"
+
+ @method.call("%#{f}", 0.000000000123456).should == "1.23456#{exp}-10"
+ @method.call("%#{f}", -0.000000000123456).should == "-1.23456#{exp}-10"
+ end
+ end
+
+ context "the exponent is greater than or equal to the precision (6 by default)" do
+ it "converts a floating point number using exponential form" do
+ @method.call("%#{f}", 1234567).should == "1.23457#{exp}+06"
+ @method.call("%#{f}", 1234567890123).should == "1.23457#{exp}+12"
+ @method.call("%#{f}", -1234567).should == "-1.23457#{exp}+06"
+ end
+ end
+
+ context "otherwise" do
+ it "converts a floating point number in dd.dddd form" do
+ @method.call("%#{f}", 0.0001).should == "0.0001"
+ @method.call("%#{f}", -0.0001).should == "-0.0001"
+ @method.call("%#{f}", 123456).should == "123456"
+ @method.call("%#{f}", -123456).should == "-123456"
+ end
+
+ it "cuts excessive digits in fractional part and keeps only 4 ones" do
+ @method.call("%#{f}", 12.12341111).should == "12.1234"
+ @method.call("%#{f}", -12.12341111).should == "-12.1234"
+ end
+
+ it "rounds the last significant digit to the closest one in fractional part" do
+ @method.call("%#{f}", 1.555555555).should == "1.55556"
+ @method.call("%#{f}", -1.555555555).should == "-1.55556"
+ @method.call("%#{f}", 1.444444444).should == "1.44444"
+ end
+
+ it "cuts fraction part to have only 6 digits at all" do
+ @method.call("%#{f}", 1.1234567).should == "1.12346"
+ @method.call("%#{f}", 12.1234567).should == "12.1235"
+ @method.call("%#{f}", 123.1234567).should == "123.123"
+ @method.call("%#{f}", 1234.1234567).should == "1234.12"
+ @method.call("%#{f}", 12345.1234567).should == "12345.1"
+ @method.call("%#{f}", 123456.1234567).should == "123456"
+ end
+ end
+
+ it "displays Float::INFINITY as Inf" do
+ @method.call("%#{f}", Float::INFINITY).should == "Inf"
+ @method.call("%#{f}", -Float::INFINITY).should == "-Inf"
+ end
+
+ it "displays Float::NAN as NaN" do
+ @method.call("%#{f}", Float::NAN).should == "NaN"
+ @method.call("%#{f}", -Float::NAN).should == "NaN"
+ end
+ end
+ end
+
+ describe "a" do
+ it "converts floating point argument as [-]0xh.hhhhp[+-]dd" do
+ @method.call("%a", 196).should == "0x1.88p+7"
+ @method.call("%a", -196).should == "-0x1.88p+7"
+ @method.call("%a", 196.1).should == "0x1.8833333333333p+7"
+ @method.call("%a", 0.01).should == "0x1.47ae147ae147bp-7"
+ @method.call("%a", -0.01).should == "-0x1.47ae147ae147bp-7"
+ end
+
+ it "displays Float::INFINITY as Inf" do
+ @method.call("%a", Float::INFINITY).should == "Inf"
+ @method.call("%a", -Float::INFINITY).should == "-Inf"
+ end
+
+ it "displays Float::NAN as NaN" do
+ @method.call("%a", Float::NAN).should == "NaN"
+ @method.call("%a", -Float::NAN).should == "NaN"
+ end
+ end
+
+ describe "A" do
+ it "converts floating point argument as [-]0xh.hhhhp[+-]dd and use uppercase X and P" do
+ @method.call("%A", 196).should == "0X1.88P+7"
+ @method.call("%A", -196).should == "-0X1.88P+7"
+ @method.call("%A", 196.1).should == "0X1.8833333333333P+7"
+ @method.call("%A", 0.01).should == "0X1.47AE147AE147BP-7"
+ @method.call("%A", -0.01).should == "-0X1.47AE147AE147BP-7"
+ end
+
+ it "displays Float::INFINITY as Inf" do
+ @method.call("%A", Float::INFINITY).should == "Inf"
+ @method.call("%A", -Float::INFINITY).should == "-Inf"
+ end
+
+ it "displays Float::NAN as NaN" do
+ @method.call("%A", Float::NAN).should == "NaN"
+ @method.call("%A", -Float::NAN).should == "NaN"
+ end
+ end
+ end
+
+ describe "other formats" do
+ describe "c" do
+ it "displays character if argument is a numeric code of character" do
+ @method.call("%c", 97).should == "a"
+ end
+
+ it "displays character if argument is a single character string" do
+ @method.call("%c", "a").should == "a"
+ end
+
+ it "displays only the first character if argument is a string of several characters" do
+ @method.call("%c", "abc").should == "a"
+ end
+
+ it "displays only the first character if argument is a string of several multibyte characters" do
+ @method.call("%c", "ã‚ã„ã†ãˆãŠ").should == "ã‚"
+ end
+
+ it "displays no characters if argument is an empty string" do
+ @method.call("%c", "").should == ""
+ end
+
+ it "raises TypeError if argument is not String or Integer and cannot be converted to them" do
+ -> {
+ @method.call("%c", [])
+ }.should raise_consistent_error(TypeError, /no implicit conversion of Array into Integer/)
+ end
+
+ it "raises TypeError if argument is nil" do
+ -> {
+ @method.call("%c", nil)
+ }.should raise_consistent_error(TypeError, /no implicit conversion of nil into Integer/)
+ end
+
+ it "tries to convert argument to String with to_str" do
+ obj = BasicObject.new
+ def obj.to_str
+ "a"
+ end
+
+ @method.call("%c", obj).should == "a"
+ end
+
+ it "tries to convert argument to Integer with to_int" do
+ obj = BasicObject.new
+ def obj.to_int
+ 90
+ end
+
+ @method.call("%c", obj).should == "Z"
+ end
+
+ it "raises TypeError if converting to String with to_str returns non-String" do
+ obj = BasicObject.new
+ def obj.to_str
+ :foo
+ end
+
+ -> {
+ @method.call("%c", obj)
+ }.should raise_consistent_error(TypeError, /can't convert BasicObject into String/)
+ end
+
+ it "raises TypeError if converting to Integer with to_int returns non-Integer" do
+ obj = BasicObject.new
+ def obj.to_int
+ :foo
+ end
+
+ -> {
+ @method.call("%c", obj)
+ }.should raise_consistent_error(TypeError, /can't convert BasicObject into Integer/)
+ end
+ end
+
+ describe "p" do
+ it "displays argument.inspect value" do
+ obj = mock("object")
+ obj.should_receive(:inspect).and_return("<inspect-result>")
+ @method.call("%p", obj).should == "<inspect-result>"
+ end
+
+ it "substitutes 'nil' for nil" do
+ @method.call("%p", nil).should == "nil"
+ end
+ end
+
+ describe "s" do
+ it "substitute argument passes as a string" do
+ @method.call("%s", "abc").should == "abc"
+ end
+
+ it "substitutes '' for nil" do
+ @method.call("%s", nil).should == ""
+ end
+
+ it "converts argument to string with to_s" do
+ obj = mock("string")
+ obj.should_receive(:to_s).and_return("abc")
+ @method.call("%s", obj).should == "abc"
+ end
+
+ it "does not try to convert with to_str" do
+ obj = BasicObject.new
+ def obj.to_str
+ "abc"
+ end
+
+ -> {
+ @method.call("%s", obj)
+ }.should.raise(NoMethodError)
+ end
+
+ it "formats a partial substring without including omitted characters" do
+ long_string = "aabbccddhelloddccbbaa"
+ sub_string = long_string[8, 5]
+ sprintf("%.#{1 * 3}s", sub_string).should == "hel"
+ end
+
+ it "formats string with precision" do
+ Kernel.format("%.3s", "hello").should == "hel"
+ Kernel.format("%-3.3s", "hello").should == "hel"
+ end
+
+ it "formats string with width" do
+ @method.call("%6s", "abc").should == " abc"
+ @method.call("%6s", "abcdefg").should == "abcdefg"
+ end
+
+ it "formats string with width and precision" do
+ @method.call("%4.6s", "abc").should == " abc"
+ @method.call("%4.6s", "abcdefg").should == "abcdef"
+ end
+
+ it "formats nil with width" do
+ @method.call("%6s", nil).should == " "
+ end
+
+ it "formats nil with precision" do
+ @method.call("%.6s", nil).should == ""
+ end
+
+ it "formats nil with width and precision" do
+ @method.call("%4.6s", nil).should == " "
+ end
+
+ it "formats multibyte string with precision" do
+ Kernel.format("%.2s", "été").should == "ét"
+ end
+
+ it "preserves encoding of the format string" do
+ str = format('%s'.encode(Encoding::UTF_8), 'foobar')
+ str.encoding.should == Encoding::UTF_8
+
+ str = format('%s'.encode(Encoding::US_ASCII), 'foobar')
+ str.encoding.should == Encoding::US_ASCII
+ end
+ end
+
+ describe "%" do
+ it "alone raises an ArgumentError" do
+ -> {
+ @method.call("%")
+ }.should.raise(ArgumentError)
+ end
+
+ it "is escaped by %" do
+ @method.call("%%").should == "%"
+ @method.call("%%d").should == "%d"
+ end
+ end
+ end
+
+ describe "flags" do
+ describe "space" do
+ context "applies to numeric formats bBdiouxXeEfgGaA" do
+ it "leaves a space at the start of non-negative numbers" do
+ @method.call("% b", 10).should == " 1010"
+ @method.call("% B", 10).should == " 1010"
+ @method.call("% d", 112).should == " 112"
+ @method.call("% i", 112).should == " 112"
+ @method.call("% o", 87).should == " 127"
+ @method.call("% u", 112).should == " 112"
+ @method.call("% x", 196).should == " c4"
+ @method.call("% X", 196).should == " C4"
+
+ @method.call("% e", 109.52).should == " 1.095200e+02"
+ @method.call("% E", 109.52).should == " 1.095200E+02"
+ @method.call("% f", 10.952).should == " 10.952000"
+ @method.call("% g", 12.1234).should == " 12.1234"
+ @method.call("% G", 12.1234).should == " 12.1234"
+ @method.call("% a", 196).should == " 0x1.88p+7"
+ @method.call("% A", 196).should == " 0X1.88P+7"
+ end
+
+ it "does not leave a space at the start of negative numbers" do
+ @method.call("% b", -10).should == "-1010"
+ @method.call("% B", -10).should == "-1010"
+ @method.call("% d", -112).should == "-112"
+ @method.call("% i", -112).should == "-112"
+ @method.call("% o", -87).should == "-127"
+ @method.call("% u", -112).should == "-112"
+ @method.call("% x", -196).should == "-c4"
+ @method.call("% X", -196).should == "-C4"
+
+ @method.call("% e", -109.52).should == "-1.095200e+02"
+ @method.call("% E", -109.52).should == "-1.095200E+02"
+ @method.call("% f", -10.952).should == "-10.952000"
+ @method.call("% g", -12.1234).should == "-12.1234"
+ @method.call("% G", -12.1234).should == "-12.1234"
+ @method.call("% a", -196).should == "-0x1.88p+7"
+ @method.call("% A", -196).should == "-0X1.88P+7"
+ end
+
+ it "prevents converting negative argument to two's complement form" do
+ @method.call("% b", -10).should == "-1010"
+ @method.call("% B", -10).should == "-1010"
+ @method.call("% o", -87).should == "-127"
+ @method.call("% x", -196).should == "-c4"
+ @method.call("% X", -196).should == "-C4"
+ end
+
+ it "treats several white spaces as one" do
+ @method.call("% b", 10).should == " 1010"
+ @method.call("% B", 10).should == " 1010"
+ @method.call("% d", 112).should == " 112"
+ @method.call("% i", 112).should == " 112"
+ @method.call("% o", 87).should == " 127"
+ @method.call("% u", 112).should == " 112"
+ @method.call("% x", 196).should == " c4"
+ @method.call("% X", 196).should == " C4"
+
+ @method.call("% e", 109.52).should == " 1.095200e+02"
+ @method.call("% E", 109.52).should == " 1.095200E+02"
+ @method.call("% f", 10.952).should == " 10.952000"
+ @method.call("% g", 12.1234).should == " 12.1234"
+ @method.call("% G", 12.1234).should == " 12.1234"
+ @method.call("% a", 196).should == " 0x1.88p+7"
+ @method.call("% A", 196).should == " 0X1.88P+7"
+ end
+ end
+ end
+
+ describe "(digit)$" do
+ it "specifies the absolute argument number for this field" do
+ @method.call("%2$b", 0, 10).should == "1010"
+ @method.call("%2$B", 0, 10).should == "1010"
+ @method.call("%2$d", 0, 112).should == "112"
+ @method.call("%2$i", 0, 112).should == "112"
+ @method.call("%2$o", 0, 87).should == "127"
+ @method.call("%2$u", 0, 112).should == "112"
+ @method.call("%2$x", 0, 196).should == "c4"
+ @method.call("%2$X", 0, 196).should == "C4"
+
+ @method.call("%2$e", 0, 109.52).should == "1.095200e+02"
+ @method.call("%2$E", 0, 109.52).should == "1.095200E+02"
+ @method.call("%2$f", 0, 10.952).should == "10.952000"
+ @method.call("%2$g", 0, 12.1234).should == "12.1234"
+ @method.call("%2$G", 0, 12.1234).should == "12.1234"
+ @method.call("%2$a", 0, 196).should == "0x1.88p+7"
+ @method.call("%2$A", 0, 196).should == "0X1.88P+7"
+
+ @method.call("%2$c", 1, 97).should == "a"
+ @method.call("%2$p", "a", []).should == "[]"
+ @method.call("%2$s", "-", "abc").should == "abc"
+ end
+
+ it "raises exception if argument number is bigger than actual arguments list" do
+ -> {
+ @method.call("%4$d", 1, 2, 3)
+ }.should.raise(ArgumentError)
+ end
+
+ it "ignores '-' sign" do
+ @method.call("%2$d", 1, 2, 3).should == "2"
+ @method.call("%-2$d", 1, 2, 3).should == "2"
+ end
+
+ it "raises ArgumentError exception when absolute and relative argument numbers are mixed" do
+ -> {
+ @method.call("%1$d %d", 1, 2)
+ }.should.raise(ArgumentError)
+ end
+ end
+
+ describe "#" do
+ context "applies to format o" do
+ it "increases the precision until the first digit will be `0' if it is not formatted as complements" do
+ @method.call("%#o", 87).should == "0127"
+ end
+
+ it "does nothing for negative argument" do
+ @method.call("%#o", -87).should == "..7651"
+ end
+ end
+
+ context "applies to formats bBxX" do
+ it "prefixes the result with 0x, 0X, 0b and 0B respectively for non-zero argument" do
+ @method.call("%#b", 10).should == "0b1010"
+ @method.call("%#b", -10).should == "0b..10110"
+ @method.call("%#B", 10).should == "0B1010"
+ @method.call("%#B", -10).should == "0B..10110"
+
+ @method.call("%#x", 196).should == "0xc4"
+ @method.call("%#x", -196).should == "0x..f3c"
+ @method.call("%#X", 196).should == "0XC4"
+ @method.call("%#X", -196).should == "0X..F3C"
+ end
+
+ it "does nothing for zero argument" do
+ @method.call("%#b", 0).should == "0"
+ @method.call("%#B", 0).should == "0"
+
+ @method.call("%#x", 0).should == "0"
+ @method.call("%#X", 0).should == "0"
+ end
+
+ it "does nothing for zero argument when combined with zero precision" do
+ @method.call("%#.0b", 0).should == ""
+ @method.call("%#.0B", 0).should == ""
+
+ @method.call("%#.0x", 0).should == ""
+ @method.call("%#.0X", 0).should == ""
+ end
+ end
+
+ context "applies to format o" do
+ it "does nothing for zero argument" do
+ @method.call("%#o", 0).should == "0"
+ @method.call("%#.1o", 0).should == "0"
+ end
+
+ it "increases the precision if precision zero is requested with zero argument" do
+ @method.call("%#.0o", 0).should == "0"
+ end
+ end
+
+ context "applies to formats aAeEfgG" do
+ it "forces a decimal point to be added, even if no digits follow" do
+ @method.call("%#.0a", 16.25).should == "0x1.p+4"
+ @method.call("%#.0A", 16.25).should == "0X1.P+4"
+
+ @method.call("%#.0e", 100).should == "1.e+02"
+ @method.call("%#.0E", 100).should == "1.E+02"
+
+ @method.call("%#.0f", 123.4).should == "123."
+
+ @method.call("%#g", 123456).should == "123456."
+ @method.call("%#G", 123456).should == "123456."
+ end
+
+ it "changes format from dd.dddd to exponential form for gG" do
+ @method.call("%#.0g", 123.4).should_not == "123."
+ @method.call("%#.0g", 123.4).should == "1.e+02"
+ end
+ end
+
+ context "applies to gG" do
+ it "does not remove trailing zeros" do
+ @method.call("%#g", 123.4).should == "123.400"
+ @method.call("%#g", 123.4).should == "123.400"
+ end
+ end
+ end
+
+ describe "+" do
+ context "applies to numeric formats bBdiouxXaAeEfgG" do
+ it "adds a leading plus sign to non-negative numbers" do
+ @method.call("%+b", 10).should == "+1010"
+ @method.call("%+B", 10).should == "+1010"
+ @method.call("%+d", 112).should == "+112"
+ @method.call("%+i", 112).should == "+112"
+ @method.call("%+o", 87).should == "+127"
+ @method.call("%+u", 112).should == "+112"
+ @method.call("%+x", 196).should == "+c4"
+ @method.call("%+X", 196).should == "+C4"
+
+ @method.call("%+e", 109.52).should == "+1.095200e+02"
+ @method.call("%+E", 109.52).should == "+1.095200E+02"
+ @method.call("%+f", 10.952).should == "+10.952000"
+ @method.call("%+g", 12.1234).should == "+12.1234"
+ @method.call("%+G", 12.1234).should == "+12.1234"
+ @method.call("%+a", 196).should == "+0x1.88p+7"
+ @method.call("%+A", 196).should == "+0X1.88P+7"
+ end
+
+ it "does not use two's complement form for negative numbers for formats bBoxX" do
+ @method.call("%+b", -10).should == "-1010"
+ @method.call("%+B", -10).should == "-1010"
+ @method.call("%+o", -87).should == "-127"
+ @method.call("%+x", -196).should == "-c4"
+ @method.call("%+X", -196).should == "-C4"
+ end
+ end
+ end
+
+ describe "-" do
+ it "left-justifies the result of conversion if width is specified" do
+ @method.call("%-10b", 10).should == "1010 "
+ @method.call("%-10B", 10).should == "1010 "
+ @method.call("%-10d", 112).should == "112 "
+ @method.call("%-10i", 112).should == "112 "
+ @method.call("%-10o", 87).should == "127 "
+ @method.call("%-10u", 112).should == "112 "
+ @method.call("%-10x", 196).should == "c4 "
+ @method.call("%-10X", 196).should == "C4 "
+
+ @method.call("%-20e", 109.52).should == "1.095200e+02 "
+ @method.call("%-20E", 109.52).should == "1.095200E+02 "
+ @method.call("%-20f", 10.952).should == "10.952000 "
+ @method.call("%-20g", 12.1234).should == "12.1234 "
+ @method.call("%-20G", 12.1234).should == "12.1234 "
+ @method.call("%-20a", 196).should == "0x1.88p+7 "
+ @method.call("%-20A", 196).should == "0X1.88P+7 "
+
+ @method.call("%-10c", 97).should == "a "
+ @method.call("%-10p", []).should == "[] "
+ @method.call("%-10s", "abc").should == "abc "
+ end
+ end
+
+ describe "0 (zero)" do
+ context "applies to numeric formats bBdiouxXaAeEfgG and width is specified" do
+ it "pads with zeros, not spaces" do
+ @method.call("%010b", 10).should == "0000001010"
+ @method.call("%010B", 10).should == "0000001010"
+ @method.call("%010d", 112).should == "0000000112"
+ @method.call("%010i", 112).should == "0000000112"
+ @method.call("%010o", 87).should == "0000000127"
+ @method.call("%010u", 112).should == "0000000112"
+ @method.call("%010x", 196).should == "00000000c4"
+ @method.call("%010X", 196).should == "00000000C4"
+
+ @method.call("%020e", 109.52).should == "000000001.095200e+02"
+ @method.call("%020E", 109.52).should == "000000001.095200E+02"
+ @method.call("%020f", 10.952).should == "0000000000010.952000"
+ @method.call("%020g", 12.1234).should == "000000000000012.1234"
+ @method.call("%020G", 12.1234).should == "000000000000012.1234"
+ @method.call("%020a", 196).should == "0x000000000001.88p+7"
+ @method.call("%020A", 196).should == "0X000000000001.88P+7"
+ end
+
+ it "uses radix-1 when displays negative argument as a two's complement" do
+ @method.call("%010b", -10).should == "..11110110"
+ @method.call("%010B", -10).should == "..11110110"
+ @method.call("%010o", -87).should == "..77777651"
+ @method.call("%010x", -196).should == "..ffffff3c"
+ @method.call("%010X", -196).should == "..FFFFFF3C"
+ end
+ end
+ end
+
+ describe "*" do
+ it "uses the previous argument as the field width" do
+ @method.call("%*b", 10, 10).should == " 1010"
+ @method.call("%*B", 10, 10).should == " 1010"
+ @method.call("%*d", 10, 112).should == " 112"
+ @method.call("%*i", 10, 112).should == " 112"
+ @method.call("%*o", 10, 87).should == " 127"
+ @method.call("%*u", 10, 112).should == " 112"
+ @method.call("%*x", 10, 196).should == " c4"
+ @method.call("%*X", 10, 196).should == " C4"
+
+ @method.call("%*e", 20, 109.52).should == " 1.095200e+02"
+ @method.call("%*E", 20, 109.52).should == " 1.095200E+02"
+ @method.call("%*f", 20, 10.952).should == " 10.952000"
+ @method.call("%*g", 20, 12.1234).should == " 12.1234"
+ @method.call("%*G", 20, 12.1234).should == " 12.1234"
+ @method.call("%*a", 20, 196).should == " 0x1.88p+7"
+ @method.call("%*A", 20, 196).should == " 0X1.88P+7"
+
+ @method.call("%*c", 10, 97).should == " a"
+ @method.call("%*p", 10, []).should == " []"
+ @method.call("%*s", 10, "abc").should == " abc"
+ end
+
+ it "left-justifies the result if width is negative" do
+ @method.call("%*b", -10, 10).should == "1010 "
+ @method.call("%*B", -10, 10).should == "1010 "
+ @method.call("%*d", -10, 112).should == "112 "
+ @method.call("%*i", -10, 112).should == "112 "
+ @method.call("%*o", -10, 87).should == "127 "
+ @method.call("%*u", -10, 112).should == "112 "
+ @method.call("%*x", -10, 196).should == "c4 "
+ @method.call("%*X", -10, 196).should == "C4 "
+
+ @method.call("%*e", -20, 109.52).should == "1.095200e+02 "
+ @method.call("%*E", -20, 109.52).should == "1.095200E+02 "
+ @method.call("%*f", -20, 10.952).should == "10.952000 "
+ @method.call("%*g", -20, 12.1234).should == "12.1234 "
+ @method.call("%*G", -20, 12.1234).should == "12.1234 "
+ @method.call("%*a", -20, 196).should == "0x1.88p+7 "
+ @method.call("%*A", -20, 196).should == "0X1.88P+7 "
+
+ @method.call("%*c", -10, 97).should == "a "
+ @method.call("%*p", -10, []).should == "[] "
+ @method.call("%*s", -10, "abc").should == "abc "
+ end
+
+ it "uses the specified argument as the width if * is followed by a number and $" do
+ @method.call("%1$*2$b", 10, 10).should == " 1010"
+ @method.call("%1$*2$B", 10, 10).should == " 1010"
+ @method.call("%1$*2$d", 112, 10).should == " 112"
+ @method.call("%1$*2$i", 112, 10).should == " 112"
+ @method.call("%1$*2$o", 87, 10).should == " 127"
+ @method.call("%1$*2$u", 112, 10).should == " 112"
+ @method.call("%1$*2$x", 196, 10).should == " c4"
+ @method.call("%1$*2$X", 196, 10).should == " C4"
+
+ @method.call("%1$*2$e", 109.52, 20).should == " 1.095200e+02"
+ @method.call("%1$*2$E", 109.52, 20).should == " 1.095200E+02"
+ @method.call("%1$*2$f", 10.952, 20).should == " 10.952000"
+ @method.call("%1$*2$g", 12.1234, 20).should == " 12.1234"
+ @method.call("%1$*2$G", 12.1234, 20).should == " 12.1234"
+ @method.call("%1$*2$a", 196, 20).should == " 0x1.88p+7"
+ @method.call("%1$*2$A", 196, 20).should == " 0X1.88P+7"
+
+ @method.call("%1$*2$c", 97, 10).should == " a"
+ @method.call("%1$*2$p", [], 10).should == " []"
+ @method.call("%1$*2$s", "abc", 10).should == " abc"
+ end
+
+ it "left-justifies the result if specified with $ argument is negative" do
+ @method.call("%1$*2$b", 10, -10).should == "1010 "
+ @method.call("%1$*2$B", 10, -10).should == "1010 "
+ @method.call("%1$*2$d", 112, -10).should == "112 "
+ @method.call("%1$*2$i", 112, -10).should == "112 "
+ @method.call("%1$*2$o", 87, -10).should == "127 "
+ @method.call("%1$*2$u", 112, -10).should == "112 "
+ @method.call("%1$*2$x", 196, -10).should == "c4 "
+ @method.call("%1$*2$X", 196, -10).should == "C4 "
+
+ @method.call("%1$*2$e", 109.52, -20).should == "1.095200e+02 "
+ @method.call("%1$*2$E", 109.52, -20).should == "1.095200E+02 "
+ @method.call("%1$*2$f", 10.952, -20).should == "10.952000 "
+ @method.call("%1$*2$g", 12.1234, -20).should == "12.1234 "
+ @method.call("%1$*2$G", 12.1234, -20).should == "12.1234 "
+ @method.call("%1$*2$a", 196, -20).should == "0x1.88p+7 "
+ @method.call("%1$*2$A", 196, -20).should == "0X1.88P+7 "
+
+ @method.call("%1$*2$c", 97, -10).should == "a "
+ @method.call("%1$*2$p", [], -10).should == "[] "
+ @method.call("%1$*2$s", "abc", -10).should == "abc "
+ end
+
+ it "raises ArgumentError when is mixed with width" do
+ -> {
+ @method.call("%*10d", 10, 112)
+ }.should.raise(ArgumentError)
+ end
+ end
+ end
+
+ describe "width" do
+ it "specifies the minimum number of characters that will be written to the result" do
+ @method.call("%10b", 10).should == " 1010"
+ @method.call("%10B", 10).should == " 1010"
+ @method.call("%10d", 112).should == " 112"
+ @method.call("%10i", 112).should == " 112"
+ @method.call("%10o", 87).should == " 127"
+ @method.call("%10u", 112).should == " 112"
+ @method.call("%10x", 196).should == " c4"
+ @method.call("%10X", 196).should == " C4"
+
+ @method.call("%20e", 109.52).should == " 1.095200e+02"
+ @method.call("%20E", 109.52).should == " 1.095200E+02"
+ @method.call("%20f", 10.952).should == " 10.952000"
+ @method.call("%20g", 12.1234).should == " 12.1234"
+ @method.call("%20G", 12.1234).should == " 12.1234"
+ @method.call("%20a", 196).should == " 0x1.88p+7"
+ @method.call("%20A", 196).should == " 0X1.88P+7"
+
+ @method.call("%10c", 97).should == " a"
+ @method.call("%10p", []).should == " []"
+ @method.call("%10s", "abc").should == " abc"
+ end
+
+ it "is ignored if argument's actual length is greater" do
+ @method.call("%5d", 1234567890).should == "1234567890"
+ end
+ end
+
+ describe "precision" do
+ context "integer types" do
+ it "controls the number of decimal places displayed" do
+ @method.call("%.6b", 10).should == "001010"
+ @method.call("%.6B", 10).should == "001010"
+ @method.call("%.5d", 112).should == "00112"
+ @method.call("%.5i", 112).should == "00112"
+ @method.call("%.5o", 87).should == "00127"
+ @method.call("%.5u", 112).should == "00112"
+
+ @method.call("%.5x", 196).should == "000c4"
+ @method.call("%.5X", 196).should == "000C4"
+ end
+ end
+
+ context "float types" do
+ it "controls the number of decimal places displayed in fraction part" do
+ @method.call("%.10e", 109.52).should == "1.0952000000e+02"
+ @method.call("%.10E", 109.52).should == "1.0952000000E+02"
+ @method.call("%.10f", 10.952).should == "10.9520000000"
+ @method.call("%.10a", 196).should == "0x1.8800000000p+7"
+ @method.call("%.10A", 196).should == "0X1.8800000000P+7"
+ end
+
+ it "does not affect G format" do
+ @method.call("%.10g", 12.1234).should == "12.1234"
+ @method.call("%.10g", 123456789).should == "123456789"
+ end
+ end
+
+ context "string formats" do
+ it "determines the maximum number of characters to be copied from the string" do
+ @method.call("%.1p", [1]).should == "["
+ @method.call("%.2p", [1]).should == "[1"
+ @method.call("%.10p", [1]).should == "[1]"
+ @method.call("%.0p", [1]).should == ""
+
+ @method.call("%.1s", "abc").should == "a"
+ @method.call("%.2s", "abc").should == "ab"
+ @method.call("%.10s", "abc").should == "abc"
+ @method.call("%.0s", "abc").should == ""
+ end
+ end
+ end
+
+ describe "reference by name" do
+ describe "%<name>s style" do
+ it "uses value passed in a hash argument" do
+ @method.call("%<foo>d", foo: 123).should == "123"
+ end
+
+ it "supports flags, width, precision and type" do
+ @method.call("%+20.10<foo>f", foo: 10.952).should == " +10.9520000000"
+ end
+
+ it "allows to place name in any position" do
+ @method.call("%+15.5<foo>f", foo: 10.952).should == " +10.95200"
+ @method.call("%+15<foo>.5f", foo: 10.952).should == " +10.95200"
+ @method.call("%+<foo>15.5f", foo: 10.952).should == " +10.95200"
+ @method.call("%<foo>+15.5f", foo: 10.952).should == " +10.95200"
+ end
+
+ it "cannot be mixed with unnamed style" do
+ -> {
+ @method.call("%d %<foo>d", 1, foo: "123")
+ }.should.raise(ArgumentError)
+ end
+ end
+
+ describe "%{name} style" do
+ it "uses value passed in a hash argument" do
+ @method.call("%{foo}", foo: 123).should == "123"
+ end
+
+ it "does not support type style" do
+ @method.call("%{foo}d", foo: 123).should == "123d"
+ end
+
+ it "supports flags, width and precision" do
+ @method.call("%-20.5{foo}", foo: "123456789").should == "12345 "
+ end
+
+ it "cannot be mixed with unnamed style" do
+ -> {
+ @method.call("%d %{foo}", 1, foo: "123")
+ }.should.raise(ArgumentError)
+ end
+
+ it "respects Hash#default when there is no set key" do
+ @method.call("%{foo}", Hash.new(123)).should == "123"
+ @method.call("%{foo}", Hash.new { 123 }).should == "123"
+ end
+
+ it "raises KeyError when Hash#default returns nil" do
+ -> {
+ @method.call("%{foo}", {})
+ }.should.raise(KeyError, 'key{foo} not found')
+
+ -> {
+ @method.call("%{foo}", Hash.new(nil))
+ }.should.raise(KeyError, 'key{foo} not found')
+
+ -> {
+ @method.call("%{foo}", Hash.new { nil })
+ }.should.raise(KeyError, 'key{foo} not found')
+ end
+
+ it "accepts a nil value for an existing key" do
+ @method.call("%{foo}", { foo: nil }).should == ""
+ end
+
+ it "converts value to String with to_s" do
+ obj = Object.new
+ def obj.to_s; end
+ def obj.to_str; end
+
+ obj.should_receive(:to_s).and_return("42")
+ obj.should_not_receive(:to_str)
+
+ @method.call("%{foo}", foo: obj).should == "42"
+ end
+ end
+ end
+
+ describe "faulty key" do
+ before :each do
+ @object = { foooo: 1 }
+ end
+
+ it "raises a KeyError" do
+ -> {
+ @method.call("%<foo>s", @object)
+ }.should.raise(KeyError)
+ end
+
+ it "sets the Hash as the receiver of KeyError" do
+ -> {
+ @method.call("%<foo>s", @object)
+ }.should.raise(KeyError) { |err|
+ err.receiver.should.equal?(@object)
+ }
+ end
+
+ it "sets the unmatched key as the key of KeyError" do
+ -> {
+ @method.call("%<foo>s", @object)
+ }.should.raise(KeyError) { |err|
+ err.key.to_s.should == 'foo'
+ }
+ end
+ end
+
+ it "does not raise error when passed more arguments than needed" do
+ sprintf("%s %d %c", "string", 2, "c", []).should == "string 2 c"
+ end
+
+ describe "when $VERBOSE is true" do
+ it "warns if too many arguments are passed" do
+ -> {
+ format("test", 1)
+ }.should complain(/too many arguments for format string/, verbose: true)
+ end
+
+ it "does not warns if too many keyword arguments are passed" do
+ -> {
+ format("test %{test}", test: 1, unused: 2)
+ }.should_not complain(verbose: true)
+ end
+
+ ruby_bug "#20593", ""..."3.4" do
+ it "doesn't warns if keyword arguments are passed and none are used" do
+ -> {
+ format("test", test: 1)
+ format("test", {})
+ }.should_not complain(verbose: true)
+ end
+ end
+ end
+end
diff --git a/spec/ruby/core/kernel/shared/sprintf_encoding.rb b/spec/ruby/core/kernel/shared/sprintf_encoding.rb
new file mode 100644
index 0000000000..849c95cbb7
--- /dev/null
+++ b/spec/ruby/core/kernel/shared/sprintf_encoding.rb
@@ -0,0 +1,67 @@
+# Keep encoding-related specs in a separate shared example to be able to skip them in IO/File/StringIO specs.
+# It's difficult to check result's encoding in the test after writing to a file/io buffer.
+describe :kernel_sprintf_encoding, shared: true do
+ it "can produce a string with valid encoding" do
+ string = @method.call("good day %{valid}", valid: "e")
+ string.encoding.should == Encoding::UTF_8
+ string.valid_encoding?.should == true
+ end
+
+ it "can produce a string with invalid encoding" do
+ string = @method.call("good day %{invalid}", invalid: "\x80")
+ string.encoding.should == Encoding::UTF_8
+ string.valid_encoding?.should == false
+ end
+
+ it "returns a String in the same encoding as the format String if compatible" do
+ string = "%s".dup.force_encoding(Encoding::KOI8_U)
+ result = @method.call(string, "dogs")
+ result.encoding.should.equal?(Encoding::KOI8_U)
+ end
+
+ it "returns a String in the argument's encoding if format encoding is more restrictive" do
+ string = "foo %s".dup.force_encoding(Encoding::US_ASCII)
+ argument = "b\303\274r".dup.force_encoding(Encoding::UTF_8)
+
+ result = @method.call(string, argument)
+ result.encoding.should.equal?(Encoding::UTF_8)
+ end
+
+ it "raises Encoding::CompatibilityError if both encodings are ASCII compatible and there are not ASCII characters" do
+ string = "Ä %s".encode('windows-1252')
+ argument = "Ђ".encode('windows-1251')
+
+ -> {
+ @method.call(string, argument)
+ }.should.raise(Encoding::CompatibilityError)
+ end
+
+ describe "%c" do
+ it "supports Unicode characters" do
+ result = @method.call("%c", 1286)
+ result.should == "Ô†"
+ result.bytes.should == [212, 134]
+
+ result = @method.call("%c", "Ø´")
+ result.should == "Ø´"
+ result.bytes.should == [216, 180]
+ end
+
+ it "raises error when a codepoint isn't representable in an encoding of a format string" do
+ format = "%c".encode("ASCII")
+
+ -> {
+ @method.call(format, 1286)
+ }.should.raise(RangeError, /out of char range/)
+ end
+
+ it "uses the encoding of the format string to interpret codepoints" do
+ format = "%c".dup.force_encoding("euc-jp")
+ result = @method.call(format, 9415601)
+
+ result.encoding.should == Encoding::EUC_JP
+ result.should == "é".encode(Encoding::EUC_JP)
+ result.bytes.should == [143, 171, 177]
+ end
+ end
+end
diff --git a/spec/ruby/core/kernel/shared/then.rb b/spec/ruby/core/kernel/shared/then.rb
new file mode 100644
index 0000000000..c71393bf50
--- /dev/null
+++ b/spec/ruby/core/kernel/shared/then.rb
@@ -0,0 +1,20 @@
+describe :kernel_then, shared: true do
+ it "yields self" do
+ object = Object.new
+ object.send(@method) { |o| o.should.equal? object }
+ end
+
+ it "returns the block return value" do
+ object = Object.new
+ object.send(@method) { 42 }.should.equal? 42
+ end
+
+ it "returns a sized Enumerator when no block given" do
+ object = Object.new
+ enum = object.send(@method)
+ enum.should.instance_of? Enumerator
+ enum.size.should.equal? 1
+ enum.peek.should.equal? object
+ enum.first.should.equal? object
+ end
+end
diff --git a/spec/ruby/core/kernel/singleton_class_spec.rb b/spec/ruby/core/kernel/singleton_class_spec.rb
index b5e0703905..7915272937 100644
--- a/spec/ruby/core/kernel/singleton_class_spec.rb
+++ b/spec/ruby/core/kernel/singleton_class_spec.rb
@@ -1,3 +1,6 @@
+# truffleruby_primitives: true
+require_relative '../../spec_helper'
+
describe "Kernel#singleton_class" do
it "returns class extended from an object" do
x = Object.new
@@ -17,11 +20,55 @@ describe "Kernel#singleton_class" do
false.singleton_class.should == FalseClass
end
- it "raises TypeError for Fixnum" do
- lambda { 123.singleton_class }.should raise_error(TypeError)
+ it "raises TypeError for Integer" do
+ -> { 123.singleton_class }.should.raise(TypeError, "can't define singleton")
+ end
+
+ it "raises TypeError for Float" do
+ -> { 3.14.singleton_class }.should.raise(TypeError, "can't define singleton")
end
it "raises TypeError for Symbol" do
- lambda { :foo.singleton_class }.should raise_error(TypeError)
+ -> { :foo.singleton_class }.should.raise(TypeError, "can't define singleton")
+ end
+
+ it "raises TypeError for a frozen deduplicated String" do
+ -> { (-"string").singleton_class }.should.raise(TypeError, "can't define singleton")
+ -> { a = -"string"; a.singleton_class }.should.raise(TypeError, "can't define singleton")
+ -> { a = "string"; (-a).singleton_class }.should.raise(TypeError, "can't define singleton")
+ end
+
+ it "returns a frozen singleton class if object is frozen" do
+ obj = Object.new
+ obj.freeze
+ obj.singleton_class.frozen?.should == true
+ end
+
+ context "for an IO object with a replaced singleton class" do
+ it "looks up singleton methods from the fresh singleton class after an object instance got a new one" do
+ proxy = -> io { io.foo }
+ if RUBY_ENGINE == 'truffleruby'
+ # We need an inline cache with only this object seen, the best way to do that is to use a Primitive
+ sclass = -> io { Primitive.singleton_class(io) }
+ else
+ sclass = -> io { io.singleton_class }
+ end
+
+ io = File.new(__FILE__)
+ io.define_singleton_method(:foo) { "old" }
+ sclass1 = sclass.call(io)
+ proxy.call(io).should == "old"
+
+ # IO#reopen is the only method which can replace an object's singleton class
+ io2 = File.new(__FILE__)
+ io.reopen(io2)
+ io.define_singleton_method(:foo) { "new" }
+ sclass2 = sclass.call(io)
+ sclass2.should_not.equal?(sclass1)
+ proxy.call(io).should == "new"
+ ensure
+ io2.close
+ io.close
+ end
end
end
diff --git a/spec/ruby/core/kernel/singleton_method_spec.rb b/spec/ruby/core/kernel/singleton_method_spec.rb
index 77022b40c2..fe8e23eb02 100644
--- a/spec/ruby/core/kernel/singleton_method_spec.rb
+++ b/spec/ruby/core/kernel/singleton_method_spec.rb
@@ -1,10 +1,10 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Kernel#singleton_method" do
- it "find a method defined on the singleton class" do
+ it "finds a method defined on the singleton class" do
obj = Object.new
def obj.foo; end
- obj.singleton_method(:foo).should be_an_instance_of(Method)
+ obj.singleton_method(:foo).should.instance_of?(Method)
end
it "returns a Method which can be called" do
@@ -23,7 +23,7 @@ describe "Kernel#singleton_method" do
obj.foo.should == 42
-> {
obj.singleton_method(:foo)
- }.should raise_error(NameError) { |e|
+ }.should.raise(NameError) { |e|
# a NameError and not a NoMethodError
e.class.should == NameError
}
@@ -33,9 +33,53 @@ describe "Kernel#singleton_method" do
obj = Object.new
-> {
obj.singleton_method(:not_existing)
- }.should raise_error(NameError) { |e|
+ }.should.raise(NameError) { |e|
# a NameError and not a NoMethodError
e.class.should == NameError
}
end
+
+ ruby_bug "#20620", ""..."3.4" do
+ it "finds a method defined in a module included in the singleton class" do
+ m = Module.new do
+ def foo
+ :foo
+ end
+ end
+
+ obj = Object.new
+ obj.singleton_class.include(m)
+
+ obj.singleton_method(:foo).should.instance_of?(Method)
+ obj.singleton_method(:foo).call.should == :foo
+ end
+
+ it "finds a method defined in a module prepended in the singleton class" do
+ m = Module.new do
+ def foo
+ :foo
+ end
+ end
+
+ obj = Object.new
+ obj.singleton_class.prepend(m)
+
+ obj.singleton_method(:foo).should.instance_of?(Method)
+ obj.singleton_method(:foo).call.should == :foo
+ end
+
+ it "finds a method defined in a module that an object is extended with" do
+ m = Module.new do
+ def foo
+ :foo
+ end
+ end
+
+ obj = Object.new
+ obj.extend(m)
+
+ obj.singleton_method(:foo).should.instance_of?(Method)
+ obj.singleton_method(:foo).call.should == :foo
+ end
+ end
end
diff --git a/spec/ruby/core/kernel/singleton_methods_spec.rb b/spec/ruby/core/kernel/singleton_methods_spec.rb
index 596e5ddad2..a7f6969519 100644
--- a/spec/ruby/core/kernel/singleton_methods_spec.rb
+++ b/spec/ruby/core/kernel/singleton_methods_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../fixtures/reflection', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../../fixtures/reflection'
+require_relative 'fixtures/classes'
describe :kernel_singleton_methods, shared: true do
it "returns an empty Array for an object with no singleton methods" do
@@ -8,39 +8,52 @@ describe :kernel_singleton_methods, shared: true do
end
it "returns the names of module methods for a module" do
- ReflectSpecs::M.singleton_methods(*@object).should include(:ms_pro, :ms_pub)
+ ReflectSpecs::M.singleton_methods(*@object).to_set.should >= Set[:ms_pro, :ms_pub]
end
it "does not return private module methods for a module" do
- ReflectSpecs::M.singleton_methods(*@object).should_not include(:ms_pri)
+ ReflectSpecs::M.singleton_methods(*@object).should_not.include?(:ms_pri)
end
it "returns the names of class methods for a class" do
- ReflectSpecs::A.singleton_methods(*@object).should include(:as_pro, :as_pub)
+ ReflectSpecs::A.singleton_methods(*@object).to_set.should >= Set[:as_pro, :as_pub]
end
it "does not return private class methods for a class" do
- ReflectSpecs::A.singleton_methods(*@object).should_not include(:as_pri)
+ ReflectSpecs::A.singleton_methods(*@object).should_not.include?(:as_pri)
end
it "returns the names of singleton methods for an object" do
- ReflectSpecs.os.singleton_methods(*@object).should include(:os_pro, :os_pub)
+ ReflectSpecs.os.singleton_methods(*@object).to_set.should >= Set[:os_pro, :os_pub]
end
end
describe :kernel_singleton_methods_modules, shared: true do
it "does not return any included methods for a module including a module" do
- ReflectSpecs::N.singleton_methods(*@object).should include(:ns_pro, :ns_pub)
+ ReflectSpecs::N.singleton_methods(*@object).to_set.should >= Set[:ns_pro, :ns_pub]
end
it "does not return any included methods for a class including a module" do
- ReflectSpecs::D.singleton_methods(*@object).should include(:ds_pro, :ds_pub)
+ ReflectSpecs::D.singleton_methods(*@object).to_set.should >= Set[:ds_pro, :ds_pub]
+ end
+
+ it "for a module does not return methods in a module prepended to Module itself" do
+ require_relative 'fixtures/singleton_methods'
+ mod = SingletonMethodsSpecs::SelfExtending
+ mod.method(:mspec_test_kernel_singleton_methods).owner.should == SingletonMethodsSpecs::Prepended
+
+ ancestors = mod.singleton_class.ancestors
+ ancestors[0...2].should == [ mod.singleton_class, mod ]
+ ancestors.should.include?(SingletonMethodsSpecs::Prepended)
+
+ # Do not search prepended modules of `Module`, as that's a non-singleton class
+ mod.singleton_methods.should == []
end
end
describe :kernel_singleton_methods_supers, shared: true do
- it "returns the names of singleton methods for an object extented with a module" do
- ReflectSpecs.oe.singleton_methods(*@object).should include(:m_pro, :m_pub)
+ it "returns the names of singleton methods for an object extended with a module" do
+ ReflectSpecs.oe.singleton_methods(*@object).to_set.should >= Set[:m_pro, :m_pub]
end
it "returns a unique list for an object extended with a module" do
@@ -49,16 +62,16 @@ describe :kernel_singleton_methods_supers, shared: true do
r.should == [:pro, :pub]
end
- it "returns the names of singleton methods for an object extented with two modules" do
- ReflectSpecs.oee.singleton_methods(*@object).should include(:m_pro, :m_pub, :n_pro, :n_pub)
+ it "returns the names of singleton methods for an object extended with two modules" do
+ ReflectSpecs.oee.singleton_methods(*@object).to_set.should >= Set[:m_pro, :m_pub, :n_pro, :n_pub]
end
- it "returns the names of singleton methods for an object extented with a module including a module" do
- ReflectSpecs.oei.singleton_methods(*@object).should include(:n_pro, :n_pub, :m_pro, :m_pub)
+ it "returns the names of singleton methods for an object extended with a module including a module" do
+ ReflectSpecs.oei.singleton_methods(*@object).to_set.should >= Set[:n_pro, :n_pub, :m_pro, :m_pub]
end
it "returns the names of inherited singleton methods for a subclass" do
- ReflectSpecs::B.singleton_methods(*@object).should include(:as_pro, :as_pub, :bs_pro, :bs_pub)
+ ReflectSpecs::B.singleton_methods(*@object).to_set.should >= Set[:as_pro, :as_pub, :bs_pro, :bs_pub]
end
it "returns a unique list for a subclass" do
@@ -68,7 +81,7 @@ describe :kernel_singleton_methods_supers, shared: true do
end
it "returns the names of inherited singleton methods for a subclass including a module" do
- ReflectSpecs::C.singleton_methods(*@object).should include(:as_pro, :as_pub, :cs_pro, :cs_pub)
+ ReflectSpecs::C.singleton_methods(*@object).to_set.should >= Set[:as_pro, :as_pub, :cs_pro, :cs_pub]
end
it "returns a unique list for a subclass including a module" do
@@ -78,57 +91,62 @@ describe :kernel_singleton_methods_supers, shared: true do
end
it "returns the names of inherited singleton methods for a subclass of a class including a module" do
- ReflectSpecs::E.singleton_methods(*@object).should include(:ds_pro, :ds_pub, :es_pro, :es_pub)
+ ReflectSpecs::E.singleton_methods(*@object).to_set.should >= Set[:ds_pro, :ds_pub, :es_pro, :es_pub]
end
it "returns the names of inherited singleton methods for a subclass of a class that includes a module, where the subclass also includes a module" do
- ReflectSpecs::F.singleton_methods(*@object).should include(:ds_pro, :ds_pub, :fs_pro, :fs_pub)
+ ReflectSpecs::F.singleton_methods(*@object).to_set.should >= Set[:ds_pro, :ds_pub, :fs_pro, :fs_pub]
end
it "returns the names of inherited singleton methods for a class extended with a module" do
- ReflectSpecs::P.singleton_methods(*@object).should include(:m_pro, :m_pub)
+ ReflectSpecs::P.singleton_methods(*@object).to_set.should >= Set[:m_pro, :m_pub]
end
end
describe :kernel_singleton_methods_private_supers, shared: true do
it "does not return private singleton methods for an object extended with a module" do
- ReflectSpecs.oe.singleton_methods(*@object).should_not include(:m_pri)
+ ReflectSpecs.oe.singleton_methods(*@object).should_not.include?(:m_pri)
end
it "does not return private singleton methods for an object extended with two modules" do
- ReflectSpecs.oee.singleton_methods(*@object).should_not include(:m_pri)
+ ReflectSpecs.oee.singleton_methods(*@object).should_not.include?(:m_pri)
end
- it "does not return private singleton methods for an object extented with a module including a module" do
- ReflectSpecs.oei.singleton_methods(*@object).should_not include(:n_pri, :m_pri)
+ it "does not return private singleton methods for an object extended with a module including a module" do
+ ReflectSpecs.oei.singleton_methods(*@object).should_not.include?(:n_pri)
+ ReflectSpecs.oei.singleton_methods(*@object).should_not.include?(:m_pri)
end
it "does not return private singleton methods for a class extended with a module" do
- ReflectSpecs::P.singleton_methods(*@object).should_not include(:m_pri)
+ ReflectSpecs::P.singleton_methods(*@object).should_not.include?(:m_pri)
end
it "does not return private inherited singleton methods for a module including a module" do
- ReflectSpecs::N.singleton_methods(*@object).should_not include(:ns_pri)
+ ReflectSpecs::N.singleton_methods(*@object).should_not.include?(:ns_pri)
end
it "does not return private inherited singleton methods for a class including a module" do
- ReflectSpecs::D.singleton_methods(*@object).should_not include(:ds_pri)
+ ReflectSpecs::D.singleton_methods(*@object).should_not.include?(:ds_pri)
end
it "does not return private inherited singleton methods for a subclass" do
- ReflectSpecs::B.singleton_methods(*@object).should_not include(:as_pri, :bs_pri)
+ ReflectSpecs::B.singleton_methods(*@object).should_not.include?(:as_pri)
+ ReflectSpecs::B.singleton_methods(*@object).should_not.include?(:bs_pri)
end
it "does not return private inherited singleton methods for a subclass including a module" do
- ReflectSpecs::C.singleton_methods(*@object).should_not include(:as_pri, :cs_pri)
+ ReflectSpecs::C.singleton_methods(*@object).should_not.include?(:as_pri)
+ ReflectSpecs::C.singleton_methods(*@object).should_not.include?(:cs_pri)
end
it "does not return private inherited singleton methods for a subclass of a class including a module" do
- ReflectSpecs::E.singleton_methods(*@object).should_not include(:ds_pri, :es_pri)
+ ReflectSpecs::E.singleton_methods(*@object).should_not.include?(:ds_pri)
+ ReflectSpecs::E.singleton_methods(*@object).should_not.include?(:es_pri)
end
it "does not return private inherited singleton methods for a subclass of a class that includes a module, where the subclass also includes a module" do
- ReflectSpecs::F.singleton_methods(*@object).should_not include(:ds_pri, :fs_pri)
+ ReflectSpecs::F.singleton_methods(*@object).should_not.include?(:ds_pri)
+ ReflectSpecs::F.singleton_methods(*@object).should_not.include?(:fs_pri)
end
end
@@ -145,7 +163,6 @@ describe "Kernel#singleton_methods" do
it_behaves_like :kernel_singleton_methods_supers, nil, true
it_behaves_like :kernel_singleton_methods_modules, nil, true
it_behaves_like :kernel_singleton_methods_private_supers, nil, true
-
end
describe "when passed false" do
@@ -153,11 +170,11 @@ describe "Kernel#singleton_methods" do
it_behaves_like :kernel_singleton_methods_modules, nil, false
it_behaves_like :kernel_singleton_methods_private_supers, nil, false
- it "returns an empty Array for an object extented with a module" do
+ it "returns an empty Array for an object extended with a module" do
ReflectSpecs.oe.singleton_methods(false).should == []
end
- it "returns an empty Array for an object extented with two modules" do
+ it "returns an empty Array for an object extended with two modules" do
ReflectSpecs.oee.singleton_methods(false).should == []
end
@@ -166,15 +183,17 @@ describe "Kernel#singleton_methods" do
end
it "returns the names of singleton methods of the subclass" do
- ReflectSpecs::B.singleton_methods(false).should include(:bs_pro, :bs_pub)
+ ReflectSpecs::B.singleton_methods(false).to_set.should >= Set[:bs_pro, :bs_pub]
end
it "does not return names of inherited singleton methods for a subclass" do
- ReflectSpecs::B.singleton_methods(false).should_not include(:as_pro, :as_pub)
+ ReflectSpecs::B.singleton_methods(false).should_not.include?(:as_pro)
+ ReflectSpecs::B.singleton_methods(false).should_not.include?(:as_pub)
end
it "does not return the names of inherited singleton methods for a class extended with a module" do
- ReflectSpecs::P.singleton_methods(false).should_not include(:m_pro, :m_pub)
+ ReflectSpecs::P.singleton_methods(false).should_not.include?(:m_pro)
+ ReflectSpecs::P.singleton_methods(false).should_not.include?(:m_pub)
end
end
end
diff --git a/spec/ruby/core/kernel/sleep_spec.rb b/spec/ruby/core/kernel/sleep_spec.rb
index bcb0060aa3..61d8cc2380 100644
--- a/spec/ruby/core/kernel/sleep_spec.rb
+++ b/spec/ruby/core/kernel/sleep_spec.rb
@@ -1,34 +1,40 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../fiber/fixtures/scheduler'
describe "Kernel#sleep" do
it "is a private method" do
- Kernel.should have_private_instance_method(:sleep)
+ Kernel.private_instance_methods(false).should.include?(:sleep)
+ end
+
+ it "returns an Integer" do
+ sleep(0.001).should.is_a?(Integer)
end
it "accepts a Float" do
- sleep(0.1).should be_close(0, 2)
+ sleep(0.001).should >= 0
end
- it "accepts a Fixnum" do
- sleep(0).should be_close(0, 2)
+ it "accepts an Integer" do
+ sleep(0).should >= 0
end
it "accepts a Rational" do
- sleep(Rational(1, 9)).should be_close(0, 2)
+ sleep(Rational(1, 999)).should >= 0
end
- it "raises an ArgumentError when passed a negative duration" do
- lambda { sleep(-0.1) }.should raise_error(ArgumentError)
- lambda { sleep(-1) }.should raise_error(ArgumentError)
+ it "accepts any Object that responds to divmod" do
+ o = Object.new
+ def o.divmod(*); [0, 0.001]; end
+ sleep(o).should >= 0
end
- it "raises a TypeError when passed nil" do
- lambda { sleep(nil) }.should raise_error(TypeError)
+ it "raises an ArgumentError when passed a negative duration" do
+ -> { sleep(-0.1) }.should.raise(ArgumentError)
+ -> { sleep(-1) }.should.raise(ArgumentError)
end
it "raises a TypeError when passed a String" do
- lambda { sleep('2') }.should raise_error(TypeError)
+ -> { sleep('2') }.should.raise(TypeError)
end
it "pauses execution indefinitely if not given a duration" do
@@ -45,6 +51,66 @@ describe "Kernel#sleep" do
t.wakeup
t.value.should == 5
end
+
+ it "sleeps with nanosecond precision" do
+ start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
+ 100.times do
+ sleep(0.0001)
+ end
+ end_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
+
+ actual_duration = end_time - start_time
+ actual_duration.should > 0.01 # 100 * 0.0001 => 0.01
+ end
+
+ it "accepts a nil duration" do
+ running = false
+ t = Thread.new do
+ running = true
+ sleep(nil)
+ 5
+ end
+
+ Thread.pass until running
+ Thread.pass while t.status and t.status != "sleep"
+
+ t.wakeup
+ t.value.should == 5
+ end
+
+ context "Kernel.sleep with Fiber scheduler" do
+ before :each do
+ Fiber.set_scheduler(FiberSpecs::LoggingScheduler.new)
+ end
+
+ after :each do
+ Fiber.set_scheduler(nil)
+ end
+
+ it "calls the scheduler without arguments when no duration is given" do
+ sleeper = Fiber.new(blocking: false) do
+ sleep
+ end
+ sleeper.resume
+ Fiber.scheduler.events.should == [{ event: :kernel_sleep, fiber: sleeper, args: [] }]
+ end
+
+ it "calls the scheduler with the given duration" do
+ sleeper = Fiber.new(blocking: false) do
+ sleep(0.01)
+ end
+ sleeper.resume
+ Fiber.scheduler.events.should == [{ event: :kernel_sleep, fiber: sleeper, args: [0.01] }]
+ end
+
+ it "does not call the scheduler if the fiber is blocking" do
+ sleeper = Fiber.new(blocking: true) do
+ sleep(0.01)
+ end
+ sleeper.resume
+ Fiber.scheduler.events.should == []
+ end
+ end
end
describe "Kernel.sleep" do
diff --git a/spec/ruby/core/kernel/spawn_spec.rb b/spec/ruby/core/kernel/spawn_spec.rb
index ad937b17dd..3432fc31da 100644
--- a/spec/ruby/core/kernel/spawn_spec.rb
+++ b/spec/ruby/core/kernel/spawn_spec.rb
@@ -1,16 +1,16 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
# These specs only run a basic usage of #spawn.
# Process.spawn has more complete specs and they are not
# run here as it is redundant and takes too long for little gain.
describe "Kernel#spawn" do
it "is a private method" do
- Kernel.should have_private_instance_method(:spawn)
+ Kernel.private_instance_methods(false).should.include?(:spawn)
end
it "executes the given command" do
- lambda {
+ -> {
Process.wait spawn("echo spawn")
}.should output_to_fd("spawn\n")
end
@@ -18,7 +18,7 @@ end
describe "Kernel.spawn" do
it "executes the given command" do
- lambda {
+ -> {
Process.wait Kernel.spawn("echo spawn")
}.should output_to_fd("spawn\n")
end
diff --git a/spec/ruby/core/kernel/sprintf_spec.rb b/spec/ruby/core/kernel/sprintf_spec.rb
index 984f31dc7f..5a4a90ff7a 100644
--- a/spec/ruby/core/kernel/sprintf_spec.rb
+++ b/spec/ruby/core/kernel/sprintf_spec.rb
@@ -1,310 +1,64 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-
-describe "Kernel#sprintf" do
- it "is a private method" do
- Kernel.should have_private_instance_method(:sprintf)
- end
-
- it "treats nil arguments as zero-width strings in %s slots" do
- sprintf("%s%d%s%s", nil, 4, 'a', 'b').should == '4ab'
- end
-
- it "passes some tests for positive %x" do
- sprintf("%x", 123).should == "7b"
- sprintf("%0x", 123).should == "7b"
- sprintf("% x", 123).should == " 7b"
- sprintf("%+x", 123).should == "+7b"
- sprintf("%+0x", 123).should == "+7b"
- sprintf("%+ x", 123).should == "+7b"
- sprintf("% 0x", 123).should == " 7b"
-
- sprintf("%#x", 123).should == "0x7b"
- sprintf("%#0x", 123).should == "0x7b"
- sprintf("%# x", 123).should == " 0x7b"
- sprintf("%#+x", 123).should == "+0x7b"
- sprintf("%#+0x", 123).should == "+0x7b"
- sprintf("%#+ x", 123).should == "+0x7b"
- sprintf("%# 0x", 123).should == " 0x7b"
-
- sprintf("%8x", 123).should == " 7b"
- sprintf("%08x", 123).should == "0000007b"
- sprintf("% 8x", 123).should == " 7b"
- sprintf("%+8x", 123).should == " +7b"
- sprintf("%+08x", 123).should == "+000007b"
- sprintf("%+ 8x", 123).should == " +7b"
- sprintf("% 08x", 123).should == " 000007b"
-
- sprintf("%#8x", 123).should == " 0x7b"
- sprintf("%#08x", 123).should == "0x00007b"
- sprintf("%# 8x", 123).should == " 0x7b"
- sprintf("%#+8x", 123).should == " +0x7b"
- sprintf("%#+08x", 123).should == "+0x0007b"
- sprintf("%#+ 8x", 123).should == " +0x7b"
- sprintf("%# 08x", 123).should == " 0x0007b"
-
- sprintf("%8.10x", 123).should == "000000007b"
- sprintf("%08.10x", 123).should == "000000007b"
- sprintf("% 8.10x", 123).should == " 000000007b"
- sprintf("%+8.10x", 123).should == "+000000007b"
- sprintf("%+08.10x", 123).should == "+000000007b"
- sprintf("%+ 8.10x", 123).should == "+000000007b"
- sprintf("% 08.10x", 123).should == " 000000007b"
-
- sprintf("%10.8x", 123).should == " 0000007b"
- sprintf("%010.8x", 123).should == " 0000007b"
- sprintf("% 10.8x", 123).should == " 0000007b"
- sprintf("%+10.8x", 123).should == " +0000007b"
- sprintf("%+010.8x", 123).should == " +0000007b"
- sprintf("%+ 10.8x", 123).should == " +0000007b"
- sprintf("% 010.8x", 123).should == " 0000007b"
- end
-
- describe "with format string that contains %{} sections" do
- it "substitutes values for named references" do
- sprintf("%{foo}f", {foo: 1}).should == "1f"
- end
-
- it "raises KeyError when no matching key is in second argument" do
- lambda { sprintf("%{foo}f", {}) }.should raise_error(KeyError)
- end
- end
-
- describe "with format string that contains %<> sections" do
- it "formats values for named references" do
- sprintf("%<foo>f", {foo: 1}).should == "1.000000"
- end
-
- it "raises KeyError when no matching key is in second argument" do
- lambda { sprintf("%<foo>f", {}) }.should raise_error(KeyError)
- end
-
- it "raises ArgumentError if missing second named argument" do
- lambda { sprintf("%<key><foo>d", {key: 1}) }.should raise_error(ArgumentError)
- end
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/sprintf'
+require_relative 'shared/sprintf_encoding'
+
+describe :kernel_sprintf_to_str, shared: true do
+ it "calls #to_str to convert the format object to a String" do
+ obj = mock('format string')
+ obj.should_receive(:to_str).and_return("to_str: %i")
+ @method.call(obj, 42).should == "to_str: 42"
end
+end
- describe "with negative values" do
- describe "with format %x" do
- it "precedes the number with '..'" do
- sprintf("%0x", -123).should == "..f85"
- sprintf("%#0x", -123).should == "0x..f85"
- sprintf("%08x", -123).should == "..ffff85"
- sprintf("%#08x", -123).should == "0x..ff85"
- sprintf("%8.10x", -123).should == "..ffffff85"
- sprintf("%08.10x", -123).should == "..ffffff85"
- sprintf("%10.8x", -123).should == " ..ffff85"
- sprintf("%010.8x", -123).should == " ..ffff85"
- end
- end
-
- describe "with format %b or %B" do
- it "precedes the number with '..'" do
- sprintf("%.7b", -5).should == "..11011"
- sprintf("%.7B", -5).should == "..11011"
- sprintf("%0b", -5).should == "..1011"
- end
- end
- end
-
- it "passes some tests for negative %x" do
- sprintf("%x", -123).should == "..f85"
- sprintf("% x", -123).should == "-7b"
- sprintf("%+x", -123).should == "-7b"
- sprintf("%+0x", -123).should == "-7b"
- sprintf("%+ x", -123).should == "-7b"
- sprintf("% 0x", -123).should == "-7b"
-
- sprintf("%#x", -123).should == "0x..f85"
- sprintf("%# x", -123).should == "-0x7b"
- sprintf("%#+x", -123).should == "-0x7b"
- sprintf("%#+0x", -123).should == "-0x7b"
- sprintf("%#+ x", -123).should == "-0x7b"
- sprintf("%# 0x", -123).should == "-0x7b"
-
- sprintf("%8x", -123).should == " ..f85"
- sprintf("% 8x", -123).should == " -7b"
- sprintf("%+8x", -123).should == " -7b"
- sprintf("%+08x", -123).should == "-000007b"
- sprintf("%+ 8x", -123).should == " -7b"
- sprintf("% 08x", -123).should == "-000007b"
-
- sprintf("%#8x", -123).should == " 0x..f85"
- sprintf("%# 8x", -123).should == " -0x7b"
- sprintf("%#+8x", -123).should == " -0x7b"
- sprintf("%#+08x", -123).should == "-0x0007b"
- sprintf("%#+ 8x", -123).should == " -0x7b"
- sprintf("%# 08x", -123).should == "-0x0007b"
-
- sprintf("% 8.10x", -123).should == "-000000007b"
- sprintf("%+8.10x", -123).should == "-000000007b"
- sprintf("%+08.10x", -123).should == "-000000007b"
- sprintf("%+ 8.10x", -123).should == "-000000007b"
- sprintf("% 08.10x", -123).should == "-000000007b"
-
- sprintf("% 10.8x", -123).should == " -0000007b"
- sprintf("%+10.8x", -123).should == " -0000007b"
- sprintf("%+010.8x", -123).should == " -0000007b"
- sprintf("%+ 10.8x", -123).should == " -0000007b"
- sprintf("% 010.8x", -123).should == " -0000007b"
- end
-
- it "passes some tests for negative %u" do
- sprintf("%u", -123).should == "-123"
- sprintf("%0u", -123).should == "-123"
- sprintf("%#u", -123).should == "-123"
- sprintf("%#0u", -123).should == "-123"
- sprintf("%8u", -123).should == " -123"
- sprintf("%08u", -123).should == "-0000123"
- sprintf("%#8u", -123).should == " -123"
- sprintf("%#08u", -123).should == "-0000123"
-
- sprintf("%30u", -123).should == " -123"
- sprintf("%030u", -123).should == "-00000000000000000000000000123"
-
- sprintf("%#30u", -123).should == " -123"
- sprintf("%#030u", -123).should == "-00000000000000000000000000123"
-
- sprintf("%24.30u", -123).should == "-000000000000000000000000000123"
- sprintf("%024.30u", -123).should == "-000000000000000000000000000123"
-
- sprintf("%#24.30u", -123).should == "-000000000000000000000000000123"
- sprintf("%#024.30u", -123).should == "-000000000000000000000000000123"
-
-
- sprintf("%30.24u", -123).should == " -000000000000000000000123"
- sprintf("%030.24u", -123).should == " -000000000000000000000123"
-
- sprintf("%#30.24u", -123).should == " -000000000000000000000123"
- sprintf("%#030.24u", -123).should == " -000000000000000000000123"
- end
-
- it "passes some tests for positive %u" do
- sprintf("%30u", 123).should == " 123"
- sprintf("%030u", 123).should == "000000000000000000000000000123"
-
- sprintf("%#30u", 123).should == " 123"
- sprintf("%#030u", 123).should == "000000000000000000000000000123"
-
- sprintf("%24.30u", 123).should == "000000000000000000000000000123"
- sprintf("%024.30u", 123).should == "000000000000000000000000000123"
-
- sprintf("%#24.30u", 123).should == "000000000000000000000000000123"
- sprintf("%#024.30u", 123).should == "000000000000000000000000000123"
-
- sprintf("%30.24u", 123).should == " 000000000000000000000123"
- sprintf("%030.24u", 123).should == " 000000000000000000000123"
-
- sprintf("%#30.24u", 123).should == " 000000000000000000000123"
- sprintf("%#030.24u", 123).should == " 000000000000000000000123"
- end
-
- it "passes some tests for positive %d" do
- sprintf("%30d", 123).should == " 123"
- sprintf("%030d", 123).should == "000000000000000000000000000123"
-
- sprintf("%#30d", 123).should == " 123"
- sprintf("%#030d", 123).should == "000000000000000000000000000123"
-
- sprintf("%24.30d", 123).should == "000000000000000000000000000123"
- sprintf("%024.30d", 123).should == "000000000000000000000000000123"
-
- sprintf("%#24.30d", 123).should == "000000000000000000000000000123"
- sprintf("%#024.30d", 123).should == "000000000000000000000000000123"
-
- sprintf("%30.24d", 123).should == " 000000000000000000000123"
- sprintf("%030.24d", 123).should == " 000000000000000000000123"
-
- sprintf("%#30.24d", 123).should == " 000000000000000000000123"
- sprintf("%#030.24d", 123).should == " 000000000000000000000123"
- end
-
- it "passes some tests for positive %f" do
- sprintf("%30f", 123.1).should == " 123.100000"
- sprintf("%030f", 123.1).should == "00000000000000000000123.100000"
-
- sprintf("%#30f", 123.1).should == " 123.100000"
- sprintf("%#030f", 123.1).should == "00000000000000000000123.100000"
-
- sprintf("%10.4f", 123.1).should == " 123.1000"
- sprintf("%010.4f", 123.1).should == "00123.1000"
-
- sprintf("%10.0f", 123.1).should == " 123"
- sprintf("%010.0f", 123.1).should == "0000000123"
- end
-
- it "passes some tests for negative %f" do
- sprintf("%30f", -123.5).should == " -123.500000"
- sprintf("%030f", -123.5).should == "-0000000000000000000123.500000"
-
- sprintf("%#30f", -123.5).should == " -123.500000"
- sprintf("%#030f", -123.5).should == "-0000000000000000000123.500000"
-
- sprintf("%10.4f", -123.5).should == " -123.5000"
- sprintf("%010.4f", -123.5).should == "-0123.5000"
-
- sprintf("%10.0f", -123.5).should == " -124"
- sprintf("%010.0f", -123.5).should == "-000000124"
- end
-
- it "passes some tests for infinite and nan" do
- sprintf("%f", Float::INFINITY).should == "Inf"
- sprintf("%f", -Float::INFINITY).should == "-Inf"
- sprintf("%f", Float::NAN).should == "NaN"
-
- sprintf("%10f", Float::INFINITY).should == " Inf"
- sprintf("%10f", -Float::INFINITY).should == " -Inf"
- sprintf("%10f", Float::NAN).should == " NaN"
- end
-
- it "passes kstephens's tests" do
- sprintf("%*1$.*2$3$d", 10, 5, 1).should == " 00001"
- sprintf("%b", 0).should == "0"
- sprintf("%B", 0).should == "0"
- sprintf("%b", -5).should == "..1011"
- sprintf("%B", -5).should == "..1011"
- sprintf("%+b", -5).should == "-101"
- sprintf("%+b", 10).should == "+1010"
- sprintf("%+b", 0).should == "+0"
- sprintf("%+o", -5).should == "-5"
- sprintf("%+o", 10).should == "+12"
- sprintf("%+o", 0).should == "+0"
- sprintf("%+d", -5).should == "-5"
- sprintf("%+d", 10).should == "+10"
- sprintf("%+d", 0).should == "+0"
- sprintf("%+x", -15).should == "-f"
- sprintf("%+x", 100).should == "+64"
- sprintf("%+x", 0).should == "+0"
- sprintf("%+X", -15).should == "-F"
- sprintf("%+X", 100).should == "+64"
- sprintf("%+X", 0).should == "+0"
- sprintf("=%02X", 1).should == "=01"
- sprintf("%+03d", 0).should == "+00"
- sprintf("%+03d", 5).should == "+05"
- sprintf("%+03d", -5).should == "-05"
- sprintf("%+03d", 12).should == "+12"
- sprintf("%+03d", -12).should == "-12"
- sprintf("%+03d", 123).should == "+123"
- sprintf("%+03d", -123).should == "-123"
- end
-
- with_feature :encoding do
- it "returns a String in the same encoding as the format String if compatible" do
- format = "%.2f %4s".force_encoding(Encoding::KOI8_U)
- result = sprintf(format, 1.2, "dogs")
- result.encoding.should equal(Encoding::KOI8_U)
- end
-
- it "returns a String in the argument encoding if format encoding is more restrictive" do
- format = "foo %s".force_encoding(Encoding::US_ASCII)
- arg = "b\303\274r".force_encoding(Encoding::UTF_8)
-
- result = sprintf(format, arg)
- result.encoding.should equal(Encoding::UTF_8)
- end
- end
+describe "Kernel#sprintf" do
+ it_behaves_like :kernel_sprintf, -> format, *args {
+ r = nil
+ -> {
+ r = sprintf(format, *args)
+ }.should_not complain(verbose: true)
+ r
+ }
+
+ it_behaves_like :kernel_sprintf_encoding, -> format, *args {
+ r = nil
+ -> {
+ r = sprintf(format, *args)
+ }.should_not complain(verbose: true)
+ r
+ }
+
+ it_behaves_like :kernel_sprintf_to_str, -> format, *args {
+ r = nil
+ -> {
+ r = sprintf(format, *args)
+ }.should_not complain(verbose: true)
+ r
+ }
end
describe "Kernel.sprintf" do
- it "needs to be reviewed for spec completeness"
+ it_behaves_like :kernel_sprintf, -> format, *args {
+ r = nil
+ -> {
+ r = Kernel.sprintf(format, *args)
+ }.should_not complain(verbose: true)
+ r
+ }
+
+ it_behaves_like :kernel_sprintf_encoding, -> format, *args {
+ r = nil
+ -> {
+ r = Kernel.sprintf(format, *args)
+ }.should_not complain(verbose: true)
+ r
+ }
+
+ it_behaves_like :kernel_sprintf_to_str, -> format, *args {
+ r = nil
+ -> {
+ r = Kernel.sprintf(format, *args)
+ }.should_not complain(verbose: true)
+ r
+ }
end
diff --git a/spec/ruby/core/kernel/srand_spec.rb b/spec/ruby/core/kernel/srand_spec.rb
index 33f99f5ac4..cbc3a7f4b8 100644
--- a/spec/ruby/core/kernel/srand_spec.rb
+++ b/spec/ruby/core/kernel/srand_spec.rb
@@ -1,9 +1,17 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe "Kernel#srand" do
+ before :each do
+ @seed = srand
+ end
+
+ after :each do
+ srand(@seed)
+ end
-describe "Kernel.srand" do
it "is a private method" do
- Kernel.should have_private_instance_method(:srand)
+ Kernel.private_instance_methods(false).should.include?(:srand)
end
it "returns the previous seed value" do
@@ -11,6 +19,10 @@ describe "Kernel.srand" do
srand(20).should == 10
end
+ it "returns the system-initialized seed value on the first call" do
+ ruby_exe('print srand(10)', options: '--disable-gems').should =~ /\A\d+\z/
+ end
+
it "seeds the RNG correctly and repeatably" do
srand(10)
x = rand
@@ -19,7 +31,7 @@ describe "Kernel.srand" do
end
it "defaults number to a random value" do
- lambda { srand }.should_not raise_error
+ -> { srand }.should_not.raise
srand.should_not == 0
end
@@ -33,7 +45,7 @@ describe "Kernel.srand" do
srand.should == -17
end
- it "accepts a Bignum as a seed" do
+ it "accepts an Integer as a seed" do
srand(0x12345678901234567890)
srand.should == 0x12345678901234567890
end
@@ -48,14 +60,14 @@ describe "Kernel.srand" do
end
it "raises a TypeError when passed nil" do
- lambda { srand(nil) }.should raise_error(TypeError)
+ -> { srand(nil) }.should.raise(TypeError)
end
it "raises a TypeError when passed a String" do
- lambda { srand("7") }.should raise_error(TypeError)
+ -> { srand("7") }.should.raise(TypeError)
end
end
-describe "Kernel#srand" do
+describe "Kernel.srand" do
it "needs to be reviewed for spec completeness"
end
diff --git a/spec/ruby/core/kernel/sub_spec.rb b/spec/ruby/core/kernel/sub_spec.rb
index 78e5eec4a8..b175e371dc 100644
--- a/spec/ruby/core/kernel/sub_spec.rb
+++ b/spec/ruby/core/kernel/sub_spec.rb
@@ -1,18 +1,18 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
# FIXME: These methods exist only when the -n or -p option is passed to
# ruby, but we currently don't have a way of specifying that.
ruby_version_is ""..."1.9" do
describe "Kernel#sub" do
it "is a private method" do
- Kernel.should have_private_instance_method(:sub)
+ Kernel.private_instance_methods(false).should.include?(:sub)
end
end
describe "Kernel#sub!" do
it "is a private method" do
- Kernel.should have_private_instance_method(:sub!)
+ Kernel.private_instance_methods(false).should.include?(:sub!)
end
end
diff --git a/spec/ruby/core/kernel/syscall_spec.rb b/spec/ruby/core/kernel/syscall_spec.rb
index bcea833f1f..63943cdad5 100644
--- a/spec/ruby/core/kernel/syscall_spec.rb
+++ b/spec/ruby/core/kernel/syscall_spec.rb
@@ -1,9 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Kernel#syscall" do
it "is a private method" do
- Kernel.should have_private_instance_method(:syscall)
+ Kernel.private_instance_methods(false).should.include?(:syscall)
end
end
diff --git a/spec/ruby/core/kernel/system_spec.rb b/spec/ruby/core/kernel/system_spec.rb
index aee75441a2..b24956104a 100644
--- a/spec/ruby/core/kernel/system_spec.rb
+++ b/spec/ruby/core/kernel/system_spec.rb
@@ -1,40 +1,48 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe :kernel_system, shared: true do
it "executes the specified command in a subprocess" do
- lambda { @object.system("echo a") }.should output_to_fd("a\n")
+ -> { @object.system("echo a") }.should output_to_fd("a\n")
- $?.should be_an_instance_of Process::Status
- $?.success?.should == true
+ $?.should.instance_of? Process::Status
+ $?.should.success?
end
it "returns true when the command exits with a zero exit status" do
@object.system(ruby_cmd('exit 0')).should == true
- $?.should be_an_instance_of Process::Status
- $?.success?.should == true
+ $?.should.instance_of? Process::Status
+ $?.should.success?
$?.exitstatus.should == 0
end
it "returns false when the command exits with a non-zero exit status" do
@object.system(ruby_cmd('exit 1')).should == false
- $?.should be_an_instance_of Process::Status
- $?.success?.should == false
+ $?.should.instance_of? Process::Status
+ $?.should_not.success?
$?.exitstatus.should == 1
end
+ it "raises RuntimeError when `exception: true` is given and the command exits with a non-zero exit status" do
+ -> { @object.system(ruby_cmd('exit 1'), exception: true) }.should.raise(RuntimeError)
+ end
+
+ it "raises Errno::ENOENT when `exception: true` is given and the specified command does not exist" do
+ -> { @object.system('feature_14386', exception: true) }.should.raise(Errno::ENOENT)
+ end
+
it "returns nil when command execution fails" do
- @object.system("sad").should be_nil
+ @object.system("sad").should == nil
- $?.should be_an_instance_of Process::Status
- $?.pid.should be_kind_of(Integer)
- $?.exitstatus.should == 127
+ $?.should.instance_of? Process::Status
+ $?.pid.should.is_a?(Integer)
+ $?.should_not.success?
end
it "does not write to stderr when command execution fails" do
- lambda { @object.system("sad") }.should output_to_fd("", STDERR)
+ -> { @object.system("sad") }.should output_to_fd("", STDERR)
end
platform_is_not :windows do
@@ -47,12 +55,29 @@ describe :kernel_system, shared: true do
end
it "executes with `sh` if the command contains shell characters" do
- lambda { @object.system("echo $0") }.should output_to_fd("sh\n")
+ -> { @object.system("echo $0") }.should output_to_fd("sh\n")
end
it "ignores SHELL env var and always uses `sh`" do
ENV['SHELL'] = "/bin/fakeshell"
- lambda { @object.system("echo $0") }.should output_to_fd("sh\n")
+ -> { @object.system("echo $0") }.should output_to_fd("sh\n")
+ end
+ end
+
+ platform_is_not :windows do
+ before :each do
+ require 'tmpdir'
+ @shell_command = File.join(Dir.mktmpdir, "noshebang.cmd")
+ File.write(@shell_command, %[echo "$PATH"\n], perm: 0o700)
+ end
+
+ after :each do
+ File.unlink(@shell_command)
+ Dir.rmdir(File.dirname(@shell_command))
+ end
+
+ it "executes with `sh` if the command is executable but not binary and there is no shebang" do
+ -> { @object.system(@shell_command) }.should output_to_fd(ENV['PATH'] + "\n")
end
end
@@ -69,19 +94,19 @@ describe :kernel_system, shared: true do
end
it "expands shell variables when given a single string argument" do
- lambda { @object.system("echo #{@shell_var}") }.should output_to_fd("foo\n")
+ -> { @object.system("echo #{@shell_var}") }.should output_to_fd("foo\n")
end
platform_is_not :windows do
it "does not expand shell variables when given multiples arguments" do
- lambda { @object.system("echo", @shell_var) }.should output_to_fd("#{@shell_var}\n")
+ -> { @object.system("echo", @shell_var) }.should output_to_fd("#{@shell_var}\n")
end
end
platform_is :windows do
it "does expand shell variables when given multiples arguments" do
# See https://bugs.ruby-lang.org/issues/12231
- lambda { @object.system("echo", @shell_var) }.should output_to_fd("foo\n")
+ -> { @object.system("echo", @shell_var) }.should output_to_fd("foo\n")
end
end
@@ -96,7 +121,7 @@ end
describe "Kernel#system" do
it "is a private method" do
- Kernel.should have_private_instance_method(:system)
+ Kernel.private_instance_methods(false).should.include?(:system)
end
it_behaves_like :kernel_system, :system, KernelSpecs::Method.new
diff --git a/spec/ruby/core/kernel/taint_spec.rb b/spec/ruby/core/kernel/taint_spec.rb
index 0c2fb3286b..9a2efbaea0 100644
--- a/spec/ruby/core/kernel/taint_spec.rb
+++ b/spec/ruby/core/kernel/taint_spec.rb
@@ -1,45 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Kernel#taint" do
- it "returns self" do
- o = Object.new
- o.taint.should equal(o)
- end
-
- it "sets the tainted bit" do
- o = Object.new
- o.taint
- o.tainted?.should == true
- end
-
- it "raises RuntimeError on an untainted, frozen object" do
- o = Object.new.freeze
- lambda { o.taint }.should raise_error(RuntimeError)
- end
-
- it "does not raise an error on a tainted, frozen object" do
- o = Object.new.taint.freeze
- o.taint.should equal(o)
- end
-
- it "has no effect on immediate values" do
- [nil, true, false].each do |v|
- v.taint
- v.tainted?.should == false
- end
- end
-
- it "no raises a RuntimeError on symbols" do
- v = :sym
- lambda { v.taint }.should_not raise_error(RuntimeError)
- v.tainted?.should == false
- end
-
- it "no raises error on fixnum values" do
- [1].each do |v|
- lambda { v.taint }.should_not raise_error(RuntimeError)
- v.tainted?.should == false
- end
+ it "has been removed" do
+ Object.new.should_not.respond_to?(:taint)
end
end
diff --git a/spec/ruby/core/kernel/tainted_spec.rb b/spec/ruby/core/kernel/tainted_spec.rb
index efb31be9d8..837eb1dafb 100644
--- a/spec/ruby/core/kernel/tainted_spec.rb
+++ b/spec/ruby/core/kernel/tainted_spec.rb
@@ -1,12 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Kernel#tainted?" do
- it "returns true if Object is tainted" do
- o = mock('o')
- p = mock('p')
- p.taint
- o.tainted?.should == false
- p.tainted?.should == true
+ it "has been removed" do
+ Object.new.should_not.respond_to?(:tainted?)
end
end
diff --git a/spec/ruby/core/kernel/tap_spec.rb b/spec/ruby/core/kernel/tap_spec.rb
index 312a34426c..453b9b84d5 100644
--- a/spec/ruby/core/kernel/tap_spec.rb
+++ b/spec/ruby/core/kernel/tap_spec.rb
@@ -1,13 +1,13 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Kernel#tap" do
it "always yields self and returns self" do
a = KernelSpecs::A.new
- a.tap{|o| o.should equal(a); 42}.should equal(a)
+ a.tap{|o| o.should.equal?(a); 42}.should.equal?(a)
end
it "raises a LocalJumpError when no block given" do
- lambda { 3.tap }.should raise_error(LocalJumpError)
+ -> { 3.tap }.should.raise(LocalJumpError)
end
end
diff --git a/spec/ruby/core/kernel/test_spec.rb b/spec/ruby/core/kernel/test_spec.rb
index 43e3a963e3..30717dfd98 100644
--- a/spec/ruby/core/kernel/test_spec.rb
+++ b/spec/ruby/core/kernel/test_spec.rb
@@ -1,14 +1,14 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Kernel#test" do
before :all do
- @file = File.dirname(__FILE__) + '/fixtures/classes.rb'
- @dir = File.dirname(__FILE__) + '/fixtures'
+ @file = __dir__ + '/fixtures/classes.rb'
+ @dir = __dir__ + '/fixtures'
end
it "is a private method" do
- Kernel.should have_private_instance_method(:test)
+ Kernel.private_instance_methods(false).should.include?(:test)
end
it "returns true when passed ?f if the argument is a regular file" do
@@ -28,7 +28,7 @@ describe "Kernel#test" do
link = tmp("file_symlink.lnk")
File.symlink(@file, link)
begin
- Kernel.test(?l, link).should be_true
+ Kernel.test(?l, link).should == true
ensure
rm_r link
end
@@ -36,11 +36,11 @@ describe "Kernel#test" do
end
it "returns true when passed ?r if the argument is readable by the effective uid" do
- Kernel.test(?r, @file).should be_true
+ Kernel.test(?r, @file).should == true
end
it "returns true when passed ?R if the argument is readable by the real uid" do
- Kernel.test(?R, @file).should be_true
+ Kernel.test(?R, @file).should == true
end
context "writable test" do
@@ -54,11 +54,11 @@ describe "Kernel#test" do
end
it "returns true when passed ?w if the argument is readable by the effective uid" do
- Kernel.test(?w, @tmp_file).should be_true
+ Kernel.test(?w, @tmp_file).should == true
end
it "returns true when passed ?W if the argument is readable by the real uid" do
- Kernel.test(?W, @tmp_file).should be_true
+ Kernel.test(?W, @tmp_file).should == true
end
end
diff --git a/spec/ruby/core/kernel/then_spec.rb b/spec/ruby/core/kernel/then_spec.rb
new file mode 100644
index 0000000000..bda5a69662
--- /dev/null
+++ b/spec/ruby/core/kernel/then_spec.rb
@@ -0,0 +1,14 @@
+require_relative '../../spec_helper'
+require_relative 'shared/then'
+
+describe "Kernel#then" do
+ ruby_version_is ""..."3.4" do
+ it_behaves_like :kernel_then, :then
+ end
+
+ ruby_version_is "3.4" do
+ it "is an alias of Kernel#yield_self" do
+ Kernel.instance_method(:then).should == Kernel.instance_method(:yield_self)
+ end
+ end
+end
diff --git a/spec/ruby/core/kernel/throw_spec.rb b/spec/ruby/core/kernel/throw_spec.rb
index 3f8d272d6d..1086126176 100644
--- a/spec/ruby/core/kernel/throw_spec.rb
+++ b/spec/ruby/core/kernel/throw_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Kernel.throw" do
it "transfers control to the end of the active catch block waiting for symbol" do
@@ -7,10 +7,10 @@ describe "Kernel.throw" do
:value
throw :blah
fail("throw didn't transfer the control")
- end.should be_nil
+ end.should == nil
end
- it "transfers control to the innermost catch block waiting for the same sympol" do
+ it "transfers control to the innermost catch block waiting for the same symbol" do
one = two = three = 0
catch :duplicate do
catch :duplicate do
@@ -42,39 +42,39 @@ describe "Kernel.throw" do
end
it "raises an ArgumentError if there is no catch block for the symbol" do
- lambda { throw :blah }.should raise_error(ArgumentError)
+ -> { throw :blah }.should.raise(ArgumentError)
end
it "raises an UncaughtThrowError if there is no catch block for the symbol" do
- lambda { throw :blah }.should raise_error(UncaughtThrowError)
+ -> { throw :blah }.should.raise(UncaughtThrowError)
end
it "raises ArgumentError if 3 or more arguments provided" do
- lambda {
+ -> {
catch :blah do
throw :blah, :return_value, 2
end
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
- lambda {
+ -> {
catch :blah do
throw :blah, :return_value, 2, 3, 4, 5
end
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
end
it "can throw an object" do
- lambda {
+ -> {
obj = Object.new
catch obj do
throw obj
end
- }.should_not raise_error(NameError)
+ }.should_not.raise(NameError)
end
end
describe "Kernel#throw" do
it "is a private method" do
- Kernel.should have_private_instance_method(:throw)
+ Kernel.private_instance_methods(false).should.include?(:throw)
end
end
diff --git a/spec/ruby/core/kernel/to_enum_spec.rb b/spec/ruby/core/kernel/to_enum_spec.rb
index 9fb228f318..1cee26b694 100644
--- a/spec/ruby/core/kernel/to_enum_spec.rb
+++ b/spec/ruby/core/kernel/to_enum_spec.rb
@@ -1,5 +1,59 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Kernel#to_enum" do
- it "needs to be reviewed for spec completeness"
+ it "is defined in Kernel" do
+ Kernel.method_defined?(:to_enum).should == true
+ end
+
+ it "returns a new enumerator" do
+ "abc".to_enum.should.instance_of?(Enumerator)
+ end
+
+ it "defaults the first argument to :each" do
+ enum = [1,2].to_enum
+ enum.map { |v| v }.should == [1,2].each { |v| v }
+ end
+
+ it "sets regexp matches in the caller" do
+ "wawa".to_enum(:scan, /./).map {|o| $& }.should == ["w", "a", "w", "a"]
+ a = []
+ "wawa".to_enum(:scan, /./).each {|o| a << $& }
+ a.should == ["w", "a", "w", "a"]
+ end
+
+ it "exposes multi-arg yields as an array" do
+ o = Object.new
+ def o.each
+ yield :a
+ yield :b1, :b2
+ yield [:c]
+ yield :d1, :d2
+ yield :e1, :e2, :e3
+ end
+
+ enum = o.to_enum
+ enum.next.should == :a
+ enum.next.should == [:b1, :b2]
+ enum.next.should == [:c]
+ enum.next.should == [:d1, :d2]
+ enum.next.should == [:e1, :e2, :e3]
+ end
+
+ it "uses the passed block's value to calculate the size of the enumerator" do
+ Object.new.to_enum { 100 }.size.should == 100
+ end
+
+ it "defers the evaluation of the passed block until #size is called" do
+ ScratchPad.record []
+
+ enum = Object.new.to_enum do
+ ScratchPad << :called
+ 100
+ end
+
+ ScratchPad.recorded.should.empty?
+
+ enum.size
+ ScratchPad.recorded.should == [:called]
+ end
end
diff --git a/spec/ruby/core/kernel/to_s_spec.rb b/spec/ruby/core/kernel/to_s_spec.rb
index c6fcca54a2..ea4b00151e 100644
--- a/spec/ruby/core/kernel/to_s_spec.rb
+++ b/spec/ruby/core/kernel/to_s_spec.rb
@@ -1,16 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Kernel#to_s" do
it "returns a String containing the name of self's class" do
Object.new.to_s.should =~ /Object/
end
-
- it "returns a tainted result if self is tainted" do
- Object.new.taint.to_s.tainted?.should be_true
- end
-
- it "returns an untrusted result if self is untrusted" do
- Object.new.untrust.to_s.untrusted?.should be_true
- end
end
diff --git a/spec/ruby/core/kernel/trace_var_spec.rb b/spec/ruby/core/kernel/trace_var_spec.rb
index 07e02feb72..150c3da266 100644
--- a/spec/ruby/core/kernel/trace_var_spec.rb
+++ b/spec/ruby/core/kernel/trace_var_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Kernel#trace_var" do
before :each do
@@ -14,7 +14,7 @@ describe "Kernel#trace_var" do
end
it "is a private method" do
- Kernel.should have_private_instance_method(:trace_var)
+ Kernel.private_instance_methods(false).should.include?(:trace_var)
end
it "hooks assignments to a global variable" do
@@ -47,8 +47,8 @@ describe "Kernel#trace_var" do
end
it "raises ArgumentError if no block or proc is provided" do
- lambda do
+ -> do
trace_var :$Kernel_trace_var_global
- end.should raise_error(ArgumentError)
+ end.should.raise(ArgumentError)
end
end
diff --git a/spec/ruby/core/kernel/trap_spec.rb b/spec/ruby/core/kernel/trap_spec.rb
index 98f386dc85..8f44f3af4b 100644
--- a/spec/ruby/core/kernel/trap_spec.rb
+++ b/spec/ruby/core/kernel/trap_spec.rb
@@ -1,12 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
describe "Kernel#trap" do
it "is a private method" do
- Kernel.should have_private_instance_method(:trap)
+ Kernel.private_instance_methods(false).should.include?(:trap)
end
-end
-describe "Kernel.trap" do
- it "needs to be reviewed for spec completeness"
+ # Behaviour is specified for Signal.trap
end
diff --git a/spec/ruby/core/kernel/trust_spec.rb b/spec/ruby/core/kernel/trust_spec.rb
index a9fda5c5c6..ef3fa9a3e1 100644
--- a/spec/ruby/core/kernel/trust_spec.rb
+++ b/spec/ruby/core/kernel/trust_spec.rb
@@ -1,25 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Kernel#trust" do
- it "returns self" do
- o = Object.new
- o.trust.should equal(o)
- end
-
- it "clears the untrusted bit" do
- o = Object.new.untrust
- o.trust
- o.untrusted?.should == false
- end
-
- it "raises RuntimeError on an untrusted, frozen object" do
- o = Object.new.untrust.freeze
- lambda { o.trust }.should raise_error(RuntimeError)
- end
-
- it "does not raise an error on a trusted, frozen object" do
- o = Object.new.freeze
- o.trust.should equal(o)
+ it "has been removed" do
+ Object.new.should_not.respond_to?(:trust)
end
end
diff --git a/spec/ruby/core/kernel/untaint_spec.rb b/spec/ruby/core/kernel/untaint_spec.rb
index 5abe5d63fc..47e8544bd4 100644
--- a/spec/ruby/core/kernel/untaint_spec.rb
+++ b/spec/ruby/core/kernel/untaint_spec.rb
@@ -1,25 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Kernel#untaint" do
- it "returns self" do
- o = Object.new
- o.untaint.should equal(o)
- end
-
- it "clears the tainted bit" do
- o = Object.new.taint
- o.untaint
- o.tainted?.should == false
- end
-
- it "raises RuntimeError on a tainted, frozen object" do
- o = Object.new.taint.freeze
- lambda { o.untaint }.should raise_error(RuntimeError)
- end
-
- it "does not raise an error on an untainted, frozen object" do
- o = Object.new.freeze
- o.untaint.should equal(o)
+ it "has been removed" do
+ Object.new.should_not.respond_to?(:untaint)
end
end
diff --git a/spec/ruby/core/kernel/untrace_var_spec.rb b/spec/ruby/core/kernel/untrace_var_spec.rb
index 3af1348ffd..8b219801c8 100644
--- a/spec/ruby/core/kernel/untrace_var_spec.rb
+++ b/spec/ruby/core/kernel/untrace_var_spec.rb
@@ -1,9 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Kernel#untrace_var" do
it "is a private method" do
- Kernel.should have_private_instance_method(:untrace_var)
+ Kernel.private_instance_methods(false).should.include?(:untrace_var)
end
end
diff --git a/spec/ruby/core/kernel/untrust_spec.rb b/spec/ruby/core/kernel/untrust_spec.rb
index 280a465807..8787ab3fc9 100644
--- a/spec/ruby/core/kernel/untrust_spec.rb
+++ b/spec/ruby/core/kernel/untrust_spec.rb
@@ -1,25 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Kernel#untrust" do
- it "returns self" do
- o = Object.new
- o.untrust.should equal(o)
- end
-
- it "sets the untrusted bit" do
- o = Object.new
- o.untrust
- o.untrusted?.should == true
- end
-
- it "raises RuntimeError on a trusted, frozen object" do
- o = Object.new.freeze
- lambda { o.untrust }.should raise_error(RuntimeError)
- end
-
- it "does not raise an error on an untrusted, frozen object" do
- o = Object.new.untrust.freeze
- o.untrust.should equal(o)
+ it "has been removed" do
+ Object.new.should_not.respond_to?(:untrust)
end
end
diff --git a/spec/ruby/core/kernel/untrusted_spec.rb b/spec/ruby/core/kernel/untrusted_spec.rb
index 43c4c0aa18..29261be9c4 100644
--- a/spec/ruby/core/kernel/untrusted_spec.rb
+++ b/spec/ruby/core/kernel/untrusted_spec.rb
@@ -1,28 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Kernel#untrusted?" do
- it "returns the untrusted status of an object" do
- o = mock('o')
- o.untrusted?.should == false
- o.untrust
- o.untrusted?.should == true
- end
-
- it "has no effect on immediate values" do
- a = nil
- b = true
- c = false
- a.untrust
- b.untrust
- c.untrust
- a.untrusted?.should == false
- b.untrusted?.should == false
- c.untrusted?.should == false
- end
-
- it "has effect on immediate values" do
- d = 1
- lambda { d.untrust }.should_not raise_error(RuntimeError)
+ it "has been removed" do
+ Object.new.should_not.respond_to?(:untrusted?)
end
end
diff --git a/spec/ruby/core/kernel/warn_spec.rb b/spec/ruby/core/kernel/warn_spec.rb
index c44116dc21..189129dd31 100644
--- a/spec/ruby/core/kernel/warn_spec.rb
+++ b/spec/ruby/core/kernel/warn_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Kernel#warn" do
before :each do
@@ -8,72 +8,291 @@ describe "Kernel#warn" do
end
after :each do
- $VERBOSE = @before_verbose
+ $VERBOSE = nil
$/ = @before_separator
+ $VERBOSE = @before_verbose
end
it "is a private method" do
- Kernel.should have_private_instance_method(:warn)
+ Kernel.private_instance_methods(false).should.include?(:warn)
end
- it "requires multiple arguments" do
+ it "accepts multiple arguments" do
Kernel.method(:warn).arity.should < 0
end
it "does not append line-end if last character is line-end" do
- lambda {
+ -> {
$VERBOSE = true
warn("this is some simple text with line-end\n")
}.should output(nil, "this is some simple text with line-end\n")
end
it "calls #write on $stderr if $VERBOSE is true" do
- lambda {
+ -> {
$VERBOSE = true
warn("this is some simple text")
}.should output(nil, "this is some simple text\n")
end
it "calls #write on $stderr if $VERBOSE is false" do
- lambda {
+ -> {
$VERBOSE = false
warn("this is some simple text")
}.should output(nil, "this is some simple text\n")
end
it "does not call #write on $stderr if $VERBOSE is nil" do
- lambda {
+ -> {
$VERBOSE = nil
warn("this is some simple text")
}.should output(nil, "")
end
it "writes each argument on a line when passed multiple arguments" do
- lambda {
+ -> {
$VERBOSE = true
warn("line 1", "line 2")
}.should output(nil, "line 1\nline 2\n")
end
it "writes each array element on a line when passes an array" do
- lambda {
+ -> {
$VERBOSE = true
warn(["line 1", "line 2"])
}.should output(nil, "line 1\nline 2\n")
end
it "does not write strings when passed no arguments" do
- lambda {
+ -> {
$VERBOSE = true
warn
}.should output("", "")
end
it "writes the default record separator and NOT $/ to $stderr after the warning message" do
- lambda {
+ -> {
$VERBOSE = true
$/ = 'rs'
warn("")
}.should output(nil, /\n/)
end
+
+ it "writes to_s representation if passed a non-string" do
+ obj = mock("obj")
+ obj.should_receive(:to_s).and_return("to_s called")
+ -> {
+ $VERBOSE = true
+ warn(obj)
+ }.should output(nil, "to_s called\n")
+ end
+
+ describe ":uplevel keyword argument" do
+ before :each do
+ $VERBOSE = true
+ end
+
+ it "prepends a message with specified line from the backtrace" do
+ w = KernelSpecs::WarnInNestedCall.new
+
+ -> { w.f4("foo", 0) }.should output(nil, %r|core/kernel/fixtures/classes.rb:#{w.warn_call_lineno}: warning: foo|)
+ -> { w.f4("foo", 1) }.should output(nil, %r|core/kernel/fixtures/classes.rb:#{w.f1_call_lineno}: warning: foo|)
+ -> { w.f4("foo", 2) }.should output(nil, %r|core/kernel/fixtures/classes.rb:#{w.f2_call_lineno}: warning: foo|)
+ -> { w.f4("foo", 3) }.should output(nil, %r|core/kernel/fixtures/classes.rb:#{w.f3_call_lineno}: warning: foo|)
+ end
+
+ # Test both explicitly without and with RubyGems as RubyGems overrides Kernel#warn
+ it "shows the caller of #require and not #require itself without RubyGems" do
+ file = fixture(__FILE__ , "warn_require_caller.rb")
+ ruby_exe(file, options: "--disable-gems", args: "2>&1").should == "#{file}:2: warning: warn-require-warning\n"
+ end
+
+ it "shows the caller of #require and not #require itself with RubyGems loaded" do
+ file = fixture(__FILE__ , "warn_require_caller.rb")
+ ruby_exe(file, options: "-rrubygems", args: "2>&1").should == "#{file}:2: warning: warn-require-warning\n"
+ end
+
+ it "doesn't show the caller when the uplevel is `nil`" do
+ w = KernelSpecs::WarnInNestedCall.new
+
+ -> { w.f4("foo", nil) }.should output(nil, "foo\n")
+ end
+
+ guard -> { Kernel.instance_method(:tap).source_location } do
+ it "skips <internal: core library methods defined in Ruby" do
+ file, line = Kernel.instance_method(:tap).source_location
+ file.should.start_with?('<internal:')
+
+ file = fixture(__FILE__ , "warn_core_method.rb")
+ n = 9
+ ruby_exe(file, options: "--disable-gems", args: "2>&1").lines.should == [
+ "#{file}:#{n+0}: warning: use X instead\n",
+ "#{file}:#{n+1}: warning: use X instead\n",
+ "#{file}:#{n+2}: warning: use X instead\n",
+ "#{file}:#{n+4}: warning: use X instead\n",
+ ]
+ end
+ end
+
+ it "accepts :category keyword with a symbol" do
+ -> {
+ $VERBOSE = true
+ warn("message", category: :deprecated)
+ }.should output(nil, "message\n")
+ end
+
+ it "accepts :category keyword with nil" do
+ -> {
+ $VERBOSE = true
+ warn("message", category: nil)
+ }.should output(nil, "message\n")
+ end
+
+ it "accepts :category keyword with object convertible to symbol" do
+ o = Object.new
+ def o.to_sym; :deprecated; end
+ -> {
+ $VERBOSE = true
+ warn("message", category: o)
+ }.should output(nil, "message\n")
+ end
+
+ it "raises if :category keyword is not nil and not convertible to symbol" do
+ -> {
+ $VERBOSE = true
+ warn("message", category: Object.new)
+ }.should.raise(TypeError)
+ end
+
+ it "converts first arg using to_s" do
+ w = KernelSpecs::WarnInNestedCall.new
+
+ -> { w.f4(false, 0) }.should output(nil, %r|core/kernel/fixtures/classes.rb:#{w.warn_call_lineno}: warning: false|)
+ -> { w.f4(nil, 1) }.should output(nil, %r|core/kernel/fixtures/classes.rb:#{w.f1_call_lineno}: warning: |)
+ obj = mock("obj")
+ obj.should_receive(:to_s).and_return("to_s called")
+ -> { w.f4(obj, 2) }.should output(nil, %r|core/kernel/fixtures/classes.rb:#{w.f2_call_lineno}: warning: to_s called|)
+ end
+
+ it "does not prepend caller information if the uplevel argument is too large" do
+ w = KernelSpecs::WarnInNestedCall.new
+ -> { w.f4("foo", 100) }.should output(nil, "warning: foo\n")
+ end
+
+ it "prepends even if a message is empty or nil" do
+ w = KernelSpecs::WarnInNestedCall.new
+
+ -> { w.f4("", 0) }.should output(nil, %r|core/kernel/fixtures/classes.rb:#{w.warn_call_lineno}: warning: \n$|)
+ -> { w.f4(nil, 0) }.should output(nil, %r|core/kernel/fixtures/classes.rb:#{w.warn_call_lineno}: warning: \n$|)
+ end
+
+ it "converts value to Integer" do
+ w = KernelSpecs::WarnInNestedCall.new
+
+ -> { w.f4(0.1) }.should output(nil, %r|classes.rb:#{w.warn_call_lineno}:|)
+ -> { w.f4(Rational(1, 2)) }.should output(nil, %r|classes.rb:#{w.warn_call_lineno}:|)
+ end
+
+ it "raises ArgumentError if passed negative value" do
+ -> { warn "", uplevel: -2 }.should.raise(ArgumentError)
+ -> { warn "", uplevel: -100 }.should.raise(ArgumentError)
+ end
+
+ it "raises ArgumentError if passed -1" do
+ -> { warn "", uplevel: -1 }.should.raise(ArgumentError)
+ end
+
+ it "raises TypeError if passed not Integer" do
+ -> { warn "", uplevel: "" }.should.raise(TypeError)
+ -> { warn "", uplevel: [] }.should.raise(TypeError)
+ -> { warn "", uplevel: {} }.should.raise(TypeError)
+ -> { warn "", uplevel: Object.new }.should.raise(TypeError)
+ end
+ end
+
+ it "treats empty hash as no keyword argument" do
+ h = {}
+ -> { warn(**h) }.should_not complain(verbose: true)
+ -> { warn('foo', **h) }.should complain("foo\n")
+ end
+
+ it "calls Warning.warn without keyword arguments if Warning.warn does not accept keyword arguments" do
+ verbose = $VERBOSE
+ $VERBOSE = false
+ class << Warning
+ alias_method :_warn, :warn
+ def warn(message)
+ ScratchPad.record(message)
+ end
+ end
+
+ begin
+ ScratchPad.clear
+ Kernel.warn("Chunky bacon!")
+ ScratchPad.recorded.should == "Chunky bacon!\n"
+
+ Kernel.warn("Deprecated bacon!", category: :deprecated)
+ ScratchPad.recorded.should == "Deprecated bacon!\n"
+ ensure
+ class << Warning
+ remove_method :warn
+ alias_method :warn, :_warn
+ remove_method :_warn
+ end
+ $VERBOSE = verbose
+ end
+ end
+
+ it "calls Warning.warn with category: nil if Warning.warn accepts keyword arguments" do
+ Warning.should_receive(:warn).with("Chunky bacon!\n", category: nil)
+ verbose = $VERBOSE
+ $VERBOSE = false
+ begin
+ Kernel.warn("Chunky bacon!")
+ ensure
+ $VERBOSE = verbose
+ end
+ end
+
+ it "calls Warning.warn with given category keyword converted to a symbol" do
+ Warning.should_receive(:warn).with("Chunky bacon!\n", category: :deprecated)
+ verbose = $VERBOSE
+ $VERBOSE = false
+ begin
+ Kernel.warn("Chunky bacon!", category: 'deprecated')
+ ensure
+ $VERBOSE = verbose
+ end
+ end
+
+ it "does not call Warning.warn if self is the Warning module" do
+ # RubyGems redefines Kernel#warn so we need to use a subprocess and disable RubyGems here
+ code = <<-RUBY
+ def Warning.warn(*args, **kwargs)
+ raise 'should not be called'
+ end
+ Kernel.instance_method(:warn).bind(Warning).call('Kernel#warn spec edge case')
+ RUBY
+ out = ruby_exe(code, args: "2>&1", options: "--disable-gems")
+ out.should == "Kernel#warn spec edge case\n"
+ $?.should.success?
+ end
+
+ it "avoids recursion if Warning#warn is redefined and calls super" do
+ # This works because of the spec above, which is the workaround for it.
+ # Note that redefining Warning#warn is a mistake which would naturally end in infinite recursion,
+ # Warning.extend Module.new { def warn } should be used instead.
+ # RubyGems redefines Kernel#warn so we need to use a subprocess and disable RubyGems here
+ code = <<-RUBY
+ module Warning
+ def warn(*args, **kwargs)
+ super
+ end
+ end
+ warn "avoid infinite recursion"
+ RUBY
+ out = ruby_exe(code, args: "2>&1", options: "--disable-gems")
+ out.should == "avoid infinite recursion\n"
+ $?.should.success?
+ end
end
diff --git a/spec/ruby/core/kernel/yield_self_spec.rb b/spec/ruby/core/kernel/yield_self_spec.rb
index 817c01f288..e311dcee47 100644
--- a/spec/ruby/core/kernel/yield_self_spec.rb
+++ b/spec/ruby/core/kernel/yield_self_spec.rb
@@ -1,26 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/then'
-has_yield_self = VersionGuard.new("2.5").match? || PlatformGuard.implementation?(:truffleruby)
-
-if has_yield_self
- describe "Kernel#yield_self" do
- it "yields self" do
- object = Object.new
- object.yield_self { |o| o.should equal object }
- end
-
- it "returns the block return value" do
- object = Object.new
- object.yield_self { 42 }.should equal 42
- end
-
- it "returns a sized Enumerator when no block given" do
- object = Object.new
- enum = object.yield_self
- enum.should be_an_instance_of Enumerator
- enum.size.should equal 1
- enum.peek.should equal object
- enum.first.should equal object
- end
- end
+describe "Kernel#yield_self" do
+ it_behaves_like :kernel_then, :yield_self
end
diff --git a/spec/ruby/core/main/define_method_spec.rb b/spec/ruby/core/main/define_method_spec.rb
index 741e0624f8..5279d078c3 100644
--- a/spec/ruby/core/main/define_method_spec.rb
+++ b/spec/ruby/core/main/define_method_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
script_binding = binding
@@ -14,15 +14,15 @@ describe "main#define_method" do
it 'creates a public method in TOPLEVEL_BINDING' do
eval @code, TOPLEVEL_BINDING
- Object.should have_method :boom
+ Object.should.respond_to? :boom
end
it 'creates a public method in script binding' do
eval @code, script_binding
- Object.should have_method :boom
+ Object.should.respond_to? :boom
end
it 'returns the method name as symbol' do
- eval(@code, TOPLEVEL_BINDING).should equal :boom
+ eval(@code, TOPLEVEL_BINDING).should.equal? :boom
end
end
diff --git a/spec/ruby/core/main/fixtures/classes.rb b/spec/ruby/core/main/fixtures/classes.rb
index 6aba948ce0..757cee4e4a 100644
--- a/spec/ruby/core/main/fixtures/classes.rb
+++ b/spec/ruby/core/main/fixtures/classes.rb
@@ -13,6 +13,14 @@ def main_public_method
end
public :main_public_method
+def main_public_method2
+end
+public :main_public_method2
+
def main_private_method
end
private :main_private_method
+
+def main_private_method2
+end
+private :main_private_method2
diff --git a/spec/ruby/core/main/fixtures/using.rb b/spec/ruby/core/main/fixtures/using.rb
new file mode 100644
index 0000000000..30713ef309
--- /dev/null
+++ b/spec/ruby/core/main/fixtures/using.rb
@@ -0,0 +1 @@
+using Module.new
diff --git a/spec/ruby/core/main/fixtures/using_in_main.rb b/spec/ruby/core/main/fixtures/using_in_main.rb
new file mode 100644
index 0000000000..a4a71c89cc
--- /dev/null
+++ b/spec/ruby/core/main/fixtures/using_in_main.rb
@@ -0,0 +1,5 @@
+MAIN = self
+
+module X
+ MAIN.send(:using, Module.new)
+end
diff --git a/spec/ruby/core/main/fixtures/using_in_method.rb b/spec/ruby/core/main/fixtures/using_in_method.rb
new file mode 100644
index 0000000000..d9ea2e9ef0
--- /dev/null
+++ b/spec/ruby/core/main/fixtures/using_in_method.rb
@@ -0,0 +1,5 @@
+def foo
+ using Module.new
+end
+
+foo
diff --git a/spec/ruby/core/main/include_spec.rb b/spec/ruby/core/main/include_spec.rb
index 1973bc8229..09f8d4d3b5 100644
--- a/spec/ruby/core/main/include_spec.rb
+++ b/spec/ruby/core/main/include_spec.rb
@@ -1,16 +1,16 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "main#include" do
it "includes the given Module in Object" do
eval "include MainSpecs::Module", TOPLEVEL_BINDING
- Object.ancestors.should include(MainSpecs::Module)
+ Object.ancestors.should.include?(MainSpecs::Module)
end
context "in a file loaded with wrapping" do
it "includes the given Module in the load wrapper" do
load(File.expand_path("../fixtures/wrapped_include.rb", __FILE__), true)
- Object.ancestors.should_not include(MainSpecs::WrapIncludeModule)
+ Object.ancestors.should_not.include?(MainSpecs::WrapIncludeModule)
end
end
end
diff --git a/spec/ruby/core/main/private_spec.rb b/spec/ruby/core/main/private_spec.rb
index 7e0a4ed57d..56a39ae3c1 100644
--- a/spec/ruby/core/main/private_spec.rb
+++ b/spec/ruby/core/main/private_spec.rb
@@ -1,23 +1,42 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "main#private" do
after :each do
Object.send(:public, :main_public_method)
+ Object.send(:public, :main_public_method2)
end
- it "sets the visibility of the given method to private" do
- eval "private :main_public_method", TOPLEVEL_BINDING
- Object.should have_private_method(:main_public_method)
+ context "when single argument is passed and it is not an array" do
+ it "sets the visibility of the given methods to private" do
+ eval "private :main_public_method", TOPLEVEL_BINDING
+ Object.private_methods(true).should.include?(:main_public_method)
+ end
end
- it "returns Object" do
- eval("private :main_public_method", TOPLEVEL_BINDING).should equal(Object)
+ context "when multiple arguments are passed" do
+ it "sets the visibility of the given methods to private" do
+ eval "private :main_public_method, :main_public_method2", TOPLEVEL_BINDING
+ Object.private_methods(true).should.include?(:main_public_method)
+ Object.private_methods(true).should.include?(:main_public_method2)
+ end
end
- it "raises a NameError when given an undefined name" do
- lambda do
- eval "private :main_undefined_method", TOPLEVEL_BINDING
- end.should raise_error(NameError)
+ context "when single argument is passed and is an array" do
+ it "sets the visibility of the given methods to private" do
+ eval "private [:main_public_method, :main_public_method2]", TOPLEVEL_BINDING
+ Object.private_methods(true).should.include?(:main_public_method)
+ Object.private_methods(true).should.include?(:main_public_method2)
+ end
+ end
+
+ it "returns argument" do
+ eval("private :main_public_method", TOPLEVEL_BINDING).should.equal?(:main_public_method)
+ end
+
+ it "raises a NameError when at least one of given method names is undefined" do
+ -> do
+ eval "private :main_public_method, :main_undefined_method", TOPLEVEL_BINDING
+ end.should.raise(NameError)
end
end
diff --git a/spec/ruby/core/main/public_spec.rb b/spec/ruby/core/main/public_spec.rb
index 6906faee04..89368ebb0d 100644
--- a/spec/ruby/core/main/public_spec.rb
+++ b/spec/ruby/core/main/public_spec.rb
@@ -1,23 +1,43 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "main#public" do
after :each do
Object.send(:private, :main_private_method)
+ Object.send(:private, :main_private_method2)
end
- it "sets the visibility of the given method to public" do
- eval "public :main_private_method", TOPLEVEL_BINDING
- Object.should_not have_private_method(:main_private_method)
+ context "when single argument is passed and it is not an array" do
+ it "sets the visibility of the given methods to public" do
+ eval "public :main_private_method", TOPLEVEL_BINDING
+ Object.private_methods(true).should_not.include?(:main_private_method)
+ end
end
- it "returns Object" do
- eval("public :main_private_method", TOPLEVEL_BINDING).should equal(Object)
+ context "when multiple arguments are passed" do
+ it "sets the visibility of the given methods to public" do
+ eval "public :main_private_method, :main_private_method2", TOPLEVEL_BINDING
+ Object.private_methods(true).should_not.include?(:main_private_method)
+ Object.private_methods(true).should_not.include?(:main_private_method2)
+ end
end
+ context "when single argument is passed and is an array" do
+ it "sets the visibility of the given methods to public" do
+ eval "public [:main_private_method, :main_private_method2]", TOPLEVEL_BINDING
+ Object.private_methods(true).should_not.include?(:main_private_method)
+ Object.private_methods(true).should_not.include?(:main_private_method2)
+ end
+ end
+
+ it "returns argument" do
+ eval("public :main_private_method", TOPLEVEL_BINDING).should.equal?(:main_private_method)
+ end
+
+
it "raises a NameError when given an undefined name" do
- lambda do
+ -> do
eval "public :main_undefined_method", TOPLEVEL_BINDING
- end.should raise_error(NameError)
+ end.should.raise(NameError)
end
end
diff --git a/spec/ruby/core/main/ruby2_keywords_spec.rb b/spec/ruby/core/main/ruby2_keywords_spec.rb
new file mode 100644
index 0000000000..d12c0ed4e4
--- /dev/null
+++ b/spec/ruby/core/main/ruby2_keywords_spec.rb
@@ -0,0 +1,9 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe "main.ruby2_keywords" do
+ it "is the same as Object.ruby2_keywords" do
+ main = TOPLEVEL_BINDING.receiver
+ main.private_methods(false).should.include?(:ruby2_keywords)
+ end
+end
diff --git a/spec/ruby/core/main/to_s_spec.rb b/spec/ruby/core/main/to_s_spec.rb
index dd5a02b0ae..642cfa4433 100644
--- a/spec/ruby/core/main/to_s_spec.rb
+++ b/spec/ruby/core/main/to_s_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "main#to_s" do
it "returns 'main'" do
diff --git a/spec/ruby/core/main/using_spec.rb b/spec/ruby/core/main/using_spec.rb
index ed18cdca39..314a6be416 100644
--- a/spec/ruby/core/main/using_spec.rb
+++ b/spec/ruby/core/main/using_spec.rb
@@ -1,134 +1,150 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe "main.using" do
+ it "requires one Module argument" do
+ -> do
+ eval('using', TOPLEVEL_BINDING)
+ end.should.raise(ArgumentError)
+
+ -> do
+ eval('using "foo"', TOPLEVEL_BINDING)
+ end.should.raise(TypeError)
+ end
-ruby_version_is "2.0.0" do
- require File.expand_path('../fixtures/classes', __FILE__)
- require File.expand_path('../fixtures/string_refinement', __FILE__)
+ it "uses refinements from the given module only in the target file" do
+ require_relative 'fixtures/string_refinement'
+ load File.expand_path('../fixtures/string_refinement_user.rb', __FILE__)
+ MainSpecs::DATA[:in_module].should == 'foo'
+ MainSpecs::DATA[:toplevel].should == 'foo'
+ -> do
+ 'hello'.foo
+ end.should.raise(NoMethodError)
+ end
- describe "main.using" do
- it "requires one Module argument" do
- lambda do
- eval('using', TOPLEVEL_BINDING)
- end.should raise_error(ArgumentError)
+ it "uses refinements from the given module for method calls in the target file" do
+ require_relative 'fixtures/string_refinement'
+ load File.expand_path('../fixtures/string_refinement_user.rb', __FILE__)
+ -> do
+ 'hello'.foo
+ end.should.raise(NoMethodError)
+ MainSpecs.call_foo('hello').should == 'foo'
+ end
- lambda do
- eval('using "foo"', TOPLEVEL_BINDING)
- end.should raise_error(TypeError)
+ it "uses refinements from the given module in the eval string" do
+ cls = MainSpecs::DATA[:cls] = Class.new {def foo; 'foo'; end}
+ MainSpecs::DATA[:mod] = Module.new do
+ refine(cls) do
+ def foo; 'bar'; end
+ end
end
+ eval(<<-EOS, TOPLEVEL_BINDING).should == 'bar'
+ using MainSpecs::DATA[:mod]
+ MainSpecs::DATA[:cls].new.foo
+ EOS
+ end
- it "uses refinements from the given module only in the target file" do
- load File.expand_path('../fixtures/string_refinement_user.rb', __FILE__)
- MainSpecs::DATA[:in_module].should == 'foo'
- MainSpecs::DATA[:toplevel].should == 'foo'
- lambda do
- 'hello'.foo
- end.should raise_error(NoMethodError)
+ it "does not affect methods defined before it is called" do
+ cls = Class.new {def foo; 'foo'; end}
+ MainSpecs::DATA[:mod] = Module.new do
+ refine(cls) do
+ def foo; 'bar'; end
+ end
end
+ x = MainSpecs::DATA[:x] = Object.new
+ eval <<-EOS, TOPLEVEL_BINDING
+ x = MainSpecs::DATA[:x]
+ def x.before_using(obj)
+ obj.foo
+ end
+ using MainSpecs::DATA[:mod]
+ def x.after_using(obj)
+ obj.foo
+ end
+ EOS
- it "uses refinements from the given module for method calls in the target file" do
- load File.expand_path('../fixtures/string_refinement_user.rb', __FILE__)
- lambda do
- 'hello'.foo
- end.should raise_error(NoMethodError)
- MainSpecs.call_foo('hello').should == 'foo'
- end
+ obj = cls.new
+ x.before_using(obj).should == 'foo'
+ x.after_using(obj).should == 'bar'
+ end
- it "uses refinements from the given module in the eval string" do
- cls = MainSpecs::DATA[:cls] = Class.new {def foo; 'foo'; end}
- MainSpecs::DATA[:mod] = Module.new do
- refine(cls) do
- def foo; 'bar'; end
- end
+ it "propagates refinements added to existing modules after it is called" do
+ cls = Class.new {def foo; 'foo'; end}
+ mod = MainSpecs::DATA[:mod] = Module.new do
+ refine(cls) do
+ def foo; 'quux'; end
end
- eval(<<-EOS, TOPLEVEL_BINDING).should == 'bar'
- using MainSpecs::DATA[:mod]
- MainSpecs::DATA[:cls].new.foo
- EOS
end
+ x = MainSpecs::DATA[:x] = Object.new
+ eval <<-EOS, TOPLEVEL_BINDING
+ using MainSpecs::DATA[:mod]
+ x = MainSpecs::DATA[:x]
+ def x.call_foo(obj)
+ obj.foo
+ end
+ def x.call_bar(obj)
+ obj.bar
+ end
+ EOS
+
+ obj = cls.new
+ x.call_foo(obj).should == 'quux'
- it "does not affect methods defined before it is called" do
- cls = Class.new {def foo; 'foo'; end}
- MainSpecs::DATA[:mod] = Module.new do
- refine(cls) do
- def foo; 'bar'; end
- end
+ mod.module_eval do
+ refine(cls) do
+ def bar; 'quux'; end
end
- x = MainSpecs::DATA[:x] = Object.new
- eval <<-EOS, TOPLEVEL_BINDING
- x = MainSpecs::DATA[:x]
- def x.before_using(obj)
- obj.foo
- end
- using MainSpecs::DATA[:mod]
- def x.after_using(obj)
- obj.foo
- end
- EOS
-
- obj = cls.new
- x.before_using(obj).should == 'foo'
- x.after_using(obj).should == 'bar'
end
- it "propagates refinements added to existing modules after it is called" do
- cls = Class.new {def foo; 'foo'; end}
- mod = MainSpecs::DATA[:mod] = Module.new do
- refine(cls) do
- def foo; 'quux'; end
- end
- end
- x = MainSpecs::DATA[:x] = Object.new
- eval <<-EOS, TOPLEVEL_BINDING
- using MainSpecs::DATA[:mod]
- x = MainSpecs::DATA[:x]
- def x.call_foo(obj)
- obj.foo
- end
- def x.call_bar(obj)
- obj.bar
- end
- EOS
-
- obj = cls.new
- x.call_foo(obj).should == 'quux'
-
- mod.module_eval do
- refine(cls) do
- def bar; 'quux'; end
- end
- end
+ x.call_bar(obj).should == 'quux'
+ end
- x.call_bar(obj).should == 'quux'
+ it "does not propagate refinements of new modules added after it is called" do
+ cls = Class.new {def foo; 'foo'; end}
+ cls2 = Class.new {def bar; 'bar'; end}
+ mod = MainSpecs::DATA[:mod] = Module.new do
+ refine(cls) do
+ def foo; 'quux'; end
+ end
end
-
- it "does not propagate refinements of new modules added after it is called" do
- cls = Class.new {def foo; 'foo'; end}
- cls2 = Class.new {def bar; 'bar'; end}
- mod = MainSpecs::DATA[:mod] = Module.new do
- refine(cls) do
- def foo; 'quux'; end
- end
+ x = MainSpecs::DATA[:x] = Object.new
+ eval <<-EOS, TOPLEVEL_BINDING
+ using MainSpecs::DATA[:mod]
+ x = MainSpecs::DATA[:x]
+ def x.call_foo(obj)
+ obj.foo
end
- x = MainSpecs::DATA[:x] = Object.new
- eval <<-EOS, TOPLEVEL_BINDING
- using MainSpecs::DATA[:mod]
- x = MainSpecs::DATA[:x]
- def x.call_foo(obj)
- obj.foo
- end
- def x.call_bar(obj)
- obj.bar
- end
- EOS
-
- x.call_foo(cls.new).should == 'quux'
-
- mod.module_eval do
- refine(cls2) do
- def bar; 'quux'; end
- end
+ def x.call_bar(obj)
+ obj.bar
end
+ EOS
- x.call_bar(cls2.new).should == 'bar'
+ x.call_foo(cls.new).should == 'quux'
+
+ mod.module_eval do
+ refine(cls2) do
+ def bar; 'quux'; end
+ end
end
+
+ x.call_bar(cls2.new).should == 'bar'
+ end
+
+ it "raises error when called from method in wrapped script" do
+ -> do
+ load File.expand_path('../fixtures/using_in_method.rb', __FILE__), true
+ end.should.raise(RuntimeError)
+ end
+
+ it "raises error when called on toplevel from module" do
+ -> do
+ load File.expand_path('../fixtures/using_in_main.rb', __FILE__), true
+ end.should.raise(RuntimeError)
+ end
+
+ it "does not raise error when wrapped with module" do
+ -> do
+ load File.expand_path('../fixtures/using.rb', __FILE__), true
+ end.should_not.raise
end
end
diff --git a/spec/ruby/core/marshal/dump_spec.rb b/spec/ruby/core/marshal/dump_spec.rb
index 393b8a93f4..9bbb7809af 100644
--- a/spec/ruby/core/marshal/dump_spec.rb
+++ b/spec/ruby/core/marshal/dump_spec.rb
@@ -1,6 +1,7 @@
-# -*- encoding: binary -*-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/marshal_data', __FILE__)
+# encoding: binary
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'fixtures/marshal_data'
describe "Marshal.dump" do
it "dumps nil" do
@@ -37,7 +38,7 @@ describe "Marshal.dump" do
].should be_computed_by(:dump)
end
- platform_is wordsize: 64 do
+ platform_is c_long_size: 64 do
it "dumps a positive Fixnum > 31 bits as a Bignum" do
Marshal.dump(2**31 + 1).should == "\x04\bl+\a\x01\x00\x00\x80"
end
@@ -46,6 +47,11 @@ describe "Marshal.dump" do
Marshal.dump(-2**31 - 1).should == "\x04\bl-\a\x01\x00\x00\x80"
end
end
+
+ it "does not use object links for objects repeatedly dumped" do
+ Marshal.dump([0, 0]).should == "\x04\b[\ai\x00i\x00"
+ Marshal.dump([2**16, 2**16]).should == "\x04\b[\ai\x03\x00\x00\x01i\x03\x00\x00\x01"
+ end
end
describe "with a Symbol" do
@@ -63,6 +69,10 @@ describe "Marshal.dump" do
"\x04\bI:\b\xE2\x86\x92\x06:\x06ET"],
[Marshal, s.encode("utf-16").to_sym,
"\x04\bI:\t\xFE\xFF!\x92\x06:\rencoding\"\vUTF-16"],
+ [Marshal, s.encode("utf-16le").to_sym,
+ "\x04\bI:\a\x92!\x06:\rencoding\"\rUTF-16LE"],
+ [Marshal, s.encode("utf-16be").to_sym,
+ "\x04\bI:\a!\x92\x06:\rencoding\"\rUTF-16BE"],
[Marshal, s.encode("euc-jp").to_sym,
"\x04\bI:\a\xA2\xAA\x06:\rencoding\"\vEUC-JP"],
[Marshal, s.encode("sjis").to_sym,
@@ -71,23 +81,28 @@ describe "Marshal.dump" do
end
it "dumps a binary encoded Symbol" do
- s = "\u2192".force_encoding("binary").to_sym
+ s = "\u2192".dup.force_encoding("binary").to_sym
Marshal.dump(s).should == "\x04\b:\b\xE2\x86\x92"
end
- end
+ it "dumps multiple Symbols sharing the same encoding" do
+ # Note that the encoding is a link for the second Symbol
+ symbol1 = "I:\t\xE2\x82\xACa\x06:\x06ET"
+ symbol2 = "I:\t\xE2\x82\xACb\x06;\x06T"
+ value = [
+ "€a".dup.force_encoding(Encoding::UTF_8).to_sym,
+ "€b".dup.force_encoding(Encoding::UTF_8).to_sym
+ ]
+ Marshal.dump(value).should == "\x04\b[\a#{symbol1}#{symbol2}"
- it "dumps an extended_object" do
- Marshal.dump(Object.new.extend(Meths)).should == "\x04\be:\nMethso:\vObject\x00"
- end
+ value = [*value, value[0]]
+ Marshal.dump(value).should == "\x04\b[\b#{symbol1}#{symbol2};\x00"
+ end
- it "dumps an object that has had an ivar added and removed as though the ivar never was set" do
- obj = Object.new
- initial = Marshal.dump(obj)
- obj.instance_variable_set(:@ivar, 1)
- Marshal.dump(obj).should == "\004\bo:\vObject\006:\n@ivari\006"
- obj.send :remove_instance_variable, :@ivar
- Marshal.dump(obj).should == initial
+ it "uses symbol links for objects repeatedly dumped" do
+ symbol = :foo
+ Marshal.dump([symbol, symbol]).should == "\x04\b[\a:\bfoo;\x00" # ;\x00 is a link to the symbol object
+ end
end
describe "with an object responding to #marshal_dump" do
@@ -99,17 +114,54 @@ describe "Marshal.dump" do
UserMarshal.should_not_receive(:name)
Marshal.dump(UserMarshal.new)
end
+
+ it "raises TypeError if an Object is an instance of an anonymous class" do
+ -> { Marshal.dump(Class.new(UserMarshal).new) }.should.raise(TypeError, /can't dump anonymous class/)
+ end
+
+ it "uses object links for objects repeatedly dumped" do
+ obj = UserMarshal.new
+ Marshal.dump([obj, obj]).should == "\x04\b[\aU:\x10UserMarshal:\tdata@\x06" # @\x06 is a link to the object
+ end
+
+ it "adds instance variables of a dumped object after the object itself into the objects table" do
+ value = "<foo>"
+ obj = MarshalSpec::UserMarshalDumpWithIvar.new("string", value)
+
+ # expect a link to the object (@\x06, that means Integer 1) is smaller than a link
+ # to the instance variable value (@\t, that means Integer 4)
+ Marshal.dump([obj, obj, value]).should == "\x04\b[\bU:)MarshalSpec::UserMarshalDumpWithIvarI[\x06\"\vstring\x06:\t@foo\"\n<foo>@\x06@\t"
+ end
end
describe "with an object responding to #_dump" do
- it "dumps the object returned by #marshal_dump" do
+ it "dumps the String returned by #_dump" do
Marshal.dump(UserDefined.new).should == "\004\bu:\020UserDefined\022\004\b[\a:\nstuff;\000"
end
+ it "dumps the String in non US-ASCII and non UTF-8 encoding" do
+ object = UserDefinedString.new("a".encode("windows-1251"))
+ Marshal.dump(object).should == "\x04\bIu:\x16UserDefinedString\x06a\x06:\rencoding\"\x11Windows-1251"
+ end
+
+ it "dumps the String in multibyte encoding" do
+ object = UserDefinedString.new("a".encode("utf-32le"))
+ Marshal.dump(object).should == "\x04\bIu:\x16UserDefinedString\ta\x00\x00\x00\x06:\rencoding\"\rUTF-32LE"
+ end
+
+ it "ignores overridden name method" do
+ obj = MarshalSpec::UserDefinedWithOverriddenName.new
+ Marshal.dump(obj).should == "\x04\bu:/MarshalSpec::UserDefinedWithOverriddenName\x12\x04\b[\a:\nstuff;\x00"
+ end
+
it "raises a TypeError if _dump returns a non-string" do
m = mock("marshaled")
m.should_receive(:_dump).and_return(0)
- lambda { Marshal.dump(m) }.should raise_error(TypeError)
+ -> { Marshal.dump(m) }.should.raise(TypeError)
+ end
+
+ it "raises TypeError if an Object is an instance of an anonymous class" do
+ -> { Marshal.dump(Class.new(UserDefined).new) }.should.raise(TypeError, /can't dump anonymous class/)
end
it "favors marshal_dump over _dump" do
@@ -118,6 +170,48 @@ describe "Marshal.dump" do
m.should_not_receive(:_dump)
Marshal.dump(m)
end
+
+ it "indexes instance variables of a String returned by #_dump at first and then indexes the object itself" do
+ class MarshalSpec::M1::A
+ def _dump(level)
+ s = +"<dump>"
+ s.instance_variable_set(:@foo, "bar")
+ s
+ end
+ end
+
+ a = MarshalSpec::M1::A.new
+
+ # 0-based index of the object a = 2, that is encoded as \x07 and printed as "\a" character.
+ # Objects are serialized in the following order: Array, a, "bar".
+ # But they are indexed in different order: Array (index=0), "bar" (index=1), a (index=2)
+ # So the second occurenc of the object a is encoded as an index 2.
+ reference = "@\a"
+ Marshal.dump([a, a]).should == "\x04\b[\aIu:\x17MarshalSpec::M1::A\v<dump>\x06:\t@foo\"\bbar#{reference}"
+ end
+
+ it "uses object links for objects repeatedly dumped" do
+ obj = UserDefined.new
+ Marshal.dump([obj, obj]).should == "\x04\b[\au:\x10UserDefined\x12\x04\b[\a:\nstuff;\x00@\x06" # @\x06 is a link to the object
+ end
+
+ it "adds instance variables of a dumped String before the object itself into the objects table" do
+ value = "<foo>"
+ obj = MarshalSpec::UserDefinedDumpWithIVars.new(+"string", value)
+
+ # expect a link to the object (@\a, that means Integer 2) is greater than a link
+ # to the instance variable value (@\x06, that means Integer 1)
+ Marshal.dump([obj, obj, value]).should == "\x04\b[\bIu:*MarshalSpec::UserDefinedDumpWithIVars\vstring\x06:\t@foo\"\n<foo>@\a@\x06"
+ end
+
+ describe "Core library classes with #_dump returning a String with instance variables" do
+ it "indexes instance variables and then a Time object itself" do
+ t = Time.utc(2022)
+ reference = "@\a"
+
+ Marshal.dump([t, t]).should == "\x04\b[\aIu:\tTime\r \x80\x1E\xC0\x00\x00\x00\x00\x06:\tzoneI\"\bUTC\x06:\x06EF#{reference}"
+ end
+ end
end
describe "with a Class" do
@@ -133,12 +227,28 @@ describe "Marshal.dump" do
Marshal.dump(UserDefined::Nested).should == "\004\bc\030UserDefined::Nested"
end
+ it "ignores overridden name method" do
+ Marshal.dump(MarshalSpec::ClassWithOverriddenName).should == "\x04\bc)MarshalSpec::ClassWithOverriddenName"
+ end
+
+ ruby_version_is "4.0" do
+ it "dumps a class with multibyte characters in name" do
+ source_object = eval("MarshalSpec::Multibyteãã‚ãƒã„Class".dup.force_encoding(Encoding::UTF_8))
+ Marshal.dump(source_object).should == "\x04\bIc,MarshalSpec::Multibyte\xE3\x81\x81\xE3\x81\x82\xE3\x81\x83\xE3\x81\x84Class\x06:\x06ET"
+ Marshal.load(Marshal.dump(source_object)) == source_object
+ end
+ end
+
+ it "uses object links for objects repeatedly dumped" do
+ Marshal.dump([String, String]).should == "\x04\b[\ac\vString@\x06" # @\x06 is a link to the object
+ end
+
it "raises TypeError with an anonymous Class" do
- lambda { Marshal.dump(Class.new) }.should raise_error(TypeError)
+ -> { Marshal.dump(Class.new) }.should.raise(TypeError, /can't dump anonymous class/)
end
it "raises TypeError with a singleton Class" do
- lambda { Marshal.dump(class << self; self end) }.should raise_error(TypeError)
+ -> { Marshal.dump(class << self; self end) }.should.raise(TypeError)
end
end
@@ -147,8 +257,24 @@ describe "Marshal.dump" do
Marshal.dump(Marshal).should == "\004\bm\fMarshal"
end
+ it "ignores overridden name method" do
+ Marshal.dump(MarshalSpec::ModuleWithOverriddenName).should == "\x04\bc*MarshalSpec::ModuleWithOverriddenName"
+ end
+
+ ruby_version_is "4.0" do
+ it "dumps a module with multibyte characters in name" do
+ source_object = eval("MarshalSpec::Multibyteã‘ã’ã“ã”Module".dup.force_encoding(Encoding::UTF_8))
+ Marshal.dump(source_object).should == "\x04\bIm-MarshalSpec::Multibyte\xE3\x81\x91\xE3\x81\x92\xE3\x81\x93\xE3\x81\x94Module\x06:\x06ET"
+ Marshal.load(Marshal.dump(source_object)) == source_object
+ end
+ end
+
+ it "uses object links for objects repeatedly dumped" do
+ Marshal.dump([Marshal, Marshal]).should == "\x04\b[\am\fMarshal@\x06" # @\x06 is a link to the object
+ end
+
it "raises TypeError with an anonymous Module" do
- lambda { Marshal.dump(Module.new) }.should raise_error(TypeError)
+ -> { Marshal.dump(Module.new) }.should.raise(TypeError, /can't dump anonymous module/)
end
end
@@ -165,6 +291,23 @@ describe "Marshal.dump" do
[Marshal, nan_value, "\004\bf\bnan"],
].should be_computed_by(:dump)
end
+
+ it "may or may not use object links for objects repeatedly dumped" do
+ # it's an MRI implementation detail - on x86 architecture object links
+ # aren't used for Float values but on amd64 - object links are used
+
+ dump = Marshal.dump([0.0, 0.0])
+ ["\x04\b[\af\x060@\x06", "\x04\b[\af\x060f\x060"].should.include?(dump)
+
+ # if object links aren't used - entries in the objects table are still
+ # occupied by Float values
+ if dump == "\x04\b[\af\x060f\x060"
+ s = "string"
+ # an index of "string" ("@\b") in the object table equals 3 (`"\b".ord - 5`),
+ # so `0.0, 0,0` elements occupied indices 1 and 2
+ Marshal.dump([0.0, 0.0, s, s]).should == "\x04\b[\tf\x060f\x060\"\vstring@\b"
+ end
+ end
end
describe "with a Bignum" do
@@ -181,15 +324,81 @@ describe "Marshal.dump" do
[Marshal, -2**64, "\004\bl-\n\000\000\000\000\000\000\000\000\001\000"],
].should be_computed_by(:dump)
end
+
+ it "uses object links for objects repeatedly dumped" do
+ n = 2**64
+ Marshal.dump([n, n]).should == "\x04\b[\al+\n\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00@\x06" # @\x06 is a link to the object
+ end
+
+ it "increases the object links counter" do
+ obj = Object.new
+ object_1_link = "\x06" # representing of (0-based) index=1 (by adding 5 for small Integers)
+ object_2_link = "\x07" # representing of index=2
+
+ # objects: Array, Object, Object
+ Marshal.dump([obj, obj]).should == "\x04\b[\ao:\vObject\x00@#{object_1_link}"
+
+ # objects: Array, Bignum, Object, Object
+ Marshal.dump([2**64, obj, obj]).should == "\x04\b[\bl+\n\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00o:\vObject\x00@#{object_2_link}"
+ Marshal.dump([2**48, obj, obj]).should == "\x04\b[\bl+\t\x00\x00\x00\x00\x00\x00\x01\x00o:\vObject\x00@#{object_2_link}"
+ Marshal.dump([2**32, obj, obj]).should == "\x04\b[\bl+\b\x00\x00\x00\x00\x01\x00o:\vObject\x00@#{object_2_link}"
+ end
+ end
+
+ describe "with a Rational" do
+ it "dumps a Rational" do
+ Marshal.dump(Rational(2, 3)).should == "\x04\bU:\rRational[\ai\ai\b"
+ end
+
+ it "uses object links for objects repeatedly dumped" do
+ r = Rational(2, 3)
+ Marshal.dump([r, r]).should == "\x04\b[\aU:\rRational[\ai\ai\b@\x06" # @\x06 is a link to the object
+ end
+ end
+
+ describe "with a Complex" do
+ it "dumps a Complex" do
+ Marshal.dump(Complex(2, 3)).should == "\x04\bU:\fComplex[\ai\ai\b"
+ end
+
+ it "uses object links for objects repeatedly dumped" do
+ c = Complex(2, 3)
+ Marshal.dump([c, c]).should == "\x04\b[\aU:\fComplex[\ai\ai\b@\x06" # @\x06 is a link to the object
+ end
+ end
+
+ describe "with a Data" do
+ it "dumps a Data" do
+ Marshal.dump(MarshalSpec::DataSpec::Measure.new(100, 'km')).should == "\x04\bS:#MarshalSpec::DataSpec::Measure\a:\vamountii:\tunit\"\akm"
+ end
+
+ it "dumps an extended Data" do
+ obj = MarshalSpec::DataSpec::MeasureExtended.new(100, "km")
+ Marshal.dump(obj).should == "\x04\bS:+MarshalSpec::DataSpec::MeasureExtended\a:\vamountii:\tunit\"\akm"
+ end
+
+ it "ignores overridden name method" do
+ obj = MarshalSpec::DataSpec::MeasureWithOverriddenName.new(100, "km")
+ Marshal.dump(obj).should == "\x04\bS:5MarshalSpec::DataSpec::MeasureWithOverriddenName\a:\vamountii:\tunit\"\akm"
+ end
+
+ it "uses object links for objects repeatedly dumped" do
+ d = MarshalSpec::DataSpec::Measure.new(100, 'km')
+ Marshal.dump([d, d]).should == "\x04\b[\aS:#MarshalSpec::DataSpec::Measure\a:\vamountii:\tunit\"\akm@\x06" # @\x06 is a link to the object
+ end
+
+ it "raises TypeError with an anonymous Struct" do
+ -> { Marshal.dump(Data.define(:a).new(1)) }.should.raise(TypeError, /can't dump anonymous class/)
+ end
end
describe "with a String" do
it "dumps a blank String" do
- Marshal.dump("".force_encoding("binary")).should == "\004\b\"\000"
+ Marshal.dump("".dup.force_encoding("binary")).should == "\004\b\"\000"
end
it "dumps a short String" do
- Marshal.dump("short".force_encoding("binary")).should == "\004\b\"\012short"
+ Marshal.dump("short".dup.force_encoding("binary")).should == "\004\b\"\012short"
end
it "dumps a long String" do
@@ -197,7 +406,7 @@ describe "Marshal.dump" do
end
it "dumps a String extended with a Module" do
- Marshal.dump("".extend(Meths).force_encoding("binary")).should == "\004\be:\nMeths\"\000"
+ Marshal.dump("".dup.extend(Meths).force_encoding("binary")).should == "\004\be:\nMeths\"\000"
end
it "dumps a String subclass" do
@@ -208,32 +417,50 @@ describe "Marshal.dump" do
Marshal.dump(UserString.new.extend(Meths).force_encoding("binary")).should == "\004\be:\nMethsC:\017UserString\"\000"
end
+ it "ignores overridden name method when dumps a String subclass" do
+ obj = MarshalSpec::StringWithOverriddenName.new
+ Marshal.dump(obj).should == "\x04\bC:*MarshalSpec::StringWithOverriddenName\"\x00"
+ end
+
it "dumps a String with instance variables" do
- str = ""
+ str = +""
str.instance_variable_set("@foo", "bar")
Marshal.dump(str.force_encoding("binary")).should == "\x04\bI\"\x00\x06:\t@foo\"\bbar"
end
- with_feature :encoding do
- it "dumps a US-ASCII String" do
- str = "abc".force_encoding("us-ascii")
- Marshal.dump(str).should == "\x04\bI\"\babc\x06:\x06EF"
- end
+ it "dumps a US-ASCII String" do
+ str = "abc".dup.force_encoding("us-ascii")
+ Marshal.dump(str).should == "\x04\bI\"\babc\x06:\x06EF"
+ end
- it "dumps a UTF-8 String" do
- str = "\x6d\xc3\xb6\x68\x72\x65".force_encoding("utf-8")
- Marshal.dump(str).should == "\x04\bI\"\vm\xC3\xB6hre\x06:\x06ET"
- end
+ it "dumps a UTF-8 String" do
+ str = "\x6d\xc3\xb6\x68\x72\x65".dup.force_encoding("utf-8")
+ Marshal.dump(str).should == "\x04\bI\"\vm\xC3\xB6hre\x06:\x06ET"
+ end
- it "dumps a String in another encoding" do
- str = "\x6d\x00\xf6\x00\x68\x00\x72\x00\x65\x00".force_encoding("utf-16le")
- result = "\x04\bI\"\x0Fm\x00\xF6\x00h\x00r\x00e\x00\x06:\rencoding\"\rUTF-16LE"
- Marshal.dump(str).should == result
- end
+ it "dumps a String in another encoding" do
+ str = "\x6d\x00\xf6\x00\x68\x00\x72\x00\x65\x00".dup.force_encoding("utf-16le")
+ result = "\x04\bI\"\x0Fm\x00\xF6\x00h\x00r\x00e\x00\x06:\rencoding\"\rUTF-16LE"
+ Marshal.dump(str).should == result
+ end
- it "dumps multiple strings using symlinks for the :E (encoding) symbol" do
- Marshal.dump(["".encode("us-ascii"), "".encode("utf-8")]).should == "\x04\b[\aI\"\x00\x06:\x06EFI\"\x00\x06;\x00T"
- end
+ it "dumps multiple strings using symlinks for the :E (encoding) symbol" do
+ Marshal.dump(["".encode("us-ascii"), "".encode("utf-8")]).should == "\x04\b[\aI\"\x00\x06:\x06EFI\"\x00\x06;\x00T"
+ end
+
+ it "uses object links for objects repeatedly dumped" do
+ s = "string"
+ Marshal.dump([s, s]).should == "\x04\b[\a\"\vstring@\x06" # @\x06 is a link to the object
+ end
+
+ it "adds instance variables after the object itself into the objects table" do
+ obj = +"string"
+ value = "<foo>"
+ obj.instance_variable_set :@foo, value
+
+ # expect a link to the object (@\x06, that means Integer 1) is smaller than a link
+ # to the instance variable value (@\a, that means Integer 2)
+ Marshal.dump([obj, obj, value]).should == "\x04\b[\bI\"\vstring\x06:\t@foo\"\n<foo>@\x06@\a"
end
end
@@ -246,14 +473,26 @@ describe "Marshal.dump" do
Marshal.dump(//im).should == "\x04\bI/\x00\x05\x06:\x06EF"
end
- it "dumps a Regexp with instance variables" do
- o = //
+ it "dumps a Regexp subclass with instance variables" do
+ o = UserRegexp.new("")
o.instance_variable_set(:@ivar, :ivar)
- Marshal.dump(o).should == "\x04\bI/\x00\x00\a:\x06EF:\n@ivar:\tivar"
+ Marshal.dump(o).should == "\x04\bIC:\x0FUserRegexp/\x00\x00\a:\x06EF:\n@ivar:\tivar"
+ end
+
+ it "dumps an extended Regexp subclass" do
+ Marshal.dump(UserRegexp.new("").extend(Meths)).should == "\x04\bIe:\nMethsC:\x0FUserRegexp/\x00\x00\x06:\x06EF"
end
- it "dumps an extended Regexp" do
- Marshal.dump(//.extend(Meths)).should == "\x04\bIe:\nMeths/\x00\x00\x06:\x06EF"
+ ruby_version_is ""..."4.1" do
+ it "dumps a Regexp with instance variables" do
+ o = Regexp.new("")
+ o.instance_variable_set(:@ivar, :ivar)
+ Marshal.dump(o).should == "\x04\bI/\x00\x00\a:\x06EF:\n@ivar:\tivar"
+ end
+
+ it "dumps an extended Regexp" do
+ Marshal.dump(Regexp.new("").extend(Meths)).should == "\x04\bIe:\nMeths/\x00\x00\x06:\x06EF"
+ end
end
it "dumps a Regexp subclass" do
@@ -261,18 +500,51 @@ describe "Marshal.dump" do
end
it "dumps a binary Regexp" do
- o = Regexp.new("".force_encoding("binary"), Regexp::FIXEDENCODING)
+ o = Regexp.new("".dup.force_encoding("binary"), Regexp::FIXEDENCODING)
Marshal.dump(o).should == "\x04\b/\x00\x10"
end
+ it "dumps an ascii-compatible Regexp" do
+ o = Regexp.new("a".encode("us-ascii"), Regexp::FIXEDENCODING)
+ Marshal.dump(o).should == "\x04\bI/\x06a\x10\x06:\x06EF"
+
+ o = Regexp.new("a".encode("us-ascii"))
+ Marshal.dump(o).should == "\x04\bI/\x06a\x00\x06:\x06EF"
+
+ o = Regexp.new("a".encode("windows-1251"), Regexp::FIXEDENCODING)
+ Marshal.dump(o).should == "\x04\bI/\x06a\x10\x06:\rencoding\"\x11Windows-1251"
+
+ o = Regexp.new("a".encode("windows-1251"))
+ Marshal.dump(o).should == "\x04\bI/\x06a\x00\x06:\x06EF"
+ end
+
it "dumps a UTF-8 Regexp" do
- o = Regexp.new("".force_encoding("utf-8"), Regexp::FIXEDENCODING)
+ o = Regexp.new("".dup.force_encoding("utf-8"), Regexp::FIXEDENCODING)
Marshal.dump(o).should == "\x04\bI/\x00\x10\x06:\x06ET"
+
+ o = Regexp.new("a".dup.force_encoding("utf-8"), Regexp::FIXEDENCODING)
+ Marshal.dump(o).should == "\x04\bI/\x06a\x10\x06:\x06ET"
+
+ o = Regexp.new("\u3042".dup.force_encoding("utf-8"), Regexp::FIXEDENCODING)
+ Marshal.dump(o).should == "\x04\bI/\b\xE3\x81\x82\x10\x06:\x06ET"
end
it "dumps a Regexp in another encoding" do
- o = Regexp.new("".force_encoding("utf-16le"), Regexp::FIXEDENCODING)
+ o = Regexp.new("".dup.force_encoding("utf-16le"), Regexp::FIXEDENCODING)
Marshal.dump(o).should == "\x04\bI/\x00\x10\x06:\rencoding\"\rUTF-16LE"
+
+ o = Regexp.new("a".encode("utf-16le"), Regexp::FIXEDENCODING)
+ Marshal.dump(o).should == "\x04\bI/\aa\x00\x10\x06:\rencoding\"\rUTF-16LE"
+ end
+
+ it "ignores overridden name method when dumps a Regexp subclass" do
+ obj = MarshalSpec::RegexpWithOverriddenName.new("")
+ Marshal.dump(obj).should == "\x04\bIC:*MarshalSpec::RegexpWithOverriddenName/\x00\x00\x06:\x06EF"
+ end
+
+ it "uses object links for objects repeatedly dumped" do
+ r = /\A.\Z/
+ Marshal.dump([r, r]).should == "\x04\b[\aI/\n\\A.\\Z\x00\x06:\x06EF@\x06" # @\x06 is a link to the object
end
end
@@ -304,6 +576,26 @@ describe "Marshal.dump" do
it "dumps an extended Array" do
Marshal.dump([].extend(Meths)).should == "\004\be:\nMeths[\000"
end
+
+ it "ignores overridden name method when dumps an Array subclass" do
+ obj = MarshalSpec::ArrayWithOverriddenName.new
+ Marshal.dump(obj).should == "\x04\bC:)MarshalSpec::ArrayWithOverriddenName[\x00"
+ end
+
+ it "uses object links for objects repeatedly dumped" do
+ a = [1]
+ Marshal.dump([a, a]).should == "\x04\b[\a[\x06i\x06@\x06" # @\x06 is a link to the object
+ end
+
+ it "adds instance variables after the object itself into the objects table" do
+ obj = []
+ value = "<foo>"
+ obj.instance_variable_set :@foo, value
+
+ # expect a link to the object (@\x06, that means Integer 1) is smaller than a link
+ # to the instance variable value (@\a, that means Integer 2)
+ Marshal.dump([obj, obj, value]).should == "\x04\b[\bI[\x00\x06:\t@foo\"\n<foo>@\x06@\a"
+ end
end
describe "with a Hash" do
@@ -311,6 +603,10 @@ describe "Marshal.dump" do
Marshal.dump({}).should == "\004\b{\000"
end
+ it "dumps a non-empty Hash" do
+ Marshal.dump({a: 1}).should == "\x04\b{\x06:\x06ai\x06"
+ end
+
it "dumps a Hash subclass" do
Marshal.dump(UserHash.new).should == "\004\bC:\rUserHash{\000"
end
@@ -319,8 +615,22 @@ describe "Marshal.dump" do
Marshal.dump(Hash.new(1)).should == "\004\b}\000i\006"
end
+ it "dumps a Hash with compare_by_identity" do
+ h = {}
+ h.compare_by_identity
+
+ Marshal.dump(h).should == "\004\bC:\tHash{\x00"
+ end
+
+ it "dumps a Hash subclass with compare_by_identity" do
+ h = UserHash.new
+ h.compare_by_identity
+
+ Marshal.dump(h).should == "\x04\bC:\rUserHashC:\tHash{\x00"
+ end
+
it "raises a TypeError with hash having default proc" do
- lambda { Marshal.dump(Hash.new {}) }.should raise_error(TypeError)
+ -> { Marshal.dump(Hash.new {}) }.should.raise(TypeError, "can't dump hash with default proc")
end
it "dumps a Hash with instance variables" do
@@ -336,6 +646,26 @@ describe "Marshal.dump" do
it "dumps an Hash subclass with a parameter to initialize" do
Marshal.dump(UserHashInitParams.new(1)).should == "\004\bIC:\027UserHashInitParams{\000\006:\a@ai\006"
end
+
+ it "ignores overridden name method when dumps a Hash subclass" do
+ obj = MarshalSpec::HashWithOverriddenName.new
+ Marshal.dump(obj).should == "\x04\bC:(MarshalSpec::HashWithOverriddenName{\x00"
+ end
+
+ it "uses object links for objects repeatedly dumped" do
+ h = {a: 1}
+ Marshal.dump([h, h]).should == "\x04\b[\a{\x06:\x06ai\x06@\x06" # @\x06 is a link to the object
+ end
+
+ it "adds instance variables after the object itself into the objects table" do
+ obj = {}
+ value = "<foo>"
+ obj.instance_variable_set :@foo, value
+
+ # expect a link to the object (@\x06, that means Integer 1) is smaller than a link
+ # to the instance variable value (@\a, that means Integer 2)
+ Marshal.dump([obj, obj, value]).should == "\x04\b[\bI{\x00\x06:\t@foo\"\n<foo>@\x06@\a"
+ end
end
describe "with a Struct" do
@@ -355,10 +685,39 @@ describe "Marshal.dump" do
end
it "dumps an extended Struct" do
- st = Struct.new("Extended", :a, :b).new
- Marshal.dump(st.extend(Meths)).should == "\004\be:\nMethsS:\025Struct::Extended\a:\006a0:\006b0"
+ obj = Struct.new("Extended", :a, :b).new.extend(Meths)
+ Marshal.dump(obj).should == "\004\be:\nMethsS:\025Struct::Extended\a:\006a0:\006b0"
+
+ s = 'hi'
+ obj.a = [:a, s]
+ obj.b = [:Meths, s]
+ Marshal.dump(obj).should == "\004\be:\nMethsS:\025Struct::Extended\a:\006a[\a;\a\"\ahi:\006b[\a;\000@\a"
Struct.send(:remove_const, :Extended)
end
+
+ it "ignores overridden name method" do
+ obj = MarshalSpec::StructWithOverriddenName.new("member")
+ Marshal.dump(obj).should == "\x04\bS:*MarshalSpec::StructWithOverriddenName\x06:\x06a\"\vmember"
+ end
+
+ it "uses object links for objects repeatedly dumped" do
+ s = Struct::Pyramid.new
+ Marshal.dump([s, s]).should == "\x04\b[\aS:\x14Struct::Pyramid\x00@\x06" # @\x06 is a link to the object
+ end
+
+ it "raises TypeError with an anonymous Struct" do
+ -> { Marshal.dump(Struct.new(:a).new(1)) }.should.raise(TypeError, /can't dump anonymous class/)
+ end
+
+ it "adds instance variables after the object itself into the objects table" do
+ obj = Struct::Pyramid.new
+ value = "<foo>"
+ obj.instance_variable_set :@foo, value
+
+ # expect a link to the object (@\x06, that means Integer 1) is smaller than a link
+ # to the instance variable value (@\a, that means Integer 2)
+ Marshal.dump([obj, obj, value]).should == "\x04\b[\bIS:\x14Struct::Pyramid\x00\x06:\t@foo\"\n<foo>@\x06@\a"
+ end
end
describe "with an Object" do
@@ -376,6 +735,13 @@ describe "Marshal.dump" do
Marshal.dump(obj).should == "\004\bo:\vObject\006:\n@ivari\006"
end
+ it "dumps an Object with a non-US-ASCII instance variable" do
+ obj = Object.new
+ ivar = "@é".dup.force_encoding(Encoding::UTF_8).to_sym
+ obj.instance_variable_set(ivar, 1)
+ Marshal.dump(obj).should == "\x04\bo:\vObject\x06I:\b@\xC3\xA9\x06:\x06ETi\x06"
+ end
+
it "dumps an Object that has had an instance variable added and removed as though it was never set" do
obj = Object.new
obj.instance_variable_set(:@ivar, 1)
@@ -383,46 +749,105 @@ describe "Marshal.dump" do
Marshal.dump(obj).should == "\004\bo:\x0BObject\x00"
end
- it "dumps an Object if it has a singleton class but no singleton methods" do
+ it "dumps an Object if it has a singleton class but no singleton methods and no singleton instance variables" do
obj = Object.new
obj.singleton_class
Marshal.dump(obj).should == "\004\bo:\x0BObject\x00"
end
- it "raises if an Object has a singleton class and singleton methods" do
+ it "ignores overridden name method" do
+ obj = MarshalSpec::ClassWithOverriddenName.new
+ Marshal.dump(obj).should == "\x04\bo:)MarshalSpec::ClassWithOverriddenName\x00"
+ end
+
+ it "raises TypeError if an Object has a singleton class and singleton methods" do
obj = Object.new
def obj.foo; end
- lambda {
+ -> {
+ Marshal.dump(obj)
+ }.should.raise(TypeError, "singleton can't be dumped")
+ end
+
+ it "raises TypeError if an Object has a singleton class and singleton instance variables" do
+ obj = Object.new
+ class << obj
+ @v = 1
+ end
+
+ -> {
Marshal.dump(obj)
- }.should raise_error(TypeError, "singleton can't be dumped")
+ }.should.raise(TypeError, "singleton can't be dumped")
+ end
+
+ it "raises TypeError if an Object is an instance of an anonymous class" do
+ anonymous_class = Class.new
+ obj = anonymous_class.new
+
+ -> { Marshal.dump(obj) }.should.raise(TypeError, /can't dump anonymous class/)
+ end
+
+ it "raises TypeError if an Object extends an anonymous module" do
+ anonymous_module = Module.new
+ obj = Object.new
+ obj.extend(anonymous_module)
+
+ -> { Marshal.dump(obj) }.should.raise(TypeError, /can't dump anonymous class/)
end
it "dumps a BasicObject subclass if it defines respond_to?" do
obj = MarshalSpec::BasicObjectSubWithRespondToFalse.new
Marshal.dump(obj).should == "\x04\bo:2MarshalSpec::BasicObjectSubWithRespondToFalse\x00"
end
+
+ it "dumps without marshaling any attached finalizer" do
+ obj = Object.new
+ finalizer = Object.new
+ def finalizer.noop(_)
+ end
+ ObjectSpace.define_finalizer(obj, finalizer.method(:noop))
+ Marshal.load(Marshal.dump(obj)).class.should == Object
+ end
+
+ it "uses object links for objects repeatedly dumped" do
+ obj = Object.new
+ Marshal.dump([obj, obj]).should == "\x04\b[\ao:\vObject\x00@\x06" # @\x06 is a link to the object
+ end
+
+ it "adds instance variables after the object itself into the objects table" do
+ obj = Object.new
+ value = "<foo>"
+ obj.instance_variable_set :@foo, value
+
+ # expect a link to the object (@\x06, that means Integer 1) is smaller than a link
+ # to the instance variable value (@\a, that means Integer 2)
+ Marshal.dump([obj, obj, value]).should == "\x04\b[\bo:\vObject\x06:\t@foo\"\n<foo>@\x06@\a"
+ end
end
describe "with a Range" do
- it "dumps a Range inclusive of end (with indeterminant order)" do
+ it "dumps a Range inclusive of end" do
dump = Marshal.dump(1..2)
+ dump.should == "\x04\bo:\nRange\b:\texclF:\nbegini\x06:\bendi\a"
+
load = Marshal.load(dump)
load.should == (1..2)
end
- it "dumps a Range exclusive of end (with indeterminant order)" do
+ it "dumps a Range exclusive of end" do
dump = Marshal.dump(1...2)
+ dump.should == "\x04\bo:\nRange\b:\texclT:\nbegini\x06:\bendi\a"
+
load = Marshal.load(dump)
load.should == (1...2)
end
- it "dumps a Range with extra instance variables" do
- range = (1...3)
- range.instance_variable_set :@foo, 42
- dump = Marshal.dump(range)
- load = Marshal.load(dump)
- load.should == range
- load.instance_variable_get(:@foo).should == 42
+ it "uses object links for objects repeatedly dumped" do
+ r = 1..2
+ Marshal.dump([r, r]).should == "\x04\b[\ao:\nRange\b:\texclF:\nbegini\x06:\bendi\a@\x06" # @\x06 is a link to the object
+ end
+
+ it "raises TypeError with an anonymous Range subclass" do
+ -> { Marshal.dump(Class.new(Range).new(1, 2)) }.should.raise(TypeError, /can't dump anonymous class/)
end
end
@@ -452,16 +877,52 @@ describe "Marshal.dump" do
base = "\x04\bIu:\tTime\r#{@t_dump}\a"
offset = ":\voffseti\x020*"
zone = ":\tzoneI\"\bAST\x06:\x06EF" # Last is 'F' (US-ASCII)
- [ "#{base}#{offset}#{zone}", "#{base}#{zone}#{offset}" ].should include(dump)
+ [ "#{base}#{offset}#{zone}", "#{base}#{zone}#{offset}" ].should.include?(dump)
end
+ end
+
+ it "dumps the zone, but not the offset if zone is UTC" do
+ dump = Marshal.dump(@utc)
+ zone = ":\tzoneI\"\bUTC\x06:\x06EF" # Last is 'F' (US-ASCII)
+ dump.should == "\x04\bIu:\tTime\r#{@utc_dump}\x06#{zone}"
+ end
+
+ it "ignores overridden name method" do
+ obj = MarshalSpec::TimeWithOverriddenName.new
+ Marshal.dump(obj).should.include?("MarshalSpec::TimeWithOverriddenName")
+ end
- it "dumps the zone, but not the offset if zone is UTC" do
- dump = Marshal.dump(@utc)
- zone = ":\tzoneI\"\bUTC\x06:\x06EF" # Last is 'F' (US-ASCII)
- dump.should == "\x04\bIu:\tTime\r#{@utc_dump}\x06#{zone}"
+ ruby_version_is "4.0" do
+ it "dumps a Time subclass with multibyte characters in name" do
+ source_object = eval("MarshalSpec::Multibyteãã‚ãƒã„Time".dup.force_encoding(Encoding::UTF_8))
+ Marshal.dump(source_object).should == "\x04\bIc+MarshalSpec::Multibyte\xE3\x81\x81\xE3\x81\x82\xE3\x81\x83\xE3\x81\x84Time\x06:\x06ET"
+ Marshal.load(Marshal.dump(source_object)) == source_object
end
end
+ it "uses object links for objects repeatedly dumped" do
+ # order of the offset and zone instance variables is a subject to change
+ # and may be different on different CRuby versions
+ base = Regexp.quote("\x04\b[\aIu:\tTime\r\xF5\xEF\e\x80\x00\x00\x00\x00\a")
+ offset = Regexp.quote(":\voffseti\x020*:\tzoneI\"\bAST\x06:\x06EF")
+ zone = Regexp.quote(":\tzoneI\"\bAST\x06:\x06EF:\voffseti\x020*")
+ instance_variables = /#{offset}|#{zone}/
+ Marshal.dump([@t, @t]).should =~ /\A#{base}#{instance_variables}@\a\Z/ # @\a is a link to the object
+ end
+
+ it "adds instance variables before the object itself into the objects table" do
+ obj = @utc
+ value = "<foo>"
+ obj.instance_variable_set :@foo, value
+
+ # expect a link to the object (@\b, that means Integer 3) is greater than a link
+ # to the instance variable value (@\x06, that means Integer 1)
+ Marshal.dump([obj, obj, value]).should == "\x04\b[\bIu:\tTime\r \x00\x1C\xC0\x00\x00\x00\x00\a:\t@foo\"\n<foo>:\tzoneI\"\bUTC\x06:\x06EF@\b@\x06"
+ end
+
+ it "raises TypeError with an anonymous Time subclass" do
+ -> { Marshal.dump(Class.new(Time).now) }.should.raise(TypeError)
+ end
end
describe "with an Exception" do
@@ -478,6 +939,62 @@ describe "Marshal.dump" do
obj.set_backtrace(["foo/bar.rb:10"])
Marshal.dump(obj).should == "\x04\bo:\x0EException\a:\tmesg\"\bfoo:\abt[\x06\"\x12foo/bar.rb:10"
end
+
+ it "dumps instance variables if they exist" do
+ obj = Exception.new("foo")
+ obj.instance_variable_set(:@ivar, 1)
+ Marshal.dump(obj).should == "\x04\bo:\x0EException\b:\tmesg\"\bfoo:\abt0:\n@ivari\x06"
+ end
+
+ it "dumps the cause for the exception" do
+ exc = nil
+ begin
+ raise StandardError, "the cause"
+ rescue StandardError => cause
+ begin
+ raise RuntimeError, "the consequence"
+ rescue RuntimeError => e
+ e.cause.should.equal?(cause)
+ exc = e
+ end
+ end
+
+ reloaded = Marshal.load(Marshal.dump(exc))
+ reloaded.cause.should.instance_of?(StandardError)
+ reloaded.cause.message.should == "the cause"
+ end
+
+ # NoMethodError uses an exception formatter on TruffleRuby and computes a message lazily
+ it "dumps the message for the raised NoMethodError exception" do
+ begin
+ "".foo
+ rescue => e
+ end
+
+ Marshal.dump(e).should =~ /undefined method [`']foo' for ("":String|an instance of String)/
+ end
+
+ it "uses object links for objects repeatedly dumped" do
+ e = Exception.new
+ Marshal.dump([e, e]).should == "\x04\b[\ao:\x0EException\a:\tmesg0:\abt0@\x06" # @\x\a is a link to the object
+ end
+
+ it "adds instance variables after the object itself into the objects table" do
+ obj = Exception.new
+ value = "<foo>"
+ obj.instance_variable_set :@foo, value
+
+ # expect a link to the object (@\x06, that means Integer 1) is smaller than a link
+ # to the instance variable value (@\a, that means Integer 2)
+ Marshal.dump([obj, obj, value]).should == "\x04\b[\bo:\x0EException\b:\tmesg0:\abt0:\t@foo\"\n<foo>@\x06@\a"
+ end
+
+ it "raises TypeError if an Object is an instance of an anonymous class" do
+ anonymous_class = Class.new(Exception)
+ obj = anonymous_class.new
+
+ -> { Marshal.dump(obj) }.should.raise(TypeError, /can't dump anonymous class/)
+ end
end
it "dumps subsequent appearances of a symbol as a link" do
@@ -497,10 +1014,10 @@ describe "Marshal.dump" do
it "raises an ArgumentError when the recursion limit is exceeded" do
h = {'one' => {'two' => {'three' => 0}}}
- lambda { Marshal.dump(h, 3) }.should raise_error(ArgumentError)
- lambda { Marshal.dump([h], 4) }.should raise_error(ArgumentError)
- lambda { Marshal.dump([], 0) }.should raise_error(ArgumentError)
- lambda { Marshal.dump([[[]]], 1) }.should raise_error(ArgumentError)
+ -> { Marshal.dump(h, 3) }.should.raise(ArgumentError)
+ -> { Marshal.dump([h], 4) }.should.raise(ArgumentError)
+ -> { Marshal.dump([], 0) }.should.raise(ArgumentError)
+ -> { Marshal.dump([[[]]], 1) }.should.raise(ArgumentError)
end
it "ignores the recursion limit if the limit is negative" do
@@ -510,7 +1027,6 @@ describe "Marshal.dump" do
end
describe "when passed an IO" do
-
it "writes the serialized data to the IO-Object" do
(obj = mock('test')).should_receive(:write).at_least(1)
Marshal.dump("test", obj)
@@ -523,60 +1039,44 @@ describe "Marshal.dump" do
it "raises an Error when the IO-Object does not respond to #write" do
obj = mock('test')
- lambda { Marshal.dump("test", obj) }.should raise_error(TypeError)
+ -> { Marshal.dump("test", obj) }.should.raise(TypeError)
end
- with_feature :encoding do
-
- it "calls binmode when it's defined" do
- obj = mock('test')
- obj.should_receive(:write).at_least(1)
- obj.should_receive(:binmode).at_least(1)
- Marshal.dump("test", obj)
- end
+ it "calls binmode when it's defined" do
+ obj = mock('test')
+ obj.should_receive(:write).at_least(1)
+ obj.should_receive(:binmode).at_least(1)
+ Marshal.dump("test", obj)
end
+ end
+ describe "when passed a StringIO" do
+ it "should raise an error" do
+ require "stringio"
+ -> { Marshal.dump(StringIO.new) }.should.raise(TypeError)
+ end
end
it "raises a TypeError if marshalling a Method instance" do
- lambda { Marshal.dump(Marshal.method(:dump)) }.should raise_error(TypeError)
+ -> { Marshal.dump(Marshal.method(:dump)) }.should.raise(TypeError)
end
it "raises a TypeError if marshalling a Proc" do
- lambda { Marshal.dump(proc {}) }.should raise_error(TypeError)
+ -> { Marshal.dump(proc {}) }.should.raise(TypeError)
end
it "raises a TypeError if dumping a IO/File instance" do
- lambda { Marshal.dump(STDIN) }.should raise_error(TypeError)
- lambda { File.open(__FILE__) { |f| Marshal.dump(f) } }.should raise_error(TypeError)
+ -> { Marshal.dump(STDIN) }.should.raise(TypeError)
+ -> { File.open(__FILE__) { |f| Marshal.dump(f) } }.should.raise(TypeError)
end
it "raises a TypeError if dumping a MatchData instance" do
- lambda { Marshal.dump(/(.)/.match("foo")) }.should raise_error(TypeError)
- end
-
- it "returns an untainted string if object is untainted" do
- Marshal.dump(Object.new).tainted?.should be_false
- end
-
- it "returns a tainted string if object is tainted" do
- Marshal.dump(Object.new.taint).tainted?.should be_true
- end
-
- it "returns a tainted string if nested object is tainted" do
- Marshal.dump([[Object.new.taint]]).tainted?.should be_true
- end
-
- it "returns a trusted string if object is trusted" do
- Marshal.dump(Object.new).untrusted?.should be_false
- end
-
- it "returns an untrusted string if object is untrusted" do
- Marshal.dump(Object.new.untrust).untrusted?.should be_true
+ -> { Marshal.dump(/(.)/.match("foo")) }.should.raise(TypeError)
end
- it "returns an untrusted string if nested object is untrusted" do
- Marshal.dump([[Object.new.untrust]]).untrusted?.should be_true
+ it "raises a TypeError if dumping a Mutex instance" do
+ m = Mutex.new
+ -> { Marshal.dump(m) }.should.raise(TypeError)
end
end
diff --git a/spec/ruby/core/marshal/fixtures/classes.rb b/spec/ruby/core/marshal/fixtures/classes.rb
new file mode 100644
index 0000000000..7c81c64927
--- /dev/null
+++ b/spec/ruby/core/marshal/fixtures/classes.rb
@@ -0,0 +1,4 @@
+module MarshalSpec
+ # empty modules
+ module M1 end
+end
diff --git a/spec/ruby/core/marshal/fixtures/marshal_data.rb b/spec/ruby/core/marshal/fixtures/marshal_data.rb
index 2931278290..c16d9e4bb6 100644
--- a/spec/ruby/core/marshal/fixtures/marshal_data.rb
+++ b/spec/ruby/core/marshal/fixtures/marshal_data.rb
@@ -1,4 +1,7 @@
-# -*- encoding: binary -*-
+# encoding: binary
+
+require_relative 'marshal_multibyte_data'
+
class UserDefined
class Nested
def ==(other)
@@ -38,7 +41,7 @@ class UserDefinedWithIvar
attr_reader :a, :b, :c
def initialize
- @a = 'stuff'
+ @a = +'stuff'
@a.instance_variable_set :@foo, :UserDefinedWithIvar
@b = 'more'
@c = @b
@@ -78,12 +81,47 @@ class UserDefinedImmediate
end
end
+class UserDefinedString
+ attr_reader :string
+
+ def initialize(string)
+ @string = string
+ end
+
+ def _dump(depth)
+ @string
+ end
+
+ def self._load(data)
+ new(data)
+ end
+end
+
+module MarshalSpec
+ class UserDefinedDumpWithIVars
+ attr_reader :string
+
+ def initialize(string, ivar_value)
+ @string = string
+ @string.instance_variable_set(:@foo, ivar_value)
+ end
+
+ def _dump(depth)
+ @string
+ end
+
+ def self._load(data)
+ new(data)
+ end
+ end
+end
+
class UserPreviouslyDefinedWithInitializedIvar
attr_accessor :field1, :field2
end
class UserMarshal
- attr_reader :data
+ attr_accessor :data
def initialize
@data = 'stuff'
@@ -120,6 +158,32 @@ class UserMarshalWithIvar
end
end
+module MarshalSpec
+ class UserMarshalDumpWithIvar
+ attr_reader :data
+
+ def initialize(data, ivar_value)
+ @data = data
+ @ivar_value = ivar_value
+ end
+
+ def marshal_dump
+ obj = [data]
+ obj.instance_variable_set(:@foo, @ivar_value)
+ obj
+ end
+
+ def marshal_load(o)
+ @data = o[0]
+ end
+
+ def ==(other)
+ self.class === other and
+ @data = other.data
+ end
+ end
+end
+
class UserArray < Array
end
@@ -167,12 +231,17 @@ module MarshalSpec
end
end
+ StructToDump = Struct.new(:a, :b)
+
class BasicObjectSubWithRespondToFalse < BasicObject
def respond_to?(method_name, include_all=false)
false
end
end
+ module ModuleToExtendBy
+ end
+
def self.random_data
randomizer = Random.new(42)
1000.times{randomizer.rand} # Make sure we exhaust his first state of 624 random words
@@ -192,6 +261,70 @@ module MarshalSpec
set_swapped_class(nil)
end
+ class ClassWithOverriddenName
+ def self.name
+ "Foo"
+ end
+ end
+
+ class ModuleWithOverriddenName
+ def self.name
+ "Foo"
+ end
+ end
+
+ class TimeWithOverriddenName < Time
+ def self.name
+ "Foo"
+ end
+ end
+
+ class StructWithOverriddenName < Struct.new(:a)
+ def self.name
+ "Foo"
+ end
+ end
+
+ class UserDefinedWithOverriddenName < UserDefined
+ def self.name
+ "Foo"
+ end
+ end
+
+ class StringWithOverriddenName < String
+ def self.name
+ "Foo"
+ end
+ end
+
+ class ArrayWithOverriddenName < Array
+ def self.name
+ "Foo"
+ end
+ end
+
+ class HashWithOverriddenName < Hash
+ def self.name
+ "Foo"
+ end
+ end
+
+ class RegexpWithOverriddenName < Regexp
+ def self.name
+ "Foo"
+ end
+ end
+
+ class ObjectWithFreezeRaisingException < Object
+ def freeze
+ raise
+ end
+ end
+
+ class ObjectWithoutFreeze < Object
+ undef freeze
+ end
+
DATA = {
"nil" => [nil, "\004\b0"],
"1..2" => [(1..2),
@@ -217,7 +350,7 @@ module MarshalSpec
"\004\b\"\012small"],
"String big" => ['big' * 100,
"\004\b\"\002,\001#{'big' * 100}"],
- "String extended" => [''.extend(Meths), # TODO: check for module on load
+ "String extended" => [''.dup.extend(Meths), # TODO: check for module on load
"\004\be:\nMeths\"\000"],
"String subclass" => [UserString.new,
"\004\bC:\017UserString\"\000"],
@@ -227,36 +360,36 @@ module MarshalSpec
"\004\b:\010big"],
"Symbol big" => [('big' * 100).to_sym,
"\004\b:\002,\001#{'big' * 100}"],
- "Bignum -2**64" => [-2**64,
+ "Integer -2**64" => [-2**64,
"\004\bl-\n\000\000\000\000\000\000\000\000\001\000"],
- "Bignum -2**63" => [-2**63,
+ "Integer -2**63" => [-2**63,
"\004\bl-\t\000\000\000\000\000\000\000\200"],
- "Fixnum -2**24" => [-2**24,
+ "Integer -2**24" => [-2**24,
"\004\bi\375\000\000\000"],
- "Fixnum -4516727" => [-4516727,
+ "Integer -4516727" => [-4516727,
"\004\bi\375\211\024\273"],
- "Fixnum -2**16" => [-2**16,
+ "Integer -2**16" => [-2**16,
"\004\bi\376\000\000"],
- "Fixnum -2**8" => [-2**8,
+ "Integer -2**8" => [-2**8,
"\004\bi\377\000"],
- "Fixnum -123" => [-123,
+ "Integer -123" => [-123,
"\004\bi\200"],
- "Fixnum -124" => [-124, "\004\bi\377\204"],
- "Fixnum 0" => [0,
+ "Integer -124" => [-124, "\004\bi\377\204"],
+ "Integer 0" => [0,
"\004\bi\000"],
- "Fixnum 5" => [5,
+ "Integer 5" => [5,
"\004\bi\n"],
- "Fixnum 122" => [122, "\004\bi\177"],
- "Fixnum 123" => [123, "\004\bi\001{"],
- "Fixnum 2**8" => [2**8,
+ "Integer 122" => [122, "\004\bi\177"],
+ "Integer 123" => [123, "\004\bi\001{"],
+ "Integer 2**8" => [2**8,
"\004\bi\002\000\001"],
- "Fixnum 2**16" => [2**16,
+ "Integer 2**16" => [2**16,
"\004\bi\003\000\000\001"],
- "Fixnum 2**24" => [2**24,
+ "Integer 2**24" => [2**24,
"\004\bi\004\000\000\000\001"],
- "Bignum 2**64" => [2**64,
+ "Integer 2**64" => [2**64,
"\004\bl+\n\000\000\000\000\000\000\000\000\001\000"],
- "Bignum 2**90" => [2**90,
+ "Integer 2**90" => [2**90,
"\004\bl+\v#{"\000" * 11}\004"],
"Class String" => [String,
"\004\bc\vString"],
@@ -324,7 +457,7 @@ module MarshalSpec
"\x04\bI\"\nsmall\x06:\x06EF"],
"String big" => ['big' * 100,
"\x04\bI\"\x02,\x01bigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbigbig\x06:\x06EF"],
- "String extended" => [''.extend(Meths), # TODO: check for module on load
+ "String extended" => [''.dup.extend(Meths), # TODO: check for module on load
"\x04\bIe:\nMeths\"\x00\x06:\x06EF"],
"String subclass" => [UserString.new,
"\004\bC:\017UserString\"\000"],
@@ -334,31 +467,31 @@ module MarshalSpec
"\004\b:\010big"],
"Symbol big" => [('big' * 100).to_sym,
"\004\b:\002,\001#{'big' * 100}"],
- "Bignum -2**64" => [-2**64,
+ "Integer -2**64" => [-2**64,
"\004\bl-\n\000\000\000\000\000\000\000\000\001\000"],
- "Bignum -2**63" => [-2**63,
+ "Integer -2**63" => [-2**63,
"\004\bl-\t\000\000\000\000\000\000\000\200"],
- "Fixnum -2**24" => [-2**24,
+ "Integer -2**24" => [-2**24,
"\004\bi\375\000\000\000"],
- "Fixnum -2**16" => [-2**16,
+ "Integer -2**16" => [-2**16,
"\004\bi\376\000\000"],
- "Fixnum -2**8" => [-2**8,
+ "Integer -2**8" => [-2**8,
"\004\bi\377\000"],
- "Fixnum -123" => [-123,
+ "Integer -123" => [-123,
"\004\bi\200"],
- "Fixnum 0" => [0,
+ "Integer 0" => [0,
"\004\bi\000"],
- "Fixnum 5" => [5,
+ "Integer 5" => [5,
"\004\bi\n"],
- "Fixnum 2**8" => [2**8,
+ "Integer 2**8" => [2**8,
"\004\bi\002\000\001"],
- "Fixnum 2**16" => [2**16,
+ "Integer 2**16" => [2**16,
"\004\bi\003\000\000\001"],
- "Fixnum 2**24" => [2**24,
+ "Integer 2**24" => [2**24,
"\004\bi\004\000\000\000\001"],
- "Bignum 2**64" => [2**64,
+ "Integer 2**64" => [2**64,
"\004\bl+\n\000\000\000\000\000\000\000\000\001\000"],
- "Bignum 2**90" => [2**90,
+ "Integer 2**90" => [2**90,
"\004\bl+\v#{"\000" * 11}\004"],
"Class String" => [String,
"\004\bc\vString"],
@@ -398,6 +531,20 @@ module MarshalSpec
"\004\bS:\024Struct::Pyramid\000"],
"Random" => random_data,
}
+
+ module DataSpec
+ Measure = Data.define(:amount, :unit)
+ Empty = Data.define
+
+ MeasureExtended = Class.new(Measure)
+ MeasureExtended.extend(Enumerable)
+
+ class MeasureWithOverriddenName < Measure
+ def self.name
+ "Foo"
+ end
+ end
+ end
end
class ArraySub < Array
diff --git a/spec/ruby/core/marshal/fixtures/marshal_multibyte_data.rb b/spec/ruby/core/marshal/fixtures/marshal_multibyte_data.rb
new file mode 100644
index 0000000000..98a0d43392
--- /dev/null
+++ b/spec/ruby/core/marshal/fixtures/marshal_multibyte_data.rb
@@ -0,0 +1,12 @@
+# -*- encoding: utf-8 -*-
+
+module MarshalSpec
+ class Multibyteãã‚ãƒã„Class
+ end
+
+ module Multibyteã‘ã’ã“ã”Module
+ end
+
+ class Multibyteãã‚ãƒã„Time < Time
+ end
+end
diff --git a/spec/ruby/core/marshal/float_spec.rb b/spec/ruby/core/marshal/float_spec.rb
index 0bdde3ccc1..5b2d68d6e1 100644
--- a/spec/ruby/core/marshal/float_spec.rb
+++ b/spec/ruby/core/marshal/float_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Marshal.dump with Float" do
it "represents NaN" do
@@ -40,7 +40,7 @@ end
describe "Marshal.load with Float" do
it "loads NaN" do
- Marshal.load("\004\bf\bnan").should be_nan
+ Marshal.load("\004\bf\bnan").should.nan?
end
it "loads +Infinity" do
diff --git a/spec/ruby/core/marshal/load_spec.rb b/spec/ruby/core/marshal/load_spec.rb
index 53d60f0619..f5a05f8e52 100644
--- a/spec/ruby/core/marshal/load_spec.rb
+++ b/spec/ruby/core/marshal/load_spec.rb
@@ -1,6 +1,1291 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/load', __FILE__)
+# encoding: binary
+require_relative '../../spec_helper'
+require_relative 'fixtures/marshal_data'
describe "Marshal.load" do
- it_behaves_like :marshal_load, :load
+ before :all do
+ @num_self_class = 1
+ end
+
+ it "raises an ArgumentError when the dumped data is truncated" do
+ obj = {first: 1, second: 2, third: 3}
+ -> { Marshal.load(Marshal.dump(obj)[0, 5]) }.should.raise(ArgumentError, "marshal data too short")
+ end
+
+ it "raises an ArgumentError when the argument is empty String" do
+ -> { Marshal.load("") }.should.raise(ArgumentError, "marshal data too short")
+ end
+
+ it "raises an ArgumentError when the dumped class is missing" do
+ Object.send(:const_set, :KaBoom, Class.new)
+ kaboom = Marshal.dump(KaBoom.new)
+ Object.send(:remove_const, :KaBoom)
+
+ -> { Marshal.load(kaboom) }.should.raise(ArgumentError)
+ end
+
+ describe "when called with freeze: true" do
+ it "returns frozen strings" do
+ string = Marshal.load(Marshal.dump("foo"), freeze: true)
+ string.should == "foo"
+ string.should.frozen?
+
+ utf8_string = "foo".encode(Encoding::UTF_8)
+ string = Marshal.load(Marshal.dump(utf8_string), freeze: true)
+ string.should == utf8_string
+ string.should.frozen?
+ end
+
+ it "returns frozen arrays" do
+ array = Marshal.load(Marshal.dump([1, 2, 3]), freeze: true)
+ array.should == [1, 2, 3]
+ array.should.frozen?
+ end
+
+ it "returns frozen hashes" do
+ hash = Marshal.load(Marshal.dump({foo: 42}), freeze: true)
+ hash.should == {foo: 42}
+ hash.should.frozen?
+ end
+
+ it "returns frozen regexps" do
+ regexp = Marshal.load(Marshal.dump(/foo/), freeze: true)
+ regexp.should == /foo/
+ regexp.should.frozen?
+ end
+
+ it "returns frozen structs" do
+ struct = Marshal.load(Marshal.dump(MarshalSpec::StructToDump.new(1, 2)), freeze: true)
+ struct.should == MarshalSpec::StructToDump.new(1, 2)
+ struct.should.frozen?
+ end
+
+ it "returns frozen objects" do
+ source_object = Object.new
+
+ object = Marshal.load(Marshal.dump(source_object), freeze: true)
+ object.should.frozen?
+ end
+
+ describe "deep freezing" do
+ it "returns hashes with frozen keys and values" do
+ key = Object.new
+ value = Object.new
+ source_object = {key => value}
+
+ hash = Marshal.load(Marshal.dump(source_object), freeze: true)
+ hash.size.should == 1
+ hash.keys[0].should.frozen?
+ hash.values[0].should.frozen?
+ end
+
+ it "returns arrays with frozen elements" do
+ object = Object.new
+ source_object = [object]
+
+ array = Marshal.load(Marshal.dump(source_object), freeze: true)
+ array.size.should == 1
+ array[0].should.frozen?
+ end
+
+ it "returns structs with frozen members" do
+ object1 = Object.new
+ object2 = Object.new
+ source_object = MarshalSpec::StructToDump.new(object1, object2)
+
+ struct = Marshal.load(Marshal.dump(source_object), freeze: true)
+ struct.a.should.frozen?
+ struct.b.should.frozen?
+ end
+
+ it "returns objects with frozen instance variables" do
+ source_object = Object.new
+ instance_variable = Object.new
+ source_object.instance_variable_set(:@a, instance_variable)
+
+ object = Marshal.load(Marshal.dump(source_object), freeze: true)
+ object.instance_variable_get(:@a).should != nil
+ object.instance_variable_get(:@a).should.frozen?
+ end
+
+ it "deduplicates frozen strings" do
+ source_object = ["foo" + "bar", "foobar"]
+ object = Marshal.load(Marshal.dump(source_object), freeze: true)
+
+ object[0].should.equal?(object[1])
+ end
+ end
+
+ it "does not freeze modules" do
+ object = Marshal.load(Marshal.dump(Kernel), freeze: true)
+ object.should_not.frozen?
+ Kernel.should_not.frozen?
+ end
+
+ it "does not freeze classes" do
+ object = Marshal.load(Marshal.dump(Object), freeze: true)
+ object.should_not.frozen?
+ Object.should_not.frozen?
+ end
+
+ it "does freeze extended objects" do
+ object = Marshal.load("\x04\be:\x0FEnumerableo:\vObject\x00", freeze: true)
+ object.should.frozen?
+ end
+
+ it "does freeze extended objects with instance variables" do
+ object = Marshal.load("\x04\be:\x0FEnumerableo:\vObject\x06:\n@ivarT", freeze: true)
+ object.should.frozen?
+ end
+
+ it "returns frozen object having #_dump method" do
+ object = Marshal.load(Marshal.dump(UserDefined.new), freeze: true)
+ object.should.frozen?
+ end
+
+ it "returns frozen object responding to #marshal_dump and #marshal_load" do
+ object = Marshal.load(Marshal.dump(UserMarshal.new), freeze: true)
+ object.should.frozen?
+ end
+
+ it "returns frozen object extended by a module" do
+ object = Object.new
+ object.extend(MarshalSpec::ModuleToExtendBy)
+
+ object = Marshal.load(Marshal.dump(object), freeze: true)
+ object.should.frozen?
+ end
+
+ it "does not call freeze method" do
+ object = MarshalSpec::ObjectWithFreezeRaisingException.new
+ object = Marshal.load(Marshal.dump(object), freeze: true)
+ object.should.frozen?
+ end
+
+ it "returns frozen object even if object does not respond to freeze method" do
+ object = MarshalSpec::ObjectWithoutFreeze.new
+ object = Marshal.load(Marshal.dump(object), freeze: true)
+ object.should.frozen?
+ end
+
+ it "returns a frozen object when is an instance of String/Array/Regexp/Hash subclass and has instance variables" do
+ source_object = UserString.new
+ source_object.instance_variable_set(:@foo, "bar")
+
+ object = Marshal.load(Marshal.dump(source_object), freeze: true)
+ object.should.frozen?
+ end
+
+ describe "when called with a proc" do
+ it "call the proc with frozen objects" do
+ arr = []
+ s = +'hi'
+ s.instance_variable_set(:@foo, 5)
+ st = Struct.new("Brittle", :a).new
+ st.instance_variable_set(:@clue, 'none')
+ st.a = 0.0
+ h = Hash.new('def')
+ h['nine'] = 9
+ a = [:a, :b, :c]
+ a.instance_variable_set(:@two, 2)
+ obj = [s, 10, s, s, st, a]
+ obj.instance_variable_set(:@zoo, 'ant')
+ proc = Proc.new { |o| arr << o; o}
+
+ Marshal.load(
+ "\x04\bI[\vI\"\ahi\a:\x06EF:\t@fooi\ni\x0F@\x06@\x06IS:\x14Struct::Brittle\x06:\x06af\x060\x06:\n@clueI\"\tnone\x06;\x00FI[\b;\b:\x06b:\x06c\x06:\t@twoi\a\x06:\t@zooI\"\bant\x06;\x00F",
+ proc,
+ freeze: true,
+ )
+
+ arr.should == [
+ false, 5, "hi", 10, "hi", "hi", 0.0, false, "none", st,
+ :b, :c, 2, a, false, "ant", ["hi", 10, "hi", "hi", st, [:a, :b, :c]],
+ ]
+
+ arr.each do |v|
+ v.should.frozen?
+ end
+
+ Struct.send(:remove_const, :Brittle)
+ end
+
+ it "does not freeze the object returned by the proc" do
+ string = Marshal.load(Marshal.dump("foo"), proc { |o| o.upcase }, freeze: true)
+ string.should == "FOO"
+ string.should_not.frozen?
+ end
+ end
+ end
+
+ describe "when called with a proc" do
+ it "call the proc with fully initialized strings" do
+ utf8_string = "foo".encode(Encoding::UTF_8)
+ Marshal.load(Marshal.dump(utf8_string), proc { |arg|
+ if arg.is_a?(String)
+ arg.should == utf8_string
+ arg.encoding.should == Encoding::UTF_8
+ end
+ arg
+ })
+ end
+
+ it "no longer mutate the object after it was passed to the proc" do
+ string = Marshal.load(Marshal.dump("foo"), :freeze.to_proc)
+ string.should.frozen?
+ end
+
+ it "call the proc with extended objects" do
+ objs = []
+ obj = Marshal.load("\x04\be:\x0FEnumerableo:\vObject\x00", Proc.new { |o| objs << o; o })
+ objs.should == [obj]
+ end
+
+ it "returns the value of the proc" do
+ Marshal.load(Marshal.dump([1,2]), proc { [3,4] }).should == [3,4]
+ end
+
+ it "calls the proc for recursively visited data" do
+ a = [1]
+ a << a
+ ret = []
+ Marshal.load(Marshal.dump(a), proc { |arg| ret << arg.inspect; arg })
+ ret[0].should == 1.inspect
+ ret[1].should == a.inspect
+ ret.size.should == 2
+ end
+
+ it "loads an Array with proc" do
+ arr = []
+ s = +'hi'
+ s.instance_variable_set(:@foo, 5)
+ st = Struct.new("Brittle", :a).new
+ st.instance_variable_set(:@clue, 'none')
+ st.a = 0.0
+ h = Hash.new('def')
+ h['nine'] = 9
+ a = [:a, :b, :c]
+ a.instance_variable_set(:@two, 2)
+ obj = [s, 10, s, s, st, a]
+ obj.instance_variable_set(:@zoo, 'ant')
+ proc = Proc.new { |o| arr << o.dup; o}
+
+ Marshal.load("\x04\bI[\vI\"\ahi\a:\x06EF:\t@fooi\ni\x0F@\x06@\x06IS:\x14Struct::Brittle\x06:\x06af\x060\x06:\n@clueI\"\tnone\x06;\x00FI[\b;\b:\x06b:\x06c\x06:\t@twoi\a\x06:\t@zooI\"\bant\x06;\x00F", proc)
+
+ arr.should == [
+ false, 5, "hi", 10, "hi", "hi", 0.0, false, "none", st,
+ :b, :c, 2, a, false, "ant", ["hi", 10, "hi", "hi", st, [:a, :b, :c]],
+ ]
+ Struct.send(:remove_const, :Brittle)
+ end
+ end
+
+ describe "when called with nil for the proc argument" do
+ it "behaves as if no proc argument was passed" do
+ a = [1]
+ a << a
+ b = Marshal.load(Marshal.dump(a), nil)
+ b.should == a
+ end
+ end
+
+ describe "when called on objects with custom _dump methods" do
+ it "does not set instance variables of an object with user-defined _dump/_load" do
+ # this string represents: <#UserPreviouslyDefinedWithInitializedIvar @field2=7 @field1=6>
+ dump_str = "\004\bu:-UserPreviouslyDefinedWithInitializedIvar\a:\f@field2i\f:\f@field1i\v"
+
+ UserPreviouslyDefinedWithInitializedIvar.should_receive(:_load).and_return(UserPreviouslyDefinedWithInitializedIvar.new)
+ marshaled_obj = Marshal.load(dump_str)
+
+ marshaled_obj.should.instance_of?(UserPreviouslyDefinedWithInitializedIvar)
+ marshaled_obj.field1.should == nil
+ marshaled_obj.field2.should == nil
+ end
+
+ it "loads the String in non US-ASCII and non UTF-8 encoding" do
+ source_object = UserDefinedString.new("a".encode("windows-1251"))
+ object = Marshal.load(Marshal.dump(source_object))
+ object.string.should == "a".encode("windows-1251")
+ end
+
+ it "loads the String in multibyte encoding" do
+ source_object = UserDefinedString.new("a".encode("utf-32le"))
+ object = Marshal.load(Marshal.dump(source_object))
+ object.string.should == "a".encode("utf-32le")
+ end
+
+ describe "that returns an immediate value" do
+ it "loads an array containing an instance of the object, followed by multiple instances of another object" do
+ str = "string"
+
+ # this string represents: [<#UserDefinedImmediate A>, <#String "string">, <#String "string">]
+ marshaled_obj = Marshal.load("\004\b[\bu:\031UserDefinedImmediate\000\"\vstring@\a")
+
+ marshaled_obj.should == [nil, str, str]
+ end
+
+ it "loads any structure with multiple references to the same object, followed by multiple instances of another object" do
+ str = "string"
+
+ # this string represents: {a: <#UserDefinedImmediate A>, b: <#UserDefinedImmediate A>, c: <#String "string">, d: <#String "string">}
+ hash_dump = "\x04\b{\t:\x06aIu:\x19UserDefinedImmediate\x00\x06:\x06ET:\x06b@\x06:\x06cI\"\vstring\x06;\aT:\x06d@\a"
+
+ marshaled_obj = Marshal.load(hash_dump)
+ marshaled_obj.should == {a: nil, b: nil, c: str, d: str}
+
+ # this string represents: [<#UserDefinedImmediate A>, <#UserDefinedImmediate A>, <#String "string">, <#String "string">]
+ array_dump = "\x04\b[\tIu:\x19UserDefinedImmediate\x00\x06:\x06ET@\x06I\"\vstring\x06;\x06T@\a"
+
+ marshaled_obj = Marshal.load(array_dump)
+ marshaled_obj.should == [nil, nil, str, str]
+ end
+
+ it "loads an array containing references to multiple instances of the object, followed by multiple instances of another object" do
+ str = "string"
+
+ # this string represents: [<#UserDefinedImmediate A>, <#UserDefinedImmediate B>, <#String "string">, <#String "string">]
+ array_dump = "\x04\b[\tIu:\x19UserDefinedImmediate\x00\x06:\x06ETIu;\x00\x00\x06;\x06TI\"\vstring\x06;\x06T@\b"
+
+ marshaled_obj = Marshal.load(array_dump)
+ marshaled_obj.should == [nil, nil, str, str]
+ end
+ end
+ end
+
+ it "loads an array containing objects having _dump method, and with proc" do
+ arr = []
+ myproc = Proc.new { |o| arr << o.dup; o }
+ o1 = UserDefined.new;
+ o2 = UserDefinedWithIvar.new
+ obj = [o1, o2, o1, o2]
+
+ Marshal.load("\x04\b[\tu:\x10UserDefined\x18\x04\b[\aI\"\nstuff\x06:\x06EF@\x06u:\x18UserDefinedWithIvar>\x04\b[\bI\"\nstuff\a:\x06EF:\t@foo:\x18UserDefinedWithIvarI\"\tmore\x06;\x00F@\a@\x06@\a", myproc)
+
+ arr[0].should == o1
+ arr[1].should == o2
+ arr[2].should == obj
+ arr.size.should == 3
+ end
+
+ it "loads an array containing objects having marshal_dump method, and with proc" do
+ arr = []
+ proc = Proc.new { |o| arr << o.dup; o }
+ o1 = UserMarshal.new
+ o2 = UserMarshalWithIvar.new
+
+ Marshal.load("\004\b[\tU:\020UserMarshal\"\nstuffU:\030UserMarshalWithIvar[\006\"\fmy data@\006@\b", proc)
+
+ arr[0].should == 'stuff'
+ arr[1].should == o1
+ arr[2].should == 'my data'
+ arr[3].should == ['my data']
+ arr[4].should == o2
+ arr[5].should == [o1, o2, o1, o2]
+
+ arr.size.should == 6
+ end
+
+ it "assigns classes to nested subclasses of Array correctly" do
+ arr = ArraySub.new(ArraySub.new)
+ arr_dump = Marshal.dump(arr)
+ Marshal.load(arr_dump).class.should == ArraySub
+ end
+
+ it "loads subclasses of Array with overridden << and push correctly" do
+ arr = ArraySubPush.new
+ arr[0] = '1'
+ arr_dump = Marshal.dump(arr)
+ Marshal.load(arr_dump).should == arr
+ end
+
+ it "raises a TypeError with bad Marshal version" do
+ marshal_data = +'\xff\xff'
+ marshal_data[0] = (Marshal::MAJOR_VERSION).chr
+ marshal_data[1] = (Marshal::MINOR_VERSION + 1).chr
+
+ -> { Marshal.load(marshal_data) }.should.raise(TypeError)
+
+ marshal_data = +'\xff\xff'
+ marshal_data[0] = (Marshal::MAJOR_VERSION - 1).chr
+ marshal_data[1] = (Marshal::MINOR_VERSION).chr
+
+ -> { Marshal.load(marshal_data) }.should.raise(TypeError)
+ end
+
+ it "raises EOFError on loading an empty file" do
+ temp_file = tmp("marshal.rubyspec.tmp.#{Process.pid}")
+ file = File.new(temp_file, "w+")
+ begin
+ -> { Marshal.load(file) }.should.raise(EOFError)
+ ensure
+ file.close
+ rm_r temp_file
+ end
+ end
+
+ # Note: Ruby 1.9 should be compatible with older marshal format
+ MarshalSpec::DATA.each do |description, (object, marshal, attributes)|
+ it "loads a #{description}" do
+ Marshal.load(marshal).should == object
+ end
+ end
+
+ MarshalSpec::DATA_19.each do |description, (object, marshal, attributes)|
+ it "loads a #{description}" do
+ Marshal.load(marshal).should == object
+ end
+ end
+
+ describe "for an Array" do
+ it "loads an array containing the same objects" do
+ s = 'oh'
+ b = 'hi'
+ r = //
+ d = [b, :no, s, :go]
+ c = String
+ f = 1.0
+
+ o1 = UserMarshalWithIvar.new; o2 = UserMarshal.new
+
+ obj = [:so, 'hello', 100, :so, :so, d, :so, o2, :so, :no, o2,
+ :go, c, nil, Struct::Pyramid.new, f, :go, :no, s, b, r,
+ :so, 'huh', o1, true, b, b, 99, r, b, s, :so, f, c, :no, o1, d]
+
+ Marshal.load("\004\b[*:\aso\"\nhelloii;\000;\000[\t\"\ahi:\ano\"\aoh:\ago;\000U:\020UserMarshal\"\nstuff;\000;\006@\n;\ac\vString0S:\024Struct::Pyramid\000f\0061;\a;\006@\t@\b/\000\000;\000\"\bhuhU:\030UserMarshalWithIvar[\006\"\fmy dataT@\b@\bih@\017@\b@\t;\000@\016@\f;\006@\021@\a").should ==
+ obj
+ end
+
+ it "loads an array having ivar" do
+ s = +'well'
+ s.instance_variable_set(:@foo, 10)
+ obj = ['5', s, 'hi'].extend(Meths, MethsMore)
+ obj.instance_variable_set(:@mix, s)
+ new_obj = Marshal.load("\004\bI[\b\"\0065I\"\twell\006:\t@fooi\017\"\ahi\006:\t@mix@\a")
+ new_obj.should == obj
+ new_obj.instance_variable_get(:@mix).should.equal? new_obj[1]
+ new_obj[1].instance_variable_get(:@foo).should == 10
+ end
+
+ it "loads an extended Array object containing a user-marshaled object" do
+ obj = [UserMarshal.new, UserMarshal.new].extend(Meths)
+ dump = "\x04\be:\nMeths[\ao:\x10UserMarshal\x06:\n@dataI\"\nstuff\x06:\x06ETo;\x06\x06;\aI\"\nstuff\x06;\bT"
+ new_obj = Marshal.load(dump)
+
+ new_obj.should == obj
+ obj_ancestors = class << obj; ancestors[1..-1]; end
+ new_obj_ancestors = class << new_obj; ancestors[1..-1]; end
+ obj_ancestors.should == new_obj_ancestors
+ end
+ end
+
+ describe "for a Hash" do
+ it "loads an extended_user_hash with a parameter to initialize" do
+ obj = UserHashInitParams.new(:abc).extend(Meths)
+
+ new_obj = Marshal.load("\004\bIe:\nMethsC:\027UserHashInitParams{\000\006:\a@a:\babc")
+
+ new_obj.should == obj
+ new_obj_metaclass_ancestors = class << new_obj; ancestors; end
+ new_obj_metaclass_ancestors[@num_self_class].should == Meths
+ new_obj_metaclass_ancestors[@num_self_class+1].should == UserHashInitParams
+ end
+
+ it "loads an extended hash object containing a user-marshaled object" do
+ obj = {a: UserMarshal.new}.extend(Meths)
+
+ new_obj = Marshal.load("\004\be:\nMeths{\006:\006aU:\020UserMarshal\"\nstuff")
+
+ new_obj.should == obj
+ new_obj_metaclass_ancestors = class << new_obj; ancestors; end
+ new_obj_metaclass_ancestors[@num_self_class].should == Meths
+ new_obj_metaclass_ancestors[@num_self_class+1].should == Hash
+ end
+
+ it "preserves hash ivars when hash contains a string having ivar" do
+ s = +'string'
+ s.instance_variable_set :@string_ivar, 'string ivar'
+ h = { key: s }
+ h.instance_variable_set :@hash_ivar, 'hash ivar'
+
+ unmarshalled = Marshal.load(Marshal.dump(h))
+ unmarshalled.instance_variable_get(:@hash_ivar).should == 'hash ivar'
+ unmarshalled[:key].instance_variable_get(:@string_ivar).should == 'string ivar'
+ end
+
+ it "preserves compare_by_identity behaviour" do
+ h = { a: 1 }
+ h.compare_by_identity
+ unmarshalled = Marshal.load(Marshal.dump(h))
+ unmarshalled.should.compare_by_identity?
+
+ h = { a: 1 }
+ unmarshalled = Marshal.load(Marshal.dump(h))
+ unmarshalled.should_not.compare_by_identity?
+ end
+
+ it "preserves compare_by_identity behaviour for a Hash subclass" do
+ h = UserHash.new({ a: 1 })
+ h.compare_by_identity
+ unmarshalled = Marshal.load(Marshal.dump(h))
+ unmarshalled.should.compare_by_identity?
+
+ h = UserHash.new({ a: 1 })
+ unmarshalled = Marshal.load(Marshal.dump(h))
+ unmarshalled.should_not.compare_by_identity?
+ end
+
+ it "allocates an instance of the proper class when Hash subclass with compare_by_identity behaviour" do
+ h = UserHash.new({ a: 1 })
+ h.compare_by_identity
+
+ unmarshalled = Marshal.load(Marshal.dump(h))
+ unmarshalled.should.kind_of?(UserHash)
+ end
+ end
+
+ describe "for a Symbol" do
+ it "loads a Symbol" do
+ sym = Marshal.load("\004\b:\vsymbol")
+ sym.should == :symbol
+ sym.encoding.should == Encoding::US_ASCII
+ end
+
+ it "loads a big Symbol" do
+ sym = ('big' * 100).to_sym
+ Marshal.load("\004\b:\002,\001#{'big' * 100}").should == sym
+ end
+
+ it "loads an encoded Symbol" do
+ s = "\u2192"
+
+ sym = Marshal.load("\x04\bI:\b\xE2\x86\x92\x06:\x06ET")
+ sym.should == s.encode("utf-8").to_sym
+ sym.encoding.should == Encoding::UTF_8
+
+ sym = Marshal.load("\x04\bI:\t\xFE\xFF!\x92\x06:\rencoding\"\vUTF-16")
+ sym.should == s.encode("utf-16").to_sym
+ sym.encoding.should == Encoding::UTF_16
+
+ sym = Marshal.load("\x04\bI:\a\x92!\x06:\rencoding\"\rUTF-16LE")
+ sym.should == s.encode("utf-16le").to_sym
+ sym.encoding.should == Encoding::UTF_16LE
+
+ sym = Marshal.load("\x04\bI:\a!\x92\x06:\rencoding\"\rUTF-16BE")
+ sym.should == s.encode("utf-16be").to_sym
+ sym.encoding.should == Encoding::UTF_16BE
+
+ sym = Marshal.load("\x04\bI:\a\xA2\xAA\x06:\rencoding\"\vEUC-JP")
+ sym.should == s.encode("euc-jp").to_sym
+ sym.encoding.should == Encoding::EUC_JP
+
+ sym = Marshal.load("\x04\bI:\a\x81\xA8\x06:\rencoding\"\x10Windows-31J")
+ sym.should == s.encode("sjis").to_sym
+ sym.encoding.should == Encoding::SJIS
+ end
+
+ it "loads a binary encoded Symbol" do
+ s = "\u2192".dup.force_encoding("binary").to_sym
+ sym = Marshal.load("\x04\b:\b\xE2\x86\x92")
+ sym.should == s
+ sym.encoding.should == Encoding::BINARY
+ end
+
+ it "loads multiple Symbols sharing the same encoding" do
+ # Note that the encoding is a link for the second Symbol
+ symbol1 = "I:\t\xE2\x82\xACa\x06:\x06ET"
+ symbol2 = "I:\t\xE2\x82\xACb\x06;\x06T"
+ dump = "\x04\b[\a#{symbol1}#{symbol2}"
+ value = Marshal.load(dump)
+ value.map(&:encoding).should == [Encoding::UTF_8, Encoding::UTF_8]
+ expected = [
+ "€a".dup.force_encoding(Encoding::UTF_8).to_sym,
+ "€b".dup.force_encoding(Encoding::UTF_8).to_sym
+ ]
+ value.should == expected
+
+ value = Marshal.load("\x04\b[\b#{symbol1}#{symbol2};\x00")
+ value.map(&:encoding).should == [Encoding::UTF_8, Encoding::UTF_8, Encoding::UTF_8]
+ value.should == [*expected, expected[0]]
+ end
+
+ it "raises ArgumentError when end of byte sequence reached before symbol characters end" do
+ Marshal.dump(:hello).should == "\x04\b:\nhello"
+
+ -> {
+ Marshal.load("\x04\b:\nhel")
+ }.should.raise(ArgumentError, "marshal data too short")
+ end
+ end
+
+ describe "for a String" do
+ it "loads a string having ivar with ref to self" do
+ obj = +'hi'
+ obj.instance_variable_set(:@self, obj)
+ Marshal.load("\004\bI\"\ahi\006:\n@self@\000").should == obj
+ end
+
+ it "loads a string through StringIO stream" do
+ require 'stringio'
+ obj = "This is a string which should be unmarshalled through StringIO stream!"
+ Marshal.load(StringIO.new(Marshal.dump(obj))).should == obj
+ end
+
+ it "sets binmode if it is loading through StringIO stream" do
+ io = StringIO.new("\004\b:\vsymbol")
+ def io.binmode; raise "binmode"; end
+ -> { Marshal.load(io) }.should.raise(RuntimeError, "binmode")
+ end
+
+ it "loads a string with an ivar" do
+ str = Marshal.load("\x04\bI\"\x00\x06:\t@fooI\"\bbar\x06:\x06EF")
+ str.instance_variable_get("@foo").should == "bar"
+ end
+
+ it "loads a String subclass with custom constructor" do
+ str = Marshal.load("\x04\bC: UserCustomConstructorString\"\x00")
+ str.should.instance_of?(UserCustomConstructorString)
+ end
+
+ it "loads a US-ASCII String" do
+ str = "abc".dup.force_encoding("us-ascii")
+ data = "\x04\bI\"\babc\x06:\x06EF"
+ result = Marshal.load(data)
+ result.should == str
+ result.encoding.should.equal?(Encoding::US_ASCII)
+ end
+
+ it "loads a UTF-8 String" do
+ str = "\x6d\xc3\xb6\x68\x72\x65".dup.force_encoding("utf-8")
+ data = "\x04\bI\"\vm\xC3\xB6hre\x06:\x06ET"
+ result = Marshal.load(data)
+ result.should == str
+ result.encoding.should.equal?(Encoding::UTF_8)
+ end
+
+ it "loads a String in another encoding" do
+ str = "\x6d\x00\xf6\x00\x68\x00\x72\x00\x65\x00".dup.force_encoding("utf-16le")
+ data = "\x04\bI\"\x0Fm\x00\xF6\x00h\x00r\x00e\x00\x06:\rencoding\"\rUTF-16LE"
+ result = Marshal.load(data)
+ result.should == str
+ result.encoding.should.equal?(Encoding::UTF_16LE)
+ end
+
+ it "loads a String as BINARY if no encoding is specified at the end" do
+ str = "\xC3\xB8".dup.force_encoding("BINARY")
+ data = "\x04\b\"\a\xC3\xB8".dup.force_encoding("UTF-8")
+ result = Marshal.load(data)
+ result.encoding.should == Encoding::BINARY
+ result.should == str
+ end
+
+ it "raises ArgumentError when end of byte sequence reached before string characters end" do
+ Marshal.dump("hello").should == "\x04\b\"\nhello"
+
+ -> {
+ Marshal.load("\x04\b\"\nhel")
+ }.should.raise(ArgumentError, "marshal data too short")
+ end
+ end
+
+ describe "for a Struct" do
+ it "loads a extended_struct having fields with same objects" do
+ s = 'hi'
+ obj = Struct.new("Extended", :a, :b).new.extend(Meths)
+ dump = "\004\be:\nMethsS:\025Struct::Extended\a:\006a0:\006b0"
+ Marshal.load(dump).should == obj
+
+ obj.a = [:a, s]
+ obj.b = [:Meths, s]
+ dump = "\004\be:\nMethsS:\025Struct::Extended\a:\006a[\a;\a\"\ahi:\006b[\a;\000@\a"
+ Marshal.load(dump).should == obj
+ Struct.send(:remove_const, :Extended)
+ end
+
+ it "loads a struct having ivar" do
+ obj = Struct.new("Thick").new
+ obj.instance_variable_set(:@foo, 5)
+ reloaded = Marshal.load("\004\bIS:\022Struct::Thick\000\006:\t@fooi\n")
+ reloaded.should == obj
+ reloaded.instance_variable_get(:@foo).should == 5
+ Struct.send(:remove_const, :Thick)
+ end
+
+ it "loads a struct having fields" do
+ obj = Struct.new("Ure1", :a, :b).new
+ Marshal.load("\004\bS:\021Struct::Ure1\a:\006a0:\006b0").should == obj
+ Struct.send(:remove_const, :Ure1)
+ end
+
+ it "does not call initialize on the unmarshaled struct" do
+ threadlocal_key = MarshalSpec::StructWithUserInitialize::THREADLOCAL_KEY
+
+ s = MarshalSpec::StructWithUserInitialize.new('foo')
+ Thread.current[threadlocal_key].should == ['foo']
+ s.a.should == 'foo'
+
+ Thread.current[threadlocal_key] = nil
+
+ dumped = Marshal.dump(s)
+ loaded = Marshal.load(dumped)
+
+ Thread.current[threadlocal_key].should == nil
+ loaded.a.should == 'foo'
+ end
+ end
+
+ describe "for a Data" do
+ it "loads a Data" do
+ obj = MarshalSpec::DataSpec::Measure.new(100, 'km')
+ dumped = "\x04\bS:#MarshalSpec::DataSpec::Measure\a:\vamountii:\tunit\"\akm"
+ Marshal.dump(obj).should == dumped
+
+ Marshal.load(dumped).should == obj
+ end
+
+ it "loads an extended Data" do
+ obj = MarshalSpec::DataSpec::MeasureExtended.new(100, "km")
+ dumped = "\x04\bS:+MarshalSpec::DataSpec::MeasureExtended\a:\vamountii:\tunit\"\akm"
+ Marshal.dump(obj).should == dumped
+
+ Marshal.load(dumped).should == obj
+ end
+
+ it "returns a frozen object" do
+ obj = MarshalSpec::DataSpec::Measure.new(100, 'km')
+ dumped = "\x04\bS:#MarshalSpec::DataSpec::Measure\a:\vamountii:\tunit\"\akm"
+ Marshal.dump(obj).should == dumped
+
+ Marshal.load(dumped).should.frozen?
+ end
+ end
+
+ describe "for an Exception" do
+ it "loads a marshalled exception with no message" do
+ obj = Exception.new
+ loaded = Marshal.load("\004\bo:\016Exception\a:\abt0:\tmesg0")
+ loaded.message.should == obj.message
+ loaded.backtrace.should == obj.backtrace
+ loaded = Marshal.load("\x04\bo:\x0EException\a:\tmesg0:\abt0")
+ loaded.message.should == obj.message
+ loaded.backtrace.should == obj.backtrace
+ end
+
+ it "loads a marshalled exception with a message" do
+ obj = Exception.new("foo")
+ loaded = Marshal.load("\004\bo:\016Exception\a:\abt0:\tmesg\"\bfoo")
+ loaded.message.should == obj.message
+ loaded.backtrace.should == obj.backtrace
+ loaded = Marshal.load("\x04\bo:\x0EException\a:\tmesgI\"\bfoo\x06:\x06EF:\abt0")
+ loaded.message.should == obj.message
+ loaded.backtrace.should == obj.backtrace
+ end
+
+ it "loads a marshalled exception with a backtrace" do
+ obj = Exception.new("foo")
+ obj.set_backtrace(["foo/bar.rb:10"])
+ loaded = Marshal.load("\004\bo:\016Exception\a:\abt[\006\"\022foo/bar.rb:10:\tmesg\"\bfoo")
+ loaded.message.should == obj.message
+ loaded.backtrace.should == obj.backtrace
+ loaded = Marshal.load("\x04\bo:\x0EException\a:\tmesgI\"\bfoo\x06:\x06EF:\abt[\x06I\"\x12foo/bar.rb:10\x06;\aF")
+ loaded.message.should == obj.message
+ loaded.backtrace.should == obj.backtrace
+ end
+
+ it "loads an marshalled exception with ivars" do
+ s = 'hi'
+ arr = [:so, :so, s, s]
+ obj = Exception.new("foo")
+ obj.instance_variable_set :@arr, arr
+
+ loaded = Marshal.load("\x04\bo:\x0EException\b:\tmesg\"\bfoo:\abt0:\t@arr[\t:\aso;\t\"\ahi@\b")
+ new_arr = loaded.instance_variable_get :@arr
+
+ loaded.message.should == obj.message
+ new_arr.should == arr
+ end
+ end
+
+ describe "for an Object" do
+ it "loads an object" do
+ Marshal.load("\004\bo:\vObject\000").should.is_a?(Object)
+ end
+
+ it "loads an extended Object" do
+ obj = Object.new.extend(Meths)
+
+ new_obj = Marshal.load("\004\be:\nMethso:\vObject\000")
+
+ new_obj.class.should == obj.class
+ new_obj_metaclass_ancestors = class << new_obj; ancestors; end
+ new_obj_metaclass_ancestors[@num_self_class, 2].should == [Meths, Object]
+ end
+
+ it "loads an object having ivar" do
+ s = 'hi'
+ arr = [:so, :so, s, s]
+ obj = Object.new
+ obj.instance_variable_set :@str, arr
+
+ new_obj = Marshal.load("\004\bo:\vObject\006:\t@str[\t:\aso;\a\"\ahi@\a")
+ new_str = new_obj.instance_variable_get :@str
+
+ new_str.should == arr
+ end
+
+ it "loads an Object with a non-US-ASCII instance variable" do
+ ivar = "@é".dup.force_encoding(Encoding::UTF_8).to_sym
+ obj = Marshal.load("\x04\bo:\vObject\x06I:\b@\xC3\xA9\x06:\x06ETi\x06")
+ obj.instance_variables.should == [ivar]
+ obj.instance_variables[0].encoding.should == Encoding::UTF_8
+ obj.instance_variable_get(ivar).should == 1
+ end
+
+ it "raises ArgumentError if the object from an 'o' stream is not dumpable as 'o' type user class" do
+ -> do
+ Marshal.load("\x04\bo:\tFile\001\001:\001\005@path\"\x10/etc/passwd")
+ end.should.raise(ArgumentError)
+ end
+
+ it "raises ArgumentError when end of byte sequence reached before class name end" do
+ Marshal.dump(Object.new).should == "\x04\bo:\vObject\x00"
+
+ -> {
+ Marshal.load("\x04\bo:\vObj")
+ }.should.raise(ArgumentError, "marshal data too short")
+ end
+ end
+
+ describe "for an object responding to #marshal_dump and #marshal_load" do
+ it "loads a user-marshaled object" do
+ obj = UserMarshal.new
+ obj.data = :data
+ value = [obj, :data]
+ dump = Marshal.dump(value)
+ dump.should == "\x04\b[\aU:\x10UserMarshal:\tdata;\x06"
+ reloaded = Marshal.load(dump)
+ reloaded.should == value
+ end
+ end
+
+ describe "for a user object" do
+ it "loads a user-marshaled extended object" do
+ obj = UserMarshal.new.extend(Meths)
+
+ new_obj = Marshal.load("\004\bU:\020UserMarshal\"\nstuff")
+
+ new_obj.should == obj
+ new_obj_metaclass_ancestors = class << new_obj; ancestors; end
+ new_obj_metaclass_ancestors[@num_self_class].should == UserMarshal
+ end
+
+ it "loads a UserObject" do
+ Marshal.load("\004\bo:\017UserObject\000").should.is_a?(UserObject)
+ end
+
+ describe "that extends a core type other than Object or BasicObject" do
+ after :each do
+ MarshalSpec.reset_swapped_class
+ end
+
+ it "raises ArgumentError if the resulting class does not extend the same type" do
+ MarshalSpec.set_swapped_class(Class.new(Hash))
+ data = Marshal.dump(MarshalSpec::SwappedClass.new)
+
+ MarshalSpec.set_swapped_class(Class.new(Array))
+ -> { Marshal.load(data) }.should.raise(ArgumentError)
+
+ MarshalSpec.set_swapped_class(Class.new)
+ -> { Marshal.load(data) }.should.raise(ArgumentError)
+ end
+ end
+ end
+
+ describe "for a Regexp" do
+ ruby_version_is "4.1" do
+ it "raises FrozenError for an extended Regexp" do
+ -> {
+ Marshal.load("\004\be:\nMethse:\016MethsMore/\n[a-z]\000")
+ }.should.raise(FrozenError)
+ end
+
+ it "raises FrozenError when regexp has instance variables" do
+ -> {
+ Marshal.load("\x04\bI/\nhello\x00\a:\x06EF:\x11@regexp_ivar[\x06i/")
+ }.should.raise(FrozenError)
+ end
+ end
+
+ ruby_version_is ""..."4.1" do
+ it "loads an extended Regexp" do
+ obj = /[a-z]/.dup.extend(Meths, MethsMore)
+ new_obj = Marshal.load("\004\be:\nMethse:\016MethsMore/\n[a-z]\000")
+
+ new_obj.should == obj
+ new_obj_metaclass_ancestors = class << new_obj; ancestors; end
+ new_obj_metaclass_ancestors[@num_self_class, 3].should ==
+ [Meths, MethsMore, Regexp]
+ end
+
+ it "restore the regexp instance variables" do
+ obj = Regexp.new("hello")
+ obj.instance_variable_set(:@regexp_ivar, [42])
+
+ new_obj = Marshal.load("\x04\bI/\nhello\x00\a:\x06EF:\x11@regexp_ivar[\x06i/")
+ new_obj.instance_variables.should == [:@regexp_ivar]
+ new_obj.instance_variable_get(:@regexp_ivar).should == [42]
+ end
+ end
+
+ it "loads a Regexp subclass instance variables" do
+ obj = UserRegexp.new('abc')
+ obj.instance_variable_set(:@noise, 'much')
+
+ new_obj = Marshal.load(Marshal.dump(obj))
+
+ new_obj.should == obj
+ new_obj.instance_variable_get(:@noise).should == 'much'
+ new_obj_metaclass_ancestors = class << new_obj; ancestors; end
+ new_obj_metaclass_ancestors[@num_self_class, 2].should ==
+ [UserRegexp, Regexp]
+ end
+
+ it "loads a Regexp subclass instance variables when it is extended with a module" do
+ obj = UserRegexp.new('').extend(Meths)
+ obj.instance_variable_set(:@noise, 'much')
+
+ new_obj = Marshal.load("\004\bIe:\nMethsC:\017UserRegexp/\000\000\006:\v@noise\"\tmuch")
+
+ new_obj.should == obj
+ new_obj.instance_variable_get(:@noise).should == 'much'
+ new_obj_metaclass_ancestors = class << new_obj; ancestors; end
+ new_obj_metaclass_ancestors[@num_self_class, 3].should ==
+ [Meths, UserRegexp, Regexp]
+ end
+
+ it "preserves Regexp encoding" do
+ source_object = Regexp.new("a".encode("utf-32le"))
+ regexp = Marshal.load(Marshal.dump(source_object))
+
+ regexp.encoding.should == Encoding::UTF_32LE
+ regexp.source.should == "a".encode("utf-32le")
+ end
+
+ it "raises ArgumentError when end of byte sequence reached before source string end" do
+ Marshal.dump(/hello world/).should == "\x04\bI/\x10hello world\x00\x06:\x06EF"
+
+ -> {
+ Marshal.load("\x04\bI/\x10hel")
+ }.should.raise(ArgumentError, "marshal data too short")
+ end
+ end
+
+ describe "for a Float" do
+ it "loads a Float NaN" do
+ obj = 0.0 / 0.0
+ Marshal.load("\004\bf\bnan").to_s.should == obj.to_s
+ end
+
+ it "loads a Float 1.3" do
+ Marshal.load("\004\bf\v1.3\000\314\315").should == 1.3
+ end
+
+ it "loads a Float -5.1867345e-22" do
+ obj = -5.1867345e-22
+ Marshal.load("\004\bf\037-5.1867345000000008e-22\000\203_").should be_close(obj, 1e-30)
+ end
+
+ it "loads a Float 1.1867345e+22" do
+ obj = 1.1867345e+22
+ Marshal.load("\004\bf\0361.1867344999999999e+22\000\344@").should == obj
+ end
+
+ it "raises ArgumentError when end of byte sequence reached before float string representation end" do
+ Marshal.dump(1.3).should == "\x04\bf\b1.3"
+
+ -> {
+ Marshal.load("\004\bf\v1")
+ }.should.raise(ArgumentError, "marshal data too short")
+ end
+ end
+
+ describe "for an Integer" do
+ it "loads 0" do
+ Marshal.load("\004\bi\000").should == 0
+ Marshal.load("\004\bi\005").should == 0
+ end
+
+ it "loads an Integer 8" do
+ Marshal.load("\004\bi\r" ).should == 8
+ end
+
+ it "loads and Integer -8" do
+ Marshal.load("\004\bi\363" ).should == -8
+ end
+
+ it "loads an Integer 1234" do
+ Marshal.load("\004\bi\002\322\004").should == 1234
+ end
+
+ it "loads an Integer -1234" do
+ Marshal.load("\004\bi\376.\373").should == -1234
+ end
+
+ it "loads an Integer 4611686018427387903" do
+ Marshal.load("\004\bl+\t\377\377\377\377\377\377\377?").should == 4611686018427387903
+ end
+
+ it "loads an Integer -4611686018427387903" do
+ Marshal.load("\004\bl-\t\377\377\377\377\377\377\377?").should == -4611686018427387903
+ end
+
+ it "loads an Integer 2361183241434822606847" do
+ Marshal.load("\004\bl+\n\377\377\377\377\377\377\377\377\177\000").should == 2361183241434822606847
+ end
+
+ it "loads an Integer -2361183241434822606847" do
+ Marshal.load("\004\bl-\n\377\377\377\377\377\377\377\377\177\000").should == -2361183241434822606847
+ end
+
+ it "raises ArgumentError if the input is too short" do
+ ["\004\bi",
+ "\004\bi\001",
+ "\004\bi\002",
+ "\004\bi\002\0",
+ "\004\bi\003",
+ "\004\bi\003\0",
+ "\004\bi\003\0\0",
+ "\004\bi\004",
+ "\004\bi\004\0",
+ "\004\bi\004\0\0",
+ "\004\bi\004\0\0\0"].each do |invalid|
+ -> { Marshal.load(invalid) }.should.raise(ArgumentError)
+ end
+ end
+
+ if 0.size == 8 # for platforms like x86_64
+ it "roundtrips 4611686018427387903 from dump/load correctly" do
+ Marshal.load(Marshal.dump(4611686018427387903)).should == 4611686018427387903
+ end
+ end
+ end
+
+ describe "for a Rational" do
+ it "loads" do
+ r = Marshal.load(Marshal.dump(Rational(1, 3)))
+ r.should == Rational(1, 3)
+ r.should.frozen?
+ end
+ end
+
+ describe "for a Complex" do
+ it "loads" do
+ c = Marshal.load(Marshal.dump(Complex(4, 3)))
+ c.should == Complex(4, 3)
+ c.should.frozen?
+ end
+ end
+
+ describe "for a Bignum" do
+ platform_is c_long_size: 64 do
+ context "that is Bignum on 32-bit platforms but Fixnum on 64-bit" do
+ it "dumps a Fixnum" do
+ val = Marshal.load("\004\bl+\ab:wU")
+ val.should == 1433877090
+ val.class.should == Integer
+ end
+
+ it "dumps an array containing multiple references to the Bignum as an array of Fixnum" do
+ arr = Marshal.load("\004\b[\al+\a\223BwU@\006")
+ arr.should == [1433879187, 1433879187]
+ arr.each { |v| v.class.should == Integer }
+ end
+ end
+ end
+ end
+
+ describe "for a Time" do
+ it "loads" do
+ Marshal.load(Marshal.dump(Time.at(1))).should == Time.at(1)
+ end
+
+ it "loads serialized instance variables" do
+ t = Time.new
+ t.instance_variable_set(:@foo, 'bar')
+
+ Marshal.load(Marshal.dump(t)).instance_variable_get(:@foo).should == 'bar'
+ end
+
+ it "loads Time objects stored as links" do
+ t = Time.new
+
+ t1, t2 = Marshal.load(Marshal.dump([t, t]))
+ t1.should.equal? t2
+ end
+
+ it "keeps the local zone" do
+ with_timezone 'AST', 3 do
+ t = Time.local(2012, 1, 1)
+ Marshal.load(Marshal.dump(t)).zone.should == t.zone
+ end
+ end
+
+ it "keeps UTC zone" do
+ t = Time.now.utc
+ t2 = Marshal.load(Marshal.dump(t))
+ t2.should.utc?
+ end
+
+ it "keeps the zone" do
+ t = nil
+
+ with_timezone 'AST', 4 do
+ t = Time.local(2012, 1, 1)
+ end
+
+ with_timezone 'EET', -2 do
+ Marshal.load(Marshal.dump(t)).zone.should == 'AST'
+ end
+ end
+
+ it "keeps utc offset" do
+ t = Time.new(2007,11,1,15,25,0, "+09:00")
+ t2 = Marshal.load(Marshal.dump(t))
+ t2.utc_offset.should == 32400
+ end
+
+ it "keeps nanoseconds" do
+ t = Time.now
+ Marshal.load(Marshal.dump(t)).nsec.should == t.nsec
+ end
+
+ it "does not add any additional instance variable" do
+ t = Time.now
+ t2 = Marshal.load(Marshal.dump(t))
+ t2.instance_variables.should.empty?
+ end
+ end
+
+ describe "for nil" do
+ it "loads" do
+ Marshal.load("\x04\b0").should == nil
+ end
+ end
+
+ describe "for true" do
+ it "loads" do
+ Marshal.load("\x04\bT").should == true
+ end
+ end
+
+ describe "for false" do
+ it "loads" do
+ Marshal.load("\x04\bF").should == false
+ end
+ end
+
+ describe "for a Class" do
+ it "loads" do
+ Marshal.load("\x04\bc\vString").should == String
+ end
+
+ it "raises ArgumentError if given the name of a non-Module" do
+ -> { Marshal.load("\x04\bc\vKernel") }.should.raise(ArgumentError)
+ end
+
+ it "raises ArgumentError if given a nonexistent class" do
+ -> { Marshal.load("\x04\bc\vStrung") }.should.raise(ArgumentError)
+ end
+
+ it "raises ArgumentError when end of byte sequence reached before class name end" do
+ Marshal.dump(String).should == "\x04\bc\vString"
+
+ -> {
+ Marshal.load("\x04\bc\vStr")
+ }.should.raise(ArgumentError, "marshal data too short")
+ end
+ end
+
+ describe "for a Module" do
+ it "loads a module" do
+ Marshal.load("\x04\bm\vKernel").should == Kernel
+ end
+
+ it "raises ArgumentError if given the name of a non-Class" do
+ -> { Marshal.load("\x04\bm\vString") }.should.raise(ArgumentError)
+ end
+
+ it "loads an old module" do
+ Marshal.load("\x04\bM\vKernel").should == Kernel
+ end
+
+ it "raises ArgumentError when end of byte sequence reached before module name end" do
+ Marshal.dump(Kernel).should == "\x04\bm\vKernel"
+
+ -> {
+ Marshal.load("\x04\bm\vKer")
+ }.should.raise(ArgumentError, "marshal data too short")
+ end
+ end
+
+ describe "for a wrapped C pointer" do
+ it "loads" do
+ class DumpableDir < Dir
+ def _dump_data
+ path
+ end
+ def _load_data path
+ initialize(path)
+ end
+ end
+
+ data = "\x04\bd:\x10DumpableDirI\"\x06.\x06:\x06ET"
+
+ dir = Marshal.load(data)
+ begin
+ dir.path.should == '.'
+ ensure
+ dir.close
+ end
+ end
+
+ it "raises TypeError when the local class is missing _load_data" do
+ class UnloadableDumpableDir < Dir
+ def _dump_data
+ path
+ end
+ # no _load_data
+ end
+
+ data = "\x04\bd:\x1AUnloadableDumpableDirI\"\x06.\x06:\x06ET"
+
+ -> { Marshal.load(data) }.should.raise(TypeError)
+ end
+
+ it "raises ArgumentError when the local class is a regular object" do
+ data = "\004\bd:\020UserDefined\0"
+
+ -> { Marshal.load(data) }.should.raise(ArgumentError)
+ end
+ end
+
+ describe "when a class does not exist in the namespace" do
+ before :each do
+ NamespaceTest.send(:const_set, :SameName, Class.new)
+ @data = Marshal.dump(NamespaceTest::SameName.new)
+ NamespaceTest.send(:remove_const, :SameName)
+ end
+
+ it "raises an ArgumentError" do
+ message = "undefined class/module NamespaceTest::SameName"
+ -> { Marshal.load(@data) }.should.raise(ArgumentError, message)
+ end
+ end
+
+ it "raises an ArgumentError with full constant name when the dumped constant is missing" do
+ NamespaceTest.send(:const_set, :KaBoom, Class.new)
+ @data = Marshal.dump(NamespaceTest::KaBoom.new)
+ NamespaceTest.send(:remove_const, :KaBoom)
+
+ -> { Marshal.load(@data) }.should.raise(ArgumentError, /NamespaceTest::KaBoom/)
+ end
end
diff --git a/spec/ruby/core/marshal/major_version_spec.rb b/spec/ruby/core/marshal/major_version_spec.rb
index 6984e22b19..931f1f6c27 100644
--- a/spec/ruby/core/marshal/major_version_spec.rb
+++ b/spec/ruby/core/marshal/major_version_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Marshal::MAJOR_VERSION" do
it "is 4" do
diff --git a/spec/ruby/core/marshal/minor_version_spec.rb b/spec/ruby/core/marshal/minor_version_spec.rb
index cfedcb62b2..f19210c4e1 100644
--- a/spec/ruby/core/marshal/minor_version_spec.rb
+++ b/spec/ruby/core/marshal/minor_version_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Marshal::MINOR_VERSION" do
it "is 8" do
diff --git a/spec/ruby/core/marshal/restore_spec.rb b/spec/ruby/core/marshal/restore_spec.rb
index 3e84a1780c..3135f881d4 100644
--- a/spec/ruby/core/marshal/restore_spec.rb
+++ b/spec/ruby/core/marshal/restore_spec.rb
@@ -1,6 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/load', __FILE__)
+require_relative '../../spec_helper'
describe "Marshal.restore" do
- it_behaves_like :marshal_load, :restore
+ it "is an alias of Marshal.load" do
+ Marshal.method(:restore).should == Marshal.method(:load)
+ end
end
diff --git a/spec/ruby/core/marshal/shared/load.rb b/spec/ruby/core/marshal/shared/load.rb
deleted file mode 100644
index e642f1a66e..0000000000
--- a/spec/ruby/core/marshal/shared/load.rb
+++ /dev/null
@@ -1,830 +0,0 @@
-# -*- encoding: binary -*-
-require File.expand_path('../../fixtures/marshal_data', __FILE__)
-require 'stringio'
-
-describe :marshal_load, shared: true do
- before :all do
- @num_self_class = 1
- end
-
- it "raises an ArgumentError when the dumped data is truncated" do
- obj = {first: 1, second: 2, third: 3}
- lambda { Marshal.send(@method, Marshal.dump(obj)[0, 5]) }.should raise_error(ArgumentError)
- end
-
- it "raises an ArgumentError when the dumped class is missing" do
- Object.send(:const_set, :KaBoom, Class.new)
- kaboom = Marshal.dump(KaBoom.new)
- Object.send(:remove_const, :KaBoom)
-
- lambda { Marshal.send(@method, kaboom) }.should raise_error(ArgumentError)
- end
-
- describe "when called with a proc" do
- it "returns the value of the proc" do
- Marshal.send(@method, Marshal.dump([1,2]), proc { [3,4] }).should == [3,4]
- end
-
- it "calls the proc for recursively visited data" do
- a = [1]
- a << a
- ret = []
- Marshal.send(@method, Marshal.dump(a), proc { |arg| ret << arg; arg })
- ret.first.should == 1
- ret[1].should == [1,a]
- ret[2].should == a
- ret.size.should == 3
- end
-
- it "loads an Array with proc" do
- arr = []
- s = 'hi'
- s.instance_variable_set(:@foo, 5)
- st = Struct.new("Brittle", :a).new
- st.instance_variable_set(:@clue, 'none')
- st.a = 0.0
- h = Hash.new('def')
- h['nine'] = 9
- a = [:a, :b, :c]
- a.instance_variable_set(:@two, 2)
- obj = [s, 10, s, s, st, a]
- obj.instance_variable_set(:@zoo, 'ant')
- proc = Proc.new { |o| arr << o; o}
-
- Marshal.send(@method, "\x04\bI[\vI\"\ahi\a:\x06EF:\t@fooi\ni\x0F@\x06@\x06IS:\x14Struct::Brittle\x06:\x06af\x060\x06:\n@clueI\"\tnone\x06;\x00FI[\b;\b:\x06b:\x06c\x06:\t@twoi\a\x06:\t@zooI\"\bant\x06;\x00F", proc)
-
- arr.should == ["hi", false, 5, 10, "hi", "hi", 0.0, st, "none", false,
- :b, :c, a, 2, ["hi", 10, "hi", "hi", st, [:a, :b, :c]], "ant", false]
-
- Struct.send(:remove_const, :Brittle)
- end
- end
-
- describe "when called with nil for the proc argument" do
- it "behaves as if no proc argument was passed" do
- a = [1]
- a << a
- b = Marshal.send(@method, Marshal.dump(a), nil)
- b.should == a
- end
- end
-
- describe "when called on objects with custom _dump methods" do
- it "does not set instance variables of an object with user-defined _dump/_load" do
- # this string represents: <#UserPreviouslyDefinedWithInitializedIvar @field2=7 @field1=6>
- dump_str = "\004\bu:-UserPreviouslyDefinedWithInitializedIvar\a:\f@field2i\f:\f@field1i\v"
-
- UserPreviouslyDefinedWithInitializedIvar.should_receive(:_load).and_return(UserPreviouslyDefinedWithInitializedIvar.new)
- marshaled_obj = Marshal.send(@method, dump_str)
-
- marshaled_obj.should be_an_instance_of(UserPreviouslyDefinedWithInitializedIvar)
- marshaled_obj.field1.should be_nil
- marshaled_obj.field2.should be_nil
- end
-
- describe "that return an immediate value" do
- it "loads an array containing an instance of the object, followed by multiple instances of another object" do
- str = "string"
-
- # this string represents: [<#UserDefinedImmediate A>, <#String "string">, <#String "string">]
- marshaled_obj = Marshal.send(@method, "\004\b[\bu:\031UserDefinedImmediate\000\"\vstring@\a")
-
- marshaled_obj.should == [nil, str, str]
- end
-
- it "loads any structure with multiple references to the same object, followed by multiple instances of another object" do
- str = "string"
-
- # this string represents: {a: <#UserDefinedImmediate A>, b: <#UserDefinedImmediate A>, c: <#String "string">, d: <#String "string">}
- hash_dump = "\x04\b{\t:\x06aIu:\x19UserDefinedImmediate\x00\x06:\x06ET:\x06b@\x06:\x06cI\"\vstring\x06;\aT:\x06d@\a"
-
- marshaled_obj = Marshal.send(@method, hash_dump)
- marshaled_obj.should == {a: nil, b: nil, c: str, d: str}
-
- # this string represents: [<#UserDefinedImmediate A>, <#UserDefinedImmediate A>, <#String "string">, <#String "string">]
- array_dump = "\x04\b[\tIu:\x19UserDefinedImmediate\x00\x06:\x06ET@\x06I\"\vstring\x06;\x06T@\a"
-
- marshaled_obj = Marshal.send(@method, array_dump)
- marshaled_obj.should == [nil, nil, str, str]
- end
-
- it "loads an array containing references to multiple instances of the object, followed by multiple instances of another object" do
- str = "string"
-
- # this string represents: [<#UserDefinedImmediate A>, <#UserDefinedImmediate B>, <#String "string">, <#String "string">]
- array_dump = "\x04\b[\tIu:\x19UserDefinedImmediate\x00\x06:\x06ETIu;\x00\x00\x06;\x06TI\"\vstring\x06;\x06T@\b"
-
- marshaled_obj = Marshal.send(@method, array_dump)
- marshaled_obj.should == [nil, nil, str, str]
- end
- end
- end
-
- it "loads an array containing objects having _dump method, and with proc" do
- arr = []
- myproc = Proc.new { |o| arr << o; o }
- o1 = UserDefined.new;
- o2 = UserDefinedWithIvar.new
- obj = [o1, o2, o1, o2]
-
- Marshal.send(@method, "\x04\b[\tu:\x10UserDefined\x18\x04\b[\aI\"\nstuff\x06:\x06EF@\x06u:\x18UserDefinedWithIvar>\x04\b[\bI\"\nstuff\a:\x06EF:\t@foo:\x18UserDefinedWithIvarI\"\tmore\x06;\x00F@\a@\x06@\a", myproc)
-
- arr.should == [o1, o2, o1, o2, obj]
- end
-
- it "loads an array containing objects having marshal_dump method, and with proc" do
- arr = []
- proc = Proc.new { |o| arr << o; o }
- o1 = UserMarshal.new
- o2 = UserMarshalWithIvar.new
- obj = [o1, o2, o1, o2]
-
- Marshal.send(@method, "\004\b[\tU:\020UserMarshal\"\nstuffU:\030UserMarshalWithIvar[\006\"\fmy data@\006@\b", proc)
-
- arr.should == ['stuff', o1, 'my data', ['my data'], o2, o1, o2, obj]
- end
-
- it "assigns classes to nested subclasses of Array correctly" do
- arr = ArraySub.new(ArraySub.new)
- arr_dump = Marshal.dump(arr)
- Marshal.send(@method, arr_dump).class.should == ArraySub
- end
-
- it "loads subclasses of Array with overridden << and push correctly" do
- arr = ArraySubPush.new
- arr[0] = '1'
- arr_dump = Marshal.dump(arr)
- Marshal.send(@method, arr_dump).should == arr
- end
-
- it "raises a TypeError with bad Marshal version" do
- marshal_data = '\xff\xff'
- marshal_data[0] = (Marshal::MAJOR_VERSION).chr
- marshal_data[1] = (Marshal::MINOR_VERSION + 1).chr
-
- lambda { Marshal.send(@method, marshal_data) }.should raise_error(TypeError)
-
- marshal_data = '\xff\xff'
- marshal_data[0] = (Marshal::MAJOR_VERSION - 1).chr
- marshal_data[1] = (Marshal::MINOR_VERSION).chr
-
- lambda { Marshal.send(@method, marshal_data) }.should raise_error(TypeError)
- end
-
- it "raises EOFError on loading an empty file" do
- temp_file = tmp("marshal.rubyspec.tmp.#{Process.pid}")
- file = File.new(temp_file, "w+")
- begin
- lambda { Marshal.send(@method, file) }.should raise_error(EOFError)
- ensure
- file.close
- rm_r temp_file
- end
- end
-
- it "returns an untainted object if source is untainted" do
- x = Object.new
- y = Marshal.send(@method, Marshal.dump(x))
- y.tainted?.should be_false
- end
-
- describe "when source is tainted" do
- it "returns a tainted object" do
- x = Object.new
- x.taint
- s = Marshal.dump(x)
- y = Marshal.send(@method, s)
- y.tainted?.should be_true
-
- # note that round-trip via Marshal does not preserve
- # the taintedness at each level of the nested structure
- y = Marshal.send(@method, Marshal.dump([[x]]))
- y.tainted?.should be_true
- y.first.tainted?.should be_true
- y.first.first.tainted?.should be_true
- end
-
- it "does not taint Symbols" do
- x = [:x]
- y = Marshal.send(@method, Marshal.dump(x).taint)
- y.tainted?.should be_true
- y.first.tainted?.should be_false
- end
-
- it "does not taint Fixnums" do
- x = [1]
- y = Marshal.send(@method, Marshal.dump(x).taint)
- y.tainted?.should be_true
- y.first.tainted?.should be_false
- end
-
- it "does not taint Bignums" do
- x = [bignum_value]
- y = Marshal.send(@method, Marshal.dump(x).taint)
- y.tainted?.should be_true
- y.first.tainted?.should be_false
- end
-
- it "does not taint Floats" do
- x = [1.2]
- y = Marshal.send(@method, Marshal.dump(x).taint)
- y.tainted?.should be_true
- y.first.tainted?.should be_false
- end
- end
-
- it "preserves taintedness of nested structure" do
- x = Object.new
- a = [[x]]
- x.taint
- y = Marshal.send(@method, Marshal.dump(a))
- y.tainted?.should be_true
- y.first.tainted?.should be_true
- y.first.first.tainted?.should be_true
- end
-
- it "returns a trusted object if source is trusted" do
- x = Object.new
- y = Marshal.send(@method, Marshal.dump(x))
- y.untrusted?.should be_false
- end
-
- it "returns an untrusted object if source is untrusted" do
- x = Object.new
- x.untrust
- y = Marshal.send(@method, Marshal.dump(x))
- y.untrusted?.should be_true
-
- # note that round-trip via Marshal does not preserve
- # the untrustedness at each level of the nested structure
- y = Marshal.send(@method, Marshal.dump([[x]]))
- y.untrusted?.should be_true
- y.first.untrusted?.should be_true
- y.first.first.untrusted?.should be_true
- end
-
- # Note: Ruby 1.9 should be compatible with older marshal format
- MarshalSpec::DATA.each do |description, (object, marshal, attributes)|
- it "loads a #{description}" do
- Marshal.send(@method, marshal).should == object
- end
- end
-
- MarshalSpec::DATA_19.each do |description, (object, marshal, attributes)|
- it "loads a #{description}" do
- Marshal.send(@method, marshal).should == object
- end
- end
-
- describe "for an Array" do
- it "loads an array containing the same objects" do
- s = 'oh'
- b = 'hi'
- r = //
- d = [b, :no, s, :go]
- c = String
- f = 1.0
-
- o1 = UserMarshalWithIvar.new; o2 = UserMarshal.new
-
- obj = [:so, 'hello', 100, :so, :so, d, :so, o2, :so, :no, o2,
- :go, c, nil, Struct::Pyramid.new, f, :go, :no, s, b, r,
- :so, 'huh', o1, true, b, b, 99, r, b, s, :so, f, c, :no, o1, d]
-
- Marshal.send(@method, "\004\b[*:\aso\"\nhelloii;\000;\000[\t\"\ahi:\ano\"\aoh:\ago;\000U:\020UserMarshal\"\nstuff;\000;\006@\n;\ac\vString0S:\024Struct::Pyramid\000f\0061;\a;\006@\t@\b/\000\000;\000\"\bhuhU:\030UserMarshalWithIvar[\006\"\fmy dataT@\b@\bih@\017@\b@\t;\000@\016@\f;\006@\021@\a").should ==
- obj
- end
-
- it "loads an array having ivar" do
- s = 'well'
- s.instance_variable_set(:@foo, 10)
- obj = ['5', s, 'hi'].extend(Meths, MethsMore)
- obj.instance_variable_set(:@mix, s)
- new_obj = Marshal.send(@method, "\004\bI[\b\"\0065I\"\twell\006:\t@fooi\017\"\ahi\006:\t@mix@\a")
- new_obj.should == obj
- new_obj.instance_variable_get(:@mix).should equal new_obj[1]
- new_obj[1].instance_variable_get(:@foo).should == 10
- end
-
- it "loads an extended Array object containing a user-marshaled object" do
- obj = [UserMarshal.new, UserMarshal.new].extend(Meths)
- new_obj = Marshal.send(@method, "\x04\be:\nMeths[\ao:\x10UserMarshal\x06:\n@dataI\"\nstuff\x06:\x06ETo;\x06\x06;\aI\"\nstuff\x06;\bT")
-
- new_obj.should == obj
- obj_ancestors = class << obj; ancestors[1..-1]; end
- new_obj_ancestors = class << new_obj; ancestors[1..-1]; end
- obj_ancestors.should == new_obj_ancestors
- end
- end
-
- describe "for a Hash" do
- it "loads an extended_user_hash with a parameter to initialize" do
- obj = UserHashInitParams.new(:abc).extend(Meths)
-
- new_obj = Marshal.send(@method, "\004\bIe:\nMethsC:\027UserHashInitParams{\000\006:\a@a:\babc")
-
- new_obj.should == obj
- new_obj_metaclass_ancestors = class << new_obj; ancestors; end
- new_obj_metaclass_ancestors[@num_self_class].should == Meths
- new_obj_metaclass_ancestors[@num_self_class+1].should == UserHashInitParams
- end
-
- it "loads an extended hash object containing a user-marshaled object" do
- obj = {a: UserMarshal.new}.extend(Meths)
-
- new_obj = Marshal.send(@method, "\004\be:\nMeths{\006:\006aU:\020UserMarshal\"\nstuff")
-
- new_obj.should == obj
- new_obj_metaclass_ancestors = class << new_obj; ancestors; end
- new_obj_metaclass_ancestors[@num_self_class].should == Meths
- new_obj_metaclass_ancestors[@num_self_class+1].should == Hash
- end
-
- it "preserves hash ivars when hash contains a string having ivar" do
- s = 'string'
- s.instance_variable_set :@string_ivar, 'string ivar'
- h = { key: s }
- h.instance_variable_set :@hash_ivar, 'hash ivar'
-
- unmarshalled = Marshal.send(@method, Marshal.dump(h))
- unmarshalled.instance_variable_get(:@hash_ivar).should == 'hash ivar'
- unmarshalled[:key].instance_variable_get(:@string_ivar).should == 'string ivar'
- end
- end
-
- describe "for a String" do
- it "loads a string having ivar with ref to self" do
- obj = 'hi'
- obj.instance_variable_set(:@self, obj)
- Marshal.send(@method, "\004\bI\"\ahi\006:\n@self@\000").should == obj
- end
-
- it "loads a string through StringIO stream" do
- obj = "This is a string which should be unmarshalled through StringIO stream!"
- Marshal.send(@method, StringIO.new(Marshal.dump(obj))).should == obj
- end
-
- it "loads a string with an ivar" do
- str = Marshal.send(@method, "\x04\bI\"\x00\x06:\t@fooI\"\bbar\x06:\x06EF")
- str.instance_variable_get("@foo").should == "bar"
- end
-
- it "loads a String subclass with custom constructor" do
- str = Marshal.send(@method, "\x04\bC: UserCustomConstructorString\"\x00")
- str.should be_an_instance_of(UserCustomConstructorString)
- end
-
- with_feature :encoding do
- it "loads a US-ASCII String" do
- str = "abc".force_encoding("us-ascii")
- data = "\x04\bI\"\babc\x06:\x06EF"
- result = Marshal.send(@method, data)
- result.should == str
- result.encoding.should equal(Encoding::US_ASCII)
- end
-
- it "loads a UTF-8 String" do
- str = "\x6d\xc3\xb6\x68\x72\x65".force_encoding("utf-8")
- data = "\x04\bI\"\vm\xC3\xB6hre\x06:\x06ET"
- result = Marshal.send(@method, data)
- result.should == str
- result.encoding.should equal(Encoding::UTF_8)
- end
-
- it "loads a String in another encoding" do
- str = "\x6d\x00\xf6\x00\x68\x00\x72\x00\x65\x00".force_encoding("utf-16le")
- data = "\x04\bI\"\x0Fm\x00\xF6\x00h\x00r\x00e\x00\x06:\rencoding\"\rUTF-16LE"
- result = Marshal.send(@method, data)
- result.should == str
- result.encoding.should equal(Encoding::UTF_16LE)
- end
-
- it "loads a String as ASCII-8BIT if no encoding is specified at the end" do
- str = "\xC3\xB8".force_encoding("ASCII-8BIT")
- data = "\x04\b\"\a\xC3\xB8".force_encoding("UTF-8")
- result = Marshal.send(@method, data)
- result.encoding.should == Encoding::ASCII_8BIT
- result.should == str
- end
- end
- end
-
- describe "for a Struct" do
- it "loads a extended_struct having fields with same objects" do
- s = 'hi'
- obj = Struct.new("Ure2", :a, :b).new.extend(Meths)
- obj.a = [:a, s]
- obj.b = [:Meths, s]
-
- Marshal.send(@method,
- "\004\be:\nMethsS:\021Struct::Ure2\a:\006a[\a;\a\"\ahi:\006b[\a;\000@\a"
- ).should == obj
- Struct.send(:remove_const, :Ure2)
- end
-
- it "loads a struct having ivar" do
- obj = Struct.new("Thick").new
- obj.instance_variable_set(:@foo, 5)
- Marshal.send(@method, "\004\bIS:\022Struct::Thick\000\006:\t@fooi\n").should == obj
- Struct.send(:remove_const, :Thick)
- end
-
- it "loads a struct having fields" do
- obj = Struct.new("Ure1", :a, :b).new
- Marshal.send(@method, "\004\bS:\021Struct::Ure1\a:\006a0:\006b0").should == obj
- Struct.send(:remove_const, :Ure1)
- end
-
- it "does not call initialize on the unmarshaled struct" do
- threadlocal_key = MarshalSpec::StructWithUserInitialize::THREADLOCAL_KEY
-
- s = MarshalSpec::StructWithUserInitialize.new('foo')
- Thread.current[threadlocal_key].should == ['foo']
- s.a.should == 'foo'
-
- Thread.current[threadlocal_key] = nil
-
- dumped = Marshal.dump(s)
- loaded = Marshal.send(@method, dumped)
-
- Thread.current[threadlocal_key].should == nil
- loaded.a.should == 'foo'
- end
- end
-
- describe "for an Exception" do
- it "loads a marshalled exception with no message" do
- obj = Exception.new
- loaded = Marshal.send(@method, "\004\bo:\016Exception\a:\abt0:\tmesg0")
- loaded.message.should == obj.message
- loaded.backtrace.should == obj.backtrace
- loaded = Marshal.send(@method, "\x04\bo:\x0EException\a:\tmesg0:\abt0")
- loaded.message.should == obj.message
- loaded.backtrace.should == obj.backtrace
- end
-
- it "loads a marshalled exception with a message" do
- obj = Exception.new("foo")
- loaded = Marshal.send(@method, "\004\bo:\016Exception\a:\abt0:\tmesg\"\bfoo")
- loaded.message.should == obj.message
- loaded.backtrace.should == obj.backtrace
- loaded = Marshal.send(@method, "\x04\bo:\x0EException\a:\tmesgI\"\bfoo\x06:\x06EF:\abt0")
- loaded.message.should == obj.message
- loaded.backtrace.should == obj.backtrace
- end
-
- it "loads a marshalled exception with a backtrace" do
- obj = Exception.new("foo")
- obj.set_backtrace(["foo/bar.rb:10"])
- loaded = Marshal.send(@method, "\004\bo:\016Exception\a:\abt[\006\"\022foo/bar.rb:10:\tmesg\"\bfoo")
- loaded.message.should == obj.message
- loaded.backtrace.should == obj.backtrace
- loaded = Marshal.send(@method, "\x04\bo:\x0EException\a:\tmesgI\"\bfoo\x06:\x06EF:\abt[\x06I\"\x12foo/bar.rb:10\x06;\aF")
- loaded.message.should == obj.message
- loaded.backtrace.should == obj.backtrace
- end
- end
-
- describe "for a user Class" do
- it "loads a user-marshaled extended object" do
- obj = UserMarshal.new.extend(Meths)
-
- new_obj = Marshal.send(@method, "\004\bU:\020UserMarshal\"\nstuff")
-
- new_obj.should == obj
- new_obj_metaclass_ancestors = class << new_obj; ancestors; end
- new_obj_metaclass_ancestors[@num_self_class].should == UserMarshal
- end
-
- it "loads a user_object" do
- UserObject.new
- Marshal.send(@method, "\004\bo:\017UserObject\000").should be_kind_of(UserObject)
- end
-
- it "loads an object" do
- Marshal.send(@method, "\004\bo:\vObject\000").should be_kind_of(Object)
- end
-
- it "raises ArgumentError if the object from an 'o' stream is not dumpable as 'o' type user class" do
- lambda do
- Marshal.send(@method, "\x04\bo:\tFile\001\001:\001\005@path\"\x10/etc/passwd")
- end.should raise_error(ArgumentError)
- end
-
- it "loads an extended Object" do
- obj = Object.new.extend(Meths)
-
- new_obj = Marshal.send(@method, "\004\be:\nMethso:\vObject\000")
-
- new_obj.class.should == obj.class
- new_obj_metaclass_ancestors = class << new_obj; ancestors; end
- new_obj_metaclass_ancestors[@num_self_class, 2].should == [Meths, Object]
- end
-
- describe "that extends a core type other than Object or BasicObject" do
- after :each do
- MarshalSpec.reset_swapped_class
- end
-
- it "raises ArgumentError if the resulting class does not extend the same type" do
- MarshalSpec.set_swapped_class(Class.new(Hash))
- data = Marshal.dump(MarshalSpec::SwappedClass.new)
-
- MarshalSpec.set_swapped_class(Class.new(Array))
- lambda { Marshal.send(@method, data) }.should raise_error(ArgumentError)
-
- MarshalSpec.set_swapped_class(Class.new)
- lambda { Marshal.send(@method, data) }.should raise_error(ArgumentError)
- end
- end
-
- it "loads an object having ivar" do
- s = 'hi'
- arr = [:so, :so, s, s]
- obj = Object.new
- obj.instance_variable_set :@str, arr
-
- new_obj = Marshal.send(@method, "\004\bo:\vObject\006:\t@str[\t:\aso;\a\"\ahi@\a")
- new_str = new_obj.instance_variable_get :@str
-
- new_str.should == arr
- end
- end
-
- describe "for a Regexp" do
- it "loads an extended Regexp" do
- obj = /[a-z]/.extend(Meths, MethsMore)
- new_obj = Marshal.send(@method, "\004\be:\nMethse:\016MethsMore/\n[a-z]\000")
-
- new_obj.should == obj
- new_obj_metaclass_ancestors = class << new_obj; ancestors; end
- new_obj_metaclass_ancestors[@num_self_class, 3].should ==
- [Meths, MethsMore, Regexp]
- end
-
- it "loads a extended_user_regexp having ivar" do
- obj = UserRegexp.new('').extend(Meths)
- obj.instance_variable_set(:@noise, 'much')
-
- new_obj = Marshal.send(@method, "\004\bIe:\nMethsC:\017UserRegexp/\000\000\006:\v@noise\"\tmuch")
-
- new_obj.should == obj
- new_obj.instance_variable_get(:@noise).should == 'much'
- new_obj_metaclass_ancestors = class << new_obj; ancestors; end
- new_obj_metaclass_ancestors[@num_self_class, 3].should ==
- [Meths, UserRegexp, Regexp]
- end
- end
-
- describe "for a Float" do
- it "loads a Float NaN" do
- obj = 0.0 / 0.0
- Marshal.send(@method, "\004\bf\bnan").to_s.should == obj.to_s
- end
-
- it "loads a Float 1.3" do
- Marshal.send(@method, "\004\bf\v1.3\000\314\315").should == 1.3
- end
-
- it "loads a Float -5.1867345e-22" do
- obj = -5.1867345e-22
- Marshal.send(@method, "\004\bf\037-5.1867345000000008e-22\000\203_").should be_close(obj, 1e-30)
- end
-
- it "loads a Float 1.1867345e+22" do
- obj = 1.1867345e+22
- Marshal.send(@method, "\004\bf\0361.1867344999999999e+22\000\344@").should == obj
- end
- end
-
- describe "for a Integer" do
- it "loads 0" do
- Marshal.send(@method, "\004\bi\000").should == 0
- Marshal.send(@method, "\004\bi\005").should == 0
- end
-
- it "loads an Integer 8" do
- Marshal.send(@method, "\004\bi\r" ).should == 8
- end
-
- it "loads and Integer -8" do
- Marshal.send(@method, "\004\bi\363" ).should == -8
- end
-
- it "loads an Integer 1234" do
- Marshal.send(@method, "\004\bi\002\322\004").should == 1234
- end
-
- it "loads an Integer -1234" do
- Marshal.send(@method, "\004\bi\376.\373").should == -1234
- end
-
- it "loads an Integer 4611686018427387903" do
- Marshal.send(@method, "\004\bl+\t\377\377\377\377\377\377\377?").should == 4611686018427387903
- end
-
- it "loads an Integer -4611686018427387903" do
- Marshal.send(@method, "\004\bl-\t\377\377\377\377\377\377\377?").should == -4611686018427387903
- end
-
- it "loads an Integer 2361183241434822606847" do
- Marshal.send(@method, "\004\bl+\n\377\377\377\377\377\377\377\377\177\000").should == 2361183241434822606847
- end
-
- it "loads an Integer -2361183241434822606847" do
- Marshal.send(@method, "\004\bl-\n\377\377\377\377\377\377\377\377\177\000").should == -2361183241434822606847
- end
-
- it "raises ArgumentError if the input is too short" do
- ["\004\bi",
- "\004\bi\001",
- "\004\bi\002",
- "\004\bi\002\0",
- "\004\bi\003",
- "\004\bi\003\0",
- "\004\bi\003\0\0",
- "\004\bi\004",
- "\004\bi\004\0",
- "\004\bi\004\0\0",
- "\004\bi\004\0\0\0"].each do |invalid|
- lambda { Marshal.send(@method, invalid) }.should raise_error(ArgumentError)
- end
- end
-
- if 0.size == 8 # for platforms like x86_64
- it "roundtrips 4611686018427387903 from dump/load correctly" do
- Marshal.send(@method, Marshal.dump(4611686018427387903)).should == 4611686018427387903
- end
- end
- end
-
- describe "for a Rational" do
- it "loads" do
- Marshal.send(@method, Marshal.dump(Rational(1, 3))).should == Rational(1, 3)
- end
- end
-
- describe "for a Complex" do
- it "loads" do
- Marshal.send(@method, Marshal.dump(Complex(4, 3))).should == Complex(4, 3)
- end
- end
-
- describe "for a Bignum" do
- platform_is wordsize: 64 do
- context "that is Bignum on 32-bit platforms but Fixnum on 64-bit" do
- it "dumps a Fixnum" do
- val = Marshal.send(@method, "\004\bl+\ab:wU")
- val.should == 1433877090
- val.class.should == Fixnum
- end
-
- it "dumps an array containing multiple references to the Bignum as an array of Fixnum" do
- arr = Marshal.send(@method, "\004\b[\al+\a\223BwU@\006")
- arr.should == [1433879187, 1433879187]
- arr.each { |v| v.class.should == Fixnum }
- end
- end
- end
- end
-
- describe "for a Time" do
- it "loads" do
- Marshal.send(@method, Marshal.dump(Time.at(1))).should == Time.at(1)
- end
-
- it "loads serialized instance variables" do
- t = Time.new
- t.instance_variable_set(:@foo, 'bar')
-
- Marshal.send(@method, Marshal.dump(t)).instance_variable_get(:@foo).should == 'bar'
- end
-
- it "loads Time objects stored as links" do
- t = Time.new
-
- t1, t2 = Marshal.send(@method, Marshal.dump([t, t]))
- t1.should equal t2
- end
-
- it "loads the zone" do
- with_timezone 'AST', 3 do
- t = Time.local(2012, 1, 1)
- Marshal.send(@method, Marshal.dump(t)).zone.should == t.zone
- end
- end
-
- it "loads nanoseconds" do
- t = Time.now
- Marshal.send(@method, Marshal.dump(t)).nsec.should == t.nsec
- end
- end
-
- describe "for nil" do
- it "loads" do
- Marshal.send(@method, "\x04\b0").should be_nil
- end
- end
-
- describe "for true" do
- it "loads" do
- Marshal.send(@method, "\x04\bT").should be_true
- end
- end
-
- describe "for false" do
- it "loads" do
- Marshal.send(@method, "\x04\bF").should be_false
- end
- end
-
- describe "for a Class" do
- it "loads" do
- Marshal.send(@method, "\x04\bc\vString").should == String
- end
-
- it "raises ArgumentError if given the name of a non-Module" do
- lambda { Marshal.send(@method, "\x04\bc\vKernel") }.should raise_error(ArgumentError)
- end
-
- it "raises ArgumentError if given a nonexistent class" do
- lambda { Marshal.send(@method, "\x04\bc\vStrung") }.should raise_error(ArgumentError)
- end
- end
-
- describe "for a Module" do
- it "loads a module" do
- Marshal.send(@method, "\x04\bm\vKernel").should == Kernel
- end
-
- it "raises ArgumentError if given the name of a non-Class" do
- lambda { Marshal.send(@method, "\x04\bm\vString") }.should raise_error(ArgumentError)
- end
-
- it "loads an old module" do
- Marshal.send(@method, "\x04\bM\vKernel").should == Kernel
- end
- end
-
- describe "for a wrapped C pointer" do
- it "loads" do
- class DumpableDir < Dir
- def _dump_data
- path
- end
- def _load_data path
- initialize(path)
- end
- end
-
- data = "\x04\bd:\x10DumpableDirI\"\x06.\x06:\x06ET"
-
- dir = Marshal.send(@method, data)
- begin
- dir.path.should == '.'
- ensure
- dir.close
- end
- end
-
- it "raises TypeError when the local class is missing _load_data" do
- class UnloadableDumpableDir < Dir
- def _dump_data
- path
- end
- # no _load_data
- end
-
- data = "\x04\bd:\x1AUnloadableDumpableDirI\"\x06.\x06:\x06ET"
-
- lambda { Marshal.send(@method, data) }.should raise_error(TypeError)
- end
-
- it "raises ArgumentError when the local class is a regular object" do
- data = "\004\bd:\020UserDefined\0"
-
- lambda { Marshal.send(@method, data) }.should raise_error(ArgumentError)
- end
- end
-
- describe "when a class does not exist in the namespace" do
- before :each do
- NamespaceTest.send(:const_set, :SameName, Class.new)
- @data = Marshal.dump(NamespaceTest::SameName.new)
- NamespaceTest.send(:remove_const, :SameName)
- end
-
- it "raises an ArgumentError" do
- message = "undefined class/module NamespaceTest::SameName"
- lambda { Marshal.send(@method, @data) }.should raise_error(ArgumentError, message)
- end
- end
-
- it "raises an ArgumentError with full constant name when the dumped constant is missing" do
- NamespaceTest.send(:const_set, :KaBoom, Class.new)
- @data = Marshal.dump(NamespaceTest::KaBoom.new)
- NamespaceTest.send(:remove_const, :KaBoom)
-
- lambda { Marshal.send(@method, @data) }.should raise_error(ArgumentError, /NamespaceTest::KaBoom/)
- end
-end
diff --git a/spec/ruby/core/matchdata/allocate_spec.rb b/spec/ruby/core/matchdata/allocate_spec.rb
new file mode 100644
index 0000000000..f41e2d5481
--- /dev/null
+++ b/spec/ruby/core/matchdata/allocate_spec.rb
@@ -0,0 +1,8 @@
+require_relative '../../spec_helper'
+
+describe "MatchData.allocate" do
+ it "is undefined" do
+ # https://bugs.ruby-lang.org/issues/16294
+ -> { MatchData.allocate }.should.raise(NoMethodError)
+ end
+end
diff --git a/spec/ruby/core/matchdata/begin_spec.rb b/spec/ruby/core/matchdata/begin_spec.rb
index b3d042066d..b4be077ae4 100644
--- a/spec/ruby/core/matchdata/begin_spec.rb
+++ b/spec/ruby/core/matchdata/begin_spec.rb
@@ -1,30 +1,132 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "MatchData#begin" do
- it "returns the offset of the start of the nth element" do
- match_data = /(.)(.)(\d+)(\d)/.match("THX1138.")
- match_data.begin(0).should == 1
- match_data.begin(2).should == 2
- end
+ context "when passed an integer argument" do
+ it "returns the character offset of the start of the nth element" do
+ match_data = /(.)(.)(\d+)(\d)/.match("THX1138.")
+ match_data.begin(0).should == 1
+ match_data.begin(2).should == 2
+ end
+
+ it "returns nil when the nth match isn't found" do
+ match_data = /something is( not)? (right)/.match("something is right")
+ match_data.begin(1).should == nil
+ end
+
+ it "returns the character offset for multi-byte strings" do
+ match_data = /(.)(.)(\d+)(\d)/.match("TñX1138.")
+ match_data.begin(0).should == 1
+ match_data.begin(2).should == 2
+ end
+
+ not_supported_on :opal do
+ it "returns the character offset for multi-byte strings with unicode regexp" do
+ match_data = /(.)(.)(\d+)(\d)/u.match("TñX1138.")
+ match_data.begin(0).should == 1
+ match_data.begin(2).should == 2
+ end
+ end
+
+ it "tries to convert the passed argument to an Integer using #to_int" do
+ obj = mock('to_int')
+ obj.should_receive(:to_int).and_return(2)
+
+ match_data = /(.)(.)(\d+)(\d)/.match("THX1138.")
+ match_data.begin(obj).should == 2
+ end
+
+ it "raises IndexError if index is out of bounds" do
+ match_data = /(?<f>foo)(?<b>bar)/.match("foobar")
+
+ -> {
+ match_data.begin(-1)
+ }.should.raise(IndexError, "index -1 out of matches")
- it "returns nil when the nth match isn't found" do
- match_data = /something is( not)? (right)/.match("something is right")
- match_data.begin(1).should be_nil
+ -> {
+ match_data.begin(3)
+ }.should.raise(IndexError, "index 3 out of matches")
+ end
end
- it "returns the offset for multi byte strings" do
- match_data = /(.)(.)(\d+)(\d)/.match("TñX1138.")
- match_data.begin(0).should == 1
- match_data.begin(2).should == 2
+ context "when passed a String argument" do
+ it "return the character offset of the start of the named capture" do
+ match_data = /(?<a>.)(.)(?<b>\d+)(\d)/.match("THX1138.")
+ match_data.begin("a").should == 1
+ match_data.begin("b").should == 3
+ end
+
+ it "returns the character offset for multi byte strings" do
+ match_data = /(?<a>.)(.)(?<b>\d+)(\d)/.match("TñX1138.")
+ match_data.begin("a").should == 1
+ match_data.begin("b").should == 3
+ end
+
+ not_supported_on :opal do
+ it "returns the character offset for multi byte strings with unicode regexp" do
+ match_data = /(?<a>.)(.)(?<b>\d+)(\d)/u.match("TñX1138.")
+ match_data.begin("a").should == 1
+ match_data.begin("b").should == 3
+ end
+ end
+
+ it "returns the character offset for the farthest match when multiple named captures use the same name" do
+ match_data = /(?<a>.)(.)(?<a>\d+)(\d)/.match("THX1138.")
+ match_data.begin("a").should == 3
+ end
+
+ it "returns the character offset for multi-byte names" do
+ match_data = /(?<æ>.)(.)(?<b>\d+)(\d)/.match("THX1138.")
+ match_data.begin("æ").should == 1
+ end
+
+ it "raises IndexError if there is no group with the provided name" do
+ match_data = /(?<f>foo)(?<b>bar)/.match("foobar")
+
+ -> {
+ match_data.begin("y")
+ }.should.raise(IndexError, "undefined group name reference: y")
+ end
end
- not_supported_on :opal do
- it "returns the offset for multi byte strings with unicode regexp" do
- match_data = /(.)(.)(\d+)(\d)/u.match("TñX1138.")
- match_data.begin(0).should == 1
- match_data.begin(2).should == 2
+ context "when passed a Symbol argument" do
+ it "return the character offset of the start of the named capture" do
+ match_data = /(?<a>.)(.)(?<b>\d+)(\d)/.match("THX1138.")
+ match_data.begin(:a).should == 1
+ match_data.begin(:b).should == 3
+ end
+
+ it "returns the character offset for multi byte strings" do
+ match_data = /(?<a>.)(.)(?<b>\d+)(\d)/.match("TñX1138.")
+ match_data.begin(:a).should == 1
+ match_data.begin(:b).should == 3
+ end
+
+ not_supported_on :opal do
+ it "returns the character offset for multi byte strings with unicode regexp" do
+ match_data = /(?<a>.)(.)(?<b>\d+)(\d)/u.match("TñX1138.")
+ match_data.begin(:a).should == 1
+ match_data.begin(:b).should == 3
+ end
+ end
+
+ it "returns the character offset for the farthest match when multiple named captures use the same name" do
+ match_data = /(?<a>.)(.)(?<a>\d+)(\d)/.match("THX1138.")
+ match_data.begin(:a).should == 3
+ end
+
+ it "returns the character offset for multi-byte names" do
+ match_data = /(?<æ>.)(.)(?<b>\d+)(\d)/.match("THX1138.")
+ match_data.begin(:æ).should == 1
+ end
+
+ it "raises IndexError if there is no group with the provided name" do
+ match_data = /(?<f>foo)(?<b>bar)/.match("foobar")
+
+ -> {
+ match_data.begin(:y)
+ }.should.raise(IndexError, "undefined group name reference: y")
end
end
end
diff --git a/spec/ruby/core/matchdata/bytebegin_spec.rb b/spec/ruby/core/matchdata/bytebegin_spec.rb
new file mode 100644
index 0000000000..fa44ec3b41
--- /dev/null
+++ b/spec/ruby/core/matchdata/bytebegin_spec.rb
@@ -0,0 +1,132 @@
+require_relative '../../spec_helper'
+
+ruby_version_is "3.4" do
+ describe "MatchData#bytebegin" do
+ context "when passed an integer argument" do
+ it "returns the byte-based offset of the start of the nth element" do
+ match_data = /(.)(.)(\d+)(\d)/.match("THX1138.")
+ match_data.bytebegin(0).should == 1
+ match_data.bytebegin(2).should == 2
+ end
+
+ it "returns nil when the nth match isn't found" do
+ match_data = /something is( not)? (right)/.match("something is right")
+ match_data.bytebegin(1).should == nil
+ end
+
+ it "returns the byte-based offset for multi-byte strings" do
+ match_data = /(.)(.)(\d+)(\d)/.match("TñX1138.")
+ match_data.bytebegin(0).should == 1
+ match_data.bytebegin(2).should == 3
+ end
+
+ not_supported_on :opal do
+ it "returns the byte-based offset for multi-byte strings with unicode regexp" do
+ match_data = /(.)(.)(\d+)(\d)/u.match("TñX1138.")
+ match_data.bytebegin(0).should == 1
+ match_data.bytebegin(2).should == 3
+ end
+ end
+
+ it "tries to convert the passed argument to an Integer using #to_int" do
+ obj = mock('to_int')
+ obj.should_receive(:to_int).and_return(2)
+
+ match_data = /(.)(.)(\d+)(\d)/.match("THX1138.")
+ match_data.bytebegin(obj).should == 2
+ end
+
+ it "raises IndexError if index is out of bounds" do
+ match_data = /(?<f>foo)(?<b>bar)/.match("foobar")
+
+ -> {
+ match_data.bytebegin(-1)
+ }.should.raise(IndexError, "index -1 out of matches")
+
+ -> {
+ match_data.bytebegin(3)
+ }.should.raise(IndexError, "index 3 out of matches")
+ end
+ end
+
+ context "when passed a String argument" do
+ it "return the byte-based offset of the start of the named capture" do
+ match_data = /(?<a>.)(.)(?<b>\d+)(\d)/.match("THX1138.")
+ match_data.bytebegin("a").should == 1
+ match_data.bytebegin("b").should == 3
+ end
+
+ it "returns the byte-based offset for multi byte strings" do
+ match_data = /(?<a>.)(.)(?<b>\d+)(\d)/.match("TñX1138.")
+ match_data.bytebegin("a").should == 1
+ match_data.bytebegin("b").should == 4
+ end
+
+ not_supported_on :opal do
+ it "returns the byte-based offset for multi byte strings with unicode regexp" do
+ match_data = /(?<a>.)(.)(?<b>\d+)(\d)/u.match("TñX1138.")
+ match_data.bytebegin("a").should == 1
+ match_data.bytebegin("b").should == 4
+ end
+ end
+
+ it "returns the byte-based offset for the farthest match when multiple named captures use the same name" do
+ match_data = /(?<a>.)(.)(?<a>\d+)(\d)/.match("THX1138.")
+ match_data.bytebegin("a").should == 3
+ end
+
+ it "returns the byte-based offset for multi-byte names" do
+ match_data = /(?<æ>.)(.)(?<b>\d+)(\d)/.match("THX1138.")
+ match_data.bytebegin("æ").should == 1
+ end
+
+ it "raises IndexError if there is no group with the provided name" do
+ match_data = /(?<f>foo)(?<b>bar)/.match("foobar")
+
+ -> {
+ match_data.bytebegin("y")
+ }.should.raise(IndexError, "undefined group name reference: y")
+ end
+ end
+
+ context "when passed a Symbol argument" do
+ it "return the byte-based offset of the start of the named capture" do
+ match_data = /(?<a>.)(.)(?<b>\d+)(\d)/.match("THX1138.")
+ match_data.bytebegin(:a).should == 1
+ match_data.bytebegin(:b).should == 3
+ end
+
+ it "returns the byte-based offset for multi byte strings" do
+ match_data = /(?<a>.)(.)(?<b>\d+)(\d)/.match("TñX1138.")
+ match_data.bytebegin(:a).should == 1
+ match_data.bytebegin(:b).should == 4
+ end
+
+ not_supported_on :opal do
+ it "returns the byte-based offset for multi byte strings with unicode regexp" do
+ match_data = /(?<a>.)(.)(?<b>\d+)(\d)/u.match("TñX1138.")
+ match_data.bytebegin(:a).should == 1
+ match_data.bytebegin(:b).should == 4
+ end
+ end
+
+ it "returns the byte-based offset for the farthest match when multiple named captures use the same name" do
+ match_data = /(?<a>.)(.)(?<a>\d+)(\d)/.match("THX1138.")
+ match_data.bytebegin(:a).should == 3
+ end
+
+ it "returns the byte-based offset for multi-byte names" do
+ match_data = /(?<æ>.)(.)(?<b>\d+)(\d)/.match("THX1138.")
+ match_data.bytebegin(:æ).should == 1
+ end
+
+ it "raises IndexError if there is no group with the provided name" do
+ match_data = /(?<f>foo)(?<b>bar)/.match("foobar")
+
+ -> {
+ match_data.bytebegin(:y)
+ }.should.raise(IndexError, "undefined group name reference: y")
+ end
+ end
+ end
+end
diff --git a/spec/ruby/core/matchdata/byteend_spec.rb b/spec/ruby/core/matchdata/byteend_spec.rb
new file mode 100644
index 0000000000..e77cbf8b0d
--- /dev/null
+++ b/spec/ruby/core/matchdata/byteend_spec.rb
@@ -0,0 +1,104 @@
+require_relative '../../spec_helper'
+
+ruby_version_is "3.4" do
+ describe "MatchData#byteend" do
+ context "when passed an integer argument" do
+ it "returns the byte-based offset of the end of the nth element" do
+ match_data = /(.)(.)(\d+)(\d)/.match("THX1138.")
+ match_data.byteend(0).should == 7
+ match_data.byteend(2).should == 3
+ end
+
+ it "returns nil when the nth match isn't found" do
+ match_data = /something is( not)? (right)/.match("something is right")
+ match_data.byteend(1).should == nil
+ end
+
+ it "returns the byte-based offset for multi-byte strings" do
+ match_data = /(.)(.)(\d+)(\d)/.match("TñX1138.")
+ match_data.byteend(0).should == 8
+ match_data.byteend(2).should == 4
+ end
+
+ not_supported_on :opal do
+ it "returns the byte-based offset for multi-byte strings with unicode regexp" do
+ match_data = /(.)(.)(\d+)(\d)/u.match("TñX1138.")
+ match_data.byteend(0).should == 8
+ match_data.byteend(2).should == 4
+ end
+ end
+
+ it "tries to convert the passed argument to an Integer using #to_int" do
+ obj = mock('to_int')
+ obj.should_receive(:to_int).and_return(2)
+
+ match_data = /(.)(.)(\d+)(\d)/.match("THX1138.")
+ match_data.byteend(obj).should == 3
+ end
+ end
+
+ context "when passed a String argument" do
+ it "return the byte-based offset of the start of the named capture" do
+ match_data = /(?<a>.)(.)(?<b>\d+)(\d)/.match("THX1138.")
+ match_data.byteend("a").should == 2
+ match_data.byteend("b").should == 6
+ end
+
+ it "returns the byte-based offset for multi byte strings" do
+ match_data = /(?<a>.)(.)(?<b>\d+)(\d)/.match("TñX1138.")
+ match_data.byteend("a").should == 3
+ match_data.byteend("b").should == 7
+ end
+
+ not_supported_on :opal do
+ it "returns the byte-based offset for multi byte strings with unicode regexp" do
+ match_data = /(?<a>.)(.)(?<b>\d+)(\d)/u.match("TñX1138.")
+ match_data.byteend("a").should == 3
+ match_data.byteend("b").should == 7
+ end
+ end
+
+ it "returns the byte-based offset for the farthest match when multiple named captures use the same name" do
+ match_data = /(?<a>.)(.)(?<a>\d+)(\d)/.match("THX1138.")
+ match_data.byteend("a").should == 6
+ end
+
+ it "returns the byte-based offset for multi-byte names" do
+ match_data = /(?<æ>.)(.)(?<b>\d+)(\d)/.match("THX1138.")
+ match_data.byteend("æ").should == 2
+ end
+ end
+
+ context "when passed a Symbol argument" do
+ it "return the byte-based offset of the start of the named capture" do
+ match_data = /(?<a>.)(.)(?<b>\d+)(\d)/.match("THX1138.")
+ match_data.byteend(:a).should == 2
+ match_data.byteend(:b).should == 6
+ end
+
+ it "returns the byte-based offset for multi byte strings" do
+ match_data = /(?<a>.)(.)(?<b>\d+)(\d)/.match("TñX1138.")
+ match_data.byteend(:a).should == 3
+ match_data.byteend(:b).should == 7
+ end
+
+ not_supported_on :opal do
+ it "returns the byte-based offset for multi byte strings with unicode regexp" do
+ match_data = /(?<a>.)(.)(?<b>\d+)(\d)/u.match("TñX1138.")
+ match_data.byteend(:a).should == 3
+ match_data.byteend(:b).should == 7
+ end
+ end
+
+ it "returns the byte-based offset for the farthest match when multiple named captures use the same name" do
+ match_data = /(?<a>.)(.)(?<a>\d+)(\d)/.match("THX1138.")
+ match_data.byteend(:a).should == 6
+ end
+
+ it "returns the byte-based offset for multi-byte names" do
+ match_data = /(?<æ>.)(.)(?<b>\d+)(\d)/.match("THX1138.")
+ match_data.byteend(:æ).should == 2
+ end
+ end
+ end
+end
diff --git a/spec/ruby/core/matchdata/byteoffset_spec.rb b/spec/ruby/core/matchdata/byteoffset_spec.rb
new file mode 100644
index 0000000000..062e84027c
--- /dev/null
+++ b/spec/ruby/core/matchdata/byteoffset_spec.rb
@@ -0,0 +1,93 @@
+require_relative '../../spec_helper'
+
+describe "MatchData#byteoffset" do
+ it "returns beginning and ending byte-based offset of whole matched substring for 0 element" do
+ m = /(.)(.)(\d+)(\d)/.match("THX1138.")
+ m.byteoffset(0).should == [1, 7]
+ end
+
+ it "returns beginning and ending byte-based offset of n-th match, all the subsequent elements are capturing groups" do
+ m = /(.)(.)(\d+)(\d)/.match("THX1138.")
+
+ m.byteoffset(2).should == [2, 3]
+ m.byteoffset(3).should == [3, 6]
+ m.byteoffset(4).should == [6, 7]
+ end
+
+ it "accepts String as a reference to a named capture" do
+ m = /(?<f>foo)(?<b>bar)/.match("foobar")
+
+ m.byteoffset("f").should == [0, 3]
+ m.byteoffset("b").should == [3, 6]
+ end
+
+ it "accepts Symbol as a reference to a named capture" do
+ m = /(?<f>foo)(?<b>bar)/.match("foobar")
+
+ m.byteoffset(:f).should == [0, 3]
+ m.byteoffset(:b).should == [3, 6]
+ end
+
+ it "returns [nil, nil] if a capturing group is optional and doesn't match" do
+ m = /(?<x>q..)?/.match("foobarbaz")
+
+ m.byteoffset("x").should == [nil, nil]
+ m.byteoffset(1).should == [nil, nil]
+ end
+
+ it "returns correct beginning and ending byte-based offset for multi-byte strings" do
+ m = /\A\u3042(.)(.)?(.)\z/.match("\u3042\u3043\u3044")
+
+ m.byteoffset(1).should == [3, 6]
+ m.byteoffset(3).should == [6, 9]
+ end
+
+ it "returns [nil, nil] if a capturing group is optional and doesn't match for multi-byte string" do
+ m = /\A\u3042(.)(.)?(.)\z/.match("\u3042\u3043\u3044")
+
+ m.byteoffset(2).should == [nil, nil]
+ end
+
+ it "converts argument into integer if is not String nor Symbol" do
+ m = /(?<f>foo)(?<b>bar)/.match("foobar")
+
+ obj = Object.new
+ def obj.to_int; 2; end
+
+ m.byteoffset(1r).should == [0, 3]
+ m.byteoffset(1.1).should == [0, 3]
+ m.byteoffset(obj).should == [3, 6]
+ end
+
+ it "raises IndexError if there is no group with the provided name" do
+ m = /(?<f>foo)(?<b>bar)/.match("foobar")
+
+ -> {
+ m.byteoffset("y")
+ }.should.raise(IndexError, "undefined group name reference: y")
+
+ -> {
+ m.byteoffset(:y)
+ }.should.raise(IndexError, "undefined group name reference: y")
+ end
+
+ it "raises IndexError if index is out of bounds" do
+ m = /(?<f>foo)(?<b>bar)/.match("foobar")
+
+ -> {
+ m.byteoffset(-1)
+ }.should.raise(IndexError, "index -1 out of matches")
+
+ -> {
+ m.byteoffset(3)
+ }.should.raise(IndexError, "index 3 out of matches")
+ end
+
+ it "raises TypeError if can't convert argument into Integer" do
+ m = /(?<f>foo)(?<b>bar)/.match("foobar")
+
+ -> {
+ m.byteoffset([])
+ }.should.raise(TypeError, "no implicit conversion of Array into Integer")
+ end
+end
diff --git a/spec/ruby/core/matchdata/captures_spec.rb b/spec/ruby/core/matchdata/captures_spec.rb
index 2a83b26cd4..fdbc1c4346 100644
--- a/spec/ruby/core/matchdata/captures_spec.rb
+++ b/spec/ruby/core/matchdata/captures_spec.rb
@@ -1,7 +1,13 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "MatchData#captures" do
it "returns an array of the match captures" do
/(.)(.)(\d+)(\d)/.match("THX1138.").captures.should == ["H","X","113","8"]
end
+
+ it "returns instances of String when given a String subclass" do
+ str = MatchDataSpecs::MyString.new("THX1138: The Movie")
+ /(.)(.)(\d+)(\d)/.match(str).captures.each { |c| c.should.instance_of?(String) }
+ end
end
diff --git a/spec/ruby/core/matchdata/deconstruct_keys_spec.rb b/spec/ruby/core/matchdata/deconstruct_keys_spec.rb
new file mode 100644
index 0000000000..9126d20394
--- /dev/null
+++ b/spec/ruby/core/matchdata/deconstruct_keys_spec.rb
@@ -0,0 +1,78 @@
+require_relative '../../spec_helper'
+
+describe "MatchData#deconstruct_keys" do
+ it "returns whole hash for nil as an argument" do
+ m = /(?<f>foo)(?<b>bar)/.match("foobar")
+
+ m.deconstruct_keys(nil).should == { f: "foo", b: "bar" }
+ end
+
+ it "returns only specified keys" do
+ m = /(?<f>foo)(?<b>bar)/.match("foobar")
+
+ m.deconstruct_keys([:f]).should == { f: "foo" }
+ end
+
+ it "requires one argument" do
+ m = /l/.match("l")
+
+ -> {
+ m.deconstruct_keys
+ }.should.raise(ArgumentError, "wrong number of arguments (given 0, expected 1)")
+ end
+
+ it "it raises error when argument is neither nil nor array" do
+ m = /(?<f>foo)(?<b>bar)/.match("foobar")
+
+ -> { m.deconstruct_keys(1) }.should.raise(TypeError, "wrong argument type Integer (expected Array)")
+ -> { m.deconstruct_keys("asd") }.should.raise(TypeError, "wrong argument type String (expected Array)")
+ -> { m.deconstruct_keys(:x) }.should.raise(TypeError, "wrong argument type Symbol (expected Array)")
+ -> { m.deconstruct_keys({}) }.should.raise(TypeError, "wrong argument type Hash (expected Array)")
+ end
+
+ it "returns {} when passed []" do
+ m = /(?<f>foo)(?<b>bar)/.match("foobar")
+
+ m.deconstruct_keys([]).should == {}
+ end
+
+ it "does not accept non-Symbol keys" do
+ m = /(?<f>foo)(?<b>bar)/.match("foobar")
+
+ -> {
+ m.deconstruct_keys(['year', :foo])
+ }.should.raise(TypeError, "wrong argument type String (expected Symbol)")
+ end
+
+ it "process keys till the first non-existing one" do
+ m = /(?<f>foo)(?<b>bar)(?<c>baz)/.match("foobarbaz")
+
+ m.deconstruct_keys([:f, :a, :b]).should == { f: "foo" }
+ end
+
+ it "returns {} when there are no named captured groups at all" do
+ m = /foo.+/.match("foobar")
+
+ m.deconstruct_keys(nil).should == {}
+ end
+
+ it "returns {} when passed more keys than named captured groups" do
+ m = /(?<f>foo)(?<b>bar)/.match("foobar")
+ m.deconstruct_keys([:f, :b, :c]).should == {}
+ end
+
+ it "includes non-participating captures as nil for nil argument" do
+ m = "hello".match(/(?<a>hello)(?<b>world)?/)
+ m.deconstruct_keys(nil).should == { a: "hello", b: nil }
+ end
+
+ it "includes non-participating captures as nil for explicit keys" do
+ m = "hello".match(/(?<a>hello)(?<b>world)?/)
+ m.deconstruct_keys([:a, :b]).should == { a: "hello", b: nil }
+ end
+
+ it "does not stop iterating at a non-participating capture" do
+ m = "hello!".match(/(?<a>hello)(?<b>world)?(?<c>!)/)
+ m.deconstruct_keys([:b, :c, :a]).should == { b: nil, c: "!", a: "hello" }
+ end
+end
diff --git a/spec/ruby/core/matchdata/deconstruct_spec.rb b/spec/ruby/core/matchdata/deconstruct_spec.rb
new file mode 100644
index 0000000000..13ebd1848f
--- /dev/null
+++ b/spec/ruby/core/matchdata/deconstruct_spec.rb
@@ -0,0 +1,7 @@
+require_relative '../../spec_helper'
+
+describe "MatchData#deconstruct" do
+ it "is an alias of MatchData#captures" do
+ MatchData.instance_method(:deconstruct).should == MatchData.instance_method(:captures)
+ end
+end
diff --git a/spec/ruby/core/matchdata/dup_spec.rb b/spec/ruby/core/matchdata/dup_spec.rb
new file mode 100644
index 0000000000..70877f07eb
--- /dev/null
+++ b/spec/ruby/core/matchdata/dup_spec.rb
@@ -0,0 +1,14 @@
+require_relative '../../spec_helper'
+
+describe "MatchData#dup" do
+ it "duplicates the match data" do
+ original = /ll/.match("hello")
+ original.instance_variable_set(:@custom_ivar, 42)
+ duplicate = original.dup
+
+ duplicate.instance_variable_get(:@custom_ivar).should == 42
+ original.regexp.should == duplicate.regexp
+ original.string.should == duplicate.string
+ original.offset(0).should == duplicate.offset(0)
+ end
+end
diff --git a/spec/ruby/core/matchdata/element_reference_spec.rb b/spec/ruby/core/matchdata/element_reference_spec.rb
index 17d16a5526..5509371cd2 100644
--- a/spec/ruby/core/matchdata/element_reference_spec.rb
+++ b/spec/ruby/core/matchdata/element_reference_spec.rb
@@ -1,4 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "MatchData#[]" do
it "acts as normal array indexing [index]" do
@@ -15,10 +16,46 @@ describe "MatchData#[]" do
it "supports accessors [start, length]" do
/(.)(.)(\d+)(\d)/.match("THX1138.")[1, 2].should == %w|H X|
/(.)(.)(\d+)(\d)/.match("THX1138.")[-3, 2].should == %w|X 113|
+
+ # negative index is larger than the number of match values
+ /(.)(.)(\d+)(\d)/.match("THX1138.")[-30, 2].should == nil
+
+ # positive index larger than number of match values
+ /(.)(.)(\d+)(\d)/.match("THX1138.")[5, 2].should == []
+ /(.)(.)(\d+)(\d)/.match("THX1138.")[6, 2].should == nil
+ /(.)(.)(\d+)(\d)/.match("THX1138.")[30, 2].should == nil
+
+ # length argument larger than number of match values is capped to match value length
+ /(.)(.)(\d+)(\d)/.match("THX1138.")[3, 10].should == %w|113 8|
+
+ /(.)(.)(\d+)(\d)/.match("THX1138.")[3, 0].should == []
+
+ /(.)(.)(\d+)(\d)/.match("THX1138.")[3, -1].should == nil
+ /(.)(.)(\d+)(\d)/.match("THX1138.")[3, -30].should == nil
end
it "supports ranges [start..end]" do
/(.)(.)(\d+)(\d)/.match("THX1138.")[1..3].should == %w|H X 113|
+ /(.)(.)(\d+)(\d)/.match("THX1138.")[3..10].should == %w|113 8|
+ /(.)(.)(\d+)(\d)/.match("THX1138.")[-30..2].should == nil
+ /(.)(.)(\d+)(\d)/.match("THX1138.")[3..1].should == []
+ end
+
+ it "supports endless ranges [start..]" do
+ /(.)(.)(\d+)(\d)/.match("THX1138.")[3..].should == %w|113 8|
+ end
+
+ it "supports beginningless ranges [..end]" do
+ /(.)(.)(\d+)(\d)/.match("THX1138.")[..1].should == %w|HX1138 H|
+ end
+
+ it "supports beginningless endless ranges [nil..nil]" do
+ /(.)(.)(\d+)(\d)/.match("THX1138.")[nil..nil].should == %w|HX1138 H X 113 8|
+ end
+
+ it "returns instances of String when given a String subclass" do
+ str = MatchDataSpecs::MyString.new("THX1138.")
+ /(.)(.)(\d+)(\d)/.match(str)[0..-1].each { |m| m.should.instance_of?(String) }
end
end
@@ -71,17 +108,17 @@ describe "MatchData#[Symbol]" do
it "raises an IndexError if there is no named match corresponding to the Symbol" do
md = 'haystack'.match(/(?<t>t(?<a>ack))/)
- lambda { md[:baz] }.should raise_error(IndexError, /baz/)
+ -> { md[:baz] }.should.raise(IndexError, /baz/)
end
it "raises an IndexError if there is no named match corresponding to the String" do
md = 'haystack'.match(/(?<t>t(?<a>ack))/)
- lambda { md['baz'] }.should raise_error(IndexError, /baz/)
+ -> { md['baz'] }.should.raise(IndexError, /baz/)
end
it "returns matches in the String's encoding" do
rex = /(?<t>t(?<a>ack))/u
- md = 'haystack'.force_encoding('euc-jp').match(rex)
+ md = 'haystack'.dup.force_encoding('euc-jp').match(rex)
md[:t].encoding.should == Encoding::EUC_JP
end
end
diff --git a/spec/ruby/core/matchdata/end_spec.rb b/spec/ruby/core/matchdata/end_spec.rb
index 4e74492105..4fee24a763 100644
--- a/spec/ruby/core/matchdata/end_spec.rb
+++ b/spec/ruby/core/matchdata/end_spec.rb
@@ -1,30 +1,104 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "MatchData#end" do
- it "returns the offset of the end of the nth element" do
- match_data = /(.)(.)(\d+)(\d)/.match("THX1138.")
- match_data.end(0).should == 7
- match_data.end(2).should == 3
- end
+ context "when passed an integer argument" do
+ it "returns the character offset of the end of the nth element" do
+ match_data = /(.)(.)(\d+)(\d)/.match("THX1138.")
+ match_data.end(0).should == 7
+ match_data.end(2).should == 3
+ end
- it "returns nil when the nth match isn't found" do
- match_data = /something is( not)? (right)/.match("something is right")
- match_data.end(1).should be_nil
+ it "returns nil when the nth match isn't found" do
+ match_data = /something is( not)? (right)/.match("something is right")
+ match_data.end(1).should == nil
+ end
+
+ it "returns the character offset for multi-byte strings" do
+ match_data = /(.)(.)(\d+)(\d)/.match("TñX1138.")
+ match_data.end(0).should == 7
+ match_data.end(2).should == 3
+ end
+
+ not_supported_on :opal do
+ it "returns the character offset for multi-byte strings with unicode regexp" do
+ match_data = /(.)(.)(\d+)(\d)/u.match("TñX1138.")
+ match_data.end(0).should == 7
+ match_data.end(2).should == 3
+ end
+ end
+
+ it "tries to convert the passed argument to an Integer using #to_int" do
+ obj = mock('to_int')
+ obj.should_receive(:to_int).and_return(2)
+
+ match_data = /(.)(.)(\d+)(\d)/.match("THX1138.")
+ match_data.end(obj).should == 3
+ end
end
- it "returns the offset for multi byte strings" do
- match_data = /(.)(.)(\d+)(\d)/.match("TñX1138.")
- match_data.end(0).should == 7
- match_data.end(2).should == 3
+ context "when passed a String argument" do
+ it "return the character offset of the start of the named capture" do
+ match_data = /(?<a>.)(.)(?<b>\d+)(\d)/.match("THX1138.")
+ match_data.end("a").should == 2
+ match_data.end("b").should == 6
+ end
+
+ it "returns the character offset for multi byte strings" do
+ match_data = /(?<a>.)(.)(?<b>\d+)(\d)/.match("TñX1138.")
+ match_data.end("a").should == 2
+ match_data.end("b").should == 6
+ end
+
+ not_supported_on :opal do
+ it "returns the character offset for multi byte strings with unicode regexp" do
+ match_data = /(?<a>.)(.)(?<b>\d+)(\d)/u.match("TñX1138.")
+ match_data.end("a").should == 2
+ match_data.end("b").should == 6
+ end
+ end
+
+ it "returns the character offset for the farthest match when multiple named captures use the same name" do
+ match_data = /(?<a>.)(.)(?<a>\d+)(\d)/.match("THX1138.")
+ match_data.end("a").should == 6
+ end
+
+ it "returns the character offset for multi-byte names" do
+ match_data = /(?<æ>.)(.)(?<b>\d+)(\d)/.match("THX1138.")
+ match_data.end("æ").should == 2
+ end
end
- not_supported_on :opal do
- it "returns the offset for multi byte strings with unicode regexp" do
- match_data = /(.)(.)(\d+)(\d)/u.match("TñX1138.")
- match_data.end(0).should == 7
- match_data.end(2).should == 3
+ context "when passed a Symbol argument" do
+ it "return the character offset of the start of the named capture" do
+ match_data = /(?<a>.)(.)(?<b>\d+)(\d)/.match("THX1138.")
+ match_data.end(:a).should == 2
+ match_data.end(:b).should == 6
+ end
+
+ it "returns the character offset for multi byte strings" do
+ match_data = /(?<a>.)(.)(?<b>\d+)(\d)/.match("TñX1138.")
+ match_data.end(:a).should == 2
+ match_data.end(:b).should == 6
+ end
+
+ not_supported_on :opal do
+ it "returns the character offset for multi byte strings with unicode regexp" do
+ match_data = /(?<a>.)(.)(?<b>\d+)(\d)/u.match("TñX1138.")
+ match_data.end(:a).should == 2
+ match_data.end(:b).should == 6
+ end
+ end
+
+ it "returns the character offset for the farthest match when multiple named captures use the same name" do
+ match_data = /(?<a>.)(.)(?<a>\d+)(\d)/.match("THX1138.")
+ match_data.end(:a).should == 6
+ end
+
+ it "returns the character offset for multi-byte names" do
+ match_data = /(?<æ>.)(.)(?<b>\d+)(\d)/.match("THX1138.")
+ match_data.end(:æ).should == 2
end
end
end
diff --git a/spec/ruby/core/matchdata/eql_spec.rb b/spec/ruby/core/matchdata/eql_spec.rb
index 192acbcd13..937c4424aa 100644
--- a/spec/ruby/core/matchdata/eql_spec.rb
+++ b/spec/ruby/core/matchdata/eql_spec.rb
@@ -1,6 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/eql', __FILE__)
+require_relative '../../spec_helper'
describe "MatchData#eql?" do
- it_behaves_like(:matchdata_eql, :eql?)
+ it "is an alias of MatchData#==" do
+ MatchData.instance_method(:eql?).should == MatchData.instance_method(:==)
+ end
end
diff --git a/spec/ruby/core/matchdata/equal_value_spec.rb b/spec/ruby/core/matchdata/equal_value_spec.rb
index 0d33d0acf2..74d3a5adcd 100644
--- a/spec/ruby/core/matchdata/equal_value_spec.rb
+++ b/spec/ruby/core/matchdata/equal_value_spec.rb
@@ -1,6 +1,26 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/eql', __FILE__)
+require_relative '../../spec_helper'
describe "MatchData#==" do
- it_behaves_like(:matchdata_eql, :==)
+ it "returns true if both operands have equal target strings, patterns, and match positions" do
+ a = 'haystack'.match(/hay/)
+ b = 'haystack'.match(/hay/)
+ a.==(b).should == true
+ end
+
+ it "returns false if the operands have different target strings" do
+ a = 'hay'.match(/hay/)
+ b = 'haystack'.match(/hay/)
+ a.==(b).should == false
+ end
+
+ it "returns false if the operands have different patterns" do
+ a = 'haystack'.match(/h.y/)
+ b = 'haystack'.match(/hay/)
+ a.==(b).should == false
+ end
+
+ it "returns false if the argument is not a MatchData object" do
+ a = 'haystack'.match(/hay/)
+ a.==(Object.new).should == false
+ end
end
diff --git a/spec/ruby/core/matchdata/fixtures/classes.rb b/spec/ruby/core/matchdata/fixtures/classes.rb
new file mode 100644
index 0000000000..54795636e5
--- /dev/null
+++ b/spec/ruby/core/matchdata/fixtures/classes.rb
@@ -0,0 +1,3 @@
+module MatchDataSpecs
+ class MyString < String; end
+end
diff --git a/spec/ruby/core/matchdata/hash_spec.rb b/spec/ruby/core/matchdata/hash_spec.rb
index 1d5c8a203f..cef18fdd20 100644
--- a/spec/ruby/core/matchdata/hash_spec.rb
+++ b/spec/ruby/core/matchdata/hash_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "MatchData#hash" do
it "needs to be reviewed for spec completeness"
diff --git a/spec/ruby/core/matchdata/inspect_spec.rb b/spec/ruby/core/matchdata/inspect_spec.rb
index 3cf968b6f5..cacbe10c5d 100644
--- a/spec/ruby/core/matchdata/inspect_spec.rb
+++ b/spec/ruby/core/matchdata/inspect_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "MatchData#inspect" do
before :each do
@@ -6,7 +6,7 @@ describe "MatchData#inspect" do
end
it "returns a String" do
- @match_data.inspect.should be_kind_of(String)
+ @match_data.inspect.should.is_a?(String)
end
it "returns a human readable representation that contains entire matched string and the captures" do
@@ -14,4 +14,10 @@ describe "MatchData#inspect" do
# it makes perfect sense. See JRUBY-4558 for example.
@match_data.inspect.should == '#<MatchData "HX1138" 1:"H" 2:"X" 3:"113" 4:"8">'
end
+
+ it "returns a human readable representation of named captures" do
+ match_data = "abc def ghi".match(/(?<first>\w+)\s+(?<last>\w+)\s+(\w+)/)
+
+ match_data.inspect.should == '#<MatchData "abc def ghi" first:"abc" last:"def">'
+ end
end
diff --git a/spec/ruby/core/matchdata/integer_at_spec.rb b/spec/ruby/core/matchdata/integer_at_spec.rb
new file mode 100644
index 0000000000..65f73a7bee
--- /dev/null
+++ b/spec/ruby/core/matchdata/integer_at_spec.rb
@@ -0,0 +1,38 @@
+# -*- encoding: utf-8 -*-
+
+require_relative '../../spec_helper'
+
+ruby_version_is "4.1" do
+ describe "MatchData#integer_at" do
+ it "converts the corresponding match to an Integer and returns it when given an Integer" do
+ md = /(\d{4})(\d{2})(\d{2})/.match("20260308")
+ md.integer_at(0).should == 20260308
+ md.integer_at(1).should == 2026
+ md.integer_at(2).should == 3
+ end
+
+ it "returns nil on non-matching index matches" do
+ md = /\b(\d)?\b/.match("THX1138.")
+ md.integer_at(1).should == nil
+ end
+
+ it "returns nil on non-integer matches" do
+ md = /(\w)?/.match("THX1138.")
+ md.integer_at(1).should == nil
+ end
+
+ it "converts the match to an Integer in the given base" do
+ md = /\w+/.match("0c")
+ md.integer_at(0).should == 0
+ md.integer_at(0, 16).should == 12
+ end
+
+ it "converts the match to an Integer in the prefix when given base is zero" do
+ /\w+/.match("010").integer_at(0, 0).should == 010
+ /\w+/.match("0x10").integer_at(0, 0).should == 0x10
+ /\w+/.match("0d10").integer_at(0, 0).should == 0d10
+ /\w+/.match("0o10").integer_at(0, 0).should == 0o10
+ /\w+/.match("0b10").integer_at(0, 0).should == 0b10
+ end
+ end
+end
diff --git a/spec/ruby/core/matchdata/length_spec.rb b/spec/ruby/core/matchdata/length_spec.rb
index 75cf607598..72d4d80cec 100644
--- a/spec/ruby/core/matchdata/length_spec.rb
+++ b/spec/ruby/core/matchdata/length_spec.rb
@@ -1,6 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/length', __FILE__)
+require_relative '../../spec_helper'
describe "MatchData#length" do
- it_behaves_like(:matchdata_length, :length)
+ it "is an alias of MatchData#size" do
+ MatchData.instance_method(:length).should == MatchData.instance_method(:size)
+ end
end
diff --git a/spec/ruby/core/matchdata/match_length_spec.rb b/spec/ruby/core/matchdata/match_length_spec.rb
new file mode 100644
index 0000000000..824f94a397
--- /dev/null
+++ b/spec/ruby/core/matchdata/match_length_spec.rb
@@ -0,0 +1,32 @@
+# -*- encoding: utf-8 -*-
+
+require_relative '../../spec_helper'
+
+describe "MatchData#match_length" do
+ it "returns the length of the corresponding match when given an Integer" do
+ md = /(.)(.)(\d+)(\d)/.match("THX1138.")
+
+ md.match_length(0).should == 6
+ md.match_length(1).should == 1
+ md.match_length(2).should == 1
+ md.match_length(3).should == 3
+ md.match_length(4).should == 1
+ end
+
+ it "returns nil on non-matching index matches" do
+ md = /\d+(\w)?/.match("THX1138.")
+ md.match_length(1).should == nil
+ end
+
+ it "returns the length of the corresponding named match when given a Symbol" do
+ md = 'haystack'.match(/(?<t>t(?<a>ack))/)
+ md.match_length(:a).should == 3
+ md.match_length(:t).should == 4
+ end
+
+ it "returns nil on non-matching index matches" do
+ md = 'haystack'.match(/(?<t>t)(?<a>all)?/)
+ md.match_length(:t).should == 1
+ md.match_length(:a).should == nil
+ end
+end
diff --git a/spec/ruby/core/matchdata/match_spec.rb b/spec/ruby/core/matchdata/match_spec.rb
new file mode 100644
index 0000000000..a16914ea15
--- /dev/null
+++ b/spec/ruby/core/matchdata/match_spec.rb
@@ -0,0 +1,32 @@
+# -*- encoding: utf-8 -*-
+
+require_relative '../../spec_helper'
+
+describe "MatchData#match" do
+ it "returns the corresponding match when given an Integer" do
+ md = /(.)(.)(\d+)(\d)/.match("THX1138.")
+
+ md.match(0).should == 'HX1138'
+ md.match(1).should == 'H'
+ md.match(2).should == 'X'
+ md.match(3).should == '113'
+ md.match(4).should == '8'
+ end
+
+ it "returns nil on non-matching index matches" do
+ md = /\d+(\w)?/.match("THX1138.")
+ md.match(1).should == nil
+ end
+
+ it "returns the corresponding named match when given a Symbol" do
+ md = 'haystack'.match(/(?<t>t(?<a>ack))/)
+ md.match(:a).should == 'ack'
+ md.match(:t).should == 'tack'
+ end
+
+ it "returns nil on non-matching index matches" do
+ md = 'haystack'.match(/(?<t>t)(?<a>all)?/)
+ md.match(:t).should == 't'
+ md.match(:a).should == nil
+ end
+end
diff --git a/spec/ruby/core/matchdata/named_captures_spec.rb b/spec/ruby/core/matchdata/named_captures_spec.rb
index cc3aaa2b45..10b1f884d6 100644
--- a/spec/ruby/core/matchdata/named_captures_spec.rb
+++ b/spec/ruby/core/matchdata/named_captures_spec.rb
@@ -1,13 +1,25 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
-ruby_version_is '2.4' do
- describe 'MatchData#named_captures' do
- it 'returns a Hash that has captured name and the matched string pairs' do
- /(?<a>.)(?<b>.)?/.match('0').named_captures.should == { 'a' => '0', 'b' => nil }
- end
+describe 'MatchData#named_captures' do
+ it 'returns a Hash that has captured name and the matched string pairs' do
+ /(?<a>.)(?<b>.)?/.match('0').named_captures.should == { 'a' => '0', 'b' => nil }
+ end
+
+ it 'prefers later captures' do
+ /\A(?<a>.)(?<b>.)(?<b>.)(?<a>.)\z/.match('0123').named_captures.should == { 'a' => '3', 'b' => '2' }
+ end
+
+ it 'returns the latest matched capture, even if a later one that does not match exists' do
+ /\A(?<a>.)(?<b>.)(?<b>.)(?<a>.)?\z/.match('012').named_captures.should == { 'a' => '0', 'b' => '2' }
+ end
+
+ it 'returns a Hash with Symbol keys when symbolize_names is provided a true value' do
+ /(?<a>.)(?<b>.)?/.match('0').named_captures(symbolize_names: true).should == { a: '0', b: nil }
+ /(?<a>.)(?<b>.)?/.match('0').named_captures(symbolize_names: "truly").should == { a: '0', b: nil }
+ end
- it 'prefers later captures' do
- /\A(?<a>.)(?<b>.)(?<b>.)(?<a>.)\z/.match('0123').named_captures.should == { 'a' => '3', 'b' => '2' }
- end
+ it 'returns a Hash with String keys when symbolize_names is provided a false value' do
+ /(?<a>.)(?<b>.)?/.match('02').named_captures(symbolize_names: false).should == { 'a' => '0', 'b' => '2' }
+ /(?<a>.)(?<b>.)?/.match('02').named_captures(symbolize_names: nil).should == { 'a' => '0', 'b' => '2' }
end
end
diff --git a/spec/ruby/core/matchdata/names_spec.rb b/spec/ruby/core/matchdata/names_spec.rb
index e298c85593..dca15985b0 100644
--- a/spec/ruby/core/matchdata/names_spec.rb
+++ b/spec/ruby/core/matchdata/names_spec.rb
@@ -1,14 +1,14 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "MatchData#names" do
it "returns an Array" do
md = 'haystack'.match(/(?<yellow>hay)/)
- md.names.should be_an_instance_of(Array)
+ md.names.should.instance_of?(Array)
end
it "sets each element to a String" do
'haystack'.match(/(?<yellow>hay)/).names.all? do |e|
- e.should be_an_instance_of(String)
+ e.should.instance_of?(String)
end
end
diff --git a/spec/ruby/core/matchdata/offset_spec.rb b/spec/ruby/core/matchdata/offset_spec.rb
index 6ddb56c1a7..5a923d6ce0 100644
--- a/spec/ruby/core/matchdata/offset_spec.rb
+++ b/spec/ruby/core/matchdata/offset_spec.rb
@@ -1,30 +1,102 @@
-# -*- encoding: utf-8 -*-
-
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "MatchData#offset" do
- it "returns a two element array with the begin and end of the nth match" do
- match_data = /(.)(.)(\d+)(\d)/.match("THX1138.")
- match_data.offset(0).should == [1, 7]
- match_data.offset(4).should == [6, 7]
+ it "returns beginning and ending character offset of whole matched substring for 0 element" do
+ m = /(.)(.)(\d+)(\d)/.match("THX1138.")
+ m.offset(0).should == [1, 7]
+ end
+
+ it "returns beginning and ending character offset of n-th match, all the subsequent elements are capturing groups" do
+ m = /(.)(.)(\d+)(\d)/.match("THX1138.")
+
+ m.offset(2).should == [2, 3]
+ m.offset(3).should == [3, 6]
+ m.offset(4).should == [6, 7]
+ end
+
+ it "accepts String as a reference to a named capture" do
+ m = /(?<f>foo)(?<b>bar)/.match("foobar")
+
+ m.offset("f").should == [0, 3]
+ m.offset("b").should == [3, 6]
+ end
+
+ it "accepts Symbol as a reference to a named capture" do
+ m = /(?<f>foo)(?<b>bar)/.match("foobar")
+
+ m.offset(:f).should == [0, 3]
+ m.offset(:b).should == [3, 6]
end
- it "returns [nil, nil] when the nth match isn't found" do
- match_data = /something is( not)? (right)/.match("something is right")
- match_data.offset(1).should == [nil, nil]
+ it "returns [nil, nil] if a capturing group is optional and doesn't match" do
+ m = /(?<x>q..)?/.match("foobarbaz")
+
+ m.offset("x").should == [nil, nil]
+ m.offset(1).should == [nil, nil]
end
- it "returns the offset for multi byte strings" do
- match_data = /(.)(.)(\d+)(\d)/.match("TñX1138.")
- match_data.offset(0).should == [1, 7]
- match_data.offset(4).should == [6, 7]
+ it "returns correct beginning and ending character offset for multi-byte strings" do
+ m = /\A\u3042(.)(.)?(.)\z/.match("\u3042\u3043\u3044")
+
+ m.offset(1).should == [1, 2]
+ m.offset(3).should == [2, 3]
end
not_supported_on :opal do
- it "returns the offset for multi byte strings with unicode regexp" do
- match_data = /(.)(.)(\d+)(\d)/u.match("TñX1138.")
- match_data.offset(0).should == [1, 7]
- match_data.offset(4).should == [6, 7]
+ it "returns correct character offset for multi-byte strings with unicode regexp" do
+ m = /\A\u3042(.)(.)?(.)\z/u.match("\u3042\u3043\u3044")
+
+ m.offset(1).should == [1, 2]
+ m.offset(3).should == [2, 3]
end
end
+
+ it "returns [nil, nil] if a capturing group is optional and doesn't match for multi-byte string" do
+ m = /\A\u3042(.)(.)?(.)\z/.match("\u3042\u3043\u3044")
+
+ m.offset(2).should == [nil, nil]
+ end
+
+ it "converts argument into integer if is not String nor Symbol" do
+ m = /(?<f>foo)(?<b>bar)/.match("foobar")
+
+ obj = Object.new
+ def obj.to_int; 2; end
+
+ m.offset(1r).should == [0, 3]
+ m.offset(1.1).should == [0, 3]
+ m.offset(obj).should == [3, 6]
+ end
+
+ it "raises IndexError if there is no group with the provided name" do
+ m = /(?<f>foo)(?<b>bar)/.match("foobar")
+
+ -> {
+ m.offset("y")
+ }.should.raise(IndexError, "undefined group name reference: y")
+
+ -> {
+ m.offset(:y)
+ }.should.raise(IndexError, "undefined group name reference: y")
+ end
+
+ it "raises IndexError if index is out of bounds" do
+ m = /(?<f>foo)(?<b>bar)/.match("foobar")
+
+ -> {
+ m.offset(-1)
+ }.should.raise(IndexError, "index -1 out of matches")
+
+ -> {
+ m.offset(3)
+ }.should.raise(IndexError, "index 3 out of matches")
+ end
+
+ it "raises TypeError if can't convert argument into Integer" do
+ m = /(?<f>foo)(?<b>bar)/.match("foobar")
+
+ -> {
+ m.offset([])
+ }.should.raise(TypeError, "no implicit conversion of Array into Integer")
+ end
end
diff --git a/spec/ruby/core/matchdata/post_match_spec.rb b/spec/ruby/core/matchdata/post_match_spec.rb
index 670e0887ab..b50d637124 100644
--- a/spec/ruby/core/matchdata/post_match_spec.rb
+++ b/spec/ruby/core/matchdata/post_match_spec.rb
@@ -1,4 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "MatchData#post_match" do
it "returns the string after the match equiv. special var $'" do
@@ -6,31 +7,18 @@ describe "MatchData#post_match" do
$'.should == ': The Movie'
end
- it "keeps taint status from the source string" do
- str = "THX1138: The Movie"
- str.taint
- res = /(.)(.)(\d+)(\d)/.match(str).post_match
- res.tainted?.should be_true
- $'.tainted?.should be_true
+ it "sets the encoding to the encoding of the source String" do
+ str = "abc".dup.force_encoding Encoding::EUC_JP
+ str.match(/b/).post_match.encoding.should.equal?(Encoding::EUC_JP)
end
- it "keeps untrusted status from the source string" do
- str = "THX1138: The Movie"
- str.untrust
- res = /(.)(.)(\d+)(\d)/.match(str).post_match
- res.untrusted?.should be_true
- $'.untrusted?.should be_true
+ it "sets an empty result to the encoding of the source String" do
+ str = "abc".dup.force_encoding Encoding::ISO_8859_1
+ str.match(/c/).post_match.encoding.should.equal?(Encoding::ISO_8859_1)
end
- with_feature :encoding do
- it "sets the encoding to the encoding of the source String" do
- str = "abc".force_encoding Encoding::EUC_JP
- str.match(/b/).post_match.encoding.should equal(Encoding::EUC_JP)
- end
-
- it "sets an empty result to the encoding of the source String" do
- str = "abc".force_encoding Encoding::ISO_8859_1
- str.match(/c/).post_match.encoding.should equal(Encoding::ISO_8859_1)
- end
+ it "returns an instance of String when given a String subclass" do
+ str = MatchDataSpecs::MyString.new("THX1138: The Movie")
+ /(.)(.)(\d+)(\d)/.match(str).post_match.should.instance_of?(String)
end
end
diff --git a/spec/ruby/core/matchdata/pre_match_spec.rb b/spec/ruby/core/matchdata/pre_match_spec.rb
index 1f1f9daec6..106612a4f7 100644
--- a/spec/ruby/core/matchdata/pre_match_spec.rb
+++ b/spec/ruby/core/matchdata/pre_match_spec.rb
@@ -1,4 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "MatchData#pre_match" do
it "returns the string before the match, equiv. special var $`" do
@@ -6,31 +7,18 @@ describe "MatchData#pre_match" do
$`.should == 'T'
end
- it "keeps taint status from the source string" do
- str = "THX1138: The Movie"
- str.taint
- res = /(.)(.)(\d+)(\d)/.match(str).pre_match
- res.tainted?.should be_true
- $`.tainted?.should be_true
+ it "sets the encoding to the encoding of the source String" do
+ str = "abc".dup.force_encoding Encoding::EUC_JP
+ str.match(/b/).pre_match.encoding.should.equal?(Encoding::EUC_JP)
end
- it "keeps untrusted status from the source string" do
- str = "THX1138: The Movie"
- str.untrust
- res = /(.)(.)(\d+)(\d)/.match(str).pre_match
- res.untrusted?.should be_true
- $`.untrusted?.should be_true
+ it "sets an empty result to the encoding of the source String" do
+ str = "abc".dup.force_encoding Encoding::ISO_8859_1
+ str.match(/a/).pre_match.encoding.should.equal?(Encoding::ISO_8859_1)
end
- with_feature :encoding do
- it "sets the encoding to the encoding of the source String" do
- str = "abc".force_encoding Encoding::EUC_JP
- str.match(/b/).pre_match.encoding.should equal(Encoding::EUC_JP)
- end
-
- it "sets an empty result to the encoding of the source String" do
- str = "abc".force_encoding Encoding::ISO_8859_1
- str.match(/a/).pre_match.encoding.should equal(Encoding::ISO_8859_1)
- end
+ it "returns an instance of String when given a String subclass" do
+ str = MatchDataSpecs::MyString.new("THX1138: The Movie")
+ /(.)(.)(\d+)(\d)/.match(str).pre_match.should.instance_of?(String)
end
end
diff --git a/spec/ruby/core/matchdata/regexp_spec.rb b/spec/ruby/core/matchdata/regexp_spec.rb
index 2fdca34c30..7dcb0e62db 100644
--- a/spec/ruby/core/matchdata/regexp_spec.rb
+++ b/spec/ruby/core/matchdata/regexp_spec.rb
@@ -1,13 +1,24 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "MatchData#regexp" do
it "returns a Regexp object" do
m = 'haystack'.match(/hay/)
- m.regexp.should be_an_instance_of(Regexp)
+ m.regexp.should.instance_of?(Regexp)
end
it "returns the pattern used in the match" do
m = 'haystack'.match(/hay/)
m.regexp.should == /hay/
end
+
+ it "returns the same Regexp used to match" do
+ r = /hay/
+ m = 'haystack'.match(r)
+ m.regexp.object_id.should == r.object_id
+ end
+
+ it "returns a Regexp for the result of gsub(String)" do
+ 'he[[o'.gsub('[', ']')
+ $~.regexp.should == /\[/
+ end
end
diff --git a/spec/ruby/core/matchdata/shared/eql.rb b/spec/ruby/core/matchdata/shared/eql.rb
deleted file mode 100644
index 098d82db5b..0000000000
--- a/spec/ruby/core/matchdata/shared/eql.rb
+++ /dev/null
@@ -1,26 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-
-describe :matchdata_eql, shared: true do
- it "returns true if both operands have equal target strings, patterns, and match positions" do
- a = 'haystack'.match(/hay/)
- b = 'haystack'.match(/hay/)
- a.send(@method, b).should be_true
- end
-
- it "returns false if the operands have different target strings" do
- a = 'hay'.match(/hay/)
- b = 'haystack'.match(/hay/)
- a.send(@method, b).should be_false
- end
-
- it "returns false if the operands have different patterns" do
- a = 'haystack'.match(/h.y/)
- b = 'haystack'.match(/hay/)
- a.send(@method, b).should be_false
- end
-
- it "returns false if the argument is not a MatchData object" do
- a = 'haystack'.match(/hay/)
- a.send(@method, Object.new).should be_false
- end
-end
diff --git a/spec/ruby/core/matchdata/shared/length.rb b/spec/ruby/core/matchdata/shared/length.rb
deleted file mode 100644
index 6312a7ed4c..0000000000
--- a/spec/ruby/core/matchdata/shared/length.rb
+++ /dev/null
@@ -1,5 +0,0 @@
-describe :matchdata_length, shared: true do
- it "length should return the number of elements in the match array" do
- /(.)(.)(\d+)(\d)/.match("THX1138.").send(@method).should == 5
- end
-end
diff --git a/spec/ruby/core/matchdata/size_spec.rb b/spec/ruby/core/matchdata/size_spec.rb
index e043f51870..f93ded72cb 100644
--- a/spec/ruby/core/matchdata/size_spec.rb
+++ b/spec/ruby/core/matchdata/size_spec.rb
@@ -1,6 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/length', __FILE__)
+require_relative '../../spec_helper'
describe "MatchData#size" do
- it_behaves_like(:matchdata_length, :size)
+ it "should return the number of elements in the match array" do
+ /(.)(.)(\d+)(\d)/.match("THX1138.").size.should == 5
+ end
end
diff --git a/spec/ruby/core/matchdata/string_spec.rb b/spec/ruby/core/matchdata/string_spec.rb
index 793684d36a..50bbb5a64f 100644
--- a/spec/ruby/core/matchdata/string_spec.rb
+++ b/spec/ruby/core/matchdata/string_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "MatchData#string" do
it "returns a copy of the match string" do
@@ -9,6 +9,18 @@ describe "MatchData#string" do
it "returns a frozen copy of the match string" do
str = /(.)(.)(\d+)(\d)/.match("THX1138.").string
str.should == "THX1138."
- str.frozen?.should == true
+ str.should.frozen?
+ end
+
+ it "returns the same frozen string for every call" do
+ md = /(.)(.)(\d+)(\d)/.match("THX1138.")
+ md.string.should.equal?(md.string)
+ end
+
+ it "returns a frozen copy of the matched string for gsub!(String)" do
+ s = +'he[[o'
+ s.gsub!('[', ']')
+ $~.string.should == 'he[[o'
+ $~.string.should.frozen?
end
end
diff --git a/spec/ruby/core/matchdata/to_a_spec.rb b/spec/ruby/core/matchdata/to_a_spec.rb
index 592a68db0e..c77fc4ab37 100644
--- a/spec/ruby/core/matchdata/to_a_spec.rb
+++ b/spec/ruby/core/matchdata/to_a_spec.rb
@@ -1,7 +1,13 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "MatchData#to_a" do
it "returns an array of matches" do
/(.)(.)(\d+)(\d)/.match("THX1138.").to_a.should == ["HX1138", "H", "X", "113", "8"]
end
+
+ it "returns instances of String when given a String subclass" do
+ str = MatchDataSpecs::MyString.new("THX1138.")
+ /(.)(.)(\d+)(\d)/.match(str)[0..-1].to_a.each { |m| m.should.instance_of?(String) }
+ end
end
diff --git a/spec/ruby/core/matchdata/to_s_spec.rb b/spec/ruby/core/matchdata/to_s_spec.rb
index 3eb3b92533..cbcc5e8a21 100644
--- a/spec/ruby/core/matchdata/to_s_spec.rb
+++ b/spec/ruby/core/matchdata/to_s_spec.rb
@@ -1,7 +1,13 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "MatchData#to_s" do
it "returns the entire matched string" do
/(.)(.)(\d+)(\d)/.match("THX1138.").to_s.should == "HX1138"
end
+
+ it "returns an instance of String when given a String subclass" do
+ str = MatchDataSpecs::MyString.new("THX1138.")
+ /(.)(.)(\d+)(\d)/.match(str).to_s.should.instance_of?(String)
+ end
end
diff --git a/spec/ruby/core/matchdata/values_at_spec.rb b/spec/ruby/core/matchdata/values_at_spec.rb
index 0b2727e001..ba5b0e662c 100644
--- a/spec/ruby/core/matchdata/values_at_spec.rb
+++ b/spec/ruby/core/matchdata/values_at_spec.rb
@@ -1,23 +1,76 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "MatchData#values_at" do
- it "returns an array of the matching value" do
- /(.)(.)(\d+)(\d)/.match("THX1138: The Movie").values_at(0, 2, -2).should == ["HX1138", "X", "113"]
+ # Should be synchronized with core/array/values_at_spec.rb and core/struct/values_at_spec.rb
+ #
+ # /(.)(.)(\d+)(\d)/.match("THX1138: The Movie").to_a # => ["HX1138", "H", "X", "113", "8"]
+
+ context "when passed a list of Integers" do
+ it "returns an array containing each value given by one of integers" do
+ /(.)(.)(\d+)(\d)/.match("THX1138: The Movie").values_at(0, 2, -2).should == ["HX1138", "X", "113"]
+ end
+
+ it "returns nil value for any integer that is out of range" do
+ /(.)(.)(\d+)(\d)/.match("THX1138: The Movie").values_at(5).should == [nil]
+ /(.)(.)(\d+)(\d)/.match("THX1138: The Movie").values_at(-6).should == [nil]
+ end
end
- describe "when passed a Range" do
- it "returns an array of the matching value" do
- /(.)(.)(\d+)(\d)/.match("THX1138: The Movie").values_at(2..4, 0..1).should == ["X", "113", "8", "HX1138", "H"]
+ context "when passed an integer Range" do
+ it "returns an array containing each value given by the elements of the range" do
+ /(.)(.)(\d+)(\d)/.match("THX1138: The Movie").values_at(0..2).should == ["HX1138", "H", "X"]
+ end
+
+ it "fills with nil values for range elements larger than the captured values number" do
+ /(.)(.)(\d+)(\d)/.match("THX1138: The Movie").values_at(0..5).should == ["HX1138", "H", "X", "113", "8", nil]
+ end
+
+ it "raises RangeError if any element of the range is negative and out of range" do
+ -> { /(.)(.)(\d+)(\d)/.match("THX1138: The Movie").values_at(-6..3) }.should.raise(RangeError, "-6..3 out of range")
+ end
+
+ it "supports endless Range" do
+ /(.)(.)(\d+)(\d)/.match("THX1138: The Movie").values_at(0..).should == ["HX1138", "H", "X", "113", "8"]
+ end
+
+ it "supports beginningless Range" do
+ /(.)(.)(\d+)(\d)/.match("THX1138: The Movie").values_at(..2).should == ["HX1138", "H", "X"]
+ end
+
+ it "returns an empty Array when Range is empty" do
+ /(.)(.)(\d+)(\d)/.match("THX1138: The Movie").values_at(2..0).should == []
end
end
- ruby_version_is '2.4' do
+ context "when passed names" do
it 'slices captures with the given names' do
/(?<a>.)(?<b>.)(?<c>.)/.match('012').values_at(:c, :a).should == ['2', '0']
end
- it 'takes names and indices' do
- /\A(?<a>.)(?<b>.)\z/.match('01').values_at(0, 1, 2, :a, :b).should == ['01', '0', '1', '0', '1']
+ it 'slices captures with the given String names' do
+ /(?<a>.)(?<b>.)(?<c>.)/.match('012').values_at('c', 'a').should == ['2', '0']
end
end
+
+ it "supports multiple integer Ranges" do
+ /(.)(.)(\d+)(\d)/.match("THX1138: The Movie").values_at(1..2, 2..3).should == ["H", "X", "X", "113"]
+ end
+
+ it "supports mixing integer Ranges and Integers" do
+ /(.)(.)(\d+)(\d)/.match("THX1138: The Movie").values_at(1..2, 4).should == ["H", "X", "8"]
+ end
+
+ it 'supports mixing of names and indices' do
+ /\A(?<a>.)(?<b>.)\z/.match('01').values_at(0, 1, 2, :a, :b).should == ['01', '0', '1', '0', '1']
+ end
+
+ it "returns a new empty Array if no arguments given" do
+ /(.)(.)(\d+)(\d)/.match("THX1138: The Movie").values_at().should == []
+ end
+
+ it "fails when passed arguments of unsupported types" do
+ -> {
+ /(.)(.)(\d+)(\d)/.match("THX1138: The Movie").values_at(Object.new)
+ }.should.raise(TypeError, "no implicit conversion of Object into Integer")
+ end
end
diff --git a/spec/ruby/core/math/acos_spec.rb b/spec/ruby/core/math/acos_spec.rb
index b0fd9baa91..4649dc527c 100644
--- a/spec/ruby/core/math/acos_spec.rb
+++ b/spec/ruby/core/math/acos_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
# arccosine : (-1.0, 1.0) --> (0, PI)
describe "Math.acos" do
@@ -8,7 +8,7 @@ describe "Math.acos" do
end
it "returns a float" do
- Math.acos(1).should be_kind_of(Float )
+ Math.acos(1).should.is_a?(Float )
end
it "returns the arccosine of the argument" do
@@ -20,30 +20,28 @@ describe "Math.acos" do
Math.acos(0.75).should be_close(0.722734247813416, TOLERANCE)
end
- conflicts_with :Complex do
- it "raises an Errno::EDOM if the argument is greater than 1.0" do
- lambda { Math.acos(1.0001) }.should raise_error(Errno::EDOM)
- end
+ it "raises an Math::DomainError if the argument is greater than 1.0" do
+ -> { Math.acos(1.0001) }.should.raise(Math::DomainError)
+ end
- it "raises an Errno::EDOM if the argument is less than -1.0" do
- lambda { Math.acos(-1.0001) }.should raise_error(Errno::EDOM)
- end
+ it "raises an Math::DomainError if the argument is less than -1.0" do
+ -> { Math.acos(-1.0001) }.should.raise(Math::DomainError)
end
it "raises a TypeError if the string argument cannot be coerced with Float()" do
- lambda { Math.acos("test") }.should raise_error(TypeError)
+ -> { Math.acos("test") }.should.raise(TypeError)
end
it "returns NaN given NaN" do
- Math.acos(nan_value).nan?.should be_true
+ Math.acos(nan_value).nan?.should == true
end
it "raises a TypeError if the argument cannot be coerced with Float()" do
- lambda { Math.acos(MathSpecs::UserClass.new) }.should raise_error(TypeError)
+ -> { Math.acos(MathSpecs::UserClass.new) }.should.raise(TypeError)
end
it "raises a TypeError if the argument is nil" do
- lambda { Math.acos(nil) }.should raise_error(TypeError)
+ -> { Math.acos(nil) }.should.raise(TypeError)
end
it "accepts any argument that can be coerced with Float()" do
diff --git a/spec/ruby/core/math/acosh_spec.rb b/spec/ruby/core/math/acosh_spec.rb
index 272bfaf6a9..ccacda37e0 100644
--- a/spec/ruby/core/math/acosh_spec.rb
+++ b/spec/ruby/core/math/acosh_spec.rb
@@ -1,9 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Math.acosh" do
it "returns a float" do
- Math.acosh(1.0).should be_kind_of(Float)
+ Math.acosh(1.0).should.is_a?(Float)
end
it "returns the principle value of the inverse hyperbolic cosine of the argument" do
@@ -11,24 +11,22 @@ describe "Math.acosh" do
Math.acosh(1.0).should be_close(0.0, TOLERANCE)
end
- conflicts_with :Complex do
- it "raises Errno::EDOM if the passed argument is less than -1.0 or greater than 1.0" do
- lambda { Math.acosh(1.0 - TOLERANCE) }.should raise_error(Errno::EDOM)
- lambda { Math.acosh(0) }.should raise_error(Errno::EDOM)
- lambda { Math.acosh(-1.0) }.should raise_error(Errno::EDOM)
- end
+ it "raises Math::DomainError if the passed argument is less than -1.0 or greater than 1.0" do
+ -> { Math.acosh(1.0 - TOLERANCE) }.should.raise(Math::DomainError)
+ -> { Math.acosh(0) }.should.raise(Math::DomainError)
+ -> { Math.acosh(-1.0) }.should.raise(Math::DomainError)
end
it "raises a TypeError if the argument cannot be coerced with Float()" do
- lambda { Math.acosh("test") }.should raise_error(TypeError)
+ -> { Math.acosh("test") }.should.raise(TypeError)
end
it "returns NaN given NaN" do
- Math.acosh(nan_value).nan?.should be_true
+ Math.acosh(nan_value).nan?.should == true
end
it "raises a TypeError if the argument is nil" do
- lambda { Math.acosh(nil) }.should raise_error(TypeError)
+ -> { Math.acosh(nil) }.should.raise(TypeError)
end
it "accepts any argument that can be coerced with Float()" do
diff --git a/spec/ruby/core/math/asin_spec.rb b/spec/ruby/core/math/asin_spec.rb
index ef3426bceb..1386bccc06 100644
--- a/spec/ruby/core/math/asin_spec.rb
+++ b/spec/ruby/core/math/asin_spec.rb
@@ -1,10 +1,10 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
# arcsine : (-1.0, 1.0) --> (-PI/2, PI/2)
describe "Math.asin" do
it "returns a float" do
- Math.asin(1).should be_kind_of(Float)
+ Math.asin(1).should.is_a?(Float)
end
it "returns the arcsine of the argument" do
@@ -16,26 +16,24 @@ describe "Math.asin" do
Math.asin(0.75).should be_close(0.8480620789814816,TOLERANCE)
end
- conflicts_with :Complex do
- it "raises an Errno::EDOM if the argument is greater than 1.0" do
- lambda { Math.asin(1.0001) }.should raise_error( Errno::EDOM)
- end
+ it "raises an Math::DomainError if the argument is greater than 1.0" do
+ -> { Math.asin(1.0001) }.should.raise( Math::DomainError)
+ end
- it "raises an Errno::EDOM if the argument is less than -1.0" do
- lambda { Math.asin(-1.0001) }.should raise_error( Errno::EDOM)
- end
+ it "raises an Math::DomainError if the argument is less than -1.0" do
+ -> { Math.asin(-1.0001) }.should.raise( Math::DomainError)
end
it "raises a TypeError if the argument cannot be coerced with Float()" do
- lambda { Math.asin("test") }.should raise_error(TypeError)
+ -> { Math.asin("test") }.should.raise(TypeError)
end
it "returns NaN given NaN" do
- Math.asin(nan_value).nan?.should be_true
+ Math.asin(nan_value).nan?.should == true
end
it "raises a TypeError if the argument is nil" do
- lambda { Math.asin(nil) }.should raise_error(TypeError)
+ -> { Math.asin(nil) }.should.raise(TypeError)
end
it "accepts any argument that can be coerced with Float()" do
diff --git a/spec/ruby/core/math/asinh_spec.rb b/spec/ruby/core/math/asinh_spec.rb
index 0761285806..8aa019f05f 100644
--- a/spec/ruby/core/math/asinh_spec.rb
+++ b/spec/ruby/core/math/asinh_spec.rb
@@ -1,9 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Math.asinh" do
it "returns a float" do
- Math.asinh(1.5).should be_kind_of(Float)
+ Math.asinh(1.5).should.is_a?(Float)
end
it "returns the inverse hyperbolic sin of the argument" do
@@ -19,15 +19,15 @@ describe "Math.asinh" do
end
it "raises a TypeError if the argument cannot be coerced with Float()" do
- lambda { Math.asinh("test") }.should raise_error(TypeError)
+ -> { Math.asinh("test") }.should.raise(TypeError)
end
it "returns NaN given NaN" do
- Math.asinh(nan_value).nan?.should be_true
+ Math.asinh(nan_value).nan?.should == true
end
it "raises a TypeError if the argument is nil" do
- lambda { Math.asinh(nil) }.should raise_error(TypeError)
+ -> { Math.asinh(nil) }.should.raise(TypeError)
end
it "accepts any argument that can be coerced with Float()" do
diff --git a/spec/ruby/core/math/atan2_spec.rb b/spec/ruby/core/math/atan2_spec.rb
index ef8f9bb78f..1f1de506c5 100644
--- a/spec/ruby/core/math/atan2_spec.rb
+++ b/spec/ruby/core/math/atan2_spec.rb
@@ -1,9 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Math.atan2" do
it "returns a float" do
- Math.atan2(1.2, 0.5).should be_kind_of(Float)
+ Math.atan2(1.2, 0.5).should.is_a?(Float)
end
it "returns the arc tangent of y, x" do
@@ -14,15 +14,15 @@ describe "Math.atan2" do
end
it "raises a TypeError if the argument cannot be coerced with Float()" do
- lambda { Math.atan2(1.0, "test") }.should raise_error(TypeError)
- lambda { Math.atan2("test", 0.0) }.should raise_error(TypeError)
- lambda { Math.atan2("test", "this") }.should raise_error(TypeError)
+ -> { Math.atan2(1.0, "test") }.should.raise(TypeError)
+ -> { Math.atan2("test", 0.0) }.should.raise(TypeError)
+ -> { Math.atan2("test", "this") }.should.raise(TypeError)
end
it "raises a TypeError if the argument is nil" do
- lambda { Math.atan2(nil, 1.0) }.should raise_error(TypeError)
- lambda { Math.atan2(-1.0, nil) }.should raise_error(TypeError)
- lambda { Math.atan2(nil, nil) }.should raise_error(TypeError)
+ -> { Math.atan2(nil, 1.0) }.should.raise(TypeError)
+ -> { Math.atan2(-1.0, nil) }.should.raise(TypeError)
+ -> { Math.atan2(nil, nil) }.should.raise(TypeError)
end
it "accepts any argument that can be coerced with Float()" do
diff --git a/spec/ruby/core/math/atan_spec.rb b/spec/ruby/core/math/atan_spec.rb
index 6787479cd9..07d04cdf82 100644
--- a/spec/ruby/core/math/atan_spec.rb
+++ b/spec/ruby/core/math/atan_spec.rb
@@ -1,10 +1,10 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
# arctangent : (-Inf, Inf) --> (-PI/2, PI/2)
describe "Math.atan" do
it "returns a float" do
- Math.atan(1).should be_kind_of(Float)
+ Math.atan(1).should.is_a?(Float)
end
it "returns the arctangent of the argument" do
@@ -17,15 +17,15 @@ describe "Math.atan" do
end
it "raises a TypeError if the argument cannot be coerced with Float()" do
- lambda { Math.atan("test") }.should raise_error(TypeError)
+ -> { Math.atan("test") }.should.raise(TypeError)
end
it "returns NaN given NaN" do
- Math.atan(nan_value).nan?.should be_true
+ Math.atan(nan_value).nan?.should == true
end
it "raises a TypeError if the argument is nil" do
- lambda { Math.atan(nil) }.should raise_error(TypeError)
+ -> { Math.atan(nil) }.should.raise(TypeError)
end
it "accepts any argument that can be coerced with Float()" do
diff --git a/spec/ruby/core/math/atanh_spec.rb b/spec/ruby/core/math/atanh_spec.rb
index ce947ceab4..edcb8f2e52 100644
--- a/spec/ruby/core/math/atanh_spec.rb
+++ b/spec/ruby/core/math/atanh_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../fixtures/math/common', __FILE__)
-require File.expand_path('../../../shared/math/atanh', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/common'
+require_relative 'shared/atanh'
describe "Math.atanh" do
it_behaves_like :math_atanh_base, :atanh, Math
diff --git a/spec/ruby/core/math/cbrt_spec.rb b/spec/ruby/core/math/cbrt_spec.rb
index 0b608151ab..4e2383043b 100644
--- a/spec/ruby/core/math/cbrt_spec.rb
+++ b/spec/ruby/core/math/cbrt_spec.rb
@@ -1,9 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Math.cbrt" do
it "returns a float" do
- Math.cbrt(1).should be_an_instance_of(Float)
+ Math.cbrt(1).should.instance_of?(Float)
end
it "returns the cubic root of the argument" do
@@ -14,11 +14,11 @@ describe "Math.cbrt" do
end
it "raises a TypeError if the argument cannot be coerced with Float()" do
- lambda { Math.cbrt("foobar") }.should raise_error(TypeError)
+ -> { Math.cbrt("foobar") }.should.raise(TypeError)
end
it "raises a TypeError if the argument is nil" do
- lambda { Math.cbrt(nil) }.should raise_error(TypeError)
+ -> { Math.cbrt(nil) }.should.raise(TypeError)
end
it "accepts any argument that can be coerced with Float()" do
diff --git a/spec/ruby/core/math/constants_spec.rb b/spec/ruby/core/math/constants_spec.rb
index 8c1b33223e..b500b21a79 100644
--- a/spec/ruby/core/math/constants_spec.rb
+++ b/spec/ruby/core/math/constants_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Math::PI" do
it "approximates the value of pi" do
diff --git a/spec/ruby/core/math/cos_spec.rb b/spec/ruby/core/math/cos_spec.rb
index 59b23b198b..e8602cde3c 100644
--- a/spec/ruby/core/math/cos_spec.rb
+++ b/spec/ruby/core/math/cos_spec.rb
@@ -1,10 +1,10 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
# cosine : (-Inf, Inf) --> (-1.0, 1.0)
describe "Math.cos" do
it "returns a float" do
- Math.cos(Math::PI).should be_kind_of(Float)
+ Math.cos(Math::PI).should.is_a?(Float)
end
it "returns the cosine of the argument expressed in radians" do
@@ -15,23 +15,31 @@ describe "Math.cos" do
Math.cos(2*Math::PI).should be_close(1.0, TOLERANCE)
end
-
it "raises a TypeError unless the argument is Numeric and has #to_f" do
- lambda { Math.cos("test") }.should raise_error(TypeError)
+ -> { Math.cos("test") }.should.raise(TypeError)
end
it "returns NaN given NaN" do
- Math.cos(nan_value).nan?.should be_true
- end
-
- it "raises a TypeError if the argument is nil" do
- lambda { Math.cos(nil) }.should raise_error(TypeError)
+ Math.cos(nan_value).nan?.should == true
end
- it "coerces its argument with #to_f" do
- f = mock_numeric('8.2')
- f.should_receive(:to_f).and_return(8.2)
- Math.cos(f).should == Math.cos(8.2)
+ describe "coerces its argument with #to_f" do
+ it "coerces its argument with #to_f" do
+ f = mock_numeric('8.2')
+ f.should_receive(:to_f).and_return(8.2)
+ Math.cos(f).should == Math.cos(8.2)
+ end
+
+ it "raises a TypeError if the given argument can't be converted to a Float" do
+ -> { Math.cos(nil) }.should.raise(TypeError)
+ -> { Math.cos(:abc) }.should.raise(TypeError)
+ end
+
+ it "raises a NoMethodError if the given argument raises a NoMethodError during type coercion to a Float" do
+ object = mock_numeric('mock-float')
+ object.should_receive(:to_f).and_raise(NoMethodError)
+ -> { Math.cos(object) }.should.raise(NoMethodError)
+ end
end
end
diff --git a/spec/ruby/core/math/cosh_spec.rb b/spec/ruby/core/math/cosh_spec.rb
index 561c3cd312..2093d8a74a 100644
--- a/spec/ruby/core/math/cosh_spec.rb
+++ b/spec/ruby/core/math/cosh_spec.rb
@@ -1,9 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Math.cosh" do
it "returns a float" do
- Math.cosh(1.0).should be_kind_of(Float)
+ Math.cosh(1.0).should.is_a?(Float)
end
it "returns the hyperbolic cosine of the argument" do
@@ -14,15 +14,15 @@ describe "Math.cosh" do
end
it "raises a TypeError if the argument cannot be coerced with Float()" do
- lambda { Math.cosh("test") }.should raise_error(TypeError)
+ -> { Math.cosh("test") }.should.raise(TypeError)
end
it "returns NaN given NaN" do
- Math.cosh(nan_value).nan?.should be_true
+ Math.cosh(nan_value).nan?.should == true
end
it "raises a TypeError if the argument is nil" do
- lambda { Math.cosh(nil) }.should raise_error(TypeError)
+ -> { Math.cosh(nil) }.should.raise(TypeError)
end
it "accepts any argument that can be coerced with Float()" do
diff --git a/spec/ruby/core/math/erf_spec.rb b/spec/ruby/core/math/erf_spec.rb
index 1ea5693dfe..5384e73ae9 100644
--- a/spec/ruby/core/math/erf_spec.rb
+++ b/spec/ruby/core/math/erf_spec.rb
@@ -1,11 +1,11 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
# erf method is the "error function" encountered in integrating the normal
# distribution (which is a normalized form of the Gaussian function).
describe "Math.erf" do
it "returns a float" do
- Math.erf(1).should be_kind_of(Float)
+ Math.erf(1).should.is_a?(Float)
end
it "returns the error function of the argument" do
@@ -21,15 +21,15 @@ describe "Math.erf" do
end
it "raises a TypeError if the argument cannot be coerced with Float()" do
- lambda { Math.erf("test") }.should raise_error(TypeError)
+ -> { Math.erf("test") }.should.raise(TypeError)
end
it "returns NaN given NaN" do
- Math.erf(nan_value).nan?.should be_true
+ Math.erf(nan_value).nan?.should == true
end
it "raises a TypeError if the argument is nil" do
- lambda { Math.erf(nil) }.should raise_error(TypeError)
+ -> { Math.erf(nil) }.should.raise(TypeError)
end
it "accepts any argument that can be coerced with Float()" do
diff --git a/spec/ruby/core/math/erfc_spec.rb b/spec/ruby/core/math/erfc_spec.rb
index 21c9e246ff..4e09a68d1e 100644
--- a/spec/ruby/core/math/erfc_spec.rb
+++ b/spec/ruby/core/math/erfc_spec.rb
@@ -1,10 +1,10 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
# erfc is the complementary error function
describe "Math.erfc" do
it "returns a float" do
- Math.erf(1).should be_kind_of(Float)
+ Math.erf(1).should.is_a?(Float)
end
it "returns the complementary error function of the argument" do
@@ -20,15 +20,15 @@ describe "Math.erfc" do
end
it "raises a TypeError if the argument cannot be coerced with Float()" do
- lambda { Math.erfc("test") }.should raise_error(TypeError)
+ -> { Math.erfc("test") }.should.raise(TypeError)
end
it "returns NaN given NaN" do
- Math.erfc(nan_value).nan?.should be_true
+ Math.erfc(nan_value).nan?.should == true
end
it "raises a TypeError if the argument is nil" do
- lambda { Math.erfc(nil) }.should raise_error(TypeError)
+ -> { Math.erfc(nil) }.should.raise(TypeError)
end
it "accepts any argument that can be coerced with Float()" do
diff --git a/spec/ruby/core/math/exp_spec.rb b/spec/ruby/core/math/exp_spec.rb
index a727404462..3688482457 100644
--- a/spec/ruby/core/math/exp_spec.rb
+++ b/spec/ruby/core/math/exp_spec.rb
@@ -1,9 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Math.exp" do
it "returns a float" do
- Math.exp(1.0).should be_kind_of(Float)
+ Math.exp(1.0).should.is_a?(Float)
end
it "returns the base-e exponential of the argument" do
@@ -14,15 +14,15 @@ describe "Math.exp" do
end
it "raises a TypeError if the argument cannot be coerced with Float()" do
- lambda { Math.exp("test") }.should raise_error(TypeError)
+ -> { Math.exp("test") }.should.raise(TypeError)
end
it "returns NaN given NaN" do
- Math.exp(nan_value).nan?.should be_true
+ Math.exp(nan_value).nan?.should == true
end
it "raises a TypeError if the argument is nil" do
- lambda { Math.exp(nil) }.should raise_error(TypeError)
+ -> { Math.exp(nil) }.should.raise(TypeError)
end
it "accepts any argument that can be coerced with Float()" do
diff --git a/spec/ruby/core/math/expm1_spec.rb b/spec/ruby/core/math/expm1_spec.rb
new file mode 100644
index 0000000000..35f62b5dbd
--- /dev/null
+++ b/spec/ruby/core/math/expm1_spec.rb
@@ -0,0 +1,37 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+ruby_version_is "4.0" do
+ describe "Math.expm1" do
+ it "calculates Math.exp(arg) - 1" do
+ Math.expm1(3).should == Math.exp(3) - 1
+ end
+
+ it "preserves precision that can be lost otherwise" do
+ Math.expm1(1.0e-16).should be_close(1.0e-16, TOLERANCE)
+ Math.expm1(1.0e-16).should != 0.0
+ end
+
+ it "raises a TypeError if the argument cannot be coerced with Float()" do
+ -> { Math.expm1("test") }.should.raise(TypeError, "can't convert String into Float")
+ end
+
+ it "returns NaN given NaN" do
+ Math.expm1(nan_value).nan?.should == true
+ end
+
+ it "raises a TypeError if the argument is nil" do
+ -> { Math.expm1(nil) }.should.raise(TypeError, "can't convert nil into Float")
+ end
+
+ it "accepts any argument that can be coerced with Float()" do
+ Math.expm1(MathSpecs::Float.new).should be_close(Math::E - 1, TOLERANCE)
+ end
+ end
+
+ describe "Math#expm1" do
+ it "is accessible as a private instance method" do
+ IncludesMath.new.send(:expm1, 23.1415).should be_close(11226018483.0012, TOLERANCE)
+ end
+ end
+end
diff --git a/spec/ruby/fixtures/math/common.rb b/spec/ruby/core/math/fixtures/common.rb
index 024732fa7a..024732fa7a 100644
--- a/spec/ruby/fixtures/math/common.rb
+++ b/spec/ruby/core/math/fixtures/common.rb
diff --git a/spec/ruby/core/math/frexp_spec.rb b/spec/ruby/core/math/frexp_spec.rb
index 4c529b0911..6853e4672f 100644
--- a/spec/ruby/core/math/frexp_spec.rb
+++ b/spec/ruby/core/math/frexp_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Math.frexp" do
it "returns the normalized fraction and exponent" do
@@ -9,16 +9,16 @@ describe "Math.frexp" do
end
it "raises a TypeError if the argument cannot be coerced with Float()" do
- lambda { Math.frexp("test") }.should raise_error(TypeError)
+ -> { Math.frexp("test") }.should.raise(TypeError)
end
it "returns NaN given NaN" do
frac, _exp = Math.frexp(nan_value)
- frac.nan?.should be_true
+ frac.nan?.should == true
end
it "raises a TypeError if the argument is nil" do
- lambda { Math.frexp(nil) }.should raise_error(TypeError)
+ -> { Math.frexp(nil) }.should.raise(TypeError)
end
it "accepts any argument that can be coerced with Float()" do
diff --git a/spec/ruby/core/math/gamma_spec.rb b/spec/ruby/core/math/gamma_spec.rb
index eb26f25bfe..9a0b14448a 100644
--- a/spec/ruby/core/math/gamma_spec.rb
+++ b/spec/ruby/core/math/gamma_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Math.gamma" do
it "returns +infinity given 0" do
@@ -51,7 +51,7 @@ describe "Math.gamma" do
end
it "raises Math::DomainError given -1" do
- lambda { Math.gamma(-1) }.should raise_error(Math::DomainError)
+ -> { Math.gamma(-1) }.should.raise(Math::DomainError)
end
# See https://bugs.ruby-lang.org/issues/10642
@@ -60,10 +60,10 @@ describe "Math.gamma" do
end
it "raises Math::DomainError given negative infinity" do
- lambda { Math.gamma(-Float::INFINITY) }.should raise_error(Math::DomainError)
+ -> { Math.gamma(-Float::INFINITY) }.should.raise(Math::DomainError)
end
it "returns NaN given NaN" do
- Math.gamma(nan_value).nan?.should be_true
+ Math.gamma(nan_value).nan?.should == true
end
end
diff --git a/spec/ruby/core/math/hypot_spec.rb b/spec/ruby/core/math/hypot_spec.rb
index f693a719f3..4ab5bd4e88 100644
--- a/spec/ruby/core/math/hypot_spec.rb
+++ b/spec/ruby/core/math/hypot_spec.rb
@@ -1,9 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Math.hypot" do
it "returns a float" do
- Math.hypot(3, 4).should be_kind_of(Float)
+ Math.hypot(3, 4).should.is_a?(Float)
end
it "returns the length of the hypotenuse of a right triangle with legs given by the arguments" do
@@ -16,17 +16,17 @@ describe "Math.hypot" do
end
it "raises a TypeError if the argument cannot be coerced with Float()" do
- lambda { Math.hypot("test", "this") }.should raise_error(TypeError)
+ -> { Math.hypot("test", "this") }.should.raise(TypeError)
end
it "returns NaN given NaN" do
- Math.hypot(nan_value, 0).nan?.should be_true
- Math.hypot(0, nan_value).nan?.should be_true
- Math.hypot(nan_value, nan_value).nan?.should be_true
+ Math.hypot(nan_value, 0).nan?.should == true
+ Math.hypot(0, nan_value).nan?.should == true
+ Math.hypot(nan_value, nan_value).nan?.should == true
end
it "raises a TypeError if the argument is nil" do
- lambda { Math.hypot(nil, nil) }.should raise_error(TypeError)
+ -> { Math.hypot(nil, nil) }.should.raise(TypeError)
end
it "accepts any argument that can be coerced with Float()" do
diff --git a/spec/ruby/core/math/ldexp_spec.rb b/spec/ruby/core/math/ldexp_spec.rb
index 360f5c5e2a..1864b7455a 100644
--- a/spec/ruby/core/math/ldexp_spec.rb
+++ b/spec/ruby/core/math/ldexp_spec.rb
@@ -1,9 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Math.ldexp" do
it "returns a float" do
- Math.ldexp(1.0, 2).should be_kind_of(Float)
+ Math.ldexp(1.0, 2).should.is_a?(Float)
end
it "returns the argument multiplied by 2**n" do
@@ -15,27 +15,27 @@ describe "Math.ldexp" do
end
it "raises a TypeError if the first argument cannot be coerced with Float()" do
- lambda { Math.ldexp("test", 2) }.should raise_error(TypeError)
+ -> { Math.ldexp("test", 2) }.should.raise(TypeError)
end
it "returns NaN given NaN" do
- Math.ldexp(nan_value, 0).nan?.should be_true
+ Math.ldexp(nan_value, 0).nan?.should == true
end
it "raises RangeError if NaN is given as the second arg" do
- lambda { Math.ldexp(0, nan_value) }.should raise_error(RangeError)
+ -> { Math.ldexp(0, nan_value) }.should.raise(RangeError)
end
it "raises a TypeError if the second argument cannot be coerced with Integer()" do
- lambda { Math.ldexp(3.2, "this") }.should raise_error(TypeError)
+ -> { Math.ldexp(3.2, "this") }.should.raise(TypeError)
end
it "raises a TypeError if the first argument is nil" do
- lambda { Math.ldexp(nil, 2) }.should raise_error(TypeError)
+ -> { Math.ldexp(nil, 2) }.should.raise(TypeError)
end
it "raises a TypeError if the second argument is nil" do
- lambda { Math.ldexp(3.1, nil) }.should raise_error(TypeError)
+ -> { Math.ldexp(3.1, nil) }.should.raise(TypeError)
end
it "accepts any first argument that can be coerced with Float()" do
@@ -45,6 +45,12 @@ describe "Math.ldexp" do
it "accepts any second argument that can be coerced with Integer()" do
Math.ldexp(3.23, MathSpecs::Integer.new).should be_close(12.92, TOLERANCE)
end
+
+ it "returns correct value that closes to the max value of double type" do
+ Math.ldexp(0.5122058490966879, 1024).should == 9.207889385574391e+307
+ Math.ldexp(0.9999999999999999, 1024).should == 1.7976931348623157e+308
+ Math.ldexp(0.99999999999999999, 1024).should == Float::INFINITY
+ end
end
describe "Math#ldexp" do
diff --git a/spec/ruby/core/math/lgamma_spec.rb b/spec/ruby/core/math/lgamma_spec.rb
index 885a1b252c..38f07d0bf8 100644
--- a/spec/ruby/core/math/lgamma_spec.rb
+++ b/spec/ruby/core/math/lgamma_spec.rb
@@ -1,20 +1,16 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Math.lgamma" do
it "returns [Infinity, 1] when passed 0" do
Math.lgamma(0).should == [infinity_value, 1]
end
- platform_is_not :windows do
- it "returns [Infinity, 1] when passed -1" do
- Math.lgamma(-1).should == [infinity_value, 1]
- end
+ it "returns [Infinity, ...] when passed -1" do
+ Math.lgamma(-1)[0].should == infinity_value
end
- ruby_version_is "2.4" do
- it "returns [Infinity, -1] when passed -0.0" do
- Math.lgamma(-0.0).should == [infinity_value, -1]
- end
+ it "returns [Infinity, -1] when passed -0.0" do
+ Math.lgamma(-0.0).should == [infinity_value, -1]
end
it "returns [log(sqrt(PI)), 1] when passed 0.5" do
@@ -42,15 +38,14 @@ describe "Math.lgamma" do
end
it "raises Math::DomainError when passed -Infinity" do
- lambda { Math.lgamma(-infinity_value) }.should raise_error(Math::DomainError)
+ -> { Math.lgamma(-infinity_value) }.should.raise(Math::DomainError)
end
it "returns [Infinity, 1] when passed Infinity" do
Math.lgamma(infinity_value).should == [infinity_value, 1]
end
- it "returns [NaN, 1] when passed NaN" do
- Math.lgamma(nan_value)[0].nan?.should be_true
- Math.lgamma(nan_value)[1].should == 1
+ it "returns [NaN, ...] when passed NaN" do
+ Math.lgamma(nan_value)[0].should.nan?
end
end
diff --git a/spec/ruby/core/math/log10_spec.rb b/spec/ruby/core/math/log10_spec.rb
index 8164b9994d..7576a67002 100644
--- a/spec/ruby/core/math/log10_spec.rb
+++ b/spec/ruby/core/math/log10_spec.rb
@@ -1,10 +1,10 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
# The common logarithm, having base 10
describe "Math.log10" do
it "returns a float" do
- Math.log10(1).should be_kind_of(Float)
+ Math.log10(1).should.is_a?(Float)
end
it "returns the base-10 logarithm of the argument" do
@@ -15,22 +15,24 @@ describe "Math.log10" do
Math.log10(10e15).should be_close(16.0, TOLERANCE)
end
- conflicts_with :Complex do
- it "raises an Errno::EDOM if the argument is less than 0" do
- lambda { Math.log10(-1e-15) }.should raise_error( Errno::EDOM)
- end
+ it "raises an Math::DomainError if the argument is less than 0" do
+ -> { Math.log10(-1e-15) }.should.raise(Math::DomainError)
end
it "raises a TypeError if the argument cannot be coerced with Float()" do
- lambda { Math.log10("test") }.should raise_error(TypeError)
+ -> { Math.log10("test") }.should.raise(TypeError)
+ end
+
+ it "raises a TypeError if passed a numerical argument as a string" do
+ -> { Math.log10("1.0") }.should.raise(TypeError)
end
it "returns NaN given NaN" do
- Math.log10(nan_value).nan?.should be_true
+ Math.log10(nan_value).nan?.should == true
end
it "raises a TypeError if the argument is nil" do
- lambda { Math.log10(nil) }.should raise_error(TypeError)
+ -> { Math.log10(nil) }.should.raise(TypeError)
end
it "accepts any argument that can be coerced with Float()" do
diff --git a/spec/ruby/core/math/log1p_spec.rb b/spec/ruby/core/math/log1p_spec.rb
new file mode 100644
index 0000000000..181b462ded
--- /dev/null
+++ b/spec/ruby/core/math/log1p_spec.rb
@@ -0,0 +1,49 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+ruby_version_is "4.0" do
+ describe "Math.log1p" do
+ it "calculates Math.log(1 + arg)" do
+ Math.log1p(3).should == Math.log(1 + 3)
+ end
+
+ it "preserves precision that can be lost otherwise" do
+ Math.log1p(1e-16).should be_close(1.0e-16, TOLERANCE)
+ Math.log1p(1e-16).should != 0.0
+ end
+
+ it "raises an Math::DomainError if the argument is less than 1" do
+ -> { Math.log1p(-1-1e-15) }.should.raise(Math::DomainError, "Numerical argument is out of domain - log1p")
+ end
+
+ it "raises a TypeError if the argument cannot be coerced with Float()" do
+ -> { Math.log1p("test") }.should.raise(TypeError, "can't convert String into Float")
+ end
+
+ it "raises a TypeError for numerical values passed as string" do
+ -> { Math.log1p("10") }.should.raise(TypeError, "can't convert String into Float")
+ end
+
+ it "does not accept a second argument for the base" do
+ -> { Math.log1p(9, 3) }.should.raise(ArgumentError, "wrong number of arguments (given 2, expected 1)")
+ end
+
+ it "returns NaN given NaN" do
+ Math.log1p(nan_value).nan?.should == true
+ end
+
+ it "raises a TypeError if the argument is nil" do
+ -> { Math.log1p(nil) }.should.raise(TypeError, "can't convert nil into Float")
+ end
+
+ it "accepts any argument that can be coerced with Float()" do
+ Math.log1p(MathSpecs::Float.new).should be_close(0.6931471805599453, TOLERANCE)
+ end
+ end
+
+ describe "Math#log1p" do
+ it "is accessible as a private instance method" do
+ IncludesMath.new.send(:log1p, 4.21).should be_close(1.65057985576528, TOLERANCE)
+ end
+ end
+end
diff --git a/spec/ruby/core/math/log2_spec.rb b/spec/ruby/core/math/log2_spec.rb
index 387f05ca9f..e38a8bb67f 100644
--- a/spec/ruby/core/math/log2_spec.rb
+++ b/spec/ruby/core/math/log2_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Math.log2" do
it "returns a float" do
@@ -15,24 +15,24 @@ describe "Math.log2" do
Math.log2((2**301+45677544234809571)).should == 301.0
end
- it "raises an Errno::EDOM if the argument is less than 0" do
- lambda { Math.log2(-1e-15) }.should raise_error( Math::DomainError)
+ it "raises Math::DomainError if the argument is less than 0" do
+ -> { Math.log2(-1e-15) }.should.raise( Math::DomainError)
end
it "raises a TypeError if the argument cannot be coerced with Float()" do
- lambda { Math.log2("test") }.should raise_error(TypeError)
+ -> { Math.log2("test") }.should.raise(TypeError)
end
it "raises a TypeError if passed a numerical argument as a string" do
- lambda { Math.log2("1.0") }.should raise_error(TypeError)
+ -> { Math.log2("1.0") }.should.raise(TypeError)
end
it "returns NaN given NaN" do
- Math.log2(nan_value).nan?.should be_true
+ Math.log2(nan_value).nan?.should == true
end
it "raises a TypeError if the argument is nil" do
- lambda { Math.log2(nil) }.should raise_error(TypeError)
+ -> { Math.log2(nil) }.should.raise(TypeError)
end
it "accepts any argument that can be coerced with Float()" do
diff --git a/spec/ruby/core/math/log_spec.rb b/spec/ruby/core/math/log_spec.rb
index 9bcccb55e2..7e0bc13bc6 100644
--- a/spec/ruby/core/math/log_spec.rb
+++ b/spec/ruby/core/math/log_spec.rb
@@ -1,10 +1,10 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
# The natural logarithm, having base Math::E
describe "Math.log" do
it "returns a float" do
- Math.log(1).should be_kind_of(Float)
+ Math.log(1).should.is_a?(Float)
end
it "returns the natural logarithm of the argument" do
@@ -15,18 +15,16 @@ describe "Math.log" do
Math.log(10e15).should be_close(36.8413614879047, TOLERANCE)
end
- conflicts_with :Complex do
- it "raises an Errno::EDOM if the argument is less than 0" do
- lambda { Math.log(-1e-15) }.should raise_error(Errno::EDOM)
- end
+ it "raises an Math::DomainError if the argument is less than 0" do
+ -> { Math.log(-1e-15) }.should.raise(Math::DomainError)
end
it "raises a TypeError if the argument cannot be coerced with Float()" do
- lambda { Math.log("test") }.should raise_error(TypeError)
+ -> { Math.log("test") }.should.raise(TypeError)
end
it "raises a TypeError for numerical values passed as string" do
- lambda { Math.log("10") }.should raise_error(TypeError)
+ -> { Math.log("10") }.should.raise(TypeError)
end
it "accepts a second argument for the base" do
@@ -35,16 +33,16 @@ describe "Math.log" do
end
it "raises a TypeError when the numerical base cannot be coerced to a float" do
- lambda { Math.log(10, "2") }.should raise_error(TypeError)
- lambda { Math.log(10, nil) }.should raise_error(TypeError)
+ -> { Math.log(10, "2") }.should.raise(TypeError)
+ -> { Math.log(10, nil) }.should.raise(TypeError)
end
it "returns NaN given NaN" do
- Math.log(nan_value).nan?.should be_true
+ Math.log(nan_value).nan?.should == true
end
it "raises a TypeError if the argument is nil" do
- lambda { Math.log(nil) }.should raise_error(TypeError)
+ -> { Math.log(nil) }.should.raise(TypeError)
end
it "accepts any argument that can be coerced with Float()" do
diff --git a/spec/ruby/core/math/shared/atanh.rb b/spec/ruby/core/math/shared/atanh.rb
new file mode 100644
index 0000000000..48a6bf836e
--- /dev/null
+++ b/spec/ruby/core/math/shared/atanh.rb
@@ -0,0 +1,44 @@
+describe :math_atanh_base, shared: true do
+ it "returns a float" do
+ @object.send(@method, 0.5).should.instance_of?(Float)
+ end
+
+ it "returns the inverse hyperbolic tangent of the argument" do
+ @object.send(@method, 0.0).should == 0.0
+ @object.send(@method, -0.0).should == -0.0
+ @object.send(@method, 0.5).should be_close(0.549306144334055, TOLERANCE)
+ @object.send(@method, -0.2).should be_close(-0.202732554054082, TOLERANCE)
+ end
+
+ it "raises a TypeError if the argument is nil" do
+ -> { @object.send(@method, nil) }.should.raise(TypeError)
+ end
+
+ it "raises a TypeError if the argument is not a Numeric" do
+ -> { @object.send(@method, "test") }.should.raise(TypeError)
+ end
+
+ it "returns Infinity if x == 1.0" do
+ @object.send(@method, 1.0).should == Float::INFINITY
+ end
+
+ it "return -Infinity if x == -1.0" do
+ @object.send(@method, -1.0).should == -Float::INFINITY
+ end
+end
+
+describe :math_atanh_private, shared: true do
+ it "is a private instance method" do
+ Math.private_instance_methods(false).should.include?(@method)
+ end
+end
+
+describe :math_atanh_no_complex, shared: true do
+ it "raises a Math::DomainError for arguments greater than 1.0" do
+ -> { @object.send(@method, 1.0 + Float::EPSILON) }.should.raise(Math::DomainError)
+ end
+
+ it "raises a Math::DomainError for arguments less than -1.0" do
+ -> { @object.send(@method, -1.0 - Float::EPSILON) }.should.raise(Math::DomainError)
+ end
+end
diff --git a/spec/ruby/core/math/sin_spec.rb b/spec/ruby/core/math/sin_spec.rb
index d8f134e609..a9479e3aec 100644
--- a/spec/ruby/core/math/sin_spec.rb
+++ b/spec/ruby/core/math/sin_spec.rb
@@ -1,10 +1,10 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
# sine : (-Inf, Inf) --> (-1.0, 1.0)
describe "Math.sin" do
it "returns a float" do
- Math.sin(Math::PI).should be_kind_of(Float)
+ Math.sin(Math::PI).should.is_a?(Float)
end
it "returns the sine of the argument expressed in radians" do
@@ -16,15 +16,15 @@ describe "Math.sin" do
end
it "raises a TypeError if the argument cannot be coerced with Float()" do
- lambda { Math.sin("test") }.should raise_error(TypeError)
+ -> { Math.sin("test") }.should.raise(TypeError)
end
it "returns NaN given NaN" do
- Math.sin(nan_value).nan?.should be_true
+ Math.sin(nan_value).nan?.should == true
end
it "raises a TypeError if the argument is nil" do
- lambda { Math.sin(nil) }.should raise_error(TypeError)
+ -> { Math.sin(nil) }.should.raise(TypeError)
end
it "accepts any argument that can be coerced with Float()" do
diff --git a/spec/ruby/core/math/sinh_spec.rb b/spec/ruby/core/math/sinh_spec.rb
index daa7d30733..de0f06affa 100644
--- a/spec/ruby/core/math/sinh_spec.rb
+++ b/spec/ruby/core/math/sinh_spec.rb
@@ -1,9 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Math.sinh" do
it "returns a float" do
- Math.sinh(1.2).should be_kind_of(Float)
+ Math.sinh(1.2).should.is_a?(Float)
end
it "returns the hyperbolic sin of the argument" do
@@ -14,15 +14,15 @@ describe "Math.sinh" do
end
it "raises a TypeError if the argument cannot be coerced with Float()" do
- lambda { Math.sinh("test") }.should raise_error(TypeError)
+ -> { Math.sinh("test") }.should.raise(TypeError)
end
it "returns NaN given NaN" do
- Math.sinh(nan_value).nan?.should be_true
+ Math.sinh(nan_value).nan?.should == true
end
it "raises a TypeError if the argument is nil" do
- lambda { Math.sinh(nil) }.should raise_error(TypeError)
+ -> { Math.sinh(nil) }.should.raise(TypeError)
end
it "accepts any argument that can be coerced with Float()" do
diff --git a/spec/ruby/core/math/sqrt_spec.rb b/spec/ruby/core/math/sqrt_spec.rb
index 03891b951a..545fa4d1c2 100644
--- a/spec/ruby/core/math/sqrt_spec.rb
+++ b/spec/ruby/core/math/sqrt_spec.rb
@@ -1,9 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Math.sqrt" do
it "returns a float" do
- Math.sqrt(1).should be_kind_of(Float)
+ Math.sqrt(1).should.is_a?(Float)
end
it "returns the square root of the argument" do
@@ -13,20 +13,24 @@ describe "Math.sqrt" do
end
it "raises a TypeError if the argument cannot be coerced with Float()" do
- lambda { Math.sqrt("test") }.should raise_error(TypeError)
+ -> { Math.sqrt("test") }.should.raise(TypeError)
end
it "returns NaN given NaN" do
- Math.sqrt(nan_value).nan?.should be_true
+ Math.sqrt(nan_value).nan?.should == true
end
it "raises a TypeError if the argument is nil" do
- lambda { Math.sqrt(nil) }.should raise_error(TypeError)
+ -> { Math.sqrt(nil) }.should.raise(TypeError)
end
it "accepts any argument that can be coerced with Float()" do
Math.sqrt(MathSpecs::Float.new).should be_close(1.0, TOLERANCE)
end
+
+ it "raises a Math::DomainError when given a negative number" do
+ -> { Math.sqrt(-1) }.should.raise(Math::DomainError)
+ end
end
describe "Math#sqrt" do
diff --git a/spec/ruby/core/math/tan_spec.rb b/spec/ruby/core/math/tan_spec.rb
index 0318ef8a14..c3e773f318 100644
--- a/spec/ruby/core/math/tan_spec.rb
+++ b/spec/ruby/core/math/tan_spec.rb
@@ -1,9 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Math.tan" do
it "returns a float" do
- Math.tan(1.35).should be_kind_of(Float)
+ Math.tan(1.35).should.is_a?(Float)
end
it "returns the tangent of the argument" do
@@ -13,21 +13,21 @@ describe "Math.tan" do
Math.tan(-9.65).should be_close(-0.229109052606441, TOLERANCE)
end
- it "returns NaN if called with +-Infinitty" do
- Math.tan(infinity_value).nan?.should == true
- Math.tan(-infinity_value).nan?.should == true
+ it "returns NaN if called with +-Infinity" do
+ Math.tan(infinity_value).should.nan?
+ Math.tan(-infinity_value).should.nan?
end
it "raises a TypeError if the argument cannot be coerced with Float()" do
- lambda { Math.tan("test") }.should raise_error(TypeError)
+ -> { Math.tan("test") }.should.raise(TypeError)
end
it "returns NaN given NaN" do
- Math.tan(nan_value).nan?.should be_true
+ Math.tan(nan_value).nan?.should == true
end
it "raises a TypeError if the argument is nil" do
- lambda { Math.tan(nil) }.should raise_error(TypeError)
+ -> { Math.tan(nil) }.should.raise(TypeError)
end
it "accepts any argument that can be coerced with Float()" do
diff --git a/spec/ruby/core/math/tanh_spec.rb b/spec/ruby/core/math/tanh_spec.rb
index 8f39dc948b..74a938ffd8 100644
--- a/spec/ruby/core/math/tanh_spec.rb
+++ b/spec/ruby/core/math/tanh_spec.rb
@@ -1,9 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Math.tanh" do
it "returns a float" do
- Math.tanh(0.5).should be_kind_of(Float)
+ Math.tanh(0.5).should.is_a?(Float)
end
it "returns the hyperbolic tangent of the argument" do
@@ -16,15 +16,15 @@ describe "Math.tanh" do
end
it "raises a TypeError if the argument cannot be coerced with Float()" do
- lambda { Math.tanh("test") }.should raise_error(TypeError)
+ -> { Math.tanh("test") }.should.raise(TypeError)
end
it "returns NaN given NaN" do
- Math.tanh(nan_value).nan?.should be_true
+ Math.tanh(nan_value).nan?.should == true
end
it "raises a TypeError if the argument is nil" do
- lambda { Math.tanh(nil) }.should raise_error(TypeError)
+ -> { Math.tanh(nil) }.should.raise(TypeError)
end
it "accepts any argument that can be coerced with Float()" do
diff --git a/spec/ruby/core/method/arity_spec.rb b/spec/ruby/core/method/arity_spec.rb
index 32a50a0999..4bb821735a 100644
--- a/spec/ruby/core/method/arity_spec.rb
+++ b/spec/ruby/core/method/arity_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Method#arity" do
SpecEvaluate.desc = "for method definition"
diff --git a/spec/ruby/core/method/call_spec.rb b/spec/ruby/core/method/call_spec.rb
index 1a90028176..cb11545e91 100644
--- a/spec/ruby/core/method/call_spec.rb
+++ b/spec/ruby/core/method/call_spec.rb
@@ -1,7 +1,54 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/call', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Method#call" do
- it_behaves_like(:method_call, :call)
+ it "invokes the method with the specified arguments, returning the method's return value" do
+ m = 12.method("+")
+ m.call(3).should == 15
+ m.call(20).should == 32
+
+ m = MethodSpecs::Methods.new.method(:attr=)
+ m.call(42).should == 42
+ end
+
+ it "raises an ArgumentError when given incorrect number of arguments" do
+ -> {
+ MethodSpecs::Methods.new.method(:two_req).call(1, 2, 3)
+ }.should.raise(ArgumentError)
+ -> {
+ MethodSpecs::Methods.new.method(:two_req).call(1)
+ }.should.raise(ArgumentError)
+ end
+
+ describe "for a Method generated by respond_to_missing?" do
+ it "invokes method_missing with the specified arguments and returns the result" do
+ @m = MethodSpecs::Methods.new
+ meth = @m.method(:handled_via_method_missing)
+ meth.call(:argument).should == [:argument]
+ end
+
+ it "invokes method_missing with the method name and the specified arguments" do
+ @m = MethodSpecs::Methods.new
+ meth = @m.method(:handled_via_method_missing)
+
+ @m.should_receive(:method_missing).with(:handled_via_method_missing, :argument)
+ meth.call(:argument)
+ end
+
+ it "invokes method_missing dynamically" do
+ @m = MethodSpecs::Methods.new
+ meth = @m.method(:handled_via_method_missing)
+
+ def @m.method_missing(*); :changed; end
+ meth.call(:argument).should == :changed
+ end
+
+ it "does not call the original method name even if it now exists" do
+ @m = MethodSpecs::Methods.new
+ meth = @m.method(:handled_via_method_missing)
+
+ def @m.handled_via_method_missing(*); :not_called; end
+ meth.call(:argument).should == [:argument]
+ end
+ end
end
diff --git a/spec/ruby/core/method/case_compare_spec.rb b/spec/ruby/core/method/case_compare_spec.rb
new file mode 100644
index 0000000000..771fea1ce5
--- /dev/null
+++ b/spec/ruby/core/method/case_compare_spec.rb
@@ -0,0 +1,7 @@
+require_relative '../../spec_helper'
+
+describe "Method#===" do
+ it "is an alias of Method#call" do
+ Method.instance_method(:===).should == Method.instance_method(:call)
+ end
+end
diff --git a/spec/ruby/core/method/clone_spec.rb b/spec/ruby/core/method/clone_spec.rb
index e3b40254f8..b0eb5751a9 100644
--- a/spec/ruby/core/method/clone_spec.rb
+++ b/spec/ruby/core/method/clone_spec.rb
@@ -1,14 +1,13 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/dup'
describe "Method#clone" do
- it "returns a copy of the method" do
- m1 = MethodSpecs::Methods.new.method(:foo)
- m2 = m1.clone
+ it_behaves_like :method_dup, :clone
- m1.should == m2
- m1.should_not equal(m2)
-
- m1.call.should == m2.call
+ it "preserves frozen status" do
+ method = Object.new.method(:method)
+ method.freeze
+ method.frozen?.should == true
+ method.clone.frozen?.should == true
end
end
diff --git a/spec/ruby/core/method/compose_spec.rb b/spec/ruby/core/method/compose_spec.rb
new file mode 100644
index 0000000000..7506e33ea8
--- /dev/null
+++ b/spec/ruby/core/method/compose_spec.rb
@@ -0,0 +1,99 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative '../proc/shared/compose'
+
+describe "Method#<<" do
+ it "returns a Proc that is the composition of self and the passed Proc" do
+ succ = MethodSpecs::Composition.new.method(:succ)
+ upcase = proc { |s| s.upcase }
+
+ (succ << upcase).call('Ruby').should == "RUBZ"
+ end
+
+ it "calls passed Proc with arguments and then calls self with result" do
+ pow_2_proc = proc { |x| x * x }
+ double_proc = proc { |x| x + x }
+
+ pow_2_method = MethodSpecs::Composition.new.method(:pow_2)
+ double_method = MethodSpecs::Composition.new.method(:double)
+
+ (pow_2_method << double_proc).call(2).should == 16
+ (double_method << pow_2_proc).call(2).should == 8
+ end
+
+ it "accepts any callable object" do
+ inc = MethodSpecs::Composition.new.method(:inc)
+
+ double = Object.new
+ def double.call(n); n * 2; end
+
+ (inc << double).call(3).should == 7
+ end
+
+ it_behaves_like :proc_compose, :<<, -> { MethodSpecs::Composition.new.method(:upcase) }
+
+ describe "composition" do
+ it "is a lambda" do
+ pow_2 = MethodSpecs::Composition.new.method(:pow_2)
+ double = proc { |x| x + x }
+
+ (pow_2 << double).is_a?(Proc).should == true
+ (pow_2 << double).should_not.lambda?
+ end
+
+ it "may accept multiple arguments" do
+ inc = MethodSpecs::Composition.new.method(:inc)
+ mul = proc { |n, m| n * m }
+
+ (inc << mul).call(2, 3).should == 7
+ end
+ end
+end
+
+describe "Method#>>" do
+ it "returns a Proc that is the composition of self and the passed Proc" do
+ upcase = proc { |s| s.upcase }
+ succ = MethodSpecs::Composition.new.method(:succ)
+
+ (succ >> upcase).call('Ruby').should == "RUBZ"
+ end
+
+ it "calls passed Proc with arguments and then calls self with result" do
+ pow_2_proc = proc { |x| x * x }
+ double_proc = proc { |x| x + x }
+
+ pow_2_method = MethodSpecs::Composition.new.method(:pow_2)
+ double_method = MethodSpecs::Composition.new.method(:double)
+
+ (pow_2_method >> double_proc).call(2).should == 8
+ (double_method >> pow_2_proc).call(2).should == 16
+ end
+
+ it "accepts any callable object" do
+ inc = MethodSpecs::Composition.new.method(:inc)
+
+ double = Object.new
+ def double.call(n); n * 2; end
+
+ (inc >> double).call(3).should == 8
+ end
+
+ it_behaves_like :proc_compose, :>>, -> { MethodSpecs::Composition.new.method(:upcase) }
+
+ describe "composition" do
+ it "is a lambda" do
+ pow_2 = MethodSpecs::Composition.new.method(:pow_2)
+ double = proc { |x| x + x }
+
+ (pow_2 >> double).is_a?(Proc).should == true
+ (pow_2 >> double).should.lambda?
+ end
+
+ it "may accept multiple arguments" do
+ mul = MethodSpecs::Composition.new.method(:mul)
+ inc = proc { |n| n + 1 }
+
+ (mul >> inc).call(2, 3).should == 7
+ end
+ end
+end
diff --git a/spec/ruby/core/method/curry_spec.rb b/spec/ruby/core/method/curry_spec.rb
index 977f7766d0..79c5d7c662 100644
--- a/spec/ruby/core/method/curry_spec.rb
+++ b/spec/ruby/core/method/curry_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Method#curry" do
it "returns a curried proc" do
@@ -7,7 +7,7 @@ describe "Method#curry" do
def x.foo(a,b,c); [a,b,c]; end
c = x.method(:foo).curry
- c.should be_kind_of(Proc)
+ c.should.is_a?(Proc)
c.call(1).call(2, 3).should == [1,2,3]
end
@@ -17,20 +17,20 @@ describe "Method#curry" do
end
it "returns a curried proc when given correct arity" do
- @obj.method(:one_req).curry(1).should be_kind_of(Proc)
- @obj.method(:zero_with_splat).curry(100).should be_kind_of(Proc)
- @obj.method(:two_req_with_splat).curry(2).should be_kind_of(Proc)
+ @obj.method(:one_req).curry(1).should.is_a?(Proc)
+ @obj.method(:zero_with_splat).curry(100).should.is_a?(Proc)
+ @obj.method(:two_req_with_splat).curry(2).should.is_a?(Proc)
end
it "raises ArgumentError when the method requires less arguments than the given arity" do
- lambda { @obj.method(:zero).curry(1) }.should raise_error(ArgumentError)
- lambda { @obj.method(:one_req_one_opt).curry(3) }.should raise_error(ArgumentError)
- lambda { @obj.method(:two_req_one_opt_with_block).curry(4) }.should raise_error(ArgumentError)
+ -> { @obj.method(:zero).curry(1) }.should.raise(ArgumentError)
+ -> { @obj.method(:one_req_one_opt).curry(3) }.should.raise(ArgumentError)
+ -> { @obj.method(:two_req_one_opt_with_block).curry(4) }.should.raise(ArgumentError)
end
it "raises ArgumentError when the method requires more arguments than the given arity" do
- lambda { @obj.method(:two_req_with_splat).curry(1) }.should raise_error(ArgumentError)
- lambda { @obj.method(:one_req).curry(0) }.should raise_error(ArgumentError)
+ -> { @obj.method(:two_req_with_splat).curry(1) }.should.raise(ArgumentError)
+ -> { @obj.method(:one_req).curry(0) }.should.raise(ArgumentError)
end
end
end
diff --git a/spec/ruby/core/method/dup_spec.rb b/spec/ruby/core/method/dup_spec.rb
new file mode 100644
index 0000000000..e3e29d8a68
--- /dev/null
+++ b/spec/ruby/core/method/dup_spec.rb
@@ -0,0 +1,15 @@
+require_relative '../../spec_helper'
+require_relative 'shared/dup'
+
+describe "Method#dup" do
+ ruby_version_is "3.4" do
+ it_behaves_like :method_dup, :dup
+
+ it "resets frozen status" do
+ method = Object.new.method(:method)
+ method.freeze
+ method.frozen?.should == true
+ method.dup.frozen?.should == false
+ end
+ end
+end
diff --git a/spec/ruby/core/method/element_reference_spec.rb b/spec/ruby/core/method/element_reference_spec.rb
index 0be47afede..65c13cf32b 100644
--- a/spec/ruby/core/method/element_reference_spec.rb
+++ b/spec/ruby/core/method/element_reference_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/call', __FILE__)
+require_relative '../../spec_helper'
describe "Method#[]" do
- it_behaves_like(:method_call, :[])
+ it "is an alias of Method#call" do
+ Method.instance_method(:[]).should == Method.instance_method(:call)
+ end
end
diff --git a/spec/ruby/core/method/eql_spec.rb b/spec/ruby/core/method/eql_spec.rb
index f8914e1d12..81fd086bd5 100644
--- a/spec/ruby/core/method/eql_spec.rb
+++ b/spec/ruby/core/method/eql_spec.rb
@@ -1,6 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/eql', __FILE__)
+require_relative '../../spec_helper'
describe "Method#eql?" do
- it_behaves_like(:method_equal, :eql?)
+ it "is an alias of Method#==" do
+ Method.instance_method(:eql?).should == Method.instance_method(:==)
+ end
end
diff --git a/spec/ruby/core/method/equal_value_spec.rb b/spec/ruby/core/method/equal_value_spec.rb
index 365e0ac424..ca9ef9f108 100644
--- a/spec/ruby/core/method/equal_value_spec.rb
+++ b/spec/ruby/core/method/equal_value_spec.rb
@@ -1,6 +1,94 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/eql', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Method#==" do
- it_behaves_like(:method_equal, :==)
+ before :each do
+ @m = MethodSpecs::Methods.new
+ @m_foo = @m.method(:foo)
+ @m2 = MethodSpecs::Methods.new
+ @a = MethodSpecs::A.new
+ end
+
+ it "returns true if methods are the same" do
+ m2 = @m.method(:foo)
+
+ (@m_foo == @m_foo).should == true
+ (@m_foo == m2).should == true
+ end
+
+ it "returns true on aliased methods" do
+ m_bar = @m.method(:bar)
+
+ (m_bar == @m_foo).should == true
+ end
+
+ it "returns true if the two core methods are aliases" do
+ s = "hello"
+ a = s.method(:size)
+ b = s.method(:length)
+ (a == b).should == true
+ end
+
+ it "returns false on a method which is neither aliased nor the same method" do
+ m2 = @m.method(:zero)
+
+ (@m_foo == m2).should == false
+ end
+
+ it "returns false for a method which is not bound to the same object" do
+ m2_foo = @m2.method(:foo)
+ a_baz = @a.method(:baz)
+
+ (@m_foo == m2_foo).should == false
+ (@m_foo == a_baz).should == false
+ end
+
+ it "returns false if the two methods are bound to the same object but were defined independently" do
+ m2 = @m.method(:same_as_foo)
+ (@m_foo == m2).should == false
+ end
+
+ it "returns true if a method was defined using the other one" do
+ MethodSpecs::Methods.send :define_method, :defined_foo, MethodSpecs::Methods.instance_method(:foo)
+ m2 = @m.method(:defined_foo)
+ (@m_foo == m2).should == true
+ end
+
+ it "returns false if comparing a method defined via define_method and def" do
+ defn = @m.method(:zero)
+ defined = @m.method(:zero_defined_method)
+
+ (defn == defined).should == false
+ (defined == defn).should == false
+ end
+
+ describe 'missing methods' do
+ it "returns true for the same method missing" do
+ miss1 = @m.method(:handled_via_method_missing)
+ miss1bis = @m.method(:handled_via_method_missing)
+ miss2 = @m.method(:also_handled)
+
+ (miss1 == miss1bis).should == true
+ (miss1 == miss2).should == false
+ end
+
+ it 'calls respond_to_missing? with true to include private methods' do
+ @m.should_receive(:respond_to_missing?).with(:some_missing_method, true).and_return(true)
+ @m.method(:some_missing_method)
+ end
+ end
+
+ it "returns false if the two methods are bound to different objects, have the same names, and identical bodies" do
+ a = MethodSpecs::Eql.instance_method(:same_body)
+ b = MethodSpecs::Eql2.instance_method(:same_body)
+ (a == b).should == false
+ end
+
+ it "returns false if the argument is not a Method object" do
+ (String.instance_method(:size) == 7).should == false
+ end
+
+ it "returns false if the argument is an unbound version of self" do
+ (method(:load) == method(:load).unbind).should == false
+ end
end
diff --git a/spec/ruby/core/method/fixtures/classes.rb b/spec/ruby/core/method/fixtures/classes.rb
index 142cbd1bec..41904df1d1 100644
--- a/spec/ruby/core/method/fixtures/classes.rb
+++ b/spec/ruby/core/method/fixtures/classes.rb
@@ -26,6 +26,8 @@ module MethodSpecs
end
alias bar foo
+ alias baz bar
+ alias qux baz
def same_as_foo
true
@@ -49,6 +51,8 @@ module MethodSpecs
def one_req(a); end
def two_req(a, b); end
+ def one_req_named(a:); end
+
def zero_with_block(&blk); end
def one_req_with_block(a, &blk); end
def two_req_with_block(a, b, &blk); end
@@ -58,6 +62,8 @@ module MethodSpecs
def one_req_two_opt(a, b=nil, c=nil); end
def two_req_one_opt(a, b, c=nil); end
+ def one_opt_named(a: nil); end
+
def one_opt_with_block(a=nil, &blk); end
def one_req_one_opt_with_block(a, b=nil, &blk); end
def one_req_two_opt_with_block(a, b=nil, c=nil, &blk); end
@@ -70,6 +76,8 @@ module MethodSpecs
def two_req_one_opt_with_splat(a, b, c=nil, *d); end
def one_req_two_opt_with_splat(a, b=nil, c=nil, *d); end
+ def zero_with_double_splat(**a); end
+
def zero_with_splat_and_block(*a, &blk); end
def one_req_with_splat_and_block(a, *b, &blk); end
def two_req_with_splat_and_block(a, b, *c, &blk); end
@@ -77,6 +85,12 @@ module MethodSpecs
def two_req_one_opt_with_splat_and_block(a, b, c=nil, *d, &blk); end
def one_req_two_opt_with_splat_and_block(a, b=nil, c=nil, *d, &blk); end
+ def my_public_method; end
+ def my_protected_method; end
+ def my_private_method; end
+ protected :my_protected_method
+ private :my_private_method
+
define_method(:zero_defined_method, Proc.new {||})
define_method(:zero_with_splat_defined_method, Proc.new {|*x|})
define_method(:one_req_defined_method, Proc.new {|x|})
@@ -181,4 +195,53 @@ module MethodSpecs
end
end
+ class Composition
+ def upcase(s)
+ s.upcase
+ end
+
+ def succ(s)
+ s.succ
+ end
+
+ def pow_2(n)
+ n * n
+ end
+
+ def double(n)
+ n + n
+ end
+
+ def inc(n)
+ n + 1
+ end
+
+ def mul(n, m)
+ n * m
+ end
+ end
+
+ module InheritedMethods
+ module A
+ private
+ def derp(message)
+ 'A'
+ end
+ end
+
+ module B
+ private
+ def derp
+ 'B' + super('superclass')
+ end
+ end
+
+ class C
+ include A
+ include B
+
+ public :derp
+ alias_method :meow, :derp
+ end
+ end
end
diff --git a/spec/ruby/core/method/hash_spec.rb b/spec/ruby/core/method/hash_spec.rb
index 67bc4c16ac..d6c8440acc 100644
--- a/spec/ruby/core/method/hash_spec.rb
+++ b/spec/ruby/core/method/hash_spec.rb
@@ -1,9 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Method#hash" do
- it "needs to be reviewed for spec completeness"
-
it "returns the same value for user methods that are eql?" do
obj = MethodSpecs::Methods.new
obj.method(:foo).hash.should == obj.method(:bar).hash
diff --git a/spec/ruby/core/method/inspect_spec.rb b/spec/ruby/core/method/inspect_spec.rb
index bfb61daf53..5eb8850ff3 100644
--- a/spec/ruby/core/method/inspect_spec.rb
+++ b/spec/ruby/core/method/inspect_spec.rb
@@ -1,6 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/to_s', __FILE__)
+require_relative '../../spec_helper'
describe "Method#inspect" do
- it_behaves_like(:method_to_s, :inspect)
+ it "is an alias of Method#to_s" do
+ Method.instance_method(:inspect).should == Method.instance_method(:to_s)
+ end
end
diff --git a/spec/ruby/core/method/name_spec.rb b/spec/ruby/core/method/name_spec.rb
index ebc5f856d1..de390c6f52 100644
--- a/spec/ruby/core/method/name_spec.rb
+++ b/spec/ruby/core/method/name_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Method#name" do
it "returns the name of the method" do
diff --git a/spec/ruby/core/method/original_name_spec.rb b/spec/ruby/core/method/original_name_spec.rb
new file mode 100644
index 0000000000..b92cf35154
--- /dev/null
+++ b/spec/ruby/core/method/original_name_spec.rb
@@ -0,0 +1,59 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe "Method#original_name" do
+ it "returns the name of the method" do
+ "abc".method(:upcase).original_name.should == :upcase
+ end
+
+ it "returns the original name when aliased" do
+ obj = MethodSpecs::Methods.new
+ obj.method(:foo).original_name.should == :foo
+ obj.method(:bar).original_name.should == :foo
+ obj.method(:bar).unbind.bind(obj).original_name.should == :foo
+ end
+
+ it "returns the original name even when aliased twice" do
+ obj = MethodSpecs::Methods.new
+ obj.method(:foo).original_name.should == :foo
+ obj.method(:baz).original_name.should == :foo
+ obj.method(:baz).unbind.bind(obj).original_name.should == :foo
+ end
+
+ it "returns the original name even when aliased thrice" do
+ obj = MethodSpecs::Methods.new
+ obj.method(:qux).original_name.should == :foo
+ obj.method(:qux).unbind.bind(obj).original_name.should == :foo
+ end
+
+ it "returns the source UnboundMethod's name (not the name given to define_method)" do
+ klass = Class.new { define_method(:my_inspect, ::Kernel.instance_method(:inspect)) }
+ klass.new.method(:my_inspect).original_name.should == :inspect
+ end
+
+ it "preserves the source method's name through define_method and alias" do
+ source = Class.new { def my_method; end }
+ klass = Class.new(source) do
+ define_method(:renamed, source.instance_method(:my_method))
+ alias aliased renamed
+ end
+ klass.new.method(:renamed).original_name.should == :my_method
+ klass.new.method(:aliased).original_name.should == :my_method
+ end
+
+ it "returns the source UnboundMethod's name for Kernel#is_a? and Kernel#kind_of?" do
+ klass = Class.new { define_method(:my_is_a?, ::Kernel.instance_method(:is_a?)) }
+ klass.new.method(:my_is_a?).original_name.should == :is_a?
+
+ klass = Class.new { define_method(:my_kind_of?, ::Kernel.instance_method(:kind_of?)) }
+ klass.new.method(:my_kind_of?).original_name.should == :kind_of?
+ end
+
+ it "preserves the source name when aliasing a define_method'd Kernel method" do
+ klass = Class.new do
+ define_method(:my_is_a?, ::Kernel.instance_method(:is_a?))
+ alias_method :renamed_is_a?, :my_is_a?
+ end
+ klass.new.method(:renamed_is_a?).original_name.should == :is_a?
+ end
+end
diff --git a/spec/ruby/core/method/owner_spec.rb b/spec/ruby/core/method/owner_spec.rb
index 3378b7bd1f..1cdc4edfa7 100644
--- a/spec/ruby/core/method/owner_spec.rb
+++ b/spec/ruby/core/method/owner_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Method#owner" do
it "returns the owner of the method" do
@@ -23,4 +23,8 @@ describe "Method#owner" do
@m.method(:handled_via_method_missing).owner.should == MethodSpecs::Methods
end
end
+
+ it "returns the class on which public was called for a private method in ancestor" do
+ MethodSpecs::InheritedMethods::C.new.method(:derp).owner.should == MethodSpecs::InheritedMethods::C
+ end
end
diff --git a/spec/ruby/core/method/parameters_spec.rb b/spec/ruby/core/method/parameters_spec.rb
index 8808bf40b4..fd88e8dcb8 100644
--- a/spec/ruby/core/method/parameters_spec.rb
+++ b/spec/ruby/core/method/parameters_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Method#parameters" do
class MethodSpecs::Methods
@@ -7,19 +7,31 @@ describe "Method#parameters" do
def one_keyrest(**a); end
def one_keyreq(a:); end
+ def one_nokey(**nil); end
def one_splat_one_req(*a,b); end
def one_splat_two_req(*a,b,c); end
def one_splat_one_req_with_block(*a,b,&blk); end
- def one_opt_with_stabby(a=->(b){true}); end
+ def one_opt_with_stabby(a=-> b { true }); end
def one_unnamed_splat(*); end
+ def one_unnamed_keyrest(**); end
def one_splat_one_block(*args, &block)
local_is_not_parameter = {}
end
+ ruby_version_is "4.1" do
+ eval <<-RUBY
+ def one_noblock(&nil); end
+ RUBY
+ end
+
+ def forward_parameters(...) end
+
+ def underscore_parameters(_, _, _ = 1, *_, _:, _: 2, **_, &_); end
+
define_method(:one_optional_defined_method) {|x = 1|}
end
@@ -176,6 +188,18 @@ describe "Method#parameters" do
m.parameters.should == [[:keyreq,:a]]
end
+ it "returns [[:nokey]] for a method with a single **nil parameter" do
+ m = MethodSpecs::Methods.instance_method(:one_nokey)
+ m.parameters.should == [[:nokey]]
+ end
+
+ ruby_version_is "4.1" do
+ it "returns [[:noblock]] for a method with a single &nil parameter" do
+ m = MethodSpecs::Methods.instance_method(:one_noblock)
+ m.parameters.should == [[:noblock]]
+ end
+ end
+
it "works with ->(){} as the value of an optional argument" do
m = MethodSpecs::Methods.instance_method(:one_opt_with_stabby)
m.parameters.should == [[:opt,:a]]
@@ -222,9 +246,27 @@ describe "Method#parameters" do
m.method(:handled_via_method_missing).parameters.should == [[:rest]]
end
- it "adds nameless rest arg for \"star\" argument" do
+ it "adds rest arg with name * for \"star\" argument" do
m = MethodSpecs::Methods.new
- m.method(:one_unnamed_splat).parameters.should == [[:rest]]
+ m.method(:one_unnamed_splat).parameters.should == [[:rest, :*]]
+ end
+
+ it "adds keyrest arg with ** as a name for \"double star\" argument" do
+ m = MethodSpecs::Methods.new
+ m.method(:one_unnamed_keyrest).parameters.should == [[:keyrest, :**]]
+ end
+
+ it "adds block arg with name & for anonymous block argument" do
+ object = Object.new
+ def object.foo(&)
+ end
+
+ object.method(:foo).parameters.should == [[:block, :&]]
+ end
+
+ it "returns [:rest, :*], [:keyrest, :**], [:block, :&] for forward parameters operator" do
+ m = MethodSpecs::Methods.new
+ m.method(:forward_parameters).parameters.should == [[:rest, :*], [:keyrest, :**], [:block, :&]]
end
it "returns the args and block for a splat and block argument" do
@@ -241,4 +283,35 @@ describe "Method#parameters" do
m = MethodSpecs::Methods.new
m.method(:writer=).parameters.should == [[:req]]
end
+
+ it "returns all parameters defined with the name _ as _" do
+ m = MethodSpecs::Methods.instance_method(:underscore_parameters)
+ m.parameters.should == [
+ [:req, :_],
+ [:req, :_],
+ [:opt, :_],
+ [:rest, :_],
+ [:keyreq, :_],
+ [:key, :_],
+ [:keyrest, :_],
+ [:block, :_]
+ ]
+ end
+
+ it "returns [[:rest]] for core methods with variable-length argument lists" do
+ # delete! takes rest args
+ "foo".method(:delete!).parameters.should == [[:rest]]
+ end
+
+ it "returns [[:rest]] or [[:opt]] for core methods with optional arguments" do
+ # pop takes 1 optional argument
+ [
+ [[:rest]],
+ [[:opt]]
+ ].should.include?([].method(:pop).parameters)
+ end
+
+ it "returns [[:req]] for each parameter for core methods with fixed-length argument lists" do
+ "foo".method(:+).parameters.should == [[:req]]
+ end
end
diff --git a/spec/ruby/core/method/private_spec.rb b/spec/ruby/core/method/private_spec.rb
new file mode 100644
index 0000000000..e708542b2e
--- /dev/null
+++ b/spec/ruby/core/method/private_spec.rb
@@ -0,0 +1,9 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe "Method#private?" do
+ it "has been removed" do
+ obj = MethodSpecs::Methods.new
+ obj.method(:my_private_method).should_not.respond_to?(:private?)
+ end
+end
diff --git a/spec/ruby/core/method/protected_spec.rb b/spec/ruby/core/method/protected_spec.rb
new file mode 100644
index 0000000000..f9e422ae3d
--- /dev/null
+++ b/spec/ruby/core/method/protected_spec.rb
@@ -0,0 +1,9 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe "Method#protected?" do
+ it "has been removed" do
+ obj = MethodSpecs::Methods.new
+ obj.method(:my_protected_method).should_not.respond_to?(:protected?)
+ end
+end
diff --git a/spec/ruby/core/method/public_spec.rb b/spec/ruby/core/method/public_spec.rb
new file mode 100644
index 0000000000..4cb23f4cf1
--- /dev/null
+++ b/spec/ruby/core/method/public_spec.rb
@@ -0,0 +1,9 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe "Method#public?" do
+ it "has been removed" do
+ obj = MethodSpecs::Methods.new
+ obj.method(:my_public_method).should_not.respond_to?(:public?)
+ end
+end
diff --git a/spec/ruby/core/method/receiver_spec.rb b/spec/ruby/core/method/receiver_spec.rb
index 2c56ab2239..315a08d288 100644
--- a/spec/ruby/core/method/receiver_spec.rb
+++ b/spec/ruby/core/method/receiver_spec.rb
@@ -1,22 +1,22 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Method#receiver" do
it "returns the receiver of the method" do
s = "abc"
- s.method(:upcase).receiver.should equal(s)
+ s.method(:upcase).receiver.should.equal?(s)
end
it "returns the right receiver even when aliased" do
obj = MethodSpecs::Methods.new
- obj.method(:foo).receiver.should equal(obj)
- obj.method(:bar).receiver.should equal(obj)
+ obj.method(:foo).receiver.should.equal?(obj)
+ obj.method(:bar).receiver.should.equal?(obj)
end
describe "for a Method generated by respond_to_missing?" do
it "returns the receiver of the method" do
m = MethodSpecs::Methods.new
- m.method(:handled_via_method_missing).receiver.should equal(m)
+ m.method(:handled_via_method_missing).receiver.should.equal?(m)
end
end
end
diff --git a/spec/ruby/core/method/shared/aliased_inspect.rb b/spec/ruby/core/method/shared/aliased_inspect.rb
new file mode 100644
index 0000000000..2a622c2f97
--- /dev/null
+++ b/spec/ruby/core/method/shared/aliased_inspect.rb
@@ -0,0 +1,31 @@
+describe :method_to_s_aliased, shared: true do
+ # @object converts a bound Method to either a Method (identity) or an
+ # UnboundMethod (-> meth { meth.unbind }), so these expectations cover both
+ # Method#to_s/#inspect and UnboundMethod#to_s/#inspect.
+
+ it "shows the original name in parentheses for an aliased method" do
+ klass = Class.new do
+ def original_method; end
+ alias_method :renamed_method, :original_method
+ end
+ @object.call(klass.new.method(:renamed_method)).send(@method).should.include? '#renamed_method(original_method)'
+ end
+
+ it "shows the source UnboundMethod's name in parentheses for a define_method'd method" do
+ klass = Class.new { define_method(:renamed_is_a?, ::Kernel.instance_method(:is_a?)) }
+ @object.call(klass.new.method(:renamed_is_a?)).send(@method).should.include? '#renamed_is_a?(is_a?)'
+ end
+
+ it "does not annotate a directly looked-up Kernel method with a shared internal name" do
+ @object.call(Object.new.method(:is_a?)).send(@method).should_not.include? '(kind_of?)'
+ @object.call(Object.new.method(:kind_of?)).send(@method).should_not.include? '(is_a?)'
+ end
+
+ it "shows the source name when aliasing a define_method'd Kernel method" do
+ klass = Class.new do
+ define_method(:my_is_a?, ::Kernel.instance_method(:is_a?))
+ alias_method :renamed_is_a?, :my_is_a?
+ end
+ @object.call(klass.new.method(:renamed_is_a?)).send(@method).should.include? '#renamed_is_a?(is_a?)'
+ end
+end
diff --git a/spec/ruby/core/method/shared/call.rb b/spec/ruby/core/method/shared/call.rb
deleted file mode 100644
index f178b9da7d..0000000000
--- a/spec/ruby/core/method/shared/call.rb
+++ /dev/null
@@ -1,51 +0,0 @@
-describe :method_call, shared: true do
- it "invokes the method with the specified arguments, returning the method's return value" do
- m = 12.method("+")
- m.send(@method, 3).should == 15
- m.send(@method, 20).should == 32
-
- m = MethodSpecs::Methods.new.method(:attr=)
- m.send(@method, 42).should == 42
- end
-
- it "raises an ArgumentError when given incorrect number of arguments" do
- lambda {
- MethodSpecs::Methods.new.method(:two_req).send(@method, 1, 2, 3)
- }.should raise_error(ArgumentError)
- lambda {
- MethodSpecs::Methods.new.method(:two_req).send(@method, 1)
- }.should raise_error(ArgumentError)
- end
-
- describe "for a Method generated by respond_to_missing?" do
- it "invokes method_missing with the specified arguments and returns the result" do
- @m = MethodSpecs::Methods.new
- meth = @m.method(:handled_via_method_missing)
- meth.send(@method, :argument).should == [:argument]
- end
-
- it "invokes method_missing with the method name and the specified arguments" do
- @m = MethodSpecs::Methods.new
- meth = @m.method(:handled_via_method_missing)
-
- @m.should_receive(:method_missing).with(:handled_via_method_missing, :argument)
- meth.send(@method, :argument)
- end
-
- it "invokes method_missing dynamically" do
- @m = MethodSpecs::Methods.new
- meth = @m.method(:handled_via_method_missing)
-
- def @m.method_missing(*); :changed; end
- meth.send(@method, :argument).should == :changed
- end
-
- it "does not call the original method name even if it now exists" do
- @m = MethodSpecs::Methods.new
- meth = @m.method(:handled_via_method_missing)
-
- def @m.handled_via_method_missing(*); :not_called; end
- meth.send(@method, :argument).should == [:argument]
- end
- end
-end
diff --git a/spec/ruby/core/method/shared/dup.rb b/spec/ruby/core/method/shared/dup.rb
new file mode 100644
index 0000000000..eee790890a
--- /dev/null
+++ b/spec/ruby/core/method/shared/dup.rb
@@ -0,0 +1,32 @@
+describe :method_dup, shared: true do
+ it "returns a copy of self" do
+ a = Object.new.method(:method)
+ b = a.send(@method)
+
+ a.should == b
+ a.should_not.equal?(b)
+ end
+
+ ruby_version_is "3.4" do
+ it "copies instance variables" do
+ method = Object.new.method(:method)
+ method.instance_variable_set(:@ivar, 1)
+ cl = method.send(@method)
+ cl.instance_variables.should == [:@ivar]
+ end
+
+ it "copies the finalizer" do
+ code = <<-'RUBY'
+ obj = Object.new.method(:method)
+
+ ObjectSpace.define_finalizer(obj, Proc.new { STDOUT.write "finalized\n" })
+
+ obj.clone
+
+ exit 0
+ RUBY
+
+ ruby_exe(code).lines.sort.should == ["finalized\n", "finalized\n"]
+ end
+ end
+end
diff --git a/spec/ruby/core/method/shared/eql.rb b/spec/ruby/core/method/shared/eql.rb
deleted file mode 100644
index 8cff45760b..0000000000
--- a/spec/ruby/core/method/shared/eql.rb
+++ /dev/null
@@ -1,94 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
-
-describe :method_equal, shared: true do
- before :each do
- @m = MethodSpecs::Methods.new
- @m_foo = @m.method(:foo)
- @m2 = MethodSpecs::Methods.new
- @a = MethodSpecs::A.new
- end
-
- it "returns true if methods are the same" do
- m2 = @m.method(:foo)
-
- @m_foo.send(@method, @m_foo).should be_true
- @m_foo.send(@method, m2).should be_true
- end
-
- it "returns true on aliased methods" do
- m_bar = @m.method(:bar)
-
- m_bar.send(@method, @m_foo).should be_true
- end
-
- it "returns true if the two core methods are aliases" do
- s = "hello"
- a = s.method(:size)
- b = s.method(:length)
- a.send(@method, b).should be_true
- end
-
- it "returns false on a method which is neither aliased nor the same method" do
- m2 = @m.method(:zero)
-
- @m_foo.send(@method, m2).should be_false
- end
-
- it "returns false for a method which is not bound to the same object" do
- m2_foo = @m2.method(:foo)
- a_baz = @a.method(:baz)
-
- @m_foo.send(@method, m2_foo).should be_false
- @m_foo.send(@method, a_baz).should be_false
- end
-
- it "returns false if the two methods are bound to the same object but were defined independently" do
- m2 = @m.method(:same_as_foo)
- @m_foo.send(@method, m2).should be_false
- end
-
- it "returns true if a method was defined using the other one" do
- MethodSpecs::Methods.send :define_method, :defined_foo, MethodSpecs::Methods.instance_method(:foo)
- m2 = @m.method(:defined_foo)
- @m_foo.send(@method, m2).should be_true
- end
-
- it "returns false if comparing a method defined via define_method and def" do
- defn = @m.method(:zero)
- defined = @m.method(:zero_defined_method)
-
- defn.send(@method, defined).should be_false
- defined.send(@method, defn).should be_false
- end
-
- describe 'missing methods' do
- it "returns true for the same method missing" do
- miss1 = @m.method(:handled_via_method_missing)
- miss1bis = @m.method(:handled_via_method_missing)
- miss2 = @m.method(:also_handled)
-
- miss1.send(@method, miss1bis).should be_true
- miss1.send(@method, miss2).should be_false
- end
-
- it 'calls respond_to_missing? with true to include private methods' do
- @m.should_receive(:respond_to_missing?).with(:some_missing_method, true).and_return(true)
- @m.method(:some_missing_method)
- end
- end
-
- it "returns false if the two methods are bound to different objects, have the same names, and identical bodies" do
- a = MethodSpecs::Eql.instance_method(:same_body)
- b = MethodSpecs::Eql2.instance_method(:same_body)
- a.send(@method, b).should be_false
- end
-
- it "returns false if the argument is not a Method object" do
- String.instance_method(:size).send(@method, 7).should be_false
- end
-
- it "returns false if the argument is an unbound version of self" do
- method(:load).send(@method, method(:load).unbind).should be_false
- end
-end
diff --git a/spec/ruby/core/method/shared/to_s.rb b/spec/ruby/core/method/shared/to_s.rb
index 239974c8e3..bfb58e6896 100644
--- a/spec/ruby/core/method/shared/to_s.rb
+++ b/spec/ruby/core/method/shared/to_s.rb
@@ -1,19 +1,19 @@
-require "#{File.dirname __FILE__}/../../../spec_helper"
-require "#{File.dirname __FILE__}/../fixtures/classes"
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
describe :method_to_s, shared: true do
before :each do
@m = MethodSpecs::MySub.new.method :bar
- @string = @m.send(@method).sub(/0x\w+/, '0xXXXXXX')
+ @string = @m.send(@method)
end
it "returns a String" do
- @m.send(@method).should be_kind_of(String)
+ @m.send(@method).should.is_a?(String)
end
it "returns a String for methods defined with attr_accessor" do
m = MethodSpecs::Methods.new.method :attr
- m.send(@method).should be_kind_of(String)
+ m.send(@method).should.is_a?(String)
end
it "returns a String containing 'Method'" do
@@ -24,6 +24,19 @@ describe :method_to_s, shared: true do
@string.should =~ /\#bar/
end
+ it "returns a String containing method arguments" do
+ obj = MethodSpecs::Methods.new
+ obj.method(:zero).send(@method).should.include?("()")
+ obj.method(:one_req).send(@method).should.include?("(a)")
+ obj.method(:one_req_named).send(@method).should.include?("(a:)")
+ obj.method(:zero_with_block).send(@method).should.include?("(&blk)")
+ obj.method(:one_opt).send(@method).should.include?("(a=...)")
+ obj.method(:one_opt_named).send(@method).should.include?("(a: ...)")
+ obj.method(:zero_with_splat).send(@method).should.include?("(*a)")
+ obj.method(:zero_with_double_splat).send(@method).should.include?("(**a)")
+ obj.method(:one_req_one_opt_with_splat_and_block).send(@method).should.include?("(a, b=..., *c, &blk)")
+ end
+
it "returns a String containing the Module the method is defined in" do
@string.should =~ /MethodSpecs::MyMod/
end
@@ -31,4 +44,38 @@ describe :method_to_s, shared: true do
it "returns a String containing the Module the method is referenced from" do
@string.should =~ /MethodSpecs::MySub/
end
+
+ it "returns a String including all details" do
+ @string.should.start_with? "#<Method: MethodSpecs::MySub(MethodSpecs::MyMod)#bar"
+ end
+
+ it "does not show the defining module if it is the same as the receiver class" do
+ MethodSpecs::A.new.method(:baz).send(@method).should.start_with? "#<Method: MethodSpecs::A#baz"
+ end
+
+ it "returns a String containing the Module containing the method if object has a singleton class but method is not defined in the singleton class" do
+ obj = MethodSpecs::MySub.new
+ obj.singleton_class
+ @m = obj.method(:bar)
+ @string = @m.send(@method)
+ @string.should.start_with? "#<Method: MethodSpecs::MySub(MethodSpecs::MyMod)#bar"
+
+ c = MethodSpecs::MySub.dup
+ m = Module.new{def bar; end}
+ c.extend(m)
+ @string = c.method(:bar).send(@method)
+ @string.should.start_with? "#<Method: #<Class:#{c.inspect}>(#{m.inspect})#bar"
+ end
+
+ it "returns a String containing the singleton class if method is defined in the singleton class" do
+ obj = MethodSpecs::MySub.new
+ def obj.bar; end
+ @m = obj.method(:bar)
+ @string = @m.send(@method).sub(/0x\h+/, '0xXXXXXX')
+ @string.should.start_with? "#<Method: #<MethodSpecs::MySub:0xXXXXXX>.bar"
+ end
+
+ it "shows the metaclass and the owner for a Module instance method retrieved from a class" do
+ String.method(:include).inspect.should.start_with?("#<Method: #<Class:String>(Module)#include")
+ end
end
diff --git a/spec/ruby/core/method/source_location_spec.rb b/spec/ruby/core/method/source_location_spec.rb
index 2ba2fdf5e9..22fcb98c74 100644
--- a/spec/ruby/core/method/source_location_spec.rb
+++ b/spec/ruby/core/method/source_location_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Method#source_location" do
before :each do
@@ -7,18 +7,18 @@ describe "Method#source_location" do
end
it "returns an Array" do
- @method.source_location.should be_an_instance_of(Array)
+ @method.source_location.should.instance_of?(Array)
end
it "sets the first value to the path of the file in which the method was defined" do
file = @method.source_location.first
- file.should be_an_instance_of(String)
- file.should == File.dirname(__FILE__) + '/fixtures/classes.rb'
+ file.should.instance_of?(String)
+ file.should == File.realpath('fixtures/classes.rb', __dir__)
end
- it "sets the last value to a Fixnum representing the line on which the method was defined" do
+ it "sets the last value to an Integer representing the line on which the method was defined" do
line = @method.source_location.last
- line.should be_an_instance_of(Fixnum)
+ line.should.instance_of?(Integer)
line.should == 5
end
@@ -86,10 +86,35 @@ describe "Method#source_location" do
method.source_location[1].should == line
end
+ it "works for core methods where it returns nil or <internal:" do
+ loc = method(:__id__).source_location
+ if loc == nil
+ loc.should == nil
+ else
+ loc[0].should.start_with?('<internal:')
+ loc[1].should.is_a?(Integer)
+ end
+
+ loc = method(:tap).source_location
+ if loc == nil
+ loc.should == nil
+ else
+ loc[0].should.start_with?('<internal:')
+ loc[1].should.is_a?(Integer)
+ end
+ end
+
+ it "works for eval with a given line" do
+ c = Class.new do
+ eval('def self.m; end', nil, "foo", 100)
+ end
+ c.method(:m).source_location.should == ["foo", 100]
+ end
+
describe "for a Method generated by respond_to_missing?" do
it "returns nil" do
m = MethodSpecs::Methods.new
- m.method(:handled_via_method_missing).source_location.should be_nil
+ m.method(:handled_via_method_missing).source_location.should == nil
end
end
end
diff --git a/spec/ruby/core/method/super_method_spec.rb b/spec/ruby/core/method/super_method_spec.rb
index cbc595b572..c63a7aaa0f 100644
--- a/spec/ruby/core/method/super_method_spec.rb
+++ b/spec/ruby/core/method/super_method_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Method#super_method" do
it "returns the method that would be called by super in the method" do
@@ -42,4 +42,23 @@ describe "Method#super_method" do
method.super_method.should == nil
end
+
+ # https://github.com/jruby/jruby/issues/7240
+ context "after changing an inherited methods visibility" do
+ it "calls the proper super method" do
+ MethodSpecs::InheritedMethods::C.new.derp.should == 'BA'
+ end
+
+ it "returns the expected super_method" do
+ method = MethodSpecs::InheritedMethods::C.new.method(:derp)
+ method.super_method.owner.should == MethodSpecs::InheritedMethods::A
+ end
+ end
+
+ context "after aliasing an inherited method" do
+ it "returns the expected super_method" do
+ method = MethodSpecs::InheritedMethods::C.new.method(:meow)
+ method.super_method.owner.should == MethodSpecs::InheritedMethods::A
+ end
+ end
end
diff --git a/spec/ruby/core/method/to_proc_spec.rb b/spec/ruby/core/method/to_proc_spec.rb
index 5a754f8597..4993cce239 100644
--- a/spec/ruby/core/method/to_proc_spec.rb
+++ b/spec/ruby/core/method/to_proc_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Method#to_proc" do
before :each do
@@ -35,7 +35,7 @@ describe "Method#to_proc" do
end
it "returns a proc that can be used by define_method" do
- x = 'test'
+ x = +'test'
to_s = class << x
define_method :foo, method(:to_s).to_proc
to_s
@@ -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
@@ -86,4 +90,15 @@ describe "Method#to_proc" do
array.each(&obj)
ScratchPad.recorded.should == [[1, 2]]
end
+
+ it "returns a proc that properly invokes module methods with super" do
+ m1 = Module.new { def foo(ary); ary << :m1; end; }
+ m2 = Module.new { def foo(ary = []); super(ary); ary << :m2; end; }
+ c2 = Class.new do
+ include m1
+ include m2
+ end
+
+ c2.new.method(:foo).to_proc.call.should == %i[m1 m2]
+ end
end
diff --git a/spec/ruby/core/method/to_s_spec.rb b/spec/ruby/core/method/to_s_spec.rb
index 1bf341f2a6..ba0b4fa3c6 100644
--- a/spec/ruby/core/method/to_s_spec.rb
+++ b/spec/ruby/core/method/to_s_spec.rb
@@ -1,6 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/to_s', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/to_s'
+require_relative 'shared/aliased_inspect'
describe "Method#to_s" do
- it_behaves_like(:method_to_s, :to_s)
+ it_behaves_like :method_to_s, :to_s
+ it_behaves_like :method_to_s_aliased, :to_s, -> meth { meth }
end
diff --git a/spec/ruby/core/method/unbind_spec.rb b/spec/ruby/core/method/unbind_spec.rb
index cb0dc65a75..994c3a8879 100644
--- a/spec/ruby/core/method/unbind_spec.rb
+++ b/spec/ruby/core/method/unbind_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Method#unbind" do
before :each do
@@ -11,23 +11,32 @@ describe "Method#unbind" do
end
it "returns an UnboundMethod" do
- @normal_um.should be_kind_of(UnboundMethod)
+ @normal_um.should.is_a?(UnboundMethod)
end
- it "returns a String containing 'UnboundMethod'" do
- @string.should =~ /\bUnboundMethod\b/
- end
+ describe "#inspect" do
+ it "returns a String containing 'UnboundMethod'" do
+ @string.should =~ /\bUnboundMethod\b/
+ end
- it "returns a String containing the method name" do
- @string.should =~ /\#bar/
- end
+ it "returns a String containing the method name" do
+ @string.should =~ /\#bar/
+ end
+
+ it "returns a String containing the Module the method is defined in" do
+ @string.should =~ /MethodSpecs::MyMod/
+ end
- it "returns a String containing the Module the method is defined in" do
- @string.should =~ /MethodSpecs::MyMod/
+ it "returns a String containing the Module the method is referenced from" do
+ @string.should =~ /MethodSpecs::MyMod/
+ end
end
- it "returns a String containing the Module the method is referenced from" do
- @string.should =~ /MethodSpecs::MySub/
+ it "keeps the origin singleton class if there is one" do
+ obj = Object.new
+ def obj.foo
+ end
+ obj.method(:foo).unbind.inspect.should.start_with?("#<UnboundMethod: #{obj.singleton_class}#foo")
end
specify "rebinding UnboundMethod to Method's obj produces exactly equivalent Methods" do
diff --git a/spec/ruby/core/module/alias_method_spec.rb b/spec/ruby/core/module/alias_method_spec.rb
index 7ad71f41f9..852879cc8a 100644
--- a/spec/ruby/core/module/alias_method_spec.rb
+++ b/spec/ruby/core/module/alias_method_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Module#alias_method" do
before :each do
@@ -14,7 +14,7 @@ describe "Module#alias_method" do
@object.double(12).should == @object.public_two(12)
end
- it "creates methods that are == to eachother" do
+ it "creates methods that are == to each other" do
@class.make_alias :uno, :public_one
@object.method(:uno).should == @object.method(:public_one)
end
@@ -28,12 +28,12 @@ describe "Module#alias_method" do
it "retains method visibility" do
@class.make_alias :private_ichi, :private_one
- lambda { @object.private_one }.should raise_error(NameError)
- lambda { @object.private_ichi }.should raise_error(NameError)
+ -> { @object.private_one }.should.raise(NameError)
+ -> { @object.private_ichi }.should.raise(NameError)
@class.make_alias :public_ichi, :public_one
@object.public_ichi.should == @object.public_one
@class.make_alias :protected_ichi, :protected_one
- lambda { @object.protected_ichi }.should raise_error(NameError)
+ -> { @object.protected_ichi }.should.raise(NameError)
end
it "handles aliasing a stub that changes visibility" do
@@ -42,16 +42,28 @@ describe "Module#alias_method" do
@object.was_private_one.should == 1
end
+ it "handles aliasing a method only present in a refinement" do
+ c = @class
+ Module.new do
+ refine c do
+ def uno_refined_method
+ end
+ alias_method :double_refined_method, :uno_refined_method
+ instance_method(:uno_refined_method).should == instance_method(:double_refined_method)
+ end
+ end
+ end
+
it "fails if origin method not found" do
- lambda { @class.make_alias :ni, :san }.should raise_error(NameError) { |e|
+ -> { @class.make_alias :ni, :san }.should.raise(NameError) { |e|
# a NameError and not a NoMethodError
e.class.should == NameError
}
end
- it "raises RuntimeError if frozen" do
+ it "raises FrozenError if frozen" do
@class.freeze
- lambda { @class.make_alias :uno, :public_one }.should raise_error(RuntimeError)
+ -> { @class.make_alias :uno, :public_one }.should.raise(FrozenError)
end
it "converts the names using #to_str" do
@@ -66,15 +78,24 @@ describe "Module#alias_method" do
end
it "raises a TypeError when the given name can't be converted using to_str" do
- lambda { @class.make_alias mock('x'), :public_one }.should raise_error(TypeError)
+ -> { @class.make_alias mock('x'), :public_one }.should.raise(TypeError)
end
- it "is a private method" do
- lambda { @class.alias_method :ichi, :public_one }.should raise_error(NoMethodError)
+ it "raises a NoMethodError if the given name raises a NoMethodError during type coercion using to_str" do
+ obj = mock("mock-name")
+ obj.should_receive(:to_str).and_raise(NoMethodError)
+ -> { @class.make_alias obj, :public_one }.should.raise(NoMethodError)
end
- it "returns self" do
- @class.send(:alias_method, :checking_return_value, :public_one).should equal(@class)
+ it "is a public method" do
+ Module.public_instance_methods(false).should.include?(:alias_method)
+ end
+
+ describe "returned value" do
+ it "returns symbol of the defined method name" do
+ @class.send(:alias_method, :checking_return_value, :public_one).should.equal?(:checking_return_value)
+ @class.send(:alias_method, 'checking_return_value', :public_one).should.equal?(:checking_return_value)
+ end
end
it "works in module" do
@@ -83,14 +104,14 @@ describe "Module#alias_method" do
it "works on private module methods in a module that has been reopened" do
ModuleSpecs::ReopeningModule.foo.should == true
- lambda { ModuleSpecs::ReopeningModule.foo2 }.should_not raise_error(NoMethodError)
+ -> { ModuleSpecs::ReopeningModule.foo2 }.should_not.raise(NoMethodError)
end
it "accesses a method defined on Object from Kernel" do
- Kernel.should_not have_public_instance_method(:module_specs_public_method_on_object)
+ Kernel.public_instance_methods(true).should_not.include?(:module_specs_public_method_on_object)
- Kernel.should have_public_instance_method(:module_specs_alias_on_kernel)
- Object.should have_public_instance_method(:module_specs_alias_on_kernel)
+ Kernel.public_instance_methods(false).should.include?(:module_specs_alias_on_kernel)
+ Object.public_instance_methods(true).should.include?(:module_specs_alias_on_kernel)
end
it "can call a method with super aliased twice" do
@@ -109,42 +130,42 @@ describe "Module#alias_method" do
it "keeps initialize private when aliasing" do
@class.make_alias(:initialize, :public_one)
- @class.private_instance_methods.include?(:initialize).should be_true
+ @class.private_instance_methods.include?(:initialize).should == true
@subclass.make_alias(:initialize, :public_one)
- @subclass.private_instance_methods.include?(:initialize).should be_true
+ @subclass.private_instance_methods.include?(:initialize).should == true
end
it "keeps initialize_copy private when aliasing" do
@class.make_alias(:initialize_copy, :public_one)
- @class.private_instance_methods.include?(:initialize_copy).should be_true
+ @class.private_instance_methods.include?(:initialize_copy).should == true
@subclass.make_alias(:initialize_copy, :public_one)
- @subclass.private_instance_methods.include?(:initialize_copy).should be_true
+ @subclass.private_instance_methods.include?(:initialize_copy).should == true
end
it "keeps initialize_clone private when aliasing" do
@class.make_alias(:initialize_clone, :public_one)
- @class.private_instance_methods.include?(:initialize_clone).should be_true
+ @class.private_instance_methods.include?(:initialize_clone).should == true
@subclass.make_alias(:initialize_clone, :public_one)
- @subclass.private_instance_methods.include?(:initialize_clone).should be_true
+ @subclass.private_instance_methods.include?(:initialize_clone).should == true
end
it "keeps initialize_dup private when aliasing" do
@class.make_alias(:initialize_dup, :public_one)
- @class.private_instance_methods.include?(:initialize_dup).should be_true
+ @class.private_instance_methods.include?(:initialize_dup).should == true
@subclass.make_alias(:initialize_dup, :public_one)
- @subclass.private_instance_methods.include?(:initialize_dup).should be_true
+ @subclass.private_instance_methods.include?(:initialize_dup).should == true
end
it "keeps respond_to_missing? private when aliasing" do
@class.make_alias(:respond_to_missing?, :public_one)
- @class.private_instance_methods.include?(:respond_to_missing?).should be_true
+ @class.private_instance_methods.include?(:respond_to_missing?).should == true
@subclass.make_alias(:respond_to_missing?, :public_one)
- @subclass.private_instance_methods.include?(:respond_to_missing?).should be_true
+ @subclass.private_instance_methods.include?(:respond_to_missing?).should == true
end
end
end
diff --git a/spec/ruby/core/module/allocate_spec.rb b/spec/ruby/core/module/allocate_spec.rb
deleted file mode 100644
index 306426881a..0000000000
--- a/spec/ruby/core/module/allocate_spec.rb
+++ /dev/null
@@ -1,14 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Module.allocate" do
- it "returns an instance of Module" do
- mod = Module.allocate
- mod.should be_an_instance_of(Module)
- end
-
- it "returns a fully-formed instance of Module" do
- mod = Module.allocate
- mod.constants.should_not == nil
- mod.methods.should_not == nil
- end
-end
diff --git a/spec/ruby/core/module/ancestors_spec.rb b/spec/ruby/core/module/ancestors_spec.rb
index 1cd537f7a0..f85884a4f3 100644
--- a/spec/ruby/core/module/ancestors_spec.rb
+++ b/spec/ruby/core/module/ancestors_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Module#ancestors" do
it "returns a list of modules included in self (including self)" do
@@ -7,27 +7,45 @@ describe "Module#ancestors" do
ModuleSpecs.ancestors.should == [ModuleSpecs]
ModuleSpecs::Basic.ancestors.should == [ModuleSpecs::Basic]
ModuleSpecs::Super.ancestors.should == [ModuleSpecs::Super, ModuleSpecs::Basic]
- ModuleSpecs.without_test_modules(ModuleSpecs::Parent.ancestors).should ==
- [ModuleSpecs::Parent, Object, Kernel, BasicObject]
- ModuleSpecs.without_test_modules(ModuleSpecs::Child.ancestors).should ==
- [ModuleSpecs::Child, ModuleSpecs::Super, ModuleSpecs::Basic, ModuleSpecs::Parent, Object, Kernel, BasicObject]
+ if defined?(Ruby::Box) && Ruby::Box.enabled?
+ ModuleSpecs.without_test_modules(ModuleSpecs::Parent.ancestors).should ==
+ [ModuleSpecs::Parent, Object, Ruby::Box::Loader, Kernel, BasicObject]
+ ModuleSpecs.without_test_modules(ModuleSpecs::Child.ancestors).should ==
+ [ModuleSpecs::Child, ModuleSpecs::Super, ModuleSpecs::Basic, ModuleSpecs::Parent, Object, Ruby::Box::Loader, Kernel, BasicObject]
+ else
+ ModuleSpecs.without_test_modules(ModuleSpecs::Parent.ancestors).should ==
+ [ModuleSpecs::Parent, Object, Kernel, BasicObject]
+ ModuleSpecs.without_test_modules(ModuleSpecs::Child.ancestors).should ==
+ [ModuleSpecs::Child, ModuleSpecs::Super, ModuleSpecs::Basic, ModuleSpecs::Parent, Object, Kernel, BasicObject]
+ end
end
it "returns only modules and classes" do
- class << ModuleSpecs::Child; self; end.ancestors.should include(ModuleSpecs::Internal, Class, Module, Object, Kernel)
+ class << ModuleSpecs::Child; self; end.ancestors.to_set.should >= Set[ModuleSpecs::Internal, Class, Module, Object, Kernel]
end
it "has 1 entry per module or class" do
ModuleSpecs::Parent.ancestors.should == ModuleSpecs::Parent.ancestors.uniq
end
+ it "returns a module that is included later into a nested module as well" do
+ m1 = Module.new
+ m2 = Module.new
+ m3 = Module.new do
+ include m2
+ end
+ m2.include m1 # should be after m3 includes m2
+
+ m3.ancestors.should == [m3, m2, m1]
+ end
+
describe "when called on a singleton class" do
it "includes the singleton classes of ancestors" do
parent = Class.new
child = Class.new(parent)
schild = child.singleton_class
- schild.ancestors.should include(schild,
+ schild.ancestors.to_set.should >= Set[schild,
parent.singleton_class,
Object.singleton_class,
BasicObject.singleton_class,
@@ -35,14 +53,14 @@ describe "Module#ancestors" do
Module,
Object,
Kernel,
- BasicObject)
+ BasicObject]
end
describe 'for a standalone module' do
it 'does not include Class' do
s_mod = ModuleSpecs.singleton_class
- s_mod.ancestors.should_not include(Class)
+ s_mod.ancestors.should_not.include?(Class)
end
it 'does not include other singleton classes' do
@@ -51,19 +69,19 @@ describe "Module#ancestors" do
s_object = Object.singleton_class
s_basic_object = BasicObject.singleton_class
- s_standalone_mod.ancestors.should_not include(s_module, s_object, s_basic_object)
+ (s_standalone_mod.ancestors & [s_module, s_object, s_basic_object]).should.empty?
end
it 'includes its own singleton class' do
s_mod = ModuleSpecs.singleton_class
- s_mod.ancestors.should include(s_mod)
+ s_mod.ancestors.should.include?(s_mod)
end
it 'includes standard chain' do
s_mod = ModuleSpecs.singleton_class
- s_mod.ancestors.should include(Module, Object, Kernel, BasicObject)
+ s_mod.ancestors.to_set.should >= Set[Module, Object, Kernel, BasicObject]
end
end
end
diff --git a/spec/ruby/core/module/append_features_spec.rb b/spec/ruby/core/module/append_features_spec.rb
index ceb8c3f8eb..4d2207330d 100644
--- a/spec/ruby/core/module/append_features_spec.rb
+++ b/spec/ruby/core/module/append_features_spec.rb
@@ -1,20 +1,20 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Module#append_features" do
it "is a private method" do
- Module.should have_private_instance_method(:append_features)
+ Module.private_instance_methods(false).should.include?(:append_features)
end
describe "on Class" do
it "is undefined" do
- Class.should_not have_private_instance_method(:append_features, true)
+ Class.private_instance_methods(true).should_not.include?(:append_features)
end
it "raises a TypeError if calling after rebinded to Class" do
- lambda {
+ -> {
Module.instance_method(:append_features).bind(Class.new).call Module.new
- }.should raise_error(TypeError)
+ }.should.raise(TypeError)
end
end
@@ -37,37 +37,25 @@ describe "Module#append_features" do
end
it "raises an ArgumentError on a cyclic include" do
- lambda {
+ -> {
ModuleSpecs::CyclicAppendA.send(:append_features, ModuleSpecs::CyclicAppendA)
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
- lambda {
+ -> {
ModuleSpecs::CyclicAppendB.send(:append_features, ModuleSpecs::CyclicAppendA)
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
end
- it "copies own tainted status to the given module" do
- other = Module.new
- Module.new.taint.send :append_features, other
- other.tainted?.should be_true
- end
-
- it "copies own untrusted status to the given module" do
- other = Module.new
- Module.new.untrust.send :append_features, other
- other.untrusted?.should be_true
- end
-
describe "when other is frozen" do
before :each do
@receiver = Module.new
@other = Module.new.freeze
end
- it "raises a RuntimeError before appending self" do
- lambda { @receiver.send(:append_features, @other) }.should raise_error(RuntimeError)
- @other.ancestors.should_not include(@receiver)
+ it "raises a FrozenError before appending self" do
+ -> { @receiver.send(:append_features, @other) }.should.raise(FrozenError)
+ @other.ancestors.should_not.include?(@receiver)
end
end
end
diff --git a/spec/ruby/core/module/attr_accessor_spec.rb b/spec/ruby/core/module/attr_accessor_spec.rb
index 4bd198dedc..a608760cf2 100644
--- a/spec/ruby/core/module/attr_accessor_spec.rb
+++ b/spec/ruby/core/module/attr_accessor_spec.rb
@@ -1,5 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/attr_added'
describe "Module#attr_accessor" do
it "creates a getter and setter for each given attribute name" do
@@ -33,10 +34,23 @@ describe "Module#attr_accessor" do
attr_accessor :spec_attr_accessor
end
- lambda { true.spec_attr_accessor = "a" }.should raise_error(RuntimeError)
+ -> { true.spec_attr_accessor = "a" }.should.raise(FrozenError)
end
- it "converts non string/symbol/fixnum names to strings using to_str" do
+ it "raises FrozenError if the receiver if frozen" do
+ c = Class.new do
+ attr_accessor :foo
+ end
+ obj = c.new
+ obj.foo = 1
+ obj.foo.should == 1
+
+ obj.freeze
+ -> { obj.foo = 42 }.should.raise(FrozenError)
+ obj.foo.should == 1
+ end
+
+ it "converts non string/symbol names to strings using to_str" do
(o = mock('test')).should_receive(:to_str).any_number_of_times.and_return("test")
c = Class.new do
attr_accessor o
@@ -48,9 +62,9 @@ describe "Module#attr_accessor" do
it "raises a TypeError when the given names can't be converted to strings using to_str" do
o = mock('o')
- lambda { Class.new { attr_accessor o } }.should raise_error(TypeError)
+ -> { Class.new { attr_accessor o } }.should.raise(TypeError)
(o = mock('123')).should_receive(:to_str).and_return(123)
- lambda { Class.new { attr_accessor o } }.should raise_error(TypeError)
+ -> { Class.new { attr_accessor o } }.should.raise(TypeError)
end
it "applies current visibility to methods created" do
@@ -59,32 +73,40 @@ describe "Module#attr_accessor" do
attr_accessor :foo
end
- lambda { c.new.foo }.should raise_error(NoMethodError)
- lambda { c.new.foo=1 }.should raise_error(NoMethodError)
+ -> { c.new.foo }.should.raise(NoMethodError)
+ -> { c.new.foo=1 }.should.raise(NoMethodError)
end
- it "is a private method" do
- lambda { Class.new.attr_accessor(:foo) }.should raise_error(NoMethodError)
+ it "is a public method" do
+ Module.public_instance_methods(false).should.include?(:attr_accessor)
+ end
+
+ it "returns an array of defined method names as symbols" do
+ Class.new do
+ (attr_accessor :foo, 'bar').should == [:foo, :foo=, :bar, :bar=]
+ end
end
describe "on immediates" do
before :each do
- class Fixnum
+ class Integer
attr_accessor :foobar
end
end
after :each do
- if Fixnum.method_defined?(:foobar)
- Fixnum.send(:remove_method, :foobar)
+ if Integer.method_defined?(:foobar)
+ Integer.send(:remove_method, :foobar)
end
- if Fixnum.method_defined?(:foobar=)
- Fixnum.send(:remove_method, :foobar=)
+ if Integer.method_defined?(:foobar=)
+ Integer.send(:remove_method, :foobar=)
end
end
it "can read through the accessor" do
- 1.foobar.should be_nil
+ 1.foobar.should == nil
end
end
+
+ it_behaves_like :module_attr_added, :attr_accessor
end
diff --git a/spec/ruby/core/module/attr_reader_spec.rb b/spec/ruby/core/module/attr_reader_spec.rb
index f2b968d3fc..2b4ca2100e 100644
--- a/spec/ruby/core/module/attr_reader_spec.rb
+++ b/spec/ruby/core/module/attr_reader_spec.rb
@@ -1,5 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/attr_added'
describe "Module#attr_reader" do
it "creates a getter for each given attribute name" do
@@ -29,10 +30,10 @@ describe "Module#attr_reader" do
attr_reader :spec_attr_reader
end
- lambda { true.instance_variable_set("@spec_attr_reader", "a") }.should raise_error(RuntimeError)
+ -> { true.instance_variable_set("@spec_attr_reader", "a") }.should.raise(RuntimeError)
end
- it "converts non string/symbol/fixnum names to strings using to_str" do
+ it "converts non string/symbol names to strings using to_str" do
(o = mock('test')).should_receive(:to_str).any_number_of_times.and_return("test")
c = Class.new do
attr_reader o
@@ -44,9 +45,9 @@ describe "Module#attr_reader" do
it "raises a TypeError when the given names can't be converted to strings using to_str" do
o = mock('o')
- lambda { Class.new { attr_reader o } }.should raise_error(TypeError)
+ -> { Class.new { attr_reader o } }.should.raise(TypeError)
(o = mock('123')).should_receive(:to_str).and_return(123)
- lambda { Class.new { attr_reader o } }.should raise_error(TypeError)
+ -> { Class.new { attr_reader o } }.should.raise(TypeError)
end
it "applies current visibility to methods created" do
@@ -55,10 +56,18 @@ describe "Module#attr_reader" do
attr_reader :foo
end
- lambda { c.new.foo }.should raise_error(NoMethodError)
+ -> { c.new.foo }.should.raise(NoMethodError)
end
- it "is a private method" do
- lambda { Class.new.attr_reader(:foo) }.should raise_error(NoMethodError)
+ it "is a public method" do
+ Module.public_instance_methods(false).should.include?(:attr_reader)
end
+
+ it "returns an array of defined method names as symbols" do
+ Class.new do
+ (attr_reader :foo, 'bar').should == [:foo, :bar]
+ end
+ end
+
+ it_behaves_like :module_attr_added, :attr_reader
end
diff --git a/spec/ruby/core/module/attr_spec.rb b/spec/ruby/core/module/attr_spec.rb
index 9a469707a1..d696864955 100644
--- a/spec/ruby/core/module/attr_spec.rb
+++ b/spec/ruby/core/module/attr_spec.rb
@@ -1,5 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/attr_added'
describe "Module#attr" do
before :each do
@@ -54,7 +55,7 @@ describe "Module#attr" do
o.attr3 = "test3 updated"
end
- it "creates a getter and setter for the given attribute name if called with and without writeable is true" do
+ it "creates a getter and setter for the given attribute name if called with and without writable is true" do
c = Class.new do
attr :attr, true
attr :attr
@@ -89,8 +90,8 @@ describe "Module#attr" do
attr :foo, true
end
- lambda { c.new.foo }.should raise_error(NoMethodError)
- lambda { c.new.foo=1 }.should raise_error(NoMethodError)
+ -> { c.new.foo }.should.raise(NoMethodError)
+ -> { c.new.foo=1 }.should.raise(NoMethodError)
end
it "creates a getter but no setter for all given attribute names" do
@@ -120,30 +121,39 @@ describe "Module#attr" do
attr :foo, :bar
end
- lambda { c.new.foo }.should raise_error(NoMethodError)
- lambda { c.new.bar }.should raise_error(NoMethodError)
+ -> { c.new.foo }.should.raise(NoMethodError)
+ -> { c.new.bar }.should.raise(NoMethodError)
end
- it "converts non string/symbol/fixnum names to strings using to_str" do
+ it "converts non string/symbol names to strings using to_str" do
(o = mock('test')).should_receive(:to_str).any_number_of_times.and_return("test")
Class.new { attr o }.new.respond_to?("test").should == true
end
it "raises a TypeError when the given names can't be converted to strings using to_str" do
o = mock('o')
- lambda { Class.new { attr o } }.should raise_error(TypeError)
+ -> { Class.new { attr o } }.should.raise(TypeError)
(o = mock('123')).should_receive(:to_str).and_return(123)
- lambda { Class.new { attr o } }.should raise_error(TypeError)
+ -> { Class.new { attr o } }.should.raise(TypeError)
end
it "with a boolean argument emits a warning when $VERBOSE is true" do
- lambda {
- $VERBOSE = true
+ -> {
Class.new { attr :foo, true }
- }.should complain(/boolean argument is obsoleted/)
+ }.should complain(/boolean argument is obsoleted/, verbose: true)
end
- it "is a private method" do
- lambda { Class.new.attr(:foo) }.should raise_error(NoMethodError)
+ it "is a public method" do
+ Module.public_instance_methods(false).should.include?(:attr)
end
+
+ it "returns an array of defined method names as symbols" do
+ Class.new do
+ (attr :foo, 'bar').should == [:foo, :bar]
+ (attr :baz, false).should == [:baz]
+ (attr :qux, true).should == [:qux, :qux=]
+ end
+ end
+
+ it_behaves_like :module_attr_added, :attr
end
diff --git a/spec/ruby/core/module/attr_writer_spec.rb b/spec/ruby/core/module/attr_writer_spec.rb
index e1308d19bb..6089b52495 100644
--- a/spec/ruby/core/module/attr_writer_spec.rb
+++ b/spec/ruby/core/module/attr_writer_spec.rb
@@ -1,5 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/attr_added'
describe "Module#attr_writer" do
it "creates a setter for each given attribute name" do
@@ -29,10 +30,20 @@ describe "Module#attr_writer" do
attr_writer :spec_attr_writer
end
- lambda { true.spec_attr_writer = "a" }.should raise_error(RuntimeError)
+ -> { true.spec_attr_writer = "a" }.should.raise(FrozenError)
end
- it "converts non string/symbol/fixnum names to strings using to_str" do
+ it "raises FrozenError if the receiver if frozen" do
+ c = Class.new do
+ attr_writer :foo
+ end
+ obj = c.new
+ obj.freeze
+
+ -> { obj.foo = 42 }.should.raise(FrozenError)
+ end
+
+ it "converts non string/symbol names to strings using to_str" do
(o = mock('test')).should_receive(:to_str).any_number_of_times.and_return("test")
c = Class.new do
attr_writer o
@@ -44,9 +55,9 @@ describe "Module#attr_writer" do
it "raises a TypeError when the given names can't be converted to strings using to_str" do
o = mock('test1')
- lambda { Class.new { attr_writer o } }.should raise_error(TypeError)
+ -> { Class.new { attr_writer o } }.should.raise(TypeError)
(o = mock('123')).should_receive(:to_str).and_return(123)
- lambda { Class.new { attr_writer o } }.should raise_error(TypeError)
+ -> { Class.new { attr_writer o } }.should.raise(TypeError)
end
it "applies current visibility to methods created" do
@@ -55,10 +66,18 @@ describe "Module#attr_writer" do
attr_writer :foo
end
- lambda { c.new.foo=1 }.should raise_error(NoMethodError)
+ -> { c.new.foo=1 }.should.raise(NoMethodError)
end
- it "is a private method" do
- lambda { Class.new.attr_writer(:foo) }.should raise_error(NoMethodError)
+ it "is a public method" do
+ Module.public_instance_methods(false).should.include?(:attr_writer)
end
+
+ it "returns an array of defined method names as symbols" do
+ Class.new do
+ (attr_writer :foo, 'bar').should == [:foo=, :bar=]
+ end
+ end
+
+ it_behaves_like :module_attr_added, :attr_writer
end
diff --git a/spec/ruby/core/module/autoload_relative_spec.rb b/spec/ruby/core/module/autoload_relative_spec.rb
new file mode 100644
index 0000000000..2e7d85496b
--- /dev/null
+++ b/spec/ruby/core/module/autoload_relative_spec.rb
@@ -0,0 +1,128 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+# Specs for Module#autoload_relative
+module ModuleSpecs
+ module AutoloadRelative
+ # Will be used for testing
+ end
+end
+
+ruby_version_is "4.1" do
+ describe "Module#autoload_relative" do
+ before :each do
+ @loaded_features = $".dup
+ end
+
+ after :each do
+ $".replace @loaded_features
+ end
+
+ it "is a public method" do
+ Module.public_instance_methods(false).should.include?(:autoload_relative)
+ end
+
+ it "registers a file to load relative to the current file the first time the named constant is accessed" do
+ ModuleSpecs::Autoload.autoload_relative :AutoloadRelativeA, "fixtures/autoload_relative_a.rb"
+ path = ModuleSpecs::Autoload.autoload?(:AutoloadRelativeA)
+ path.should_not == nil
+ path.should.end_with?("autoload_relative_a.rb")
+ File.exist?(path).should == true
+ end
+
+ it "loads the registered file when the constant is accessed" do
+ ModuleSpecs::Autoload.autoload_relative :AutoloadRelativeB, "fixtures/autoload_relative_a.rb"
+ ModuleSpecs::Autoload::AutoloadRelativeB.should.is_a?(Module)
+ end
+
+ it "returns nil" do
+ ModuleSpecs::Autoload.autoload_relative(:AutoloadRelativeC, "fixtures/autoload_relative_a.rb").should == nil
+ end
+
+ it "registers a file to load the first time the named constant is accessed" do
+ module ModuleSpecs::Autoload::AutoloadRelativeTest
+ autoload_relative :D, "fixtures/autoload_relative_a.rb"
+ end
+ path = ModuleSpecs::Autoload::AutoloadRelativeTest.autoload?(:D)
+ path.should_not == nil
+ path.should.end_with?("autoload_relative_a.rb")
+ end
+
+ it "sets the autoload constant in the constants table" do
+ ModuleSpecs::Autoload.autoload_relative :AutoloadRelativeTableTest, "fixtures/autoload_relative_a.rb"
+ ModuleSpecs::Autoload.should.const_defined?(:AutoloadRelativeTableTest, false)
+ end
+
+ it "calls #to_path on non-String filenames" do
+ name = mock("autoload_relative mock")
+ name.should_receive(:to_path).and_return("fixtures/autoload_relative_a.rb")
+ ModuleSpecs::Autoload.autoload_relative :AutoloadRelativeToPath, name
+ ModuleSpecs::Autoload.autoload?(:AutoloadRelativeToPath).should_not == nil
+ end
+
+ it "calls #to_str on non-String filenames" do
+ name = mock("autoload_relative mock")
+ name.should_receive(:to_str).and_return("fixtures/autoload_relative_a.rb")
+ ModuleSpecs::Autoload.autoload_relative :AutoloadRelativeToStr, name
+ ModuleSpecs::Autoload.autoload?(:AutoloadRelativeToStr).should_not == nil
+ end
+
+ it "raises a TypeError if the filename argument is not a String or pathname" do
+ -> {
+ ModuleSpecs::Autoload.autoload_relative :AutoloadRelativeTypError, nil
+ }.should.raise(TypeError)
+ end
+
+ it "raises a NameError if the constant name is not valid" do
+ -> {
+ ModuleSpecs::Autoload.autoload_relative :invalid_name, "fixtures/autoload_relative_a.rb"
+ }.should.raise(NameError)
+ end
+
+ it "raises an ArgumentError if the constant name starts with a lowercase letter" do
+ -> {
+ ModuleSpecs::Autoload.autoload_relative :autoload, "fixtures/autoload_relative_a.rb"
+ }.should.raise(NameError)
+ end
+
+ it "raises LoadError if called from eval without file context" do
+ -> {
+ ModuleSpecs::Autoload.module_eval('autoload_relative :EvalTest, "fixtures/autoload_relative_a.rb"')
+ }.should.raise(LoadError, /autoload_relative called without file context/)
+ end
+
+ it "can autoload in instance_eval with a file context" do
+ path = nil
+ ModuleSpecs::Autoload.instance_eval(<<-CODE, __FILE__, __LINE__)
+ autoload_relative :InstanceEvalTest, "fixtures/autoload_relative_a.rb"
+ path = autoload?(:InstanceEvalTest)
+ CODE
+ path.should_not == nil
+ path.should.end_with?("autoload_relative_a.rb")
+ end
+
+ it "resolves paths relative to the file where it's called" do
+ # Using fixtures/autoload_relative_a.rb which exists
+ ModuleSpecs::Autoload.autoload_relative :RelativePathTest, "fixtures/autoload_relative_a.rb"
+ path = ModuleSpecs::Autoload.autoload?(:RelativePathTest)
+ path.should.include?("fixtures")
+ path.should.end_with?("autoload_relative_a.rb")
+ end
+
+ it "can load nested directory paths" do
+ ModuleSpecs::Autoload.autoload_relative :NestedPath, "fixtures/autoload_relative_a.rb"
+ path = ModuleSpecs::Autoload.autoload?(:NestedPath)
+ path.should_not == nil
+ File.exist?(path).should == true
+ end
+
+ describe "interoperability with autoload?" do
+ it "returns the absolute path with autoload?" do
+ ModuleSpecs::Autoload.autoload_relative :QueryTest, "fixtures/autoload_relative_a.rb"
+ path = ModuleSpecs::Autoload.autoload?(:QueryTest)
+ # Should be an absolute path
+ Pathname.new(path).absolute?.should == true
+ end
+ end
+end
+end
diff --git a/spec/ruby/core/module/autoload_spec.rb b/spec/ruby/core/module/autoload_spec.rb
index 9116ddf0a9..057237a92f 100644
--- a/spec/ruby/core/module/autoload_spec.rb
+++ b/spec/ruby/core/module/autoload_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require 'thread'
+require_relative '../../spec_helper'
+require_relative '../../fixtures/code_loading'
+require_relative 'fixtures/classes'
describe "Module#autoload?" do
it "returns the name of the file that will be autoloaded" do
@@ -9,24 +9,43 @@ describe "Module#autoload?" do
end
it "returns nil if no file has been registered for a constant" do
- ModuleSpecs::Autoload.autoload?(:Manualload).should be_nil
+ ModuleSpecs::Autoload.autoload?(:Manualload).should == nil
+ end
+
+ it "returns the name of the file that will be autoloaded if an ancestor defined that autoload" do
+ ModuleSpecs::Autoload::Parent.autoload :AnotherAutoload, "another_autoload.rb"
+ ModuleSpecs::Autoload::Child.autoload?(:AnotherAutoload).should == "another_autoload.rb"
+ end
+
+ it "returns nil if an ancestor defined that autoload but recursion is disabled" do
+ ModuleSpecs::Autoload::Parent.autoload :InheritedAutoload, "inherited_autoload.rb"
+ ModuleSpecs::Autoload::Child.autoload?(:InheritedAutoload, false).should == nil
+ end
+
+ it "returns the name of the file that will be loaded if recursion is disabled but the autoload is defined on the class itself" do
+ ModuleSpecs::Autoload::Child.autoload :ChildAutoload, "child_autoload.rb"
+ ModuleSpecs::Autoload::Child.autoload?(:ChildAutoload, false).should == "child_autoload.rb"
end
end
describe "Module#autoload" do
before :all do
@non_existent = fixture __FILE__, "no_autoload.rb"
+ CodeLoadingSpecs.preload_rubygems
end
before :each do
@loaded_features = $".dup
- @frozen_module = Module.new.freeze
ScratchPad.clear
+ @remove = []
end
after :each do
$".replace @loaded_features
+ @remove.each { |const|
+ ModuleSpecs::Autoload.send :remove_const, const
+ }
end
it "registers a file to load the first time the named constant is accessed" do
@@ -36,21 +55,34 @@ describe "Module#autoload" do
it "sets the autoload constant in the constants table" do
ModuleSpecs::Autoload.autoload :B, @non_existent
- ModuleSpecs::Autoload.should have_constant(:B)
+ ModuleSpecs::Autoload.should.const_defined?(:B, false)
+ end
+
+ it "can be overridden with a second autoload on the same constant" do
+ ModuleSpecs::Autoload.autoload :Overridden, @non_existent
+ @remove << :Overridden
+ ModuleSpecs::Autoload.autoload?(:Overridden).should == @non_existent
+
+ path = fixture(__FILE__, "autoload_overridden.rb")
+ ModuleSpecs::Autoload.autoload :Overridden, path
+ ModuleSpecs::Autoload.autoload?(:Overridden).should == path
+
+ ModuleSpecs::Autoload::Overridden.should == :overridden
end
it "loads the registered constant when it is accessed" do
- ModuleSpecs::Autoload.should_not have_constant(:X)
+ ModuleSpecs::Autoload.should_not.const_defined?(:X)
ModuleSpecs::Autoload.autoload :X, fixture(__FILE__, "autoload_x.rb")
+ @remove << :X
ModuleSpecs::Autoload::X.should == :x
- ModuleSpecs::Autoload.send(:remove_const, :X)
end
it "loads the registered constant into a dynamically created class" do
cls = Class.new { autoload :C, fixture(__FILE__, "autoload_c.rb") }
ModuleSpecs::Autoload::DynClass = cls
+ @remove << :DynClass
- ScratchPad.recorded.should be_nil
+ ScratchPad.recorded.should == nil
ModuleSpecs::Autoload::DynClass::C.new.loaded.should == :dynclass_c
ScratchPad.recorded.should == :loaded
end
@@ -58,8 +90,9 @@ describe "Module#autoload" do
it "loads the registered constant into a dynamically created module" do
mod = Module.new { autoload :D, fixture(__FILE__, "autoload_d.rb") }
ModuleSpecs::Autoload::DynModule = mod
+ @remove << :DynModule
- ScratchPad.recorded.should be_nil
+ ScratchPad.recorded.should == nil
ModuleSpecs::Autoload::DynModule::D.new.loaded.should == :dynmodule_d
ScratchPad.recorded.should == :loaded
end
@@ -95,9 +128,10 @@ describe "Module#autoload" do
it "does not load the file when the constant is already set" do
ModuleSpecs::Autoload.autoload :I, fixture(__FILE__, "autoload_i.rb")
+ @remove << :I
ModuleSpecs::Autoload.const_set :I, 3
ModuleSpecs::Autoload::I.should == 3
- ScratchPad.recorded.should be_nil
+ ScratchPad.recorded.should == nil
end
it "loads a file with .rb extension when passed the name without the extension" do
@@ -105,17 +139,26 @@ describe "Module#autoload" do
ModuleSpecs::Autoload::J.should == :autoload_j
end
+ it "calls main.require(path) to load the file" do
+ ModuleSpecs::Autoload.autoload :ModuleAutoloadCallsRequire, "module_autoload_not_exist.rb"
+ main = TOPLEVEL_BINDING.eval("self")
+ main.should_receive(:require).with("module_autoload_not_exist.rb")
+ # The constant won't be defined since require is mocked to do nothing
+ -> { ModuleSpecs::Autoload::ModuleAutoloadCallsRequire }.should.raise(NameError)
+ end
+
it "does not load the file if the file is manually required" do
filename = fixture(__FILE__, "autoload_k.rb")
ModuleSpecs::Autoload.autoload :KHash, filename
+ @remove << :KHash
require filename
ScratchPad.recorded.should == :loaded
ScratchPad.clear
- ModuleSpecs::Autoload::KHash.should be_kind_of(Class)
+ ModuleSpecs::Autoload::KHash.should.is_a?(Class)
ModuleSpecs::Autoload::KHash::K.should == :autoload_k
- ScratchPad.recorded.should be_nil
+ ScratchPad.recorded.should == nil
end
it "ignores the autoload request if the file is already loaded" do
@@ -127,8 +170,8 @@ describe "Module#autoload" do
ScratchPad.clear
ModuleSpecs::Autoload.autoload :S, filename
- ModuleSpecs::Autoload.autoload?(:S).should be_nil
- ModuleSpecs::Autoload.send(:remove_const, :S)
+ @remove << :S
+ ModuleSpecs::Autoload.autoload?(:S).should == nil
end
it "retains the autoload even if the request to require fails" do
@@ -137,9 +180,9 @@ describe "Module#autoload" do
ModuleSpecs::Autoload.autoload :NotThere, filename
ModuleSpecs::Autoload.autoload?(:NotThere).should == filename
- lambda {
+ -> {
require filename
- }.should raise_error(LoadError)
+ }.should.raise(LoadError)
ModuleSpecs::Autoload.autoload?(:NotThere).should == filename
end
@@ -158,28 +201,322 @@ describe "Module#autoload" do
ModuleSpecs::Autoload.use_ex1.should == :good
end
- it "does not load the file when referring to the constant in defined?" do
- module ModuleSpecs::Autoload::Q
- autoload :R, fixture(__FILE__, "autoload.rb")
- defined?(R).should == "constant"
+ it "considers an autoload constant as loaded when autoload is called for/from the current file" do
+ filename = fixture(__FILE__, "autoload_during_require_current_file.rb")
+ require filename
+
+ ScratchPad.recorded.should == nil
+ end
+
+ describe "interacting with defined?" do
+ it "does not load the file when referring to the constant in defined?" do
+ module ModuleSpecs::Autoload::Dog
+ autoload :R, fixture(__FILE__, "autoload_exception.rb")
+ end
+
+ defined?(ModuleSpecs::Autoload::Dog::R).should == "constant"
+ ScratchPad.recorded.should == nil
+
+ ModuleSpecs::Autoload::Dog.should.const_defined?(:R, false)
+ end
+
+ it "loads an autoloaded parent when referencing a nested constant" do
+ module ModuleSpecs::Autoload
+ autoload :GoodParent, fixture(__FILE__, "autoload_nested.rb")
+ end
+ @remove << :GoodParent
+
+ defined?(ModuleSpecs::Autoload::GoodParent::Nested).should == 'constant'
+ ScratchPad.recorded.should == :loaded
+ end
+
+ it "returns nil when it fails to load an autoloaded parent when referencing a nested constant" do
+ module ModuleSpecs::Autoload
+ autoload :BadParent, fixture(__FILE__, "autoload_exception.rb")
+ end
+
+ defined?(ModuleSpecs::Autoload::BadParent::Nested).should == nil
+ ScratchPad.recorded.should == :exception
+ end
+ end
+
+ describe "the autoload is triggered when the same file is required directly" do
+ before :each do
+ module ModuleSpecs::Autoload
+ autoload :RequiredDirectly, fixture(__FILE__, "autoload_required_directly.rb")
+ end
+ @remove << :RequiredDirectly
+ @path = fixture(__FILE__, "autoload_required_directly.rb")
+ @check = -> {
+ [
+ defined?(ModuleSpecs::Autoload::RequiredDirectly),
+ ModuleSpecs::Autoload.autoload?(:RequiredDirectly)
+ ]
+ }
+ ScratchPad.record @check
+ end
+
+ it "with a full path" do
+ @check.call.should == ["constant", @path]
+ require @path
+ ScratchPad.recorded.should == [nil, nil]
+ @check.call.should == ["constant", nil]
+ end
+
+ it "with a relative path" do
+ @check.call.should == ["constant", @path]
+ $:.push File.dirname(@path)
+ begin
+ require "autoload_required_directly.rb"
+ ensure
+ $:.pop
+ end
+ ScratchPad.recorded.should == [nil, nil]
+ @check.call.should == ["constant", nil]
+ end
+
+ it "in a nested require" do
+ nested = fixture(__FILE__, "autoload_required_directly_nested.rb")
+ nested_require = -> {
+ result = nil
+ ScratchPad.record -> {
+ result = @check.call
+ }
+ require nested
+ result
+ }
+ ScratchPad.record nested_require
+
+ @check.call.should == ["constant", @path]
+ require @path
+ ScratchPad.recorded.should == [nil, nil]
+ @check.call.should == ["constant", nil]
+ end
+
+ it "does not raise an error if the autoload constant was not defined" do
+ module ModuleSpecs::Autoload
+ autoload :RequiredDirectlyNoConstant, fixture(__FILE__, "autoload_required_directly_no_constant.rb")
+ end
+ @path = fixture(__FILE__, "autoload_required_directly_no_constant.rb")
+ @remove << :RequiredDirectlyNoConstant
+ @check = -> {
+ [
+ defined?(ModuleSpecs::Autoload::RequiredDirectlyNoConstant),
+ ModuleSpecs::Autoload.constants(false).include?(:RequiredDirectlyNoConstant),
+ ModuleSpecs::Autoload.const_defined?(:RequiredDirectlyNoConstant),
+ ModuleSpecs::Autoload.autoload?(:RequiredDirectlyNoConstant)
+ ]
+ }
+ ScratchPad.record @check
+ @check.call.should == ["constant", true, true, @path]
+ $:.push File.dirname(@path)
+ begin
+ require "autoload_required_directly_no_constant.rb"
+ ensure
+ $:.pop
+ end
+ ScratchPad.recorded.should == [nil, true, false, nil]
+ @check.call.should == [nil, true, false, nil]
+ end
+ end
+
+ describe "after the autoload is triggered by require" do
+ before :each do
+ @path = tmp("autoload.rb")
+ end
+
+ after :each do
+ rm_r @path
+ end
+
+ it "the mapping feature to autoload is removed, and a new autoload with the same path is considered" do
+ ModuleSpecs::Autoload.autoload :RequireMapping1, @path
+ touch(@path) { |f| f.puts "ModuleSpecs::Autoload::RequireMapping1 = 1" }
+ ModuleSpecs::Autoload::RequireMapping1.should == 1
+
+ $LOADED_FEATURES.delete(@path)
+ ModuleSpecs::Autoload.autoload :RequireMapping2, @path[0...-3]
+ @remove << :RequireMapping2
+ touch(@path) { |f| f.puts "ModuleSpecs::Autoload::RequireMapping2 = 2" }
+ ModuleSpecs::Autoload::RequireMapping2.should == 2
+ end
+ end
+
+ def check_before_during_thread_after(const, &check)
+ before = check.call
+ to_autoload_thread, from_autoload_thread = Queue.new, Queue.new
+ ScratchPad.record -> {
+ from_autoload_thread.push check.call
+ to_autoload_thread.pop
+ }
+ t = Thread.new {
+ in_loading_thread = from_autoload_thread.pop
+ in_other_thread = check.call
+ to_autoload_thread.push :done
+ [in_loading_thread, in_other_thread]
+ }
+ in_loading_thread, in_other_thread = nil
+ begin
+ ModuleSpecs::Autoload.const_get(const)
+ ensure
+ in_loading_thread, in_other_thread = t.value
+ end
+ after = check.call
+ [before, in_loading_thread, in_other_thread, after]
+ end
+
+ describe "during the autoload before the constant is assigned" do
+ before :each do
+ @path = fixture(__FILE__, "autoload_during_autoload.rb")
+ ModuleSpecs::Autoload.autoload :DuringAutoload, @path
+ @remove << :DuringAutoload
+ raise unless ModuleSpecs::Autoload.autoload?(:DuringAutoload) == @path
+ end
+
+ it "returns nil in autoload thread and 'constant' otherwise for defined?" do
+ results = check_before_during_thread_after(:DuringAutoload) {
+ defined?(ModuleSpecs::Autoload::DuringAutoload)
+ }
+ results.should == ['constant', nil, 'constant', 'constant']
+ end
+
+ it "keeps the constant in Module#constants" do
+ results = check_before_during_thread_after(:DuringAutoload) {
+ ModuleSpecs::Autoload.constants(false).include?(:DuringAutoload)
+ }
+ results.should == [true, true, true, true]
+ end
+
+ it "returns false in autoload thread and true otherwise for Module#const_defined?" do
+ results = check_before_during_thread_after(:DuringAutoload) {
+ ModuleSpecs::Autoload.const_defined?(:DuringAutoload, false)
+ }
+ results.should == [true, false, true, true]
+ end
+
+ it "returns nil in autoload thread and returns the path in other threads for Module#autoload?" do
+ results = check_before_during_thread_after(:DuringAutoload) {
+ ModuleSpecs::Autoload.autoload?(:DuringAutoload)
+ }
+ results.should == [@path, nil, @path, nil]
end
- ModuleSpecs::Autoload::Q.should have_constant(:R)
end
- it "does not remove the constant from the constant table if load fails" do
+ describe "during the autoload after the constant is assigned" do
+ before :each do
+ @path = fixture(__FILE__, "autoload_during_autoload_after_define.rb")
+ ModuleSpecs::Autoload.autoload :DuringAutoloadAfterDefine, @path
+ @autoload_location = [__FILE__, __LINE__ - 1]
+ @const_location = [@path, 2]
+ @remove << :DuringAutoloadAfterDefine
+ raise unless ModuleSpecs::Autoload.autoload?(:DuringAutoloadAfterDefine) == @path
+ end
+
+ it "returns 'constant' in both threads" do
+ results = check_before_during_thread_after(:DuringAutoloadAfterDefine) {
+ defined?(ModuleSpecs::Autoload::DuringAutoloadAfterDefine)
+ }
+ results.should == ['constant', 'constant', 'constant', 'constant']
+ end
+
+ it "Module#constants include the autoloaded in both threads" do
+ results = check_before_during_thread_after(:DuringAutoloadAfterDefine) {
+ ModuleSpecs::Autoload.constants(false).include?(:DuringAutoloadAfterDefine)
+ }
+ results.should == [true, true, true, true]
+ end
+
+ it "Module#const_defined? returns true in both threads" do
+ results = check_before_during_thread_after(:DuringAutoloadAfterDefine) {
+ ModuleSpecs::Autoload.const_defined?(:DuringAutoloadAfterDefine, false)
+ }
+ results.should == [true, true, true, true]
+ end
+
+ it "returns nil in autoload thread and returns the path in other threads for Module#autoload?" do
+ results = check_before_during_thread_after(:DuringAutoloadAfterDefine) {
+ ModuleSpecs::Autoload.autoload?(:DuringAutoloadAfterDefine)
+ }
+ results.should == [@path, nil, @path, nil]
+ end
+
+ ruby_bug("#20188", ""..."3.4") do
+ it "returns the real constant location in autoload thread and returns the autoload location in other threads for Module#const_source_location" do
+ results = check_before_during_thread_after(:DuringAutoloadAfterDefine) {
+ ModuleSpecs::Autoload.const_source_location(:DuringAutoloadAfterDefine)
+ }
+ results.should == [@autoload_location, @const_location, @autoload_location, @const_location]
+ end
+ end
+ end
+
+ it "does not remove the constant from Module#constants if load fails and keeps it as an autoload" do
ModuleSpecs::Autoload.autoload :Fail, @non_existent
- ModuleSpecs::Autoload.should have_constant(:Fail)
- lambda { ModuleSpecs::Autoload::Fail }.should raise_error(LoadError)
- ModuleSpecs::Autoload.should have_constant(:Fail)
+ ModuleSpecs::Autoload.const_defined?(:Fail).should == true
+ ModuleSpecs::Autoload.should.const_defined?(:Fail, false)
+ ModuleSpecs::Autoload.autoload?(:Fail).should == @non_existent
+
+ -> { ModuleSpecs::Autoload::Fail }.should.raise(LoadError)
+
+ ModuleSpecs::Autoload.should.const_defined?(:Fail, false)
+ ModuleSpecs::Autoload.const_defined?(:Fail).should == true
+ ModuleSpecs::Autoload.autoload?(:Fail).should == @non_existent
+
+ -> { ModuleSpecs::Autoload::Fail }.should.raise(LoadError)
end
- it "does not remove the constant from the constant table if the loaded files does not define it" do
- ModuleSpecs::Autoload.autoload :O, fixture(__FILE__, "autoload_o.rb")
- ModuleSpecs::Autoload.should have_constant(:O)
+ it "does not remove the constant from Module#constants if load raises a RuntimeError and keeps it as an autoload" do
+ path = fixture(__FILE__, "autoload_raise.rb")
+ ScratchPad.record []
+ ModuleSpecs::Autoload.autoload :Raise, path
+
+ ModuleSpecs::Autoload.const_defined?(:Raise).should == true
+ ModuleSpecs::Autoload.should.const_defined?(:Raise, false)
+ ModuleSpecs::Autoload.autoload?(:Raise).should == path
- lambda { ModuleSpecs::Autoload::O }.should raise_error(NameError)
- ModuleSpecs::Autoload.should have_constant(:O)
+ -> { ModuleSpecs::Autoload::Raise }.should.raise(RuntimeError)
+ ScratchPad.recorded.should == [:raise]
+
+ ModuleSpecs::Autoload.should.const_defined?(:Raise, false)
+ ModuleSpecs::Autoload.const_defined?(:Raise).should == true
+ ModuleSpecs::Autoload.autoload?(:Raise).should == path
+
+ -> { ModuleSpecs::Autoload::Raise }.should.raise(RuntimeError)
+ ScratchPad.recorded.should == [:raise, :raise]
+ end
+
+ it "removes the constant from Module#constants if the loaded file does not define it" do
+ path = fixture(__FILE__, "autoload_o.rb")
+ ScratchPad.record []
+ ModuleSpecs::Autoload.autoload :O, path
+
+ ModuleSpecs::Autoload.const_defined?(:O).should == true
+ ModuleSpecs::Autoload.should.const_defined?(:O, false)
+ ModuleSpecs::Autoload.autoload?(:O).should == path
+
+ -> { ModuleSpecs::Autoload::O }.should.raise(NameError)
+
+ ModuleSpecs::Autoload.const_defined?(:O).should == false
+ ModuleSpecs::Autoload.should_not.const_defined?(:O)
+ ModuleSpecs::Autoload.autoload?(:O).should == nil
+ -> { ModuleSpecs::Autoload.const_get(:O) }.should.raise(NameError)
+ end
+
+ it "does not try to load the file again if the loaded file did not define the constant" do
+ path = fixture(__FILE__, "autoload_o.rb")
+ ScratchPad.record []
+ ModuleSpecs::Autoload.autoload :NotDefinedByFile, path
+
+ -> { ModuleSpecs::Autoload::NotDefinedByFile }.should.raise(NameError)
+ ScratchPad.recorded.should == [:loaded]
+ -> { ModuleSpecs::Autoload::NotDefinedByFile }.should.raise(NameError)
+ ScratchPad.recorded.should == [:loaded]
+
+ Thread.new {
+ -> { ModuleSpecs::Autoload::NotDefinedByFile }.should.raise(NameError)
+ }.join
+ ScratchPad.recorded.should == [:loaded]
end
it "returns 'constant' on referring the constant with defined?()" do
@@ -187,7 +524,7 @@ describe "Module#autoload" do
autoload :R, fixture(__FILE__, "autoload.rb")
defined?(R).should == 'constant'
end
- ModuleSpecs::Autoload::Q.should have_constant(:R)
+ ModuleSpecs::Autoload::Q.should.const_defined?(:R, false)
end
it "does not load the file when removing an autoload constant" do
@@ -195,12 +532,13 @@ describe "Module#autoload" do
autoload :R, fixture(__FILE__, "autoload.rb")
remove_const :R
end
- ModuleSpecs::Autoload::Q.should_not have_constant(:R)
+ ModuleSpecs::Autoload::Q.should_not.const_defined?(:R)
end
it "does not load the file when accessing the constants table of the module" do
ModuleSpecs::Autoload.autoload :P, @non_existent
- ModuleSpecs::Autoload.const_defined?(:P).should be_true
+ ModuleSpecs::Autoload.const_defined?(:P).should == true
+ ModuleSpecs::Autoload.const_defined?("P").should == true
end
it "loads the file when opening a module that is the autoloaded constant" do
@@ -211,43 +549,188 @@ describe "Module#autoload" do
X = get_value
end
end
+ @remove << :U
ModuleSpecs::Autoload::U::V::X.should == :autoload_uvx
end
- it "loads the file that defines subclass XX::YY < YY and YY is a top level constant" do
-
+ it "loads the file that defines subclass XX::CS_CONST_AUTOLOAD < CS_CONST_AUTOLOAD and CS_CONST_AUTOLOAD is a top level constant" do
module ModuleSpecs::Autoload::XX
- autoload :YY, fixture(__FILE__, "autoload_subclass.rb")
+ autoload :CS_CONST_AUTOLOAD, fixture(__FILE__, "autoload_subclass.rb")
end
- ModuleSpecs::Autoload::XX::YY.superclass.should == YY
+ ModuleSpecs::Autoload::XX::CS_CONST_AUTOLOAD.superclass.should == CS_CONST_AUTOLOAD
end
+ describe "after autoloading searches for the constant like the original lookup" do
+ it "in lexical scopes if both declared and defined in parent" do
+ module ModuleSpecs::Autoload
+ ScratchPad.record -> {
+ DeclaredAndDefinedInParent = :declared_and_defined_in_parent
+ }
+ autoload :DeclaredAndDefinedInParent, fixture(__FILE__, "autoload_callback.rb")
+ class LexicalScope
+ DeclaredAndDefinedInParent.should == :declared_and_defined_in_parent
+
+ # The constant is really in Autoload, not Autoload::LexicalScope
+ self.should_not.const_defined?(:DeclaredAndDefinedInParent)
+ -> { const_get(:DeclaredAndDefinedInParent) }.should.raise(NameError)
+ end
+ DeclaredAndDefinedInParent.should == :declared_and_defined_in_parent
+ end
+ end
+
+ it "in lexical scopes if declared in parent and defined in current" do
+ module ModuleSpecs::Autoload
+ ScratchPad.record -> {
+ class LexicalScope
+ DeclaredInParentDefinedInCurrent = :declared_in_parent_defined_in_current
+ end
+ }
+ autoload :DeclaredInParentDefinedInCurrent, fixture(__FILE__, "autoload_callback.rb")
+
+ class LexicalScope
+ DeclaredInParentDefinedInCurrent.should == :declared_in_parent_defined_in_current
+ LexicalScope::DeclaredInParentDefinedInCurrent.should == :declared_in_parent_defined_in_current
+ end
+
+ # Basically, the parent autoload constant remains in a "undefined" state
+ self.autoload?(:DeclaredInParentDefinedInCurrent).should == nil
+ const_defined?(:DeclaredInParentDefinedInCurrent).should == false
+ -> { DeclaredInParentDefinedInCurrent }.should.raise(NameError)
- it "looks up the constant in the scope where it is referred" do
- module ModuleSpecs
- module Autoload
- autoload :QQ, fixture(__FILE__, "autoload_scope.rb")
- class PP
- QQ.new.should be_kind_of(ModuleSpecs::Autoload::PP::QQ)
+ ModuleSpecs::Autoload::LexicalScope.send(:remove_const, :DeclaredInParentDefinedInCurrent)
+ end
+ end
+
+ it "warns once in verbose mode if the constant was defined in a parent scope" do
+ ScratchPad.record -> {
+ ModuleSpecs::DeclaredInCurrentDefinedInParent = :declared_in_current_defined_in_parent
+ }
+
+ module ModuleSpecs
+ module Autoload
+ autoload :DeclaredInCurrentDefinedInParent, fixture(__FILE__, "autoload_callback.rb")
+ self.autoload?(:DeclaredInCurrentDefinedInParent).should == fixture(__FILE__, "autoload_callback.rb")
+ const_defined?(:DeclaredInCurrentDefinedInParent).should == true
+
+ -> {
+ DeclaredInCurrentDefinedInParent
+ }.should complain(
+ /Expected .*autoload_callback.rb to define ModuleSpecs::Autoload::DeclaredInCurrentDefinedInParent but it didn't/,
+ verbose: true,
+ )
+
+ -> {
+ DeclaredInCurrentDefinedInParent
+ }.should_not complain(/.*/, verbose: true)
+ self.autoload?(:DeclaredInCurrentDefinedInParent).should == nil
+ const_defined?(:DeclaredInCurrentDefinedInParent).should == false
+ ModuleSpecs.const_defined?(:DeclaredInCurrentDefinedInParent).should == true
end
end
end
- end
- it "looks up the constant when in a meta class scope" do
- module ModuleSpecs
- module Autoload
- autoload :R, fixture(__FILE__, "autoload_r.rb")
+ it "looks up in parent scope after failed autoload" do
+ @remove << :DeclaredInCurrentDefinedInParent
+ module ModuleSpecs::Autoload
+ ScratchPad.record -> {
+ DeclaredInCurrentDefinedInParent = :declared_in_current_defined_in_parent
+ }
+
+ class LexicalScope
+ autoload :DeclaredInCurrentDefinedInParent, fixture(__FILE__, "autoload_callback.rb")
+ -> { DeclaredInCurrentDefinedInParent }.should_not.raise(NameError)
+ # Basically, the autoload constant remains in a "undefined" state
+ self.autoload?(:DeclaredInCurrentDefinedInParent).should == nil
+ const_defined?(:DeclaredInCurrentDefinedInParent).should == false
+ -> { const_get(:DeclaredInCurrentDefinedInParent) }.should.raise(NameError)
+ end
+
+ DeclaredInCurrentDefinedInParent.should == :declared_in_current_defined_in_parent
+ end
+ end
+
+ it "in the included modules" do
+ @remove << :DefinedInIncludedModule
+ module ModuleSpecs::Autoload
+ ScratchPad.record -> {
+ module DefinedInIncludedModule
+ Incl = :defined_in_included_module
+ end
+ include DefinedInIncludedModule
+ }
+ autoload :Incl, fixture(__FILE__, "autoload_callback.rb")
+ Incl.should == :defined_in_included_module
+ end
+ end
+
+ it "in the included modules of the superclass" do
+ @remove << :DefinedInSuperclassIncludedModule
+ module ModuleSpecs::Autoload
+ class LookupAfterAutoloadSuper
+ end
+ class LookupAfterAutoloadChild < LookupAfterAutoloadSuper
+ end
+
+ ScratchPad.record -> {
+ module DefinedInSuperclassIncludedModule
+ InclS = :defined_in_superclass_included_module
+ end
+ LookupAfterAutoloadSuper.include DefinedInSuperclassIncludedModule
+ }
+
+ class LookupAfterAutoloadChild
+ autoload :InclS, fixture(__FILE__, "autoload_callback.rb")
+ InclS.should == :defined_in_superclass_included_module
+ end
+ end
+ end
+
+ it "in the prepended modules" do
+ @remove << :DefinedInPrependedModule
+ module ModuleSpecs::Autoload
+ ScratchPad.record -> {
+ module DefinedInPrependedModule
+ Prep = :defined_in_prepended_module
+ end
+ include DefinedInPrependedModule
+ }
+ autoload :Prep, fixture(__FILE__, "autoload_callback.rb")
+ Prep.should == :defined_in_prepended_module
+ end
+ end
+
+ it "in a meta class scope" do
+ module ModuleSpecs::Autoload
+ ScratchPad.record -> {
+ class MetaScope
+ end
+ }
+ autoload :MetaScope, fixture(__FILE__, "autoload_callback.rb")
class << self
def r
- R.new
+ MetaScope.new
end
end
end
+ ModuleSpecs::Autoload.r.should.is_a?(ModuleSpecs::Autoload::MetaScope)
end
- ModuleSpecs::Autoload.r.should be_kind_of(ModuleSpecs::Autoload::R)
+ end
+
+ it "should trigger the autoload when using `private_constant`" do
+ @remove << :DynClass
+ module ModuleSpecs::Autoload
+ autoload :DynClass, fixture(__FILE__, "autoload_c.rb")
+ private_constant :DynClass
+
+ ScratchPad.recorded.should == nil
+
+ DynClass::C.new.loaded.should == :dynclass_c
+ ScratchPad.recorded.should == :loaded
+ end
+
+ -> { ModuleSpecs::Autoload::DynClass }.should.raise(NameError, /private constant/)
end
# [ruby-core:19127] [ruby-core:29941]
@@ -260,10 +743,45 @@ describe "Module#autoload" do
end
end
end
+ @remove << :W
- ModuleSpecs::Autoload::W::Y.should be_kind_of(Class)
+ ModuleSpecs::Autoload::W::Y.should.is_a?(Class)
ScratchPad.recorded.should == :loaded
- ModuleSpecs::Autoload::W.send(:remove_const, :Y)
+ end
+
+ it "does not call #require a second time and does not warn if already loading the same feature with #require" do
+ main = TOPLEVEL_BINDING.eval("self")
+ main.should_not_receive(:require)
+
+ module ModuleSpecs::Autoload
+ autoload :AutoloadDuringRequire, fixture(__FILE__, "autoload_during_require.rb")
+ end
+
+ -> {
+ Kernel.require fixture(__FILE__, "autoload_during_require.rb")
+ }.should_not complain(verbose: true)
+ ModuleSpecs::Autoload::AutoloadDuringRequire.should.is_a?(Class)
+ end
+
+ it "does not call #require a second time and does not warn if feature sets and trigger autoload on itself" do
+ main = TOPLEVEL_BINDING.eval("self")
+ main.should_not_receive(:require)
+
+ -> {
+ Kernel.require fixture(__FILE__, "autoload_self_during_require.rb")
+ }.should_not complain(verbose: true)
+ ModuleSpecs::Autoload::AutoloadSelfDuringRequire.should.is_a?(Class)
+ end
+
+ it "handles multiple autoloads in the same file" do
+ $LOAD_PATH.unshift(File.expand_path('../fixtures/multi', __FILE__))
+ begin
+ require 'foo/bar_baz'
+ ModuleSpecs::Autoload::Foo::Bar.should.is_a?(Class)
+ ModuleSpecs::Autoload::Foo::Baz.should.is_a?(Class)
+ ensure
+ $LOAD_PATH.shift
+ end
end
it "calls #to_path on non-string filenames" do
@@ -273,26 +791,27 @@ describe "Module#autoload" do
end
it "raises an ArgumentError when an empty filename is given" do
- lambda { ModuleSpecs.autoload :A, "" }.should raise_error(ArgumentError)
+ -> { ModuleSpecs.autoload :A, "" }.should.raise(ArgumentError)
end
it "raises a NameError when the constant name starts with a lower case letter" do
- lambda { ModuleSpecs.autoload "a", @non_existent }.should raise_error(NameError)
+ -> { ModuleSpecs.autoload "a", @non_existent }.should.raise(NameError)
end
it "raises a NameError when the constant name starts with a number" do
- lambda { ModuleSpecs.autoload "1two", @non_existent }.should raise_error(NameError)
+ -> { ModuleSpecs.autoload "1two", @non_existent }.should.raise(NameError)
end
it "raises a NameError when the constant name has a space in it" do
- lambda { ModuleSpecs.autoload "a name", @non_existent }.should raise_error(NameError)
+ -> { ModuleSpecs.autoload "a name", @non_existent }.should.raise(NameError)
end
it "shares the autoload request across dup'ed copies of modules" do
require fixture(__FILE__, "autoload_s.rb")
+ @remove << :S
filename = fixture(__FILE__, "autoload_t.rb")
mod1 = Module.new { autoload :T, filename }
- lambda {
+ -> {
ModuleSpecs::Autoload::S = mod1
}.should complain(/already initialized constant/)
mod2 = mod1.dup
@@ -301,7 +820,7 @@ describe "Module#autoload" do
mod2.autoload?(:T).should == filename
mod1::T.should == :autoload_t
- lambda { mod2::T }.should raise_error(NameError)
+ -> { mod2::T }.should.raise(NameError)
end
it "raises a TypeError if opening a class with a different superclass than the class defined in the autoload file" do
@@ -309,35 +828,53 @@ describe "Module#autoload" do
class ModuleSpecs::Autoload::ZZ
end
- lambda do
+ -> do
class ModuleSpecs::Autoload::Z < ModuleSpecs::Autoload::ZZ
end
- end.should raise_error(TypeError)
+ end.should.raise(TypeError)
end
- it "raises a TypeError if not passed a String or object respodning to #to_path for the filename" do
+ it "raises a TypeError if not passed a String or object responding to #to_path for the filename" do
name = mock("autoload_name.rb")
- lambda { ModuleSpecs::Autoload.autoload :Str, name }.should raise_error(TypeError)
+ -> { ModuleSpecs::Autoload.autoload :Str, name }.should.raise(TypeError)
end
it "calls #to_path on non-String filename arguments" do
name = mock("autoload_name.rb")
name.should_receive(:to_path).and_return("autoload_name.rb")
- lambda { ModuleSpecs::Autoload.autoload :Str, name }.should_not raise_error
+ -> { ModuleSpecs::Autoload.autoload :Str, name }.should_not.raise
end
describe "on a frozen module" do
- it "raises a RuntimeError before setting the name" do
- lambda { @frozen_module.autoload :Foo, @non_existent }.should raise_error(RuntimeError)
- @frozen_module.should_not have_constant(:Foo)
+ it "raises a FrozenError before setting the name" do
+ frozen_module = Module.new.freeze
+ -> { frozen_module.autoload :Foo, @non_existent }.should.raise(FrozenError)
+ frozen_module.should_not.const_defined?(:Foo)
+ end
+ end
+
+ describe "when changing $LOAD_PATH" do
+ before do
+ $LOAD_PATH.unshift(File.expand_path('../fixtures/path1', __FILE__))
+ end
+
+ after do
+ $LOAD_PATH.shift
+ $LOAD_PATH.shift
+ end
+
+ it "does not reload a file due to a different load path" do
+ ModuleSpecs::Autoload.autoload :LoadPath, "load_path"
+ ModuleSpecs::Autoload::LoadPath.loaded.should == :autoload_load_path
end
end
describe "(concurrently)" do
it "blocks a second thread while a first is doing the autoload" do
ModuleSpecs::Autoload.autoload :Concur, fixture(__FILE__, "autoload_concur.rb")
+ @remove << :Concur
start = false
@@ -379,78 +916,107 @@ describe "Module#autoload" do
t1_val.should == 1
t2_val.should == t1_val
- t2_exc.should be_nil
-
- ModuleSpecs::Autoload.send(:remove_const, :Concur)
+ t2_exc.should == nil
end
- end
- describe "when changing $LOAD_PATH" do
+ # https://bugs.ruby-lang.org/issues/10892
+ it "blocks others threads while doing an autoload" do
+ file_path = fixture(__FILE__, "repeated_concurrent_autoload.rb")
+ autoload_path = file_path.sub(/\.rb\Z/, '')
+ mod_count = 30
+ thread_count = 16
+
+ mod_names = []
+ mod_count.times do |i|
+ mod_name = :"Mod#{i}"
+ Object.autoload mod_name, autoload_path
+ mod_names << mod_name
+ end
- before do
- $LOAD_PATH.unshift(File.expand_path('../fixtures/path1', __FILE__))
- end
+ barrier = ModuleSpecs::CyclicBarrier.new thread_count
+ ScratchPad.record ModuleSpecs::ThreadSafeCounter.new
- after do
- $LOAD_PATH.shift
- $LOAD_PATH.shift
- end
+ threads = (1..thread_count).map do
+ Thread.new do
+ mod_names.each do |mod_name|
+ break false unless barrier.enabled?
- it "does not reload a file due to a different load path" do
- ModuleSpecs::Autoload.autoload :LoadPath, "load_path"
- ModuleSpecs::Autoload::LoadPath.loaded.should == :autoload_load_path
- end
+ was_last_one_in = barrier.await # wait for all threads to finish the iteration
+ # clean up so we can autoload the same file again
+ $LOADED_FEATURES.delete(file_path) if was_last_one_in && $LOADED_FEATURES.include?(file_path)
+ barrier.await # get ready for race
- end
-
- describe "(concurrently)" do
- ruby_bug "#10892", ""..."2.3" do
- it "blocks others threads while doing an autoload" do
- file_path = fixture(__FILE__, "repeated_concurrent_autoload.rb")
- autoload_path = file_path.sub(/\.rb\Z/, '')
- mod_count = 30
- thread_count = 16
-
- mod_names = []
- mod_count.times do |i|
- mod_name = :"Mod#{i}"
- Object.autoload mod_name, autoload_path
- mod_names << mod_name
+ begin
+ Object.const_get(mod_name).foo
+ rescue NameError, NoMethodError # rubocop:disable Lint/ShadowedException
+ barrier.disable!
+ break false
+ end
+ end
end
+ end
- barrier = ModuleSpecs::CyclicBarrier.new thread_count
- ScratchPad.record ModuleSpecs::ThreadSafeCounter.new
-
- threads = (1..thread_count).map do
- Thread.new do
- mod_names.each do |mod_name|
- break false unless barrier.enabled?
-
- was_last_one_in = barrier.await # wait for all threads to finish the iteration
- # clean up so we can autoload the same file again
- $LOADED_FEATURES.delete(file_path) if was_last_one_in && $LOADED_FEATURES.include?(file_path)
- barrier.await # get ready for race
-
- begin
- Object.const_get(mod_name).foo
- rescue NoMethodError
- barrier.disable!
- break false
- end
- end
+ # check that no thread got a NameError or NoMethodError because of partially loaded module
+ threads.all? {|t| t.value}.should == true
+
+ # check that the autoloaded file was evaled exactly once
+ ScratchPad.recorded.get.should == mod_count
+
+ mod_names.each do |mod_name|
+ Object.send(:remove_const, mod_name)
+ end
+ ensure
+ threads.each(&:join) if threads
+ end
+
+ it "raises a NameError in each thread if the constant is not set" do
+ file = fixture(__FILE__, "autoload_never_set.rb")
+ start = false
+
+ threads = Array.new(10) do
+ Thread.new do
+ Thread.pass until start
+ begin
+ ModuleSpecs::Autoload.autoload :NeverSetConstant, file
+ Thread.pass
+ ModuleSpecs::Autoload::NeverSetConstant
+ rescue NameError => e
+ e
+ ensure
+ Thread.pass
end
end
+ end
- # check that no thread got a NoMethodError because of partially loaded module
- threads.all? {|t| t.value}.should be_true
+ start = true
+ threads.each { |t|
+ t.value.should.instance_of?(NameError)
+ }
+ end
- # check that the autoloaded file was evaled exactly once
- ScratchPad.recorded.get.should == mod_count
+ it "raises a LoadError in each thread if the file does not exist" do
+ file = fixture(__FILE__, "autoload_does_not_exist.rb")
+ start = false
- mod_names.each do |mod_name|
- Object.send(:remove_const, mod_name)
+ threads = Array.new(10) do
+ Thread.new do
+ Thread.pass until start
+ begin
+ ModuleSpecs::Autoload.autoload :FileDoesNotExist, file
+ Thread.pass
+ ModuleSpecs::Autoload::FileDoesNotExist
+ rescue LoadError => e
+ e
+ ensure
+ Thread.pass
+ end
end
end
+
+ start = true
+ threads.each { |t|
+ t.value.should.instance_of?(LoadError)
+ }
end
end
diff --git a/spec/ruby/core/module/case_compare_spec.rb b/spec/ruby/core/module/case_compare_spec.rb
index 92f2c2065b..49ac359f6f 100644
--- a/spec/ruby/core/module/case_compare_spec.rb
+++ b/spec/ruby/core/module/case_compare_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Module#===" do
it "returns true when the given Object is an instance of self or of self's descendants" do
diff --git a/spec/ruby/core/module/class_eval_spec.rb b/spec/ruby/core/module/class_eval_spec.rb
index 90deef9c2f..0c190ceaff 100644
--- a/spec/ruby/core/module/class_eval_spec.rb
+++ b/spec/ruby/core/module/class_eval_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/class_eval', __FILE__)
+require_relative '../../spec_helper'
describe "Module#class_eval" do
- it_behaves_like :module_class_eval, :class_eval
+ it "is an alias of Module#module_eval" do
+ Module.instance_method(:class_eval).should == Module.instance_method(:module_eval)
+ end
end
diff --git a/spec/ruby/core/module/class_exec_spec.rb b/spec/ruby/core/module/class_exec_spec.rb
index f9c12cfa48..d47a6ba982 100644
--- a/spec/ruby/core/module/class_exec_spec.rb
+++ b/spec/ruby/core/module/class_exec_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/class_exec', __FILE__)
+require_relative '../../spec_helper'
describe "Module#class_exec" do
- it_behaves_like :module_class_exec, :class_exec
+ it "is an alias of Module#module_exec" do
+ Module.instance_method(:class_exec).should == Module.instance_method(:module_exec)
+ end
end
diff --git a/spec/ruby/core/module/class_variable_defined_spec.rb b/spec/ruby/core/module/class_variable_defined_spec.rb
index d47329455f..dedce9589a 100644
--- a/spec/ruby/core/module/class_variable_defined_spec.rb
+++ b/spec/ruby/core/module/class_variable_defined_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Module#class_variable_defined?" do
it "returns true if a class variable with the given name is defined in self" do
@@ -19,13 +19,13 @@ describe "Module#class_variable_defined?" do
obj = mock("metaclass class variable")
meta = obj.singleton_class
meta.send :class_variable_set, :@@var, 1
- meta.send(:class_variable_defined?, :@@var).should be_true
+ meta.send(:class_variable_defined?, :@@var).should == true
end
it "returns false if the class variable is not defined in a metaclass" do
obj = mock("metaclass class variable")
meta = obj.singleton_class
- meta.class_variable_defined?(:@@var).should be_false
+ meta.class_variable_defined?(:@@var).should == false
end
it "returns true if a class variables with the given name is defined in an included module" do
@@ -42,16 +42,16 @@ describe "Module#class_variable_defined?" do
it "raises a NameError when the given name is not allowed" do
c = Class.new
- lambda {
+ -> {
c.class_variable_defined?(:invalid_name)
- }.should raise_error(NameError)
+ }.should.raise(NameError)
- lambda {
+ -> {
c.class_variable_defined?("@invalid_name")
- }.should raise_error(NameError)
+ }.should.raise(NameError)
end
- it "converts a non string/symbol/fixnum name to string using to_str" do
+ it "converts a non string/symbol name to string using to_str" do
c = Class.new { class_variable_set :@@class_var, "test" }
(o = mock('@@class_var')).should_receive(:to_str).and_return("@@class_var")
c.class_variable_defined?(o).should == true
@@ -60,13 +60,13 @@ describe "Module#class_variable_defined?" do
it "raises a TypeError when the given names can't be converted to strings using to_str" do
c = Class.new { class_variable_set :@@class_var, "test" }
o = mock('123')
- lambda {
+ -> {
c.class_variable_defined?(o)
- }.should raise_error(TypeError)
+ }.should.raise(TypeError)
o.should_receive(:to_str).and_return(123)
- lambda {
+ -> {
c.class_variable_defined?(o)
- }.should raise_error(TypeError)
+ }.should.raise(TypeError)
end
end
diff --git a/spec/ruby/core/module/class_variable_get_spec.rb b/spec/ruby/core/module/class_variable_get_spec.rb
index 7068801cc0..13f06cb94a 100644
--- a/spec/ruby/core/module/class_variable_get_spec.rb
+++ b/spec/ruby/core/module/class_variable_get_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Module#class_variable_get" do
it "returns the value of the class variable with the given name" do
@@ -15,16 +15,16 @@ describe "Module#class_variable_get" do
it "raises a NameError for a class variable named '@@'" do
c = Class.new
- lambda { c.send(:class_variable_get, "@@") }.should raise_error(NameError)
- lambda { c.send(:class_variable_get, :"@@") }.should raise_error(NameError)
+ -> { c.send(:class_variable_get, "@@") }.should.raise(NameError)
+ -> { c.send(:class_variable_get, :"@@") }.should.raise(NameError)
end
it "raises a NameError for a class variables with the given name defined in an extended module" do
c = Class.new
c.extend ModuleSpecs::MVars
- lambda {
+ -> {
c.send(:class_variable_get, "@@mvar")
- }.should raise_error(NameError)
+ }.should.raise(NameError)
end
it "returns class variables defined in the class body and accessed in the metaclass" do
@@ -49,18 +49,18 @@ describe "Module#class_variable_get" do
it "raises a NameError when an uninitialized class variable is accessed" do
c = Class.new
[:@@no_class_var, "@@no_class_var"].each do |cvar|
- lambda { c.send(:class_variable_get, cvar) }.should raise_error(NameError)
+ -> { c.send(:class_variable_get, cvar) }.should.raise(NameError)
end
end
it "raises a NameError when the given name is not allowed" do
c = Class.new
- lambda { c.send(:class_variable_get, :invalid_name) }.should raise_error(NameError)
- lambda { c.send(:class_variable_get, "@invalid_name") }.should raise_error(NameError)
+ -> { c.send(:class_variable_get, :invalid_name) }.should.raise(NameError)
+ -> { c.send(:class_variable_get, "@invalid_name") }.should.raise(NameError)
end
- it "converts a non string/symbol/fixnum name to string using to_str" do
+ it "converts a non string/symbol name to string using to_str" do
c = Class.new { class_variable_set :@@class_var, "test" }
(o = mock('@@class_var')).should_receive(:to_str).and_return("@@class_var")
c.send(:class_variable_get, o).should == "test"
@@ -69,8 +69,8 @@ describe "Module#class_variable_get" do
it "raises a TypeError when the given names can't be converted to strings using to_str" do
c = Class.new { class_variable_set :@@class_var, "test" }
o = mock('123')
- lambda { c.send(:class_variable_get, o) }.should raise_error(TypeError)
+ -> { c.send(:class_variable_get, o) }.should.raise(TypeError)
o.should_receive(:to_str).and_return(123)
- lambda { c.send(:class_variable_get, o) }.should raise_error(TypeError)
+ -> { c.send(:class_variable_get, o) }.should.raise(TypeError)
end
end
diff --git a/spec/ruby/core/module/class_variable_set_spec.rb b/spec/ruby/core/module/class_variable_set_spec.rb
index 6d36298f5f..a3d759767b 100644
--- a/spec/ruby/core/module/class_variable_set_spec.rb
+++ b/spec/ruby/core/module/class_variable_set_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Module#class_variable_set" do
it "sets the class variable with the given name to the given value" do
@@ -25,27 +25,27 @@ describe "Module#class_variable_set" do
c.send(:class_variable_get, "@@mvar").should == :new_mvar
end
- it "raises a RuntimeError when self is frozen" do
- lambda {
+ it "raises a FrozenError when self is frozen" do
+ -> {
Class.new.freeze.send(:class_variable_set, :@@test, "test")
- }.should raise_error(RuntimeError)
- lambda {
+ }.should.raise(FrozenError)
+ -> {
Module.new.freeze.send(:class_variable_set, :@@test, "test")
- }.should raise_error(RuntimeError)
+ }.should.raise(FrozenError)
end
it "raises a NameError when the given name is not allowed" do
c = Class.new
- lambda {
+ -> {
c.send(:class_variable_set, :invalid_name, "test")
- }.should raise_error(NameError)
- lambda {
+ }.should.raise(NameError)
+ -> {
c.send(:class_variable_set, "@invalid_name", "test")
- }.should raise_error(NameError)
+ }.should.raise(NameError)
end
- it "converts a non string/symbol/fixnum name to string using to_str" do
+ it "converts a non string/symbol name to string using to_str" do
(o = mock('@@class_var')).should_receive(:to_str).and_return("@@class_var")
c = Class.new
c.send(:class_variable_set, o, "test")
@@ -55,8 +55,8 @@ describe "Module#class_variable_set" do
it "raises a TypeError when the given names can't be converted to strings using to_str" do
c = Class.new { class_variable_set :@@class_var, "test" }
o = mock('123')
- lambda { c.send(:class_variable_set, o, "test") }.should raise_error(TypeError)
+ -> { c.send(:class_variable_set, o, "test") }.should.raise(TypeError)
o.should_receive(:to_str).and_return(123)
- lambda { c.send(:class_variable_set, o, "test") }.should raise_error(TypeError)
+ -> { c.send(:class_variable_set, o, "test") }.should.raise(TypeError)
end
end
diff --git a/spec/ruby/core/module/class_variables_spec.rb b/spec/ruby/core/module/class_variables_spec.rb
index 066052cd01..9529df48ae 100644
--- a/spec/ruby/core/module/class_variables_spec.rb
+++ b/spec/ruby/core/module/class_variables_spec.rb
@@ -1,10 +1,10 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Module#class_variables" do
it "returns an Array with the names of class variables of self" do
- ModuleSpecs::ClassVars::A.class_variables.should include(:@@a_cvar)
- ModuleSpecs::ClassVars::M.class_variables.should include(:@@m_cvar)
+ ModuleSpecs::ClassVars::A.class_variables.should.include?(:@@a_cvar)
+ ModuleSpecs::ClassVars::M.class_variables.should.include?(:@@m_cvar)
end
it "returns an Array of Symbols of class variable names defined in a metaclass" do
@@ -15,12 +15,20 @@ describe "Module#class_variables" do
end
it "returns an Array with names of class variables defined in metaclasses" do
- ModuleSpecs::CVars.class_variables.should include(:@@cls, :@@meta)
+ ModuleSpecs::CVars.class_variables.to_set.should >= Set[:@@cls, :@@meta]
end
it "does not return class variables defined in extended modules" do
c = Class.new
c.extend ModuleSpecs::MVars
- c.class_variables.should_not include(:@@mvar)
+ c.class_variables.should_not.include?(:@@mvar)
+ end
+
+ it "returns the correct class variables when inherit is given" do
+ ModuleSpecs::SubCVars.class_variables(false).should == [:@@sub]
+ ModuleSpecs::SubCVars.new.singleton_class.class_variables(false).should == []
+
+ ModuleSpecs::SubCVars.class_variables(true).should == [:@@sub, :@@cls, :@@meta]
+ ModuleSpecs::SubCVars.new.singleton_class.class_variables(true).should == [:@@sub, :@@cls, :@@meta]
end
end
diff --git a/spec/ruby/core/module/comparison_spec.rb b/spec/ruby/core/module/comparison_spec.rb
index e7608d64b9..86ee5db22a 100644
--- a/spec/ruby/core/module/comparison_spec.rb
+++ b/spec/ruby/core/module/comparison_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Module#<=>" do
it "returns -1 if self is a subclass of or includes the given module" do
@@ -16,7 +16,7 @@ describe "Module#<=>" do
(ModuleSpecs::Super <=> ModuleSpecs::Super).should == 0
end
- it "returns +1 if self is a superclas of or included by the given module" do
+ it "returns +1 if self is a superclass of or included by the given module" do
(ModuleSpecs::Parent <=> ModuleSpecs::Child).should == +1
(ModuleSpecs::Basic <=> ModuleSpecs::Child).should == +1
(ModuleSpecs::Super <=> ModuleSpecs::Child).should == +1
diff --git a/spec/ruby/core/module/const_added_spec.rb b/spec/ruby/core/module/const_added_spec.rb
new file mode 100644
index 0000000000..b60af7a2e8
--- /dev/null
+++ b/spec/ruby/core/module/const_added_spec.rb
@@ -0,0 +1,238 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'fixtures/const_added'
+
+describe "Module#const_added" do
+ it "is a private instance method" do
+ Module.private_instance_methods(false).should.include?(:const_added)
+ end
+
+ it "returns nil in the default implementation" do
+ Module.new do
+ const_added(:TEST).should == nil
+ end
+ end
+
+ it "for a class defined with the `class` keyword, const_added runs before inherited" do
+ ScratchPad.record []
+
+ mod = Module.new do
+ def self.const_added(_)
+ ScratchPad << :const_added
+ end
+ end
+
+ parent = Class.new do
+ def self.inherited(_)
+ ScratchPad << :inherited
+ end
+ end
+
+ class mod::C < parent; end
+
+ ScratchPad.recorded.should == [:const_added, :inherited]
+ end
+
+ it "the superclass of a class assigned to a constant is set before const_added is called" do
+ ScratchPad.record []
+
+ parent = Class.new do
+ def self.const_added(name)
+ ScratchPad << name
+ ScratchPad << const_get(name).superclass
+ end
+ end
+
+ class parent::C < parent; end
+
+ ScratchPad.recorded.should == [:C, parent]
+ end
+
+ it "is called when a new constant is assigned on self" do
+ ScratchPad.record []
+
+ mod = Module.new do
+ def self.const_added(name)
+ ScratchPad << name
+ end
+ end
+
+ mod.module_eval(<<-RUBY, __FILE__, __LINE__ + 1)
+ TEST = 1
+ RUBY
+
+ ScratchPad.recorded.should == [:TEST]
+ end
+
+ it "is called when a new constant is assigned on self through const_set" do
+ ScratchPad.record []
+
+ mod = Module.new do
+ def self.const_added(name)
+ ScratchPad << name
+ end
+ end
+
+ mod.const_set(:TEST, 1)
+
+ ScratchPad.recorded.should == [:TEST]
+ end
+
+ it "is called when a new module is defined under self" do
+ ScratchPad.record []
+
+ mod = Module.new do
+ def self.const_added(name)
+ ScratchPad << name
+ end
+ end
+
+ mod.module_eval(<<-RUBY, __FILE__, __LINE__ + 1)
+ module SubModule
+ end
+
+ module SubModule
+ end
+ RUBY
+
+ ScratchPad.recorded.should == [:SubModule]
+ end
+
+ it "is called when a new module is defined under a named module (assigned to a constant)" do
+ ScratchPad.record []
+
+ ModuleSpecs::ConstAddedSpecs::NamedModule = Module.new do
+ def self.const_added(name)
+ ScratchPad << name
+ end
+
+ module self::A
+ def self.const_added(name)
+ ScratchPad << name
+ end
+
+ module self::B
+ end
+ end
+ end
+
+ ScratchPad.recorded.should == [:A, :B]
+ ModuleSpecs::ConstAddedSpecs.send :remove_const, :NamedModule
+ end
+
+ it "is called when a new class is defined under self" do
+ ScratchPad.record []
+
+ mod = Module.new do
+ def self.const_added(name)
+ ScratchPad << name
+ end
+ end
+
+ mod.module_eval(<<-RUBY, __FILE__, __LINE__ + 1)
+ class SubClass
+ end
+
+ class SubClass
+ end
+ RUBY
+
+ ScratchPad.recorded.should == [:SubClass]
+ end
+
+ it "is called when a new class is defined under a named module (assigned to a constant)" do
+ ScratchPad.record []
+
+ ModuleSpecs::ConstAddedSpecs::NamedModuleB = Module.new do
+ def self.const_added(name)
+ ScratchPad << name
+ end
+
+ class self::A
+ def self.const_added(name)
+ ScratchPad << name
+ end
+
+ class self::B
+ end
+ end
+ end
+
+ ScratchPad.recorded.should == [:A, :B]
+ ModuleSpecs::ConstAddedSpecs.send :remove_const, :NamedModuleB
+ end
+
+ it "is called when an autoload is defined" do
+ ScratchPad.record []
+
+ mod = Module.new do
+ def self.const_added(name)
+ ScratchPad << name
+ end
+ end
+
+ mod.autoload :Autoload, "foo"
+ ScratchPad.recorded.should == [:Autoload]
+ end
+
+ it "is called with a precise caller location with the line of definition" do
+ ScratchPad.record []
+
+ mod = Module.new do
+ def self.const_added(name)
+ location = caller_locations(1, 1)[0]
+ ScratchPad << location.lineno
+ end
+ end
+
+ line = __LINE__
+ mod.module_eval(<<-RUBY, __FILE__, __LINE__ + 1)
+ TEST = 1
+
+ module SubModule
+ end
+
+ class SubClass
+ end
+ RUBY
+
+ mod.const_set(:CONST_SET, 1)
+
+ ScratchPad.recorded.should == [line + 2, line + 4, line + 7, line + 11]
+ end
+
+ it "is called when the constant is already assigned a value" do
+ ScratchPad.record []
+
+ mod = Module.new do
+ def self.const_added(name)
+ ScratchPad.record const_get(name)
+ end
+ end
+
+ mod.module_eval(<<-RUBY, __FILE__, __LINE__ + 1)
+ TEST = 123
+ RUBY
+
+ ScratchPad.recorded.should == 123
+ end
+
+ it "records re-definition of existing constants" do
+ ScratchPad.record []
+
+ mod = Module.new do
+ def self.const_added(name)
+ ScratchPad << const_get(name)
+ end
+ end
+
+ -> {
+ mod.module_eval(<<-RUBY, __FILE__, __LINE__ + 1)
+ TEST = 123
+ TEST = 456
+ RUBY
+ }.should complain(/warning: already initialized constant .+::TEST/)
+
+ ScratchPad.recorded.should == [123, 456]
+ end
+end
diff --git a/spec/ruby/core/module/const_defined_spec.rb b/spec/ruby/core/module/const_defined_spec.rb
index 0789a03e1c..9d973c2b2b 100644
--- a/spec/ruby/core/module/const_defined_spec.rb
+++ b/spec/ruby/core/module/const_defined_spec.rb
@@ -1,8 +1,8 @@
# encoding: utf-8
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../fixtures/constants', __FILE__)
-require File.expand_path('../fixtures/constant_unicode', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../../fixtures/constants'
+require_relative 'fixtures/constant_unicode'
describe "Module#const_defined?" do
it "returns true if the given Symbol names a constant defined in the receiver" do
@@ -14,30 +14,40 @@ describe "Module#const_defined?" do
it "returns true if the constant is defined in the receiver's superclass" do
# CS_CONST4 is defined in the superclass of ChildA
- ConstantSpecs::ContainerA::ChildA.const_defined?(:CS_CONST4).should be_true
+ ConstantSpecs::ContainerA::ChildA.const_defined?(:CS_CONST4).should == true
end
- it "returns true if the constant is defined in a mixed-in module of the receiver" do
+ it "returns true if the constant is defined in a mixed-in module of the receiver's parent" do
# CS_CONST10 is defined in a module included by ChildA
- ConstantSpecs::ContainerA::ChildA.const_defined?(:CS_CONST10).should be_true
+ ConstantSpecs::ContainerA::ChildA.const_defined?(:CS_CONST10).should == true
+ end
+
+ it "returns true if the constant is defined in a mixed-in module (with prepends) of the receiver" do
+ # CS_CONST11 is defined in the module included by ContainerPrepend
+ ConstantSpecs::ContainerPrepend.const_defined?(:CS_CONST11).should == true
end
it "returns true if the constant is defined in Object and the receiver is a module" do
# CS_CONST1 is defined in Object
- ConstantSpecs::ModuleA.const_defined?(:CS_CONST1).should be_true
+ ConstantSpecs::ModuleA.const_defined?(:CS_CONST1).should == true
end
it "returns true if the constant is defined in Object and the receiver is a class that has Object among its ancestors" do
# CS_CONST1 is defined in Object
- ConstantSpecs::ContainerA::ChildA.const_defined?(:CS_CONST1).should be_true
+ ConstantSpecs::ContainerA::ChildA.const_defined?(:CS_CONST1).should == true
end
it "returns false if the constant is defined in the receiver's superclass and the inherit flag is false" do
- ConstantSpecs::ContainerA::ChildA.const_defined?(:CS_CONST4, false).should be_false
+ ConstantSpecs::ContainerA::ChildA.const_defined?(:CS_CONST4, false).should == false
end
it "returns true if the constant is defined in the receiver's superclass and the inherit flag is true" do
- ConstantSpecs::ContainerA::ChildA.const_defined?(:CS_CONST4, true).should be_true
+ ConstantSpecs::ContainerA::ChildA.const_defined?(:CS_CONST4, true).should == true
+ end
+
+ it "coerces the inherit flag to a boolean" do
+ ConstantSpecs::ContainerA::ChildA.const_defined?(:CS_CONST4, nil).should == false
+ ConstantSpecs::ContainerA::ChildA.const_defined?(:CS_CONST4, :true).should == true
end
it "returns true if the given String names a constant defined in the receiver" do
@@ -48,21 +58,23 @@ describe "Module#const_defined?" do
end
it "returns true when passed a constant name with unicode characters" do
- ConstantUnicodeSpecs.const_defined?("CS_CONSTλ").should be_true
+ ConstantUnicodeSpecs.const_defined?("CS_CONSTλ").should == true
end
it "returns true when passed a constant name with EUC-JP characters" do
str = "CS_CONSTλ".encode("euc-jp")
ConstantSpecs.const_set str, 1
- ConstantSpecs.const_defined?(str).should be_true
+ ConstantSpecs.const_defined?(str).should == true
+ ensure
+ ConstantSpecs.send(:remove_const, str)
end
it "returns false if the constant is not defined in the receiver, its superclass, or any included modules" do
# The following constant isn't defined at all.
- ConstantSpecs::ContainerA::ChildA.const_defined?(:CS_CONST4726).should be_false
+ ConstantSpecs::ContainerA::ChildA.const_defined?(:CS_CONST4726).should == false
# DETACHED_CONSTANT is defined in ConstantSpecs::Detached, which isn't
# included by or inherited from ParentA
- ConstantSpecs::ParentA.const_defined?(:DETACHED_CONSTANT).should be_false
+ ConstantSpecs::ParentA.const_defined?(:DETACHED_CONSTANT).should == false
end
it "does not call #const_missing if the constant is not defined in the receiver" do
@@ -70,54 +82,67 @@ describe "Module#const_defined?" do
ConstantSpecs::ClassA.const_defined?(:CS_CONSTX).should == false
end
- it "calls #to_str to convert the given name to a String" do
- name = mock("ClassA")
- name.should_receive(:to_str).and_return("ClassA")
- ConstantSpecs.const_defined?(name).should == true
+ describe "converts the given name to a String using #to_str" do
+ it "calls #to_str to convert the given name to a String" do
+ name = mock("ClassA")
+ name.should_receive(:to_str).and_return("ClassA")
+ ConstantSpecs.const_defined?(name).should == true
+ end
+
+ it "raises a TypeError if the given name can't be converted to a String" do
+ -> { ConstantSpecs.const_defined?(nil) }.should.raise(TypeError)
+ -> { ConstantSpecs.const_defined?([]) }.should.raise(TypeError)
+ end
+
+ it "raises a NoMethodError if the given argument raises a NoMethodError during type coercion to a String" do
+ name = mock("classA")
+ name.should_receive(:to_str).and_raise(NoMethodError)
+ -> { ConstantSpecs.const_defined?(name) }.should.raise(NoMethodError)
+ end
end
it "special cases Object and checks it's included Modules" do
- Object.const_defined?(:CS_CONST10).should be_true
+ Object.const_defined?(:CS_CONST10).should == true
end
it "returns true for toplevel constant when the name begins with '::'" do
- ConstantSpecs.const_defined?("::Array").should be_true
+ ConstantSpecs.const_defined?("::Array").should == true
end
it "returns true when passed a scoped constant name" do
- ConstantSpecs.const_defined?("ClassC::CS_CONST1").should be_true
+ ConstantSpecs.const_defined?("ClassC::CS_CONST1").should == true
end
it "returns true when passed a scoped constant name for a constant in the inheritance hierarchy and the inherited flag is default" do
- ConstantSpecs::ClassD.const_defined?("ClassE::CS_CONST2").should be_true
+ ConstantSpecs::ClassD.const_defined?("ClassE::CS_CONST2").should == true
end
it "returns true when passed a scoped constant name for a constant in the inheritance hierarchy and the inherited flag is true" do
- ConstantSpecs::ClassD.const_defined?("ClassE::CS_CONST2", true).should be_true
+ ConstantSpecs::ClassD.const_defined?("ClassE::CS_CONST2", true).should == true
end
it "returns false when passed a scoped constant name for a constant in the inheritance hierarchy and the inherited flag is false" do
- ConstantSpecs::ClassD.const_defined?("ClassE::CS_CONST2", false).should be_false
+ ConstantSpecs::ClassD.const_defined?("ClassE::CS_CONST2", false).should == false
end
it "returns false when the name begins with '::' and the toplevel constant does not exist" do
- ConstantSpecs.const_defined?("::Name").should be_false
+ ConstantSpecs.const_defined?("::Name").should == false
end
it "raises a NameError if the name does not start with a capital letter" do
- lambda { ConstantSpecs.const_defined? "name" }.should raise_error(NameError)
+ -> { ConstantSpecs.const_defined? "name" }.should.raise(NameError)
end
it "raises a NameError if the name starts with '_'" do
- lambda { ConstantSpecs.const_defined? "__CONSTX__" }.should raise_error(NameError)
+ -> { ConstantSpecs.const_defined? "__CONSTX__" }.should.raise(NameError)
end
it "raises a NameError if the name starts with '@'" do
- lambda { ConstantSpecs.const_defined? "@Name" }.should raise_error(NameError)
+ -> { ConstantSpecs.const_defined? "@Name" }.should.raise(NameError)
end
it "raises a NameError if the name starts with '!'" do
- lambda { ConstantSpecs.const_defined? "!Name" }.should raise_error(NameError)
+ -> { ConstantSpecs.const_defined? "!Name" }.should.raise(NameError)
end
it "returns true or false for the nested name" do
@@ -130,15 +155,15 @@ describe "Module#const_defined?" do
it "raises a NameError if the name contains non-alphabetic characters except '_'" do
ConstantSpecs.const_defined?("CS_CONSTX").should == false
- lambda { ConstantSpecs.const_defined? "Name=" }.should raise_error(NameError)
- lambda { ConstantSpecs.const_defined? "Name?" }.should raise_error(NameError)
+ -> { ConstantSpecs.const_defined? "Name=" }.should.raise(NameError)
+ -> { ConstantSpecs.const_defined? "Name?" }.should.raise(NameError)
end
it "raises a TypeError if conversion to a String by calling #to_str fails" do
name = mock('123')
- lambda { ConstantSpecs.const_defined? name }.should raise_error(TypeError)
+ -> { ConstantSpecs.const_defined? name }.should.raise(TypeError)
name.should_receive(:to_str).and_return(123)
- lambda { ConstantSpecs.const_defined? name }.should raise_error(TypeError)
+ -> { ConstantSpecs.const_defined? name }.should.raise(TypeError)
end
end
diff --git a/spec/ruby/core/module/const_get_spec.rb b/spec/ruby/core/module/const_get_spec.rb
index 6f8d5d930f..68b5594faa 100644
--- a/spec/ruby/core/module/const_get_spec.rb
+++ b/spec/ruby/core/module/const_get_spec.rb
@@ -1,5 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../fixtures/constants', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../../fixtures/constants'
+require_relative 'fixtures/constants_autoload'
describe "Module#const_get" do
it "accepts a String or Symbol name" do
@@ -8,28 +9,28 @@ describe "Module#const_get" do
end
it "raises a NameError if no constant is defined in the search path" do
- lambda { ConstantSpecs.const_get :CS_CONSTX }.should raise_error(NameError)
+ -> { ConstantSpecs.const_get :CS_CONSTX }.should.raise(NameError)
end
it "raises a NameError with the not found constant symbol" do
- error_inspection = lambda { |e| e.name.should == :CS_CONSTX }
- lambda { ConstantSpecs.const_get :CS_CONSTX }.should raise_error(NameError, &error_inspection)
+ error_inspection = -> e { e.name.should == :CS_CONSTX }
+ -> { ConstantSpecs.const_get :CS_CONSTX }.should.raise(NameError, &error_inspection)
end
it "raises a NameError if the name does not start with a capital letter" do
- lambda { ConstantSpecs.const_get "name" }.should raise_error(NameError)
+ -> { ConstantSpecs.const_get "name" }.should.raise(NameError)
end
it "raises a NameError if the name starts with a non-alphabetic character" do
- lambda { ConstantSpecs.const_get "__CONSTX__" }.should raise_error(NameError)
- lambda { ConstantSpecs.const_get "@CS_CONST1" }.should raise_error(NameError)
- lambda { ConstantSpecs.const_get "!CS_CONST1" }.should raise_error(NameError)
+ -> { ConstantSpecs.const_get "__CONSTX__" }.should.raise(NameError)
+ -> { ConstantSpecs.const_get "@CS_CONST1" }.should.raise(NameError)
+ -> { ConstantSpecs.const_get "!CS_CONST1" }.should.raise(NameError)
end
it "raises a NameError if the name contains non-alphabetic characters except '_'" do
Object.const_get("CS_CONST1").should == :const1
- lambda { ConstantSpecs.const_get "CS_CONST1=" }.should raise_error(NameError)
- lambda { ConstantSpecs.const_get "CS_CONST1?" }.should raise_error(NameError)
+ -> { ConstantSpecs.const_get "CS_CONST1=" }.should.raise(NameError)
+ -> { ConstantSpecs.const_get "CS_CONST1?" }.should.raise(NameError)
end
it "calls #to_str to convert the given name to a String" do
@@ -40,10 +41,10 @@ describe "Module#const_get" do
it "raises a TypeError if conversion to a String by calling #to_str fails" do
name = mock('123')
- lambda { ConstantSpecs.const_get(name) }.should raise_error(TypeError)
+ -> { ConstantSpecs.const_get(name) }.should.raise(TypeError)
name.should_receive(:to_str).and_return(123)
- lambda { ConstantSpecs.const_get(name) }.should raise_error(TypeError)
+ -> { ConstantSpecs.const_get(name) }.should.raise(TypeError)
end
it "calls #const_missing on the receiver if unable to locate the constant" do
@@ -52,23 +53,23 @@ describe "Module#const_get" do
end
it "does not search the singleton class of a Class or Module" do
- lambda do
+ -> do
ConstantSpecs::ContainerA::ChildA.const_get(:CS_CONST14)
- end.should raise_error(NameError)
- lambda { ConstantSpecs.const_get(:CS_CONST14) }.should raise_error(NameError)
+ end.should.raise(NameError)
+ -> { ConstantSpecs.const_get(:CS_CONST14) }.should.raise(NameError)
end
it "does not search the containing scope" do
ConstantSpecs::ContainerA::ChildA.const_get(:CS_CONST20).should == :const20_2
- lambda do
+ -> do
ConstantSpecs::ContainerA::ChildA.const_get(:CS_CONST5)
- end.should raise_error(NameError)
+ end.should.raise(NameError)
end
- it "raises a NameError if the constant is defined in the receiver's supperclass and the inherit flag is false" do
- lambda do
+ it "raises a NameError if the constant is defined in the receiver's superclass and the inherit flag is false" do
+ -> do
ConstantSpecs::ContainerA::ChildA.const_get(:CS_CONST4, false)
- end.should raise_error(NameError)
+ end.should.raise(NameError)
end
it "searches into the receiver superclasses if the inherit flag is true" do
@@ -76,39 +77,81 @@ describe "Module#const_get" do
end
it "raises a NameError when the receiver is a Module, the constant is defined at toplevel and the inherit flag is false" do
- lambda do
+ -> do
ConstantSpecs::ModuleA.const_get(:CS_CONST1, false)
- end.should raise_error(NameError)
+ end.should.raise(NameError)
end
it "raises a NameError when the receiver is a Class, the constant is defined at toplevel and the inherit flag is false" do
- lambda do
+ -> do
ConstantSpecs::ContainerA::ChildA.const_get(:CS_CONST1, false)
- end.should raise_error(NameError)
+ end.should.raise(NameError)
+ end
+
+ it "coerces the inherit flag to a boolean" do
+ ConstantSpecs::ContainerA::ChildA.const_get(:CS_CONST4, :true).should == :const4
+
+ -> do
+ ConstantSpecs::ContainerA::ChildA.const_get(:CS_CONST1, nil)
+ end.should.raise(NameError)
end
it "accepts a toplevel scope qualifier" do
ConstantSpecs.const_get("::CS_CONST1").should == :const1
end
+ it "accepts a toplevel scope qualifier when inherit is false" do
+ ConstantSpecs.const_get("::CS_CONST1", false).should == :const1
+ -> { ConstantSpecs.const_get("CS_CONST1", false) }.should.raise(NameError)
+ end
+
+ it "returns a constant whose module is defined the toplevel" do
+ ConstantSpecs.const_get("ConstantSpecsTwo::Foo").should == :cs_two_foo
+ ConstantSpecsThree.const_get("ConstantSpecsTwo::Foo").should == :cs_three_foo
+ end
+
it "accepts a scoped constant name" do
ConstantSpecs.const_get("ClassA::CS_CONST10").should == :const10_10
end
+ it "raises a NameError if the name includes two successive scope separators" do
+ -> { ConstantSpecs.const_get("ClassA::::CS_CONST10") }.should.raise(NameError)
+ end
+
it "raises a NameError if only '::' is passed" do
- lambda { ConstantSpecs.const_get("::") }.should raise_error(NameError)
+ -> { ConstantSpecs.const_get("::") }.should.raise(NameError)
end
it "raises a NameError if a Symbol has a toplevel scope qualifier" do
- lambda { ConstantSpecs.const_get(:'::CS_CONST1') }.should raise_error(NameError)
+ -> { ConstantSpecs.const_get(:'::CS_CONST1') }.should.raise(NameError)
end
it "raises a NameError if a Symbol is a scoped constant name" do
- lambda { ConstantSpecs.const_get(:'ClassA::CS_CONST10') }.should raise_error(NameError)
+ -> { ConstantSpecs.const_get(:'ClassA::CS_CONST10') }.should.raise(NameError)
end
it "does read private constants" do
- ConstantSpecs.const_get(:CS_PRIVATE).should == :cs_private
+ ConstantSpecs.const_get(:CS_PRIVATE).should == :cs_private
+ end
+
+ it 'does autoload a constant' do
+ Object.const_get('CSAutoloadA').name.should == 'CSAutoloadA'
+ end
+
+ it 'does autoload a constant with a toplevel scope qualifier' do
+ Object.const_get('::CSAutoloadB').name.should == 'CSAutoloadB'
+ end
+
+ it 'does autoload a module and resolve a constant within' do
+ Object.const_get('CSAutoloadC::CONST').should == 7
+ end
+
+ it 'does autoload a non-toplevel module' do
+ Object.const_get('CSAutoloadD::InnerModule').name.should == 'CSAutoloadD::InnerModule'
+ end
+
+ it "raises a NameError when the nested constant does not exist on the module but exists in Object" do
+ -> { Object.const_get('ConstantSpecs::CS_CONST1') }.should.raise(NameError)
end
describe "with statically assigned constants" do
@@ -159,50 +202,72 @@ describe "Module#const_get" do
ConstantSpecs::ContainerA::ChildA::CS_CONST301 = :const301_5
ConstantSpecs::ContainerA::ChildA.const_get(:CS_CONST301).should == :const301_5
+ ensure
+ ConstantSpecs::ClassA.send(:remove_const, :CS_CONST301)
+ ConstantSpecs::ModuleA.send(:remove_const, :CS_CONST301)
+ ConstantSpecs::ParentA.send(:remove_const, :CS_CONST301)
+ ConstantSpecs::ContainerA::ChildA.send(:remove_const, :CS_CONST301)
end
it "searches a module included in the immediate class before the superclass" do
ConstantSpecs::ParentB::CS_CONST302 = :const302_1
ConstantSpecs::ModuleF::CS_CONST302 = :const302_2
ConstantSpecs::ContainerB::ChildB.const_get(:CS_CONST302).should == :const302_2
+ ensure
+ ConstantSpecs::ParentB.send(:remove_const, :CS_CONST302)
+ ConstantSpecs::ModuleF.send(:remove_const, :CS_CONST302)
end
it "searches the superclass before a module included in the superclass" do
ConstantSpecs::ModuleE::CS_CONST303 = :const303_1
ConstantSpecs::ParentB::CS_CONST303 = :const303_2
ConstantSpecs::ContainerB::ChildB.const_get(:CS_CONST303).should == :const303_2
+ ensure
+ ConstantSpecs::ModuleE.send(:remove_const, :CS_CONST303)
+ ConstantSpecs::ParentB.send(:remove_const, :CS_CONST303)
end
it "searches a module included in the superclass" do
ConstantSpecs::ModuleA::CS_CONST304 = :const304_1
ConstantSpecs::ModuleE::CS_CONST304 = :const304_2
ConstantSpecs::ContainerB::ChildB.const_get(:CS_CONST304).should == :const304_2
+ ensure
+ ConstantSpecs::ModuleA.send(:remove_const, :CS_CONST304)
+ ConstantSpecs::ModuleE.send(:remove_const, :CS_CONST304)
end
it "searches the superclass chain" do
ConstantSpecs::ModuleA::CS_CONST305 = :const305
ConstantSpecs::ContainerB::ChildB.const_get(:CS_CONST305).should == :const305
+ ensure
+ ConstantSpecs::ModuleA.send(:remove_const, :CS_CONST305)
end
it "returns a toplevel constant when the receiver is a Class" do
Object::CS_CONST306 = :const306
ConstantSpecs::ContainerB::ChildB.const_get(:CS_CONST306).should == :const306
+ ensure
+ Object.send(:remove_const, :CS_CONST306)
end
it "returns a toplevel constant when the receiver is a Module" do
Object::CS_CONST308 = :const308
ConstantSpecs.const_get(:CS_CONST308).should == :const308
ConstantSpecs::ModuleA.const_get(:CS_CONST308).should == :const308
+ ensure
+ Object.send(:remove_const, :CS_CONST308)
end
it "returns the updated value of a constant" do
ConstantSpecs::ClassB::CS_CONST309 = :const309_1
ConstantSpecs::ClassB.const_get(:CS_CONST309).should == :const309_1
- lambda {
+ -> {
ConstantSpecs::ClassB::CS_CONST309 = :const309_2
}.should complain(/already initialized constant/)
ConstantSpecs::ClassB.const_get(:CS_CONST309).should == :const309_2
+ ensure
+ ConstantSpecs::ClassB.send(:remove_const, :CS_CONST309)
end
end
end
diff --git a/spec/ruby/core/module/const_missing_spec.rb b/spec/ruby/core/module/const_missing_spec.rb
index 24f2b49edc..80a2caccab 100644
--- a/spec/ruby/core/module/const_missing_spec.rb
+++ b/spec/ruby/core/module/const_missing_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../fixtures/constants', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../../fixtures/constants'
describe "Module#const_missing" do
it "is called when an undefined constant is referenced via literal form" do
@@ -11,9 +11,9 @@ describe "Module#const_missing" do
end
it "raises NameError and includes the name of the value that wasn't found" do
- lambda {
+ -> {
ConstantSpecs.const_missing("HelloMissing")
- }.should raise_error(NameError, /ConstantSpecs::HelloMissing/)
+ }.should.raise(NameError, /ConstantSpecs::HelloMissing/)
end
it "raises NameError and does not include toplevel Object" do
@@ -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/const_set_spec.rb b/spec/ruby/core/module/const_set_spec.rb
index 6f4f6f980f..aa3c6bbcfc 100644
--- a/spec/ruby/core/module/const_set_spec.rb
+++ b/spec/ruby/core/module/const_set_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../fixtures/constants', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../../fixtures/constants'
describe "Module#const_set" do
it "sets the constant specified by a String or Symbol to the given value" do
@@ -8,22 +8,29 @@ describe "Module#const_set" do
ConstantSpecs.const_set "CS_CONST402", :const402
ConstantSpecs.const_get(:CS_CONST402).should == :const402
+ ensure
+ ConstantSpecs.send(:remove_const, :CS_CONST401)
+ ConstantSpecs.send(:remove_const, :CS_CONST402)
end
it "returns the value set" do
ConstantSpecs.const_set(:CS_CONST403, :const403).should == :const403
+ ensure
+ ConstantSpecs.send(:remove_const, :CS_CONST403)
end
it "sets the name of an anonymous module" do
m = Module.new
ConstantSpecs.const_set(:CS_CONST1000, m)
m.name.should == "ConstantSpecs::CS_CONST1000"
+ ensure
+ ConstantSpecs.send(:remove_const, :CS_CONST1000)
end
- it "does not set the name of a module scoped by an anonymous module" do
+ it "sets the name of a module scoped by an anonymous module" do
a, b = Module.new, Module.new
a.const_set :B, b
- b.name.should be_nil
+ b.name.should.end_with? '::B'
end
it "sets the name of contained modules when assigning a toplevel anonymous module" do
@@ -38,23 +45,27 @@ describe "Module#const_set" do
b.name.should == "ModuleSpecs_CS3::B"
c.name.should == "ModuleSpecs_CS3::B::C"
d.name.should == "ModuleSpecs_CS3::D"
+ ensure
+ Object.send(:remove_const, :ModuleSpecs_CS3)
end
it "raises a NameError if the name does not start with a capital letter" do
- lambda { ConstantSpecs.const_set "name", 1 }.should raise_error(NameError)
+ -> { ConstantSpecs.const_set "name", 1 }.should.raise(NameError)
end
it "raises a NameError if the name starts with a non-alphabetic character" do
- lambda { ConstantSpecs.const_set "__CONSTX__", 1 }.should raise_error(NameError)
- lambda { ConstantSpecs.const_set "@Name", 1 }.should raise_error(NameError)
- lambda { ConstantSpecs.const_set "!Name", 1 }.should raise_error(NameError)
- lambda { ConstantSpecs.const_set "::Name", 1 }.should raise_error(NameError)
+ -> { ConstantSpecs.const_set "__CONSTX__", 1 }.should.raise(NameError)
+ -> { ConstantSpecs.const_set "@Name", 1 }.should.raise(NameError)
+ -> { ConstantSpecs.const_set "!Name", 1 }.should.raise(NameError)
+ -> { ConstantSpecs.const_set "::Name", 1 }.should.raise(NameError)
end
it "raises a NameError if the name contains non-alphabetic characters except '_'" do
ConstantSpecs.const_set("CS_CONST404", :const404).should == :const404
- lambda { ConstantSpecs.const_set "Name=", 1 }.should raise_error(NameError)
- lambda { ConstantSpecs.const_set "Name?", 1 }.should raise_error(NameError)
+ -> { ConstantSpecs.const_set "Name=", 1 }.should.raise(NameError)
+ -> { ConstantSpecs.const_set "Name?", 1 }.should.raise(NameError)
+ ensure
+ ConstantSpecs.send(:remove_const, :CS_CONST404)
end
it "calls #to_str to convert the given name to a String" do
@@ -62,14 +73,62 @@ describe "Module#const_set" do
name.should_receive(:to_str).and_return("CS_CONST405")
ConstantSpecs.const_set(name, :const405).should == :const405
ConstantSpecs::CS_CONST405.should == :const405
+ ensure
+ ConstantSpecs.send(:remove_const, :CS_CONST405)
end
it "raises a TypeError if conversion to a String by calling #to_str fails" do
name = mock('123')
- lambda { ConstantSpecs.const_set name, 1 }.should raise_error(TypeError)
+ -> { ConstantSpecs.const_set name, 1 }.should.raise(TypeError)
name.should_receive(:to_str).and_return(123)
- lambda { ConstantSpecs.const_set name, 1 }.should raise_error(TypeError)
+ -> { ConstantSpecs.const_set name, 1 }.should.raise(TypeError)
+ end
+
+ describe "when overwriting an existing constant" do
+ it "warns if the previous value was a normal value" do
+ mod = Module.new
+ mod.const_set :Foo, 42
+ -> {
+ mod.const_set :Foo, 1
+ }.should complain(/already initialized constant/)
+ mod.const_get(:Foo).should == 1
+ end
+
+ it "does not warn if the previous value was an autoload" do
+ mod = Module.new
+ mod.autoload :Foo, "not-existing"
+ -> {
+ mod.const_set :Foo, 1
+ }.should_not complain
+ mod.const_get(:Foo).should == 1
+ end
+
+ it "does not warn after a failed autoload" do
+ path = fixture(__FILE__, "autoload_o.rb")
+ ScratchPad.record []
+ mod = Module.new
+
+ mod.autoload :Foo, path
+ -> { mod::Foo }.should.raise(NameError)
+
+ mod.const_defined?(:Foo).should == false
+ mod.autoload?(:Foo).should == nil
+
+ -> {
+ mod.const_set :Foo, 1
+ }.should_not complain
+ mod.const_get(:Foo).should == 1
+ end
+
+ it "does not warn if the new value is an autoload" do
+ mod = Module.new
+ mod.const_set :Foo, 42
+ -> {
+ mod.autoload :Foo, "not-existing"
+ }.should_not complain
+ mod.const_get(:Foo).should == 42
+ end
end
describe "on a frozen module" do
@@ -78,9 +137,9 @@ describe "Module#const_set" do
@name = :Foo
end
- it "raises a RuntimeError before setting the name" do
- lambda { @frozen.const_set @name, nil }.should raise_error(RuntimeError)
- @frozen.should_not have_constant(@name)
+ it "raises a FrozenError before setting the name" do
+ -> { @frozen.const_set @name, nil }.should.raise(FrozenError)
+ @frozen.should_not.const_defined?(@name)
end
end
end
diff --git a/spec/ruby/core/module/const_source_location_spec.rb b/spec/ruby/core/module/const_source_location_spec.rb
new file mode 100644
index 0000000000..e6cef727e2
--- /dev/null
+++ b/spec/ruby/core/module/const_source_location_spec.rb
@@ -0,0 +1,281 @@
+require_relative '../../spec_helper'
+require_relative '../../fixtures/constants'
+
+describe "Module#const_source_location" do
+ before do
+ @constants_fixture_path = File.expand_path('../../fixtures/constants.rb', __dir__)
+ end
+
+ describe "with dynamically assigned constants" do
+ it "searches a path in the immediate class or module first" do
+ ConstantSpecs::ClassA::CSL_CONST301 = :const301_1
+ ConstantSpecs::ClassA.const_source_location(:CSL_CONST301).should == [__FILE__, __LINE__ - 1]
+
+ ConstantSpecs::ModuleA::CSL_CONST301 = :const301_2
+ ConstantSpecs::ModuleA.const_source_location(:CSL_CONST301).should == [__FILE__, __LINE__ - 1]
+
+ ConstantSpecs::ParentA::CSL_CONST301 = :const301_3
+ ConstantSpecs::ParentA.const_source_location(:CSL_CONST301).should == [__FILE__, __LINE__ - 1]
+
+ ConstantSpecs::ContainerA::ChildA::CSL_CONST301 = :const301_5
+ ConstantSpecs::ContainerA::ChildA.const_source_location(:CSL_CONST301).should == [__FILE__, __LINE__ - 1]
+ ensure
+ ConstantSpecs::ClassA.send(:remove_const, :CSL_CONST301)
+ ConstantSpecs::ModuleA.send(:remove_const, :CSL_CONST301)
+ ConstantSpecs::ParentA.send(:remove_const, :CSL_CONST301)
+ ConstantSpecs::ContainerA::ChildA.send(:remove_const, :CSL_CONST301)
+ end
+
+ it "searches a path in a module included in the immediate class before the superclass" do
+ ConstantSpecs::ParentB::CSL_CONST302 = :const302_1
+ ConstantSpecs::ModuleF::CSL_CONST302 = :const302_2
+ ConstantSpecs::ContainerB::ChildB.const_source_location(:CSL_CONST302).should == [__FILE__, __LINE__ - 1]
+ ensure
+ ConstantSpecs::ParentB.send(:remove_const, :CSL_CONST302)
+ ConstantSpecs::ModuleF.send(:remove_const, :CSL_CONST302)
+ end
+
+ it "searches a path in the superclass before a module included in the superclass" do
+ ConstantSpecs::ModuleE::CSL_CONST303 = :const303_1
+ ConstantSpecs::ParentB::CSL_CONST303 = :const303_2
+ ConstantSpecs::ContainerB::ChildB.const_source_location(:CSL_CONST303).should == [__FILE__, __LINE__ - 1]
+ ensure
+ ConstantSpecs::ModuleE.send(:remove_const, :CSL_CONST303)
+ ConstantSpecs::ParentB.send(:remove_const, :CSL_CONST303)
+ end
+
+ it "searches a path in a module included in the superclass" do
+ ConstantSpecs::ModuleA::CSL_CONST304 = :const304_1
+ ConstantSpecs::ModuleE::CSL_CONST304 = :const304_2
+ ConstantSpecs::ContainerB::ChildB.const_source_location(:CSL_CONST304).should == [__FILE__, __LINE__ - 1]
+ ensure
+ ConstantSpecs::ModuleA.send(:remove_const, :CSL_CONST304)
+ ConstantSpecs::ModuleE.send(:remove_const, :CSL_CONST304)
+ end
+
+ it "searches a path in the superclass chain" do
+ ConstantSpecs::ModuleA::CSL_CONST305 = :const305
+ ConstantSpecs::ContainerB::ChildB.const_source_location(:CSL_CONST305).should == [__FILE__, __LINE__ - 1]
+ ensure
+ ConstantSpecs::ModuleA.send(:remove_const, :CSL_CONST305)
+ end
+
+ it "returns path to a toplevel constant when the receiver is a Class" do
+ Object::CSL_CONST306 = :const306
+ ConstantSpecs::ContainerB::ChildB.const_source_location(:CSL_CONST306).should == [__FILE__, __LINE__ - 1]
+ ensure
+ Object.send(:remove_const, :CSL_CONST306)
+ end
+
+ it "returns path to a toplevel constant when the receiver is a Module" do
+ Object::CSL_CONST308 = :const308
+ ConstantSpecs.const_source_location(:CSL_CONST308).should == [__FILE__, __LINE__ - 1]
+ ConstantSpecs::ModuleA.const_source_location(:CSL_CONST308).should == [__FILE__, __LINE__ - 2]
+ ensure
+ Object.send(:remove_const, :CSL_CONST308)
+ end
+
+ it "returns path to the updated value of a constant" do
+ ConstantSpecs::ClassB::CSL_CONST309 = :const309_1
+ ConstantSpecs::ClassB.const_source_location(:CSL_CONST309).should == [__FILE__, __LINE__ - 1]
+
+ -> {
+ ConstantSpecs::ClassB::CSL_CONST309 = :const309_2
+ }.should complain(/already initialized constant/)
+ ConstantSpecs::ClassB.const_source_location(:CSL_CONST309).should == [__FILE__, __LINE__ - 2]
+ ensure
+ ConstantSpecs::ClassB.send(:remove_const, :CSL_CONST309)
+ end
+ end
+
+ describe "with statically assigned constants" do
+ it "works for the module and class keywords" do
+ ConstantSpecs.const_source_location(:ModuleB).should == [@constants_fixture_path, ConstantSpecs::ModuleB::LINE]
+ ConstantSpecs.const_source_location(:ClassA).should == [@constants_fixture_path, ConstantSpecs::ClassA::LINE]
+ end
+
+ it "searches location path the immediate class or module first" do
+ ConstantSpecs::ClassA.const_source_location(:CS_CONST10).should == [@constants_fixture_path, ConstantSpecs::ClassA::CS_CONST10_LINE]
+ ConstantSpecs::ModuleA.const_source_location(:CS_CONST10).should == [@constants_fixture_path, ConstantSpecs::ModuleA::CS_CONST10_LINE]
+ ConstantSpecs::ParentA.const_source_location(:CS_CONST10).should == [@constants_fixture_path, ConstantSpecs::ParentA::CS_CONST10_LINE]
+ ConstantSpecs::ContainerA.const_source_location(:CS_CONST10).should == [@constants_fixture_path, ConstantSpecs::ContainerA::CS_CONST10_LINE]
+ ConstantSpecs::ContainerA::ChildA.const_source_location(:CS_CONST10).should == [@constants_fixture_path, ConstantSpecs::ContainerA::ChildA::CS_CONST10_LINE]
+ end
+
+ it "searches location path a module included in the immediate class before the superclass" do
+ ConstantSpecs::ContainerA::ChildA.const_source_location(:CS_CONST15).should == [@constants_fixture_path, ConstantSpecs::ModuleC::CS_CONST15_LINE]
+ end
+
+ it "searches location path the superclass before a module included in the superclass" do
+ ConstantSpecs::ContainerA::ChildA.const_source_location(:CS_CONST11).should == [@constants_fixture_path, ConstantSpecs::ParentA::CS_CONST11_LINE]
+ end
+
+ it "searches location path a module included in the superclass" do
+ ConstantSpecs::ContainerA::ChildA.const_source_location(:CS_CONST12).should == [@constants_fixture_path, ConstantSpecs::ModuleB::CS_CONST12_LINE]
+ end
+
+ it "searches location path the superclass chain" do
+ ConstantSpecs::ContainerA::ChildA.const_source_location(:CS_CONST13).should == [@constants_fixture_path, ConstantSpecs::ModuleA::CS_CONST13_LINE]
+ end
+
+ it "returns location path a toplevel constant when the receiver is a Class" do
+ ConstantSpecs::ContainerA::ChildA.const_source_location(:CS_CONST1).should == [@constants_fixture_path, CS_CONST1_LINE]
+ end
+
+ it "returns location path a toplevel constant when the receiver is a Module" do
+ ConstantSpecs.const_source_location(:CS_CONST1).should == [@constants_fixture_path, CS_CONST1_LINE]
+ ConstantSpecs::ModuleA.const_source_location(:CS_CONST1).should == [@constants_fixture_path, CS_CONST1_LINE]
+ end
+ end
+
+ it "return empty path if constant defined in C code" do
+ Object.const_source_location(:String).should == []
+ end
+
+ it "accepts a String or Symbol name" do
+ Object.const_source_location(:CS_CONST1).should == [@constants_fixture_path, CS_CONST1_LINE]
+ Object.const_source_location("CS_CONST1").should == [@constants_fixture_path, CS_CONST1_LINE]
+ end
+
+ it "returns nil if no constant is defined in the search path" do
+ ConstantSpecs.const_source_location(:CS_CONSTX).should == nil
+ end
+
+ it "raises a NameError if the name does not start with a capital letter" do
+ -> { ConstantSpecs.const_source_location "name" }.should.raise(NameError)
+ end
+
+ it "raises a NameError if the name starts with a non-alphabetic character" do
+ -> { ConstantSpecs.const_source_location "__CONSTX__" }.should.raise(NameError)
+ -> { ConstantSpecs.const_source_location "@CS_CONST1" }.should.raise(NameError)
+ -> { ConstantSpecs.const_source_location "!CS_CONST1" }.should.raise(NameError)
+ end
+
+ it "raises a NameError if the name contains non-alphabetic characters except '_'" do
+ Object.const_source_location("CS_CONST1").should == [@constants_fixture_path, CS_CONST1_LINE]
+ -> { ConstantSpecs.const_source_location "CS_CONST1=" }.should.raise(NameError)
+ -> { ConstantSpecs.const_source_location "CS_CONST1?" }.should.raise(NameError)
+ end
+
+ it "calls #to_str to convert the given name to a String" do
+ name = mock("ClassA")
+ name.should_receive(:to_str).and_return("ClassA")
+ ConstantSpecs.const_source_location(name).should == [@constants_fixture_path, ConstantSpecs::ClassA::LINE]
+ end
+
+ it "raises a TypeError if conversion to a String by calling #to_str fails" do
+ name = mock('123')
+ -> { ConstantSpecs.const_source_location(name) }.should.raise(TypeError)
+
+ name.should_receive(:to_str).and_return(123)
+ -> { ConstantSpecs.const_source_location(name) }.should.raise(TypeError)
+ end
+
+ it "does not search the singleton class of a Class or Module" do
+ ConstantSpecs::ContainerA::ChildA.const_source_location(:CS_CONST14).should == nil
+ ConstantSpecs.const_source_location(:CS_CONST14).should == nil
+ end
+
+ it "does not search the containing scope" do
+ ConstantSpecs::ContainerA::ChildA.const_source_location(:CS_CONST20).should == [@constants_fixture_path, ConstantSpecs::ParentA::CS_CONST20_LINE]
+ ConstantSpecs::ContainerA::ChildA.const_source_location(:CS_CONST5) == nil
+ end
+
+ it "returns nil if the constant is defined in the receiver's superclass and the inherit flag is false" do
+ ConstantSpecs::ContainerA::ChildA.const_source_location(:CS_CONST4, false).should == nil
+ end
+
+ it "searches into the receiver superclasses if the inherit flag is true" do
+ ConstantSpecs::ContainerA::ChildA.const_source_location(:CS_CONST4, true).should == [@constants_fixture_path, ConstantSpecs::ParentA::CS_CONST4_LINE]
+ end
+
+ it "returns nil when the receiver is a Module, the constant is defined at toplevel and the inherit flag is false" do
+ ConstantSpecs::ModuleA.const_source_location(:CS_CONST1, false).should == nil
+ end
+
+ it "returns nil when the receiver is a Class, the constant is defined at toplevel and the inherit flag is false" do
+ ConstantSpecs::ContainerA::ChildA.const_source_location(:CS_CONST1, false).should == nil
+ end
+
+ it "accepts a toplevel scope qualifier" do
+ ConstantSpecs.const_source_location("::CS_CONST1").should == [@constants_fixture_path, CS_CONST1_LINE]
+ end
+
+ it "accepts a scoped constant name" do
+ ConstantSpecs.const_source_location("ClassA::CS_CONST10").should == [@constants_fixture_path, ConstantSpecs::ClassA::CS_CONST10_LINE]
+ end
+
+ it "returns updated location from const_set" do
+ mod = Module.new
+ const_line = __LINE__ + 1
+ mod.const_set :Foo, 1
+ mod.const_source_location(:Foo).should == [__FILE__, const_line]
+ end
+
+ it "raises a NameError if the name includes two successive scope separators" do
+ -> { ConstantSpecs.const_source_location("ClassA::::CS_CONST10") }.should.raise(NameError)
+ end
+
+ it "raises a NameError if only '::' is passed" do
+ -> { ConstantSpecs.const_source_location("::") }.should.raise(NameError)
+ end
+
+ it "raises a NameError if a Symbol has a toplevel scope qualifier" do
+ -> { ConstantSpecs.const_source_location(:'::CS_CONST1') }.should.raise(NameError)
+ end
+
+ it "raises a NameError if a Symbol is a scoped constant name" do
+ -> { ConstantSpecs.const_source_location(:'ClassA::CS_CONST10') }.should.raise(NameError)
+ end
+
+ it "does search private constants path" do
+ ConstantSpecs.const_source_location(:CS_PRIVATE).should == [@constants_fixture_path, ConstantSpecs::CS_PRIVATE_LINE]
+ end
+
+ it "works for eval with a given line" do
+ c = Class.new do
+ eval('self::C = 1', nil, "foo", 100)
+ end
+ c.const_source_location(:C).should == ["foo", 100]
+ end
+
+ context 'autoload' do
+ before :all do
+ ConstantSpecs.autoload :CSL_CONST1, "#{__dir__}/notexisting.rb"
+ @line = __LINE__ - 1
+ end
+
+ before :each do
+ @loaded_features = $".dup
+ end
+
+ after :each do
+ $".replace @loaded_features
+ end
+
+ it 'returns the autoload location while not resolved' do
+ ConstantSpecs.const_source_location('CSL_CONST1').should == [__FILE__, @line]
+ end
+
+ it 'returns where the constant was resolved when resolved' do
+ file = fixture(__FILE__, 'autoload_location.rb')
+ ConstantSpecs.autoload :CONST_LOCATION, file
+ line = ConstantSpecs::CONST_LOCATION
+ ConstantSpecs.const_source_location('CONST_LOCATION').should == [file, line]
+ end
+
+ ruby_bug("#20188", ""..."3.4") do
+ it 'returns the real constant location as soon as it is defined' do
+ file = fixture(__FILE__, 'autoload_const_source_location.rb')
+ ConstantSpecs.autoload :ConstSource, file
+ autoload_location = [__FILE__, __LINE__ - 1]
+
+ ConstantSpecs.const_source_location(:ConstSource).should == autoload_location
+ ConstantSpecs::ConstSource::LOCATION.should == ConstantSpecs.const_source_location(:ConstSource)
+ ConstantSpecs::BEFORE_DEFINE_LOCATION.should == autoload_location
+ ConstantSpecs.send :remove_const, :ConstSource
+ ConstantSpecs.send :remove_const, :BEFORE_DEFINE_LOCATION
+ end
+ end
+ end
+end
diff --git a/spec/ruby/core/module/constants_spec.rb b/spec/ruby/core/module/constants_spec.rb
index c331482bfb..f2f12761e3 100644
--- a/spec/ruby/core/module/constants_spec.rb
+++ b/spec/ruby/core/module/constants_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../fixtures/constants', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../../fixtures/constants'
+require_relative 'fixtures/classes'
describe "Module.constants" do
it "returns an array of the names of all toplevel constants" do
@@ -13,12 +13,13 @@ describe "Module.constants" do
it "returns an array of Symbol names" do
# This in NOT an exhaustive list
- Module.constants.should include(:Array, :Bignum, :Class, :Comparable, :Dir,
+ Module.constants.to_set.should >= Set[
+ :Array, :Class, :Comparable, :Dir,
:Enumerable, :ENV, :Exception, :FalseClass,
- :File, :Fixnum, :Float, :Hash, :Integer, :IO,
+ :File, :Float, :Hash, :Integer, :IO,
:Kernel, :Math, :Method, :Module, :NilClass,
:Numeric, :Object, :Range, :Regexp, :String,
- :Symbol, :Thread, :Time, :TrueClass)
+ :Symbol, :Thread, :Time, :TrueClass]
end
it "returns Module's constants when given a parameter" do
@@ -43,37 +44,43 @@ end
describe "Module#constants" do
it "returns an array of Symbol names of all constants defined in the module and all included modules" do
ConstantSpecs::ContainerA.constants.sort.should == [
- :CS_CONST10, :CS_CONST23, :CS_CONST24, :CS_CONST5, :ChildA
+ :CS_CONST10, :CS_CONST10_LINE, :CS_CONST23, :CS_CONST24, :CS_CONST5, :ChildA
]
end
it "returns all constants including inherited when passed true" do
ConstantSpecs::ContainerA.constants(true).sort.should == [
- :CS_CONST10, :CS_CONST23, :CS_CONST24, :CS_CONST5, :ChildA
+ :CS_CONST10, :CS_CONST10_LINE, :CS_CONST23, :CS_CONST24, :CS_CONST5, :ChildA
]
end
it "returns all constants including inherited when passed some object" do
ConstantSpecs::ContainerA.constants(Object.new).sort.should == [
- :CS_CONST10, :CS_CONST23, :CS_CONST24, :CS_CONST5, :ChildA
+ :CS_CONST10, :CS_CONST10_LINE, :CS_CONST23, :CS_CONST24, :CS_CONST5, :ChildA
]
end
it "doesn't returns inherited constants when passed false" do
ConstantSpecs::ContainerA.constants(false).sort.should == [
- :CS_CONST10, :CS_CONST23, :CS_CONST5, :ChildA
+ :CS_CONST10, :CS_CONST10_LINE, :CS_CONST23, :CS_CONST5, :ChildA
]
end
it "doesn't returns inherited constants when passed nil" do
ConstantSpecs::ContainerA.constants(nil).sort.should == [
- :CS_CONST10, :CS_CONST23, :CS_CONST5, :ChildA
+ :CS_CONST10, :CS_CONST10_LINE, :CS_CONST23, :CS_CONST5, :ChildA
]
end
it "returns only public constants" do
ModuleSpecs::PrivConstModule.constants.should == [:PUBLIC_CONSTANT]
end
+
+ it "returns only constants starting with an uppercase letter" do
+ # e.g. fatal, IO::generic_readable and IO::generic_writable should not be returned by Module#constants
+ Object.constants.each { |c| c[0].should == c[0].upcase }
+ IO.constants.each { |c| c[0].should == c[0].upcase }
+ end
end
describe "Module#constants" do
@@ -86,6 +93,6 @@ describe "Module#constants" do
end
it "includes names of constants defined after a module is included" do
- ConstantSpecs::ContainerA.constants.should include(:CS_CONST251)
+ ConstantSpecs::ContainerA.constants.should.include?(:CS_CONST251)
end
end
diff --git a/spec/ruby/core/module/define_method_spec.rb b/spec/ruby/core/module/define_method_spec.rb
index 412a69a65a..f838e2b85f 100644
--- a/spec/ruby/core/module/define_method_spec.rb
+++ b/spec/ruby/core/module/define_method_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
class DefineMethodSpecClass
end
@@ -12,7 +12,7 @@ describe "passed { |a, b = 1| } creates a method that" do
end
it "raises an ArgumentError when passed zero arguments" do
- lambda { @klass.new.m }.should raise_error(ArgumentError)
+ -> { @klass.new.m }.should.raise(ArgumentError)
end
it "has a default value for b when passed one argument" do
@@ -24,7 +24,7 @@ describe "passed { |a, b = 1| } creates a method that" do
end
it "raises an ArgumentError when passed three arguments" do
- lambda { @klass.new.m(1, 2, 3) }.should raise_error(ArgumentError)
+ -> { @klass.new.m(1, 2, 3) }.should.raise(ArgumentError)
end
end
@@ -47,7 +47,7 @@ describe "Module#define_method when given an UnboundMethod" do
end
define_method(:another_test_method, instance_method(:test_method))
end
- klass.new.should have_method(:another_test_method)
+ klass.new.should.respond_to?(:another_test_method)
end
describe "defining a method on a singleton class" do
@@ -83,11 +83,28 @@ describe "Module#define_method when given an UnboundMethod" do
define_method :piggy, instance_method(:ziggy)
end
- lambda { foo.new.ziggy }.should raise_error(NoMethodError)
+ -> { foo.new.ziggy }.should.raise(NoMethodError)
foo.new.piggy.should == 'piggy'
end
end
+describe "Module#define_method" do
+ describe "when the default definee is not the same as the module" do
+ it "sets the visibility of the method to public" do
+ klass = Class.new
+ class << klass
+ private
+ define_method(:meta) do
+ define_method(:foo) { :foo }
+ end
+ end
+
+ klass.send :meta
+ klass.new.foo.should == :foo
+ end
+ end
+end
+
describe "Module#define_method when name is not a special private name" do
describe "given an UnboundMethod" do
describe "and called from the target module" do
@@ -98,8 +115,8 @@ describe "Module#define_method when name is not a special private name" do
define_method(:baz, ModuleSpecs::EmptyFooMethod)
end
- klass.should have_public_instance_method(:bar)
- klass.should have_private_instance_method(:baz)
+ klass.public_instance_methods(false).should.include?(:bar)
+ klass.private_instance_methods(false).should.include?(:baz)
end
end
@@ -112,10 +129,21 @@ describe "Module#define_method when name is not a special private name" do
klass.send(:define_method, :baz, ModuleSpecs::EmptyFooMethod)
end
- klass.should have_public_instance_method(:bar)
- klass.should have_public_instance_method(:baz)
+ klass.public_instance_methods(false).should.include?(:bar)
+ klass.public_instance_methods(false).should.include?(:baz)
end
end
+
+ it "sets the method owner for a dynamically added method with a different original owner" do
+ mixin_module = Module.new do
+ def bar; end
+ end
+
+ foo = Object.new
+ foo.singleton_class.define_method(:bar, mixin_module.instance_method(:bar))
+
+ foo.method(:bar).owner.should == foo.singleton_class
+ end
end
describe "passed a block" do
@@ -127,8 +155,8 @@ describe "Module#define_method when name is not a special private name" do
define_method(:baz) {}
end
- klass.should have_public_instance_method(:bar)
- klass.should have_private_instance_method(:baz)
+ klass.public_instance_methods(false).should.include?(:bar)
+ klass.private_instance_methods(false).should.include?(:baz)
end
end
@@ -141,8 +169,8 @@ describe "Module#define_method when name is not a special private name" do
klass.send(:define_method, :baz) {}
end
- klass.should have_public_instance_method(:bar)
- klass.should have_public_instance_method(:baz)
+ klass.public_instance_methods(false).should.include?(:bar)
+ klass.public_instance_methods(false).should.include?(:baz)
end
end
end
@@ -154,7 +182,7 @@ describe "Module#define_method when name is :initialize" do
klass = Class.new do
define_method(:initialize) { }
end
- klass.should have_private_instance_method(:initialize)
+ klass.private_instance_methods(false).should.include?(:initialize)
end
end
@@ -165,7 +193,7 @@ describe "Module#define_method when name is :initialize" do
end
define_method(:initialize, instance_method(:test_method))
end
- klass.should have_private_instance_method(:initialize)
+ klass.private_instance_methods(false).should.include?(:initialize)
end
end
end
@@ -194,7 +222,7 @@ describe "Module#define_method" do
it "defines a new method with the given name and the given block as body in self" do
class DefineMethodSpecClass
define_method(:block_test1) { self }
- define_method(:block_test2, &lambda { self })
+ define_method(:block_test2, &-> { self })
end
o = DefineMethodSpecClass.new
@@ -202,39 +230,74 @@ describe "Module#define_method" do
o.block_test2.should == o
end
+ it "raises TypeError if name cannot converted to String" do
+ -> {
+ Class.new { define_method(1001, -> {}) }
+ }.should.raise(TypeError, /is not a symbol nor a string/)
+
+ -> {
+ Class.new { define_method([], -> {}) }
+ }.should.raise(TypeError, /is not a symbol nor a string/)
+ end
+
+ it "converts non-String name to String with #to_str" do
+ obj = Object.new
+ def obj.to_str() "foo" end
+
+ new_class = Class.new { define_method(obj, -> { :called }) }
+ new_class.new.foo.should == :called
+ end
+
+ it "raises TypeError when #to_str called on non-String name returns non-String value" do
+ obj = Object.new
+ def obj.to_str() [] end
+
+ -> {
+ Class.new { define_method(obj, -> {}) }
+ }.should raise_consistent_error(TypeError, /can't convert Object into String/)
+ end
+
it "raises a TypeError when the given method is no Method/Proc" do
- lambda {
+ -> {
Class.new { define_method(:test, "self") }
- }.should raise_error(TypeError)
+ }.should.raise(TypeError, "wrong argument type String (expected Proc/Method/UnboundMethod)")
- lambda {
+ -> {
Class.new { define_method(:test, 1234) }
- }.should raise_error(TypeError)
+ }.should.raise(TypeError, "wrong argument type Integer (expected Proc/Method/UnboundMethod)")
- lambda {
+ -> {
Class.new { define_method(:test, nil) }
- }.should raise_error(TypeError)
+ }.should.raise(TypeError, "wrong argument type NilClass (expected Proc/Method/UnboundMethod)")
+ end
+
+ it "uses provided Method/Proc even if block is specified" do
+ new_class = Class.new do
+ define_method(:test, -> { :method_is_called }) do
+ :block_is_called
+ end
+ end
+
+ new_class.new.test.should == :method_is_called
end
it "raises an ArgumentError when no block is given" do
- lambda {
+ -> {
Class.new { define_method(:test) }
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
end
- ruby_version_is "2.3" do
- it "does not use the caller block when no block is given" do
- o = Object.new
- def o.define(name)
- self.class.class_eval do
- define_method(name)
- end
+ it "does not use the caller block when no block is given" do
+ o = Object.new
+ def o.define(name)
+ self.class.class_eval do
+ define_method(name)
end
-
- lambda {
- o.define(:foo) { raise "not used" }
- }.should raise_error(ArgumentError)
end
+
+ -> {
+ o.define(:foo) { raise "not used" }
+ }.should.raise(ArgumentError)
end
it "does not change the arity check style of the original proc" do
@@ -244,13 +307,13 @@ describe "Module#define_method" do
end
obj = DefineMethodSpecClass.new
- lambda { obj.proc_style_test :arg }.should raise_error(ArgumentError)
+ -> { obj.proc_style_test :arg }.should.raise(ArgumentError)
end
- it "raises a RuntimeError if frozen" do
- lambda {
+ it "raises a FrozenError if frozen" do
+ -> {
Class.new { freeze; define_method(:foo) {} }
- }.should raise_error(RuntimeError)
+ }.should.raise(FrozenError)
end
it "accepts a Method (still bound)" do
@@ -263,13 +326,13 @@ describe "Module#define_method" do
o = DefineMethodSpecClass.new
o.data = :foo
m = o.method(:inspect_data)
- m.should be_an_instance_of(Method)
+ m.should.instance_of?(Method)
klass = Class.new(DefineMethodSpecClass)
klass.send(:define_method,:other_inspect, m)
c = klass.new
c.data = :bar
c.other_inspect.should == "data is bar"
- lambda{o.other_inspect}.should raise_error(NoMethodError)
+ ->{o.other_inspect}.should.raise(NoMethodError)
end
it "raises a TypeError when a Method from a singleton class is defined on another class" do
@@ -281,9 +344,9 @@ describe "Module#define_method" do
end
m = c.method(:foo)
- lambda {
+ -> {
Class.new { define_method :bar, m }
- }.should raise_error(TypeError)
+ }.should.raise(TypeError, /can't bind singleton method to a different class/)
end
it "raises a TypeError when a Method from one class is defined on an unrelated class" do
@@ -293,9 +356,9 @@ describe "Module#define_method" do
end
m = c.new.method(:foo)
- lambda {
+ -> {
Class.new { define_method :bar, m }
- }.should raise_error(TypeError)
+ }.should.raise(TypeError)
end
it "accepts an UnboundMethod from an attr_accessor method" do
@@ -307,7 +370,7 @@ describe "Module#define_method" do
o = DefineMethodSpecClass.new
DefineMethodSpecClass.send(:undef_method, :accessor_method)
- lambda { o.accessor_method }.should raise_error(NoMethodError)
+ -> { o.accessor_method }.should.raise(NoMethodError)
DefineMethodSpecClass.send(:define_method, :accessor_method, m)
@@ -335,6 +398,14 @@ describe "Module#define_method" do
object2.other_cool_method.should == "data is foo"
end
+ it "accepts a proc from a Symbol" do
+ symbol_proc = :+.to_proc
+ klass = Class.new do
+ define_method :foo, &symbol_proc
+ end
+ klass.new.foo(1, 2).should == 3
+ end
+
it "maintains the Proc's scope" do
class DefineMethodByProcClass
in_scope = true
@@ -344,7 +415,7 @@ describe "Module#define_method" do
end
o = DefineMethodByProcClass.new
- o.proc_test.should be_true
+ o.proc_test.should == true
end
it "accepts a String method name" do
@@ -357,8 +428,8 @@ describe "Module#define_method" do
klass.new.string_test.should == "string_test result"
end
- it "is private" do
- Module.should have_private_instance_method(:define_method)
+ it "is a public method" do
+ Module.public_instance_methods(false).should.include?(:define_method)
end
it "returns its symbol" do
@@ -372,7 +443,7 @@ describe "Module#define_method" do
klass = Class.new {
define_method :bar, ModuleSpecs::UnboundMethodTest.instance_method(:foo)
}
- klass.new.should respond_to(:bar)
+ klass.new.should.respond_to?(:bar)
end
it "allows an UnboundMethod from a parent class to be defined on a child class" do
@@ -380,7 +451,7 @@ describe "Module#define_method" do
child = Class.new(parent) {
define_method :baz, parent.instance_method(:foo)
}
- child.new.should respond_to(:baz)
+ child.new.should.respond_to?(:baz)
end
it "allows an UnboundMethod from a module to be defined on another unrelated module" do
@@ -388,23 +459,75 @@ describe "Module#define_method" do
define_method :bar, ModuleSpecs::UnboundMethodTest.instance_method(:foo)
}
klass = Class.new { include mod }
- klass.new.should respond_to(:bar)
+ klass.new.should.respond_to?(:bar)
+ end
+
+
+ it "allows an UnboundMethod of a Kernel method retrieved from Object to defined on a BasicObject subclass" do
+ klass = Class.new(BasicObject) do
+ define_method :instance_of?, ::Object.instance_method(:instance_of?)
+ end
+ klass.new.instance_of?(klass).should == true
end
it "raises a TypeError when an UnboundMethod from a child class is defined on a parent class" do
- lambda {
+ -> {
ParentClass = Class.new { define_method(:foo) { :bar } }
ChildClass = Class.new(ParentClass) { define_method(:foo) { :baz } }
ParentClass.send :define_method, :foo, ChildClass.instance_method(:foo)
- }.should raise_error(TypeError)
+ }.should.raise(TypeError, /bind argument must be a subclass of ChildClass/)
+ ensure
+ Object.send(:remove_const, :ParentClass)
+ Object.send(:remove_const, :ChildClass)
end
it "raises a TypeError when an UnboundMethod from one class is defined on an unrelated class" do
- lambda {
+ -> {
DestinationClass = Class.new {
define_method :bar, ModuleSpecs::InstanceMeth.instance_method(:foo)
}
- }.should raise_error(TypeError)
+ }.should.raise(TypeError, /bind argument must be a subclass of ModuleSpecs::InstanceMeth/)
+ end
+
+ it "raises a TypeError when an UnboundMethod from a singleton class is defined on another class" do
+ c = Class.new do
+ class << self
+ def foo
+ end
+ end
+ end
+ m = c.method(:foo).unbind
+
+ -> {
+ Class.new { define_method :bar, m }
+ }.should.raise(TypeError, /can't bind singleton method to a different class/)
+ end
+
+ it "defines a new method with public visibility when a Method passed and the class/module of the context isn't equal to the receiver of #define_method" do
+ c = Class.new do
+ private def foo
+ "public"
+ end
+ end
+
+ object = c.new
+ object.singleton_class.define_method(:bar, object.method(:foo))
+
+ object.bar.should == "public"
+ end
+
+ it "defines the new method according to the scope visibility when a Method passed and the class/module of the context is equal to the receiver of #define_method" do
+ c = Class.new do
+ def foo; end
+ end
+
+ object = c.new
+ object.singleton_class.class_eval do
+ private
+ define_method(:bar, c.new.method(:foo))
+ end
+
+ -> { object.bar }.should.raise(NoMethodError)
end
end
@@ -421,11 +544,11 @@ describe "Module#define_method" do
end
it "raises an ArgumentError when passed one argument" do
- lambda { @klass.new.m 1 }.should raise_error(ArgumentError)
+ -> { @klass.new.m 1 }.should.raise(ArgumentError)
end
it "raises an ArgumentError when passed two arguments" do
- lambda { @klass.new.m 1, 2 }.should raise_error(ArgumentError)
+ -> { @klass.new.m 1, 2 }.should.raise(ArgumentError)
end
end
@@ -441,11 +564,11 @@ describe "Module#define_method" do
end
it "raises an ArgumentError when passed one argument" do
- lambda { @klass.new.m 1 }.should raise_error(ArgumentError)
+ -> { @klass.new.m 1 }.should.raise(ArgumentError)
end
it "raises an ArgumentError when passed two arguments" do
- lambda { @klass.new.m 1, 2 }.should raise_error(ArgumentError)
+ -> { @klass.new.m 1, 2 }.should.raise(ArgumentError)
end
end
@@ -457,21 +580,50 @@ describe "Module#define_method" do
end
it "raises an ArgumentError when passed zero arguments" do
- lambda { @klass.new.m }.should raise_error(ArgumentError)
+ -> { @klass.new.m }.should.raise(ArgumentError)
+ end
+
+ it "raises an ArgumentError when passed zero arguments and a block" do
+ -> { @klass.new.m { :computed } }.should.raise(ArgumentError)
+ end
+
+ it "raises an ArgumentError when passed two arguments" do
+ -> { @klass.new.m 1, 2 }.should.raise(ArgumentError)
+ end
+
+ it "receives the value passed as the argument when passed one argument" do
+ @klass.new.m(1).should == 1
+ end
+ end
+
+ describe "passed { |a,| } creates a method that" do
+ before :each do
+ @klass = Class.new do
+ define_method(:m) { |a,| a }
+ end
+ end
+
+ it "raises an ArgumentError when passed zero arguments" do
+ -> { @klass.new.m }.should.raise(ArgumentError)
end
it "raises an ArgumentError when passed zero arguments and a block" do
- lambda { @klass.new.m { :computed } }.should raise_error(ArgumentError)
+ -> { @klass.new.m { :computed } }.should.raise(ArgumentError)
end
it "raises an ArgumentError when passed two arguments" do
- lambda { @klass.new.m 1, 2 }.should raise_error(ArgumentError)
+ -> { @klass.new.m 1, 2 }.should.raise(ArgumentError)
end
it "receives the value passed as the argument when passed one argument" do
@klass.new.m(1).should == 1
end
+ it "does not destructure the passed argument" do
+ @klass.new.m([1, 2]).should == [1, 2]
+ # for comparison:
+ proc { |a,| a }.call([1, 2]).should == 1
+ end
end
describe "passed { |*a| } creates a method that" do
@@ -502,7 +654,7 @@ describe "Module#define_method" do
end
it "raises an ArgumentError when passed zero arguments" do
- lambda { @klass.new.m }.should raise_error(ArgumentError)
+ -> { @klass.new.m }.should.raise(ArgumentError)
end
it "returns the value computed by the block when passed one argument" do
@@ -530,19 +682,19 @@ describe "Module#define_method" do
end
it "raises an ArgumentError when passed zero arguments" do
- lambda { @klass.new.m }.should raise_error(ArgumentError)
+ -> { @klass.new.m }.should.raise(ArgumentError)
end
it "raises an ArgumentError when passed one argument" do
- lambda { @klass.new.m 1 }.should raise_error(ArgumentError)
+ -> { @klass.new.m 1 }.should.raise(ArgumentError)
end
it "raises an ArgumentError when passed one argument and a block" do
- lambda { @klass.new.m(1) { } }.should raise_error(ArgumentError)
+ -> { @klass.new.m(1) { } }.should.raise(ArgumentError)
end
it "raises an ArgumentError when passed three arguments" do
- lambda { @klass.new.m 1, 2, 3 }.should raise_error(ArgumentError)
+ -> { @klass.new.m 1, 2, 3 }.should.raise(ArgumentError)
end
end
@@ -554,15 +706,15 @@ describe "Module#define_method" do
end
it "raises an ArgumentError when passed zero arguments" do
- lambda { @klass.new.m }.should raise_error(ArgumentError)
+ -> { @klass.new.m }.should.raise(ArgumentError)
end
it "raises an ArgumentError when passed one argument" do
- lambda { @klass.new.m 1 }.should raise_error(ArgumentError)
+ -> { @klass.new.m 1 }.should.raise(ArgumentError)
end
it "raises an ArgumentError when passed one argument and a block" do
- lambda { @klass.new.m(1) { } }.should raise_error(ArgumentError)
+ -> { @klass.new.m(1) { } }.should.raise(ArgumentError)
end
it "receives an empty array as the third argument when passed two arguments" do
@@ -575,7 +727,7 @@ describe "Module#define_method" do
end
end
-describe "Method#define_method when passed a Method object" do
+describe "Module#define_method when passed a Method object" do
before :each do
@klass = Class.new do
def m(a, b, *c)
@@ -600,7 +752,7 @@ describe "Method#define_method when passed a Method object" do
end
end
-describe "Method#define_method when passed an UnboundMethod object" do
+describe "Module#define_method when passed an UnboundMethod object" do
before :each do
@klass = Class.new do
def m(a, b, *c)
@@ -624,3 +776,71 @@ describe "Method#define_method when passed an UnboundMethod object" do
@obj.method(:n).parameters.should == @obj.method(:m).parameters
end
end
+
+describe "Module#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.respond_to? :nested_method_in_proc_for_define_method
+
+ t.new.nested_method_in_proc_for_define_method.should == 42
+ end
+ end
+end
+
+describe "Module#define_method when passed a block" do
+ describe "behaves exactly like a lambda" do
+ it "for return" do
+ Class.new do
+ define_method(:foo) do
+ return 42
+ end
+ end.new.foo.should == 42
+ end
+
+ it "for break" do
+ Class.new do
+ define_method(:foo) do
+ break 42
+ end
+ end.new.foo.should == 42
+ end
+
+ it "for next" do
+ Class.new do
+ define_method(:foo) do
+ next 42
+ end
+ end.new.foo.should == 42
+ end
+
+ it "for redo" do
+ Class.new do
+ result = []
+ define_method(:foo) do
+ if result.empty?
+ result << :first
+ redo
+ else
+ result << :second
+ result
+ end
+ end
+ end.new.foo.should == [:first, :second]
+ end
+ end
+end
diff --git a/spec/ruby/core/module/define_singleton_method_spec.rb b/spec/ruby/core/module/define_singleton_method_spec.rb
index 0841d5d7e2..eb5cb89ed1 100644
--- a/spec/ruby/core/module/define_singleton_method_spec.rb
+++ b/spec/ruby/core/module/define_singleton_method_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Module#define_singleton_method" do
it "defines the given method as an class method with the given name in self" do
@@ -6,12 +6,10 @@ describe "Module#define_singleton_method" do
define_singleton_method :a do
42
end
- define_singleton_method(:b, lambda {|x| 2*x })
+ define_singleton_method(:b, -> x { 2*x })
end
klass.a.should == 42
klass.b(10).should == 20
end
-
- it "needs to be reviewed for spec completeness"
end
diff --git a/spec/ruby/core/module/deprecate_constant_spec.rb b/spec/ruby/core/module/deprecate_constant_spec.rb
index 8c7a170f1c..597379eb87 100644
--- a/spec/ruby/core/module/deprecate_constant_spec.rb
+++ b/spec/ruby/core/module/deprecate_constant_spec.rb
@@ -1,52 +1,70 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-ruby_version_is "2.3" do
- describe "Module#deprecate_constant" do
- before :each do
- @module = Module.new
- @value = :value
- @module::PUBLIC1 = @value
- @module::PUBLIC2 = @value
- @module::PRIVATE = @value
- @module.private_constant :PRIVATE
- @module.deprecate_constant :PRIVATE
- @pattern = /deprecated/
+require_relative '../../spec_helper'
+
+describe "Module#deprecate_constant" do
+ before :each do
+ @module = Module.new
+ @value = :value
+ @module::PUBLIC1 = @value
+ @module::PUBLIC2 = @value
+ @module::PRIVATE = @value
+ @module.private_constant :PRIVATE
+ @module.deprecate_constant :PRIVATE
+ end
+
+ describe "when accessing the deprecated module" do
+ it "passes the accessing" do
+ @module.deprecate_constant :PUBLIC1
+
+ value = nil
+ -> {
+ value = @module::PUBLIC1
+ }.should complain(/warning: constant .+::PUBLIC1 is deprecated/)
+ value.should.equal?(@value)
+
+ -> { @module::PRIVATE }.should.raise(NameError)
end
- describe "when accessing the deprecated module" do
- it "passes the accessing" do
- @module.deprecate_constant :PUBLIC1
+ it "warns with a message" do
+ @module.deprecate_constant :PUBLIC1
+
+ -> { @module::PUBLIC1 }.should complain(/warning: constant .+::PUBLIC1 is deprecated/)
+ -> { @module.const_get :PRIVATE }.should complain(/warning: constant .+::PRIVATE is deprecated/)
+ end
- value = nil
- lambda {
- value = @module::PUBLIC1
- }.should complain(@pattern)
- value.should equal(@value)
+ it "does not warn if Warning[:deprecated] is false" do
+ @module.deprecate_constant :PUBLIC1
- lambda { @module::PRIVATE }.should raise_error(NameError)
+ deprecated = Warning[:deprecated]
+ begin
+ Warning[:deprecated] = false
+ -> { @module::PUBLIC1 }.should_not complain
+ ensure
+ Warning[:deprecated] = deprecated
end
+ end
+ end
+ ruby_bug '#20900', ''...'3.4' do
+ describe "when removing the deprecated module" do
it "warns with a message" do
@module.deprecate_constant :PUBLIC1
-
- lambda { @module::PUBLIC1 }.should complain(@pattern)
- lambda { @module.const_get :PRIVATE }.should complain(@pattern)
+ -> { @module.module_eval {remove_const :PUBLIC1} }.should complain(/warning: constant .+::PUBLIC1 is deprecated/)
end
end
+ end
- it "accepts multiple symbols and strings as constant names" do
- @module.deprecate_constant "PUBLIC1", :PUBLIC2
+ it "accepts multiple symbols and strings as constant names" do
+ @module.deprecate_constant "PUBLIC1", :PUBLIC2
- lambda { @module::PUBLIC1 }.should complain(@pattern)
- lambda { @module::PUBLIC2 }.should complain(@pattern)
- end
+ -> { @module::PUBLIC1 }.should complain(/warning: constant .+::PUBLIC1 is deprecated/)
+ -> { @module::PUBLIC2 }.should complain(/warning: constant .+::PUBLIC2 is deprecated/)
+ end
- it "returns self" do
- @module.deprecate_constant(:PUBLIC1).should equal(@module)
- end
+ it "returns self" do
+ @module.deprecate_constant(:PUBLIC1).should.equal?(@module)
+ end
- it "raises a NameError when given an undefined name" do
- lambda { @module.deprecate_constant :UNDEFINED }.should raise_error(NameError)
- end
+ it "raises a NameError when given an undefined name" do
+ -> { @module.deprecate_constant :UNDEFINED }.should.raise(NameError)
end
end
diff --git a/spec/ruby/core/module/eql_spec.rb b/spec/ruby/core/module/eql_spec.rb
index f8878d7f4e..76bb271d8d 100644
--- a/spec/ruby/core/module/eql_spec.rb
+++ b/spec/ruby/core/module/eql_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/equal_value', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/equal_value'
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..01ab06152d 100644
--- a/spec/ruby/core/module/equal_spec.rb
+++ b/spec/ruby/core/module/equal_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/equal_value', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/equal_value'
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..a7191cd755 100644
--- a/spec/ruby/core/module/equal_value_spec.rb
+++ b/spec/ruby/core/module/equal_value_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/equal_value', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/equal_value'
describe "Module#==" do
- it_behaves_like(:module_equal, :==)
+ it_behaves_like :module_equal, :==
end
diff --git a/spec/ruby/core/module/extend_object_spec.rb b/spec/ruby/core/module/extend_object_spec.rb
index 73c1623dce..b428eb7924 100644
--- a/spec/ruby/core/module/extend_object_spec.rb
+++ b/spec/ruby/core/module/extend_object_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Module#extend_object" do
before :each do
@@ -7,18 +7,18 @@ describe "Module#extend_object" do
end
it "is a private method" do
- Module.should have_private_instance_method(:extend_object)
+ Module.private_instance_methods(false).should.include?(:extend_object)
end
describe "on Class" do
it "is undefined" do
- Class.should_not have_private_instance_method(:extend_object, true)
+ Class.private_instance_methods(true).should_not.include?(:extend_object)
end
it "raises a TypeError if calling after rebinded to Class" do
- lambda {
+ -> {
Module.instance_method(:extend_object).bind(Class.new).call Object.new
- }.should raise_error(TypeError)
+ }.should.raise(TypeError)
end
end
@@ -42,18 +42,6 @@ describe "Module#extend_object" do
ScratchPad.recorded.should == :extended
end
- it "does not copy own tainted status to the given object" do
- other = Object.new
- Module.new.taint.send :extend_object, other
- other.tainted?.should be_false
- end
-
- it "does not copy own untrusted status to the given object" do
- other = Object.new
- Module.new.untrust.send :extend_object, other
- other.untrusted?.should be_false
- end
-
describe "when given a frozen object" do
before :each do
@receiver = Module.new
@@ -61,8 +49,8 @@ describe "Module#extend_object" do
end
it "raises a RuntimeError before extending the object" do
- lambda { @receiver.send(:extend_object, @object) }.should raise_error(RuntimeError)
- @object.should_not be_kind_of(@receiver)
+ -> { @receiver.send(:extend_object, @object) }.should.raise(RuntimeError)
+ @object.should_not.is_a?(@receiver)
end
end
end
diff --git a/spec/ruby/core/module/extended_spec.rb b/spec/ruby/core/module/extended_spec.rb
index 0a62dd9850..a4ec5a4ba7 100644
--- a/spec/ruby/core/module/extended_spec.rb
+++ b/spec/ruby/core/module/extended_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Module#extended" do
it "is called when an object gets extended with self" do
@@ -39,6 +39,6 @@ describe "Module#extended" do
end
it "is private in its default implementation" do
- Module.new.private_methods.should include(:extended)
+ Module.new.private_methods.should.include?(:extended)
end
end
diff --git a/spec/ruby/core/module/fixtures/autoload_callback.rb b/spec/ruby/core/module/fixtures/autoload_callback.rb
new file mode 100644
index 0000000000..51d53eb580
--- /dev/null
+++ b/spec/ruby/core/module/fixtures/autoload_callback.rb
@@ -0,0 +1,2 @@
+block = ScratchPad.recorded
+block.call
diff --git a/spec/ruby/core/module/fixtures/autoload_const_source_location.rb b/spec/ruby/core/module/fixtures/autoload_const_source_location.rb
new file mode 100644
index 0000000000..ee0e5a689f
--- /dev/null
+++ b/spec/ruby/core/module/fixtures/autoload_const_source_location.rb
@@ -0,0 +1,6 @@
+module ConstantSpecs
+ BEFORE_DEFINE_LOCATION = const_source_location(:ConstSource)
+ module ConstSource
+ LOCATION = Object.const_source_location(name)
+ end
+end
diff --git a/spec/ruby/core/module/fixtures/autoload_during_autoload.rb b/spec/ruby/core/module/fixtures/autoload_during_autoload.rb
new file mode 100644
index 0000000000..5202bd8b23
--- /dev/null
+++ b/spec/ruby/core/module/fixtures/autoload_during_autoload.rb
@@ -0,0 +1,7 @@
+block = ScratchPad.recorded
+ScratchPad.record(block.call)
+
+module ModuleSpecs::Autoload
+ class DuringAutoload
+ end
+end
diff --git a/spec/ruby/core/module/fixtures/autoload_during_autoload_after_define.rb b/spec/ruby/core/module/fixtures/autoload_during_autoload_after_define.rb
new file mode 100644
index 0000000000..a9d886dfd6
--- /dev/null
+++ b/spec/ruby/core/module/fixtures/autoload_during_autoload_after_define.rb
@@ -0,0 +1,6 @@
+module ModuleSpecs::Autoload
+ class DuringAutoloadAfterDefine
+ block = ScratchPad.recorded
+ ScratchPad.record(block.call)
+ end
+end
diff --git a/spec/ruby/core/module/fixtures/autoload_during_require.rb b/spec/ruby/core/module/fixtures/autoload_during_require.rb
new file mode 100644
index 0000000000..6fd81592e3
--- /dev/null
+++ b/spec/ruby/core/module/fixtures/autoload_during_require.rb
@@ -0,0 +1,4 @@
+module ModuleSpecs::Autoload
+ class AutoloadDuringRequire
+ end
+end
diff --git a/spec/ruby/core/module/fixtures/autoload_during_require_current_file.rb b/spec/ruby/core/module/fixtures/autoload_during_require_current_file.rb
new file mode 100644
index 0000000000..5aa8595065
--- /dev/null
+++ b/spec/ruby/core/module/fixtures/autoload_during_require_current_file.rb
@@ -0,0 +1,5 @@
+module ModuleSpecs::Autoload
+ autoload(:AutoloadCurrentFile, __FILE__)
+
+ ScratchPad.record autoload?(:AutoloadCurrentFile)
+end
diff --git a/spec/ruby/core/module/fixtures/autoload_exception.rb b/spec/ruby/core/module/fixtures/autoload_exception.rb
new file mode 100644
index 0000000000..09acf9f537
--- /dev/null
+++ b/spec/ruby/core/module/fixtures/autoload_exception.rb
@@ -0,0 +1,3 @@
+ScratchPad.record(:exception)
+
+raise 'intentional error to test failure conditions during autoloading'
diff --git a/spec/ruby/core/module/fixtures/autoload_location.rb b/spec/ruby/core/module/fixtures/autoload_location.rb
new file mode 100644
index 0000000000..318851b2df
--- /dev/null
+++ b/spec/ruby/core/module/fixtures/autoload_location.rb
@@ -0,0 +1,3 @@
+module ConstantSpecs
+ CONST_LOCATION = __LINE__
+end
diff --git a/spec/ruby/core/module/fixtures/autoload_nested.rb b/spec/ruby/core/module/fixtures/autoload_nested.rb
new file mode 100644
index 0000000000..073cec0dce
--- /dev/null
+++ b/spec/ruby/core/module/fixtures/autoload_nested.rb
@@ -0,0 +1,8 @@
+module ModuleSpecs::Autoload
+ module GoodParent
+ class Nested
+ end
+ end
+end
+
+ScratchPad.record(:loaded)
diff --git a/spec/ruby/core/module/fixtures/autoload_never_set.rb b/spec/ruby/core/module/fixtures/autoload_never_set.rb
new file mode 100644
index 0000000000..8b13789179
--- /dev/null
+++ b/spec/ruby/core/module/fixtures/autoload_never_set.rb
@@ -0,0 +1 @@
+
diff --git a/spec/ruby/core/module/fixtures/autoload_o.rb b/spec/ruby/core/module/fixtures/autoload_o.rb
index 6d54ddaf12..7d88f969b2 100644
--- a/spec/ruby/core/module/fixtures/autoload_o.rb
+++ b/spec/ruby/core/module/fixtures/autoload_o.rb
@@ -1 +1,2 @@
# does not define ModuleSpecs::Autoload::O
+ScratchPad << :loaded
diff --git a/spec/ruby/core/module/fixtures/autoload_overridden.rb b/spec/ruby/core/module/fixtures/autoload_overridden.rb
new file mode 100644
index 0000000000..7062bcfabc
--- /dev/null
+++ b/spec/ruby/core/module/fixtures/autoload_overridden.rb
@@ -0,0 +1,3 @@
+module ModuleSpecs::Autoload
+ Overridden = :overridden
+end
diff --git a/spec/ruby/core/module/fixtures/autoload_raise.rb b/spec/ruby/core/module/fixtures/autoload_raise.rb
new file mode 100644
index 0000000000..f6051e3ba2
--- /dev/null
+++ b/spec/ruby/core/module/fixtures/autoload_raise.rb
@@ -0,0 +1,2 @@
+ScratchPad << :raise
+raise "exception during autoload"
diff --git a/spec/ruby/core/module/fixtures/autoload_relative_a.rb b/spec/ruby/core/module/fixtures/autoload_relative_a.rb
new file mode 100644
index 0000000000..494181adc2
--- /dev/null
+++ b/spec/ruby/core/module/fixtures/autoload_relative_a.rb
@@ -0,0 +1,9 @@
+module ModuleSpecs
+ module Autoload
+ class AutoloadRelativeA
+ end
+
+ class AutoloadRelativeB
+ end
+ end
+end
diff --git a/spec/ruby/core/module/fixtures/autoload_required_directly.rb b/spec/ruby/core/module/fixtures/autoload_required_directly.rb
new file mode 100644
index 0000000000..bed60a71ec
--- /dev/null
+++ b/spec/ruby/core/module/fixtures/autoload_required_directly.rb
@@ -0,0 +1,7 @@
+block = ScratchPad.recorded
+ScratchPad.record(block.call)
+
+module ModuleSpecs::Autoload
+ class RequiredDirectly
+ end
+end
diff --git a/spec/ruby/core/module/fixtures/autoload_required_directly_nested.rb b/spec/ruby/core/module/fixtures/autoload_required_directly_nested.rb
new file mode 100644
index 0000000000..a9f11c2188
--- /dev/null
+++ b/spec/ruby/core/module/fixtures/autoload_required_directly_nested.rb
@@ -0,0 +1 @@
+ScratchPad.recorded.call
diff --git a/spec/ruby/core/module/fixtures/autoload_required_directly_no_constant.rb b/spec/ruby/core/module/fixtures/autoload_required_directly_no_constant.rb
new file mode 100644
index 0000000000..25e08c1129
--- /dev/null
+++ b/spec/ruby/core/module/fixtures/autoload_required_directly_no_constant.rb
@@ -0,0 +1,2 @@
+block = ScratchPad.recorded
+ScratchPad.record(block.call)
diff --git a/spec/ruby/core/module/fixtures/autoload_scope.rb b/spec/ruby/core/module/fixtures/autoload_scope.rb
deleted file mode 100644
index 04193687b5..0000000000
--- a/spec/ruby/core/module/fixtures/autoload_scope.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-module ModuleSpecs
- module Autoload
- class PP
- class QQ
- end
- end
- end
-end
diff --git a/spec/ruby/core/module/fixtures/autoload_self_during_require.rb b/spec/ruby/core/module/fixtures/autoload_self_during_require.rb
new file mode 100644
index 0000000000..f4a514a807
--- /dev/null
+++ b/spec/ruby/core/module/fixtures/autoload_self_during_require.rb
@@ -0,0 +1,5 @@
+module ModuleSpecs::Autoload
+ autoload :AutoloadSelfDuringRequire, __FILE__
+ class AutoloadSelfDuringRequire
+ end
+end
diff --git a/spec/ruby/core/module/fixtures/autoload_subclass.rb b/spec/ruby/core/module/fixtures/autoload_subclass.rb
index 569972118c..8027fa3fcd 100644
--- a/spec/ruby/core/module/fixtures/autoload_subclass.rb
+++ b/spec/ruby/core/module/fixtures/autoload_subclass.rb
@@ -1,10 +1,10 @@
-class YY
+class CS_CONST_AUTOLOAD
end
module ModuleSpecs
module Autoload
module XX
- class YY < YY
+ class CS_CONST_AUTOLOAD < CS_CONST_AUTOLOAD
end
end
end
diff --git a/spec/ruby/core/module/fixtures/classes.rb b/spec/ruby/core/module/fixtures/classes.rb
index f93c39683e..964f64c593 100644
--- a/spec/ruby/core/module/fixtures/classes.rb
+++ b/spec/ruby/core/module/fixtures/classes.rb
@@ -1,11 +1,14 @@
module ModuleSpecs
def self.without_test_modules(modules)
- ignore = %w[MSpecRSpecAdapter PP::ObjectMixin ModuleSpecs::IncludedInObject MainSpecs::Module ConstantSpecs::ModuleA]
+ ignore = %w[MSpecRSpecAdapter PP::ObjectMixin MainSpecs::Module ConstantSpecs::ModuleA]
modules.reject { |k| ignore.include?(k.name) }
end
CONST = :plain_constant
+ class NamedClass
+ end
+
module PrivConstModule
PRIVATE_CONSTANT = 1
private_constant :PRIVATE_CONSTANT
@@ -39,6 +42,14 @@ module ModuleSpecs
class LookupChild < Lookup
end
+ module ModuleWithPrepend
+ prepend LookupMod
+ end
+
+ class WithPrependedModule
+ include ModuleWithPrepend
+ end
+
class Parent
# For private_class_method spec
def self.private_method; end
@@ -349,6 +360,10 @@ module ModuleSpecs
end
end
+ class SubCVars < CVars
+ @@sub = :sub
+ end
+
module MVars
@@mvar = :mvar
end
@@ -373,6 +388,7 @@ module ModuleSpecs
# empty modules
module M1; end
module M2; end
+ module M3; end
module Autoload
def self.use_ex1
@@ -386,6 +402,12 @@ module ModuleSpecs
end
end
+ class Parent
+ end
+
+ class Child < Parent
+ end
+
module FromThread
module A
autoload :B, fixture(__FILE__, "autoload_empty.rb")
@@ -574,6 +596,32 @@ module ModuleSpecs
private :foo
end
EmptyFooMethod = m.instance_method(:foo)
+
+ # for undefined_instance_methods spec
+ module UndefinedInstanceMethods
+ module Super
+ def super_included_method; end
+ end
+
+ class Parent
+ def undefed_method; end
+ undef_method :undefed_method
+
+ def parent_method; end
+ def another_parent_method; end
+ end
+
+ class Child < Parent
+ include Super
+
+ undef_method :parent_method
+ undef_method :another_parent_method
+ end
+
+ class Grandchild < Child
+ undef_method :super_included_method
+ end
+ end
end
class Object
diff --git a/spec/ruby/core/module/fixtures/const_added.rb b/spec/ruby/core/module/fixtures/const_added.rb
new file mode 100644
index 0000000000..0f5baad65d
--- /dev/null
+++ b/spec/ruby/core/module/fixtures/const_added.rb
@@ -0,0 +1,4 @@
+module ModuleSpecs
+ module ConstAddedSpecs
+ end
+end
diff --git a/spec/ruby/core/module/fixtures/constants_autoload.rb b/spec/ruby/core/module/fixtures/constants_autoload.rb
new file mode 100644
index 0000000000..8e9aa8de0c
--- /dev/null
+++ b/spec/ruby/core/module/fixtures/constants_autoload.rb
@@ -0,0 +1,6 @@
+autoload :CSAutoloadA, fixture(__FILE__, 'constants_autoload_a.rb')
+autoload :CSAutoloadB, fixture(__FILE__, 'constants_autoload_b.rb')
+autoload :CSAutoloadC, fixture(__FILE__, 'constants_autoload_c.rb')
+module CSAutoloadD
+ autoload :InnerModule, fixture(__FILE__, 'constants_autoload_d.rb')
+end
diff --git a/spec/ruby/core/module/fixtures/constants_autoload_a.rb b/spec/ruby/core/module/fixtures/constants_autoload_a.rb
new file mode 100644
index 0000000000..48d3b63681
--- /dev/null
+++ b/spec/ruby/core/module/fixtures/constants_autoload_a.rb
@@ -0,0 +1,2 @@
+module CSAutoloadA
+end
diff --git a/spec/ruby/core/module/fixtures/constants_autoload_b.rb b/spec/ruby/core/module/fixtures/constants_autoload_b.rb
new file mode 100644
index 0000000000..29cd742d03
--- /dev/null
+++ b/spec/ruby/core/module/fixtures/constants_autoload_b.rb
@@ -0,0 +1,2 @@
+module CSAutoloadB
+end
diff --git a/spec/ruby/core/module/fixtures/constants_autoload_c.rb b/spec/ruby/core/module/fixtures/constants_autoload_c.rb
new file mode 100644
index 0000000000..9d6a6bf4d7
--- /dev/null
+++ b/spec/ruby/core/module/fixtures/constants_autoload_c.rb
@@ -0,0 +1,3 @@
+module CSAutoloadC
+ CONST = 7
+end
diff --git a/spec/ruby/core/module/fixtures/constants_autoload_d.rb b/spec/ruby/core/module/fixtures/constants_autoload_d.rb
new file mode 100644
index 0000000000..52d550bab0
--- /dev/null
+++ b/spec/ruby/core/module/fixtures/constants_autoload_d.rb
@@ -0,0 +1,4 @@
+module CSAutoloadD
+ module InnerModule
+ end
+end
diff --git a/spec/ruby/core/module/fixtures/module.rb b/spec/ruby/core/module/fixtures/module.rb
index 9050a272ec..34543ca2b4 100644
--- a/spec/ruby/core/module/fixtures/module.rb
+++ b/spec/ruby/core/module/fixtures/module.rb
@@ -1,4 +1,8 @@
module ModuleSpecs
module Anonymous
+ module Child
+ end
+
+ SameChild = Child
end
end
diff --git a/spec/ruby/core/module/fixtures/multi/foo.rb b/spec/ruby/core/module/fixtures/multi/foo.rb
new file mode 100644
index 0000000000..549996f08f
--- /dev/null
+++ b/spec/ruby/core/module/fixtures/multi/foo.rb
@@ -0,0 +1,6 @@
+module ModuleSpecs::Autoload
+ module Foo
+ autoload :Bar, 'foo/bar_baz'
+ autoload :Baz, 'foo/bar_baz'
+ end
+end
diff --git a/spec/ruby/core/module/fixtures/multi/foo/bar_baz.rb b/spec/ruby/core/module/fixtures/multi/foo/bar_baz.rb
new file mode 100644
index 0000000000..53d3849e1f
--- /dev/null
+++ b/spec/ruby/core/module/fixtures/multi/foo/bar_baz.rb
@@ -0,0 +1,11 @@
+require 'foo'
+
+module ModuleSpecs::Autoload
+ module Foo
+ class Bar
+ end
+
+ class Baz
+ end
+ end
+end
diff --git a/spec/ruby/core/module/fixtures/name.rb b/spec/ruby/core/module/fixtures/name.rb
index fb9e66c309..25c74d3944 100644
--- a/spec/ruby/core/module/fixtures/name.rb
+++ b/spec/ruby/core/module/fixtures/name.rb
@@ -7,4 +7,7 @@ module ModuleSpecs
Cß.name
end
end
+
+ module NameSpecs
+ end
end
diff --git a/spec/ruby/core/module/fixtures/refine.rb b/spec/ruby/core/module/fixtures/refine.rb
index 46975361dd..e8215aa640 100644
--- a/spec/ruby/core/module/fixtures/refine.rb
+++ b/spec/ruby/core/module/fixtures/refine.rb
@@ -3,6 +3,10 @@ module ModuleSpecs
def foo; "foo" end
end
+ class ClassWithSuperFoo
+ def foo; [:C] end
+ end
+
module PrependedModule
def foo; "foo from prepended module"; end
end
@@ -10,4 +14,12 @@ module ModuleSpecs
module IncludedModule
def foo; "foo from included module"; end
end
+
+ def self.build_refined_class(for_super: false)
+ if for_super
+ Class.new(ClassWithSuperFoo)
+ else
+ Class.new(ClassWithFoo)
+ end
+ end
end
diff --git a/spec/ruby/core/module/fixtures/set_temporary_name.rb b/spec/ruby/core/module/fixtures/set_temporary_name.rb
new file mode 100644
index 0000000000..901b3b94d1
--- /dev/null
+++ b/spec/ruby/core/module/fixtures/set_temporary_name.rb
@@ -0,0 +1,4 @@
+module ModuleSpecs
+ module SetTemporaryNameSpec
+ end
+end
diff --git a/spec/ruby/core/module/fixtures/using.rb b/spec/ruby/core/module/fixtures/using.rb
deleted file mode 100644
index 0ed9355af1..0000000000
--- a/spec/ruby/core/module/fixtures/using.rb
+++ /dev/null
@@ -1,10 +0,0 @@
-module ModuleSpecs
- module EmptyRefinement
- end
-
- module RefinementForStringToS
- refine String do
- def to_s; "hello from refinement"; end
- end
- end
-end
diff --git a/spec/ruby/core/module/freeze_spec.rb b/spec/ruby/core/module/freeze_spec.rb
index 07a0ee0837..fd76141431 100644
--- a/spec/ruby/core/module/freeze_spec.rb
+++ b/spec/ruby/core/module/freeze_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Module#freeze" do
it "needs to be reviewed for spec completeness"
diff --git a/spec/ruby/core/module/gt_spec.rb b/spec/ruby/core/module/gt_spec.rb
index 73a6c80b69..04cdd90efb 100644
--- a/spec/ruby/core/module/gt_spec.rb
+++ b/spec/ruby/core/module/gt_spec.rb
@@ -1,12 +1,12 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Module#>" do
it "returns false if self is a subclass of or includes the given module" do
- (ModuleSpecs::Child > ModuleSpecs::Parent).should be_false
- (ModuleSpecs::Child > ModuleSpecs::Basic).should be_false
- (ModuleSpecs::Child > ModuleSpecs::Super).should be_false
- (ModuleSpecs::Super > ModuleSpecs::Basic).should be_false
+ (ModuleSpecs::Child > ModuleSpecs::Parent).should == false
+ (ModuleSpecs::Child > ModuleSpecs::Basic).should == false
+ (ModuleSpecs::Child > ModuleSpecs::Super).should == false
+ (ModuleSpecs::Super > ModuleSpecs::Basic).should == false
end
it "returns true if self is a superclass of or included by the given module" do
@@ -31,6 +31,6 @@ describe "Module#>" do
end
it "raises a TypeError if the argument is not a class/module" do
- lambda { ModuleSpecs::Parent > mock('x') }.should raise_error(TypeError)
+ -> { ModuleSpecs::Parent > mock('x') }.should.raise(TypeError)
end
end
diff --git a/spec/ruby/core/module/gte_spec.rb b/spec/ruby/core/module/gte_spec.rb
index 84758e2df6..b19fc9fac3 100644
--- a/spec/ruby/core/module/gte_spec.rb
+++ b/spec/ruby/core/module/gte_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Module#>=" do
it "returns true if self is a superclass of, the same as or included by given module" do
@@ -28,6 +28,6 @@ describe "Module#>=" do
end
it "raises a TypeError if the argument is not a class/module" do
- lambda { ModuleSpecs::Parent >= mock('x') }.should raise_error(TypeError)
+ -> { ModuleSpecs::Parent >= mock('x') }.should.raise(TypeError)
end
end
diff --git a/spec/ruby/core/module/include_spec.rb b/spec/ruby/core/module/include_spec.rb
index e5d19fc820..b6201550e4 100644
--- a/spec/ruby/core/module/include_spec.rb
+++ b/spec/ruby/core/module/include_spec.rb
@@ -1,9 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Module#include" do
it "is a public method" do
- Module.should have_public_instance_method(:include, false)
+ Module.public_instance_methods(false).should.include?(:include)
end
it "calls #append_features(self) in reversed order on each module" do
@@ -33,24 +33,40 @@ describe "Module#include" do
end
it "adds all ancestor modules when a previously included module is included again" do
- ModuleSpecs::MultipleIncludes.ancestors.should include(ModuleSpecs::MA, ModuleSpecs::MB)
+ ModuleSpecs::MultipleIncludes.ancestors.to_set.should >= Set[ModuleSpecs::MA, ModuleSpecs::MB]
ModuleSpecs::MB.include(ModuleSpecs::MC)
ModuleSpecs::MultipleIncludes.include(ModuleSpecs::MB)
- ModuleSpecs::MultipleIncludes.ancestors.should include(ModuleSpecs::MA, ModuleSpecs::MB, ModuleSpecs::MC)
+ ModuleSpecs::MultipleIncludes.ancestors.to_set.should >= Set[ModuleSpecs::MA, ModuleSpecs::MB, ModuleSpecs::MC]
end
it "raises a TypeError when the argument is not a Module" do
- lambda { ModuleSpecs::Basic.include(Class.new) }.should raise_error(TypeError)
+ -> { ModuleSpecs::Basic.include(Class.new) }.should.raise(TypeError)
end
it "does not raise a TypeError when the argument is an instance of a subclass of Module" do
- lambda { ModuleSpecs::SubclassSpec.include(ModuleSpecs::Subclass.new) }.should_not raise_error(TypeError)
+ class ModuleSpecs::SubclassSpec::AClass
+ end
+ -> { ModuleSpecs::SubclassSpec::AClass.include(ModuleSpecs::Subclass.new) }.should_not.raise(TypeError)
+ ensure
+ ModuleSpecs::SubclassSpec.send(:remove_const, :AClass)
+ end
+
+ it "raises a TypeError when the argument is a refinement" do
+ refinement = nil
+
+ Module.new do
+ refine String do
+ refinement = self
+ end
+ end
+
+ -> { ModuleSpecs::Basic.include(refinement) }.should.raise(TypeError, "Cannot include refinement")
end
it "imports constants to modules and classes" do
- ModuleSpecs::A.constants.should include(:CONSTANT_A)
- ModuleSpecs::B.constants.should include(:CONSTANT_A, :CONSTANT_B)
- ModuleSpecs::C.constants.should include(:CONSTANT_A, :CONSTANT_B)
+ ModuleSpecs::A.constants.should.include?(:CONSTANT_A)
+ ModuleSpecs::B.constants.to_set.should >= Set[:CONSTANT_A, :CONSTANT_B]
+ ModuleSpecs::C.constants.to_set.should >= Set[:CONSTANT_A, :CONSTANT_B]
end
it "shadows constants from ancestors" do
@@ -68,9 +84,9 @@ describe "Module#include" do
end
it "imports instance methods to modules and classes" do
- ModuleSpecs::A.instance_methods.should include(:ma)
- ModuleSpecs::B.instance_methods.should include(:ma,:mb)
- ModuleSpecs::C.instance_methods.should include(:ma,:mb)
+ ModuleSpecs::A.instance_methods.should.include?(:ma)
+ ModuleSpecs::B.instance_methods.to_set.should >= Set[:ma,:mb]
+ ModuleSpecs::C.instance_methods.to_set.should >= Set[:ma,:mb]
end
it "does not import methods to modules and classes" do
@@ -104,9 +120,9 @@ describe "Module#include" do
class A; include M; end
class B < A; include M; end
- all = [A,B,M]
+ all = [A, B, M]
- (B.ancestors & all).should == [B, A, M]
+ (B.ancestors.filter { |a| all.include?(a) }).should == [B, A, M]
end
end
@@ -130,7 +146,7 @@ describe "Module#include" do
anc = B.ancestors
[B, U, V, W, A, X].each do |i|
- anc.include?(i).should be_true
+ anc.include?(i).should == true
end
class B; include V; end
@@ -138,7 +154,7 @@ describe "Module#include" do
# the only new module is Y, it is added after U since it follows U in V mixin list:
anc = B.ancestors
[B, U, Y, V, W, A, X].each do |i|
- anc.include?(i).should be_true
+ anc.include?(i).should == true
end
end
end
@@ -158,31 +174,19 @@ describe "Module#include" do
end
it "detects cyclic includes" do
- lambda {
+ -> {
module ModuleSpecs::M
include ModuleSpecs::M
end
- }.should raise_error(ArgumentError)
- end
-
- ruby_version_is ''...'2.4' do
- it "accepts no-arguments" do
- lambda {
- Module.new do
- include
- end
- }.should_not raise_error
- end
+ }.should.raise(ArgumentError)
end
- ruby_version_is '2.4' do
- it "doesn't accept no-arguments" do
- lambda {
- Module.new do
- include
- end
- }.should raise_error(ArgumentError)
- end
+ it "doesn't accept no-arguments" do
+ -> {
+ Module.new do
+ include
+ end
+ }.should.raise(ArgumentError)
end
it "returns the class it's included into" do
@@ -246,6 +250,360 @@ describe "Module#include" do
remove_const :C
end
end
+
+ it "updates the method when an included module is updated" do
+ a_class = Class.new do
+ def foo
+ 'a'
+ end
+ end
+
+ m_module = Module.new
+
+ b_class = Class.new(a_class) do
+ include m_module
+ end
+
+ b = b_class.new
+
+ foo = -> { b.foo }
+
+ foo.call.should == 'a'
+
+ m_module.module_eval do
+ def foo
+ 'm'
+ end
+ end
+
+ foo.call.should == 'm'
+ end
+
+
+ it "updates the method when a module included after a call is later updated" do
+ m_module = Module.new
+ a_class = Class.new do
+ def foo
+ 'a'
+ end
+ end
+ b_class = Class.new(a_class)
+ b = b_class.new
+ foo = -> { b.foo }
+ foo.call.should == 'a'
+
+ b_class.include m_module
+ foo.call.should == 'a'
+
+ m_module.module_eval do
+ def foo
+ "m"
+ end
+ end
+ foo.call.should == 'm'
+ end
+
+ it "updates the method when a nested included module is updated" do
+ a_class = Class.new do
+ def foo
+ 'a'
+ end
+ end
+
+ n_module = Module.new
+
+ m_module = Module.new do
+ include n_module
+ end
+
+ b_class = Class.new(a_class) do
+ include m_module
+ end
+
+ b = b_class.new
+
+ foo = -> { b.foo }
+
+ foo.call.should == 'a'
+
+ n_module.module_eval do
+ def foo
+ 'n'
+ end
+ end
+
+ foo.call.should == 'n'
+ end
+
+ it "updates the method when a new module is included" do
+ a_class = Class.new do
+ def foo
+ 'a'
+ end
+ end
+
+ m_module = Module.new do
+ def foo
+ 'm'
+ end
+ end
+
+ b_class = Class.new(a_class)
+ b = b_class.new
+
+ foo = -> { b.foo }
+
+ foo.call.should == 'a'
+
+ b_class.class_eval do
+ include m_module
+ end
+
+ foo.call.should == 'm'
+ end
+
+ it "updates the method when a new module with nested module is included" do
+ a_class = Class.new do
+ def foo
+ 'a'
+ end
+ end
+
+ n_module = Module.new do
+ def foo
+ 'n'
+ end
+ end
+
+ m_module = Module.new do
+ include n_module
+ end
+
+ b_class = Class.new(a_class)
+ b = b_class.new
+
+ foo = -> { b.foo }
+
+ foo.call.should == 'a'
+
+ b_class.class_eval do
+ include m_module
+ end
+
+ foo.call.should == 'n'
+ end
+
+ it "updates the constant when an included module is updated" do
+ module ModuleSpecs::ConstUpdated
+ module A
+ FOO = 'a'
+ end
+
+ module M
+ end
+
+ module B
+ include A
+ include M
+ def self.foo
+ FOO
+ end
+ end
+
+ B.foo.should == 'a'
+
+ M.const_set(:FOO, 'm')
+ B.foo.should == 'm'
+ end
+ ensure
+ ModuleSpecs.send(:remove_const, :ConstUpdated)
+ end
+
+ it "updates the constant when a module included after a call is later updated" do
+ module ModuleSpecs::ConstLaterUpdated
+ module A
+ FOO = 'a'
+ end
+
+ module B
+ include A
+ def self.foo
+ FOO
+ end
+ end
+
+ B.foo.should == 'a'
+
+ module M
+ end
+ B.include M
+
+ B.foo.should == 'a'
+
+ M.const_set(:FOO, 'm')
+ B.foo.should == 'm'
+ end
+ ensure
+ ModuleSpecs.send(:remove_const, :ConstLaterUpdated)
+ end
+
+ it "updates the constant when a module included in another module after a call is later updated" do
+ module ModuleSpecs::ConstModuleLaterUpdated
+ module A
+ FOO = 'a'
+ end
+
+ module B
+ include A
+ def self.foo
+ FOO
+ end
+ end
+
+ B.foo.should == 'a'
+
+ module M
+ end
+ B.include M
+
+ B.foo.should == 'a'
+
+ M.const_set(:FOO, 'm')
+ B.foo.should == 'm'
+ end
+ ensure
+ ModuleSpecs.send(:remove_const, :ConstModuleLaterUpdated)
+ end
+
+ it "updates the constant when a nested included module is updated" do
+ module ModuleSpecs::ConstUpdatedNestedIncludeUpdated
+ module A
+ FOO = 'a'
+ end
+
+ module N
+ end
+
+ module M
+ include N
+ end
+
+ module B
+ include A
+ include M
+ def self.foo
+ FOO
+ end
+ end
+
+ B.foo.should == 'a'
+
+ N.const_set(:FOO, 'n')
+ B.foo.should == 'n'
+ end
+ ensure
+ ModuleSpecs.send(:remove_const, :ConstUpdatedNestedIncludeUpdated)
+ end
+
+ it "updates the constant when a new module is included" do
+ module ModuleSpecs::ConstUpdatedNewInclude
+ module A
+ FOO = 'a'
+ end
+
+ module M
+ FOO = 'm'
+ end
+
+ module B
+ include A
+ def self.foo
+ FOO
+ end
+ end
+
+ B.foo.should == 'a'
+
+ B.include(M)
+ B.foo.should == 'm'
+ end
+ ensure
+ ModuleSpecs.send(:remove_const, :ConstUpdatedNewInclude)
+ end
+
+ it "updates the constant when a new module with nested module is included" do
+ module ModuleSpecs::ConstUpdatedNestedIncluded
+ module A
+ FOO = 'a'
+ end
+
+ module N
+ FOO = 'n'
+ end
+
+ module M
+ include N
+ end
+
+ module B
+ include A
+ def self.foo
+ FOO
+ end
+ end
+
+ B.foo.should == 'a'
+
+ B.include M
+ B.foo.should == 'n'
+ end
+ ensure
+ ModuleSpecs.send(:remove_const, :ConstUpdatedNestedIncluded)
+ end
+
+ it "overrides a previous super method call" do
+ c1 = Class.new do
+ def foo
+ [:c1]
+ end
+ end
+ c2 = Class.new(c1) do
+ def foo
+ [:c2] + super
+ end
+ end
+ c2.new.foo.should == [:c2, :c1]
+ m = Module.new do
+ def foo
+ [:m1]
+ end
+ end
+ c2.include(m)
+ c2.new.foo.should == [:c2, :m1]
+ end
+
+ it "update a module when a nested module is updated and includes a module on its own" do
+ m1 = Module.new
+ m2 = Module.new do
+ def m2; [:m2]; end
+ end
+ m3 = Module.new do
+ def m3; [:m3]; end
+ end
+ m4 = Module.new do
+ def m4; [:m4]; end
+ end
+ c = Class.new
+
+ c.include(m1)
+ m1.include(m2)
+ m2.include(m3)
+ m3.include(m4)
+
+ c.new.m2.should == [:m2]
+ c.new.m3.should == [:m3]
+ c.new.m4.should == [:m4]
+ end
end
describe "Module#include?" do
@@ -264,7 +622,7 @@ describe "Module#include?" do
end
it "raises a TypeError when no module was given" do
- lambda { ModuleSpecs::Child.include?("Test") }.should raise_error(TypeError)
- lambda { ModuleSpecs::Child.include?(ModuleSpecs::Parent) }.should raise_error(TypeError)
+ -> { ModuleSpecs::Child.include?("Test") }.should.raise(TypeError)
+ -> { ModuleSpecs::Child.include?(ModuleSpecs::Parent) }.should.raise(TypeError)
end
end
diff --git a/spec/ruby/core/module/included_modules_spec.rb b/spec/ruby/core/module/included_modules_spec.rb
index 91e1298eef..e22ee5e6cf 100644
--- a/spec/ruby/core/module/included_modules_spec.rb
+++ b/spec/ruby/core/module/included_modules_spec.rb
@@ -1,12 +1,14 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Module#included_modules" do
it "returns a list of modules included in self" do
ModuleSpecs.included_modules.should == []
- ModuleSpecs::Child.included_modules.should include(ModuleSpecs::Super, ModuleSpecs::Basic, Kernel)
- ModuleSpecs::Parent.included_modules.should include(Kernel)
+
+ ModuleSpecs::Child.included_modules.to_set.should >= Set[ModuleSpecs::Super, ModuleSpecs::Basic, Kernel]
+ ModuleSpecs::Parent.included_modules.should.include?(Kernel)
ModuleSpecs::Basic.included_modules.should == []
- ModuleSpecs::Super.included_modules.should include(ModuleSpecs::Basic)
+ ModuleSpecs::Super.included_modules.should.include?(ModuleSpecs::Basic)
+ ModuleSpecs::WithPrependedModule.included_modules.should.include?(ModuleSpecs::ModuleWithPrepend)
end
end
diff --git a/spec/ruby/core/module/included_spec.rb b/spec/ruby/core/module/included_spec.rb
index 39a08b6ed8..d8a6c3f839 100644
--- a/spec/ruby/core/module/included_spec.rb
+++ b/spec/ruby/core/module/included_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Module#included" do
it "is invoked when self is included in another module or class" do
@@ -34,11 +34,11 @@ describe "Module#included" do
end
it "is private in its default implementation" do
- Module.should have_private_instance_method(:included)
+ Module.private_instance_methods(false).should.include?(:included)
end
it "works with super using a singleton class" do
ModuleSpecs::SingletonOnModuleCase::Bar.include ModuleSpecs::SingletonOnModuleCase::Foo
- ModuleSpecs::SingletonOnModuleCase::Bar.included_called?.should == true
+ ModuleSpecs::SingletonOnModuleCase::Bar.should.included_called?
end
end
diff --git a/spec/ruby/core/module/initialize_copy_spec.rb b/spec/ruby/core/module/initialize_copy_spec.rb
index 85f1bbeb17..7ae48f85a9 100644
--- a/spec/ruby/core/module/initialize_copy_spec.rb
+++ b/spec/ruby/core/module/initialize_copy_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Module#initialize_copy" do
it "should retain singleton methods when duped" do
@@ -7,4 +7,12 @@ describe "Module#initialize_copy" do
end
mod.dup.methods(false).should == [:hello]
end
+
+ # jruby/jruby#5245, https://bugs.ruby-lang.org/issues/3461
+ it "should produce a duped module with inspectable class methods" do
+ mod = Module.new
+ def mod.hello
+ end
+ mod.dup.method(:hello).inspect.should =~ /Module.*hello/
+ end
end
diff --git a/spec/ruby/core/module/initialize_spec.rb b/spec/ruby/core/module/initialize_spec.rb
index b32e0f5d2a..99e41e4619 100644
--- a/spec/ruby/core/module/initialize_spec.rb
+++ b/spec/ruby/core/module/initialize_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Module#initialize" do
it "accepts a block" do
diff --git a/spec/ruby/core/module/inspect_spec.rb b/spec/ruby/core/module/inspect_spec.rb
new file mode 100644
index 0000000000..68c8494c96
--- /dev/null
+++ b/spec/ruby/core/module/inspect_spec.rb
@@ -0,0 +1,7 @@
+require_relative '../../spec_helper'
+
+describe "Module#inspect" do
+ it "is an alias of Module#to_s" do
+ Module.instance_method(:inspect).should == Module.instance_method(:to_s)
+ end
+end
diff --git a/spec/ruby/core/module/instance_method_spec.rb b/spec/ruby/core/module/instance_method_spec.rb
index 82e397b4bc..8615e352f6 100644
--- a/spec/ruby/core/module/instance_method_spec.rb
+++ b/spec/ruby/core/module/instance_method_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Module#instance_method" do
before :all do
@@ -9,7 +9,7 @@ describe "Module#instance_method" do
end
it "is a public method" do
- Module.should have_public_instance_method(:instance_method, false)
+ Module.public_instance_methods(false).should.include?(:instance_method)
end
it "requires an argument" do
@@ -17,26 +17,26 @@ describe "Module#instance_method" do
end
it "returns an UnboundMethod corresponding to the given name" do
- @parent_um.should be_kind_of(UnboundMethod)
+ @parent_um.should.is_a?(UnboundMethod)
@parent_um.bind(ModuleSpecs::InstanceMeth.new).call.should == :foo
end
it "returns an UnboundMethod corresponding to the given name from a superclass" do
- @child_um.should be_kind_of(UnboundMethod)
+ @child_um.should.is_a?(UnboundMethod)
@child_um.bind(ModuleSpecs::InstanceMethChild.new).call.should == :foo
end
it "returns an UnboundMethod corresponding to the given name from an included Module" do
- @mod_um.should be_kind_of(UnboundMethod)
+ @mod_um.should.is_a?(UnboundMethod)
@mod_um.bind(ModuleSpecs::InstanceMethChild.new).call.should == :bar
end
it "returns an UnboundMethod when given a protected method name" do
- ModuleSpecs::Basic.instance_method(:protected_module).should be_an_instance_of(UnboundMethod)
+ ModuleSpecs::Basic.instance_method(:protected_module).should.instance_of?(UnboundMethod)
end
it "returns an UnboundMethod when given a private method name" do
- ModuleSpecs::Basic.instance_method(:private_module).should be_an_instance_of(UnboundMethod)
+ ModuleSpecs::Basic.instance_method(:private_module).should.instance_of?(UnboundMethod)
end
it "gives UnboundMethod method name, Module defined in and Module extracted from" do
@@ -45,20 +45,41 @@ describe "Module#instance_method" do
@parent_um.inspect.should =~ /\bModuleSpecs::InstanceMeth\b/
@child_um.inspect.should =~ /\bfoo\b/
@child_um.inspect.should =~ /\bModuleSpecs::InstanceMeth\b/
- @child_um.inspect.should =~ /\bModuleSpecs::InstanceMethChild\b/
+
@mod_um.inspect.should =~ /\bbar\b/
@mod_um.inspect.should =~ /\bModuleSpecs::InstanceMethMod\b/
- @mod_um.inspect.should =~ /\bModuleSpecs::InstanceMethChild\b/
end
- it "raises a TypeError if not passed a symbol" do
- lambda { Object.instance_method([]) }.should raise_error(TypeError)
- lambda { Object.instance_method(0) }.should raise_error(TypeError)
+ it "raises a TypeError if the given name is not a String/Symbol" do
+ -> { Object.instance_method([]) }.should.raise(TypeError, /is not a symbol nor a string/)
+ -> { Object.instance_method(0) }.should.raise(TypeError, /is not a symbol nor a string/)
+ -> { Object.instance_method(nil) }.should.raise(TypeError, /is not a symbol nor a string/)
+ -> { Object.instance_method(mock('x')) }.should.raise(TypeError, /is not a symbol nor a string/)
+ end
+
+ it "accepts String name argument" do
+ method = ModuleSpecs::InstanceMeth.instance_method(:foo)
+ method.should.is_a?(UnboundMethod)
+ end
+
+ it "accepts Symbol name argument" do
+ method = ModuleSpecs::InstanceMeth.instance_method("foo")
+ method.should.is_a?(UnboundMethod)
end
- it "raises a TypeError if the given name is not a string/symbol" do
- lambda { Object.instance_method(nil) }.should raise_error(TypeError)
- lambda { Object.instance_method(mock('x')) }.should raise_error(TypeError)
+ it "converts non-String name by calling #to_str method" do
+ obj = Object.new
+ def obj.to_str() "foo" end
+
+ method = ModuleSpecs::InstanceMeth.instance_method(obj)
+ method.should.is_a?(UnboundMethod)
+ end
+
+ it "raises TypeError when passed non-String name and #to_str returns non-String value" do
+ obj = Object.new
+ def obj.to_str() [] end
+
+ -> { ModuleSpecs::InstanceMeth.instance_method(obj) }.should raise_consistent_error(TypeError, /can't convert Object into String/)
end
it "raises a NameError if the method has been undefined" do
@@ -66,13 +87,13 @@ describe "Module#instance_method" do
child.send :undef_method, :foo
um = ModuleSpecs::InstanceMeth.instance_method(:foo)
um.should == @parent_um
- lambda do
+ -> do
child.instance_method(:foo)
- end.should raise_error(NameError)
+ end.should.raise(NameError)
end
it "raises a NameError if the method does not exist" do
- lambda { Object.instance_method(:missing) }.should raise_error(NameError)
+ -> { Object.instance_method(:missing) }.should.raise(NameError)
end
it "sets the NameError#name attribute to the name of the missing method" do
diff --git a/spec/ruby/core/module/instance_methods_spec.rb b/spec/ruby/core/module/instance_methods_spec.rb
index 289879cdbc..dbb6df8c34 100644
--- a/spec/ruby/core/module/instance_methods_spec.rb
+++ b/spec/ruby/core/module/instance_methods_spec.rb
@@ -1,24 +1,25 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Module#instance_methods" do
it "does not return methods undefined in a superclass" do
methods = ModuleSpecs::Parent.instance_methods(false)
- methods.should_not include(:undefed_method)
+ methods.should_not.include?(:undefed_method)
end
it "only includes module methods on an included module" do
methods = ModuleSpecs::Basic.instance_methods(false)
- methods.should include(:public_module)
+ methods.should.include?(:public_module)
# Child is an including class
methods = ModuleSpecs::Child.instance_methods(false)
- methods.should include(:public_child)
- methods.should_not include(:public_module)
+ methods.should.include?(:public_child)
+ methods.should_not.include?(:public_module)
end
it "does not return methods undefined in a subclass" do
methods = ModuleSpecs::Grandchild.instance_methods
- methods.should_not include(:parent_method, :another_parent_method)
+ methods.should_not.include?(:parent_method)
+ methods.should_not.include?(:another_parent_method)
end
it "does not return methods undefined in the current class" do
@@ -28,34 +29,35 @@ describe "Module#instance_methods" do
end
ModuleSpecs::Child.send(:undef_method, :undefed_child)
methods = ModuleSpecs::Child.instance_methods
- methods.should_not include(:undefed_method, :undefed_child)
+ methods.should_not.include?(:undefed_method)
+ methods.should_not.include?(:undefed_child)
end
it "does not return methods from an included module that are undefined in the class" do
- ModuleSpecs::Grandchild.instance_methods.should_not include(:super_included_method)
+ ModuleSpecs::Grandchild.instance_methods.should_not.include?(:super_included_method)
end
it "returns the public and protected methods of self if include_super is false" do
methods = ModuleSpecs::Parent.instance_methods(false)
- methods.should include(:protected_parent, :public_parent)
+ methods.to_set.should >= Set[:protected_parent, :public_parent]
methods = ModuleSpecs::Child.instance_methods(false)
- methods.should include(:protected_child, :public_child)
+ methods.to_set.should >= Set[:protected_child, :public_child]
end
it "returns the public and protected methods of self and it's ancestors" do
methods = ModuleSpecs::Basic.instance_methods
- methods.should include(:protected_module, :public_module)
+ methods.to_set.should >= Set[:protected_module, :public_module]
methods = ModuleSpecs::Super.instance_methods
- methods.should include(:protected_module, :protected_super_module,
- :public_module, :public_super_module)
+ methods.to_set.should >= Set[:protected_module, :protected_super_module,
+ :public_module, :public_super_module]
end
it "makes a private Object instance method public in Kernel" do
methods = Kernel.instance_methods
- methods.should include(:module_specs_private_method_on_object_for_kernel_public)
+ methods.should.include?(:module_specs_private_method_on_object_for_kernel_public)
methods = Object.instance_methods
- methods.should_not include(:module_specs_private_method_on_object_for_kernel_public)
+ methods.should_not.include?(:module_specs_private_method_on_object_for_kernel_public)
end
end
diff --git a/spec/ruby/core/module/lt_spec.rb b/spec/ruby/core/module/lt_spec.rb
index ce0d25b5a2..8567a24993 100644
--- a/spec/ruby/core/module/lt_spec.rb
+++ b/spec/ruby/core/module/lt_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Module#<" do
it "returns true if self is a subclass of or includes the given module" do
@@ -10,10 +10,10 @@ describe "Module#<" do
end
it "returns false if self is a superclass of or included by the given module" do
- (ModuleSpecs::Parent < ModuleSpecs::Child).should be_false
- (ModuleSpecs::Basic < ModuleSpecs::Child).should be_false
- (ModuleSpecs::Super < ModuleSpecs::Child).should be_false
- (ModuleSpecs::Basic < ModuleSpecs::Super).should be_false
+ (ModuleSpecs::Parent < ModuleSpecs::Child).should == false
+ (ModuleSpecs::Basic < ModuleSpecs::Child).should == false
+ (ModuleSpecs::Super < ModuleSpecs::Child).should == false
+ (ModuleSpecs::Basic < ModuleSpecs::Super).should == false
end
it "returns false if self is the same as the given module" do
@@ -31,6 +31,6 @@ describe "Module#<" do
end
it "raises a TypeError if the argument is not a class/module" do
- lambda { ModuleSpecs::Parent < mock('x') }.should raise_error(TypeError)
+ -> { ModuleSpecs::Parent < mock('x') }.should.raise(TypeError)
end
end
diff --git a/spec/ruby/core/module/lte_spec.rb b/spec/ruby/core/module/lte_spec.rb
index 8a699b4714..c6aab94e9f 100644
--- a/spec/ruby/core/module/lte_spec.rb
+++ b/spec/ruby/core/module/lte_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Module#<=" do
it "returns true if self is a subclass of, the same as or includes the given module" do
@@ -28,6 +28,6 @@ describe "Module#<=" do
end
it "raises a TypeError if the argument is not a class/module" do
- lambda { ModuleSpecs::Parent <= mock('x') }.should raise_error(TypeError)
+ -> { ModuleSpecs::Parent <= mock('x') }.should.raise(TypeError)
end
end
diff --git a/spec/ruby/core/module/method_added_spec.rb b/spec/ruby/core/module/method_added_spec.rb
index 643291be17..996a14eb86 100644
--- a/spec/ruby/core/module/method_added_spec.rb
+++ b/spec/ruby/core/module/method_added_spec.rb
@@ -1,9 +1,13 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Module#method_added" do
+ before :each do
+ ScratchPad.record []
+ end
+
it "is a private instance method" do
- Module.should have_private_instance_method(:method_added)
+ Module.private_instance_methods(false).should.include?(:method_added)
end
it "returns nil in the default implementation" do
@@ -13,8 +17,6 @@ describe "Module#method_added" do
end
it "is called when a new instance method is defined in self" do
- ScratchPad.record []
-
Module.new do
def self.method_added(name)
ScratchPad << name
@@ -32,8 +34,6 @@ describe "Module#method_added" do
it "is not called when a singleton method is added" do
# obj.singleton_method_added is called instead
- ScratchPad.record []
-
klass = Class.new
def klass.method_added(name)
ScratchPad << name
@@ -57,6 +57,90 @@ describe "Module#method_added" do
undef_method :method_to_undef
end
- m.should_not have_method(:method_to_undef)
+ m.should_not.respond_to?(:method_to_undef)
+ end
+
+ it "is not called when a method changes visibility" do
+ Module.new do
+ def public_method
+ end
+
+ def private_method
+ end
+
+ def self.method_added(name)
+ ScratchPad << name
+ end
+
+ public :public_method
+ private :public_method
+
+ private :private_method
+ public :private_method
+ end
+
+ ScratchPad.recorded.should == []
+ end
+
+ it "is called when using #private in a subclass" do
+ parent = Class.new do
+ def foo
+ end
+ end
+
+ Class.new(parent) do
+ def self.method_added(name)
+ ScratchPad << name
+ end
+
+ # Create an instance as that might initialize some method lookup caches, which is interesting to test
+ self.new.foo
+
+ private :foo
+ public :foo
+ end
+
+ ScratchPad.recorded.should == [:foo]
+ end
+
+ it "is not called when a method is copied via module_function, rather #singleton_method_added is called" do
+ Module.new do
+ def mod_function
+ end
+
+ def self.method_added(name)
+ ScratchPad << [:method_added, name]
+ end
+
+ def self.singleton_method_added(name)
+ ScratchPad << [:singleton_method_added, name]
+ end
+
+ ScratchPad.record []
+
+ module_function :mod_function
+ end
+
+ ScratchPad.recorded.should == [[:singleton_method_added, :mod_function]]
+ end
+
+ it "is called with a precise caller location with the line of the 'def'" do
+ line = nil
+
+ Module.new do
+ def self.method_added(name)
+ location = caller_locations(1, 1)[0]
+ ScratchPad << location.lineno
+ end
+
+ line = __LINE__
+ def first
+ end
+
+ def second
+ end
+ end
+
+ ScratchPad.recorded.should == [line + 1, line + 4]
end
end
diff --git a/spec/ruby/core/module/method_defined_spec.rb b/spec/ruby/core/module/method_defined_spec.rb
index d6206fa57e..e6b4c7b817 100644
--- a/spec/ruby/core/module/method_defined_spec.rb
+++ b/spec/ruby/core/module/method_defined_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Module#method_defined?" do
it "returns true if a public or private method with the given name is defined in self, self's ancestors or one of self's included modules" do
@@ -27,17 +27,17 @@ describe "Module#method_defined?" do
it "does not search Object or Kernel when called on a module" do
m = Module.new
- m.method_defined?(:module_specs_public_method_on_kernel).should be_false
+ m.method_defined?(:module_specs_public_method_on_kernel).should == false
end
- it "raises a TypeError when the given object is not a string/symbol/fixnum" do
+ it "raises a TypeError when the given object is not a string/symbol" do
c = Class.new
o = mock('123')
- lambda { c.method_defined?(o) }.should raise_error(TypeError)
+ -> { c.method_defined?(o) }.should.raise(TypeError)
o.should_receive(:to_str).and_return(123)
- lambda { c.method_defined?(o) }.should raise_error(TypeError)
+ -> { c.method_defined?(o) }.should.raise(TypeError)
end
it "converts the given name to a string using to_str" do
@@ -46,4 +46,53 @@ describe "Module#method_defined?" do
c.method_defined?(o).should == true
end
+
+ # works as method_defined?(method_name)
+ describe "when passed true as a second optional argument" do
+ it "performs a lookup in ancestors" do
+ ModuleSpecs::Child.method_defined?(:public_child, true).should == true
+ ModuleSpecs::Child.method_defined?(:protected_child, true).should == true
+ ModuleSpecs::Child.method_defined?(:accessor_method, true).should == true
+ ModuleSpecs::Child.method_defined?(:private_child, true).should == false
+
+ # Defined in Parent
+ ModuleSpecs::Child.method_defined?(:public_parent, true).should == true
+ ModuleSpecs::Child.method_defined?(:protected_parent, true).should == true
+ ModuleSpecs::Child.method_defined?(:private_parent, true).should == false
+
+ # Defined in Module
+ ModuleSpecs::Child.method_defined?(:public_module, true).should == true
+ ModuleSpecs::Child.method_defined?(:protected_module, true).should == true
+ ModuleSpecs::Child.method_defined?(:private_module, true).should == false
+
+ # Defined in SuperModule
+ ModuleSpecs::Child.method_defined?(:public_super_module, true).should == true
+ ModuleSpecs::Child.method_defined?(:protected_super_module, true).should == true
+ ModuleSpecs::Child.method_defined?(:private_super_module, true).should == false
+ end
+ end
+
+ describe "when passed false as a second optional argument" do
+ it "checks only the class itself" do
+ ModuleSpecs::Child.method_defined?(:public_child, false).should == true
+ ModuleSpecs::Child.method_defined?(:protected_child, false).should == true
+ ModuleSpecs::Child.method_defined?(:accessor_method, false).should == true
+ ModuleSpecs::Child.method_defined?(:private_child, false).should == false
+
+ # Defined in Parent
+ ModuleSpecs::Child.method_defined?(:public_parent, false).should == false
+ ModuleSpecs::Child.method_defined?(:protected_parent, false).should == false
+ ModuleSpecs::Child.method_defined?(:private_parent, false).should == false
+
+ # Defined in Module
+ ModuleSpecs::Child.method_defined?(:public_module, false).should == false
+ ModuleSpecs::Child.method_defined?(:protected_module, false).should == false
+ ModuleSpecs::Child.method_defined?(:private_module, false).should == false
+
+ # Defined in SuperModule
+ ModuleSpecs::Child.method_defined?(:public_super_module, false).should == false
+ ModuleSpecs::Child.method_defined?(:protected_super_module, false).should == false
+ ModuleSpecs::Child.method_defined?(:private_super_module, false).should == false
+ end
+ end
end
diff --git a/spec/ruby/core/module/method_removed_spec.rb b/spec/ruby/core/module/method_removed_spec.rb
index 4c1443cfaa..80e546406c 100644
--- a/spec/ruby/core/module/method_removed_spec.rb
+++ b/spec/ruby/core/module/method_removed_spec.rb
@@ -1,9 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Module#method_removed" do
it "is a private instance method" do
- Module.should have_private_instance_method(:method_removed)
+ Module.private_instance_methods(false).should.include?(:method_removed)
end
it "returns nil in the default implementation" do
diff --git a/spec/ruby/core/module/method_undefined_spec.rb b/spec/ruby/core/module/method_undefined_spec.rb
index 65001b9421..596c5c50e2 100644
--- a/spec/ruby/core/module/method_undefined_spec.rb
+++ b/spec/ruby/core/module/method_undefined_spec.rb
@@ -1,9 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Module#method_undefined" do
it "is a private instance method" do
- Module.should have_private_instance_method(:method_undefined)
+ Module.private_instance_methods(false).should.include?(:method_undefined)
end
it "returns nil in the default implementation" do
diff --git a/spec/ruby/core/module/module_eval_spec.rb b/spec/ruby/core/module/module_eval_spec.rb
index 2bef0e9abf..bcd51ca19d 100644
--- a/spec/ruby/core/module/module_eval_spec.rb
+++ b/spec/ruby/core/module/module_eval_spec.rb
@@ -1,7 +1,175 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/class_eval', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Module#module_eval" do
- it_behaves_like :module_class_eval, :module_eval
+ # TODO: This should probably be replaced with a "should behave like" that uses
+ # the many scoping/binding specs from kernel/eval_spec, since most of those
+ # behaviors are the same for instance_eval. See also module_eval/class_eval.
+
+ it "evaluates a given string in the context of self" do
+ ModuleSpecs.module_eval("self").should == ModuleSpecs
+ ModuleSpecs.module_eval("1 + 1").should == 2
+ end
+
+ it "does not add defined methods to other classes" do
+ FalseClass.module_eval do
+ def foo
+ 'foo'
+ end
+ end
+ -> {42.foo}.should.raise(NoMethodError)
+ end
+
+ it "resolves constants in the caller scope" do
+ ModuleSpecs::ClassEvalTest.get_constant_from_scope.should == ModuleSpecs::Lookup
+ end
+
+ it "resolves constants in the caller scope ignoring send" do
+ ModuleSpecs::ClassEvalTest.get_constant_from_scope_with_send(:module_eval).should == ModuleSpecs::Lookup
+ end
+
+ it "resolves constants in the receiver's scope" do
+ ModuleSpecs.module_eval("Lookup").should == ModuleSpecs::Lookup
+ ModuleSpecs.module_eval("Lookup::LOOKIE").should == ModuleSpecs::Lookup::LOOKIE
+ end
+
+ it "defines constants in the receiver's scope" do
+ ModuleSpecs.module_eval("module NewEvaluatedModule;end")
+ ModuleSpecs.const_defined?(:NewEvaluatedModule, false).should == true
+ end
+
+ it "evaluates a given block in the context of self" do
+ ModuleSpecs.module_eval { self }.should == ModuleSpecs
+ ModuleSpecs.module_eval { 1 + 1 }.should == 2
+ end
+
+ it "passes the module as the first argument of the block" do
+ given = nil
+ ModuleSpecs.module_eval do |block_parameter|
+ given = block_parameter
+ end
+ given.should.equal? ModuleSpecs
+ end
+
+ it "uses the optional filename and lineno parameters for error messages" do
+ ModuleSpecs.module_eval("[__FILE__, __LINE__]", "test", 102).should == ["test", 102]
+ end
+
+ it "uses the caller location as default filename" do
+ ModuleSpecs.module_eval("[__FILE__, __LINE__]").should == ["(eval at #{__FILE__}:#{__LINE__})", 1]
+ end
+
+ it "converts a non-string filename to a string using to_str" do
+ (file = mock(__FILE__)).should_receive(:to_str).and_return(__FILE__)
+ ModuleSpecs.module_eval("1+1", file)
+
+ (file = mock(__FILE__)).should_receive(:to_str).and_return(__FILE__)
+ ModuleSpecs.module_eval("1+1", file, 15)
+ end
+
+ it "raises a TypeError when the given filename can't be converted to string using to_str" do
+ (file = mock('123')).should_receive(:to_str).and_return(123)
+ -> { ModuleSpecs.module_eval("1+1", file) }.should raise_consistent_error(TypeError, /can't convert MockObject into String/)
+ end
+
+ it "converts non string eval-string to string using to_str" do
+ (o = mock('1 + 1')).should_receive(:to_str).and_return("1 + 1")
+ ModuleSpecs.module_eval(o).should == 2
+
+ (o = mock('1 + 1')).should_receive(:to_str).and_return("1 + 1")
+ ModuleSpecs.module_eval(o, "file.rb").should == 2
+
+ (o = mock('1 + 1')).should_receive(:to_str).and_return("1 + 1")
+ ModuleSpecs.module_eval(o, "file.rb", 15).should == 2
+ end
+
+ it "raises a TypeError when the given eval-string can't be converted to string using to_str" do
+ o = mock('x')
+ -> { ModuleSpecs.module_eval(o) }.should.raise(TypeError, "no implicit conversion of MockObject into String")
+
+ (o = mock('123')).should_receive(:to_str).and_return(123)
+ -> { ModuleSpecs.module_eval(o) }.should raise_consistent_error(TypeError, /can't convert MockObject into String/)
+ end
+
+ it "raises an ArgumentError when no arguments and no block are given" do
+ -> { ModuleSpecs.module_eval }.should.raise(ArgumentError, "wrong number of arguments (given 0, expected 1..3)")
+ end
+
+ it "raises an ArgumentError when more than 3 arguments are given" do
+ -> {
+ ModuleSpecs.module_eval("1 + 1", "some file", 0, "bogus")
+ }.should.raise(ArgumentError, "wrong number of arguments (given 4, expected 1..3)")
+ end
+
+ it "raises an ArgumentError when a block and normal arguments are given" do
+ -> {
+ ModuleSpecs.module_eval("1 + 1") { 1 + 1 }
+ }.should.raise(ArgumentError, "wrong number of arguments (given 1, expected 0)")
+ end
+
+ # This case was found because Rubinius was caching the compiled
+ # version of the string and not duping the methods within the
+ # eval, causing the method addition to change the static scope
+ # of the shared CompiledCode.
+ it "adds methods respecting the lexical constant scope" do
+ code = "def self.attribute; C; end"
+
+ a = Class.new do
+ self::C = "A"
+ end
+
+ b = Class.new do
+ self::C = "B"
+ end
+
+ a.module_eval(code)
+ b.module_eval(code)
+
+ a.attribute.should == "A"
+ b.attribute.should == "B"
+ end
+
+ it "activates refinements from the eval scope" do
+ refinery = Module.new do
+ refine ModuleSpecs::NamedClass do
+ def foo
+ "bar"
+ end
+ end
+ end
+
+ mid = :module_eval
+ result = nil
+
+ Class.new do
+ using refinery
+
+ result = send(mid, "ModuleSpecs::NamedClass.new.foo")
+ end
+
+ result.should == "bar"
+ end
+
+ it "activates refinements from the eval scope with block" do
+ refinery = Module.new do
+ refine ModuleSpecs::NamedClass do
+ def foo
+ "bar"
+ end
+ end
+ end
+
+ mid = :module_eval
+ result = nil
+
+ Class.new do
+ using refinery
+
+ result = send(mid) do
+ ModuleSpecs::NamedClass.new.foo
+ end
+ end
+
+ result.should == "bar"
+ end
end
diff --git a/spec/ruby/core/module/module_exec_spec.rb b/spec/ruby/core/module/module_exec_spec.rb
index 77d74a083b..6b36e8a02f 100644
--- a/spec/ruby/core/module/module_exec_spec.rb
+++ b/spec/ruby/core/module/module_exec_spec.rb
@@ -1,7 +1,38 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/class_exec', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Module#module_exec" do
- it_behaves_like :module_class_exec, :module_exec
+ it "does not add defined methods to other classes" do
+ FalseClass.module_exec do
+ def foo
+ 'foo'
+ end
+ end
+ -> {42.foo}.should.raise(NoMethodError)
+ end
+
+ it "defines method in the receiver's scope" do
+ ModuleSpecs::Subclass.module_exec { def foo; end }
+ ModuleSpecs::Subclass.new.respond_to?(:foo).should == true
+ end
+
+ it "evaluates a given block in the context of self" do
+ ModuleSpecs::Subclass.module_exec { self }.should == ModuleSpecs::Subclass
+ ModuleSpecs::Subclass.new.module_exec { 1 + 1 }.should == 2
+ end
+
+ it "raises a LocalJumpError when no block is given" do
+ -> { ModuleSpecs::Subclass.module_exec }.should.raise(LocalJumpError)
+ end
+
+ it "passes arguments to the block" do
+ a = ModuleSpecs::Subclass
+ a.module_exec(1) { |b| b }.should.equal?(1)
+ end
+
+ describe "with optional argument" do
+ it "does not destructure a single array argument" do
+ ModuleSpecs::Subclass.module_exec([1, 2, 3]) { |a = 99| a }.should == [1, 2, 3]
+ end
+ end
end
diff --git a/spec/ruby/core/module/module_function_spec.rb b/spec/ruby/core/module/module_function_spec.rb
index 61509c8d03..41bd152608 100644
--- a/spec/ruby/core/module/module_function_spec.rb
+++ b/spec/ruby/core/module/module_function_spec.rb
@@ -1,24 +1,24 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Module#module_function" do
it "is a private method" do
- Module.should have_private_instance_method(:module_function)
+ Module.private_instance_methods(false).should.include?(:module_function)
end
describe "on Class" do
it "is undefined" do
- Class.should_not have_private_instance_method(:module_function, true)
+ Class.private_instance_methods(true).should_not.include?(:module_function)
end
it "raises a TypeError if calling after rebinded to Class" do
- lambda {
+ -> {
Module.instance_method(:module_function).bind(Class.new).call
- }.should raise_error(TypeError)
+ }.should.raise(TypeError)
- lambda {
+ -> {
Module.instance_method(:module_function).bind(Class.new).call :foo
- }.should raise_error(TypeError)
+ }.should.raise(TypeError)
end
end
end
@@ -38,14 +38,12 @@ describe "Module#module_function with specific method names" do
m.respond_to?(:test3).should == false
end
- it "returns the current module" do
- x = nil
- m = Module.new do
- def test() end
- x = module_function :test
+ it "returns argument or arguments if given" do
+ Module.new do
+ def foo; end
+ module_function(:foo).should.equal?(:foo)
+ module_function(:foo, :foo).should == [:foo, :foo]
end
-
- x.should == m
end
it "creates an independent copy of the method, not a redirect" do
@@ -85,9 +83,9 @@ describe "Module#module_function with specific method names" do
(o = mock('x')).extend(m)
o.respond_to?(:test).should == false
- m.should have_private_instance_method(:test)
+ m.private_instance_methods(false).should.include?(:test)
o.send(:test).should == "hello"
- lambda { o.test }.should raise_error(NoMethodError)
+ -> { o.test }.should.raise(NoMethodError)
end
it "makes the new Module methods public" do
@@ -116,17 +114,17 @@ describe "Module#module_function with specific method names" do
it "raises a TypeError when the given names can't be converted to string using to_str" do
o = mock('123')
- lambda { Module.new { module_function(o) } }.should raise_error(TypeError)
+ -> { Module.new { module_function(o) } }.should.raise(TypeError)
o.should_receive(:to_str).and_return(123)
- lambda { Module.new { module_function(o) } }.should raise_error(TypeError)
+ -> { Module.new { module_function(o) } }.should.raise(TypeError)
end
it "can make accessible private methods" do # JRUBY-4214
m = Module.new do
module_function :require
end
- m.respond_to?(:require).should be_true
+ m.respond_to?(:require).should == true
end
it "creates Module methods that super up the singleton class of the module" do
@@ -146,38 +144,82 @@ describe "Module#module_function with specific method names" do
m.foo.should == ["m", "super_m"]
end
+
+ context "methods created with define_method" do
+ context "passed a block" do
+ it "creates duplicates of the given instance methods" do
+ m = Module.new do
+ define_method :test1 do; end
+ module_function :test1
+ end
+
+ m.respond_to?(:test1).should == true
+ end
+ end
+
+ context "passed a method" do
+ it "creates duplicates of the given instance methods" do
+ module_with_method = Module.new do
+ def test1; end
+ end
+
+ c = Class.new do
+ extend module_with_method
+ end
+
+ m = Module.new do
+ define_method :test2, c.method(:test1)
+ module_function :test2
+ end
+
+ m.respond_to?(:test2).should == true
+ end
+ end
+
+ context "passed an unbound method" do
+ it "creates duplicates of the given instance methods" do
+ module_with_method = Module.new do
+ def test1; end
+ end
+
+ m = Module.new do
+ define_method :test2, module_with_method.instance_method(:test1)
+ module_function :test2
+ end
+
+ m.respond_to?(:test2).should == true
+ end
+ end
+ end
end
describe "Module#module_function as a toggle (no arguments) in a Module body" do
it "makes any subsequently defined methods module functions with the normal semantics" do
- m = Module.new {
+ m = Module.new do
module_function
def test1() end
def test2() end
- }
+ end
m.respond_to?(:test1).should == true
m.respond_to?(:test2).should == true
end
- it "returns the current module" do
- x = nil
- m = Module.new {
- x = module_function
- }
-
- x.should == m
+ it "returns nil" do
+ Module.new do
+ module_function.should.equal?(nil)
+ end
end
it "stops creating module functions if the body encounters another toggle " \
"like public/protected/private without arguments" do
- m = Module.new {
+ m = Module.new do
module_function
def test1() end
def test2() end
public
def test3() end
- }
+ end
m.respond_to?(:test1).should == true
m.respond_to?(:test2).should == true
@@ -186,14 +228,14 @@ describe "Module#module_function as a toggle (no arguments) in a Module body" do
it "does not stop creating module functions if the body encounters " \
"public/protected/private WITH arguments" do
- m = Module.new {
+ m = Module.new do
def foo() end
module_function
def test1() end
def test2() end
public :foo
def test3() end
- }
+ end
m.respond_to?(:test1).should == true
m.respond_to?(:test2).should == true
@@ -201,69 +243,116 @@ describe "Module#module_function as a toggle (no arguments) in a Module body" do
end
it "does not affect module_evaled method definitions also if outside the eval itself" do
- m = Module.new {
+ m = Module.new do
module_function
module_eval { def test1() end }
module_eval " def test2() end "
- }
+ end
m.respond_to?(:test1).should == false
m.respond_to?(:test2).should == false
end
it "has no effect if inside a module_eval if the definitions are outside of it" do
- m = Module.new {
+ m = Module.new do
module_eval { module_function }
def test1() end
def test2() end
- }
+ end
m.respond_to?(:test1).should == false
m.respond_to?(:test2).should == false
end
it "functions normally if both toggle and definitions inside a module_eval" do
- m = Module.new {
- module_eval {
+ m = Module.new do
+ module_eval do
module_function
def test1() end
def test2() end
- }
- }
+ end
+ end
m.respond_to?(:test1).should == true
m.respond_to?(:test2).should == true
end
- it "affects evaled method definitions also even when outside the eval itself" do
- m = Module.new {
+ it "affects eval'ed method definitions also even when outside the eval itself" do
+ m = Module.new do
module_function
eval "def test1() end"
- }
+ end
m.respond_to?(:test1).should == true
end
it "doesn't affect definitions when inside an eval even if the definitions are outside of it" do
- m = Module.new {
+ m = Module.new do
eval "module_function"
def test1() end
- }
+ end
m.respond_to?(:test1).should == false
end
it "functions normally if both toggle and definitions inside a eval" do
- m = Module.new {
+ m = Module.new do
eval <<-CODE
module_function
def test1() end
def test2() end
CODE
- }
+ end
m.respond_to?(:test1).should == true
m.respond_to?(:test2).should == true
end
+
+ context "methods are defined with define_method" do
+ context "passed a block" do
+ it "makes any subsequently defined methods module functions with the normal semantics" do
+ m = Module.new do
+ module_function
+ define_method :test1 do; end
+ end
+
+ m.respond_to?(:test1).should == true
+ end
+ end
+
+ context "passed a method" do
+ it "makes any subsequently defined methods module functions with the normal semantics" do
+ module_with_method = Module.new do
+ def test1; end
+ end
+
+ c = Class.new do
+ extend module_with_method
+ end
+
+ m = Module.new do
+ module_function
+ define_method :test2, c.method(:test1)
+ end
+
+ m.respond_to?(:test2).should == true
+ end
+ end
+
+ context "passed an unbound method" do
+ it "makes any subsequently defined methods module functions with the normal semantics" do
+ module_with_method = Module.new do
+ def test1; end
+ end
+
+ m = Module.new do
+ module_function
+ define_method :test2, module_with_method.instance_method(:test1)
+ end
+
+ m.respond_to?(:test2).should == true
+ end
+ end
+ end
end
diff --git a/spec/ruby/core/module/name_spec.rb b/spec/ruby/core/module/name_spec.rb
index 0727278591..332c08d782 100644
--- a/spec/ruby/core/module/name_spec.rb
+++ b/spec/ruby/core/module/name_spec.rb
@@ -1,21 +1,69 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/module', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/module'
describe "Module#name" do
it "is nil for an anonymous module" do
- Module.new.name.should be_nil
+ Module.new.name.should == nil
end
- it "is nil when assigned to a constant in an anonymous module" do
+ it "is not nil when assigned to a constant in an anonymous module" do
m = Module.new
m::N = Module.new
- m::N.name.should be_nil
+ m::N.name.should.end_with? '::N'
end
it "is not nil for a nested module created with the module keyword" do
m = Module.new
module m::N; end
- m::N.name.should =~ /#<Module:0x[0-9a-f]+>::N/
+ m::N.name.should =~ /\A#<Module:0x[0-9a-f]+>::N\z/
+ end
+
+ it "returns nil for a singleton class" do
+ Module.new.singleton_class.name.should == nil
+ String.singleton_class.name.should == nil
+ Object.new.singleton_class.name.should == nil
+ end
+
+ it "changes when the module is reachable through a constant path" do
+ m = Module.new
+ module m::N; end
+ m::N.name.should =~ /\A#<Module:0x\h+>::N\z/
+ ModuleSpecs::Anonymous::WasAnnon = m::N
+ m::N.name.should == "ModuleSpecs::Anonymous::WasAnnon"
+ ensure
+ ModuleSpecs::Anonymous.send(:remove_const, :WasAnnon)
+ end
+
+ it "may be the repeated in different module objects" do
+ m = Module.new
+ n = Module.new
+
+ suppress_warning do
+ ModuleSpecs::Anonymous::SameName = m
+ ModuleSpecs::Anonymous::SameName = n
+ end
+
+ m.name.should == "ModuleSpecs::Anonymous::SameName"
+ n.name.should == "ModuleSpecs::Anonymous::SameName"
+ end
+
+ it "is set after it is removed from a constant" do
+ module ModuleSpecs
+ module ModuleToRemove
+ end
+
+ mod = ModuleToRemove
+ remove_const(:ModuleToRemove)
+ mod.name.should == "ModuleSpecs::ModuleToRemove"
+ end
+ end
+
+ it "is set after it is removed from a constant under an anonymous module" do
+ m = Module.new
+ module m::Child; end
+ child = m::Child
+ m.send(:remove_const, :Child)
+ child.name.should =~ /\A#<Module:0x\h+>::Child\z/
end
it "is set when opened with the module keyword" do
@@ -26,10 +74,20 @@ describe "Module#name" do
ModuleSpecs::Anonymous.name.should == "ModuleSpecs::Anonymous"
end
- it "is set when assigning to a constant" do
+ it "is set when assigning to a constant (constant path matches outer module name)" do
m = Module.new
ModuleSpecs::Anonymous::A = m
m.name.should == "ModuleSpecs::Anonymous::A"
+ ensure
+ ModuleSpecs::Anonymous.send(:remove_const, :A)
+ end
+
+ it "is set when assigning to a constant (constant path does not match outer module name)" do
+ m = Module.new
+ ModuleSpecs::Anonymous::SameChild::A = m
+ m.name.should == "ModuleSpecs::Anonymous::Child::A"
+ ensure
+ ModuleSpecs::Anonymous::SameChild.send(:remove_const, :A)
end
it "is not modified when assigning to a new constant after it has been accessed" do
@@ -38,6 +96,18 @@ describe "Module#name" do
m.name.should == "ModuleSpecs::Anonymous::B"
ModuleSpecs::Anonymous::C = m
m.name.should == "ModuleSpecs::Anonymous::B"
+ ensure
+ ModuleSpecs::Anonymous.send(:remove_const, :B)
+ ModuleSpecs::Anonymous.send(:remove_const, :C)
+ end
+
+ it "is not modified when assigned to a different anonymous module" do
+ m = Module.new
+ module m::M; end
+ first_name = m::M.name.dup
+ module m::N; end
+ m::N::F = m::M
+ m::M.name.should == first_name
end
# http://bugs.ruby-lang.org/issues/6067
@@ -59,10 +129,77 @@ describe "Module#name" do
ModuleSpecs::NameEncoding.new.name.encoding.should == Encoding::UTF_8
end
- it "is set when the anonymous outer module name is set" do
+ it "is set when the anonymous outer module name is set (module in one single constant)" do
m = Module.new
m::N = Module.new
ModuleSpecs::Anonymous::E = m
m::N.name.should == "ModuleSpecs::Anonymous::E::N"
+ ensure
+ ModuleSpecs::Anonymous.send(:remove_const, :E)
+ end
+
+ # https://bugs.ruby-lang.org/issues/19681
+ it "is set when the anonymous outer module name is set (module in several constants)" do
+ m = Module.new
+ m::N = Module.new
+ m::O = m::N
+ ModuleSpecs::Anonymous::StoredInMultiplePlaces = m
+ valid_names = [
+ "ModuleSpecs::Anonymous::StoredInMultiplePlaces::N",
+ "ModuleSpecs::Anonymous::StoredInMultiplePlaces::O"
+ ]
+ valid_names.should.include?(m::N.name) # You get one of the two, but you don't know which one.
+ ensure
+ ModuleSpecs::Anonymous.send(:remove_const, :StoredInMultiplePlaces)
+ end
+
+ it "is set in #const_added callback when a module defined in the top-level scope" do
+ ruby_exe(<<~RUBY, args: "2>&1").chomp.should == "TEST1\nTEST2"
+ class Module
+ def const_added(name)
+ puts const_get(name).name
+ end
+ end
+
+ # module with name
+ module TEST1
+ end
+
+ # anonymous module
+ TEST2 = Module.new
+ RUBY
+ end
+
+ it "is set in #const_added callback for a nested module when an outer module defined in the top-level scope" do
+ ScratchPad.record []
+
+ ModuleSpecs::NameSpecs::NamedModule = Module.new do
+ def self.const_added(name)
+ ScratchPad << const_get(name).name
+ end
+
+ module self::A
+ def self.const_added(name)
+ ScratchPad << const_get(name).name
+ end
+
+ module self::B
+ end
+ end
+ end
+
+ ScratchPad.recorded.should.one?(/#<Module.+>::A$/)
+ ScratchPad.recorded.should.one?(/#<Module.+>::A::B$/)
+ ModuleSpecs::NameSpecs.send :remove_const, :NamedModule
+ end
+
+ it "returns a frozen String" do
+ ModuleSpecs.name.should.frozen?
+ end
+
+ it "always returns the same String for a given Module" do
+ s1 = ModuleSpecs.name
+ s2 = ModuleSpecs.name
+ s1.should.equal?(s2)
end
end
diff --git a/spec/ruby/core/module/nesting_spec.rb b/spec/ruby/core/module/nesting_spec.rb
index 0a86e5b8fc..d0611b3efe 100644
--- a/spec/ruby/core/module/nesting_spec.rb
+++ b/spec/ruby/core/module/nesting_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Module::Nesting" do
diff --git a/spec/ruby/core/module/new_spec.rb b/spec/ruby/core/module/new_spec.rb
index 21d3f954fa..ec7a0cfa77 100644
--- a/spec/ruby/core/module/new_spec.rb
+++ b/spec/ruby/core/module/new_spec.rb
@@ -1,11 +1,15 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Module.new" do
it "creates a new anonymous Module" do
Module.new.is_a?(Module).should == true
end
+ it "creates a module without a name" do
+ Module.new.name.should == nil
+ end
+
it "creates a new Module and passes it to the provided block" do
test_mod = nil
m = Module.new do |mod|
diff --git a/spec/ruby/core/module/prepend_features_spec.rb b/spec/ruby/core/module/prepend_features_spec.rb
index 6f341804d1..3a50f2c2a4 100644
--- a/spec/ruby/core/module/prepend_features_spec.rb
+++ b/spec/ruby/core/module/prepend_features_spec.rb
@@ -1,9 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Module#prepend_features" do
it "is a private method" do
- Module.should have_private_instance_method(:prepend_features, true)
+ Module.private_instance_methods(false).should.include?(:prepend_features)
end
it "gets called when self is included in another module/class" do
@@ -23,21 +23,9 @@ describe "Module#prepend_features" do
end
it "raises an ArgumentError on a cyclic prepend" do
- lambda {
+ -> {
ModuleSpecs::CyclicPrepend.send(:prepend_features, ModuleSpecs::CyclicPrepend)
- }.should raise_error(ArgumentError)
- end
-
- it "copies own tainted status to the given module" do
- other = Module.new
- Module.new.taint.send :prepend_features, other
- other.tainted?.should be_true
- end
-
- it "copies own untrusted status to the given module" do
- other = Module.new
- Module.new.untrust.send :prepend_features, other
- other.untrusted?.should be_true
+ }.should.raise(ArgumentError)
end
it "clears caches of the given module" do
@@ -64,13 +52,13 @@ describe "Module#prepend_features" do
describe "on Class" do
it "is undefined" do
- Class.should_not have_private_instance_method(:prepend_features, true)
+ Class.private_instance_methods(true).should_not.include?(:prepend_features)
end
it "raises a TypeError if calling after rebinded to Class" do
- lambda {
+ -> {
Module.instance_method(:prepend_features).bind(Class.new).call Module.new
- }.should raise_error(TypeError)
+ }.should.raise(TypeError)
end
end
end
diff --git a/spec/ruby/core/module/prepend_spec.rb b/spec/ruby/core/module/prepend_spec.rb
index c0cce616a2..f7887e6d6a 100644
--- a/spec/ruby/core/module/prepend_spec.rb
+++ b/spec/ruby/core/module/prepend_spec.rb
@@ -1,9 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Module#prepend" do
it "is a public method" do
- Module.should have_public_instance_method(:prepend, false)
+ Module.public_instance_methods(false).should.include?(:prepend)
end
it "does not affect the superclass" do
@@ -36,27 +36,450 @@ describe "Module#prepend" do
ScratchPad.recorded.should == [ [ m3, c], [ m2, c ], [ m, c ] ]
end
+ it "updates the method when a module is prepended" do
+ m_module = Module.new do
+ def foo
+ "m"
+ end
+ end
+ a_class = Class.new do
+ def foo
+ 'a'
+ end
+ end
+ a = a_class.new
+ foo = -> { a.foo }
+ foo.call.should == 'a'
+ a_class.class_eval do
+ prepend m_module
+ end
+ foo.call.should == 'm'
+ end
+
+ it "updates the method when a prepended module is updated" do
+ m_module = Module.new
+ a_class = Class.new do
+ prepend m_module
+ def foo
+ 'a'
+ end
+ end
+ a = a_class.new
+ foo = -> { a.foo }
+ foo.call.should == 'a'
+ m_module.module_eval do
+ def foo
+ "m"
+ end
+ end
+ foo.call.should == 'm'
+ end
+
+ it "updates the optimized method when a prepended module is updated" do
+ out = ruby_exe(<<~RUBY)
+ module M; end
+ class Integer
+ prepend M
+ end
+ l = -> { 1 + 2 }
+ p l.call
+ M.module_eval do
+ def +(o)
+ $called = true
+ super(o)
+ end
+ end
+ p l.call
+ p $called
+ RUBY
+ out.should == "3\n3\ntrue\n"
+ end
+
+ it "updates the method when there is a base included method and the prepended module overrides it" do
+ base_module = Module.new do
+ def foo
+ 'a'
+ end
+ end
+ a_class = Class.new do
+ include base_module
+ end
+ a = a_class.new
+ foo = -> { a.foo }
+ foo.call.should == 'a'
+
+ m_module = Module.new do
+ def foo
+ "m"
+ end
+ end
+ a_class.prepend m_module
+ foo.call.should == 'm'
+ end
+
+ it "updates the method when there is a base included method and the prepended module is later updated" do
+ base_module = Module.new do
+ def foo
+ 'a'
+ end
+ end
+ a_class = Class.new do
+ include base_module
+ end
+ a = a_class.new
+ foo = -> { a.foo }
+ foo.call.should == 'a'
+
+ m_module = Module.new
+ a_class.prepend m_module
+ foo.call.should == 'a'
+
+ m_module.module_eval do
+ def foo
+ "m"
+ end
+ end
+ foo.call.should == 'm'
+ end
+
+ it "updates the method when a module prepended after a call is later updated" do
+ m_module = Module.new
+ a_class = Class.new do
+ def foo
+ 'a'
+ end
+ end
+ a = a_class.new
+ foo = -> { a.foo }
+ foo.call.should == 'a'
+
+ a_class.prepend m_module
+ foo.call.should == 'a'
+
+ m_module.module_eval do
+ def foo
+ "m"
+ end
+ end
+ foo.call.should == 'm'
+ end
+
+ it "updates the method when a module is prepended after another and the method is defined later on that module" do
+ m_module = Module.new do
+ def foo
+ 'a'
+ end
+ end
+ a_class = Class.new
+ a_class.prepend m_module
+ a = a_class.new
+ foo = -> { a.foo }
+ foo.call.should == 'a'
+
+ n_module = Module.new
+ a_class.prepend n_module
+ foo.call.should == 'a'
+
+ n_module.module_eval do
+ def foo
+ "n"
+ end
+ end
+ foo.call.should == 'n'
+ end
+
+ it "updates the method when a module is included in a prepended module and the method is defined later" do
+ a_class = Class.new
+ base_module = Module.new do
+ def foo
+ 'a'
+ end
+ end
+ a_class.prepend base_module
+ a = a_class.new
+ foo = -> { a.foo }
+ foo.call.should == 'a'
+
+ m_module = Module.new
+ n_module = Module.new
+ m_module.include n_module
+ a_class.prepend m_module
+
+ n_module.module_eval do
+ def foo
+ "n"
+ end
+ end
+ foo.call.should == 'n'
+ end
+
+ it "updates the method when a new module with an included module is prepended" do
+ a_class = Class.new do
+ def foo
+ 'a'
+ end
+ end
+
+ n_module = Module.new do
+ def foo
+ 'n'
+ end
+ end
+
+ m_module = Module.new do
+ include n_module
+ end
+
+ a = a_class.new
+ foo = -> { a.foo }
+
+ foo.call.should == 'a'
+
+ a_class.class_eval do
+ prepend m_module
+ end
+
+ foo.call.should == 'n'
+ end
+
+ it "updates the constant when a module is prepended" do
+ module ModuleSpecs::ConstUpdatePrepended
+ module M
+ FOO = 'm'
+ end
+ module A
+ FOO = 'a'
+ end
+ module B
+ include A
+ def self.foo
+ FOO
+ end
+ end
+
+ B.foo.should == 'a'
+ B.prepend M
+ B.foo.should == 'm'
+ end
+ ensure
+ ModuleSpecs.send(:remove_const, :ConstUpdatePrepended)
+ end
+
+ it "updates the constant when a prepended module is updated" do
+ module ModuleSpecs::ConstPrependedUpdated
+ module M
+ end
+ module A
+ FOO = 'a'
+ end
+ module B
+ include A
+ prepend M
+ def self.foo
+ FOO
+ end
+ end
+ B.foo.should == 'a'
+ M.const_set(:FOO, 'm')
+ B.foo.should == 'm'
+ end
+ ensure
+ ModuleSpecs.send(:remove_const, :ConstPrependedUpdated)
+ end
+
+ it "updates the constant when there is a base included constant and the prepended module overrides it" do
+ module ModuleSpecs::ConstIncludedPrependedOverride
+ module Base
+ FOO = 'a'
+ end
+ module A
+ include Base
+ def self.foo
+ FOO
+ end
+ end
+ A.foo.should == 'a'
+
+ module M
+ FOO = 'm'
+ end
+ A.prepend M
+ A.foo.should == 'm'
+ end
+ ensure
+ ModuleSpecs.send(:remove_const, :ConstIncludedPrependedOverride)
+ end
+
+ it "updates the constant when there is a base included constant and the prepended module is later updated" do
+ module ModuleSpecs::ConstIncludedPrependedLaterUpdated
+ module Base
+ FOO = 'a'
+ end
+ module A
+ include Base
+ def self.foo
+ FOO
+ end
+ end
+ A.foo.should == 'a'
+
+ module M
+ end
+ A.prepend M
+ A.foo.should == 'a'
+
+ M.const_set(:FOO, 'm')
+ A.foo.should == 'm'
+ end
+ ensure
+ ModuleSpecs.send(:remove_const, :ConstIncludedPrependedLaterUpdated)
+ end
+
+ it "updates the constant when a module prepended after a constant is later updated" do
+ module ModuleSpecs::ConstUpdatedPrependedAfterLaterUpdated
+ module M
+ end
+ module A
+ FOO = 'a'
+ end
+ module B
+ include A
+ def self.foo
+ FOO
+ end
+ end
+ B.foo.should == 'a'
+
+ B.prepend M
+ B.foo.should == 'a'
+
+ M.const_set(:FOO, 'm')
+ B.foo.should == 'm'
+ end
+ ensure
+ ModuleSpecs.send(:remove_const, :ConstUpdatedPrependedAfterLaterUpdated)
+ end
+
+ it "updates the constant when a module is prepended after another and the constant is defined later on that module" do
+ module ModuleSpecs::ConstUpdatedPrependedAfterConstDefined
+ module M
+ FOO = 'm'
+ end
+ module A
+ prepend M
+ def self.foo
+ FOO
+ end
+ end
+
+ A.foo.should == 'm'
+
+ module N
+ end
+ A.prepend N
+ A.foo.should == 'm'
+
+ N.const_set(:FOO, 'n')
+ A.foo.should == 'n'
+ end
+ ensure
+ ModuleSpecs.send(:remove_const, :ConstUpdatedPrependedAfterConstDefined)
+ end
+
+ it "updates the constant when a module is included in a prepended module and the constant is defined later" do
+ module ModuleSpecs::ConstUpdatedIncludedInPrependedConstDefinedLater
+ module A
+ def self.foo
+ FOO
+ end
+ end
+ module Base
+ FOO = 'a'
+ end
+
+ A.prepend Base
+ A.foo.should == 'a'
+
+ module N
+ end
+ module M
+ include N
+ end
+
+ A.prepend M
+
+ N.const_set(:FOO, 'n')
+ A.foo.should == 'n'
+ end
+ ensure
+ ModuleSpecs.send(:remove_const, :ConstUpdatedIncludedInPrependedConstDefinedLater)
+ end
+
+ it "updates the constant when a new module with an included module is prepended" do
+ module ModuleSpecs::ConstUpdatedNewModuleIncludedPrepended
+ module A
+ FOO = 'a'
+ end
+ module B
+ include A
+ def self.foo
+ FOO
+ end
+ end
+ module N
+ FOO = 'n'
+ end
+
+ module M
+ include N
+ end
+
+ B.foo.should == 'a'
+
+ B.prepend M
+ B.foo.should == 'n'
+ end
+ ensure
+ ModuleSpecs.send(:remove_const, :ConstUpdatedNewModuleIncludedPrepended)
+ end
+
it "raises a TypeError when the argument is not a Module" do
- lambda { ModuleSpecs::Basic.prepend(Class.new) }.should raise_error(TypeError)
+ -> { ModuleSpecs::Basic.prepend(Class.new) }.should.raise(TypeError)
end
it "does not raise a TypeError when the argument is an instance of a subclass of Module" do
- lambda { ModuleSpecs::SubclassSpec.prepend(ModuleSpecs::Subclass.new) }.should_not raise_error(TypeError)
+ class ModuleSpecs::SubclassSpec::AClass
+ end
+ -> { ModuleSpecs::SubclassSpec::AClass.prepend(ModuleSpecs::Subclass.new) }.should_not.raise(TypeError)
+ ensure
+ ModuleSpecs::SubclassSpec.send(:remove_const, :AClass)
+ end
+
+ it "raises a TypeError when the argument is a refinement" do
+ refinement = nil
+
+ Module.new do
+ refine String do
+ refinement = self
+ end
+ end
+
+ -> { ModuleSpecs::Basic.prepend(refinement) }.should.raise(TypeError, "Cannot prepend refinement")
end
it "imports constants" do
m1 = Module.new
m1::MY_CONSTANT = 1
m2 = Module.new { prepend(m1) }
- m2.constants.should include(:MY_CONSTANT)
+ m2.constants.should.include?(:MY_CONSTANT)
end
it "imports instance methods" do
- Module.new { prepend ModuleSpecs::A }.instance_methods.should include(:ma)
+ Module.new { prepend ModuleSpecs::A }.instance_methods.should.include?(:ma)
end
it "does not import methods to modules and classes" do
- Module.new { prepend ModuleSpecs::A }.methods.should_not include(:ma)
+ Module.new { prepend ModuleSpecs::A }.methods.should_not.include?(:ma)
end
it "allows wrapping methods" do
@@ -82,7 +505,7 @@ describe "Module#prepend" do
it "includes prepended modules in ancestors" do
m = Module.new
- Class.new { prepend(m) }.ancestors.should include(m)
+ Class.new { prepend(m) }.ancestors.should.include?(m)
end
it "reports the prepended module as the method owner" do
@@ -104,34 +527,46 @@ describe "Module#prepend" do
c.new.alias.should == :m
end
+ it "reports the class for the owner of an aliased method on the class" do
+ m = Module.new
+ c = Class.new { prepend(m); def meth; :c end; alias_method :alias, :meth }
+ c.instance_method(:alias).owner.should == c
+ end
+
+ it "reports the class for the owner of a method aliased from the prepended module" do
+ m = Module.new { def meth; :m end }
+ c = Class.new { prepend(m); alias_method :alias, :meth }
+ c.instance_method(:alias).owner.should == c
+ end
+
it "sees an instance of a prepended class as kind of the prepended module" do
m = Module.new
c = Class.new { prepend(m) }
- c.new.should be_kind_of(m)
+ c.new.should.is_a?(m)
end
it "keeps the module in the chain when dupping the class" do
m = Module.new
c = Class.new { prepend(m) }
- c.dup.new.should be_kind_of(m)
+ c.dup.new.should.is_a?(m)
end
- it "keeps the module in the chain when dupping an intermediate module" do
+ it "uses only new module when dupping the module" do
m1 = Module.new { def calc(x) x end }
m2 = Module.new { prepend(m1) }
c1 = Class.new { prepend(m2) }
m2dup = m2.dup
- m2dup.ancestors.should == [m2dup,m1,m2]
+ m2dup.ancestors.should == [m1,m2dup]
c2 = Class.new { prepend(m2dup) }
c1.ancestors[0,3].should == [m1,m2,c1]
- c1.new.should be_kind_of(m1)
- c2.ancestors[0,4].should == [m2dup,m1,m2,c2]
- c2.new.should be_kind_of(m1)
+ c1.new.should.is_a?(m1)
+ c2.ancestors[0,3].should == [m1,m2dup,c2]
+ c2.new.should.is_a?(m1)
end
it "depends on prepend_features to add the module" do
m = Module.new { def self.prepend_features(mod) end }
- Class.new { prepend(m) }.ancestors.should_not include(m)
+ Class.new { prepend(m) }.ancestors.should_not.include?(m)
end
it "adds the module in the subclass chains" do
@@ -192,7 +627,7 @@ describe "Module#prepend" do
super << :class
end
end
- lambda { c.new.chain }.should raise_error(NoMethodError)
+ -> { c.new.chain }.should.raise(NoMethodError)
end
it "calls prepended after prepend_features" do
@@ -211,32 +646,32 @@ describe "Module#prepend" do
ScratchPad.recorded.should == [[:prepend_features, c], [:prepended, c]]
end
+ it "prepends a module if it is included in a super class" do
+ module ModuleSpecs::M3
+ module M; end
+ class A; include M; end
+ class B < A; prepend M; end
+
+ all = [A, B, M]
+
+ (B.ancestors.filter { |a| all.include?(a) }).should == [M, B, A, M]
+ end
+ end
+
it "detects cyclic prepends" do
- lambda {
+ -> {
module ModuleSpecs::P
prepend ModuleSpecs::P
end
- }.should raise_error(ArgumentError)
- end
-
- ruby_version_is ''...'2.4' do
- it "accepts no-arguments" do
- lambda {
- Module.new do
- prepend
- end
- }.should_not raise_error
- end
+ }.should.raise(ArgumentError)
end
- ruby_version_is '2.4' do
- it "doesn't accept no-arguments" do
- lambda {
- Module.new do
- prepend
- end
- }.should raise_error(ArgumentError)
- end
+ it "doesn't accept no-arguments" do
+ -> {
+ Module.new do
+ prepend
+ end
+ }.should.raise(ArgumentError)
end
it "returns the class it's included into" do
@@ -343,6 +778,33 @@ describe "Module#prepend" do
ary.should == [3, 2, 1]
end
+ it "does not prepend a second copy if the module already indirectly exists in the hierarchy" do
+ mod = Module.new do; end
+ submod = Module.new do; end
+ klass = Class.new do; end
+ klass.include(mod)
+ mod.prepend(submod)
+ klass.include(mod)
+
+ klass.ancestors.take(4).should == [klass, submod, mod, Object]
+ end
+
+ # https://bugs.ruby-lang.org/issues/17423
+ describe "when module already exists in ancestor chain" do
+ it "modifies the ancestor chain" do
+ m = Module.new do; end
+ a = Module.new do; end
+ b = Class.new do; end
+
+ b.include(a)
+ a.prepend(m)
+ b.ancestors.take(4).should == [b, m, a, Object]
+
+ b.prepend(m)
+ b.ancestors.take(5).should == [m, b, m, a, Object]
+ end
+ end
+
describe "called on a module" do
describe "included into a class"
it "does not obscure the module's methods from reflective access" do
@@ -355,7 +817,7 @@ describe "Module#prepend" do
pre = Module.new
mod.prepend pre
- cls.instance_methods.should include(:foo)
+ cls.instance_methods.should.include?(:foo)
end
end
end
diff --git a/spec/ruby/core/module/prepended_spec.rb b/spec/ruby/core/module/prepended_spec.rb
index ed8e473941..ccd450d668 100644
--- a/spec/ruby/core/module/prepended_spec.rb
+++ b/spec/ruby/core/module/prepended_spec.rb
@@ -1,6 +1,6 @@
# -*- encoding: us-ascii -*-
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Module#prepended" do
before :each do
@@ -8,7 +8,7 @@ describe "Module#prepended" do
end
it "is a private method" do
- Module.should have_private_instance_method(:prepended, true)
+ Module.private_instance_methods(false).should.include?(:prepended)
end
it "is invoked when self is prepended to another module or class" do
diff --git a/spec/ruby/core/module/private_class_method_spec.rb b/spec/ruby/core/module/private_class_method_spec.rb
index ec10bcbf87..7ce07f1600 100644
--- a/spec/ruby/core/module/private_class_method_spec.rb
+++ b/spec/ruby/core/module/private_class_method_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Module#private_class_method" do
before :each do
@@ -22,11 +22,11 @@ describe "Module#private_class_method" do
it "makes an existing class method private" do
ModuleSpecs::Parent.private_method_1.should == nil
ModuleSpecs::Parent.private_class_method :private_method_1
- lambda { ModuleSpecs::Parent.private_method_1 }.should raise_error(NoMethodError)
+ -> { ModuleSpecs::Parent.private_method_1 }.should.raise(NoMethodError)
# Technically above we're testing the Singleton classes, class method(right?).
# Try a "real" class method set private.
- lambda { ModuleSpecs::Parent.private_method }.should raise_error(NoMethodError)
+ -> { ModuleSpecs::Parent.private_method }.should.raise(NoMethodError)
end
it "makes an existing class method private up the inheritance tree" do
@@ -34,8 +34,8 @@ describe "Module#private_class_method" do
ModuleSpecs::Child.private_method_1.should == nil
ModuleSpecs::Child.private_class_method :private_method_1
- lambda { ModuleSpecs::Child.private_method_1 }.should raise_error(NoMethodError)
- lambda { ModuleSpecs::Child.private_method }.should raise_error(NoMethodError)
+ -> { ModuleSpecs::Child.private_method_1 }.should.raise(NoMethodError)
+ -> { ModuleSpecs::Child.private_method }.should.raise(NoMethodError)
end
it "accepts more than one method at a time" do
@@ -44,14 +44,14 @@ describe "Module#private_class_method" do
ModuleSpecs::Child.private_class_method :private_method_1, :private_method_2
- lambda { ModuleSpecs::Child.private_method_1 }.should raise_error(NoMethodError)
- lambda { ModuleSpecs::Child.private_method_2 }.should raise_error(NoMethodError)
+ -> { ModuleSpecs::Child.private_method_1 }.should.raise(NoMethodError)
+ -> { ModuleSpecs::Child.private_method_2 }.should.raise(NoMethodError)
end
it "raises a NameError if class method doesn't exist" do
- lambda do
+ -> do
ModuleSpecs.private_class_method :no_method_here
- end.should raise_error(NameError)
+ end.should.raise(NameError)
end
it "makes a class method private" do
@@ -59,23 +59,33 @@ describe "Module#private_class_method" do
def self.foo() "foo" end
private_class_method :foo
end
- lambda { c.foo }.should raise_error(NoMethodError)
+ -> { c.foo }.should.raise(NoMethodError)
end
it "raises a NameError when the given name is not a method" do
- lambda do
+ -> do
Class.new do
private_class_method :foo
end
- end.should raise_error(NameError)
+ end.should.raise(NameError)
end
it "raises a NameError when the given name is an instance method" do
- lambda do
+ -> do
Class.new do
def foo() "foo" end
private_class_method :foo
end
- end.should raise_error(NameError)
+ end.should.raise(NameError)
+ end
+
+ context "when single argument is passed and is an array" do
+ it "sets the visibility of the given methods to private" do
+ c = Class.new do
+ def self.foo() "foo" end
+ private_class_method [:foo]
+ end
+ -> { c.foo }.should.raise(NoMethodError)
+ end
end
end
diff --git a/spec/ruby/core/module/private_constant_spec.rb b/spec/ruby/core/module/private_constant_spec.rb
index af0b1facdd..ca0df48c0b 100644
--- a/spec/ruby/core/module/private_constant_spec.rb
+++ b/spec/ruby/core/module/private_constant_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Module#private_constant" do
it "can only be passed constant names defined in the target (self) module" do
@@ -6,9 +6,9 @@ describe "Module#private_constant" do
cls1.const_set :Foo, true
cls2 = Class.new(cls1)
- lambda do
+ -> do
cls2.send :private_constant, :Foo
- end.should raise_error(NameError)
+ end.should.raise(NameError)
end
it "accepts strings as constant names" do
@@ -16,7 +16,7 @@ describe "Module#private_constant" do
cls.const_set :Foo, true
cls.send :private_constant, "Foo"
- lambda { cls::Foo }.should raise_error(NameError)
+ -> { cls::Foo }.should.raise(NameError)
end
it "accepts multiple names" do
@@ -26,7 +26,7 @@ describe "Module#private_constant" do
mod.send :private_constant, :Foo, :Bar
- lambda {mod::Foo}.should raise_error(NameError)
- lambda {mod::Bar}.should raise_error(NameError)
+ -> {mod::Foo}.should.raise(NameError)
+ -> {mod::Bar}.should.raise(NameError)
end
end
diff --git a/spec/ruby/core/module/private_instance_methods_spec.rb b/spec/ruby/core/module/private_instance_methods_spec.rb
index f5c4c3a0f9..ae0f21d1dd 100644
--- a/spec/ruby/core/module/private_instance_methods_spec.rb
+++ b/spec/ruby/core/module/private_instance_methods_spec.rb
@@ -1,24 +1,24 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../../../fixtures/reflection', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative '../../fixtures/reflection'
# TODO: rewrite
describe "Module#private_instance_methods" do
it "returns a list of private methods in module and its ancestors" do
- ModuleSpecs::CountsMixin.should have_private_instance_method(:private_3)
+ ModuleSpecs::CountsMixin.private_instance_methods(false).should.include?(:private_3)
- ModuleSpecs::CountsParent.should have_private_instance_method(:private_2)
- ModuleSpecs::CountsParent.should have_private_instance_method(:private_3)
+ ModuleSpecs::CountsParent.private_instance_methods(false).should.include?(:private_2)
+ ModuleSpecs::CountsParent.private_instance_methods(true).should.include?(:private_3)
- ModuleSpecs::CountsChild.should have_private_instance_method(:private_1)
- ModuleSpecs::CountsChild.should have_private_instance_method(:private_2)
- ModuleSpecs::CountsChild.should have_private_instance_method(:private_3)
+ ModuleSpecs::CountsChild.private_instance_methods(false).should.include?(:private_1)
+ ModuleSpecs::CountsChild.private_instance_methods(true).should.include?(:private_2)
+ ModuleSpecs::CountsChild.private_instance_methods(true).should.include?(:private_3)
end
it "when passed false as a parameter, should return only methods defined in that module" do
- ModuleSpecs::CountsMixin.should have_private_instance_method(:private_3, false)
- ModuleSpecs::CountsParent.should have_private_instance_method(:private_2, false)
- ModuleSpecs::CountsChild.should have_private_instance_method(:private_1, false)
+ ModuleSpecs::CountsMixin.private_instance_methods(false).should.include?(:private_3)
+ ModuleSpecs::CountsParent.private_instance_methods(false).should.include?(:private_2)
+ ModuleSpecs::CountsChild.private_instance_methods(false).should.include?(:private_1)
end
it "default list should be the same as passing true as an argument" do
diff --git a/spec/ruby/core/module/private_method_defined_spec.rb b/spec/ruby/core/module/private_method_defined_spec.rb
index b3e1814056..f730decc0a 100644
--- a/spec/ruby/core/module/private_method_defined_spec.rb
+++ b/spec/ruby/core/module/private_method_defined_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Module#private_method_defined?" do
it "returns true if the named private method is defined by module or its ancestors" do
@@ -31,37 +31,37 @@ describe "Module#private_method_defined?" do
ModuleSpecs::CountsMixin.private_method_defined?(:private_3).should == true
end
- it "raises a TypeError if passed a Fixnum" do
- lambda do
+ it "raises a TypeError if passed an Integer" do
+ -> do
ModuleSpecs::CountsMixin.private_method_defined?(1)
- end.should raise_error(TypeError)
+ end.should.raise(TypeError)
end
it "raises a TypeError if passed nil" do
- lambda do
+ -> do
ModuleSpecs::CountsMixin.private_method_defined?(nil)
- end.should raise_error(TypeError)
+ end.should.raise(TypeError)
end
it "raises a TypeError if passed false" do
- lambda do
+ -> do
ModuleSpecs::CountsMixin.private_method_defined?(false)
- end.should raise_error(TypeError)
+ end.should.raise(TypeError)
end
it "raises a TypeError if passed an object that does not defined #to_str" do
- lambda do
+ -> do
ModuleSpecs::CountsMixin.private_method_defined?(mock('x'))
- end.should raise_error(TypeError)
+ end.should.raise(TypeError)
end
it "raises a TypeError if passed an object that defines #to_sym" do
sym = mock('symbol')
def sym.to_sym() :private_3 end
- lambda do
+ -> do
ModuleSpecs::CountsMixin.private_method_defined?(sym)
- end.should raise_error(TypeError)
+ end.should.raise(TypeError)
end
it "calls #to_str to convert an Object" do
@@ -69,4 +69,52 @@ describe "Module#private_method_defined?" do
def str.to_str() 'private_3' end
ModuleSpecs::CountsMixin.private_method_defined?(str).should == true
end
+
+ describe "when passed true as a second optional argument" do
+ it "performs a lookup in ancestors" do
+ ModuleSpecs::Child.private_method_defined?(:public_child, true).should == false
+ ModuleSpecs::Child.private_method_defined?(:protected_child, true).should == false
+ ModuleSpecs::Child.private_method_defined?(:accessor_method, true).should == false
+ ModuleSpecs::Child.private_method_defined?(:private_child, true).should == true
+
+ # Defined in Parent
+ ModuleSpecs::Child.private_method_defined?(:public_parent, true).should == false
+ ModuleSpecs::Child.private_method_defined?(:protected_parent, true).should == false
+ ModuleSpecs::Child.private_method_defined?(:private_parent, true).should == true
+
+ # Defined in Module
+ ModuleSpecs::Child.private_method_defined?(:public_module, true).should == false
+ ModuleSpecs::Child.private_method_defined?(:protected_module, true).should == false
+ ModuleSpecs::Child.private_method_defined?(:private_module, true).should == true
+
+ # Defined in SuperModule
+ ModuleSpecs::Child.private_method_defined?(:public_super_module, true).should == false
+ ModuleSpecs::Child.private_method_defined?(:protected_super_module, true).should == false
+ ModuleSpecs::Child.private_method_defined?(:private_super_module, true).should == true
+ end
+ end
+
+ describe "when passed false as a second optional argument" do
+ it "checks only the class itself" do
+ ModuleSpecs::Child.private_method_defined?(:public_child, false).should == false
+ ModuleSpecs::Child.private_method_defined?(:protected_child, false).should == false
+ ModuleSpecs::Child.private_method_defined?(:accessor_method, false).should == false
+ ModuleSpecs::Child.private_method_defined?(:private_child, false).should == true
+
+ # Defined in Parent
+ ModuleSpecs::Child.private_method_defined?(:public_parent, false).should == false
+ ModuleSpecs::Child.private_method_defined?(:protected_parent, false).should == false
+ ModuleSpecs::Child.private_method_defined?(:private_parent, false).should == false
+
+ # Defined in Module
+ ModuleSpecs::Child.private_method_defined?(:public_module, false).should == false
+ ModuleSpecs::Child.private_method_defined?(:protected_module, false).should == false
+ ModuleSpecs::Child.private_method_defined?(:private_module, false).should == false
+
+ # Defined in SuperModule
+ ModuleSpecs::Child.private_method_defined?(:public_super_module, false).should == false
+ ModuleSpecs::Child.private_method_defined?(:protected_super_module, false).should == false
+ ModuleSpecs::Child.private_method_defined?(:private_super_module, false).should == false
+ end
+ end
end
diff --git a/spec/ruby/core/module/private_spec.rb b/spec/ruby/core/module/private_spec.rb
index bfdb5016c2..e60fdb24cc 100644
--- a/spec/ruby/core/module/private_spec.rb
+++ b/spec/ruby/core/module/private_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/set_visibility', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/set_visibility'
describe "Module#private" do
it_behaves_like :set_visibility, :private
@@ -17,7 +17,7 @@ describe "Module#private" do
private :foo
end
- lambda { obj.foo }.should raise_error(NoMethodError)
+ -> { obj.foo }.should.raise(NoMethodError)
end
it "makes a public Object instance method private in a new module" do
@@ -25,30 +25,71 @@ describe "Module#private" do
private :module_specs_public_method_on_object
end
- m.should have_private_instance_method(:module_specs_public_method_on_object)
+ m.private_instance_methods(false).should.include?(:module_specs_public_method_on_object)
# Ensure we did not change Object's method
- Object.should_not have_private_instance_method(:module_specs_public_method_on_object)
+ Object.private_instance_methods(true).should_not.include?(:module_specs_public_method_on_object)
end
it "makes a public Object instance method private in Kernel" do
- Kernel.should have_private_instance_method(
+ Kernel.private_instance_methods(false).should.include?(
:module_specs_public_method_on_object_for_kernel_private)
- Object.should_not have_private_instance_method(
+ Object.private_instance_methods(true).should_not.include?(
:module_specs_public_method_on_object_for_kernel_private)
end
- it "returns self" do
+ it "returns argument or arguments if given" do
(class << Object.new; self; end).class_eval do
def foo; end
- private(:foo).should equal(self)
- private.should equal(self)
+ private(:foo).should.equal?(:foo)
+ private([:foo, :foo]).should == [:foo, :foo]
+ private(:foo, :foo).should == [:foo, :foo]
+ private.should.equal?(nil)
end
end
it "raises a NameError when given an undefined name" do
- lambda do
+ -> do
Module.new.send(:private, :undefined)
- end.should raise_error(NameError)
+ end.should.raise(NameError)
+ end
+
+ it "only makes the method private in the class it is called on" do
+ base = Class.new do
+ def wrapped
+ 1
+ end
+ end
+
+ klass = Class.new(base) do
+ def wrapped
+ super + 1
+ end
+ private :wrapped
+ end
+
+ base.new.wrapped.should == 1
+ -> do
+ klass.new.wrapped
+ end.should.raise(NameError)
+ end
+
+ it "continues to allow a prepended module method to call super" do
+ wrapper = Module.new do
+ def wrapped
+ super + 1
+ end
+ end
+
+ klass = Class.new do
+ prepend wrapper
+
+ def wrapped
+ 1
+ end
+ private :wrapped
+ end
+
+ klass.new.wrapped.should == 2
end
end
diff --git a/spec/ruby/core/module/protected_instance_methods_spec.rb b/spec/ruby/core/module/protected_instance_methods_spec.rb
index d5c9e5cd33..ea7ded030e 100644
--- a/spec/ruby/core/module/protected_instance_methods_spec.rb
+++ b/spec/ruby/core/module/protected_instance_methods_spec.rb
@@ -1,21 +1,21 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../../../fixtures/reflection', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative '../../fixtures/reflection'
# TODO: rewrite
describe "Module#protected_instance_methods" do
it "returns a list of protected methods in module and its ancestors" do
methods = ModuleSpecs::CountsMixin.protected_instance_methods
- methods.should include(:protected_3)
+ methods.should.include?(:protected_3)
methods = ModuleSpecs::CountsParent.protected_instance_methods
- methods.should include(:protected_3)
- methods.should include(:protected_2)
+ methods.should.include?(:protected_3)
+ methods.should.include?(:protected_2)
methods = ModuleSpecs::CountsChild.protected_instance_methods
- methods.should include(:protected_3)
- methods.should include(:protected_2)
- methods.should include(:protected_1)
+ methods.should.include?(:protected_3)
+ methods.should.include?(:protected_2)
+ methods.should.include?(:protected_1)
end
it "when passed false as a parameter, should return only methods defined in that module" do
diff --git a/spec/ruby/core/module/protected_method_defined_spec.rb b/spec/ruby/core/module/protected_method_defined_spec.rb
index af08efae81..78ba120c2f 100644
--- a/spec/ruby/core/module/protected_method_defined_spec.rb
+++ b/spec/ruby/core/module/protected_method_defined_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Module#protected_method_defined?" do
it "returns true if the named protected method is defined by module or its ancestors" do
@@ -31,37 +31,37 @@ describe "Module#protected_method_defined?" do
ModuleSpecs::CountsMixin.protected_method_defined?(:protected_3).should == true
end
- it "raises a TypeError if passed a Fixnum" do
- lambda do
+ it "raises a TypeError if passed an Integer" do
+ -> do
ModuleSpecs::CountsMixin.protected_method_defined?(1)
- end.should raise_error(TypeError)
+ end.should.raise(TypeError)
end
it "raises a TypeError if passed nil" do
- lambda do
+ -> do
ModuleSpecs::CountsMixin.protected_method_defined?(nil)
- end.should raise_error(TypeError)
+ end.should.raise(TypeError)
end
it "raises a TypeError if passed false" do
- lambda do
+ -> do
ModuleSpecs::CountsMixin.protected_method_defined?(false)
- end.should raise_error(TypeError)
+ end.should.raise(TypeError)
end
it "raises a TypeError if passed an object that does not defined #to_str" do
- lambda do
+ -> do
ModuleSpecs::CountsMixin.protected_method_defined?(mock('x'))
- end.should raise_error(TypeError)
+ end.should.raise(TypeError)
end
it "raises a TypeError if passed an object that defines #to_sym" do
sym = mock('symbol')
def sym.to_sym() :protected_3 end
- lambda do
+ -> do
ModuleSpecs::CountsMixin.protected_method_defined?(sym)
- end.should raise_error(TypeError)
+ end.should.raise(TypeError)
end
it "calls #to_str to convert an Object" do
@@ -69,4 +69,52 @@ describe "Module#protected_method_defined?" do
str.should_receive(:to_str).and_return("protected_3")
ModuleSpecs::CountsMixin.protected_method_defined?(str).should == true
end
+
+ describe "when passed true as a second optional argument" do
+ it "performs a lookup in ancestors" do
+ ModuleSpecs::Child.protected_method_defined?(:public_child, true).should == false
+ ModuleSpecs::Child.protected_method_defined?(:protected_child, true).should == true
+ ModuleSpecs::Child.protected_method_defined?(:accessor_method, true).should == false
+ ModuleSpecs::Child.protected_method_defined?(:private_child, true).should == false
+
+ # Defined in Parent
+ ModuleSpecs::Child.protected_method_defined?(:public_parent, true).should == false
+ ModuleSpecs::Child.protected_method_defined?(:protected_parent, true).should == true
+ ModuleSpecs::Child.protected_method_defined?(:private_parent, true).should == false
+
+ # Defined in Module
+ ModuleSpecs::Child.protected_method_defined?(:public_module, true).should == false
+ ModuleSpecs::Child.protected_method_defined?(:protected_module, true).should == true
+ ModuleSpecs::Child.protected_method_defined?(:private_module, true).should == false
+
+ # Defined in SuperModule
+ ModuleSpecs::Child.protected_method_defined?(:public_super_module, true).should == false
+ ModuleSpecs::Child.protected_method_defined?(:protected_super_module, true).should == true
+ ModuleSpecs::Child.protected_method_defined?(:private_super_module, true).should == false
+ end
+ end
+
+ describe "when passed false as a second optional argument" do
+ it "checks only the class itself" do
+ ModuleSpecs::Child.protected_method_defined?(:public_child, false).should == false
+ ModuleSpecs::Child.protected_method_defined?(:protected_child, false).should == true
+ ModuleSpecs::Child.protected_method_defined?(:accessor_method, false).should == false
+ ModuleSpecs::Child.protected_method_defined?(:private_child, false).should == false
+
+ # Defined in Parent
+ ModuleSpecs::Child.protected_method_defined?(:public_parent, false).should == false
+ ModuleSpecs::Child.protected_method_defined?(:protected_parent, false).should == false
+ ModuleSpecs::Child.protected_method_defined?(:private_parent, false).should == false
+
+ # Defined in Module
+ ModuleSpecs::Child.protected_method_defined?(:public_module, false).should == false
+ ModuleSpecs::Child.protected_method_defined?(:protected_module, false).should == false
+ ModuleSpecs::Child.protected_method_defined?(:private_module, false).should == false
+
+ # Defined in SuperModule
+ ModuleSpecs::Child.protected_method_defined?(:public_super_module, false).should == false
+ ModuleSpecs::Child.protected_method_defined?(:protected_super_module, false).should == false
+ ModuleSpecs::Child.protected_method_defined?(:private_super_module, false).should == false
+ end
+ end
end
diff --git a/spec/ruby/core/module/protected_spec.rb b/spec/ruby/core/module/protected_spec.rb
index 7e77138c12..3ef6c76fae 100644
--- a/spec/ruby/core/module/protected_spec.rb
+++ b/spec/ruby/core/module/protected_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/set_visibility', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/set_visibility'
describe "Module#protected" do
before :each do
@@ -18,7 +18,7 @@ describe "Module#protected" do
protected :protected_method_1
end
- lambda { ModuleSpecs::Parent.protected_method_1 }.should raise_error(NoMethodError)
+ -> { ModuleSpecs::Parent.protected_method_1 }.should.raise(NoMethodError)
end
it "makes a public Object instance method protected in a new module" do
@@ -26,31 +26,32 @@ describe "Module#protected" do
protected :module_specs_public_method_on_object
end
- m.should have_protected_instance_method(:module_specs_public_method_on_object)
+ m.protected_instance_methods(false).should.include?(:module_specs_public_method_on_object)
# Ensure we did not change Object's method
- Object.should_not have_protected_instance_method(:module_specs_public_method_on_object)
+ Object.protected_instance_methods(true).should_not.include?(:module_specs_public_method_on_object)
end
it "makes a public Object instance method protected in Kernel" do
- Kernel.should have_protected_instance_method(
+ Kernel.protected_instance_methods(false).should.include?(
:module_specs_public_method_on_object_for_kernel_protected)
- Object.should_not have_protected_instance_method(
+ Object.protected_instance_methods(true).should_not.include?(
:module_specs_public_method_on_object_for_kernel_protected)
end
- it "returns self" do
+ it "returns argument or arguments if given" do
(class << Object.new; self; end).class_eval do
def foo; end
- protected(:foo).should equal(self)
- protected.should equal(self)
+ protected(:foo).should.equal?(:foo)
+ protected([:foo, :foo]).should == [:foo, :foo]
+ protected(:foo, :foo).should == [:foo, :foo]
+ protected.should.equal?(nil)
end
end
it "raises a NameError when given an undefined name" do
- lambda do
+ -> do
Module.new.send(:protected, :undefined)
- end.should raise_error(NameError)
+ end.should.raise(NameError)
end
end
-
diff --git a/spec/ruby/core/module/public_class_method_spec.rb b/spec/ruby/core/module/public_class_method_spec.rb
index 2c909b1223..4aca4d4311 100644
--- a/spec/ruby/core/module/public_class_method_spec.rb
+++ b/spec/ruby/core/module/public_class_method_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Module#public_class_method" do
before :each do
@@ -18,7 +18,7 @@ describe "Module#public_class_method" do
end
it "makes an existing class method public" do
- lambda { ModuleSpecs::Parent.public_method_1 }.should raise_error(NoMethodError)
+ -> { ModuleSpecs::Parent.public_method_1 }.should.raise(NoMethodError)
ModuleSpecs::Parent.public_class_method :public_method_1
ModuleSpecs::Parent.public_method_1.should == nil
@@ -29,7 +29,7 @@ describe "Module#public_class_method" do
it "makes an existing class method public up the inheritance tree" do
ModuleSpecs::Child.private_class_method :public_method_1
- lambda { ModuleSpecs::Child.public_method_1 }.should raise_error(NoMethodError)
+ -> { ModuleSpecs::Child.public_method_1 }.should.raise(NoMethodError)
ModuleSpecs::Child.public_class_method :public_method_1
ModuleSpecs::Child.public_method_1.should == nil
@@ -37,8 +37,8 @@ describe "Module#public_class_method" do
end
it "accepts more than one method at a time" do
- lambda { ModuleSpecs::Parent.public_method_1 }.should raise_error(NameError)
- lambda { ModuleSpecs::Parent.public_method_2 }.should raise_error(NameError)
+ -> { ModuleSpecs::Parent.public_method_1 }.should.raise(NameError)
+ -> { ModuleSpecs::Parent.public_method_2 }.should.raise(NameError)
ModuleSpecs::Child.public_class_method :public_method_1, :public_method_2
@@ -47,9 +47,9 @@ describe "Module#public_class_method" do
end
it "raises a NameError if class method doesn't exist" do
- lambda do
+ -> do
ModuleSpecs.public_class_method :no_method_here
- end.should raise_error(NameError)
+ end.should.raise(NameError)
end
it "makes a class method public" do
@@ -62,19 +62,33 @@ describe "Module#public_class_method" do
end
it "raises a NameError when the given name is not a method" do
- lambda do
+ -> do
Class.new do
public_class_method :foo
end
- end.should raise_error(NameError)
+ end.should.raise(NameError)
end
it "raises a NameError when the given name is an instance method" do
- lambda do
+ -> do
Class.new do
def foo() "foo" end
public_class_method :foo
end
- end.should raise_error(NameError)
+ end.should.raise(NameError)
+ end
+
+ context "when single argument is passed and is an array" do
+ it "makes a class method public" do
+ c = Class.new do
+ class << self
+ private
+ def foo() "foo" end
+ end
+ public_class_method [:foo]
+ end
+
+ c.foo.should == "foo"
+ end
end
end
diff --git a/spec/ruby/core/module/public_constant_spec.rb b/spec/ruby/core/module/public_constant_spec.rb
index cbf51a6df6..87a051f125 100644
--- a/spec/ruby/core/module/public_constant_spec.rb
+++ b/spec/ruby/core/module/public_constant_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Module#public_constant" do
it "can only be passed constant names defined in the target (self) module" do
@@ -6,9 +6,9 @@ describe "Module#public_constant" do
cls1.const_set :Foo, true
cls2 = Class.new(cls1)
- lambda do
+ -> do
cls2.send :public_constant, :Foo
- end.should raise_error(NameError)
+ end.should.raise(NameError)
end
it "accepts strings as constant names" do
diff --git a/spec/ruby/core/module/public_instance_method_spec.rb b/spec/ruby/core/module/public_instance_method_spec.rb
index c1e94c5fed..87c1bae599 100644
--- a/spec/ruby/core/module/public_instance_method_spec.rb
+++ b/spec/ruby/core/module/public_instance_method_spec.rb
@@ -1,9 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Module#public_instance_method" do
it "is a public method" do
- Module.should have_public_instance_method(:public_instance_method, false)
+ Module.public_instance_methods(false).should.include?(:public_instance_method)
end
it "requires an argument" do
@@ -13,12 +13,12 @@ describe "Module#public_instance_method" do
describe "when given a public method name" do
it "returns an UnboundMethod corresponding to the defined Module" do
ret = ModuleSpecs::Super.public_instance_method(:public_module)
- ret.should be_an_instance_of(UnboundMethod)
- ret.owner.should equal(ModuleSpecs::Basic)
+ ret.should.instance_of?(UnboundMethod)
+ ret.owner.should.equal?(ModuleSpecs::Basic)
ret = ModuleSpecs::Super.public_instance_method(:public_super_module)
- ret.should be_an_instance_of(UnboundMethod)
- ret.owner.should equal(ModuleSpecs::Super)
+ ret.should.instance_of?(UnboundMethod)
+ ret.owner.should.equal?(ModuleSpecs::Super)
end
it "accepts if the name is a Symbol or String" do
@@ -28,31 +28,31 @@ describe "Module#public_instance_method" do
end
it "raises a TypeError when given a name is not Symbol or String" do
- lambda { Module.new.public_instance_method(nil) }.should raise_error(TypeError)
+ -> { Module.new.public_instance_method(nil) }.should.raise(TypeError)
end
it "raises a NameError when given a protected method name" do
- lambda do
+ -> do
ModuleSpecs::Basic.public_instance_method(:protected_module)
- end.should raise_error(NameError)
+ end.should.raise(NameError)
end
it "raises a NameError if the method is private" do
- lambda do
+ -> do
ModuleSpecs::Basic.public_instance_method(:private_module)
- end.should raise_error(NameError)
+ end.should.raise(NameError)
end
it "raises a NameError if the method has been undefined" do
- lambda do
+ -> do
ModuleSpecs::Parent.public_instance_method(:undefed_method)
- end.should raise_error(NameError)
+ end.should.raise(NameError)
end
it "raises a NameError if the method does not exist" do
- lambda do
+ -> do
Module.new.public_instance_method(:missing)
- end.should raise_error(NameError)
+ end.should.raise(NameError)
end
it "sets the NameError#name attribute to the name of the missing method" do
diff --git a/spec/ruby/core/module/public_instance_methods_spec.rb b/spec/ruby/core/module/public_instance_methods_spec.rb
index 14453109c3..edea00d927 100644
--- a/spec/ruby/core/module/public_instance_methods_spec.rb
+++ b/spec/ruby/core/module/public_instance_methods_spec.rb
@@ -1,25 +1,25 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../../../fixtures/reflection', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative '../../fixtures/reflection'
# TODO: rewrite
describe "Module#public_instance_methods" do
it "returns a list of public methods in module and its ancestors" do
methods = ModuleSpecs::CountsMixin.public_instance_methods
- methods.should include(:public_3)
+ methods.should.include?(:public_3)
methods = ModuleSpecs::CountsParent.public_instance_methods
- methods.should include(:public_3)
- methods.should include(:public_2)
+ methods.should.include?(:public_3)
+ methods.should.include?(:public_2)
methods = ModuleSpecs::CountsChild.public_instance_methods
- methods.should include(:public_3)
- methods.should include(:public_2)
- methods.should include(:public_1)
+ methods.should.include?(:public_3)
+ methods.should.include?(:public_2)
+ methods.should.include?(:public_1)
methods = ModuleSpecs::Child2.public_instance_methods
- methods.should include(:foo)
+ methods.should.include?(:foo)
end
it "when passed false as a parameter, should return only methods defined in that module" do
diff --git a/spec/ruby/core/module/public_method_defined_spec.rb b/spec/ruby/core/module/public_method_defined_spec.rb
index 329778ac15..70cd992358 100644
--- a/spec/ruby/core/module/public_method_defined_spec.rb
+++ b/spec/ruby/core/module/public_method_defined_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Module#public_method_defined?" do
it "returns true if the named public method is defined by module or its ancestors" do
@@ -31,37 +31,37 @@ describe "Module#public_method_defined?" do
ModuleSpecs::CountsMixin.public_method_defined?(:public_3).should == true
end
- it "raises a TypeError if passed a Fixnum" do
- lambda do
+ it "raises a TypeError if passed an Integer" do
+ -> do
ModuleSpecs::CountsMixin.public_method_defined?(1)
- end.should raise_error(TypeError)
+ end.should.raise(TypeError)
end
it "raises a TypeError if passed nil" do
- lambda do
+ -> do
ModuleSpecs::CountsMixin.public_method_defined?(nil)
- end.should raise_error(TypeError)
+ end.should.raise(TypeError)
end
it "raises a TypeError if passed false" do
- lambda do
+ -> do
ModuleSpecs::CountsMixin.public_method_defined?(false)
- end.should raise_error(TypeError)
+ end.should.raise(TypeError)
end
it "raises a TypeError if passed an object that does not defined #to_str" do
- lambda do
+ -> do
ModuleSpecs::CountsMixin.public_method_defined?(mock('x'))
- end.should raise_error(TypeError)
+ end.should.raise(TypeError)
end
it "raises a TypeError if passed an object that defines #to_sym" do
sym = mock('symbol')
def sym.to_sym() :public_3 end
- lambda do
+ -> do
ModuleSpecs::CountsMixin.public_method_defined?(sym)
- end.should raise_error(TypeError)
+ end.should.raise(TypeError)
end
it "calls #to_str to convert an Object" do
diff --git a/spec/ruby/core/module/public_spec.rb b/spec/ruby/core/module/public_spec.rb
index 8507689752..f35c64143b 100644
--- a/spec/ruby/core/module/public_spec.rb
+++ b/spec/ruby/core/module/public_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/set_visibility', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/set_visibility'
describe "Module#public" do
it_behaves_like :set_visibility, :public
@@ -14,31 +14,32 @@ describe "Module#public" do
public :module_specs_private_method_on_object
end
- m.should have_public_instance_method(:module_specs_private_method_on_object)
+ m.public_instance_methods(false).should.include?(:module_specs_private_method_on_object)
# Ensure we did not change Object's method
- Object.should_not have_public_instance_method(:module_specs_private_method_on_object)
+ Object.public_instance_methods(true).should_not.include?(:module_specs_private_method_on_object)
end
it "makes a private Object instance method public in Kernel" do
- Kernel.should have_public_instance_method(
+ Kernel.public_instance_methods(false).should.include?(
:module_specs_private_method_on_object_for_kernel_public)
- Object.should_not have_public_instance_method(
+ Object.public_instance_methods(true).should_not.include?(
:module_specs_private_method_on_object_for_kernel_public)
end
- it "returns self" do
+ it "returns argument or arguments if given" do
(class << Object.new; self; end).class_eval do
def foo; end
- private :foo
- public(:foo).should equal(self)
- public.should equal(self)
+ public(:foo).should.equal?(:foo)
+ public([:foo, :foo]).should == [:foo, :foo]
+ public(:foo, :foo).should == [:foo, :foo]
+ public.should.equal?(nil)
end
end
it "raises a NameError when given an undefined name" do
- lambda do
+ -> do
Module.new.send(:public, :undefined)
- end.should raise_error(NameError)
+ end.should.raise(NameError)
end
end
diff --git a/spec/ruby/core/module/refine_spec.rb b/spec/ruby/core/module/refine_spec.rb
index 67832ff676..d0fc7015f8 100644
--- a/spec/ruby/core/module/refine_spec.rb
+++ b/spec/ruby/core/module/refine_spec.rb
@@ -1,8 +1,5 @@
-
-return ## this code causes double free and now we are debugging.
-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/refine', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/refine'
describe "Module#refine" do
it "runs its block in an anonymous module" do
@@ -14,7 +11,7 @@ describe "Module#refine" do
end
mod.should_not == inner_self
- inner_self.should be_kind_of(Module)
+ inner_self.should.is_a?(Module)
inner_self.name.should == nil
end
@@ -46,7 +43,7 @@ describe "Module#refine" do
end
end
- inner_self.public_instance_methods.should include(:blah)
+ inner_self.public_instance_methods.should.include?(:blah)
end
it "returns created anonymous module" do
@@ -62,52 +59,65 @@ describe "Module#refine" do
end
it "raises ArgumentError if not passed an argument" do
- lambda do
+ -> do
Module.new do
refine {}
end
- end.should raise_error(ArgumentError)
+ end.should.raise(ArgumentError)
end
it "raises TypeError if not passed a class" do
- lambda do
+ -> do
Module.new do
refine("foo") {}
end
- end.should raise_error(TypeError)
+ end.should.raise(TypeError, "wrong argument type String (expected Class or Module)")
end
- ruby_version_is "" ... "2.4" do
- it "raises TypeError if passed a module" do
- lambda do
- Module.new do
- refine(Enumerable) {}
+ it "accepts a module as argument" do
+ inner_self = nil
+ Module.new do
+ refine(Enumerable) do
+ def blah
end
- end.should raise_error(TypeError)
+ inner_self = self
+ end
end
+
+ inner_self.public_instance_methods.should.include?(:blah)
end
- ruby_version_is "2.4" do
- it "accepts a module as argument" do
- inner_self = nil
- Module.new do
- refine(Enumerable) do
- def blah
- end
- inner_self = self
+ it "applies refinements to the module" do
+ refinement = Module.new do
+ refine(Enumerable) do
+ def foo?
+ self.any? ? "yes" : "no"
end
end
+ end
+
+ foo = Class.new do
+ using refinement
+
+ def initialize(items)
+ @items = items
+ end
- inner_self.public_instance_methods.should include(:blah)
+ def result
+ @items.foo?
+ end
end
+
+ foo.new([]).result.should == "no"
+ foo.new([1]).result.should == "yes"
end
it "raises ArgumentError if not given a block" do
- lambda do
+ -> do
Module.new do
refine String
end
- end.should raise_error(ArgumentError)
+ end.should.raise(ArgumentError)
end
it "applies refinements to calls in the refine block" do
@@ -124,9 +134,9 @@ describe "Module#refine" do
it "doesn't apply refinements outside the refine block" do
Module.new do
refine(String) {def foo; "foo"; end}
- -> () {
+ -> {
"hello".foo
- }.should raise_error(NoMethodError)
+ }.should.raise(NoMethodError)
end
end
@@ -135,7 +145,7 @@ describe "Module#refine" do
refine(String) {def foo; 'foo'; end}
end
- lambda {"hello".foo}.should raise_error(NoMethodError)
+ -> {"hello".foo}.should.raise(NoMethodError)
end
# When defining multiple refinements in the same module,
@@ -192,14 +202,14 @@ describe "Module#refine" do
result = nil
- -> () {
+ -> {
Module.new do
using refinery_integer
using refinery_array
[1, 2].to_json_format
end
- }.should raise_error(NoMethodError)
+ }.should.raise(NoMethodError)
end
# method lookup:
@@ -211,8 +221,10 @@ describe "Module#refine" do
# * The included modules of C
describe "method lookup" do
it "looks in the object singleton class first" do
+ refined_class = ModuleSpecs.build_refined_class
+
refinement = Module.new do
- refine ModuleSpecs::ClassWithFoo do
+ refine refined_class do
def foo; "foo from refinement"; end
end
end
@@ -221,7 +233,7 @@ describe "Module#refine" do
Module.new do
using refinement
- obj = ModuleSpecs::ClassWithFoo.new
+ obj = refined_class.new
class << obj
def foo; "foo from singleton class"; end
end
@@ -231,68 +243,48 @@ describe "Module#refine" do
result.should == "foo from singleton class"
end
- it "looks in prepended modules from the refinement first" do
- refinement = Module.new do
- refine ModuleSpecs::ClassWithFoo do
- include ModuleSpecs::IncludedModule
- prepend ModuleSpecs::PrependedModule
-
- def foo; "foo from refinement"; end
+ it "looks in later included modules of the refined module first" do
+ a = Module.new do
+ def foo
+ "foo from A"
end
end
- result = nil
- Module.new do
- using refinement
- result = ModuleSpecs::ClassWithFoo.new.foo
- end
-
- result.should == "foo from prepended module"
- end
-
- it "looks in refinement then" do
- refinement = Module.new do
- refine(ModuleSpecs::ClassWithFoo) do
- include ModuleSpecs::IncludedModule
-
- def foo; "foo from refinement"; end
+ include_me_later = Module.new do
+ def foo
+ "foo from IncludeMeLater"
end
end
- result = nil
- Module.new do
- using refinement
- result = ModuleSpecs::ClassWithFoo.new.foo
+ c = Class.new do
+ include a
end
- result.should == "foo from refinement"
- end
-
- it "looks in included modules from the refinement then" do
refinement = Module.new do
- refine ModuleSpecs::ClassWithFoo do
- include ModuleSpecs::IncludedModule
- end
- end
+ refine c do; end
+ end
result = nil
Module.new do
using refinement
- result = ModuleSpecs::ClassWithFoo.new.foo
+ c.include include_me_later
+ result = c.new.foo
end
- result.should == "foo from included module"
+ result.should == "foo from IncludeMeLater"
end
it "looks in the class then" do
+ refined_class = ModuleSpecs.build_refined_class
+
refinement = Module.new do
- refine(ModuleSpecs::ClassWithFoo) { }
+ refine(refined_class) { }
end
result = nil
Module.new do
using refinement
- result = ModuleSpecs::ClassWithFoo.new.foo
+ result = refined_class.new.foo
end
result.should == "foo"
@@ -302,12 +294,14 @@ describe "Module#refine" do
# methods in a subclass have priority over refinements in a superclass
it "does not override methods in subclasses" do
- subclass = Class.new(ModuleSpecs::ClassWithFoo) do
+ refined_class = ModuleSpecs.build_refined_class
+
+ subclass = Class.new(refined_class) do
def foo; "foo from subclass"; end
end
refinement = Module.new do
- refine ModuleSpecs::ClassWithFoo do
+ refine refined_class do
def foo; "foo from refinement"; end
end
end
@@ -321,109 +315,95 @@ describe "Module#refine" do
result.should == "foo from subclass"
end
- context "for methods accesses indirectly" do
- ruby_version_is "" ... "2.4" do
- it "is not honored by Kernel#send" do
- refinement = Module.new do
- refine ModuleSpecs::ClassWithFoo do
- def foo; "foo from refinement"; end
- end
- end
+ context "for methods accessed indirectly" do
+ it "is honored by Kernel#send" do
+ refined_class = ModuleSpecs.build_refined_class
- result = nil
- Module.new do
- using refinement
- result = ModuleSpecs::ClassWithFoo.new.send :foo
+ refinement = Module.new do
+ refine refined_class do
+ def foo; "foo from refinement"; end
end
-
- result.should == "foo"
end
- it "is not honored by BasicObject#__send__" do
- refinement = Module.new do
- refine ModuleSpecs::ClassWithFoo do
- def foo; "foo from refinement"; end
- end
- end
-
- result = nil
- Module.new do
- using refinement
- result = ModuleSpecs::ClassWithFoo.new.__send__ :foo
- end
-
- result.should == "foo"
+ result = nil
+ Module.new do
+ using refinement
+ result = refined_class.new.send :foo
end
- it "is not honored by Symbol#to_proc" do
- refinement = Module.new do
- refine Integer do
- def to_s
- "(#{super})"
- end
- end
- end
+ result.should == "foo from refinement"
+ end
+
+ it "is honored by BasicObject#__send__" do
+ refined_class = ModuleSpecs.build_refined_class
- result = nil
- Module.new do
- using refinement
- result = [1, 2, 3].map(&:to_s)
+ refinement = Module.new do
+ refine refined_class do
+ def foo; "foo from refinement"; end
end
+ end
- result.should == ["1", "2", "3"]
+ result = nil
+ Module.new do
+ using refinement
+ result = refined_class.new.__send__ :foo
end
+
+ result.should == "foo from refinement"
end
- ruby_version_is "2.4" do
- it "is honored by Kernel#send" do
- refinement = Module.new do
- refine ModuleSpecs::ClassWithFoo do
- def foo; "foo from refinement"; end
+ it "is honored by Symbol#to_proc" do
+ refinement = Module.new do
+ refine Integer do
+ def to_s
+ "(#{super})"
end
end
+ end
- result = nil
- Module.new do
- using refinement
- result = ModuleSpecs::ClassWithFoo.new.send :foo
- end
-
- result.should == "foo from refinement"
+ result = nil
+ Module.new do
+ using refinement
+ result = [1, 2, 3].map(&:to_s)
end
- it "is honored by BasicObject#__send__" do
- refinement = Module.new do
- refine ModuleSpecs::ClassWithFoo do
- def foo; "foo from refinement"; end
- end
- end
+ result.should == ["(1)", "(2)", "(3)"]
+ end
+
+ it "is honored by Kernel#public_send" do
+ refined_class = ModuleSpecs.build_refined_class
- result = nil
- Module.new do
- using refinement
- result = ModuleSpecs::ClassWithFoo.new.__send__ :foo
+ refinement = Module.new do
+ refine refined_class do
+ def foo; "foo from refinement"; end
end
+ end
- result.should == "foo from refinement"
+ result = nil
+ Module.new do
+ using refinement
+ result = refined_class.new.public_send :foo
end
- it "is honored by Symbol#to_proc" do
- refinement = Module.new do
- refine Integer do
- def to_s
- "(#{super})"
- end
- end
- end
+ result.should == "foo from refinement"
+ end
- result = nil
- Module.new do
- using refinement
- result = [1, 2, 3].map(&:to_s)
+ it "is honored by string interpolation" do
+ refinement = Module.new do
+ refine Integer do
+ def to_s
+ "foo"
+ end
end
+ end
- result.should == ["(1)", "(2)", "(3)"]
+ result = nil
+ Module.new do
+ using refinement
+ result = "#{1}"
end
+
+ result.should == "foo"
end
it "is honored by Kernel#binding" do
@@ -451,7 +431,7 @@ describe "Module#refine" do
result.should == "hello from refinement"
end
- it "is not honored by Kernel#method" do
+ it "is honored by Kernel#method" do
klass = Class.new
refinement = Module.new do
refine klass do
@@ -459,15 +439,50 @@ describe "Module#refine" do
end
end
- -> {
- Module.new do
- using refinement
- klass.new.method(:foo)
+ result = nil
+ Module.new do
+ using refinement
+ result = klass.new.method(:foo).class
+ end
+
+ result.should == Method
+ end
+
+ it "is honored by Kernel#public_method" do
+ klass = Class.new
+ refinement = Module.new do
+ refine klass do
+ def foo; end
+ end
+ end
+
+ result = nil
+ Module.new do
+ using refinement
+ result = klass.new.public_method(:foo).class
+ end
+
+ result.should == Method
+ end
+
+ it "is honored by Kernel#instance_method" do
+ klass = Class.new
+ refinement = Module.new do
+ refine klass do
+ def foo; end
end
- }.should raise_error(NameError, /undefined method `foo'/)
+ end
+
+ result = nil
+ Module.new do
+ using refinement
+ result = klass.instance_method(:foo).class
+ end
+
+ result.should == UnboundMethod
end
- it "is not honored by Kernel#respond_to?" do
+ it "is honored by Kernel#respond_to?" do
klass = Class.new
refinement = Module.new do
refine klass do
@@ -481,18 +496,14 @@ describe "Module#refine" do
result = klass.new.respond_to?(:foo)
end
- result.should == false
+ result.should == true
end
- end
- context "when super is called in a refinement" do
- it "looks in the included to refinery module" do
+ it "is honored by &" do
refinement = Module.new do
- refine ModuleSpecs::ClassWithFoo do
- include ModuleSpecs::IncludedModule
-
- def foo
- super
+ refine String do
+ def to_proc(*args)
+ -> * { 'foo' }
end
end
end
@@ -500,15 +511,19 @@ describe "Module#refine" do
result = nil
Module.new do
using refinement
- result = ModuleSpecs::ClassWithFoo.new.foo
+ result = ["hola"].map(&"upcase")
end
- result.should == "foo from included module"
+ result.should == ['foo']
end
+ end
+ context "when super is called in a refinement" do
it "looks in the refined class" do
+ refined_class = ModuleSpecs.build_refined_class
+
refinement = Module.new do
- refine ModuleSpecs::ClassWithFoo do
+ refine refined_class do
def foo
super
end
@@ -518,7 +533,7 @@ describe "Module#refine" do
result = nil
Module.new do
using refinement
- result = ModuleSpecs::ClassWithFoo.new.foo
+ result = refined_class.new.foo
end
result.should == "foo"
@@ -527,19 +542,21 @@ describe "Module#refine" do
# super in a method of a refinement invokes the method in the refined
# class even if there is another refinement which has been activated
# in the same context.
- it "looks in the refined class even if there is another active refinement" do
+ it "looks in the refined class first if called from refined method" do
+ refined_class = ModuleSpecs.build_refined_class(for_super: true)
+
refinement = Module.new do
- refine ModuleSpecs::ClassWithFoo do
+ refine refined_class do
def foo
- "foo from refinement"
+ [:R1]
end
end
end
refinement_with_super = Module.new do
- refine ModuleSpecs::ClassWithFoo do
+ refine refined_class do
def foo
- super
+ [:R2] + super
end
end
end
@@ -548,13 +565,77 @@ describe "Module#refine" do
Module.new do
using refinement
using refinement_with_super
- result = ModuleSpecs::ClassWithFoo.new.foo
+ result = refined_class.new.foo
end
- result.should == "foo"
+ result.should == [:R2, :C]
+ end
+
+ it "looks only in the refined class even if there is another active refinement" do
+ refined_class = ModuleSpecs.build_refined_class(for_super: true)
+
+ refinement = Module.new do
+ refine refined_class do
+ def bar
+ "you cannot see me from super because I belong to another active R"
+ end
+ end
+ end
+
+ refinement_with_super = Module.new do
+ refine refined_class do
+ def bar
+ super
+ end
+ end
+ end
+
+
+ Module.new do
+ using refinement
+ using refinement_with_super
+ -> {
+ refined_class.new.bar
+ }.should.raise(NoMethodError)
+ end
end
end
+ it 'and alias aliases a method within a refinement module, but not outside it' do
+ Module.new do
+ using Module.new {
+ refine Array do
+ alias :orig_count :count
+ end
+ }
+ [1,2].orig_count.should == 2
+ end
+ -> { [1,2].orig_count }.should.raise(NoMethodError)
+ end
+
+ it 'and alias_method aliases a method within a refinement module, but not outside it' do
+ Module.new do
+ using Module.new {
+ refine Array do
+ alias_method :orig_count, :count
+ end
+ }
+ [1,2].orig_count.should == 2
+ end
+ -> { [1,2].orig_count }.should.raise(NoMethodError)
+ end
+
+ it "and instance_methods returns a list of methods including those of the refined module" do
+ methods = Array.instance_methods
+ methods_2 = []
+ Module.new do
+ refine Array do
+ methods_2 = instance_methods
+ end
+ end
+ methods.should == methods_2
+ end
+
# Refinements are inherited by module inclusion.
# That is, using activates all refinements in the ancestors of the specified module.
# Refinements in a descendant have priority over refinements in an ancestor.
@@ -615,5 +696,18 @@ describe "Module#refine" do
result.should == "hello from refinement"
end
end
-end
+ it 'does not list methods defined only in refinement' do
+ refine_object = Module.new do
+ refine Object do
+ def refinement_only_method
+ end
+ end
+ end
+ klass = Class.new { instance_methods.should_not.include?(:refinement_only_method) }
+ instance = klass.new
+ instance.methods.should_not.include? :refinement_only_method
+ instance.respond_to?(:refinement_only_method).should == false
+ -> { instance.method :refinement_only_method }.should.raise(NameError)
+ end
+end
diff --git a/spec/ruby/core/module/refinements_spec.rb b/spec/ruby/core/module/refinements_spec.rb
new file mode 100644
index 0000000000..05658a8b0e
--- /dev/null
+++ b/spec/ruby/core/module/refinements_spec.rb
@@ -0,0 +1,43 @@
+require_relative '../../spec_helper'
+
+describe "Module#refinements" do
+ it "returns refinements defined in a module" do
+ ScratchPad.record []
+
+ m = Module.new do
+ refine String do
+ ScratchPad << self
+ end
+
+ refine Array do
+ ScratchPad << self
+ end
+ end
+
+ m.refinements.sort_by(&:object_id).should == ScratchPad.recorded.sort_by(&:object_id)
+ end
+
+ it "does not return refinements defined in the included module" do
+ ScratchPad.record []
+
+ m1 = Module.new do
+ refine Integer do
+ nil
+ end
+ end
+
+ m2 = Module.new do
+ include m1
+
+ refine String do
+ ScratchPad << self
+ end
+ end
+
+ m2.refinements.should == ScratchPad.recorded
+ end
+
+ it "returns an empty array if no refinements defined in a module" do
+ Module.new.refinements.should == []
+ end
+end
diff --git a/spec/ruby/core/module/remove_class_variable_spec.rb b/spec/ruby/core/module/remove_class_variable_spec.rb
index adf2c1d1f8..fccb29f52d 100644
--- a/spec/ruby/core/module/remove_class_variable_spec.rb
+++ b/spec/ruby/core/module/remove_class_variable_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Module#remove_class_variable" do
it "removes class variable" do
@@ -18,27 +18,27 @@ describe "Module#remove_class_variable" do
meta = obj.singleton_class
meta.send :class_variable_set, :@@var, 1
meta.send(:remove_class_variable, :@@var).should == 1
- meta.class_variable_defined?(:@@var).should be_false
+ meta.class_variable_defined?(:@@var).should == false
end
it "raises a NameError when removing class variable declared in included module" do
c = ModuleSpecs::RemoveClassVariable.new { include ModuleSpecs::MVars.dup }
- lambda { c.send(:remove_class_variable, :@@mvar) }.should raise_error(NameError)
+ -> { c.send(:remove_class_variable, :@@mvar) }.should.raise(NameError)
end
it "raises a NameError when passed a symbol with one leading @" do
- lambda { ModuleSpecs::MVars.send(:remove_class_variable, :@mvar) }.should raise_error(NameError)
+ -> { ModuleSpecs::MVars.send(:remove_class_variable, :@mvar) }.should.raise(NameError)
end
it "raises a NameError when passed a symbol with no leading @" do
- lambda { ModuleSpecs::MVars.send(:remove_class_variable, :mvar) }.should raise_error(NameError)
+ -> { ModuleSpecs::MVars.send(:remove_class_variable, :mvar) }.should.raise(NameError)
end
it "raises a NameError when an uninitialized class variable is given" do
- lambda { ModuleSpecs::MVars.send(:remove_class_variable, :@@nonexisting_class_variable) }.should raise_error(NameError)
+ -> { ModuleSpecs::MVars.send(:remove_class_variable, :@@nonexisting_class_variable) }.should.raise(NameError)
end
it "is public" do
- Module.should_not have_private_instance_method(:remove_class_variable)
+ Module.private_instance_methods(true).should_not.include?(:remove_class_variable)
end
end
diff --git a/spec/ruby/core/module/remove_const_spec.rb b/spec/ruby/core/module/remove_const_spec.rb
index 0c1b87598e..4e4b9fcb45 100644
--- a/spec/ruby/core/module/remove_const_spec.rb
+++ b/spec/ruby/core/module/remove_const_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../fixtures/constants', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../../fixtures/constants'
describe "Module#remove_const" do
it "removes the constant specified by a String or Symbol from the receiver's constant table" do
@@ -7,13 +7,13 @@ describe "Module#remove_const" do
ConstantSpecs::ModuleM::CS_CONST252.should == :const252
ConstantSpecs::ModuleM.send :remove_const, :CS_CONST252
- lambda { ConstantSpecs::ModuleM::CS_CONST252 }.should raise_error(NameError)
+ -> { ConstantSpecs::ModuleM::CS_CONST252 }.should.raise(NameError)
ConstantSpecs::ModuleM::CS_CONST253 = :const253
ConstantSpecs::ModuleM::CS_CONST253.should == :const253
ConstantSpecs::ModuleM.send :remove_const, "CS_CONST253"
- lambda { ConstantSpecs::ModuleM::CS_CONST253 }.should raise_error(NameError)
+ -> { ConstantSpecs::ModuleM::CS_CONST253 }.should.raise(NameError)
end
it "returns the value of the removed constant" do
@@ -23,7 +23,7 @@ describe "Module#remove_const" do
it "raises a NameError and does not call #const_missing if the constant is not defined" do
ConstantSpecs.should_not_receive(:const_missing)
- lambda { ConstantSpecs.send(:remove_const, :Nonexistent) }.should raise_error(NameError)
+ -> { ConstantSpecs.send(:remove_const, :Nonexistent) }.should.raise(NameError)
end
it "raises a NameError and does not call #const_missing if the constant is not defined directly in the module" do
@@ -32,30 +32,30 @@ describe "Module#remove_const" do
ConstantSpecs::ContainerA::CS_CONST255.should == :const255
ConstantSpecs::ContainerA.should_not_receive(:const_missing)
- lambda do
+ -> do
ConstantSpecs::ContainerA.send :remove_const, :CS_CONST255
- end.should raise_error(NameError)
+ end.should.raise(NameError)
ensure
ConstantSpecs::ModuleM.send :remove_const, "CS_CONST255"
end
end
it "raises a NameError if the name does not start with a capital letter" do
- lambda { ConstantSpecs.send :remove_const, "name" }.should raise_error(NameError)
+ -> { ConstantSpecs.send :remove_const, "name" }.should.raise(NameError)
end
it "raises a NameError if the name starts with a non-alphabetic character" do
- lambda { ConstantSpecs.send :remove_const, "__CONSTX__" }.should raise_error(NameError)
- lambda { ConstantSpecs.send :remove_const, "@Name" }.should raise_error(NameError)
- lambda { ConstantSpecs.send :remove_const, "!Name" }.should raise_error(NameError)
- lambda { ConstantSpecs.send :remove_const, "::Name" }.should raise_error(NameError)
+ -> { ConstantSpecs.send :remove_const, "__CONSTX__" }.should.raise(NameError)
+ -> { ConstantSpecs.send :remove_const, "@Name" }.should.raise(NameError)
+ -> { ConstantSpecs.send :remove_const, "!Name" }.should.raise(NameError)
+ -> { ConstantSpecs.send :remove_const, "::Name" }.should.raise(NameError)
end
it "raises a NameError if the name contains non-alphabetic characters except '_'" do
ConstantSpecs::ModuleM::CS_CONST256 = :const256
ConstantSpecs::ModuleM.send :remove_const, "CS_CONST256"
- lambda { ConstantSpecs.send :remove_const, "Name=" }.should raise_error(NameError)
- lambda { ConstantSpecs.send :remove_const, "Name?" }.should raise_error(NameError)
+ -> { ConstantSpecs.send :remove_const, "Name=" }.should.raise(NameError)
+ -> { ConstantSpecs.send :remove_const, "Name?" }.should.raise(NameError)
end
it "calls #to_str to convert the given name to a String" do
@@ -67,18 +67,41 @@ describe "Module#remove_const" do
it "raises a TypeError if conversion to a String by calling #to_str fails" do
name = mock('123')
- lambda { ConstantSpecs.send :remove_const, name }.should raise_error(TypeError)
+ -> { ConstantSpecs.send :remove_const, name }.should.raise(TypeError)
name.should_receive(:to_str).and_return(123)
- lambda { ConstantSpecs.send :remove_const, name }.should raise_error(TypeError)
+ -> { ConstantSpecs.send :remove_const, name }.should.raise(TypeError)
end
it "is a private method" do
- Module.private_methods.should include(:remove_const)
+ Module.private_methods.should.include?(:remove_const)
end
it "returns nil when removing autoloaded constant" do
ConstantSpecs.autoload :AutoloadedConstant, 'a_file'
- ConstantSpecs.send(:remove_const, :AutoloadedConstant).should be_nil
+ ConstantSpecs.send(:remove_const, :AutoloadedConstant).should == nil
+ end
+
+ it "updates the constant value" do
+ module ConstantSpecs::RemovedConstantUpdate
+ module M
+ FOO = 'm'
+ end
+
+ module A
+ include M
+ FOO = 'a'
+ def self.foo
+ FOO
+ end
+ end
+
+ A.foo.should == 'a'
+
+ A.send(:remove_const,:FOO)
+ A.foo.should == 'm'
+ end
+ ensure
+ ConstantSpecs.send(:remove_const, :RemovedConstantUpdate)
end
end
diff --git a/spec/ruby/core/module/remove_method_spec.rb b/spec/ruby/core/module/remove_method_spec.rb
index f98cfa8daa..39add01e36 100644
--- a/spec/ruby/core/module/remove_method_spec.rb
+++ b/spec/ruby/core/module/remove_method_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
module ModuleSpecs
class Parent
@@ -20,8 +20,8 @@ describe "Module#remove_method" do
@module = Module.new { def method_to_remove; end }
end
- it "is a private method" do
- Module.should have_private_instance_method(:remove_method, false)
+ it "is a public method" do
+ Module.public_instance_methods(false).should.include?(:remove_method)
end
it "removes the method from a class" do
@@ -43,6 +43,28 @@ describe "Module#remove_method" do
x.method_to_remove.should == 1
end
+ it "updates the method implementation" do
+ m_module = Module.new do
+ def foo
+ 'm'
+ end
+ end
+
+ a_class = Class.new do
+ include m_module
+
+ def foo
+ 'a'
+ end
+ end
+
+ a = a_class.new
+ foo = -> { a.foo }
+ foo.call.should == 'a'
+ a_class.remove_method(:foo)
+ foo.call.should == 'm'
+ end
+
it "removes multiple methods with 1 call" do
klass = Class.new do
def method_to_remove_1; 1; end
@@ -66,23 +88,23 @@ describe "Module#remove_method" do
end
it "returns self" do
- @module.send(:remove_method, :method_to_remove).should equal(@module)
+ @module.send(:remove_method, :method_to_remove).should.equal?(@module)
end
it "raises a NameError when attempting to remove method further up the inheritance tree" do
- lambda {
- class Third < ModuleSpecs::Second
+ Class.new(ModuleSpecs::Second) do
+ -> {
remove_method :method_to_remove
- end
- }.should raise_error(NameError)
+ }.should.raise(NameError)
+ end
end
it "raises a NameError when attempting to remove a missing method" do
- lambda {
- class Third < ModuleSpecs::Second
+ Class.new(ModuleSpecs::Second) do
+ -> {
remove_method :blah
- end
- }.should raise_error(NameError)
+ }.should.raise(NameError)
+ end
end
describe "on frozen instance" do
@@ -90,20 +112,20 @@ describe "Module#remove_method" do
@frozen = @module.dup.freeze
end
- it "raises a RuntimeError when passed a name" do
- lambda { @frozen.send :remove_method, :method_to_remove }.should raise_error(RuntimeError)
+ it "raises a FrozenError when passed a name" do
+ -> { @frozen.send :remove_method, :method_to_remove }.should.raise(FrozenError)
end
- it "raises a RuntimeError when passed a missing name" do
- lambda { @frozen.send :remove_method, :not_exist }.should raise_error(RuntimeError)
+ it "raises a FrozenError when passed a missing name" do
+ -> { @frozen.send :remove_method, :not_exist }.should.raise(FrozenError)
end
it "raises a TypeError when passed a not name" do
- lambda { @frozen.send :remove_method, Object.new }.should raise_error(TypeError)
+ -> { @frozen.send :remove_method, Object.new }.should.raise(TypeError)
end
it "does not raise exceptions when no arguments given" do
- @frozen.send(:remove_method).should equal(@frozen)
+ @frozen.send(:remove_method).should.equal?(@frozen)
end
end
end
diff --git a/spec/ruby/core/module/ruby2_keywords_spec.rb b/spec/ruby/core/module/ruby2_keywords_spec.rb
new file mode 100644
index 0000000000..e392642978
--- /dev/null
+++ b/spec/ruby/core/module/ruby2_keywords_spec.rb
@@ -0,0 +1,248 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe "Module#ruby2_keywords" do
+ class << self
+ ruby2_keywords def mark(*args)
+ args
+ end
+ end
+
+ it "marks the final hash argument as keyword hash" do
+ last = mark(1, 2, a: "a").last
+ Hash.ruby2_keywords_hash?(last).should == true
+ end
+
+ it "makes a copy of the hash and only marks the copy as keyword hash" do
+ obj = Object.new
+ obj.singleton_class.class_exec do
+ def regular(*args)
+ args.last
+ end
+ end
+
+ h = {a: 1}
+
+ last = mark(**h).last
+ Hash.ruby2_keywords_hash?(last).should == true
+ Hash.ruby2_keywords_hash?(h).should == false
+
+ last2 = mark(**last).last # last is already marked
+ Hash.ruby2_keywords_hash?(last2).should == true
+ Hash.ruby2_keywords_hash?(last).should == true
+ last2.should_not.equal?(last)
+ Hash.ruby2_keywords_hash?(h).should == false
+ end
+
+ it "makes a copy and unmark the Hash when calling a method taking (arg)" do
+ obj = Object.new
+ obj.singleton_class.class_exec do
+ def single(arg)
+ arg
+ end
+ end
+
+ h = { a: 1 }
+ args = mark(**h)
+ marked = args.last
+ Hash.ruby2_keywords_hash?(marked).should == true
+
+ after_usage = obj.single(*args)
+ after_usage.should == h
+ after_usage.should_not.equal?(h)
+ after_usage.should_not.equal?(marked)
+ Hash.ruby2_keywords_hash?(after_usage).should == false
+ Hash.ruby2_keywords_hash?(marked).should == true
+ end
+
+ it "makes a copy and unmark the Hash when calling a method taking (**kw)" do
+ obj = Object.new
+ obj.singleton_class.class_exec do
+ def kwargs(**kw)
+ kw
+ end
+ end
+
+ h = { a: 1 }
+ args = mark(**h)
+ marked = args.last
+ Hash.ruby2_keywords_hash?(marked).should == true
+
+ after_usage = obj.kwargs(*args)
+ after_usage.should == h
+ after_usage.should_not.equal?(h)
+ after_usage.should_not.equal?(marked)
+ Hash.ruby2_keywords_hash?(after_usage).should == false
+ Hash.ruby2_keywords_hash?(marked).should == true
+ end
+
+ it "makes a copy and unmark the Hash when calling a method taking (*args)" do
+ obj = Object.new
+ obj.singleton_class.class_exec do
+ def splat(*args)
+ args.last
+ end
+
+ def splat1(arg, *args)
+ args.last
+ end
+
+ def proc_call(*args)
+ -> *a { a.last }.call(*args)
+ end
+ end
+
+ h = { a: 1 }
+ args = mark(**h)
+ marked = args.last
+ Hash.ruby2_keywords_hash?(marked).should == true
+
+ after_usage = obj.splat(*args)
+ after_usage.should == h
+ after_usage.should_not.equal?(h)
+ after_usage.should_not.equal?(marked)
+ Hash.ruby2_keywords_hash?(after_usage).should == false
+ Hash.ruby2_keywords_hash?(marked).should == true
+
+ args = mark(1, **h)
+ marked = args.last
+ after_usage = obj.splat1(*args)
+ after_usage.should == h
+ after_usage.should_not.equal?(h)
+ after_usage.should_not.equal?(marked)
+ Hash.ruby2_keywords_hash?(after_usage).should == false
+ Hash.ruby2_keywords_hash?(marked).should == true
+
+ args = mark(**h)
+ marked = args.last
+ after_usage = obj.proc_call(*args)
+ after_usage.should == h
+ after_usage.should_not.equal?(h)
+ after_usage.should_not.equal?(marked)
+ Hash.ruby2_keywords_hash?(after_usage).should == false
+ Hash.ruby2_keywords_hash?(marked).should == true
+
+ args = mark(**h)
+ marked = args.last
+ after_usage = obj.send(:splat, *args)
+ after_usage.should == h
+ after_usage.should_not.equal?(h)
+ after_usage.should_not.equal?(marked)
+ Hash.ruby2_keywords_hash?(after_usage).should == false
+ Hash.ruby2_keywords_hash?(marked).should == true
+ end
+
+ it "applies to the underlying method and applies across aliasing" do
+ obj = Object.new
+
+ obj.singleton_class.class_exec do
+ def foo(*a) a.last end
+ alias_method :bar, :foo
+ ruby2_keywords :foo
+
+ def baz(*a) a.last end
+ ruby2_keywords :baz
+ alias_method :bob, :baz
+ end
+
+ last = obj.foo(1, 2, a: "a")
+ Hash.ruby2_keywords_hash?(last).should == true
+
+ last = obj.bar(1, 2, a: "a")
+ Hash.ruby2_keywords_hash?(last).should == true
+
+ last = obj.baz(1, 2, a: "a")
+ Hash.ruby2_keywords_hash?(last).should == true
+
+ last = obj.bob(1, 2, a: "a")
+ Hash.ruby2_keywords_hash?(last).should == true
+ end
+
+ it "returns nil" do
+ obj = Object.new
+
+ obj.singleton_class.class_exec do
+ def foo(*a) end
+
+ ruby2_keywords(:foo).should == nil
+ end
+ end
+
+ it "raises NameError when passed not existing method name" do
+ obj = Object.new
+
+ -> {
+ obj.singleton_class.class_exec do
+ ruby2_keywords :not_existing
+ end
+ }.should.raise(NameError, /undefined method [`']not_existing'/)
+ end
+
+ it "accepts String as well" do
+ obj = Object.new
+
+ obj.singleton_class.class_exec do
+ def foo(*a) a.last end
+ ruby2_keywords "foo"
+ end
+
+ last = obj.foo(1, 2, a: "a")
+ Hash.ruby2_keywords_hash?(last).should == true
+ end
+
+ it "raises TypeError when passed not Symbol or String" do
+ obj = Object.new
+
+ -> {
+ obj.singleton_class.class_exec do
+ ruby2_keywords Object.new
+ end
+ }.should.raise(TypeError, /is not a symbol nor a string/)
+ end
+
+ it "prints warning when a method does not accept argument splat" do
+ obj = Object.new
+ def obj.foo(a, b, c) end
+
+ -> {
+ obj.singleton_class.class_exec do
+ ruby2_keywords :foo
+ end
+ }.should complain(/Skipping set of ruby2_keywords flag for/)
+ end
+
+ it "prints warning when a method accepts keywords" do
+ obj = Object.new
+ def obj.foo(*a, b:) end
+
+ -> {
+ obj.singleton_class.class_exec do
+ ruby2_keywords :foo
+ end
+ }.should complain(/Skipping set of ruby2_keywords flag for/)
+ end
+
+ it "prints warning when a method accepts keyword splat" do
+ obj = Object.new
+ def obj.foo(*a, **b) end
+
+ -> {
+ obj.singleton_class.class_exec do
+ ruby2_keywords :foo
+ end
+ }.should complain(/Skipping set of ruby2_keywords flag for/)
+ end
+
+ ruby_version_is "4.0" do
+ it "prints warning when a method accepts post arguments" do
+ obj = Object.new
+ def obj.foo(*a, b) end
+
+ -> {
+ obj.singleton_class.class_exec do
+ ruby2_keywords :foo
+ end
+ }.should complain(/Skipping set of ruby2_keywords flag for/)
+ end
+ end
+end
diff --git a/spec/ruby/core/module/set_temporary_name_spec.rb b/spec/ruby/core/module/set_temporary_name_spec.rb
new file mode 100644
index 0000000000..7c159121fa
--- /dev/null
+++ b/spec/ruby/core/module/set_temporary_name_spec.rb
@@ -0,0 +1,145 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/set_temporary_name'
+
+describe "Module#set_temporary_name" do
+ it "can assign a temporary name" do
+ m = Module.new
+ m.name.should == nil
+
+ m.set_temporary_name("fake_name")
+ m.name.should == "fake_name"
+
+ m.set_temporary_name(nil)
+ m.name.should == nil
+ end
+
+ it "returns self" do
+ m = Module.new
+ m.set_temporary_name("fake_name").should.equal? m
+ end
+
+ it "can assign a temporary name which is not a valid constant path" do
+ m = Module.new
+
+ m.set_temporary_name("name")
+ m.name.should == "name"
+
+ m.set_temporary_name("Template['foo.rb']")
+ m.name.should == "Template['foo.rb']"
+
+ m.set_temporary_name("a::B")
+ m.name.should == "a::B"
+
+ m.set_temporary_name("A::b")
+ m.name.should == "A::b"
+
+ m.set_temporary_name("A::B::")
+ m.name.should == "A::B::"
+
+ m.set_temporary_name("A::::B")
+ m.name.should == "A::::B"
+
+ m.set_temporary_name("A=")
+ m.name.should == "A="
+ end
+
+ it "can't assign empty string as name" do
+ m = Module.new
+ -> { m.set_temporary_name("") }.should.raise(ArgumentError, "empty class/module name")
+ end
+
+ it "can't assign a constant name as a temporary name" do
+ m = Module.new
+ -> { m.set_temporary_name("Object") }.should.raise(ArgumentError, "the temporary name must not be a constant path to avoid confusion")
+ end
+
+ it "can't assign a constant path as a temporary name" do
+ m = Module.new
+ -> { m.set_temporary_name("A::B") }.should.raise(ArgumentError, "the temporary name must not be a constant path to avoid confusion")
+ -> { m.set_temporary_name("::A") }.should.raise(ArgumentError, "the temporary name must not be a constant path to avoid confusion")
+ -> { m.set_temporary_name("::A::B") }.should.raise(ArgumentError, "the temporary name must not be a constant path to avoid confusion")
+ end
+
+ it "can't assign name to permanent module" do
+ -> { Object.set_temporary_name("fake_name") }.should.raise(RuntimeError, "can't change permanent name")
+ end
+
+ it "can assign a temporary name to a module nested into an anonymous module" do
+ m = Module.new
+ module m::N; end
+ m::N.name.should =~ /\A#<Module:0x\h+>::N\z/
+
+ m::N.set_temporary_name("fake_name")
+ m::N.name.should == "fake_name"
+
+ m::N.set_temporary_name(nil)
+ m::N.name.should == nil
+ end
+
+ it "discards a temporary name when an outer anonymous module gets a permanent name" do
+ m = Module.new
+ module m::N; end
+
+ m::N.set_temporary_name("fake_name")
+ m::N.name.should == "fake_name"
+
+ ModuleSpecs::SetTemporaryNameSpec::M = m
+ m::N.name.should == "ModuleSpecs::SetTemporaryNameSpec::M::N"
+ ModuleSpecs::SetTemporaryNameSpec.send :remove_const, :M
+ end
+
+ it "can update the name when assigned to a constant" do
+ m = Module.new
+ m::N = Module.new
+ m::N.name.should =~ /\A#<Module:0x\h+>::N\z/
+ m::N.set_temporary_name(nil)
+
+ m::M = m::N
+ m::M.name.should =~ /\A#<Module:0x\h+>::M\z/m
+ end
+
+ it "can reassign a temporary name repeatedly" do
+ m = Module.new
+
+ m.set_temporary_name("fake_name")
+ m.name.should == "fake_name"
+
+ m.set_temporary_name("fake_name_2")
+ m.name.should == "fake_name_2"
+ end
+
+ ruby_bug "#21094", ""..."4.0" do
+ it "also updates a name of a nested module" do
+ m = Module.new
+ m::N = Module.new
+ m::N.name.should =~ /\A#<Module:0x\h+>::N\z/
+
+ m.set_temporary_name "m"
+ m::N.name.should == "m::N"
+
+ m.set_temporary_name nil
+ m::N.name.should == nil
+ end
+ end
+
+ it "keeps temporary name when assigned in an anonymous module" do
+ outer = Module.new
+ m = Module.new
+ m.set_temporary_name "m"
+ m.name.should == "m"
+ outer::M = m
+ m.name.should == "m"
+ m.inspect.should == "m"
+ end
+
+ it "keeps temporary name when assigned in an anonymous module and nested before" do
+ outer = Module.new
+ m = Module.new
+ outer::A = m
+ m.set_temporary_name "m"
+ m.name.should == "m"
+ outer::M = m
+ m.name.should == "m"
+ m.inspect.should == "m"
+ end
+end
diff --git a/spec/ruby/core/module/shared/attr_added.rb b/spec/ruby/core/module/shared/attr_added.rb
new file mode 100644
index 0000000000..ce832cdcff
--- /dev/null
+++ b/spec/ruby/core/module/shared/attr_added.rb
@@ -0,0 +1,34 @@
+describe :module_attr_added, shared: true do
+ it "calls method_added for normal classes" do
+ ScratchPad.record []
+
+ cls = Class.new do
+ class << self
+ def method_added(name)
+ ScratchPad.recorded << name
+ end
+ end
+ end
+
+ cls.send(@method, :foo)
+
+ ScratchPad.recorded.each {|name| name.to_s.should =~ /foo[=]?/}
+ end
+
+ it "calls singleton_method_added for singleton classes" do
+ ScratchPad.record []
+ cls = Class.new do
+ class << self
+ def singleton_method_added(name)
+ # called for this def so ignore it
+ return if name == :singleton_method_added
+ ScratchPad.recorded << name
+ end
+ end
+ end
+
+ cls.singleton_class.send(@method, :foo)
+
+ ScratchPad.recorded.each {|name| name.to_s.should =~ /foo[=]?/}
+ end
+end
diff --git a/spec/ruby/core/module/shared/class_eval.rb b/spec/ruby/core/module/shared/class_eval.rb
deleted file mode 100644
index 6bb9668fee..0000000000
--- a/spec/ruby/core/module/shared/class_eval.rb
+++ /dev/null
@@ -1,115 +0,0 @@
-describe :module_class_eval, shared: true do
- # TODO: This should probably be replaced with a "should behave like" that uses
- # the many scoping/binding specs from kernel/eval_spec, since most of those
- # behaviors are the same for instance_eval. See also module_eval/class_eval.
-
- it "evaluates a given string in the context of self" do
- ModuleSpecs.send(@method, "self").should == ModuleSpecs
- ModuleSpecs.send(@method, "1 + 1").should == 2
- end
-
- it "does not add defined methods to other classes" do
- FalseClass.send(@method) do
- def foo
- 'foo'
- end
- end
- lambda {42.foo}.should raise_error(NoMethodError)
- end
-
- it "resolves constants in the caller scope" do
- ModuleSpecs::ClassEvalTest.get_constant_from_scope.should == ModuleSpecs::Lookup
- end
-
- it "resolves constants in the caller scope ignoring send" do
- ModuleSpecs::ClassEvalTest.get_constant_from_scope_with_send(@method).should == ModuleSpecs::Lookup
- end
-
- it "resolves constants in the receiver's scope" do
- ModuleSpecs.send(@method, "Lookup").should == ModuleSpecs::Lookup
- ModuleSpecs.send(@method, "Lookup::LOOKIE").should == ModuleSpecs::Lookup::LOOKIE
- end
-
- it "defines constants in the receiver's scope" do
- ModuleSpecs.send(@method, "module NewEvaluatedModule;end")
- ModuleSpecs.const_defined?(:NewEvaluatedModule, false).should == true
- end
-
- it "evaluates a given block in the context of self" do
- ModuleSpecs.send(@method) { self }.should == ModuleSpecs
- ModuleSpecs.send(@method) { 1 + 1 }.should == 2
- end
-
- it "passes the module as the first argument of the block" do
- given = nil
- ModuleSpecs.send(@method) do |block_parameter|
- given = block_parameter
- end
- given.should equal ModuleSpecs
- end
-
- it "uses the optional filename and lineno parameters for error messages" do
- ModuleSpecs.send(@method, "[__FILE__, __LINE__]", "test", 102).should == ["test", 102]
- end
-
- it "converts a non-string filename to a string using to_str" do
- (file = mock(__FILE__)).should_receive(:to_str).and_return(__FILE__)
- ModuleSpecs.send(@method, "1+1", file)
- end
-
- it "raises a TypeError when the given filename can't be converted to string using to_str" do
- (file = mock('123')).should_receive(:to_str).and_return(123)
- lambda { ModuleSpecs.send(@method, "1+1", file) }.should raise_error(TypeError)
- end
-
- it "converts non string eval-string to string using to_str" do
- (o = mock('1 + 1')).should_receive(:to_str).and_return("1 + 1")
- ModuleSpecs.send(@method, o).should == 2
- end
-
- it "raises a TypeError when the given eval-string can't be converted to string using to_str" do
- o = mock('x')
- lambda { ModuleSpecs.send(@method, o) }.should raise_error(TypeError)
-
- (o = mock('123')).should_receive(:to_str).and_return(123)
- lambda { ModuleSpecs.send(@method, o) }.should raise_error(TypeError)
- end
-
- it "raises an ArgumentError when no arguments and no block are given" do
- lambda { ModuleSpecs.send(@method) }.should raise_error(ArgumentError)
- end
-
- it "raises an ArgumentError when more than 3 arguments are given" do
- lambda {
- ModuleSpecs.send(@method, "1 + 1", "some file", 0, "bogus")
- }.should raise_error(ArgumentError)
- end
-
- it "raises an ArgumentError when a block and normal arguments are given" do
- lambda {
- ModuleSpecs.send(@method, "1 + 1") { 1 + 1 }
- }.should raise_error(ArgumentError)
- end
-
- # This case was found because Rubinius was caching the compiled
- # version of the string and not duping the methods within the
- # eval, causing the method addition to change the static scope
- # of the shared CompiledCode.
- it "adds methods respecting the lexical constant scope" do
- code = "def self.attribute; C; end"
-
- a = Class.new do
- self::C = "A"
- end
-
- b = Class.new do
- self::C = "B"
- end
-
- a.send @method, code
- b.send @method, code
-
- a.attribute.should == "A"
- b.attribute.should == "B"
- end
-end
diff --git a/spec/ruby/core/module/shared/class_exec.rb b/spec/ruby/core/module/shared/class_exec.rb
deleted file mode 100644
index c5c18b0a34..0000000000
--- a/spec/ruby/core/module/shared/class_exec.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-describe :module_class_exec, shared: true do
- it "does not add defined methods to other classes" do
- FalseClass.send(@method) do
- def foo
- 'foo'
- end
- end
- lambda {42.foo}.should raise_error(NoMethodError)
- end
-
- it "defines method in the receiver's scope" do
- ModuleSpecs::Subclass.send(@method) { def foo; end }
- ModuleSpecs::Subclass.new.respond_to?(:foo).should == true
- end
-
- it "evaluates a given block in the context of self" do
- ModuleSpecs::Subclass.send(@method) { self }.should == ModuleSpecs::Subclass
- ModuleSpecs::Subclass.new.send(@method) { 1 + 1 }.should == 2
- end
-
- it "raises a LocalJumpError when no block is given" do
- lambda { ModuleSpecs::Subclass.send(@method) }.should raise_error(LocalJumpError)
- end
-
- it "passes arguments to the block" do
- a = ModuleSpecs::Subclass
- a.send(@method, 1) { |b| b }.should equal(1)
- end
-end
diff --git a/spec/ruby/core/module/shared/set_visibility.rb b/spec/ruby/core/module/shared/set_visibility.rb
index c39d59e05d..38cc2ad260 100644
--- a/spec/ruby/core/module/shared/set_visibility.rb
+++ b/spec/ruby/core/module/shared/set_visibility.rb
@@ -2,7 +2,56 @@
describe :set_visibility, shared: true do
it "is a private method" do
- Module.should have_private_instance_method(@method, false)
+ Module.private_instance_methods(false).should.include?(@method)
+ end
+
+ describe "with argument" do
+ describe "one or more arguments" do
+ it "sets visibility of given method names" do
+ visibility = @method
+ old_visibility = [:protected, :private].find {|vis| vis != visibility }
+
+ mod = Module.new {
+ send old_visibility
+ def test1() end
+ def test2() end
+ send visibility, :test1, :test2
+ }
+ mod.send(:"#{visibility}_instance_methods", false).should.include?(:test1)
+ mod.send(:"#{visibility}_instance_methods", false).should.include?(:test2)
+ end
+ end
+
+ describe "array as a single argument" do
+ it "sets visibility of given method names" do
+ visibility = @method
+ old_visibility = [:protected, :private].find {|vis| vis != visibility }
+
+ mod = Module.new {
+ send old_visibility
+ def test1() end
+ def test2() end
+ send visibility, [:test1, :test2]
+ }
+ mod.send(:"#{visibility}_instance_methods", false).should.include?(:test1)
+ mod.send(:"#{visibility}_instance_methods", false).should.include?(:test2)
+ end
+ end
+
+ it "does not clone method from the ancestor when setting to the same visibility in a child" do
+ visibility = @method
+ parent = Module.new {
+ def test_method; end
+ send(visibility, :test_method)
+ }
+
+ child = Module.new {
+ include parent
+ send(visibility, :test_method)
+ }
+
+ child.send(:"#{visibility}_instance_methods", false).should_not.include?(:test_method)
+ end
end
describe "without arguments" do
@@ -15,8 +64,8 @@ describe :set_visibility, shared: true do
def test2() end
}
- mod.should send(:"have_#{@method}_instance_method", :test1, false)
- mod.should send(:"have_#{@method}_instance_method", :test2, false)
+ mod.send(:"#{@method}_instance_methods", false).should.include?(:test1)
+ mod.send(:"#{@method}_instance_methods", false).should.include?(:test2)
end
it "stops setting visibility if the body encounters other visibility setters without arguments" do
@@ -29,7 +78,7 @@ describe :set_visibility, shared: true do
def test1() end
}
- mod.should send(:"have_#{new_visibility}_instance_method", :test1, false)
+ mod.send(:"#{new_visibility}_instance_methods", false).should.include?(:test1)
end
it "continues setting visibility if the body encounters other visibility setters with arguments" do
@@ -41,7 +90,7 @@ describe :set_visibility, shared: true do
def test2() end
}
- mod.should send(:"have_#{@method}_instance_method", :test2, false)
+ mod.send(:"#{@method}_instance_methods", false).should.include?(:test2)
end
it "does not affect module_evaled method definitions when itself is outside the eval" do
@@ -53,8 +102,8 @@ describe :set_visibility, shared: true do
module_eval " def test2() end "
}
- mod.should have_public_instance_method(:test1, false)
- mod.should have_public_instance_method(:test2, false)
+ mod.public_instance_methods(false).should.include?(:test1)
+ mod.public_instance_methods(false).should.include?(:test2)
end
it "does not affect outside method definitions when itself is inside a module_eval" do
@@ -65,7 +114,7 @@ describe :set_visibility, shared: true do
def test1() end
}
- mod.should have_public_instance_method(:test1, false)
+ mod.public_instance_methods(false).should.include?(:test1)
end
it "affects normally if itself and method definitions are inside a module_eval" do
@@ -78,7 +127,7 @@ describe :set_visibility, shared: true do
}
}
- mod.should send(:"have_#{@method}_instance_method", :test1, false)
+ mod.send(:"#{@method}_instance_methods", false).should.include?(:test1)
end
it "does not affect method definitions when itself is inside an eval and method definitions are outside" do
@@ -91,7 +140,7 @@ describe :set_visibility, shared: true do
def test1() end
}
- mod.should send(:"have_#{initialized_visibility}_instance_method", :test1, false)
+ mod.send(:"#{initialized_visibility}_instance_methods", false).should.include?(:test1)
end
it "affects evaled method definitions when itself is outside the eval" do
@@ -102,7 +151,7 @@ describe :set_visibility, shared: true do
eval "def test1() end"
}
- mod.should send(:"have_#{@method}_instance_method", :test1, false)
+ mod.send(:"#{@method}_instance_methods", false).should.include?(:test1)
end
it "affects normally if itself and following method definitions are inside a eval" do
@@ -115,7 +164,7 @@ describe :set_visibility, shared: true do
CODE
}
- mod.should send(:"have_#{@method}_instance_method", :test1, false)
+ mod.send(:"#{@method}_instance_methods", false).should.include?(:test1)
end
describe "within a closure" do
@@ -128,7 +177,7 @@ describe :set_visibility, shared: true do
def test1() end
}
- mod.should send(:"have_#{@method}_instance_method", :test1, false)
+ mod.send(:"#{@method}_instance_methods", false).should.include?(:test1)
end
end
end
diff --git a/spec/ruby/core/module/singleton_class_spec.rb b/spec/ruby/core/module/singleton_class_spec.rb
index 177dfc224f..052755b73b 100644
--- a/spec/ruby/core/module/singleton_class_spec.rb
+++ b/spec/ruby/core/module/singleton_class_spec.rb
@@ -1,27 +1,27 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Module#singleton_class?" do
it "returns true for singleton classes" do
xs = self.singleton_class
- xs.singleton_class?.should == true
+ xs.should.singleton_class?
end
it "returns false for other classes" do
c = Class.new
- c.singleton_class?.should == false
+ c.should_not.singleton_class?
end
describe "with singleton values" do
it "returns false for nil's singleton class" do
- NilClass.singleton_class?.should == false
+ NilClass.should_not.singleton_class?
end
it "returns false for true's singleton class" do
- TrueClass.singleton_class?.should == false
+ TrueClass.should_not.singleton_class?
end
it "returns false for false's singleton class" do
- FalseClass.singleton_class?.should == false
+ FalseClass.should_not.singleton_class?
end
end
end
diff --git a/spec/ruby/core/module/to_s_spec.rb b/spec/ruby/core/module/to_s_spec.rb
index de924a8739..83c0ae0825 100644
--- a/spec/ruby/core/module/to_s_spec.rb
+++ b/spec/ruby/core/module/to_s_spec.rb
@@ -1,18 +1,70 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Module#to_s" do
+ it 'returns the name of the module if it has a name' do
+ Enumerable.to_s.should == 'Enumerable'
+ String.to_s.should == 'String'
+ end
+
it "returns the full constant path leading to the module" do
ModuleSpecs::LookupMod.to_s.should == "ModuleSpecs::LookupMod"
end
it "works with an anonymous module" do
m = Module.new
- m.to_s.should =~ /#<Module:0x[0-9a-f]+>/
+ m.to_s.should =~ /\A#<Module:0x\h+>\z/
end
it "works with an anonymous class" do
c = Class.new
- c.to_s.should =~ /#<Class:0x[0-9a-f]+>/
+ c.to_s.should =~ /\A#<Class:0x\h+>\z/
+ end
+
+ it 'for the singleton class of an object of an anonymous class' do
+ klass = Class.new
+ obj = klass.new
+ sclass = obj.singleton_class
+ sclass.to_s.should == "#<Class:#{obj}>"
+ sclass.to_s.should =~ /\A#<Class:#<#{klass}:0x\h+>>\z/
+ sclass.to_s.should =~ /\A#<Class:#<#<Class:0x\h+>:0x\h+>>\z/
+ end
+
+ it 'for a singleton class of a module includes the module name' do
+ ModuleSpecs.singleton_class.to_s.should == '#<Class:ModuleSpecs>'
+ end
+
+ it 'for a metaclass includes the class name' do
+ ModuleSpecs::NamedClass.singleton_class.to_s.should == '#<Class:ModuleSpecs::NamedClass>'
+ end
+
+ it 'for objects includes class name and object ID' do
+ obj = ModuleSpecs::NamedClass.new
+ obj.singleton_class.to_s.should =~ /\A#<Class:#<ModuleSpecs::NamedClass:0x\h+>>\z/
+ end
+
+ it "always show the refinement name, even if the module is named" do
+ module ModuleSpecs::RefinementInspect
+ R = refine String do
+ end
+ end
+
+ ModuleSpecs::RefinementInspect::R.name.should == 'ModuleSpecs::RefinementInspect::R'
+ ModuleSpecs::RefinementInspect::R.to_s.should == '#<refinement:String@ModuleSpecs::RefinementInspect>'
+ ensure
+ ModuleSpecs.send(:remove_const, :RefinementInspect)
+ end
+
+ it 'does not call #inspect or #to_s for singleton classes' do
+ klass = Class.new
+ obj = klass.new
+ def obj.to_s
+ "to_s"
+ end
+ def obj.inspect
+ "inspect"
+ end
+ sclass = obj.singleton_class
+ sclass.to_s.should =~ /\A#<Class:#<#{Regexp.escape klass.to_s}:0x\h+>>\z/
end
end
diff --git a/spec/ruby/core/module/undef_method_spec.rb b/spec/ruby/core/module/undef_method_spec.rb
index 663ab2ffc8..d77640cb7e 100644
--- a/spec/ruby/core/module/undef_method_spec.rb
+++ b/spec/ruby/core/module/undef_method_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
module ModuleSpecs
class Parent
@@ -18,8 +18,8 @@ describe "Module#undef_method" do
@module = Module.new { def method_to_undef; end }
end
- it "is a private method" do
- Module.should have_private_instance_method(:undef_method, false)
+ it "is a public method" do
+ Module.public_instance_methods(false).should.include?(:undef_method)
end
it "requires multiple arguments" do
@@ -34,8 +34,8 @@ describe "Module#undef_method" do
x = klass.new
klass.send(:undef_method, :method_to_undef, :another_method_to_undef)
- lambda { x.method_to_undef }.should raise_error(NoMethodError)
- lambda { x.another_method_to_undef }.should raise_error(NoMethodError)
+ -> { x.method_to_undef }.should.raise(NoMethodError)
+ -> { x.another_method_to_undef }.should.raise(NoMethodError)
end
it "does not undef any instance methods when argument not given" do
@@ -46,11 +46,40 @@ describe "Module#undef_method" do
end
it "returns self" do
- @module.send(:undef_method, :method_to_undef).should equal(@module)
+ @module.send(:undef_method, :method_to_undef).should.equal?(@module)
end
- it "raises a NameError when passed a missing name" do
- lambda { @module.send :undef_method, :not_exist }.should raise_error(NameError) { |e|
+ it "raises a NameError when passed a missing name for a module" do
+ -> { @module.send :undef_method, :not_exist }.should.raise(NameError, /undefined method [`']not_exist' for module [`']#{@module}'/) { |e|
+ # a NameError and not a NoMethodError
+ e.class.should == NameError
+ }
+ end
+
+ it "raises a NameError when passed a missing name for a class" do
+ klass = Class.new
+ -> { klass.send :undef_method, :not_exist }.should.raise(NameError, /undefined method [`']not_exist' for class [`']#{klass}'/) { |e|
+ # a NameError and not a NoMethodError
+ e.class.should == NameError
+ }
+ end
+
+ it "raises a NameError when passed a missing name for a singleton class" do
+ klass = Class.new
+ obj = klass.new
+ sclass = obj.singleton_class
+
+ -> { sclass.send :undef_method, :not_exist }.should.raise(NameError, /undefined method [`']not_exist' for class [`']#{sclass}'/) { |e|
+ e.message.should =~ /[`']#<Class:#<#<Class:/
+
+ # a NameError and not a NoMethodError
+ e.class.should == NameError
+ }
+ end
+
+ it "raises a NameError when passed a missing name for a metaclass" do
+ klass = String.singleton_class
+ -> { klass.send :undef_method, :not_exist }.should.raise(NameError, /undefined method [`']not_exist' for class [`']String'/) { |e|
# a NameError and not a NoMethodError
e.class.should == NameError
}
@@ -61,20 +90,20 @@ describe "Module#undef_method" do
@frozen = @module.dup.freeze
end
- it "raises a RuntimeError when passed a name" do
- lambda { @frozen.send :undef_method, :method_to_undef }.should raise_error(RuntimeError)
+ it "raises a FrozenError when passed a name" do
+ -> { @frozen.send :undef_method, :method_to_undef }.should.raise(FrozenError)
end
- it "raises a RuntimeError when passed a missing name" do
- lambda { @frozen.send :undef_method, :not_exist }.should raise_error(RuntimeError)
+ it "raises a FrozenError when passed a missing name" do
+ -> { @frozen.send :undef_method, :not_exist }.should.raise(FrozenError)
end
it "raises a TypeError when passed a not name" do
- lambda { @frozen.send :undef_method, Object.new }.should raise_error(TypeError)
+ -> { @frozen.send :undef_method, Object.new }.should.raise(TypeError)
end
it "does not raise exceptions when no arguments given" do
- @frozen.send(:undef_method).should equal(@frozen)
+ @frozen.send(:undef_method).should.equal?(@frozen)
end
end
end
@@ -91,7 +120,7 @@ describe "Module#undef_method with symbol" do
klass.send :undef_method, :method_to_undef
- lambda { x.method_to_undef }.should raise_error(NoMethodError)
+ -> { x.method_to_undef }.should.raise(NoMethodError)
end
it "removes a method defined in a super class" do
@@ -101,7 +130,7 @@ describe "Module#undef_method with symbol" do
child_class.send :undef_method, :method_to_undef
- lambda { child.method_to_undef }.should raise_error(NoMethodError)
+ -> { child.method_to_undef }.should.raise(NoMethodError)
end
it "does not remove a method defined in a super class when removed from a subclass" do
@@ -127,7 +156,7 @@ describe "Module#undef_method with string" do
klass.send :undef_method, 'another_method_to_undef'
- lambda { x.another_method_to_undef }.should raise_error(NoMethodError)
+ -> { x.another_method_to_undef }.should.raise(NoMethodError)
end
it "removes a method defined in a super class" do
@@ -137,7 +166,7 @@ describe "Module#undef_method with string" do
child_class.send :undef_method, 'another_method_to_undef'
- lambda { child.another_method_to_undef }.should raise_error(NoMethodError)
+ -> { child.another_method_to_undef }.should.raise(NoMethodError)
end
it "does not remove a method defined in a super class when removed from a subclass" do
diff --git a/spec/ruby/core/module/undefined_instance_methods_spec.rb b/spec/ruby/core/module/undefined_instance_methods_spec.rb
new file mode 100644
index 0000000000..9f731c6adf
--- /dev/null
+++ b/spec/ruby/core/module/undefined_instance_methods_spec.rb
@@ -0,0 +1,25 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe "Module#undefined_instance_methods" do
+ it "returns methods undefined in the class" do
+ methods = ModuleSpecs::UndefinedInstanceMethods::Parent.undefined_instance_methods
+ methods.should == [:undefed_method]
+ end
+
+ it "returns inherited methods undefined in the class" do
+ methods = ModuleSpecs::UndefinedInstanceMethods::Child.undefined_instance_methods
+ methods.to_set.should >= Set[:parent_method, :another_parent_method]
+ end
+
+ it "returns methods from an included module that are undefined in the class" do
+ methods = ModuleSpecs::UndefinedInstanceMethods::Grandchild.undefined_instance_methods
+ methods.should.include?(:super_included_method)
+ end
+
+ it "does not returns ancestors undefined methods" do
+ methods = ModuleSpecs::UndefinedInstanceMethods::Grandchild.undefined_instance_methods
+ methods.should_not.include?(:parent_method)
+ methods.should_not.include?(:another_parent_method)
+ end
+end
diff --git a/spec/ruby/core/module/used_refinements_spec.rb b/spec/ruby/core/module/used_refinements_spec.rb
new file mode 100644
index 0000000000..40dd4a444e
--- /dev/null
+++ b/spec/ruby/core/module/used_refinements_spec.rb
@@ -0,0 +1,85 @@
+require_relative '../../spec_helper'
+
+describe "Module.used_refinements" do
+ it "returns list of all refinements imported in the current scope" do
+ refinement_int = nil
+ refinement_str = nil
+ ScratchPad.record []
+
+ m1 = Module.new do
+ refine Integer do
+ refinement_int = self
+ end
+ end
+
+ m2 = Module.new do
+ refine String do
+ refinement_str = self
+ end
+ end
+
+ Module.new do
+ using m1
+ using m2
+
+ Module.used_refinements.each { |r| ScratchPad << r }
+ end
+
+ ScratchPad.recorded.sort_by(&:object_id).should == [refinement_int, refinement_str].sort_by(&:object_id)
+ end
+
+ it "returns empty array if does not have any refinements imported" do
+ used_refinements = nil
+
+ Module.new do
+ used_refinements = Module.used_refinements
+ end
+
+ used_refinements.should == []
+ end
+
+ it "ignores refinements imported in a module that is included into the current one" do
+ used_refinements = nil
+
+ m1 = Module.new do
+ refine Integer do
+ nil
+ end
+ end
+
+ m2 = Module.new do
+ using m1
+ end
+
+ Module.new do
+ include m2
+
+ used_refinements = Module.used_refinements
+ end
+
+ used_refinements.should == []
+ end
+
+ it "returns refinements even not defined directly in a module refinements are imported from" do
+ used_refinements = nil
+ ScratchPad.record []
+
+ m1 = Module.new do
+ refine Integer do
+ ScratchPad << self
+ end
+ end
+
+ m2 = Module.new do
+ include m1
+ end
+
+ Module.new do
+ using m2
+
+ used_refinements = Module.used_refinements
+ end
+
+ used_refinements.should == ScratchPad.recorded
+ end
+end
diff --git a/spec/ruby/core/module/using_spec.rb b/spec/ruby/core/module/using_spec.rb
index 32e8f8f96b..cff0edef28 100644
--- a/spec/ruby/core/module/using_spec.rb
+++ b/spec/ruby/core/module/using_spec.rb
@@ -1,5 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/using', __FILE__)
+require_relative '../../spec_helper'
describe "Module#using" do
it "imports class refinements from module into the current class/module" do
@@ -25,39 +24,39 @@ describe "Module#using" do
end
end
- -> () {
+ -> {
Module.new do
using refinement
end
- }.should_not raise_error
+ }.should_not.raise
end
it "accepts module without refinements" do
mod = Module.new
- -> () {
+ -> {
Module.new do
using mod
end
- }.should_not raise_error
+ }.should_not.raise
end
it "does not accept class" do
klass = Class.new
- -> () {
+ -> {
Module.new do
using klass
end
- }.should raise_error(TypeError)
+ }.should.raise(TypeError)
end
it "raises TypeError if passed something other than module" do
- -> () {
+ -> {
Module.new do
using "foo"
end
- }.should raise_error(TypeError)
+ }.should.raise(TypeError)
end
it "returns self" do
@@ -68,7 +67,7 @@ describe "Module#using" do
result = using refinement
end
- result.should equal(mod)
+ result.should.equal?(mod)
end
it "works in classes too" do
@@ -90,13 +89,13 @@ describe "Module#using" do
it "raises error in method scope" do
mod = Module.new do
def self.foo
- using ModuleSpecs::EmptyRefinement
+ using Module.new {}
end
end
- -> () {
+ -> {
mod.foo
- }.should raise_error(RuntimeError, /Module#using is not permitted in methods/)
+ }.should.raise(RuntimeError, /Module#using is not permitted in methods/)
end
it "activates refinement even for existed objects" do
@@ -156,7 +155,11 @@ describe "Module#using" do
Module.new do
Class.new do
- using ModuleSpecs::RefinementForStringToS
+ using Module.new {
+ refine String do
+ def to_s; "hello from refinement"; end
+ end
+ }
ScratchPad << "1".to_s
end
@@ -175,7 +178,11 @@ describe "Module#using" do
Module.new do
Class.new do
ScratchPad << "1".to_s
- using ModuleSpecs::RefinementForStringToS
+ using Module.new {
+ refine String do
+ def to_s; "hello from refinement"; end
+ end
+ }
ScratchPad << "1".to_s
end
end
@@ -236,12 +243,106 @@ describe "Module#using" do
mod.call_foo(c).should == "foo from refinement"
end
+ it "is active for module defined via Module.new {}" do
+ refinement = Module.new do
+ refine Integer do
+ def foo; "foo from refinement"; end
+ end
+ end
+
+ result = nil
+
+ Module.new do
+ using refinement
+
+ Module.new do
+ result = 1.foo
+ end
+ end
+
+ result.should == "foo from refinement"
+ end
+
+ it "is active for class defined via Class.new {}" do
+ refinement = Module.new do
+ refine Integer do
+ def foo; "foo from refinement"; end
+ end
+ end
+
+ result = nil
+
+ Module.new do
+ using refinement
+
+ Class.new do
+ result = 1.foo
+ end
+ end
+
+ result.should == "foo from refinement"
+ end
+
+ it "is active for block called via instance_exec" do
+ refinement = Module.new do
+ refine Integer do
+ def foo; "foo from refinement"; end
+ end
+ end
+
+ c = Class.new do
+ using refinement
+
+ def abc
+ block = -> {
+ 1.foo
+ }
+
+ self.instance_exec(&block)
+ end
+ end
+
+ c.new.abc.should == "foo from refinement"
+ end
+
+ it "is active for block called via instance_eval" do
+ refinement = Module.new do
+ refine String do
+ def foo; "foo from refinement"; end
+ end
+ end
+
+ c = Class.new do
+ using refinement
+
+ def initialize
+ @a = +"1703"
+
+ @a.instance_eval do
+ def abc
+ "#{self}: #{self.foo}"
+ end
+ end
+ end
+
+ def abc
+ @a.abc
+ end
+ end
+
+ c.new.abc.should == "1703: foo from refinement"
+ end
+
it "is not active if `using` call is not evaluated" do
result = nil
Module.new do
if false
- using ModuleSpecs::RefinementForStringToS
+ using Module.new {
+ refine String do
+ def to_s; "hello from refinement"; end
+ end
+ }
end
result = "1".to_s
end
diff --git a/spec/ruby/core/mutex/lock_spec.rb b/spec/ruby/core/mutex/lock_spec.rb
index b5c2b168e8..4fee29091a 100644
--- a/spec/ruby/core/mutex/lock_spec.rb
+++ b/spec/ruby/core/mutex/lock_spec.rb
@@ -1,41 +1,92 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Mutex#lock" do
- before :each do
- ScratchPad.clear
- end
-
it "returns self" do
m = Mutex.new
m.lock.should == m
m.unlock
end
- it "waits if the lock is not available" do
+ it "blocks the caller if already locked" do
m = Mutex.new
-
m.lock
+ -> { m.lock }.should block_caller
+ end
- th = Thread.new do
- m.lock
- ScratchPad.record :after_lock
- end
-
- Thread.pass while th.status and th.status != "sleep"
-
- ScratchPad.recorded.should be_nil
- m.unlock
- th.join
- ScratchPad.recorded.should == :after_lock
+ it "does not block the caller if not locked" do
+ m = Mutex.new
+ -> { m.lock }.should_not block_caller
end
# Unable to find a specific ticket but behavior change may be
# related to this ML thread.
- it "raises a ThreadError when used recursively" do
+ it "raises a deadlock ThreadError when used recursively" do
m = Mutex.new
m.lock
-> {
m.lock
- }.should raise_error(ThreadError)
+ }.should.raise(ThreadError, /deadlock/)
+ end
+
+ it "raises a deadlock ThreadError when multiple fibers from the same thread try to lock" do
+ m = Mutex.new
+
+ m.lock
+ f0 = Fiber.new do
+ m.lock
+ end
+ -> { f0.resume }.should.raise(ThreadError, /deadlock/)
+
+ m.unlock
+ f1 = Fiber.new do
+ m.lock
+ Fiber.yield
+ end
+ f2 = Fiber.new do
+ m.lock
+ end
+ f1.resume
+ -> { f2.resume }.should.raise(ThreadError, /deadlock/)
+ end
+
+ it "does not raise deadlock if a fiber's attempt to lock was interrupted" do
+ lock = Mutex.new
+ main = Thread.current
+
+ t2 = nil
+ t1 = Thread.new do
+ loop do
+ # interrupt fiber below looping on synchronize
+ sleep 0.01
+ t2.raise if t2
+ end
+ end
+
+ # loop ten times to try to handle the interrupt during synchronize
+ t2 = Thread.new do
+ 10.times do
+ Fiber.new do
+ begin
+ loop { lock.synchronize {} }
+ rescue RuntimeError
+ end
+ end.resume
+
+ Fiber.new do
+ -> do
+ lock.synchronize {}
+ end.should_not.raise(ThreadError)
+ end.resume
+ rescue RuntimeError
+ retry
+ end
+ end
+ t2.join
+ ensure
+ t1.kill rescue nil
+ t2.kill rescue nil
+
+ t1.join
+ t2.join
end
end
diff --git a/spec/ruby/core/mutex/locked_spec.rb b/spec/ruby/core/mutex/locked_spec.rb
index 7b92534be4..1818cdb4f3 100644
--- a/spec/ruby/core/mutex/locked_spec.rb
+++ b/spec/ruby/core/mutex/locked_spec.rb
@@ -1,15 +1,15 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Mutex#locked?" do
it "returns true if locked" do
m = Mutex.new
m.lock
- m.locked?.should be_true
+ m.locked?.should == true
end
it "returns false if unlocked" do
m = Mutex.new
- m.locked?.should be_false
+ m.locked?.should == false
end
it "returns the status of the lock" do
@@ -27,10 +27,10 @@ describe "Mutex#locked?" do
Thread.pass until m1_locked
- m1.locked?.should be_true
+ m1.locked?.should == true
m2.unlock # release th
th.join
# A Thread releases its locks upon termination
- m1.locked?.should be_false
+ m1.locked?.should == false
end
end
diff --git a/spec/ruby/core/mutex/owned_spec.rb b/spec/ruby/core/mutex/owned_spec.rb
index 2e1c3f2481..ea7d5faf1c 100644
--- a/spec/ruby/core/mutex/owned_spec.rb
+++ b/spec/ruby/core/mutex/owned_spec.rb
@@ -1,10 +1,10 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Mutex#owned?" do
describe "when unlocked" do
it "returns false" do
m = Mutex.new
- m.owned?.should be_false
+ m.owned?.should == false
end
end
@@ -12,7 +12,7 @@ describe "Mutex#owned?" do
it "returns true" do
m = Mutex.new
m.lock
- m.owned?.should be_true
+ m.owned?.should == true
end
end
@@ -37,7 +37,17 @@ describe "Mutex#owned?" do
end
Thread.pass until locked
- m.owned?.should be_false
+ m.owned?.should == false
end
end
+
+ it "is held per Fiber" do
+ m = Mutex.new
+ m.lock
+
+ Fiber.new do
+ m.locked?.should == true
+ m.owned?.should == false
+ end.resume
+ end
end
diff --git a/spec/ruby/core/mutex/sleep_spec.rb b/spec/ruby/core/mutex/sleep_spec.rb
index a3fb86fba7..71b089d251 100644
--- a/spec/ruby/core/mutex/sleep_spec.rb
+++ b/spec/ruby/core/mutex/sleep_spec.rb
@@ -1,33 +1,35 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Mutex#sleep" do
describe "when not locked by the current thread" do
it "raises a ThreadError" do
m = Mutex.new
- lambda { m.sleep }.should raise_error(ThreadError)
+ -> { m.sleep }.should.raise(ThreadError)
end
it "raises an ArgumentError if passed a negative duration" do
m = Mutex.new
- lambda { m.sleep(-0.1) }.should raise_error(ArgumentError)
- lambda { m.sleep(-1) }.should raise_error(ArgumentError)
+ -> { m.sleep(-0.1) }.should.raise(ArgumentError)
+ -> { m.sleep(-1) }.should.raise(ArgumentError)
end
end
it "raises an ArgumentError if passed a negative duration" do
m = Mutex.new
m.lock
- lambda { m.sleep(-0.1) }.should raise_error(ArgumentError)
- lambda { m.sleep(-1) }.should raise_error(ArgumentError)
+ -> { m.sleep(-0.1) }.should.raise(ArgumentError)
+ -> { m.sleep(-1) }.should.raise(ArgumentError)
end
it "pauses execution for approximately the duration requested" do
m = Mutex.new
m.lock
- duration = 0.1
- start = Time.now
+ duration = 0.001
+ start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
m.sleep duration
- (Time.now - start).should be_close(duration, 0.2)
+ now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
+ (now - start).should >= 0
+ (now - start).should < (duration + TIME_TOLERANCE)
end
it "unlocks the mutex while sleeping" do
@@ -35,8 +37,8 @@ describe "Mutex#sleep" do
locked = false
th = Thread.new { m.lock; locked = true; m.sleep }
Thread.pass until locked
- Thread.pass while th.status and th.status != "sleep"
- m.locked?.should be_false
+ Thread.pass until th.stop?
+ m.locked?.should == false
th.run
th.join
end
@@ -44,8 +46,8 @@ describe "Mutex#sleep" do
it "relocks the mutex when woken" do
m = Mutex.new
m.lock
- m.sleep(0.01)
- m.locked?.should be_true
+ m.sleep(0.001)
+ m.locked?.should == true
end
it "relocks the mutex when woken by an exception being raised" do
@@ -61,14 +63,49 @@ describe "Mutex#sleep" do
end
end
Thread.pass until locked
- Thread.pass while th.status and th.status != "sleep"
+ Thread.pass until th.stop?
th.raise(Exception)
- th.value.should be_true
+ th.value.should == true
end
it "returns the rounded number of seconds asleep" do
m = Mutex.new
+ locked = false
+ th = Thread.start do
+ m.lock
+ locked = true
+ m.sleep
+ end
+ Thread.pass until locked
+ Thread.pass until th.stop?
+ th.wakeup
+ th.value.should.is_a?(Integer)
+ end
+
+ it "accepts nil as a sleep duration" do
+ m = Mutex.new
+ -> {
+ m.lock
+ m.sleep(nil)
+ }.should block_caller
+ end
+
+ it "wakes up when requesting sleep times near or equal to zero" do
+ times = []
+ val = 1
+
+ # power of two divisor so we eventually get near zero
+ loop do
+ val = val / 16.0
+ times << val
+ break if val == 0.0
+ end
+
+ m = Mutex.new
m.lock
- m.sleep(0.01).should be_kind_of(Integer)
+ times.each do |time|
+ # just testing that sleep completes
+ -> {m.sleep(time)}.should_not.raise
+ end
end
end
diff --git a/spec/ruby/core/mutex/synchronize_spec.rb b/spec/ruby/core/mutex/synchronize_spec.rb
index ec64aa60fa..823f29a634 100644
--- a/spec/ruby/core/mutex/synchronize_spec.rb
+++ b/spec/ruby/core/mutex/synchronize_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Mutex#synchronize" do
it "wraps the lock/unlock pair in an ensure" do
@@ -8,20 +8,59 @@ describe "Mutex#synchronize" do
synchronized = false
th = Thread.new do
- lambda do
+ -> do
m1.synchronize do
synchronized = true
m2.lock
raise Exception
end
- end.should raise_error(Exception)
+ end.should.raise(Exception)
end
Thread.pass until synchronized
- m1.locked?.should be_true
+ m1.locked?.should == true
m2.unlock
th.join
- m1.locked?.should be_false
+ m1.locked?.should == false
+ end
+
+ it "blocks the caller if already locked" do
+ m = Mutex.new
+ m.lock
+ -> { m.synchronize { } }.should block_caller
+ end
+
+ it "does not block the caller if not locked" do
+ m = Mutex.new
+ -> { m.synchronize { } }.should_not block_caller
+ end
+
+ it "blocks the caller if another thread is also in the synchronize block" do
+ m = Mutex.new
+ q1 = Queue.new
+ q2 = Queue.new
+
+ t = Thread.new {
+ m.synchronize {
+ q1.push :ready
+ q2.pop
+ }
+ }
+
+ q1.pop.should == :ready
+
+ -> { m.synchronize { } }.should block_caller
+
+ q2.push :done
+ t.join
+ end
+
+ it "is not recursive" do
+ m = Mutex.new
+
+ m.synchronize do
+ -> { m.synchronize { } }.should.raise(ThreadError)
+ end
end
end
diff --git a/spec/ruby/core/mutex/try_lock_spec.rb b/spec/ruby/core/mutex/try_lock_spec.rb
index 3e875ff9ec..1da0735d6a 100644
--- a/spec/ruby/core/mutex/try_lock_spec.rb
+++ b/spec/ruby/core/mutex/try_lock_spec.rb
@@ -1,16 +1,16 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Mutex#try_lock" do
describe "when unlocked" do
it "returns true" do
m = Mutex.new
- m.try_lock.should be_true
+ m.try_lock.should == true
end
it "locks the mutex" do
m = Mutex.new
m.try_lock
- m.locked?.should be_true
+ m.locked?.should == true
end
end
@@ -18,7 +18,7 @@ describe "Mutex#try_lock" do
it "returns false" do
m = Mutex.new
m.lock
- m.try_lock.should be_false
+ m.try_lock.should == false
end
end
@@ -26,7 +26,7 @@ describe "Mutex#try_lock" do
it "returns false" do
m = Mutex.new
m.lock
- Thread.new { m.try_lock }.value.should be_false
+ Thread.new { m.try_lock }.value.should == false
end
end
end
diff --git a/spec/ruby/core/mutex/unlock_spec.rb b/spec/ruby/core/mutex/unlock_spec.rb
index 4601fde634..ed493cf84a 100644
--- a/spec/ruby/core/mutex/unlock_spec.rb
+++ b/spec/ruby/core/mutex/unlock_spec.rb
@@ -1,9 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Mutex#unlock" do
it "raises ThreadError unless Mutex is locked" do
mutex = Mutex.new
- lambda { mutex.unlock }.should raise_error(ThreadError)
+ -> { mutex.unlock }.should.raise(ThreadError)
end
it "raises ThreadError unless thread owns Mutex" do
@@ -17,9 +17,9 @@ describe "Mutex#unlock" do
# avoid race on mutex.lock
Thread.pass until mutex.locked?
- Thread.pass while th.status and th.status != "sleep"
+ Thread.pass until th.stop?
- lambda { mutex.unlock }.should raise_error(ThreadError)
+ -> { mutex.unlock }.should.raise(ThreadError)
wait.unlock
th.join
@@ -33,6 +33,6 @@ describe "Mutex#unlock" do
th.join
- lambda { mutex.unlock }.should raise_error(ThreadError)
+ -> { mutex.unlock }.should.raise(ThreadError)
end
end
diff --git a/spec/ruby/core/nil/and_spec.rb b/spec/ruby/core/nil/and_spec.rb
index 96e0472661..cd25aff1de 100644
--- a/spec/ruby/core/nil/and_spec.rb
+++ b/spec/ruby/core/nil/and_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "NilClass#&" do
it "returns false" do
diff --git a/spec/ruby/core/nil/case_compare_spec.rb b/spec/ruby/core/nil/case_compare_spec.rb
new file mode 100644
index 0000000000..142560c6f5
--- /dev/null
+++ b/spec/ruby/core/nil/case_compare_spec.rb
@@ -0,0 +1,13 @@
+require_relative '../../spec_helper'
+
+describe "NilClass#===" do
+ it "returns true for nil" do
+ (nil === nil).should == true
+ end
+
+ it "returns false for non-nil object" do
+ (nil === 1).should == false
+ (nil === "").should == false
+ (nil === Object).should == false
+ end
+end
diff --git a/spec/ruby/core/nil/dup_spec.rb b/spec/ruby/core/nil/dup_spec.rb
index 10b1209736..e0be9540a6 100644
--- a/spec/ruby/core/nil/dup_spec.rb
+++ b/spec/ruby/core/nil/dup_spec.rb
@@ -1,9 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
-ruby_version_is '2.4' do
- describe "NilClass#dup" do
- it "returns self" do
- nil.dup.should equal(nil)
- end
+describe "NilClass#dup" do
+ it "returns self" do
+ nil.dup.should.equal?(nil)
end
end
diff --git a/spec/ruby/core/nil/inspect_spec.rb b/spec/ruby/core/nil/inspect_spec.rb
index f7a5e7d1af..1babc3d062 100644
--- a/spec/ruby/core/nil/inspect_spec.rb
+++ b/spec/ruby/core/nil/inspect_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "NilClass#inspect" do
it "returns the string 'nil'" do
diff --git a/spec/ruby/core/nil/match_spec.rb b/spec/ruby/core/nil/match_spec.rb
new file mode 100644
index 0000000000..27ebc53c3d
--- /dev/null
+++ b/spec/ruby/core/nil/match_spec.rb
@@ -0,0 +1,21 @@
+require_relative '../../spec_helper'
+
+describe "NilClass#=~" do
+ it "returns nil matching any object" do
+ o = nil
+
+ suppress_warning do
+ (o =~ /Object/).should == nil
+ (o =~ 'Object').should == nil
+ (o =~ Object).should == nil
+ (o =~ Object.new).should == nil
+ (o =~ nil).should == nil
+ (o =~ false).should == nil
+ (o =~ true).should == nil
+ end
+ end
+
+ it "should not warn" do
+ -> { nil =~ /a/ }.should_not complain(verbose: true)
+ end
+end
diff --git a/spec/ruby/core/nil/nil_spec.rb b/spec/ruby/core/nil/nil_spec.rb
index 8369b21a66..2cf97621c6 100644
--- a/spec/ruby/core/nil/nil_spec.rb
+++ b/spec/ruby/core/nil/nil_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "NilClass#nil?" do
it "returns true" do
- nil.nil?.should == true
+ nil.should.nil?
end
end
diff --git a/spec/ruby/core/nil/nilclass_spec.rb b/spec/ruby/core/nil/nilclass_spec.rb
index 3f28cde0bd..55c5d0eba7 100644
--- a/spec/ruby/core/nil/nilclass_spec.rb
+++ b/spec/ruby/core/nil/nilclass_spec.rb
@@ -1,15 +1,15 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "NilClass" do
it ".allocate raises a TypeError" do
- lambda do
+ -> do
NilClass.allocate
- end.should raise_error(TypeError)
+ end.should.raise(TypeError)
end
it ".new is undefined" do
- lambda do
+ -> do
NilClass.new
- end.should raise_error(NoMethodError)
+ end.should.raise(NoMethodError)
end
end
diff --git a/spec/ruby/core/nil/or_spec.rb b/spec/ruby/core/nil/or_spec.rb
index 2c5811b8c2..473a833d71 100644
--- a/spec/ruby/core/nil/or_spec.rb
+++ b/spec/ruby/core/nil/or_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "NilClass#|" do
it "returns false if other is nil or false, otherwise true" do
diff --git a/spec/ruby/core/nil/rationalize_spec.rb b/spec/ruby/core/nil/rationalize_spec.rb
index 1292cfd250..69fb257a7f 100644
--- a/spec/ruby/core/nil/rationalize_spec.rb
+++ b/spec/ruby/core/nil/rationalize_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "NilClass#rationalize" do
it "returns 0/1" do
@@ -10,7 +10,7 @@ describe "NilClass#rationalize" do
end
it "raises ArgumentError when passed more than one argument" do
- lambda { nil.rationalize(0.1, 0.1) }.should raise_error(ArgumentError)
- lambda { nil.rationalize(0.1, 0.1, 2) }.should raise_error(ArgumentError)
+ -> { nil.rationalize(0.1, 0.1) }.should.raise(ArgumentError)
+ -> { nil.rationalize(0.1, 0.1, 2) }.should.raise(ArgumentError)
end
end
diff --git a/spec/ruby/core/nil/singleton_method_spec.rb b/spec/ruby/core/nil/singleton_method_spec.rb
new file mode 100644
index 0000000000..f121b42f81
--- /dev/null
+++ b/spec/ruby/core/nil/singleton_method_spec.rb
@@ -0,0 +1,13 @@
+require_relative '../../spec_helper'
+
+describe "NilClass#singleton_method" do
+ it "raises regardless of whether NilClass defines the method" do
+ -> { nil.singleton_method(:foo) }.should.raise(NameError)
+ begin
+ def (nil).foo; end
+ -> { nil.singleton_method(:foo) }.should.raise(NameError)
+ ensure
+ NilClass.send(:remove_method, :foo)
+ end
+ end
+end
diff --git a/spec/ruby/core/nil/to_a_spec.rb b/spec/ruby/core/nil/to_a_spec.rb
index 6febd88c40..b8b339e330 100644
--- a/spec/ruby/core/nil/to_a_spec.rb
+++ b/spec/ruby/core/nil/to_a_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "NilClass#to_a" do
it "returns an empty array" do
diff --git a/spec/ruby/core/nil/to_c_spec.rb b/spec/ruby/core/nil/to_c_spec.rb
index 5b768b4afc..f449ddb6a3 100644
--- a/spec/ruby/core/nil/to_c_spec.rb
+++ b/spec/ruby/core/nil/to_c_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "NilClass#to_c" do
it "returns Complex(0, 0)" do
- nil.to_c.should eql(Complex(0, 0))
+ nil.to_c.should.eql?(Complex(0, 0))
end
end
diff --git a/spec/ruby/core/nil/to_f_spec.rb b/spec/ruby/core/nil/to_f_spec.rb
index d4890cd42b..a5f24ba3bf 100644
--- a/spec/ruby/core/nil/to_f_spec.rb
+++ b/spec/ruby/core/nil/to_f_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "NilClass#to_f" do
it "returns 0.0" do
diff --git a/spec/ruby/core/nil/to_h_spec.rb b/spec/ruby/core/nil/to_h_spec.rb
index 5300802d19..5c8d5dc25a 100644
--- a/spec/ruby/core/nil/to_h_spec.rb
+++ b/spec/ruby/core/nil/to_h_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "NilClass#to_h" do
it "returns an empty hash" do
diff --git a/spec/ruby/core/nil/to_i_spec.rb b/spec/ruby/core/nil/to_i_spec.rb
index 91282822a8..d3d088e999 100644
--- a/spec/ruby/core/nil/to_i_spec.rb
+++ b/spec/ruby/core/nil/to_i_spec.rb
@@ -1,11 +1,11 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "NilClass#to_i" do
it "returns 0" do
nil.to_i.should == 0
end
- it "does not cause NilClass to be coerced to Fixnum" do
+ it "does not cause NilClass to be coerced to Integer" do
(0 == nil).should == false
end
end
diff --git a/spec/ruby/core/nil/to_r_spec.rb b/spec/ruby/core/nil/to_r_spec.rb
index efbd2f5540..8be43baf00 100644
--- a/spec/ruby/core/nil/to_r_spec.rb
+++ b/spec/ruby/core/nil/to_r_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "NilClass#to_r" do
it "returns 0/1" do
diff --git a/spec/ruby/core/nil/to_s_spec.rb b/spec/ruby/core/nil/to_s_spec.rb
index 935bb63a9b..016ba4165a 100644
--- a/spec/ruby/core/nil/to_s_spec.rb
+++ b/spec/ruby/core/nil/to_s_spec.rb
@@ -1,7 +1,15 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "NilClass#to_s" do
it "returns the string ''" do
nil.to_s.should == ""
end
+
+ it "returns a frozen string" do
+ nil.to_s.should.frozen?
+ end
+
+ it "always returns the same string" do
+ nil.to_s.should.equal?(nil.to_s)
+ end
end
diff --git a/spec/ruby/core/nil/xor_spec.rb b/spec/ruby/core/nil/xor_spec.rb
index 7f2131e795..31ce33e971 100644
--- a/spec/ruby/core/nil/xor_spec.rb
+++ b/spec/ruby/core/nil/xor_spec.rb
@@ -1,11 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "NilClass#^" do
- it "returns false if other is nil or false, otherwise true" do
- (nil ^ nil).should == false
- (nil ^ true).should == true
- (nil ^ false).should == false
- (nil ^ "").should == true
- (nil ^ mock('x')).should == true
+ it "is an alias of NilClass#|" do
+ nil.method(:^).should == nil.method(:|)
end
end
diff --git a/spec/ruby/core/numeric/abs2_spec.rb b/spec/ruby/core/numeric/abs2_spec.rb
index f1094845fb..12866f9c47 100644
--- a/spec/ruby/core/numeric/abs2_spec.rb
+++ b/spec/ruby/core/numeric/abs2_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Numeric#abs2" do
before :each do
@@ -18,7 +18,7 @@ describe "Numeric#abs2" do
it "returns the square of the absolute value of self" do
@numbers.each do |number|
- number.abs2.should eql(number.abs ** 2)
+ number.abs2.should.eql?(number.abs ** 2)
end
end
@@ -29,6 +29,6 @@ describe "Numeric#abs2" do
end
it "returns NaN when self is NaN" do
- nan_value.abs2.nan?.should be_true
+ nan_value.abs2.nan?.should == true
end
end
diff --git a/spec/ruby/core/numeric/abs_spec.rb b/spec/ruby/core/numeric/abs_spec.rb
index 4aa25359a2..4b16e06c97 100644
--- a/spec/ruby/core/numeric/abs_spec.rb
+++ b/spec/ruby/core/numeric/abs_spec.rb
@@ -1,5 +1,19 @@
-require File.expand_path('../shared/abs', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Numeric#abs" do
- it_behaves_like(:numeric_abs, :abs)
+ before :each do
+ @obj = NumericSpecs::Subclass.new
+ end
+
+ it "returns self when self is greater than 0" do
+ @obj.should_receive(:<).with(0).and_return(false)
+ @obj.abs.should == @obj
+ end
+
+ it "returns self\#@- when self is less than 0" do
+ @obj.should_receive(:<).with(0).and_return(true)
+ @obj.should_receive(:-@).and_return(:absolute_value)
+ @obj.abs.should == :absolute_value
+ end
end
diff --git a/spec/ruby/core/numeric/angle_spec.rb b/spec/ruby/core/numeric/angle_spec.rb
index d7134168b3..25d2834a52 100644
--- a/spec/ruby/core/numeric/angle_spec.rb
+++ b/spec/ruby/core/numeric/angle_spec.rb
@@ -1,6 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/complex/numeric/arg', __FILE__)
+require_relative '../../spec_helper'
describe "Numeric#angle" do
- it_behaves_like(:numeric_arg, :angle)
+ it "is an alias of Numeric#arg" do
+ Numeric.instance_method(:angle).should == Numeric.instance_method(:arg)
+ end
end
diff --git a/spec/ruby/core/numeric/arg_spec.rb b/spec/ruby/core/numeric/arg_spec.rb
index 0729a29226..4fd059d7fc 100644
--- a/spec/ruby/core/numeric/arg_spec.rb
+++ b/spec/ruby/core/numeric/arg_spec.rb
@@ -1,6 +1,38 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/complex/numeric/arg', __FILE__)
+require_relative '../../spec_helper'
describe "Numeric#arg" do
- it_behaves_like(:numeric_arg, :arg)
+ before :each do
+ @numbers = [
+ 20,
+ Rational(3, 4),
+ bignum_value,
+ infinity_value
+ ]
+ end
+
+ it "returns 0 if positive" do
+ @numbers.each do |number|
+ number.arg.should == 0
+ end
+ end
+
+ it "returns Pi if negative" do
+ @numbers.each do |number|
+ (0-number).arg.should == Math::PI
+ end
+ end
+
+ describe "with a Numeric subclass" do
+ it "returns 0 if self#<(0) returns false" do
+ numeric = mock_numeric('positive')
+ numeric.should_receive(:<).with(0).and_return(false)
+ numeric.arg.should == 0
+ end
+
+ it "returns Pi if self#<(0) returns true" do
+ numeric = mock_numeric('positive')
+ numeric.should_receive(:<).with(0).and_return(true)
+ numeric.arg.should == Math::PI
+ end
+ end
end
diff --git a/spec/ruby/core/numeric/ceil_spec.rb b/spec/ruby/core/numeric/ceil_spec.rb
index 6e7d8211fb..00c856e79b 100644
--- a/spec/ruby/core/numeric/ceil_spec.rb
+++ b/spec/ruby/core/numeric/ceil_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Numeric#ceil" do
it "converts self to a Float (using #to_f) and returns the #ceil'ed result" do
diff --git a/spec/ruby/core/numeric/clone_spec.rb b/spec/ruby/core/numeric/clone_spec.rb
new file mode 100644
index 0000000000..1d06fdb050
--- /dev/null
+++ b/spec/ruby/core/numeric/clone_spec.rb
@@ -0,0 +1,30 @@
+require_relative '../../spec_helper'
+
+describe "Numeric#clone" do
+ it "returns self" do
+ value = 1
+ value.clone.should.equal?(value)
+
+ subclass = Class.new(Numeric)
+ value = subclass.new
+ value.clone.should.equal?(value)
+ end
+
+ it "does not change frozen status" do
+ 1.clone.frozen?.should == true
+ end
+
+ it "accepts optional keyword argument :freeze" do
+ value = 1
+ value.clone(freeze: true).should.equal?(value)
+ end
+
+ it "raises ArgumentError if passed freeze: false" do
+ -> { 1.clone(freeze: false) }.should.raise(ArgumentError, /can't unfreeze/)
+ end
+
+ it "does not change frozen status if passed freeze: nil" do
+ value = 1
+ value.clone(freeze: nil).should.equal?(value)
+ end
+end
diff --git a/spec/ruby/core/numeric/coerce_spec.rb b/spec/ruby/core/numeric/coerce_spec.rb
index 820d900dd5..9344d99ee6 100644
--- a/spec/ruby/core/numeric/coerce_spec.rb
+++ b/spec/ruby/core/numeric/coerce_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Numeric#coerce" do
before :each do
@@ -25,52 +25,35 @@ describe "Numeric#coerce" do
class << a; true; end
# watch it explode
- lambda { a.coerce(b) }.should raise_error(TypeError)
+ -> { a.coerce(b) }.should.raise(TypeError)
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")
+ -> { @obj.coerce(other) }.should.raise(TypeError)
end
it "raises a TypeError when passed nil" do
- lambda { @obj.coerce(nil) }.should raise_error(TypeError)
+ -> { @obj.coerce(nil) }.should.raise(TypeError)
end
it "raises a TypeError when passed a boolean" do
- lambda { @obj.coerce(false) }.should raise_error(TypeError)
+ -> { @obj.coerce(false) }.should.raise(TypeError)
end
it "raises a TypeError when passed a Symbol" do
- lambda { @obj.coerce(:symbol) }.should raise_error(TypeError)
+ -> { @obj.coerce(:symbol) }.should.raise(TypeError)
end
- it "raises an ArgumentError when passed a String" do
- lambda { @obj.coerce("test") }.should raise_error(ArgumentError)
+ it "raises an ArgumentError when passed a non-numeric String" do
+ -> { @obj.coerce("test") }.should.raise(ArgumentError)
end
end
diff --git a/spec/ruby/core/numeric/comparison_spec.rb b/spec/ruby/core/numeric/comparison_spec.rb
index 59676c01ad..b0a9390cc0 100644
--- a/spec/ruby/core/numeric/comparison_spec.rb
+++ b/spec/ruby/core/numeric/comparison_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Numeric#<=>" do
before :each do
@@ -26,22 +26,22 @@ describe "Numeric#<=>" do
end
it "is called when instances are compared with #<" do
- (@a < @b).should be_false
+ (@a < @b).should == false
ScratchPad.recorded.should == :numeric_comparison
end
it "is called when instances are compared with #<=" do
- (@a <= @b).should be_false
+ (@a <= @b).should == false
ScratchPad.recorded.should == :numeric_comparison
end
it "is called when instances are compared with #>" do
- (@a > @b).should be_true
+ (@a > @b).should == true
ScratchPad.recorded.should == :numeric_comparison
end
it "is called when instances are compared with #>=" do
- (@a >= @b).should be_true
+ (@a >= @b).should == true
ScratchPad.recorded.should == :numeric_comparison
end
end
diff --git a/spec/ruby/core/numeric/conj_spec.rb b/spec/ruby/core/numeric/conj_spec.rb
index 8fa0fd9457..f376a0d4b1 100644
--- a/spec/ruby/core/numeric/conj_spec.rb
+++ b/spec/ruby/core/numeric/conj_spec.rb
@@ -1,6 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/complex/numeric/conj', __FILE__)
+require_relative '../../spec_helper'
describe "Numeric#conj" do
- it_behaves_like(:numeric_conj, :conj)
+ it "is an alias of Numeric#conjugate" do
+ Numeric.instance_method(:conj).should == Numeric.instance_method(:conjugate)
+ end
end
diff --git a/spec/ruby/core/numeric/conjugate_spec.rb b/spec/ruby/core/numeric/conjugate_spec.rb
index f7e095514e..ea4731991d 100644
--- a/spec/ruby/core/numeric/conjugate_spec.rb
+++ b/spec/ruby/core/numeric/conjugate_spec.rb
@@ -1,6 +1,20 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/complex/numeric/conj', __FILE__)
+require_relative '../../spec_helper'
describe "Numeric#conjugate" do
- it_behaves_like(:numeric_conj, :conjugate)
+ before :each do
+ @numbers = [
+ 20, # Integer
+ 398.72, # Float
+ Rational(3, 4), # Rational
+ bignum_value,
+ infinity_value,
+ nan_value
+ ]
+ end
+
+ it "returns self" do
+ @numbers.each do |number|
+ number.conjugate.should.equal?(number)
+ end
+ end
end
diff --git a/spec/ruby/core/numeric/denominator_spec.rb b/spec/ruby/core/numeric/denominator_spec.rb
index 3ae4530c18..34729446a2 100644
--- a/spec/ruby/core/numeric/denominator_spec.rb
+++ b/spec/ruby/core/numeric/denominator_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Numeric#denominator" do
# The Numeric child classes override this method, so their behaviour is
diff --git a/spec/ruby/core/numeric/div_spec.rb b/spec/ruby/core/numeric/div_spec.rb
index f3f82c3ca4..a17961850c 100644
--- a/spec/ruby/core/numeric/div_spec.rb
+++ b/spec/ruby/core/numeric/div_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Numeric#div" do
before :each do
@@ -15,8 +15,8 @@ describe "Numeric#div" do
end
it "raises ZeroDivisionError for 0" do
- lambda { @obj.div(0) }.should raise_error(ZeroDivisionError)
- lambda { @obj.div(0.0) }.should raise_error(ZeroDivisionError)
- lambda { @obj.div(Complex(0,0)) }.should raise_error(ZeroDivisionError)
+ -> { @obj.div(0) }.should.raise(ZeroDivisionError)
+ -> { @obj.div(0.0) }.should.raise(ZeroDivisionError)
+ -> { @obj.div(Complex(0,0)) }.should.raise(ZeroDivisionError)
end
end
diff --git a/spec/ruby/core/numeric/divmod_spec.rb b/spec/ruby/core/numeric/divmod_spec.rb
index 5de2d86c77..8d5259bbcd 100644
--- a/spec/ruby/core/numeric/divmod_spec.rb
+++ b/spec/ruby/core/numeric/divmod_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Numeric#divmod" do
before :each do
diff --git a/spec/ruby/core/numeric/dup_spec.rb b/spec/ruby/core/numeric/dup_spec.rb
new file mode 100644
index 0000000000..c158c618de
--- /dev/null
+++ b/spec/ruby/core/numeric/dup_spec.rb
@@ -0,0 +1,16 @@
+require_relative '../../spec_helper'
+
+describe "Numeric#dup" do
+ it "returns self" do
+ value = 1
+ value.dup.should.equal?(value)
+
+ subclass = Class.new(Numeric)
+ value = subclass.new
+ value.dup.should.equal?(value)
+ end
+
+ it "does not change frozen status" do
+ 1.dup.frozen?.should == true
+ end
+end
diff --git a/spec/ruby/core/numeric/eql_spec.rb b/spec/ruby/core/numeric/eql_spec.rb
index 367a298a74..80c58caef4 100644
--- a/spec/ruby/core/numeric/eql_spec.rb
+++ b/spec/ruby/core/numeric/eql_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Numeric#eql?" do
before :each do
@@ -7,16 +7,16 @@ describe "Numeric#eql?" do
end
it "returns false if self's and other's types don't match" do
- @obj.should_not eql(1)
- @obj.should_not eql(-1.5)
- @obj.should_not eql(bignum_value)
- @obj.should_not eql(:sym)
+ @obj.should_not.eql?(1)
+ @obj.should_not.eql?(-1.5)
+ @obj.should_not.eql?(bignum_value)
+ @obj.should_not.eql?(:sym)
end
it "returns the result of calling self#== with other when self's and other's types match" do
other = NumericSpecs::Subclass.new
@obj.should_receive(:==).with(other).and_return("result", nil)
- @obj.should eql(other)
- @obj.should_not eql(other)
+ @obj.should.eql?(other)
+ @obj.should_not.eql?(other)
end
end
diff --git a/spec/ruby/core/numeric/fdiv_spec.rb b/spec/ruby/core/numeric/fdiv_spec.rb
index 4b27382012..2c22c6a86a 100644
--- a/spec/ruby/core/numeric/fdiv_spec.rb
+++ b/spec/ruby/core/numeric/fdiv_spec.rb
@@ -1,5 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/quo', __FILE__)
+require_relative '../../spec_helper'
describe "Numeric#fdiv" do
it "coerces self with #to_f" do
@@ -19,7 +18,7 @@ describe "Numeric#fdiv" do
end
it "returns a Float" do
- bignum_value.fdiv(Float::MAX).should be_an_instance_of(Float)
+ bignum_value.fdiv(Float::MAX).should.instance_of?(Float)
end
it "returns Infinity if other is 0" do
@@ -27,6 +26,6 @@ describe "Numeric#fdiv" do
end
it "returns NaN if other is NaN" do
- 3334.fdiv(nan_value).nan?.should be_true
+ 3334.fdiv(nan_value).nan?.should == true
end
end
diff --git a/spec/ruby/core/numeric/finite_spec.rb b/spec/ruby/core/numeric/finite_spec.rb
index 9fb2252845..2c18c89466 100644
--- a/spec/ruby/core/numeric/finite_spec.rb
+++ b/spec/ruby/core/numeric/finite_spec.rb
@@ -1,10 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
-ruby_version_is "2.4" do
- describe "Numeric#finite?" do
- it "returns true by default" do
- o = mock_numeric("finite")
- o.finite?.should be_true
- end
+describe "Numeric#finite?" do
+ it "returns true by default" do
+ o = mock_numeric("finite")
+ o.finite?.should == true
end
end
diff --git a/spec/ruby/core/numeric/floor_spec.rb b/spec/ruby/core/numeric/floor_spec.rb
index c68ed0423a..80a4868e4d 100644
--- a/spec/ruby/core/numeric/floor_spec.rb
+++ b/spec/ruby/core/numeric/floor_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Numeric#floor" do
before :each do
diff --git a/spec/ruby/core/numeric/i_spec.rb b/spec/ruby/core/numeric/i_spec.rb
index fae4fefe3d..f5fb99dfd3 100644
--- a/spec/ruby/core/numeric/i_spec.rb
+++ b/spec/ruby/core/numeric/i_spec.rb
@@ -1,8 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Numeric#i" do
it "returns a Complex object" do
- 34.i.should be_an_instance_of(Complex)
+ 34.i.should.instance_of?(Complex)
end
it "sets the real part to 0" do
diff --git a/spec/ruby/core/numeric/imag_spec.rb b/spec/ruby/core/numeric/imag_spec.rb
index a80e42d265..761d6b0dbe 100644
--- a/spec/ruby/core/numeric/imag_spec.rb
+++ b/spec/ruby/core/numeric/imag_spec.rb
@@ -1,6 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/complex/numeric/imag', __FILE__)
+require_relative '../../spec_helper'
describe "Numeric#imag" do
- it_behaves_like(:numeric_imag, :imag)
+ it "is an alias of Numeric#imaginary" do
+ Numeric.instance_method(:imag).should == Numeric.instance_method(:imaginary)
+ end
end
diff --git a/spec/ruby/core/numeric/imaginary_spec.rb b/spec/ruby/core/numeric/imaginary_spec.rb
index 41226569b3..7b5d94cc75 100644
--- a/spec/ruby/core/numeric/imaginary_spec.rb
+++ b/spec/ruby/core/numeric/imaginary_spec.rb
@@ -1,6 +1,26 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/complex/numeric/imag', __FILE__)
+require_relative '../../spec_helper'
describe "Numeric#imaginary" do
- it_behaves_like(:numeric_imag, :imaginary)
+ before :each do
+ @numbers = [
+ 20, # Integer
+ 398.72, # Float
+ Rational(3, 4), # Rational
+ bignum_value, # Bignum
+ infinity_value,
+ nan_value
+ ].map{|n| [n,-n]}.flatten
+ end
+
+ it "returns 0" do
+ @numbers.each do |number|
+ number.imaginary.should == 0
+ end
+ end
+
+ it "raises an ArgumentError if given any arguments" do
+ @numbers.each do |number|
+ -> { number.imaginary(number) }.should.raise(ArgumentError)
+ end
+ end
end
diff --git a/spec/ruby/core/numeric/infinite_spec.rb b/spec/ruby/core/numeric/infinite_spec.rb
index a527cb4370..3ea7825c8c 100644
--- a/spec/ruby/core/numeric/infinite_spec.rb
+++ b/spec/ruby/core/numeric/infinite_spec.rb
@@ -1,10 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
-ruby_version_is "2.4" do
- describe "Numeric#infinite?" do
- it "returns nil by default" do
- o = mock_numeric("infinite")
- o.infinite?.should == nil
- end
+describe "Numeric#infinite?" do
+ it "returns nil by default" do
+ o = mock_numeric("infinite")
+ o.infinite?.should == nil
end
end
diff --git a/spec/ruby/core/numeric/integer_spec.rb b/spec/ruby/core/numeric/integer_spec.rb
index acff8eb830..adbac4d7aa 100644
--- a/spec/ruby/core/numeric/integer_spec.rb
+++ b/spec/ruby/core/numeric/integer_spec.rb
@@ -1,8 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Numeric#integer?" do
it "returns false" do
- NumericSpecs::Subclass.new.integer?.should == false
+ NumericSpecs::Subclass.new.should_not.integer?
end
end
diff --git a/spec/ruby/core/numeric/magnitude_spec.rb b/spec/ruby/core/numeric/magnitude_spec.rb
index 947ee69730..ea4dbd166f 100644
--- a/spec/ruby/core/numeric/magnitude_spec.rb
+++ b/spec/ruby/core/numeric/magnitude_spec.rb
@@ -1,5 +1,7 @@
-require File.expand_path('../shared/abs', __FILE__)
+require_relative "../../spec_helper"
describe "Numeric#magnitude" do
- it_behaves_like(:numeric_abs, :magnitude)
+ it "is an alias of Numeric#abs" do
+ Numeric.instance_method(:magnitude).should == Numeric.instance_method(:abs)
+ end
end
diff --git a/spec/ruby/core/numeric/modulo_spec.rb b/spec/ruby/core/numeric/modulo_spec.rb
index a6ea7a8f14..0baf96dc18 100644
--- a/spec/ruby/core/numeric/modulo_spec.rb
+++ b/spec/ruby/core/numeric/modulo_spec.rb
@@ -1,7 +1,12 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
-describe :numeric_modulo_19, shared: true do
+describe "Numeric#modulo" do
+ it "is an alias of Numeric#%" do
+ Numeric.instance_method(:modulo).should == Numeric.instance_method(:%)
+ end
+end
+
+describe "Numeric#%" do
it "returns self - other * self.div(other)" do
s = mock_numeric('self')
o = mock_numeric('other')
@@ -11,14 +16,6 @@ describe :numeric_modulo_19, shared: true do
s.should_receive(:div).with(o).and_return(n3)
o.should_receive(:*).with(n3).and_return(n4)
s.should_receive(:-).with(n4).and_return(n5)
- s.send(@method, o).should == n5
+ (s % o).should == n5
end
end
-
-describe "Numeric#modulo" do
- it_behaves_like :numeric_modulo_19, :modulo
-end
-
-describe "Numeric#%" do
- it_behaves_like :numeric_modulo_19, :%
-end
diff --git a/spec/ruby/core/numeric/negative_spec.rb b/spec/ruby/core/numeric/negative_spec.rb
index 27e5c65fe3..f2d8a847da 100644
--- a/spec/ruby/core/numeric/negative_spec.rb
+++ b/spec/ruby/core/numeric/negative_spec.rb
@@ -1,43 +1,41 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
-ruby_version_is "2.3" do
- describe "Numeric#negative?" do
- describe "on positive numbers" do
- it "returns false" do
- 1.negative?.should be_false
- 0.1.negative?.should be_false
- end
+describe "Numeric#negative?" do
+ describe "on positive numbers" do
+ it "returns false" do
+ 1.negative?.should == false
+ 0.1.negative?.should == false
end
+ end
- describe "on zero" do
- it "returns false" do
- 0.negative?.should be_false
- 0.0.negative?.should be_false
- end
+ describe "on zero" do
+ it "returns false" do
+ 0.negative?.should == false
+ 0.0.negative?.should == false
end
+ end
- describe "on negative numbers" do
- it "returns true" do
- -1.negative?.should be_true
- -0.1.negative?.should be_true
- end
+ describe "on negative numbers" do
+ it "returns true" do
+ -1.negative?.should == true
+ -0.1.negative?.should == true
end
end
+end
- describe "Numeric#negative?" do
- before(:each) do
- @obj = NumericSpecs::Subclass.new
- end
+describe "Numeric#negative?" do
+ before(:each) do
+ @obj = NumericSpecs::Subclass.new
+ end
- it "returns true if self is less than 0" do
- @obj.should_receive(:<).with(0).and_return(true)
- @obj.negative?.should == true
- end
+ it "returns true if self is less than 0" do
+ @obj.should_receive(:<).with(0).and_return(true)
+ @obj.should.negative?
+ end
- it "returns false if self is greater than 0" do
- @obj.should_receive(:<).with(0).and_return(false)
- @obj.negative?.should == false
- end
+ it "returns false if self is greater than 0" do
+ @obj.should_receive(:<).with(0).and_return(false)
+ @obj.should_not.negative?
end
end
diff --git a/spec/ruby/core/numeric/nonzero_spec.rb b/spec/ruby/core/numeric/nonzero_spec.rb
index 55b7880d0e..464ed4f4f8 100644
--- a/spec/ruby/core/numeric/nonzero_spec.rb
+++ b/spec/ruby/core/numeric/nonzero_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Numeric#nonzero?" do
before :each do
diff --git a/spec/ruby/core/numeric/numerator_spec.rb b/spec/ruby/core/numeric/numerator_spec.rb
index 4a20f8792a..668df8b797 100644
--- a/spec/ruby/core/numeric/numerator_spec.rb
+++ b/spec/ruby/core/numeric/numerator_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Numeric#numerator" do
before :all do
diff --git a/spec/ruby/core/numeric/numeric_spec.rb b/spec/ruby/core/numeric/numeric_spec.rb
index 9429ab55a0..2bcf2a1175 100644
--- a/spec/ruby/core/numeric/numeric_spec.rb
+++ b/spec/ruby/core/numeric/numeric_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Numeric" do
it "includes Comparable" do
diff --git a/spec/ruby/core/numeric/phase_spec.rb b/spec/ruby/core/numeric/phase_spec.rb
index 7c408db83b..3abe8f2e02 100644
--- a/spec/ruby/core/numeric/phase_spec.rb
+++ b/spec/ruby/core/numeric/phase_spec.rb
@@ -1,6 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/complex/numeric/arg', __FILE__)
+require_relative '../../spec_helper'
describe "Numeric#phase" do
- it_behaves_like(:numeric_arg, :phase)
+ it "is an alias of Numeric#arg" do
+ Numeric.instance_method(:phase).should == Numeric.instance_method(:arg)
+ end
end
diff --git a/spec/ruby/core/numeric/polar_spec.rb b/spec/ruby/core/numeric/polar_spec.rb
index 5492483215..0695d7afb2 100644
--- a/spec/ruby/core/numeric/polar_spec.rb
+++ b/spec/ruby/core/numeric/polar_spec.rb
@@ -1,6 +1,50 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/complex/numeric/polar', __FILE__)
+require_relative '../../spec_helper'
describe "Numeric#polar" do
- it_behaves_like(:numeric_polar, :polar)
+ before :each do
+ @pos_numbers = [
+ 1,
+ 3898172610**9,
+ 987.18273,
+ Float::MAX,
+ Rational(13,7),
+ infinity_value,
+ ]
+ @neg_numbers = @pos_numbers.map {|n| -n}
+ @numbers = @pos_numbers + @neg_numbers
+ @numbers.push(0, 0.0)
+ end
+
+ it "returns a two-element Array" do
+ @numbers.each do |number|
+ number.polar.should.instance_of?(Array)
+ number.polar.size.should == 2
+ end
+ end
+
+ it "sets the first value to the absolute value of self" do
+ @numbers.each do |number|
+ number.polar.first.should == number.abs
+ end
+ end
+
+ it "sets the last value to 0 if self is positive" do
+ (@numbers - @neg_numbers).each do |number|
+ number.should >= 0
+ number.polar.last.should == 0
+ end
+ end
+
+ it "sets the last value to Pi if self is negative" do
+ @neg_numbers.each do |number|
+ number.should < 0
+ number.polar.last.should == Math::PI
+ end
+ end
+
+ it "returns [NaN, NaN] if self is NaN" do
+ nan_value.polar.size.should == 2
+ nan_value.polar.first.nan?.should == true
+ nan_value.polar.last.nan?.should == true
+ end
end
diff --git a/spec/ruby/core/numeric/positive_spec.rb b/spec/ruby/core/numeric/positive_spec.rb
index 516de7db89..7c8d15cd9f 100644
--- a/spec/ruby/core/numeric/positive_spec.rb
+++ b/spec/ruby/core/numeric/positive_spec.rb
@@ -1,43 +1,41 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
-ruby_version_is "2.3" do
- describe "Numeric#positive?" do
- describe "on positive numbers" do
- it "returns true" do
- 1.positive?.should be_true
- 0.1.positive?.should be_true
- end
+describe "Numeric#positive?" do
+ describe "on positive numbers" do
+ it "returns true" do
+ 1.positive?.should == true
+ 0.1.positive?.should == true
end
+ end
- describe "on zero" do
- it "returns false" do
- 0.positive?.should be_false
- 0.0.positive?.should be_false
- end
+ describe "on zero" do
+ it "returns false" do
+ 0.positive?.should == false
+ 0.0.positive?.should == false
end
+ end
- describe "on negative numbers" do
- it "returns false" do
- -1.positive?.should be_false
- -0.1.positive?.should be_false
- end
+ describe "on negative numbers" do
+ it "returns false" do
+ -1.positive?.should == false
+ -0.1.positive?.should == false
end
end
+end
- describe "Numeric#positive?" do
- before(:each) do
- @obj = NumericSpecs::Subclass.new
- end
+describe "Numeric#positive?" do
+ before(:each) do
+ @obj = NumericSpecs::Subclass.new
+ end
- it "returns true if self is greater than 0" do
- @obj.should_receive(:>).with(0).and_return(true)
- @obj.positive?.should == true
- end
+ it "returns true if self is greater than 0" do
+ @obj.should_receive(:>).with(0).and_return(true)
+ @obj.should.positive?
+ end
- it "returns false if self is less than 0" do
- @obj.should_receive(:>).with(0).and_return(false)
- @obj.positive?.should == false
- end
+ it "returns false if self is less than 0" do
+ @obj.should_receive(:>).with(0).and_return(false)
+ @obj.should_not.positive?
end
end
diff --git a/spec/ruby/core/numeric/quo_spec.rb b/spec/ruby/core/numeric/quo_spec.rb
index 24c752aac1..66ff019231 100644
--- a/spec/ruby/core/numeric/quo_spec.rb
+++ b/spec/ruby/core/numeric/quo_spec.rb
@@ -1,14 +1,13 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/quo', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Numeric#quo" do
it "returns the result of self divided by the given Integer as a Rational" do
- 5.quo(2).should eql(Rational(5,2))
+ 5.quo(2).should.eql?(Rational(5,2))
end
it "returns the result of self divided by the given Float as a Float" do
- 2.quo(2.5).should eql(0.8)
+ 2.quo(2.5).should.eql?(0.8)
end
it "returns the result of self divided by the given Bignum as a Float" do
@@ -16,11 +15,11 @@ describe "Numeric#quo" do
end
it "raises a ZeroDivisionError when the given Integer is 0" do
- lambda { 0.quo(0) }.should raise_error(ZeroDivisionError)
- lambda { 10.quo(0) }.should raise_error(ZeroDivisionError)
- lambda { -10.quo(0) }.should raise_error(ZeroDivisionError)
- lambda { bignum_value.quo(0) }.should raise_error(ZeroDivisionError)
- lambda { -bignum_value.quo(0) }.should raise_error(ZeroDivisionError)
+ -> { 0.quo(0) }.should.raise(ZeroDivisionError)
+ -> { 10.quo(0) }.should.raise(ZeroDivisionError)
+ -> { -10.quo(0) }.should.raise(ZeroDivisionError)
+ -> { bignum_value.quo(0) }.should.raise(ZeroDivisionError)
+ -> { (-bignum_value).quo(0) }.should.raise(ZeroDivisionError)
end
it "calls #to_r to convert the object to a Rational" do
@@ -34,16 +33,16 @@ describe "Numeric#quo" do
obj = NumericSpecs::Subclass.new
obj.should_receive(:to_r).and_return(1)
- lambda { obj.quo(19) }.should raise_error(TypeError)
+ -> { obj.quo(19) }.should.raise(TypeError)
end
it "raises a TypeError when given a non-Integer" do
- lambda {
+ -> {
(obj = mock('x')).should_not_receive(:to_int)
13.quo(obj)
- }.should raise_error(TypeError)
- lambda { 13.quo("10") }.should raise_error(TypeError)
- lambda { 13.quo(:symbol) }.should raise_error(TypeError)
+ }.should.raise(TypeError)
+ -> { 13.quo("10") }.should.raise(TypeError)
+ -> { 13.quo(:symbol) }.should.raise(TypeError)
end
it "returns the result of calling self#/ with other" do
@@ -52,4 +51,13 @@ describe "Numeric#quo" do
obj.quo(19).should == 1.quo(20)
end
+
+ it "raises a ZeroDivisionError if the given argument is zero and not a Float" do
+ -> { 1.quo(0) }.should.raise(ZeroDivisionError)
+ end
+
+ it "returns infinity if the given argument is zero and is a Float" do
+ (1.quo(0.0)).to_s.should == 'Infinity'
+ (-1.quo(0.0)).to_s.should == '-Infinity'
+ end
end
diff --git a/spec/ruby/core/numeric/real_spec.rb b/spec/ruby/core/numeric/real_spec.rb
index 3e34410155..09d482a691 100644
--- a/spec/ruby/core/numeric/real_spec.rb
+++ b/spec/ruby/core/numeric/real_spec.rb
@@ -1,13 +1,37 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/complex/numeric/real', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Numeric#real" do
- it_behaves_like(:numeric_real, :real)
+ before :each do
+ @numbers = [
+ 20, # Integer
+ 398.72, # Float
+ Rational(3, 4), # Rational
+ bignum_value, # Bignum
+ infinity_value,
+ nan_value
+ ].map{ |n| [n, -n] }.flatten
+ end
+
+ it "returns self" do
+ @numbers.each do |number|
+ if number.to_f.nan?
+ number.real.nan?.should == true
+ else
+ number.real.should == number
+ end
+ end
+ end
+
+ it "raises an ArgumentError if given any arguments" do
+ @numbers.each do |number|
+ -> { number.real(number) }.should.raise(ArgumentError)
+ end
+ end
end
describe "Numeric#real?" do
it "returns true" do
- NumericSpecs::Subclass.new.real?.should == true
+ NumericSpecs::Subclass.new.should.real?
end
end
diff --git a/spec/ruby/core/numeric/rect_spec.rb b/spec/ruby/core/numeric/rect_spec.rb
index 88d5ee3881..65cdcc5229 100644
--- a/spec/ruby/core/numeric/rect_spec.rb
+++ b/spec/ruby/core/numeric/rect_spec.rb
@@ -1,6 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/rect', __FILE__)
+require_relative '../../spec_helper'
describe "Numeric#rect" do
- it_behaves_like(:numeric_rect, :rect)
+ it "is an alias of Numeric#rectangular" do
+ Numeric.instance_method(:rect).should == Numeric.instance_method(:rectangular)
+ end
end
diff --git a/spec/ruby/core/numeric/rectangular_spec.rb b/spec/ruby/core/numeric/rectangular_spec.rb
index b34100ca74..81afccc12d 100644
--- a/spec/ruby/core/numeric/rectangular_spec.rb
+++ b/spec/ruby/core/numeric/rectangular_spec.rb
@@ -1,6 +1,48 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/rect', __FILE__)
+require_relative '../../spec_helper'
describe "Numeric#rectangular" do
- it_behaves_like(:numeric_rect, :rectangular)
+ before :each do
+ @numbers = [
+ 20, # Integer
+ 398.72, # Float
+ Rational(3, 4), # Rational
+ 99999999**99, # Bignum
+ infinity_value,
+ nan_value
+ ]
+ end
+
+ it "returns an Array" do
+ @numbers.each do |number|
+ number.rectangular.should.instance_of?(Array)
+ end
+ end
+
+ it "returns a two-element Array" do
+ @numbers.each do |number|
+ number.rectangular.size.should == 2
+ end
+ end
+
+ it "returns self as the first element" do
+ @numbers.each do |number|
+ if Float === number and number.nan?
+ number.rectangular.first.nan?.should == true
+ else
+ number.rectangular.first.should == number
+ end
+ end
+ end
+
+ it "returns 0 as the last element" do
+ @numbers.each do |number|
+ number.rectangular.last.should == 0
+ end
+ end
+
+ it "raises an ArgumentError if given any arguments" do
+ @numbers.each do |number|
+ -> { number.rectangular(number) }.should.raise(ArgumentError)
+ end
+ end
end
diff --git a/spec/ruby/core/numeric/remainder_spec.rb b/spec/ruby/core/numeric/remainder_spec.rb
index 6d26d39669..bdf7358b21 100644
--- a/spec/ruby/core/numeric/remainder_spec.rb
+++ b/spec/ruby/core/numeric/remainder_spec.rb
@@ -1,18 +1,19 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Numeric#remainder" do
before :each do
@obj = NumericSpecs::Subclass.new
@result = mock("Numeric#% result")
@other = mock("Passed Object")
+ @other.should_receive(:coerce).with(@obj).and_return([@obj, @other])
end
it "returns the result of calling self#% with other if self is 0" do
@obj.should_receive(:%).with(@other).and_return(@result)
@result.should_receive(:==).with(0).and_return(true)
- @obj.remainder(@other).should equal(@result)
+ @obj.remainder(@other).should.equal?(@result)
end
it "returns the result of calling self#% with other if self and other are greater than 0" do
@@ -24,7 +25,7 @@ describe "Numeric#remainder" do
@obj.should_receive(:>).with(0).and_return(true)
@other.should_receive(:<).with(0).and_return(false)
- @obj.remainder(@other).should equal(@result)
+ @obj.remainder(@other).should.equal?(@result)
end
it "returns the result of calling self#% with other if self and other are less than 0" do
@@ -36,7 +37,7 @@ describe "Numeric#remainder" do
@obj.should_receive(:>).with(0).and_return(false)
- @obj.remainder(@other).should equal(@result)
+ @obj.remainder(@other).should.equal?(@result)
end
it "returns the result of calling self#% with other - other if self is greater than 0 and other is less than 0" do
diff --git a/spec/ruby/core/numeric/round_spec.rb b/spec/ruby/core/numeric/round_spec.rb
index 6e79decfa0..47c5837693 100644
--- a/spec/ruby/core/numeric/round_spec.rb
+++ b/spec/ruby/core/numeric/round_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Numeric#round" do
before :each do
diff --git a/spec/ruby/core/numeric/shared/abs.rb b/spec/ruby/core/numeric/shared/abs.rb
deleted file mode 100644
index 406c9f3981..0000000000
--- a/spec/ruby/core/numeric/shared/abs.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
-
-describe :numeric_abs, shared: true do
- before :each do
- @obj = NumericSpecs::Subclass.new
- end
-
- it "returns self when self is greater than 0" do
- @obj.should_receive(:<).with(0).and_return(false)
- @obj.send(@method).should == @obj
- end
-
- it "returns self\#@- when self is less than 0" do
- @obj.should_receive(:<).with(0).and_return(true)
- @obj.should_receive(:-@).and_return(:absolute_value)
- @obj.send(@method).should == :absolute_value
- end
-end
diff --git a/spec/ruby/core/numeric/shared/quo.rb b/spec/ruby/core/numeric/shared/quo.rb
deleted file mode 100644
index 2392636fe7..0000000000
--- a/spec/ruby/core/numeric/shared/quo.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-describe :numeric_quo_18, shared: true do
- it "returns the result of calling self#/ with other" do
- obj = mock_numeric('numeric')
- obj.should_receive(:/).with(19).and_return(:result)
- obj.send(@method, 19).should == :result
- end
-end
diff --git a/spec/ruby/core/numeric/shared/rect.rb b/spec/ruby/core/numeric/shared/rect.rb
deleted file mode 100644
index cda5fede7f..0000000000
--- a/spec/ruby/core/numeric/shared/rect.rb
+++ /dev/null
@@ -1,48 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-
-describe :numeric_rect, shared: true do
- before :each do
- @numbers = [
- 20, # Integer
- 398.72, # Float
- Rational(3, 4), # Rational
- 99999999**99, # Bignum
- infinity_value,
- nan_value
- ]
- end
-
- it "returns an Array" do
- @numbers.each do |number|
- number.send(@method).should be_an_instance_of(Array)
- end
- end
-
- it "returns a two-element Array" do
- @numbers.each do |number|
- number.send(@method).size.should == 2
- end
- end
-
- it "returns self as the first element" do
- @numbers.each do |number|
- if Float === number and number.nan?
- number.send(@method).first.nan?.should be_true
- else
- number.send(@method).first.should == number
- end
- end
- end
-
- it "returns 0 as the last element" do
- @numbers.each do |number|
- number.send(@method).last.should == 0
- end
- end
-
- it "raises an ArgumentError if given any arguments" do
- @numbers.each do |number|
- lambda { number.send(@method, number) }.should raise_error(ArgumentError)
- end
- end
-end
diff --git a/spec/ruby/core/numeric/shared/step.rb b/spec/ruby/core/numeric/shared/step.rb
index 3072830534..66b8c1af0d 100644
--- a/spec/ruby/core/numeric/shared/step.rb
+++ b/spec/ruby/core/numeric/shared/step.rb
@@ -1,56 +1,64 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
# Describes Numeric#step shared specs between different argument styles.
-# To be able to do it, the @step_args var must contain a Proc that transforms
+# To be able to do it, the @step ivar must contain a Proc that transforms
# the step call arguments passed as positional arguments to the style of
# arguments pretended to test.
-describe :numeric_step, :shared => true do
+describe :numeric_step, shared: true do
before :each do
ScratchPad.record []
- @prc = lambda { |x| ScratchPad << x }
+ @prc = -> x { ScratchPad << x }
end
it "defaults to step = 1" do
- 1.send(@method, *@step_args.call(5), &@prc)
- ScratchPad.recorded.should eql [1, 2, 3, 4, 5]
+ @step.call(1, 5, &@prc)
+ ScratchPad.recorded.should.eql? [1, 2, 3, 4, 5]
end
- describe "when self, stop and step are Fixnums" do
- it "yields only Fixnums" do
- 1.send(@method, *@step_args.call(5, 1)) { |x| x.should be_an_instance_of(Fixnum) }
+ it "defaults to an infinite limit with a step size of 1 for Integers" do
+ 1.step.first(5).should == [1, 2, 3, 4, 5]
+ end
+
+ it "defaults to an infinite limit with a step size of 1.0 for Floats" do
+ 1.0.step.first(5).should == [1.0, 2.0, 3.0, 4.0, 5.0]
+ end
+
+ describe "when self, stop and step are Integers" do
+ it "yields only Integers" do
+ @step.call(1, 5, 1) { |x| x.should.instance_of?(Integer) }
end
describe "with a positive step" do
it "yields while increasing self by step until stop is reached" do
- 1.send(@method, *@step_args.call(5, 1), &@prc)
- ScratchPad.recorded.should eql [1, 2, 3, 4, 5]
+ @step.call(1, 5, 1, &@prc)
+ ScratchPad.recorded.should.eql? [1, 2, 3, 4, 5]
end
it "yields once when self equals stop" do
- 1.send(@method, *@step_args.call(1, 1), &@prc)
- ScratchPad.recorded.should eql [1]
+ @step.call(1, 1, 1, &@prc)
+ ScratchPad.recorded.should.eql? [1]
end
it "does not yield when self is greater than stop" do
- 2.send(@method, *@step_args.call(1, 1), &@prc)
- ScratchPad.recorded.should eql []
+ @step.call(2, 1, 1, &@prc)
+ ScratchPad.recorded.should.eql? []
end
end
describe "with a negative step" do
it "yields while decreasing self by step until stop is reached" do
- 5.send(@method, *@step_args.call(1, -1), &@prc)
- ScratchPad.recorded.should eql [5, 4, 3, 2, 1]
+ @step.call(5, 1, -1, &@prc)
+ ScratchPad.recorded.should.eql? [5, 4, 3, 2, 1]
end
it "yields once when self equals stop" do
- 5.send(@method, *@step_args.call(5, -1), &@prc)
- ScratchPad.recorded.should eql [5]
+ @step.call(5, 5, -1, &@prc)
+ ScratchPad.recorded.should.eql? [5]
end
it "does not yield when self is less than stop" do
- 1.send(@method, *@step_args.call(5, -1), &@prc)
+ @step.call(1, 5, -1, &@prc)
ScratchPad.recorded.should == []
end
end
@@ -58,156 +66,157 @@ describe :numeric_step, :shared => true do
describe "when at least one of self, stop or step is a Float" do
it "yields Floats even if only self is a Float" do
- 1.5.send(@method, *@step_args.call(5, 1)) { |x| x.should be_an_instance_of(Float) }
+ @step.call(1.5, 5, 1) { |x| x.should.instance_of?(Float) }
end
it "yields Floats even if only stop is a Float" do
- 1.send(@method, *@step_args.call(5.0, 1)) { |x| x.should be_an_instance_of(Float) }
+ @step.call(1, 5.0, 1) { |x| x.should.instance_of?(Float) }
end
it "yields Floats even if only step is a Float" do
- 1.send(@method, *@step_args.call(5, 1.0)) { |x| x.should be_an_instance_of(Float) }
+ @step.call(1, 5, 1.0) { |x| x.should.instance_of?(Float) }
end
describe "with a positive step" do
it "yields while increasing self by step while < stop" do
- 1.5.send(@method, *@step_args.call(5, 1), &@prc)
- ScratchPad.recorded.should eql [1.5, 2.5, 3.5, 4.5]
+ @step.call(1.5, 5, 1, &@prc)
+ ScratchPad.recorded.should.eql? [1.5, 2.5, 3.5, 4.5]
end
it "yields once when self equals stop" do
- 1.5.send(@method, *@step_args.call(1.5, 1), &@prc)
- ScratchPad.recorded.should eql [1.5]
+ @step.call(1.5, 1.5, 1, &@prc)
+ ScratchPad.recorded.should.eql? [1.5]
end
it "does not yield when self is greater than stop" do
- 2.5.send(@method, *@step_args.call(1.5, 1), &@prc)
+ @step.call(2.5, 1.5, 1, &@prc)
ScratchPad.recorded.should == []
end
it "is careful about not yielding a value greater than limit" do
# As 9*1.3+1.0 == 12.700000000000001 > 12.7, we test:
- 1.0.send(@method, *@step_args.call(12.7, 1.3), &@prc)
- ScratchPad.recorded.should eql [1.0, 2.3, 3.6, 4.9, 6.2, 7.5, 8.8, 10.1, 11.4, 12.7]
+ @step.call(1.0, 12.7, 1.3, &@prc)
+ ScratchPad.recorded.should.eql? [1.0, 2.3, 3.6, 4.9, 6.2, 7.5, 8.8, 10.1, 11.4, 12.7]
end
end
describe "with a negative step" do
it "yields while decreasing self by step while self > stop" do
- 5.send(@method, *@step_args.call(1.5, -1), &@prc)
- ScratchPad.recorded.should eql [5.0, 4.0, 3.0, 2.0]
+ @step.call(5, 1.5, -1, &@prc)
+ ScratchPad.recorded.should.eql? [5.0, 4.0, 3.0, 2.0]
end
it "yields once when self equals stop" do
- 1.5.send(@method, *@step_args.call(1.5, -1), &@prc)
- ScratchPad.recorded.should eql [1.5]
+ @step.call(1.5, 1.5, -1, &@prc)
+ ScratchPad.recorded.should.eql? [1.5]
end
it "does not yield when self is less than stop" do
- 1.send(@method, *@step_args.call(5, -1.5), &@prc)
+ @step.call(1, 5, -1.5, &@prc)
ScratchPad.recorded.should == []
end
it "is careful about not yielding a value smaller than limit" do
# As -9*1.3-1.0 == -12.700000000000001 < -12.7, we test:
- -1.0.send(@method, *@step_args.call(-12.7, -1.3), &@prc)
- ScratchPad.recorded.should eql [-1.0, -2.3, -3.6, -4.9, -6.2, -7.5, -8.8, -10.1, -11.4, -12.7]
+ @step.call(-1.0, -12.7, -1.3, &@prc)
+ ScratchPad.recorded.should.eql? [-1.0, -2.3, -3.6, -4.9, -6.2, -7.5, -8.8, -10.1, -11.4, -12.7]
end
end
describe "with a positive Infinity step" do
it "yields once if self < stop" do
- 42.send(@method, *@step_args.call(100, infinity_value), &@prc)
- ScratchPad.recorded.should eql [42.0]
+ @step.call(42, 100, infinity_value, &@prc)
+ ScratchPad.recorded.should.eql? [42.0]
end
it "yields once when stop is Infinity" do
- 42.send(@method, *@step_args.call(infinity_value, infinity_value), &@prc)
- ScratchPad.recorded.should eql [42.0]
+ @step.call(42, infinity_value, infinity_value, &@prc)
+ ScratchPad.recorded.should.eql? [42.0]
end
it "yields once when self equals stop" do
- 42.send(@method, *@step_args.call(42, infinity_value), &@prc)
- ScratchPad.recorded.should eql [42.0]
+ @step.call(42, 42, infinity_value, &@prc)
+ ScratchPad.recorded.should.eql? [42.0]
end
it "yields once when self and stop are Infinity" do
- (infinity_value).send(@method, *@step_args.call(infinity_value, infinity_value), &@prc)
+ # @step.call(infinity_value, infinity_value, infinity_value, &@prc)
+ @step.call(infinity_value, infinity_value, infinity_value, &@prc)
ScratchPad.recorded.should == [infinity_value]
end
it "does not yield when self > stop" do
- 100.send(@method, *@step_args.call(42, infinity_value), &@prc)
+ @step.call(100, 42, infinity_value, &@prc)
ScratchPad.recorded.should == []
end
it "does not yield when stop is -Infinity" do
- 42.send(@method, *@step_args.call(-infinity_value, infinity_value), &@prc)
+ @step.call(42, -infinity_value, infinity_value, &@prc)
ScratchPad.recorded.should == []
end
end
describe "with a negative Infinity step" do
it "yields once if self > stop" do
- 42.send(@method, *@step_args.call(6, -infinity_value), &@prc)
- ScratchPad.recorded.should eql [42.0]
+ @step.call(42, 6, -infinity_value, &@prc)
+ ScratchPad.recorded.should.eql? [42.0]
end
it "yields once if stop is -Infinity" do
- 42.send(@method, *@step_args.call(-infinity_value, -infinity_value), &@prc)
- ScratchPad.recorded.should eql [42.0]
+ @step.call(42, -infinity_value, -infinity_value, &@prc)
+ ScratchPad.recorded.should.eql? [42.0]
end
it "yields once when self equals stop" do
- 42.send(@method, *@step_args.call(42, -infinity_value), &@prc)
- ScratchPad.recorded.should eql [42.0]
+ @step.call(42, 42, -infinity_value, &@prc)
+ ScratchPad.recorded.should.eql? [42.0]
end
it "yields once when self and stop are Infinity" do
- (infinity_value).send(@method, *@step_args.call(infinity_value, -infinity_value), &@prc)
+ @step.call(infinity_value, infinity_value, -infinity_value, &@prc)
ScratchPad.recorded.should == [infinity_value]
end
it "does not yield when self > stop" do
- 42.send(@method, *@step_args.call(100, -infinity_value), &@prc)
+ @step.call(42, 100, -infinity_value, &@prc)
ScratchPad.recorded.should == []
end
it "does not yield when stop is Infinity" do
- 42.send(@method, *@step_args.call(infinity_value, -infinity_value), &@prc)
+ @step.call(42, infinity_value, -infinity_value, &@prc)
ScratchPad.recorded.should == []
end
end
describe "with a Infinity stop and a positive step" do
it "does not yield when self is infinity" do
- (infinity_value).send(@method, *@step_args.call(infinity_value, 1), &@prc)
+ @step.call(infinity_value, infinity_value, 1, &@prc)
ScratchPad.recorded.should == []
end
end
describe "with a Infinity stop and a negative step" do
it "does not yield when self is negative infinity" do
- (-infinity_value).send(@method, *@step_args.call(infinity_value, -1), &@prc)
+ @step.call(-infinity_value, infinity_value, -1, &@prc)
ScratchPad.recorded.should == []
end
it "does not yield when self is positive infinity" do
- infinity_value.send(@method, *@step_args.call(infinity_value, -1), &@prc)
+ @step.call(infinity_value, infinity_value, -1, &@prc)
ScratchPad.recorded.should == []
end
end
describe "with a negative Infinity stop and a positive step" do
it "does not yield when self is negative infinity" do
- (-infinity_value).send(@method, *@step_args.call(-infinity_value, 1), &@prc)
+ @step.call(-infinity_value, -infinity_value, 1, &@prc)
ScratchPad.recorded.should == []
end
end
describe "with a negative Infinity stop and a negative step" do
it "does not yield when self is negative infinity" do
- (-infinity_value).send(@method, *@step_args.call(-infinity_value, -1), &@prc)
+ @step.call(-infinity_value, -infinity_value, -1, &@prc)
ScratchPad.recorded.should == []
end
end
@@ -215,75 +224,62 @@ describe :numeric_step, :shared => true do
end
describe "when step is a String" do
- error = nil
- ruby_version_is ""..."2.4" do
- error = ArgumentError
- end
- ruby_version_is "2.4"..."2.5" do
- error = TypeError
- end
- ruby_version_is "2.5" do
- error = ArgumentError
- end
-
- describe "with self and stop as Fixnums" do
- it "raises an #{error} when step is a numeric representation" do
- lambda { 1.send(@method, *@step_args.call(5, "1")) {} }.should raise_error(error)
- lambda { 1.send(@method, *@step_args.call(5, "0.1")) {} }.should raise_error(error)
- lambda { 1.send(@method, *@step_args.call(5, "1/3")) {} }.should raise_error(error)
+ describe "with self and stop as Integers" do
+ it "raises an ArgumentError when step is a numeric representation" do
+ -> { @step.call(1, 5, "1") {} }.should.raise(ArgumentError)
+ -> { @step.call(1, 5, "0.1") {} }.should.raise(ArgumentError)
+ -> { @step.call(1, 5, "1/3") {} }.should.raise(ArgumentError)
end
- it "raises an #{error} with step as an alphanumeric string" do
- lambda { 1.send(@method, *@step_args.call(5, "foo")) {} }.should raise_error(error)
+ it "raises an ArgumentError with step as an alphanumeric string" do
+ -> { @step.call(1, 5, "foo") {} }.should.raise(ArgumentError)
end
end
describe "with self and stop as Floats" do
- it "raises an #{error} when step is a numeric representation" do
- lambda { 1.1.send(@method, *@step_args.call(5.1, "1")) {} }.should raise_error(error)
- lambda { 1.1.send(@method, *@step_args.call(5.1, "0.1")) {} }.should raise_error(error)
- lambda { 1.1.send(@method, *@step_args.call(5.1, "1/3")) {} }.should raise_error(error)
+ it "raises an ArgumentError when step is a numeric representation" do
+ -> { @step.call(1.1, 5.1, "1") {} }.should.raise(ArgumentError)
+ -> { @step.call(1.1, 5.1, "0.1") {} }.should.raise(ArgumentError)
+ -> { @step.call(1.1, 5.1, "1/3") {} }.should.raise(ArgumentError)
end
- it "raises an #{error} with step as an alphanumeric string" do
- lambda { 1.1.send(@method, *@step_args.call(5.1, "foo")) {} }.should raise_error(error)
+ it "raises an ArgumentError with step as an alphanumeric string" do
+ -> { @step.call(1.1, 5.1, "foo") {} }.should.raise(ArgumentError)
end
end
end
it "does not rescue ArgumentError exceptions" do
- lambda { 1.send(@method, *@step_args.call(2)) { raise ArgumentError, "" }}.should raise_error(ArgumentError)
+ -> { @step.call(1, 2) { raise ArgumentError, "" }}.should.raise(ArgumentError)
end
it "does not rescue TypeError exceptions" do
- lambda { 1.send(@method, *@step_args.call(2)) { raise TypeError, "" } }.should raise_error(TypeError)
+ -> { @step.call(1, 2) { raise TypeError, "" } }.should.raise(TypeError)
end
describe "when no block is given" do
- it "returns an Enumerator when step is 0" do
- 1.send(@method, *@step_args.call(2, 0)).should be_an_instance_of(Enumerator)
- end
+ step_enum_class = Enumerator::ArithmeticSequence
- it "returns an Enumerator when not passed a block and self > stop" do
- 1.send(@method, *@step_args.call(0, 2)).should be_an_instance_of(Enumerator)
+ it "returns an #{step_enum_class} when not passed a block and self > stop" do
+ @step.call(1, 0, 2).should.instance_of?(step_enum_class)
end
- it "returns an Enumerator when not passed a block and self < stop" do
- 1.send(@method, *@step_args.call(2, 3)).should be_an_instance_of(Enumerator)
+ it "returns an #{step_enum_class} when not passed a block and self < stop" do
+ @step.call(1, 2, 3).should.instance_of?(step_enum_class)
end
- it "returns an Enumerator that uses the given step" do
- 0.send(@method, *@step_args.call(5, 2)).to_a.should eql [0, 2, 4]
+ it "returns an #{step_enum_class} that uses the given step" do
+ @step.call(0, 5, 2).to_a.should.eql? [0, 2, 4]
end
describe "when step is a String" do
- describe "with self and stop as Fixnums" do
+ describe "with self and stop as Integers" do
it "returns an Enumerator" do
- 1.send(@method, *@step_args.call(5, "foo")).should be_an_instance_of(Enumerator)
+ @step.call(1, 5, "foo").should.instance_of?(Enumerator)
end
end
describe "with self and stop as Floats" do
it "returns an Enumerator" do
- 1.1.send(@method, *@step_args.call(5.1, "foo")).should be_an_instance_of(Enumerator)
+ @step.call(1.1, 5.1, "foo").should.instance_of?(Enumerator)
end
end
end
@@ -291,132 +287,121 @@ describe :numeric_step, :shared => true do
describe "returned Enumerator" do
describe "size" do
describe "when step is a String" do
- error = nil
- ruby_version_is ""..."2.4" do
- error = ArgumentError
- end
- ruby_version_is "2.4"..."2.5" do
- error = TypeError
- end
- ruby_version_is "2.5" do
- error = ArgumentError
- end
-
- describe "with self and stop as Fixnums" do
- it "raises an #{error} when step is a numeric representation" do
- lambda { 1.send(@method, *@step_args.call(5, "1")).size }.should raise_error(error)
- lambda { 1.send(@method, *@step_args.call(5, "0.1")).size }.should raise_error(error)
- lambda { 1.send(@method, *@step_args.call(5, "1/3")).size }.should raise_error(error)
+ describe "with self and stop as Integers" do
+ it "raises an ArgumentError when step is a numeric representation" do
+ -> { @step.call(1, 5, "1").size }.should.raise(ArgumentError)
+ -> { @step.call(1, 5, "0.1").size }.should.raise(ArgumentError)
+ -> { @step.call(1, 5, "1/3").size }.should.raise(ArgumentError)
end
- it "raises an #{error} with step as an alphanumeric string" do
- lambda { 1.send(@method, *@step_args.call(5, "foo")).size }.should raise_error(error)
+ it "raises an ArgumentError with step as an alphanumeric string" do
+ -> { @step.call(1, 5, "foo").size }.should.raise(ArgumentError)
end
end
describe "with self and stop as Floats" do
- it "raises an #{error} when step is a numeric representation" do
- lambda { 1.1.send(@method, *@step_args.call(5.1, "1")).size }.should raise_error(error)
- lambda { 1.1.send(@method, *@step_args.call(5.1, "0.1")).size }.should raise_error(error)
- lambda { 1.1.send(@method, *@step_args.call(5.1, "1/3")).size }.should raise_error(error)
+ it "raises an ArgumentError when step is a numeric representation" do
+ -> { @step.call(1.1, 5.1, "1").size }.should.raise(ArgumentError)
+ -> { @step.call(1.1, 5.1, "0.1").size }.should.raise(ArgumentError)
+ -> { @step.call(1.1, 5.1, "1/3").size }.should.raise(ArgumentError)
end
- it "raises an #{error} with step as an alphanumeric string" do
- lambda { 1.1.send(@method, *@step_args.call(5.1, "foo")).size }.should raise_error(error)
+ it "raises an ArgumentError with step as an alphanumeric string" do
+ -> { @step.call(1.1, 5.1, "foo").size }.should.raise(ArgumentError)
end
end
end
- describe "when self, stop and step are Fixnums and step is positive" do
+ describe "when self, stop and step are Integers and step is positive" do
it "returns the difference between self and stop divided by the number of steps" do
- 5.send(@method, *@step_args.call(10, 11)).size.should == 1
- 5.send(@method, *@step_args.call(10, 6)).size.should == 1
- 5.send(@method, *@step_args.call(10, 5)).size.should == 2
- 5.send(@method, *@step_args.call(10, 4)).size.should == 2
- 5.send(@method, *@step_args.call(10, 2)).size.should == 3
- 5.send(@method, *@step_args.call(10, 1)).size.should == 6
- 5.send(@method, *@step_args.call(10)).size.should == 6
- 10.send(@method, *@step_args.call(10, 1)).size.should == 1
+ @step.call(5, 10, 11).size.should == 1
+ @step.call(5, 10, 6).size.should == 1
+ @step.call(5, 10, 5).size.should == 2
+ @step.call(5, 10, 4).size.should == 2
+ @step.call(5, 10, 2).size.should == 3
+ @step.call(5, 10, 1).size.should == 6
+ @step.call(5, 10).size.should == 6
+ @step.call(10, 10, 1).size.should == 1
end
it "returns 0 if value > limit" do
- 11.send(@method, *@step_args.call(10, 1)).size.should == 0
+ @step.call(11, 10, 1).size.should == 0
end
end
- describe "when self, stop and step are Fixnums and step is negative" do
+ describe "when self, stop and step are Integers and step is negative" do
it "returns the difference between self and stop divided by the number of steps" do
- 10.send(@method, *@step_args.call(5, -11)).size.should == 1
- 10.send(@method, *@step_args.call(5, -6)).size.should == 1
- 10.send(@method, *@step_args.call(5, -5)).size.should == 2
- 10.send(@method, *@step_args.call(5, -4)).size.should == 2
- 10.send(@method, *@step_args.call(5, -2)).size.should == 3
- 10.send(@method, *@step_args.call(5, -1)).size.should == 6
- 10.send(@method, *@step_args.call(10, -1)).size.should == 1
+ @step.call(10, 5, -11).size.should == 1
+ @step.call(10, 5, -6).size.should == 1
+ @step.call(10, 5, -5).size.should == 2
+ @step.call(10, 5, -4).size.should == 2
+ @step.call(10, 5, -2).size.should == 3
+ @step.call(10, 5, -1).size.should == 6
+ @step.call(10, 10, -1).size.should == 1
end
it "returns 0 if value < limit" do
- 10.send(@method, *@step_args.call(11, -1)).size.should == 0
+ @step.call(10, 11, -1).size.should == 0
end
end
describe "when self, stop or step is a Float" do
describe "and step is positive" do
it "returns the difference between self and stop divided by the number of steps" do
- 5.send(@method, *@step_args.call(10, 11.0)).size.should == 1
- 5.send(@method, *@step_args.call(10, 6.0)).size.should == 1
- 5.send(@method, *@step_args.call(10, 5.0)).size.should == 2
- 5.send(@method, *@step_args.call(10, 4.0)).size.should == 2
- 5.send(@method, *@step_args.call(10, 2.0)).size.should == 3
- 5.send(@method, *@step_args.call(10, 0.5)).size.should == 11
- 5.send(@method, *@step_args.call(10, 1.0)).size.should == 6
- 5.send(@method, *@step_args.call(10.5)).size.should == 6
- 10.send(@method, *@step_args.call(10, 1.0)).size.should == 1
+ @step.call(5, 10, 11.0).size.should == 1
+ @step.call(5, 10, 6.0).size.should == 1
+ @step.call(5, 10, 5.0).size.should == 2
+ @step.call(5, 10, 4.0).size.should == 2
+ @step.call(5, 10, 2.0).size.should == 3
+ @step.call(5, 10, 0.5).size.should == 11
+ @step.call(5, 10, 1.0).size.should == 6
+ @step.call(5, 10.5).size.should == 6
+ @step.call(10, 10, 1.0).size.should == 1
end
it "returns 0 if value > limit" do
- 10.send(@method, *@step_args.call(5.5)).size.should == 0
- 11.send(@method, *@step_args.call(10, 1.0)).size.should == 0
- 11.send(@method, *@step_args.call(10, 1.5)).size.should == 0
- 10.send(@method, *@step_args.call(5, infinity_value)).size.should == 0
+ @step.call(10, 5.5).size.should == 0
+ @step.call(11, 10, 1.0).size.should == 0
+ @step.call(11, 10, 1.5).size.should == 0
+ @step.call(10, 5, infinity_value).size.should == 0
end
it "returns 1 if step is infinity_value" do
- 5.send(@method, *@step_args.call(10, infinity_value)).size.should == 1
+ @step.call(5, 10, infinity_value).size.should == 1
end
end
describe "and step is negative" do
it "returns the difference between self and stop divided by the number of steps" do
- 10.send(@method, *@step_args.call(5, -11.0)).size.should == 1
- 10.send(@method, *@step_args.call(5, -6.0)).size.should == 1
- 10.send(@method, *@step_args.call(5, -5.0)).size.should == 2
- 10.send(@method, *@step_args.call(5, -4.0)).size.should == 2
- 10.send(@method, *@step_args.call(5, -2.0)).size.should == 3
- 10.send(@method, *@step_args.call(5, -0.5)).size.should == 11
- 10.send(@method, *@step_args.call(5, -1.0)).size.should == 6
- 10.send(@method, *@step_args.call(10, -1.0)).size.should == 1
+ @step.call(10, 5, -11.0).size.should == 1
+ @step.call(10, 5, -6.0).size.should == 1
+ @step.call(10, 5, -5.0).size.should == 2
+ @step.call(10, 5, -4.0).size.should == 2
+ @step.call(10, 5, -2.0).size.should == 3
+ @step.call(10, 5, -0.5).size.should == 11
+ @step.call(10, 5, -1.0).size.should == 6
+ @step.call(10, 10, -1.0).size.should == 1
end
it "returns 0 if value < limit" do
- 10.send(@method, *@step_args.call(11, -1.0)).size.should == 0
- 10.send(@method, *@step_args.call(11, -1.5)).size.should == 0
- 5.send(@method, *@step_args.call(10, -infinity_value)).size.should == 0
+ @step.call(10, 11, -1.0).size.should == 0
+ @step.call(10, 11, -1.5).size.should == 0
+ @step.call(5, 10, -infinity_value).size.should == 0
end
it "returns 1 if step is infinity_value" do
- 10.send(@method, *@step_args.call(5, -infinity_value)).size.should == 1
+ @step.call(10, 5, -infinity_value).size.should == 1
end
end
end
describe "when stop is not passed" do
it "returns infinity_value" do
- 1.send(@method, *@step_args.call()).size.should == infinity_value
+ @step.call(1).size.should == infinity_value
end
end
describe "when stop is nil" do
it "returns infinity_value" do
- 1.send(@method, *@step_args.call(nil, 5)).size.should == infinity_value
+ @step.call(1, nil, 5).size.should == infinity_value
end
end
end
diff --git a/spec/ruby/core/numeric/singleton_method_added_spec.rb b/spec/ruby/core/numeric/singleton_method_added_spec.rb
index a650d286f2..327bb5662a 100644
--- a/spec/ruby/core/numeric/singleton_method_added_spec.rb
+++ b/spec/ruby/core/numeric/singleton_method_added_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Numeric#singleton_method_added" do
before :all do
@@ -18,24 +18,24 @@ describe "Numeric#singleton_method_added" do
end
it "raises a TypeError when trying to define a singleton method on a Numeric" do
- lambda do
+ -> do
a = NumericSpecs::Subclass.new
def a.test; end
- end.should raise_error(TypeError)
+ end.should.raise(TypeError)
- lambda do
+ -> do
a = 1
def a.test; end
- end.should raise_error(TypeError)
+ end.should.raise(TypeError)
- lambda do
+ -> do
a = 1.5
def a.test; end
- end.should raise_error(TypeError)
+ end.should.raise(TypeError)
- lambda do
+ -> do
a = bignum_value
def a.test; end
- end.should raise_error(TypeError)
+ end.should.raise(TypeError)
end
end
diff --git a/spec/ruby/core/numeric/step_spec.rb b/spec/ruby/core/numeric/step_spec.rb
index 256c150d4e..6896009eb6 100644
--- a/spec/ruby/core/numeric/step_spec.rb
+++ b/spec/ruby/core/numeric/step_spec.rb
@@ -1,67 +1,46 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/step', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/step'
describe "Numeric#step" do
describe 'with positional args' do
it "raises an ArgumentError when step is 0" do
- lambda { 1.step(5, 0) {} }.should raise_error(ArgumentError)
+ -> { 1.step(5, 0) {} }.should.raise(ArgumentError)
end
it "raises an ArgumentError when step is 0.0" do
- lambda { 1.step(2, 0.0) {} }.should raise_error(ArgumentError)
+ -> { 1.step(2, 0.0) {} }.should.raise(ArgumentError)
end
before :all do
# This lambda definition limits to return the arguments it receives.
# It's needed to test numeric_step behaviour with positional arguments.
- @step_args = ->(*args) { args }
+ @step = -> receiver, *args, &block { receiver.step(*args, &block) }
end
-
it_behaves_like :numeric_step, :step
describe "when no block is given" do
- it "returns an Enumerator when step is 0" do
- 1.step(5, 0).should be_an_instance_of(Enumerator)
- end
-
- it "returns an Enumerator when step is 0.0" do
- 1.step(2, 0.0).should be_an_instance_of(Enumerator)
- end
+ step_enum_class = Enumerator::ArithmeticSequence
- describe "returned Enumerator" do
+ describe "returned #{step_enum_class}" do
describe "size" do
- it "raises an ArgumentError when step is 0" do
- enum = 1.step(5, 0)
- lambda { enum.size }.should raise_error(ArgumentError)
+ it "defaults to an infinite size" do
+ enum = 1.step
+ enum.size.should == Float::INFINITY
end
+ end
- it "raises an ArgumentError when step is 0.0" do
- enum = 1.step(2, 0.0)
- lambda { enum.size }.should raise_error(ArgumentError)
+ describe "type" do
+ it "returns an instance of Enumerator::ArithmeticSequence" do
+ 1.step(10).class.should == Enumerator::ArithmeticSequence
end
end
end
end
-
end
describe 'with keyword arguments' do
- it "doesn't raise an error when step is 0" do
- lambda { 1.step(to: 5, by: 0) { break } }.should_not raise_error
- end
-
- it "doesn't raise an error when step is 0.0" do
- lambda { 1.step(to: 2, by: 0.0) { break } }.should_not raise_error
- end
-
- it "should loop over self when step is 0 or 0.0" do
- 1.step(to: 2, by: 0.0).take(5).should eql [1.0, 1.0, 1.0, 1.0, 1.0]
- 1.step(to: 2, by: 0).take(5).should eql [1, 1, 1, 1, 1]
- 1.1.step(to: 2, by: 0).take(5).should eql [1.1, 1.1, 1.1, 1.1, 1.1]
- end
-
describe "when no block is given" do
describe "returned Enumerator" do
describe "size" do
@@ -69,19 +48,11 @@ describe "Numeric#step" do
1.step(by: 42).size.should == infinity_value
end
- it "should return infinity_value when step is 0" do
- 1.step(to: 5, by: 0).size.should == infinity_value
- end
-
- it "should return infinity_value when step is 0.0" do
- 1.step(to: 2, by: 0.0).size.should == infinity_value
- end
-
it "should return infinity_value when ascending towards a limit of Float::INFINITY" do
1.step(to: Float::INFINITY, by: 42).size.should == infinity_value
end
- it "should return infinity_value when decending towards a limit of -Float::INFINITY" do
+ it "should return infinity_value when descending towards a limit of -Float::INFINITY" do
1.step(to: -Float::INFINITY, by: -42).size.should == infinity_value
end
@@ -97,64 +68,51 @@ describe "Numeric#step" do
end
before :all do
- # This lambda transforms a positional step method args into
- # keyword arguments.
+ # This lambda transforms a positional step method args into keyword arguments.
# It's needed to test numeric_step behaviour with keyword arguments.
- @step_args = ->(*args) do
- kw_args = {to: args[0]}
+ @step = -> receiver, *args, &block do
+ kw_args = { to: args[0] }
kw_args[:by] = args[1] if args.size == 2
- [kw_args]
+ receiver.step(**kw_args, &block)
end
end
it_behaves_like :numeric_step, :step
end
describe 'with mixed arguments' do
- it "doesn't raise an error when step is 0" do
- lambda { 1.step(5, by: 0) { break } }.should_not raise_error
+ it " raises an ArgumentError when step is 0" do
+ -> { 1.step(5, by: 0) { break } }.should.raise(ArgumentError)
end
- it "doesn't raise an error when step is 0.0" do
- lambda { 1.step(2, by: 0.0) { break } }.should_not raise_error
+ it "raises an ArgumentError when step is 0.0" do
+ -> { 1.step(2, by: 0.0) { break } }.should.raise(ArgumentError)
end
it "raises a ArgumentError when limit and to are defined" do
- lambda { 1.step(5, 1, to: 5) { break } }.should raise_error(ArgumentError)
+ -> { 1.step(5, 1, to: 5) { break } }.should.raise(ArgumentError)
end
it "raises a ArgumentError when step and by are defined" do
- lambda { 1.step(5, 1, by: 5) { break } }.should raise_error(ArgumentError)
- end
-
- it "should loop over self when step is 0 or 0.0" do
- 1.step(2, by: 0.0).take(5).should eql [1.0, 1.0, 1.0, 1.0, 1.0]
- 1.step(2, by: 0).take(5).should eql [1, 1, 1, 1, 1]
- 1.1.step(2, by: 0).take(5).should eql [1.1, 1.1, 1.1, 1.1, 1.1]
+ -> { 1.step(5, 1, by: 5) { break } }.should.raise(ArgumentError)
end
describe "when no block is given" do
describe "returned Enumerator" do
describe "size" do
- it "should return infinity_value when step is 0" do
- 1.step(5, by: 0).size.should == infinity_value
- end
-
- it "should return infinity_value when step is 0.0" do
- 1.step(2, by: 0.0).size.should == infinity_value
- end
end
end
end
+
before :all do
# This lambda definition transforms a positional step method args into
# a mix of positional and keyword arguments.
# It's needed to test numeric_step behaviour with positional mixed with
# keyword arguments.
- @step_args = ->(*args) do
+ @step = -> receiver, *args, &block do
if args.size == 2
- [args[0], {by: args[1]}]
+ receiver.step(args[0], by: args[1], &block)
else
- args
+ receiver.step(*args, &block)
end
end
end
diff --git a/spec/ruby/core/numeric/to_c_spec.rb b/spec/ruby/core/numeric/to_c_spec.rb
index 38452231b0..70b7a9dd0c 100644
--- a/spec/ruby/core/numeric/to_c_spec.rb
+++ b/spec/ruby/core/numeric/to_c_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Numeric#to_c" do
before :all do
@@ -22,7 +22,7 @@ describe "Numeric#to_c" do
it "returns a Complex object" do
@numbers.each do |number|
- number.to_c.should be_an_instance_of(Complex)
+ number.to_c.should.instance_of?(Complex)
end
end
@@ -30,7 +30,7 @@ describe "Numeric#to_c" do
@numbers.each do |number|
real = number.to_c.real
if Float === number and number.nan?
- real.nan?.should be_true
+ real.nan?.should == true
else
real.should == number
end
diff --git a/spec/ruby/core/numeric/to_int_spec.rb b/spec/ruby/core/numeric/to_int_spec.rb
index 4f1df3e042..3cc39a6d40 100644
--- a/spec/ruby/core/numeric/to_int_spec.rb
+++ b/spec/ruby/core/numeric/to_int_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Numeric#to_int" do
it "returns self#to_i" do
diff --git a/spec/ruby/core/numeric/truncate_spec.rb b/spec/ruby/core/numeric/truncate_spec.rb
index f1a2d4de64..f1592334c5 100644
--- a/spec/ruby/core/numeric/truncate_spec.rb
+++ b/spec/ruby/core/numeric/truncate_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Numeric#truncate" do
before :each do
diff --git a/spec/ruby/core/numeric/uminus_spec.rb b/spec/ruby/core/numeric/uminus_spec.rb
index 7385f5f599..39065fa392 100644
--- a/spec/ruby/core/numeric/uminus_spec.rb
+++ b/spec/ruby/core/numeric/uminus_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Numeric#-@" do
it "returns the same value with opposite sign (integers)" do
diff --git a/spec/ruby/core/numeric/uplus_spec.rb b/spec/ruby/core/numeric/uplus_spec.rb
index 557142295a..88cf5e037b 100644
--- a/spec/ruby/core/numeric/uplus_spec.rb
+++ b/spec/ruby/core/numeric/uplus_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Numeric#+@" do
it "returns self" do
diff --git a/spec/ruby/core/numeric/zero_spec.rb b/spec/ruby/core/numeric/zero_spec.rb
index d46e8807ea..0fb7619bcd 100644
--- a/spec/ruby/core/numeric/zero_spec.rb
+++ b/spec/ruby/core/numeric/zero_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Numeric#zero?" do
before :each do
@@ -8,11 +8,11 @@ describe "Numeric#zero?" do
it "returns true if self is 0" do
@obj.should_receive(:==).with(0).and_return(true)
- @obj.zero?.should == true
+ @obj.should.zero?
end
it "returns false if self is not 0" do
@obj.should_receive(:==).with(0).and_return(false)
- @obj.zero?.should == false
+ @obj.should_not.zero?
end
end
diff --git a/spec/ruby/core/objectspace/_id2ref_spec.rb b/spec/ruby/core/objectspace/_id2ref_spec.rb
index 6e0b6e03fb..a9fd526b7d 100644
--- a/spec/ruby/core/objectspace/_id2ref_spec.rb
+++ b/spec/ruby/core/objectspace/_id2ref_spec.rb
@@ -1,25 +1,65 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
-describe "ObjectSpace._id2ref" do
- it "converts an object id to a reference to the object" do
- s = "I am a string"
- r = ObjectSpace._id2ref(s.object_id)
- r.should == s
+ruby_version_is "4.0" do
+ describe "ObjectSpace._id2ref" do
+ it "is deprecated" do
+ id = nil.object_id
+ -> {
+ ObjectSpace._id2ref(id)
+ }.should complain(/warning: ObjectSpace\._id2ref is deprecated/)
+ end
end
+end
- it "retrieves a Fixnum by object_id" do
- f = 1
- r = ObjectSpace._id2ref(f.object_id)
- r.should == f
- end
+ruby_version_is ""..."4.0" do
+ describe "ObjectSpace._id2ref" do
+ it "converts an object id to a reference to the object" do
+ s = "I am a string"
+ r = ObjectSpace._id2ref(s.object_id)
+ r.should == s
+ end
- it "retrieves a Symbol by object_id" do
- s = :sym
- r = ObjectSpace._id2ref(s.object_id)
- r.should == s
- end
+ it "retrieves true by object_id" do
+ ObjectSpace._id2ref(true.object_id).should == true
+ end
+
+ it "retrieves false by object_id" do
+ ObjectSpace._id2ref(false.object_id).should == false
+ end
+
+ it "retrieves nil by object_id" do
+ ObjectSpace._id2ref(nil.object_id).should == nil
+ end
+
+ it "retrieves a small Integer by object_id" do
+ ObjectSpace._id2ref(1.object_id).should == 1
+ ObjectSpace._id2ref((-42).object_id).should == -42
+ end
+
+ it "retrieves a large Integer by object_id" do
+ obj = 1 << 88
+ ObjectSpace._id2ref(obj.object_id).should.equal?(obj)
+ end
+
+ it "retrieves a Symbol by object_id" do
+ ObjectSpace._id2ref(:sym.object_id).should.equal?(:sym)
+ end
+
+ it "retrieves a String by object_id" do
+ obj = "str"
+ ObjectSpace._id2ref(obj.object_id).should.equal?(obj)
+ end
+
+ it "retrieves a frozen literal String by object_id" do
+ ObjectSpace._id2ref("frozen string literal _id2ref".freeze.object_id).should.equal?("frozen string literal _id2ref".freeze)
+ end
+
+ it "retrieves an Encoding by object_id" do
+ ObjectSpace._id2ref(Encoding::UTF_8.object_id).should.equal?(Encoding::UTF_8)
+ end
- it 'raises RangeError when an object could not be found' do
- proc { ObjectSpace._id2ref(1 << 60) }.should raise_error(RangeError)
+ it 'raises RangeError when an object could not be found' do
+ proc { ObjectSpace._id2ref(1 << 60) }.should.raise(RangeError)
+ end
end
end
diff --git a/spec/ruby/core/objectspace/add_finalizer_spec.rb b/spec/ruby/core/objectspace/add_finalizer_spec.rb
deleted file mode 100644
index 2d529f2d6c..0000000000
--- a/spec/ruby/core/objectspace/add_finalizer_spec.rb
+++ /dev/null
@@ -1,5 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "ObjectSpace.add_finalizer" do
- it "needs to be reviewed for spec completeness"
-end
diff --git a/spec/ruby/core/objectspace/call_finalizer_spec.rb b/spec/ruby/core/objectspace/call_finalizer_spec.rb
deleted file mode 100644
index bb7cee68a4..0000000000
--- a/spec/ruby/core/objectspace/call_finalizer_spec.rb
+++ /dev/null
@@ -1,5 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "ObjectSpace.call_finalizer" do
- it "needs to be reviewed for spec completeness"
-end
diff --git a/spec/ruby/core/objectspace/count_objects_spec.rb b/spec/ruby/core/objectspace/count_objects_spec.rb
index 3e77d562a8..e9831a3a42 100644
--- a/spec/ruby/core/objectspace/count_objects_spec.rb
+++ b/spec/ruby/core/objectspace/count_objects_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "ObjectSpace.count_objects" do
it "needs to be reviewed for spec completeness"
diff --git a/spec/ruby/core/objectspace/define_finalizer_spec.rb b/spec/ruby/core/objectspace/define_finalizer_spec.rb
index 969e8b16b0..5441cb4a21 100644
--- a/spec/ruby/core/objectspace/define_finalizer_spec.rb
+++ b/spec/ruby/core/objectspace/define_finalizer_spec.rb
@@ -1,101 +1,217 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+# Why do we not test that finalizers are run by the GC? The documentation
+# says that finalizers are never guaranteed to be run, so we can't
+# spec that they are. On some implementations of Ruby the finalizers may
+# run asynchronously, meaning that we can't predict when they'll run,
+# even if they were guaranteed to do so. Even on MRI finalizers can be
+# very unpredictable, due to conservative stack scanning and references
+# left in unused memory.
-# NOTE: A call to define_finalizer does not guarantee that the
-# passed proc or callable will be called at any particular time.
-# It is highly questionable whether these aspects of ObjectSpace
-# should be spec'd at all.
describe "ObjectSpace.define_finalizer" do
it "raises an ArgumentError if the action does not respond to call" do
- lambda {
- ObjectSpace.define_finalizer("", mock("ObjectSpace.define_finalizer no #call"))
- }.should raise_error(ArgumentError)
+ -> {
+ ObjectSpace.define_finalizer(Object.new, mock("ObjectSpace.define_finalizer no #call"))
+ }.should.raise(ArgumentError)
end
it "accepts an object and a proc" do
- handler = lambda { |obj| obj }
- ObjectSpace.define_finalizer("garbage", handler).should == [0, handler]
+ handler = -> id { id }
+ ObjectSpace.define_finalizer(Object.new, handler).should == [0, handler]
+ end
+
+ it "accepts an object and a bound method" do
+ handler = mock("callable")
+ def handler.finalize(id) end
+ finalize = handler.method(:finalize)
+ ObjectSpace.define_finalizer(Object.new, finalize).should == [0, finalize]
end
it "accepts an object and a callable" do
handler = mock("callable")
- def handler.call(obj) end
- ObjectSpace.define_finalizer("garbage", handler).should == [0, handler]
+ def handler.call(id) end
+ ObjectSpace.define_finalizer(Object.new, handler).should == [0, handler]
+ end
+
+ it "accepts an object and a block" do
+ handler = -> id { id }
+ ObjectSpace.define_finalizer(Object.new, &handler).should == [0, handler]
end
it "raises ArgumentError trying to define a finalizer on a non-reference" do
- lambda {
+ -> {
ObjectSpace.define_finalizer(:blah) { 1 }
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
end
# see [ruby-core:24095]
- with_feature :fork do
- it "calls finalizer on process termination" do
- rd, wr = IO.pipe
- pid = Process.fork do
- rd.close
- handler = ObjectSpaceFixtures.scoped(wr)
- obj = "Test"
- ObjectSpace.define_finalizer(obj, handler)
- exit 0
+ it "calls finalizer on process termination" do
+ code = <<-RUBY
+ def scoped
+ Proc.new { puts "finalizer run" }
end
+ handler = scoped
+ obj = +"Test"
+ ObjectSpace.define_finalizer(obj, handler)
+ exit 0
+ RUBY
- wr.close
- begin
- rd.read.should == "finalized"
- ensure
- rd.close
- Process.wait pid
+ ruby_exe(code, :args => "2>&1").should.include?("finalizer run\n")
+ end
+
+ it "warns if the finalizer has the object as the receiver" do
+ code = <<-RUBY
+ class CapturesSelf
+ def initialize
+ ObjectSpace.define_finalizer(self, proc {
+ puts "finalizer run"
+ })
+ end
end
- end
+ CapturesSelf.new
+ exit 0
+ RUBY
- it "calls finalizer at exit even if it is self-referencing" do
- rd, wr = IO.pipe
- pid = Process.fork do
- rd.close
- obj = "Test"
- handler = Proc.new { wr.write "finalized"; wr.close }
- ObjectSpace.define_finalizer(obj, handler)
- exit 0
+ ruby_exe(code, :args => "2>&1").should.include?("warning: finalizer references object to be finalized\n")
+ end
+
+ it "warns if the finalizer is a method bound to the receiver" do
+ code = <<-RUBY
+ class CapturesSelf
+ def initialize
+ ObjectSpace.define_finalizer(self, method(:finalize))
+ end
+ def finalize(id)
+ puts "finalizer run"
+ end
end
+ CapturesSelf.new
+ exit 0
+ RUBY
+
+ ruby_exe(code, :args => "2>&1").should.include?("warning: finalizer references object to be finalized\n")
+ end
- wr.close
- begin
- rd.read.should == "finalized"
- ensure
- rd.close
- Process.wait pid
+ it "warns if the finalizer was a block in the receiver" do
+ code = <<-RUBY
+ class CapturesSelf
+ def initialize
+ ObjectSpace.define_finalizer(self) do
+ puts "finalizer run"
+ end
+ end
end
- end
+ CapturesSelf.new
+ exit 0
+ RUBY
- # These specs are defined under the fork specs because there is no
- # deterministic way to force finalizers to be run, except process exit, so
- # we rely on that.
- it "allows multiple finalizers with different 'callables' to be defined" do
- rd1, wr1 = IO.pipe
- rd2, wr2 = IO.pipe
+ ruby_exe(code, :args => "2>&1").should.include?("warning: finalizer references object to be finalized\n")
+ end
- pid = Kernel::fork do
- rd1.close
- rd2.close
- obj = mock("ObjectSpace.define_finalizer multiple")
+ it "calls a finalizer at exit even if it is self-referencing" do
+ code = <<-RUBY
+ obj = +"Test"
+ handler = Proc.new { puts "finalizer run" }
+ ObjectSpace.define_finalizer(obj, handler)
+ exit 0
+ RUBY
- ObjectSpace.define_finalizer(obj, Proc.new { wr1.write "finalized1"; wr1.close })
- ObjectSpace.define_finalizer(obj, Proc.new { wr2.write "finalized2"; wr2.close })
+ ruby_exe(code).should.include?("finalizer run\n")
+ end
+
+ it "calls a finalizer at exit even if it is indirectly self-referencing" do
+ code = <<-RUBY
+ class CapturesSelf
+ def initialize
+ ObjectSpace.define_finalizer(self, finalizer(self))
+ end
+ def finalizer(zelf)
+ proc do
+ puts "finalizer run"
+ end
+ end
+ end
+ CapturesSelf.new
+ exit 0
+ RUBY
+ ruby_exe(code, :args => "2>&1").should.include?("finalizer run\n")
+ end
+
+ it "calls a finalizer defined in a finalizer running at exit" do
+ code = <<-RUBY
+ obj = +"Test"
+ handler = Proc.new do
+ obj2 = +"Test"
+ handler2 = Proc.new { puts "finalizer 2 run" }
+ ObjectSpace.define_finalizer(obj2, handler2)
exit 0
end
+ ObjectSpace.define_finalizer(obj, handler)
+ exit 0
+ RUBY
+
+ ruby_exe(code, :args => "2>&1").should.include?("finalizer 2 run\n")
+ end
+
+ it "allows multiple finalizers with different 'callables' to be defined" do
+ code = <<-'RUBY'
+ obj = Object.new
+
+ ObjectSpace.define_finalizer(obj, Proc.new { STDOUT.write "finalized1\n" })
+ ObjectSpace.define_finalizer(obj, Proc.new { STDOUT.write "finalized2\n" })
+
+ exit 0
+ RUBY
+
+ ruby_exe(code).lines.sort.should == ["finalized1\n", "finalized2\n"]
+ end
+
+ it "defines same finalizer only once" do
+ code = <<~RUBY
+ obj = Object.new
+ p = proc { |id| print "ok" }
+ ObjectSpace.define_finalizer(obj, p.dup)
+ ObjectSpace.define_finalizer(obj, p.dup)
+ RUBY
- wr1.close
- wr2.close
+ ruby_exe(code).should == "ok"
+ end
+
+ it "returns the defined finalizer" do
+ obj = Object.new
+ p = proc { |id| }
+ p2 = p.dup
+
+ ret = ObjectSpace.define_finalizer(obj, p)
+ ret.should == [0, p]
+ ret[1].should.equal?(p)
+
+ ret = ObjectSpace.define_finalizer(obj, p2)
+ ret.should == [0, p]
+ ret[1].should.equal?(p)
+ end
+
+ describe "when $VERBOSE is not nil" do
+ it "warns if an exception is raised in finalizer" do
+ code = <<-RUBY
+ ObjectSpace.define_finalizer(Object.new) { raise "finalizing" }
+ RUBY
+
+ out = ruby_exe(code, args: "2>&1")
+ out.should.include?("warning: Exception in finalizer")
+ out.should.include?("finalizing")
+ end
+ end
- rd1.read.should == "finalized1"
- rd2.read.should == "finalized2"
+ describe "when $VERBOSE is nil" do
+ it "does not warn even if an exception is raised in finalizer" do
+ code = <<-RUBY
+ ObjectSpace.define_finalizer(Object.new) { raise "finalizing" }
+ RUBY
- rd1.close
- rd2.close
- Process.wait pid
+ ruby_exe(code, args: "2>&1", options: "-W0").should == ""
end
end
end
diff --git a/spec/ruby/core/objectspace/each_object_spec.rb b/spec/ruby/core/objectspace/each_object_spec.rb
index 604b45cb34..aee0fd629c 100644
--- a/spec/ruby/core/objectspace/each_object_spec.rb
+++ b/spec/ruby/core/objectspace/each_object_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "ObjectSpace.each_object" do
it "calls the block once for each living, non-immediate object in the Ruby process" do
@@ -39,7 +39,7 @@ describe "ObjectSpace.each_object" do
new_obj = klass.new
counter = ObjectSpace.each_object(klass)
- counter.should be_an_instance_of(Enumerator)
+ counter.should.instance_of?(Enumerator)
counter.each{}.should == 1
# this is needed to prevent the new_obj from being GC'd too early
new_obj.should_not == nil
@@ -47,20 +47,20 @@ describe "ObjectSpace.each_object" do
it "finds an object stored in a global variable" do
$object_space_global_variable = ObjectSpaceFixtures::ObjectToBeFound.new(:global)
- ObjectSpaceFixtures.to_be_found_symbols.should include(:global)
+ ObjectSpaceFixtures.to_be_found_symbols.should.include?(:global)
end
it "finds an object stored in a top-level constant" do
- ObjectSpaceFixtures.to_be_found_symbols.should include(:top_level_constant)
+ ObjectSpaceFixtures.to_be_found_symbols.should.include?(:top_level_constant)
end
it "finds an object stored in a second-level constant" do
- ObjectSpaceFixtures.to_be_found_symbols.should include(:second_level_constant)
+ ObjectSpaceFixtures.to_be_found_symbols.should.include?(:second_level_constant)
end
it "finds an object stored in a local variable" do
local = ObjectSpaceFixtures::ObjectToBeFound.new(:local)
- ObjectSpaceFixtures.to_be_found_symbols.should include(:local)
+ ObjectSpaceFixtures.to_be_found_symbols.should.include?(:local)
end
it "finds an object stored in a local variable captured in a block explicitly" do
@@ -69,7 +69,7 @@ describe "ObjectSpace.each_object" do
Proc.new { local_in_block }
}.call
- ObjectSpaceFixtures.to_be_found_symbols.should include(:local_in_block_explicit)
+ ObjectSpaceFixtures.to_be_found_symbols.should.include?(:local_in_block_explicit)
end
it "finds an object stored in a local variable captured in a block implicitly" do
@@ -78,11 +78,11 @@ describe "ObjectSpace.each_object" do
Proc.new { }
}.call
- ObjectSpaceFixtures.to_be_found_symbols.should include(:local_in_block_implicit)
+ ObjectSpaceFixtures.to_be_found_symbols.should.include?(:local_in_block_implicit)
end
it "finds an object stored in a local variable captured in by a method defined with a block" do
- ObjectSpaceFixtures.to_be_found_symbols.should include(:captured_by_define_method)
+ ObjectSpaceFixtures.to_be_found_symbols.should.include?(:captured_by_define_method)
end
it "finds an object stored in a local variable captured in a Proc#binding" do
@@ -91,7 +91,7 @@ describe "ObjectSpace.each_object" do
Proc.new { }.binding
}.call
- ObjectSpaceFixtures.to_be_found_symbols.should include(:local_in_proc_binding)
+ ObjectSpaceFixtures.to_be_found_symbols.should.include?(:local_in_proc_binding)
end
it "finds an object stored in a local variable captured in a Kernel#binding" do
@@ -100,45 +100,45 @@ describe "ObjectSpace.each_object" do
binding
}.call
- ObjectSpaceFixtures.to_be_found_symbols.should include(:local_in_kernel_binding)
+ ObjectSpaceFixtures.to_be_found_symbols.should.include?(:local_in_kernel_binding)
end
it "finds an object stored in a local variable set in a binding manually" do
b = binding
b.eval("local = ObjectSpaceFixtures::ObjectToBeFound.new(:local_in_manual_binding)")
- ObjectSpaceFixtures.to_be_found_symbols.should include(:local_in_manual_binding)
+ ObjectSpaceFixtures.to_be_found_symbols.should.include?(:local_in_manual_binding)
end
it "finds an object stored in an array" do
array = [ObjectSpaceFixtures::ObjectToBeFound.new(:array)]
- ObjectSpaceFixtures.to_be_found_symbols.should include(:array)
+ ObjectSpaceFixtures.to_be_found_symbols.should.include?(:array)
end
it "finds an object stored in a hash key" do
hash = {ObjectSpaceFixtures::ObjectToBeFound.new(:hash_key) => :value}
- ObjectSpaceFixtures.to_be_found_symbols.should include(:hash_key)
+ ObjectSpaceFixtures.to_be_found_symbols.should.include?(:hash_key)
end
it "finds an object stored in a hash value" do
hash = {a: ObjectSpaceFixtures::ObjectToBeFound.new(:hash_value)}
- ObjectSpaceFixtures.to_be_found_symbols.should include(:hash_value)
+ ObjectSpaceFixtures.to_be_found_symbols.should.include?(:hash_value)
end
it "finds an object stored in an instance variable" do
local = ObjectSpaceFixtures::ObjectWithInstanceVariable.new
- ObjectSpaceFixtures.to_be_found_symbols.should include(:instance_variable)
+ ObjectSpaceFixtures.to_be_found_symbols.should.include?(:instance_variable)
end
it "finds an object stored in a thread local" do
thread = Thread.new {}
thread.thread_variable_set(:object_space_thread_local, ObjectSpaceFixtures::ObjectToBeFound.new(:thread_local))
- ObjectSpaceFixtures.to_be_found_symbols.should include(:thread_local)
+ ObjectSpaceFixtures.to_be_found_symbols.should.include?(:thread_local)
thread.join
end
it "finds an object stored in a fiber local" do
Thread.current[:object_space_fiber_local] = ObjectSpaceFixtures::ObjectToBeFound.new(:fiber_local)
- ObjectSpaceFixtures.to_be_found_symbols.should include(:fiber_local)
+ ObjectSpaceFixtures.to_be_found_symbols.should.include?(:fiber_local)
end
it "finds an object captured in an at_exit handler" do
@@ -150,7 +150,7 @@ describe "ObjectSpace.each_object" do
end
}.call
- ObjectSpaceFixtures.to_be_found_symbols.should include(:at_exit)
+ ObjectSpaceFixtures.to_be_found_symbols.should.include?(:at_exit)
end
it "finds an object captured in finalizer" do
@@ -164,9 +164,9 @@ describe "ObjectSpace.each_object" do
})
}.call
- ObjectSpaceFixtures.to_be_found_symbols.should include(:finalizer)
+ ObjectSpaceFixtures.to_be_found_symbols.should.include?(:finalizer)
- alive.should_not be_nil
+ alive.should_not == nil
end
describe "on singleton classes" do
@@ -184,18 +184,9 @@ describe "ObjectSpace.each_object" do
hidden.should == nil
end
- ruby_version_is ""..."2.3" do
- it "does not walk singleton classes" do
- @sclass.should be_kind_of(@meta)
- ObjectSpace.each_object(@meta).to_a.should_not include(@sclass)
- end
- end
-
- ruby_version_is "2.3" do
- it "walks singleton classes" do
- @sclass.should be_kind_of(@meta)
- ObjectSpace.each_object(@meta).to_a.should include(@sclass)
- end
+ it "walks singleton classes" do
+ @sclass.should.is_a?(@meta)
+ ObjectSpace.each_object(@meta).to_a.should.include?(@sclass)
end
end
@@ -210,11 +201,8 @@ describe "ObjectSpace.each_object" do
expected = [ a, b, c, d ]
- # singleton classes should be walked only on >= 2.3
- ruby_version_is "2.3" do
- expected << c_sclass
- c_sclass.should be_kind_of(a.singleton_class)
- end
+ expected << c_sclass
+ c_sclass.should.is_a?(a.singleton_class)
b.extend Enumerable # included modules should not be walked
diff --git a/spec/ruby/core/objectspace/finalizers_spec.rb b/spec/ruby/core/objectspace/finalizers_spec.rb
deleted file mode 100644
index 8d5f6cc029..0000000000
--- a/spec/ruby/core/objectspace/finalizers_spec.rb
+++ /dev/null
@@ -1,5 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "ObjectSpace.finalizers" do
- it "needs to be reviewed for spec completeness"
-end
diff --git a/spec/ruby/core/objectspace/fixtures/classes.rb b/spec/ruby/core/objectspace/fixtures/classes.rb
index 9a4b0aa865..612156c180 100644
--- a/spec/ruby/core/objectspace/fixtures/classes.rb
+++ b/spec/ruby/core/objectspace/fixtures/classes.rb
@@ -24,7 +24,7 @@ module ObjectSpaceFixtures
end
def self.define_finalizer
- handler = lambda { |obj| ScratchPad.record :finalized }
+ handler = -> obj { ScratchPad.record :finalized }
ObjectSpace.define_finalizer "#{rand 5}", handler
end
diff --git a/spec/ruby/core/objectspace/garbage_collect_spec.rb b/spec/ruby/core/objectspace/garbage_collect_spec.rb
index aa7e233b25..d2db22e0aa 100644
--- a/spec/ruby/core/objectspace/garbage_collect_spec.rb
+++ b/spec/ruby/core/objectspace/garbage_collect_spec.rb
@@ -1,17 +1,17 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "ObjectSpace.garbage_collect" do
it "can be invoked without any exceptions" do
- lambda { ObjectSpace.garbage_collect }.should_not raise_error
+ -> { ObjectSpace.garbage_collect }.should_not.raise
end
- it "doesn't accept any arguments" do
- lambda { ObjectSpace.garbage_collect(1) }.should raise_error(ArgumentError)
+ it "accepts keyword arguments" do
+ ObjectSpace.garbage_collect(full_mark: true, immediate_sweep: true).should == nil
end
it "ignores the supplied block" do
- lambda { ObjectSpace.garbage_collect {} }.should_not raise_error
+ -> { ObjectSpace.garbage_collect {} }.should_not.raise
end
it "always returns nil" do
diff --git a/spec/ruby/core/objectspace/remove_finalizer_spec.rb b/spec/ruby/core/objectspace/remove_finalizer_spec.rb
deleted file mode 100644
index 3053c31511..0000000000
--- a/spec/ruby/core/objectspace/remove_finalizer_spec.rb
+++ /dev/null
@@ -1,5 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "ObjectSpace.remove_finalizer" do
- it "needs to be reviewed for spec completeness"
-end
diff --git a/spec/ruby/core/objectspace/undefine_finalizer_spec.rb b/spec/ruby/core/objectspace/undefine_finalizer_spec.rb
index 98f521db98..98ffc6a986 100644
--- a/spec/ruby/core/objectspace/undefine_finalizer_spec.rb
+++ b/spec/ruby/core/objectspace/undefine_finalizer_spec.rb
@@ -1,5 +1,33 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "ObjectSpace.undefine_finalizer" do
- it "needs to be reviewed for spec completeness"
+ it "removes finalizers for an object" do
+ code = <<~RUBY
+ obj = Object.new
+ ObjectSpace.define_finalizer(obj, proc { |id| puts "hello" })
+ ObjectSpace.undefine_finalizer(obj)
+ RUBY
+
+ ruby_exe(code).should.empty?
+ end
+
+ it "should not remove finalizers for a frozen object" do
+ code = <<~RUBY
+ obj = Object.new
+ ObjectSpace.define_finalizer(obj, proc { |id| print "ok" })
+ obj.freeze
+ begin
+ ObjectSpace.undefine_finalizer(obj)
+ rescue
+ end
+ RUBY
+
+ ruby_exe(code).should == "ok"
+ end
+
+ it "should raise when removing finalizers for a frozen object" do
+ obj = Object.new
+ obj.freeze
+ -> { ObjectSpace.undefine_finalizer(obj) }.should.raise(FrozenError)
+ end
end
diff --git a/spec/ruby/core/objectspace/weakkeymap/clear_spec.rb b/spec/ruby/core/objectspace/weakkeymap/clear_spec.rb
new file mode 100644
index 0000000000..b1804ec9b0
--- /dev/null
+++ b/spec/ruby/core/objectspace/weakkeymap/clear_spec.rb
@@ -0,0 +1,25 @@
+require_relative '../../../spec_helper'
+
+describe "ObjectSpace::WeakKeyMap#clear" do
+ it "removes all the entries" do
+ m = ObjectSpace::WeakKeyMap.new
+
+ key = Object.new
+ value = Object.new
+ m[key] = value
+
+ key2 = Object.new
+ value2 = Object.new
+ m[key2] = value2
+
+ m.clear
+
+ m.key?(key).should == false
+ m.key?(key2).should == false
+ end
+
+ it "returns self" do
+ m = ObjectSpace::WeakKeyMap.new
+ m.clear.should.equal?(m)
+ end
+end
diff --git a/spec/ruby/core/objectspace/weakkeymap/delete_spec.rb b/spec/ruby/core/objectspace/weakkeymap/delete_spec.rb
new file mode 100644
index 0000000000..ad32c2c75e
--- /dev/null
+++ b/spec/ruby/core/objectspace/weakkeymap/delete_spec.rb
@@ -0,0 +1,49 @@
+require_relative '../../../spec_helper'
+
+describe "ObjectSpace::WeakKeyMap#delete" do
+ it "removes the entry and returns the deleted value" do
+ m = ObjectSpace::WeakKeyMap.new
+ key = Object.new
+ value = Object.new
+ m[key] = value
+
+ m.delete(key).should == value
+ m.key?(key).should == false
+ end
+
+ it "uses equality semantic" do
+ m = ObjectSpace::WeakKeyMap.new
+ key = "foo".upcase
+ value = Object.new
+ m[key] = value
+
+ m.delete("foo".upcase).should == value
+ m.key?(key).should == false
+ end
+
+ it "calls supplied block if the key is not found" do
+ key = Object.new
+ m = ObjectSpace::WeakKeyMap.new
+ return_value = m.delete(key) do |yielded_key|
+ yielded_key.should == key
+ 5
+ end
+ return_value.should == 5
+ end
+
+ it "returns nil if the key is not found when no block is given" do
+ m = ObjectSpace::WeakKeyMap.new
+ m.delete(Object.new).should == nil
+ end
+
+ it "returns nil when a key cannot be garbage collected" do
+ map = ObjectSpace::WeakKeyMap.new
+
+ map.delete(1).should == nil
+ map.delete(1.0).should == nil
+ map.delete(:a).should == nil
+ map.delete(true).should == nil
+ map.delete(false).should == nil
+ map.delete(nil).should == nil
+ end
+end
diff --git a/spec/ruby/core/objectspace/weakkeymap/element_reference_spec.rb b/spec/ruby/core/objectspace/weakkeymap/element_reference_spec.rb
new file mode 100644
index 0000000000..53eff79c40
--- /dev/null
+++ b/spec/ruby/core/objectspace/weakkeymap/element_reference_spec.rb
@@ -0,0 +1,105 @@
+require_relative '../../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe "ObjectSpace::WeakKeyMap#[]" do
+ it "is faithful to the map's content" do
+ map = ObjectSpace::WeakKeyMap.new
+ key1, key2 = %w[a b].map(&:upcase)
+ ref1, ref2 = %w[x y]
+ map[key1] = ref1
+ map[key1].should == ref1
+ map[key1] = ref1
+ map[key1].should == ref1
+ map[key2] = ref2
+ map[key1].should == ref1
+ map[key2].should == ref2
+ end
+
+ it "compares keys with #eql? semantics" do
+ map = ObjectSpace::WeakKeyMap.new
+ key = [1.0]
+ map[key] = "x"
+ map[[1]].should == nil
+ map[[1.0]].should == "x"
+ key.should == [1.0] # keep the key alive until here to keep the map entry
+
+ map = ObjectSpace::WeakKeyMap.new
+ key = [1]
+ map[key] = "x"
+ map[[1.0]].should == nil
+ map[[1]].should == "x"
+ key.should == [1] # keep the key alive until here to keep the map entry
+
+ map = ObjectSpace::WeakKeyMap.new
+ key1, key2 = %w[a a].map(&:upcase)
+ ref = "x"
+ map[key1] = ref
+ map[key2].should == ref
+ end
+
+ it "compares key via #hash first" do
+ x = mock('0')
+ x.should_receive(:hash).and_return(0)
+
+ map = ObjectSpace::WeakKeyMap.new
+ key = 'foo'
+ map[key] = :bar
+ map[x].should == nil
+ end
+
+ it "does not compare keys with different #hash values via #eql?" do
+ x = mock('x')
+ x.should_not_receive(:eql?)
+ x.stub!(:hash).and_return(0)
+
+ y = mock('y')
+ y.should_not_receive(:eql?)
+ y.stub!(:hash).and_return(1)
+
+ map = ObjectSpace::WeakKeyMap.new
+ map[y] = 1
+ map[x].should == nil
+ end
+
+ it "compares keys with the same #hash value via #eql?" do
+ x = mock('x')
+ x.should_receive(:eql?).and_return(true)
+ x.stub!(:hash).and_return(42)
+
+ y = mock('y')
+ y.should_not_receive(:eql?)
+ y.stub!(:hash).and_return(42)
+
+ map = ObjectSpace::WeakKeyMap.new
+ map[y] = 1
+ map[x].should == 1
+ end
+
+ it "finds a value via an identical key even when its #eql? isn't reflexive" do
+ x = mock('x')
+ x.should_receive(:hash).at_least(1).and_return(42)
+ x.stub!(:eql?).and_return(false) # Stubbed for clarity and latitude in implementation; not actually sent by MRI.
+
+ map = ObjectSpace::WeakKeyMap.new
+ map[x] = :x
+ map[x].should == :x
+ end
+
+ it "supports keys with private #hash method" do
+ key = WeakKeyMapSpecs::KeyWithPrivateHash.new
+ map = ObjectSpace::WeakKeyMap.new
+ map[key] = 42
+ map[key].should == 42
+ end
+
+ it "returns nil and does not raise error when a key cannot be garbage collected" do
+ map = ObjectSpace::WeakKeyMap.new
+
+ map[1].should == nil
+ map[1.0].should == nil
+ map[:a].should == nil
+ map[true].should == nil
+ map[false].should == nil
+ map[nil].should == nil
+ end
+end
diff --git a/spec/ruby/core/objectspace/weakkeymap/element_set_spec.rb b/spec/ruby/core/objectspace/weakkeymap/element_set_spec.rb
new file mode 100644
index 0000000000..cf59aebc6f
--- /dev/null
+++ b/spec/ruby/core/objectspace/weakkeymap/element_set_spec.rb
@@ -0,0 +1,80 @@
+require_relative '../../../spec_helper'
+
+describe "ObjectSpace::WeakKeyMap#[]=" do
+ def should_accept(map, key, value)
+ (map[key] = value).should == value
+ map.should.key?(key)
+ map[key].should == value
+ end
+
+ it "is correct" do
+ map = ObjectSpace::WeakKeyMap.new
+ key1, key2 = %w[a b].map(&:upcase)
+ ref1, ref2 = %w[x y]
+ should_accept(map, key1, ref1)
+ should_accept(map, key1, ref1)
+ should_accept(map, key2, ref2)
+ map[key1].should == ref1
+ end
+
+ it "requires the keys to implement #hash" do
+ map = ObjectSpace::WeakKeyMap.new
+ -> { map[BasicObject.new] = 1 }.should.raise(NoMethodError, /undefined method [`']hash' for an instance of BasicObject/)
+ end
+
+ it "accepts frozen keys or values" do
+ map = ObjectSpace::WeakKeyMap.new
+ x = Object.new
+ should_accept(map, x, true)
+ should_accept(map, x, false)
+ should_accept(map, x, 42)
+ should_accept(map, x, :foo)
+
+ y = Object.new.freeze
+ should_accept(map, x, y)
+ should_accept(map, y, x)
+ end
+
+ it "does not duplicate and freeze String keys (like Hash#[]= does)" do
+ map = ObjectSpace::WeakKeyMap.new
+ key = +"a"
+ map[key] = 1
+
+ map.getkey("a").should.equal? key
+ map.getkey("a").should_not.frozen?
+
+ key.should == "a" # keep the key alive until here to keep the map entry
+ end
+
+ context "a key cannot be garbage collected" do
+ it "raises ArgumentError when Integer is used as a key" do
+ map = ObjectSpace::WeakKeyMap.new
+ -> { map[1] = "x" }.should.raise(ArgumentError, /WeakKeyMap (keys )?must be garbage collectable/)
+ end
+
+ it "raises ArgumentError when Float is used as a key" do
+ map = ObjectSpace::WeakKeyMap.new
+ -> { map[1.0] = "x" }.should.raise(ArgumentError, /WeakKeyMap (keys )?must be garbage collectable/)
+ end
+
+ it "raises ArgumentError when Symbol is used as a key" do
+ map = ObjectSpace::WeakKeyMap.new
+ -> { map[:a] = "x" }.should.raise(ArgumentError, /WeakKeyMap (keys )?must be garbage collectable/)
+ end
+
+ it "raises ArgumentError when true is used as a key" do
+ map = ObjectSpace::WeakKeyMap.new
+ -> { map[true] = "x" }.should.raise(ArgumentError, /WeakKeyMap (keys )?must be garbage collectable/)
+ end
+
+ it "raises ArgumentError when false is used as a key" do
+ map = ObjectSpace::WeakKeyMap.new
+ -> { map[false] = "x" }.should.raise(ArgumentError, /WeakKeyMap (keys )?must be garbage collectable/)
+ end
+
+ it "raises ArgumentError when nil is used as a key" do
+ map = ObjectSpace::WeakKeyMap.new
+ -> { map[nil] = "x" }.should.raise(ArgumentError, /WeakKeyMap (keys )?must be garbage collectable/)
+ end
+ end
+end
diff --git a/spec/ruby/core/objectspace/weakkeymap/fixtures/classes.rb b/spec/ruby/core/objectspace/weakkeymap/fixtures/classes.rb
new file mode 100644
index 0000000000..0fd04551b5
--- /dev/null
+++ b/spec/ruby/core/objectspace/weakkeymap/fixtures/classes.rb
@@ -0,0 +1,5 @@
+module WeakKeyMapSpecs
+ class KeyWithPrivateHash
+ private :hash
+ end
+end
diff --git a/spec/ruby/core/objectspace/weakkeymap/getkey_spec.rb b/spec/ruby/core/objectspace/weakkeymap/getkey_spec.rb
new file mode 100644
index 0000000000..798a2e2cda
--- /dev/null
+++ b/spec/ruby/core/objectspace/weakkeymap/getkey_spec.rb
@@ -0,0 +1,26 @@
+require_relative '../../../spec_helper'
+
+describe "ObjectSpace::WeakKeyMap#getkey" do
+ it "returns the existing equal key" do
+ map = ObjectSpace::WeakKeyMap.new
+ key1, key2 = %w[a a].map(&:upcase)
+
+ map[key1] = true
+ map.getkey(key2).should.equal?(key1)
+ map.getkey("X").should == nil
+
+ key1.should == "A" # keep the key alive until here to keep the map entry
+ key2.should == "A" # keep the key alive until here to keep the map entry
+ end
+
+ it "returns nil when a key cannot be garbage collected" do
+ map = ObjectSpace::WeakKeyMap.new
+
+ map.getkey(1).should == nil
+ map.getkey(1.0).should == nil
+ map.getkey(:a).should == nil
+ map.getkey(true).should == nil
+ map.getkey(false).should == nil
+ map.getkey(nil).should == nil
+ end
+end
diff --git a/spec/ruby/core/objectspace/weakkeymap/inspect_spec.rb b/spec/ruby/core/objectspace/weakkeymap/inspect_spec.rb
new file mode 100644
index 0000000000..b6bb469158
--- /dev/null
+++ b/spec/ruby/core/objectspace/weakkeymap/inspect_spec.rb
@@ -0,0 +1,19 @@
+require_relative '../../../spec_helper'
+
+describe "ObjectSpace::WeakKeyMap#inspect" do
+ it "only displays size in output" do
+ map = ObjectSpace::WeakKeyMap.new
+ key1, key2, key3 = "foo", "bar", "bar"
+ map.inspect.should =~ /\A\#<ObjectSpace::WeakKeyMap:0x\h+ size=0>\z/
+ map[key1] = 1
+ map.inspect.should =~ /\A\#<ObjectSpace::WeakKeyMap:0x\h+ size=1>\z/
+ map[key2] = 2
+ map.inspect.should =~ /\A\#<ObjectSpace::WeakKeyMap:0x\h+ size=2>\z/
+ map[key3] = 3
+ map.inspect.should =~ /\A\#<ObjectSpace::WeakKeyMap:0x\h+ size=2>\z/
+
+ key1.should == "foo" # keep the key alive until here to keep the map entry
+ key2.should == "bar" # keep the key alive until here to keep the map entry
+ key3.should == "bar" # keep the key alive until here to keep the map entry
+ end
+end
diff --git a/spec/ruby/core/objectspace/weakkeymap/key_spec.rb b/spec/ruby/core/objectspace/weakkeymap/key_spec.rb
new file mode 100644
index 0000000000..e0b6866671
--- /dev/null
+++ b/spec/ruby/core/objectspace/weakkeymap/key_spec.rb
@@ -0,0 +1,42 @@
+require_relative '../../../spec_helper'
+
+describe "ObjectSpace::WeakKeyMap#key?" do
+ it "recognizes keys in use" do
+ map = ObjectSpace::WeakKeyMap.new
+ key1, key2 = %w[a b].map(&:upcase)
+ ref1, ref2 = %w[x y]
+
+ map[key1] = ref1
+ map.key?(key1).should == true
+ map[key1] = ref1
+ map.key?(key1).should == true
+ map[key2] = ref2
+ map.key?(key2).should == true
+ end
+
+ it "matches using equality semantics" do
+ map = ObjectSpace::WeakKeyMap.new
+ key1, key2 = %w[a a].map(&:upcase)
+ ref = "x"
+ map[key1] = ref
+ map.key?(key2).should == true
+ end
+
+ it "reports true if the pair exists and the value is nil" do
+ map = ObjectSpace::WeakKeyMap.new
+ key = Object.new
+ map[key] = nil
+ map.key?(key).should == true
+ end
+
+ it "returns false when a key cannot be garbage collected" do
+ map = ObjectSpace::WeakKeyMap.new
+
+ map.key?(1).should == false
+ map.key?(1.0).should == false
+ map.key?(:a).should == false
+ map.key?(true).should == false
+ map.key?(false).should == false
+ map.key?(nil).should == false
+ end
+end
diff --git a/spec/ruby/core/objectspace/weakmap/delete_spec.rb b/spec/ruby/core/objectspace/weakmap/delete_spec.rb
new file mode 100644
index 0000000000..03beebbb83
--- /dev/null
+++ b/spec/ruby/core/objectspace/weakmap/delete_spec.rb
@@ -0,0 +1,28 @@
+require_relative '../../../spec_helper'
+
+describe "ObjectSpace::WeakMap#delete" do
+ it "removes the entry and returns the deleted value" do
+ m = ObjectSpace::WeakMap.new
+ key = Object.new
+ value = Object.new
+ m[key] = value
+
+ m.delete(key).should == value
+ m.key?(key).should == false
+ end
+
+ it "calls supplied block if the key is not found" do
+ key = Object.new
+ m = ObjectSpace::WeakMap.new
+ return_value = m.delete(key) do |yielded_key|
+ yielded_key.should == key
+ 5
+ end
+ return_value.should == 5
+ end
+
+ it "returns nil if the key is not found when no block is given" do
+ m = ObjectSpace::WeakMap.new
+ m.delete(Object.new).should == nil
+ end
+end
diff --git a/spec/ruby/core/objectspace/weakmap/each_key_spec.rb b/spec/ruby/core/objectspace/weakmap/each_key_spec.rb
new file mode 100644
index 0000000000..df971deeb9
--- /dev/null
+++ b/spec/ruby/core/objectspace/weakmap/each_key_spec.rb
@@ -0,0 +1,11 @@
+require_relative '../../../spec_helper'
+require_relative 'shared/members'
+require_relative 'shared/each'
+
+describe "ObjectSpace::WeakMap#each_key" do
+ it_behaves_like :weakmap_members, -> map { a = []; map.each_key{ |k| a << k }; a }, %w[A B]
+end
+
+describe "ObjectSpace::WeakMap#each_key" do
+ it_behaves_like :weakmap_each, :each_key
+end
diff --git a/spec/ruby/core/objectspace/weakmap/each_pair_spec.rb b/spec/ruby/core/objectspace/weakmap/each_pair_spec.rb
new file mode 100644
index 0000000000..272669ad0a
--- /dev/null
+++ b/spec/ruby/core/objectspace/weakmap/each_pair_spec.rb
@@ -0,0 +1,8 @@
+require_relative '../../../spec_helper'
+
+describe "ObjectSpace::WeakMap#each_pair" do
+ it "is an alias of ObjectSpace::WeakMap#each" do
+ ObjectSpace::WeakMap.instance_method(:each_pair).should ==
+ ObjectSpace::WeakMap.instance_method(:each)
+ end
+end
diff --git a/spec/ruby/core/objectspace/weakmap/each_spec.rb b/spec/ruby/core/objectspace/weakmap/each_spec.rb
new file mode 100644
index 0000000000..8493a36158
--- /dev/null
+++ b/spec/ruby/core/objectspace/weakmap/each_spec.rb
@@ -0,0 +1,11 @@
+require_relative '../../../spec_helper'
+require_relative 'shared/members'
+require_relative 'shared/each'
+
+describe "ObjectSpace::WeakMap#each" do
+ it_behaves_like :weakmap_members, -> map { a = []; map.each{ |k,v| a << "#{k}#{v}" }; a }, %w[Ax By]
+end
+
+describe "ObjectSpace::WeakMap#each" do
+ it_behaves_like :weakmap_each, :each
+end
diff --git a/spec/ruby/core/objectspace/weakmap/each_value_spec.rb b/spec/ruby/core/objectspace/weakmap/each_value_spec.rb
new file mode 100644
index 0000000000..89f2f6ae98
--- /dev/null
+++ b/spec/ruby/core/objectspace/weakmap/each_value_spec.rb
@@ -0,0 +1,11 @@
+require_relative '../../../spec_helper'
+require_relative 'shared/members'
+require_relative 'shared/each'
+
+describe "ObjectSpace::WeakMap#each_value" do
+ it_behaves_like :weakmap_members, -> map { a = []; map.each_value{ |k| a << k }; a }, %w[x y]
+end
+
+describe "ObjectSpace::WeakMap#each_value" do
+ it_behaves_like :weakmap_each, :each_value
+end
diff --git a/spec/ruby/core/objectspace/weakmap/element_reference_spec.rb b/spec/ruby/core/objectspace/weakmap/element_reference_spec.rb
new file mode 100644
index 0000000000..cb3174cbfa
--- /dev/null
+++ b/spec/ruby/core/objectspace/weakmap/element_reference_spec.rb
@@ -0,0 +1,24 @@
+require_relative '../../../spec_helper'
+
+describe "ObjectSpace::WeakMap#[]" do
+ it "is faithful to the map's content" do
+ map = ObjectSpace::WeakMap.new
+ key1, key2 = %w[a b].map(&:upcase)
+ ref1, ref2 = %w[x y]
+ map[key1] = ref1
+ map[key1].should == ref1
+ map[key1] = ref1
+ map[key1].should == ref1
+ map[key2] = ref2
+ map[key1].should == ref1
+ map[key2].should == ref2
+ end
+
+ it "matches using identity semantics" do
+ map = ObjectSpace::WeakMap.new
+ key1, key2 = %w[a a].map(&:upcase)
+ ref = "x"
+ map[key1] = ref
+ map[key2].should == nil
+ end
+end
diff --git a/spec/ruby/core/objectspace/weakmap/element_set_spec.rb b/spec/ruby/core/objectspace/weakmap/element_set_spec.rb
new file mode 100644
index 0000000000..8588877158
--- /dev/null
+++ b/spec/ruby/core/objectspace/weakmap/element_set_spec.rb
@@ -0,0 +1,38 @@
+require_relative '../../../spec_helper'
+
+describe "ObjectSpace::WeakMap#[]=" do
+ def should_accept(map, key, value)
+ (map[key] = value).should == value
+ map.should.key?(key)
+ map[key].should == value
+ end
+
+ it "is correct" do
+ map = ObjectSpace::WeakMap.new
+ key1, key2 = %w[a b].map(&:upcase)
+ ref1, ref2 = %w[x y]
+ should_accept(map, key1, ref1)
+ should_accept(map, key1, ref1)
+ should_accept(map, key2, ref2)
+ map[key1].should == ref1
+ end
+
+ it "accepts primitive or frozen keys or values" do
+ map = ObjectSpace::WeakMap.new
+ x = Object.new
+ should_accept(map, true, x)
+ should_accept(map, false, x)
+ should_accept(map, nil, x)
+ should_accept(map, 42, x)
+ should_accept(map, :foo, x)
+
+ should_accept(map, x, true)
+ should_accept(map, x, false)
+ should_accept(map, x, 42)
+ should_accept(map, x, :foo)
+
+ y = Object.new.freeze
+ should_accept(map, x, y)
+ should_accept(map, y, x)
+ end
+end
diff --git a/spec/ruby/core/objectspace/weakmap/include_spec.rb b/spec/ruby/core/objectspace/weakmap/include_spec.rb
new file mode 100644
index 0000000000..1affaef907
--- /dev/null
+++ b/spec/ruby/core/objectspace/weakmap/include_spec.rb
@@ -0,0 +1,32 @@
+require_relative '../../../spec_helper'
+
+describe "ObjectSpace::WeakMap#include?" do
+ it "recognizes keys in use" do
+ map = ObjectSpace::WeakMap.new
+ key1, key2 = %w[a b].map(&:upcase)
+ ref1, ref2 = %w[x y]
+
+ map[key1] = ref1
+ map.include?(key1).should == true
+ map[key1] = ref1
+ map.include?(key1).should == true
+ map[key2] = ref2
+ map.include?(key2).should == true
+ end
+
+ it "matches using identity semantics" do
+ map = ObjectSpace::WeakMap.new
+ key1, key2 = %w[a a].map(&:upcase)
+ ref = "x"
+ map[key1] = ref
+ map.include?(key2).should == false
+ end
+
+ it "reports true if the pair exists and the value is nil" do
+ map = ObjectSpace::WeakMap.new
+ key = Object.new
+ map[key] = nil
+ map.size.should == 1
+ map.include?(key).should == true
+ end
+end
diff --git a/spec/ruby/core/objectspace/weakmap/inspect_spec.rb b/spec/ruby/core/objectspace/weakmap/inspect_spec.rb
new file mode 100644
index 0000000000..f064f6e3ea
--- /dev/null
+++ b/spec/ruby/core/objectspace/weakmap/inspect_spec.rb
@@ -0,0 +1,25 @@
+require_relative '../../../spec_helper'
+
+describe "ObjectSpace::WeakMap#inspect" do
+ it "displays object pointers in output" do
+ map = ObjectSpace::WeakMap.new
+ # important to test with BasicObject (without Kernel) here to test edge cases
+ key1, key2 = [BasicObject.new, Object.new]
+ ref1, ref2 = [BasicObject.new, Object.new]
+ map.inspect.should =~ /\A\#<ObjectSpace::WeakMap:0x\h+>\z/
+ map[key1] = ref1
+ map.inspect.should =~ /\A\#<ObjectSpace::WeakMap:0x\h+: \#<BasicObject:0x\h+> => \#<BasicObject:0x\h+>>\z/
+ map[key1] = ref1
+ map.inspect.should =~ /\A\#<ObjectSpace::WeakMap:0x\h+: \#<BasicObject:0x\h+> => \#<BasicObject:0x\h+>>\z/
+ map[key2] = ref2
+
+ regexp1 = /\A\#<ObjectSpace::WeakMap:0x\h+: \#<BasicObject:0x\h+> => \#<BasicObject:0x\h+>, \#<Object:0x\h+> => \#<Object:0x\h+>>\z/
+ regexp2 = /\A\#<ObjectSpace::WeakMap:0x\h+: \#<Object:0x\h+> => \#<Object:0x\h+>, \#<BasicObject:0x\h+> => \#<BasicObject:0x\h+>>\z/
+ str = map.inspect
+ if str =~ regexp1
+ str.should =~ regexp1
+ else
+ str.should =~ regexp2
+ end
+ end
+end
diff --git a/spec/ruby/core/objectspace/weakmap/key_spec.rb b/spec/ruby/core/objectspace/weakmap/key_spec.rb
new file mode 100644
index 0000000000..5d38f1fa5f
--- /dev/null
+++ b/spec/ruby/core/objectspace/weakmap/key_spec.rb
@@ -0,0 +1,8 @@
+require_relative '../../../spec_helper'
+
+describe "ObjectSpace::WeakMap#key?" do
+ it "is an alias of ObjectSpace::WeakMap#include?" do
+ ObjectSpace::WeakMap.instance_method(:key?).should ==
+ ObjectSpace::WeakMap.instance_method(:include?)
+ end
+end
diff --git a/spec/ruby/core/objectspace/weakmap/keys_spec.rb b/spec/ruby/core/objectspace/weakmap/keys_spec.rb
new file mode 100644
index 0000000000..7b1494bdd7
--- /dev/null
+++ b/spec/ruby/core/objectspace/weakmap/keys_spec.rb
@@ -0,0 +1,6 @@
+require_relative '../../../spec_helper'
+require_relative 'shared/members'
+
+describe "ObjectSpace::WeakMap#keys" do
+ it_behaves_like :weakmap_members, -> map { map.keys }, %w[A B]
+end
diff --git a/spec/ruby/core/objectspace/weakmap/length_spec.rb b/spec/ruby/core/objectspace/weakmap/length_spec.rb
new file mode 100644
index 0000000000..8ad47aa9d6
--- /dev/null
+++ b/spec/ruby/core/objectspace/weakmap/length_spec.rb
@@ -0,0 +1,8 @@
+require_relative '../../../spec_helper'
+
+describe "ObjectSpace::WeakMap#length" do
+ it "is an alias of ObjectSpace::WeakMap#size" do
+ ObjectSpace::WeakMap.instance_method(:length).should ==
+ ObjectSpace::WeakMap.instance_method(:size)
+ end
+end
diff --git a/spec/ruby/core/objectspace/weakmap/member_spec.rb b/spec/ruby/core/objectspace/weakmap/member_spec.rb
new file mode 100644
index 0000000000..eaf9a76285
--- /dev/null
+++ b/spec/ruby/core/objectspace/weakmap/member_spec.rb
@@ -0,0 +1,8 @@
+require_relative '../../../spec_helper'
+
+describe "ObjectSpace::WeakMap#member?" do
+ it "is an alias of ObjectSpace::WeakMap#include?" do
+ ObjectSpace::WeakMap.instance_method(:member?).should ==
+ ObjectSpace::WeakMap.instance_method(:include?)
+ end
+end
diff --git a/spec/ruby/core/objectspace/weakmap/shared/each.rb b/spec/ruby/core/objectspace/weakmap/shared/each.rb
new file mode 100644
index 0000000000..771c416dde
--- /dev/null
+++ b/spec/ruby/core/objectspace/weakmap/shared/each.rb
@@ -0,0 +1,10 @@
+describe :weakmap_each, shared: true do
+ it "must take a block, except when empty" do
+ map = ObjectSpace::WeakMap.new
+ key = "a".upcase
+ ref = "x"
+ map.send(@method).should == map
+ map[key] = ref
+ -> { map.send(@method) }.should.raise(LocalJumpError)
+ end
+end
diff --git a/spec/ruby/core/objectspace/weakmap/shared/members.rb b/spec/ruby/core/objectspace/weakmap/shared/members.rb
new file mode 100644
index 0000000000..57226c8d7a
--- /dev/null
+++ b/spec/ruby/core/objectspace/weakmap/shared/members.rb
@@ -0,0 +1,14 @@
+describe :weakmap_members, shared: true do
+ it "is correct" do
+ map = ObjectSpace::WeakMap.new
+ key1, key2 = %w[a b].map(&:upcase)
+ ref1, ref2 = %w[x y]
+ @method.call(map).should == []
+ map[key1] = ref1
+ @method.call(map).should == @object[0..0]
+ map[key1] = ref1
+ @method.call(map).should == @object[0..0]
+ map[key2] = ref2
+ @method.call(map).sort.should == @object
+ end
+end
diff --git a/spec/ruby/core/objectspace/weakmap/size_spec.rb b/spec/ruby/core/objectspace/weakmap/size_spec.rb
new file mode 100644
index 0000000000..d301750c62
--- /dev/null
+++ b/spec/ruby/core/objectspace/weakmap/size_spec.rb
@@ -0,0 +1,16 @@
+require_relative '../../../spec_helper'
+
+describe "ObjectSpace::WeakMap#size" do
+ it "is correct" do
+ map = ObjectSpace::WeakMap.new
+ key1, key2 = %w[a b].map(&:upcase)
+ ref1, ref2 = %w[x y]
+ map.size.should == 0
+ map[key1] = ref1
+ map.size.should == 1
+ map[key1] = ref1
+ map.size.should == 1
+ map[key2] = ref2
+ map.size.should == 2
+ end
+end
diff --git a/spec/ruby/core/objectspace/weakmap/values_spec.rb b/spec/ruby/core/objectspace/weakmap/values_spec.rb
new file mode 100644
index 0000000000..6f6f90d0ba
--- /dev/null
+++ b/spec/ruby/core/objectspace/weakmap/values_spec.rb
@@ -0,0 +1,6 @@
+require_relative '../../../spec_helper'
+require_relative 'shared/members'
+
+describe "ObjectSpace::WeakMap#values" do
+ it_behaves_like :weakmap_members, -> map { map.values }, %w[x y]
+end
diff --git a/spec/ruby/core/objectspace/weakmap_spec.rb b/spec/ruby/core/objectspace/weakmap_spec.rb
new file mode 100644
index 0000000000..2f3f93c291
--- /dev/null
+++ b/spec/ruby/core/objectspace/weakmap_spec.rb
@@ -0,0 +1,12 @@
+require_relative '../../spec_helper'
+
+describe "ObjectSpace::WeakMap" do
+
+ # Note that we can't really spec the most important aspect of this class: that entries get removed when the values
+ # become unreachable. This is because Ruby does not offer a way to reliable invoke GC (GC.start is not enough, neither
+ # on MRI or on alternative implementations).
+
+ it "includes Enumerable" do
+ ObjectSpace::WeakMap.include?(Enumerable).should == true
+ end
+end
diff --git a/spec/ruby/core/proc/allocate_spec.rb b/spec/ruby/core/proc/allocate_spec.rb
index 6bfb94dbc2..96c4eb9fa8 100644
--- a/spec/ruby/core/proc/allocate_spec.rb
+++ b/spec/ruby/core/proc/allocate_spec.rb
@@ -1,9 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Proc.allocate" do
it "raises a TypeError" do
- lambda {
+ -> {
Proc.allocate
- }.should raise_error(TypeError)
+ }.should.raise(TypeError)
end
end
diff --git a/spec/ruby/core/proc/arity_spec.rb b/spec/ruby/core/proc/arity_spec.rb
index 251710a663..5c7728cb30 100644
--- a/spec/ruby/core/proc/arity_spec.rb
+++ b/spec/ruby/core/proc/arity_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Proc#arity" do
SpecEvaluate.desc = "for definition"
@@ -268,6 +268,14 @@ describe "Proc#arity" do
@a.arity.should == 3
@b.arity.should == 3
end
+
+ # implicit rest
+ evaluate <<-ruby do
+ @a = lambda { |a, | }
+ ruby
+
+ @a.arity.should == 1
+ end
end
context "returns negative values" do
@@ -530,6 +538,14 @@ describe "Proc#arity" do
@a.arity.should == 1
@b.arity.should == 5
end
+
+ # implicit rest
+ evaluate <<-ruby do
+ @a = proc { |a, | }
+ ruby
+
+ @a.arity.should == 1
+ end
end
context "returns negative values" do
diff --git a/spec/ruby/core/proc/binding_spec.rb b/spec/ruby/core/proc/binding_spec.rb
index 05cc68217e..d643cbf89c 100644
--- a/spec/ruby/core/proc/binding_spec.rb
+++ b/spec/ruby/core/proc/binding_spec.rb
@@ -1,16 +1,16 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Proc#binding" do
it "returns a Binding instance" do
- [Proc.new{}, lambda {}, proc {}].each { |p|
- p.binding.should be_kind_of(Binding)
+ [Proc.new{}, -> {}, proc {}].each { |p|
+ p.binding.should.is_a?(Binding)
}
end
it "returns the binding associated with self" do
obj = mock('binding')
def obj.test_binding(some, params)
- lambda {}
+ -> {}
end
lambdas_binding = obj.test_binding(1, 2).binding
diff --git a/spec/ruby/core/proc/block_pass_spec.rb b/spec/ruby/core/proc/block_pass_spec.rb
index e956885654..82c08db8a7 100644
--- a/spec/ruby/core/proc/block_pass_spec.rb
+++ b/spec/ruby/core/proc/block_pass_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Proc as a block pass argument" do
def revivify(&b)
@@ -8,34 +8,14 @@ describe "Proc as a block pass argument" do
it "remains the same object if re-vivified by the target method" do
p = Proc.new {}
p2 = revivify(&p)
- p.object_id.should == p2.object_id
+ p.should.equal? p2
p.should == p2
end
it "remains the same object if reconstructed with Proc.new" do
p = Proc.new {}
p2 = Proc.new(&p)
- p.object_id.should == p2.object_id
- p.should == p2
- end
-end
-
-describe "Proc as an implicit block pass argument" do
- def revivify
- Proc.new
- end
-
- it "remains the same object if re-vivified by the target method" do
- p = Proc.new {}
- p2 = revivify(&p)
- p.object_id.should == p2.object_id
- p.should == p2
- end
-
- it "remains the same object if reconstructed with Proc.new" do
- p = Proc.new {}
- p2 = Proc.new(&p)
- p.object_id.should == p2.object_id
+ p.should.equal? p2
p.should == p2
end
end
diff --git a/spec/ruby/core/proc/call_spec.rb b/spec/ruby/core/proc/call_spec.rb
index 1c28eae9b0..8b65be97c9 100644
--- a/spec/ruby/core/proc/call_spec.rb
+++ b/spec/ruby/core/proc/call_spec.rb
@@ -1,16 +1,138 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/call', __FILE__)
-require File.expand_path('../shared/call_arguments', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/common'
+require_relative 'fixtures/proc_call'
+require_relative 'fixtures/proc_call_frozen'
describe "Proc#call" do
- it_behaves_like :proc_call, :call
- it_behaves_like :proc_call_block_args, :call
-end
+ it "invokes self" do
+ Proc.new { "test!" }.call.should == "test!"
+ -> { "test!" }.call.should == "test!"
+ proc { "test!" }.call.should == "test!"
+ end
-describe "Proc#call on a Proc created with Proc.new" do
- it_behaves_like :proc_call_on_proc_new, :call
-end
+ it "sets self's parameters to the given values" do
+ Proc.new { |a, b| a + b }.call(1, 2).should == 3
+ Proc.new { |*args| args }.call(1, 2, 3, 4).should == [1, 2, 3, 4]
+ Proc.new { |_, *args| args }.call(1, 2, 3).should == [2, 3]
+
+ -> a, b { a + b }.call(1, 2).should == 3
+ -> *args { args }.call(1, 2, 3, 4).should == [1, 2, 3, 4]
+ -> _, *args { args }.call(1, 2, 3).should == [2, 3]
+
+ proc { |a, b| a + b }.call(1, 2).should == 3
+ proc { |*args| args }.call(1, 2, 3, 4).should == [1, 2, 3, 4]
+ proc { |_, *args| args }.call(1, 2, 3).should == [2, 3]
+ end
+
+ it "can receive block arguments" do
+ Proc.new {|&b| b.call}.call {1 + 1}.should == 2
+ -> &b { b.call}.call {1 + 1}.should == 2
+ proc {|&b| b.call}.call {1 + 1}.should == 2
+ end
+
+ it "yields to the block given at declaration and not to the block argument" do
+ proc_creator = Object.new
+ def proc_creator.create
+ Proc.new do |&b|
+ yield
+ end
+ end
+ a_proc = proc_creator.create { 7 }
+ a_proc.call { 3 }.should == 7
+ end
+
+ it "can call its block argument declared with a block argument" do
+ proc_creator = Object.new
+ def proc_creator.create(method_name)
+ Proc.new do |&b|
+ yield + b.send(method_name)
+ end
+ end
+ a_proc = proc_creator.create(:call) { 7 }
+ a_proc.call { 3 }.should == 10
+ end
+
+ describe "on a Proc created with frozen_string_literal: true/false" do
+ it "doesn't duplicate frozen strings" do
+ ProcCallSpecs.call.frozen?.should == false
+ ProcCallSpecs.call_freeze.frozen?.should == true
+ ProcCallFrozenSpecs.call.frozen?.should == true
+ ProcCallFrozenSpecs.call_freeze.frozen?.should == true
+ end
+ end
+
+ context "on a Proc created with Proc.new" do
+ it "replaces missing arguments with nil" do
+ Proc.new { |a, b| [a, b] }.call.should == [nil, nil]
+ Proc.new { |a, b| [a, b] }.call(1).should == [1, nil]
+ end
+
+ it "silently ignores extra arguments" do
+ Proc.new { |a, b| a + b }.call(1, 2, 5).should == 3
+ end
+
+ it "auto-explodes a single Array argument" do
+ p = Proc.new { |a, b| [a, b] }
+ p.call(1, 2).should == [1, 2]
+ p.call([1, 2]).should == [1, 2]
+ p.call([1, 2, 3]).should == [1, 2]
+ p.call([1, 2, 3], 4).should == [[1, 2, 3], 4]
+ end
+ end
+
+ context "on a Proc created with Kernel#lambda or Kernel#proc" do
+ it "ignores excess arguments when self is a proc" do
+ a = proc {|x| x}.call(1, 2)
+ a.should == 1
+
+ a = proc {|x| x}.call(1, 2, 3)
+ a.should == 1
+
+ a = proc {|x:| x}.call(2, x: 1)
+ a.should == 1
+ end
+
+ it "will call #to_ary on argument and return self if return is nil" do
+ argument = ProcSpecs::ToAryAsNil.new
+ result = proc { |x, _| x }.call(argument)
+ result.should == argument
+ end
+
+ it "substitutes nil for missing arguments when self is a proc" do
+ proc {|x,y| [x,y]}.call.should == [nil,nil]
+
+ a = proc {|x,y| [x, y]}.call(1)
+ a.should == [1,nil]
+ end
+
+ it "raises an ArgumentError on excess arguments when self is a lambda" do
+ -> {
+ -> x { x }.call(1, 2)
+ }.should.raise(ArgumentError)
+
+ -> {
+ -> x { x }.call(1, 2, 3)
+ }.should.raise(ArgumentError)
+ end
+
+ it "raises an ArgumentError on missing arguments when self is a lambda" do
+ -> {
+ -> x { x }.call
+ }.should.raise(ArgumentError)
+
+ -> {
+ -> x, y { [x,y] }.call(1)
+ }.should.raise(ArgumentError)
+ end
+
+ it "treats a single Array argument as a single argument when self is a lambda" do
+ -> a { a }.call([1, 2]).should == [1, 2]
+ -> a, b { [a, b] }.call([1, 2], 3).should == [[1,2], 3]
+ end
-describe "Proc#call on a Proc created with Kernel#lambda or Kernel#proc" do
- it_behaves_like :proc_call_on_proc_or_lambda, :call
+ it "treats a single Array argument as a single argument when self is a proc" do
+ proc { |a| a }.call([1, 2]).should == [1, 2]
+ proc { |a, b| [a, b] }.call([1, 2], 3).should == [[1,2], 3]
+ end
+ end
end
diff --git a/spec/ruby/core/proc/case_compare_spec.rb b/spec/ruby/core/proc/case_compare_spec.rb
index 55760c4ff3..421afb24f0 100644
--- a/spec/ruby/core/proc/case_compare_spec.rb
+++ b/spec/ruby/core/proc/case_compare_spec.rb
@@ -1,16 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/call', __FILE__)
-require File.expand_path('../shared/call_arguments', __FILE__)
+require_relative '../../spec_helper'
describe "Proc#===" do
- it_behaves_like :proc_call, :===
- it_behaves_like :proc_call_block_args, :===
-end
-
-describe "Proc#=== on a Proc created with Proc.new" do
- it_behaves_like :proc_call_on_proc_new, :===
-end
-
-describe "Proc#=== on a Proc created with Kernel#lambda or Kernel#proc" do
- it_behaves_like :proc_call_on_proc_or_lambda, :===
+ it "is an alias of Proc#call" do
+ Proc.instance_method(:===).should == Proc.instance_method(:call)
+ end
end
diff --git a/spec/ruby/core/proc/clone_spec.rb b/spec/ruby/core/proc/clone_spec.rb
index 0f0806645b..aee4873e09 100644
--- a/spec/ruby/core/proc/clone_spec.rb
+++ b/spec/ruby/core/proc/clone_spec.rb
@@ -1,6 +1,28 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/dup', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/common'
+require_relative 'shared/dup'
describe "Proc#clone" do
- it_behaves_like(:proc_dup, :clone)
+ it_behaves_like :proc_dup, :clone
+
+ ruby_bug "cloning a frozen proc is broken on Ruby 3.3", ""..."3.4" do
+ it "preserves frozen status" do
+ proc = Proc.new { }
+ proc.freeze
+ proc.frozen?.should == true
+ proc.clone.frozen?.should == true
+ end
+ end
+
+ it "calls #initialize_clone on subclass" do
+ obj = ProcSpecs::MyProc2.new(:a, 2) { }
+ dup = obj.clone
+
+ dup.should_not.equal?(obj)
+ dup.class.should == ProcSpecs::MyProc2
+
+ dup.first.should == :a
+ dup.second.should == 2
+ dup.initializer.should == :clone
+ end
end
diff --git a/spec/ruby/core/proc/compose_spec.rb b/spec/ruby/core/proc/compose_spec.rb
new file mode 100644
index 0000000000..9e9b57e06f
--- /dev/null
+++ b/spec/ruby/core/proc/compose_spec.rb
@@ -0,0 +1,142 @@
+require_relative '../../spec_helper'
+require_relative 'shared/compose'
+
+describe "Proc#<<" do
+ it "returns a Proc that is the composition of self and the passed Proc" do
+ upcase = proc { |s| s.upcase }
+ succ = proc { |s| s.succ }
+
+ (succ << upcase).call('Ruby').should == "RUBZ"
+ end
+
+ it "calls passed Proc with arguments and then calls self with result" do
+ f = proc { |x| x * x }
+ g = proc { |x| x + x }
+
+ (f << g).call(2).should == 16
+ (g << f).call(2).should == 8
+ end
+
+ it "accepts any callable object" do
+ inc = proc { |n| n + 1 }
+
+ double = Object.new
+ def double.call(n); n * 2; end
+
+ (inc << double).call(3).should == 7
+ end
+
+ it_behaves_like :proc_compose, :<<, -> { proc { |s| s.upcase } }
+
+ describe "composition" do
+ it "is a Proc" do
+ f = proc { |x| x * x }
+ g = proc { |x| x + x }
+
+ (f << g).is_a?(Proc).should == true
+ (f << g).should_not.lambda?
+ end
+
+ it "is a lambda when parameter is lambda" do
+ f = -> x { x * x }
+ g = proc { |x| x + x }
+ lambda_proc = -> x { x }
+
+ # lambda << proc
+ (f << g).is_a?(Proc).should == true
+ (f << g).should_not.lambda?
+
+ # lambda << lambda
+ (f << lambda_proc).is_a?(Proc).should == true
+ (f << lambda_proc).should.lambda?
+
+ # proc << lambda
+ (g << f).is_a?(Proc).should == true
+ (g << f).should.lambda?
+ end
+
+ it "may accept multiple arguments" do
+ inc = proc { |n| n + 1 }
+ mul = proc { |n, m| n * m }
+
+ (inc << mul).call(2, 3).should == 7
+ end
+
+ it "passes blocks to the second proc" do
+ ScratchPad.record []
+ one = proc { |&arg| arg.call :one if arg }
+ two = proc { |&arg| arg.call :two if arg }
+ (one << two).call { |x| ScratchPad << x }
+ ScratchPad.recorded.should == [:two]
+ end
+ end
+end
+
+describe "Proc#>>" do
+ it "returns a Proc that is the composition of self and the passed Proc" do
+ upcase = proc { |s| s.upcase }
+ succ = proc { |s| s.succ }
+
+ (succ >> upcase).call('Ruby').should == "RUBZ"
+ end
+
+ it "calls passed Proc with arguments and then calls self with result" do
+ f = proc { |x| x * x }
+ g = proc { |x| x + x }
+
+ (f >> g).call(2).should == 8
+ (g >> f).call(2).should == 16
+ end
+
+ it "accepts any callable object" do
+ inc = proc { |n| n + 1 }
+
+ double = Object.new
+ def double.call(n); n * 2; end
+
+ (inc >> double).call(3).should == 8
+ end
+
+ it_behaves_like :proc_compose, :>>, -> { proc { |s| s.upcase } }
+
+ describe "composition" do
+ it "is a Proc" do
+ f = proc { |x| x * x }
+ g = proc { |x| x + x }
+
+ (f >> g).is_a?(Proc).should == true
+ (f >> g).should_not.lambda?
+ end
+
+ it "is a Proc when other is lambda" do
+ f = proc { |x| x * x }
+ g = -> x { x + x }
+
+ (f >> g).is_a?(Proc).should == true
+ (f >> g).should_not.lambda?
+ end
+
+ it "is a lambda when self is lambda" do
+ f = -> x { x * x }
+ g = proc { |x| x + x }
+
+ (f >> g).is_a?(Proc).should == true
+ (f >> g).should.lambda?
+ end
+
+ it "may accept multiple arguments" do
+ inc = proc { |n| n + 1 }
+ mul = proc { |n, m| n * m }
+
+ (mul >> inc).call(2, 3).should == 7
+ end
+
+ it "passes blocks to the first proc" do
+ ScratchPad.record []
+ one = proc { |&arg| arg.call :one if arg }
+ two = proc { |&arg| arg.call :two if arg }
+ (one >> two).call { |x| ScratchPad << x }
+ ScratchPad.recorded.should == [:one]
+ end
+ end
+end
diff --git a/spec/ruby/core/proc/curry_spec.rb b/spec/ruby/core/proc/curry_spec.rb
index a294606957..de13983ca6 100644
--- a/spec/ruby/core/proc/curry_spec.rb
+++ b/spec/ruby/core/proc/curry_spec.rb
@@ -1,19 +1,19 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Proc#curry" do
before :each do
@proc_add = Proc.new {|x,y,z| (x||0) + (y||0) + (z||0) }
- @lambda_add = lambda {|x,y,z| (x||0) + (y||0) + (z||0) }
+ @lambda_add = -> x, y, z { (x||0) + (y||0) + (z||0) }
end
it "returns a Proc when called on a proc" do
p = proc { true }
- p.curry.should be_an_instance_of(Proc)
+ p.curry.should.instance_of?(Proc)
end
it "returns a Proc when called on a lambda" do
- p = lambda { true }
- p.curry.should be_an_instance_of(Proc)
+ p = -> { true }
+ p.curry.should.instance_of?(Proc)
end
it "calls the curried proc with the arguments if sufficient arguments have been given" do
@@ -23,11 +23,11 @@ describe "Proc#curry" do
it "returns a Proc that consumes the remainder of the arguments unless sufficient arguments have been given" do
proc2 = @proc_add.curry[1][2]
- proc2.should be_an_instance_of(Proc)
+ proc2.should.instance_of?(Proc)
proc2.call(3).should == 6
lambda2 = @lambda_add.curry[1][2]
- lambda2.should be_an_instance_of(Proc)
+ lambda2.should.instance_of?(Proc)
lambda2.call(3).should == 6
@proc_add.curry.call(1,2,3).should == 6
@@ -36,10 +36,10 @@ describe "Proc#curry" do
it "can be called multiple times on the same Proc" do
@proc_add.curry
- lambda { @proc_add.curry }.should_not raise_error
+ -> { @proc_add.curry }.should_not.raise
@lambda_add.curry
- lambda { @lambda_add.curry }.should_not raise_error
+ -> { @lambda_add.curry }.should_not.raise
end
it "can be passed superfluous arguments if created from a proc" do
@@ -49,21 +49,21 @@ describe "Proc#curry" do
end
it "raises an ArgumentError if passed superfluous arguments when created from a lambda" do
- lambda { @lambda_add.curry[1,2,3,4] }.should raise_error(ArgumentError)
- lambda { @lambda_add.curry[1,2].curry[3,4,5,6] }.should raise_error(ArgumentError)
+ -> { @lambda_add.curry[1,2,3,4] }.should.raise(ArgumentError)
+ -> { @lambda_add.curry[1,2].curry[3,4,5,6] }.should.raise(ArgumentError)
end
it "returns Procs with arities of -1" do
@proc_add.curry.arity.should == -1
@lambda_add.curry.arity.should == -1
- l = lambda { |*a| }
+ l = -> *a { }
l.curry.arity.should == -1
end
it "produces Procs that raise ArgumentError for #binding" do
- lambda do
+ -> do
@proc_add.curry.binding
- end.should raise_error(ArgumentError)
+ end.should.raise(ArgumentError)
end
it "produces Procs that return [[:rest]] for #parameters" do
@@ -81,7 +81,7 @@ describe "Proc#curry" do
end
it "combines arguments and calculates incoming arity accurately for successively currying" do
- l = lambda{|a,b,c| a+b+c }
+ l = -> a, b, c { a+b+c }
l1 = l.curry.call(1)
# the l1 currying seems unnecessary, but it triggered the original issue
l2 = l1.curry.call(2)
@@ -93,46 +93,46 @@ end
describe "Proc#curry with arity argument" do
before :each do
- @proc_add = proc {|x,y,z| (x||0) + (y||0) + (z||0) }
- @lambda_add = lambda {|x,y,z| (x||0) + (y||0) + (z||0) }
+ @proc_add = proc { |x,y,z| (x||0) + (y||0) + (z||0) }
+ @lambda_add = -> x, y, z { (x||0) + (y||0) + (z||0) }
end
it "accepts an optional Integer argument for the arity" do
- lambda { @proc_add.curry(3) }.should_not raise_error
- lambda { @lambda_add.curry(3) }.should_not raise_error
+ -> { @proc_add.curry(3) }.should_not.raise
+ -> { @lambda_add.curry(3) }.should_not.raise
end
it "returns a Proc when called on a proc" do
- @proc_add.curry(3).should be_an_instance_of(Proc)
+ @proc_add.curry(3).should.instance_of?(Proc)
end
it "returns a Proc when called on a lambda" do
- @lambda_add.curry(3).should be_an_instance_of(Proc)
+ @lambda_add.curry(3).should.instance_of?(Proc)
end
# [ruby-core:24127]
it "retains the lambda-ness of the Proc on which its called" do
- @lambda_add.curry(3).lambda?.should be_true
- @proc_add.curry(3).lambda?.should be_false
+ @lambda_add.curry(3).lambda?.should == true
+ @proc_add.curry(3).lambda?.should == false
end
it "raises an ArgumentError if called on a lambda that requires more than _arity_ arguments" do
- lambda { @lambda_add.curry(2) }.should raise_error(ArgumentError)
- lambda { lambda{|x, y, z, *more|}.curry(2) }.should raise_error(ArgumentError)
+ -> { @lambda_add.curry(2) }.should.raise(ArgumentError)
+ -> { -> x, y, z, *more{}.curry(2) }.should.raise(ArgumentError)
end
it 'returns a Proc if called on a lambda that requires fewer than _arity_ arguments but may take more' do
- lambda{|a, b, c, d=nil, e=nil|}.curry(4).should be_an_instance_of(Proc)
- lambda{|a, b, c, d=nil, *e|}.curry(4).should be_an_instance_of(Proc)
- lambda{|a, b, c, *d|}.curry(4).should be_an_instance_of(Proc)
+ -> a, b, c, d=nil, e=nil {}.curry(4).should.instance_of?(Proc)
+ -> a, b, c, d=nil, *e {}.curry(4).should.instance_of?(Proc)
+ -> a, b, c, *d {}.curry(4).should.instance_of?(Proc)
end
it "raises an ArgumentError if called on a lambda that requires fewer than _arity_ arguments" do
- lambda { @lambda_add.curry(4) }.should raise_error(ArgumentError)
- lambda { lambda { true }.curry(1) }.should raise_error(ArgumentError)
- lambda { lambda {|a, b=nil|}.curry(5) }.should raise_error(ArgumentError)
- lambda { lambda {|a, &b|}.curry(2) }.should raise_error(ArgumentError)
- lambda { lambda {|a, b=nil, &c|}.curry(3) }.should raise_error(ArgumentError)
+ -> { @lambda_add.curry(4) }.should.raise(ArgumentError)
+ -> { -> { true }.curry(1) }.should.raise(ArgumentError)
+ -> { -> a, b=nil {}.curry(5) }.should.raise(ArgumentError)
+ -> { -> a, &b {}.curry(2) }.should.raise(ArgumentError)
+ -> { -> a, b=nil, &c {}.curry(3) }.should.raise(ArgumentError)
end
it "calls the curried proc with the arguments if _arity_ arguments have been given" do
@@ -142,39 +142,38 @@ describe "Proc#curry with arity argument" do
it "returns a Proc that consumes the remainder of the arguments when fewer than _arity_ arguments are given" do
proc2 = @proc_add.curry(3)[1][2]
- proc2.should be_an_instance_of(Proc)
+ proc2.should.instance_of?(Proc)
proc2.call(3).should == 6
lambda2 = @lambda_add.curry(3)[1][2]
- lambda2.should be_an_instance_of(Proc)
+ lambda2.should.instance_of?(Proc)
lambda2.call(3).should == 6
end
it "can be specified multiple times on the same Proc" do
@proc_add.curry(2)
- lambda { @proc_add.curry(1) }.should_not raise_error
+ -> { @proc_add.curry(1) }.should_not.raise
@lambda_add.curry(3)
- lambda { @lambda_add.curry(3) }.should_not raise_error
+ -> { @lambda_add.curry(3) }.should_not.raise
end
it "can be passed more than _arity_ arguments if created from a proc" do
- lambda { @proc_add.curry(3)[1,2,3,4].should == 6 }.should_not
- raise_error(ArgumentError)
- lambda { @proc_add.curry(1)[1,2].curry(3)[3,4,5,6].should == 6 }.should_not
- raise_error(ArgumentError)
+ @proc_add.curry(3)[1,2,3,4].should == 6
+
+ @proc_add.curry(3)[1,2].curry(3)[3,4,5,6].should == 6
end
it "raises an ArgumentError if passed more than _arity_ arguments when created from a lambda" do
- lambda { @lambda_add.curry(3)[1,2,3,4] }.should raise_error(ArgumentError)
- lambda { @lambda_add.curry(1)[1,2].curry(3)[3,4,5,6] }.should raise_error(ArgumentError)
+ -> { @lambda_add.curry(3)[1,2,3,4] }.should.raise(ArgumentError)
+ -> { @lambda_add.curry(3)[1,2].curry(3)[3,4,5,6] }.should.raise(ArgumentError)
end
it "returns Procs with arities of -1 regardless of the value of _arity_" do
@proc_add.curry(1).arity.should == -1
@proc_add.curry(2).arity.should == -1
@lambda_add.curry(3).arity.should == -1
- l = lambda { |*a| }
+ l = -> *a { }
l.curry(3).arity.should == -1
end
end
diff --git a/spec/ruby/core/proc/dup_spec.rb b/spec/ruby/core/proc/dup_spec.rb
index ea3fe8aac9..8604389422 100644
--- a/spec/ruby/core/proc/dup_spec.rb
+++ b/spec/ruby/core/proc/dup_spec.rb
@@ -1,6 +1,26 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/dup', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/common'
+require_relative 'shared/dup'
describe "Proc#dup" do
- it_behaves_like(:proc_dup, :dup)
+ it_behaves_like :proc_dup, :dup
+
+ it "resets frozen status" do
+ proc = Proc.new { }
+ proc.freeze
+ proc.frozen?.should == true
+ proc.dup.frozen?.should == false
+ end
+
+ it "calls #initialize_dup on subclass" do
+ obj = ProcSpecs::MyProc2.new(:a, 2) { }
+ dup = obj.dup
+
+ dup.should_not.equal?(obj)
+ dup.class.should == ProcSpecs::MyProc2
+
+ dup.first.should == :a
+ dup.second.should == 2
+ dup.initializer.should == :dup
+ end
end
diff --git a/spec/ruby/core/proc/element_reference_spec.rb b/spec/ruby/core/proc/element_reference_spec.rb
index f3dec21253..ac14292464 100644
--- a/spec/ruby/core/proc/element_reference_spec.rb
+++ b/spec/ruby/core/proc/element_reference_spec.rb
@@ -1,16 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/call', __FILE__)
-require File.expand_path('../shared/call_arguments', __FILE__)
+require_relative '../../spec_helper'
describe "Proc#[]" do
- it_behaves_like :proc_call, :[]
- it_behaves_like :proc_call_block_args, :[]
-end
-
-describe "Proc#call on a Proc created with Proc.new" do
- it_behaves_like :proc_call_on_proc_new, :call
-end
-
-describe "Proc#call on a Proc created with Kernel#lambda or Kernel#proc" do
- it_behaves_like :proc_call_on_proc_or_lambda, :call
+ it "is an alias of Proc#call" do
+ Proc.instance_method(:[]).should == Proc.instance_method(:call)
+ end
end
diff --git a/spec/ruby/core/proc/eql_spec.rb b/spec/ruby/core/proc/eql_spec.rb
index e0cc80bb48..1a5fb42a0e 100644
--- a/spec/ruby/core/proc/eql_spec.rb
+++ b/spec/ruby/core/proc/eql_spec.rb
@@ -1,6 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/equal', __FILE__)
+require_relative '../../spec_helper'
describe "Proc#eql?" do
- it_behaves_like(:proc_equal_undefined, :eql?)
+ it "is an alias of Proc#==" do
+ Proc.instance_method(:eql?).should == Proc.instance_method(:==)
+ end
end
diff --git a/spec/ruby/core/proc/equal_value_spec.rb b/spec/ruby/core/proc/equal_value_spec.rb
index e50ea1a53b..92e462152e 100644
--- a/spec/ruby/core/proc/equal_value_spec.rb
+++ b/spec/ruby/core/proc/equal_value_spec.rb
@@ -1,6 +1,83 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/equal', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/common'
describe "Proc#==" do
- it_behaves_like(:proc_equal_undefined, :==)
+ it "is a public method" do
+ Proc.public_instance_methods(false).should.include?(:==)
+ end
+
+ it "returns true if self and other are the same object" do
+ p = proc { :foo }
+ (p == p).should == true
+
+ p = Proc.new { :foo }
+ (p == p).should == true
+
+ p = -> { :foo }
+ (p == p).should == true
+ end
+
+ it "returns true if other is a dup of the original" do
+ p = proc { :foo }
+ (p == p.dup).should == true
+
+ p = Proc.new { :foo }
+ (p == p.dup).should == true
+
+ p = -> { :foo }
+ (p == p.dup).should == true
+ end
+
+ # identical here means the same method invocation.
+ it "returns false when bodies are the same but capture env is not identical" do
+ a = ProcSpecs.proc_for_1
+ b = ProcSpecs.proc_for_1
+
+ (a == b).should == false
+ end
+
+ it "returns false if procs are distinct but have the same body and environment" do
+ p = proc { :foo }
+ p2 = proc { :foo }
+ (p == p2).should == false
+ end
+
+ it "returns false if lambdas are distinct but have same body and environment" do
+ x = -> { :foo }
+ x2 = -> { :foo }
+ (x == x2).should == false
+ end
+
+ it "returns false if using comparing lambda to proc, even with the same body and env" do
+ p = -> { :foo }
+ p2 = proc { :foo }
+ (p == p2).should == false
+
+ x = proc { :bar }
+ x2 = -> { :bar }
+ (x == x2).should == false
+ end
+
+ it "returns false if other is not a Proc" do
+ p = proc { :foo }
+ (p == []).should == false
+
+ p = Proc.new { :foo }
+ (p == Object.new).should == false
+
+ p = -> { :foo }
+ (p == :foo).should == false
+ end
+
+ it "returns false if self and other are both procs but have different bodies" do
+ p = proc { :bar }
+ p2 = proc { :foo }
+ (p == p2).should == false
+ end
+
+ it "returns false if self and other are both lambdas but have different bodies" do
+ p = -> { :foo }
+ p2 = -> { :bar }
+ (p == p2).should == false
+ end
end
diff --git a/spec/ruby/core/proc/fixtures/common.rb b/spec/ruby/core/proc/fixtures/common.rb
index 6e27a2dee7..dfe67d7ba8 100644
--- a/spec/ruby/core/proc/fixtures/common.rb
+++ b/spec/ruby/core/proc/fixtures/common.rb
@@ -32,7 +32,28 @@ module ProcSpecs
@second = b
end
- attr_reader :first, :second
+ attr_reader :first, :second, :initializer
+
+ def initialize_copy(other)
+ super
+ @initializer = :copy
+ @first = other.first
+ @second = other.second
+ end
+
+ def initialize_dup(other)
+ super
+ @initializer = :dup
+ @first = other.first
+ @second = other.second
+ end
+
+ def initialize_clone(other, **options)
+ super
+ @initializer = :clone
+ @first = other.first
+ @second = other.second
+ end
end
class Arity
diff --git a/spec/ruby/core/proc/fixtures/proc_call.rb b/spec/ruby/core/proc/fixtures/proc_call.rb
new file mode 100644
index 0000000000..32048f5319
--- /dev/null
+++ b/spec/ruby/core/proc/fixtures/proc_call.rb
@@ -0,0 +1,10 @@
+# frozen_string_literal: false
+module ProcCallSpecs
+ def self.call
+ proc {|a| a }.call("sometext")
+ end
+
+ def self.call_freeze
+ proc {|a| a }.call("sometext".freeze)
+ end
+end
diff --git a/spec/ruby/core/proc/fixtures/proc_call_frozen.rb b/spec/ruby/core/proc/fixtures/proc_call_frozen.rb
new file mode 100644
index 0000000000..29ffc3c4c9
--- /dev/null
+++ b/spec/ruby/core/proc/fixtures/proc_call_frozen.rb
@@ -0,0 +1,10 @@
+# frozen_string_literal: true
+module ProcCallFrozenSpecs
+ def self.call
+ proc {|a| a }.call("sometext")
+ end
+
+ def self.call_freeze
+ proc {|a| a }.call("sometext".freeze)
+ end
+end
diff --git a/spec/ruby/core/proc/fixtures/source_location.rb b/spec/ruby/core/proc/fixtures/source_location.rb
index 468262e02a..5572094630 100644
--- a/spec/ruby/core/proc/fixtures/source_location.rb
+++ b/spec/ruby/core/proc/fixtures/source_location.rb
@@ -5,7 +5,7 @@ module ProcSpecs
end
def self.my_lambda
- lambda { true }
+ -> { true }
end
def self.my_proc_new
@@ -24,7 +24,7 @@ module ProcSpecs
end
def self.my_multiline_lambda
- lambda do
+ -> do
'a'.upcase
1 + 22
end
@@ -43,8 +43,8 @@ module ProcSpecs
end
def self.my_detached_lambda
- body = lambda { true }
- lambda(&body)
+ body = -> { true }
+ suppress_warning {lambda(&body)}
end
def self.my_detached_proc_new
diff --git a/spec/ruby/core/proc/hash_spec.rb b/spec/ruby/core/proc/hash_spec.rb
index 1f5b6d5aa1..adcb1ccb78 100644
--- a/spec/ruby/core/proc/hash_spec.rb
+++ b/spec/ruby/core/proc/hash_spec.rb
@@ -1,13 +1,13 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Proc#hash" do
it "is provided" do
- proc {}.respond_to?(:hash).should be_true
- lambda {}.respond_to?(:hash).should be_true
+ proc {}.respond_to?(:hash).should == true
+ -> {}.respond_to?(:hash).should == true
end
it "returns an Integer" do
- proc { 1 + 489 }.hash.should be_kind_of(Fixnum)
+ proc { 1 + 489 }.hash.should.is_a?(Integer)
end
it "is stable" do
diff --git a/spec/ruby/core/proc/inspect_spec.rb b/spec/ruby/core/proc/inspect_spec.rb
index 860647baa7..96995ec410 100644
--- a/spec/ruby/core/proc/inspect_spec.rb
+++ b/spec/ruby/core/proc/inspect_spec.rb
@@ -1,6 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/to_s', __FILE__)
+require_relative '../../spec_helper'
describe "Proc#inspect" do
- it_behaves_like :proc_to_s, :inspect
+ it "is an alias of Proc#to_s" do
+ Proc.instance_method(:inspect).should == Proc.instance_method(:to_s)
+ end
end
diff --git a/spec/ruby/core/proc/lambda_spec.rb b/spec/ruby/core/proc/lambda_spec.rb
index 33c9ebdd55..1ff6147319 100644
--- a/spec/ruby/core/proc/lambda_spec.rb
+++ b/spec/ruby/core/proc/lambda_spec.rb
@@ -1,60 +1,55 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/common', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/common'
describe "Proc#lambda?" do
it "returns true if the Proc was created from a block with the lambda keyword" do
- lambda {}.lambda?.should be_true
+ -> {}.lambda?.should == true
end
it "returns false if the Proc was created from a block with the proc keyword" do
- proc {}.lambda?.should be_false
+ proc {}.lambda?.should == false
end
it "returns false if the Proc was created from a block with Proc.new" do
- Proc.new {}.lambda?.should be_false
- end
-
- it "is preserved when passing a Proc with & to the lambda keyword" do
- lambda(&lambda{}).lambda?.should be_true
- lambda(&proc{}).lambda?.should be_false
+ Proc.new {}.lambda?.should == false
end
it "is preserved when passing a Proc with & to the proc keyword" do
- proc(&lambda{}).lambda?.should be_true
- proc(&proc{}).lambda?.should be_false
+ proc(&->{}).lambda?.should == true
+ proc(&proc{}).lambda?.should == false
end
it "is preserved when passing a Proc with & to Proc.new" do
- Proc.new(&lambda{}).lambda?.should be_true
- Proc.new(&proc{}).lambda?.should be_false
+ Proc.new(&->{}).lambda?.should == true
+ Proc.new(&proc{}).lambda?.should == false
end
it "returns false if the Proc was created from a block with &" do
- ProcSpecs.new_proc_from_amp{}.lambda?.should be_false
+ ProcSpecs.new_proc_from_amp{}.lambda?.should == false
end
it "is preserved when the Proc was passed using &" do
- ProcSpecs.new_proc_from_amp(&lambda{}).lambda?.should be_true
- ProcSpecs.new_proc_from_amp(&proc{}).lambda?.should be_false
- ProcSpecs.new_proc_from_amp(&Proc.new{}).lambda?.should be_false
+ ProcSpecs.new_proc_from_amp(&->{}).lambda?.should == true
+ ProcSpecs.new_proc_from_amp(&proc{}).lambda?.should == false
+ ProcSpecs.new_proc_from_amp(&Proc.new{}).lambda?.should == false
end
it "returns true for a Method converted to a Proc" do
m = :foo.method(:to_s)
- m.to_proc.lambda?.should be_true
- ProcSpecs.new_proc_from_amp(&m).lambda?.should be_true
+ m.to_proc.lambda?.should == true
+ ProcSpecs.new_proc_from_amp(&m).lambda?.should == true
end
# [ruby-core:24127]
it "is preserved when a Proc is curried" do
- lambda{}.curry.lambda?.should be_true
- proc{}.curry.lambda?.should be_false
- Proc.new{}.curry.lambda?.should be_false
+ ->{}.curry.lambda?.should == true
+ proc{}.curry.lambda?.should == false
+ Proc.new{}.curry.lambda?.should == false
end
it "is preserved when a curried Proc is called without enough arguments" do
- lambda{|x,y|}.curry.call(42).lambda?.should be_true
- proc{|x,y|}.curry.call(42).lambda?.should be_false
- Proc.new{|x,y|}.curry.call(42).lambda?.should be_false
+ -> x, y{}.curry.call(42).lambda?.should == true
+ proc{|x,y|}.curry.call(42).lambda?.should == false
+ Proc.new{|x,y|}.curry.call(42).lambda?.should == false
end
end
diff --git a/spec/ruby/core/proc/new_spec.rb b/spec/ruby/core/proc/new_spec.rb
index 5dc0061a47..f0b817f0cb 100644
--- a/spec/ruby/core/proc/new_spec.rb
+++ b/spec/ruby/core/proc/new_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/common', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/common'
describe "Proc.new with an associated block" do
it "returns a proc that represents the block" do
@@ -71,7 +71,7 @@ describe "Proc.new with an associated block" do
end
res = some_method()
- lambda { res.call }.should raise_error(LocalJumpError)
+ -> { res.call }.should.raise(LocalJumpError)
end
it "returns from within enclosing method when 'return' is used in the block" do
@@ -86,7 +86,7 @@ describe "Proc.new with an associated block" do
it "returns a subclass of Proc" do
obj = ProcSpecs::MyProc.new { }
- obj.should be_kind_of(ProcSpecs::MyProc)
+ obj.should.is_a?(ProcSpecs::MyProc)
end
it "calls initialize on the Proc object" do
@@ -94,18 +94,6 @@ describe "Proc.new with an associated block" do
obj.first.should == :a
obj.second.should == 2
end
-
- it "returns a new Proc instance from the block passed to the containing method" do
- prc = ProcSpecs.new_proc_in_method { "hello" }
- prc.should be_an_instance_of(Proc)
- prc.call.should == "hello"
- end
-
- it "returns a new Proc instance from the block passed to the containing method" do
- prc = ProcSpecs.new_proc_subclass_in_method { "hello" }
- prc.should be_an_instance_of(ProcSpecs::ProcSubclass)
- prc.call.should == "hello"
- end
end
describe "Proc.new with a block argument" do
@@ -113,7 +101,7 @@ describe "Proc.new with a block argument" do
passed_prc = Proc.new { "hello".size }
prc = Proc.new(&passed_prc)
- prc.should equal(passed_prc)
+ prc.should.equal?(passed_prc)
prc.call.should == 5
end
@@ -122,7 +110,7 @@ describe "Proc.new with a block argument" do
passed_prc = Proc.new(&method)
prc = Proc.new(&passed_prc)
- prc.should equal(passed_prc)
+ prc.should.equal?(passed_prc)
prc.call.should == 5
end
@@ -130,7 +118,7 @@ describe "Proc.new with a block argument" do
passed_prc = Proc.new(&:size)
prc = Proc.new(&passed_prc)
- prc.should equal(passed_prc)
+ prc.should.equal?(passed_prc)
prc.call("hello").should == 5
end
end
@@ -141,7 +129,7 @@ describe "Proc.new with a block argument called indirectly from a subclass" do
passed_prc.class.should == ProcSpecs::MyProc
prc = ProcSpecs::MyProc.new(&passed_prc)
- prc.should equal(passed_prc)
+ prc.should.equal?(passed_prc)
prc.call.should == 5
end
@@ -151,7 +139,7 @@ describe "Proc.new with a block argument called indirectly from a subclass" do
passed_prc.class.should == ProcSpecs::MyProc
prc = ProcSpecs::MyProc.new(&passed_prc)
- prc.should equal(passed_prc)
+ prc.should.equal?(passed_prc)
prc.call.should == 5
end
@@ -160,31 +148,31 @@ describe "Proc.new with a block argument called indirectly from a subclass" do
passed_prc.class.should == ProcSpecs::MyProc
prc = ProcSpecs::MyProc.new(&passed_prc)
- prc.should equal(passed_prc)
+ prc.should.equal?(passed_prc)
prc.call("hello").should == 5
end
end
describe "Proc.new without a block" do
it "raises an ArgumentError" do
- lambda { Proc.new }.should raise_error(ArgumentError)
+ -> { Proc.new }.should.raise(ArgumentError)
end
it "raises an ArgumentError if invoked from within a method with no block" do
- lambda { ProcSpecs.new_proc_in_method }.should raise_error(ArgumentError)
+ -> { ProcSpecs.new_proc_in_method }.should.raise(ArgumentError)
end
it "raises an ArgumentError if invoked on a subclass from within a method with no block" do
- lambda { ProcSpecs.new_proc_subclass_in_method }.should raise_error(ArgumentError)
+ -> { ProcSpecs.new_proc_subclass_in_method }.should.raise(ArgumentError)
end
- it "uses the implicit block from an enclosing method" do
+ it "raises an ArgumentError when passed no block" do
def some_method
Proc.new
end
- prc = some_method { "hello" }
-
- prc.call.should == "hello"
+ -> { ProcSpecs.new_proc_in_method { "hello" } }.should.raise(ArgumentError, 'tried to create Proc object without a block')
+ -> { ProcSpecs.new_proc_subclass_in_method { "hello" } }.should.raise(ArgumentError, 'tried to create Proc object without a block')
+ -> { some_method { "hello" } }.should.raise(ArgumentError, 'tried to create Proc object without a block')
end
end
diff --git a/spec/ruby/core/proc/parameters_spec.rb b/spec/ruby/core/proc/parameters_spec.rb
index 3ba8a0cc32..ac8c6e3560 100644
--- a/spec/ruby/core/proc/parameters_spec.rb
+++ b/spec/ruby/core/proc/parameters_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Proc#parameters" do
it "returns an empty Array for a proc expecting no parameters" do
@@ -7,8 +7,8 @@ describe "Proc#parameters" do
it "returns an Array of Arrays for a proc expecting parameters" do
p = proc {|x| }
- p.parameters.should be_an_instance_of(Array)
- p.parameters.first.should be_an_instance_of(Array)
+ p.parameters.should.instance_of?(Array)
+ p.parameters.first.should.instance_of?(Array)
end
it "sets the first element of each sub-Array to :opt for optional arguments" do
@@ -20,55 +20,78 @@ describe "Proc#parameters" do
proc {|x| }.parameters.first.first.should == :opt
end
+ it "sets the first element of each sub-Array to :req for required argument if lambda keyword used" do
+ proc {|x| }.parameters(lambda: true).first.first.should == :req
+ proc {|y,*x| }.parameters(lambda: true).first.first.should == :req
+ end
+
+ it "regards named parameters in procs as required if lambda keyword used" do
+ proc {|x| }.parameters(lambda: true).first.first.should == :req
+ end
+
+ it "regards named parameters in lambda as optional if lambda: false keyword used" do
+ -> x { }.parameters(lambda: false).first.first.should == :opt
+ end
+
+ it "regards named parameters in procs and lambdas as required if lambda keyword is truthy" do
+ proc {|x| }.parameters(lambda: 123).first.first.should == :req
+ -> x { }.parameters(lambda: 123).first.first.should == :req
+ end
+
+ it "ignores the lambda keyword if it is nil" do
+ proc {|x|}.parameters(lambda: nil).first.first.should == :opt
+ -> x { }.parameters(lambda: nil).first.first.should == :req
+ end
+
it "regards optional keyword parameters in procs as optional" do
proc {|x: :y| }.parameters.first.first.should == :key
end
it "regards parameters with default values as optional" do
- lambda {|x=1| }.parameters.first.first.should == :opt
+ -> x=1 { }.parameters.first.first.should == :opt
proc {|x=1| }.parameters.first.first.should == :opt
end
it "sets the first element of each sub-Array to :req for required arguments" do
- lambda {|x,y=[]| }.parameters.first.first.should == :req
- lambda {|y,*x| }.parameters.first.first.should == :req
+ -> x, y=[] { }.parameters.first.first.should == :req
+ -> y, *x { }.parameters.first.first.should == :req
end
it "regards named parameters in lambdas as required" do
- lambda {|x| }.parameters.first.first.should == :req
+ -> x { }.parameters.first.first.should == :req
end
it "regards keyword parameters in lambdas as required" do
- eval("lambda {|x:| }").parameters.first.first.should == :keyreq
+ -> x: { }.parameters.first.first.should == :keyreq
end
it "sets the first element of each sub-Array to :rest for parameters prefixed with asterisks" do
- lambda {|*x| }.parameters.first.first.should == :rest
- lambda {|x,*y| }.parameters.last.first.should == :rest
+ -> *x { }.parameters.first.first.should == :rest
+ -> x, *y { }.parameters.last.first.should == :rest
proc {|*x| }.parameters.first.first.should == :rest
proc {|x,*y| }.parameters.last.first.should == :rest
end
it "sets the first element of each sub-Array to :keyrest for parameters prefixed with double asterisks" do
- lambda {|**x| }.parameters.first.first.should == :keyrest
- lambda {|x,**y| }.parameters.last.first.should == :keyrest
+ -> **x { }.parameters.first.first.should == :keyrest
+ -> x, **y { }.parameters.last.first.should == :keyrest
proc {|**x| }.parameters.first.first.should == :keyrest
proc {|x,**y| }.parameters.last.first.should == :keyrest
end
it "sets the first element of each sub-Array to :block for parameters prefixed with ampersands" do
- lambda {|&x| }.parameters.first.first.should == :block
- lambda {|x,&y| }.parameters.last.first.should == :block
+ -> &x { }.parameters.first.first.should == :block
+ -> x, &y { }.parameters.last.first.should == :block
proc {|&x| }.parameters.first.first.should == :block
proc {|x,&y| }.parameters.last.first.should == :block
end
it "sets the second element of each sub-Array to the name of the argument" do
- lambda {|x| }.parameters.first.last.should == :x
- lambda {|x=Math::PI| }.parameters.first.last.should == :x
- lambda {|an_argument, glark, &foo| }.parameters[1].last.should == :glark
- lambda {|*rest| }.parameters.first.last.should == :rest
- lambda {|&block| }.parameters.first.last.should == :block
+ -> x { }.parameters.first.last.should == :x
+ -> x=Math::PI { }.parameters.first.last.should == :x
+ -> an_argument, glark, &foo { }.parameters[1].last.should == :glark
+ -> *rest { }.parameters.first.last.should == :rest
+ -> &block { }.parameters.first.last.should == :block
proc {|x| }.parameters.first.last.should == :x
proc {|x=Math::PI| }.parameters.first.last.should == :x
proc {|an_argument, glark, &foo| }.parameters[1].last.should == :glark
@@ -76,20 +99,85 @@ describe "Proc#parameters" do
proc {|&block| }.parameters.first.last.should == :block
end
- it "ignores unnamed rest args" do
- lambda {|x,|}.parameters.should == [[:req, :x]]
+ it "ignores unnamed rest arguments" do
+ -> x {}.parameters.should == [[:req, :x]]
+ end
+
+ it "ignores implicit rest arguments" do
+ proc { |x, | }.parameters.should == [[:opt, :x]]
+ -> x { }.parameters.should == [[:req, :x]]
+ end
+
+ it "adds rest arg with name * for \"star\" argument" do
+ -> * {}.parameters.should == [[:rest, :*]]
end
- it "adds nameless rest arg for \"star\" argument" do
- lambda {|x,*|}.parameters.should == [[:req, :x], [:rest]]
+ it "adds keyrest arg with ** as a name for \"double star\" argument" do
+ -> ** {}.parameters.should == [[:keyrest, :**]]
+ end
+
+ it "adds block arg with name & for anonymous block argument" do
+ -> & {}.parameters.should == [[:block, :&]]
end
it "does not add locals as block options with a block and splat" do
- lambda do |*args, &blk|
+ -> *args, &blk do
local_is_not_parameter = {}
end.parameters.should == [[:rest, :args], [:block, :blk]]
proc do |*args, &blk|
local_is_not_parameter = {}
end.parameters.should == [[:rest, :args], [:block, :blk]]
end
+
+ it "returns all parameters defined with the name _ as _" do
+ proc = proc {|_, _, _ = 1, *_, _:, _: 2, **_, &_| }
+ proc.parameters.should == [
+ [:opt, :_],
+ [:opt, :_],
+ [:opt, :_],
+ [:rest, :_],
+ [:keyreq, :_],
+ [:key, :_],
+ [:keyrest, :_],
+ [:block, :_]
+ ]
+
+ lambda = -> _, _, _ = 1, *_, _:, _: 2, **_, &_ {}
+ lambda.parameters.should == [
+ [:req, :_],
+ [:req, :_],
+ [:opt, :_],
+ [:rest, :_],
+ [:keyreq, :_],
+ [:key, :_],
+ [:keyrest, :_],
+ [:block, :_]
+ ]
+ end
+
+ it "returns :nokey for **nil parameter" do
+ proc { |**nil| }.parameters.should == [[:nokey]]
+ end
+
+ ruby_version_is "3.4"..."4.0" do
+ it "handles the usage of `it` as a parameter" do
+ eval("proc { it }").parameters.should == [[:opt, nil]]
+ eval("lambda { it }").parameters.should == [[:req]]
+ end
+ end
+
+ ruby_version_is "4.0" do
+ it "handles the usage of `it` as a parameter" do
+ eval("proc { it }").parameters.should == [[:opt]]
+ eval("lambda { it }").parameters.should == [[:req]]
+ end
+ end
+
+ ruby_version_is "4.1" do
+ it "returns :noblock for &nil parameter" do
+ eval <<~RUBY
+ proc { |&nil| }.parameters.should == [[:noblock]]
+ RUBY
+ end
+ end
end
diff --git a/spec/ruby/core/proc/ruby2_keywords_spec.rb b/spec/ruby/core/proc/ruby2_keywords_spec.rb
new file mode 100644
index 0000000000..e06fad8693
--- /dev/null
+++ b/spec/ruby/core/proc/ruby2_keywords_spec.rb
@@ -0,0 +1,66 @@
+require_relative '../../spec_helper'
+
+describe "Proc#ruby2_keywords" do
+ it "marks the final hash argument as keyword hash" do
+ f = -> *a { a.last }
+ f.ruby2_keywords
+
+ last = f.call(1, 2, a: "a")
+ Hash.ruby2_keywords_hash?(last).should == true
+ end
+
+ it "applies to the underlying method and applies across duplication" do
+ f1 = -> *a { a.last }
+ f1.ruby2_keywords
+ f2 = f1.dup
+
+ Hash.ruby2_keywords_hash?(f1.call(1, 2, a: "a")).should == true
+ Hash.ruby2_keywords_hash?(f2.call(1, 2, a: "a")).should == true
+
+ f3 = -> *a { a.last }
+ f4 = f3.dup
+ f3.ruby2_keywords
+
+ Hash.ruby2_keywords_hash?(f3.call(1, 2, a: "a")).should == true
+ Hash.ruby2_keywords_hash?(f4.call(1, 2, a: "a")).should == true
+ end
+
+ it "returns self" do
+ f = -> *a { }
+ f.ruby2_keywords.should.equal? f
+ end
+
+ it "prints warning when a proc does not accept argument splat" do
+ f = -> a, b, c { }
+
+ -> {
+ f.ruby2_keywords
+ }.should complain(/Skipping set of ruby2_keywords flag for/)
+ end
+
+ it "prints warning when a proc accepts keywords" do
+ f = -> *a, b: { }
+
+ -> {
+ f.ruby2_keywords
+ }.should complain(/Skipping set of ruby2_keywords flag for/)
+ end
+
+ it "prints warning when a proc accepts keyword splat" do
+ f = -> *a, **b { }
+
+ -> {
+ f.ruby2_keywords
+ }.should complain(/Skipping set of ruby2_keywords flag for/)
+ end
+
+ ruby_version_is "4.0" do
+ it "prints warning when a proc accepts post arguments" do
+ f = -> *a, b { }
+
+ -> {
+ f.ruby2_keywords
+ }.should complain(/Skipping set of ruby2_keywords flag for/)
+ end
+ end
+end
diff --git a/spec/ruby/core/proc/shared/call.rb b/spec/ruby/core/proc/shared/call.rb
deleted file mode 100644
index 11355537b0..0000000000
--- a/spec/ruby/core/proc/shared/call.rb
+++ /dev/null
@@ -1,96 +0,0 @@
-require File.expand_path('../../fixtures/common', __FILE__)
-
-describe :proc_call, shared: true do
- it "invokes self" do
- Proc.new { "test!" }.send(@method).should == "test!"
- lambda { "test!" }.send(@method).should == "test!"
- proc { "test!" }.send(@method).should == "test!"
- end
-
- it "sets self's parameters to the given values" do
- Proc.new { |a, b| a + b }.send(@method, 1, 2).should == 3
- Proc.new { |*args| args }.send(@method, 1, 2, 3, 4).should == [1, 2, 3, 4]
- Proc.new { |_, *args| args }.send(@method, 1, 2, 3).should == [2, 3]
-
- lambda { |a, b| a + b }.send(@method, 1, 2).should == 3
- lambda { |*args| args }.send(@method, 1, 2, 3, 4).should == [1, 2, 3, 4]
- lambda { |_, *args| args }.send(@method, 1, 2, 3).should == [2, 3]
-
- proc { |a, b| a + b }.send(@method, 1, 2).should == 3
- proc { |*args| args }.send(@method, 1, 2, 3, 4).should == [1, 2, 3, 4]
- proc { |_, *args| args }.send(@method, 1, 2, 3).should == [2, 3]
- end
-end
-
-
-describe :proc_call_on_proc_new, shared: true do
- it "replaces missing arguments with nil" do
- Proc.new { |a, b| [a, b] }.send(@method).should == [nil, nil]
- Proc.new { |a, b| [a, b] }.send(@method, 1).should == [1, nil]
- end
-
- it "silently ignores extra arguments" do
- Proc.new { |a, b| a + b }.send(@method, 1, 2, 5).should == 3
- end
-
- it "auto-explodes a single Array argument" do
- p = Proc.new { |a, b| [a, b] }
- p.send(@method, 1, 2).should == [1, 2]
- p.send(@method, [1, 2]).should == [1, 2]
- p.send(@method, [1, 2, 3]).should == [1, 2]
- p.send(@method, [1, 2, 3], 4).should == [[1, 2, 3], 4]
- end
-end
-
-describe :proc_call_on_proc_or_lambda, shared: true do
- it "ignores excess arguments when self is a proc" do
- a = proc {|x| x}.send(@method, 1, 2)
- a.should == 1
-
- a = proc {|x| x}.send(@method, 1, 2, 3)
- a.should == 1
- end
-
- it "will call #to_ary on argument and return self if return is nil" do
- argument = ProcSpecs::ToAryAsNil.new
- result = proc { |x, _| x }.send(@method, argument)
- result.should == argument
- end
-
- it "substitutes nil for missing arguments when self is a proc" do
- proc {|x,y| [x,y]}.send(@method).should == [nil,nil]
-
- a = proc {|x,y| [x, y]}.send(@method, 1)
- a.should == [1,nil]
- end
-
- it "raises an ArgumentError on excess arguments when self is a lambda" do
- lambda {
- lambda {|x| x}.send(@method, 1, 2)
- }.should raise_error(ArgumentError)
-
- lambda {
- lambda {|x| x}.send(@method, 1, 2, 3)
- }.should raise_error(ArgumentError)
- end
-
- it "raises an ArgumentError on missing arguments when self is a lambda" do
- lambda {
- lambda {|x| x}.send(@method)
- }.should raise_error(ArgumentError)
-
- lambda {
- lambda {|x,y| [x,y]}.send(@method, 1)
- }.should raise_error(ArgumentError)
- end
-
- it "treats a single Array argument as a single argument when self is a lambda" do
- lambda { |a| a }.send(@method, [1, 2]).should == [1, 2]
- lambda { |a, b| [a, b] }.send(@method, [1, 2], 3).should == [[1,2], 3]
- end
-
- it "treats a single Array argument as a single argument when self is a proc" do
- proc { |a| a }.send(@method, [1, 2]).should == [1, 2]
- proc { |a, b| [a, b] }.send(@method, [1, 2], 3).should == [[1,2], 3]
- end
-end
diff --git a/spec/ruby/core/proc/shared/call_arguments.rb b/spec/ruby/core/proc/shared/call_arguments.rb
deleted file mode 100644
index 2e510b194e..0000000000
--- a/spec/ruby/core/proc/shared/call_arguments.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-describe :proc_call_block_args, shared: true do
- it "can receive block arguments" do
- Proc.new {|&b| b.send(@method)}.send(@method) {1 + 1}.should == 2
- lambda {|&b| b.send(@method)}.send(@method) {1 + 1}.should == 2
- proc {|&b| b.send(@method)}.send(@method) {1 + 1}.should == 2
- end
-end
diff --git a/spec/ruby/core/proc/shared/compose.rb b/spec/ruby/core/proc/shared/compose.rb
new file mode 100644
index 0000000000..c004cec7c9
--- /dev/null
+++ b/spec/ruby/core/proc/shared/compose.rb
@@ -0,0 +1,22 @@
+describe :proc_compose, shared: true do
+ it "raises TypeError if passed not callable object" do
+ lhs = @object.call
+ not_callable = Object.new
+
+ -> {
+ lhs.send(@method, not_callable)
+ }.should.raise(TypeError, "callable object is expected")
+
+ end
+
+ it "does not try to coerce argument with #to_proc" do
+ lhs = @object.call
+
+ succ = Object.new
+ def succ.to_proc(s); s.succ; end
+
+ -> {
+ lhs.send(@method, succ)
+ }.should.raise(TypeError, "callable object is expected")
+ end
+end
diff --git a/spec/ruby/core/proc/shared/dup.rb b/spec/ruby/core/proc/shared/dup.rb
index fb6fff299d..2821d2e00f 100644
--- a/spec/ruby/core/proc/shared/dup.rb
+++ b/spec/ruby/core/proc/shared/dup.rb
@@ -1,10 +1,39 @@
describe :proc_dup, shared: true do
it "returns a copy of self" do
- a = lambda { "hello" }
+ a = -> { "hello" }
b = a.send(@method)
- a.should_not equal(b)
+ a.should_not.equal?(b)
a.call.should == b.call
end
+
+ it "returns an instance of subclass" do
+ cl = Class.new(Proc)
+
+ cl.new{}.send(@method).class.should == cl
+ end
+
+ ruby_version_is "3.4" do
+ it "copies instance variables" do
+ proc = -> { "hello" }
+ proc.instance_variable_set(:@ivar, 1)
+ cl = proc.send(@method)
+ cl.instance_variables.should == [:@ivar]
+ end
+
+ it "copies the finalizer" do
+ code = <<-'RUBY'
+ obj = Proc.new { }
+
+ ObjectSpace.define_finalizer(obj, Proc.new { STDOUT.write "finalized\n" })
+
+ obj.clone
+
+ exit 0
+ RUBY
+
+ ruby_exe(code).lines.sort.should == ["finalized\n", "finalized\n"]
+ end
+ end
end
diff --git a/spec/ruby/core/proc/shared/equal.rb b/spec/ruby/core/proc/shared/equal.rb
deleted file mode 100644
index c2735ffb2f..0000000000
--- a/spec/ruby/core/proc/shared/equal.rb
+++ /dev/null
@@ -1,100 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/common', __FILE__)
-
-describe :proc_equal, shared: true do
- it "is a public method" do
- Proc.should have_public_instance_method(@method, false)
- end
-
- it "returns true if self and other are the same object" do
- p = proc { :foo }
- p.send(@method, p).should be_true
-
- p = Proc.new { :foo }
- p.send(@method, p).should be_true
-
- p = lambda { :foo }
- p.send(@method, p).should be_true
- end
-
- it "returns true if other is a dup of the original" do
- p = proc { :foo }
- p.send(@method, p.dup).should be_true
-
- p = Proc.new { :foo }
- p.send(@method, p.dup).should be_true
-
- p = lambda { :foo }
- p.send(@method, p.dup).should be_true
- end
-
- # identical here means the same method invocation.
- it "returns false when bodies are the same but capture env is not identical" do
- a = ProcSpecs.proc_for_1
- b = ProcSpecs.proc_for_1
-
- a.send(@method, b).should be_false
- end
-
- it "returns true if both procs have the same body and environment" do
- p = proc { :foo }
- p2 = proc { :foo }
- p.send(@method, p2).should be_true
- end
-
- it "returns true if both lambdas with the same body and environment" do
- x = lambda { :foo }
- x2 = lambda { :foo }
- x.send(@method, x2).should be_true
- end
-
- it "returns true if both different kinds of procs with the same body and env" do
- p = lambda { :foo }
- p2 = proc { :foo }
- p.send(@method, p2).should be_true
-
- x = proc { :bar }
- x2 = lambda { :bar }
- x.send(@method, x2).should be_true
- end
-
- it "returns false if other is not a Proc" do
- p = proc { :foo }
- p.send(@method, []).should be_false
-
- p = Proc.new { :foo }
- p.send(@method, Object.new).should be_false
-
- p = lambda { :foo }
- p.send(@method, :foo).should be_false
- end
-
- it "returns false if self and other are both procs but have different bodies" do
- p = proc { :bar }
- p2 = proc { :foo }
- p.send(@method, p2).should be_false
- end
-
- it "returns false if self and other are both lambdas but have different bodies" do
- p = lambda { :foo }
- p2 = lambda { :bar }
- p.send(@method, p2).should be_false
- end
-end
-
-describe :proc_equal_undefined, shared: true do
- it "is not defined" do
- Proc.should_not have_instance_method(@method, false)
- end
-
- it "returns false if other is a dup of the original" do
- p = proc { :foo }
- p.send(@method, p.dup).should be_false
-
- p = Proc.new { :foo }
- p.send(@method, p.dup).should be_false
-
- p = lambda { :foo }
- p.send(@method, p.dup).should be_false
- end
-end
diff --git a/spec/ruby/core/proc/shared/to_s.rb b/spec/ruby/core/proc/shared/to_s.rb
deleted file mode 100644
index c3f82a73f3..0000000000
--- a/spec/ruby/core/proc/shared/to_s.rb
+++ /dev/null
@@ -1,27 +0,0 @@
-describe :proc_to_s, shared: true do
- describe "for a proc created with Proc.new" do
- it "returns a description optionally including file and line number" do
- Proc.new { "hello" }.send(@method).should =~ /^#<Proc:([^ ]*?)(@([^ ]*)\/to_s\.rb:4)?>$/
- end
- end
-
- describe "for a proc created with lambda" do
- it "returns a description including '(lambda)' and optionally including file and line number" do
- lambda { "hello" }.send(@method).should =~ /^#<Proc:([^ ]*?)(@([^ ]*)\/to_s\.rb:10)? \(lambda\)>$/
- end
- end
-
- describe "for a proc created with proc" do
- it "returns a description optionally including file and line number" do
- proc { "hello" }.send(@method).should =~ /^#<Proc:([^ ]*?)(@([^ ]*)\/to_s\.rb:16)?>$/
- end
- end
-
- describe "for a proc created with UnboundMethod#to_proc" do
- it "returns a description including '(lambda)' and optionally including file and line number" do
- def hello; end
-
- method("hello").to_proc.send(@method).should =~ /^#<Proc:([^ ]*?)(@([^ ]*)\/to_s\.rb:22)? \(lambda\)>$/
- end
- end
-end
diff --git a/spec/ruby/core/proc/source_location_spec.rb b/spec/ruby/core/proc/source_location_spec.rb
index 311d13c050..d27ad0559e 100644
--- a/spec/ruby/core/proc/source_location_spec.rb
+++ b/spec/ruby/core/proc/source_location_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/source_location', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/source_location'
describe "Proc#source_location" do
before :each do
@@ -10,52 +10,52 @@ describe "Proc#source_location" do
end
it "returns an Array" do
- @proc.source_location.should be_an_instance_of(Array)
- @proc_new.source_location.should be_an_instance_of(Array)
- @lambda.source_location.should be_an_instance_of(Array)
- @method.source_location.should be_an_instance_of(Array)
+ @proc.source_location.should.instance_of?(Array)
+ @proc_new.source_location.should.instance_of?(Array)
+ @lambda.source_location.should.instance_of?(Array)
+ @method.source_location.should.instance_of?(Array)
end
it "sets the first value to the path of the file in which the proc was defined" do
file = @proc.source_location.first
- file.should be_an_instance_of(String)
- file.should == File.dirname(__FILE__) + '/fixtures/source_location.rb'
+ file.should.instance_of?(String)
+ file.should == File.realpath('fixtures/source_location.rb', __dir__)
file = @proc_new.source_location.first
- file.should be_an_instance_of(String)
- file.should == File.dirname(__FILE__) + '/fixtures/source_location.rb'
+ file.should.instance_of?(String)
+ file.should == File.realpath('fixtures/source_location.rb', __dir__)
file = @lambda.source_location.first
- file.should be_an_instance_of(String)
- file.should == File.dirname(__FILE__) + '/fixtures/source_location.rb'
+ file.should.instance_of?(String)
+ file.should == File.realpath('fixtures/source_location.rb', __dir__)
file = @method.source_location.first
- file.should be_an_instance_of(String)
- file.should == File.dirname(__FILE__) + '/fixtures/source_location.rb'
+ file.should.instance_of?(String)
+ file.should == File.realpath('fixtures/source_location.rb', __dir__)
end
- it "sets the last value to a Fixnum representing the line on which the proc was defined" do
+ it "sets the last value to an Integer representing the line on which the proc was defined" do
line = @proc.source_location.last
- line.should be_an_instance_of(Fixnum)
+ line.should.instance_of?(Integer)
line.should == 4
line = @proc_new.source_location.last
- line.should be_an_instance_of(Fixnum)
+ line.should.instance_of?(Integer)
line.should == 12
line = @lambda.source_location.last
- line.should be_an_instance_of(Fixnum)
+ line.should.instance_of?(Integer)
line.should == 8
line = @method.source_location.last
- line.should be_an_instance_of(Fixnum)
+ line.should.instance_of?(Integer)
line.should == 15
end
it "works even if the proc was created on the same line" do
proc { true }.source_location.should == [__FILE__, __LINE__]
Proc.new { true }.source_location.should == [__FILE__, __LINE__]
- lambda { true }.source_location.should == [__FILE__, __LINE__]
+ -> { true }.source_location.should == [__FILE__, __LINE__]
end
it "returns the first line of a multi-line proc (i.e. the line containing 'proc do')" do
@@ -69,4 +69,23 @@ describe "Proc#source_location" do
ProcSpecs::SourceLocation.my_detached_proc_new.source_location.last.should == 51
ProcSpecs::SourceLocation.my_detached_lambda.source_location.last.should == 46
end
+
+ it "returns the same value for a proc-ified method as the method reports" do
+ method = ProcSpecs::SourceLocation.method(:my_proc)
+ proc = method.to_proc
+
+ method.source_location.should == proc.source_location
+ end
+
+ it "returns nil for a core method that has been proc-ified" do
+ method = [].method(:<<)
+ proc = method.to_proc
+
+ proc.source_location.should == nil
+ end
+
+ it "works for eval with a given line" do
+ proc = eval('-> {}', nil, "foo", 100)
+ proc.source_location.should == ["foo", 100]
+ end
end
diff --git a/spec/ruby/core/proc/to_proc_spec.rb b/spec/ruby/core/proc/to_proc_spec.rb
index e5637c9f41..7f35a4f19b 100644
--- a/spec/ruby/core/proc/to_proc_spec.rb
+++ b/spec/ruby/core/proc/to_proc_spec.rb
@@ -1,9 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Proc#to_proc" do
it "returns self" do
- [Proc.new {}, lambda {}, proc {}].each { |p|
- p.to_proc.should equal(p)
+ [Proc.new {}, -> {}, proc {}].each { |p|
+ p.to_proc.should.equal?(p)
}
end
end
diff --git a/spec/ruby/core/proc/to_s_spec.rb b/spec/ruby/core/proc/to_s_spec.rb
index e0b248c369..58a9aa76fb 100644
--- a/spec/ruby/core/proc/to_s_spec.rb
+++ b/spec/ruby/core/proc/to_s_spec.rb
@@ -1,6 +1,62 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/to_s', __FILE__)
+require_relative '../../spec_helper'
describe "Proc#to_s" do
- it_behaves_like :proc_to_s, :to_s
+ describe "for a proc created with Proc.new" do
+ it "returns a description including file and line number" do
+ Proc.new { "hello" }.to_s.should =~ /^#<Proc:([^ ]*?) #{Regexp.escape __FILE__}:#{__LINE__ }>$/
+ end
+
+ it "has a binary encoding" do
+ Proc.new { "hello" }.to_s.encoding.should == Encoding::BINARY
+ end
+ end
+
+ describe "for a proc created with lambda" do
+ it "returns a description including '(lambda)' and including file and line number" do
+ -> { "hello" }.to_s.should =~ /^#<Proc:([^ ]*?) #{Regexp.escape __FILE__}:#{__LINE__ } \(lambda\)>$/
+ end
+
+ it "has a binary encoding" do
+ -> { "hello" }.to_s.encoding.should == Encoding::BINARY
+ end
+ end
+
+ describe "for a proc created with proc" do
+ it "returns a description including file and line number" do
+ proc { "hello" }.to_s.should =~ /^#<Proc:([^ ]*?) #{Regexp.escape __FILE__}:#{__LINE__ }>$/
+ end
+
+ it "has a binary encoding" do
+ proc { "hello" }.to_s.encoding.should == Encoding::BINARY
+ end
+ end
+
+ describe "for a proc created with UnboundMethod#to_proc" do
+ it "returns a description including '(lambda)' and optionally including file and line number" do
+ def hello; end
+ s = method("hello").to_proc.to_s
+ if s.include? __FILE__
+ s.should =~ /^#<Proc:([^ ]*?) #{Regexp.escape __FILE__}:#{__LINE__ - 3} \(lambda\)>$/
+ else
+ s.should =~ /^#<Proc:([^ ]*?) \(lambda\)>$/
+ end
+ end
+
+ it "has a binary encoding" do
+ def hello; end
+ method("hello").to_proc.to_s.encoding.should == Encoding::BINARY
+ end
+ end
+
+ describe "for a proc created with Symbol#to_proc" do
+ it "returns a description including '(&:symbol)'" do
+ proc = :foobar.to_proc
+ proc.to_s.should.include?('(&:foobar)')
+ end
+
+ it "has a binary encoding" do
+ proc = :foobar.to_proc
+ proc.to_s.encoding.should == Encoding::BINARY
+ end
+ end
end
diff --git a/spec/ruby/core/proc/yield_spec.rb b/spec/ruby/core/proc/yield_spec.rb
index 930e44ea78..e6ee2d5eff 100644
--- a/spec/ruby/core/proc/yield_spec.rb
+++ b/spec/ruby/core/proc/yield_spec.rb
@@ -1,16 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/call', __FILE__)
-require File.expand_path('../shared/call_arguments', __FILE__)
+require_relative '../../spec_helper'
describe "Proc#yield" do
- it_behaves_like :proc_call, :yield
- it_behaves_like :proc_call_block_args, :yield
-end
-
-describe "Proc#yield on a Proc created with Proc.new" do
- it_behaves_like :proc_call_on_proc_new, :yield
-end
-
-describe "Proc#yield on a Proc created with Kernel#lambda or Kernel#proc" do
- it_behaves_like :proc_call_on_proc_or_lambda, :yield
+ it "is an alias of Proc#call" do
+ Proc.instance_method(:yield).should == Proc.instance_method(:call)
+ end
end
diff --git a/spec/ruby/core/process/_fork_spec.rb b/spec/ruby/core/process/_fork_spec.rb
new file mode 100644
index 0000000000..620f243ce5
--- /dev/null
+++ b/spec/ruby/core/process/_fork_spec.rb
@@ -0,0 +1,24 @@
+require_relative '../../spec_helper'
+
+describe "Process._fork" do
+ it "for #respond_to? returns the same as Process.respond_to?(:fork)" do
+ Process.respond_to?(:_fork).should == Process.respond_to?(:fork)
+ end
+
+ # Using respond_to? in a guard here is OK because the correct semantics
+ # are that _fork is implemented if and only if fork is (see above).
+ guard_not -> { Process.respond_to?(:fork) } do
+ it "raises a NotImplementedError when called" do
+ -> { Process._fork }.should.raise(NotImplementedError)
+ end
+ end
+
+ guard -> { Process.respond_to?(:fork) } do
+ it "is called by Process#fork" do
+ Process.should_receive(:_fork).once.and_return(42)
+
+ pid = Process.fork {}
+ pid.should.equal?(42)
+ end
+ end
+end
diff --git a/spec/ruby/core/process/abort_spec.rb b/spec/ruby/core/process/abort_spec.rb
index f7113c8b7e..1b6ad1da43 100644
--- a/spec/ruby/core/process/abort_spec.rb
+++ b/spec/ruby/core/process/abort_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/process/abort', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../../shared/process/abort'
describe "Process.abort" do
it_behaves_like :process_abort, :abort, Process
diff --git a/spec/ruby/core/process/argv0_spec.rb b/spec/ruby/core/process/argv0_spec.rb
new file mode 100644
index 0000000000..4c7a2c9ecb
--- /dev/null
+++ b/spec/ruby/core/process/argv0_spec.rb
@@ -0,0 +1,23 @@
+require_relative '../../spec_helper'
+
+describe "Process.argv0" do
+ it "returns a String" do
+ Process.argv0.should.is_a?(String)
+ end
+
+ it "is the path given as the main script and the same as __FILE__" do
+ script = "fixtures/argv0.rb"
+
+ Dir.chdir(__dir__) do
+ ruby_exe(script).should == "#{script}\n#{script}\nOK"
+ end
+ end
+
+ it "returns a frozen object" do
+ Process.argv0.should.frozen?
+ end
+
+ it "returns every time the same object" do
+ Process.argv0.should.equal?(Process.argv0)
+ end
+end
diff --git a/spec/ruby/core/process/clock_getres_spec.rb b/spec/ruby/core/process/clock_getres_spec.rb
new file mode 100644
index 0000000000..85aa2b25f1
--- /dev/null
+++ b/spec/ruby/core/process/clock_getres_spec.rb
@@ -0,0 +1,33 @@
+require_relative '../../spec_helper'
+
+describe "Process.clock_getres" do
+ # These are documented
+
+ it "with :GETTIMEOFDAY_BASED_CLOCK_REALTIME reports 1 microsecond" do
+ Process.clock_getres(:GETTIMEOFDAY_BASED_CLOCK_REALTIME, :nanosecond).should == 1_000
+ end
+
+ it "with :TIME_BASED_CLOCK_REALTIME reports 1 second" do
+ Process.clock_getres(:TIME_BASED_CLOCK_REALTIME, :nanosecond).should == 1_000_000_000
+ end
+
+ platform_is_not :windows do
+ it "with :GETRUSAGE_BASED_CLOCK_PROCESS_CPUTIME_ID reports 1 microsecond" do
+ Process.clock_getres(:GETRUSAGE_BASED_CLOCK_PROCESS_CPUTIME_ID, :nanosecond).should == 1_000
+ end
+ end
+
+ # These are observed
+
+ platform_is :linux, :darwin, :windows do
+ it "with Process::CLOCK_REALTIME reports at least 10 millisecond" do
+ Process.clock_getres(Process::CLOCK_REALTIME, :nanosecond).should <= 10_000_000
+ end
+ end
+
+ platform_is :linux, :darwin, :windows do
+ it "with Process::CLOCK_MONOTONIC reports at least 10 millisecond" do
+ Process.clock_getres(Process::CLOCK_MONOTONIC, :nanosecond).should <= 10_000_000
+ end
+ end
+end
diff --git a/spec/ruby/core/process/clock_gettime_spec.rb b/spec/ruby/core/process/clock_gettime_spec.rb
new file mode 100644
index 0000000000..88158904e1
--- /dev/null
+++ b/spec/ruby/core/process/clock_gettime_spec.rb
@@ -0,0 +1,152 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/clocks'
+
+describe "Process.clock_gettime" do
+ ProcessSpecs.clock_constants.each do |name, value|
+ it "can be called with Process::#{name}" do
+ Process.clock_gettime(value).should.instance_of?(Float)
+ end
+ end
+
+ describe 'time units' do
+ it 'handles a fixed set of time units' do
+ [:nanosecond, :microsecond, :millisecond, :second].each do |unit|
+ Process.clock_gettime(Process::CLOCK_MONOTONIC, unit).should.is_a?(Integer)
+ end
+
+ [:float_microsecond, :float_millisecond, :float_second].each do |unit|
+ Process.clock_gettime(Process::CLOCK_MONOTONIC, unit).should.instance_of?(Float)
+ end
+ end
+
+ it 'raises an ArgumentError for an invalid time unit' do
+ -> { Process.clock_gettime(Process::CLOCK_MONOTONIC, :bad) }.should.raise(ArgumentError)
+ end
+
+ it 'defaults to :float_second' do
+ t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
+ t2 = Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_second)
+
+ t1.should.instance_of?(Float)
+ t2.should.instance_of?(Float)
+ t2.should be_close(t1, TIME_TOLERANCE)
+ end
+
+ it 'uses the default time unit (:float_second) when passed nil' do
+ t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC, nil)
+ t2 = Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_second)
+
+ t1.should.instance_of?(Float)
+ t2.should.instance_of?(Float)
+ t2.should be_close(t1, TIME_TOLERANCE)
+ end
+ end
+
+ describe "supports the platform clocks mentioned in the documentation" do
+ it "CLOCK_REALTIME" do
+ Process.clock_gettime(Process::CLOCK_REALTIME).should.instance_of?(Float)
+ end
+
+ it "CLOCK_MONOTONIC" do
+ Process.clock_gettime(Process::CLOCK_MONOTONIC).should.instance_of?(Float)
+ end
+
+ # These specs need macOS 10.12+ / darwin 16+
+ guard -> { platform_is_not(:darwin) or kernel_version_is '16' } do
+ platform_is :linux, :openbsd, :darwin do
+ it "CLOCK_PROCESS_CPUTIME_ID" do
+ Process.clock_gettime(Process::CLOCK_PROCESS_CPUTIME_ID).should.instance_of?(Float)
+ end
+ end
+
+ platform_is :linux, :freebsd, :openbsd, :darwin do
+ it "CLOCK_THREAD_CPUTIME_ID" do
+ Process.clock_gettime(Process::CLOCK_THREAD_CPUTIME_ID).should.instance_of?(Float)
+ end
+ end
+
+ platform_is :linux, :darwin do
+ it "CLOCK_MONOTONIC_RAW" do
+ Process.clock_gettime(Process::CLOCK_MONOTONIC_RAW).should.instance_of?(Float)
+ end
+ end
+
+ platform_is :darwin do
+ it "CLOCK_MONOTONIC_RAW_APPROX" do
+ Process.clock_gettime(Process::CLOCK_MONOTONIC_RAW_APPROX).should.instance_of?(Float)
+ end
+
+ it "CLOCK_UPTIME_RAW and CLOCK_UPTIME_RAW_APPROX" do
+ Process.clock_gettime(Process::CLOCK_UPTIME_RAW).should.instance_of?(Float)
+ Process.clock_gettime(Process::CLOCK_UPTIME_RAW_APPROX).should.instance_of?(Float)
+ end
+ end
+ end
+
+ platform_is :freebsd do
+ it "CLOCK_VIRTUAL" do
+ Process.clock_gettime(Process::CLOCK_VIRTUAL).should.instance_of?(Float)
+ end
+
+ it "CLOCK_PROF" do
+ Process.clock_gettime(Process::CLOCK_PROF).should.instance_of?(Float)
+ end
+ end
+
+ platform_is :freebsd, :openbsd do
+ it "CLOCK_UPTIME" do
+ Process.clock_gettime(Process::CLOCK_UPTIME).should.instance_of?(Float)
+ end
+ end
+
+ platform_is :freebsd do
+ it "CLOCK_REALTIME_FAST and CLOCK_REALTIME_PRECISE" do
+ Process.clock_gettime(Process::CLOCK_REALTIME_FAST).should.instance_of?(Float)
+ Process.clock_gettime(Process::CLOCK_REALTIME_PRECISE).should.instance_of?(Float)
+ end
+
+ it "CLOCK_MONOTONIC_FAST and CLOCK_MONOTONIC_PRECISE" do
+ Process.clock_gettime(Process::CLOCK_MONOTONIC_FAST).should.instance_of?(Float)
+ Process.clock_gettime(Process::CLOCK_MONOTONIC_PRECISE).should.instance_of?(Float)
+ end
+
+ it "CLOCK_UPTIME_FAST and CLOCK_UPTIME_PRECISE" do
+ Process.clock_gettime(Process::CLOCK_UPTIME_FAST).should.instance_of?(Float)
+ Process.clock_gettime(Process::CLOCK_UPTIME_PRECISE).should.instance_of?(Float)
+ end
+
+ it "CLOCK_SECOND" do
+ Process.clock_gettime(Process::CLOCK_SECOND).should.instance_of?(Float)
+ end
+ end
+
+ guard -> { platform_is :linux and kernel_version_is '2.6.32' } do
+ it "CLOCK_REALTIME_COARSE" do
+ Process.clock_gettime(Process::CLOCK_REALTIME_COARSE).should.instance_of?(Float)
+ end
+
+ it "CLOCK_MONOTONIC_COARSE" do
+ Process.clock_gettime(Process::CLOCK_MONOTONIC_COARSE).should.instance_of?(Float)
+ end
+ end
+
+ guard -> { platform_is :linux and kernel_version_is '2.6.39' } do
+ it "CLOCK_BOOTTIME" do
+ skip "No Process::CLOCK_BOOTTIME" unless defined?(Process::CLOCK_BOOTTIME)
+ Process.clock_gettime(Process::CLOCK_BOOTTIME).should.instance_of?(Float)
+ end
+ end
+
+ guard -> { platform_is "x86_64-linux" and kernel_version_is '3.0' } do
+ it "CLOCK_REALTIME_ALARM" do
+ skip "No Process::CLOCK_REALTIME_ALARM" unless defined?(Process::CLOCK_REALTIME_ALARM)
+ Process.clock_gettime(Process::CLOCK_REALTIME_ALARM).should.instance_of?(Float)
+ end
+
+ it "CLOCK_BOOTTIME_ALARM" do
+ skip "No Process::CLOCK_BOOTTIME_ALARM" unless defined?(Process::CLOCK_BOOTTIME_ALARM)
+ Process.clock_gettime(Process::CLOCK_BOOTTIME_ALARM).should.instance_of?(Float)
+ end
+ end
+ end
+end
diff --git a/spec/ruby/core/process/constants_spec.rb b/spec/ruby/core/process/constants_spec.rb
index 2fa93ad8bf..5a4c478e74 100644
--- a/spec/ruby/core/process/constants_spec.rb
+++ b/spec/ruby/core/process/constants_spec.rb
@@ -1,63 +1,126 @@
+require_relative '../../spec_helper'
describe "Process::Constants" do
platform_is :darwin, :netbsd, :freebsd do
- it "has the correct constant values on BSD-like systems" do
- Process::WNOHANG.should == 1
- Process::WUNTRACED.should == 2
- Process::PRIO_PROCESS.should == 0
- Process::PRIO_PGRP.should == 1
- Process::PRIO_USER.should == 2
- Process::RLIM_INFINITY.should == 9223372036854775807
- Process::RLIMIT_CPU.should == 0
- Process::RLIMIT_FSIZE.should == 1
- Process::RLIMIT_DATA.should == 2
- Process::RLIMIT_STACK.should == 3
- Process::RLIMIT_CORE.should == 4
- Process::RLIMIT_RSS.should == 5
- Process::RLIMIT_MEMLOCK.should == 6
- Process::RLIMIT_NPROC.should == 7
- Process::RLIMIT_NOFILE.should == 8
+ describe "on BSD-like systems" do
+ %i[
+ WNOHANG
+ WUNTRACED
+ PRIO_PROCESS
+ PRIO_PGRP
+ PRIO_USER
+ RLIM_INFINITY
+ RLIMIT_CPU
+ RLIMIT_FSIZE
+ RLIMIT_DATA
+ RLIMIT_STACK
+ RLIMIT_CORE
+ RLIMIT_RSS
+ RLIMIT_MEMLOCK
+ RLIMIT_NPROC
+ RLIMIT_NOFILE
+ ].each do |const|
+ it "defines #{const}" do
+ Process.const_defined?(const).should == true
+ Process.const_get(const).should.instance_of?(Integer)
+ end
+ end
end
end
platform_is :darwin do
- it "has the correct constant values on Darwin" do
- Process::RLIM_SAVED_MAX.should == 9223372036854775807
- Process::RLIM_SAVED_CUR.should == 9223372036854775807
- Process::RLIMIT_AS.should == 5
+ describe "on Darwin" do
+ %i[
+ RLIM_SAVED_MAX
+ RLIM_SAVED_CUR
+ RLIMIT_AS
+ ].each do |const|
+ it "defines #{const}" do
+ Process.const_defined?(const).should == true
+ Process.const_get(const).should.instance_of?(Integer)
+ end
+ end
end
end
platform_is :linux do
- it "has the correct constant values on Linux" do
- Process::WNOHANG.should == 1
- Process::WUNTRACED.should == 2
- Process::PRIO_PROCESS.should == 0
- Process::PRIO_PGRP.should == 1
- Process::PRIO_USER.should == 2
- Process::RLIMIT_CPU.should == 0
- Process::RLIMIT_FSIZE.should == 1
- Process::RLIMIT_DATA.should == 2
- Process::RLIMIT_STACK.should == 3
- Process::RLIMIT_CORE.should == 4
- Process::RLIMIT_RSS.should == 5
- Process::RLIMIT_NPROC.should == 6
- Process::RLIMIT_NOFILE.should == 7
- Process::RLIMIT_MEMLOCK.should == 8
- Process::RLIMIT_AS.should == 9
-
- # These values appear to change according to the platform.
- values = [4294967295, 9223372036854775807, 18446744073709551615]
- values.include?(Process::RLIM_INFINITY).should be_true
- values.include?(Process::RLIM_SAVED_MAX).should be_true
- values.include?(Process::RLIM_SAVED_CUR).should be_true
+ describe "on Linux" do
+ %i[
+ WNOHANG
+ WUNTRACED
+ PRIO_PROCESS
+ PRIO_PGRP
+ PRIO_USER
+ RLIMIT_CPU
+ RLIMIT_FSIZE
+ RLIMIT_DATA
+ RLIMIT_STACK
+ RLIMIT_CORE
+ RLIMIT_RSS
+ RLIMIT_NPROC
+ RLIMIT_NOFILE
+ RLIMIT_MEMLOCK
+ RLIMIT_AS
+ RLIM_INFINITY
+ RLIM_SAVED_MAX
+ RLIM_SAVED_CUR
+ ].each do |const|
+ it "defines #{const}" do
+ Process.const_defined?(const).should == true
+ Process.const_get(const).should.instance_of?(Integer)
+ end
+ end
end
end
platform_is :netbsd, :freebsd do
- it "Process::RLIMIT_SBSIZE" do
- Process::RLIMIT_SBSIZE.should == 9 # FIXME: what's it equal?
- Process::RLIMIT_AS.should == 10
+ describe "on NetBSD and FreeBSD" do
+ %i[
+ RLIMIT_SBSIZE
+ RLIMIT_AS
+ ].each do |const|
+ it "defines #{const}" do
+ Process.const_defined?(const).should == true
+ Process.const_get(const).should.instance_of?(Integer)
+ end
+ end
+ end
+ end
+
+ platform_is :freebsd do
+ describe "on FreeBSD" do
+ %i[
+ RLIMIT_NPTS
+ ].each do |const|
+ it "defines #{const}" do
+ Process.const_defined?(const).should == true
+ Process.const_get(const).should.instance_of?(Integer)
+ end
+ end
+ end
+ end
+
+ platform_is :windows do
+ describe "on Windows" do
+ %i[
+ RLIMIT_CPU
+ RLIMIT_FSIZE
+ RLIMIT_DATA
+ RLIMIT_STACK
+ RLIMIT_CORE
+ RLIMIT_RSS
+ RLIMIT_NPROC
+ RLIMIT_NOFILE
+ RLIMIT_MEMLOCK
+ RLIMIT_AS
+ RLIM_INFINITY
+ RLIM_SAVED_MAX
+ RLIM_SAVED_CUR
+ ].each do |const|
+ it "does not define #{const}" do
+ Process.const_defined?(const).should == false
+ end
+ end
end
end
end
diff --git a/spec/ruby/core/process/daemon_spec.rb b/spec/ruby/core/process/daemon_spec.rb
index f68ddfe253..7198dfa6ee 100644
--- a/spec/ruby/core/process/daemon_spec.rb
+++ b/spec/ruby/core/process/daemon_spec.rb
@@ -1,7 +1,11 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/common', __FILE__)
-
-platform_is_not :windows do
+require_relative '../../spec_helper'
+require_relative 'fixtures/common'
+
+guard -> {
+ Process.respond_to?(:fork) and
+ # macOS 15 is not working for these examples
+ !(/darwin/ =~ RUBY_PLATFORM && /15/ =~ `sw_vers -productVersion`)
+} do
describe :process_daemon_keep_stdio_open_false, shared: true do
it "redirects stdout to /dev/null" do
@daemon.invoke("keep_stdio_open_false_stdout", @object).should == ""
@@ -86,10 +90,6 @@ platform_is_not :windows do
@daemon.invoke("stay_in_dir", [true]).should == @invoke_dir
end
- it "does not change to the root directory if the first argument is non-false" do
- @daemon.invoke("stay_in_dir", [:yes]).should == @invoke_dir
- end
-
describe "when the second argument is not given" do
it_behaves_like :process_daemon_keep_stdio_open_false, nil, [false]
end
@@ -105,19 +105,19 @@ platform_is_not :windows do
describe "when the second argument is true" do
it_behaves_like :process_daemon_keep_stdio_open_true, nil, [false, true]
end
-
- describe "when the second argument is non-false" do
- it_behaves_like :process_daemon_keep_stdio_open_true, nil, [false, :yes]
- end
end
end
-platform_is :windows do
+guard_not -> { Process.respond_to?(:fork) } do
describe "Process.daemon" do
+ it "returns false from #respond_to?" do
+ Process.respond_to?(:daemon).should == false
+ end
+
it "raises a NotImplementedError" do
- lambda {
+ -> {
Process.daemon
- }.should raise_error(NotImplementedError)
+ }.should.raise(NotImplementedError)
end
end
end
diff --git a/spec/ruby/core/process/detach_spec.rb b/spec/ruby/core/process/detach_spec.rb
index 7a38e290ce..862768a909 100644
--- a/spec/ruby/core/process/detach_spec.rb
+++ b/spec/ruby/core/process/detach_spec.rb
@@ -1,46 +1,82 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/common'
describe "Process.detach" do
- platform_is_not :windows do
- it "returns a thread" do
- pid = Process.fork { Process.exit! }
- thr = Process.detach(pid)
- thr.should be_kind_of(Thread)
- thr.join
- end
+ ProcessSpecs.use_system_ruby(self)
- it "produces the exit Process::Status as the thread value" do
- pid = Process.fork { Process.exit! }
- thr = Process.detach(pid)
- thr.join
+ it "returns a thread" do
+ pid = Process.spawn(*ruby_exe, "-e", "exit")
+ thr = Process.detach(pid)
+ thr.should.is_a?(Thread)
+ thr.join
+ end
- status = thr.value
- status.should be_kind_of(Process::Status)
- status.pid.should == pid
- end
+ it "produces the exit Process::Status as the thread value" do
+ pid = Process.spawn(*ruby_exe, "-e", "exit")
+ thr = Process.detach(pid)
+ thr.join
- platform_is_not :openbsd do
- it "reaps the child process's status automatically" do
- pid = Process.fork { Process.exit! }
- Process.detach(pid).join
- lambda { Process.waitpid(pid) }.should raise_error(Errno::ECHILD)
- end
+ status = thr.value
+ status.should.is_a?(Process::Status)
+ status.pid.should == pid
+ end
+
+ platform_is_not :openbsd do
+ it "reaps the child process's status automatically" do
+ pid = Process.spawn(*ruby_exe, "-e", "exit")
+ Process.detach(pid).join
+ -> { Process.waitpid(pid) }.should.raise(Errno::ECHILD)
end
+ end
- it "sets the :pid thread-local to the PID" do
- pid = Process.fork { Process.exit! }
- thr = Process.detach(pid)
- thr.join
+ it "sets the :pid thread-local to the PID" do
+ pid = Process.spawn(*ruby_exe, "-e", "exit")
+ thr = Process.detach(pid)
+ thr.join
- thr[:pid].should == pid
- end
+ thr[:pid].should == pid
+ end
- it "provides a #pid method on the returned thread which returns the PID" do
- pid = Process.fork { Process.exit! }
- thr = Process.detach(pid)
- thr.join
+ it "provides a #pid method on the returned thread which returns the PID" do
+ pid = Process.spawn(*ruby_exe, "-e", "exit")
+ thr = Process.detach(pid)
+ thr.join
- thr.pid.should == pid
- end
+ thr.pid.should == pid
+ end
+
+ it "tolerates not existing child process pid" do
+ # Use a value that is close to the INT_MAX (pid usually is signed int).
+ # It should (at least) be greater than allowed pid limit value that depends on OS.
+ pid_not_existing = 2.pow(30)
+
+ # Check that there is no a child process with this hardcoded pid.
+ # Command `kill 0 pid`:
+ # - returns "1" if a process exists and
+ # - raises Errno::ESRCH otherwise
+ -> { Process.kill(0, pid_not_existing) }.should.raise(Errno::ESRCH)
+
+ thr = Process.detach(pid_not_existing)
+ thr.join
+
+ thr.should.is_a?(Thread)
+ end
+
+ it "calls #to_int to implicitly convert non-Integer pid to Integer" do
+ pid = MockObject.new('mock-enumerable')
+ pid.should_receive(:to_int).and_return(100500)
+
+ Process.detach(pid).join
+ end
+
+ it "raises TypeError when pid argument does not have #to_int method" do
+ -> { Process.detach(Object.new) }.should.raise(TypeError, "no implicit conversion of Object into Integer")
+ end
+
+ it "raises TypeError when #to_int returns non-Integer value" do
+ pid = MockObject.new('mock-enumerable')
+ pid.should_receive(:to_int).and_return(:symbol)
+
+ -> { Process.detach(pid) }.should raise_consistent_error(TypeError, "can't convert MockObject into Integer (MockObject#to_int gives Symbol)")
end
end
diff --git a/spec/ruby/core/process/egid_spec.rb b/spec/ruby/core/process/egid_spec.rb
index 316343944c..69c86bebe2 100644
--- a/spec/ruby/core/process/egid_spec.rb
+++ b/spec/ruby/core/process/egid_spec.rb
@@ -1,8 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Process.egid" do
it "returns the effective group ID for this process" do
- Process.egid.should be_kind_of(Integer)
+ Process.egid.should.is_a?(Integer)
end
it "also goes by Process::GID.eid" do
@@ -15,5 +15,44 @@ describe "Process.egid" do
end
describe "Process.egid=" do
- it "needs to be reviewed for spec completeness"
+
+ platform_is_not :windows do
+ it "raises TypeError if not passed an Integer or String" do
+ -> { Process.egid = Object.new }.should.raise(TypeError)
+ end
+
+ it "sets the effective group id to its own gid if given the username corresponding to its own gid" do
+ raise unless Process.gid == Process.egid
+
+ require "etc"
+ group = Etc.getgrgid(Process.gid).name
+
+ Process.egid = group
+ Process.egid.should == Process.gid
+ end
+
+ as_user do
+ it "raises Errno::ERPERM if run by a non superuser trying to set the root group id" do
+ -> { Process.egid = 0 }.should.raise(Errno::EPERM)
+ end
+
+ platform_is :linux do
+ it "raises Errno::ERPERM if run by a non superuser trying to set the group id from group name" do
+ -> { Process.egid = "root" }.should.raise(Errno::EPERM)
+ end
+ end
+ end
+
+ as_superuser do
+ context "when ran by a superuser" do
+ it "sets the effective group id for the current process if run by a superuser" do
+ code = <<-RUBY
+ Process.egid = 1
+ puts Process.egid
+ RUBY
+ ruby_exe(code).should == "1\n"
+ end
+ end
+ end
+ end
end
diff --git a/spec/ruby/core/process/euid_spec.rb b/spec/ruby/core/process/euid_spec.rb
index 1855ef66f5..da76f06e59 100644
--- a/spec/ruby/core/process/euid_spec.rb
+++ b/spec/ruby/core/process/euid_spec.rb
@@ -1,8 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Process.euid" do
it "returns the effective user ID for this process" do
- Process.euid.should be_kind_of(Fixnum)
+ Process.euid.should.is_a?(Integer)
end
it "also goes by Process::UID.eid" do
@@ -18,40 +18,37 @@ describe "Process.euid=" do
platform_is_not :windows do
it "raises TypeError if not passed an Integer" do
- lambda { Process.euid = Object.new }.should raise_error(TypeError)
+ -> { Process.euid = Object.new }.should.raise(TypeError)
+ end
+
+ it "sets the effective user id to its own uid if given the username corresponding to its own uid" do
+ raise unless Process.uid == Process.euid
+
+ require "etc"
+ user = Etc.getpwuid(Process.uid).name
+
+ Process.euid = user
+ Process.euid.should == Process.uid
end
as_user do
it "raises Errno::ERPERM if run by a non superuser trying to set the superuser id" do
- lambda { (Process.euid = 0)}.should raise_error(Errno::EPERM)
+ -> { Process.euid = 0 }.should.raise(Errno::EPERM)
end
it "raises Errno::ERPERM if run by a non superuser trying to set the superuser id from username" do
- lambda { Process.euid = "root" }.should raise_error(Errno::EPERM)
+ -> { Process.euid = "root" }.should.raise(Errno::EPERM)
end
end
as_superuser do
describe "if run by a superuser" do
- with_feature :fork do
- it "sets the effective user id for the current process if run by a superuser" do
- read, write = IO.pipe
- pid = Process.fork do
- begin
- read.close
- Process.euid = 1
- write << Process.euid
- write.close
- rescue Exception => e
- write << e << e.backtrace
- end
- Process.exit!
- end
- write.close
- euid = read.gets
- euid.should == "1"
- Process.wait pid
- end
+ it "sets the effective user id for the current process if run by a superuser" do
+ code = <<-RUBY
+ Process.euid = 1
+ puts Process.euid
+ RUBY
+ ruby_exe(code).should == "1\n"
end
end
end
diff --git a/spec/ruby/core/process/exec_spec.rb b/spec/ruby/core/process/exec_spec.rb
index b4eddf526e..a48d461b02 100644
--- a/spec/ruby/core/process/exec_spec.rb
+++ b/spec/ruby/core/process/exec_spec.rb
@@ -1,57 +1,49 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Process.exec" do
it "raises Errno::ENOENT for an empty string" do
- lambda { Process.exec "" }.should raise_error(Errno::ENOENT)
+ -> { Process.exec "" }.should.raise(Errno::ENOENT)
end
it "raises Errno::ENOENT for a command which does not exist" do
- lambda { Process.exec "bogus-noent-script.sh" }.should raise_error(Errno::ENOENT)
+ -> { Process.exec "bogus-noent-script.sh" }.should.raise(Errno::ENOENT)
end
it "raises an ArgumentError if the command includes a null byte" do
- lambda { Process.exec "\000" }.should raise_error(ArgumentError)
+ -> { Process.exec "\000" }.should.raise(ArgumentError)
end
unless File.executable?(__FILE__) # Some FS (e.g. vboxfs) locate all files executable
platform_is_not :windows do
it "raises Errno::EACCES when the file does not have execute permissions" do
- lambda { Process.exec __FILE__ }.should raise_error(Errno::EACCES)
+ -> { Process.exec __FILE__ }.should.raise(Errno::EACCES)
end
end
platform_is :windows do
it "raises Errno::EACCES or Errno::ENOEXEC when the file is not an executable file" do
- lambda { Process.exec __FILE__ }.should raise_error(SystemCallError) { |e|
- [Errno::EACCES, Errno::ENOEXEC].should include(e.class)
+ -> { Process.exec __FILE__ }.should.raise(SystemCallError) { |e|
+ [Errno::EACCES, Errno::ENOEXEC].should.include?(e.class)
}
end
end
end
- platform_is_not :openbsd do
- it "raises Errno::EACCES when passed a directory" do
- lambda { Process.exec File.dirname(__FILE__) }.should raise_error(Errno::EACCES)
- end
- end
-
- platform_is :openbsd do
- it "raises Errno::EISDIR when passed a directory" do
- lambda { Process.exec File.dirname(__FILE__) }.should raise_error(Errno::EISDIR)
- end
+ it "raises Errno::EACCES when passed a directory" do
+ -> { Process.exec __dir__ }.should.raise(Errno::EACCES)
end
it "runs the specified command, replacing current process" do
- ruby_exe('Process.exec "echo hello"; puts "fail"', escape: true).should == "hello\n"
+ ruby_exe('Process.exec "echo hello"; puts "fail"').should == "hello\n"
end
it "sets the current directory when given the :chdir option" do
tmpdir = tmp("")[0..-2]
platform_is_not :windows do
- ruby_exe("Process.exec(\"pwd\", chdir: #{tmpdir.inspect})", escape: true).should == "#{tmpdir}\n"
+ ruby_exe("Process.exec(\"pwd\", chdir: #{tmpdir.inspect})").should == "#{tmpdir}\n"
end
platform_is :windows do
- ruby_exe("Process.exec(\"cd\", chdir: #{tmpdir.inspect})", escape: true).tr('\\', '/').should == "#{tmpdir}\n"
+ ruby_exe("Process.exec(\"cd\", chdir: #{tmpdir.inspect})").tr('\\', '/').should == "#{tmpdir}\n"
end
end
@@ -81,13 +73,13 @@ describe "Process.exec" do
platform_is_not :windows do
it "subjects the specified command to shell expansion" do
result = Dir.chdir(@dir) do
- ruby_exe('Process.exec "echo *"', escape: true)
+ ruby_exe('Process.exec "echo *"')
end
result.chomp.should == @name
end
it "creates an argument array with shell parsing semantics for whitespace" do
- ruby_exe('Process.exec "echo a b c d"', escape: true).should == "a b c d\n"
+ ruby_exe('Process.exec "echo a b c d"').should == "a b c d\n"
end
end
@@ -95,13 +87,13 @@ describe "Process.exec" do
# There is no shell expansion on Windows
it "does not subject the specified command to shell expansion on Windows" do
result = Dir.chdir(@dir) do
- ruby_exe('Process.exec "echo *"', escape: true)
+ ruby_exe('Process.exec "echo *"')
end
result.should == "*\n"
end
it "does not create an argument array with shell parsing semantics for whitespace on Windows" do
- ruby_exe('Process.exec "echo a b c d"', escape: true).should == "a b c d\n"
+ ruby_exe('Process.exec "echo a b c d"').should == "a b c d\n"
end
end
@@ -113,7 +105,7 @@ describe "Process.exec" do
platform_is :windows do
cmd = '"cmd.exe", "/C", "echo", "*"'
end
- ruby_exe("Process.exec #{cmd}", escape: true).should == "*\n"
+ ruby_exe("Process.exec #{cmd}").should == "*\n"
end
end
@@ -132,29 +124,29 @@ describe "Process.exec" do
end
it "sets environment variables in the child environment" do
- ruby_exe('Process.exec({"FOO" => "BAR"}, "echo ' + var + '")', escape: true).should == "BAR\n"
+ ruby_exe('Process.exec({"FOO" => "BAR"}, "echo ' + var + '")').should == "BAR\n"
end
it "unsets environment variables whose value is nil" do
platform_is_not :windows do
- ruby_exe('Process.exec({"FOO" => nil}, "echo ' + var + '")', escape: true).should == "\n"
+ ruby_exe('Process.exec({"FOO" => nil}, "echo ' + var + '")').should == "\n"
end
platform_is :windows do
# On Windows, echo-ing a non-existent env var is treated as echo-ing any other string of text
- ruby_exe('Process.exec({"FOO" => nil}, "echo ' + var + '")', escape: true).should == var + "\n"
+ ruby_exe('Process.exec({"FOO" => nil}, "echo ' + var + '")').should == var + "\n"
end
end
it "coerces environment argument using to_hash" do
- ruby_exe('o = Object.new; def o.to_hash; {"FOO" => "BAR"}; end; Process.exec(o, "echo ' + var + '")', escape: true).should == "BAR\n"
+ ruby_exe('o = Object.new; def o.to_hash; {"FOO" => "BAR"}; end; Process.exec(o, "echo ' + var + '")').should == "BAR\n"
end
it "unsets other environment variables when given a true :unsetenv_others option" do
platform_is_not :windows do
- ruby_exe('Process.exec("echo ' + var + '", unsetenv_others: true)', escape: true).should == "\n"
+ ruby_exe('Process.exec("echo ' + var + '", unsetenv_others: true)').should == "\n"
end
platform_is :windows do
- ruby_exe('Process.exec("' + ENV['COMSPEC'].gsub('\\', '\\\\\\') + ' /C echo ' + var + '", unsetenv_others: true)', escape: true).should == var + "\n"
+ ruby_exe('Process.exec("' + ENV['COMSPEC'].gsub('\\', '\\\\\\') + ' /C echo ' + var + '", unsetenv_others: true)').should == var + "\n"
end
end
end
@@ -162,26 +154,26 @@ describe "Process.exec" do
describe "with a command array" do
it "uses the first element as the command name and the second as the argv[0] value" do
platform_is_not :windows do
- ruby_exe('Process.exec(["/bin/sh", "argv_zero"], "-c", "echo $0")', escape: true).should == "argv_zero\n"
+ ruby_exe('Process.exec(["/bin/sh", "argv_zero"], "-c", "echo $0")').should == "argv_zero\n"
end
platform_is :windows do
- ruby_exe('Process.exec(["cmd.exe", "/C"], "/C", "echo", "argv_zero")', escape: true).should == "argv_zero\n"
+ ruby_exe('Process.exec(["cmd.exe", "/C"], "/C", "echo", "argv_zero")').should == "argv_zero\n"
end
end
it "coerces the argument using to_ary" do
platform_is_not :windows do
- ruby_exe('o = Object.new; def o.to_ary; ["/bin/sh", "argv_zero"]; end; Process.exec(o, "-c", "echo $0")', escape: true).should == "argv_zero\n"
+ ruby_exe('o = Object.new; def o.to_ary; ["/bin/sh", "argv_zero"]; end; Process.exec(o, "-c", "echo $0")').should == "argv_zero\n"
end
platform_is :windows do
- ruby_exe('o = Object.new; def o.to_ary; ["cmd.exe", "/C"]; end; Process.exec(o, "/C", "echo", "argv_zero")', escape: true).should == "argv_zero\n"
+ ruby_exe('o = Object.new; def o.to_ary; ["cmd.exe", "/C"]; end; Process.exec(o, "/C", "echo", "argv_zero")').should == "argv_zero\n"
end
end
it "raises an ArgumentError if the Array does not have exactly two elements" do
- lambda { Process.exec([]) }.should raise_error(ArgumentError)
- lambda { Process.exec([:a]) }.should raise_error(ArgumentError)
- lambda { Process.exec([:a, :b, :c]) }.should raise_error(ArgumentError)
+ -> { Process.exec([]) }.should.raise(ArgumentError)
+ -> { Process.exec([:a]) }.should.raise(ArgumentError)
+ -> { Process.exec([:a, :b, :c]) }.should.raise(ArgumentError)
end
end
@@ -200,18 +192,49 @@ describe "Process.exec" do
it "maps the key to a file descriptor in the child that inherits the file descriptor from the parent specified by the value" do
map_fd_fixture = fixture __FILE__, "map_fd.rb"
cmd = <<-EOC
- f = File.open("#{@name}", "w+")
- child_fd = f.fileno + 1
- File.open("#{@child_fd_file}", "w") { |io| io.print child_fd }
- Process.exec "#{ruby_cmd(map_fd_fixture)} \#{child_fd}", { child_fd => f }
+ f = File.open(#{@name.inspect}, "w+")
+ File.open(#{__FILE__.inspect}, "r") do |io|
+ child_fd = io.fileno
+ File.open(#{@child_fd_file.inspect}, "w") { |io| io.print child_fd }
+ Process.exec "#{ruby_cmd(map_fd_fixture)} \#{child_fd}", { child_fd => f }
+ end
EOC
- ruby_exe(cmd, escape: true)
+ ruby_exe(cmd)
child_fd = IO.read(@child_fd_file).to_i
child_fd.to_i.should > STDERR.fileno
File.read(@name).should == "writing to fd: #{child_fd}"
end
+
+ it "lets the process after exec have specified file descriptor despite close_on_exec" do
+ map_fd_fixture = fixture __FILE__, "map_fd.rb"
+ cmd = <<-EOC
+ f = File.open(#{@name.inspect}, 'w+')
+ puts(f.fileno, f.close_on_exec?)
+ STDOUT.flush
+ Process.exec("#{ruby_cmd(map_fd_fixture)} \#{f.fileno}", f.fileno => f.fileno)
+ EOC
+
+ output = ruby_exe(cmd)
+ child_fd, close_on_exec = output.split
+
+ child_fd.to_i.should > STDERR.fileno
+ close_on_exec.should == 'true'
+ File.read(@name).should == "writing to fd: #{child_fd}"
+ end
+
+ it "sets close_on_exec to false on specified fd even when it fails" do
+ cmd = <<-EOC
+ f = File.open(#{__FILE__.inspect}, 'r')
+ puts(f.close_on_exec?)
+ Process.exec('/', f.fileno => f.fileno) rescue nil
+ puts(f.close_on_exec?)
+ EOC
+
+ output = ruby_exe(cmd)
+ output.split.should == ['true', 'false']
+ end
end
end
end
diff --git a/spec/ruby/core/process/exit_spec.rb b/spec/ruby/core/process/exit_spec.rb
index 7cbd0c363e..4f7dc94407 100644
--- a/spec/ruby/core/process/exit_spec.rb
+++ b/spec/ruby/core/process/exit_spec.rb
@@ -1,10 +1,10 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/process/exit', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../../shared/process/exit'
describe "Process.exit" do
it_behaves_like :process_exit, :exit, Process
end
describe "Process.exit!" do
- it_behaves_like :process_exit!, :exit!, Process
+ it_behaves_like :process_exit!, :exit!, "Process"
end
diff --git a/spec/ruby/core/process/fixtures/argv0.rb b/spec/ruby/core/process/fixtures/argv0.rb
new file mode 100644
index 0000000000..847a3e903e
--- /dev/null
+++ b/spec/ruby/core/process/fixtures/argv0.rb
@@ -0,0 +1,6 @@
+puts Process.argv0
+puts __FILE__
+
+if Process.argv0 == __FILE__
+ print "OK"
+end
diff --git a/spec/ruby/core/process/fixtures/clocks.rb b/spec/ruby/core/process/fixtures/clocks.rb
new file mode 100644
index 0000000000..5757e280be
--- /dev/null
+++ b/spec/ruby/core/process/fixtures/clocks.rb
@@ -0,0 +1,18 @@
+module ProcessSpecs
+ def self.clock_constants
+ clocks = []
+
+ platform_is_not :windows do
+ clocks += Process.constants.select { |c| c.to_s.start_with?('CLOCK_') }
+
+ # These require CAP_WAKE_ALARM and are not documented in
+ # Process#clock_gettime. They return EINVAL if the permission
+ # is not granted.
+ clocks -= [:CLOCK_BOOTTIME_ALARM, :CLOCK_REALTIME_ALARM]
+ end
+
+ clocks.sort.map { |c|
+ [c, Process.const_get(c)]
+ }
+ end
+end
diff --git a/spec/ruby/core/process/fixtures/common.rb b/spec/ruby/core/process/fixtures/common.rb
index bdbf1e654b..f49513d262 100644
--- a/spec/ruby/core/process/fixtures/common.rb
+++ b/spec/ruby/core/process/fixtures/common.rb
@@ -3,11 +3,15 @@ module ProcessSpecs
if defined?(MSpecScript::SYSTEM_RUBY)
context.send(:before, :all) do
@ruby = ::RUBY_EXE
- Object.const_set(:RUBY_EXE, MSpecScript::SYSTEM_RUBY)
+ suppress_warning {
+ Object.const_set(:RUBY_EXE, MSpecScript::SYSTEM_RUBY)
+ }
end
context.send(:after, :all) do
- Object.const_set(:RUBY_EXE, @ruby)
+ suppress_warning {
+ Object.const_set(:RUBY_EXE, @ruby)
+ }
end
end
end
diff --git a/spec/ruby/core/process/fixtures/in.txt b/spec/ruby/core/process/fixtures/in.txt
new file mode 100644
index 0000000000..cf52303bdc
--- /dev/null
+++ b/spec/ruby/core/process/fixtures/in.txt
@@ -0,0 +1 @@
+stdin
diff --git a/spec/ruby/core/process/fixtures/kill.rb b/spec/ruby/core/process/fixtures/kill.rb
index 0b88f8ee1f..b922a043f1 100644
--- a/spec/ruby/core/process/fixtures/kill.rb
+++ b/spec/ruby/core/process/fixtures/kill.rb
@@ -1,5 +1,3 @@
-require 'thread'
-
pid_file = ARGV.shift
scenario = ARGV.shift
diff --git a/spec/ruby/core/process/fixtures/map_fd.rb b/spec/ruby/core/process/fixtures/map_fd.rb
index fc542625b0..3ed887486b 100644
--- a/spec/ruby/core/process/fixtures/map_fd.rb
+++ b/spec/ruby/core/process/fixtures/map_fd.rb
@@ -1,6 +1,7 @@
fd = ARGV.shift.to_i
-f = File.for_fd fd
+f = File.for_fd(fd)
+f.autoclose = false
begin
f.write "writing to fd: #{fd}"
ensure
diff --git a/spec/ruby/core/process/fork_spec.rb b/spec/ruby/core/process/fork_spec.rb
index 2de2231dc5..a4f765247d 100644
--- a/spec/ruby/core/process/fork_spec.rb
+++ b/spec/ruby/core/process/fork_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/process/fork', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../../shared/process/fork'
describe "Process.fork" do
it_behaves_like :process_fork, :fork, Process
diff --git a/spec/ruby/core/process/getpgid_spec.rb b/spec/ruby/core/process/getpgid_spec.rb
index b92fb15152..c1dd007b16 100644
--- a/spec/ruby/core/process/getpgid_spec.rb
+++ b/spec/ruby/core/process/getpgid_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Process.getpgid" do
platform_is_not :windows do
diff --git a/spec/ruby/core/process/getpgrp_spec.rb b/spec/ruby/core/process/getpgrp_spec.rb
index 9643a16b2a..e1d1c5f92d 100644
--- a/spec/ruby/core/process/getpgrp_spec.rb
+++ b/spec/ruby/core/process/getpgrp_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
# see setpgrp_spec.rb
diff --git a/spec/ruby/core/process/getpriority_spec.rb b/spec/ruby/core/process/getpriority_spec.rb
index 68307b9bd5..53fe7bfe20 100644
--- a/spec/ruby/core/process/getpriority_spec.rb
+++ b/spec/ruby/core/process/getpriority_spec.rb
@@ -1,23 +1,23 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Process.getpriority" do
platform_is_not :windows do
it "coerces arguments to Integers" do
ret = Process.getpriority mock_int(Process::PRIO_PROCESS), mock_int(0)
- ret.should be_kind_of(Fixnum)
+ ret.should.is_a?(Integer)
end
it "gets the scheduling priority for a specified process" do
- Process.getpriority(Process::PRIO_PROCESS, 0).should be_kind_of(Fixnum)
+ Process.getpriority(Process::PRIO_PROCESS, 0).should.is_a?(Integer)
end
it "gets the scheduling priority for a specified process group" do
- Process.getpriority(Process::PRIO_PGRP, 0).should be_kind_of(Fixnum)
+ Process.getpriority(Process::PRIO_PGRP, 0).should.is_a?(Integer)
end
it "gets the scheduling priority for a specified user" do
- Process.getpriority(Process::PRIO_USER, 0).should be_kind_of(Fixnum)
+ Process.getpriority(Process::PRIO_USER, 0).should.is_a?(Integer)
end
end
end
diff --git a/spec/ruby/core/process/getrlimit_spec.rb b/spec/ruby/core/process/getrlimit_spec.rb
index 7924d43081..d36d8c3335 100644
--- a/spec/ruby/core/process/getrlimit_spec.rb
+++ b/spec/ruby/core/process/getrlimit_spec.rb
@@ -1,8 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
platform_is :aix do
# In AIX, if getrlimit(2) is called multiple times with RLIMIT_DATA,
- # the first call and the subequent calls return slightly different
+ # the first call and the subsequent calls return slightly different
# values of rlim_cur, even if the process does nothing between
# the calls. This behavior causes some of the tests in this spec
# to fail, so call Process.getrlimit(:DATA) once and discard the result.
@@ -11,13 +11,13 @@ platform_is :aix do
Process.getrlimit(:DATA)
end
-platform_is_not :windows do
- describe "Process.getrlimit" do
+describe "Process.getrlimit" do
+ platform_is_not :windows do
it "returns a two-element Array of Integers" do
result = Process.getrlimit Process::RLIMIT_CORE
result.size.should == 2
- result.first.should be_kind_of(Integer)
- result.last.should be_kind_of(Integer)
+ result.first.should.is_a?(Integer)
+ result.last.should.is_a?(Integer)
end
context "when passed an Object" do
@@ -36,33 +36,33 @@ platform_is_not :windows do
obj = mock("process getrlimit integer")
obj.should_receive(:to_int).and_return(nil)
- lambda { Process.getrlimit(obj) }.should raise_error(TypeError)
+ -> { Process.getrlimit(obj) }.should.raise(TypeError)
end
end
context "when passed a Symbol" do
- Process.constants.grep(/\ARLIMIT_/) do |fullname|
- short = $'
- it "coerces :#{short} into #{fullname}" do
+ it "coerces the short name into the full RLIMIT_ prefixed name" do
+ Process.constants.grep(/\ARLIMIT_/) do |fullname|
+ short = fullname[/\ARLIMIT_(.+)/, 1]
Process.getrlimit(short.to_sym).should == Process.getrlimit(Process.const_get(fullname))
end
end
it "raises ArgumentError when passed an unknown resource" do
- lambda { Process.getrlimit(:FOO) }.should raise_error(ArgumentError)
+ -> { Process.getrlimit(:FOO) }.should.raise(ArgumentError)
end
end
context "when passed a String" do
- Process.constants.grep(/\ARLIMIT_/) do |fullname|
- short = $'
- it "coerces '#{short}' into #{fullname}" do
+ it "coerces the short name into the full RLIMIT_ prefixed name" do
+ Process.constants.grep(/\ARLIMIT_/) do |fullname|
+ short = fullname[/\ARLIMIT_(.+)/, 1]
Process.getrlimit(short).should == Process.getrlimit(Process.const_get(fullname))
end
end
it "raises ArgumentError when passed an unknown resource" do
- lambda { Process.getrlimit("FOO") }.should raise_error(ArgumentError)
+ -> { Process.getrlimit("FOO") }.should.raise(ArgumentError)
end
end
@@ -88,4 +88,13 @@ platform_is_not :windows do
end
end
end
+
+ platform_is :windows do
+ it "is not implemented" do
+ Process.respond_to?(:getrlimit).should == false
+ -> do
+ Process.getrlimit(nil)
+ end.should.raise NotImplementedError
+ end
+ end
end
diff --git a/spec/ruby/core/process/gid/change_privilege_spec.rb b/spec/ruby/core/process/gid/change_privilege_spec.rb
index 9670e4970f..4ada277514 100644
--- a/spec/ruby/core/process/gid/change_privilege_spec.rb
+++ b/spec/ruby/core/process/gid/change_privilege_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "Process::GID.change_privilege" do
it "needs to be reviewed for spec completeness"
diff --git a/spec/ruby/core/process/gid/eid_spec.rb b/spec/ruby/core/process/gid/eid_spec.rb
index 6d6a672fea..3f2186bb6a 100644
--- a/spec/ruby/core/process/gid/eid_spec.rb
+++ b/spec/ruby/core/process/gid/eid_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "Process::GID.eid" do
it "needs to be reviewed for spec completeness"
diff --git a/spec/ruby/core/process/gid/grant_privilege_spec.rb b/spec/ruby/core/process/gid/grant_privilege_spec.rb
index 27373c7113..10da7f8a26 100644
--- a/spec/ruby/core/process/gid/grant_privilege_spec.rb
+++ b/spec/ruby/core/process/gid/grant_privilege_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "Process::GID.grant_privilege" do
it "needs to be reviewed for spec completeness"
diff --git a/spec/ruby/core/process/gid/re_exchange_spec.rb b/spec/ruby/core/process/gid/re_exchange_spec.rb
index 4f3a242680..9642c81c5b 100644
--- a/spec/ruby/core/process/gid/re_exchange_spec.rb
+++ b/spec/ruby/core/process/gid/re_exchange_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "Process::GID.re_exchange" do
it "needs to be reviewed for spec completeness"
diff --git a/spec/ruby/core/process/gid/re_exchangeable_spec.rb b/spec/ruby/core/process/gid/re_exchangeable_spec.rb
index 1fc5298f26..1c38f903d5 100644
--- a/spec/ruby/core/process/gid/re_exchangeable_spec.rb
+++ b/spec/ruby/core/process/gid/re_exchangeable_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "Process::GID.re_exchangeable?" do
it "needs to be reviewed for spec completeness"
diff --git a/spec/ruby/core/process/gid/rid_spec.rb b/spec/ruby/core/process/gid/rid_spec.rb
index fb5c51e412..ad66c94e72 100644
--- a/spec/ruby/core/process/gid/rid_spec.rb
+++ b/spec/ruby/core/process/gid/rid_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "Process::GID.rid" do
it "needs to be reviewed for spec completeness"
diff --git a/spec/ruby/core/process/gid/sid_available_spec.rb b/spec/ruby/core/process/gid/sid_available_spec.rb
index 59b2c3ae1e..8d86b3e9d2 100644
--- a/spec/ruby/core/process/gid/sid_available_spec.rb
+++ b/spec/ruby/core/process/gid/sid_available_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "Process::GID.sid_available?" do
it "needs to be reviewed for spec completeness"
diff --git a/spec/ruby/core/process/gid/switch_spec.rb b/spec/ruby/core/process/gid/switch_spec.rb
index 7ae6dae9a7..b162f1e782 100644
--- a/spec/ruby/core/process/gid/switch_spec.rb
+++ b/spec/ruby/core/process/gid/switch_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "Process::GID.switch" do
it "needs to be reviewed for spec completeness"
diff --git a/spec/ruby/core/process/gid_spec.rb b/spec/ruby/core/process/gid_spec.rb
index c39c60a95f..ca935ed520 100644
--- a/spec/ruby/core/process/gid_spec.rb
+++ b/spec/ruby/core/process/gid_spec.rb
@@ -1,10 +1,10 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Process.gid" do
platform_is_not :windows do
it "returns the correct gid for the user executing this process" do
- current_gid_according_to_unix = `id -gr`.to_i
- Process.gid.should == current_gid_according_to_unix
+ current_gid_according_to_unix = `id -gr`.to_i
+ Process.gid.should == current_gid_according_to_unix
end
end
diff --git a/spec/ruby/core/process/groups_spec.rb b/spec/ruby/core/process/groups_spec.rb
index 0669258bf3..fa916671a4 100644
--- a/spec/ruby/core/process/groups_spec.rb
+++ b/spec/ruby/core/process/groups_spec.rb
@@ -1,26 +1,37 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Process.groups" do
platform_is_not :windows do
it "gets an Array of the gids of groups in the supplemental group access list" do
groups = `id -G`.scan(/\d+/).map { |i| i.to_i }
+ # Include the standard `id` command output. On macOS, GNU
+ # coreutils `id` is limited to NGROUPS_MAX groups, because of
+ # the backward compatibility of getgroups(2).
+ (groups |= `/usr/bin/id -G`.scan(/\d+/).map { |i| i.to_i }) rescue nil
gid = Process.gid
- expected = (groups.sort - [gid]).sort
- actual = (Process.groups - [gid]).sort
+ expected = (groups.sort - [gid]).uniq.sort
+ actual = (Process.groups - [gid]).uniq.sort
actual.should == expected
end
+ end
+end
- # NOTE: This is kind of sketchy.
- it "sets the list of gids of groups in the supplemental group access list" do
- groups = Process.groups
- if Process.uid == 0
+describe "Process.groups=" do
+ platform_is_not :windows, :android do
+ as_superuser do
+ it "sets the list of gids of groups in the supplemental group access list" do
+ groups = Process.groups
Process.groups = []
Process.groups.should == []
Process.groups = groups
Process.groups.sort.should == groups.sort
- else
- platform_is :aix do
+ end
+ end
+
+ as_user do
+ platform_is :aix do
+ it "sets the list of gids of groups in the supplemental group access list" do
# setgroups() is not part of the POSIX standard,
# so its behavior varies from OS to OS. AIX allows a non-root
# process to set the supplementary group IDs, as long as
@@ -30,6 +41,7 @@ describe "Process.groups" do
# it should no longer be able to set any supplementary
# group IDs, even if it originally belonged to them.
# It should only be able to set its primary group ID.
+ groups = Process.groups
Process.groups = groups
Process.groups.sort.should == groups.sort
Process.groups = []
@@ -38,17 +50,18 @@ describe "Process.groups" do
Process.groups.should == [ Process.gid ]
supplementary = groups - [ Process.gid ]
if supplementary.length > 0
- lambda { Process.groups = supplementary }.should raise_error(Errno::EPERM)
+ -> { Process.groups = supplementary }.should.raise(Errno::EPERM)
end
end
- platform_is_not :aix do
- lambda { Process.groups = [] }.should raise_error(Errno::EPERM)
+ end
+
+ platform_is_not :aix do
+ it "raises Errno::EPERM" do
+ -> {
+ Process.groups = [0]
+ }.should.raise(Errno::EPERM)
end
end
end
end
end
-
-describe "Process.groups=" do
- it "needs to be reviewed for spec completeness"
-end
diff --git a/spec/ruby/core/process/initgroups_spec.rb b/spec/ruby/core/process/initgroups_spec.rb
index 084c52652c..d9f31936cb 100644
--- a/spec/ruby/core/process/initgroups_spec.rb
+++ b/spec/ruby/core/process/initgroups_spec.rb
@@ -1,19 +1,21 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Process.initgroups" do
- platform_is_not :windows do
- it "initializes the supplemental group access list" do
- name = `id -un`.strip
- groups = Process.groups
- gid = groups.max.to_i + 1
- augmented_groups = `id -G`.scan(/\d+/).map {|i| i.to_i} << gid
- if Process.uid == 0
- Process.groups = []
- Process.initgroups(name, gid).sort.should == augmented_groups.sort
- Process.groups.sort.should == augmented_groups.sort
- Process.groups = groups
- else
- lambda { Process.initgroups(name, gid) }.should raise_error(Errno::EPERM)
+ platform_is_not :windows, :android do
+ as_user do
+ it "initializes the supplemental group access list" do
+ name = `id -un`.strip
+ groups = Process.groups
+ gid = groups.max.to_i + 1
+ augmented_groups = `id -G`.scan(/\d+/).map {|i| i.to_i} << gid
+ if Process.uid == 0
+ Process.groups = []
+ Process.initgroups(name, gid).sort.should == augmented_groups.sort
+ Process.groups.sort.should == augmented_groups.sort
+ Process.groups = groups
+ else
+ -> { Process.initgroups(name, gid) }.should.raise(Errno::EPERM)
+ end
end
end
end
diff --git a/spec/ruby/core/process/kill_spec.rb b/spec/ruby/core/process/kill_spec.rb
index 4316daf374..885c2bf2b7 100644
--- a/spec/ruby/core/process/kill_spec.rb
+++ b/spec/ruby/core/process/kill_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/common', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/common'
describe "Process.kill" do
ProcessSpecs.use_system_ruby(self)
@@ -9,27 +9,31 @@ describe "Process.kill" do
end
it "raises an ArgumentError for unknown signals" do
- lambda { Process.kill("FOO", @pid) }.should raise_error(ArgumentError)
+ -> { Process.kill("FOO", @pid) }.should.raise(ArgumentError)
end
it "raises an ArgumentError if passed a lowercase signal name" do
- lambda { Process.kill("term", @pid) }.should raise_error(ArgumentError)
+ -> { Process.kill("term", @pid) }.should.raise(ArgumentError)
end
- it "raises an ArgumentError if signal is not a Fixnum or String" do
+ it "raises an ArgumentError if signal is not an Integer or String" do
signal = mock("process kill signal")
signal.should_not_receive(:to_int)
- lambda { Process.kill(signal, @pid) }.should raise_error(ArgumentError)
+ -> { Process.kill(signal, @pid) }.should.raise(ArgumentError)
end
it "raises Errno::ESRCH if the process does not exist" do
pid = Process.spawn(*ruby_exe, "-e", "sleep 10")
Process.kill("SIGKILL", pid)
Process.wait(pid)
- lambda {
+ -> {
Process.kill("SIGKILL", pid)
- }.should raise_error(Errno::ESRCH)
+ }.should.raise(Errno::ESRCH)
+ end
+
+ it "checks for existence and permissions to signal a process, but does not actually signal it, when using signal 0" do
+ Process.kill(0, @pid).should == 1
end
end
@@ -65,7 +69,7 @@ platform_is_not :windows do
@sp.result.should == "signaled"
end
- it "acceps an Integer as a signal value" do
+ it "accepts an Integer as a signal value" do
Process.kill(15, @sp.pid)
@sp.result.should == "signaled"
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..1bd8adf798
--- /dev/null
+++ b/spec/ruby/core/process/last_status_spec.rb
@@ -0,0 +1,18 @@
+require_relative '../../spec_helper'
+
+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(ArgumentError)
+ end
+end
diff --git a/spec/ruby/core/process/maxgroups_spec.rb b/spec/ruby/core/process/maxgroups_spec.rb
index 8a40a1aba6..895b384bd0 100644
--- a/spec/ruby/core/process/maxgroups_spec.rb
+++ b/spec/ruby/core/process/maxgroups_spec.rb
@@ -1,9 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
platform_is_not :windows do
describe "Process.maxgroups" do
it "returns the maximum number of gids allowed in the supplemental group access list" do
- Process.maxgroups.should be_kind_of(Fixnum)
+ Process.maxgroups.should.is_a?(Integer)
end
it "sets the maximum number of gids allowed in the supplemental group access list" do
diff --git a/spec/ruby/core/process/pid_spec.rb b/spec/ruby/core/process/pid_spec.rb
index 114b20f11f..42b0b918b9 100644
--- a/spec/ruby/core/process/pid_spec.rb
+++ b/spec/ruby/core/process/pid_spec.rb
@@ -1,9 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Process.pid" do
it "returns the process id of this process" do
pid = Process.pid
- pid.should be_kind_of(Fixnum)
+ pid.should.is_a?(Integer)
Process.pid.should == pid
end
end
diff --git a/spec/ruby/core/process/ppid_spec.rb b/spec/ruby/core/process/ppid_spec.rb
index ec6ce865ee..47c32a8591 100644
--- a/spec/ruby/core/process/ppid_spec.rb
+++ b/spec/ruby/core/process/ppid_spec.rb
@@ -1,23 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Process.ppid" do
- with_feature :fork do
+ platform_is_not :windows do
it "returns the process id of the parent of this process" do
-
- read, write = IO.pipe
-
- child_pid = Process.fork {
- read.close
- write << "#{Process.ppid}\n"
- write.close
- exit!
- }
-
- write.close
- pid = read.gets
- read.close
- Process.wait(child_pid)
- pid.to_i.should == Process.pid
+ ruby_exe("puts Process.ppid").should == "#{Process.pid}\n"
end
end
end
diff --git a/spec/ruby/core/process/set_proctitle_spec.rb b/spec/ruby/core/process/set_proctitle_spec.rb
index e004f8efc9..28a0fa6cee 100644
--- a/spec/ruby/core/process/set_proctitle_spec.rb
+++ b/spec/ruby/core/process/set_proctitle_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
# Note that there's no way to get the current process title defined as a spec
# somewhere. Process.setproctitle explicitly does not change `$0` so the only
@@ -17,7 +17,7 @@ describe 'Process.setproctitle' do
title = 'rubyspec-proctitle-test'
Process.setproctitle(title).should == title
- `ps -ocommand= -p#{$$}`.should include(title)
+ `ps -ocommand= -p#{$$}`.should.include?(title)
end
end
end
diff --git a/spec/ruby/core/process/setpgid_spec.rb b/spec/ruby/core/process/setpgid_spec.rb
index bd1596d0eb..1442d7f99c 100644
--- a/spec/ruby/core/process/setpgid_spec.rb
+++ b/spec/ruby/core/process/setpgid_spec.rb
@@ -1,7 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Process.setpgid" do
- with_feature :fork do
+ guard -> { Process.respond_to?(:fork) } do
+ # Must use fork as setpgid(2) gives EACCESS after execve()
it "sets the process group id of the specified process" do
rd, wr = IO.pipe
diff --git a/spec/ruby/core/process/setpgrp_spec.rb b/spec/ruby/core/process/setpgrp_spec.rb
index 8e72795f96..7c4344f115 100644
--- a/spec/ruby/core/process/setpgrp_spec.rb
+++ b/spec/ruby/core/process/setpgrp_spec.rb
@@ -1,8 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
# TODO: put these in the right files.
describe "Process.setpgrp and Process.getpgrp" do
- platform_is_not :windows do
+ guard -> { Process.respond_to?(:fork) } do
it "sets and gets the process group ID of the calling process" do
# there are two synchronization points here:
# One for the child to let the parent know that it has finished
diff --git a/spec/ruby/core/process/setpriority_spec.rb b/spec/ruby/core/process/setpriority_spec.rb
index 7b437a547a..4d60973429 100644
--- a/spec/ruby/core/process/setpriority_spec.rb
+++ b/spec/ruby/core/process/setpriority_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Process.setpriority" do
platform_is_not :windows do
@@ -29,13 +29,32 @@ describe "Process.setpriority" do
end
as_superuser do
- it "sets the scheduling priority for a specified user" do
- p = Process.getpriority(Process::PRIO_USER, 0)
- Process.setpriority(Process::PRIO_USER, 0, p + 1).should == 0
- Process.getpriority(Process::PRIO_USER, 0).should == (p + 1)
- Process.setpriority(Process::PRIO_USER, 0, p).should == 0
+ guard -> {
+ prio = Process.getpriority(Process::PRIO_USER, 0)
+ # The nice value is a value in the range -20 to 19.
+ # This test tries to change the nice value to +-1, so it cannot run if prio == -20 || prio == 19.
+ if -20 < prio && prio < 19
+ begin
+ # Check if we can lower the nice value or not.
+ #
+ # We are not always able to do it even as a root.
+ # Docker container is not always able to do it depending upon the configuration,
+ # which cannot know from the container itself.
+ Process.setpriority(Process::PRIO_USER, 0, prio - 1)
+ Process.setpriority(Process::PRIO_USER, 0, prio)
+ true
+ rescue Errno::EACCES
+ false
+ end
+ end
+ } do
+ it "sets the scheduling priority for a specified user" do
+ prio = Process.getpriority(Process::PRIO_USER, 0)
+ Process.setpriority(Process::PRIO_USER, 0, prio + 1).should == 0
+ Process.getpriority(Process::PRIO_USER, 0).should == (prio + 1)
+ Process.setpriority(Process::PRIO_USER, 0, prio).should == 0
+ end
end
end
end
-
end
diff --git a/spec/ruby/core/process/setrlimit_spec.rb b/spec/ruby/core/process/setrlimit_spec.rb
index 5d137ca6c1..f02ab46fca 100644
--- a/spec/ruby/core/process/setrlimit_spec.rb
+++ b/spec/ruby/core/process/setrlimit_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
-platform_is_not :windows do
- describe "Process.setrlimit" do
+describe "Process.setrlimit" do
+ platform_is_not :windows do
context "when passed an Object" do
before do
@resource = Process::RLIMIT_CORE
@@ -9,200 +9,196 @@ platform_is_not :windows do
end
it "calls #to_int to convert resource to an Integer" do
- Process.setrlimit(mock_int(@resource), @limit, @max).should be_nil
+ Process.setrlimit(mock_int(@resource), @limit, @max).should == nil
end
it "raises a TypeError if #to_int for resource does not return an Integer" do
obj = mock("process getrlimit integer")
obj.should_receive(:to_int).and_return(nil)
- lambda { Process.setrlimit(obj, @limit, @max) }.should raise_error(TypeError)
+ -> { Process.setrlimit(obj, @limit, @max) }.should.raise(TypeError)
end
it "calls #to_int to convert the soft limit to an Integer" do
- Process.setrlimit(@resource, mock_int(@limit), @max).should be_nil
+ Process.setrlimit(@resource, mock_int(@limit), @max).should == nil
end
it "raises a TypeError if #to_int for resource does not return an Integer" do
obj = mock("process getrlimit integer")
obj.should_receive(:to_int).and_return(nil)
- lambda { Process.setrlimit(@resource, obj, @max) }.should raise_error(TypeError)
+ -> { Process.setrlimit(@resource, obj, @max) }.should.raise(TypeError)
end
it "calls #to_int to convert the hard limit to an Integer" do
- Process.setrlimit(@resource, @limit, mock_int(@max)).should be_nil
+ Process.setrlimit(@resource, @limit, mock_int(@max)).should == nil
end
it "raises a TypeError if #to_int for resource does not return an Integer" do
obj = mock("process getrlimit integer")
obj.should_receive(:to_int).and_return(nil)
- lambda { Process.setrlimit(@resource, @limit, obj) }.should raise_error(TypeError)
+ -> { Process.setrlimit(@resource, @limit, obj) }.should.raise(TypeError)
end
end
context "when passed a Symbol" do
platform_is_not :openbsd do
it "coerces :AS into RLIMIT_AS" do
- Process.setrlimit(:AS, *Process.getrlimit(Process::RLIMIT_AS)).should be_nil
+ Process.setrlimit(:AS, *Process.getrlimit(Process::RLIMIT_AS)).should == nil
end
end
it "coerces :CORE into RLIMIT_CORE" do
- Process.setrlimit(:CORE, *Process.getrlimit(Process::RLIMIT_CORE)).should be_nil
+ Process.setrlimit(:CORE, *Process.getrlimit(Process::RLIMIT_CORE)).should == nil
end
it "coerces :CPU into RLIMIT_CPU" do
- Process.setrlimit(:CPU, *Process.getrlimit(Process::RLIMIT_CPU)).should be_nil
+ Process.setrlimit(:CPU, *Process.getrlimit(Process::RLIMIT_CPU)).should == nil
end
it "coerces :DATA into RLIMIT_DATA" do
- Process.setrlimit(:DATA, *Process.getrlimit(Process::RLIMIT_DATA)).should be_nil
+ Process.setrlimit(:DATA, *Process.getrlimit(Process::RLIMIT_DATA)).should == nil
end
it "coerces :FSIZE into RLIMIT_FSIZE" do
- Process.setrlimit(:FSIZE, *Process.getrlimit(Process::RLIMIT_FSIZE)).should be_nil
+ Process.setrlimit(:FSIZE, *Process.getrlimit(Process::RLIMIT_FSIZE)).should == nil
end
it "coerces :NOFILE into RLIMIT_NOFILE" do
- Process.setrlimit(:NOFILE, *Process.getrlimit(Process::RLIMIT_NOFILE)).should be_nil
+ Process.setrlimit(:NOFILE, *Process.getrlimit(Process::RLIMIT_NOFILE)).should == nil
end
it "coerces :STACK into RLIMIT_STACK" do
- Process.setrlimit(:STACK, *Process.getrlimit(Process::RLIMIT_STACK)).should be_nil
+ Process.setrlimit(:STACK, *Process.getrlimit(Process::RLIMIT_STACK)).should == nil
end
- platform_is_not :solaris, :aix do
+ platform_is_not :aix do
it "coerces :MEMLOCK into RLIMIT_MEMLOCK" do
- Process.setrlimit(:MEMLOCK, *Process.getrlimit(Process::RLIMIT_MEMLOCK)).should be_nil
+ Process.setrlimit(:MEMLOCK, *Process.getrlimit(Process::RLIMIT_MEMLOCK)).should == nil
end
end
- platform_is_not :solaris do
- it "coerces :NPROC into RLIMIT_NPROC" do
- Process.setrlimit(:NPROC, *Process.getrlimit(Process::RLIMIT_NPROC)).should be_nil
- end
+ it "coerces :NPROC into RLIMIT_NPROC" do
+ Process.setrlimit(:NPROC, *Process.getrlimit(Process::RLIMIT_NPROC)).should == nil
+ end
- it "coerces :RSS into RLIMIT_RSS" do
- Process.setrlimit(:RSS, *Process.getrlimit(Process::RLIMIT_RSS)).should be_nil
- end
+ it "coerces :RSS into RLIMIT_RSS" do
+ Process.setrlimit(:RSS, *Process.getrlimit(Process::RLIMIT_RSS)).should == nil
end
platform_is :netbsd, :freebsd do
it "coerces :SBSIZE into RLIMIT_SBSIZE" do
- Process.setrlimit(:SBSIZE, *Process.getrlimit(Process::RLIMIT_SBSIZE)).should be_nil
+ Process.setrlimit(:SBSIZE, *Process.getrlimit(Process::RLIMIT_SBSIZE)).should == nil
end
end
platform_is :linux do
it "coerces :RTPRIO into RLIMIT_RTPRIO" do
- Process.setrlimit(:RTPRIO, *Process.getrlimit(Process::RLIMIT_RTPRIO)).should be_nil
+ Process.setrlimit(:RTPRIO, *Process.getrlimit(Process::RLIMIT_RTPRIO)).should == 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
+ Process.setrlimit(:RTTIME, *Process.getrlimit(Process::RLIMIT_RTTIME)).should == nil
end
end
it "coerces :SIGPENDING into RLIMIT_SIGPENDING" do
- Process.setrlimit(:SIGPENDING, *Process.getrlimit(Process::RLIMIT_SIGPENDING)).should be_nil
+ Process.setrlimit(:SIGPENDING, *Process.getrlimit(Process::RLIMIT_SIGPENDING)).should == nil
end
it "coerces :MSGQUEUE into RLIMIT_MSGQUEUE" do
- Process.setrlimit(:MSGQUEUE, *Process.getrlimit(Process::RLIMIT_MSGQUEUE)).should be_nil
+ Process.setrlimit(:MSGQUEUE, *Process.getrlimit(Process::RLIMIT_MSGQUEUE)).should == nil
end
it "coerces :NICE into RLIMIT_NICE" do
- Process.setrlimit(:NICE, *Process.getrlimit(Process::RLIMIT_NICE)).should be_nil
+ Process.setrlimit(:NICE, *Process.getrlimit(Process::RLIMIT_NICE)).should == nil
end
end
it "raises ArgumentError when passed an unknown resource" do
- lambda { Process.setrlimit(:FOO, 1, 1) }.should raise_error(ArgumentError)
+ -> { Process.setrlimit(:FOO, 1, 1) }.should.raise(ArgumentError)
end
end
context "when passed a String" do
platform_is_not :openbsd do
it "coerces 'AS' into RLIMIT_AS" do
- Process.setrlimit("AS", *Process.getrlimit(Process::RLIMIT_AS)).should be_nil
+ Process.setrlimit("AS", *Process.getrlimit(Process::RLIMIT_AS)).should == nil
end
end
it "coerces 'CORE' into RLIMIT_CORE" do
- Process.setrlimit("CORE", *Process.getrlimit(Process::RLIMIT_CORE)).should be_nil
+ Process.setrlimit("CORE", *Process.getrlimit(Process::RLIMIT_CORE)).should == nil
end
it "coerces 'CPU' into RLIMIT_CPU" do
- Process.setrlimit("CPU", *Process.getrlimit(Process::RLIMIT_CPU)).should be_nil
+ Process.setrlimit("CPU", *Process.getrlimit(Process::RLIMIT_CPU)).should == nil
end
it "coerces 'DATA' into RLIMIT_DATA" do
- Process.setrlimit("DATA", *Process.getrlimit(Process::RLIMIT_DATA)).should be_nil
+ Process.setrlimit("DATA", *Process.getrlimit(Process::RLIMIT_DATA)).should == nil
end
it "coerces 'FSIZE' into RLIMIT_FSIZE" do
- Process.setrlimit("FSIZE", *Process.getrlimit(Process::RLIMIT_FSIZE)).should be_nil
+ Process.setrlimit("FSIZE", *Process.getrlimit(Process::RLIMIT_FSIZE)).should == nil
end
it "coerces 'NOFILE' into RLIMIT_NOFILE" do
- Process.setrlimit("NOFILE", *Process.getrlimit(Process::RLIMIT_NOFILE)).should be_nil
+ Process.setrlimit("NOFILE", *Process.getrlimit(Process::RLIMIT_NOFILE)).should == nil
end
it "coerces 'STACK' into RLIMIT_STACK" do
- Process.setrlimit("STACK", *Process.getrlimit(Process::RLIMIT_STACK)).should be_nil
+ Process.setrlimit("STACK", *Process.getrlimit(Process::RLIMIT_STACK)).should == nil
end
- platform_is_not :solaris, :aix do
+ platform_is_not :aix do
it "coerces 'MEMLOCK' into RLIMIT_MEMLOCK" do
- Process.setrlimit("MEMLOCK", *Process.getrlimit(Process::RLIMIT_MEMLOCK)).should be_nil
+ Process.setrlimit("MEMLOCK", *Process.getrlimit(Process::RLIMIT_MEMLOCK)).should == nil
end
end
- platform_is_not :solaris do
- it "coerces 'NPROC' into RLIMIT_NPROC" do
- Process.setrlimit("NPROC", *Process.getrlimit(Process::RLIMIT_NPROC)).should be_nil
- end
+ it "coerces 'NPROC' into RLIMIT_NPROC" do
+ Process.setrlimit("NPROC", *Process.getrlimit(Process::RLIMIT_NPROC)).should == nil
+ end
- it "coerces 'RSS' into RLIMIT_RSS" do
- Process.setrlimit("RSS", *Process.getrlimit(Process::RLIMIT_RSS)).should be_nil
- end
+ it "coerces 'RSS' into RLIMIT_RSS" do
+ Process.setrlimit("RSS", *Process.getrlimit(Process::RLIMIT_RSS)).should == nil
end
platform_is :netbsd, :freebsd do
it "coerces 'SBSIZE' into RLIMIT_SBSIZE" do
- Process.setrlimit("SBSIZE", *Process.getrlimit(Process::RLIMIT_SBSIZE)).should be_nil
+ Process.setrlimit("SBSIZE", *Process.getrlimit(Process::RLIMIT_SBSIZE)).should == nil
end
end
platform_is :linux do
it "coerces 'RTPRIO' into RLIMIT_RTPRIO" do
- Process.setrlimit("RTPRIO", *Process.getrlimit(Process::RLIMIT_RTPRIO)).should be_nil
+ Process.setrlimit("RTPRIO", *Process.getrlimit(Process::RLIMIT_RTPRIO)).should == 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
+ Process.setrlimit("RTTIME", *Process.getrlimit(Process::RLIMIT_RTTIME)).should == nil
end
end
it "coerces 'SIGPENDING' into RLIMIT_SIGPENDING" do
- Process.setrlimit("SIGPENDING", *Process.getrlimit(Process::RLIMIT_SIGPENDING)).should be_nil
+ Process.setrlimit("SIGPENDING", *Process.getrlimit(Process::RLIMIT_SIGPENDING)).should == nil
end
it "coerces 'MSGQUEUE' into RLIMIT_MSGQUEUE" do
- Process.setrlimit("MSGQUEUE", *Process.getrlimit(Process::RLIMIT_MSGQUEUE)).should be_nil
+ Process.setrlimit("MSGQUEUE", *Process.getrlimit(Process::RLIMIT_MSGQUEUE)).should == nil
end
it "coerces 'NICE' into RLIMIT_NICE" do
- Process.setrlimit("NICE", *Process.getrlimit(Process::RLIMIT_NICE)).should be_nil
+ Process.setrlimit("NICE", *Process.getrlimit(Process::RLIMIT_NICE)).should == nil
end
end
it "raises ArgumentError when passed an unknown resource" do
- lambda { Process.setrlimit("FOO", 1, 1) }.should raise_error(ArgumentError)
+ -> { Process.setrlimit("FOO", 1, 1) }.should.raise(ArgumentError)
end
end
@@ -217,7 +213,7 @@ platform_is_not :windows do
obj.should_receive(:to_str).and_return("CORE")
obj.should_not_receive(:to_int)
- Process.setrlimit(obj, @limit, @max).should be_nil
+ Process.setrlimit(obj, @limit, @max).should == nil
end
it "calls #to_int if #to_str does not return a String" do
@@ -225,8 +221,17 @@ platform_is_not :windows do
obj.should_receive(:to_str).and_return(nil)
obj.should_receive(:to_int).and_return(@resource)
- Process.setrlimit(obj, @limit, @max).should be_nil
+ Process.setrlimit(obj, @limit, @max).should == nil
end
end
end
+
+ platform_is :windows do
+ it "is not implemented" do
+ Process.respond_to?(:setrlimit).should == false
+ -> do
+ Process.setrlimit(nil, nil)
+ end.should.raise NotImplementedError
+ end
+ end
end
diff --git a/spec/ruby/core/process/setsid_spec.rb b/spec/ruby/core/process/setsid_spec.rb
index abb75f8225..c83f912066 100644
--- a/spec/ruby/core/process/setsid_spec.rb
+++ b/spec/ruby/core/process/setsid_spec.rb
@@ -1,37 +1,16 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Process.setsid" do
- with_feature :fork do
+ platform_is_not :windows do
it "establishes this process as a new session and process group leader" do
- read, write = IO.pipe
- read2, write2 = IO.pipe
- pid = Process.fork {
- begin
- read.close
- write2.close
- pgid = Process.setsid
- write << pgid
- write.close
- read2.gets
- rescue Exception => e
- write << e << e.backtrace
- end
- Process.exit!
- }
- write.close
- read2.close
- pgid_child = Integer(read.gets)
- read.close
- platform_is_not :aix do
- # AIX does not allow Process.getsid(pid)
- # if pid is in a different session.
- pgid = Process.getsid(pid)
- pgid_child.should == pgid
- end
- write2.close
- Process.wait pid
+ sid = Process.getsid
- pgid_child.should_not == Process.getsid
+ out = ruby_exe("p Process.getsid; p Process.setsid; p Process.getsid").lines
+ out[0].should == "#{sid}\n"
+ out[1].should == out[2]
+ out[2].should_not == "#{sid}\n"
+
+ sid.should == Process.getsid
end
end
end
diff --git a/spec/ruby/core/process/spawn_spec.rb b/spec/ruby/core/process/spawn_spec.rb
index 330ec8fcd8..fb619dce42 100644
--- a/spec/ruby/core/process/spawn_spec.rb
+++ b/spec/ruby/core/process/spawn_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/common', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/common'
newline = "\n"
platform_is :windows do
@@ -7,27 +7,25 @@ platform_is :windows do
end
describe :process_spawn_does_not_close_std_streams, shared: true do
- platform_is_not :windows do
- it "does not close STDIN" do
- code = "STDOUT.puts STDIN.read(0).inspect"
- cmd = "Process.wait Process.spawn(#{ruby_cmd(code).inspect}, #{@options.inspect})"
- ruby_exe(cmd, args: "> #{@output}")
- File.binread(@output).should == %[""#{newline}]
- end
+ it "does not close STDIN" do
+ code = "puts STDIN.read"
+ cmd = "Process.wait Process.spawn(#{ruby_cmd(code).inspect}, #{@options.inspect})"
+ ruby_exe(cmd, args: "< #{fixture(__FILE__, "in.txt")} > #{@name}")
+ File.binread(@name).should == %[stdin#{newline}]
+ end
- it "does not close STDOUT" do
- code = "STDOUT.puts 'hello'"
- cmd = "Process.wait Process.spawn(#{ruby_cmd(code).inspect}, #{@options.inspect})"
- ruby_exe(cmd, args: "> #{@output}")
- File.binread(@output).should == "hello#{newline}"
- end
+ it "does not close STDOUT" do
+ code = "STDOUT.puts 'hello'"
+ cmd = "Process.wait Process.spawn(#{ruby_cmd(code).inspect}, #{@options.inspect})"
+ ruby_exe(cmd, args: "> #{@name}")
+ File.binread(@name).should == "hello#{newline}"
+ end
- it "does not close STDERR" do
- code = "STDERR.puts 'hello'"
- cmd = "Process.wait Process.spawn(#{ruby_cmd(code).inspect}, #{@options.inspect})"
- ruby_exe(cmd, args: "2> #{@output}")
- File.binread(@output).should == "hello#{newline}"
- end
+ it "does not close STDERR" do
+ code = "STDERR.puts 'hello'"
+ cmd = "Process.wait Process.spawn(#{ruby_cmd(code).inspect}, #{@options.inspect})"
+ ruby_exe(cmd, args: "2> #{@name}")
+ File.binread(@name).should =~ /hello#{newline}/
end
end
@@ -47,13 +45,13 @@ describe "Process.spawn" do
end
it "executes the given command" do
- lambda { Process.wait Process.spawn("echo spawn") }.should output_to_fd("spawn\n")
+ -> { Process.wait Process.spawn("echo spawn") }.should output_to_fd("spawn\n")
end
- it "returns the process ID of the new process as a Fixnum" do
+ it "returns the process ID of the new process as an Integer" do
pid = Process.spawn(*ruby_exe, "-e", "exit")
Process.wait pid
- pid.should be_an_instance_of(Fixnum)
+ pid.should.instance_of?(Integer)
end
it "returns immediately" do
@@ -69,43 +67,43 @@ describe "Process.spawn" do
describe "with a single argument" do
platform_is_not :windows do
it "subjects the specified command to shell expansion" do
- lambda { Process.wait Process.spawn("echo *") }.should_not output_to_fd("*\n")
+ -> { Process.wait Process.spawn("echo *") }.should_not output_to_fd("*\n")
end
it "creates an argument array with shell parsing semantics for whitespace" do
- lambda { Process.wait Process.spawn("echo a b c d") }.should output_to_fd("a b c d\n")
+ -> { Process.wait Process.spawn("echo a b c d") }.should output_to_fd("a b c d\n")
end
end
platform_is :windows do
# There is no shell expansion on Windows
it "does not subject the specified command to shell expansion on Windows" do
- lambda { Process.wait Process.spawn("echo *") }.should output_to_fd("*\n")
+ -> { Process.wait Process.spawn("echo *") }.should output_to_fd("*\n")
end
it "does not create an argument array with shell parsing semantics for whitespace on Windows" do
- lambda { Process.wait Process.spawn("echo a b c d") }.should output_to_fd("a b c d\n")
+ -> { Process.wait Process.spawn("echo a b c d") }.should output_to_fd("a b c d\n")
end
end
it "calls #to_str to convert the argument to a String" do
o = mock("to_str")
o.should_receive(:to_str).and_return("echo foo")
- lambda { Process.wait Process.spawn(o) }.should output_to_fd("foo\n")
+ -> { Process.wait Process.spawn(o) }.should output_to_fd("foo\n")
end
it "raises an ArgumentError if the command includes a null byte" do
- lambda { Process.spawn "\000" }.should raise_error(ArgumentError)
+ -> { Process.spawn "\000" }.should.raise(ArgumentError)
end
it "raises a TypeError if the argument does not respond to #to_str" do
- lambda { Process.spawn :echo }.should raise_error(TypeError)
+ -> { Process.spawn :echo }.should.raise(TypeError)
end
end
describe "with multiple arguments" do
it "does not subject the arguments to shell expansion" do
- lambda { Process.wait Process.spawn("echo", "*") }.should output_to_fd("*\n")
+ -> { Process.wait Process.spawn("echo", "*") }.should output_to_fd("*\n")
end
it "preserves whitespace in passed arguments" do
@@ -114,36 +112,36 @@ describe "Process.spawn" do
# The echo command on Windows takes quotes literally
out = "\"a b c d\"\n"
end
- lambda { Process.wait Process.spawn("echo", "a b c d") }.should output_to_fd(out)
+ -> { Process.wait Process.spawn("echo", "a b c d") }.should output_to_fd(out)
end
it "calls #to_str to convert the arguments to Strings" do
o = mock("to_str")
o.should_receive(:to_str).and_return("foo")
- lambda { Process.wait Process.spawn("echo", o) }.should output_to_fd("foo\n")
+ -> { Process.wait Process.spawn("echo", o) }.should output_to_fd("foo\n")
end
it "raises an ArgumentError if an argument includes a null byte" do
- lambda { Process.spawn "echo", "\000" }.should raise_error(ArgumentError)
+ -> { Process.spawn "echo", "\000" }.should.raise(ArgumentError)
end
it "raises a TypeError if an argument does not respond to #to_str" do
- lambda { Process.spawn "echo", :foo }.should raise_error(TypeError)
+ -> { Process.spawn "echo", :foo }.should.raise(TypeError)
end
end
describe "with a command array" do
it "uses the first element as the command name and the second as the argv[0] value" do
platform_is_not :windows do
- lambda { Process.wait Process.spawn(["/bin/sh", "argv_zero"], "-c", "echo $0") }.should output_to_fd("argv_zero\n")
+ -> { Process.wait Process.spawn(["/bin/sh", "argv_zero"], "-c", "echo $0") }.should output_to_fd("argv_zero\n")
end
platform_is :windows do
- lambda { Process.wait Process.spawn(["cmd.exe", "/C"], "/C", "echo", "argv_zero") }.should output_to_fd("argv_zero\n")
+ -> { Process.wait Process.spawn(["cmd.exe", "/C"], "/C", "echo", "argv_zero") }.should output_to_fd("argv_zero\n")
end
end
it "does not subject the arguments to shell expansion" do
- lambda { Process.wait Process.spawn(["echo", "echo"], "*") }.should output_to_fd("*\n")
+ -> { Process.wait Process.spawn(["echo", "echo"], "*") }.should output_to_fd("*\n")
end
it "preserves whitespace in passed arguments" do
@@ -152,47 +150,47 @@ describe "Process.spawn" do
# The echo command on Windows takes quotes literally
out = "\"a b c d\"\n"
end
- lambda { Process.wait Process.spawn(["echo", "echo"], "a b c d") }.should output_to_fd(out)
+ -> { Process.wait Process.spawn(["echo", "echo"], "a b c d") }.should output_to_fd(out)
end
it "calls #to_ary to convert the argument to an Array" do
o = mock("to_ary")
platform_is_not :windows do
o.should_receive(:to_ary).and_return(["/bin/sh", "argv_zero"])
- lambda { Process.wait Process.spawn(o, "-c", "echo $0") }.should output_to_fd("argv_zero\n")
+ -> { Process.wait Process.spawn(o, "-c", "echo $0") }.should output_to_fd("argv_zero\n")
end
platform_is :windows do
o.should_receive(:to_ary).and_return(["cmd.exe", "/C"])
- lambda { Process.wait Process.spawn(o, "/C", "echo", "argv_zero") }.should output_to_fd("argv_zero\n")
+ -> { Process.wait Process.spawn(o, "/C", "echo", "argv_zero") }.should output_to_fd("argv_zero\n")
end
end
it "calls #to_str to convert the first element to a String" do
o = mock("to_str")
o.should_receive(:to_str).and_return("echo")
- lambda { Process.wait Process.spawn([o, "echo"], "foo") }.should output_to_fd("foo\n")
+ -> { Process.wait Process.spawn([o, "echo"], "foo") }.should output_to_fd("foo\n")
end
it "calls #to_str to convert the second element to a String" do
o = mock("to_str")
o.should_receive(:to_str).and_return("echo")
- lambda { Process.wait Process.spawn(["echo", o], "foo") }.should output_to_fd("foo\n")
+ -> { Process.wait Process.spawn(["echo", o], "foo") }.should output_to_fd("foo\n")
end
it "raises an ArgumentError if the Array does not have exactly two elements" do
- lambda { Process.spawn([]) }.should raise_error(ArgumentError)
- lambda { Process.spawn([:a]) }.should raise_error(ArgumentError)
- lambda { Process.spawn([:a, :b, :c]) }.should raise_error(ArgumentError)
+ -> { Process.spawn([]) }.should.raise(ArgumentError)
+ -> { Process.spawn([:a]) }.should.raise(ArgumentError)
+ -> { Process.spawn([:a, :b, :c]) }.should.raise(ArgumentError)
end
it "raises an ArgumentError if the Strings in the Array include a null byte" do
- lambda { Process.spawn ["\000", "echo"] }.should raise_error(ArgumentError)
- lambda { Process.spawn ["echo", "\000"] }.should raise_error(ArgumentError)
+ -> { Process.spawn ["\000", "echo"] }.should.raise(ArgumentError)
+ -> { Process.spawn ["echo", "\000"] }.should.raise(ArgumentError)
end
it "raises a TypeError if an element in the Array does not respond to #to_str" do
- lambda { Process.spawn ["echo", :echo] }.should raise_error(TypeError)
- lambda { Process.spawn [:echo, "echo"] }.should raise_error(TypeError)
+ -> { Process.spawn ["echo", :echo] }.should.raise(TypeError)
+ -> { Process.spawn [:echo, "echo"] }.should.raise(TypeError)
end
end
@@ -209,13 +207,29 @@ describe "Process.spawn" do
it "unsets environment variables whose value is nil" do
ENV["FOO"] = "BAR"
- Process.wait Process.spawn({"FOO" => nil}, "echo #{@var}>#{@name}")
- expected = "\n"
- platform_is :windows do
- # Windows does not expand the variable if it is unset
- expected = "#{@var}\n"
+ -> do
+ Process.wait Process.spawn({"FOO" => nil}, ruby_cmd("p ENV['FOO']"))
+ end.should output_to_fd("nil\n")
+ end
+
+ platform_is_not :windows do
+ it "uses the passed env['PATH'] to search the executable" do
+ dir = tmp("spawn_path_dir")
+ mkdir_p dir
+ begin
+ exe = 'process-spawn-executable-in-path'
+ path = "#{dir}/#{exe}"
+ File.write(path, "#!/bin/sh\necho $1")
+ File.chmod(0755, path)
+
+ env = { "PATH" => "#{dir}#{File::PATH_SEPARATOR}#{ENV['PATH']}" }
+ Process.wait Process.spawn(env, exe, 'OK', out: @name)
+ $?.should.success?
+ File.read(@name).should == "OK\n"
+ ensure
+ rm_r dir
+ end
end
- File.read(@name).should == expected
end
it "calls #to_hash to convert the environment" do
@@ -240,21 +254,21 @@ describe "Process.spawn" do
end
it "raises an ArgumentError if an environment key includes an equals sign" do
- lambda do
+ -> do
Process.spawn({"FOO=" => "BAR"}, "echo #{@var}>#{@name}")
- end.should raise_error(ArgumentError)
+ end.should.raise(ArgumentError)
end
it "raises an ArgumentError if an environment key includes a null byte" do
- lambda do
+ -> do
Process.spawn({"\000" => "BAR"}, "echo #{@var}>#{@name}")
- end.should raise_error(ArgumentError)
+ end.should.raise(ArgumentError)
end
it "raises an ArgumentError if an environment value includes a null byte" do
- lambda do
+ -> do
Process.spawn({"FOO" => "\000"}, "echo #{@var}>#{@name}")
- end.should raise_error(ArgumentError)
+ end.should.raise(ArgumentError)
end
# :unsetenv_others
@@ -271,7 +285,7 @@ describe "Process.spawn" do
it "unsets other environment variables when given a true :unsetenv_others option" do
ENV["FOO"] = "BAR"
Process.wait Process.spawn(*@common_env_spawn_args, unsetenv_others: true)
- $?.success?.should be_true
+ $?.success?.should == true
File.read(@name).should == "\n"
end
end
@@ -279,7 +293,7 @@ describe "Process.spawn" do
it "does not unset other environment variables when given a false :unsetenv_others option" do
ENV["FOO"] = "BAR"
Process.wait Process.spawn(*@common_env_spawn_args, unsetenv_others: false)
- $?.success?.should be_true
+ $?.success?.should == true
File.read(@name).should == "BAR\n"
end
@@ -287,7 +301,7 @@ describe "Process.spawn" do
it "does not unset environment variables included in the environment hash" do
env = @minimal_env.merge({"FOO" => "BAR"})
Process.wait Process.spawn(env, "echo #{@var}>#{@name}", unsetenv_others: true)
- $?.success?.should be_true
+ $?.success?.should == true
File.read(@name).should == "BAR\n"
end
end
@@ -296,25 +310,25 @@ describe "Process.spawn" do
platform_is_not :windows do
it "joins the current process group by default" do
- lambda do
+ -> do
Process.wait Process.spawn(ruby_cmd("print Process.getpgid(Process.pid)"))
end.should output_to_fd(Process.getpgid(Process.pid).to_s)
end
it "joins the current process if pgroup: false" do
- lambda do
+ -> do
Process.wait Process.spawn(ruby_cmd("print Process.getpgid(Process.pid)"), pgroup: false)
end.should output_to_fd(Process.getpgid(Process.pid).to_s)
end
it "joins the current process if pgroup: nil" do
- lambda do
+ -> do
Process.wait Process.spawn(ruby_cmd("print Process.getpgid(Process.pid)"), pgroup: nil)
end.should output_to_fd(Process.getpgid(Process.pid).to_s)
end
it "joins a new process group if pgroup: true" do
- process = lambda do
+ process = -> do
Process.wait Process.spawn(ruby_cmd("print Process.getpgid(Process.pid)"), pgroup: true)
end
@@ -323,7 +337,7 @@ describe "Process.spawn" do
end
it "joins a new process group if pgroup: 0" do
- process = lambda do
+ process = -> do
Process.wait Process.spawn(ruby_cmd("print Process.getpgid(Process.pid)"), pgroup: 0)
end
@@ -333,23 +347,33 @@ describe "Process.spawn" do
it "joins the specified process group if pgroup: pgid" do
pgid = Process.getpgid(Process.pid)
- lambda do
- Process.wait Process.spawn(ruby_cmd("print Process.getpgid(Process.pid)"), pgroup: pgid)
- end.should output_to_fd(pgid.to_s)
+ # The process group is not available on all platforms.
+ # See "man proc" - /proc/[pid]/stat - (5) pgrp
+ # In Travis aarch64 environment, the value is 0.
+ #
+ # $ cat /proc/[pid]/stat
+ # 19179 (ruby) S 19160 0 0 ...
+ unless pgid.zero?
+ -> do
+ Process.wait Process.spawn(ruby_cmd("print Process.getpgid(Process.pid)"), pgroup: pgid)
+ end.should output_to_fd(pgid.to_s)
+ else
+ skip "The process group is not available."
+ end
end
it "raises an ArgumentError if given a negative :pgroup option" do
- lambda { Process.spawn("echo", pgroup: -1) }.should raise_error(ArgumentError)
+ -> { Process.spawn("echo", pgroup: -1) }.should.raise(ArgumentError)
end
it "raises a TypeError if given a symbol as :pgroup option" do
- lambda { Process.spawn("echo", pgroup: :true) }.should raise_error(TypeError)
+ -> { Process.spawn("echo", pgroup: :true) }.should.raise(TypeError)
end
end
platform_is :windows do
it "raises an ArgumentError if given :pgroup option" do
- lambda { Process.spawn("echo", pgroup: false) }.should raise_error(ArgumentError)
+ -> { Process.spawn("echo", pgroup: false) }.should.raise(ArgumentError)
end
end
@@ -360,7 +384,7 @@ describe "Process.spawn" do
# :chdir
it "uses the current working directory as its working directory" do
- lambda do
+ -> do
Process.wait Process.spawn(ruby_cmd("print Dir.pwd"))
end.should output_to_fd(Dir.pwd)
end
@@ -376,7 +400,7 @@ describe "Process.spawn" do
end
it "changes to the directory passed for :chdir" do
- lambda do
+ -> do
Process.wait Process.spawn(ruby_cmd("print Dir.pwd"), chdir: @dir)
end.should output_to_fd(@dir)
end
@@ -385,23 +409,67 @@ describe "Process.spawn" do
dir = mock("spawn_to_path")
dir.should_receive(:to_path).and_return(@dir)
- lambda do
+ -> do
Process.wait Process.spawn(ruby_cmd("print Dir.pwd"), chdir: dir)
end.should output_to_fd(@dir)
end
end
+ # chdir
+
+ platform_is :linux do
+ describe "inside Dir.chdir" do
+ def child_pids(pid)
+ `pgrep -P #{pid}`.lines.map { |child| Integer(child) }
+ end
+
+ it "does not create extra process without chdir" do
+ pid = Process.spawn("sleep 10")
+ begin
+ child_pids(pid).size.should == 0
+ ensure
+ Process.kill("TERM", pid)
+ Process.wait(pid)
+ end
+ end
+
+ it "kills extra chdir processes" do
+ pid = nil
+ Dir.chdir("/") do
+ pid = Process.spawn("sleep 10")
+ end
+
+ children = child_pids(pid)
+ children.size.should <= 1
+
+ Process.kill("TERM", pid)
+ Process.wait(pid)
+
+ if children.size > 0
+ # wait a bit for children to die
+ sleep(1)
+
+ children.each do |child|
+ -> do
+ Process.kill("TERM", child)
+ end.should.raise(Errno::ESRCH)
+ end
+ end
+ end
+ end
+ end
+
# :umask
it "uses the current umask by default" do
- lambda do
+ -> do
Process.wait Process.spawn(ruby_cmd("print File.umask"))
end.should output_to_fd(File.umask.to_s)
end
platform_is_not :windows do
it "sets the umask if given the :umask option" do
- lambda do
+ -> do
Process.wait Process.spawn(ruby_cmd("print File.umask"), umask: 146)
end.should output_to_fd("146")
end
@@ -409,9 +477,19 @@ describe "Process.spawn" do
# redirection
- it "redirects STDOUT to the given file descriptior if out: Fixnum" do
+ it 'redirects to the wrapped IO using wrapped_io.to_io if out: wrapped_io' do
+ File.open(@name, 'w') do |file|
+ -> do
+ wrapped_io = mock('wrapped IO')
+ wrapped_io.should_receive(:to_io).and_return(file)
+ Process.wait Process.spawn('echo Hello World', out: wrapped_io)
+ end.should output_to_fd("Hello World\n", file)
+ end
+ end
+
+ it "redirects STDOUT to the given file descriptor if out: Integer" do
File.open(@name, 'w') do |file|
- lambda do
+ -> do
Process.wait Process.spawn("echo glark", out: file.fileno)
end.should output_to_fd("glark\n", file)
end
@@ -419,7 +497,7 @@ describe "Process.spawn" do
it "redirects STDOUT to the given file if out: IO" do
File.open(@name, 'w') do |file|
- lambda do
+ -> do
Process.wait Process.spawn("echo glark", out: file)
end.should output_to_fd("glark\n", file)
end
@@ -435,9 +513,9 @@ describe "Process.spawn" do
File.read(@name).should == "glark\n"
end
- it "redirects STDERR to the given file descriptior if err: Fixnum" do
+ it "redirects STDERR to the given file descriptor if err: Integer" do
File.open(@name, 'w') do |file|
- lambda do
+ -> do
Process.wait Process.spawn("echo glark>&2", err: file.fileno)
end.should output_to_fd("glark\n", file)
end
@@ -445,7 +523,7 @@ describe "Process.spawn" do
it "redirects STDERR to the given file descriptor if err: IO" do
File.open(@name, 'w') do |file|
- lambda do
+ -> do
Process.wait Process.spawn("echo glark>&2", err: file)
end.should output_to_fd("glark\n", file)
end
@@ -458,15 +536,15 @@ describe "Process.spawn" do
it "redirects STDERR to child STDOUT if :err => [:child, :out]" do
File.open(@name, 'w') do |file|
- lambda do
+ -> do
Process.wait Process.spawn("echo glark>&2", :out => file, :err => [:child, :out])
end.should output_to_fd("glark\n", file)
end
end
- it "redirects both STDERR and STDOUT to the given file descriptior" do
+ it "redirects both STDERR and STDOUT to the given file descriptor" do
File.open(@name, 'w') do |file|
- lambda do
+ -> do
Process.wait Process.spawn(ruby_cmd("print(:glark); STDOUT.flush; STDERR.print(:bang)"),
[:out, :err] => file.fileno)
end.should output_to_fd("glarkbang", file)
@@ -475,7 +553,7 @@ describe "Process.spawn" do
it "redirects both STDERR and STDOUT to the given IO" do
File.open(@name, 'w') do |file|
- lambda do
+ -> do
Process.wait Process.spawn(ruby_cmd("print(:glark); STDOUT.flush; STDERR.print(:bang)"),
[:out, :err] => file)
end.should output_to_fd("glarkbang", file)
@@ -488,126 +566,208 @@ describe "Process.spawn" do
File.read(@name).should == "glarkbang"
end
- context "when passed close_others: true" do
- before :each do
- @output = tmp("spawn_close_others_true")
- @options = { close_others: true }
- end
-
- after :each do
- rm_r @output
+ platform_is_not :windows, :android do
+ it "closes STDERR in the child if :err => :close" do
+ File.open(@name, 'w') do |file|
+ -> do
+ code = "begin; STDOUT.puts 'out'; STDERR.puts 'hello'; rescue => e; puts 'rescued'; end"
+ Process.wait Process.spawn(ruby_cmd(code), :out => file, :err => :close)
+ end.should output_to_fd("out\nrescued\n", file)
+ end
end
+ end
- it "closes file descriptors >= 3 in the child process" do
- IO.pipe do |r, w|
- begin
- pid = Process.spawn(ruby_cmd("while File.exist? '#{@name}'; sleep 0.1; end"), @options)
- w.close
- lambda { r.read_nonblock(1) }.should raise_error(EOFError)
- ensure
- rm_r @name
- Process.wait(pid) if pid
- end
+ platform_is_not :windows do
+ it "redirects non-default file descriptor to itself" do
+ File.open(@name, 'w') do |file|
+ -> do
+ Process.wait Process.spawn(
+ ruby_cmd("f = IO.new(#{file.fileno}, 'w'); f.print(:bang); f.flush"), file.fileno => file.fileno)
+ end.should output_to_fd("bang", file)
end
end
-
- it_should_behave_like :process_spawn_does_not_close_std_streams
end
- context "when passed close_others: false" do
- before :each do
- @output = tmp("spawn_close_others_false")
- @options = { close_others: false }
- end
+ it "redirects default file descriptor to itself" do
+ -> do
+ Process.wait Process.spawn(
+ ruby_cmd("f = IO.new(#{STDOUT.fileno}, 'w'); f.print(:bang); f.flush"), STDOUT.fileno => STDOUT.fileno)
+ end.should output_to_fd("bang", STDOUT)
+ end
- after :each do
- rm_r @output
- end
+ # :close_others
- it "closes file descriptors >= 3 in the child process because they are set close_on_exec by default" do
- IO.pipe do |r, w|
- begin
- pid = Process.spawn(ruby_cmd("while File.exist? '#{@name}'; sleep 0.1; end"), @options)
+ platform_is_not :windows do
+ context "defaults :close_others to" do
+ it "false" do
+ IO.pipe do |r, w|
+ w.close_on_exec = false
+ code = "io = IO.new(#{w.fileno}); io.puts('inherited'); io.close"
+ pid = Process.spawn(ruby_cmd(code))
w.close
- lambda { r.read_nonblock(1) }.should raise_error(EOFError)
- ensure
- rm_r @name
- Process.wait(pid) if pid
+ Process.wait(pid)
+ r.read.should == "inherited\n"
end
end
end
- platform_is_not :windows do
- it "does not close file descriptors >= 3 in the child process if fds are set close_on_exec=false" do
+ context "when passed close_others: true" do
+ before :each do
+ @options = { close_others: true }
+ end
+
+ it "closes file descriptors >= 3 in the child process even if fds are set close_on_exec=false" do
+ touch @name
IO.pipe do |r, w|
r.close_on_exec = false
w.close_on_exec = false
+
begin
pid = Process.spawn(ruby_cmd("while File.exist? '#{@name}'; sleep 0.1; end"), @options)
w.close
- lambda { r.read_nonblock(1) }.should raise_error(Errno::EAGAIN)
+ r.read(1).should == nil
ensure
rm_r @name
Process.wait(pid) if pid
end
end
end
+
+ it_should_behave_like :process_spawn_does_not_close_std_streams
end
- it_should_behave_like :process_spawn_does_not_close_std_streams
+ context "when passed close_others: false" do
+ before :each do
+ @options = { close_others: false }
+ end
+
+ it "closes file descriptors >= 3 in the child process because they are set close_on_exec by default" do
+ touch @name
+ IO.pipe do |r, w|
+ begin
+ pid = Process.spawn(ruby_cmd("while File.exist? '#{@name}'; sleep 0.1; end"), @options)
+ w.close
+ r.read(1).should == nil
+ ensure
+ rm_r @name
+ Process.wait(pid) if pid
+ end
+ end
+ end
+
+ it "does not close file descriptors >= 3 in the child process if fds are set close_on_exec=false" do
+ IO.pipe do |r, w|
+ r.close_on_exec = false
+ w.close_on_exec = false
+
+ code = "fd = IO.for_fd(#{w.fileno}); fd.autoclose = false; fd.write 'abc'; fd.close"
+ pid = Process.spawn(ruby_cmd(code), @options)
+ begin
+ w.close
+ r.read.should == 'abc'
+ ensure
+ Process.wait(pid)
+ end
+ end
+ end
+
+ it_should_behave_like :process_spawn_does_not_close_std_streams
+ end
end
# error handling
it "raises an ArgumentError if passed no command arguments" do
- lambda { Process.spawn }.should raise_error(ArgumentError)
+ -> { Process.spawn }.should.raise(ArgumentError)
end
it "raises an ArgumentError if passed env or options but no command arguments" do
- lambda { Process.spawn({}) }.should raise_error(ArgumentError)
+ -> { Process.spawn({}) }.should.raise(ArgumentError)
end
it "raises an ArgumentError if passed env and options but no command arguments" do
- lambda { Process.spawn({}, {}) }.should raise_error(ArgumentError)
+ -> { Process.spawn({}, {}) }.should.raise(ArgumentError)
end
it "raises an Errno::ENOENT for an empty string" do
- lambda { Process.spawn "" }.should raise_error(Errno::ENOENT)
+ -> { Process.spawn "" }.should.raise(Errno::ENOENT)
end
it "raises an Errno::ENOENT if the command does not exist" do
- lambda { Process.spawn "nonesuch" }.should raise_error(Errno::ENOENT)
+ -> { Process.spawn "nonesuch" }.should.raise(Errno::ENOENT, "No such file or directory - nonesuch")
+ end
+
+ it "sets $? to exit status 127 when the command does not exist" do
+ Process.spawn("nonesuch") rescue nil
+ $?.exitstatus.should == 127
+ end
+
+ it "raises an Errno::ENOENT if the file does not exist" do
+ -> { Process.spawn "./nonesuch" }.should.raise(Errno::ENOENT, "No such file or directory - ./nonesuch")
+ end
+
+ it "sets $? to exit status 127 when the file does not exist" do
+ Process.spawn("./nonesuch") rescue nil
+ $?.exitstatus.should == 127
+ end
+
+ platform_is_not :windows do
+ it "raises an Errno::EACCES when the path is a directory" do
+ -> { Process.spawn "./" }.should.raise(Errno::EACCES, "Permission denied - ./")
+ end
end
unless File.executable?(__FILE__) # Some FS (e.g. vboxfs) locate all files executable
platform_is_not :windows do
it "raises an Errno::EACCES when the file does not have execute permissions" do
- lambda { Process.spawn __FILE__ }.should raise_error(Errno::EACCES)
+ -> { Process.spawn __FILE__ }.should.raise(Errno::EACCES, "Permission denied - #{__FILE__}")
+ end
+
+ it "sets $? to exit status 127 when the file does not have execute permissions" do
+ Process.spawn(__FILE__) rescue nil
+ $?.exitstatus.should == 127
+ end
+
+ it "raises an Errno::ENOENT when a non-executable file is found in PATH" do
+ dir = tmp("spawn_path_non_executable_dir")
+ mkdir_p dir
+ begin
+ exe = 'process-spawn-non-executable-in-path'
+ File.write("#{dir}/#{exe}", "#!/bin/sh\necho hi")
+ File.chmod(0644, "#{dir}/#{exe}")
+ env = { "PATH" => "#{dir}#{File::PATH_SEPARATOR}#{ENV['PATH']}" }
+ -> { Process.spawn(env, exe) }.should.raise(Errno::ENOENT, "No such file or directory - #{exe}")
+ $?.exitstatus.should == 127
+ ensure
+ rm_r dir
+ end
end
end
platform_is :windows do
it "raises Errno::EACCES or Errno::ENOEXEC when the file is not an executable file" do
- lambda { Process.spawn __FILE__ }.should raise_error(SystemCallError) { |e|
- [Errno::EACCES, Errno::ENOEXEC].should include(e.class)
+ -> { Process.spawn __FILE__ }.should.raise(SystemCallError) { |e|
+ [Errno::EACCES, Errno::ENOEXEC].should.include?(e.class)
}
end
end
end
- it "raises an Errno::EACCES when passed a directory" do
- lambda { Process.spawn File.dirname(__FILE__) }.should raise_error(Errno::EACCES)
+ it "raises an Errno::EACCES or Errno::EISDIR when passed a directory" do
+ -> { Process.spawn __dir__ }.should.raise(SystemCallError) { |e|
+ [Errno::EACCES, Errno::EISDIR].should.include?(e.class)
+ }
end
it "raises an ArgumentError when passed a string key in options" do
- lambda { Process.spawn("echo", "chdir" => Dir.pwd) }.should raise_error(ArgumentError)
+ -> { Process.spawn("echo", "chdir" => Dir.pwd) }.should.raise(ArgumentError)
end
it "raises an ArgumentError when passed an unknown option key" do
- lambda { Process.spawn("echo", nonesuch: :foo) }.should raise_error(ArgumentError)
+ -> { Process.spawn("echo", nonesuch: :foo) }.should.raise(ArgumentError)
end
- platform_is_not :windows do
+ platform_is_not :windows, :aix do
describe "with Integer option keys" do
before :each do
@name = tmp("spawn_fd_map.txt")
@@ -621,13 +781,15 @@ describe "Process.spawn" do
end
it "maps the key to a file descriptor in the child that inherits the file descriptor from the parent specified by the value" do
- child_fd = @io.fileno + 1
- args = ruby_cmd(fixture(__FILE__, "map_fd.rb"), args: [child_fd.to_s])
- pid = Process.spawn(*args, { child_fd => @io })
- Process.waitpid pid
- @io.rewind
-
- @io.read.should == "writing to fd: #{child_fd}"
+ File.open(__FILE__, "r") do |f|
+ child_fd = f.fileno
+ args = ruby_cmd(fixture(__FILE__, "map_fd.rb"), args: [child_fd.to_s])
+ pid = Process.spawn(*args, { child_fd => @io })
+ Process.waitpid pid
+ @io.rewind
+
+ @io.read.should == "writing to fd: #{child_fd}"
+ end
end
end
end
diff --git a/spec/ruby/core/process/status/bit_and_spec.rb b/spec/ruby/core/process/status/bit_and_spec.rb
index 963d2c6c26..a5b1123e90 100644
--- a/spec/ruby/core/process/status/bit_and_spec.rb
+++ b/spec/ruby/core/process/status/bit_and_spec.rb
@@ -1,5 +1,38 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
-describe "Process::Status#&" do
- it "needs to be reviewed for spec completeness"
+ruby_version_is ""..."4.0" do
+
+ describe "Process::Status#&" do
+ it "returns a bitwise and of the integer status of an exited child" do
+ suppress_warning do
+ ruby_exe("exit(29)", exit_status: 29)
+ ($? & 0).should == 0
+ ($? & $?.to_i).should == $?.to_i
+
+ # Actual value is implementation specific
+ platform_is :linux do
+ # 29 == 0b11101
+ ($? & 0b1011100000000).should == 0b1010100000000
+ end
+ end
+ end
+
+ ruby_version_is ""..."4.0" do
+ it "raises an ArgumentError if mask is negative" do
+ suppress_warning do
+ ruby_exe("exit(0)")
+ -> {
+ $? & -1
+ }.should.raise(ArgumentError, 'negative mask value: -1')
+ end
+ end
+
+ it "shows a deprecation warning" do
+ ruby_exe("exit(0)")
+ -> {
+ $? & 0
+ }.should complain(/warning: Process::Status#& is deprecated and will be removed .*use other Process::Status predicates instead/)
+ end
+ end
+ end
end
diff --git a/spec/ruby/core/process/status/coredump_spec.rb b/spec/ruby/core/process/status/coredump_spec.rb
index 8988cff9e1..fbbaf926f7 100644
--- a/spec/ruby/core/process/status/coredump_spec.rb
+++ b/spec/ruby/core/process/status/coredump_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "Process::Status#coredump?" do
it "needs to be reviewed for spec completeness"
diff --git a/spec/ruby/core/process/status/equal_value_spec.rb b/spec/ruby/core/process/status/equal_value_spec.rb
index 1eaaf82273..d8a2be26b8 100644
--- a/spec/ruby/core/process/status/equal_value_spec.rb
+++ b/spec/ruby/core/process/status/equal_value_spec.rb
@@ -1,5 +1,15 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "Process::Status#==" do
- it "needs to be reviewed for spec completeness"
+ it "returns true when compared to the integer status of an exited child" do
+ ruby_exe("exit(29)", exit_status: 29)
+ $?.to_i.should == $?
+ $?.should == $?.to_i
+ end
+
+ it "returns true when compared to the integer status of a terminated child" do
+ ruby_exe("Process.kill(:KILL, $$); exit(29)", exit_status: platform_is(:windows) ? 0 : :SIGKILL)
+ $?.to_i.should == $?
+ $?.should == $?.to_i
+ end
end
diff --git a/spec/ruby/core/process/status/exited_spec.rb b/spec/ruby/core/process/status/exited_spec.rb
index 79863360c5..ad14b35000 100644
--- a/spec/ruby/core/process/status/exited_spec.rb
+++ b/spec/ruby/core/process/status/exited_spec.rb
@@ -1,37 +1,32 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "Process::Status#exited?" do
-
describe "for a child that exited normally" do
-
before :each do
ruby_exe("exit(0)")
end
it "returns true" do
- $?.exited?.should be_true
+ $?.exited?.should == true
end
end
describe "for a terminated child" do
-
before :each do
- ruby_exe("Process.kill(:KILL, $$); exit(42)")
+ ruby_exe("Process.kill(:KILL, $$); exit(42)", exit_status: platform_is(:windows) ? 0 : :SIGKILL)
end
platform_is_not :windows do
it "returns false" do
- $?.exited?.should be_false
+ $?.exited?.should == false
end
end
platform_is :windows do
it "always returns true" do
- $?.exited?.should be_true
+ $?.exited?.should == true
end
end
-
end
-
end
diff --git a/spec/ruby/core/process/status/exitstatus_spec.rb b/spec/ruby/core/process/status/exitstatus_spec.rb
index 57baf77724..5c86c2b3c8 100644
--- a/spec/ruby/core/process/status/exitstatus_spec.rb
+++ b/spec/ruby/core/process/status/exitstatus_spec.rb
@@ -1,13 +1,25 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "Process::Status#exitstatus" do
-
before :each do
- ruby_exe("exit(42)")
+ ruby_exe("exit(42)", exit_status: 42)
end
it "returns the process exit code" do
$?.exitstatus.should == 42
end
+ describe "for a child that raised SignalException" do
+ before :each do
+ ruby_exe("Process.kill(:KILL, $$); exit(42)", exit_status: platform_is(:windows) ? 0 : :SIGKILL)
+ end
+
+ platform_is_not :windows do
+ # The exitstatus is not set in these cases. See the termsig_spec
+ # for info on where the signal number (SIGTERM) is available.
+ it "returns nil" do
+ $?.exitstatus.should == nil
+ end
+ end
+ end
end
diff --git a/spec/ruby/core/process/status/inspect_spec.rb b/spec/ruby/core/process/status/inspect_spec.rb
index f3e7d8c9ab..03f0479f2c 100644
--- a/spec/ruby/core/process/status/inspect_spec.rb
+++ b/spec/ruby/core/process/status/inspect_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "Process::Status#inspect" do
it "needs to be reviewed for spec completeness"
diff --git a/spec/ruby/core/process/status/pid_spec.rb b/spec/ruby/core/process/status/pid_spec.rb
index 3389c242ff..9965fc3bdf 100644
--- a/spec/ruby/core/process/status/pid_spec.rb
+++ b/spec/ruby/core/process/status/pid_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
platform_is_not :windows do
describe "Process::Status#pid" do
diff --git a/spec/ruby/core/process/status/right_shift_spec.rb b/spec/ruby/core/process/status/right_shift_spec.rb
index 5786d4163c..5689526f54 100644
--- a/spec/ruby/core/process/status/right_shift_spec.rb
+++ b/spec/ruby/core/process/status/right_shift_spec.rb
@@ -1,5 +1,37 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
-describe "Process::Status#>>" do
- it "needs to be reviewed for spec completeness"
+ruby_version_is ""..."4.0" do
+
+ describe "Process::Status#>>" do
+ it "returns a right shift of the integer status of an exited child" do
+ suppress_warning do
+ ruby_exe("exit(29)", exit_status: 29)
+ ($? >> 0).should == $?.to_i
+ ($? >> 1).should == $?.to_i >> 1
+
+ # Actual value is implementation specific
+ platform_is :linux do
+ ($? >> 8).should == 29
+ end
+ end
+ end
+
+ ruby_version_is ""..."4.0" do
+ it "raises an ArgumentError if shift value is negative" do
+ suppress_warning do
+ ruby_exe("exit(0)")
+ -> {
+ $? >> -1
+ }.should.raise(ArgumentError, 'negative shift value: -1')
+ end
+ end
+
+ it "shows a deprecation warning" do
+ ruby_exe("exit(0)")
+ -> {
+ $? >> 0
+ }.should complain(/warning: Process::Status#>> is deprecated and will be removed .*use other Process::Status attributes instead/)
+ end
+ end
+ end
end
diff --git a/spec/ruby/core/process/status/signaled_spec.rb b/spec/ruby/core/process/status/signaled_spec.rb
index 0f80a525c9..8cf409bb42 100644
--- a/spec/ruby/core/process/status/signaled_spec.rb
+++ b/spec/ruby/core/process/status/signaled_spec.rb
@@ -1,35 +1,31 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "Process::Status#signaled?" do
-
describe "for a cleanly exited child" do
-
before :each do
ruby_exe("exit(0)")
end
it "returns false" do
- $?.signaled?.should be_false
+ $?.signaled?.should == false
end
end
describe "for a terminated child" do
-
before :each do
- ruby_exe("Process.kill(:KILL, $$); exit(42)")
+ ruby_exe("Process.kill(:KILL, $$); exit(42)", exit_status: platform_is(:windows) ? 0 : :SIGKILL)
end
platform_is_not :windows do
it "returns true" do
- $?.signaled?.should be_true
+ $?.signaled?.should == true
end
end
platform_is :windows do
it "always returns false" do
- $?.signaled?.should be_false
+ $?.signaled?.should == false
end
end
-
end
end
diff --git a/spec/ruby/core/process/status/stopped_spec.rb b/spec/ruby/core/process/status/stopped_spec.rb
index e984cefaf7..bebd441d6f 100644
--- a/spec/ruby/core/process/status/stopped_spec.rb
+++ b/spec/ruby/core/process/status/stopped_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "Process::Status#stopped?" do
it "needs to be reviewed for spec completeness"
diff --git a/spec/ruby/core/process/status/stopsig_spec.rb b/spec/ruby/core/process/status/stopsig_spec.rb
index 95fc5b0e77..b2a7c5d9e2 100644
--- a/spec/ruby/core/process/status/stopsig_spec.rb
+++ b/spec/ruby/core/process/status/stopsig_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "Process::Status#stopsig" do
it "needs to be reviewed for spec completeness"
diff --git a/spec/ruby/core/process/status/success_spec.rb b/spec/ruby/core/process/status/success_spec.rb
index e589d3f819..f61243c667 100644
--- a/spec/ruby/core/process/status/success_spec.rb
+++ b/spec/ruby/core/process/status/success_spec.rb
@@ -1,51 +1,41 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "Process::Status#success?" do
-
describe "for a child that exited normally" do
-
before :each do
ruby_exe("exit(0)")
end
it "returns true" do
- $?.success?.should be_true
+ $?.success?.should == true
end
end
describe "for a child that exited with a non zero status" do
-
before :each do
- ruby_exe("exit(42)")
+ ruby_exe("exit(42)", exit_status: 42)
end
it "returns false" do
- $?.success?.should be_false
+ $?.success?.should == false
end
end
describe "for a child that was terminated" do
-
before :each do
- ruby_exe("Process.kill(:KILL, $$); exit(42)")
+ ruby_exe("Process.kill(:KILL, $$); exit(42)", exit_status: platform_is(:windows) ? 0 : :SIGKILL)
end
platform_is_not :windows do
-
it "returns nil" do
- $?.success?.should be_nil
+ $?.success?.should == nil
end
-
end
platform_is :windows do
-
it "always returns true" do
- $?.success?.should be_true
+ $?.success?.should == true
end
-
end
-
end
-
end
diff --git a/spec/ruby/core/process/status/termsig_spec.rb b/spec/ruby/core/process/status/termsig_spec.rb
index d4f55e2521..1d57724d12 100644
--- a/spec/ruby/core/process/status/termsig_spec.rb
+++ b/spec/ruby/core/process/status/termsig_spec.rb
@@ -1,39 +1,43 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "Process::Status#termsig" do
-
describe "for a child that exited normally" do
-
before :each do
ruby_exe("exit(0)")
end
- it "returns true" do
- $?.termsig.should be_nil
+ it "returns nil" do
+ $?.termsig.should == nil
end
end
- describe "for a child that was sent a signal" do
-
+ describe "for a child that raised SignalException" do
before :each do
- ruby_exe("Process.kill(:KILL, $$); exit(42)")
+ ruby_exe("raise SignalException, 'SIGTERM'", exit_status: :SIGTERM)
end
platform_is_not :windows do
+ it "returns the signal" do
+ $?.termsig.should == Signal.list["TERM"]
+ end
+ end
+ end
+ describe "for a child that was sent a signal" do
+ before :each do
+ ruby_exe("Process.kill(:KILL, $$); exit(42)", exit_status: platform_is(:windows) ? 0 : :SIGKILL)
+ end
+
+ platform_is_not :windows do
it "returns the signal" do
$?.termsig.should == Signal.list["KILL"]
end
-
end
platform_is :windows do
-
it "always returns nil" do
- $?.termsig.should be_nil
+ $?.termsig.should == nil
end
-
end
-
end
end
diff --git a/spec/ruby/core/process/status/to_i_spec.rb b/spec/ruby/core/process/status/to_i_spec.rb
index c45724552e..0bfb883d23 100644
--- a/spec/ruby/core/process/status/to_i_spec.rb
+++ b/spec/ruby/core/process/status/to_i_spec.rb
@@ -1,5 +1,13 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "Process::Status#to_i" do
- it "needs to be reviewed for spec completeness"
+ it "returns an integer when the child exits" do
+ ruby_exe('exit 48', exit_status: 48)
+ $?.to_i.should.instance_of?(Integer)
+ end
+
+ it "returns an integer when the child is signaled" do
+ ruby_exe('raise SignalException, "TERM"', exit_status: platform_is(:windows) ? 3 : :SIGTERM)
+ $?.to_i.should.instance_of?(Integer)
+ end
end
diff --git a/spec/ruby/core/process/status/to_int_spec.rb b/spec/ruby/core/process/status/to_int_spec.rb
index 8c988d7e19..fb596c1bfb 100644
--- a/spec/ruby/core/process/status/to_int_spec.rb
+++ b/spec/ruby/core/process/status/to_int_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "Process::Status#to_int" do
it "needs to be reviewed for spec completeness"
diff --git a/spec/ruby/core/process/status/to_s_spec.rb b/spec/ruby/core/process/status/to_s_spec.rb
index ac87f4712a..5c0d4cd30c 100644
--- a/spec/ruby/core/process/status/to_s_spec.rb
+++ b/spec/ruby/core/process/status/to_s_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "Process::Status#to_s" do
it "needs to be reviewed for spec completeness"
diff --git a/spec/ruby/core/process/status/wait_spec.rb b/spec/ruby/core/process/status/wait_spec.rb
new file mode 100644
index 0000000000..8bd7fc6b43
--- /dev/null
+++ b/spec/ruby/core/process/status/wait_spec.rb
@@ -0,0 +1,102 @@
+require_relative '../../../spec_helper'
+require_relative '../fixtures/common'
+
+describe "Process::Status.wait" do
+ ProcessSpecs.use_system_ruby(self)
+
+ before :all do
+ begin
+ leaked = Process.waitall
+ # Ruby-space should not see PIDs used by rjit
+ raise "subprocesses leaked before wait specs: #{leaked}" unless leaked.empty?
+ rescue NotImplementedError
+ end
+ end
+
+ it "returns a status with pid -1 if there are no child processes" do
+ Process::Status.wait.pid.should == -1
+ end
+
+ platform_is_not :windows do
+ it "returns a status with its child pid" do
+ pid = Process.spawn(ruby_cmd('exit'))
+ status = Process::Status.wait
+ status.should.instance_of?(Process::Status)
+ status.pid.should == pid
+ end
+
+ it "should not set $? to the Process::Status" do
+ pid = Process.spawn(ruby_cmd('exit'))
+ status = Process::Status.wait
+ $?.should_not.equal?(status)
+ end
+
+ it "should not change the value of $?" do
+ pid = Process.spawn(ruby_cmd('exit'))
+ Process.wait
+ status = $?
+ Process::Status.wait
+ status.should.equal?($?)
+ end
+
+ it "waits for any child process if no pid is given" do
+ pid = Process.spawn(ruby_cmd('exit'))
+ Process::Status.wait.pid.should == pid
+ -> { Process.kill(0, pid) }.should.raise(Errno::ESRCH)
+ end
+
+ it "waits for a specific child if a pid is given" do
+ pid1 = Process.spawn(ruby_cmd('exit'))
+ pid2 = Process.spawn(ruby_cmd('exit'))
+ Process::Status.wait(pid2).pid.should == pid2
+ Process::Status.wait(pid1).pid.should == pid1
+ -> { Process.kill(0, pid1) }.should.raise(Errno::ESRCH)
+ -> { Process.kill(0, pid2) }.should.raise(Errno::ESRCH)
+ end
+
+ it "coerces the pid to an Integer" do
+ pid1 = Process.spawn(ruby_cmd('exit'))
+ Process::Status.wait(mock_int(pid1)).pid.should == pid1
+ -> { Process.kill(0, pid1) }.should.raise(Errno::ESRCH)
+ end
+
+ # This spec is probably system-dependent.
+ it "waits for a child whose process group ID is that of the calling process" do
+ pid1 = Process.spawn(ruby_cmd('exit'), pgroup: true)
+ pid2 = Process.spawn(ruby_cmd('exit'))
+
+ Process::Status.wait(0).pid.should == pid2
+ Process::Status.wait.pid.should == pid1
+ end
+
+ # This spec is probably system-dependent.
+ guard -> { Process.respond_to?(:fork) } do
+ it "doesn't block if no child is available when WNOHANG is used" do
+ read, write = IO.pipe
+ pid = Process.fork do
+ read.close
+ Signal.trap("TERM") { Process.exit! }
+ write << 1
+ write.close
+ sleep
+ end
+
+ Process::Status.wait(pid, Process::WNOHANG).should == nil
+
+ # wait for the child to setup its TERM handler
+ write.close
+ read.read(1)
+ read.close
+
+ Process.kill("TERM", pid)
+ Process::Status.wait.pid.should == pid
+ end
+ end
+
+ it "always accepts flags=0" do
+ pid = Process.spawn(ruby_cmd('exit'))
+ Process::Status.wait(-1, 0).pid.should == pid
+ -> { Process.kill(0, pid) }.should.raise(Errno::ESRCH)
+ end
+ end
+end
diff --git a/spec/ruby/core/process/sys/getegid_spec.rb b/spec/ruby/core/process/sys/getegid_spec.rb
index c21b890519..5b8588f147 100644
--- a/spec/ruby/core/process/sys/getegid_spec.rb
+++ b/spec/ruby/core/process/sys/getegid_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "Process::Sys.getegid" do
it "needs to be reviewed for spec completeness"
diff --git a/spec/ruby/core/process/sys/geteuid_spec.rb b/spec/ruby/core/process/sys/geteuid_spec.rb
index 85c8d6e1bb..0ce7fc5459 100644
--- a/spec/ruby/core/process/sys/geteuid_spec.rb
+++ b/spec/ruby/core/process/sys/geteuid_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "Process::Sys.geteuid" do
it "needs to be reviewed for spec completeness"
diff --git a/spec/ruby/core/process/sys/getgid_spec.rb b/spec/ruby/core/process/sys/getgid_spec.rb
index 945d3340f7..05c0fd4c0b 100644
--- a/spec/ruby/core/process/sys/getgid_spec.rb
+++ b/spec/ruby/core/process/sys/getgid_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "Process::Sys.getgid" do
it "needs to be reviewed for spec completeness"
diff --git a/spec/ruby/core/process/sys/getuid_spec.rb b/spec/ruby/core/process/sys/getuid_spec.rb
index ead6e3044f..56bcef01cc 100644
--- a/spec/ruby/core/process/sys/getuid_spec.rb
+++ b/spec/ruby/core/process/sys/getuid_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "Process::Sys.getuid" do
it "needs to be reviewed for spec completeness"
diff --git a/spec/ruby/core/process/sys/issetugid_spec.rb b/spec/ruby/core/process/sys/issetugid_spec.rb
index 2919c351a7..4fc7dc3bc6 100644
--- a/spec/ruby/core/process/sys/issetugid_spec.rb
+++ b/spec/ruby/core/process/sys/issetugid_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "Process::Sys.issetugid" do
it "needs to be reviewed for spec completeness"
diff --git a/spec/ruby/core/process/sys/setegid_spec.rb b/spec/ruby/core/process/sys/setegid_spec.rb
index edc0d59da4..8f20330b94 100644
--- a/spec/ruby/core/process/sys/setegid_spec.rb
+++ b/spec/ruby/core/process/sys/setegid_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "Process::Sys.setegid" do
it "needs to be reviewed for spec completeness"
diff --git a/spec/ruby/core/process/sys/seteuid_spec.rb b/spec/ruby/core/process/sys/seteuid_spec.rb
index 70cc78bec4..57d3a4800d 100644
--- a/spec/ruby/core/process/sys/seteuid_spec.rb
+++ b/spec/ruby/core/process/sys/seteuid_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "Process::Sys.seteuid" do
it "needs to be reviewed for spec completeness"
diff --git a/spec/ruby/core/process/sys/setgid_spec.rb b/spec/ruby/core/process/sys/setgid_spec.rb
index 25272b1eec..cc712e0102 100644
--- a/spec/ruby/core/process/sys/setgid_spec.rb
+++ b/spec/ruby/core/process/sys/setgid_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "Process::Sys.setgid" do
it "needs to be reviewed for spec completeness"
diff --git a/spec/ruby/core/process/sys/setregid_spec.rb b/spec/ruby/core/process/sys/setregid_spec.rb
index 18a5834c80..57d491a707 100644
--- a/spec/ruby/core/process/sys/setregid_spec.rb
+++ b/spec/ruby/core/process/sys/setregid_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "Process::Sys.setregid" do
it "needs to be reviewed for spec completeness"
diff --git a/spec/ruby/core/process/sys/setresgid_spec.rb b/spec/ruby/core/process/sys/setresgid_spec.rb
index 9f1736b460..9be06612c1 100644
--- a/spec/ruby/core/process/sys/setresgid_spec.rb
+++ b/spec/ruby/core/process/sys/setresgid_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "Process::Sys.setresgid" do
it "needs to be reviewed for spec completeness"
diff --git a/spec/ruby/core/process/sys/setresuid_spec.rb b/spec/ruby/core/process/sys/setresuid_spec.rb
index 94c892bfdf..1092b349cb 100644
--- a/spec/ruby/core/process/sys/setresuid_spec.rb
+++ b/spec/ruby/core/process/sys/setresuid_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "Process::Sys.setresuid" do
it "needs to be reviewed for spec completeness"
diff --git a/spec/ruby/core/process/sys/setreuid_spec.rb b/spec/ruby/core/process/sys/setreuid_spec.rb
index 72a8e61e7a..f3451c63c8 100644
--- a/spec/ruby/core/process/sys/setreuid_spec.rb
+++ b/spec/ruby/core/process/sys/setreuid_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "Process::Sys.setreuid" do
it "needs to be reviewed for spec completeness"
diff --git a/spec/ruby/core/process/sys/setrgid_spec.rb b/spec/ruby/core/process/sys/setrgid_spec.rb
index ae820c98b8..27eea2ed86 100644
--- a/spec/ruby/core/process/sys/setrgid_spec.rb
+++ b/spec/ruby/core/process/sys/setrgid_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "Process::Sys.setrgid" do
it "needs to be reviewed for spec completeness"
diff --git a/spec/ruby/core/process/sys/setruid_spec.rb b/spec/ruby/core/process/sys/setruid_spec.rb
index 4f40f6666a..9dbd84bf68 100644
--- a/spec/ruby/core/process/sys/setruid_spec.rb
+++ b/spec/ruby/core/process/sys/setruid_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "Process::Sys.setruid" do
it "needs to be reviewed for spec completeness"
diff --git a/spec/ruby/core/process/sys/setuid_spec.rb b/spec/ruby/core/process/sys/setuid_spec.rb
index 13bf072ad1..e06c3588a5 100644
--- a/spec/ruby/core/process/sys/setuid_spec.rb
+++ b/spec/ruby/core/process/sys/setuid_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "Process::Sys.setuid" do
it "needs to be reviewed for spec completeness"
diff --git a/spec/ruby/core/process/times_spec.rb b/spec/ruby/core/process/times_spec.rb
index 01a5595ef9..a7ffbb79e5 100644
--- a/spec/ruby/core/process/times_spec.rb
+++ b/spec/ruby/core/process/times_spec.rb
@@ -1,27 +1,19 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Process.times" do
- it "returns a Struct::Tms" do
- Process.times.should be_kind_of(Struct::Tms)
+ it "returns a Process::Tms" do
+ Process.times.should.is_a?(Process::Tms)
end
- it "returns current cpu times" do
- t = Process.times
+ # TODO: Intel C Compiler does not work this example
+ # http://rubyci.s3.amazonaws.com/icc-x64/ruby-master/log/20221013T030005Z.fail.html.gz
+ unless RbConfig::CONFIG['CC']&.include?("icx")
+ it "returns current cpu times" do
+ t = Process.times
+ user = t.utime
- # Do busy work for a wall-clock interval.
- start = Time.now
- 1 until (Time.now - start) > 0.5
-
- # Ensure times is larger. NOTE that there is no
- # guarantee of an upper bound since anything may be
- # happening at the OS level, so we ONLY check that at
- # least an interval has elapsed. Also, we are assuming
- # there is a correlation between wall clock time and
- # process time. In practice, there is an observed
- # discrepancy often 10% or greater. In other words,
- # this is a very fuzzy test.
- t2 = Process.times
- diff = (t2.utime + t2.stime) - (t.utime + t.stime)
- diff.should > 0
+ 1 until Process.times.utime > user
+ Process.times.utime.should > user
+ end
end
end
diff --git a/spec/ruby/core/process/tms/cstime_spec.rb b/spec/ruby/core/process/tms/cstime_spec.rb
new file mode 100644
index 0000000000..9c2d9e8632
--- /dev/null
+++ b/spec/ruby/core/process/tms/cstime_spec.rb
@@ -0,0 +1,17 @@
+require_relative '../../../spec_helper'
+
+describe "Process::Tms#cstime" do
+ it "returns cstime attribute" do
+ cstime = Object.new
+ Process::Tms.new(nil, nil, nil, cstime).cstime.should == cstime
+ end
+end
+
+describe "Process::Tms#cstime=" do
+ it "assigns a value to the cstime attribute" do
+ cstime = Object.new
+ tms = Process::Tms.new
+ tms.cstime = cstime
+ tms.cstime.should == cstime
+ end
+end
diff --git a/spec/ruby/core/process/tms/cutime_spec.rb b/spec/ruby/core/process/tms/cutime_spec.rb
new file mode 100644
index 0000000000..0ac3ff1964
--- /dev/null
+++ b/spec/ruby/core/process/tms/cutime_spec.rb
@@ -0,0 +1,17 @@
+require_relative '../../../spec_helper'
+
+describe "Process::Tms#cutime" do
+ it "returns cutime attribute" do
+ cutime = Object.new
+ Process::Tms.new(nil, nil, cutime, nil).cutime.should == cutime
+ end
+end
+
+describe "Process::Tms#cutime=" do
+ it "assigns a value to the cutime attribute" do
+ cutime = Object.new
+ tms = Process::Tms.new
+ tms.cutime = cutime
+ tms.cutime.should == cutime
+ end
+end
diff --git a/spec/ruby/core/process/tms/stime_spec.rb b/spec/ruby/core/process/tms/stime_spec.rb
new file mode 100644
index 0000000000..1e8371475f
--- /dev/null
+++ b/spec/ruby/core/process/tms/stime_spec.rb
@@ -0,0 +1,17 @@
+require_relative '../../../spec_helper'
+
+describe "Process::Tms#stime" do
+ it "returns stime attribute" do
+ stime = Object.new
+ Process::Tms.new(nil, stime, nil, nil).stime.should == stime
+ end
+end
+
+describe "Process::Tms#stime=" do
+ it "assigns a value to the stime attribute" do
+ stime = Object.new
+ tms = Process::Tms.new
+ tms.stime = stime
+ tms.stime.should == stime
+ end
+end
diff --git a/spec/ruby/core/process/tms/utime_spec.rb b/spec/ruby/core/process/tms/utime_spec.rb
new file mode 100644
index 0000000000..403a31e2e6
--- /dev/null
+++ b/spec/ruby/core/process/tms/utime_spec.rb
@@ -0,0 +1,17 @@
+require_relative '../../../spec_helper'
+
+describe "Process::Tms#utime" do
+ it "returns utime attribute" do
+ utime = Object.new
+ Process::Tms.new(utime, nil, nil, nil).utime.should == utime
+ end
+end
+
+describe "Process::Tms#utime=" do
+ it "assigns a value to the ctime attribute" do
+ utime = Object.new
+ tms = Process::Tms.new
+ tms.utime = utime
+ tms.utime.should == utime
+ end
+end
diff --git a/spec/ruby/core/process/uid/change_privilege_spec.rb b/spec/ruby/core/process/uid/change_privilege_spec.rb
index 91a38bfcdf..e4b552dd94 100644
--- a/spec/ruby/core/process/uid/change_privilege_spec.rb
+++ b/spec/ruby/core/process/uid/change_privilege_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "Process::UID.change_privilege" do
it "needs to be reviewed for spec completeness"
diff --git a/spec/ruby/core/process/uid/eid_spec.rb b/spec/ruby/core/process/uid/eid_spec.rb
index 39fcd13d93..f0bb9ce762 100644
--- a/spec/ruby/core/process/uid/eid_spec.rb
+++ b/spec/ruby/core/process/uid/eid_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "Process::UID.eid" do
it "needs to be reviewed for spec completeness"
diff --git a/spec/ruby/core/process/uid/grant_privilege_spec.rb b/spec/ruby/core/process/uid/grant_privilege_spec.rb
index c4d3443de8..2b8a5c9102 100644
--- a/spec/ruby/core/process/uid/grant_privilege_spec.rb
+++ b/spec/ruby/core/process/uid/grant_privilege_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "Process::UID.grant_privilege" do
it "needs to be reviewed for spec completeness"
diff --git a/spec/ruby/core/process/uid/re_exchange_spec.rb b/spec/ruby/core/process/uid/re_exchange_spec.rb
index 2f9b0d6a87..c0f10f33c4 100644
--- a/spec/ruby/core/process/uid/re_exchange_spec.rb
+++ b/spec/ruby/core/process/uid/re_exchange_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "Process::UID.re_exchange" do
it "needs to be reviewed for spec completeness"
diff --git a/spec/ruby/core/process/uid/re_exchangeable_spec.rb b/spec/ruby/core/process/uid/re_exchangeable_spec.rb
index 63f45fa662..8200d7ecb7 100644
--- a/spec/ruby/core/process/uid/re_exchangeable_spec.rb
+++ b/spec/ruby/core/process/uid/re_exchangeable_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "Process::UID.re_exchangeable?" do
it "needs to be reviewed for spec completeness"
diff --git a/spec/ruby/core/process/uid/rid_spec.rb b/spec/ruby/core/process/uid/rid_spec.rb
index cdfe08e3be..e865cbfef6 100644
--- a/spec/ruby/core/process/uid/rid_spec.rb
+++ b/spec/ruby/core/process/uid/rid_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "Process::UID.rid" do
it "needs to be reviewed for spec completeness"
diff --git a/spec/ruby/core/process/uid/sid_available_spec.rb b/spec/ruby/core/process/uid/sid_available_spec.rb
index 5d51366dd4..be7912eb68 100644
--- a/spec/ruby/core/process/uid/sid_available_spec.rb
+++ b/spec/ruby/core/process/uid/sid_available_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "Process::UID.sid_available?" do
it "needs to be reviewed for spec completeness"
diff --git a/spec/ruby/core/process/uid/switch_spec.rb b/spec/ruby/core/process/uid/switch_spec.rb
index 6747ee4f43..4191b97db4 100644
--- a/spec/ruby/core/process/uid/switch_spec.rb
+++ b/spec/ruby/core/process/uid/switch_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "Process::UID.switch" do
it "needs to be reviewed for spec completeness"
diff --git a/spec/ruby/core/process/uid_spec.rb b/spec/ruby/core/process/uid_spec.rb
index 1b561f47e0..1e218ef4fe 100644
--- a/spec/ruby/core/process/uid_spec.rb
+++ b/spec/ruby/core/process/uid_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Process.uid" do
platform_is_not :windows do
@@ -18,67 +18,40 @@ describe "Process.uid" do
end
describe "Process.uid=" do
-
platform_is_not :windows do
it "raises TypeError if not passed an Integer" do
- lambda { Process.uid = Object.new }.should raise_error(TypeError)
+ -> { Process.uid = Object.new }.should.raise(TypeError)
end
as_user do
it "raises Errno::ERPERM if run by a non privileged user trying to set the superuser id" do
- lambda { (Process.uid = 0)}.should raise_error(Errno::EPERM)
+ -> { (Process.uid = 0)}.should.raise(Errno::EPERM)
end
it "raises Errno::ERPERM if run by a non privileged user trying to set the superuser id from username" do
- lambda { Process.uid = "root" }.should raise_error(Errno::EPERM)
+ -> { Process.uid = "root" }.should.raise(Errno::EPERM)
end
end
as_superuser do
describe "if run by a superuser" do
- with_feature :fork do
- it "sets the real user id for the current process" do
- read, write = IO.pipe
- pid = Process.fork do
- begin
- read.close
- Process.uid = 1
- write << Process.uid
- write.close
- rescue Exception => e
- write << e << e.backtrace
- end
- Process.exit!
- end
- write.close
- uid = read.gets
- uid.should == "1"
- Process.wait pid
- end
+ it "sets the real user id for the current process" do
+ code = <<-RUBY
+ Process.uid = 1
+ puts Process.uid
+ RUBY
+ ruby_exe(code).should == "1\n"
+ end
- it "sets the real user id if preceded by Process.euid=id" do
- read, write = IO.pipe
- pid = Process.fork do
- begin
- read.close
- Process.euid = 1
- Process.uid = 1
- write << Process.uid
- write.close
- rescue Exception => e
- write << e << e.backtrace
- end
- Process.exit!
- end
- write.close
- uid = read.gets
- uid.should == "1"
- Process.wait pid
- end
+ it "sets the real user id if preceded by Process.euid=id" do
+ code = <<-RUBY
+ Process.euid = 1
+ Process.uid = 1
+ puts Process.uid
+ RUBY
+ ruby_exe(code).should == "1\n"
end
end
end
end
-
- it "needs to be reviewed for spec completeness"
end
diff --git a/spec/ruby/core/process/wait2_spec.rb b/spec/ruby/core/process/wait2_spec.rb
index d1f3a47b7f..1fa6f76151 100644
--- a/spec/ruby/core/process/wait2_spec.rb
+++ b/spec/ruby/core/process/wait2_spec.rb
@@ -1,32 +1,46 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/common'
describe "Process.wait2" do
+ ProcessSpecs.use_system_ruby(self)
+
before :all do
# HACK: this kludge is temporarily necessary because some
# misbehaving spec somewhere else does not clear processes
+ # Note: background processes are unavoidable with RJIT,
+ # but we shouldn't reap them from Ruby-space
begin
Process.wait(-1, Process::WNOHANG)
$stderr.puts "Leaked process before wait2 specs! Waiting for it"
leaked = Process.waitall
- $stderr.puts "leaked before wait2 specs: #{leaked}"
+ $stderr.puts "leaked before wait2 specs: #{leaked}" unless leaked.empty?
+ # Ruby-space should not see PIDs used by rjit
+ leaked.should.empty?
rescue Errno::ECHILD # No child processes
rescue NotImplementedError
end
end
- platform_is_not :windows do
- it "returns the pid and status of child process" do
- pidf = Process.fork { Process.exit! 99 }
- results = Process.wait2
- results.size.should == 2
- pidw, status = results
- pidf.should == pidw
- status.exitstatus.should == 99
- end
+ it "returns the pid and status of child process" do
+ pidf = Process.spawn(*ruby_exe, "-e", "exit 99")
+ results = Process.wait2
+ results.size.should == 2
+ pidw, status = results
+ pidf.should == pidw
+ status.exitstatus.should == 99
end
it "raises a StandardError if no child processes exist" do
- lambda { Process.wait2 }.should raise_error(Errno::ECHILD)
- lambda { Process.wait2 }.should raise_error(StandardError)
+ -> { Process.wait2 }.should.raise(Errno::ECHILD)
+ -> { Process.wait2 }.should.raise(StandardError)
+ end
+
+ it "returns nil if the child process is still running when given the WNOHANG flag" do
+ IO.popen(ruby_cmd('STDIN.getbyte'), "w") do |io|
+ pid, status = Process.wait2(io.pid, Process::WNOHANG)
+ pid.should == nil
+ status.should == nil
+ io.write('a')
+ end
end
end
diff --git a/spec/ruby/core/process/wait_spec.rb b/spec/ruby/core/process/wait_spec.rb
index 8111621695..5a1889487c 100644
--- a/spec/ruby/core/process/wait_spec.rb
+++ b/spec/ruby/core/process/wait_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/common', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/common'
describe "Process.wait" do
ProcessSpecs.use_system_ruby(self)
@@ -7,32 +7,44 @@ describe "Process.wait" do
before :all do
begin
leaked = Process.waitall
- puts "leaked before wait specs: #{leaked}" unless leaked.empty?
+ # Ruby-space should not see PIDs used by rjit
+ raise "subprocesses leaked before wait specs: #{leaked}" unless leaked.empty?
rescue NotImplementedError
end
end
it "raises an Errno::ECHILD if there are no child processes" do
- lambda { Process.wait }.should raise_error(Errno::ECHILD)
+ -> { Process.wait }.should.raise(Errno::ECHILD)
end
- platform_is_not :windows do
- it "returns its childs pid" do
- pid = Process.spawn(ruby_cmd('exit'))
- Process.wait.should == pid
- end
+ it "returns its child pid" do
+ pid = Process.spawn(ruby_cmd('exit'))
+ Process.wait.should == pid
+ end
- it "sets $? to a Process::Status" do
- pid = Process.spawn(ruby_cmd('exit'))
- Process.wait
- $?.should be_kind_of(Process::Status)
- $?.pid.should == pid
+ it "returns nil when the process has not yet completed and WNOHANG is specified" do
+ cmd = platform_is(:windows) ? "timeout" : "sleep"
+ pid = spawn("#{cmd} 5")
+ begin
+ Process.wait(pid, Process::WNOHANG).should == nil
+ Process.kill("KILL", pid)
+ ensure
+ Process.wait(pid)
end
+ end
+ it "sets $? to a Process::Status" do
+ pid = Process.spawn(ruby_cmd('exit'))
+ Process.wait
+ $?.should.is_a?(Process::Status)
+ $?.pid.should == pid
+ end
+
+ platform_is_not :windows do
it "waits for any child process if no pid is given" do
pid = Process.spawn(ruby_cmd('exit'))
Process.wait.should == pid
- lambda { Process.kill(0, pid) }.should raise_error(Errno::ESRCH)
+ -> { Process.kill(0, pid) }.should.raise(Errno::ESRCH)
end
it "waits for a specific child if a pid is given" do
@@ -40,14 +52,14 @@ describe "Process.wait" do
pid2 = Process.spawn(ruby_cmd('exit'))
Process.wait(pid2).should == pid2
Process.wait(pid1).should == pid1
- lambda { Process.kill(0, pid1) }.should raise_error(Errno::ESRCH)
- lambda { Process.kill(0, pid2) }.should raise_error(Errno::ESRCH)
+ -> { Process.kill(0, pid1) }.should.raise(Errno::ESRCH)
+ -> { Process.kill(0, pid2) }.should.raise(Errno::ESRCH)
end
it "coerces the pid to an Integer" do
pid1 = Process.spawn(ruby_cmd('exit'))
Process.wait(mock_int(pid1)).should == pid1
- lambda { Process.kill(0, pid1) }.should raise_error(Errno::ESRCH)
+ -> { Process.kill(0, pid1) }.should.raise(Errno::ESRCH)
end
# This spec is probably system-dependent.
@@ -58,8 +70,10 @@ describe "Process.wait" do
Process.wait(0).should == pid2
Process.wait.should == pid1
end
+ end
- # This spec is probably system-dependent.
+ # This spec is probably system-dependent.
+ guard -> { Process.respond_to?(:fork) } do
it "doesn't block if no child is available when WNOHANG is used" do
read, write = IO.pipe
pid = Process.fork do
@@ -70,7 +84,7 @@ describe "Process.wait" do
sleep
end
- Process.wait(pid, Process::WNOHANG).should be_nil
+ Process.wait(pid, Process::WNOHANG).should == nil
# wait for the child to setup its TERM handler
write.close
@@ -80,11 +94,13 @@ describe "Process.wait" do
Process.kill("TERM", pid)
Process.wait.should == pid
end
+ end
+ platform_is_not :windows do
it "always accepts flags=0" do
pid = Process.spawn(ruby_cmd('exit'))
Process.wait(-1, 0).should == pid
- lambda { Process.kill(0, pid) }.should raise_error(Errno::ESRCH)
+ -> { Process.kill(0, pid) }.should.raise(Errno::ESRCH)
end
end
end
diff --git a/spec/ruby/core/process/waitall_spec.rb b/spec/ruby/core/process/waitall_spec.rb
index e1fc38d2bc..f5fbce71c1 100644
--- a/spec/ruby/core/process/waitall_spec.rb
+++ b/spec/ruby/core/process/waitall_spec.rb
@@ -1,6 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/common'
describe "Process.waitall" do
+ ProcessSpecs.use_system_ruby(self)
+
before :all do
begin
Process.waitall
@@ -13,35 +16,28 @@ describe "Process.waitall" do
end
it "takes no arguments" do
- lambda { Process.waitall(0) }.should raise_error(ArgumentError)
+ -> { Process.waitall(0) }.should.raise(ArgumentError)
end
platform_is_not :windows do
- it "waits for all children" do
+ it "waits for all children and returns an array of pid/status pairs" do
pids = []
- pids << Process.fork { Process.exit! 2 }
- pids << Process.fork { Process.exit! 1 }
- pids << Process.fork { Process.exit! 0 }
- Process.waitall
+ pids << Process.spawn(ruby_cmd('exit 2'))
+ pids << Process.spawn(ruby_cmd('exit 1'))
+ pids << Process.spawn(ruby_cmd('exit 0'))
+ a = Process.waitall
pids.each { |pid|
- lambda { Process.kill(0, pid) }.should raise_error(Errno::ESRCH)
+ -> { Process.kill(0, pid) }.should.raise(Errno::ESRCH)
}
- end
- it "returns an array of pid/status pairs" do
- pids = []
- pids << Process.fork { Process.exit! 2 }
- pids << Process.fork { Process.exit! 1 }
- pids << Process.fork { Process.exit! 0 }
- a = Process.waitall
- a.should be_kind_of(Array)
+ a.should.is_a?(Array)
a.size.should == 3
pids.each { |pid|
pid_status = a.assoc(pid)
- pid_status.should be_kind_of(Array)
+ pid_status.should.is_a?(Array)
pid_status.size.should == 2
pid_status.first.should == pid
- pid_status.last.should be_kind_of(Process::Status)
+ pid_status.last.should.is_a?(Process::Status)
}
end
end
diff --git a/spec/ruby/core/process/waitpid2_spec.rb b/spec/ruby/core/process/waitpid2_spec.rb
index 303c59fda3..70fe0fbeee 100644
--- a/spec/ruby/core/process/waitpid2_spec.rb
+++ b/spec/ruby/core/process/waitpid2_spec.rb
@@ -1,5 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Process.waitpid2" do
- it "needs to be reviewed for spec completeness"
+ it "is an alias of Process.wait2" do
+ Process.method(:waitpid2).should == Process.method(:wait2)
+ end
end
diff --git a/spec/ruby/core/process/waitpid_spec.rb b/spec/ruby/core/process/waitpid_spec.rb
index c95e8d59dd..9b2f49e7cf 100644
--- a/spec/ruby/core/process/waitpid_spec.rb
+++ b/spec/ruby/core/process/waitpid_spec.rb
@@ -1,15 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Process.waitpid" do
- it "needs to be reviewed for spec completeness"
-
- it "returns nil when the process has not yet completed and WNOHANG is specified" do
- pid = spawn("sleep 5")
- begin
- Process.waitpid(pid, Process::WNOHANG).should == nil
- Process.kill("KILL", pid)
- ensure
- Process.wait(pid)
- end
+ it "is an alias of Process.wait" do
+ Process.method(:waitpid).should == Process.method(:wait)
end
end
diff --git a/spec/ruby/core/process/warmup_spec.rb b/spec/ruby/core/process/warmup_spec.rb
new file mode 100644
index 0000000000..4530ae222c
--- /dev/null
+++ b/spec/ruby/core/process/warmup_spec.rb
@@ -0,0 +1,9 @@
+require_relative '../../spec_helper'
+
+describe "Process.warmup" do
+ # The behavior is entirely implementation specific.
+ # Other implementations are free to just make it a noop
+ it "is implemented" do
+ Process.warmup.should == true
+ end
+end
diff --git a/spec/ruby/core/queue/append_spec.rb b/spec/ruby/core/queue/append_spec.rb
new file mode 100644
index 0000000000..34165a7506
--- /dev/null
+++ b/spec/ruby/core/queue/append_spec.rb
@@ -0,0 +1,6 @@
+require_relative '../../spec_helper'
+require_relative '../../shared/queue/enque'
+
+describe "Queue#<<" do
+ it_behaves_like :queue_enq, :<<, -> { Queue.new }
+end
diff --git a/spec/ruby/core/queue/clear_spec.rb b/spec/ruby/core/queue/clear_spec.rb
new file mode 100644
index 0000000000..3245e4cb83
--- /dev/null
+++ b/spec/ruby/core/queue/clear_spec.rb
@@ -0,0 +1,6 @@
+require_relative '../../spec_helper'
+require_relative '../../shared/queue/clear'
+
+describe "Queue#clear" do
+ it_behaves_like :queue_clear, :clear, -> { Queue.new }
+end
diff --git a/spec/ruby/core/queue/close_spec.rb b/spec/ruby/core/queue/close_spec.rb
new file mode 100644
index 0000000000..c0d774cd74
--- /dev/null
+++ b/spec/ruby/core/queue/close_spec.rb
@@ -0,0 +1,6 @@
+require_relative '../../spec_helper'
+require_relative '../../shared/queue/close'
+
+describe "Queue#close" do
+ it_behaves_like :queue_close, :close, -> { Queue.new }
+end
diff --git a/spec/ruby/core/queue/closed_spec.rb b/spec/ruby/core/queue/closed_spec.rb
new file mode 100644
index 0000000000..10d552996d
--- /dev/null
+++ b/spec/ruby/core/queue/closed_spec.rb
@@ -0,0 +1,6 @@
+require_relative '../../spec_helper'
+require_relative '../../shared/queue/closed'
+
+describe "Queue#closed?" do
+ it_behaves_like :queue_closed?, :closed?, -> { Queue.new }
+end
diff --git a/spec/ruby/core/queue/deq_spec.rb b/spec/ruby/core/queue/deq_spec.rb
new file mode 100644
index 0000000000..374611366e
--- /dev/null
+++ b/spec/ruby/core/queue/deq_spec.rb
@@ -0,0 +1,7 @@
+require_relative '../../spec_helper'
+
+describe "Queue#deq" do
+ it "is an alias of Queue#pop" do
+ Queue.instance_method(:deq).should == Queue.instance_method(:pop)
+ end
+end
diff --git a/spec/ruby/core/queue/empty_spec.rb b/spec/ruby/core/queue/empty_spec.rb
new file mode 100644
index 0000000000..55ca777466
--- /dev/null
+++ b/spec/ruby/core/queue/empty_spec.rb
@@ -0,0 +1,6 @@
+require_relative '../../spec_helper'
+require_relative '../../shared/queue/empty'
+
+describe "Queue#empty?" do
+ it_behaves_like :queue_empty?, :empty?, -> { Queue.new }
+end
diff --git a/spec/ruby/core/queue/enq_spec.rb b/spec/ruby/core/queue/enq_spec.rb
new file mode 100644
index 0000000000..76ecf0ca5f
--- /dev/null
+++ b/spec/ruby/core/queue/enq_spec.rb
@@ -0,0 +1,7 @@
+require_relative '../../spec_helper'
+
+describe "Queue#enq" do
+ it "is an alias of Queue#<<" do
+ Queue.instance_method(:enq).should == Queue.instance_method(:<<)
+ end
+end
diff --git a/spec/ruby/core/queue/freeze_spec.rb b/spec/ruby/core/queue/freeze_spec.rb
new file mode 100644
index 0000000000..ced2cc52dd
--- /dev/null
+++ b/spec/ruby/core/queue/freeze_spec.rb
@@ -0,0 +1,6 @@
+require_relative '../../spec_helper'
+require_relative '../../shared/queue/freeze'
+
+describe "Queue#freeze" do
+ it_behaves_like :queue_freeze, :freeze, -> { Queue.new }
+end
diff --git a/spec/ruby/core/queue/initialize_spec.rb b/spec/ruby/core/queue/initialize_spec.rb
new file mode 100644
index 0000000000..080e4d0abd
--- /dev/null
+++ b/spec/ruby/core/queue/initialize_spec.rb
@@ -0,0 +1,60 @@
+require_relative '../../spec_helper'
+
+describe "Queue#initialize" do
+ it "can be passed no arguments for an empty Queue" do
+ q = Queue.new
+ q.size.should == 0
+ q.should.empty?
+ end
+
+ it "is a private method" do
+ Queue.private_instance_methods.include?(:initialize).should == true
+ end
+
+ it "adds all elements of the passed Enumerable to self" do
+ q = Queue.new([1, 2, 3])
+ q.size.should == 3
+ q.should_not.empty?
+ q.pop.should == 1
+ q.pop.should == 2
+ q.pop.should == 3
+ q.should.empty?
+ end
+
+ describe "converts the given argument to an Array using #to_a" do
+ it "uses #to_a on the provided Enumerable" do
+ enumerable = MockObject.new('mock-enumerable')
+ enumerable.should_receive(:to_a).and_return([1, 2, 3])
+ q = Queue.new(enumerable)
+ q.size.should == 3
+ q.should_not.empty?
+ q.pop.should == 1
+ q.pop.should == 2
+ q.pop.should == 3
+ q.should.empty?
+ end
+
+ it "raises a TypeError if the given argument can't be converted to an Array" do
+ -> { Queue.new(42) }.should.raise(TypeError)
+ -> { Queue.new(:abc) }.should.raise(TypeError)
+ end
+
+ it "raises a NoMethodError if the given argument raises a NoMethodError during type coercion to an Array" do
+ enumerable = MockObject.new('mock-enumerable')
+ enumerable.should_receive(:to_a).and_raise(NoMethodError)
+ -> { Queue.new(enumerable) }.should.raise(NoMethodError)
+ end
+ end
+
+ it "raises TypeError if the provided Enumerable does not respond to #to_a" do
+ enumerable = MockObject.new('mock-enumerable')
+ -> { Queue.new(enumerable) }.should.raise(TypeError, "can't convert MockObject into Array")
+ end
+
+ it "raises TypeError if #to_a does not return Array" do
+ enumerable = MockObject.new('mock-enumerable')
+ enumerable.should_receive(:to_a).and_return("string")
+
+ -> { Queue.new(enumerable) }.should raise_consistent_error(TypeError, "can't convert MockObject into Array (MockObject#to_a gives String)")
+ end
+end
diff --git a/spec/ruby/core/queue/length_spec.rb b/spec/ruby/core/queue/length_spec.rb
new file mode 100644
index 0000000000..0566b1d547
--- /dev/null
+++ b/spec/ruby/core/queue/length_spec.rb
@@ -0,0 +1,7 @@
+require_relative '../../spec_helper'
+
+describe "Queue#length" do
+ it "is an alias of Queue#size" do
+ Queue.instance_method(:length).should == Queue.instance_method(:size)
+ end
+end
diff --git a/spec/ruby/core/queue/num_waiting_spec.rb b/spec/ruby/core/queue/num_waiting_spec.rb
new file mode 100644
index 0000000000..edc0c37a82
--- /dev/null
+++ b/spec/ruby/core/queue/num_waiting_spec.rb
@@ -0,0 +1,6 @@
+require_relative '../../spec_helper'
+require_relative '../../shared/queue/num_waiting'
+
+describe "Queue#num_waiting" do
+ it_behaves_like :queue_num_waiting, :num_waiting, -> { Queue.new }
+end
diff --git a/spec/ruby/core/queue/pop_spec.rb b/spec/ruby/core/queue/pop_spec.rb
new file mode 100644
index 0000000000..3dff7db242
--- /dev/null
+++ b/spec/ruby/core/queue/pop_spec.rb
@@ -0,0 +1,11 @@
+require_relative '../../spec_helper'
+require_relative '../../shared/queue/deque'
+require_relative '../../shared/types/rb_num2dbl_fails'
+
+describe "Queue#pop" do
+ it_behaves_like :queue_deq, :pop, -> { Queue.new }
+end
+
+describe "Queue operations with timeout" do
+ it_behaves_like :rb_num2dbl_fails, nil, -> v { q = Queue.new; q.push(1); q.pop(timeout: v) }
+end
diff --git a/spec/ruby/core/queue/push_spec.rb b/spec/ruby/core/queue/push_spec.rb
new file mode 100644
index 0000000000..ef622ac89d
--- /dev/null
+++ b/spec/ruby/core/queue/push_spec.rb
@@ -0,0 +1,7 @@
+require_relative '../../spec_helper'
+
+describe "Queue#push" do
+ it "is an alias of Queue#<<" do
+ Queue.instance_method(:push).should == Queue.instance_method(:<<)
+ end
+end
diff --git a/spec/ruby/core/queue/shift_spec.rb b/spec/ruby/core/queue/shift_spec.rb
new file mode 100644
index 0000000000..074332359c
--- /dev/null
+++ b/spec/ruby/core/queue/shift_spec.rb
@@ -0,0 +1,7 @@
+require_relative '../../spec_helper'
+
+describe "Queue#shift" do
+ it "is an alias of Queue#pop" do
+ Queue.instance_method(:shift).should == Queue.instance_method(:pop)
+ end
+end
diff --git a/spec/ruby/core/queue/size_spec.rb b/spec/ruby/core/queue/size_spec.rb
new file mode 100644
index 0000000000..f528dfe797
--- /dev/null
+++ b/spec/ruby/core/queue/size_spec.rb
@@ -0,0 +1,6 @@
+require_relative '../../spec_helper'
+require_relative '../../shared/queue/length'
+
+describe "Queue#size" do
+ it_behaves_like :queue_length, :size, -> { Queue.new }
+end
diff --git a/spec/ruby/core/random/bytes_spec.rb b/spec/ruby/core/random/bytes_spec.rb
index d954261329..c9be07cd3f 100644
--- a/spec/ruby/core/random/bytes_spec.rb
+++ b/spec/ruby/core/random/bytes_spec.rb
@@ -1,24 +1,14 @@
-# -*- encoding: binary -*-
-require File.expand_path('../../../spec_helper', __FILE__)
+# encoding: binary
+require_relative '../../spec_helper'
+require_relative 'shared/bytes'
describe "Random#bytes" do
- it "returns a String" do
- Random.new.bytes(1).should be_an_instance_of(String)
- end
-
- it "returns a String of the length given as argument" do
- Random.new.bytes(15).length.should == 15
- end
-
- it "returns an ASCII-8BIT String" do
- Random.new.bytes(15).encoding.should == Encoding::ASCII_8BIT
- end
+ it_behaves_like :random_bytes, :bytes, Random.new
it "returns the same output for a given seed" do
Random.new(33).bytes(2).should == Random.new(33).bytes(2)
end
- # Should double check this is official spec
it "returns the same numeric output for a given seed across all implementations and platforms" do
rnd = Random.new(33)
rnd.bytes(2).should == "\x14\\"
@@ -27,13 +17,13 @@ describe "Random#bytes" do
end
it "returns the same numeric output for a given huge seed across all implementations and platforms" do
- rnd = Random.new(bignum_value ** 4)
+ rnd = Random.new(2 ** (63 * 4))
rnd.bytes(2).should == "_\x91"
rnd.bytes(1000) # skip some
rnd.bytes(2).should == "\x17\x12"
end
+end
- it "returns a random binary String" do
- Random.new.bytes(12).should_not == Random.new.bytes(12)
- end
+describe "Random.bytes" do
+ it_behaves_like :random_bytes, :bytes, Random
end
diff --git a/spec/ruby/core/random/default_spec.rb b/spec/ruby/core/random/default_spec.rb
index 51a76c01ce..9e4845986d 100644
--- a/spec/ruby/core/random/default_spec.rb
+++ b/spec/ruby/core/random/default_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Random::DEFAULT" do
- it "returns a Random instance" do
- Random::DEFAULT.should be_an_instance_of(Random)
+ it "is no longer defined" do
+ Random.should_not.const_defined?(:DEFAULT)
end
end
diff --git a/spec/ruby/core/random/equal_value_spec.rb b/spec/ruby/core/random/equal_value_spec.rb
index 738f549f1d..5f470d6a4c 100644
--- a/spec/ruby/core/random/equal_value_spec.rb
+++ b/spec/ruby/core/random/equal_value_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Random#==" do
it "returns true if the two objects have the same state" do
diff --git a/spec/ruby/core/random/fixtures/classes.rb b/spec/ruby/core/random/fixtures/classes.rb
new file mode 100644
index 0000000000..9c8d113e24
--- /dev/null
+++ b/spec/ruby/core/random/fixtures/classes.rb
@@ -0,0 +1,15 @@
+module RandomSpecs
+ CustomRangeInteger = Struct.new(:value) do
+ def to_int; value; end
+ def <=>(other); to_int <=> other.to_int; end
+ def -(other); self.class.new(to_int - other.to_int); end
+ def +(other); self.class.new(to_int + other.to_int); end
+ end
+
+ CustomRangeFloat = Struct.new(:value) do
+ def to_f; value; end
+ def <=>(other); to_f <=> other.to_f; end
+ def -(other); to_f - other.to_f; end
+ def +(other); self.class.new(to_f + other.to_f); end
+ end
+end
diff --git a/spec/ruby/core/random/new_seed_spec.rb b/spec/ruby/core/random/new_seed_spec.rb
index a8efaee2b1..b2741aaa31 100644
--- a/spec/ruby/core/random/new_seed_spec.rb
+++ b/spec/ruby/core/random/new_seed_spec.rb
@@ -1,8 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Random.new_seed" do
- it "returns a Bignum" do
- Random.new_seed.should be_an_instance_of(Bignum)
+ it "returns an Integer" do
+ Random.new_seed.should.instance_of?(Integer)
end
it "returns an arbitrary seed value each time" do
diff --git a/spec/ruby/core/random/new_spec.rb b/spec/ruby/core/random/new_spec.rb
index 8160f44d79..e20d487137 100644
--- a/spec/ruby/core/random/new_spec.rb
+++ b/spec/ruby/core/random/new_spec.rb
@@ -1,16 +1,17 @@
+require_relative "../../spec_helper"
describe "Random.new" do
it "returns a new instance of Random" do
- Random.new.should be_an_instance_of(Random)
+ Random.new.should.instance_of?(Random)
end
it "uses a random seed value if none is supplied" do
- Random.new.seed.should be_an_instance_of(Bignum)
+ Random.new.seed.should.instance_of?(Integer)
end
it "returns Random instances initialized with different seeds" do
first = Random.new
second = Random.new
- (0..20).map { first.rand } .should_not == (0..20).map { second.rand }
+ (0..20).map { first.rand }.should_not == (0..20).map { second.rand }
end
it "accepts an Integer seed value as an argument" do
@@ -30,8 +31,8 @@ describe "Random.new" do
end
it "raises a RangeError if passed a Complex (with imaginary part) seed value as an argument" do
- lambda do
+ -> do
Random.new(Complex(20,2))
- end.should raise_error(RangeError)
+ end.should.raise(RangeError)
end
end
diff --git a/spec/ruby/core/random/rand_spec.rb b/spec/ruby/core/random/rand_spec.rb
index e0cb133abd..c882db6381 100644
--- a/spec/ruby/core/random/rand_spec.rb
+++ b/spec/ruby/core/random/rand_spec.rb
@@ -1,9 +1,10 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/rand'
describe "Random.rand" do
- it "returns a Float if no max argument is passed" do
- Random.rand.should be_kind_of(Float)
- end
+ it_behaves_like :random_number, :rand, Random.new
+ it_behaves_like :random_number, :rand, Random
it "returns a Float >= 0 if no max argument is passed" do
floats = 200.times.map { Random.rand }
@@ -23,10 +24,6 @@ describe "Random.rand" do
floats_a.should == floats_b
end
- it "returns an Integer if an Integer argument is passed" do
- Random.rand(20).should be_kind_of(Integer)
- end
-
it "returns an Integer >= 0 if an Integer argument is passed" do
ints = 200.times.map { Random.rand(34) }
ints.min.should >= 0
@@ -48,13 +45,13 @@ describe "Random.rand" do
it "coerces arguments to Integers with #to_int" do
obj = mock_numeric('int')
obj.should_receive(:to_int).and_return(99)
- Random.rand(obj).should be_kind_of(Integer)
+ Random.rand(obj).should.is_a?(Integer)
end
end
describe "Random#rand with Fixnum" do
it "returns an Integer" do
- Random.new.rand(20).should be_an_instance_of(Fixnum)
+ Random.new.rand(20).should.instance_of?(Integer)
end
it "returns a Fixnum greater than or equal to 0" do
@@ -83,22 +80,22 @@ describe "Random#rand with Fixnum" do
end
it "raises an ArgumentError when the argument is 0" do
- lambda do
+ -> do
Random.new.rand(0)
- end.should raise_error(ArgumentError)
+ end.should.raise(ArgumentError)
end
it "raises an ArgumentError when the argument is negative" do
- lambda do
+ -> do
Random.new.rand(-12)
- end.should raise_error(ArgumentError)
+ end.should.raise(ArgumentError)
end
end
describe "Random#rand with Bignum" do
it "typically returns a Bignum" do
rnd = Random.new(1)
- 10.times.map{ rnd.rand(bignum_value*2) }.max.should be_an_instance_of(Bignum)
+ 10.times.map{ rnd.rand(bignum_value*2) }.max.should.instance_of?(Integer)
end
it "returns a Bignum greater than or equal to 0" do
@@ -122,15 +119,15 @@ describe "Random#rand with Bignum" do
end
it "raises an ArgumentError when the argument is negative" do
- lambda do
+ -> do
Random.new.rand(-bignum_value)
- end.should raise_error(ArgumentError)
+ end.should.raise(ArgumentError)
end
end
describe "Random#rand with Float" do
it "returns a Float" do
- Random.new.rand(20.43).should be_an_instance_of(Float)
+ Random.new.rand(20.43).should.instance_of?(Float)
end
it "returns a Float greater than or equal to 0.0" do
@@ -154,21 +151,27 @@ describe "Random#rand with Float" do
end
it "raises an ArgumentError when the argument is negative" do
- lambda do
+ -> do
Random.new.rand(-1.234567)
- end.should raise_error(ArgumentError)
+ end.should.raise(ArgumentError)
end
end
describe "Random#rand with Range" do
it "returns an element from the Range" do
- Random.new.rand(20..43).should be_an_instance_of(Fixnum)
+ Random.new.rand(20..43).should.instance_of?(Integer)
+ end
+
+ it "supports custom object types" do
+ rand(RandomSpecs::CustomRangeInteger.new(1)..RandomSpecs::CustomRangeInteger.new(42)).should.instance_of?(RandomSpecs::CustomRangeInteger)
+ rand(RandomSpecs::CustomRangeFloat.new(1.0)..RandomSpecs::CustomRangeFloat.new(42.0)).should.instance_of?(RandomSpecs::CustomRangeFloat)
+ rand(Time.now..Time.now).should.instance_of?(Time)
end
it "returns an object that is a member of the Range" do
prng = Random.new
r = 20..30
- 20.times { r.member?(prng.rand(r)).should be_true }
+ 20.times { r.member?(prng.rand(r)).should == true }
end
it "works with inclusive ranges" do
@@ -198,19 +201,24 @@ describe "Random#rand with Range" do
end
it "considers Integers as Floats if one end point is a float" do
- Random.new(42).rand(0.0..1).should be_kind_of(Float)
- Random.new(42).rand(0..1.0).should be_kind_of(Float)
+ Random.new(42).rand(0.0..1).should.is_a?(Float)
+ Random.new(42).rand(0..1.0).should.is_a?(Float)
+ end
+
+ it "returns a float within a given float range" do
+ Random.new(42).rand(0.0...100.0).should == 37.454011884736246
+ Random.new(42).rand(-100.0...0.0).should == -62.545988115263754
end
it "raises an ArgumentError when the startpoint lacks #+ and #- methods" do
- lambda do
+ -> do
Random.new.rand(Object.new..67)
- end.should raise_error(ArgumentError)
+ end.should.raise(ArgumentError)
end
it "raises an ArgumentError when the endpoint lacks #+ and #- methods" do
- lambda do
+ -> do
Random.new.rand(68..Object.new)
- end.should raise_error(ArgumentError)
+ end.should.raise(ArgumentError)
end
end
diff --git a/spec/ruby/core/random/random_number_spec.rb b/spec/ruby/core/random/random_number_spec.rb
new file mode 100644
index 0000000000..bad81aeff6
--- /dev/null
+++ b/spec/ruby/core/random/random_number_spec.rb
@@ -0,0 +1,8 @@
+require_relative '../../spec_helper'
+require_relative 'shared/rand'
+
+describe "Random.random_number" do
+ it_behaves_like :random_number, :random_number, Random.new
+
+ it_behaves_like :random_number, :random_number, Random
+end
diff --git a/spec/ruby/core/random/raw_seed_spec.rb b/spec/ruby/core/random/raw_seed_spec.rb
deleted file mode 100644
index 881cceada9..0000000000
--- a/spec/ruby/core/random/raw_seed_spec.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-# -*- encoding: binary -*-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/urandom', __FILE__)
-
-ruby_version_is "2.5" do
- describe "Random.urandom" do
- it_behaves_like :random_urandom, :urandom
- end
-end
diff --git a/spec/ruby/core/random/seed_spec.rb b/spec/ruby/core/random/seed_spec.rb
index 5acb068efe..6529b2c873 100644
--- a/spec/ruby/core/random/seed_spec.rb
+++ b/spec/ruby/core/random/seed_spec.rb
@@ -1,8 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Random#seed" do
it "returns an Integer" do
- Random.new.seed.should be_kind_of(Integer)
+ Random.new.seed.should.is_a?(Integer)
end
it "returns an arbitrary seed if the constructor was called without arguments" do
diff --git a/spec/ruby/core/random/shared/bytes.rb b/spec/ruby/core/random/shared/bytes.rb
new file mode 100644
index 0000000000..86c64d5696
--- /dev/null
+++ b/spec/ruby/core/random/shared/bytes.rb
@@ -0,0 +1,17 @@
+describe :random_bytes, shared: true do
+ it "returns a String" do
+ @object.send(@method, 1).should.instance_of?(String)
+ end
+
+ it "returns a String of the length given as argument" do
+ @object.send(@method, 15).length.should == 15
+ end
+
+ it "returns a binary String" do
+ @object.send(@method, 15).encoding.should == Encoding::BINARY
+ end
+
+ it "returns a random binary String" do
+ @object.send(@method, 12).should_not == @object.send(@method, 12)
+ end
+end
diff --git a/spec/ruby/core/random/shared/rand.rb b/spec/ruby/core/random/shared/rand.rb
new file mode 100644
index 0000000000..655c75c9f1
--- /dev/null
+++ b/spec/ruby/core/random/shared/rand.rb
@@ -0,0 +1,9 @@
+describe :random_number, shared: true do
+ it "returns a Float if no max argument is passed" do
+ @object.send(@method).should.is_a?(Float)
+ end
+
+ it "returns an Integer if an Integer argument is passed" do
+ @object.send(@method, 20).should.is_a?(Integer)
+ end
+end
diff --git a/spec/ruby/core/random/shared/urandom.rb b/spec/ruby/core/random/shared/urandom.rb
deleted file mode 100644
index f50d30c9de..0000000000
--- a/spec/ruby/core/random/shared/urandom.rb
+++ /dev/null
@@ -1,23 +0,0 @@
-describe :random_urandom, shared: true do
- it "returns a String" do
- Random.send(@method, 1).should be_an_instance_of(String)
- end
-
- it "returns a String of the length given as argument" do
- Random.send(@method, 15).length.should == 15
- end
-
- it "raises an ArgumentError on a negative size" do
- lambda {
- Random.send(@method, -1)
- }.should raise_error(ArgumentError)
- end
-
- it "returns an ASCII-8BIT String" do
- Random.send(@method, 15).encoding.should == Encoding::ASCII_8BIT
- end
-
- it "returns a random binary String" do
- Random.send(@method, 12).should_not == Random.send(@method, 12)
- end
-end
diff --git a/spec/ruby/core/random/srand_spec.rb b/spec/ruby/core/random/srand_spec.rb
index 8ce863f5a9..1ef8e32cfb 100644
--- a/spec/ruby/core/random/srand_spec.rb
+++ b/spec/ruby/core/random/srand_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Random.srand" do
it "returns an arbitrary seed if .srand wasn't called previously with an argument and no argument is supplied this time" do
diff --git a/spec/ruby/core/random/urandom_spec.rb b/spec/ruby/core/random/urandom_spec.rb
index 1cc0103e35..94e9423a06 100644
--- a/spec/ruby/core/random/urandom_spec.rb
+++ b/spec/ruby/core/random/urandom_spec.rb
@@ -1,9 +1,25 @@
-# -*- encoding: binary -*-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/urandom', __FILE__)
+require_relative '../../spec_helper'
-ruby_version_is "2.3"..."2.5" do
- describe "Random.raw_seed" do
- it_behaves_like :random_urandom, :raw_seed
+describe "Random.urandom" do
+ it "returns a String" do
+ Random.urandom(1).should.instance_of?(String)
+ end
+
+ it "returns a String of the length given as argument" do
+ Random.urandom(15).length.should == 15
+ end
+
+ it "raises an ArgumentError on a negative size" do
+ -> {
+ Random.urandom(-1)
+ }.should.raise(ArgumentError)
+ end
+
+ it "returns a binary String" do
+ Random.urandom(15).encoding.should == Encoding::BINARY
+ end
+
+ it "returns a random binary String" do
+ Random.urandom(12).should_not == Random.urandom(12)
end
end
diff --git a/spec/ruby/core/range/begin_spec.rb b/spec/ruby/core/range/begin_spec.rb
index 090ae0a24b..ab82b45b7e 100644
--- a/spec/ruby/core/range/begin_spec.rb
+++ b/spec/ruby/core/range/begin_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/begin', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/begin'
describe "Range#begin" do
- it_behaves_like(:range_begin, :begin)
+ it_behaves_like :range_begin, :begin
end
diff --git a/spec/ruby/core/range/bsearch_spec.rb b/spec/ruby/core/range/bsearch_spec.rb
index a10dcea61e..151a1798cf 100644
--- a/spec/ruby/core/range/bsearch_spec.rb
+++ b/spec/ruby/core/range/bsearch_spec.rb
@@ -1,40 +1,48 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../enumerable/shared/enumeratorized', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../enumerable/shared/enumeratorized'
describe "Range#bsearch" do
it "returns an Enumerator when not passed a block" do
- (0..1).bsearch.should be_an_instance_of(Enumerator)
+ (0..1).bsearch.should.instance_of?(Enumerator)
end
it_behaves_like :enumeratorized_with_unknown_size, :bsearch, (1..3)
it "raises a TypeError if the block returns an Object" do
- lambda { (0..1).bsearch { Object.new } }.should raise_error(TypeError)
+ -> { (0..1).bsearch { Object.new } }.should.raise(TypeError, "wrong argument type Object (must be numeric, true, false or nil)")
end
- it "raises a TypeError if the block returns a String" do
- lambda { (0..1).bsearch { "1" } }.should raise_error(TypeError)
+ it "raises a TypeError if the block returns a String and boundaries are Integer values" do
+ -> { (0..1).bsearch { "1" } }.should.raise(TypeError, "wrong argument type String (must be numeric, true, false or nil)")
+ end
+
+ it "raises a TypeError if the block returns a String and boundaries are Float values" do
+ -> { (0.0..1.0).bsearch { "1" } }.should.raise(TypeError, "wrong argument type String (must be numeric, true, false or nil)")
end
it "raises a TypeError if the Range has Object values" do
value = mock("range bsearch")
r = Range.new value, value
- lambda { r.bsearch { true } }.should raise_error(TypeError)
+ -> { r.bsearch { true } }.should.raise(TypeError, "can't do binary search for MockObject")
end
it "raises a TypeError if the Range has String values" do
- lambda { ("a".."e").bsearch { true } }.should raise_error(TypeError)
+ -> { ("a".."e").bsearch { true } }.should.raise(TypeError, "can't do binary search for String")
+ end
+
+ it "raises TypeError when non-Numeric begin/end and block not passed" do
+ -> { ("a".."e").bsearch }.should.raise(TypeError, "can't do binary search for String")
end
context "with Integer values" do
context "with a block returning true or false" do
it "returns nil if the block returns false for every element" do
- (0...3).bsearch { |x| x > 3 }.should be_nil
+ (0...3).bsearch { |x| x > 3 }.should == nil
end
it "returns nil if the block returns nil for every element" do
- (0..3).bsearch { |x| nil }.should be_nil
+ (0..3).bsearch { |x| nil }.should == nil
end
it "returns minimum element if the block returns true for every element" do
@@ -54,21 +62,21 @@ describe "Range#bsearch" do
context "with a block returning negative, zero, positive numbers" do
it "returns nil if the block returns less than zero for every element" do
- (0..3).bsearch { |x| x <=> 5 }.should be_nil
+ (0..3).bsearch { |x| x <=> 5 }.should == nil
end
it "returns nil if the block returns greater than zero for every element" do
- (0..3).bsearch { |x| x <=> -1 }.should be_nil
+ (0..3).bsearch { |x| x <=> -1 }.should == nil
end
it "returns nil if the block never returns zero" do
- (0..3).bsearch { |x| x < 2 ? 1 : -1 }.should be_nil
+ (0..3).bsearch { |x| x < 2 ? 1 : -1 }.should == nil
end
it "accepts (+/-)Float::INFINITY from the block" do
- (0..4).bsearch { |x| Float::INFINITY }.should be_nil
- (0..4).bsearch { |x| -Float::INFINITY }.should be_nil
+ (0..4).bsearch { |x| Float::INFINITY }.should == nil
+ (0..4).bsearch { |x| -Float::INFINITY }.should == nil
end
it "returns an element at an index for which block returns 0.0" do
@@ -78,48 +86,97 @@ describe "Range#bsearch" do
it "returns an element at an index for which block returns 0" do
result = (0..4).bsearch { |x| x < 1 ? 1 : x > 3 ? -1 : 0 }
- [1, 2].should include(result)
+ [1, 2].should.include?(result)
end
end
+
+ it "returns nil for empty ranges" do
+ (0...0).bsearch { true }.should == nil
+ (0...0).bsearch { false }.should == nil
+ (0...0).bsearch { 1 }.should == nil
+ (0...0).bsearch { 0 }.should == nil
+ (0...0).bsearch { -1 }.should == nil
+
+ (4..2).bsearch { true }.should == nil
+ (4..2).bsearch { 1 }.should == nil
+ (4..2).bsearch { 0 }.should == nil
+ (4..2).bsearch { -1 }.should == nil
+ end
+
+ it "returns enumerator when block not passed" do
+ (0...3).bsearch.kind_of?(Enumerator).should == true
+ end
end
context "with Float values" do
context "with a block returning true or false" do
it "returns nil if the block returns false for every element" do
- (0.1...2.3).bsearch { |x| x > 3 }.should be_nil
+ (0.1...2.3).bsearch { |x| x > 3 }.should == nil
end
it "returns nil if the block returns nil for every element" do
- (-0.0..2.3).bsearch { |x| nil }.should be_nil
+ (-0.0..2.3).bsearch { |x| nil }.should == nil
end
it "returns minimum element if the block returns true for every element" do
- (-0.2..4.8).bsearch { |x| x < 4 }.should == -0.2
+ (-0.2..4.8).bsearch { |x| x < 5 }.should == -0.2
end
it "returns the smallest element for which block returns true" do
(0..4.2).bsearch { |x| x >= 2 }.should == 2
(-1.2..4.3).bsearch { |x| x >= 1 }.should == 1
end
+
+ it "returns a boundary element if appropriate" do
+ (1.0..3.0).bsearch { |x| x >= 3.0 }.should == 3.0
+ (1.0...3.0).bsearch { |x| x >= 3.0.prev_float }.should == 3.0.prev_float
+ (1.0..3.0).bsearch { |x| x >= 1.0 }.should == 1.0
+ (1.0...3.0).bsearch { |x| x >= 1.0 }.should == 1.0
+ end
+
+ it "works with infinity bounds" do
+ inf = Float::INFINITY
+ (0..inf).bsearch { |x| x == inf }.should == inf
+ (0...inf).bsearch { |x| x == inf }.should == nil
+ (-inf..0).bsearch { |x| x != -inf }.should == -Float::MAX
+ (-inf...0).bsearch { |x| x != -inf }.should == -Float::MAX
+ (inf..inf).bsearch { |x| true }.should == inf
+ (inf...inf).bsearch { |x| true }.should == nil
+ (-inf..-inf).bsearch { |x| true }.should == -inf
+ (-inf...-inf).bsearch { |x| true }.should == nil
+ (inf..0).bsearch { true }.should == nil
+ (inf...0).bsearch { true }.should == nil
+ (0..-inf).bsearch { true }.should == nil
+ (0...-inf).bsearch { true }.should == nil
+ (inf..-inf).bsearch { true }.should == nil
+ (inf...-inf).bsearch { true }.should == nil
+ (0..inf).bsearch { |x| x >= 3 }.should == 3.0
+ (0...inf).bsearch { |x| x >= 3 }.should == 3.0
+ (-inf..0).bsearch { |x| x >= -3 }.should == -3.0
+ (-inf...0).bsearch { |x| x >= -3 }.should == -3.0
+ (-inf..inf).bsearch { |x| x >= 3 }.should == 3.0
+ (-inf...inf).bsearch { |x| x >= 3 }.should == 3.0
+ (0..inf).bsearch { |x| x >= Float::MAX }.should == Float::MAX
+ (0...inf).bsearch { |x| x >= Float::MAX }.should == Float::MAX
+ end
end
context "with a block returning negative, zero, positive numbers" do
it "returns nil if the block returns less than zero for every element" do
- (-2.0..3.2).bsearch { |x| x <=> 5 }.should be_nil
+ (-2.0..3.2).bsearch { |x| x <=> 5 }.should == nil
end
it "returns nil if the block returns greater than zero for every element" do
- (0.3..3.0).bsearch { |x| x <=> -1 }.should be_nil
-
+ (0.3..3.0).bsearch { |x| x <=> -1 }.should == nil
end
it "returns nil if the block never returns zero" do
- (0.2..2.3).bsearch { |x| x < 2 ? 1 : -1 }.should be_nil
+ (0.2..2.3).bsearch { |x| x < 2 ? 1 : -1 }.should == nil
end
it "accepts (+/-)Float::INFINITY from the block" do
- (0.1..4.5).bsearch { |x| Float::INFINITY }.should be_nil
- (-5.0..4.0).bsearch { |x| -Float::INFINITY }.should be_nil
+ (0.1..4.5).bsearch { |x| Float::INFINITY }.should == nil
+ (-5.0..4.0).bsearch { |x| -Float::INFINITY }.should == nil
end
it "returns an element at an index for which block returns 0.0" do
@@ -130,8 +187,280 @@ describe "Range#bsearch" do
it "returns an element at an index for which block returns 0" do
result = (0.1..4.9).bsearch { |x| x < 1 ? 1 : x > 3 ? -1 : 0 }
result.should >= 1
- result.should <= 2
+ result.should <= 3
+ end
+
+ it "returns an element at an index for which block returns 0 (small numbers)" do
+ result = (0.1..0.3).bsearch { |x| x < 0.1 ? 1 : x > 0.3 ? -1 : 0 }
+ result.should >= 0.1
+ result.should <= 0.3
+ end
+
+ it "returns a boundary element if appropriate" do
+ (1.0..3.0).bsearch { |x| 3.0 - x }.should == 3.0
+ (1.0...3.0).bsearch { |x| 3.0.prev_float - x }.should == 3.0.prev_float
+ (1.0..3.0).bsearch { |x| 1.0 - x }.should == 1.0
+ (1.0...3.0).bsearch { |x| 1.0 - x }.should == 1.0
+ end
+
+ it "works with infinity bounds" do
+ inf = Float::INFINITY
+ (0..inf).bsearch { |x| x == inf ? 0 : 1 }.should == inf
+ (0...inf).bsearch { |x| x == inf ? 0 : 1 }.should == nil
+ (-inf...0).bsearch { |x| x == -inf ? 0 : -1 }.should == -inf
+ (-inf..0).bsearch { |x| x == -inf ? 0 : -1 }.should == -inf
+ (inf..inf).bsearch { 0 }.should == inf
+ (inf...inf).bsearch { 0 }.should == nil
+ (-inf..-inf).bsearch { 0 }.should == -inf
+ (-inf...-inf).bsearch { 0 }.should == nil
+ (inf..0).bsearch { 0 }.should == nil
+ (inf...0).bsearch { 0 }.should == nil
+ (0..-inf).bsearch { 0 }.should == nil
+ (0...-inf).bsearch { 0 }.should == nil
+ (inf..-inf).bsearch { 0 }.should == nil
+ (inf...-inf).bsearch { 0 }.should == nil
+ (-inf..inf).bsearch { |x| 3 - x }.should == 3.0
+ (-inf...inf).bsearch { |x| 3 - x }.should == 3.0
+ (0...inf).bsearch { |x| x >= Float::MAX ? 0 : 1 }.should == Float::MAX
end
end
+
+ it "returns enumerator when block not passed" do
+ (0.1...2.3).bsearch.kind_of?(Enumerator).should == true
+ end
+ end
+
+ context "with endless ranges and Integer values" do
+ context "with a block returning true or false" do
+ it "returns minimum element if the block returns true for every element" do
+ eval("(-2..)").bsearch { |x| true }.should == -2
+ end
+
+ it "returns the smallest element for which block returns true" do
+ eval("(0..)").bsearch { |x| x >= 2 }.should == 2
+ eval("(-1..)").bsearch { |x| x >= 1 }.should == 1
+ end
+ end
+
+ context "with a block returning negative, zero, positive numbers" do
+ it "returns nil if the block returns less than zero for every element" do
+ eval("(0..)").bsearch { |x| -1 }.should == nil
+ end
+
+ it "returns nil if the block never returns zero" do
+ eval("(0..)").bsearch { |x| x > 5 ? -1 : 1 }.should == nil
+ end
+
+ it "accepts -Float::INFINITY from the block" do
+ eval("(0..)").bsearch { |x| -Float::INFINITY }.should == nil
+ end
+
+ it "returns an element at an index for which block returns 0.0" do
+ result = eval("(0..)").bsearch { |x| x < 2 ? 1.0 : x > 2 ? -1.0 : 0.0 }
+ result.should == 2
+ end
+
+ it "returns an element at an index for which block returns 0" do
+ result = eval("(0..)").bsearch { |x| x < 1 ? 1 : x > 3 ? -1 : 0 }
+ [1, 2, 3].should.include?(result)
+ end
+ end
+
+ it "returns enumerator when block not passed" do
+ eval("(-2..)").bsearch.kind_of?(Enumerator).should == true
+ end
+ end
+
+ context "with endless ranges and Float values" do
+ context "with a block returning true or false" do
+ it "returns nil if the block returns false for every element" do
+ eval("(0.1..)").bsearch { |x| x < 0.0 }.should == nil
+ eval("(0.1...)").bsearch { |x| x < 0.0 }.should == nil
+ end
+
+ it "returns nil if the block returns nil for every element" do
+ eval("(-0.0..)").bsearch { |x| nil }.should == nil
+ eval("(-0.0...)").bsearch { |x| nil }.should == nil
+ end
+
+ it "returns minimum element if the block returns true for every element" do
+ eval("(-0.2..)").bsearch { |x| true }.should == -0.2
+ eval("(-0.2...)").bsearch { |x| true }.should == -0.2
+ end
+
+ it "returns the smallest element for which block returns true" do
+ eval("(0..)").bsearch { |x| x >= 2 }.should == 2
+ eval("(-1.2..)").bsearch { |x| x >= 1 }.should == 1
+ end
+
+ it "works with infinity bounds" do
+ inf = Float::INFINITY
+ eval("(inf..)").bsearch { |x| true }.should == inf
+ eval("(inf...)").bsearch { |x| true }.should == nil
+ eval("(-inf..)").bsearch { |x| true }.should == -inf
+ eval("(-inf...)").bsearch { |x| true }.should == -inf
+ end
+ end
+
+ context "with a block returning negative, zero, positive numbers" do
+ it "returns nil if the block returns less than zero for every element" do
+ eval("(-2.0..)").bsearch { |x| -1 }.should == nil
+ eval("(-2.0...)").bsearch { |x| -1 }.should == nil
+ end
+
+ it "returns nil if the block returns greater than zero for every element" do
+ eval("(0.3..)").bsearch { |x| 1 }.should == nil
+ eval("(0.3...)").bsearch { |x| 1 }.should == nil
+ end
+
+ it "returns nil if the block never returns zero" do
+ eval("(0.2..)").bsearch { |x| x < 2 ? 1 : -1 }.should == nil
+ end
+
+ it "accepts (+/-)Float::INFINITY from the block" do
+ eval("(0.1..)").bsearch { |x| Float::INFINITY }.should == nil
+ eval("(-5.0..)").bsearch { |x| -Float::INFINITY }.should == nil
+ end
+
+ it "returns an element at an index for which block returns 0.0" do
+ result = eval("(0.0..)").bsearch { |x| x < 2 ? 1.0 : x > 2 ? -1.0 : 0.0 }
+ result.should == 2
+ end
+
+ it "returns an element at an index for which block returns 0" do
+ result = eval("(0.1..)").bsearch { |x| x < 1 ? 1 : x > 3 ? -1 : 0 }
+ result.should >= 1
+ result.should <= 3
+ end
+
+ it "works with infinity bounds" do
+ inf = Float::INFINITY
+ eval("(inf..)").bsearch { |x| 1 }.should == nil
+ eval("(inf...)").bsearch { |x| 1 }.should == nil
+ eval("(inf..)").bsearch { |x| x == inf ? 0 : 1 }.should == inf
+ eval("(inf...)").bsearch { |x| x == inf ? 0 : 1 }.should == nil
+ eval("(-inf..)").bsearch { |x| x == -inf ? 0 : -1 }.should == -inf
+ eval("(-inf...)").bsearch { |x| x == -inf ? 0 : -1 }.should == -inf
+ eval("(-inf..)").bsearch { |x| 3 - x }.should == 3
+ eval("(-inf...)").bsearch { |x| 3 - x }.should == 3
+ eval("(0.0...)").bsearch { 0 }.should != inf
+ end
+ end
+
+ it "returns enumerator when block not passed" do
+ eval("(0.1..)").bsearch.kind_of?(Enumerator).should == true
+ end
+ end
+
+ context "with beginless ranges and Integer values" do
+ context "with a block returning true or false" do
+ it "returns the smallest element for which block returns true" do
+ (..10).bsearch { |x| x >= 2 }.should == 2
+ (...-1).bsearch { |x| x >= -10 }.should == -10
+ end
+ end
+
+ context "with a block returning negative, zero, positive numbers" do
+ it "returns nil if the block returns greater than zero for every element" do
+ (..0).bsearch { |x| 1 }.should == nil
+ end
+
+ it "returns nil if the block never returns zero" do
+ (..0).bsearch { |x| x > 5 ? -1 : 1 }.should == nil
+ end
+
+ it "accepts Float::INFINITY from the block" do
+ (..0).bsearch { |x| Float::INFINITY }.should == nil
+ end
+
+ it "returns an element at an index for which block returns 0.0" do
+ result = (..10).bsearch { |x| x < 2 ? 1.0 : x > 2 ? -1.0 : 0.0 }
+ result.should == 2
+ end
+
+ it "returns an element at an index for which block returns 0" do
+ result = (...10).bsearch { |x| x < 1 ? 1 : x > 3 ? -1 : 0 }
+ [1, 2, 3].should.include?(result)
+ end
+ end
+
+ it "returns enumerator when block not passed" do
+ (..10).bsearch.kind_of?(Enumerator).should == true
+ end
+ end
+
+ context "with beginless ranges and Float values" do
+ context "with a block returning true or false" do
+ it "returns nil if the block returns true for every element" do
+ (..-0.1).bsearch { |x| x > 0.0 }.should == nil
+ (...-0.1).bsearch { |x| x > 0.0 }.should == nil
+ end
+
+ it "returns nil if the block returns nil for every element" do
+ (..-0.1).bsearch { |x| nil }.should == nil
+ (...-0.1).bsearch { |x| nil }.should == nil
+ end
+
+ it "returns the smallest element for which block returns true" do
+ (..10).bsearch { |x| x >= 2 }.should == 2
+ (..10).bsearch { |x| x >= 1 }.should == 1
+ end
+
+ it "works with infinity bounds" do
+ inf = Float::INFINITY
+ (..inf).bsearch { |x| true }.should == -inf
+ (...inf).bsearch { |x| true }.should == -inf
+ (..-inf).bsearch { |x| true }.should == -inf
+ (...-inf).bsearch { |x| true }.should == nil
+ end
+ end
+
+ context "with a block returning negative, zero, positive numbers" do
+ it "returns nil if the block returns less than zero for every element" do
+ (..5.0).bsearch { |x| -1 }.should == nil
+ (...5.0).bsearch { |x| -1 }.should == nil
+ end
+
+ it "returns nil if the block returns greater than zero for every element" do
+ (..1.1).bsearch { |x| 1 }.should == nil
+ (...1.1).bsearch { |x| 1 }.should == nil
+ end
+
+ it "returns nil if the block never returns zero" do
+ (..6.3).bsearch { |x| x < 2 ? 1 : -1 }.should == nil
+ end
+
+ it "accepts (+/-)Float::INFINITY from the block" do
+ (..5.0).bsearch { |x| Float::INFINITY }.should == nil
+ (..7.0).bsearch { |x| -Float::INFINITY }.should == nil
+ end
+
+ it "returns an element at an index for which block returns 0.0" do
+ result = (..8.0).bsearch { |x| x < 2 ? 1.0 : x > 2 ? -1.0 : 0.0 }
+ result.should == 2
+ end
+
+ it "returns an element at an index for which block returns 0" do
+ result = (..8.0).bsearch { |x| x < 1 ? 1 : x > 3 ? -1 : 0 }
+ result.should >= 1
+ result.should <= 3
+ end
+
+ it "works with infinity bounds" do
+ inf = Float::INFINITY
+ (..-inf).bsearch { |x| 1 }.should == nil
+ (...-inf).bsearch { |x| 1 }.should == nil
+ (..inf).bsearch { |x| x == inf ? 0 : 1 }.should == inf
+ (...inf).bsearch { |x| x == inf ? 0 : 1 }.should == nil
+ (..-inf).bsearch { |x| x == -inf ? 0 : -1 }.should == -inf
+ (...-inf).bsearch { |x| x == -inf ? 0 : -1 }.should == nil
+ (..inf).bsearch { |x| 3 - x }.should == 3
+ (...inf).bsearch { |x| 3 - x }.should == 3
+ end
+ end
+
+ it "returns enumerator when block not passed" do
+ (..-0.1).bsearch.kind_of?(Enumerator).should == true
+ end
end
end
diff --git a/spec/ruby/core/range/case_compare_spec.rb b/spec/ruby/core/range/case_compare_spec.rb
index cada3b7cd5..7a76487d68 100644
--- a/spec/ruby/core/range/case_compare_spec.rb
+++ b/spec/ruby/core/range/case_compare_spec.rb
@@ -1,11 +1,17 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/cover_and_include', __FILE__)
-require File.expand_path('../shared/cover', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/cover_and_include'
+require_relative 'shared/cover'
describe "Range#===" do
- it "returns the result of calling #include? on self" do
- range = 0...10
- range.should_receive(:include?).with(2).and_return(:true)
- (range === 2).should == :true
+ it "returns the result of calling #cover? on self" do
+ range = RangeSpecs::WithoutSucc.new(0)..RangeSpecs::WithoutSucc.new(10)
+ (range === RangeSpecs::WithoutSucc.new(2)).should == true
+ end
+
+ it_behaves_like :range_cover_and_include, :===
+ it_behaves_like :range_cover, :===
+
+ it "returns true on any value if begin and end are both nil" do
+ (nil..nil).should === 1
end
end
diff --git a/spec/ruby/core/range/clone_spec.rb b/spec/ruby/core/range/clone_spec.rb
new file mode 100644
index 0000000000..cf6ce74da0
--- /dev/null
+++ b/spec/ruby/core/range/clone_spec.rb
@@ -0,0 +1,26 @@
+require_relative '../../spec_helper'
+
+describe "Range#clone" do
+ it "duplicates the range" do
+ original = (1..3)
+ copy = original.clone
+ copy.begin.should == 1
+ copy.end.should == 3
+ copy.should_not.exclude_end?
+ copy.should_not.equal? original
+
+ original = ("a"..."z")
+ copy = original.clone
+ copy.begin.should == "a"
+ copy.end.should == "z"
+ copy.should.exclude_end?
+ copy.should_not.equal? original
+ end
+
+ it "maintains the frozen state" do
+ (1..2).clone.frozen?.should == (1..2).frozen?
+ (1..).clone.frozen?.should == (1..).frozen?
+ Range.new(1, 2).clone.frozen?.should == Range.new(1, 2).frozen?
+ Class.new(Range).new(1, 2).clone.frozen?.should == Class.new(Range).new(1, 2).frozen?
+ end
+end
diff --git a/spec/ruby/core/range/count_spec.rb b/spec/ruby/core/range/count_spec.rb
new file mode 100644
index 0000000000..24d4a9caf3
--- /dev/null
+++ b/spec/ruby/core/range/count_spec.rb
@@ -0,0 +1,12 @@
+require_relative '../../spec_helper'
+
+describe "Range#count" do
+ it "returns Infinity for beginless ranges without arguments or blocks" do
+ inf = Float::INFINITY
+ eval("('a'...)").count.should == inf
+ eval("(7..)").count.should == inf
+ (...'a').count.should == inf
+ (...nil).count.should == inf
+ (..10.0).count.should == inf
+ end
+end
diff --git a/spec/ruby/core/range/cover_spec.rb b/spec/ruby/core/range/cover_spec.rb
index 9c8b914d6d..eb8d5453bf 100644
--- a/spec/ruby/core/range/cover_spec.rb
+++ b/spec/ruby/core/range/cover_spec.rb
@@ -1,9 +1,14 @@
-# -*- encoding: ascii-8bit -*-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/cover_and_include', __FILE__)
-require File.expand_path('../shared/cover', __FILE__)
+# encoding: binary
+require_relative '../../spec_helper'
+require_relative 'shared/cover_and_include'
+require_relative 'shared/cover'
describe "Range#cover?" do
it_behaves_like :range_cover_and_include, :cover?
it_behaves_like :range_cover, :cover?
+ it_behaves_like :range_cover_subrange, :cover?
+
+ it "covers U+9995 in the range U+0999..U+9999" do
+ ("\u{999}".."\u{9999}").cover?("\u{9995}").should == true
+ end
end
diff --git a/spec/ruby/core/range/dup_spec.rb b/spec/ruby/core/range/dup_spec.rb
index cdb792c97f..fab3c3f1b2 100644
--- a/spec/ruby/core/range/dup_spec.rb
+++ b/spec/ruby/core/range/dup_spec.rb
@@ -1,15 +1,23 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Range#dup" do
it "duplicates the range" do
- copy = (1..3).dup
+ original = (1..3)
+ copy = original.dup
copy.begin.should == 1
copy.end.should == 3
- copy.exclude_end?.should == false
+ copy.should_not.exclude_end?
+ copy.should_not.equal?(original)
copy = ("a"..."z").dup
copy.begin.should == "a"
copy.end.should == "z"
- copy.exclude_end?.should == true
+ copy.should.exclude_end?
+ end
+
+ it "creates an unfrozen range" do
+ (1..2).dup.should_not.frozen?
+ (1..).dup.should_not.frozen?
+ Range.new(1, 2).dup.should_not.frozen?
end
end
diff --git a/spec/ruby/core/range/each_spec.rb b/spec/ruby/core/range/each_spec.rb
index 4520f3cde6..b4389f864d 100644
--- a/spec/ruby/core/range/each_spec.rb
+++ b/spec/ruby/core/range/each_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../enumerable/shared/enumeratorized', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../enumerable/shared/enumeratorized'
describe "Range#each" do
it "passes each element to the given block by using #succ" do
@@ -32,29 +32,64 @@ describe "Range#each" do
a.should == [x, y]
end
+ it "works for non-ASCII ranges" do
+ a = []
+ ('Σ'..'Ω').each { |i| a << i }
+ a.should == ["Σ", "Τ", "Υ", "Φ", "Χ", "Ψ", "Ω"]
+ end
+
+ it "works with endless ranges" do
+ a = []
+ (-2..).each { |x| break if x > 2; a << x }
+ a.should == [-2, -1, 0, 1, 2]
+
+ a = []
+ (-2...).each { |x| break if x > 2; a << x }
+ a.should == [-2, -1, 0, 1, 2]
+ end
+
+ it "works with String endless ranges" do
+ a = []
+ ('A'..).each { |x| break if x > "D"; a << x }
+ a.should == ["A", "B", "C", "D"]
+
+ a = []
+ ('A'...).each { |x| break if x > "D"; a << x }
+ a.should == ["A", "B", "C", "D"]
+ end
+
+ it "raises a TypeError beginless ranges" do
+ -> { (..2).each { |x| x } }.should.raise(TypeError)
+ end
+
it "raises a TypeError if the first element does not respond to #succ" do
- lambda { (0.5..2.4).each { |i| i } }.should raise_error(TypeError)
+ -> { (0.5..2.4).each { |i| i } }.should.raise(TypeError)
b = mock('x')
(a = mock('1')).should_receive(:<=>).with(b).and_return(1)
- lambda { (a..b).each { |i| i } }.should raise_error(TypeError)
+ -> { (a..b).each { |i| i } }.should.raise(TypeError)
end
it "returns self" do
range = 1..10
- range.each{}.should equal(range)
+ range.each{}.should.equal?(range)
end
it "returns an enumerator when no block given" do
enum = (1..3).each
- enum.should be_an_instance_of(Enumerator)
+ enum.should.instance_of?(Enumerator)
enum.to_a.should == [1, 2, 3]
end
- it "raises a TypeError if the first element is a Time object" do
- t = Time.now
- lambda { (t..t+1).each { |i| i } }.should raise_error(TypeError)
+ it "supports Time objects that respond to #succ" do
+ t = Time.utc(1970)
+ def t.succ; self + 1 end
+ t_succ = t.succ
+ def t_succ.succ; self + 1; end
+
+ (t..t_succ).to_a.should == [Time.utc(1970), Time.utc(1970, nil, nil, nil, nil, 1)]
+ (t...t_succ).to_a.should == [Time.utc(1970)]
end
it "passes each Symbol element by using #succ" do
diff --git a/spec/ruby/core/range/end_spec.rb b/spec/ruby/core/range/end_spec.rb
index 128f44c309..9e5e6f7d43 100644
--- a/spec/ruby/core/range/end_spec.rb
+++ b/spec/ruby/core/range/end_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/end', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/end'
describe "Range#end" do
- it_behaves_like(:range_end, :end)
+ it_behaves_like :range_end, :end
end
diff --git a/spec/ruby/core/range/entries_spec.rb b/spec/ruby/core/range/entries_spec.rb
new file mode 100644
index 0000000000..29296711dc
--- /dev/null
+++ b/spec/ruby/core/range/entries_spec.rb
@@ -0,0 +1,7 @@
+require_relative '../../spec_helper'
+
+describe "Range#entries" do
+ it "is an alias of Range#to_a" do
+ Range.instance_method(:entries).should == Range.instance_method(:to_a)
+ end
+end
diff --git a/spec/ruby/core/range/eql_spec.rb b/spec/ruby/core/range/eql_spec.rb
index 2d495ee175..cdc19c9331 100644
--- a/spec/ruby/core/range/eql_spec.rb
+++ b/spec/ruby/core/range/eql_spec.rb
@@ -1,10 +1,10 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/equal_value', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/equal_value'
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
+ (0..1).should_not.eql?(0..1.0)
end
end
diff --git a/spec/ruby/core/range/equal_value_spec.rb b/spec/ruby/core/range/equal_value_spec.rb
index 488fe73c55..83dcf5cec8 100644
--- a/spec/ruby/core/range/equal_value_spec.rb
+++ b/spec/ruby/core/range/equal_value_spec.rb
@@ -1,10 +1,18 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/equal_value', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/equal_value'
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
+ (0..1).should == (0..1.0)
+ end
+
+ it "returns true if the endpoints are == for endless ranges" do
+ eval("(1.0..)").should == eval("(1.0..)")
+ end
+
+ it "returns true if the endpoints are == for beginless ranges" do
+ (...10).should == (...10)
end
end
diff --git a/spec/ruby/core/range/exclude_end_spec.rb b/spec/ruby/core/range/exclude_end_spec.rb
index 5bbdaa25a7..c4006fea78 100644
--- a/spec/ruby/core/range/exclude_end_spec.rb
+++ b/spec/ruby/core/range/exclude_end_spec.rb
@@ -1,19 +1,19 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Range#exclude_end?" do
it "returns false if the range does not exclude the end value" do
- (-2..2).exclude_end?.should == false
- ('A'..'B').exclude_end?.should == false
- (0.5..2.4).exclude_end?.should == false
- (0xfffd..0xffff).exclude_end?.should == false
- Range.new(0, 1).exclude_end?.should == false
+ (-2..2).should_not.exclude_end?
+ ('A'..'B').should_not.exclude_end?
+ (0.5..2.4).should_not.exclude_end?
+ (0xfffd..0xffff).should_not.exclude_end?
+ Range.new(0, 1).should_not.exclude_end?
end
it "returns true if the range excludes the end value" do
- (0...5).exclude_end?.should == true
- ('A'...'B').exclude_end?.should == true
- (0.5...2.4).exclude_end?.should == true
- (0xfffd...0xffff).exclude_end?.should == true
- Range.new(0, 1, true).exclude_end?.should == true
+ (0...5).should.exclude_end?
+ ('A'...'B').should.exclude_end?
+ (0.5...2.4).should.exclude_end?
+ (0xfffd...0xffff).should.exclude_end?
+ Range.new(0, 1, true).should.exclude_end?
end
end
diff --git a/spec/ruby/core/range/first_spec.rb b/spec/ruby/core/range/first_spec.rb
index 7cd3781d34..54bd73a4e8 100644
--- a/spec/ruby/core/range/first_spec.rb
+++ b/spec/ruby/core/range/first_spec.rb
@@ -1,8 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/begin', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/begin'
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]
@@ -21,7 +21,7 @@ describe "Range#first" do
end
it "raises an ArgumentError when count is negative" do
- lambda { (0..2).first(-1) }.should raise_error(ArgumentError)
+ -> { (0..2).first(-1) }.should.raise(ArgumentError)
end
it "calls #to_int to convert the argument" do
@@ -32,7 +32,7 @@ describe "Range#first" do
it "raises a TypeError if #to_int does not return an Integer" do
obj = mock("to_int")
obj.should_receive(:to_int).and_return("1")
- lambda { (2..3).first(obj) }.should raise_error(TypeError)
+ -> { (2..3).first(obj) }.should.raise(TypeError)
end
it "truncates the value when passed a Float" do
@@ -40,10 +40,14 @@ describe "Range#first" do
end
it "raises a TypeError when passed nil" do
- lambda { (2..3).first(nil) }.should raise_error(TypeError)
+ -> { (2..3).first(nil) }.should.raise(TypeError)
end
it "raises a TypeError when passed a String" do
- lambda { (2..3).first("1") }.should raise_error(TypeError)
+ -> { (2..3).first("1") }.should.raise(TypeError)
+ end
+
+ it "raises a RangeError when called on an beginless range" do
+ -> { (..1).first }.should.raise(RangeError)
end
end
diff --git a/spec/ruby/core/range/fixtures/classes.rb b/spec/ruby/core/range/fixtures/classes.rb
index de46d7d4a9..3a1df010b2 100644
--- a/spec/ruby/core/range/fixtures/classes.rb
+++ b/spec/ruby/core/range/fixtures/classes.rb
@@ -40,6 +40,28 @@ module RangeSpecs
end
end
+ class WithoutSucc
+ include Comparable
+ attr_reader :n
+
+ def initialize(n)
+ @n = n
+ end
+
+ def eql?(other)
+ inspect.eql? other.inspect
+ end
+ alias :== :eql?
+
+ def inspect
+ "WithoutSucc(#{@n})"
+ end
+
+ def <=>(other)
+ @n <=> other.n
+ end
+ end
+
class Xs < Custom # represent a string of 'x's
def succ
Xs.new(@length + 1)
@@ -62,4 +84,7 @@ module RangeSpecs
class MyRange < Range
end
+
+ class ComparisonError < RuntimeError
+ end
end
diff --git a/spec/ruby/core/range/frozen_spec.rb b/spec/ruby/core/range/frozen_spec.rb
new file mode 100644
index 0000000000..8dab5e5339
--- /dev/null
+++ b/spec/ruby/core/range/frozen_spec.rb
@@ -0,0 +1,25 @@
+require_relative '../../spec_helper'
+
+# There is no Range#frozen? method but this feels like the best place for these specs
+describe "Range#frozen?" do
+ it "is true for literal ranges" do
+ (1..2).should.frozen?
+ (1..).should.frozen?
+ (..1).should.frozen?
+ end
+
+ it "is true for Range.new" do
+ Range.new(1, 2).should.frozen?
+ Range.new(1, nil).should.frozen?
+ Range.new(nil, 1).should.frozen?
+ end
+
+ it "is false for instances of a subclass of Range" do
+ sub_range = Class.new(Range).new(1, 2)
+ sub_range.should_not.frozen?
+ end
+
+ it "is false for Range.allocate" do
+ Range.allocate.should_not.frozen?
+ end
+end
diff --git a/spec/ruby/core/range/hash_spec.rb b/spec/ruby/core/range/hash_spec.rb
index dcac523487..087f5d6de8 100644
--- a/spec/ruby/core/range/hash_spec.rb
+++ b/spec/ruby/core/range/hash_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Range#hash" do
it "is provided" do
@@ -14,11 +14,11 @@ describe "Range#hash" do
(0..10).hash.should_not == (0...10).hash
end
- it "generates a Fixnum for the hash value" do
- (0..0).hash.should be_an_instance_of(Fixnum)
- (0..1).hash.should be_an_instance_of(Fixnum)
- (0...10).hash.should be_an_instance_of(Fixnum)
- (0..10).hash.should be_an_instance_of(Fixnum)
+ it "generates an Integer for the hash value" do
+ (0..0).hash.should.instance_of?(Integer)
+ (0..1).hash.should.instance_of?(Integer)
+ (0...10).hash.should.instance_of?(Integer)
+ (0..10).hash.should.instance_of?(Integer)
end
end
diff --git a/spec/ruby/core/range/include_spec.rb b/spec/ruby/core/range/include_spec.rb
index 2d7450f8ae..e5cc0dc234 100644
--- a/spec/ruby/core/range/include_spec.rb
+++ b/spec/ruby/core/range/include_spec.rb
@@ -1,10 +1,98 @@
-# -*- encoding: ascii-8bit -*-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/cover_and_include', __FILE__)
-require File.expand_path('../shared/include', __FILE__)
-require File.expand_path('../shared/cover', __FILE__)
+# encoding: binary
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/cover_and_include'
describe "Range#include?" do
it_behaves_like :range_cover_and_include, :include?
- it_behaves_like :range_include, :include?
+
+ describe "on string elements" do
+ it "returns true if other is matched by element.succ" do
+ ('a'..'c').include?('b').should == true
+ ('a'...'c').include?('b').should == true
+ end
+
+ it "returns false if other is not matched by element.succ" do
+ ('a'..'c').include?('bc').should == false
+ ('a'...'c').include?('bc').should == false
+ end
+ end
+
+ describe "with weird succ" do
+ describe "when included end value" do
+ before :each do
+ @range = RangeSpecs::TenfoldSucc.new(1)..RangeSpecs::TenfoldSucc.new(99)
+ end
+
+ it "returns false if other is less than first element" do
+ @range.include?(RangeSpecs::TenfoldSucc.new(0)).should == false
+ end
+
+ it "returns true if other is equal as first element" do
+ @range.include?(RangeSpecs::TenfoldSucc.new(1)).should == true
+ end
+
+ it "returns true if other is matched by element.succ" do
+ @range.include?(RangeSpecs::TenfoldSucc.new(10)).should == true
+ end
+
+ it "returns false if other is not matched by element.succ" do
+ @range.include?(RangeSpecs::TenfoldSucc.new(2)).should == false
+ end
+
+ it "returns false if other is equal as last element but not matched by element.succ" do
+ @range.include?(RangeSpecs::TenfoldSucc.new(99)).should == false
+ end
+
+ it "returns false if other is greater than last element but matched by element.succ" do
+ @range.include?(RangeSpecs::TenfoldSucc.new(100)).should == false
+ end
+ end
+
+ describe "when excluded end value" do
+ before :each do
+ @range = RangeSpecs::TenfoldSucc.new(1)...RangeSpecs::TenfoldSucc.new(99)
+ end
+
+ it "returns false if other is less than first element" do
+ @range.include?(RangeSpecs::TenfoldSucc.new(0)).should == false
+ end
+
+ it "returns true if other is equal as first element" do
+ @range.include?(RangeSpecs::TenfoldSucc.new(1)).should == true
+ end
+
+ it "returns true if other is matched by element.succ" do
+ @range.include?(RangeSpecs::TenfoldSucc.new(10)).should == true
+ end
+
+ it "returns false if other is not matched by element.succ" do
+ @range.include?(RangeSpecs::TenfoldSucc.new(2)).should == false
+ end
+
+ it "returns false if other is equal as last element but not matched by element.succ" do
+ @range.include?(RangeSpecs::TenfoldSucc.new(99)).should == false
+ end
+
+ it "returns false if other is greater than last element but matched by element.succ" do
+ @range.include?(RangeSpecs::TenfoldSucc.new(100)).should == false
+ end
+ end
+ end
+
+ describe "with Time endpoints" do
+ it "uses cover? logic" do
+ now = Time.now
+ range = (now..(now + 60))
+
+ range.include?(now).should == true
+ range.include?(now - 1).should == false
+ range.include?(now + 60).should == true
+ range.include?(now + 61).should == false
+ end
+ end
+
+ it "does not include U+9995 in the range U+0999..U+9999" do
+ ("\u{999}".."\u{9999}").include?("\u{9995}").should == false
+ end
end
diff --git a/spec/ruby/core/range/initialize_spec.rb b/spec/ruby/core/range/initialize_spec.rb
index 457f048f8a..b1a0565ab2 100644
--- a/spec/ruby/core/range/initialize_spec.rb
+++ b/spec/ruby/core/range/initialize_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Range#initialize" do
before do
@@ -6,36 +6,36 @@ describe "Range#initialize" do
end
it "is private" do
- Range.should have_private_instance_method("initialize")
+ Range.private_instance_methods(false).should.include?(:initialize)
end
it "initializes correctly the Range object when given 2 arguments" do
- lambda { @range.send(:initialize, 0, 1) }.should_not raise_error
+ -> { @range.send(:initialize, 0, 1) }.should_not.raise
end
it "initializes correctly the Range object when given 3 arguments" do
- lambda { @range.send(:initialize, 0, 1, true) }.should_not raise_error
+ -> { @range.send(:initialize, 0, 1, true) }.should_not.raise
end
it "raises an ArgumentError if passed without or with only one argument" do
- lambda { @range.send(:initialize) }.should raise_error(ArgumentError)
- lambda { @range.send(:initialize, 1) }.should raise_error(ArgumentError)
+ -> { @range.send(:initialize) }.should.raise(ArgumentError)
+ -> { @range.send(:initialize, 1) }.should.raise(ArgumentError)
end
it "raises an ArgumentError if passed with four or more arguments" do
- lambda { @range.send(:initialize, 1, 3, 5, 7) }.should raise_error(ArgumentError)
- lambda { @range.send(:initialize, 1, 3, 5, 7, 9) }.should raise_error(ArgumentError)
+ -> { @range.send(:initialize, 1, 3, 5, 7) }.should.raise(ArgumentError)
+ -> { @range.send(:initialize, 1, 3, 5, 7, 9) }.should.raise(ArgumentError)
end
- it "raises a NameError if called on an already initialized Range" do
- lambda { (0..1).send(:initialize, 1, 3) }.should raise_error(NameError)
- lambda { (0..1).send(:initialize, 1, 3, true) }.should raise_error(NameError)
+ it "raises a FrozenError if called on an already initialized Range" do
+ -> { (0..1).send(:initialize, 1, 3) }.should.raise(FrozenError)
+ -> { (0..1).send(:initialize, 1, 3, true) }.should.raise(FrozenError)
end
it "raises an ArgumentError if arguments don't respond to <=>" do
o1 = Object.new
o2 = Object.new
- lambda { @range.send(:initialize, o1, o2) }.should raise_error(ArgumentError)
+ -> { @range.send(:initialize, o1, o2) }.should.raise(ArgumentError)
end
end
diff --git a/spec/ruby/core/range/inspect_spec.rb b/spec/ruby/core/range/inspect_spec.rb
index 8f5de933d3..072de123b7 100644
--- a/spec/ruby/core/range/inspect_spec.rb
+++ b/spec/ruby/core/range/inspect_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Range#inspect" do
it "provides a printable form, using #inspect to convert the start and end objects" do
@@ -12,15 +12,18 @@ describe "Range#inspect" do
(0.5..2.4).inspect.should == "0.5..2.4"
end
- it "returns a tainted string if either end is tainted" do
- (("a".taint)..."c").inspect.tainted?.should be_true
- ("a"...("c".taint)).inspect.tainted?.should be_true
- ("a"..."c").taint.inspect.tainted?.should be_true
+ it "works for endless ranges" do
+ eval("(1..)").inspect.should == "1.."
+ eval("(0.1...)").inspect.should == "0.1..."
end
- it "returns a untrusted string if either end is untrusted" do
- (("a".untrust)..."c").inspect.untrusted?.should be_true
- ("a"...("c".untrust)).inspect.untrusted?.should be_true
- ("a"..."c").untrust.inspect.untrusted?.should be_true
+ it "works for beginless ranges" do
+ (..1).inspect.should == "..1"
+ (...0.1).inspect.should == "...0.1"
+ end
+
+ it "works for nil ... nil ranges" do
+ (..nil).inspect.should == "nil..nil"
+ eval("(nil...)").inspect.should == "nil...nil"
end
end
diff --git a/spec/ruby/core/range/last_spec.rb b/spec/ruby/core/range/last_spec.rb
index 581e04f785..a7db7f85a7 100644
--- a/spec/ruby/core/range/last_spec.rb
+++ b/spec/ruby/core/range/last_spec.rb
@@ -1,13 +1,17 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/end', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/end'
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]
end
+ it "returns the specified number if elements for single element inclusive range" do
+ (1..1).last(1).should == [1]
+ end
+
it "returns an empty array for an empty Range" do
(0...0).last(2).should == []
end
@@ -21,7 +25,7 @@ describe "Range#last" do
end
it "raises an ArgumentError when count is negative" do
- lambda { (0..2).last(-1) }.should raise_error(ArgumentError)
+ -> { (0..2).last(-1) }.should.raise(ArgumentError)
end
it "calls #to_int to convert the argument" do
@@ -32,7 +36,7 @@ describe "Range#last" do
it "raises a TypeError if #to_int does not return an Integer" do
obj = mock("to_int")
obj.should_receive(:to_int).and_return("1")
- lambda { (2..3).last(obj) }.should raise_error(TypeError)
+ -> { (2..3).last(obj) }.should.raise(TypeError)
end
it "truncates the value when passed a Float" do
@@ -40,10 +44,14 @@ describe "Range#last" do
end
it "raises a TypeError when passed nil" do
- lambda { (2..3).last(nil) }.should raise_error(TypeError)
+ -> { (2..3).last(nil) }.should.raise(TypeError)
end
it "raises a TypeError when passed a String" do
- lambda { (2..3).last("1") }.should raise_error(TypeError)
+ -> { (2..3).last("1") }.should.raise(TypeError)
+ end
+
+ it "raises a RangeError when called on an endless range" do
+ -> { eval("(1..)").last }.should.raise(RangeError)
end
end
diff --git a/spec/ruby/core/range/max_spec.rb b/spec/ruby/core/range/max_spec.rb
index 66e40bce1a..57714967ce 100644
--- a/spec/ruby/core/range/max_spec.rb
+++ b/spec/ruby/core/range/max_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Range#max" do
it "returns the maximum value in the range when called with no arguments" do
@@ -14,36 +14,65 @@ describe "Range#max" do
end
it "raises TypeError when called on an exclusive range and a non Integer value" do
- lambda { (303.20...908.1111).max }.should raise_error(TypeError)
+ -> { (303.20...908.1111).max }.should.raise(TypeError)
end
it "returns nil when the endpoint is less than the start point" do
- (100..10).max.should be_nil
- ('z'..'l').max.should be_nil
+ (100..10).max.should == nil
+ ('z'..'l').max.should == nil
end
it "returns nil when the endpoint equals the start point and the range is exclusive" do
- (5...5).max.should be_nil
+ (5...5).max.should == nil
end
it "returns the endpoint when the endpoint equals the start point and the range is inclusive" do
- (5..5).max.should equal(5)
+ (5..5).max.should.equal?(5)
end
it "returns nil when the endpoint is less than the start point in a Float range" do
- (3003.20..908.1111).max.should be_nil
+ (3003.20..908.1111).max.should == nil
end
it "returns end point when the range is Time..Time(included end point)" do
time_start = Time.now
time_end = Time.now + 1.0
- (time_start..time_end).max.should equal(time_end)
+ (time_start..time_end).max.should.equal?(time_end)
end
it "raises TypeError when called on a Time...Time(excluded end point)" do
time_start = Time.now
time_end = Time.now + 1.0
- lambda { (time_start...time_end).max }.should raise_error(TypeError)
+ -> { (time_start...time_end).max }.should.raise(TypeError)
+ end
+
+ it "raises RangeError when called on an endless range" do
+ -> { eval("(1..)").max }.should.raise(RangeError)
+ end
+
+ it "returns the end point for beginless ranges" do
+ (..1).max.should == 1
+ (..1.0).max.should == 1.0
+ end
+
+ ruby_version_is ""..."4.0" do
+ it "raises for an exclusive beginless Integer range" do
+ -> {
+ (...1).max
+ }.should.raise(TypeError, 'cannot exclude end value with non Integer begin value')
+ end
+ end
+
+ ruby_version_is "4.0" do
+ it "returns the end point for exclusive beginless Integer ranges" do
+ (...1).max.should == 0
+ end
+ end
+
+ it "raises for an exclusive beginless non Integer range" do
+ -> {
+ (...1.0).max
+ }.should.raise(TypeError, 'cannot exclude non Integer end value')
end
end
@@ -53,7 +82,7 @@ describe "Range#max given a block" do
(1..10).max {|a,b| acc << [a,b]; a }
acc.flatten!
(1..10).each do |value|
- acc.include?(value).should be_true
+ acc.include?(value).should == true
end
end
@@ -75,8 +104,12 @@ describe "Range#max given a block" do
end
it "returns nil when the endpoint is less than the start point" do
- (100..10).max {|x,y| x <=> y}.should be_nil
- ('z'..'l').max {|x,y| x <=> y}.should be_nil
- (5...5).max {|x,y| x <=> y}.should be_nil
+ (100..10).max {|x,y| x <=> y}.should == nil
+ ('z'..'l').max {|x,y| x <=> y}.should == nil
+ (5...5).max {|x,y| x <=> y}.should == nil
+ end
+
+ it "raises RangeError when called with custom comparison method on an beginless range" do
+ -> { (..1).max {|a, b| a} }.should.raise(RangeError)
end
end
diff --git a/spec/ruby/core/range/member_spec.rb b/spec/ruby/core/range/member_spec.rb
index afcca9bf19..98835e4cf3 100644
--- a/spec/ruby/core/range/member_spec.rb
+++ b/spec/ruby/core/range/member_spec.rb
@@ -1,10 +1,7 @@
-# -*- encoding: ascii-8bit -*-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/cover_and_include', __FILE__)
-require File.expand_path('../shared/include', __FILE__)
-require File.expand_path('../shared/cover', __FILE__)
+require_relative '../../spec_helper'
describe "Range#member?" do
- it_behaves_like :range_cover_and_include, :member?
- it_behaves_like :range_include, :member?
+ it "is an alias of Range#include?" do
+ Range.instance_method(:member?).should == Range.instance_method(:include?)
+ end
end
diff --git a/spec/ruby/core/range/min_spec.rb b/spec/ruby/core/range/min_spec.rb
index b6eebd8c35..9c83d3deca 100644
--- a/spec/ruby/core/range/min_spec.rb
+++ b/spec/ruby/core/range/min_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Range#min" do
it "returns the minimum value in the range when called with no arguments" do
@@ -11,32 +11,41 @@ describe "Range#min" do
end
it "returns nil when the start point is greater than the endpoint" do
- (100..10).min.should be_nil
- ('z'..'l').min.should be_nil
+ (100..10).min.should == nil
+ ('z'..'l').min.should == nil
end
it "returns nil when the endpoint equals the start point and the range is exclusive" do
- (7...7).min.should be_nil
+ (7...7).min.should == nil
end
it "returns the start point when the endpoint equals the start point and the range is inclusive" do
- (7..7).min.should equal(7)
+ (7..7).min.should.equal?(7)
end
it "returns nil when the start point is greater than the endpoint in a Float range" do
- (3003.20..908.1111).min.should be_nil
+ (3003.20..908.1111).min.should == nil
end
it "returns start point when the range is Time..Time(included end point)" do
time_start = Time.now
time_end = Time.now + 1.0
- (time_start..time_end).min.should equal(time_start)
+ (time_start..time_end).min.should.equal?(time_start)
end
it "returns start point when the range is Time...Time(excluded end point)" do
time_start = Time.now
time_end = Time.now + 1.0
- (time_start...time_end).min.should equal(time_start)
+ (time_start...time_end).min.should.equal?(time_start)
+ end
+
+ it "returns the start point for endless ranges" do
+ eval("(1..)").min.should == 1
+ eval("(1.0...)").min.should == 1.0
+ end
+
+ it "raises RangeError when called on an beginless range" do
+ -> { (..1).min }.should.raise(RangeError)
end
end
@@ -46,7 +55,7 @@ describe "Range#min given a block" do
(1..10).min {|a,b| acc << [a,b]; a }
acc.flatten!
(1..10).each do |value|
- acc.include?(value).should be_true
+ acc.include?(value).should == true
end
end
@@ -68,8 +77,12 @@ describe "Range#min given a block" do
end
it "returns nil when the start point is greater than the endpoint" do
- (100..10).min {|x,y| x <=> y}.should be_nil
- ('z'..'l').min {|x,y| x <=> y}.should be_nil
- (7...7).min {|x,y| x <=> y}.should be_nil
+ (100..10).min {|x,y| x <=> y}.should == nil
+ ('z'..'l').min {|x,y| x <=> y}.should == nil
+ (7...7).min {|x,y| x <=> y}.should == nil
+ end
+
+ it "raises RangeError when called with custom comparison method on an endless range" do
+ -> { eval("(1..)").min {|a, b| a} }.should.raise(RangeError)
end
end
diff --git a/spec/ruby/core/range/minmax_spec.rb b/spec/ruby/core/range/minmax_spec.rb
new file mode 100644
index 0000000000..16c7626ea3
--- /dev/null
+++ b/spec/ruby/core/range/minmax_spec.rb
@@ -0,0 +1,130 @@
+require_relative '../../spec_helper'
+
+describe 'Range#minmax' do
+ before(:each) do
+ @x = mock('x')
+ @y = mock('y')
+
+ @x.should_receive(:<=>).with(@y).any_number_of_times.and_return(-1) # x < y
+ @x.should_receive(:<=>).with(@x).any_number_of_times.and_return(0) # x == x
+ @y.should_receive(:<=>).with(@x).any_number_of_times.and_return(1) # y > x
+ @y.should_receive(:<=>).with(@y).any_number_of_times.and_return(0) # y == y
+ end
+
+ describe 'on an inclusive range' do
+ it 'should raise RangeError on an endless range without iterating the range' do
+ @x.should_not_receive(:succ)
+
+ range = (@x..)
+
+ -> { range.minmax }.should.raise(RangeError, 'cannot get the maximum of endless range')
+ end
+
+ it 'raises RangeError or ArgumentError on a beginless range' do
+ range = (..@x)
+
+ -> { range.minmax }.should.raise(StandardError) { |e|
+ if RangeError === e
+ # error from #min
+ -> { raise e }.should.raise(RangeError, 'cannot get the minimum of beginless range')
+ else
+ # error from #max
+ -> { raise e }.should.raise(ArgumentError, 'comparison of NilClass with MockObject failed')
+ end
+ }
+ end
+
+ it 'should return beginning of range if beginning and end are equal without iterating the range' do
+ @x.should_not_receive(:succ)
+
+ (@x..@x).minmax.should == [@x, @x]
+ end
+
+ it 'should return nil pair if beginning is greater than end without iterating the range' do
+ @y.should_not_receive(:succ)
+
+ (@y..@x).minmax.should == [nil, nil]
+ end
+
+ it 'should return the minimum and maximum values for a non-numeric range without iterating the range' do
+ @x.should_not_receive(:succ)
+
+ (@x..@y).minmax.should == [@x, @y]
+ end
+
+ it 'should return the minimum and maximum values for a numeric range' do
+ (1..3).minmax.should == [1, 3]
+ end
+
+ it 'should return the minimum and maximum values for a numeric range without iterating the range' do
+ # We cannot set expectations on integers,
+ # so we "prevent" iteration by picking a value that would iterate until the spec times out.
+ range_end = Float::INFINITY
+
+ (1..range_end).minmax.should == [1, range_end]
+ end
+
+ it 'should return the minimum and maximum values according to the provided block by iterating the range' do
+ @x.should_receive(:succ).once.and_return(@y)
+
+ (@x..@y).minmax { |x, y| - (x <=> y) }.should == [@y, @x]
+ end
+ end
+
+ describe 'on an exclusive range' do
+ it 'should raise RangeError on an endless range' do
+ @x.should_not_receive(:succ)
+ range = (@x...)
+
+ -> { range.minmax }.should.raise(RangeError, 'cannot get the maximum of endless range')
+ end
+
+ it 'should raise RangeError on a beginless range' do
+ range = (...@x)
+
+ -> { range.minmax }.should.raise(RangeError,
+ /cannot get the maximum of beginless range with custom comparison method|cannot get the minimum of beginless range/)
+ end
+
+ it 'should return nil pair if beginning and end are equal without iterating the range' do
+ @x.should_not_receive(:succ)
+
+ (@x...@x).minmax.should == [nil, nil]
+ end
+
+ it 'should return nil pair if beginning is greater than end without iterating the range' do
+ @y.should_not_receive(:succ)
+
+ (@y...@x).minmax.should == [nil, nil]
+ end
+
+ it 'should return the minimum and maximum values for a non-numeric range by iterating the range' do
+ @x.should_receive(:succ).once.and_return(@y)
+
+ (@x...@y).minmax.should == [@x, @x]
+ end
+
+ it 'should return the minimum and maximum values for a numeric range' do
+ (1...3).minmax.should == [1, 2]
+ end
+
+ it 'should return the minimum and maximum values for a numeric range without iterating the range' do
+ # We cannot set expectations on integers,
+ # so we "prevent" iteration by picking a value that would iterate until the spec times out.
+ range_end = bignum_value
+
+ (1...range_end).minmax.should == [1, range_end - 1]
+ end
+
+ it 'raises TypeError if the end value is not an integer' do
+ range = (0...Float::INFINITY)
+ -> { range.minmax }.should.raise(TypeError, 'cannot exclude non Integer end value')
+ end
+
+ it 'should return the minimum and maximum values according to the provided block by iterating the range' do
+ @x.should_receive(:succ).once.and_return(@y)
+
+ (@x...@y).minmax { |x, y| - (x <=> y) }.should == [@x, @x]
+ end
+ end
+end
diff --git a/spec/ruby/core/range/new_spec.rb b/spec/ruby/core/range/new_spec.rb
index f0d24e4aeb..9a35f28c7e 100644
--- a/spec/ruby/core/range/new_spec.rb
+++ b/spec/ruby/core/range/new_spec.rb
@@ -1,4 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Range.new" do
it "constructs a range using the given start and end" do
@@ -24,11 +25,53 @@ describe "Range.new" do
end
it "raises an ArgumentError when the given start and end can't be compared by using #<=>" do
- lambda { Range.new(1, mock('x')) }.should raise_error(ArgumentError)
- lambda { Range.new(mock('x'), mock('y')) }.should raise_error(ArgumentError)
+ -> { Range.new(1, mock('x')) }.should.raise(ArgumentError)
+ -> { Range.new(mock('x'), mock('y')) }.should.raise(ArgumentError)
b = mock('x')
(a = mock('nil')).should_receive(:<=>).with(b).and_return(nil)
- lambda { Range.new(a, b) }.should raise_error(ArgumentError)
+ -> { Range.new(a, b) }.should.raise(ArgumentError)
+ end
+
+ it "does not rescue exception raised in #<=> when compares the given start and end" do
+ b = mock('a')
+ a = mock('b')
+ a.should_receive(:<=>).with(b).and_raise(RangeSpecs::ComparisonError)
+
+ -> { Range.new(a, b) }.should.raise(RangeSpecs::ComparisonError)
+ end
+
+ describe "beginless/endless range" do
+ it "allows beginless left boundary" do
+ range = Range.new(nil, 1)
+ range.begin.should == nil
+ end
+
+ it "distinguishes ranges with included and excluded right boundary" do
+ range_exclude = Range.new(nil, 1, true)
+ range_include = Range.new(nil, 1, false)
+
+ range_exclude.should_not == range_include
+ end
+
+ it "allows endless right boundary" do
+ range = Range.new(1, nil)
+ range.end.should == nil
+ end
+
+ it "distinguishes ranges with included and excluded right boundary" do
+ range_exclude = Range.new(1, nil, true)
+ range_include = Range.new(1, nil, false)
+
+ range_exclude.should_not == range_include
+ end
+
+ it "creates a frozen range if the class is Range.class" do
+ Range.new(1, 2).should.frozen?
+ end
+
+ it "does not create a frozen range if the class is not Range.class" do
+ Class.new(Range).new(1, 2).should_not.frozen?
+ end
end
end
diff --git a/spec/ruby/core/range/overlap_spec.rb b/spec/ruby/core/range/overlap_spec.rb
new file mode 100644
index 0000000000..201cd2b1ff
--- /dev/null
+++ b/spec/ruby/core/range/overlap_spec.rb
@@ -0,0 +1,87 @@
+require_relative '../../spec_helper'
+
+describe "Range#overlap?" do
+ it "returns true if other Range overlaps self" do
+ (0..2).overlap?(1..3).should == true
+ (1..3).overlap?(0..2).should == true
+ (0..2).overlap?(0..2).should == true
+ (0..3).overlap?(1..2).should == true
+ (1..2).overlap?(0..3).should == true
+
+ ('a'..'c').overlap?('b'..'d').should == true
+ end
+
+ it "returns false if other Range does not overlap self" do
+ (0..2).overlap?(3..4).should == false
+ (0..2).overlap?(-4..-1).should == false
+
+ ('a'..'c').overlap?('d'..'f').should == false
+ end
+
+ it "raises TypeError when called with non-Range argument" do
+ -> {
+ (0..2).overlap?(1)
+ }.should.raise(TypeError, "wrong argument type Integer (expected Range)")
+ end
+
+ it "returns true when beginningless and endless Ranges overlap" do
+ (0..2).overlap?(..3).should == true
+ (0..2).overlap?(..1).should == true
+ (0..2).overlap?(..0).should == true
+
+ (..3).overlap?(0..2).should == true
+ (..1).overlap?(0..2).should == true
+ (..0).overlap?(0..2).should == true
+
+ (0..2).overlap?(-1..).should == true
+ (0..2).overlap?(1..).should == true
+ (0..2).overlap?(2..).should == true
+
+ (-1..).overlap?(0..2).should == true
+ (1..).overlap?(0..2).should == true
+ (2..).overlap?(0..2).should == true
+
+ (0..).overlap?(2..).should == true
+ (..0).overlap?(..2).should == true
+ end
+
+ it "returns false when beginningless and endless Ranges do not overlap" do
+ (0..2).overlap?(..-1).should == false
+ (0..2).overlap?(3..).should == false
+
+ (..-1).overlap?(0..2).should == false
+ (3..).overlap?(0..2).should == false
+ end
+
+ it "returns false when Ranges are not compatible" do
+ (0..2).overlap?('a'..'d').should == false
+ end
+
+ it "return false when self is empty" do
+ (2..0).overlap?(1..3).should == false
+ (2...2).overlap?(1..3).should == false
+ (1...1).overlap?(1...1).should == false
+ (2..0).overlap?(2..0).should == false
+
+ ('c'..'a').overlap?('b'..'d').should == false
+ ('a'...'a').overlap?('b'..'d').should == false
+ ('b'...'b').overlap?('b'...'b').should == false
+ ('c'...'a').overlap?('c'...'a').should == false
+ end
+
+ it "return false when other Range is empty" do
+ (1..3).overlap?(2..0).should == false
+ (1..3).overlap?(2...2).should == false
+
+ ('b'..'d').overlap?('c'..'a').should == false
+ ('b'..'d').overlap?('c'...'c').should == false
+ end
+
+ it "takes into account exclusive end" do
+ (0...2).overlap?(2..4).should == false
+ (2..4).overlap?(0...2).should == false
+
+ ('a'...'c').overlap?('c'..'e').should == false
+ ('c'..'e').overlap?('a'...'c').should == false
+ end
+end
diff --git a/spec/ruby/core/range/percent_spec.rb b/spec/ruby/core/range/percent_spec.rb
new file mode 100644
index 0000000000..5ec6770ddb
--- /dev/null
+++ b/spec/ruby/core/range/percent_spec.rb
@@ -0,0 +1,16 @@
+require_relative '../../spec_helper'
+
+describe "Range#%" do
+ it "works as a Range#step" do
+ aseq = (1..10) % 2
+ aseq.class.should == Enumerator::ArithmeticSequence
+ aseq.begin.should == 1
+ aseq.end.should == 10
+ aseq.step.should == 2
+ aseq.to_a.should == [1, 3, 5, 7, 9]
+ end
+
+ it "produces an arithmetic sequence with a percent sign in #inspect" do
+ ((1..10) % 2).inspect.should == "((1..10).%(2))"
+ end
+end
diff --git a/spec/ruby/core/range/range_spec.rb b/spec/ruby/core/range/range_spec.rb
index ca6da29e47..8e9433f8c1 100644
--- a/spec/ruby/core/range/range_spec.rb
+++ b/spec/ruby/core/range/range_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Range" do
it "includes Enumerable" do
diff --git a/spec/ruby/core/range/reverse_each_spec.rb b/spec/ruby/core/range/reverse_each_spec.rb
new file mode 100644
index 0000000000..49790e8b0a
--- /dev/null
+++ b/spec/ruby/core/range/reverse_each_spec.rb
@@ -0,0 +1,125 @@
+require_relative '../../spec_helper'
+
+describe "Range#reverse_each" do
+ it "traverses the Range in reverse order and passes each element to block" do
+ a = []
+ (1..3).reverse_each { |i| a << i }
+ a.should == [3, 2, 1]
+
+ a = []
+ (1...3).reverse_each { |i| a << i }
+ a.should == [2, 1]
+ end
+
+ it "returns self" do
+ r = (1..3)
+ r.reverse_each { |x| }.should.equal?(r)
+ end
+
+ it "returns an Enumerator if no block given" do
+ enum = (1..3).reverse_each
+ enum.should.instance_of?(Enumerator)
+ enum.to_a.should == [3, 2, 1]
+ end
+
+ it "raises a TypeError for endless Ranges of Integers" do
+ -> {
+ (1..).reverse_each.take(3)
+ }.should.raise(TypeError, "can't iterate from NilClass")
+ end
+
+ it "raises a TypeError for endless Ranges of non-Integers" do
+ -> {
+ ("a"..).reverse_each.take(3)
+ }.should.raise(TypeError, "can't iterate from NilClass")
+ end
+
+ context "Integer boundaries" do
+ it "supports beginningless Ranges" do
+ (..5).reverse_each.take(3).should == [5, 4, 3]
+ end
+ end
+
+ context "non-Integer boundaries" do
+ it "uses #succ to iterate a Range of non-Integer elements" do
+ y = mock('y')
+ x = mock('x')
+
+ x.should_receive(:succ).any_number_of_times.and_return(y)
+ x.should_receive(:<=>).with(y).any_number_of_times.and_return(-1)
+ x.should_receive(:<=>).with(x).any_number_of_times.and_return(0)
+ y.should_receive(:<=>).with(x).any_number_of_times.and_return(1)
+ y.should_receive(:<=>).with(y).any_number_of_times.and_return(0)
+
+ a = []
+ (x..y).each { |i| a << i }
+ a.should == [x, y]
+ end
+
+ it "uses #succ to iterate a Range of Strings" do
+ a = []
+ ('A'..'D').reverse_each { |i| a << i }
+ a.should == ['D','C','B','A']
+ end
+
+ it "uses #succ to iterate a Range of Symbols" do
+ a = []
+ (:A..:D).reverse_each { |i| a << i }
+ a.should == [:D, :C, :B, :A]
+ end
+
+ it "raises a TypeError when `begin` value does not respond to #succ" do
+ -> { (Time.now..Time.now).reverse_each { |x| x } }.should.raise(TypeError, /can't iterate from Time/)
+ -> { (//..//).reverse_each { |x| x } }.should.raise(TypeError, /can't iterate from Regexp/)
+ -> { ([]..[]).reverse_each { |x| x } }.should.raise(TypeError, /can't iterate from Array/)
+ end
+
+ it "does not support beginningless Ranges" do
+ -> {
+ (..'a').reverse_each { |x| x }
+ }.should.raise(TypeError, /can't iterate from NilClass/)
+ end
+ end
+
+ context "when no block is given" do
+ describe "returned Enumerator size" do
+ it "returns the Range size when Range size is finite" do
+ (1..3).reverse_each.size.should == 3
+ (1...3).reverse_each.size.should == 2
+
+ (1..3.3).reverse_each.size.should == 3
+ (1...3.3).reverse_each.size.should == 3
+ end
+
+ ruby_version_is ""..."3.4" do
+ it "returns a size when it is not iterable" do
+ (1.1..3).reverse_each.size.should == 2
+ (1.1..3.3).reverse_each.size.should == 3
+ (1.1..nil).reverse_each.size.should == Float::INFINITY
+ (nil..3.3).reverse_each.size.should == Float::INFINITY
+ (nil..nil).reverse_each.size.should == nil
+ end
+ end
+
+ ruby_version_is "3.4" do
+ it "raises TypeError when the range is not iterable" do
+ -> { (1.1..3).reverse_each.size }.should.raise(TypeError, /can't iterate from Integer/)
+ -> { (1.1..3.3).reverse_each.size }.should.raise(TypeError, /can't iterate from Float/)
+ -> { (1.1..nil).reverse_each.size }.should.raise(TypeError, /can't iterate from NilClass/)
+ -> { (nil..3.3).reverse_each.size }.should.raise(TypeError, /can't iterate from Float/)
+ -> { (nil..nil).reverse_each.size }.should.raise(TypeError, /can't iterate from NilClass/)
+ end
+ end
+
+ ruby_bug "#20936", "3.4"..."4.0" do
+ it "returns Infinity when Range size is infinite" do
+ (..3).reverse_each.size.should == Float::INFINITY
+ end
+ end
+
+ it "returns nil when Range size is unknown" do
+ ('a'..'z').reverse_each.size.should == nil
+ end
+ end
+ end
+end
diff --git a/spec/ruby/core/range/shared/cover.rb b/spec/ruby/core/range/shared/cover.rb
index 1d9c008a87..189f3da4bf 100644
--- a/spec/ruby/core/range/shared/cover.rb
+++ b/spec/ruby/core/range/shared/cover.rb
@@ -1,31 +1,31 @@
-# -*- encoding: ascii-8bit -*-
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
+# encoding: binary
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
describe :range_cover, shared: true do
it "uses the range element's <=> to make the comparison" do
a = mock('a')
a.should_receive(:<=>).twice.and_return(-1,-1)
- (a..'z').send(@method, 'b').should be_true
+ (a..'z').send(@method, 'b').should == true
end
it "uses a continuous inclusion test" do
- ('a'..'f').send(@method, 'aa').should be_true
- ('a'..'f').send(@method, 'babe').should be_true
- ('a'..'f').send(@method, 'baby').should be_true
- ('a'..'f').send(@method, 'ga').should be_false
- (-10..-2).send(@method, -2.5).should be_true
+ ('a'..'f').send(@method, 'aa').should == true
+ ('a'..'f').send(@method, 'babe').should == true
+ ('a'..'f').send(@method, 'baby').should == true
+ ('a'..'f').send(@method, 'ga').should == false
+ (-10..-2).send(@method, -2.5).should == true
end
describe "on string elements" do
it "returns true if other is matched by element.succ" do
- ('a'..'c').send(@method, 'b').should be_true
- ('a'...'c').send(@method, 'b').should be_true
+ ('a'..'c').send(@method, 'b').should == true
+ ('a'...'c').send(@method, 'b').should == true
end
it "returns true if other is not matched by element.succ" do
- ('a'..'c').send(@method, 'bc').should be_true
- ('a'...'c').send(@method, 'bc').should be_true
+ ('a'..'c').send(@method, 'bc').should == true
+ ('a'...'c').send(@method, 'bc').should == true
end
end
@@ -36,27 +36,27 @@ describe :range_cover, shared: true do
end
it "returns false if other is less than first element" do
- @range.send(@method, RangeSpecs::TenfoldSucc.new(0)).should be_false
+ @range.send(@method, RangeSpecs::TenfoldSucc.new(0)).should == false
end
it "returns true if other is equal as first element" do
- @range.send(@method, RangeSpecs::TenfoldSucc.new(1)).should be_true
+ @range.send(@method, RangeSpecs::TenfoldSucc.new(1)).should == true
end
it "returns true if other is matched by element.succ" do
- @range.send(@method, RangeSpecs::TenfoldSucc.new(10)).should be_true
+ @range.send(@method, RangeSpecs::TenfoldSucc.new(10)).should == true
end
it "returns true if other is not matched by element.succ" do
- @range.send(@method, RangeSpecs::TenfoldSucc.new(2)).should be_true
+ @range.send(@method, RangeSpecs::TenfoldSucc.new(2)).should == true
end
it "returns true if other is equal as last element but not matched by element.succ" do
- @range.send(@method, RangeSpecs::TenfoldSucc.new(99)).should be_true
+ @range.send(@method, RangeSpecs::TenfoldSucc.new(99)).should == true
end
it "returns false if other is greater than last element but matched by element.succ" do
- @range.send(@method, RangeSpecs::TenfoldSucc.new(100)).should be_false
+ @range.send(@method, RangeSpecs::TenfoldSucc.new(100)).should == false
end
end
@@ -66,28 +66,128 @@ describe :range_cover, shared: true do
end
it "returns false if other is less than first element" do
- @range.send(@method, RangeSpecs::TenfoldSucc.new(0)).should be_false
+ @range.send(@method, RangeSpecs::TenfoldSucc.new(0)).should == false
end
it "returns true if other is equal as first element" do
- @range.send(@method, RangeSpecs::TenfoldSucc.new(1)).should be_true
+ @range.send(@method, RangeSpecs::TenfoldSucc.new(1)).should == true
end
it "returns true if other is matched by element.succ" do
- @range.send(@method, RangeSpecs::TenfoldSucc.new(10)).should be_true
+ @range.send(@method, RangeSpecs::TenfoldSucc.new(10)).should == true
end
it "returns true if other is not matched by element.succ" do
- @range.send(@method, RangeSpecs::TenfoldSucc.new(2)).should be_true
+ @range.send(@method, RangeSpecs::TenfoldSucc.new(2)).should == true
end
it "returns false if other is equal as last element but not matched by element.succ" do
- @range.send(@method, RangeSpecs::TenfoldSucc.new(99)).should be_false
+ @range.send(@method, RangeSpecs::TenfoldSucc.new(99)).should == false
end
it "returns false if other is greater than last element but matched by element.succ" do
- @range.send(@method, RangeSpecs::TenfoldSucc.new(100)).should be_false
+ @range.send(@method, RangeSpecs::TenfoldSucc.new(100)).should == false
end
end
end
end
+
+describe :range_cover_subrange, shared: true do
+ context "range argument" do
+ it "accepts range argument" do
+ (0..10).send(@method, (3..7)).should == true
+ (0..10).send(@method, (3..15)).should == false
+ (0..10).send(@method, (-2..7)).should == false
+
+ (1.1..7.9).send(@method, (2.5..6.5)).should == true
+ (1.1..7.9).send(@method, (2.5..8.5)).should == false
+ (1.1..7.9).send(@method, (0.5..6.5)).should == false
+
+ ('c'..'i').send(@method, ('d'..'f')).should == true
+ ('c'..'i').send(@method, ('d'..'z')).should == false
+ ('c'..'i').send(@method, ('a'..'f')).should == false
+
+ range_10_100 = RangeSpecs::TenfoldSucc.new(10)..RangeSpecs::TenfoldSucc.new(100)
+ range_20_90 = RangeSpecs::TenfoldSucc.new(20)..RangeSpecs::TenfoldSucc.new(90)
+ range_20_110 = RangeSpecs::TenfoldSucc.new(20)..RangeSpecs::TenfoldSucc.new(110)
+ range_0_90 = RangeSpecs::TenfoldSucc.new(0)..RangeSpecs::TenfoldSucc.new(90)
+
+ range_10_100.send(@method, range_20_90).should == true
+ range_10_100.send(@method, range_20_110).should == false
+ range_10_100.send(@method, range_0_90).should == false
+ end
+
+ it "supports boundaries of different comparable types" do
+ (0..10).send(@method, (3.1..7.9)).should == true
+ (0..10).send(@method, (3.1..15.9)).should == false
+ (0..10).send(@method, (-2.1..7.9)).should == false
+ end
+
+ it "returns false if types are not comparable" do
+ (0..10).send(@method, ('a'..'z')).should == false
+ (0..10).send(@method, (RangeSpecs::TenfoldSucc.new(0)..RangeSpecs::TenfoldSucc.new(100))).should == false
+ end
+
+ it "honors exclusion of right boundary (:exclude_end option)" do
+ # Integer
+ (0..10).send(@method, (0..10)).should == true
+ (0...10).send(@method, (0...10)).should == true
+
+ (0..10).send(@method, (0...10)).should == true
+ (0...10).send(@method, (0..10)).should == false
+
+ (0...11).send(@method, (0..10)).should == true
+ (0..10).send(@method, (0...11)).should == true
+
+ # Float
+ (0..10.1).send(@method, (0..10.1)).should == true
+ (0...10.1).send(@method, (0...10.1)).should == true
+
+ (0..10.1).send(@method, (0...10.1)).should == true
+ (0...10.1).send(@method, (0..10.1)).should == false
+
+ (0...11.1).send(@method, (0..10.1)).should == true
+ (0..10.1).send(@method, (0...11.1)).should == false
+ end
+ end
+
+ it "allows self to be a beginless range" do
+ (...10).send(@method, (3..7)).should == true
+ (...10).send(@method, (3..15)).should == false
+
+ (..7.9).send(@method, (2.5..6.5)).should == true
+ (..7.9).send(@method, (2.5..8.5)).should == false
+
+ (..'i').send(@method, ('d'..'f')).should == true
+ (..'i').send(@method, ('d'..'z')).should == false
+ end
+
+ it "allows self to be a endless range" do
+ eval("(0...)").send(@method, (3..7)).should == true
+ eval("(5...)").send(@method, (3..15)).should == false
+
+ eval("(1.1..)").send(@method, (2.5..6.5)).should == true
+ eval("(3.3..)").send(@method, (2.5..8.5)).should == false
+
+ eval("('a'..)").send(@method, ('d'..'f')).should == true
+ eval("('p'..)").send(@method, ('d'..'z')).should == false
+ end
+
+ it "accepts beginless range argument" do
+ (..10).send(@method, (...10)).should == true
+ (0..10).send(@method, (...10)).should == false
+
+ (1.1..7.9).send(@method, (...10.5)).should == false
+
+ ('c'..'i').send(@method, (..'i')).should == false
+ end
+
+ it "accepts endless range argument" do
+ eval("(0..)").send(@method, eval("(0...)")).should == true
+ (0..10).send(@method, eval("(0...)")).should == false
+
+ (1.1..7.9).send(@method, eval("(0.8...)")).should == false
+
+ ('c'..'i').send(@method, eval("('a'..)")).should == false
+ end
+end
diff --git a/spec/ruby/core/range/shared/cover_and_include.rb b/spec/ruby/core/range/shared/cover_and_include.rb
index 4222424571..97721a7307 100644
--- a/spec/ruby/core/range/shared/cover_and_include.rb
+++ b/spec/ruby/core/range/shared/cover_and_include.rb
@@ -1,5 +1,5 @@
-# -*- encoding: ascii-8bit -*-
-require File.expand_path('../../../../spec_helper', __FILE__)
+# encoding: binary
+require_relative '../../../spec_helper'
describe :range_cover_and_include, shared: true do
it "returns true if other is an element of self" do
@@ -19,48 +19,68 @@ describe :range_cover_and_include, shared: true do
(0.5...2.4).send(@method, 2.4).should == false
end
+ it "returns true if other is an element of self for endless ranges" do
+ (1..).send(@method, 2.4).should == true
+ (0.5...).send(@method, 2.4).should == true
+ end
+
+ it "returns true if other is an element of self for beginless ranges" do
+ (..10).send(@method, 2.4).should == true
+ (...10.5).send(@method, 2.4).should == true
+ end
+
+ it "returns false if values are not comparable" do
+ (1..10).send(@method, nil).should == false
+ (1...10).send(@method, nil).should == false
+
+ (..10).send(@method, nil).should == false
+ (...10).send(@method, nil).should == false
+
+ (1..).send(@method, nil).should == false
+ (1...).send(@method, nil).should == false
+ end
+
it "compares values using <=>" do
rng = (1..5)
m = mock("int")
m.should_receive(:coerce).and_return([1, 2])
m.should_receive(:<=>).and_return(1)
- rng.send(@method, m).should be_false
+ rng.send(@method, m).should == false
end
it "raises an ArgumentError without exactly one argument" do
- lambda{ (1..2).send(@method) }.should raise_error(ArgumentError)
- lambda{ (1..2).send(@method, 1, 2) }.should raise_error(ArgumentError)
+ ->{ (1..2).send(@method) }.should.raise(ArgumentError)
+ ->{ (1..2).send(@method, 1, 2) }.should.raise(ArgumentError)
end
it "returns true if argument is equal to the first value of the range" do
- (0..5).send(@method, 0).should be_true
- ('f'..'s').send(@method, 'f').should be_true
+ (0..5).send(@method, 0).should == true
+ ('f'..'s').send(@method, 'f').should == true
end
it "returns true if argument is equal to the last value of the range" do
- (0..5).send(@method, 5).should be_true
- (0...5).send(@method, 4).should be_true
- ('f'..'s').send(@method, 's').should be_true
+ (0..5).send(@method, 5).should == true
+ (0...5).send(@method, 4).should == true
+ ('f'..'s').send(@method, 's').should == true
end
it "returns true if argument is less than the last value of the range and greater than the first value" do
- (20..30).send(@method, 28).should be_true
- ('e'..'h').send(@method, 'g').should be_true
- ("\u{999}".."\u{9999}").send @method, "\u{9995}"
+ (20..30).send(@method, 28).should == true
+ ('e'..'h').send(@method, 'g').should == true
end
it "returns true if argument is sole element in the range" do
- (30..30).send(@method, 30).should be_true
+ (30..30).send(@method, 30).should == true
end
it "returns false if range is empty" do
- (30...30).send(@method, 30).should be_false
- (30...30).send(@method, nil).should be_false
+ (30...30).send(@method, 30).should == false
+ (30...30).send(@method, nil).should == false
end
it "returns false if the range does not contain the argument" do
- ('A'..'C').send(@method, 20.9).should be_false
- ('A'...'C').send(@method, 'C').should be_false
+ ('A'..'C').send(@method, 20.9).should == false
+ ('A'...'C').send(@method, 'C').should == false
end
end
diff --git a/spec/ruby/core/range/shared/equal_value.rb b/spec/ruby/core/range/shared/equal_value.rb
index 0bdcf65c3f..363c6be558 100644
--- a/spec/ruby/core/range/shared/equal_value.rb
+++ b/spec/ruby/core/range/shared/equal_value.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../fixtures/classes', __FILE__)
+require_relative '../fixtures/classes'
describe :range_eql, shared: true do
it "returns true if other has same begin, end, and exclude_end? values" do
@@ -42,4 +42,10 @@ describe :range_eql, shared: true do
b = RangeSpecs::MyRange.new(RangeSpecs::Xs.new(3), RangeSpecs::Xs.new(5))
a.send(@method, b).should == true
end
+
+ it "works for endless Ranges" do
+ eval("(1..)").send(@method, eval("(1..)")).should == true
+ eval("(0.5...)").send(@method, eval("(0.5...)")).should == true
+ eval("(1..)").send(@method, eval("(1...)")).should == false
+ end
end
diff --git a/spec/ruby/core/range/shared/include.rb b/spec/ruby/core/range/shared/include.rb
deleted file mode 100644
index 44fd86f067..0000000000
--- a/spec/ruby/core/range/shared/include.rb
+++ /dev/null
@@ -1,91 +0,0 @@
-# -*- encoding: ascii-8bit -*-
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
-
-describe :range_include, shared: true do
- describe "on string elements" do
- it "returns true if other is matched by element.succ" do
- ('a'..'c').send(@method, 'b').should be_true
- ('a'...'c').send(@method, 'b').should be_true
- end
-
- it "returns false if other is not matched by element.succ" do
- ('a'..'c').send(@method, 'bc').should be_false
- ('a'...'c').send(@method, 'bc').should be_false
- end
- end
-
- describe "with weird succ" do
- describe "when included end value" do
- before :each do
- @range = RangeSpecs::TenfoldSucc.new(1)..RangeSpecs::TenfoldSucc.new(99)
- end
-
- it "returns false if other is less than first element" do
- @range.send(@method, RangeSpecs::TenfoldSucc.new(0)).should be_false
- end
-
- it "returns true if other is equal as first element" do
- @range.send(@method, RangeSpecs::TenfoldSucc.new(1)).should be_true
- end
-
- it "returns true if other is matched by element.succ" do
- @range.send(@method, RangeSpecs::TenfoldSucc.new(10)).should be_true
- end
-
- it "returns false if other is not matched by element.succ" do
- @range.send(@method, RangeSpecs::TenfoldSucc.new(2)).should be_false
- end
-
- it "returns false if other is equal as last element but not matched by element.succ" do
- @range.send(@method, RangeSpecs::TenfoldSucc.new(99)).should be_false
- end
-
- it "returns false if other is greater than last element but matched by element.succ" do
- @range.send(@method, RangeSpecs::TenfoldSucc.new(100)).should be_false
- end
- end
-
- describe "when excluded end value" do
- before :each do
- @range = RangeSpecs::TenfoldSucc.new(1)...RangeSpecs::TenfoldSucc.new(99)
- end
-
- it "returns false if other is less than first element" do
- @range.send(@method, RangeSpecs::TenfoldSucc.new(0)).should be_false
- end
-
- it "returns true if other is equal as first element" do
- @range.send(@method, RangeSpecs::TenfoldSucc.new(1)).should be_true
- end
-
- it "returns true if other is matched by element.succ" do
- @range.send(@method, RangeSpecs::TenfoldSucc.new(10)).should be_true
- end
-
- it "returns false if other is not matched by element.succ" do
- @range.send(@method, RangeSpecs::TenfoldSucc.new(2)).should be_false
- end
-
- it "returns false if other is equal as last element but not matched by element.succ" do
- @range.send(@method, RangeSpecs::TenfoldSucc.new(99)).should be_false
- end
-
- it "returns false if other is greater than last element but matched by element.succ" do
- @range.send(@method, RangeSpecs::TenfoldSucc.new(100)).should be_false
- end
- end
- end
-
- describe "with Time endpoints" do
- it "uses cover? logic" do
- now = Time.now
- range = (now..(now + 60))
-
- range.include?(now).should == true
- range.include?(now - 1).should == false
- range.include?(now + 60).should == true
- range.include?(now + 61).should == false
- end
- end
-end
diff --git a/spec/ruby/core/range/size_spec.rb b/spec/ruby/core/range/size_spec.rb
index ecf0ecf606..3a8843b99d 100644
--- a/spec/ruby/core/range/size_spec.rb
+++ b/spec/ruby/core/range/size_spec.rb
@@ -1,31 +1,92 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Range#size" do
it "returns the number of elements in the range" do
(1..16).size.should == 16
(1...16).size.should == 15
-
- (1.0..16.0).size.should == 16
- (1.0...16.0).size.should == 15
- (1.0..15.9).size.should == 15
- (1.1..16.0).size.should == 15
- (1.1..15.9).size.should == 15
end
it "returns 0 if last is less than first" do
(16..0).size.should == 0
- (16.0..0.0).size.should == 0
- (Float::INFINITY..0).size.should == 0
end
it 'returns Float::INFINITY for increasing, infinite ranges' do
(0..Float::INFINITY).size.should == Float::INFINITY
- (-Float::INFINITY..0).size.should == Float::INFINITY
- (-Float::INFINITY..Float::INFINITY).size.should == Float::INFINITY
+ end
+
+ it 'returns Float::INFINITY for endless ranges if the start is numeric' do
+ eval("(1..)").size.should == Float::INFINITY
+ end
+
+ it 'returns nil for endless ranges if the start is not numeric' do
+ eval("('z'..)").size.should == nil
+ end
+
+ ruby_version_is ""..."3.4" do
+ it 'returns Float::INFINITY for all beginless ranges if the end is numeric' do
+ (..1).size.should == Float::INFINITY
+ (...0.5).size.should == Float::INFINITY
+ end
+
+ it 'returns nil for all beginless ranges if the end is not numeric' do
+ (...'o').size.should == nil
+ end
+
+ it 'returns nil if the start and the end is both nil' do
+ (nil..nil).size.should == nil
+ end
+ end
+
+ ruby_version_is ""..."3.4" do
+ it "returns the number of elements in the range" do
+ (1.0..16.0).size.should == 16
+ (1.0...16.0).size.should == 15
+ (1.0..15.9).size.should == 15
+ (1.1..16.0).size.should == 15
+ (1.1..15.9).size.should == 15
+ end
+
+ it "returns 0 if last is less than first" do
+ (16.0..0.0).size.should == 0
+ (Float::INFINITY..0).size.should == 0
+ end
+
+ it 'returns Float::INFINITY for increasing, infinite ranges' do
+ (-Float::INFINITY..0).size.should == Float::INFINITY
+ (-Float::INFINITY..Float::INFINITY).size.should == Float::INFINITY
+ end
+
+ it 'returns Float::INFINITY for endless ranges if the start is numeric' do
+ eval("(0.5...)").size.should == Float::INFINITY
+ end
+
+ it 'returns nil for endless ranges if the start is not numeric' do
+ eval("([]...)").size.should == nil
+ end
+ end
+
+ ruby_version_is "3.4" do
+ it 'raises TypeError if a range is not iterable' do
+ -> { (1.0..16.0).size }.should.raise(TypeError, /can't iterate from/)
+ -> { (1.0...16.0).size }.should.raise(TypeError, /can't iterate from/)
+ -> { (1.0..15.9).size }.should.raise(TypeError, /can't iterate from/)
+ -> { (1.1..16.0).size }.should.raise(TypeError, /can't iterate from/)
+ -> { (1.1..15.9).size }.should.raise(TypeError, /can't iterate from/)
+ -> { (16.0..0.0).size }.should.raise(TypeError, /can't iterate from/)
+ -> { (Float::INFINITY..0).size }.should.raise(TypeError, /can't iterate from/)
+ -> { (-Float::INFINITY..0).size }.should.raise(TypeError, /can't iterate from/)
+ -> { (-Float::INFINITY..Float::INFINITY).size }.should.raise(TypeError, /can't iterate from/)
+ -> { (..1).size }.should.raise(TypeError, /can't iterate from/)
+ -> { (...0.5).size }.should.raise(TypeError, /can't iterate from/)
+ -> { (..nil).size }.should.raise(TypeError, /can't iterate from/)
+ -> { (...'o').size }.should.raise(TypeError, /can't iterate from/)
+ -> { eval("(0.5...)").size }.should.raise(TypeError, /can't iterate from/)
+ -> { eval("([]...)").size }.should.raise(TypeError, /can't iterate from/)
+ end
end
it "returns nil if first and last are not Numeric" do
- (:a..:z).size.should be_nil
- ('a'..'z').size.should be_nil
+ (:a..:z).size.should == nil
+ ('a'..'z').size.should == nil
end
end
diff --git a/spec/ruby/core/range/step_spec.rb b/spec/ruby/core/range/step_spec.rb
index b5bce66861..faab95d88d 100644
--- a/spec/ruby/core/range/step_spec.rb
+++ b/spec/ruby/core/range/step_spec.rb
@@ -1,146 +1,194 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Range#step" do
before :each do
ScratchPad.record []
end
- it "returns an enumerator when no block is given" do
- enum = (1..10).step(4)
- enum.should be_an_instance_of(Enumerator)
- enum.to_a.should eql([1, 5, 9])
- end
-
it "returns self" do
r = 1..2
- r.step { }.should equal(r)
+ r.step { }.should.equal?(r)
end
- it "raises TypeError if step" do
- obj = mock("mock")
- lambda { (1..10).step(obj) { } }.should raise_error(TypeError)
- end
+ ruby_version_is ""..."3.4" do
+ it "calls #to_int to coerce step to an Integer" do
+ obj = mock("Range#step")
+ obj.should_receive(:to_int).and_return(1)
- it "calls #to_int to coerce step to an Integer" do
- obj = mock("Range#step")
- obj.should_receive(:to_int).and_return(1)
+ (1..2).step(obj) { |x| ScratchPad << x }
+ ScratchPad.recorded.should.eql?([1, 2])
+ end
- (1..2).step(obj) { |x| ScratchPad << x }
- ScratchPad.recorded.should eql([1, 2])
- end
+ it "raises a TypeError if step does not respond to #to_int" do
+ obj = mock("Range#step non-integer")
- it "raises a TypeError if step does not respond to #to_int" do
- obj = mock("Range#step non-integer")
+ -> { (1..2).step(obj) { } }.should.raise(TypeError)
+ end
- lambda { (1..2).step(obj) { } }.should raise_error(TypeError)
- end
+ it "raises a TypeError if #to_int does not return an Integer" do
+ obj = mock("Range#step non-integer")
+ obj.should_receive(:to_int).and_return("1")
- it "raises a TypeError if #to_int does not return an Integer" do
- obj = mock("Range#step non-integer")
- obj.should_receive(:to_int).and_return("1")
+ -> { (1..2).step(obj) { } }.should.raise(TypeError)
+ end
- lambda { (1..2).step(obj) { } }.should raise_error(TypeError)
- end
+ it "raises a TypeError if the first element does not respond to #succ" do
+ obj = mock("Range#step non-comparable")
+ obj.should_receive(:<=>).with(obj).and_return(1)
- it "coerces the argument to integer by invoking to_int" do
- (obj = mock("2")).should_receive(:to_int).and_return(2)
- res = []
- (1..10).step(obj) {|x| res << x}
- res.should == [1, 3, 5, 7, 9]
+ -> { (obj..obj).step { |x| x } }.should.raise(TypeError)
+ end
end
- it "raises a TypeError if the first element does not respond to #succ" do
- obj = mock("Range#step non-comparable")
- obj.should_receive(:<=>).with(obj).and_return(1)
+ ruby_version_is "3.4" do
+ it "calls #coerce to coerce step to an Integer" do
+ obj = mock("Range#step")
+ obj.should_receive(:coerce).at_least(:once).and_return([1, 2])
+
+ (1..3).step(obj) { |x| ScratchPad << x }
+ ScratchPad.recorded.should.eql?([1, 3])
+ end
- lambda { (obj..obj).step { |x| x } }.should raise_error(TypeError)
+ it "raises a TypeError if step does not respond to #coerce" do
+ obj = mock("Range#step non-coercible")
+
+ -> { (1..2).step(obj) { } }.should.raise(TypeError)
+ end
end
it "raises an ArgumentError if step is 0" do
- lambda { (-1..1).step(0) { |x| x } }.should raise_error(ArgumentError)
+ -> { (-1..1).step(0) { |x| x } }.should.raise(ArgumentError)
end
it "raises an ArgumentError if step is 0.0" do
- lambda { (-1..1).step(0.0) { |x| x } }.should raise_error(ArgumentError)
+ -> { (-1..1).step(0.0) { |x| x } }.should.raise(ArgumentError)
end
- it "raises an ArgumentError if step is negative" do
- lambda { (-1..1).step(-2) { |x| x } }.should raise_error(ArgumentError)
+ ruby_version_is "3.4" do
+ it "does not iterate if step is 0 for bounded non-numeric ranges" do
+ t = Time.utc(2023, 2, 24)
+ (t..t + 1).step(0) { |x| ScratchPad << x }
+ ScratchPad.recorded.should == []
+ end
+
+ it "raises an ArgumentError when iterating a beginless range" do
+ -> { (..10).step(1) { break } }.should.raise(ArgumentError,
+ "#step iteration for beginless ranges is meaningless")
+ end
+ end
+
+ ruby_version_is ""..."3.4" do
+ it "raises an ArgumentError if step is negative" do
+ -> { (-1..1).step(-2) { |x| x } }.should.raise(ArgumentError)
+ end
end
describe "with inclusive end" do
describe "and Integer values" do
it "yields Integer values incremented by 1 and less than or equal to end when not passed a step" do
(-2..2).step { |x| ScratchPad << x }
- ScratchPad.recorded.should eql([-2, -1, 0, 1, 2])
+ ScratchPad.recorded.should.eql?([-2, -1, 0, 1, 2])
end
it "yields Integer values incremented by an Integer step" do
(-5..5).step(2) { |x| ScratchPad << x }
- ScratchPad.recorded.should eql([-5, -3, -1, 1, 3, 5])
+ ScratchPad.recorded.should.eql?([-5, -3, -1, 1, 3, 5])
end
it "yields Float values incremented by a Float step" do
(-2..2).step(1.5) { |x| ScratchPad << x }
- ScratchPad.recorded.should eql([-2.0, -0.5, 1.0])
+ ScratchPad.recorded.should.eql?([-2.0, -0.5, 1.0])
+ end
+
+ ruby_version_is "3.4" do
+ it "does not iterate if step is negative for forward range" do
+ (-1..1).step(-1) { |x| ScratchPad << x }
+ ScratchPad.recorded.should.eql?([])
+ end
+
+ it "iterates backward if step is negative for backward range" do
+ (1..-1).step(-1) { |x| ScratchPad << x }
+ ScratchPad.recorded.should.eql?([1, 0, -1])
+ end
end
end
describe "and Float values" do
it "yields Float values incremented by 1 and less than or equal to end when not passed a step" do
(-2.0..2.0).step { |x| ScratchPad << x }
- ScratchPad.recorded.should eql([-2.0, -1.0, 0.0, 1.0, 2.0])
+ ScratchPad.recorded.should.eql?([-2.0, -1.0, 0.0, 1.0, 2.0])
end
it "yields Float values incremented by an Integer step" do
(-5.0..5.0).step(2) { |x| ScratchPad << x }
- ScratchPad.recorded.should eql([-5.0, -3.0, -1.0, 1.0, 3.0, 5.0])
+ ScratchPad.recorded.should.eql?([-5.0, -3.0, -1.0, 1.0, 3.0, 5.0])
end
it "yields Float values incremented by a Float step" do
(-1.0..1.0).step(0.5) { |x| ScratchPad << x }
- ScratchPad.recorded.should eql([-1.0, -0.5, 0.0, 0.5, 1.0])
+ ScratchPad.recorded.should.eql?([-1.0, -0.5, 0.0, 0.5, 1.0])
end
it "returns Float values of 'step * n + begin <= end'" do
(1.0..6.4).step(1.8) { |x| ScratchPad << x }
(1.0..12.7).step(1.3) { |x| ScratchPad << x }
- ScratchPad.recorded.should eql([1.0, 2.8, 4.6, 6.4, 1.0, 2.3, 3.6,
+ ScratchPad.recorded.should.eql?([1.0, 2.8, 4.6, 6.4, 1.0, 2.3, 3.6,
4.9, 6.2, 7.5, 8.8, 10.1, 11.4, 12.7])
end
+
+ it "handles infinite values at either end" do
+ (-Float::INFINITY..0.0).step(2) { |x| ScratchPad << x; break if ScratchPad.recorded.size == 3 }
+ ScratchPad.recorded.should.eql?([-Float::INFINITY, -Float::INFINITY, -Float::INFINITY])
+
+ ScratchPad.record []
+ (0.0..Float::INFINITY).step(2) { |x| ScratchPad << x; break if ScratchPad.recorded.size == 3 }
+ ScratchPad.recorded.should.eql?([0.0, 2.0, 4.0])
+ end
+
+ ruby_version_is "3.4" do
+ it "does not iterate if step is negative for forward range" do
+ (-1.0..1.0).step(-0.5) { |x| ScratchPad << x }
+ ScratchPad.recorded.should.eql?([])
+ end
+
+ it "iterates backward if step is negative for backward range" do
+ (1.0..-1.0).step(-0.5) { |x| ScratchPad << x }
+ ScratchPad.recorded.should.eql?([1.0, 0.5, 0.0, -0.5, -1.0])
+ end
+ end
end
describe "and Integer, Float values" do
it "yields Float values incremented by 1 and less than or equal to end when not passed a step" do
(-2..2.0).step { |x| ScratchPad << x }
- ScratchPad.recorded.should eql([-2.0, -1.0, 0.0, 1.0, 2.0])
+ ScratchPad.recorded.should.eql?([-2.0, -1.0, 0.0, 1.0, 2.0])
end
it "yields Float values incremented by an Integer step" do
(-5..5.0).step(2) { |x| ScratchPad << x }
- ScratchPad.recorded.should eql([-5.0, -3.0, -1.0, 1.0, 3.0, 5.0])
+ ScratchPad.recorded.should.eql?([-5.0, -3.0, -1.0, 1.0, 3.0, 5.0])
end
it "yields Float values incremented by a Float step" do
(-1..1.0).step(0.5) { |x| ScratchPad << x }
- ScratchPad.recorded.should eql([-1.0, -0.5, 0.0, 0.5, 1.0])
+ ScratchPad.recorded.should.eql?([-1.0, -0.5, 0.0, 0.5, 1.0])
end
end
describe "and Float, Integer values" do
it "yields Float values incremented by 1 and less than or equal to end when not passed a step" do
(-2.0..2).step { |x| ScratchPad << x }
- ScratchPad.recorded.should eql([-2.0, -1.0, 0.0, 1.0, 2.0])
+ ScratchPad.recorded.should.eql?([-2.0, -1.0, 0.0, 1.0, 2.0])
end
it "yields Float values incremented by an Integer step" do
(-5.0..5).step(2) { |x| ScratchPad << x }
- ScratchPad.recorded.should eql([-5.0, -3.0, -1.0, 1.0, 3.0, 5.0])
+ ScratchPad.recorded.should.eql?([-5.0, -3.0, -1.0, 1.0, 3.0, 5.0])
end
it "yields Float values incremented by a Float step" do
(-1.0..1).step(0.5) { |x| ScratchPad << x }
- ScratchPad.recorded.should eql([-1.0, -0.5, 0.0, 0.5, 1.0])
+ ScratchPad.recorded.should.eql?([-1.0, -0.5, 0.0, 0.5, 1.0])
end
end
@@ -156,16 +204,99 @@ describe "Range#step" do
end
it "raises a TypeError when passed a Float step" do
- lambda { ("A".."G").step(2.0) { } }.should raise_error(TypeError)
+ -> { ("A".."G").step(2.0) { } }.should.raise(TypeError)
+ end
+
+ ruby_version_is ""..."3.4" do
+ it "calls #succ on begin and each element returned by #succ" do
+ obj = mock("Range#step String start")
+ obj.should_receive(:<=>).exactly(3).times.and_return(-1, -1, -1, 0)
+ obj.should_receive(:succ).exactly(2).times.and_return(obj)
+
+ (obj..obj).step { |x| ScratchPad << x }
+ ScratchPad.recorded.should == [obj, obj, obj]
+ end
end
- it "calls #succ on begin and each element returned by #succ" do
- obj = mock("Range#step String start")
- obj.should_receive(:<=>).exactly(3).times.and_return(-1, -1, -1, 0)
- obj.should_receive(:succ).exactly(2).times.and_return(obj)
+ ruby_version_is "3.4" do
+ it "yields String values adjusted by step and less than or equal to end" do
+ ("A".."AAA").step("A") { |x| ScratchPad << x }
+ ScratchPad.recorded.should == ["A", "AA", "AAA"]
+ end
+
+ it "raises a TypeError when passed an incompatible type step" do
+ -> { ("A".."G").step([]) { } }.should.raise(TypeError)
+ end
+
+ it "calls #+ on begin and each element returned by #+" do
+ start = mock("Range#step String start")
+ stop = mock("Range#step String stop")
+
+ mid1 = mock("Range#step String mid1")
+ mid2 = mock("Range#step String mid2")
+
+ step = mock("Range#step String step")
+
+ # Deciding on the direction of iteration
+ start.should_receive(:<=>).with(stop).at_least(:twice).and_return(-1)
+ # Deciding whether the step moves iteration in the right direction
+ start.should_receive(:<=>).with(mid1).and_return(-1)
+ # Iteration 1
+ start.should_receive(:+).at_least(:once).with(step).and_return(mid1)
+ # Iteration 2
+ mid1.should_receive(:<=>).with(stop).and_return(-1)
+ mid1.should_receive(:+).with(step).and_return(mid2)
+ # Iteration 3
+ mid2.should_receive(:<=>).with(stop).and_return(0)
+
+ (start..stop).step(step) { |x| ScratchPad << x }
+ ScratchPad.recorded.should == [start, mid1, mid2]
+ end
+
+ it "iterates backward if the step is decreasing values, and the range is backward" do
+ start = mock("Range#step String start")
+ stop = mock("Range#step String stop")
+
+ mid1 = mock("Range#step String mid1")
+ mid2 = mock("Range#step String mid2")
+
+ step = mock("Range#step String step")
+
+ # Deciding on the direction of iteration
+ start.should_receive(:<=>).with(stop).at_least(:twice).and_return(1)
+ # Deciding whether the step moves iteration in the right direction
+ start.should_receive(:<=>).with(mid1).and_return(1)
+ # Iteration 1
+ start.should_receive(:+).at_least(:once).with(step).and_return(mid1)
+ # Iteration 2
+ mid1.should_receive(:<=>).with(stop).and_return(1)
+ mid1.should_receive(:+).with(step).and_return(mid2)
+ # Iteration 3
+ mid2.should_receive(:<=>).with(stop).and_return(0)
+
+ (start..stop).step(step) { |x| ScratchPad << x }
+ ScratchPad.recorded.should == [start, mid1, mid2]
+ end
+
+ it "does no iteration of the direction of the range and of the step don't match" do
+ start = mock("Range#step String start")
+ stop = mock("Range#step String stop")
+
+ mid1 = mock("Range#step String mid1")
+ mid2 = mock("Range#step String mid2")
+
+ step = mock("Range#step String step")
- (obj..obj).step { |x| ScratchPad << x }
- ScratchPad.recorded.should == [obj, obj, obj]
+ # Deciding on the direction of iteration: stop > start
+ start.should_receive(:<=>).with(stop).at_least(:twice).and_return(1)
+ # Deciding whether the step moves iteration in the right direction
+ # start + step < start, the direction is opposite to the range's
+ start.should_receive(:+).with(step).and_return(mid1)
+ start.should_receive(:<=>).with(mid1).and_return(-1)
+
+ (start..stop).step(step) { |x| ScratchPad << x }
+ ScratchPad.recorded.should == []
+ end
end
end
end
@@ -174,124 +305,271 @@ describe "Range#step" do
describe "and Integer values" do
it "yields Integer values incremented by 1 and less than end when not passed a step" do
(-2...2).step { |x| ScratchPad << x }
- ScratchPad.recorded.should eql([-2, -1, 0, 1])
+ ScratchPad.recorded.should.eql?([-2, -1, 0, 1])
end
it "yields Integer values incremented by an Integer step" do
(-5...5).step(2) { |x| ScratchPad << x }
- ScratchPad.recorded.should eql([-5, -3, -1, 1, 3])
+ ScratchPad.recorded.should.eql?([-5, -3, -1, 1, 3])
end
it "yields Float values incremented by a Float step" do
(-2...2).step(1.5) { |x| ScratchPad << x }
- ScratchPad.recorded.should eql([-2.0, -0.5, 1.0])
+ ScratchPad.recorded.should.eql?([-2.0, -0.5, 1.0])
end
end
describe "and Float values" do
it "yields Float values incremented by 1 and less than end when not passed a step" do
(-2.0...2.0).step { |x| ScratchPad << x }
- ScratchPad.recorded.should eql([-2.0, -1.0, 0.0, 1.0])
+ ScratchPad.recorded.should.eql?([-2.0, -1.0, 0.0, 1.0])
end
it "yields Float values incremented by an Integer step" do
(-5.0...5.0).step(2) { |x| ScratchPad << x }
- ScratchPad.recorded.should eql([-5.0, -3.0, -1.0, 1.0, 3.0])
+ ScratchPad.recorded.should.eql?([-5.0, -3.0, -1.0, 1.0, 3.0])
end
it "yields Float values incremented by a Float step" do
(-1.0...1.0).step(0.5) { |x| ScratchPad << x }
- ScratchPad.recorded.should eql([-1.0, -0.5, 0.0, 0.5])
+ ScratchPad.recorded.should.eql?([-1.0, -0.5, 0.0, 0.5])
end
it "returns Float values of 'step * n + begin < end'" do
(1.0...6.4).step(1.8) { |x| ScratchPad << x }
+ ScratchPad.recorded.should.eql?([1.0, 2.8, 4.6])
+ end
+
+ it "correctly handles values near the upper limit" do # https://bugs.ruby-lang.org/issues/16612
(1.0...55.6).step(18.2) { |x| ScratchPad << x }
- ScratchPad.recorded.should eql([1.0, 2.8, 4.6, 1.0, 19.2, 37.4])
+ ScratchPad.recorded.should.eql?([1.0, 19.2, 37.4, 55.599999999999994])
+
+ (1.0...55.6).step(18.2).size.should == 4
+ end
+
+ it "handles infinite values at either end" do
+ (-Float::INFINITY...0.0).step(2) { |x| ScratchPad << x; break if ScratchPad.recorded.size == 3 }
+ ScratchPad.recorded.should.eql?([-Float::INFINITY, -Float::INFINITY, -Float::INFINITY])
+
+ ScratchPad.record []
+ (0.0...Float::INFINITY).step(2) { |x| ScratchPad << x; break if ScratchPad.recorded.size == 3 }
+ ScratchPad.recorded.should.eql?([0.0, 2.0, 4.0])
+ end
+
+ ruby_version_is "3.4" do
+ it "iterates backward with exclusive end if step is negative" do
+ (1.0...-1.0).step(-0.5) { |x| ScratchPad << x }
+ ScratchPad.recorded.should.eql?([1.0, 0.5, 0.0, -0.5])
+ end
end
end
describe "and Integer, Float values" do
it "yields Float values incremented by 1 and less than end when not passed a step" do
(-2...2.0).step { |x| ScratchPad << x }
- ScratchPad.recorded.should eql([-2.0, -1.0, 0.0, 1.0])
+ ScratchPad.recorded.should.eql?([-2.0, -1.0, 0.0, 1.0])
end
it "yields Float values incremented by an Integer step" do
(-5...5.0).step(2) { |x| ScratchPad << x }
- ScratchPad.recorded.should eql([-5.0, -3.0, -1.0, 1.0, 3.0])
+ ScratchPad.recorded.should.eql?([-5.0, -3.0, -1.0, 1.0, 3.0])
end
it "yields an Float and then Float values incremented by a Float step" do
(-1...1.0).step(0.5) { |x| ScratchPad << x }
- ScratchPad.recorded.should eql([-1.0, -0.5, 0.0, 0.5])
+ ScratchPad.recorded.should.eql?([-1.0, -0.5, 0.0, 0.5])
end
end
describe "and Float, Integer values" do
it "yields Float values incremented by 1 and less than end when not passed a step" do
(-2.0...2).step { |x| ScratchPad << x }
- ScratchPad.recorded.should eql([-2.0, -1.0, 0.0, 1.0])
+ ScratchPad.recorded.should.eql?([-2.0, -1.0, 0.0, 1.0])
end
it "yields Float values incremented by an Integer step" do
(-5.0...5).step(2) { |x| ScratchPad << x }
- ScratchPad.recorded.should eql([-5.0, -3.0, -1.0, 1.0, 3.0])
+ ScratchPad.recorded.should.eql?([-5.0, -3.0, -1.0, 1.0, 3.0])
end
it "yields Float values incremented by a Float step" do
(-1.0...1).step(0.5) { |x| ScratchPad << x }
- ScratchPad.recorded.should eql([-1.0, -0.5, 0.0, 0.5])
+ ScratchPad.recorded.should.eql?([-1.0, -0.5, 0.0, 0.5])
+ end
+ end
+
+ describe "and String values" do
+ ruby_version_is ""..."3.4" do
+ it "yields String values incremented by #succ and less than or equal to end when not passed a step" do
+ ("A"..."E").step { |x| ScratchPad << x }
+ ScratchPad.recorded.should == ["A", "B", "C", "D"]
+ end
+
+ it "yields String values incremented by #succ called Integer step times" do
+ ("A"..."G").step(2) { |x| ScratchPad << x }
+ ScratchPad.recorded.should == ["A", "C", "E"]
+ end
+
+ it "raises a TypeError when passed a Float step" do
+ -> { ("A"..."G").step(2.0) { } }.should.raise(TypeError)
+ end
+ end
+
+ ruby_version_is "3.4" do
+ it "yields String values adjusted by step and less than or equal to end" do
+ ("A"..."AAA").step("A") { |x| ScratchPad << x }
+ ScratchPad.recorded.should == ["A", "AA"]
+ end
+
+ it "raises a TypeError when passed an incompatible type step" do
+ -> { ("A".."G").step([]) { } }.should.raise(TypeError)
+ end
+ end
+ end
+ end
+
+ describe "with an endless range" do
+ describe "and Integer values" do
+ it "yield Integer values incremented by 1 when not passed a step" do
+ (-2..).step { |x| break if x > 2; ScratchPad << x }
+ ScratchPad.recorded.should.eql?([-2, -1, 0, 1, 2])
+
+ ScratchPad.record []
+ (-2...).step { |x| break if x > 2; ScratchPad << x }
+ ScratchPad.recorded.should.eql?([-2, -1, 0, 1, 2])
+ end
+
+ it "yields Integer values incremented by an Integer step" do
+ (-5..).step(2) { |x| break if x > 3; ScratchPad << x }
+ ScratchPad.recorded.should.eql?([-5, -3, -1, 1, 3])
+
+ ScratchPad.record []
+ (-5...).step(2) { |x| break if x > 3; ScratchPad << x }
+ ScratchPad.recorded.should.eql?([-5, -3, -1, 1, 3])
+ end
+
+ it "yields Float values incremented by a Float step" do
+ (-2..).step(1.5) { |x| break if x > 1.0; ScratchPad << x }
+ ScratchPad.recorded.should.eql?([-2.0, -0.5, 1.0])
+
+ ScratchPad.record []
+ (-2..).step(1.5) { |x| break if x > 1.0; ScratchPad << x }
+ ScratchPad.recorded.should.eql?([-2.0, -0.5, 1.0])
+ end
+ end
+
+ describe "and Float values" do
+ it "yields Float values incremented by 1 and less than end when not passed a step" do
+ (-2.0..).step { |x| break if x > 1.5; ScratchPad << x }
+ ScratchPad.recorded.should.eql?([-2.0, -1.0, 0.0, 1.0])
+
+ ScratchPad.record []
+ (-2.0...).step { |x| break if x > 1.5; ScratchPad << x }
+ ScratchPad.recorded.should.eql?([-2.0, -1.0, 0.0, 1.0])
+ end
+
+ it "yields Float values incremented by an Integer step" do
+ (-5.0..).step(2) { |x| break if x > 3.5; ScratchPad << x }
+ ScratchPad.recorded.should.eql?([-5.0, -3.0, -1.0, 1.0, 3.0])
+
+ ScratchPad.record []
+ (-5.0...).step(2) { |x| break if x > 3.5; ScratchPad << x }
+ ScratchPad.recorded.should.eql?([-5.0, -3.0, -1.0, 1.0, 3.0])
+ end
+
+ it "yields Float values incremented by a Float step" do
+ (-1.0..).step(0.5) { |x| break if x > 0.6; ScratchPad << x }
+ ScratchPad.recorded.should.eql?([-1.0, -0.5, 0.0, 0.5])
+
+ ScratchPad.record []
+ (-1.0...).step(0.5) { |x| break if x > 0.6; ScratchPad << x }
+ ScratchPad.recorded.should.eql?([-1.0, -0.5, 0.0, 0.5])
+ end
+
+ it "computes each value independently to avoid accumulating floating-point errors" do
+ result = []
+ (0.0..).step(0.1) { |x| result << x; break if result.size == 20 }
+ expected = 20.times.map { |i| i * 0.1 + 0.0 }
+ result.should.eql?(expected)
+ end
+
+ it "handles infinite values at the start" do
+ (-Float::INFINITY..).step(2) { |x| ScratchPad << x; break if ScratchPad.recorded.size == 3 }
+ ScratchPad.recorded.should.eql?([-Float::INFINITY, -Float::INFINITY, -Float::INFINITY])
+
+ ScratchPad.record []
+ (-Float::INFINITY...).step(2) { |x| ScratchPad << x; break if ScratchPad.recorded.size == 3 }
+ ScratchPad.recorded.should.eql?([-Float::INFINITY, -Float::INFINITY, -Float::INFINITY])
end
end
describe "and String values" do
it "yields String values incremented by #succ and less than or equal to end when not passed a step" do
- ("A"..."E").step { |x| ScratchPad << x }
+ ('A'..).step { |x| break if x > "D"; ScratchPad << x }
+ ScratchPad.recorded.should == ["A", "B", "C", "D"]
+
+ ScratchPad.record []
+ ('A'...).step { |x| break if x > "D"; ScratchPad << x }
ScratchPad.recorded.should == ["A", "B", "C", "D"]
end
it "yields String values incremented by #succ called Integer step times" do
- ("A"..."G").step(2) { |x| ScratchPad << x }
+ ('A'..).step(2) { |x| break if x > "F"; ScratchPad << x }
+ ScratchPad.recorded.should == ["A", "C", "E"]
+
+ ScratchPad.record []
+ ('A'...).step(2) { |x| break if x > "F"; ScratchPad << x }
ScratchPad.recorded.should == ["A", "C", "E"]
end
it "raises a TypeError when passed a Float step" do
- lambda { ("A"..."G").step(2.0) { } }.should raise_error(TypeError)
+ -> { ('A'..).step(2.0) { } }.should.raise(TypeError)
+ -> { ('A'...).step(2.0) { } }.should.raise(TypeError)
end
- end
- end
- describe "when no block is given" do
- describe "returned Enumerator" do
- describe "size" do
- it "raises a TypeError if step does not respond to #to_int" do
- obj = mock("Range#step non-integer")
- enum = (1..2).step(obj)
- lambda { enum.size }.should raise_error(TypeError)
- end
-
- it "raises a TypeError if #to_int does not return an Integer" do
- obj = mock("Range#step non-integer")
- obj.should_receive(:to_int).and_return("1")
- enum = (1..2).step(obj)
+ ruby_version_is "3.4" do
+ it "yields String values adjusted by step" do
+ ('A'..).step("A") { |x| break if x > "AAA"; ScratchPad << x }
+ ScratchPad.recorded.should == ["A", "AA", "AAA"]
- lambda { enum.size }.should raise_error(TypeError)
+ ScratchPad.record []
+ ('A'...).step("A") { |x| break if x > "AAA"; ScratchPad << x }
+ ScratchPad.recorded.should == ["A", "AA", "AAA"]
end
- it "raises an ArgumentError if step is 0" do
- enum = (-1..1).step(0)
- lambda { enum.size }.should raise_error(ArgumentError)
+ it "raises a TypeError when passed an incompatible type step" do
+ -> { ('A'..).step([]) { } }.should.raise(TypeError)
+ -> { ('A'...).step([]) { } }.should.raise(TypeError)
end
+ end
+ end
+ end
+
+ describe "when no block is given" do
+ it "raises an ArgumentError if step is 0" do
+ -> { (-1..1).step(0) }.should.raise(ArgumentError)
+ end
- it "raises an ArgumentError if step is 0.0" do
- enum = (-1..1).step(0.0)
- lambda { enum.size }.should raise_error(ArgumentError)
+ describe "returned Enumerator" do
+ describe "size" do
+ ruby_version_is ""..."3.4" do
+ it "raises a TypeError if step does not respond to #to_int" do
+ obj = mock("Range#step non-integer")
+ -> { (1..2).step(obj) }.should.raise(TypeError)
+ end
+
+ it "raises a TypeError if #to_int does not return an Integer" do
+ obj = mock("Range#step non-integer")
+ obj.should_receive(:to_int).and_return("1")
+ -> { (1..2).step(obj) }.should.raise(TypeError)
+ end
end
- it "raises an ArgumentError if step is negative" do
- enum = (-1..1).step(-2)
- lambda { enum.size }.should raise_error(ArgumentError)
+ ruby_version_is "3.4" do
+ it "does not raise if step is incompatible" do
+ obj = mock("Range#step non-integer")
+ -> { (1..2).step(obj) }.should_not.raise
+ end
end
it "returns the ceil of range size divided by the number of steps" do
@@ -307,6 +585,11 @@ describe "Range#step" do
(-5...5).step(2).size.should == 5
end
+ it "returns the ceil of range size divided by the number of steps even if step is negative" do
+ (-1..1).step(-1).size.should == 0
+ (1..-1).step(-1).size.should == 3
+ end
+
it "returns the correct number of steps when one of the arguments is a float" do
(-1..1.0).step(0.5).size.should == 5
(-1.0...1.0).step(0.5).size.should == 4
@@ -324,22 +607,117 @@ describe "Range#step" do
(-2...2.0).step.size.should == 4
(-2.0...2).step.size.should == 4
(1.0...6.4).step(1.8).size.should == 3
- (1.0...55.6).step(18.2).size.should == 3
end
- it "returns nil with begin and end are String" do
- ("A".."E").step(2).size.should == nil
- ("A"..."E").step(2).size.should == nil
- ("A".."E").step.size.should == nil
- ("A"..."E").step.size.should == nil
+ ruby_version_is ""..."3.4" do
+ it "returns nil with begin and end are String" do
+ ("A".."E").step(2).size.should == nil
+ ("A"..."E").step(2).size.should == nil
+ ("A".."E").step.size.should == nil
+ ("A"..."E").step.size.should == nil
+ end
+
+ it "return nil and not raises a TypeError if the first element does not respond to #succ" do
+ obj = mock("Range#step non-comparable")
+ obj.should_receive(:<=>).with(obj).and_return(1)
+ enum = (obj..obj).step
+ -> { enum.size }.should_not.raise
+ enum.size.should == nil
+ end
+ end
+
+ ruby_version_is "3.4" do
+ it "returns nil with begin and end are String" do
+ ("A".."E").step("A").size.should == nil
+ ("A"..."E").step("A").size.should == nil
+ end
+
+ it "return nil and not raises a TypeError if the first element is not of compatible type" do
+ obj = mock("Range#step non-comparable")
+ obj.should_receive(:<=>).with(obj).and_return(1)
+ enum = (obj..obj).step(obj)
+ -> { enum.size }.should_not.raise
+ enum.size.should == nil
+ end
+ end
+ end
+
+ # We use .take below to ensure the enumerator works
+ # because that's an Enumerable method and so it uses the Enumerator behavior
+ # not just a method overridden in Enumerator::ArithmeticSequence.
+ describe "type" do
+ context "when both begin and end are numerics" do
+ it "returns an instance of Enumerator::ArithmeticSequence" do
+ (1..10).step.class.should == Enumerator::ArithmeticSequence
+ (1..10).step(3).take(4).should == [1, 4, 7, 10]
+ end
+ end
+
+ context "when begin is not defined and end is numeric" do
+ it "returns an instance of Enumerator::ArithmeticSequence" do
+ (..10).step.class.should == Enumerator::ArithmeticSequence
+ end
+ end
+
+ context "when range is endless" do
+ it "returns an instance of Enumerator::ArithmeticSequence when begin is numeric" do
+ (1..).step.class.should == Enumerator::ArithmeticSequence
+ (1..).step(2).take(3).should == [1, 3, 5]
+ end
+
+ ruby_version_is ""..."3.4" do
+ it "returns an instance of Enumerator when begin is not numeric" do
+ ("a"..).step.class.should == Enumerator
+ ("a"..).step(2).take(3).should == %w[a c e]
+ end
+ end
+
+ ruby_version_is "3.4" do
+ it "returns an instance of Enumerator when begin is not numeric" do
+ ("a"..).step("a").class.should == Enumerator
+ ("a"..).step("a").take(3).should == %w[a aa aaa]
+ end
+ end
+ end
+
+ context "when range is beginless and endless" do
+ ruby_version_is ""..."3.4" do
+ it "returns an instance of Enumerator" do
+ Range.new(nil, nil).step.class.should == Enumerator
+ end
+ end
+
+ ruby_version_is "3.4" do
+ it "raises an ArgumentError" do
+ -> { Range.new(nil, nil).step(1) }.should.raise(ArgumentError,
+ "#step for non-numeric beginless ranges is meaningless")
+ end
+ end
+ end
+
+ context "when range is beginless and finite" do
+ ruby_version_is "3.4" do
+ it "raises an ArgumentError if step is non-numeric" do
+ -> { (..10).step("a") }.should.raise(ArgumentError,
+ "#step for non-numeric beginless ranges is meaningless")
+ end
+ end
end
- it "return nil and not raises a TypeError if the first element does not respond to #succ" do
- obj = mock("Range#step non-comparable")
- obj.should_receive(:<=>).with(obj).and_return(1)
- enum = (obj..obj).step
- lambda { enum.size }.should_not raise_error
- enum.size.should == nil
+ context "when begin and end are not numerics" do
+ ruby_version_is ""..."3.4" do
+ it "returns an instance of Enumerator" do
+ ("a".."z").step.class.should == Enumerator
+ ("a".."z").step(3).take(4).should == %w[a d g j]
+ end
+ end
+
+ ruby_version_is "3.4" do
+ it "returns an instance of Enumerator" do
+ ("a".."z").step("a").class.should == Enumerator
+ ("a".."z").step("a").take(4).should == %w[a aa aaa aaaa]
+ end
+ end
end
end
end
diff --git a/spec/ruby/core/range/to_a_spec.rb b/spec/ruby/core/range/to_a_spec.rb
index d1b838295b..6221ae5f71 100644
--- a/spec/ruby/core/range/to_a_spec.rb
+++ b/spec/ruby/core/range/to_a_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Range#to_a" do
it "converts self to an array" do
@@ -6,7 +6,7 @@ describe "Range#to_a" do
('A'..'D').to_a.should == ['A','B','C','D']
('A'...'D').to_a.should == ['A','B','C']
(0xfffd...0xffff).to_a.should == [0xfffd,0xfffe]
- lambda { (0.5..2.4).to_a }.should raise_error(TypeError)
+ -> { (0.5..2.4).to_a }.should.raise(TypeError)
end
it "returns empty array for descending-ordered" do
@@ -16,7 +16,24 @@ describe "Range#to_a" do
(0xffff...0xfffd).to_a.should == []
end
+ it "works with Ranges of 64-bit integers" do
+ large = 1 << 40
+ (large..large+1).to_a.should == [1099511627776, 1099511627777]
+ end
+
it "works with Ranges of Symbols" do
(:A..:z).to_a.size.should == 58
end
+
+ it "works for non-ASCII ranges" do
+ ('Σ'..'Ω').to_a.should == ["Σ", "Τ", "Υ", "Φ", "Χ", "Ψ", "Ω"]
+ end
+
+ it "throws an exception for endless ranges" do
+ -> { eval("(1..)").to_a }.should.raise(RangeError)
+ end
+
+ it "throws an exception for beginless ranges" do
+ -> { (..1).to_a }.should.raise(TypeError)
+ end
end
diff --git a/spec/ruby/core/range/to_s_spec.rb b/spec/ruby/core/range/to_s_spec.rb
index b59849fc57..460c330912 100644
--- a/spec/ruby/core/range/to_s_spec.rb
+++ b/spec/ruby/core/range/to_s_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Range#to_s" do
it "provides a printable form of self" do
@@ -11,15 +11,13 @@ describe "Range#to_s" do
(0.5..2.4).to_s.should == "0.5..2.4"
end
- it "returns a tainted string if either end is tainted" do
- (("a".taint)..."c").to_s.tainted?.should be_true
- ("a"...("c".taint)).to_s.tainted?.should be_true
- ("a"..."c").taint.to_s.tainted?.should be_true
+ it "can show endless ranges" do
+ eval("(1..)").to_s.should == "1.."
+ eval("(1.0...)").to_s.should == "1.0..."
end
- it "returns a untrusted string if either end is untrusted" do
- (("a".untrust)..."c").to_s.untrusted?.should be_true
- ("a"...("c".untrust)).to_s.untrusted?.should be_true
- ("a"..."c").untrust.to_s.untrusted?.should be_true
+ it "can show beginless ranges" do
+ (..1).to_s.should == "..1"
+ (...1.0).to_s.should == "...1.0"
end
end
diff --git a/spec/ruby/core/range/to_set_spec.rb b/spec/ruby/core/range/to_set_spec.rb
new file mode 100644
index 0000000000..ac81d2cc4b
--- /dev/null
+++ b/spec/ruby/core/range/to_set_spec.rb
@@ -0,0 +1,54 @@
+require_relative '../../spec_helper'
+require_relative '../enumerable/fixtures/classes'
+
+describe "Range#to_set" do
+ it "returns a new Set created from self" do
+ (1..4).to_set.should == Set[1, 2, 3, 4]
+ (1...4).to_set.should == Set[1, 2, 3]
+ end
+
+ it "passes down passed blocks" do
+ (1..3).to_set { |x| x * x }.should == Set[1, 4, 9]
+ end
+
+ it "raises a TypeError for a beginningless range" do
+ -> {
+ (..0).to_set
+ }.should.raise(TypeError, "can't iterate from NilClass")
+ end
+
+ ruby_version_is "4.0" do
+ it "raises a RangeError if the range is endless" do
+ -> { (1..).to_set }.should.raise(RangeError, "cannot convert endless range to a set")
+ -> { (1...).to_set }.should.raise(RangeError, "cannot convert endless range to a set")
+ end
+ end
+
+ context "given positional arguments" do
+ ruby_version_is ""..."4.0" do
+ it "instantiates an object of provided as the first argument set class" do
+ set = (1..3).to_set(EnumerableSpecs::SetSubclass)
+ set.should.is_a?(EnumerableSpecs::SetSubclass)
+ set.to_a.sort.should == [1, 2, 3]
+ end
+ end
+
+ ruby_version_is "4.0"..."4.1" do
+ it "instantiates an object of provided as the first argument set class and warns" do
+ -> {
+ set = (1..3).to_set(EnumerableSpecs::SetSubclass)
+ set.should.is_a?(EnumerableSpecs::SetSubclass)
+ set.to_a.sort.should == [1, 2, 3]
+ }.should complain(/warning: passing arguments to Enumerable#to_set is deprecated/)
+ end
+ end
+
+ ruby_version_is "4.1" do
+ it "does not accept any positional argument" do
+ -> {
+ (1..3).to_set(EnumerableSpecs::SetSubclass)
+ }.should.raise(ArgumentError, "wrong number of arguments (given 1, expected 0)")
+ end
+ end
+ end
+end
diff --git a/spec/ruby/core/rational/abs_spec.rb b/spec/ruby/core/rational/abs_spec.rb
index b04cbd2020..6bb4a0fbef 100644
--- a/spec/ruby/core/rational/abs_spec.rb
+++ b/spec/ruby/core/rational/abs_spec.rb
@@ -1,5 +1,11 @@
-require File.expand_path('../../../shared/rational/abs', __FILE__)
+require_relative "../../spec_helper"
describe "Rational#abs" do
- it_behaves_like(:rational_abs, :abs)
+ it "returns self's absolute value" do
+ Rational(3, 4).abs.should == Rational(3, 4)
+ Rational(-3, 4).abs.should == Rational(3, 4)
+ Rational(3, -4).abs.should == Rational(3, 4)
+
+ Rational(bignum_value, -bignum_value).abs.should == Rational(bignum_value, bignum_value)
+ end
end
diff --git a/spec/ruby/core/rational/ceil_spec.rb b/spec/ruby/core/rational/ceil_spec.rb
index e7aca07d33..0464eab101 100644
--- a/spec/ruby/core/rational/ceil_spec.rb
+++ b/spec/ruby/core/rational/ceil_spec.rb
@@ -1,5 +1,48 @@
-require File.expand_path('../../../shared/rational/ceil', __FILE__)
+require_relative "../../spec_helper"
+require_relative "../integer/shared/integer_ceil_precision"
describe "Rational#ceil" do
- it_behaves_like(:rational_ceil, :ceil)
+ context "with values equal to integers" do
+ it_behaves_like :integer_ceil_precision, :Rational
+ end
+
+ before do
+ @rational = Rational(2200, 7)
+ end
+
+ describe "with no arguments (precision = 0)" do
+ it "returns the Integer value rounded toward positive infinity" do
+ @rational.ceil.should.eql? 315
+
+ Rational(1, 2).ceil.should.eql? 1
+ Rational(-1, 2).ceil.should.eql? 0
+ Rational(1, 1).ceil.should.eql? 1
+ end
+ end
+
+ describe "with a precision < 0" do
+ it "moves the rounding point n decimal places left, returning an Integer" do
+ @rational.ceil(-3).should.eql? 1000
+ @rational.ceil(-2).should.eql? 400
+ @rational.ceil(-1).should.eql? 320
+
+ Rational(100, 2).ceil(-1).should.eql? 50
+ Rational(100, 2).ceil(-2).should.eql? 100
+ Rational(-100, 2).ceil(-1).should.eql?(-50)
+ Rational(-100, 2).ceil(-2).should.eql?(0)
+ end
+ end
+
+ describe "with precision > 0" do
+ it "moves the rounding point n decimal places right, returning a Rational" do
+ @rational.ceil(1).should.eql? Rational(3143, 10)
+ @rational.ceil(2).should.eql? Rational(31429, 100)
+ @rational.ceil(3).should.eql? Rational(157143, 500)
+
+ Rational(100, 2).ceil(1).should.eql? Rational(50, 1)
+ Rational(100, 2).ceil(2).should.eql? Rational(50, 1)
+ Rational(-100, 2).ceil(1).should.eql? Rational(-50, 1)
+ Rational(-100, 2).ceil(2).should.eql? Rational(-50, 1)
+ end
+ end
end
diff --git a/spec/ruby/core/rational/coerce_spec.rb b/spec/ruby/core/rational/coerce_spec.rb
deleted file mode 100644
index 2cfe1db415..0000000000
--- a/spec/ruby/core/rational/coerce_spec.rb
+++ /dev/null
@@ -1,5 +0,0 @@
-require File.expand_path('../../../shared/rational/coerce', __FILE__)
-
-describe "Rational#coerce" do
- 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 47e3ab043d..482e904989 100644
--- a/spec/ruby/core/rational/comparison_spec.rb
+++ b/spec/ruby/core/rational/comparison_spec.rb
@@ -1,21 +1,93 @@
-require File.expand_path('../../../shared/rational/comparison', __FILE__)
+require_relative "../../spec_helper"
+require_relative 'fixtures/rational'
describe "Rational#<=> when passed a Rational object" do
- it_behaves_like(:rational_cmp_rat, :<=>)
+ it "returns 1 when self is greater than the passed argument" do
+ (Rational(4, 4) <=> Rational(3, 4)).should.equal?(1)
+ (Rational(-3, 4) <=> Rational(-4, 4)).should.equal?(1)
+ end
+
+ it "returns 0 when self is equal to the passed argument" do
+ (Rational(4, 4) <=> Rational(4, 4)).should.equal?(0)
+ (Rational(-3, 4) <=> Rational(-3, 4)).should.equal?(0)
+ end
+
+ it "returns -1 when self is less than the passed argument" do
+ (Rational(3, 4) <=> Rational(4, 4)).should.equal?(-1)
+ (Rational(-4, 4) <=> Rational(-3, 4)).should.equal?(-1)
+ end
end
-describe "Rational#<=> when passed a Integer object" do
- it_behaves_like(:rational_cmp_int, :<=>)
+describe "Rational#<=> when passed an Integer object" do
+ it "returns 1 when self is greater than the passed argument" do
+ (Rational(4, 4) <=> 0).should.equal?(1)
+ (Rational(4, 4) <=> -10).should.equal?(1)
+ (Rational(-3, 4) <=> -1).should.equal?(1)
+ end
+
+ it "returns 0 when self is equal to the passed argument" do
+ (Rational(4, 4) <=> 1).should.equal?(0)
+ (Rational(-8, 4) <=> -2).should.equal?(0)
+ end
+
+ it "returns -1 when self is less than the passed argument" do
+ (Rational(3, 4) <=> 1).should.equal?(-1)
+ (Rational(-4, 4) <=> 0).should.equal?(-1)
+ end
end
describe "Rational#<=> when passed a Float object" do
- it_behaves_like(:rational_cmp_float, :<=>)
+ it "returns 1 when self is greater than the passed argument" do
+ (Rational(4, 4) <=> 0.5).should.equal?(1)
+ (Rational(4, 4) <=> -1.5).should.equal?(1)
+ (Rational(-3, 4) <=> -0.8).should.equal?(1)
+ end
+
+ it "returns 0 when self is equal to the passed argument" do
+ (Rational(4, 4) <=> 1.0).should.equal?(0)
+ (Rational(-6, 4) <=> -1.5).should.equal?(0)
+ end
+
+ it "returns -1 when self is less than the passed argument" do
+ (Rational(3, 4) <=> 1.2).should.equal?(-1)
+ (Rational(-4, 4) <=> 0.5).should.equal?(-1)
+ end
end
describe "Rational#<=> when passed an Object that responds to #coerce" do
- it_behaves_like(:rational_cmp_coerce, :<=>)
+ it "calls #coerce on the passed argument with self" do
+ rational = Rational(3, 4)
+
+ obj = mock("Object")
+ obj.should_receive(:coerce).with(rational).and_return([1, 2])
+
+ rational <=> obj
+ end
+
+ it "calls #<=> on the coerced Rational with the coerced Object" do
+ rational = Rational(3, 4)
+
+ coerced_rational = mock("Coerced Rational")
+ coerced_rational.should_receive(:<=>).and_return(:result)
+
+ coerced_obj = mock("Coerced Object")
+
+ obj = mock("Object")
+ obj.should_receive(:coerce).and_return([coerced_rational, coerced_obj])
+
+ (rational <=> obj).should == :result
+ end
+
+ it "does not rescue exception raised in other#coerce" do
+ b = mock("numeric with failed #coerce")
+ b.should_receive(:coerce).and_raise(RationalSpecs::CoerceError)
+
+ -> { Rational(3, 4) <=> b }.should.raise(RationalSpecs::CoerceError)
+ end
end
describe "Rational#<=> when passed a non-Numeric Object that doesn't respond to #coerce" do
- it_behaves_like(:rational_cmp_other, :<=>)
+ it "returns nil" do
+ (Rational <=> mock("Object")).should == nil
+ end
end
diff --git a/spec/ruby/core/rational/denominator_spec.rb b/spec/ruby/core/rational/denominator_spec.rb
index ac2795ded1..ba6e936d60 100644
--- a/spec/ruby/core/rational/denominator_spec.rb
+++ b/spec/ruby/core/rational/denominator_spec.rb
@@ -1,5 +1,14 @@
-require File.expand_path('../../../shared/rational/denominator', __FILE__)
+require_relative "../../spec_helper"
describe "Rational#denominator" do
- it_behaves_like(:rational_denominator, :denominator)
+ it "returns the denominator" do
+ Rational(3, 4).denominator.should.equal?(4)
+ Rational(3, -4).denominator.should.equal?(4)
+
+ Rational(1, bignum_value).denominator.should == bignum_value
+ end
+
+ it "returns 1 if no denominator was given" do
+ Rational(80).denominator.should == 1
+ end
end
diff --git a/spec/ruby/core/rational/div_spec.rb b/spec/ruby/core/rational/div_spec.rb
index 1fd304b646..a679663543 100644
--- a/spec/ruby/core/rational/div_spec.rb
+++ b/spec/ruby/core/rational/div_spec.rb
@@ -1,17 +1,54 @@
-require File.expand_path('../../../shared/rational/div', __FILE__)
+require_relative "../../spec_helper"
describe "Rational#div" do
- it_behaves_like(:rational_div, :div)
+ it "returns an Integer" do
+ Rational(229, 21).div(82).should.is_a?(Integer)
+ end
+
+ it "raises an ArgumentError if passed more than one argument" do
+ -> { Rational(3, 4).div(2,3) }.should.raise(ArgumentError)
+ end
+
+ # See http://redmine.ruby-lang.org/issues/show/1648
+ it "raises a TypeError if passed a non-numeric argument" do
+ -> { Rational(3, 4).div([]) }.should.raise(TypeError)
+ end
end
describe "Rational#div passed a Rational" do
- it_behaves_like(:rational_div_rat, :div)
+ it "performs integer division and returns the result" do
+ Rational(2, 3).div(Rational(2, 3)).should == 1
+ Rational(-2, 9).div(Rational(-9, 2)).should == 0
+ end
+
+ it "raises a ZeroDivisionError when the argument has a numerator of 0" do
+ -> { Rational(3, 4).div(Rational(0, 3)) }.should.raise(ZeroDivisionError)
+ end
+
+ it "raises a ZeroDivisionError when the argument has a numerator of 0.0" do
+ -> { Rational(3, 4).div(Rational(0.0, 3)) }.should.raise(ZeroDivisionError)
+ end
end
describe "Rational#div passed an Integer" do
- it_behaves_like(:rational_div_int, :div)
+ it "performs integer division and returns the result" do
+ Rational(2, 1).div(1).should == 2
+ Rational(25, 5).div(-50).should == -1
+ end
+
+ it "raises a ZeroDivisionError when the argument is 0" do
+ -> { Rational(3, 4).div(0) }.should.raise(ZeroDivisionError)
+ end
end
describe "Rational#div passed a Float" do
- it_behaves_like(:rational_div_float, :div)
+ it "performs integer division and returns the result" do
+ Rational(2, 3).div(30.333).should == 0
+ Rational(2, 9).div(Rational(-8.6)).should == -1
+ Rational(3.12).div(0.5).should == 6
+ end
+
+ it "raises a ZeroDivisionError when the argument is 0.0" do
+ -> { Rational(3, 4).div(0.0) }.should.raise(ZeroDivisionError)
+ end
end
diff --git a/spec/ruby/core/rational/divide_spec.rb b/spec/ruby/core/rational/divide_spec.rb
index 75e447878c..c45d1fca2f 100644
--- a/spec/ruby/core/rational/divide_spec.rb
+++ b/spec/ruby/core/rational/divide_spec.rb
@@ -1,17 +1,74 @@
-require File.expand_path('../../../shared/rational/divide', __FILE__)
+require_relative "../../spec_helper"
+require_relative 'shared/arithmetic_exception_in_coerce'
describe "Rational#/" do
- it_behaves_like(:rational_divide, :/)
+ it "calls #coerce on the passed argument with self" do
+ rational = Rational(3, 4)
+ obj = mock("Object")
+ obj.should_receive(:coerce).with(rational).and_return([1, 2])
+
+ rational / obj
+ end
+
+ it "calls #/ on the coerced Rational with the coerced Object" do
+ rational = Rational(3, 4)
+
+ coerced_rational = mock("Coerced Rational")
+ coerced_rational.should_receive(:/).and_return(:result)
+
+ coerced_obj = mock("Coerced Object")
+
+ obj = mock("Object")
+ obj.should_receive(:coerce).and_return([coerced_rational, coerced_obj])
+
+ (rational / obj).should == :result
+ end
+
+ it_behaves_like :rational_arithmetic_exception_in_coerce, :/
end
describe "Rational#/ when passed an Integer" do
- it_behaves_like(:rational_divide_int, :/)
+ it "returns self divided by other as a Rational" do
+ (Rational(3, 4) / 2).should.eql?(Rational(3, 8))
+ (Rational(2, 4) / 2).should.eql?(Rational(1, 4))
+ (Rational(6, 7) / -2).should.eql?(Rational(-3, 7))
+ end
+
+ it "raises a ZeroDivisionError when passed 0" do
+ -> { Rational(3, 4) / 0 }.should.raise(ZeroDivisionError)
+ end
end
describe "Rational#/ when passed a Rational" do
- it_behaves_like(:rational_divide_rat, :/)
+ it "returns self divided by other as a Rational" do
+ (Rational(3, 4) / Rational(3, 4)).should.eql?(Rational(1, 1))
+ (Rational(2, 4) / Rational(1, 4)).should.eql?(Rational(2, 1))
+
+ (Rational(2, 4) / 2).should == Rational(1, 4)
+ (Rational(6, 7) / -2).should == Rational(-3, 7)
+ end
+
+ it "raises a ZeroDivisionError when passed a Rational with a numerator of 0" do
+ -> { Rational(3, 4) / Rational(0, 1) }.should.raise(ZeroDivisionError)
+ end
end
describe "Rational#/ when passed a Float" do
- it_behaves_like(:rational_divide_float, :/)
+ it "returns self divided by other as a Float" do
+ (Rational(3, 4) / 0.75).should.eql?(1.0)
+ (Rational(3, 4) / 0.25).should.eql?(3.0)
+ (Rational(3, 4) / 0.3).should.eql?(2.5)
+
+ (Rational(-3, 4) / 0.3).should.eql?(-2.5)
+ (Rational(3, -4) / 0.3).should.eql?(-2.5)
+ (Rational(3, 4) / -0.3).should.eql?(-2.5)
+ end
+
+ it "returns infinity when passed 0" do
+ (Rational(3, 4) / 0.0).infinite?.should.eql?(1)
+ (Rational(-3, -4) / 0.0).infinite?.should.eql?(1)
+
+ (Rational(-3, 4) / 0.0).infinite?.should.eql?(-1)
+ (Rational(3, -4) / 0.0).infinite?.should.eql?(-1)
+ end
end
diff --git a/spec/ruby/core/rational/divmod_spec.rb b/spec/ruby/core/rational/divmod_spec.rb
index ee03c9498a..68f8ecfd2d 100644
--- a/spec/ruby/core/rational/divmod_spec.rb
+++ b/spec/ruby/core/rational/divmod_spec.rb
@@ -1,13 +1,42 @@
-require File.expand_path('../../../shared/rational/divmod', __FILE__)
+require_relative "../../spec_helper"
describe "Rational#divmod when passed a Rational" do
- it_behaves_like(:rational_divmod_rat, :divmod)
+ it "returns the quotient as Integer and the remainder as Rational" do
+ Rational(7, 4).divmod(Rational(1, 2)).should.eql?([3, Rational(1, 4)])
+ Rational(7, 4).divmod(Rational(-1, 2)).should.eql?([-4, Rational(-1, 4)])
+ Rational(0, 4).divmod(Rational(4, 3)).should.eql?([0, Rational(0, 1)])
+
+ Rational(bignum_value, 4).divmod(Rational(4, 3)).should.eql?([3458764513820540928, Rational(0, 1)])
+ end
+
+ it "raises a ZeroDivisionError when passed a Rational with a numerator of 0" do
+ -> { Rational(7, 4).divmod(Rational(0, 3)) }.should.raise(ZeroDivisionError)
+ end
end
describe "Rational#divmod when passed an Integer" do
- it_behaves_like(:rational_divmod_int, :divmod)
+ it "returns the quotient as Integer and the remainder as Rational" do
+ Rational(7, 4).divmod(2).should.eql?([0, Rational(7, 4)])
+ Rational(7, 4).divmod(-2).should.eql?([-1, Rational(-1, 4)])
+
+ Rational(bignum_value, 4).divmod(3).should.eql?([1537228672809129301, Rational(1, 1)])
+ end
+
+ it "raises a ZeroDivisionError when passed 0" do
+ -> { Rational(7, 4).divmod(0) }.should.raise(ZeroDivisionError)
+ end
end
describe "Rational#divmod when passed a Float" do
- it_behaves_like(:rational_divmod_float, :divmod)
+ it "returns the quotient as Integer and the remainder as Float" do
+ Rational(7, 4).divmod(0.5).should.eql?([3, 0.25])
+ end
+
+ it "returns the quotient as Integer and the remainder as Float" do
+ Rational(7, 4).divmod(-0.5).should.eql?([-4, -0.25])
+ end
+
+ it "raises a ZeroDivisionError when passed 0" do
+ -> { Rational(7, 4).divmod(0.0) }.should.raise(ZeroDivisionError)
+ end
end
diff --git a/spec/ruby/core/rational/equal_value_spec.rb b/spec/ruby/core/rational/equal_value_spec.rb
index 708eccf6d1..1dd077ea41 100644
--- a/spec/ruby/core/rational/equal_value_spec.rb
+++ b/spec/ruby/core/rational/equal_value_spec.rb
@@ -1,17 +1,39 @@
-require File.expand_path('../../../shared/rational/equal_value', __FILE__)
+require_relative "../../spec_helper"
describe "Rational#==" do
- it_behaves_like(:rational_equal_value, :==)
+ it "returns the result of calling #== with self on the passed argument" do
+ obj = mock("Object")
+ obj.should_receive(:==).and_return(:result)
+
+ (Rational(3, 4) == obj).should_not == false
+ end
end
describe "Rational#== when passed a Rational" do
- it_behaves_like(:rational_equal_value_rat, :==)
+ it "returns true if self has the same numerator and denominator as the passed argument" do
+ (Rational(3, 4) == Rational(3, 4)).should == true
+ (Rational(-3, -4) == Rational(3, 4)).should == true
+ (Rational(-4, 5) == Rational(4, -5)).should == true
+
+ (Rational(bignum_value, 3) == Rational(bignum_value, 3)).should == true
+ (Rational(-bignum_value, 3) == Rational(bignum_value, -3)).should == true
+ end
end
describe "Rational#== when passed a Float" do
- it_behaves_like(:rational_equal_value_float, :==)
+ it "converts self to a Float and compares it with the passed argument" do
+ (Rational(3, 4) == 0.75).should == true
+ (Rational(4, 2) == 2.0).should == true
+ (Rational(-4, 2) == -2.0).should == true
+ (Rational(4, -2) == -2.0).should == true
+ end
end
describe "Rational#== when passed an Integer" do
- it_behaves_like(:rational_equal_value_int, :==)
+ it "returns true if self has the passed argument as numerator and a denominator of 1" do
+ # Rational(x, y) reduces x and y automatically
+ (Rational(4, 2) == 2).should == true
+ (Rational(-4, 2) == -2).should == true
+ (Rational(4, -2) == -2).should == true
+ end
end
diff --git a/spec/ruby/core/rational/exponent_spec.rb b/spec/ruby/core/rational/exponent_spec.rb
index e4810d1b41..88b4a43796 100644
--- a/spec/ruby/core/rational/exponent_spec.rb
+++ b/spec/ruby/core/rational/exponent_spec.rb
@@ -1,5 +1,236 @@
-require File.expand_path('../../../shared/rational/exponent', __FILE__)
+require_relative "../../spec_helper"
describe "Rational#**" do
- it_behaves_like(:rational_exponent, :**)
+ describe "when passed Rational" do
+ # Guard against the Mathn library
+ guard -> { !defined?(Math.rsqrt) } do
+ it "returns Rational(1) if the exponent is Rational(0)" do
+ (Rational(0) ** Rational(0)).should.eql?(Rational(1))
+ (Rational(1) ** Rational(0)).should.eql?(Rational(1))
+ (Rational(3, 4) ** Rational(0)).should.eql?(Rational(1))
+ (Rational(-1) ** Rational(0)).should.eql?(Rational(1))
+ (Rational(-3, 4) ** Rational(0)).should.eql?(Rational(1))
+ (Rational(bignum_value) ** Rational(0)).should.eql?(Rational(1))
+ (Rational(-bignum_value) ** Rational(0)).should.eql?(Rational(1))
+ end
+
+ it "returns self raised to the argument as a Rational if the exponent's denominator is 1" do
+ (Rational(3, 4) ** Rational(1, 1)).should.eql?(Rational(3, 4))
+ (Rational(3, 4) ** Rational(2, 1)).should.eql?(Rational(9, 16))
+ (Rational(3, 4) ** Rational(-1, 1)).should.eql?(Rational(4, 3))
+ (Rational(3, 4) ** Rational(-2, 1)).should.eql?(Rational(16, 9))
+ end
+
+ it "returns self raised to the argument as a Float if the exponent's denominator is not 1" do
+ (Rational(3, 4) ** Rational(4, 3)).should be_close(0.681420222312052, TOLERANCE)
+ (Rational(3, 4) ** Rational(-4, 3)).should be_close(1.46752322173095, TOLERANCE)
+ (Rational(3, 4) ** Rational(4, -3)).should be_close(1.46752322173095, TOLERANCE)
+ end
+
+ it "returns a complex number when self is negative and the passed argument is not 0" do
+ (Rational(-3, 4) ** Rational(-4, 3)).should be_close(Complex(-0.7337616108654732, 1.2709123906625817), TOLERANCE)
+ end
+ end
+ end
+
+ describe "when passed Integer" do
+ it "returns the Rational value of self raised to the passed argument" do
+ (Rational(3, 4) ** 4).should == Rational(81, 256)
+ (Rational(3, 4) ** -4).should == Rational(256, 81)
+ (Rational(-3, 4) ** -4).should == Rational(256, 81)
+ (Rational(3, -4) ** -4).should == Rational(256, 81)
+
+ (Rational(bignum_value, 4) ** 4).should == Rational(452312848583266388373324160190187140051835877600158453279131187530910662656, 1)
+ (Rational(3, bignum_value) ** -4).should == Rational(115792089237316195423570985008687907853269984665640564039457584007913129639936, 81)
+ (Rational(-bignum_value, 4) ** -4).should == Rational(1, 452312848583266388373324160190187140051835877600158453279131187530910662656)
+ (Rational(3, -bignum_value) ** -4).should == Rational(115792089237316195423570985008687907853269984665640564039457584007913129639936, 81)
+ end
+
+ # Guard against the Mathn library
+ guard -> { !defined?(Math.rsqrt) } do
+ it "returns Rational(1, 1) when the passed argument is 0" do
+ (Rational(3, 4) ** 0).should.eql?(Rational(1, 1))
+ (Rational(-3, 4) ** 0).should.eql?(Rational(1, 1))
+ (Rational(3, -4) ** 0).should.eql?(Rational(1, 1))
+
+ (Rational(bignum_value, 4) ** 0).should.eql?(Rational(1, 1))
+ (Rational(3, -bignum_value) ** 0).should.eql?(Rational(1, 1))
+ end
+ end
+ end
+
+ describe "when passed Bignum" do
+ # #5713
+ it "returns Rational(0) when self is Rational(0) and the exponent is positive" do
+ (Rational(0) ** bignum_value).should.eql?(Rational(0))
+ end
+
+ it "raises ZeroDivisionError when self is Rational(0) and the exponent is negative" do
+ -> { Rational(0) ** -bignum_value }.should.raise(ZeroDivisionError)
+ end
+
+ it "returns Rational(1) when self is Rational(1)" do
+ (Rational(1) ** bignum_value).should.eql?(Rational(1))
+ (Rational(1) ** -bignum_value).should.eql?(Rational(1))
+ end
+
+ it "returns Rational(1) when self is Rational(-1) and the exponent is positive and even" do
+ (Rational(-1) ** bignum_value(0)).should.eql?(Rational(1))
+ (Rational(-1) ** bignum_value(2)).should.eql?(Rational(1))
+ end
+
+ it "returns Rational(-1) when self is Rational(-1) and the exponent is positive and odd" do
+ (Rational(-1) ** bignum_value(1)).should.eql?(Rational(-1))
+ (Rational(-1) ** bignum_value(3)).should.eql?(Rational(-1))
+ end
+
+ ruby_version_is ""..."3.4" do
+ it "returns positive Infinity when self is > 1" do
+ -> {
+ (Rational(2) ** bignum_value).infinite?.should == 1
+ }.should complain(/warning: in a\*\*b, b may be too big/)
+ -> {
+ (Rational(fixnum_max) ** bignum_value).infinite?.should == 1
+ }.should complain(/warning: in a\*\*b, b may be too big/)
+ end
+
+ it "returns 0.0 when self is > 1 and the exponent is negative" do
+ -> {
+ (Rational(2) ** -bignum_value).should.eql?(0.0)
+ }.should complain(/warning: in a\*\*b, b may be too big/)
+ -> {
+ (Rational(fixnum_max) ** -bignum_value).should.eql?(0.0)
+ }.should complain(/warning: in a\*\*b, b may be too big/)
+ end
+ end
+
+ ruby_version_is "3.4" do
+ it "raises an ArgumentError when self is > 1" do
+ -> {
+ (Rational(2) ** bignum_value)
+ }.should.raise(ArgumentError, "exponent is too large")
+ -> {
+ (Rational(fixnum_max) ** bignum_value)
+ }.should.raise(ArgumentError, "exponent is too large")
+ end
+
+ it "raises an ArgumentError when self is > 1 and the exponent is negative" do
+ -> {
+ (Rational(2) ** -bignum_value)
+ }.should.raise(ArgumentError, "exponent is too large")
+ -> {
+ (Rational(fixnum_max) ** -bignum_value)
+ }.should.raise(ArgumentError, "exponent is too large")
+ end
+
+ it "raises an ArgumentError when self is < -1" do
+ -> {
+ (Rational(-2) ** bignum_value)
+ }.should.raise(ArgumentError, "exponent is too large")
+ -> {
+ (Rational(fixnum_min) ** bignum_value)
+ }.should.raise(ArgumentError, "exponent is too large")
+ end
+
+ it "raises an ArgumentError when self is < -1 and the exponent is negative" do
+ -> {
+ (Rational(-2) ** -bignum_value)
+ }.should.raise(ArgumentError, "exponent is too large")
+ -> {
+ (Rational(fixnum_min) ** -bignum_value)
+ }.should.raise(ArgumentError, "exponent is too large")
+ end
+ end
+
+ # Fails on linux due to pow() bugs in glibc: http://sources.redhat.com/bugzilla/show_bug.cgi?id=3866
+ platform_is_not :linux do
+ ruby_version_is ""..."3.4" do
+ it "returns positive Infinity when self < -1" do
+ -> {
+ (Rational(-2) ** bignum_value).infinite?.should == 1
+ }.should complain(/warning: in a\*\*b, b may be too big/)
+ -> {
+ (Rational(-2) ** (bignum_value + 1)).infinite?.should == 1
+ }.should complain(/warning: in a\*\*b, b may be too big/)
+ -> {
+ (Rational(fixnum_min) ** bignum_value).infinite?.should == 1
+ }.should complain(/warning: in a\*\*b, b may be too big/)
+ end
+
+ it "returns 0.0 when self is < -1 and the exponent is negative" do
+ -> {
+ (Rational(-2) ** -bignum_value).should.eql?(0.0)
+ }.should complain(/warning: in a\*\*b, b may be too big/)
+ -> {
+ (Rational(fixnum_min) ** -bignum_value).should.eql?(0.0)
+ }.should complain(/warning: in a\*\*b, b may be too big/)
+ end
+ end
+ end
+ end
+
+ describe "when passed Float" do
+ it "returns self converted to Float and raised to the passed argument" do
+ (Rational(3, 1) ** 3.0).should.eql?(27.0)
+ (Rational(3, 1) ** 1.5).should be_close(5.19615242270663, TOLERANCE)
+ (Rational(3, 1) ** -1.5).should be_close(0.192450089729875, TOLERANCE)
+ end
+
+ it "returns a complex number if self is negative and the passed argument is not 0" do
+ (Rational(-3, 2) ** 1.5).should be_close(Complex(0.0, -1.8371173070873836), TOLERANCE)
+ (Rational(3, -2) ** 1.5).should be_close(Complex(0.0, -1.8371173070873836), TOLERANCE)
+ (Rational(3, -2) ** -1.5).should be_close(Complex(0.0, 0.5443310539518174), TOLERANCE)
+ end
+
+ it "returns Complex(1.0) when the passed argument is 0.0" do
+ (Rational(3, 4) ** 0.0).should == Complex(1.0)
+ (Rational(-3, 4) ** 0.0).should == Complex(1.0)
+ (Rational(-3, 4) ** 0.0).should == Complex(1.0)
+ end
+ end
+
+ it "calls #coerce on the passed argument with self" do
+ rational = Rational(3, 4)
+ obj = mock("Object")
+ obj.should_receive(:coerce).with(rational).and_return([1, 2])
+
+ rational ** obj
+ end
+
+ it "calls #** on the coerced Rational with the coerced Object" do
+ rational = Rational(3, 4)
+
+ coerced_rational = mock("Coerced Rational")
+ coerced_rational.should_receive(:**).and_return(:result)
+
+ coerced_obj = mock("Coerced Object")
+
+ obj = mock("Object")
+ obj.should_receive(:coerce).and_return([coerced_rational, coerced_obj])
+
+ (rational ** obj).should == :result
+ end
+
+ it "raises ZeroDivisionError for Rational(0, 1) passed a negative Integer" do
+ [-1, -4, -9999].each do |exponent|
+ -> { Rational(0, 1) ** exponent }.should.raise(ZeroDivisionError, "divided by 0")
+ end
+ end
+
+ it "raises ZeroDivisionError for Rational(0, 1) passed a negative Rational with denominator 1" do
+ [Rational(-1, 1), Rational(-3, 1)].each do |exponent|
+ -> { Rational(0, 1) ** exponent }.should.raise(ZeroDivisionError, "divided by 0")
+ end
+ end
+
+ # #7513
+ it "raises ZeroDivisionError for Rational(0, 1) passed a negative Rational" do
+ -> { Rational(0, 1) ** Rational(-3, 2) }.should.raise(ZeroDivisionError, "divided by 0")
+ end
+
+ it "returns Infinity for Rational(0, 1) passed a negative Float" do
+ [-1.0, -3.0, -3.14].each do |exponent|
+ (Rational(0, 1) ** exponent).infinite?.should == 1
+ end
+ end
end
diff --git a/spec/ruby/core/rational/fdiv_spec.rb b/spec/ruby/core/rational/fdiv_spec.rb
index 15b4ed0619..118d93dbe7 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__)
+require_relative "../../spec_helper"
describe "Rational#fdiv" do
- it_behaves_like(:rational_fdiv, :fdiv)
+ it "needs to be reviewed for spec completeness"
end
diff --git a/spec/ruby/core/rational/fixtures/rational.rb b/spec/ruby/core/rational/fixtures/rational.rb
new file mode 100644
index 0000000000..844d7f9820
--- /dev/null
+++ b/spec/ruby/core/rational/fixtures/rational.rb
@@ -0,0 +1,14 @@
+module RationalSpecs
+ class SubNumeric < Numeric
+ def initialize(value)
+ @value = Rational(value)
+ end
+
+ def to_r
+ @value
+ end
+ end
+
+ class CoerceError < StandardError
+ end
+end
diff --git a/spec/ruby/core/rational/floor_spec.rb b/spec/ruby/core/rational/floor_spec.rb
index 485abcf58f..6d4cee79a9 100644
--- a/spec/ruby/core/rational/floor_spec.rb
+++ b/spec/ruby/core/rational/floor_spec.rb
@@ -1,5 +1,49 @@
-require File.expand_path('../../../shared/rational/floor', __FILE__)
+require_relative "../../spec_helper"
+require_relative "../integer/shared/integer_floor_precision"
describe "Rational#floor" do
- it_behaves_like(:rational_floor, :floor)
+ context "with values equal to integers" do
+ it_behaves_like :integer_floor_precision, :Rational
+ end
+
+ before do
+ @rational = Rational(2200, 7)
+ end
+
+ describe "with no arguments (precision = 0)" do
+
+ it "returns the Integer value rounded toward negative infinity" do
+ @rational.floor.should.eql? 314
+
+ Rational(1, 2).floor.should.eql? 0
+ Rational(-1, 2).floor.should.eql?(-1)
+ Rational(1, 1).floor.should.eql? 1
+ end
+ end
+
+ describe "with a precision < 0" do
+ it "moves the rounding point n decimal places left, returning an Integer" do
+ @rational.floor(-3).should.eql? 0
+ @rational.floor(-2).should.eql? 300
+ @rational.floor(-1).should.eql? 310
+
+ Rational(100, 2).floor(-1).should.eql? 50
+ Rational(100, 2).floor(-2).should.eql? 0
+ Rational(-100, 2).floor(-1).should.eql?(-50)
+ Rational(-100, 2).floor(-2).should.eql?(-100)
+ end
+ end
+
+ describe "with a precision > 0" do
+ it "moves the rounding point n decimal places right, returning a Rational" do
+ @rational.floor(1).should.eql? Rational(1571, 5)
+ @rational.floor(2).should.eql? Rational(7857, 25)
+ @rational.floor(3).should.eql? Rational(62857, 200)
+
+ Rational(100, 2).floor(1).should.eql? Rational(50, 1)
+ Rational(100, 2).floor(2).should.eql? Rational(50, 1)
+ Rational(-100, 2).floor(1).should.eql? Rational(-50, 1)
+ Rational(-100, 2).floor(2).should.eql? Rational(-50, 1)
+ end
+ end
end
diff --git a/spec/ruby/core/rational/hash_spec.rb b/spec/ruby/core/rational/hash_spec.rb
index a17572d57e..528638056a 100644
--- a/spec/ruby/core/rational/hash_spec.rb
+++ b/spec/ruby/core/rational/hash_spec.rb
@@ -1,5 +1,9 @@
-require File.expand_path('../../../shared/rational/hash', __FILE__)
+require_relative "../../spec_helper"
describe "Rational#hash" do
- it_behaves_like(:rational_hash, :hash)
+ # BUG: Rational(2, 3).hash == Rational(3, 2).hash
+ it "is static" do
+ Rational(2, 3).hash.should == Rational(2, 3).hash
+ Rational(2, 4).hash.should_not == Rational(2, 3).hash
+ end
end
diff --git a/spec/ruby/core/rational/inspect_spec.rb b/spec/ruby/core/rational/inspect_spec.rb
index 452cf9c5ae..edc5cffee9 100644
--- a/spec/ruby/core/rational/inspect_spec.rb
+++ b/spec/ruby/core/rational/inspect_spec.rb
@@ -1,5 +1,14 @@
-require File.expand_path('../../../shared/rational/inspect', __FILE__)
+require_relative "../../spec_helper"
describe "Rational#inspect" do
- it_behaves_like(:rational_inspect, :inspect)
+ it "returns a string representation of self" do
+ Rational(3, 4).inspect.should == "(3/4)"
+ Rational(-5, 8).inspect.should == "(-5/8)"
+ Rational(-1, -2).inspect.should == "(1/2)"
+
+ # Guard against the Mathn library
+ guard -> { !defined?(Math.rsqrt) } do
+ Rational(bignum_value, 1).inspect.should == "(#{bignum_value}/1)"
+ end
+ end
end
diff --git a/spec/ruby/core/rational/integer_spec.rb b/spec/ruby/core/rational/integer_spec.rb
index 451e42ee14..cd7fa97fcf 100644
--- a/spec/ruby/core/rational/integer_spec.rb
+++ b/spec/ruby/core/rational/integer_spec.rb
@@ -1,9 +1,13 @@
+require_relative "../../spec_helper"
describe "Rational#integer?" do
- it "returns false for a rational with a numerator and no denominator" do
- Rational(20).integer?.should be_false
+ # Guard against the Mathn library
+ guard -> { !defined?(Math.rsqrt) } do
+ it "returns false for a rational with a numerator and no denominator" do
+ Rational(20).integer?.should == false
+ end
end
it "returns false for a rational with a numerator and a denominator" do
- Rational(20,3).integer?.should be_false
+ Rational(20,3).integer?.should == false
end
end
diff --git a/spec/ruby/core/rational/magnitude_spec.rb b/spec/ruby/core/rational/magnitude_spec.rb
index 288b9a3fa3..0df637df7a 100644
--- a/spec/ruby/core/rational/magnitude_spec.rb
+++ b/spec/ruby/core/rational/magnitude_spec.rb
@@ -1,5 +1,7 @@
-require File.expand_path('../../../shared/rational/abs', __FILE__)
+require_relative "../../spec_helper"
-describe "Rational#abs" do
- it_behaves_like(:rational_abs, :magnitude)
+describe "Rational#magnitude" do
+ it "is an alias of Rational#abs" do
+ Rational.instance_method(:magnitude).should == Rational.instance_method(:abs)
+ end
end
diff --git a/spec/ruby/core/rational/marshal_dump_spec.rb b/spec/ruby/core/rational/marshal_dump_spec.rb
index 46e9267ebd..06bf36f166 100644
--- a/spec/ruby/core/rational/marshal_dump_spec.rb
+++ b/spec/ruby/core/rational/marshal_dump_spec.rb
@@ -1,8 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Rational#marshal_dump" do
it "is a private method" do
- Rational.should have_private_instance_method(:marshal_dump, false)
+ Rational.private_instance_methods(false).should.include?(:marshal_dump)
end
it "dumps numerator and denominator" do
diff --git a/spec/ruby/core/rational/minus_spec.rb b/spec/ruby/core/rational/minus_spec.rb
index 9e28cb1c4f..4e10e118b9 100644
--- a/spec/ruby/core/rational/minus_spec.rb
+++ b/spec/ruby/core/rational/minus_spec.rb
@@ -1,5 +1,51 @@
-require File.expand_path('../../../shared/rational/minus', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/arithmetic_exception_in_coerce'
describe "Rational#-" do
- it_behaves_like(:rational_minus, :-)
+ it_behaves_like :rational_arithmetic_exception_in_coerce, :-
+
+ it "calls #coerce on the passed argument with self" do
+ rational = Rational(3, 4)
+ obj = mock("Object")
+ obj.should_receive(:coerce).with(rational).and_return([1, 2])
+
+ rational - obj
+ end
+
+ it "calls #- on the coerced Rational with the coerced Object" do
+ rational = Rational(3, 4)
+
+ coerced_rational = mock("Coerced Rational")
+ coerced_rational.should_receive(:-).and_return(:result)
+
+ coerced_obj = mock("Coerced Object")
+
+ obj = mock("Object")
+ obj.should_receive(:coerce).and_return([coerced_rational, coerced_obj])
+
+ (rational - obj).should == :result
+ end
+end
+
+describe "Rational#- passed a Rational" do
+ it "returns the result of subtracting other from self as a Rational" do
+ (Rational(3, 4) - Rational(0, 1)).should.eql?(Rational(3, 4))
+ (Rational(3, 4) - Rational(1, 4)).should.eql?(Rational(1, 2))
+
+ (Rational(3, 4) - Rational(2, 1)).should.eql?(Rational(-5, 4))
+ end
+end
+
+describe "Rational#- passed a Float" do
+ it "returns the result of subtracting other from self as a Float" do
+ (Rational(3, 4) - 0.2).should.eql?(0.55)
+ (Rational(3, 4) - 2.5).should.eql?(-1.75)
+ end
+end
+
+describe "Rational#- passed an Integer" do
+ it "returns the result of subtracting other from self as a Rational" do
+ (Rational(3, 4) - 1).should.eql?(Rational(-1, 4))
+ (Rational(3, 4) - 2).should.eql?(Rational(-5, 4))
+ end
end
diff --git a/spec/ruby/core/rational/modulo_spec.rb b/spec/ruby/core/rational/modulo_spec.rb
index 81e7c13797..6241077f68 100644
--- a/spec/ruby/core/rational/modulo_spec.rb
+++ b/spec/ruby/core/rational/modulo_spec.rb
@@ -1,5 +1,43 @@
-require File.expand_path('../../../shared/rational/modulo', __FILE__)
+require_relative "../../spec_helper"
describe "Rational#%" do
- it_behaves_like(:rational_modulo, :%)
+ it "returns the remainder when this value is divided by other" do
+ (Rational(2, 3) % Rational(2, 3)).should == Rational(0, 1)
+ (Rational(4, 3) % Rational(2, 3)).should == Rational(0, 1)
+ (Rational(2, -3) % Rational(-2, 3)).should == Rational(0, 1)
+ (Rational(0, -1) % -1).should == Rational(0, 1)
+
+ (Rational(7, 4) % Rational(1, 2)).should == Rational(1, 4)
+ (Rational(7, 4) % 1).should == Rational(3, 4)
+ (Rational(7, 4) % Rational(1, 7)).should == Rational(1, 28)
+
+ (Rational(3, 4) % -1).should == Rational(-1, 4)
+ (Rational(1, -5) % -1).should == Rational(-1, 5)
+ end
+
+ it "returns a Float value when the argument is Float" do
+ (Rational(7, 4) % 1.0).should.is_a?(Float)
+ (Rational(7, 4) % 1.0).should == 0.75
+ (Rational(7, 4) % 0.26).should be_close(0.19, 0.0001)
+ end
+
+ it "raises ZeroDivisionError on zero denominator" do
+ -> {
+ Rational(3, 5) % Rational(0, 1)
+ }.should.raise(ZeroDivisionError)
+
+ -> {
+ Rational(0, 1) % Rational(0, 1)
+ }.should.raise(ZeroDivisionError)
+
+ -> {
+ Rational(3, 5) % 0
+ }.should.raise(ZeroDivisionError)
+ end
+
+ it "raises a ZeroDivisionError when the argument is 0.0" do
+ -> {
+ Rational(3, 5) % 0.0
+ }.should.raise(ZeroDivisionError)
+ end
end
diff --git a/spec/ruby/core/rational/multiply_spec.rb b/spec/ruby/core/rational/multiply_spec.rb
index c45491fde3..3e059cbc1c 100644
--- a/spec/ruby/core/rational/multiply_spec.rb
+++ b/spec/ruby/core/rational/multiply_spec.rb
@@ -1,17 +1,65 @@
-require File.expand_path('../../../shared/rational/multiply', __FILE__)
+require_relative "../../spec_helper"
+require_relative 'shared/arithmetic_exception_in_coerce'
describe "Rational#*" do
- it_behaves_like(:rational_multiply, :*)
+ it "calls #coerce on the passed argument with self" do
+ rational = Rational(3, 4)
+ obj = mock("Object")
+ obj.should_receive(:coerce).with(rational).and_return([1, 2])
+
+ rational * obj
+ end
+
+ it "calls #* on the coerced Rational with the coerced Object" do
+ rational = Rational(3, 4)
+
+ coerced_rational = mock("Coerced Rational")
+ coerced_rational.should_receive(:*).and_return(:result)
+
+ coerced_obj = mock("Coerced Object")
+
+ obj = mock("Object")
+ obj.should_receive(:coerce).and_return([coerced_rational, coerced_obj])
+
+ (rational * obj).should == :result
+ end
+
+ it_behaves_like :rational_arithmetic_exception_in_coerce, :*
end
describe "Rational#* passed a Rational" do
- it_behaves_like(:rational_multiply_rat, :*)
+ it "returns self divided by other as a Rational" do
+ (Rational(3, 4) * Rational(3, 4)).should.eql?(Rational(9, 16))
+ (Rational(2, 4) * Rational(1, 4)).should.eql?(Rational(1, 8))
+
+ (Rational(3, 4) * Rational(0, 1)).should.eql?(Rational(0, 4))
+ end
end
describe "Rational#* passed a Float" do
- it_behaves_like(:rational_multiply_float, :*)
+ it "returns self divided by other as a Float" do
+ (Rational(3, 4) * 0.75).should.eql?(0.5625)
+ (Rational(3, 4) * 0.25).should.eql?(0.1875)
+ (Rational(3, 4) * 0.3).should be_close(0.225, TOLERANCE)
+
+ (Rational(-3, 4) * 0.3).should be_close(-0.225, TOLERANCE)
+ (Rational(3, -4) * 0.3).should be_close(-0.225, TOLERANCE)
+ (Rational(3, 4) * -0.3).should be_close(-0.225, TOLERANCE)
+
+ (Rational(3, 4) * 0.0).should.eql?(0.0)
+ (Rational(-3, -4) * 0.0).should.eql?(0.0)
+
+ (Rational(-3, 4) * 0.0).should.eql?(0.0)
+ (Rational(3, -4) * 0.0).should.eql?(0.0)
+ end
end
describe "Rational#* passed an Integer" do
- it_behaves_like(:rational_multiply_int, :*)
+ it "returns self divided by other as a Rational" do
+ (Rational(3, 4) * 2).should.eql?(Rational(3, 2))
+ (Rational(2, 4) * 2).should.eql?(Rational(1, 1))
+ (Rational(6, 7) * -2).should.eql?(Rational(-12, 7))
+
+ (Rational(3, 4) * 0).should.eql?(Rational(0, 4))
+ end
end
diff --git a/spec/ruby/core/rational/numerator_spec.rb b/spec/ruby/core/rational/numerator_spec.rb
index ac6591291d..631bb4703c 100644
--- a/spec/ruby/core/rational/numerator_spec.rb
+++ b/spec/ruby/core/rational/numerator_spec.rb
@@ -1,5 +1,10 @@
-require File.expand_path('../../../shared/rational/numerator', __FILE__)
+require_relative "../../spec_helper"
describe "Rational#numerator" do
- it_behaves_like(:rational_numerator, :numerator)
+ it "returns the numerator" do
+ Rational(3, 4).numerator.should.equal?(3)
+ Rational(3, -4).numerator.should.equal?(-3)
+
+ Rational(bignum_value, 1).numerator.should == bignum_value
+ end
end
diff --git a/spec/ruby/core/rational/plus_spec.rb b/spec/ruby/core/rational/plus_spec.rb
index b82c44bbad..92f830a105 100644
--- a/spec/ruby/core/rational/plus_spec.rb
+++ b/spec/ruby/core/rational/plus_spec.rb
@@ -1,16 +1,50 @@
-require File.expand_path('../../../shared/rational/plus', __FILE__)
+require_relative "../../spec_helper"
+require_relative 'shared/arithmetic_exception_in_coerce'
describe "Rational#+" do
- it_behaves_like(:rational_plus, :+)
+ it "calls #coerce on the passed argument with self" do
+ rational = Rational(3, 4)
+ obj = mock("Object")
+ obj.should_receive(:coerce).with(rational).and_return([1, 2])
+
+ rational + obj
+ end
+
+ it "calls #+ on the coerced Rational with the coerced Object" do
+ rational = Rational(3, 4)
+
+ coerced_rational = mock("Coerced Rational")
+ coerced_rational.should_receive(:+).and_return(:result)
+
+ coerced_obj = mock("Coerced Object")
+
+ obj = mock("Object")
+ obj.should_receive(:coerce).and_return([coerced_rational, coerced_obj])
+
+ (rational + obj).should == :result
+ end
+
+ it_behaves_like :rational_arithmetic_exception_in_coerce, :+
end
describe "Rational#+ with a Rational" do
- it_behaves_like(:rational_plus_rat, :+)
+ it "returns the result of subtracting other from self as a Rational" do
+ (Rational(3, 4) + Rational(0, 1)).should.eql?(Rational(3, 4))
+ (Rational(3, 4) + Rational(1, 4)).should.eql?(Rational(1, 1))
+
+ (Rational(3, 4) + Rational(2, 1)).should.eql?(Rational(11, 4))
+ end
end
describe "Rational#+ with a Float" do
- it_behaves_like(:rational_plus_float, :+)
+ it "returns the result of subtracting other from self as a Float" do
+ (Rational(3, 4) + 0.2).should.eql?(0.95)
+ (Rational(3, 4) + 2.5).should.eql?(3.25)
+ end
end
describe "Rational#+ with an Integer" do
- it_behaves_like(:rational_plus_int, :+)
+ it "returns the result of subtracting other from self as a Rational" do
+ (Rational(3, 4) + 1).should.eql?(Rational(7, 4))
+ (Rational(3, 4) + 2).should.eql?(Rational(11, 4))
+ end
end
diff --git a/spec/ruby/core/rational/quo_spec.rb b/spec/ruby/core/rational/quo_spec.rb
index f4d04d5f6f..62178f403b 100644
--- a/spec/ruby/core/rational/quo_spec.rb
+++ b/spec/ruby/core/rational/quo_spec.rb
@@ -1,5 +1,7 @@
-require File.expand_path('../../../shared/rational/divide', __FILE__)
+require_relative "../../spec_helper"
describe "Rational#quo" do
- it_behaves_like(:rational_divide, :quo)
+ it "is an alias of Rational#/" do
+ Rational.instance_method(:quo).should == Rational.instance_method(:/)
+ end
end
diff --git a/spec/ruby/core/rational/rational_spec.rb b/spec/ruby/core/rational/rational_spec.rb
index fc3108c11b..278c4116a4 100644
--- a/spec/ruby/core/rational/rational_spec.rb
+++ b/spec/ruby/core/rational/rational_spec.rb
@@ -1,7 +1,11 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Rational" do
it "includes Comparable" do
Rational.include?(Comparable).should == true
end
+
+ it "does not respond to new" do
+ -> { Rational.new(1) }.should.raise(NoMethodError)
+ end
end
diff --git a/spec/ruby/core/rational/rationalize_spec.rb b/spec/ruby/core/rational/rationalize_spec.rb
index 053e245cff..9c86824ddd 100644
--- a/spec/ruby/core/rational/rationalize_spec.rb
+++ b/spec/ruby/core/rational/rationalize_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Rational#rationalize" do
it "returns self with no argument" do
@@ -30,7 +30,7 @@ describe "Rational#rationalize" do
end
it "raises ArgumentError when passed more than one argument" do
- lambda { Rational(1,1).rationalize(0.1, 0.1) }.should raise_error(ArgumentError)
- lambda { Rational(1,1).rationalize(0.1, 0.1, 2) }.should raise_error(ArgumentError)
+ -> { Rational(1,1).rationalize(0.1, 0.1) }.should.raise(ArgumentError)
+ -> { Rational(1,1).rationalize(0.1, 0.1, 2) }.should.raise(ArgumentError)
end
end
diff --git a/spec/ruby/core/rational/remainder_spec.rb b/spec/ruby/core/rational/remainder_spec.rb
index 1de276548f..86ba4674e6 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__)
+require_relative "../../spec_helper"
describe "Rational#remainder" do
- it_behaves_like(:rational_remainder, :remainder)
+ it "needs to be reviewed for spec completeness"
end
diff --git a/spec/ruby/core/rational/round_spec.rb b/spec/ruby/core/rational/round_spec.rb
index 2b432f3234..dd6f66f408 100644
--- a/spec/ruby/core/rational/round_spec.rb
+++ b/spec/ruby/core/rational/round_spec.rb
@@ -1,5 +1,106 @@
-require File.expand_path('../../../shared/rational/round', __FILE__)
+require_relative '../../spec_helper'
describe "Rational#round" do
- it_behaves_like(:rational_round, :round)
+ before do
+ @rational = Rational(2200, 7)
+ end
+
+ describe "with no arguments (precision = 0)" do
+ it "returns an integer" do
+ @rational.round.should.is_a?(Integer)
+ Rational(0, 1).round(0).should.is_a?(Integer)
+ Rational(124, 1).round(0).should.is_a?(Integer)
+ end
+
+ it "returns the truncated value toward the nearest integer" do
+ @rational.round.should == 314
+ Rational(0, 1).round(0).should == 0
+ Rational(2, 1).round(0).should == 2
+ end
+
+ it "returns the rounded value toward the nearest integer" do
+ Rational(1, 2).round.should == 1
+ Rational(-1, 2).round.should == -1
+ Rational(3, 2).round.should == 2
+ Rational(-3, 2).round.should == -2
+ Rational(5, 2).round.should == 3
+ Rational(-5, 2).round.should == -3
+ end
+ end
+
+ describe "with a precision < 0" do
+ it "returns an integer" do
+ @rational.round(-2).should.is_a?(Integer)
+ @rational.round(-1).should.is_a?(Integer)
+ Rational(0, 1).round(-1).should.is_a?(Integer)
+ Rational(2, 1).round(-1).should.is_a?(Integer)
+ end
+
+ it "moves the truncation point n decimal places left" do
+ @rational.round(-3).should == 0
+ @rational.round(-2).should == 300
+ @rational.round(-1).should == 310
+ end
+ end
+
+ describe "with a precision > 0" do
+ it "returns a Rational" do
+ @rational.round(1).should.is_a?(Rational)
+ @rational.round(2).should.is_a?(Rational)
+ # Guard against the Mathn library
+ guard -> { !defined?(Math.rsqrt) } do
+ Rational(0, 1).round(1).should.is_a?(Rational)
+ Rational(2, 1).round(1).should.is_a?(Rational)
+ end
+ end
+
+ it "moves the truncation point n decimal places right" do
+ @rational.round(1).should == Rational(3143, 10)
+ @rational.round(2).should == Rational(31429, 100)
+ @rational.round(3).should == Rational(157143, 500)
+ Rational(0, 1).round(1).should == Rational(0, 1)
+ Rational(2, 1).round(1).should == Rational(2, 1)
+ end
+
+ it "doesn't alter the value if the precision is too great" do
+ Rational(3, 2).round(10).should == Rational(3, 2).round(20)
+ end
+
+ # #6605
+ it "doesn't fail when rounding to an absurdly large positive precision" do
+ Rational(3, 2).round(2_097_171).should == Rational(3, 2)
+ end
+ end
+
+ describe "with half option" do
+ it "returns an Integer when precision is not passed" do
+ Rational(10, 4).round(half: nil).should == 3
+ Rational(10, 4).round(half: :up).should == 3
+ Rational(10, 4).round(half: :down).should == 2
+ Rational(10, 4).round(half: :even).should == 2
+ Rational(-10, 4).round(half: nil).should == -3
+ Rational(-10, 4).round(half: :up).should == -3
+ Rational(-10, 4).round(half: :down).should == -2
+ Rational(-10, 4).round(half: :even).should == -2
+ end
+
+ it "returns a Rational when the precision is greater than 0" do
+ Rational(25, 100).round(1, half: nil).should == Rational(3, 10)
+ Rational(25, 100).round(1, half: :up).should == Rational(3, 10)
+ Rational(25, 100).round(1, half: :down).should == Rational(1, 5)
+ Rational(25, 100).round(1, half: :even).should == Rational(1, 5)
+ Rational(35, 100).round(1, half: nil).should == Rational(2, 5)
+ Rational(35, 100).round(1, half: :up).should == Rational(2, 5)
+ Rational(35, 100).round(1, half: :down).should == Rational(3, 10)
+ Rational(35, 100).round(1, half: :even).should == Rational(2, 5)
+ Rational(-25, 100).round(1, half: nil).should == Rational(-3, 10)
+ Rational(-25, 100).round(1, half: :up).should == Rational(-3, 10)
+ Rational(-25, 100).round(1, half: :down).should == Rational(-1, 5)
+ Rational(-25, 100).round(1, half: :even).should == Rational(-1, 5)
+ end
+
+ it "raise for a non-existent round mode" do
+ -> { Rational(10, 4).round(half: :nonsense) }.should.raise(ArgumentError, "invalid rounding mode: nonsense")
+ end
+ end
end
diff --git a/spec/ruby/core/rational/shared/arithmetic_exception_in_coerce.rb b/spec/ruby/core/rational/shared/arithmetic_exception_in_coerce.rb
new file mode 100644
index 0000000000..e15169c912
--- /dev/null
+++ b/spec/ruby/core/rational/shared/arithmetic_exception_in_coerce.rb
@@ -0,0 +1,11 @@
+require_relative '../fixtures/rational'
+
+describe :rational_arithmetic_exception_in_coerce, 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(RationalSpecs::CoerceError)
+
+ # e.g. Rational(3, 4) + b
+ -> { Rational(3, 4).send(@method, b) }.should.raise(RationalSpecs::CoerceError)
+ end
+end
diff --git a/spec/ruby/core/rational/to_f_spec.rb b/spec/ruby/core/rational/to_f_spec.rb
index 92ff2444b4..40e3f11c0c 100644
--- a/spec/ruby/core/rational/to_f_spec.rb
+++ b/spec/ruby/core/rational/to_f_spec.rb
@@ -1,5 +1,16 @@
-require File.expand_path('../../../shared/rational/to_f', __FILE__)
+require_relative "../../spec_helper"
describe "Rational#to_f" do
- it_behaves_like(:rational_to_f, :to_f)
+ it "returns self converted to a Float" do
+ Rational(3, 4).to_f.should.eql?(0.75)
+ Rational(3, -4).to_f.should.eql?(-0.75)
+ Rational(-1, 4).to_f.should.eql?(-0.25)
+ Rational(-1, -4).to_f.should.eql?(0.25)
+ end
+
+ it "converts to a Float for large numerator and denominator" do
+ num = 1000000000000000000000000000000000048148248609680896326399448564623182963452541226153892315137780403285956264146010000000000000000000000000000000000048148248609680896326399448564623182963452541226153892315137780403285956264146010000000000000000000000000000000000048148248609680896326399448564623182963452541226153892315137780403285956264146009
+ den = 2000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+ Rational(num, den).to_f.should == 500.0
+ end
end
diff --git a/spec/ruby/core/rational/to_i_spec.rb b/spec/ruby/core/rational/to_i_spec.rb
index fda6b06e96..e61b1b6c3b 100644
--- a/spec/ruby/core/rational/to_i_spec.rb
+++ b/spec/ruby/core/rational/to_i_spec.rb
@@ -1,5 +1,12 @@
-require File.expand_path('../../../shared/rational/to_i', __FILE__)
+require_relative "../../spec_helper"
describe "Rational#to_i" do
- it_behaves_like(:rational_to_i, :to_i)
+ it "converts self to an Integer by truncation" do
+ Rational(7, 4).to_i.should.eql?(1)
+ Rational(11, 4).to_i.should.eql?(2)
+ end
+
+ it "converts self to an Integer by truncation" do
+ Rational(-7, 4).to_i.should.eql?(-1)
+ end
end
diff --git a/spec/ruby/core/rational/to_r_spec.rb b/spec/ruby/core/rational/to_r_spec.rb
index 6e44cf1b23..eb6097f595 100644
--- a/spec/ruby/core/rational/to_r_spec.rb
+++ b/spec/ruby/core/rational/to_r_spec.rb
@@ -1,11 +1,17 @@
-require File.expand_path('../../../shared/rational/to_r', __FILE__)
+require_relative "../../spec_helper"
describe "Rational#to_r" do
- it_behaves_like(:rational_to_r, :to_r)
+ it "returns self" do
+ a = Rational(3, 4)
+ a.to_r.should.equal?(a)
+
+ a = Rational(bignum_value, 4)
+ a.to_r.should.equal?(a)
+ end
it "raises TypeError trying to convert BasicObject" do
obj = BasicObject.new
- lambda { Rational(obj) }.should raise_error(TypeError)
+ -> { Rational(obj) }.should.raise(TypeError)
end
it "works when a BasicObject has to_r" do
@@ -15,6 +21,6 @@ describe "Rational#to_r" do
it "fails when a BasicObject's to_r does not return a Rational" do
obj = BasicObject.new; def obj.to_r; 1 end
- lambda { Rational(obj) }.should raise_error(TypeError)
+ -> { Rational(obj) }.should.raise(TypeError)
end
end
diff --git a/spec/ruby/core/rational/to_s_spec.rb b/spec/ruby/core/rational/to_s_spec.rb
index 7d1702b8fa..24e30778e5 100644
--- a/spec/ruby/core/rational/to_s_spec.rb
+++ b/spec/ruby/core/rational/to_s_spec.rb
@@ -1,5 +1,14 @@
-require File.expand_path('../../../shared/rational/to_s', __FILE__)
+require_relative "../../spec_helper"
describe "Rational#to_s" do
- it_behaves_like(:rational_to_s, :to_s)
+ it "returns a string representation of self" do
+ # Guard against the Mathn library
+ guard -> { !defined?(Math.rsqrt) } do
+ Rational(1, 1).to_s.should == "1/1"
+ Rational(2, 1).to_s.should == "2/1"
+ end
+ Rational(1, 2).to_s.should == "1/2"
+ Rational(-1, 3).to_s.should == "-1/3"
+ Rational(1, -3).to_s.should == "-1/3"
+ end
end
diff --git a/spec/ruby/core/rational/truncate_spec.rb b/spec/ruby/core/rational/truncate_spec.rb
index 000db73357..3614431a7f 100644
--- a/spec/ruby/core/rational/truncate_spec.rb
+++ b/spec/ruby/core/rational/truncate_spec.rb
@@ -1,5 +1,71 @@
-require File.expand_path('../../../shared/rational/truncate', __FILE__)
+require_relative "../../spec_helper"
describe "Rational#truncate" do
- it_behaves_like(:rational_truncate, :truncate)
+ before do
+ @rational = Rational(2200, 7)
+ end
+
+ describe "with no arguments (precision = 0)" do
+ it "returns an integer" do
+ @rational.truncate.should.is_a?(Integer)
+ end
+
+ it "returns the truncated value toward 0" do
+ @rational.truncate.should == 314
+ Rational(1, 2).truncate.should == 0
+ Rational(-1, 2).truncate.should == 0
+ end
+ end
+
+ describe "with an explicit precision = 0" do
+ it "returns an integer" do
+ @rational.truncate(0).should.is_a?(Integer)
+ end
+
+ it "returns the truncated value toward 0" do
+ @rational.truncate(0).should == 314
+ Rational(1, 2).truncate(0).should == 0
+ Rational(-1, 2).truncate(0).should == 0
+ end
+ end
+
+ describe "with a precision < 0" do
+ it "returns an integer" do
+ @rational.truncate(-2).should.is_a?(Integer)
+ @rational.truncate(-1).should.is_a?(Integer)
+ end
+
+ it "moves the truncation point n decimal places left" do
+ @rational.truncate(-3).should == 0
+ @rational.truncate(-2).should == 300
+ @rational.truncate(-1).should == 310
+ end
+ end
+
+ describe "with a precision > 0" do
+ it "returns a Rational" do
+ @rational.truncate(1).should.is_a?(Rational)
+ @rational.truncate(2).should.is_a?(Rational)
+ end
+
+ it "moves the truncation point n decimal places right" do
+ @rational.truncate(1).should == Rational(1571, 5)
+ @rational.truncate(2).should == Rational(7857, 25)
+ @rational.truncate(3).should == Rational(62857, 200)
+ end
+ end
+
+ describe "with an invalid value for precision" do
+ it "raises a TypeError" do
+ -> { @rational.truncate(nil) }.should.raise(TypeError, "not an integer")
+ -> { @rational.truncate(1.0) }.should.raise(TypeError, "not an integer")
+ -> { @rational.truncate('') }.should.raise(TypeError, "not an integer")
+ end
+
+ it "does not call to_int on the argument" do
+ object = Object.new
+ object.should_not_receive(:to_int)
+ -> { @rational.truncate(object) }.should.raise(TypeError, "not an integer")
+ end
+ end
end
diff --git a/spec/ruby/core/rational/zero_spec.rb b/spec/ruby/core/rational/zero_spec.rb
index e6dd751922..2e4f783d5c 100644
--- a/spec/ruby/core/rational/zero_spec.rb
+++ b/spec/ruby/core/rational/zero_spec.rb
@@ -1,13 +1,14 @@
+require_relative "../../spec_helper"
describe "Rational#zero?" do
it "returns true if the numerator is 0" do
- Rational(0,26).zero?.should be_true
+ Rational(0,26).zero?.should == true
end
it "returns true if the numerator is 0.0" do
- Rational(0.0,26).zero?.should be_true
+ Rational(0.0,26).zero?.should == true
end
it "returns false if the numerator isn't 0" do
- Rational(26).zero?.should be_false
+ Rational(26).zero?.should == false
end
end
diff --git a/spec/ruby/core/refinement/append_features_spec.rb b/spec/ruby/core/refinement/append_features_spec.rb
new file mode 100644
index 0000000000..cffc9ed308
--- /dev/null
+++ b/spec/ruby/core/refinement/append_features_spec.rb
@@ -0,0 +1,19 @@
+require_relative '../../spec_helper'
+
+describe "Refinement#append_features" do
+ it "is not defined" do
+ Refinement.private_instance_methods(true).should_not.include?(:append_features)
+ end
+
+ it "is not called by Module#include" do
+ c = Class.new
+ Module.new do
+ refine c do
+ called = false
+ define_method(:append_features){called = true}
+ proc{c.include(self)}.should.raise(TypeError)
+ called.should == false
+ end
+ end
+ end
+end
diff --git a/spec/ruby/core/refinement/extend_object_spec.rb b/spec/ruby/core/refinement/extend_object_spec.rb
new file mode 100644
index 0000000000..f6fe2a60ea
--- /dev/null
+++ b/spec/ruby/core/refinement/extend_object_spec.rb
@@ -0,0 +1,21 @@
+require_relative '../../spec_helper'
+
+describe "Refinement#extend_object" do
+ it "is not defined" do
+ Refinement.private_instance_methods(true).should_not.include?(:extend_object)
+ end
+
+ it "is not called by Object#extend" do
+ c = Class.new
+ Module.new do
+ refine c do
+ called = false
+ define_method(:extend_object) { called = true }
+ -> {
+ c.extend(self)
+ }.should.raise(TypeError)
+ called.should == false
+ end
+ end
+ end
+end
diff --git a/spec/ruby/core/refinement/fixtures/classes.rb b/spec/ruby/core/refinement/fixtures/classes.rb
new file mode 100644
index 0000000000..94324db47c
--- /dev/null
+++ b/spec/ruby/core/refinement/fixtures/classes.rb
@@ -0,0 +1,10 @@
+module RefinementSpec
+
+ module ModuleWithAncestors
+ include Module.new do
+ def indent(level)
+ " " * level + self
+ end
+ end
+ end
+end
diff --git a/spec/ruby/core/refinement/import_methods_spec.rb b/spec/ruby/core/refinement/import_methods_spec.rb
new file mode 100644
index 0000000000..bcb5e9b066
--- /dev/null
+++ b/spec/ruby/core/refinement/import_methods_spec.rb
@@ -0,0 +1,287 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe "Refinement#import_methods" do
+ context "when methods are defined in Ruby code" do
+ it "imports methods" do
+ str_utils = Module.new do
+ def indent(level)
+ " " * level + self
+ end
+ end
+
+ Module.new do
+ refine String do
+ import_methods str_utils
+ "foo".indent(3).should == " foo"
+ end
+ end
+ end
+
+ it "throws an exception when argument is not a module" do
+ Module.new do
+ refine String do
+ -> {
+ import_methods Integer
+ }.should.raise(TypeError, "wrong argument type Class (expected Module)")
+ end
+ end
+ end
+
+ it "imports methods from multiple modules" do
+ str_utils = Module.new do
+ def indent(level)
+ " " * level + self
+ end
+ end
+
+ str_utils_fancy = Module.new do
+ def indent_star(level)
+ "*" * level + self
+ end
+ end
+
+ Module.new do
+ refine String do
+ import_methods str_utils, str_utils_fancy
+ "foo".indent(3).should == " foo"
+ "foo".indent_star(3).should == "***foo"
+ end
+ end
+ end
+
+ it "imports a method defined in the last module if method with same name is defined in multiple modules" do
+ str_utils = Module.new do
+ def indent(level)
+ " " * level + self
+ end
+ end
+
+ str_utils_fancy = Module.new do
+ def indent(level)
+ "*" * level + self
+ end
+ end
+
+ Module.new do
+ refine String do
+ import_methods str_utils, str_utils_fancy
+ "foo".indent(3).should == "***foo"
+ end
+ end
+ end
+
+ it "still imports methods of modules listed before a module that contains method not defined in Ruby" do
+ str_utils = Module.new do
+ def indent(level)
+ " " * level + self
+ end
+ end
+
+ string_refined = Module.new do
+ refine String do
+ -> {
+ import_methods str_utils, Kernel
+ }.should.raise(ArgumentError)
+ end
+ end
+
+ Module.new do
+ using string_refined
+ "foo".indent(3).should == " foo"
+ end
+ end
+ end
+
+ it "warns if a module includes/prepends some other module" do
+ module1 = Module.new do
+ end
+
+ module2 = Module.new do
+ include module1
+ end
+
+ Module.new do
+ refine String do
+ -> {
+ import_methods module2
+ }.should complain(/warning: #<Module:\w*> has ancestors, but Refinement#import_methods doesn't import their methods/)
+ end
+ end
+
+ Module.new do
+ refine String do
+ -> {
+ import_methods RefinementSpec::ModuleWithAncestors
+ }.should complain(/warning: RefinementSpec::ModuleWithAncestors has ancestors, but Refinement#import_methods doesn't import their methods/)
+ end
+ end
+ end
+
+ it "doesn't import methods from included/prepended modules" do
+ Module.new do
+ refine String do
+ suppress_warning { import_methods RefinementSpec::ModuleWithAncestors }
+ end
+
+ using self
+ -> {
+ "foo".indent(3)
+ }.should.raise(NoMethodError, /undefined method [`']indent' for ("foo":String|an instance of String)/)
+ end
+ end
+
+ it "doesn't import any methods if one of the arguments is not a module" do
+ str_utils = Module.new do
+ def indent(level)
+ " " * level + self
+ end
+ end
+
+ string_refined = Module.new do
+ refine String do
+ -> {
+ import_methods str_utils, Integer
+ }.should.raise(TypeError)
+ end
+ end
+
+ Module.new do
+ using string_refined
+ -> {
+ "foo".indent(3)
+ }.should.raise(NoMethodError)
+ end
+ end
+
+ it "imports methods from multiple modules so that methods see other's module's methods" do
+ str_utils = Module.new do
+ def indent(level)
+ " " * level + self
+ end
+ end
+
+ str_utils_normal = Module.new do
+ def indent_normal(level)
+ self.indent(level)
+ end
+ end
+
+ Module.new do
+ refine String do
+ import_methods str_utils, str_utils_normal
+ end
+
+ using self
+ "foo".indent_normal(3).should == " foo"
+ end
+ end
+
+ it "imports methods from module so that methods can see each other" do
+ str_utils = Module.new do
+ def indent(level)
+ " " * level + self
+ end
+
+ def indent_with_dot(level)
+ self.indent(level) + "."
+ end
+ end
+
+ Module.new do
+ refine String do
+ import_methods str_utils
+ end
+
+ using self
+ "foo".indent_with_dot(3).should == " foo."
+ end
+ end
+
+ it "doesn't import module's class methods" do
+ str_utils = Module.new do
+ def self.indent(level)
+ " " * level + self
+ end
+ end
+
+ Module.new do
+ refine String do
+ import_methods str_utils
+ end
+
+ using self
+ -> {
+ String.indent(3)
+ }.should.raise(NoMethodError, /undefined method [`']indent' for (String:Class|class String)/)
+ end
+ end
+
+ it "imports module methods with super" do
+ class_to_refine = Class.new do
+ def foo(number)
+ 2 * number
+ end
+ end
+
+ extension = Module.new do
+ def foo(number)
+ super * 2
+ end
+ end
+
+ refinement = Module.new do
+ refine class_to_refine do
+ import_methods extension
+ end
+ end
+
+ Module.new do
+ using refinement
+ class_to_refine.new.foo(2).should == 8
+ end
+ end
+
+ it "correctly sets owner as the refinement module" do
+ str_utils = Module.new do
+ def indent(level)
+ " " * level + self
+ end
+ end
+
+ refinement = Module.new do
+ refine String do
+ import_methods str_utils
+ end
+ end
+
+ Module.new do
+ using refinement
+
+ String.instance_method(:indent).owner.should == refinement.refinements.first
+ end
+ end
+
+ context "when methods are not defined in Ruby code" do
+ it "raises ArgumentError" do
+ Module.new do
+ refine String do
+ -> {
+ import_methods Kernel
+ }.should.raise(ArgumentError)
+ end
+ end
+ end
+
+ it "raises ArgumentError when importing methods from C extension" do
+ require 'zlib'
+ Module.new do
+ refine String do
+ -> {
+ import_methods Zlib
+ }.should.raise(ArgumentError, /Can't import method which is not defined with Ruby code: Zlib#*/)
+ end
+ end
+ end
+ end
+end
diff --git a/spec/ruby/core/refinement/include_spec.rb b/spec/ruby/core/refinement/include_spec.rb
new file mode 100644
index 0000000000..55ac89ffb5
--- /dev/null
+++ b/spec/ruby/core/refinement/include_spec.rb
@@ -0,0 +1,13 @@
+require_relative '../../spec_helper'
+
+describe "Refinement#include" do
+ it "raises a TypeError" do
+ Module.new do
+ refine String do
+ -> {
+ include Module.new
+ }.should.raise(TypeError, "Refinement#include has been removed")
+ end
+ end
+ end
+end
diff --git a/spec/ruby/core/refinement/prepend_features_spec.rb b/spec/ruby/core/refinement/prepend_features_spec.rb
new file mode 100644
index 0000000000..9dc5838f1f
--- /dev/null
+++ b/spec/ruby/core/refinement/prepend_features_spec.rb
@@ -0,0 +1,19 @@
+require_relative '../../spec_helper'
+
+describe "Refinement#prepend_features" do
+ it "is not defined" do
+ Refinement.private_instance_methods(true).should_not.include?(:prepend_features)
+ end
+
+ it "is not called by Module#prepend" do
+ c = Class.new
+ Module.new do
+ refine c do
+ called = false
+ define_method(:prepend_features){called = true}
+ proc{c.prepend(self)}.should.raise(TypeError)
+ called.should == false
+ end
+ end
+ end
+end
diff --git a/spec/ruby/core/refinement/prepend_spec.rb b/spec/ruby/core/refinement/prepend_spec.rb
new file mode 100644
index 0000000000..fd70dd6f97
--- /dev/null
+++ b/spec/ruby/core/refinement/prepend_spec.rb
@@ -0,0 +1,13 @@
+require_relative '../../spec_helper'
+
+describe "Refinement#prepend" do
+ it "raises a TypeError" do
+ Module.new do
+ refine String do
+ -> {
+ prepend Module.new
+ }.should.raise(TypeError, "Refinement#prepend has been removed")
+ end
+ end
+ end
+end
diff --git a/spec/ruby/core/refinement/refined_class_spec.rb b/spec/ruby/core/refinement/refined_class_spec.rb
new file mode 100644
index 0000000000..90f8d963d8
--- /dev/null
+++ b/spec/ruby/core/refinement/refined_class_spec.rb
@@ -0,0 +1,33 @@
+require_relative "../../spec_helper"
+
+describe "Refinement#refined_class" do
+ ruby_version_is ""..."3.4" do
+ it "has been deprecated in favour of Refinement#target" do
+ refinement_int = nil
+
+ Module.new do
+ refine Integer do
+ refinement_int = self
+ end
+ end
+
+ -> {
+ refinement_int.refined_class
+ }.should complain(/warning: Refinement#refined_class is deprecated and will be removed in Ruby 3.4; use Refinement#target instead/)
+ end
+ end
+
+ ruby_version_is "3.4" do
+ it "has been removed" do
+ refinement_int = nil
+
+ Module.new do
+ refine Integer do
+ refinement_int = self
+ end
+ end
+
+ refinement_int.should_not.respond_to?(:refined_class)
+ end
+ end
+end
diff --git a/spec/ruby/core/refinement/target_spec.rb b/spec/ruby/core/refinement/target_spec.rb
new file mode 100644
index 0000000000..eaee71e8c6
--- /dev/null
+++ b/spec/ruby/core/refinement/target_spec.rb
@@ -0,0 +1,15 @@
+require_relative "../../spec_helper"
+
+describe "Refinement#target" do
+ it "returns the class refined by the receiver" do
+ refinement_int = nil
+
+ Module.new do
+ refine Integer do
+ refinement_int = self
+ end
+ end
+
+ refinement_int.target.should == Integer
+ end
+end
diff --git a/spec/ruby/core/regexp/case_compare_spec.rb b/spec/ruby/core/regexp/case_compare_spec.rb
index 84ac957d12..29aada70bc 100644
--- a/spec/ruby/core/regexp/case_compare_spec.rb
+++ b/spec/ruby/core/regexp/case_compare_spec.rb
@@ -1,25 +1,35 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Regexp#===" do
it "is true if there is a match" do
- (/abc/ === "aabcc").should be_true
+ (/abc/ === "aabcc").should == true
end
it "is false if there is no match" do
- (/abc/ === "xyz").should be_false
+ (/abc/ === "xyz").should == false
end
it "returns true if it matches a Symbol" do
- (/a/ === :a).should be_true
+ (/a/ === :a).should == true
end
it "returns false if it does not match a Symbol" do
- (/a/ === :b).should be_false
+ (/a/ === :b).should == false
end
- # mirroring https://github.com/ruby/ruby/blob/trunk/test/ruby/test_regexp.rb
+ # mirroring https://github.com/ruby/ruby/blob/master/test/ruby/test_regexp.rb
it "returns false if the other value cannot be coerced to a string" do
- (/abc/ === nil).should be_false
- (/abc/ === /abc/).should be_false
+ (/abc/ === nil).should == false
+ (/abc/ === /abc/).should == false
+ end
+
+ it "uses #to_str on string-like objects" do
+ stringlike = Class.new do
+ def to_str
+ "abc"
+ end
+ end.new
+
+ (/abc/ === stringlike).should == true
end
end
diff --git a/spec/ruby/core/regexp/casefold_spec.rb b/spec/ruby/core/regexp/casefold_spec.rb
index 55efcaa765..d36467a989 100644
--- a/spec/ruby/core/regexp/casefold_spec.rb
+++ b/spec/ruby/core/regexp/casefold_spec.rb
@@ -1,8 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Regexp#casefold?" do
it "returns the value of the case-insensitive flag" do
- /abc/i.casefold?.should == true
- /xyz/.casefold?.should == false
+ /abc/i.should.casefold?
+ /xyz/.should_not.casefold?
end
end
diff --git a/spec/ruby/core/regexp/compile_spec.rb b/spec/ruby/core/regexp/compile_spec.rb
index 530816e07c..887c8d77dc 100644
--- a/spec/ruby/core/regexp/compile_spec.rb
+++ b/spec/ruby/core/regexp/compile_spec.rb
@@ -1,18 +1,19 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/new_ascii', __FILE__)
-require File.expand_path('../shared/new_ascii_8bit', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/new'
describe "Regexp.compile" do
- it_behaves_like :regexp_new_ascii, :compile
- it_behaves_like :regexp_new_ascii_8bit, :compile
+ it_behaves_like :regexp_new, :compile
end
describe "Regexp.compile given a String" do
- it_behaves_like :regexp_new_string_ascii, :compile
- it_behaves_like :regexp_new_string_ascii_8bit, :compile
+ it_behaves_like :regexp_new_string, :compile
+ it_behaves_like :regexp_new_string_binary, :compile
end
describe "Regexp.compile given a Regexp" do
- it_behaves_like :regexp_new_regexp_ascii, :compile
- it_behaves_like :regexp_new_regexp_ascii_8bit, :compile
+ it_behaves_like :regexp_new_regexp, :compile
+end
+
+describe "Regexp.compile given a non-String/Regexp" do
+ it_behaves_like :regexp_new_non_string_or_regexp, :compile
end
diff --git a/spec/ruby/core/regexp/encoding_spec.rb b/spec/ruby/core/regexp/encoding_spec.rb
index c30519c9d7..fb4fdba064 100644
--- a/spec/ruby/core/regexp/encoding_spec.rb
+++ b/spec/ruby/core/regexp/encoding_spec.rb
@@ -1,9 +1,9 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Regexp#encoding" do
it "returns an Encoding object" do
- /glar/.encoding.should be_an_instance_of(Encoding)
+ /glar/.encoding.should.instance_of?(Encoding)
end
it "defaults to US-ASCII if the Regexp contains only US-ASCII character" do
@@ -14,8 +14,8 @@ describe "Regexp#encoding" do
/ASCII/n.encoding.should == Encoding::US_ASCII
end
- it "returns ASCII-8BIT if the 'n' modifier is supplied and non-US-ASCII characters are present" do
- /\xc2\xa1/n.encoding.should == Encoding::ASCII_8BIT
+ it "returns BINARY if the 'n' modifier is supplied and non-US-ASCII characters are present" do
+ /\xc2\xa1/n.encoding.should == Encoding::BINARY
end
it "defaults to UTF-8 if \\u escapes appear" do
@@ -55,4 +55,8 @@ describe "Regexp#encoding" do
/foo/.encoding.should_not == Encoding::EUC_JP
Encoding.default_internal = old_internal
end
+
+ it "allows otherwise invalid characters if NOENCODING is specified" do
+ Regexp.new('([\x00-\xFF])', Regexp::IGNORECASE | Regexp::NOENCODING).encoding.should == Encoding::BINARY
+ end
end
diff --git a/spec/ruby/core/regexp/eql_spec.rb b/spec/ruby/core/regexp/eql_spec.rb
index 7288ff45fe..5924333fbd 100644
--- a/spec/ruby/core/regexp/eql_spec.rb
+++ b/spec/ruby/core/regexp/eql_spec.rb
@@ -1,6 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/equal_value', __FILE__)
+require_relative '../../spec_helper'
describe "Regexp#eql?" do
- it_behaves_like :regexp_eql, :eql?
+ it "is an alias of Regexp#==" do
+ Regexp.instance_method(:eql?).should == Regexp.instance_method(:==)
+ end
end
diff --git a/spec/ruby/core/regexp/equal_value_spec.rb b/spec/ruby/core/regexp/equal_value_spec.rb
index 4ddaec8e4e..ad8dc33222 100644
--- a/spec/ruby/core/regexp/equal_value_spec.rb
+++ b/spec/ruby/core/regexp/equal_value_spec.rb
@@ -1,6 +1,33 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/equal_value', __FILE__)
+require_relative '../../spec_helper'
describe "Regexp#==" do
- it_behaves_like :regexp_eql, :==
+ it "is true if self and other have the same pattern" do
+ (/abc/ == /abc/).should == true
+ (/abc/ == /abd/).should == false
+ end
+
+ not_supported_on :opal do
+ it "is true if self and other have the same character set code" do
+ (/abc/ == /abc/x).should == false
+ (/abc/x == /abc/x).should == true
+ (/abc/u == /abc/n).should == false
+ (/abc/u == /abc/u).should == true
+ (/abc/n == /abc/n).should == true
+ end
+ end
+
+ it "is true if other has the same #casefold? values" do
+ (/abc/ == /abc/i).should == false
+ (/abc/i == /abc/i).should == true
+ end
+
+ not_supported_on :opal do
+ it "is true if self does not specify /n option and other does" do
+ (// == //n).should == true
+ end
+
+ it "is true if self specifies /n option and other does not" do
+ (//n == //).should == true
+ end
+ end
end
diff --git a/spec/ruby/core/regexp/escape_spec.rb b/spec/ruby/core/regexp/escape_spec.rb
index 56b6cc5059..99e5eb71d6 100644
--- a/spec/ruby/core/regexp/escape_spec.rb
+++ b/spec/ruby/core/regexp/escape_spec.rb
@@ -1,6 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/quote', __FILE__)
+require_relative '../../spec_helper'
describe "Regexp.escape" do
- it_behaves_like :regexp_quote, :escape
+ it "is an alias of Regexp.quote" do
+ Regexp.method(:escape).should == Regexp.method(:quote)
+ end
end
diff --git a/spec/ruby/core/regexp/fixed_encoding_spec.rb b/spec/ruby/core/regexp/fixed_encoding_spec.rb
index 8a11de9575..5d8b1c2860 100644
--- a/spec/ruby/core/regexp/fixed_encoding_spec.rb
+++ b/spec/ruby/core/regexp/fixed_encoding_spec.rb
@@ -1,36 +1,36 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Regexp#fixed_encoding?" do
it "returns false by default" do
- /needle/.fixed_encoding?.should be_false
+ /needle/.fixed_encoding?.should == false
end
it "returns false if the 'n' modifier was supplied to the Regexp" do
- /needle/n.fixed_encoding?.should be_false
+ /needle/n.fixed_encoding?.should == false
end
it "returns true if the 'u' modifier was supplied to the Regexp" do
- /needle/u.fixed_encoding?.should be_true
+ /needle/u.fixed_encoding?.should == true
end
it "returns true if the 's' modifier was supplied to the Regexp" do
- /needle/s.fixed_encoding?.should be_true
+ /needle/s.fixed_encoding?.should == true
end
it "returns true if the 'e' modifier was supplied to the Regexp" do
- /needle/e.fixed_encoding?.should be_true
+ /needle/e.fixed_encoding?.should == true
end
it "returns true if the Regexp contains a \\u escape" do
- /needle \u{8768}/.fixed_encoding?.should be_true
+ /needle \u{8768}/.fixed_encoding?.should == true
end
it "returns true if the Regexp contains a UTF-8 literal" do
- /文字化ã‘/.fixed_encoding?.should be_true
+ /文字化ã‘/.fixed_encoding?.should == true
end
it "returns true if the Regexp was created with the Regexp::FIXEDENCODING option" do
- Regexp.new("", Regexp::FIXEDENCODING).fixed_encoding?.should be_true
+ Regexp.new("", Regexp::FIXEDENCODING).fixed_encoding?.should == true
end
end
diff --git a/spec/ruby/core/regexp/hash_spec.rb b/spec/ruby/core/regexp/hash_spec.rb
index 77b79b1ce5..2d42e288e6 100644
--- a/spec/ruby/core/regexp/hash_spec.rb
+++ b/spec/ruby/core/regexp/hash_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Regexp#hash" do
it "is provided" do
diff --git a/spec/ruby/core/regexp/initialize_spec.rb b/spec/ruby/core/regexp/initialize_spec.rb
index 3c32f97a31..1c0133acae 100644
--- a/spec/ruby/core/regexp/initialize_spec.rb
+++ b/spec/ruby/core/regexp/initialize_spec.rb
@@ -1,15 +1,29 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Regexp#initialize" do
it "is a private method" do
- Regexp.should have_private_method(:initialize)
+ Regexp.private_instance_methods(false).should.include?(:initialize)
end
- it "raises a SecurityError on a Regexp literal" do
- lambda { //.send(:initialize, "") }.should raise_error(SecurityError)
+ it "raises a FrozenError on a Regexp literal" do
+ -> { //.send(:initialize, "") }.should.raise(FrozenError)
end
- it "raises a TypeError on an initialized non-literal Regexp" do
- lambda { Regexp.new("").send(:initialize, "") }.should raise_error(TypeError)
+ ruby_version_is "4.1" do
+ it "raises a FrozenError on an initialized non-literal Regexp" do
+ regexp = Regexp.new("")
+ -> { regexp.send(:initialize, "") }.should.raise(FrozenError)
+ end
+ end
+
+ ruby_version_is ""..."4.1" do
+ it "raises a TypeError on an initialized non-literal Regexp" do
+ -> { Regexp.new("").send(:initialize, "") }.should.raise(TypeError)
+ end
+ end
+
+ it "raises a TypeError on an initialized non-literal Regexp subclass" do
+ r = Class.new(Regexp).new("")
+ -> { r.send(:initialize, "") }.should.raise(TypeError)
end
end
diff --git a/spec/ruby/core/regexp/inspect_spec.rb b/spec/ruby/core/regexp/inspect_spec.rb
index a2855cae5b..f4e39234f5 100644
--- a/spec/ruby/core/regexp/inspect_spec.rb
+++ b/spec/ruby/core/regexp/inspect_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Regexp#inspect" do
it "returns a formatted string that would eval to the same regexp" do
diff --git a/spec/ruby/core/regexp/last_match_spec.rb b/spec/ruby/core/regexp/last_match_spec.rb
index 4673554f91..6c256cc1cf 100644
--- a/spec/ruby/core/regexp/last_match_spec.rb
+++ b/spec/ruby/core/regexp/last_match_spec.rb
@@ -1,14 +1,56 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Regexp.last_match" do
it "returns MatchData instance when not passed arguments" do
/c(.)t/ =~ 'cat'
- Regexp.last_match.should be_kind_of(MatchData)
+ Regexp.last_match.should.is_a?(MatchData)
end
- it "returns the nth field in this MatchData when passed a Fixnum" do
+ it "returns the nth field in this MatchData when passed an Integer" do
/c(.)t/ =~ 'cat'
Regexp.last_match(1).should == 'a'
end
+
+ it "returns nil when there is no match" do
+ /foo/ =~ "TEST123"
+ Regexp.last_match(:test).should == nil
+ Regexp.last_match(1).should == nil
+ Regexp.last_match(Object.new).should == nil
+ Regexp.last_match("test").should == nil
+ end
+
+ describe "when given a Symbol" do
+ it "returns a named capture" do
+ /(?<test>[A-Z]+.*)/ =~ "TEST123"
+ Regexp.last_match(:test).should == "TEST123"
+ end
+
+ it "raises an IndexError when given a missing name" do
+ /(?<test>[A-Z]+.*)/ =~ "TEST123"
+ -> { Regexp.last_match(:missing) }.should.raise(IndexError)
+ end
+ end
+
+ describe "when given a String" do
+ it "returns a named capture" do
+ /(?<test>[A-Z]+.*)/ =~ "TEST123"
+ Regexp.last_match("test").should == "TEST123"
+ end
+ end
+
+ describe "when given an Object" do
+ it "coerces argument to an index using #to_int" do
+ obj = mock("converted to int")
+ obj.should_receive(:to_int).and_return(1)
+ /(?<test>[A-Z]+.*)/ =~ "TEST123"
+ Regexp.last_match(obj).should == "TEST123"
+ end
+
+ it "raises a TypeError when unable to coerce" do
+ obj = Object.new
+ /(?<test>[A-Z]+.*)/ =~ "TEST123"
+ -> { Regexp.last_match(obj) }.should.raise(TypeError)
+ end
+ end
end
diff --git a/spec/ruby/core/regexp/linear_time_spec.rb b/spec/ruby/core/regexp/linear_time_spec.rb
new file mode 100644
index 0000000000..f70021dfed
--- /dev/null
+++ b/spec/ruby/core/regexp/linear_time_spec.rb
@@ -0,0 +1,80 @@
+require_relative '../../spec_helper'
+
+describe "Regexp.linear_time?" do
+ it "returns true if matching can be done in linear time" do
+ Regexp.linear_time?(/a/).should == true
+ Regexp.linear_time?('a').should == true
+ end
+
+ it "returns true if matching can be done in linear time for a binary Regexp" do
+ Regexp.linear_time?(/[\x80-\xff]/n).should == true
+ end
+
+ it "return false if matching can't be done in linear time" do
+ Regexp.linear_time?(/(a)\1/).should == false
+ Regexp.linear_time?("(a)\\1").should == false
+ end
+
+ it "accepts flags for string argument" do
+ Regexp.linear_time?('a', Regexp::IGNORECASE).should == true
+ end
+
+ it "warns about flags being ignored for regexp arguments" do
+ -> {
+ Regexp.linear_time?(/a/, Regexp::IGNORECASE)
+ }.should complain(/warning: flags ignored/)
+ end
+
+ it "returns true for positive lookahead" do
+ Regexp.linear_time?(/a*(?:(?=a*)a)*b/).should == true
+ end
+
+ it "returns true for positive lookbehind" do
+ Regexp.linear_time?(/a*(?:(?<=a)a*)*b/).should == true
+ end
+
+ it "returns true for negative lookbehind" do
+ Regexp.linear_time?(/a*(?:(?<!a)a*)*b/).should == true
+ end
+
+ # There are two known ways to make Regexp linear:
+ # * Using a DFA (deterministic finite-state automaton) Regexp engine, which always matches in linear time (e.g. TruffleRuby with TRegex)
+ # * Caching position and state to avoid catastrophic backtracking (e.g. CRuby: https://bugs.ruby-lang.org/issues/19104)
+ #
+ # Both approach should be allowed and given that DFA Regexp engines
+ # are much faster there should be no specs preventing using them.
+ uses_regexp_caching = RUBY_ENGINE == 'ruby'
+ uses_dfa_regexp_engine = !uses_regexp_caching
+
+ # The following specs should not be relied upon,
+ # they are here only to illustrate differences between Regexp engines.
+ guard -> { uses_regexp_caching } do
+ it "returns true for negative lookahead" do
+ Regexp.linear_time?(/a*(?:(?!a*)a*)*b/).should == true
+ end
+
+ it "returns true for atomic groups" do
+ Regexp.linear_time?(/a*(?:(?>a)a*)*b/).should == true
+ end
+
+ it "returns true for possessive quantifiers" do
+ Regexp.linear_time?(/a*(?:(?:a)?+a*)*b/).should == true
+ end
+
+ it "returns true for positive lookbehind with capture group" do
+ Regexp.linear_time?(/.(?<=(a))/).should == true
+ end
+ end
+
+ # The following specs should not be relied upon,
+ # they are here only to illustrate differences between Regexp engines.
+ guard -> { uses_dfa_regexp_engine } do
+ it "returns true for non-recursive subexpression call" do
+ Regexp.linear_time?(/(?<a>a){0}\g<a>/).should == true
+ end
+
+ it "returns true for positive lookahead with capture group" do
+ Regexp.linear_time?(/x+(?=(a))/).should == true
+ end
+ end
+end
diff --git a/spec/ruby/core/regexp/match_spec.rb b/spec/ruby/core/regexp/match_spec.rb
index 872c3ff59e..276cecc8e4 100644
--- a/spec/ruby/core/regexp/match_spec.rb
+++ b/spec/ruby/core/regexp/match_spec.rb
@@ -1,18 +1,18 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe :regexp_match, shared: true do
it "returns nil if there is no match" do
- /xyz/.send(@method,"abxyc").should be_nil
+ /xyz/.send(@method,"abxyc").should == nil
end
it "returns nil if the object is nil" do
- /\w+/.send(@method, nil).should be_nil
+ /\w+/.send(@method, nil).should == nil
end
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,18 +24,22 @@ 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)
+ /(.)(.)(.)/.match("abc").should.is_a?(MatchData)
end
it "returns a MatchData object, when argument is a Symbol" do
- /(.)(.)(.)/.match(:abc).should be_kind_of(MatchData)
+ /(.)(.)(.)/.match(:abc).should.is_a?(MatchData)
end
it "raises a TypeError on an uninitialized Regexp" do
- lambda { Regexp.allocate.match('foo') }.should raise_error(TypeError)
+ -> { Regexp.allocate.match('foo') }.should.raise(TypeError)
+ end
+
+ it "raises TypeError on an uninitialized Regexp" do
+ -> { Regexp.allocate.match('foo'.encode("UTF-16LE")) }.should.raise(TypeError)
end
describe "with [string, position]" do
@@ -44,15 +48,13 @@ describe "Regexp#match" do
/(.).(.)/.match("01234", 1).captures.should == ["1", "3"]
end
- with_feature :encoding do
- it "uses the start as a character offset" do
- /(.).(.)/.match("零一二三四", 1).captures.should == ["一", "三"]
- end
+ it "uses the start as a character offset" do
+ /(.).(.)/.match("零一二三四", 1).captures.should == ["一", "三"]
+ end
- it "raises an ArgumentError for an invalid encoding" do
- x96 = ([150].pack('C')).force_encoding('utf-8')
- lambda { /(.).(.)/.match("Hello, #{x96} world!", 1) }.should raise_error(ArgumentError)
- end
+ it "raises an ArgumentError for an invalid encoding" do
+ x96 = ([150].pack('C')).force_encoding('utf-8')
+ -> { /(.).(.)/.match("Hello, #{x96} world!", 1) }.should.raise(ArgumentError)
end
end
@@ -61,22 +63,20 @@ describe "Regexp#match" do
/(.).(.)/.match("01234", -4).captures.should == ["1", "3"]
end
- with_feature :encoding do
- it "uses the start as a character offset" do
- /(.).(.)/.match("零一二三四", -4).captures.should == ["一", "三"]
- end
+ it "uses the start as a character offset" do
+ /(.).(.)/.match("零一二三四", -4).captures.should == ["一", "三"]
+ end
- it "raises an ArgumentError for an invalid encoding" do
- x96 = ([150].pack('C')).force_encoding('utf-8')
- lambda { /(.).(.)/.match("Hello, #{x96} world!", -1) }.should raise_error(ArgumentError)
- end
+ it "raises an ArgumentError for an invalid encoding" do
+ x96 = ([150].pack('C')).force_encoding('utf-8')
+ -> { /(.).(.)/.match("Hello, #{x96} world!", -1) }.should.raise(ArgumentError)
end
end
describe "when passed a block" do
it "yields the MatchData" do
/./.match("abc") {|m| ScratchPad.record m }
- ScratchPad.recorded.should be_kind_of(MatchData)
+ ScratchPad.recorded.should.is_a?(MatchData)
end
it "returns the block result" do
@@ -94,49 +94,47 @@ describe "Regexp#match" do
it "resets $~ if passed nil" do
# set $~
/./.match("a")
- $~.should be_kind_of(MatchData)
+ $~.should.is_a?(MatchData)
/1/.match(nil)
- $~.should be_nil
+ $~.should == nil
end
- it "raises TypeError when the given argument cannot be coarce to String" do
+ it "raises TypeError when the given argument cannot be coerced to String" do
f = 1
- lambda { /foo/.match(f)[0] }.should raise_error(TypeError)
+ -> { /foo/.match(f)[0] }.should.raise(TypeError)
end
it "raises TypeError when the given argument is an Exception" do
f = Exception.new("foo")
- lambda { /foo/.match(f)[0] }.should raise_error(TypeError)
+ -> { /foo/.match(f)[0] }.should.raise(TypeError)
end
end
-ruby_version_is "2.4" do
- describe "Regexp#match?" do
- before :each do
- # Resetting Regexp.last_match
- /DONTMATCH/.match ''
- end
+describe "Regexp#match?" do
+ before :each do
+ # Resetting Regexp.last_match
+ /DONTMATCH/.match ''
+ end
- context "when matches the given value" do
- it "returns true but does not set Regexp.last_match" do
- /string/i.match?('string').should be_true
- Regexp.last_match.should be_nil
- end
+ context "when matches the given value" do
+ it "returns true but does not set Regexp.last_match" do
+ /string/i.match?('string').should == true
+ Regexp.last_match.should == nil
end
+ end
- it "returns false when does not match the given value" do
- /STRING/.match?('string').should be_false
- end
+ it "returns false when does not match the given value" do
+ /STRING/.match?('string').should == false
+ end
- it "takes matching position as the 2nd argument" do
- /str/i.match?('string', 0).should be_true
- /str/i.match?('string', 1).should be_false
- end
+ it "takes matching position as the 2nd argument" do
+ /str/i.match?('string', 0).should == true
+ /str/i.match?('string', 1).should == false
+ end
- it "returns false when given nil" do
- /./.match?(nil).should be_false
- end
+ it "returns false when given nil" do
+ /./.match?(nil).should == false
end
end
diff --git a/spec/ruby/core/regexp/named_captures_spec.rb b/spec/ruby/core/regexp/named_captures_spec.rb
index c495d00a35..4d3fdd23ab 100644
--- a/spec/ruby/core/regexp/named_captures_spec.rb
+++ b/spec/ruby/core/regexp/named_captures_spec.rb
@@ -1,8 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Regexp#named_captures" do
it "returns a Hash" do
- /foo/.named_captures.should be_an_instance_of(Hash)
+ /foo/.named_captures.should.instance_of?(Hash)
end
it "returns an empty Hash when there are no capture groups" do
@@ -17,7 +17,7 @@ describe "Regexp#named_captures" do
it "sets the values of the Hash to Arrays" do
rex = /this (?<is>is) [aA] (?<pat>pate?rn)/
rex.named_captures.values.each do |value|
- value.should be_an_instance_of(Array)
+ value.should.instance_of?(Array)
end
end
diff --git a/spec/ruby/core/regexp/names_spec.rb b/spec/ruby/core/regexp/names_spec.rb
index bbd994d993..9013f41e20 100644
--- a/spec/ruby/core/regexp/names_spec.rb
+++ b/spec/ruby/core/regexp/names_spec.rb
@@ -1,8 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Regexp#names" do
it "returns an Array" do
- /foo/.names.should be_an_instance_of(Array)
+ /foo/.names.should.instance_of?(Array)
end
it "returns an empty Array if there are no named captures" do
@@ -11,7 +11,7 @@ describe "Regexp#names" do
it "returns each named capture as a String" do
/n(?<cap>ee)d(?<ture>le)/.names.each do |name|
- name.should be_an_instance_of(String)
+ name.should.instance_of?(String)
end
end
diff --git a/spec/ruby/core/regexp/new_spec.rb b/spec/ruby/core/regexp/new_spec.rb
index c9581e661f..79210e9a23 100644
--- a/spec/ruby/core/regexp/new_spec.rb
+++ b/spec/ruby/core/regexp/new_spec.rb
@@ -1,30 +1,19 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/new_ascii', __FILE__)
-require File.expand_path('../shared/new_ascii_8bit', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/new'
describe "Regexp.new" do
- it_behaves_like :regexp_new_ascii, :new
- it_behaves_like :regexp_new_ascii_8bit, :new
+ it_behaves_like :regexp_new, :new
end
describe "Regexp.new given a String" do
- it_behaves_like :regexp_new_string_ascii, :new
- it_behaves_like :regexp_new_string_ascii_8bit, :new
+ it_behaves_like :regexp_new_string, :new
+ it_behaves_like :regexp_new_string_binary, :new
end
describe "Regexp.new given a Regexp" do
- it_behaves_like :regexp_new_regexp_ascii, :new
- it_behaves_like :regexp_new_regexp_ascii_8bit, :new
+ it_behaves_like :regexp_new_regexp, :new
end
-describe "Regexp.new given a Fixnum" do
- it "raises a TypeError" do
- lambda { Regexp.new(1) }.should raise_error(TypeError)
- end
-end
-
-describe "Regexp.new given a Float" do
- it "raises a TypeError" do
- lambda { Regexp.new(1.0) }.should raise_error(TypeError)
- end
+describe "Regexp.new given a non-String/Regexp" do
+ it_behaves_like :regexp_new_non_string_or_regexp, :new
end
diff --git a/spec/ruby/core/regexp/options_spec.rb b/spec/ruby/core/regexp/options_spec.rb
index 10aeeac919..c3401cee6e 100644
--- a/spec/ruby/core/regexp/options_spec.rb
+++ b/spec/ruby/core/regexp/options_spec.rb
@@ -1,10 +1,10 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Regexp#options" do
- it "returns a Fixnum bitvector of regexp options for the Regexp object" do
- /cat/.options.should be_kind_of(Fixnum)
+ it "returns an Integer bitvector of regexp options for the Regexp object" do
+ /cat/.options.should.is_a?(Integer)
not_supported_on :opal do
- /cat/ix.options.should be_kind_of(Fixnum)
+ /cat/ix.options.should.is_a?(Integer)
end
end
@@ -29,7 +29,7 @@ describe "Regexp#options" do
end
it "raises a TypeError on an uninitialized Regexp" do
- lambda { Regexp.allocate.options }.should raise_error(TypeError)
+ -> { Regexp.allocate.options }.should.raise(TypeError)
end
it "includes Regexp::FIXEDENCODING for a Regexp literal with the 'u' option" do
diff --git a/spec/ruby/core/regexp/quote_spec.rb b/spec/ruby/core/regexp/quote_spec.rb
index a38903ef15..27fa0c0669 100644
--- a/spec/ruby/core/regexp/quote_spec.rb
+++ b/spec/ruby/core/regexp/quote_spec.rb
@@ -1,6 +1,43 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/quote', __FILE__)
+# encoding: binary
+
+require_relative '../../spec_helper'
describe "Regexp.quote" do
- it_behaves_like :regexp_quote, :quote
+ it "escapes any characters with special meaning in a regular expression" do
+ Regexp.quote('\*?{}.+^$[]()- ').should == '\\\\\*\?\{\}\.\+\^\$\[\]\(\)\-\\ '
+ Regexp.quote("\*?{}.+^$[]()- ").should == '\\*\\?\\{\\}\\.\\+\\^\\$\\[\\]\\(\\)\\-\\ '
+ Regexp.quote('\n\r\f\t').should == '\\\\n\\\\r\\\\f\\\\t'
+ Regexp.quote("\n\r\f\t").should == '\\n\\r\\f\\t'
+ end
+
+ it "works with symbols" do
+ Regexp.quote(:symbol).should == 'symbol'
+ end
+
+ it "works with substrings" do
+ str = ".+[]()"[1...-1]
+ Regexp.quote(str).should == '\+\[\]\('
+ end
+
+ it "works for broken strings" do
+ Regexp.quote("a.\x85b.".dup.force_encoding("US-ASCII")).should =="a\\.\x85b\\.".dup.force_encoding("US-ASCII")
+ Regexp.quote("a.\x80".dup.force_encoding("UTF-8")).should == "a\\.\x80".dup.force_encoding("UTF-8")
+ end
+
+ it "sets the encoding of the result to US-ASCII if there are only US-ASCII characters present in the input String" do
+ str = "abc".dup.force_encoding("euc-jp")
+ Regexp.quote(str).encoding.should == Encoding::US_ASCII
+ end
+
+ it "sets the encoding of the result to the encoding of the String if any non-US-ASCII characters are present in an input String with valid encoding" do
+ str = "ã‚りãŒã¨ã†".dup.force_encoding("utf-8")
+ str.valid_encoding?.should == true
+ Regexp.quote(str).encoding.should == Encoding::UTF_8
+ end
+
+ it "sets the encoding of the result to BINARY if any non-US-ASCII characters are present in an input String with invalid encoding" do
+ str = "\xff".dup.force_encoding "us-ascii"
+ str.valid_encoding?.should == false
+ Regexp.quote("\xff").encoding.should == Encoding::BINARY
+ end
end
diff --git a/spec/ruby/core/regexp/shared/equal_value.rb b/spec/ruby/core/regexp/shared/equal_value.rb
deleted file mode 100644
index 803988de9e..0000000000
--- a/spec/ruby/core/regexp/shared/equal_value.rb
+++ /dev/null
@@ -1,31 +0,0 @@
-describe :regexp_eql, shared: true do
- it "is true if self and other have the same pattern" do
- /abc/.send(@method, /abc/).should == true
- /abc/.send(@method, /abd/).should == false
- end
-
- not_supported_on :opal do
- it "is true if self and other have the same character set code" do
- /abc/.send(@method, /abc/x).should == false
- /abc/x.send(@method, /abc/x).should == true
- /abc/u.send(@method, /abc/n).should == false
- /abc/u.send(@method, /abc/u).should == true
- /abc/n.send(@method, /abc/n).should == true
- end
- end
-
- it "is true if other has the same #casefold? values" do
- /abc/.send(@method, /abc/i).should == false
- /abc/i.send(@method, /abc/i).should == true
- end
-
- not_supported_on :opal do
- it "is true if self does not specify /n option and other does" do
- //.send(@method, //n).should == true
- end
-
- it "is true if self specifies /n option and other does not" do
- //n.send(@method, //).should == true
- end
- end
-end
diff --git a/spec/ruby/core/regexp/shared/new.rb b/spec/ruby/core/regexp/shared/new.rb
new file mode 100644
index 0000000000..affdaf855c
--- /dev/null
+++ b/spec/ruby/core/regexp/shared/new.rb
@@ -0,0 +1,321 @@
+# encoding: binary
+
+describe :regexp_new, shared: true do
+ it "requires one argument and creates a new regular expression object" do
+ Regexp.send(@method, '').is_a?(Regexp).should == true
+ end
+
+ ruby_version_is "4.1" do
+ it "is frozen" do
+ Regexp.send(@method, '').should.frozen?
+ end
+ end
+
+ it "works by default for subclasses with overridden #initialize" do
+ class RegexpSpecsSubclass < Regexp
+ def initialize(*args)
+ super
+ @args = args
+ end
+
+ attr_accessor :args
+ end
+
+ class RegexpSpecsSubclassTwo < Regexp; end
+
+ RegexpSpecsSubclass.send(@method, "hi").should.is_a?(RegexpSpecsSubclass)
+ RegexpSpecsSubclass.send(@method, "hi").args.first.should == "hi"
+
+ RegexpSpecsSubclassTwo.send(@method, "hi").should.is_a?(RegexpSpecsSubclassTwo)
+ end
+end
+
+describe :regexp_new_non_string_or_regexp, shared: true do
+ it "calls #to_str method for non-String/Regexp argument" do
+ obj = Object.new
+ def obj.to_str() "a" end
+
+ Regexp.send(@method, obj).should == /a/
+ end
+
+ it "raises TypeError if there is no #to_str method for non-String/Regexp argument" do
+ obj = Object.new
+ -> { Regexp.send(@method, obj) }.should.raise(TypeError, "no implicit conversion of Object into String")
+
+ -> { Regexp.send(@method, 1) }.should.raise(TypeError, "no implicit conversion of Integer into String")
+ -> { Regexp.send(@method, 1.0) }.should.raise(TypeError, "no implicit conversion of Float into String")
+ -> { Regexp.send(@method, :symbol) }.should.raise(TypeError, "no implicit conversion of Symbol into String")
+ -> { Regexp.send(@method, []) }.should.raise(TypeError, "no implicit conversion of Array into String")
+ end
+
+ it "raises TypeError if #to_str returns non-String value" do
+ obj = Object.new
+ def obj.to_str() [] end
+
+ -> { Regexp.send(@method, obj) }.should raise_consistent_error(TypeError, /can't convert Object into String/)
+ end
+end
+
+describe :regexp_new_string, shared: true do
+ it "uses the String argument as an unescaped literal to construct a Regexp object" do
+ Regexp.send(@method, "^hi{2,3}fo.o$").should == /^hi{2,3}fo.o$/
+ end
+
+ it "raises a RegexpError when passed an incorrect regexp" do
+ -> { Regexp.send(@method, "^[$", 0) }.should.raise(RegexpError, Regexp.new(Regexp.escape("premature end of char-class: /^[$/")))
+ end
+
+ it "does not set Regexp options if only given one argument" do
+ r = Regexp.send(@method, 'Hi')
+ (r.options & Regexp::IGNORECASE).should == 0
+ (r.options & Regexp::MULTILINE).should == 0
+ not_supported_on :opal do
+ (r.options & Regexp::EXTENDED).should == 0
+ end
+ end
+
+ it "does not set Regexp options if second argument is nil or false" do
+ r = Regexp.send(@method, 'Hi', nil)
+ (r.options & Regexp::IGNORECASE).should == 0
+ (r.options & Regexp::MULTILINE).should == 0
+ not_supported_on :opal do
+ (r.options & Regexp::EXTENDED).should == 0
+ end
+
+ r = Regexp.send(@method, 'Hi', false)
+ (r.options & Regexp::IGNORECASE).should == 0
+ (r.options & Regexp::MULTILINE).should == 0
+ not_supported_on :opal do
+ (r.options & Regexp::EXTENDED).should == 0
+ end
+ end
+
+ it "sets options from second argument if it is true" do
+ r = Regexp.send(@method, 'Hi', true)
+ (r.options & Regexp::IGNORECASE).should_not == 0
+ (r.options & Regexp::MULTILINE).should == 0
+ not_supported_on :opal do
+ (r.options & Regexp::EXTENDED).should == 0
+ end
+ end
+
+ it "sets options from second argument if it is one of the Integer option constants" do
+ r = Regexp.send(@method, 'Hi', Regexp::IGNORECASE)
+ (r.options & Regexp::IGNORECASE).should_not == 0
+ (r.options & Regexp::MULTILINE).should == 0
+ not_supported_on :opal do
+ (r.options & Regexp::EXTENDED).should == 0
+ end
+
+ r = Regexp.send(@method, 'Hi', Regexp::MULTILINE)
+ (r.options & Regexp::IGNORECASE).should == 0
+ (r.options & Regexp::MULTILINE).should_not == 0
+ not_supported_on :opal do
+ (r.options & Regexp::EXTENDED).should == 0
+ end
+
+ not_supported_on :opal do
+ r = Regexp.send(@method, 'Hi', Regexp::EXTENDED)
+ (r.options & Regexp::IGNORECASE).should == 0
+ (r.options & Regexp::MULTILINE).should == 0
+ (r.options & Regexp::EXTENDED).should_not == 1
+ end
+ end
+
+ it "accepts an Integer of two or more options ORed together as the second argument" do
+ r = Regexp.send(@method, 'Hi', Regexp::IGNORECASE | Regexp::EXTENDED)
+ (r.options & Regexp::IGNORECASE).should_not == 0
+ (r.options & Regexp::MULTILINE).should == 0
+ (r.options & Regexp::EXTENDED).should_not == 0
+ end
+
+ it "does not try to convert the second argument to Integer with #to_int method call" do
+ ScratchPad.clear
+ obj = Object.new
+ def obj.to_int() ScratchPad.record(:called) end
+
+ -> {
+ Regexp.send(@method, "Hi", obj)
+ }.should complain(/expected true or false as ignorecase/, {verbose: true})
+
+ ScratchPad.recorded.should == nil
+ end
+
+ it "warns any non-Integer, non-nil, non-false second argument" do
+ r = nil
+ -> {
+ r = Regexp.send(@method, 'Hi', Object.new)
+ }.should complain(/expected true or false as ignorecase/, {verbose: true})
+ (r.options & Regexp::IGNORECASE).should_not == 0
+ (r.options & Regexp::MULTILINE).should == 0
+ not_supported_on :opal do
+ (r.options & Regexp::EXTENDED).should == 0
+ end
+ end
+
+ it "accepts a String of supported flags as the second argument" do
+ r = Regexp.send(@method, 'Hi', 'i')
+ (r.options & Regexp::IGNORECASE).should_not == 0
+ (r.options & Regexp::MULTILINE).should == 0
+ not_supported_on :opal do
+ (r.options & Regexp::EXTENDED).should == 0
+ end
+
+ r = Regexp.send(@method, 'Hi', 'imx')
+ (r.options & Regexp::IGNORECASE).should_not == 0
+ (r.options & Regexp::MULTILINE).should_not == 0
+ not_supported_on :opal do
+ (r.options & Regexp::EXTENDED).should_not == 0
+ end
+
+ r = Regexp.send(@method, 'Hi', 'mimi')
+ (r.options & Regexp::IGNORECASE).should_not == 0
+ (r.options & Regexp::MULTILINE).should_not == 0
+ not_supported_on :opal do
+ (r.options & Regexp::EXTENDED).should == 0
+ end
+
+ r = Regexp.send(@method, 'Hi', '')
+ (r.options & Regexp::IGNORECASE).should == 0
+ (r.options & Regexp::MULTILINE).should == 0
+ not_supported_on :opal do
+ (r.options & Regexp::EXTENDED).should == 0
+ end
+ end
+
+ it "raises an Argument error if the second argument contains unsupported chars" do
+ -> { Regexp.send(@method, 'Hi', 'e') }.should.raise(ArgumentError, "unknown regexp option: e")
+ -> { Regexp.send(@method, 'Hi', 'n') }.should.raise(ArgumentError, "unknown regexp option: n")
+ -> { Regexp.send(@method, 'Hi', 's') }.should.raise(ArgumentError, "unknown regexp option: s")
+ -> { Regexp.send(@method, 'Hi', 'u') }.should.raise(ArgumentError, "unknown regexp option: u")
+ -> { Regexp.send(@method, 'Hi', 'j') }.should.raise(ArgumentError, "unknown regexp option: j")
+ -> { Regexp.send(@method, 'Hi', 'mjx') }.should.raise(ArgumentError, /unknown regexp option: mjx\b/)
+ end
+
+ describe "with escaped characters" do
+ it "raises a Regexp error if there is a trailing backslash" do
+ -> { Regexp.send(@method, "\\") }.should.raise(RegexpError, Regexp.new(Regexp.escape("too short escape sequence: /\\/")))
+ end
+
+ it "does not raise a Regexp error if there is an escaped trailing backslash" do
+ -> { Regexp.send(@method, "\\\\") }.should_not.raise(RegexpError)
+ end
+
+ it "accepts a backspace followed by a non-special character" do
+ Regexp.send(@method, "\\N").should == /#{"\x5c"+"N"}/
+ end
+
+ it "raises a RegexpError if \\x is not followed by any hexadecimal digits" do
+ -> { Regexp.send(@method, "\\" + "xn") }.should.raise(RegexpError, Regexp.new(Regexp.escape("invalid hex escape: /\\xn/")))
+ end
+
+ it "raises a RegexpError if less than four digits are given for \\uHHHH" do
+ -> { Regexp.send(@method, "\\" + "u304") }.should.raise(RegexpError, Regexp.new(Regexp.escape("invalid Unicode escape: /\\u304/")))
+ end
+
+ it "raises a RegexpError if the \\u{} escape is empty" do
+ -> { Regexp.send(@method, "\\" + "u{}") }.should.raise(RegexpError, Regexp.new(Regexp.escape("invalid Unicode list: /\\u{}/")))
+ end
+
+ it "raises a RegexpError if the \\u{} escape contains non hexadecimal digits" do
+ -> { Regexp.send(@method, "\\" + "u{abcX}") }.should.raise(RegexpError, Regexp.new(Regexp.escape("invalid Unicode list: /\\u{abcX}/")))
+ end
+
+ it "raises a RegexpError if more than six hexadecimal digits are given" do
+ -> { Regexp.send(@method, "\\" + "u{0ffffff}") }.should.raise(RegexpError, Regexp.new(Regexp.escape("invalid Unicode range: /\\u{0ffffff}/")))
+ end
+
+ it "returns a Regexp with US-ASCII encoding if only 7-bit ASCII characters are present regardless of the input String's encoding" do
+ Regexp.send(@method, "abc").encoding.should == Encoding::US_ASCII
+ end
+
+ it "returns a Regexp with source String having US-ASCII encoding if only 7-bit ASCII characters are present regardless of the input String's encoding" do
+ Regexp.send(@method, "abc").source.encoding.should == Encoding::US_ASCII
+ end
+
+ it "returns a Regexp with US-ASCII encoding if UTF-8 escape sequences using only 7-bit ASCII are present" do
+ Regexp.send(@method, "\u{61}").encoding.should == Encoding::US_ASCII
+ end
+
+ it "returns a Regexp with source String having US-ASCII encoding if UTF-8 escape sequences using only 7-bit ASCII are present" do
+ Regexp.send(@method, "\u{61}").source.encoding.should == Encoding::US_ASCII
+ end
+
+ it "returns a Regexp with UTF-8 encoding if any UTF-8 escape sequences outside 7-bit ASCII are present" do
+ Regexp.send(@method, "\u{ff}").encoding.should == Encoding::UTF_8
+ end
+
+ it "returns a Regexp with source String having UTF-8 encoding if any UTF-8 escape sequences outside 7-bit ASCII are present" do
+ Regexp.send(@method, "\u{ff}").source.encoding.should == Encoding::UTF_8
+ end
+
+ it "returns a Regexp with the input String's encoding" do
+ str = "\x82\xa0".dup.force_encoding(Encoding::Shift_JIS)
+ Regexp.send(@method, str).encoding.should == Encoding::Shift_JIS
+ end
+
+ it "returns a Regexp with source String having the input String's encoding" do
+ str = "\x82\xa0".dup.force_encoding(Encoding::Shift_JIS)
+ Regexp.send(@method, str).source.encoding.should == Encoding::Shift_JIS
+ end
+ end
+end
+
+describe :regexp_new_string_binary, shared: true do
+ describe "with escaped characters" do
+ end
+end
+
+describe :regexp_new_regexp, shared: true do
+ it "uses the argument as a literal to construct a Regexp object" do
+ Regexp.send(@method, /^hi{2,3}fo.o$/).should == /^hi{2,3}fo.o$/
+ end
+
+ it "preserves any options given in the Regexp literal" do
+ (Regexp.send(@method, /Hi/i).options & Regexp::IGNORECASE).should_not == 0
+ (Regexp.send(@method, /Hi/m).options & Regexp::MULTILINE).should_not == 0
+ not_supported_on :opal do
+ (Regexp.send(@method, /Hi/x).options & Regexp::EXTENDED).should_not == 0
+ end
+
+ not_supported_on :opal do
+ r = Regexp.send @method, /Hi/imx
+ (r.options & Regexp::IGNORECASE).should_not == 0
+ (r.options & Regexp::MULTILINE).should_not == 0
+ (r.options & Regexp::EXTENDED).should_not == 0
+ end
+
+ r = Regexp.send @method, /Hi/
+ (r.options & Regexp::IGNORECASE).should == 0
+ (r.options & Regexp::MULTILINE).should == 0
+ not_supported_on :opal do
+ (r.options & Regexp::EXTENDED).should == 0
+ end
+ end
+
+ it "does not honour options given as additional arguments" do
+ r = nil
+ -> {
+ r = Regexp.send @method, /hi/, Regexp::IGNORECASE
+ }.should complain(/flags ignored/)
+ (r.options & Regexp::IGNORECASE).should == 0
+ end
+
+ not_supported_on :opal do
+ it "sets the encoding to UTF-8 if the Regexp literal has the 'u' option" do
+ Regexp.send(@method, /Hi/u).encoding.should == Encoding::UTF_8
+ end
+
+ it "sets the encoding to EUC-JP if the Regexp literal has the 'e' option" do
+ Regexp.send(@method, /Hi/e).encoding.should == Encoding::EUC_JP
+ end
+
+ it "sets the encoding to Windows-31J if the Regexp literal has the 's' option" do
+ Regexp.send(@method, /Hi/s).encoding.should == Encoding::Windows_31J
+ end
+
+ it "sets the encoding to US-ASCII if the Regexp literal has the 'n' option and the source String is ASCII only" do
+ Regexp.send(@method, /Hi/n).encoding.should == Encoding::US_ASCII
+ end
+ end
+end
diff --git a/spec/ruby/core/regexp/shared/new_ascii.rb b/spec/ruby/core/regexp/shared/new_ascii.rb
deleted file mode 100644
index 98c458312e..0000000000
--- a/spec/ruby/core/regexp/shared/new_ascii.rb
+++ /dev/null
@@ -1,464 +0,0 @@
-# -*- encoding: binary -*-
-describe :regexp_new_ascii, shared: true do
- it "requires one argument and creates a new regular expression object" do
- Regexp.send(@method, '').is_a?(Regexp).should == true
- end
-
- it "works by default for subclasses with overridden #initialize" do
- class RegexpSpecsSubclass < Regexp
- def initialize(*args)
- super
- @args = args
- end
-
- attr_accessor :args
- end
-
- class RegexpSpecsSubclassTwo < Regexp; end
-
- RegexpSpecsSubclass.send(@method, "hi").should be_kind_of(RegexpSpecsSubclass)
- RegexpSpecsSubclass.send(@method, "hi").args.first.should == "hi"
-
- RegexpSpecsSubclassTwo.send(@method, "hi").should be_kind_of(RegexpSpecsSubclassTwo)
- end
-end
-
-describe :regexp_new_string_ascii, shared: true do
- it "uses the String argument as an unescaped literal to construct a Regexp object" do
- Regexp.send(@method, "^hi{2,3}fo.o$").should == /^hi{2,3}fo.o$/
- end
-
- it "raises a RegexpError when passed an incorrect regexp" do
- lambda { Regexp.send(@method, "^[$", 0) }.should raise_error(RegexpError)
- end
-
- it "does not set Regexp options if only given one argument" do
- r = Regexp.send(@method, 'Hi')
- (r.options & Regexp::IGNORECASE).should == 0
- (r.options & Regexp::MULTILINE).should == 0
- not_supported_on :opal do
- (r.options & Regexp::EXTENDED).should == 0
- end
- end
-
- it "does not set Regexp options if second argument is nil or false" do
- r = Regexp.send(@method, 'Hi', nil)
- (r.options & Regexp::IGNORECASE).should == 0
- (r.options & Regexp::MULTILINE).should == 0
- not_supported_on :opal do
- (r.options & Regexp::EXTENDED).should == 0
- end
-
- r = Regexp.send(@method, 'Hi', false)
- (r.options & Regexp::IGNORECASE).should == 0
- (r.options & Regexp::MULTILINE).should == 0
- not_supported_on :opal do
- (r.options & Regexp::EXTENDED).should == 0
- end
- end
-
- it "sets options from second argument if it is one of the Fixnum option constants" do
- r = Regexp.send(@method, 'Hi', Regexp::IGNORECASE)
- (r.options & Regexp::IGNORECASE).should_not == 0
- (r.options & Regexp::MULTILINE).should == 0
- not_supported_on :opal do
- (r.options & Regexp::EXTENDED).should == 0
- end
-
- r = Regexp.send(@method, 'Hi', Regexp::MULTILINE)
- (r.options & Regexp::IGNORECASE).should == 0
- (r.options & Regexp::MULTILINE).should_not == 0
- not_supported_on :opal do
- (r.options & Regexp::EXTENDED).should == 0
- end
-
- not_supported_on :opal do
- r = Regexp.send(@method, 'Hi', Regexp::EXTENDED)
- (r.options & Regexp::IGNORECASE).should == 0
- (r.options & Regexp::MULTILINE).should == 0
- (r.options & Regexp::EXTENDED).should_not == 1
- end
- end
-
- it "accepts a Fixnum of two or more options ORed together as the second argument" do
- r = Regexp.send(@method, 'Hi', Regexp::IGNORECASE | Regexp::EXTENDED)
- (r.options & Regexp::IGNORECASE).should_not == 0
- (r.options & Regexp::MULTILINE).should == 0
- (r.options & Regexp::EXTENDED).should_not == 0
- end
-
- it "treats any non-Fixnum, non-nil, non-false second argument as IGNORECASE" do
- r = Regexp.send(@method, 'Hi', Object.new)
- (r.options & Regexp::IGNORECASE).should_not == 0
- (r.options & Regexp::MULTILINE).should == 0
- not_supported_on :opal do
- (r.options & Regexp::EXTENDED).should == 0
- end
- end
-
- it "ignores the third argument if it is 'e' or 'euc' (case-insensitive)" do
- lambda {
- Regexp.send(@method, 'Hi', nil, 'e').encoding.should == Encoding::US_ASCII
- Regexp.send(@method, 'Hi', nil, 'euc').encoding.should == Encoding::US_ASCII
- Regexp.send(@method, 'Hi', nil, 'E').encoding.should == Encoding::US_ASCII
- Regexp.send(@method, 'Hi', nil, 'EUC').encoding.should == Encoding::US_ASCII
- }.should complain(/encoding option is ignored/)
- end
-
- it "ignores the third argument if it is 's' or 'sjis' (case-insensitive)" do
- lambda {
- Regexp.send(@method, 'Hi', nil, 's').encoding.should == Encoding::US_ASCII
- Regexp.send(@method, 'Hi', nil, 'sjis').encoding.should == Encoding::US_ASCII
- Regexp.send(@method, 'Hi', nil, 'S').encoding.should == Encoding::US_ASCII
- Regexp.send(@method, 'Hi', nil, 'SJIS').encoding.should == Encoding::US_ASCII
- }.should complain(/encoding option is ignored/)
- end
-
- it "ignores the third argument if it is 'u' or 'utf8' (case-insensitive)" do
- lambda {
- Regexp.send(@method, 'Hi', nil, 'u').encoding.should == Encoding::US_ASCII
- Regexp.send(@method, 'Hi', nil, 'utf8').encoding.should == Encoding::US_ASCII
- Regexp.send(@method, 'Hi', nil, 'U').encoding.should == Encoding::US_ASCII
- Regexp.send(@method, 'Hi', nil, 'UTF8').encoding.should == Encoding::US_ASCII
- }.should complain(/encoding option is ignored/)
- end
-
- it "uses US_ASCII encoding if third argument is 'n' or 'none' (case insensitive) and only ascii characters" do
- Regexp.send(@method, 'Hi', nil, 'n').encoding.should == Encoding::US_ASCII
- Regexp.send(@method, 'Hi', nil, 'none').encoding.should == Encoding::US_ASCII
- Regexp.send(@method, 'Hi', nil, 'N').encoding.should == Encoding::US_ASCII
- Regexp.send(@method, 'Hi', nil, 'NONE').encoding.should == Encoding::US_ASCII
- end
-
- it "uses ASCII_8BIT encoding if third argument is 'n' or 'none' (case insensitive) and non-ascii characters" do
- a = "(?:[\x8E\xA1-\xFE])"
- str = "\A(?:#{a}|x*)\z"
-
- Regexp.send(@method, str, nil, 'N').encoding.should == Encoding::ASCII_8BIT
- Regexp.send(@method, str, nil, 'n').encoding.should == Encoding::ASCII_8BIT
- Regexp.send(@method, str, nil, 'none').encoding.should == Encoding::ASCII_8BIT
- Regexp.send(@method, str, nil, 'NONE').encoding.should == Encoding::ASCII_8BIT
- end
-
- describe "with escaped characters" do
- it "raises a Regexp error if there is a trailing backslash" do
- lambda { Regexp.send(@method, "\\") }.should raise_error(RegexpError)
- end
-
- it "does not raise a Regexp error if there is an escaped trailing backslash" do
- lambda { Regexp.send(@method, "\\\\") }.should_not raise_error(RegexpError)
- end
-
- it "accepts a backspace followed by a character" do
- Regexp.send(@method, "\\N").should == /#{"\x5c"+"N"}/
- end
-
- it "accepts a one-digit octal value" do
- Regexp.send(@method, "\0").should == /#{"\x00"}/
- end
-
- it "accepts a two-digit octal value" do
- Regexp.send(@method, "\11").should == /#{"\x09"}/
- end
-
- it "accepts a one-digit hexadecimal value" do
- Regexp.send(@method, "\x9n").should == /#{"\x09n"}/
- end
-
- it "accepts a two-digit hexadecimal value" do
- Regexp.send(@method, "\x23").should == /#{"\x23"}/
- end
-
- it "interprets a digit following a two-digit hexadecimal value as a character" do
- Regexp.send(@method, "\x420").should == /#{"\x420"}/
- end
-
- it "raises a RegexpError if \\x is not followed by any hexadecimal digits" do
- lambda { Regexp.send(@method, "\\" + "xn") }.should raise_error(RegexpError)
- end
-
- it "accepts an escaped string interpolation" do
- Regexp.send(@method, "\#{abc}").should == /#{"\#{abc}"}/
- end
-
- it "accepts '\\n'" do
- Regexp.send(@method, "\n").should == /#{"\x0a"}/
- end
-
- it "accepts '\\t'" do
- Regexp.send(@method, "\t").should == /#{"\x09"}/
- end
-
- it "accepts '\\r'" do
- Regexp.send(@method, "\r").should == /#{"\x0d"}/
- end
-
- it "accepts '\\f'" do
- Regexp.send(@method, "\f").should == /#{"\x0c"}/
- end
-
- it "accepts '\\v'" do
- Regexp.send(@method, "\v").should == /#{"\x0b"}/
- end
-
- it "accepts '\\a'" do
- Regexp.send(@method, "\a").should == /#{"\x07"}/
- end
-
- it "accepts '\\e'" do
- Regexp.send(@method, "\e").should == /#{"\x1b"}/
- end
-
- it "accepts '\\C-\\n'" do
- Regexp.send(@method, "\C-\n").should == /#{"\x0a"}/
- end
-
- it "accepts '\\C-\\t'" do
- Regexp.send(@method, "\C-\t").should == /#{"\x09"}/
- end
-
- it "accepts '\\C-\\r'" do
- Regexp.send(@method, "\C-\r").should == /#{"\x0d"}/
- end
-
- it "accepts '\\C-\\f'" do
- Regexp.send(@method, "\C-\f").should == /#{"\x0c"}/
- end
-
- it "accepts '\\C-\\v'" do
- Regexp.send(@method, "\C-\v").should == /#{"\x0b"}/
- end
-
- it "accepts '\\C-\\a'" do
- Regexp.send(@method, "\C-\a").should == /#{"\x07"}/
- end
-
- it "accepts '\\C-\\e'" do
- Regexp.send(@method, "\C-\e").should == /#{"\x1b"}/
- end
-
- it "accepts '\\c\\n'" do
- Regexp.send(@method, "\C-\n").should == /#{"\x0a"}/
- end
-
- it "accepts '\\c\\t'" do
- Regexp.send(@method, "\C-\t").should == /#{"\x09"}/
- end
-
- it "accepts '\\c\\r'" do
- Regexp.send(@method, "\C-\r").should == /#{"\x0d"}/
- end
-
- it "accepts '\\c\\f'" do
- Regexp.send(@method, "\C-\f").should == /#{"\x0c"}/
- end
-
- it "accepts '\\c\\v'" do
- Regexp.send(@method, "\C-\v").should == /#{"\x0b"}/
- end
-
- it "accepts '\\c\\a'" do
- Regexp.send(@method, "\C-\a").should == /#{"\x07"}/
- end
-
- it "accepts '\\c\\e'" do
- Regexp.send(@method, "\C-\e").should == /#{"\x1b"}/
- end
-
- it "accepts multiple consecutive '\\' characters" do
- Regexp.send(@method, "\\\\\\N").should == /#{"\\\\\\"+"N"}/
- end
-
- it "accepts characters and escaped octal digits" do
- Regexp.send(@method, "abc\076").should == /#{"abc\x3e"}/
- end
-
- it "accepts escaped octal digits and characters" do
- Regexp.send(@method, "\076abc").should == /#{"\x3eabc"}/
- end
-
- it "accepts characters and escaped hexadecimal digits" do
- Regexp.send(@method, "abc\x42").should == /#{"abc\x42"}/
- end
-
- it "accepts escaped hexadecimal digits and characters" do
- Regexp.send(@method, "\x3eabc").should == /#{"\x3eabc"}/
- end
-
- it "accepts escaped hexadecimal and octal digits" do
- Regexp.send(@method, "\061\x42").should == /#{"\x31\x42"}/
- end
-
- it "accepts \\u{H} for a single Unicode codepoint" do
- Regexp.send(@method, "\u{f}").should == /#{"\x0f"}/
- end
-
- it "accepts \\u{HH} for a single Unicode codepoint" do
- Regexp.send(@method, "\u{7f}").should == /#{"\x7f"}/
- end
-
- it "accepts \\u{HHH} for a single Unicode codepoint" do
- Regexp.send(@method, "\u{07f}").should == /#{"\x7f"}/
- end
-
- it "accepts \\u{HHHH} for a single Unicode codepoint" do
- Regexp.send(@method, "\u{0000}").should == /#{"\x00"}/
- end
-
- it "accepts \\u{HHHHH} for a single Unicode codepoint" do
- Regexp.send(@method, "\u{00001}").should == /#{"\x01"}/
- end
-
- it "accepts \\u{HHHHHH} for a single Unicode codepoint" do
- Regexp.send(@method, "\u{000000}").should == /#{"\x00"}/
- end
-
- it "accepts characters followed by \\u{HHHH}" do
- Regexp.send(@method, "abc\u{3042}").should == /#{"abc\u3042"}/
- end
-
- it "accepts \\u{HHHH} followed by characters" do
- Regexp.send(@method, "\u{3042}abc").should == /#{"\u3042abc"}/
- end
-
- it "accepts escaped hexadecimal digits followed by \\u{HHHH}" do
- Regexp.send(@method, "\x42\u{3042}").should == /#{"\x42\u3042"}/
- end
-
- it "accepts escaped octal digits followed by \\u{HHHH}" do
- Regexp.send(@method, "\056\u{3042}").should == /#{"\x2e\u3042"}/
- end
-
- it "accepts a combination of escaped octal and hexadecimal digits and \\u{HHHH}" do
- Regexp.send(@method, "\056\x42\u{3042}\x52\076").should == /#{"\x2e\x42\u3042\x52\x3e"}/
- end
-
- it "accepts \\uHHHH for a single Unicode codepoint" do
- Regexp.send(@method, "\u3042").should == /#{"\u3042"}/
- end
-
- it "accepts characters followed by \\uHHHH" do
- Regexp.send(@method, "abc\u3042").should == /#{"abc\u3042"}/
- end
-
- it "accepts \\uHHHH followed by characters" do
- Regexp.send(@method, "\u3042abc").should == /#{"\u3042abc"}/
- end
-
- it "accepts escaped hexadecimal digits followed by \\uHHHH" do
- Regexp.send(@method, "\x42\u3042").should == /#{"\x42\u3042"}/
- end
-
- it "accepts escaped octal digits followed by \\uHHHH" do
- Regexp.send(@method, "\056\u3042").should == /#{"\x2e\u3042"}/
- end
-
- it "accepts a combination of escaped octal and hexadecimal digits and \\uHHHH" do
- Regexp.send(@method, "\056\x42\u3042\x52\076").should == /#{"\x2e\x42\u3042\x52\x3e"}/
- end
-
- it "raises a RegexpError if less than four digits are given for \\uHHHH" do
- lambda { Regexp.send(@method, "\\" + "u304") }.should raise_error(RegexpError)
- end
-
- it "raises a RegexpError if the \\u{} escape is empty" do
- lambda { Regexp.send(@method, "\\" + "u{}") }.should raise_error(RegexpError)
- end
-
- it "raises a RegexpError if more than six hexadecimal digits are given" do
- lambda { Regexp.send(@method, "\\" + "u{0ffffff}") }.should raise_error(RegexpError)
- end
-
- it "returns a Regexp with US-ASCII encoding if only 7-bit ASCII characters are present regardless of the input String's encoding" do
- Regexp.send(@method, "abc").encoding.should == Encoding::US_ASCII
- end
-
- it "returns a Regexp with source String having US-ASCII encoding if only 7-bit ASCII characters are present regardless of the input String's encoding" do
- Regexp.send(@method, "abc").source.encoding.should == Encoding::US_ASCII
- end
-
- it "returns a Regexp with US-ASCII encoding if UTF-8 escape sequences using only 7-bit ASCII are present" do
- Regexp.send(@method, "\u{61}").encoding.should == Encoding::US_ASCII
- end
-
- it "returns a Regexp with source String having US-ASCII encoding if UTF-8 escape sequences using only 7-bit ASCII are present" do
- Regexp.send(@method, "\u{61}").source.encoding.should == Encoding::US_ASCII
- end
-
- it "returns a Regexp with UTF-8 encoding if any UTF-8 escape sequences outside 7-bit ASCII are present" do
- Regexp.send(@method, "\u{ff}").encoding.should == Encoding::UTF_8
- end
-
- it "returns a Regexp with source String having UTF-8 encoding if any UTF-8 escape sequences outside 7-bit ASCII are present" do
- Regexp.send(@method, "\u{ff}").source.encoding.should == Encoding::UTF_8
- end
-
- it "returns a Regexp with the input String's encoding" do
- str = "\x82\xa0".force_encoding(Encoding::Shift_JIS)
- Regexp.send(@method, str).encoding.should == Encoding::Shift_JIS
- end
-
- it "returns a Regexp with source String having the input String's encoding" do
- str = "\x82\xa0".force_encoding(Encoding::Shift_JIS)
- Regexp.send(@method, str).source.encoding.should == Encoding::Shift_JIS
- end
- end
-end
-
-describe :regexp_new_regexp_ascii, shared: true do
- it "uses the argument as a literal to construct a Regexp object" do
- Regexp.send(@method, /^hi{2,3}fo.o$/).should == /^hi{2,3}fo.o$/
- end
-
- it "preserves any options given in the Regexp literal" do
- (Regexp.send(@method, /Hi/i).options & Regexp::IGNORECASE).should_not == 0
- (Regexp.send(@method, /Hi/m).options & Regexp::MULTILINE).should_not == 0
- not_supported_on :opal do
- (Regexp.send(@method, /Hi/x).options & Regexp::EXTENDED).should_not == 0
- end
-
- not_supported_on :opal do
- r = Regexp.send @method, /Hi/imx
- (r.options & Regexp::IGNORECASE).should_not == 0
- (r.options & Regexp::MULTILINE).should_not == 0
- (r.options & Regexp::EXTENDED).should_not == 0
- end
-
- r = Regexp.send @method, /Hi/
- (r.options & Regexp::IGNORECASE).should == 0
- (r.options & Regexp::MULTILINE).should == 0
- not_supported_on :opal do
- (r.options & Regexp::EXTENDED).should == 0
- end
- end
-
- it "does not honour options given as additional arguments" do
- r = nil
- lambda {
- r = Regexp.send @method, /hi/, Regexp::IGNORECASE
- }.should complain(/flags ignored/)
- (r.options & Regexp::IGNORECASE).should == 0
- end
-
- not_supported_on :opal do
- it "sets the encoding to UTF-8 if the Regexp literal has the 'u' option" do
- Regexp.send(@method, /Hi/u).encoding.should == Encoding::UTF_8
- end
-
- it "sets the encoding to EUC-JP if the Regexp literal has the 'e' option" do
- Regexp.send(@method, /Hi/e).encoding.should == Encoding::EUC_JP
- end
-
- it "sets the encoding to Windows-31J if the Regexp literal has the 's' option" do
- Regexp.send(@method, /Hi/s).encoding.should == Encoding::Windows_31J
- end
-
- it "sets the encoding to US-ASCII if the Regexp literal has the 'n' option and the source String is ASCII only" do
- Regexp.send(@method, /Hi/n).encoding.should == Encoding::US_ASCII
- end
-
- it "sets the encoding to source String's encoding if the Regexp literal has the 'n' option and the source String is not ASCII only" do
- Regexp.send(@method, Regexp.new("\\xff", nil, 'n')).encoding.should == Encoding::ASCII_8BIT
- end
- end
-end
diff --git a/spec/ruby/core/regexp/shared/new_ascii_8bit.rb b/spec/ruby/core/regexp/shared/new_ascii_8bit.rb
deleted file mode 100644
index 5110a08380..0000000000
--- a/spec/ruby/core/regexp/shared/new_ascii_8bit.rb
+++ /dev/null
@@ -1,553 +0,0 @@
-# -*- encoding: ascii-8bit -*-
-
-describe :regexp_new_ascii_8bit, shared: true do
- it "requires one argument and creates a new regular expression object" do
- Regexp.send(@method, '').is_a?(Regexp).should == true
- end
-
- it "works by default for subclasses with overridden #initialize" do
- class RegexpSpecsSubclass < Regexp
- def initialize(*args)
- super
- @args = args
- end
-
- attr_accessor :args
- end
-
- class RegexpSpecsSubclassTwo < Regexp; end
-
- RegexpSpecsSubclass.send(@method, "hi").should be_kind_of(RegexpSpecsSubclass)
- RegexpSpecsSubclass.send(@method, "hi").args.first.should == "hi"
-
- RegexpSpecsSubclassTwo.send(@method, "hi").should be_kind_of(RegexpSpecsSubclassTwo)
- end
-end
-
-describe :regexp_new_string_ascii_8bit, shared: true do
- it "uses the String argument as an unescaped literal to construct a Regexp object" do
- Regexp.send(@method, "^hi{2,3}fo.o$").should == /^hi{2,3}fo.o$/
- end
-
- it "raises a RegexpError when passed an incorrect regexp" do
- lambda { Regexp.send(@method, "^[$", 0) }.should raise_error(RegexpError)
- end
-
- it "does not set Regexp options if only given one argument" do
- r = Regexp.send(@method, 'Hi')
- (r.options & Regexp::IGNORECASE).should == 0
- (r.options & Regexp::MULTILINE).should == 0
- not_supported_on :opal do
- (r.options & Regexp::EXTENDED).should == 0
- end
- end
-
- it "does not set Regexp options if second argument is nil or false" do
- r = Regexp.send(@method, 'Hi', nil)
- (r.options & Regexp::IGNORECASE).should == 0
- (r.options & Regexp::MULTILINE).should == 0
- not_supported_on :opal do
- (r.options & Regexp::EXTENDED).should == 0
- end
-
- r = Regexp.send(@method, 'Hi', false)
- (r.options & Regexp::IGNORECASE).should == 0
- (r.options & Regexp::MULTILINE).should == 0
- not_supported_on :opal do
- (r.options & Regexp::EXTENDED).should == 0
- end
- end
-
- it "sets options from second argument if it is one of the Fixnum option constants" do
- r = Regexp.send(@method, 'Hi', Regexp::IGNORECASE)
- (r.options & Regexp::IGNORECASE).should_not == 0
- (r.options & Regexp::MULTILINE).should == 0
- not_supported_on :opal do
- (r.options & Regexp::EXTENDED).should == 0
- end
-
- r = Regexp.send(@method, 'Hi', Regexp::MULTILINE)
- (r.options & Regexp::IGNORECASE).should == 0
- (r.options & Regexp::MULTILINE).should_not == 0
- not_supported_on :opal do
- (r.options & Regexp::EXTENDED).should == 0
- end
-
- not_supported_on :opal do
- r = Regexp.send(@method, 'Hi', Regexp::EXTENDED)
- (r.options & Regexp::IGNORECASE).should == 0
- (r.options & Regexp::MULTILINE).should == 0
- (r.options & Regexp::EXTENDED).should_not == 1
- end
- end
-
- it "accepts a Fixnum of two or more options ORed together as the second argument" do
- r = Regexp.send(@method, 'Hi', Regexp::IGNORECASE | Regexp::EXTENDED)
- (r.options & Regexp::IGNORECASE).should_not == 0
- (r.options & Regexp::MULTILINE).should == 0
- (r.options & Regexp::EXTENDED).should_not == 0
- end
-
- it "treats any non-Fixnum, non-nil, non-false second argument as IGNORECASE" do
- r = Regexp.send(@method, 'Hi', Object.new)
- (r.options & Regexp::IGNORECASE).should_not == 0
- (r.options & Regexp::MULTILINE).should == 0
- not_supported_on :opal do
- (r.options & Regexp::EXTENDED).should == 0
- end
- end
-
- it "ignores the third argument if it is 'e' or 'euc' (case-insensitive)" do
- lambda {
- Regexp.send(@method, 'Hi', nil, 'e').encoding.should == Encoding::US_ASCII
- Regexp.send(@method, 'Hi', nil, 'euc').encoding.should == Encoding::US_ASCII
- Regexp.send(@method, 'Hi', nil, 'E').encoding.should == Encoding::US_ASCII
- Regexp.send(@method, 'Hi', nil, 'EUC').encoding.should == Encoding::US_ASCII
- }.should complain(/encoding option is ignored/)
- end
-
- it "ignores the third argument if it is 's' or 'sjis' (case-insensitive)" do
- lambda {
- Regexp.send(@method, 'Hi', nil, 's').encoding.should == Encoding::US_ASCII
- Regexp.send(@method, 'Hi', nil, 'sjis').encoding.should == Encoding::US_ASCII
- Regexp.send(@method, 'Hi', nil, 'S').encoding.should == Encoding::US_ASCII
- Regexp.send(@method, 'Hi', nil, 'SJIS').encoding.should == Encoding::US_ASCII
- }.should complain(/encoding option is ignored/)
- end
-
- it "ignores the third argument if it is 'u' or 'utf8' (case-insensitive)" do
- lambda {
- Regexp.send(@method, 'Hi', nil, 'u').encoding.should == Encoding::US_ASCII
- Regexp.send(@method, 'Hi', nil, 'utf8').encoding.should == Encoding::US_ASCII
- Regexp.send(@method, 'Hi', nil, 'U').encoding.should == Encoding::US_ASCII
- Regexp.send(@method, 'Hi', nil, 'UTF8').encoding.should == Encoding::US_ASCII
- }.should complain(/encoding option is ignored/)
- end
-
- it "uses US_ASCII encoding if third argument is 'n' or 'none' (case insensitive) and only ascii characters" do
- Regexp.send(@method, 'Hi', nil, 'n').encoding.should == Encoding::US_ASCII
- Regexp.send(@method, 'Hi', nil, 'none').encoding.should == Encoding::US_ASCII
- Regexp.send(@method, 'Hi', nil, 'N').encoding.should == Encoding::US_ASCII
- Regexp.send(@method, 'Hi', nil, 'NONE').encoding.should == Encoding::US_ASCII
- end
-
- it "uses ASCII_8BIT encoding if third argument is 'n' or 'none' (case insensitive) and non-ascii characters" do
- a = "(?:[\x8E\xA1-\xFE])"
- str = "\A(?:#{a}|x*)\z"
-
- Regexp.send(@method, str, nil, 'N').encoding.should == Encoding::ASCII_8BIT
- Regexp.send(@method, str, nil, 'n').encoding.should == Encoding::ASCII_8BIT
- Regexp.send(@method, str, nil, 'none').encoding.should == Encoding::ASCII_8BIT
- Regexp.send(@method, str, nil, 'NONE').encoding.should == Encoding::ASCII_8BIT
- end
-
- describe "with escaped characters" do
- it "raises a Regexp error if there is a trailing backslash" do
- lambda { Regexp.send(@method, "\\") }.should raise_error(RegexpError)
- end
-
- it "accepts a backspace followed by a character" do
- Regexp.send(@method, "\\N").should == /#{"\x5c"+"N"}/
- end
-
- it "accepts a one-digit octal value" do
- Regexp.send(@method, "\0").should == /#{"\x00"}/
- end
-
- it "accepts a two-digit octal value" do
- Regexp.send(@method, "\11").should == /#{"\x09"}/
- end
-
- it "accepts a three-digit octal value" do
- Regexp.send(@method, "\315").should == /#{"\xcd"}/
- end
-
- it "interprets a digit following a three-digit octal value as a character" do
- Regexp.send(@method, "\3762").should == /#{"\xfe2"}/
- end
-
- it "accepts a one-digit hexadecimal value" do
- Regexp.send(@method, "\x9n").should == /#{"\x09n"}/
- end
-
- it "accepts a two-digit hexadecimal value" do
- Regexp.send(@method, "\x23").should == /#{"\x23"}/
- end
-
- it "interprets a digit following a two-digit hexadecimal value as a character" do
- Regexp.send(@method, "\x420").should == /#{"\x420"}/
- end
-
- it "raises a RegexpError if \\x is not followed by any hexadecimal digits" do
- lambda { Regexp.send(@method, "\\" + "xn") }.should raise_error(RegexpError)
- end
-
- it "accepts an escaped string interpolation" do
- Regexp.send(@method, "\#{abc}").should == /#{"\#{abc}"}/
- end
-
- it "accepts '\\n'" do
- Regexp.send(@method, "\n").should == /#{"\x0a"}/
- end
-
- it "accepts '\\t'" do
- Regexp.send(@method, "\t").should == /#{"\x09"}/
- end
-
- it "accepts '\\r'" do
- Regexp.send(@method, "\r").should == /#{"\x0d"}/
- end
-
- it "accepts '\\f'" do
- Regexp.send(@method, "\f").should == /#{"\x0c"}/
- end
-
- it "accepts '\\v'" do
- Regexp.send(@method, "\v").should == /#{"\x0b"}/
- end
-
- it "accepts '\\a'" do
- Regexp.send(@method, "\a").should == /#{"\x07"}/
- end
-
- it "accepts '\\e'" do
- Regexp.send(@method, "\e").should == /#{"\x1b"}/
- end
-
- it "accepts '\\C-\\n'" do
- Regexp.send(@method, "\C-\n").should == /#{"\x0a"}/
- end
-
- it "accepts '\\C-\\t'" do
- Regexp.send(@method, "\C-\t").should == /#{"\x09"}/
- end
-
- it "accepts '\\C-\\r'" do
- Regexp.send(@method, "\C-\r").should == /#{"\x0d"}/
- end
-
- it "accepts '\\C-\\f'" do
- Regexp.send(@method, "\C-\f").should == /#{"\x0c"}/
- end
-
- it "accepts '\\C-\\v'" do
- Regexp.send(@method, "\C-\v").should == /#{"\x0b"}/
- end
-
- it "accepts '\\C-\\a'" do
- Regexp.send(@method, "\C-\a").should == /#{"\x07"}/
- end
-
- it "accepts '\\C-\\e'" do
- Regexp.send(@method, "\C-\e").should == /#{"\x1b"}/
- end
-
- it "accepts '\\c\\n'" do
- Regexp.send(@method, "\C-\n").should == /#{"\x0a"}/
- end
-
- it "accepts '\\c\\t'" do
- Regexp.send(@method, "\C-\t").should == /#{"\x09"}/
- end
-
- it "accepts '\\c\\r'" do
- Regexp.send(@method, "\C-\r").should == /#{"\x0d"}/
- end
-
- it "accepts '\\c\\f'" do
- Regexp.send(@method, "\C-\f").should == /#{"\x0c"}/
- end
-
- it "accepts '\\c\\v'" do
- Regexp.send(@method, "\C-\v").should == /#{"\x0b"}/
- end
-
- it "accepts '\\c\\a'" do
- Regexp.send(@method, "\C-\a").should == /#{"\x07"}/
- end
-
- it "accepts '\\c\\e'" do
- Regexp.send(@method, "\C-\e").should == /#{"\x1b"}/
- end
-
- it "accepts '\\M-\\n'" do
- Regexp.send(@method, "\M-\n").should == /#{"\x8a"}/
- end
-
- it "accepts '\\M-\\t'" do
- Regexp.send(@method, "\M-\t").should == /#{"\x89"}/
- end
-
- it "accepts '\\M-\\r'" do
- Regexp.send(@method, "\M-\r").should == /#{"\x8d"}/
- end
-
- it "accepts '\\M-\\f'" do
- Regexp.send(@method, "\M-\f").should == /#{"\x8c"}/
- end
-
- it "accepts '\\M-\\v'" do
- Regexp.send(@method, "\M-\v").should == /#{"\x8b"}/
- end
-
- it "accepts '\\M-\\a'" do
- Regexp.send(@method, "\M-\a").should == /#{"\x87"}/
- end
-
- it "accepts '\\M-\\e'" do
- Regexp.send(@method, "\M-\e").should == /#{"\x9b"}/
- end
-
- it "accepts '\\M-\\C-\\n'" do
- Regexp.send(@method, "\M-\n").should == /#{"\x8a"}/
- end
-
- it "accepts '\\M-\\C-\\t'" do
- Regexp.send(@method, "\M-\t").should == /#{"\x89"}/
- end
-
- it "accepts '\\M-\\C-\\r'" do
- Regexp.send(@method, "\M-\r").should == /#{"\x8d"}/
- end
-
- it "accepts '\\M-\\C-\\f'" do
- Regexp.send(@method, "\M-\f").should == /#{"\x8c"}/
- end
-
- it "accepts '\\M-\\C-\\v'" do
- Regexp.send(@method, "\M-\v").should == /#{"\x8b"}/
- end
-
- it "accepts '\\M-\\C-\\a'" do
- Regexp.send(@method, "\M-\a").should == /#{"\x87"}/
- end
-
- it "accepts '\\M-\\C-\\e'" do
- Regexp.send(@method, "\M-\e").should == /#{"\x9b"}/
- end
-
- it "accepts '\\M-\\c\\n'" do
- Regexp.send(@method, "\M-\n").should == /#{"\x8a"}/
- end
-
- it "accepts '\\M-\\c\\t'" do
- Regexp.send(@method, "\M-\t").should == /#{"\x89"}/
- end
-
- it "accepts '\\M-\\c\\r'" do
- Regexp.send(@method, "\M-\r").should == /#{"\x8d"}/
- end
-
- it "accepts '\\M-\\c\\f'" do
- Regexp.send(@method, "\M-\f").should == /#{"\x8c"}/
- end
-
- it "accepts '\\M-\\c\\v'" do
- Regexp.send(@method, "\M-\v").should == /#{"\x8b"}/
- end
-
- it "accepts '\\M-\\c\\a'" do
- Regexp.send(@method, "\M-\a").should == /#{"\x87"}/
- end
-
- it "accepts '\\M-\\c\\e'" do
- Regexp.send(@method, "\M-\e").should == /#{"\x9b"}/
- end
-
- it "accepts multiple consecutive '\\' characters" do
- Regexp.send(@method, "\\\\\\N").should == /#{"\\\\\\"+"N"}/
- end
-
- it "accepts characters and escaped octal digits" do
- Regexp.send(@method, "abc\076").should == /#{"abc\x3e"}/
- end
-
- it "accepts escaped octal digits and characters" do
- Regexp.send(@method, "\076abc").should == /#{"\x3eabc"}/
- end
-
- it "accepts characters and escaped hexadecimal digits" do
- Regexp.send(@method, "abc\x42").should == /#{"abc\x42"}/
- end
-
- it "accepts escaped hexadecimal digits and characters" do
- Regexp.send(@method, "\x3eabc").should == /#{"\x3eabc"}/
- end
-
- it "accepts escaped hexadecimal and octal digits" do
- Regexp.send(@method, "\061\x42").should == /#{"\x31\x42"}/
- end
-
- it "accepts \\u{H} for a single Unicode codepoint" do
- Regexp.send(@method, "\u{f}").should == /#{"\x0f"}/
- end
-
- it "accepts \\u{HH} for a single Unicode codepoint" do
- Regexp.send(@method, "\u{7f}").should == /#{"\x7f"}/
- end
-
- it "accepts \\u{HHH} for a single Unicode codepoint" do
- Regexp.send(@method, "\u{07f}").should == /#{"\x7f"}/
- end
-
- it "accepts \\u{HHHH} for a single Unicode codepoint" do
- Regexp.send(@method, "\u{0000}").should == /#{"\x00"}/
- end
-
- it "accepts \\u{HHHHH} for a single Unicode codepoint" do
- Regexp.send(@method, "\u{00001}").should == /#{"\x01"}/
- end
-
- it "accepts \\u{HHHHHH} for a single Unicode codepoint" do
- Regexp.send(@method, "\u{000000}").should == /#{"\x00"}/
- end
-
- it "accepts characters followed by \\u{HHHH}" do
- Regexp.send(@method, "abc\u{3042}").should == /#{"abc\u3042"}/
- end
-
- it "accepts \\u{HHHH} followed by characters" do
- Regexp.send(@method, "\u{3042}abc").should == /#{"\u3042abc"}/
- end
-
- it "accepts escaped hexadecimal digits followed by \\u{HHHH}" do
- Regexp.send(@method, "\x42\u{3042}").should == /#{"\x42\u3042"}/
- end
-
- it "accepts escaped octal digits followed by \\u{HHHH}" do
- Regexp.send(@method, "\056\u{3042}").should == /#{"\x2e\u3042"}/
- end
-
- it "accepts a combination of escaped octal and hexadecimal digits and \\u{HHHH}" do
- Regexp.send(@method, "\056\x42\u{3042}\x52\076").should == /#{"\x2e\x42\u3042\x52\x3e"}/
- end
-
- it "accepts \\uHHHH for a single Unicode codepoint" do
- Regexp.send(@method, "\u3042").should == /#{"\u3042"}/
- end
-
- it "accepts characters followed by \\uHHHH" do
- Regexp.send(@method, "abc\u3042").should == /#{"abc\u3042"}/
- end
-
- it "accepts \\uHHHH followed by characters" do
- Regexp.send(@method, "\u3042abc").should == /#{"\u3042abc"}/
- end
-
- it "accepts escaped hexadecimal digits followed by \\uHHHH" do
- Regexp.send(@method, "\x42\u3042").should == /#{"\x42\u3042"}/
- end
-
- it "accepts escaped octal digits followed by \\uHHHH" do
- Regexp.send(@method, "\056\u3042").should == /#{"\x2e\u3042"}/
- end
-
- it "accepts a combination of escaped octal and hexadecimal digits and \\uHHHH" do
- Regexp.send(@method, "\056\x42\u3042\x52\076").should == /#{"\x2e\x42\u3042\x52\x3e"}/
- end
-
- it "raises a RegexpError if less than four digits are given for \\uHHHH" do
- lambda { Regexp.send(@method, "\\" + "u304") }.should raise_error(RegexpError)
- end
-
- it "raises a RegexpError if the \\u{} escape is empty" do
- lambda { Regexp.send(@method, "\\" + "u{}") }.should raise_error(RegexpError)
- end
-
- it "raises a RegexpError if more than six hexadecimal digits are given" do
- lambda { Regexp.send(@method, "\\" + "u{0ffffff}") }.should raise_error(RegexpError)
- end
-
- it "returns a Regexp with US-ASCII encoding if only 7-bit ASCII characters are present regardless of the input String's encoding" do
- Regexp.send(@method, "abc").encoding.should == Encoding::US_ASCII
- end
-
- it "returns a Regexp with source String having US-ASCII encoding if only 7-bit ASCII characters are present regardless of the input String's encoding" do
- Regexp.send(@method, "abc").source.encoding.should == Encoding::US_ASCII
- end
-
- it "returns a Regexp with US-ASCII encoding if UTF-8 escape sequences using only 7-bit ASCII are present" do
- Regexp.send(@method, "\u{61}").encoding.should == Encoding::US_ASCII
- end
-
- it "returns a Regexp with source String having US-ASCII encoding if UTF-8 escape sequences using only 7-bit ASCII are present" do
- Regexp.send(@method, "\u{61}").source.encoding.should == Encoding::US_ASCII
- end
-
- it "returns a Regexp with UTF-8 encoding if any UTF-8 escape sequences outside 7-bit ASCII are present" do
- Regexp.send(@method, "\u{ff}").encoding.should == Encoding::UTF_8
- end
-
- it "returns a Regexp with source String having UTF-8 encoding if any UTF-8 escape sequences outside 7-bit ASCII are present" do
- Regexp.send(@method, "\u{ff}").source.encoding.should == Encoding::UTF_8
- end
-
- it "returns a Regexp with the input String's encoding" do
- str = "\x82\xa0".force_encoding(Encoding::Shift_JIS)
- Regexp.send(@method, str).encoding.should == Encoding::Shift_JIS
- end
-
- it "returns a Regexp with source String having the input String's encoding" do
- str = "\x82\xa0".force_encoding(Encoding::Shift_JIS)
- Regexp.send(@method, str).source.encoding.should == Encoding::Shift_JIS
- end
- end
-end
-
-describe :regexp_new_regexp_ascii_8bit, shared: true do
- it "uses the argument as a literal to construct a Regexp object" do
- Regexp.send(@method, /^hi{2,3}fo.o$/).should == /^hi{2,3}fo.o$/
- end
-
- it "preserves any options given in the Regexp literal" do
- (Regexp.send(@method, /Hi/i).options & Regexp::IGNORECASE).should_not == 0
- (Regexp.send(@method, /Hi/m).options & Regexp::MULTILINE).should_not == 0
- not_supported_on :opal do
- (Regexp.send(@method, /Hi/x).options & Regexp::EXTENDED).should_not == 0
- end
-
- not_supported_on :opal do
- r = Regexp.send @method, /Hi/imx
- (r.options & Regexp::IGNORECASE).should_not == 0
- (r.options & Regexp::MULTILINE).should_not == 0
- (r.options & Regexp::EXTENDED).should_not == 0
- end
-
- r = Regexp.send @method, /Hi/
- (r.options & Regexp::IGNORECASE).should == 0
- (r.options & Regexp::MULTILINE).should == 0
- not_supported_on :opal do
- (r.options & Regexp::EXTENDED).should == 0
- end
- end
-
- it "does not honour options given as additional arguments" do
- r = nil
- lambda {
- r = Regexp.send @method, /hi/, Regexp::IGNORECASE
- }.should complain(/flags ignored/)
- (r.options & Regexp::IGNORECASE).should == 0
- end
-
- not_supported_on :opal do
- it "sets the encoding to UTF-8 if the Regexp literal has the 'u' option" do
- Regexp.send(@method, /Hi/u).encoding.should == Encoding::UTF_8
- end
-
- it "sets the encoding to EUC-JP if the Regexp literal has the 'e' option" do
- Regexp.send(@method, /Hi/e).encoding.should == Encoding::EUC_JP
- end
-
- it "sets the encoding to Windows-31J if the Regexp literal has the 's' option" do
- Regexp.send(@method, /Hi/s).encoding.should == Encoding::Windows_31J
- end
-
- it "sets the encoding to US-ASCII if the Regexp literal has the 'n' option and the source String is ASCII only" do
- Regexp.send(@method, /Hi/n).encoding.should == Encoding::US_ASCII
- end
-
- it "sets the encoding to source String's encoding if the Regexp literal has the 'n' option and the source String is not ASCII only" do
- Regexp.send(@method, Regexp.new("\\xff", nil, 'n')).encoding.should == Encoding::ASCII_8BIT
- end
- end
-end
diff --git a/spec/ruby/core/regexp/shared/quote.rb b/spec/ruby/core/regexp/shared/quote.rb
deleted file mode 100644
index 016cb0b164..0000000000
--- a/spec/ruby/core/regexp/shared/quote.rb
+++ /dev/null
@@ -1,31 +0,0 @@
-# -*- encoding: ascii-8bit -*-
-
-describe :regexp_quote, shared: true do
- it "escapes any characters with special meaning in a regular expression" do
- Regexp.send(@method, '\*?{}.+^[]()- ').should == '\\\\\*\?\{\}\.\+\^\[\]\(\)\-\\ '
- Regexp.send(@method, "\*?{}.+^[]()- ").should == '\\*\\?\\{\\}\\.\\+\\^\\[\\]\\(\\)\\-\\ '
- Regexp.send(@method, '\n\r\f\t').should == '\\\\n\\\\r\\\\f\\\\t'
- Regexp.send(@method, "\n\r\f\t").should == '\\n\\r\\f\\t'
- end
-
- it "works with symbols" do
- Regexp.send(@method, :symbol).should == 'symbol'
- end
-
- it "sets the encoding of the result to US-ASCII if there are only US-ASCII characters present in the input String" do
- str = "abc".force_encoding("euc-jp")
- Regexp.send(@method, str).encoding.should == Encoding::US_ASCII
- end
-
- it "sets the encoding of the result to the encoding of the String if any non-US-ASCII characters are present in an input String with valid encoding" do
- str = "ã‚りãŒã¨ã†".force_encoding("utf-8")
- str.valid_encoding?.should be_true
- Regexp.send(@method, str).encoding.should == Encoding::UTF_8
- end
-
- it "sets the encoding of the result to ASCII-8BIT if any non-US-ASCII characters are present in an input String with invalid encoding" do
- str = "\xff".force_encoding "us-ascii"
- str.valid_encoding?.should be_false
- Regexp.send(@method, "\xff").encoding.should == Encoding::ASCII_8BIT
- end
-end
diff --git a/spec/ruby/core/regexp/source_spec.rb b/spec/ruby/core/regexp/source_spec.rb
index 3960a09395..4eebf280f0 100644
--- a/spec/ruby/core/regexp/source_spec.rb
+++ b/spec/ruby/core/regexp/source_spec.rb
@@ -1,5 +1,5 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Regexp#source" do
it "returns the original string of the pattern" do
@@ -9,21 +9,39 @@ describe "Regexp#source" do
/x(.)xz/.source.should == "x(.)xz"
end
- it "will remove escape characters" do
- /foo\/bar/.source.should == "foo/bar"
+ it "keeps escape sequences as is" do
+ /\x20\+/.source.should == '\x20\+'
+ end
+
+ describe "escaping" do
+ it "keeps escaping of metacharacter" do
+ /\$/.source.should == "\\$"
+ end
+
+ it "keeps escaping of metacharacter used as a terminator" do
+ %r+\++.source.should == "\\+"
+ end
+
+ it "removes escaping of non-metacharacter used as a terminator" do
+ %r@\@@.source.should == "@"
+ end
+
+ it "keeps escaping of non-metacharacter not used as a terminator" do
+ /\@/.source.should == "\\@"
+ end
end
not_supported_on :opal do
it "has US-ASCII encoding when created from an ASCII-only \\u{} literal" do
re = /[\u{20}-\u{7E}]/
- re.source.encoding.should equal(Encoding::US_ASCII)
+ re.source.encoding.should.equal?(Encoding::US_ASCII)
end
end
not_supported_on :opal do
it "has UTF-8 encoding when created from a non-ASCII-only \\u{} literal" do
re = /[\u{20}-\u{7EE}]/
- re.source.encoding.should equal(Encoding::UTF_8)
+ re.source.encoding.should.equal?(Encoding::UTF_8)
end
end
end
diff --git a/spec/ruby/core/regexp/timeout_spec.rb b/spec/ruby/core/regexp/timeout_spec.rb
new file mode 100644
index 0000000000..a1ec475ef3
--- /dev/null
+++ b/spec/ruby/core/regexp/timeout_spec.rb
@@ -0,0 +1,33 @@
+require_relative '../../spec_helper'
+
+describe "Regexp.timeout" do
+ after :each do
+ Regexp.timeout = nil
+ end
+
+ it "returns global timeout" do
+ Regexp.timeout = 3
+ Regexp.timeout.should == 3
+ end
+
+ it "raises Regexp::TimeoutError after global timeout elapsed" do
+ Regexp.timeout = 0.001
+ Regexp.timeout.should == 0.001
+
+ -> {
+ # A typical ReDoS case
+ /^(a*)*$/ =~ "a" * 1000000 + "x"
+ }.should.raise(Regexp::TimeoutError, "regexp match timeout")
+ end
+
+ it "raises Regexp::TimeoutError after timeout keyword value elapsed" do
+ Regexp.timeout = 3 # This should be ignored
+ Regexp.timeout.should == 3
+
+ re = Regexp.new("^a*b?a*$", timeout: 0.001)
+
+ -> {
+ re =~ "a" * 1000000 + "x"
+ }.should.raise(Regexp::TimeoutError, "regexp match timeout")
+ end
+end
diff --git a/spec/ruby/core/regexp/to_s_spec.rb b/spec/ruby/core/regexp/to_s_spec.rb
index a23fd78975..798eaee6c2 100644
--- a/spec/ruby/core/regexp/to_s_spec.rb
+++ b/spec/ruby/core/regexp/to_s_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Regexp#to_s" do
not_supported_on :opal do
diff --git a/spec/ruby/core/regexp/try_convert_spec.rb b/spec/ruby/core/regexp/try_convert_spec.rb
index e782fc07fb..da5e10adce 100644
--- a/spec/ruby/core/regexp/try_convert_spec.rb
+++ b/spec/ruby/core/regexp/try_convert_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Regexp.try_convert" do
not_supported_on :opal do
@@ -9,7 +9,7 @@ describe "Regexp.try_convert" do
it "returns nil if given an argument that can't be converted to a Regexp" do
['', 'glark', [], Object.new, :pat].each do |arg|
- Regexp.try_convert(arg).should be_nil
+ Regexp.try_convert(arg).should == nil
end
end
@@ -18,4 +18,10 @@ describe "Regexp.try_convert" do
rex.should_receive(:to_regexp).and_return(/(p(a)t[e]rn)/)
Regexp.try_convert(rex).should == /(p(a)t[e]rn)/
end
+
+ it "raises a TypeError if the object does not return an Regexp from #to_regexp" do
+ obj = mock("regexp")
+ obj.should_receive(:to_regexp).and_return("string")
+ -> { Regexp.try_convert(obj) }.should raise_consistent_error(TypeError, "can't convert MockObject into Regexp (MockObject#to_regexp gives String)")
+ end
end
diff --git a/spec/ruby/core/regexp/union_spec.rb b/spec/ruby/core/regexp/union_spec.rb
index 0f62747753..c0a9d12fed 100644
--- a/spec/ruby/core/regexp/union_spec.rb
+++ b/spec/ruby/core/regexp/union_spec.rb
@@ -1,6 +1,6 @@
# encoding: utf-8
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Regexp.union" do
it "returns /(?!)/ when passed no arguments" do
@@ -43,6 +43,27 @@ describe "Regexp.union" do
Regexp.union("\u00A9".encode("ISO-8859-1"), "a".encode("UTF-8")).encoding.should == Encoding::ISO_8859_1
end
+ it "returns ASCII-8BIT if the regexp encodings are ASCII-8BIT and at least one has non-ASCII characters" do
+ us_ascii_implicit, us_ascii_explicit, binary = /abc/, /[\x00-\x7f]/n, /[\x80-\xBF]/n
+ us_ascii_implicit.encoding.should == Encoding::US_ASCII
+ us_ascii_explicit.encoding.should == Encoding::US_ASCII
+ binary.encoding.should == Encoding::BINARY
+
+ Regexp.union(us_ascii_implicit, us_ascii_explicit, binary).encoding.should == Encoding::BINARY
+ Regexp.union(us_ascii_implicit, binary, us_ascii_explicit).encoding.should == Encoding::BINARY
+ Regexp.union(us_ascii_explicit, us_ascii_implicit, binary).encoding.should == Encoding::BINARY
+ Regexp.union(us_ascii_explicit, binary, us_ascii_implicit).encoding.should == Encoding::BINARY
+ Regexp.union(binary, us_ascii_implicit, us_ascii_explicit).encoding.should == Encoding::BINARY
+ Regexp.union(binary, us_ascii_explicit, us_ascii_implicit).encoding.should == Encoding::BINARY
+ end
+
+ it "return US-ASCII if all patterns are ASCII-only" do
+ Regexp.union(/abc/e, /def/e).encoding.should == Encoding::US_ASCII
+ Regexp.union(/abc/n, /def/n).encoding.should == Encoding::US_ASCII
+ Regexp.union(/abc/s, /def/s).encoding.should == Encoding::US_ASCII
+ Regexp.union(/abc/u, /def/u).encoding.should == Encoding::US_ASCII
+ end
+
it "returns a Regexp with UTF-8 if one part is UTF-8" do
Regexp.union(/probl[éeè]me/i, /help/i).encoding.should == Encoding::UTF_8
end
@@ -52,85 +73,85 @@ describe "Regexp.union" do
end
it "raises ArgumentError if the arguments include conflicting ASCII-incompatible Strings" do
- lambda {
+ -> {
Regexp.union("a".encode("UTF-16LE"), "b".encode("UTF-16BE"))
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError, 'incompatible encodings: UTF-16LE and UTF-16BE')
end
it "raises ArgumentError if the arguments include conflicting ASCII-incompatible Regexps" do
- lambda {
+ -> {
Regexp.union(Regexp.new("a".encode("UTF-16LE")),
Regexp.new("b".encode("UTF-16BE")))
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError, 'incompatible encodings: UTF-16LE and UTF-16BE')
end
it "raises ArgumentError if the arguments include conflicting fixed encoding Regexps" do
- lambda {
+ -> {
Regexp.union(Regexp.new("a".encode("UTF-8"), Regexp::FIXEDENCODING),
Regexp.new("b".encode("US-ASCII"), Regexp::FIXEDENCODING))
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError, 'incompatible encodings: UTF-8 and US-ASCII')
end
it "raises ArgumentError if the arguments include a fixed encoding Regexp and a String containing non-ASCII-compatible characters in a different encoding" do
- lambda {
+ -> {
Regexp.union(Regexp.new("a".encode("UTF-8"), Regexp::FIXEDENCODING),
"\u00A9".encode("ISO-8859-1"))
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError, 'incompatible encodings: UTF-8 and ISO-8859-1')
end
it "raises ArgumentError if the arguments include a String containing non-ASCII-compatible characters and a fixed encoding Regexp in a different encoding" do
- lambda {
+ -> {
Regexp.union("\u00A9".encode("ISO-8859-1"),
Regexp.new("a".encode("UTF-8"), Regexp::FIXEDENCODING))
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError, 'incompatible encodings: ISO-8859-1 and UTF-8')
end
it "raises ArgumentError if the arguments include an ASCII-incompatible String and an ASCII-only String" do
- lambda {
+ -> {
Regexp.union("a".encode("UTF-16LE"), "b".encode("UTF-8"))
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError, /ASCII incompatible encoding: UTF-16LE|incompatible encodings: UTF-16LE and US-ASCII/)
end
it "raises ArgumentError if the arguments include an ASCII-incompatible Regexp and an ASCII-only String" do
- lambda {
+ -> {
Regexp.union(Regexp.new("a".encode("UTF-16LE")), "b".encode("UTF-8"))
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError, /ASCII incompatible encoding: UTF-16LE|incompatible encodings: UTF-16LE and US-ASCII/)
end
it "raises ArgumentError if the arguments include an ASCII-incompatible String and an ASCII-only Regexp" do
- lambda {
+ -> {
Regexp.union("a".encode("UTF-16LE"), Regexp.new("b".encode("UTF-8")))
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError, /ASCII incompatible encoding: UTF-16LE|incompatible encodings: UTF-16LE and US-ASCII/)
end
it "raises ArgumentError if the arguments include an ASCII-incompatible Regexp and an ASCII-only Regexp" do
- lambda {
+ -> {
Regexp.union(Regexp.new("a".encode("UTF-16LE")), Regexp.new("b".encode("UTF-8")))
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError, /ASCII incompatible encoding: UTF-16LE|incompatible encodings: UTF-16LE and US-ASCII/)
end
it "raises ArgumentError if the arguments include an ASCII-incompatible String and a String containing non-ASCII-compatible characters in a different encoding" do
- lambda {
+ -> {
Regexp.union("a".encode("UTF-16LE"), "\u00A9".encode("ISO-8859-1"))
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError, 'incompatible encodings: UTF-16LE and ISO-8859-1')
end
it "raises ArgumentError if the arguments include an ASCII-incompatible Regexp and a String containing non-ASCII-compatible characters in a different encoding" do
- lambda {
+ -> {
Regexp.union(Regexp.new("a".encode("UTF-16LE")), "\u00A9".encode("ISO-8859-1"))
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError, 'incompatible encodings: UTF-16LE and ISO-8859-1')
end
it "raises ArgumentError if the arguments include an ASCII-incompatible String and a Regexp containing non-ASCII-compatible characters in a different encoding" do
- lambda {
+ -> {
Regexp.union("a".encode("UTF-16LE"), Regexp.new("\u00A9".encode("ISO-8859-1")))
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError, 'incompatible encodings: UTF-16LE and ISO-8859-1')
end
it "raises ArgumentError if the arguments include an ASCII-incompatible Regexp and a Regexp containing non-ASCII-compatible characters in a different encoding" do
- lambda {
+ -> {
Regexp.union(Regexp.new("a".encode("UTF-16LE")), Regexp.new("\u00A9".encode("ISO-8859-1")))
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError, 'incompatible encodings: UTF-16LE and ISO-8859-1')
end
it "uses to_str to convert arguments (if not Regexp)" do
@@ -139,11 +160,23 @@ describe "Regexp.union" do
Regexp.union(obj, "bar").should == /foo|bar/
end
+ it "uses to_regexp to convert argument" do
+ obj = mock('pattern')
+ obj.should_receive(:to_regexp).and_return(/foo/)
+ Regexp.union(obj).should == /foo/
+ end
+
+ it "accepts a Symbol as argument" do
+ Regexp.union(:foo).should == /foo/
+ end
+
it "accepts a single array of patterns as arguments" do
Regexp.union(["skiing", "sledding"]).should == /skiing|sledding/
not_supported_on :opal do
Regexp.union([/dogs/, /cats/i]).should == /(?-mix:dogs)|(?i-mx:cats)/
end
- lambda{Regexp.union(["skiing", "sledding"], [/dogs/, /cats/i])}.should raise_error(TypeError)
+ -> {
+ Regexp.union(["skiing", "sledding"], [/dogs/, /cats/i])
+ }.should.raise(TypeError, 'no implicit conversion of Array into String')
end
end
diff --git a/spec/ruby/core/set/add_spec.rb b/spec/ruby/core/set/add_spec.rb
new file mode 100644
index 0000000000..1a018b186a
--- /dev/null
+++ b/spec/ruby/core/set/add_spec.rb
@@ -0,0 +1,44 @@
+require_relative '../../spec_helper'
+
+describe "Set#add" do
+ before :each do
+ @set = Set.new
+ end
+
+ it "adds the passed Object to self" do
+ @set.add("dog")
+ @set.should.include?("dog")
+ end
+
+ it "returns self" do
+ @set.add("dog").should.equal?(@set)
+ end
+end
+
+describe "Set#add?" do
+ before :each do
+ @set = Set.new
+ end
+
+ it "adds the passed Object to self" do
+ @set.add?("cat")
+ @set.should.include?("cat")
+ end
+
+ it "returns self when the Object has not yet been added to self" do
+ @set.add?("cat").should.equal?(@set)
+ end
+
+ it "returns nil when the Object has already been added to self" do
+ @set.add?("cat")
+ @set.add?("cat").should == nil
+ end
+
+ it "raises RuntimeError when called during iteration" do
+ set = Set[:a, :b, :c, :d, :e, :f]
+ set.each do |_m|
+ -> { set << 1 }.should.raise(RuntimeError, /iteration/)
+ end
+ set.should == Set[:a, :b, :c, :d, :e, :f]
+ end
+end
diff --git a/spec/ruby/core/set/append_spec.rb b/spec/ruby/core/set/append_spec.rb
new file mode 100644
index 0000000000..4f4e2351e2
--- /dev/null
+++ b/spec/ruby/core/set/append_spec.rb
@@ -0,0 +1,7 @@
+require_relative '../../spec_helper'
+
+describe "Set#<<" do
+ it "is an alias of Set#add" do
+ Set.instance_method(:<<).should == Set.instance_method(:add)
+ end
+end
diff --git a/spec/ruby/core/set/case_compare_spec.rb b/spec/ruby/core/set/case_compare_spec.rb
new file mode 100644
index 0000000000..6fe749c79b
--- /dev/null
+++ b/spec/ruby/core/set/case_compare_spec.rb
@@ -0,0 +1,7 @@
+require_relative '../../spec_helper'
+
+describe "Set#===" do
+ it "is an alias of Set#include?" do
+ Set.instance_method(:===).should == Set.instance_method(:include?)
+ end
+end
diff --git a/spec/ruby/core/set/classify_spec.rb b/spec/ruby/core/set/classify_spec.rb
new file mode 100644
index 0000000000..a225ab7cbb
--- /dev/null
+++ b/spec/ruby/core/set/classify_spec.rb
@@ -0,0 +1,26 @@
+require_relative '../../spec_helper'
+
+describe "Set#classify" do
+ before :each do
+ @set = Set["one", "two", "three", "four"]
+ end
+
+ it "yields each Object in self" do
+ res = []
+ @set.classify { |x| res << x }
+ res.sort.should == ["one", "two", "three", "four"].sort
+ end
+
+ it "returns an Enumerator when passed no block" do
+ enum = @set.classify
+ enum.should.instance_of?(Enumerator)
+
+ classified = enum.each { |x| x.length }
+ classified.should == { 3 => Set["one", "two"], 4 => Set["four"], 5 => Set["three"] }
+ end
+
+ it "classifies the Objects in self based on the block's return value" do
+ classified = @set.classify { |x| x.length }
+ classified.should == { 3 => Set["one", "two"], 4 => Set["four"], 5 => Set["three"] }
+ end
+end
diff --git a/spec/ruby/core/set/clear_spec.rb b/spec/ruby/core/set/clear_spec.rb
new file mode 100644
index 0000000000..c61a0d78f2
--- /dev/null
+++ b/spec/ruby/core/set/clear_spec.rb
@@ -0,0 +1,16 @@
+require_relative '../../spec_helper'
+
+describe "Set#clear" do
+ before :each do
+ @set = Set["one", "two", "three", "four"]
+ end
+
+ it "removes all elements from self" do
+ @set.clear
+ @set.should.empty?
+ end
+
+ it "returns self" do
+ @set.clear.should.equal?(@set)
+ end
+end
diff --git a/spec/ruby/core/set/collect_spec.rb b/spec/ruby/core/set/collect_spec.rb
new file mode 100644
index 0000000000..b78ee493d4
--- /dev/null
+++ b/spec/ruby/core/set/collect_spec.rb
@@ -0,0 +1,7 @@
+require_relative '../../spec_helper'
+
+describe "Set#collect!" do
+ it "is an alias of Set#map!" do
+ Set.instance_method(:collect!).should == Set.instance_method(:map!)
+ end
+end
diff --git a/spec/ruby/core/set/compare_by_identity_spec.rb b/spec/ruby/core/set/compare_by_identity_spec.rb
new file mode 100644
index 0000000000..458e760da0
--- /dev/null
+++ b/spec/ruby/core/set/compare_by_identity_spec.rb
@@ -0,0 +1,153 @@
+require_relative '../../spec_helper'
+
+describe "Set#compare_by_identity" do
+ it "compares its members by identity" do
+ a = "a"
+ b1 = "b"
+ b2 = b1.dup
+
+ set = Set.new
+ set.compare_by_identity
+ set.merge([a, a, b1, b2])
+ set.to_a.sort.should == [a, b1, b2].sort
+ end
+
+ it "causes future comparisons on the receiver to be made by identity" do
+ elt = [1]
+ set = Set.new
+ set << elt
+ set.member?(elt.dup).should == true
+ set.compare_by_identity
+ set.member?(elt.dup).should == false
+ end
+
+ it "rehashes internally so that old members can be looked up" do
+ set = Set.new
+ (1..10).each { |k| set << k }
+ o = Object.new
+ def o.hash; 123; end
+ set << o
+ set.compare_by_identity
+ set.member?(o).should == true
+ end
+
+ it "returns self" do
+ set = Set.new
+ result = set.compare_by_identity
+ result.should.equal?(set)
+ end
+
+ it "is idempotent and has no effect on an already compare_by_identity set" do
+ set = Set.new.compare_by_identity
+ set << :foo
+ set.compare_by_identity.should.equal?(set)
+ set.should.compare_by_identity?
+ set.to_a.should == [:foo]
+ end
+
+ it "uses the semantics of BasicObject#equal? to determine members identity" do
+ :a.equal?(:a).should == true
+ Set.new.compare_by_identity.merge([:a, :a]).to_a.should == [:a]
+
+ ary1 = [1]
+ ary2 = [1]
+ ary1.equal?(ary2).should == false
+ Set.new.compare_by_identity.merge([ary1, ary2]).to_a.sort.should == [ary1, ary2].sort
+ end
+
+ it "uses #equal? semantics, but doesn't actually call #equal? to determine identity" do
+ set = Set.new.compare_by_identity
+ obj = mock("equal")
+ obj.should_not_receive(:equal?)
+ set << :foo
+ set << obj
+ set.to_a.should == [:foo, obj]
+ end
+
+ it "does not call #hash on members" do
+ elt = mock("element")
+ elt.should_not_receive(:hash)
+ set = Set.new.compare_by_identity
+ set << elt
+ set.member?(elt).should == true
+ end
+
+ it "regards #dup'd objects as having different identities" do
+ a1 = "a"
+ a2 = a1.dup
+
+ set = Set.new.compare_by_identity
+ set.merge([a1, a2])
+ set.to_a.sort.should == [a1, a2].sort
+ end
+
+ it "regards #clone'd objects as having different identities" do
+ a1 = "a"
+ a2 = a1.clone
+
+ set = Set.new.compare_by_identity
+ set.merge([a1, a2])
+ set.to_a.sort.should == [a1, a2].sort
+ end
+
+ ruby_version_is "4.0" do
+ it "raises a FrozenError on frozen sets" do
+ set = Set.new.freeze
+ -> {
+ set.compare_by_identity
+ }.should.raise(FrozenError, /can't modify frozen Set: (#<)?Set(\[|: {)[\]}]>?/)
+ end
+ end
+
+ ruby_version_is ""..."4.0" do
+ it "raises a FrozenError on frozen sets" do
+ set = Set.new.freeze
+ -> {
+ set.compare_by_identity
+ }.should.raise(FrozenError, /frozen Hash/)
+ end
+ end
+
+ it "persists over #dups" do
+ set = Set.new.compare_by_identity
+ set << :a
+ set_dup = set.dup
+ set_dup.should == set
+ set_dup << :a
+ set_dup.to_a.should == [:a]
+ end
+
+ it "persists over #clones" do
+ set = Set.new.compare_by_identity
+ set << :a
+ set_clone = set.clone
+ set_clone.should == set
+ set_clone << :a
+ set_clone.to_a.should == [:a]
+ end
+
+ it "is not equal to set what does not compare by identity" do
+ Set.new([1, 2]).should == Set.new([1, 2])
+ Set.new([1, 2]).should_not == Set.new([1, 2]).compare_by_identity
+ end
+end
+
+describe "Set#compare_by_identity?" do
+ it "returns false by default" do
+ Set.new.should_not.compare_by_identity?
+ end
+
+ it "returns true once #compare_by_identity has been invoked on self" do
+ set = Set.new
+ set.compare_by_identity
+ set.should.compare_by_identity?
+ end
+
+ it "returns true when called multiple times on the same set" do
+ set = Set.new
+ set.compare_by_identity
+ set.should.compare_by_identity?
+ set.should.compare_by_identity?
+ set.should.compare_by_identity?
+ end
+end
diff --git a/spec/ruby/core/set/comparison_spec.rb b/spec/ruby/core/set/comparison_spec.rb
new file mode 100644
index 0000000000..eb18a198e5
--- /dev/null
+++ b/spec/ruby/core/set/comparison_spec.rb
@@ -0,0 +1,26 @@
+require_relative '../../spec_helper'
+
+describe "Set#<=>" do
+ it "returns 0 if the sets are equal" do
+ (Set[] <=> Set[]).should == 0
+ (Set[:a, :b, :c] <=> Set[:a, :b, :c]).should == 0
+ end
+
+ it "returns -1 if the set is a proper subset of the other set" do
+ (Set[] <=> Set[1]).should == -1
+ (Set[1, 2] <=> Set[1, 2, 3]).should == -1
+ end
+
+ it "returns +1 if the set is a proper superset of other set" do
+ (Set[1] <=> Set[]).should == +1
+ (Set[1, 2, 3] <=> Set[1, 2]).should == +1
+ end
+
+ it "returns nil if the set has unique elements" do
+ (Set[1, 2, 3] <=> Set[:a, :b, :c]).should == nil
+ end
+
+ it "returns nil when the argument is not set-like" do
+ (Set[] <=> false).should == nil
+ end
+end
diff --git a/spec/ruby/core/set/constructor_spec.rb b/spec/ruby/core/set/constructor_spec.rb
new file mode 100644
index 0000000000..11138f3a5b
--- /dev/null
+++ b/spec/ruby/core/set/constructor_spec.rb
@@ -0,0 +1,14 @@
+require_relative '../../spec_helper'
+
+describe "Set[]" do
+ it "returns a new Set populated with the passed Objects" do
+ set = Set[1, 2, 3]
+
+ set.instance_of?(Set).should == true
+ set.size.should.eql?(3)
+
+ set.should.include?(1)
+ set.should.include?(2)
+ set.should.include?(3)
+ end
+end
diff --git a/spec/ruby/core/set/delete_if_spec.rb b/spec/ruby/core/set/delete_if_spec.rb
new file mode 100644
index 0000000000..b231dff50d
--- /dev/null
+++ b/spec/ruby/core/set/delete_if_spec.rb
@@ -0,0 +1,37 @@
+require_relative '../../spec_helper'
+
+describe "Set#delete_if" do
+ before :each do
+ @set = Set["one", "two", "three"]
+ end
+
+ it "yields every element of self" do
+ ret = []
+ @set.delete_if { |x| ret << x }
+ ret.sort.should == ["one", "two", "three"].sort
+ end
+
+ it "deletes every element from self for which the passed block returns true" do
+ @set.delete_if { |x| x.size == 3 }
+ @set.size.should.eql?(1)
+
+ @set.should_not.include?("one")
+ @set.should_not.include?("two")
+ @set.should.include?("three")
+ end
+
+ it "returns self" do
+ @set.delete_if { |x| x }.should.equal?(@set)
+ end
+
+ it "returns an Enumerator when passed no block" do
+ enum = @set.delete_if
+ enum.should.instance_of?(Enumerator)
+
+ enum.each { |x| x.size == 3 }
+
+ @set.should_not.include?("one")
+ @set.should_not.include?("two")
+ @set.should.include?("three")
+ end
+end
diff --git a/spec/ruby/core/set/delete_spec.rb b/spec/ruby/core/set/delete_spec.rb
new file mode 100644
index 0000000000..cdc6dd7b36
--- /dev/null
+++ b/spec/ruby/core/set/delete_spec.rb
@@ -0,0 +1,36 @@
+require_relative '../../spec_helper'
+
+describe "Set#delete" do
+ before :each do
+ @set = Set["a", "b", "c"]
+ end
+
+ it "deletes the passed Object from self" do
+ @set.delete("a")
+ @set.should_not.include?("a")
+ end
+
+ it "returns self" do
+ @set.delete("a").should.equal?(@set)
+ @set.delete("x").should.equal?(@set)
+ end
+end
+
+describe "Set#delete?" do
+ before :each do
+ @set = Set["a", "b", "c"]
+ end
+
+ it "deletes the passed Object from self" do
+ @set.delete?("a")
+ @set.should_not.include?("a")
+ end
+
+ it "returns self when the passed Object is in self" do
+ @set.delete?("a").should.equal?(@set)
+ end
+
+ it "returns nil when the passed Object is not in self" do
+ @set.delete?("x").should == nil
+ end
+end
diff --git a/spec/ruby/core/set/difference_spec.rb b/spec/ruby/core/set/difference_spec.rb
new file mode 100644
index 0000000000..22d89973a8
--- /dev/null
+++ b/spec/ruby/core/set/difference_spec.rb
@@ -0,0 +1,7 @@
+require_relative '../../spec_helper'
+
+describe "Set#difference" do
+ it "is an alias of Set#-" do
+ Set.instance_method(:difference).should == Set.instance_method(:-)
+ end
+end
diff --git a/spec/ruby/core/set/disjoint_spec.rb b/spec/ruby/core/set/disjoint_spec.rb
new file mode 100644
index 0000000000..d415c21045
--- /dev/null
+++ b/spec/ruby/core/set/disjoint_spec.rb
@@ -0,0 +1,22 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/set_like'
+
+describe "Set#disjoint?" do
+ it "returns false when two Sets have at least one element in common" do
+ Set[1, 2].disjoint?(Set[2, 3]).should == false
+ end
+
+ it "returns true when two Sets have no element in common" do
+ Set[1, 2].disjoint?(Set[3, 4]).should == true
+ end
+
+ context "when comparing to a Set-like object" do
+ it "returns false when a Set has at least one element in common with a Set-like object" do
+ Set[1, 2].disjoint?(SetSpecs::SetLike.new([2, 3])).should == false
+ end
+
+ it "returns true when a Set has no element in common with a Set-like object" do
+ Set[1, 2].disjoint?(SetSpecs::SetLike.new([3, 4])).should == true
+ end
+ end
+end
diff --git a/spec/ruby/core/set/divide_spec.rb b/spec/ruby/core/set/divide_spec.rb
new file mode 100644
index 0000000000..409a22df75
--- /dev/null
+++ b/spec/ruby/core/set/divide_spec.rb
@@ -0,0 +1,68 @@
+require_relative '../../spec_helper'
+
+describe "Set#divide" do
+ it "divides self into a set of subsets based on the blocks return values" do
+ set = Set["one", "two", "three", "four", "five"].divide { |x| x.length }
+ set.map { |x| x.to_a.sort }.sort.should == [["five", "four"], ["one", "two"], ["three"]]
+ end
+
+ it "yields each Object to the block" do
+ ret = []
+ Set["one", "two", "three", "four", "five"].divide { |x| ret << x }
+ ret.sort.should == ["five", "four", "one", "three", "two"]
+ end
+
+ it "returns an enumerator when not passed a block" do
+ ret = Set[1, 2, 3, 4].divide
+ ret.should.is_a?(Enumerator)
+ ret.each(&:even?).should == Set[Set[1, 3], Set[2, 4]]
+ end
+end
+
+describe "Set#divide when passed a block with an arity of 2" do
+ it "divides self into a set of subsets based on the blocks return values" do
+ set = Set[1, 3, 4, 6, 9, 10, 11].divide { |x, y| (x - y).abs == 1 }
+ set.map{ |x| x.to_a.sort }.sort.should == [[1], [3, 4], [6], [9, 10, 11]]
+ end
+
+ ruby_version_is "4.0" do
+ it "yields each two Object to the block" do
+ ret = []
+ Set[1, 2].divide { |x, y| ret << [x, y] }
+ ret.sort.should == [[1, 2], [2, 1]]
+ end
+ end
+
+ ruby_version_is ""..."4.0" do
+ it "yields each two Object to the block" do
+ ret = []
+ Set[1, 2].divide { |x, y| ret << [x, y] }
+ ret.sort.should == [[1, 1], [1, 2], [2, 1], [2, 2]]
+ end
+ end
+
+ it "returns an enumerator when not passed a block" do
+ ret = Set[1, 2, 3, 4].divide
+ ret.should.is_a?(Enumerator)
+ ret.each { |a, b| (a + b).even? }.should == Set[Set[1, 3], Set[2, 4]]
+ end
+end
+
+describe "Set#divide when passed a block with an arity of > 2" do
+ it "only uses the first element if the arity > 2" do
+ set = Set["one", "two", "three", "four", "five"].divide do |x, y, z|
+ y.should == nil
+ z.should == nil
+ x.length
+ end
+ set.map { |x| x.to_a.sort }.sort.should == [["five", "four"], ["one", "two"], ["three"]]
+ end
+
+ it "only uses the first element if the arity = -1" do
+ set = Set["one", "two", "three", "four", "five"].divide do |*xs|
+ xs.size.should == 1
+ xs.first.length
+ end
+ set.map { |x| x.to_a.sort }.sort.should == [["five", "four"], ["one", "two"], ["three"]]
+ end
+end
diff --git a/spec/ruby/core/set/each_spec.rb b/spec/ruby/core/set/each_spec.rb
new file mode 100644
index 0000000000..bdafc99571
--- /dev/null
+++ b/spec/ruby/core/set/each_spec.rb
@@ -0,0 +1,26 @@
+require_relative '../../spec_helper'
+
+describe "Set#each" do
+ before :each do
+ @set = Set[1, 2, 3]
+ end
+
+ it "yields each Object in self" do
+ ret = []
+ @set.each { |x| ret << x }
+ ret.sort.should == [1, 2, 3]
+ end
+
+ it "returns self" do
+ @set.each { |x| x }.should.equal?(@set)
+ end
+
+ it "returns an Enumerator when not passed a block" do
+ enum = @set.each
+ enum.should.instance_of?(Enumerator)
+
+ ret = []
+ enum.each { |x| ret << x }
+ ret.sort.should == [1, 2, 3]
+ end
+end
diff --git a/spec/ruby/core/set/empty_spec.rb b/spec/ruby/core/set/empty_spec.rb
new file mode 100644
index 0000000000..c71f2ce18d
--- /dev/null
+++ b/spec/ruby/core/set/empty_spec.rb
@@ -0,0 +1,9 @@
+require_relative '../../spec_helper'
+
+describe "Set#empty?" do
+ it "returns true if self is empty" do
+ Set[].empty?.should == true
+ Set[1].empty?.should == false
+ Set[1,2,3].empty?.should == false
+ end
+end
diff --git a/spec/ruby/core/set/enumerable/to_set_spec.rb b/spec/ruby/core/set/enumerable/to_set_spec.rb
new file mode 100644
index 0000000000..f139e1c025
--- /dev/null
+++ b/spec/ruby/core/set/enumerable/to_set_spec.rb
@@ -0,0 +1,12 @@
+require_relative '../../../spec_helper'
+
+describe "Enumerable#to_set" do
+ it "returns a new Set created from self" do
+ [1, 2, 3].to_set.should == Set[1, 2, 3]
+ {a: 1, b: 2}.to_set.should == Set[[:b, 2], [:a, 1]]
+ end
+
+ it "passes down passed blocks" do
+ [1, 2, 3].to_set { |x| x * x }.should == Set[1, 4, 9]
+ end
+end
diff --git a/spec/ruby/core/set/eql_spec.rb b/spec/ruby/core/set/eql_spec.rb
new file mode 100644
index 0000000000..e7eacf2999
--- /dev/null
+++ b/spec/ruby/core/set/eql_spec.rb
@@ -0,0 +1,22 @@
+require_relative '../../spec_helper'
+
+describe "Set#eql?" do
+ ruby_version_is ""..."4.0" do
+ it "returns true when the passed argument is a Set and contains the same elements" do
+ Set[].should.eql?(Set[])
+ Set[1, 2, 3].should.eql?(Set[1, 2, 3])
+ Set[1, 2, 3].should.eql?(Set[3, 2, 1])
+ Set["a", :b, ?c].should.eql?(Set[?c, :b, "a"])
+
+ Set[1, 2, 3].should_not.eql?(Set[1.0, 2, 3])
+ Set[1, 2, 3].should_not.eql?(Set[2, 3])
+ Set[1, 2, 3].should_not.eql?(Set[])
+ end
+ end
+
+ ruby_version_is "4.0" do
+ it "is an alias of Set#==" do
+ Set.instance_method(:eql?).should == Set.instance_method(:==)
+ end
+ end
+end
diff --git a/spec/ruby/core/set/equal_value_spec.rb b/spec/ruby/core/set/equal_value_spec.rb
new file mode 100644
index 0000000000..721a79a3f1
--- /dev/null
+++ b/spec/ruby/core/set/equal_value_spec.rb
@@ -0,0 +1,34 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/set_like'
+
+describe "Set#==" do
+ it "returns true when the passed Object is a Set and self and the Object contain the same elements" do
+ Set[].should == Set[]
+ Set[1, 2, 3].should == Set[1, 2, 3]
+ Set["1", "2", "3"].should == Set["1", "2", "3"]
+
+ Set[1, 2, 3].should_not == Set[1.0, 2, 3]
+ Set[1, 2, 3].should_not == [1, 2, 3]
+ end
+
+ it "does not depend on the order of the elements" do
+ Set[1, 2, 3].should == Set[3, 2, 1]
+ Set[:a, "b", ?c].should == Set[?c, "b", :a]
+ end
+
+ it "does not depend on the order of nested Sets" do
+ Set[Set[1], Set[2], Set[3]].should == Set[Set[3], Set[2], Set[1]]
+
+ set1 = Set[Set["a", "b"], Set["c", "d"], Set["e", "f"]]
+ set2 = Set[Set["c", "d"], Set["a", "b"], Set["e", "f"]]
+ set1.should == set2
+ end
+
+ ruby_version_is ""..."4.0" do
+ context "when comparing to a Set-like object" do
+ it "returns true when a Set and a Set-like object contain the same elements" do
+ Set[1, 2, 3].should == SetSpecs::SetLike.new([1, 2, 3])
+ end
+ end
+ end
+end
diff --git a/spec/ruby/core/set/exclusion_spec.rb b/spec/ruby/core/set/exclusion_spec.rb
new file mode 100644
index 0000000000..52ee34fe78
--- /dev/null
+++ b/spec/ruby/core/set/exclusion_spec.rb
@@ -0,0 +1,17 @@
+require_relative '../../spec_helper'
+
+describe "Set#^" do
+ before :each do
+ @set = Set[1, 2, 3, 4]
+ end
+
+ it "returns a new Set containing elements that are not in both self and the passed Enumerable" do
+ (@set ^ Set[3, 4, 5]).should == Set[1, 2, 5]
+ (@set ^ [3, 4, 5]).should == Set[1, 2, 5]
+ end
+
+ it "raises an ArgumentError when passed a non-Enumerable" do
+ -> { @set ^ 3 }.should.raise(ArgumentError)
+ -> { @set ^ Object.new }.should.raise(ArgumentError)
+ end
+end
diff --git a/spec/ruby/core/set/filter_spec.rb b/spec/ruby/core/set/filter_spec.rb
new file mode 100644
index 0000000000..d0c294c27f
--- /dev/null
+++ b/spec/ruby/core/set/filter_spec.rb
@@ -0,0 +1,7 @@
+require_relative '../../spec_helper'
+
+describe "Set#filter!" do
+ it "is an alias of Set#select!" do
+ Set.instance_method(:filter!).should == Set.instance_method(:select!)
+ end
+end
diff --git a/spec/ruby/core/set/fixtures/set_like.rb b/spec/ruby/core/set/fixtures/set_like.rb
new file mode 100644
index 0000000000..86dec2ed52
--- /dev/null
+++ b/spec/ruby/core/set/fixtures/set_like.rb
@@ -0,0 +1,30 @@
+
+module SetSpecs
+ # This class is used to test the interaction of "Set-like" objects with real Sets
+ #
+ # These "Set-like" objects reply to is_a?(Set) with true and thus real Set objects are able to transparently
+ # interoperate with them in a duck-typing manner.
+ class SetLike
+ include Enumerable
+
+ def is_a?(klass)
+ super || klass == ::Set
+ end
+
+ def initialize(entries)
+ @entries = entries
+ end
+
+ def each(&block)
+ @entries.each(&block)
+ end
+
+ def inspect
+ "#<#{self.class}: {#{map(&:inspect).join(", ")}}>"
+ end
+
+ def size
+ @entries.size
+ end
+ end
+end
diff --git a/spec/ruby/core/set/flatten_merge_spec.rb b/spec/ruby/core/set/flatten_merge_spec.rb
new file mode 100644
index 0000000000..3904d969ae
--- /dev/null
+++ b/spec/ruby/core/set/flatten_merge_spec.rb
@@ -0,0 +1,24 @@
+require_relative '../../spec_helper'
+
+describe "Set#flatten_merge" do
+ ruby_version_is ""..."4.0" do
+ it "is protected" do
+ Set.protected_instance_methods(false).should.include?(:flatten_merge)
+ end
+
+ it "flattens the passed Set and merges it into self" do
+ set1 = Set[1, 2]
+ set2 = Set[3, 4, Set[5, 6]]
+
+ set1.send(:flatten_merge, set2).should == Set[1, 2, 3, 4, 5, 6]
+ end
+
+ it "raises an ArgumentError when trying to flatten a recursive Set" do
+ set1 = Set[1, 2, 3]
+ set2 = Set[5, 6, 7]
+ set2 << set2
+
+ -> { set1.send(:flatten_merge, set2) }.should.raise(ArgumentError)
+ end
+ end
+end
diff --git a/spec/ruby/core/set/flatten_spec.rb b/spec/ruby/core/set/flatten_spec.rb
new file mode 100644
index 0000000000..ca6323fac8
--- /dev/null
+++ b/spec/ruby/core/set/flatten_spec.rb
@@ -0,0 +1,49 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/set_like'
+set_version = defined?(Set::VERSION) ? Set::VERSION : '1.0.0'
+
+describe "Set#flatten" do
+ it "returns a copy of self with each included Set flattened" do
+ set = Set[1, 2, Set[3, 4, Set[5, 6, Set[7, 8]]], 9, 10]
+ flattened_set = set.flatten
+
+ flattened_set.should_not.equal?(set)
+ flattened_set.should == Set[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
+ end
+
+ it "raises an ArgumentError when self is recursive" do
+ (set = Set[]) << set
+ -> { set.flatten }.should.raise(ArgumentError)
+ end
+
+ ruby_version_is ""..."4.0" do
+ context "when Set contains a Set-like object" do
+ it "returns a copy of self with each included Set-like object flattened" do
+ Set[SetSpecs::SetLike.new([1])].flatten.should == Set[1]
+ end
+ end
+ end
+end
+
+describe "Set#flatten!" do
+ it "flattens self" do
+ set = Set[1, 2, Set[3, 4, Set[5, 6, Set[7, 8]]], 9, 10]
+ set.flatten!
+ set.should == Set[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
+ end
+
+ it "returns self when self was modified" do
+ set = Set[1, 2, Set[3, 4]]
+ set.flatten!.should.equal?(set)
+ end
+
+ it "returns nil when self was not modified" do
+ set = Set[1, 2, 3, 4]
+ set.flatten!.should == nil
+ end
+
+ it "raises an ArgumentError when self is recursive" do
+ (set = Set[]) << set
+ -> { set.flatten! }.should.raise(ArgumentError)
+ end
+end
diff --git a/spec/ruby/core/set/gt_spec.rb b/spec/ruby/core/set/gt_spec.rb
new file mode 100644
index 0000000000..8a7e421e40
--- /dev/null
+++ b/spec/ruby/core/set/gt_spec.rb
@@ -0,0 +1,7 @@
+require_relative '../../spec_helper'
+
+describe "Set#>" do
+ it "is an alias of Set#proper_superset?" do
+ Set.instance_method(:>).should == Set.instance_method(:proper_superset?)
+ end
+end
diff --git a/spec/ruby/core/set/gte_spec.rb b/spec/ruby/core/set/gte_spec.rb
new file mode 100644
index 0000000000..e98c3cb1e2
--- /dev/null
+++ b/spec/ruby/core/set/gte_spec.rb
@@ -0,0 +1,7 @@
+require_relative '../../spec_helper'
+
+describe "Set#>=" do
+ it "is an alias of Set#superset?" do
+ Set.instance_method(:>=).should == Set.instance_method(:superset?)
+ end
+end
diff --git a/spec/ruby/core/set/hash_spec.rb b/spec/ruby/core/set/hash_spec.rb
new file mode 100644
index 0000000000..63a0aa66a5
--- /dev/null
+++ b/spec/ruby/core/set/hash_spec.rb
@@ -0,0 +1,19 @@
+require_relative '../../spec_helper'
+
+describe "Set#hash" do
+ it "is static" do
+ Set[].hash.should == Set[].hash
+ Set[1, 2, 3].hash.should == Set[1, 2, 3].hash
+ Set[:a, "b", ?c].hash.should == Set[?c, "b", :a].hash
+
+ Set[].hash.should_not == Set[1, 2, 3].hash
+ Set[1, 2, 3].hash.should_not == Set[:a, "b", ?c].hash
+ end
+
+ ruby_version_is ""..."4.0" do
+ # see https://github.com/jruby/jruby/issues/8393
+ it "is equal to nil.hash for an uninitialized Set" do
+ Set.allocate.hash.should == nil.hash
+ end
+ end
+end
diff --git a/spec/ruby/core/set/include_spec.rb b/spec/ruby/core/set/include_spec.rb
new file mode 100644
index 0000000000..92a6ca04e6
--- /dev/null
+++ b/spec/ruby/core/set/include_spec.rb
@@ -0,0 +1,31 @@
+require_relative '../../spec_helper'
+
+describe "Set#include?" do
+ it "returns true when self contains the passed Object" do
+ set = Set[:a, :b, :c]
+ set.include?(:a).should == true
+ set.include?(:e).should == false
+ end
+
+ describe "member equality" do
+ it "is checked using both #hash and #eql?" do
+ obj = Object.new
+ obj_another = Object.new
+
+ def obj.hash; 42 end
+ def obj_another.hash; 42 end
+ def obj_another.eql?(o) hash == o.hash end
+
+ set = Set["a", "b", "c", obj]
+ set.include?(obj_another).should == true
+ end
+
+ it "is not checked using #==" do
+ obj = Object.new
+ set = Set["a", "b", "c"]
+
+ obj.should_not_receive(:==)
+ set.include?(obj)
+ end
+ end
+end
diff --git a/spec/ruby/core/set/initialize_clone_spec.rb b/spec/ruby/core/set/initialize_clone_spec.rb
new file mode 100644
index 0000000000..13abb7ee4e
--- /dev/null
+++ b/spec/ruby/core/set/initialize_clone_spec.rb
@@ -0,0 +1,15 @@
+require_relative '../../spec_helper'
+
+describe "Set#initialize_clone" do
+ # See https://bugs.ruby-lang.org/issues/14266
+ it "does not freeze the new Set when called from clone(freeze: false)" do
+ set1 = Set[1, 2]
+ set1.freeze
+ set2 = set1.clone(freeze: false)
+ set1.frozen?.should == true
+ set2.frozen?.should == false
+ set2.add 3
+ set1.should == Set[1, 2]
+ set2.should == Set[1, 2, 3]
+ end
+end
diff --git a/spec/ruby/core/set/initialize_spec.rb b/spec/ruby/core/set/initialize_spec.rb
new file mode 100644
index 0000000000..45538b38fb
--- /dev/null
+++ b/spec/ruby/core/set/initialize_spec.rb
@@ -0,0 +1,88 @@
+require_relative '../../spec_helper'
+
+describe "Set#initialize" do
+ it "is private" do
+ Set.private_instance_methods(false).should.include?(:initialize)
+ end
+
+ it "adds all elements of the passed Enumerable to self" do
+ s = Set.new([1, 2, 3])
+ s.size.should.eql?(3)
+ s.should.include?(1)
+ s.should.include?(2)
+ s.should.include?(3)
+ end
+
+ it "uses #each_entry on the provided Enumerable" do
+ enumerable = MockObject.new('mock-enumerable')
+ enumerable.should_receive(:each_entry).and_yield(1).and_yield(2).and_yield(3)
+ s = Set.new(enumerable)
+ s.size.should.eql?(3)
+ s.should.include?(1)
+ s.should.include?(2)
+ s.should.include?(3)
+ end
+
+ it "uses #each on the provided Enumerable if it does not respond to #each_entry" do
+ enumerable = MockObject.new('mock-enumerable')
+ enumerable.should_receive(:each).and_yield(1).and_yield(2).and_yield(3)
+ s = Set.new(enumerable)
+ s.size.should.eql?(3)
+ s.should.include?(1)
+ s.should.include?(2)
+ s.should.include?(3)
+ end
+
+ it "raises if the provided Enumerable does not respond to #each_entry or #each" do
+ enumerable = MockObject.new('mock-enumerable')
+ -> { Set.new(enumerable) }.should.raise(ArgumentError, "value must be enumerable")
+ end
+
+ it "should initialize with empty array and set" do
+ s = Set.new([])
+ s.size.should.eql?(0)
+
+ s = Set.new({})
+ s.size.should.eql?(0)
+ end
+
+ it "preprocesses all elements by a passed block before adding to self" do
+ s = Set.new([1, 2, 3]) { |x| x * x }
+ s.size.should.eql?(3)
+ s.should.include?(1)
+ s.should.include?(4)
+ s.should.include?(9)
+ end
+
+ it "should initialize with empty array and block" do
+ s = Set.new([]) { |x| x * x }
+ s.size.should.eql?(0)
+ end
+
+ it "should initialize with empty set and block" do
+ s = Set.new(Set.new) { |x| x * x }
+ s.size.should.eql?(0)
+ end
+
+ it "should initialize with set" do
+ o = Set.new([1, 2])
+ s = Set.new(o)
+ s.size.should.eql?(2)
+ s.should.include?(1)
+ s.should.include?(2)
+ end
+
+ it "should initialize with set and block" do
+ o = Set.new([1, 2])
+ s = Set.new(o) { |e| e + 2 }
+ s.size.should.eql?(2)
+ s.should.include?(3)
+ s.should.include?(4)
+ end
+
+ it "should initialize with just block" do
+ s = Set.new { |x| x * x }
+ s.size.should.eql?(0)
+ s.should.eql?(Set.new)
+ end
+end
diff --git a/spec/ruby/core/set/inspect_spec.rb b/spec/ruby/core/set/inspect_spec.rb
new file mode 100644
index 0000000000..45aeed280e
--- /dev/null
+++ b/spec/ruby/core/set/inspect_spec.rb
@@ -0,0 +1,7 @@
+require_relative '../../spec_helper'
+
+describe "Set#inspect" do
+ it "is an alias of Set#to_s" do
+ Set.instance_method(:inspect).should == Set.instance_method(:to_s)
+ end
+end
diff --git a/spec/ruby/core/set/intersect_spec.rb b/spec/ruby/core/set/intersect_spec.rb
new file mode 100644
index 0000000000..d04a1af441
--- /dev/null
+++ b/spec/ruby/core/set/intersect_spec.rb
@@ -0,0 +1,22 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/set_like'
+
+describe "Set#intersect?" do
+ it "returns true when two Sets have at least one element in common" do
+ Set[1, 2].intersect?(Set[2, 3]).should == true
+ end
+
+ it "returns false when two Sets have no element in common" do
+ Set[1, 2].intersect?(Set[3, 4]).should == false
+ end
+
+ context "when comparing to a Set-like object" do
+ it "returns true when a Set has at least one element in common with a Set-like object" do
+ Set[1, 2].intersect?(SetSpecs::SetLike.new([2, 3])).should == true
+ end
+
+ it "returns false when a Set has no element in common with a Set-like object" do
+ Set[1, 2].intersect?(SetSpecs::SetLike.new([3, 4])).should == false
+ end
+ end
+end
diff --git a/spec/ruby/core/set/intersection_spec.rb b/spec/ruby/core/set/intersection_spec.rb
new file mode 100644
index 0000000000..c14e1f62ad
--- /dev/null
+++ b/spec/ruby/core/set/intersection_spec.rb
@@ -0,0 +1,23 @@
+require_relative '../../spec_helper'
+
+describe "Set#intersection" do
+ it "is an alias of Set#&" do
+ Set.instance_method(:intersection).should == Set.instance_method(:&)
+ end
+end
+
+describe "Set#&" do
+ before :each do
+ @set = Set[:a, :b, :c]
+ end
+
+ it "returns a new Set containing only elements shared by self and the passed Enumerable" do
+ (@set & Set[:b, :c, :d, :e]).should == Set[:b, :c]
+ (@set & [:b, :c, :d]).should == Set[:b, :c]
+ end
+
+ it "raises an ArgumentError when passed a non-Enumerable" do
+ -> { @set & 1 }.should.raise(ArgumentError)
+ -> { @set & Object.new }.should.raise(ArgumentError)
+ end
+end
diff --git a/spec/ruby/core/set/join_spec.rb b/spec/ruby/core/set/join_spec.rb
new file mode 100644
index 0000000000..1c1e8a8af8
--- /dev/null
+++ b/spec/ruby/core/set/join_spec.rb
@@ -0,0 +1,30 @@
+require_relative '../../spec_helper'
+
+describe "Set#join" do
+ it "returns an empty string if the Set is empty" do
+ Set[].join.should == ''
+ end
+
+ it "returns a new string formed by joining elements after conversion" do
+ set = Set[:a, :b, :c]
+ set.join.should == "abc"
+ end
+
+ it "does not separate elements when the passed separator is nil" do
+ set = Set[:a, :b, :c]
+ set.join(nil).should == "abc"
+ end
+
+ it "returns a string formed by concatenating each element separated by the separator" do
+ set = Set[:a, :b, :c]
+ set.join(' | ').should == "a | b | c"
+ end
+
+ ruby_version_is ""..."4.0" do
+ it "calls #to_a to convert the Set in to an Array" do
+ set = Set[:a, :b, :c]
+ set.should_receive(:to_a).and_return([:a, :b, :c])
+ set.join.should == "abc"
+ end
+ end
+end
diff --git a/spec/ruby/core/set/keep_if_spec.rb b/spec/ruby/core/set/keep_if_spec.rb
new file mode 100644
index 0000000000..7ca5d0cd43
--- /dev/null
+++ b/spec/ruby/core/set/keep_if_spec.rb
@@ -0,0 +1,37 @@
+require_relative '../../spec_helper'
+
+describe "Set#keep_if" do
+ before :each do
+ @set = Set["one", "two", "three"]
+ end
+
+ it "yields every element of self" do
+ ret = []
+ @set.keep_if { |x| ret << x }
+ ret.sort.should == ["one", "two", "three"].sort
+ end
+
+ it "keeps every element from self for which the passed block returns true" do
+ @set.keep_if { |x| x.size != 3 }
+ @set.size.should.eql?(1)
+
+ @set.should_not.include?("one")
+ @set.should_not.include?("two")
+ @set.should.include?("three")
+ end
+
+ it "returns self" do
+ @set.keep_if {}.should.equal?(@set)
+ end
+
+ it "returns an Enumerator when passed no block" do
+ enum = @set.keep_if
+ enum.should.instance_of?(Enumerator)
+
+ enum.each { |x| x.size != 3 }
+
+ @set.should_not.include?("one")
+ @set.should_not.include?("two")
+ @set.should.include?("three")
+ end
+end
diff --git a/spec/ruby/core/set/length_spec.rb b/spec/ruby/core/set/length_spec.rb
new file mode 100644
index 0000000000..9b0d3622b8
--- /dev/null
+++ b/spec/ruby/core/set/length_spec.rb
@@ -0,0 +1,7 @@
+require_relative '../../spec_helper'
+
+describe "Set#length" do
+ it "is an alias of Set#size" do
+ Set.instance_method(:length).should == Set.instance_method(:size)
+ end
+end
diff --git a/spec/ruby/core/set/lt_spec.rb b/spec/ruby/core/set/lt_spec.rb
new file mode 100644
index 0000000000..0f5bc9c642
--- /dev/null
+++ b/spec/ruby/core/set/lt_spec.rb
@@ -0,0 +1,7 @@
+require_relative '../../spec_helper'
+
+describe "Set#<" do
+ it "is an alias of Set#proper_subset?" do
+ Set.instance_method(:<).should == Set.instance_method(:proper_subset?)
+ end
+end
diff --git a/spec/ruby/core/set/lte_spec.rb b/spec/ruby/core/set/lte_spec.rb
new file mode 100644
index 0000000000..291d582240
--- /dev/null
+++ b/spec/ruby/core/set/lte_spec.rb
@@ -0,0 +1,7 @@
+require_relative '../../spec_helper'
+
+describe "Set#<=" do
+ it "is an alias of Set#subset?" do
+ Set.instance_method(:<=).should == Set.instance_method(:subset?)
+ end
+end
diff --git a/spec/ruby/core/set/map_spec.rb b/spec/ruby/core/set/map_spec.rb
new file mode 100644
index 0000000000..fd04a8bde1
--- /dev/null
+++ b/spec/ruby/core/set/map_spec.rb
@@ -0,0 +1,22 @@
+require_relative '../../spec_helper'
+
+describe "Set#map!" do
+ before :each do
+ @set = Set[1, 2, 3, 4, 5]
+ end
+
+ it "yields each Object in self" do
+ res = []
+ @set.map! { |x| res << x }
+ res.sort.should == [1, 2, 3, 4, 5].sort
+ end
+
+ it "returns self" do
+ @set.map! { |x| x }.should.equal?(@set)
+ end
+
+ it "replaces self with the return values of the block" do
+ @set.map! { |x| x * 2 }
+ @set.should == Set[2, 4, 6, 8, 10]
+ end
+end
diff --git a/spec/ruby/core/set/member_spec.rb b/spec/ruby/core/set/member_spec.rb
new file mode 100644
index 0000000000..a36308eec7
--- /dev/null
+++ b/spec/ruby/core/set/member_spec.rb
@@ -0,0 +1,7 @@
+require_relative '../../spec_helper'
+
+describe "Set#member?" do
+ it "is an alias of Set#include?" do
+ Set.instance_method(:member?).should == Set.instance_method(:include?)
+ end
+end
diff --git a/spec/ruby/core/set/merge_spec.rb b/spec/ruby/core/set/merge_spec.rb
new file mode 100644
index 0000000000..a2c1a7e706
--- /dev/null
+++ b/spec/ruby/core/set/merge_spec.rb
@@ -0,0 +1,29 @@
+require_relative '../../spec_helper'
+
+describe "Set#merge" do
+ it "adds the elements of the passed Enumerable to self" do
+ Set[:a, :b].merge(Set[:b, :c, :d]).should == Set[:a, :b, :c, :d]
+ Set[1, 2].merge([3, 4]).should == Set[1, 2, 3, 4]
+ end
+
+ it "returns self" do
+ set = Set[1, 2]
+ set.merge([3, 4]).should.equal?(set)
+ end
+
+ it "raises an ArgumentError when passed a non-Enumerable" do
+ -> { Set[1, 2].merge(1) }.should.raise(ArgumentError)
+ -> { Set[1, 2].merge(Object.new) }.should.raise(ArgumentError)
+ end
+
+ it "raises RuntimeError when called during iteration" do
+ set = Set[:a, :b]
+ set.each do |_m|
+ -> { set.merge([1, 2]) }.should.raise(RuntimeError, /iteration/)
+ end
+ end
+
+ it "accepts multiple arguments" do
+ Set[:a, :b].merge(Set[:b, :c], [:d]).should == Set[:a, :b, :c, :d]
+ end
+end
diff --git a/spec/ruby/core/set/minus_spec.rb b/spec/ruby/core/set/minus_spec.rb
new file mode 100644
index 0000000000..8574708559
--- /dev/null
+++ b/spec/ruby/core/set/minus_spec.rb
@@ -0,0 +1,17 @@
+require_relative '../../spec_helper'
+
+describe "Set#-" do
+ before :each do
+ @set = Set[:a, :b, :c]
+ end
+
+ it "returns a new Set containing self's elements excluding the elements in the passed Enumerable" do
+ (@set - Set[:a, :b]).should == Set[:c]
+ (@set - [:b, :c]).should == Set[:a]
+ end
+
+ it "raises an ArgumentError when passed a non-Enumerable" do
+ -> { @set - 1 }.should.raise(ArgumentError)
+ -> { @set - Object.new }.should.raise(ArgumentError)
+ end
+end
diff --git a/spec/ruby/core/set/plus_spec.rb b/spec/ruby/core/set/plus_spec.rb
new file mode 100644
index 0000000000..839f77fc39
--- /dev/null
+++ b/spec/ruby/core/set/plus_spec.rb
@@ -0,0 +1,7 @@
+require_relative '../../spec_helper'
+
+describe "Set#+" do
+ it "is an alias of Set#|" do
+ Set.instance_method(:+).should == Set.instance_method(:|)
+ end
+end
diff --git a/spec/ruby/core/set/pretty_print_cycle_spec.rb b/spec/ruby/core/set/pretty_print_cycle_spec.rb
new file mode 100644
index 0000000000..7e6017c112
--- /dev/null
+++ b/spec/ruby/core/set/pretty_print_cycle_spec.rb
@@ -0,0 +1,14 @@
+require_relative '../../spec_helper'
+
+describe "Set#pretty_print_cycle" do
+ it "passes the 'pretty print' representation of a self-referencing Set to the pretty print writer" do
+ pp = mock("PrettyPrint")
+ ruby_version_is(""..."4.0") do
+ pp.should_receive(:text).with("#<Set: {...}>")
+ end
+ ruby_version_is("4.0") do
+ pp.should_receive(:text).with("Set[...]")
+ end
+ Set[1, 2, 3].pretty_print_cycle(pp)
+ end
+end
diff --git a/spec/ruby/core/set/proper_subset_spec.rb b/spec/ruby/core/set/proper_subset_spec.rb
new file mode 100644
index 0000000000..3fd27da131
--- /dev/null
+++ b/spec/ruby/core/set/proper_subset_spec.rb
@@ -0,0 +1,35 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/set_like'
+set_version = defined?(Set::VERSION) ? Set::VERSION : '1.0.0'
+
+describe "Set#proper_subset?" do
+ before :each do
+ @set = Set[1, 2, 3, 4]
+ end
+
+ it "returns true if passed a Set that self is a proper subset of" do
+ Set[].proper_subset?(@set).should == true
+ Set[].proper_subset?(Set[1, 2, 3]).should == true
+ Set[].proper_subset?(Set["a", :b, ?c]).should == true
+
+ Set[1, 2, 3].proper_subset?(@set).should == true
+ Set[1, 3].proper_subset?(@set).should == true
+ Set[1, 2].proper_subset?(@set).should == true
+ Set[1].proper_subset?(@set).should == true
+
+ Set[5].proper_subset?(@set).should == false
+ Set[1, 5].proper_subset?(@set).should == false
+ Set[nil].proper_subset?(@set).should == false
+ Set["test"].proper_subset?(@set).should == false
+
+ @set.proper_subset?(@set).should == false
+ Set[].proper_subset?(Set[]).should == false
+ end
+
+ it "raises an ArgumentError when passed a non-Set" do
+ -> { Set[].proper_subset?([]) }.should.raise(ArgumentError)
+ -> { Set[].proper_subset?(1) }.should.raise(ArgumentError)
+ -> { Set[].proper_subset?("test") }.should.raise(ArgumentError)
+ -> { Set[].proper_subset?(Object.new) }.should.raise(ArgumentError)
+ end
+end
diff --git a/spec/ruby/core/set/proper_superset_spec.rb b/spec/ruby/core/set/proper_superset_spec.rb
new file mode 100644
index 0000000000..e95c67ef0e
--- /dev/null
+++ b/spec/ruby/core/set/proper_superset_spec.rb
@@ -0,0 +1,42 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/set_like'
+
+describe "Set#proper_superset?" do
+ before :each do
+ @set = Set[1, 2, 3, 4]
+ end
+
+ it "returns true if passed a Set that self is a proper superset of" do
+ @set.proper_superset?(Set[]).should == true
+ Set[1, 2, 3].proper_superset?(Set[]).should == true
+ Set["a", :b, ?c].proper_superset?(Set[]).should == true
+
+ @set.proper_superset?(Set[1, 2, 3]).should == true
+ @set.proper_superset?(Set[1, 3]).should == true
+ @set.proper_superset?(Set[1, 2]).should == true
+ @set.proper_superset?(Set[1]).should == true
+
+ @set.proper_superset?(Set[5]).should == false
+ @set.proper_superset?(Set[1, 5]).should == false
+ @set.proper_superset?(Set[nil]).should == false
+ @set.proper_superset?(Set["test"]).should == false
+
+ @set.proper_superset?(@set).should == false
+ Set[].proper_superset?(Set[]).should == false
+ end
+
+ it "raises an ArgumentError when passed a non-Set" do
+ -> { Set[].proper_superset?([]) }.should.raise(ArgumentError)
+ -> { Set[].proper_superset?(1) }.should.raise(ArgumentError)
+ -> { Set[].proper_superset?("test") }.should.raise(ArgumentError)
+ -> { Set[].proper_superset?(Object.new) }.should.raise(ArgumentError)
+ end
+
+ ruby_version_is ""..."4.0" do
+ context "when comparing to a Set-like object" do
+ it "returns true if passed a Set-like object that self is a proper superset of" do
+ Set[1, 2, 3, 4].proper_superset?(SetSpecs::SetLike.new([1, 2, 3])).should == true
+ end
+ end
+ end
+end
diff --git a/spec/ruby/core/set/reject_spec.rb b/spec/ruby/core/set/reject_spec.rb
new file mode 100644
index 0000000000..b00a36812b
--- /dev/null
+++ b/spec/ruby/core/set/reject_spec.rb
@@ -0,0 +1,41 @@
+require_relative '../../spec_helper'
+
+describe "Set#reject!" do
+ before :each do
+ @set = Set["one", "two", "three"]
+ end
+
+ it "yields every element of self" do
+ ret = []
+ @set.reject! { |x| ret << x }
+ ret.sort.should == ["one", "two", "three"].sort
+ end
+
+ it "deletes every element from self for which the passed block returns true" do
+ @set.reject! { |x| x.size == 3 }
+ @set.size.should.eql?(1)
+
+ @set.should_not.include?("one")
+ @set.should_not.include?("two")
+ @set.should.include?("three")
+ end
+
+ it "returns self when self was modified" do
+ @set.reject! { |x| true }.should.equal?(@set)
+ end
+
+ it "returns nil when self was not modified" do
+ @set.reject! { |x| false }.should == nil
+ end
+
+ it "returns an Enumerator when passed no block" do
+ enum = @set.reject!
+ enum.should.instance_of?(Enumerator)
+
+ enum.each { |x| x.size == 3 }
+
+ @set.should_not.include?("one")
+ @set.should_not.include?("two")
+ @set.should.include?("three")
+ end
+end
diff --git a/spec/ruby/core/set/replace_spec.rb b/spec/ruby/core/set/replace_spec.rb
new file mode 100644
index 0000000000..2a51a024dc
--- /dev/null
+++ b/spec/ruby/core/set/replace_spec.rb
@@ -0,0 +1,24 @@
+require_relative '../../spec_helper'
+
+describe "Set#replace" do
+ before :each do
+ @set = Set[:a, :b, :c]
+ end
+
+ it "replaces the contents with other and returns self" do
+ @set.replace(Set[1, 2, 3]).should == @set
+ @set.should == Set[1, 2, 3]
+ end
+
+ it "raises RuntimeError when called during iteration" do
+ set = Set[:a, :b, :c, :d, :e, :f]
+ set.each do |_m|
+ -> { set.replace(Set[1, 2, 3]) }.should.raise(RuntimeError, /iteration/)
+ end
+ set.should == Set[:a, :b, :c, :d, :e, :f]
+ end
+
+ it "accepts any enumerable as other" do
+ @set.replace([1, 2, 3]).should == Set[1, 2, 3]
+ end
+end
diff --git a/spec/ruby/core/set/select_spec.rb b/spec/ruby/core/set/select_spec.rb
new file mode 100644
index 0000000000..619194605b
--- /dev/null
+++ b/spec/ruby/core/set/select_spec.rb
@@ -0,0 +1,41 @@
+require_relative '../../spec_helper'
+
+describe "Set#select!" do
+ before :each do
+ @set = Set["one", "two", "three"]
+ end
+
+ it "yields every element of self" do
+ ret = []
+ @set.select! { |x| ret << x }
+ ret.sort.should == ["one", "two", "three"].sort
+ end
+
+ it "keeps every element from self for which the passed block returns true" do
+ @set.select! { |x| x.size != 3 }
+ @set.size.should.eql?(1)
+
+ @set.should_not.include?("one")
+ @set.should_not.include?("two")
+ @set.should.include?("three")
+ end
+
+ it "returns self when self was modified" do
+ @set.select! { false }.should.equal?(@set)
+ end
+
+ it "returns nil when self was not modified" do
+ @set.select! { true }.should == nil
+ end
+
+ it "returns an Enumerator when passed no block" do
+ enum = @set.select!
+ enum.should.instance_of?(Enumerator)
+
+ enum.each { |x| x.size != 3 }
+
+ @set.should_not.include?("one")
+ @set.should_not.include?("two")
+ @set.should.include?("three")
+ end
+end
diff --git a/spec/ruby/core/set/set_spec.rb b/spec/ruby/core/set/set_spec.rb
new file mode 100644
index 0000000000..fd1d2072e3
--- /dev/null
+++ b/spec/ruby/core/set/set_spec.rb
@@ -0,0 +1,10 @@
+require_relative '../../spec_helper'
+
+describe 'Set' do
+ it 'is available without explicit requiring' do
+ output = ruby_exe(<<~RUBY, options: '--disable-gems', args: '2>&1')
+ puts Set.new([1, 2, 3]).to_a.inspect
+ RUBY
+ output.chomp.should == "[1, 2, 3]"
+ end
+end
diff --git a/spec/ruby/core/set/size_spec.rb b/spec/ruby/core/set/size_spec.rb
new file mode 100644
index 0000000000..c57272a235
--- /dev/null
+++ b/spec/ruby/core/set/size_spec.rb
@@ -0,0 +1,8 @@
+require_relative '../../spec_helper'
+
+describe "Set#size" do
+ it "returns the number of elements in the set" do
+ set = Set[:a, :b, :c]
+ set.size.should == 3
+ end
+end
diff --git a/spec/ruby/core/set/sortedset/sortedset_spec.rb b/spec/ruby/core/set/sortedset/sortedset_spec.rb
new file mode 100644
index 0000000000..c8f65f0851
--- /dev/null
+++ b/spec/ruby/core/set/sortedset/sortedset_spec.rb
@@ -0,0 +1,13 @@
+require_relative '../../../spec_helper'
+
+describe "SortedSet" do
+ ruby_version_is ""..."4.0" do
+ it "raises error including message that it has been extracted from the set stdlib" do
+ -> {
+ SortedSet
+ }.should.raise(RuntimeError) { |e|
+ e.message.should.include?("The `SortedSet` class has been extracted from the `set` library")
+ }
+ end
+ end
+end
diff --git a/spec/ruby/core/set/subset_spec.rb b/spec/ruby/core/set/subset_spec.rb
new file mode 100644
index 0000000000..81869d4993
--- /dev/null
+++ b/spec/ruby/core/set/subset_spec.rb
@@ -0,0 +1,35 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/set_like'
+set_version = defined?(Set::VERSION) ? Set::VERSION : '1.0.0'
+
+describe "Set#subset?" do
+ before :each do
+ @set = Set[1, 2, 3, 4]
+ end
+
+ it "returns true if passed a Set that is equal to self or self is a subset of" do
+ @set.subset?(@set).should == true
+ Set[].subset?(Set[]).should == true
+
+ Set[].subset?(@set).should == true
+ Set[].subset?(Set[1, 2, 3]).should == true
+ Set[].subset?(Set["a", :b, ?c]).should == true
+
+ Set[1, 2, 3].subset?(@set).should == true
+ Set[1, 3].subset?(@set).should == true
+ Set[1, 2].subset?(@set).should == true
+ Set[1].subset?(@set).should == true
+
+ Set[5].subset?(@set).should == false
+ Set[1, 5].subset?(@set).should == false
+ Set[nil].subset?(@set).should == false
+ Set["test"].subset?(@set).should == false
+ end
+
+ it "raises an ArgumentError when passed a non-Set" do
+ -> { Set[].subset?([]) }.should.raise(ArgumentError)
+ -> { Set[].subset?(1) }.should.raise(ArgumentError)
+ -> { Set[].subset?("test") }.should.raise(ArgumentError)
+ -> { Set[].subset?(Object.new) }.should.raise(ArgumentError)
+ end
+end
diff --git a/spec/ruby/core/set/subtract_spec.rb b/spec/ruby/core/set/subtract_spec.rb
new file mode 100644
index 0000000000..ae4bc73d41
--- /dev/null
+++ b/spec/ruby/core/set/subtract_spec.rb
@@ -0,0 +1,16 @@
+require_relative '../../spec_helper'
+
+describe "Set#subtract" do
+ before :each do
+ @set = Set[:a, :b, :c]
+ end
+
+ it "deletes any elements contained in other and returns self" do
+ @set.subtract(Set[:b, :c]).should == @set
+ @set.should == Set[:a]
+ end
+
+ it "accepts any enumerable as other" do
+ @set.subtract([:c]).should == Set[:a, :b]
+ end
+end
diff --git a/spec/ruby/core/set/superset_spec.rb b/spec/ruby/core/set/superset_spec.rb
new file mode 100644
index 0000000000..7e7db2b179
--- /dev/null
+++ b/spec/ruby/core/set/superset_spec.rb
@@ -0,0 +1,42 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/set_like'
+
+describe "Set#superset?" do
+ before :each do
+ @set = Set[1, 2, 3, 4]
+ end
+
+ it "returns true if passed a Set that equals self or self is a proper superset of" do
+ @set.superset?(@set).should == true
+ Set[].superset?(Set[]).should == true
+
+ @set.superset?(Set[]).should == true
+ Set[1, 2, 3].superset?(Set[]).should == true
+ Set["a", :b, ?c].superset?(Set[]).should == true
+
+ @set.superset?(Set[1, 2, 3]).should == true
+ @set.superset?(Set[1, 3]).should == true
+ @set.superset?(Set[1, 2]).should == true
+ @set.superset?(Set[1]).should == true
+
+ @set.superset?(Set[5]).should == false
+ @set.superset?(Set[1, 5]).should == false
+ @set.superset?(Set[nil]).should == false
+ @set.superset?(Set["test"]).should == false
+ end
+
+ it "raises an ArgumentError when passed a non-Set" do
+ -> { Set[].superset?([]) }.should.raise(ArgumentError)
+ -> { Set[].superset?(1) }.should.raise(ArgumentError)
+ -> { Set[].superset?("test") }.should.raise(ArgumentError)
+ -> { Set[].superset?(Object.new) }.should.raise(ArgumentError)
+ end
+
+ ruby_version_is ""..."4.0" do
+ context "when comparing to a Set-like object" do
+ it "returns true if passed a Set-like object that self is a superset of" do
+ Set[1, 2, 3, 4].superset?(SetSpecs::SetLike.new([1, 2, 3])).should == true
+ end
+ end
+ end
+end
diff --git a/spec/ruby/core/set/to_a_spec.rb b/spec/ruby/core/set/to_a_spec.rb
new file mode 100644
index 0000000000..1e9800167a
--- /dev/null
+++ b/spec/ruby/core/set/to_a_spec.rb
@@ -0,0 +1,7 @@
+require_relative '../../spec_helper'
+
+describe "Set#to_a" do
+ it "returns an array containing elements of self" do
+ Set[1, 2, 3].to_a.sort.should == [1, 2, 3]
+ end
+end
diff --git a/spec/ruby/core/set/to_s_spec.rb b/spec/ruby/core/set/to_s_spec.rb
new file mode 100644
index 0000000000..7f768bdcbf
--- /dev/null
+++ b/spec/ruby/core/set/to_s_spec.rb
@@ -0,0 +1,47 @@
+require_relative "../../spec_helper"
+
+describe "Set#to_s" do
+ it "returns a String representation of self" do
+ Set[].to_s.should.is_a?(String)
+ Set[nil, false, true].to_s.should.is_a?(String)
+ Set[1, 2, 3].to_s.should.is_a?(String)
+ Set["1", "2", "3"].to_s.should.is_a?(String)
+ Set[:a, "b", Set[?c]].to_s.should.is_a?(String)
+ end
+
+ ruby_version_is "4.0" do
+ it "does include the elements of the set" do
+ Set["1"].to_s.should == 'Set["1"]'
+ end
+ end
+
+ ruby_version_is ""..."4.0" do
+ it "does include the elements of the set" do
+ Set["1"].to_s.should == '#<Set: {"1"}>'
+ end
+ end
+
+ it "puts spaces between the elements" do
+ Set["1", "2"].to_s.should.include?('", "')
+ end
+
+ ruby_version_is "4.0" do
+ it "correctly handles cyclic-references" do
+ set1 = Set[]
+ set2 = Set[set1]
+ set1 << set2
+ set1.to_s.should.is_a?(String)
+ set1.to_s.should.include?("Set[...]")
+ end
+ end
+
+ ruby_version_is ""..."4.0" do
+ it "correctly handles cyclic-references" do
+ set1 = Set[]
+ set2 = Set[set1]
+ set1 << set2
+ set1.to_s.should.is_a?(String)
+ set1.to_s.should.include?("#<Set: {...}>")
+ end
+ end
+end
diff --git a/spec/ruby/core/set/union_spec.rb b/spec/ruby/core/set/union_spec.rb
new file mode 100644
index 0000000000..206535aae2
--- /dev/null
+++ b/spec/ruby/core/set/union_spec.rb
@@ -0,0 +1,23 @@
+require_relative '../../spec_helper'
+
+describe "Set#union" do
+ it "is an alias of Set#|" do
+ Set.instance_method(:union).should == Set.instance_method(:|)
+ end
+end
+
+describe "Set#|" do
+ before :each do
+ @set = Set[:a, :b, :c]
+ end
+
+ it "returns a new Set containing all elements of self and the passed Enumerable" do
+ (@set | Set[:b, :d, :e]).should == Set[:a, :b, :c, :d, :e]
+ (@set | [:b, :e]).should == Set[:a, :b, :c, :e]
+ end
+
+ it "raises an ArgumentError when passed a non-Enumerable" do
+ -> { @set | 1 }.should.raise(ArgumentError)
+ -> { @set | Object.new }.should.raise(ArgumentError)
+ end
+end
diff --git a/spec/ruby/core/signal/fixtures/trap_all.rb b/spec/ruby/core/signal/fixtures/trap_all.rb
new file mode 100644
index 0000000000..afa00b498d
--- /dev/null
+++ b/spec/ruby/core/signal/fixtures/trap_all.rb
@@ -0,0 +1,15 @@
+cannot_be_trapped = %w[KILL STOP] # See man 2 signal
+
+(Signal.list.keys - cannot_be_trapped).each do |signal|
+ begin
+ Signal.trap(signal, -> {})
+ rescue ArgumentError => e
+ unless /can't trap reserved signal|Signal already used by VM or OS/ =~ e.message
+ raise e
+ end
+ else
+ Signal.trap(signal, "DEFAULT")
+ end
+end
+
+puts "OK"
diff --git a/spec/ruby/core/signal/list_spec.rb b/spec/ruby/core/signal/list_spec.rb
index 510b671337..56ad6828fe 100644
--- a/spec/ruby/core/signal/list_spec.rb
+++ b/spec/ruby/core/signal/list_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Signal.list" do
RUBY_SIGNALS = %w{
@@ -61,4 +61,8 @@ describe "Signal.list" do
it "includes the EXIT key with a value of zero" do
Signal.list["EXIT"].should == 0
end
+
+ it "includes the KILL key with a value of nine" do
+ Signal.list["KILL"].should == 9
+ end
end
diff --git a/spec/ruby/core/signal/signame_spec.rb b/spec/ruby/core/signal/signame_spec.rb
index 1874a67933..82f040a6f9 100644
--- a/spec/ruby/core/signal/signame_spec.rb
+++ b/spec/ruby/core/signal/signame_spec.rb
@@ -1,23 +1,34 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Signal.signame" do
it "takes a signal name with a well known signal number" do
Signal.signame(0).should == "EXIT"
end
- ruby_version_is "2.0"..."2.3" do
- it "raises an ArgumentError if the argument is an invalid signal number" do
- lambda { Signal.signame(-1) }.should raise_error(ArgumentError)
- end
+ it "returns nil if the argument is an invalid signal number" do
+ Signal.signame(-1).should == nil
end
- ruby_version_is "2.3" do
- it "returns nil if the argument is an invalid signal number" do
- Signal.signame(-1).should == nil
- end
+ it "calls #to_int on an object to convert to an Integer" do
+ obj = mock('signal')
+ obj.should_receive(:to_int).and_return(0)
+ Signal.signame(obj).should == "EXIT"
end
it "raises a TypeError when the passed argument can't be coerced to Integer" do
- lambda { Signal.signame("hello") }.should raise_error(TypeError)
+ -> { Signal.signame("hello") }.should.raise(TypeError)
+ end
+
+ it "raises a TypeError when the passed argument responds to #to_int but does not return an Integer" do
+ obj = mock('signal')
+ obj.should_receive(:to_int).and_return('not an int')
+ -> { Signal.signame(obj) }.should.raise(TypeError)
+ end
+
+ platform_is_not :windows do
+ it "the original should take precedence 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..5d3105fee8 100644
--- a/spec/ruby/core/signal/trap_spec.rb
+++ b/spec/ruby/core/signal/trap_spec.rb
@@ -1,12 +1,12 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
-platform_is_not :windows do
- describe "Signal.trap" do
+describe "Signal.trap" do
+ platform_is_not :windows do
before :each do
ScratchPad.clear
-
- @proc = lambda { ScratchPad.record :proc_trap }
+ @proc = -> {}
@saved_trap = Signal.trap(:HUP, @proc)
+ @hup_number = Signal.list["HUP"]
end
after :each do
@@ -14,13 +14,14 @@ platform_is_not :windows do
end
it "returns the previous handler" do
- Signal.trap(:HUP, @saved_trap).should equal(@proc)
+ Signal.trap(:HUP, @saved_trap).should.equal?(@proc)
end
- it "accepts a block in place of a proc/command argument" do
+ it "accepts a block" do
done = false
- Signal.trap(:HUP) do
+ Signal.trap(:HUP) do |signo|
+ signo.should == @hup_number
ScratchPad.record :block_trap
done = true
end
@@ -31,6 +32,94 @@ platform_is_not :windows do
ScratchPad.recorded.should == :block_trap
end
+ it "accepts a proc" do
+ done = false
+
+ handler = -> signo {
+ signo.should == @hup_number
+ ScratchPad.record :proc_trap
+ done = true
+ }
+
+ Signal.trap(:HUP, handler)
+
+ Process.kill :HUP, Process.pid
+ Thread.pass until done
+
+ ScratchPad.recorded.should == :proc_trap
+ end
+
+ it "accepts a method" do
+ done = false
+
+ handler_class = Class.new
+ hup_number = @hup_number
+
+ handler_class.define_method :handler_method do |signo|
+ signo.should == hup_number
+ ScratchPad.record :method_trap
+ done = true
+ end
+
+ handler_method = handler_class.new.method(:handler_method)
+
+ Signal.trap(:HUP, handler_method)
+
+ Process.kill :HUP, Process.pid
+ Thread.pass until done
+
+ ScratchPad.recorded.should == :method_trap
+ end
+
+ it "accepts anything you can call" do
+ done = false
+
+ callable = Object.new
+ hup_number = @hup_number
+
+ callable.singleton_class.define_method :call do |signo|
+ signo.should == hup_number
+ ScratchPad.record :callable_trap
+ done = true
+ end
+
+ Signal.trap(:HUP, callable)
+
+ Process.kill :HUP, Process.pid
+ Thread.pass until done
+
+ ScratchPad.recorded.should == :callable_trap
+ end
+
+ it "raises an exception for a non-callable at the point of use" do
+ not_callable = Object.new
+ Signal.trap(:HUP, not_callable)
+ -> {
+ Process.kill :HUP, Process.pid
+ loop { Thread.pass }
+ }.should.raise(NoMethodError)
+ end
+
+ it "accepts a non-callable that becomes callable when used" do
+ done = false
+
+ late_callable = Object.new
+ hup_number = @hup_number
+
+ Signal.trap(:HUP, late_callable)
+
+ late_callable.singleton_class.define_method :call do |signo|
+ signo.should == hup_number
+ ScratchPad.record :late_callable_trap
+ done = true
+ end
+
+ Process.kill :HUP, Process.pid
+ Thread.pass until done
+
+ ScratchPad.recorded.should == :late_callable_trap
+ end
+
it "is possible to create a new Thread when the handler runs" do
done = false
@@ -45,91 +134,187 @@ platform_is_not :windows do
Process.kill :HUP, Process.pid
Thread.pass until done
- ScratchPad.recorded.should be_true
+ ScratchPad.recorded.should == true
+ end
+
+ it "registers an handler doing nothing with :IGNORE" do
+ Signal.trap :HUP, :IGNORE
+ Signal.trap(:HUP, @saved_trap).should == "IGNORE"
+ end
+
+ it "can register a new handler after :IGNORE" do
+ Signal.trap :HUP, :IGNORE
+
+ done = false
+ Signal.trap(:HUP) do
+ ScratchPad.record :block_trap
+ done = true
+ end
+
+ Process.kill(:HUP, Process.pid).should == 1
+ Thread.pass until done
+ ScratchPad.recorded.should == :block_trap
end
it "ignores the signal when passed nil" do
Signal.trap :HUP, nil
- Signal.trap(:HUP, @saved_trap).should be_nil
+ Signal.trap(:HUP, @saved_trap).should == nil
end
- it "accepts 'DEFAULT' as a symbol in place of a proc" do
+ it "accepts :DEFAULT in place of a proc" do
Signal.trap :HUP, :DEFAULT
- Signal.trap(:HUP, :DEFAULT).should == "DEFAULT"
+ Signal.trap(:HUP, @saved_trap).should == "DEFAULT"
end
- it "accepts 'SIG_DFL' as a symbol in place of a proc" do
+ it "accepts :SIG_DFL in place of a proc" do
Signal.trap :HUP, :SIG_DFL
- Signal.trap(:HUP, :SIG_DFL).should == "DEFAULT"
+ Signal.trap(:HUP, @saved_trap).should == "DEFAULT"
end
- it "accepts 'SIG_IGN' as a symbol in place of a proc" do
+ it "accepts :SIG_IGN in place of a proc" do
Signal.trap :HUP, :SIG_IGN
- Signal.trap(:HUP, :SIG_IGN).should == "IGNORE"
+ Signal.trap(:HUP, @saved_trap).should == "IGNORE"
end
- it "accepts 'IGNORE' as a symbol in place of a proc" do
+ it "accepts :IGNORE in place of a proc" do
Signal.trap :HUP, :IGNORE
- Signal.trap(:HUP, :IGNORE).should == "IGNORE"
+ Signal.trap(:HUP, @saved_trap).should == "IGNORE"
+ end
+
+ it "accepts 'SIG_DFL' in place of a proc" do
+ Signal.trap :HUP, "SIG_DFL"
+ Signal.trap(:HUP, @saved_trap).should == "DEFAULT"
+ end
+
+ it "accepts 'DEFAULT' in place of a proc" do
+ Signal.trap :HUP, "DEFAULT"
+ Signal.trap(:HUP, @saved_trap).should == "DEFAULT"
+ end
+
+ it "accepts 'SIG_IGN' in place of a proc" do
+ Signal.trap :HUP, "SIG_IGN"
+ Signal.trap(:HUP, @saved_trap).should == "IGNORE"
+ end
+
+ it "accepts 'IGNORE' in place of a proc" do
+ Signal.trap :HUP, "IGNORE"
+ Signal.trap(:HUP, @saved_trap).should == "IGNORE"
end
it "accepts long names as Strings" do
Signal.trap "SIGHUP", @proc
- Signal.trap("SIGHUP", @saved_trap).should equal(@proc)
+ Signal.trap("SIGHUP", @saved_trap).should.equal?(@proc)
end
- it "acceps short names as Strings" do
+ it "accepts short names as Strings" do
Signal.trap "HUP", @proc
- Signal.trap("HUP", @saved_trap).should equal(@proc)
+ Signal.trap("HUP", @saved_trap).should.equal?(@proc)
end
it "accepts long names as Symbols" do
Signal.trap :SIGHUP, @proc
- Signal.trap(:SIGHUP, @saved_trap).should equal(@proc)
+ Signal.trap(:SIGHUP, @saved_trap).should.equal?(@proc)
end
it "accepts short names as Symbols" do
Signal.trap :HUP, @proc
- Signal.trap(:HUP, @saved_trap).should equal(@proc)
+ Signal.trap(:HUP, @saved_trap).should.equal?(@proc)
end
- it "accepts 'SIG_DFL' in place of a proc" do
- Signal.trap :HUP, "SIG_DFL"
- Signal.trap(:HUP, @saved_trap).should == "DEFAULT"
+ it "calls #to_str on an object to convert to a String" do
+ obj = mock("signal")
+ obj.should_receive(:to_str).exactly(2).times.and_return("HUP")
+ Signal.trap obj, @proc
+ Signal.trap(obj, @saved_trap).should.equal?(@proc)
end
- it "accepts 'DEFAULT' in place of a proc" do
- Signal.trap :HUP, "DEFAULT"
- Signal.trap(:HUP, @saved_trap).should == "DEFAULT"
+ it "accepts Integer values" do
+ hup = Signal.list["HUP"]
+ Signal.trap hup, @proc
+ Signal.trap(hup, @saved_trap).should.equal?(@proc)
end
- it "accepts 'SIG_IGN' in place of a proc" do
- Signal.trap :HUP, "SIG_IGN"
- Signal.trap(:HUP, "SIG_IGN").should == "IGNORE"
+ it "does not call #to_int on an object to convert to an Integer" do
+ obj = mock("signal")
+ obj.should_not_receive(:to_int)
+ -> { Signal.trap obj, @proc }.should.raise(ArgumentError, /bad signal type/)
end
- it "accepts 'IGNORE' in place of a proc" do
- Signal.trap :HUP, "IGNORE"
- Signal.trap(:HUP, "IGNORE").should == "IGNORE"
+ it "raises ArgumentError when passed unknown signal" do
+ -> { Signal.trap(300) { } }.should.raise(ArgumentError, "invalid signal number (300)")
+ -> { Signal.trap("USR10") { } }.should.raise(ArgumentError, /\Aunsupported signal [`']SIGUSR10'\z/)
+ -> { Signal.trap("SIGUSR10") { } }.should.raise(ArgumentError, /\Aunsupported signal [`']SIGUSR10'\z/)
+ end
+
+ it "raises ArgumentError when passed signal is not Integer, String or Symbol" do
+ -> { Signal.trap(nil) { } }.should.raise(ArgumentError, "bad signal type NilClass")
+ -> { Signal.trap(100.0) { } }.should.raise(ArgumentError, "bad signal type Float")
+ -> { Signal.trap(Rational(100)) { } }.should.raise(ArgumentError, "bad signal type Rational")
+ end
+
+ # See man 2 signal
+ %w[KILL STOP].each do |signal|
+ it "raises ArgumentError or Errno::EINVAL for SIG#{signal}" do
+ -> {
+ Signal.trap(signal, -> {})
+ }.should.raise(StandardError) { |e|
+ [ArgumentError, Errno::EINVAL].should.include?(e.class)
+ e.message.should =~ /Invalid argument|Signal already used by VM or OS/
+ }
+ end
+ end
+
+ %w[SEGV BUS ILL FPE VTALRM].each do |signal|
+ it "raises ArgumentError for SIG#{signal} which is reserved by Ruby" do
+ -> {
+ Signal.trap(signal, -> {})
+ }.should.raise(ArgumentError, "can't trap reserved signal: SIG#{signal}")
+ end
+ end
+
+ it "allows to register a handler for all known signals, except reserved signals for which it raises ArgumentError" do
+ out = ruby_exe(fixture(__FILE__, "trap_all.rb"), args: "2>&1")
+ out.should == "OK\n"
+ $?.exitstatus.should == 0
+ end
+
+ it "returns 'DEFAULT' for the initial SIGINT handler" do
+ ruby_exe("print Signal.trap(:INT) { abort }").should == 'DEFAULT'
+ end
+
+ it "returns SYSTEM_DEFAULT if passed DEFAULT and no handler was ever set" do
+ Signal.trap("PROF", "DEFAULT").should == "SYSTEM_DEFAULT"
+ end
+
+ it "accepts 'SYSTEM_DEFAULT' and uses the OS handler for SIGPIPE" do
+ code = <<-RUBY
+ p Signal.trap('PIPE', 'SYSTEM_DEFAULT')
+ r, w = IO.pipe
+ r.close
+ loop { w.write("a"*1024) }
+ RUBY
+ out = ruby_exe(code, exit_status: :SIGPIPE)
+ status = $?
+ out.should == "nil\n"
+ status.should.signaled?
end
end
-end
-describe "Signal.trap" do
describe "the special EXIT signal code" do
it "accepts the EXIT code" do
- code = "trap(:EXIT, proc { print 1 })"
+ code = "Signal.trap(:EXIT, proc { print 1 })"
ruby_exe(code).should == "1"
end
it "runs the proc before at_exit handlers" do
- code = "at_exit {print 1}; trap(:EXIT, proc {print 2}); at_exit {print 3}"
+ code = "at_exit {print 1}; Signal.trap(:EXIT, proc {print 2}); at_exit {print 3}"
ruby_exe(code).should == "231"
end
it "can unset the handler" do
- code = "trap(:EXIT, proc { print 1 }); trap(:EXIT, 'DEFAULT')"
+ code = "Signal.trap(:EXIT, proc { print 1 }); Signal.trap(:EXIT, 'DEFAULT')"
ruby_exe(code).should == ""
end
end
+
end
diff --git a/spec/ruby/core/sizedqueue/append_spec.rb b/spec/ruby/core/sizedqueue/append_spec.rb
new file mode 100644
index 0000000000..c52baa3802
--- /dev/null
+++ b/spec/ruby/core/sizedqueue/append_spec.rb
@@ -0,0 +1,16 @@
+require_relative '../../spec_helper'
+require_relative '../../shared/queue/enque'
+require_relative '../../shared/sizedqueue/enque'
+require_relative '../../shared/types/rb_num2dbl_fails'
+
+describe "SizedQueue#<<" do
+ it_behaves_like :queue_enq, :<<, -> { SizedQueue.new(10) }
+end
+
+describe "SizedQueue#<<" do
+ it_behaves_like :sizedqueue_enq, :<<, -> n { SizedQueue.new(n) }
+end
+
+describe "SizedQueue operations with timeout" do
+ it_behaves_like :rb_num2dbl_fails, nil, -> v { q = SizedQueue.new(1); q.send(:<<, 1, timeout: v) }
+end
diff --git a/spec/ruby/core/sizedqueue/clear_spec.rb b/spec/ruby/core/sizedqueue/clear_spec.rb
new file mode 100644
index 0000000000..abae01c6c0
--- /dev/null
+++ b/spec/ruby/core/sizedqueue/clear_spec.rb
@@ -0,0 +1,6 @@
+require_relative '../../spec_helper'
+require_relative '../../shared/queue/clear'
+
+describe "SizedQueue#clear" do
+ it_behaves_like :queue_clear, :clear, -> { SizedQueue.new(10) }
+end
diff --git a/spec/ruby/core/sizedqueue/close_spec.rb b/spec/ruby/core/sizedqueue/close_spec.rb
new file mode 100644
index 0000000000..0e0af851cb
--- /dev/null
+++ b/spec/ruby/core/sizedqueue/close_spec.rb
@@ -0,0 +1,6 @@
+require_relative '../../spec_helper'
+require_relative '../../shared/queue/close'
+
+describe "SizedQueue#close" do
+ it_behaves_like :queue_close, :close, -> { SizedQueue.new(10) }
+end
diff --git a/spec/ruby/core/sizedqueue/closed_spec.rb b/spec/ruby/core/sizedqueue/closed_spec.rb
new file mode 100644
index 0000000000..4b90da1faa
--- /dev/null
+++ b/spec/ruby/core/sizedqueue/closed_spec.rb
@@ -0,0 +1,6 @@
+require_relative '../../spec_helper'
+require_relative '../../shared/queue/closed'
+
+describe "SizedQueue#closed?" do
+ it_behaves_like :queue_closed?, :closed?, -> { SizedQueue.new(10) }
+end
diff --git a/spec/ruby/core/sizedqueue/deq_spec.rb b/spec/ruby/core/sizedqueue/deq_spec.rb
new file mode 100644
index 0000000000..51ff706557
--- /dev/null
+++ b/spec/ruby/core/sizedqueue/deq_spec.rb
@@ -0,0 +1,7 @@
+require_relative '../../spec_helper'
+
+describe "SizedQueue#deq" do
+ it "is an alias of SizedQueue#pop" do
+ SizedQueue.instance_method(:deq).should == SizedQueue.instance_method(:pop)
+ end
+end
diff --git a/spec/ruby/core/sizedqueue/empty_spec.rb b/spec/ruby/core/sizedqueue/empty_spec.rb
new file mode 100644
index 0000000000..9b0d4ff013
--- /dev/null
+++ b/spec/ruby/core/sizedqueue/empty_spec.rb
@@ -0,0 +1,6 @@
+require_relative '../../spec_helper'
+require_relative '../../shared/queue/empty'
+
+describe "SizedQueue#empty?" do
+ it_behaves_like :queue_empty?, :empty?, -> { SizedQueue.new(10) }
+end
diff --git a/spec/ruby/core/sizedqueue/enq_spec.rb b/spec/ruby/core/sizedqueue/enq_spec.rb
new file mode 100644
index 0000000000..94697cd247
--- /dev/null
+++ b/spec/ruby/core/sizedqueue/enq_spec.rb
@@ -0,0 +1,7 @@
+require_relative '../../spec_helper'
+
+describe "SizedQueue#enq" do
+ it "is an alias of SizedQueue#<<" do
+ SizedQueue.instance_method(:enq).should == SizedQueue.instance_method(:<<)
+ end
+end
diff --git a/spec/ruby/core/sizedqueue/freeze_spec.rb b/spec/ruby/core/sizedqueue/freeze_spec.rb
new file mode 100644
index 0000000000..98f01cae2f
--- /dev/null
+++ b/spec/ruby/core/sizedqueue/freeze_spec.rb
@@ -0,0 +1,6 @@
+require_relative '../../spec_helper'
+require_relative '../../shared/queue/freeze'
+
+describe "SizedQueue#freeze" do
+ it_behaves_like :queue_freeze, :freeze, -> { SizedQueue.new(1) }
+end
diff --git a/spec/ruby/core/sizedqueue/length_spec.rb b/spec/ruby/core/sizedqueue/length_spec.rb
new file mode 100644
index 0000000000..b9d16d8932
--- /dev/null
+++ b/spec/ruby/core/sizedqueue/length_spec.rb
@@ -0,0 +1,7 @@
+require_relative '../../spec_helper'
+
+describe "SizedQueue#length" do
+ it "is an alias of SizedQueue#size" do
+ SizedQueue.instance_method(:length).should == SizedQueue.instance_method(:size)
+ end
+end
diff --git a/spec/ruby/core/sizedqueue/max_spec.rb b/spec/ruby/core/sizedqueue/max_spec.rb
new file mode 100644
index 0000000000..cbabb5dc10
--- /dev/null
+++ b/spec/ruby/core/sizedqueue/max_spec.rb
@@ -0,0 +1,10 @@
+require_relative '../../spec_helper'
+require_relative '../../shared/sizedqueue/max'
+
+describe "SizedQueue#max" do
+ it_behaves_like :sizedqueue_max, :max, -> n { SizedQueue.new(n) }
+end
+
+describe "SizedQueue#max=" do
+ it_behaves_like :sizedqueue_max=, :max=, -> n { SizedQueue.new(n) }
+end
diff --git a/spec/ruby/core/sizedqueue/new_spec.rb b/spec/ruby/core/sizedqueue/new_spec.rb
new file mode 100644
index 0000000000..d5704732c3
--- /dev/null
+++ b/spec/ruby/core/sizedqueue/new_spec.rb
@@ -0,0 +1,6 @@
+require_relative '../../spec_helper'
+require_relative '../../shared/sizedqueue/new'
+
+describe "SizedQueue.new" do
+ it_behaves_like :sizedqueue_new, :new, -> *n { SizedQueue.new(*n) }
+end
diff --git a/spec/ruby/core/sizedqueue/num_waiting_spec.rb b/spec/ruby/core/sizedqueue/num_waiting_spec.rb
new file mode 100644
index 0000000000..9aef25e33d
--- /dev/null
+++ b/spec/ruby/core/sizedqueue/num_waiting_spec.rb
@@ -0,0 +1,6 @@
+require_relative '../../spec_helper'
+require_relative '../../shared/sizedqueue/num_waiting'
+
+describe "SizedQueue#num_waiting" do
+ it_behaves_like :sizedqueue_num_waiting, :new, -> n { SizedQueue.new(n) }
+end
diff --git a/spec/ruby/core/sizedqueue/pop_spec.rb b/spec/ruby/core/sizedqueue/pop_spec.rb
new file mode 100644
index 0000000000..6338ddbaa0
--- /dev/null
+++ b/spec/ruby/core/sizedqueue/pop_spec.rb
@@ -0,0 +1,11 @@
+require_relative '../../spec_helper'
+require_relative '../../shared/queue/deque'
+require_relative '../../shared/types/rb_num2dbl_fails'
+
+describe "SizedQueue#pop" do
+ it_behaves_like :queue_deq, :pop, -> { SizedQueue.new(10) }
+end
+
+describe "SizedQueue operations with timeout" do
+ it_behaves_like :rb_num2dbl_fails, nil, -> v { q = SizedQueue.new(10); q.push(1); q.pop(timeout: v) }
+end
diff --git a/spec/ruby/core/sizedqueue/push_spec.rb b/spec/ruby/core/sizedqueue/push_spec.rb
new file mode 100644
index 0000000000..943d0fcfb4
--- /dev/null
+++ b/spec/ruby/core/sizedqueue/push_spec.rb
@@ -0,0 +1,7 @@
+require_relative '../../spec_helper'
+
+describe "SizedQueue#push" do
+ it "is an alias of SizedQueue#<<" do
+ SizedQueue.instance_method(:push).should == SizedQueue.instance_method(:<<)
+ end
+end
diff --git a/spec/ruby/core/sizedqueue/shift_spec.rb b/spec/ruby/core/sizedqueue/shift_spec.rb
new file mode 100644
index 0000000000..f410f3f80d
--- /dev/null
+++ b/spec/ruby/core/sizedqueue/shift_spec.rb
@@ -0,0 +1,7 @@
+require_relative '../../spec_helper'
+
+describe "SizedQueue#shift" do
+ it "is an alias of SizedQueue#pop" do
+ SizedQueue.instance_method(:shift).should == SizedQueue.instance_method(:pop)
+ end
+end
diff --git a/spec/ruby/core/sizedqueue/size_spec.rb b/spec/ruby/core/sizedqueue/size_spec.rb
new file mode 100644
index 0000000000..dfa76faabe
--- /dev/null
+++ b/spec/ruby/core/sizedqueue/size_spec.rb
@@ -0,0 +1,6 @@
+require_relative '../../spec_helper'
+require_relative '../../shared/queue/length'
+
+describe "SizedQueue#size" do
+ it_behaves_like :queue_length, :size, -> { SizedQueue.new(10) }
+end
diff --git a/spec/ruby/core/string/allocate_spec.rb b/spec/ruby/core/string/allocate_spec.rb
index 9048815c5d..00dadaf076 100644
--- a/spec/ruby/core/string/allocate_spec.rb
+++ b/spec/ruby/core/string/allocate_spec.rb
@@ -1,9 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "String.allocate" do
it "returns an instance of String" do
str = String.allocate
- str.should be_an_instance_of(String)
+ str.should.instance_of?(String)
end
it "returns a fully-formed String" do
@@ -14,6 +14,6 @@ describe "String.allocate" do
end
it "returns a binary String" do
- String.new.encoding.should == Encoding::BINARY
+ String.allocate.encoding.should == Encoding::BINARY
end
end
diff --git a/spec/ruby/core/string/append_as_bytes_spec.rb b/spec/ruby/core/string/append_as_bytes_spec.rb
new file mode 100644
index 0000000000..feead64615
--- /dev/null
+++ b/spec/ruby/core/string/append_as_bytes_spec.rb
@@ -0,0 +1,60 @@
+require_relative '../../spec_helper'
+
+describe "String#append_bytes" do
+ ruby_version_is "3.4" do
+ it "doesn't allow to mutate frozen strings" do
+ str = "hello".freeze
+ -> { str.append_as_bytes("\xE2\x82") }.should.raise(FrozenError)
+ end
+
+ it "allows creating broken strings in UTF8" do
+ str = +"hello"
+ str.append_as_bytes("\xE2\x82")
+ str.valid_encoding?.should == false
+
+ str.append_as_bytes("\xAC")
+ str.valid_encoding?.should == true
+ end
+
+ it "allows creating broken strings in UTF_32" do
+ str = "abc".encode(Encoding::UTF_32LE)
+ str.append_as_bytes("def")
+ str.encoding.should == Encoding::UTF_32LE
+ str.valid_encoding?.should == false
+ end
+
+ it "never changes the receiver encoding" do
+ str = "".b
+ str.append_as_bytes("€")
+ str.encoding.should == Encoding::BINARY
+ end
+
+ it "accepts variadic String or Integer arguments" do
+ str = "hello".b
+ str.append_as_bytes("\xE2\x82", 12, 43, "\xAC")
+ str.encoding.should == Encoding::BINARY
+ str.should == "hello\xE2\x82\f+\xAC".b
+ end
+
+ it "truncates integers to the least significant byte" do
+ str = +""
+ str.append_as_bytes(0x131, 0x232, 0x333, bignum_value, bignum_value(1))
+ str.bytes.should == [0x31, 0x32, 0x33, 0, 1]
+ end
+
+ it "wraps negative integers" do
+ str = "".b
+ str.append_as_bytes(-1, -bignum_value, -bignum_value(1))
+ str.bytes.should == [0xFF, 0, 0xFF]
+ end
+
+ it "only accepts strings or integers, and doesn't attempt to cast with #to_str or #to_int" do
+ to_str = mock("to_str")
+ to_str.should_not_receive(:to_str)
+ to_str.should_not_receive(:to_int)
+
+ str = +"hello"
+ -> { str.append_as_bytes(to_str) }.should.raise(TypeError, "wrong argument type MockObject (expected String or Integer)")
+ end
+ end
+end
diff --git a/spec/ruby/core/string/append_spec.rb b/spec/ruby/core/string/append_spec.rb
index 87b2dca725..e0f71b7c97 100644
--- a/spec/ruby/core/string/append_spec.rb
+++ b/spec/ruby/core/string/append_spec.rb
@@ -1,8 +1,14 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/concat', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/concat'
describe "String#<<" do
it_behaves_like :string_concat, :<<
it_behaves_like :string_concat_encoding, :<<
+ it_behaves_like :string_concat_type_coercion, :<<
+
+ it "raises an ArgumentError when given the incorrect number of arguments" do
+ -> { "hello".send(:<<) }.should.raise(ArgumentError)
+ -> { "hello".send(:<<, "one", "two") }.should.raise(ArgumentError)
+ end
end
diff --git a/spec/ruby/core/string/ascii_only_spec.rb b/spec/ruby/core/string/ascii_only_spec.rb
index 1bf9cfa4a1..9af663beb8 100644
--- a/spec/ruby/core/string/ascii_only_spec.rb
+++ b/spec/ruby/core/string/ascii_only_spec.rb
@@ -1,85 +1,82 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes.rb', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
-with_feature :encoding do
- describe "String#ascii_only?" do
- describe "with ASCII only characters" do
- it "returns true if the encoding is UTF-8" do
- [ ["hello", true],
- ["hello".encode('UTF-8'), true],
- ["hello".force_encoding('UTF-8'), true],
- ].should be_computed_by(:ascii_only?)
- end
-
- it "returns true if the encoding is US-ASCII" do
- "hello".force_encoding(Encoding::US_ASCII).ascii_only?.should be_true
- "hello".encode(Encoding::US_ASCII).ascii_only?.should be_true
- end
-
- it "returns true for all single-character UTF-8 Strings" do
- 0.upto(127) do |n|
- n.chr.ascii_only?.should be_true
- end
- end
+describe "String#ascii_only?" do
+ describe "with ASCII only characters" do
+ it "returns true if the encoding is UTF-8" do
+ [ ["hello", true],
+ ["hello".encode('UTF-8'), true],
+ ["hello".dup.force_encoding('UTF-8'), true],
+ ].should be_computed_by(:ascii_only?)
end
- describe "with non-ASCII only characters" do
- it "returns false if the encoding is ASCII-8BIT" do
- chr = 128.chr
- chr.encoding.should == Encoding::ASCII_8BIT
- chr.ascii_only?.should be_false
- end
-
- it "returns false if the String contains any non-ASCII characters" do
- [ ["\u{6666}", false],
- ["hello, \u{6666}", false],
- ["\u{6666}".encode('UTF-8'), false],
- ["\u{6666}".force_encoding('UTF-8'), false],
- ].should be_computed_by(:ascii_only?)
- end
+ it "returns true if the encoding is US-ASCII" do
+ "hello".dup.force_encoding(Encoding::US_ASCII).ascii_only?.should == true
+ "hello".encode(Encoding::US_ASCII).ascii_only?.should == true
+ end
- it "returns false if the encoding is US-ASCII" do
- [ ["\u{6666}".force_encoding(Encoding::US_ASCII), false],
- ["hello, \u{6666}".force_encoding(Encoding::US_ASCII), false],
- ].should be_computed_by(:ascii_only?)
+ it "returns true for all single-character UTF-8 Strings" do
+ 0.upto(127) do |n|
+ n.chr.ascii_only?.should == true
end
end
+ end
- it "returns true for the empty String with an ASCII-compatible encoding" do
- "".ascii_only?.should be_true
- "".encode('UTF-8').ascii_only?.should be_true
+ describe "with non-ASCII only characters" do
+ it "returns false if the encoding is BINARY" do
+ chr = 128.chr
+ chr.encoding.should == Encoding::BINARY
+ chr.ascii_only?.should == false
end
- it "returns false for the empty String with a non-ASCII-compatible encoding" do
- "".force_encoding('UTF-16LE').ascii_only?.should be_false
- "".encode('UTF-16BE').ascii_only?.should be_false
+ it "returns false if the String contains any non-ASCII characters" do
+ [ ["\u{6666}", false],
+ ["hello, \u{6666}", false],
+ ["\u{6666}".encode('UTF-8'), false],
+ ["\u{6666}".dup.force_encoding('UTF-8'), false],
+ ].should be_computed_by(:ascii_only?)
end
- it "returns false for a non-empty String with non-ASCII-compatible encoding" do
- "\x78\x00".force_encoding("UTF-16LE").ascii_only?.should be_false
+ it "returns false if the encoding is US-ASCII" do
+ [ ["\u{6666}".dup.force_encoding(Encoding::US_ASCII), false],
+ ["hello, \u{6666}".dup.force_encoding(Encoding::US_ASCII), false],
+ ].should be_computed_by(:ascii_only?)
end
+ end
- it "returns false when interpolating non ascii strings" do
- base = "EU currency is"
- base.force_encoding(Encoding::US_ASCII)
- euro = "\u20AC"
- interp = "#{base} #{euro}"
- euro.ascii_only?.should be_false
- base.ascii_only?.should be_true
- interp.ascii_only?.should be_false
- end
+ it "returns true for the empty String with an ASCII-compatible encoding" do
+ "".ascii_only?.should == true
+ "".encode('UTF-8').ascii_only?.should == true
+ end
- it "returns false after appending non ASCII characters to an empty String" do
- ("" << "λ").ascii_only?.should be_false
- end
+ it "returns false for the empty String with a non-ASCII-compatible encoding" do
+ "".dup.force_encoding('UTF-16LE').ascii_only?.should == false
+ "".encode('UTF-16BE').ascii_only?.should == false
+ end
- it "returns false when concatenating an ASCII and non-ASCII String" do
- "".concat("λ").ascii_only?.should be_false
- end
+ it "returns false for a non-empty String with non-ASCII-compatible encoding" do
+ "\x78\x00".dup.force_encoding("UTF-16LE").ascii_only?.should == false
+ end
- it "returns false when replacing an ASCII String with a non-ASCII String" do
- "".replace("λ").ascii_only?.should be_false
- end
+ it "returns false when interpolating non ascii strings" do
+ base = "EU currency is".dup.force_encoding(Encoding::US_ASCII)
+ euro = "\u20AC"
+ interp = "#{base} #{euro}"
+ euro.ascii_only?.should == false
+ base.ascii_only?.should == true
+ interp.ascii_only?.should == false
+ end
+
+ it "returns false after appending non ASCII characters to an empty String" do
+ ("".dup << "λ").ascii_only?.should == false
+ end
+
+ it "returns false when concatenating an ASCII and non-ASCII String" do
+ "".dup.concat("λ").ascii_only?.should == false
+ end
+
+ it "returns false when replacing an ASCII String with a non-ASCII String" do
+ "".dup.replace("λ").ascii_only?.should == false
end
end
diff --git a/spec/ruby/core/string/b_spec.rb b/spec/ruby/core/string/b_spec.rb
index 89fcedf7c4..d181447709 100644
--- a/spec/ruby/core/string/b_spec.rb
+++ b/spec/ruby/core/string/b_spec.rb
@@ -1,24 +1,16 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
+# frozen_string_literal: false
+require_relative '../../spec_helper'
describe "String#b" do
- with_feature :encoding do
- it "returns an ASCII-8BIT encoded string" do
- "Hello".b.should == "Hello".force_encoding(Encoding::ASCII_8BIT)
- "ã“ã‚“ã¡ã«ã¯".b.should == "ã“ã‚“ã¡ã«ã¯".force_encoding(Encoding::ASCII_8BIT)
- end
-
- it "returns new string without modifying self" do
- str = "ã“ã‚“ã¡ã«ã¯"
- str.b.should_not equal(str)
- str.should == "ã“ã‚“ã¡ã«ã¯"
- end
+ it "returns a binary encoded string" do
+ "Hello".b.should == "Hello".force_encoding(Encoding::BINARY)
+ "ã“ã‚“ã¡ã«ã¯".b.should == "ã“ã‚“ã¡ã«ã¯".force_encoding(Encoding::BINARY)
+ end
- it "copies own tainted/untrusted status to the returning value" do
- utf_8 = "ã“ã‚“ã¡ã«ã¯".taint.untrust
- ret = utf_8.b
- ret.tainted?.should be_true
- ret.untrusted?.should be_true
- end
+ it "returns new string without modifying self" do
+ str = "ã“ã‚“ã¡ã«ã¯"
+ str.b.should_not.equal?(str)
+ str.should == "ã“ã‚“ã¡ã«ã¯"
end
end
diff --git a/spec/ruby/core/string/byteindex_spec.rb b/spec/ruby/core/string/byteindex_spec.rb
new file mode 100644
index 0000000000..f4c6408790
--- /dev/null
+++ b/spec/ruby/core/string/byteindex_spec.rb
@@ -0,0 +1,298 @@
+# -*- encoding: utf-8 -*-
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/byte_index_common.rb'
+
+describe "String#byteindex" do
+ it "calls #to_str to convert the first argument" do
+ char = mock("string index char")
+ char.should_receive(:to_str).and_return("b")
+ "abc".byteindex(char).should == 1
+ end
+
+ it "calls #to_int to convert the second argument" do
+ offset = mock("string index offset")
+ offset.should_receive(:to_int).and_return(1)
+ "abc".byteindex("c", offset).should == 2
+ end
+
+ it "does not raise IndexError when byte offset is correct or on string boundary" do
+ "ã‚".byteindex("").should == 0
+ "ã‚".byteindex("", 0).should == 0
+ "ã‚".byteindex("", 3).should == 3
+ end
+
+ it_behaves_like :byte_index_common, :byteindex
+end
+
+describe "String#byteindex with String" do
+ it "behaves the same as String#byteindex(char) for one-character strings" do
+ "blablabla hello cruel world...!".split("").uniq.each do |str|
+ chr = str[0]
+ str.byteindex(str).should == str.byteindex(chr)
+
+ 0.upto(str.size + 1) do |start|
+ str.byteindex(str, start).should == str.byteindex(chr, start)
+ end
+
+ (-str.size - 1).upto(-1) do |start|
+ str.byteindex(str, start).should == str.byteindex(chr, start)
+ end
+ end
+ end
+
+ it "returns the byteindex of the first occurrence of the given substring" do
+ "blablabla".byteindex("").should == 0
+ "blablabla".byteindex("b").should == 0
+ "blablabla".byteindex("bla").should == 0
+ "blablabla".byteindex("blabla").should == 0
+ "blablabla".byteindex("blablabla").should == 0
+
+ "blablabla".byteindex("l").should == 1
+ "blablabla".byteindex("la").should == 1
+ "blablabla".byteindex("labla").should == 1
+ "blablabla".byteindex("lablabla").should == 1
+
+ "blablabla".byteindex("a").should == 2
+ "blablabla".byteindex("abla").should == 2
+ "blablabla".byteindex("ablabla").should == 2
+ end
+
+ it "treats the offset as a byteindex" do
+ "aaaaa".byteindex("a", 0).should == 0
+ "aaaaa".byteindex("a", 2).should == 2
+ "aaaaa".byteindex("a", 4).should == 4
+ end
+
+ it "ignores string subclasses" do
+ "blablabla".byteindex(StringSpecs::MyString.new("bla")).should == 0
+ StringSpecs::MyString.new("blablabla").byteindex("bla").should == 0
+ StringSpecs::MyString.new("blablabla").byteindex(StringSpecs::MyString.new("bla")).should == 0
+ end
+
+ it "starts the search at the given offset" do
+ "blablabla".byteindex("bl", 0).should == 0
+ "blablabla".byteindex("bl", 1).should == 3
+ "blablabla".byteindex("bl", 2).should == 3
+ "blablabla".byteindex("bl", 3).should == 3
+
+ "blablabla".byteindex("bla", 0).should == 0
+ "blablabla".byteindex("bla", 1).should == 3
+ "blablabla".byteindex("bla", 2).should == 3
+ "blablabla".byteindex("bla", 3).should == 3
+
+ "blablabla".byteindex("blab", 0).should == 0
+ "blablabla".byteindex("blab", 1).should == 3
+ "blablabla".byteindex("blab", 2).should == 3
+ "blablabla".byteindex("blab", 3).should == 3
+
+ "blablabla".byteindex("la", 1).should == 1
+ "blablabla".byteindex("la", 2).should == 4
+ "blablabla".byteindex("la", 3).should == 4
+ "blablabla".byteindex("la", 4).should == 4
+
+ "blablabla".byteindex("lab", 1).should == 1
+ "blablabla".byteindex("lab", 2).should == 4
+ "blablabla".byteindex("lab", 3).should == 4
+ "blablabla".byteindex("lab", 4).should == 4
+
+ "blablabla".byteindex("ab", 2).should == 2
+ "blablabla".byteindex("ab", 3).should == 5
+ "blablabla".byteindex("ab", 4).should == 5
+ "blablabla".byteindex("ab", 5).should == 5
+
+ "blablabla".byteindex("", 0).should == 0
+ "blablabla".byteindex("", 1).should == 1
+ "blablabla".byteindex("", 2).should == 2
+ "blablabla".byteindex("", 7).should == 7
+ "blablabla".byteindex("", 8).should == 8
+ "blablabla".byteindex("", 9).should == 9
+ end
+
+ it "starts the search at offset + self.length if offset is negative" do
+ str = "blablabla"
+
+ ["bl", "bla", "blab", "la", "lab", "ab", ""].each do |needle|
+ (-str.length .. -1).each do |offset|
+ str.byteindex(needle, offset).should ==
+ str.byteindex(needle, offset + str.length)
+ end
+ end
+ end
+
+ it "returns nil if the substring isn't found" do
+ "blablabla".byteindex("B").should == nil
+ "blablabla".byteindex("z").should == nil
+ "blablabla".byteindex("BLA").should == nil
+ "blablabla".byteindex("blablablabla").should == nil
+ "blablabla".byteindex("", 10).should == nil
+
+ "hello".byteindex("he", 1).should == nil
+ "hello".byteindex("he", 2).should == nil
+ "I’ve got a multibyte character.\n".byteindex("\n\n").should == nil
+ end
+
+ it "returns the character byteindex of a multibyte character" do
+ "ã‚りãŒã¨ã†".byteindex("ãŒ").should == 6
+ end
+
+ it "returns the character byteindex after offset" do
+ "ã‚れã‚れ".byteindex("ã‚", 3).should == 6
+ "ã‚りãŒã¨ã†ã‚りãŒã¨ã†".byteindex("ãŒ", 9).should == 21
+ end
+
+ it "returns the character byteindex after a partial first match" do
+ "</</h".byteindex("</h").should == 2
+ end
+
+ it "raises an Encoding::CompatibilityError if the encodings are incompatible" do
+ char = "れ".encode Encoding::EUC_JP
+ -> do
+ "ã‚れ".byteindex(char)
+ end.should.raise(Encoding::CompatibilityError)
+ end
+
+ it "handles a substring in a superset encoding" do
+ 'abc'.dup.force_encoding(Encoding::US_ASCII).byteindex('é').should == nil
+ end
+
+ it "handles a substring in a subset encoding" do
+ 'été'.byteindex('t'.dup.force_encoding(Encoding::US_ASCII)).should == 2
+ end
+end
+
+describe "String#byteindex with Regexp" do
+ it "behaves the same as String#byteindex(string) for escaped string regexps" do
+ ["blablabla", "hello cruel world...!"].each do |str|
+ ["", "b", "bla", "lab", "o c", "d."].each do |needle|
+ regexp = Regexp.new(Regexp.escape(needle))
+ str.byteindex(regexp).should == str.byteindex(needle)
+
+ 0.upto(str.size + 1) do |start|
+ str.byteindex(regexp, start).should == str.byteindex(needle, start)
+ end
+
+ (-str.size - 1).upto(-1) do |start|
+ str.byteindex(regexp, start).should == str.byteindex(needle, start)
+ end
+ end
+ end
+ end
+
+ it "returns the byteindex of the first match of regexp" do
+ "blablabla".byteindex(/bla/).should == 0
+ "blablabla".byteindex(/BLA/i).should == 0
+
+ "blablabla".byteindex(/.{0}/).should == 0
+ "blablabla".byteindex(/.{6}/).should == 0
+ "blablabla".byteindex(/.{9}/).should == 0
+
+ "blablabla".byteindex(/.*/).should == 0
+ "blablabla".byteindex(/.+/).should == 0
+
+ "blablabla".byteindex(/lab|b/).should == 0
+
+ not_supported_on :opal do
+ "blablabla".byteindex(/\A/).should == 0
+ "blablabla".byteindex(/\Z/).should == 9
+ "blablabla".byteindex(/\z/).should == 9
+ "blablabla\n".byteindex(/\Z/).should == 9
+ "blablabla\n".byteindex(/\z/).should == 10
+ end
+
+ "blablabla".byteindex(/^/).should == 0
+ "\nblablabla".byteindex(/^/).should == 0
+ "b\nablabla".byteindex(/$/).should == 1
+ "bl\nablabla".byteindex(/$/).should == 2
+
+ "blablabla".byteindex(/.l./).should == 0
+ end
+
+ it "starts the search at the given offset" do
+ "blablabla".byteindex(/.{0}/, 5).should == 5
+ "blablabla".byteindex(/.{1}/, 5).should == 5
+ "blablabla".byteindex(/.{2}/, 5).should == 5
+ "blablabla".byteindex(/.{3}/, 5).should == 5
+ "blablabla".byteindex(/.{4}/, 5).should == 5
+
+ "blablabla".byteindex(/.{0}/, 3).should == 3
+ "blablabla".byteindex(/.{1}/, 3).should == 3
+ "blablabla".byteindex(/.{2}/, 3).should == 3
+ "blablabla".byteindex(/.{5}/, 3).should == 3
+ "blablabla".byteindex(/.{6}/, 3).should == 3
+
+ "blablabla".byteindex(/.l./, 0).should == 0
+ "blablabla".byteindex(/.l./, 1).should == 3
+ "blablabla".byteindex(/.l./, 2).should == 3
+ "blablabla".byteindex(/.l./, 3).should == 3
+
+ "xblaxbla".byteindex(/x./, 0).should == 0
+ "xblaxbla".byteindex(/x./, 1).should == 4
+ "xblaxbla".byteindex(/x./, 2).should == 4
+
+ not_supported_on :opal do
+ "blablabla\n".byteindex(/\Z/, 9).should == 9
+ end
+ end
+
+ it "starts the search at offset + self.length if offset is negative" do
+ str = "blablabla"
+
+ ["bl", "bla", "blab", "la", "lab", "ab", ""].each do |needle|
+ (-str.length .. -1).each do |offset|
+ str.byteindex(needle, offset).should ==
+ str.byteindex(needle, offset + str.length)
+ end
+ end
+ end
+
+ it "returns nil if the substring isn't found" do
+ "blablabla".byteindex(/BLA/).should == nil
+
+ "blablabla".byteindex(/.{10}/).should == nil
+ "blaxbla".byteindex(/.x/, 3).should == nil
+ "blaxbla".byteindex(/..x/, 2).should == nil
+ end
+
+ it "returns nil if the Regexp matches the empty string and the offset is out of range" do
+ "ruby".byteindex(//, 12).should == nil
+ end
+
+ it "supports \\G which matches at the given start offset" do
+ "helloYOU.".byteindex(/\GYOU/, 5).should == 5
+ "helloYOU.".byteindex(/\GYOU/).should == nil
+
+ re = /\G.+YOU/
+ # The # marks where \G will match.
+ [
+ ["#hi!YOUall.", 0],
+ ["h#i!YOUall.", 1],
+ ["hi#!YOUall.", 2],
+ ["hi!#YOUall.", nil]
+ ].each do |spec|
+
+ start = spec[0].byteindex("#")
+ str = spec[0].delete("#")
+
+ str.byteindex(re, start).should == spec[1]
+ end
+ end
+
+ it "converts start_offset to an integer via to_int" do
+ obj = mock('1')
+ obj.should_receive(:to_int).and_return(1)
+ "RWOARW".byteindex(/R./, obj).should == 4
+ end
+
+ it "returns the character byteindex of a multibyte character" do
+ "ã‚りãŒã¨ã†".byteindex(/ãŒ/).should == 6
+ end
+
+ it "returns the character byteindex after offset" do
+ "ã‚れã‚れ".byteindex(/ã‚/, 3).should == 6
+ end
+
+ it "treats the offset as a byteindex" do
+ "ã‚れã‚ã‚れ".byteindex(/ã‚/, 6).should == 6
+ end
+end
diff --git a/spec/ruby/core/string/byterindex_spec.rb b/spec/ruby/core/string/byterindex_spec.rb
new file mode 100644
index 0000000000..569820463d
--- /dev/null
+++ b/spec/ruby/core/string/byterindex_spec.rb
@@ -0,0 +1,353 @@
+# -*- encoding: utf-8 -*-
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/byte_index_common.rb'
+
+describe "String#byterindex with object" do
+ it "tries to convert obj to a string via to_str" do
+ obj = mock('lo')
+ def obj.to_str() "lo" end
+ "hello".byterindex(obj).should == "hello".byterindex("lo")
+
+ obj = mock('o')
+ def obj.respond_to?(arg, *) true end
+ def obj.method_missing(*args) "o" end
+ "hello".byterindex(obj).should == "hello".byterindex("o")
+ end
+
+ it "calls #to_int to convert the second argument" do
+ offset = mock("string index offset")
+ offset.should_receive(:to_int).and_return(3)
+ "abc".byterindex("c", offset).should == 2
+ end
+
+ it "does not raise IndexError when byte offset is correct or on string boundary" do
+ "ã‚".byterindex("", 0).should == 0
+ "ã‚".byterindex("", 3).should == 3
+ "ã‚".byterindex("").should == 3
+ end
+
+ it_behaves_like :byte_index_common, :byterindex
+end
+
+describe "String#byterindex with String" do
+ it "behaves the same as String#byterindex(char) for one-character strings" do
+ "blablabla hello cruel world...!".split("").uniq.each do |str|
+ chr = str[0]
+ str.byterindex(str).should == str.byterindex(chr)
+
+ 0.upto(str.size + 1) do |start|
+ str.byterindex(str, start).should == str.byterindex(chr, start)
+ end
+
+ (-str.size - 1).upto(-1) do |start|
+ str.byterindex(str, start).should == str.byterindex(chr, start)
+ end
+ end
+ end
+
+ it "behaves the same as String#byterindex(?char) for one-character strings" do
+ "blablabla hello cruel world...!".split("").uniq.each do |str|
+ chr = str[0] =~ / / ? str[0] : eval("?#{str[0]}")
+ str.byterindex(str).should == str.byterindex(chr)
+
+ 0.upto(str.size + 1) do |start|
+ str.byterindex(str, start).should == str.byterindex(chr, start)
+ end
+
+ (-str.size - 1).upto(-1) do |start|
+ str.byterindex(str, start).should == str.byterindex(chr, start)
+ end
+ end
+ end
+
+ it "returns the index of the last occurrence of the given substring" do
+ "blablabla".byterindex("").should == 9
+ "blablabla".byterindex("a").should == 8
+ "blablabla".byterindex("la").should == 7
+ "blablabla".byterindex("bla").should == 6
+ "blablabla".byterindex("abla").should == 5
+ "blablabla".byterindex("labla").should == 4
+ "blablabla".byterindex("blabla").should == 3
+ "blablabla".byterindex("ablabla").should == 2
+ "blablabla".byterindex("lablabla").should == 1
+ "blablabla".byterindex("blablabla").should == 0
+
+ "blablabla".byterindex("l").should == 7
+ "blablabla".byterindex("bl").should == 6
+ "blablabla".byterindex("abl").should == 5
+ "blablabla".byterindex("labl").should == 4
+ "blablabla".byterindex("blabl").should == 3
+ "blablabla".byterindex("ablabl").should == 2
+ "blablabla".byterindex("lablabl").should == 1
+ "blablabla".byterindex("blablabl").should == 0
+
+ "blablabla".byterindex("b").should == 6
+ "blablabla".byterindex("ab").should == 5
+ "blablabla".byterindex("lab").should == 4
+ "blablabla".byterindex("blab").should == 3
+ "blablabla".byterindex("ablab").should == 2
+ "blablabla".byterindex("lablab").should == 1
+ "blablabla".byterindex("blablab").should == 0
+ end
+
+ it "ignores string subclasses" do
+ "blablabla".byterindex(StringSpecs::MyString.new("bla")).should == 6
+ StringSpecs::MyString.new("blablabla").byterindex("bla").should == 6
+ StringSpecs::MyString.new("blablabla").byterindex(StringSpecs::MyString.new("bla")).should == 6
+ end
+
+ it "starts the search at the given offset" do
+ "blablabla".byterindex("bl", 0).should == 0
+ "blablabla".byterindex("bl", 1).should == 0
+ "blablabla".byterindex("bl", 2).should == 0
+ "blablabla".byterindex("bl", 3).should == 3
+
+ "blablabla".byterindex("bla", 0).should == 0
+ "blablabla".byterindex("bla", 1).should == 0
+ "blablabla".byterindex("bla", 2).should == 0
+ "blablabla".byterindex("bla", 3).should == 3
+
+ "blablabla".byterindex("blab", 0).should == 0
+ "blablabla".byterindex("blab", 1).should == 0
+ "blablabla".byterindex("blab", 2).should == 0
+ "blablabla".byterindex("blab", 3).should == 3
+ "blablabla".byterindex("blab", 6).should == 3
+ "blablablax".byterindex("blab", 6).should == 3
+
+ "blablabla".byterindex("la", 1).should == 1
+ "blablabla".byterindex("la", 2).should == 1
+ "blablabla".byterindex("la", 3).should == 1
+ "blablabla".byterindex("la", 4).should == 4
+
+ "blablabla".byterindex("lab", 1).should == 1
+ "blablabla".byterindex("lab", 2).should == 1
+ "blablabla".byterindex("lab", 3).should == 1
+ "blablabla".byterindex("lab", 4).should == 4
+
+ "blablabla".byterindex("ab", 2).should == 2
+ "blablabla".byterindex("ab", 3).should == 2
+ "blablabla".byterindex("ab", 4).should == 2
+ "blablabla".byterindex("ab", 5).should == 5
+
+ "blablabla".byterindex("", 0).should == 0
+ "blablabla".byterindex("", 1).should == 1
+ "blablabla".byterindex("", 2).should == 2
+ "blablabla".byterindex("", 7).should == 7
+ "blablabla".byterindex("", 8).should == 8
+ "blablabla".byterindex("", 9).should == 9
+ "blablabla".byterindex("", 10).should == 9
+ end
+
+ it "starts the search at offset + self.length if offset is negative" do
+ str = "blablabla"
+
+ ["bl", "bla", "blab", "la", "lab", "ab", ""].each do |needle|
+ (-str.length .. -1).each do |offset|
+ str.byterindex(needle, offset).should ==
+ str.byterindex(needle, offset + str.length)
+ end
+ end
+ end
+
+ it "returns nil if the substring isn't found" do
+ "blablabla".byterindex("B").should == nil
+ "blablabla".byterindex("z").should == nil
+ "blablabla".byterindex("BLA").should == nil
+ "blablabla".byterindex("blablablabla").should == nil
+
+ "hello".byterindex("lo", 0).should == nil
+ "hello".byterindex("lo", 1).should == nil
+ "hello".byterindex("lo", 2).should == nil
+
+ "hello".byterindex("llo", 0).should == nil
+ "hello".byterindex("llo", 1).should == nil
+
+ "hello".byterindex("el", 0).should == nil
+ "hello".byterindex("ello", 0).should == nil
+
+ "hello".byterindex("", -6).should == nil
+ "hello".byterindex("", -7).should == nil
+
+ "hello".byterindex("h", -6).should == nil
+ end
+
+ it "tries to convert start_offset to an integer via to_int" do
+ obj = mock('5')
+ def obj.to_int() 5 end
+ "str".byterindex("st", obj).should == 0
+
+ obj = mock('5')
+ def obj.respond_to?(arg, *) true end
+ def obj.method_missing(*args) 5 end
+ "str".byterindex("st", obj).should == 0
+ end
+
+ it "raises a TypeError when given offset is nil" do
+ -> { "str".byterindex("st", nil) }.should.raise(TypeError)
+ end
+
+ it "handles a substring in a superset encoding" do
+ 'abc'.dup.force_encoding(Encoding::US_ASCII).byterindex('é').should == nil
+ end
+
+ it "handles a substring in a subset encoding" do
+ 'été'.byterindex('t'.dup.force_encoding(Encoding::US_ASCII)).should == 2
+ end
+end
+
+describe "String#byterindex with Regexp" do
+ it "behaves the same as String#byterindex(string) for escaped string regexps" do
+ ["blablabla", "hello cruel world...!"].each do |str|
+ ["", "b", "bla", "lab", "o c", "d."].each do |needle|
+ regexp = Regexp.new(Regexp.escape(needle))
+ str.byterindex(regexp).should == str.byterindex(needle)
+
+ 0.upto(str.size + 1) do |start|
+ str.byterindex(regexp, start).should == str.byterindex(needle, start)
+ end
+
+ (-str.size - 1).upto(-1) do |start|
+ str.byterindex(regexp, start).should == str.byterindex(needle, start)
+ end
+ end
+ end
+ end
+
+ it "returns the index of the first match from the end of string of regexp" do
+ "blablabla".byterindex(/bla/).should == 6
+ "blablabla".byterindex(/BLA/i).should == 6
+
+ "blablabla".byterindex(/.{0}/).should == 9
+ "blablabla".byterindex(/.{1}/).should == 8
+ "blablabla".byterindex(/.{2}/).should == 7
+ "blablabla".byterindex(/.{6}/).should == 3
+ "blablabla".byterindex(/.{9}/).should == 0
+
+ "blablabla".byterindex(/.*/).should == 9
+ "blablabla".byterindex(/.+/).should == 8
+
+ "blablabla".byterindex(/bla|a/).should == 8
+
+ not_supported_on :opal do
+ "blablabla".byterindex(/\A/).should == 0
+ "blablabla".byterindex(/\Z/).should == 9
+ "blablabla".byterindex(/\z/).should == 9
+ "blablabla\n".byterindex(/\Z/).should == 10
+ "blablabla\n".byterindex(/\z/).should == 10
+ end
+
+ "blablabla".byterindex(/^/).should == 0
+ not_supported_on :opal do
+ "\nblablabla".byterindex(/^/).should == 1
+ "b\nlablabla".byterindex(/^/).should == 2
+ end
+ "blablabla".byterindex(/$/).should == 9
+
+ "blablabla".byterindex(/.l./).should == 6
+ end
+
+ it "starts the search at the given offset" do
+ "blablabla".byterindex(/.{0}/, 5).should == 5
+ "blablabla".byterindex(/.{1}/, 5).should == 5
+ "blablabla".byterindex(/.{2}/, 5).should == 5
+ "blablabla".byterindex(/.{3}/, 5).should == 5
+ "blablabla".byterindex(/.{4}/, 5).should == 5
+
+ "blablabla".byterindex(/.{0}/, 3).should == 3
+ "blablabla".byterindex(/.{1}/, 3).should == 3
+ "blablabla".byterindex(/.{2}/, 3).should == 3
+ "blablabla".byterindex(/.{5}/, 3).should == 3
+ "blablabla".byterindex(/.{6}/, 3).should == 3
+
+ "blablabla".byterindex(/.l./, 0).should == 0
+ "blablabla".byterindex(/.l./, 1).should == 0
+ "blablabla".byterindex(/.l./, 2).should == 0
+ "blablabla".byterindex(/.l./, 3).should == 3
+
+ "blablablax".byterindex(/.x/, 10).should == 8
+ "blablablax".byterindex(/.x/, 9).should == 8
+ "blablablax".byterindex(/.x/, 8).should == 8
+
+ "blablablax".byterindex(/..x/, 10).should == 7
+ "blablablax".byterindex(/..x/, 9).should == 7
+ "blablablax".byterindex(/..x/, 8).should == 7
+ "blablablax".byterindex(/..x/, 7).should == 7
+
+ not_supported_on :opal do
+ "blablabla\n".byterindex(/\Z/, 9).should == 9
+ end
+ end
+
+ it "starts the search at offset + self.length if offset is negative" do
+ str = "blablabla"
+
+ ["bl", "bla", "blab", "la", "lab", "ab", ""].each do |needle|
+ (-str.length .. -1).each do |offset|
+ str.byterindex(needle, offset).should ==
+ str.byterindex(needle, offset + str.length)
+ end
+ end
+ end
+
+ it "returns nil if the substring isn't found" do
+ "blablabla".byterindex(/BLA/).should == nil
+ "blablabla".byterindex(/.{10}/).should == nil
+ "blablablax".byterindex(/.x/, 7).should == nil
+ "blablablax".byterindex(/..x/, 6).should == nil
+
+ not_supported_on :opal do
+ "blablabla".byterindex(/\Z/, 5).should == nil
+ "blablabla".byterindex(/\z/, 5).should == nil
+ "blablabla\n".byterindex(/\z/, 9).should == nil
+ end
+ end
+
+ not_supported_on :opal do
+ it "supports \\G which matches at the given start offset" do
+ "helloYOU.".byterindex(/YOU\G/, 8).should == 5
+ "helloYOU.".byterindex(/YOU\G/).should == nil
+
+ idx = "helloYOUall!".index("YOU")
+ re = /YOU.+\G.+/
+ # The # marks where \G will match.
+ [
+ ["helloYOU#all.", nil],
+ ["helloYOUa#ll.", idx],
+ ["helloYOUal#l.", idx],
+ ["helloYOUall#.", idx],
+ ["helloYOUall.#", nil]
+ ].each do |i|
+ start = i[0].index("#")
+ str = i[0].delete("#")
+
+ str.byterindex(re, start).should == i[1]
+ end
+ end
+ end
+
+ it "tries to convert start_offset to an integer" do
+ obj = mock('5')
+ def obj.to_int() 5 end
+ "str".byterindex(/../, obj).should == 1
+
+ obj = mock('5')
+ def obj.respond_to?(arg, *) true end
+ def obj.method_missing(*args); 5; end
+ "str".byterindex(/../, obj).should == 1
+ end
+
+ it "raises a TypeError when given offset is nil" do
+ -> { "str".byterindex(/../, nil) }.should.raise(TypeError)
+ end
+
+ it "returns the reverse byte index of a multibyte character" do
+ "ã‚りãŒã‚ŠãŒã¨ã†".byterindex("ãŒ").should == 12
+ "ã‚りãŒã‚ŠãŒã¨ã†".byterindex(/ãŒ/).should == 12
+ end
+
+ it "returns the character index before the finish" do
+ "ã‚りãŒã‚ŠãŒã¨ã†".byterindex("ãŒ", 9).should == 6
+ "ã‚りãŒã‚ŠãŒã¨ã†".byterindex(/ãŒ/, 9).should == 6
+ end
+end
diff --git a/spec/ruby/core/string/bytes_spec.rb b/spec/ruby/core/string/bytes_spec.rb
index b1f5ba412f..e6019fb987 100644
--- a/spec/ruby/core/string/bytes_spec.rb
+++ b/spec/ruby/core/string/bytes_spec.rb
@@ -1,5 +1,5 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "String#bytes" do
before :each do
@@ -9,7 +9,7 @@ describe "String#bytes" do
end
it "returns an Array when no block is given" do
- @utf8.bytes.should be_an_instance_of(Array)
+ @utf8.bytes.should.instance_of?(Array)
end
it "yields each byte to a block if one is given, returning self" do
@@ -22,9 +22,9 @@ describe "String#bytes" do
@utf8_ascii.bytes.to_a.size.should == @utf8_ascii.bytesize
end
- it "returns bytes as Fixnums" do
- @ascii.bytes.to_a.each {|b| b.should be_an_instance_of(Fixnum)}
- @utf8_ascii.bytes { |b| b.should be_an_instance_of(Fixnum) }
+ it "returns bytes as Integers" do
+ @ascii.bytes.to_a.each {|b| b.should.instance_of?(Integer)}
+ @utf8_ascii.bytes { |b| b.should.instance_of?(Integer) }
end
it "agrees with #unpack('C*')" do
@@ -36,22 +36,20 @@ describe "String#bytes" do
end
end
-with_feature :encoding do
- describe "String#bytes" do
- before :each do
- @utf8 = "æ±äº¬"
- @ascii = 'Tokyo'
- @utf8_ascii = @utf8 + @ascii
- end
+describe "String#bytes" do
+ before :each do
+ @utf8 = "æ±äº¬"
+ @ascii = 'Tokyo'
+ @utf8_ascii = @utf8 + @ascii
+ end
- it "agrees with #getbyte" do
- @utf8_ascii.bytes.to_a.each_with_index do |byte,index|
- byte.should == @utf8_ascii.getbyte(index)
- end
+ it "agrees with #getbyte" do
+ @utf8_ascii.bytes.to_a.each_with_index do |byte,index|
+ byte.should == @utf8_ascii.getbyte(index)
end
+ end
- it "is unaffected by #force_encoding" do
- @utf8.force_encoding('ASCII').bytes.to_a.should == @utf8.bytes.to_a
- end
+ it "is unaffected by #force_encoding" do
+ @utf8.dup.force_encoding('ASCII').bytes.to_a.should == @utf8.bytes.to_a
end
end
diff --git a/spec/ruby/core/string/bytesize_spec.rb b/spec/ruby/core/string/bytesize_spec.rb
index 51da179da8..2bbefc0820 100644
--- a/spec/ruby/core/string/bytesize_spec.rb
+++ b/spec/ruby/core/string/bytesize_spec.rb
@@ -1,37 +1,33 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes.rb', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
-with_feature :encoding do
- describe "#String#bytesize" do
- it "needs to be reviewed for spec completeness"
-
- it "returns the length of self in bytes" do
- "hello".bytesize.should == 5
- " ".bytesize.should == 1
- end
+describe "String#bytesize" do
+ it "returns the length of self in bytes" do
+ "hello".bytesize.should == 5
+ " ".bytesize.should == 1
+ end
- it "works with strings containing single UTF-8 characters" do
- "\u{6666}".bytesize.should == 3
- end
+ it "works with strings containing single UTF-8 characters" do
+ "\u{6666}".bytesize.should == 3
+ end
- it "works with pseudo-ASCII strings containing single UTF-8 characters" do
- "\u{6666}".force_encoding('ASCII').bytesize.should == 3
- end
+ it "works with pseudo-ASCII strings containing single UTF-8 characters" do
+ "\u{6666}".dup.force_encoding('ASCII').bytesize.should == 3
+ end
- it "works with strings containing UTF-8 characters" do
- "c \u{6666}".force_encoding('UTF-8').bytesize.should == 5
- "c \u{6666}".bytesize.should == 5
- end
+ it "works with strings containing UTF-8 characters" do
+ "c \u{6666}".dup.force_encoding('UTF-8').bytesize.should == 5
+ "c \u{6666}".bytesize.should == 5
+ end
- it "works with pseudo-ASCII strings containing UTF-8 characters" do
- "c \u{6666}".force_encoding('ASCII').bytesize.should == 5
- end
+ it "works with pseudo-ASCII strings containing UTF-8 characters" do
+ "c \u{6666}".dup.force_encoding('ASCII').bytesize.should == 5
+ end
- it "returns 0 for the empty string" do
- "".bytesize.should == 0
- "".force_encoding('ASCII').bytesize.should == 0
- "".force_encoding('UTF-8').bytesize.should == 0
- end
+ it "returns 0 for the empty string" do
+ "".bytesize.should == 0
+ "".dup.force_encoding('ASCII').bytesize.should == 0
+ "".dup.force_encoding('UTF-8').bytesize.should == 0
end
end
diff --git a/spec/ruby/core/string/byteslice_spec.rb b/spec/ruby/core/string/byteslice_spec.rb
index 263810971e..4ad9e8d8f1 100644
--- a/spec/ruby/core/string/byteslice_spec.rb
+++ b/spec/ruby/core/string/byteslice_spec.rb
@@ -1,7 +1,7 @@
-# -*- encoding: binary -*-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes.rb', __FILE__)
-require File.expand_path('../shared/slice.rb', __FILE__)
+# encoding: binary
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/slice'
describe "String#byteslice" do
it "needs to reviewed for spec completeness"
@@ -17,13 +17,17 @@ describe "String#byteslice with Range" do
it_behaves_like :string_slice_range, :byteslice
end
-with_feature :encoding do
- describe "String#byteslice on on non ASCII strings" do
- it "returns byteslice of unicode strings" do
- "\u3042".byteslice(1).should == "\x81".force_encoding("UTF-8")
- "\u3042".byteslice(1, 2).should == "\x81\x82".force_encoding("UTF-8")
- "\u3042".byteslice(1..2).should == "\x81\x82".force_encoding("UTF-8")
- "\u3042".byteslice(-1).should == "\x82".force_encoding("UTF-8")
- end
+describe "String#byteslice on non ASCII strings" do
+ it "returns byteslice of unicode strings" do
+ "\u3042".byteslice(1).should == "\x81".dup.force_encoding("UTF-8")
+ "\u3042".byteslice(1, 2).should == "\x81\x82".dup.force_encoding("UTF-8")
+ "\u3042".byteslice(1..2).should == "\x81\x82".dup.force_encoding("UTF-8")
+ "\u3042".byteslice(-1).should == "\x82".dup.force_encoding("UTF-8")
+ end
+
+ it "returns a String in the same encoding as self" do
+ "ruby".encode("UTF-8").slice(0).encoding.should == Encoding::UTF_8
+ "ruby".encode("US-ASCII").slice(0).encoding.should == Encoding::US_ASCII
+ "ruby".encode("Windows-1251").slice(0).encoding.should == Encoding::Windows_1251
end
end
diff --git a/spec/ruby/core/string/bytesplice_spec.rb b/spec/ruby/core/string/bytesplice_spec.rb
new file mode 100644
index 0000000000..3e5e6fe1ee
--- /dev/null
+++ b/spec/ruby/core/string/bytesplice_spec.rb
@@ -0,0 +1,290 @@
+# -*- encoding: utf-8 -*-
+# frozen_string_literal: false
+require_relative '../../spec_helper'
+
+describe "String#bytesplice" do
+ it "raises IndexError when index is less than -bytesize" do
+ -> { "hello".bytesplice(-6, 0, "xxx") }.should.raise(IndexError, "index -6 out of string")
+ end
+
+ it "raises IndexError when index is greater than bytesize" do
+ -> { "hello".bytesplice(6, 0, "xxx") }.should.raise(IndexError, "index 6 out of string")
+ end
+
+ it "raises IndexError for negative length" do
+ -> { "abc".bytesplice(0, -2, "") }.should.raise(IndexError, "negative length -2")
+ end
+
+ it "replaces with integer indices" do
+ "hello".bytesplice(-5, 0, "xxx").should == "xxxhello"
+ "hello".bytesplice(0, 0, "xxx").should == "xxxhello"
+ "hello".bytesplice(0, 1, "xxx").should == "xxxello"
+ "hello".bytesplice(0, 5, "xxx").should == "xxx"
+ "hello".bytesplice(0, 6, "xxx").should == "xxx"
+ end
+
+ it "raises RangeError when range left boundary is less than -bytesize" do
+ -> { "hello".bytesplice(-6...-6, "xxx") }.should.raise(RangeError, "-6...-6 out of range")
+ end
+
+ it "replaces with ranges" do
+ "hello".bytesplice(-5...-5, "xxx").should == "xxxhello"
+ "hello".bytesplice(0...0, "xxx").should == "xxxhello"
+ "hello".bytesplice(0..0, "xxx").should == "xxxello"
+ "hello".bytesplice(0...1, "xxx").should == "xxxello"
+ "hello".bytesplice(0..1, "xxx").should == "xxxllo"
+ "hello".bytesplice(0..-1, "xxx").should == "xxx"
+ "hello".bytesplice(0...5, "xxx").should == "xxx"
+ "hello".bytesplice(0...6, "xxx").should == "xxx"
+ end
+
+ it "raises TypeError when integer index is provided without length argument" do
+ -> { "hello".bytesplice(0, "xxx") }.should.raise(TypeError, "wrong argument type Integer (expected Range)")
+ end
+
+ it "replaces on an empty string" do
+ "".bytesplice(0, 0, "").should == ""
+ "".bytesplice(0, 0, "xxx").should == "xxx"
+ end
+
+ it "mutates self" do
+ s = "hello"
+ s.bytesplice(2, 1, "xxx").should.equal?(s)
+ end
+
+ it "raises when string is frozen" do
+ s = "hello".freeze
+ -> { s.bytesplice(2, 1, "xxx") }.should.raise(FrozenError, "can't modify frozen String: \"hello\"")
+ end
+
+ it "raises IndexError when str_index is less than -bytesize" do
+ -> { "hello".bytesplice(2, 1, "HELLO", -6, 0) }.should.raise(IndexError, "index -6 out of string")
+ end
+
+ it "raises IndexError when str_index is greater than bytesize" do
+ -> { "hello".bytesplice(2, 1, "HELLO", 6, 0) }.should.raise(IndexError, "index 6 out of string")
+ end
+
+ it "raises IndexError for negative str length" do
+ -> { "abc".bytesplice(0, 1, "", 0, -2) }.should.raise(IndexError, "negative length -2")
+ end
+
+ it "replaces with integer str indices" do
+ "hello".bytesplice(1, 2, "HELLO", -5, 0).should == "hlo"
+ "hello".bytesplice(1, 2, "HELLO", 0, 0).should == "hlo"
+ "hello".bytesplice(1, 2, "HELLO", 0, 1).should == "hHlo"
+ "hello".bytesplice(1, 2, "HELLO", 0, 5).should == "hHELLOlo"
+ "hello".bytesplice(1, 2, "HELLO", 0, 6).should == "hHELLOlo"
+ end
+
+ it "raises RangeError when str range left boundary is less than -bytesize" do
+ -> { "hello".bytesplice(0..1, "HELLO", -6...-6) }.should.raise(RangeError, "-6...-6 out of range")
+ end
+
+ it "replaces with str ranges" do
+ "hello".bytesplice(1..2, "HELLO", -5...-5).should == "hlo"
+ "hello".bytesplice(1..2, "HELLO", 0...0).should == "hlo"
+ "hello".bytesplice(1..2, "HELLO", 0..0).should == "hHlo"
+ "hello".bytesplice(1..2, "HELLO", 0...1).should == "hHlo"
+ "hello".bytesplice(1..2, "HELLO", 0..1).should == "hHElo"
+ "hello".bytesplice(1..2, "HELLO", 0..-1).should == "hHELLOlo"
+ "hello".bytesplice(1..2, "HELLO", 0...5).should == "hHELLOlo"
+ "hello".bytesplice(1..2, "HELLO", 0...6).should == "hHELLOlo"
+ end
+
+ it "raises ArgumentError when integer str index is provided without str length argument" do
+ -> { "hello".bytesplice(0, 1, "xxx", 0) }.should.raise(ArgumentError, "wrong number of arguments (given 4, expected 2, 3, or 5)")
+ end
+
+ it "replaces on an empty string with str index/length" do
+ "".bytesplice(0, 0, "", 0, 0).should == ""
+ "".bytesplice(0, 0, "xxx", 0, 1).should == "x"
+ end
+
+ it "mutates self with substring and str index/length" do
+ s = "hello"
+ s.bytesplice(2, 1, "xxx", 1, 2).should.equal?(s)
+ s.should.eql?("hexxlo")
+ end
+
+ it "raises when string is frozen and str index/length" do
+ s = "hello".freeze
+ -> { s.bytesplice(2, 1, "xxx", 0, 1) }.should.raise(FrozenError, "can't modify frozen String: \"hello\"")
+ end
+
+ it "replaces on an empty string with str range" do
+ "".bytesplice(0..0, "", 0..0).should == ""
+ "".bytesplice(0..0, "xyz", 0..1).should == "xy"
+ end
+
+ it "mutates self with substring and str range" do
+ s = "hello"
+ s.bytesplice(2..2, "xyz", 1..2).should.equal?(s)
+ s.should.eql?("heyzlo")
+ end
+
+ it "raises when string is frozen and str range" do
+ s = "hello".freeze
+ -> { s.bytesplice(2..2, "yzx", 0..1) }.should.raise(FrozenError, "can't modify frozen String: \"hello\"")
+ end
+end
+
+describe "String#bytesplice with multibyte characters" do
+ it "raises IndexError when index is out of byte size boundary" do
+ -> { "ã“ã‚“ã«ã¡ã¯".bytesplice(-16, 0, "xxx") }.should.raise(IndexError, "index -16 out of string")
+ end
+
+ it "raises IndexError when index is not on a codepoint boundary" do
+ -> { "ã“ã‚“ã«ã¡ã¯".bytesplice(1, 0, "xxx") }.should.raise(IndexError, "offset 1 does not land on character boundary")
+ end
+
+ it "raises IndexError when length is not matching the codepoint boundary" do
+ -> { "ã“ã‚“ã«ã¡ã¯".bytesplice(0, 1, "xxx") }.should.raise(IndexError, "offset 1 does not land on character boundary")
+ -> { "ã“ã‚“ã«ã¡ã¯".bytesplice(0, 2, "xxx") }.should.raise(IndexError, "offset 2 does not land on character boundary")
+ end
+
+ it "replaces with integer indices" do
+ "ã“ã‚“ã«ã¡ã¯".bytesplice(-15, 0, "xxx").should == "xxxã“ã‚“ã«ã¡ã¯"
+ "ã“ã‚“ã«ã¡ã¯".bytesplice(0, 0, "xxx").should == "xxxã“ã‚“ã«ã¡ã¯"
+ "ã“ã‚“ã«ã¡ã¯".bytesplice(0, 3, "xxx").should == "xxxã‚“ã«ã¡ã¯"
+ "ã“ã‚“ã«ã¡ã¯".bytesplice(3, 3, "ã¯ã¯").should == "ã“ã¯ã¯ã«ã¡ã¯"
+ "ã“ã‚“ã«ã¡ã¯".bytesplice(15, 0, "xxx").should == "ã“ã‚“ã«ã¡ã¯xxx"
+ end
+
+ it "replaces with range" do
+ "ã“ã‚“ã«ã¡ã¯".bytesplice(-15...-16, "xxx").should == "xxxã“ã‚“ã«ã¡ã¯"
+ "ã“ã‚“ã«ã¡ã¯".bytesplice(0...0, "xxx").should == "xxxã“ã‚“ã«ã¡ã¯"
+ "ã“ã‚“ã«ã¡ã¯".bytesplice(0..2, "xxx").should == "xxxã‚“ã«ã¡ã¯"
+ "ã“ã‚“ã«ã¡ã¯".bytesplice(0...3, "xxx").should == "xxxã‚“ã«ã¡ã¯"
+ "ã“ã‚“ã«ã¡ã¯".bytesplice(0..5, "xxx").should == "xxxã«ã¡ã¯"
+ "ã“ã‚“ã«ã¡ã¯".bytesplice(0..-1, "xxx").should == "xxx"
+ "ã“ã‚“ã«ã¡ã¯".bytesplice(0...15, "xxx").should == "xxx"
+ "ã“ã‚“ã«ã¡ã¯".bytesplice(0...18, "xxx").should == "xxx"
+ end
+
+ it "treats negative length for range as 0" do
+ "ã“ã‚“ã«ã¡ã¯".bytesplice(0...-100, "xxx").should == "xxxã“ã‚“ã«ã¡ã¯"
+ "ã“ã‚“ã«ã¡ã¯".bytesplice(3...-100, "xxx").should == "ã“xxxã‚“ã«ã¡ã¯"
+ "ã“ã‚“ã«ã¡ã¯".bytesplice(-15...-100, "xxx").should == "xxxã“ã‚“ã«ã¡ã¯"
+ end
+
+ it "raises when ranges not match codepoint boundaries" do
+ -> { "ã“ã‚“ã«ã¡ã¯".bytesplice(0..0, "x") }.should.raise(IndexError, "offset 1 does not land on character boundary")
+ -> { "ã“ã‚“ã«ã¡ã¯".bytesplice(0..1, "x") }.should.raise(IndexError, "offset 2 does not land on character boundary")
+ # Begin is incorrect
+ -> { "ã“ã‚“ã«ã¡ã¯".bytesplice(-4..-1, "x") }.should.raise(IndexError, "offset 11 does not land on character boundary")
+ -> { "ã“ã‚“ã«ã¡ã¯".bytesplice(-5..-1, "x") }.should.raise(IndexError, "offset 10 does not land on character boundary")
+ # End is incorrect
+ -> { "ã“ã‚“ã«ã¡ã¯".bytesplice(-3..-2, "x") }.should.raise(IndexError, "offset 14 does not land on character boundary")
+ -> { "ã“ã‚“ã«ã¡ã¯".bytesplice(-3..-3, "x") }.should.raise(IndexError, "offset 13 does not land on character boundary")
+ end
+
+ it "deals with a different encoded argument" do
+ s = "ã“ã‚“ã«ã¡ã¯"
+ s.encoding.should == Encoding::UTF_8
+ sub = "xxxxxx"
+ sub.force_encoding(Encoding::US_ASCII)
+
+ result = s.bytesplice(0, 3, sub)
+ result.should == "xxxxxxã‚“ã«ã¡ã¯"
+ result.encoding.should == Encoding::UTF_8
+
+ s = "xxxxxx"
+ s.force_encoding(Encoding::US_ASCII)
+ sub = "ã“ã‚“ã«ã¡ã¯"
+ sub.encoding.should == Encoding::UTF_8
+
+ result = s.bytesplice(0, 3, sub)
+ result.should == "ã“ã‚“ã«ã¡ã¯xxx"
+ result.encoding.should == Encoding::UTF_8
+ end
+
+ it "raises IndexError when str_index is out of byte size boundary" do
+ -> { "ã“ã‚“ã«ã¡ã¯".bytesplice(3, 3, "ã“ã‚“ã«ã¡ã¯", -16, 0) }.should.raise(IndexError, "index -16 out of string")
+ end
+
+ it "raises IndexError when str_index is not on a codepoint boundary" do
+ -> { "ã“ã‚“ã«ã¡ã¯".bytesplice(3, 3, "ã“ã‚“ã«ã¡ã¯", 1, 0) }.should.raise(IndexError, "offset 1 does not land on character boundary")
+ end
+
+ it "raises IndexError when str_length is not matching the codepoint boundary" do
+ -> { "ã“ã‚“ã«ã¡ã¯".bytesplice(3, 3, "ã“ã‚“ã«ã¡ã¯", 0, 1) }.should.raise(IndexError, "offset 1 does not land on character boundary")
+ -> { "ã“ã‚“ã«ã¡ã¯".bytesplice(3, 3, "ã“ã‚“ã«ã¡ã¯", 0, 2) }.should.raise(IndexError, "offset 2 does not land on character boundary")
+ end
+
+ it "replaces with integer str indices" do
+ "ã“ã‚“ã«ã¡ã¯".bytesplice(3, 3, "ã“ã‚“ã«ã¡ã¯", -15, 0).should == "ã“ã«ã¡ã¯"
+ "ã“ã‚“ã«ã¡ã¯".bytesplice(3, 3, "ã“ã‚“ã«ã¡ã¯", 0, 0).should == "ã“ã«ã¡ã¯"
+ "ã“ã‚“ã«ã¡ã¯".bytesplice(3, 3, "ã“ã‚“ã«ã¡ã¯", 0, 3).should == "ã“ã“ã«ã¡ã¯"
+ "ã“ã‚“ã«ã¡ã¯".bytesplice(3, 3, "ã¯ã¯", 3, 3).should == "ã“ã¯ã«ã¡ã¯"
+ "ã“ã‚“ã«ã¡ã¯".bytesplice(3, 3, "ã“ã‚“ã«ã¡ã¯", 15, 0).should == "ã“ã«ã¡ã¯"
+ end
+
+ it "replaces with str range" do
+ "ã“ã‚“ã«ã¡ã¯".bytesplice(0..2, "ã“ã‚“ã«ã¡ã¯", -15...-16).should == "ã‚“ã«ã¡ã¯"
+ "ã“ã‚“ã«ã¡ã¯".bytesplice(0..2, "ã“ã‚“ã«ã¡ã¯", 0...0).should == "ã‚“ã«ã¡ã¯"
+ "ã“ã‚“ã«ã¡ã¯".bytesplice(0..2, "ã“ã‚“ã«ã¡ã¯", 3..5).should == "ã‚“ã‚“ã«ã¡ã¯"
+ "ã“ã‚“ã«ã¡ã¯".bytesplice(0..2, "ã“ã‚“ã«ã¡ã¯", 3...6).should == "ã‚“ã‚“ã«ã¡ã¯"
+ "ã“ã‚“ã«ã¡ã¯".bytesplice(0..2, "ã“ã‚“ã«ã¡ã¯", 3..8).should == "ã‚“ã«ã‚“ã«ã¡ã¯"
+ "ã“ã‚“ã«ã¡ã¯".bytesplice(0..2, "ã“ã‚“ã«ã¡ã¯", 0..-1).should == "ã“ã‚“ã«ã¡ã¯ã‚“ã«ã¡ã¯"
+ "ã“ã‚“ã«ã¡ã¯".bytesplice(0..2, "ã“ã‚“ã«ã¡ã¯", 0...15).should == "ã“ã‚“ã«ã¡ã¯ã‚“ã«ã¡ã¯"
+ "ã“ã‚“ã«ã¡ã¯".bytesplice(0..2, "ã“ã‚“ã«ã¡ã¯", 0...18).should == "ã“ã‚“ã«ã¡ã¯ã‚“ã«ã¡ã¯"
+ end
+
+ it "treats negative length for str range as 0" do
+ "ã“ã‚“ã«ã¡ã¯".bytesplice(0..2, "ã“ã‚“ã«ã¡ã¯", 0...-100).should == "ã‚“ã«ã¡ã¯"
+ "ã“ã‚“ã«ã¡ã¯".bytesplice(0..2, "ã“ã‚“ã«ã¡ã¯", 3...-100).should == "ã‚“ã«ã¡ã¯"
+ "ã“ã‚“ã«ã¡ã¯".bytesplice(0..2, "ã“ã‚“ã«ã¡ã¯", -15...-100).should == "ã‚“ã«ã¡ã¯"
+ end
+
+ it "raises when ranges not match codepoint boundaries in str" do
+ -> { "ã“ã‚“ã«ã¡ã¯".bytesplice(3...3, "ã“", 0..0) }.should.raise(IndexError, "offset 1 does not land on character boundary")
+ -> { "ã“ã‚“ã«ã¡ã¯".bytesplice(3...3, "ã“", 0..1) }.should.raise(IndexError, "offset 2 does not land on character boundary")
+ # Begin is incorrect
+ -> { "ã“ã‚“ã«ã¡ã¯".bytesplice(3...3, "ã“ã‚“ã«ã¡ã¯", -4..-1) }.should.raise(IndexError, "offset 11 does not land on character boundary")
+ -> { "ã“ã‚“ã«ã¡ã¯".bytesplice(3...3, "ã“ã‚“ã«ã¡ã¯", -5..-1) }.should.raise(IndexError, "offset 10 does not land on character boundary")
+ # End is incorrect
+ -> { "ã“ã‚“ã«ã¡ã¯".bytesplice(3...3, "ã“ã‚“ã«ã¡ã¯", -3..-2) }.should.raise(IndexError, "offset 14 does not land on character boundary")
+ -> { "ã“ã‚“ã«ã¡ã¯".bytesplice(3...3, "ã“ã‚“ã«ã¡ã¯", -3..-3) }.should.raise(IndexError, "offset 13 does not land on character boundary")
+ end
+
+ it "deals with a different encoded argument with str index/length" do
+ s = "ã“ã‚“ã«ã¡ã¯"
+ s.encoding.should == Encoding::UTF_8
+ sub = "goodbye"
+ sub.force_encoding(Encoding::US_ASCII)
+
+ result = s.bytesplice(3, 3, sub, 0, 3)
+ result.should == "ã“gooã«ã¡ã¯"
+ result.encoding.should == Encoding::UTF_8
+
+ s = "hello"
+ s.force_encoding(Encoding::US_ASCII)
+ sub = "ã“ã‚“ã«ã¡ã¯"
+ sub.encoding.should == Encoding::UTF_8
+
+ result = s.bytesplice(1, 2, sub, 3, 3)
+ result.should == "hã‚“lo"
+ result.encoding.should == Encoding::UTF_8
+ end
+
+ it "deals with a different encoded argument with str range" do
+ s = "ã“ã‚“ã«ã¡ã¯"
+ s.encoding.should == Encoding::UTF_8
+ sub = "goodbye"
+ sub.force_encoding(Encoding::US_ASCII)
+
+ result = s.bytesplice(3..5, sub, 0..2)
+ result.should == "ã“gooã«ã¡ã¯"
+ result.encoding.should == Encoding::UTF_8
+
+ s = "hello"
+ s.force_encoding(Encoding::US_ASCII)
+ sub = "ã“ã‚“ã«ã¡ã¯"
+ sub.encoding.should == Encoding::UTF_8
+
+ result = s.bytesplice(1..2, sub, 3..5)
+ result.should == "hã‚“lo"
+ result.encoding.should == Encoding::UTF_8
+ end
+end
diff --git a/spec/ruby/core/string/capitalize_spec.rb b/spec/ruby/core/string/capitalize_spec.rb
index 497e1453cd..12b1675c2e 100644
--- a/spec/ruby/core/string/capitalize_spec.rb
+++ b/spec/ruby/core/string/capitalize_spec.rb
@@ -1,6 +1,6 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes.rb', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "String#capitalize" do
it "returns a copy of self with the first character converted to uppercase and the remainder to lowercase" do
@@ -10,61 +10,198 @@ describe "String#capitalize" do
"hello".capitalize.should == "Hello"
"HELLO".capitalize.should == "Hello"
"123ABC".capitalize.should == "123abc"
+ "abcdef"[1...-1].capitalize.should == "Bcde"
end
- it "taints resulting string when self is tainted" do
- "".taint.capitalize.tainted?.should == true
- "hello".taint.capitalize.tainted?.should == true
+ describe "full Unicode case mapping" do
+ it "works for all of Unicode with no option" do
+ "äöÜ".capitalize.should == "Äöü"
+ end
+
+ it "only capitalizes the first resulting character when upcasing a character produces a multi-character sequence" do
+ "ß".capitalize.should == "Ss"
+ end
+
+ it "updates string metadata" do
+ capitalized = "ßeT".capitalize
+
+ capitalized.should == "Sset"
+ capitalized.size.should == 4
+ capitalized.bytesize.should == 4
+ capitalized.ascii_only?.should == true
+ end
end
- ruby_version_is ''...'2.4' do
- it "is locale insensitive (only upcases a-z and only downcases A-Z)" do
- "ÄÖÜ".capitalize.should == "ÄÖÜ"
- "ärger".capitalize.should == "ärger"
- "BÄR".capitalize.should == "BÄr"
+ describe "ASCII-only case mapping" do
+ it "does not capitalize non-ASCII characters" do
+ "ßet".capitalize(:ascii).should == "ßet"
+ end
+
+ it "handles non-ASCII substrings properly" do
+ "garçon"[1...-1].capitalize(:ascii).should == "Arço"
end
end
- ruby_version_is '2.4' do
- it "works for all of Unicode" do
- "äöü".capitalize.should == "Äöü"
+ describe "full Unicode case mapping adapted for Turkic languages" do
+ it "capitalizes ASCII characters according to Turkic semantics" do
+ "iSa".capitalize(:turkic).should == "İsa"
+ end
+
+ it "allows Lithuanian as an extra option" do
+ "iSa".capitalize(:turkic, :lithuanian).should == "İsa"
+ end
+
+ it "does not allow any other additional option" do
+ -> { "iSa".capitalize(:turkic, :ascii) }.should.raise(ArgumentError)
end
end
- it "returns subclass instances when called on a subclass" do
- StringSpecs::MyString.new("hello").capitalize.should be_an_instance_of(StringSpecs::MyString)
- StringSpecs::MyString.new("Hello").capitalize.should be_an_instance_of(StringSpecs::MyString)
+ describe "full Unicode case mapping adapted for Lithuanian" do
+ it "currently works the same as full Unicode case mapping" do
+ "iß".capitalize(:lithuanian).should == "Iß"
+ end
+
+ it "allows Turkic as an extra option (and applies Turkic semantics)" do
+ "iß".capitalize(:lithuanian, :turkic).should == "İß"
+ end
+
+ it "does not allow any other additional option" do
+ -> { "iß".capitalize(:lithuanian, :ascii) }.should.raise(ArgumentError)
+ end
+ end
+
+ it "does not allow the :fold option for upcasing" do
+ -> { "abc".capitalize(:fold) }.should.raise(ArgumentError)
+ end
+
+ it "does not allow invalid options" do
+ -> { "abc".capitalize(:invalid_option) }.should.raise(ArgumentError)
+ end
+
+ it "returns String instances when called on a subclass" do
+ StringSpecs::MyString.new("hello").capitalize.should.instance_of?(String)
+ StringSpecs::MyString.new("Hello").capitalize.should.instance_of?(String)
+ end
+
+ it "returns a String in the same encoding as self" do
+ "h".encode("US-ASCII").capitalize.encoding.should == Encoding::US_ASCII
end
end
describe "String#capitalize!" do
it "capitalizes self in place" do
- a = "hello"
- a.capitalize!.should equal(a)
+ a = +"hello"
+ a.capitalize!.should.equal?(a)
a.should == "Hello"
end
- ruby_version_is '2.4' do
- it "capitalizes self in place for all of Unicode" do
- a = "äöü"
- a.capitalize!.should equal(a)
+ it "modifies self in place for non-ascii-compatible encodings" do
+ a = "heLLo".encode("utf-16le")
+ a.capitalize!
+ a.should == "Hello".encode("utf-16le")
+ end
+
+ describe "full Unicode case mapping" do
+ it "modifies self in place for all of Unicode with no option" do
+ a = +"äöÜ"
+ a.capitalize!
a.should == "Äöü"
end
+
+ it "only capitalizes the first resulting character when upcasing a character produces a multi-character sequence" do
+ a = +"ß"
+ a.capitalize!
+ a.should == "Ss"
+ end
+
+ it "works for non-ascii-compatible encodings" do
+ a = "äöü".encode("utf-16le")
+ a.capitalize!
+ a.should == "Äöü".encode("utf-16le")
+ end
+
+ it "updates string metadata" do
+ capitalized = +"ßeT"
+ capitalized.capitalize!
+
+ capitalized.should == "Sset"
+ capitalized.size.should == 4
+ capitalized.bytesize.should == 4
+ capitalized.ascii_only?.should == true
+ end
+ end
+
+ describe "modifies self in place for ASCII-only case mapping" do
+ it "does not capitalize non-ASCII characters" do
+ a = +"ßet"
+ a.capitalize!(:ascii)
+ a.should == "ßet"
+ end
+
+ it "works for non-ascii-compatible encodings" do
+ a = "aBc".encode("utf-16le")
+ a.capitalize!(:ascii)
+ a.should == "Abc".encode("utf-16le")
+ end
+ end
+
+ describe "modifies self in place for full Unicode case mapping adapted for Turkic languages" do
+ it "capitalizes ASCII characters according to Turkic semantics" do
+ a = +"iSa"
+ a.capitalize!(:turkic)
+ a.should == "İsa"
+ end
+
+ it "allows Lithuanian as an extra option" do
+ a = +"iSa"
+ a.capitalize!(:turkic, :lithuanian)
+ a.should == "İsa"
+ end
+
+ it "does not allow any other additional option" do
+ -> { a = "iSa"; a.capitalize!(:turkic, :ascii) }.should.raise(ArgumentError)
+ end
+ end
+
+ describe "modifies self in place for full Unicode case mapping adapted for Lithuanian" do
+ it "currently works the same as full Unicode case mapping" do
+ a = +"iß"
+ a.capitalize!(:lithuanian)
+ a.should == "Iß"
+ end
+
+ it "allows Turkic as an extra option (and applies Turkic semantics)" do
+ a = +"iß"
+ a.capitalize!(:lithuanian, :turkic)
+ a.should == "İß"
+ end
+
+ it "does not allow any other additional option" do
+ -> { a = "iß"; a.capitalize!(:lithuanian, :ascii) }.should.raise(ArgumentError)
+ end
+ end
+
+ it "does not allow the :fold option for upcasing" do
+ -> { a = "abc"; a.capitalize!(:fold) }.should.raise(ArgumentError)
+ end
+
+ it "does not allow invalid options" do
+ -> { a = "abc"; a.capitalize!(:invalid_option) }.should.raise(ArgumentError)
end
it "returns nil when no changes are made" do
- a = "Hello"
+ a = +"Hello"
a.capitalize!.should == nil
a.should == "Hello"
- "".capitalize!.should == nil
- "H".capitalize!.should == nil
+ (+"").capitalize!.should == nil
+ (+"H").capitalize!.should == nil
end
- it "raises a RuntimeError when self is frozen" do
+ it "raises a FrozenError when self is frozen" do
["", "Hello", "hello"].each do |a|
a.freeze
- lambda { a.capitalize! }.should raise_error(RuntimeError)
+ -> { a.capitalize! }.should.raise(FrozenError)
end
end
end
diff --git a/spec/ruby/core/string/case_compare_spec.rb b/spec/ruby/core/string/case_compare_spec.rb
index 930f5bea90..f98ec003be 100644
--- a/spec/ruby/core/string/case_compare_spec.rb
+++ b/spec/ruby/core/string/case_compare_spec.rb
@@ -1,8 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/eql', __FILE__)
-require File.expand_path('../shared/equal_value', __FILE__)
+require_relative '../../spec_helper'
describe "String#===" do
- it_behaves_like(:string_eql_value, :===)
- it_behaves_like(:string_equal_value, :===)
+ it "is an alias of String#==" do
+ String.instance_method(:===).should == String.instance_method(:==)
+ end
end
diff --git a/spec/ruby/core/string/casecmp_spec.rb b/spec/ruby/core/string/casecmp_spec.rb
index c77d97815c..90577aaac0 100644
--- a/spec/ruby/core/string/casecmp_spec.rb
+++ b/spec/ruby/core/string/casecmp_spec.rb
@@ -1,6 +1,6 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes.rb', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "String#casecmp independent of case" do
it "returns -1 when less than other" do
@@ -25,16 +25,12 @@ describe "String#casecmp independent of case" do
"abc".casecmp(other).should == 0
end
- ruby_version_is ""..."2.5" do
- it "raises a TypeError if other can't be converted to a string" do
- lambda { "abc".casecmp(mock('abc')) }.should raise_error(TypeError)
- end
+ it "returns nil if other can't be converted to a string" do
+ "abc".casecmp(mock('abc')).should == nil
end
- ruby_version_is "2.5" do
- it "returns nil if other can't be converted to a string" do
- "abc".casecmp(mock('abc')).should be_nil
- end
+ it "returns nil if incompatible encodings" do
+ "ã‚れ".casecmp("れ".encode(Encoding::EUC_JP)).should == nil
end
describe "in UTF-8 mode" do
@@ -96,6 +92,10 @@ describe "String#casecmp independent of case" do
it "returns 1 when numerically greater than other" do
@lower_a_tilde.casecmp(@upper_a_tilde).should == 1
end
+
+ it "does not case fold" do
+ "ß".casecmp("ss").should == 1
+ end
end
describe "when comparing a subclass instance" do
@@ -117,68 +117,88 @@ describe "String#casecmp independent of case" do
"B".casecmp(a).should == 1
end
end
+
+ it "returns 0 for empty strings in different encodings" do
+ ''.b.casecmp('').should == 0
+ ''.b.casecmp(''.encode("UTF-32LE")).should == 0
+ end
end
-ruby_version_is "2.4" do
- describe 'String#casecmp? independent of case' do
- it 'returns true when equal to other' do
- 'abc'.casecmp?('abc').should == true
- 'abc'.casecmp?('ABC').should == true
- end
+describe 'String#casecmp? independent of case' do
+ it 'returns true when equal to other' do
+ 'abc'.casecmp?('abc').should == true
+ 'abc'.casecmp?('ABC').should == true
+ end
- it 'returns false when not equal to other' do
- 'abc'.casecmp?('DEF').should == false
- 'abc'.casecmp?('def').should == false
+ it 'returns false when not equal to other' do
+ 'abc'.casecmp?('DEF').should == false
+ 'abc'.casecmp?('def').should == false
+ end
+
+ it "tries to convert other to string using to_str" do
+ other = mock('x')
+ other.should_receive(:to_str).and_return("abc")
+
+ "abc".casecmp?(other).should == true
+ end
+
+ it "returns nil if incompatible encodings" do
+ "ã‚れ".casecmp?("れ".encode(Encoding::EUC_JP)).should == nil
+ end
+
+ describe 'for UNICODE characters' do
+ it 'returns true when downcase(:fold) on unicode' do
+ 'äöü'.casecmp?('ÄÖÜ').should == true
end
+ end
- it "tries to convert other to string using to_str" do
- other = mock('x')
- other.should_receive(:to_str).and_return("abc")
+ describe "when comparing a subclass instance" do
+ it 'returns true when equal to other' do
+ a = StringSpecs::MyString.new "a"
+ 'a'.casecmp?(a).should == true
+ 'A'.casecmp?(a).should == true
+ end
- "abc".casecmp?(other).should == true
+ it 'returns false when not equal to other' do
+ b = StringSpecs::MyString.new "a"
+ 'b'.casecmp?(b).should == false
+ 'B'.casecmp?(b).should == false
end
+ end
- describe 'for UNICODE characters' do
- it 'returns true when downcase(:fold) on unicode' do
- 'äöü'.casecmp?('ÄÖÜ').should == true
+ describe "in UTF-8 mode" do
+ describe "for non-ASCII characters" do
+ before :each do
+ @upper_a_tilde = "Ã"
+ @lower_a_tilde = "ã"
+ @upper_a_umlaut = "Ä"
+ @lower_a_umlaut = "ä"
end
- end
- describe "when comparing a subclass instance" do
- it 'returns true when equal to other' do
- a = StringSpecs::MyString.new "a"
- 'a'.casecmp?(a).should == true
- 'A'.casecmp?(a).should == true
+ it "returns true when they are the same with normalized case" do
+ @upper_a_tilde.casecmp?(@lower_a_tilde).should == true
end
- it 'returns false when not equal to other' do
- b = StringSpecs::MyString.new "a"
- 'b'.casecmp?(b).should == false
- 'B'.casecmp?(b).should == false
+ it "returns false when they are unrelated" do
+ @upper_a_tilde.casecmp?(@upper_a_umlaut).should == false
end
- end
- describe "in UTF-8 mode" do
- describe "for non-ASCII characters" do
- before :each do
- @upper_a_tilde = "Ã"
- @lower_a_tilde = "ã"
- @upper_a_umlaut = "Ä"
- @lower_a_umlaut = "ä"
- end
-
- it "returns true when they are the same with normalized case" do
- @upper_a_tilde.casecmp?(@lower_a_tilde).should == true
- end
-
- it "returns false when they are unrelated" do
- @upper_a_tilde.casecmp?(@upper_a_umlaut).should == false
- end
-
- it "returns true when they have the same bytes" do
- @upper_a_tilde.casecmp?(@upper_a_tilde).should == true
- end
+ it "returns true when they have the same bytes" do
+ @upper_a_tilde.casecmp?(@upper_a_tilde).should == true
end
end
end
+
+ it "case folds" do
+ "ß".casecmp?("ss").should == true
+ end
+
+ it "returns nil if other can't be converted to a string" do
+ "abc".casecmp?(mock('abc')).should == nil
+ end
+
+ it "returns true for empty strings in different encodings" do
+ ''.b.should.casecmp?('')
+ ''.b.should.casecmp?(''.encode("UTF-32LE"))
+ end
end
diff --git a/spec/ruby/core/string/center_spec.rb b/spec/ruby/core/string/center_spec.rb
index 4a40ef88bf..ac5b8a2ff3 100644
--- a/spec/ruby/core/string/center_spec.rb
+++ b/spec/ruby/core/string/center_spec.rb
@@ -1,6 +1,6 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes.rb', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "String#center with length, padding" do
it "returns a new string of specified length with self centered and padded with padstr" do
@@ -47,14 +47,6 @@ describe "String#center with length, padding" do
"radiology".center(8, '-').should == "radiology"
end
- it "taints result when self or padstr is tainted" do
- "x".taint.center(4).tainted?.should == true
- "x".taint.center(0).tainted?.should == true
- "".taint.center(0).tainted?.should == true
- "x".taint.center(4, "*").tainted?.should == true
- "x".center(4, "*".taint).tainted?.should == true
- end
-
it "calls #to_int to convert length to an integer" do
"_".center(3.8, "^").should == "^_^"
@@ -65,10 +57,10 @@ describe "String#center with length, padding" do
end
it "raises a TypeError when length can't be converted to an integer" do
- lambda { "hello".center("x") }.should raise_error(TypeError)
- lambda { "hello".center("x", "y") }.should raise_error(TypeError)
- lambda { "hello".center([]) }.should raise_error(TypeError)
- lambda { "hello".center(mock('x')) }.should raise_error(TypeError)
+ -> { "hello".center("x") }.should.raise(TypeError)
+ -> { "hello".center("x", "y") }.should.raise(TypeError)
+ -> { "hello".center([]) }.should.raise(TypeError)
+ -> { "hello".center(mock('x')) }.should.raise(TypeError)
end
it "calls #to_str to convert padstr to a String" do
@@ -79,55 +71,47 @@ describe "String#center with length, padding" do
end
it "raises a TypeError when padstr can't be converted to a string" do
- lambda { "hello".center(20, 100) }.should raise_error(TypeError)
- lambda { "hello".center(20, []) }.should raise_error(TypeError)
- lambda { "hello".center(20, mock('x')) }.should raise_error(TypeError)
+ -> { "hello".center(20, 100) }.should.raise(TypeError)
+ -> { "hello".center(20, []) }.should.raise(TypeError)
+ -> { "hello".center(20, mock('x')) }.should.raise(TypeError)
end
it "raises an ArgumentError if padstr is empty" do
- lambda { "hello".center(10, "") }.should raise_error(ArgumentError)
- lambda { "hello".center(0, "") }.should raise_error(ArgumentError)
+ -> { "hello".center(10, "") }.should.raise(ArgumentError)
+ -> { "hello".center(0, "") }.should.raise(ArgumentError)
end
- it "returns subclass instances when called on subclasses" do
- StringSpecs::MyString.new("").center(10).should be_an_instance_of(StringSpecs::MyString)
- StringSpecs::MyString.new("foo").center(10).should be_an_instance_of(StringSpecs::MyString)
- StringSpecs::MyString.new("foo").center(10, StringSpecs::MyString.new("x")).should be_an_instance_of(StringSpecs::MyString)
+ it "returns String instances when called on subclasses" do
+ StringSpecs::MyString.new("").center(10).should.instance_of?(String)
+ StringSpecs::MyString.new("foo").center(10).should.instance_of?(String)
+ StringSpecs::MyString.new("foo").center(10, StringSpecs::MyString.new("x")).should.instance_of?(String)
- "".center(10, StringSpecs::MyString.new("x")).should be_an_instance_of(String)
- "foo".center(10, StringSpecs::MyString.new("x")).should be_an_instance_of(String)
+ "".center(10, StringSpecs::MyString.new("x")).should.instance_of?(String)
+ "foo".center(10, StringSpecs::MyString.new("x")).should.instance_of?(String)
end
- it "when padding is tainted and self is untainted returns a tainted string if and only if length is longer than self" do
- "hello".center(4, 'X'.taint).tainted?.should be_false
- "hello".center(5, 'X'.taint).tainted?.should be_false
- "hello".center(6, 'X'.taint).tainted?.should be_true
+ describe "with width" do
+ it "returns a String in the same encoding as the original" do
+ str = "abc".dup.force_encoding Encoding::IBM437
+ result = str.center 6
+ result.should == " abc "
+ result.encoding.should.equal?(Encoding::IBM437)
+ end
end
- with_feature :encoding do
- describe "with width" do
- it "returns a String in the same encoding as the original" do
- str = "abc".force_encoding Encoding::IBM437
- result = str.center 6
- result.should == " abc "
- result.encoding.should equal(Encoding::IBM437)
- end
+ describe "with width, pattern" do
+ it "returns a String in the compatible encoding" do
+ str = "abc".dup.force_encoding Encoding::IBM437
+ result = str.center 6, "ã‚"
+ result.should == "ã‚abcã‚ã‚"
+ result.encoding.should.equal?(Encoding::UTF_8)
end
- describe "with width, pattern" do
- it "returns a String in the compatible encoding" do
- str = "abc".force_encoding Encoding::IBM437
- result = str.center 6, "ã‚"
- result.should == "ã‚abcã‚ã‚"
- result.encoding.should equal(Encoding::UTF_8)
- end
-
- it "raises an Encoding::CompatibilityError if the encodings are incompatible" do
- pat = "ã‚¢".encode Encoding::EUC_JP
- lambda do
- "ã‚れ".center 5, pat
- end.should raise_error(Encoding::CompatibilityError)
- end
+ it "raises an Encoding::CompatibilityError if the encodings are incompatible" do
+ pat = "ã‚¢".encode Encoding::EUC_JP
+ -> do
+ "ã‚れ".center 5, pat
+ end.should.raise(Encoding::CompatibilityError)
end
end
end
diff --git a/spec/ruby/core/string/chars_spec.rb b/spec/ruby/core/string/chars_spec.rb
index 75cef89be1..ee85430574 100644
--- a/spec/ruby/core/string/chars_spec.rb
+++ b/spec/ruby/core/string/chars_spec.rb
@@ -1,11 +1,16 @@
-require File.expand_path('../shared/chars', __FILE__)
-require File.expand_path('../shared/each_char_without_block', __FILE__)
+require_relative "../../spec_helper"
+require_relative 'shared/chars'
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)
- ary.should == ['h', 'e', 'l', 'l', 'o']
+ "hello".chars.should == ['h', 'e', 'l', 'l', 'o']
+ end
+
+ it "returns Strings in the same encoding as self" do
+ "hello".encode("US-ASCII").chars.each do |c|
+ c.encoding.should == Encoding::US_ASCII
+ end
end
end
diff --git a/spec/ruby/core/string/chilled_string_spec.rb b/spec/ruby/core/string/chilled_string_spec.rb
new file mode 100644
index 0000000000..6a5e846db2
--- /dev/null
+++ b/spec/ruby/core/string/chilled_string_spec.rb
@@ -0,0 +1,151 @@
+require_relative '../../spec_helper'
+
+describe "chilled String" do
+ guard -> { ruby_version_is "3.4" and !"test".equal?("test") } do
+ describe "chilled string literals" do
+
+ describe "#frozen?" do
+ it "returns false" do
+ "chilled".frozen?.should == false
+ end
+ end
+
+ describe "#-@" do
+ it "returns a different instance" do
+ input = "chilled"
+ interned = (-input)
+ interned.frozen?.should == true
+ interned.object_id.should_not == input.object_id
+ end
+ end
+
+ describe "#+@" do
+ it "returns a different instance" do
+ input = "chilled"
+ duped = (+input)
+ duped.frozen?.should == false
+ duped.object_id.should_not == input.object_id
+ end
+ end
+
+ describe "#clone" do
+ it "preserves chilled status" do
+ input = "chilled".clone
+ -> {
+ input << "-mutated"
+ }.should complain(/literal string will be frozen in the future/)
+ input.should == "chilled-mutated"
+ end
+ end
+
+ describe "mutation" do
+ it "emits a warning" do
+ input = "chilled"
+ -> {
+ input << "-mutated"
+ }.should complain(/literal string will be frozen in the future/)
+ input.should == "chilled-mutated"
+ end
+
+ it "emits a warning for concatenated strings" do
+ input = "still" "+chilled"
+ -> {
+ input << "-mutated"
+ }.should complain(/literal string will be frozen in the future/)
+ input.should == "still+chilled-mutated"
+ end
+
+ it "emits a warning on singleton_class creation" do
+ -> {
+ "chilled".singleton_class
+ }.should complain(/literal string will be frozen in the future/)
+ end
+
+ it "emits a warning on instance variable assignment" do
+ -> {
+ "chilled".instance_variable_set(:@ivar, 42)
+ }.should complain(/literal string will be frozen in the future/)
+ end
+
+ it "raises FrozenError after the string was explicitly frozen" do
+ input = "chilled"
+ input.freeze
+ -> {
+ -> {
+ input << "mutated"
+ }.should.raise(FrozenError)
+ }.should_not complain(/literal string will be frozen in the future/)
+ end
+ end
+ end
+
+ describe "chilled strings returned by Symbol#to_s" do
+
+ describe "#frozen?" do
+ it "returns false" do
+ :chilled.to_s.frozen?.should == false
+ end
+ end
+
+ describe "#-@" do
+ it "returns a different instance" do
+ input = :chilled.to_s
+ interned = (-input)
+ interned.frozen?.should == true
+ interned.object_id.should_not == input.object_id
+ end
+ end
+
+ describe "#+@" do
+ it "returns a different instance" do
+ input = :chilled.to_s
+ duped = (+input)
+ duped.frozen?.should == false
+ duped.object_id.should_not == input.object_id
+ end
+ end
+
+ describe "#clone" do
+ it "preserves chilled status" do
+ input = :chilled.to_s.clone
+ -> {
+ input << "-mutated"
+ }.should complain(/string returned by :chilled\.to_s will be frozen in the future/)
+ input.should == "chilled-mutated"
+ end
+ end
+
+ describe "mutation" do
+ it "emits a warning" do
+ input = :chilled.to_s
+ -> {
+ input << "-mutated"
+ }.should complain(/string returned by :chilled\.to_s will be frozen in the future/)
+ input.should == "chilled-mutated"
+ end
+
+ it "emits a warning on singleton_class creation" do
+ -> {
+ :chilled.to_s.singleton_class
+ }.should complain(/string returned by :chilled\.to_s will be frozen in the future/)
+ end
+
+ it "emits a warning on instance variable assignment" do
+ -> {
+ :chilled.to_s.instance_variable_set(:@ivar, 42)
+ }.should complain(/string returned by :chilled\.to_s will be frozen in the future/)
+ end
+
+ it "raises FrozenError after the string was explicitly frozen" do
+ input = :chilled.to_s
+ input.freeze
+ -> {
+ -> {
+ input << "mutated"
+ }.should.raise(FrozenError)
+ }.should_not complain(/string returned by :chilled\.to_s will be frozen in the future/)
+ end
+ end
+ end
+ end
+end
diff --git a/spec/ruby/core/string/chomp_spec.rb b/spec/ruby/core/string/chomp_spec.rb
index 5daa8c5a40..3a8550892f 100644
--- a/spec/ruby/core/string/chomp_spec.rb
+++ b/spec/ruby/core/string/chomp_spec.rb
@@ -1,16 +1,19 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes.rb', __FILE__)
+# frozen_string_literal: false
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "String#chomp" do
describe "when passed no argument" do
before do
# Ensure that $/ is set to the default value
+ @verbose, $VERBOSE = $VERBOSE, nil
@dollar_slash, $/ = $/, "\n"
end
after do
$/ = @dollar_slash
+ $VERBOSE = @verbose
end
it "does not modify a String with no trailing carriage return or newline" do
@@ -19,7 +22,7 @@ describe "String#chomp" do
it "returns a copy of the String when it is not modified" do
str = "abc"
- str.chomp.should_not equal(str)
+ str.chomp.should_not.equal?(str)
end
it "removes one trailing newline" do
@@ -30,7 +33,7 @@ describe "String#chomp" do
"abc\r\r".chomp.should == "abc\r"
end
- it "removes one trailing carrige return, newline pair" do
+ it "removes one trailing carriage return, newline pair" do
"abc\r\n\r\n".chomp.should == "abc\r\n"
end
@@ -38,19 +41,23 @@ describe "String#chomp" do
"".chomp.should == ""
end
- it "taints the result if self is tainted" do
- "abc".taint.chomp.tainted?.should be_true
+ it "returns a String in the same encoding as self" do
+ "abc\n\n".encode("US-ASCII").chomp.encoding.should == Encoding::US_ASCII
end
- it "returns subclass instances when called on a subclass" do
+ it "returns String instances when called on a subclass" do
str = StringSpecs::MyString.new("hello\n").chomp
- str.should be_an_instance_of(StringSpecs::MyString)
+ str.should.instance_of?(String)
end
it "removes trailing characters that match $/ when it has been assigned a value" do
$/ = "cdef"
"abcdef".chomp.should == "ab"
end
+
+ it "removes one trailing newline for string with invalid encoding" do
+ "\xa0\xa1\n".chomp.should == "\xa0\xa1"
+ end
end
describe "when passed nil" do
@@ -60,11 +67,7 @@ describe "String#chomp" do
it "returns a copy of the String" do
str = "abc"
- str.chomp(nil).should_not equal(str)
- end
-
- it "taints the result if self is tainted" do
- "abc".taint.chomp(nil).tainted?.should be_true
+ str.chomp(nil).should_not.equal?(str)
end
it "returns an empty String when self is empty" do
@@ -93,13 +96,13 @@ describe "String#chomp" do
"abc\r\n\r\n\r\n".chomp("").should == "abc"
end
- it "taints the result if self is tainted" do
- "abc".taint.chomp("").tainted?.should be_true
- end
-
it "returns an empty String when self is empty" do
"".chomp("").should == ""
end
+
+ it "removes one trailing newline for string with invalid encoding" do
+ "\xa0\xa1\n".chomp("").should == "\xa0\xa1"
+ end
end
describe "when passed '\\n'" do
@@ -111,14 +114,10 @@ describe "String#chomp" do
"abc\r\r".chomp("\n").should == "abc\r"
end
- it "removes one trailing carrige return, newline pair" do
+ it "removes one trailing carriage return, newline pair" do
"abc\r\n\r\n".chomp("\n").should == "abc\r\n"
end
- it "taints the result if self is tainted" do
- "abc".taint.chomp("\n").tainted?.should be_true
- end
-
it "returns an empty String when self is empty" do
"".chomp("\n").should == ""
end
@@ -134,7 +133,7 @@ describe "String#chomp" do
it "raises a TypeError if #to_str does not return a String" do
arg = mock("string chomp")
arg.should_receive(:to_str).and_return(1)
- lambda { "abc".chomp(arg) }.should raise_error(TypeError)
+ -> { "abc".chomp(arg) }.should.raise(TypeError)
end
end
@@ -151,12 +150,8 @@ describe "String#chomp" do
"".chomp("abc").should == ""
end
- it "taints the result if self is tainted" do
- "abc".taint.chomp("abc").tainted?.should be_true
- end
-
- it "does not taint the result when the argument is tainted" do
- "abc".chomp("abc".taint).tainted?.should be_false
+ it "returns an empty String when the argument equals self" do
+ "abc".chomp("abc").should == ""
end
end
end
@@ -165,20 +160,22 @@ describe "String#chomp!" do
describe "when passed no argument" do
before do
# Ensure that $/ is set to the default value
+ @verbose, $VERBOSE = $VERBOSE, nil
@dollar_slash, $/ = $/, "\n"
end
after do
$/ = @dollar_slash
+ $VERBOSE = @verbose
end
it "modifies self" do
str = "abc\n"
- str.chomp!.should equal(str)
+ str.chomp!.should.equal?(str)
end
it "returns nil if self is not modified" do
- "abc".chomp!.should be_nil
+ "abc".chomp!.should == nil
end
it "removes one trailing newline" do
@@ -189,21 +186,17 @@ describe "String#chomp!" do
"abc\r\r".chomp!.should == "abc\r"
end
- it "removes one trailing carrige return, newline pair" do
+ it "removes one trailing carriage return, newline pair" do
"abc\r\n\r\n".chomp!.should == "abc\r\n"
end
it "returns nil when self is empty" do
- "".chomp!.should be_nil
- end
-
- it "taints the result if self is tainted" do
- "abc\n".taint.chomp!.tainted?.should be_true
+ "".chomp!.should == nil
end
it "returns subclass instances when called on a subclass" do
str = StringSpecs::MyString.new("hello\n").chomp!
- str.should be_an_instance_of(StringSpecs::MyString)
+ str.should.instance_of?(StringSpecs::MyString)
end
it "removes trailing characters that match $/ when it has been assigned a value" do
@@ -214,11 +207,11 @@ describe "String#chomp!" do
describe "when passed nil" do
it "returns nil" do
- "abc\r\n".chomp!(nil).should be_nil
+ "abc\r\n".chomp!(nil).should == nil
end
it "returns nil when self is empty" do
- "".chomp!(nil).should be_nil
+ "".chomp!(nil).should == nil
end
end
@@ -232,7 +225,7 @@ describe "String#chomp!" do
end
it "does not remove a final carriage return" do
- "abc\r".chomp!("").should be_nil
+ "abc\r".chomp!("").should == nil
end
it "removes more than one trailing newlines" do
@@ -243,12 +236,8 @@ describe "String#chomp!" do
"abc\r\n\r\n\r\n".chomp!("").should == "abc"
end
- it "taints the result if self is tainted" do
- "abc\n".taint.chomp!("").tainted?.should be_true
- end
-
it "returns nil when self is empty" do
- "".chomp!("").should be_nil
+ "".chomp!("").should == nil
end
end
@@ -261,16 +250,12 @@ describe "String#chomp!" do
"abc\r\r".chomp!("\n").should == "abc\r"
end
- it "removes one trailing carrige return, newline pair" do
+ it "removes one trailing carriage return, newline pair" do
"abc\r\n\r\n".chomp!("\n").should == "abc\r\n"
end
- it "taints the result if self is tainted" do
- "abc\n".taint.chomp!("\n").tainted?.should be_true
- end
-
it "returns nil when self is empty" do
- "".chomp!("\n").should be_nil
+ "".chomp!("\n").should == nil
end
end
@@ -284,7 +269,7 @@ describe "String#chomp!" do
it "raises a TypeError if #to_str does not return a String" do
arg = mock("string chomp")
arg.should_receive(:to_str).and_return(1)
- lambda { "abc".chomp!(arg) }.should raise_error(TypeError)
+ -> { "abc".chomp!(arg) }.should.raise(TypeError)
end
end
@@ -294,94 +279,88 @@ describe "String#chomp!" do
end
it "returns nil if the argument does not match the trailing characters" do
- "abc".chomp!("def").should be_nil
+ "abc".chomp!("def").should == nil
end
it "returns nil when self is empty" do
- "".chomp!("abc").should be_nil
- end
-
- it "taints the result if self is tainted" do
- "abc".taint.chomp!("abc").tainted?.should be_true
- end
-
- it "does not taint the result when the argument is tainted" do
- "abc".chomp!("abc".taint).tainted?.should be_false
+ "".chomp!("abc").should == nil
end
end
- it "raises a RuntimeError on a frozen instance when it is modified" do
+ it "raises a FrozenError on a frozen instance when it is modified" do
a = "string\n\r"
a.freeze
- lambda { a.chomp! }.should raise_error(RuntimeError)
+ -> { a.chomp! }.should.raise(FrozenError)
end
# see [ruby-core:23666]
- it "raises a RuntimeError on a frozen instance when it would not be modified" do
+ it "raises a FrozenError on a frozen instance when it would not be modified" do
a = "string\n\r"
a.freeze
- lambda { a.chomp!(nil) }.should raise_error(RuntimeError)
- lambda { a.chomp!("x") }.should raise_error(RuntimeError)
+ -> { a.chomp!(nil) }.should.raise(FrozenError)
+ -> { a.chomp!("x") }.should.raise(FrozenError)
end
end
-with_feature :encoding do
- describe "String#chomp" do
- before :each do
- @before_separator = $/
- end
+describe "String#chomp" do
+ before :each do
+ @verbose, $VERBOSE = $VERBOSE, nil
+ @before_separator = $/
+ end
- after :each do
- $/ = @before_separator
- end
+ after :each do
+ $/ = @before_separator
+ $VERBOSE = @verbose
+ end
- it "does not modify a multi-byte character" do
- "ã‚れ".chomp.should == "ã‚れ"
- end
+ it "does not modify a multi-byte character" do
+ "ã‚れ".chomp.should == "ã‚れ"
+ end
- it "removes the final carriage return, newline from a multibyte String" do
- "ã‚れ\r\n".chomp.should == "ã‚れ"
- end
+ it "removes the final carriage return, newline from a multibyte String" do
+ "ã‚れ\r\n".chomp.should == "ã‚れ"
+ end
- it "removes the final carriage return, newline from a non-ASCII String" do
- str = "abc\r\n".encode "utf-32be"
- str.chomp.should == "abc".encode("utf-32be")
- end
+ it "removes the final carriage return, newline from a non-ASCII String" do
+ str = "abc\r\n".encode "utf-32be"
+ str.chomp.should == "abc".encode("utf-32be")
+ end
- it "removes the final carriage return, newline from a non-ASCII String when the record separator is changed" do
- $/ = "\n".encode("utf-8")
- str = "abc\r\n".encode "utf-32be"
- str.chomp.should == "abc".encode("utf-32be")
- end
+ it "removes the final carriage return, newline from a non-ASCII String when the record separator is changed" do
+ $/ = "\n".encode("utf-8")
+ str = "abc\r\n".encode "utf-32be"
+ str.chomp.should == "abc".encode("utf-32be")
end
+end
- describe "String#chomp!" do
- before :each do
- @before_separator = $/
- end
+describe "String#chomp!" do
+ before :each do
+ @verbose, $VERBOSE = $VERBOSE, nil
+ @before_separator = $/
+ end
- after :each do
- $/ = @before_separator
- end
+ after :each do
+ $/ = @before_separator
+ $VERBOSE = @verbose
+ end
- it "returns nil when the String is not modified" do
- "ã‚れ".chomp!.should be_nil
- end
+ it "returns nil when the String is not modified" do
+ "ã‚れ".chomp!.should == nil
+ end
- it "removes the final carriage return, newline from a multibyte String" do
- "ã‚れ\r\n".chomp!.should == "ã‚れ"
- end
+ it "removes the final carriage return, newline from a multibyte String" do
+ "ã‚れ\r\n".chomp!.should == "ã‚れ"
+ end
- it "removes the final carriage return, newline from a non-ASCII String" do
- str = "abc\r\n".encode "utf-32be"
- str.chomp!.should == "abc".encode("utf-32be")
- end
+ it "removes the final carriage return, newline from a non-ASCII String" do
+ str = "abc\r\n".encode "utf-32be"
+ str.chomp!.should == "abc".encode("utf-32be")
+ end
- it "removes the final carriage return, newline from a non-ASCII String when the record separator is changed" do
- $/ = "\n".encode("utf-8")
- str = "abc\r\n".encode "utf-32be"
- str.chomp!.should == "abc".encode("utf-32be")
- end
+ it "removes the final carriage return, newline from a non-ASCII String when the record separator is changed" do
+ $/ = "\n".encode("utf-8")
+ str = "abc\r\n".encode "utf-32be"
+ str.chomp!.should == "abc".encode("utf-32be")
end
end
diff --git a/spec/ruby/core/string/chop_spec.rb b/spec/ruby/core/string/chop_spec.rb
index 4e9a39f866..2113da543b 100644
--- a/spec/ruby/core/string/chop_spec.rb
+++ b/spec/ruby/core/string/chop_spec.rb
@@ -1,6 +1,7 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes.rb', __FILE__)
+# frozen_string_literal: false
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "String#chop" do
it "removes the final character" do
@@ -19,7 +20,7 @@ describe "String#chop" do
"abc\r\n".chop.should == "abc"
end
- it "removes the carrige return, newline if they are the only characters" do
+ it "removes the carriage return, newline if they are the only characters" do
"\r\n".chop.should == ""
end
@@ -27,19 +28,17 @@ describe "String#chop" do
"abc\r\n\r\n".chop.should == "abc\r\n"
end
- with_feature :encoding do
- it "removes a multi-byte character" do
- "ã‚れ".chop.should == "ã‚"
- end
+ it "removes a multi-byte character" do
+ "ã‚れ".chop.should == "ã‚"
+ end
- it "removes the final carriage return, newline from a multibyte String" do
- "ã‚れ\r\n".chop.should == "ã‚れ"
- end
+ it "removes the final carriage return, newline from a multibyte String" do
+ "ã‚れ\r\n".chop.should == "ã‚れ"
+ end
- it "removes the final carriage return, newline from a non-ASCII String" do
- str = "abc\r\n".encode "utf-32be"
- str.chop.should == "abc".encode("utf-32be")
- end
+ it "removes the final carriage return, newline from a non-ASCII String" do
+ str = "abc\r\n".encode "utf-32be"
+ str.chop.should == "abc".encode("utf-32be")
end
it "returns an empty string when applied to an empty string" do
@@ -48,21 +47,15 @@ describe "String#chop" do
it "returns a new string when applied to an empty string" do
s = ""
- s.chop.should_not equal(s)
- end
-
- it "taints result when self is tainted" do
- "hello".taint.chop.tainted?.should == true
- "".taint.chop.tainted?.should == true
+ s.chop.should_not.equal?(s)
end
- it "untrusts result when self is untrusted" do
- "hello".untrust.chop.untrusted?.should == true
- "".untrust.chop.untrusted?.should == true
+ it "returns String instances when called on a subclass" do
+ StringSpecs::MyString.new("hello\n").chop.should.instance_of?(String)
end
- it "returns subclass instances when called on a subclass" do
- StringSpecs::MyString.new("hello\n").chop.should be_an_instance_of(StringSpecs::MyString)
+ it "returns a String in the same encoding as self" do
+ "abc\n\n".encode("US-ASCII").chop.encoding.should == Encoding::US_ASCII
end
end
@@ -83,7 +76,7 @@ describe "String#chop!" do
"abc\r\n".chop!.should == "abc"
end
- it "removes the carrige return, newline if they are the only characters" do
+ it "removes the carriage return, newline if they are the only characters" do
"\r\n".chop!.should == ""
end
@@ -91,38 +84,36 @@ describe "String#chop!" do
"abc\r\n\r\n".chop!.should == "abc\r\n"
end
- with_feature :encoding do
- it "removes a multi-byte character" do
- "ã‚れ".chop!.should == "ã‚"
- end
+ it "removes a multi-byte character" do
+ "ã‚れ".chop!.should == "ã‚"
+ end
- it "removes the final carriage return, newline from a multibyte String" do
- "ã‚れ\r\n".chop!.should == "ã‚れ"
- end
+ it "removes the final carriage return, newline from a multibyte String" do
+ "ã‚れ\r\n".chop!.should == "ã‚れ"
+ end
- it "removes the final carriage return, newline from a non-ASCII String" do
- str = "abc\r\n".encode "utf-32be"
- str.chop!.should == "abc".encode("utf-32be")
- end
+ it "removes the final carriage return, newline from a non-ASCII String" do
+ str = "abc\r\n".encode "utf-32be"
+ str.chop!.should == "abc".encode("utf-32be")
end
it "returns self if modifications were made" do
str = "hello"
- str.chop!.should equal(str)
+ str.chop!.should.equal?(str)
end
it "returns nil when called on an empty string" do
- "".chop!.should be_nil
+ "".chop!.should == nil
end
- it "raises a RuntimeError on a frozen instance that is modified" do
- lambda { "string\n\r".freeze.chop! }.should raise_error(RuntimeError)
+ it "raises a FrozenError on a frozen instance that is modified" do
+ -> { "string\n\r".freeze.chop! }.should.raise(FrozenError)
end
# see [ruby-core:23666]
- it "raises a RuntimeError on a frozen instance that would not be modified" do
+ it "raises a FrozenError on a frozen instance that would not be modified" do
a = ""
a.freeze
- lambda { a.chop! }.should raise_error(RuntimeError)
+ -> { a.chop! }.should.raise(FrozenError)
end
end
diff --git a/spec/ruby/core/string/chr_spec.rb b/spec/ruby/core/string/chr_spec.rb
index c7834b78b7..26c7d51202 100644
--- a/spec/ruby/core/string/chr_spec.rb
+++ b/spec/ruby/core/string/chr_spec.rb
@@ -1,44 +1,42 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-with_feature :encoding do
- describe "String#chr" do
- it "returns a copy of self" do
- s = 'e'
- s.object_id.should_not == s.chr.object_id
- end
-
- it "returns a String" do
- 'glark'.chr.should be_an_instance_of(String)
- end
-
- it "returns an empty String if self is an empty String" do
- "".chr.should == ""
- end
-
- it "returns a 1-character String" do
- "glark".chr.size.should == 1
- end
-
- it "returns the character at the start of the String" do
- "Goodbye, world".chr.should == "G"
- end
-
- it "returns a String in the same encoding as self" do
- "\x24".encode(Encoding::US_ASCII).chr.encoding.should == Encoding::US_ASCII
- end
-
- it "understands multi-byte characters" do
- s = "\u{9879}"
- s.bytesize.should == 3
- s.chr.should == s
- end
-
- it "understands Strings that contain a mixture of character widths" do
- three = "\u{8082}"
- three.bytesize.should == 3
- four = "\u{77082}"
- four.bytesize.should == 4
- "#{three}#{four}".chr.should == three
- end
+require_relative '../../spec_helper'
+
+describe "String#chr" do
+ it "returns a copy of self" do
+ s = 'e'
+ s.should_not.equal? s.chr
+ end
+
+ it "returns a String" do
+ 'glark'.chr.should.instance_of?(String)
+ end
+
+ it "returns an empty String if self is an empty String" do
+ "".chr.should == ""
+ end
+
+ it "returns a 1-character String" do
+ "glark".chr.size.should == 1
+ end
+
+ it "returns the character at the start of the String" do
+ "Goodbye, world".chr.should == "G"
+ end
+
+ it "returns a String in the same encoding as self" do
+ "\x24".encode(Encoding::US_ASCII).chr.encoding.should == Encoding::US_ASCII
+ end
+
+ it "understands multi-byte characters" do
+ s = "\u{9879}"
+ s.bytesize.should == 3
+ s.chr.should == s
+ end
+
+ it "understands Strings that contain a mixture of character widths" do
+ three = "\u{8082}"
+ three.bytesize.should == 3
+ four = "\u{77082}"
+ four.bytesize.should == 4
+ "#{three}#{four}".chr.should == three
end
end
diff --git a/spec/ruby/core/string/clear_spec.rb b/spec/ruby/core/string/clear_spec.rb
index 6a8b6018d0..d4688d3689 100644
--- a/spec/ruby/core/string/clear_spec.rb
+++ b/spec/ruby/core/string/clear_spec.rb
@@ -1,39 +1,38 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+# frozen_string_literal: false
+require_relative '../../spec_helper'
-with_feature :encoding do
- describe "String#clear" do
- before :each do
- @s = "Jolene"
- end
+describe "String#clear" do
+ before :each do
+ @s = "Jolene"
+ end
- it "sets self equal to the empty String" do
- @s.clear
- @s.should == ""
- end
+ it "sets self equal to the empty String" do
+ @s.clear
+ @s.should == ""
+ end
- it "returns self after emptying it" do
- cleared = @s.clear
- cleared.should == ""
- cleared.object_id.should == @s.object_id
- end
+ it "returns self after emptying it" do
+ cleared = @s.clear
+ cleared.should == ""
+ cleared.should.equal? @s
+ end
- it "preserves its encoding" do
- @s.encode!(Encoding::SHIFT_JIS)
- @s.encoding.should == Encoding::SHIFT_JIS
- @s.clear.encoding.should == Encoding::SHIFT_JIS
- @s.encoding.should == Encoding::SHIFT_JIS
- end
+ it "preserves its encoding" do
+ @s.encode!(Encoding::SHIFT_JIS)
+ @s.encoding.should == Encoding::SHIFT_JIS
+ @s.clear.encoding.should == Encoding::SHIFT_JIS
+ @s.encoding.should == Encoding::SHIFT_JIS
+ end
- it "works with multibyte Strings" do
- s = "\u{9765}\u{876}"
- s.clear
- s.should == ""
- end
+ it "works with multibyte Strings" do
+ s = "\u{9765}\u{876}"
+ s.clear
+ s.should == ""
+ end
- it "raises a RuntimeError if self is frozen" do
- @s.freeze
- lambda { @s.clear }.should raise_error(RuntimeError)
- lambda { "".freeze.clear }.should raise_error(RuntimeError)
- end
+ it "raises a FrozenError if self is frozen" do
+ @s.freeze
+ -> { @s.clear }.should.raise(FrozenError)
+ -> { "".freeze.clear }.should.raise(FrozenError)
end
end
diff --git a/spec/ruby/core/string/clone_spec.rb b/spec/ruby/core/string/clone_spec.rb
index 3940858e53..2cb289d2c1 100644
--- a/spec/ruby/core/string/clone_spec.rb
+++ b/spec/ruby/core/string/clone_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "String#clone" do
before :each do
@@ -43,8 +43,8 @@ describe "String#clone" do
end
it "copies frozen state" do
- @obj.freeze.clone.frozen?.should be_true
- "".freeze.clone.frozen?.should be_true
+ @obj.freeze.clone.frozen?.should == true
+ "".freeze.clone.frozen?.should == true
end
it "does not modify the original string when changing cloned string" do
@@ -54,5 +54,8 @@ describe "String#clone" do
orig.should == "xtring"
clone.should == "string"
end
-end
+ it "returns a String in the same encoding as self" do
+ "a".encode("US-ASCII").clone.encoding.should == Encoding::US_ASCII
+ end
+end
diff --git a/spec/ruby/core/string/codepoints_spec.rb b/spec/ruby/core/string/codepoints_spec.rb
index 6304513583..4434eb66a5 100644
--- a/spec/ruby/core/string/codepoints_spec.rb
+++ b/spec/ruby/core/string/codepoints_spec.rb
@@ -1,20 +1,17 @@
-# -*- encoding: binary -*-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/codepoints', __FILE__)
-require File.expand_path('../shared/each_codepoint_without_block', __FILE__)
+# encoding: binary
+require_relative '../../spec_helper'
+require_relative 'shared/codepoints'
-with_feature :encoding do
- describe "String#codepoints" do
- it_behaves_like(:string_codepoints, :codepoints)
+describe "String#codepoints" do
+ 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]
- end
+ it "returns an Array when no block is given" do
+ "abc".codepoints.should == [?a.ord, ?b.ord, ?c.ord]
+ end
- it "raises an ArgumentError when no block is given if self has an invalid encoding" do
- s = "\xDF".force_encoding(Encoding::UTF_8)
- s.valid_encoding?.should be_false
- lambda {s.send(@method)}.should raise_error(ArgumentError)
- end
+ it "raises an ArgumentError when no block is given if self has an invalid encoding" do
+ s = "\xDF".dup.force_encoding(Encoding::UTF_8)
+ s.valid_encoding?.should == false
+ -> { s.codepoints }.should.raise(ArgumentError)
end
end
diff --git a/spec/ruby/core/string/comparison_spec.rb b/spec/ruby/core/string/comparison_spec.rb
index 5a0e7fabc3..0737c131bb 100644
--- a/spec/ruby/core/string/comparison_spec.rb
+++ b/spec/ruby/core/string/comparison_spec.rb
@@ -1,6 +1,6 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes.rb', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "String#<=> with String" do
it "compares individual characters based on their ascii value" do
@@ -61,12 +61,12 @@ describe "String#<=> with String" do
end
it "ignores encoding difference" do
- ("ÄÖÛ".force_encoding("utf-8") <=> "ÄÖÜ".force_encoding("iso-8859-1")).should == -1
- ("ÄÖÜ".force_encoding("utf-8") <=> "ÄÖÛ".force_encoding("iso-8859-1")).should == 1
+ ("ÄÖÛ".dup.force_encoding("utf-8") <=> "ÄÖÜ".dup.force_encoding("iso-8859-1")).should == -1
+ ("ÄÖÜ".dup.force_encoding("utf-8") <=> "ÄÖÛ".dup.force_encoding("iso-8859-1")).should == 1
end
it "returns 0 with identical ASCII-compatible bytes of different encodings" do
- ("abc".force_encoding("utf-8") <=> "abc".force_encoding("iso-8859-1")).should == 0
+ ("abc".dup.force_encoding("utf-8") <=> "abc".dup.force_encoding("iso-8859-1")).should == 0
end
it "compares the indices of the encodings when the strings have identical non-ASCII-compatible bytes" do
@@ -75,13 +75,17 @@ describe "String#<=> with String" do
(xff_1 <=> xff_2).should == -1
(xff_2 <=> xff_1).should == 1
end
+
+ it "returns 0 when comparing 2 empty strings but one is not ASCII-compatible" do
+ ("" <=> "".dup.force_encoding('iso-2022-jp')).should == 0
+ end
end
# Note: This is inconsistent with Array#<=> which calls #to_ary instead of
# just using it as an indicator.
describe "String#<=>" do
it "returns nil if its argument provides neither #to_str nor #<=>" do
- ("abc" <=> mock('x')).should be_nil
+ ("abc" <=> mock('x')).should == nil
end
it "uses the result of calling #to_str for comparison when #to_str is defined" do
@@ -103,6 +107,6 @@ describe "String#<=>" do
def obj.<=>(other); other <=> self; end
obj.should_receive(:<=>).once
- ("abc" <=> obj).should be_nil
+ ("abc" <=> obj).should == nil
end
end
diff --git a/spec/ruby/core/string/concat_spec.rb b/spec/ruby/core/string/concat_spec.rb
index 939be5ed0a..0194a357a0 100644
--- a/spec/ruby/core/string/concat_spec.rb
+++ b/spec/ruby/core/string/concat_spec.rb
@@ -1,28 +1,27 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/concat', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/concat'
describe "String#concat" do
it_behaves_like :string_concat, :concat
it_behaves_like :string_concat_encoding, :concat
+ it_behaves_like :string_concat_type_coercion, :concat
- ruby_version_is "2.4" do
- it "takes multiple arguments" do
- str = "hello "
- str.concat "wo", "", "rld"
- str.should == "hello world"
- end
+ it "takes multiple arguments" do
+ str = +"hello "
+ str.concat "wo", "", "rld"
+ str.should == "hello world"
+ end
- it "concatenates the initial value when given arguments contain 2 self" do
- str = "hello"
- str.concat str, str
- str.should == "hellohellohello"
- end
+ it "concatenates the initial value when given arguments contain 2 self" do
+ str = +"hello"
+ str.concat str, str
+ str.should == "hellohellohello"
+ end
- it "returns self when given no arguments" do
- str = "hello"
- str.concat.should equal(str)
- str.should == "hello"
- end
+ it "returns self when given no arguments" do
+ str = +"hello"
+ str.concat.should.equal?(str)
+ str.should == "hello"
end
end
diff --git a/spec/ruby/core/string/count_spec.rb b/spec/ruby/core/string/count_spec.rb
index 3afb79a9fc..fd127c6ff2 100644
--- a/spec/ruby/core/string/count_spec.rb
+++ b/spec/ruby/core/string/count_spec.rb
@@ -1,6 +1,6 @@
-# -*- encoding: binary -*-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes.rb', __FILE__)
+# encoding: binary
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "String#count" do
it "counts occurrences of chars from the intersection of the specified sets" do
@@ -23,7 +23,7 @@ describe "String#count" do
end
it "raises an ArgumentError when given no arguments" do
- lambda { "hell yeah".count }.should raise_error(ArgumentError)
+ -> { "hell yeah".count }.should.raise(ArgumentError)
end
it "negates sets starting with ^" do
@@ -76,8 +76,8 @@ describe "String#count" do
it "raises if the given sequences are invalid" do
s = "hel-[()]-lo012^"
- lambda { s.count("h-e") }.should raise_error(ArgumentError)
- lambda { s.count("^h-e") }.should raise_error(ArgumentError)
+ -> { s.count("h-e") }.should.raise(ArgumentError)
+ -> { s.count("^h-e") }.should.raise(ArgumentError)
end
it 'returns the number of occurrences of a multi-byte character' do
@@ -98,8 +98,8 @@ describe "String#count" do
end
it "raises a TypeError when a set arg can't be converted to a string" do
- lambda { "hello world".count(100) }.should raise_error(TypeError)
- lambda { "hello world".count([]) }.should raise_error(TypeError)
- lambda { "hello world".count(mock('x')) }.should raise_error(TypeError)
+ -> { "hello world".count(100) }.should.raise(TypeError)
+ -> { "hello world".count([]) }.should.raise(TypeError)
+ -> { "hello world".count(mock('x')) }.should.raise(TypeError)
end
end
diff --git a/spec/ruby/core/string/crypt_spec.rb b/spec/ruby/core/string/crypt_spec.rb
index d3bf5ec732..924b4d48cf 100644
--- a/spec/ruby/core/string/crypt_spec.rb
+++ b/spec/ruby/core/string/crypt_spec.rb
@@ -1,75 +1,92 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes.rb', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "String#crypt" do
- # Note: MRI's documentation just says that the C stdlib function crypt() is
- # called.
- #
- # I'm not sure if crypt() is guaranteed to produce the same result across
- # different platforms. It seems that there is one standard UNIX implementation
- # of crypt(), but that alternative implementations are possible. See
- # http://www.unix.org.ua/orelly/networking/puis/ch08_06.htm
- it "returns a cryptographic hash of self by applying the UNIX crypt algorithm with the specified salt" do
- "".crypt("aa").should == "aaQSqAReePlq6"
- "nutmeg".crypt("Mi").should == "MiqkFWCm1fNJI"
- "ellen1".crypt("ri").should == "ri79kNd7V6.Sk"
- "Sharon".crypt("./").should == "./UY9Q7TvYJDg"
- "norahs".crypt("am").should == "amfIADT2iqjA."
- "norahs".crypt("7a").should == "7azfT5tIdyh0I"
-
- # Only uses first 8 chars of string
- "01234567".crypt("aa").should == "aa4c4gpuvCkSE"
- "012345678".crypt("aa").should == "aa4c4gpuvCkSE"
- "0123456789".crypt("aa").should == "aa4c4gpuvCkSE"
-
- # Only uses first 2 chars of salt
- "hello world".crypt("aa").should == "aayPz4hyPS1wI"
- "hello world".crypt("aab").should == "aayPz4hyPS1wI"
- "hello world".crypt("aabc").should == "aayPz4hyPS1wI"
- end
+ platform_is :openbsd do
+ it "returns a cryptographic hash of self by applying the bcrypt algorithm with the specified salt" do
+ "mypassword".crypt("$2a$04$0WVaz0pV3jzfZ5G5tpmHWu").should == "$2a$04$0WVaz0pV3jzfZ5G5tpmHWuBQGbkjzgtSc3gJbmdy0GAGMa45MFM2."
- it "raises an ArgumentError when the salt is shorter than two characters" do
- lambda { "hello".crypt("") }.should raise_error(ArgumentError)
- lambda { "hello".crypt("f") }.should raise_error(ArgumentError)
- lambda { "hello".crypt("\x00\x00") }.should raise_error(ArgumentError)
- lambda { "hello".crypt("\x00a") }.should raise_error(ArgumentError)
- lambda { "hello".crypt("a\x00") }.should raise_error(ArgumentError)
- end
+ # Only uses first 72 characters of string
+ ("12345678"*9).crypt("$2a$04$0WVaz0pV3jzfZ5G5tpmHWu").should == "$2a$04$0WVaz0pV3jzfZ5G5tpmHWukj/ORBnsMjCGpST/zCJnAypc7eAbutK"
+ ("12345678"*10).crypt("$2a$04$0WVaz0pV3jzfZ5G5tpmHWu").should == "$2a$04$0WVaz0pV3jzfZ5G5tpmHWukj/ORBnsMjCGpST/zCJnAypc7eAbutK"
- ruby_version_is "2.3" do
- it "raises an ArgumentError when the string contains NUL character" do
- lambda { "poison\0null".crypt("aa") }.should raise_error(ArgumentError)
+ # Only uses first 29 characters of salt
+ "mypassword".crypt("$2a$04$0WVaz0pV3jzfZ5G5tpmHWuB").should == "$2a$04$0WVaz0pV3jzfZ5G5tpmHWuBQGbkjzgtSc3gJbmdy0GAGMa45MFM2."
end
- end
- it "calls #to_str to converts the salt arg to a String" do
- obj = mock('aa')
- obj.should_receive(:to_str).and_return("aa")
+ it "raises Errno::EINVAL when the salt is shorter than 29 characters" do
+ -> { "mypassword".crypt("$2a$04$0WVaz0pV3jzfZ5G5tpmHW") }.should.raise(Errno::EINVAL)
+ end
- "".crypt(obj).should == "aaQSqAReePlq6"
- end
+ it "calls #to_str to converts the salt arg to a String" do
+ obj = mock('$2a$04$0WVaz0pV3jzfZ5G5tpmHWu')
+ obj.should_receive(:to_str).and_return("$2a$04$0WVaz0pV3jzfZ5G5tpmHWu")
- it "raises a type error when the salt arg can't be converted to a string" do
- lambda { "".crypt(5) }.should raise_error(TypeError)
- lambda { "".crypt(mock('x')) }.should raise_error(TypeError)
+ "mypassword".crypt(obj).should == "$2a$04$0WVaz0pV3jzfZ5G5tpmHWuBQGbkjzgtSc3gJbmdy0GAGMa45MFM2."
+ end
+
+ it "doesn't return subclass instances" do
+ StringSpecs::MyString.new("mypassword").crypt("$2a$04$0WVaz0pV3jzfZ5G5tpmHWu").should.instance_of?(String)
+ "mypassword".crypt(StringSpecs::MyString.new("$2a$04$0WVaz0pV3jzfZ5G5tpmHWu")).should.instance_of?(String)
+ StringSpecs::MyString.new("mypassword").crypt(StringSpecs::MyString.new("$2a$04$0WVaz0pV3jzfZ5G5tpmHWu")).should.instance_of?(String)
+ end
end
- it "taints the result if either salt or self is tainted" do
- tainted_salt = "aa"
- tainted_str = "hello"
+ platform_is_not :openbsd do
+ # Note: MRI's documentation just says that the C stdlib function crypt() is
+ # called.
+ #
+ # I'm not sure if crypt() is guaranteed to produce the same result across
+ # different platforms. It seems that there is one standard UNIX implementation
+ # of crypt(), but that alternative implementations are possible. See
+ # http://www.unix.org.ua/orelly/networking/puis/ch08_06.htm
+ it "returns a cryptographic hash of self by applying the UNIX crypt algorithm with the specified salt" do
+ "".crypt("aa").should == "aaQSqAReePlq6"
+ "nutmeg".crypt("Mi").should == "MiqkFWCm1fNJI"
+ "ellen1".crypt("ri").should == "ri79kNd7V6.Sk"
+ "Sharon".crypt("./").should == "./UY9Q7TvYJDg"
+ "norahs".crypt("am").should == "amfIADT2iqjA."
+ "norahs".crypt("7a").should == "7azfT5tIdyh0I"
+
+ # Only uses first 8 chars of string
+ "01234567".crypt("aa").should == "aa4c4gpuvCkSE"
+ "012345678".crypt("aa").should == "aa4c4gpuvCkSE"
+ "0123456789".crypt("aa").should == "aa4c4gpuvCkSE"
- tainted_salt.taint
- tainted_str.taint
+ # Only uses first 2 chars of salt
+ "hello world".crypt("aa").should == "aayPz4hyPS1wI"
+ "hello world".crypt("aab").should == "aayPz4hyPS1wI"
+ "hello world".crypt("aabc").should == "aayPz4hyPS1wI"
+ end
+
+ it "raises an ArgumentError when the string contains NUL character" do
+ -> { "poison\0null".crypt("aa") }.should.raise(ArgumentError)
+ end
+
+ it "calls #to_str to converts the salt arg to a String" do
+ obj = mock('aa')
+ obj.should_receive(:to_str).and_return("aa")
- "hello".crypt("aa").tainted?.should == false
- tainted_str.crypt("aa").tainted?.should == true
- "hello".crypt(tainted_salt).tainted?.should == true
- tainted_str.crypt(tainted_salt).tainted?.should == true
+ "".crypt(obj).should == "aaQSqAReePlq6"
+ end
+
+ it "doesn't return subclass instances" do
+ StringSpecs::MyString.new("hello").crypt("aa").should.instance_of?(String)
+ "hello".crypt(StringSpecs::MyString.new("aa")).should.instance_of?(String)
+ StringSpecs::MyString.new("hello").crypt(StringSpecs::MyString.new("aa")).should.instance_of?(String)
+ end
+
+ it "raises an ArgumentError when the salt is shorter than two characters" do
+ -> { "hello".crypt("") }.should.raise(ArgumentError)
+ -> { "hello".crypt("f") }.should.raise(ArgumentError)
+ -> { "hello".crypt("\x00\x00") }.should.raise(ArgumentError)
+ -> { "hello".crypt("\x00a") }.should.raise(ArgumentError)
+ -> { "hello".crypt("a\x00") }.should.raise(ArgumentError)
+ end
end
- it "doesn't return subclass instances" do
- StringSpecs::MyString.new("hello").crypt("aa").should be_an_instance_of(String)
- "hello".crypt(StringSpecs::MyString.new("aa")).should be_an_instance_of(String)
- StringSpecs::MyString.new("hello").crypt(StringSpecs::MyString.new("aa")).should be_an_instance_of(String)
+ it "raises a type error when the salt arg can't be converted to a string" do
+ -> { "".crypt(5) }.should.raise(TypeError)
+ -> { "".crypt(mock('x')) }.should.raise(TypeError)
end
end
diff --git a/spec/ruby/core/string/dedup_spec.rb b/spec/ruby/core/string/dedup_spec.rb
new file mode 100644
index 0000000000..940f07668e
--- /dev/null
+++ b/spec/ruby/core/string/dedup_spec.rb
@@ -0,0 +1,7 @@
+require_relative '../../spec_helper'
+
+describe 'String#dedup' do
+ it "is an alias of String#-@" do
+ String.instance_method(:dedup).should == String.instance_method(:-@)
+ end
+end
diff --git a/spec/ruby/core/string/delete_prefix_spec.rb b/spec/ruby/core/string/delete_prefix_spec.rb
new file mode 100644
index 0000000000..fc69adcbad
--- /dev/null
+++ b/spec/ruby/core/string/delete_prefix_spec.rb
@@ -0,0 +1,83 @@
+# -*- encoding: utf-8 -*-
+# frozen_string_literal: false
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe "String#delete_prefix" do
+ it "returns a copy of the string, with the given prefix removed" do
+ 'hello'.delete_prefix('hell').should == 'o'
+ 'hello'.delete_prefix('hello').should == ''
+ end
+
+ it "returns a copy of the string, when the prefix isn't found" do
+ s = 'hello'
+ r = s.delete_prefix('hello!')
+ r.should_not.equal? s
+ r.should == s
+ r = s.delete_prefix('ell')
+ r.should_not.equal? s
+ r.should == s
+ r = s.delete_prefix('')
+ r.should_not.equal? s
+ r.should == s
+ end
+
+ it "does not remove partial bytes, only full characters" do
+ "\xe3\x81\x82".delete_prefix("\xe3").should == "\xe3\x81\x82"
+ end
+
+ it "doesn't set $~" do
+ $~ = nil
+
+ 'hello'.delete_prefix('hell')
+ $~.should == nil
+ end
+
+ it "calls to_str on its argument" do
+ o = mock('x')
+ o.should_receive(:to_str).and_return 'hell'
+ 'hello'.delete_prefix(o).should == 'o'
+ end
+
+ it "returns a String instance when called on a subclass instance" do
+ s = StringSpecs::MyString.new('hello')
+ s.delete_prefix('hell').should.instance_of?(String)
+ end
+
+ it "returns a String in the same encoding as self" do
+ 'hello'.encode("US-ASCII").delete_prefix('hell').encoding.should == Encoding::US_ASCII
+ end
+end
+
+describe "String#delete_prefix!" do
+ it "removes the found prefix" do
+ s = 'hello'
+ s.delete_prefix!('hell').should.equal?(s)
+ s.should == 'o'
+ end
+
+ it "returns nil if no change is made" do
+ s = 'hello'
+ s.delete_prefix!('ell').should == nil
+ s.delete_prefix!('').should == nil
+ end
+
+ it "doesn't set $~" do
+ $~ = nil
+
+ 'hello'.delete_prefix!('hell')
+ $~.should == nil
+ end
+
+ it "calls to_str on its argument" do
+ o = mock('x')
+ o.should_receive(:to_str).and_return 'hell'
+ 'hello'.delete_prefix!(o).should == 'o'
+ end
+
+ it "raises a FrozenError when self is frozen" do
+ -> { 'hello'.freeze.delete_prefix!('hell') }.should.raise(FrozenError)
+ -> { 'hello'.freeze.delete_prefix!('') }.should.raise(FrozenError)
+ -> { ''.freeze.delete_prefix!('') }.should.raise(FrozenError)
+ end
+end
diff --git a/spec/ruby/core/string/delete_spec.rb b/spec/ruby/core/string/delete_spec.rb
index 536d4a95af..adb5150cff 100644
--- a/spec/ruby/core/string/delete_spec.rb
+++ b/spec/ruby/core/string/delete_spec.rb
@@ -1,6 +1,7 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes.rb', __FILE__)
+# frozen_string_literal: false
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "String#delete" do
it "returns a new string with the chars from the intersection of sets removed" do
@@ -14,7 +15,7 @@ describe "String#delete" do
end
it "raises an ArgumentError when given no arguments" do
- lambda { "hell yeah".delete }.should raise_error(ArgumentError)
+ -> { "hell yeah".delete }.should.raise(ArgumentError)
end
it "negates sets starting with ^" do
@@ -62,17 +63,10 @@ describe "String#delete" do
not_supported_on :opal do
xFF = [0xFF].pack('C')
range = "\x00 - #{xFF}".force_encoding('utf-8')
- lambda { "hello".delete(range).should == "" }.should raise_error(ArgumentError)
+ -> { "hello".delete(range).should == "" }.should.raise(ArgumentError)
end
- lambda { "hello".delete("h-e") }.should raise_error(ArgumentError)
- lambda { "hello".delete("^h-e") }.should raise_error(ArgumentError)
- end
-
- it "taints result when self is tainted" do
- "hello".taint.delete("e").tainted?.should == true
- "hello".taint.delete("a-z").tainted?.should == true
-
- "hello".delete("e".taint).tainted?.should == false
+ -> { "hello".delete("h-e") }.should.raise(ArgumentError)
+ -> { "hello".delete("^h-e") }.should.raise(ArgumentError)
end
it "tries to convert each set arg to a string using to_str" do
@@ -86,20 +80,24 @@ describe "String#delete" do
end
it "raises a TypeError when one set arg can't be converted to a string" do
- lambda { "hello world".delete(100) }.should raise_error(TypeError)
- lambda { "hello world".delete([]) }.should raise_error(TypeError)
- lambda { "hello world".delete(mock('x')) }.should raise_error(TypeError)
+ -> { "hello world".delete(100) }.should.raise(TypeError)
+ -> { "hello world".delete([]) }.should.raise(TypeError)
+ -> { "hello world".delete(mock('x')) }.should.raise(TypeError)
+ end
+
+ it "returns String instances when called on a subclass" do
+ StringSpecs::MyString.new("oh no!!!").delete("!").should.instance_of?(String)
end
- it "returns subclass instances when called on a subclass" do
- StringSpecs::MyString.new("oh no!!!").delete("!").should be_an_instance_of(StringSpecs::MyString)
+ it "returns a String in the same encoding as self" do
+ "hello".encode("US-ASCII").delete("lo").encoding.should == Encoding::US_ASCII
end
end
describe "String#delete!" do
it "modifies self in place and returns self" do
a = "hello"
- a.delete!("aeiou", "^e").should equal(a)
+ a.delete!("aeiou", "^e").should.equal?(a)
a.should == "hell"
end
@@ -109,11 +107,11 @@ describe "String#delete!" do
a.should == "hello"
end
- it "raises a RuntimeError when self is frozen" do
+ it "raises a FrozenError when self is frozen" do
a = "hello"
a.freeze
- lambda { a.delete!("") }.should raise_error(RuntimeError)
- lambda { a.delete!("aeiou", "^e") }.should raise_error(RuntimeError)
+ -> { a.delete!("") }.should.raise(FrozenError)
+ -> { a.delete!("aeiou", "^e") }.should.raise(FrozenError)
end
end
diff --git a/spec/ruby/core/string/delete_suffix_spec.rb b/spec/ruby/core/string/delete_suffix_spec.rb
new file mode 100644
index 0000000000..11d8fbbac1
--- /dev/null
+++ b/spec/ruby/core/string/delete_suffix_spec.rb
@@ -0,0 +1,83 @@
+# -*- encoding: utf-8 -*-
+# frozen_string_literal: false
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe "String#delete_suffix" do
+ it "returns a copy of the string, with the given suffix removed" do
+ 'hello'.delete_suffix('ello').should == 'h'
+ 'hello'.delete_suffix('hello').should == ''
+ end
+
+ it "returns a copy of the string, when the suffix isn't found" do
+ s = 'hello'
+ r = s.delete_suffix('!hello')
+ r.should_not.equal? s
+ r.should == s
+ r = s.delete_suffix('ell')
+ r.should_not.equal? s
+ r.should == s
+ r = s.delete_suffix('')
+ r.should_not.equal? s
+ r.should == s
+ end
+
+ it "does not remove partial bytes, only full characters" do
+ "\xe3\x81\x82".delete_suffix("\x82").should == "\xe3\x81\x82"
+ end
+
+ it "doesn't set $~" do
+ $~ = nil
+
+ 'hello'.delete_suffix('ello')
+ $~.should == nil
+ end
+
+ it "calls to_str on its argument" do
+ o = mock('x')
+ o.should_receive(:to_str).and_return 'ello'
+ 'hello'.delete_suffix(o).should == 'h'
+ end
+
+ it "returns a String instance when called on a subclass instance" do
+ s = StringSpecs::MyString.new('hello')
+ s.delete_suffix('ello').should.instance_of?(String)
+ end
+
+ it "returns a String in the same encoding as self" do
+ "hello".encode("US-ASCII").delete_suffix("ello").encoding.should == Encoding::US_ASCII
+ end
+end
+
+describe "String#delete_suffix!" do
+ it "removes the found prefix" do
+ s = 'hello'
+ s.delete_suffix!('ello').should.equal?(s)
+ s.should == 'h'
+ end
+
+ it "returns nil if no change is made" do
+ s = 'hello'
+ s.delete_suffix!('ell').should == nil
+ s.delete_suffix!('').should == nil
+ end
+
+ it "doesn't set $~" do
+ $~ = nil
+
+ 'hello'.delete_suffix!('ello')
+ $~.should == nil
+ end
+
+ it "calls to_str on its argument" do
+ o = mock('x')
+ o.should_receive(:to_str).and_return 'ello'
+ 'hello'.delete_suffix!(o).should == 'h'
+ end
+
+ it "raises a FrozenError when self is frozen" do
+ -> { 'hello'.freeze.delete_suffix!('ello') }.should.raise(FrozenError)
+ -> { 'hello'.freeze.delete_suffix!('') }.should.raise(FrozenError)
+ -> { ''.freeze.delete_suffix!('') }.should.raise(FrozenError)
+ end
+end
diff --git a/spec/ruby/core/string/downcase_spec.rb b/spec/ruby/core/string/downcase_spec.rb
index f591c0fa09..4f7f44e5d4 100644
--- a/spec/ruby/core/string/downcase_spec.rb
+++ b/spec/ruby/core/string/downcase_spec.rb
@@ -1,6 +1,7 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes.rb', __FILE__)
+# frozen_string_literal: false
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "String#downcase" do
it "returns a copy of self with all uppercase letters downcased" do
@@ -8,50 +9,173 @@ describe "String#downcase" do
"hello".downcase.should == "hello"
end
- ruby_version_is ''...'2.4' do
- it "is locale insensitive (only replaces A-Z)" do
- "ÄÖÜ".downcase.should == "ÄÖÜ"
+ it "returns a String in the same encoding as self" do
+ "hELLO".encode("US-ASCII").downcase.encoding.should == Encoding::US_ASCII
+ end
+
+ describe "full Unicode case mapping" do
+ it "works for all of Unicode with no option" do
+ "ÄÖÜ".downcase.should == "äöü"
+ end
- str = Array.new(256) { |c| c.chr }.join
- expected = Array.new(256) do |i|
- c = i.chr
- c.between?("A", "Z") ? c.downcase : c
- end.join
+ it "updates string metadata" do
+ downcased = "\u{212A}ING".downcase
- str.downcase.should == expected
+ downcased.should == "king"
+ downcased.size.should == 4
+ downcased.bytesize.should == 4
+ downcased.ascii_only?.should == true
end
end
- ruby_version_is '2.4' do
- it "works for all of Unicode" do
- "ÄÖÜ".downcase.should == "äöü"
+ describe "ASCII-only case mapping" do
+ it "does not downcase non-ASCII characters" do
+ "Câ„«R".downcase(:ascii).should == "câ„«r"
+ end
+
+ it "works with substrings" do
+ "prefix TÉ"[-2..-1].downcase(:ascii).should == "tÉ"
+ end
+ end
+
+ describe "full Unicode case mapping adapted for Turkic languages" do
+ it "downcases characters according to Turkic semantics" do
+ "İ".downcase(:turkic).should == "i"
+ end
+
+ it "allows Lithuanian as an extra option" do
+ "İ".downcase(:turkic, :lithuanian).should == "i"
+ end
+
+ it "does not allow any other additional option" do
+ -> { "İ".downcase(:turkic, :ascii) }.should.raise(ArgumentError)
end
end
- it "taints result when self is tainted" do
- "".taint.downcase.tainted?.should == true
- "x".taint.downcase.tainted?.should == true
- "X".taint.downcase.tainted?.should == true
+ describe "full Unicode case mapping adapted for Lithuanian" do
+ it "currently works the same as full Unicode case mapping" do
+ "İS".downcase(:lithuanian).should == "i\u{307}s"
+ end
+
+ it "allows Turkic as an extra option (and applies Turkic semantics)" do
+ "İS".downcase(:lithuanian, :turkic).should == "is"
+ end
+
+ it "does not allow any other additional option" do
+ -> { "İS".downcase(:lithuanian, :ascii) }.should.raise(ArgumentError)
+ end
+ end
+
+ describe "case folding" do
+ it "case folds special characters" do
+ "ß".downcase.should == "ß"
+ "ß".downcase(:fold).should == "ss"
+ end
+ end
+
+ it "does not allow invalid options" do
+ -> { "ABC".downcase(:invalid_option) }.should.raise(ArgumentError)
end
- it "returns a subclass instance for subclasses" do
- StringSpecs::MyString.new("FOObar").downcase.should be_an_instance_of(StringSpecs::MyString)
+ it "returns a String instance for subclasses" do
+ StringSpecs::MyString.new("FOObar").downcase.should.instance_of?(String)
end
end
describe "String#downcase!" do
it "modifies self in place" do
a = "HeLlO"
- a.downcase!.should equal(a)
+ a.downcase!.should.equal?(a)
a.should == "hello"
end
- ruby_version_is '2.4' do
- it "modifies self in place for all of Unicode" do
+ it "modifies self in place for non-ascii-compatible encodings" do
+ a = "HeLlO".encode("utf-16le")
+ a.downcase!
+ a.should == "hello".encode("utf-16le")
+ end
+
+ describe "full Unicode case mapping" do
+ it "modifies self in place for all of Unicode with no option" do
a = "ÄÖÜ"
- a.downcase!.should equal(a)
+ a.downcase!
a.should == "äöü"
end
+
+ it "updates string metadata" do
+ downcased = "\u{212A}ING"
+ downcased.downcase!
+
+ downcased.should == "king"
+ downcased.size.should == 4
+ downcased.bytesize.should == 4
+ downcased.ascii_only?.should == true
+ end
+ end
+
+ describe "ASCII-only case mapping" do
+ it "does not downcase non-ASCII characters" do
+ a = "Câ„«R"
+ a.downcase!(:ascii)
+ a.should == "câ„«r"
+ end
+
+ it "works for non-ascii-compatible encodings" do
+ a = "ABC".encode("utf-16le")
+ a.downcase!(:ascii)
+ a.should == "abc".encode("utf-16le")
+ end
+ end
+
+ describe "full Unicode case mapping adapted for Turkic languages" do
+ it "downcases characters according to Turkic semantics" do
+ a = "İ"
+ a.downcase!(:turkic)
+ a.should == "i"
+ end
+
+ it "allows Lithuanian as an extra option" do
+ a = "İ"
+ a.downcase!(:turkic, :lithuanian)
+ a.should == "i"
+ end
+
+ it "does not allow any other additional option" do
+ -> { a = "İ"; a.downcase!(:turkic, :ascii) }.should.raise(ArgumentError)
+ end
+ end
+
+ describe "full Unicode case mapping adapted for Lithuanian" do
+ it "currently works the same as full Unicode case mapping" do
+ a = "İS"
+ a.downcase!(:lithuanian)
+ a.should == "i\u{307}s"
+ end
+
+ it "allows Turkic as an extra option (and applies Turkic semantics)" do
+ a = "İS"
+ a.downcase!(:lithuanian, :turkic)
+ a.should == "is"
+ end
+
+ it "does not allow any other additional option" do
+ -> { a = "İS"; a.downcase!(:lithuanian, :ascii) }.should.raise(ArgumentError)
+ end
+ end
+
+ describe "case folding" do
+ it "case folds special characters" do
+ a = "ß"
+ a.downcase!
+ a.should == "ß"
+
+ a.downcase!(:fold)
+ a.should == "ss"
+ end
+ end
+
+ it "does not allow invalid options" do
+ -> { a = "ABC"; a.downcase!(:invalid_option) }.should.raise(ArgumentError)
end
it "returns nil if no modifications were made" do
@@ -60,14 +184,12 @@ describe "String#downcase!" do
a.should == "hello"
end
- it "raises a RuntimeError when self is frozen" do
- lambda { "HeLlo".freeze.downcase! }.should raise_error(RuntimeError)
- lambda { "hello".freeze.downcase! }.should raise_error(RuntimeError)
+ it "raises a FrozenError when self is frozen" do
+ -> { "HeLlo".freeze.downcase! }.should.raise(FrozenError)
+ -> { "hello".freeze.downcase! }.should.raise(FrozenError)
end
- with_feature :encoding do
- it "sets the result String encoding to the source String encoding" do
- "ABC".downcase.encoding.should equal(Encoding::UTF_8)
- end
+ it "sets the result String encoding to the source String encoding" do
+ "ABC".downcase.encoding.should.equal?(Encoding::UTF_8)
end
end
diff --git a/spec/ruby/core/string/dump_spec.rb b/spec/ruby/core/string/dump_spec.rb
index db743ad08f..176be79db2 100644
--- a/spec/ruby/core/string/dump_spec.rb
+++ b/spec/ruby/core/string/dump_spec.rb
@@ -1,20 +1,18 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "String#dump" do
- it "taints the result if self is tainted" do
- "foo".taint.dump.tainted?.should == true
- "foo\n".taint.dump.tainted?.should == true
+ it "does not take into account if a string is frozen" do
+ "foo".freeze.dump.should_not.frozen?
end
- it "untrusts the result if self is untrusted" do
- "foo".untrust.dump.untrusted?.should == true
- "foo\n".untrust.dump.untrusted?.should == true
+ it "returns a String instance" do
+ StringSpecs::MyString.new.dump.should.instance_of?(String)
end
- it "returns a subclass instance" do
- StringSpecs::MyString.new.dump.should be_an_instance_of(StringSpecs::MyString)
+ it "wraps string with \"" do
+ "foo".dump.should == '"foo"'
end
it "returns a string with special characters replaced with \\<char> notation" do
@@ -35,10 +33,11 @@ describe "String#dump" do
].should be_computed_by(:dump)
end
- it "returns a string with \\#<char> when # is followed by $, @, {" do
- [ ["\#$", '"\\#$"'],
- ["\#@", '"\\#@"'],
- ["\#{", '"\\#{"']
+ it "returns a string with \\#<char> when # is followed by $, @, @@, {" do
+ [ ["\#$PATH", '"\\#$PATH"'],
+ ["\#@a", '"\\#@a"'],
+ ["\#@@a", '"\\#@@a"'],
+ ["\#{a}", '"\\#{a}"']
].should be_computed_by(:dump)
end
@@ -343,82 +342,55 @@ describe "String#dump" do
].should be_computed_by(:dump)
end
- ruby_version_is ''...'2.4' do
- it "returns a string with multi-byte UTF-8 characters replaced by \\u{} notation with lower-case hex digits" do
- [ [0200.chr('utf-8'), '"\u{80}"'],
- [0201.chr('utf-8'), '"\u{81}"'],
- [0202.chr('utf-8'), '"\u{82}"'],
- [0203.chr('utf-8'), '"\u{83}"'],
- [0204.chr('utf-8'), '"\u{84}"'],
- [0206.chr('utf-8'), '"\u{86}"'],
- [0207.chr('utf-8'), '"\u{87}"'],
- [0210.chr('utf-8'), '"\u{88}"'],
- [0211.chr('utf-8'), '"\u{89}"'],
- [0212.chr('utf-8'), '"\u{8a}"'],
- [0213.chr('utf-8'), '"\u{8b}"'],
- [0214.chr('utf-8'), '"\u{8c}"'],
- [0215.chr('utf-8'), '"\u{8d}"'],
- [0216.chr('utf-8'), '"\u{8e}"'],
- [0217.chr('utf-8'), '"\u{8f}"'],
- [0220.chr('utf-8'), '"\u{90}"'],
- [0221.chr('utf-8'), '"\u{91}"'],
- [0222.chr('utf-8'), '"\u{92}"'],
- [0223.chr('utf-8'), '"\u{93}"'],
- [0224.chr('utf-8'), '"\u{94}"'],
- [0225.chr('utf-8'), '"\u{95}"'],
- [0226.chr('utf-8'), '"\u{96}"'],
- [0227.chr('utf-8'), '"\u{97}"'],
- [0230.chr('utf-8'), '"\u{98}"'],
- [0231.chr('utf-8'), '"\u{99}"'],
- [0232.chr('utf-8'), '"\u{9a}"'],
- [0233.chr('utf-8'), '"\u{9b}"'],
- [0234.chr('utf-8'), '"\u{9c}"'],
- [0235.chr('utf-8'), '"\u{9d}"'],
- [0236.chr('utf-8'), '"\u{9e}"'],
- [0237.chr('utf-8'), '"\u{9f}"'],
- ].should be_computed_by(:dump)
- end
+ it "returns a string with multi-byte UTF-8 characters less than or equal 0xFFFF replaced by \\uXXXX notation with upper-case hex digits" do
+ [ [0200.chr('utf-8'), '"\u0080"'],
+ [0201.chr('utf-8'), '"\u0081"'],
+ [0202.chr('utf-8'), '"\u0082"'],
+ [0203.chr('utf-8'), '"\u0083"'],
+ [0204.chr('utf-8'), '"\u0084"'],
+ [0206.chr('utf-8'), '"\u0086"'],
+ [0207.chr('utf-8'), '"\u0087"'],
+ [0210.chr('utf-8'), '"\u0088"'],
+ [0211.chr('utf-8'), '"\u0089"'],
+ [0212.chr('utf-8'), '"\u008A"'],
+ [0213.chr('utf-8'), '"\u008B"'],
+ [0214.chr('utf-8'), '"\u008C"'],
+ [0215.chr('utf-8'), '"\u008D"'],
+ [0216.chr('utf-8'), '"\u008E"'],
+ [0217.chr('utf-8'), '"\u008F"'],
+ [0220.chr('utf-8'), '"\u0090"'],
+ [0221.chr('utf-8'), '"\u0091"'],
+ [0222.chr('utf-8'), '"\u0092"'],
+ [0223.chr('utf-8'), '"\u0093"'],
+ [0224.chr('utf-8'), '"\u0094"'],
+ [0225.chr('utf-8'), '"\u0095"'],
+ [0226.chr('utf-8'), '"\u0096"'],
+ [0227.chr('utf-8'), '"\u0097"'],
+ [0230.chr('utf-8'), '"\u0098"'],
+ [0231.chr('utf-8'), '"\u0099"'],
+ [0232.chr('utf-8'), '"\u009A"'],
+ [0233.chr('utf-8'), '"\u009B"'],
+ [0234.chr('utf-8'), '"\u009C"'],
+ [0235.chr('utf-8'), '"\u009D"'],
+ [0236.chr('utf-8'), '"\u009E"'],
+ [0237.chr('utf-8'), '"\u009F"'],
+ [0177777.chr('utf-8'), '"\uFFFF"'],
+ ].should be_computed_by(:dump)
end
- ruby_version_is '2.4' do
- it "returns a string with multi-byte UTF-8 characters replaced by \\u{} notation with lower-case hex digits" do
- [ [0200.chr('utf-8'), '"\u0080"'],
- [0201.chr('utf-8'), '"\u0081"'],
- [0202.chr('utf-8'), '"\u0082"'],
- [0203.chr('utf-8'), '"\u0083"'],
- [0204.chr('utf-8'), '"\u0084"'],
- [0206.chr('utf-8'), '"\u0086"'],
- [0207.chr('utf-8'), '"\u0087"'],
- [0210.chr('utf-8'), '"\u0088"'],
- [0211.chr('utf-8'), '"\u0089"'],
- [0212.chr('utf-8'), '"\u008A"'],
- [0213.chr('utf-8'), '"\u008B"'],
- [0214.chr('utf-8'), '"\u008C"'],
- [0215.chr('utf-8'), '"\u008D"'],
- [0216.chr('utf-8'), '"\u008E"'],
- [0217.chr('utf-8'), '"\u008F"'],
- [0220.chr('utf-8'), '"\u0090"'],
- [0221.chr('utf-8'), '"\u0091"'],
- [0222.chr('utf-8'), '"\u0092"'],
- [0223.chr('utf-8'), '"\u0093"'],
- [0224.chr('utf-8'), '"\u0094"'],
- [0225.chr('utf-8'), '"\u0095"'],
- [0226.chr('utf-8'), '"\u0096"'],
- [0227.chr('utf-8'), '"\u0097"'],
- [0230.chr('utf-8'), '"\u0098"'],
- [0231.chr('utf-8'), '"\u0099"'],
- [0232.chr('utf-8'), '"\u009A"'],
- [0233.chr('utf-8'), '"\u009B"'],
- [0234.chr('utf-8'), '"\u009C"'],
- [0235.chr('utf-8'), '"\u009D"'],
- [0236.chr('utf-8'), '"\u009E"'],
- [0237.chr('utf-8'), '"\u009F"'],
- ].should be_computed_by(:dump)
- end
+ it "returns a string with multi-byte UTF-8 characters greater than 0xFFFF replaced by \\u{XXXXXX} notation with upper-case hex digits" do
+ 0x10000.chr('utf-8').dump.should == '"\u{10000}"'
+ 0x10FFFF.chr('utf-8').dump.should == '"\u{10FFFF}"'
end
it "includes .force_encoding(name) if the encoding isn't ASCII compatible" do
- "\u{876}".encode('utf-16be').dump.should == "\"\\bv\".force_encoding(\"UTF-16BE\")"
- "\u{876}".encode('utf-16le').dump.should == "\"v\\b\".force_encoding(\"UTF-16LE\")"
+ "\u{876}".encode('utf-16be').dump.should.end_with?(".force_encoding(\"UTF-16BE\")")
+ "\u{876}".encode('utf-16le').dump.should.end_with?(".force_encoding(\"UTF-16LE\")")
+ end
+
+ it "returns a String in the same encoding as self" do
+ "foo".encode("ISO-8859-1").dump.encoding.should == Encoding::ISO_8859_1
+ "foo".encode('windows-1251').dump.encoding.should == Encoding::Windows_1251
+ 1.chr.dump.encoding.should == Encoding::US_ASCII
end
end
diff --git a/spec/ruby/core/string/dup_spec.rb b/spec/ruby/core/string/dup_spec.rb
index 81fb1308cc..e367f7a311 100644
--- a/spec/ruby/core/string/dup_spec.rb
+++ b/spec/ruby/core/string/dup_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "String#dup" do
before :each do
@@ -21,7 +21,7 @@ describe "String#dup" do
it "does not copy singleton methods" do
def @obj.special() :the_one end
dup = @obj.dup
- lambda { dup.special }.should raise_error(NameError)
+ -> { dup.special }.should.raise(NameError)
end
it "does not copy modules included in the singleton class" do
@@ -30,7 +30,7 @@ describe "String#dup" do
end
dup = @obj.dup
- lambda { dup.repr }.should raise_error(NameError)
+ -> { dup.repr }.should.raise(NameError)
end
it "does not copy constants defined in the singleton class" do
@@ -39,7 +39,7 @@ describe "String#dup" do
end
dup = @obj.dup
- lambda { class << dup; CLONE; end }.should raise_error(NameError)
+ -> { class << dup; CLONE; end }.should.raise(NameError)
end
it "does not modify the original string when changing dupped string" do
@@ -49,4 +49,17 @@ describe "String#dup" do
orig.should == "xtring"
dup.should == "string"
end
+
+ it "does not modify the original setbyte-mutated string when changing dupped string" do
+ orig = +"a"
+ orig.setbyte 0, "b".ord
+ copy = orig.dup
+ orig.setbyte 0, "c".ord
+ orig.should == "c"
+ copy.should == "b"
+ end
+
+ it "returns a String in the same encoding as self" do
+ "hello".encode("US-ASCII").dup.encoding.should == Encoding::US_ASCII
+ end
end
diff --git a/spec/ruby/core/string/each_byte_spec.rb b/spec/ruby/core/string/each_byte_spec.rb
index 2282cd6d7a..1884df416b 100644
--- a/spec/ruby/core/string/each_byte_spec.rb
+++ b/spec/ruby/core/string/each_byte_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes.rb', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "String#each_byte" do
it "passes each byte in self to the given block" do
@@ -9,39 +9,39 @@ describe "String#each_byte" do
end
it "keeps iterating from the old position (to new string end) when self changes" do
- r = ""
- s = "hello world"
+ r = +""
+ s = +"hello world"
s.each_byte do |c|
r << c
s.insert(0, "<>") if r.size < 3
end
r.should == "h><>hello world"
- r = ""
- s = "hello world"
+ r = +""
+ s = +"hello world"
s.each_byte { |c| s.slice!(-1); r << c }
r.should == "hello "
- r = ""
- s = "hello world"
+ r = +""
+ s = +"hello world"
s.each_byte { |c| s.slice!(0); r << c }
r.should == "hlowrd"
- r = ""
- s = "hello world"
+ r = +""
+ s = +"hello world"
s.each_byte { |c| s.slice!(0..-1); r << c }
r.should == "h"
end
it "returns self" do
s = "hello"
- (s.each_byte {}).should equal(s)
+ (s.each_byte {}).should.equal?(s)
end
describe "when no block is given" do
it "returns an enumerator" do
enum = "hello".each_byte
- enum.should be_an_instance_of(Enumerator)
+ enum.should.instance_of?(Enumerator)
enum.to_a.should == [104, 101, 108, 108, 111]
end
diff --git a/spec/ruby/core/string/each_char_spec.rb b/spec/ruby/core/string/each_char_spec.rb
index 3233c7609d..36219f79db 100644
--- a/spec/ruby/core/string/each_char_spec.rb
+++ b/spec/ruby/core/string/each_char_spec.rb
@@ -1,7 +1,8 @@
-require File.expand_path('../shared/chars', __FILE__)
-require File.expand_path('../shared/each_char_without_block', __FILE__)
+require_relative "../../spec_helper"
+require_relative 'shared/chars'
+require_relative 'shared/each_char_without_block'
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..08d4292371 100644
--- a/spec/ruby/core/string/each_codepoint_spec.rb
+++ b/spec/ruby/core/string/each_codepoint_spec.rb
@@ -1,10 +1,38 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/codepoints', __FILE__)
-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)
+# encoding: binary
+require_relative '../../spec_helper'
+require_relative 'shared/codepoints'
+
+describe "String#each_codepoint" do
+ it_behaves_like :string_codepoints, :each_codepoint
+
+ describe "when no block is given" do
+ it "returns an Enumerator" do
+ "".each_codepoint.should.instance_of?(Enumerator)
+ end
+
+ it "returns an Enumerator even when self has an invalid encoding" do
+ s = "\xDF".dup.force_encoding(Encoding::UTF_8)
+ s.valid_encoding?.should == false
+ s.each_codepoint.should.instance_of?(Enumerator)
+ end
+
+ describe "returned Enumerator" do
+ describe "size" do
+ it "should return the size of the string" do
+ str = "hello"
+ str.each_codepoint.size.should == str.size
+ str = "ola"
+ str.each_codepoint.size.should == str.size
+ str = "\303\207\342\210\202\303\251\306\222g"
+ str.each_codepoint.size.should == str.size
+ end
+
+ it "should return the size of the string even when the string has an invalid encoding" do
+ s = "\xDF".dup.force_encoding(Encoding::UTF_8)
+ s.valid_encoding?.should == false
+ s.each_codepoint.size.should == 1
+ end
+ end
+ end
end
end
diff --git a/spec/ruby/core/string/each_grapheme_cluster_spec.rb b/spec/ruby/core/string/each_grapheme_cluster_spec.rb
new file mode 100644
index 0000000000..e1fa4ae67b
--- /dev/null
+++ b/spec/ruby/core/string/each_grapheme_cluster_spec.rb
@@ -0,0 +1,16 @@
+require_relative "../../spec_helper"
+require_relative 'shared/chars'
+require_relative 'shared/grapheme_clusters'
+require_relative 'shared/each_char_without_block'
+
+describe "String#each_grapheme_cluster" do
+ it_behaves_like :string_chars, :each_grapheme_cluster
+ it_behaves_like :string_grapheme_clusters, :each_grapheme_cluster
+ it_behaves_like :string_each_char_without_block, :each_grapheme_cluster
+
+ it "yields String instances for subclasses" do
+ a = []
+ StringSpecs::MyString.new("abc").each_grapheme_cluster { |s| a << s.class }
+ a.should == [String, String, String]
+ end
+end
diff --git a/spec/ruby/core/string/each_line_spec.rb b/spec/ruby/core/string/each_line_spec.rb
index 865ae264d6..90fc920bf1 100644
--- a/spec/ruby/core/string/each_line_spec.rb
+++ b/spec/ruby/core/string/each_line_spec.rb
@@ -1,9 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/each_line', __FILE__)
-require File.expand_path('../shared/each_line_without_block', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/each_line'
+require_relative 'shared/each_line_without_block'
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/element_reference_spec.rb b/spec/ruby/core/string/element_reference_spec.rb
index 785bbdaf80..f6e1750c93 100644
--- a/spec/ruby/core/string/element_reference_spec.rb
+++ b/spec/ruby/core/string/element_reference_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes.rb', __FILE__)
-require File.expand_path('../shared/slice.rb', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/slice'
describe "String#[]" do
it_behaves_like :string_slice, :[]
diff --git a/spec/ruby/core/string/element_set_spec.rb b/spec/ruby/core/string/element_set_spec.rb
index fea03607f2..2abc5117aa 100644
--- a/spec/ruby/core/string/element_set_spec.rb
+++ b/spec/ruby/core/string/element_set_spec.rb
@@ -1,11 +1,12 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes.rb', __FILE__)
+# frozen_string_literal: false
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
# TODO: Add missing String#[]= specs:
# String#[re, idx] = obj
-describe "String#[]= with Fixnum index" do
+describe "String#[]= with Integer index" do
it "replaces the char at idx with other_str" do
a = "hello"
a[0] = "bam"
@@ -14,29 +15,19 @@ describe "String#[]= with Fixnum index" do
a.should == "bamelo"
end
- it "taints self if other_str is tainted" do
- a = "hello"
- a[0] = "".taint
- a.tainted?.should == true
-
- a = "hello"
- a[0] = "x".taint
- a.tainted?.should == true
- end
-
it "raises an IndexError without changing self if idx is outside of self" do
str = "hello"
- lambda { str[20] = "bam" }.should raise_error(IndexError)
+ -> { str[20] = "bam" }.should.raise(IndexError)
str.should == "hello"
- lambda { str[-20] = "bam" }.should raise_error(IndexError)
+ -> { str[-20] = "bam" }.should.raise(IndexError)
str.should == "hello"
- lambda { ""[-1] = "bam" }.should raise_error(IndexError)
+ -> { ""[-1] = "bam" }.should.raise(IndexError)
end
- # Behaviour verfieid correct by matz in
+ # Behaviour is verified by matz in
# http://redmine.ruby-lang.org/issues/show/1750
it "allows assignment to the zero'th element of an empty String" do
str = ""
@@ -46,15 +37,15 @@ describe "String#[]= with Fixnum index" do
it "raises IndexError if the string index doesn't match a position in the string" do
str = "hello"
- lambda { str['y'] = "bam" }.should raise_error(IndexError)
+ -> { str['y'] = "bam" }.should.raise(IndexError)
str.should == "hello"
end
- it "raises a RuntimeError when self is frozen" do
+ it "raises a FrozenError when self is frozen" do
a = "hello"
a.freeze
- lambda { a[0] = "bam" }.should raise_error(RuntimeError)
+ -> { a[0] = "bam" }.should.raise(FrozenError)
end
it "calls to_int on index" do
@@ -78,73 +69,77 @@ describe "String#[]= with Fixnum index" do
end
it "raises a TypeError if other_str can't be converted to a String" do
- lambda { "test"[1] = [] }.should raise_error(TypeError)
- lambda { "test"[1] = mock('x') }.should raise_error(TypeError)
- lambda { "test"[1] = nil }.should raise_error(TypeError)
+ -> { "test"[1] = [] }.should.raise(TypeError)
+ -> { "test"[1] = mock('x') }.should.raise(TypeError)
+ -> { "test"[1] = nil }.should.raise(TypeError)
end
- with_feature :encoding do
- it "raises a TypeError if passed a Fixnum replacement" do
- lambda { "abc"[1] = 65 }.should raise_error(TypeError)
- end
+ it "raises a TypeError if passed an Integer replacement" do
+ -> { "abc"[1] = 65 }.should.raise(TypeError)
+ end
- it "raises an IndexError if the index is greater than character size" do
- lambda { "ã‚れ"[4] = "a" }.should raise_error(IndexError)
- end
+ it "raises an IndexError if the index is greater than character size" do
+ -> { "ã‚れ"[4] = "a" }.should.raise(IndexError)
+ end
- it "calls #to_int to convert the index" do
- index = mock("string element set")
- index.should_receive(:to_int).and_return(1)
+ it "calls #to_int to convert the index" do
+ index = mock("string element set")
+ index.should_receive(:to_int).and_return(1)
- str = "ã‚れ"
- str[index] = "a"
- str.should == "ã‚a"
- end
+ str = "ã‚れ"
+ str[index] = "a"
+ str.should == "ã‚a"
+ end
- it "raises a TypeError if #to_int does not return an Fixnum" do
- index = mock("string element set")
- index.should_receive(:to_int).and_return('1')
+ it "raises a TypeError if #to_int does not return an Integer" do
+ index = mock("string element set")
+ index.should_receive(:to_int).and_return('1')
- lambda { "abc"[index] = "d" }.should raise_error(TypeError)
- end
+ -> { "abc"[index] = "d" }.should.raise(TypeError)
+ end
- it "raises an IndexError if #to_int returns a value out of range" do
- index = mock("string element set")
- index.should_receive(:to_int).and_return(4)
+ it "raises an IndexError if #to_int returns a value out of range" do
+ index = mock("string element set")
+ index.should_receive(:to_int).and_return(4)
- lambda { "ab"[index] = "c" }.should raise_error(IndexError)
- end
+ -> { "ab"[index] = "c" }.should.raise(IndexError)
+ end
- it "replaces a character with a multibyte character" do
- str = "ã‚りãŒã¨u"
- str[4] = "ã†"
- str.should == "ã‚りãŒã¨ã†"
- end
+ it "replaces a character with a multibyte character" do
+ str = "ã‚りãŒã¨u"
+ str[4] = "ã†"
+ str.should == "ã‚りãŒã¨ã†"
+ end
- it "replaces a multibyte character with a character" do
- str = "ã‚りãŒã¨ã†"
- str[4] = "u"
- str.should == "ã‚りãŒã¨u"
- end
+ it "replaces a multibyte character with a character" do
+ str = "ã‚りãŒã¨ã†"
+ str[4] = "u"
+ str.should == "ã‚りãŒã¨u"
+ end
- it "replaces a multibyte character with a multibyte character" do
- str = "ã‚りãŒã¨ãŠ"
- str[4] = "ã†"
- str.should == "ã‚りãŒã¨ã†"
- end
+ it "replaces a multibyte character with a multibyte character" do
+ str = "ã‚りãŒã¨ãŠ"
+ str[4] = "ã†"
+ str.should == "ã‚りãŒã¨ã†"
+ end
- it "encodes the String in an encoding compatible with the replacement" do
- str = " ".force_encoding Encoding::US_ASCII
- rep = [160].pack('C').force_encoding Encoding::ASCII_8BIT
- str[0] = rep
- str.encoding.should equal(Encoding::ASCII_8BIT)
- end
+ it "encodes the String in an encoding compatible with the replacement" do
+ str = " ".force_encoding Encoding::US_ASCII
+ rep = [160].pack('C').force_encoding Encoding::BINARY
+ str[0] = rep
+ str.encoding.should.equal?(Encoding::BINARY)
+ end
- it "raises an Encoding::CompatibilityError if the replacement encoding is incompatible" do
- str = "ã‚れ"
- rep = "ãŒ".encode Encoding::EUC_JP
- lambda { str[0] = rep }.should raise_error(Encoding::CompatibilityError)
- end
+ it "updates the string to a compatible encoding" do
+ str = " "
+ str[1] = [0xB9].pack("C*")
+ str.encoding.should == Encoding::ASCII_8BIT
+ end
+
+ it "raises an Encoding::CompatibilityError if the replacement encoding is incompatible" do
+ str = "ã‚れ"
+ rep = "ãŒ".encode Encoding::EUC_JP
+ -> { str[0] = rep }.should.raise(Encoding::CompatibilityError)
end
end
@@ -169,40 +164,38 @@ describe "String#[]= with String index" do
it "raises an IndexError if the search String is not found" do
str = "abcde"
- lambda { str["g"] = "h" }.should raise_error(IndexError)
+ -> { str["g"] = "h" }.should.raise(IndexError)
end
- with_feature :encoding do
- it "replaces characters with a multibyte character" do
- str = "ã‚りgaã¨ã†"
- str["ga"] = "ãŒ"
- str.should == "ã‚りãŒã¨ã†"
- end
+ it "replaces characters with a multibyte character" do
+ str = "ã‚りgaã¨ã†"
+ str["ga"] = "ãŒ"
+ str.should == "ã‚りãŒã¨ã†"
+ end
- it "replaces multibyte characters with characters" do
- str = "ã‚りãŒã¨ã†"
- str["ãŒ"] = "ga"
- str.should == "ã‚りgaã¨ã†"
- end
+ it "replaces multibyte characters with characters" do
+ str = "ã‚りãŒã¨ã†"
+ str["ãŒ"] = "ga"
+ str.should == "ã‚りgaã¨ã†"
+ end
- it "replaces multibyte characters with multibyte characters" do
- str = "ã‚りãŒã¨ã†"
- str["ãŒ"] = "ã‹"
- str.should == "ã‚りã‹ã¨ã†"
- end
+ it "replaces multibyte characters with multibyte characters" do
+ str = "ã‚りãŒã¨ã†"
+ str["ãŒ"] = "ã‹"
+ str.should == "ã‚りã‹ã¨ã†"
+ end
- it "encodes the String in an encoding compatible with the replacement" do
- str = " ".force_encoding Encoding::US_ASCII
- rep = [160].pack('C').force_encoding Encoding::ASCII_8BIT
- str[" "] = rep
- str.encoding.should equal(Encoding::ASCII_8BIT)
- end
+ it "encodes the String in an encoding compatible with the replacement" do
+ str = " ".force_encoding Encoding::US_ASCII
+ rep = [160].pack('C').force_encoding Encoding::BINARY
+ str[" "] = rep
+ str.encoding.should.equal?(Encoding::BINARY)
+ end
- it "raises an Encoding::CompatibilityError if the replacement encoding is incompatible" do
- str = "ã‚れ"
- rep = "ãŒ".encode Encoding::EUC_JP
- lambda { str["れ"] = rep }.should raise_error(Encoding::CompatibilityError)
- end
+ it "raises an Encoding::CompatibilityError if the replacement encoding is incompatible" do
+ str = "ã‚れ"
+ rep = "ãŒ".encode Encoding::EUC_JP
+ -> { str["れ"] = rep }.should.raise(Encoding::CompatibilityError)
end
end
@@ -215,7 +208,7 @@ describe "String#[]= with a Regexp index" do
it "raises IndexError if the regexp index doesn't match a position in the string" do
str = "hello"
- lambda { str[/y/] = "bam" }.should raise_error(IndexError)
+ -> { str[/y/] = "bam" }.should.raise(IndexError)
str.should == "hello"
end
@@ -232,7 +225,7 @@ describe "String#[]= with a Regexp index" do
rep = mock("string element set regexp")
rep.should_not_receive(:to_str)
- lambda { "abc"[/def/] = rep }.should raise_error(IndexError)
+ -> { "abc"[/def/] = rep }.should.raise(IndexError)
end
describe "with 3 arguments" do
@@ -245,11 +238,11 @@ describe "String#[]= with a Regexp index" do
str.should == "axc"
end
- it "raises a TypeError if #to_int does not return a Fixnum" do
+ it "raises a TypeError if #to_int does not return an Integer" do
ref = mock("string element set regexp ref")
ref.should_receive(:to_int).and_return(nil)
- lambda { "abc"[/a(b)/, ref] = "x" }.should raise_error(TypeError)
+ -> { "abc"[/a(b)/, ref] = "x" }.should.raise(TypeError)
end
it "uses the 2nd of 3 arguments as which capture should be replaced" do
@@ -268,56 +261,54 @@ describe "String#[]= with a Regexp index" do
rep = mock("string element set regexp")
rep.should_not_receive(:to_str)
- lambda { "abc"[/a(b)/, 2] = rep }.should raise_error(IndexError)
+ -> { "abc"[/a(b)/, 2] = rep }.should.raise(IndexError)
end
it "raises IndexError if the specified capture isn't available" do
str = "aaa bbb ccc"
- lambda { str[/a (bbb) c/, 2] = "ddd" }.should raise_error(IndexError)
- lambda { str[/a (bbb) c/, -2] = "ddd" }.should raise_error(IndexError)
+ -> { str[/a (bbb) c/, 2] = "ddd" }.should.raise(IndexError)
+ -> { str[/a (bbb) c/, -2] = "ddd" }.should.raise(IndexError)
end
describe "when the optional capture does not match" do
it "raises an IndexError before setting the replacement" do
str1 = "a b c"
str2 = str1.dup
- lambda { str2[/a (b) (Z)?/, 2] = "d" }.should raise_error(IndexError)
+ -> { str2[/a (b) (Z)?/, 2] = "d" }.should.raise(IndexError)
str2.should == str1
end
end
end
- with_feature :encoding do
- it "replaces characters with a multibyte character" do
- str = "ã‚りgaã¨ã†"
- str[/ga/] = "ãŒ"
- str.should == "ã‚りãŒã¨ã†"
- end
+ it "replaces characters with a multibyte character" do
+ str = "ã‚りgaã¨ã†"
+ str[/ga/] = "ãŒ"
+ str.should == "ã‚りãŒã¨ã†"
+ end
- it "replaces multibyte characters with characters" do
- str = "ã‚りãŒã¨ã†"
- str[/ãŒ/] = "ga"
- str.should == "ã‚りgaã¨ã†"
- end
+ it "replaces multibyte characters with characters" do
+ str = "ã‚りãŒã¨ã†"
+ str[/ãŒ/] = "ga"
+ str.should == "ã‚りgaã¨ã†"
+ end
- it "replaces multibyte characters with multibyte characters" do
- str = "ã‚りãŒã¨ã†"
- str[/ãŒ/] = "ã‹"
- str.should == "ã‚りã‹ã¨ã†"
- end
+ it "replaces multibyte characters with multibyte characters" do
+ str = "ã‚りãŒã¨ã†"
+ str[/ãŒ/] = "ã‹"
+ str.should == "ã‚りã‹ã¨ã†"
+ end
- it "encodes the String in an encoding compatible with the replacement" do
- str = " ".force_encoding Encoding::US_ASCII
- rep = [160].pack('C').force_encoding Encoding::ASCII_8BIT
- str[/ /] = rep
- str.encoding.should equal(Encoding::ASCII_8BIT)
- end
+ it "encodes the String in an encoding compatible with the replacement" do
+ str = " ".force_encoding Encoding::US_ASCII
+ rep = [160].pack('C').force_encoding Encoding::BINARY
+ str[/ /] = rep
+ str.encoding.should.equal?(Encoding::BINARY)
+ end
- it "raises an Encoding::CompatibilityError if the replacement encoding is incompatible" do
- str = "ã‚れ"
- rep = "ãŒ".encode Encoding::EUC_JP
- lambda { str[/れ/] = rep }.should raise_error(Encoding::CompatibilityError)
- end
+ it "raises an Encoding::CompatibilityError if the replacement encoding is incompatible" do
+ str = "ã‚れ"
+ rep = "ãŒ".encode Encoding::EUC_JP
+ -> { str[/れ/] = rep }.should.raise(Encoding::CompatibilityError)
end
end
@@ -367,11 +358,11 @@ describe "String#[]= with a Range index" do
end
it "raises a RangeError if negative Range begin is out of range" do
- lambda { "abc"[-4..-2] = "x" }.should raise_error(RangeError)
+ -> { "abc"[-4..-2] = "x" }.should.raise(RangeError, "-4..-2 out of range")
end
it "raises a RangeError if positive Range begin is greater than String size" do
- lambda { "abc"[4..2] = "x" }.should raise_error(RangeError)
+ -> { "abc"[4..2] = "x" }.should.raise(RangeError, "4..2 out of range")
end
it "uses the Range end as an index rather than a count" do
@@ -392,59 +383,57 @@ describe "String#[]= with a Range index" do
str.should == "abcxd"
end
- with_feature :encoding do
- it "replaces characters with a multibyte character" do
- str = "ã‚りgaã¨ã†"
- str[2..3] = "ãŒ"
- str.should == "ã‚りãŒã¨ã†"
- end
+ it "replaces characters with a multibyte character" do
+ str = "ã‚りgaã¨ã†"
+ str[2..3] = "ãŒ"
+ str.should == "ã‚りãŒã¨ã†"
+ end
- it "replaces multibyte characters with characters" do
- str = "ã‚りãŒã¨ã†"
- str[2...3] = "ga"
- str.should == "ã‚りgaã¨ã†"
- end
+ it "replaces multibyte characters with characters" do
+ str = "ã‚りãŒã¨ã†"
+ str[2...3] = "ga"
+ str.should == "ã‚りgaã¨ã†"
+ end
- it "replaces multibyte characters by negative indexes" do
- str = "ã‚りãŒã¨ã†"
- str[-3...-2] = "ga"
- str.should == "ã‚りgaã¨ã†"
- end
+ it "replaces multibyte characters by negative indexes" do
+ str = "ã‚りãŒã¨ã†"
+ str[-3...-2] = "ga"
+ str.should == "ã‚りgaã¨ã†"
+ end
- it "replaces multibyte characters with multibyte characters" do
- str = "ã‚りãŒã¨ã†"
- str[2..2] = "ã‹"
- str.should == "ã‚りã‹ã¨ã†"
- end
+ it "replaces multibyte characters with multibyte characters" do
+ str = "ã‚りãŒã¨ã†"
+ str[2..2] = "ã‹"
+ str.should == "ã‚りã‹ã¨ã†"
+ end
- it "deletes a multibyte character" do
- str = "ã‚りã¨ã†"
- str[2..3] = ""
- str.should == "ã‚り"
- end
+ it "deletes a multibyte character" do
+ str = "ã‚りã¨ã†"
+ str[2..3] = ""
+ str.should == "ã‚り"
+ end
- it "inserts a multibyte character" do
- str = "ã‚りã¨ã†"
- str[2...2] = "ãŒ"
- str.should == "ã‚りãŒã¨ã†"
- end
+ it "inserts a multibyte character" do
+ str = "ã‚りã¨ã†"
+ str[2...2] = "ãŒ"
+ str.should == "ã‚りãŒã¨ã†"
+ end
- it "encodes the String in an encoding compatible with the replacement" do
- str = " ".force_encoding Encoding::US_ASCII
- rep = [160].pack('C').force_encoding Encoding::ASCII_8BIT
- str[0..1] = rep
- str.encoding.should equal(Encoding::ASCII_8BIT)
- end
+ it "encodes the String in an encoding compatible with the replacement" do
+ str = " ".force_encoding Encoding::US_ASCII
+ rep = [160].pack('C').force_encoding Encoding::BINARY
+ str[0..1] = rep
+ str.encoding.should.equal?(Encoding::BINARY)
+ end
- it "raises an Encoding::CompatibilityError if the replacement encoding is incompatible" do
- str = "ã‚れ"
- rep = "ãŒ".encode Encoding::EUC_JP
- lambda { str[0..1] = rep }.should raise_error(Encoding::CompatibilityError)
- end
+ it "raises an Encoding::CompatibilityError if the replacement encoding is incompatible" do
+ str = "ã‚れ"
+ rep = "ãŒ".encode Encoding::EUC_JP
+ -> { str[0..1] = rep }.should.raise(Encoding::CompatibilityError)
end
end
-describe "String#[]= with Fixnum index, count" do
+describe "String#[]= with Integer index, count" do
it "starts at idx and overwrites count characters before inserting the rest of other_str" do
a = "hello"
a[0, 2] = "xx"
@@ -493,16 +482,6 @@ describe "String#[]= with Fixnum index, count" do
a.should == "hellobob"
end
- it "taints self if other_str is tainted" do
- a = "hello"
- a[0, 0] = "".taint
- a.tainted?.should == true
-
- a = "hello"
- a[1, 4] = "x".taint
- a.tainted?.should == true
- end
-
it "calls #to_int to convert the index and count objects" do
index = mock("string element set index")
index.should_receive(:to_int).and_return(-4)
@@ -519,14 +498,14 @@ describe "String#[]= with Fixnum index, count" do
index = mock("string element set index")
index.should_receive(:to_int).and_return("1")
- lambda { "abc"[index, 2] = "xyz" }.should raise_error(TypeError)
+ -> { "abc"[index, 2] = "xyz" }.should.raise(TypeError)
end
it "raises a TypeError if #to_int for count does not return an Integer" do
count = mock("string element set count")
count.should_receive(:to_int).and_return("1")
- lambda { "abc"[1, count] = "xyz" }.should raise_error(TypeError)
+ -> { "abc"[1, count] = "xyz" }.should.raise(TypeError)
end
it "calls #to_str to convert the replacement object" do
@@ -542,71 +521,69 @@ describe "String#[]= with Fixnum index, count" do
r = mock("string element set replacement")
r.should_receive(:to_str).and_return(nil)
- lambda { "abc"[1, 1] = r }.should raise_error(TypeError)
+ -> { "abc"[1, 1] = r }.should.raise(TypeError)
end
it "raises an IndexError if |idx| is greater than the length of the string" do
- lambda { "hello"[6, 0] = "bob" }.should raise_error(IndexError)
- lambda { "hello"[-6, 0] = "bob" }.should raise_error(IndexError)
+ -> { "hello"[6, 0] = "bob" }.should.raise(IndexError)
+ -> { "hello"[-6, 0] = "bob" }.should.raise(IndexError)
end
it "raises an IndexError if count < 0" do
- lambda { "hello"[0, -1] = "bob" }.should raise_error(IndexError)
- lambda { "hello"[1, -1] = "bob" }.should raise_error(IndexError)
+ -> { "hello"[0, -1] = "bob" }.should.raise(IndexError)
+ -> { "hello"[1, -1] = "bob" }.should.raise(IndexError)
end
it "raises a TypeError if other_str is a type other than String" do
- lambda { "hello"[0, 2] = nil }.should raise_error(TypeError)
- lambda { "hello"[0, 2] = [] }.should raise_error(TypeError)
- lambda { "hello"[0, 2] = 33 }.should raise_error(TypeError)
+ -> { "hello"[0, 2] = nil }.should.raise(TypeError)
+ -> { "hello"[0, 2] = [] }.should.raise(TypeError)
+ -> { "hello"[0, 2] = 33 }.should.raise(TypeError)
end
- with_feature :encoding do
- it "replaces characters with a multibyte character" do
- str = "ã‚りgaã¨ã†"
- str[2, 2] = "ãŒ"
- str.should == "ã‚りãŒã¨ã†"
- end
+ it "replaces characters with a multibyte character" do
+ str = "ã‚りgaã¨ã†"
+ str[2, 2] = "ãŒ"
+ str.should == "ã‚りãŒã¨ã†"
+ end
- it "replaces multibyte characters with characters" do
- str = "ã‚りãŒã¨ã†"
- str[2, 1] = "ga"
- str.should == "ã‚りgaã¨ã†"
- end
+ it "replaces multibyte characters with characters" do
+ str = "ã‚りãŒã¨ã†"
+ str[2, 1] = "ga"
+ str.should == "ã‚りgaã¨ã†"
+ end
- it "replaces multibyte characters with multibyte characters" do
- str = "ã‚りãŒã¨ã†"
- str[2, 1] = "ã‹"
- str.should == "ã‚りã‹ã¨ã†"
- end
+ it "replaces multibyte characters with multibyte characters" do
+ str = "ã‚りãŒã¨ã†"
+ str[2, 1] = "ã‹"
+ str.should == "ã‚りã‹ã¨ã†"
+ end
- it "deletes a multibyte character" do
- str = "ã‚りã¨ã†"
- str[2, 2] = ""
- str.should == "ã‚り"
- end
+ it "deletes a multibyte character" do
+ str = "ã‚りã¨ã†"
+ str[2, 2] = ""
+ str.should == "ã‚り"
+ end
- it "inserts a multibyte character" do
- str = "ã‚りã¨ã†"
- str[2, 0] = "ãŒ"
- str.should == "ã‚りãŒã¨ã†"
- end
+ it "inserts a multibyte character" do
+ str = "ã‚りã¨ã†"
+ str[2, 0] = "ãŒ"
+ str.should == "ã‚りãŒã¨ã†"
+ end
- it "raises an IndexError if the character index is out of range of a multibyte String" do
- lambda { "ã‚れ"[3, 0] = "り" }.should raise_error(IndexError)
- end
+ it "raises an IndexError if the character index is out of range of a multibyte String" do
+ -> { "ã‚れ"[3, 0] = "り" }.should.raise(IndexError)
+ end
- it "encodes the String in an encoding compatible with the replacement" do
- str = " ".force_encoding Encoding::US_ASCII
- rep = [160].pack('C').force_encoding Encoding::ASCII_8BIT
- str[0, 1] = rep
- str.encoding.should equal(Encoding::ASCII_8BIT)
- end
+ it "encodes the String in an encoding compatible with the replacement" do
+ str = " ".force_encoding Encoding::US_ASCII
+ rep = [160].pack('C').force_encoding Encoding::BINARY
+ str[0, 1] = rep
+ str.encoding.should.equal?(Encoding::BINARY)
+ end
- it "raises an Encoding::CompatibilityError if the replacement encoding is incompatible" do
- str = "ã‚れ"
- rep = "ãŒ".encode Encoding::EUC_JP
- lambda { str[0, 1] = rep }.should raise_error(Encoding::CompatibilityError)
- end
+ it "raises an Encoding::CompatibilityError if the replacement encoding is incompatible" do
+ str = "ã‚れ"
+ rep = "ãŒ".encode Encoding::EUC_JP
+ -> { str[0, 1] = rep }.should.raise(Encoding::CompatibilityError)
end
end
diff --git a/spec/ruby/core/string/empty_spec.rb b/spec/ruby/core/string/empty_spec.rb
index c13e1145e4..8e53a16afc 100644
--- a/spec/ruby/core/string/empty_spec.rb
+++ b/spec/ruby/core/string/empty_spec.rb
@@ -1,12 +1,12 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes.rb', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "String#empty?" do
it "returns true if the string has a length of zero" do
- "hello".empty?.should == false
- " ".empty?.should == false
- "\x00".empty?.should == false
- "".empty?.should == true
- StringSpecs::MyString.new("").empty?.should == true
+ "hello".should_not.empty?
+ " ".should_not.empty?
+ "\x00".should_not.empty?
+ "".should.empty?
+ StringSpecs::MyString.new("").should.empty?
end
end
diff --git a/spec/ruby/core/string/encode_spec.rb b/spec/ruby/core/string/encode_spec.rb
index d051dd58c9..ab096f4041 100644
--- a/spec/ruby/core/string/encode_spec.rb
+++ b/spec/ruby/core/string/encode_spec.rb
@@ -1,159 +1,240 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/encode', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/encode'
-with_feature :encoding do
- describe "String#encode" do
- before :each do
- @external = Encoding.default_external
- @internal = Encoding.default_internal
+describe "String#encode" do
+ before :each do
+ @external = Encoding.default_external
+ @internal = Encoding.default_internal
+ end
+
+ after :each do
+ Encoding.default_external = @external
+ Encoding.default_internal = @internal
+ end
+
+ it_behaves_like :string_encode, :encode
+
+ describe "when passed no options" do
+ it "returns a copy when Encoding.default_internal is nil" do
+ Encoding.default_internal = nil
+ str = "ã‚"
+ encoded = str.encode
+ encoded.should_not.equal?(str)
+ encoded.should == str
end
- after :each do
- Encoding.default_external = @external
- Encoding.default_internal = @internal
+ it "returns a copy for a ASCII-only String when Encoding.default_internal is nil" do
+ Encoding.default_internal = nil
+ str = "abc"
+ encoded = str.encode
+ encoded.should_not.equal?(str)
+ encoded.should == str
+ end
+
+ it "encodes an ascii substring of a binary string to UTF-8" do
+ x82 = [0x82].pack('C')
+ str = "#{x82}foo".dup.force_encoding("binary")[1..-1].encode("utf-8")
+ str.should == "foo".dup.force_encoding("utf-8")
+ str.encoding.should.equal?(Encoding::UTF_8)
+ end
+ end
+
+ describe "when passed to encoding" do
+ it "returns a copy when passed the same encoding as the String" do
+ str = "ã‚"
+ encoded = str.encode(Encoding::UTF_8)
+ encoded.should_not.equal?(str)
+ encoded.should == str
end
- it_behaves_like :string_encode, :encode
+ it "round trips a String" do
+ str = "abc def".dup.force_encoding Encoding::US_ASCII
+ str.encode("utf-32be").encode("ascii").should == "abc def"
+ end
+ end
- describe "when passed no options" do
- it "returns a copy when Encoding.default_internal is nil" do
- Encoding.default_internal = nil
- str = "ã‚"
- str.encode.should_not equal(str)
- end
+ describe "when passed options" do
+ it "returns a copy when Encoding.default_internal is nil" do
+ Encoding.default_internal = nil
+ str = "ã‚"
+ str.encode(invalid: :replace).should_not.equal?(str)
+ end
- it "returns a copy for a ASCII-only String when Encoding.default_internal is nil" do
- Encoding.default_internal = nil
- str = "abc"
- str.encode.should_not equal(str)
- end
+ it "normalizes newlines with cr_newline option" do
+ "\r\nfoo".encode(cr_newline: true).should == "\r\rfoo"
+ "\rfoo".encode(cr_newline: true).should == "\rfoo"
+ "\nfoo".encode(cr_newline: true).should == "\rfoo"
+ end
- it "encodes an ascii substring of a binary string to UTF-8" do
- x82 = [0x82].pack('C')
- str = "#{x82}foo".force_encoding("ascii-8bit")[1..-1].encode("utf-8")
- str.should == "foo".force_encoding("utf-8")
- str.encoding.should equal(Encoding::UTF_8)
- end
+ it "normalizes newlines with crlf_newline option" do
+ "\r\nfoo".encode(crlf_newline: true).should == "\r\r\nfoo"
+ "\rfoo".encode(crlf_newline: true).should == "\rfoo"
+ "\nfoo".encode(crlf_newline: true).should == "\r\nfoo"
end
- describe "when passed to encoding" do
- it "returns a copy when passed the same encoding as the String" do
- str = "ã‚"
- str.encode(Encoding::UTF_8).should_not equal(str)
- end
+ it "normalizes newlines with universal_newline option" do
+ "\r\nfoo".encode(universal_newline: true).should == "\nfoo"
+ "\rfoo".encode(universal_newline: true).should == "\nfoo"
+ "\nfoo".encode(universal_newline: true).should == "\nfoo"
+ end
- it "round trips a String" do
- str = "abc def".force_encoding Encoding::US_ASCII
- str.encode("utf-32be").encode("ascii").should == "abc def"
- end
+ it "replaces invalid encoding in source with default replacement" do
+ encoded = "ã¡\xE3\x81\xFF".encode("UTF-16LE", invalid: :replace)
+ encoded.should == "\u3061\ufffd\ufffd".encode("UTF-16LE")
+ encoded.encode("UTF-8").should == "ã¡\ufffd\ufffd"
end
- describe "when passed options" do
- it "returns a copy when Encoding.default_internal is nil" do
- Encoding.default_internal = nil
- str = "ã‚"
- str.encode(invalid: :replace).should_not equal(str)
- end
+ it "replaces invalid encoding in source with a specified replacement" do
+ encoded = "ã¡\xE3\x81\xFF".encode("UTF-16LE", invalid: :replace, replace: "foo")
+ encoded.should == "\u3061foofoo".encode("UTF-16LE")
+ encoded.encode("UTF-8").should == "ã¡foofoo"
+ end
- it "normalizes newlines" do
- "\r\nfoo".encode(universal_newline: true).should == "\nfoo"
+ it "replace multiple invalid bytes at the end with a single replacement character" do
+ "\xE3\x81\x93\xE3\x81".encode("UTF-8", invalid: :replace).should == "\u3053\ufffd"
+ end
- "\rfoo".encode(universal_newline: true).should == "\nfoo"
- end
+ it "replaces invalid encoding in source using a specified replacement even when a fallback is given" do
+ encoded = "ã¡\xE3\x81\xFF".encode("UTF-16LE", invalid: :replace, replace: "foo", fallback: -> c { "bar" })
+ encoded.should == "\u3061foofoo".encode("UTF-16LE")
+ encoded.encode("UTF-8").should == "ã¡foofoo"
end
- describe "when passed to, from" do
- it "returns a copy in the destination encoding when both encodings are the same" do
- str = "ã‚"
- str.force_encoding("ascii-8bit")
- encoded = str.encode("utf-8", "utf-8")
+ it "replaces undefined encoding in destination with default replacement" do
+ encoded = "B\ufffd".encode(Encoding::US_ASCII, undef: :replace)
+ encoded.should == "B?".encode(Encoding::US_ASCII)
+ encoded.encode("UTF-8").should == "B?"
+ end
- encoded.should_not equal(str)
- encoded.encoding.should == Encoding::UTF_8
- end
+ it "replaces undefined encoding in destination with a specified replacement" do
+ encoded = "B\ufffd".encode(Encoding::US_ASCII, undef: :replace, replace: "foo")
+ encoded.should == "Bfoo".encode(Encoding::US_ASCII)
+ encoded.encode("UTF-8").should == "Bfoo"
+ end
- it "returns the transcoded string" do
- str = "\x00\x00\x00\x1F"
- str.encode(Encoding::UTF_8, Encoding::UTF_16BE).should == "\u0000\u001f"
- end
+ it "replaces undefined encoding in destination with a specified replacement even if a fallback is given" do
+ encoded = "B\ufffd".encode(Encoding::US_ASCII, undef: :replace, replace: "foo", fallback: proc {|x| "bar"})
+ encoded.should == "Bfoo".encode(Encoding::US_ASCII)
+ encoded.encode("UTF-8").should == "Bfoo"
end
- describe "when passed to, options" do
- it "returns a copy when the destination encoding is the same as the String encoding" do
- str = "ã‚"
- str.encode(Encoding::UTF_8, undef: :replace).should_not equal(str)
- end
+ it "replaces undefined encoding in destination using a fallback proc" do
+ encoded = "B\ufffd".encode(Encoding::US_ASCII, fallback: proc {|x| "bar"})
+ encoded.should == "Bbar".encode(Encoding::US_ASCII)
+ encoded.encode("UTF-8").should == "Bbar"
end
- describe "when passed to, from, options" do
- it "returns a copy when both encodings are the same" do
- str = "ã‚"
- str.encode("utf-8", "utf-8", invalid: :replace).should_not equal(str)
- end
+ it "replaces invalid encoding in source using replace even when fallback is given as proc" do
+ encoded = "ã¡\xE3\x81\xFF".encode("UTF-16LE", invalid: :replace, replace: "foo", fallback: proc {|x| "bar"})
+ encoded.should == "\u3061foofoo".encode("UTF-16LE")
+ encoded.encode("UTF-8").should == "ã¡foofoo"
end
end
- describe "String#encode!" do
- before :each do
- @external = Encoding.default_external
- @internal = Encoding.default_internal
+ describe "when passed to, from" do
+ it "returns a copy in the destination encoding when both encodings are the same" do
+ str = "ã‚".dup.force_encoding("binary")
+ encoded = str.encode("utf-8", "utf-8")
+
+ encoded.should_not.equal?(str)
+ encoded.should == str.force_encoding("utf-8")
+ encoded.encoding.should == Encoding::UTF_8
end
- after :each do
- Encoding.default_external = @external
- Encoding.default_internal = @internal
+ it "returns the transcoded string" do
+ str = "\x00\x00\x00\x1F"
+ str.encode(Encoding::UTF_8, Encoding::UTF_16BE).should == "\u0000\u001f"
end
+ end
- it_behaves_like :string_encode, :encode!
+ describe "when passed to, options" do
+ it "returns a copy when the destination encoding is the same as the String encoding" do
+ str = "ã‚"
+ encoded = str.encode(Encoding::UTF_8, undef: :replace)
+ encoded.should_not.equal?(str)
+ encoded.should == str
+ end
+ end
- it "raises a RuntimeError when called on a frozen String" do
- lambda { "foo".freeze.encode!("euc-jp") }.should raise_error(RuntimeError)
+ describe "when passed to, from, options" do
+ it "returns a copy when both encodings are the same" do
+ str = "ã‚"
+ encoded = str.encode("utf-8", "utf-8", invalid: :replace)
+ encoded.should_not.equal?(str)
+ encoded.should == str
end
- # http://redmine.ruby-lang.org/issues/show/1836
- it "raises a RuntimeError when called on a frozen String when it's a no-op" do
- lambda { "foo".freeze.encode!("utf-8") }.should raise_error(RuntimeError)
+ it "returns a copy in the destination encoding when both encodings are the same" do
+ str = "ã‚".dup.force_encoding("binary")
+ encoded = str.encode("utf-8", "utf-8", invalid: :replace)
+
+ encoded.should_not.equal?(str)
+ encoded.should == str.force_encoding("utf-8")
+ encoded.encoding.should == Encoding::UTF_8
end
+ end
+end
+
+describe "String#encode!" do
+ before :each do
+ @external = Encoding.default_external
+ @internal = Encoding.default_internal
+ end
+
+ after :each do
+ Encoding.default_external = @external
+ Encoding.default_internal = @internal
+ end
- describe "when passed no options" do
- it "returns self when Encoding.default_internal is nil" do
- Encoding.default_internal = nil
- str = "ã‚"
- str.encode!.should equal(str)
- end
+ it_behaves_like :string_encode, :encode!
- it "returns self for a ASCII-only String when Encoding.default_internal is nil" do
- Encoding.default_internal = nil
- str = "abc"
- str.encode!.should equal(str)
- end
+ it "raises a FrozenError when called on a frozen String" do
+ -> { "foo".freeze.encode!("euc-jp") }.should.raise(FrozenError)
+ end
+
+ # http://redmine.ruby-lang.org/issues/show/1836
+ it "raises a FrozenError when called on a frozen String when it's a no-op" do
+ -> { "foo".freeze.encode!("utf-8") }.should.raise(FrozenError)
+ end
+
+ describe "when passed no options" do
+ it "returns self when Encoding.default_internal is nil" do
+ Encoding.default_internal = nil
+ str = +"ã‚"
+ str.encode!.should.equal?(str)
end
- describe "when passed options" do
- it "returns self for ASCII-only String when Encoding.default_internal is nil" do
- Encoding.default_internal = nil
- str = "abc"
- str.encode!(invalid: :replace).should equal(str)
- end
+ it "returns self for a ASCII-only String when Encoding.default_internal is nil" do
+ Encoding.default_internal = nil
+ str = +"abc"
+ str.encode!.should.equal?(str)
end
+ end
- describe "when passed to encoding" do
- it "returns self" do
- str = "abc"
- result = str.encode!(Encoding::BINARY)
- result.encoding.should equal(Encoding::BINARY)
- result.should equal(str)
- end
+ describe "when passed options" do
+ it "returns self for ASCII-only String when Encoding.default_internal is nil" do
+ Encoding.default_internal = nil
+ str = +"abc"
+ str.encode!(invalid: :replace).should.equal?(str)
end
+ end
+
+ describe "when passed to encoding" do
+ it "returns self" do
+ str = +"abc"
+ result = str.encode!(Encoding::BINARY)
+ result.encoding.should.equal?(Encoding::BINARY)
+ result.should.equal?(str)
+ end
+ end
- describe "when passed to, from" do
- it "returns self" do
- str = "ã‚ã‚"
- result = str.encode!("euc-jp", "utf-8")
- result.encoding.should equal(Encoding::EUC_JP)
- result.should equal(str)
- end
+ describe "when passed to, from" do
+ it "returns self" do
+ str = +"ã‚ã‚"
+ result = str.encode!("euc-jp", "utf-8")
+ result.encoding.should.equal?(Encoding::EUC_JP)
+ result.should.equal?(str)
end
end
end
diff --git a/spec/ruby/core/string/encoding_spec.rb b/spec/ruby/core/string/encoding_spec.rb
index 9c655757a8..aa0e4765ed 100644
--- a/spec/ruby/core/string/encoding_spec.rb
+++ b/spec/ruby/core/string/encoding_spec.rb
@@ -1,189 +1,184 @@
# -*- encoding: us-ascii -*-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/iso-8859-9-encoding', __FILE__)
-
-with_feature :encoding do
- describe "String#encoding" do
- it "returns an Encoding object" do
- String.new.encoding.should be_an_instance_of(Encoding)
- end
-
- it "is equal to the source encoding by default" do
- s = StringSpecs::ISO88599Encoding.new
- s.cedilla.encoding.should == s.source_encoding
- end
-
- it "returns the given encoding if #force_encoding has been called" do
- "a".force_encoding(Encoding::SHIFT_JIS).encoding.should == Encoding::SHIFT_JIS
- end
-
- it "returns the given encoding if #encode!has been called" do
- "a".encode!(Encoding::SHIFT_JIS).encoding.should == Encoding::SHIFT_JIS
- end
- end
-
- describe "String#encoding for US-ASCII Strings" do
- it "returns US-ASCII if self is US-ASCII" do
- "a".encoding.should == Encoding::US_ASCII
- end
-
- it "returns US-ASCII if self is US-ASCII only, despite the default internal encoding being different" do
- default_internal = Encoding.default_internal
- Encoding.default_internal = Encoding::UTF_8
- "a".encoding.should == Encoding::US_ASCII
- Encoding.default_internal = default_internal
- end
-
- it "returns US-ASCII if self is US-ASCII only, despite the default external encoding being different" do
- default_external = Encoding.default_external
- Encoding.default_external = Encoding::UTF_8
- "a".encoding.should == Encoding::US_ASCII
- Encoding.default_external = default_external
- end
-
- it "returns US-ASCII if self is US-ASCII only, despite the default internal and external encodings being different" do
- default_internal = Encoding.default_internal
- default_external = Encoding.default_external
- Encoding.default_internal = Encoding::UTF_8
- Encoding.default_external = Encoding::UTF_8
- "a".encoding.should == Encoding::US_ASCII
- Encoding.default_external = default_external
- Encoding.default_internal = default_internal
- end
-
- it "returns US-ASCII if self is US-ASCII only, despite the default encodings being different" do
- default_internal = Encoding.default_internal
- default_external = Encoding.default_external
- Encoding.default_internal = Encoding::UTF_8
- Encoding.default_external = Encoding::UTF_8
- "a".encoding.should == Encoding::US_ASCII
- Encoding.default_external = default_external
- Encoding.default_internal = default_internal
- end
-
- end
-
- describe "String#encoding for Strings with \\u escapes" do
- it "returns UTF-8" do
- "\u{4040}".encoding.should == Encoding::UTF_8
- end
-
- it "returns US-ASCII if self is US-ASCII only" do
- s = "\u{40}"
- s.ascii_only?.should be_true
- s.encoding.should == Encoding::US_ASCII
- end
-
- it "returns UTF-8 if self isn't US-ASCII only" do
- s = "\u{4076}\u{619}"
- s.ascii_only?.should be_false
- s.encoding.should == Encoding::UTF_8
- end
-
- it "is not affected by the default internal encoding" do
- default_internal = Encoding.default_internal
- Encoding.default_internal = Encoding::ISO_8859_15
- "\u{5050}".encoding.should == Encoding::UTF_8
- "\u{50}".encoding.should == Encoding::US_ASCII
- Encoding.default_internal = default_internal
- end
-
- it "is not affected by the default external encoding" do
- default_external = Encoding.default_external
- Encoding.default_external = Encoding::SHIFT_JIS
- "\u{50}".encoding.should == Encoding::US_ASCII
- "\u{5050}".encoding.should == Encoding::UTF_8
- Encoding.default_external = default_external
- end
-
- it "is not affected by both the default internal and external encoding being set at the same time" do
- default_internal = Encoding.default_internal
- default_external = Encoding.default_external
- Encoding.default_internal = Encoding::EUC_JP
- Encoding.default_external = Encoding::SHIFT_JIS
- "\u{50}".encoding.should == Encoding::US_ASCII
- "\u{507}".encoding.should == Encoding::UTF_8
- Encoding.default_external = default_external
- Encoding.default_internal = default_internal
- end
-
- it "returns the given encoding if #force_encoding has been called" do
- "\u{20}".force_encoding(Encoding::SHIFT_JIS).encoding.should == Encoding::SHIFT_JIS
- "\u{2020}".force_encoding(Encoding::SHIFT_JIS).encoding.should == Encoding::SHIFT_JIS
- end
-
- it "returns the given encoding if #encode!has been called" do
- "\u{20}".encode!(Encoding::SHIFT_JIS).encoding.should == Encoding::SHIFT_JIS
- "\u{2020}".encode!(Encoding::SHIFT_JIS).encoding.should == Encoding::SHIFT_JIS
- end
- end
-
- describe "String#encoding for Strings with \\x escapes" do
-
- it "returns US-ASCII if self is US-ASCII only" do
- s = "\x61"
- s.ascii_only?.should be_true
- s.encoding.should == Encoding::US_ASCII
- end
-
- it "returns ASCII-8BIT when an escape creates a byte with the 8th bit set if the source encoding is US-ASCII" do
- __ENCODING__.should == Encoding::US_ASCII
- str = " "
- str.encoding.should == Encoding::US_ASCII
- str += [0xDF].pack('C')
- str.ascii_only?.should be_false
- str.encoding.should == Encoding::ASCII_8BIT
- end
-
- # TODO: Deal with case when the byte in question isn't valid in the source
- # encoding?
- it "returns the source encoding when an escape creates a byte with the 8th bit set if the source encoding isn't US-ASCII" do
- fixture = StringSpecs::ISO88599Encoding.new
- fixture.source_encoding.should == Encoding::ISO8859_9
- fixture.x_escape.ascii_only?.should be_false
- fixture.x_escape.encoding.should == Encoding::ISO8859_9
- end
-
- it "is not affected by the default internal encoding" do
- default_internal = Encoding.default_internal
- Encoding.default_internal = Encoding::ISO_8859_15
- "\x50".encoding.should == Encoding::US_ASCII
- "\x50".encoding.should == Encoding::US_ASCII
- Encoding.default_internal = default_internal
- end
-
- it "is not affected by the default external encoding" do
- default_external = Encoding.default_external
- Encoding.default_external = Encoding::SHIFT_JIS
- "\x50".encoding.should == Encoding::US_ASCII
- [0xD4].pack('C').encoding.should == Encoding::ASCII_8BIT
- Encoding.default_external = default_external
- end
-
- it "is not affected by both the default internal and external encoding being set at the same time" do
- default_internal = Encoding.default_internal
- default_external = Encoding.default_external
- Encoding.default_internal = Encoding::EUC_JP
- Encoding.default_external = Encoding::SHIFT_JIS
- x50 = "\x50"
- x50.encoding.should == Encoding::US_ASCII
- [0xD4].pack('C').encoding.should == Encoding::ASCII_8BIT
- Encoding.default_external = default_external
- Encoding.default_internal = default_internal
- end
-
- it "returns the given encoding if #force_encoding has been called" do
- x50 = "\x50"
- x50.force_encoding(Encoding::SHIFT_JIS).encoding.should == Encoding::SHIFT_JIS
- xD4 = [212].pack('C')
- xD4.force_encoding(Encoding::ISO_8859_9).encoding.should == Encoding::ISO_8859_9
- end
-
- it "returns the given encoding if #encode!has been called" do
- x50 = "\x50"
- x50.encode!(Encoding::SHIFT_JIS).encoding.should == Encoding::SHIFT_JIS
- x00 = "x\00"
- x00.encode!(Encoding::UTF_8).encoding.should == Encoding::UTF_8
- end
+require_relative '../../spec_helper'
+require_relative 'fixtures/iso-8859-9-encoding'
+
+describe "String#encoding" do
+ it "returns an Encoding object" do
+ String.new.encoding.should.instance_of?(Encoding)
+ end
+
+ it "is equal to the source encoding by default" do
+ s = StringSpecs::ISO88599Encoding.new
+ s.cedilla.encoding.should == s.source_encoding
+ s.cedilla.encode("utf-8").should == 350.chr(Encoding::UTF_8) # S-cedilla
+ end
+
+ it "returns the given encoding if #force_encoding has been called" do
+ "a".dup.force_encoding(Encoding::SHIFT_JIS).encoding.should == Encoding::SHIFT_JIS
+ end
+
+ it "returns the given encoding if #encode!has been called" do
+ "a".dup.encode!(Encoding::SHIFT_JIS).encoding.should == Encoding::SHIFT_JIS
+ end
+end
+
+describe "String#encoding for US-ASCII Strings" do
+ it "returns US-ASCII if self is US-ASCII" do
+ "a".encoding.should == Encoding::US_ASCII
+ end
+
+ it "returns US-ASCII if self is US-ASCII only, despite the default internal encoding being different" do
+ default_internal = Encoding.default_internal
+ Encoding.default_internal = Encoding::UTF_8
+ "a".encoding.should == Encoding::US_ASCII
+ Encoding.default_internal = default_internal
+ end
+
+ it "returns US-ASCII if self is US-ASCII only, despite the default external encoding being different" do
+ default_external = Encoding.default_external
+ Encoding.default_external = Encoding::UTF_8
+ "a".encoding.should == Encoding::US_ASCII
+ Encoding.default_external = default_external
+ end
+
+ it "returns US-ASCII if self is US-ASCII only, despite the default internal and external encodings being different" do
+ default_internal = Encoding.default_internal
+ default_external = Encoding.default_external
+ Encoding.default_internal = Encoding::UTF_8
+ Encoding.default_external = Encoding::UTF_8
+ "a".encoding.should == Encoding::US_ASCII
+ Encoding.default_external = default_external
+ Encoding.default_internal = default_internal
+ end
+
+ it "returns US-ASCII if self is US-ASCII only, despite the default encodings being different" do
+ default_internal = Encoding.default_internal
+ default_external = Encoding.default_external
+ Encoding.default_internal = Encoding::UTF_8
+ Encoding.default_external = Encoding::UTF_8
+ "a".encoding.should == Encoding::US_ASCII
+ Encoding.default_external = default_external
+ Encoding.default_internal = default_internal
+ end
+
+end
+
+describe "String#encoding for Strings with \\u escapes" do
+ it "returns UTF-8" do
+ "\u{4040}".encoding.should == Encoding::UTF_8
+ end
+
+ it "returns US-ASCII if self is US-ASCII only" do
+ s = "\u{40}"
+ s.ascii_only?.should == true
+ s.encoding.should == Encoding::US_ASCII
+ end
+
+ it "returns UTF-8 if self isn't US-ASCII only" do
+ s = "\u{4076}\u{619}"
+ s.ascii_only?.should == false
+ s.encoding.should == Encoding::UTF_8
+ end
+
+ it "is not affected by the default internal encoding" do
+ default_internal = Encoding.default_internal
+ Encoding.default_internal = Encoding::ISO_8859_15
+ "\u{5050}".encoding.should == Encoding::UTF_8
+ "\u{50}".encoding.should == Encoding::US_ASCII
+ Encoding.default_internal = default_internal
+ end
+
+ it "is not affected by the default external encoding" do
+ default_external = Encoding.default_external
+ Encoding.default_external = Encoding::SHIFT_JIS
+ "\u{50}".encoding.should == Encoding::US_ASCII
+ "\u{5050}".encoding.should == Encoding::UTF_8
+ Encoding.default_external = default_external
+ end
+
+ it "is not affected by both the default internal and external encoding being set at the same time" do
+ default_internal = Encoding.default_internal
+ default_external = Encoding.default_external
+ Encoding.default_internal = Encoding::EUC_JP
+ Encoding.default_external = Encoding::SHIFT_JIS
+ "\u{50}".encoding.should == Encoding::US_ASCII
+ "\u{507}".encoding.should == Encoding::UTF_8
+ Encoding.default_external = default_external
+ Encoding.default_internal = default_internal
+ end
+
+ it "returns the given encoding if #force_encoding has been called" do
+ "\u{20}".dup.force_encoding(Encoding::SHIFT_JIS).encoding.should == Encoding::SHIFT_JIS
+ "\u{2020}".dup.force_encoding(Encoding::SHIFT_JIS).encoding.should == Encoding::SHIFT_JIS
+ end
+
+ it "returns the given encoding if #encode!has been called" do
+ "\u{20}".dup.encode!(Encoding::SHIFT_JIS).encoding.should == Encoding::SHIFT_JIS
+ "\u{2020}".dup.encode!(Encoding::SHIFT_JIS).encoding.should == Encoding::SHIFT_JIS
+ end
+end
+
+describe "String#encoding for Strings with \\x escapes" do
+
+ it "returns US-ASCII if self is US-ASCII only" do
+ s = "\x61"
+ s.ascii_only?.should == true
+ s.encoding.should == Encoding::US_ASCII
+ end
+
+ it "returns BINARY when an escape creates a byte with the 8th bit set if the source encoding is US-ASCII" do
+ __ENCODING__.should == Encoding::US_ASCII
+ str = " "
+ str.encoding.should == Encoding::US_ASCII
+ str += [0xDF].pack('C')
+ str.ascii_only?.should == false
+ str.encoding.should == Encoding::BINARY
+ end
+
+ # TODO: Deal with case when the byte in question isn't valid in the source
+ # encoding?
+ it "returns the source encoding when an escape creates a byte with the 8th bit set if the source encoding isn't US-ASCII" do
+ fixture = StringSpecs::ISO88599Encoding.new
+ fixture.source_encoding.should == Encoding::ISO8859_9
+ fixture.x_escape.ascii_only?.should == false
+ fixture.x_escape.encoding.should == Encoding::ISO8859_9
+ end
+
+ it "is not affected by the default internal encoding" do
+ default_internal = Encoding.default_internal
+ Encoding.default_internal = Encoding::ISO_8859_15
+ "\x50".encoding.should == Encoding::US_ASCII
+ "\x50".encoding.should == Encoding::US_ASCII
+ Encoding.default_internal = default_internal
+ end
+
+ it "is not affected by the default external encoding" do
+ default_external = Encoding.default_external
+ Encoding.default_external = Encoding::SHIFT_JIS
+ "\x50".encoding.should == Encoding::US_ASCII
+ [0xD4].pack('C').encoding.should == Encoding::BINARY
+ Encoding.default_external = default_external
+ end
+
+ it "is not affected by both the default internal and external encoding being set at the same time" do
+ default_internal = Encoding.default_internal
+ default_external = Encoding.default_external
+ Encoding.default_internal = Encoding::EUC_JP
+ Encoding.default_external = Encoding::SHIFT_JIS
+ x50 = "\x50"
+ x50.encoding.should == Encoding::US_ASCII
+ [0xD4].pack('C').encoding.should == Encoding::BINARY
+ Encoding.default_external = default_external
+ Encoding.default_internal = default_internal
+ end
+
+ it "returns the given encoding if #force_encoding has been called" do
+ "\x50".dup.force_encoding(Encoding::SHIFT_JIS).encoding.should == Encoding::SHIFT_JIS
+ [212].pack('C').force_encoding(Encoding::ISO_8859_9).encoding.should == Encoding::ISO_8859_9
+ end
+
+ it "returns the given encoding if #encode!has been called" do
+ "\x50".dup.encode!(Encoding::SHIFT_JIS).encoding.should == Encoding::SHIFT_JIS
+ "x\00".dup.encode!(Encoding::UTF_8).encoding.should == Encoding::UTF_8
end
end
diff --git a/spec/ruby/core/string/end_with_spec.rb b/spec/ruby/core/string/end_with_spec.rb
index 2c3ff07272..ac4fff72ad 100644
--- a/spec/ruby/core/string/end_with_spec.rb
+++ b/spec/ruby/core/string/end_with_spec.rb
@@ -1,50 +1,8 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes.rb', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative '../../shared/string/end_with'
describe "String#end_with?" do
- it "returns true only if ends match" do
- s = "hello"
- s.end_with?('o').should be_true
- s.end_with?('llo').should be_true
- end
-
- it 'returns false if the end does not match' do
- s = 'hello'
- s.end_with?('ll').should be_false
- end
-
- it "returns true if the search string is empty" do
- "hello".end_with?("").should be_true
- "".end_with?("").should be_true
- end
-
- it "returns true only if any ending match" do
- "hello".end_with?('x', 'y', 'llo', 'z').should be_true
- end
-
- it "converts its argument using :to_str" do
- s = "hello"
- find = mock('o')
- find.should_receive(:to_str).and_return("o")
- s.end_with?(find).should be_true
- end
-
- it "ignores arguments not convertible to string" do
- "hello".end_with?().should be_false
- lambda { "hello".end_with?(1) }.should raise_error(TypeError)
- lambda { "hello".end_with?(["o"]) }.should raise_error(TypeError)
- lambda { "hello".end_with?(1, nil, "o") }.should raise_error(TypeError)
- end
-
- it "uses only the needed arguments" do
- find = mock('h')
- find.should_not_receive(:to_str)
- "hello".end_with?("o",find).should be_true
- end
-
- it "works for multibyte strings" do
- "céréale".end_with?("réale").should be_true
- end
-
+ it_behaves_like :end_with, :to_s
end
diff --git a/spec/ruby/core/string/eql_spec.rb b/spec/ruby/core/string/eql_spec.rb
index df094e122f..46ebeda509 100644
--- a/spec/ruby/core/string/eql_spec.rb
+++ b/spec/ruby/core/string/eql_spec.rb
@@ -1,21 +1,21 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/eql', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/eql'
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
- 'hello'.should_not eql(5)
+ 'hello'.should_not.eql?(5)
not_supported_on :opal do
- 'hello'.should_not eql(:hello)
+ 'hello'.should_not.eql?(:hello)
end
- 'hello'.should_not eql(mock('x'))
+ 'hello'.should_not.eql?(mock('x'))
end
it "does not try to call #to_str on the given argument" do
(obj = mock('x')).should_not_receive(:to_str)
- 'hello'.should_not eql(obj)
+ 'hello'.should_not.eql?(obj)
end
end
end
diff --git a/spec/ruby/core/string/equal_value_spec.rb b/spec/ruby/core/string/equal_value_spec.rb
index bf252d6d30..e8b706c524 100644
--- a/spec/ruby/core/string/equal_value_spec.rb
+++ b/spec/ruby/core/string/equal_value_spec.rb
@@ -1,8 +1,30 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/eql', __FILE__)
-require File.expand_path('../shared/equal_value', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/eql'
describe "String#==" do
- it_behaves_like(:string_eql_value, :==)
- it_behaves_like(:string_equal_value, :==)
+ it_behaves_like :string_eql_value, :==
+
+ it "returns false if obj does not respond to to_str" do
+ ('hello' == 5).should == false
+ not_supported_on :opal do
+ ('hello' == :hello).should == false
+ end
+ ('hello' == mock('x')).should == false
+ end
+
+ it "returns obj == self if obj responds to to_str" do
+ obj = Object.new
+
+ # String#== merely checks if #to_str is defined. It does
+ # not call it.
+ obj.stub!(:to_str)
+
+ obj.should_receive(:==).and_return(true)
+
+ ('hello' == obj).should == true
+ end
+
+ it "is not fooled by NUL characters" do
+ ("abc\0def" == "abc\0xyz").should == false
+ end
end
diff --git a/spec/ruby/core/string/fixtures/classes.rb b/spec/ruby/core/string/fixtures/classes.rb
index 6af106f9d3..26fcd51b5d 100644
--- a/spec/ruby/core/string/fixtures/classes.rb
+++ b/spec/ruby/core/string/fixtures/classes.rb
@@ -4,7 +4,7 @@ class Object
def unpack_format(count=nil, repeat=nil)
format = "#{instance_variable_get(:@method)}#{count}"
format *= repeat if repeat
- format
+ format.dup # because it may then become tainted
end
end
@@ -46,4 +46,15 @@ module StringSpecs
self.replace(str)
end
end
+
+ class SpecialVarProcessor
+ def process(match)
+ if $~ != nil
+ str = $~[0]
+ else
+ str = "unset"
+ end
+ "<#{str}>"
+ end
+ end
end
diff --git a/spec/ruby/core/string/fixtures/iso-8859-9-encoding.rb b/spec/ruby/core/string/fixtures/iso-8859-9-encoding.rb
index 61a691ff78..cfa91dedc3 100644
--- a/spec/ruby/core/string/fixtures/iso-8859-9-encoding.rb
+++ b/spec/ruby/core/string/fixtures/iso-8859-9-encoding.rb
@@ -4,6 +4,6 @@ module StringSpecs
def source_encoding; __ENCODING__; end
def x_escape; [0xDF].pack('C').force_encoding("iso-8859-9"); end
def ascii_only; "glark"; end
- def cedilla; "Åž"; end
+ def cedilla; "Þ"; end # S-cedilla
end
end
diff --git a/spec/ruby/core/string/fixtures/to_c.rb b/spec/ruby/core/string/fixtures/to_c.rb
new file mode 100644
index 0000000000..7776933263
--- /dev/null
+++ b/spec/ruby/core/string/fixtures/to_c.rb
@@ -0,0 +1,5 @@
+module StringSpecs
+ def self.to_c_method(string)
+ string.to_c
+ end
+end
diff --git a/spec/ruby/core/string/fixtures/utf-8-encoding.rb b/spec/ruby/core/string/fixtures/utf-8-encoding.rb
deleted file mode 100644
index fd243ec522..0000000000
--- a/spec/ruby/core/string/fixtures/utf-8-encoding.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-# -*- encoding: utf-8 -*-
-module StringSpecs
- class UTF8Encoding
- def self.source_encoding; __ENCODING__; end
- def self.egrave; "é"; end
- end
-end
diff --git a/spec/ruby/core/string/force_encoding_spec.rb b/spec/ruby/core/string/force_encoding_spec.rb
index d163c75ac3..fc6914213f 100644
--- a/spec/ruby/core/string/force_encoding_spec.rb
+++ b/spec/ruby/core/string/force_encoding_spec.rb
@@ -1,53 +1,72 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+# frozen_string_literal: false
+require_relative '../../spec_helper'
-with_feature :encoding do
- describe "String#force_encoding" do
- it "accepts a String as the name of an Encoding" do
- "abc".force_encoding('shift_jis').encoding.should == Encoding::Shift_JIS
+describe "String#force_encoding" do
+ it "accepts a String as the name of an Encoding" do
+ "abc".force_encoding('shift_jis').encoding.should == Encoding::Shift_JIS
+ end
+
+ describe "with a special encoding name" do
+ before :each do
+ @original_encoding = Encoding.default_internal
end
- it "accepts an Encoding instance" do
- "abc".force_encoding(Encoding::SHIFT_JIS).encoding.should == Encoding::Shift_JIS
+ after :each do
+ Encoding.default_internal = @original_encoding
end
- it "calls #to_str to convert an object to an encoding name" do
- obj = mock("force_encoding")
- obj.should_receive(:to_str).and_return("utf-8")
+ it "accepts valid special encoding names" do
+ Encoding.default_internal = "US-ASCII"
+ "abc".force_encoding("internal").encoding.should == Encoding::US_ASCII
+ end
- "abc".force_encoding(obj).encoding.should == Encoding::UTF_8
+ it "defaults to BINARY if special encoding name is not set" do
+ Encoding.default_internal = nil
+ "abc".force_encoding("internal").encoding.should == Encoding::BINARY
end
+ end
- it "raises a TypeError if #to_str does not return a String" do
- obj = mock("force_encoding")
- obj.should_receive(:to_str).and_return(1)
+ it "accepts an Encoding instance" do
+ "abc".force_encoding(Encoding::SHIFT_JIS).encoding.should == Encoding::Shift_JIS
+ end
- lambda { "abc".force_encoding(obj) }.should raise_error(TypeError)
- end
+ it "calls #to_str to convert an object to an encoding name" do
+ obj = mock("force_encoding")
+ obj.should_receive(:to_str).and_return("utf-8")
- it "raises a TypeError if passed nil" do
- lambda { "abc".force_encoding(nil) }.should raise_error(TypeError)
- end
+ "abc".force_encoding(obj).encoding.should == Encoding::UTF_8
+ end
- it "returns self" do
- str = "abc"
- str.force_encoding('utf-8').should equal(str)
- end
+ it "raises a TypeError if #to_str does not return a String" do
+ obj = mock("force_encoding")
+ obj.should_receive(:to_str).and_return(1)
- it "sets the encoding even if the String contents are invalid in that encoding" do
- str = "\u{9765}"
- str.force_encoding('euc-jp')
- str.encoding.should == Encoding::EUC_JP
- str.valid_encoding?.should be_false
- end
+ -> { "abc".force_encoding(obj) }.should.raise(TypeError)
+ end
- it "does not transcode self" do
- str = "\u{8612}"
- str.dup.force_encoding('utf-16le').should_not == str.encode('utf-16le')
- end
+ it "raises a TypeError if passed nil" do
+ -> { "abc".force_encoding(nil) }.should.raise(TypeError)
+ end
- it "raises a RuntimeError if self is frozen" do
- str = "abcd".freeze
- lambda { str.force_encoding(str.encoding) }.should raise_error(RuntimeError)
- end
+ it "returns self" do
+ str = "abc"
+ str.force_encoding('utf-8').should.equal?(str)
+ end
+
+ it "sets the encoding even if the String contents are invalid in that encoding" do
+ str = "\u{9765}"
+ str.force_encoding('euc-jp')
+ str.encoding.should == Encoding::EUC_JP
+ str.valid_encoding?.should == false
+ end
+
+ it "does not transcode self" do
+ str = "é"
+ str.dup.force_encoding('utf-16le').should_not == str.encode('utf-16le')
+ end
+
+ it "raises a FrozenError if self is frozen" do
+ str = "abcd".freeze
+ -> { str.force_encoding(str.encoding) }.should.raise(FrozenError)
end
end
diff --git a/spec/ruby/core/string/freeze_spec.rb b/spec/ruby/core/string/freeze_spec.rb
index bd7c2fbc73..8485e8de21 100644
--- a/spec/ruby/core/string/freeze_spec.rb
+++ b/spec/ruby/core/string/freeze_spec.rb
@@ -1,14 +1,14 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+# frozen_string_literal: false
+require_relative '../../spec_helper'
describe "String#freeze" do
it "produces the same object whenever called on an instance of a literal in the source" do
- ids = Array.new(2) { "abc".freeze.object_id }
- ids.first.should == ids.last
+ "abc".freeze.should.equal? "abc".freeze
end
it "doesn't produce the same object for different instances of literals in the source" do
- "abc".object_id.should_not == "abc".object_id
+ "abc".should_not.equal? "abc"
end
it "being a special form doesn't change the value of defined?" do
diff --git a/spec/ruby/core/string/getbyte_spec.rb b/spec/ruby/core/string/getbyte_spec.rb
index b46ab1ab64..d4619dca61 100644
--- a/spec/ruby/core/string/getbyte_spec.rb
+++ b/spec/ruby/core/string/getbyte_spec.rb
@@ -1,9 +1,9 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "String#getbyte" do
it "returns an Integer if given a valid index" do
- "a".getbyte(0).should be_kind_of(Integer)
+ "a".getbyte(0).should.is_a?(Integer)
end
it "starts indexing at 0" do
@@ -51,19 +51,19 @@ describe "String#getbyte" do
end
it "returns nil for out-of-bound indexes" do
- "g".getbyte(1).should be_nil
+ "g".getbyte(1).should == nil
end
it "regards the empty String as containing no bytes" do
- "".getbyte(0).should be_nil
+ "".getbyte(0).should == nil
end
it "raises an ArgumentError unless given one argument" do
- lambda { "glark".getbyte }.should raise_error(ArgumentError)
- lambda { "food".getbyte(0,0) }.should raise_error(ArgumentError)
+ -> { "glark".getbyte }.should.raise(ArgumentError)
+ -> { "food".getbyte(0,0) }.should.raise(ArgumentError)
end
it "raises a TypeError unless its argument can be coerced into an Integer" do
- lambda { "a".getbyte('a') }.should raise_error(TypeError)
+ -> { "a".getbyte('a') }.should.raise(TypeError)
end
end
diff --git a/spec/ruby/core/string/grapheme_clusters_spec.rb b/spec/ruby/core/string/grapheme_clusters_spec.rb
new file mode 100644
index 0000000000..380a245083
--- /dev/null
+++ b/spec/ruby/core/string/grapheme_clusters_spec.rb
@@ -0,0 +1,14 @@
+require_relative "../../spec_helper"
+require_relative 'shared/chars'
+require_relative 'shared/grapheme_clusters'
+
+describe "String#grapheme_clusters" do
+ it_behaves_like :string_chars, :grapheme_clusters
+ it_behaves_like :string_grapheme_clusters, :grapheme_clusters
+
+ it "returns an array when no block given" do
+ string = "ab\u{1f3f3}\u{fe0f}\u{200d}\u{1f308}\u{1F43E}"
+ string.grapheme_clusters.should == ['a', 'b', "\u{1f3f3}\u{fe0f}\u{200d}\u{1f308}", "\u{1F43E}"]
+
+ end
+end
diff --git a/spec/ruby/core/string/gsub_spec.rb b/spec/ruby/core/string/gsub_spec.rb
index 026b037b6c..d0e1c30bd2 100644
--- a/spec/ruby/core/string/gsub_spec.rb
+++ b/spec/ruby/core/string/gsub_spec.rb
@@ -1,6 +1,7 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes.rb', __FILE__)
+# frozen_string_literal: false
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe :string_gsub_named_capture, shared: true do
it "replaces \\k named backreferences with the regexp's corresponding capture" do
@@ -160,52 +161,12 @@ describe "String#gsub with pattern and replacement" do
it_behaves_like :string_gsub_named_capture, :gsub
- it "taints the result if the original string or replacement is tainted" do
- hello = "hello"
- hello_t = "hello"
- a = "a"
- a_t = "a"
- empty = ""
- empty_t = ""
-
- hello_t.taint; a_t.taint; empty_t.taint
-
- hello_t.gsub(/./, a).tainted?.should == true
- hello_t.gsub(/./, empty).tainted?.should == true
-
- hello.gsub(/./, a_t).tainted?.should == true
- hello.gsub(/./, empty_t).tainted?.should == true
- hello.gsub(//, empty_t).tainted?.should == true
-
- hello.gsub(//.taint, "foo").tainted?.should == false
- end
-
it "handles pattern collapse" do
str = "ã“ã«ã¡ã‚"
reg = %r!!
str.gsub(reg, ".").should == ".ã“.ã«.ã¡.ã‚."
end
- it "untrusts the result if the original string or replacement is untrusted" do
- hello = "hello"
- hello_t = "hello"
- a = "a"
- a_t = "a"
- empty = ""
- empty_t = ""
-
- hello_t.untrust; a_t.untrust; empty_t.untrust
-
- hello_t.gsub(/./, a).untrusted?.should == true
- hello_t.gsub(/./, empty).untrusted?.should == true
-
- hello.gsub(/./, a_t).untrusted?.should == true
- hello.gsub(/./, empty_t).untrusted?.should == true
- hello.gsub(//, empty_t).untrusted?.should == true
-
- hello.gsub(//.untrust, "foo").untrusted?.should == false
- end
-
it "tries to convert pattern to a string using to_str" do
pattern = mock('.')
def pattern.to_str() "." end
@@ -214,9 +175,9 @@ describe "String#gsub with pattern and replacement" do
end
it "raises a TypeError when pattern can't be converted to a string" do
- lambda { "hello".gsub([], "x") }.should raise_error(TypeError)
- lambda { "hello".gsub(Object.new, "x") }.should raise_error(TypeError)
- lambda { "hello".gsub(nil, "x") }.should raise_error(TypeError)
+ -> { "hello".gsub([], "x") }.should.raise(TypeError)
+ -> { "hello".gsub(Object.new, "x") }.should.raise(TypeError)
+ -> { "hello".gsub(nil, "x") }.should.raise(TypeError)
end
it "tries to convert replacement to a string using to_str" do
@@ -227,20 +188,18 @@ describe "String#gsub with pattern and replacement" do
end
it "raises a TypeError when replacement can't be converted to a string" do
- lambda { "hello".gsub(/[aeiou]/, []) }.should raise_error(TypeError)
- lambda { "hello".gsub(/[aeiou]/, Object.new) }.should raise_error(TypeError)
- lambda { "hello".gsub(/[aeiou]/, nil) }.should raise_error(TypeError)
+ -> { "hello".gsub(/[aeiou]/, []) }.should.raise(TypeError)
+ -> { "hello".gsub(/[aeiou]/, Object.new) }.should.raise(TypeError)
+ -> { "hello".gsub(/[aeiou]/, nil) }.should.raise(TypeError)
end
- it "returns subclass instances when called on a subclass" do
- StringSpecs::MyString.new("").gsub(//, "").should be_an_instance_of(StringSpecs::MyString)
- StringSpecs::MyString.new("").gsub(/foo/, "").should be_an_instance_of(StringSpecs::MyString)
- StringSpecs::MyString.new("foo").gsub(/foo/, "").should be_an_instance_of(StringSpecs::MyString)
- StringSpecs::MyString.new("foo").gsub("foo", "").should be_an_instance_of(StringSpecs::MyString)
+ it "returns String instances when called on a subclass" do
+ StringSpecs::MyString.new("").gsub(//, "").should.instance_of?(String)
+ StringSpecs::MyString.new("").gsub(/foo/, "").should.instance_of?(String)
+ StringSpecs::MyString.new("foo").gsub(/foo/, "").should.instance_of?(String)
+ StringSpecs::MyString.new("foo").gsub("foo", "").should.instance_of?(String)
end
- # Note: $~ cannot be tested because mspec messes with it
-
it "sets $~ to MatchData of last match and nil when there's none" do
'hello.'.gsub('hello', 'x')
$~[0].should == 'hello'
@@ -254,6 +213,18 @@ describe "String#gsub with pattern and replacement" do
'hello.'.gsub(/not/, 'x')
$~.should == nil
end
+
+ it "handles a pattern in a superset encoding" do
+ result = 'abc'.force_encoding(Encoding::US_ASCII).gsub('é', 'è')
+ result.should == 'abc'
+ result.encoding.should == Encoding::US_ASCII
+ end
+
+ it "handles a pattern in a subset encoding" do
+ result = 'été'.gsub('t'.force_encoding(Encoding::US_ASCII), 'u')
+ result.should == 'éué'
+ result.encoding.should == Encoding::UTF_8
+ end
end
describe "String#gsub with pattern and Hash" do
@@ -298,7 +269,7 @@ describe "String#gsub with pattern and Hash" do
it "uses the hash's value set from default_proc for missing keys" do
hsh = {}
- hsh.default_proc = lambda { |k,v| 'lamb' }
+ hsh.default_proc = -> k, v { 'lamb' }
"food!".gsub(/./, hsh).should == "lamblamblamblamblamb"
end
@@ -321,27 +292,6 @@ describe "String#gsub with pattern and Hash" do
repl = '\& \0 \1 \` \\\' \+ \\\\ foo'
"hello".gsub(/(.+)/, 'hello' => repl ).should == repl
end
-
- it "untrusts the result if the original string is untrusted" do
- str = "Ghana".untrust
- str.gsub(/[Aa]na/, 'ana' => '').untrusted?.should be_true
- end
-
- it "untrusts the result if a hash value is untrusted" do
- str = "Ghana"
- str.gsub(/a$/, 'a' => 'di'.untrust).untrusted?.should be_true
- end
-
- it "taints the result if the original string is tainted" do
- str = "Ghana".taint
- str.gsub(/[Aa]na/, 'ana' => '').tainted?.should be_true
- end
-
- it "taints the result if a hash value is tainted" do
- str = "Ghana"
- str.gsub(/a$/, 'a' => 'di'.taint).tainted?.should be_true
- end
-
end
describe "String#gsub! with pattern and Hash" do
@@ -387,7 +337,7 @@ describe "String#gsub! with pattern and Hash" do
it "uses the hash's value set from default_proc for missing keys" do
hsh = {}
- hsh.default_proc = lambda { |k,v| 'lamb' }
+ hsh.default_proc = -> k, v { 'lamb' }
"food!".gsub!(/./, hsh).should == "lamblamblamblamblamb"
end
@@ -410,27 +360,6 @@ describe "String#gsub! with pattern and Hash" do
repl = '\& \0 \1 \` \\\' \+ \\\\ foo'
"hello".gsub!(/(.+)/, 'hello' => repl ).should == repl
end
-
- it "keeps untrusted state" do
- str = "Ghana".untrust
- str.gsub!(/[Aa]na/, 'ana' => '').untrusted?.should be_true
- end
-
- it "untrusts self if a hash value is untrusted" do
- str = "Ghana"
- str.gsub!(/a$/, 'a' => 'di'.untrust).untrusted?.should be_true
- end
-
- it "keeps tainted state" do
- str = "Ghana".taint
- str.gsub!(/[Aa]na/, 'ana' => '').tainted?.should be_true
- end
-
- it "taints self if a hash value is tainted" do
- str = "Ghana"
- str.gsub!(/a$/, 'a' => 'di'.taint).tainted?.should be_true
- end
-
end
describe "String#gsub with pattern and block" do
@@ -458,6 +387,11 @@ describe "String#gsub with pattern and block" do
offsets.should == [[1, 2], [4, 5]]
end
+ it "does not set $~ for procs created from methods" do
+ str = "hello"
+ str.gsub("l", &StringSpecs::SpecialVarProcessor.new.method(:process)).should == "he<unset><unset>o"
+ end
+
it "restores $~ after leaving the block" do
[/./, "l"].each do |pattern|
old_md = nil
@@ -504,40 +438,20 @@ describe "String#gsub with pattern and block" do
"hello".gsub(/.+/) { obj }.should == "ok"
end
- it "untrusts the result if the original string or replacement is untrusted" do
- hello = "hello"
- hello_t = "hello"
- a = "a"
- a_t = "a"
- empty = ""
- empty_t = ""
-
- hello_t.untrust; a_t.untrust; empty_t.untrust
-
- hello_t.gsub(/./) { a }.untrusted?.should == true
- hello_t.gsub(/./) { empty }.untrusted?.should == true
-
- hello.gsub(/./) { a_t }.untrusted?.should == true
- hello.gsub(/./) { empty_t }.untrusted?.should == true
- hello.gsub(//) { empty_t }.untrusted?.should == true
-
- hello.gsub(//.untrust) { "foo" }.untrusted?.should == false
- end
-
it "uses the compatible encoding if they are compatible" do
s = "hello"
s2 = "#{195.chr}#{192.chr}#{195.chr}"
- s.gsub(/l/) { |bar| 195.chr }.encoding.should == Encoding::ASCII_8BIT
- s2.gsub("#{192.chr}") { |bar| "hello" }.encoding.should == Encoding::ASCII_8BIT
+ s.gsub(/l/) { |bar| 195.chr }.encoding.should == Encoding::BINARY
+ s2.gsub("#{192.chr}") { |bar| "hello" }.encoding.should == Encoding::BINARY
end
it "raises an Encoding::CompatibilityError if the encodings are not compatible" do
s = "hllëllo"
s2 = "hellö"
- lambda { s.gsub(/l/) { |bar| "РуÑÑкий".force_encoding("iso-8859-5") } }.should raise_error(Encoding::CompatibilityError)
- lambda { s2.gsub(/l/) { |bar| "РуÑÑкий".force_encoding("iso-8859-5") } }.should raise_error(Encoding::CompatibilityError)
+ -> { s.gsub(/l/) { |bar| "РуÑÑкий".force_encoding("iso-8859-5") } }.should.raise(Encoding::CompatibilityError)
+ -> { s2.gsub(/l/) { |bar| "РуÑÑкий".force_encoding("iso-8859-5") } }.should.raise(Encoding::CompatibilityError)
end
it "replaces the incompatible part properly even if the encodings are not compatible" do
@@ -549,7 +463,7 @@ describe "String#gsub with pattern and block" do
not_supported_on :opal do
it "raises an ArgumentError if encoding is not valid" do
x92 = [0x92].pack('C').force_encoding('utf-8')
- lambda { "a#{x92}b".gsub(/[^\x00-\x7f]/u, '') }.should raise_error(ArgumentError)
+ -> { "a#{x92}b".gsub(/[^\x00-\x7f]/u, '') }.should.raise(ArgumentError)
end
end
end
@@ -557,7 +471,7 @@ end
describe "String#gsub with pattern and without replacement and block" do
it "returns an enumerator" do
enum = "abca".gsub(/a/)
- enum.should be_an_instance_of(Enumerator)
+ enum.should.instance_of?(Enumerator)
enum.to_a.should == ["a", "a"]
end
@@ -570,31 +484,27 @@ describe "String#gsub with pattern and without replacement and block" do
end
end
+describe "String#gsub with a string pattern" do
+ it "handles multibyte characters" do
+ "é".gsub("é", "â").should == "â"
+ "aé".gsub("é", "â").should == "aâ"
+ "éa".gsub("é", "â").should == "âa"
+ end
+end
+
describe "String#gsub! with pattern and replacement" do
it "modifies self in place and returns self" do
a = "hello"
- a.gsub!(/[aeiou]/, '*').should equal(a)
+ a.gsub!(/[aeiou]/, '*').should.equal?(a)
a.should == "h*ll*"
end
it "modifies self in place with multi-byte characters and returns self" do
a = "¿por qué?"
- a.gsub!(/([a-z\d]*)/, "*").should equal(a)
+ a.gsub!(/([a-z\d]*)/, "*").should.equal?(a)
a.should == "*¿** **é*?*"
end
- it "taints self if replacement is tainted" do
- a = "hello"
- a.gsub!(/./.taint, "foo").tainted?.should == false
- a.gsub!(/./, "foo".taint).tainted?.should == true
- end
-
- it "untrusts self if replacement is untrusted" do
- a = "hello"
- a.gsub!(/./.untrust, "foo").untrusted?.should == false
- a.gsub!(/./, "foo".untrust).untrusted?.should == true
- end
-
it "returns nil if no modifications were made" do
a = "hello"
a.gsub!(/z/, '*').should == nil
@@ -603,33 +513,42 @@ describe "String#gsub! with pattern and replacement" do
end
# See [ruby-core:23666]
- it "raises a RuntimeError when self is frozen" do
+ it "raises a FrozenError when self is frozen" do
s = "hello"
s.freeze
- lambda { s.gsub!(/ROAR/, "x") }.should raise_error(RuntimeError)
- lambda { s.gsub!(/e/, "e") }.should raise_error(RuntimeError)
- lambda { s.gsub!(/[aeiou]/, '*') }.should raise_error(RuntimeError)
+ -> { s.gsub!(/ROAR/, "x") }.should.raise(FrozenError)
+ -> { s.gsub!(/e/, "e") }.should.raise(FrozenError)
+ -> { s.gsub!(/[aeiou]/, '*') }.should.raise(FrozenError)
end
-end
-describe "String#gsub! with pattern and block" do
- it "modifies self in place and returns self" do
- a = "hello"
- a.gsub!(/[aeiou]/) { '*' }.should equal(a)
- a.should == "h*ll*"
+ it "handles a pattern in a superset encoding" do
+ string = 'abc'.force_encoding(Encoding::US_ASCII)
+
+ result = string.gsub!('é', 'è')
+
+ result.should == nil
+ string.should == 'abc'
+ string.encoding.should == Encoding::US_ASCII
end
- it "taints self if block's result is tainted" do
- a = "hello"
- a.gsub!(/./.taint) { "foo" }.tainted?.should == false
- a.gsub!(/./) { "foo".taint }.tainted?.should == true
+ it "handles a pattern in a subset encoding" do
+ string = 'été'
+ pattern = 't'.force_encoding(Encoding::US_ASCII)
+
+ result = string.gsub!(pattern, 'u')
+
+ result.should == string
+ string.should == 'éué'
+ string.encoding.should == Encoding::UTF_8
end
+end
- it "untrusts self if block's result is untrusted" do
+describe "String#gsub! with pattern and block" do
+ it "modifies self in place and returns self" do
a = "hello"
- a.gsub!(/./.untrust) { "foo" }.untrusted?.should == false
- a.gsub!(/./) { "foo".untrust }.untrusted?.should == true
+ a.gsub!(/[aeiou]/) { '*' }.should.equal?(a)
+ a.should == "h*ll*"
end
it "returns nil if no modifications were made" do
@@ -640,29 +559,29 @@ describe "String#gsub! with pattern and block" do
end
# See [ruby-core:23663]
- it "raises a RuntimeError when self is frozen" do
+ it "raises a FrozenError when self is frozen" do
s = "hello"
s.freeze
- lambda { s.gsub!(/ROAR/) { "x" } }.should raise_error(RuntimeError)
- lambda { s.gsub!(/e/) { "e" } }.should raise_error(RuntimeError)
- lambda { s.gsub!(/[aeiou]/) { '*' } }.should raise_error(RuntimeError)
+ -> { s.gsub!(/ROAR/) { "x" } }.should.raise(FrozenError)
+ -> { s.gsub!(/e/) { "e" } }.should.raise(FrozenError)
+ -> { s.gsub!(/[aeiou]/) { '*' } }.should.raise(FrozenError)
end
it "uses the compatible encoding if they are compatible" do
s = "hello"
s2 = "#{195.chr}#{192.chr}#{195.chr}"
- s.gsub!(/l/) { |bar| 195.chr }.encoding.should == Encoding::ASCII_8BIT
- s2.gsub!("#{192.chr}") { |bar| "hello" }.encoding.should == Encoding::ASCII_8BIT
+ s.gsub!(/l/) { |bar| 195.chr }.encoding.should == Encoding::BINARY
+ s2.gsub!("#{192.chr}") { |bar| "hello" }.encoding.should == Encoding::BINARY
end
it "raises an Encoding::CompatibilityError if the encodings are not compatible" do
s = "hllëllo"
s2 = "hellö"
- lambda { s.gsub!(/l/) { |bar| "РуÑÑкий".force_encoding("iso-8859-5") } }.should raise_error(Encoding::CompatibilityError)
- lambda { s2.gsub!(/l/) { |bar| "РуÑÑкий".force_encoding("iso-8859-5") } }.should raise_error(Encoding::CompatibilityError)
+ -> { s.gsub!(/l/) { |bar| "РуÑÑкий".force_encoding("iso-8859-5") } }.should.raise(Encoding::CompatibilityError)
+ -> { s2.gsub!(/l/) { |bar| "РуÑÑкий".force_encoding("iso-8859-5") } }.should.raise(Encoding::CompatibilityError)
end
it "replaces the incompatible part properly even if the encodings are not compatible" do
@@ -674,7 +593,7 @@ describe "String#gsub! with pattern and block" do
not_supported_on :opal do
it "raises an ArgumentError if encoding is not valid" do
x92 = [0x92].pack('C').force_encoding('utf-8')
- lambda { "a#{x92}b".gsub!(/[^\x00-\x7f]/u, '') }.should raise_error(ArgumentError)
+ -> { "a#{x92}b".gsub!(/[^\x00-\x7f]/u, '') }.should.raise(ArgumentError)
end
end
end
@@ -682,7 +601,7 @@ end
describe "String#gsub! with pattern and without replacement and block" do
it "returns an enumerator" do
enum = "abca".gsub!(/a/)
- enum.should be_an_instance_of(Enumerator)
+ enum.should.instance_of?(Enumerator)
enum.to_a.should == ["a", "a"]
end
diff --git a/spec/ruby/core/string/hash_spec.rb b/spec/ruby/core/string/hash_spec.rb
index 255168cebd..0b26214b55 100644
--- a/spec/ruby/core/string/hash_spec.rb
+++ b/spec/ruby/core/string/hash_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes.rb', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "String#hash" do
it "returns a hash based on a string's length and content" do
diff --git a/spec/ruby/core/string/hex_spec.rb b/spec/ruby/core/string/hex_spec.rb
index 8a9257c310..364e915681 100644
--- a/spec/ruby/core/string/hex_spec.rb
+++ b/spec/ruby/core/string/hex_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes.rb', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
# TODO: Move actual results to String#to_int() and spec in terms of it
describe "String#hex" do
diff --git a/spec/ruby/core/string/include_spec.rb b/spec/ruby/core/string/include_spec.rb
index d7780de602..d943430335 100644
--- a/spec/ruby/core/string/include_spec.rb
+++ b/spec/ruby/core/string/include_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes.rb', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "String#include? with String" do
it "returns true if self contains other_str" do
@@ -13,6 +13,20 @@ describe "String#include? with String" do
StringSpecs::MyString.new("hello").include?(StringSpecs::MyString.new("lo")).should == true
end
+ it "returns true if both strings are empty" do
+ "".should.include?("")
+ "".dup.force_encoding("EUC-JP").should.include?("")
+ "".should.include?("".dup.force_encoding("EUC-JP"))
+ "".dup.force_encoding("EUC-JP").should.include?("".dup.force_encoding("EUC-JP"))
+ end
+
+ it "returns true if the RHS is empty" do
+ "a".should.include?("")
+ "a".dup.force_encoding("EUC-JP").should.include?("")
+ "a".should.include?("".dup.force_encoding("EUC-JP"))
+ "a".dup.force_encoding("EUC-JP").should.include?("".dup.force_encoding("EUC-JP"))
+ end
+
it "tries to convert other to string using to_str" do
other = mock('lo')
other.should_receive(:to_str).and_return("lo")
@@ -21,15 +35,15 @@ describe "String#include? with String" do
end
it "raises a TypeError if other can't be converted to string" do
- lambda { "hello".include?([]) }.should raise_error(TypeError)
- lambda { "hello".include?('h'.ord) }.should raise_error(TypeError)
- lambda { "hello".include?(mock('x')) }.should raise_error(TypeError)
+ -> { "hello".include?([]) }.should.raise(TypeError)
+ -> { "hello".include?('h'.ord) }.should.raise(TypeError)
+ -> { "hello".include?(mock('x')) }.should.raise(TypeError)
end
it "raises an Encoding::CompatibilityError if the encodings are incompatible" do
pat = "ã‚¢".encode Encoding::EUC_JP
- lambda do
+ -> do
"ã‚れ".include?(pat)
- end.should raise_error(Encoding::CompatibilityError)
+ end.should.raise(Encoding::CompatibilityError)
end
end
diff --git a/spec/ruby/core/string/index_spec.rb b/spec/ruby/core/string/index_spec.rb
index 37d11a0fd7..3f82181b98 100644
--- a/spec/ruby/core/string/index_spec.rb
+++ b/spec/ruby/core/string/index_spec.rb
@@ -1,18 +1,18 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes.rb', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "String#index" do
it "raises a TypeError if passed nil" do
- lambda { "abc".index nil }.should raise_error(TypeError)
+ -> { "abc".index nil }.should.raise(TypeError)
end
it "raises a TypeError if passed a boolean" do
- lambda { "abc".index true }.should raise_error(TypeError)
+ -> { "abc".index true }.should.raise(TypeError)
end
it "raises a TypeError if passed a Symbol" do
- lambda { "abc".index :a }.should raise_error(TypeError)
+ -> { "abc".index :a }.should.raise(TypeError)
end
it "calls #to_str to convert the first argument" do
@@ -27,8 +27,8 @@ describe "String#index" do
"abc".index("c", offset).should == 2
end
- it "raises a TypeError if passed a Fixnum" do
- lambda { "abc".index 97 }.should raise_error(TypeError)
+ it "raises a TypeError if passed an Integer" do
+ -> { "abc".index 97 }.should.raise(TypeError)
end
end
@@ -137,27 +137,42 @@ describe "String#index with String" do
"hello".index("he", 1).should == nil
"hello".index("he", 2).should == nil
+ "I’ve got a multibyte character.\n".index("\n\n").should == nil
end
- with_feature :encoding do
- it "returns the character index of a multibyte character" do
- "ã‚りãŒã¨ã†".index("ãŒ").should == 2
- end
+ it "returns the character index of a multibyte character" do
+ "ã‚りãŒã¨ã†".index("ãŒ").should == 2
+ end
- it "returns the character index after offset" do
- "ã‚れã‚れ".index("ã‚", 1).should == 2
- end
+ it "returns the character index after offset" do
+ "ã‚れã‚れ".index("ã‚", 1).should == 2
+ "ã‚りãŒã¨ã†ã‚りãŒã¨ã†".index("ãŒ", 3).should == 7
+ end
- it "returns the character index after a partial first match" do
- "</</h".index("</h").should == 2
- end
+ it "returns the character index after a partial first match" do
+ "</</h".index("</h").should == 2
+ end
- it "raises an Encoding::CompatibilityError if the encodings are incompatible" do
- char = "れ".encode Encoding::EUC_JP
- lambda do
- "ã‚れ".index char
- end.should raise_error(Encoding::CompatibilityError)
- end
+ it "raises an Encoding::CompatibilityError if the encodings are incompatible" do
+ char = "れ".encode Encoding::EUC_JP
+ -> do
+ "ã‚れ".index char
+ end.should.raise(Encoding::CompatibilityError)
+ end
+
+ it "handles a substring in a superset encoding" do
+ 'abc'.dup.force_encoding(Encoding::US_ASCII).index('é').should == nil
+ end
+
+ it "handles a substring in a subset encoding" do
+ 'été'.index('t'.dup.force_encoding(Encoding::US_ASCII)).should == 1
+ end
+
+ it "raises an Encoding::CompatibilityError if the encodings are incompatible" do
+ str = 'abc'.dup.force_encoding("ISO-2022-JP")
+ pattern = 'b'.dup.force_encoding("EUC-JP")
+
+ -> { str.index(pattern) }.should.raise(Encoding::CompatibilityError, "incompatible character encodings: ISO-2022-JP and EUC-JP")
end
end
@@ -216,6 +231,15 @@ describe "String#index with Regexp" do
$~.should == nil
end
+ it "always clear $~" do
+ "a".index(/a/)
+ $~.should_not == nil
+
+ string = "blablabla"
+ string.index(/bla/, string.length + 1)
+ $~.should == nil
+ end
+
it "starts the search at the given offset" do
"blablabla".index(/.{0}/, 5).should == 5
"blablabla".index(/.{1}/, 5).should == 5
@@ -263,7 +287,7 @@ describe "String#index with Regexp" do
end
it "returns nil if the Regexp matches the empty string and the offset is out of range" do
- "ruby".index(//,12).should be_nil
+ "ruby".index(//,12).should == nil
end
it "supports \\G which matches at the given start offset" do
@@ -292,24 +316,22 @@ describe "String#index with Regexp" do
"RWOARW".index(/R./, obj).should == 4
end
- with_feature :encoding do
- it "returns the character index of a multibyte character" do
- "ã‚りãŒã¨ã†".index(/ãŒ/).should == 2
- end
+ it "returns the character index of a multibyte character" do
+ "ã‚りãŒã¨ã†".index(/ãŒ/).should == 2
+ end
- it "returns the character index after offset" do
- "ã‚れã‚れ".index(/ã‚/, 1).should == 2
- end
+ it "returns the character index after offset" do
+ "ã‚れã‚れ".index(/ã‚/, 1).should == 2
+ end
- it "treats the offset as a character index" do
- "ã‚れã‚ã‚れ".index(/ã‚/, 3).should == 3
- end
+ it "treats the offset as a character index" do
+ "ã‚れã‚ã‚れ".index(/ã‚/, 3).should == 3
+ end
- it "raises an Encoding::CompatibilityError if the encodings are incompatible" do
- re = Regexp.new "れ".encode(Encoding::EUC_JP)
- lambda do
- "ã‚れ".index re
- end.should raise_error(Encoding::CompatibilityError)
- end
+ it "raises an Encoding::CompatibilityError if the encodings are incompatible" do
+ re = Regexp.new "れ".encode(Encoding::EUC_JP)
+ -> do
+ "ã‚れ".index re
+ end.should.raise(Encoding::CompatibilityError, "incompatible encoding regexp match (EUC-JP regexp with UTF-8 string)")
end
end
diff --git a/spec/ruby/core/string/initialize_spec.rb b/spec/ruby/core/string/initialize_spec.rb
index cbb281c8d5..b0c1e2e573 100644
--- a/spec/ruby/core/string/initialize_spec.rb
+++ b/spec/ruby/core/string/initialize_spec.rb
@@ -1,10 +1,10 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/replace', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/replace'
describe "String#initialize" do
it "is a private method" do
- String.should have_private_instance_method(:initialize)
+ String.private_instance_methods(false).should.include?(:initialize)
end
describe "with no arguments" do
@@ -16,7 +16,7 @@ describe "String#initialize" do
it "does not raise an exception when frozen" do
a = "hello".freeze
- a.send(:initialize).should equal(a)
+ a.send(:initialize).should.equal?(a)
end
end
diff --git a/spec/ruby/core/string/insert_spec.rb b/spec/ruby/core/string/insert_spec.rb
index c207fcc13b..c89793a8ca 100644
--- a/spec/ruby/core/string/insert_spec.rb
+++ b/spec/ruby/core/string/insert_spec.rb
@@ -1,7 +1,7 @@
# -*- encoding: utf-8 -*-
-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes.rb', __FILE__)
+# frozen_string_literal: false
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "String#insert with index, other" do
it "inserts other before the character at the given index" do
@@ -23,8 +23,8 @@ describe "String#insert with index, other" do
end
it "raises an IndexError if the index is beyond string" do
- lambda { "abcd".insert(5, 'X') }.should raise_error(IndexError)
- lambda { "abcd".insert(-6, 'X') }.should raise_error(IndexError)
+ -> { "abcd".insert(5, 'X') }.should.raise(IndexError)
+ -> { "abcd".insert(-6, 'X') }.should.raise(IndexError)
end
it "converts index to an integer using to_int" do
@@ -41,44 +41,41 @@ describe "String#insert with index, other" do
"abcd".insert(-3, other).should == "abXYZcd"
end
- it "taints self if string to insert is tainted" do
- str = "abcd"
- str.insert(0, "T".taint).tainted?.should == true
-
- str = "abcd"
- other = mock('T')
- def other.to_str() "T".taint end
- str.insert(0, other).tainted?.should == true
- end
-
it "raises a TypeError if other can't be converted to string" do
- lambda { "abcd".insert(-6, Object.new)}.should raise_error(TypeError)
- lambda { "abcd".insert(-6, []) }.should raise_error(TypeError)
- lambda { "abcd".insert(-6, mock('x')) }.should raise_error(TypeError)
+ -> { "abcd".insert(-6, Object.new)}.should.raise(TypeError)
+ -> { "abcd".insert(-6, []) }.should.raise(TypeError)
+ -> { "abcd".insert(-6, mock('x')) }.should.raise(TypeError)
end
- it "raises a RuntimeError if self is frozen" do
+ it "raises a FrozenError if self is frozen" do
str = "abcd".freeze
- lambda { str.insert(4, '') }.should raise_error(RuntimeError)
- lambda { str.insert(4, 'X') }.should raise_error(RuntimeError)
+ -> { str.insert(4, '') }.should.raise(FrozenError)
+ -> { str.insert(4, 'X') }.should.raise(FrozenError)
end
- with_feature :encoding do
- it "inserts a character into a multibyte encoded string" do
- "ã‚りãŒã¨ã†".insert(1, 'ü').should == "ã‚üりãŒã¨ã†"
- end
+ it "inserts a character into a multibyte encoded string" do
+ "ã‚りãŒã¨ã†".insert(1, 'ü').should == "ã‚üりãŒã¨ã†"
+ end
- it "returns a String in the compatible encoding" do
- str = "".force_encoding(Encoding::US_ASCII)
- str.insert(0, "ã‚りãŒã¨ã†")
- str.encoding.should == Encoding::UTF_8
- end
+ it "returns a String in the compatible encoding" do
+ str = "".force_encoding(Encoding::US_ASCII)
+ str.insert(0, "ã‚りãŒã¨ã†")
+ str.encoding.should == Encoding::UTF_8
+ end
+
+ it "raises an Encoding::CompatibilityError if the encodings are incompatible" do
+ pat = "ã‚¢".encode Encoding::EUC_JP
+ -> do
+ "ã‚れ".insert 0, pat
+ end.should.raise(Encoding::CompatibilityError)
+ end
- it "raises an Encoding::CompatibilityError if the encodings are incompatible" do
- pat = "ã‚¢".encode Encoding::EUC_JP
- lambda do
- "ã‚れ".insert 0, pat
- end.should raise_error(Encoding::CompatibilityError)
+ it "should not call subclassed string methods" do
+ cls = Class.new(String) do
+ def replace(arg)
+ raise "should not call replace"
+ end
end
+ cls.new("abcd").insert(0, 'X').should == "Xabcd"
end
end
diff --git a/spec/ruby/core/string/inspect_spec.rb b/spec/ruby/core/string/inspect_spec.rb
index a3e18c0ee3..8b91ce2f84 100644
--- a/spec/ruby/core/string/inspect_spec.rb
+++ b/spec/ruby/core/string/inspect_spec.rb
@@ -1,20 +1,10 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes.rb', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "String#inspect" do
- it "taints the result if self is tainted" do
- "foo".taint.inspect.tainted?.should == true
- "foo\n".taint.inspect.tainted?.should == true
- end
-
- it "untrusts the result if self is untrusted" do
- "foo".untrust.inspect.untrusted?.should == true
- "foo\n".untrust.inspect.untrusted?.should == true
- end
-
it "does not return a subclass instance" do
- StringSpecs::MyString.new.inspect.should be_an_instance_of(String)
+ StringSpecs::MyString.new.inspect.should.instance_of?(String)
end
it "returns a string with special characters replaced with \\<char> notation" do
@@ -29,6 +19,21 @@ describe "String#inspect" do
].should be_computed_by(:inspect)
end
+ it "returns a string with special characters replaced with \\<char> notation for UTF-16" do
+ pairs = [
+ ["\a", '"\\a"'],
+ ["\b", '"\\b"'],
+ ["\t", '"\\t"'],
+ ["\n", '"\\n"'],
+ ["\v", '"\\v"'],
+ ["\f", '"\\f"'],
+ ["\r", '"\\r"'],
+ ["\e", '"\\e"']
+ ].map { |str, result| [str.encode('UTF-16LE'), result] }
+
+ pairs.should be_computed_by(:inspect)
+ end
+
it "returns a string with \" and \\ escaped with a backslash" do
[ ["\"", '"\\""'],
["\\", '"\\\\"']
@@ -317,6 +322,15 @@ describe "String#inspect" do
0.chr.inspect.should == '"\\x00"'
end
+ it "uses \\x notation for broken UTF-8 sequences" do
+ "\xF0\x9F".inspect.should == '"\\xF0\\x9F"'
+ end
+
+ it "works for broken US-ASCII strings" do
+ s = "©".dup.force_encoding("US-ASCII")
+ s.inspect.should == '"\xC2\xA9"'
+ end
+
describe "when default external is UTF-8" do
before :each do
@extenc, Encoding.default_external = Encoding.default_external, Encoding::UTF_8
@@ -489,4 +503,18 @@ describe "String#inspect" do
].should be_computed_by(:inspect)
end
end
+
+ describe "when the string's encoding is different than the result's encoding" do
+ describe "and the string's encoding is ASCII-compatible but the characters are non-ASCII" do
+ it "returns a string with the non-ASCII characters replaced by \\x notation" do
+ "\u{3042}".encode("EUC-JP").inspect.should == '"\\x{A4A2}"'
+ end
+ end
+
+ describe "and the string has both ASCII-compatible and ASCII-incompatible chars" do
+ it "returns a string with the non-ASCII characters replaced by \\u notation" do
+ "hello привет".encode("utf-16le").inspect.should == '"hello \\u043F\\u0440\\u0438\\u0432\\u0435\\u0442"'
+ end
+ end
+ end
end
diff --git a/spec/ruby/core/string/intern_spec.rb b/spec/ruby/core/string/intern_spec.rb
index 71f3633920..af85e56dba 100644
--- a/spec/ruby/core/string/intern_spec.rb
+++ b/spec/ruby/core/string/intern_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes.rb', __FILE__)
-require File.expand_path('../shared/to_sym.rb', __FILE__)
+require_relative '../../spec_helper'
describe "String#intern" do
- it_behaves_like(:string_to_sym, :intern)
+ it "is an alias of String#to_sym" do
+ String.instance_method(:intern).should == String.instance_method(:to_sym)
+ end
end
diff --git a/spec/ruby/core/string/length_spec.rb b/spec/ruby/core/string/length_spec.rb
index 5f51f6bc01..a723babdbc 100644
--- a/spec/ruby/core/string/length_spec.rb
+++ b/spec/ruby/core/string/length_spec.rb
@@ -1,7 +1,56 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes.rb', __FILE__)
-require File.expand_path('../shared/length', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "String#length" do
- it_behaves_like(:string_length, :length)
+ it "returns the length of self" do
+ "".length.should == 0
+ "\x00".length.should == 1
+ "one".length.should == 3
+ "two".length.should == 3
+ "three".length.should == 5
+ "four".length.should == 4
+ end
+
+ it "returns the length of a string in different encodings" do
+ utf8_str = 'ã“ã«ã¡ã‚' * 100
+ utf8_str.length.should == 400
+ utf8_str.encode(Encoding::UTF_32BE).length.should == 400
+ utf8_str.encode(Encoding::SHIFT_JIS).length.should == 400
+ end
+
+ it "returns the length of the new self after encoding is changed" do
+ str = +'ã“ã«ã¡ã‚'
+ str.length
+
+ str.force_encoding('BINARY').length.should == 12
+ end
+
+ it "returns the correct length after force_encoding(BINARY)" do
+ utf8 = "ã‚"
+ ascii = "a"
+ concat = utf8 + ascii
+
+ concat.encoding.should == Encoding::UTF_8
+ concat.bytesize.should == 4
+
+ concat.length.should == 2
+ concat.force_encoding(Encoding::ASCII_8BIT)
+ concat.length.should == 4
+ end
+
+ it "adds 1 for every invalid byte in UTF-8" do
+ "\xF4\x90\x80\x80".length.should == 4
+ "a\xF4\x90\x80\x80b".length.should == 6
+ "é\xF4\x90\x80\x80è".length.should == 6
+ end
+
+ it "adds 1 (and not 2) for a incomplete surrogate in UTF-16" do
+ "\x00\xd8".dup.force_encoding("UTF-16LE").length.should == 1
+ "\xd8\x00".dup.force_encoding("UTF-16BE").length.should == 1
+ end
+
+ it "adds 1 for a broken sequence in UTF-32" do
+ "\x04\x03\x02\x01".dup.force_encoding("UTF-32LE").length.should == 1
+ "\x01\x02\x03\x04".dup.force_encoding("UTF-32BE").length.should == 1
+ end
end
diff --git a/spec/ruby/core/string/lines_spec.rb b/spec/ruby/core/string/lines_spec.rb
index e5f24816af..40ab5f71d8 100644
--- a/spec/ruby/core/string/lines_spec.rb
+++ b/spec/ruby/core/string/lines_spec.rb
@@ -1,22 +1,19 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/each_line', __FILE__)
-require File.expand_path('../shared/each_line_without_block', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/each_line'
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, ' ')
+ ary = "hello world".lines(' ')
ary.should == ["hello ", "world"]
end
- ruby_version_is '2.4' do
- context "when `chomp` keyword argument is passed" do
- it "removes new line characters" do
- "hello \nworld\n".lines(chomp: true).should == ["hello ", "world"]
- "hello \r\nworld\r\n".lines(chomp: true).should == ["hello ", "world"]
- end
+ context "when `chomp` keyword argument is passed" do
+ it "removes new line characters" do
+ "hello \nworld\n".lines(chomp: true).should == ["hello ", "world"]
+ "hello \r\nworld\r\n".lines(chomp: true).should == ["hello ", "world"]
end
end
end
diff --git a/spec/ruby/core/string/ljust_spec.rb b/spec/ruby/core/string/ljust_spec.rb
index f66fb0c573..0b2aab2638 100644
--- a/spec/ruby/core/string/ljust_spec.rb
+++ b/spec/ruby/core/string/ljust_spec.rb
@@ -1,6 +1,6 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes.rb', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "String#ljust with length, padding" do
it "returns a new string of specified length with self left justified and padded with padstr" do
@@ -31,14 +31,6 @@ describe "String#ljust with length, padding" do
"radiology".ljust(8, '-').should == "radiology"
end
- it "taints result when self or padstr is tainted" do
- "x".taint.ljust(4).tainted?.should == true
- "x".taint.ljust(0).tainted?.should == true
- "".taint.ljust(0).tainted?.should == true
- "x".taint.ljust(4, "*").tainted?.should == true
- "x".ljust(4, "*".taint).tainted?.should == true
- end
-
it "tries to convert length to an integer using to_int" do
"^".ljust(3.8, "_^").should == "^_^"
@@ -49,10 +41,10 @@ describe "String#ljust with length, padding" do
end
it "raises a TypeError when length can't be converted to an integer" do
- lambda { "hello".ljust("x") }.should raise_error(TypeError)
- lambda { "hello".ljust("x", "y") }.should raise_error(TypeError)
- lambda { "hello".ljust([]) }.should raise_error(TypeError)
- lambda { "hello".ljust(mock('x')) }.should raise_error(TypeError)
+ -> { "hello".ljust("x") }.should.raise(TypeError)
+ -> { "hello".ljust("x", "y") }.should.raise(TypeError)
+ -> { "hello".ljust([]) }.should.raise(TypeError)
+ -> { "hello".ljust(mock('x')) }.should.raise(TypeError)
end
it "tries to convert padstr to a string using to_str" do
@@ -63,54 +55,46 @@ describe "String#ljust with length, padding" do
end
it "raises a TypeError when padstr can't be converted" do
- lambda { "hello".ljust(20, []) }.should raise_error(TypeError)
- lambda { "hello".ljust(20, Object.new)}.should raise_error(TypeError)
- lambda { "hello".ljust(20, mock('x')) }.should raise_error(TypeError)
+ -> { "hello".ljust(20, []) }.should.raise(TypeError)
+ -> { "hello".ljust(20, Object.new)}.should.raise(TypeError)
+ -> { "hello".ljust(20, mock('x')) }.should.raise(TypeError)
end
it "raises an ArgumentError when padstr is empty" do
- lambda { "hello".ljust(10, '') }.should raise_error(ArgumentError)
+ -> { "hello".ljust(10, '') }.should.raise(ArgumentError)
end
- it "returns subclass instances when called on subclasses" do
- StringSpecs::MyString.new("").ljust(10).should be_an_instance_of(StringSpecs::MyString)
- StringSpecs::MyString.new("foo").ljust(10).should be_an_instance_of(StringSpecs::MyString)
- StringSpecs::MyString.new("foo").ljust(10, StringSpecs::MyString.new("x")).should be_an_instance_of(StringSpecs::MyString)
+ it "returns String instances when called on subclasses" do
+ StringSpecs::MyString.new("").ljust(10).should.instance_of?(String)
+ StringSpecs::MyString.new("foo").ljust(10).should.instance_of?(String)
+ StringSpecs::MyString.new("foo").ljust(10, StringSpecs::MyString.new("x")).should.instance_of?(String)
- "".ljust(10, StringSpecs::MyString.new("x")).should be_an_instance_of(String)
- "foo".ljust(10, StringSpecs::MyString.new("x")).should be_an_instance_of(String)
+ "".ljust(10, StringSpecs::MyString.new("x")).should.instance_of?(String)
+ "foo".ljust(10, StringSpecs::MyString.new("x")).should.instance_of?(String)
end
- it "when padding is tainted and self is untainted returns a tainted string if and only if length is longer than self" do
- "hello".ljust(4, 'X'.taint).tainted?.should be_false
- "hello".ljust(5, 'X'.taint).tainted?.should be_false
- "hello".ljust(6, 'X'.taint).tainted?.should be_true
+ describe "with width" do
+ it "returns a String in the same encoding as the original" do
+ str = "abc".dup.force_encoding Encoding::IBM437
+ result = str.ljust 5
+ result.should == "abc "
+ result.encoding.should.equal?(Encoding::IBM437)
+ end
end
- with_feature :encoding do
- describe "with width" do
- it "returns a String in the same encoding as the original" do
- str = "abc".force_encoding Encoding::IBM437
- result = str.ljust 5
- result.should == "abc "
- result.encoding.should equal(Encoding::IBM437)
- end
+ describe "with width, pattern" do
+ it "returns a String in the compatible encoding" do
+ str = "abc".dup.force_encoding Encoding::IBM437
+ result = str.ljust 5, "ã‚"
+ result.should == "abcã‚ã‚"
+ result.encoding.should.equal?(Encoding::UTF_8)
end
- describe "with width, pattern" do
- it "returns a String in the compatible encoding" do
- str = "abc".force_encoding Encoding::IBM437
- result = str.ljust 5, "ã‚"
- result.should == "abcã‚ã‚"
- result.encoding.should equal(Encoding::UTF_8)
- end
-
- it "raises an Encoding::CompatibilityError if the encodings are incompatible" do
- pat = "ã‚¢".encode Encoding::EUC_JP
- lambda do
- "ã‚れ".ljust 5, pat
- end.should raise_error(Encoding::CompatibilityError)
- end
+ it "raises an Encoding::CompatibilityError if the encodings are incompatible" do
+ pat = "ã‚¢".encode Encoding::EUC_JP
+ -> do
+ "ã‚れ".ljust 5, pat
+ end.should.raise(Encoding::CompatibilityError)
end
end
end
diff --git a/spec/ruby/core/string/lstrip_spec.rb b/spec/ruby/core/string/lstrip_spec.rb
index 7ef94be567..5896f8d7da 100644
--- a/spec/ruby/core/string/lstrip_spec.rb
+++ b/spec/ruby/core/string/lstrip_spec.rb
@@ -1,35 +1,37 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes.rb', __FILE__)
+# frozen_string_literal: false
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/strip'
describe "String#lstrip" do
+ it_behaves_like :string_strip, :lstrip
+
it "returns a copy of self with leading whitespace removed" do
- " hello ".lstrip.should == "hello "
- " hello world ".lstrip.should == "hello world "
- "\n\r\t\n\v\r hello world ".lstrip.should == "hello world "
- "hello".lstrip.should == "hello"
- "\000 \000hello\000 \000".lstrip.should == "\000 \000hello\000 \000"
+ " hello ".lstrip.should == "hello "
+ " hello world ".lstrip.should == "hello world "
+ "\n\r\t\n\v\r hello world ".lstrip.should == "hello world "
+ "hello".lstrip.should == "hello"
+ " ã“ã«ã¡ã‚".lstrip.should == "ã“ã«ã¡ã‚"
end
- it "does not strip leading \\0" do
- "\x00hello".lstrip.should == "\x00hello"
+ it "works with lazy substrings" do
+ " hello "[1...-1].lstrip.should == "hello "
+ " hello world "[1...-1].lstrip.should == "hello world "
+ "\n\r\t\n\v\r hello world "[1...-1].lstrip.should == "hello world "
+ " ã“ã«ã¡ã‚ "[1...-1].lstrip.should == "ã“ã«ã¡ã‚"
end
- it "taints the result when self is tainted" do
- "".taint.lstrip.tainted?.should == true
- "ok".taint.lstrip.tainted?.should == true
- " ok".taint.lstrip.tainted?.should == true
+ it "strips leading \\0" do
+ "\x00hello".lstrip.should == "hello"
+ "\000 \000hello\000 \000".lstrip.should == "hello\000 \000"
end
end
describe "String#lstrip!" do
it "modifies self in place and returns self" do
a = " hello "
- a.lstrip!.should equal(a)
+ a.lstrip!.should.equal?(a)
a.should == "hello "
-
- a = "\000 \000hello\000 \000"
- a.lstrip!
- a.should == "\000 \000hello\000 \000"
end
it "returns nil if no modifications were made" do
@@ -38,13 +40,35 @@ describe "String#lstrip!" do
a.should == "hello"
end
- it "raises a RuntimeError on a frozen instance that is modified" do
- lambda { " hello ".freeze.lstrip! }.should raise_error(RuntimeError)
+ it "makes a string empty if it is only whitespace" do
+ "".lstrip!.should == nil
+ " ".lstrip.should == ""
+ " ".lstrip.should == ""
+ end
+
+ it "removes leading NULL bytes and whitespace" do
+ a = "\000 \000hello\000 \000"
+ a.lstrip!
+ a.should == "hello\000 \000"
+ end
+
+ it "raises a FrozenError on a frozen instance that is modified" do
+ -> { " hello ".freeze.lstrip! }.should.raise(FrozenError)
end
# see [ruby-core:23657]
- it "raises a RuntimeError on a frozen instance that would not be modified" do
- lambda { "hello".freeze.lstrip! }.should raise_error(RuntimeError)
- lambda { "".freeze.lstrip! }.should raise_error(RuntimeError)
+ it "raises a FrozenError on a frozen instance that would not be modified" do
+ -> { "hello".freeze.lstrip! }.should.raise(FrozenError)
+ -> { "".freeze.lstrip! }.should.raise(FrozenError)
+ end
+
+ it "raises an ArgumentError if the first non-space codepoint is invalid" do
+ s = "\xDFabc".force_encoding(Encoding::UTF_8)
+ s.valid_encoding?.should == false
+ -> { s.lstrip! }.should.raise(ArgumentError)
+
+ s = " \xDFabc".force_encoding(Encoding::UTF_8)
+ s.valid_encoding?.should == false
+ -> { s.lstrip! }.should.raise(ArgumentError)
end
end
diff --git a/spec/ruby/core/string/match_spec.rb b/spec/ruby/core/string/match_spec.rb
index 94e28e7297..3ea8d90aa8 100644
--- a/spec/ruby/core/string/match_spec.rb
+++ b/spec/ruby/core/string/match_spec.rb
@@ -1,6 +1,6 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes.rb', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe :string_match_escaped_literal, shared: true do
not_supported_on :opal do
@@ -19,8 +19,8 @@ describe "String#=~" do
end
it "raises a TypeError if a obj is a string" do
- lambda { "some string" =~ "another string" }.should raise_error(TypeError)
- lambda { "a" =~ StringSpecs::MyString.new("b") }.should raise_error(TypeError)
+ -> { "some string" =~ "another string" }.should.raise(TypeError)
+ -> { "a" =~ StringSpecs::MyString.new("b") }.should.raise(TypeError)
end
it "invokes obj.=~ with self if obj is neither a string nor regexp" do
@@ -43,10 +43,8 @@ describe "String#=~" do
$~.should == nil
end
- with_feature :encoding do
- it "returns the character index of a found match" do
- ("ã“ã«ã¡ã‚" =~ /ã«/).should == 1
- end
+ it "returns the character index of a found match" do
+ ("ã“ã«ã¡ã‚" =~ /ã«/).should == 1
end
end
@@ -64,10 +62,8 @@ describe "String#match" do
"01234".match(/(.).(.)/, 1).captures.should == ["1", "3"]
end
- with_feature :encoding do
- it "uses the start as a character offset" do
- "零一二三四".match(/(.).(.)/, 1).captures.should == ["一", "三"]
- end
+ it "uses the start as a character offset" do
+ "零一二三四".match(/(.).(.)/, 1).captures.should == ["一", "三"]
end
end
@@ -76,10 +72,8 @@ describe "String#match" do
"01234".match(/(.).(.)/, -4).captures.should == ["1", "3"]
end
- with_feature :encoding do
- it "uses the start as a character offset" do
- "零一二三四".match(/(.).(.)/, -4).captures.should == ["一", "三"]
- end
+ it "uses the start as a character offset" do
+ "零一二三四".match(/(.).(.)/, -4).captures.should == ["一", "三"]
end
end
end
@@ -87,7 +81,7 @@ describe "String#match" do
describe "when passed a block" do
it "yields the MatchData" do
"abc".match(/./) {|m| ScratchPad.record m }
- ScratchPad.recorded.should be_kind_of(MatchData)
+ ScratchPad.recorded.should.is_a?(MatchData)
end
it "returns the block result" do
@@ -113,9 +107,9 @@ describe "String#match" do
end
it "raises a TypeError if pattern is not a regexp or a string" do
- lambda { 'hello'.match(10) }.should raise_error(TypeError)
+ -> { 'hello'.match(10) }.should.raise(TypeError)
not_supported_on :opal do
- lambda { 'hello'.match(:ell) }.should raise_error(TypeError)
+ -> { 'hello'.match(:ell) }.should.raise(TypeError)
end
end
@@ -143,33 +137,39 @@ describe "String#match" do
end
it "calls match on the regular expression" do
- regexp = /./
- regexp.should_receive(:match).and_return(:foo)
- 'hello'.match(regexp).should == :foo
+ # Can't use regexp.should_receive(:match).and_return(:foo) since regexps are frozen
+ ScratchPad.clear
+ regexp = Class.new(Regexp) {
+ def match(*args)
+ ScratchPad.record [:match, *args]
+ super(*args)
+ end
+ }.new('.')
+
+ 'hello'.match(regexp)
+ ScratchPad.recorded.should == [:match, 'hello']
end
end
-ruby_version_is "2.4" do
- describe "String#match?" do
- before :each do
- # Resetting Regexp.last_match
- /DONTMATCH/.match ''
- end
+describe "String#match?" do
+ before :each do
+ # Resetting Regexp.last_match
+ /DONTMATCH/.match ''
+ end
- context "when matches the given regex" do
- it "returns true but does not set Regexp.last_match" do
- 'string'.match?(/string/i).should be_true
- Regexp.last_match.should be_nil
- end
+ context "when matches the given regex" do
+ it "returns true but does not set Regexp.last_match" do
+ 'string'.match?(/string/i).should == true
+ Regexp.last_match.should == nil
end
+ end
- it "returns false when does not match the given regex" do
- 'string'.match?(/STRING/).should be_false
- end
+ it "returns false when does not match the given regex" do
+ 'string'.match?(/STRING/).should == false
+ end
- it "takes matching position as the 2nd argument" do
- 'string'.match?(/str/i, 0).should be_true
- 'string'.match?(/str/i, 1).should be_false
- end
+ it "takes matching position as the 2nd argument" do
+ 'string'.match?(/str/i, 0).should == true
+ 'string'.match?(/str/i, 1).should == false
end
end
diff --git a/spec/ruby/core/string/modulo_spec.rb b/spec/ruby/core/string/modulo_spec.rb
index 4f26ac5033..f93ec4bcf8 100644
--- a/spec/ruby/core/string/modulo_spec.rb
+++ b/spec/ruby/core/string/modulo_spec.rb
@@ -1,7 +1,26 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes.rb', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../kernel/shared/sprintf'
+require_relative '../kernel/shared/sprintf_encoding'
+require_relative 'fixtures/classes'
+require_relative '../../shared/hash/key_error'
describe "String#%" do
+ it_behaves_like :kernel_sprintf, -> format, *args {
+ format % args
+ }
+
+ it_behaves_like :kernel_sprintf_encoding, -> format, *args {
+ format % args
+ }
+end
+
+# TODO: these specs are mostly redundant with kernel/shared/sprintf.rb specs.
+# These specs should be moved there and deduplicated.
+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
@@ -14,47 +33,70 @@ describe "String#%" do
("%d%% %s" % [10, "of chickens!"]).should == "10% of chickens!"
end
- ruby_version_is ""..."2.5" do
- it "formats single % character at the end as literal %" do
- ("%" % []).should == "%"
- ("foo%" % []).should == "foo%"
+ describe "output's encoding" do
+ it "is the same as the format string if passed value is encoding-compatible" do
+ [Encoding::BINARY, Encoding::US_ASCII, Encoding::UTF_8, Encoding::SHIFT_JIS].each do |encoding|
+ ("hello %s!".encode(encoding) % "world").encoding.should == encoding
+ end
end
- end
- ruby_version_is "2.5" do
- it "raises an error if single % appears at the end" do
- lambda { ("%" % []) }.should raise_error(ArgumentError)
- lambda { ("foo%" % [])}.should raise_error(ArgumentError)
+ it "negotiates a compatible encoding if necessary" do
+ ("hello %s" % 195.chr).encoding.should == Encoding::BINARY
+ ("hello %s".encode("shift_jis") % "wörld").encoding.should == Encoding::UTF_8
end
- end
- it "formats single % character before a newline as literal %" do
- ("%\n" % []).should == "%\n"
- ("foo%\n" % []).should == "foo%\n"
- ("%\n.3f" % 1.2).should == "%\n.3f"
+ it "raises if a compatible encoding can't be found" do
+ -> { "hello %s".encode("utf-8") % "world".encode("UTF-16LE") }.should.raise(Encoding::CompatibilityError)
+ end
end
- it "formats single % character before a NUL as literal %" do
- ("%\0" % []).should == "%\0"
- ("foo%\0" % []).should == "foo%\0"
- ("%\0.3f" % 1.2).should == "%\0.3f"
+ it "raises an error if single % appears at the end" do
+ -> { ("%" % []) }.should.raise(ArgumentError)
+ -> { ("foo%" % [])}.should.raise(ArgumentError)
end
- it "raises an error if single % appears anywhere else" do
- lambda { (" % " % []) }.should raise_error(ArgumentError)
- lambda { ("foo%quux" % []) }.should raise_error(ArgumentError)
- end
+ ruby_version_is ""..."3.4" do
+ it "formats single % character before a newline as literal %" do
+ ("%\n" % []).should == "%\n"
+ ("foo%\n" % []).should == "foo%\n"
+ ("%\n.3f" % 1.2).should == "%\n.3f"
+ end
- it "raises an error if NULL or \\n appear anywhere else in the format string" do
- begin
- old_debug, $DEBUG = $DEBUG, false
+ it "formats single % character before a NUL as literal %" do
+ ("%\0" % []).should == "%\0"
+ ("foo%\0" % []).should == "foo%\0"
+ ("%\0.3f" % 1.2).should == "%\0.3f"
+ end
- lambda { "%.\n3f" % 1.2 }.should raise_error(ArgumentError)
- lambda { "%.3\nf" % 1.2 }.should raise_error(ArgumentError)
- lambda { "%.\03f" % 1.2 }.should raise_error(ArgumentError)
- lambda { "%.3\0f" % 1.2 }.should raise_error(ArgumentError)
- ensure
- $DEBUG = old_debug
+ it "raises an error if single % appears anywhere else" do
+ -> { (" % " % []) }.should.raise(ArgumentError)
+ -> { ("foo%quux" % []) }.should.raise(ArgumentError)
+ end
+
+ it "raises an error if NULL or \\n appear anywhere else in the format string" do
+ begin
+ old_debug, $DEBUG = $DEBUG, false
+
+ -> { "%.\n3f" % 1.2 }.should.raise(ArgumentError)
+ -> { "%.3\nf" % 1.2 }.should.raise(ArgumentError)
+ -> { "%.\03f" % 1.2 }.should.raise(ArgumentError)
+ -> { "%.3\0f" % 1.2 }.should.raise(ArgumentError)
+ ensure
+ $DEBUG = old_debug
+ end
+ end
+ end
+
+ ruby_version_is "3.4" do
+ it "raises an ArgumentError if % is not followed by a conversion specifier" do
+ -> { "%" % [] }.should.raise(ArgumentError)
+ -> { "%\n" % [] }.should.raise(ArgumentError)
+ -> { "%\0" % [] }.should.raise(ArgumentError)
+ -> { " % " % [] }.should.raise(ArgumentError)
+ -> { "%.\n3f" % 1.2 }.should.raise(ArgumentError)
+ -> { "%.3\nf" % 1.2 }.should.raise(ArgumentError)
+ -> { "%.\03f" % 1.2 }.should.raise(ArgumentError)
+ -> { "%.3\0f" % 1.2 }.should.raise(ArgumentError)
end
end
@@ -77,8 +119,8 @@ describe "String#%" do
s = $stderr
$stderr = IOStub.new
- lambda { "" % [1, 2, 3] }.should raise_error(ArgumentError)
- lambda { "%s" % [1, 2, 3] }.should raise_error(ArgumentError)
+ -> { "" % [1, 2, 3] }.should.raise(ArgumentError)
+ -> { "%s" % [1, 2, 3] }.should.raise(ArgumentError)
ensure
$DEBUG = old_debug
$stderr = s
@@ -98,26 +140,34 @@ describe "String#%" do
end
end
- it "replaces trailing absolute argument specifier without type with percent sign" do
- ("hello %1$" % "foo").should == "hello %"
+ ruby_version_is ""..."3.4" do
+ it "replaces trailing absolute argument specifier without type with percent sign" do
+ ("hello %1$" % "foo").should == "hello %"
+ end
+ end
+
+ ruby_version_is "3.4" do
+ it "raises an ArgumentError if absolute argument specifier is followed by a conversion specifier" do
+ -> { "hello %1$" % "foo" }.should.raise(ArgumentError)
+ end
end
it "raises an ArgumentError when given invalid argument specifiers" do
- lambda { "%1" % [] }.should raise_error(ArgumentError)
- lambda { "%+" % [] }.should raise_error(ArgumentError)
- lambda { "%-" % [] }.should raise_error(ArgumentError)
- lambda { "%#" % [] }.should raise_error(ArgumentError)
- lambda { "%0" % [] }.should raise_error(ArgumentError)
- lambda { "%*" % [] }.should raise_error(ArgumentError)
- lambda { "%." % [] }.should raise_error(ArgumentError)
- lambda { "%_" % [] }.should raise_error(ArgumentError)
- lambda { "%0$s" % "x" }.should raise_error(ArgumentError)
- lambda { "%*0$s" % [5, "x"] }.should raise_error(ArgumentError)
- lambda { "%*1$.*0$1$s" % [1, 2, 3] }.should raise_error(ArgumentError)
+ -> { "%1" % [] }.should.raise(ArgumentError)
+ -> { "%+" % [] }.should.raise(ArgumentError)
+ -> { "%-" % [] }.should.raise(ArgumentError)
+ -> { "%#" % [] }.should.raise(ArgumentError)
+ -> { "%0" % [] }.should.raise(ArgumentError)
+ -> { "%*" % [] }.should.raise(ArgumentError)
+ -> { "%." % [] }.should.raise(ArgumentError)
+ -> { "%_" % [] }.should.raise(ArgumentError)
+ -> { "%0$s" % "x" }.should.raise(ArgumentError)
+ -> { "%*0$s" % [5, "x"] }.should.raise(ArgumentError)
+ -> { "%*1$.*0$1$s" % [1, 2, 3] }.should.raise(ArgumentError)
end
it "raises an ArgumentError when multiple positional argument tokens are given for one format specifier" do
- lambda { "%1$1$s" % "foo" }.should raise_error(ArgumentError)
+ -> { "%1$1$s" % "foo" }.should.raise(ArgumentError)
end
it "respects positional arguments and precision tokens given for one format specifier" do
@@ -133,36 +183,36 @@ describe "String#%" do
end
it "raises an ArgumentError when multiple width star tokens are given for one format specifier" do
- lambda { "%**s" % [5, 5, 5] }.should raise_error(ArgumentError)
+ -> { "%**s" % [5, 5, 5] }.should.raise(ArgumentError)
end
it "raises an ArgumentError when a width star token is seen after a width token" do
- lambda { "%5*s" % [5, 5] }.should raise_error(ArgumentError)
+ -> { "%5*s" % [5, 5] }.should.raise(ArgumentError)
end
it "raises an ArgumentError when multiple precision tokens are given" do
- lambda { "%.5.5s" % 5 }.should raise_error(ArgumentError)
- lambda { "%.5.*s" % [5, 5] }.should raise_error(ArgumentError)
- lambda { "%.*.5s" % [5, 5] }.should raise_error(ArgumentError)
+ -> { "%.5.5s" % 5 }.should.raise(ArgumentError)
+ -> { "%.5.*s" % [5, 5] }.should.raise(ArgumentError)
+ -> { "%.*.5s" % [5, 5] }.should.raise(ArgumentError)
end
it "raises an ArgumentError when there are less arguments than format specifiers" do
("foo" % []).should == "foo"
- lambda { "%s" % [] }.should raise_error(ArgumentError)
- lambda { "%s %s" % [1] }.should raise_error(ArgumentError)
+ -> { "%s" % [] }.should.raise(ArgumentError)
+ -> { "%s %s" % [1] }.should.raise(ArgumentError)
end
it "raises an ArgumentError when absolute and relative argument numbers are mixed" do
- lambda { "%s %1$s" % "foo" }.should raise_error(ArgumentError)
- lambda { "%1$s %s" % "foo" }.should raise_error(ArgumentError)
+ -> { "%s %1$s" % "foo" }.should.raise(ArgumentError)
+ -> { "%1$s %s" % "foo" }.should.raise(ArgumentError)
- lambda { "%s %2$s" % ["foo", "bar"] }.should raise_error(ArgumentError)
- lambda { "%2$s %s" % ["foo", "bar"] }.should raise_error(ArgumentError)
+ -> { "%s %2$s" % ["foo", "bar"] }.should.raise(ArgumentError)
+ -> { "%2$s %s" % ["foo", "bar"] }.should.raise(ArgumentError)
- lambda { "%*2$s" % [5, 5, 5] }.should raise_error(ArgumentError)
- lambda { "%*.*2$s" % [5, 5, 5] }.should raise_error(ArgumentError)
- lambda { "%*2$.*2$s" % [5, 5, 5] }.should raise_error(ArgumentError)
- lambda { "%*.*2$s" % [5, 5, 5] }.should raise_error(ArgumentError)
+ -> { "%*2$s" % [5, 5, 5] }.should.raise(ArgumentError)
+ -> { "%*.*2$s" % [5, 5, 5] }.should.raise(ArgumentError)
+ -> { "%*2$.*2$s" % [5, 5, 5] }.should.raise(ArgumentError)
+ -> { "%*.*2$s" % [5, 5, 5] }.should.raise(ArgumentError)
end
it "allows reuse of the one argument multiple via absolute argument numbers" do
@@ -171,13 +221,13 @@ describe "String#%" do
end
it "always interprets an array argument as a list of argument parameters" do
- lambda { "%p" % [] }.should raise_error(ArgumentError)
+ -> { "%p" % [] }.should.raise(ArgumentError)
("%p" % [1]).should == "1"
("%p %p" % [1, 2]).should == "1 2"
end
it "always interprets an array subclass argument as a list of argument parameters" do
- lambda { "%p" % StringSpecs::MyArray[] }.should raise_error(ArgumentError)
+ -> { "%p" % StringSpecs::MyArray[] }.should.raise(ArgumentError)
("%p" % StringSpecs::MyArray[1]).should == "1"
("%p %p" % StringSpecs::MyArray[1, 2]).should == "1 2"
end
@@ -248,7 +298,7 @@ describe "String#%" do
x = mock("string modulo to_ary")
x.should_receive(:to_ary).and_return("x")
- lambda { "%s" % x }.should raise_error(TypeError)
+ -> { "%s" % x }.should.raise(TypeError)
end
it "tries to convert the argument to Array by calling #to_ary" do
@@ -271,28 +321,7 @@ describe "String#%" do
"%f", "%g", "%G", "%i", "%o", "%p",
"%s", "%u", "%x", "%X"
].each do |format|
- (StringSpecs::MyString.new(format) % universal).should be_an_instance_of(String)
- end
- end
-
- it "always taints the result when the format string is tainted" do
- universal = mock('0')
- def universal.to_int() 0 end
- def universal.to_str() "0" end
- def universal.to_f() 0.0 end
-
- [
- "", "foo",
- "%b", "%B", "%c", "%d", "%e", "%E",
- "%f", "%g", "%G", "%i", "%o", "%p",
- "%s", "%u", "%x", "%X"
- ].each do |format|
- subcls_format = StringSpecs::MyString.new(format)
- subcls_format.taint
- format.taint
-
- (format % universal).tainted?.should == true
- (subcls_format % universal).tainted?.should == true
+ (StringSpecs::MyString.new(format) % universal).should.instance_of?(String)
end
end
@@ -355,15 +384,15 @@ describe "String#%" do
("%*c" % [10, 3]).should == " \003"
("%c" % 42).should == "*"
- lambda { "%c" % Object }.should raise_error(TypeError)
+ -> { "%c" % Object }.should.raise(TypeError)
end
it "supports single character strings as argument for %c" do
("%c" % 'A').should == "A"
end
- it "raises an exception for multiple character strings as argument for %c" do
- lambda { "%c" % 'AA' }.should raise_error(ArgumentError)
+ it "supports only the first character as argument for %c" do
+ ("%c" % 'AA').should == "A"
end
it "calls to_str on argument for %c formats" do
@@ -533,7 +562,7 @@ describe "String#%" do
("%1$p" % [10, 5]).should == "10"
("%-22p" % 10).should == "10 "
("%*p" % [10, 10]).should == " 10"
- ("%p" % {capture: 1}).should == "{:capture=>1}"
+ ("%p" % {capture: 1}).should == {capture: 1}.inspect
("%p" % "str").should == "\"str\""
end
@@ -549,18 +578,6 @@ describe "String#%" do
# ("%p" % obj).should == "obj"
end
- it "taints result for %p when argument.inspect is tainted" do
- obj = mock('x')
- def obj.inspect() "x".taint end
-
- ("%p" % obj).tainted?.should == true
-
- obj = mock('x'); obj.taint
- def obj.inspect() "x" end
-
- ("%p" % obj).tainted?.should == false
- end
-
it "supports string formats using %s" do
("%s" % "hello").should == "hello"
("%s" % "").should == ""
@@ -589,16 +606,11 @@ describe "String#%" do
# ("%s" % obj).should == "obj"
end
- it "taints result for %s when argument is tainted" do
- ("%s" % "x".taint).tainted?.should == true
- ("%s" % mock('x').taint).tainted?.should == true
- end
-
# MRI crashes on this one.
# See http://groups.google.com/group/ruby-core-google/t/c285c18cd94c216d
it "raises an ArgumentError for huge precisions for %s" do
- block = lambda { "%.25555555555555555555555555555555555555s" % "hello world" }
- block.should raise_error(ArgumentError)
+ block = -> { "%.25555555555555555555555555555555555555s" % "hello world" }
+ block.should.raise(ArgumentError)
end
# Note: %u has been changed to an alias for %d in 1.9.
@@ -690,19 +702,19 @@ describe "String#%" do
(format % "0b1101").should == (format % Kernel.Integer("0b1101"))
(format % "0b1101_0000").should == (format % Kernel.Integer("0b1101_0000"))
(format % "0777").should == (format % Kernel.Integer("0777"))
- lambda {
+ -> {
# see [ruby-core:14139] for more details
(format % "0777").should == (format % Kernel.Integer("0777"))
- }.should_not raise_error(ArgumentError)
+ }.should_not.raise(ArgumentError)
- lambda { format % "0__7_7_7" }.should raise_error(ArgumentError)
+ -> { format % "0__7_7_7" }.should.raise(ArgumentError)
- lambda { format % "" }.should raise_error(ArgumentError)
- lambda { format % "x" }.should raise_error(ArgumentError)
- lambda { format % "5x" }.should raise_error(ArgumentError)
- lambda { format % "08" }.should raise_error(ArgumentError)
- lambda { format % "0b2" }.should raise_error(ArgumentError)
- lambda { format % "123__456" }.should raise_error(ArgumentError)
+ -> { format % "" }.should.raise(ArgumentError)
+ -> { format % "x" }.should.raise(ArgumentError)
+ -> { format % "5x" }.should.raise(ArgumentError)
+ -> { format % "08" }.should.raise(ArgumentError)
+ -> { format % "0b2" }.should.raise(ArgumentError)
+ -> { format % "123__456" }.should.raise(ArgumentError)
obj = mock('5')
obj.should_receive(:to_i).and_return(5)
@@ -729,21 +741,25 @@ describe "String#%" do
(format % "-10.4e-20").should == (format % -10.4e-20)
(format % ".5").should == (format % 0.5)
(format % "-.5").should == (format % -0.5)
+
+ ruby_version_is "3.4" do
+ (format % "10.").should == (format % 10)
+ end
+
# Something's strange with this spec:
# it works just fine in individual mode, but not when run as part of a group
(format % "10_1_0.5_5_5").should == (format % 1010.555)
(format % "0777").should == (format % 777)
- lambda { format % "" }.should raise_error(ArgumentError)
- lambda { format % "x" }.should raise_error(ArgumentError)
- lambda { format % "." }.should raise_error(ArgumentError)
- lambda { format % "10." }.should raise_error(ArgumentError)
- lambda { format % "5x" }.should raise_error(ArgumentError)
- lambda { format % "0b1" }.should raise_error(ArgumentError)
- lambda { format % "10e10.5" }.should raise_error(ArgumentError)
- lambda { format % "10__10" }.should raise_error(ArgumentError)
- lambda { format % "10.10__10" }.should raise_error(ArgumentError)
+ -> { format % "" }.should.raise(ArgumentError)
+ -> { format % "x" }.should.raise(ArgumentError)
+ -> { format % "." }.should.raise(ArgumentError)
+ -> { format % "5x" }.should.raise(ArgumentError)
+ -> { format % "0b1" }.should.raise(ArgumentError)
+ -> { format % "10e10.5" }.should.raise(ArgumentError)
+ -> { format % "10__10" }.should.raise(ArgumentError)
+ -> { format % "10.10__10" }.should.raise(ArgumentError)
obj = mock('5.0')
obj.should_receive(:to_f).and_return(5.0)
@@ -753,10 +769,6 @@ describe "String#%" do
it "behaves as if calling Kernel#Float for #{format} arguments, when the passed argument is hexadecimal string" do
(format % "0xA").should == (format % 0xA)
end
-
- it "doesn't taint the result for #{format} when argument is tainted" do
- (format % "5".taint).tainted?.should == false
- end
end
describe "when format string contains %{} sections" do
@@ -764,12 +776,8 @@ 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)
+ -> {"%{foo}" % []}.should.raise(ArgumentError)
end
end
@@ -779,11 +787,11 @@ describe "String#%" do
end
it "raises KeyError if key is missing from passed-in hash" do
- lambda {"%<foo>d" % {}}.should raise_error(KeyError)
+ -> {"%<foo>d" % {}}.should.raise(KeyError)
end
it "should raise ArgumentError if no hash given" do
- lambda {"%<foo>" % []}.should raise_error(ArgumentError)
+ -> {"%<foo>" % []}.should.raise(ArgumentError)
end
end
end
diff --git a/spec/ruby/core/string/multiply_spec.rb b/spec/ruby/core/string/multiply_spec.rb
index d932ebeb8e..c15f670c46 100644
--- a/spec/ruby/core/string/multiply_spec.rb
+++ b/spec/ruby/core/string/multiply_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes.rb', __FILE__)
-require File.expand_path('../../../shared/string/times', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative '../../shared/string/times'
describe "String#*" do
- it_behaves_like :string_times, :*, ->(str, times) { str * times }
+ it_behaves_like :string_times, :*, -> str, times { str * times }
end
diff --git a/spec/ruby/core/string/new_spec.rb b/spec/ruby/core/string/new_spec.rb
index b429ac48d2..aadf1e0e46 100644
--- a/spec/ruby/core/string/new_spec.rb
+++ b/spec/ruby/core/string/new_spec.rb
@@ -1,25 +1,21 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "String.new" do
it "returns an instance of String" do
str = String.new
- str.should be_an_instance_of(String)
+ str.should.instance_of?(String)
end
- ruby_version_is "2.3" do
- it "accepts an encoding argument" do
- xA4xA2 = [0xA4, 0xA2].pack('CC').force_encoding 'utf-8'
- str = String.new(xA4xA2, encoding: 'euc-jp')
- str.encoding.should == Encoding::EUC_JP
- end
+ it "accepts an encoding argument" do
+ xA4xA2 = [0xA4, 0xA2].pack('CC').force_encoding 'utf-8'
+ str = String.new(xA4xA2, encoding: 'euc-jp')
+ str.encoding.should == Encoding::EUC_JP
end
- ruby_version_is "2.4" do
- it "accepts a capacity argument" do
- String.new("", capacity: 100_000).should == ""
- String.new("abc", capacity: 100_000).should == "abc"
- end
+ it "accepts a capacity argument" do
+ String.new("", capacity: 100_000).should == ""
+ String.new("abc", capacity: 100_000).should == "abc"
end
it "returns a fully-formed String" do
@@ -32,7 +28,7 @@ describe "String.new" do
it "returns a new string given a string argument" do
str1 = "test"
str = String.new(str1)
- str.should be_an_instance_of(String)
+ str.should.instance_of?(String)
str.should == str1
str << "more"
str.should == "testmore"
@@ -40,7 +36,7 @@ describe "String.new" do
it "returns an instance of a subclass" do
a = StringSpecs::MyString.new("blah")
- a.should be_an_instance_of(StringSpecs::MyString)
+ a.should.instance_of?(StringSpecs::MyString)
a.should == "blah"
end
@@ -55,8 +51,8 @@ describe "String.new" do
end
it "raises TypeError on inconvertible object" do
- lambda { String.new 5 }.should raise_error(TypeError)
- lambda { String.new nil }.should raise_error(TypeError)
+ -> { String.new 5 }.should.raise(TypeError)
+ -> { String.new nil }.should.raise(TypeError)
end
it "returns a binary String" do
diff --git a/spec/ruby/core/string/next_spec.rb b/spec/ruby/core/string/next_spec.rb
index 6b4a98d993..2ab121a909 100644
--- a/spec/ruby/core/string/next_spec.rb
+++ b/spec/ruby/core/string/next_spec.rb
@@ -1,11 +1,13 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes.rb', __FILE__)
-require File.expand_path('../shared/succ.rb', __FILE__)
+require_relative '../../spec_helper'
describe "String#next" do
- it_behaves_like(:string_succ, :next)
+ it "is an alias of String#succ" do
+ String.instance_method(:next).should == String.instance_method(:succ)
+ end
end
describe "String#next!" do
- it_behaves_like(:string_succ_bang, :"next!")
+ it "is an alias of String#succ!" do
+ String.instance_method(:next!).should == String.instance_method(:succ!)
+ end
end
diff --git a/spec/ruby/core/string/oct_spec.rb b/spec/ruby/core/string/oct_spec.rb
index 7cdbabc436..7637692217 100644
--- a/spec/ruby/core/string/oct_spec.rb
+++ b/spec/ruby/core/string/oct_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes.rb', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
# Note: We can't completely spec this in terms of to_int() because hex()
# allows the base to be changed by a base specifier in the string.
diff --git a/spec/ruby/core/string/ord_spec.rb b/spec/ruby/core/string/ord_spec.rb
index 64466fde58..5a17fc1d87 100644
--- a/spec/ruby/core/string/ord_spec.rb
+++ b/spec/ruby/core/string/ord_spec.rb
@@ -1,30 +1,33 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
-with_feature :encoding do
- describe "String#ord" do
- it "returns a Fixnum" do
- 'a'.ord.should be_an_instance_of(Fixnum)
- end
+describe "String#ord" do
+ it "returns an Integer" do
+ 'a'.ord.should.instance_of?(Integer)
+ end
- it "returns the codepoint of the first character in the String" do
- 'a'.ord.should == 97
- end
+ it "returns the codepoint of the first character in the String" do
+ 'a'.ord.should == 97
+ end
- it "ignores subsequent characters" do
- "\u{287}a".ord.should == "\u{287}".ord
- end
+ it "ignores subsequent characters" do
+ "\u{287}a".ord.should == "\u{287}".ord
+ end
- it "understands multibyte characters" do
- "\u{9879}".ord.should == 39033
- end
+ it "understands multibyte characters" do
+ "\u{9879}".ord.should == 39033
+ end
- it "is equivalent to #codepoints.first" do
- "\u{981}\u{982}".ord.should == "\u{981}\u{982}".codepoints.first
- end
+ it "is equivalent to #codepoints.first" do
+ "\u{981}\u{982}".ord.should == "\u{981}\u{982}".codepoints.first
+ end
+
+ it "raises an ArgumentError if called on an empty String" do
+ -> { ''.ord }.should.raise(ArgumentError)
+ end
- it "raises an ArgumentError if called on an empty String" do
- lambda { ''.ord }.should raise_error(ArgumentError)
- end
+ it "raises ArgumentError if the character is broken" do
+ s = "©".dup.force_encoding("US-ASCII")
+ -> { s.ord }.should.raise(ArgumentError, "invalid byte sequence in US-ASCII")
end
end
diff --git a/spec/ruby/core/string/partition_spec.rb b/spec/ruby/core/string/partition_spec.rb
index 04f49db1b1..29fe910b39 100644
--- a/spec/ruby/core/string/partition_spec.rb
+++ b/spec/ruby/core/string/partition_spec.rb
@@ -1,7 +1,10 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes.rb', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/partition'
describe "String#partition with String" do
+ it_behaves_like :string_partition, :partition
+
it "returns an array of substrings based on splitting on the given string" do
"hello world".partition("o").should == ["hell", "o", " world"]
end
@@ -28,11 +31,33 @@ describe "String#partition with String" do
end
it "raises an error if not convertible to string" do
- lambda{ "hello".partition(5) }.should raise_error(TypeError)
- lambda{ "hello".partition(nil) }.should raise_error(TypeError)
+ ->{ "hello".partition(5) }.should.raise(TypeError)
+ ->{ "hello".partition(nil) }.should.raise(TypeError)
end
it "takes precedence over a given block" do
"hello world".partition("o") { true }.should == ["hell", "o", " world"]
end
+
+ it "handles a pattern in a superset encoding" do
+ string = "hello".dup.force_encoding(Encoding::US_ASCII)
+
+ result = string.partition("é")
+
+ result.should == ["hello", "", ""]
+ result[0].encoding.should == Encoding::US_ASCII
+ result[1].encoding.should == Encoding::US_ASCII
+ result[2].encoding.should == Encoding::US_ASCII
+ end
+
+ it "handles a pattern in a subset encoding" do
+ pattern = "o".dup.force_encoding(Encoding::US_ASCII)
+
+ result = "héllo world".partition(pattern)
+
+ result.should == ["héll", "o", " world"]
+ result[0].encoding.should == Encoding::UTF_8
+ result[1].encoding.should == Encoding::US_ASCII
+ result[2].encoding.should == Encoding::UTF_8
+ end
end
diff --git a/spec/ruby/core/string/plus_spec.rb b/spec/ruby/core/string/plus_spec.rb
index addc8873eb..0464141c37 100644
--- a/spec/ruby/core/string/plus_spec.rb
+++ b/spec/ruby/core/string/plus_spec.rb
@@ -1,8 +1,11 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/concat', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/concat'
describe "String#+" do
+ it_behaves_like :string_concat_encoding, :+
+ it_behaves_like :string_concat_type_coercion, :+
+
it "returns a new string containing the given string concatenated to self" do
("" + "").should == ""
("" + "Hello").should == "Hello"
@@ -18,30 +21,17 @@ describe "String#+" do
end
it "raises a TypeError when given any object that fails #to_str" do
- lambda { "" + Object.new }.should raise_error(TypeError)
- lambda { "" + 65 }.should raise_error(TypeError)
+ -> { "" + Object.new }.should.raise(TypeError)
+ -> { "" + 65 }.should.raise(TypeError)
end
it "doesn't return subclass instances" do
- (StringSpecs::MyString.new("hello") + "").should be_an_instance_of(String)
- (StringSpecs::MyString.new("hello") + "foo").should be_an_instance_of(String)
- (StringSpecs::MyString.new("hello") + StringSpecs::MyString.new("foo")).should be_an_instance_of(String)
- (StringSpecs::MyString.new("hello") + StringSpecs::MyString.new("")).should be_an_instance_of(String)
- (StringSpecs::MyString.new("") + StringSpecs::MyString.new("")).should be_an_instance_of(String)
- ("hello" + StringSpecs::MyString.new("foo")).should be_an_instance_of(String)
- ("hello" + StringSpecs::MyString.new("")).should be_an_instance_of(String)
+ (StringSpecs::MyString.new("hello") + "").should.instance_of?(String)
+ (StringSpecs::MyString.new("hello") + "foo").should.instance_of?(String)
+ (StringSpecs::MyString.new("hello") + StringSpecs::MyString.new("foo")).should.instance_of?(String)
+ (StringSpecs::MyString.new("hello") + StringSpecs::MyString.new("")).should.instance_of?(String)
+ (StringSpecs::MyString.new("") + StringSpecs::MyString.new("")).should.instance_of?(String)
+ ("hello" + StringSpecs::MyString.new("foo")).should.instance_of?(String)
+ ("hello" + StringSpecs::MyString.new("")).should.instance_of?(String)
end
-
- it "taints the result when self or other is tainted" do
- strs = ["", "OK", StringSpecs::MyString.new(""), StringSpecs::MyString.new("OK")]
- strs += strs.map { |s| s.dup.taint }
-
- strs.each do |str|
- strs.each do |other|
- (str + other).tainted?.should == (str.tainted? | other.tainted?)
- end
- end
- end
-
- it_behaves_like :string_concat_encoding, :+
end
diff --git a/spec/ruby/core/string/prepend_spec.rb b/spec/ruby/core/string/prepend_spec.rb
index 17e97fd844..a8da4e62cb 100644
--- a/spec/ruby/core/string/prepend_spec.rb
+++ b/spec/ruby/core/string/prepend_spec.rb
@@ -1,10 +1,11 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes.rb', __FILE__)
+# frozen_string_literal: false
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "String#prepend" do
it "prepends the given argument to self and returns self" do
str = "world"
- str.prepend("hello ").should equal(str)
+ str.prepend("hello ").should.equal?(str)
str.should == "hello world"
end
@@ -16,16 +17,16 @@ describe "String#prepend" do
end
it "raises a TypeError if the given argument can't be converted to a String" do
- lambda { "hello ".prepend [] }.should raise_error(TypeError)
- lambda { 'hello '.prepend mock('x') }.should raise_error(TypeError)
+ -> { "hello ".prepend [] }.should.raise(TypeError)
+ -> { 'hello '.prepend mock('x') }.should.raise(TypeError)
end
- it "raises a RuntimeError when self is frozen" do
+ it "raises a FrozenError when self is frozen" do
a = "hello"
a.freeze
- lambda { a.prepend "" }.should raise_error(RuntimeError)
- lambda { a.prepend "test" }.should raise_error(RuntimeError)
+ -> { a.prepend "" }.should.raise(FrozenError)
+ -> { a.prepend "test" }.should.raise(FrozenError)
end
it "works when given a subclass instance" do
@@ -34,31 +35,21 @@ describe "String#prepend" do
a.should == "hello world"
end
- it "taints self if other is tainted" do
- x = "x"
- x.prepend("".taint).tainted?.should be_true
-
- x = "x"
- x.prepend("y".taint).tainted?.should be_true
+ it "takes multiple arguments" do
+ str = " world"
+ str.prepend "he", "", "llo"
+ str.should == "hello world"
end
- ruby_version_is "2.4" do
- it "takes multiple arguments" do
- str = " world"
- str.prepend "he", "", "llo"
- str.should == "hello world"
- end
-
- it "prepends the initial value when given arguments contain 2 self" do
- str = "hello"
- str.prepend str, str
- str.should == "hellohellohello"
- end
+ it "prepends the initial value when given arguments contain 2 self" do
+ str = "hello"
+ str.prepend str, str
+ str.should == "hellohellohello"
+ end
- it "returns self when given no arguments" do
- str = "hello"
- str.prepend.should equal(str)
- str.should == "hello"
- end
+ it "returns self when given no arguments" do
+ str = "hello"
+ str.prepend.should.equal?(str)
+ str.should == "hello"
end
end
diff --git a/spec/ruby/core/string/replace_spec.rb b/spec/ruby/core/string/replace_spec.rb
index 0f59a9a1ab..ef9bab4f3c 100644
--- a/spec/ruby/core/string/replace_spec.rb
+++ b/spec/ruby/core/string/replace_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/replace', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/replace'
describe "String#replace" do
it_behaves_like :string_replace, :replace
diff --git a/spec/ruby/core/string/reverse_spec.rb b/spec/ruby/core/string/reverse_spec.rb
index c37e815ba3..e37c1125db 100644
--- a/spec/ruby/core/string/reverse_spec.rb
+++ b/spec/ruby/core/string/reverse_spec.rb
@@ -1,7 +1,8 @@
# encoding: utf-8
+# frozen_string_literal: false
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes.rb', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "String#reverse" do
it "returns a new string with the characters of self in reverse order" do
@@ -10,43 +11,60 @@ describe "String#reverse" do
"".reverse.should == ""
end
- it "taints the result if self is tainted" do
- "".taint.reverse.tainted?.should == true
- "m".taint.reverse.tainted?.should == true
+ it "returns String instances when called on a subclass" do
+ StringSpecs::MyString.new("stressed").reverse.should.instance_of?(String)
+ StringSpecs::MyString.new("m").reverse.should.instance_of?(String)
+ StringSpecs::MyString.new("").reverse.should.instance_of?(String)
end
- with_feature :encoding do
- it "reverses a string with multi byte characters" do
- "微軟正黑體".reverse.should == "體黑正軟微"
- end
+ it "reverses a string with multi byte characters" do
+ "微軟正黑體".reverse.should == "體黑正軟微"
end
+ it "works with a broken string" do
+ str = "微軟\xDF\xDE正黑體".force_encoding(Encoding::UTF_8)
+
+ str.valid_encoding?.should == false
+
+ str.reverse.should == "體黑正\xDE\xDF軟微"
+ end
+
+ it "returns a String in the same encoding as self" do
+ "stressed".encode("US-ASCII").reverse.encoding.should == Encoding::US_ASCII
+ end
end
describe "String#reverse!" do
it "reverses self in place and always returns self" do
a = "stressed"
- a.reverse!.should equal(a)
+ a.reverse!.should.equal?(a)
a.should == "desserts"
"".reverse!.should == ""
end
- it "raises a RuntimeError on a frozen instance that is modified" do
- lambda { "anna".freeze.reverse! }.should raise_error(RuntimeError)
- lambda { "hello".freeze.reverse! }.should raise_error(RuntimeError)
+ it "raises a FrozenError on a frozen instance that is modified" do
+ -> { "anna".freeze.reverse! }.should.raise(FrozenError)
+ -> { "hello".freeze.reverse! }.should.raise(FrozenError)
end
# see [ruby-core:23666]
- it "raises a RuntimeError on a frozen instance that would not be modified" do
- lambda { "".freeze.reverse! }.should raise_error(RuntimeError)
+ it "raises a FrozenError on a frozen instance that would not be modified" do
+ -> { "".freeze.reverse! }.should.raise(FrozenError)
end
- with_feature :encoding do
- it "reverses a string with multi byte characters" do
- str = "微軟正黑體"
- str.reverse!
- str.should == "體黑正軟微"
- end
+ it "reverses a string with multi byte characters" do
+ str = "微軟正黑體"
+ str.reverse!
+ str.should == "體黑正軟微"
+ end
+
+ it "works with a broken string" do
+ str = "微軟\xDF\xDE正黑體".force_encoding(Encoding::UTF_8)
+
+ str.valid_encoding?.should == false
+ str.reverse!
+
+ str.should == "體黑正\xDE\xDF軟微"
end
end
diff --git a/spec/ruby/core/string/rindex_spec.rb b/spec/ruby/core/string/rindex_spec.rb
index 7085914189..acecec224f 100644
--- a/spec/ruby/core/string/rindex_spec.rb
+++ b/spec/ruby/core/string/rindex_spec.rb
@@ -1,20 +1,23 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes.rb', __FILE__)
-require File.expand_path('../fixtures/utf-8-encoding.rb', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "String#rindex with object" do
- it "raises a TypeError if obj isn't a String, Fixnum or Regexp" do
+ it "raises a TypeError if obj isn't a String or Regexp" do
not_supported_on :opal do
- lambda { "hello".rindex(:sym) }.should raise_error(TypeError)
+ -> { "hello".rindex(:sym) }.should.raise(TypeError)
end
- lambda { "hello".rindex(mock('x')) }.should raise_error(TypeError)
+ -> { "hello".rindex(mock('x')) }.should.raise(TypeError)
+ end
+
+ it "raises a TypeError if obj is an Integer" do
+ -> { "hello".rindex(42) }.should.raise(TypeError)
end
it "doesn't try to convert obj to an integer via to_int" do
obj = mock('x')
obj.should_not_receive(:to_int)
- lambda { "hello".rindex(obj) }.should raise_error(TypeError)
+ -> { "hello".rindex(obj) }.should.raise(TypeError)
end
it "tries to convert obj to a string via to_str" do
@@ -190,7 +193,22 @@ describe "String#rindex with String" do
end
it "raises a TypeError when given offset is nil" do
- lambda { "str".rindex("st", nil) }.should raise_error(TypeError)
+ -> { "str".rindex("st", nil) }.should.raise(TypeError)
+ end
+
+ it "handles a substring in a superset encoding" do
+ 'abc'.dup.force_encoding(Encoding::US_ASCII).rindex('é').should == nil
+ end
+
+ it "handles a substring in a subset encoding" do
+ 'été'.rindex('t'.dup.force_encoding(Encoding::US_ASCII)).should == 1
+ end
+
+ it "raises an Encoding::CompatibilityError if the encodings are incompatible" do
+ str = 'abc'.dup.force_encoding("ISO-2022-JP")
+ pattern = 'b'.dup.force_encoding("EUC-JP")
+
+ -> { str.rindex(pattern) }.should.raise(Encoding::CompatibilityError, "incompatible character encodings: ISO-2022-JP and EUC-JP")
end
end
@@ -344,25 +362,23 @@ describe "String#rindex with Regexp" do
end
it "raises a TypeError when given offset is nil" do
- lambda { "str".rindex(/../, nil) }.should raise_error(TypeError)
+ -> { "str".rindex(/../, nil) }.should.raise(TypeError)
end
- with_feature :encoding do
- it "returns the reverse character index of a multibyte character" do
- "ã‚りãŒã‚ŠãŒã¨ã†".rindex("ãŒ").should == 4
- "ã‚りãŒã‚ŠãŒã¨ã†".rindex(/ãŒ/).should == 4
- end
+ it "returns the reverse character index of a multibyte character" do
+ "ã‚りãŒã‚ŠãŒã¨ã†".rindex("ãŒ").should == 4
+ "ã‚りãŒã‚ŠãŒã¨ã†".rindex(/ãŒ/).should == 4
+ end
- it "returns the character index before the finish" do
- "ã‚りãŒã‚ŠãŒã¨ã†".rindex("ãŒ", 3).should == 2
- "ã‚りãŒã‚ŠãŒã¨ã†".rindex(/ãŒ/, 3).should == 2
- end
+ it "returns the character index before the finish" do
+ "ã‚りãŒã‚ŠãŒã¨ã†".rindex("ãŒ", 3).should == 2
+ "ã‚りãŒã‚ŠãŒã¨ã†".rindex(/ãŒ/, 3).should == 2
+ end
- it "raises an Encoding::CompatibilityError if the encodings are incompatible" do
- re = Regexp.new "れ".encode(Encoding::EUC_JP)
- lambda do
- "ã‚れ".rindex re
- end.should raise_error(Encoding::CompatibilityError)
- end
+ it "raises an Encoding::CompatibilityError if the encodings are incompatible" do
+ re = Regexp.new "れ".encode(Encoding::EUC_JP)
+ -> do
+ "ã‚れ".rindex re
+ end.should.raise(Encoding::CompatibilityError, "incompatible encoding regexp match (EUC-JP regexp with UTF-8 string)")
end
end
diff --git a/spec/ruby/core/string/rjust_spec.rb b/spec/ruby/core/string/rjust_spec.rb
index 85cb1fe213..9f9c369745 100644
--- a/spec/ruby/core/string/rjust_spec.rb
+++ b/spec/ruby/core/string/rjust_spec.rb
@@ -1,6 +1,6 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes.rb', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "String#rjust with length, padding" do
it "returns a new string of specified length with self right justified and padded with padstr" do
@@ -31,14 +31,6 @@ describe "String#rjust with length, padding" do
"radiology".rjust(8, '-').should == "radiology"
end
- it "taints result when self or padstr is tainted" do
- "x".taint.rjust(4).tainted?.should == true
- "x".taint.rjust(0).tainted?.should == true
- "".taint.rjust(0).tainted?.should == true
- "x".taint.rjust(4, "*").tainted?.should == true
- "x".rjust(4, "*".taint).tainted?.should == true
- end
-
it "tries to convert length to an integer using to_int" do
"^".rjust(3.8, "^_").should == "^_^"
@@ -49,10 +41,10 @@ describe "String#rjust with length, padding" do
end
it "raises a TypeError when length can't be converted to an integer" do
- lambda { "hello".rjust("x") }.should raise_error(TypeError)
- lambda { "hello".rjust("x", "y") }.should raise_error(TypeError)
- lambda { "hello".rjust([]) }.should raise_error(TypeError)
- lambda { "hello".rjust(mock('x')) }.should raise_error(TypeError)
+ -> { "hello".rjust("x") }.should.raise(TypeError)
+ -> { "hello".rjust("x", "y") }.should.raise(TypeError)
+ -> { "hello".rjust([]) }.should.raise(TypeError)
+ -> { "hello".rjust(mock('x')) }.should.raise(TypeError)
end
it "tries to convert padstr to a string using to_str" do
@@ -63,54 +55,46 @@ describe "String#rjust with length, padding" do
end
it "raises a TypeError when padstr can't be converted" do
- lambda { "hello".rjust(20, []) }.should raise_error(TypeError)
- lambda { "hello".rjust(20, Object.new)}.should raise_error(TypeError)
- lambda { "hello".rjust(20, mock('x')) }.should raise_error(TypeError)
+ -> { "hello".rjust(20, []) }.should.raise(TypeError)
+ -> { "hello".rjust(20, Object.new)}.should.raise(TypeError)
+ -> { "hello".rjust(20, mock('x')) }.should.raise(TypeError)
end
it "raises an ArgumentError when padstr is empty" do
- lambda { "hello".rjust(10, '') }.should raise_error(ArgumentError)
+ -> { "hello".rjust(10, '') }.should.raise(ArgumentError)
end
- it "returns subclass instances when called on subclasses" do
- StringSpecs::MyString.new("").rjust(10).should be_an_instance_of(StringSpecs::MyString)
- StringSpecs::MyString.new("foo").rjust(10).should be_an_instance_of(StringSpecs::MyString)
- StringSpecs::MyString.new("foo").rjust(10, StringSpecs::MyString.new("x")).should be_an_instance_of(StringSpecs::MyString)
+ it "returns String instances when called on subclasses" do
+ StringSpecs::MyString.new("").rjust(10).should.instance_of?(String)
+ StringSpecs::MyString.new("foo").rjust(10).should.instance_of?(String)
+ StringSpecs::MyString.new("foo").rjust(10, StringSpecs::MyString.new("x")).should.instance_of?(String)
- "".rjust(10, StringSpecs::MyString.new("x")).should be_an_instance_of(String)
- "foo".rjust(10, StringSpecs::MyString.new("x")).should be_an_instance_of(String)
+ "".rjust(10, StringSpecs::MyString.new("x")).should.instance_of?(String)
+ "foo".rjust(10, StringSpecs::MyString.new("x")).should.instance_of?(String)
end
- it "when padding is tainted and self is untainted returns a tainted string if and only if length is longer than self" do
- "hello".rjust(4, 'X'.taint).tainted?.should be_false
- "hello".rjust(5, 'X'.taint).tainted?.should be_false
- "hello".rjust(6, 'X'.taint).tainted?.should be_true
+ describe "with width" do
+ it "returns a String in the same encoding as the original" do
+ str = "abc".dup.force_encoding Encoding::IBM437
+ result = str.rjust 5
+ result.should == " abc"
+ result.encoding.should.equal?(Encoding::IBM437)
+ end
end
- with_feature :encoding do
- describe "with width" do
- it "returns a String in the same encoding as the original" do
- str = "abc".force_encoding Encoding::IBM437
- result = str.rjust 5
- result.should == " abc"
- result.encoding.should equal(Encoding::IBM437)
- end
+ describe "with width, pattern" do
+ it "returns a String in the compatible encoding" do
+ str = "abc".dup.force_encoding Encoding::IBM437
+ result = str.rjust 5, "ã‚"
+ result.should == "ã‚ã‚abc"
+ result.encoding.should.equal?(Encoding::UTF_8)
end
- describe "with width, pattern" do
- it "returns a String in the compatible encoding" do
- str = "abc".force_encoding Encoding::IBM437
- result = str.rjust 5, "ã‚"
- result.should == "ã‚ã‚abc"
- result.encoding.should equal(Encoding::UTF_8)
- end
-
- it "raises an Encoding::CompatibilityError if the encodings are incompatible" do
- pat = "ã‚¢".encode Encoding::EUC_JP
- lambda do
- "ã‚れ".rjust 5, pat
- end.should raise_error(Encoding::CompatibilityError)
- end
+ it "raises an Encoding::CompatibilityError if the encodings are incompatible" do
+ pat = "ã‚¢".encode Encoding::EUC_JP
+ -> do
+ "ã‚れ".rjust 5, pat
+ end.should.raise(Encoding::CompatibilityError)
end
end
end
diff --git a/spec/ruby/core/string/rpartition_spec.rb b/spec/ruby/core/string/rpartition_spec.rb
index c58d96f298..a7dd7430b7 100644
--- a/spec/ruby/core/string/rpartition_spec.rb
+++ b/spec/ruby/core/string/rpartition_spec.rb
@@ -1,7 +1,10 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes.rb', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/partition'
describe "String#rpartition with String" do
+ it_behaves_like :string_partition, :rpartition
+
it "returns an array of substrings based on splitting on the given string" do
"hello world".rpartition("o").should == ["hello w", "o", "rld"]
end
@@ -11,6 +14,19 @@ describe "String#rpartition with String" do
"hello".rpartition("hello").should == ["", "hello", ""]
end
+ it "returns original string if regexp doesn't match" do
+ "hello".rpartition("/x/").should == ["", "", "hello"]
+ end
+
+ it "returns new object if doesn't match" do
+ str = "hello"
+ str.rpartition("/no_match/").last.should_not.equal?(str)
+ end
+
+ it "handles multibyte string correctly" do
+ "ユーザ@ドメイン".rpartition(/@/).should == ["ユーザ", "@", "ドメイン"]
+ end
+
it "accepts regexp" do
"hello!".rpartition(/l./).should == ["hel", "lo", "!"]
end
@@ -27,7 +43,29 @@ describe "String#rpartition with String" do
end
it "raises an error if not convertible to string" do
- lambda{ "hello".rpartition(5) }.should raise_error(TypeError)
- lambda{ "hello".rpartition(nil) }.should raise_error(TypeError)
+ ->{ "hello".rpartition(5) }.should.raise(TypeError)
+ ->{ "hello".rpartition(nil) }.should.raise(TypeError)
+ end
+
+ it "handles a pattern in a superset encoding" do
+ string = "hello".dup.force_encoding(Encoding::US_ASCII)
+
+ result = string.rpartition("é")
+
+ result.should == ["", "", "hello"]
+ result[0].encoding.should == Encoding::US_ASCII
+ result[1].encoding.should == Encoding::US_ASCII
+ result[2].encoding.should == Encoding::US_ASCII
+ end
+
+ it "handles a pattern in a subset encoding" do
+ pattern = "o".dup.force_encoding(Encoding::US_ASCII)
+
+ result = "héllo world".rpartition(pattern)
+
+ result.should == ["héllo w", "o", "rld"]
+ result[0].encoding.should == Encoding::UTF_8
+ result[1].encoding.should == Encoding::US_ASCII
+ result[2].encoding.should == Encoding::UTF_8
end
end
diff --git a/spec/ruby/core/string/rstrip_spec.rb b/spec/ruby/core/string/rstrip_spec.rb
index 9dd686ce55..1638ea375d 100644
--- a/spec/ruby/core/string/rstrip_spec.rb
+++ b/spec/ruby/core/string/rstrip_spec.rb
@@ -1,30 +1,36 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes.rb', __FILE__)
+# frozen_string_literal: false
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/strip'
describe "String#rstrip" do
+ it_behaves_like :string_strip, :rstrip
+
it "returns a copy of self with trailing whitespace removed" do
" hello ".rstrip.should == " hello"
" hello world ".rstrip.should == " hello world"
" hello world \n\r\t\n\v\r".rstrip.should == " hello world"
"hello".rstrip.should == "hello"
"hello\x00".rstrip.should == "hello"
+ "ã“ã«ã¡ã‚ ".rstrip.should == "ã“ã«ã¡ã‚"
end
- it "returns a copy of self with all trailing whitespace and NULL bytes removed" do
- "\x00 \x00hello\x00 \x00".rstrip.should == "\x00 \x00hello"
+ it "works with lazy substrings" do
+ " hello "[1...-1].rstrip.should == " hello"
+ " hello world "[1...-1].rstrip.should == " hello world"
+ " hello world \n\r\t\n\v\r"[1...-1].rstrip.should == " hello world"
+ " ã“ã«ã¡ã‚ "[1...-1].rstrip.should == "ã“ã«ã¡ã‚"
end
- it "taints the result when self is tainted" do
- "".taint.rstrip.tainted?.should == true
- "ok".taint.rstrip.tainted?.should == true
- "ok ".taint.rstrip.tainted?.should == true
+ it "returns a copy of self with all trailing whitespace and NULL bytes removed" do
+ "\x00 \x00hello\x00 \x00".rstrip.should == "\x00 \x00hello"
end
end
describe "String#rstrip!" do
it "modifies self in place and returns self" do
a = " hello "
- a.rstrip!.should equal(a)
+ a.rstrip!.should.equal?(a)
a.should == " hello"
end
@@ -40,13 +46,35 @@ describe "String#rstrip!" do
a.should == "hello"
end
- it "raises a RuntimeError on a frozen instance that is modified" do
- lambda { " hello ".freeze.rstrip! }.should raise_error(RuntimeError)
+ it "makes a string empty if it is only whitespace" do
+ "".rstrip!.should == nil
+ " ".rstrip.should == ""
+ " ".rstrip.should == ""
+ end
+
+ it "removes trailing NULL bytes and whitespace" do
+ a = "\000 goodbye \000"
+ a.rstrip!
+ a.should == "\000 goodbye"
+ end
+
+ it "raises a FrozenError on a frozen instance that is modified" do
+ -> { " hello ".freeze.rstrip! }.should.raise(FrozenError)
end
# see [ruby-core:23666]
- it "raises a RuntimeError on a frozen instance that would not be modified" do
- lambda { "hello".freeze.rstrip! }.should raise_error(RuntimeError)
- lambda { "".freeze.rstrip! }.should raise_error(RuntimeError)
+ it "raises a FrozenError on a frozen instance that would not be modified" do
+ -> { "hello".freeze.rstrip! }.should.raise(FrozenError)
+ -> { "".freeze.rstrip! }.should.raise(FrozenError)
+ end
+
+ it "raises an Encoding::CompatibilityError if the last non-space codepoint is invalid" do
+ s = "abc\xDF".force_encoding(Encoding::UTF_8)
+ s.valid_encoding?.should == false
+ -> { s.rstrip! }.should.raise(Encoding::CompatibilityError)
+
+ s = "abc\xDF ".force_encoding(Encoding::UTF_8)
+ s.valid_encoding?.should == false
+ -> { s.rstrip! }.should.raise(Encoding::CompatibilityError)
end
end
diff --git a/spec/ruby/core/string/scan_spec.rb b/spec/ruby/core/string/scan_spec.rb
index f09daa1b74..47fa7214c2 100644
--- a/spec/ruby/core/string/scan_spec.rb
+++ b/spec/ruby/core/string/scan_spec.rb
@@ -1,6 +1,6 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes.rb', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "String#scan" do
it "returns an array containing all matches" do
@@ -58,39 +58,30 @@ describe "String#scan" do
end
it "raises a TypeError if pattern isn't a Regexp and can't be converted to a String" do
- lambda { "cruel world".scan(5) }.should raise_error(TypeError)
+ -> { "cruel world".scan(5) }.should.raise(TypeError)
not_supported_on :opal do
- lambda { "cruel world".scan(:test) }.should raise_error(TypeError)
+ -> { "cruel world".scan(:test) }.should.raise(TypeError)
end
- lambda { "cruel world".scan(mock('x')) }.should raise_error(TypeError)
+ -> { "cruel world".scan(mock('x')) }.should.raise(TypeError)
end
- it "taints the results if the String argument is tainted" do
- a = "hello hello hello".scan("hello".taint)
- a.each { |m| m.tainted?.should be_true }
+ # jruby/jruby#5513
+ it "does not raise any errors when passed a multi-byte string" do
+ "ã‚ã‚ã‚aaaã‚ã‚ã‚".scan("ã‚ã‚ã‚").should == ["ã‚ã‚ã‚", "ã‚ã‚ã‚"]
end
- it "taints the results when passed a String argument if self is tainted" do
- a = "hello hello hello".taint.scan("hello")
- a.each { |m| m.tainted?.should be_true }
- end
-
- it "taints the results if the Regexp argument is tainted" do
- a = "hello".scan(/./.taint)
- a.each { |m| m.tainted?.should be_true }
- end
-
- it "taints the results when passed a Regexp argument if self is tainted" do
- a = "hello".taint.scan(/./)
- a.each { |m| m.tainted?.should be_true }
+ it "returns Strings in the same encoding as self" do
+ "cruel world".encode("US-ASCII").scan(/\w+/).each do |s|
+ s.encoding.should == Encoding::US_ASCII
+ end
end
end
describe "String#scan with pattern and block" do
it "returns self" do
s = "foo"
- s.scan(/./) {}.should equal(s)
- s.scan(/roar/) {}.should equal(s)
+ s.scan(/./) {}.should.equal?(s)
+ s.scan(/roar/) {}.should.equal?(s)
end
it "passes each match to the block as one argument: an array" do
@@ -112,11 +103,11 @@ describe "String#scan with pattern and block" do
offsets = []
str.scan(/([aeiou])/) do
- md = $~
- md.string.should == str
- matches << md.to_a
- offsets << md.offset(0)
- str
+ md = $~
+ md.string.should == str
+ matches << md.to_a
+ offsets << md.offset(0)
+ str
end
matches.should == [["e", "e"], ["o", "o"]]
@@ -126,11 +117,11 @@ describe "String#scan with pattern and block" do
offsets = []
str.scan("l") do
- md = $~
- md.string.should == str
- matches << md.to_a
- offsets << md.offset(0)
- str
+ md = $~
+ md.string.should == str
+ matches << md.to_a
+ offsets << md.offset(0)
+ str
end
matches.should == [["l"], ["l"]]
@@ -166,22 +157,6 @@ describe "String#scan with pattern and block" do
$~.should == nil
end
- it "taints the results if the String argument is tainted" do
- "hello hello hello".scan("hello".taint).each { |m| m.tainted?.should be_true }
- end
-
- it "taints the results when passed a String argument if self is tainted" do
- "hello hello hello".taint.scan("hello").each { |m| m.tainted?.should be_true }
- end
-
- it "taints the results if the Regexp argument is tainted" do
- "hello".scan(/./.taint).each { |m| m.tainted?.should be_true }
- end
-
- it "taints the results when passed a Regexp argument if self is tainted" do
- "hello".taint.scan(/./).each { |m| m.tainted?.should be_true }
- end
-
it "passes block arguments as individual arguments when blocks are provided" do
"a b c\na b c\na b c".scan(/(\w*) (\w*) (\w*)/) do |first,second,third|
first.should == 'a';
@@ -189,4 +164,10 @@ describe "String#scan with pattern and block" do
third.should == 'c';
end
end
+
+ it "yields String instances for subclasses" do
+ a = []
+ StringSpecs::MyString.new("abc").scan(/./) { |s| a << s.class }
+ a.should == [String, String, String]
+ end
end
diff --git a/spec/ruby/core/string/scrub_spec.rb b/spec/ruby/core/string/scrub_spec.rb
index 815eb0fbb7..9dc55dbef7 100644
--- a/spec/ruby/core/string/scrub_spec.rb
+++ b/spec/ruby/core/string/scrub_spec.rb
@@ -1,5 +1,7 @@
# -*- encoding: utf-8 -*-
-require File.expand_path("../../../spec_helper", __FILE__)
+# frozen_string_literal: false
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "String#scrub with a default replacement" do
it "returns self for valid strings" do
@@ -13,18 +15,33 @@ describe "String#scrub with a default replacement" do
"abc\u3042#{x81}".scrub.should == "abc\u3042\uFFFD"
end
+ it "replaces invalid byte sequences in lazy substrings" do
+ x81 = [0x81].pack('C').force_encoding('utf-8')
+ "abc\u3042#{x81}def"[1...-1].scrub.should == "bc\u3042\uFFFDde"
+ end
+
it "returns a copy of self when the input encoding is BINARY" do
input = "foo".encode('BINARY')
input.scrub.should == "foo"
end
-
it "replaces invalid byte sequences when using ASCII as the input encoding" do
xE3x80 = [0xE3, 0x80].pack('CC').force_encoding 'utf-8'
input = "abc\u3042#{xE3x80}".force_encoding('ASCII')
input.scrub.should == "abc?????"
end
+
+ it "returns a String in the same encoding as self" do
+ x81 = [0x81].pack('C').force_encoding('utf-8')
+ "abc\u3042#{x81}".scrub.encoding.should == Encoding::UTF_8
+ end
+
+ it "returns String instances when called on a subclass" do
+ StringSpecs::MyString.new("foo").scrub.should.instance_of?(String)
+ input = [0x81].pack('C').force_encoding('utf-8')
+ StringSpecs::MyString.new(input).scrub.should.instance_of?(String)
+ end
end
describe "String#scrub with a custom replacement" do
@@ -39,6 +56,15 @@ describe "String#scrub with a custom replacement" do
"abc\u3042#{x81}".scrub("*").should == "abc\u3042*"
end
+ it "replaces invalid byte sequences in frozen strings" do
+ x81 = [0x81].pack('C').force_encoding('utf-8')
+ (-"abc\u3042#{x81}").scrub("*").should == "abc\u3042*"
+
+ leading_surrogate = [0x00, 0xD8]
+ utf16_str = ("abc".encode('UTF-16LE').bytes + leading_surrogate).pack('c*').force_encoding('UTF-16LE')
+ (-(utf16_str)).scrub("*".encode('UTF-16LE')).should == "abc*".encode('UTF-16LE')
+ end
+
it "replaces an incomplete character at the end with a single replacement" do
xE3x80 = [0xE3, 0x80].pack('CC').force_encoding 'utf-8'
xE3x80.scrub("*").should == "*"
@@ -47,16 +73,27 @@ describe "String#scrub with a custom replacement" do
it "raises ArgumentError for replacements with an invalid encoding" do
x81 = [0x81].pack('C').force_encoding('utf-8')
xE4 = [0xE4].pack('C').force_encoding('utf-8')
- block = lambda { "foo#{x81}".scrub(xE4) }
+ block = -> { "foo#{x81}".scrub(xE4) }
+
+ block.should.raise(ArgumentError)
+ end
- block.should raise_error(ArgumentError)
+ it "returns a String in the same encoding as self" do
+ x81 = [0x81].pack('C').force_encoding('utf-8')
+ "abc\u3042#{x81}".scrub("*").encoding.should == Encoding::UTF_8
end
it "raises TypeError when a non String replacement is given" do
x81 = [0x81].pack('C').force_encoding('utf-8')
- block = lambda { "foo#{x81}".scrub(1) }
+ block = -> { "foo#{x81}".scrub(1) }
+
+ block.should.raise(TypeError)
+ end
- block.should raise_error(TypeError)
+ it "returns String instances when called on a subclass" do
+ StringSpecs::MyString.new("foo").scrub("*").should.instance_of?(String)
+ input = [0x81].pack('C').force_encoding('utf-8')
+ StringSpecs::MyString.new(input).scrub("*").should.instance_of?(String)
end
end
@@ -82,6 +119,12 @@ describe "String#scrub with a block" do
replaced.should == "€€"
end
+
+ it "returns String instances when called on a subclass" do
+ StringSpecs::MyString.new("foo").scrub { |b| "*" }.should.instance_of?(String)
+ input = [0x81].pack('C').force_encoding('utf-8')
+ StringSpecs::MyString.new(input).scrub { |b| "<#{b.unpack("H*")[0]}>" }.should.instance_of?(String)
+ end
end
describe "String#scrub!" do
@@ -98,4 +141,24 @@ describe "String#scrub!" do
input.scrub! { |b| "<?>" }
input.should == "a<?>"
end
+
+ it "maintains the state of frozen strings that are already valid" do
+ input = "a"
+ input.freeze
+ input.scrub!
+ input.frozen?.should == true
+ end
+
+ it "preserves the instance variables of already valid strings" do
+ input = "a"
+ input.instance_variable_set(:@a, 'b')
+ input.scrub!
+ input.instance_variable_get(:@a).should == 'b'
+ end
+
+ it "accepts a frozen string as a replacement" do
+ input = "a\xE2"
+ input.scrub!('.'.freeze)
+ input.should == 'a.'
+ end
end
diff --git a/spec/ruby/core/string/setbyte_spec.rb b/spec/ruby/core/string/setbyte_spec.rb
index 6373d74be1..d9fcc279c0 100644
--- a/spec/ruby/core/string/setbyte_spec.rb
+++ b/spec/ruby/core/string/setbyte_spec.rb
@@ -1,9 +1,10 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
+# frozen_string_literal: false
+require_relative '../../spec_helper'
describe "String#setbyte" do
it "returns an Integer" do
- "a".setbyte(0,1).should be_kind_of(Integer)
+ "a".setbyte(0,1).should.is_a?(Integer)
end
it "modifies the receiver" do
@@ -33,9 +34,15 @@ describe "String#setbyte" do
it "can invalidate a String's encoding" do
str = "glark"
- str.valid_encoding?.should be_true
+ str.valid_encoding?.should == true
str.setbyte(2,253)
- str.valid_encoding?.should be_false
+ str.valid_encoding?.should == false
+
+ str = "ABC"
+ str.setbyte(0, 0x20) # ' '
+ str.should.valid_encoding?
+ str.setbyte(0, 0xE3)
+ str.should_not.valid_encoding?
end
it "regards a negative index as counting from the end of the String" do
@@ -51,11 +58,11 @@ describe "String#setbyte" do
end
it "raises an IndexError if the index is greater than the String bytesize" do
- lambda { "?".setbyte(1, 97) }.should raise_error(IndexError)
+ -> { "?".setbyte(1, 97) }.should.raise(IndexError)
end
- it "raises an IndexError if the nexgative index is greater magnitude than the String bytesize" do
- lambda { "???".setbyte(-5, 97) }.should raise_error(IndexError)
+ it "raises an IndexError if the negative index is greater magnitude than the String bytesize" do
+ -> { "???".setbyte(-5, 97) }.should.raise(IndexError)
end
it "sets a byte at an index greater than String size" do
@@ -75,14 +82,14 @@ describe "String#setbyte" do
str1.should_not == "ledgehog"
end
- it "raises a RuntimeError if self is frozen" do
+ it "raises a FrozenError if self is frozen" do
str = "cold".freeze
- str.frozen?.should be_true
- lambda { str.setbyte(3,96) }.should raise_error(RuntimeError)
+ str.frozen?.should == true
+ -> { str.setbyte(3,96) }.should.raise(FrozenError)
end
it "raises a TypeError unless the second argument is an Integer" do
- lambda { "a".setbyte(0,'a') }.should raise_error(TypeError)
+ -> { "a".setbyte(0,'a') }.should.raise(TypeError)
end
it "calls #to_int to convert the index" do
diff --git a/spec/ruby/core/string/shared/byte_index_common.rb b/spec/ruby/core/string/shared/byte_index_common.rb
new file mode 100644
index 0000000000..bae6cff49f
--- /dev/null
+++ b/spec/ruby/core/string/shared/byte_index_common.rb
@@ -0,0 +1,63 @@
+# -*- encoding: utf-8 -*-
+require_relative '../../../spec_helper'
+
+describe :byte_index_common, shared: true do
+ describe "raises on type errors" do
+ it "raises a TypeError if passed nil" do
+ -> { "abc".send(@method, nil) }.should.raise(TypeError, "no implicit conversion of nil into String")
+ end
+
+ it "raises a TypeError if passed a boolean" do
+ -> { "abc".send(@method, true) }.should.raise(TypeError, "no implicit conversion of true into String")
+ end
+
+ it "raises a TypeError if passed a Symbol" do
+ not_supported_on :opal do
+ -> { "abc".send(@method, :a) }.should.raise(TypeError, "no implicit conversion of Symbol into String")
+ end
+ end
+
+ it "raises a TypeError if passed a Symbol" do
+ obj = mock('x')
+ obj.should_not_receive(:to_int)
+ -> { "hello".send(@method, obj) }.should.raise(TypeError, "no implicit conversion of MockObject into String")
+ end
+
+ it "raises a TypeError if passed an Integer" do
+ -> { "abc".send(@method, 97) }.should.raise(TypeError, "no implicit conversion of Integer into String")
+ end
+ end
+
+ describe "with multibyte codepoints" do
+ it "raises an IndexError when byte offset lands in the middle of a multibyte character" do
+ -> { "ã‚".send(@method, "", 1) }.should.raise(IndexError, "offset 1 does not land on character boundary")
+ -> { "ã‚".send(@method, "", 2) }.should.raise(IndexError, "offset 2 does not land on character boundary")
+ -> { "ã‚".send(@method, "", -1) }.should.raise(IndexError, "offset 2 does not land on character boundary")
+ -> { "ã‚".send(@method, "", -2) }.should.raise(IndexError, "offset 1 does not land on character boundary")
+ end
+
+ it "raises an Encoding::CompatibilityError if the encodings are incompatible" do
+ re = Regexp.new "れ".encode(Encoding::EUC_JP)
+ -> do
+ "ã‚れ".send(@method, re)
+ end.should.raise(Encoding::CompatibilityError, "incompatible encoding regexp match (EUC-JP regexp with UTF-8 string)")
+ end
+ end
+
+ describe "with global variables" do
+ it "doesn't set $~ for non regex search" do
+ $~ = nil
+
+ 'hello.'.send(@method, 'll')
+ $~.should == nil
+ end
+
+ it "sets $~ to MatchData of match and nil when there's none" do
+ 'hello.'.send(@method, /.e./)
+ $~[0].should == 'hel'
+
+ 'hello.'.send(@method, /not/)
+ $~.should == nil
+ end
+ end
+end
diff --git a/spec/ruby/core/string/shared/chars.rb b/spec/ruby/core/string/shared/chars.rb
index c1cf324dc5..826d403589 100644
--- a/spec/ruby/core/string/shared/chars.rb
+++ b/spec/ruby/core/string/shared/chars.rb
@@ -1,6 +1,6 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
describe :string_chars, shared: true do
it "passes each char in self to the given block" do
@@ -11,70 +11,76 @@ describe :string_chars, shared: true do
it "returns self" do
s = StringSpecs::MyString.new "hello"
- s.send(@method){}.should equal(s)
+ s.send(@method){}.should.equal?(s)
end
-
it "is unicode aware" do
"\303\207\342\210\202\303\251\306\222g".send(@method).to_a.should ==
["\303\207", "\342\210\202", "\303\251", "\306\222", "g"]
end
- with_feature :encoding do
- it "returns characters in the same encoding as self" do
- "&%".force_encoding('Shift_JIS').send(@method).to_a.all? {|c| c.encoding.name.should == 'Shift_JIS'}
- "&%".encode('ASCII-8BIT').send(@method).to_a.all? {|c| c.encoding.name.should == 'ASCII-8BIT'}
- end
+ it "returns characters in the same encoding as self" do
+ "&%".dup.force_encoding('Shift_JIS').send(@method).to_a.all? {|c| c.encoding.name.should == 'Shift_JIS'}
+ "&%".encode('BINARY').send(@method).to_a.all? {|c| c.encoding.should == Encoding::BINARY }
+ end
- it "works with multibyte characters" do
- s = "\u{8987}".force_encoding("UTF-8")
- s.bytesize.should == 3
- s.send(@method).to_a.should == [s]
- end
+ it "works with multibyte characters" do
+ s = "\u{8987}".dup.force_encoding("UTF-8")
+ s.bytesize.should == 3
+ s.send(@method).to_a.should == [s]
+ end
- it "works if the String's contents is invalid for its encoding" do
- xA4 = [0xA4].pack('C')
- xA4.force_encoding('UTF-8')
- xA4.valid_encoding?.should be_false
- xA4.send(@method).to_a.should == [xA4.force_encoding("UTF-8")]
- end
+ it "works if the String's contents is invalid for its encoding" do
+ xA4 = [0xA4].pack('C')
+ xA4.force_encoding('UTF-8')
+ xA4.valid_encoding?.should == false
+ xA4.send(@method).to_a.should == [xA4.force_encoding("UTF-8")]
+ end
- it "returns a different character if the String is transcoded" do
- s = "\u{20AC}".force_encoding('UTF-8')
- s.encode('UTF-8').send(@method).to_a.should == ["\u{20AC}".force_encoding('UTF-8')]
- s.encode('iso-8859-15').send(@method).to_a.should == [[0xA4].pack('C').force_encoding('iso-8859-15')]
- s.encode('iso-8859-15').encode('UTF-8').send(@method).to_a.should == ["\u{20AC}".force_encoding('UTF-8')]
- end
+ it "returns a different character if the String is transcoded" do
+ s = "\u{20AC}".dup.force_encoding('UTF-8')
+ s.encode('UTF-8').send(@method).to_a.should == ["\u{20AC}".dup.force_encoding('UTF-8')]
+ s.encode('iso-8859-15').send(@method).to_a.should == [[0xA4].pack('C').force_encoding('iso-8859-15')]
+ s.encode('iso-8859-15').encode('UTF-8').send(@method).to_a.should == ["\u{20AC}".dup.force_encoding('UTF-8')]
+ end
- it "uses the String's encoding to determine what characters it contains" do
- s = "\u{24B62}"
+ it "uses the String's encoding to determine what characters it contains" do
+ s = +"\u{24B62}"
- s.force_encoding('UTF-8').send(@method).to_a.should == [
- s.force_encoding('UTF-8')
- ]
- s.force_encoding('BINARY').send(@method).to_a.should == [
- [0xF0].pack('C').force_encoding('BINARY'),
- [0xA4].pack('C').force_encoding('BINARY'),
- [0xAD].pack('C').force_encoding('BINARY'),
- [0xA2].pack('C').force_encoding('BINARY')
- ]
- s.force_encoding('SJIS').send(@method).to_a.should == [
- [0xF0,0xA4].pack('CC').force_encoding('SJIS'),
- [0xAD].pack('C').force_encoding('SJIS'),
- [0xA2].pack('C').force_encoding('SJIS')
- ]
- end
+ s.force_encoding('UTF-8').send(@method).to_a.should == [
+ s.force_encoding('UTF-8')
+ ]
+ s.force_encoding('BINARY').send(@method).to_a.should == [
+ [0xF0].pack('C').force_encoding('BINARY'),
+ [0xA4].pack('C').force_encoding('BINARY'),
+ [0xAD].pack('C').force_encoding('BINARY'),
+ [0xA2].pack('C').force_encoding('BINARY')
+ ]
+ s.force_encoding('SJIS').send(@method).to_a.should == [
+ [0xF0,0xA4].pack('CC').force_encoding('SJIS'),
+ [0xAD].pack('C').force_encoding('SJIS'),
+ [0xA2].pack('C').force_encoding('SJIS')
+ ]
+ end
- it "taints resulting strings when self is tainted" do
- str = "hello"
+ it "returns individual chars for dummy encodings" do
+ "ab".dup.force_encoding(Encoding::UTF_7).send(@method).to_a.should == [
+ "\x61".dup.force_encoding(Encoding::UTF_7),
+ "\x62".dup.force_encoding(Encoding::UTF_7)
+ ]
- str.send(@method) do |x|
- x.tainted?.should == false
- end
+ "abcd".dup.force_encoding(Encoding::UTF_16).send(@method).to_a.should == [
+ "\x61".dup.force_encoding(Encoding::UTF_16),
+ "\x62".dup.force_encoding(Encoding::UTF_16),
+ "\x63".dup.force_encoding(Encoding::UTF_16),
+ "\x64".dup.force_encoding(Encoding::UTF_16)
+ ]
- str.dup.taint.send(@method) do |x|
- x.tainted?.should == true
- end
- end
+ "abcd".dup.force_encoding(Encoding::UTF_32).send(@method).to_a.should == [
+ "\x61".dup.force_encoding(Encoding::UTF_32),
+ "\x62".dup.force_encoding(Encoding::UTF_32),
+ "\x63".dup.force_encoding(Encoding::UTF_32),
+ "\x64".dup.force_encoding(Encoding::UTF_32)
+ ]
end
end
diff --git a/spec/ruby/core/string/shared/codepoints.rb b/spec/ruby/core/string/shared/codepoints.rb
index 68f82b4468..b6abf6a3ff 100644
--- a/spec/ruby/core/string/shared/codepoints.rb
+++ b/spec/ruby/core/string/shared/codepoints.rb
@@ -1,9 +1,15 @@
-# -*- encoding: binary -*-
+# encoding: binary
describe :string_codepoints, shared: true do
+ it "returns self" do
+ s = "foo"
+ result = s.send(@method) {}
+ result.should.equal? s
+ end
+
it "raises an ArgumentError when self has an invalid encoding and a method is called on the returned Enumerator" do
- s = "\xDF".force_encoding(Encoding::UTF_8)
- s.valid_encoding?.should be_false
- lambda { s.send(@method).to_a }.should raise_error(ArgumentError)
+ s = "\xDF".dup.force_encoding(Encoding::UTF_8)
+ s.valid_encoding?.should == false
+ -> { s.send(@method).to_a }.should.raise(ArgumentError)
end
it "yields each codepoint to the block if one is given" do
@@ -15,18 +21,18 @@ describe :string_codepoints, shared: true do
end
it "raises an ArgumentError if self's encoding is invalid and a block is given" do
- s = "\xDF".force_encoding(Encoding::UTF_8)
- s.valid_encoding?.should be_false
- lambda { s.send(@method) { } }.should raise_error(ArgumentError)
+ s = "\xDF".dup.force_encoding(Encoding::UTF_8)
+ s.valid_encoding?.should == false
+ -> { s.send(@method) { } }.should.raise(ArgumentError)
end
- it "returns codepoints as Fixnums" do
+ it "yields codepoints as Integers" do
"glark\u{20}".send(@method).to_a.each do |codepoint|
- codepoint.should be_an_instance_of(Fixnum)
+ codepoint.should.instance_of?(Integer)
end
end
- it "returns one codepoint for each character" do
+ it "yields one codepoint for each character" do
s = "\u{9876}\u{28}\u{1987}"
s.send(@method).to_a.size.should == s.chars.to_a.size
end
@@ -37,20 +43,25 @@ describe :string_codepoints, shared: true do
s.send(@method).to_a.should == [38937]
end
- it "returns the codepoint corresponding to the character's position in the String's encoding" do
+ it "yields the codepoints corresponding to the character's position in the String's encoding" do
"\u{787}".send(@method).to_a.should == [1927]
end
it "round-trips to the original String using Integer#chr" do
s = "\u{13}\u{7711}\u{1010}"
- s2 = ""
+ s2 = +""
s.send(@method) {|n| s2 << n.chr(Encoding::UTF_8)}
s.should == s2
end
- it "is synonymous with #bytes for Strings which are single-byte optimisable" do
+ it "is synonymous with #bytes for Strings which are single-byte optimizable" do
s = "(){}".encode('ascii')
- s.ascii_only?.should be_true
+ s.ascii_only?.should == true
s.send(@method).to_a.should == s.bytes.to_a
end
+
+ it "returns individual bytes for dummy encodings UTF-16 and UTF-32" do
+ "abcd".dup.force_encoding(Encoding::UTF_16).send(@method).to_a.should == [97, 98, 99, 100]
+ "abcd".dup.force_encoding(Encoding::UTF_32).send(@method).to_a.should == [97, 98, 99, 100]
+ end
end
diff --git a/spec/ruby/core/string/shared/concat.rb b/spec/ruby/core/string/shared/concat.rb
index 7da995fdc7..60cd0e12d4 100644
--- a/spec/ruby/core/string/shared/concat.rb
+++ b/spec/ruby/core/string/shared/concat.rb
@@ -1,56 +1,35 @@
+# frozen_string_literal: false
describe :string_concat, shared: true do
it "concatenates the given argument to self and returns self" do
str = 'hello '
- str.send(@method, 'world').should equal(str)
+ str.send(@method, 'world').should.equal?(str)
str.should == "hello world"
end
- it "converts the given argument to a String using to_str" do
- obj = mock('world!')
- obj.should_receive(:to_str).and_return("world!")
- a = 'hello '.send(@method, obj)
- a.should == 'hello world!'
- end
-
- it "raises a TypeError if the given argument can't be converted to a String" do
- lambda { 'hello '.send(@method, []) }.should raise_error(TypeError)
- lambda { 'hello '.send(@method, mock('x')) }.should raise_error(TypeError)
- end
-
- it "raises a RuntimeError when self is frozen" do
+ it "raises a FrozenError when self is frozen" do
a = "hello"
a.freeze
- lambda { a.send(@method, "") }.should raise_error(RuntimeError)
- lambda { a.send(@method, "test") }.should raise_error(RuntimeError)
+ -> { a.send(@method, "") }.should.raise(FrozenError)
+ -> { a.send(@method, "test") }.should.raise(FrozenError)
end
it "returns a String when given a subclass instance" do
a = "hello"
a.send(@method, StringSpecs::MyString.new(" world"))
a.should == "hello world"
- a.should be_an_instance_of(String)
+ a.should.instance_of?(String)
end
it "returns an instance of same class when called on a subclass" do
str = StringSpecs::MyString.new("hello")
str.send(@method, " world")
str.should == "hello world"
- str.should be_an_instance_of(StringSpecs::MyString)
- end
-
- it "taints self if other is tainted" do
- "x".send(@method, "".taint).tainted?.should == true
- "x".send(@method, "y".taint).tainted?.should == true
- end
-
- it "untrusts self if other is untrusted" do
- "x".send(@method, "".untrust).untrusted?.should == true
- "x".send(@method, "y".untrust).untrusted?.should == true
+ str.should.instance_of?(StringSpecs::MyString)
end
describe "with Integer" do
- it "concatencates the argument interpreted as a codepoint" do
+ it "concatenates the argument interpreted as a codepoint" do
b = "".send(@method, 33)
b.should == "!"
@@ -60,39 +39,39 @@ describe :string_concat, shared: true do
end
# #5855
- it "returns a ASCII-8BIT string if self is US-ASCII and the argument is between 128-255 (inclusive)" do
+ it "returns a BINARY string if self is US-ASCII and the argument is between 128-255 (inclusive)" do
a = ("".encode(Encoding::US_ASCII).send(@method, 128))
- a.encoding.should == Encoding::ASCII_8BIT
+ a.encoding.should == Encoding::BINARY
a.should == 128.chr
a = ("".encode(Encoding::US_ASCII).send(@method, 255))
- a.encoding.should == Encoding::ASCII_8BIT
+ a.encoding.should == Encoding::BINARY
a.should == 255.chr
end
it "raises RangeError if the argument is an invalid codepoint for self's encoding" do
- lambda { "".encode(Encoding::US_ASCII).send(@method, 256) }.should raise_error(RangeError)
- lambda { "".encode(Encoding::EUC_JP).send(@method, 0x81) }.should raise_error(RangeError)
+ -> { "".encode(Encoding::US_ASCII).send(@method, 256) }.should.raise(RangeError)
+ -> { "".encode(Encoding::EUC_JP).send(@method, 0x81) }.should.raise(RangeError)
end
it "raises RangeError if the argument is negative" do
- lambda { "".send(@method, -200) }.should raise_error(RangeError)
- lambda { "".send(@method, -bignum_value) }.should raise_error(RangeError)
+ -> { "".send(@method, -200) }.should.raise(RangeError)
+ -> { "".send(@method, -bignum_value) }.should.raise(RangeError)
end
it "doesn't call to_int on its argument" do
x = mock('x')
x.should_not_receive(:to_int)
- lambda { "".send(@method, x) }.should raise_error(TypeError)
+ -> { "".send(@method, x) }.should.raise(TypeError)
end
- it "raises a RuntimeError when self is frozen" do
+ it "raises a FrozenError when self is frozen" do
a = "hello"
a.freeze
- lambda { a.send(@method, 0) }.should raise_error(RuntimeError)
- lambda { a.send(@method, 33) }.should raise_error(RuntimeError)
+ -> { a.send(@method, 0) }.should.raise(FrozenError)
+ -> { a.send(@method, 33) }.should.raise(FrozenError)
end
end
end
@@ -112,7 +91,7 @@ describe :string_concat_encoding, shared: true do
end
it "raises Encoding::CompatibilityError if neither are empty" do
- lambda { "x".encode("UTF-16LE").send(@method, "y".encode("UTF-8")) }.should raise_error(Encoding::CompatibilityError)
+ -> { "x".encode("UTF-16LE").send(@method, "y".encode("UTF-8")) }.should.raise(Encoding::CompatibilityError)
end
end
@@ -130,7 +109,7 @@ describe :string_concat_encoding, shared: true do
end
it "raises Encoding::CompatibilityError if neither are empty" do
- lambda { "x".encode("UTF-8").send(@method, "y".encode("UTF-16LE")) }.should raise_error(Encoding::CompatibilityError)
+ -> { "x".encode("UTF-8").send(@method, "y".encode("UTF-16LE")) }.should.raise(Encoding::CompatibilityError)
end
end
@@ -148,13 +127,33 @@ describe :string_concat_encoding, shared: true do
end
it "raises Encoding::CompatibilityError if neither are ASCII-only" do
- lambda { "\u00E9".encode("UTF-8").send(@method, "\u00E9".encode("ISO-8859-1")) }.should raise_error(Encoding::CompatibilityError)
+ -> { "\u00E9".encode("UTF-8").send(@method, "\u00E9".encode("ISO-8859-1")) }.should.raise(Encoding::CompatibilityError)
end
end
- describe "when self is ASCII-8BIT and argument is US-ASCII" do
- it "uses ASCII-8BIT encoding" do
- "abc".encode("ASCII-8BIT").send(@method, "123".encode("US-ASCII")).encoding.should == Encoding::ASCII_8BIT
+ describe "when self is BINARY and argument is US-ASCII" do
+ it "uses BINARY encoding" do
+ "abc".encode("BINARY").send(@method, "123".encode("US-ASCII")).encoding.should == Encoding::BINARY
end
end
end
+
+describe :string_concat_type_coercion, shared: true do
+ it "converts the given argument to a String using to_str" do
+ obj = mock('world!')
+ obj.should_receive(:to_str).and_return("world!")
+ a = 'hello '.send(@method, obj)
+ a.should == 'hello world!'
+ end
+
+ it "raises a TypeError if the given argument can't be converted to a String" do
+ -> { 'hello '.send(@method, []) }.should.raise(TypeError)
+ -> { 'hello '.send(@method, mock('x')) }.should.raise(TypeError)
+ end
+
+ it "raises a NoMethodError if the given argument raises a NoMethodError during type coercion to a String" do
+ obj = mock('world!')
+ obj.should_receive(:to_str).and_raise(NoMethodError)
+ -> { 'hello '.send(@method, obj) }.should.raise(NoMethodError)
+ end
+end
diff --git a/spec/ruby/core/string/shared/each_char_without_block.rb b/spec/ruby/core/string/shared/each_char_without_block.rb
index 40808cfd9f..3c32bae42b 100644
--- a/spec/ruby/core/string/shared/each_char_without_block.rb
+++ b/spec/ruby/core/string/shared/each_char_without_block.rb
@@ -1,12 +1,12 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
describe :string_each_char_without_block, shared: true do
describe "when no block is given" do
it "returns an enumerator" do
enum = "hello".send(@method)
- enum.should be_an_instance_of(Enumerator)
+ enum.should.instance_of?(Enumerator)
enum.to_a.should == ['h', 'e', 'l', 'l', 'o']
end
diff --git a/spec/ruby/core/string/shared/each_codepoint_without_block.rb b/spec/ruby/core/string/shared/each_codepoint_without_block.rb
deleted file mode 100644
index 92b7f76032..0000000000
--- a/spec/ruby/core/string/shared/each_codepoint_without_block.rb
+++ /dev/null
@@ -1,33 +0,0 @@
-# -*- encoding: binary -*-
-describe :string_each_codepoint_without_block, shared: true do
- describe "when no block is given" do
- it "returns an Enumerator" do
- "".send(@method).should be_an_instance_of(Enumerator)
- end
-
- it "returns an Enumerator even when self has an invalid encoding" do
- s = "\xDF".force_encoding(Encoding::UTF_8)
- s.valid_encoding?.should be_false
- s.send(@method).should be_an_instance_of(Enumerator)
- end
-
- describe "returned Enumerator" do
- describe "size" do
- it "should return the size of the string" do
- str = "hello"
- str.send(@method).size.should == str.size
- str = "ola"
- str.send(@method).size.should == str.size
- str = "\303\207\342\210\202\303\251\306\222g"
- str.send(@method).size.should == str.size
- end
-
- it "should return the size of the string even when the string has an invalid encoding" do
- s = "\xDF".force_encoding(Encoding::UTF_8)
- s.valid_encoding?.should be_false
- s.send(@method).size.should == 1
- end
- end
- end
- end
-end
diff --git a/spec/ruby/core/string/shared/each_line.rb b/spec/ruby/core/string/shared/each_line.rb
index dee741e270..127db876ad 100644
--- a/spec/ruby/core/string/shared/each_line.rb
+++ b/spec/ruby/core/string/shared/each_line.rb
@@ -27,10 +27,17 @@ describe :string_each_line, shared: true do
c.should == ["hello\n", "\n", "\n", "world"]
end
- it "taints substrings that are passed to the block if self is tainted" do
- "one\ntwo\r\nthree".taint.send(@method) { |s| s.tainted?.should == true }
+ it "splits strings containing multibyte characters" do
+ s = <<~EOS
+ foo
+ 🤡🤡🤡🤡🤡🤡🤡
+ bar
+ baz
+ EOS
- "x.y.".send(@method, ".".taint) { |s| s.tainted?.should == false }
+ b = []
+ s.send(@method) { |part| b << part }
+ b.should == ["foo\n", "🤡🤡🤡🤡🤡🤡🤡\n", "bar\n", "baz\n"]
end
it "passes self as a whole to the block if the separator is nil" do
@@ -39,31 +46,37 @@ describe :string_each_line, shared: true do
a.should == ["one\ntwo\r\nthree"]
end
- ruby_version_is ''...'2.5' do
- it "yields paragraphs (broken by 2 or more successive newlines) when passed ''" do
+ context "when passed '' (paragraph mode, broken by 2 or more successive newlines)" do
+ it "replaces multiple newlines with only two ones" do
a = []
"hello\nworld\n\n\nand\nuniverse\n\n\n\n\n".send(@method, '') { |s| a << s }
- a.should == ["hello\nworld\n\n\n", "and\nuniverse\n\n\n\n\n"]
+ a.should == ["hello\nworld\n\n", "and\nuniverse\n\n"]
a = []
"hello\nworld\n\n\nand\nuniverse\n\n\n\n\ndog".send(@method, '') { |s| a << s }
- a.should == ["hello\nworld\n\n\n", "and\nuniverse\n\n\n\n\n", "dog"]
+ a.should == ["hello\nworld\n\n", "and\nuniverse\n\n", "dog"]
end
- end
-quarantine! do # Currently fails on Travis
- ruby_version_is '2.5' do
- it "yields paragraphs (broken by 2 or more successive newlines) when passed ''" do
+ it 'handles \r\n-style newlines' do
a = []
- "hello\nworld\n\n\nand\nuniverse\n\n\n\n\n".send(@method, '') { |s| a << s }
- a.should == ["hello\nworld\n\n", "and\nuniverse\n\n"]
+ "hello\nworld\r\n\r\n\nand\nuniverse\n\r\n\n\n\n".send(@method, '') { |s| a << s }
+ a.should == ["hello\nworld\r\n\r\n", "and\nuniverse\n\r\n"]
a = []
- "hello\nworld\n\n\nand\nuniverse\n\n\n\n\ndog".send(@method, '') { |s| a << s }
- a.should == ["hello\nworld\n\n", "and\nuniverse\n\n", "dog"]
+ "hello\r\nworld\n\n\nand\nuniverse\n\n\n\r\n\r\ndog".send(@method, '') { |s| a << s }
+ a.should == ["hello\r\nworld\n\n", "and\nuniverse\n\n", "dog"]
+ end
+
+ it "removes trailing newlines with `chomp: true`" do
+ a = []
+ "hello\nworld\n\n\nand\nuniverse\n\n\n\n\n".send(@method, '', chomp: true) { |s| a << s }
+ a.should == ["hello\nworld", "and\nuniverse"]
+
+ a = []
+ "hello\nworld\n\n\nand\nuniverse\n\n\n\n\ndog".send(@method, '', chomp: true) { |s| a << s }
+ a.should == ["hello\nworld", "and\nuniverse", "dog"]
end
end
-end
describe "uses $/" do
before :each do
@@ -71,7 +84,7 @@ end
end
after :each do
- $/ = @before_separator
+ suppress_warning {$/ = @before_separator}
end
it "as the separator when none is given" do
@@ -83,10 +96,10 @@ end
expected = []
str.send(@method, sep) { |x| expected << x }
- $/ = sep
+ suppress_warning {$/ = sep}
actual = []
- str.send(@method) { |x| actual << x }
+ suppress_warning {str.send(@method) { |x| actual << x }}
actual.should == expected
end
@@ -94,15 +107,15 @@ end
end
end
- it "yields subclass instances for subclasses" do
+ it "yields String instances for subclasses" do
a = []
StringSpecs::MyString.new("hello\nworld").send(@method) { |s| a << s.class }
- a.should == [StringSpecs::MyString, StringSpecs::MyString]
+ a.should == [String, String]
end
it "returns self" do
s = "hello\nworld"
- (s.send(@method) {}).should equal(s)
+ (s.send(@method) {}).should.equal?(s)
end
it "tries to convert the separator to a string using to_str" do
@@ -115,15 +128,21 @@ end
end
it "does not care if the string is modified while substituting" do
- str = "hello\nworld."
+ str = +"hello\nworld."
out = []
str.send(@method){|x| out << x; str[-1] = '!' }.should == "hello\nworld!"
out.should == ["hello\n", "world."]
end
+ it "returns Strings in the same encoding as self" do
+ "one\ntwo\r\nthree".encode("US-ASCII").send(@method) do |s|
+ s.encoding.should == Encoding::US_ASCII
+ end
+ end
+
it "raises a TypeError when the separator can't be converted to a string" do
- lambda { "hello world".send(@method, false) {} }.should raise_error(TypeError)
- lambda { "hello world".send(@method, mock('x')) {} }.should raise_error(TypeError)
+ -> { "hello world".send(@method, false) {} }.should.raise(TypeError)
+ -> { "hello world".send(@method, mock('x')) {} }.should.raise(TypeError)
end
it "accepts a string separator" do
@@ -131,20 +150,49 @@ end
end
it "raises a TypeError when the separator is a symbol" do
- lambda { "hello world".send(@method, :o).to_a }.should raise_error(TypeError)
+ -> { "hello world".send(@method, :o).to_a }.should.raise(TypeError)
end
- ruby_version_is '2.4' do
- context "when `chomp` keyword argument is passed" do
- it "removes new line characters" do
- a = []
- "hello \nworld\n".send(@method, chomp: true) { |s| a << s }
- a.should == ["hello ", "world"]
+ context "when `chomp` keyword argument is passed" do
+ it "removes new line characters when separator is not specified" do
+ a = []
+ "hello \nworld\n".send(@method, chomp: true) { |s| a << s }
+ a.should == ["hello ", "world"]
- a = []
- "hello \r\nworld\r\n".send(@method, chomp: true) { |s| a << s }
- a.should == ["hello ", "world"]
- end
+ a = []
+ "hello \r\nworld\r\n".send(@method, chomp: true) { |s| a << s }
+ a.should == ["hello ", "world"]
+ end
+
+ it "removes only specified separator" do
+ a = []
+ "hello world".send(@method, ' ', chomp: true) { |s| a << s }
+ a.should == ["hello", "world"]
+ end
+
+ # https://bugs.ruby-lang.org/issues/14257
+ it "ignores new line characters when separator is specified" do
+ a = []
+ "hello\n world\n".send(@method, ' ', chomp: true) { |s| a << s }
+ a.should == ["hello\n", "world\n"]
+
+ a = []
+ "hello\r\n world\r\n".send(@method, ' ', chomp: true) { |s| a << s }
+ a.should == ["hello\r\n", "world\r\n"]
end
end
+
+ it "does not split lines for dummy UTF-16" do
+ "a\nb".encode(Encoding::UTF_16).lines.should == [
+ "\xFE\xFF\x00\x61\x00\n\x00\x62".dup.force_encoding(Encoding::UTF_16)
+ ]
+
+ str = "\x00\n\n\x00".dup.force_encoding(Encoding::UTF_16)
+ str.lines.should == [str]
+ end
+
+ it "raises Encoding::ConverterNotFoundError for dummy UTF-7" do
+ str = "a\nb".dup.force_encoding(Encoding::UTF_7)
+ -> { str.lines }.should.raise(Encoding::ConverterNotFoundError)
+ end
end
diff --git a/spec/ruby/core/string/shared/each_line_without_block.rb b/spec/ruby/core/string/shared/each_line_without_block.rb
index 8e08b0390c..af0ab69c00 100644
--- a/spec/ruby/core/string/shared/each_line_without_block.rb
+++ b/spec/ruby/core/string/shared/each_line_without_block.rb
@@ -2,7 +2,7 @@ describe :string_each_line_without_block, shared: true do
describe "when no block is given" do
it "returns an enumerator" do
enum = "hello world".send(@method, ' ')
- enum.should be_an_instance_of(Enumerator)
+ enum.should.instance_of?(Enumerator)
enum.to_a.should == ["hello ", "world"]
end
diff --git a/spec/ruby/core/string/shared/encode.rb b/spec/ruby/core/string/shared/encode.rb
index 71d46b1bd3..7f644c26d9 100644
--- a/spec/ruby/core/string/shared/encode.rb
+++ b/spec/ruby/core/string/shared/encode.rb
@@ -1,4 +1,5 @@
# -*- encoding: utf-8 -*-
+# frozen_string_literal: false
describe :string_encode, shared: true do
describe "when passed no options" do
it "transcodes to Encoding.default_internal when set" do
@@ -8,20 +9,20 @@ describe :string_encode, shared: true do
end
it "transcodes a 7-bit String despite no generic converting being available" do
- lambda do
- Encoding::Converter.new Encoding::Emacs_Mule, Encoding::ASCII_8BIT
- end.should raise_error(Encoding::ConverterNotFoundError)
+ -> do
+ Encoding::Converter.new Encoding::Emacs_Mule, Encoding::BINARY
+ end.should.raise(Encoding::ConverterNotFoundError)
Encoding.default_internal = Encoding::Emacs_Mule
- str = "\x79".force_encoding Encoding::ASCII_8BIT
+ str = "\x79".force_encoding Encoding::BINARY
- str.send(@method).should == "y".force_encoding(Encoding::ASCII_8BIT)
+ str.send(@method).should == "y".force_encoding(Encoding::BINARY)
end
it "raises an Encoding::ConverterNotFoundError when no conversion is possible" do
Encoding.default_internal = Encoding::Emacs_Mule
- str = [0x80].pack('C').force_encoding Encoding::ASCII_8BIT
- lambda { str.send(@method) }.should raise_error(Encoding::ConverterNotFoundError)
+ str = [0x80].pack('C').force_encoding Encoding::BINARY
+ -> { str.send(@method) }.should.raise(Encoding::ConverterNotFoundError)
end
end
@@ -51,25 +52,33 @@ describe :string_encode, shared: true do
end
it "transcodes a 7-bit String despite no generic converting being available" do
- lambda do
- Encoding::Converter.new Encoding::Emacs_Mule, Encoding::ASCII_8BIT
- end.should raise_error(Encoding::ConverterNotFoundError)
+ -> do
+ Encoding::Converter.new Encoding::Emacs_Mule, Encoding::BINARY
+ end.should.raise(Encoding::ConverterNotFoundError)
- str = "\x79".force_encoding Encoding::ASCII_8BIT
- str.send(@method, Encoding::Emacs_Mule).should == "y".force_encoding(Encoding::ASCII_8BIT)
+ str = "\x79".force_encoding Encoding::BINARY
+ str.send(@method, Encoding::Emacs_Mule).should == "y".force_encoding(Encoding::BINARY)
end
it "raises an Encoding::ConverterNotFoundError when no conversion is possible" do
- str = [0x80].pack('C').force_encoding Encoding::ASCII_8BIT
- lambda do
+ str = [0x80].pack('C').force_encoding Encoding::BINARY
+ -> do
str.send(@method, Encoding::Emacs_Mule)
- end.should raise_error(Encoding::ConverterNotFoundError)
+ end.should.raise(Encoding::ConverterNotFoundError)
end
it "raises an Encoding::ConverterNotFoundError for an invalid encoding" do
- lambda do
+ -> do
"abc".send(@method, "xyz")
- end.should raise_error(Encoding::ConverterNotFoundError)
+ end.should.raise(Encoding::ConverterNotFoundError)
+ end
+
+ it "raises an Encoding::UndefinedConversionError when a character cannot be represented in the destination encoding" do
+ # U+0100 (Ä€) is valid UTF-8 but not representable in windows-1252
+ str = "test\u0100".force_encoding('utf-8')
+ -> {
+ str.send(@method, Encoding::Windows_1252)
+ }.should.raise(Encoding::UndefinedConversionError)
end
end
@@ -83,7 +92,7 @@ describe :string_encode, shared: true do
options = mock("string encode options")
options.should_receive(:to_hash).and_return({ undef: :replace })
- result = "ã‚\ufffdã‚".send(@method, options)
+ result = "ã‚\ufffdã‚".send(@method, **options)
result.should == "ã‚\ufffdã‚"
end
@@ -95,10 +104,10 @@ describe :string_encode, shared: true do
it "raises an Encoding::ConverterNotFoundError when no conversion is possible despite 'invalid: :replace, undef: :replace'" do
Encoding.default_internal = Encoding::Emacs_Mule
- str = [0x80].pack('C').force_encoding Encoding::ASCII_8BIT
- lambda do
+ str = [0x80].pack('C').force_encoding Encoding::BINARY
+ -> do
str.send(@method, invalid: :replace, undef: :replace)
- end.should raise_error(Encoding::ConverterNotFoundError)
+ end.should.raise(Encoding::ConverterNotFoundError)
end
it "replaces invalid characters when replacing Emacs-Mule encoded strings" do
@@ -141,11 +150,19 @@ describe :string_encode, shared: true do
"ab#{xFF}c".send(@method, Encoding::ISO_8859_1, invalid: :replace).should == "ab?c"
end
+ it "raises UndefinedConversionError for characters not representable in destination encoding with only invalid: :replace" do
+ # U+0100 (Ä€) is valid UTF-8 but not representable in windows-1252
+ str = "test\u0100".force_encoding('utf-8')
+ -> {
+ str.send(@method, Encoding::Windows_1252, invalid: :replace, replace: "")
+ }.should.raise(Encoding::UndefinedConversionError)
+ end
+
it "calls #to_hash to convert the options object" do
options = mock("string encode options")
options.should_receive(:to_hash).and_return({ undef: :replace })
- result = "ã‚?ã‚".send(@method, Encoding::EUC_JP, options)
+ result = "ã‚?ã‚".send(@method, Encoding::EUC_JP, **options)
xA4xA2 = [0xA4, 0xA2].pack('CC').force_encoding('utf-8')
result.should == "#{xA4xA2}?#{xA4xA2}".force_encoding("euc-jp")
end
@@ -153,7 +170,7 @@ describe :string_encode, shared: true do
describe "when passed to, from, options" do
it "replaces undefined characters in the destination encoding" do
- str = "ã‚?ã‚".force_encoding Encoding::ASCII_8BIT
+ str = "ã‚?ã‚".force_encoding Encoding::BINARY
result = str.send(@method, "euc-jp", "utf-8", undef: :replace)
xA4xA2 = [0xA4, 0xA2].pack('CC').force_encoding('utf-8')
result.should == "#{xA4xA2}?#{xA4xA2}".force_encoding("euc-jp")
@@ -161,7 +178,7 @@ describe :string_encode, shared: true do
it "replaces invalid characters in the destination encoding" do
xFF = [0xFF].pack('C').force_encoding('utf-8')
- str = "ab#{xFF}c".force_encoding Encoding::ASCII_8BIT
+ str = "ab#{xFF}c".force_encoding Encoding::BINARY
str.send(@method, "iso-8859-1", "utf-8", invalid: :replace).should == "ab?c"
end
@@ -170,7 +187,7 @@ describe :string_encode, shared: true do
to.should_receive(:to_str).and_return("iso-8859-1")
xFF = [0xFF].pack('C').force_encoding('utf-8')
- str = "ab#{xFF}c".force_encoding Encoding::ASCII_8BIT
+ str = "ab#{xFF}c".force_encoding Encoding::BINARY
str.send(@method, to, "utf-8", invalid: :replace).should == "ab?c"
end
@@ -179,7 +196,7 @@ describe :string_encode, shared: true do
from.should_receive(:to_str).and_return("utf-8")
xFF = [0xFF].pack('C').force_encoding('utf-8')
- str = "ab#{xFF}c".force_encoding Encoding::ASCII_8BIT
+ str = "ab#{xFF}c".force_encoding Encoding::BINARY
str.send(@method, "iso-8859-1", from, invalid: :replace).should == "ab?c"
end
@@ -188,8 +205,192 @@ describe :string_encode, shared: true do
options.should_receive(:to_hash).and_return({ invalid: :replace })
xFF = [0xFF].pack('C').force_encoding('utf-8')
- str = "ab#{xFF}c".force_encoding Encoding::ASCII_8BIT
- str.send(@method, "iso-8859-1", "utf-8", options).should == "ab?c"
+ str = "ab#{xFF}c".force_encoding Encoding::BINARY
+ str.send(@method, "iso-8859-1", "utf-8", **options).should == "ab?c"
+ end
+ end
+
+ describe "given the fallback option" do
+ context "given a hash" do
+ it "looks up the replacement value from the hash" do
+ encoded = "B\ufffd".encode(Encoding::US_ASCII, fallback: { "\ufffd" => "bar" })
+ encoded.should == "Bbar"
+ end
+
+ it "calls to_str on the returned value" do
+ obj = Object.new
+ obj.should_receive(:to_str).and_return("bar")
+ encoded = "B\ufffd".encode(Encoding::US_ASCII, fallback: { "\ufffd" => obj })
+ encoded.should == "Bbar"
+ end
+
+ it "does not call to_s on the returned value" do
+ obj = Object.new
+ obj.should_not_receive(:to_s)
+ -> {
+ "B\ufffd".encode(Encoding::US_ASCII, fallback: { "\ufffd" => obj })
+ }.should.raise(TypeError, "no implicit conversion of Object into String")
+ end
+
+ it "raises an error if the key is not present in the hash" do
+ -> {
+ "B\ufffd".encode(Encoding::US_ASCII, fallback: { "foo" => "bar" })
+ }.should.raise(Encoding::UndefinedConversionError, "U+FFFD from UTF-8 to US-ASCII")
+ end
+
+ it "raises an error if the value is itself invalid" do
+ -> {
+ "B\ufffd".encode(Encoding::US_ASCII, fallback: { "\ufffd" => "\uffee" })
+ }.should.raise(ArgumentError, "too big fallback string")
+ end
+
+ it "uses the hash's default value if set" do
+ hash = {}
+ hash.default = "bar"
+ encoded = "B\ufffd".encode(Encoding::US_ASCII, fallback: hash)
+ encoded.should == "Bbar"
+ end
+
+ it "uses the result of calling default_proc if set" do
+ hash = {}
+ hash.default_proc = -> _, _ { "bar" }
+ encoded = "B\ufffd".encode(Encoding::US_ASCII, fallback: hash)
+ encoded.should == "Bbar"
+ end
+ end
+
+ context "given an object inheriting from Hash" do
+ before do
+ klass = Class.new(Hash)
+ @hash_like = klass.new
+ @hash_like["\ufffd"] = "bar"
+ end
+
+ it "looks up the replacement value from the object" do
+ encoded = "B\ufffd".encode(Encoding::US_ASCII, fallback: @hash_like)
+ encoded.should == "Bbar"
+ end
+ end
+
+ context "given an object responding to []" do
+ before do
+ klass = Class.new do
+ def [](c) = c.bytes.inspect
+ end
+ @hash_like = klass.new
+ end
+
+ it "calls [] on the object, passing the invalid character" do
+ encoded = "B\ufffd".encode(Encoding::US_ASCII, fallback: @hash_like)
+ encoded.should == "B[239, 191, 189]"
+ end
+ end
+
+ context "given an object not responding to []" do
+ before do
+ @non_hash_like = Object.new
+ end
+
+ it "raises an error" do
+ -> {
+ "B\ufffd".encode(Encoding::US_ASCII, fallback: @non_hash_like)
+ }.should.raise(Encoding::UndefinedConversionError, "U+FFFD from UTF-8 to US-ASCII")
+ end
+ end
+
+ context "given a proc" do
+ it "calls the proc to get the replacement value, passing in the invalid character" do
+ encoded = "B\ufffd".encode(Encoding::US_ASCII, fallback: proc { |c| c.bytes.inspect })
+ encoded.should == "B[239, 191, 189]"
+ end
+
+ it "calls to_str on the returned value" do
+ obj = Object.new
+ obj.should_receive(:to_str).and_return("bar")
+ encoded = "B\ufffd".encode(Encoding::US_ASCII, fallback: proc { |c| obj })
+ encoded.should == "Bbar"
+ end
+
+ it "does not call to_s on the returned value" do
+ obj = Object.new
+ obj.should_not_receive(:to_s)
+ -> {
+ "B\ufffd".encode(Encoding::US_ASCII, fallback: proc { |c| obj })
+ }.should.raise(TypeError, "no implicit conversion of Object into String")
+ end
+
+ it "raises an error if the returned value is itself invalid" do
+ -> {
+ "B\ufffd".encode(Encoding::US_ASCII, fallback: -> c { "\uffee" })
+ }.should.raise(ArgumentError, "too big fallback string")
+ end
+ end
+
+ context "given a lambda" do
+ it "calls the lambda to get the replacement value, passing in the invalid character" do
+ encoded = "B\ufffd".encode(Encoding::US_ASCII, fallback: -> c { c.bytes.inspect })
+ encoded.should == "B[239, 191, 189]"
+ end
+
+ it "calls to_str on the returned value" do
+ obj = Object.new
+ obj.should_receive(:to_str).and_return("bar")
+ encoded = "B\ufffd".encode(Encoding::US_ASCII, fallback: -> c { obj })
+ encoded.should == "Bbar"
+ end
+
+ it "does not call to_s on the returned value" do
+ obj = Object.new
+ obj.should_not_receive(:to_s)
+ -> {
+ "B\ufffd".encode(Encoding::US_ASCII, fallback: -> c { obj })
+ }.should.raise(TypeError, "no implicit conversion of Object into String")
+ end
+
+ it "raises an error if the returned value is itself invalid" do
+ -> {
+ "B\ufffd".encode(Encoding::US_ASCII, fallback: -> c { "\uffee" })
+ }.should.raise(ArgumentError, "too big fallback string")
+ end
+ end
+
+ context "given a method" do
+ def replace(c) = c.bytes.inspect
+ def replace_bad(c) = "\uffee"
+
+ def replace_to_str(c)
+ obj = Object.new
+ obj.should_receive(:to_str).and_return("bar")
+ obj
+ end
+
+ def replace_to_s(c)
+ obj = Object.new
+ obj.should_not_receive(:to_s)
+ obj
+ end
+
+ it "calls the method to get the replacement value, passing in the invalid character" do
+ encoded = "B\ufffd".encode(Encoding::US_ASCII, fallback: method(:replace))
+ encoded.should == "B[239, 191, 189]"
+ end
+
+ it "calls to_str on the returned value" do
+ encoded = "B\ufffd".encode(Encoding::US_ASCII, fallback: method(:replace_to_str))
+ encoded.should == "Bbar"
+ end
+
+ it "does not call to_s on the returned value" do
+ -> {
+ "B\ufffd".encode(Encoding::US_ASCII, fallback: method(:replace_to_s))
+ }.should.raise(TypeError, "no implicit conversion of Object into String")
+ end
+
+ it "raises an error if the returned value is itself invalid" do
+ -> {
+ "B\ufffd".encode(Encoding::US_ASCII, fallback: method(:replace_bad))
+ }.should.raise(ArgumentError, "too big fallback string")
+ end
end
end
@@ -242,6 +443,6 @@ describe :string_encode, shared: true do
end
it "raises ArgumentError if the value of the :xml option is not :text or :attr" do
- lambda { ''.send(@method, "UTF-8", xml: :other) }.should raise_error(ArgumentError)
+ -> { ''.send(@method, "UTF-8", xml: :other) }.should.raise(ArgumentError)
end
end
diff --git a/spec/ruby/core/string/shared/eql.rb b/spec/ruby/core/string/shared/eql.rb
index 92dfa91923..0e356c69e8 100644
--- a/spec/ruby/core/string/shared/eql.rb
+++ b/spec/ruby/core/string/shared/eql.rb
@@ -1,34 +1,38 @@
-# -*- encoding: binary -*-
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
+# encoding: binary
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
describe :string_eql_value, shared: true do
it "returns true if self <=> string returns 0" do
- 'hello'.send(@method, 'hello').should be_true
+ 'hello'.send(@method, 'hello').should == true
end
it "returns false if self <=> string does not return 0" do
- "more".send(@method, "MORE").should be_false
- "less".send(@method, "greater").should be_false
+ "more".send(@method, "MORE").should == false
+ "less".send(@method, "greater").should == false
end
it "ignores encoding difference of compatible string" do
- "hello".force_encoding("utf-8").send(@method, "hello".force_encoding("iso-8859-1")).should be_true
+ "hello".dup.force_encoding("utf-8").send(@method, "hello".dup.force_encoding("iso-8859-1")).should == true
end
it "considers encoding difference of incompatible string" do
- "\xff".force_encoding("utf-8").send(@method, "\xff".force_encoding("iso-8859-1")).should be_false
+ "\xff".dup.force_encoding("utf-8").send(@method, "\xff".dup.force_encoding("iso-8859-1")).should == false
end
it "considers encoding compatibility" do
- "hello".force_encoding("utf-8").send(@method, "hello".force_encoding("utf-32le")).should be_false
+ "abcd".dup.force_encoding("utf-8").send(@method, "abcd".dup.force_encoding("utf-32le")).should == false
end
it "ignores subclass differences" do
a = "hello"
b = StringSpecs::MyString.new("hello")
- a.send(@method, b).should be_true
- b.send(@method, a).should be_true
+ a.send(@method, b).should == true
+ b.send(@method, a).should == true
+ end
+
+ it "returns true when comparing 2 empty strings but one is not ASCII-compatible" do
+ "".send(@method, "".dup.force_encoding('iso-2022-jp')).should == true
end
end
diff --git a/spec/ruby/core/string/shared/equal_value.rb b/spec/ruby/core/string/shared/equal_value.rb
deleted file mode 100644
index 6df76478c7..0000000000
--- a/spec/ruby/core/string/shared/equal_value.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
-
-describe :string_equal_value, shared: true do
- it "returns false if obj does not respond to to_str" do
- 'hello'.send(@method, 5).should be_false
- not_supported_on :opal do
- 'hello'.send(@method, :hello).should be_false
- end
- 'hello'.send(@method, mock('x')).should be_false
- end
-
- it "returns obj == self if obj responds to to_str" do
- obj = Object.new
-
- # String#== merely checks if #to_str is defined. It does
- # not call it.
- obj.stub!(:to_str)
-
- # Don't use @method for :== in `obj.should_recerive(:==)`
- obj.should_receive(:==).and_return(true)
-
- 'hello'.send(@method, obj).should be_true
- end
-
- it "is not fooled by NUL characters" do
- "abc\0def".send(@method, "abc\0xyz").should be_false
- end
-end
diff --git a/spec/ruby/core/string/shared/grapheme_clusters.rb b/spec/ruby/core/string/shared/grapheme_clusters.rb
new file mode 100644
index 0000000000..dd8c7ed5fe
--- /dev/null
+++ b/spec/ruby/core/string/shared/grapheme_clusters.rb
@@ -0,0 +1,25 @@
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
+
+describe :string_grapheme_clusters, shared: true do
+ it "passes each grapheme cluster in self to the given block" do
+ a = []
+ # test string: abc[rainbow flag emoji][paw prints]
+ "ab\u{1f3f3}\u{fe0f}\u{200d}\u{1f308}\u{1F43E}".send(@method) { |c| a << c }
+ a.should == ['a', 'b', "\u{1f3f3}\u{fe0f}\u{200d}\u{1f308}", "\u{1F43E}"]
+ end
+
+ it "returns grapheme clusters for various UTF encodings" do
+ [Encoding::UTF_16LE, Encoding::UTF_16BE, Encoding::UTF_32LE, Encoding::UTF_32BE].each do |enc|
+ a = []
+ # test string: abc[rainbow flag emoji][paw prints]
+ "ab\u{1f3f3}\u{fe0f}\u{200d}\u{1f308}\u{1F43E}".encode(enc).send(@method) { |c| a << c }
+ a.should == ['a', 'b', "\u{1f3f3}\u{fe0f}\u{200d}\u{1f308}", "\u{1F43E}"].map { |s| s.encode(enc) }
+ end
+ end
+
+ it "returns self" do
+ s = StringSpecs::MyString.new "ab\u{1f3f3}\u{fe0f}\u{200d}\u{1f308}\u{1F43E}"
+ s.send(@method) {}.should.equal?(s)
+ end
+end
diff --git a/spec/ruby/core/string/shared/length.rb b/spec/ruby/core/string/shared/length.rb
deleted file mode 100644
index 0e6e66ee1c..0000000000
--- a/spec/ruby/core/string/shared/length.rb
+++ /dev/null
@@ -1,28 +0,0 @@
-# encoding: utf-8
-
-describe :string_length, shared: true do
- it "returns the length of self" do
- "".send(@method).should == 0
- "\x00".send(@method).should == 1
- "one".send(@method).should == 3
- "two".send(@method).should == 3
- "three".send(@method).should == 5
- "four".send(@method).should == 4
- end
-
- with_feature :encoding do
- it "returns the length of a string in different encodings" do
- utf8_str = 'ã“ã«ã¡ã‚' * 100
- utf8_str.size.should == 400
- utf8_str.encode(Encoding::UTF_32BE).size.should == 400
- utf8_str.encode(Encoding::SHIFT_JIS).size.should == 400
- end
-
- it "returns the length of the new self after encoding is changed" do
- str = 'ã“ã«ã¡ã‚'
- str.send(@method)
-
- str.force_encoding('ASCII-8BIT').send(@method).should == 12
- end
- end
-end
diff --git a/spec/ruby/core/string/shared/partition.rb b/spec/ruby/core/string/shared/partition.rb
new file mode 100644
index 0000000000..3f7e606eb3
--- /dev/null
+++ b/spec/ruby/core/string/shared/partition.rb
@@ -0,0 +1,33 @@
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
+
+describe :string_partition, shared: true do
+ it "returns String instances when called on a subclass" do
+ StringSpecs::MyString.new("hello").send(@method, "l").each do |item|
+ item.should.instance_of?(String)
+ end
+
+ StringSpecs::MyString.new("hello").send(@method, "x").each do |item|
+ item.should.instance_of?(String)
+ end
+
+ StringSpecs::MyString.new("hello").send(@method, /l./).each do |item|
+ item.should.instance_of?(String)
+ end
+ end
+
+ it "returns before- and after- parts in the same encoding as self" do
+ strings = "hello".encode("US-ASCII").send(@method, "ello")
+ strings[0].encoding.should == Encoding::US_ASCII
+ strings[2].encoding.should == Encoding::US_ASCII
+
+ strings = "hello".encode("US-ASCII").send(@method, /ello/)
+ strings[0].encoding.should == Encoding::US_ASCII
+ strings[2].encoding.should == Encoding::US_ASCII
+ end
+
+ it "returns the matching part in the separator's encoding" do
+ strings = "hello".encode("US-ASCII").send(@method, "ello")
+ strings[1].encoding.should == Encoding::UTF_8
+ end
+end
diff --git a/spec/ruby/core/string/shared/replace.rb b/spec/ruby/core/string/shared/replace.rb
index 9f5446fbbe..73b26351f1 100644
--- a/spec/ruby/core/string/shared/replace.rb
+++ b/spec/ruby/core/string/shared/replace.rb
@@ -1,7 +1,8 @@
+# frozen_string_literal: false
describe :string_replace, shared: true do
it "returns self" do
a = "a"
- a.send(@method, "b").should equal(a)
+ a.send(@method, "b").should.equal?(a)
end
it "replaces the content of self with other" do
@@ -10,34 +11,6 @@ describe :string_replace, shared: true do
a.should == "another string"
end
- it "taints self if other is tainted" do
- a = ""
- b = "".taint
- a.send(@method, b)
- a.tainted?.should == true
- end
-
- it "does not untaint self if other is untainted" do
- a = "".taint
- b = ""
- a.send(@method, b)
- a.tainted?.should == true
- end
-
- it "untrusts self if other is untrusted" do
- a = ""
- b = "".untrust
- a.send(@method, b)
- a.untrusted?.should == true
- end
-
- it "does not trust self if other is trusted" do
- a = "".untrust
- b = ""
- a.send(@method, b)
- a.untrusted?.should == true
- end
-
it "replaces the encoding of self with that of other" do
a = "".encode("UTF-16LE")
b = "".encode("UTF-8")
@@ -47,7 +20,7 @@ describe :string_replace, shared: true do
it "carries over the encoding invalidity" do
a = "\u{8765}".force_encoding('ascii')
- "".send(@method, a).valid_encoding?.should be_false
+ "".send(@method, a).valid_encoding?.should == false
end
it "tries to convert other to string using to_str" do
@@ -57,19 +30,19 @@ describe :string_replace, shared: true do
end
it "raises a TypeError if other can't be converted to string" do
- lambda { "hello".send(@method, 123) }.should raise_error(TypeError)
- lambda { "hello".send(@method, []) }.should raise_error(TypeError)
- lambda { "hello".send(@method, mock('x')) }.should raise_error(TypeError)
+ -> { "hello".send(@method, 123) }.should.raise(TypeError)
+ -> { "hello".send(@method, []) }.should.raise(TypeError)
+ -> { "hello".send(@method, mock('x')) }.should.raise(TypeError)
end
- it "raises a RuntimeError on a frozen instance that is modified" do
+ it "raises a FrozenError on a frozen instance that is modified" do
a = "hello".freeze
- lambda { a.send(@method, "world") }.should raise_error(RuntimeError)
+ -> { a.send(@method, "world") }.should.raise(FrozenError)
end
# see [ruby-core:23666]
- it "raises a RuntimeError on a frozen instance when self-replacing" do
+ it "raises a FrozenError on a frozen instance when self-replacing" do
a = "hello".freeze
- lambda { a.send(@method, a) }.should raise_error(RuntimeError)
+ -> { a.send(@method, a) }.should.raise(FrozenError)
end
end
diff --git a/spec/ruby/core/string/shared/slice.rb b/spec/ruby/core/string/shared/slice.rb
index 697fa2e530..d296ab6680 100644
--- a/spec/ruby/core/string/shared/slice.rb
+++ b/spec/ruby/core/string/shared/slice.rb
@@ -21,17 +21,17 @@ describe :string_slice, shared: true do
end
it "raises a TypeError if the given index is nil" do
- lambda { "hello".send(@method, nil) }.should raise_error(TypeError)
+ -> { "hello".send(@method, nil) }.should.raise(TypeError)
end
it "raises a TypeError if the given index can't be converted to an Integer" do
- lambda { "hello".send(@method, mock('x')) }.should raise_error(TypeError)
- lambda { "hello".send(@method, {}) }.should raise_error(TypeError)
- lambda { "hello".send(@method, []) }.should raise_error(TypeError)
+ -> { "hello".send(@method, mock('x')) }.should.raise(TypeError)
+ -> { "hello".send(@method, {}) }.should.raise(TypeError)
+ -> { "hello".send(@method, []) }.should.raise(TypeError)
end
it "raises a RangeError if the index is too big" do
- lambda { "hello".send(@method, bignum_value) }.should raise_error(RangeError)
+ -> { "hello".send(@method, bignum_value) }.should.raise(RangeError)
end
end
@@ -80,21 +80,12 @@ describe :string_slice_index_length, shared: true do
"hello there".send(@method, -3,2).should == "er"
end
- it "always taints resulting strings when self is tainted" do
- str = "hello world"
- str.taint
-
- str.send(@method, 0,0).tainted?.should == true
- str.send(@method, 0,1).tainted?.should == true
- str.send(@method, 2,1).tainted?.should == true
- end
-
- it "returns a string with the same encoding" do
+ it "returns a string with the same encoding as self" do
s = "hello there"
s.send(@method, 1, 9).encoding.should == s.encoding
- a = "hello".force_encoding("binary")
- b = " there".force_encoding("ISO-8859-1")
+ a = "hello".dup.force_encoding("binary")
+ b = " there".dup.force_encoding("ISO-8859-1")
c = (a + b).force_encoding(Encoding::US_ASCII)
c.send(@method, 0, 5).encoding.should == Encoding::US_ASCII
@@ -119,6 +110,8 @@ describe :string_slice_index_length, shared: true do
"x".send(@method, -2,0).should == nil
"x".send(@method, -2,1).should == nil
+
+ "x".send(@method, fixnum_max, 1).should == nil
end
it "returns nil if the length is negative" do
@@ -126,6 +119,18 @@ describe :string_slice_index_length, shared: true do
"hello there".send(@method, -4,-3).should == nil
end
+ platform_is pointer_size: 64 do
+ it "returns nil if the length is negative big value" do
+ "hello there".send(@method, 4, -(1 << 31)).should == nil
+
+ # by some reason length < -(1 << 31) on CI on Windows leads to
+ # 'RangeError: bignum too big to convert into `long'' error
+ platform_is_not :windows do
+ "hello there".send(@method, 4, -(1 << 63)).should == nil
+ end
+ end
+ end
+
it "calls to_int on the given index and the given length" do
"hello".send(@method, 0.5, 1).should == "h"
"hello".send(@method, 0.5, 2.5).should == "he"
@@ -140,30 +145,35 @@ describe :string_slice_index_length, shared: true do
end
it "raises a TypeError when idx or length can't be converted to an integer" do
- lambda { "hello".send(@method, mock('x'), 0) }.should raise_error(TypeError)
- lambda { "hello".send(@method, 0, mock('x')) }.should raise_error(TypeError)
+ -> { "hello".send(@method, mock('x'), 0) }.should.raise(TypeError)
+ -> { "hello".send(@method, 0, mock('x')) }.should.raise(TypeError)
# I'm deliberately including this here.
# It means that str.send(@method, other, idx) isn't supported.
- lambda { "hello".send(@method, "", 0) }.should raise_error(TypeError)
+ -> { "hello".send(@method, "", 0) }.should.raise(TypeError)
end
it "raises a TypeError when the given index or the given length is nil" do
- lambda { "hello".send(@method, 1, nil) }.should raise_error(TypeError)
- lambda { "hello".send(@method, nil, 1) }.should raise_error(TypeError)
- lambda { "hello".send(@method, nil, nil) }.should raise_error(TypeError)
+ -> { "hello".send(@method, 1, nil) }.should.raise(TypeError)
+ -> { "hello".send(@method, nil, 1) }.should.raise(TypeError)
+ -> { "hello".send(@method, nil, nil) }.should.raise(TypeError)
end
it "raises a RangeError if the index or length is too big" do
- lambda { "hello".send(@method, bignum_value, 1) }.should raise_error(RangeError)
- lambda { "hello".send(@method, 0, bignum_value) }.should raise_error(RangeError)
+ -> { "hello".send(@method, bignum_value, 1) }.should.raise(RangeError)
+ -> { "hello".send(@method, 0, bignum_value) }.should.raise(RangeError)
+ end
+
+ it "raises a RangeError if the index or length is too small" do
+ -> { "hello".send(@method, -bignum_value, 1) }.should.raise(RangeError)
+ -> { "hello".send(@method, 0, -bignum_value) }.should.raise(RangeError)
end
- it "returns subclass instances" do
+ it "returns String instances" do
s = StringSpecs::MyString.new("hello")
- s.send(@method, 0,0).should be_an_instance_of(StringSpecs::MyString)
- s.send(@method, 0,4).should be_an_instance_of(StringSpecs::MyString)
- s.send(@method, 1,4).should be_an_instance_of(StringSpecs::MyString)
+ s.send(@method, 0,0).should.instance_of?(String)
+ s.send(@method, 0,4).should.instance_of?(String)
+ s.send(@method, 1,4).should.instance_of?(String)
end
it "handles repeated application" do
@@ -202,6 +212,10 @@ describe :string_slice_range, shared: true do
"x".send(@method, 1..-1).should == ""
end
+ it "returns a String in the same encoding as self" do
+ "hello there".encode("US-ASCII").send(@method, 1..1).encoding.should == Encoding::US_ASCII
+ end
+
it "returns nil if the beginning of the range falls outside of self" do
"hello there".send(@method, 12..-1).should == nil
"hello there".send(@method, 20..25).should == nil
@@ -234,23 +248,11 @@ describe :string_slice_range, shared: true do
"x".send(@method, 1...-1).should == ""
end
- it "always taints resulting strings when self is tainted" do
- str = "hello world"
- str.taint
-
- str.send(@method, 0..0).tainted?.should == true
- str.send(@method, 0...0).tainted?.should == true
- str.send(@method, 0..1).tainted?.should == true
- str.send(@method, 0...1).tainted?.should == true
- str.send(@method, 2..3).tainted?.should == true
- str.send(@method, 2..0).tainted?.should == true
- end
-
- it "returns subclass instances" do
+ it "returns String instances" do
s = StringSpecs::MyString.new("hello")
- s.send(@method, 0...0).should be_an_instance_of(StringSpecs::MyString)
- s.send(@method, 0..4).should be_an_instance_of(StringSpecs::MyString)
- s.send(@method, 1..4).should be_an_instance_of(StringSpecs::MyString)
+ s.send(@method, 0...0).should.instance_of?(String)
+ s.send(@method, 0..4).should.instance_of?(String)
+ s.send(@method, 1..4).should.instance_of?(String)
end
it "calls to_int on range arguments" do
@@ -289,6 +291,30 @@ describe :string_slice_range, shared: true do
"hello world".send(@method, 6..5).send(@method, -1..-1).should == nil
"hello world".send(@method, 6..5).send(@method, 1..1).should == nil
end
+
+ it "raises a type error if a range is passed with a length" do
+ ->{ "hello".send(@method, 1..2, 1) }.should.raise(TypeError)
+ end
+
+ it "raises a RangeError if one of the bound is too big" do
+ -> { "hello".send(@method, bignum_value..(bignum_value + 1)) }.should.raise(RangeError)
+ -> { "hello".send(@method, 0..bignum_value) }.should.raise(RangeError)
+ end
+
+ it "works with endless ranges" do
+ "hello there".send(@method, eval("(2..)")).should == "llo there"
+ "hello there".send(@method, eval("(2...)")).should == "llo there"
+ "hello there".send(@method, eval("(-4..)")).should == "here"
+ "hello there".send(@method, eval("(-4...)")).should == "here"
+ end
+
+ it "works with beginless ranges" do
+ "hello there".send(@method, (..5)).should == "hello "
+ "hello there".send(@method, (...5)).should == "hello"
+ "hello there".send(@method, (..-4)).should == "hello th"
+ "hello there".send(@method, (...-4)).should == "hello t"
+ "hello there".send(@method, (...nil)).should == "hello there"
+ end
end
describe :string_slice_regexp, shared: true do
@@ -301,31 +327,14 @@ describe :string_slice_regexp, shared: true do
"hello there".send(@method, /xyz/).should == nil
end
- not_supported_on :opal do
- it "always taints resulting strings when self or regexp is tainted" do
- strs = ["hello world"]
- strs += strs.map { |s| s.dup.taint }
-
- strs.each do |str|
- str.send(@method, //).tainted?.should == str.tainted?
- str.send(@method, /hello/).tainted?.should == str.tainted?
-
- tainted_re = /./
- tainted_re.taint
-
- str.send(@method, tainted_re).tainted?.should == true
- end
- end
-
- it "returns an untrusted string if the regexp is untrusted" do
- "hello".send(@method, /./.untrust).untrusted?.should be_true
- end
+ it "returns a String in the same encoding as self" do
+ "hello there".encode("US-ASCII").send(@method, /[aeiou](.)\1/).encoding.should == Encoding::US_ASCII
end
- it "returns subclass instances" do
+ it "returns String instances" do
s = StringSpecs::MyString.new("hello")
- s.send(@method, //).should be_an_instance_of(StringSpecs::MyString)
- s.send(@method, /../).should be_an_instance_of(StringSpecs::MyString)
+ s.send(@method, //).should.instance_of?(String)
+ s.send(@method, /../).should.instance_of?(String)
end
it "sets $~ to MatchData when there is a match and nil when there's none" do
@@ -352,42 +361,28 @@ describe :string_slice_regexp_index, shared: true do
"har".send(@method, /(.)(.)(.)/, -3).should == "h"
end
- it "always taints resulting strings when self or regexp is tainted" do
- strs = ["hello world"]
- strs += strs.map { |s| s.dup.taint }
-
- strs.each do |str|
- str.send(@method, //, 0).tainted?.should == str.tainted?
- str.send(@method, /hello/, 0).tainted?.should == str.tainted?
-
- str.send(@method, /(.)(.)(.)/, 0).tainted?.should == str.tainted?
- str.send(@method, /(.)(.)(.)/, 1).tainted?.should == str.tainted?
- str.send(@method, /(.)(.)(.)/, -1).tainted?.should == str.tainted?
- str.send(@method, /(.)(.)(.)/, -2).tainted?.should == str.tainted?
-
- tainted_re = /(.)(.)(.)/
- tainted_re.taint
+ it "returns nil if there is no match" do
+ "hello there".send(@method, /(what?)/, 1).should == nil
+ end
- str.send(@method, tainted_re, 0).tainted?.should == true
- str.send(@method, tainted_re, 1).tainted?.should == true
- str.send(@method, tainted_re, -1).tainted?.should == true
- end
+ it "returns nil if the index is larger than the number of captures" do
+ "hello there".send(@method, /hello (.)/, 2).should == nil
+ # You can't refer to 0 using negative indices
+ "hello there".send(@method, /hello (.)/, -2).should == nil
end
- not_supported_on :opal do
- it "returns an untrusted string if the regexp is untrusted" do
- "hello".send(@method, /(.)/.untrust, 1).untrusted?.should be_true
- end
+ it "returns nil if there is no capture for the given index" do
+ "hello there".send(@method, /[aeiou](.)\1/, 2).should == nil
end
- it "returns nil if there is no match" do
- "hello there".send(@method, /(what?)/, 1).should == nil
+ it "returns nil if the given capture group was not matched but still sets $~" do
+ "test".send(@method, /te(z)?/, 1).should == nil
+ $~[0].should == "te"
+ $~[1].should == nil
end
- it "returns nil if there is no capture for the given index" do
- "hello there".send(@method, /[aeiou](.)\1/, 2).should == nil
- # You can't refer to 0 using negative indices
- "hello there".send(@method, /[aeiou](.)\1/, -2).should == nil
+ it "returns a String in the same encoding as self" do
+ "hello there".encode("US-ASCII").send(@method, /[aeiou](.)\1/, 0).encoding.should == Encoding::US_ASCII
end
it "calls to_int on the given index" do
@@ -399,19 +394,19 @@ describe :string_slice_regexp_index, shared: true do
end
it "raises a TypeError when the given index can't be converted to Integer" do
- lambda { "hello".send(@method, /(.)(.)(.)/, mock('x')) }.should raise_error(TypeError)
- lambda { "hello".send(@method, /(.)(.)(.)/, {}) }.should raise_error(TypeError)
- lambda { "hello".send(@method, /(.)(.)(.)/, []) }.should raise_error(TypeError)
+ -> { "hello".send(@method, /(.)(.)(.)/, mock('x')) }.should.raise(TypeError)
+ -> { "hello".send(@method, /(.)(.)(.)/, {}) }.should.raise(TypeError)
+ -> { "hello".send(@method, /(.)(.)(.)/, []) }.should.raise(TypeError)
end
it "raises a TypeError when the given index is nil" do
- lambda { "hello".send(@method, /(.)(.)(.)/, nil) }.should raise_error(TypeError)
+ -> { "hello".send(@method, /(.)(.)(.)/, nil) }.should.raise(TypeError)
end
- it "returns subclass instances" do
+ it "returns String instances" do
s = StringSpecs::MyString.new("hello")
- s.send(@method, /(.)(.)/, 0).should be_an_instance_of(StringSpecs::MyString)
- s.send(@method, /(.)(.)/, 1).should be_an_instance_of(StringSpecs::MyString)
+ s.send(@method, /(.)(.)/, 0).should.instance_of?(String)
+ s.send(@method, /(.)(.)/, 1).should.instance_of?(String)
end
it "sets $~ to MatchData when there is a match and nil when there's none" do
@@ -432,19 +427,6 @@ describe :string_slice_string, shared: true do
"hello there".send(@method, s).should == s
end
- it "taints resulting strings when other is tainted" do
- strs = ["", "hello world", "hello"]
- strs += strs.map { |s| s.dup.taint }
-
- strs.each do |str|
- strs.each do |other|
- r = str.send(@method, other)
-
- r.tainted?.should == !r.nil? & other.tainted?
- end
- end
- end
-
it "doesn't set $~" do
$~ = nil
@@ -460,14 +442,14 @@ describe :string_slice_string, shared: true do
o = mock('x')
o.should_not_receive(:to_str)
- lambda { "hello".send(@method, o) }.should raise_error(TypeError)
+ -> { "hello".send(@method, o) }.should.raise(TypeError)
end
- it "returns a subclass instance when given a subclass instance" do
+ it "returns a String instance when given a subclass instance" do
s = StringSpecs::MyString.new("el")
r = "hello".send(@method, s)
r.should == "el"
- r.should be_an_instance_of(StringSpecs::MyString)
+ r.should.instance_of?(String)
end
end
@@ -493,51 +475,29 @@ describe :string_slice_regexp_group, shared: true do
"hello there".send(@method, /(?<g>h(?<g>.))/, 'g').should == "e"
end
- it "always taints resulting strings when self or regexp is tainted" do
- strs = ["hello world"]
- strs += strs.map { |s| s.dup.taint }
-
- strs.each do |str|
- str.send(@method, /(?<hi>hello)/, 'hi').tainted?.should == str.tainted?
-
- str.send(@method, /(?<g>(.)(.)(.))/, 'g').tainted?.should == str.tainted?
- str.send(@method, /(?<h>.)(.)(.)/, 'h').tainted?.should == str.tainted?
- str.send(@method, /(.)(?<a>.)(.)/, 'a').tainted?.should == str.tainted?
- str.send(@method, /(.)(.)(?<r>.)/, 'r').tainted?.should == str.tainted?
- str.send(@method, /(?<h>.)(?<a>.)(?<r>.)/, 'r').tainted?.should == str.tainted?
-
- tainted_re = /(?<a>.)(?<b>.)(?<c>.)/
- tainted_re.taint
-
- str.send(@method, tainted_re, 'a').tainted?.should be_true
- str.send(@method, tainted_re, 'b').tainted?.should be_true
- str.send(@method, tainted_re, 'c').tainted?.should be_true
- end
- end
-
it "returns nil if there is no match" do
- "hello there".send(@method, /(?<whut>what?)/, 'whut').should be_nil
+ "hello there".send(@method, /(?<whut>what?)/, 'whut').should == nil
end
it "raises an IndexError if there is no capture for the given name" do
- lambda do
+ -> do
"hello there".send(@method, /[aeiou](.)\1/, 'non')
- end.should raise_error(IndexError)
+ end.should.raise(IndexError)
end
it "raises a TypeError when the given name is not a String" do
- lambda { "hello".send(@method, /(?<q>.)/, mock('x')) }.should raise_error(TypeError)
- lambda { "hello".send(@method, /(?<q>.)/, {}) }.should raise_error(TypeError)
- lambda { "hello".send(@method, /(?<q>.)/, []) }.should raise_error(TypeError)
+ -> { "hello".send(@method, /(?<q>.)/, mock('x')) }.should.raise(TypeError)
+ -> { "hello".send(@method, /(?<q>.)/, {}) }.should.raise(TypeError)
+ -> { "hello".send(@method, /(?<q>.)/, []) }.should.raise(TypeError)
end
it "raises an IndexError when given the empty String as a group name" do
- lambda { "hello".send(@method, /(?<q>)/, '') }.should raise_error(IndexError)
+ -> { "hello".send(@method, /(?<q>)/, '') }.should.raise(IndexError)
end
- it "returns subclass instances" do
+ it "returns String instances" do
s = StringSpecs::MyString.new("hello")
- s.send(@method, /(?<q>.)/, 'q').should be_an_instance_of(StringSpecs::MyString)
+ s.send(@method, /(?<q>.)/, 'q').should.instance_of?(String)
end
it "sets $~ to MatchData when there is a match and nil when there's none" do
@@ -545,13 +505,13 @@ describe :string_slice_regexp_group, shared: true do
$~[0].should == 'he'
'hello'.send(@method, /(?<non>not)/, 'non')
- $~.should be_nil
+ $~.should == nil
end
end
end
describe :string_slice_symbol, shared: true do
it "raises TypeError" do
- lambda { 'hello'.send(@method, :hello) }.should raise_error(TypeError)
+ -> { 'hello'.send(@method, :hello) }.should.raise(TypeError)
end
end
diff --git a/spec/ruby/core/string/shared/strip.rb b/spec/ruby/core/string/shared/strip.rb
new file mode 100644
index 0000000000..39c7232ff9
--- /dev/null
+++ b/spec/ruby/core/string/shared/strip.rb
@@ -0,0 +1,14 @@
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
+
+describe :string_strip, shared: true do
+ it "returns a String in the same encoding as self" do
+ " hello ".encode("US-ASCII").send(@method).encoding.should == Encoding::US_ASCII
+ end
+
+ it "returns String instances when called on a subclass" do
+ StringSpecs::MyString.new(" hello ").send(@method).should.instance_of?(String)
+ StringSpecs::MyString.new(" ").send(@method).should.instance_of?(String)
+ StringSpecs::MyString.new("").send(@method).should.instance_of?(String)
+ end
+end
diff --git a/spec/ruby/core/string/shared/succ.rb b/spec/ruby/core/string/shared/succ.rb
deleted file mode 100644
index 4854cb7146..0000000000
--- a/spec/ruby/core/string/shared/succ.rb
+++ /dev/null
@@ -1,88 +0,0 @@
-# -*- encoding: binary -*-
-describe :string_succ, shared: true do
- it "returns an empty string for empty strings" do
- "".send(@method).should == ""
- end
-
- it "returns the successor by increasing the rightmost alphanumeric (digit => digit, letter => letter with same case)" do
- "abcd".send(@method).should == "abce"
- "THX1138".send(@method).should == "THX1139"
-
- "<<koala>>".send(@method).should == "<<koalb>>"
- "==A??".send(@method).should == "==B??"
- end
-
- it "increases non-alphanumerics (via ascii rules) if there are no alphanumerics" do
- "***".send(@method).should == "**+"
- "**`".send(@method).should == "**a"
- end
-
- it "increases the next best alphanumeric (jumping over non-alphanumerics) if there is a carry" do
- "dz".send(@method).should == "ea"
- "HZ".send(@method).should == "IA"
- "49".send(@method).should == "50"
-
- "izz".send(@method).should == "jaa"
- "IZZ".send(@method).should == "JAA"
- "699".send(@method).should == "700"
-
- "6Z99z99Z".send(@method).should == "7A00a00A"
-
- "1999zzz".send(@method).should == "2000aaa"
- "NZ/[]ZZZ9999".send(@method).should == "OA/[]AAA0000"
- end
-
- it "increases the next best character if there is a carry for non-alphanumerics" do
- "(\xFF".send(@method).should == ")\x00"
- "`\xFF".send(@method).should == "a\x00"
- "<\xFF\xFF".send(@method).should == "=\x00\x00"
- end
-
- it "adds an additional character (just left to the last increased one) if there is a carry and no character left to increase" do
- "z".send(@method).should == "aa"
- "Z".send(@method).should == "AA"
- "9".send(@method).should == "10"
-
- "zz".send(@method).should == "aaa"
- "ZZ".send(@method).should == "AAA"
- "99".send(@method).should == "100"
-
- "9Z99z99Z".send(@method).should == "10A00a00A"
-
- "ZZZ9999".send(@method).should == "AAAA0000"
- "/[]9999".send(@method).should == "/[]10000"
- "/[]ZZZ9999".send(@method).should == "/[]AAAA0000"
- "Z/[]ZZZ9999".send(@method).should == "AA/[]AAA0000"
-
- # non-alphanumeric cases
- "\xFF".send(@method).should == "\x01\x00"
- "\xFF\xFF".send(@method).should == "\x01\x00\x00"
- end
-
- it "returns subclass instances when called on a subclass" do
- StringSpecs::MyString.new("").send(@method).should be_an_instance_of(StringSpecs::MyString)
- StringSpecs::MyString.new("a").send(@method).should be_an_instance_of(StringSpecs::MyString)
- StringSpecs::MyString.new("z").send(@method).should be_an_instance_of(StringSpecs::MyString)
- end
-
- it "taints the result if self is tainted" do
- ["", "a", "z", "Z", "9", "\xFF", "\xFF\xFF"].each do |s|
- s.taint.send(@method).tainted?.should == true
- end
- end
-end
-
-describe :string_succ_bang, shared: true do
- it "is equivalent to succ, but modifies self in place (still returns self)" do
- ["", "abcd", "THX1138"].each do |s|
- r = s.dup.send(@method)
- s.send(@method).should equal(s)
- s.should == r
- end
- end
-
- it "raises a RuntimeError if self is frozen" do
- lambda { "".freeze.send(@method) }.should raise_error(RuntimeError)
- lambda { "abcd".freeze.send(@method) }.should raise_error(RuntimeError)
- end
-end
diff --git a/spec/ruby/core/string/shared/to_a.rb b/spec/ruby/core/string/shared/to_a.rb
deleted file mode 100644
index bad3ea6584..0000000000
--- a/spec/ruby/core/string/shared/to_a.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-describe :string_to_a, shared: true do
- it "returns an empty array for empty strings" do
- "".send(@method).should == []
- end
-
- it "returns an array containing the string for non-empty strings" do
- "hello".send(@method).should == ["hello"]
- end
-end
diff --git a/spec/ruby/core/string/shared/to_s.rb b/spec/ruby/core/string/shared/to_s.rb
deleted file mode 100644
index a5a13e4f26..0000000000
--- a/spec/ruby/core/string/shared/to_s.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-describe :string_to_s, shared: true do
- it "returns self when self.class == String" do
- a = "a string"
- a.should equal(a.send(@method))
- end
-
- it "returns a new instance of String when called on a subclass" do
- a = StringSpecs::MyString.new("a string")
- s = a.send(@method)
- s.should == "a string"
- s.should be_an_instance_of(String)
- end
-
- it "taints the result when self is tainted" do
- "x".taint.send(@method).tainted?.should == true
- StringSpecs::MyString.new("x").taint.send(@method).tainted?.should == true
- end
-end
diff --git a/spec/ruby/core/string/shared/to_sym.rb b/spec/ruby/core/string/shared/to_sym.rb
deleted file mode 100644
index 1180d64712..0000000000
--- a/spec/ruby/core/string/shared/to_sym.rb
+++ /dev/null
@@ -1,63 +0,0 @@
-describe :string_to_sym, shared: true do
- it "returns the symbol corresponding to self" do
- "Koala".send(@method).should equal :Koala
- 'cat'.send(@method).should equal :cat
- '@cat'.send(@method).should equal :@cat
- 'cat and dog'.send(@method).should equal :"cat and dog"
- "abc=".send(@method).should equal :abc=
- end
-
- it "does not special case +(binary) and -(binary)" do
- "+(binary)".send(@method).should equal :"+(binary)"
- "-(binary)".send(@method).should equal :"-(binary)"
- end
-
- it "does not special case certain operators" do
- "!@".send(@method).should equal :"!@"
- "~@".send(@method).should equal :"~@"
- "!(unary)".send(@method).should equal :"!(unary)"
- "~(unary)".send(@method).should equal :"~(unary)"
- "+(unary)".send(@method).should equal :"+(unary)"
- "-(unary)".send(@method).should equal :"-(unary)"
- end
-
- it "returns a US-ASCII Symbol for a UTF-8 String containing only US-ASCII characters" do
- sym = "foobar".send(@method)
- sym.encoding.should == Encoding::US_ASCII
- sym.should equal :"foobar"
- end
-
- it "returns a US-ASCII Symbol for a binary String containing only US-ASCII characters" do
- sym = "foobar".b.send(@method)
- sym.encoding.should == Encoding::US_ASCII
- sym.should equal :"foobar"
- end
-
- it "returns a UTF-8 Symbol for a UTF-8 String containing non US-ASCII characters" do
- sym = "il était une fois".send(@method)
- sym.encoding.should == Encoding::UTF_8
- sym.should equal :"il était une #{'fois'}"
- end
-
- it "returns a UTF-16LE Symbol for a UTF-16LE String containing non US-ASCII characters" do
- utf16_str = "UtéF16".encode(Encoding::UTF_16LE)
- sym = utf16_str.send(@method)
- sym.encoding.should == Encoding::UTF_16LE
- sym.to_s.should == utf16_str
- end
-
- it "returns a binary Symbol for a binary String containing non US-ASCII characters" do
- binary_string = "binarí".b
- sym = binary_string.send(@method)
- sym.encoding.should == Encoding::BINARY
- sym.to_s.should == binary_string
- end
-
- it "raises an EncodingError for UTF-8 String containing invalid bytes" do
- invalid_utf8 = "\xC3"
- invalid_utf8.valid_encoding?.should == false
- -> {
- invalid_utf8.send(@method)
- }.should raise_error(EncodingError, /invalid/)
- end
-end
diff --git a/spec/ruby/core/string/size_spec.rb b/spec/ruby/core/string/size_spec.rb
index b3172453ea..6fc81480c4 100644
--- a/spec/ruby/core/string/size_spec.rb
+++ b/spec/ruby/core/string/size_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes.rb', __FILE__)
-require File.expand_path('../shared/length', __FILE__)
+require_relative '../../spec_helper'
describe "String#size" do
- it_behaves_like(:string_length, :size)
+ it "is an alias of String#length" do
+ String.instance_method(:size).should == String.instance_method(:length)
+ end
end
diff --git a/spec/ruby/core/string/slice_spec.rb b/spec/ruby/core/string/slice_spec.rb
index 8018cc2140..16d7665bbf 100644
--- a/spec/ruby/core/string/slice_spec.rb
+++ b/spec/ruby/core/string/slice_spec.rb
@@ -1,39 +1,12 @@
-# -*- encoding: utf-8 -*-
-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes.rb', __FILE__)
-require File.expand_path('../shared/slice.rb', __FILE__)
+# frozen_string_literal: false
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/slice'
describe "String#slice" do
- it_behaves_like :string_slice, :slice
-end
-
-describe "String#slice with index, length" do
- it_behaves_like :string_slice_index_length, :slice
-end
-
-describe "String#slice with Range" do
- it_behaves_like :string_slice_range, :slice
-end
-
-describe "String#slice with Regexp" do
- it_behaves_like :string_slice_regexp, :slice
-end
-
-describe "String#slice with Regexp, index" do
- it_behaves_like :string_slice_regexp_index, :slice
-end
-
-describe "String#slice with Regexp, group" do
- it_behaves_like :string_slice_regexp_group, :slice
-end
-
-describe "String#slice with String" do
- it_behaves_like :string_slice_string, :slice
-end
-
-describe "String#slice with Symbol" do
- it_behaves_like :string_slice_symbol, :slice
+ it "is an alias of String#[]" do
+ String.instance_method(:slice).should == String.instance_method(:[])
+ end
end
describe "String#slice! with index" do
@@ -53,10 +26,10 @@ describe "String#slice! with index" do
a.should == "hello"
end
- it "raises a RuntimeError if self is frozen" do
- lambda { "hello".freeze.slice!(1) }.should raise_error(RuntimeError)
- lambda { "hello".freeze.slice!(10) }.should raise_error(RuntimeError)
- lambda { "".freeze.slice!(0) }.should raise_error(RuntimeError)
+ it "raises a FrozenError if self is frozen" do
+ -> { "hello".freeze.slice!(1) }.should.raise(FrozenError)
+ -> { "hello".freeze.slice!(10) }.should.raise(FrozenError)
+ -> { "".freeze.slice!(0) }.should.raise(FrozenError)
end
it "calls to_int on index" do
@@ -72,15 +45,13 @@ describe "String#slice! with index" do
"hello".slice!(obj).should == ?e
end
- with_feature :encoding do
-
- it "returns the character given by the character index" do
- "hellö there".send(@method, 1).should == "e"
- "hellö there".send(@method, 4).should == "ö"
- "hellö there".send(@method, 6).should == "t"
- end
+ it "returns the character given by the character index" do
+ "hellö there".slice!(1).should == "e"
+ "hellö there".slice!(4).should == "ö"
+ "hellö there".slice!(6).should == "t"
end
+
end
describe "String#slice! with index, length" do
@@ -96,14 +67,6 @@ describe "String#slice! with index, length" do
a.should == "h"
end
- it "always taints resulting strings when self is tainted" do
- str = "hello world"
- str.taint
-
- str.slice!(0, 0).tainted?.should == true
- str.slice!(2, 1).tainted?.should == true
- end
-
it "returns nil if the given position is out of self" do
a = "hello"
a.slice(10, 3).should == nil
@@ -119,14 +82,14 @@ describe "String#slice! with index, length" do
a.should == "hello"
end
- it "raises a RuntimeError if self is frozen" do
- lambda { "hello".freeze.slice!(1, 2) }.should raise_error(RuntimeError)
- lambda { "hello".freeze.slice!(10, 3) }.should raise_error(RuntimeError)
- lambda { "hello".freeze.slice!(-10, 3)}.should raise_error(RuntimeError)
- lambda { "hello".freeze.slice!(4, -3) }.should raise_error(RuntimeError)
- lambda { "hello".freeze.slice!(10, 3) }.should raise_error(RuntimeError)
- lambda { "hello".freeze.slice!(-10, 3)}.should raise_error(RuntimeError)
- lambda { "hello".freeze.slice!(4, -3) }.should raise_error(RuntimeError)
+ it "raises a FrozenError if self is frozen" do
+ -> { "hello".freeze.slice!(1, 2) }.should.raise(FrozenError)
+ -> { "hello".freeze.slice!(10, 3) }.should.raise(FrozenError)
+ -> { "hello".freeze.slice!(-10, 3)}.should.raise(FrozenError)
+ -> { "hello".freeze.slice!(4, -3) }.should.raise(FrozenError)
+ -> { "hello".freeze.slice!(10, 3) }.should.raise(FrozenError)
+ -> { "hello".freeze.slice!(-10, 3)}.should.raise(FrozenError)
+ -> { "hello".freeze.slice!(4, -3) }.should.raise(FrozenError)
end
it "calls to_int on idx and length" do
@@ -142,25 +105,22 @@ describe "String#slice! with index, length" do
"hello".slice!(obj, obj).should == "ll"
end
- it "returns subclass instances" do
+ it "returns String instances" do
s = StringSpecs::MyString.new("hello")
- s.slice!(0, 0).should be_an_instance_of(StringSpecs::MyString)
- s.slice!(0, 4).should be_an_instance_of(StringSpecs::MyString)
+ s.slice!(0, 0).should.instance_of?(String)
+ s.slice!(0, 4).should.instance_of?(String)
end
- with_feature :encoding do
-
- it "returns the substring given by the character offsets" do
- "hellö there".send(@method, 1,0).should == ""
- "hellö there".send(@method, 1,3).should == "ell"
- "hellö there".send(@method, 1,6).should == "ellö t"
- "hellö there".send(@method, 1,9).should == "ellö ther"
- end
+ it "returns the substring given by the character offsets" do
+ "hellö there".slice!(1,0).should == ""
+ "hellö there".slice!(1,3).should == "ell"
+ "hellö there".slice!(1,6).should == "ellö t"
+ "hellö there".slice!(1,9).should == "ellö ther"
+ end
- it "treats invalid bytes as single bytes" do
- xE6xCB = [0xE6,0xCB].pack('CC').force_encoding('utf-8')
- "a#{xE6xCB}b".send(@method, 1, 2).should == xE6xCB
- end
+ it "treats invalid bytes as single bytes" do
+ xE6xCB = [0xE6,0xCB].pack('CC').force_encoding('utf-8')
+ "a#{xE6xCB}b".slice!(1, 2).should == xE6xCB
end
end
@@ -188,18 +148,10 @@ describe "String#slice! Range" do
b.should == "hello"
end
- it "always taints resulting strings when self is tainted" do
- str = "hello world"
- str.taint
-
- str.slice!(0..0).tainted?.should == true
- str.slice!(2..3).tainted?.should == true
- end
-
- it "returns subclass instances" do
+ it "returns String instances" do
s = StringSpecs::MyString.new("hello")
- s.slice!(0...0).should be_an_instance_of(StringSpecs::MyString)
- s.slice!(0..4).should be_an_instance_of(StringSpecs::MyString)
+ s.slice!(0...0).should.instance_of?(String)
+ s.slice!(0..4).should.instance_of?(String)
end
it "calls to_int on range arguments" do
@@ -236,27 +188,25 @@ describe "String#slice! Range" do
a.slice!(range_incl).should == "OO"
end
- with_feature :encoding do
-
- it "returns the substring given by the character offsets of the range" do
- "hellö there".send(@method, 1..1).should == "e"
- "hellö there".send(@method, 1..3).should == "ell"
- "hellö there".send(@method, 1...3).should == "el"
- "hellö there".send(@method, -4..-2).should == "her"
- "hellö there".send(@method, -4...-2).should == "he"
- "hellö there".send(@method, 5..-1).should == " there"
- "hellö there".send(@method, 5...-1).should == " ther"
- end
+ it "returns the substring given by the character offsets of the range" do
+ "hellö there".slice!(1..1).should == "e"
+ "hellö there".slice!(1..3).should == "ell"
+ "hellö there".slice!(1...3).should == "el"
+ "hellö there".slice!(-4..-2).should == "her"
+ "hellö there".slice!(-4...-2).should == "he"
+ "hellö there".slice!(5..-1).should == " there"
+ "hellö there".slice!(5...-1).should == " ther"
end
- it "raises a RuntimeError on a frozen instance that is modified" do
- lambda { "hello".freeze.slice!(1..3) }.should raise_error(RuntimeError)
+
+ it "raises a FrozenError on a frozen instance that is modified" do
+ -> { "hello".freeze.slice!(1..3) }.should.raise(FrozenError)
end
# see redmine #1551
- it "raises a RuntimeError on a frozen instance that would not be modified" do
- lambda { "hello".freeze.slice!(10..20)}.should raise_error(RuntimeError)
+ it "raises a FrozenError on a frozen instance that would not be modified" do
+ -> { "hello".freeze.slice!(10..20)}.should.raise(FrozenError)
end
end
@@ -277,39 +227,15 @@ describe "String#slice! with Regexp" do
s.should == "this is a string"
end
- it "always taints resulting strings when self or regexp is tainted" do
- strs = ["hello world"]
- strs += strs.map { |s| s.dup.taint }
-
- strs.each do |str|
- str = str.dup
- str.slice!(//).tainted?.should == str.tainted?
- str.slice!(/hello/).tainted?.should == str.tainted?
-
- tainted_re = /./
- tainted_re.taint
-
- str.slice!(tainted_re).tainted?.should == true
- end
- end
-
- it "doesn't taint self when regexp is tainted" do
- s = "hello"
- s.slice!(/./.taint)
- s.tainted?.should == false
- end
-
- it "returns subclass instances" do
+ it "returns String instances" do
s = StringSpecs::MyString.new("hello")
- s.slice!(//).should be_an_instance_of(StringSpecs::MyString)
- s.slice!(/../).should be_an_instance_of(StringSpecs::MyString)
+ s.slice!(//).should.instance_of?(String)
+ s.slice!(/../).should.instance_of?(String)
end
- with_feature :encoding do
- it "returns the matching portion of self with a multi byte character" do
- "hëllo there".send(@method, /[ë](.)\1/).should == "ëll"
- "".send(@method, //).should == ""
- end
+ it "returns the matching portion of self with a multi byte character" do
+ "hëllo there".slice!(/[ë](.)\1/).should == "ëll"
+ "".slice!(//).should == ""
end
it "sets $~ to MatchData when there is a match and nil when there's none" do
@@ -320,12 +246,12 @@ describe "String#slice! with Regexp" do
$~.should == nil
end
- it "raises a RuntimeError on a frozen instance that is modified" do
- lambda { "this is a string".freeze.slice!(/s.*t/) }.should raise_error(RuntimeError)
+ it "raises a FrozenError on a frozen instance that is modified" do
+ -> { "this is a string".freeze.slice!(/s.*t/) }.should.raise(FrozenError)
end
- it "raises a RuntimeError on a frozen instance that would not be modified" do
- lambda { "this is a string".freeze.slice!(/zzz/) }.should raise_error(RuntimeError)
+ it "raises a FrozenError on a frozen instance that would not be modified" do
+ -> { "this is a string".freeze.slice!(/zzz/) }.should.raise(FrozenError)
end
end
@@ -338,28 +264,6 @@ describe "String#slice! with Regexp, index" do
str.should == "ho here"
end
- it "always taints resulting strings when self or regexp is tainted" do
- strs = ["hello world"]
- strs += strs.map { |s| s.dup.taint }
-
- strs.each do |str|
- str = str.dup
- str.slice!(//, 0).tainted?.should == str.tainted?
- str.slice!(/hello/, 0).tainted?.should == str.tainted?
-
- tainted_re = /(.)(.)(.)/
- tainted_re.taint
-
- str.slice!(tainted_re, 1).tainted?.should == true
- end
- end
-
- it "doesn't taint self when regexp is tainted" do
- s = "hello"
- s.slice!(/(.)(.)/.taint, 1)
- s.tainted?.should == false
- end
-
it "returns nil if there was no match" do
s = "this is a string"
s.slice!(/x(zzz)/, 1).should == nil
@@ -383,22 +287,20 @@ describe "String#slice! with Regexp, index" do
"har".slice!(/(.)(.)(.)/, obj).should == "a"
end
- it "returns subclass instances" do
+ it "returns String instances" do
s = StringSpecs::MyString.new("hello")
- s.slice!(/(.)(.)/, 0).should be_an_instance_of(StringSpecs::MyString)
- s.slice!(/(.)(.)/, 1).should be_an_instance_of(StringSpecs::MyString)
+ s.slice!(/(.)(.)/, 0).should.instance_of?(String)
+ s.slice!(/(.)(.)/, 1).should.instance_of?(String)
end
- with_feature :encoding do
- it "returns the encoding aware capture for the given index" do
- "hår".send(@method, /(.)(.)(.)/, 0).should == "hår"
- "hår".send(@method, /(.)(.)(.)/, 1).should == "h"
- "hår".send(@method, /(.)(.)(.)/, 2).should == "å"
- "hår".send(@method, /(.)(.)(.)/, 3).should == "r"
- "hår".send(@method, /(.)(.)(.)/, -1).should == "r"
- "hår".send(@method, /(.)(.)(.)/, -2).should == "å"
- "hår".send(@method, /(.)(.)(.)/, -3).should == "h"
- end
+ it "returns the encoding aware capture for the given index" do
+ "hår".slice!(/(.)(.)(.)/, 0).should == "hår"
+ "hår".slice!(/(.)(.)(.)/, 1).should == "h"
+ "hår".slice!(/(.)(.)(.)/, 2).should == "å"
+ "hår".slice!(/(.)(.)(.)/, 3).should == "r"
+ "hår".slice!(/(.)(.)(.)/, -1).should == "r"
+ "hår".slice!(/(.)(.)(.)/, -2).should == "å"
+ "hår".slice!(/(.)(.)(.)/, -3).should == "h"
end
it "sets $~ to MatchData when there is a match and nil when there's none" do
@@ -412,10 +314,10 @@ describe "String#slice! with Regexp, index" do
$~.should == nil
end
- it "raises a RuntimeError if self is frozen" do
- lambda { "this is a string".freeze.slice!(/s.*t/) }.should raise_error(RuntimeError)
- lambda { "this is a string".freeze.slice!(/zzz/, 0)}.should raise_error(RuntimeError)
- lambda { "this is a string".freeze.slice!(/(.)/, 2)}.should raise_error(RuntimeError)
+ it "raises a FrozenError if self is frozen" do
+ -> { "this is a string".freeze.slice!(/s.*t/) }.should.raise(FrozenError)
+ -> { "this is a string".freeze.slice!(/zzz/, 0)}.should.raise(FrozenError)
+ -> { "this is a string".freeze.slice!(/(.)/, 2)}.should.raise(FrozenError)
end
end
@@ -426,21 +328,6 @@ describe "String#slice! with String" do
c.should == "he hello"
end
- it "taints resulting strings when other is tainted" do
- strs = ["", "hello world", "hello"]
- strs += strs.map { |s| s.dup.taint }
-
- strs.each do |str|
- str = str.dup
- strs.each do |other|
- other = other.dup
- r = str.slice!(other)
-
- r.tainted?.should == !r.nil? & other.tainted?
- end
- end
- end
-
it "doesn't set $~" do
$~ = nil
@@ -458,19 +345,19 @@ describe "String#slice! with String" do
o = mock('x')
o.should_not_receive(:to_str)
- lambda { "hello".slice!(o) }.should raise_error(TypeError)
+ -> { "hello".slice!(o) }.should.raise(TypeError)
end
it "returns a subclass instance when given a subclass instance" do
s = StringSpecs::MyString.new("el")
r = "hello".slice!(s)
r.should == "el"
- r.should be_an_instance_of(StringSpecs::MyString)
+ r.should.instance_of?(String)
end
- it "raises a RuntimeError if self is frozen" do
- lambda { "hello hello".freeze.slice!('llo') }.should raise_error(RuntimeError)
- lambda { "this is a string".freeze.slice!('zzz')}.should raise_error(RuntimeError)
- lambda { "this is a string".freeze.slice!('zzz')}.should raise_error(RuntimeError)
+ it "raises a FrozenError if self is frozen" do
+ -> { "hello hello".freeze.slice!('llo') }.should.raise(FrozenError)
+ -> { "this is a string".freeze.slice!('zzz')}.should.raise(FrozenError)
+ -> { "this is a string".freeze.slice!('zzz')}.should.raise(FrozenError)
end
end
diff --git a/spec/ruby/core/string/split_spec.rb b/spec/ruby/core/string/split_spec.rb
index 1a4128f828..6e8c1c6219 100644
--- a/spec/ruby/core/string/split_spec.rb
+++ b/spec/ruby/core/string/split_spec.rb
@@ -1,21 +1,24 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes.rb', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "String#split with String" do
- with_feature :encoding do
- it "throws an ArgumentError if the pattern is not a valid string" do
- str = 'проверка'
- broken_str = 'проверка'
- broken_str.force_encoding('binary')
- broken_str.chop!
- broken_str.force_encoding('utf-8')
- lambda { str.split(broken_str) }.should raise_error(ArgumentError)
- end
+ it "throws an ArgumentError if the string is not a valid" do
+ s = "\xDF".dup.force_encoding(Encoding::UTF_8)
- it "splits on multibyte characters" do
- "ã‚りãŒã‚ŠãŒã¨ã†".split("ãŒ").should == ["ã‚り", "り", "ã¨ã†"]
- end
+ -> { s.split }.should.raise(ArgumentError)
+ -> { s.split(':') }.should.raise(ArgumentError)
+ end
+
+ it "throws an ArgumentError if the pattern is not a valid string" do
+ str = 'проверка'
+ broken_str = "\xDF".dup.force_encoding(Encoding::UTF_8)
+
+ -> { str.split(broken_str) }.should.raise(ArgumentError)
+ end
+
+ it "splits on multibyte characters" do
+ "ã‚りãŒã‚ŠãŒã¨ã†".split("ãŒ").should == ["ã‚り", "り", "ã¨ã†"]
end
it "returns an array of substrings based on splitting on the given string" do
@@ -26,9 +29,35 @@ describe "String#split with String" do
"1,2,,3,4,,".split(',').should == ["1", "2", "", "3", "4"]
"1,2,,3,4,,".split(',', 0).should == ["1", "2", "", "3", "4"]
" a b c\nd ".split(" ").should == ["", "a", "b", "c\nd"]
+ " a ã‚ c\nd ".split(" ").should == ["", "a", "ã‚", "c\nd"]
"hai".split("hai").should == []
",".split(",").should == []
",".split(",", 0).should == []
+ "ã‚".split("ã‚").should == []
+ "ã‚".split("ã‚", 0).should == []
+ end
+
+ it "does not suppress trailing empty fields when a positive limit is given" do
+ " 1 2 ".split(" ", 2).should == ["1", "2 "]
+ " 1 2 ".split(" ", 3).should == ["1", "2", ""]
+ " 1 2 ".split(" ", 4).should == ["1", "2", ""]
+ " 1 ã‚ ".split(" ", 2).should == ["1", "ã‚ "]
+ " 1 ã‚ ".split(" ", 3).should == ["1", "ã‚", ""]
+ " 1 ã‚ ".split(" ", 4).should == ["1", "ã‚", ""]
+
+ "1,2,".split(',', 2).should == ["1", "2,"]
+ "1,2,".split(',', 3).should == ["1", "2", ""]
+ "1,2,".split(',', 4).should == ["1", "2", ""]
+ "1,ã‚,".split(',', 2).should == ["1", "ã‚,"]
+ "1,ã‚,".split(',', 3).should == ["1", "ã‚", ""]
+ "1,ã‚,".split(',', 4).should == ["1", "ã‚", ""]
+
+ "1 2 ".split(/ /, 2).should == ["1", "2 "]
+ "1 2 ".split(/ /, 3).should == ["1", "2", ""]
+ "1 2 ".split(/ /, 4).should == ["1", "2", ""]
+ "1 ã‚ ".split(/ /, 2).should == ["1", "ã‚ "]
+ "1 ã‚ ".split(/ /, 3).should == ["1", "ã‚", ""]
+ "1 ã‚ ".split(/ /, 4).should == ["1", "ã‚", ""]
end
it "returns an array with one entry if limit is 1: the original string" do
@@ -64,26 +93,47 @@ describe "String#split with String" do
",".split(",", -1).should == ["", ""]
end
+ it "raises a RangeError when the limit is larger than int" do
+ -> { "a,b".split(" ", 2147483649) }.should.raise(RangeError)
+ end
+
it "defaults to $; when string isn't given or nil" do
- begin
+ suppress_warning do
old_fs = $;
+ begin
+ [",", ":", "", "XY", nil].each do |fs|
+ $; = fs
- [",", ":", "", "XY", nil].each do |fs|
- $; = fs
-
- ["x,y,z,,,", "1:2:", "aXYbXYcXY", ""].each do |str|
- expected = str.split(fs || " ")
+ ["x,y,z,,,", "1:2:", "aXYbXYcXY", ""].each do |str|
+ expected = str.split(fs || " ")
- str.split(nil).should == expected
- str.split.should == expected
+ str.split(nil).should == expected
+ str.split.should == expected
- str.split(nil, -1).should == str.split(fs || " ", -1)
- str.split(nil, 0).should == str.split(fs || " ", 0)
- str.split(nil, 2).should == str.split(fs || " ", 2)
+ str.split(nil, -1).should == str.split(fs || " ", -1)
+ str.split(nil, 0).should == str.split(fs || " ", 0)
+ str.split(nil, 2).should == str.split(fs || " ", 2)
+ end
end
+ ensure
+ $; = old_fs
end
- ensure
- $; = old_fs
+ end
+ end
+
+ context "when $; is not nil" do
+ before do
+ suppress_warning do
+ @old_value, $; = $;, 'foobar'
+ end
+ end
+
+ after do
+ $; = @old_value
+ end
+
+ it "warns" do
+ -> { "".split }.should complain(/warning: \$; is set to non-nil value/)
end
end
@@ -142,48 +192,48 @@ describe "String#split with String" do
"foo".split("bar", 3).should == ["foo"]
end
- it "returns subclass instances based on self" do
+ it "returns String instances based on self" do
["", "x.y.z.", " x y "].each do |str|
["", ".", " "].each do |pat|
[-1, 0, 1, 2].each do |limit|
StringSpecs::MyString.new(str).split(pat, limit).each do |x|
- x.should be_an_instance_of(StringSpecs::MyString)
+ x.should.instance_of?(String)
end
str.split(StringSpecs::MyString.new(pat), limit).each do |x|
- x.should be_an_instance_of(String)
+ x.should.instance_of?(String)
end
end
end
end
end
- it "does not call constructor on created subclass instances" do
- # can't call should_not_receive on an object that doesn't yet exist
- # so failure here is signalled by exception, not expectation failure
+ it "returns an empty array when whitespace is split on whitespace" do
+ " ".split(" ").should == []
+ " \n ".split(" ").should == []
+ " ".split(" ").should == []
+ " \t ".split(" ").should == []
+ end
- s = StringSpecs::StringWithRaisingConstructor.new('silly:string')
- s.split(':').first.should == 'silly'
+ it "doesn't split on non-ascii whitespace" do
+ "a\u{2008}b".split(" ").should == ["a\u{2008}b"]
end
- it "taints the resulting strings if self is tainted" do
- ["", "x.y.z.", " x y "].each do |str|
- ["", ".", " "].each do |pat|
- [-1, 0, 1, 2].each do |limit|
- str.dup.taint.split(pat).each do |x|
- x.tainted?.should == true
- end
+ it "returns Strings in the same encoding as self" do
+ strings = "hello world".encode("US-ASCII").split(" ")
- str.split(pat.dup.taint).each do |x|
- x.tainted?.should == false
- end
- end
- end
- end
+ strings[0].encoding.should == Encoding::US_ASCII
+ strings[1].encoding.should == Encoding::US_ASCII
end
end
describe "String#split with Regexp" do
+ it "throws an ArgumentError if the string is not a valid" do
+ s = "\xDF".dup.force_encoding(Encoding::UTF_8)
+
+ -> { s.split(/./) }.should.raise(ArgumentError)
+ end
+
it "divides self on regexp matches" do
" now's the time".split(/ /).should == ["", "now's", "", "the", "time"]
" x\ny ".split(/ /).should == ["", "x\ny"]
@@ -238,25 +288,26 @@ describe "String#split with Regexp" do
end
it "defaults to $; when regexp isn't given or nil" do
- begin
+ suppress_warning do
old_fs = $;
+ begin
+ [/,/, /:/, //, /XY/, /./].each do |fs|
+ $; = fs
- [/,/, /:/, //, /XY/, /./].each do |fs|
- $; = fs
-
- ["x,y,z,,,", "1:2:", "aXYbXYcXY", ""].each do |str|
- expected = str.split(fs)
+ ["x,y,z,,,", "1:2:", "aXYbXYcXY", ""].each do |str|
+ expected = str.split(fs)
- str.split(nil).should == expected
- str.split.should == expected
+ str.split(nil).should == expected
+ str.split.should == expected
- str.split(nil, -1).should == str.split(fs, -1)
- str.split(nil, 0).should == str.split(fs, 0)
- str.split(nil, 2).should == str.split(fs, 2)
+ str.split(nil, -1).should == str.split(fs, -1)
+ str.split(nil, 0).should == str.split(fs, 0)
+ str.split(nil, 2).should == str.split(fs, 2)
+ end
end
+ ensure
+ $; = old_fs
end
- ensure
- $; = old_fs
end
end
@@ -316,8 +367,8 @@ describe "String#split with Regexp" do
end
it "returns a type error if limit can't be converted to an integer" do
- lambda {"1.2.3.4".split(".", "three")}.should raise_error(TypeError)
- lambda {"1.2.3.4".split(".", nil) }.should raise_error(TypeError)
+ -> {"1.2.3.4".split(".", "three")}.should.raise(TypeError)
+ -> {"1.2.3.4".split(".", nil) }.should.raise(TypeError)
end
it "doesn't set $~" do
@@ -335,71 +386,161 @@ describe "String#split with Regexp" do
"foo".split(/bar/, 3).should == ["foo"]
end
- it "returns subclass instances based on self" do
+ it "returns String instances based on self" do
["", "x:y:z:", " x y "].each do |str|
[//, /:/, /\s+/].each do |pat|
[-1, 0, 1, 2].each do |limit|
StringSpecs::MyString.new(str).split(pat, limit).each do |x|
- x.should be_an_instance_of(StringSpecs::MyString)
+ x.should.instance_of?(String)
end
end
end
end
end
- it "does not call constructor on created subclass instances" do
- # can't call should_not_receive on an object that doesn't yet exist
- # so failure here is signalled by exception, not expectation failure
+ it "returns Strings in the same encoding as self" do
+ ary = "а б в".split
+ encodings = ary.map { |s| s.encoding }
+ encodings.should == [Encoding::UTF_8, Encoding::UTF_8, Encoding::UTF_8]
+ end
- s = StringSpecs::StringWithRaisingConstructor.new('silly:string')
- s.split(/:/).first.should == 'silly'
+ it "splits a string on each character for a multibyte encoding and empty split" do
+ "That's why efficiency could not be helped".split("").size.should == 39
end
- it "taints the resulting strings if self is tainted" do
- ["", "x:y:z:", " x y "].each do |str|
- [//, /:/, /\s+/].each do |pat|
- [-1, 0, 1, 2].each do |limit|
- str.dup.taint.split(pat, limit).each do |x|
- # See the spec below for why the conditional is here
- x.tainted?.should be_true unless x.empty?
- end
- end
- end
- end
+ it "returns an ArgumentError if an invalid UTF-8 string is supplied" do
+ broken_str = +'проверка' # in russian, means "test"
+ broken_str.force_encoding('binary')
+ broken_str.chop!
+ broken_str.force_encoding('utf-8')
+ ->{ broken_str.split(/\r\n|\r|\n/) }.should.raise(ArgumentError)
end
- it "taints an empty string if self is tainted" do
- ":".taint.split(//, -1).last.tainted?.should be_true
+ # See https://bugs.ruby-lang.org/issues/12689 and https://github.com/jruby/jruby/issues/4868
+ it "allows concurrent Regexp calls in a shared context" do
+ str = 'a,b,c,d,e'
+
+ p = proc { str.split(/,/) }
+ results = 10.times.map { Thread.new { x = nil; 100.times { x = p.call }; x } }.map(&:value)
+
+ results.should == [%w[a b c d e]] * 10
end
- it "doesn't taints the resulting strings if the Regexp is tainted" do
- ["", "x:y:z:", " x y "].each do |str|
- [//, /:/, /\s+/].each do |pat|
- [-1, 0, 1, 2].each do |limit|
- str.split(pat.dup.taint, limit).each do |x|
- x.tainted?.should be_false
- end
- end
- end
+ context "when a block is given" do
+ it "yields each split substring with default pattern" do
+ a = []
+ returned_object = "chunky bacon".split { |str| a << str.capitalize }
+
+ returned_object.should == "chunky bacon"
+ a.should == ["Chunky", "Bacon"]
end
- end
- it "retains the encoding of the source string" do
- ary = "а б в".split
- encodings = ary.map { |s| s.encoding }
- encodings.should == [Encoding::UTF_8, Encoding::UTF_8, Encoding::UTF_8]
+ it "yields each split substring with default pattern for a lazy substring" do
+ a = []
+ returned_object = "chunky bacon"[1...-1].split { |str| a << str.capitalize }
+
+ returned_object.should == "hunky baco"
+ a.should == ["Hunky", "Baco"]
+ end
+
+ it "yields each split substring with default pattern for a non-ASCII string" do
+ a = []
+ returned_object = "l'été arrive bientôt".split { |str| a << str }
+
+ returned_object.should == "l'été arrive bientôt"
+ a.should == ["l'été", "arrive", "bientôt"]
+ end
+
+ it "yields each split substring with default pattern for a non-ASCII lazy substring" do
+ a = []
+ returned_object = "l'été arrive bientôt"[1...-1].split { |str| a << str }
+
+ returned_object.should == "'été arrive bientô"
+ a.should == ["'été", "arrive", "bientô"]
+ end
+
+ it "yields the string when limit is 1" do
+ a = []
+ returned_object = "chunky bacon".split("", 1) { |str| a << str.capitalize }
+
+ returned_object.should == "chunky bacon"
+ a.should == ["Chunky bacon"]
+ end
+
+ it "yields each split letter" do
+ a = []
+ returned_object = "chunky".split("", 0) { |str| a << str.capitalize }
+
+ returned_object.should == "chunky"
+ a.should == %w(C H U N K Y)
+ end
+
+ it "yields each split substring with a pattern" do
+ a = []
+ returned_object = "chunky-bacon".split("-", 0) { |str| a << str.capitalize }
+
+ returned_object.should == "chunky-bacon"
+ a.should == ["Chunky", "Bacon"]
+ end
+
+ it "yields each split substring with empty regexp pattern" do
+ a = []
+ returned_object = "chunky".split(//) { |str| a << str.capitalize }
+
+ returned_object.should == "chunky"
+ a.should == %w(C H U N K Y)
+ end
+
+ it "yields each split substring with empty regexp pattern and limit" do
+ a = []
+ returned_object = "chunky".split(//, 3) { |str| a << str.capitalize }
+
+ returned_object.should == "chunky"
+ a.should == %w(C H Unky)
+ end
+
+ it "yields each split substring with a regexp pattern" do
+ a = []
+ returned_object = "chunky:bacon".split(/:/) { |str| a << str.capitalize }
+
+ returned_object.should == "chunky:bacon"
+ a.should == ["Chunky", "Bacon"]
+ end
+
+ it "returns a string as is (and doesn't call block) if it is empty" do
+ a = []
+ returned_object = "".split { |str| a << str.capitalize }
+
+ returned_object.should == ""
+ a.should == []
+ end
end
+ describe "for a String subclass" do
+ it "yields instances of String" do
+ a = []
+ StringSpecs::MyString.new("a|b").split("|") { |str| a << str }
+ first, last = a
- it "splits a string on each character for a multibyte encoding and empty split" do
- "That's why efficiency could not be helped".split("").size.should == 39
+ first.should.instance_of?(String)
+ first.should == "a"
+
+ last.should.instance_of?(String)
+ last.should == "b"
+ end
end
- it "returns an ArgumentError if an invalid UTF-8 string is supplied" do
- broken_str = 'проверка' # in russian, means "test"
- broken_str.force_encoding('binary')
- broken_str.chop!
- broken_str.force_encoding('utf-8')
- lambda{ broken_str.split(/\r\n|\r|\n/) }.should raise_error(ArgumentError)
+ it "raises a TypeError when not called with nil, String, or Regexp" do
+ -> { "hello".split(42) }.should.raise(TypeError)
+ -> { "hello".split(:ll) }.should.raise(TypeError)
+ -> { "hello".split(false) }.should.raise(TypeError)
+ -> { "hello".split(Object.new) }.should.raise(TypeError)
+ end
+
+ it "returns Strings in the same encoding as self" do
+ strings = "hello world".encode("US-ASCII").split(/ /)
+
+ strings[0].encoding.should == Encoding::US_ASCII
+ strings[1].encoding.should == Encoding::US_ASCII
end
end
diff --git a/spec/ruby/core/string/squeeze_spec.rb b/spec/ruby/core/string/squeeze_spec.rb
index d6b3fb6de6..52b6e1eed4 100644
--- a/spec/ruby/core/string/squeeze_spec.rb
+++ b/spec/ruby/core/string/squeeze_spec.rb
@@ -1,6 +1,7 @@
-# -*- encoding: binary -*-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes.rb', __FILE__)
+# encoding: binary
+# frozen_string_literal: false
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
# TODO: rewrite all these specs
@@ -50,16 +51,8 @@ describe "String#squeeze" do
it "raises an ArgumentError when the parameter is out of sequence" do
s = "--subbookkeeper--"
- lambda { s.squeeze("e-b") }.should raise_error(ArgumentError)
- lambda { s.squeeze("^e-b") }.should raise_error(ArgumentError)
- end
-
- it "taints the result when self is tainted" do
- "hello".taint.squeeze("e").tainted?.should == true
- "hello".taint.squeeze("a-z").tainted?.should == true
-
- "hello".squeeze("e".taint).tainted?.should == false
- "hello".squeeze("l".taint).tainted?.should == false
+ -> { s.squeeze("e-b") }.should.raise(ArgumentError)
+ -> { s.squeeze("^e-b") }.should.raise(ArgumentError)
end
it "tries to convert each set arg to a string using to_str" do
@@ -72,21 +65,26 @@ describe "String#squeeze" do
"hello room".squeeze(other_string, other_string2).should == "hello rom"
end
+ it "returns a String in the same encoding as self" do
+ "yellow moon".encode("US-ASCII").squeeze.encoding.should == Encoding::US_ASCII
+ "yellow moon".encode("US-ASCII").squeeze("a").encoding.should == Encoding::US_ASCII
+ end
+
it "raises a TypeError when one set arg can't be converted to a string" do
- lambda { "hello world".squeeze([]) }.should raise_error(TypeError)
- lambda { "hello world".squeeze(Object.new)}.should raise_error(TypeError)
- lambda { "hello world".squeeze(mock('x')) }.should raise_error(TypeError)
+ -> { "hello world".squeeze([]) }.should.raise(TypeError)
+ -> { "hello world".squeeze(Object.new)}.should.raise(TypeError)
+ -> { "hello world".squeeze(mock('x')) }.should.raise(TypeError)
end
- it "returns subclass instances when called on a subclass" do
- StringSpecs::MyString.new("oh no!!!").squeeze("!").should be_an_instance_of(StringSpecs::MyString)
+ it "returns String instances when called on a subclass" do
+ StringSpecs::MyString.new("oh no!!!").squeeze("!").should.instance_of?(String)
end
end
describe "String#squeeze!" do
it "modifies self in place and returns self" do
a = "yellow moon"
- a.squeeze!.should equal(a)
+ a.squeeze!.should.equal?(a)
a.should == "yelow mon"
end
@@ -99,15 +97,15 @@ describe "String#squeeze!" do
it "raises an ArgumentError when the parameter is out of sequence" do
s = "--subbookkeeper--"
- lambda { s.squeeze!("e-b") }.should raise_error(ArgumentError)
- lambda { s.squeeze!("^e-b") }.should raise_error(ArgumentError)
+ -> { s.squeeze!("e-b") }.should.raise(ArgumentError)
+ -> { s.squeeze!("^e-b") }.should.raise(ArgumentError)
end
- it "raises a RuntimeError when self is frozen" do
+ it "raises a FrozenError when self is frozen" do
a = "yellow moon"
a.freeze
- lambda { a.squeeze!("") }.should raise_error(RuntimeError)
- lambda { a.squeeze! }.should raise_error(RuntimeError)
+ -> { a.squeeze!("") }.should.raise(FrozenError)
+ -> { a.squeeze! }.should.raise(FrozenError)
end
end
diff --git a/spec/ruby/core/string/start_with_spec.rb b/spec/ruby/core/string/start_with_spec.rb
index b85081037d..8b0ba6b5a7 100644
--- a/spec/ruby/core/string/start_with_spec.rb
+++ b/spec/ruby/core/string/start_with_spec.rb
@@ -1,45 +1,18 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes.rb', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative '../../shared/string/start_with'
describe "String#start_with?" do
- it "returns true only if beginning match" do
- s = "hello"
- s.start_with?('h').should be_true
- s.start_with?('hel').should be_true
- s.start_with?('el').should be_false
- end
-
- it "returns true only if any beginning match" do
- "hello".start_with?('x', 'y', 'he', 'z').should be_true
- end
-
- it "returns true if the search string is empty" do
- "hello".start_with?("").should be_true
- "".start_with?("").should be_true
- end
-
- it "converts its argument using :to_str" do
- s = "hello"
- find = mock('h')
- find.should_receive(:to_str).and_return("h")
- s.start_with?(find).should be_true
- end
-
- it "ignores arguments not convertible to string" do
- "hello".start_with?().should be_false
- lambda { "hello".start_with?(1) }.should raise_error(TypeError)
- lambda { "hello".start_with?(["h"]) }.should raise_error(TypeError)
- lambda { "hello".start_with?(1, nil, "h").should }.should raise_error(TypeError)
- end
+ it_behaves_like :start_with, :to_s
- it "uses only the needed arguments" do
- find = mock('h')
- find.should_not_receive(:to_str)
- "hello".start_with?("h",find).should be_true
+ # Here and not in the shared examples because this is invalid as a Symbol
+ it "matches part of a character with the same part" do
+ "\xA9".should.start_with?("\xA9") # A9 is not a character head for UTF-8
end
- it "works for multibyte strings" do
- "céréale".start_with?("cér").should be_true
+ it "checks we are matching only part of a character" do
+ "\xe3\x81\x82".size.should == 1
+ "\xe3\x81\x82".should_not.start_with?("\xe3")
end
end
diff --git a/spec/ruby/core/string/string_spec.rb b/spec/ruby/core/string/string_spec.rb
index 37a858acae..cdefbbecbd 100644
--- a/spec/ruby/core/string/string_spec.rb
+++ b/spec/ruby/core/string/string_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "String" do
it "includes Comparable" do
diff --git a/spec/ruby/core/string/strip_spec.rb b/spec/ruby/core/string/strip_spec.rb
index 747fd8cdf2..81994a7f2e 100644
--- a/spec/ruby/core/string/strip_spec.rb
+++ b/spec/ruby/core/string/strip_spec.rb
@@ -1,39 +1,31 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes.rb', __FILE__)
+# frozen_string_literal: false
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/strip'
describe "String#strip" do
+ it_behaves_like :string_strip, :strip
+
it "returns a new string with leading and trailing whitespace removed" do
" hello ".strip.should == "hello"
" hello world ".strip.should == "hello world"
"\tgoodbye\r\v\n".strip.should == "goodbye"
- "\x00 goodbye \x00".strip.should == "\x00 goodbye"
- end
-
- it "returns a copy of self with trailing NULL bytes and whitespace" do
- " \x00 goodbye \x00 ".strip.should == "\x00 goodbye"
end
- it "taints the result when self is tainted" do
- "".taint.strip.tainted?.should == true
- "ok".taint.strip.tainted?.should == true
- " ok ".taint.strip.tainted?.should == true
+ it "returns a copy of self without leading and trailing NULL bytes and whitespace" do
+ " \x00 goodbye \x00 ".strip.should == "goodbye"
end
end
describe "String#strip!" do
it "modifies self in place and returns self" do
a = " hello "
- a.strip!.should equal(a)
+ a.strip!.should.equal?(a)
a.should == "hello"
a = "\tgoodbye\r\v\n"
a.strip!
a.should == "goodbye"
-
- a = "\000 goodbye \000"
- a.strip!
- a.should == "\000 goodbye"
-
end
it "returns nil if no modifications where made" do
@@ -42,19 +34,25 @@ describe "String#strip!" do
a.should == "hello"
end
- it "modifies self removing trailing NULL bytes and whitespace" do
- a = " \x00 goodbye \x00 "
+ it "makes a string empty if it is only whitespace" do
+ "".strip!.should == nil
+ " ".strip.should == ""
+ " ".strip.should == ""
+ end
+
+ it "removes leading and trailing NULL bytes and whitespace" do
+ a = "\000 goodbye \000"
a.strip!
- a.should == "\x00 goodbye"
+ a.should == "goodbye"
end
- it "raises a RuntimeError on a frozen instance that is modified" do
- lambda { " hello ".freeze.strip! }.should raise_error(RuntimeError)
+ it "raises a FrozenError on a frozen instance that is modified" do
+ -> { " hello ".freeze.strip! }.should.raise(FrozenError)
end
# see #1552
- it "raises a RuntimeError on a frozen instance that would not be modified" do
- lambda {"hello".freeze.strip! }.should raise_error(RuntimeError)
- lambda {"".freeze.strip! }.should raise_error(RuntimeError)
+ it "raises a FrozenError on a frozen instance that would not be modified" do
+ -> {"hello".freeze.strip! }.should.raise(FrozenError)
+ -> {"".freeze.strip! }.should.raise(FrozenError)
end
end
diff --git a/spec/ruby/core/string/sub_spec.rb b/spec/ruby/core/string/sub_spec.rb
index deaa7e27f1..f0082fba59 100644
--- a/spec/ruby/core/string/sub_spec.rb
+++ b/spec/ruby/core/string/sub_spec.rb
@@ -1,12 +1,13 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes.rb', __FILE__)
+# frozen_string_literal: false
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "String#sub with pattern, replacement" do
it "returns a copy of self when no modification is made" do
a = "hello"
b = a.sub(/w.*$/, "*")
- b.should_not equal(a)
+ b.should_not.equal?(a)
b.should == "hello"
end
@@ -137,26 +138,6 @@ describe "String#sub with pattern, replacement" do
"hello".sub(/./, 'hah\\').should == 'hah\\ello'
end
- it "taints the result if the original string or replacement is tainted" do
- hello = "hello"
- hello_t = "hello"
- a = "a"
- a_t = "a"
- empty = ""
- empty_t = ""
-
- hello_t.taint; a_t.taint; empty_t.taint
-
- hello_t.sub(/./, a).tainted?.should == true
- hello_t.sub(/./, empty).tainted?.should == true
-
- hello.sub(/./, a_t).tainted?.should == true
- hello.sub(/./, empty_t).tainted?.should == true
- hello.sub(//, empty_t).tainted?.should == true
-
- hello.sub(//.taint, "foo").tainted?.should == false
- end
-
it "tries to convert pattern to a string using to_str" do
pattern = mock('.')
pattern.should_receive(:to_str).and_return(".")
@@ -166,16 +147,16 @@ describe "String#sub with pattern, replacement" do
not_supported_on :opal do
it "raises a TypeError when pattern is a Symbol" do
- lambda { "hello".sub(:woot, "x") }.should raise_error(TypeError)
+ -> { "hello".sub(:woot, "x") }.should.raise(TypeError)
end
end
it "raises a TypeError when pattern is an Array" do
- lambda { "hello".sub([], "x") }.should raise_error(TypeError)
+ -> { "hello".sub([], "x") }.should.raise(TypeError)
end
it "raises a TypeError when pattern can't be converted to a string" do
- lambda { "hello".sub(Object.new, nil) }.should raise_error(TypeError)
+ -> { "hello".sub(Object.new, nil) }.should.raise(TypeError)
end
it "tries to convert replacement to a string using to_str" do
@@ -186,15 +167,15 @@ describe "String#sub with pattern, replacement" do
end
it "raises a TypeError when replacement can't be converted to a string" do
- lambda { "hello".sub(/[aeiou]/, []) }.should raise_error(TypeError)
- lambda { "hello".sub(/[aeiou]/, 99) }.should raise_error(TypeError)
+ -> { "hello".sub(/[aeiou]/, []) }.should.raise(TypeError)
+ -> { "hello".sub(/[aeiou]/, 99) }.should.raise(TypeError)
end
- it "returns subclass instances when called on a subclass" do
- StringSpecs::MyString.new("").sub(//, "").should be_an_instance_of(StringSpecs::MyString)
- StringSpecs::MyString.new("").sub(/foo/, "").should be_an_instance_of(StringSpecs::MyString)
- StringSpecs::MyString.new("foo").sub(/foo/, "").should be_an_instance_of(StringSpecs::MyString)
- StringSpecs::MyString.new("foo").sub("foo", "").should be_an_instance_of(StringSpecs::MyString)
+ it "returns String instances when called on a subclass" do
+ StringSpecs::MyString.new("").sub(//, "").should.instance_of?(String)
+ StringSpecs::MyString.new("").sub(/foo/, "").should.instance_of?(String)
+ StringSpecs::MyString.new("foo").sub(/foo/, "").should.instance_of?(String)
+ StringSpecs::MyString.new("foo").sub("foo", "").should.instance_of?(String)
end
it "sets $~ to MatchData of match and nil when there's none" do
@@ -223,6 +204,17 @@ describe "String#sub with pattern, replacement" do
"ababa".sub(/(b)/, '\\\\\1').should == "a\\baba"
end
+ it "handles a pattern in a superset encoding" do
+ result = 'abc'.force_encoding(Encoding::US_ASCII).sub('é', 'è')
+ result.should == 'abc'
+ result.encoding.should == Encoding::US_ASCII
+ end
+
+ it "handles a pattern in a subset encoding" do
+ result = 'été'.sub('t'.force_encoding(Encoding::US_ASCII), 'u')
+ result.should == 'éué'
+ result.encoding.should == Encoding::UTF_8
+ end
end
describe "String#sub with pattern and block" do
@@ -240,10 +232,10 @@ describe "String#sub with pattern and block" do
offsets = []
str.sub(/([aeiou])/) do
- md = $~
- md.string.should == str
- offsets << md.offset(0)
- str
+ md = $~
+ md.string.should == str
+ offsets << md.offset(0)
+ str
end.should == "hhellollo"
offsets.should == [[1, 2]]
@@ -284,41 +276,15 @@ describe "String#sub with pattern and block" do
obj.should_receive(:to_s).and_return("ok")
"hello".sub(/.+/) { obj }.should == "ok"
end
-
- it "taints the result if the original string or replacement is tainted" do
- hello = "hello"
- hello_t = "hello"
- a = "a"
- a_t = "a"
- empty = ""
- empty_t = ""
-
- hello_t.taint; a_t.taint; empty_t.taint
-
- hello_t.sub(/./) { a }.tainted?.should == true
- hello_t.sub(/./) { empty }.tainted?.should == true
-
- hello.sub(/./) { a_t }.tainted?.should == true
- hello.sub(/./) { empty_t }.tainted?.should == true
- hello.sub(//) { empty_t }.tainted?.should == true
-
- hello.sub(//.taint) { "foo" }.tainted?.should == false
- end
end
describe "String#sub! with pattern, replacement" do
it "modifies self in place and returns self" do
a = "hello"
- a.sub!(/[aeiou]/, '*').should equal(a)
+ a.sub!(/[aeiou]/, '*').should.equal?(a)
a.should == "h*llo"
end
- it "taints self if replacement is tainted" do
- a = "hello"
- a.sub!(/./.taint, "foo").tainted?.should == false
- a.sub!(/./, "foo".taint).tainted?.should == true
- end
-
it "returns nil if no modifications were made" do
a = "hello"
a.sub!(/z/, '*').should == nil
@@ -326,20 +292,41 @@ describe "String#sub! with pattern, replacement" do
a.should == "hello"
end
- it "raises a RuntimeError when self is frozen" do
+ it "raises a FrozenError when self is frozen" do
s = "hello"
s.freeze
- lambda { s.sub!(/ROAR/, "x") }.should raise_error(RuntimeError)
- lambda { s.sub!(/e/, "e") }.should raise_error(RuntimeError)
- lambda { s.sub!(/[aeiou]/, '*') }.should raise_error(RuntimeError)
+ -> { s.sub!(/ROAR/, "x") }.should.raise(FrozenError)
+ -> { s.sub!(/e/, "e") }.should.raise(FrozenError)
+ -> { s.sub!(/[aeiou]/, '*') }.should.raise(FrozenError)
+ end
+
+ it "handles a pattern in a superset encoding" do
+ string = 'abc'.force_encoding(Encoding::US_ASCII)
+
+ result = string.sub!('é', 'è')
+
+ result.should == nil
+ string.should == 'abc'
+ string.encoding.should == Encoding::US_ASCII
+ end
+
+ it "handles a pattern in a subset encoding" do
+ string = 'été'
+ pattern = 't'.force_encoding(Encoding::US_ASCII)
+
+ result = string.sub!(pattern, 'u')
+
+ result.should == string
+ string.should == 'éué'
+ string.encoding.should == Encoding::UTF_8
end
end
describe "String#sub! with pattern and block" do
it "modifies self in place and returns self" do
a = "hello"
- a.sub!(/[aeiou]/) { '*' }.should equal(a)
+ a.sub!(/[aeiou]/) { '*' }.should.equal?(a)
a.should == "h*llo"
end
@@ -352,21 +339,15 @@ describe "String#sub! with pattern and block" do
offsets = []
str.dup.sub!(/([aeiou])/) do
- md = $~
- md.string.should == str
- offsets << md.offset(0)
- str
+ md = $~
+ md.string.should == str
+ offsets << md.offset(0)
+ str
end.should == "hhellollo"
offsets.should == [[1, 2]]
end
- it "taints self if block's result is tainted" do
- a = "hello"
- a.sub!(/./.taint) { "foo" }.tainted?.should == false
- a.sub!(/./) { "foo".taint }.tainted?.should == true
- end
-
it "returns nil if no modifications were made" do
a = "hello"
a.sub!(/z/) { '*' }.should == nil
@@ -376,16 +357,16 @@ describe "String#sub! with pattern and block" do
it "raises a RuntimeError if the string is modified while substituting" do
str = "hello"
- lambda { str.sub!(//) { str << 'x' } }.should raise_error(RuntimeError)
+ -> { str.sub!(//) { str << 'x' } }.should.raise(RuntimeError)
end
- it "raises a RuntimeError when self is frozen" do
+ it "raises a FrozenError when self is frozen" do
s = "hello"
s.freeze
- lambda { s.sub!(/ROAR/) { "x" } }.should raise_error(RuntimeError)
- lambda { s.sub!(/e/) { "e" } }.should raise_error(RuntimeError)
- lambda { s.sub!(/[aeiou]/) { '*' } }.should raise_error(RuntimeError)
+ -> { s.sub!(/ROAR/) { "x" } }.should.raise(FrozenError)
+ -> { s.sub!(/e/) { "e" } }.should.raise(FrozenError)
+ -> { s.sub!(/[aeiou]/) { '*' } }.should.raise(FrozenError)
end
end
@@ -428,7 +409,7 @@ describe "String#sub with pattern and Hash" do
it "uses the hash's value set from default_proc for missing keys" do
hsh = {}
- hsh.default_proc = lambda { |k,v| 'lamb' }
+ hsh.default_proc = -> k, v { 'lamb' }
"food!".sub(/./, hsh).should == "lambood!"
end
@@ -452,26 +433,6 @@ describe "String#sub with pattern and Hash" do
"hello".sub(/(.+)/, 'hello' => repl ).should == repl
end
- it "untrusts the result if the original string is untrusted" do
- str = "Ghana".untrust
- str.sub(/[Aa]na/, 'ana' => '').untrusted?.should be_true
- end
-
- it "untrusts the result if a hash value is untrusted" do
- str = "Ghana"
- str.sub(/a$/, 'a' => 'di'.untrust).untrusted?.should be_true
- end
-
- it "taints the result if the original string is tainted" do
- str = "Ghana".taint
- str.sub(/[Aa]na/, 'ana' => '').tainted?.should be_true
- end
-
- it "taints the result if a hash value is tainted" do
- str = "Ghana"
- str.sub(/a$/, 'a' => 'di'.taint).tainted?.should be_true
- end
-
end
describe "String#sub! with pattern and Hash" do
@@ -513,7 +474,7 @@ describe "String#sub! with pattern and Hash" do
it "uses the hash's value set from default_proc for missing keys" do
hsh = {}
- hsh.default_proc = lambda { |k,v| 'lamb' }
+ hsh.default_proc = -> k, v { 'lamb' }
"food!".sub!(/./, hsh).should == "lambood!"
end
@@ -536,36 +497,16 @@ describe "String#sub! with pattern and Hash" do
repl = '\& \0 \1 \` \\\' \+ \\\\ foo'
"hello".sub!(/(.+)/, 'hello' => repl ).should == repl
end
-
- it "keeps untrusted state" do
- str = "Ghana".untrust
- str.sub!(/[Aa]na/, 'ana' => '').untrusted?.should be_true
- end
-
- it "untrusts self if a hash value is untrusted" do
- str = "Ghana"
- str.sub!(/a$/, 'a' => 'di'.untrust).untrusted?.should be_true
- end
-
- it "keeps tainted state" do
- str = "Ghana".taint
- str.sub!(/[Aa]na/, 'ana' => '').tainted?.should be_true
- end
-
- it "taints self if a hash value is tainted" do
- str = "Ghana"
- str.sub!(/a$/, 'a' => 'di'.taint).tainted?.should be_true
- end
end
describe "String#sub with pattern and without replacement and block" do
it "raises a ArgumentError" do
- lambda { "abca".sub(/a/) }.should raise_error(ArgumentError)
+ -> { "abca".sub(/a/) }.should.raise(ArgumentError)
end
end
describe "String#sub! with pattern and without replacement and block" do
it "raises a ArgumentError" do
- lambda { "abca".sub!(/a/) }.should raise_error(ArgumentError)
+ -> { "abca".sub!(/a/) }.should.raise(ArgumentError)
end
end
diff --git a/spec/ruby/core/string/succ_spec.rb b/spec/ruby/core/string/succ_spec.rb
index 311453702d..87beca8b09 100644
--- a/spec/ruby/core/string/succ_spec.rb
+++ b/spec/ruby/core/string/succ_spec.rb
@@ -1,11 +1,90 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes.rb', __FILE__)
-require File.expand_path('../shared/succ.rb', __FILE__)
+# encoding: binary
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "String#succ" do
- it_behaves_like(:string_succ, :succ)
+ it "returns an empty string for empty strings" do
+ "".succ.should == ""
+ end
+
+ it "returns the successor by increasing the rightmost alphanumeric (digit => digit, letter => letter with same case)" do
+ "abcd".succ.should == "abce"
+ "THX1138".succ.should == "THX1139"
+
+ "<<koala>>".succ.should == "<<koalb>>"
+ "==A??".succ.should == "==B??"
+ end
+
+ it "increases non-alphanumerics (via ascii rules) if there are no alphanumerics" do
+ "***".succ.should == "**+"
+ "**`".succ.should == "**a"
+ end
+
+ it "increases the next best alphanumeric (jumping over non-alphanumerics) if there is a carry" do
+ "dz".succ.should == "ea"
+ "HZ".succ.should == "IA"
+ "49".succ.should == "50"
+
+ "izz".succ.should == "jaa"
+ "IZZ".succ.should == "JAA"
+ "699".succ.should == "700"
+
+ "6Z99z99Z".succ.should == "7A00a00A"
+
+ "1999zzz".succ.should == "2000aaa"
+ "NZ/[]ZZZ9999".succ.should == "OA/[]AAA0000"
+ end
+
+ it "increases the next best character if there is a carry for non-alphanumerics" do
+ "(\xFF".succ.should == ")\x00"
+ "`\xFF".succ.should == "a\x00"
+ "<\xFF\xFF".succ.should == "=\x00\x00"
+ end
+
+ it "adds an additional character (just left to the last increased one) if there is a carry and no character left to increase" do
+ "z".succ.should == "aa"
+ "Z".succ.should == "AA"
+ "9".succ.should == "10"
+
+ "zz".succ.should == "aaa"
+ "ZZ".succ.should == "AAA"
+ "99".succ.should == "100"
+
+ "9Z99z99Z".succ.should == "10A00a00A"
+
+ "ZZZ9999".succ.should == "AAAA0000"
+ "/[]9999".succ.should == "/[]10000"
+ "/[]ZZZ9999".succ.should == "/[]AAAA0000"
+ "Z/[]ZZZ9999".succ.should == "AA/[]AAA0000"
+
+ # non-alphanumeric cases
+ "\xFF".succ.should == "\x01\x00"
+ "\xFF\xFF".succ.should == "\x01\x00\x00"
+ end
+
+ it "returns String instances when called on a subclass" do
+ StringSpecs::MyString.new("").succ.should.instance_of?(String)
+ StringSpecs::MyString.new("a").succ.should.instance_of?(String)
+ StringSpecs::MyString.new("z").succ.should.instance_of?(String)
+ end
+
+ it "returns a String in the same encoding as self" do
+ "z".encode("US-ASCII").succ.encoding.should == Encoding::US_ASCII
+ end
end
describe "String#succ!" do
- it_behaves_like(:string_succ_bang, :"succ!")
+ it "is equivalent to succ, but modifies self in place (still returns self)" do
+ ["", "abcd", "THX1138"].each do |s|
+ s = +s
+ r = s.dup.succ!
+ s.succ!.should.equal?(s)
+ s.should == r
+ end
+ end
+
+ it "raises a FrozenError if self is frozen" do
+ -> { "".freeze.succ! }.should.raise(FrozenError)
+ -> { "abcd".freeze.succ! }.should.raise(FrozenError)
+ end
end
diff --git a/spec/ruby/core/string/sum_spec.rb b/spec/ruby/core/string/sum_spec.rb
index 2d68668f49..c283b7c254 100644
--- a/spec/ruby/core/string/sum_spec.rb
+++ b/spec/ruby/core/string/sum_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes.rb', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "String#sum" do
it "returns a basic n-bit checksum of the characters in self" do
diff --git a/spec/ruby/core/string/swapcase_spec.rb b/spec/ruby/core/string/swapcase_spec.rb
index c2b583acab..f0e6e0182c 100644
--- a/spec/ruby/core/string/swapcase_spec.rb
+++ b/spec/ruby/core/string/swapcase_spec.rb
@@ -1,52 +1,179 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes.rb', __FILE__)
+# frozen_string_literal: false
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "String#swapcase" do
it "returns a new string with all uppercase chars from self converted to lowercase and vice versa" do
- "Hello".swapcase.should == "hELLO"
- "cYbEr_PuNk11".swapcase.should == "CyBeR_pUnK11"
- "+++---111222???".swapcase.should == "+++---111222???"
+ "Hello".swapcase.should == "hELLO"
+ "cYbEr_PuNk11".swapcase.should == "CyBeR_pUnK11"
+ "+++---111222???".swapcase.should == "+++---111222???"
end
- it "taints resulting string when self is tainted" do
- "".taint.swapcase.tainted?.should == true
- "hello".taint.swapcase.tainted?.should == true
+ it "returns a String in the same encoding as self" do
+ "Hello".encode("US-ASCII").swapcase.encoding.should == Encoding::US_ASCII
end
- ruby_version_is ''...'2.4' do
- it "is locale insensitive (only upcases a-z and only downcases A-Z)" do
- "ÄÖÜ".swapcase.should == "ÄÖÜ"
- "ärger".swapcase.should == "äRGER"
- "BÄR".swapcase.should == "bÄr"
+ describe "full Unicode case mapping" do
+ it "works for all of Unicode with no option" do
+ "äÖü".swapcase.should == "ÄöÜ"
+ end
+
+ it "updates string metadata" do
+ swapcased = "Aßet".swapcase
+
+ swapcased.should == "aSSET"
+ swapcased.size.should == 5
+ swapcased.bytesize.should == 5
+ swapcased.ascii_only?.should == true
end
end
- ruby_version_is '2.4' do
- it "works for all of Unicode" do
- "äÖü".swapcase.should == "ÄöÜ"
+ describe "ASCII-only case mapping" do
+ it "does not swapcase non-ASCII characters" do
+ "aßet".swapcase(:ascii).should == "AßET"
+ end
+
+ it "works with substrings" do
+ "prefix aTé"[-3..-1].swapcase(:ascii).should == "Até"
+ end
+ end
+
+ describe "full Unicode case mapping adapted for Turkic languages" do
+ it "swaps case of ASCII characters according to Turkic semantics" do
+ "aiS".swapcase(:turkic).should == "Aİs"
+ end
+
+ it "allows Lithuanian as an extra option" do
+ "aiS".swapcase(:turkic, :lithuanian).should == "Aİs"
+ end
+
+ it "does not allow any other additional option" do
+ -> { "aiS".swapcase(:turkic, :ascii) }.should.raise(ArgumentError)
end
end
- it "returns subclass instances when called on a subclass" do
- StringSpecs::MyString.new("").swapcase.should be_an_instance_of(StringSpecs::MyString)
- StringSpecs::MyString.new("hello").swapcase.should be_an_instance_of(StringSpecs::MyString)
+ describe "full Unicode case mapping adapted for Lithuanian" do
+ it "currently works the same as full Unicode case mapping" do
+ "Iß".swapcase(:lithuanian).should == "iSS"
+ end
+
+ it "allows Turkic as an extra option (and applies Turkic semantics)" do
+ "iS".swapcase(:lithuanian, :turkic).should == "İs"
+ end
+
+ it "does not allow any other additional option" do
+ -> { "aiS".swapcase(:lithuanian, :ascii) }.should.raise(ArgumentError)
+ end
+ end
+
+ it "does not allow the :fold option for upcasing" do
+ -> { "abc".swapcase(:fold) }.should.raise(ArgumentError)
+ end
+
+ it "does not allow invalid options" do
+ -> { "abc".swapcase(:invalid_option) }.should.raise(ArgumentError)
+ end
+
+ it "returns String instances when called on a subclass" do
+ StringSpecs::MyString.new("").swapcase.should.instance_of?(String)
+ StringSpecs::MyString.new("hello").swapcase.should.instance_of?(String)
end
end
describe "String#swapcase!" do
it "modifies self in place" do
a = "cYbEr_PuNk11"
- a.swapcase!.should equal(a)
+ a.swapcase!.should.equal?(a)
a.should == "CyBeR_pUnK11"
end
- ruby_version_is '2.4' do
- it "modifies self in place for all of Unicode" do
+ it "modifies self in place for non-ascii-compatible encodings" do
+ a = "cYbEr_PuNk11".encode("utf-16le")
+ a.swapcase!
+ a.should == "CyBeR_pUnK11".encode("utf-16le")
+ end
+
+ describe "full Unicode case mapping" do
+ it "modifies self in place for all of Unicode with no option" do
a = "äÖü"
- a.swapcase!.should equal(a)
+ a.swapcase!
a.should == "ÄöÜ"
end
+
+ it "works for non-ascii-compatible encodings" do
+ a = "äÖü".encode("utf-16le")
+ a.swapcase!
+ a.should == "ÄöÜ".encode("utf-16le")
+ end
+
+ it "updates string metadata" do
+ swapcased = "Aßet"
+ swapcased.swapcase!
+
+ swapcased.should == "aSSET"
+ swapcased.size.should == 5
+ swapcased.bytesize.should == 5
+ swapcased.ascii_only?.should == true
+ end
+ end
+
+ describe "modifies self in place for ASCII-only case mapping" do
+ it "does not swapcase non-ASCII characters" do
+ a = "aßet"
+ a.swapcase!(:ascii)
+ a.should == "AßET"
+ end
+
+ it "works for non-ascii-compatible encodings" do
+ a = "aBc".encode("utf-16le")
+ a.swapcase!(:ascii)
+ a.should == "AbC".encode("utf-16le")
+ end
+ end
+
+ describe "modifies self in place for full Unicode case mapping adapted for Turkic languages" do
+ it "swaps case of ASCII characters according to Turkic semantics" do
+ a = "aiS"
+ a.swapcase!(:turkic)
+ a.should == "Aİs"
+ end
+
+ it "allows Lithuanian as an extra option" do
+ a = "aiS"
+ a.swapcase!(:turkic, :lithuanian)
+ a.should == "Aİs"
+ end
+
+ it "does not allow any other additional option" do
+ -> { a = "aiS"; a.swapcase!(:turkic, :ascii) }.should.raise(ArgumentError)
+ end
+ end
+
+ describe "full Unicode case mapping adapted for Lithuanian" do
+ it "currently works the same as full Unicode case mapping" do
+ a = "Iß"
+ a.swapcase!(:lithuanian)
+ a.should == "iSS"
+ end
+
+ it "allows Turkic as an extra option (and applies Turkic semantics)" do
+ a = "iS"
+ a.swapcase!(:lithuanian, :turkic)
+ a.should == "İs"
+ end
+
+ it "does not allow any other additional option" do
+ -> { a = "aiS"; a.swapcase!(:lithuanian, :ascii) }.should.raise(ArgumentError)
+ end
+ end
+
+ it "does not allow the :fold option for upcasing" do
+ -> { a = "abc"; a.swapcase!(:fold) }.should.raise(ArgumentError)
+ end
+
+ it "does not allow invalid options" do
+ -> { a = "abc"; a.swapcase!(:invalid_option) }.should.raise(ArgumentError)
end
it "returns nil if no modifications were made" do
@@ -57,10 +184,10 @@ describe "String#swapcase!" do
"".swapcase!.should == nil
end
- it "raises a RuntimeError when self is frozen" do
+ it "raises a FrozenError when self is frozen" do
["", "hello"].each do |a|
a.freeze
- lambda { a.swapcase! }.should raise_error(RuntimeError)
+ -> { a.swapcase! }.should.raise(FrozenError)
end
end
end
diff --git a/spec/ruby/core/string/to_c_spec.rb b/spec/ruby/core/string/to_c_spec.rb
index da353e18d5..9cd0ed4401 100644
--- a/spec/ruby/core/string/to_c_spec.rb
+++ b/spec/ruby/core/string/to_c_spec.rb
@@ -1,99 +1,53 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../../shared/kernel/complex'
+require_relative 'fixtures/to_c'
describe "String#to_c" do
- it "returns a Complex object" do
- '9'.to_c.should be_an_instance_of(Complex)
- end
-
- it "understands integers" do
- '20'.to_c.should == Complex(20)
- end
-
- it "understands negative integers" do
- '-3'.to_c.should == Complex(-3)
- end
-
- it "understands fractions (numerator/denominator) for the real part" do
- '2/3'.to_c.should == Complex(Rational(2, 3))
- end
-
- it "understands fractions (numerator/denominator) for the imaginary part" do
- '4+2/3i'.to_c.should == Complex(4, Rational(2, 3))
- end
-
- it "understands negative fractions (-numerator/denominator) for the real part" do
- '-2/3'.to_c.should == Complex(Rational(-2, 3))
- end
-
- it "understands negative fractions (-numerator/denominator) for the imaginary part" do
- '7-2/3i'.to_c.should == Complex(7, Rational(-2, 3))
- end
-
- it "understands floats (a.b) for the real part" do
- '2.3'.to_c.should == Complex(2.3)
- end
-
- it "understands floats (a.b) for the imaginary part" do
- '4+2.3i'.to_c.should == Complex(4, 2.3)
- end
-
- it "understands negative floats (-a.b) for the real part" do
- '-2.33'.to_c.should == Complex(-2.33)
- end
-
- it "understands negative floats (-a.b) for the imaginary part" do
- '7-28.771i'.to_c.should == Complex(7, -28.771)
- end
-
- it "understands an integer followed by 'i' to mean that integer is the imaginary part" do
- '35i'.to_c.should == Complex(0,35)
- end
-
- it "understands a negative integer followed by 'i' to mean that negative integer is the imaginary part" do
- '-29i'.to_c.should == Complex(0,-29)
- end
-
- it "understands an 'i' by itself as denoting a complex number with an imaginary part of 1" do
- 'i'.to_c.should == Complex(0,1)
- end
-
- it "understands a '-i' by itself as denoting a complex number with an imaginary part of -1" do
- '-i'.to_c.should == Complex(0,-1)
- end
-
- it "understands 'a+bi' to mean a complex number with 'a' as the real part, 'b' as the imaginary" do
- '79+4i'.to_c.should == Complex(79,4)
- end
+ it_behaves_like :kernel_complex, :to_c_method, StringSpecs
+end
- it "understands 'a-bi' to mean a complex number with 'a' as the real part, '-b' as the imaginary" do
- '79-4i'.to_c.should == Complex(79,-4)
+describe "String#to_c" do
+ it "returns a complex number with 0 as the real part, 0 as the imaginary part for unrecognised Strings" do
+ 'ruby'.to_c.should == Complex(0, 0)
end
- it "understands scientific notation for the real part" do
- '2e3+4i'.to_c.should == Complex(2e3,4)
+ it "ignores trailing garbage" do
+ '79+4iruby'.to_c.should == Complex(79, 4)
+ '7__9+4__0i'.to_c.should == Complex(7, 0)
end
- it "understands negative scientific notation for the real part" do
- '-2e3+4i'.to_c.should == Complex(-2e3,4)
- end
+ context "it treats special float value strings as characters" do
+ it "parses any string that starts with 'I' as 1i" do
+ 'Infinity'.to_c.should == Complex(0, 1)
+ '-Infinity'.to_c.should == Complex(0, -1)
+ 'Insecure'.to_c.should == Complex(0, 1)
+ '-Insecure'.to_c.should == Complex(0, -1)
+ end
- it "understands scientific notation for the imaginary part" do
- '4+2e3i'.to_c.should == Complex(4, 2e3)
+ it "does not parse any numeric information in 'NaN'" do
+ 'NaN'.to_c.should == Complex(0, 0)
+ end
end
- it "understands negative scientific notation for the imaginary part" do
- '4-2e3i'.to_c.should == Complex(4, -2e3)
+ it "allows null-byte" do
+ "1-2i\0".to_c.should == Complex(1, -2)
+ "1\0-2i".to_c.should == Complex(1, 0)
+ "\01-2i".to_c.should == Complex(0, 0)
end
- it "understands scientific notation for the real and imaginary part in the same String" do
- '2e3+2e4i'.to_c.should == Complex(2e3,2e4)
+ it "raises Encoding::CompatibilityError if String is in not ASCII-compatible encoding" do
+ -> {
+ '79+4i'.encode("UTF-16").to_c
+ }.should.raise(Encoding::CompatibilityError, "ASCII incompatible encoding: UTF-16")
end
- it "understands negative scientific notation for the real and imaginary part in the same String" do
- '-2e3-2e4i'.to_c.should == Complex(-2e3,-2e4)
- end
+ it "treats a sequence of underscores as an end of Complex string" do
+ "5+3_1i".to_c.should == Complex(5, 31)
+ "5+3__1i".to_c.should == Complex(5)
+ "5+3___1i".to_c.should == Complex(5)
- it "returns a complex number with 0 as the real part, 0 as the imaginary part for unrecognised Strings" do
- 'ruby'.to_c.should == Complex(0,0)
+ "12_3".to_c.should == Complex(123)
+ "12__3".to_c.should == Complex(12)
+ "12___3".to_c.should == Complex(12)
end
end
diff --git a/spec/ruby/core/string/to_f_spec.rb b/spec/ruby/core/string/to_f_spec.rb
index 8454651ab2..bb09e4f2f3 100644
--- a/spec/ruby/core/string/to_f_spec.rb
+++ b/spec/ruby/core/string/to_f_spec.rb
@@ -1,19 +1,19 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes.rb', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
# src.scan(/[+-]?[\d_]+\.[\d_]+(e[+-]?[\d_]+)?\b|[+-]?[\d_]+e[+-]?[\d_]+\b/i)
describe "String#to_f" do
it "treats leading characters of self as a floating point number" do
- "123.45e1".to_f.should == 1234.5
- "45.67 degrees".to_f.should == 45.67
- "0".to_f.should == 0.0
- "123.45e1".to_f.should == 1234.5
+ "123.45e1".to_f.should == 1234.5
+ "45.67 degrees".to_f.should == 45.67
+ "0".to_f.should == 0.0
- ".5".to_f.should == 0.5
- ".5e1".to_f.should == 5.0
- "5e".to_f.should == 5.0
- "5E".to_f.should == 5.0
+ ".5".to_f.should == 0.5
+ ".5e1".to_f.should == 5.0
+ "5.".to_f.should == 5.0
+ "5e".to_f.should == 5.0
+ "5E".to_f.should == 5.0
end
it "treats special float value strings as characters" do
@@ -42,18 +42,39 @@ describe "String#to_f" do
"1_234_567.890_1".to_f.should == 1_234_567.890_1
end
- it "returns 0 for strings with any non-digit in them" do
- "blah".to_f.should == 0
- "0b5".to_f.should == 0
- "0d5".to_f.should == 0
- "0o5".to_f.should == 0
- "0xx5".to_f.should == 0
- end
-
it "returns 0 for strings with leading underscores" do
"_9".to_f.should == 0
end
+ it "stops if the underscore is not followed or preceded by a number" do
+ "1__2".to_f.should == 1.0
+ "1_.2".to_f.should == 1.0
+ "1._2".to_f.should == 1.0
+ "1.2_e2".to_f.should == 1.2
+ "1.2e_2".to_f.should == 1.2
+ "1_x2".to_f.should == 1.0
+ "1x_2".to_f.should == 1.0
+ "+_1".to_f.should == 0.0
+ "-_1".to_f.should == 0.0
+ end
+
+ it "does not allow prefixes to autodetect the base" do
+ "0b10".to_f.should == 0
+ "010".to_f.should == 10
+ "0o10".to_f.should == 0
+ "0d10".to_f.should == 0
+ "0x10".to_f.should == 0
+ end
+
+ it "treats any non-numeric character other than '.', 'e' and '_' as terminals" do
+ "blah".to_f.should == 0
+ "1b5".to_f.should == 1
+ "1d5".to_f.should == 1
+ "1o5".to_f.should == 1
+ "1xx5".to_f.should == 1
+ "x5".to_f.should == 0
+ end
+
it "takes an optional sign" do
"-45.67 degrees".to_f.should == -45.67
"+45.67 degrees".to_f.should == 45.67
@@ -62,8 +83,58 @@ describe "String#to_f" do
(1.0 / "-0".to_f).to_s.should == "-Infinity"
end
+ it "treats a second 'e' as terminal" do
+ "1.234e1e2".to_f.should == 1.234e1
+ end
+
+ it "treats a second '.' as terminal" do
+ "1.2.3".to_f.should == 1.2
+ end
+
+ it "treats a '.' after an 'e' as terminal" do
+ "1.234e1.9".to_f.should == 1.234e1
+ end
+
it "returns 0.0 if the conversion fails" do
"bad".to_f.should == 0.0
"thx1138".to_f.should == 0.0
end
+
+ it "ignores leading and trailing whitespace" do
+ " 1.2".to_f.should == 1.2
+ "1.2 ".to_f.should == 1.2
+ " 1.2 ".to_f.should == 1.2
+ "\t1.2".to_f.should == 1.2
+ "\n1.2".to_f.should == 1.2
+ "\v1.2".to_f.should == 1.2
+ "\f1.2".to_f.should == 1.2
+ "\r1.2".to_f.should == 1.2
+ end
+
+ it "treats non-printable ASCII characters as terminals" do
+ "\0001.2".to_f.should == 0
+ "\0011.2".to_f.should == 0
+ "\0371.2".to_f.should == 0
+ "\1771.2".to_f.should == 0
+ "\2001.2".b.to_f.should == 0
+ "\3771.2".b.to_f.should == 0
+ end
+
+ it "raises Encoding::CompatibilityError if String is in not ASCII-compatible encoding" do
+ -> {
+ '1.2'.encode("UTF-16").to_f
+ }.should.raise(Encoding::CompatibilityError, "ASCII incompatible encoding: UTF-16")
+ end
+
+ it "allows String representation without a fractional part" do
+ "1.".to_f.should == 1.0
+ "+1.".to_f.should == 1.0
+ "-1.".to_f.should == -1.0
+ "1.e+0".to_f.should == 1.0
+ "1.e+0".to_f.should == 1.0
+
+ ruby_bug "#20705", ""..."3.4" do
+ "1.e-2".to_f.should be_close(0.01, TOLERANCE)
+ end
+ end
end
diff --git a/spec/ruby/core/string/to_i_spec.rb b/spec/ruby/core/string/to_i_spec.rb
index be0f67a46a..629750bd73 100644
--- a/spec/ruby/core/string/to_i_spec.rb
+++ b/spec/ruby/core/string/to_i_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes.rb', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "String#to_i" do
it "returns 0 for strings with leading underscores" do
@@ -10,6 +10,18 @@ describe "String#to_i" do
"1_2_3asdf".to_i.should == 123
end
+ it "ignores multiple non-consecutive underscores when the first digit is 0" do
+ (2..16).each do |base|
+ "0_0_010".to_i(base).should == base;
+ end
+ end
+
+ it "bails out at the first double underscore if the first digit is 0" do
+ (2..16).each do |base|
+ "010__1".to_i(base).should == base;
+ end
+ end
+
it "ignores leading whitespaces" do
[ " 123", " 123", "\r\n\r\n123", "\t\t123",
"\r\n\t\n123", " \t\n\r\t 123"].each do |str|
@@ -126,34 +138,34 @@ describe "String#to_i" do
end
it "raises an ArgumentError for illegal bases (1, < 0 or > 36)" do
- lambda { "".to_i(1) }.should raise_error(ArgumentError)
- lambda { "".to_i(-1) }.should raise_error(ArgumentError)
- lambda { "".to_i(37) }.should raise_error(ArgumentError)
+ -> { "".to_i(1) }.should.raise(ArgumentError)
+ -> { "".to_i(-1) }.should.raise(ArgumentError)
+ -> { "".to_i(37) }.should.raise(ArgumentError)
end
- it "returns a Fixnum for long strings with trailing spaces" do
+ it "returns an Integer for long strings with trailing spaces" do
"0 ".to_i.should == 0
- "0 ".to_i.should be_an_instance_of(Fixnum)
+ "0 ".to_i.should.instance_of?(Integer)
"10 ".to_i.should == 10
- "10 ".to_i.should be_an_instance_of(Fixnum)
+ "10 ".to_i.should.instance_of?(Integer)
"-10 ".to_i.should == -10
- "-10 ".to_i.should be_an_instance_of(Fixnum)
+ "-10 ".to_i.should.instance_of?(Integer)
end
- it "returns a Fixnum for long strings with leading spaces" do
+ it "returns an Integer for long strings with leading spaces" do
" 0".to_i.should == 0
- " 0".to_i.should be_an_instance_of(Fixnum)
+ " 0".to_i.should.instance_of?(Integer)
" 10".to_i.should == 10
- " 10".to_i.should be_an_instance_of(Fixnum)
+ " 10".to_i.should.instance_of?(Integer)
" -10".to_i.should == -10
- " -10".to_i.should be_an_instance_of(Fixnum)
+ " -10".to_i.should.instance_of?(Integer)
end
- it "returns the correct Bignum for long strings" do
+ it "returns the correct Integer for long strings" do
"245789127594125924165923648312749312749327482".to_i.should == 245789127594125924165923648312749312749327482
"-245789127594125924165923648312749312749327482".to_i.should == -245789127594125924165923648312749312749327482
end
diff --git a/spec/ruby/core/string/to_r_spec.rb b/spec/ruby/core/string/to_r_spec.rb
index 7fa16f6f49..fb7c9d108e 100644
--- a/spec/ruby/core/string/to_r_spec.rb
+++ b/spec/ruby/core/string/to_r_spec.rb
@@ -1,8 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "String#to_r" do
it "returns a Rational object" do
- String.new.to_r.should be_an_instance_of(Rational)
+ String.new.to_r.should.instance_of?(Rational)
end
it "returns (0/1) for the empty String" do
@@ -29,10 +29,14 @@ describe "String#to_r" do
"a1765, ".to_r.should_not == Rational(1765, 1)
end
- it "treats leading hypens as minus signs" do
+ it "treats leading hyphen as minus signs" do
"-20".to_r.should == Rational(-20, 1)
end
+ it "accepts leading plus signs" do
+ "+20".to_r.should == Rational(20, 1)
+ end
+
it "does not treat a leading period without a numeric prefix as a decimal point" do
".9".to_r.should_not == Rational(8106479329266893, 9007199254740992)
end
diff --git a/spec/ruby/core/string/to_s_spec.rb b/spec/ruby/core/string/to_s_spec.rb
index b483b1b138..c48c7f89ac 100644
--- a/spec/ruby/core/string/to_s_spec.rb
+++ b/spec/ruby/core/string/to_s_spec.rb
@@ -1,7 +1,16 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes.rb', __FILE__)
-require File.expand_path('../shared/to_s.rb', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "String#to_s" do
- it_behaves_like(:string_to_s, :to_s)
+ it "returns self when self.class == String" do
+ a = "a string"
+ a.should.equal?(a.to_s)
+ end
+
+ it "returns a new instance of String when called on a subclass" do
+ a = StringSpecs::MyString.new("a string")
+ s = a.to_s
+ s.should == "a string"
+ s.should.instance_of?(String)
+ end
end
diff --git a/spec/ruby/core/string/to_str_spec.rb b/spec/ruby/core/string/to_str_spec.rb
index fb1260a687..8253b3d8a3 100644
--- a/spec/ruby/core/string/to_str_spec.rb
+++ b/spec/ruby/core/string/to_str_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes.rb', __FILE__)
-require File.expand_path('../shared/to_s.rb', __FILE__)
+require_relative '../../spec_helper'
describe "String#to_str" do
- it_behaves_like(:string_to_s, :to_str)
+ it "is an alias of String#to_s" do
+ String.instance_method(:to_str).should == String.instance_method(:to_s)
+ end
end
diff --git a/spec/ruby/core/string/to_sym_spec.rb b/spec/ruby/core/string/to_sym_spec.rb
index 7659f266cd..f0ffe58674 100644
--- a/spec/ruby/core/string/to_sym_spec.rb
+++ b/spec/ruby/core/string/to_sym_spec.rb
@@ -1,7 +1,74 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes.rb', __FILE__)
-require File.expand_path('../shared/to_sym.rb', __FILE__)
+require_relative '../../spec_helper'
describe "String#to_sym" do
- it_behaves_like(:string_to_sym, :to_sym)
+ it "returns the symbol corresponding to self" do
+ "Koala".to_sym.should.equal? :Koala
+ 'cat'.to_sym.should.equal? :cat
+ '@cat'.to_sym.should.equal? :@cat
+ 'cat and dog'.to_sym.should.equal? :"cat and dog"
+ "abc=".to_sym.should.equal? :abc=
+ end
+
+ it "does not special case +(binary) and -(binary)" do
+ "+(binary)".to_sym.should.equal? :"+(binary)"
+ "-(binary)".to_sym.should.equal? :"-(binary)"
+ end
+
+ it "does not special case certain operators" do
+ "!@".to_sym.should.equal? :"!@"
+ "~@".to_sym.should.equal? :"~@"
+ "!(unary)".to_sym.should.equal? :"!(unary)"
+ "~(unary)".to_sym.should.equal? :"~(unary)"
+ "+(unary)".to_sym.should.equal? :"+(unary)"
+ "-(unary)".to_sym.should.equal? :"-(unary)"
+ end
+
+ it "returns a US-ASCII Symbol for a UTF-8 String containing only US-ASCII characters" do
+ sym = "foobar".to_sym
+ sym.encoding.should == Encoding::US_ASCII
+ sym.should.equal? :"foobar"
+ end
+
+ it "returns a US-ASCII Symbol for a binary String containing only US-ASCII characters" do
+ sym = "foobar".b.to_sym
+ sym.encoding.should == Encoding::US_ASCII
+ sym.should.equal? :"foobar"
+ end
+
+ it "returns a UTF-8 Symbol for a UTF-8 String containing non US-ASCII characters" do
+ sym = "il était une fois".to_sym
+ sym.encoding.should == Encoding::UTF_8
+ sym.should.equal? :"il était une fois"
+ end
+
+ it "returns a UTF-16LE Symbol for a UTF-16LE String containing non US-ASCII characters" do
+ utf16_str = "UtéF16".encode(Encoding::UTF_16LE)
+ sym = utf16_str.to_sym
+ sym.encoding.should == Encoding::UTF_16LE
+ sym.to_s.should == utf16_str
+ end
+
+ it "returns a binary Symbol for a binary String containing non US-ASCII characters" do
+ binary_string = "binarí".b
+ sym = binary_string.to_sym
+ sym.encoding.should == Encoding::BINARY
+ sym.to_s.should == binary_string
+ end
+
+ it "ignores existing symbols with different encoding" do
+ source = "fée"
+
+ iso_symbol = source.dup.force_encoding(Encoding::ISO_8859_1).to_sym
+ iso_symbol.encoding.should == Encoding::ISO_8859_1
+ binary_symbol = source.dup.force_encoding(Encoding::BINARY).to_sym
+ binary_symbol.encoding.should == Encoding::BINARY
+ end
+
+ it "raises an EncodingError for UTF-8 String containing invalid bytes" do
+ invalid_utf8 = "\xC3"
+ invalid_utf8.should_not.valid_encoding?
+ -> {
+ invalid_utf8.to_sym
+ }.should.raise(EncodingError, 'invalid symbol in encoding UTF-8 :"\xC3"')
+ end
end
diff --git a/spec/ruby/core/string/tr_s_spec.rb b/spec/ruby/core/string/tr_s_spec.rb
index ea2ffa71b9..22a193ec4b 100644
--- a/spec/ruby/core/string/tr_s_spec.rb
+++ b/spec/ruby/core/string/tr_s_spec.rb
@@ -1,6 +1,7 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes.rb', __FILE__)
+# frozen_string_literal: false
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "String#tr_s" do
it "returns a string processed according to tr with newly duplicate characters removed" do
@@ -17,6 +18,13 @@ describe "String#tr_s" do
"hello ^--^".tr_s("---", "_").should == "hello ^_^"
end
+ it "accepts c1-c1 notation to denote range of one character" do
+ "hello".tr_s('e-e', 'x').should == "hxllo"
+ "123456789".tr_s("2-23","xy").should == "1xy456789"
+ "hello ^-^".tr_s("e-", "a-a_").should == "hallo ^_^"
+ "hello ^-^".tr_s("---o", "_a").should == "hella ^_^"
+ end
+
it "pads to_str with its last char if it is shorter than from_string" do
"this".tr_s("this", "x").should == "x"
end
@@ -45,64 +53,51 @@ describe "String#tr_s" do
"bla".tr_s(from_str, to_str).should == "BlA"
end
- it "returns subclass instances when called on a subclass" do
- StringSpecs::MyString.new("hello").tr_s("e", "a").should be_an_instance_of(StringSpecs::MyString)
+ it "returns String instances when called on a subclass" do
+ StringSpecs::MyString.new("hello").tr_s("e", "a").should.instance_of?(String)
end
- it "taints the result when self is tainted" do
- ["h", "hello"].each do |str|
- tainted_str = str.dup.taint
-
- tainted_str.tr_s("e", "a").tainted?.should == true
-
- str.tr_s("e".taint, "a").tainted?.should == false
- str.tr_s("e", "a".taint).tainted?.should == false
- end
+ # http://redmine.ruby-lang.org/issues/show/1839
+ it "can replace a 7-bit ASCII character with a multibyte one" do
+ a = "uber"
+ a.encoding.should == Encoding::UTF_8
+ b = a.tr_s("u","ü")
+ b.should == "über"
+ b.encoding.should == Encoding::UTF_8
end
- with_feature :encoding do
- # http://redmine.ruby-lang.org/issues/show/1839
- it "can replace a 7-bit ASCII character with a multibyte one" do
- a = "uber"
- a.encoding.should == Encoding::UTF_8
- b = a.tr_s("u","ü")
- b.should == "über"
- b.encoding.should == Encoding::UTF_8
- end
-
- it "can replace multiple 7-bit ASCII characters with a multibyte one" do
- a = "uuuber"
- a.encoding.should == Encoding::UTF_8
- b = a.tr_s("u","ü")
- b.should == "über"
- b.encoding.should == Encoding::UTF_8
- end
-
- it "can replace a multibyte character with a single byte one" do
- a = "über"
- a.encoding.should == Encoding::UTF_8
- b = a.tr_s("ü","u")
- b.should == "uber"
- b.encoding.should == Encoding::UTF_8
- end
+ it "can replace multiple 7-bit ASCII characters with a multibyte one" do
+ a = "uuuber"
+ a.encoding.should == Encoding::UTF_8
+ b = a.tr_s("u","ü")
+ b.should == "über"
+ b.encoding.should == Encoding::UTF_8
+ end
- it "can replace multiple multibyte characters with a single byte one" do
- a = "üüüber"
- a.encoding.should == Encoding::UTF_8
- b = a.tr_s("ü","u")
- b.should == "uber"
- b.encoding.should == Encoding::UTF_8
- end
+ it "can replace a multibyte character with a single byte one" do
+ a = "über"
+ a.encoding.should == Encoding::UTF_8
+ b = a.tr_s("ü","u")
+ b.should == "uber"
+ b.encoding.should == Encoding::UTF_8
+ end
- it "does not replace a multibyte character where part of the bytes match the tr string" do
- str = "æ¤Žåæ·±å¤"
- a = "\u0080\u0082\u0083\u0084\u0085\u0086\u0087\u0088\u0089\u008A\u008B\u008C\u008E\u0091\u0092\u0093\u0094\u0095\u0096\u0097\u0098\u0099\u009A\u009B\u009C\u009E\u009F"
- b = "€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“â€â€¢â€“—˜™š›œžŸ"
- str.tr_s(a, b).should == "æ¤Žåæ·±å¤"
- end
+ it "can replace multiple multibyte characters with a single byte one" do
+ a = "üüüber"
+ a.encoding.should == Encoding::UTF_8
+ b = a.tr_s("ü","u")
+ b.should == "uber"
+ b.encoding.should == Encoding::UTF_8
+ end
+ it "does not replace a multibyte character where part of the bytes match the tr string" do
+ str = "æ¤Žåæ·±å¤"
+ a = "\u0080\u0082\u0083\u0084\u0085\u0086\u0087\u0088\u0089\u008A\u008B\u008C\u008E\u0091\u0092\u0093\u0094\u0095\u0096\u0097\u0098\u0099\u009A\u009B\u009C\u009E\u009F"
+ b = "€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“â€â€¢â€“—˜™š›œžŸ"
+ str.tr_s(a, b).should == "æ¤Žåæ·±å¤"
end
+
end
describe "String#tr_s!" do
@@ -127,10 +122,10 @@ describe "String#tr_s!" do
s.should == "hello"
end
- it "raises a RuntimeError if self is frozen" do
+ it "raises a FrozenError if self is frozen" do
s = "hello".freeze
- lambda { s.tr_s!("el", "ar") }.should raise_error(RuntimeError)
- lambda { s.tr_s!("l", "r") }.should raise_error(RuntimeError)
- lambda { s.tr_s!("", "") }.should raise_error(RuntimeError)
+ -> { s.tr_s!("el", "ar") }.should.raise(FrozenError)
+ -> { s.tr_s!("l", "r") }.should.raise(FrozenError)
+ -> { s.tr_s!("", "") }.should.raise(FrozenError)
end
end
diff --git a/spec/ruby/core/string/tr_spec.rb b/spec/ruby/core/string/tr_spec.rb
index 16d2d318e1..cb57c3851e 100644
--- a/spec/ruby/core/string/tr_spec.rb
+++ b/spec/ruby/core/string/tr_spec.rb
@@ -1,6 +1,7 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes.rb', __FILE__)
+# frozen_string_literal: false
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "String#tr" do
it "returns a new string with the characters from from_string replaced by the ones in to_string" do
@@ -16,17 +17,24 @@ describe "String#tr" do
"hello ^-^".tr("---", "_").should == "hello ^_^"
end
+ it "accepts c1-c1 notation to denote range of one character" do
+ "hello".tr('e-e', 'x').should == "hxllo"
+ "123456789".tr("2-23","xy").should == "1xy456789"
+ "hello ^-^".tr("e-", "a-a_").should == "hallo ^_^"
+ "hello ^-^".tr("---o", "_a").should == "hella ^_^"
+ end
+
it "pads to_str with its last char if it is shorter than from_string" do
"this".tr("this", "x").should == "xxxx"
"hello".tr("a-z", "A-H.").should == "HE..."
end
it "raises an ArgumentError a descending range in the replacement as containing just the start character" do
- lambda { "hello".tr("a-y", "z-b") }.should raise_error(ArgumentError)
+ -> { "hello".tr("a-y", "z-b") }.should.raise(ArgumentError)
end
it "raises an ArgumentError a descending range in the source as empty" do
- lambda { "hello".tr("l-a", "z") }.should raise_error(ArgumentError)
+ -> { "hello".tr("l-a", "z") }.should.raise(ArgumentError)
end
it "translates chars not in from_string when it starts with a ^" do
@@ -57,47 +65,34 @@ describe "String#tr" do
"bla".tr(from_str, to_str).should == "BlA"
end
- it "returns subclass instances when called on a subclass" do
- StringSpecs::MyString.new("hello").tr("e", "a").should be_an_instance_of(StringSpecs::MyString)
+ it "returns Stringinstances when called on a subclass" do
+ StringSpecs::MyString.new("hello").tr("e", "a").should.instance_of?(String)
end
- it "taints the result when self is tainted" do
- ["h", "hello"].each do |str|
- tainted_str = str.dup.taint
-
- tainted_str.tr("e", "a").tainted?.should == true
-
- str.tr("e".taint, "a").tainted?.should == false
- str.tr("e", "a".taint).tainted?.should == false
- end
+ # http://redmine.ruby-lang.org/issues/show/1839
+ it "can replace a 7-bit ASCII character with a multibyte one" do
+ a = "uber"
+ a.encoding.should == Encoding::UTF_8
+ b = a.tr("u","ü")
+ b.should == "über"
+ b.encoding.should == Encoding::UTF_8
end
- with_feature :encoding do
- # http://redmine.ruby-lang.org/issues/show/1839
- it "can replace a 7-bit ASCII character with a multibyte one" do
- a = "uber"
- a.encoding.should == Encoding::UTF_8
- b = a.tr("u","ü")
- b.should == "über"
- b.encoding.should == Encoding::UTF_8
- end
-
- it "can replace a multibyte character with a single byte one" do
- a = "über"
- a.encoding.should == Encoding::UTF_8
- b = a.tr("ü","u")
- b.should == "uber"
- b.encoding.should == Encoding::UTF_8
- end
-
- it "does not replace a multibyte character where part of the bytes match the tr string" do
- str = "æ¤Žåæ·±å¤"
- a = "\u0080\u0082\u0083\u0084\u0085\u0086\u0087\u0088\u0089\u008A\u008B\u008C\u008E\u0091\u0092\u0093\u0094\u0095\u0096\u0097\u0098\u0099\u009A\u009B\u009C\u009E\u009F"
- b = "€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“â€â€¢â€“—˜™š›œžŸ"
- str.tr(a, b).should == "æ¤Žåæ·±å¤"
- end
+ it "can replace a multibyte character with a single byte one" do
+ a = "über"
+ a.encoding.should == Encoding::UTF_8
+ b = a.tr("ü","u")
+ b.should == "uber"
+ b.encoding.should == Encoding::UTF_8
+ end
+ it "does not replace a multibyte character where part of the bytes match the tr string" do
+ str = "æ¤Žåæ·±å¤"
+ a = "\u0080\u0082\u0083\u0084\u0085\u0086\u0087\u0088\u0089\u008A\u008B\u008C\u008E\u0091\u0092\u0093\u0094\u0095\u0096\u0097\u0098\u0099\u009A\u009B\u009C\u009E\u009F"
+ b = "€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“â€â€¢â€“—˜™š›œžŸ"
+ str.tr(a, b).should == "æ¤Žåæ·±å¤"
end
+
end
describe "String#tr!" do
@@ -122,10 +117,10 @@ describe "String#tr!" do
s.should == "hello"
end
- it "raises a RuntimeError if self is frozen" do
+ it "raises a FrozenError if self is frozen" do
s = "abcdefghijklmnopqR".freeze
- lambda { s.tr!("cdefg", "12") }.should raise_error(RuntimeError)
- lambda { s.tr!("R", "S") }.should raise_error(RuntimeError)
- lambda { s.tr!("", "") }.should raise_error(RuntimeError)
+ -> { s.tr!("cdefg", "12") }.should.raise(FrozenError)
+ -> { s.tr!("R", "S") }.should.raise(FrozenError)
+ -> { s.tr!("", "") }.should.raise(FrozenError)
end
end
diff --git a/spec/ruby/core/string/try_convert_spec.rb b/spec/ruby/core/string/try_convert_spec.rb
index ce12839c59..0c0219cd2e 100644
--- a/spec/ruby/core/string/try_convert_spec.rb
+++ b/spec/ruby/core/string/try_convert_spec.rb
@@ -1,50 +1,50 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "String.try_convert" do
it "returns the argument if it's a String" do
x = String.new
- String.try_convert(x).should equal(x)
+ String.try_convert(x).should.equal?(x)
end
it "returns the argument if it's a kind of String" do
x = StringSpecs::MyString.new
- String.try_convert(x).should equal(x)
+ String.try_convert(x).should.equal?(x)
end
it "returns nil when the argument does not respond to #to_str" do
- String.try_convert(Object.new).should be_nil
+ String.try_convert(Object.new).should == nil
end
it "sends #to_str to the argument and returns the result if it's nil" do
obj = mock("to_str")
obj.should_receive(:to_str).and_return(nil)
- String.try_convert(obj).should be_nil
+ String.try_convert(obj).should == nil
end
it "sends #to_str to the argument and returns the result if it's a String" do
x = String.new
obj = mock("to_str")
obj.should_receive(:to_str).and_return(x)
- String.try_convert(obj).should equal(x)
+ String.try_convert(obj).should.equal?(x)
end
it "sends #to_str to the argument and returns the result if it's a kind of String" do
x = StringSpecs::MyString.new
obj = mock("to_str")
obj.should_receive(:to_str).and_return(x)
- String.try_convert(obj).should equal(x)
+ String.try_convert(obj).should.equal?(x)
end
it "sends #to_str to the argument and raises TypeError if it's not a kind of String" do
obj = mock("to_str")
obj.should_receive(:to_str).and_return(Object.new)
- lambda { String.try_convert obj }.should raise_error(TypeError)
+ -> { String.try_convert obj }.should raise_consistent_error(TypeError, "can't convert MockObject into String (MockObject#to_str gives Object)")
end
it "does not rescue exceptions raised by #to_str" do
obj = mock("to_str")
obj.should_receive(:to_str).and_raise(RuntimeError)
- lambda { String.try_convert obj }.should raise_error(RuntimeError)
+ -> { String.try_convert obj }.should.raise(RuntimeError)
end
end
diff --git a/spec/ruby/core/string/uminus_spec.rb b/spec/ruby/core/string/uminus_spec.rb
index 53e73b7e67..43abf71d50 100644
--- a/spec/ruby/core/string/uminus_spec.rb
+++ b/spec/ruby/core/string/uminus_spec.rb
@@ -1,21 +1,53 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+# frozen_string_literal: false
+require_relative '../../spec_helper'
-ruby_version_is "2.3" do
- describe 'String#-@' do
- it 'returns self if the String is frozen' do
- input = 'foo'.freeze
- output = -input
+describe 'String#-@' do
+ it 'returns self if the String is frozen' do
+ input = 'foo'.freeze
+ output = -input
- output.equal?(input).should == true
- output.frozen?.should == true
- end
+ output.should.equal?(input)
+ output.should.frozen?
+ end
+
+ it 'returns a frozen copy if the String is not frozen' do
+ input = 'foo'
+ output = -input
+
+ output.should.frozen?
+ output.should_not.equal?(input)
+ output.should == 'foo'
+ end
+
+ 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 "deduplicates frozen strings" do
+ dynamic = %w(this string is frozen).join(' ').freeze
+
+ dynamic.should_not.equal?("this string is frozen".freeze)
+
+ (-dynamic).should.equal?("this string is frozen".freeze)
+ (-dynamic).should.equal?((-"this string is frozen").freeze)
+ end
- it 'returns a frozen copy if the String is not frozen' do
- input = 'foo'
- output = -input
+ it "does not deduplicate a frozen string when it has instance variables" do
+ dynamic = %w(this string is frozen).join(' ')
+ dynamic.instance_variable_set(:@a, 1)
+ dynamic.freeze
- output.frozen?.should == true
- output.should == 'foo'
- end
+ (-dynamic).should_not.equal?("this string is frozen".freeze)
+ (-dynamic).should_not.equal?((-"this string is frozen").freeze)
+ (-dynamic).should.equal?(-dynamic)
end
end
diff --git a/spec/ruby/core/string/undump_spec.rb b/spec/ruby/core/string/undump_spec.rb
new file mode 100644
index 0000000000..8516e24b3b
--- /dev/null
+++ b/spec/ruby/core/string/undump_spec.rb
@@ -0,0 +1,441 @@
+# encoding: utf-8
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe "String#undump" do
+ it "does not take into account if a string is frozen" do
+ '"foo"'.freeze.undump.should_not.frozen?
+ end
+
+ it "always returns String instance" do
+ StringSpecs::MyString.new('"foo"').undump.should.instance_of?(String)
+ end
+
+ it "strips outer \"" do
+ '"foo"'.undump.should == 'foo'
+ end
+
+ it "returns a string with special characters in \\<char> notation replaced with the characters" do
+ [ ['"\\a"', "\a"],
+ ['"\\b"', "\b"],
+ ['"\\t"', "\t"],
+ ['"\\n"', "\n"],
+ ['"\\v"', "\v"],
+ ['"\\f"', "\f"],
+ ['"\\r"', "\r"],
+ ['"\\e"', "\e"]
+ ].should be_computed_by(:undump)
+ end
+
+ it "returns a string with unescaped sequences \" and \\" do
+ [ ['"\\""' , "\""],
+ ['"\\\\"', "\\"]
+ ].should be_computed_by(:undump)
+ end
+
+ it "returns a string with unescaped sequences \\#<char> when # is followed by $, @, {" do
+ [ ['"\\#$PATH"', "\#$PATH"],
+ ['"\\#@a"', "\#@a"],
+ ['"\\#@@a"', "\#@@a"],
+ ['"\\#{a}"', "\#{a}"]
+ ].should be_computed_by(:undump)
+ end
+
+ it "returns a string with # not escaped when followed by any other character" do
+ [ ['"#"', '#'],
+ ['"#1"', '#1']
+ ].should be_computed_by(:undump)
+ end
+
+ it "returns a string with printable non-alphanumeric characters" do
+ [ ['" "', ' '],
+ ['"!"', '!'],
+ ['"$"', '$'],
+ ['"%"', '%'],
+ ['"&"', '&'],
+ ['"\'"', '\''],
+ ['"("', '('],
+ ['")"', ')'],
+ ['"*"', '*'],
+ ['"+"', '+'],
+ ['","', ','],
+ ['"-"', '-'],
+ ['"."', '.'],
+ ['"/"', '/'],
+ ['":"', ':'],
+ ['";"', ';'],
+ ['"<"', '<'],
+ ['"="', '='],
+ ['">"', '>'],
+ ['"?"', '?'],
+ ['"@"', '@'],
+ ['"["', '['],
+ ['"]"', ']'],
+ ['"^"', '^'],
+ ['"_"', '_'],
+ ['"`"', '`'],
+ ['"{"', '{'],
+ ['"|"', '|'],
+ ['"}"', '}'],
+ ['"~"', '~']
+ ].should be_computed_by(:undump)
+ end
+
+ it "returns a string with numeric characters unescaped" do
+ [ ['"0"', "0"],
+ ['"1"', "1"],
+ ['"2"', "2"],
+ ['"3"', "3"],
+ ['"4"', "4"],
+ ['"5"', "5"],
+ ['"6"', "6"],
+ ['"7"', "7"],
+ ['"8"', "8"],
+ ['"9"', "9"],
+ ].should be_computed_by(:undump)
+ end
+
+ it "returns a string with upper-case alpha characters unescaped" do
+ [ ['"A"', 'A'],
+ ['"B"', 'B'],
+ ['"C"', 'C'],
+ ['"D"', 'D'],
+ ['"E"', 'E'],
+ ['"F"', 'F'],
+ ['"G"', 'G'],
+ ['"H"', 'H'],
+ ['"I"', 'I'],
+ ['"J"', 'J'],
+ ['"K"', 'K'],
+ ['"L"', 'L'],
+ ['"M"', 'M'],
+ ['"N"', 'N'],
+ ['"O"', 'O'],
+ ['"P"', 'P'],
+ ['"Q"', 'Q'],
+ ['"R"', 'R'],
+ ['"S"', 'S'],
+ ['"T"', 'T'],
+ ['"U"', 'U'],
+ ['"V"', 'V'],
+ ['"W"', 'W'],
+ ['"X"', 'X'],
+ ['"Y"', 'Y'],
+ ['"Z"', 'Z']
+ ].should be_computed_by(:undump)
+ end
+
+ it "returns a string with lower-case alpha characters unescaped" do
+ [ ['"a"', 'a'],
+ ['"b"', 'b'],
+ ['"c"', 'c'],
+ ['"d"', 'd'],
+ ['"e"', 'e'],
+ ['"f"', 'f'],
+ ['"g"', 'g'],
+ ['"h"', 'h'],
+ ['"i"', 'i'],
+ ['"j"', 'j'],
+ ['"k"', 'k'],
+ ['"l"', 'l'],
+ ['"m"', 'm'],
+ ['"n"', 'n'],
+ ['"o"', 'o'],
+ ['"p"', 'p'],
+ ['"q"', 'q'],
+ ['"r"', 'r'],
+ ['"s"', 's'],
+ ['"t"', 't'],
+ ['"u"', 'u'],
+ ['"v"', 'v'],
+ ['"w"', 'w'],
+ ['"x"', 'x'],
+ ['"y"', 'y'],
+ ['"z"', 'z']
+ ].should be_computed_by(:undump)
+ end
+
+ it "returns a string with \\x notation replaced with non-printing ASCII character" do
+ [ ['"\\x00"', 0000.chr.force_encoding('utf-8')],
+ ['"\\x01"', 0001.chr.force_encoding('utf-8')],
+ ['"\\x02"', 0002.chr.force_encoding('utf-8')],
+ ['"\\x03"', 0003.chr.force_encoding('utf-8')],
+ ['"\\x04"', 0004.chr.force_encoding('utf-8')],
+ ['"\\x05"', 0005.chr.force_encoding('utf-8')],
+ ['"\\x06"', 0006.chr.force_encoding('utf-8')],
+ ['"\\x0E"', 0016.chr.force_encoding('utf-8')],
+ ['"\\x0F"', 0017.chr.force_encoding('utf-8')],
+ ['"\\x10"', 0020.chr.force_encoding('utf-8')],
+ ['"\\x11"', 0021.chr.force_encoding('utf-8')],
+ ['"\\x12"', 0022.chr.force_encoding('utf-8')],
+ ['"\\x13"', 0023.chr.force_encoding('utf-8')],
+ ['"\\x14"', 0024.chr.force_encoding('utf-8')],
+ ['"\\x15"', 0025.chr.force_encoding('utf-8')],
+ ['"\\x16"', 0026.chr.force_encoding('utf-8')],
+ ['"\\x17"', 0027.chr.force_encoding('utf-8')],
+ ['"\\x18"', 0030.chr.force_encoding('utf-8')],
+ ['"\\x19"', 0031.chr.force_encoding('utf-8')],
+ ['"\\x1A"', 0032.chr.force_encoding('utf-8')],
+ ['"\\x1C"', 0034.chr.force_encoding('utf-8')],
+ ['"\\x1D"', 0035.chr.force_encoding('utf-8')],
+ ['"\\x1E"', 0036.chr.force_encoding('utf-8')],
+ ['"\\x1F"', 0037.chr.force_encoding('utf-8')],
+ ['"\\x7F"', 0177.chr.force_encoding('utf-8')],
+ ['"\\x80"', 0200.chr.force_encoding('utf-8')],
+ ['"\\x81"', 0201.chr.force_encoding('utf-8')],
+ ['"\\x82"', 0202.chr.force_encoding('utf-8')],
+ ['"\\x83"', 0203.chr.force_encoding('utf-8')],
+ ['"\\x84"', 0204.chr.force_encoding('utf-8')],
+ ['"\\x85"', 0205.chr.force_encoding('utf-8')],
+ ['"\\x86"', 0206.chr.force_encoding('utf-8')],
+ ['"\\x87"', 0207.chr.force_encoding('utf-8')],
+ ['"\\x88"', 0210.chr.force_encoding('utf-8')],
+ ['"\\x89"', 0211.chr.force_encoding('utf-8')],
+ ['"\\x8A"', 0212.chr.force_encoding('utf-8')],
+ ['"\\x8B"', 0213.chr.force_encoding('utf-8')],
+ ['"\\x8C"', 0214.chr.force_encoding('utf-8')],
+ ['"\\x8D"', 0215.chr.force_encoding('utf-8')],
+ ['"\\x8E"', 0216.chr.force_encoding('utf-8')],
+ ['"\\x8F"', 0217.chr.force_encoding('utf-8')],
+ ['"\\x90"', 0220.chr.force_encoding('utf-8')],
+ ['"\\x91"', 0221.chr.force_encoding('utf-8')],
+ ['"\\x92"', 0222.chr.force_encoding('utf-8')],
+ ['"\\x93"', 0223.chr.force_encoding('utf-8')],
+ ['"\\x94"', 0224.chr.force_encoding('utf-8')],
+ ['"\\x95"', 0225.chr.force_encoding('utf-8')],
+ ['"\\x96"', 0226.chr.force_encoding('utf-8')],
+ ['"\\x97"', 0227.chr.force_encoding('utf-8')],
+ ['"\\x98"', 0230.chr.force_encoding('utf-8')],
+ ['"\\x99"', 0231.chr.force_encoding('utf-8')],
+ ['"\\x9A"', 0232.chr.force_encoding('utf-8')],
+ ['"\\x9B"', 0233.chr.force_encoding('utf-8')],
+ ['"\\x9C"', 0234.chr.force_encoding('utf-8')],
+ ['"\\x9D"', 0235.chr.force_encoding('utf-8')],
+ ['"\\x9E"', 0236.chr.force_encoding('utf-8')],
+ ['"\\x9F"', 0237.chr.force_encoding('utf-8')],
+ ['"\\xA0"', 0240.chr.force_encoding('utf-8')],
+ ['"\\xA1"', 0241.chr.force_encoding('utf-8')],
+ ['"\\xA2"', 0242.chr.force_encoding('utf-8')],
+ ['"\\xA3"', 0243.chr.force_encoding('utf-8')],
+ ['"\\xA4"', 0244.chr.force_encoding('utf-8')],
+ ['"\\xA5"', 0245.chr.force_encoding('utf-8')],
+ ['"\\xA6"', 0246.chr.force_encoding('utf-8')],
+ ['"\\xA7"', 0247.chr.force_encoding('utf-8')],
+ ['"\\xA8"', 0250.chr.force_encoding('utf-8')],
+ ['"\\xA9"', 0251.chr.force_encoding('utf-8')],
+ ['"\\xAA"', 0252.chr.force_encoding('utf-8')],
+ ['"\\xAB"', 0253.chr.force_encoding('utf-8')],
+ ['"\\xAC"', 0254.chr.force_encoding('utf-8')],
+ ['"\\xAD"', 0255.chr.force_encoding('utf-8')],
+ ['"\\xAE"', 0256.chr.force_encoding('utf-8')],
+ ['"\\xAF"', 0257.chr.force_encoding('utf-8')],
+ ['"\\xB0"', 0260.chr.force_encoding('utf-8')],
+ ['"\\xB1"', 0261.chr.force_encoding('utf-8')],
+ ['"\\xB2"', 0262.chr.force_encoding('utf-8')],
+ ['"\\xB3"', 0263.chr.force_encoding('utf-8')],
+ ['"\\xB4"', 0264.chr.force_encoding('utf-8')],
+ ['"\\xB5"', 0265.chr.force_encoding('utf-8')],
+ ['"\\xB6"', 0266.chr.force_encoding('utf-8')],
+ ['"\\xB7"', 0267.chr.force_encoding('utf-8')],
+ ['"\\xB8"', 0270.chr.force_encoding('utf-8')],
+ ['"\\xB9"', 0271.chr.force_encoding('utf-8')],
+ ['"\\xBA"', 0272.chr.force_encoding('utf-8')],
+ ['"\\xBB"', 0273.chr.force_encoding('utf-8')],
+ ['"\\xBC"', 0274.chr.force_encoding('utf-8')],
+ ['"\\xBD"', 0275.chr.force_encoding('utf-8')],
+ ['"\\xBE"', 0276.chr.force_encoding('utf-8')],
+ ['"\\xBF"', 0277.chr.force_encoding('utf-8')],
+ ['"\\xC0"', 0300.chr.force_encoding('utf-8')],
+ ['"\\xC1"', 0301.chr.force_encoding('utf-8')],
+ ['"\\xC2"', 0302.chr.force_encoding('utf-8')],
+ ['"\\xC3"', 0303.chr.force_encoding('utf-8')],
+ ['"\\xC4"', 0304.chr.force_encoding('utf-8')],
+ ['"\\xC5"', 0305.chr.force_encoding('utf-8')],
+ ['"\\xC6"', 0306.chr.force_encoding('utf-8')],
+ ['"\\xC7"', 0307.chr.force_encoding('utf-8')],
+ ['"\\xC8"', 0310.chr.force_encoding('utf-8')],
+ ['"\\xC9"', 0311.chr.force_encoding('utf-8')],
+ ['"\\xCA"', 0312.chr.force_encoding('utf-8')],
+ ['"\\xCB"', 0313.chr.force_encoding('utf-8')],
+ ['"\\xCC"', 0314.chr.force_encoding('utf-8')],
+ ['"\\xCD"', 0315.chr.force_encoding('utf-8')],
+ ['"\\xCE"', 0316.chr.force_encoding('utf-8')],
+ ['"\\xCF"', 0317.chr.force_encoding('utf-8')],
+ ['"\\xD0"', 0320.chr.force_encoding('utf-8')],
+ ['"\\xD1"', 0321.chr.force_encoding('utf-8')],
+ ['"\\xD2"', 0322.chr.force_encoding('utf-8')],
+ ['"\\xD3"', 0323.chr.force_encoding('utf-8')],
+ ['"\\xD4"', 0324.chr.force_encoding('utf-8')],
+ ['"\\xD5"', 0325.chr.force_encoding('utf-8')],
+ ['"\\xD6"', 0326.chr.force_encoding('utf-8')],
+ ['"\\xD7"', 0327.chr.force_encoding('utf-8')],
+ ['"\\xD8"', 0330.chr.force_encoding('utf-8')],
+ ['"\\xD9"', 0331.chr.force_encoding('utf-8')],
+ ['"\\xDA"', 0332.chr.force_encoding('utf-8')],
+ ['"\\xDB"', 0333.chr.force_encoding('utf-8')],
+ ['"\\xDC"', 0334.chr.force_encoding('utf-8')],
+ ['"\\xDD"', 0335.chr.force_encoding('utf-8')],
+ ['"\\xDE"', 0336.chr.force_encoding('utf-8')],
+ ['"\\xDF"', 0337.chr.force_encoding('utf-8')],
+ ['"\\xE0"', 0340.chr.force_encoding('utf-8')],
+ ['"\\xE1"', 0341.chr.force_encoding('utf-8')],
+ ['"\\xE2"', 0342.chr.force_encoding('utf-8')],
+ ['"\\xE3"', 0343.chr.force_encoding('utf-8')],
+ ['"\\xE4"', 0344.chr.force_encoding('utf-8')],
+ ['"\\xE5"', 0345.chr.force_encoding('utf-8')],
+ ['"\\xE6"', 0346.chr.force_encoding('utf-8')],
+ ['"\\xE7"', 0347.chr.force_encoding('utf-8')],
+ ['"\\xE8"', 0350.chr.force_encoding('utf-8')],
+ ['"\\xE9"', 0351.chr.force_encoding('utf-8')],
+ ['"\\xEA"', 0352.chr.force_encoding('utf-8')],
+ ['"\\xEB"', 0353.chr.force_encoding('utf-8')],
+ ['"\\xEC"', 0354.chr.force_encoding('utf-8')],
+ ['"\\xED"', 0355.chr.force_encoding('utf-8')],
+ ['"\\xEE"', 0356.chr.force_encoding('utf-8')],
+ ['"\\xEF"', 0357.chr.force_encoding('utf-8')],
+ ['"\\xF0"', 0360.chr.force_encoding('utf-8')],
+ ['"\\xF1"', 0361.chr.force_encoding('utf-8')],
+ ['"\\xF2"', 0362.chr.force_encoding('utf-8')],
+ ['"\\xF3"', 0363.chr.force_encoding('utf-8')],
+ ['"\\xF4"', 0364.chr.force_encoding('utf-8')],
+ ['"\\xF5"', 0365.chr.force_encoding('utf-8')],
+ ['"\\xF6"', 0366.chr.force_encoding('utf-8')],
+ ['"\\xF7"', 0367.chr.force_encoding('utf-8')],
+ ['"\\xF8"', 0370.chr.force_encoding('utf-8')],
+ ['"\\xF9"', 0371.chr.force_encoding('utf-8')],
+ ['"\\xFA"', 0372.chr.force_encoding('utf-8')],
+ ['"\\xFB"', 0373.chr.force_encoding('utf-8')],
+ ['"\\xFC"', 0374.chr.force_encoding('utf-8')],
+ ['"\\xFD"', 0375.chr.force_encoding('utf-8')],
+ ['"\\xFE"', 0376.chr.force_encoding('utf-8')],
+ ['"\\xFF"', 0377.chr.force_encoding('utf-8')]
+ ].should be_computed_by(:undump)
+ end
+
+ it "returns a string with \\u{} notation replaced with multi-byte UTF-8 characters" do
+ [ ['"\u{80}"', 0200.chr('utf-8')],
+ ['"\u{81}"', 0201.chr('utf-8')],
+ ['"\u{82}"', 0202.chr('utf-8')],
+ ['"\u{83}"', 0203.chr('utf-8')],
+ ['"\u{84}"', 0204.chr('utf-8')],
+ ['"\u{86}"', 0206.chr('utf-8')],
+ ['"\u{87}"', 0207.chr('utf-8')],
+ ['"\u{88}"', 0210.chr('utf-8')],
+ ['"\u{89}"', 0211.chr('utf-8')],
+ ['"\u{8a}"', 0212.chr('utf-8')],
+ ['"\u{8b}"', 0213.chr('utf-8')],
+ ['"\u{8c}"', 0214.chr('utf-8')],
+ ['"\u{8d}"', 0215.chr('utf-8')],
+ ['"\u{8e}"', 0216.chr('utf-8')],
+ ['"\u{8f}"', 0217.chr('utf-8')],
+ ['"\u{90}"', 0220.chr('utf-8')],
+ ['"\u{91}"', 0221.chr('utf-8')],
+ ['"\u{92}"', 0222.chr('utf-8')],
+ ['"\u{93}"', 0223.chr('utf-8')],
+ ['"\u{94}"', 0224.chr('utf-8')],
+ ['"\u{95}"', 0225.chr('utf-8')],
+ ['"\u{96}"', 0226.chr('utf-8')],
+ ['"\u{97}"', 0227.chr('utf-8')],
+ ['"\u{98}"', 0230.chr('utf-8')],
+ ['"\u{99}"', 0231.chr('utf-8')],
+ ['"\u{9a}"', 0232.chr('utf-8')],
+ ['"\u{9b}"', 0233.chr('utf-8')],
+ ['"\u{9c}"', 0234.chr('utf-8')],
+ ['"\u{9d}"', 0235.chr('utf-8')],
+ ['"\u{9e}"', 0236.chr('utf-8')],
+ ['"\u{9f}"', 0237.chr('utf-8')],
+ ].should be_computed_by(:undump)
+ end
+
+ it "returns a string with \\uXXXX notation replaced with multi-byte UTF-8 characters" do
+ [ ['"\u0080"', 0200.chr('utf-8')],
+ ['"\u0081"', 0201.chr('utf-8')],
+ ['"\u0082"', 0202.chr('utf-8')],
+ ['"\u0083"', 0203.chr('utf-8')],
+ ['"\u0084"', 0204.chr('utf-8')],
+ ['"\u0086"', 0206.chr('utf-8')],
+ ['"\u0087"', 0207.chr('utf-8')],
+ ['"\u0088"', 0210.chr('utf-8')],
+ ['"\u0089"', 0211.chr('utf-8')],
+ ['"\u008a"', 0212.chr('utf-8')],
+ ['"\u008b"', 0213.chr('utf-8')],
+ ['"\u008c"', 0214.chr('utf-8')],
+ ['"\u008d"', 0215.chr('utf-8')],
+ ['"\u008e"', 0216.chr('utf-8')],
+ ['"\u008f"', 0217.chr('utf-8')],
+ ['"\u0090"', 0220.chr('utf-8')],
+ ['"\u0091"', 0221.chr('utf-8')],
+ ['"\u0092"', 0222.chr('utf-8')],
+ ['"\u0093"', 0223.chr('utf-8')],
+ ['"\u0094"', 0224.chr('utf-8')],
+ ['"\u0095"', 0225.chr('utf-8')],
+ ['"\u0096"', 0226.chr('utf-8')],
+ ['"\u0097"', 0227.chr('utf-8')],
+ ['"\u0098"', 0230.chr('utf-8')],
+ ['"\u0099"', 0231.chr('utf-8')],
+ ['"\u009a"', 0232.chr('utf-8')],
+ ['"\u009b"', 0233.chr('utf-8')],
+ ['"\u009c"', 0234.chr('utf-8')],
+ ['"\u009d"', 0235.chr('utf-8')],
+ ['"\u009e"', 0236.chr('utf-8')],
+ ['"\u009f"', 0237.chr('utf-8')],
+ ].should be_computed_by(:undump)
+ end
+
+ it "undumps correctly string produced from non ASCII-compatible one" do
+ s = "\u{876}".encode('utf-16be')
+ s.dump.undump.should == s
+
+ '"\\bv".force_encoding("UTF-16BE")'.undump.should == "\u0876".encode('utf-16be')
+ end
+
+ it "returns a String in the same encoding as self" do
+ '"foo"'.encode("ISO-8859-1").undump.encoding.should == Encoding::ISO_8859_1
+ '"foo"'.encode('windows-1251').undump.encoding.should == Encoding::Windows_1251
+ end
+
+ describe "Limitations" do
+ it "cannot undump non ASCII-compatible string" do
+ -> { '"foo"'.encode('utf-16le').undump }.should.raise(Encoding::CompatibilityError)
+ end
+ end
+
+ describe "invalid dump" do
+ it "raises RuntimeError exception if wrapping \" are missing" do
+ -> { 'foo'.undump }.should.raise(RuntimeError, /invalid dumped string/)
+ -> { '"foo'.undump }.should.raise(RuntimeError, /unterminated dumped string/)
+ -> { 'foo"'.undump }.should.raise(RuntimeError, /invalid dumped string/)
+ -> { "'foo'".undump }.should.raise(RuntimeError, /invalid dumped string/)
+ end
+
+ it "raises RuntimeError if there is incorrect \\x sequence" do
+ -> { '"\x"'.undump }.should.raise(RuntimeError, /invalid hex escape/)
+ -> { '"\\x3y"'.undump }.should.raise(RuntimeError, /invalid hex escape/)
+ end
+
+ it "raises RuntimeError in there is incorrect \\u sequence" do
+ -> { '"\\u"'.undump }.should.raise(RuntimeError, /invalid Unicode escape/)
+ -> { '"\\u{"'.undump }.should.raise(RuntimeError, /invalid Unicode escape/)
+ -> { '"\\u{3042"'.undump }.should.raise(RuntimeError, /invalid Unicode escape/)
+ -> { '"\\u"'.undump }.should.raise(RuntimeError, /invalid Unicode escape/)
+ end
+
+ it "raises RuntimeError if there is malformed dump of non ASCII-compatible string" do
+ -> { '"".force_encoding("BINARY"'.undump }.should.raise(RuntimeError, /invalid dumped string/)
+ -> { '"".force_encoding("Unknown")'.undump }.should.raise(RuntimeError, /dumped string has unknown encoding name/)
+ -> { '"".force_encoding()'.undump }.should.raise(RuntimeError, /invalid dumped string/)
+ end
+
+ it "raises RuntimeError if string contains \0 character" do
+ -> { "\"foo\0\"".undump }.should.raise(RuntimeError, /string contains null byte/)
+ end
+
+ it "raises RuntimeError if string contains non ASCII character" do
+ -> { "\"\u3042\"".undump }.should.raise(RuntimeError, /non-ASCII character detected/)
+ end
+
+ it "raises RuntimeError if there are some excessive \"" do
+ -> { '" "" "'.undump }.should.raise(RuntimeError, /invalid dumped string/)
+ end
+ end
+end
diff --git a/spec/ruby/core/string/unicode_normalize_spec.rb b/spec/ruby/core/string/unicode_normalize_spec.rb
index 138c0455fd..92b3a46b43 100644
--- a/spec/ruby/core/string/unicode_normalize_spec.rb
+++ b/spec/ruby/core/string/unicode_normalize_spec.rb
@@ -1,5 +1,6 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
+# frozen_string_literal: false
+require_relative '../../spec_helper'
# Examples taken from http://www.unicode.org/reports/tr15/#Norm_Forms
@@ -48,15 +49,15 @@ describe "String#unicode_normalize" do
end
it "raises an Encoding::CompatibilityError if string is not in an unicode encoding" do
- lambda do
+ -> do
[0xE0].pack('C').force_encoding("ISO-8859-1").unicode_normalize(:nfd)
- end.should raise_error(Encoding::CompatibilityError)
+ end.should.raise(Encoding::CompatibilityError)
end
it "raises an ArgumentError if the specified form is invalid" do
- lambda {
+ -> {
@angstrom.unicode_normalize(:invalid_form)
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
end
end
@@ -101,15 +102,15 @@ describe "String#unicode_normalize!" do
end
it "raises an Encoding::CompatibilityError if the string is not in an unicode encoding" do
- lambda {
+ -> {
[0xE0].pack('C').force_encoding("ISO-8859-1").unicode_normalize!
- }.should raise_error(Encoding::CompatibilityError)
+ }.should.raise(Encoding::CompatibilityError)
end
it "raises an ArgumentError if the specified form is invalid" do
ohm = "\u2126"
- lambda {
+ -> {
ohm.unicode_normalize!(:invalid_form)
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
end
end
diff --git a/spec/ruby/core/string/unicode_normalized_spec.rb b/spec/ruby/core/string/unicode_normalized_spec.rb
index dc5e2742e4..3ca27d35dd 100644
--- a/spec/ruby/core/string/unicode_normalized_spec.rb
+++ b/spec/ruby/core/string/unicode_normalized_spec.rb
@@ -1,5 +1,6 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
+# frozen_string_literal: false
+require_relative '../../spec_helper'
describe "String#unicode_normalized?" do
before :each do
@@ -24,51 +25,51 @@ describe "String#unicode_normalized?" do
end
it "defaults to the nfc normalization form if no forms are specified" do
- @nfc_normalized_str.unicode_normalized?.should == true
- @nfd_normalized_str.unicode_normalized?.should == false
+ @nfc_normalized_str.should.unicode_normalized?
+ @nfd_normalized_str.should_not.unicode_normalized?
end
it "returns true if string is empty" do
- "".unicode_normalized?.should == true
+ "".should.unicode_normalized?
end
it "returns true if string does not contain any unicode codepoints" do
- "abc".unicode_normalized?.should == true
+ "abc".should.unicode_normalized?
end
it "raises an Encoding::CompatibilityError if the string is not in an unicode encoding" do
- lambda { @nfc_normalized_str.force_encoding("ISO-8859-1").unicode_normalized? }.should raise_error(Encoding::CompatibilityError)
+ -> { @nfc_normalized_str.force_encoding("ISO-8859-1").unicode_normalized? }.should.raise(Encoding::CompatibilityError)
end
it "raises an ArgumentError if the specified form is invalid" do
- lambda { @nfc_normalized_str.unicode_normalized?(:invalid_form) }.should raise_error(ArgumentError)
+ -> { @nfc_normalized_str.unicode_normalized?(:invalid_form) }.should.raise(ArgumentError)
end
it "returns true if str is in Unicode normalization form (nfc)" do
str = "a\u0300"
- str.unicode_normalized?(:nfc).should be_false
+ str.unicode_normalized?(:nfc).should == false
str.unicode_normalize!(:nfc)
- str.unicode_normalized?(:nfc).should be_true
+ str.unicode_normalized?(:nfc).should == true
end
it "returns true if str is in Unicode normalization form (nfd)" do
str = "a\u00E0"
- str.unicode_normalized?(:nfd).should be_false
+ str.unicode_normalized?(:nfd).should == false
str.unicode_normalize!(:nfd)
- str.unicode_normalized?(:nfd).should be_true
+ str.unicode_normalized?(:nfd).should == true
end
it "returns true if str is in Unicode normalization form (nfkc)" do
str = "a\u0300"
- str.unicode_normalized?(:nfkc).should be_false
+ str.unicode_normalized?(:nfkc).should == false
str.unicode_normalize!(:nfkc)
- str.unicode_normalized?(:nfkc).should be_true
+ str.unicode_normalized?(:nfkc).should == true
end
it "returns true if str is in Unicode normalization form (nfkd)" do
str = "a\u00E0"
- str.unicode_normalized?(:nfkd).should be_false
+ str.unicode_normalized?(:nfkd).should == false
str.unicode_normalize!(:nfkd)
- str.unicode_normalized?(:nfkd).should be_true
+ str.unicode_normalized?(:nfkd).should == true
end
end
diff --git a/spec/ruby/core/string/unpack/a_spec.rb b/spec/ruby/core/string/unpack/a_spec.rb
index 18882c91a6..a68e842e15 100644
--- a/spec/ruby/core/string/unpack/a_spec.rb
+++ b/spec/ruby/core/string/unpack/a_spec.rb
@@ -1,14 +1,16 @@
-# -*- encoding: ascii-8bit -*-
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
-require File.expand_path('../shared/basic', __FILE__)
-require File.expand_path('../shared/string', __FILE__)
+# encoding: binary
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
+require_relative 'shared/basic'
+require_relative 'shared/string'
+require_relative 'shared/taint'
describe "String#unpack with format 'A'" do
it_behaves_like :string_unpack_basic, 'A'
it_behaves_like :string_unpack_no_platform, 'A'
it_behaves_like :string_unpack_string, 'A'
it_behaves_like :string_unpack_Aa, 'A'
+ it_behaves_like :string_unpack_taint, 'A'
it "removes trailing space and NULL bytes from the decoded string" do
[ ["a\x00 b \x00", ["a\x00 b", ""]],
@@ -29,8 +31,8 @@ describe "String#unpack with format 'A'" do
end
it "decodes into raw (ascii) string values" do
- str = "str".force_encoding('UTF-8').unpack("A*")[0]
- str.encoding.name.should == 'ASCII-8BIT'
+ str = "str".dup.force_encoding('UTF-8').unpack("A*")[0]
+ str.encoding.should == Encoding::BINARY
end
end
@@ -40,6 +42,7 @@ describe "String#unpack with format 'a'" do
it_behaves_like :string_unpack_no_platform, 'a'
it_behaves_like :string_unpack_string, 'a'
it_behaves_like :string_unpack_Aa, 'a'
+ it_behaves_like :string_unpack_taint, 'a'
it "does not remove trailing whitespace or NULL bytes from the decoded string" do
[ ["a\x00 b \x00", ["a\x00 b \x00"]],
@@ -57,7 +60,7 @@ describe "String#unpack with format 'a'" do
it "decodes into raw (ascii) string values" do
str = "".unpack("a*")[0]
- str.encoding.name.should == 'ASCII-8BIT'
+ str.encoding.should == Encoding::BINARY
end
end
diff --git a/spec/ruby/core/string/unpack/at_spec.rb b/spec/ruby/core/string/unpack/at_spec.rb
index 70cbebd2ba..f4999f5922 100644
--- a/spec/ruby/core/string/unpack/at_spec.rb
+++ b/spec/ruby/core/string/unpack/at_spec.rb
@@ -1,7 +1,7 @@
-# -*- encoding: ascii-8bit -*-
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
-require File.expand_path('../shared/basic', __FILE__)
+# encoding: binary
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
+require_relative 'shared/basic'
describe "String#unpack with format '@'" do
it_behaves_like :string_unpack_basic, '@'
@@ -24,6 +24,6 @@ describe "String#unpack with format '@'" do
end
it "raises an ArgumentError if the count exceeds the size of the String" do
- lambda { "\x01\x02\x03\x04".unpack("C2@5C") }.should raise_error(ArgumentError)
+ -> { "\x01\x02\x03\x04".unpack("C2@5C") }.should.raise(ArgumentError)
end
end
diff --git a/spec/ruby/core/string/unpack/b_spec.rb b/spec/ruby/core/string/unpack/b_spec.rb
index fa632e6526..fac6ef5151 100644
--- a/spec/ruby/core/string/unpack/b_spec.rb
+++ b/spec/ruby/core/string/unpack/b_spec.rb
@@ -1,11 +1,13 @@
-# -*- encoding: ascii-8bit -*-
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
-require File.expand_path('../shared/basic', __FILE__)
+# encoding: binary
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
+require_relative 'shared/basic'
+require_relative 'shared/taint'
describe "String#unpack with format 'B'" do
it_behaves_like :string_unpack_basic, 'B'
it_behaves_like :string_unpack_no_platform, 'B'
+ it_behaves_like :string_unpack_taint, 'B'
it "decodes one bit from each byte for each format character starting with the most significant bit" do
[ ["\x00", "B", ["0"]],
@@ -84,18 +86,26 @@ describe "String#unpack with format 'B'" do
].should be_computed_by(:unpack, "BBB")
end
- it "ignores NULL bytes between directives" do
- "\x80\x00".unpack("B\x00B").should == ["1", "0"]
+ it "raise ArgumentError for NULL bytes between directives" do
+ -> {
+ "\x80\x00".unpack("B\x00B")
+ }.should.raise(ArgumentError, /unknown unpack directive/)
end
it "ignores spaces between directives" do
"\x80\x00".unpack("B B").should == ["1", "0"]
end
+
+ it "decodes into US-ASCII string values" do
+ str = "s".dup.force_encoding('UTF-8').unpack("B*")[0]
+ str.encoding.name.should == 'US-ASCII'
+ end
end
describe "String#unpack with format 'b'" do
it_behaves_like :string_unpack_basic, 'b'
it_behaves_like :string_unpack_no_platform, 'b'
+ it_behaves_like :string_unpack_taint, 'b'
it "decodes one bit from each byte for each format character starting with the least significant bit" do
[ ["\x00", "b", ["0"]],
@@ -174,8 +184,10 @@ describe "String#unpack with format 'b'" do
].should be_computed_by(:unpack, "bbb")
end
- it "ignores NULL bytes between directives" do
- "\x01\x00".unpack("b\x00b").should == ["1", "0"]
+ it "raise ArgumentError for NULL bytes between directives" do
+ -> {
+ "\x01\x00".unpack("b\x00b")
+ }.should.raise(ArgumentError, /unknown unpack directive/)
end
it "ignores spaces between directives" do
@@ -183,8 +195,7 @@ describe "String#unpack with format 'b'" do
end
it "decodes into US-ASCII string values" do
- str = "s".force_encoding('UTF-8').unpack("b*")[0]
+ str = "s".dup.force_encoding('UTF-8').unpack("b*")[0]
str.encoding.name.should == 'US-ASCII'
end
-
end
diff --git a/spec/ruby/core/string/unpack/c_spec.rb b/spec/ruby/core/string/unpack/c_spec.rb
index 36de462cac..d881015b5e 100644
--- a/spec/ruby/core/string/unpack/c_spec.rb
+++ b/spec/ruby/core/string/unpack/c_spec.rb
@@ -1,7 +1,7 @@
-# -*- encoding: ascii-8bit -*-
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
-require File.expand_path('../shared/basic', __FILE__)
+# encoding: binary
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
+require_relative 'shared/basic'
describe :string_unpack_8bit, shared: true do
it "decodes one byte for a single format character" do
@@ -20,7 +20,7 @@ describe :string_unpack_8bit, shared: true do
"abc".unpack(unpack_format('*')).should == [97, 98, 99]
end
- it "decodes the remaining bytes when passed the '*' modifer after another directive" do
+ it "decodes the remaining bytes when passed the '*' modifier after another directive" do
"abc".unpack(unpack_format()+unpack_format('*')).should == [97, 98, 99]
end
@@ -35,8 +35,10 @@ describe :string_unpack_8bit, shared: true do
].should be_computed_by(:unpack, unpack_format(3))
end
- it "ignores NULL bytes between directives" do
- "abc".unpack(unpack_format("\000", 2)).should == [97, 98]
+ it "raise ArgumentError for NULL bytes between directives" do
+ -> {
+ "abc".unpack(unpack_format("\000", 2))
+ }.should.raise(ArgumentError, /unknown unpack directive/)
end
it "ignores spaces between directives" do
diff --git a/spec/ruby/core/string/unpack/carret_spec.rb b/spec/ruby/core/string/unpack/carret_spec.rb
new file mode 100644
index 0000000000..815df0c718
--- /dev/null
+++ b/spec/ruby/core/string/unpack/carret_spec.rb
@@ -0,0 +1,43 @@
+# encoding: binary
+ruby_version_is "4.1" do
+ require_relative '../../../spec_helper'
+ require_relative '../fixtures/classes'
+ require_relative 'shared/basic'
+
+ describe "String#unpack with format '^'" do
+ it_behaves_like :string_unpack_basic, '^'
+ it_behaves_like :string_unpack_no_platform, '^'
+
+ it "returns the current offset that start from 0" do
+ "".unpack("^").should == [0]
+ end
+
+ it "returns the current offset after the last decode ended" do
+ "a".unpack("CC^").should == [97, nil, 1]
+ end
+
+ it "returns the current offset that start from the given offset" do
+ "abc".unpack("^", offset: 1).should == [1]
+ end
+
+ it "returns the offset moved by 'X'" do
+ "\x01\x02\x03\x04".unpack("C3X2^").should == [1, 2, 3, 1]
+ end
+
+ it "returns the offset moved by 'x'" do
+ "\x01\x02\x03\x04".unpack("Cx2^").should == [1, 3]
+ end
+
+ it "returns the offset to the position the previous decode ended" do
+ "foo".unpack("A4^").should == ["foo", 3]
+ "foo".unpack("a4^").should == ["foo", 3]
+ "foo".unpack("Z5^").should == ["foo", 3]
+ end
+
+ it "returns the offset including truncated part" do
+ "foo ".unpack("A*^").should == ["foo", 6]
+ "foo\0".unpack("Z*^").should == ["foo", 4]
+ "foo\0\0\0".unpack("Z5^").should == ["foo", 5]
+ end
+ end
+end
diff --git a/spec/ruby/core/string/unpack/comment_spec.rb b/spec/ruby/core/string/unpack/comment_spec.rb
index 884960b337..050d2b7fc0 100644
--- a/spec/ruby/core/string/unpack/comment_spec.rb
+++ b/spec/ruby/core/string/unpack/comment_spec.rb
@@ -1,6 +1,6 @@
-# -*- encoding: ascii-8bit -*-
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
+# encoding: binary
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
describe "String#unpack" do
it "ignores directives text from '#' to the first newline" do
diff --git a/spec/ruby/core/string/unpack/d_spec.rb b/spec/ruby/core/string/unpack/d_spec.rb
index db4638f8ef..0e4f57ec04 100644
--- a/spec/ruby/core/string/unpack/d_spec.rb
+++ b/spec/ruby/core/string/unpack/d_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
-require File.expand_path('../shared/basic', __FILE__)
-require File.expand_path('../shared/float', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
+require_relative 'shared/basic'
+require_relative 'shared/float'
little_endian do
describe "String#unpack with format 'D'" do
diff --git a/spec/ruby/core/string/unpack/e_spec.rb b/spec/ruby/core/string/unpack/e_spec.rb
index cb74c00206..c958be1c8b 100644
--- a/spec/ruby/core/string/unpack/e_spec.rb
+++ b/spec/ruby/core/string/unpack/e_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
-require File.expand_path('../shared/basic', __FILE__)
-require File.expand_path('../shared/float', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
+require_relative 'shared/basic'
+require_relative 'shared/float'
describe "String#unpack with format 'E'" do
it_behaves_like :string_unpack_basic, 'E'
diff --git a/spec/ruby/core/string/unpack/f_spec.rb b/spec/ruby/core/string/unpack/f_spec.rb
index 60dad46703..ec8b9d435e 100644
--- a/spec/ruby/core/string/unpack/f_spec.rb
+++ b/spec/ruby/core/string/unpack/f_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
-require File.expand_path('../shared/basic', __FILE__)
-require File.expand_path('../shared/float', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
+require_relative 'shared/basic'
+require_relative 'shared/float'
little_endian do
describe "String#unpack with format 'F'" do
diff --git a/spec/ruby/core/string/unpack/g_spec.rb b/spec/ruby/core/string/unpack/g_spec.rb
index f5bec1534e..ffc423b152 100644
--- a/spec/ruby/core/string/unpack/g_spec.rb
+++ b/spec/ruby/core/string/unpack/g_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
-require File.expand_path('../shared/basic', __FILE__)
-require File.expand_path('../shared/float', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
+require_relative 'shared/basic'
+require_relative 'shared/float'
describe "String#unpack with format 'G'" do
it_behaves_like :string_unpack_basic, 'G'
diff --git a/spec/ruby/core/string/unpack/h_spec.rb b/spec/ruby/core/string/unpack/h_spec.rb
index 00d6d68eee..0cf8d943a7 100644
--- a/spec/ruby/core/string/unpack/h_spec.rb
+++ b/spec/ruby/core/string/unpack/h_spec.rb
@@ -1,11 +1,13 @@
-# -*- encoding: ascii-8bit -*-
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
-require File.expand_path('../shared/basic', __FILE__)
+# encoding: binary
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
+require_relative 'shared/basic'
+require_relative 'shared/taint'
describe "String#unpack with format 'H'" do
it_behaves_like :string_unpack_basic, 'H'
it_behaves_like :string_unpack_no_platform, 'H'
+ it_behaves_like :string_unpack_taint, 'H'
it "decodes one nibble from each byte for each format character starting with the most significant bit" do
[ ["\x8f", "H", ["8"]],
@@ -54,18 +56,25 @@ describe "String#unpack with format 'H'" do
].should be_computed_by(:unpack, "HHH")
end
- it "ignores NULL bytes between directives" do
- "\x01\x10".unpack("H\x00H").should == ["0", "1"]
+ it "raise ArgumentError for NULL bytes between directives" do
+ -> {
+ "\x01\x10".unpack("H\x00H")
+ }.should.raise(ArgumentError, /unknown unpack directive/)
end
it "ignores spaces between directives" do
"\x01\x10".unpack("H H").should == ["0", "1"]
end
+
+ it "should make strings with US_ASCII encoding" do
+ "\x01".unpack("H")[0].encoding.should == Encoding::US_ASCII
+ end
end
describe "String#unpack with format 'h'" do
it_behaves_like :string_unpack_basic, 'h'
it_behaves_like :string_unpack_no_platform, 'h'
+ it_behaves_like :string_unpack_taint, 'h'
it "decodes one nibble from each byte for each format character starting with the least significant bit" do
[ ["\x8f", "h", ["f"]],
@@ -114,11 +123,17 @@ describe "String#unpack with format 'h'" do
].should be_computed_by(:unpack, "hhh")
end
- it "ignores NULL bytes between directives" do
- "\x01\x10".unpack("h\x00h").should == ["1", "0"]
+ it "raise ArgumentError for NULL bytes between directives" do
+ -> {
+ "\x01\x10".unpack("h\x00h")
+ }.should.raise(ArgumentError, /unknown unpack directive/)
end
it "ignores spaces between directives" do
"\x01\x10".unpack("h h").should == ["1", "0"]
end
+
+ it "should make strings with US_ASCII encoding" do
+ "\x01".unpack("h")[0].encoding.should == Encoding::US_ASCII
+ end
end
diff --git a/spec/ruby/core/string/unpack/i_spec.rb b/spec/ruby/core/string/unpack/i_spec.rb
index f3183afe99..b4bbba1923 100644
--- a/spec/ruby/core/string/unpack/i_spec.rb
+++ b/spec/ruby/core/string/unpack/i_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
-require File.expand_path('../shared/basic', __FILE__)
-require File.expand_path('../shared/integer', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
+require_relative 'shared/basic'
+require_relative 'shared/integer'
describe "String#unpack with format 'I'" do
describe "with modifier '<'" do
diff --git a/spec/ruby/core/string/unpack/j_spec.rb b/spec/ruby/core/string/unpack/j_spec.rb
index 49c460aeb3..3c2baad642 100644
--- a/spec/ruby/core/string/unpack/j_spec.rb
+++ b/spec/ruby/core/string/unpack/j_spec.rb
@@ -1,277 +1,272 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
-require File.expand_path('../shared/basic', __FILE__)
-require File.expand_path('../shared/integer', __FILE__)
-
-ruby_version_is '2.3' do
- # To handle the special case of x64-mingw32
- pointer_size = RUBY_PLATFORM =~ /\bx64\b/ ? 64 : 1.size * 8
-
- if pointer_size == 64 then
- little_endian do
- describe "String#unpack with format 'J'" do
- describe "with modifier '_'" do
- it_behaves_like :string_unpack_64bit_le, 'J_'
- it_behaves_like :string_unpack_64bit_le_unsigned, 'J_'
- end
-
- describe "with modifier '!'" do
- it_behaves_like :string_unpack_64bit_le, 'J!'
- it_behaves_like :string_unpack_64bit_le_unsigned, 'J!'
- end
- end
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
+require_relative 'shared/basic'
+require_relative 'shared/integer'
- describe "String#unpack with format 'j'" do
- describe "with modifier '_'" do
- it_behaves_like :string_unpack_64bit_le, 'j_'
- it_behaves_like :string_unpack_64bit_le_signed, 'j_'
- end
+platform_is pointer_size: 64 do
+ little_endian do
+ describe "String#unpack with format 'J'" do
+ describe "with modifier '_'" do
+ it_behaves_like :string_unpack_64bit_le, 'J_'
+ it_behaves_like :string_unpack_64bit_le_unsigned, 'J_'
+ end
- describe "with modifier '!'" do
- it_behaves_like :string_unpack_64bit_le, 'j!'
- it_behaves_like :string_unpack_64bit_le_signed, 'j!'
- end
+ describe "with modifier '!'" do
+ it_behaves_like :string_unpack_64bit_le, 'J!'
+ it_behaves_like :string_unpack_64bit_le_unsigned, 'J!'
end
end
- big_endian do
- describe "String#unpack with format 'J'" do
- describe "with modifier '_'" do
- it_behaves_like :string_unpack_64bit_be, 'J_'
- it_behaves_like :string_unpack_64bit_be_unsigned, 'J_'
- end
-
- describe "with modifier '!'" do
- it_behaves_like :string_unpack_64bit_be, 'J!'
- it_behaves_like :string_unpack_64bit_be_unsigned, 'J!'
- end
+ describe "String#unpack with format 'j'" do
+ describe "with modifier '_'" do
+ it_behaves_like :string_unpack_64bit_le, 'j_'
+ it_behaves_like :string_unpack_64bit_le_signed, 'j_'
end
- describe "String#unpack with format 'j'" do
- describe "with modifier '_'" do
- it_behaves_like :string_unpack_64bit_be, 'j_'
- it_behaves_like :string_unpack_64bit_be_signed, 'j_'
- end
-
- describe "with modifier '!'" do
- it_behaves_like :string_unpack_64bit_be, 'j!'
- it_behaves_like :string_unpack_64bit_be_signed, 'j!'
- end
+ describe "with modifier '!'" do
+ it_behaves_like :string_unpack_64bit_le, 'j!'
+ it_behaves_like :string_unpack_64bit_le_signed, 'j!'
end
end
+ end
+ big_endian do
describe "String#unpack with format 'J'" do
- describe "with modifier '<'" do
- it_behaves_like :string_unpack_64bit_le, 'J<'
- it_behaves_like :string_unpack_64bit_le_unsigned, 'J<'
- end
-
- describe "with modifier '>'" do
- it_behaves_like :string_unpack_64bit_be, 'J>'
- it_behaves_like :string_unpack_64bit_be_unsigned, 'J>'
+ describe "with modifier '_'" do
+ it_behaves_like :string_unpack_64bit_be, 'J_'
+ it_behaves_like :string_unpack_64bit_be_unsigned, 'J_'
end
- describe "with modifier '<' and '_'" do
- it_behaves_like :string_unpack_64bit_le, 'J<_'
- it_behaves_like :string_unpack_64bit_le, 'J_<'
- it_behaves_like :string_unpack_64bit_le_unsigned, 'J<_'
- it_behaves_like :string_unpack_64bit_le_unsigned, 'J_<'
- end
-
- describe "with modifier '<' and '!'" do
- it_behaves_like :string_unpack_64bit_le, 'J<!'
- it_behaves_like :string_unpack_64bit_le, 'J!<'
- it_behaves_like :string_unpack_64bit_le_unsigned, 'J<!'
- it_behaves_like :string_unpack_64bit_le_unsigned, 'J!<'
+ describe "with modifier '!'" do
+ it_behaves_like :string_unpack_64bit_be, 'J!'
+ it_behaves_like :string_unpack_64bit_be_unsigned, 'J!'
end
+ end
- describe "with modifier '>' and '_'" do
- it_behaves_like :string_unpack_64bit_be, 'J>_'
- it_behaves_like :string_unpack_64bit_be, 'J_>'
- it_behaves_like :string_unpack_64bit_be_unsigned, 'J>_'
- it_behaves_like :string_unpack_64bit_be_unsigned, 'J_>'
+ describe "String#unpack with format 'j'" do
+ describe "with modifier '_'" do
+ it_behaves_like :string_unpack_64bit_be, 'j_'
+ it_behaves_like :string_unpack_64bit_be_signed, 'j_'
end
- describe "with modifier '>' and '!'" do
- it_behaves_like :string_unpack_64bit_be, 'J>!'
- it_behaves_like :string_unpack_64bit_be, 'J!>'
- it_behaves_like :string_unpack_64bit_be_unsigned, 'J>!'
- it_behaves_like :string_unpack_64bit_be_unsigned, 'J!>'
+ describe "with modifier '!'" do
+ it_behaves_like :string_unpack_64bit_be, 'j!'
+ it_behaves_like :string_unpack_64bit_be_signed, 'j!'
end
end
+ end
- describe "String#unpack with format 'j'" do
- describe "with modifier '<'" do
- it_behaves_like :string_unpack_64bit_le, 'j<'
- it_behaves_like :string_unpack_64bit_le_signed, 'j<'
- end
+ describe "String#unpack with format 'J'" do
+ describe "with modifier '<'" do
+ it_behaves_like :string_unpack_64bit_le, 'J<'
+ it_behaves_like :string_unpack_64bit_le_unsigned, 'J<'
+ end
- describe "with modifier '>'" do
- it_behaves_like :string_unpack_64bit_be, 'j>'
- it_behaves_like :string_unpack_64bit_be_signed, 'j>'
- end
+ describe "with modifier '>'" do
+ it_behaves_like :string_unpack_64bit_be, 'J>'
+ it_behaves_like :string_unpack_64bit_be_unsigned, 'J>'
+ end
- describe "with modifier '<' and '_'" do
- it_behaves_like :string_unpack_64bit_le, 'j<_'
- it_behaves_like :string_unpack_64bit_le, 'j_<'
- it_behaves_like :string_unpack_64bit_le_signed, 'j<_'
- it_behaves_like :string_unpack_64bit_le_signed, 'j_<'
- end
+ describe "with modifier '<' and '_'" do
+ it_behaves_like :string_unpack_64bit_le, 'J<_'
+ it_behaves_like :string_unpack_64bit_le, 'J_<'
+ it_behaves_like :string_unpack_64bit_le_unsigned, 'J<_'
+ it_behaves_like :string_unpack_64bit_le_unsigned, 'J_<'
+ end
- describe "with modifier '<' and '!'" do
- it_behaves_like :string_unpack_64bit_le, 'j<!'
- it_behaves_like :string_unpack_64bit_le, 'j!<'
- it_behaves_like :string_unpack_64bit_le_signed, 'j<!'
- it_behaves_like :string_unpack_64bit_le_signed, 'j!<'
- end
+ describe "with modifier '<' and '!'" do
+ it_behaves_like :string_unpack_64bit_le, 'J<!'
+ it_behaves_like :string_unpack_64bit_le, 'J!<'
+ it_behaves_like :string_unpack_64bit_le_unsigned, 'J<!'
+ it_behaves_like :string_unpack_64bit_le_unsigned, 'J!<'
+ end
- describe "with modifier '>' and '_'" do
- it_behaves_like :string_unpack_64bit_be, 'j>_'
- it_behaves_like :string_unpack_64bit_be, 'j_>'
- it_behaves_like :string_unpack_64bit_be_signed, 'j>_'
- it_behaves_like :string_unpack_64bit_be_signed, 'j_>'
- end
+ describe "with modifier '>' and '_'" do
+ it_behaves_like :string_unpack_64bit_be, 'J>_'
+ it_behaves_like :string_unpack_64bit_be, 'J_>'
+ it_behaves_like :string_unpack_64bit_be_unsigned, 'J>_'
+ it_behaves_like :string_unpack_64bit_be_unsigned, 'J_>'
+ end
- describe "with modifier '>' and '!'" do
- it_behaves_like :string_unpack_64bit_be, 'j>!'
- it_behaves_like :string_unpack_64bit_be, 'j!>'
- it_behaves_like :string_unpack_64bit_be_signed, 'j>!'
- it_behaves_like :string_unpack_64bit_be_signed, 'j!>'
- end
+ describe "with modifier '>' and '!'" do
+ it_behaves_like :string_unpack_64bit_be, 'J>!'
+ it_behaves_like :string_unpack_64bit_be, 'J!>'
+ it_behaves_like :string_unpack_64bit_be_unsigned, 'J>!'
+ it_behaves_like :string_unpack_64bit_be_unsigned, 'J!>'
end
end
- if pointer_size == 32 then
- little_endian do
- describe "String#unpack with format 'J'" do
- describe "with modifier '_'" do
- it_behaves_like :string_unpack_32bit_le, 'J_'
- it_behaves_like :string_unpack_32bit_le_unsigned, 'J_'
- end
-
- describe "with modifier '!'" do
- it_behaves_like :string_unpack_32bit_le, 'J!'
- it_behaves_like :string_unpack_32bit_le_unsigned, 'J!'
- end
- end
-
- describe "String#unpack with format 'j'" do
- describe "with modifier '_'" do
- it_behaves_like :string_unpack_32bit_le, 'j_'
- it_behaves_like :string_unpack_32bit_le_signed, 'j_'
- end
+ describe "String#unpack with format 'j'" do
+ describe "with modifier '<'" do
+ it_behaves_like :string_unpack_64bit_le, 'j<'
+ it_behaves_like :string_unpack_64bit_le_signed, 'j<'
+ end
- describe "with modifier '!'" do
- it_behaves_like :string_unpack_32bit_le, 'j!'
- it_behaves_like :string_unpack_32bit_le_signed, 'j!'
- end
- end
+ describe "with modifier '>'" do
+ it_behaves_like :string_unpack_64bit_be, 'j>'
+ it_behaves_like :string_unpack_64bit_be_signed, 'j>'
end
- big_endian do
- describe "String#unpack with format 'J'" do
- describe "with modifier '_'" do
- it_behaves_like :string_unpack_32bit_be, 'J_'
- it_behaves_like :string_unpack_32bit_be_unsigned, 'J_'
- end
+ describe "with modifier '<' and '_'" do
+ it_behaves_like :string_unpack_64bit_le, 'j<_'
+ it_behaves_like :string_unpack_64bit_le, 'j_<'
+ it_behaves_like :string_unpack_64bit_le_signed, 'j<_'
+ it_behaves_like :string_unpack_64bit_le_signed, 'j_<'
+ end
- describe "with modifier '!'" do
- it_behaves_like :string_unpack_32bit_be, 'J!'
- it_behaves_like :string_unpack_32bit_be_unsigned, 'J!'
- end
- end
+ describe "with modifier '<' and '!'" do
+ it_behaves_like :string_unpack_64bit_le, 'j<!'
+ it_behaves_like :string_unpack_64bit_le, 'j!<'
+ it_behaves_like :string_unpack_64bit_le_signed, 'j<!'
+ it_behaves_like :string_unpack_64bit_le_signed, 'j!<'
+ end
- describe "String#unpack with format 'j'" do
- describe "with modifier '_'" do
- it_behaves_like :string_unpack_32bit_be, 'j_'
- it_behaves_like :string_unpack_32bit_be_signed, 'j_'
- end
+ describe "with modifier '>' and '_'" do
+ it_behaves_like :string_unpack_64bit_be, 'j>_'
+ it_behaves_like :string_unpack_64bit_be, 'j_>'
+ it_behaves_like :string_unpack_64bit_be_signed, 'j>_'
+ it_behaves_like :string_unpack_64bit_be_signed, 'j_>'
+ end
- describe "with modifier '!'" do
- it_behaves_like :string_unpack_32bit_be, 'j!'
- it_behaves_like :string_unpack_32bit_be_signed, 'j!'
- end
- end
+ describe "with modifier '>' and '!'" do
+ it_behaves_like :string_unpack_64bit_be, 'j>!'
+ it_behaves_like :string_unpack_64bit_be, 'j!>'
+ it_behaves_like :string_unpack_64bit_be_signed, 'j>!'
+ it_behaves_like :string_unpack_64bit_be_signed, 'j!>'
end
+ end
+end
+platform_is pointer_size: 32 do
+ little_endian do
describe "String#unpack with format 'J'" do
- describe "with modifier '<'" do
- it_behaves_like :string_unpack_32bit_le, 'J<'
- it_behaves_like :string_unpack_32bit_le_unsigned, 'J<'
+ describe "with modifier '_'" do
+ it_behaves_like :string_unpack_32bit_le, 'J_'
+ it_behaves_like :string_unpack_32bit_le_unsigned, 'J_'
end
- describe "with modifier '>'" do
- it_behaves_like :string_unpack_32bit_be, 'J>'
- it_behaves_like :string_unpack_32bit_be_unsigned, 'J>'
+ describe "with modifier '!'" do
+ it_behaves_like :string_unpack_32bit_le, 'J!'
+ it_behaves_like :string_unpack_32bit_le_unsigned, 'J!'
end
+ end
- describe "with modifier '<' and '_'" do
- it_behaves_like :string_unpack_32bit_le, 'J<_'
- it_behaves_like :string_unpack_32bit_le, 'J_<'
- it_behaves_like :string_unpack_32bit_le_unsigned, 'J<_'
- it_behaves_like :string_unpack_32bit_le_unsigned, 'J_<'
+ describe "String#unpack with format 'j'" do
+ describe "with modifier '_'" do
+ it_behaves_like :string_unpack_32bit_le, 'j_'
+ it_behaves_like :string_unpack_32bit_le_signed, 'j_'
end
- describe "with modifier '<' and '!'" do
- it_behaves_like :string_unpack_32bit_le, 'J<!'
- it_behaves_like :string_unpack_32bit_le, 'J!<'
- it_behaves_like :string_unpack_32bit_le_unsigned, 'J<!'
- it_behaves_like :string_unpack_32bit_le_unsigned, 'J!<'
+ describe "with modifier '!'" do
+ it_behaves_like :string_unpack_32bit_le, 'j!'
+ it_behaves_like :string_unpack_32bit_le_signed, 'j!'
end
+ end
+ end
- describe "with modifier '>' and '_'" do
- it_behaves_like :string_unpack_32bit_be, 'J>_'
- it_behaves_like :string_unpack_32bit_be, 'J_>'
- it_behaves_like :string_unpack_32bit_be_unsigned, 'J>_'
- it_behaves_like :string_unpack_32bit_be_unsigned, 'J_>'
+ big_endian do
+ describe "String#unpack with format 'J'" do
+ describe "with modifier '_'" do
+ it_behaves_like :string_unpack_32bit_be, 'J_'
+ it_behaves_like :string_unpack_32bit_be_unsigned, 'J_'
end
- describe "with modifier '>' and '!'" do
- it_behaves_like :string_unpack_32bit_be, 'J>!'
- it_behaves_like :string_unpack_32bit_be, 'J!>'
- it_behaves_like :string_unpack_32bit_be_unsigned, 'J>!'
- it_behaves_like :string_unpack_32bit_be_unsigned, 'J!>'
+ describe "with modifier '!'" do
+ it_behaves_like :string_unpack_32bit_be, 'J!'
+ it_behaves_like :string_unpack_32bit_be_unsigned, 'J!'
end
end
describe "String#unpack with format 'j'" do
- describe "with modifier '<'" do
- it_behaves_like :string_unpack_32bit_le, 'j<'
- it_behaves_like :string_unpack_32bit_le_signed, 'j<'
+ describe "with modifier '_'" do
+ it_behaves_like :string_unpack_32bit_be, 'j_'
+ it_behaves_like :string_unpack_32bit_be_signed, 'j_'
end
- describe "with modifier '>'" do
- it_behaves_like :string_unpack_32bit_be, 'j>'
- it_behaves_like :string_unpack_32bit_be_signed, 'j>'
+ describe "with modifier '!'" do
+ it_behaves_like :string_unpack_32bit_be, 'j!'
+ it_behaves_like :string_unpack_32bit_be_signed, 'j!'
end
+ end
+ end
- describe "with modifier '<' and '_'" do
- it_behaves_like :string_unpack_32bit_le, 'j<_'
- it_behaves_like :string_unpack_32bit_le, 'j_<'
- it_behaves_like :string_unpack_32bit_le_signed, 'j<_'
- it_behaves_like :string_unpack_32bit_le_signed, 'j_<'
- end
+ describe "String#unpack with format 'J'" do
+ describe "with modifier '<'" do
+ it_behaves_like :string_unpack_32bit_le, 'J<'
+ it_behaves_like :string_unpack_32bit_le_unsigned, 'J<'
+ end
- describe "with modifier '<' and '!'" do
- it_behaves_like :string_unpack_32bit_le, 'j<!'
- it_behaves_like :string_unpack_32bit_le, 'j!<'
- it_behaves_like :string_unpack_32bit_le_signed, 'j<!'
- it_behaves_like :string_unpack_32bit_le_signed, 'j!<'
- end
+ describe "with modifier '>'" do
+ it_behaves_like :string_unpack_32bit_be, 'J>'
+ it_behaves_like :string_unpack_32bit_be_unsigned, 'J>'
+ end
- describe "with modifier '>' and '_'" do
- it_behaves_like :string_unpack_32bit_be, 'j>_'
- it_behaves_like :string_unpack_32bit_be, 'j_>'
- it_behaves_like :string_unpack_32bit_be_signed, 'j>_'
- it_behaves_like :string_unpack_32bit_be_signed, 'j_>'
- end
+ describe "with modifier '<' and '_'" do
+ it_behaves_like :string_unpack_32bit_le, 'J<_'
+ it_behaves_like :string_unpack_32bit_le, 'J_<'
+ it_behaves_like :string_unpack_32bit_le_unsigned, 'J<_'
+ it_behaves_like :string_unpack_32bit_le_unsigned, 'J_<'
+ end
- describe "with modifier '>' and '!'" do
- it_behaves_like :string_unpack_32bit_be, 'j>!'
- it_behaves_like :string_unpack_32bit_be, 'j!>'
- it_behaves_like :string_unpack_32bit_be_signed, 'j>!'
- it_behaves_like :string_unpack_32bit_be_signed, 'j!>'
- end
+ describe "with modifier '<' and '!'" do
+ it_behaves_like :string_unpack_32bit_le, 'J<!'
+ it_behaves_like :string_unpack_32bit_le, 'J!<'
+ it_behaves_like :string_unpack_32bit_le_unsigned, 'J<!'
+ it_behaves_like :string_unpack_32bit_le_unsigned, 'J!<'
+ end
+
+ describe "with modifier '>' and '_'" do
+ it_behaves_like :string_unpack_32bit_be, 'J>_'
+ it_behaves_like :string_unpack_32bit_be, 'J_>'
+ it_behaves_like :string_unpack_32bit_be_unsigned, 'J>_'
+ it_behaves_like :string_unpack_32bit_be_unsigned, 'J_>'
+ end
+
+ describe "with modifier '>' and '!'" do
+ it_behaves_like :string_unpack_32bit_be, 'J>!'
+ it_behaves_like :string_unpack_32bit_be, 'J!>'
+ it_behaves_like :string_unpack_32bit_be_unsigned, 'J>!'
+ it_behaves_like :string_unpack_32bit_be_unsigned, 'J!>'
+ end
+ end
+
+ describe "String#unpack with format 'j'" do
+ describe "with modifier '<'" do
+ it_behaves_like :string_unpack_32bit_le, 'j<'
+ it_behaves_like :string_unpack_32bit_le_signed, 'j<'
+ end
+
+ describe "with modifier '>'" do
+ it_behaves_like :string_unpack_32bit_be, 'j>'
+ it_behaves_like :string_unpack_32bit_be_signed, 'j>'
+ end
+
+ describe "with modifier '<' and '_'" do
+ it_behaves_like :string_unpack_32bit_le, 'j<_'
+ it_behaves_like :string_unpack_32bit_le, 'j_<'
+ it_behaves_like :string_unpack_32bit_le_signed, 'j<_'
+ it_behaves_like :string_unpack_32bit_le_signed, 'j_<'
+ end
+
+ describe "with modifier '<' and '!'" do
+ it_behaves_like :string_unpack_32bit_le, 'j<!'
+ it_behaves_like :string_unpack_32bit_le, 'j!<'
+ it_behaves_like :string_unpack_32bit_le_signed, 'j<!'
+ it_behaves_like :string_unpack_32bit_le_signed, 'j!<'
+ end
+
+ describe "with modifier '>' and '_'" do
+ it_behaves_like :string_unpack_32bit_be, 'j>_'
+ it_behaves_like :string_unpack_32bit_be, 'j_>'
+ it_behaves_like :string_unpack_32bit_be_signed, 'j>_'
+ it_behaves_like :string_unpack_32bit_be_signed, 'j_>'
+ end
+
+ describe "with modifier '>' and '!'" do
+ it_behaves_like :string_unpack_32bit_be, 'j>!'
+ it_behaves_like :string_unpack_32bit_be, 'j!>'
+ it_behaves_like :string_unpack_32bit_be_signed, 'j>!'
+ it_behaves_like :string_unpack_32bit_be_signed, 'j!>'
end
end
end
diff --git a/spec/ruby/core/string/unpack/l_spec.rb b/spec/ruby/core/string/unpack/l_spec.rb
index 11f0648fc7..0adb567eca 100644
--- a/spec/ruby/core/string/unpack/l_spec.rb
+++ b/spec/ruby/core/string/unpack/l_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
-require File.expand_path('../shared/basic', __FILE__)
-require File.expand_path('../shared/integer', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
+require_relative 'shared/basic'
+require_relative 'shared/integer'
describe "String#unpack with format 'L'" do
describe "with modifier '<'" do
@@ -14,7 +14,7 @@ describe "String#unpack with format 'L'" do
it_behaves_like :string_unpack_32bit_be_unsigned, 'L>'
end
- guard -> { platform_is wordsize: 32 or platform_is :mingw32 } do
+ platform_is c_long_size: 32 do
describe "with modifier '<' and '_'" do
it_behaves_like :string_unpack_32bit_le, 'L<_'
it_behaves_like :string_unpack_32bit_le, 'L_<'
@@ -44,7 +44,7 @@ describe "String#unpack with format 'L'" do
end
end
- guard -> { platform_is wordsize: 64 and platform_is_not :mingw32 } do
+ platform_is c_long_size: 64 do
describe "with modifier '<' and '_'" do
it_behaves_like :string_unpack_64bit_le, 'L<_'
it_behaves_like :string_unpack_64bit_le, 'L_<'
@@ -86,7 +86,7 @@ describe "String#unpack with format 'l'" do
it_behaves_like :string_unpack_32bit_be_signed, 'l>'
end
- guard -> { platform_is wordsize: 32 or platform_is :mingw32 } do
+ platform_is c_long_size: 32 do
describe "with modifier '<' and '_'" do
it_behaves_like :string_unpack_32bit_le, 'l<_'
it_behaves_like :string_unpack_32bit_le, 'l_<'
@@ -116,7 +116,7 @@ describe "String#unpack with format 'l'" do
end
end
- guard -> { platform_is wordsize: 64 and platform_is_not :mingw32 } do
+ platform_is c_long_size: 64 do
describe "with modifier '<' and '_'" do
it_behaves_like :string_unpack_64bit_le, 'l<_'
it_behaves_like :string_unpack_64bit_le, 'l_<'
@@ -160,7 +160,7 @@ little_endian do
it_behaves_like :string_unpack_32bit_le_signed, 'l'
end
- guard -> { platform_is wordsize: 32 or platform_is :mingw32 } do
+ platform_is c_long_size: 32 do
describe "String#unpack with format 'L' with modifier '_'" do
it_behaves_like :string_unpack_32bit_le, 'L_'
it_behaves_like :string_unpack_32bit_le_unsigned, 'L_'
@@ -182,7 +182,7 @@ little_endian do
end
end
- guard -> { platform_is wordsize: 64 and platform_is_not :mingw32 } do
+ platform_is c_long_size: 64 do
describe "String#unpack with format 'L' with modifier '_'" do
it_behaves_like :string_unpack_64bit_le, 'L_'
it_behaves_like :string_unpack_64bit_le_unsigned, 'L_'
@@ -218,7 +218,7 @@ big_endian do
it_behaves_like :string_unpack_32bit_be_signed, 'l'
end
- guard -> { platform_is wordsize: 32 or platform_is :mingw32 } do
+ platform_is c_long_size: 32 do
describe "String#unpack with format 'L' with modifier '_'" do
it_behaves_like :string_unpack_32bit_be, 'L_'
it_behaves_like :string_unpack_32bit_be_unsigned, 'L_'
@@ -240,7 +240,7 @@ big_endian do
end
end
- guard -> { platform_is wordsize: 64 and platform_is_not :mingw32 } do
+ platform_is c_long_size: 64 do
describe "String#unpack with format 'L' with modifier '_'" do
it_behaves_like :string_unpack_64bit_be, 'L_'
it_behaves_like :string_unpack_64bit_be_unsigned, 'L_'
diff --git a/spec/ruby/core/string/unpack/m_spec.rb b/spec/ruby/core/string/unpack/m_spec.rb
index 104f282fed..c1c1eea629 100644
--- a/spec/ruby/core/string/unpack/m_spec.rb
+++ b/spec/ruby/core/string/unpack/m_spec.rb
@@ -1,11 +1,13 @@
-# -*- encoding: ascii-8bit -*-
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
-require File.expand_path('../shared/basic', __FILE__)
+# encoding: binary
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
+require_relative 'shared/basic'
+require_relative 'shared/taint'
describe "String#unpack with format 'M'" do
it_behaves_like :string_unpack_basic, 'M'
it_behaves_like :string_unpack_no_platform, 'M'
+ it_behaves_like :string_unpack_taint, 'M'
it "decodes an empty string" do
"".unpack("M").should == [""]
@@ -95,11 +97,17 @@ describe "String#unpack with format 'M'" do
["=FF=\n", ["\xff"]]
].should be_computed_by(:unpack, "M")
end
+
+ it "unpacks incomplete escape sequences as literal characters" do
+ "foo=".unpack("M").should == ["foo="]
+ "foo=4".unpack("M").should == ["foo=4"]
+ end
end
describe "String#unpack with format 'm'" do
it_behaves_like :string_unpack_basic, 'm'
it_behaves_like :string_unpack_no_platform, 'm'
+ it_behaves_like :string_unpack_taint, 'm'
it "decodes an empty string" do
"".unpack("m").should == [""]
@@ -167,4 +175,18 @@ describe "String#unpack with format 'm'" do
"".unpack("m").first.encoding.should == Encoding::BINARY
"Ojs8PT4/QA==\n".unpack("m").first.encoding.should == Encoding::BINARY
end
+
+ it "does not raise an error for an invalid base64 character" do
+ "dGV%zdA==".unpack("m").should == ["test"]
+ end
+
+ describe "when given count 0" do
+ it "decodes base64" do
+ "dGVzdA==".unpack("m0").should == ["test"]
+ end
+
+ it "raises an ArgumentError for an invalid base64 character" do
+ -> { "dGV%zdA==".unpack("m0") }.should.raise(ArgumentError)
+ end
+ end
end
diff --git a/spec/ruby/core/string/unpack/n_spec.rb b/spec/ruby/core/string/unpack/n_spec.rb
index 6e85346338..09173f4fcb 100644
--- a/spec/ruby/core/string/unpack/n_spec.rb
+++ b/spec/ruby/core/string/unpack/n_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
-require File.expand_path('../shared/basic', __FILE__)
-require File.expand_path('../shared/integer', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
+require_relative 'shared/basic'
+require_relative 'shared/integer'
describe "String#unpack with format 'N'" do
it_behaves_like :string_unpack_basic, 'N'
diff --git a/spec/ruby/core/string/unpack/p_spec.rb b/spec/ruby/core/string/unpack/p_spec.rb
index 7c9a502a15..4103730269 100644
--- a/spec/ruby/core/string/unpack/p_spec.rb
+++ b/spec/ruby/core/string/unpack/p_spec.rb
@@ -1,21 +1,44 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
-require File.expand_path('../shared/basic', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
+require_relative 'shared/basic'
+require_relative 'shared/taint'
describe "String#unpack with format 'P'" do
it_behaves_like :string_unpack_basic, 'P'
+ it_behaves_like :string_unpack_taint, 'P'
- it "returns a random object after consuming a size-of a machine word bytes" do
- str = "\0" * 1.size
- str.unpack("P").should be_kind_of(Object)
+ it "round-trips a string through pack and unpack" do
+ ["hello"].pack("P").unpack("P5").should == ["hello"]
+ end
+
+ it "cannot unpack a string except from the same object that created it, or a duplicate of it" do
+ packed = ["hello"].pack("P")
+ packed.unpack("P5").should == ["hello"]
+ packed.dup.unpack("P5").should == ["hello"]
+ -> { packed.to_sym.to_s.unpack("P5") }.should.raise(ArgumentError, /no associated pointer/)
+ end
+
+ it "reads as many characters as specified" do
+ ["hello"].pack("P").unpack("P1").should == ["h"]
+ end
+
+ it "reads only as far as a NUL character" do
+ ["hello"].pack("P").unpack("P10").should == ["hello"]
end
end
describe "String#unpack with format 'p'" do
it_behaves_like :string_unpack_basic, 'p'
+ it_behaves_like :string_unpack_taint, 'p'
+
+ it "round-trips a string through pack and unpack" do
+ ["hello"].pack("p").unpack("p").should == ["hello"]
+ end
- it "returns a random object after consuming a size-of a machine word bytes" do
- str = "\0" * 1.size
- str.unpack("p").should be_kind_of(Object)
+ it "cannot unpack a string except from the same object that created it, or a duplicate of it" do
+ packed = ["hello"].pack("p")
+ packed.unpack("p").should == ["hello"]
+ packed.dup.unpack("p").should == ["hello"]
+ -> { packed.to_sym.to_s.unpack("p") }.should.raise(ArgumentError, /no associated pointer/)
end
end
diff --git a/spec/ruby/core/string/unpack/percent_spec.rb b/spec/ruby/core/string/unpack/percent_spec.rb
index 38cf81b037..7142bbf241 100644
--- a/spec/ruby/core/string/unpack/percent_spec.rb
+++ b/spec/ruby/core/string/unpack/percent_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
describe "String#unpack with format '%'" do
it "raises an Argument Error" do
- lambda { "abc".unpack("%") }.should raise_error(ArgumentError)
+ -> { "abc".unpack("%") }.should.raise(ArgumentError)
end
end
diff --git a/spec/ruby/core/string/unpack/q_spec.rb b/spec/ruby/core/string/unpack/q_spec.rb
index 91e65a9405..2f667d6c4d 100644
--- a/spec/ruby/core/string/unpack/q_spec.rb
+++ b/spec/ruby/core/string/unpack/q_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
-require File.expand_path('../shared/basic', __FILE__)
-require File.expand_path('../shared/integer', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
+require_relative 'shared/basic'
+require_relative 'shared/integer'
describe "String#unpack with format 'Q'" do
describe "with modifier '<'" do
diff --git a/spec/ruby/core/string/unpack/r_spec.rb b/spec/ruby/core/string/unpack/r_spec.rb
new file mode 100644
index 0000000000..a385951aa8
--- /dev/null
+++ b/spec/ruby/core/string/unpack/r_spec.rb
@@ -0,0 +1,85 @@
+# encoding: binary
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
+require_relative 'shared/basic'
+
+ruby_version_is "4.1" do
+ describe "String#unpack with format 'R'" do
+ it_behaves_like :string_unpack_basic, 'R'
+ it_behaves_like :string_unpack_no_platform, 'R'
+
+ it "decodes a ULEB128 integer" do
+ [ ["\x00", [0]],
+ ["\x01", [1]],
+ ["\x7f", [127]],
+ ["\x80\x01", [128]],
+ ["\xff\x7f", [0x3fff]],
+ ["\x80\x80\x01", [0x4000]],
+ ["\xff\xff\xff\xff\x0f", [0xffffffff]],
+ ["\x80\x80\x80\x80\x10", [0x100000000]],
+ ["\xff\xff\xff\xff\xff\xff\xff\xff\xff\x01", [0xffff_ffff_ffff_ffff]],
+ ].should be_computed_by(:unpack, "R")
+ end
+
+ it "decodes multiple values with '*' modifier" do
+ "\x01\x02".unpack("R*").should == [1, 2]
+ "\x7f\x80\x01".unpack("R*").should == [127, 128]
+ end
+
+ it "returns nil for incomplete data" do
+ "\xFF".unpack("R").should == [nil]
+ "\xFF".unpack1("R").should == nil
+ end
+
+ it "returns nil for remaining incomplete values after a valid one" do
+ bytes = [256].pack("R")
+ (bytes + "\xFF").unpack("RRRR").should == [256, nil, nil, nil]
+ end
+
+ it "skips incomplete values with '*' modifier" do
+ "\xFF".unpack("R*").should == []
+ end
+ end
+
+ describe "String#unpack with format 'r'" do
+ it_behaves_like :string_unpack_basic, 'r'
+ it_behaves_like :string_unpack_no_platform, 'r'
+
+ it "decodes a SLEB128 integer" do
+ [ ["\x00", [0]],
+ ["\x01", [1]],
+ ["\x7f", [-1]],
+ ["\x7e", [-2]],
+ ["\xff\x00", [127]],
+ ["\x80\x01", [128]],
+ ["\x81\x7f", [-127]],
+ ["\x80\x7f", [-128]],
+ ].should be_computed_by(:unpack, "r")
+ end
+
+ it "decodes larger numbers" do
+ "\xff\xff\x00".unpack("r").should == [0x3fff]
+ "\x80\x80\x01".unpack("r").should == [0x4000]
+ "\x81\x80\x7f".unpack("r").should == [-0x3fff]
+ "\x80\x80\x7f".unpack("r").should == [-0x4000]
+ end
+
+ it "decodes multiple values with '*' modifier" do
+ "\x00\x01\x7f".unpack("r*").should == [0, 1, -1]
+ end
+
+ it "returns nil for incomplete data" do
+ "\xFF".unpack("r").should == [nil]
+ "\xFF".unpack1("r").should == nil
+ end
+
+ it "returns nil for remaining incomplete values after a valid one" do
+ bytes = [256].pack("r")
+ (bytes + "\xFF").unpack("rrrr").should == [256, nil, nil, nil]
+ end
+
+ it "skips incomplete values with '*' modifier" do
+ "\xFF".unpack("r*").should == []
+ end
+ end
+end
diff --git a/spec/ruby/core/string/unpack/s_spec.rb b/spec/ruby/core/string/unpack/s_spec.rb
index c6b079b0a6..d331fd720e 100644
--- a/spec/ruby/core/string/unpack/s_spec.rb
+++ b/spec/ruby/core/string/unpack/s_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
-require File.expand_path('../shared/basic', __FILE__)
-require File.expand_path('../shared/integer', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
+require_relative 'shared/basic'
+require_relative 'shared/integer'
describe "String#unpack with format 'S'" do
describe "with modifier '<'" do
diff --git a/spec/ruby/core/string/unpack/shared/basic.rb b/spec/ruby/core/string/unpack/shared/basic.rb
index 0ecbf615af..2ee2d6899a 100644
--- a/spec/ruby/core/string/unpack/shared/basic.rb
+++ b/spec/ruby/core/string/unpack/shared/basic.rb
@@ -1,29 +1,27 @@
describe :string_unpack_basic, shared: true do
it "ignores whitespace in the format string" do
- "abc".unpack("a \t\n\v\f\r"+unpack_format).should be_an_instance_of(Array)
+ "abc".unpack("a \t\n\v\f\r"+unpack_format).should.instance_of?(Array)
end
it "calls #to_str to coerce the directives string" do
d = mock("unpack directive")
d.should_receive(:to_str).and_return("a"+unpack_format)
- "abc".unpack(d).should be_an_instance_of(Array)
+ "abc".unpack(d).should.instance_of?(Array)
end
- it "raises a TypeError when passed nil" do
- lambda { "abc".unpack(nil) }.should raise_error(TypeError)
- end
-
- it "raises a TypeError when passed an Integer" do
- lambda { "abc".unpack(1) }.should raise_error(TypeError)
+ it "raises ArgumentError when a directive is unknown" do
+ -> { "abcdefgh".unpack("a K" + unpack_format) }.should.raise(ArgumentError, "unknown unpack directive 'K' in 'a K#{unpack_format}'")
+ -> { "abcdefgh".unpack("a 0" + unpack_format) }.should.raise(ArgumentError, "unknown unpack directive '0' in 'a 0#{unpack_format}'")
+ -> { "abcdefgh".unpack("a :" + unpack_format) }.should.raise(ArgumentError, "unknown unpack directive ':' in 'a :#{unpack_format}'")
end
end
describe :string_unpack_no_platform, shared: true do
it "raises an ArgumentError when the format modifier is '_'" do
- lambda { "abcdefgh".unpack(unpack_format("_")) }.should raise_error(ArgumentError)
+ -> { "abcdefgh".unpack(unpack_format("_")) }.should.raise(ArgumentError)
end
it "raises an ArgumentError when the format modifier is '!'" do
- lambda { "abcdefgh".unpack(unpack_format("!")) }.should raise_error(ArgumentError)
+ -> { "abcdefgh".unpack(unpack_format("!")) }.should.raise(ArgumentError)
end
end
diff --git a/spec/ruby/core/string/unpack/shared/float.rb b/spec/ruby/core/string/unpack/shared/float.rb
index 208dc357af..5525c3fe73 100644
--- a/spec/ruby/core/string/unpack/shared/float.rb
+++ b/spec/ruby/core/string/unpack/shared/float.rb
@@ -1,4 +1,4 @@
-# -*- encoding: ascii-8bit -*-
+# encoding: binary
describe :string_unpack_float_le, shared: true do
it "decodes one float for a single format character" do
@@ -53,12 +53,13 @@ describe :string_unpack_float_le, shared: true do
it "decodes NaN" do
# mumble mumble NaN mumble https://bugs.ruby-lang.org/issues/5884
- [nan_value].pack(unpack_format).unpack(unpack_format).first.nan?.should be_true
+ [nan_value].pack(unpack_format).unpack(unpack_format).first.nan?.should == true
end
- it "ignores NULL bytes between directives" do
- array = "\x9a\x999@33\xb3?".unpack(unpack_format("\000", 2))
- array.should == [2.9000000953674316, 1.399999976158142]
+ it "raise ArgumentError for NULL bytes between directives" do
+ -> {
+ "\x9a\x999@33\xb3?".unpack(unpack_format("\000", 2))
+ }.should.raise(ArgumentError, /unknown unpack directive/)
end
it "ignores spaces between directives" do
@@ -120,12 +121,13 @@ describe :string_unpack_float_be, shared: true do
it "decodes NaN" do
# mumble mumble NaN mumble https://bugs.ruby-lang.org/issues/5884
- [nan_value].pack(unpack_format).unpack(unpack_format).first.nan?.should be_true
+ [nan_value].pack(unpack_format).unpack(unpack_format).first.nan?.should == true
end
- it "ignores NULL bytes between directives" do
- array = "@9\x99\x9a?\xb333".unpack(unpack_format("\000", 2))
- array.should == [2.9000000953674316, 1.399999976158142]
+ it "raise ArgumentError for NULL bytes between directives" do
+ -> {
+ "@9\x99\x9a?\xb333".unpack(unpack_format("\000", 2))
+ }.should.raise(ArgumentError, /unknown unpack directive/)
end
it "ignores spaces between directives" do
@@ -190,11 +192,13 @@ describe :string_unpack_double_le, shared: true do
it "decodes NaN" do
# mumble mumble NaN mumble https://bugs.ruby-lang.org/issues/5884
- [nan_value].pack(unpack_format).unpack(unpack_format).first.nan?.should be_true
+ [nan_value].pack(unpack_format).unpack(unpack_format).first.nan?.should == true
end
- it "ignores NULL bytes between directives" do
- "333333\x07@ffffff\xf6?".unpack(unpack_format("\000", 2)).should == [2.9, 1.4]
+ it "raise ArgumentError for NULL bytes between directives" do
+ -> {
+ "333333\x07@ffffff\xf6?".unpack(unpack_format("\000", 2))
+ }.should.raise(ArgumentError, /unknown unpack directive/)
end
it "ignores spaces between directives" do
@@ -258,11 +262,13 @@ describe :string_unpack_double_be, shared: true do
it "decodes NaN" do
# mumble mumble NaN mumble https://bugs.ruby-lang.org/issues/5884
- [nan_value].pack(unpack_format).unpack(unpack_format).first.nan?.should be_true
+ [nan_value].pack(unpack_format).unpack(unpack_format).first.nan?.should == true
end
- it "ignores NULL bytes between directives" do
- "@\x07333333?\xf6ffffff".unpack(unpack_format("\000", 2)).should == [2.9, 1.4]
+ it "raise ArgumentError for NULL bytes between directives" do
+ -> {
+ "@\x07333333?\xf6ffffff".unpack(unpack_format("\000", 2))
+ }.should.raise(ArgumentError, /unknown unpack directive/)
end
it "ignores spaces between directives" do
diff --git a/spec/ruby/core/string/unpack/shared/integer.rb b/spec/ruby/core/string/unpack/shared/integer.rb
index 03dfb5c682..c66156536b 100644
--- a/spec/ruby/core/string/unpack/shared/integer.rb
+++ b/spec/ruby/core/string/unpack/shared/integer.rb
@@ -1,4 +1,4 @@
-# -*- encoding: ascii-8bit -*-
+# encoding: binary
describe :string_unpack_16bit_le, shared: true do
it "decodes one short for a single format character" do
@@ -32,8 +32,10 @@ describe :string_unpack_16bit_le, shared: true do
].should be_computed_by(:unpack, unpack_format(3))
end
- it "ignores NULL bytes between directives" do
- "abcd".unpack(unpack_format("\000", 2)).should == [25185, 25699]
+ it "raise ArgumentError for NULL bytes between directives" do
+ -> {
+ "abcd".unpack(unpack_format("\000", 2))
+ }.should.raise(ArgumentError, /unknown unpack directive/)
end
it "ignores spaces between directives" do
@@ -85,8 +87,10 @@ describe :string_unpack_16bit_be, shared: true do
].should be_computed_by(:unpack, unpack_format(3))
end
- it "ignores NULL bytes between directives" do
- "badc".unpack(unpack_format("\000", 2)).should == [25185, 25699]
+ it "raise ArgumentError for NULL bytes between directives" do
+ -> {
+ "badc".unpack(unpack_format("\000", 2))
+ }.should.raise(ArgumentError, /unknown unpack directive/)
end
it "ignores spaces between directives" do
@@ -139,8 +143,10 @@ describe :string_unpack_32bit_le, shared: true do
].should be_computed_by(:unpack, unpack_format(3))
end
- it "ignores NULL bytes between directives" do
- "abcdefgh".unpack(unpack_format("\000", 2)).should == [1684234849, 1751606885]
+ it "raise ArgumentError for NULL bytes between directives" do
+ -> {
+ "abcdefgh".unpack(unpack_format("\000", 2))
+ }.should.raise(ArgumentError, /unknown unpack directive/)
end
it "ignores spaces between directives" do
@@ -193,8 +199,10 @@ describe :string_unpack_32bit_be, shared: true do
].should be_computed_by(:unpack, unpack_format(3))
end
- it "ignores NULL bytes between directives" do
- "dcbahgfe".unpack(unpack_format("\000", 2)).should == [1684234849, 1751606885]
+ it "raise ArgumentError for NULL bytes between directives" do
+ -> {
+ "dcbahgfe".unpack(unpack_format("\000", 2))
+ }.should.raise(ArgumentError, /unknown unpack directive/)
end
it "ignores spaces between directives" do
@@ -243,9 +251,10 @@ describe :string_unpack_64bit_le, shared: true do
"abc".unpack(unpack_format('*')).should == []
end
- it "ignores NULL bytes between directives" do
- array = "abcdefghabghefcd".unpack(unpack_format("\000", 2))
- array.should == [7523094288207667809, 7233738012216484449]
+ it "raise ArgumentError for NULL bytes between directives" do
+ -> {
+ "badc".unpack(unpack_format("\000", 2))
+ }.should.raise(ArgumentError, /unknown unpack directive/)
end
it "ignores spaces between directives" do
@@ -305,9 +314,10 @@ describe :string_unpack_64bit_be, shared: true do
"abc".unpack(unpack_format('*')).should == []
end
- it "ignores NULL bytes between directives" do
- array = "hgfedcbadcfehgba".unpack(unpack_format("\000", 2))
- array.should == [7523094288207667809, 7233738012216484449]
+ it "raise ArgumentError for NULL bytes between directives" do
+ -> {
+ "hgfedcbadcfehgba".unpack(unpack_format("\000", 2))
+ }.should.raise(ArgumentError, /unknown unpack directive/)
end
it "ignores spaces between directives" do
diff --git a/spec/ruby/core/string/unpack/shared/taint.rb b/spec/ruby/core/string/unpack/shared/taint.rb
new file mode 100644
index 0000000000..79c7251f01
--- /dev/null
+++ b/spec/ruby/core/string/unpack/shared/taint.rb
@@ -0,0 +1,2 @@
+describe :string_unpack_taint, shared: true do
+end
diff --git a/spec/ruby/core/string/unpack/shared/unicode.rb b/spec/ruby/core/string/unpack/shared/unicode.rb
index a2b4e142b2..9b4e0c09de 100644
--- a/spec/ruby/core/string/unpack/shared/unicode.rb
+++ b/spec/ruby/core/string/unpack/shared/unicode.rb
@@ -50,8 +50,10 @@ describe :string_unpack_unicode, shared: true do
"\xc2\x80".unpack("UUUU").should == [0x80]
end
- it "ignores NULL bytes between directives" do
- "\x01\x02".unpack("U\x00U").should == [1, 2]
+ it "raise ArgumentError for NULL bytes between directives" do
+ -> {
+ "\x01\x02".unpack("U\x00U")
+ }.should.raise(ArgumentError, /unknown unpack directive/)
end
it "ignores spaces between directives" do
diff --git a/spec/ruby/core/string/unpack/u_spec.rb b/spec/ruby/core/string/unpack/u_spec.rb
index 0765da8d96..720c1b8583 100644
--- a/spec/ruby/core/string/unpack/u_spec.rb
+++ b/spec/ruby/core/string/unpack/u_spec.rb
@@ -1,26 +1,29 @@
-# -*- encoding: ascii-8bit -*-
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
-require File.expand_path('../shared/basic', __FILE__)
-require File.expand_path('../shared/unicode', __FILE__)
+# encoding: binary
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
+require_relative 'shared/basic'
+require_relative 'shared/unicode'
+require_relative 'shared/taint'
describe "String#unpack with format 'U'" do
it_behaves_like :string_unpack_basic, 'U'
it_behaves_like :string_unpack_no_platform, 'U'
it_behaves_like :string_unpack_unicode, 'U'
+ it_behaves_like :string_unpack_taint, 'U'
it "raises ArgumentError on a malformed byte sequence" do
- lambda { "\xE3".unpack('U') }.should raise_error(ArgumentError)
+ -> { "\xE3".unpack('U') }.should.raise(ArgumentError)
end
it "raises ArgumentError on a malformed byte sequence and doesn't continue when used with the * modifier" do
- lambda { "\xE3".unpack('U*') }.should raise_error(ArgumentError)
+ -> { "\xE3".unpack('U*') }.should.raise(ArgumentError)
end
end
describe "String#unpack with format 'u'" do
it_behaves_like :string_unpack_basic, 'u'
it_behaves_like :string_unpack_no_platform, 'u'
+ it_behaves_like :string_unpack_taint, 'u'
it "decodes an empty string as an empty string" do
"".unpack("u").should == [""]
@@ -28,10 +31,10 @@ describe "String#unpack with format 'u'" do
it "decodes into raw (ascii) string values" do
str = "".unpack("u")[0]
- str.encoding.name.should == 'ASCII-8BIT'
+ str.encoding.should == Encoding::BINARY
- str = "1".force_encoding('UTF-8').unpack("u")[0]
- str.encoding.name.should == 'ASCII-8BIT'
+ str = "1".dup.force_encoding('UTF-8').unpack("u")[0]
+ str.encoding.should == Encoding::BINARY
end
it "decodes the complete string ignoring newlines when given a single directive" do
diff --git a/spec/ruby/core/string/unpack/v_spec.rb b/spec/ruby/core/string/unpack/v_spec.rb
index 33cf23c68b..929e8712cb 100644
--- a/spec/ruby/core/string/unpack/v_spec.rb
+++ b/spec/ruby/core/string/unpack/v_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
-require File.expand_path('../shared/basic', __FILE__)
-require File.expand_path('../shared/integer', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
+require_relative 'shared/basic'
+require_relative 'shared/integer'
describe "String#unpack with format 'V'" do
it_behaves_like :string_unpack_basic, 'V'
diff --git a/spec/ruby/core/string/unpack/w_spec.rb b/spec/ruby/core/string/unpack/w_spec.rb
index 22f5980a46..cc9aecac9c 100644
--- a/spec/ruby/core/string/unpack/w_spec.rb
+++ b/spec/ruby/core/string/unpack/w_spec.rb
@@ -1,7 +1,7 @@
-# -*- encoding: ascii-8bit -*-
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
-require File.expand_path('../shared/basic', __FILE__)
+# encoding: binary
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
+require_relative 'shared/basic'
describe "String#unpack with directive 'w'" do
it_behaves_like :string_unpack_basic, 'w'
@@ -15,11 +15,23 @@ describe "String#unpack with directive 'w'" do
].should be_computed_by(:unpack, "w")
end
- it "ignores NULL bytes between directives" do
- "\x01\x02\x03".unpack("w\x00w").should == [1, 2]
+ it "raise ArgumentError for NULL bytes between directives" do
+ -> {
+ "\x01\x02\x03".unpack("w\x00w")
+ }.should.raise(ArgumentError, /unknown unpack directive/)
end
it "ignores spaces between directives" do
"\x01\x02\x03".unpack("w w").should == [1, 2]
end
end
+
+describe "String#unpack with directive 'w*'" do
+
+ it "decodes BER-compressed integers" do
+ "\x01\x02\x03\x04".unpack("w*").should == [1, 2, 3, 4]
+ "\x00\xCE\x0F\x84\x80\x80\x80\x80\x80\x80\x80\x80\x00\x01\x00".unpack("w*").should == [0, 9999, 2**65, 1, 0]
+ "\x81\x80\x80\x80\x80\x80\x80\x80\x80\x00\x90\x80\x80\x80\x80\x80\x80\x80\x03\x01\x02".unpack("w*").should == [2**63, (2**60 + 3), 1, 2]
+ end
+
+end
diff --git a/spec/ruby/core/string/unpack/x_spec.rb b/spec/ruby/core/string/unpack/x_spec.rb
index e765472413..fb2e79fc1f 100644
--- a/spec/ruby/core/string/unpack/x_spec.rb
+++ b/spec/ruby/core/string/unpack/x_spec.rb
@@ -1,7 +1,7 @@
-# -*- encoding: ascii-8bit -*-
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
-require File.expand_path('../shared/basic', __FILE__)
+# encoding: binary
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
+require_relative 'shared/basic'
describe "String#unpack with format 'X'" do
it_behaves_like :string_unpack_basic, 'X'
@@ -24,11 +24,11 @@ describe "String#unpack with format 'X'" do
end
it "raises an ArgumentError when passed the '*' modifier if the remaining bytes exceed the bytes from the index to the start of the String" do
- lambda { "abcd".unpack("CX*C") }.should raise_error(ArgumentError)
+ -> { "abcd".unpack("CX*C") }.should.raise(ArgumentError)
end
it "raises an ArgumentError if the count exceeds the bytes from current index to the start of the String" do
- lambda { "\x01\x02\x03\x04".unpack("C3X4C") }.should raise_error(ArgumentError)
+ -> { "\x01\x02\x03\x04".unpack("C3X4C") }.should.raise(ArgumentError)
end
end
@@ -57,6 +57,6 @@ describe "String#unpack with format 'x'" do
end
it "raises an ArgumentError if the count exceeds the size of the String" do
- lambda { "\x01\x02\x03\x04".unpack("C2x3C") }.should raise_error(ArgumentError)
+ -> { "\x01\x02\x03\x04".unpack("C2x3C") }.should.raise(ArgumentError)
end
end
diff --git a/spec/ruby/core/string/unpack/z_spec.rb b/spec/ruby/core/string/unpack/z_spec.rb
index 7c3d167ac2..1030390550 100644
--- a/spec/ruby/core/string/unpack/z_spec.rb
+++ b/spec/ruby/core/string/unpack/z_spec.rb
@@ -1,13 +1,15 @@
-# -*- encoding: ascii-8bit -*-
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
-require File.expand_path('../shared/basic', __FILE__)
-require File.expand_path('../shared/string', __FILE__)
+# encoding: binary
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
+require_relative 'shared/basic'
+require_relative 'shared/string'
+require_relative 'shared/taint'
describe "String#unpack with format 'Z'" do
it_behaves_like :string_unpack_basic, 'Z'
it_behaves_like :string_unpack_no_platform, 'Z'
it_behaves_like :string_unpack_string, 'Z'
+ it_behaves_like :string_unpack_taint, 'Z'
it "stops decoding at NULL bytes when passed the '*' modifier" do
"a\x00\x00 b \x00c".unpack('Z*Z*Z*Z*').should == ["a", "", " b ", "c"]
@@ -18,4 +20,9 @@ describe "String#unpack with format 'Z'" do
["\x00a\x00 bc \x00", ["", "c"]]
].should be_computed_by(:unpack, "Z5Z")
end
+
+ it "does not advance past the null byte when given a 'Z' format specifier" do
+ "a\x00\x0f".unpack('Zxc').should == ['a', 15]
+ "a\x00\x0f".unpack('Zcc').should == ['a', 0, 15]
+ end
end
diff --git a/spec/ruby/core/string/unpack1_spec.rb b/spec/ruby/core/string/unpack1_spec.rb
index 6941bc1173..ee10042eb8 100644
--- a/spec/ruby/core/string/unpack1_spec.rb
+++ b/spec/ruby/core/string/unpack1_spec.rb
@@ -1,12 +1,61 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-ruby_version_is "2.4" do
- describe "String#unpack1" do
- it "returns the first value of #unpack" do
- "ABCD".unpack1('x3C').should == "ABCD".unpack('x3C')[0]
- "\u{3042 3044 3046}".unpack1("U*").should == 0x3042
- "aG9nZWZ1Z2E=".unpack1("m").should == "hogefuga"
- "A".unpack1("B*").should == "01000001"
+require_relative '../../spec_helper'
+
+describe "String#unpack1" do
+ it "returns the first value of #unpack" do
+ "ABCD".unpack1('x3C').should == "ABCD".unpack('x3C')[0]
+ "\u{3042 3044 3046}".unpack1("U*").should == 0x3042
+ "aG9nZWZ1Z2E=".unpack1("m").should == "hogefuga"
+ "A".unpack1("B*").should == "01000001"
+ end
+
+ it "starts unpacking from the given offset" do
+ "ZZABCD".unpack1('x3C', offset: 2).should == "ABCD".unpack('x3C')[0]
+ "ZZZZaG9nZWZ1Z2E=".unpack1("m", offset: 4).should == "hogefuga"
+ "ZA".unpack1("B*", offset: 1).should == "01000001"
+ end
+
+ it "traits offset as a bytes offset" do
+ "؈".unpack("CC").should == [216, 136]
+ "؈".unpack1("C").should == 216
+ "؈".unpack1("C", offset: 1).should == 136
+ end
+
+ describe "when the offset is negative" do
+ ruby_version_is "4.1" do
+ it "starts unpacking from the end" do
+ "abc".unpack1("C", offset: -2).should == 98
+ end
+
+ it "raises an ArgumentError if it is less than -length" do
+ -> { "a".unpack1("C", offset: -2) }.should.raise(ArgumentError, "offset outside of string")
+ end
+ end
+
+ ruby_version_is ""..."4.1" do
+ it "raises an ArgumentError" do
+ -> { "a".unpack1("C", offset: -1) }.should.raise(ArgumentError, "offset can't be negative")
+ end
+ end
+ end
+
+ it "returns nil if the offset is at the end of the string" do
+ "a".unpack1("C", offset: 1).should == nil
+ end
+
+ it "raises an ArgumentError when the offset is larger than the string bytesize" do
+ -> { "a".unpack1("C", offset: 2) }.should.raise(ArgumentError, "offset outside of string")
+ end
+
+ context "with format 'm0'" do
+ # unpack1("m0") takes a special code path that calls Pack.unpackBase46Strict instead of Pack.unpack_m,
+ # which is why we repeat the tests for unpack("m0") here.
+
+ it "decodes base64" do
+ "dGVzdA==".unpack1("m0").should == "test"
+ end
+
+ it "raises an ArgumentError for an invalid base64 character" do
+ -> { "dGV%zdA==".unpack1("m0") }.should.raise(ArgumentError)
end
end
end
diff --git a/spec/ruby/core/string/unpack_spec.rb b/spec/ruby/core/string/unpack_spec.rb
new file mode 100644
index 0000000000..eb4710ce14
--- /dev/null
+++ b/spec/ruby/core/string/unpack_spec.rb
@@ -0,0 +1,46 @@
+require_relative '../../spec_helper'
+
+describe "String#unpack" do
+ it "raises a TypeError when passed nil" do
+ -> { "abc".unpack(nil) }.should.raise(TypeError)
+ end
+
+ it "raises a TypeError when passed an Integer" do
+ -> { "abc".unpack(1) }.should.raise(TypeError)
+ end
+
+ it "starts unpacking from the given offset" do
+ "abc".unpack("CC", offset: 1).should == [98, 99]
+ end
+
+ it "traits offset as a bytes offset" do
+ "؈".unpack("CC").should == [216, 136]
+ "؈".unpack("CC", offset: 1).should == [136, nil]
+ end
+
+ describe "when the offset is negative" do
+ ruby_version_is "4.1" do
+ it "starts unpacking from the end" do
+ "abc".unpack("CC", offset: -2).should == [98, 99]
+ end
+
+ it "raises an ArgumentError if it is less than -length" do
+ -> { "a".unpack("C", offset: -2) }.should.raise(ArgumentError, "offset outside of string")
+ end
+ end
+
+ ruby_version_is ""..."4.1" do
+ it "raises an ArgumentError" do
+ -> { "a".unpack("C", offset: -1) }.should.raise(ArgumentError, "offset can't be negative")
+ end
+ end
+ end
+
+ it "returns nil if the offset is at the end of the string" do
+ "a".unpack("C", offset: 1).should == [nil]
+ end
+
+ it "raises an ArgumentError when the offset is larger than the string" do
+ -> { "a".unpack("C", offset: 2) }.should.raise(ArgumentError, "offset outside of string")
+ end
+end
diff --git a/spec/ruby/core/string/upcase_spec.rb b/spec/ruby/core/string/upcase_spec.rb
index 0094380664..a6e1869267 100644
--- a/spec/ruby/core/string/upcase_spec.rb
+++ b/spec/ruby/core/string/upcase_spec.rb
@@ -1,6 +1,7 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes.rb', __FILE__)
+# frozen_string_literal: false
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "String#upcase" do
it "returns a copy of self with all lowercase letters upcased" do
@@ -8,51 +9,169 @@ describe "String#upcase" do
"hello".upcase.should == "HELLO"
end
- ruby_version_is ''...'2.4' do
- it "is locale insensitive (only replaces a-z)" do
- "äöü".upcase.should == "äöü"
+ it "returns a String in the same encoding as self" do
+ "hello".encode("US-ASCII").upcase.encoding.should == Encoding::US_ASCII
+ end
+
+ describe "full Unicode case mapping" do
+ it "works for all of Unicode with no option" do
+ "äöü".upcase.should == "ÄÖÜ"
+ end
- str = Array.new(256) { |c| c.chr }.join
- expected = Array.new(256) do |i|
- c = i.chr
- c.between?("a", "z") ? c.upcase : c
- end.join
+ it "updates string metadata" do
+ upcased = "aßet".upcase
- str.upcase.should == expected
+ upcased.should == "ASSET"
+ upcased.size.should == 5
+ upcased.bytesize.should == 5
+ upcased.ascii_only?.should == true
end
end
- ruby_version_is '2.4' do
- it "works for all of Unicode" do
- "äöü".upcase.should == "ÄÖÜ"
+ describe "ASCII-only case mapping" do
+ it "does not upcase non-ASCII characters" do
+ "aßet".upcase(:ascii).should == "AßET"
+ end
+
+ it "works with substrings" do
+ "prefix té"[-2..-1].upcase(:ascii).should == "Té"
+ end
+ end
+
+ describe "full Unicode case mapping adapted for Turkic languages" do
+ it "upcases ASCII characters according to Turkic semantics" do
+ "i".upcase(:turkic).should == "İ"
+ end
+
+ it "allows Lithuanian as an extra option" do
+ "i".upcase(:turkic, :lithuanian).should == "İ"
+ end
+
+ it "does not allow any other additional option" do
+ -> { "i".upcase(:turkic, :ascii) }.should.raise(ArgumentError)
end
end
- it "taints result when self is tainted" do
- "".taint.upcase.tainted?.should == true
- "X".taint.upcase.tainted?.should == true
- "x".taint.upcase.tainted?.should == true
+ describe "full Unicode case mapping adapted for Lithuanian" do
+ it "currently works the same as full Unicode case mapping" do
+ "iß".upcase(:lithuanian).should == "ISS"
+ end
+
+ it "allows Turkic as an extra option (and applies Turkic semantics)" do
+ "iß".upcase(:lithuanian, :turkic).should == "İSS"
+ end
+
+ it "does not allow any other additional option" do
+ -> { "iß".upcase(:lithuanian, :ascii) }.should.raise(ArgumentError)
+ end
end
- it "returns a subclass instance for subclasses" do
- StringSpecs::MyString.new("fooBAR").upcase.should be_an_instance_of(StringSpecs::MyString)
+ it "does not allow the :fold option for upcasing" do
+ -> { "abc".upcase(:fold) }.should.raise(ArgumentError)
+ end
+
+ it "does not allow invalid options" do
+ -> { "abc".upcase(:invalid_option) }.should.raise(ArgumentError)
+ end
+
+ it "returns a String instance for subclasses" do
+ StringSpecs::MyString.new("fooBAR").upcase.should.instance_of?(String)
end
end
describe "String#upcase!" do
it "modifies self in place" do
a = "HeLlO"
- a.upcase!.should equal(a)
+ a.upcase!.should.equal?(a)
a.should == "HELLO"
end
+ it "modifies self in place for non-ascii-compatible encodings" do
+ a = "HeLlO".encode("utf-16le")
+ a.upcase!
+ a.should == "HELLO".encode("utf-16le")
+ end
- ruby_version_is '2.4' do
- it "modifies self in place for all of Unicode" do
+ describe "full Unicode case mapping" do
+ it "modifies self in place for all of Unicode with no option" do
a = "äöü"
- a.upcase!.should equal(a)
+ a.upcase!
a.should == "ÄÖÜ"
end
+
+ it "works for non-ascii-compatible encodings" do
+ a = "äöü".encode("utf-16le")
+ a.upcase!
+ a.should == "ÄÖÜ".encode("utf-16le")
+ end
+
+ it "updates string metadata for self" do
+ upcased = "aßet"
+ upcased.upcase!
+
+ upcased.should == "ASSET"
+ upcased.size.should == 5
+ upcased.bytesize.should == 5
+ upcased.ascii_only?.should == true
+ end
+ end
+
+ describe "modifies self in place for ASCII-only case mapping" do
+ it "does not upcase non-ASCII characters" do
+ a = "aßet"
+ a.upcase!(:ascii)
+ a.should == "AßET"
+ end
+
+ it "works for non-ascii-compatible encodings" do
+ a = "abc".encode("utf-16le")
+ a.upcase!(:ascii)
+ a.should == "ABC".encode("utf-16le")
+ end
+ end
+
+ describe "modifies self in place for full Unicode case mapping adapted for Turkic languages" do
+ it "upcases ASCII characters according to Turkic semantics" do
+ a = "i"
+ a.upcase!(:turkic)
+ a.should == "İ"
+ end
+
+ it "allows Lithuanian as an extra option" do
+ a = "i"
+ a.upcase!(:turkic, :lithuanian)
+ a.should == "İ"
+ end
+
+ it "does not allow any other additional option" do
+ -> { a = "i"; a.upcase!(:turkic, :ascii) }.should.raise(ArgumentError)
+ end
+ end
+
+ describe "modifies self in place for full Unicode case mapping adapted for Lithuanian" do
+ it "currently works the same as full Unicode case mapping" do
+ a = "iß"
+ a.upcase!(:lithuanian)
+ a.should == "ISS"
+ end
+
+ it "allows Turkic as an extra option (and applies Turkic semantics)" do
+ a = "iß"
+ a.upcase!(:lithuanian, :turkic)
+ a.should == "İSS"
+ end
+
+ it "does not allow any other additional option" do
+ -> { a = "iß"; a.upcase!(:lithuanian, :ascii) }.should.raise(ArgumentError)
+ end
+ end
+
+ it "does not allow the :fold option for upcasing" do
+ -> { a = "abc"; a.upcase!(:fold) }.should.raise(ArgumentError)
+ end
+
+ it "does not allow invalid options" do
+ -> { a = "abc"; a.upcase!(:invalid_option) }.should.raise(ArgumentError)
end
it "returns nil if no modifications were made" do
@@ -61,8 +180,8 @@ describe "String#upcase!" do
a.should == "HELLO"
end
- it "raises a RuntimeError when self is frozen" do
- lambda { "HeLlo".freeze.upcase! }.should raise_error(RuntimeError)
- lambda { "HELLO".freeze.upcase! }.should raise_error(RuntimeError)
+ it "raises a FrozenError when self is frozen" do
+ -> { "HeLlo".freeze.upcase! }.should.raise(FrozenError)
+ -> { "HELLO".freeze.upcase! }.should.raise(FrozenError)
end
end
diff --git a/spec/ruby/core/string/uplus_spec.rb b/spec/ruby/core/string/uplus_spec.rb
index eafa721903..20767bcc01 100644
--- a/spec/ruby/core/string/uplus_spec.rb
+++ b/spec/ruby/core/string/uplus_spec.rb
@@ -1,24 +1,60 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+# frozen_string_literal: false
+require_relative '../../spec_helper'
-ruby_version_is "2.3" do
- describe 'String#+@' do
- it 'returns an unfrozen copy of a frozen String' do
- input = 'foo'.freeze
- output = +input
+describe 'String#+@' do
+ it 'returns an unfrozen copy of a frozen String' do
+ input = 'foo'.freeze
+ output = +input
+
+ output.should_not.frozen?
+ output.should == 'foo'
+
+ output << 'bar'
+ output.should == 'foobar'
+ end
+
+ it 'returns a mutable String itself' do
+ input = String.new("foo")
+ output = +input
+
+ output.should.equal?(input)
+
+ input << "bar"
+ output.should == "foobar"
+ end
- output.frozen?.should == false
- output.should == 'foo'
+ context 'if file has "frozen_string_literal: true" magic comment' do
+ it 'returns mutable copy of a literal' do
+ ruby_exe(fixture(__FILE__, "freeze_magic_comment.rb")).should == 'mutable'
end
+ end
- it 'returns self if the String is not frozen' do
+ context 'if file has "frozen_string_literal: false" magic comment' do
+ it 'returns literal string itself' do
input = 'foo'
output = +input
output.equal?(input).should == true
end
+ end
- it 'returns mutable copy despite freeze-magic-comment in file' do
- ruby_exe(fixture(__FILE__, "freeze_magic_comment.rb")).should == 'mutable'
+ context 'if file has no frozen_string_literal magic comment' do
+ ruby_version_is ''...'3.4' do
+ it 'returns literal string itself' do
+ eval(<<~RUBY).should == true
+ s = "foo"
+ s.equal?(+s)
+ RUBY
+ end
+ end
+
+ ruby_version_is '3.4' do
+ it 'returns mutable copy of a literal' do
+ eval(<<~RUBY).should == false
+ s = "foo"
+ s.equal?(+s)
+ RUBY
+ end
end
end
end
diff --git a/spec/ruby/core/string/upto_spec.rb b/spec/ruby/core/string/upto_spec.rb
index 6b998eed3c..2eea06fd01 100644
--- a/spec/ruby/core/string/upto_spec.rb
+++ b/spec/ruby/core/string/upto_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes.rb', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "String#upto" do
it "passes successive values, starting at self and ending at other_string, to the block" do
@@ -8,7 +8,7 @@ describe "String#upto" do
a.should == ["*+", "*,", "*-", "*.", "*/", "*0", "*1", "*2", "*3"]
end
- it "calls the block once even when start eqals stop" do
+ it "calls the block once even when start equals stop" do
a = []
"abc".upto("abc") { |s| a << s }
a.should == ["abc"]
@@ -53,13 +53,13 @@ describe "String#upto" do
end
it "raises a TypeError if other can't be converted to a string" do
- lambda { "abc".upto(123) { } }.should raise_error(TypeError)
- lambda { "abc".upto(mock('x')){ } }.should raise_error(TypeError)
+ -> { "abc".upto(123) { } }.should.raise(TypeError)
+ -> { "abc".upto(mock('x')){ } }.should.raise(TypeError)
end
it "does not work with symbols" do
- lambda { "a".upto(:c).to_a }.should raise_error(TypeError)
+ -> { "a".upto(:c).to_a }.should.raise(TypeError)
end
it "returns non-alphabetic characters in the ASCII range for single letters" do
@@ -74,6 +74,18 @@ describe "String#upto" do
a.should == ["a", "b", "c"]
end
+ it "works with non-ASCII ranges" do
+ a = []
+ 'Σ'.upto('Ω') { |s| a << s }
+ a.should == ["Σ", "Τ", "Υ", "Φ", "Χ", "Ψ", "Ω"]
+ end
+
+ it "raises Encoding::CompatibilityError when incompatible characters are given" do
+ char1 = 'a'.dup.force_encoding("EUC-JP")
+ char2 = 'b'.dup.force_encoding("ISO-2022-JP")
+ -> { char1.upto(char2) {} }.should.raise(Encoding::CompatibilityError, "incompatible character encodings: EUC-JP and ISO-2022-JP")
+ end
+
describe "on sequence of numbers" do
it "calls the block as Integer#upto" do
"8".upto("11").to_a.should == 8.upto(11).map(&:to_s)
@@ -83,7 +95,7 @@ describe "String#upto" do
describe "when no block is given" do
it "returns an enumerator" do
enum = "aaa".upto("baa", true)
- enum.should be_an_instance_of(Enumerator)
+ enum.should.instance_of?(Enumerator)
enum.count.should == 26**2
end
diff --git a/spec/ruby/core/string/valid_encoding/utf_8_spec.rb b/spec/ruby/core/string/valid_encoding/utf_8_spec.rb
new file mode 100644
index 0000000000..a14c3af830
--- /dev/null
+++ b/spec/ruby/core/string/valid_encoding/utf_8_spec.rb
@@ -0,0 +1,214 @@
+# -*- encoding: utf-8 -*-
+require_relative '../../../spec_helper'
+
+describe "String#valid_encoding? and UTF-8" do
+ def utf8(bytes)
+ bytes.pack("C*").force_encoding("UTF-8")
+ end
+
+ describe "1-byte character" do
+ it "is valid if is in format 0xxxxxxx" do
+ utf8([0b00000000]).valid_encoding?.should == true
+ utf8([0b01111111]).valid_encoding?.should == true
+ end
+
+ it "is not valid if is not in format 0xxxxxxx" do
+ utf8([0b10000000]).valid_encoding?.should == false
+ utf8([0b11111111]).valid_encoding?.should == false
+ end
+ end
+
+ describe "2-bytes character" do
+ it "is valid if in format [110xxxxx 10xxxxx]" do
+ utf8([0b11000010, 0b10000000]).valid_encoding?.should == true
+ utf8([0b11000010, 0b10111111]).valid_encoding?.should == true
+
+ utf8([0b11011111, 0b10000000]).valid_encoding?.should == true
+ utf8([0b11011111, 0b10111111]).valid_encoding?.should == true
+ end
+
+ it "is not valid if the first byte is not in format 110xxxxx" do
+ utf8([0b00000010, 0b10000000]).valid_encoding?.should == false
+ utf8([0b00100010, 0b10000000]).valid_encoding?.should == false
+ utf8([0b01000010, 0b10000000]).valid_encoding?.should == false
+ utf8([0b01100010, 0b10000000]).valid_encoding?.should == false
+ utf8([0b10000010, 0b10000000]).valid_encoding?.should == false
+ utf8([0b10100010, 0b10000000]).valid_encoding?.should == false
+ utf8([0b11000010, 0b10000000]).valid_encoding?.should == true # correct bytes
+ utf8([0b11100010, 0b10000000]).valid_encoding?.should == false
+ end
+
+ it "is not valid if the second byte is not in format 10xxxxxx" do
+ utf8([0b11000010, 0b00000000]).valid_encoding?.should == false
+ utf8([0b11000010, 0b01000000]).valid_encoding?.should == false
+ utf8([0b11000010, 0b11000000]).valid_encoding?.should == false
+ end
+
+ it "is not valid if is smaller than [xxxxxx10 xx000000] (codepoints < U+007F, that are encoded with the 1-byte format)" do
+ utf8([0b11000000, 0b10111111]).valid_encoding?.should == false
+ utf8([0b11000001, 0b10111111]).valid_encoding?.should == false
+ end
+
+ it "is not valid if the first byte is missing" do
+ bytes = [0b11000010, 0b10000000]
+ utf8(bytes[1..1]).valid_encoding?.should == false
+ end
+
+ it "is not valid if the second byte is missing" do
+ bytes = [0b11000010, 0b10000000]
+ utf8(bytes[0..0]).valid_encoding?.should == false
+ end
+ end
+
+ describe "3-bytes character" do
+ it "is valid if in format [1110xxxx 10xxxxxx 10xxxxxx]" do
+ utf8([0b11100000, 0b10100000, 0b10000000]).valid_encoding?.should == true
+ utf8([0b11100000, 0b10100000, 0b10111111]).valid_encoding?.should == true
+ utf8([0b11100000, 0b10111111, 0b10111111]).valid_encoding?.should == true
+ utf8([0b11101111, 0b10111111, 0b10111111]).valid_encoding?.should == true
+ end
+
+ it "is not valid if the first byte is not in format 1110xxxx" do
+ utf8([0b00000000, 0b10100000, 0b10000000]).valid_encoding?.should == false
+ utf8([0b00010000, 0b10100000, 0b10000000]).valid_encoding?.should == false
+ utf8([0b00100000, 0b10100000, 0b10000000]).valid_encoding?.should == false
+ utf8([0b00110000, 0b10100000, 0b10000000]).valid_encoding?.should == false
+ utf8([0b01000000, 0b10100000, 0b10000000]).valid_encoding?.should == false
+ utf8([0b01010000, 0b10100000, 0b10000000]).valid_encoding?.should == false
+ utf8([0b01100000, 0b10100000, 0b10000000]).valid_encoding?.should == false
+ utf8([0b01110000, 0b10100000, 0b10000000]).valid_encoding?.should == false
+ utf8([0b10000000, 0b10100000, 0b10000000]).valid_encoding?.should == false
+ utf8([0b10010000, 0b10100000, 0b10000000]).valid_encoding?.should == false
+ utf8([0b10100000, 0b10100000, 0b10000000]).valid_encoding?.should == false
+ utf8([0b10110000, 0b10100000, 0b10000000]).valid_encoding?.should == false
+ utf8([0b11000000, 0b10100000, 0b10000000]).valid_encoding?.should == false
+ utf8([0b11010000, 0b10100000, 0b10000000]).valid_encoding?.should == false
+ utf8([0b11100000, 0b10100000, 0b10000000]).valid_encoding?.should == true # correct bytes
+ utf8([0b11110000, 0b10100000, 0b10000000]).valid_encoding?.should == false
+ end
+
+ it "is not valid if the second byte is not in format 10xxxxxx" do
+ utf8([0b11100000, 0b00100000, 0b10000000]).valid_encoding?.should == false
+ utf8([0b11100000, 0b01100000, 0b10000000]).valid_encoding?.should == false
+ utf8([0b11100000, 0b11100000, 0b10000000]).valid_encoding?.should == false
+ end
+
+ it "is not valid if the third byte is not in format 10xxxxxx" do
+ utf8([0b11100000, 0b10100000, 0b00000000]).valid_encoding?.should == false
+ utf8([0b11100000, 0b10100000, 0b01000000]).valid_encoding?.should == false
+ utf8([0b11100000, 0b10100000, 0b01000000]).valid_encoding?.should == false
+ end
+
+ it "is not valid if is smaller than [xxxx0000 xx100000 xx000000] (codepoints < U+07FF that are encoded with the 2-byte format)" do
+ utf8([0b11100000, 0b10010000, 0b10000000]).valid_encoding?.should == false
+ utf8([0b11100000, 0b10001000, 0b10000000]).valid_encoding?.should == false
+ utf8([0b11100000, 0b10000100, 0b10000000]).valid_encoding?.should == false
+ utf8([0b11100000, 0b10000010, 0b10000000]).valid_encoding?.should == false
+ utf8([0b11100000, 0b10000001, 0b10000000]).valid_encoding?.should == false
+ utf8([0b11100000, 0b10000000, 0b10000000]).valid_encoding?.should == false
+ end
+
+ it "is not valid if in range [xxxx1101 xx100000 xx000000] - [xxxx1101 xx111111 xx111111] (codepoints U+D800 - U+DFFF)" do
+ utf8([0b11101101, 0b10100000, 0b10000000]).valid_encoding?.should == false
+ utf8([0b11101101, 0b10100000, 0b10000001]).valid_encoding?.should == false
+ utf8([0b11101101, 0b10111111, 0b10111111]).valid_encoding?.should == false
+
+ utf8([0b11101101, 0b10011111, 0b10111111]).valid_encoding?.should == true # lower boundary - 1
+ utf8([0b11101110, 0b10000000, 0b10000000]).valid_encoding?.should == true # upper boundary + 1
+ end
+
+ it "is not valid if the first byte is missing" do
+ bytes = [0b11100000, 0b10100000, 0b10000000]
+ utf8(bytes[2..3]).valid_encoding?.should == false
+ end
+
+ it "is not valid if the second byte is missing" do
+ bytes = [0b11100000, 0b10100000, 0b10000000]
+ utf8([bytes[0], bytes[2]]).valid_encoding?.should == false
+ end
+
+ it "is not valid if the second and the third bytes are missing" do
+ bytes = [0b11100000, 0b10100000, 0b10000000]
+ utf8(bytes[0..0]).valid_encoding?.should == false
+ end
+ end
+
+ describe "4-bytes character" do
+ it "is valid if in format [11110xxx 10xxxxxx 10xxxxxx 10xxxxxx]" do
+ utf8([0b11110000, 0b10010000, 0b10000000, 0b10000000]).valid_encoding?.should == true
+ utf8([0b11110000, 0b10010000, 0b10000000, 0b10111111]).valid_encoding?.should == true
+ utf8([0b11110000, 0b10010000, 0b10111111, 0b10111111]).valid_encoding?.should == true
+ utf8([0b11110000, 0b10111111, 0b10111111, 0b10111111]).valid_encoding?.should == true
+ utf8([0b11110100, 0b10001111, 0b10111111, 0b10111111]).valid_encoding?.should == true
+ end
+
+ it "is not valid if the first byte is not in format 11110xxx" do
+ utf8([0b11100000, 0b10010000, 0b10000000, 0b10000000]).valid_encoding?.should == false
+ utf8([0b11010000, 0b10010000, 0b10000000, 0b10000000]).valid_encoding?.should == false
+ utf8([0b10110000, 0b10010000, 0b10000000, 0b10000000]).valid_encoding?.should == false
+ utf8([0b01110000, 0b10010000, 0b10000000, 0b10000000]).valid_encoding?.should == false
+ end
+
+ it "is not valid if the second byte is not in format 10xxxxxx" do
+ utf8([0b11110000, 0b00010000, 0b10000000, 0b10000000]).valid_encoding?.should == false
+ utf8([0b11110000, 0b01010000, 0b10000000, 0b10000000]).valid_encoding?.should == false
+ utf8([0b11110000, 0b10010000, 0b10000000, 0b10000000]).valid_encoding?.should == true # correct bytes
+ utf8([0b11110000, 0b11010000, 0b10000000, 0b10000000]).valid_encoding?.should == false
+ end
+
+ it "is not valid if the third byte is not in format 10xxxxxx" do
+ utf8([0b11110000, 0b10010000, 0b00000000, 0b10000000]).valid_encoding?.should == false
+ utf8([0b11110000, 0b10010000, 0b01000000, 0b10000000]).valid_encoding?.should == false
+ utf8([0b11110000, 0b10010000, 0b10000000, 0b10000000]).valid_encoding?.should == true # correct bytes
+ utf8([0b11110000, 0b10010000, 0b11000000, 0b10000000]).valid_encoding?.should == false
+ end
+
+ it "is not valid if the forth byte is not in format 10xxxxxx" do
+ utf8([0b11110000, 0b10010000, 0b10000000, 0b00000000]).valid_encoding?.should == false
+ utf8([0b11110000, 0b10010000, 0b10000000, 0b01000000]).valid_encoding?.should == false
+ utf8([0b11110000, 0b10010000, 0b10000000, 0b10000000]).valid_encoding?.should == true # correct bytes
+ utf8([0b11110000, 0b10010000, 0b10000000, 0b11000000]).valid_encoding?.should == false
+ end
+
+ it "is not valid if is smaller than [xxxxx000 xx001000 xx000000 xx000000] (codepoint < U+10000)" do
+ utf8([0b11110000, 0b10000111, 0b10000000, 0b10000000]).valid_encoding?.should == false
+ utf8([0b11110000, 0b10000110, 0b10000000, 0b10000000]).valid_encoding?.should == false
+ utf8([0b11110000, 0b10000101, 0b10000000, 0b10000000]).valid_encoding?.should == false
+ utf8([0b11110000, 0b10000100, 0b10000000, 0b10000000]).valid_encoding?.should == false
+ utf8([0b11110000, 0b10000011, 0b10000000, 0b10000000]).valid_encoding?.should == false
+ utf8([0b11110000, 0b10000010, 0b10000000, 0b10000000]).valid_encoding?.should == false
+ utf8([0b11110000, 0b10000001, 0b10000000, 0b10000000]).valid_encoding?.should == false
+ utf8([0b11110000, 0b10000000, 0b10000000, 0b10000000]).valid_encoding?.should == false
+ end
+
+ it "is not valid if is greater than [xxxxx100 xx001111 xx111111 xx111111] (codepoint > U+10FFFF)" do
+ utf8([0b11110100, 0b10010000, 0b10000000, 0b10000000]).valid_encoding?.should == false
+ utf8([0b11110100, 0b10100000, 0b10000000, 0b10000000]).valid_encoding?.should == false
+ utf8([0b11110100, 0b10110000, 0b10000000, 0b10000000]).valid_encoding?.should == false
+
+ utf8([0b11110101, 0b10001111, 0b10111111, 0b10111111]).valid_encoding?.should == false
+ utf8([0b11110110, 0b10001111, 0b10111111, 0b10111111]).valid_encoding?.should == false
+ utf8([0b11110111, 0b10001111, 0b10111111, 0b10111111]).valid_encoding?.should == false
+ end
+
+ it "is not valid if the first byte is missing" do
+ bytes = [0b11110000, 0b10010000, 0b10000000, 0b10000000]
+ utf8(bytes[1..3]).valid_encoding?.should == false
+ end
+
+ it "is not valid if the second byte is missing" do
+ bytes = [0b11110000, 0b10010000, 0b10000000, 0b10000000]
+ utf8([bytes[0], bytes[2], bytes[3]]).valid_encoding?.should == false
+ end
+
+ it "is not valid if the second and the third bytes are missing" do
+ bytes = [0b11110000, 0b10010000, 0b10000000, 0b10000000]
+ utf8([bytes[0], bytes[3]]).valid_encoding?.should == false
+ end
+
+ it "is not valid if the second, the third and the fourth bytes are missing" do
+ bytes = [0b11110000, 0b10010000, 0b10000000, 0b10000000]
+ utf8(bytes[0..0]).valid_encoding?.should == false
+ end
+ end
+end
diff --git a/spec/ruby/core/string/valid_encoding_spec.rb b/spec/ruby/core/string/valid_encoding_spec.rb
index ddd0fe52a2..f29220fc99 100644
--- a/spec/ruby/core/string/valid_encoding_spec.rb
+++ b/spec/ruby/core/string/valid_encoding_spec.rb
@@ -1,129 +1,133 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
-with_feature :encoding do
- describe "String#valid_encoding?" do
- it "returns true if the String's encoding is valid" do
- "a".valid_encoding?.should be_true
- "\u{8365}\u{221}".valid_encoding?.should be_true
- end
+describe "String#valid_encoding?" do
+ it "returns true if the String's encoding is valid" do
+ "a".valid_encoding?.should == true
+ "\u{8365}\u{221}".valid_encoding?.should == true
+ end
+
+ it "returns true if self is valid in the current encoding and other encodings" do
+ str = +"\x77"
+ str.force_encoding('utf-8').valid_encoding?.should == true
+ str.force_encoding('binary').valid_encoding?.should == true
+ end
- it "returns true if self is valid in the current encoding and other encodings" do
- str = "\x77"
- str.force_encoding('utf-8').valid_encoding?.should be_true
- str.force_encoding('ascii-8bit').valid_encoding?.should be_true
- end
+ it "returns true for all encodings self is valid in" do
+ str = +"\xE6\x9D\x94"
+ str.force_encoding('BINARY').valid_encoding?.should == true
+ str.force_encoding('UTF-8').valid_encoding?.should == true
+ str.force_encoding('US-ASCII').valid_encoding?.should == false
+ str.force_encoding('Big5').valid_encoding?.should == false
+ str.force_encoding('CP949').valid_encoding?.should == false
+ str.force_encoding('Emacs-Mule').valid_encoding?.should == false
+ str.force_encoding('EUC-JP').valid_encoding?.should == false
+ str.force_encoding('EUC-KR').valid_encoding?.should == false
+ str.force_encoding('EUC-TW').valid_encoding?.should == false
+ str.force_encoding('GB18030').valid_encoding?.should == false
+ str.force_encoding('GBK').valid_encoding?.should == false
+ str.force_encoding('ISO-8859-1').valid_encoding?.should == true
+ str.force_encoding('ISO-8859-2').valid_encoding?.should == true
+ str.force_encoding('ISO-8859-3').valid_encoding?.should == true
+ str.force_encoding('ISO-8859-4').valid_encoding?.should == true
+ str.force_encoding('ISO-8859-5').valid_encoding?.should == true
+ str.force_encoding('ISO-8859-6').valid_encoding?.should == true
+ str.force_encoding('ISO-8859-7').valid_encoding?.should == true
+ str.force_encoding('ISO-8859-8').valid_encoding?.should == true
+ str.force_encoding('ISO-8859-9').valid_encoding?.should == true
+ str.force_encoding('ISO-8859-10').valid_encoding?.should == true
+ str.force_encoding('ISO-8859-11').valid_encoding?.should == true
+ str.force_encoding('ISO-8859-13').valid_encoding?.should == true
+ str.force_encoding('ISO-8859-14').valid_encoding?.should == true
+ str.force_encoding('ISO-8859-15').valid_encoding?.should == true
+ str.force_encoding('ISO-8859-16').valid_encoding?.should == true
+ str.force_encoding('KOI8-R').valid_encoding?.should == true
+ str.force_encoding('KOI8-U').valid_encoding?.should == true
+ str.force_encoding('Shift_JIS').valid_encoding?.should == false
+ "\xD8\x00".dup.force_encoding('UTF-16BE').valid_encoding?.should == false
+ "\x00\xD8".dup.force_encoding('UTF-16LE').valid_encoding?.should == false
+ "\x04\x03\x02\x01".dup.force_encoding('UTF-32BE').valid_encoding?.should == false
+ "\x01\x02\x03\x04".dup.force_encoding('UTF-32LE').valid_encoding?.should == false
+ str.force_encoding('Windows-1251').valid_encoding?.should == true
+ str.force_encoding('IBM437').valid_encoding?.should == true
+ str.force_encoding('IBM737').valid_encoding?.should == true
+ str.force_encoding('IBM775').valid_encoding?.should == true
+ str.force_encoding('CP850').valid_encoding?.should == true
+ str.force_encoding('IBM852').valid_encoding?.should == true
+ str.force_encoding('CP852').valid_encoding?.should == true
+ str.force_encoding('IBM855').valid_encoding?.should == true
+ str.force_encoding('CP855').valid_encoding?.should == true
+ str.force_encoding('IBM857').valid_encoding?.should == true
+ str.force_encoding('IBM860').valid_encoding?.should == true
+ str.force_encoding('IBM861').valid_encoding?.should == true
+ str.force_encoding('IBM862').valid_encoding?.should == true
+ str.force_encoding('IBM863').valid_encoding?.should == true
+ str.force_encoding('IBM864').valid_encoding?.should == true
+ str.force_encoding('IBM865').valid_encoding?.should == true
+ str.force_encoding('IBM866').valid_encoding?.should == true
+ str.force_encoding('IBM869').valid_encoding?.should == true
+ str.force_encoding('Windows-1258').valid_encoding?.should == true
+ str.force_encoding('GB1988').valid_encoding?.should == true
+ str.force_encoding('macCentEuro').valid_encoding?.should == true
+ str.force_encoding('macCroatian').valid_encoding?.should == true
+ str.force_encoding('macCyrillic').valid_encoding?.should == true
+ str.force_encoding('macGreek').valid_encoding?.should == true
+ str.force_encoding('macIceland').valid_encoding?.should == true
+ str.force_encoding('macRoman').valid_encoding?.should == true
+ str.force_encoding('macRomania').valid_encoding?.should == true
+ str.force_encoding('macThai').valid_encoding?.should == true
+ str.force_encoding('macTurkish').valid_encoding?.should == true
+ str.force_encoding('macUkraine').valid_encoding?.should == true
+ str.force_encoding('stateless-ISO-2022-JP').valid_encoding?.should == false
+ str.force_encoding('eucJP-ms').valid_encoding?.should == false
+ str.force_encoding('CP51932').valid_encoding?.should == false
+ str.force_encoding('GB2312').valid_encoding?.should == false
+ str.force_encoding('GB12345').valid_encoding?.should == false
+ str.force_encoding('ISO-2022-JP').valid_encoding?.should == true
+ str.force_encoding('ISO-2022-JP-2').valid_encoding?.should == true
+ str.force_encoding('CP50221').valid_encoding?.should == true
+ str.force_encoding('Windows-1252').valid_encoding?.should == true
+ str.force_encoding('Windows-1250').valid_encoding?.should == true
+ str.force_encoding('Windows-1256').valid_encoding?.should == true
+ str.force_encoding('Windows-1253').valid_encoding?.should == true
+ str.force_encoding('Windows-1255').valid_encoding?.should == true
+ str.force_encoding('Windows-1254').valid_encoding?.should == true
+ str.force_encoding('TIS-620').valid_encoding?.should == true
+ str.force_encoding('Windows-874').valid_encoding?.should == true
+ str.force_encoding('Windows-1257').valid_encoding?.should == true
+ str.force_encoding('Windows-31J').valid_encoding?.should == false
+ str.force_encoding('MacJapanese').valid_encoding?.should == false
+ str.force_encoding('UTF-7').valid_encoding?.should == true
+ str.force_encoding('UTF8-MAC').valid_encoding?.should == true
+ end
- it "returns true for all encodings self is valid in" do
- str = "\u{6754}"
- str.force_encoding('ASCII-8BIT').valid_encoding?.should be_true
- str.force_encoding('UTF-8').valid_encoding?.should be_true
- str.force_encoding('US-ASCII').valid_encoding?.should be_false
- str.force_encoding('Big5').valid_encoding?.should be_false
- str.force_encoding('CP949').valid_encoding?.should be_false
- str.force_encoding('Emacs-Mule').valid_encoding?.should be_false
- str.force_encoding('EUC-JP').valid_encoding?.should be_false
- str.force_encoding('EUC-KR').valid_encoding?.should be_false
- str.force_encoding('EUC-TW').valid_encoding?.should be_false
- str.force_encoding('GB18030').valid_encoding?.should be_false
- str.force_encoding('GBK').valid_encoding?.should be_false
- str.force_encoding('ISO-8859-1').valid_encoding?.should be_true
- str.force_encoding('ISO-8859-2').valid_encoding?.should be_true
- str.force_encoding('ISO-8859-3').valid_encoding?.should be_true
- str.force_encoding('ISO-8859-4').valid_encoding?.should be_true
- str.force_encoding('ISO-8859-5').valid_encoding?.should be_true
- str.force_encoding('ISO-8859-6').valid_encoding?.should be_true
- str.force_encoding('ISO-8859-7').valid_encoding?.should be_true
- str.force_encoding('ISO-8859-8').valid_encoding?.should be_true
- str.force_encoding('ISO-8859-9').valid_encoding?.should be_true
- str.force_encoding('ISO-8859-10').valid_encoding?.should be_true
- str.force_encoding('ISO-8859-11').valid_encoding?.should be_true
- str.force_encoding('ISO-8859-13').valid_encoding?.should be_true
- str.force_encoding('ISO-8859-14').valid_encoding?.should be_true
- str.force_encoding('ISO-8859-15').valid_encoding?.should be_true
- str.force_encoding('ISO-8859-16').valid_encoding?.should be_true
- str.force_encoding('KOI8-R').valid_encoding?.should be_true
- str.force_encoding('KOI8-U').valid_encoding?.should be_true
- str.force_encoding('Shift_JIS').valid_encoding?.should be_false
- str.force_encoding('UTF-16BE').valid_encoding?.should be_false
- str.force_encoding('UTF-16LE').valid_encoding?.should be_false
- str.force_encoding('UTF-32BE').valid_encoding?.should be_false
- str.force_encoding('UTF-32LE').valid_encoding?.should be_false
- str.force_encoding('Windows-1251').valid_encoding?.should be_true
- str.force_encoding('IBM437').valid_encoding?.should be_true
- str.force_encoding('IBM737').valid_encoding?.should be_true
- str.force_encoding('IBM775').valid_encoding?.should be_true
- str.force_encoding('CP850').valid_encoding?.should be_true
- str.force_encoding('IBM852').valid_encoding?.should be_true
- str.force_encoding('CP852').valid_encoding?.should be_true
- str.force_encoding('IBM855').valid_encoding?.should be_true
- str.force_encoding('CP855').valid_encoding?.should be_true
- str.force_encoding('IBM857').valid_encoding?.should be_true
- str.force_encoding('IBM860').valid_encoding?.should be_true
- str.force_encoding('IBM861').valid_encoding?.should be_true
- str.force_encoding('IBM862').valid_encoding?.should be_true
- str.force_encoding('IBM863').valid_encoding?.should be_true
- str.force_encoding('IBM864').valid_encoding?.should be_true
- str.force_encoding('IBM865').valid_encoding?.should be_true
- str.force_encoding('IBM866').valid_encoding?.should be_true
- str.force_encoding('IBM869').valid_encoding?.should be_true
- str.force_encoding('Windows-1258').valid_encoding?.should be_true
- str.force_encoding('GB1988').valid_encoding?.should be_true
- str.force_encoding('macCentEuro').valid_encoding?.should be_true
- str.force_encoding('macCroatian').valid_encoding?.should be_true
- str.force_encoding('macCyrillic').valid_encoding?.should be_true
- str.force_encoding('macGreek').valid_encoding?.should be_true
- str.force_encoding('macIceland').valid_encoding?.should be_true
- str.force_encoding('macRoman').valid_encoding?.should be_true
- str.force_encoding('macRomania').valid_encoding?.should be_true
- str.force_encoding('macThai').valid_encoding?.should be_true
- str.force_encoding('macTurkish').valid_encoding?.should be_true
- str.force_encoding('macUkraine').valid_encoding?.should be_true
- str.force_encoding('stateless-ISO-2022-JP').valid_encoding?.should be_false
- str.force_encoding('eucJP-ms').valid_encoding?.should be_false
- str.force_encoding('CP51932').valid_encoding?.should be_false
- str.force_encoding('GB2312').valid_encoding?.should be_false
- str.force_encoding('GB12345').valid_encoding?.should be_false
- str.force_encoding('ISO-2022-JP').valid_encoding?.should be_true
- str.force_encoding('ISO-2022-JP-2').valid_encoding?.should be_true
- str.force_encoding('CP50221').valid_encoding?.should be_true
- str.force_encoding('Windows-1252').valid_encoding?.should be_true
- str.force_encoding('Windows-1250').valid_encoding?.should be_true
- str.force_encoding('Windows-1256').valid_encoding?.should be_true
- str.force_encoding('Windows-1253').valid_encoding?.should be_true
- str.force_encoding('Windows-1255').valid_encoding?.should be_true
- str.force_encoding('Windows-1254').valid_encoding?.should be_true
- str.force_encoding('TIS-620').valid_encoding?.should be_true
- str.force_encoding('Windows-874').valid_encoding?.should be_true
- str.force_encoding('Windows-1257').valid_encoding?.should be_true
- str.force_encoding('Windows-31J').valid_encoding?.should be_false
- str.force_encoding('MacJapanese').valid_encoding?.should be_false
- str.force_encoding('UTF-7').valid_encoding?.should be_true
- str.force_encoding('UTF8-MAC').valid_encoding?.should be_true
- end
+ it "returns true for IBM720 encoding self is valid in" do
+ str = +"\xE6\x9D\x94"
+ str.force_encoding('IBM720').valid_encoding?.should == true
+ str.force_encoding('CP720').valid_encoding?.should == true
+ end
- it "returns false if self is valid in one encoding, but invalid in the one it's tagged with" do
- str = "\u{8765}"
- str.valid_encoding?.should be_true
- str = str.force_encoding('ascii')
- str.valid_encoding?.should be_false
- end
+ it "returns false if self is valid in one encoding, but invalid in the one it's tagged with" do
+ str = +"\u{8765}"
+ str.valid_encoding?.should == true
+ str.force_encoding('ascii')
+ str.valid_encoding?.should == false
+ end
- it "returns false if self contains a character invalid in the associated encoding" do
- "abc#{[0x80].pack('C')}".force_encoding('ascii').valid_encoding?.should be_false
- end
+ it "returns false if self contains a character invalid in the associated encoding" do
+ "abc#{[0x80].pack('C')}".dup.force_encoding('ascii').valid_encoding?.should == false
+ end
- it "returns false if a valid String had an invalid character appended to it" do
- str = "a"
- str.valid_encoding?.should be_true
- str << [0xDD].pack('C').force_encoding('utf-8')
- str.valid_encoding?.should be_false
- end
+ it "returns false if a valid String had an invalid character appended to it" do
+ str = +"a"
+ str.valid_encoding?.should == true
+ str << [0xDD].pack('C').force_encoding('utf-8')
+ str.valid_encoding?.should == false
+ end
- it "returns true if an invalid string is appended another invalid one but both make a valid string" do
- str = [0xD0].pack('C').force_encoding('utf-8')
- str.valid_encoding?.should be_false
- str << [0xBF].pack('C').force_encoding('utf-8')
- str.valid_encoding?.should be_true
- end
+ it "returns true if an invalid string is appended another invalid one but both make a valid string" do
+ str = [0xD0].pack('C').force_encoding('utf-8')
+ str.valid_encoding?.should == false
+ str << [0xBF].pack('C').force_encoding('utf-8')
+ str.valid_encoding?.should == true
end
end
diff --git a/spec/ruby/core/struct/clone_spec.rb b/spec/ruby/core/struct/clone_spec.rb
new file mode 100644
index 0000000000..40c4d52d57
--- /dev/null
+++ b/spec/ruby/core/struct/clone_spec.rb
@@ -0,0 +1,7 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/dup'
+
+describe "Struct-based class#clone" do
+ it_behaves_like :struct_dup, :clone
+end
diff --git a/spec/ruby/core/struct/constants_spec.rb b/spec/ruby/core/struct/constants_spec.rb
new file mode 100644
index 0000000000..7e8af1a211
--- /dev/null
+++ b/spec/ruby/core/struct/constants_spec.rb
@@ -0,0 +1,13 @@
+require_relative '../../spec_helper'
+
+describe "Struct::Group" do
+ it "is no longer defined" do
+ Struct.should_not.const_defined?(:Group)
+ end
+end
+
+describe "Struct::Passwd" do
+ it "is no longer defined" do
+ Struct.should_not.const_defined?(:Passwd)
+ end
+end
diff --git a/spec/ruby/core/struct/deconstruct_keys_spec.rb b/spec/ruby/core/struct/deconstruct_keys_spec.rb
new file mode 100644
index 0000000000..590e1ab40b
--- /dev/null
+++ b/spec/ruby/core/struct/deconstruct_keys_spec.rb
@@ -0,0 +1,130 @@
+require_relative '../../spec_helper'
+
+describe "Struct#deconstruct_keys" do
+ it "returns a hash of attributes" do
+ struct = Struct.new(:x, :y)
+ s = struct.new(1, 2)
+
+ s.deconstruct_keys([:x, :y]).should == {x: 1, y: 2}
+ end
+
+ it "requires one argument" do
+ struct = Struct.new(:x)
+ obj = struct.new(1)
+
+ -> {
+ obj.deconstruct_keys
+ }.should.raise(ArgumentError, /wrong number of arguments \(given 0, expected 1\)/)
+ end
+
+ it "returns only specified keys" do
+ struct = Struct.new(:x, :y, :z)
+ s = struct.new(1, 2, 3)
+
+ s.deconstruct_keys([:x, :y]).should == {x: 1, y: 2}
+ s.deconstruct_keys([:x] ).should == {x: 1}
+ s.deconstruct_keys([] ).should == {}
+ end
+
+ it "accepts string attribute names" do
+ struct = Struct.new(:x, :y)
+ s = struct.new(1, 2)
+
+ s.deconstruct_keys(['x', 'y']).should == {'x' => 1, 'y' => 2}
+ end
+
+ it "accepts argument position number as well but returns them as keys" do
+ struct = Struct.new(:x, :y, :z)
+ s = struct.new(10, 20, 30)
+
+ s.deconstruct_keys([0, 1, 2]).should == {0 => 10, 1 => 20, 2 => 30}
+ s.deconstruct_keys([0, 1] ).should == {0 => 10, 1 => 20}
+ s.deconstruct_keys([0] ).should == {0 => 10}
+ s.deconstruct_keys([-1] ).should == {-1 => 30}
+ end
+
+ it "ignores incorrect position numbers" do
+ struct = Struct.new(:x, :y, :z)
+ s = struct.new(10, 20, 30)
+
+ s.deconstruct_keys([0, 3]).should == {0 => 10}
+ end
+
+ it "support mixing attribute names and argument position numbers" do
+ struct = Struct.new(:x, :y)
+ s = struct.new(1, 2)
+
+ s.deconstruct_keys([0, :x]).should == {0 => 1, :x => 1}
+ end
+
+ it "returns an empty hash when there are more keys than attributes" do
+ struct = Struct.new(:x, :y)
+ s = struct.new(1, 2)
+
+ s.deconstruct_keys([:x, :y, :a]).should == {}
+ end
+
+ it "returns at first not existing attribute name" do
+ struct = Struct.new(:x, :y)
+ s = struct.new(1, 2)
+
+ s.deconstruct_keys([:a, :x]).should == {}
+ s.deconstruct_keys([:x, :a]).should == {x: 1}
+ end
+
+ it "returns at first not existing argument position number" do
+ struct = Struct.new(:x, :y)
+ s = struct.new(1, 2)
+
+ s.deconstruct_keys([3, 0]).should == {}
+ s.deconstruct_keys([0, 3]).should == {0 => 1}
+ end
+
+ it "accepts nil argument and return all the attributes" do
+ struct = Struct.new(:x, :y)
+ obj = struct.new(1, 2)
+
+ obj.deconstruct_keys(nil).should == {x: 1, y: 2}
+ end
+
+ it "tries to convert a key with #to_int if index is not a String nor a Symbol, but responds to #to_int" do
+ struct = Struct.new(:x, :y)
+ s = struct.new(1, 2)
+
+ key = mock("to_int")
+ key.should_receive(:to_int).and_return(1)
+
+ s.deconstruct_keys([key]).should == { key => 2 }
+ end
+
+ it "raises a TypeError if the conversion with #to_int does not return an Integer" do
+ struct = Struct.new(:x, :y)
+ s = struct.new(1, 2)
+
+ key = mock("to_int")
+ key.should_receive(:to_int).and_return("not an Integer")
+
+ -> {
+ s.deconstruct_keys([key])
+ }.should raise_consistent_error(TypeError, /can't convert MockObject into Integer/)
+ end
+
+ it "raises TypeError if index is not a String, a Symbol and not convertible to Integer" do
+ struct = Struct.new(:x, :y)
+ s = struct.new(1, 2)
+
+ -> {
+ s.deconstruct_keys([0, []])
+ }.should.raise(TypeError, "no implicit conversion of Array into Integer")
+ end
+
+ it "raise TypeError if passed anything except nil or array" do
+ struct = Struct.new(:x, :y)
+ s = struct.new(1, 2)
+
+ -> { s.deconstruct_keys('x') }.should.raise(TypeError, /expected Array or nil/)
+ -> { s.deconstruct_keys(1) }.should.raise(TypeError, /expected Array or nil/)
+ -> { s.deconstruct_keys(:x) }.should.raise(TypeError, /expected Array or nil/)
+ -> { s.deconstruct_keys({}) }.should.raise(TypeError, /expected Array or nil/)
+ end
+end
diff --git a/spec/ruby/core/struct/deconstruct_spec.rb b/spec/ruby/core/struct/deconstruct_spec.rb
new file mode 100644
index 0000000000..aad82ac2ba
--- /dev/null
+++ b/spec/ruby/core/struct/deconstruct_spec.rb
@@ -0,0 +1,7 @@
+require_relative '../../spec_helper'
+
+describe "Struct#deconstruct" do
+ it "is an alias of Struct#to_a" do
+ Struct.instance_method(:deconstruct).should == Struct.instance_method(:to_a)
+ end
+end
diff --git a/spec/ruby/core/struct/dig_spec.rb b/spec/ruby/core/struct/dig_spec.rb
index c222eec9e4..52e4d1dd9a 100644
--- a/spec/ruby/core/struct/dig_spec.rb
+++ b/spec/ruby/core/struct/dig_spec.rb
@@ -1,44 +1,52 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
-ruby_version_is "2.3" do
- describe "Struct#dig" do
- before(:each) do
- @klass = Struct.new(:a)
- @instance = @klass.new(@klass.new({ b: [1, 2, 3] }))
- end
+describe "Struct#dig" do
+ before(:each) do
+ @klass = Struct.new(:a)
+ @instance = @klass.new(@klass.new({ b: [1, 2, 3] }))
+ end
- it "returns the nested value specified by the sequence of keys" do
- @instance.dig(:a, :a).should == { b: [1, 2, 3] }
- end
+ it "returns the nested value specified by the sequence of keys" do
+ @instance.dig(:a, :a).should == { b: [1, 2, 3] }
+ end
- it "returns the nested value specified if the sequence includes an index" do
- @instance.dig(:a, :a, :b, 0).should == 1
- end
+ it "accepts String keys" do
+ @instance.dig('a', 'a').should == { b: [1, 2, 3] }
+ end
- it "returns nil if any intermediate step is nil" do
- @instance.dig(:b, 0).should == nil
- end
+ it "returns the value by the index" do
+ instance = Struct.new(:a, :b).new(:one, :two)
+ instance.dig(0).should == :one
+ instance.dig(1).should == :two
+ end
- it "raises a TypeError if any intermediate step does not respond to #dig" do
- instance = @klass.new(1)
- lambda {
- instance.dig(:a, 3)
- }.should raise_error(TypeError)
- end
+ it "returns the nested value specified if the sequence includes an index" do
+ @instance.dig(:a, :a, :b, 0).should == 1
+ end
- it "raises an ArgumentError if no arguments provided" do
- lambda { @instance.dig }.should raise_error(ArgumentError)
- end
+ it "returns nil if any intermediate step is nil" do
+ @instance.dig(:b, 0).should == nil
+ end
- it "calls #dig on any intermediate step with the rest of the sequence as arguments" do
- obj = Object.new
- instance = @klass.new(obj)
+ it "raises a TypeError if any intermediate step does not respond to #dig" do
+ instance = @klass.new(1)
+ -> {
+ instance.dig(:a, 3)
+ }.should.raise(TypeError)
+ end
+
+ it "raises an ArgumentError if no arguments provided" do
+ -> { @instance.dig }.should.raise(ArgumentError)
+ end
- def obj.dig(*args)
- {dug: args}
- end
+ it "calls #dig on any intermediate step with the rest of the sequence as arguments" do
+ obj = Object.new
+ instance = @klass.new(obj)
- instance.dig(:a, :bar, :baz).should == { dug: [:bar, :baz] }
+ def obj.dig(*args)
+ {dug: args}
end
+
+ instance.dig(:a, :bar, :baz).should == { dug: [:bar, :baz] }
end
end
diff --git a/spec/ruby/core/struct/dup_spec.rb b/spec/ruby/core/struct/dup_spec.rb
index d1da31d6d5..8b50c39014 100644
--- a/spec/ruby/core/struct/dup_spec.rb
+++ b/spec/ruby/core/struct/dup_spec.rb
@@ -1,8 +1,11 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/dup'
describe "Struct-based class#dup" do
+ it_behaves_like :struct_dup, :dup
+
# From https://github.com/jruby/jruby/issues/3686
it "retains an included module in the ancestor chain for the struct's singleton class" do
klass = Struct.new(:foo)
diff --git a/spec/ruby/core/struct/each_pair_spec.rb b/spec/ruby/core/struct/each_pair_spec.rb
index 79a962a6ad..db146c81e9 100644
--- a/spec/ruby/core/struct/each_pair_spec.rb
+++ b/spec/ruby/core/struct/each_pair_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/accessor', __FILE__)
-require File.expand_path('../../enumerable/shared/enumeratorized', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/accessor'
+require_relative '../enumerable/shared/enumeratorized'
describe "Struct#each_pair" do
before :each do
@@ -21,11 +21,11 @@ describe "Struct#each_pair" do
end
it "returns self if passed a block" do
- @car.each_pair {}.should equal(@car)
+ @car.each_pair {}.should.equal?(@car)
end
it "returns an Enumerator if not passed a block" do
- @car.each_pair.should be_an_instance_of(Enumerator)
+ @car.each_pair.should.instance_of?(Enumerator)
end
it_behaves_like :struct_accessor, :each_pair
diff --git a/spec/ruby/core/struct/each_spec.rb b/spec/ruby/core/struct/each_spec.rb
index 86302d91c6..4fbdfee02a 100644
--- a/spec/ruby/core/struct/each_spec.rb
+++ b/spec/ruby/core/struct/each_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/accessor', __FILE__)
-require File.expand_path('../../enumerable/shared/enumeratorized', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/accessor'
+require_relative '../enumerable/shared/enumeratorized'
describe "Struct#each" do
it "passes each value to the given block" do
@@ -19,7 +19,7 @@ describe "Struct#each" do
it "returns an Enumerator if not passed a block" do
car = StructClasses::Car.new('Ford', 'Ranger')
- car.each.should be_an_instance_of(Enumerator)
+ car.each.should.instance_of?(Enumerator)
end
it_behaves_like :struct_accessor, :each
diff --git a/spec/ruby/core/struct/element_reference_spec.rb b/spec/ruby/core/struct/element_reference_spec.rb
index dc51fbfff1..b94f3aae8c 100644
--- a/spec/ruby/core/struct/element_reference_spec.rb
+++ b/spec/ruby/core/struct/element_reference_spec.rb
@@ -1,9 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Struct[]" do
it "is a synonym for new" do
- StructClasses::Ruby['2.0', 'i686'].should be_kind_of(StructClasses::Ruby)
+ StructClasses::Ruby['2.0', 'i686'].should.is_a?(StructClasses::Ruby)
end
end
@@ -26,20 +26,20 @@ describe "Struct#[]" do
it "fails when it does not know about the requested attribute" do
car = StructClasses::Car.new('Ford', 'Ranger')
- lambda { car[3] }.should raise_error(IndexError)
- lambda { car[-4] }.should raise_error(IndexError)
- lambda { car[:body] }.should raise_error(NameError)
- lambda { car['wheels'] }.should raise_error(NameError)
+ -> { car[3] }.should.raise(IndexError)
+ -> { car[-4] }.should.raise(IndexError)
+ -> { car[:body] }.should.raise(NameError)
+ -> { car['wheels'] }.should.raise(NameError)
end
it "fails if passed too many arguments" do
car = StructClasses::Car.new('Ford', 'Ranger')
- lambda { car[:make, :model] }.should raise_error(ArgumentError)
+ -> { car[:make, :model] }.should.raise(ArgumentError)
end
it "fails if not passed a string, symbol, or integer" do
car = StructClasses::Car.new('Ford', 'Ranger')
- lambda { car[Object.new] }.should raise_error(TypeError)
+ -> { car[Object.new] }.should.raise(TypeError)
end
it "returns attribute names that contain hyphens" do
diff --git a/spec/ruby/core/struct/element_set_spec.rb b/spec/ruby/core/struct/element_set_spec.rb
index 3d482bdb71..e5438ca09a 100644
--- a/spec/ruby/core/struct/element_set_spec.rb
+++ b/spec/ruby/core/struct/element_set_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Struct#[]=" do
it "assigns the passed value" do
@@ -21,9 +21,16 @@ describe "Struct#[]=" do
it "fails when trying to assign attributes which don't exist" do
car = StructClasses::Car.new('Ford', 'Ranger')
- lambda { car[:something] = true }.should raise_error(NameError)
- lambda { car[3] = true }.should raise_error(IndexError)
- lambda { car[-4] = true }.should raise_error(IndexError)
- lambda { car[Object.new] = true }.should raise_error(TypeError)
+ -> { car[:something] = true }.should.raise(NameError)
+ -> { car[3] = true }.should.raise(IndexError)
+ -> { car[-4] = true }.should.raise(IndexError)
+ -> { car[Object.new] = true }.should.raise(TypeError)
+ end
+
+ it "raises a FrozenError on a frozen struct" do
+ car = StructClasses::Car.new('Ford', 'Ranger')
+ car.freeze
+
+ -> { car[:model] = 'Escape' }.should.raise(FrozenError)
end
end
diff --git a/spec/ruby/core/struct/eql_spec.rb b/spec/ruby/core/struct/eql_spec.rb
index dfa97811c6..327c927278 100644
--- a/spec/ruby/core/struct/eql_spec.rb
+++ b/spec/ruby/core/struct/eql_spec.rb
@@ -1,13 +1,13 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/equal_value', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/equal_value'
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)
similar_car = StructClasses::Car.new("Honda", "Accord", 1998.0)
- car.send(@method, similar_car).should be_false
+ car.should_not.eql?(similar_car)
end
end
diff --git a/spec/ruby/core/struct/equal_value_spec.rb b/spec/ruby/core/struct/equal_value_spec.rb
index a343213417..0c0f7ba570 100644
--- a/spec/ruby/core/struct/equal_value_spec.rb
+++ b/spec/ruby/core/struct/equal_value_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/equal_value', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/equal_value'
describe "Struct#==" do
- it_behaves_like(:struct_equal_value, :==)
+ it_behaves_like :struct_equal_value, :==
end
diff --git a/spec/ruby/core/struct/filter_spec.rb b/spec/ruby/core/struct/filter_spec.rb
new file mode 100644
index 0000000000..5d11f47e6b
--- /dev/null
+++ b/spec/ruby/core/struct/filter_spec.rb
@@ -0,0 +1,8 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe "Struct#filter" do
+ it "is an alias of Struct#select" do
+ StructClasses::Car.instance_method(:filter).should == StructClasses::Car.instance_method(:select)
+ end
+end
diff --git a/spec/ruby/core/struct/fixtures/classes.rb b/spec/ruby/core/struct/fixtures/classes.rb
index 6d620f9060..675d403abd 100644
--- a/spec/ruby/core/struct/fixtures/classes.rb
+++ b/spec/ruby/core/struct/fixtures/classes.rb
@@ -3,6 +3,7 @@ module StructClasses
class Apple < Struct; end
Ruby = Struct.new(:version, :platform)
+ Single = Struct.new(:value)
Car = Struct.new(:make, :model, :year)
@@ -13,6 +14,12 @@ module StructClasses
end
end
+ class StructWithOverriddenName < Struct.new(:a)
+ def self.name
+ "A"
+ end
+ end
+
class SubclassX < Struct
end
@@ -23,4 +30,6 @@ module StructClasses
super
end
end
+
+ class StructSubclass < Struct; end
end
diff --git a/spec/ruby/core/struct/hash_spec.rb b/spec/ruby/core/struct/hash_spec.rb
index 517d3ab44e..750387b326 100644
--- a/spec/ruby/core/struct/hash_spec.rb
+++ b/spec/ruby/core/struct/hash_spec.rb
@@ -1,24 +1,38 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/accessor', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/accessor'
describe "Struct#hash" do
- it "returns the same fixnum for structs with the same content" do
+ it "returns the same integer for structs with the same content" do
[StructClasses::Ruby.new("1.8.6", "PPC"),
StructClasses::Car.new("Hugo", "Foo", "1972")].each do |stc|
stc.hash.should == stc.dup.hash
- stc.hash.should be_kind_of(Fixnum)
+ stc.hash.should.is_a?(Integer)
end
end
it "returns the same value if structs are #eql?" do
car = StructClasses::Car.new("Honda", "Accord", "1998")
similar_car = StructClasses::Car.new("Honda", "Accord", "1998")
- car.should eql(similar_car)
+ car.should.eql?(similar_car)
car.hash.should == similar_car.hash
end
+ it "returns different hashes for structs with different values" do
+ s1 = StructClasses::Ruby.new('2.7.0', 'linux')
+ s2 = StructClasses::Ruby.new('2.7.0', 'macos')
+ s1.hash.should_not == s2.hash
+ end
+
+ it "returns different hashes for structs with different values when using keyword_init: true" do
+ key = :"1 non symbol member"
+ struct_class = Struct.new(key, keyword_init: true)
+ t1 = struct_class.new(key => 1)
+ t2 = struct_class.new(key => 2)
+ t1.hash.should_not == t2.hash
+ end
+
it "allows for overriding methods in an included module" do
mod = Module.new do
def hash
@@ -42,5 +56,9 @@ describe "Struct#hash" do
# See the Struct#eql? specs
end
+ it "returns different hashes for different struct classes" do
+ Struct.new(:x).new(1).hash.should != Struct.new(:y).new(1).hash
+ end
+
it_behaves_like :struct_accessor, :hash
end
diff --git a/spec/ruby/core/struct/initialize_spec.rb b/spec/ruby/core/struct/initialize_spec.rb
index 989459114a..c824f52e13 100644
--- a/spec/ruby/core/struct/initialize_spec.rb
+++ b/spec/ruby/core/struct/initialize_spec.rb
@@ -1,10 +1,10 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Struct#initialize" do
it "is private" do
- StructClasses::Car.should have_private_instance_method(:initialize)
+ StructClasses::Car.private_instance_methods(true).should.include?(:initialize)
end
it 'allows valid Ruby method names for members' do
@@ -40,4 +40,35 @@ describe "Struct#initialize" do
it "can be overridden" do
StructClasses::SubclassX.new(:y).new.key.should == :value
end
+
+ it "can be initialized with keyword arguments" do
+ positional_args = StructClasses::Ruby.new("3.2", "OS")
+ keyword_args = StructClasses::Ruby.new(version: "3.2", platform: "OS")
+
+ positional_args.version.should == keyword_args.version
+ positional_args.platform.should == keyword_args.platform
+ end
+
+ it "accepts positional arguments with empty keyword arguments" do
+ data = StructClasses::Single.new(42, **{})
+
+ data.value.should == 42
+
+ data = StructClasses::Ruby.new("3.2", "OS", **{})
+
+ data.version.should == "3.2"
+ data.platform.should == "OS"
+ end
+
+ it "can be called via delegated ... from a prepended module" do
+ wrapper = Module.new do
+ def initialize(...)
+ super(...)
+ end
+ end
+
+ klass = Class.new(Struct.new(:a)) { prepend wrapper }
+ s = klass.new("x")
+ s.a.should == "x"
+ end
end
diff --git a/spec/ruby/core/struct/inspect_spec.rb b/spec/ruby/core/struct/inspect_spec.rb
index 94fb71a5f1..13fd0bef41 100644
--- a/spec/ruby/core/struct/inspect_spec.rb
+++ b/spec/ruby/core/struct/inspect_spec.rb
@@ -1,15 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/inspect', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Struct#inspect" do
- it "returns a string representation of some kind" do
- car = StructClasses::Car.new('Ford', 'Ranger')
- car.inspect.should == '#<struct StructClasses::Car make="Ford", model="Ranger", year=nil>'
-
- Whiskey = Struct.new(:name, :ounces)
- Whiskey.new('Jack', 100).inspect.should == '#<struct Whiskey name="Jack", ounces=100>'
+ it "is an alias of Struct#to_s" do
+ StructClasses::Car.instance_method(:inspect).should == StructClasses::Car.instance_method(:to_s)
end
-
- it_behaves_like(:struct_inspect, :inspect)
end
diff --git a/spec/ruby/core/struct/instance_variable_get_spec.rb b/spec/ruby/core/struct/instance_variable_get_spec.rb
new file mode 100644
index 0000000000..e3555cd246
--- /dev/null
+++ b/spec/ruby/core/struct/instance_variable_get_spec.rb
@@ -0,0 +1,16 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe "Struct#instance_variable_get" do
+ it "returns nil for attributes" do
+ car = StructClasses::Car.new("Hugo", "Foo", "1972")
+ car.instance_variable_get(:@make).should == nil
+ end
+
+ it "returns a user value for variables with the same name as attributes" do
+ car = StructClasses::Car.new("Hugo", "Foo", "1972")
+ car.instance_variable_set :@make, "explicit"
+ car.instance_variable_get(:@make).should == "explicit"
+ car.make.should == "Hugo"
+ end
+end
diff --git a/spec/ruby/core/struct/instance_variables_spec.rb b/spec/ruby/core/struct/instance_variables_spec.rb
index 3abb8578a5..f6d30ea97e 100644
--- a/spec/ruby/core/struct/instance_variables_spec.rb
+++ b/spec/ruby/core/struct/instance_variables_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Struct#instance_variables" do
it "returns an empty array if only attributes are defined" do
diff --git a/spec/ruby/core/struct/keyword_init_spec.rb b/spec/ruby/core/struct/keyword_init_spec.rb
new file mode 100644
index 0000000000..42fcd3cc29
--- /dev/null
+++ b/spec/ruby/core/struct/keyword_init_spec.rb
@@ -0,0 +1,45 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+# See https://bugs.ruby-lang.org/issues/18008
+describe "StructClass#keyword_init?" do
+ it "returns true for a struct that accepts keyword arguments to initialize" do
+ struct = Struct.new(:arg, keyword_init: true)
+ struct.keyword_init?.should == true
+ end
+
+ it "returns false for a struct that does not accept keyword arguments to initialize" do
+ struct = Struct.new(:arg, keyword_init: false)
+ struct.keyword_init?.should == false
+ end
+
+ it "returns nil for a struct that did not explicitly specify keyword_init" do
+ struct = Struct.new(:arg)
+ struct.keyword_init?.should == nil
+ end
+
+ it "returns nil for a struct that does specify keyword_init to be nil" do
+ struct = Struct.new(:arg, keyword_init: nil)
+ struct.keyword_init?.should == nil
+ end
+
+ it "returns true for any truthy value, not just for true" do
+ struct = Struct.new(:arg, keyword_init: 1)
+ struct.keyword_init?.should == true
+
+ struct = Struct.new(:arg, keyword_init: "")
+ struct.keyword_init?.should == true
+
+ struct = Struct.new(:arg, keyword_init: [])
+ struct.keyword_init?.should == true
+
+ struct = Struct.new(:arg, keyword_init: {})
+ struct.keyword_init?.should == true
+ end
+
+ context "class inheriting Struct" do
+ it "isn't available in a subclass" do
+ StructClasses::StructSubclass.should_not.respond_to?(:keyword_init?)
+ end
+ end
+end
diff --git a/spec/ruby/core/struct/length_spec.rb b/spec/ruby/core/struct/length_spec.rb
index 067bb08f88..8d48f4118d 100644
--- a/spec/ruby/core/struct/length_spec.rb
+++ b/spec/ruby/core/struct/length_spec.rb
@@ -1,12 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/accessor', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Struct#length" do
- it "returns the number of attributes" do
- StructClasses::Car.new('Cadillac', 'DeVille').length.should == 3
- StructClasses::Car.new.length.should == 3
+ it "is an alias of Struct#size" do
+ StructClasses::Car.instance_method(:length).should == StructClasses::Car.instance_method(:size)
end
-
- it_behaves_like :struct_accessor, :length
end
diff --git a/spec/ruby/core/struct/members_spec.rb b/spec/ruby/core/struct/members_spec.rb
index 702e536a55..1ff7b9387a 100644
--- a/spec/ruby/core/struct/members_spec.rb
+++ b/spec/ruby/core/struct/members_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/accessor', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/accessor'
describe "Struct#members" do
it "returns an array of attribute names" do
@@ -11,3 +11,15 @@ describe "Struct#members" do
it_behaves_like :struct_accessor, :members
end
+
+describe "StructClass#members" do
+ it "returns an array of attribute names" do
+ StructClasses::Car.members.should == [:make, :model, :year]
+ end
+
+ context "class inheriting Struct" do
+ it "isn't available in a subclass" do
+ StructClasses::StructSubclass.should_not.respond_to?(:members)
+ end
+ end
+end
diff --git a/spec/ruby/core/struct/new_spec.rb b/spec/ruby/core/struct/new_spec.rb
index 314f749955..b3ece2efed 100644
--- a/spec/ruby/core/struct/new_spec.rb
+++ b/spec/ruby/core/struct/new_spec.rb
@@ -1,11 +1,13 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Struct.new" do
it "creates a constant in Struct namespace with string as first argument" do
struct = Struct.new('Animal', :name, :legs, :eyeballs)
struct.should == Struct::Animal
struct.name.should == "Struct::Animal"
+ ensure
+ Struct.send(:remove_const, :Animal)
end
it "overwrites previously defined constants with string as first argument" do
@@ -13,12 +15,14 @@ describe "Struct.new" do
first.should == Struct::Person
second = nil
- lambda {
+ -> {
second = Struct.new('Person', :hair, :sex)
- }.should complain(/redefining constant/)
+ }.should complain(/constant/)
second.should == Struct::Person
first.members.should_not == second.members
+ ensure
+ Struct.send(:remove_const, :Person)
end
it "calls to_str on its first argument (constant name)" do
@@ -27,51 +31,71 @@ describe "Struct.new" do
struct = Struct.new(obj)
struct.should == Struct::Foo
struct.name.should == "Struct::Foo"
+ ensure
+ Struct.send(:remove_const, :Foo)
end
it "creates a new anonymous class with nil first argument" do
struct = Struct.new(nil, :foo)
struct.new("bar").foo.should == "bar"
- struct.should be_kind_of(Class)
- struct.name.should be_nil
+ struct.should.is_a?(Class)
+ struct.name.should == nil
end
it "creates a new anonymous class with symbol arguments" do
struct = Struct.new(:make, :model)
- struct.should be_kind_of(Class)
+ struct.should.is_a?(Class)
struct.name.should == nil
end
it "does not create a constant with symbol as first argument" do
Struct.new(:Animal2, :name, :legs, :eyeballs)
- Struct.const_defined?("Animal2").should be_false
+ Struct.const_defined?("Animal2").should == false
end
+ it "allows non-ASCII member name" do
+ name = "r\xe9sum\xe9".dup.force_encoding(Encoding::ISO_8859_1).to_sym
+ struct = Struct.new(name)
+ struct.new("foo").send(name).should == "foo"
+ end
it "fails with invalid constant name as first argument" do
- lambda { Struct.new('animal', :name, :legs, :eyeballs) }.should raise_error(NameError)
+ -> { Struct.new('animal', :name, :legs, :eyeballs) }.should.raise(NameError)
end
it "raises a TypeError if object doesn't respond to to_sym" do
- lambda { Struct.new(:animal, mock('giraffe')) }.should raise_error(TypeError)
- lambda { Struct.new(:animal, 1.0) }.should raise_error(TypeError)
- lambda { Struct.new(:animal, Time.now) }.should raise_error(TypeError)
- lambda { Struct.new(:animal, Class) }.should raise_error(TypeError)
- lambda { Struct.new(:animal, nil) }.should raise_error(TypeError)
- lambda { Struct.new(:animal, true) }.should raise_error(TypeError)
- lambda { Struct.new(:animal, ['chris', 'evan']) }.should raise_error(TypeError)
- lambda { Struct.new(:animal, { name: 'chris' }) }.should raise_error(TypeError)
+ -> { Struct.new(:animal, mock('giraffe')) }.should.raise(TypeError)
+ -> { Struct.new(:animal, 1.0) }.should.raise(TypeError)
+ -> { Struct.new(:animal, Time.now) }.should.raise(TypeError)
+ -> { Struct.new(:animal, Class) }.should.raise(TypeError)
+ -> { Struct.new(:animal, nil) }.should.raise(TypeError)
+ -> { Struct.new(:animal, true) }.should.raise(TypeError)
+ -> { Struct.new(:animal, ['chris', 'evan']) }.should.raise(TypeError)
+ end
+
+ it "raises a TypeError if passed a Hash with an unknown key" do
+ -> { Struct.new(:animal, { name: 'chris' }) }.should.raise(TypeError)
+ end
+
+ it "works when not provided any arguments" do
+ c = Struct.new
+ c.should.is_a?(Class)
+ c.superclass.should == Struct
+ end
+
+ it "raises ArgumentError when there is a duplicate member" do
+ -> { Struct.new(:foo, :foo) }.should.raise(ArgumentError, "duplicate member: foo")
end
it "raises a TypeError if object is not a Symbol" do
obj = mock(':ruby')
def obj.to_sym() :ruby end
- lambda { Struct.new(:animal, obj) }.should raise_error(TypeError)
+ -> { Struct.new(:animal, obj) }.should.raise(TypeError)
end
it "processes passed block with instance_eval" do
klass = Struct.new(:something) { @something_else = 'something else entirely!' }
- klass.instance_variables.should include(:@something_else)
+ klass.instance_variables.should.include?(:@something_else)
end
context "with a block" do
@@ -92,7 +116,7 @@ describe "Struct.new" do
klass = Struct.new(:attr) do |block_parameter|
given = block_parameter
end
- klass.should equal(given)
+ klass.should.equal?(given)
end
end
@@ -100,6 +124,8 @@ describe "Struct.new" do
it "creates a constant in subclass' namespace" do
struct = StructClasses::Apple.new('Computer', :size)
struct.should == StructClasses::Apple::Computer
+ ensure
+ StructClasses::Apple.send(:remove_const, :Computer)
end
it "creates an instance" do
@@ -107,17 +133,123 @@ describe "Struct.new" do
end
it "creates reader methods" do
- StructClasses::Ruby.new.should have_method(:version)
- StructClasses::Ruby.new.should have_method(:platform)
+ StructClasses::Ruby.new.should.respond_to?(:version)
+ StructClasses::Ruby.new.should.respond_to?(:platform)
end
it "creates writer methods" do
- StructClasses::Ruby.new.should have_method(:version=)
- StructClasses::Ruby.new.should have_method(:platform=)
+ StructClasses::Ruby.new.should.respond_to?(:version=)
+ StructClasses::Ruby.new.should.respond_to?(:platform=)
end
it "fails with too many arguments" do
- lambda { StructClasses::Ruby.new('2.0', 'i686', true) }.should raise_error(ArgumentError)
+ -> { StructClasses::Ruby.new('2.0', 'i686', true) }.should.raise(ArgumentError)
+ end
+
+ it "accepts keyword arguments to initialize" do
+ type = Struct.new(:args)
+
+ obj = type.new(args: 42)
+ obj2 = type.new(42)
+
+ obj.should == obj2
+ obj.args.should == 42
+ obj2.args.should == 42
+ end
+
+ context "given positional and keyword arguments" do
+ it "treats keyword arguments as a positional parameter" do
+ type = Struct.new(:a, :b)
+ s = type.new("a", b: "b")
+ s.a.should == "a"
+ s.b.should == {b: "b"}
+
+ type = Struct.new(:a, :b, :c)
+ s = type.new("a", b: "b", c: "c")
+ s.a.should == "a"
+ s.b.should == {b: "b", c: "c"}
+ s.c.should == nil
+ end
+
+ it "ignores empty keyword arguments" do
+ type = Struct.new(:a, :b)
+ h = {}
+ s = type.new("a", **h)
+
+ s.a.should == "a"
+ s.b.should == nil
+ end
+
+ it "raises ArgumentError when all struct attribute values are specified" do
+ type = Struct.new(:a, :b)
+ -> { type.new("a", "b", c: "c") }.should.raise(ArgumentError, "struct size differs")
+ end
+ end
+ end
+
+ context "keyword_init: true option" do
+ before :all do
+ @struct_with_kwa = Struct.new(:name, :legs, keyword_init: true)
+ end
+
+ it "creates a class that accepts keyword arguments to initialize" do
+ obj = @struct_with_kwa.new(name: "elefant", legs: 4)
+ obj.name.should == "elefant"
+ obj.legs.should == 4
+ end
+
+ it "raises when there is a duplicate member" do
+ -> { Struct.new(:foo, :foo, keyword_init: true) }.should.raise(ArgumentError, "duplicate member: foo")
+ end
+
+ describe "new class instantiation" do
+ it "accepts arguments as hash as well" do
+ obj = @struct_with_kwa.new({name: "elefant", legs: 4})
+ obj.name.should == "elefant"
+ obj.legs.should == 4
+ end
+
+ it "allows missing arguments" do
+ obj = @struct_with_kwa.new(name: "elefant")
+ obj.name.should == "elefant"
+ obj.legs.should == nil
+ end
+
+ it "allows no arguments" do
+ obj = @struct_with_kwa.new
+ obj.name.should == nil
+ obj.legs.should == nil
+ end
+
+ it "raises ArgumentError when passed not declared keyword argument" do
+ -> {
+ @struct_with_kwa.new(name: "elefant", legs: 4, foo: "bar")
+ }.should.raise(ArgumentError, /unknown keywords: foo/)
+ end
+
+ it "raises ArgumentError when passed a list of arguments" do
+ -> {
+ @struct_with_kwa.new("elefant", 4)
+ }.should.raise(ArgumentError, /wrong number of arguments/)
+ end
+
+ it "raises ArgumentError when passed a single non-hash argument" do
+ -> {
+ @struct_with_kwa.new("elefant")
+ }.should.raise(ArgumentError, /wrong number of arguments/)
+ end
+ end
+ end
+
+ context "keyword_init: false option" do
+ before :all do
+ @struct_without_kwa = Struct.new(:name, :legs, keyword_init: false)
+ end
+
+ it "behaves like it does without :keyword_init option" do
+ obj = @struct_without_kwa.new("elefant", 4)
+ obj.name.should == "elefant"
+ obj.legs.should == 4
end
end
end
diff --git a/spec/ruby/core/struct/select_spec.rb b/spec/ruby/core/struct/select_spec.rb
index da80eea0e8..5f26a177eb 100644
--- a/spec/ruby/core/struct/select_spec.rb
+++ b/spec/ruby/core/struct/select_spec.rb
@@ -1,11 +1,15 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/accessor', __FILE__)
-require File.expand_path('../../enumerable/shared/enumeratorized', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/accessor'
+require_relative '../enumerable/shared/enumeratorized'
describe "Struct#select" do
+ it_behaves_like :struct_accessor, :select
+ it_behaves_like :enumeratorized_with_origin_size, :select, Struct.new(:foo).new
+
it "raises an ArgumentError if given any non-block arguments" do
- lambda { StructClasses::Car.new.select(1) { } }.should raise_error(ArgumentError)
+ struct = StructClasses::Car.new
+ -> { struct.select(1) { } }.should.raise(ArgumentError)
end
it "returns a new array of elements for which block is true" do
@@ -15,16 +19,13 @@ describe "Struct#select" do
it "returns an instance of Array" do
struct = StructClasses::Car.new("Ford", "Escort", "1995")
- struct.select { true }.should be_an_instance_of(Array)
+ struct.select { true }.should.instance_of?(Array)
end
describe "without block" do
it "returns an instance of Enumerator" do
struct = Struct.new(:foo).new
- struct.select.should be_an_instance_of(Enumerator)
+ struct.select.should.instance_of?(Enumerator)
end
end
-
- it_behaves_like :struct_accessor, :select
- it_behaves_like :enumeratorized_with_origin_size, :select, Struct.new(:foo).new
end
diff --git a/spec/ruby/core/struct/shared/dup.rb b/spec/ruby/core/struct/shared/dup.rb
new file mode 100644
index 0000000000..994f3f443e
--- /dev/null
+++ b/spec/ruby/core/struct/shared/dup.rb
@@ -0,0 +1,9 @@
+describe :struct_dup, shared: true do
+ it "duplicates members" do
+ klass = Struct.new(:foo, :bar)
+ instance = klass.new(14, 2)
+ duped = instance.send(@method)
+ duped.foo.should == 14
+ duped.bar.should == 2
+ end
+end
diff --git a/spec/ruby/core/struct/shared/equal_value.rb b/spec/ruby/core/struct/shared/equal_value.rb
index 711862cb44..a7e0856df5 100644
--- a/spec/ruby/core/struct/shared/equal_value.rb
+++ b/spec/ruby/core/struct/shared/equal_value.rb
@@ -16,6 +16,13 @@ describe :struct_equal_value, shared: true do
car.send(@method, different_car).should == false
end
+ it "returns false if other is of a different class" do
+ car = StructClasses::Car.new("Honda", "Accord", "1998")
+ klass = Struct.new(:make, :model, :year)
+ clone = klass.new("Honda", "Accord", "1998")
+ car.send(@method, clone).should == false
+ end
+
it "handles recursive structures by returning false if a difference can be found" do
x = StructClasses::Car.new("Honda", "Accord", "1998")
x[:make] = x
diff --git a/spec/ruby/core/struct/shared/inspect.rb b/spec/ruby/core/struct/shared/inspect.rb
deleted file mode 100644
index 90594a5452..0000000000
--- a/spec/ruby/core/struct/shared/inspect.rb
+++ /dev/null
@@ -1,5 +0,0 @@
-describe :struct_inspect, shared: true do
- it "returns a string representation without the class name for anonymous structs" do
- Struct.new(:a).new("").send(@method).should == '#<struct a="">'
- end
-end
diff --git a/spec/ruby/core/struct/size_spec.rb b/spec/ruby/core/struct/size_spec.rb
index 29b1d2bfba..5f07320bb9 100644
--- a/spec/ruby/core/struct/size_spec.rb
+++ b/spec/ruby/core/struct/size_spec.rb
@@ -1,10 +1,11 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/accessor', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/accessor'
describe "Struct#size" do
- it "is a synonym for length" do
- StructClasses::Car.new.size.should == StructClasses::Car.new.length
+ it "returns the number of attributes" do
+ StructClasses::Car.new('Cadillac', 'DeVille').length.should == 3
+ StructClasses::Car.new.length.should == 3
end
it_behaves_like :struct_accessor, :size
diff --git a/spec/ruby/core/struct/struct_spec.rb b/spec/ruby/core/struct/struct_spec.rb
index 6c1941aed5..9fab9c0629 100644
--- a/spec/ruby/core/struct/struct_spec.rb
+++ b/spec/ruby/core/struct/struct_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Struct" do
it "includes Enumerable" do
@@ -21,7 +21,7 @@ describe "Struct anonymous class instance methods" do
it "reader method should not interfere with undefined methods" do
car = StructClasses::Car.new('Ford', 'Ranger')
- lambda { car.something_weird }.should raise_error(NoMethodError)
+ -> { car.something_weird }.should.raise(NoMethodError)
end
it "writer method be a synonym for []=" do
@@ -33,6 +33,13 @@ describe "Struct anonymous class instance methods" do
car['model'].should == 'F150'
car[1].should == 'F150'
end
+
+ it "writer methods raise a FrozenError on a frozen struct" do
+ car = StructClasses::Car.new('Ford', 'Ranger')
+ car.freeze
+
+ -> { car.model = 'Escape' }.should.raise(FrozenError)
+ end
end
describe "Struct subclasses" do
diff --git a/spec/ruby/core/struct/tms/cstime_spec.rb b/spec/ruby/core/struct/tms/cstime_spec.rb
deleted file mode 100644
index 839b02b6e9..0000000000
--- a/spec/ruby/core/struct/tms/cstime_spec.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-
-describe "Struct::Tms#cstime" do
- it "needs to be reviewed for spec completeness"
-end
-
-describe "Struct::Tms#cstime=" do
- it "needs to be reviewed for spec completeness"
-end
diff --git a/spec/ruby/core/struct/tms/cutime_spec.rb b/spec/ruby/core/struct/tms/cutime_spec.rb
deleted file mode 100644
index 235f378fab..0000000000
--- a/spec/ruby/core/struct/tms/cutime_spec.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-
-describe "Struct::Tms#cutime" do
- it "needs to be reviewed for spec completeness"
-end
-
-describe "Struct::Tms#cutime=" do
- it "needs to be reviewed for spec completeness"
-end
diff --git a/spec/ruby/core/struct/tms/element_reference_spec.rb b/spec/ruby/core/struct/tms/element_reference_spec.rb
deleted file mode 100644
index f1735341b4..0000000000
--- a/spec/ruby/core/struct/tms/element_reference_spec.rb
+++ /dev/null
@@ -1,5 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-
-describe "Struct::Tms.[]" do
- it "needs to be reviewed for spec completeness"
-end
diff --git a/spec/ruby/core/struct/tms/members_spec.rb b/spec/ruby/core/struct/tms/members_spec.rb
deleted file mode 100644
index ddfca83659..0000000000
--- a/spec/ruby/core/struct/tms/members_spec.rb
+++ /dev/null
@@ -1,5 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-
-describe "Struct::Tms.members" do
- it "needs to be reviewed for spec completeness"
-end
diff --git a/spec/ruby/core/struct/tms/new_spec.rb b/spec/ruby/core/struct/tms/new_spec.rb
deleted file mode 100644
index cf7a501aa2..0000000000
--- a/spec/ruby/core/struct/tms/new_spec.rb
+++ /dev/null
@@ -1,5 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-
-describe "Struct::Tms.new" do
- it "needs to be reviewed for spec completeness"
-end
diff --git a/spec/ruby/core/struct/tms/stime_spec.rb b/spec/ruby/core/struct/tms/stime_spec.rb
deleted file mode 100644
index f45253cf44..0000000000
--- a/spec/ruby/core/struct/tms/stime_spec.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-
-describe "Struct::Tms#stime" do
- it "needs to be reviewed for spec completeness"
-end
-
-describe "Struct::Tms#stime=" do
- it "needs to be reviewed for spec completeness"
-end
diff --git a/spec/ruby/core/struct/tms/utime_spec.rb b/spec/ruby/core/struct/tms/utime_spec.rb
deleted file mode 100644
index ea6783a17b..0000000000
--- a/spec/ruby/core/struct/tms/utime_spec.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-
-describe "Struct::Tms#utime" do
- it "needs to be reviewed for spec completeness"
-end
-
-describe "Struct::Tms#utime=" do
- it "needs to be reviewed for spec completeness"
-end
diff --git a/spec/ruby/core/struct/to_a_spec.rb b/spec/ruby/core/struct/to_a_spec.rb
index f8e9a3658d..cb61dc45cc 100644
--- a/spec/ruby/core/struct/to_a_spec.rb
+++ b/spec/ruby/core/struct/to_a_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/accessor', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/accessor'
describe "Struct#to_a" do
it "returns the values for this instance as an array" do
diff --git a/spec/ruby/core/struct/to_h_spec.rb b/spec/ruby/core/struct/to_h_spec.rb
index 6b8037f950..e0846ef268 100644
--- a/spec/ruby/core/struct/to_h_spec.rb
+++ b/spec/ruby/core/struct/to_h_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Struct#to_h" do
it "returns a Hash with members as keys" do
@@ -12,4 +12,57 @@ describe "Struct#to_h" do
car.to_h[:make] = 'Suzuki'
car.make.should == 'Ford'
end
+
+ context "with block" do
+ it "converts [key, value] pairs returned by the block to a hash" do
+ car = StructClasses::Car.new('Ford', 'Ranger')
+
+ h = car.to_h { |k, v| [k.to_s, "#{v}".downcase] }
+ h.should == { "make" => "ford", "model" => "ranger", "year" => "" }
+ end
+
+ it "passes to a block each pair's key and value as separate arguments" do
+ s = StructClasses::Ruby.new('3.2.4', 'macos')
+
+ ScratchPad.record []
+ s.to_h { |k, v| ScratchPad << [k, v]; [k, v] }
+ ScratchPad.recorded.sort.should == [[:platform, 'macos'], [:version, '3.2.4']]
+
+ ScratchPad.record []
+ s.to_h { |*args| ScratchPad << args; [args[0], args[1]] }
+ ScratchPad.recorded.sort.should == [[:platform, 'macos'], [:version, '3.2.4']]
+ end
+
+ it "raises ArgumentError if block returns longer or shorter array" do
+ -> do
+ StructClasses::Car.new.to_h { |k, v| [k.to_s, "#{v}".downcase, 1] }
+ end.should.raise(ArgumentError, /element has wrong array length/)
+
+ -> do
+ StructClasses::Car.new.to_h { |k, v| [k] }
+ end.should.raise(ArgumentError, /element has wrong array length/)
+ end
+
+ it "raises TypeError if block returns something other than Array" do
+ -> do
+ StructClasses::Car.new.to_h { |k, v| "not-array" }
+ end.should.raise(TypeError, /wrong element type String/)
+ end
+
+ it "coerces returned pair to Array with #to_ary" do
+ x = mock('x')
+ x.stub!(:to_ary).and_return([:b, 'b'])
+
+ StructClasses::Car.new.to_h { |k| x }.should == { :b => 'b' }
+ end
+
+ it "does not coerce returned pair to Array with #to_a" do
+ x = mock('x')
+ x.stub!(:to_a).and_return([:b, 'b'])
+
+ -> do
+ StructClasses::Car.new.to_h { |k| x }
+ end.should.raise(TypeError, /wrong element type MockObject/)
+ end
+ end
end
diff --git a/spec/ruby/core/struct/to_s_spec.rb b/spec/ruby/core/struct/to_s_spec.rb
index b9fd413093..9648b8af9b 100644
--- a/spec/ruby/core/struct/to_s_spec.rb
+++ b/spec/ruby/core/struct/to_s_spec.rb
@@ -1,12 +1,43 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/inspect', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Struct#to_s" do
- it "is a synonym for inspect" do
+ it "returns a string representation showing members and values" do
car = StructClasses::Car.new('Ford', 'Ranger')
- car.inspect.should == car.to_s
+ car.to_s.should == '#<struct StructClasses::Car make="Ford", model="Ranger", year=nil>'
end
- it_behaves_like(:struct_inspect, :to_s)
+ it "returns a string representation without the class name for anonymous structs" do
+ Struct.new(:a).new("").to_s.should == '#<struct a="">'
+ end
+
+ it "returns a string representation without the class name for structs nested in anonymous classes" do
+ c = Class.new
+ c.class_eval <<~DOC
+ class Foo < Struct.new(:a); end
+ DOC
+
+ c::Foo.new("").to_s.should == '#<struct a="">'
+ end
+
+ it "returns a string representation without the class name for structs nested in anonymous modules" do
+ m = Module.new
+ m.module_eval <<~DOC
+ class Foo < Struct.new(:a); end
+ DOC
+
+ m::Foo.new("").to_s.should == '#<struct a="">'
+ end
+
+ it "does not call #name method" do
+ struct = StructClasses::StructWithOverriddenName.new("")
+ struct.to_s.should == '#<struct StructClasses::StructWithOverriddenName a="">'
+ end
+
+ it "does not call #name method when struct is anonymous" do
+ struct = Struct.new(:a)
+ def struct.name; "A"; end
+
+ struct.new("").to_s.should == '#<struct a="">'
+ end
end
diff --git a/spec/ruby/core/struct/values_at_spec.rb b/spec/ruby/core/struct/values_at_spec.rb
index 58016e2f2a..6aac5d96b3 100644
--- a/spec/ruby/core/struct/values_at_spec.rb
+++ b/spec/ruby/core/struct/values_at_spec.rb
@@ -1,16 +1,59 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+# Should be synchronized with core/array/values_at_spec.rb
describe "Struct#values_at" do
- it "returns an array of values" do
+ before do
clazz = Struct.new(:name, :director, :year)
- movie = clazz.new('Sympathy for Mr. Vengence', 'Chan-wook Park', 2002)
- movie.values_at(0, 1).should == ['Sympathy for Mr. Vengence', 'Chan-wook Park']
- movie.values_at(0..2).should == ['Sympathy for Mr. Vengence', 'Chan-wook Park', 2002]
+ @movie = clazz.new('Sympathy for Mr. Vengeance', 'Chan-wook Park', 2002)
+ end
+
+ context "when passed a list of Integers" do
+ it "returns an array containing each value given by one of integers" do
+ @movie.values_at(0, 1).should == ['Sympathy for Mr. Vengeance', 'Chan-wook Park']
+ end
+
+ it "raises IndexError if any of integers is out of range" do
+ -> { @movie.values_at(3) }.should.raise(IndexError, "offset 3 too large for struct(size:3)")
+ -> { @movie.values_at(-4) }.should.raise(IndexError, "offset -4 too small for struct(size:3)")
+ end
+ end
+
+ context "when passed an integer Range" do
+ it "returns an array containing each value given by the elements of the range" do
+ @movie.values_at(0..2).should == ['Sympathy for Mr. Vengeance', 'Chan-wook Park', 2002]
+ end
+
+ it "fills with nil values for range elements larger than the structure" do
+ @movie.values_at(0..3).should == ['Sympathy for Mr. Vengeance', 'Chan-wook Park', 2002, nil]
+ end
+
+ it "raises RangeError if any element of the range is negative and out of range" do
+ -> { @movie.values_at(-4..3) }.should.raise(RangeError, "-4..3 out of range")
+ end
+
+ it "supports endless Range" do
+ @movie.values_at(0..).should == ["Sympathy for Mr. Vengeance", "Chan-wook Park", 2002]
+ end
+
+ it "supports beginningless Range" do
+ @movie.values_at(..2).should == ["Sympathy for Mr. Vengeance", "Chan-wook Park", 2002]
+ end
+ end
+
+ it "supports multiple integer Ranges" do
+ @movie.values_at(0..2, 1..2).should == ['Sympathy for Mr. Vengeance', 'Chan-wook Park', 2002, 'Chan-wook Park', 2002]
+ end
+
+ it "supports mixing integer Ranges and Integers" do
+ @movie.values_at(0..2, 2).should == ['Sympathy for Mr. Vengeance', 'Chan-wook Park', 2002, 2002]
+ end
+
+ it "returns a new empty Array if no arguments given" do
+ @movie.values_at().should == []
end
it "fails when passed unsupported types" do
- car = StructClasses::Car.new('Ford', 'Ranger')
- lambda { car.values_at('make') }.should raise_error(TypeError)
+ -> { @movie.values_at('make') }.should.raise(TypeError, "no implicit conversion of String into Integer")
end
end
diff --git a/spec/ruby/core/struct/values_spec.rb b/spec/ruby/core/struct/values_spec.rb
index 0e86d33cb5..16583253d7 100644
--- a/spec/ruby/core/struct/values_spec.rb
+++ b/spec/ruby/core/struct/values_spec.rb
@@ -1,11 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Struct#values" do
- it "is a synonym for to_a" do
- car = StructClasses::Car.new('Nissan', 'Maxima')
- car.values.should == car.to_a
-
- StructClasses::Car.new.values.should == StructClasses::Car.new.to_a
+ it "is an alias of Struct#to_a" do
+ StructClasses::Car.instance_method(:values).should == StructClasses::Car.instance_method(:to_a)
end
end
diff --git a/spec/ruby/core/symbol/all_symbols_spec.rb b/spec/ruby/core/symbol/all_symbols_spec.rb
index d18d58ba48..689f6211de 100644
--- a/spec/ruby/core/symbol/all_symbols_spec.rb
+++ b/spec/ruby/core/symbol/all_symbols_spec.rb
@@ -1,14 +1,19 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Symbol.all_symbols" do
- it "returns an array containing all the Symbols in the symbol table" do
+ it "returns an array of Symbols" do
all_symbols = Symbol.all_symbols
- all_symbols.should be_an_instance_of(Array)
- all_symbols.all? { |s| s.is_a?(Symbol) ? true : (p s; false) }.should == true
+ all_symbols.should.instance_of?(Array)
+ all_symbols.each { |s| s.should.instance_of?(Symbol) }
end
- it "returns an Array containing Symbols that have been created" do
+ it "includes symbols that are strongly referenced" do
symbol = "symbol_specs_#{rand(5_000_000)}".to_sym
- Symbol.all_symbols.should include(symbol)
+ Symbol.all_symbols.should.include?(symbol)
+ end
+
+ it "includes symbols that are referenced in source code but not yet executed" do
+ Symbol.all_symbols.any? { |s| s.to_s == 'symbol_specs_referenced_in_source_code' }.should == true
+ :symbol_specs_referenced_in_source_code
end
end
diff --git a/spec/ruby/core/symbol/capitalize_spec.rb b/spec/ruby/core/symbol/capitalize_spec.rb
index 73850a2a8c..a93d951e6a 100644
--- a/spec/ruby/core/symbol/capitalize_spec.rb
+++ b/spec/ruby/core/symbol/capitalize_spec.rb
@@ -1,9 +1,9 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Symbol#capitalize" do
it "returns a Symbol" do
- :glark.capitalize.should be_an_instance_of(Symbol)
+ :glark.capitalize.should.instance_of?(Symbol)
end
it "converts the first character to uppercase if it is ASCII" do
@@ -14,18 +14,9 @@ describe "Symbol#capitalize" do
:"£1.20".capitalize.should == :"£1.20"
end
- ruby_version_is ''...'2.4' do
- it "leaves the first character alone if it is not an alphabetical ASCII character" do
- "\u{00DE}c".to_sym.capitalize.should == :"Þc"
- "\u{00DF}C".to_sym.capitalize.should == :"ßc"
- end
- end
-
- ruby_version_is '2.4' do
- it "capitalizes the first character if it is Unicode" do
- :"äöü".capitalize.should == :"Äöü"
- :"aou".capitalize.should == :"Aou"
- end
+ it "capitalizes the first character if it is Unicode" do
+ :"äöü".capitalize.should == :"Äöü"
+ :"aou".capitalize.should == :"Aou"
end
it "converts subsequent uppercase ASCII characters to their lowercase equivalents" do
@@ -40,12 +31,6 @@ describe "Symbol#capitalize" do
:mIxEd.capitalize.should == :Mixed
end
- ruby_version_is ''...'2.4' do
- it "leaves uppercase Unicode characters as they were" do
- "a\u{00DE}c".to_sym.capitalize.should == :"AÞc"
- end
- end
-
it "leaves lowercase Unicode characters (except in first position) as they were" do
"a\u{00DF}C".to_sym.capitalize.should == :"Aßc"
end
diff --git a/spec/ruby/core/symbol/case_compare_spec.rb b/spec/ruby/core/symbol/case_compare_spec.rb
index 5c705c0b04..a296132c04 100644
--- a/spec/ruby/core/symbol/case_compare_spec.rb
+++ b/spec/ruby/core/symbol/case_compare_spec.rb
@@ -1,11 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Symbol#===" do
- it "returns true when the argument is a Symbol" do
- (Symbol === :ruby).should == true
- end
-
- it "returns false when the argument is a String" do
- (Symbol === 'ruby').should == false
+ it "is an alias of Symbol#==" do
+ Symbol.instance_method(:===).should == Symbol.instance_method(:==)
end
end
diff --git a/spec/ruby/core/symbol/casecmp_spec.rb b/spec/ruby/core/symbol/casecmp_spec.rb
index 352c5b99cb..dcb77a8350 100644
--- a/spec/ruby/core/symbol/casecmp_spec.rb
+++ b/spec/ruby/core/symbol/casecmp_spec.rb
@@ -1,5 +1,5 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Symbol#casecmp with Symbol" do
it "compares symbols without regard to case" do
@@ -56,91 +56,97 @@ describe "Symbol#casecmp with Symbol" do
lower_a_tilde.casecmp(upper_a_tilde).should == 1
lower_a_umlaut.casecmp(upper_a_umlaut).should == 1
end
+
+ it "returns 0 for empty strings in different encodings" do
+ ''.to_sym.casecmp(''.encode("UTF-32LE").to_sym).should == 0
+ end
end
describe "Symbol#casecmp" do
it "returns nil if other is a String" do
- :abc.casecmp("abc").should be_nil
+ :abc.casecmp("abc").should == nil
end
- it "returns nil if other is a Fixnum" do
- :abc.casecmp(1).should be_nil
+ it "returns nil if other is an Integer" do
+ :abc.casecmp(1).should == nil
end
it "returns nil if other is an object" do
obj = mock("string <=>")
- :abc.casecmp(obj).should be_nil
+ :abc.casecmp(obj).should == nil
end
end
-ruby_version_is "2.4" do
- describe 'Symbol#casecmp?' do
- it "compares symbols without regard to case" do
- :abcdef.casecmp?(:abcde).should == false
- :aBcDeF.casecmp?(:abcdef).should == true
- :abcdef.casecmp?(:abcdefg).should == false
- :abcdef.casecmp?(:ABCDEF).should == true
- end
-
- it "doesn't consider non-ascii characters equal that aren't" do
- # -- Latin-1 --
- upper_a_tilde = "\xC3".b.to_sym
- upper_a_umlaut = "\xC4".b.to_sym
- lower_a_tilde = "\xE3".b.to_sym
- lower_a_umlaut = "\xE4".b.to_sym
-
- lower_a_tilde.casecmp?(lower_a_umlaut).should_not == true
- lower_a_umlaut.casecmp?(lower_a_tilde).should_not == true
- upper_a_tilde.casecmp?(upper_a_umlaut).should_not == true
- upper_a_umlaut.casecmp?(upper_a_tilde).should_not == true
-
- # -- UTF-8 --
- upper_a_tilde = :"Ã"
- lower_a_tilde = :"ã"
- upper_a_umlaut = :"Ä"
- lower_a_umlaut = :"ä"
-
- lower_a_tilde.casecmp?(lower_a_umlaut).should_not == true
- lower_a_umlaut.casecmp?(lower_a_tilde).should_not == true
- upper_a_tilde.casecmp?(upper_a_umlaut).should_not == true
- upper_a_umlaut.casecmp?(upper_a_tilde).should_not == true
- end
-
- it "doesn't do case mapping for non-ascii and non-unicode characters" do
- # -- Latin-1 --
- upper_a_tilde = "\xC3".b.to_sym
- upper_a_umlaut = "\xC4".b.to_sym
- lower_a_tilde = "\xE3".b.to_sym
- lower_a_umlaut = "\xE4".b.to_sym
-
- upper_a_tilde.casecmp?(lower_a_tilde).should == false
- upper_a_umlaut.casecmp?(lower_a_umlaut).should == false
- lower_a_tilde.casecmp?(upper_a_tilde).should == false
- lower_a_umlaut.casecmp?(upper_a_umlaut).should == false
- end
-
- it 'does case mapping for unicode characters' do
- # -- UTF-8 --
- upper_a_tilde = :"Ã"
- lower_a_tilde = :"ã"
- upper_a_umlaut = :"Ä"
- lower_a_umlaut = :"ä"
-
- upper_a_tilde.casecmp?(lower_a_tilde).should == true
- upper_a_umlaut.casecmp?(lower_a_umlaut).should == true
- lower_a_tilde.casecmp?(upper_a_tilde).should == true
- lower_a_umlaut.casecmp?(upper_a_umlaut).should == true
- end
-
- it 'returns nil when comparing characters with different encodings' do
- # -- Latin-1 --
- upper_a_tilde = "\xC3".b.to_sym
-
- # -- UTF-8 --
- lower_a_tilde = :"ã"
-
- upper_a_tilde.casecmp?(lower_a_tilde).should == nil
- lower_a_tilde.casecmp?(upper_a_tilde).should == nil
- end
+describe 'Symbol#casecmp?' do
+ it "compares symbols without regard to case" do
+ :abcdef.casecmp?(:abcde).should == false
+ :aBcDeF.casecmp?(:abcdef).should == true
+ :abcdef.casecmp?(:abcdefg).should == false
+ :abcdef.casecmp?(:ABCDEF).should == true
+ end
+
+ it "doesn't consider non-ascii characters equal that aren't" do
+ # -- Latin-1 --
+ upper_a_tilde = "\xC3".b.to_sym
+ upper_a_umlaut = "\xC4".b.to_sym
+ lower_a_tilde = "\xE3".b.to_sym
+ lower_a_umlaut = "\xE4".b.to_sym
+
+ lower_a_tilde.casecmp?(lower_a_umlaut).should_not == true
+ lower_a_umlaut.casecmp?(lower_a_tilde).should_not == true
+ upper_a_tilde.casecmp?(upper_a_umlaut).should_not == true
+ upper_a_umlaut.casecmp?(upper_a_tilde).should_not == true
+
+ # -- UTF-8 --
+ upper_a_tilde = :"Ã"
+ lower_a_tilde = :"ã"
+ upper_a_umlaut = :"Ä"
+ lower_a_umlaut = :"ä"
+
+ lower_a_tilde.casecmp?(lower_a_umlaut).should_not == true
+ lower_a_umlaut.casecmp?(lower_a_tilde).should_not == true
+ upper_a_tilde.casecmp?(upper_a_umlaut).should_not == true
+ upper_a_umlaut.casecmp?(upper_a_tilde).should_not == true
+ end
+
+ it "doesn't do case mapping for non-ascii and non-unicode characters" do
+ # -- Latin-1 --
+ upper_a_tilde = "\xC3".b.to_sym
+ upper_a_umlaut = "\xC4".b.to_sym
+ lower_a_tilde = "\xE3".b.to_sym
+ lower_a_umlaut = "\xE4".b.to_sym
+
+ upper_a_tilde.casecmp?(lower_a_tilde).should == false
+ upper_a_umlaut.casecmp?(lower_a_umlaut).should == false
+ lower_a_tilde.casecmp?(upper_a_tilde).should == false
+ lower_a_umlaut.casecmp?(upper_a_umlaut).should == false
+ end
+
+ it 'does case mapping for unicode characters' do
+ # -- UTF-8 --
+ upper_a_tilde = :"Ã"
+ lower_a_tilde = :"ã"
+ upper_a_umlaut = :"Ä"
+ lower_a_umlaut = :"ä"
+
+ upper_a_tilde.casecmp?(lower_a_tilde).should == true
+ upper_a_umlaut.casecmp?(lower_a_umlaut).should == true
+ lower_a_tilde.casecmp?(upper_a_tilde).should == true
+ lower_a_umlaut.casecmp?(upper_a_umlaut).should == true
+ end
+
+ it 'returns nil when comparing characters with different encodings' do
+ # -- Latin-1 --
+ upper_a_tilde = "\xC3".b.to_sym
+
+ # -- UTF-8 --
+ lower_a_tilde = :"ã"
+
+ upper_a_tilde.casecmp?(lower_a_tilde).should == nil
+ lower_a_tilde.casecmp?(upper_a_tilde).should == nil
+ end
+
+ it "returns true for empty symbols in different encodings" do
+ ''.to_sym.should.casecmp?(''.encode("UTF-32LE").to_sym)
end
end
diff --git a/spec/ruby/core/symbol/comparison_spec.rb b/spec/ruby/core/symbol/comparison_spec.rb
index 91edd1f0d9..6d56176e97 100644
--- a/spec/ruby/core/symbol/comparison_spec.rb
+++ b/spec/ruby/core/symbol/comparison_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Symbol#<=> with Symbol" do
it "compares individual characters based on their ascii value" do
@@ -37,15 +37,15 @@ end
describe "Symbol#<=>" do
it "returns nil if other is a String" do
- (:abc <=> "abc").should be_nil
+ (:abc <=> "abc").should == nil
end
- it "returns nil if other is a Fixnum" do
- (:abc <=> 1).should be_nil
+ it "returns nil if other is an Integer" do
+ (:abc <=> 1).should == nil
end
it "returns nil if other is an object" do
obj = mock("string <=>")
- (:abc <=> obj).should be_nil
+ (:abc <=> obj).should == nil
end
end
diff --git a/spec/ruby/core/symbol/downcase_spec.rb b/spec/ruby/core/symbol/downcase_spec.rb
index 6eb19e087a..76418aa9da 100644
--- a/spec/ruby/core/symbol/downcase_spec.rb
+++ b/spec/ruby/core/symbol/downcase_spec.rb
@@ -1,9 +1,9 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Symbol#downcase" do
it "returns a Symbol" do
- :glark.downcase.should be_an_instance_of(Symbol)
+ :glark.downcase.should.instance_of?(Symbol)
end
it "converts uppercase ASCII characters to their lowercase equivalents" do
@@ -14,17 +14,9 @@ describe "Symbol#downcase" do
"\u{E0}Bc".to_sym.downcase.should == :"àbc"
end
- ruby_version_is ''...'2.4' do
- it "leaves uppercase Unicode characters as they were" do
- "\u{DE}Bc".to_sym.downcase.should == :"Þbc"
- end
- end
-
- ruby_version_is '2.4' do
- it "uncapitalizes all Unicode characters" do
- "ÄÖÜ".to_sym.downcase.should == :"äöü"
- "AOU".to_sym.downcase.should == :"aou"
- end
+ it "uncapitalizes all Unicode characters" do
+ "ÄÖÜ".to_sym.downcase.should == :"äöü"
+ "AOU".to_sym.downcase.should == :"aou"
end
it "leaves non-alphabetic ASCII characters as they were" do
diff --git a/spec/ruby/core/symbol/dup_spec.rb b/spec/ruby/core/symbol/dup_spec.rb
index 2ca4d84078..eef3078030 100644
--- a/spec/ruby/core/symbol/dup_spec.rb
+++ b/spec/ruby/core/symbol/dup_spec.rb
@@ -1,9 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
-ruby_version_is '2.4' do
- describe "Symbol#dup" do
- it "returns self" do
- :a_symbol.dup.should equal(:a_symbol)
- end
+describe "Symbol#dup" do
+ it "returns self" do
+ :a_symbol.dup.should.equal?(:a_symbol)
end
end
diff --git a/spec/ruby/core/symbol/element_reference_spec.rb b/spec/ruby/core/symbol/element_reference_spec.rb
index 4116274ee0..360a661891 100644
--- a/spec/ruby/core/symbol/element_reference_spec.rb
+++ b/spec/ruby/core/symbol/element_reference_spec.rb
@@ -1,6 +1,263 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/slice.rb', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Symbol#[]" do
- it_behaves_like(:symbol_slice, :[])
+ describe "with an Integer index" do
+ it "returns the character code of the element at the index" do
+ :symbol[1].should == ?y
+ end
+
+ it "returns nil if the index starts from the end and is greater than the length" do
+ :symbol[-10].should == nil
+ end
+
+ it "returns nil if the index is greater than the length" do
+ :symbol[42].should == nil
+ end
+ end
+
+ describe "with an Integer index and length" do
+ describe "and a positive index and length" do
+ it "returns a slice" do
+ :symbol[1, 3].should == "ymb"
+ end
+
+ it "returns a blank slice if the length is 0" do
+ :symbol[0, 0].should == ""
+ :symbol[1, 0].should == ""
+ end
+
+ it "returns a slice of all remaining characters if the given length is greater than the actual length" do
+ :symbol[1, 100].should == "ymbol"
+ end
+
+ it "returns nil if the index is greater than the length" do
+ :symbol[10, 1].should == nil
+ end
+ end
+
+ describe "and a positive index and negative length" do
+ it "returns nil" do
+ :symbol[0, -1].should == nil
+ :symbol[1, -1].should == nil
+ end
+ end
+
+ describe "and a negative index and positive length" do
+ it "returns a slice starting from the end upto the length" do
+ :symbol[-3, 2].should == "bo"
+ end
+
+ it "returns a blank slice if the length is 0" do
+ :symbol[-1, 0].should == ""
+ end
+
+ it "returns a slice of all remaining characters if the given length is larger than the actual length" do
+ :symbol[-4, 100].should == "mbol"
+ end
+
+ it "returns nil if the index is past the start" do
+ :symbol[-10, 1].should == nil
+ end
+ end
+
+ describe "and a negative index and negative length" do
+ it "returns nil" do
+ :symbol[-1, -1].should == nil
+ end
+ end
+
+ describe "and a Float length" do
+ it "converts the length to an Integer" do
+ :symbol[2, 2.5].should == "mb"
+ end
+ end
+
+ describe "and a nil length" do
+ it "raises a TypeError" do
+ -> { :symbol[1, nil] }.should.raise(TypeError)
+ end
+ end
+
+ describe "and a length that cannot be converted into an Integer" do
+ it "raises a TypeError when given an Array" do
+ -> { :symbol[1, Array.new] }.should.raise(TypeError)
+ end
+
+ it "raises a TypeError when given an Hash" do
+ -> { :symbol[1, Hash.new] }.should.raise(TypeError)
+ end
+
+ it "raises a TypeError when given an Object" do
+ -> { :symbol[1, Object.new] }.should.raise(TypeError)
+ end
+ end
+ end
+
+ describe "with a Float index" do
+ it "converts the index to an Integer" do
+ :symbol[1.5].should == ?y
+ end
+ end
+
+ describe "with a nil index" do
+ it "raises a TypeError" do
+ -> { :symbol[nil] }.should.raise(TypeError)
+ end
+ end
+
+ describe "with an index that cannot be converted into an Integer" do
+ it "raises a TypeError when given an Array" do
+ -> { :symbol[Array.new] }.should.raise(TypeError)
+ end
+
+ it "raises a TypeError when given an Hash" do
+ -> { :symbol[Hash.new] }.should.raise(TypeError)
+ end
+
+ it "raises a TypeError when given an Object" do
+ -> { :symbol[Object.new] }.should.raise(TypeError)
+ end
+ end
+
+ describe "with a Range slice" do
+ describe "that is within bounds" do
+ it "returns a slice if both range values begin at the start and are within bounds" do
+ :symbol[1..4].should == "ymbo"
+ end
+
+ it "returns a slice if the first range value begins at the start and the last begins at the end" do
+ :symbol[1..-1].should == "ymbol"
+ end
+
+ it "returns a slice if the first range value begins at the end and the last begins at the end" do
+ :symbol[-4..-1].should == "mbol"
+ end
+ end
+
+ describe "that is out of bounds" do
+ it "returns nil if the first range value begins past the end" do
+ :symbol[10..12].should == nil
+ end
+
+ it "returns a blank string if the first range value is within bounds and the last range value is not" do
+ :symbol[-2..-10].should == ""
+ :symbol[2..-10].should == ""
+ end
+
+ it "returns nil if the first range value starts from the end and is within bounds and the last value starts from the end and is greater than the length" do
+ :symbol[-10..-12].should == nil
+ end
+
+ it "returns nil if the first range value starts from the end and is out of bounds and the last value starts from the end and is less than the length" do
+ :symbol[-10..-2].should == nil
+ end
+ end
+
+ describe "with Float values" do
+ it "converts the first value to an Integer" do
+ :symbol[0.5..2].should == "sym"
+ end
+
+ it "converts the last value to an Integer" do
+ :symbol[0..2.5].should == "sym"
+ end
+ end
+ end
+
+ describe "with a Range subclass slice" do
+ it "returns a slice" do
+ range = SymbolSpecs::MyRange.new(1, 4)
+ :symbol[range].should == "ymbo"
+ end
+ end
+
+ describe "with a Regex slice" do
+ describe "without a capture index" do
+ it "returns a string of the match" do
+ :symbol[/[^bol]+/].should == "sym"
+ end
+
+ it "returns nil if the expression does not match" do
+ :symbol[/0-9/].should == nil
+ end
+
+ it "sets $~ to the MatchData if there is a match" do
+ :symbol[/[^bol]+/]
+ $~[0].should == "sym"
+ end
+
+ it "does not set $~ if there if there is not a match" do
+ :symbol[/[0-9]+/]
+ $~.should == nil
+ end
+ end
+
+ describe "with a capture index" do
+ it "returns a string of the complete match if the capture index is 0" do
+ :symbol[/(sy)(mb)(ol)/, 0].should == "symbol"
+ end
+
+ it "returns a string for the matched capture at the given index" do
+ :symbol[/(sy)(mb)(ol)/, 1].should == "sy"
+ :symbol[/(sy)(mb)(ol)/, -1].should == "ol"
+ end
+
+ it "returns nil if there is no capture for the index" do
+ :symbol[/(sy)(mb)(ol)/, 4].should == nil
+ :symbol[/(sy)(mb)(ol)/, -4].should == nil
+ end
+
+ it "converts the index to an Integer" do
+ :symbol[/(sy)(mb)(ol)/, 1.5].should == "sy"
+ end
+
+ describe "and an index that cannot be converted to an Integer" do
+ it "raises a TypeError when given an Hash" do
+ -> { :symbol[/(sy)(mb)(ol)/, Hash.new] }.should.raise(TypeError)
+ end
+
+ it "raises a TypeError when given an Array" do
+ -> { :symbol[/(sy)(mb)(ol)/, Array.new] }.should.raise(TypeError)
+ end
+
+ it "raises a TypeError when given an Object" do
+ -> { :symbol[/(sy)(mb)(ol)/, Object.new] }.should.raise(TypeError)
+ end
+ end
+
+ it "raises a TypeError if the index is nil" do
+ -> { :symbol[/(sy)(mb)(ol)/, nil] }.should.raise(TypeError)
+ end
+
+ it "sets $~ to the MatchData if there is a match" do
+ :symbol[/(sy)(mb)(ol)/, 0]
+ $~[0].should == "symbol"
+ $~[1].should == "sy"
+ $~[2].should == "mb"
+ $~[3].should == "ol"
+ end
+
+ it "does not set $~ to the MatchData if there is not a match" do
+ :symbol[/0-9/, 0]
+ $~.should == nil
+ end
+ end
+ end
+
+ describe "with a String slice" do
+ it "does not set $~" do
+ $~ = nil
+ :symbol["sym"]
+ $~.should == nil
+ end
+
+ it "returns a string if there is match" do
+ :symbol["ymb"].should == "ymb"
+ end
+
+ it "returns nil if there is not a match" do
+ :symbol["foo"].should == nil
+ end
+ end
end
diff --git a/spec/ruby/core/symbol/empty_spec.rb b/spec/ruby/core/symbol/empty_spec.rb
index 7be0007355..1d90a59a5b 100644
--- a/spec/ruby/core/symbol/empty_spec.rb
+++ b/spec/ruby/core/symbol/empty_spec.rb
@@ -1,11 +1,11 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Symbol#empty?" do
it "returns true if self is empty" do
- :"".empty?.should be_true
+ :"".empty?.should == true
end
it "returns false if self is non-empty" do
- :"a".empty?.should be_false
+ :"a".empty?.should == false
end
end
diff --git a/spec/ruby/core/symbol/encoding_spec.rb b/spec/ruby/core/symbol/encoding_spec.rb
index b6128562b9..732fd62e26 100644
--- a/spec/ruby/core/symbol/encoding_spec.rb
+++ b/spec/ruby/core/symbol/encoding_spec.rb
@@ -1,6 +1,6 @@
# encoding: utf-8
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Symbol#encoding for ASCII symbols" do
it "is US-ASCII" do
diff --git a/spec/ruby/core/symbol/end_with_spec.rb b/spec/ruby/core/symbol/end_with_spec.rb
new file mode 100644
index 0000000000..4b9f5a4996
--- /dev/null
+++ b/spec/ruby/core/symbol/end_with_spec.rb
@@ -0,0 +1,8 @@
+# -*- encoding: utf-8 -*-
+
+require_relative '../../spec_helper'
+require_relative '../../shared/string/end_with'
+
+describe "Symbol#end_with?" do
+ it_behaves_like :end_with, :to_sym
+end
diff --git a/spec/ruby/core/symbol/equal_value_spec.rb b/spec/ruby/core/symbol/equal_value_spec.rb
index 7c305fab39..3fe997d02a 100644
--- a/spec/ruby/core/symbol/equal_value_spec.rb
+++ b/spec/ruby/core/symbol/equal_value_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Symbol#==" do
it "only returns true when the other is exactly the same symbol" do
diff --git a/spec/ruby/core/symbol/id2name_spec.rb b/spec/ruby/core/symbol/id2name_spec.rb
index 932dd7171d..abcbff65f4 100644
--- a/spec/ruby/core/symbol/id2name_spec.rb
+++ b/spec/ruby/core/symbol/id2name_spec.rb
@@ -1,6 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/id2name', __FILE__)
+require_relative '../../spec_helper'
describe "Symbol#id2name" do
- it_behaves_like(:symbol_id2name, :id2name)
+ it "is an alias of Symbol#to_s" do
+ Symbol.instance_method(:id2name).should == Symbol.instance_method(:to_s)
+ end
end
diff --git a/spec/ruby/core/symbol/inspect_spec.rb b/spec/ruby/core/symbol/inspect_spec.rb
index dead6e34fc..f2269996af 100644
--- a/spec/ruby/core/symbol/inspect_spec.rb
+++ b/spec/ruby/core/symbol/inspect_spec.rb
@@ -1,10 +1,12 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Symbol#inspect" do
symbols = {
fred: ":fred",
:fred? => ":fred?",
:fred! => ":fred!",
+ :BAD! => ":BAD!",
+ :_BAD! => ":_BAD!",
:$ruby => ":$ruby",
:@ruby => ":@ruby",
:@@ruby => ":@@ruby",
@@ -64,9 +66,9 @@ describe "Symbol#inspect" do
:~ => ":~",
:| => ":|",
- :"!" => [":\"!\"", ":!" ],
- :"!=" => [":\"!=\"", ":!="],
- :"!~" => [":\"!~\"", ":!~"],
+ :"!" => ":!",
+ :"!=" => ":!=",
+ :"!~" => ":!~",
:"\$" => ":\"$\"", # for justice!
:"&&" => ":\"&&\"",
:"'" => ":\"\'\"",
@@ -94,12 +96,36 @@ describe "Symbol#inspect" do
:"foo " => ":\"foo \"",
:" foo" => ":\" foo\"",
:" " => ":\" \"",
+
+ :"ê" => [":ê", ":\"\\u00EA\""],
+ :"测" => [":测", ":\"\\u6D4B\""],
+ :"🦊" => [":🦊", ":\"\\u{1F98A}\""],
}
+ expected_by_encoding = Encoding::default_external == Encoding::UTF_8 ? 0 : 1
symbols.each do |input, expected|
- expected = expected[1] if expected.is_a?(Array)
+ expected = expected[expected_by_encoding] if expected.is_a?(Array)
it "returns self as a symbol literal for #{expected}" do
input.inspect.should == expected
end
end
+
+ it "quotes BINARY symbols" do
+ sym = "foo\xA4".b.to_sym
+ sym.inspect.should == ':"foo\xA4"'
+ end
+
+ it "quotes symbols in non-ASCII-compatible encodings" do
+ Encoding.list.reject(&:ascii_compatible?).reject(&:dummy?).each do |encoding|
+ sym = "foo".encode(encoding).to_sym
+ sym.inspect.should == ':"foo"'
+ end
+ end
+
+ it "quotes and escapes symbols in dummy encodings" do
+ Encoding.list.select(&:dummy?).each do |encoding|
+ sym = "abcd".dup.force_encoding(encoding).to_sym
+ sym.inspect.should == ':"\x61\x62\x63\x64"'
+ end
+ end
end
diff --git a/spec/ruby/core/symbol/intern_spec.rb b/spec/ruby/core/symbol/intern_spec.rb
index c1ac5aeac1..746d313d40 100644
--- a/spec/ruby/core/symbol/intern_spec.rb
+++ b/spec/ruby/core/symbol/intern_spec.rb
@@ -1,11 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Symbol#intern" do
- it "returns self" do
- :foo.intern.should == :foo
- end
-
- it "returns a Symbol" do
- :foo.intern.should be_kind_of(Symbol)
+ it "is an alias of Symbol#to_sym" do
+ Symbol.instance_method(:intern).should == Symbol.instance_method(:to_sym)
end
end
diff --git a/spec/ruby/core/symbol/length_spec.rb b/spec/ruby/core/symbol/length_spec.rb
index e7e0700d5a..29dd4ad46b 100644
--- a/spec/ruby/core/symbol/length_spec.rb
+++ b/spec/ruby/core/symbol/length_spec.rb
@@ -1,6 +1,23 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/length', __FILE__)
+require_relative '../../spec_helper'
describe "Symbol#length" do
- it_behaves_like :symbol_length, :length
+ it "returns 0 for empty name" do
+ :''.length.should == 0
+ end
+
+ it "returns 1 for name formed by a NUL character" do
+ :"\x00".length.should == 1
+ end
+
+ it "returns 3 for name formed by 3 ASCII characters" do
+ :one.length.should == 3
+ end
+
+ it "returns 4 for name formed by 4 ASCII characters" do
+ :four.length.should == 4
+ end
+
+ it "returns 4 for name formed by 1 multibyte and 3 ASCII characters" do
+ :"\xC3\x9Cber".length.should == 4
+ end
end
diff --git a/spec/ruby/core/symbol/match_spec.rb b/spec/ruby/core/symbol/match_spec.rb
index 768e3b00da..7b165218c6 100644
--- a/spec/ruby/core/symbol/match_spec.rb
+++ b/spec/ruby/core/symbol/match_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe :symbol_match, shared: true do
it "returns the index of the beginning of the match" do
@@ -6,7 +6,7 @@ describe :symbol_match, shared: true do
end
it "returns nil if there is no match" do
- :a.send(@method, /b/).should be_nil
+ :a.send(@method, /b/).should == nil
end
it "sets the last match pseudo-variables" do
@@ -19,52 +19,59 @@ describe "Symbol#=~" do
it_behaves_like :symbol_match, :=~
end
-ruby_version_is ""..."2.4" do
- describe "Symbol#match" do
- it_behaves_like :symbol_match, :match
+describe "Symbol#match" do
+ it "returns the MatchData" do
+ result = :abc.match(/b/)
+ result.should.is_a?(MatchData)
+ result[0].should == 'b'
+ end
+
+ it "returns nil if there is no match" do
+ :a.match(/b/).should == nil
+ end
+
+ it "sets the last match pseudo-variables" do
+ :a.match(/(.)/)[0].should == 'a'
+ $1.should == "a"
end
-end
-ruby_version_is "2.4" do
- describe "Symbol#match" do
- it "returns the MatchData" do
- result = :abc.match(/b/)
- result.should be_kind_of(MatchData)
- result[0].should == 'b'
+ describe "when passed a block" do
+ it "yields the MatchData" do
+ :abc.match(/./) {|m| ScratchPad.record m }
+ ScratchPad.recorded.should.is_a?(MatchData)
end
- it "returns nil if there is no match" do
- :a.match(/b/).should be_nil
+ it "returns the block result" do
+ :abc.match(/./) { :result }.should == :result
end
- it "sets the last match pseudo-variables" do
- :a.match(/(.)/)[0].should == 'a'
- $1.should == "a"
+ it "does not yield if there is no match" do
+ ScratchPad.record []
+ :b.match(/a/) {|m| ScratchPad << m }
+ ScratchPad.recorded.should == []
end
end
end
-ruby_version_is "2.4" do
- describe "Symbol#match?" do
- before :each do
- # Resetting Regexp.last_match
- /DONTMATCH/.match ''
- end
+describe "Symbol#match?" do
+ before :each do
+ # Resetting Regexp.last_match
+ /DONTMATCH/.match ''
+ end
- context "when matches the given regex" do
- it "returns true but does not set Regexp.last_match" do
- :string.match?(/string/i).should be_true
- Regexp.last_match.should be_nil
- end
+ context "when matches the given regex" do
+ it "returns true but does not set Regexp.last_match" do
+ :string.match?(/string/i).should == true
+ Regexp.last_match.should == nil
end
+ end
- it "returns false when does not match the given regex" do
- :string.match?(/STRING/).should be_false
- end
+ it "returns false when does not match the given regex" do
+ :string.match?(/STRING/).should == false
+ end
- it "takes matching position as the 2nd argument" do
- :string.match?(/str/i, 0).should be_true
- :string.match?(/str/i, 1).should be_false
- end
+ it "takes matching position as the 2nd argument" do
+ :string.match?(/str/i, 0).should == true
+ :string.match?(/str/i, 1).should == false
end
end
diff --git a/spec/ruby/core/symbol/name_spec.rb b/spec/ruby/core/symbol/name_spec.rb
new file mode 100644
index 0000000000..f9b631266c
--- /dev/null
+++ b/spec/ruby/core/symbol/name_spec.rb
@@ -0,0 +1,17 @@
+require_relative '../../spec_helper'
+
+describe "Symbol#name" do
+ it "returns string" do
+ :ruby.name.should == "ruby"
+ :ルビー.name.should == "ルビー"
+ end
+
+ it "returns same string instance" do
+ :"ruby_3".name.should.equal?(:ruby_3.name)
+ :"ruby_#{1+2}".name.should.equal?(:ruby_3.name)
+ end
+
+ it "returns frozen string" do
+ :symbol.name.should.frozen?
+ end
+end
diff --git a/spec/ruby/core/symbol/next_spec.rb b/spec/ruby/core/symbol/next_spec.rb
index 65ffbebd40..e80bbaa508 100644
--- a/spec/ruby/core/symbol/next_spec.rb
+++ b/spec/ruby/core/symbol/next_spec.rb
@@ -1,6 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/succ', __FILE__)
+require_relative '../../spec_helper'
describe "Symbol#next" do
- it_behaves_like :symbol_succ, :next
+ it "is an alias of Symbol#succ" do
+ Symbol.instance_method(:next).should == Symbol.instance_method(:succ)
+ end
end
diff --git a/spec/ruby/core/symbol/shared/id2name.rb b/spec/ruby/core/symbol/shared/id2name.rb
deleted file mode 100644
index 47f97bd332..0000000000
--- a/spec/ruby/core/symbol/shared/id2name.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-describe :symbol_id2name, shared: true do
- it "returns the string corresponding to self" do
- :rubinius.send(@method).should == "rubinius"
- :squash.send(@method).should == "squash"
- :[].send(@method).should == "[]"
- :@ruby.send(@method).should == "@ruby"
- :@@ruby.send(@method).should == "@@ruby"
- end
-end
diff --git a/spec/ruby/core/symbol/shared/length.rb b/spec/ruby/core/symbol/shared/length.rb
deleted file mode 100644
index 692e8c57e3..0000000000
--- a/spec/ruby/core/symbol/shared/length.rb
+++ /dev/null
@@ -1,23 +0,0 @@
-# -*- encoding: utf-8 -*-
-
-describe :symbol_length, shared: true do
- it "returns 0 for empty name" do
- :''.send(@method).should == 0
- end
-
- it "returns 1 for name formed by a NUL character" do
- :"\x00".send(@method).should == 1
- end
-
- it "returns 3 for name formed by 3 ASCII characters" do
- :one.send(@method).should == 3
- end
-
- it "returns 4 for name formed by 4 ASCII characters" do
- :four.send(@method).should == 4
- end
-
- it "returns 4 for name formed by 1 multibyte and 3 ASCII characters" do
- :"\xC3\x9Cber".send(@method).should == 4
- end
-end
diff --git a/spec/ruby/core/symbol/shared/slice.rb b/spec/ruby/core/symbol/shared/slice.rb
deleted file mode 100644
index d39b02f319..0000000000
--- a/spec/ruby/core/symbol/shared/slice.rb
+++ /dev/null
@@ -1,278 +0,0 @@
-require File.expand_path('../../fixtures/classes.rb', __FILE__)
-
-describe :symbol_slice, shared: true do
- describe "with an Integer index" do
- it "returns the character code of the element at the index" do
- :symbol.send(@method, 1).should == ?y
- end
-
- it "returns nil if the index starts from the end and is greater than the length" do
- :symbol.send(@method, -10).should be_nil
- end
-
- it "returns nil if the index is greater than the length" do
- :symbol.send(@method, 42).should be_nil
- end
- end
-
- describe "with an Integer index and length" do
- describe "and a positive index and length" do
- it "returns a slice" do
- :symbol.send(@method, 1,3).should == "ymb"
- end
-
- it "returns a blank slice if the length is 0" do
- :symbol.send(@method, 0,0).should == ""
- :symbol.send(@method, 1,0).should == ""
- end
-
- it "returns a slice of all remaining characters if the given length is greater than the actual length" do
- :symbol.send(@method, 1,100).should == "ymbol"
- end
-
- it "returns nil if the index is greater than the length" do
- :symbol.send(@method, 10,1).should be_nil
- end
- end
-
- describe "and a positive index and negative length" do
- it "returns nil" do
- :symbol.send(@method, 0,-1).should be_nil
- :symbol.send(@method, 1,-1).should be_nil
- end
- end
-
- describe "and a negative index and positive length" do
- it "returns a slice starting from the end upto the length" do
- :symbol.send(@method, -3,2).should == "bo"
- end
-
- it "returns a blank slice if the length is 0" do
- :symbol.send(@method, -1,0).should == ""
- end
-
- it "returns a slice of all remaining characters if the given length is larger than the actual length" do
- :symbol.send(@method, -4,100).should == "mbol"
- end
-
- it "returns nil if the index is past the start" do
- :symbol.send(@method, -10,1).should be_nil
- end
- end
-
- describe "and a negative index and negative length" do
- it "returns nil" do
- :symbol.send(@method, -1,-1).should be_nil
- end
- end
-
- describe "and a Float length" do
- it "converts the length to an Integer" do
- :symbol.send(@method, 2,2.5).should == "mb"
- end
- end
-
- describe "and a nil length" do
- it "raises a TypeError" do
- lambda { :symbol.send(@method, 1,nil) }.should raise_error(TypeError)
- end
- end
-
- describe "and a length that cannot be converted into an Integer" do
- it "raises a TypeError when given an Array" do
- lambda { :symbol.send(@method, 1,Array.new) }.should raise_error(TypeError)
- end
-
- it "raises a TypeError when given an Hash" do
- lambda { :symbol.send(@method, 1,Hash.new) }.should raise_error(TypeError)
- end
-
- it "raises a TypeError when given an Object" do
- lambda { :symbol.send(@method, 1,Object.new) }.should raise_error(TypeError)
- end
- end
- end
-
- describe "with a Float index" do
- it "converts the index to an Integer" do
- :symbol.send(@method, 1.5).should == ?y
- end
- end
-
- describe "with a nil index" do
- it "raises a TypeError" do
- lambda { :symbol.send(@method, nil) }.should raise_error(TypeError)
- end
- end
-
- describe "with an index that cannot be converted into an Integer" do
- it "raises a TypeError when given an Array" do
- lambda { :symbol.send(@method, Array.new) }.should raise_error(TypeError)
- end
-
- it "raises a TypeError when given an Hash" do
- lambda { :symbol.send(@method, Hash.new) }.should raise_error(TypeError)
- end
-
- it "raises a TypeError when given an Object" do
- lambda { :symbol.send(@method, Object.new) }.should raise_error(TypeError)
- end
- end
-
- describe "with a Range slice" do
- describe "that is within bounds" do
- it "returns a slice if both range values begin at the start and are within bounds" do
- :symbol.send(@method, 1..4).should == "ymbo"
- end
-
- it "returns a slice if the first range value begins at the start and the last begins at the end" do
- :symbol.send(@method, 1..-1).should == "ymbol"
- end
-
- it "returns a slice if the first range value begins at the end and the last begins at the end" do
- :symbol.send(@method, -4..-1).should == "mbol"
- end
- end
-
- describe "that is out of bounds" do
- it "returns nil if the first range value begins past the end" do
- :symbol.send(@method, 10..12).should be_nil
- end
-
- it "returns a blank string if the first range value is within bounds and the last range value is not" do
- :symbol.send(@method, -2..-10).should == ""
- :symbol.send(@method, 2..-10).should == ""
- end
-
- it "returns nil if the first range value starts from the end and is within bounds and the last value starts from the end and is greater than the length" do
- :symbol.send(@method, -10..-12).should be_nil
- end
-
- it "returns nil if the first range value starts from the end and is out of bounds and the last value starts from the end and is less than the length" do
- :symbol.send(@method, -10..-2).should be_nil
- end
- end
-
- describe "with Float values" do
- it "converts the first value to an Integer" do
- :symbol.send(@method, 0.5..2).should == "sym"
- end
-
- it "converts the last value to an Integer" do
- :symbol.send(@method, 0..2.5).should == "sym"
- end
- end
- end
-
- describe "with a Range subclass slice" do
- it "returns a slice" do
- range = SymbolSpecs::MyRange.new(1, 4)
- :symbol.send(@method, range).should == "ymbo"
- end
- end
-
- describe "with a Regex slice" do
- describe "without a capture index" do
- it "returns a string of the match" do
- :symbol.send(@method, /[^bol]+/).should == "sym"
- end
-
- it "returns nil if the expression does not match" do
- :symbol.send(@method, /0-9/).should be_nil
- end
-
- it "sets $~ to the MatchData if there is a match" do
- :symbol.send(@method, /[^bol]+/)
- $~[0].should == "sym"
- end
-
- it "does not set $~ if there if there is not a match" do
- :symbol.send(@method, /[0-9]+/)
- $~.should be_nil
- end
-
- it "returns a tainted string if the regexp is tainted" do
- :symbol.send(@method, /./.taint).tainted?.should be_true
- end
-
- it "returns an untrusted string if the regexp is untrusted" do
- :symbol.send(@method, /./.untrust).untrusted?.should be_true
- end
- end
-
- describe "with a capture index" do
- it "returns a string of the complete match if the capture index is 0" do
- :symbol.send(@method, /(sy)(mb)(ol)/, 0).should == "symbol"
- end
-
- it "returns a string for the matched capture at the given index" do
- :symbol.send(@method, /(sy)(mb)(ol)/, 1).should == "sy"
- :symbol.send(@method, /(sy)(mb)(ol)/, -1).should == "ol"
- end
-
- it "returns nil if there is no capture for the index" do
- :symbol.send(@method, /(sy)(mb)(ol)/, 4).should be_nil
- :symbol.send(@method, /(sy)(mb)(ol)/, -4).should be_nil
- end
-
- it "converts the index to an Integer" do
- :symbol.send(@method, /(sy)(mb)(ol)/, 1.5).should == "sy"
- end
-
- it "returns a tainted string if the regexp is tainted" do
- :symbol.send(@method, /(.)/.taint, 1).tainted?.should be_true
- end
-
- it "returns an untrusted string if the regexp is untrusted" do
- :symbol.send(@method, /(.)/.untrust, 1).untrusted?.should be_true
- end
-
- describe "and an index that cannot be converted to an Integer" do
- it "raises a TypeError when given an Hash" do
- lambda { :symbol.send(@method, /(sy)(mb)(ol)/, Hash.new) }.should raise_error(TypeError)
- end
-
- it "raises a TypeError when given an Array" do
- lambda { :symbol.send(@method, /(sy)(mb)(ol)/, Array.new) }.should raise_error(TypeError)
- end
-
- it "raises a TypeError when given an Object" do
- lambda { :symbol.send(@method, /(sy)(mb)(ol)/, Object.new) }.should raise_error(TypeError)
- end
- end
-
- it "raises a TypeError if the index is nil" do
- lambda { :symbol.send(@method, /(sy)(mb)(ol)/, nil) }.should raise_error(TypeError)
- end
-
- it "sets $~ to the MatchData if there is a match" do
- :symbol.send(@method, /(sy)(mb)(ol)/, 0)
- $~[0].should == "symbol"
- $~[1].should == "sy"
- $~[2].should == "mb"
- $~[3].should == "ol"
- end
-
- it "does not set $~ to the MatchData if there is not a match" do
- :symbol.send(@method, /0-9/, 0)
- $~.should be_nil
- end
- end
- end
-
- describe "with a String slice" do
- it "does not set $~" do
- $~ = nil
- :symbol.send(@method, "sym")
- $~.should be_nil
- end
-
- it "returns a string if there is match" do
- :symbol.send(@method, "ymb").should == "ymb"
- end
-
- it "returns nil if there is not a match" do
- :symbol.send(@method, "foo").should be_nil
- end
- end
-end
diff --git a/spec/ruby/core/symbol/shared/succ.rb b/spec/ruby/core/symbol/shared/succ.rb
deleted file mode 100644
index 0e371490f9..0000000000
--- a/spec/ruby/core/symbol/shared/succ.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-
-describe :symbol_succ, shared: true do
- it "returns a successor" do
- :abcd.send(@method).should == :abce
- :THX1138.send(@method).should == :THX1139
- end
-
- it "propagates a 'carry'" do
- :"1999zzz".send(@method).should == :"2000aaa"
- :ZZZ9999.send(@method).should == :AAAA0000
- end
-
- it "increments non-alphanumeric characters when no alphanumeric characters are present" do
- :"<<koala>>".send(@method).should == :"<<koalb>>"
- :"***".send(@method).should == :"**+"
- end
-end
diff --git a/spec/ruby/core/symbol/size_spec.rb b/spec/ruby/core/symbol/size_spec.rb
index a6dfe092ec..b5d375b3aa 100644
--- a/spec/ruby/core/symbol/size_spec.rb
+++ b/spec/ruby/core/symbol/size_spec.rb
@@ -1,6 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/length', __FILE__)
+require_relative '../../spec_helper'
describe "Symbol#size" do
- it_behaves_like :symbol_length, :size
+ it "is an alias of Symbol#length" do
+ Symbol.instance_method(:size).should == Symbol.instance_method(:length)
+ end
end
diff --git a/spec/ruby/core/symbol/slice_spec.rb b/spec/ruby/core/symbol/slice_spec.rb
index 3c535ac4b0..050a2cf38c 100644
--- a/spec/ruby/core/symbol/slice_spec.rb
+++ b/spec/ruby/core/symbol/slice_spec.rb
@@ -1,6 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/slice.rb', __FILE__)
+require_relative '../../spec_helper'
describe "Symbol#slice" do
- it_behaves_like(:symbol_slice, :slice)
+ it "is an alias of Symbol#[]" do
+ Symbol.instance_method(:slice).should == Symbol.instance_method(:[])
+ end
end
diff --git a/spec/ruby/core/symbol/start_with_spec.rb b/spec/ruby/core/symbol/start_with_spec.rb
new file mode 100644
index 0000000000..cd43279003
--- /dev/null
+++ b/spec/ruby/core/symbol/start_with_spec.rb
@@ -0,0 +1,8 @@
+# -*- encoding: utf-8 -*-
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative '../../shared/string/start_with'
+
+describe "Symbol#start_with?" do
+ it_behaves_like :start_with, :to_sym
+end
diff --git a/spec/ruby/core/symbol/succ_spec.rb b/spec/ruby/core/symbol/succ_spec.rb
index 21bfb7e4aa..893164a2a6 100644
--- a/spec/ruby/core/symbol/succ_spec.rb
+++ b/spec/ruby/core/symbol/succ_spec.rb
@@ -1,6 +1,18 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/succ', __FILE__)
+require_relative '../../spec_helper'
describe "Symbol#succ" do
- it_behaves_like :symbol_succ, :succ
+ it "returns a successor" do
+ :abcd.succ.should == :abce
+ :THX1138.succ.should == :THX1139
+ end
+
+ it "propagates a 'carry'" do
+ :"1999zzz".succ.should == :"2000aaa"
+ :ZZZ9999.succ.should == :AAAA0000
+ end
+
+ it "increments non-alphanumeric characters when no alphanumeric characters are present" do
+ :"<<koala>>".succ.should == :"<<koalb>>"
+ :"***".succ.should == :"**+"
+ end
end
diff --git a/spec/ruby/core/symbol/swapcase_spec.rb b/spec/ruby/core/symbol/swapcase_spec.rb
index 3124f782bc..95fc29e32b 100644
--- a/spec/ruby/core/symbol/swapcase_spec.rb
+++ b/spec/ruby/core/symbol/swapcase_spec.rb
@@ -1,9 +1,9 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Symbol#swapcase" do
it "returns a Symbol" do
- :glark.swapcase.should be_an_instance_of(Symbol)
+ :glark.swapcase.should.instance_of?(Symbol)
end
it "converts lowercase ASCII characters to their uppercase equivalents" do
@@ -18,21 +18,9 @@ describe "Symbol#swapcase" do
:mIxEd.swapcase.should == :MiXeD
end
- ruby_version_is ''...'2.4' do
- it "leaves uppercase Unicode characters as they were" do
- "\u{00DE}Bc".to_sym.swapcase.should == :"ÞbC"
- end
-
- it "leaves lowercase Unicode characters as they were" do
- "\u{00DF}Bc".to_sym.swapcase.should == :"ßbC"
- end
- end
-
- ruby_version_is '2.4' do
- it "swaps the case for Unicode characters" do
- "äÖü".to_sym.swapcase.should == :"ÄöÜ"
- "aOu".to_sym.swapcase.should == :"AoU"
- end
+ it "swaps the case for Unicode characters" do
+ "äÖü".to_sym.swapcase.should == :"ÄöÜ"
+ "aOu".to_sym.swapcase.should == :"AoU"
end
it "leaves non-alphabetic ASCII characters as they were" do
diff --git a/spec/ruby/core/symbol/symbol_spec.rb b/spec/ruby/core/symbol/symbol_spec.rb
index af6b46fed3..3534686a08 100644
--- a/spec/ruby/core/symbol/symbol_spec.rb
+++ b/spec/ruby/core/symbol/symbol_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Symbol" do
it "includes Comparable" do
@@ -6,14 +6,14 @@ describe "Symbol" do
end
it ".allocate raises a TypeError" do
- lambda do
+ -> do
Symbol.allocate
- end.should raise_error(TypeError)
+ end.should.raise(TypeError)
end
it ".new is undefined" do
- lambda do
+ -> do
Symbol.new
- end.should raise_error(NoMethodError)
+ end.should.raise(NoMethodError)
end
end
diff --git a/spec/ruby/core/symbol/to_proc_spec.rb b/spec/ruby/core/symbol/to_proc_spec.rb
index be625994d9..93ed1e9e9b 100644
--- a/spec/ruby/core/symbol/to_proc_spec.rb
+++ b/spec/ruby/core/symbol/to_proc_spec.rb
@@ -1,9 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Symbol#to_proc" do
it "returns a new Proc" do
proc = :to_s.to_proc
- proc.should be_kind_of(Proc)
+ proc.should.is_a?(Proc)
end
it "sends self to arguments passed when calling #call on the Proc" do
@@ -12,19 +12,54 @@ describe "Symbol#to_proc" do
:to_s.to_proc.call(obj).should == "Received #to_s"
end
- it "raises an ArgumentError when calling #call on the Proc without receiver" do
- lambda { :object_id.to_proc.call }.should raise_error(ArgumentError)
+ it "returns a Proc with #lambda? true" do
+ pr = :to_s.to_proc
+ pr.should.lambda?
end
- it "produces a proc that always returns [[:rest]] for #parameters" do
+ it "produces a Proc with arity -2" do
pr = :to_s.to_proc
- pr.parameters.should == [[:rest]]
+ pr.arity.should == -2
end
-end
-describe "Symbol#to_proc" do
- before :all do
- @klass = Class.new do
+ it "produces a Proc that always returns [[:req], [:rest]] for #parameters" do
+ pr = :to_s.to_proc
+ pr.parameters.should == [[:req], [:rest]]
+ end
+
+ it "only calls public methods" do
+ body = proc do
+ public def pub; @a << :pub end
+ protected def pro; @a << :pro end
+ private def pri; @a << :pri end
+ attr_reader :a
+ end
+
+ @a = []
+ singleton_class.class_eval(&body)
+ tap(&:pub)
+ proc{tap(&:pro)}.should.raise(NoMethodError, /protected method [`']pro' called/)
+ proc{tap(&:pri)}.should.raise(NoMethodError, /private method [`']pri' called/)
+ @a.should == [:pub]
+
+ @a = []
+ c = Class.new(&body)
+ o = c.new
+ o.instance_variable_set(:@a, [])
+ o.tap(&:pub)
+ proc{tap(&:pro)}.should.raise(NoMethodError, /protected method [`']pro' called/)
+ proc{o.tap(&:pri)}.should.raise(NoMethodError, /private method [`']pri' called/)
+ o.a.should == [:pub]
+ end
+
+ it "raises an ArgumentError when calling #call on the Proc without receiver" do
+ -> {
+ :object_id.to_proc.call
+ }.should.raise(ArgumentError, /no receiver given|wrong number of arguments \(given 0, expected 1\+\)/)
+ end
+
+ it "passes along the block passed to Proc#call" do
+ klass = Class.new do
def m
yield
end
@@ -33,9 +68,11 @@ describe "Symbol#to_proc" do
:m.to_proc.call(self) { :value }
end
end
+ klass.new.to_proc.should == :value
end
- it "passes along the block passed to Proc#call" do
- @klass.new.to_proc.should == :value
+ it "produces a proc with source location nil" do
+ pr = :to_s.to_proc
+ pr.source_location.should == nil
end
end
diff --git a/spec/ruby/core/symbol/to_s_spec.rb b/spec/ruby/core/symbol/to_s_spec.rb
index 40c13675b3..2cb57c4cbc 100644
--- a/spec/ruby/core/symbol/to_s_spec.rb
+++ b/spec/ruby/core/symbol/to_s_spec.rb
@@ -1,6 +1,32 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/id2name', __FILE__)
+require_relative '../../spec_helper'
describe "Symbol#to_s" do
- it_behaves_like(:symbol_id2name, :to_s)
+ it "returns the string corresponding to self" do
+ :rubinius.to_s.should == "rubinius"
+ :squash.to_s.should == "squash"
+ :[].to_s.should == "[]"
+ :@ruby.to_s.should == "@ruby"
+ :@@ruby.to_s.should == "@@ruby"
+ end
+
+ it "returns a String in the same encoding as self" do
+ string = "ruby".encode("US-ASCII")
+ symbol = string.to_sym
+
+ symbol.to_s.encoding.should == Encoding::US_ASCII
+ end
+
+ ruby_version_is "3.4" do
+ it "warns about mutating returned string" do
+ -> { :bad!.to_s.upcase! }.should complain(/warning: string returned by :bad!.to_s will be frozen in the future/)
+ end
+
+ it "does not warn about mutation when Warning[:deprecated] is false" do
+ deprecated = Warning[:deprecated]
+ Warning[:deprecated] = false
+ -> { :bad!.to_s.upcase! }.should_not complain
+ ensure
+ Warning[:deprecated] = deprecated
+ end
+ end
end
diff --git a/spec/ruby/core/symbol/to_sym_spec.rb b/spec/ruby/core/symbol/to_sym_spec.rb
index 7f26684850..062daa3fc7 100644
--- a/spec/ruby/core/symbol/to_sym_spec.rb
+++ b/spec/ruby/core/symbol/to_sym_spec.rb
@@ -1,9 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Symbol#to_sym" do
it "returns self" do
[:rubinius, :squash, :[], :@ruby, :@@ruby].each do |sym|
- sym.to_sym.should == sym
+ sym.to_sym.should.equal?(sym)
end
end
end
diff --git a/spec/ruby/core/symbol/upcase_spec.rb b/spec/ruby/core/symbol/upcase_spec.rb
index fe2c88d294..3895d95efb 100644
--- a/spec/ruby/core/symbol/upcase_spec.rb
+++ b/spec/ruby/core/symbol/upcase_spec.rb
@@ -1,26 +1,18 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Symbol#upcase" do
it "returns a Symbol" do
- :glark.upcase.should be_an_instance_of(Symbol)
+ :glark.upcase.should.instance_of?(Symbol)
end
it "converts lowercase ASCII characters to their uppercase equivalents" do
:lOwEr.upcase.should == :LOWER
end
- ruby_version_is ''...'2.4' do
- it "leaves lowercase Unicode characters as they were" do
- "\u{E0}Bc".to_sym.upcase.should == :"àBC"
- end
- end
-
- ruby_version_is '2.4' do
- it "capitalizes all Unicode characters" do
- "äöü".to_sym.upcase.should == :"ÄÖÜ"
- "aou".to_sym.upcase.should == :"AOU"
- end
+ it "capitalizes all Unicode characters" do
+ "äöü".to_sym.upcase.should == :"ÄÖÜ"
+ "aou".to_sym.upcase.should == :"AOU"
end
it "leaves non-alphabetic ASCII characters as they were" do
diff --git a/spec/ruby/core/systemexit/initialize_spec.rb b/spec/ruby/core/systemexit/initialize_spec.rb
index bf5c8b7798..2cebaa7993 100644
--- a/spec/ruby/core/systemexit/initialize_spec.rb
+++ b/spec/ruby/core/systemexit/initialize_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "SystemExit#initialize" do
it "accepts a status" do
@@ -24,4 +24,3 @@ describe "SystemExit#initialize" do
s.status.should == 0
end
end
-
diff --git a/spec/ruby/core/systemexit/success_spec.rb b/spec/ruby/core/systemexit/success_spec.rb
index 038a0e7e4d..ba2fd22ded 100644
--- a/spec/ruby/core/systemexit/success_spec.rb
+++ b/spec/ruby/core/systemexit/success_spec.rb
@@ -1,13 +1,13 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "SystemExit#success?" do
it "returns true when the status is 0" do
s = SystemExit.new 0
- s.success?.should == true
+ s.should.success?
end
it "returns false when the status is not 0" do
s = SystemExit.new 1
- s.success?.should == false
+ s.should_not.success?
end
end
diff --git a/spec/ruby/core/thread/abort_on_exception_spec.rb b/spec/ruby/core/thread/abort_on_exception_spec.rb
index e424b2fd26..aeca50e5c1 100644
--- a/spec/ruby/core/thread/abort_on_exception_spec.rb
+++ b/spec/ruby/core/thread/abort_on_exception_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Thread#abort_on_exception" do
before do
@@ -13,12 +13,12 @@ describe "Thread#abort_on_exception" do
end
it "is false by default" do
- @thread.abort_on_exception.should be_false
+ @thread.abort_on_exception.should == false
end
it "returns true when #abort_on_exception= is passed true" do
@thread.abort_on_exception = true
- @thread.abort_on_exception.should be_true
+ @thread.abort_on_exception.should == true
end
end
@@ -35,11 +35,11 @@ describe :thread_abort_on_exception, shared: true do
ScratchPad << :before
@thread.abort_on_exception = true if @object
- lambda do
+ -> do
ThreadSpecs.state = :run
# Wait for the main thread to be interrupted
sleep
- end.should raise_error(RuntimeError, "Thread#abort_on_exception= specs")
+ end.should.raise(RuntimeError, "Thread#abort_on_exception= specs")
ScratchPad << :after
rescue Exception => e
@@ -72,7 +72,7 @@ describe "Thread.abort_on_exception" do
end
after do
- Thread.abort_on_exception = @abort_on_exception
+ Thread.abort_on_exception = @abort_on_exception
end
it "is false by default" do
@@ -81,7 +81,7 @@ describe "Thread.abort_on_exception" do
it "returns true when .abort_on_exception= is passed true" do
Thread.abort_on_exception = true
- Thread.abort_on_exception.should be_true
+ Thread.abort_on_exception.should == true
end
end
diff --git a/spec/ruby/core/thread/add_trace_func_spec.rb b/spec/ruby/core/thread/add_trace_func_spec.rb
index c2010ef317..0abae81a78 100644
--- a/spec/ruby/core/thread/add_trace_func_spec.rb
+++ b/spec/ruby/core/thread/add_trace_func_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Thread#add_trace_func" do
it "needs to be reviewed for spec completeness"
diff --git a/spec/ruby/core/thread/alive_spec.rb b/spec/ruby/core/thread/alive_spec.rb
index c1459ac693..c2f5f5371d 100644
--- a/spec/ruby/core/thread/alive_spec.rb
+++ b/spec/ruby/core/thread/alive_spec.rb
@@ -1,41 +1,41 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Thread#alive?" do
it "can check it's own status" do
- ThreadSpecs.status_of_current_thread.alive?.should == true
+ ThreadSpecs.status_of_current_thread.should.alive?
end
it "describes a running thread" do
- ThreadSpecs.status_of_running_thread.alive?.should == true
+ ThreadSpecs.status_of_running_thread.should.alive?
end
it "describes a sleeping thread" do
- ThreadSpecs.status_of_sleeping_thread.alive?.should == true
+ ThreadSpecs.status_of_sleeping_thread.should.alive?
end
it "describes a blocked thread" do
- ThreadSpecs.status_of_blocked_thread.alive?.should == true
+ ThreadSpecs.status_of_blocked_thread.should.alive?
end
it "describes a completed thread" do
- ThreadSpecs.status_of_completed_thread.alive?.should == false
+ ThreadSpecs.status_of_completed_thread.should_not.alive?
end
it "describes a killed thread" do
- ThreadSpecs.status_of_killed_thread.alive?.should == false
+ ThreadSpecs.status_of_killed_thread.should_not.alive?
end
it "describes a thread with an uncaught exception" do
- ThreadSpecs.status_of_thread_with_uncaught_exception.alive?.should == false
+ ThreadSpecs.status_of_thread_with_uncaught_exception.should_not.alive?
end
it "describes a dying running thread" do
- ThreadSpecs.status_of_dying_running_thread.alive?.should == true
+ ThreadSpecs.status_of_dying_running_thread.should.alive?
end
it "describes a dying sleeping thread" do
- ThreadSpecs.status_of_dying_sleeping_thread.alive?.should == true
+ ThreadSpecs.status_of_dying_sleeping_thread.should.alive?
end
it "returns true for a killed but still running thread" do
@@ -51,7 +51,7 @@ describe "Thread#alive?" do
ThreadSpecs.spin_until_sleeping(t)
t.kill
- t.alive?.should == true
+ t.should.alive?
exit = true
t.join
end
diff --git a/spec/ruby/core/thread/allocate_spec.rb b/spec/ruby/core/thread/allocate_spec.rb
index 1db05878ba..0b4e4f1b1f 100644
--- a/spec/ruby/core/thread/allocate_spec.rb
+++ b/spec/ruby/core/thread/allocate_spec.rb
@@ -1,9 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Thread.allocate" do
it "raises a TypeError" do
- lambda {
+ -> {
Thread.allocate
- }.should raise_error(TypeError)
+ }.should.raise(TypeError)
end
end
diff --git a/spec/ruby/core/thread/backtrace/limit_spec.rb b/spec/ruby/core/thread/backtrace/limit_spec.rb
new file mode 100644
index 0000000000..b55ca67ea0
--- /dev/null
+++ b/spec/ruby/core/thread/backtrace/limit_spec.rb
@@ -0,0 +1,13 @@
+require_relative '../../../spec_helper'
+
+describe "Thread::Backtrace.limit" do
+ it "returns maximum backtrace length set by --backtrace-limit command-line option" do
+ out = ruby_exe("print Thread::Backtrace.limit", options: "--backtrace-limit=2")
+ out.should == "2"
+ end
+
+ it "returns -1 when --backtrace-limit command-line option is not set" do
+ out = ruby_exe("print Thread::Backtrace.limit")
+ out.should == "-1"
+ end
+end
diff --git a/spec/ruby/core/thread/backtrace/location/absolute_path_spec.rb b/spec/ruby/core/thread/backtrace/location/absolute_path_spec.rb
index 6810bdcd78..6d9482f2ae 100644
--- a/spec/ruby/core/thread/backtrace/location/absolute_path_spec.rb
+++ b/spec/ruby/core/thread/backtrace/location/absolute_path_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../../../spec_helper'
+require_relative 'fixtures/classes'
describe 'Thread::Backtrace::Location#absolute_path' do
before :each do
@@ -9,4 +9,85 @@ describe 'Thread::Backtrace::Location#absolute_path' do
it 'returns the absolute path of the call frame' do
@frame.absolute_path.should == File.realpath(__FILE__)
end
+
+ it 'returns an absolute path when using a relative main script path' do
+ script = fixture(__FILE__, 'absolute_path_main.rb')
+ Dir.chdir(File.dirname(script)) do
+ ruby_exe('absolute_path_main.rb').should == "absolute_path_main.rb\n#{script}\n"
+ end
+ end
+
+ it 'returns the correct absolute path when using a relative main script path and changing CWD' do
+ script = fixture(__FILE__, 'subdir/absolute_path_main_chdir.rb')
+ sibling = fixture(__FILE__, 'subdir/sibling.rb')
+ subdir = File.dirname script
+ Dir.chdir(fixture(__FILE__)) do
+ ruby_exe('subdir/absolute_path_main_chdir.rb').should == "subdir/absolute_path_main_chdir.rb\n#{subdir}\n#{subdir}\n#{script}\n#{sibling}\n"
+ end
+ end
+
+ context "when used in eval with a given filename" do
+ it "returns nil with absolute_path" do
+ code = "caller_locations(0)[0].absolute_path"
+
+ eval(code, nil, "foo.rb").should == nil
+ eval(code, nil, "foo/bar.rb").should == nil
+ end
+ end
+
+ context "when used in #method_added" do
+ it "returns the user filename that defined the method" do
+ path = fixture(__FILE__, "absolute_path_method_added.rb")
+ load path
+ locations = ScratchPad.recorded
+ locations[0].absolute_path.should == path
+ # Make sure it's from the class body, not from the file top-level
+ locations[0].label.should.include? 'MethodAddedAbsolutePath'
+ end
+ end
+
+ context "when used in a core method" do
+ it "returns nil" do
+ location = nil
+ tap { location = caller_locations(1, 1)[0] }
+ location.label.should =~ /\A(?:Kernel#)?tap\z/
+ if location.path.start_with?("<internal:")
+ location.absolute_path.should == nil
+ else
+ location.absolute_path.should == File.realpath(__FILE__)
+ end
+ end
+ end
+
+ context "canonicalization" do
+ platform_is_not :windows do
+ before :each do
+ @file = fixture(__FILE__, "absolute_path.rb")
+ @symlink = tmp("symlink.rb")
+ File.symlink(@file, @symlink)
+ ScratchPad.record []
+ end
+
+ after :each do
+ rm_r @symlink
+ end
+
+ it "returns a canonical path without symlinks, even when __FILE__ does not" do
+ realpath = File.realpath(@symlink)
+ realpath.should_not == @symlink
+
+ load @symlink
+ ScratchPad.recorded.should == [@symlink, realpath]
+ end
+
+ it "returns a canonical path without symlinks, even when __FILE__ is removed" do
+ realpath = File.realpath(@symlink)
+ realpath.should_not == @symlink
+
+ ScratchPad << -> { rm_r(@symlink) }
+ load @symlink
+ ScratchPad.recorded.should == [@symlink, realpath]
+ end
+ end
+ end
end
diff --git a/spec/ruby/core/thread/backtrace/location/base_label_spec.rb b/spec/ruby/core/thread/backtrace/location/base_label_spec.rb
index cba7e3f34c..739f62f42f 100644
--- a/spec/ruby/core/thread/backtrace/location/base_label_spec.rb
+++ b/spec/ruby/core/thread/backtrace/location/base_label_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../../../spec_helper'
+require_relative 'fixtures/classes'
describe 'Thread::Backtrace::Location#base_label' do
before :each do
@@ -9,4 +9,41 @@ describe 'Thread::Backtrace::Location#base_label' do
it 'returns the base label of the call frame' do
@frame.base_label.should == '<top (required)>'
end
+
+ describe 'when call frame is inside a block' do
+ before :each do
+ @frame = ThreadBacktraceLocationSpecs.block_location[0]
+ end
+
+ it 'returns the name of the method that contains the block' do
+ @frame.base_label.should == 'block_location'
+ end
+ end
+
+ it "is <module:A> for a module body" do
+ module ThreadBacktraceLocationSpecs
+ module ModuleLabel
+ ScratchPad.record caller_locations(0, 1)[0].base_label
+ end
+ end
+ ScratchPad.recorded.should == '<module:ModuleLabel>'
+ end
+
+ it "is <class:A> for a class body" do
+ module ThreadBacktraceLocationSpecs
+ class ClassLabel
+ ScratchPad.record caller_locations(0, 1)[0].base_label
+ end
+ end
+ ScratchPad.recorded.should == '<class:ClassLabel>'
+ end
+
+ it "is 'singleton class' for a singleton class body" do
+ module ThreadBacktraceLocationSpecs
+ class << Object.new
+ ScratchPad.record caller_locations(0, 1)[0].base_label
+ end
+ end
+ ScratchPad.recorded.should =~ /\A(singleton class|<singleton class>)\z/
+ end
end
diff --git a/spec/ruby/core/thread/backtrace/location/fixtures/absolute_path.rb b/spec/ruby/core/thread/backtrace/location/fixtures/absolute_path.rb
new file mode 100644
index 0000000000..875e97ffac
--- /dev/null
+++ b/spec/ruby/core/thread/backtrace/location/fixtures/absolute_path.rb
@@ -0,0 +1,4 @@
+action = ScratchPad.recorded.pop
+ScratchPad << __FILE__
+action.call if action
+ScratchPad << caller_locations(0)[0].absolute_path
diff --git a/spec/ruby/core/thread/backtrace/location/fixtures/absolute_path_main.rb b/spec/ruby/core/thread/backtrace/location/fixtures/absolute_path_main.rb
new file mode 100644
index 0000000000..d2b23393d4
--- /dev/null
+++ b/spec/ruby/core/thread/backtrace/location/fixtures/absolute_path_main.rb
@@ -0,0 +1,2 @@
+puts __FILE__
+puts caller_locations(0)[0].absolute_path
diff --git a/spec/ruby/core/thread/backtrace/location/fixtures/absolute_path_method_added.rb b/spec/ruby/core/thread/backtrace/location/fixtures/absolute_path_method_added.rb
new file mode 100644
index 0000000000..26d6298a19
--- /dev/null
+++ b/spec/ruby/core/thread/backtrace/location/fixtures/absolute_path_method_added.rb
@@ -0,0 +1,10 @@
+module ThreadBacktraceLocationSpecs
+ class MethodAddedAbsolutePath
+ def self.method_added(name)
+ ScratchPad.record caller_locations
+ end
+
+ def foo
+ end
+ end
+end
diff --git a/spec/ruby/core/thread/backtrace/location/fixtures/classes.rb b/spec/ruby/core/thread/backtrace/location/fixtures/classes.rb
index 3e42d8cf81..103c36b3a0 100644
--- a/spec/ruby/core/thread/backtrace/location/fixtures/classes.rb
+++ b/spec/ruby/core/thread/backtrace/location/fixtures/classes.rb
@@ -1,10 +1,26 @@
+# These are top-level def on purpose to test those cases
+
+def label_top_method = ThreadBacktraceLocationSpecs::LABEL.call
+
+def self.label_sdef_method_of_main = ThreadBacktraceLocationSpecs::LABEL.call
+
+class << self
+ def label_sclass_method_of_main = ThreadBacktraceLocationSpecs::LABEL.call
+end
+
module ThreadBacktraceLocationSpecs
MODULE_LOCATION = caller_locations(0) rescue nil
+ INSTANCE = Object.new.extend(self)
+ LABEL = -> { caller_locations(1, 1)[0].label }
def self.locations
caller_locations
end
+ def instance_method_location
+ caller_locations(0)
+ end
+
def self.method_location
caller_locations(0)
end
@@ -14,4 +30,110 @@ module ThreadBacktraceLocationSpecs
return caller_locations(0)
end
end
+
+ def instance_block_location
+ 1.times do
+ return caller_locations(0)
+ end
+ end
+
+ def self.locations_inside_nested_blocks
+ first_level_location = nil
+ second_level_location = nil
+ third_level_location = nil
+
+ 1.times do
+ first_level_location = locations[0]
+ 1.times do
+ second_level_location = locations[0]
+ 1.times do
+ third_level_location = locations[0]
+ end
+ end
+ end
+
+ [first_level_location, second_level_location, third_level_location]
+ end
+
+ def instance_locations_inside_nested_block
+ loc = nil
+ 1.times do
+ 1.times do
+ loc = caller_locations(0)
+ end
+ end
+ loc
+ end
+
+ def original_method = LABEL.call
+ alias_method :aliased_method, :original_method
+
+ module M
+ class C
+ def regular_instance_method = LABEL.call
+
+ def self.sdef_class_method = LABEL.call
+
+ class << self
+ def sclass_method = LABEL.call
+
+ def block_in_sclass_method
+ -> {
+ -> { LABEL.call }.call
+ }.call
+ end
+ end
+ block_in_sclass_method
+ end
+ end
+
+ class M::D
+ def scoped_method = LABEL.call
+
+ def self.sdef_scoped_method = LABEL.call
+
+ class << self
+ def sclass_scoped_method = LABEL.call
+ end
+
+ module ::ThreadBacktraceLocationSpecs
+ def top = LABEL.call
+ end
+
+ class ::ThreadBacktraceLocationSpecs::Nested
+ def top_nested = LABEL.call
+
+ class C
+ def top_nested_c = LABEL.call
+ end
+ end
+ end
+
+ SOME_OBJECT = Object.new
+ SOME_OBJECT.instance_exec do
+ def unknown_def_singleton_method = LABEL.call
+
+ def self.unknown_sdef_singleton_method = LABEL.call
+ end
+
+ M.module_eval do
+ def module_eval_method = LABEL.call
+
+ def self.sdef_module_eval_method = LABEL.call
+ end
+
+ def ThreadBacktraceLocationSpecs.string_class_method = LABEL.call
+
+ module M
+ def ThreadBacktraceLocationSpecs.nested_class_method = LABEL.call
+ end
+
+ module M
+ module_function def mod_function = LABEL.call
+ end
+
+ expr = self
+ def expr.sdef_expression = LABEL.call
+
+ def expr.block_in_sdef_expression = -> { LABEL.call }.call
end
diff --git a/spec/ruby/core/thread/backtrace/location/fixtures/locations_in_main.rb b/spec/ruby/core/thread/backtrace/location/fixtures/locations_in_main.rb
new file mode 100644
index 0000000000..b124c8161c
--- /dev/null
+++ b/spec/ruby/core/thread/backtrace/location/fixtures/locations_in_main.rb
@@ -0,0 +1,5 @@
+1.times do
+ puts Thread.current.backtrace_locations(1..1)[0].label
+end
+
+require_relative 'locations_in_required'
diff --git a/spec/ruby/core/thread/backtrace/location/fixtures/locations_in_required.rb b/spec/ruby/core/thread/backtrace/location/fixtures/locations_in_required.rb
new file mode 100644
index 0000000000..5f5ed89e98
--- /dev/null
+++ b/spec/ruby/core/thread/backtrace/location/fixtures/locations_in_required.rb
@@ -0,0 +1,3 @@
+1.times do
+ puts Thread.current.backtrace_locations(1..1)[0].label
+end
diff --git a/spec/ruby/core/thread/backtrace/location/fixtures/main.rb b/spec/ruby/core/thread/backtrace/location/fixtures/main.rb
index d2d14ac957..bde208a059 100644
--- a/spec/ruby/core/thread/backtrace/location/fixtures/main.rb
+++ b/spec/ruby/core/thread/backtrace/location/fixtures/main.rb
@@ -1,5 +1,5 @@
-def example
+def backtrace_location_example
caller_locations[0].path
end
-print example
+print backtrace_location_example
diff --git a/spec/ruby/core/thread/backtrace/location/fixtures/path.rb b/spec/ruby/core/thread/backtrace/location/fixtures/path.rb
new file mode 100644
index 0000000000..fba34cb0bc
--- /dev/null
+++ b/spec/ruby/core/thread/backtrace/location/fixtures/path.rb
@@ -0,0 +1,2 @@
+ScratchPad << __FILE__
+ScratchPad << caller_locations(0)[0].path
diff --git a/spec/ruby/core/thread/backtrace/location/fixtures/subdir/absolute_path_main_chdir.rb b/spec/ruby/core/thread/backtrace/location/fixtures/subdir/absolute_path_main_chdir.rb
new file mode 100644
index 0000000000..33c8fb36ef
--- /dev/null
+++ b/spec/ruby/core/thread/backtrace/location/fixtures/subdir/absolute_path_main_chdir.rb
@@ -0,0 +1,11 @@
+puts __FILE__
+puts __dir__
+Dir.chdir __dir__
+
+# Check __dir__ is still correct after chdir
+puts __dir__
+
+puts caller_locations(0)[0].absolute_path
+
+# require_relative also needs to know the absolute path of the current file so we test it here too
+require_relative 'sibling'
diff --git a/spec/ruby/core/thread/backtrace/location/fixtures/subdir/sibling.rb b/spec/ruby/core/thread/backtrace/location/fixtures/subdir/sibling.rb
new file mode 100644
index 0000000000..2a854ddccd
--- /dev/null
+++ b/spec/ruby/core/thread/backtrace/location/fixtures/subdir/sibling.rb
@@ -0,0 +1 @@
+puts __FILE__
diff --git a/spec/ruby/core/thread/backtrace/location/inspect_spec.rb b/spec/ruby/core/thread/backtrace/location/inspect_spec.rb
index 56d440c04a..4df88a2f33 100644
--- a/spec/ruby/core/thread/backtrace/location/inspect_spec.rb
+++ b/spec/ruby/core/thread/backtrace/location/inspect_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../../../spec_helper'
+require_relative 'fixtures/classes'
describe 'Thread::Backtrace::Location#inspect' do
before :each do
@@ -8,6 +8,6 @@ describe 'Thread::Backtrace::Location#inspect' do
end
it 'converts the call frame to a String' do
- @frame.inspect.should include("#{__FILE__}:#{@line}:in ")
+ @frame.inspect.should.include?("#{__FILE__}:#{@line}:in ")
end
end
diff --git a/spec/ruby/core/thread/backtrace/location/label_spec.rb b/spec/ruby/core/thread/backtrace/location/label_spec.rb
index 4e67509d0f..5f6a7b73df 100644
--- a/spec/ruby/core/thread/backtrace/location/label_spec.rb
+++ b/spec/ruby/core/thread/backtrace/location/label_spec.rb
@@ -1,20 +1,227 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../../../spec_helper'
+require_relative 'fixtures/classes'
describe 'Thread::Backtrace::Location#label' do
it 'returns the base label of the call frame' do
- ThreadBacktraceLocationSpecs.locations[0].label.should include('<top (required)>')
+ ThreadBacktraceLocationSpecs.locations[0].label.should.include?('<top (required)>')
end
it 'returns the method name for a method location' do
- ThreadBacktraceLocationSpecs.method_location[0].label.should == "method_location"
+ ThreadBacktraceLocationSpecs.method_location[0].label.should =~ /\A(?:ThreadBacktraceLocationSpecs\.)?method_location\z/
end
it 'returns the block name for a block location' do
- ThreadBacktraceLocationSpecs.block_location[0].label.should == "block in block_location"
+ ThreadBacktraceLocationSpecs.block_location[0].label.should =~ /\Ablock in (?:ThreadBacktraceLocationSpecs\.)?block_location\z/
end
it 'returns the module name for a module location' do
- ThreadBacktraceLocationSpecs::MODULE_LOCATION[0].label.should include "ThreadBacktraceLocationSpecs"
+ ThreadBacktraceLocationSpecs::MODULE_LOCATION[0].label.should == "<module:ThreadBacktraceLocationSpecs>"
+ end
+
+ it 'includes the nesting level of a block as part of the location label' do
+ first_level_location, second_level_location, third_level_location =
+ ThreadBacktraceLocationSpecs.locations_inside_nested_blocks
+
+ first_level_location.label.should =~ /\Ablock in (?:ThreadBacktraceLocationSpecs\.)?locations_inside_nested_blocks\z/
+ second_level_location.label.should =~ /\Ablock \(2 levels\) in (?:ThreadBacktraceLocationSpecs\.)?locations_inside_nested_blocks\z/
+ third_level_location.label.should =~ /\Ablock \(3 levels\) in (?:ThreadBacktraceLocationSpecs\.)?locations_inside_nested_blocks\z/
+ end
+
+ it 'sets the location label for a top-level block differently depending on it being in the main file or a required file' do
+ path = fixture(__FILE__, "locations_in_main.rb")
+ main_label, required_label = ruby_exe(path).lines
+
+ main_label.should == "block in <main>\n"
+ required_label.should == "block in <top (required)>\n"
+ end
+
+ it "return the same name as the caller for eval" do
+ this = caller_locations(0)[0].label
+ eval("caller_locations(0)[0]").label.should == this
+
+ b = binding
+ b.eval("caller_locations(0)[0]").label.should == this
+
+ b.local_variable_set(:binding_var1, 1)
+ b.eval("caller_locations(0)[0]").label.should == this
+
+ b.local_variable_set(:binding_var2, 2)
+ b.eval("caller_locations(0)[0]").label.should == this
+
+ b.local_variable_set(:binding_var2, 2)
+ eval("caller_locations(0)[0]", b).label.should == this
+ end
+
+ ruby_version_is "3.4" do
+ describe "is Module#method for" do
+ it "a core method defined natively" do
+ BasicObject.instance_method(:instance_exec).should_not.source_location
+ loc = nil
+ loc = instance_exec { caller_locations(1, 1)[0] }
+ loc.label.should == "BasicObject#instance_exec"
+ end
+
+ it "a core method defined in Ruby" do
+ Kernel.instance_method(:tap).should.source_location
+ loc = nil
+ tap { loc = caller_locations(1, 1)[0] }
+ loc.label.should == "Kernel#tap"
+ end
+
+ it "an instance method defined in Ruby" do
+ ThreadBacktraceLocationSpecs::INSTANCE.instance_method_location[0].label.should == "ThreadBacktraceLocationSpecs#instance_method_location"
+ end
+
+ it "a block in an instance method defined in Ruby" do
+ ThreadBacktraceLocationSpecs::INSTANCE.instance_block_location[0].label.should == "block in ThreadBacktraceLocationSpecs#instance_block_location"
+ end
+
+ it "a nested block in an instance method defined in Ruby" do
+ ThreadBacktraceLocationSpecs::INSTANCE.instance_locations_inside_nested_block[0].label.should == "block (2 levels) in ThreadBacktraceLocationSpecs#instance_locations_inside_nested_block"
+ end
+
+ it "a method defined via module_exec" do
+ ThreadBacktraceLocationSpecs.module_exec do
+ def in_module_exec
+ caller_locations(0)
+ end
+ end
+ ThreadBacktraceLocationSpecs::INSTANCE.in_module_exec[0].label.should == "ThreadBacktraceLocationSpecs#in_module_exec"
+ end
+
+ it "a method defined via module_eval" do
+ ThreadBacktraceLocationSpecs.module_eval <<~RUBY
+ def in_module_eval
+ caller_locations(0)
+ end
+ RUBY
+ ThreadBacktraceLocationSpecs::INSTANCE.in_module_eval[0].label.should == "ThreadBacktraceLocationSpecs#in_module_eval"
+ end
+ end
+
+ describe "is Module.method for" do
+ it "a singleton method defined in Ruby" do
+ ThreadBacktraceLocationSpecs.method_location[0].label.should == "ThreadBacktraceLocationSpecs.method_location"
+ end
+
+ it "a block in a singleton method defined in Ruby" do
+ ThreadBacktraceLocationSpecs.block_location[0].label.should == "block in ThreadBacktraceLocationSpecs.block_location"
+ end
+
+ it "a nested block in a singleton method defined in Ruby" do
+ ThreadBacktraceLocationSpecs.locations_inside_nested_blocks[2].label.should == "block (3 levels) in ThreadBacktraceLocationSpecs.locations_inside_nested_blocks"
+ end
+
+ it "a singleton method defined via def Const.method" do
+ def ThreadBacktraceLocationSpecs.def_singleton
+ caller_locations(0)
+ end
+ ThreadBacktraceLocationSpecs.def_singleton[0].label.should == "ThreadBacktraceLocationSpecs.def_singleton"
+ end
+ end
+
+ it "shows the original method name for an aliased method" do
+ ThreadBacktraceLocationSpecs::INSTANCE.aliased_method.should == "ThreadBacktraceLocationSpecs#original_method"
+ end
+
+ # A wide variety of cases.
+ # These show interesting cases when trying to determine the name statically/at parse time
+ describe "is correct for" do
+ base = ThreadBacktraceLocationSpecs
+
+ it "M::C#regular_instance_method" do
+ base::M::C.new.regular_instance_method.should == "#{base}::M::C#regular_instance_method"
+ end
+
+ it "M::C.sdef_class_method" do
+ base::M::C.sdef_class_method.should == "#{base}::M::C.sdef_class_method"
+ end
+
+ it "M::C.sclass_method" do
+ base::M::C.sclass_method.should == "#{base}::M::C.sclass_method"
+ end
+
+ it "M::C.block_in_sclass_method" do
+ base::M::C.block_in_sclass_method.should == "block (2 levels) in #{base}::M::C.block_in_sclass_method"
+ end
+
+ it "M::D#scoped_method" do
+ base::M::D.new.scoped_method.should == "#{base}::M::D#scoped_method"
+ end
+
+ it "M::D.sdef_scoped_method" do
+ base::M::D.sdef_scoped_method.should == "#{base}::M::D.sdef_scoped_method"
+ end
+
+ it "M::D.sclass_scoped_method" do
+ base::M::D.sclass_scoped_method.should == "#{base}::M::D.sclass_scoped_method"
+ end
+
+ it "ThreadBacktraceLocationSpecs#top" do
+ ThreadBacktraceLocationSpecs::INSTANCE.top.should == "ThreadBacktraceLocationSpecs#top"
+ end
+
+ it "ThreadBacktraceLocationSpecs::Nested#top_nested" do
+ ThreadBacktraceLocationSpecs::Nested.new.top_nested.should == "ThreadBacktraceLocationSpecs::Nested#top_nested"
+ end
+
+ it "ThreadBacktraceLocationSpecs::Nested::C#top_nested_c" do
+ ThreadBacktraceLocationSpecs::Nested::C.new.top_nested_c.should == "ThreadBacktraceLocationSpecs::Nested::C#top_nested_c"
+ end
+
+ it "Object#label_top_method" do
+ label_top_method.should == "Object#label_top_method"
+ end
+
+ it "main.label_sdef_method_of_main" do
+ main = TOPLEVEL_BINDING.receiver
+ main.label_sdef_method_of_main.should == "label_sdef_method_of_main"
+ end
+
+ it "main.label_sclass_method_of_main" do
+ main = TOPLEVEL_BINDING.receiver
+ main.label_sclass_method_of_main.should == "label_sclass_method_of_main"
+ end
+
+ it "unknown_def_singleton_method" do
+ base::SOME_OBJECT.unknown_def_singleton_method.should == "unknown_def_singleton_method"
+ end
+
+ it "unknown_sdef_singleton_method" do
+ base::SOME_OBJECT.unknown_sdef_singleton_method.should == "unknown_sdef_singleton_method"
+ end
+
+ it "M#module_eval_method" do
+ Object.new.extend(base::M).module_eval_method.should == "#{base}::M#module_eval_method"
+ end
+
+ it "M.sdef_module_eval_method" do
+ base::M.sdef_module_eval_method.should == "#{base}::M.sdef_module_eval_method"
+ end
+
+ it "ThreadBacktraceLocationSpecs.string_class_method" do
+ ThreadBacktraceLocationSpecs.string_class_method.should == "ThreadBacktraceLocationSpecs.string_class_method"
+ end
+
+ it "ThreadBacktraceLocationSpecs.nested_class_method" do
+ ThreadBacktraceLocationSpecs.nested_class_method.should == "ThreadBacktraceLocationSpecs.nested_class_method"
+ end
+
+ it "M#mod_function" do
+ Object.new.extend(base::M).send(:mod_function).should == "#{base}::M#mod_function"
+ end
+
+ it "M.mod_function" do
+ base::M.mod_function.should == "#{base}::M.mod_function"
+ end
+
+ it "sdef_expression" do
+ base.sdef_expression.should == "#{base}.sdef_expression"
+ end
+
+ it "block_in_sdef_expression" do
+ base.block_in_sdef_expression.should == "block in #{base}.block_in_sdef_expression"
+ end
+ end
end
end
diff --git a/spec/ruby/core/thread/backtrace/location/lineno_spec.rb b/spec/ruby/core/thread/backtrace/location/lineno_spec.rb
index 7d203008e5..10457f80f0 100644
--- a/spec/ruby/core/thread/backtrace/location/lineno_spec.rb
+++ b/spec/ruby/core/thread/backtrace/location/lineno_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../../../spec_helper'
+require_relative 'fixtures/classes'
describe 'Thread::Backtrace::Location#lineno' do
before :each do
@@ -7,7 +7,17 @@ describe 'Thread::Backtrace::Location#lineno' do
@line = __LINE__ - 1
end
- it 'returns the absolute path of the call frame' do
+ it 'returns the line number of the call frame' do
@frame.lineno.should == @line
end
+
+ it 'should be the same line number as in #to_s, including for core methods' do
+ # Get the caller_locations from a call made into a core library method
+ locations = [:non_empty].map { caller_locations }[0]
+
+ locations.each do |location|
+ line_number = location.to_s[/:(\d+):/, 1]
+ location.lineno.should == Integer(line_number)
+ end
+ end
end
diff --git a/spec/ruby/core/thread/backtrace/location/path_spec.rb b/spec/ruby/core/thread/backtrace/location/path_spec.rb
index c2f2058990..75f76833a9 100644
--- a/spec/ruby/core/thread/backtrace/location/path_spec.rb
+++ b/spec/ruby/core/thread/backtrace/location/path_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../../../spec_helper'
+require_relative 'fixtures/classes'
describe 'Thread::Backtrace::Location#path' do
context 'outside a main script' do
@@ -41,7 +41,7 @@ describe 'Thread::Backtrace::Location#path' do
context 'when using a relative script path' do
it 'returns a path relative to the working directory' do
path = 'fixtures/main.rb'
- directory = File.dirname(__FILE__)
+ directory = __dir__
Dir.chdir(directory) {
ruby_exe(path)
}.should == path
@@ -56,7 +56,7 @@ describe 'Thread::Backtrace::Location#path' do
end
context 'when the script is outside of the working directory' do
- before do
+ before :each do
@parent_dir = tmp('path_outside_pwd')
@sub_dir = File.join(@parent_dir, 'sub')
@script = File.join(@parent_dir, 'main.rb')
@@ -67,9 +67,7 @@ describe 'Thread::Backtrace::Location#path' do
cp(source, @script)
end
- after do
- rm_r(@script)
- rm_r(@sub_dir)
+ after :each do
rm_r(@parent_dir)
end
@@ -88,4 +86,39 @@ describe 'Thread::Backtrace::Location#path' do
end
end
end
+
+ it 'should be the same path as in #to_s, including for core methods' do
+ # Get the caller_locations from a call made into a core library method
+ locations = [:non_empty].map { caller_locations }[0]
+
+ locations.each do |location|
+ filename = location.to_s[/^(.+):\d+:/, 1]
+ path = location.path
+
+ path.should == filename
+ end
+ end
+
+ context "canonicalization" do
+ platform_is_not :windows do
+ before :each do
+ @file = fixture(__FILE__, "path.rb")
+ @symlink = tmp("symlink.rb")
+ File.symlink(@file, @symlink)
+ ScratchPad.record []
+ end
+
+ after :each do
+ rm_r @symlink
+ end
+
+ it "returns a non-canonical path with symlinks, the same as __FILE__" do
+ realpath = File.realpath(@symlink)
+ realpath.should_not == @symlink
+
+ load @symlink
+ ScratchPad.recorded.should == [@symlink, @symlink]
+ end
+ end
+ end
end
diff --git a/spec/ruby/core/thread/backtrace/location/to_s_spec.rb b/spec/ruby/core/thread/backtrace/location/to_s_spec.rb
index 486d7da4c9..983ce4c3f8 100644
--- a/spec/ruby/core/thread/backtrace/location/to_s_spec.rb
+++ b/spec/ruby/core/thread/backtrace/location/to_s_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../../../spec_helper'
+require_relative 'fixtures/classes'
describe 'Thread::Backtrace::Location#to_s' do
before :each do
@@ -8,6 +8,6 @@ describe 'Thread::Backtrace::Location#to_s' do
end
it 'converts the call frame to a String' do
- @frame.to_s.should include("#{__FILE__}:#{@line}:in ")
+ @frame.to_s.should.include?("#{__FILE__}:#{@line}:in ")
end
end
diff --git a/spec/ruby/core/thread/backtrace_locations_spec.rb b/spec/ruby/core/thread/backtrace_locations_spec.rb
new file mode 100644
index 0000000000..28a488f311
--- /dev/null
+++ b/spec/ruby/core/thread/backtrace_locations_spec.rb
@@ -0,0 +1,79 @@
+require_relative '../../spec_helper'
+
+describe "Thread#backtrace_locations" do
+ it "returns an Array" do
+ locations = Thread.current.backtrace_locations
+ locations.should.instance_of?(Array)
+ locations.should_not.empty?
+ end
+
+ it "sets each element to a Thread::Backtrace::Location" do
+ locations = Thread.current.backtrace_locations
+ locations.each { |loc| loc.should.instance_of?(Thread::Backtrace::Location) }
+ end
+
+ it "can be called on any Thread" do
+ locations = Thread.new { Thread.current.backtrace_locations }.value
+ locations.should.instance_of?(Array)
+ locations.should_not.empty?
+ locations.each { |loc| loc.should.instance_of?(Thread::Backtrace::Location) }
+ end
+
+ it "can be called with a number of locations to omit" do
+ locations1 = Thread.current.backtrace_locations
+ locations2 = Thread.current.backtrace_locations(2)
+ locations2.length.should == locations1[2..-1].length
+ locations2.map(&:to_s).should == locations1[2..-1].map(&:to_s)
+ end
+
+ it "can be called with a maximum number of locations to return as second parameter" do
+ locations1 = Thread.current.backtrace_locations
+ locations2 = Thread.current.backtrace_locations(2, 3)
+ locations2.map(&:to_s).should == locations1[2..4].map(&:to_s)
+ end
+
+ it "can be called with a range" do
+ locations1 = Thread.current.backtrace_locations
+ locations2 = Thread.current.backtrace_locations(2..4)
+ locations2.map(&:to_s).should == locations1[2..4].map(&:to_s)
+ end
+
+ it "can be called with a range whose end is negative" do
+ Thread.current.backtrace_locations(2..-1).map(&:to_s).should == Thread.current.backtrace_locations[2..-1].map(&:to_s)
+ Thread.current.backtrace_locations(2..-2).map(&:to_s).should == Thread.current.backtrace_locations[2..-2].map(&:to_s)
+ end
+
+ it "can be called with an endless range" do
+ locations1 = Thread.current.backtrace_locations(0)
+ locations2 = Thread.current.backtrace_locations(eval("(2..)"))
+ locations2.map(&:to_s).should == locations1[2..-1].map(&:to_s)
+ end
+
+ it "can be called with an beginless range" do
+ locations1 = Thread.current.backtrace_locations(0)
+ locations2 = Thread.current.backtrace_locations((..5))
+ locations2.map(&:to_s)[eval("(2..)")].should == locations1[(..5)].map(&:to_s)[eval("(2..)")]
+ end
+
+ it "returns nil if omitting more locations than available" do
+ Thread.current.backtrace_locations(100).should == nil
+ Thread.current.backtrace_locations(100..-1).should == nil
+ end
+
+ it "returns [] if omitting exactly the number of locations available" do
+ omit = Thread.current.backtrace_locations.length
+ Thread.current.backtrace_locations(omit).should == []
+ end
+
+ it "without argument is the same as showing all locations with 0..-1" do
+ Thread.current.backtrace_locations.map(&:to_s).should == Thread.current.backtrace_locations(0..-1).map(&:to_s)
+ end
+
+ it "the first location reports the call to #backtrace_locations" do
+ Thread.current.backtrace_locations(0..0)[0].to_s.should =~ /\A#{__FILE__ }:#{__LINE__ }:in [`'](?:Thread#)?backtrace_locations'\z/
+ end
+
+ it "[1..-1] is the same as #caller_locations(0..-1) for Thread.current" do
+ Thread.current.backtrace_locations(1..-1).map(&:to_s).should == caller_locations(0..-1).map(&:to_s)
+ end
+end
diff --git a/spec/ruby/core/thread/backtrace_spec.rb b/spec/ruby/core/thread/backtrace_spec.rb
index a20fdee956..770c300f06 100644
--- a/spec/ruby/core/thread/backtrace_spec.rb
+++ b/spec/ruby/core/thread/backtrace_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Thread#backtrace" do
it "returns the current backtrace of a thread" do
@@ -12,8 +12,8 @@ describe "Thread#backtrace" do
Thread.pass while t.status && t.status != 'sleep'
backtrace = t.backtrace
- backtrace.should be_kind_of(Array)
- backtrace.first.should =~ /`sleep'/
+ backtrace.should.is_a?(Array)
+ backtrace.first.should =~ /[`'](?:Kernel#)?sleep'/
t.raise 'finish the thread'
t.join
@@ -24,4 +24,46 @@ 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.is_a?(Array)
+ end
+
+ it "can be called with a number of locations to omit" do
+ locations1 = Thread.current.backtrace
+ locations2 = Thread.current.backtrace(2)
+ locations1[2..-1].length.should == locations2.length
+ locations1[2..-1].map(&:to_s).should == locations2.map(&:to_s)
+ end
+
+ it "can be called with a maximum number of locations to return as second parameter" do
+ locations1 = Thread.current.backtrace
+ locations2 = Thread.current.backtrace(2, 3)
+ locations1[2..4].map(&:to_s).should == locations2.map(&:to_s)
+ end
+
+ it "can be called with a range" do
+ locations1 = Thread.current.backtrace
+ locations2 = Thread.current.backtrace(2..4)
+ locations1[2..4].map(&:to_s).should == locations2.map(&:to_s)
+ end
+
+ it "can be called with a range whose end is negative" do
+ Thread.current.backtrace(2..-1).should == Thread.current.backtrace[2..-1]
+ Thread.current.backtrace(2..-2).should == Thread.current.backtrace[2..-2]
+ end
+
+ it "returns nil if omitting more locations than available" do
+ Thread.current.backtrace(100).should == nil
+ Thread.current.backtrace(100..-1).should == nil
+ end
+
+ it "returns [] if omitting exactly the number of locations available" do
+ omit = Thread.current.backtrace.length
+ Thread.current.backtrace(omit).should == []
+ end
end
diff --git a/spec/ruby/core/thread/current_spec.rb b/spec/ruby/core/thread/current_spec.rb
index cc969b71c4..f893f078ba 100644
--- a/spec/ruby/core/thread/current_spec.rb
+++ b/spec/ruby/core/thread/current_spec.rb
@@ -1,15 +1,31 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Thread.current" do
it "returns a thread" do
current = Thread.current
- current.should be_kind_of(Thread)
+ current.should.is_a?(Thread)
end
it "returns the current thread" do
t = Thread.new { Thread.current }
- t.value.should equal(t)
- Thread.current.should_not equal(t.value)
+ 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/each_caller_location_spec.rb b/spec/ruby/core/thread/each_caller_location_spec.rb
new file mode 100644
index 0000000000..15fda1a37b
--- /dev/null
+++ b/spec/ruby/core/thread/each_caller_location_spec.rb
@@ -0,0 +1,47 @@
+require_relative '../../spec_helper'
+
+describe "Thread.each_caller_location" do
+ it "iterates through the current execution stack and matches caller_locations content and type" do
+ ScratchPad.record []
+ Thread.each_caller_location { |l| ScratchPad << l; }
+
+ ScratchPad.recorded.map(&:to_s).should == caller_locations.map(&:to_s)
+ ScratchPad.recorded[0].should.is_a?(Thread::Backtrace::Location)
+ end
+
+ it "returns subset of 'Thread.to_enum(:each_caller_location)' locations" do
+ ar = []
+ ecl = Thread.each_caller_location { |x| ar << x }
+
+ (ar.map(&:to_s) - Thread.to_enum(:each_caller_location).to_a.map(&:to_s)).should.empty?
+ end
+
+ it "stops the backtrace iteration if 'break' occurs" do
+ i = 0
+ ar = []
+ ecl = Thread.each_caller_location do |x|
+ ar << x
+ i += 1
+ break x if i == 2
+ end
+
+ ar.map(&:to_s).should == caller_locations(1, 2).map(&:to_s)
+ ecl.should.is_a?(Thread::Backtrace::Location)
+ end
+
+ it "returns nil" do
+ Thread.each_caller_location {}.should == nil
+ end
+
+ it "raises LocalJumpError when called without a block" do
+ -> {
+ Thread.each_caller_location
+ }.should.raise(LocalJumpError, "no block given")
+ end
+
+ it "doesn't accept keyword arguments" do
+ -> {
+ Thread.each_caller_location(12, foo: 10) {}
+ }.should.raise(ArgumentError);
+ end
+end
diff --git a/spec/ruby/core/thread/element_reference_spec.rb b/spec/ruby/core/thread/element_reference_spec.rb
index 81b11d2c09..72892f6c50 100644
--- a/spec/ruby/core/thread/element_reference_spec.rb
+++ b/spec/ruby/core/thread/element_reference_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Thread#[]" do
it "gives access to thread local values" do
@@ -37,8 +37,19 @@ describe "Thread#[]" do
t2["value"].should == 2
end
+ it "converts a key that is neither String nor Symbol with #to_str" do
+ key = mock('value')
+ key.should_receive(:to_str).and_return('value')
+
+ th = Thread.new do
+ Thread.current[:value] = 1
+ end.join
+
+ th[key].should == 1
+ end
+
it "raises exceptions on the wrong type of keys" do
- lambda { Thread.current[nil] }.should raise_error(TypeError)
- lambda { Thread.current[5] }.should raise_error(TypeError)
+ -> { Thread.current[nil] }.should.raise(TypeError)
+ -> { Thread.current[5] }.should.raise(TypeError)
end
end
diff --git a/spec/ruby/core/thread/element_set_spec.rb b/spec/ruby/core/thread/element_set_spec.rb
index b76078f685..97d6c23980 100644
--- a/spec/ruby/core/thread/element_set_spec.rb
+++ b/spec/ruby/core/thread/element_set_spec.rb
@@ -1,25 +1,47 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Thread#[]=" do
after :each do
Thread.current[:value] = nil
end
- it "raises a RuntimeError if the thread is frozen" do
- running = false
- t = Thread.new do
- t.freeze
+ it "raises a FrozenError if the thread is frozen" do
+ Thread.new do
+ th = Thread.current
+ th.freeze
-> {
- t[:foo] = "bar"
- }.should raise_error(RuntimeError, /frozen/)
- end
- t.join
+ th[:foo] = "bar"
+ }.should.raise(FrozenError, "can't modify frozen thread locals")
+ end.join
+ end
+
+ it "accepts Strings and Symbols" do
+ t1 = Thread.new do
+ Thread.current[:value] = 1
+ end.join
+ t2 = Thread.new do
+ Thread.current["value"] = 2
+ end.join
+
+ t1[:value].should == 1
+ t2[:value].should == 2
+ end
+
+ it "converts a key that is neither String nor Symbol with #to_str" do
+ key = mock('value')
+ key.should_receive(:to_str).and_return('value')
+
+ th = Thread.new do
+ Thread.current[key] = 1
+ end.join
+
+ th[:value].should == 1
end
it "raises exceptions on the wrong type of keys" do
- lambda { Thread.current[nil] = true }.should raise_error(TypeError)
- lambda { Thread.current[5] = true }.should raise_error(TypeError)
+ -> { Thread.current[nil] = true }.should.raise(TypeError)
+ -> { Thread.current[5] = true }.should.raise(TypeError)
end
it "is not shared across fibers" do
@@ -29,7 +51,7 @@ describe "Thread#[]=" do
Thread.current[:value].should == 1
end
fib.resume
- Thread.current[:value].should be_nil
+ Thread.current[:value].should == nil
Thread.current[:value] = 2
fib.resume
Thread.current[:value] = 2
diff --git a/spec/ruby/core/thread/exclusive_spec.rb b/spec/ruby/core/thread/exclusive_spec.rb
deleted file mode 100644
index 66c87f4713..0000000000
--- a/spec/ruby/core/thread/exclusive_spec.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Thread.exclusive" do
- before :each do
- ScratchPad.clear
- end
-
- it "yields to the block" do
- Thread.exclusive { ScratchPad.record true }
- ScratchPad.recorded.should == true
- end
-
- it "returns the result of yielding" do
- Thread.exclusive { :result }.should == :result
- end
-
- it "needs to be reviewed for spec completeness"
-end
diff --git a/spec/ruby/core/thread/exit_spec.rb b/spec/ruby/core/thread/exit_spec.rb
index 0fb329e66f..dbcd889898 100644
--- a/spec/ruby/core/thread/exit_spec.rb
+++ b/spec/ruby/core/thread/exit_spec.rb
@@ -1,6 +1,11 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/exit', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe "Thread#exit" do
+ it "is an alias of Thread#kill" do
+ Thread.instance_method(:exit).should == Thread.instance_method(:kill)
+ end
+end
describe "Thread#exit!" do
it "needs to be reviewed for spec completeness"
@@ -10,6 +15,6 @@ describe "Thread.exit" do
it "causes the current thread to exit" do
thread = Thread.new { Thread.exit; sleep }
thread.join
- thread.status.should be_false
+ thread.status.should == false
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..fe27dec4a2
--- /dev/null
+++ b/spec/ruby/core/thread/fetch_spec.rb
@@ -0,0 +1,66 @@
+require_relative '../../spec_helper'
+
+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(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
+
+ describe 'with a block' 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 block value if fiber-local variable hasn't been assigned" do
+ th = Thread.new {}
+ th.join
+ th.fetch(:cat) { true }.should == true
+ end
+
+ it "does not call the block if value has been assigned" do
+ th = Thread.new { Thread.current[:cat] = 'meow' }
+ th.join
+ var = :not_updated
+ th.fetch(:cat) { var = :updated }.should == 'meow'
+ var.should == :not_updated
+ end
+
+ it "uses the block if a default is given and warns about it" do
+ th = Thread.new {}
+ th.join
+ -> {
+ th.fetch(:cat, false) { true }.should == true
+ }.should complain(/warning: block supersedes default value argument/)
+ end
+ end
+
+ it 'raises an ArgumentError when not passed one or two arguments' do
+ -> { Thread.current.fetch() }.should.raise(ArgumentError)
+ -> { Thread.current.fetch(1, 2, 3) }.should.raise(ArgumentError)
+ end
+end
diff --git a/spec/ruby/core/thread/fixtures/classes.rb b/spec/ruby/core/thread/fixtures/classes.rb
index 601e515e3e..14d5d2f7bf 100644
--- a/spec/ruby/core/thread/fixtures/classes.rb
+++ b/spec/ruby/core/thread/fixtures/classes.rb
@@ -1,10 +1,3 @@
-unless defined? Channel
- require 'thread'
- class Channel < Queue
- alias receive shift
- end
-end
-
module ThreadSpecs
class SubThread < Thread
@@ -13,12 +6,38 @@ module ThreadSpecs
end
end
+ class NewThreadToRaise
+ def self.raise(*args, **kwargs, &block)
+ thread = Thread.new do
+ Thread.current.report_on_exception = false
+
+ if block_given?
+ block.call do
+ sleep
+ end
+ else
+ sleep
+ end
+ end
+
+ Thread.pass until thread.stop?
+
+ thread.raise(*args, **kwargs)
+
+ thread.join
+ ensure
+ thread.kill if thread.alive?
+ Thread.pass while thread.alive? # Thread#kill may not terminate a thread immediately so it may be detected as a leaked one
+ end
+ end
+
class Status
- attr_reader :thread, :inspect, :status
+ attr_reader :thread, :inspect, :status, :to_s
def initialize(thread)
@thread = thread
@alive = thread.alive?
@inspect = thread.inspect
+ @to_s = thread.to_s
@status = thread.status
@stop = thread.stop?
end
@@ -188,7 +207,7 @@ module ThreadSpecs
def self.join_dying_thread_with_outer_ensure(kill_method_name=:kill)
t = dying_thread_with_outer_ensure(kill_method_name) { yield }
- lambda { t.join }.should raise_error(RuntimeError, "In dying thread")
+ -> { t.join }.should.raise(RuntimeError, "In dying thread")
return t
end
diff --git a/spec/ruby/core/thread/fork_spec.rb b/spec/ruby/core/thread/fork_spec.rb
index d321230812..60d574a185 100644
--- a/spec/ruby/core/thread/fork_spec.rb
+++ b/spec/ruby/core/thread/fork_spec.rb
@@ -1,9 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/start', __FILE__)
+require_relative '../../spec_helper'
describe "Thread.fork" do
- describe "Thread.start" do
- it_behaves_like :thread_start, :fork
+ it "is an alias of Thread.start" do
+ Thread.method(:fork).should == Thread.method(:start)
end
end
diff --git a/spec/ruby/core/thread/group_spec.rb b/spec/ruby/core/thread/group_spec.rb
index aecc1422ba..d0d4704b66 100644
--- a/spec/ruby/core/thread/group_spec.rb
+++ b/spec/ruby/core/thread/group_spec.rb
@@ -1,5 +1,16 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+
describe "Thread#group" do
- it "needs to be reviewed for spec completeness"
+ it "returns the default thread group for the main thread" do
+ Thread.main.group.should == ThreadGroup::Default
+ end
+
+ it "returns the thread group explicitly set for this thread" do
+ thread = Thread.new { nil }
+ thread_group = ThreadGroup.new
+ thread_group.add(thread)
+ thread.group.should == thread_group
+ ensure
+ thread.join if thread
+ end
end
diff --git a/spec/ruby/core/thread/handle_interrupt_spec.rb b/spec/ruby/core/thread/handle_interrupt_spec.rb
new file mode 100644
index 0000000000..aa03d4c66d
--- /dev/null
+++ b/spec/ruby/core/thread/handle_interrupt_spec.rb
@@ -0,0 +1,125 @@
+require_relative '../../spec_helper'
+
+describe "Thread.handle_interrupt" do
+ def make_handle_interrupt_thread(interrupt_config, blocking = true)
+ interrupt_class = Class.new(RuntimeError)
+
+ ScratchPad.record []
+
+ in_handle_interrupt = Queue.new
+ can_continue = Queue.new
+
+ thread = Thread.new do
+ begin
+ Thread.handle_interrupt(interrupt_config) do
+ begin
+ in_handle_interrupt << true
+ if blocking
+ Thread.pass # Make it clearer the other thread needs to wait for this one to be in #pop
+ can_continue.pop
+ else
+ begin
+ can_continue.pop(true)
+ rescue ThreadError
+ Thread.pass
+ retry
+ end
+ end
+ rescue interrupt_class
+ ScratchPad << :interrupted
+ end
+ end
+ rescue interrupt_class
+ ScratchPad << :deferred
+ end
+ end
+
+ in_handle_interrupt.pop
+ if blocking
+ # Ensure the thread is inside Thread#pop, as if thread.raise is done before it would be deferred
+ Thread.pass until thread.stop?
+ end
+ thread.raise interrupt_class, "interrupt"
+ can_continue << true
+ thread.join
+
+ ScratchPad.recorded
+ end
+
+ before :each do
+ Thread.pending_interrupt?.should == false # sanity check
+ end
+
+ it "with :never defers interrupts until exiting the handle_interrupt block" do
+ make_handle_interrupt_thread(RuntimeError => :never).should == [:deferred]
+ end
+
+ it "with :on_blocking defers interrupts until the next blocking call" do
+ make_handle_interrupt_thread(RuntimeError => :on_blocking).should == [:interrupted]
+ make_handle_interrupt_thread({ RuntimeError => :on_blocking }, false).should == [:deferred]
+ end
+
+ it "with :immediate handles interrupts immediately" do
+ make_handle_interrupt_thread(RuntimeError => :immediate).should == [:interrupted]
+ end
+
+ it "with :immediate immediately runs pending interrupts, before the block" do
+ Thread.handle_interrupt(RuntimeError => :never) do
+ current = Thread.current
+ Thread.new {
+ current.raise "interrupt immediate"
+ }.join
+
+ Thread.pending_interrupt?.should == true
+ -> {
+ Thread.handle_interrupt(RuntimeError => :immediate) {
+ flunk "not reached"
+ }
+ }.should.raise(RuntimeError, "interrupt immediate")
+ Thread.pending_interrupt?.should == false
+ end
+ end
+
+ it "also works with suspended Fibers and does not duplicate interrupts" do
+ fiber = Fiber.new { Fiber.yield }
+ fiber.resume
+
+ Thread.handle_interrupt(RuntimeError => :never) do
+ current = Thread.current
+ Thread.new {
+ current.raise "interrupt with fibers"
+ }.join
+
+ Thread.pending_interrupt?.should == true
+ -> {
+ Thread.handle_interrupt(RuntimeError => :immediate) {
+ flunk "not reached"
+ }
+ }.should.raise(RuntimeError, "interrupt with fibers")
+ Thread.pending_interrupt?.should == false
+ end
+
+ fiber.resume
+ end
+
+ it "runs pending interrupts at the end of the block, even if there was an exception raised in the block" do
+ executed = false
+ -> {
+ Thread.handle_interrupt(RuntimeError => :never) do
+ current = Thread.current
+ Thread.new {
+ current.raise "interrupt exception"
+ }.join
+
+ Thread.pending_interrupt?.should == true
+ executed = true
+ raise "regular exception"
+ end
+ }.should.raise(RuntimeError, "interrupt exception")
+ executed.should == true
+ end
+
+ it "supports multiple pairs in the Hash" do
+ make_handle_interrupt_thread(ArgumentError => :never, RuntimeError => :never).should == [:deferred]
+ end
+end
diff --git a/spec/ruby/core/thread/ignore_deadlock_spec.rb b/spec/ruby/core/thread/ignore_deadlock_spec.rb
new file mode 100644
index 0000000000..b48bc9f9b0
--- /dev/null
+++ b/spec/ruby/core/thread/ignore_deadlock_spec.rb
@@ -0,0 +1,19 @@
+require_relative '../../spec_helper'
+
+describe "Thread.ignore_deadlock" do
+ it "returns false by default" do
+ Thread.ignore_deadlock.should == false
+ end
+end
+
+describe "Thread.ignore_deadlock=" do
+ it "changes the value of Thread.ignore_deadlock" do
+ ignore_deadlock = Thread.ignore_deadlock
+ Thread.ignore_deadlock = true
+ begin
+ Thread.ignore_deadlock.should == true
+ ensure
+ Thread.ignore_deadlock = ignore_deadlock
+ end
+ end
+end
diff --git a/spec/ruby/core/thread/initialize_spec.rb b/spec/ruby/core/thread/initialize_spec.rb
index b6345f03de..b9a94560ee 100644
--- a/spec/ruby/core/thread/initialize_spec.rb
+++ b/spec/ruby/core/thread/initialize_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Thread#initialize" do
@@ -15,11 +15,11 @@ describe "Thread#initialize" do
end
it "raises a ThreadError" do
- lambda {
+ -> {
@t.instance_eval do
initialize {}
end
- }.should raise_error(ThreadError)
+ }.should.raise(ThreadError)
end
end
diff --git a/spec/ruby/core/thread/inspect_spec.rb b/spec/ruby/core/thread/inspect_spec.rb
index 95e598eb6a..fee401830a 100644
--- a/spec/ruby/core/thread/inspect_spec.rb
+++ b/spec/ruby/core/thread/inspect_spec.rb
@@ -1,44 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
describe "Thread#inspect" do
- it "can check it's own status" do
- ThreadSpecs.status_of_current_thread.inspect.should include('run')
- end
-
- it "describes a running thread" do
- ThreadSpecs.status_of_running_thread.inspect.should include('run')
- end
-
- it "describes a sleeping thread" do
- ThreadSpecs.status_of_sleeping_thread.inspect.should include('sleep')
- end
-
- it "describes a blocked thread" do
- ThreadSpecs.status_of_blocked_thread.inspect.should include('sleep')
- end
-
- it "describes a completed thread" do
- ThreadSpecs.status_of_completed_thread.inspect.should include('dead')
- end
-
- it "describes a killed thread" do
- ThreadSpecs.status_of_killed_thread.inspect.should include('dead')
- end
-
- it "describes a thread with an uncaught exception" do
- ThreadSpecs.status_of_thread_with_uncaught_exception.inspect.should include('dead')
- end
-
- it "describes a dying sleeping thread" do
- ThreadSpecs.status_of_dying_sleeping_thread.inspect.should include('sleep')
- end
-
- it "reports aborting on a killed thread" do
- ThreadSpecs.status_of_dying_running_thread.inspect.should include('aborting')
- end
-
- it "reports aborting on a killed thread after sleep" do
- ThreadSpecs.status_of_dying_thread_after_sleep.inspect.should include('aborting')
+ it "is an alias of Thread#to_s" do
+ Thread.instance_method(:inspect).should == Thread.instance_method(:to_s)
end
end
diff --git a/spec/ruby/core/thread/join_spec.rb b/spec/ruby/core/thread/join_spec.rb
index 249b3d333e..f4332167f1 100644
--- a/spec/ruby/core/thread/join_spec.rb
+++ b/spec/ruby/core/thread/join_spec.rb
@@ -1,46 +1,51 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Thread#join" do
it "returns the thread when it is finished" do
t = Thread.new {}
- t.join.should equal(t)
+ t.join.should.equal?(t)
end
it "returns the thread when it is finished when given a timeout" do
t = Thread.new {}
t.join
- t.join(0).should equal(t)
+ t.join(0).should.equal?(t)
end
it "coerces timeout to a Float if it is not nil" do
t = Thread.new {}
t.join
- t.join(0).should equal(t)
- t.join(0.0).should equal(t)
- t.join(nil).should equal(t)
- lambda { t.join(:foo) }.should raise_error TypeError
- lambda { t.join("bar") }.should raise_error TypeError
+ t.join(0).should.equal?(t)
+ t.join(0.0).should.equal?(t)
+ t.join(nil).should.equal?(t)
+ end
+
+ it "raises TypeError if the argument is not a valid timeout" do
+ t = Thread.new { }
+ t.join
+ -> { t.join(:foo) }.should.raise TypeError
+ -> { t.join("bar") }.should.raise TypeError
end
it "returns nil if it is not finished when given a timeout" do
- c = Channel.new
- t = Thread.new { c.receive }
+ q = Queue.new
+ t = Thread.new { q.pop }
begin
t.join(0).should == nil
ensure
- c << true
+ q << true
end
t.join.should == t
end
it "accepts a floating point timeout length" do
- c = Channel.new
- t = Thread.new { c.receive }
+ q = Queue.new
+ t = Thread.new { q.pop }
begin
t.join(0.01).should == nil
ensure
- c << true
+ q << true
end
t.join.should == t
end
@@ -50,16 +55,16 @@ describe "Thread#join" do
Thread.current.report_on_exception = false
raise NotImplementedError.new("Just kidding")
}
- lambda { t.join }.should raise_error(NotImplementedError)
+ -> { t.join }.should.raise(NotImplementedError)
end
it "returns the dead thread" do
t = Thread.new { Thread.current.kill }
- t.join.should equal(t)
+ t.join.should.equal?(t)
end
it "raises any uncaught exception encountered in ensure block" do
t = ThreadSpecs.dying_thread_ensures { raise NotImplementedError.new("Just kidding") }
- lambda { t.join }.should raise_error(NotImplementedError)
+ -> { t.join }.should.raise(NotImplementedError)
end
end
diff --git a/spec/ruby/core/thread/key_spec.rb b/spec/ruby/core/thread/key_spec.rb
index d82a21ab39..a14aeb8d31 100644
--- a/spec/ruby/core/thread/key_spec.rb
+++ b/spec/ruby/core/thread/key_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Thread#key?" do
before :each do
@@ -16,31 +16,38 @@ describe "Thread#key?" do
@th.key?(:stanley.to_s).should == false
end
+ it "converts a key that is neither String nor Symbol with #to_str" do
+ key = mock('key')
+ key.should_receive(:to_str).and_return('oliver')
+
+ @th.key?(key).should == true
+ end
+
it "raises exceptions on the wrong type of keys" do
- lambda { Thread.current.key? nil }.should raise_error(TypeError)
- lambda { Thread.current.key? 5 }.should raise_error(TypeError)
+ -> { Thread.current.key? nil }.should.raise(TypeError)
+ -> { Thread.current.key? 5 }.should.raise(TypeError)
end
it "is not shared across fibers" do
fib = Fiber.new do
Thread.current[:val1] = 1
Fiber.yield
- Thread.current.key?(:val1).should be_true
- Thread.current.key?(:val2).should be_false
+ Thread.current.key?(:val1).should == true
+ Thread.current.key?(:val2).should == false
end
- Thread.current.key?(:val1).should_not be_true
+ Thread.current.key?(:val1).should_not == true
fib.resume
Thread.current[:val2] = 2
fib.resume
- Thread.current.key?(:val1).should be_false
- Thread.current.key?(:val2).should be_true
+ Thread.current.key?(:val1).should == false
+ Thread.current.key?(:val2).should == true
end
it "stores a local in another thread when in a fiber" do
fib = Fiber.new do
t = Thread.new do
sleep
- Thread.current.key?(:value).should be_true
+ Thread.current.key?(:value).should == true
end
Thread.pass while t.status and t.status != "sleep"
diff --git a/spec/ruby/core/thread/keys_spec.rb b/spec/ruby/core/thread/keys_spec.rb
index 0fc8184e06..3a2edd2456 100644
--- a/spec/ruby/core/thread/keys_spec.rb
+++ b/spec/ruby/core/thread/keys_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Thread#keys" do
it "returns an array of the names of the thread-local variables as symbols" do
@@ -16,22 +16,22 @@ describe "Thread#keys" do
fib = Fiber.new do
Thread.current[:val1] = 1
Fiber.yield
- Thread.current.keys.should include(:val1)
- Thread.current.keys.should_not include(:val2)
+ Thread.current.keys.should.include?(:val1)
+ Thread.current.keys.should_not.include?(:val2)
end
- Thread.current.keys.should_not include(:val1)
+ Thread.current.keys.should_not.include?(:val1)
fib.resume
Thread.current[:val2] = 2
fib.resume
- Thread.current.keys.should include(:val2)
- Thread.current.keys.should_not include(:val1)
+ Thread.current.keys.should.include?(:val2)
+ Thread.current.keys.should_not.include?(:val1)
end
it "stores a local in another thread when in a fiber" do
fib = Fiber.new do
t = Thread.new do
sleep
- Thread.current.keys.should include(:value)
+ Thread.current.keys.should.include?(:value)
end
Thread.pass while t.status and t.status != "sleep"
diff --git a/spec/ruby/core/thread/kill_spec.rb b/spec/ruby/core/thread/kill_spec.rb
index cf71307af5..907cc5c4d8 100644
--- a/spec/ruby/core/thread/kill_spec.rb
+++ b/spec/ruby/core/thread/kill_spec.rb
@@ -1,21 +1,230 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/exit', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
-describe "Thread#kill" do
- it_behaves_like :thread_exit, :kill
-end
+# This spec randomly kills mspec worker like: https://ci.appveyor.com/project/ruby/ruby/builds/19473223/job/f69derxnlo09xhuj
+# TODO: Investigate the cause or at least print helpful logs, and remove this `platform_is_not` guard.
+platform_is_not :mingw do
+ describe "Thread#kill" do
+ before :each do
+ ScratchPad.clear
+ end
-describe "Thread#kill!" do
- it "needs to be reviewed for spec completeness"
-end
+ it "kills sleeping thread" do
+ sleeping_thread = Thread.new do
+ sleep
+ ScratchPad.record :after_sleep
+ end
+ Thread.pass while sleeping_thread.status and sleeping_thread.status != "sleep"
+ sleeping_thread.kill
+ sleeping_thread.join
+ ScratchPad.recorded.should == nil
+ end
+
+ it "kills current thread" do
+ thread = Thread.new do
+ Thread.current.kill
+ ScratchPad.record :after_sleep
+ end
+ thread.join
+ ScratchPad.recorded.should == nil
+ end
+
+ it "runs ensure clause" do
+ thread = ThreadSpecs.dying_thread_ensures(:kill) { ScratchPad.record :in_ensure_clause }
+ thread.join
+ ScratchPad.recorded.should == :in_ensure_clause
+ end
+
+ it "runs nested ensure clauses" do
+ ScratchPad.record []
+ @outer = Thread.new do
+ begin
+ @inner = Thread.new do
+ begin
+ sleep
+ ensure
+ ScratchPad << :inner_ensure_clause
+ end
+ end
+ sleep
+ ensure
+ ScratchPad << :outer_ensure_clause
+ @inner.kill
+ @inner.join
+ end
+ end
+ Thread.pass while @outer.status and @outer.status != "sleep"
+ Thread.pass until @inner
+ Thread.pass while @inner.status and @inner.status != "sleep"
+ @outer.kill
+ @outer.join
+ ScratchPad.recorded.should.include?(:inner_ensure_clause)
+ ScratchPad.recorded.should.include?(:outer_ensure_clause)
+ end
+
+ it "does not set $!" do
+ thread = ThreadSpecs.dying_thread_ensures(:kill) { ScratchPad.record $! }
+ thread.join
+ ScratchPad.recorded.should == nil
+ end
+
+ it "does not reset $!" do
+ ScratchPad.record []
+
+ exc = RuntimeError.new("foo")
+ thread = Thread.new do
+ begin
+ raise exc
+ ensure
+ ScratchPad << $!
+ begin
+ Thread.current.kill
+ ensure
+ ScratchPad << $!
+ end
+ end
+ end
+ thread.join
+ ScratchPad.recorded.should == [exc, exc]
+ end
+
+ it "cannot be rescued" do
+ thread = Thread.new do
+ begin
+ Thread.current.kill
+ rescue Exception
+ ScratchPad.record :in_rescue
+ end
+ ScratchPad.record :end_of_thread_block
+ end
+
+ thread.join
+ ScratchPad.recorded.should == nil
+ end
+
+ it "kills the entire thread when a fiber is active" do
+ t = Thread.new do
+ Fiber.new do
+ sleep
+ end.resume
+ ScratchPad.record :fiber_resumed
+ end
+ Thread.pass while t.status and t.status != "sleep"
+ t.kill
+ t.join
+ ScratchPad.recorded.should == nil
+ end
+
+ it "kills other fibers of that thread without running their ensure clauses" do
+ t = Thread.new do
+ f = Fiber.new do
+ ScratchPad.record :fiber_resumed
+ begin
+ Fiber.yield
+ ensure
+ ScratchPad.record :fiber_ensure
+ end
+ end
+ f.resume
+ sleep
+ end
+ Thread.pass until t.stop?
+ t.kill
+ t.join
+ ScratchPad.recorded.should == :fiber_resumed
+ end
+
+ # This spec is a mess. It fails randomly, it hangs on MRI, it needs to be removed
+ quarantine! do
+ it "killing dying running does nothing" do
+ in_ensure_clause = false
+ exit_loop = true
+ t = ThreadSpecs.dying_thread_ensures do
+ in_ensure_clause = true
+ loop { if exit_loop then break end }
+ ScratchPad.record :after_stop
+ end
+
+ Thread.pass until in_ensure_clause == true
+ 10.times { t.kill; Thread.pass }
+ exit_loop = true
+ t.join
+ ScratchPad.recorded.should == :after_stop
+ end
+ end
+
+ quarantine! do
+
+ it "propagates inner exception to Thread.join if there is an outer ensure clause" do
+ thread = ThreadSpecs.dying_thread_with_outer_ensure(:kill) { }
+ -> { thread.join }.should.raise(RuntimeError, "In dying thread")
+ end
+
+ it "runs all outer ensure clauses even if inner ensure clause raises exception" do
+ ThreadSpecs.join_dying_thread_with_outer_ensure(:kill) { ScratchPad.record :in_outer_ensure_clause }
+ ScratchPad.recorded.should == :in_outer_ensure_clause
+ end
+
+ it "sets $! in outer ensure clause if inner ensure clause raises exception" do
+ ThreadSpecs.join_dying_thread_with_outer_ensure(:kill) { ScratchPad.record $! }
+ ScratchPad.recorded.to_s.should == "In dying thread"
+ end
+ end
+
+ it "can be rescued by outer rescue clause when inner ensure clause raises exception" do
+ thread = Thread.new do
+ begin
+ begin
+ Thread.current.kill
+ ensure
+ raise "In dying thread"
+ end
+ rescue Exception
+ ScratchPad.record $!
+ end
+ :end_of_thread_block
+ end
+
+ thread.value.should == :end_of_thread_block
+ ScratchPad.recorded.to_s.should == "In dying thread"
+ end
+
+ it "is deferred if ensure clause does Thread.stop" do
+ ThreadSpecs.wakeup_dying_sleeping_thread(:kill) { Thread.stop; ScratchPad.record :after_sleep }
+ ScratchPad.recorded.should == :after_sleep
+ end
+
+ # Hangs on 1.8.6.114 OS X, possibly also on Linux
+ quarantine! do
+ it "is deferred if ensure clause sleeps" do
+ ThreadSpecs.wakeup_dying_sleeping_thread(:kill) { sleep; ScratchPad.record :after_sleep }
+ ScratchPad.recorded.should == :after_sleep
+ end
+ end
+
+ # This case occurred in JRuby where native threads are used to provide
+ # the same behavior as MRI green threads. Key to this issue was the fact
+ # that the thread which called #exit in its block was also being explicitly
+ # sent #join from outside the thread. The 100.times provides a certain
+ # probability that the deadlock will occur. It was sufficient to reliably
+ # reproduce the deadlock in JRuby.
+ it "does not deadlock when called from within the thread while being joined from without" do
+ 100.times do
+ t = Thread.new { Thread.stop; Thread.current.kill }
+ Thread.pass while t.status and t.status != "sleep"
+ t.wakeup.should == t
+ t.join.should == t
+ end
+ end
+ end
-describe "Thread.kill" do
- it "causes the given thread to exit" do
- thread = Thread.new { sleep }
- Thread.pass while thread.status and thread.status != "sleep"
- Thread.kill(thread).should == thread
- thread.join
- thread.status.should be_false
+ describe "Thread.kill" do
+ it "causes the given thread to exit" do
+ thread = Thread.new { sleep }
+ Thread.pass while thread.status and thread.status != "sleep"
+ Thread.kill(thread).should == thread
+ thread.join
+ thread.status.should == false
+ end
end
end
diff --git a/spec/ruby/core/thread/list_spec.rb b/spec/ruby/core/thread/list_spec.rb
index b8deb98260..5036841d58 100644
--- a/spec/ruby/core/thread/list_spec.rb
+++ b/spec/ruby/core/thread/list_spec.rb
@@ -1,17 +1,17 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Thread.list" do
it "includes the current and main thread" do
- Thread.list.should include(Thread.current)
- Thread.list.should include(Thread.main)
+ Thread.list.should.include?(Thread.current)
+ Thread.list.should.include?(Thread.main)
end
it "includes threads of non-default thread groups" do
t = Thread.new { sleep }
begin
ThreadGroup.new.add(t)
- Thread.list.should include(t)
+ Thread.list.should.include?(t)
ensure
t.kill
t.join
@@ -21,22 +21,35 @@ describe "Thread.list" do
it "does not include deceased threads" do
t = Thread.new { 1; }
t.join
- Thread.list.should_not include(t)
+ Thread.list.should_not.include?(t)
end
it "includes waiting threads" do
- c = Channel.new
- t = Thread.new { c.receive }
+ q = Queue.new
+ t = Thread.new { q.pop }
begin
Thread.pass while t.status and t.status != 'sleep'
- Thread.list.should include(t)
+ Thread.list.should.include?(t)
ensure
- c << nil
+ q << nil
t.join
end
end
-end
-describe "Thread.list" do
- it "needs to be reviewed for spec completeness"
+ it "returns instances of Thread and not null or nil values" do
+ spawner = Thread.new do
+ Array.new(100) do
+ Thread.new {}
+ end
+ end
+
+ begin
+ Thread.list.each { |th|
+ th.should.is_a?(Thread)
+ }
+ end while spawner.alive?
+
+ threads = spawner.value
+ threads.each(&:join)
+ end
end
diff --git a/spec/ruby/core/thread/main_spec.rb b/spec/ruby/core/thread/main_spec.rb
index 0cada8f59d..ec91709576 100644
--- a/spec/ruby/core/thread/main_spec.rb
+++ b/spec/ruby/core/thread/main_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Thread.main" do
it "returns the main thread" do
diff --git a/spec/ruby/core/thread/name_spec.rb b/spec/ruby/core/thread/name_spec.rb
index 0417d7a500..47d807be4d 100644
--- a/spec/ruby/core/thread/name_spec.rb
+++ b/spec/ruby/core/thread/name_spec.rb
@@ -1,56 +1,54 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-ruby_version_is '2.3' do
- describe "Thread#name" do
- before :each do
- @thread = Thread.new {}
- end
-
- after :each do
- @thread.join
- end
-
- it "is nil initially" do
- @thread.name.should == nil
- end
-
- it "returns the thread name" do
- @thread.name = "thread_name"
- @thread.name.should == "thread_name"
- end
- end
-
- describe "Thread#name=" do
- before :each do
- @thread = Thread.new {}
- end
-
- after :each do
- @thread.join
- end
-
- it "can be set to a String" do
- @thread.name = "new thread name"
- @thread.name.should == "new thread name"
- end
-
- it "raises an ArgumentError if the name includes a null byte" do
- lambda {
- @thread.name = "new thread\0name"
- }.should raise_error(ArgumentError)
- end
-
- it "can be reset to nil" do
- @thread.name = nil
- @thread.name.should == nil
- end
-
- it "calls #to_str to convert name to String" do
- name = mock("Thread#name")
- name.should_receive(:to_str).and_return("a thread name")
-
- @thread.name = name
- @thread.name.should == "a thread name"
- end
+require_relative '../../spec_helper'
+
+describe "Thread#name" do
+ before :each do
+ @thread = Thread.new {}
+ end
+
+ after :each do
+ @thread.join
+ end
+
+ it "is nil initially" do
+ @thread.name.should == nil
+ end
+
+ it "returns the thread name" do
+ @thread.name = "thread_name"
+ @thread.name.should == "thread_name"
+ end
+end
+
+describe "Thread#name=" do
+ before :each do
+ @thread = Thread.new {}
+ end
+
+ after :each do
+ @thread.join
+ end
+
+ it "can be set to a String" do
+ @thread.name = "new thread name"
+ @thread.name.should == "new thread name"
+ end
+
+ it "raises an ArgumentError if the name includes a null byte" do
+ -> {
+ @thread.name = "new thread\0name"
+ }.should.raise(ArgumentError)
+ end
+
+ it "can be reset to nil" do
+ @thread.name = nil
+ @thread.name.should == nil
+ end
+
+ it "calls #to_str to convert name to String" do
+ name = mock("Thread#name")
+ name.should_receive(:to_str).and_return("a thread name")
+
+ @thread.name = name
+ @thread.name.should == "a thread name"
end
end
diff --git a/spec/ruby/core/thread/native_thread_id_spec.rb b/spec/ruby/core/thread/native_thread_id_spec.rb
new file mode 100644
index 0000000000..cc72e0b853
--- /dev/null
+++ b/spec/ruby/core/thread/native_thread_id_spec.rb
@@ -0,0 +1,31 @@
+require_relative '../../spec_helper'
+
+platform_is :linux, :darwin, :windows, :freebsd do
+ describe "Thread#native_thread_id" do
+ it "returns an integer when the thread is alive" do
+ Thread.current.native_thread_id.should.is_a?(Integer)
+ end
+
+ it "returns nil when the thread is not running" do
+ t = Thread.new {}
+ t.join
+ t.native_thread_id.should == nil
+ end
+
+ it "each thread has different native thread id" do
+ t = Thread.new { sleep }
+ Thread.pass until t.stop?
+ main_thread_id = Thread.current.native_thread_id
+ t_thread_id = t.native_thread_id
+
+ # native_thread_id can be nil on a M:N scheduler
+ t_thread_id.should.is_a?(Integer) if t_thread_id != nil
+
+ main_thread_id.should_not == t_thread_id
+
+ t.run
+ t.join
+ t.native_thread_id.should == nil
+ end
+ end
+end
diff --git a/spec/ruby/core/thread/new_spec.rb b/spec/ruby/core/thread/new_spec.rb
index b1ed5560a1..acb6cd4e30 100644
--- a/spec/ruby/core/thread/new_spec.rb
+++ b/spec/ruby/core/thread/new_spec.rb
@@ -1,12 +1,12 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Thread.new" do
it "creates a thread executing the given block" do
- c = Channel.new
- Thread.new { c << true }.join
- c << false
- c.receive.should == true
+ q = Queue.new
+ Thread.new { q << true }.join
+ q << false
+ q.pop.should == true
end
it "can pass arguments to the thread block" do
@@ -18,7 +18,7 @@ describe "Thread.new" do
end
it "raises an exception when not given a block" do
- lambda { Thread.new }.should raise_error(ThreadError)
+ -> { Thread.new }.should.raise(ThreadError)
end
it "creates a subclass of thread calls super with a block in initialize" do
@@ -34,9 +34,9 @@ describe "Thread.new" do
end
end
- lambda {
+ -> {
c.new
- }.should raise_error(ThreadError)
+ }.should.raise(ThreadError)
end
it "calls and respects #initialize for the block to use" do
@@ -53,4 +53,31 @@ describe "Thread.new" do
ScratchPad.recorded.should == [:good, :in_thread]
end
+ it "releases Mutexes held by the Thread when the Thread finishes" do
+ m1 = Mutex.new
+ m2 = Mutex.new
+ t = Thread.new {
+ m1.lock
+ m1.should.locked?
+ m2.lock
+ m2.should.locked?
+ }
+ t.join
+ m1.should_not.locked?
+ m2.should_not.locked?
+ end
+
+ it "releases Mutexes held by the Thread when the Thread finishes, also with Mutex#synchronize" do
+ m = Mutex.new
+ t = Thread.new {
+ m.synchronize {
+ m.unlock
+ m.lock
+ }
+ m.lock
+ m.should.locked?
+ }
+ t.join
+ m.should_not.locked?
+ end
end
diff --git a/spec/ruby/core/thread/pass_spec.rb b/spec/ruby/core/thread/pass_spec.rb
index 128de934ac..a5ac11a58c 100644
--- a/spec/ruby/core/thread/pass_spec.rb
+++ b/spec/ruby/core/thread/pass_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Thread.pass" do
it "returns nil" do
diff --git a/spec/ruby/core/thread/pending_interrupt_spec.rb b/spec/ruby/core/thread/pending_interrupt_spec.rb
new file mode 100644
index 0000000000..5fbe7422a9
--- /dev/null
+++ b/spec/ruby/core/thread/pending_interrupt_spec.rb
@@ -0,0 +1,32 @@
+require_relative '../../spec_helper'
+
+describe "Thread.pending_interrupt?" do
+ it "returns false if there are no pending interrupts, e.g., outside any Thread.handle_interrupt block" do
+ Thread.pending_interrupt?.should == false
+ end
+
+ it "returns true if there are pending interrupts, e.g., Thread#raise inside Thread.handle_interrupt" do
+ executed = false
+ -> {
+ Thread.handle_interrupt(RuntimeError => :never) do
+ Thread.pending_interrupt?.should == false
+
+ current = Thread.current
+ Thread.new {
+ current.raise "interrupt"
+ }.join
+
+ Thread.pending_interrupt?.should == true
+ executed = true
+ end
+ }.should.raise(RuntimeError, "interrupt")
+ executed.should == true
+ Thread.pending_interrupt?.should == false
+ end
+end
+
+describe "Thread#pending_interrupt?" do
+ it "returns whether the given threads has pending interrupts" do
+ Thread.current.pending_interrupt?.should == false
+ end
+end
diff --git a/spec/ruby/core/thread/priority_spec.rb b/spec/ruby/core/thread/priority_spec.rb
index b986fb7a0d..970f7f9971 100644
--- a/spec/ruby/core/thread/priority_spec.rb
+++ b/spec/ruby/core/thread/priority_spec.rb
@@ -1,42 +1,45 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
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
it "inherits the priority of the current thread while running" do
- @thread.alive?.should be_true
+ @thread.alive?.should == true
@thread.priority.should == @current_priority
end
it "maintain the priority of the current thread after death" do
ThreadSpecs.state = :exit
@thread.join
- @thread.alive?.should be_false
+ @thread.alive?.should == false
@thread.priority.should == @current_priority
end
it "returns an integer" do
- @thread.priority.should be_kind_of(Integer)
+ @thread.priority.should.is_a?(Integer)
end
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
@@ -56,13 +59,14 @@ describe "Thread#priority=" do
describe "when set with a non-integer" do
it "raises a type error" do
- lambda{ @thread.priority = Object.new }.should raise_error(TypeError)
+ ->{ @thread.priority = Object.new }.should.raise(TypeError)
end
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/thread/raise_spec.rb b/spec/ruby/core/thread/raise_spec.rb
index 8724d26202..efc09d4a35 100644
--- a/spec/ruby/core/thread/raise_spec.rb
+++ b/spec/ruby/core/thread/raise_spec.rb
@@ -1,13 +1,23 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../../../shared/kernel/raise', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative '../../shared/kernel/raise'
describe "Thread#raise" do
- it "ignores dead threads" do
+ it "is a public method" do
+ Thread.public_instance_methods.should.include?(:raise)
+ end
+
+ it_behaves_like :kernel_raise, :raise, ThreadSpecs::NewThreadToRaise
+ it_behaves_like :kernel_raise_across_contexts, :raise, ThreadSpecs::NewThreadToRaise
+ ruby_version_is "4.0" do
+ it_behaves_like :kernel_raise_with_cause, :raise, ThreadSpecs::NewThreadToRaise
+ end
+
+ it "ignores dead threads and returns nil" do
t = Thread.new { :dead }
Thread.pass while t.alive?
- lambda {t.raise("Kill the thread")}.should_not raise_error
- lambda {t.value}.should_not raise_error
+ t.raise("Kill the thread").should == nil
+ t.join
end
end
@@ -26,27 +36,27 @@ describe "Thread#raise on a sleeping thread" do
it "raises a RuntimeError if no exception class is given" do
@thr.raise
Thread.pass while @thr.status
- ScratchPad.recorded.should be_kind_of(RuntimeError)
+ ScratchPad.recorded.should.is_a?(RuntimeError)
end
it "raises the given exception" do
@thr.raise Exception
Thread.pass while @thr.status
- ScratchPad.recorded.should be_kind_of(Exception)
+ ScratchPad.recorded.should.is_a?(Exception)
end
it "raises the given exception with the given message" do
@thr.raise Exception, "get to work"
Thread.pass while @thr.status
- ScratchPad.recorded.should be_kind_of(Exception)
+ ScratchPad.recorded.should.is_a?(Exception)
ScratchPad.recorded.message.should == "get to work"
end
it "raises the given exception and the backtrace is the one of the interrupted thread" do
@thr.raise Exception
Thread.pass while @thr.status
- ScratchPad.recorded.should be_kind_of(Exception)
- ScratchPad.recorded.backtrace[0].should include("sleep")
+ ScratchPad.recorded.should.is_a?(Exception)
+ ScratchPad.recorded.backtrace[0].should.include?("sleep")
end
it "is captured and raised by Thread#value" do
@@ -58,7 +68,7 @@ describe "Thread#raise on a sleeping thread" do
ThreadSpecs.spin_until_sleeping(t)
t.raise
- lambda { t.value }.should raise_error(RuntimeError)
+ -> { t.value }.should.raise(RuntimeError)
end
it "raises a RuntimeError when called with no arguments inside rescue" do
@@ -76,7 +86,80 @@ describe "Thread#raise on a sleeping thread" do
ThreadSpecs.spin_until_sleeping(t)
t.raise
end
- lambda {t.value}.should raise_error(RuntimeError)
+ -> { t.value }.should.raise(RuntimeError)
+ end
+
+ it "re-raises a previously rescued exception without overwriting the backtrace" do
+ t = Thread.new do
+ -> { # To make sure there is at least one entry in the call stack
+ begin
+ sleep
+ rescue => e
+ e
+ end
+ }.call
+ end
+
+ ThreadSpecs.spin_until_sleeping(t)
+
+ begin
+ initial_raise_line = __LINE__; raise 'raised'
+ rescue => raised
+ raise_again_line = __LINE__; t.raise raised
+ raised_again = t.value
+
+ raised_again.backtrace.first.should.include?("#{__FILE__}:#{initial_raise_line}:")
+ raised_again.backtrace.first.should_not.include?("#{__FILE__}:#{raise_again_line}:")
+ end
+ end
+
+ it "calls #exception in both the caller and in the target thread" do
+ cls = Class.new(Exception) do
+ attr_accessor :log
+ def initialize(*args)
+ @log = [] # This is shared because the super #exception uses a shallow clone
+ super
+ end
+
+ def exception(*args)
+ @log << [self, Thread.current, args]
+ super
+ end
+ end
+ exc = cls.new
+
+ @thr.raise exc, "Thread#raise #exception spec"
+ @thr.join
+ ScratchPad.recorded.should.is_a?(cls)
+ exc.log.should == [
+ [exc, Thread.current, ["Thread#raise #exception spec"]],
+ [ScratchPad.recorded, @thr, []]
+ ]
+ end
+
+ it "calls #set_backtrace only in the caller thread" do
+ cls = Class.new(Exception) do
+ attr_accessor :log
+ def initialize(*args)
+ @log = [] # This is shared because the super #exception uses a shallow clone
+ super
+ end
+
+ def set_backtrace(backtrace)
+ @log << [Thread.current, backtrace]
+ super
+ end
+ end
+ exc = cls.new
+
+ backtrace = ["a.rb:1"]
+
+ @thr.raise exc, "Thread#raise #set_backtrace spec", backtrace
+ @thr.join
+ ScratchPad.recorded.should.is_a?(cls)
+ exc.log.should == [
+ [Thread.current, backtrace]
+ ]
end
end
@@ -97,30 +180,33 @@ describe "Thread#raise on a running thread" do
it "raises a RuntimeError if no exception class is given" do
@thr.raise
Thread.pass while @thr.status
- ScratchPad.recorded.should be_kind_of(RuntimeError)
+ ScratchPad.recorded.should.is_a?(RuntimeError)
end
it "raises the given exception" do
@thr.raise Exception
Thread.pass while @thr.status
- ScratchPad.recorded.should be_kind_of(Exception)
+ ScratchPad.recorded.should.is_a?(Exception)
end
it "raises the given exception with the given message" do
@thr.raise Exception, "get to work"
Thread.pass while @thr.status
- ScratchPad.recorded.should be_kind_of(Exception)
+ ScratchPad.recorded.should.is_a?(Exception)
ScratchPad.recorded.message.should == "get to work"
end
it "can go unhandled" do
+ q = Queue.new
t = Thread.new do
Thread.current.report_on_exception = false
+ q << true
loop { Thread.pass }
end
+ q.pop # wait for `report_on_exception = false`.
t.raise
- lambda {t.value}.should raise_error(RuntimeError)
+ -> { t.value }.should.raise(RuntimeError)
end
it "raises the given argument even when there is an active exception" do
@@ -139,7 +225,7 @@ describe "Thread#raise on a running thread" do
rescue
Thread.pass until raised
t.raise RangeError
- lambda {t.value}.should raise_error(RangeError)
+ -> { t.value }.should.raise(RangeError)
end
end
@@ -151,7 +237,7 @@ describe "Thread#raise on a running thread" do
1/0
rescue ZeroDivisionError
raised = true
- loop { }
+ loop { Thread.pass }
end
end
begin
@@ -160,7 +246,7 @@ describe "Thread#raise on a running thread" do
Thread.pass until raised
t.raise
end
- lambda {t.value}.should raise_error(RuntimeError)
+ -> { t.value }.should.raise(RuntimeError)
end
end
@@ -176,6 +262,6 @@ describe "Thread#raise on same thread" do
Thread.current.raise
end
end
- lambda {t.value}.should raise_error(RuntimeError)
+ -> { t.value }.should.raise(RuntimeError, '')
end
end
diff --git a/spec/ruby/core/thread/report_on_exception_spec.rb b/spec/ruby/core/thread/report_on_exception_spec.rb
index 4128dad470..9cf5260808 100644
--- a/spec/ruby/core/thread/report_on_exception_spec.rb
+++ b/spec/ruby/core/thread/report_on_exception_spec.rb
@@ -1,102 +1,155 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
-ruby_version_is "2.4" do
- describe "Thread.report_on_exception" do
- it "defaults to false" do
- ruby_exe("p Thread.report_on_exception").should == "false\n"
- end
+describe "Thread.report_on_exception" do
+ it "defaults to true" do
+ ruby_exe("p Thread.report_on_exception").should == "true\n"
end
+end
- describe "Thread.report_on_exception=" do
- before :each do
- @report_on_exception = Thread.report_on_exception
- end
+describe "Thread.report_on_exception=" do
+ before :each do
+ @report_on_exception = Thread.report_on_exception
+ end
- after :each do
- Thread.report_on_exception = @report_on_exception
- end
+ after :each do
+ Thread.report_on_exception = @report_on_exception
+ end
- it "changes the default value for new threads" do
- Thread.report_on_exception = true
- Thread.report_on_exception.should == true
- t = Thread.new {}
- t.join
- t.report_on_exception.should == true
- end
+ it "changes the default value for new threads" do
+ Thread.report_on_exception = true
+ Thread.report_on_exception.should == true
+ t = Thread.new {}
+ t.join
+ t.report_on_exception.should == true
end
+end
- describe "Thread#report_on_exception" do
- it "returns whether the Thread will print a backtrace if it exits with an exception" do
- t = Thread.new { Thread.current.report_on_exception = true }
- t.join
- t.report_on_exception.should == true
+describe "Thread#report_on_exception" do
+ it "returns true for the main Thread" do
+ Thread.current.report_on_exception.should == true
+ end
- t = Thread.new { Thread.current.report_on_exception = false }
- t.join
- t.report_on_exception.should == false
- end
+ it "returns true for new Threads" do
+ Thread.new { Thread.current.report_on_exception }.value.should == true
end
- describe "Thread#report_on_exception=" do
- describe "when set to true" do
- it "prints a backtrace on $stderr if it terminates with an exception" do
- t = nil
- -> {
- t = Thread.new {
- Thread.current.report_on_exception = true
- raise RuntimeError, "Thread#report_on_exception specs"
- }
- Thread.pass while t.alive?
- }.should output("", /Thread.+terminated with exception.+Thread#report_on_exception specs/m)
+ it "returns whether the Thread will print a backtrace if it exits with an exception" do
+ t = Thread.new { Thread.current.report_on_exception = true }
+ t.join
+ t.report_on_exception.should == true
- -> {
- t.join
- }.should raise_error(RuntimeError, "Thread#report_on_exception specs")
+ t = Thread.new { Thread.current.report_on_exception = false }
+ t.join
+ t.report_on_exception.should == false
+ end
+end
+
+describe "Thread#report_on_exception=" do
+ describe "when set to true" do
+ it "prints a backtrace on $stderr if it terminates with an exception" do
+ t = nil
+ -> {
+ t = Thread.new {
+ Thread.current.report_on_exception = true
+ raise RuntimeError, "Thread#report_on_exception specs"
+ }
+ Thread.pass while t.alive?
+ }.should output("", /Thread.+terminated with exception.+Thread#report_on_exception specs/m)
+
+ -> {
+ t.join
+ }.should.raise(RuntimeError, "Thread#report_on_exception specs")
+ end
+
+ it "prints a backtrace on $stderr in the regular backtrace order" do
+ line_raise = __LINE__ + 2
+ def foo
+ raise RuntimeError, "Thread#report_on_exception specs backtrace order"
end
+
+ line_call_foo = __LINE__ + 5
+ go = false
+ t = Thread.new {
+ Thread.current.report_on_exception = true
+ Thread.pass until go
+ foo
+ }
+
+ -> {
+ go = true
+ Thread.pass while t.alive?
+ }.should output("", /\A
+#{Regexp.quote(t.inspect)}\sterminated\swith\sexception\s\(report_on_exception\sis\strue\):\n
+#{Regexp.quote(__FILE__)}:#{line_raise}:in\s[`']foo':\sThread\#report_on_exception\sspecs\sbacktrace\sorder\s\(RuntimeError\)\n
+\tfrom\s#{Regexp.quote(__FILE__)}:#{line_call_foo}:in\s[`']block\s\(4\slevels\)\sin\s<top\s\(required\)>'\n
+\z/x)
+
+ -> {
+ t.join
+ }.should.raise(RuntimeError, "Thread#report_on_exception specs backtrace order")
end
- describe "when set to false" do
- it "lets the thread terminates silently with an exception" do
- t = nil
- -> {
- t = Thread.new {
- Thread.current.report_on_exception = false
- raise RuntimeError, "Thread#report_on_exception specs"
- }
- Thread.pass while t.alive?
- }.should output("", "")
+ it "prints the backtrace even if the thread was killed just after Thread#raise" do
+ t = nil
+ ready = false
+ -> {
+ t = Thread.new {
+ Thread.current.report_on_exception = true
+ ready = true
+ sleep
+ }
- -> {
- t.join
- }.should raise_error(RuntimeError, "Thread#report_on_exception specs")
- end
+ Thread.pass until ready and t.stop?
+ t.raise RuntimeError, "Thread#report_on_exception before kill spec"
+ t.kill
+ Thread.pass while t.alive?
+ }.should output("", /Thread.+terminated with exception.+Thread#report_on_exception before kill spec/m)
+
+ -> {
+ t.join
+ }.should.raise(RuntimeError, "Thread#report_on_exception before kill spec")
end
+ end
- ruby_bug "#13163", "2.4"..."2.5" do
- describe "when used in conjunction with Thread#abort_on_exception" do
- it "first reports then send the exception back to the main Thread" do
- t = nil
- mutex = Mutex.new
+ describe "when set to false" do
+ it "lets the thread terminates silently with an exception" do
+ t = nil
+ -> {
+ t = Thread.new {
+ Thread.current.report_on_exception = false
+ raise RuntimeError, "Thread#report_on_exception specs"
+ }
+ Thread.pass while t.alive?
+ }.should output("", "")
+
+ -> {
+ t.join
+ }.should.raise(RuntimeError, "Thread#report_on_exception specs")
+ end
+ end
+
+ describe "when used in conjunction with Thread#abort_on_exception" do
+ it "first reports then send the exception back to the main Thread" do
+ t = nil
+ mutex = Mutex.new
+ mutex.lock
+ -> {
+ t = Thread.new {
+ Thread.current.abort_on_exception = true
+ Thread.current.report_on_exception = true
mutex.lock
- -> {
- t = Thread.new {
- Thread.current.abort_on_exception = true
- Thread.current.report_on_exception = true
- mutex.lock
- mutex.unlock
- raise RuntimeError, "Thread#report_on_exception specs"
- }
-
- -> {
- mutex.sleep(5)
- }.should raise_error(RuntimeError, "Thread#report_on_exception specs")
- }.should output("", /Thread.+terminated with exception.+Thread#report_on_exception specs/m)
-
- -> {
- t.join
- }.should raise_error(RuntimeError, "Thread#report_on_exception specs")
- end
- end
+ mutex.unlock
+ raise RuntimeError, "Thread#report_on_exception specs"
+ }
+
+ -> {
+ mutex.sleep(5)
+ }.should.raise(RuntimeError, "Thread#report_on_exception specs")
+ }.should output("", /Thread.+terminated with exception.+Thread#report_on_exception specs/m)
+
+ -> {
+ t.join
+ }.should.raise(RuntimeError, "Thread#report_on_exception specs")
end
end
end
diff --git a/spec/ruby/core/thread/run_spec.rb b/spec/ruby/core/thread/run_spec.rb
index 26ed9ed961..f86f793489 100644
--- a/spec/ruby/core/thread/run_spec.rb
+++ b/spec/ruby/core/thread/run_spec.rb
@@ -1,9 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
-require File.expand_path('../shared/wakeup', __FILE__)
+require_relative 'shared/wakeup'
describe "Thread#run" do
it_behaves_like :thread_wakeup, :run
end
-
diff --git a/spec/ruby/core/thread/set_trace_func_spec.rb b/spec/ruby/core/thread/set_trace_func_spec.rb
index 6dd5448d79..e5d8298ae0 100644
--- a/spec/ruby/core/thread/set_trace_func_spec.rb
+++ b/spec/ruby/core/thread/set_trace_func_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Thread#set_trace_func" do
it "needs to be reviewed for spec completeness"
diff --git a/spec/ruby/core/thread/shared/exit.rb b/spec/ruby/core/thread/shared/exit.rb
deleted file mode 100644
index 0c9198c538..0000000000
--- a/spec/ruby/core/thread/shared/exit.rb
+++ /dev/null
@@ -1,176 +0,0 @@
-describe :thread_exit, shared: true do
- before :each do
- ScratchPad.clear
- end
-
- it "kills sleeping thread" do
- sleeping_thread = Thread.new do
- sleep
- ScratchPad.record :after_sleep
- end
- Thread.pass while sleeping_thread.status and sleeping_thread.status != "sleep"
- sleeping_thread.send(@method)
- sleeping_thread.join
- ScratchPad.recorded.should == nil
- end
-
- it "kills current thread" do
- thread = Thread.new do
- Thread.current.send(@method)
- ScratchPad.record :after_sleep
- end
- thread.join
- ScratchPad.recorded.should == nil
- end
-
- it "runs ensure clause" do
- thread = ThreadSpecs.dying_thread_ensures(@method) { ScratchPad.record :in_ensure_clause }
- thread.join
- ScratchPad.recorded.should == :in_ensure_clause
- end
-
- it "runs nested ensure clauses" do
- ScratchPad.record []
- @outer = Thread.new do
- begin
- @inner = Thread.new do
- begin
- sleep
- ensure
- ScratchPad << :inner_ensure_clause
- end
- end
- sleep
- ensure
- ScratchPad << :outer_ensure_clause
- @inner.send(@method)
- @inner.join
- end
- end
- Thread.pass while @outer.status and @outer.status != "sleep"
- Thread.pass until @inner
- Thread.pass while @inner.status and @inner.status != "sleep"
- @outer.send(@method)
- @outer.join
- ScratchPad.recorded.should include(:inner_ensure_clause)
- ScratchPad.recorded.should include(:outer_ensure_clause)
- end
-
- it "does not set $!" do
- thread = ThreadSpecs.dying_thread_ensures(@method) { ScratchPad.record $! }
- thread.join
- ScratchPad.recorded.should == nil
- end
-
- it "cannot be rescued" do
- thread = Thread.new do
- begin
- Thread.current.send(@method)
- rescue Exception
- ScratchPad.record :in_rescue
- end
- ScratchPad.record :end_of_thread_block
- end
-
- thread.join
- ScratchPad.recorded.should == nil
- end
-
- with_feature :fiber do
- it "kills the entire thread when a fiber is active" do
- t = Thread.new do
- Fiber.new do
- sleep
- end.resume
- ScratchPad.record :fiber_resumed
- end
- Thread.pass while t.status and t.status != "sleep"
- t.send(@method)
- t.join
- ScratchPad.recorded.should == nil
- end
- end
-
- # This spec is a mess. It fails randomly, it hangs on MRI, it needs to be removed
- quarantine! do
- it "killing dying running does nothing" do
- in_ensure_clause = false
- exit_loop = true
- t = ThreadSpecs.dying_thread_ensures do
- in_ensure_clause = true
- loop { if exit_loop then break end }
- ScratchPad.record :after_stop
- end
-
- Thread.pass until in_ensure_clause == true
- 10.times { t.send(@method); Thread.pass }
- exit_loop = true
- t.join
- ScratchPad.recorded.should == :after_stop
- end
- end
-
- quarantine! do
-
- it "propagates inner exception to Thread.join if there is an outer ensure clause" do
- thread = ThreadSpecs.dying_thread_with_outer_ensure(@method) { }
- lambda { thread.join }.should raise_error(RuntimeError, "In dying thread")
- end
-
- it "runs all outer ensure clauses even if inner ensure clause raises exception" do
- ThreadSpecs.join_dying_thread_with_outer_ensure(@method) { ScratchPad.record :in_outer_ensure_clause }
- ScratchPad.recorded.should == :in_outer_ensure_clause
- end
-
- it "sets $! in outer ensure clause if inner ensure clause raises exception" do
- ThreadSpecs.join_dying_thread_with_outer_ensure(@method) { ScratchPad.record $! }
- ScratchPad.recorded.to_s.should == "In dying thread"
- end
- end
-
- it "can be rescued by outer rescue clause when inner ensure clause raises exception" do
- thread = Thread.new do
- begin
- begin
- Thread.current.send(@method)
- ensure
- raise "In dying thread"
- end
- rescue Exception
- ScratchPad.record $!
- end
- :end_of_thread_block
- end
-
- thread.value.should == :end_of_thread_block
- ScratchPad.recorded.to_s.should == "In dying thread"
- end
-
- it "is deferred if ensure clause does Thread.stop" do
- ThreadSpecs.wakeup_dying_sleeping_thread(@method) { Thread.stop; ScratchPad.record :after_sleep }
- ScratchPad.recorded.should == :after_sleep
- end
-
- # Hangs on 1.8.6.114 OS X, possibly also on Linux
- quarantine! do
- it "is deferred if ensure clause sleeps" do
- ThreadSpecs.wakeup_dying_sleeping_thread(@method) { sleep; ScratchPad.record :after_sleep }
- ScratchPad.recorded.should == :after_sleep
- end
- end
-
- # This case occurred in JRuby where native threads are used to provide
- # the same behavior as MRI green threads. Key to this issue was the fact
- # that the thread which called #exit in its block was also being explicitly
- # sent #join from outside the thread. The 100.times provides a certain
- # probability that the deadlock will occur. It was sufficient to reliably
- # reproduce the deadlock in JRuby.
- it "does not deadlock when called from within the thread while being joined from without" do
- 100.times do
- t = Thread.new { Thread.stop; Thread.current.send(@method) }
- Thread.pass while t.status and t.status != "sleep"
- t.wakeup.should == t
- t.join.should == t
- end
- end
-end
diff --git a/spec/ruby/core/thread/shared/start.rb b/spec/ruby/core/thread/shared/start.rb
deleted file mode 100644
index 80ce063a0e..0000000000
--- a/spec/ruby/core/thread/shared/start.rb
+++ /dev/null
@@ -1,41 +0,0 @@
-describe :thread_start, shared: true do
- before :each do
- ScratchPad.clear
- end
-
- it "raises an ArgumentError if not passed a block" do
- lambda {
- Thread.send(@method)
- }.should raise_error(ArgumentError)
- end
-
- it "spawns a new Thread running the block" do
- run = false
- t = Thread.send(@method) { run = true }
- t.should be_kind_of(Thread)
- t.join
-
- run.should be_true
- end
-
- it "respects Thread subclasses" do
- c = Class.new(Thread)
- t = c.send(@method) { }
- t.should be_kind_of(c)
-
- t.join
- end
-
- it "does not call #initialize" do
- c = Class.new(Thread) do
- def initialize
- ScratchPad.record :bad
- end
- end
-
- t = c.send(@method) { }
- t.join
-
- ScratchPad.recorded.should == nil
- end
-end
diff --git a/spec/ruby/core/thread/shared/wakeup.rb b/spec/ruby/core/thread/shared/wakeup.rb
index 71838d88e5..c89235ba60 100644
--- a/spec/ruby/core/thread/shared/wakeup.rb
+++ b/spec/ruby/core/thread/shared/wakeup.rb
@@ -36,7 +36,7 @@ describe :thread_wakeup, shared: true do
it "does not result in a deadlock" do
t = Thread.new do
- 100.times { Thread.stop }
+ 10.times { Thread.stop }
end
while t.status
@@ -47,6 +47,7 @@ describe :thread_wakeup, shared: true do
t.status.should == false
end
Thread.pass
+ sleep 0.001
end
t.status.should == false
@@ -56,6 +57,6 @@ describe :thread_wakeup, shared: true do
it "raises a ThreadError when trying to wake up a dead thread" do
t = Thread.new { 1 }
t.join
- lambda { t.send @method }.should raise_error(ThreadError)
+ -> { t.send @method }.should.raise(ThreadError)
end
end
diff --git a/spec/ruby/core/thread/start_spec.rb b/spec/ruby/core/thread/start_spec.rb
index 932e782382..a2ee52180b 100644
--- a/spec/ruby/core/thread/start_spec.rb
+++ b/spec/ruby/core/thread/start_spec.rb
@@ -1,9 +1,43 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/start', __FILE__)
+require_relative '../../spec_helper'
describe "Thread.start" do
- describe "Thread.start" do
- it_behaves_like :thread_start, :start
+ before :each do
+ ScratchPad.clear
+ end
+
+ it "raises an ArgumentError if not passed a block" do
+ -> {
+ Thread.start
+ }.should.raise(ArgumentError)
+ end
+
+ it "spawns a new Thread running the block" do
+ run = false
+ t = Thread.start { run = true }
+ t.should.is_a?(Thread)
+ t.join
+
+ run.should == true
+ end
+
+ it "respects Thread subclasses" do
+ c = Class.new(Thread)
+ t = c.start { }
+ t.should.is_a?(c)
+
+ t.join
+ end
+
+ it "does not call #initialize" do
+ c = Class.new(Thread) do
+ def initialize
+ ScratchPad.record :bad
+ end
+ end
+
+ t = c.start { }
+ t.join
+
+ ScratchPad.recorded.should == nil
end
end
diff --git a/spec/ruby/core/thread/status_spec.rb b/spec/ruby/core/thread/status_spec.rb
index 6cfdf0be40..4fde663c91 100644
--- a/spec/ruby/core/thread/status_spec.rb
+++ b/spec/ruby/core/thread/status_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Thread#status" do
it "can check it's own status" do
diff --git a/spec/ruby/core/thread/stop_spec.rb b/spec/ruby/core/thread/stop_spec.rb
index 0bc99487fd..084ab46ef6 100644
--- a/spec/ruby/core/thread/stop_spec.rb
+++ b/spec/ruby/core/thread/stop_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Thread.stop" do
it "causes the current thread to sleep indefinitely" do
@@ -13,42 +13,42 @@ end
describe "Thread#stop?" do
it "can check it's own status" do
- ThreadSpecs.status_of_current_thread.stop?.should == false
+ ThreadSpecs.status_of_current_thread.should_not.stop?
end
it "describes a running thread" do
- ThreadSpecs.status_of_running_thread.stop?.should == false
+ ThreadSpecs.status_of_running_thread.should_not.stop?
end
it "describes a sleeping thread" do
- ThreadSpecs.status_of_sleeping_thread.stop?.should == true
+ ThreadSpecs.status_of_sleeping_thread.should.stop?
end
it "describes a blocked thread" do
- ThreadSpecs.status_of_blocked_thread.stop?.should == true
+ ThreadSpecs.status_of_blocked_thread.should.stop?
end
it "describes a completed thread" do
- ThreadSpecs.status_of_completed_thread.stop?.should == true
+ ThreadSpecs.status_of_completed_thread.should.stop?
end
it "describes a killed thread" do
- ThreadSpecs.status_of_killed_thread.stop?.should == true
+ ThreadSpecs.status_of_killed_thread.should.stop?
end
it "describes a thread with an uncaught exception" do
- ThreadSpecs.status_of_thread_with_uncaught_exception.stop?.should == true
+ ThreadSpecs.status_of_thread_with_uncaught_exception.should.stop?
end
it "describes a dying running thread" do
- ThreadSpecs.status_of_dying_running_thread.stop?.should == false
+ ThreadSpecs.status_of_dying_running_thread.should_not.stop?
end
it "describes a dying sleeping thread" do
- ThreadSpecs.status_of_dying_sleeping_thread.stop?.should == true
+ ThreadSpecs.status_of_dying_sleeping_thread.should.stop?
end
it "describes a dying thread after sleep" do
- ThreadSpecs.status_of_dying_thread_after_sleep.stop?.should == false
+ ThreadSpecs.status_of_dying_thread_after_sleep.should_not.stop?
end
end
diff --git a/spec/ruby/core/thread/terminate_spec.rb b/spec/ruby/core/thread/terminate_spec.rb
index bb89d87762..68c431a0c0 100644
--- a/spec/ruby/core/thread/terminate_spec.rb
+++ b/spec/ruby/core/thread/terminate_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/exit', __FILE__)
+require_relative '../../spec_helper'
describe "Thread#terminate" do
- it_behaves_like :thread_exit, :terminate
+ it "is an alias of Thread#kill" do
+ Thread.instance_method(:terminate).should == Thread.instance_method(:kill)
+ end
end
diff --git a/spec/ruby/core/thread/thread_variable_get_spec.rb b/spec/ruby/core/thread/thread_variable_get_spec.rb
index 0e02c30fad..3d92cd5479 100644
--- a/spec/ruby/core/thread/thread_variable_get_spec.rb
+++ b/spec/ruby/core/thread/thread_variable_get_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Thread#thread_variable_get" do
before :each do
@@ -10,16 +10,51 @@ describe "Thread#thread_variable_get" do
end
it "returns nil if the variable is not set" do
- @t.thread_variable_get(:a).should be_nil
+ @t.thread_variable_get(:a).should == nil
end
- it "returns the value previously set by #[]=" do
- @t.thread_variable_set :a, 49
+ it "returns the value previously set by #thread_variable_set" do
+ @t.thread_variable_set(:a, 49)
@t.thread_variable_get(:a).should == 49
end
it "returns a value private to self" do
- @t.thread_variable_set :thread_variable_get_spec, 82
- Thread.current.thread_variable_get(:thread_variable_get_spec).should be_nil
+ @t.thread_variable_set(:thread_variable_get_spec, 82)
+ Thread.current.thread_variable_get(:thread_variable_get_spec).should == nil
+ end
+
+ it "accepts String and Symbol keys interchangeably" do
+ @t.thread_variable_set("a", 49)
+ @t.thread_variable_get("a").should == 49
+ @t.thread_variable_get(:a).should == 49
+ end
+
+ it "converts a key that is neither String nor Symbol with #to_str" do
+ key = mock('key')
+ key.should_receive(:to_str).and_return('a')
+ @t.thread_variable_set(:a, 49)
+ @t.thread_variable_get(key).should == 49
+ end
+
+ it "does not raise FrozenError if the thread is frozen" do
+ @t.freeze
+ @t.thread_variable_get(:a).should == nil
+ end
+
+ it "raises a TypeError if the key is neither Symbol nor String when thread variables are already set" do
+ @t.thread_variable_set(:a, 49)
+ -> { @t.thread_variable_get(123) }.should.raise(TypeError, /123 is not a symbol/)
+ end
+
+ ruby_version_is '3.4' do
+ it "raises a TypeError if the key is neither Symbol nor String when no thread variables are set" do
+ -> { @t.thread_variable_get(123) }.should.raise(TypeError, /123 is not a symbol/)
+ end
+
+ it "raises a TypeError if the key is neither Symbol nor String without calling #to_sym" do
+ key = mock('key')
+ key.should_not_receive(:to_sym)
+ -> { @t.thread_variable_get(key) }.should.raise(TypeError, /#{Regexp.escape(key.inspect)} is not a symbol/)
+ end
end
end
diff --git a/spec/ruby/core/thread/thread_variable_set_spec.rb b/spec/ruby/core/thread/thread_variable_set_spec.rb
index 0f55341132..f8d25364ae 100644
--- a/spec/ruby/core/thread/thread_variable_set_spec.rb
+++ b/spec/ruby/core/thread/thread_variable_set_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Thread#thread_variable_set" do
before :each do
@@ -10,17 +10,53 @@ describe "Thread#thread_variable_set" do
end
it "returns the value set" do
- (@t.thread_variable_set :a, 2).should == 2
+ @t.thread_variable_set(:a, 2).should == 2
end
it "sets a value that will be returned by #thread_variable_get" do
- @t.thread_variable_set :a, 49
+ @t.thread_variable_set(:a, 49)
@t.thread_variable_get(:a).should == 49
end
it "sets a value private to self" do
- @t.thread_variable_set :thread_variable_get_spec, 82
+ @t.thread_variable_set(:thread_variable_get_spec, 82)
@t.thread_variable_get(:thread_variable_get_spec).should == 82
- Thread.current.thread_variable_get(:thread_variable_get_spec).should be_nil
+ Thread.current.thread_variable_get(:thread_variable_get_spec).should == nil
+ end
+
+ it "accepts String and Symbol keys interchangeably" do
+ @t.thread_variable_set('a', 49)
+ @t.thread_variable_get('a').should == 49
+
+ @t.thread_variable_set(:a, 50)
+ @t.thread_variable_get('a').should == 50
+ end
+
+ it "converts a key that is neither String nor Symbol with #to_str" do
+ key = mock('key')
+ key.should_receive(:to_str).and_return('a')
+ @t.thread_variable_set(key, 49)
+ @t.thread_variable_get(:a).should == 49
+ end
+
+ it "removes a key if the value is nil" do
+ @t.thread_variable_set(:a, 52)
+ @t.thread_variable_set(:a, nil)
+ @t.thread_variable?(:a).should == false
+ end
+
+ it "raises a FrozenError if the thread is frozen" do
+ @t.freeze
+ -> { @t.thread_variable_set(:a, 1) }.should.raise(FrozenError, "can't modify frozen thread locals")
+ end
+
+ it "raises a TypeError if the key is neither Symbol nor String, nor responds to #to_str" do
+ -> { @t.thread_variable_set(123, 1) }.should.raise(TypeError, /123 is not a symbol/)
+ end
+
+ it "does not try to convert the key with #to_sym" do
+ key = mock('key')
+ key.should_not_receive(:to_sym)
+ -> { @t.thread_variable_set(key, 42) }.should.raise(TypeError, /#{Regexp.quote(key.inspect)} is not a symbol/)
end
end
diff --git a/spec/ruby/core/thread/thread_variable_spec.rb b/spec/ruby/core/thread/thread_variable_spec.rb
index b409b3abfc..ebafd4f3eb 100644
--- a/spec/ruby/core/thread/thread_variable_spec.rb
+++ b/spec/ruby/core/thread/thread_variable_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Thread#thread_variable?" do
before :each do
@@ -10,12 +10,51 @@ describe "Thread#thread_variable?" do
end
it "returns false if the thread variables do not contain 'key'" do
- @t.thread_variable_set :a, 2
- @t.thread_variable?(:b).should be_false
+ @t.thread_variable_set(:a, 2)
+ @t.thread_variable?(:b).should == false
end
it "returns true if the thread variables contain 'key'" do
- @t.thread_variable_set :a, 2
- @t.thread_variable?(:a).should be_true
+ @t.thread_variable_set(:a, 2)
+ @t.thread_variable?(:a).should == true
+ end
+
+ it "accepts String and Symbol keys interchangeably" do
+ @t.thread_variable?('a').should == false
+ @t.thread_variable?(:a).should == false
+
+ @t.thread_variable_set(:a, 49)
+
+ @t.thread_variable?('a').should == true
+ @t.thread_variable?(:a).should == true
+ end
+
+ it "converts a key that is neither String nor Symbol with #to_str" do
+ key = mock('key')
+ key.should_receive(:to_str).and_return('a')
+ @t.thread_variable_set(:a, 49)
+ @t.thread_variable?(key).should == true
+ end
+
+ it "does not raise FrozenError if the thread is frozen" do
+ @t.freeze
+ @t.thread_variable?(:a).should == false
+ end
+
+ it "raises a TypeError if the key is neither Symbol nor String when thread variables are already set" do
+ @t.thread_variable_set(:a, 49)
+ -> { @t.thread_variable?(123) }.should.raise(TypeError, /123 is not a symbol/)
+ end
+
+ ruby_version_is '3.4' do
+ it "raises a TypeError if the key is neither Symbol nor String when no thread variables are set" do
+ -> { @t.thread_variable?(123) }.should.raise(TypeError, /123 is not a symbol/)
+ end
+
+ it "raises a TypeError if the key is neither Symbol nor String without calling #to_sym" do
+ key = mock('key')
+ key.should_not_receive(:to_sym)
+ -> { @t.thread_variable?(key) }.should.raise(TypeError, /#{Regexp.escape(key.inspect)} is not a symbol/)
+ end
end
end
diff --git a/spec/ruby/core/thread/thread_variables_spec.rb b/spec/ruby/core/thread/thread_variables_spec.rb
index 538c85c5e4..f15c681a8f 100644
--- a/spec/ruby/core/thread/thread_variables_spec.rb
+++ b/spec/ruby/core/thread/thread_variables_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Thread#thread_variables" do
before :each do
@@ -10,15 +10,31 @@ describe "Thread#thread_variables" do
end
it "returns the keys of all the values set" do
- @t.thread_variable_set :a, 2
- @t.thread_variable_set :b, 4
- @t.thread_variable_set :c, 6
+ @t.thread_variable_set(:a, 2)
+ @t.thread_variable_set(:b, 4)
+ @t.thread_variable_set(:c, 6)
@t.thread_variables.sort.should == [:a, :b, :c]
end
- it "sets a value private to self" do
- @t.thread_variable_set :thread_variables_spec_a, 82
- @t.thread_variable_set :thread_variables_spec_b, 82
+ it "returns the keys private to self" do
+ @t.thread_variable_set(:a, 82)
+ @t.thread_variable_set(:b, 82)
+ Thread.current.thread_variables.should_not.include?(:a)
+ Thread.current.thread_variables.should_not.include?(:b)
+ end
+
+ it "only contains user thread variables and is empty initially" do
Thread.current.thread_variables.should == []
+ @t.thread_variables.should == []
+ end
+
+ it "returns keys as Symbols" do
+ key = mock('key')
+ key.should_receive(:to_str).and_return('a')
+
+ @t.thread_variable_set(key, 49)
+ @t.thread_variable_set('b', 50)
+ @t.thread_variable_set(:c, 51)
+ @t.thread_variables.sort.should == [:a, :b, :c]
end
end
diff --git a/spec/ruby/core/thread/to_s_spec.rb b/spec/ruby/core/thread/to_s_spec.rb
new file mode 100644
index 0000000000..2aef426de8
--- /dev/null
+++ b/spec/ruby/core/thread/to_s_spec.rb
@@ -0,0 +1,54 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe "Thread#to_s" do
+ it "returns a description including file and line number" do
+ thread, line = Thread.new { "hello" }, __LINE__
+ thread.join
+ thread.to_s.should =~ /^#<Thread:([^ ]*?) #{Regexp.escape __FILE__}:#{line} \w+>$/
+ end
+
+ it "has a binary encoding" do
+ ThreadSpecs.status_of_current_thread.to_s.encoding.should == Encoding::BINARY
+ end
+
+ it "can check it's own status" do
+ ThreadSpecs.status_of_current_thread.to_s.should.include?('run')
+ end
+
+ it "describes a running thread" do
+ ThreadSpecs.status_of_running_thread.to_s.should.include?('run')
+ end
+
+ it "describes a sleeping thread" do
+ ThreadSpecs.status_of_sleeping_thread.to_s.should.include?('sleep')
+ end
+
+ it "describes a blocked thread" do
+ ThreadSpecs.status_of_blocked_thread.to_s.should.include?('sleep')
+ end
+
+ it "describes a completed thread" do
+ ThreadSpecs.status_of_completed_thread.to_s.should.include?('dead')
+ end
+
+ it "describes a killed thread" do
+ ThreadSpecs.status_of_killed_thread.to_s.should.include?('dead')
+ end
+
+ it "describes a thread with an uncaught exception" do
+ ThreadSpecs.status_of_thread_with_uncaught_exception.to_s.should.include?('dead')
+ end
+
+ it "describes a dying sleeping thread" do
+ ThreadSpecs.status_of_dying_sleeping_thread.to_s.should.include?('sleep')
+ end
+
+ it "reports aborting on a killed thread" do
+ ThreadSpecs.status_of_dying_running_thread.to_s.should.include?('aborting')
+ end
+
+ it "reports aborting on a killed thread after sleep" do
+ ThreadSpecs.status_of_dying_thread_after_sleep.to_s.should.include?('aborting')
+ end
+end
diff --git a/spec/ruby/core/thread/value_spec.rb b/spec/ruby/core/thread/value_spec.rb
index 3d900959df..50c823171d 100644
--- a/spec/ruby/core/thread/value_spec.rb
+++ b/spec/ruby/core/thread/value_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Thread#value" do
it "returns the result of the block" do
@@ -11,11 +11,21 @@ describe "Thread#value" do
Thread.current.report_on_exception = false
raise "Hello"
}
- lambda { t.value }.should raise_error(RuntimeError, "Hello")
+ -> { t.value }.should.raise(RuntimeError, "Hello")
end
it "is nil for a killed thread" do
t = Thread.new { Thread.current.exit }
t.value.should == nil
end
+
+ it "returns when the thread finished" do
+ q = Queue.new
+ t = Thread.new {
+ q.pop
+ }
+ -> { t.value }.should block_caller
+ q.push :result
+ t.value.should == :result
+ end
end
diff --git a/spec/ruby/core/thread/wakeup_spec.rb b/spec/ruby/core/thread/wakeup_spec.rb
index 5197a03a35..da5dfea377 100644
--- a/spec/ruby/core/thread/wakeup_spec.rb
+++ b/spec/ruby/core/thread/wakeup_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/wakeup', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/wakeup'
describe "Thread#wakeup" do
it_behaves_like :thread_wakeup, :wakeup
diff --git a/spec/ruby/core/threadgroup/add_spec.rb b/spec/ruby/core/threadgroup/add_spec.rb
index 3b88d3460e..2921c1ab22 100644
--- a/spec/ruby/core/threadgroup/add_spec.rb
+++ b/spec/ruby/core/threadgroup/add_spec.rb
@@ -1,36 +1,39 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
describe "ThreadGroup#add" do
before :each do
- @chan1,@chan2 = Channel.new,Channel.new
- @thread = Thread.new { @chan1 << :go; @chan2.receive }
- @chan1.receive
+ @q1, @q2 = Queue.new, Queue.new
+ @thread = Thread.new { @q1 << :go; @q2.pop }
+ @q1.pop
end
after :each do
- @chan2 << :done
+ @q2 << :done
@thread.join
end
- it "adds the given thread to a group and returns self" do
- @thread.group.should_not == nil
+ # This spec randomly kills mspec worker like: https://ci.appveyor.com/project/ruby/ruby/build/9806/job/37tx2atojy96227m
+ # TODO: Investigate the cause or at least print helpful logs, and remove this `platform_is_not` guard.
+ platform_is_not :mingw do
+ it "adds the given thread to a group and returns self" do
+ @thread.group.should_not == nil
- tg = ThreadGroup.new
- tg.add(@thread).should == tg
- @thread.group.should == tg
- tg.list.include?(@thread).should == true
- end
+ tg = ThreadGroup.new
+ tg.add(@thread).should == tg
+ @thread.group.should == tg
+ tg.list.include?(@thread).should == true
+ end
- it "removes itself from any other threadgroup" do
- tg1 = ThreadGroup.new
- tg2 = ThreadGroup.new
+ it "removes itself from any other threadgroup" do
+ tg1 = ThreadGroup.new
+ tg2 = ThreadGroup.new
- tg1.add(@thread)
- @thread.group.should == tg1
- tg2.add(@thread)
- @thread.group.should == tg2
- tg2.list.include?(@thread).should == true
- tg1.list.include?(@thread).should == false
+ tg1.add(@thread)
+ @thread.group.should == tg1
+ tg2.add(@thread)
+ @thread.group.should == tg2
+ tg2.list.include?(@thread).should == true
+ tg1.list.include?(@thread).should == false
+ end
end
end
diff --git a/spec/ruby/core/threadgroup/default_spec.rb b/spec/ruby/core/threadgroup/default_spec.rb
index d72b86ed39..4f57508abf 100644
--- a/spec/ruby/core/threadgroup/default_spec.rb
+++ b/spec/ruby/core/threadgroup/default_spec.rb
@@ -1,8 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "ThreadGroup::Default" do
it "is a ThreadGroup instance" do
- ThreadGroup::Default.should be_kind_of(ThreadGroup)
+ ThreadGroup::Default.should.is_a?(ThreadGroup)
end
it "is the ThreadGroup of the main thread" do
diff --git a/spec/ruby/core/threadgroup/enclose_spec.rb b/spec/ruby/core/threadgroup/enclose_spec.rb
index 5827ddb6aa..6f703d4ce2 100644
--- a/spec/ruby/core/threadgroup/enclose_spec.rb
+++ b/spec/ruby/core/threadgroup/enclose_spec.rb
@@ -1,15 +1,14 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
describe "ThreadGroup#enclose" do
before :each do
- @chan1,@chan2 = Channel.new,Channel.new
- @thread = Thread.new { @chan1 << :go; @chan2.receive }
- @chan1.receive
+ @q1, @q2 = Queue.new, Queue.new
+ @thread = Thread.new { @q1 << :go; @q2.pop }
+ @q1.pop
end
after :each do
- @chan2 << :done
+ @q2 << :done
@thread.join
end
@@ -18,8 +17,8 @@ describe "ThreadGroup#enclose" do
default_group = @thread.group
thread_group.add(@thread)
thread_group.enclose
- lambda do
+ -> do
default_group.add(@thread)
- end.should raise_error(ThreadError)
+ end.should.raise(ThreadError)
end
end
diff --git a/spec/ruby/core/threadgroup/enclosed_spec.rb b/spec/ruby/core/threadgroup/enclosed_spec.rb
index 2c1c79f24a..cf8a5bb4c6 100644
--- a/spec/ruby/core/threadgroup/enclosed_spec.rb
+++ b/spec/ruby/core/threadgroup/enclosed_spec.rb
@@ -1,14 +1,14 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "ThreadGroup#enclosed?" do
it "returns false when a ThreadGroup has not been enclosed (default state)" do
thread_group = ThreadGroup.new
- thread_group.enclosed?.should be_false
+ thread_group.enclosed?.should == false
end
it "returns true when a ThreadGroup is enclosed" do
thread_group = ThreadGroup.new
thread_group.enclose
- thread_group.enclosed?.should be_true
+ thread_group.enclosed?.should == true
end
end
diff --git a/spec/ruby/core/threadgroup/fixtures/classes.rb b/spec/ruby/core/threadgroup/fixtures/classes.rb
deleted file mode 100644
index 7dfe5e92d1..0000000000
--- a/spec/ruby/core/threadgroup/fixtures/classes.rb
+++ /dev/null
@@ -1,6 +0,0 @@
-unless defined? Channel
- require 'thread'
- class Channel < Queue
- alias receive shift
- end
-end
diff --git a/spec/ruby/core/threadgroup/list_spec.rb b/spec/ruby/core/threadgroup/list_spec.rb
index aa7b3f73fa..ef601d75ea 100644
--- a/spec/ruby/core/threadgroup/list_spec.rb
+++ b/spec/ruby/core/threadgroup/list_spec.rb
@@ -1,20 +1,19 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
describe "ThreadGroup#list" do
it "returns the list of threads in the group" do
- chan = Channel.new
- th1 = Thread.new { chan << :go; sleep }
- chan.receive.should == :go
+ q = Queue.new
+ th1 = Thread.new { q << :go; sleep }
+ q.pop.should == :go
tg = ThreadGroup.new
tg.add(th1)
- tg.list.should include(th1)
+ tg.list.should.include?(th1)
- th2 = Thread.new { chan << :go; sleep }
- chan.receive.should == :go
+ th2 = Thread.new { q << :go; sleep }
+ q.pop.should == :go
tg.add(th2)
- (tg.list & [th1, th2]).should include(th1, th2)
+ (tg.list & [th1, th2]).to_set.should == Set[th1, th2]
Thread.pass while th1.status and th1.status != 'sleep'
Thread.pass while th2.status and th2.status != 'sleep'
diff --git a/spec/ruby/core/time/_dump_spec.rb b/spec/ruby/core/time/_dump_spec.rb
index bec16dab69..21f0806327 100644
--- a/spec/ruby/core/time/_dump_spec.rb
+++ b/spec/ruby/core/time/_dump_spec.rb
@@ -1,5 +1,5 @@
-# -*- encoding: binary -*-
-require File.expand_path('../../../spec_helper', __FILE__)
+# encoding: binary
+require_relative '../../spec_helper'
describe "Time#_dump" do
before :each do
@@ -10,22 +10,22 @@ describe "Time#_dump" do
end
it "is a private method" do
- Time.should have_private_instance_method(:_dump, false)
+ Time.private_instance_methods(false).should.include?(:_dump)
end
# http://redmine.ruby-lang.org/issues/show/627
it "preserves the GMT flag" do
- @t.gmt?.should == true
+ @t.should.gmt?
dump = @t.send(:_dump).unpack("VV").first
((dump >> 30) & 0x1).should == 1
- @local.gmt?.should == false
+ @local.should_not.gmt?
dump = @local.send(:_dump).unpack("VV").first
((dump >> 30) & 0x1).should == 0
end
it "dumps a Time object to a bytestring" do
- @s.should be_an_instance_of(String)
+ @s.should.instance_of?(String)
@s.should == [3222863947, 2235564032].pack("VV")
end
@@ -53,4 +53,3 @@ describe "Time#_dump" do
t.send(:_dump).should == "\364\001\031\200\313\000\020\004"
end
end
-
diff --git a/spec/ruby/core/time/_load_spec.rb b/spec/ruby/core/time/_load_spec.rb
index 12fcb219ed..a74e3dc129 100644
--- a/spec/ruby/core/time/_load_spec.rb
+++ b/spec/ruby/core/time/_load_spec.rb
@@ -1,9 +1,9 @@
-# -*- encoding: binary -*-
-require File.expand_path('../../../spec_helper', __FILE__)
+# encoding: binary
+require_relative '../../spec_helper'
describe "Time._load" do
it "is a private method" do
- Time.should have_private_method(:_load, false)
+ Time.private_methods(false).should.include?(:_load)
end
# http://redmine.ruby-lang.org/issues/show/627
@@ -43,12 +43,9 @@ describe "Time._load" do
t.to_s.should == "2010-10-22 16:57:48 UTC"
end
- with_feature :encoding do
- it "treats the data as binary data" do
- data = "\x04\bu:\tTime\r\fM\x1C\xC0\x00\x00\xD0\xBE"
- data.force_encoding Encoding::UTF_8
- t = Marshal.load(data)
- t.to_s.should == "2013-04-08 12:47:45 UTC"
- end
+ it "treats the data as binary data" do
+ data = "\x04\bu:\tTime\r\fM\x1C\xC0\x00\x00\xD0\xBE".dup.force_encoding Encoding::UTF_8
+ t = Marshal.load(data)
+ t.to_s.should == "2013-04-08 12:47:45 UTC"
end
end
diff --git a/spec/ruby/core/time/asctime_spec.rb b/spec/ruby/core/time/asctime_spec.rb
index 3303e06f21..17e155787a 100644
--- a/spec/ruby/core/time/asctime_spec.rb
+++ b/spec/ruby/core/time/asctime_spec.rb
@@ -1,6 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/asctime', __FILE__)
+require_relative '../../spec_helper'
describe "Time#asctime" do
- it_behaves_like(:time_asctime, :asctime)
+ it "returns a canonical string representation of time" do
+ t = Time.now
+ t.asctime.should == t.strftime("%a %b %e %H:%M:%S %Y")
+ end
end
diff --git a/spec/ruby/core/time/at_spec.rb b/spec/ruby/core/time/at_spec.rb
index 40c729316e..10d4d36a68 100644
--- a/spec/ruby/core/time/at_spec.rb
+++ b/spec/ruby/core/time/at_spec.rb
@@ -1,4 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Time.at" do
describe "passed Numeric" do
@@ -13,13 +14,13 @@ describe "Time.at" do
end
it "returns a non-UTC Time" do
- Time.at(1184027924).utc?.should == false
+ Time.at(1184027924).should_not.utc?
end
it "returns a subclass instance on a Time subclass" do
c = Class.new(Time)
t = c.at(0)
- t.should be_an_instance_of(c)
+ t.should.instance_of?(c)
end
it "roundtrips a Rational produced by #to_r" do
@@ -31,10 +32,17 @@ describe "Time.at" do
t2.nsec.should == t.nsec
end
- describe "passed BigDecimal" do
- it "doesn't round input value" do
- require 'bigdecimal'
- Time.at(BigDecimal.new('1.1')).to_f.should == 1.1
+ describe "passed Rational" do
+ it "returns Time with correct microseconds" do
+ t = Time.at(Rational(1_486_570_508_539_759, 1_000_000))
+ t.usec.should == 539_759
+ t.nsec.should == 539_759_000
+ end
+
+ it "returns Time with correct nanoseconds" do
+ t = Time.at(Rational(1_486_570_508_539_759_123, 1_000_000_000))
+ t.usec.should == 539_759
+ t.nsec.should == 539_759_123
end
end
end
@@ -48,33 +56,33 @@ describe "Time.at" do
it "creates a dup time object with the value given by time" do
t1 = Time.new
t2 = Time.at(t1)
- t1.object_id.should_not == t2.object_id
+ t1.should_not.equal? t2
end
it "returns a UTC time if the argument is UTC" do
t = Time.now.getgm
- Time.at(t).utc?.should == true
+ Time.at(t).should.utc?
end
it "returns a non-UTC time if the argument is non-UTC" do
t = Time.now
- Time.at(t).utc?.should == false
+ Time.at(t).should_not.utc?
end
it "returns a subclass instance" do
c = Class.new(Time)
t = c.at(Time.now)
- t.should be_an_instance_of(c)
+ t.should.instance_of?(c)
end
end
describe "passed non-Time, non-Numeric" do
it "raises a TypeError with a String argument" do
- lambda { Time.at("0") }.should raise_error(TypeError)
+ -> { Time.at("0") }.should.raise(TypeError)
end
it "raises a TypeError with a nil argument" do
- lambda { Time.at(nil) }.should raise_error(TypeError)
+ -> { Time.at(nil) }.should.raise(TypeError)
end
describe "with an argument that responds to #to_int" do
@@ -91,6 +99,12 @@ describe "Time.at" do
o.should_receive(:to_r).and_return(Rational(5, 2))
Time.at(o).should == Time.at(Rational(5, 2))
end
+
+ it "needs for the argument to respond to #to_int too" do
+ o = mock('rational-but-no-to_int')
+ def o.to_r; Rational(5, 2) end
+ -> { Time.at(o) }.should.raise(TypeError, "can't convert MockObject into an exact number")
+ end
end
end
@@ -126,20 +140,177 @@ describe "Time.at" do
describe "passed [Integer, nil]" do
it "raises a TypeError" do
- lambda { Time.at(0, nil) }.should raise_error(TypeError)
+ -> { Time.at(0, nil) }.should.raise(TypeError)
end
end
describe "passed [Integer, String]" do
it "raises a TypeError" do
- lambda { Time.at(0, "0") }.should raise_error(TypeError)
+ -> { Time.at(0, "0") }.should.raise(TypeError)
end
end
describe "passed [Time, Integer]" do
# #8173
it "raises a TypeError" do
- lambda { Time.at(Time.now, 500000) }.should raise_error(TypeError)
+ -> { Time.at(Time.now, 500000) }.should.raise(TypeError)
+ end
+ end
+
+ describe "passed [Time, Numeric, format]" do
+ context ":nanosecond format" do
+ it "treats second argument as nanoseconds" do
+ Time.at(0, 123456789, :nanosecond).nsec.should == 123456789
+ end
+ end
+
+ context ":nsec format" do
+ it "treats second argument as nanoseconds" do
+ Time.at(0, 123456789, :nsec).nsec.should == 123456789
+ end
+ end
+
+ context ":microsecond format" do
+ it "treats second argument as microseconds" do
+ Time.at(0, 123456, :microsecond).nsec.should == 123456000
+ end
+ end
+
+ context ":usec format" do
+ it "treats second argument as microseconds" do
+ Time.at(0, 123456, :usec).nsec.should == 123456000
+ end
+ end
+
+ context ":millisecond format" do
+ it "treats second argument as milliseconds" do
+ Time.at(0, 123, :millisecond).nsec.should == 123000000
+ end
+ end
+
+ context "not supported format" do
+ it "raises ArgumentError" do
+ -> { Time.at(0, 123456, 2) }.should.raise(ArgumentError)
+ -> { Time.at(0, 123456, nil) }.should.raise(ArgumentError)
+ -> { Time.at(0, 123456, :invalid) }.should.raise(ArgumentError)
+ end
+
+ it "does not try to convert format to Symbol with #to_sym" do
+ format = +"usec"
+ format.should_not_receive(:to_sym)
+ -> { Time.at(0, 123456, format) }.should.raise(ArgumentError)
+ end
+ end
+
+ it "supports Float second argument" do
+ Time.at(0, 123456789.500, :nanosecond).nsec.should == 123456789
+ Time.at(0, 123456789.500, :nsec).nsec.should == 123456789
+ Time.at(0, 123456.500, :microsecond).nsec.should == 123456500
+ Time.at(0, 123456.500, :usec).nsec.should == 123456500
+ Time.at(0, 123.500, :millisecond).nsec.should == 123500000
+ end
+ end
+
+ describe ":in keyword argument" do
+ before do
+ @epoch_time = Time.now.to_i
+ end
+
+ it "could be UTC offset as a String in '+HH:MM or '-HH:MM' format" do
+ time = Time.at(@epoch_time, in: "+05:00")
+
+ time.utc_offset.should == 5*60*60
+ time.zone.should == nil
+ time.to_i.should == @epoch_time
+
+ time = Time.at(@epoch_time, in: "-09:00")
+
+ time.utc_offset.should == -9*60*60
+ time.zone.should == nil
+ time.to_i.should == @epoch_time
+
+ time = Time.at(@epoch_time, in: "-09:00:01")
+
+ time.utc_offset.should == -(9*60*60 + 1)
+ time.zone.should == nil
+ time.to_i.should == @epoch_time
+ end
+
+ it "could be UTC offset as a number of seconds" do
+ time = Time.at(@epoch_time, in: 5*60*60)
+
+ time.utc_offset.should == 5*60*60
+ time.zone.should == nil
+ time.to_i.should == @epoch_time
+
+ time = Time.at(@epoch_time, in: -9*60*60)
+
+ time.utc_offset.should == -9*60*60
+ time.zone.should == nil
+ time.to_i.should == @epoch_time
+ end
+
+ it "could be UTC offset as a 'UTC' String" do
+ time = Time.at(@epoch_time, in: "UTC")
+
+ time.utc_offset.should == 0
+ time.zone.should == "UTC"
+ time.to_i.should == @epoch_time
+ end
+
+ it "could be UTC offset as a military zone A-Z" do
+ time = Time.at(@epoch_time, in: "B")
+
+ time.utc_offset.should == 3600 * 2
+ time.zone.should == nil
+ time.to_i.should == @epoch_time
+ end
+
+ it "could be a timezone object" do
+ zone = TimeSpecs::TimezoneWithName.new(name: "Asia/Colombo")
+ time = Time.at(@epoch_time, in: zone)
+
+ time.utc_offset.should == 5*3600+30*60
+ time.zone.should == zone
+ time.to_i.should == @epoch_time
+
+ zone = TimeSpecs::TimezoneWithName.new(name: "PST")
+ time = Time.at(@epoch_time, in: zone)
+
+ time.utc_offset.should == -9*60*60
+ time.zone.should == zone
+ time.to_i.should == @epoch_time
+ end
+
+ it "raises ArgumentError if format is invalid" do
+ -> { Time.at(@epoch_time, in: "+09:99") }.should.raise(ArgumentError)
+ -> { Time.at(@epoch_time, in: "ABC") }.should.raise(ArgumentError)
+ end
+
+ it "raises ArgumentError if hours greater than 23" do # TODO
+ -> { Time.at(@epoch_time, in: "+24:00") }.should.raise(ArgumentError, "utc_offset out of range")
+ -> { Time.at(@epoch_time, in: "+2400") }.should.raise(ArgumentError, "utc_offset out of range")
+
+ -> { Time.at(@epoch_time, in: "+99:00") }.should.raise(ArgumentError, "utc_offset out of range")
+ -> { Time.at(@epoch_time, in: "+9900") }.should.raise(ArgumentError, "utc_offset out of range")
+ end
+
+ it "raises ArgumentError if minutes greater than 59" do # TODO
+ -> { Time.at(@epoch_time, in: "+00:60") }.should.raise(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:60')
+ -> { Time.at(@epoch_time, in: "+0060") }.should.raise(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +0060')
+
+ -> { Time.at(@epoch_time, in: "+00:99") }.should.raise(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:99')
+ -> { Time.at(@epoch_time, in: "+0099") }.should.raise(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +0099')
+ end
+
+ ruby_bug '#20797', ''...'3.4' do
+ it "raises ArgumentError if seconds greater than 59" do
+ -> { Time.at(@epoch_time, in: "+00:00:60") }.should.raise(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:00:60')
+ -> { Time.at(@epoch_time, in: "+000060") }.should.raise(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +000060')
+
+ -> { Time.at(@epoch_time, in: "+00:00:99") }.should.raise(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:00:99')
+ -> { Time.at(@epoch_time, in: "+000099") }.should.raise(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +000099')
+ end
end
end
end
diff --git a/spec/ruby/core/time/ceil_spec.rb b/spec/ruby/core/time/ceil_spec.rb
new file mode 100644
index 0000000000..18e26f9994
--- /dev/null
+++ b/spec/ruby/core/time/ceil_spec.rb
@@ -0,0 +1,44 @@
+require_relative '../../spec_helper'
+
+describe "Time#ceil" do
+ before do
+ @time = Time.utc(2010, 3, 30, 5, 43, "25.0123456789".to_r)
+ end
+
+ it "defaults to ceiling to 0 places" do
+ @time.ceil.should == Time.utc(2010, 3, 30, 5, 43, 26.to_r)
+ end
+
+ it "ceils to 0 decimal places with an explicit argument" do
+ @time.ceil(0).should == Time.utc(2010, 3, 30, 5, 43, 26.to_r)
+ end
+
+ it "ceils to 2 decimal places with an explicit argument" do
+ @time.ceil(2).should == Time.utc(2010, 3, 30, 5, 43, "25.02".to_r)
+ end
+
+ it "ceils to 4 decimal places with an explicit argument" do
+ @time.ceil(4).should == Time.utc(2010, 3, 30, 5, 43, "25.0124".to_r)
+ end
+
+ it "ceils to 7 decimal places with an explicit argument" do
+ @time.ceil(7).should == Time.utc(2010, 3, 30, 5, 43, "25.0123457".to_r)
+ end
+
+ it "returns an instance of Time, even if #ceil is called on a subclass" do
+ subclass = Class.new(Time)
+ instance = subclass.at(0)
+ instance.class.should.equal? subclass
+ instance.ceil.should.instance_of?(Time)
+ end
+
+ it "copies own timezone to the returning value" do
+ @time.zone.should == @time.ceil.zone
+
+ time = with_timezone "JST-9" do
+ Time.at 0, 1
+ end
+
+ time.zone.should == time.ceil.zone
+ end
+end
diff --git a/spec/ruby/core/time/comparison_spec.rb b/spec/ruby/core/time/comparison_spec.rb
index c5a5b83d28..0790088f9e 100644
--- a/spec/ruby/core/time/comparison_spec.rb
+++ b/spec/ruby/core/time/comparison_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Time#<=>" do
it "returns 1 if the first argument is a point in time after the second argument" do
@@ -45,6 +45,42 @@ describe "Time#<=>" do
(Time.at(100, 0) <=> Time.at(100, Rational(1,1000))).should == -1
end
+ it "returns nil when compared to an Integer because Time does not respond to #coerce" do
+ time = Time.at(1)
+ time.respond_to?(:coerce).should == false
+ time.should_receive(:respond_to?).exactly(2).and_return(false)
+ -> {
+ (time <=> 2).should == nil
+ (2 <=> time).should == nil
+ }.should_not complain
+ end
+
+ context "given different timezones" do
+ it "returns 0 if time is the same as other" do
+ # three timezones, all at the same timestamp
+ time_utc = Time.new(2000, 1, 1, 0, 0, 0, 0)
+ time_cet = Time.new(2000, 1, 1, 1, 0, 0, '+01:00')
+ time_brt = Time.new(1999, 12, 31, 21, 0, 0, '-03:00')
+ (time_utc <=> time_cet).should == 0
+ (time_utc <=> time_brt).should == 0
+ (time_cet <=> time_brt).should == 0
+ end
+
+ it "returns -1 if the first argument is before the second argument" do
+ # time_brt is later, even though the date is earlier
+ time_utc = Time.new(2000, 1, 1, 0, 0, 0, 0)
+ time_brt = Time.new(1999, 12, 31, 23, 0, 0, '-03:00')
+ (time_utc <=> time_brt).should == -1
+ end
+
+ it "returns 1 if the first argument is before the second argument" do
+ # time_brt is later, even though the date is earlier
+ time_utc = Time.new(2000, 1, 1, 0, 0, 0, 0)
+ time_brt = Time.new(1999, 12, 31, 23, 0, 0, '-03:00')
+ (time_brt <=> time_utc).should == 1
+ end
+ end
+
describe "given a non-Time argument" do
it "returns nil if argument <=> self returns nil" do
t = Time.now
@@ -88,7 +124,7 @@ describe "Time#<=>" do
def r.<=>(other); other <=> self; end
r.should_receive(:<=>).once
- (t <=> r).should be_nil
+ (t <=> r).should == nil
end
end
end
diff --git a/spec/ruby/core/time/ctime_spec.rb b/spec/ruby/core/time/ctime_spec.rb
index cf9c1ee850..b609b03974 100644
--- a/spec/ruby/core/time/ctime_spec.rb
+++ b/spec/ruby/core/time/ctime_spec.rb
@@ -1,6 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/asctime', __FILE__)
+require_relative '../../spec_helper'
describe "Time#ctime" do
- it_behaves_like(:time_asctime, :ctime)
+ it "is an alias of Time#asctime" do
+ Time.instance_method(:ctime).should == Time.instance_method(:asctime)
+ end
end
diff --git a/spec/ruby/core/time/day_spec.rb b/spec/ruby/core/time/day_spec.rb
index 8e77446070..3dec17644c 100644
--- a/spec/ruby/core/time/day_spec.rb
+++ b/spec/ruby/core/time/day_spec.rb
@@ -1,6 +1,17 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/day', __FILE__)
+require_relative '../../spec_helper'
describe "Time#day" do
- it_behaves_like(:time_day, :day)
+ it "returns the day of the month (1..n) for a local Time" do
+ with_timezone("CET", 1) do
+ Time.local(1970, 1, 1).day.should == 1
+ end
+ end
+
+ it "returns the day of the month for a UTC Time" do
+ Time.utc(1970, 1, 1).day.should == 1
+ end
+
+ it "returns the day of the month for a Time with a fixed offset" do
+ Time.new(2012, 1, 1, 0, 0, 0, -3600).day.should == 1
+ end
end
diff --git a/spec/ruby/core/time/deconstruct_keys_spec.rb b/spec/ruby/core/time/deconstruct_keys_spec.rb
new file mode 100644
index 0000000000..9918728c1d
--- /dev/null
+++ b/spec/ruby/core/time/deconstruct_keys_spec.rb
@@ -0,0 +1,43 @@
+require_relative '../../spec_helper'
+
+describe "Time#deconstruct_keys" do
+ it "returns whole hash for nil as an argument" do
+ d = Time.utc(2022, 10, 5, 13, 30)
+ res = { year: 2022, month: 10, day: 5, yday: 278, wday: 3, hour: 13,
+ min: 30, sec: 0, subsec: 0, dst: false, zone: "UTC" }
+ d.deconstruct_keys(nil).should == res
+ end
+
+ it "returns only specified keys" do
+ d = Time.utc(2022, 10, 5, 13, 39)
+ d.deconstruct_keys([:zone, :subsec]).should == { zone: "UTC", subsec: 0 }
+ end
+
+ it "requires one argument" do
+ -> {
+ Time.new(2022, 10, 5, 13, 30).deconstruct_keys
+ }.should.raise(ArgumentError)
+ end
+
+ it "it raises error when argument is neither nil nor array" do
+ d = Time.new(2022, 10, 5, 13, 30)
+
+ -> { d.deconstruct_keys(1) }.should.raise(TypeError, "wrong argument type Integer (expected Array or nil)")
+ -> { d.deconstruct_keys("asd") }.should.raise(TypeError, "wrong argument type String (expected Array or nil)")
+ -> { d.deconstruct_keys(:x) }.should.raise(TypeError, "wrong argument type Symbol (expected Array or nil)")
+ -> { d.deconstruct_keys({}) }.should.raise(TypeError, "wrong argument type Hash (expected Array or nil)")
+ end
+
+ it "returns {} when passed []" do
+ Time.new(2022, 10, 5, 13, 30).deconstruct_keys([]).should == {}
+ end
+
+ it "ignores non-Symbol keys" do
+ Time.new(2022, 10, 5, 13, 30).deconstruct_keys(['year', []]).should == {}
+ end
+
+ it "ignores not existing Symbol keys and processes keys after the first non-existing one" do
+ d = Time.utc(2022, 10, 5, 13, 30)
+ d.deconstruct_keys([:year, :a, :month, :b, :day]).should == { year: 2022, month: 10, day: 5 }
+ end
+end
diff --git a/spec/ruby/core/time/dst_spec.rb b/spec/ruby/core/time/dst_spec.rb
index 05a0a213c5..42daf86875 100644
--- a/spec/ruby/core/time/dst_spec.rb
+++ b/spec/ruby/core/time/dst_spec.rb
@@ -1,6 +1,10 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/isdst', __FILE__)
+require_relative '../../spec_helper'
describe "Time#dst?" do
- it_behaves_like(:time_isdst, :dst?)
+ it "returns whether time is during daylight saving time" do
+ with_timezone("America/Los_Angeles") do
+ Time.local(2007, 9, 9, 0, 0, 0).dst?.should == true
+ Time.local(2007, 1, 9, 0, 0, 0).dst?.should == false
+ end
+ end
end
diff --git a/spec/ruby/core/time/dup_spec.rb b/spec/ruby/core/time/dup_spec.rb
index b32ce96d44..33aa1304ef 100644
--- a/spec/ruby/core/time/dup_spec.rb
+++ b/spec/ruby/core/time/dup_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Time#dup" do
it "returns a Time object that represents the same time" do
@@ -7,7 +7,7 @@ describe "Time#dup" do
end
it "copies the gmt state flag" do
- Time.now.gmtime.dup.gmt?.should == true
+ Time.now.gmtime.dup.should.gmt?
end
it "returns an independent Time object" do
@@ -15,32 +15,32 @@ describe "Time#dup" do
t2 = t.dup
t.gmtime
- t2.gmt?.should == false
+ t2.should_not.gmt?
end
it "returns a subclass instance" do
c = Class.new(Time)
t = c.now
- t.should be_an_instance_of(c)
- t.dup.should be_an_instance_of(c)
+ t.should.instance_of?(c)
+ t.dup.should.instance_of?(c)
end
it "returns a clone of Time instance" do
c = Time.dup
t = c.now
- t.should be_an_instance_of(c)
- t.should_not be_an_instance_of(Time)
+ t.should.instance_of?(c)
+ t.should_not.instance_of?(Time)
- t.dup.should be_an_instance_of(c)
- t.dup.should_not be_an_instance_of(Time)
+ t.dup.should.instance_of?(c)
+ t.dup.should_not.instance_of?(Time)
end
it "does not copy frozen status from the original" do
t = Time.now
t.freeze
t2 = t.dup
- t2.frozen?.should be_false
+ t2.frozen?.should == false
end
end
diff --git a/spec/ruby/core/time/eql_spec.rb b/spec/ruby/core/time/eql_spec.rb
index af96c96cc3..b7505969dd 100644
--- a/spec/ruby/core/time/eql_spec.rb
+++ b/spec/ruby/core/time/eql_spec.rb
@@ -1,29 +1,29 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Time#eql?" do
it "returns true if self and other have the same whole number of seconds" do
- Time.at(100).should eql(Time.at(100))
+ Time.at(100).should.eql?(Time.at(100))
end
it "returns false if self and other have differing whole numbers of seconds" do
- Time.at(100).should_not eql(Time.at(99))
+ Time.at(100).should_not.eql?(Time.at(99))
end
it "returns true if self and other have the same number of microseconds" do
- Time.at(100, 100).should eql(Time.at(100, 100))
+ Time.at(100, 100).should.eql?(Time.at(100, 100))
end
it "returns false if self and other have differing numbers of microseconds" do
- Time.at(100, 100).should_not eql(Time.at(100, 99))
+ Time.at(100, 100).should_not.eql?(Time.at(100, 99))
end
it "returns false if self and other have differing fractional microseconds" do
- Time.at(100, Rational(100,1000)).should_not eql(Time.at(100, Rational(99,1000)))
+ Time.at(100, Rational(100,1000)).should_not.eql?(Time.at(100, Rational(99,1000)))
end
it "returns false when given a non-time value" do
- Time.at(100, 100).should_not eql("100")
- Time.at(100, 100).should_not eql(100)
- Time.at(100, 100).should_not eql(100.1)
+ Time.at(100, 100).should_not.eql?("100")
+ Time.at(100, 100).should_not.eql?(100)
+ Time.at(100, 100).should_not.eql?(100.1)
end
end
diff --git a/spec/ruby/core/time/fixtures/classes.rb b/spec/ruby/core/time/fixtures/classes.rb
index 328f9160f6..21c4e1effb 100644
--- a/spec/ruby/core/time/fixtures/classes.rb
+++ b/spec/ruby/core/time/fixtures/classes.rb
@@ -9,4 +9,97 @@ module TimeSpecs
end
end
+ class Timezone
+ def initialize(options)
+ @offset = options[:offset]
+ end
+
+ def local_to_utc(t)
+ t - @offset
+ end
+
+ def utc_to_local(t)
+ t + @offset
+ end
+ end
+
+ class TimezoneMethodCallRecorder < Timezone
+ def initialize(options, &blk)
+ super(options)
+ @blk = blk
+ end
+
+ def local_to_utc(t)
+ @blk.call(t)
+ super
+ end
+
+ def utc_to_local(t)
+ @blk.call(t)
+ super
+ end
+ end
+
+ class TimeLikeArgumentRecorder
+ def self.result
+ arguments = []
+
+ zone = TimeSpecs::TimezoneMethodCallRecorder.new(offset: 0) do |obj|
+ arguments << obj
+ end
+
+ # ensure timezone's methods are called at least once
+ Time.new(2000, 1, 1, 12, 0, 0, zone)
+
+ return arguments[0]
+ end
+ end
+
+ Z = Struct.new(:offset, :abbr)
+ Zone = Struct.new(:std, :dst, :dst_range)
+ Zones = {
+ "Asia/Colombo" => Zone[Z[5*3600+30*60, "MMT"], nil, nil],
+ "PST" => Zone[Z[(-9*60*60), "PST"], nil, nil],
+ }
+
+ class TimezoneWithName < Timezone
+ attr_reader :name
+
+ def initialize(options)
+ @name = options[:name]
+ @std, @dst, @dst_range = *Zones[@name]
+ end
+
+ def dst?(t)
+ @dst_range&.cover?(t.mon)
+ end
+
+ def zone(t)
+ (dst?(t) ? @dst : @std)
+ end
+
+ def utc_offset(t)
+ zone(t)&.offset || 0
+ end
+
+ def abbr(t)
+ zone(t)&.abbr
+ end
+
+ def local_to_utc(t)
+ t - utc_offset(t)
+ end
+
+ def utc_to_local(t)
+ t + utc_offset(t)
+ end
+ end
+
+ class TimeWithFindTimezone < Time
+ def self.find_timezone(name)
+ TimezoneWithName.new(name: name.to_s)
+ end
+ end
+
+ TimezoneWithAbbr = TimezoneWithName
end
diff --git a/spec/ruby/core/time/floor_spec.rb b/spec/ruby/core/time/floor_spec.rb
new file mode 100644
index 0000000000..41e5142b19
--- /dev/null
+++ b/spec/ruby/core/time/floor_spec.rb
@@ -0,0 +1,36 @@
+require_relative '../../spec_helper'
+
+describe "Time#floor" do
+ before do
+ @time = Time.utc(2010, 3, 30, 5, 43, "25.123456789".to_r)
+ end
+
+ it "defaults to flooring to 0 places" do
+ @time.floor.should == Time.utc(2010, 3, 30, 5, 43, 25.to_r)
+ end
+
+ it "floors to 0 decimal places with an explicit argument" do
+ @time.floor(0).should == Time.utc(2010, 3, 30, 5, 43, 25.to_r)
+ end
+
+ it "floors to 7 decimal places with an explicit argument" do
+ @time.floor(7).should == Time.utc(2010, 3, 30, 5, 43, "25.1234567".to_r)
+ end
+
+ it "returns an instance of Time, even if #floor is called on a subclass" do
+ subclass = Class.new(Time)
+ instance = subclass.at(0)
+ instance.class.should.equal? subclass
+ instance.floor.should.instance_of?(Time)
+ end
+
+ it "copies own timezone to the returning value" do
+ @time.zone.should == @time.floor.zone
+
+ time = with_timezone "JST-9" do
+ Time.at 0, 1
+ end
+
+ time.zone.should == time.floor.zone
+ end
+end
diff --git a/spec/ruby/core/time/friday_spec.rb b/spec/ruby/core/time/friday_spec.rb
index d38a261080..8bee7f7558 100644
--- a/spec/ruby/core/time/friday_spec.rb
+++ b/spec/ruby/core/time/friday_spec.rb
@@ -1,11 +1,11 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Time#friday?" do
it "returns true if time represents Friday" do
- Time.local(2000, 1, 7).friday?.should == true
+ Time.local(2000, 1, 7).should.friday?
end
it "returns false if time doesn't represent Friday" do
- Time.local(2000, 1, 1).friday?.should == false
+ Time.local(2000, 1, 1).should_not.friday?
end
end
diff --git a/spec/ruby/core/time/getgm_spec.rb b/spec/ruby/core/time/getgm_spec.rb
index f091b5c493..7698156c8c 100644
--- a/spec/ruby/core/time/getgm_spec.rb
+++ b/spec/ruby/core/time/getgm_spec.rb
@@ -1,6 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/getgm', __FILE__)
+require_relative '../../spec_helper'
describe "Time#getgm" do
- it_behaves_like(:time_getgm, :getgm)
+ it "is an alias of Time#getutc" do
+ Time.instance_method(:getgm).should == Time.instance_method(:getutc)
+ end
end
diff --git a/spec/ruby/core/time/getlocal_spec.rb b/spec/ruby/core/time/getlocal_spec.rb
index a94d7f751b..7e5334c303 100644
--- a/spec/ruby/core/time/getlocal_spec.rb
+++ b/spec/ruby/core/time/getlocal_spec.rb
@@ -1,4 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Time#getlocal" do
it "returns a new time which is the local representation of time" do
@@ -13,6 +14,7 @@ describe "Time#getlocal" do
t = Time.gm(2007, 1, 9, 12, 0, 0).getlocal(3630)
t.should == Time.new(2007, 1, 9, 13, 0, 30, 3630)
t.utc_offset.should == 3630
+ t.zone.should == nil
end
platform_is_not :windows do
@@ -39,7 +41,7 @@ describe "Time#getlocal" do
it "returns a Time with a UTC offset of the specified number of Rational seconds" do
t = Time.gm(2007, 1, 9, 12, 0, 0).getlocal(Rational(7201, 2))
t.should == Time.new(2007, 1, 9, 13, 0, Rational(1, 2), Rational(7201, 2))
- t.utc_offset.should eql(Rational(7201, 2))
+ t.utc_offset.should.eql?(Rational(7201, 2))
end
describe "with an argument that responds to #to_r" do
@@ -48,7 +50,7 @@ describe "Time#getlocal" do
o.should_receive(:to_r).and_return(Rational(7201, 2))
t = Time.gm(2007, 1, 9, 12, 0, 0).getlocal(o)
t.should == Time.new(2007, 1, 9, 13, 0, Rational(1, 2), Rational(7201, 2))
- t.utc_offset.should eql(Rational(7201, 2))
+ t.utc_offset.should.eql?(Rational(7201, 2))
end
end
@@ -58,12 +60,24 @@ describe "Time#getlocal" do
t.utc_offset.should == 3600
end
+ it "returns a Time with a UTC offset specified as +HH:MM:SS" do
+ t = Time.gm(2007, 1, 9, 12, 0, 0).getlocal("+01:00:01")
+ t.should == Time.new(2007, 1, 9, 13, 0, 1, 3601)
+ t.utc_offset.should == 3601
+ end
+
it "returns a Time with a UTC offset specified as -HH:MM" do
t = Time.gm(2007, 1, 9, 12, 0, 0).getlocal("-01:00")
t.should == Time.new(2007, 1, 9, 11, 0, 0, -3600)
t.utc_offset.should == -3600
end
+ it "returns a Time with a UTC offset specified as -HH:MM:SS" do
+ t = Time.gm(2007, 1, 9, 12, 0, 0).getlocal("-01:00:01")
+ t.should == Time.new(2007, 1, 9, 10, 59, 59, -3601)
+ t.utc_offset.should == -3601
+ end
+
describe "with an argument that responds to #to_str" do
it "coerces using #to_str" do
o = mock('string')
@@ -76,23 +90,117 @@ describe "Time#getlocal" do
it "raises ArgumentError if the String argument is not of the form (+|-)HH:MM" do
t = Time.now
- lambda { t.getlocal("3600") }.should raise_error(ArgumentError)
+ -> { t.getlocal("3600") }.should.raise(ArgumentError)
end
it "raises ArgumentError if the String argument is not in an ASCII-compatible encoding" do
t = Time.now
- lambda { t.getlocal("-01:00".encode("UTF-16LE")) }.should raise_error(ArgumentError)
+ -> { t.getlocal("-01:00".encode("UTF-16LE")) }.should.raise(ArgumentError)
end
it "raises ArgumentError if the argument represents a value less than or equal to -86400 seconds" do
t = Time.new
t.getlocal(-86400 + 1).utc_offset.should == (-86400 + 1)
- lambda { t.getlocal(-86400) }.should raise_error(ArgumentError)
+ -> { t.getlocal(-86400) }.should.raise(ArgumentError)
end
it "raises ArgumentError if the argument represents a value greater than or equal to 86400 seconds" do
t = Time.new
t.getlocal(86400 - 1).utc_offset.should == (86400 - 1)
- lambda { t.getlocal(86400) }.should raise_error(ArgumentError)
+ -> { t.getlocal(86400) }.should.raise(ArgumentError)
+ end
+
+ it "raises ArgumentError if String argument and hours greater than 23" do
+ -> { Time.now.getlocal("+24:00") }.should.raise(ArgumentError, "utc_offset out of range")
+ -> { Time.now.getlocal("+2400") }.should.raise(ArgumentError, "utc_offset out of range")
+
+ -> { Time.now.getlocal("+99:00") }.should.raise(ArgumentError, "utc_offset out of range")
+ -> { Time.now.getlocal("+9900") }.should.raise(ArgumentError, "utc_offset out of range")
+ end
+
+ it "raises ArgumentError if String argument and minutes greater than 59" do
+ -> { Time.now.getlocal("+00:60") }.should.raise(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:60')
+ -> { Time.now.getlocal("+0060") }.should.raise(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +0060')
+
+ -> { Time.now.getlocal("+00:99") }.should.raise(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:99')
+ -> { Time.now.getlocal("+0099") }.should.raise(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +0099')
+ end
+
+ ruby_bug '#20797', ''...'3.4' do
+ it "raises ArgumentError if String argument and seconds greater than 59" do
+ -> { Time.now.getlocal("+00:00:60") }.should.raise(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:00:60')
+ -> { Time.now.getlocal("+000060") }.should.raise(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +000060')
+
+ -> { Time.now.getlocal("+00:00:99") }.should.raise(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:00:99')
+ -> { Time.now.getlocal("+000099") }.should.raise(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +000099')
+ end
+ end
+
+ describe "with a timezone argument" do
+ it "returns a Time in the timezone" do
+ zone = TimeSpecs::Timezone.new(offset: (5*3600+30*60))
+ time = Time.utc(2000, 1, 1, 12, 0, 0).getlocal(zone)
+
+ time.zone.should == zone
+ time.utc_offset.should == 5*3600+30*60
+ end
+
+ it "accepts timezone argument that must have #local_to_utc and #utc_to_local methods" do
+ zone = Object.new
+ def zone.utc_to_local(time)
+ time
+ end
+ def zone.local_to_utc(time)
+ time
+ end
+
+ -> {
+ Time.utc(2000, 1, 1, 12, 0, 0).getlocal(zone).should.is_a?(Time)
+ }.should_not.raise
+ end
+
+ it "raises TypeError if timezone does not implement #utc_to_local method" do
+ zone = Object.new
+ def zone.local_to_utc(time)
+ time
+ end
+
+ -> {
+ Time.utc(2000, 1, 1, 12, 0, 0).getlocal(zone)
+ }.should.raise(TypeError, /can't convert \w+ into an exact number/)
+ end
+
+ it "does not raise exception if timezone does not implement #local_to_utc method" do
+ zone = Object.new
+ def zone.utc_to_local(time)
+ time
+ end
+
+ -> {
+ Time.utc(2000, 1, 1, 12, 0, 0).getlocal(zone).should.is_a?(Time)
+ }.should_not.raise
+ end
+
+ context "subject's class implements .find_timezone method" do
+ it "calls .find_timezone to build a time object if passed zone name as a timezone argument" do
+ time = TimeSpecs::TimeWithFindTimezone.utc(2000, 1, 1, 12, 0, 0).getlocal("Asia/Colombo")
+ time.zone.should.is_a? TimeSpecs::TimezoneWithName
+ time.zone.name.should == "Asia/Colombo"
+
+ time = TimeSpecs::TimeWithFindTimezone.utc(2000, 1, 1, 12, 0, 0).getlocal("some invalid zone name")
+ time.zone.should.is_a? TimeSpecs::TimezoneWithName
+ time.zone.name.should == "some invalid zone name"
+ end
+
+ it "does not call .find_timezone if passed any not string/numeric/timezone timezone argument" do
+ [Object.new, [], {}, :"some zone"].each do |zone|
+ time = TimeSpecs::TimeWithFindTimezone.utc(2000, 1, 1, 12, 0, 0)
+
+ -> {
+ time.getlocal(zone)
+ }.should.raise(TypeError, /can't convert \w+ into an exact number/)
+ end
+ end
+ end
end
end
diff --git a/spec/ruby/core/time/getutc_spec.rb b/spec/ruby/core/time/getutc_spec.rb
index a6e74cfb98..1d49059a71 100644
--- a/spec/ruby/core/time/getutc_spec.rb
+++ b/spec/ruby/core/time/getutc_spec.rb
@@ -1,6 +1,11 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/getgm', __FILE__)
+require_relative '../../spec_helper'
describe "Time#getutc" do
- it_behaves_like(:time_getgm, :getutc)
+ it "returns a new time which is the utc representation of time" do
+ # Testing with America/Regina here because it doesn't have DST.
+ with_timezone("CST", -6) do
+ t = Time.local(2007, 1, 9, 6, 0, 0)
+ t.getutc.should == Time.gm(2007, 1, 9, 12, 0, 0)
+ end
+ end
end
diff --git a/spec/ruby/core/time/gm_spec.rb b/spec/ruby/core/time/gm_spec.rb
index a6f2858216..fbabede6ba 100644
--- a/spec/ruby/core/time/gm_spec.rb
+++ b/spec/ruby/core/time/gm_spec.rb
@@ -1,10 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/gm', __FILE__)
-require File.expand_path('../shared/time_params', __FILE__)
+require_relative '../../spec_helper'
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 "is an alias of Time.utc" do
+ Time.method(:gm).should == Time.method(:utc)
+ end
end
diff --git a/spec/ruby/core/time/gmt_offset_spec.rb b/spec/ruby/core/time/gmt_offset_spec.rb
index b7613eed2f..1769981753 100644
--- a/spec/ruby/core/time/gmt_offset_spec.rb
+++ b/spec/ruby/core/time/gmt_offset_spec.rb
@@ -1,6 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/gmt_offset', __FILE__)
+require_relative '../../spec_helper'
describe "Time#gmt_offset" do
- it_behaves_like(:time_gmt_offset, :gmt_offset)
+ it "is an alias of Time#utc_offset" do
+ Time.instance_method(:gmt_offset).should == Time.instance_method(:utc_offset)
+ end
end
diff --git a/spec/ruby/core/time/gmt_spec.rb b/spec/ruby/core/time/gmt_spec.rb
index 78ebcd0f5e..38e98cc43c 100644
--- a/spec/ruby/core/time/gmt_spec.rb
+++ b/spec/ruby/core/time/gmt_spec.rb
@@ -1,8 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Time#gmt?" do
- it "returns true if time represents a time in UTC (GMT)" do
- Time.now.gmt?.should == false
- Time.now.gmtime.gmt?.should == true
+ it "is an alias of Time#utc?" do
+ Time.instance_method(:gmt?).should == Time.instance_method(:utc?)
end
end
diff --git a/spec/ruby/core/time/gmtime_spec.rb b/spec/ruby/core/time/gmtime_spec.rb
index 49a1f10479..e7e1d4ffb2 100644
--- a/spec/ruby/core/time/gmtime_spec.rb
+++ b/spec/ruby/core/time/gmtime_spec.rb
@@ -1,6 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/gmtime', __FILE__)
+require_relative '../../spec_helper'
describe "Time#gmtime" do
- it_behaves_like(:time_gmtime, :gmtime)
+ it "is an alias of Time#utc" do
+ Time.instance_method(:gmtime).should == Time.instance_method(:utc)
+ end
end
diff --git a/spec/ruby/core/time/gmtoff_spec.rb b/spec/ruby/core/time/gmtoff_spec.rb
index 505b5d0c1b..c7d801a681 100644
--- a/spec/ruby/core/time/gmtoff_spec.rb
+++ b/spec/ruby/core/time/gmtoff_spec.rb
@@ -1,6 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/gmt_offset', __FILE__)
+require_relative '../../spec_helper'
describe "Time#gmtoff" do
- it_behaves_like(:time_gmt_offset, :gmtoff)
+ it "is an alias of Time#utc_offset" do
+ Time.instance_method(:gmtoff).should == Time.instance_method(:utc_offset)
+ end
end
diff --git a/spec/ruby/core/time/hash_spec.rb b/spec/ruby/core/time/hash_spec.rb
index 77014c5dc8..1cfc56eab0 100644
--- a/spec/ruby/core/time/hash_spec.rb
+++ b/spec/ruby/core/time/hash_spec.rb
@@ -1,8 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Time#hash" do
- it "returns a Fixnum" do
- Time.at(100).hash.should be_an_instance_of(Fixnum)
+ it "returns an Integer" do
+ Time.at(100).hash.should.instance_of?(Integer)
end
it "is stable" do
diff --git a/spec/ruby/core/time/hour_spec.rb b/spec/ruby/core/time/hour_spec.rb
index 65a2ae6ad7..ca69c25adb 100644
--- a/spec/ruby/core/time/hour_spec.rb
+++ b/spec/ruby/core/time/hour_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Time#hour" do
it "returns the hour of the day (0..23) for a local Time" do
diff --git a/spec/ruby/core/time/inspect_spec.rb b/spec/ruby/core/time/inspect_spec.rb
index 7f57a2c4cb..c3a4519a24 100644
--- a/spec/ruby/core/time/inspect_spec.rb
+++ b/spec/ruby/core/time/inspect_spec.rb
@@ -1,6 +1,33 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/inspect', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/inspect'
describe "Time#inspect" do
it_behaves_like :inspect, :inspect
+
+ it "preserves microseconds" do
+ t = Time.utc(2007, 11, 1, 15, 25, 0, 123456)
+ t.inspect.should == "2007-11-01 15:25:00.123456 UTC"
+ end
+
+ it "omits trailing zeros from microseconds" do
+ t = Time.utc(2007, 11, 1, 15, 25, 0, 100000)
+ t.inspect.should == "2007-11-01 15:25:00.1 UTC"
+ end
+
+ it "uses the correct time zone without microseconds" do
+ t = Time.utc(2000, 1, 1)
+ t = t.localtime(9*3600)
+ t.inspect.should == "2000-01-01 09:00:00 +0900"
+ end
+
+ it "uses the correct time zone with microseconds" do
+ t = Time.utc(2000, 1, 1, 0, 0, 0, 123456)
+ t = t.localtime(9*3600)
+ t.inspect.should == "2000-01-01 09:00:00.123456 +0900"
+ end
+
+ it "preserves nanoseconds" do
+ t = Time.utc(2007, 11, 1, 15, 25, 0, 123456.789r)
+ t.inspect.should == "2007-11-01 15:25:00.123456789 UTC"
+ end
end
diff --git a/spec/ruby/core/time/isdst_spec.rb b/spec/ruby/core/time/isdst_spec.rb
index de71bf68ff..759953cca7 100644
--- a/spec/ruby/core/time/isdst_spec.rb
+++ b/spec/ruby/core/time/isdst_spec.rb
@@ -1,6 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/isdst', __FILE__)
+require_relative '../../spec_helper'
describe "Time#isdst" do
- it_behaves_like(:time_isdst, :isdst)
+ it "is an alias of Time#dst?" do
+ Time.instance_method(:isdst).should == Time.instance_method(:dst?)
+ end
end
diff --git a/spec/ruby/core/time/iso8601_spec.rb b/spec/ruby/core/time/iso8601_spec.rb
new file mode 100644
index 0000000000..a6efc57b28
--- /dev/null
+++ b/spec/ruby/core/time/iso8601_spec.rb
@@ -0,0 +1,33 @@
+require_relative '../../spec_helper'
+
+describe "Time#iso8601" do
+ ruby_version_is "3.4" do
+ it "generates ISO-8601 strings in Z for UTC times" do
+ t = Time.utc(1985, 4, 12, 23, 20, 50, 521245)
+ t.iso8601.should == "1985-04-12T23:20:50Z"
+ t.iso8601(2).should == "1985-04-12T23:20:50.52Z"
+ t.iso8601(9).should == "1985-04-12T23:20:50.521245000Z"
+ end
+
+ it "generates ISO-8601 string with timezone offset for non-UTC times" do
+ t = Time.new(1985, 4, 12, 23, 20, 50, "+02:00")
+ t.iso8601.should == "1985-04-12T23:20:50+02:00"
+ t.iso8601(2).should == "1985-04-12T23:20:50.00+02:00"
+ end
+
+ it "year is always at least 4 digits" do
+ t = Time.utc(12, 4, 12)
+ t.iso8601.should == "0012-04-12T00:00:00Z"
+ end
+
+ it "year can be more than 4 digits" do
+ t = Time.utc(40_000, 4, 12)
+ t.iso8601.should == "40000-04-12T00:00:00Z"
+ end
+
+ it "year can be negative" do
+ t = Time.utc(-2000, 4, 12)
+ t.iso8601.should == "-2000-04-12T00:00:00Z"
+ end
+ end
+end
diff --git a/spec/ruby/core/time/local_spec.rb b/spec/ruby/core/time/local_spec.rb
index 63c644e4ea..581ed171d5 100644
--- a/spec/ruby/core/time/local_spec.rb
+++ b/spec/ruby/core/time/local_spec.rb
@@ -1,11 +1,11 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/local', __FILE__)
-require File.expand_path('../shared/time_params', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/local'
+require_relative 'shared/time_params'
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/localtime_spec.rb b/spec/ruby/core/time/localtime_spec.rb
index 6f682b0b34..1c0b11b7a6 100644
--- a/spec/ruby/core/time/localtime_spec.rb
+++ b/spec/ruby/core/time/localtime_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Time#localtime" do
it "converts self to local time, modifying the receiver" do
@@ -12,7 +12,7 @@ describe "Time#localtime" do
it "returns self" do
t = Time.gm(2007, 1, 9, 12, 0, 0)
- t.localtime.should equal(t)
+ t.localtime.should.equal?(t)
end
it "converts time to the UTC offset specified as an Integer number of seconds" do
@@ -26,13 +26,13 @@ describe "Time#localtime" do
it "does not raise an error if already in the right time zone" do
time = Time.now
time.freeze
- time.localtime.should equal(time)
+ time.localtime.should.equal?(time)
end
- it "raises a RuntimeError if the time has a different time zone" do
+ it "raises a FrozenError if the time has a different time zone" do
time = Time.gm(2007, 1, 9, 12, 0, 0)
time.freeze
- lambda { time.localtime }.should raise_error(RuntimeError)
+ -> { time.localtime }.should.raise(FrozenError)
end
end
@@ -51,7 +51,7 @@ describe "Time#localtime" do
t = Time.gm(2007, 1, 9, 12, 0, 0)
t.localtime(Rational(7201, 2))
t.should == Time.new(2007, 1, 9, 13, 0, Rational(1, 2), Rational(7201, 2))
- t.utc_offset.should eql(Rational(7201, 2))
+ t.utc_offset.should.eql?(Rational(7201, 2))
end
describe "with an argument that responds to #to_r" do
@@ -61,7 +61,7 @@ describe "Time#localtime" do
t = Time.gm(2007, 1, 9, 12, 0, 0)
t.localtime(o)
t.should == Time.new(2007, 1, 9, 13, 0, Rational(1, 2), Rational(7201, 2))
- t.utc_offset.should eql(Rational(7201, 2))
+ t.utc_offset.should.eql?(Rational(7201, 2))
end
end
@@ -72,6 +72,13 @@ describe "Time#localtime" do
t.utc_offset.should == 3600
end
+ it "returns a Time with a UTC offset specified as +HH:MM:SS" do
+ t = Time.gm(2007, 1, 9, 12, 0, 0)
+ t.localtime("+01:00:01")
+ t.should == Time.new(2007, 1, 9, 13, 0, 1, 3601)
+ t.utc_offset.should == 3601
+ end
+
it "returns a Time with a UTC offset specified as -HH:MM" do
t = Time.gm(2007, 1, 9, 12, 0, 0)
t.localtime("-01:00")
@@ -79,6 +86,51 @@ describe "Time#localtime" do
t.utc_offset.should == -3600
end
+ it "returns a Time with a UTC offset specified as -HH:MM:SS" do
+ t = Time.gm(2007, 1, 9, 12, 0, 0)
+ t.localtime("-01:00:01")
+ t.should == Time.new(2007, 1, 9, 10, 59, 59, -3601)
+ t.utc_offset.should == -3601
+ end
+
+ it "returns a Time with a UTC offset specified as UTC" do
+ t = Time.new(2007, 1, 9, 12, 0, 0, 3600)
+ t.localtime("UTC")
+ t.utc_offset.should == 0
+ end
+
+ it "returns a Time with a UTC offset specified as A-Z military zone" do
+ t = Time.new(2007, 1, 9, 12, 0, 0, 3600)
+ t.localtime("B")
+ t.utc_offset.should == 3600 * 2
+ end
+
+ it "raises ArgumentError if String argument and hours greater than 23" do
+ -> { Time.now.localtime("+24:00") }.should.raise(ArgumentError, "utc_offset out of range")
+ -> { Time.now.localtime("+2400") }.should.raise(ArgumentError, "utc_offset out of range")
+
+ -> { Time.now.localtime("+99:00") }.should.raise(ArgumentError, "utc_offset out of range")
+ -> { Time.now.localtime("+9900") }.should.raise(ArgumentError, "utc_offset out of range")
+ end
+
+ it "raises ArgumentError if String argument and minutes greater than 59" do
+ -> { Time.now.localtime("+00:60") }.should.raise(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:60')
+ -> { Time.now.localtime("+0060") }.should.raise(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +0060')
+
+ -> { Time.now.localtime("+00:99") }.should.raise(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:99')
+ -> { Time.now.localtime("+0099") }.should.raise(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +0099')
+ end
+
+ ruby_bug '#20797', ''...'3.4' do
+ it "raises ArgumentError if String argument and seconds greater than 59" do
+ -> { Time.now.localtime("+00:00:60") }.should.raise(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:00:60')
+ -> { Time.now.localtime("+000060") }.should.raise(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +000060')
+
+ -> { Time.now.localtime("+00:00:99") }.should.raise(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:00:99')
+ -> { Time.now.localtime("+000099") }.should.raise(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +000099')
+ end
+ end
+
platform_is_not :windows do
it "changes the timezone according to the set one" do
t = Time.new(2005, 2, 27, 22, 50, 0, -3600)
@@ -90,6 +142,19 @@ describe "Time#localtime" do
t.utc_offset.should == -18000
end
+
+ it "does nothing if already in a local time zone" do
+ time = with_timezone("America/New_York") do
+ Time.new(2005, 2, 27, 22, 50, 0)
+ end
+ zone = time.zone
+
+ with_timezone("Europe/Amsterdam") do
+ time.localtime
+ end
+
+ time.zone.should == zone
+ end
end
describe "with an argument that responds to #to_str" do
@@ -103,25 +168,36 @@ describe "Time#localtime" do
end
end
+ describe "with an argument that responds to #utc_to_local" do
+ it "coerces using #utc_to_local" do
+ o = mock('string')
+ o.should_receive(:utc_to_local).and_return(Time.new(2007, 1, 9, 13, 0, 0, 3600))
+ t = Time.gm(2007, 1, 9, 12, 0, 0)
+ t.localtime(o)
+ t.should == Time.new(2007, 1, 9, 13, 0, 0, 3600)
+ t.utc_offset.should == 3600
+ end
+ end
+
it "raises ArgumentError if the String argument is not of the form (+|-)HH:MM" do
t = Time.now
- lambda { t.localtime("3600") }.should raise_error(ArgumentError)
+ -> { t.localtime("3600") }.should.raise(ArgumentError)
end
it "raises ArgumentError if the String argument is not in an ASCII-compatible encoding" do
t = Time.now
- lambda { t.localtime("-01:00".encode("UTF-16LE")) }.should raise_error(ArgumentError)
+ -> { t.localtime("-01:00".encode("UTF-16LE")) }.should.raise(ArgumentError)
end
it "raises ArgumentError if the argument represents a value less than or equal to -86400 seconds" do
t = Time.new
t.localtime(-86400 + 1).utc_offset.should == (-86400 + 1)
- lambda { t.localtime(-86400) }.should raise_error(ArgumentError)
+ -> { t.localtime(-86400) }.should.raise(ArgumentError)
end
it "raises ArgumentError if the argument represents a value greater than or equal to 86400 seconds" do
t = Time.new
t.localtime(86400 - 1).utc_offset.should == (86400 - 1)
- lambda { t.localtime(86400) }.should raise_error(ArgumentError)
+ -> { t.localtime(86400) }.should.raise(ArgumentError)
end
end
diff --git a/spec/ruby/core/time/mday_spec.rb b/spec/ruby/core/time/mday_spec.rb
index 5fbff299cc..78021785f9 100644
--- a/spec/ruby/core/time/mday_spec.rb
+++ b/spec/ruby/core/time/mday_spec.rb
@@ -1,6 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/day', __FILE__)
+require_relative '../../spec_helper'
describe "Time#mday" do
- it_behaves_like(:time_day, :mday)
+ it "is an alias of Time#day" do
+ Time.instance_method(:mday).should == Time.instance_method(:day)
+ end
end
diff --git a/spec/ruby/core/time/min_spec.rb b/spec/ruby/core/time/min_spec.rb
index c1c3ebed3b..7d087d4046 100644
--- a/spec/ruby/core/time/min_spec.rb
+++ b/spec/ruby/core/time/min_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Time#min" do
it "returns the minute of the hour (0..59) for a local Time" do
diff --git a/spec/ruby/core/time/minus_spec.rb b/spec/ruby/core/time/minus_spec.rb
index 4e2bb60333..ee3d8acda8 100644
--- a/spec/ruby/core/time/minus_spec.rb
+++ b/spec/ruby/core/time/minus_spec.rb
@@ -1,4 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Time#-" do
it "decrements the time by the specified amount" do
@@ -19,18 +20,18 @@ describe "Time#-" do
end
it "raises a TypeError if given argument is a coercible String" do
- lambda { Time.now - "1" }.should raise_error(TypeError)
- lambda { Time.now - "0.1" }.should raise_error(TypeError)
- lambda { Time.now - "1/3" }.should raise_error(TypeError)
+ -> { Time.now - "1" }.should.raise(TypeError)
+ -> { Time.now - "0.1" }.should.raise(TypeError)
+ -> { Time.now - "1/3" }.should.raise(TypeError)
end
it "raises TypeError on argument that can't be coerced" do
- lambda { Time.now - Object.new }.should raise_error(TypeError)
- lambda { Time.now - "stuff" }.should raise_error(TypeError)
+ -> { Time.now - Object.new }.should.raise(TypeError)
+ -> { Time.now - "stuff" }.should.raise(TypeError)
end
it "raises TypeError on nil argument" do
- lambda { Time.now - nil }.should raise_error(TypeError)
+ -> { Time.now - nil }.should.raise(TypeError)
end
it "tracks microseconds" do
@@ -78,21 +79,38 @@ describe "Time#-" do
end
it "returns a UTC time if self is UTC" do
- (Time.utc(2012) - 10).utc?.should == true
+ (Time.utc(2012) - 10).should.utc?
end
it "returns a non-UTC time if self is non-UTC" do
- (Time.local(2012) - 10).utc?.should == false
+ (Time.local(2012) - 10).should_not.utc?
end
it "returns a time with the same fixed offset as self" do
(Time.new(2012, 1, 1, 0, 0, 0, 3600) - 10).utc_offset.should == 3600
end
+ it "preserves time zone" do
+ time_with_zone = Time.now.utc
+ time_with_zone.zone.should == (time_with_zone - 1).zone
+
+ time_with_zone = Time.now
+ time_with_zone.zone.should == (time_with_zone - 1).zone
+ end
+
+ context "zone is a timezone object" do
+ it "preserves time zone" do
+ zone = TimeSpecs::Timezone.new(offset: (5*3600+30*60))
+ time = Time.new(2012, 1, 1, 12, 0, 0, zone) - 1
+
+ time.zone.should == zone
+ end
+ end
+
it "does not return a subclass instance" do
c = Class.new(Time)
- x = c.now + 1
- x.should be_an_instance_of(Time)
+ x = c.now - 1
+ x.should.instance_of?(Time)
end
it "returns a time with nanoseconds precision between two time objects" do
diff --git a/spec/ruby/core/time/mktime_spec.rb b/spec/ruby/core/time/mktime_spec.rb
index 68ac1b90ac..83bf12293a 100644
--- a/spec/ruby/core/time/mktime_spec.rb
+++ b/spec/ruby/core/time/mktime_spec.rb
@@ -1,11 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/local', __FILE__)
-require File.expand_path('../shared/time_params', __FILE__)
+require_relative '../../spec_helper'
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 "is an alias of Time.local" do
+ Time.method(:mktime).should == Time.method(:local)
+ end
end
diff --git a/spec/ruby/core/time/mon_spec.rb b/spec/ruby/core/time/mon_spec.rb
index 2408341143..d57549dadd 100644
--- a/spec/ruby/core/time/mon_spec.rb
+++ b/spec/ruby/core/time/mon_spec.rb
@@ -1,6 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/month', __FILE__)
+require_relative '../../spec_helper'
describe "Time#mon" do
- it_behaves_like(:time_month, :mon)
+ it "is an alias of Time#month" do
+ Time.instance_method(:mon).should == Time.instance_method(:month)
+ end
end
diff --git a/spec/ruby/core/time/monday_spec.rb b/spec/ruby/core/time/monday_spec.rb
index 47b09c9a07..47ecaeb1db 100644
--- a/spec/ruby/core/time/monday_spec.rb
+++ b/spec/ruby/core/time/monday_spec.rb
@@ -1,11 +1,11 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Time#monday?" do
it "returns true if time represents Monday" do
- Time.local(2000, 1, 3).monday?.should == true
+ Time.local(2000, 1, 3).should.monday?
end
it "returns false if time doesn't represent Monday" do
- Time.local(2000, 1, 1).monday?.should == false
+ Time.local(2000, 1, 1).should_not.monday?
end
end
diff --git a/spec/ruby/core/time/month_spec.rb b/spec/ruby/core/time/month_spec.rb
index 6323c6205a..eae0e85acd 100644
--- a/spec/ruby/core/time/month_spec.rb
+++ b/spec/ruby/core/time/month_spec.rb
@@ -1,6 +1,17 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/month', __FILE__)
+require_relative '../../spec_helper'
describe "Time#month" do
- it_behaves_like(:time_month, :month)
+ it "returns the month of the year for a local Time" do
+ with_timezone("CET", 1) do
+ Time.local(1970, 1).month.should == 1
+ end
+ end
+
+ it "returns the month of the year for a UTC Time" do
+ Time.utc(1970, 1).month.should == 1
+ end
+
+ it "returns the four digit year for a Time with a fixed offset" do
+ Time.new(2012, 1, 1, 0, 0, 0, -3600).month.should == 1
+ end
end
diff --git a/spec/ruby/core/time/new_spec.rb b/spec/ruby/core/time/new_spec.rb
index a92715c81c..91ce4b2e3a 100644
--- a/spec/ruby/core/time/new_spec.rb
+++ b/spec/ruby/core/time/new_spec.rb
@@ -1,20 +1,21 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/now', __FILE__)
-require File.expand_path('../shared/local', __FILE__)
-require File.expand_path('../shared/time_params', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/now'
+require_relative 'shared/local'
+require_relative 'shared/time_params'
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
it "returns a non-UTC time" do
- Time.new(2000, 1, 1, 0, 0, 0, 0).utc?.should == false
+ Time.new(2000, 1, 1, 0, 0, 0, 0).should_not.utc?
end
it "returns a Time with a UTC offset of the specified number of Integer seconds" do
@@ -30,14 +31,14 @@ describe "Time.new with a utc_offset argument" do
end
it "returns a Time with a UTC offset of the specified number of Rational seconds" do
- Time.new(2000, 1, 1, 0, 0, 0, Rational(5, 2)).utc_offset.should eql(Rational(5, 2))
+ Time.new(2000, 1, 1, 0, 0, 0, Rational(5, 2)).utc_offset.should.eql?(Rational(5, 2))
end
describe "with an argument that responds to #to_r" do
it "coerces using #to_r" do
o = mock_numeric('rational')
o.should_receive(:to_r).and_return(Rational(5, 2))
- Time.new(2000, 1, 1, 0, 0, 0, o).utc_offset.should eql(Rational(5, 2))
+ Time.new(2000, 1, 1, 0, 0, 0, o).utc_offset.should.eql?(Rational(5, 2))
end
end
@@ -49,6 +50,38 @@ describe "Time.new with a utc_offset argument" do
Time.new(2000, 1, 1, 0, 0, 0, "-04:10").utc_offset.should == -15000
end
+ it "returns a Time with a UTC offset specified as +HH:MM:SS" do
+ Time.new(2000, 1, 1, 0, 0, 0, "+05:30:37").utc_offset.should == 19837
+ end
+
+ it "returns a Time with a UTC offset specified as -HH:MM" do
+ Time.new(2000, 1, 1, 0, 0, 0, "-04:10:43").utc_offset.should == -15043
+ end
+
+ it "returns a Time with a UTC offset specified as +HH" do
+ Time.new(2000, 1, 1, 0, 0, 0, "+05").utc_offset.should == 3600 * 5
+ end
+
+ it "returns a Time with a UTC offset specified as -HH" do
+ Time.new(2000, 1, 1, 0, 0, 0, "-05").utc_offset.should == -3600 * 5
+ end
+
+ it "returns a Time with a UTC offset specified as +HHMM" do
+ Time.new(2000, 1, 1, 0, 0, 0, "+0530").utc_offset.should == 19800
+ end
+
+ it "returns a Time with a UTC offset specified as -HHMM" do
+ Time.new(2000, 1, 1, 0, 0, 0, "-0530").utc_offset.should == -19800
+ end
+
+ it "returns a Time with a UTC offset specified as +HHMMSS" do
+ Time.new(2000, 1, 1, 0, 0, 0, "+053037").utc_offset.should == 19837
+ end
+
+ it "returns a Time with a UTC offset specified as -HHMMSS" do
+ Time.new(2000, 1, 1, 0, 0, 0, "-053037").utc_offset.should == -19837
+ end
+
describe "with an argument that responds to #to_str" do
it "coerces using #to_str" do
o = mock('string')
@@ -57,6 +90,48 @@ describe "Time.new with a utc_offset argument" do
end
end
+ it "returns a Time with UTC offset specified as UTC" do
+ Time.new(2000, 1, 1, 0, 0, 0, "UTC").utc_offset.should == 0
+ end
+
+ it "returns a Time with UTC offset specified as a single letter military timezone" do
+ [
+ ["A", 3600],
+ ["B", 3600 * 2],
+ ["C", 3600 * 3],
+ ["D", 3600 * 4],
+ ["E", 3600 * 5],
+ ["F", 3600 * 6],
+ ["G", 3600 * 7],
+ ["H", 3600 * 8],
+ ["I", 3600 * 9],
+ # J is not supported
+ ["K", 3600 * 10],
+ ["L", 3600 * 11],
+ ["M", 3600 * 12],
+ ["N", 3600 * -1],
+ ["O", 3600 * -2],
+ ["P", 3600 * -3],
+ ["Q", 3600 * -4],
+ ["R", 3600 * -5],
+ ["S", 3600 * -6],
+ ["T", 3600 * -7],
+ ["U", 3600 * -8],
+ ["V", 3600 * -9],
+ ["W", 3600 * -10],
+ ["X", 3600 * -11],
+ ["Y", 3600 * -12],
+ ["Z", 0]
+ ].each do |letter, offset|
+ Time.new(2000, 1, 1, 0, 0, 0, letter).utc_offset.should == offset
+ end
+ end
+
+ it "raises ArgumentError if the string argument is J" do
+ message = '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: J'
+ -> { Time.new(2000, 1, 1, 0, 0, 0, "J") }.should.raise(ArgumentError, message)
+ end
+
it "returns a local Time if the argument is nil" do
with_timezone("PST", -8) do
t = Time.new(2000, 1, 1, 0, 0, 0, nil)
@@ -67,33 +142,598 @@ describe "Time.new with a utc_offset argument" do
# [Bug #8679], r47676
it "disallows a value for minutes greater than 59" do
- lambda {
+ -> {
Time.new(2000, 1, 1, 0, 0, 0, "+01:60")
- }.should raise_error(ArgumentError)
- lambda {
+ }.should.raise(ArgumentError)
+ -> {
Time.new(2000, 1, 1, 0, 0, 0, "+01:99")
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
end
it "raises ArgumentError if the String argument is not of the form (+|-)HH:MM" do
- lambda { Time.new(2000, 1, 1, 0, 0, 0, "3600") }.should raise_error(ArgumentError)
+ -> { Time.new(2000, 1, 1, 0, 0, 0, "3600") }.should.raise(ArgumentError)
end
it "raises ArgumentError if the hour value is greater than 23" do
- lambda { Time.new(2000, 1, 1, 0, 0, 0, "+24:00") }.should raise_error(ArgumentError)
+ -> { Time.new(2000, 1, 1, 0, 0, 0, "+24:00") }.should.raise(ArgumentError)
end
it "raises ArgumentError if the String argument is not in an ASCII-compatible encoding" do
- lambda { Time.new(2000, 1, 1, 0, 0, 0, "-04:10".encode("UTF-16LE")) }.should raise_error(ArgumentError)
+ # Don't check exception message - it was changed in previous CRuby versions:
+ # - "string contains null byte"
+ # - '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset'
+ -> {
+ Time.new(2000, 1, 1, 0, 0, 0, "-04:10".encode("UTF-16LE"))
+ }.should.raise(ArgumentError)
end
it "raises ArgumentError if the argument represents a value less than or equal to -86400 seconds" do
Time.new(2000, 1, 1, 0, 0, 0, -86400 + 1).utc_offset.should == (-86400 + 1)
- lambda { Time.new(2000, 1, 1, 0, 0, 0, -86400) }.should raise_error(ArgumentError)
+ -> { Time.new(2000, 1, 1, 0, 0, 0, -86400) }.should.raise(ArgumentError)
end
it "raises ArgumentError if the argument represents a value greater than or equal to 86400 seconds" do
Time.new(2000, 1, 1, 0, 0, 0, 86400 - 1).utc_offset.should == (86400 - 1)
- lambda { Time.new(2000, 1, 1, 0, 0, 0, 86400) }.should raise_error(ArgumentError)
+ -> { Time.new(2000, 1, 1, 0, 0, 0, 86400) }.should.raise(ArgumentError)
+ end
+
+ it "raises ArgumentError if the utc_offset argument is greater than or equal to 10e9" do
+ -> { Time.new(2000, 1, 1, 0, 0, 0, 1000000000) }.should.raise(ArgumentError)
+ end
+end
+
+# The method #local_to_utc is tested only here because Time.new is the only method that calls #local_to_utc.
+describe "Time.new with a timezone argument" do
+ it "returns a Time in the timezone" do
+ zone = TimeSpecs::Timezone.new(offset: (5*3600+30*60))
+ time = Time.new(2000, 1, 1, 12, 0, 0, zone)
+
+ time.zone.should == zone
+ time.utc_offset.should == 5*3600+30*60
+ time.wday.should == 6
+ time.yday.should == 1
+ end
+
+ it "accepts timezone argument that must have #local_to_utc and #utc_to_local methods" do
+ zone = Object.new
+ def zone.utc_to_local(time)
+ time
+ end
+ def zone.local_to_utc(time)
+ time
+ end
+
+ Time.new(2000, 1, 1, 12, 0, 0, zone).should.is_a?(Time)
+ end
+
+ it "raises TypeError if timezone does not implement #local_to_utc method" do
+ zone = Object.new
+ def zone.utc_to_local(time)
+ time
+ end
+
+ -> {
+ Time.new(2000, 1, 1, 12, 0, 0, zone)
+ }.should.raise(TypeError, /can't convert Object into an exact number/)
+ end
+
+ it "does not raise exception if timezone does not implement #utc_to_local method" do
+ zone = Object.new
+ def zone.local_to_utc(time)
+ time
+ end
+
+ Time.new(2000, 1, 1, 12, 0, 0, zone).should.is_a?(Time)
+ end
+
+ # The result also should be a Time or Time-like object (not necessary to be the same class)
+ # or respond to #to_int method. The zone of the result is just ignored.
+ describe "returned value by #utc_to_local and #local_to_utc methods" do
+ it "could be Time instance" do
+ zone = Object.new
+ def zone.local_to_utc(t)
+ time = Time.utc(t.year, t.mon, t.day, t.hour, t.min, t.sec)
+ time - 60 * 60 # - 1 hour
+ end
+
+ Time.new(2000, 1, 1, 12, 0, 0, zone).should.is_a?(Time)
+ Time.new(2000, 1, 1, 12, 0, 0, zone).utc_offset.should == 60*60
+ end
+
+ it "could be Time subclass instance" do
+ zone = Object.new
+ def zone.local_to_utc(t)
+ time = Time.utc(t.year, t.mon, t.day, t.hour, t.min, t.sec)
+ time -= 60 * 60 # - 1 hour
+ Class.new(Time).utc(time.year, time.mon, time.day, time.hour, t.min, t.sec)
+ end
+
+ Time.new(2000, 1, 1, 12, 0, 0, zone).should.is_a?(Time)
+ Time.new(2000, 1, 1, 12, 0, 0, zone).utc_offset.should == 60*60
+ end
+
+ it "could be any object with #to_i method" do
+ zone = Object.new
+ def zone.local_to_utc(time)
+ obj = Object.new
+ obj.singleton_class.define_method(:to_i) { time.to_i - 60*60 }
+ obj
+ end
+
+ Time.new(2000, 1, 1, 12, 0, 0, zone).should.is_a?(Time)
+ Time.new(2000, 1, 1, 12, 0, 0, zone).utc_offset.should == 60*60
+ end
+
+ it "could have any #zone and #utc_offset because they are ignored if it isn't an instance of Time" do
+ zone = Object.new
+ def zone.local_to_utc(time)
+ Struct.new(:to_i, :zone, :utc_offset).new(time.to_i, 'America/New_York', -5*60*60)
+ end
+ Time.new(2000, 1, 1, 12, 0, 0, zone).utc_offset.should == 0
+
+ zone = Object.new
+ def zone.local_to_utc(time)
+ Struct.new(:to_i, :zone, :utc_offset).new(time.to_i, 'Asia/Tokyo', 9*60*60)
+ end
+ Time.new(2000, 1, 1, 12, 0, 0, zone).utc_offset.should == 0
+ end
+
+ it "cannot have arbitrary #utc_offset if it is an instance of Time" do
+ zone = Object.new
+ def zone.local_to_utc(t)
+ Time.new(t.year, t.mon, t.mday, t.hour, t.min, t.sec, 9*60*60)
+ end
+ Time.new(2000, 1, 1, 12, 0, 0, zone).utc_offset.should == 9*60*60
+ end
+
+ it "raises ArgumentError if difference between argument and result is too large" do
+ zone = Object.new
+ def zone.local_to_utc(t)
+ Time.utc(t.year, t.mon, t.day + 1, t.hour, t.min, t.sec)
+ end
+
+ -> {
+ Time.new(2000, 1, 1, 12, 0, 0, zone)
+ }.should.raise(ArgumentError, "utc_offset out of range")
+ end
+ end
+
+ # https://github.com/ruby/ruby/blob/v2_6_0/time.c#L5330
+ #
+ # Time-like argument to these methods is similar to a Time object in UTC without sub-second;
+ # it has attribute readers for the parts, e.g. year, month, and so on, and epoch time readers, to_i
+ #
+ # The sub-second attributes are fixed as 0, and utc_offset, zone, isdst, and their aliases are same as a Time object in UTC
+ describe "Time-like argument of #utc_to_local and #local_to_utc methods" do
+ before do
+ @obj = TimeSpecs::TimeLikeArgumentRecorder.result
+ @obj.should_not == nil
+ end
+
+ it "implements subset of Time methods" do
+ # List only methods that are explicitly documented.
+ [
+ :year, :mon, :mday, :hour, :min, :sec, :to_i, :isdst
+ ].each do |name|
+ @obj.respond_to?(name).should == true
+ end
+ end
+
+ it "has attribute values the same as a Time object in UTC" do
+ @obj.usec.should == 0
+ @obj.nsec.should == 0
+ @obj.subsec.should == 0
+ @obj.tv_usec.should == 0
+ @obj.tv_nsec.should == 0
+
+ @obj.utc_offset.should == 0
+ @obj.zone.should == "UTC"
+ @obj.isdst.should == Time.new.utc.isdst
+ end
+ end
+
+ context "#name method" do
+ it "uses the optional #name method for marshaling" do
+ zone = TimeSpecs::TimezoneWithName.new(name: "Asia/Colombo")
+ time = Time.new(2000, 1, 1, 12, 0, 0, zone)
+ time_loaded = Marshal.load(Marshal.dump(time))
+
+ time_loaded.zone.should == "Asia/Colombo"
+ time_loaded.utc_offset.should == 5*3600+30*60
+ end
+
+ it "cannot marshal Time if #name method isn't implemented" do
+ zone = TimeSpecs::Timezone.new(offset: (5*3600+30*60))
+ time = Time.new(2000, 1, 1, 12, 0, 0, zone)
+
+ -> {
+ Marshal.dump(time)
+ }.should.raise(NoMethodError, /undefined method [`']name' for/)
+ end
+ end
+
+ it "the #abbr method is used by '%Z' in #strftime" do
+ zone = TimeSpecs::TimezoneWithAbbr.new(name: "Asia/Colombo")
+ time = Time.new(2000, 1, 1, 12, 0, 0, zone)
+
+ time.strftime("%Z").should == "MMT"
+ end
+
+ # At loading marshaled data, a timezone name will be converted to a timezone object
+ # by find_timezone class method, if the method is defined.
+ # Similarly, that class method will be called when a timezone argument does not have
+ # the necessary methods mentioned above.
+ context "subject's class implements .find_timezone method" do
+ it "calls .find_timezone to build a time object at loading marshaled data" do
+ zone = TimeSpecs::TimezoneWithName.new(name: "Asia/Colombo")
+ time = TimeSpecs::TimeWithFindTimezone.new(2000, 1, 1, 12, 0, 0, zone)
+ time_loaded = Marshal.load(Marshal.dump(time))
+
+ time_loaded.zone.should.is_a? TimeSpecs::TimezoneWithName
+ time_loaded.zone.name.should == "Asia/Colombo"
+ time_loaded.utc_offset.should == 5*3600+30*60
+ end
+
+ it "calls .find_timezone to build a time object if passed zone name as a timezone argument" do
+ time = TimeSpecs::TimeWithFindTimezone.new(2000, 1, 1, 12, 0, 0, "Asia/Colombo")
+ time.zone.should.is_a? TimeSpecs::TimezoneWithName
+ time.zone.name.should == "Asia/Colombo"
+
+ time = TimeSpecs::TimeWithFindTimezone.new(2000, 1, 1, 12, 0, 0, "some invalid zone name")
+ time.zone.should.is_a? TimeSpecs::TimezoneWithName
+ time.zone.name.should == "some invalid zone name"
+ end
+
+ it "does not call .find_timezone if passed any not string/numeric/timezone timezone argument" do
+ [Object.new, [], {}, :"some zone"].each do |zone|
+ -> {
+ TimeSpecs::TimeWithFindTimezone.new(2000, 1, 1, 12, 0, 0, zone)
+ }.should.raise(TypeError, /can't convert \w+ into an exact number/)
+ end
+ end
+ end
+
+ describe ":in keyword argument" do
+ it "could be UTC offset as a String in '+HH:MM or '-HH:MM' format" do
+ time = Time.new(2000, 1, 1, 12, 0, 0, in: "+05:00")
+
+ time.utc_offset.should == 5*60*60
+ time.zone.should == nil
+
+ time = Time.new(2000, 1, 1, 12, 0, 0, in: "-09:00")
+
+ time.utc_offset.should == -9*60*60
+ time.zone.should == nil
+
+ time = Time.new(2000, 1, 1, 12, 0, 0, in: "-09:00:01")
+
+ time.utc_offset.should == -(9*60*60 + 1)
+ time.zone.should == nil
+ end
+
+ it "could be UTC offset as a number of seconds" do
+ time = Time.new(2000, 1, 1, 12, 0, 0, in: 5*60*60)
+
+ time.utc_offset.should == 5*60*60
+ time.zone.should == nil
+
+ time = Time.new(2000, 1, 1, 12, 0, 0, in: -9*60*60)
+
+ time.utc_offset.should == -9*60*60
+ time.zone.should == nil
+ end
+
+ it "returns a Time with UTC offset specified as a single letter military timezone" do
+ Time.new(2000, 1, 1, 0, 0, 0, in: "W").utc_offset.should == 3600 * -10
+ end
+
+ it "could be a timezone object" do
+ zone = TimeSpecs::TimezoneWithName.new(name: "Asia/Colombo")
+ time = Time.new(2000, 1, 1, 12, 0, 0, in: zone)
+
+ time.utc_offset.should == 5*3600+30*60
+ time.zone.should == zone
+
+ zone = TimeSpecs::TimezoneWithName.new(name: "PST")
+ time = Time.new(2000, 1, 1, 12, 0, 0, in: zone)
+
+ time.utc_offset.should == -9*60*60
+ time.zone.should == zone
+ end
+
+ it "allows omitting minor arguments" do
+ Time.new(2000, 1, 1, 12, 1, 1, in: "+05:00").should == Time.new(2000, 1, 1, 12, 1, 1, "+05:00")
+ Time.new(2000, 1, 1, 12, 1, in: "+05:00").should == Time.new(2000, 1, 1, 12, 1, 0, "+05:00")
+ Time.new(2000, 1, 1, 12, in: "+05:00").should == Time.new(2000, 1, 1, 12, 0, 0, "+05:00")
+ Time.new(2000, 1, 1, in: "+05:00").should == Time.new(2000, 1, 1, 0, 0, 0, "+05:00")
+ Time.new(2000, 1, in: "+05:00").should == Time.new(2000, 1, 1, 0, 0, 0, "+05:00")
+ Time.new(2000, in: "+05:00").should == Time.new(2000, 1, 1, 0, 0, 0, "+05:00")
+ Time.new(in: "+05:00").should be_close(Time.now.getlocal("+05:00"), TIME_TOLERANCE)
+ end
+
+ it "converts to a provided timezone if all the positional arguments are omitted" do
+ Time.new(in: "+05:00").utc_offset.should == 5*3600
+ end
+
+ it "raises ArgumentError if format is invalid" do
+ -> { Time.new(2000, 1, 1, 12, 0, 0, in: "+09:99") }.should.raise(ArgumentError)
+ -> { Time.new(2000, 1, 1, 12, 0, 0, in: "ABC") }.should.raise(ArgumentError)
+ end
+
+ it "raises ArgumentError if two offset arguments are given" do
+ -> {
+ Time.new(2000, 1, 1, 12, 0, 0, "+05:00", in: "+05:00")
+ }.should.raise(ArgumentError, "timezone argument given as positional and keyword arguments")
+ end
+ end
+
+ describe "Time.new with a String argument" do
+ it "parses an ISO-8601 like format" do
+ t = Time.utc(2020, 12, 24, 15, 56, 17)
+
+ Time.new("2020-12-24T15:56:17Z").should == t
+ Time.new("2020-12-25 00:56:17 +09:00").should == t
+ Time.new("2020-12-25 00:57:47 +09:01:30").should == t
+ Time.new("2020-12-25 00:56:17 +0900").should == t
+ Time.new("2020-12-25 00:57:47 +090130").should == t
+ Time.new("2020-12-25T00:56:17+09:00").should == t
+
+ Time.new("2020-12-25T00:56:17.123456+09:00").should == Time.utc(2020, 12, 24, 15, 56, 17, 123456)
+ end
+
+ it "accepts precision keyword argument and truncates specified digits of sub-second part" do
+ Time.new("2021-12-25 00:00:00.123456789876 +09:00").subsec.should == 0.123456789r
+ Time.new("2021-12-25 00:00:00.123456789876 +09:00", precision: nil).subsec.should == 0.123456789876r
+ Time.new("2021-12-25 00:00:00 +09:00", precision: 0).subsec.should == 0
+ Time.new("2021-12-25 00:00:00.123456789876 +09:00", precision: -1).subsec.should == 0.123456789876r
+ end
+
+ it "returns Time in local timezone if not provided in the String argument" do
+ Time.new("2021-12-25 00:00:00").zone.should == Time.new(2021, 12, 25).zone
+ Time.new("2021-12-25 00:00:00").utc_offset.should == Time.new(2021, 12, 25).utc_offset
+ end
+
+ it "returns Time in timezone specified in the String argument" do
+ Time.new("2021-12-25 00:00:00 +05:00").to_s.should == "2021-12-25 00:00:00 +0500"
+ end
+
+ it "returns Time in timezone specified in the String argument even if the in keyword argument provided" do
+ Time.new("2021-12-25 00:00:00 +09:00", in: "-01:00").to_s.should == "2021-12-25 00:00:00 +0900"
+ end
+
+ it "returns Time in timezone specified with in keyword argument if timezone isn't provided in the String argument" do
+ Time.new("2021-12-25 00:00:00", in: "-01:00").to_s.should == "2021-12-25 00:00:00 -0100"
+ end
+
+ it "returns Time of Jan 1 for string with just year" do
+ Time.new("2021").should == Time.new(2021, 1, 1)
+ Time.new("2021").zone.should == Time.new(2021, 1, 1).zone
+ Time.new("2021").utc_offset.should == Time.new(2021, 1, 1).utc_offset
+ end
+
+ it "returns Time of Jan 1 for string with just year in timezone specified with in keyword argument" do
+ Time.new("2021", in: "+17:00").to_s.should == "2021-01-01 00:00:00 +1700"
+ end
+
+ it "converts precision keyword argument into Integer if is not nil" do
+ obj = Object.new
+ def obj.to_int; 3; end
+
+ Time.new("2021-12-25 00:00:00.123456789876 +09:00", precision: 1.2).subsec.should == 0.1r
+ Time.new("2021-12-25 00:00:00.123456789876 +09:00", precision: obj).subsec.should == 0.123r
+ Time.new("2021-12-25 00:00:00.123456789876 +09:00", precision: 3r).subsec.should == 0.123r
+ end
+
+ it "returns Time with correct subseconds when given seconds fraction is shorted than 6 digits" do
+ Time.new("2020-12-25T00:56:17.123 +09:00").nsec.should == 123000000
+ Time.new("2020-12-25T00:56:17.123 +09:00").usec.should == 123000
+ Time.new("2020-12-25T00:56:17.123 +09:00").subsec.should == 0.123
+ end
+
+ it "returns Time with correct subseconds when given seconds fraction is milliseconds" do
+ Time.new("2020-12-25T00:56:17.123456 +09:00").nsec.should == 123456000
+ Time.new("2020-12-25T00:56:17.123456 +09:00").usec.should == 123456
+ Time.new("2020-12-25T00:56:17.123456 +09:00").subsec.should == 0.123456
+ end
+
+ it "returns Time with correct subseconds when given seconds fraction is longer that 6 digits but shorted than 9 digits" do
+ Time.new("2020-12-25T00:56:17.12345678 +09:00").nsec.should == 123456780
+ Time.new("2020-12-25T00:56:17.12345678 +09:00").usec.should == 123456
+ Time.new("2020-12-25T00:56:17.12345678 +09:00").subsec.should == 0.12345678
+ end
+
+ it "returns Time with correct subseconds when given seconds fraction is nanoseconds" do
+ Time.new("2020-12-25T00:56:17.123456789 +09:00").nsec.should == 123456789
+ Time.new("2020-12-25T00:56:17.123456789 +09:00").usec.should == 123456
+ Time.new("2020-12-25T00:56:17.123456789 +09:00").subsec.should == 0.123456789
+ end
+
+ it "returns Time with correct subseconds when given seconds fraction is longer than 9 digits" do
+ Time.new("2020-12-25T00:56:17.123456789876 +09:00").nsec.should == 123456789
+ Time.new("2020-12-25T00:56:17.123456789876 +09:00").usec.should == 123456
+ Time.new("2020-12-25T00:56:17.123456789876 +09:00").subsec.should == 0.123456789
+ end
+
+ it "raise TypeError is can't convert precision keyword argument into Integer" do
+ -> {
+ Time.new("2021-12-25 00:00:00.123456789876 +09:00", precision: "")
+ }.should.raise(TypeError, "no implicit conversion of String into Integer")
+ end
+
+ it "raises ArgumentError if part of time string is missing" do
+ -> {
+ Time.new("2020-12-25 00:56 +09:00")
+ }.should.raise(ArgumentError, /missing sec part: 00:56 |can't parse:/)
+
+ -> {
+ Time.new("2020-12-25 00 +09:00")
+ }.should.raise(ArgumentError, /missing min part: 00 |can't parse:/)
+ end
+
+ it "raises ArgumentError if the time part is missing" do
+ -> {
+ Time.new("2020-12-25")
+ }.should.raise(ArgumentError, /no time information|can't parse:/)
+ end
+
+ it "raises ArgumentError if day is missing" do
+ -> {
+ Time.new("2020-12")
+ }.should.raise(ArgumentError, /no time information|can't parse:/)
+ end
+
+ it "raises ArgumentError if subsecond is missing after dot" do
+ -> {
+ Time.new("2020-12-25 00:56:17. +0900")
+ }.should.raise(ArgumentError, /subsecond expected after dot: 00:56:17. |can't parse:/)
+ end
+
+ it "raises ArgumentError if String argument is not in the supported format" do
+ -> {
+ Time.new("021-12-25 00:00:00.123456 +09:00")
+ }.should.raise(ArgumentError, /year must be 4 or more digits: 021|can't parse:/)
+
+ -> {
+ Time.new("2020-012-25 00:56:17 +0900")
+ }.should.raise(ArgumentError, /\Atwo digits mon is expected after [`']-': -012-25 00:\z|can't parse:/)
+
+ -> {
+ Time.new("2020-2-25 00:56:17 +0900")
+ }.should.raise(ArgumentError, /\Atwo digits mon is expected after [`']-': -2-25 00:56\z|can't parse:/)
+
+ -> {
+ Time.new("2020-12-215 00:56:17 +0900")
+ }.should.raise(ArgumentError, /\Atwo digits mday is expected after [`']-': -215 00:56:\z|can't parse:/)
+
+ -> {
+ Time.new("2020-12-25 000:56:17 +0900")
+ }.should.raise(ArgumentError, /two digits hour is expected: 000:56:17 |can't parse:/)
+
+ -> {
+ Time.new("2020-12-25 0:56:17 +0900")
+ }.should.raise(ArgumentError, /two digits hour is expected: 0:56:17 \+0|can't parse:/)
+
+ -> {
+ Time.new("2020-12-25 00:516:17 +0900")
+ }.should.raise(ArgumentError, /\Atwo digits min is expected after [`']:': :516:17 \+09\z|can't parse:/)
+
+ -> {
+ Time.new("2020-12-25 00:6:17 +0900")
+ }.should.raise(ArgumentError, /\Atwo digits min is expected after [`']:': :6:17 \+0900\z|can't parse:/)
+
+ -> {
+ Time.new("2020-12-25 00:56:137 +0900")
+ }.should.raise(ArgumentError, /\Atwo digits sec is expected after [`']:': :137 \+0900\z|can't parse:/)
+
+ -> {
+ Time.new("2020-12-25 00:56:7 +0900")
+ }.should.raise(ArgumentError, /\Atwo digits sec is expected after [`']:': :7 \+0900\z|can't parse:/)
+
+ -> {
+ Time.new("2020-12-25 00:56. +0900")
+ }.should.raise(ArgumentError, /fraction min is not supported: 00:56\.|can't parse:/)
+
+ -> {
+ Time.new("2020-12-25 00. +0900")
+ }.should.raise(ArgumentError, /fraction hour is not supported: 00\.|can't parse:/)
+ end
+
+ it "raises ArgumentError if date/time parts values are not valid" do
+ -> {
+ Time.new("2020-13-25 00:56:17 +09:00")
+ }.should.raise(ArgumentError, /(mon|argument) out of range/)
+
+ -> {
+ Time.new("2020-12-32 00:56:17 +09:00")
+ }.should.raise(ArgumentError, /(mday|argument) out of range/)
+
+ -> {
+ Time.new("2020-12-25 25:56:17 +09:00")
+ }.should.raise(ArgumentError, /(hour|argument) out of range/)
+
+ -> {
+ Time.new("2020-12-25 00:61:17 +09:00")
+ }.should.raise(ArgumentError, /(min|argument) out of range/)
+
+ -> {
+ Time.new("2020-12-25 00:56:61 +09:00")
+ }.should.raise(ArgumentError, /(sec|argument) out of range/)
+
+ -> {
+ Time.new("2020-12-25 00:56:17 +23:59:60")
+ }.should.raise(ArgumentError, /utc_offset|argument out of range/)
+
+ -> {
+ Time.new("2020-12-25 00:56:17 +24:00")
+ }.should.raise(ArgumentError, /(utc_offset|argument) out of range/)
+
+ -> {
+ Time.new("2020-12-25 00:56:17 +23:61")
+ }.should.raise(ArgumentError, /utc_offset/)
+
+ ruby_bug '#20797', ''...'3.4' do
+ -> {
+ Time.new("2020-12-25 00:56:17 +00:23:61")
+ }.should.raise(ArgumentError, /utc_offset/)
+ end
+ end
+
+ it "raises ArgumentError if utc offset parts are not valid" do
+ -> { Time.new("2020-12-25 00:56:17 +24:00") }.should.raise(ArgumentError, "utc_offset out of range")
+ -> { Time.new("2020-12-25 00:56:17 +2400") }.should.raise(ArgumentError, "utc_offset out of range")
+
+ -> { Time.new("2020-12-25 00:56:17 +99:00") }.should.raise(ArgumentError, "utc_offset out of range")
+ -> { Time.new("2020-12-25 00:56:17 +9900") }.should.raise(ArgumentError, "utc_offset out of range")
+
+ -> { Time.new("2020-12-25 00:56:17 +00:60") }.should.raise(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:60')
+ -> { Time.new("2020-12-25 00:56:17 +0060") }.should.raise(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +0060')
+
+ -> { Time.new("2020-12-25 00:56:17 +00:99") }.should.raise(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:99')
+ -> { Time.new("2020-12-25 00:56:17 +0099") }.should.raise(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +0099')
+
+ ruby_bug '#20797', ''...'3.4' do
+ -> { Time.new("2020-12-25 00:56:17 +00:00:60") }.should.raise(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:00:60')
+ -> { Time.new("2020-12-25 00:56:17 +000060") }.should.raise(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +000060')
+
+ -> { Time.new("2020-12-25 00:56:17 +00:00:99") }.should.raise(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:00:99')
+ -> { Time.new("2020-12-25 00:56:17 +000099") }.should.raise(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +000099')
+ end
+ end
+
+ it "raises ArgumentError if string has not ascii-compatible encoding" do
+ -> {
+ Time.new("2021-11-31 00:00:60 +09:00".encode("utf-32le"))
+ }.should.raise(ArgumentError, "time string should have ASCII compatible encoding")
+ end
+
+ it "raises ArgumentError if string doesn't start with year" do
+ -> {
+ Time.new("a\nb")
+ }.should.raise(ArgumentError, "can't parse: \"a\\nb\"")
+ end
+
+ it "raises ArgumentError if string has extra characters after offset" do
+ -> {
+ Time.new("2021-11-31 00:00:59 +09:00 abc")
+ }.should.raise(ArgumentError, /can't parse.+ abc/)
+ end
+
+ it "raises ArgumentError when there are leading space characters" do
+ -> { Time.new(" 2020-12-02 00:00:00") }.should.raise(ArgumentError, /can't parse/)
+ -> { Time.new("\t2020-12-02 00:00:00") }.should.raise(ArgumentError, /can't parse/)
+ -> { Time.new("\n2020-12-02 00:00:00") }.should.raise(ArgumentError, /can't parse/)
+ -> { Time.new("\v2020-12-02 00:00:00") }.should.raise(ArgumentError, /can't parse/)
+ -> { Time.new("\f2020-12-02 00:00:00") }.should.raise(ArgumentError, /can't parse/)
+ -> { Time.new("\r2020-12-02 00:00:00") }.should.raise(ArgumentError, /can't parse/)
+ end
+
+ it "raises ArgumentError when there are trailing whitespaces" do
+ -> { Time.new("2020-12-02 00:00:00 ") }.should.raise(ArgumentError, /can't parse/)
+ -> { Time.new("2020-12-02 00:00:00\t") }.should.raise(ArgumentError, /can't parse/)
+ -> { Time.new("2020-12-02 00:00:00\n") }.should.raise(ArgumentError, /can't parse/)
+ -> { Time.new("2020-12-02 00:00:00\v") }.should.raise(ArgumentError, /can't parse/)
+ -> { Time.new("2020-12-02 00:00:00\f") }.should.raise(ArgumentError, /can't parse/)
+ -> { Time.new("2020-12-02 00:00:00\r") }.should.raise(ArgumentError, /can't parse/)
+ end
end
end
diff --git a/spec/ruby/core/time/now_spec.rb b/spec/ruby/core/time/now_spec.rb
index 399a1a22e2..533cf68380 100644
--- a/spec/ruby/core/time/now_spec.rb
+++ b/spec/ruby/core/time/now_spec.rb
@@ -1,6 +1,181 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/now', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/now'
describe "Time.now" do
- it_behaves_like(:time_now, :now)
+ it_behaves_like :time_now, :now
+
+ describe ":in keyword argument" do
+ it "could be UTC offset as a String in '+HH:MM or '-HH:MM' format" do
+ time = Time.now(in: "+05:00")
+
+ time.utc_offset.should == 5*60*60
+ time.zone.should == nil
+
+ time = Time.now(in: "-09:00")
+
+ time.utc_offset.should == -9*60*60
+ time.zone.should == nil
+
+ time = Time.now(in: "-09:00:01")
+
+ time.utc_offset.should == -(9*60*60 + 1)
+ time.zone.should == nil
+ end
+
+ it "could be UTC offset as a number of seconds" do
+ time = Time.now(in: 5*60*60)
+
+ time.utc_offset.should == 5*60*60
+ time.zone.should == nil
+
+ time = Time.now(in: -9*60*60)
+
+ time.utc_offset.should == -9*60*60
+ time.zone.should == nil
+ end
+
+ it "returns a Time with UTC offset specified as a single letter military timezone" do
+ Time.now(in: "W").utc_offset.should == 3600 * -10
+ end
+
+ it "could be a timezone object" do
+ zone = TimeSpecs::TimezoneWithName.new(name: "Asia/Colombo")
+ time = Time.now(in: zone)
+
+ time.utc_offset.should == 5*3600+30*60
+ time.zone.should == zone
+
+ zone = TimeSpecs::TimezoneWithName.new(name: "PST")
+ time = Time.now(in: zone)
+
+ time.utc_offset.should == -9*60*60
+ time.zone.should == zone
+ end
+
+ it "raises ArgumentError if format is invalid" do
+ -> { Time.now(in: "+09:99") }.should.raise(ArgumentError)
+ -> { Time.now(in: "ABC") }.should.raise(ArgumentError)
+ end
+
+ it "raises ArgumentError if String argument and hours greater than 23" do
+ -> { Time.now(in: "+24:00") }.should.raise(ArgumentError, "utc_offset out of range")
+ -> { Time.now(in: "+2400") }.should.raise(ArgumentError, "utc_offset out of range")
+
+ -> { Time.now(in: "+99:00") }.should.raise(ArgumentError, "utc_offset out of range")
+ -> { Time.now(in: "+9900") }.should.raise(ArgumentError, "utc_offset out of range")
+ end
+
+ it "raises ArgumentError if String argument and minutes greater than 59" do
+ -> { Time.now(in: "+00:60") }.should.raise(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:60')
+ -> { Time.now(in: "+0060") }.should.raise(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +0060')
+
+ -> { Time.now(in: "+00:99") }.should.raise(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:99')
+ -> { Time.now(in: "+0099") }.should.raise(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +0099')
+ end
+
+ ruby_bug '#20797', ''...'3.4' do
+ it "raises ArgumentError if String argument and seconds greater than 59" do
+ -> { Time.now(in: "+00:00:60") }.should.raise(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:00:60')
+ -> { Time.now(in: "+000060") }.should.raise(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +000060')
+
+ -> { Time.now(in: "+00:00:99") }.should.raise(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +00:00:99')
+ -> { Time.now(in: "+000099") }.should.raise(ArgumentError, '"+HH:MM", "-HH:MM", "UTC" or "A".."I","K".."Z" expected for utc_offset: +000099')
+ end
+ end
+ end
+
+ describe "Timezone object" do # https://bugs.ruby-lang.org/issues/17485
+ it "raises TypeError if timezone does not implement #utc_to_local method" do
+ zone = Object.new
+ def zone.local_to_utc(time)
+ time
+ end
+
+ -> {
+ Time.now(in: zone)
+ }.should.raise(TypeError, /can't convert Object into an exact number/)
+ end
+
+ it "does not raise exception if timezone does not implement #local_to_utc method" do
+ zone = Object.new
+ def zone.utc_to_local(time)
+ time
+ end
+
+ Time.now(in: zone).should.is_a?(Time)
+ end
+
+ # The result also should be a Time or Time-like object (not necessary to be the same class)
+ # or Integer. The zone of the result is just ignored.
+ describe "returned value by #utc_to_local and #local_to_utc methods" do
+ it "could be Time instance" do
+ zone = Object.new
+ def zone.utc_to_local(t)
+ time = Time.new(t.year, t.mon, t.day, t.hour, t.min, t.sec, t.utc_offset)
+ time + 60 * 60 # + 1 hour
+ end
+
+ Time.now(in: zone).should.is_a?(Time)
+ Time.now(in: zone).utc_offset.should == 3600
+ end
+
+ it "could be Time subclass instance" do
+ zone = Object.new
+ def zone.utc_to_local(t)
+ time = Time.new(t.year, t.mon, t.day, t.hour, t.min, t.sec, t.utc_offset)
+ time += 60 * 60 # + 1 hour
+
+ Class.new(Time).new(time.year, time.mon, time.day, time.hour, time.min, time.sec, time.utc_offset)
+ end
+
+ Time.now(in: zone).should.is_a?(Time)
+ Time.now(in: zone).utc_offset.should == 3600
+ end
+
+ it "could be Integer" do
+ zone = Object.new
+ def zone.utc_to_local(time)
+ time.to_i + 60*60
+ end
+
+ Time.now(in: zone).should.is_a?(Time)
+ Time.now(in: zone).utc_offset.should == 60*60
+ end
+
+ it "could have any #zone and #utc_offset because they are ignored" do
+ zone = Object.new
+ def zone.utc_to_local(t)
+ Struct.new(:year, :mon, :mday, :hour, :min, :sec, :isdst, :to_i, :zone, :utc_offset) # rubocop:disable Lint/StructNewOverride
+ .new(t.year, t.mon, t.mday, t.hour, t.min, t.sec, t.isdst, t.to_i, 'America/New_York', -5*60*60)
+ end
+ Time.now(in: zone).utc_offset.should == 0
+
+ zone = Object.new
+ def zone.utc_to_local(t)
+ Struct.new(:year, :mon, :mday, :hour, :min, :sec, :isdst, :to_i, :zone, :utc_offset) # rubocop:disable Lint/StructNewOverride
+ .new(t.year, t.mon, t.mday, t.hour, t.min, t.sec, t.isdst, t.to_i, 'Asia/Tokyo', 9*60*60)
+ end
+ Time.now(in: zone).utc_offset.should == 0
+
+ zone = Object.new
+ def zone.utc_to_local(t)
+ Time.new(t.year, t.mon, t.mday, t.hour, t.min, t.sec, 9*60*60)
+ end
+ Time.now(in: zone).utc_offset.should == 0
+ end
+
+ it "raises ArgumentError if difference between argument and result is too large" do
+ zone = Object.new
+ def zone.utc_to_local(t)
+ time = Time.utc(t.year, t.mon, t.day, t.hour, t.min, t.sec, t.utc_offset)
+ time -= 24 * 60 * 60 # - 1 day
+ Time.utc(time.year, time.mon, time.day, time.hour, time.min, time.sec, time.utc_offset)
+ end
+
+ -> {
+ Time.now(in: zone)
+ }.should.raise(ArgumentError, "utc_offset out of range")
+ end
+ end
+ end
end
diff --git a/spec/ruby/core/time/nsec_spec.rb b/spec/ruby/core/time/nsec_spec.rb
index 3a6be1d016..9338eb435a 100644
--- a/spec/ruby/core/time/nsec_spec.rb
+++ b/spec/ruby/core/time/nsec_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Time#nsec" do
it "returns 0 for a Time constructed with a whole number of seconds" do
@@ -24,4 +24,8 @@ describe "Time#nsec" do
it "returns the nanoseconds part of a Time constructed with an Rational number of microseconds" do
Time.at(0, Rational(99, 10)).nsec.should == 9900
end
+
+ it "returns a positive value for dates before the epoch" do
+ Time.utc(1969, 11, 12, 13, 18, 57, 404240).nsec.should == 404240000
+ end
end
diff --git a/spec/ruby/core/time/plus_spec.rb b/spec/ruby/core/time/plus_spec.rb
index 29931f8a87..6bd01bcdf3 100644
--- a/spec/ruby/core/time/plus_spec.rb
+++ b/spec/ruby/core/time/plus_spec.rb
@@ -1,4 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Time#+" do
it "increments the time by the specified amount" do
@@ -16,9 +17,9 @@ describe "Time#+" do
end
it "raises a TypeError if given argument is a coercible String" do
- lambda { Time.now + "1" }.should raise_error(TypeError)
- lambda { Time.now + "0.1" }.should raise_error(TypeError)
- lambda { Time.now + "1/3" }.should raise_error(TypeError)
+ -> { Time.now + "1" }.should.raise(TypeError)
+ -> { Time.now + "0.1" }.should.raise(TypeError)
+ -> { Time.now + "1/3" }.should.raise(TypeError)
end
it "increments the time by the specified amount as rational numbers" do
@@ -31,34 +32,51 @@ describe "Time#+" do
end
it "raises TypeError on argument that can't be coerced into Rational" do
- lambda { Time.now + Object.new }.should raise_error(TypeError)
- lambda { Time.now + "stuff" }.should raise_error(TypeError)
+ -> { Time.now + Object.new }.should.raise(TypeError)
+ -> { Time.now + "stuff" }.should.raise(TypeError)
end
it "returns a UTC time if self is UTC" do
- (Time.utc(2012) + 10).utc?.should == true
+ (Time.utc(2012) + 10).should.utc?
end
it "returns a non-UTC time if self is non-UTC" do
- (Time.local(2012) + 10).utc?.should == false
+ (Time.local(2012) + 10).should_not.utc?
end
it "returns a time with the same fixed offset as self" do
(Time.new(2012, 1, 1, 0, 0, 0, 3600) + 10).utc_offset.should == 3600
end
+ it "preserves time zone" do
+ time_with_zone = Time.now.utc
+ time_with_zone.zone.should == (time_with_zone + 1).zone
+
+ time_with_zone = Time.now
+ time_with_zone.zone.should == (time_with_zone + 1).zone
+ end
+
+ context "zone is a timezone object" do
+ it "preserves time zone" do
+ zone = TimeSpecs::Timezone.new(offset: (5*3600+30*60))
+ time = Time.new(2012, 1, 1, 12, 0, 0, zone) + 1
+
+ time.zone.should == zone
+ end
+ end
+
it "does not return a subclass instance" do
c = Class.new(Time)
x = c.now + 1
- x.should be_an_instance_of(Time)
+ x.should.instance_of?(Time)
end
it "raises TypeError on Time argument" do
- lambda { Time.now + Time.now }.should raise_error(TypeError)
+ -> { Time.now + Time.now }.should.raise(TypeError)
end
it "raises TypeError on nil argument" do
- lambda { Time.now + nil }.should raise_error(TypeError)
+ -> { Time.now + nil }.should.raise(TypeError)
end
#see [ruby-dev:38446]
diff --git a/spec/ruby/core/time/round_spec.rb b/spec/ruby/core/time/round_spec.rb
index a9a793c156..a739cabfdf 100644
--- a/spec/ruby/core/time/round_spec.rb
+++ b/spec/ruby/core/time/round_spec.rb
@@ -1,9 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Time#round" do
before do
@time = Time.utc(2010, 3, 30, 5, 43, "25.123456789".to_r)
- @subclass = Class.new(Time).now
end
it "defaults to rounding to 0 places" do
@@ -19,7 +18,10 @@ describe "Time#round" do
end
it "returns an instance of Time, even if #round is called on a subclass" do
- @subclass.round.should be_an_instance_of(Time)
+ subclass = Class.new(Time)
+ instance = subclass.at(0)
+ instance.class.should.equal? subclass
+ instance.round.should.instance_of?(Time)
end
it "copies own timezone to the returning value" do
diff --git a/spec/ruby/core/time/saturday_spec.rb b/spec/ruby/core/time/saturday_spec.rb
index 0d827a6184..0e51407366 100644
--- a/spec/ruby/core/time/saturday_spec.rb
+++ b/spec/ruby/core/time/saturday_spec.rb
@@ -1,11 +1,11 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Time#saturday?" do
it "returns true if time represents Saturday" do
- Time.local(2000, 1, 1).saturday?.should == true
+ Time.local(2000, 1, 1).should.saturday?
end
it "returns false if time doesn't represent Saturday" do
- Time.local(2000, 1, 2).saturday?.should == false
+ Time.local(2000, 1, 2).should_not.saturday?
end
end
diff --git a/spec/ruby/core/time/sec_spec.rb b/spec/ruby/core/time/sec_spec.rb
index e753235b53..73fc5ce1fc 100644
--- a/spec/ruby/core/time/sec_spec.rb
+++ b/spec/ruby/core/time/sec_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Time#sec" do
it "returns the second of the minute(0..60) for time" do
diff --git a/spec/ruby/core/time/shared/asctime.rb b/spec/ruby/core/time/shared/asctime.rb
deleted file mode 100644
index d096666863..0000000000
--- a/spec/ruby/core/time/shared/asctime.rb
+++ /dev/null
@@ -1,6 +0,0 @@
-describe :time_asctime, shared: true do
- it "returns a canonical string representation of time" do
- t = Time.now
- t.send(@method).should == t.strftime("%a %b %e %H:%M:%S %Y")
- end
-end
diff --git a/spec/ruby/core/time/shared/day.rb b/spec/ruby/core/time/shared/day.rb
deleted file mode 100644
index 472dc959c1..0000000000
--- a/spec/ruby/core/time/shared/day.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-describe :time_day, shared: true do
- it "returns the day of the month (1..n) for a local Time" do
- with_timezone("CET", 1) do
- Time.local(1970, 1, 1).send(@method).should == 1
- end
- end
-
- it "returns the day of the month for a UTC Time" do
- Time.utc(1970, 1, 1).send(@method).should == 1
- end
-
- it "returns the day of the month for a Time with a fixed offset" do
- Time.new(2012, 1, 1, 0, 0, 0, -3600).send(@method).should == 1
- end
-end
diff --git a/spec/ruby/core/time/shared/getgm.rb b/spec/ruby/core/time/shared/getgm.rb
deleted file mode 100644
index 3576365772..0000000000
--- a/spec/ruby/core/time/shared/getgm.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-describe :time_getgm, shared: true do
- it "returns a new time which is the utc representation of time" do
- # Testing with America/Regina here because it doesn't have DST.
- with_timezone("CST", -6) do
- t = Time.local(2007, 1, 9, 6, 0, 0)
- t.send(@method).should == Time.gm(2007, 1, 9, 12, 0, 0)
- end
- end
-end
diff --git a/spec/ruby/core/time/shared/gm.rb b/spec/ruby/core/time/shared/gm.rb
deleted file mode 100644
index 805e35766c..0000000000
--- a/spec/ruby/core/time/shared/gm.rb
+++ /dev/null
@@ -1,22 +0,0 @@
-describe :time_gm, shared: true do
- it "creates a time based on given values, interpreted as UTC (GMT)" do
- Time.send(@method, 2000,"jan",1,20,15,1).inspect.should == "2000-01-01 20:15:01 UTC"
- end
-
- it "creates a time based on given C-style gmtime arguments, interpreted as UTC (GMT)" do
- time = Time.send(@method, 1, 15, 20, 1, 1, 2000, :ignored, :ignored, :ignored, :ignored)
- time.inspect.should == "2000-01-01 20:15:01 UTC"
- end
-
- it "interprets pre-Gregorian reform dates using Gregorian proleptic calendar" do
- Time.send(@method, 1582, 10, 4, 12).to_i.should == -12220200000 # 2299150j
- end
-
- it "interprets Julian-Gregorian gap dates using Gregorian proleptic calendar" do
- Time.send(@method, 1582, 10, 14, 12).to_i.should == -12219336000 # 2299160j
- end
-
- it "interprets post-Gregorian reform dates using Gregorian calendar" do
- Time.send(@method, 1582, 10, 15, 12).to_i.should == -12219249600 # 2299161j
- end
-end
diff --git a/spec/ruby/core/time/shared/gmt_offset.rb b/spec/ruby/core/time/shared/gmt_offset.rb
deleted file mode 100644
index cb842be2f3..0000000000
--- a/spec/ruby/core/time/shared/gmt_offset.rb
+++ /dev/null
@@ -1,53 +0,0 @@
-describe :time_gmt_offset, shared: true do
- it "returns the offset in seconds between the timezone of time and UTC" do
- with_timezone("AST", 3) do
- Time.new.send(@method).should == 10800
- end
- end
-
- platform_is_not :windows do
- it "returns the correct offset for US Eastern time zone around daylight savings time change" do
- # "2010-03-14 01:59:59 -0500" + 1 ==> "2010-03-14 03:00:00 -0400"
- with_timezone("EST5EDT") do
- t = Time.local(2010,3,14,1,59,59)
- t.send(@method).should == -5*60*60
- (t + 1).send(@method).should == -4*60*60
- end
- end
-
- it "returns the correct offset for Hawaii around daylight savings time change" do
- # "2010-03-14 01:59:59 -1000" + 1 ==> "2010-03-14 02:00:00 -1000"
- with_timezone("Pacific/Honolulu") do
- t = Time.local(2010,3,14,1,59,59)
- t.send(@method).should == -10*60*60
- (t + 1).send(@method).should == -10*60*60
- end
- end
-
- it "returns the correct offset for New Zealand around daylight savings time change" do
- # "2010-04-04 02:59:59 +1300" + 1 ==> "2010-04-04 02:00:00 +1200"
- with_timezone("Pacific/Auckland") do
- t = Time.local(2010,4,4,1,59,59) + (60 * 60)
- t.send(@method).should == 13*60*60
- (t + 1).send(@method).should == 12*60*60
- end
- end
- end
-
- it "returns offset as Rational" do
- Time.new(2010,4,4,1,59,59,7245).send(@method).should == 7245
- Time.new(2010,4,4,1,59,59,7245.5).send(@method).should == Rational(14491,2)
- end
-
- context 'given positive offset' do
- it 'returns a positive offset' do
- Time.new(2013,3,17,nil,nil,nil,"+03:00").send(@method).should == 10800
- end
- end
-
- context 'given negative offset' do
- it 'returns a negative offset' do
- Time.new(2013,3,17,nil,nil,nil,"-03:00").send(@method).should == -10800
- end
- end
-end
diff --git a/spec/ruby/core/time/shared/gmtime.rb b/spec/ruby/core/time/shared/gmtime.rb
deleted file mode 100644
index e684a1fd95..0000000000
--- a/spec/ruby/core/time/shared/gmtime.rb
+++ /dev/null
@@ -1,33 +0,0 @@
-describe :time_gmtime, shared: true do
- it "converts self to UTC, modifying the receiver" do
- # Testing with America/Regina here because it doesn't have DST.
- with_timezone("CST", -6) do
- t = Time.local(2007, 1, 9, 6, 0, 0)
- t.send(@method)
- t.should == Time.gm(2007, 1, 9, 12, 0, 0)
- end
- end
-
- it "returns self" do
- with_timezone("CST", -6) do
- t = Time.local(2007, 1, 9, 12, 0, 0)
- t.send(@method).should equal(t)
- end
- end
-
- describe "on a frozen time" do
- it "does not raise an error if already in UTC" do
- time = Time.gm(2007, 1, 9, 12, 0, 0)
- time.freeze
- time.send(@method).should equal(time)
- end
-
- it "raises a RuntimeError if the time is not UTC" do
- with_timezone("CST", -6) do
- time = Time.now
- time.freeze
- lambda { time.send(@method) }.should raise_error(RuntimeError)
- end
- end
- end
-end
diff --git a/spec/ruby/core/time/shared/inspect.rb b/spec/ruby/core/time/shared/inspect.rb
index c707382a6e..82f7f3c686 100644
--- a/spec/ruby/core/time/shared/inspect.rb
+++ b/spec/ruby/core/time/shared/inspect.rb
@@ -15,9 +15,7 @@ describe :inspect, shared: true do
Time.new(2000, 1, 1, 20, 15, 01, 3600).send(@method).should == "2000-01-01 20:15:01 +0100"
end
- with_feature :encoding do
- it "returns a US-ASCII encoded string" do
- Time.now.send(@method).encoding.should equal(Encoding::US_ASCII)
- end
+ it "returns a US-ASCII encoded string" do
+ Time.now.send(@method).encoding.should.equal?(Encoding::US_ASCII)
end
end
diff --git a/spec/ruby/core/time/shared/isdst.rb b/spec/ruby/core/time/shared/isdst.rb
deleted file mode 100644
index bc6d139230..0000000000
--- a/spec/ruby/core/time/shared/isdst.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-describe :time_isdst, shared: true do
- it "dst? returns whether time is during daylight saving time" do
- with_timezone("America/Los_Angeles") do
- Time.local(2007, 9, 9, 0, 0, 0).send(@method).should == true
- Time.local(2007, 1, 9, 0, 0, 0).send(@method).should == false
- end
- end
-end
diff --git a/spec/ruby/core/time/shared/local.rb b/spec/ruby/core/time/shared/local.rb
index 43f331c4c1..068e314999 100644
--- a/spec/ruby/core/time/shared/local.rb
+++ b/spec/ruby/core/time/shared/local.rb
@@ -7,12 +7,10 @@ describe :time_local, shared: true do
end
platform_is_not :windows do
- describe "timezone changes" do
- it "correctly adjusts the timezone change to 'CEST' on 'Europe/Amsterdam'" do
- with_timezone("Europe/Amsterdam") do
- Time.send(@method, 1940, 5, 16).to_a.should ==
- [0, 40, 1, 16, 5, 1940, 4, 137, true, "CEST"]
- end
+ it "uses the 'CET' timezone with TZ=Europe/Amsterdam in 1970" do
+ with_timezone("Europe/Amsterdam") do
+ Time.send(@method, 1970, 5, 16).to_a.should ==
+ [0, 0, 0, 16, 5, 1970, 6, 136, false, "CET"]
end
end
end
@@ -41,5 +39,4 @@ describe :time_local_10_arg, shared: true do
end
end
end
-
end
diff --git a/spec/ruby/core/time/shared/month.rb b/spec/ruby/core/time/shared/month.rb
deleted file mode 100644
index 31ca679557..0000000000
--- a/spec/ruby/core/time/shared/month.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-describe :time_month, shared: true do
- it "returns the month of the year for a local Time" do
- with_timezone("CET", 1) do
- Time.local(1970, 1).send(@method).should == 1
- end
- end
-
- it "returns the month of the year for a UTC Time" do
- Time.utc(1970, 1).send(@method).should == 1
- end
-
- it "returns the four digit year for a Time with a fixed offset" do
- Time.new(2012, 1, 1, 0, 0, 0, -3600).send(@method).should == 1
- end
-end
diff --git a/spec/ruby/core/time/shared/now.rb b/spec/ruby/core/time/shared/now.rb
index c35115fcf4..839cfdcd2a 100644
--- a/spec/ruby/core/time/shared/now.rb
+++ b/spec/ruby/core/time/shared/now.rb
@@ -1,14 +1,14 @@
-require File.expand_path('../../fixtures/classes', __FILE__)
+require_relative '../fixtures/classes'
describe :time_now, shared: true do
it "creates a subclass instance if called on a subclass" do
- TimeSpecs::SubTime.send(@method).should be_an_instance_of(TimeSpecs::SubTime)
- TimeSpecs::MethodHolder.send(@method).should be_an_instance_of(Time)
+ TimeSpecs::SubTime.send(@method).should.instance_of?(TimeSpecs::SubTime)
+ TimeSpecs::MethodHolder.send(@method).should.instance_of?(Time)
end
it "sets the current time" do
now = TimeSpecs::MethodHolder.send(@method)
- now.to_f.should be_close(Process.clock_gettime(Process::CLOCK_REALTIME), 10.0)
+ now.to_f.should be_close(Process.clock_gettime(Process::CLOCK_REALTIME), TIME_TOLERANCE)
end
it "uses the local timezone" do
@@ -17,4 +17,17 @@ describe :time_now, shared: true do
now.utc_offset.should == (-8 * 60 * 60)
end
end
+
+ it "has at least microsecond precision" do
+ # The clock should not be less accurate than expected (times should
+ # not all be a multiple of the next precision up, assuming precisions
+ # are multiples of ten.)
+ expected = 1_000
+ t = 0
+ 10_000.times.find do
+ t = Time.now.nsec
+ t % (expected * 10) != 0
+ end
+ (t % (expected * 10)).should != 0
+ end
end
diff --git a/spec/ruby/core/time/shared/time_params.rb b/spec/ruby/core/time/shared/time_params.rb
index 120d8d3af1..f0de986b8e 100644
--- a/spec/ruby/core/time/shared/time_params.rb
+++ b/spec/ruby/core/time/shared/time_params.rb
@@ -30,7 +30,7 @@ describe :time_params, shared: true do
end
it "raises a TypeError if the year is nil" do
- lambda { Time.send(@method, nil) }.should raise_error(TypeError)
+ -> { Time.send(@method, nil) }.should.raise(TypeError)
end
it "accepts nil month, day, hour, minute, and second" do
@@ -145,46 +145,55 @@ describe :time_params, shared: true do
end
it "raises an ArgumentError for out of range month" do
- lambda {
- Time.send(@method, 2008, 13, 31, 23, 59, 59)
- }.should raise_error(ArgumentError)
+ # For some reason MRI uses a different message for month in 13-15 and month>=16
+ -> {
+ Time.send(@method, 2008, 16, 31, 23, 59, 59)
+ }.should.raise(ArgumentError, /(mon|argument) out of range/)
end
it "raises an ArgumentError for out of range day" do
- lambda {
+ -> {
Time.send(@method, 2008, 12, 32, 23, 59, 59)
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
end
it "raises an ArgumentError for out of range hour" do
- lambda {
+ -> {
Time.send(@method, 2008, 12, 31, 25, 59, 59)
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
end
it "raises an ArgumentError for out of range minute" do
- lambda {
+ -> {
Time.send(@method, 2008, 12, 31, 23, 61, 59)
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
end
it "raises an ArgumentError for out of range second" do
- lambda {
+ # For some reason MRI uses different messages for seconds 61-63 and seconds >= 64
+ -> {
Time.send(@method, 2008, 12, 31, 23, 59, 61)
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError, /(sec|argument) out of range/)
+ -> {
+ Time.send(@method, 2008, 12, 31, 23, 59, -1)
+ }.should.raise(ArgumentError, "argument out of range")
+ end
+
+ it "raises ArgumentError when given 8 arguments" do
+ -> { Time.send(@method, *[0]*8) }.should.raise(ArgumentError)
end
it "raises ArgumentError when given 9 arguments" do
- lambda { Time.send(@method, *[0]*9) }.should raise_error(ArgumentError)
+ -> { Time.send(@method, *[0]*9) }.should.raise(ArgumentError)
end
it "raises ArgumentError when given 11 arguments" do
- lambda { Time.send(@method, *[0]*11) }.should raise_error(ArgumentError)
+ -> { Time.send(@method, *[0]*11) }.should.raise(ArgumentError)
end
it "returns subclass instances" do
c = Class.new(Time)
- c.send(@method, 2008, "12").should be_an_instance_of(c)
+ c.send(@method, 2008, "12").should.instance_of?(c)
end
end
@@ -202,25 +211,25 @@ describe :time_params_10_arg, shared: true do
end
it "raises an ArgumentError for out of range values" do
- lambda {
+ -> {
Time.send(@method, 61, 59, 23, 31, 12, 2008, :ignored, :ignored, :ignored, :ignored)
- }.should raise_error(ArgumentError) # sec
+ }.should.raise(ArgumentError) # sec
- lambda {
+ -> {
Time.send(@method, 59, 61, 23, 31, 12, 2008, :ignored, :ignored, :ignored, :ignored)
- }.should raise_error(ArgumentError) # min
+ }.should.raise(ArgumentError) # min
- lambda {
+ -> {
Time.send(@method, 59, 59, 25, 31, 12, 2008, :ignored, :ignored, :ignored, :ignored)
- }.should raise_error(ArgumentError) # hour
+ }.should.raise(ArgumentError) # hour
- lambda {
+ -> {
Time.send(@method, 59, 59, 23, 32, 12, 2008, :ignored, :ignored, :ignored, :ignored)
- }.should raise_error(ArgumentError) # day
+ }.should.raise(ArgumentError) # day
- lambda {
+ -> {
Time.send(@method, 59, 59, 23, 31, 13, 2008, :ignored, :ignored, :ignored, :ignored)
- }.should raise_error(ArgumentError) # month
+ }.should.raise(ArgumentError) # month
end
end
@@ -230,6 +239,10 @@ describe :time_params_microseconds, shared: true do
t.usec.should == 123
end
+ it "raises an ArgumentError for out of range microsecond" do
+ -> { Time.send(@method, 2000, 1, 1, 20, 15, 1, 1000000) }.should.raise(ArgumentError)
+ end
+
it "handles fractional microseconds as a Float" do
t = Time.send(@method, 2000, 1, 1, 20, 15, 1, 1.75)
t.usec.should == 1
diff --git a/spec/ruby/core/time/shared/to_i.rb b/spec/ruby/core/time/shared/to_i.rb
deleted file mode 100644
index 03497c700b..0000000000
--- a/spec/ruby/core/time/shared/to_i.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-describe :time_to_i, shared: true do
- it "returns the value of time as an integer number of seconds since epoch" do
- Time.at(0).send(@method).should == 0
- end
-
- it "doesn't return an actual number of seconds in time" do
- Time.at(65.5).send(@method).should == 65
- end
-end
diff --git a/spec/ruby/core/time/strftime_spec.rb b/spec/ruby/core/time/strftime_spec.rb
index 1cb3575eec..1528a668a1 100644
--- a/spec/ruby/core/time/strftime_spec.rb
+++ b/spec/ruby/core/time/strftime_spec.rb
@@ -1,19 +1,19 @@
# encoding: utf-8
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/time/strftime_for_date', __FILE__)
-require File.expand_path('../../../shared/time/strftime_for_time', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../../shared/time/strftime_for_date'
+require_relative '../../shared/time/strftime_for_time'
describe "Time#strftime" do
before :all do
- @new_date = lambda { |y,m,d| Time.gm(y,m,d) }
- @new_time = lambda { |*args| Time.gm(*args) }
- @new_time_in_zone = lambda { |zone,offset,*args|
+ @new_date = -> y, m, d { Time.gm(y,m,d) }
+ @new_time = -> *args { Time.gm(*args) }
+ @new_time_in_zone = -> zone, offset, *args {
with_timezone(zone, offset) do
Time.new(*args)
end
}
- @new_time_with_offset = lambda { |y,m,d,h,min,s,offset|
+ @new_time_with_offset = -> y, m, d, h, min, s, offset {
Time.new(y,m,d,h,min,s,offset)
}
@@ -25,7 +25,7 @@ describe "Time#strftime" do
# Differences with date
it "requires an argument" do
- lambda { @time.strftime }.should raise_error(ArgumentError)
+ -> { @time.strftime }.should.raise(ArgumentError)
end
# %Z is zone name or empty for Time
@@ -49,4 +49,43 @@ describe "Time#strftime" do
time = @new_time_with_offset[2012, 1, 1, 0, 0, 0, Rational(36645, 10)]
time.strftime("%::z").should == "+01:01:05"
end
+
+ it "supports RFC 3339 UTC for unknown offset local time, -0000, as %-z" do
+ time = Time.gm(2022)
+
+ time.strftime("%z").should == "+0000"
+ time.strftime("%-z").should == "-0000"
+ time.strftime("%-:z").should == "-00:00"
+ time.strftime("%-::z").should == "-00:00:00"
+ end
+
+ it "applies '-' flag to UTC time" do
+ time = Time.utc(2022)
+ time.strftime("%-z").should == "-0000"
+
+ time = Time.gm(2022)
+ time.strftime("%-z").should == "-0000"
+
+ time = Time.new(2022, 1, 1, 0, 0, 0, "Z")
+ time.strftime("%-z").should == "-0000"
+
+ time = Time.new(2022, 1, 1, 0, 0, 0, "-00:00")
+ time.strftime("%-z").should == "-0000"
+
+ time = Time.new(2022, 1, 1, 0, 0, 0, "+03:00").utc
+ time.strftime("%-z").should == "-0000"
+ end
+
+ it "ignores '-' flag for non-UTC time" do
+ time = Time.new(2022, 1, 1, 0, 0, 0, "+03:00")
+ time.strftime("%-z").should == "+0300"
+ end
+
+ it "works correctly with width, _ and 0 flags, and :" do
+ Time.now.utc.strftime("%-_10z").should == " -000"
+ Time.now.utc.strftime("%-10z").should == "-000000000"
+ Time.now.utc.strftime("%-010:z").should == "-000000:00"
+ Time.now.utc.strftime("%-_10:z").should == " -0:00"
+ Time.now.utc.strftime("%-_10::z").should == " -0:00:00"
+ end
end
diff --git a/spec/ruby/core/time/subsec_spec.rb b/spec/ruby/core/time/subsec_spec.rb
index d9d262a513..3ed1bf5dd1 100644
--- a/spec/ruby/core/time/subsec_spec.rb
+++ b/spec/ruby/core/time/subsec_spec.rb
@@ -1,27 +1,27 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Time#subsec" do
- it "returns 0 as a Fixnum for a Time with a whole number of seconds" do
- Time.at(100).subsec.should eql(0)
+ it "returns 0 as an Integer for a Time with a whole number of seconds" do
+ Time.at(100).subsec.should.eql?(0)
end
it "returns the fractional seconds as a Rational for a Time constructed with a Rational number of seconds" do
- Time.at(Rational(3, 2)).subsec.should eql(Rational(1, 2))
+ Time.at(Rational(3, 2)).subsec.should.eql?(Rational(1, 2))
end
it "returns the fractional seconds as a Rational for a Time constructed with a Float number of seconds" do
- Time.at(10.75).subsec.should eql(Rational(3, 4))
+ Time.at(10.75).subsec.should.eql?(Rational(3, 4))
end
it "returns the fractional seconds as a Rational for a Time constructed with an Integer number of microseconds" do
- Time.at(0, 999999).subsec.should eql(Rational(999999, 1000000))
+ Time.at(0, 999999).subsec.should.eql?(Rational(999999, 1000000))
end
it "returns the fractional seconds as a Rational for a Time constructed with an Rational number of microseconds" do
- Time.at(0, Rational(9, 10)).subsec.should eql(Rational(9, 10000000))
+ Time.at(0, Rational(9, 10)).subsec.should.eql?(Rational(9, 10000000))
end
it "returns the fractional seconds as a Rational for a Time constructed with an Float number of microseconds" do
- Time.at(0, 0.75).subsec.should eql(Rational(3, 4000000))
+ Time.at(0, 0.75).subsec.should.eql?(Rational(3, 4000000))
end
end
diff --git a/spec/ruby/core/time/succ_spec.rb b/spec/ruby/core/time/succ_spec.rb
deleted file mode 100644
index 6831200741..0000000000
--- a/spec/ruby/core/time/succ_spec.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-describe "Time#succ" do
- it "returns a new time one second later than time" do
- -> {
- @result = Time.at(100).succ
- }.should complain(/Time#succ is obsolete/)
- @result.should == Time.at(101)
- end
-
- it "returns a new instance" do
- t1 = Time.at(100)
- t2 = nil
- -> {
- t2 = t1.succ
- }.should complain(/Time#succ is obsolete/)
- t1.object_id.should_not == t2.object_id
- end
-end
diff --git a/spec/ruby/core/time/sunday_spec.rb b/spec/ruby/core/time/sunday_spec.rb
index 823174cf71..0d46421132 100644
--- a/spec/ruby/core/time/sunday_spec.rb
+++ b/spec/ruby/core/time/sunday_spec.rb
@@ -1,11 +1,11 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Time#sunday?" do
it "returns true if time represents Sunday" do
- Time.local(2000, 1, 2).sunday?.should == true
+ Time.local(2000, 1, 2).should.sunday?
end
it "returns false if time doesn't represent Sunday" do
- Time.local(2000, 1, 1).sunday?.should == false
+ Time.local(2000, 1, 1).should_not.sunday?
end
end
diff --git a/spec/ruby/core/time/thursday_spec.rb b/spec/ruby/core/time/thursday_spec.rb
index 5788fd9bc7..c11e79d2fa 100644
--- a/spec/ruby/core/time/thursday_spec.rb
+++ b/spec/ruby/core/time/thursday_spec.rb
@@ -1,11 +1,11 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Time#thursday?" do
it "returns true if time represents Thursday" do
- Time.local(2000, 1, 6).thursday?.should == true
+ Time.local(2000, 1, 6).should.thursday?
end
it "returns false if time doesn't represent Thursday" do
- Time.local(2000, 1, 1).thursday?.should == false
+ Time.local(2000, 1, 1).should_not.thursday?
end
end
diff --git a/spec/ruby/core/time/time_spec.rb b/spec/ruby/core/time/time_spec.rb
index 1c870c8e0f..b0803a7f21 100644
--- a/spec/ruby/core/time/time_spec.rb
+++ b/spec/ruby/core/time/time_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Time" do
it "includes Comparable" do
diff --git a/spec/ruby/core/time/to_a_spec.rb b/spec/ruby/core/time/to_a_spec.rb
index a4c4a8fbc9..3728b8c526 100644
--- a/spec/ruby/core/time/to_a_spec.rb
+++ b/spec/ruby/core/time/to_a_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Time#to_a" do
platform_is_not :windows do
diff --git a/spec/ruby/core/time/to_f_spec.rb b/spec/ruby/core/time/to_f_spec.rb
index d737848b4b..6101dcf871 100644
--- a/spec/ruby/core/time/to_f_spec.rb
+++ b/spec/ruby/core/time/to_f_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Time#to_f" do
it "returns the float number of seconds + usecs since the epoch" do
diff --git a/spec/ruby/core/time/to_i_spec.rb b/spec/ruby/core/time/to_i_spec.rb
index 1a733f02cf..00c4215d31 100644
--- a/spec/ruby/core/time/to_i_spec.rb
+++ b/spec/ruby/core/time/to_i_spec.rb
@@ -1,6 +1,18 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/to_i', __FILE__)
+require_relative '../../spec_helper'
describe "Time#to_i" do
- it_behaves_like(:time_to_i, :to_i)
+ it "returns the value of time as an integer number of seconds since epoch" do
+ Time.at(0).to_i.should == 0
+ end
+
+ it "doesn't return an actual number of seconds in time" do
+ Time.at(65.5).to_i.should == 65
+ end
+
+ it "rounds fractional seconds toward zero" do
+ t = Time.utc(1960, 1, 1, 0, 0, 0, 999_999)
+
+ t.to_f.to_i.should == -315619199
+ t.to_i.should == -315619200
+ end
end
diff --git a/spec/ruby/core/time/to_r_spec.rb b/spec/ruby/core/time/to_r_spec.rb
index 53e469463a..e30f5d8f94 100644
--- a/spec/ruby/core/time/to_r_spec.rb
+++ b/spec/ruby/core/time/to_r_spec.rb
@@ -1,11 +1,11 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Time#to_r" do
it "returns the a Rational representing seconds and subseconds since the epoch" do
- Time.at(Rational(11, 10)).to_r.should eql(Rational(11, 10))
+ Time.at(Rational(11, 10)).to_r.should.eql?(Rational(11, 10))
end
it "returns a Rational even for a whole number of seconds" do
- Time.at(2).to_r.should eql(Rational(2))
+ Time.at(2).to_r.should.eql?(Rational(2))
end
end
diff --git a/spec/ruby/core/time/to_s_spec.rb b/spec/ruby/core/time/to_s_spec.rb
index 8dc81f60a9..ac6c0908ac 100644
--- a/spec/ruby/core/time/to_s_spec.rb
+++ b/spec/ruby/core/time/to_s_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/inspect', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/inspect'
describe "Time#to_s" do
it_behaves_like :inspect, :to_s
diff --git a/spec/ruby/core/time/tuesday_spec.rb b/spec/ruby/core/time/tuesday_spec.rb
index 87c3236eea..0e7b9e7506 100644
--- a/spec/ruby/core/time/tuesday_spec.rb
+++ b/spec/ruby/core/time/tuesday_spec.rb
@@ -1,11 +1,11 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Time#tuesday?" do
it "returns true if time represents Tuesday" do
- Time.local(2000, 1, 4).tuesday?.should == true
+ Time.local(2000, 1, 4).should.tuesday?
end
it "returns false if time doesn't represent Tuesday" do
- Time.local(2000, 1, 1).tuesday?.should == false
+ Time.local(2000, 1, 1).should_not.tuesday?
end
end
diff --git a/spec/ruby/core/time/tv_nsec_spec.rb b/spec/ruby/core/time/tv_nsec_spec.rb
index d477f6fbec..802138bf3a 100644
--- a/spec/ruby/core/time/tv_nsec_spec.rb
+++ b/spec/ruby/core/time/tv_nsec_spec.rb
@@ -1,5 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Time#tv_nsec" do
- it "needs to be reviewed for spec completeness"
+ it "is an alias of Time#nsec" do
+ Time.instance_method(:tv_nsec).should == Time.instance_method(:nsec)
+ end
end
diff --git a/spec/ruby/core/time/tv_sec_spec.rb b/spec/ruby/core/time/tv_sec_spec.rb
index 36f090be7b..21bdb53ee6 100644
--- a/spec/ruby/core/time/tv_sec_spec.rb
+++ b/spec/ruby/core/time/tv_sec_spec.rb
@@ -1,6 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/to_i', __FILE__)
+require_relative '../../spec_helper'
describe "Time#tv_sec" do
- it_behaves_like(:time_to_i, :tv_sec)
+ it "is an alias of Time#to_i" do
+ Time.instance_method(:tv_sec).should == Time.instance_method(:to_i)
+ end
end
diff --git a/spec/ruby/core/time/tv_usec_spec.rb b/spec/ruby/core/time/tv_usec_spec.rb
index 4a1b87be7a..e922ee5625 100644
--- a/spec/ruby/core/time/tv_usec_spec.rb
+++ b/spec/ruby/core/time/tv_usec_spec.rb
@@ -1,5 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Time#tv_usec" do
- it "needs to be reviewed for spec completeness"
+ it "is an alias of Time#usec" do
+ Time.instance_method(:tv_usec).should == Time.instance_method(:usec)
+ end
end
diff --git a/spec/ruby/core/time/usec_spec.rb b/spec/ruby/core/time/usec_spec.rb
index 018253ec77..6ea52f5e79 100644
--- a/spec/ruby/core/time/usec_spec.rb
+++ b/spec/ruby/core/time/usec_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Time#usec" do
it "returns 0 for a Time constructed with a whole number of seconds" do
@@ -36,4 +36,8 @@ describe "Time#usec" do
it "returns the microseconds for time created by Time#local" do
Time.local(1,2,3,4,5,Rational(6.78)).usec.should == 780000
end
+
+ it "returns a positive value for dates before the epoch" do
+ Time.utc(1969, 11, 12, 13, 18, 57, 404240).usec.should == 404240
+ end
end
diff --git a/spec/ruby/core/time/utc_offset_spec.rb b/spec/ruby/core/time/utc_offset_spec.rb
index 4be885f2e3..8d2fff2012 100644
--- a/spec/ruby/core/time/utc_offset_spec.rb
+++ b/spec/ruby/core/time/utc_offset_spec.rb
@@ -1,6 +1,61 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/gmt_offset', __FILE__)
+require_relative '../../spec_helper'
describe "Time#utc_offset" do
- it_behaves_like(:time_gmt_offset, :utc_offset)
+ it "returns the offset in seconds between the timezone of time and UTC" do
+ with_timezone("AST", 3) do
+ Time.new.utc_offset.should == 10800
+ end
+ end
+
+ it "returns 0 when the date is UTC" do
+ with_timezone("AST", 3) do
+ Time.new.utc.utc_offset.should == 0
+ end
+ end
+
+ platform_is_not :windows do
+ it "returns the correct offset for US Eastern time zone around daylight savings time change" do
+ # "2010-03-14 01:59:59 -0500" + 1 ==> "2010-03-14 03:00:00 -0400"
+ with_timezone("EST5EDT") do
+ t = Time.local(2010,3,14,1,59,59)
+ t.utc_offset.should == -5*60*60
+ (t + 1).utc_offset.should == -4*60*60
+ end
+ end
+
+ it "returns the correct offset for Hawaii around daylight savings time change" do
+ # "2010-03-14 01:59:59 -1000" + 1 ==> "2010-03-14 02:00:00 -1000"
+ with_timezone("Pacific/Honolulu") do
+ t = Time.local(2010,3,14,1,59,59)
+ t.utc_offset.should == -10*60*60
+ (t + 1).utc_offset.should == -10*60*60
+ end
+ end
+
+ it "returns the correct offset for New Zealand around daylight savings time change" do
+ # "2010-04-04 02:59:59 +1300" + 1 ==> "2010-04-04 02:00:00 +1200"
+ with_timezone("Pacific/Auckland") do
+ t = Time.local(2010,4,4,1,59,59) + (60 * 60)
+ t.utc_offset.should == 13*60*60
+ (t + 1).utc_offset.should == 12*60*60
+ end
+ end
+ end
+
+ it "returns offset as Rational" do
+ Time.new(2010,4,4,1,59,59,7245).utc_offset.should == 7245
+ Time.new(2010,4,4,1,59,59,7245.5).utc_offset.should == Rational(14491,2)
+ end
+
+ context 'given positive offset' do
+ it 'returns a positive offset' do
+ Time.new(2013,3,17,nil,nil,nil,"+03:00").utc_offset.should == 10800
+ end
+ end
+
+ context 'given negative offset' do
+ it 'returns a negative offset' do
+ Time.new(2013,3,17,nil,nil,nil,"-03:00").utc_offset.should == -10800
+ end
+ end
end
diff --git a/spec/ruby/core/time/utc_spec.rb b/spec/ruby/core/time/utc_spec.rb
index f88b9c7cbc..35c1daa9e5 100644
--- a/spec/ruby/core/time/utc_spec.rb
+++ b/spec/ruby/core/time/utc_spec.rb
@@ -1,21 +1,169 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/gm', __FILE__)
-require File.expand_path('../shared/gmtime', __FILE__)
-require File.expand_path('../shared/time_params', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/time_params'
describe "Time#utc?" do
- it "returns true if time represents a time in UTC (GMT)" do
+ it "returns true only if time represents a time in UTC (GMT)" do
Time.now.utc?.should == false
+ Time.now.utc.utc?.should == true
+ end
+
+ it "treats time as UTC what was created in different ways" do
+ Time.now.utc.utc?.should == true
+ Time.now.utc.utc?.should == true
+ Time.now.getgm.utc?.should == true
+ Time.now.getutc.utc?.should == true
+ Time.utc(2022).utc?.should == true
+ end
+
+ it "does treat time with 'UTC' offset as UTC" do
+ Time.new(2022, 1, 1, 0, 0, 0, "UTC").utc?.should == true
+ Time.now.localtime("UTC").utc?.should == true
+ Time.at(Time.now, in: 'UTC').utc?.should == true
+
+ Time.new(2022, 1, 1, 0, 0, 0, in: "UTC").utc?.should == true
+ Time.now(in: "UTC").utc?.should == true
+ end
+
+ it "does treat time with Z offset as UTC" do
+ Time.new(2022, 1, 1, 0, 0, 0, "Z").utc?.should == true
+ Time.now.localtime("Z").utc?.should == true
+ Time.at(Time.now, in: 'Z').utc?.should == true
+
+ Time.new(2022, 1, 1, 0, 0, 0, in: "Z").utc?.should == true
+ Time.now(in: "Z").utc?.should == true
+ end
+
+ it "does treat time with -00:00 offset as UTC" do
+ Time.new(2022, 1, 1, 0, 0, 0, "-00:00").utc?.should == true
+ Time.now.localtime("-00:00").utc?.should == true
+ Time.at(Time.now, in: '-00:00').utc?.should == true
+ end
+
+ it "does not treat time with +00:00 offset as UTC" do
+ Time.new(2022, 1, 1, 0, 0, 0, "+00:00").utc?.should == false
+ Time.now.localtime("+00:00").utc?.should == false
+ Time.at(Time.now, in: "+00:00").utc?.should == false
+ end
+
+ it "does not treat time with 0 offset as UTC" do
+ Time.new(2022, 1, 1, 0, 0, 0, 0).utc?.should == false
+ Time.now.localtime(0).utc?.should == false
+ Time.at(Time.now, in: 0).utc?.should == false
end
end
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_params, :utc
+ it_behaves_like :time_params_10_arg, :utc
+ it_behaves_like :time_params_microseconds, :utc
+
+ it "creates a time based on given values, interpreted as UTC (GMT)" do
+ Time.utc(2000,"jan",1,20,15,1).inspect.should == "2000-01-01 20:15:01 UTC"
+ end
+
+ it "creates a time based on given C-style gmtime arguments, interpreted as UTC (GMT)" do
+ time = Time.utc(1, 15, 20, 1, 1, 2000, :ignored, :ignored, :ignored, :ignored)
+ time.inspect.should == "2000-01-01 20:15:01 UTC"
+ end
+
+ it "interprets pre-Gregorian reform dates using Gregorian proleptic calendar" do
+ Time.utc(1582, 10, 4, 12).to_i.should == -12220200000 # 2299150j
+ end
+
+ it "interprets Julian-Gregorian gap dates using Gregorian proleptic calendar" do
+ Time.utc(1582, 10, 14, 12).to_i.should == -12219336000 # 2299160j
+ end
+
+ it "interprets post-Gregorian reform dates using Gregorian calendar" do
+ Time.utc(1582, 10, 15, 12).to_i.should == -12219249600 # 2299161j
+ end
+
+ it "handles fractional usec close to rounding limit" do
+ time = Time.utc(2000, 1, 1, 12, 30, 0, 9999r/10000)
+
+ time.usec.should == 0
+ time.nsec.should == 999
+ end
+
+ guard -> {
+ with_timezone 'right/UTC' do
+ (Time.utc(1972, 6, 30, 23, 59, 59) + 1).sec == 60
+ end
+ } do
+ it "handles real leap seconds in zone 'right/UTC'" do
+ with_timezone 'right/UTC' do
+ time = Time.utc(1972, 6, 30, 23, 59, 60)
+
+ time.sec.should == 60
+ time.min.should == 59
+ time.hour.should == 23
+ time.day.should == 30
+ time.month.should == 6
+ end
+ end
+ end
+
+ it "handles bad leap seconds by carrying values forward" do
+ with_timezone 'UTC' do
+ time = Time.utc(2017, 7, 5, 23, 59, 60)
+ time.sec.should == 0
+ time.min.should == 0
+ time.hour.should == 0
+ time.day.should == 6
+ time.month.should == 7
+ end
+ end
+
+ it "handles a value of 60 for seconds by carrying values forward in zone 'UTC'" do
+ with_timezone 'UTC' do
+ time = Time.utc(1972, 6, 30, 23, 59, 60)
+
+ time.sec.should == 0
+ time.min.should == 0
+ time.hour.should == 0
+ time.day.should == 1
+ time.month.should == 7
+ end
+ end
end
describe "Time#utc" do
- it_behaves_like(:time_gmtime, :utc)
+ it "converts self to UTC, modifying the receiver" do
+ # Testing with America/Regina here because it doesn't have DST.
+ with_timezone("CST", -6) do
+ t = Time.local(2007, 1, 9, 6, 0, 0)
+ t.utc
+ # Time#== compensates for time zones, so check all parts separately
+ t.year.should == 2007
+ t.month.should == 1
+ t.mday.should == 9
+ t.hour.should == 12
+ t.min.should == 0
+ t.sec.should == 0
+ t.zone.should == "UTC"
+ end
+ end
+
+ it "returns self" do
+ with_timezone("CST", -6) do
+ t = Time.local(2007, 1, 9, 12, 0, 0)
+ t.utc.should.equal?(t)
+ end
+ end
+
+ describe "on a frozen time" do
+ it "does not raise an error if already in UTC" do
+ time = Time.gm(2007, 1, 9, 12, 0, 0)
+ time.freeze
+ time.utc.should.equal?(time)
+ end
+
+ it "raises a FrozenError if the time is not UTC" do
+ with_timezone("CST", -6) do
+ time = Time.now
+ time.freeze
+ -> { time.utc }.should.raise(FrozenError)
+ end
+ end
+ end
end
diff --git a/spec/ruby/core/time/wday_spec.rb b/spec/ruby/core/time/wday_spec.rb
index 72bc718356..9f63f67de9 100644
--- a/spec/ruby/core/time/wday_spec.rb
+++ b/spec/ruby/core/time/wday_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Time#wday" do
it "returns an integer representing the day of the week, 0..6, with Sunday being 0" do
diff --git a/spec/ruby/core/time/wednesday_spec.rb b/spec/ruby/core/time/wednesday_spec.rb
index 8e836e3e02..cc686681d7 100644
--- a/spec/ruby/core/time/wednesday_spec.rb
+++ b/spec/ruby/core/time/wednesday_spec.rb
@@ -1,11 +1,11 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Time#wednesday?" do
it "returns true if time represents Wednesday" do
- Time.local(2000, 1, 5).wednesday?.should == true
+ Time.local(2000, 1, 5).should.wednesday?
end
it "returns false if time doesn't represent Wednesday" do
- Time.local(2000, 1, 1).wednesday?.should == false
+ Time.local(2000, 1, 1).should_not.wednesday?
end
end
diff --git a/spec/ruby/core/time/xmlschema_spec.rb b/spec/ruby/core/time/xmlschema_spec.rb
new file mode 100644
index 0000000000..6a26861a45
--- /dev/null
+++ b/spec/ruby/core/time/xmlschema_spec.rb
@@ -0,0 +1,9 @@
+require_relative '../../spec_helper'
+
+describe "Time#xmlschema" do
+ ruby_version_is "3.4" do
+ it "is an alias of Time#iso8601" do
+ Time.instance_method(:xmlschema).should == Time.instance_method(:iso8601)
+ end
+ end
+end
diff --git a/spec/ruby/core/time/yday_spec.rb b/spec/ruby/core/time/yday_spec.rb
index 2b7aca1565..e920c2e28d 100644
--- a/spec/ruby/core/time/yday_spec.rb
+++ b/spec/ruby/core/time/yday_spec.rb
@@ -1,4 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../../shared/time/yday'
describe "Time#yday" do
it "returns an integer representing the day of the year, 1..366" do
@@ -7,15 +8,5 @@ describe "Time#yday" do
end
end
- it 'returns the correct value for each day of each month' do
- mdays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
-
- yday = 1
- mdays.each_with_index do |days, month|
- days.times do |day|
- Time.new(2014, month+1, day+1).yday.should == yday
- yday += 1
- end
- end
- end
+ it_behaves_like :time_yday, -> year, month, day { Time.new(year, month, day).yday }
end
diff --git a/spec/ruby/core/time/year_spec.rb b/spec/ruby/core/time/year_spec.rb
index 4e18eb1353..d2d50062c5 100644
--- a/spec/ruby/core/time/year_spec.rb
+++ b/spec/ruby/core/time/year_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Time#year" do
it "returns the four digit year for a local Time as an Integer" do
diff --git a/spec/ruby/core/time/zone_spec.rb b/spec/ruby/core/time/zone_spec.rb
index 9c7acd66e3..2cb3c5e7bb 100644
--- a/spec/ruby/core/time/zone_spec.rb
+++ b/spec/ruby/core/time/zone_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Time#zone" do
platform_is_not :windows do
@@ -6,7 +6,7 @@ describe "Time#zone" do
with_timezone("America/New_York") do
Time.new(2001, 1, 1, 0, 0, 0).zone.should == "EST"
Time.new(2001, 7, 1, 0, 0, 0).zone.should == "EDT"
- %w[EST EDT].should include Time.now.zone
+ %w[EST EDT].should.include? Time.now.zone
end
end
end
@@ -29,7 +29,7 @@ describe "Time#zone" do
t = Time.new(2005, 2, 27, 22, 50, 0, -3600)
with_timezone("America/New_York") do
- t.getlocal("+05:00").zone.should be_nil
+ t.getlocal("+05:00").zone.should == nil
end
end
@@ -52,14 +52,35 @@ describe "Time#zone" do
end
it "doesn't raise errors for a Time with a fixed offset" do
- lambda {
- Time.new(2001, 1, 1, 0, 0, 0, "+05:00").zone
- }.should_not raise_error
+ Time.new(2001, 1, 1, 0, 0, 0, "+05:00").zone.should == nil
end
end
it "returns UTC when called on a UTC time" do
Time.now.utc.zone.should == "UTC"
+ Time.now.gmtime.zone.should == "UTC"
+ Time.now.getgm.zone.should == "UTC"
+ Time.now.getutc.zone.should == "UTC"
+ Time.utc(2022).zone.should == "UTC"
+ Time.new(2022, 1, 1, 0, 0, 0, "UTC").zone.should == "UTC"
+ Time.new(2022, 1, 1, 0, 0, 0, "Z").zone.should == "UTC"
+ Time.now.localtime("UTC").zone.should == "UTC"
+ Time.now.localtime("Z").zone.should == "UTC"
+ Time.at(Time.now, in: 'UTC').zone.should == "UTC"
+ Time.at(Time.now, in: 'Z').zone.should == "UTC"
+
+ Time.new(2022, 1, 1, 0, 0, 0, "-00:00").zone.should == "UTC"
+ Time.now.localtime("-00:00").zone.should == "UTC"
+ Time.at(Time.now, in: '-00:00').zone.should == "UTC"
+
+ Time.new(2022, 1, 1, 0, 0, 0, in: "UTC").zone.should == "UTC"
+ Time.new(2022, 1, 1, 0, 0, 0, in: "Z").zone.should == "UTC"
+
+ Time.now(in: 'UTC').zone.should == "UTC"
+ Time.now(in: 'Z').zone.should == "UTC"
+
+ Time.at(Time.now, in: 'UTC').zone.should == "UTC"
+ Time.at(Time.now, in: 'Z').zone.should == "UTC"
end
platform_is_not :aix, :windows do
diff --git a/spec/ruby/core/tracepoint/allow_reentry_spec.rb b/spec/ruby/core/tracepoint/allow_reentry_spec.rb
new file mode 100644
index 0000000000..475cca29a9
--- /dev/null
+++ b/spec/ruby/core/tracepoint/allow_reentry_spec.rb
@@ -0,0 +1,30 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe 'TracePoint.allow_reentry' do
+ it 'allows the reentrance in a given block' do
+ event_lines = []
+ l1 = l2 = l3 = l4 = nil
+ TracePoint.new(:line) do |tp|
+ next unless TracePointSpec.target_thread?
+
+ event_lines << tp.lineno
+ next if (__LINE__ + 2 .. __LINE__ + 4).cover?(tp.lineno)
+ TracePoint.allow_reentry do
+ a = 1; l3 = __LINE__
+ b = 2; l4 = __LINE__
+ end
+ end.enable do
+ c = 3; l1 = __LINE__
+ d = 4; l2 = __LINE__
+ end
+
+ event_lines.should == [l1, l3, l4, l2, l3, l4]
+ end
+
+ it 'raises RuntimeError when not called inside a TracePoint' do
+ -> {
+ TracePoint.allow_reentry{}
+ }.should.raise(RuntimeError)
+ end
+end
diff --git a/spec/ruby/core/tracepoint/binding_spec.rb b/spec/ruby/core/tracepoint/binding_spec.rb
new file mode 100644
index 0000000000..6de6e47d7d
--- /dev/null
+++ b/spec/ruby/core/tracepoint/binding_spec.rb
@@ -0,0 +1,21 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe 'TracePoint#binding' do
+ def test
+ secret = 42
+ end
+
+ it 'return the generated binding object from event' do
+ bindings = []
+ TracePoint.new(:return) { |tp|
+ next unless TracePointSpec.target_thread?
+ bindings << tp.binding
+ }.enable {
+ test
+ }
+ bindings.size.should == 1
+ bindings[0].should.is_a?(Binding)
+ bindings[0].local_variables.should == [:secret]
+ end
+end
diff --git a/spec/ruby/core/tracepoint/callee_id_spec.rb b/spec/ruby/core/tracepoint/callee_id_spec.rb
index b7571027d6..cc08a45504 100644
--- a/spec/ruby/core/tracepoint/callee_id_spec.rb
+++ b/spec/ruby/core/tracepoint/callee_id_spec.rb
@@ -1,20 +1,18 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
-ruby_version_is '2.4' do
- describe "TracePoint#callee_id" do
- it "returns the called name of the method being called" do
- a = []
- obj = TracePointSpec::ClassWithMethodAlias.new
+describe "TracePoint#callee_id" do
+ it "returns the called name of the method being called" do
+ a = []
+ obj = TracePointSpec::ClassWithMethodAlias.new
- TracePoint.new(:call) do |tp|
- a << tp.callee_id
- end.enable do
- obj.m_alias
- end
-
- a.should == [:m_alias]
+ TracePoint.new(:call) do |tp|
+ next unless TracePointSpec.target_thread?
+ a << tp.callee_id
+ end.enable do
+ obj.m_alias
end
+
+ a.should == [:m_alias]
end
end
-
diff --git a/spec/ruby/core/tracepoint/defined_class_spec.rb b/spec/ruby/core/tracepoint/defined_class_spec.rb
new file mode 100644
index 0000000000..53c86a8210
--- /dev/null
+++ b/spec/ruby/core/tracepoint/defined_class_spec.rb
@@ -0,0 +1,27 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe 'TracePoint#defined_class' do
+ it 'returns class or module of the method being called' do
+ last_class_name = nil
+ TracePoint.new(:call) do |tp|
+ next unless TracePointSpec.target_thread?
+ last_class_name = tp.defined_class
+ end.enable do
+ TracePointSpec::B.new.foo
+ last_class_name.should.equal?(TracePointSpec::B)
+
+ TracePointSpec::B.new.bar
+ last_class_name.should.equal?(TracePointSpec::A)
+
+ c = TracePointSpec::C.new
+ last_class_name.should.equal?(TracePointSpec::C)
+
+ c.foo
+ last_class_name.should.equal?(TracePointSpec::B)
+
+ c.bar
+ last_class_name.should.equal?(TracePointSpec::A)
+ end
+ end
+end
diff --git a/spec/ruby/core/tracepoint/disable_spec.rb b/spec/ruby/core/tracepoint/disable_spec.rb
new file mode 100644
index 0000000000..73a31b3b81
--- /dev/null
+++ b/spec/ruby/core/tracepoint/disable_spec.rb
@@ -0,0 +1,76 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe 'TracePoint#disable' do
+ it 'returns true if trace was enabled' do
+ called = false
+ trace = TracePoint.new(:line) do |tp|
+ next unless TracePointSpec.target_thread?
+ called = true
+ end
+
+ trace.enable
+ begin
+ line_event = true
+ ensure
+ ret = trace.disable
+ ret.should == true
+ end
+ called.should == true
+
+ # Check the TracePoint is disabled
+ called = false
+ line_event = true
+ called.should == false
+ end
+
+ it 'returns false if trace was disabled' do
+ called = false
+ trace = TracePoint.new(:line) do |tp|
+ next unless TracePointSpec.target_thread?
+ called = true
+ end
+
+ line_event = true
+ trace.disable.should == false
+ line_event = true
+ called.should == false
+ end
+
+ it 'is disabled within a block & is enabled outside the block' do
+ enabled = nil
+ trace = TracePoint.new(:line) {}
+ trace.enable
+ begin
+ trace.disable { enabled = trace.enabled? }
+ enabled.should == false
+ trace.should.enabled?
+ ensure
+ trace.disable
+ end
+ end
+
+ it 'returns the return value of the block' do
+ trace = TracePoint.new(:line) {}
+ trace.enable
+ begin
+ trace.disable { 42 }.should == 42
+ trace.should.enabled?
+ ensure
+ trace.disable
+ end
+ end
+
+ it 'can accept param within a block but it should not yield arguments' do
+ trace = TracePoint.new(:line) {}
+ trace.enable
+ begin
+ trace.disable do |*args|
+ args.should == []
+ end
+ trace.should.enabled?
+ ensure
+ trace.disable
+ end
+ end
+end
diff --git a/spec/ruby/core/tracepoint/enable_spec.rb b/spec/ruby/core/tracepoint/enable_spec.rb
new file mode 100644
index 0000000000..bf61c35154
--- /dev/null
+++ b/spec/ruby/core/tracepoint/enable_spec.rb
@@ -0,0 +1,543 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe 'TracePoint#enable' do
+ describe 'without a block' do
+ it 'returns false if trace was disabled' do
+ called = false
+ trace = TracePoint.new(:line) do |tp|
+ next unless TracePointSpec.target_thread?
+ called = true
+ end
+
+ line_event = true
+ called.should == false
+
+ ret = trace.enable
+ begin
+ ret.should == false
+ line_event = true
+ called.should == true
+ ensure
+ trace.disable
+ end
+ end
+
+ it 'returns true if trace was already enabled' do
+ called = false
+ trace = TracePoint.new(:line) do |tp|
+ next unless TracePointSpec.target_thread?
+ called = true
+ end
+
+ line_event = true
+ called.should == false
+
+ ret = trace.enable
+ begin
+ ret.should == false
+
+ trace.enable.should == true
+
+ line_event = true
+ called.should == true
+ ensure
+ trace.disable
+ trace.should_not.enabled?
+ end
+ end
+ end
+
+ describe 'with a block' do
+ it 'enables the trace object within a block' do
+ event_name = nil
+ TracePoint.new(:line) do |tp|
+ next unless TracePointSpec.target_thread?
+ event_name = tp.event
+ end.enable { event_name.should.equal?(:line) }
+ end
+
+ it 'enables the trace object only for the current thread' do
+ threads = []
+ trace = TracePoint.new(:line) do |tp|
+ # Runs on purpose on any Thread
+ threads << Thread.current
+ end
+
+ thread = nil
+ trace.enable do
+ line_event = true
+ thread = Thread.new do
+ event_in_other_thread = true
+ end
+ thread.join
+ end
+
+ threads = threads.uniq
+ threads.should.include?(Thread.current)
+ threads.should_not.include?(thread)
+ end
+
+ it 'can accept arguments within a block but it should not yield arguments' do
+ event_name = nil
+ trace = TracePoint.new(:line) do |tp|
+ next unless TracePointSpec.target_thread?
+ event_name = tp.event
+ end
+ trace.enable do |*args|
+ event_name.should.equal?(:line)
+ args.should == []
+ end
+ trace.should_not.enabled?
+ end
+
+ it 'enables trace object on calling with a block if it was already enabled' do
+ enabled = nil
+ trace = TracePoint.new(:line) {}
+ trace.enable
+ begin
+ trace.enable { enabled = trace.enabled? }
+ enabled.should == true
+ ensure
+ trace.disable
+ end
+ end
+
+ it 'returns the return value of the block' do
+ trace = TracePoint.new(:line) {}
+ trace.enable { 42 }.should == 42
+ end
+
+ it 'disables the trace object outside the block' do
+ called = false
+ trace = TracePoint.new(:line) do
+ next unless TracePointSpec.target_thread?
+ called = true
+ end
+ trace.enable {
+ line_event = true
+ }
+ called.should == true
+ trace.should_not.enabled?
+ end
+ end
+
+ describe "when nested" do
+ before do
+ @path_prefix = ' '
+ end
+
+ it "enables both TracePoints but only calls the respective callbacks" do
+ called = false
+ first = TracePoint.new(:line) do |tp|
+ next unless TracePointSpec.target_thread?
+ called = true
+ end
+
+ all = []
+ inspects = []
+ second = TracePoint.new(:line) { |tp|
+ next unless TracePointSpec.target_thread?
+ all << tp
+ inspects << tp.inspect
+ }
+
+ line = nil
+ first.enable do
+ second.enable do
+ line = __LINE__
+ end
+ end
+
+ all.uniq.should == [second]
+ inspects.uniq.should == ["#<TracePoint:line#{@path_prefix}#{__FILE__}:#{line}>"]
+ called.should == true
+ end
+ end
+
+ describe 'target: option' do
+ before :each do
+ ScratchPad.record []
+ end
+
+ it 'enables trace point for specific location' do
+ trace = TracePoint.new(:call) do |tp|
+ next unless TracePointSpec.target_thread?
+ ScratchPad << tp.method_id
+ end
+
+ obj = Object.new
+ def obj.foo; end
+ def obj.bar; end
+
+ trace.enable(target: obj.method(:foo)) do
+ obj.foo
+ obj.bar
+ end
+
+ ScratchPad.recorded.should == [:foo]
+ end
+
+ it 'traces all the events triggered in specified location' do
+ trace = TracePoint.new(:line, :call, :return, :b_call, :b_return) do |tp|
+ next unless TracePointSpec.target_thread?
+ ScratchPad << tp.event
+ end
+
+ obj = Object.new
+ def obj.foo
+ bar
+ -> {}.call
+ end
+ def obj.bar; end
+
+ trace.enable(target: obj.method(:foo)) do
+ obj.foo
+ end
+
+ ScratchPad.recorded.uniq.sort.should == [:call, :return, :b_call, :b_return, :line].sort
+ end
+
+ it 'does not trace events in nested locations' do
+ trace = TracePoint.new(:call) do |tp|
+ next unless TracePointSpec.target_thread?
+ ScratchPad << tp.method_id
+ end
+
+ obj = Object.new
+ def obj.foo
+ bar
+ end
+ def obj.bar
+ baz
+ end
+ def obj.baz
+ end
+
+ trace.enable(target: obj.method(:foo)) do
+ obj.foo
+ end
+
+ ScratchPad.recorded.should == [:foo]
+ end
+
+ it "traces some events in nested blocks" do
+ klass = Class.new do
+ def foo
+ 1.times do
+ 1.times do
+ bar do
+ end
+ end
+ end
+ end
+
+ def bar(&blk)
+ blk.call
+ end
+ end
+
+ trace = TracePoint.new(:b_call) do |tp|
+ next unless TracePointSpec.target_thread?
+ ScratchPad << tp.lineno
+ end
+
+ obj = klass.new
+ _, lineno = obj.method(:foo).source_location
+
+ trace.enable(target: obj.method(:foo)) do
+ obj.foo
+ end
+
+ ScratchPad.recorded.should == (lineno+1..lineno+3).to_a
+ end
+
+ describe 'option value' do
+ it 'accepts Method' do
+ trace = TracePoint.new(:call) do |tp|
+ next unless TracePointSpec.target_thread?
+ ScratchPad << tp.method_id
+ end
+
+ obj = Object.new
+ def obj.foo; end
+
+ trace.enable(target: obj.method(:foo)) do
+ obj.foo
+ end
+
+ ScratchPad.recorded.should == [:foo]
+ end
+
+ it 'accepts UnboundMethod' do
+ trace = TracePoint.new(:call) do |tp|
+ next unless TracePointSpec.target_thread?
+ ScratchPad << tp.method_id
+ end
+
+ klass = Class.new do
+ def foo; end
+ end
+
+ unbound_method = klass.instance_method(:foo)
+ trace.enable(target: unbound_method) do
+ klass.new.foo
+ end
+
+ ScratchPad.recorded.should == [:foo]
+ end
+
+ it 'accepts Proc' do
+ trace = TracePoint.new(:b_call) do |tp|
+ next unless TracePointSpec.target_thread?
+ ScratchPad << tp.lineno
+ end
+
+ block = proc {}
+ _, lineno = block.source_location
+
+ trace.enable(target: block) do
+ block.call
+ end
+
+ ScratchPad.recorded.should == [lineno]
+ lineno.should.is_a?(Integer)
+ end
+ end
+
+ it "raises ArgumentError if target object cannot trigger specified event" do
+ trace = TracePoint.new(:call) do |tp|
+ next unless TracePointSpec.target_thread?
+ ScratchPad << tp.method_id
+ end
+
+ block = proc {}
+
+ -> {
+ trace.enable(target: block) do
+ block.call # triggers :b_call and :b_return events
+ end
+ }.should.raise(ArgumentError, /can not enable any hooks/)
+ end
+
+ it "raises ArgumentError if passed not Method/UnboundMethod/Proc" do
+ trace = TracePoint.new(:call) {}
+
+ -> {
+ trace.enable(target: Object.new) do
+ end
+ }.should.raise(ArgumentError, /specified target is not supported/)
+ end
+
+ context "nested enabling and disabling" do
+ it "raises ArgumentError if trace point already enabled with target is re-enabled with target" do
+ trace = TracePoint.new(:b_call) {}
+
+ -> {
+ trace.enable(target: -> {}) do
+ trace.enable(target: -> {}) do
+ end
+ end
+ }.should.raise(ArgumentError, /can't nest-enable a targett?ing TracePoint/)
+ end
+
+ it "raises ArgumentError if trace point already enabled without target is re-enabled with target" do
+ trace = TracePoint.new(:b_call) {}
+
+ -> {
+ trace.enable do
+ trace.enable(target: -> {}) do
+ end
+ end
+ }.should.raise(ArgumentError, /can't nest-enable a targett?ing TracePoint/)
+ end
+
+ it "raises ArgumentError if trace point already enabled with target is re-enabled without target" do
+ trace = TracePoint.new(:b_call) {}
+
+ -> {
+ trace.enable(target: -> {}) do
+ trace.enable do
+ end
+ end
+ }.should.raise(ArgumentError, /can't nest-enable a targett?ing TracePoint/)
+ end
+
+ it "raises ArgumentError if trace point already enabled with target is disabled with block" do
+ trace = TracePoint.new(:b_call) {}
+
+ -> {
+ trace.enable(target: -> {}) do
+ trace.disable do
+ end
+ end
+ }.should.raise(ArgumentError, /can't disable a targett?ing TracePoint in a block/)
+ end
+
+ it "traces events when trace point with target is enabled in another trace point enabled without target" do
+ trace_outer = TracePoint.new(:b_call) do |tp|
+ next unless TracePointSpec.target_thread?
+ ScratchPad << :outer
+ end
+
+ trace_inner = TracePoint.new(:b_call) do |tp|
+ next unless TracePointSpec.target_thread?
+ ScratchPad << :inner
+ end
+
+ target = -> {}
+
+ trace_outer.enable do
+ trace_inner.enable(target: target) do
+ target.call
+ end
+ end
+
+ ScratchPad.recorded.should == [:outer, :outer, :outer, :inner]
+ end
+
+ it "traces events when trace point with target is enabled in another trace point enabled with target" do
+ trace_outer = TracePoint.new(:b_call) do |tp|
+ next unless TracePointSpec.target_thread?
+ ScratchPad << :outer
+ end
+
+ trace_inner = TracePoint.new(:b_call) do |tp|
+ next unless TracePointSpec.target_thread?
+ ScratchPad << :inner
+ end
+
+ target = -> {}
+
+ trace_outer.enable(target: target) do
+ trace_inner.enable(target: target) do
+ target.call
+ end
+ end
+
+ ScratchPad.recorded.should == [:inner, :outer]
+ end
+
+ it "traces events when trace point without target is enabled in another trace point enabled with target" do
+ trace_outer = TracePoint.new(:b_call) do |tp|
+ next unless TracePointSpec.target_thread?
+ ScratchPad << :outer
+ end
+
+ trace_inner = TracePoint.new(:b_call) do |tp|
+ next unless TracePointSpec.target_thread?
+ ScratchPad << :inner
+ end
+
+ target = -> {}
+
+ trace_outer.enable(target: target) do
+ trace_inner.enable do
+ target.call
+ end
+ end
+
+ ScratchPad.recorded.should == [:inner, :inner, :outer]
+ end
+ end
+ end
+
+ describe 'target_line: option' do
+ before :each do
+ ScratchPad.record []
+ end
+
+ it "traces :line events only on specified line of code" do
+ trace = TracePoint.new(:line) do |tp|
+ next unless TracePointSpec.target_thread?
+ ScratchPad << tp.lineno
+ end
+
+ target = -> {
+ x = 1
+ y = 2 # <= this line is target
+ z = x + y
+ }
+ _, lineno = target.source_location
+ target_line = lineno + 2
+
+ trace.enable(target_line: target_line, target: target) do
+ target.call
+ end
+
+ ScratchPad.recorded.should == [target_line]
+ end
+
+ it "raises ArgumentError if :target option isn't specified" do
+ trace = TracePoint.new(:line) {}
+
+ -> {
+ trace.enable(target_line: 67) do
+ end
+ }.should.raise(ArgumentError, /only target_line is specified/)
+ end
+
+ it "raises ArgumentError if :line event isn't registered" do
+ trace = TracePoint.new(:call) {}
+
+ target = -> {
+ x = 1
+ y = 2 # <= this line is target
+ z = x + y
+ }
+ _, lineno = target.source_location
+ target_line = lineno + 2
+
+ -> {
+ trace.enable(target_line: target_line, target: target) do
+ end
+ }.should.raise(ArgumentError, /target_line is specified, but line event is not specified/)
+ end
+
+ it "raises ArgumentError if :target_line value is out of target code lines range" do
+ trace = TracePoint.new(:line) {}
+
+ -> {
+ trace.enable(target_line: 1, target: -> { }) do
+ end
+ }.should.raise(ArgumentError, /can not enable any hooks/)
+ end
+
+ it "raises TypeError if :target_line value couldn't be coerced to Integer" do
+ trace = TracePoint.new(:line) {}
+
+ -> {
+ trace.enable(target_line: Object.new, target: -> { }) do
+ end
+ }.should.raise(TypeError, /no implicit conversion of \w+? into Integer/)
+ end
+
+ it "raises ArgumentError if :target_line value is negative" do
+ trace = TracePoint.new(:line) {}
+
+ -> {
+ trace.enable(target_line: -2, target: -> { }) do
+ end
+ }.should.raise(ArgumentError, /can not enable any hooks/)
+ end
+
+ it "accepts value that could be coerced to Integer" do
+ trace = TracePoint.new(:line) do |tp|
+ next unless TracePointSpec.target_thread?
+ ScratchPad << tp.lineno
+ end
+
+ target = -> {
+ x = 1 # <= this line is target
+ }
+ _, lineno = target.source_location
+ target_line = lineno + 1
+
+ trace.enable(target_line: target_line.to_r, target: target) do
+ target.call
+ end
+
+ ScratchPad.recorded.should == [target_line]
+ end
+ end
+end
diff --git a/spec/ruby/core/tracepoint/enabled_spec.rb b/spec/ruby/core/tracepoint/enabled_spec.rb
new file mode 100644
index 0000000000..0e9566a02c
--- /dev/null
+++ b/spec/ruby/core/tracepoint/enabled_spec.rb
@@ -0,0 +1,15 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe 'TracePoint#enabled?' do
+ it 'returns true when current status of the trace is enable' do
+ trace = TracePoint.new(:line) {}
+ trace.enable do
+ trace.should.enabled?
+ end
+ end
+
+ it 'returns false when current status of the trace is disabled' do
+ TracePoint.new(:line) {}.should_not.enabled?
+ end
+end
diff --git a/spec/ruby/core/tracepoint/eval_script_spec.rb b/spec/ruby/core/tracepoint/eval_script_spec.rb
new file mode 100644
index 0000000000..7ec53e7094
--- /dev/null
+++ b/spec/ruby/core/tracepoint/eval_script_spec.rb
@@ -0,0 +1,23 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe "TracePoint#eval_script" do
+ it "is the evald source code" do
+ ScratchPad.record []
+
+ script = <<-CODE
+ def foo
+ p :hello
+ end
+ CODE
+
+ TracePoint.new(:script_compiled) do |e|
+ next unless TracePointSpec.target_thread?
+ ScratchPad << e.eval_script
+ end.enable do
+ eval script
+ end
+
+ ScratchPad.recorded.should == [script]
+ end
+end
diff --git a/spec/ruby/core/tracepoint/event_spec.rb b/spec/ruby/core/tracepoint/event_spec.rb
new file mode 100644
index 0000000000..58017dc98d
--- /dev/null
+++ b/spec/ruby/core/tracepoint/event_spec.rb
@@ -0,0 +1,22 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe 'TracePoint#event' do
+ it 'returns the type of event' do
+ event_name = nil
+ TracePoint.new(:end, :call) do |tp|
+ next unless TracePointSpec.target_thread?
+ event_name = tp.event
+ end.enable do
+ TracePointSpec.test
+ event_name.should.equal?(:call)
+
+ TracePointSpec::B.new.foo
+ event_name.should.equal?(:call)
+
+ class TracePointSpec::B; end
+ event_name.should.equal?(:end)
+ end
+
+ end
+end
diff --git a/spec/ruby/core/tracepoint/fixtures/classes.rb b/spec/ruby/core/tracepoint/fixtures/classes.rb
index fd22ac319d..3ab1b00b16 100644
--- a/spec/ruby/core/tracepoint/fixtures/classes.rb
+++ b/spec/ruby/core/tracepoint/fixtures/classes.rb
@@ -1,8 +1,40 @@
module TracePointSpec
+ @thread = Thread.current
+
+ def self.target_thread?
+ Thread.current == @thread
+ end
+
class ClassWithMethodAlias
def m
end
alias_method :m_alias, :m
end
-end
+ module A
+ def bar; end
+ end
+
+ class B
+ include A
+
+ def foo; end;
+ end
+
+ class C < B
+ def initialize
+ end
+
+ def foo
+ super
+ end
+
+ def bar
+ super
+ end
+ end
+
+ def self.test
+ 'test'
+ end
+end
diff --git a/spec/ruby/core/tracepoint/inspect_spec.rb b/spec/ruby/core/tracepoint/inspect_spec.rb
new file mode 100644
index 0000000000..6cc2ebe243
--- /dev/null
+++ b/spec/ruby/core/tracepoint/inspect_spec.rb
@@ -0,0 +1,141 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe 'TracePoint#inspect' do
+ before do
+ @path_prefix = ' '
+ end
+
+ it 'returns a string containing a human-readable TracePoint status' do
+ TracePoint.new(:line) {}.inspect.should == '#<TracePoint:disabled>'
+ end
+
+ it "shows only whether it's enabled when outside the TracePoint handler" do
+ trace = TracePoint.new(:line) {}
+ trace.enable
+
+ trace.inspect.should == '#<TracePoint:enabled>'
+
+ trace.disable
+ end
+
+ it 'returns a String showing the event, path and line' do
+ inspect = nil
+ line = nil
+ TracePoint.new(:line) { |tp|
+ next unless TracePointSpec.target_thread?
+ next unless tp.path == __FILE__
+
+ inspect ||= tp.inspect
+ }.enable do
+ line = __LINE__
+ end
+
+ inspect.should == "#<TracePoint:line#{@path_prefix}#{__FILE__}:#{line}>"
+ end
+
+ it 'returns a String showing the event, method, path and line for a :call event' do
+ inspect = nil
+ line = nil
+ TracePoint.new(:call) { |tp|
+ next unless TracePointSpec.target_thread?
+ next unless tp.path == __FILE__
+
+ inspect ||= tp.inspect
+ }.enable do
+ line = __LINE__ + 1
+ def trace_point_spec_test_call; end
+ trace_point_spec_test_call
+ end
+
+ inspect.should =~ /\A#<TracePoint:call [`']trace_point_spec_test_call'#{@path_prefix}#{__FILE__}:#{line}>\z/
+ end
+
+ it 'returns a String showing the event, method, path and line for a :return event' do
+ inspect = nil
+ line = nil
+ TracePoint.new(:return) { |tp|
+ next unless TracePointSpec.target_thread?
+ next unless tp.path == __FILE__
+
+ inspect ||= tp.inspect
+ }.enable do
+ line = __LINE__ + 4
+ def trace_point_spec_test_return
+ a = 1
+ return a
+ end
+ trace_point_spec_test_return
+ end
+ ruby_version_is("3.4") { line -= 1 }
+
+ inspect.should =~ /\A#<TracePoint:return [`']trace_point_spec_test_return'#{@path_prefix}#{__FILE__}:#{line}>\z/
+ end
+
+ it 'returns a String showing the event, method, path and line for a :c_call event' do
+ inspect = nil
+ tracepoint = TracePoint.new(:c_call) { |tp|
+ next unless TracePointSpec.target_thread?
+ next unless tp.path == __FILE__
+
+ inspect ||= tp.inspect
+ }
+ line = __LINE__ + 2
+ tracepoint.enable do
+ [0, 1].max
+ end
+
+ inspect.should =~ /\A#<TracePoint:c_call [`']max'#{@path_prefix}#{__FILE__}:#{line}>\z/
+ end
+
+ it 'returns a String showing the event, path and line for a :class event' do
+ inspect = nil
+ line = nil
+ TracePoint.new(:class) { |tp|
+ next unless TracePointSpec.target_thread?
+ next unless tp.path == __FILE__
+
+ inspect ||= tp.inspect
+ }.enable do
+ line = __LINE__ + 1
+ class TracePointSpec::C
+ end
+ end
+
+ inspect.should == "#<TracePoint:class#{@path_prefix}#{__FILE__}:#{line}>"
+ end
+
+ it 'returns a String showing the event and thread for :thread_begin event' do
+ inspect = nil
+ thread = nil
+ thread_inspection = nil
+ TracePoint.new(:thread_begin) { |tp|
+ next unless Thread.current == thread
+
+ inspect ||= tp.inspect
+ }.enable(target_thread: nil) do
+ thread = Thread.new {}
+ thread_inspection = thread.inspect
+ thread.join
+ end
+
+ inspect.should == "#<TracePoint:thread_begin #{thread_inspection}>"
+ end
+
+ it 'returns a String showing the event and thread for :thread_end event' do
+ inspect = nil
+ thread = nil
+ thread_inspection = nil
+ TracePoint.new(:thread_end) { |tp|
+ next unless Thread.current == thread
+
+ inspect ||= tp.inspect
+ }.enable(target_thread: nil) do
+ thread = Thread.new {}
+ thread_inspection = thread.inspect
+ thread.join
+ end
+
+ inspect.should == "#<TracePoint:thread_end #{thread_inspection}>"
+ end
+end
diff --git a/spec/ruby/core/tracepoint/lineno_spec.rb b/spec/ruby/core/tracepoint/lineno_spec.rb
new file mode 100644
index 0000000000..7c46d5222b
--- /dev/null
+++ b/spec/ruby/core/tracepoint/lineno_spec.rb
@@ -0,0 +1,20 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe 'TracePoint#lineno' do
+ it 'returns the line number of the event' do
+ lineno = nil
+ TracePoint.new(:line) { |tp|
+ next unless TracePointSpec.target_thread?
+ lineno = tp.lineno
+ }.enable do
+ line_event = true
+ end
+ lineno.should == __LINE__ - 2
+ end
+
+ it 'raises RuntimeError if accessed from outside' do
+ tp = TracePoint.new(:line) {}
+ -> { tp.lineno }.should.raise(RuntimeError, 'access from outside')
+ end
+end
diff --git a/spec/ruby/core/tracepoint/method_id_spec.rb b/spec/ruby/core/tracepoint/method_id_spec.rb
new file mode 100644
index 0000000000..67740f2d7d
--- /dev/null
+++ b/spec/ruby/core/tracepoint/method_id_spec.rb
@@ -0,0 +1,15 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe 'TracePoint#method_id' do
+ it 'returns the name at the definition of the method being called' do
+ method_name = nil
+ TracePoint.new(:call) { |tp|
+ next unless TracePointSpec.target_thread?
+ method_name = tp.method_id
+ }.enable do
+ TracePointSpec.test
+ method_name.should.equal?(:test)
+ end
+ end
+end
diff --git a/spec/ruby/core/tracepoint/new_spec.rb b/spec/ruby/core/tracepoint/new_spec.rb
new file mode 100644
index 0000000000..763b35292b
--- /dev/null
+++ b/spec/ruby/core/tracepoint/new_spec.rb
@@ -0,0 +1,72 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe 'TracePoint.new' do
+ it 'returns a new TracePoint object, not enabled by default' do
+ TracePoint.new(:line) {}.enabled?.should == false
+ end
+
+ it 'includes :line event when event is not specified' do
+ event_name = nil
+ TracePoint.new { |tp|
+ next unless TracePointSpec.target_thread?
+ event_name = tp.event
+ }.enable do
+ event_name.should.equal?(:line)
+
+ event_name = nil
+ TracePointSpec.test
+ event_name.should.equal?(:line)
+
+ event_name = nil
+ TracePointSpec::B.new.foo
+ event_name.should.equal?(:line)
+ end
+ end
+
+ it 'converts given event name as string into symbol using to_sym' do
+ event_name = nil
+ (o = mock('line')).should_receive(:to_sym).and_return(:line)
+
+ TracePoint.new(o) { |tp|
+ next unless TracePointSpec.target_thread?
+ event_name = tp.event
+ }.enable do
+ line_event = true
+ event_name.should == :line
+ end
+ end
+
+ it 'includes multiple events when multiple event names are passed as params' do
+ event_name = nil
+ TracePoint.new(:end, :call) do |tp|
+ next unless TracePointSpec.target_thread?
+ event_name = tp.event
+ end.enable do
+ TracePointSpec.test
+ event_name.should.equal?(:call)
+
+ TracePointSpec::B.new.foo
+ event_name.should.equal?(:call)
+
+ class TracePointSpec::B; end
+ event_name.should.equal?(:end)
+ end
+ end
+
+ it 'raises a TypeError when the given object is not a string/symbol' do
+ o = mock('123')
+ -> { TracePoint.new(o) {} }.should.raise(TypeError)
+
+ o.should_receive(:to_sym).and_return(123)
+ -> { TracePoint.new(o) {} }.should.raise(TypeError)
+ end
+
+ it 'expects to be called with a block' do
+ -> { TracePoint.new(:line) }.should.raise(ArgumentError, "must be called with a block")
+ end
+
+ it "raises a Argument error when the given argument doesn't match an event name" do
+ -> { TracePoint.new(:test) }.should.raise(ArgumentError, "unknown event: test")
+ end
+end
diff --git a/spec/ruby/core/tracepoint/parameters_spec.rb b/spec/ruby/core/tracepoint/parameters_spec.rb
new file mode 100644
index 0000000000..82aee3caa4
--- /dev/null
+++ b/spec/ruby/core/tracepoint/parameters_spec.rb
@@ -0,0 +1,28 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe 'TracePoint#parameters' do
+ it 'returns the parameters of block' do
+ f = proc {|x, y, z| }
+ parameters = nil
+ TracePoint.new(:b_call) { |tp|
+ next unless TracePointSpec.target_thread?
+ parameters = tp.parameters
+ }.enable do
+ f.call
+ parameters.should == [[:opt, :x], [:opt, :y], [:opt, :z]]
+ end
+ end
+
+ it 'returns the parameters of lambda block' do
+ f = -> x, y, z { }
+ parameters = nil
+ TracePoint.new(:b_call) { |tp|
+ next unless TracePointSpec.target_thread?
+ parameters = tp.parameters
+ }.enable do
+ f.call(1, 2, 3)
+ parameters.should == [[:req, :x], [:req, :y], [:req, :z]]
+ end
+ end
+end
diff --git a/spec/ruby/core/tracepoint/path_spec.rb b/spec/ruby/core/tracepoint/path_spec.rb
new file mode 100644
index 0000000000..aa6868ead2
--- /dev/null
+++ b/spec/ruby/core/tracepoint/path_spec.rb
@@ -0,0 +1,26 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe 'TracePoint#path' do
+ it 'returns the path of the file being run' do
+ path = nil
+ TracePoint.new(:line) { |tp|
+ next unless TracePointSpec.target_thread?
+ path = tp.path
+ }.enable do
+ line_event = true
+ end
+ path.should == "#{__FILE__}"
+ end
+
+ it 'equals "(eval at __FILE__:__LINE__)" inside an eval for :end event' do
+ path = nil
+ TracePoint.new(:end) { |tp|
+ next unless TracePointSpec.target_thread?
+ path = tp.path
+ }.enable do
+ eval("module TracePointSpec; end")
+ end
+ path.should == "(eval at #{__FILE__}:#{__LINE__ - 2})"
+ end
+end
diff --git a/spec/ruby/core/tracepoint/raised_exception_spec.rb b/spec/ruby/core/tracepoint/raised_exception_spec.rb
new file mode 100644
index 0000000000..b1199902f2
--- /dev/null
+++ b/spec/ruby/core/tracepoint/raised_exception_spec.rb
@@ -0,0 +1,36 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe 'TracePoint#raised_exception' do
+ it 'returns value from exception raised on the :raise event' do
+ raised_exception, error_result = nil
+ trace = TracePoint.new(:raise) { |tp|
+ next unless TracePointSpec.target_thread?
+ raised_exception = tp.raised_exception
+ }
+ trace.enable do
+ begin
+ raise StandardError
+ rescue => e
+ error_result = e
+ end
+ raised_exception.should.equal?(error_result)
+ end
+ end
+
+ it 'returns value from exception rescued on the :rescue event' do
+ raised_exception, error_result = nil
+ trace = TracePoint.new(:rescue) { |tp|
+ next unless TracePointSpec.target_thread?
+ raised_exception = tp.raised_exception
+ }
+ trace.enable do
+ begin
+ raise StandardError
+ rescue => e
+ error_result = e
+ end
+ raised_exception.should.equal?(error_result)
+ end
+ end
+end
diff --git a/spec/ruby/core/tracepoint/return_value_spec.rb b/spec/ruby/core/tracepoint/return_value_spec.rb
new file mode 100644
index 0000000000..e84c7dd762
--- /dev/null
+++ b/spec/ruby/core/tracepoint/return_value_spec.rb
@@ -0,0 +1,17 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe 'TracePoint#return_value' do
+ def test; 'test' end
+
+ it 'returns value from :return event' do
+ trace_value = nil
+ TracePoint.new(:return) { |tp|
+ next unless TracePointSpec.target_thread?
+ trace_value = tp.return_value
+ }.enable do
+ test
+ trace_value.should == 'test'
+ end
+ end
+end
diff --git a/spec/ruby/core/tracepoint/self_spec.rb b/spec/ruby/core/tracepoint/self_spec.rb
new file mode 100644
index 0000000000..bf9a2b6a45
--- /dev/null
+++ b/spec/ruby/core/tracepoint/self_spec.rb
@@ -0,0 +1,26 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe 'TracePoint#self' do
+ it 'return the trace object from event' do
+ trace = nil
+ TracePoint.new(:line) { |tp|
+ next unless TracePointSpec.target_thread?
+ trace = tp.self
+ }.enable do
+ trace.equal?(self).should == true
+ end
+ end
+
+ it 'return the class object from a class event' do
+ trace = nil
+ TracePoint.new(:class) { |tp|
+ next unless TracePointSpec.target_thread?
+ trace = tp.self
+ }.enable do
+ class TracePointSpec::C
+ end
+ end
+ trace.should.equal? TracePointSpec::C
+ end
+end
diff --git a/spec/ruby/core/tracepoint/trace_spec.rb b/spec/ruby/core/tracepoint/trace_spec.rb
new file mode 100644
index 0000000000..167f594bb9
--- /dev/null
+++ b/spec/ruby/core/tracepoint/trace_spec.rb
@@ -0,0 +1,10 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe 'TracePoint.trace' do
+ it 'activates the trace automatically' do
+ trace = TracePoint.trace(:line) {}
+ trace.should.enabled?
+ trace.disable
+ end
+end
diff --git a/spec/ruby/core/true/and_spec.rb b/spec/ruby/core/true/and_spec.rb
index b81b6b36b6..99e69d3ae0 100644
--- a/spec/ruby/core/true/and_spec.rb
+++ b/spec/ruby/core/true/and_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "TrueClass#&" do
it "returns false if other is nil or false, otherwise true" do
diff --git a/spec/ruby/core/true/case_compare_spec.rb b/spec/ruby/core/true/case_compare_spec.rb
new file mode 100644
index 0000000000..dee6dd0227
--- /dev/null
+++ b/spec/ruby/core/true/case_compare_spec.rb
@@ -0,0 +1,13 @@
+require_relative '../../spec_helper'
+
+describe "TrueClass#===" do
+ it "returns true for true" do
+ (true === true).should == true
+ end
+
+ it "returns false for non-true object" do
+ (true === 1).should == false
+ (true === "").should == false
+ (true === Object).should == false
+ end
+end
diff --git a/spec/ruby/core/true/dup_spec.rb b/spec/ruby/core/true/dup_spec.rb
index cdf60e5bd6..2628f6d374 100644
--- a/spec/ruby/core/true/dup_spec.rb
+++ b/spec/ruby/core/true/dup_spec.rb
@@ -1,9 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
-ruby_version_is '2.4' do
- describe "TrueClass#dup" do
- it "returns self" do
- true.dup.should equal(true)
- end
+describe "TrueClass#dup" do
+ it "returns self" do
+ true.dup.should.equal?(true)
end
end
diff --git a/spec/ruby/core/true/inspect_spec.rb b/spec/ruby/core/true/inspect_spec.rb
index baf26123c8..b9f5390b5c 100644
--- a/spec/ruby/core/true/inspect_spec.rb
+++ b/spec/ruby/core/true/inspect_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "TrueClass#inspect" do
- it "returns the string 'true'" do
- true.inspect.should == "true"
+ it "is an alias of TrueClass#to_s" do
+ true.method(:inspect).should == true.method(:to_s)
end
end
diff --git a/spec/ruby/core/true/or_spec.rb b/spec/ruby/core/true/or_spec.rb
index a104551ae8..9bf76a62b8 100644
--- a/spec/ruby/core/true/or_spec.rb
+++ b/spec/ruby/core/true/or_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "TrueClass#|" do
it "returns true" do
diff --git a/spec/ruby/core/true/singleton_method_spec.rb b/spec/ruby/core/true/singleton_method_spec.rb
new file mode 100644
index 0000000000..58689fb6e5
--- /dev/null
+++ b/spec/ruby/core/true/singleton_method_spec.rb
@@ -0,0 +1,13 @@
+require_relative '../../spec_helper'
+
+describe "TrueClass#singleton_method" do
+ it "raises regardless of whether TrueClass defines the method" do
+ -> { true.singleton_method(:foo) }.should.raise(NameError)
+ begin
+ def (true).foo; end
+ -> { true.singleton_method(:foo) }.should.raise(NameError)
+ ensure
+ TrueClass.send(:remove_method, :foo)
+ end
+ end
+end
diff --git a/spec/ruby/core/true/to_s_spec.rb b/spec/ruby/core/true/to_s_spec.rb
index 0e2a807a95..2c6f3889e9 100644
--- a/spec/ruby/core/true/to_s_spec.rb
+++ b/spec/ruby/core/true/to_s_spec.rb
@@ -1,7 +1,15 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "TrueClass#to_s" do
it "returns the string 'true'" do
true.to_s.should == "true"
end
+
+ it "returns a frozen string" do
+ true.to_s.should.frozen?
+ end
+
+ it "always returns the same string" do
+ true.to_s.should.equal?(true.to_s)
+ end
end
diff --git a/spec/ruby/core/true/trueclass_spec.rb b/spec/ruby/core/true/trueclass_spec.rb
index 8837117d71..1c1a0ddbe2 100644
--- a/spec/ruby/core/true/trueclass_spec.rb
+++ b/spec/ruby/core/true/trueclass_spec.rb
@@ -1,15 +1,15 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "TrueClass" do
it ".allocate raises a TypeError" do
- lambda do
+ -> do
TrueClass.allocate
- end.should raise_error(TypeError)
+ end.should.raise(TypeError)
end
it ".new is undefined" do
- lambda do
+ -> do
TrueClass.new
- end.should raise_error(NoMethodError)
+ end.should.raise(NoMethodError)
end
end
diff --git a/spec/ruby/core/true/xor_spec.rb b/spec/ruby/core/true/xor_spec.rb
index 1d0ad394da..8f5ecd5075 100644
--- a/spec/ruby/core/true/xor_spec.rb
+++ b/spec/ruby/core/true/xor_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "TrueClass#^" do
it "returns true if other is nil or false, otherwise false" do
diff --git a/spec/ruby/core/unboundmethod/arity_spec.rb b/spec/ruby/core/unboundmethod/arity_spec.rb
index a804235b70..cd700b9f9b 100644
--- a/spec/ruby/core/unboundmethod/arity_spec.rb
+++ b/spec/ruby/core/unboundmethod/arity_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "UnboundMethod#arity" do
SpecEvaluate.desc = "for method definition"
diff --git a/spec/ruby/core/unboundmethod/bind_call_spec.rb b/spec/ruby/core/unboundmethod/bind_call_spec.rb
new file mode 100644
index 0000000000..ee1dad9c9e
--- /dev/null
+++ b/spec/ruby/core/unboundmethod/bind_call_spec.rb
@@ -0,0 +1,58 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe "UnboundMethod#bind_call" do
+ before :each do
+ @normal_um = UnboundMethodSpecs::Methods.new.method(:foo).unbind
+ @parent_um = UnboundMethodSpecs::Parent.new.method(:foo).unbind
+ @child1_um = UnboundMethodSpecs::Child1.new.method(:foo).unbind
+ @child2_um = UnboundMethodSpecs::Child2.new.method(:foo).unbind
+ @normal_um_super = UnboundMethodSpecs::Mod.instance_method(:foo_super)
+ @parent_um_super = UnboundMethodSpecs::Parent.new.method(:foo_super).unbind
+ end
+
+ it "raises TypeError if object is not kind_of? the Module the method defined in" do
+ -> { @normal_um.bind_call(UnboundMethodSpecs::B.new) }.should.raise(TypeError)
+ end
+
+ it "binds and calls the method if object is kind_of the Module the method defined in" do
+ @normal_um.bind_call(UnboundMethodSpecs::Methods.new).should == true
+ end
+
+ it "binds and calls the method on any object when UnboundMethod is unbound from a module" do
+ UnboundMethodSpecs::Mod.instance_method(:from_mod).bind_call(Object.new).should == nil
+ end
+
+ it "binds and calls the method for any object kind_of? the Module the method is defined in" do
+ @parent_um.bind_call(UnboundMethodSpecs::Child1.new).should == nil
+ @child1_um.bind_call(UnboundMethodSpecs::Parent.new).should == nil
+ @child2_um.bind_call(UnboundMethodSpecs::Child1.new).should == nil
+ end
+
+ it "binds and calls a Kernel method retrieved from Object on BasicObject" do
+ Object.instance_method(:instance_of?).bind_call(BasicObject.new, BasicObject).should == true
+ end
+
+ it "binds and calls a Parent's class method to any Child's class methods" do
+ um = UnboundMethodSpecs::Parent.method(:class_method).unbind
+ um.bind_call(UnboundMethodSpecs::Child1).should == "I am UnboundMethodSpecs::Child1"
+ end
+
+ it "will raise when binding a an object singleton's method to another object" do
+ other = UnboundMethodSpecs::Parent.new
+ p = UnboundMethodSpecs::Parent.new
+ class << p
+ def singleton_method
+ :single
+ end
+ end
+ um = p.method(:singleton_method).unbind
+ ->{ um.bind_call(other) }.should.raise(TypeError)
+ end
+
+ it "allows calling super for module methods bound to hierarchies that do not already have that module" do
+ p = UnboundMethodSpecs::Parent.new
+
+ @normal_um_super.bind_call(p).should == true
+ end
+end
diff --git a/spec/ruby/core/unboundmethod/bind_spec.rb b/spec/ruby/core/unboundmethod/bind_spec.rb
index 3f7a7bf3ac..087994ff57 100644
--- a/spec/ruby/core/unboundmethod/bind_spec.rb
+++ b/spec/ruby/core/unboundmethod/bind_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "UnboundMethod#bind" do
before :each do
@@ -7,25 +7,37 @@ describe "UnboundMethod#bind" do
@parent_um = UnboundMethodSpecs::Parent.new.method(:foo).unbind
@child1_um = UnboundMethodSpecs::Child1.new.method(:foo).unbind
@child2_um = UnboundMethodSpecs::Child2.new.method(:foo).unbind
+ @normal_um_super = UnboundMethodSpecs::Mod.instance_method(:foo_super)
+ @parent_um_super = UnboundMethodSpecs::Parent.new.method(:foo_super).unbind
end
it "raises TypeError if object is not kind_of? the Module the method defined in" do
- lambda { @normal_um.bind(UnboundMethodSpecs::B.new) }.should raise_error(TypeError)
+ -> { @normal_um.bind(UnboundMethodSpecs::B.new) }.should.raise(TypeError)
end
it "returns Method for any object that is kind_of? the Module method was extracted from" do
- @normal_um.bind(UnboundMethodSpecs::Methods.new).should be_kind_of(Method)
+ @normal_um.bind(UnboundMethodSpecs::Methods.new).should.is_a?(Method)
end
it "returns Method on any object when UnboundMethod is unbound from a module" do
- UnboundMethodSpecs::Mod.instance_method(:from_mod).bind(Object.new).should be_kind_of(Method)
+ UnboundMethodSpecs::Mod.instance_method(:from_mod).bind(Object.new).should.is_a?(Method)
end
- it "returns Method returned for obj is equal to one directly returned by obj.method" do
+ it "the returned Method is equal to the one directly returned by obj.method" do
obj = UnboundMethodSpecs::Methods.new
@normal_um.bind(obj).should == obj.method(:foo)
end
+ it "returns Method for any object kind_of? the Module the method is defined in" do
+ @parent_um.bind(UnboundMethodSpecs::Child1.new).should.is_a?(Method)
+ @child1_um.bind(UnboundMethodSpecs::Parent.new).should.is_a?(Method)
+ @child2_um.bind(UnboundMethodSpecs::Child1.new).should.is_a?(Method)
+ end
+
+ it "allows binding a Kernel method retrieved from Object on BasicObject" do
+ Object.instance_method(:instance_of?).bind(BasicObject.new).call(BasicObject).should == true
+ end
+
it "returns a callable method" do
obj = UnboundMethodSpecs::Methods.new
@normal_um.bind(obj).call.should == obj.foo
@@ -33,7 +45,7 @@ describe "UnboundMethod#bind" do
it "binds a Parent's class method to any Child's class methods" do
m = UnboundMethodSpecs::Parent.method(:class_method).unbind.bind(UnboundMethodSpecs::Child1)
- m.should be_an_instance_of(Method)
+ m.should.instance_of?(Method)
m.call.should == "I am UnboundMethodSpecs::Child1"
end
@@ -46,6 +58,12 @@ describe "UnboundMethod#bind" do
end
end
um = p.method(:singleton_method).unbind
- lambda{ um.bind(other) }.should raise_error(TypeError)
+ ->{ um.bind(other) }.should.raise(TypeError)
+ end
+
+ it "allows calling super for module methods bound to hierarchies that do not already have that module" do
+ p = UnboundMethodSpecs::Parent.new
+
+ @normal_um_super.bind(p).call.should == true
end
end
diff --git a/spec/ruby/core/unboundmethod/clone_spec.rb b/spec/ruby/core/unboundmethod/clone_spec.rb
index 2f3fd834ad..1e7fb18744 100644
--- a/spec/ruby/core/unboundmethod/clone_spec.rb
+++ b/spec/ruby/core/unboundmethod/clone_spec.rb
@@ -1,12 +1,13 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/dup'
describe "UnboundMethod#clone" do
- it "returns a copy of the UnboundMethod" do
- um1 = UnboundMethodSpecs::Methods.instance_method(:foo)
- um2 = um1.clone
+ it_behaves_like :unboundmethod_dup, :clone
- (um1 == um2).should == true
- um1.bind(UnboundMethodSpecs::Methods.new).call.should == um2.bind(UnboundMethodSpecs::Methods.new).call
+ it "preserves frozen status" do
+ method = Class.instance_method(:instance_method)
+ method.freeze
+ method.frozen?.should == true
+ method.clone.frozen?.should == true
end
end
diff --git a/spec/ruby/core/unboundmethod/dup_spec.rb b/spec/ruby/core/unboundmethod/dup_spec.rb
new file mode 100644
index 0000000000..5a78dd8e36
--- /dev/null
+++ b/spec/ruby/core/unboundmethod/dup_spec.rb
@@ -0,0 +1,15 @@
+require_relative '../../spec_helper'
+require_relative 'shared/dup'
+
+describe "UnboundMethod#dup" do
+ ruby_version_is "3.4" do
+ it_behaves_like :unboundmethod_dup, :dup
+
+ it "resets frozen status" do
+ method = Class.instance_method(:instance_method)
+ method.freeze
+ method.frozen?.should == true
+ method.dup.frozen?.should == false
+ end
+ end
+end
diff --git a/spec/ruby/core/unboundmethod/eql_spec.rb b/spec/ruby/core/unboundmethod/eql_spec.rb
index 8e91ef375e..3b299d047a 100644
--- a/spec/ruby/core/unboundmethod/eql_spec.rb
+++ b/spec/ruby/core/unboundmethod/eql_spec.rb
@@ -1,5 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "UnboundMethod#eql?" do
- it "needs to be reviewed for spec completeness"
+ it "is an alias of UnboundMethod#==" do
+ UnboundMethod.instance_method(:eql?).should == UnboundMethod.instance_method(:==)
+ end
end
diff --git a/spec/ruby/core/unboundmethod/equal_value_spec.rb b/spec/ruby/core/unboundmethod/equal_value_spec.rb
index de141254c1..24d5233299 100644
--- a/spec/ruby/core/unboundmethod/equal_value_spec.rb
+++ b/spec/ruby/core/unboundmethod/equal_value_spec.rb
@@ -1,10 +1,10 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
context "Creating UnboundMethods" do
specify "there is no difference between Method#unbind and Module#instance_method" do
- UnboundMethodSpecs::Methods.instance_method(:foo).should be_kind_of(UnboundMethod)
- UnboundMethodSpecs::Methods.new.method(:foo).unbind.should be_kind_of(UnboundMethod)
+ UnboundMethodSpecs::Methods.instance_method(:foo).should.is_a?(UnboundMethod)
+ UnboundMethodSpecs::Methods.new.method(:foo).unbind.should.is_a?(UnboundMethod)
end
end
@@ -35,6 +35,12 @@ describe "UnboundMethod#==" do
@method_one = UnboundMethodSpecs::Methods.instance_method(:one)
@method_two = UnboundMethodSpecs::Methods.instance_method(:two)
+
+ @mixin = UnboundMethodSpecs::Mixin.instance_method(:mixin_method)
+ @includer_base = UnboundMethodSpecs::IncluderBase.new.method(:mixin_method).unbind
+ @includer_child = UnboundMethodSpecs::IncluderChild.new.method(:mixin_method).unbind
+ @extender_base = UnboundMethodSpecs::ExtenderBase.method(:mixin_method).unbind
+ @extender_child = UnboundMethodSpecs::ExtenderChild.method(:mixin_method).unbind
end
it "returns true if objects refer to the same method" do
@@ -76,19 +82,43 @@ describe "UnboundMethod#==" do
(@identical_body == @original_body).should == false
end
- it "returns false if same method but one extracted from a subclass" do
- (@parent == @child1).should == false
- (@child1 == @parent).should == false
+ it "returns true if same method but one extracted from a subclass" do
+ (@parent == @child1).should == true
+ (@child1 == @parent).should == true
end
- it "returns false if same method but extracted from two different subclasses" do
- (@child2 == @child1).should == false
- (@child1 == @child2).should == false
+ it "returns true if same method but extracted from two different subclasses" do
+ (@child2 == @child1).should == true
+ (@child1 == @child2).should == true
end
- it "returns false if methods are the same but added from an included Module" do
- (@includee == @includer).should == false
- (@includer == @includee).should == false
+ it "returns true if methods are the same but added from an included Module" do
+ (@includee == @includer).should == true
+ (@includer == @includee).should == true
+ end
+
+ ruby_bug "#21873", ""..."4.1" do
+ it "returns true if same method is present in an object through module inclusion" do
+ (@mixin == @includer_base).should == true
+ (@includer_base == @mixin).should == true
+
+ (@mixin == @includer_child).should == true
+ (@includer_child == @mixin).should == true
+
+ (@includer_base == @includer_child).should == true
+ (@includer_child == @includer_base).should == true
+ end
+
+ it "returns true if same method is present in an object through module extension" do
+ (@mixin == @extender_base).should == true
+ (@extender_base == @mixin).should == true
+
+ (@mixin == @extender_child).should == true
+ (@extender_child == @mixin).should == true
+
+ (@extender_base == @extender_child).should == true
+ (@extender_child == @extender_base).should == true
+ end
end
it "returns false if both have same Module, same name, identical body but not the same" do
@@ -98,4 +128,38 @@ describe "UnboundMethod#==" do
(@discard_1 == UnboundMethodSpecs::Methods.instance_method(:discard_1)).should == false
end
+
+ it "considers methods through aliasing equal" do
+ c = Class.new do
+ class << self
+ alias_method :n, :new
+ end
+ end
+
+ c.method(:new).should == c.method(:n)
+ c.method(:n).should == Class.instance_method(:new).bind(c)
+ end
+
+ it "considers methods through visibility change equal" do
+ c = Class.new do
+ class << self
+ private :new
+ end
+ end
+
+ c.method(:new).should == Class.instance_method(:new).bind(c)
+ end
+
+ it "considers methods through aliasing and visibility change equal" do
+ c = Class.new do
+ class << self
+ alias_method :n, :new
+ private :new
+ end
+ end
+
+ c.method(:new).should == c.method(:n)
+ c.method(:n).should == Class.instance_method(:new).bind(c)
+ c.method(:new).should == Class.instance_method(:new).bind(c)
+ end
end
diff --git a/spec/ruby/core/unboundmethod/fixtures/classes.rb b/spec/ruby/core/unboundmethod/fixtures/classes.rb
index 43e21916bf..58120c2f88 100644
--- a/spec/ruby/core/unboundmethod/fixtures/classes.rb
+++ b/spec/ruby/core/unboundmethod/fixtures/classes.rb
@@ -22,6 +22,7 @@ module UnboundMethodSpecs
module Mod
def from_mod; end
+ def foo_super; super; end
end
class Methods
@@ -34,6 +35,8 @@ module UnboundMethodSpecs
def with_block(&block); end
alias bar foo
+ alias baz bar
+ alias qux baz
alias alias_1 foo
alias alias_2 foo
@@ -52,10 +55,19 @@ module UnboundMethodSpecs
def discard_1(); :discard; end
def discard_2(); :discard; end
+
+ def my_public_method; end
+ def my_protected_method; end
+ def my_private_method; end
+ protected :my_protected_method
+ private :my_private_method
end
class Parent
def foo; end
+ def foo_super
+ true
+ end
def self.class_method
"I am #{name}"
end
@@ -69,6 +81,22 @@ module UnboundMethodSpecs
end
end
+ module Mixin
+ def mixin_method; end
+ end
+
+ class IncluderBase
+ include Mixin
+ end
+
+ class IncluderChild < IncluderBase; end
+
+ class ExtenderBase
+ extend Mixin
+ end
+
+ class ExtenderChild < ExtenderBase; end
+
class A
def baz(a, b)
return [__FILE__, self.class]
@@ -83,4 +111,14 @@ module UnboundMethodSpecs
class C < B
def overridden; end
end
+
+ module HashSpecs
+ class SuperClass
+ def foo
+ end
+ end
+
+ class SubClass < SuperClass
+ end
+ end
end
diff --git a/spec/ruby/core/unboundmethod/hash_spec.rb b/spec/ruby/core/unboundmethod/hash_spec.rb
index 6ba6c04834..6888675bc1 100644
--- a/spec/ruby/core/unboundmethod/hash_spec.rb
+++ b/spec/ruby/core/unboundmethod/hash_spec.rb
@@ -1,9 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "UnboundMethod#hash" do
- it "needs to be reviewed for spec completeness"
-
it "returns the same value for user methods that are eql?" do
foo, bar = UnboundMethodSpecs::Methods.instance_method(:foo), UnboundMethodSpecs::Methods.instance_method(:bar)
foo.hash.should == bar.hash
@@ -14,4 +12,11 @@ describe "UnboundMethod#hash" do
to_s, inspect = Array.instance_method(:to_s), Array.instance_method(:inspect)
to_s.hash.should == inspect.hash
end
+
+ it "equals a hash of the same method in the superclass" do
+ foo_in_superclass = UnboundMethodSpecs::HashSpecs::SuperClass.instance_method(:foo)
+ foo = UnboundMethodSpecs::HashSpecs::SubClass.instance_method(:foo)
+
+ foo.hash.should == foo_in_superclass.hash
+ end
end
diff --git a/spec/ruby/core/unboundmethod/inspect_spec.rb b/spec/ruby/core/unboundmethod/inspect_spec.rb
index ffef61a639..b0fcfd00ea 100644
--- a/spec/ruby/core/unboundmethod/inspect_spec.rb
+++ b/spec/ruby/core/unboundmethod/inspect_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/to_s', __FILE__)
+require_relative '../../spec_helper'
describe "UnboundMethod#inspect" do
- it_behaves_like(:unboundmethod_to_s, :inspect)
+ it "is an alias of UnboundMethod#to_s" do
+ UnboundMethod.instance_method(:inspect).should == UnboundMethod.instance_method(:to_s)
+ end
end
diff --git a/spec/ruby/core/unboundmethod/name_spec.rb b/spec/ruby/core/unboundmethod/name_spec.rb
index c4602d529a..4d0fb34fc8 100644
--- a/spec/ruby/core/unboundmethod/name_spec.rb
+++ b/spec/ruby/core/unboundmethod/name_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "UnboundMethod#name" do
it "returns the name of the method" do
diff --git a/spec/ruby/core/unboundmethod/original_name_spec.rb b/spec/ruby/core/unboundmethod/original_name_spec.rb
new file mode 100644
index 0000000000..cd5f55805d
--- /dev/null
+++ b/spec/ruby/core/unboundmethod/original_name_spec.rb
@@ -0,0 +1,59 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe "UnboundMethod#original_name" do
+ it "returns the name of the method" do
+ String.instance_method(:upcase).original_name.should == :upcase
+ end
+
+ it "returns the original name" do
+ obj = UnboundMethodSpecs::Methods.new
+ obj.method(:foo).unbind.original_name.should == :foo
+ obj.method(:bar).unbind.original_name.should == :foo
+ UnboundMethodSpecs::Methods.instance_method(:bar).original_name.should == :foo
+ end
+
+ it "returns the original name even when aliased twice" do
+ obj = UnboundMethodSpecs::Methods.new
+ obj.method(:foo).unbind.original_name.should == :foo
+ obj.method(:baz).unbind.original_name.should == :foo
+ UnboundMethodSpecs::Methods.instance_method(:baz).original_name.should == :foo
+ end
+
+ it "returns the original name even when aliased thrice" do
+ obj = UnboundMethodSpecs::Methods.new
+ obj.method(:qux).unbind.original_name.should == :foo
+ UnboundMethodSpecs::Methods.instance_method(:qux).original_name.should == :foo
+ end
+
+ it "returns the source UnboundMethod's name (not the name given to define_method)" do
+ klass = Class.new { define_method(:my_inspect, ::Kernel.instance_method(:inspect)) }
+ klass.instance_method(:my_inspect).original_name.should == :inspect
+ end
+
+ it "preserves the source method's name through define_method and alias" do
+ source = Class.new { def my_method; end }
+ klass = Class.new(source) do
+ define_method(:renamed, source.instance_method(:my_method))
+ alias aliased renamed
+ end
+ klass.instance_method(:renamed).original_name.should == :my_method
+ klass.instance_method(:aliased).original_name.should == :my_method
+ end
+
+ it "returns the source UnboundMethod's name for Kernel#is_a? and Kernel#kind_of?" do
+ klass = Class.new { define_method(:my_is_a?, ::Kernel.instance_method(:is_a?)) }
+ klass.instance_method(:my_is_a?).original_name.should == :is_a?
+
+ klass = Class.new { define_method(:my_kind_of?, ::Kernel.instance_method(:kind_of?)) }
+ klass.instance_method(:my_kind_of?).original_name.should == :kind_of?
+ end
+
+ it "preserves the source name when aliasing a define_method'd Kernel method" do
+ klass = Class.new do
+ define_method(:my_is_a?, ::Kernel.instance_method(:is_a?))
+ alias_method :renamed_is_a?, :my_is_a?
+ end
+ klass.instance_method(:renamed_is_a?).original_name.should == :is_a?
+ end
+end
diff --git a/spec/ruby/core/unboundmethod/owner_spec.rb b/spec/ruby/core/unboundmethod/owner_spec.rb
index 165b175147..b099c56de1 100644
--- a/spec/ruby/core/unboundmethod/owner_spec.rb
+++ b/spec/ruby/core/unboundmethod/owner_spec.rb
@@ -1,5 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative '../method/fixtures/classes'
describe "UnboundMethod#owner" do
it "returns the owner of the method" do
@@ -23,4 +24,8 @@ describe "UnboundMethod#owner" do
child_singleton_class.instance_method(:class_method).owner.should == parent_singleton_class
child_singleton_class.instance_method(:another_class_method).owner.should == child_singleton_class
end
+
+ it "returns the class on which public was called for a private method in ancestor" do
+ MethodSpecs::InheritedMethods::C.instance_method(:derp).owner.should == MethodSpecs::InheritedMethods::C
+ end
end
diff --git a/spec/ruby/core/unboundmethod/parameters_spec.rb b/spec/ruby/core/unboundmethod/parameters_spec.rb
index a48c967ea5..2a3cb18196 100644
--- a/spec/ruby/core/unboundmethod/parameters_spec.rb
+++ b/spec/ruby/core/unboundmethod/parameters_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "UnboundMethod#parameters" do
it "needs to be reviewed for spec completeness"
diff --git a/spec/ruby/core/unboundmethod/private_spec.rb b/spec/ruby/core/unboundmethod/private_spec.rb
new file mode 100644
index 0000000000..5a563939d1
--- /dev/null
+++ b/spec/ruby/core/unboundmethod/private_spec.rb
@@ -0,0 +1,9 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe "UnboundMethod#private?" do
+ it "has been removed" do
+ obj = UnboundMethodSpecs::Methods.new
+ obj.method(:my_private_method).unbind.should_not.respond_to?(:private?)
+ end
+end
diff --git a/spec/ruby/core/unboundmethod/protected_spec.rb b/spec/ruby/core/unboundmethod/protected_spec.rb
new file mode 100644
index 0000000000..70622d658d
--- /dev/null
+++ b/spec/ruby/core/unboundmethod/protected_spec.rb
@@ -0,0 +1,9 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe "UnboundMethod#protected?" do
+ it "has been removed" do
+ obj = UnboundMethodSpecs::Methods.new
+ obj.method(:my_protected_method).unbind.should_not.respond_to?(:protected?)
+ end
+end
diff --git a/spec/ruby/core/unboundmethod/public_spec.rb b/spec/ruby/core/unboundmethod/public_spec.rb
new file mode 100644
index 0000000000..ae75e2601c
--- /dev/null
+++ b/spec/ruby/core/unboundmethod/public_spec.rb
@@ -0,0 +1,9 @@
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+describe "UnboundMethod#public?" do
+ it "has been removed" do
+ obj = UnboundMethodSpecs::Methods.new
+ obj.method(:my_public_method).unbind.should_not.respond_to?(:public?)
+ end
+end
diff --git a/spec/ruby/core/unboundmethod/shared/dup.rb b/spec/ruby/core/unboundmethod/shared/dup.rb
new file mode 100644
index 0000000000..fd30f75c5b
--- /dev/null
+++ b/spec/ruby/core/unboundmethod/shared/dup.rb
@@ -0,0 +1,32 @@
+describe :unboundmethod_dup, shared: true do
+ it "returns a copy of self" do
+ a = Class.instance_method(:instance_method)
+ b = a.send(@method)
+
+ a.should == b
+ a.should_not.equal?(b)
+ end
+
+ ruby_version_is "3.4" do
+ it "copies instance variables" do
+ method = Class.instance_method(:instance_method)
+ method.instance_variable_set(:@ivar, 1)
+ cl = method.send(@method)
+ cl.instance_variables.should == [:@ivar]
+ end
+
+ it "copies the finalizer" do
+ code = <<-'RUBY'
+ obj = Class.instance_method(:instance_method)
+
+ ObjectSpace.define_finalizer(obj, Proc.new { STDOUT.write "finalized\n" })
+
+ obj.clone
+
+ exit 0
+ RUBY
+
+ ruby_exe(code).lines.sort.should == ["finalized\n", "finalized\n"]
+ end
+ end
+end
diff --git a/spec/ruby/core/unboundmethod/shared/to_s.rb b/spec/ruby/core/unboundmethod/shared/to_s.rb
deleted file mode 100644
index 07ba0903e2..0000000000
--- a/spec/ruby/core/unboundmethod/shared/to_s.rb
+++ /dev/null
@@ -1,25 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
-
-describe :unboundmethod_to_s, shared: true do
- before :each do
- @from_module = UnboundMethodSpecs::Methods.instance_method(:from_mod)
- @from_method = UnboundMethodSpecs::Methods.new.method(:from_mod).unbind
- end
-
- it "returns a String" do
- @from_module.send(@method).should be_kind_of(String)
- @from_method.send(@method).should be_kind_of(String)
- end
-
- it "the String reflects that this is an UnboundMethod object" do
- @from_module.send(@method).should =~ /\bUnboundMethod\b/
- @from_method.send(@method).should =~ /\bUnboundMethod\b/
- end
-
- it "the String shows the method name, Module defined in and Module extracted from" do
- @from_module.send(@method).should =~ /\bfrom_mod\b/
- @from_module.send(@method).should =~ /\bUnboundMethodSpecs::Mod\b/
- @from_method.send(@method).should =~ /\bUnboundMethodSpecs::Methods\b/
- end
-end
diff --git a/spec/ruby/core/unboundmethod/source_location_spec.rb b/spec/ruby/core/unboundmethod/source_location_spec.rb
index 8b95f0776b..927600bfcb 100644
--- a/spec/ruby/core/unboundmethod/source_location_spec.rb
+++ b/spec/ruby/core/unboundmethod/source_location_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "UnboundMethod#source_location" do
before :each do
@@ -8,13 +8,13 @@ describe "UnboundMethod#source_location" do
it "sets the first value to the path of the file in which the method was defined" do
file = @method.source_location.first
- file.should be_an_instance_of(String)
- file.should == File.dirname(__FILE__) + '/fixtures/classes.rb'
+ file.should.instance_of?(String)
+ file.should == File.realpath('fixtures/classes.rb', __dir__)
end
- it "sets the last value to a Fixnum representing the line on which the method was defined" do
+ it "sets the last value to an Integer representing the line on which the method was defined" do
line = @method.source_location.last
- line.should be_an_instance_of(Fixnum)
+ line.should.instance_of?(Integer)
line.should == 5
end
@@ -49,4 +49,11 @@ describe "UnboundMethod#source_location" do
method.source_location[0].should =~ /#{__FILE__}/
method.source_location[1].should == line
end
+
+ it "works for eval with a given line" do
+ c = Class.new do
+ eval('def m; end', nil, "foo", 100)
+ end
+ c.instance_method(:m).source_location.should == ["foo", 100]
+ end
end
diff --git a/spec/ruby/core/unboundmethod/super_method_spec.rb b/spec/ruby/core/unboundmethod/super_method_spec.rb
index 49d356fd2b..aa7c129377 100644
--- a/spec/ruby/core/unboundmethod/super_method_spec.rb
+++ b/spec/ruby/core/unboundmethod/super_method_spec.rb
@@ -1,5 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative '../method/fixtures/classes'
describe "UnboundMethod#super_method" do
it "returns the method that would be called by super in the method" do
@@ -25,4 +26,24 @@ describe "UnboundMethod#super_method" do
method.super_method.should == nil
end
+
+ # https://github.com/jruby/jruby/issues/7240
+ context "after changing an inherited methods visibility" do
+ it "calls the proper super method" do
+ method = MethodSpecs::InheritedMethods::C.instance_method(:derp)
+ method.bind(MethodSpecs::InheritedMethods::C.new).call.should == 'BA'
+ end
+
+ it "returns the expected super_method" do
+ method = MethodSpecs::InheritedMethods::C.instance_method(:derp)
+ method.super_method.owner.should == MethodSpecs::InheritedMethods::A
+ end
+ end
+
+ context "after aliasing an inherited method" do
+ it "returns the expected super_method" do
+ method = MethodSpecs::InheritedMethods::C.instance_method(:meow)
+ method.super_method.owner.should == MethodSpecs::InheritedMethods::A
+ end
+ end
end
diff --git a/spec/ruby/core/unboundmethod/to_s_spec.rb b/spec/ruby/core/unboundmethod/to_s_spec.rb
index 77e1d713f0..b90f315c3a 100644
--- a/spec/ruby/core/unboundmethod/to_s_spec.rb
+++ b/spec/ruby/core/unboundmethod/to_s_spec.rb
@@ -1,7 +1,36 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/to_s', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative '../method/shared/aliased_inspect'
describe "UnboundMethod#to_s" do
- it_behaves_like(:unboundmethod_to_s, :to_s)
+ it_behaves_like :method_to_s_aliased, :to_s, -> meth { meth.unbind }
+
+ before :each do
+ @from_module = UnboundMethodSpecs::Methods.instance_method(:from_mod)
+ @from_method = UnboundMethodSpecs::Methods.new.method(:from_mod).unbind
+ end
+
+ it "returns a String" do
+ @from_module.to_s.should.is_a?(String)
+ @from_method.to_s.should.is_a?(String)
+ end
+
+ it "the String reflects that this is an UnboundMethod object" do
+ @from_module.to_s.should =~ /\bUnboundMethod\b/
+ @from_method.to_s.should =~ /\bUnboundMethod\b/
+ end
+
+ it "the String shows the method name, Module defined in and Module extracted from" do
+ @from_module.to_s.should =~ /\bfrom_mod\b/
+ @from_module.to_s.should =~ /\bUnboundMethodSpecs::Mod\b/
+ end
+
+ it "returns a String including all details" do
+ @from_module.to_s.should.start_with? "#<UnboundMethod: UnboundMethodSpecs::Mod#from_mod"
+ @from_method.to_s.should.start_with? "#<UnboundMethod: UnboundMethodSpecs::Mod#from_mod"
+ end
+
+ it "does not show the defining module if it is the same as the origin" do
+ UnboundMethodSpecs::A.instance_method(:baz).to_s.should.start_with? "#<UnboundMethod: UnboundMethodSpecs::A#baz"
+ end
end
diff --git a/spec/ruby/core/warning/categories_spec.rb b/spec/ruby/core/warning/categories_spec.rb
new file mode 100644
index 0000000000..1e310ef38b
--- /dev/null
+++ b/spec/ruby/core/warning/categories_spec.rb
@@ -0,0 +1,12 @@
+require_relative '../../spec_helper'
+
+ruby_version_is "3.4" do
+ describe "Warning.categories" do
+ # There might be more, but these are standard across Ruby implementations
+ it "returns the list of possible warning categories" do
+ Warning.categories.should.include? :deprecated
+ Warning.categories.should.include? :experimental
+ Warning.categories.should.include? :performance
+ end
+ end
+end
diff --git a/spec/ruby/core/warning/element_reference_spec.rb b/spec/ruby/core/warning/element_reference_spec.rb
new file mode 100644
index 0000000000..5f977759ec
--- /dev/null
+++ b/spec/ruby/core/warning/element_reference_spec.rb
@@ -0,0 +1,27 @@
+require_relative '../../spec_helper'
+
+describe "Warning.[]" do
+ it "returns default values for categories :deprecated and :experimental" do
+ # If any warning options were set on the Ruby that will be executed, then
+ # it's possible this test will fail. In this case we will skip this test.
+ skip if ruby_exe.any? { |opt| opt.start_with?("-W") }
+
+ ruby_exe('p [Warning[:deprecated], Warning[:experimental]]').chomp.should == "[false, true]"
+ ruby_exe('p [Warning[:deprecated], Warning[:experimental]]', options: "-w").chomp.should == "[true, true]"
+ end
+
+ it "returns default values for :performance category" do
+ ruby_exe('p Warning[:performance]').chomp.should == "false"
+ ruby_exe('p Warning[:performance]', options: "-w").chomp.should == "false"
+ end
+
+ it "raises for unknown category" do
+ -> { Warning[:noop] }.should.raise(ArgumentError, /unknown category: noop/)
+ end
+
+ it "raises for non-Symbol category" do
+ -> { Warning[42] }.should.raise(TypeError)
+ -> { Warning[false] }.should.raise(TypeError)
+ -> { Warning["noop"] }.should.raise(TypeError)
+ end
+end
diff --git a/spec/ruby/core/warning/element_set_spec.rb b/spec/ruby/core/warning/element_set_spec.rb
new file mode 100644
index 0000000000..3c8ceb721e
--- /dev/null
+++ b/spec/ruby/core/warning/element_set_spec.rb
@@ -0,0 +1,39 @@
+require_relative '../../spec_helper'
+
+describe "Warning.[]=" do
+ it "emits and suppresses warnings for :deprecated" do
+ ruby_exe('Warning[:deprecated] = true; $; = ""', args: "2>&1").should =~ /is deprecated/
+ ruby_exe('Warning[:deprecated] = false; $; = ""', args: "2>&1").should == ""
+ end
+
+ describe ":experimental" do
+ before do
+ @src = 'warn "This is experimental warning.", category: :experimental'
+ end
+
+ it "emits and suppresses warnings for :experimental" do
+ ruby_exe("Warning[:experimental] = true; eval('#{@src}')", args: "2>&1").should =~ /is experimental/
+ ruby_exe("Warning[:experimental] = false; eval('#{@src}')", args: "2>&1").should == ""
+ end
+ end
+
+ it "enables or disables performance warnings" do
+ original = Warning[:performance]
+ begin
+ Warning[:performance] = !original
+ Warning[:performance].should == !original
+ ensure
+ Warning[:performance] = original
+ end
+ end
+
+ it "raises for unknown category" do
+ -> { Warning[:noop] = false }.should.raise(ArgumentError, /unknown category: noop/)
+ end
+
+ it "raises for non-Symbol category" do
+ -> { Warning[42] = false }.should.raise(TypeError)
+ -> { Warning[false] = false }.should.raise(TypeError)
+ -> { Warning["noop"] = false }.should.raise(TypeError)
+ end
+end
diff --git a/spec/ruby/core/warning/performance_warning_spec.rb b/spec/ruby/core/warning/performance_warning_spec.rb
new file mode 100644
index 0000000000..ab0badcd3d
--- /dev/null
+++ b/spec/ruby/core/warning/performance_warning_spec.rb
@@ -0,0 +1,28 @@
+require_relative '../../spec_helper'
+
+
+describe "Performance warnings" do
+ guard -> { ruby_version_is("3.4") || RUBY_ENGINE == "truffleruby" } do
+ # Optimising Integer, Float or Symbol methods is kind of implementation detail
+ # but multiple implementations do so. So it seems reasonable to have a test case
+ # for at least one such common method.
+ # See https://bugs.ruby-lang.org/issues/20429
+ context "when redefined optimised methods" do
+ it "emits performance warning for redefining Integer#+" do
+ code = <<~CODE
+ Warning[:performance] = true
+
+ class Integer
+ ORIG_METHOD = instance_method(:+)
+
+ def +(...)
+ ORIG_METHOD.bind(self).call(...)
+ end
+ end
+ CODE
+
+ ruby_exe(code, args: "2>&1").should.include?("warning: Redefining 'Integer#+' disables interpreter and JIT optimizations")
+ end
+ end
+ end
+end
diff --git a/spec/ruby/core/warning/warn_spec.rb b/spec/ruby/core/warning/warn_spec.rb
index 44e9eb707b..62f36e3454 100644
--- a/spec/ruby/core/warning/warn_spec.rb
+++ b/spec/ruby/core/warning/warn_spec.rb
@@ -1,60 +1,187 @@
-require File.expand_path("../../../spec_helper", __FILE__)
+require_relative '../../spec_helper'
describe "Warning.warn" do
- ruby_version_is "2.4" do
- it "complains" do
+ it "complains" do
+ -> {
+ Warning.warn("Chunky bacon!")
+ }.should complain("Chunky bacon!")
+ end
+
+ it "does not add a newline" do
+ ruby_exe("Warning.warn('test')", args: "2>&1").should == "test"
+ end
+
+ it "returns nil" do
+ ruby_exe("p Warning.warn('test')", args: "2>&1").should == "testnil\n"
+ end
+
+ it "extends itself" do
+ Warning.singleton_class.ancestors.should.include?(Warning)
+ end
+
+ it "has Warning as the method owner" do
+ ruby_exe("p Warning.method(:warn).owner").should == "Warning\n"
+ end
+
+ it "can be overridden" do
+ code = <<-RUBY
+ $stdout.sync = true
+ $stderr.sync = true
+ def Warning.warn(msg)
+ if msg.start_with?("A")
+ puts msg.upcase
+ else
+ super
+ end
+ end
+ Warning.warn("A warning!")
+ Warning.warn("warning from stderr\n")
+ RUBY
+ ruby_exe(code, args: "2>&1").should == %Q[A WARNING!\nwarning from stderr\n]
+ end
+
+ it "is called by parser warnings" do
+ Warning.should_receive(:warn)
+ verbose = $VERBOSE
+ $VERBOSE = false
+ begin
+ eval "{ key: :value, key: :value2 }"
+ ensure
+ $VERBOSE = verbose
+ end
+ end
+
+ it "is called by Kernel.warn with nil category keyword" do
+ Warning.should_receive(:warn).with("Chunky bacon!\n", category: nil)
+ verbose = $VERBOSE
+ $VERBOSE = false
+ begin
+ Kernel.warn("Chunky bacon!")
+ ensure
+ $VERBOSE = verbose
+ end
+ end
+
+ it "is called by Kernel.warn with given category keyword converted to a symbol" do
+ Warning.should_receive(:warn).with("Chunky bacon!\n", category: :deprecated)
+ verbose = $VERBOSE
+ $VERBOSE = false
+ begin
+ Kernel.warn("Chunky bacon!", category: "deprecated")
+ ensure
+ $VERBOSE = verbose
+ end
+ end
+
+ it "warns when category is :deprecated and Warning[:deprecated] is true" do
+ warn_deprecated = Warning[:deprecated]
+ Warning[:deprecated] = true
+ begin
+ -> {
+ Warning.warn("foo", category: :deprecated)
+ }.should complain("foo")
+ ensure
+ Warning[:deprecated] = warn_deprecated
+ end
+ end
+
+ it "warns when category is :experimental and Warning[:experimental] is true" do
+ warn_experimental = Warning[:experimental]
+ Warning[:experimental] = true
+ begin
-> {
- Warning.warn("Chunky bacon!")
- }.should complain("Chunky bacon!")
+ Warning.warn("foo", category: :experimental)
+ }.should complain("foo")
+ ensure
+ Warning[:experimental] = warn_experimental
end
+ end
- it "extends itself" do
- Warning.singleton_class.ancestors.should include(Warning)
+ ruby_version_is "3.4" do
+ it "warns when category is :strict_unused_block but Warning[:strict_unused_block] is false" do
+ warn_strict_unused_block = Warning[:strict_unused_block]
+ Warning[:strict_unused_block] = true
+ begin
+ -> {
+ Warning.warn("foo", category: :strict_unused_block)
+ }.should complain("foo")
+ ensure
+ Warning[:strict_unused_block] = warn_strict_unused_block
+ end
end
+ end
- it "has Warning as the method owner" do
- ruby_exe("p Warning.method(:warn).owner").should == "Warning\n"
+ it "doesn't print message when category is :deprecated but Warning[:deprecated] is false" do
+ warn_deprecated = Warning[:deprecated]
+ Warning[:deprecated] = false
+ begin
+ -> {
+ Warning.warn("foo", category: :deprecated)
+ }.should_not complain
+ ensure
+ Warning[:deprecated] = warn_deprecated
end
+ end
- it "can be overridden" do
- code = <<-RUBY
- $stdout.sync = true
- $stderr.sync = true
- def Warning.warn(msg)
- if msg.start_with?("A")
- puts msg.upcase
- else
- super
- end
- end
- Warning.warn("A warning!")
- Warning.warn("warning from stderr\n")
- RUBY
- ruby_exe(code, args: "2>&1").should == %Q[A WARNING!\nwarning from stderr\n]
+ it "doesn't print message when category is :experimental but Warning[:experimental] is false" do
+ warn_experimental = Warning[:experimental]
+ Warning[:experimental] = false
+ begin
+ -> {
+ Warning.warn("foo", category: :experimental)
+ }.should_not complain
+ ensure
+ Warning[:experimental] = warn_experimental
end
+ end
- it "is called by parser warnings" do
- Warning.should_receive(:warn)
- verbose = $VERBOSE
- $VERBOSE = false
+ ruby_version_is "3.4" do
+ it "doesn't print message when category is :strict_unused_block but Warning[:strict_unused_block] is false" do
+ warn_strict_unused_block = Warning[:strict_unused_block]
+ Warning[:strict_unused_block] = false
begin
- eval "{ key: :value, key: :value2 }"
+ -> {
+ Warning.warn("foo", category: :strict_unused_block)
+ }.should_not complain
ensure
- $VERBOSE = verbose
+ Warning[:strict_unused_block] = warn_strict_unused_block
end
end
end
- ruby_version_is "2.5" do
- it "is called by Kernel.warn" do
- Warning.should_receive(:warn)
- verbose = $VERBOSE
- $VERBOSE = false
+ ruby_bug '#20573', ''...'3.4' do
+ it "isn't called by Kernel.warn when category is :deprecated but Warning[:deprecated] is false" do
+ warn_deprecated = Warning[:deprecated]
+ begin
+ Warning[:deprecated] = false
+ Warning.should_not_receive(:warn)
+ Kernel.warn("foo", category: :deprecated)
+ ensure
+ Warning[:deprecated] = warn_deprecated
+ end
+ end
+
+ it "isn't called by Kernel.warn when category is :experimental but Warning[:experimental] is false" do
+ warn_experimental = Warning[:experimental]
begin
- Kernel.warn("Chunky bacon!")
+ Warning[:experimental] = false
+ Warning.should_not_receive(:warn)
+ Kernel.warn("foo", category: :experimental)
ensure
- $VERBOSE = verbose
+ Warning[:experimental] = warn_experimental
end
end
end
+
+ it "prints the message when VERBOSE is false" do
+ -> { Warning.warn("foo") }.should complain("foo")
+ end
+
+ it "prints the message when VERBOSE is nil" do
+ -> { Warning.warn("foo") }.should complain("foo", verbose: nil)
+ end
+
+ it "prints the message when VERBOSE is true" do
+ -> { Warning.warn("foo") }.should complain("foo", verbose: true)
+ end
end
diff --git a/spec/ruby/default.mspec b/spec/ruby/default.mspec
index 90f4c1ccaa..c8b1215f56 100644
--- a/spec/ruby/default.mspec
+++ b/spec/ruby/default.mspec
@@ -1,3 +1,4 @@
+# -*- ruby -*-
# Configuration file for Ruby >= 2.0 implementations.
class MSpecScript
@@ -19,8 +20,11 @@ class MSpecScript
# C extension API specs
set :capi, [ 'optional/capi' ]
+ # Thread safety specs
+ set :thread_safety, [ 'optional/thread_safety' ]
+
# A list of _all_ optional specs
- set :optional, get(:capi)
+ set :optional, get(:capi) + get(:thread_safety)
# An ordered list of the directories containing specs to run
set :files, get(:command_line) + get(:language) + get(:core) + get(:library) + get(:security) + get(:optional)
@@ -29,24 +33,22 @@ class MSpecScript
set :ci_files, get(:files)
# The default implementation to run the specs.
- # TODO: this needs to be more sophisticated since the
- # executable is not consistently named.
set :target, 'ruby'
set :backtrace_filter, /mspec\//
set :tags_patterns, [
- [%r(language/), 'tags/1.9/language/'],
- [%r(core/), 'tags/1.9/core/'],
- [%r(command_line/), 'tags/1.9/command_line/'],
- [%r(library/), 'tags/1.9/library/'],
- [%r(security/), 'tags/1.9/security/'],
- [/_spec.rb$/, '_tags.txt']
+ [%r(language/), 'tags/language/'],
+ [%r(core/), 'tags/core/'],
+ [%r(command_line/), 'tags/command_line/'],
+ [%r(library/), 'tags/library/'],
+ [%r(security/), 'tags/security/'],
+ [/_spec\.rb$/, '_tags.txt']
]
- # Enable features
- MSpec.enable_feature :fiber
- MSpec.enable_feature :fiber_library
- MSpec.enable_feature :fork if respond_to?(:fork, true)
- MSpec.enable_feature :encoding
+ set :toplevel_constants_excludes, [
+ /\wSpecs?$/,
+ /^CS_CONST/,
+ /^CSL_CONST/,
+ ]
end
diff --git a/spec/ruby/fixtures/class.rb b/spec/ruby/fixtures/class.rb
index 9609eb6f3c..98cb6c82a2 100644
--- a/spec/ruby/fixtures/class.rb
+++ b/spec/ruby/fixtures/class.rb
@@ -1,9 +1,11 @@
module ClassSpecs
def self.sclass_with_block
+ eval <<-RUBY
class << self
yield
end
+ RUBY
end
def self.sclass_with_return
@@ -110,7 +112,7 @@ module ClassSpecs
class M < L; end
# Can't use a method here because of class definition in method body error
- ANON_CLASS_FOR_NEW = lambda do
+ ANON_CLASS_FOR_NEW = -> do
Class.new do
class NamedInModule
end
@@ -120,6 +122,10 @@ module ClassSpecs
end
end
end
+
+ DEFINE_CLASS = -> do
+ class ::A; end
+ end
end
class Class
diff --git a/spec/ruby/fixtures/code/a/load_fixture.dylib b/spec/ruby/fixtures/code/a/load_fixture.dylib
new file mode 100644
index 0000000000..31f4b1a7bb
--- /dev/null
+++ b/spec/ruby/fixtures/code/a/load_fixture.dylib
@@ -0,0 +1 @@
+ScratchPad << :ext_dylib
diff --git a/spec/ruby/fixtures/code/c/load_fixture.rb b/spec/ruby/fixtures/code/c/load_fixture.rb
new file mode 100644
index 0000000000..4a6e9c9601
--- /dev/null
+++ b/spec/ruby/fixtures/code/c/load_fixture.rb
@@ -0,0 +1 @@
+ScratchPad << :loaded
diff --git a/spec/ruby/fixtures/code/concurrent.rb b/spec/ruby/fixtures/code/concurrent.rb
index 054b8fc055..b3602a3db4 100644
--- a/spec/ruby/fixtures/code/concurrent.rb
+++ b/spec/ruby/fixtures/code/concurrent.rb
@@ -2,7 +2,7 @@ ScratchPad.recorded << :con_pre
Thread.current[:in_concurrent_rb] = true
if t = Thread.current[:wait_for]
- Thread.pass until t.backtrace && t.backtrace.any? { |call| call.include? 'require' }
+ Thread.pass until t.backtrace && t.backtrace.any? { |call| call.include? 'require' } && t.stop?
end
if Thread.current[:con_raise]
diff --git a/spec/ruby/fixtures/code/concurrent_require_fixture.rb b/spec/ruby/fixtures/code/concurrent_require_fixture.rb
new file mode 100644
index 0000000000..d4ce734183
--- /dev/null
+++ b/spec/ruby/fixtures/code/concurrent_require_fixture.rb
@@ -0,0 +1,4 @@
+object = ScratchPad.recorded
+thread = Thread.new { object.require(__FILE__) }
+Thread.pass until thread.stop?
+ScratchPad.record(thread)
diff --git a/spec/ruby/fixtures/code/d/load_fixture.rb.rb b/spec/ruby/fixtures/code/d/load_fixture.rb.rb
new file mode 100644
index 0000000000..7e9217729a
--- /dev/null
+++ b/spec/ruby/fixtures/code/d/load_fixture.rb.rb
@@ -0,0 +1 @@
+ScratchPad << :rbrb
diff --git a/spec/ruby/fixtures/code/load_fixture.dylib b/spec/ruby/fixtures/code/load_fixture.dylib
new file mode 100644
index 0000000000..31f4b1a7bb
--- /dev/null
+++ b/spec/ruby/fixtures/code/load_fixture.dylib
@@ -0,0 +1 @@
+ScratchPad << :ext_dylib
diff --git a/spec/ruby/fixtures/code/load_fixture.ext.dylib b/spec/ruby/fixtures/code/load_fixture.ext.dylib
new file mode 100644
index 0000000000..31f4b1a7bb
--- /dev/null
+++ b/spec/ruby/fixtures/code/load_fixture.ext.dylib
@@ -0,0 +1 @@
+ScratchPad << :ext_dylib
diff --git a/spec/ruby/fixtures/code/load_fixture_and__FILE__.rb b/spec/ruby/fixtures/code/load_fixture_and__FILE__.rb
new file mode 100644
index 0000000000..27388c7d8d
--- /dev/null
+++ b/spec/ruby/fixtures/code/load_fixture_and__FILE__.rb
@@ -0,0 +1 @@
+ScratchPad << __FILE__
diff --git a/spec/ruby/fixtures/code/load_wrap_fixture.rb b/spec/ruby/fixtures/code/load_wrap_fixture.rb
new file mode 100644
index 0000000000..526bbf8c82
--- /dev/null
+++ b/spec/ruby/fixtures/code/load_wrap_fixture.rb
@@ -0,0 +1,12 @@
+class LoadSpecWrap
+ ScratchPad << String
+end
+
+LOAD_WRAP_SPECS_TOP_LEVEL_CONSTANT = 1
+
+def load_wrap_specs_top_level_method
+ :load_wrap_specs_top_level_method
+end
+ScratchPad << method(:load_wrap_specs_top_level_method).owner
+
+ScratchPad << self
diff --git a/spec/ruby/fixtures/code/recursive_require_fixture.rb b/spec/ruby/fixtures/code/recursive_require_fixture.rb
index 8842a6ad74..ebeba34fce 100644
--- a/spec/ruby/fixtures/code/recursive_require_fixture.rb
+++ b/spec/ruby/fixtures/code/recursive_require_fixture.rb
@@ -1,3 +1,3 @@
-require File.expand_path("../recursive_require_fixture.rb", __FILE__)
+require_relative 'recursive_require_fixture'
ScratchPad << :loaded
diff --git a/spec/ruby/fixtures/code/wrap_fixture.rb b/spec/ruby/fixtures/code/wrap_fixture.rb
deleted file mode 100644
index b83a8970d7..0000000000
--- a/spec/ruby/fixtures/code/wrap_fixture.rb
+++ /dev/null
@@ -1,3 +0,0 @@
-class LoadSpecWrap
- ScratchPad << self
-end
diff --git a/spec/ruby/fixtures/code_loading.rb b/spec/ruby/fixtures/code_loading.rb
index d6cf0edb47..decd56a358 100644
--- a/spec/ruby/fixtures/code_loading.rb
+++ b/spec/ruby/fixtures/code_loading.rb
@@ -12,7 +12,22 @@ module CodeLoadingSpecs
end
end
+ def self.preload_rubygems
+ # Require RubyGems eagerly, to ensure #require is already the RubyGems
+ # version and RubyGems is only loaded once, before starting #require/#autoload specs
+ # which snapshot $LOADED_FEATURES and could cause RubyGems to load twice.
+ # #require specs also snapshot #require, and could end up redefining #require as the original core Kernel#require.
+ @rubygems ||= begin
+ require "rubygems"
+ true
+ rescue LoadError
+ true
+ end
+ end
+
def self.spec_setup
+ preload_rubygems
+
@saved_loaded_features = $LOADED_FEATURES.clone
@saved_load_path = $LOAD_PATH.clone
ScratchPad.record []
diff --git a/spec/ruby/fixtures/constants.rb b/spec/ruby/fixtures/constants.rb
index e5b20596ef..7f0b88daab 100644
--- a/spec/ruby/fixtures/constants.rb
+++ b/spec/ruby/fixtures/constants.rb
@@ -1,7 +1,7 @@
# Contains all static code examples of all constants behavior in language and
# library specs. The specs include language/constants_spec.rb and the specs
-# for Module#const_defined?, Module#const_get, Module#const_set,
-# Module#remove_const, Module#const_missing and Module#constants.
+# for Module#const_defined?, Module#const_get, Module#const_set, Module#remove_const,
+# Module#const_source_location, Module#const_missing and Module#constants.
#
# Rather than defining a class structure for each example, a canonical set of
# classes is used along with numerous constants, in most cases, a unique
@@ -10,7 +10,7 @@
# variety in class and module configurations, including hierarchy,
# containment, inclusion, singletons and toplevel.
#
-# Constants are numbered for for uniqueness. The CS_ prefix is uniformly used
+# Constants are numbered for uniqueness. The CS_ prefix is uniformly used
# and is to minimize clashes with other toplevel constants (see e.g. ModuleA
# which is included in Object). Constant values are symbols. A numbered suffix
# is used to distinguish constants with the same name defined in different
@@ -28,28 +28,34 @@
# for completeness. No other constant of this name should be defined in the
# specs.
CS_CONST1 = :const1 # only defined here
+CS_CONST1_LINE = __LINE__ - 1
module ConstantSpecs
# Included at toplevel
module ModuleA
CS_CONST10 = :const10_1
+ CS_CONST10_LINE = __LINE__ - 1
CS_CONST12 = :const12_2
CS_CONST13 = :const13
+ CS_CONST13_LINE = __LINE__ - 1
CS_CONST21 = :const21_2
end
# Included in ParentA
module ModuleB
+ LINE = __LINE__ - 1
CS_CONST10 = :const10_9
CS_CONST11 = :const11_2
CS_CONST12 = :const12_1
+ CS_CONST12_LINE = __LINE__ - 1
end
# Included in ChildA
module ModuleC
CS_CONST10 = :const10_4
CS_CONST15 = :const15_1
+ CS_CONST15_LINE = __LINE__ - 1
end
# Included in ChildA metaclass
@@ -70,12 +76,21 @@ module ConstantSpecs
CS_CONST10 = :const10_8
end
+ # Included in ContainerA
+ module ModuleIncludePrepended
+ prepend ModuleD
+
+ CS_CONST11 = :const11_8
+ end
+
# The following classes/modules have all the constants set "statically".
# Contrast with the classes below where the constants are set as the specs
# are run.
class ClassA
+ LINE = __LINE__ - 1
CS_CONST10 = :const10_10
+ CS_CONST10_LINE = __LINE__ - 1
CS_CONST16 = :const16
CS_CONST17 = :const17_2
CS_CONST22 = :const22_1
@@ -97,10 +112,14 @@ module ConstantSpecs
include ModuleB
CS_CONST4 = :const4
+ CS_CONST4_LINE = __LINE__ - 1
CS_CONST10 = :const10_5
+ CS_CONST10_LINE = __LINE__ - 1
CS_CONST11 = :const11_1
+ CS_CONST11_LINE = __LINE__ - 1
CS_CONST15 = :const15_2
CS_CONST20 = :const20_2
+ CS_CONST20_LINE = __LINE__ - 1
CS_CONST21 = :const21_1
CS_CONST22 = :const22_2
@@ -118,6 +137,7 @@ module ConstantSpecs
CS_CONST5 = :const5
CS_CONST10 = :const10_2
+ CS_CONST10_LINE = __LINE__ - 1
CS_CONST23 = :const23
class ChildA < ParentA
@@ -135,6 +155,7 @@ module ConstantSpecs
CS_CONST6 = :const6
CS_CONST10 = :const10_3
+ CS_CONST10_LINE = __LINE__ - 1
CS_CONST19 = :const19_2
def self.const10; CS_CONST10; end
@@ -156,6 +177,10 @@ module ConstantSpecs
def const10; CS_CONST10; end
end
+ class ContainerPrepend
+ include ModuleIncludePrepended
+ end
+
class ContainerA::ChildA
def self.const23; CS_CONST23; end
end
@@ -282,7 +307,18 @@ module ConstantSpecs
end
CS_PRIVATE = :cs_private
+ CS_PRIVATE_LINE = __LINE__ - 1
private_constant :CS_PRIVATE
end
+module ConstantSpecsThree
+ module ConstantSpecsTwo
+ Foo = :cs_three_foo
+ end
+end
+
+module ConstantSpecsTwo
+ Foo = :cs_two_foo
+end
+
include ConstantSpecs::ModuleA
diff --git a/spec/ruby/fixtures/io.rb b/spec/ruby/fixtures/io.rb
new file mode 100644
index 0000000000..87ebbbb2bd
--- /dev/null
+++ b/spec/ruby/fixtures/io.rb
@@ -0,0 +1,12 @@
+module IOSpec
+ def self.exhaust_write_buffer(io)
+ written = 0
+ buf = " " * 4096
+
+ while true
+ written += io.write_nonblock(buf)
+ end
+ rescue Errno::EAGAIN, Errno::EWOULDBLOCK
+ written
+ end
+end
diff --git a/spec/ruby/fixtures/rational.rb b/spec/ruby/fixtures/rational.rb
deleted file mode 100644
index d0d05d0437..0000000000
--- a/spec/ruby/fixtures/rational.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-module RationalSpecs
- class SubNumeric < Numeric
- def initialize(value)
- @value = Rational(value)
- end
-
- def to_r
- @value
- end
- end
-end
diff --git a/spec/ruby/language/BEGIN_spec.rb b/spec/ruby/language/BEGIN_spec.rb
index 826d5f0c89..25db32b96a 100644
--- a/spec/ruby/language/BEGIN_spec.rb
+++ b/spec/ruby/language/BEGIN_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../spec_helper', __FILE__)
+require_relative '../spec_helper'
describe "The BEGIN keyword" do
before :each do
@@ -15,7 +15,12 @@ describe "The BEGIN keyword" do
end
it "must appear in a top-level context" do
- lambda { eval "1.times { BEGIN { 1 } }" }.should raise_error(SyntaxError)
+ -> { eval "1.times { BEGIN { 1 } }" }.should.raise(SyntaxError)
+ end
+
+ it "uses top-level for self" do
+ eval("BEGIN { ScratchPad << self.to_s }", TOPLEVEL_BINDING)
+ ScratchPad.recorded.should == ['main']
end
it "runs first in a given code unit" do
@@ -29,4 +34,8 @@ describe "The BEGIN keyword" do
ScratchPad.recorded.should == ['foo', 'bar']
end
+
+ it "returns the top-level script's filename for __FILE__" do
+ ruby_exe(fixture(__FILE__, "begin_file.rb")).chomp.should =~ /begin_file\.rb$/
+ end
end
diff --git a/spec/ruby/language/END_spec.rb b/spec/ruby/language/END_spec.rb
new file mode 100644
index 0000000000..c84f0cc9ac
--- /dev/null
+++ b/spec/ruby/language/END_spec.rb
@@ -0,0 +1,33 @@
+require_relative '../spec_helper'
+require_relative '../shared/kernel/at_exit'
+
+describe "The END keyword" do
+ it_behaves_like :kernel_at_exit, :END
+
+ it "runs only once for multiple calls" do
+ ruby_exe("10.times { END { puts 'foo' }; } ").should == "foo\n"
+ end
+
+ it "is affected by the toplevel assignment" do
+ ruby_exe("foo = 'foo'; END { puts foo }").should == "foo\n"
+ end
+
+ it "warns when END is used in a method" do
+ ruby_exe(<<~ruby, args: "2>&1").should =~ /warning: END in method; use at_exit/
+ def foo
+ END { }
+ end
+ ruby
+ end
+
+ context "END blocks and at_exit callbacks are mixed" do
+ it "runs them all in reverse order of registration" do
+ ruby_exe(<<~ruby).should == "at_exit#2\nEND#2\nat_exit#1\nEND#1\n"
+ END { puts 'END#1' }
+ at_exit { puts 'at_exit#1' }
+ END { puts 'END#2' }
+ at_exit { puts 'at_exit#2' }
+ ruby
+ end
+ end
+end
diff --git a/spec/ruby/language/README b/spec/ruby/language/README
index 74eaf58709..ae08e17fb1 100644
--- a/spec/ruby/language/README
+++ b/spec/ruby/language/README
@@ -4,7 +4,7 @@ words. These words significantly describe major elements of the language,
including flow control constructs like 'for' and 'while', conditional
execution like 'if' and 'unless', exceptional execution control like 'rescue',
etc. There are also literals for the basic "types" like String, Regexp, Array
-and Fixnum.
+and Integer.
Behavioral specifications describe the behavior of concrete entities. Rather
than using concepts of computation to organize these spec files, we use
diff --git a/spec/ruby/language/alias_spec.rb b/spec/ruby/language/alias_spec.rb
index e9f0050e17..4b3d36d308 100644
--- a/spec/ruby/language/alias_spec.rb
+++ b/spec/ruby/language/alias_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../spec_helper', __FILE__)
+require_relative '../spec_helper'
class AliasObject
attr :foo
@@ -38,20 +38,29 @@ describe "The alias keyword" do
@obj.a.should == 5
end
- it "works with a doubule quoted symbol on the left-hand side" do
+ it "works with a double quoted symbol on the left-hand side" do
@meta.class_eval do
alias :"a" value
end
@obj.a.should == 5
end
- it "works with an interoplated symbol on the left-hand side" do
+ it "works with an interpolated symbol on the left-hand side" do
@meta.class_eval do
alias :"#{'a'}" value
end
@obj.a.should == 5
end
+ it "works with an interpolated symbol with non-literal embedded expression on the left-hand side" do
+ @meta.class_eval do
+ eval %Q{
+ alias :"#{'a' + ''.to_s}" value
+ }
+ end
+ @obj.a.should == 5
+ end
+
it "works with a simple symbol on the right-hand side" do
@meta.class_eval do
alias a :value
@@ -66,20 +75,29 @@ describe "The alias keyword" do
@obj.a.should == 5
end
- it "works with a doubule quoted symbol on the right-hand side" do
+ it "works with a double quoted symbol on the right-hand side" do
@meta.class_eval do
alias a :"value"
end
@obj.a.should == 5
end
- it "works with an interoplated symbol on the right-hand side" do
+ it "works with an interpolated symbol on the right-hand side" do
@meta.class_eval do
alias a :"#{'value'}"
end
@obj.a.should == 5
end
+ it "works with an interpolated symbol with non-literal embedded expression on the right-hand side" do
+ @meta.class_eval do
+ eval %Q{
+ alias a :"#{'value' + ''.to_s}"
+ }
+ end
+ @obj.a.should == 5
+ end
+
it "adds the new method to the list of methods" do
original_methods = @obj.methods
@meta.class_eval do
@@ -122,7 +140,7 @@ describe "The alias keyword" do
end
@obj.__value.should == 5
- lambda { AliasObject.new.__value }.should raise_error(NoMethodError)
+ -> { AliasObject.new.__value }.should.raise(NoMethodError)
end
it "operates on the class/module metaclass when used in instance_eval" do
@@ -131,7 +149,7 @@ describe "The alias keyword" do
end
AliasObject.__klass_method.should == 7
- lambda { Object.__klass_method }.should raise_error(NoMethodError)
+ -> { Object.__klass_method }.should.raise(NoMethodError)
end
it "operates on the class/module metaclass when used in instance_exec" do
@@ -140,7 +158,7 @@ describe "The alias keyword" do
end
AliasObject.__klass_method2.should == 7
- lambda { Object.__klass_method2 }.should raise_error(NoMethodError)
+ -> { Object.__klass_method2 }.should.raise(NoMethodError)
end
it "operates on methods defined via attr, attr_reader, and attr_accessor" do
@@ -204,7 +222,7 @@ describe "The alias keyword" do
end
it "operates on methods with splat arguments defined in a superclass using text block for class eval" do
- class Sub < AliasObject;end
+ subclass = Class.new(AliasObject)
AliasObject.class_eval <<-code
def test(*args)
4
@@ -215,32 +233,62 @@ describe "The alias keyword" do
alias test_without_check test
alias test test_with_check
code
- Sub.new.test("testing").should == 4
+ subclass.new.test("testing").should == 4
end
- it "is not allowed against Fixnum or String instances" do
- lambda do
+ it "is not allowed against Integer or String instances" do
+ -> do
1.instance_eval do
alias :foo :to_s
end
- end.should raise_error(TypeError)
+ end.should.raise(TypeError)
- lambda do
+ -> do
:blah.instance_eval do
alias :foo :to_s
end
- end.should raise_error(TypeError)
+ end.should.raise(TypeError)
end
it "on top level defines the alias on Object" do
# because it defines on the default definee / current module
- ruby_exe("def foo; end; alias bla foo; print method(:bla).owner", escape: true).should == "Object"
+ ruby_exe("def foo; end; alias bla foo; print method(:bla).owner").should == "Object"
end
it "raises a NameError when passed a missing name" do
- lambda { @meta.class_eval { alias undef_method not_exist } }.should raise_error(NameError) { |e|
+ -> { @meta.class_eval { alias undef_method not_exist } }.should.raise(NameError) { |e|
# a NameError and not a NoMethodError
e.class.should == NameError
}
end
+
+ it "defines the method on the aliased class when the original method is from a parent class" do
+ parent = Class.new do
+ def parent_method
+ end
+ end
+ child = Class.new(parent) do
+ alias parent_method_alias parent_method
+ end
+
+ child.instance_method(:parent_method_alias).owner.should == child
+ child.instance_methods(false).should.include?(:parent_method_alias)
+ end
+end
+
+describe "The alias keyword" do
+ it "can create a new global variable, synonym of the original" do
+ code = '$a = 1; alias $b $a; p [$a, $b]; $b = 2; p [$a, $b]'
+ ruby_exe(code).should == "[1, 1]\n[2, 2]\n"
+ end
+
+ it "can override an existing global variable and make them synonyms" do
+ code = '$a = 1; $b = 2; alias $b $a; p [$a, $b]; $b = 3; p [$a, $b]'
+ ruby_exe(code).should == "[1, 1]\n[3, 3]\n"
+ end
+
+ it "supports aliasing twice the same global variables" do
+ code = '$a = 1; alias $b $a; alias $b $a; p [$a, $b]'
+ ruby_exe(code).should == "[1, 1]\n"
+ end
end
diff --git a/spec/ruby/language/and_spec.rb b/spec/ruby/language/and_spec.rb
index e084fd3cef..c5c255989b 100644
--- a/spec/ruby/language/and_spec.rb
+++ b/spec/ruby/language/and_spec.rb
@@ -1,11 +1,11 @@
-require File.expand_path('../../spec_helper', __FILE__)
+require_relative '../spec_helper'
describe "The '&&' statement" do
it "short-circuits evaluation at the first condition to be false" do
x = nil
true && false && x = 1
- x.should be_nil
+ x.should == nil
end
it "evaluates to the first condition not to be true" do
@@ -33,9 +33,9 @@ describe "The '&&' statement" do
end
it "treats empty expressions as nil" do
- (() && true).should be_nil
- (true && ()).should be_nil
- (() && ()).should be_nil
+ (() && true).should == nil
+ (true && ()).should == nil
+ (() && ()).should == nil
end
end
@@ -44,7 +44,7 @@ describe "The 'and' statement" do
it "short-circuits evaluation at the first condition to be false" do
x = nil
true and false and x = 1
- x.should be_nil
+ x.should == nil
end
it "evaluates to the first condition not to be true" do
@@ -72,9 +72,9 @@ describe "The 'and' statement" do
end
it "treats empty expressions as nil" do
- (() and true).should be_nil
- (true and ()).should be_nil
- (() and ()).should be_nil
+ (() and true).should == nil
+ (true and ()).should == nil
+ (() and ()).should == nil
end
end
diff --git a/spec/ruby/language/array_spec.rb b/spec/ruby/language/array_spec.rb
index c3ed8c14c5..78cf36c201 100644
--- a/spec/ruby/language/array_spec.rb
+++ b/spec/ruby/language/array_spec.rb
@@ -1,10 +1,10 @@
-require File.expand_path('../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/array', __FILE__)
+require_relative '../spec_helper'
+require_relative 'fixtures/array'
describe "Array literals" do
it "[] should return a new array populated with the given elements" do
array = [1, 'a', nil]
- array.should be_kind_of(Array)
+ array.should.is_a?(Array)
array[0].should == 1
array[1].should == 'a'
array[2].should == nil
@@ -12,7 +12,7 @@ describe "Array literals" do
it "[] treats empty expressions as nil elements" do
array = [0, (), 2, (), 4]
- array.should be_kind_of(Array)
+ array.should.is_a?(Array)
array[0].should == 0
array[1].should == nil
array[2].should == 2
@@ -36,6 +36,13 @@ describe "Array literals" do
[1, *nil, 3].should == [1, 3]
[*nil, *nil, *nil].should == []
end
+
+ it "evaluates each argument exactly once" do
+ se = ArraySpec::SideEffect.new
+ se.array_result(true)
+ se.array_result(false)
+ se.call_count.should == 4
+ end
end
describe "Bareword array literal" do
@@ -82,7 +89,7 @@ describe "The unpacking splat operator (*)" do
it "returns a new array containing the same values when applied to an array inside an empty array" do
splatted_array = [3, 4, 5]
[*splatted_array].should == splatted_array
- [*splatted_array].should_not equal(splatted_array)
+ [*splatted_array].should_not.equal?(splatted_array)
end
it "unpacks the start and count arguments in an array slice assignment" do
@@ -128,7 +135,7 @@ describe "The unpacking splat operator (*)" do
it "when applied to a non-Array value uses it unchanged if it does not respond_to?(:to_a)" do
obj = Object.new
- obj.should_not respond_to(:to_a)
+ obj.should_not.respond_to?(:to_a)
[1, *obj].should == [1, obj]
end
@@ -148,8 +155,12 @@ describe "The unpacking splat operator (*)" do
b = [1, 0]
[*a, 3, *a, *b].should == [1, 2, 3, 1, 2, 1, 0]
end
-end
-
-describe "The packing splat operator (*)" do
+ ruby_version_is "4.0" do
+ it "does not call #to_a on nil" do
+ e = nil
+ e.should_not_receive(:to_a)
+ [*e].should == []
+ end
+ end
end
diff --git a/spec/ruby/language/assignments_spec.rb b/spec/ruby/language/assignments_spec.rb
new file mode 100644
index 0000000000..d621c9f0c6
--- /dev/null
+++ b/spec/ruby/language/assignments_spec.rb
@@ -0,0 +1,582 @@
+require_relative '../spec_helper'
+
+# Should be synchronized with spec/ruby/language/optional_assignments_spec.rb
+# Some specs for assignments are located in language/variables_spec.rb
+describe 'Assignments' do
+ describe 'using =' do
+ describe 'evaluation order' do
+ it 'evaluates expressions left to right when assignment with an accessor' do
+ object = Object.new
+ def object.a=(value) end
+ ScratchPad.record []
+
+ (ScratchPad << :receiver; object).a = (ScratchPad << :rhs; :value)
+ ScratchPad.recorded.should == [:receiver, :rhs]
+ end
+
+ it 'evaluates expressions left to right when assignment with a #[]=' do
+ object = Object.new
+ def object.[]=(_, _) end
+ ScratchPad.record []
+
+ (ScratchPad << :receiver; object)[(ScratchPad << :argument; :a)] = (ScratchPad << :rhs; :value)
+ ScratchPad.recorded.should == [:receiver, :argument, :rhs]
+ end
+
+ it 'evaluates expressions left to right when assignment with compounded constant' do
+ m = Module.new
+ ScratchPad.record []
+
+ (ScratchPad << :module; m)::A = (ScratchPad << :rhs; :value)
+ ScratchPad.recorded.should == [:module, :rhs]
+ end
+
+ it 'raises TypeError after evaluation of right-hand-side when compounded constant module is not a module' do
+ ScratchPad.record []
+
+ -> {
+ (:not_a_module)::A = (ScratchPad << :rhs; :value)
+ }.should.raise(TypeError)
+
+ ScratchPad.recorded.should == [:rhs]
+ end
+ end
+
+ context "given block argument" do
+ before do
+ @klass = Class.new do
+ def initialize(h) @h = h end
+ def [](k, &block) @h[k]; end
+ def []=(k, v, &block) @h[k] = v; end
+ end
+ end
+
+ ruby_version_is ""..."3.4" do
+ it "accepts block argument" do
+ obj = @klass.new(a: 1)
+ block = proc {}
+
+ eval "obj[:a, &block] = 2"
+ eval("obj[:a, &block]").should == 2
+ end
+ end
+
+ ruby_version_is "3.4" do
+ it "raises SyntaxError" do
+ obj = @klass.new(a: 1)
+ block = proc {}
+
+ -> {
+ eval "obj[:a, &block] = 2"
+ }.should.raise(SyntaxError, /unexpected block arg given in index assignment|block arg given in index assignment/)
+ end
+ end
+ end
+
+ context "given keyword arguments" do
+ before do
+ @klass = Class.new do
+ attr_reader :x
+
+ def []=(*args, **kw)
+ @x = [args, kw]
+ end
+ end
+ end
+
+ ruby_version_is ""..."3.4" do
+ it "supports keyword arguments in index assignments" do
+ a = @klass.new
+ eval "a[1, 2, 3, b: 4] = 5"
+ a.x.should == [[1, 2, 3, {b: 4}, 5], {}]
+ end
+ end
+
+ ruby_version_is "3.4" do
+ it "raises SyntaxError when given keyword arguments in index assignments" do
+ a = @klass.new
+ -> { eval "a[1, 2, 3, b: 4] = 5" }.should.raise(SyntaxError,
+ /keywords are not allowed in index assignment expressions|keyword arg given in index assignment/) # prism|parse.y
+ end
+ end
+ end
+ end
+
+ describe 'using +=' do
+ describe 'using an accessor' do
+ before do
+ klass = Class.new { attr_accessor :b }
+ @a = klass.new
+ end
+
+ it 'does evaluate receiver only once when assigns' do
+ ScratchPad.record []
+ @a.b = 1
+
+ (ScratchPad << :evaluated; @a).b += 2
+
+ ScratchPad.recorded.should == [:evaluated]
+ @a.b.should == 3
+ end
+
+ it 'ignores method visibility when receiver is self' do
+ klass_with_private_methods = Class.new do
+ def initialize(n) @a = n end
+ def public_method(n); self.a += n end
+ private
+ def a; @a end
+ def a=(n) @a = n; 42 end
+ end
+
+ a = klass_with_private_methods.new(0)
+ a.public_method(2).should == 2
+ end
+ end
+
+ describe 'using a #[]' do
+ before do
+ klass = Class.new do
+ def [](k)
+ @hash ||= {}
+ @hash[k]
+ end
+
+ def []=(k, v)
+ @hash ||= {}
+ @hash[k] = v
+ 7
+ end
+ end
+ @b = klass.new
+ end
+
+ it 'evaluates receiver only once when assigns' do
+ ScratchPad.record []
+ a = {k: 1}
+
+ (ScratchPad << :evaluated; a)[:k] += 2
+
+ ScratchPad.recorded.should == [:evaluated]
+ a[:k].should == 3
+ end
+
+ it 'ignores method visibility when receiver is self' do
+ klass_with_private_methods = Class.new do
+ def initialize(h) @a = h end
+ def public_method(k, n); self[k] += n end
+ private
+ def [](k) @a[k] end
+ def []=(k, v) @a[k] = v; 42 end
+ end
+
+ a = klass_with_private_methods.new(k: 0)
+ a.public_method(:k, 2).should == 2
+ end
+
+ context "given block argument" do
+ before do
+ @klass = Class.new do
+ def initialize(h) @h = h end
+ def [](k, &block) @h[k]; end
+ def []=(k, v, &block) @h[k] = v; end
+ end
+ end
+
+ ruby_version_is ""..."3.4" do
+ it "accepts block argument" do
+ obj = @klass.new(a: 1)
+ block = proc {}
+
+ eval "obj[:a, &block] += 2"
+ eval("obj[:a, &block]").should == 3
+ end
+ end
+
+ ruby_version_is "3.4" do
+ it "raises SyntaxError" do
+ obj = @klass.new(a: 1)
+ block = proc {}
+
+ -> {
+ eval "obj[:a, &block] += 2"
+ }.should.raise(SyntaxError, /unexpected block arg given in index assignment|block arg given in index assignment/)
+ end
+ end
+ end
+
+ context "given keyword arguments" do
+ before do
+ @klass = Class.new do
+ attr_reader :x
+
+ def [](*args)
+ 100
+ end
+
+ def []=(*args, **kw)
+ @x = [args, kw]
+ end
+ end
+ end
+
+ ruby_version_is ""..."3.4" do
+ it "supports keyword arguments in index assignments" do
+ a = @klass.new
+ eval "a[1, 2, 3, b: 4] += 5"
+ a.x.should == [[1, 2, 3, 105], {b: 4}]
+ end
+ end
+
+ ruby_version_is "3.4" do
+ it "raises SyntaxError when given keyword arguments in index assignments" do
+ a = @klass.new
+ -> { eval "a[1, 2, 3, b: 4] += 5" }.should.raise(SyntaxError,
+ /keywords are not allowed in index assignment expressions|keyword arg given in index assignment/) # prism|parse.y
+ end
+ end
+ end
+
+ context 'splatted argument' do
+ it 'correctly handles it' do
+ @b[:m] = 10
+ (@b[*[:m]] += 10).should == 20
+ @b[:m].should == 20
+
+ @b[:n] = 10
+ (@b[*(1; [:n])] += 10).should == 20
+ @b[:n].should == 20
+
+ @b[:k] = 10
+ (@b[*begin 1; [:k] end] += 10).should == 20
+ @b[:k].should == 20
+ end
+
+ it 'calls #to_a only once' do
+ k = Object.new
+ def k.to_a
+ ScratchPad << :to_a
+ [:k]
+ end
+
+ ScratchPad.record []
+ @b[:k] = 10
+ (@b[*k] += 10).should == 20
+ @b[:k].should == 20
+ ScratchPad.recorded.should == [:to_a]
+ end
+
+ it 'correctly handles a nested splatted argument' do
+ @b[:k] = 10
+ (@b[*[*[:k]]] += 10).should == 20
+ @b[:k].should == 20
+ end
+
+ it 'correctly handles multiple nested splatted arguments' do
+ klass_with_multiple_parameters = Class.new do
+ def [](k1, k2, k3)
+ @hash ||= {}
+ @hash[:"#{k1}#{k2}#{k3}"]
+ end
+
+ def []=(k1, k2, k3, v)
+ @hash ||= {}
+ @hash[:"#{k1}#{k2}#{k3}"] = v
+ 7
+ end
+ end
+ a = klass_with_multiple_parameters.new
+
+ a[:a, :b, :c] = 10
+ (a[*[:a], *[:b], *[:c]] += 10).should == 20
+ a[:a, :b, :c].should == 20
+ end
+ end
+ end
+
+ describe 'using compounded constants' do
+ it 'causes side-effects of the module part to be applied only once (when assigns)' do
+ module ConstantSpecs
+ OpAssignTrue = 1
+ end
+
+ suppress_warning do # already initialized constant
+ x = 0
+ (x += 1; ConstantSpecs)::OpAssignTrue += 2
+ x.should == 1
+ ConstantSpecs::OpAssignTrue.should == 3
+ end
+
+ ConstantSpecs.send :remove_const, :OpAssignTrue
+ end
+ end
+ end
+end
+
+# generic cases
+describe 'Multiple assignments' do
+ it 'assigns multiple targets when assignment with an accessor' do
+ object = Object.new
+ class << object
+ attr_accessor :a, :b
+ end
+
+ object.a, object.b = :a, :b
+
+ object.a.should == :a
+ object.b.should == :b
+ end
+
+ it 'assigns multiple targets when assignment with a nested accessor' do
+ object = Object.new
+ class << object
+ attr_accessor :a, :b
+ end
+
+ (object.a, object.b), c = [:a, :b], nil
+
+ object.a.should == :a
+ object.b.should == :b
+ end
+
+ it 'assigns multiple targets when assignment with a #[]=' do
+ object = Object.new
+ class << object
+ def []=(k, v) (@h ||= {})[k] = v; end
+ def [](k) (@h ||= {})[k]; end
+ end
+
+ object[:a], object[:b] = :a, :b
+
+ object[:a].should == :a
+ object[:b].should == :b
+ end
+
+ it 'assigns multiple targets when assignment with a nested #[]=' do
+ object = Object.new
+ class << object
+ def []=(k, v) (@h ||= {})[k] = v; end
+ def [](k) (@h ||= {})[k]; end
+ end
+
+ (object[:a], object[:b]), c = [:v1, :v2], nil
+
+ object[:a].should == :v1
+ object[:b].should == :v2
+ end
+
+ it 'assigns multiple targets when assignment with compounded constant' do
+ m = Module.new
+
+ m::A, m::B = :a, :b
+
+ m::A.should == :a
+ m::B.should == :b
+ end
+
+ it 'assigns multiple targets when assignment with a nested compounded constant' do
+ m = Module.new
+
+ (m::A, m::B), c = [:a, :b], nil
+
+ m::A.should == :a
+ m::B.should == :b
+ end
+end
+
+describe 'Multiple assignments' do
+ describe 'evaluation order' do
+ it 'evaluates expressions left to right when assignment with an accessor' do
+ object = Object.new
+ def object.a=(value) end
+ ScratchPad.record []
+
+ (ScratchPad << :a; object).a, (ScratchPad << :b; object).a = (ScratchPad << :c; :c), (ScratchPad << :d; :d)
+ ScratchPad.recorded.should == [:a, :b, :c, :d]
+ end
+
+ it 'evaluates expressions left to right when assignment with a nested accessor' do
+ object = Object.new
+ def object.a=(value) end
+ ScratchPad.record []
+
+ ((ScratchPad << :a; object).a, foo), bar = [(ScratchPad << :b; :b)]
+ ScratchPad.recorded.should == [:a, :b]
+ end
+
+ it 'evaluates expressions left to right when assignment with a deeply nested accessor' do
+ o = Object.new
+ def o.a=(value) end
+ def o.b=(value) end
+ def o.c=(value) end
+ def o.d=(value) end
+ def o.e=(value) end
+ def o.f=(value) end
+ ScratchPad.record []
+
+ (ScratchPad << :a; o).a,
+ ((ScratchPad << :b; o).b,
+ ((ScratchPad << :c; o).c, (ScratchPad << :d; o).d),
+ (ScratchPad << :e; o).e),
+ (ScratchPad << :f; o).f = (ScratchPad << :value; :value)
+
+ ScratchPad.recorded.should == [:a, :b, :c, :d, :e, :f, :value]
+ end
+
+ it 'evaluates expressions left to right when assignment with a #[]=' do
+ object = Object.new
+ def object.[]=(_, _) end
+ ScratchPad.record []
+
+ (ScratchPad << :a; object)[(ScratchPad << :b; :b)], (ScratchPad << :c; object)[(ScratchPad << :d; :d)] = (ScratchPad << :e; :e), (ScratchPad << :f; :f)
+ ScratchPad.recorded.should == [:a, :b, :c, :d, :e, :f]
+ end
+
+ it 'evaluates expressions left to right when assignment with a nested #[]=' do
+ object = Object.new
+ def object.[]=(_, _) end
+ ScratchPad.record []
+
+ ((ScratchPad << :a; object)[(ScratchPad << :b; :b)], foo), bar = [(ScratchPad << :c; :c)]
+ ScratchPad.recorded.should == [:a, :b, :c]
+ end
+
+ it 'evaluates expressions left to right when assignment with a deeply nested #[]=' do
+ o = Object.new
+ def o.[]=(_, _) end
+ ScratchPad.record []
+
+ (ScratchPad << :ra; o)[(ScratchPad << :aa; :aa)],
+ ((ScratchPad << :rb; o)[(ScratchPad << :ab; :ab)],
+ ((ScratchPad << :rc; o)[(ScratchPad << :ac; :ac)], (ScratchPad << :rd; o)[(ScratchPad << :ad; :ad)]),
+ (ScratchPad << :re; o)[(ScratchPad << :ae; :ae)]),
+ (ScratchPad << :rf; o)[(ScratchPad << :af; :af)] = (ScratchPad << :value; :value)
+
+ ScratchPad.recorded.should == [:ra, :aa, :rb, :ab, :rc, :ac, :rd, :ad, :re, :ae, :rf, :af, :value]
+ end
+
+ it 'evaluates expressions left to right when assignment with compounded constant' do
+ m = Module.new
+ ScratchPad.record []
+
+ (ScratchPad << :a; m)::A, (ScratchPad << :b; m)::B = (ScratchPad << :c; :c), (ScratchPad << :d; :d)
+ ScratchPad.recorded.should == [:a, :b, :c, :d]
+ end
+
+ it 'evaluates expressions left to right when assignment with a nested compounded constant' do
+ m = Module.new
+ ScratchPad.record []
+
+ ((ScratchPad << :a; m)::A, foo), bar = [(ScratchPad << :b; :b)]
+ ScratchPad.recorded.should == [:a, :b]
+ end
+
+ it 'evaluates expressions left to right when assignment with deeply nested compounded constants' do
+ m = Module.new
+ ScratchPad.record []
+
+ (ScratchPad << :a; m)::A,
+ ((ScratchPad << :b; m)::B,
+ ((ScratchPad << :c; m)::C, (ScratchPad << :d; m)::D),
+ (ScratchPad << :e; m)::E),
+ (ScratchPad << :f; m)::F = (ScratchPad << :value; :value)
+
+ ScratchPad.recorded.should == [:a, :b, :c, :d, :e, :f, :value]
+ end
+ end
+
+ context 'when assignment with method call and receiver is self' do
+ it 'assigns values correctly when assignment with accessor' do
+ object = Object.new
+ class << object
+ attr_accessor :a, :b
+
+ def assign(v1, v2)
+ self.a, self.b = v1, v2
+ end
+ end
+
+ object.assign :v1, :v2
+ object.a.should == :v1
+ object.b.should == :v2
+ end
+
+ it 'evaluates expressions right to left when assignment with a nested accessor' do
+ object = Object.new
+ class << object
+ attr_accessor :a, :b
+
+ def assign(v1, v2)
+ (self.a, self.b), c = [v1, v2], nil
+ end
+ end
+
+ object.assign :v1, :v2
+ object.a.should == :v1
+ object.b.should == :v2
+ end
+
+ it 'assigns values correctly when assignment with a #[]=' do
+ object = Object.new
+ class << object
+ def []=(key, v)
+ @h ||= {}
+ @h[key] = v
+ end
+
+ def [](key)
+ (@h || {})[key]
+ end
+
+ def assign(k1, v1, k2, v2)
+ self[k1], self[k2] = v1, v2
+ end
+ end
+
+ object.assign :k1, :v1, :k2, :v2
+ object[:k1].should == :v1
+ object[:k2].should == :v2
+ end
+
+ it 'assigns values correctly when assignment with a nested #[]=' do
+ object = Object.new
+ class << object
+ def []=(key, v)
+ @h ||= {}
+ @h[key] = v
+ end
+
+ def [](key)
+ (@h || {})[key]
+ end
+
+ def assign(k1, v1, k2, v2)
+ (self[k1], self[k2]), c = [v1, v2], nil
+ end
+ end
+
+ object.assign :k1, :v1, :k2, :v2
+ object[:k1].should == :v1
+ object[:k2].should == :v2
+ end
+
+ it 'assigns values correctly when assignment with compounded constant' do
+ m = Module.new
+ m.module_exec do
+ self::A, self::B = :v1, :v2
+ end
+
+ m::A.should == :v1
+ m::B.should == :v2
+ end
+
+ it 'assigns values correctly when assignment with a nested compounded constant' do
+ m = Module.new
+ m.module_exec do
+ (self::A, self::B), c = [:v1, :v2], nil
+ end
+
+ m::A.should == :v1
+ m::B.should == :v2
+ end
+ end
+end
diff --git a/spec/ruby/language/block_spec.rb b/spec/ruby/language/block_spec.rb
index 733e90211c..5bdb993aea 100644
--- a/spec/ruby/language/block_spec.rb
+++ b/spec/ruby/language/block_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/block', __FILE__)
+require_relative '../spec_helper'
+require_relative 'fixtures/block'
describe "A block yielded a single" do
before :all do
@@ -13,7 +13,7 @@ describe "A block yielded a single" do
it "receives the identical Array object" do
ary = [1, 2]
- m(ary) { |a| a }.should equal(ary)
+ m(ary) { |a| a }.should.equal?(ary)
end
it "assigns the Array to a single rest argument" do
@@ -36,89 +36,102 @@ describe "A block yielded a single" do
m([1, 2]) { |a=5, b=4, c=3| [a, b, c] }.should == [1, 2, 3]
end
- it "assgins elements to post arguments" do
+ it "assigns elements to post arguments" do
m([1, 2]) { |a=5, b, c, d| [a, b, c, d] }.should == [5, 1, 2, nil]
end
- it "assigns elements to required arguments when a keyword rest argument is present" do
- m([1, 2]) { |a, **k| [a, k] }.should == [1, {}]
+ it "assigns elements to pre arguments" do
+ m([1, 2]) { |a, b, c, d=5| [a, b, c, d] }.should == [1, 2, nil, 5]
end
- it "assigns elements to mixed argument types" do
- result = m([1, 2, 3, {x: 9}]) { |a, b=5, *c, d, e: 2, **k| [a, b, c, d, e, k] }
- result.should == [1, 2, [], 3, 2, {x: 9}]
+ it "assigns elements to pre and post arguments" do
+ m([1 ]) { |a, b=5, c=6, d, e| [a, b, c, d, e] }.should == [1, 5, 6, nil, nil]
+ m([1, 2 ]) { |a, b=5, c=6, d, e| [a, b, c, d, e] }.should == [1, 5, 6, 2, nil]
+ m([1, 2, 3 ]) { |a, b=5, c=6, d, e| [a, b, c, d, e] }.should == [1, 5, 6, 2, 3]
+ m([1, 2, 3, 4 ]) { |a, b=5, c=6, d, e| [a, b, c, d, e] }.should == [1, 2, 6, 3, 4]
+ m([1, 2, 3, 4, 5 ]) { |a, b=5, c=6, d, e| [a, b, c, d, e] }.should == [1, 2, 3, 4, 5]
+ m([1, 2, 3, 4, 5, 6]) { |a, b=5, c=6, d, e| [a, b, c, d, e] }.should == [1, 2, 3, 4, 5]
end
- it "assigns symbol keys from a Hash to keyword arguments" do
- result = m(["a" => 1, a: 10]) { |a=nil, **b| [a, b] }
- result.should == [{"a" => 1}, a: 10]
+ it "assigns elements to pre and post arguments when *rest is present" do
+ m([1 ]) { |a, b=5, c=6, *d, e, f| [a, b, c, d, e, f] }.should == [1, 5, 6, [], nil, nil]
+ m([1, 2 ]) { |a, b=5, c=6, *d, e, f| [a, b, c, d, e, f] }.should == [1, 5, 6, [], 2, nil]
+ m([1, 2, 3 ]) { |a, b=5, c=6, *d, e, f| [a, b, c, d, e, f] }.should == [1, 5, 6, [], 2, 3]
+ m([1, 2, 3, 4 ]) { |a, b=5, c=6, *d, e, f| [a, b, c, d, e, f] }.should == [1, 2, 6, [], 3, 4]
+ m([1, 2, 3, 4, 5 ]) { |a, b=5, c=6, *d, e, f| [a, b, c, d, e, f] }.should == [1, 2, 3, [], 4, 5]
+ m([1, 2, 3, 4, 5, 6]) { |a, b=5, c=6, *d, e, f| [a, b, c, d, e, f] }.should == [1, 2, 3, [4], 5, 6]
end
- it "assigns symbol keys from a Hash returned by #to_hash to keyword arguments" do
- obj = mock("coerce block keyword arguments")
- obj.should_receive(:to_hash).and_return({"a" => 1, b: 2})
+ it "does not autosplat single argument to required arguments when a keyword rest argument is present" do
+ m([1, 2]) { |a, **k| [a, k] }.should == [[1, 2], {}]
+ end
- result = m([obj]) { |a=nil, **b| [a, b] }
- result.should == [{"a" => 1}, b: 2]
+ it "does not autosplat single argument to required arguments when keyword arguments are present" do
+ m([1, 2]) { |a, b: :b, c: :c| [a, b, c] }.should == [[1, 2], :b, :c]
+ end
+
+ it "raises error when required keyword arguments are present" do
+ -> {
+ m([1, 2]) { |a, b:, c:| [a, b, c] }
+ }.should.raise(ArgumentError, "missing keywords: :b, :c")
+ end
+
+ it "assigns elements to mixed argument types" do
+ result = m([1, 2, 3, {x: 9}]) { |a, b=5, *c, d, e: 2, **k| [a, b, c, d, e, k] }
+ result.should == [1, 2, [3], {x: 9}, 2, {}]
end
- ruby_version_is "2.2.1" do # SEGV on MRI 2.2.0
- it "calls #to_hash on the argument but does not use the result when no keywords are present" do
+ it "does not treat final Hash as keyword arguments and does not autosplat" do
+ result = m(["a" => 1, a: 10]) { |a=nil, **b| [a, b] }
+ result.should == [[{"a" => 1, a: 10}], {}]
+ end
+
+ it "does not call #to_hash on final argument to get keyword arguments and does not autosplat" do
+ suppress_keyword_warning do
obj = mock("coerce block keyword arguments")
- obj.should_receive(:to_hash).and_return({"a" => 1, "b" => 2})
+ obj.should_not_receive(:to_hash)
result = m([obj]) { |a=nil, **b| [a, b] }
- result.should == [{"a" => 1, "b" => 2}, {}]
+ result.should == [[obj], {}]
end
end
- it "assigns non-symbol keys to non-keyword arguments" do
- result = m(["a" => 10, b: 2]) { |a=nil, **b| [a, b] }
- result.should == [{"a" => 10}, {b: 2}]
- end
+ it "does not call #to_hash on the argument when optional argument and keyword argument accepted and does not autosplat" do
+ obj = mock("coerce block keyword arguments")
+ obj.should_not_receive(:to_hash)
- it "does not treat hashes with string keys as keyword arguments" do
- result = m(["a" => 10]) { |a = nil, **b| [a, b] }
- result.should == [{"a" => 10}, {}]
+ result = m([obj]) { |a=nil, **b| [a, b] }
+ result.should == [[obj], {}]
end
- it "calls #to_hash on the last element if keyword arguments are present" do
- obj = mock("destructure block keyword arguments")
- obj.should_receive(:to_hash).and_return({x: 9})
+ describe "when non-symbol keys are in a keyword arguments Hash" do
+ it "does not separate non-symbol keys and symbol keys and does not autosplat" do
+ suppress_keyword_warning do
+ result = m(["a" => 10, b: 2]) { |a=nil, **b| [a, b] }
+ result.should == [[{"a" => 10, b: 2}], {}]
+ end
+ end
+ end
- result = m([1, 2, 3, obj]) { |a, *b, c, **k| [a, b, c, k] }
- result.should == [1, [2], 3, {x: 9}]
+ it "does not treat hashes with string keys as keyword arguments and does not autosplat" do
+ result = m(["a" => 10]) { |a = nil, **b| [a, b] }
+ result.should == [[{"a" => 10}], {}]
end
- it "assigns the last element to a non-keyword argument if #to_hash returns nil" do
+ it "does not call #to_hash on the last element if keyword arguments are present" do
obj = mock("destructure block keyword arguments")
- obj.should_receive(:to_hash).and_return(nil)
+ obj.should_not_receive(:to_hash)
result = m([1, 2, 3, obj]) { |a, *b, c, **k| [a, b, c, k] }
result.should == [1, [2, 3], obj, {}]
end
- it "calls #to_hash on the last element when there are more arguments than parameters" do
+ it "does not call #to_hash on the last element when there are more arguments than parameters" do
x = mock("destructure matching block keyword argument")
- x.should_receive(:to_hash).and_return({x: 9})
+ x.should_not_receive(:to_hash)
result = m([1, 2, 3, {y: 9}, 4, 5, x]) { |a, b=5, c, **k| [a, b, c, k] }
- result.should == [1, 2, 3, {x: 9}]
- end
-
- it "raises a TypeError if #to_hash does not return a Hash" do
- obj = mock("destructure block keyword arguments")
- obj.should_receive(:to_hash).and_return(1)
-
- lambda { m([1, 2, 3, obj]) { |a, *b, c, **k| } }.should raise_error(TypeError)
- end
-
- it "raises the error raised inside #to_hash" do
- obj = mock("destructure block keyword arguments")
- error = RuntimeError.new("error while converting to a hash")
- obj.should_receive(:to_hash).and_raise(error)
-
- lambda { m([1, 2, 3, obj]) { |a, *b, c, **k| } }.should raise_error(error)
+ result.should == [1, 2, 3, {}]
end
it "does not call #to_ary on the Array" do
@@ -165,11 +178,70 @@ describe "A block yielded a single" do
m(obj) { |a, b, c| [a, b, c] }.should == [obj, nil, nil]
end
+ it "receives the object if it does not respond to #to_ary" do
+ obj = Object.new
+
+ m(obj) { |a, b, c| [a, b, c] }.should == [obj, nil, nil]
+ end
+
+ it "calls #respond_to? to check if object has method #to_ary" do
+ obj = mock("destructure block arguments")
+ obj.should_receive(:respond_to?).with(:to_ary, true).and_return(true)
+ obj.should_receive(:to_ary).and_return([1, 2])
+
+ m(obj) { |a, b, c| [a, b, c] }.should == [1, 2, nil]
+ end
+
+ it "calls #respond_to? on a BasicObject to check if object has method #to_ary" do
+ ScratchPad.record []
+ obj = BasicObject.new
+ def obj.respond_to?(name, *)
+ ScratchPad << [:respond_to?, name]
+ name == :to_ary ? true : super
+ end
+ def obj.to_ary
+ ScratchPad << :to_ary
+ [1, 2]
+ end
+
+ m(obj) { |a, b, c| [a, b, c] }.should == [1, 2, nil]
+ ScratchPad.recorded.should == [[:respond_to?, :to_ary], :to_ary]
+ end
+
+ it "receives the object if it does not respond to #respond_to?" do
+ obj = BasicObject.new
+
+ m(obj) { |a, b, c| [a, b, c] }.should == [obj, nil, nil]
+ end
+
+ it "calls #to_ary on the object when it is defined dynamically" do
+ obj = Object.new
+ def obj.method_missing(name, *args, &block)
+ if name == :to_ary
+ [1, 2]
+ else
+ super
+ end
+ end
+ def obj.respond_to_missing?(name, include_private)
+ name == :to_ary
+ end
+
+ m(obj) { |a, b, c| [a, b, c] }.should == [1, 2, nil]
+ end
+
it "raises a TypeError if #to_ary does not return an Array" do
obj = mock("destructure block arguments")
obj.should_receive(:to_ary).and_return(1)
- lambda { m(obj) { |a, b| } }.should raise_error(TypeError)
+ -> { m(obj) { |a, b| } }.should.raise(TypeError)
+ end
+
+ it "raises error transparently if #to_ary raises error on its own" do
+ obj = Object.new
+ def obj.to_ary; raise "Exception raised in #to_ary" end
+
+ -> { m(obj) { |a, b| } }.should.raise(RuntimeError, "Exception raised in #to_ary")
end
end
end
@@ -217,6 +289,10 @@ describe "A block" do
it "does not raise an exception when values are yielded" do
@y.s(0) { 1 }.should == 1
end
+
+ it "may include a rescue clause" do
+ @y.z do raise ArgumentError; rescue ArgumentError; 7; end.should == 7
+ end
end
describe "taking || arguments" do
@@ -227,11 +303,15 @@ describe "A block" do
it "does not raise an exception when values are yielded" do
@y.s(0) { || 1 }.should == 1
end
+
+ it "may include a rescue clause" do
+ @y.z do || raise ArgumentError; rescue ArgumentError; 7; end.should == 7
+ end
end
describe "taking |a| arguments" do
it "assigns nil to the argument when no values are yielded" do
- @y.z { |a| a }.should be_nil
+ @y.z { |a| a }.should == nil
end
it "assigns the value yielded to the argument" do
@@ -242,7 +322,7 @@ describe "A block" do
obj = mock("block yield to_ary")
obj.should_not_receive(:to_ary)
- @y.s(obj) { |a| a }.should equal(obj)
+ @y.s(obj) { |a| a }.should.equal?(obj)
end
it "assigns the first value yielded to the argument" do
@@ -252,10 +332,14 @@ describe "A block" do
it "does not destructure a single Array value" do
@y.s([1, 2]) { |a| a }.should == [1, 2]
end
+
+ it "may include a rescue clause" do
+ @y.s(1) do |x| raise ArgumentError; rescue ArgumentError; 7; end.should == 7
+ end
end
describe "taking |a, b| arguments" do
- it "assgins nil to the arguments when no values are yielded" do
+ it "assigns nil to the arguments when no values are yielded" do
@y.z { |a, b| [a, b] }.should == [nil, nil]
end
@@ -314,16 +398,15 @@ describe "A block" do
obj = mock("block yield to_ary invalid")
obj.should_receive(:to_ary).and_return(1)
- lambda { @y.s(obj) { |a, b| } }.should raise_error(TypeError)
+ -> { @y.s(obj) { |a, b| } }.should.raise(TypeError)
end
it "raises the original exception if #to_ary raises an exception" do
obj = mock("block yield to_ary raising an exception")
obj.should_receive(:to_ary).and_raise(ZeroDivisionError)
- lambda { @y.s(obj) { |a, b| } }.should raise_error(ZeroDivisionError)
+ -> { @y.s(obj) { |a, b| } }.should.raise(ZeroDivisionError)
end
-
end
describe "taking |a, *b| arguments" do
@@ -378,7 +461,7 @@ describe "A block" do
obj = mock("block yield to_ary invalid")
obj.should_receive(:to_ary).and_return(1)
- lambda { @y.s(obj) { |a, *b| } }.should raise_error(TypeError)
+ -> { @y.s(obj) { |a, *b| } }.should.raise(TypeError)
end
end
@@ -456,10 +539,10 @@ describe "A block" do
describe "taking |a, | arguments" do
it "assigns nil to the argument when no values are yielded" do
- @y.z { |a, | a }.should be_nil
+ @y.z { |a, | a }.should == nil
end
- it "assgins the argument a single value yielded" do
+ it "assigns the argument a single value yielded" do
@y.s(1) { |a, | a }.should == 1
end
@@ -472,7 +555,7 @@ describe "A block" do
end
it "assigns nil to the argument when passed an empty Array" do
- @y.s([]) { |a, | a }.should be_nil
+ @y.s([]) { |a, | a }.should == nil
end
it "assigns the argument the first element of the Array when passed a single Array" do
@@ -503,7 +586,7 @@ describe "A block" do
obj = mock("block yield to_ary invalid")
obj.should_receive(:to_ary).and_return(1)
- lambda { @y.s(obj) { |a, | } }.should raise_error(TypeError)
+ -> { @y.s(obj) { |a, | } }.should.raise(TypeError)
end
end
@@ -545,7 +628,7 @@ describe "A block" do
obj = mock("block yield to_ary invalid")
obj.should_receive(:to_ary).and_return(1)
- lambda { @y.s(obj) { |(a, b)| } }.should raise_error(TypeError)
+ -> { @y.s(obj) { |(a, b)| } }.should.raise(TypeError)
end
end
@@ -586,7 +669,7 @@ describe "A block" do
obj = mock("block yield to_ary invalid")
obj.should_receive(:to_ary).and_return(1)
- lambda { @y.s(obj) { |(a, b), c| } }.should raise_error(TypeError)
+ -> { @y.s(obj) { |(a, b), c| } }.should.raise(TypeError)
end
end
@@ -626,6 +709,12 @@ describe "A block" do
end
end
+ describe "taking |*a, b:|" do
+ it "merges the hash into the splatted array" do
+ @y.k { |*a, b:| [a, b] }.should == [[], true]
+ end
+ end
+
describe "arguments with _" do
it "extracts arguments with _" do
@y.m([[1, 2, 3], 4]) { |(_, a, _), _| a }.should == 2
@@ -639,15 +728,51 @@ describe "A block" do
describe "taking identically-named arguments" do
it "raises a SyntaxError for standard arguments" do
- lambda { eval "lambda { |x,x| }" }.should raise_error(SyntaxError)
- lambda { eval "->(x,x) {}" }.should raise_error(SyntaxError)
- lambda { eval "Proc.new { |x,x| }" }.should raise_error(SyntaxError)
+ -> { eval "lambda { |x,x| }" }.should.raise(SyntaxError)
+ -> { eval "->(x,x) {}" }.should.raise(SyntaxError)
+ -> { eval "Proc.new { |x,x| }" }.should.raise(SyntaxError)
end
it "accepts unnamed arguments" do
- eval("lambda { |_,_| }").should be_an_instance_of(Proc)
- eval("->(_,_) {}").should be_an_instance_of(Proc)
- eval("Proc.new { |_,_| }").should be_an_instance_of(Proc)
+ lambda { |_,_| }.should.instance_of?(Proc) # rubocop:disable Style/Lambda
+ -> _,_ {}.should.instance_of?(Proc)
+ Proc.new { |_,_| }.should.instance_of?(Proc)
+ end
+ end
+
+ describe 'pre and post parameters' do
+ it "assigns nil to unassigned required arguments" do
+ proc { |a, *b, c, d| [a, b, c, d] }.call(1, 2).should == [1, [], 2, nil]
+ end
+
+ it "assigns elements to optional arguments" do
+ proc { |a=5, b=4, c=3| [a, b, c] }.call(1, 2).should == [1, 2, 3]
+ end
+
+ it "assigns elements to post arguments" do
+ proc { |a=5, b, c, d| [a, b, c, d] }.call(1, 2).should == [5, 1, 2, nil]
+ end
+
+ it "assigns elements to pre arguments" do
+ proc { |a, b, c, d=5| [a, b, c, d] }.call(1, 2).should == [1, 2, nil, 5]
+ end
+
+ it "assigns elements to pre and post arguments" do
+ proc { |a, b=5, c=6, d, e| [a, b, c, d, e] }.call(1 ).should == [1, 5, 6, nil, nil]
+ proc { |a, b=5, c=6, d, e| [a, b, c, d, e] }.call(1, 2 ).should == [1, 5, 6, 2, nil]
+ proc { |a, b=5, c=6, d, e| [a, b, c, d, e] }.call(1, 2, 3 ).should == [1, 5, 6, 2, 3]
+ proc { |a, b=5, c=6, d, e| [a, b, c, d, e] }.call(1, 2, 3, 4 ).should == [1, 2, 6, 3, 4]
+ proc { |a, b=5, c=6, d, e| [a, b, c, d, e] }.call(1, 2, 3, 4, 5 ).should == [1, 2, 3, 4, 5]
+ proc { |a, b=5, c=6, d, e| [a, b, c, d, e] }.call(1, 2, 3, 4, 5, 6).should == [1, 2, 3, 4, 5]
+ end
+
+ it "assigns elements to pre and post arguments when *rest is present" do
+ proc { |a, b=5, c=6, *d, e, f| [a, b, c, d, e, f] }.call(1 ).should == [1, 5, 6, [], nil, nil]
+ proc { |a, b=5, c=6, *d, e, f| [a, b, c, d, e, f] }.call(1, 2 ).should == [1, 5, 6, [], 2, nil]
+ proc { |a, b=5, c=6, *d, e, f| [a, b, c, d, e, f] }.call(1, 2, 3 ).should == [1, 5, 6, [], 2, 3]
+ proc { |a, b=5, c=6, *d, e, f| [a, b, c, d, e, f] }.call(1, 2, 3, 4 ).should == [1, 2, 6, [], 3, 4]
+ proc { |a, b=5, c=6, *d, e, f| [a, b, c, d, e, f] }.call(1, 2, 3, 4, 5 ).should == [1, 2, 3, [], 4, 5]
+ proc { |a, b=5, c=6, *d, e, f| [a, b, c, d, e, f] }.call(1, 2, 3, 4, 5, 6).should == [1, 2, 3, [4], 5, 6]
end
end
end
@@ -662,29 +787,29 @@ describe "Block-local variables" do
end
it "can not have the same name as one of the standard parameters" do
- lambda { eval "[1].each {|foo; foo| }" }.should raise_error(SyntaxError)
- lambda { eval "[1].each {|foo, bar; glark, bar| }" }.should raise_error(SyntaxError)
+ -> { eval "[1].each {|foo; foo| }" }.should.raise(SyntaxError)
+ -> { eval "[1].each {|foo, bar; glark, bar| }" }.should.raise(SyntaxError)
end
it "can not be prefixed with an asterisk" do
- lambda { eval "[1].each {|foo; *bar| }" }.should raise_error(SyntaxError)
- lambda do
+ -> { eval "[1].each {|foo; *bar| }" }.should.raise(SyntaxError)
+ -> do
eval "[1].each {|foo, bar; glark, *fnord| }"
- end.should raise_error(SyntaxError)
+ end.should.raise(SyntaxError)
end
it "can not be prefixed with an ampersand" do
- lambda { eval "[1].each {|foo; &bar| }" }.should raise_error(SyntaxError)
- lambda do
+ -> { eval "[1].each {|foo; &bar| }" }.should.raise(SyntaxError)
+ -> do
eval "[1].each {|foo, bar; glark, &fnord| }"
- end.should raise_error(SyntaxError)
+ end.should.raise(SyntaxError)
end
it "can not be assigned default values" do
- lambda { eval "[1].each {|foo; bar=1| }" }.should raise_error(SyntaxError)
- lambda do
+ -> { eval "[1].each {|foo; bar=1| }" }.should.raise(SyntaxError)
+ -> do
eval "[1].each {|foo, bar; glark, fnord=:fnord| }"
- end.should raise_error(SyntaxError)
+ end.should.raise(SyntaxError)
end
it "need not be preceded by standard parameters" do
@@ -693,8 +818,8 @@ describe "Block-local variables" do
end
it "only allow a single semi-colon in the parameter list" do
- lambda { eval "[1].each {|foo; bar; glark| }" }.should raise_error(SyntaxError)
- lambda { eval "[1].each {|; bar; glark| }" }.should raise_error(SyntaxError)
+ -> { eval "[1].each {|foo; bar; glark| }" }.should.raise(SyntaxError)
+ -> { eval "[1].each {|; bar; glark| }" }.should.raise(SyntaxError)
end
it "override shadowed variables from the outer scope" do
@@ -719,21 +844,21 @@ describe "Block-local variables" do
end
it "are not automatically instantiated in the outer scope" do
- defined?(glark).should be_nil
+ defined?(glark).should == nil
[1].each {|;glark| 1}
- defined?(glark).should be_nil
+ defined?(glark).should == nil
end
it "are automatically instantiated in the block" do
[1].each do |;glark|
- glark.should be_nil
+ glark.should == nil
end
end
it "are visible in deeper scopes before initialization" do
[1].each {|;glark|
[1].each {
- defined?(glark).should_not be_nil
+ defined?(glark).should_not == nil
glark = 1
}
glark.should == 1
@@ -756,12 +881,18 @@ describe "Post-args" do
end.call(1, 2, 3).should == [[], 1, 2, 3]
end
- it "are required" do
- lambda {
- lambda do |*a, b|
+ it "are required for a lambda" do
+ -> {
+ -> *a, b do
[a, b]
end.call
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
+ end
+
+ it "are assigned to nil when not enough arguments are given to a proc" do
+ proc do |a, *b, c|
+ [a, b, c]
+ end.call.should == [nil, [], nil]
end
describe "with required args" do
@@ -826,26 +957,27 @@ describe "Post-args" do
end
describe "with a circular argument reference" do
- it "shadows an existing local with the same name as the argument" do
- a = 1
- -> {
- @proc = eval "proc { |a=a| a }"
- }.should complain(/circular argument reference/)
- @proc.call.should == nil
+ ruby_version_is ""..."3.4" do
+ it "raises a SyntaxError if using the argument in its default value" do
+ a = 1
+ -> {
+ eval "proc { |a=a| a }"
+ }.should.raise(SyntaxError)
+ end
end
- it "shadows an existing method with the same name as the argument" do
- def a; 1; end
- -> {
- @proc = eval "proc { |a=a| a }"
- }.should complain(/circular argument reference/)
- @proc.call.should == nil
+ ruby_version_is "3.4" do
+ it "is nil if using the argument in its default value" do
+ -> {
+ eval "proc { |a=a| a }.call"
+ }.call.should == nil
+ end
end
+ end
- it "calls an existing method with the same name as the argument if explicitly using ()" do
- def a; 1; end
- proc { |a=a()| a }.call.should == 1
- end
+ it "calls an existing method with the same name as the argument if explicitly using ()" do
+ def a; 1; end
+ proc { |a=a()| a }.call.should == 1
end
end
@@ -863,3 +995,154 @@ describe "Post-args" do
end
end
end
+
+# tested more thoroughly in language/delegation_spec.rb
+describe "Anonymous block forwarding" do
+ it "forwards blocks to other method that formally declares anonymous block" do
+ def b(&); c(&) end
+ def c(&); yield :non_null end
+
+ b { |c| c }.should == :non_null
+ end
+
+ it "requires the anonymous block parameter to be declared if directly passing a block" do
+ -> { eval "def a; b(&); end; def b; end" }.should.raise(SyntaxError)
+ end
+
+ it "works when it's the only declared parameter" do
+ def inner; yield end
+ def block_only(&); inner(&) end
+
+ block_only { 1 }.should == 1
+ end
+
+ it "works alongside positional parameters" do
+ def inner; yield end
+ def pos(arg1, &); inner(&) end
+
+ pos(:a) { 1 }.should == 1
+ end
+
+ it "works alongside positional arguments and splatted keyword arguments" do
+ def inner; yield end
+ def pos_kwrest(arg1, **kw, &); inner(&) end
+
+ pos_kwrest(:a, arg: 3) { 1 }.should == 1
+ end
+
+ it "works alongside positional arguments and disallowed keyword arguments" do
+ def inner; yield end
+ def no_kw(arg1, **nil, &); inner(&) end
+
+ no_kw(:a) { 1 }.should == 1
+ end
+
+ it "works alongside explicit keyword arguments" do
+ eval <<-EOF
+ def inner; yield end
+ def rest_kw(*a, kwarg: 1, &); inner(&) end
+ def kw(kwarg: 1, &); inner(&) end
+ def pos_kw_kwrest(arg1, kwarg: 1, **kw, &); inner(&) end
+ def pos_rkw(arg1, kwarg1:, &); inner(&) end
+ def all(arg1, arg2, *rest, post1, post2, kw1: 1, kw2: 2, okw1:, okw2:, &); inner(&) end
+ def all_kwrest(arg1, arg2, *rest, post1, post2, kw1: 1, kw2: 2, okw1:, okw2:, **kw, &); inner(&) end
+ EOF
+
+ rest_kw { 1 }.should == 1
+ kw { 1 }.should == 1
+ pos_kw_kwrest(:a) { 1 }.should == 1
+ pos_rkw(:a, kwarg1: 3) { 1 }.should == 1
+ all(:a, :b, :c, :d, :e, okw1: 'x', okw2: 'y') { 1 }.should == 1
+ all_kwrest(:a, :b, :c, :d, :e, okw1: 'x', okw2: 'y') { 1 }.should == 1
+ end
+end
+
+describe "`it` calls without arguments in a block" do
+ ruby_version_is ""..."3.4" do
+ it "emits a deprecation warning" do
+ -> {
+ eval "proc { it }"
+ }.should complain(/warning: `it` calls without arguments will refer to the first block param in Ruby 3.4; use it\(\) or self.it/)
+ end
+
+ it "emits a deprecation warning if numbered parameters are used" do
+ -> {
+ eval "proc { it; _1 }"
+ }.should complain(/warning: `it` calls without arguments will refer to the first block param in Ruby 3.4; use it\(\) or self.it/)
+ end
+
+ it "does not emit a deprecation warning when a block has parameters" do
+ -> { eval "proc { |a, b| it }" }.should_not complain
+ -> { eval "proc { |*rest| it }" }.should_not complain
+ -> { eval "proc { |*| it }" }.should_not complain
+ -> { eval "proc { |a:, b:| it }" }.should_not complain
+ -> { eval "proc { |**kw| it }" }.should_not complain
+ -> { eval "proc { |**| it }" }.should_not complain
+ -> { eval "proc { |&block| it }" }.should_not complain
+ -> { eval "proc { |&| it }" }.should_not complain
+ -> { eval "proc { || it }" }.should_not complain
+ end
+
+ it "does not emit a deprecation warning when `it` calls with arguments" do
+ -> { eval "proc { it(42) }" }.should_not complain
+ -> { eval "proc { it 42 }" }.should_not complain
+ end
+
+ it "does not emit a deprecation warning when `it` calls with a block" do
+ -> { eval "proc { it {} }" }.should_not complain
+ end
+
+ it "does not emit a deprecation warning when a local variable inside the block named `it` exists" do
+ -> { eval "proc { it = 42; it }" }.should_not complain
+ end
+
+ it "does not emit a deprecation warning when `it` calls with explicit empty arguments list" do
+ -> { eval "proc { it() }" }.should_not complain
+ end
+
+ it "calls the method `it` if defined" do
+ o = Object.new
+ def o.it
+ 21
+ end
+ suppress_warning do
+ o.instance_eval("proc { it * 2 }").call(1).should == 42
+ end
+ end
+ end
+
+ ruby_version_is "4.1" do
+ it "works alongside disallowed block argument" do
+ no_block = eval <<-EOF
+ proc {|arg1, &nil| arg1}
+ EOF
+
+ no_block.call(:a).should == :a
+ -> { no_block.call(:a) {} }.should.raise(ArgumentError, 'no block accepted')
+ end
+ end
+end
+
+# Duplicates specs in language/it_parameter_spec.rb
+# Need them here to run on Ruby versions prior 3.4
+# TODO: remove when the minimal supported Ruby version is 3.4
+describe "if `it` is defined as a variable" do
+ it "treats `it` as a captured variable if defined outside of a block" do
+ it = 5
+ proc { it }.call(0).should == 5
+ end
+
+ it "treats `it` as a local variable if defined inside of a block" do
+ proc { it = 5; it }.call(0).should == 5
+ end
+end
+
+describe "Block-parameter destructuring" do
+ it "does not warn about unused inner names in verbose mode" do
+ -> {
+ eval <<~RUBY, binding, __FILE__, __LINE__ + 1
+ proc { |key, (val1, val2)| [key, val2] }
+ RUBY
+ }.should_not complain(verbose: true)
+ end
+end
diff --git a/spec/ruby/language/break_spec.rb b/spec/ruby/language/break_spec.rb
index da3c3bd272..5c9b8060c3 100644
--- a/spec/ruby/language/break_spec.rb
+++ b/spec/ruby/language/break_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/break', __FILE__)
+require_relative '../spec_helper'
+require_relative 'fixtures/break'
describe "The break statement in a block" do
before :each do
@@ -24,6 +24,24 @@ describe "The break statement in a block" do
value.should == :value
end
end
+
+ describe "captured and delegated to another method repeatedly" do
+ it "breaks out of the block" do
+ @program.looped_break_in_captured_block
+ ScratchPad.recorded.should == [:begin,
+ :preloop,
+ :predele,
+ :preyield,
+ :prebreak,
+ :postbreak,
+ :postyield,
+ :postdele,
+ :predele,
+ :preyield,
+ :prebreak,
+ :end]
+ end
+ end
end
describe "The break statement in a captured block" do
@@ -34,29 +52,29 @@ describe "The break statement in a captured block" do
describe "when the invocation of the scope creating the block is still active" do
it "raises a LocalJumpError when invoking the block from the scope creating the block" do
- lambda { @program.break_in_method }.should raise_error(LocalJumpError)
+ -> { @program.break_in_method }.should.raise(LocalJumpError)
ScratchPad.recorded.should == [:a, :xa, :d, :b]
end
it "raises a LocalJumpError when invoking the block from a method" do
- lambda { @program.break_in_nested_method }.should raise_error(LocalJumpError)
+ -> { @program.break_in_nested_method }.should.raise(LocalJumpError)
ScratchPad.recorded.should == [:a, :xa, :cc, :aa, :b]
end
it "raises a LocalJumpError when yielding to the block" do
- lambda { @program.break_in_yielding_method }.should raise_error(LocalJumpError)
+ -> { @program.break_in_yielding_method }.should.raise(LocalJumpError)
ScratchPad.recorded.should == [:a, :xa, :cc, :aa, :b]
end
end
describe "from a scope that has returned" do
it "raises a LocalJumpError when calling the block from a method" do
- lambda { @program.break_in_method_captured }.should raise_error(LocalJumpError)
+ -> { @program.break_in_method_captured }.should.raise(LocalJumpError)
ScratchPad.recorded.should == [:a, :za, :xa, :zd, :zb]
end
it "raises a LocalJumpError when yielding to the block" do
- lambda { @program.break_in_yield_captured }.should raise_error(LocalJumpError)
+ -> { @program.break_in_yield_captured }.should.raise(LocalJumpError)
ScratchPad.recorded.should == [:a, :za, :xa, :zd, :aa, :zb]
end
end
@@ -70,7 +88,7 @@ describe "The break statement in a captured block" do
e
end
end
- thread_with_break.value.should be_an_instance_of(LocalJumpError)
+ thread_with_break.value.should.instance_of?(LocalJumpError)
end
end
end
@@ -82,7 +100,7 @@ describe "The break statement in a lambda" do
end
it "returns from the lambda" do
- l = lambda {
+ l = -> {
ScratchPad << :before
break :foo
ScratchPad << :after
@@ -93,7 +111,7 @@ describe "The break statement in a lambda" do
it "returns from the call site if the lambda is passed as a block" do
def mid(&b)
- lambda {
+ -> {
ScratchPad << :before
b.call
ScratchPad << :unreachable1
@@ -190,7 +208,7 @@ describe "Break inside a while loop" do
it "passes the value returned by a method with omitted parenthesis and passed block" do
obj = BreakSpecs::Block.new
- lambda { break obj.method :value do |x| x end }.call.should == :value
+ -> { break obj.method :value do |x| x end }.call.should == :value
end
end
@@ -234,6 +252,25 @@ describe "Break inside a while loop" do
end
end
+describe "The break statement in a method" do
+ it "is invalid and raises a SyntaxError" do
+ -> {
+ eval("def m; break; end")
+ }.should.raise(SyntaxError)
+ end
+end
+
+describe "The break statement in a module literal" do
+ it "is invalid and raises a SyntaxError" do
+ code = <<~RUBY
+ module BreakSpecs:ModuleWithBreak
+ break
+ end
+ RUBY
+
+ -> { eval(code) }.should.raise(SyntaxError)
+ end
+end
# TODO: Rewrite all the specs from here to the end of the file in the style
# above.
@@ -344,4 +381,22 @@ describe "Executing break from within a block" do
bt2.three
ScratchPad.recorded.should == [:two_ensure, :three_post, :three_ensure]
end
+
+ it "works when passing through a super call" do
+ cls1 = Class.new { def foo; yield; end }
+ cls2 = Class.new(cls1) { def foo; super { break 1 }; end }
+
+ -> do
+ cls2.new.foo.should == 1
+ end.should_not.raise
+ end
+
+ it "raises LocalJumpError when converted into a proc during a super call" do
+ cls1 = Class.new { def foo(&b); b; end }
+ cls2 = Class.new(cls1) { def foo; super { break 1 }.call; end }
+
+ -> do
+ cls2.new.foo
+ end.should.raise(LocalJumpError)
+ end
end
diff --git a/spec/ruby/language/case_spec.rb b/spec/ruby/language/case_spec.rb
index 25f5d0efc4..41881bf20a 100644
--- a/spec/ruby/language/case_spec.rb
+++ b/spec/ruby/language/case_spec.rb
@@ -1,17 +1,17 @@
-require File.expand_path('../../spec_helper', __FILE__)
+require_relative '../spec_helper'
describe "The 'case'-construct" do
it "evaluates the body of the when clause matching the case target expression" do
case 1
- when 2; false
- when 1; true
+ when 2; false
+ when 1; true
end.should == true
end
it "evaluates the body of the when clause whose array expression includes the case target expression" do
case 2
- when 3, 4; false
- when 1, 2; true
+ when 3, 4; false
+ when 1, 2; true
end.should == true
end
@@ -21,39 +21,74 @@ describe "The 'case'-construct" do
def bar; @calls << :bar; end
case true
- when foo, bar;
+ when foo, bar;
end
@calls.should == [:foo, :bar]
end
+ it "matches an Integer literal whose value does not fit in a 32-bit int" do
+ big = 10_000_000_000
+ case big
+ when 10_000_000_000; true
+ else false
+ end.should == true
+
+ case -3_000_000_000
+ when -3_000_000_000; true
+ else false
+ end.should == true
+ end
+
+ it "matches an arbitrary-precision Integer literal" do
+ huge = 1267650600228229401496703205376
+ case huge
+ when 1267650600228229401496703205376; true
+ else false
+ end.should == true
+ end
+
+ it "dispatches correctly with mixed small and large Integer literals" do
+ pick = -> x {
+ case x
+ when 1267650600228229401496703205376 then :beyond_long
+ when 10_000_000_000 then :beyond_int
+ when 1 then :fits_int
+ else :other
+ end
+ }
+
+ [1267650600228229401496703205376, 10_000_000_000, 1, :nope].map(&pick).should ==
+ [:beyond_long, :beyond_int, :fits_int, :other]
+ end
+
it "evaluates the body of the when clause whose range expression includes the case target expression" do
case 5
- when 21..30; false
- when 1..20; true
+ when 21..30; false
+ when 1..20; true
end.should == true
end
it "returns nil when no 'then'-bodies are given" do
case "a"
- when "a"
- when "b"
+ when "a"
+ when "b"
end.should == nil
end
it "evaluates the 'else'-body when no other expression matches" do
case "c"
- when "a"; 'foo'
- when "b"; 'bar'
- else 'zzz'
+ when "a"; 'foo'
+ when "b"; 'bar'
+ else 'zzz'
end.should == 'zzz'
end
it "returns nil when no expression matches and 'else'-body is empty" do
case "c"
- when "a"; "a"
- when "b"; "b"
- else
+ when "a"; "a"
+ when "b"; "b"
+ else
end.should == nil
end
@@ -70,105 +105,152 @@ describe "The 'case'-construct" do
it "returns the statement following 'then'" do
case "a"
- when "a" then 'foo'
- when "b" then 'bar'
+ when "a" then 'foo'
+ when "b" then 'bar'
end.should == 'foo'
end
it "tests classes with case equality" do
case "a"
- when String
- 'foo'
- when Symbol
- 'bar'
+ when String
+ 'foo'
+ when Symbol
+ 'bar'
end.should == 'foo'
end
it "tests with matching regexps" do
case "hello"
- when /abc/; false
- when /^hell/; true
+ when /abc/; false
+ when /^hell/; true
end.should == true
end
+ it "tests with matching regexps and sets $~ and captures" do
+ case "foo42"
+ when /oo(\d+)/
+ $~.should.is_a?(MatchData)
+ $1.should == "42"
+ else
+ flunk
+ end
+ $~.should.is_a?(MatchData)
+ $1.should == "42"
+ end
+
+ it "tests with a string interpolated in a regexp" do
+ digits = '\d+'
+ case "foo44"
+ when /oo(#{digits})/
+ $~.should.is_a?(MatchData)
+ $1.should == "44"
+ else
+ flunk
+ end
+ $~.should.is_a?(MatchData)
+ $1.should == "44"
+ end
+
+ it "tests with a regexp interpolated within another regexp" do
+ digits_regexp = /\d+/
+ case "foo43"
+ when /oo(#{digits_regexp})/
+ $~.should.is_a?(MatchData)
+ $1.should == "43"
+ else
+ flunk
+ end
+ $~.should.is_a?(MatchData)
+ $1.should == "43"
+ end
+
it "does not test with equality when given classes" do
case :symbol.class
- when Symbol
- "bar"
- when String
- "bar"
- else
- "foo"
+ when Symbol
+ "bar"
+ when String
+ "bar"
+ else
+ "foo"
end.should == "foo"
end
it "takes lists of values" do
case 'z'
- when 'a', 'b', 'c', 'd'
- "foo"
- when 'x', 'y', 'z'
- "bar"
+ when 'a', 'b', 'c', 'd'
+ "foo"
+ when 'x', 'y', 'z'
+ "bar"
end.should == "bar"
case 'b'
- when 'a', 'b', 'c', 'd'
- "foo"
- when 'x', 'y', 'z'
- "bar"
+ when 'a', 'b', 'c', 'd'
+ "foo"
+ when 'x', 'y', 'z'
+ "bar"
end.should == "foo"
end
+ it "tests an empty array" do
+ case []
+ when []
+ 'foo'
+ else
+ 'bar'
+ end.should == 'foo'
+ end
+
it "expands arrays to lists of values" do
case 'z'
- when *['a', 'b', 'c', 'd']
- "foo"
- when *['x', 'y', 'z']
- "bar"
+ when *['a', 'b', 'c', 'd']
+ "foo"
+ when *['x', 'y', 'z']
+ "bar"
end.should == "bar"
end
it "takes an expanded array in addition to a list of values" do
case 'f'
- when 'f', *['a', 'b', 'c', 'd']
- "foo"
- when *['x', 'y', 'z']
- "bar"
+ when 'f', *['a', 'b', 'c', 'd']
+ "foo"
+ when *['x', 'y', 'z']
+ "bar"
end.should == "foo"
case 'b'
- when 'f', *['a', 'b', 'c', 'd']
- "foo"
- when *['x', 'y', 'z']
- "bar"
+ when 'f', *['a', 'b', 'c', 'd']
+ "foo"
+ when *['x', 'y', 'z']
+ "bar"
end.should == "foo"
end
it "takes an expanded array before additional listed values" do
case 'f'
- when *['a', 'b', 'c', 'd'], 'f'
- "foo"
- when *['x', 'y', 'z']
- "bar"
+ when *['a', 'b', 'c', 'd'], 'f'
+ "foo"
+ when *['x', 'y', 'z']
+ "bar"
end.should == 'foo'
end
it "expands arrays from variables before additional listed values" do
a = ['a', 'b', 'c']
case 'a'
- when *a, 'd', 'e'
- "foo"
- when 'x'
- "bar"
+ when *a, 'd', 'e'
+ "foo"
+ when 'x'
+ "bar"
end.should == "foo"
end
it "expands arrays from variables before a single additional listed value" do
a = ['a', 'b', 'c']
case 'a'
- when *a, 'd'
- "foo"
- when 'x'
- "bar"
+ when *a, 'd'
+ "foo"
+ when 'x'
+ "bar"
end.should == "foo"
end
@@ -177,10 +259,10 @@ describe "The 'case'-construct" do
b = ['d', 'e', 'f']
case 'f'
- when *a, *b, 'g', 'h'
- "foo"
- when 'x'
- "bar"
+ when *a, *b, 'g', 'h'
+ "foo"
+ when 'x'
+ "bar"
end.should == "foo"
end
@@ -190,50 +272,50 @@ describe "The 'case'-construct" do
b = ['f']
case 'f'
- when 'f', *a|b
- "foo"
- when *['x', 'y', 'z']
- "bar"
+ when 'f', *a|b
+ "foo"
+ when *['x', 'y', 'z']
+ "bar"
end.should == "foo"
end
it "never matches when clauses with no values" do
case nil
- when *[]
- "foo"
+ when *[]
+ "foo"
end.should == nil
end
it "lets you define a method after the case statement" do
case (def foo; 'foo'; end; 'f')
- when 'a'
- 'foo'
- when 'f'
- 'bar'
+ when 'a'
+ 'foo'
+ when 'f'
+ 'bar'
end.should == 'bar'
end
it "raises a SyntaxError when 'else' is used when no 'when' is given" do
- lambda {
+ -> {
eval <<-CODE
case 4
- else
- true
+ else
+ true
end
CODE
- }.should raise_error(SyntaxError)
+ }.should.raise(SyntaxError)
end
it "raises a SyntaxError when 'else' is used before a 'when' was given" do
- lambda {
+ -> {
eval <<-CODE
case 4
- else
- true
- when 4; false
+ else
+ true
+ when 4; false
end
CODE
- }.should raise_error(SyntaxError)
+ }.should.raise(SyntaxError)
end
it "supports nested case statements" do
@@ -282,61 +364,18 @@ describe "The 'case'-construct" do
100
end.should == 100
end
-end
-
-describe "The 'case'-construct with no target expression" do
- it "evaluates the body of the first clause when at least one of its condition expressions is true" do
- case
- when true, false; 'foo'
- end.should == 'foo'
- end
-
- it "evaluates the body of the first when clause that is not false/nil" do
- case
- when false; 'foo'
- when 2; 'bar'
- when 1 == 1; 'baz'
- end.should == 'bar'
-
- case
- when false; 'foo'
- when nil; 'foo'
- when 1 == 1; 'bar'
- end.should == 'bar'
- end
-
- it "evaluates the body of the else clause if all when clauses are false/nil" do
- case
- when false; 'foo'
- when nil; 'foo'
- when 1 == 2; 'bar'
- else 'baz'
- end.should == 'baz'
- end
-
- it "evaluates multiple conditional expressions as a boolean disjunction" do
- case
- when true, false; 'foo'
- else 'bar'
- end.should == 'foo'
-
- case
- when false, true; 'foo'
- else 'bar'
- end.should == 'foo'
- end
it "evaluates true as only 'true' when true is the first clause" do
case 1
- when true; "bad"
- when Integer; "good"
+ when true; "bad"
+ when Integer; "good"
end.should == "good"
end
it "evaluates false as only 'false' when false is the first clause" do
case nil
- when false; "bad"
- when nil; "good"
+ when false; "bad"
+ when nil; "good"
end.should == "good"
end
@@ -352,17 +391,17 @@ describe "The 'case'-construct with no target expression" do
a2 = ['b', 'a', 'r']
case 'f'
- when *a1, *['x', 'y', 'z']
- "foo"
- when *a2, *['x', 'y', 'z']
- "bar"
+ when *a1, *['x', 'y', 'z']
+ "foo"
+ when *a2, *['x', 'y', 'z']
+ "bar"
end.should == "foo"
case 'b'
- when *a1, *['x', 'y', 'z']
- "foo"
- when *a2, *['x', 'y', 'z']
- "bar"
+ when *a1, *['x', 'y', 'z']
+ "foo"
+ when *a2, *['x', 'y', 'z']
+ "bar"
end.should == "bar"
end
@@ -386,4 +425,120 @@ describe "The 'case'-construct with no target expression" do
:called
end.should == :called
end
+
+ it "only matches last value in complex expressions within ()" do
+ case 'a'
+ when ('a'; 'b')
+ :wrong_called
+ when ('b'; 'a')
+ :called
+ end.should == :called
+ end
+
+ it "supports declaring variables in the case target expression" do
+ def test(v)
+ case new_variable_in_expression = v
+ when true
+ # This extra block is a test that `new_variable_in_expression` is declared outside of it and not inside
+ self.then { new_variable_in_expression }
+ else
+ # Same
+ self.then { new_variable_in_expression.casecmp?("foo") }
+ end
+ end
+
+ self.test("bar").should == false
+ self.test(true).should == true
+ end
+
+ ruby_version_is ""..."3.4" do
+ it "warns if there are identical when clauses" do
+ -> {
+ eval <<~RUBY
+ case 1
+ when 2
+ :foo
+ when 2
+ :bar
+ end
+ RUBY
+ }.should complain(/warning: (duplicated .when' clause with line \d+ is ignored|'when' clause on line \d+ duplicates 'when' clause on line \d+ and is ignored)/, verbose: true)
+ end
+ end
+
+ ruby_version_is "3.4" do
+ it "warns if there are identical when clauses" do
+ -> {
+ eval <<~RUBY
+ case 1
+ when 2
+ :foo
+ when 2
+ :bar
+ end
+ RUBY
+ }.should complain(/warning: 'when' clause on line \d+ duplicates 'when' clause on line \d+ and is ignored/, verbose: true)
+ end
+ end
+end
+
+describe "The 'case'-construct with no target expression" do
+ it "evaluates the body of the first clause when at least one of its condition expressions is true" do
+ case
+ when true, false; 'foo'
+ end.should == 'foo'
+ end
+
+ it "evaluates the body of the first when clause that is not false/nil" do
+ case
+ when false; 'foo'
+ when 2; 'bar'
+ when 1 == 1; 'baz'
+ end.should == 'bar'
+
+ case
+ when false; 'foo'
+ when nil; 'foo'
+ when 1 == 1; 'bar'
+ end.should == 'bar'
+ end
+
+ it "evaluates the body of the else clause if all when clauses are false/nil" do
+ case
+ when false; 'foo'
+ when nil; 'foo'
+ when 1 == 2; 'bar'
+ else 'baz'
+ end.should == 'baz'
+ end
+
+ it "evaluates multiple conditional expressions as a boolean disjunction" do
+ case
+ when true, false; 'foo'
+ else 'bar'
+ end.should == 'foo'
+
+ case
+ when false, true; 'foo'
+ else 'bar'
+ end.should == 'foo'
+ end
+
+ # Homogeneous cases are often optimized to avoid === using a jump table, and should be tested separately.
+ # See https://github.com/jruby/jruby/issues/6440
+ it "handles homogeneous cases" do
+ case
+ when 1; 'foo'
+ when 2; 'bar'
+ end.should == 'foo'
+ end
+
+ it "expands arrays to lists of values" do
+ case
+ when *[false]
+ "foo"
+ when *[true]
+ "bar"
+ end.should == "bar"
+ end
end
diff --git a/spec/ruby/language/class_spec.rb b/spec/ruby/language/class_spec.rb
index ba4af3d880..7ea4857514 100644
--- a/spec/ruby/language/class_spec.rb
+++ b/spec/ruby/language/class_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/class', __FILE__)
+require_relative '../spec_helper'
+require_relative '../fixtures/class'
ClassSpecsNumber = 12
@@ -10,21 +10,32 @@ end
describe "The class keyword" do
it "creates a new class with semicolon" do
class ClassSpecsKeywordWithSemicolon; end
- ClassSpecsKeywordWithSemicolon.should be_an_instance_of(Class)
+ ClassSpecsKeywordWithSemicolon.should.instance_of?(Class)
end
- ruby_version_is "2.3" do
- it "does not raise a SyntaxError when opening a class without a semicolon" do
- eval "class ClassSpecsKeywordWithoutSemicolon end"
- ClassSpecsKeywordWithoutSemicolon.should be_an_instance_of(Class)
- end
+ it "does not raise a SyntaxError when opening a class without a semicolon" do
+ eval "class ClassSpecsKeywordWithoutSemicolon end"
+ ClassSpecsKeywordWithoutSemicolon.should.instance_of?(Class)
+ end
+
+ it "can redefine a class when called from a block" do
+ ClassSpecs::DEFINE_CLASS.call
+ A.should.instance_of?(Class)
+
+ Object.send(:remove_const, :A)
+ defined?(A).should == nil
+
+ ClassSpecs::DEFINE_CLASS.call
+ A.should.instance_of?(Class)
+ ensure
+ Object.send(:remove_const, :A) if defined?(::A)
end
end
describe "A class definition" do
it "creates a new class" do
- ClassSpecs::A.should be_kind_of(Class)
- ClassSpecs::A.new.should be_kind_of(ClassSpecs::A)
+ ClassSpecs::A.should.is_a?(Class)
+ ClassSpecs::A.new.should.is_a?(ClassSpecs::A)
end
it "has no class variables" do
@@ -32,30 +43,37 @@ describe "A class definition" do
end
it "raises TypeError if constant given as class name exists and is not a Module" do
- lambda {
+ -> {
class ClassSpecsNumber
end
- }.should raise_error(TypeError)
+ }.should.raise(TypeError, /\AClassSpecsNumber is not a class/)
+ end
+
+ it "raises TypeError if constant given as class name exists and is a Module but not a Class" do
+ -> {
+ class ClassSpecs
+ end
+ }.should.raise(TypeError, /\AClassSpecs is not a class/)
end
# test case known to be detecting bugs (JRuby, MRI)
it "raises TypeError if the constant qualifying the class is nil" do
- lambda {
+ -> {
class nil::Foo
end
- }.should raise_error(TypeError)
+ }.should.raise(TypeError)
end
it "raises TypeError if any constant qualifying the class is not a Module" do
- lambda {
+ -> {
class ClassSpecs::Number::MyClass
end
- }.should raise_error(TypeError)
+ }.should.raise(TypeError)
- lambda {
+ -> {
class ClassSpecsNumber::MyClass
end
- }.should raise_error(TypeError)
+ }.should.raise(TypeError)
end
it "inherits from Object by default" do
@@ -66,10 +84,10 @@ describe "A class definition" do
module ClassSpecs
class SuperclassResetToSubclass < L
end
- lambda {
+ -> {
class SuperclassResetToSubclass < M
end
- }.should raise_error(TypeError, /superclass mismatch/)
+ }.should.raise(TypeError, /superclass mismatch/)
end
end
@@ -79,10 +97,10 @@ describe "A class definition" do
end
SuperclassReopenedBasicObject.superclass.should == A
- lambda {
+ -> {
class SuperclassReopenedBasicObject < BasicObject
end
- }.should raise_error(TypeError, /superclass mismatch/)
+ }.should.raise(TypeError, /superclass mismatch/)
SuperclassReopenedBasicObject.superclass.should == A
end
end
@@ -94,10 +112,10 @@ describe "A class definition" do
end
SuperclassReopenedObject.superclass.should == A
- lambda {
+ -> {
class SuperclassReopenedObject < Object
end
- }.should raise_error(TypeError, /superclass mismatch/)
+ }.should.raise(TypeError, /superclass mismatch/)
SuperclassReopenedObject.superclass.should == A
end
end
@@ -119,19 +137,19 @@ describe "A class definition" do
class NoSuperclassSet
end
- lambda {
+ -> {
class NoSuperclassSet < String
end
- }.should raise_error(TypeError, /superclass mismatch/)
+ }.should.raise(TypeError, /superclass mismatch/)
end
end
it "allows using self as the superclass if self is a class" do
ClassSpecs::I::J.superclass.should == ClassSpecs::I
- lambda {
+ -> {
class ShouldNotWork < self; end
- }.should raise_error(TypeError)
+ }.should.raise(TypeError)
end
it "first evaluates the superclass before checking if the class already exists" do
@@ -150,7 +168,7 @@ describe "A class definition" do
it "raises a TypeError if inheriting from a metaclass" do
obj = mock("metaclass super")
meta = obj.singleton_class
- lambda { class ClassSpecs::MetaclassSuper < meta; end }.should raise_error(TypeError)
+ -> { class ClassSpecs::MetaclassSuper < meta; end }.should.raise(TypeError)
end
it "allows the declaration of class variables in the body" do
@@ -159,7 +177,7 @@ describe "A class definition" do
end
it "stores instance variables defined in the class body in the class object" do
- ClassSpecs.string_instance_variables(ClassSpecs::B).should include("@ivar")
+ ClassSpecs.string_instance_variables(ClassSpecs::B).should.include?("@ivar")
ClassSpecs::B.instance_variable_get(:@ivar).should == :ivar
end
@@ -171,9 +189,9 @@ describe "A class definition" do
end
it "allows the definition of class-level instance variables in a class method" do
- ClassSpecs.string_instance_variables(ClassSpecs::C).should_not include("@civ")
+ ClassSpecs.string_instance_variables(ClassSpecs::C).should_not.include?("@civ")
ClassSpecs::C.make_class_instance_variable
- ClassSpecs.string_instance_variables(ClassSpecs::C).should include("@civ")
+ ClassSpecs.string_instance_variables(ClassSpecs::C).should.include?("@civ")
ClassSpecs::C.remove_instance_variable :@civ
end
@@ -212,16 +230,16 @@ describe "A class definition" do
describe "within a block creates a new class in the lexical scope" do
it "for named classes at the toplevel" do
klass = Class.new do
- class Howdy
+ class CS_CONST_CLASS_SPECS
end
def self.get_class_name
- Howdy.name
+ CS_CONST_CLASS_SPECS.name
end
end
- Howdy.name.should == 'Howdy'
- klass.get_class_name.should == 'Howdy'
+ klass.get_class_name.should == 'CS_CONST_CLASS_SPECS'
+ ::CS_CONST_CLASS_SPECS.name.should == 'CS_CONST_CLASS_SPECS'
end
it "for named classes in a module" do
@@ -260,13 +278,16 @@ describe "A class definition" do
AnonWithConstant.name.should == 'AnonWithConstant'
klass.get_class_name.should == 'AnonWithConstant'
+ ensure
+ Object.send(:remove_const, :AnonWithConstant)
end
end
end
describe "An outer class definition" do
it "contains the inner classes" do
- ClassSpecs::Container.constants.should include(:A, :B)
+ ClassSpecs::Container.constants.should.include?(:A)
+ ClassSpecs::Container.constants.should.include?(:B)
end
end
@@ -276,7 +297,7 @@ describe "A class definition extending an object (sclass)" do
end
it "raises a TypeError when trying to extend numbers" do
- lambda {
+ -> {
eval <<-CODE
class << 1
def xyz
@@ -284,11 +305,23 @@ describe "A class definition extending an object (sclass)" do
end
end
CODE
- }.should raise_error(TypeError)
+ }.should.raise(TypeError)
end
- it "allows accessing the block of the original scope" do
- ClassSpecs.sclass_with_block { 123 }.should == 123
+ it "raises a TypeError when trying to extend non-Class" do
+ error_msg = /superclass must be a.* Class/
+ -> { class TestClass < ""; end }.should.raise(TypeError, error_msg)
+ -> { class TestClass < 1; end }.should.raise(TypeError, error_msg)
+ -> { class TestClass < :symbol; end }.should.raise(TypeError, error_msg)
+ -> { class TestClass < mock('o'); end }.should.raise(TypeError, error_msg)
+ -> { class TestClass < Module.new; end }.should.raise(TypeError, error_msg)
+ -> { class TestClass < BasicObject.new; end }.should.raise(TypeError, error_msg)
+ end
+
+ it "does not allow accessing the block of the original scope" do
+ -> {
+ ClassSpecs.sclass_with_block { 123 }
+ }.should.raise(SyntaxError)
end
it "can use return to cause the enclosing method to return" do
@@ -308,11 +341,11 @@ describe "Reopening a class" do
end
it "raises a TypeError when superclasses mismatch" do
- lambda { class ClassSpecs::A < Array; end }.should raise_error(TypeError)
+ -> { class ClassSpecs::A < Array; end }.should.raise(TypeError)
end
it "adds new methods to subclasses" do
- lambda { ClassSpecs::M.m }.should raise_error(NoMethodError)
+ -> { ClassSpecs::M.m }.should.raise(NoMethodError)
class ClassSpecs::L
def self.m
1
@@ -321,6 +354,39 @@ describe "Reopening a class" do
ClassSpecs::M.m.should == 1
ClassSpecs::L.singleton_class.send(:remove_method, :m)
end
+
+ it "does not reopen a class included in Object" do
+ ruby_exe(<<~RUBY).should == "false"
+ module IncludedInObject
+ class IncludedClass
+ end
+ end
+ class Object
+ include IncludedInObject
+ end
+ class IncludedClass
+ end
+ print IncludedInObject::IncludedClass == Object::IncludedClass
+ RUBY
+ end
+
+ it "does not reopen a class included in non-Object modules" do
+ ruby_exe(<<~RUBY).should == "false/false"
+ module Included
+ module IncludedClass; end
+ end
+ module M
+ include Included
+ module IncludedClass; end
+ end
+ class C
+ include Included
+ module IncludedClass; end
+ end
+ print Included::IncludedClass == M::IncludedClass, "/",
+ Included::IncludedClass == C::IncludedClass
+ RUBY
+ end
end
describe "class provides hooks" do
diff --git a/spec/ruby/language/class_variable_spec.rb b/spec/ruby/language/class_variable_spec.rb
index 463f731a93..84a7684c6d 100644
--- a/spec/ruby/language/class_variable_spec.rb
+++ b/spec/ruby/language/class_variable_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/class_variables', __FILE__)
+require_relative '../spec_helper'
+require_relative '../fixtures/class_variables'
describe "A class variable" do
after :each do
@@ -30,19 +30,19 @@ describe "A class variable defined in a module" do
end
it "is not defined in these classes" do
- ClassVariablesSpec::ClassC.cvar_defined?.should be_false
+ ClassVariablesSpec::ClassC.cvar_defined?.should == false
end
it "is only updated in the module a method defined in the module is used" do
ClassVariablesSpec::ClassC.cvar_m = "new value"
ClassVariablesSpec::ClassC.cvar_m.should == "new value"
- ClassVariablesSpec::ClassC.cvar_defined?.should be_false
+ ClassVariablesSpec::ClassC.cvar_defined?.should == false
end
it "is updated in the class when a Method defined in the class is used" do
ClassVariablesSpec::ClassC.cvar_c = "new value"
- ClassVariablesSpec::ClassC.cvar_defined?.should be_true
+ ClassVariablesSpec::ClassC.cvar_defined?.should == true
end
it "can be accessed inside the class using the module methods" do
@@ -55,11 +55,11 @@ describe "A class variable defined in a module" do
end
it "is defined in the extended module" do
- ClassVariablesSpec::ModuleN.class_variable_defined?(:@@cvar_n).should be_true
+ ClassVariablesSpec::ModuleN.class_variable_defined?(:@@cvar_n).should == true
end
it "is not defined in the extending module" do
- ClassVariablesSpec::ModuleO.class_variable_defined?(:@@cvar_n).should be_false
+ ClassVariablesSpec::ModuleO.class_variable_defined?(:@@cvar_n).should == false
end
end
@@ -70,15 +70,45 @@ describe 'A class variable definition' do
c = Class.new(b)
b.class_variable_set(:@@cv, :value)
- lambda { a.class_variable_get(:@@cv) }.should raise_error(NameError)
+ -> { a.class_variable_get(:@@cv) }.should.raise(NameError)
b.class_variable_get(:@@cv).should == :value
c.class_variable_get(:@@cv).should == :value
# updates the same variable
c.class_variable_set(:@@cv, :next)
- lambda { a.class_variable_get(:@@cv) }.should raise_error(NameError)
+ -> { a.class_variable_get(:@@cv) }.should.raise(NameError)
b.class_variable_get(:@@cv).should == :next
c.class_variable_get(:@@cv).should == :next
end
end
+
+describe 'Accessing a class variable' do
+ it "raises a RuntimeError when accessed from the toplevel scope (not in some module or class)" do
+ -> {
+ eval "@@cvar_toplevel1"
+ }.should.raise(RuntimeError, 'class variable access from toplevel')
+ -> {
+ eval "@@cvar_toplevel2 = 2"
+ }.should.raise(RuntimeError, 'class variable access from toplevel')
+ end
+
+ it "does not raise an error when checking if defined from the toplevel scope" do
+ -> {
+ eval "defined?(@@cvar_toplevel1)"
+ }.should_not.raise
+ end
+
+ it "raises a RuntimeError when a class variable is overtaken in an ancestor class" do
+ parent = Class.new()
+ subclass = Class.new(parent)
+ subclass.class_variable_set(:@@cvar_overtaken, :subclass)
+ parent.class_variable_set(:@@cvar_overtaken, :parent)
+
+ -> {
+ subclass.class_variable_get(:@@cvar_overtaken)
+ }.should.raise(RuntimeError, /class variable @@cvar_overtaken of .+ is overtaken by .+/)
+
+ parent.class_variable_get(:@@cvar_overtaken).should == :parent
+ end
+end
diff --git a/spec/ruby/language/comment_spec.rb b/spec/ruby/language/comment_spec.rb
new file mode 100644
index 0000000000..dd788e681c
--- /dev/null
+++ b/spec/ruby/language/comment_spec.rb
@@ -0,0 +1,13 @@
+require_relative '../spec_helper'
+
+describe "The comment" do
+ it "can be placed between fluent dot now" do
+ code = <<~CODE
+ 10
+ # some comment
+ .to_s
+ CODE
+
+ eval(code).should == '10'
+ end
+end
diff --git a/spec/ruby/language/constants_spec.rb b/spec/ruby/language/constants_spec.rb
index 1d3cecd9c6..0880230a36 100644
--- a/spec/ruby/language/constants_spec.rb
+++ b/spec/ruby/language/constants_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/constants', __FILE__)
-require File.expand_path('../fixtures/constants_sclass', __FILE__)
-require File.expand_path('../fixtures/constant_visibility', __FILE__)
+require_relative '../spec_helper'
+require_relative '../fixtures/constants'
+require_relative 'fixtures/constants_sclass'
+require_relative 'fixtures/constant_visibility'
# Read the documentation in fixtures/constants.rb for the guidelines and
# rationale for the structure and organization of these specs.
@@ -49,10 +49,10 @@ describe "Literal (A::X) constant resolution" do
end
it "does not search the singleton class of the class or module" do
- lambda do
+ -> do
ConstantSpecs::ContainerA::ChildA::CS_CONST14
- end.should raise_error(NameError)
- lambda { ConstantSpecs::CS_CONST14 }.should raise_error(NameError)
+ end.should.raise(NameError)
+ -> { ConstantSpecs::CS_CONST14 }.should.raise(NameError)
end
end
@@ -72,39 +72,60 @@ describe "Literal (A::X) constant resolution" do
ConstantSpecs::ModuleA::CS_CONST101 = :const101_5
ConstantSpecs::ModuleA::CS_CONST101.should == :const101_5
+ ensure
+ ConstantSpecs::ClassB.send(:remove_const, :CS_CONST101)
+ ConstantSpecs::ParentB.send(:remove_const, :CS_CONST101)
+ ConstantSpecs::ContainerB.send(:remove_const, :CS_CONST101)
+ ConstantSpecs::ContainerB::ChildB.send(:remove_const, :CS_CONST101)
+ ConstantSpecs::ModuleA.send(:remove_const, :CS_CONST101)
end
it "searches a module included in the immediate class before the superclass" do
ConstantSpecs::ParentB::CS_CONST102 = :const102_1
ConstantSpecs::ModuleF::CS_CONST102 = :const102_2
ConstantSpecs::ContainerB::ChildB::CS_CONST102.should == :const102_2
+ ensure
+ ConstantSpecs::ParentB.send(:remove_const, :CS_CONST102)
+ ConstantSpecs::ModuleF.send(:remove_const, :CS_CONST102)
end
it "searches the superclass before a module included in the superclass" do
ConstantSpecs::ModuleE::CS_CONST103 = :const103_1
ConstantSpecs::ParentB::CS_CONST103 = :const103_2
ConstantSpecs::ContainerB::ChildB::CS_CONST103.should == :const103_2
+ ensure
+ ConstantSpecs::ModuleE.send(:remove_const, :CS_CONST103)
+ ConstantSpecs::ParentB.send(:remove_const, :CS_CONST103)
end
it "searches a module included in the superclass" do
ConstantSpecs::ModuleA::CS_CONST104 = :const104_1
ConstantSpecs::ModuleE::CS_CONST104 = :const104_2
ConstantSpecs::ContainerB::ChildB::CS_CONST104.should == :const104_2
+ ensure
+ ConstantSpecs::ModuleA.send(:remove_const, :CS_CONST104)
+ ConstantSpecs::ModuleE.send(:remove_const, :CS_CONST104)
end
it "searches the superclass chain" do
ConstantSpecs::ModuleA::CS_CONST105 = :const105
ConstantSpecs::ContainerB::ChildB::CS_CONST105.should == :const105
+ ensure
+ ConstantSpecs::ModuleA.send(:remove_const, :CS_CONST105)
end
it "searches Object if no class or module qualifier is given" do
CS_CONST106 = :const106
CS_CONST106.should == :const106
+ ensure
+ Object.send(:remove_const, :CS_CONST106)
end
it "searches Object if a toplevel qualifier (::X) is given" do
::CS_CONST107 = :const107
::CS_CONST107.should == :const107
+ ensure
+ Object.send(:remove_const, :CS_CONST107)
end
it "does not search the singleton class of the class or module" do
@@ -112,9 +133,9 @@ describe "Literal (A::X) constant resolution" do
CS_CONST108 = :const108_1
end
- lambda do
+ -> do
ConstantSpecs::ContainerB::ChildB::CS_CONST108
- end.should raise_error(NameError)
+ end.should.raise(NameError)
module ConstantSpecs
class << self
@@ -122,7 +143,10 @@ describe "Literal (A::X) constant resolution" do
end
end
- lambda { ConstantSpecs::CS_CONST108 }.should raise_error(NameError)
+ -> { ConstantSpecs::CS_CONST108 }.should.raise(NameError)
+ ensure
+ ConstantSpecs::ContainerB::ChildB.singleton_class.send(:remove_const, :CS_CONST108)
+ ConstantSpecs.singleton_class.send(:remove_const, :CS_CONST108)
end
it "returns the updated value when a constant is reassigned" do
@@ -133,25 +157,53 @@ describe "Literal (A::X) constant resolution" do
ConstantSpecs::ClassB::CS_CONST109 = :const109_2
}.should complain(/already initialized constant/)
ConstantSpecs::ClassB::CS_CONST109.should == :const109_2
+ ensure
+ ConstantSpecs::ClassB.send(:remove_const, :CS_CONST109)
end
- it "evaluates the right hand side before evaluating a constant path" do
+ it "evaluates left-to-right" do
mod = Module.new
mod.module_eval <<-EOC
- ConstantSpecsRHS::B = begin
- module ConstantSpecsRHS; end
-
- "hello"
- end
+ order = []
+ ConstantSpecsRHS = Module.new
+ (order << :lhs; ConstantSpecsRHS)::B = (order << :rhs)
EOC
- mod::ConstantSpecsRHS::B.should == 'hello'
+ mod::ConstantSpecsRHS::B.should == [:lhs, :rhs]
end
end
it "raises a NameError if no constant is defined in the search path" do
- lambda { ConstantSpecs::ParentA::CS_CONSTX }.should raise_error(NameError)
+ -> { ConstantSpecs::ParentA::CS_CONSTX }.should.raise(NameError)
+ end
+
+ it "uses the module or class #name to craft the error message" do
+ mod = Module.new do
+ def self.name
+ "ModuleName"
+ end
+
+ def self.inspect
+ "<unusable info>"
+ end
+ end
+
+ -> { mod::DOES_NOT_EXIST }.should.raise(NameError, /uninitialized constant ModuleName::DOES_NOT_EXIST/)
+ end
+
+ it "uses the module or class #inspect to craft the error message if they are anonymous" do
+ mod = Module.new do
+ def self.name
+ nil
+ end
+
+ def self.inspect
+ "<unusable info>"
+ end
+ end
+
+ -> { mod::DOES_NOT_EXIST }.should.raise(NameError, /uninitialized constant <unusable info>::DOES_NOT_EXIST/)
end
it "sends #const_missing to the original class or module scope" do
@@ -163,10 +215,10 @@ describe "Literal (A::X) constant resolution" do
end
it "raises a TypeError if a non-class or non-module qualifier is given" do
- lambda { CS_CONST1::CS_CONST }.should raise_error(TypeError)
- lambda { 1::CS_CONST }.should raise_error(TypeError)
- lambda { "mod"::CS_CONST }.should raise_error(TypeError)
- lambda { false::CS_CONST }.should raise_error(TypeError)
+ -> { CS_CONST1::CS_CONST }.should.raise(TypeError)
+ -> { 1::CS_CONST }.should.raise(TypeError)
+ -> { "mod"::CS_CONST }.should.raise(TypeError)
+ -> { false::CS_CONST }.should.raise(TypeError)
end
end
@@ -212,7 +264,7 @@ describe "Constant resolution within methods" do
end
it "does not search the lexical scope of the caller" do
- lambda { ConstantSpecs::ClassA.const16 }.should raise_error(NameError)
+ -> { ConstantSpecs::ClassA.const16 }.should.raise(NameError)
end
it "searches the lexical scope of a block" do
@@ -225,9 +277,9 @@ describe "Constant resolution within methods" do
end
it "does not search the lexical scope of qualifying modules" do
- lambda do
+ -> do
ConstantSpecs::ContainerA::ChildA.const23
- end.should raise_error(NameError)
+ end.should.raise(NameError)
end
end
@@ -248,6 +300,12 @@ describe "Constant resolution within methods" do
ConstantSpecs::ClassB.new.const201.should == :const201_2
ConstantSpecs::ParentB.new.const201.should == :const201_3
ConstantSpecs::ContainerB::ChildB.new.const201.should == :const201_5
+ ensure
+ ConstantSpecs::ModuleA.send(:remove_const, :CS_CONST201)
+ ConstantSpecs::ClassB.send(:remove_const, :CS_CONST201)
+ ConstantSpecs::ParentB.send(:remove_const, :CS_CONST201)
+ ConstantSpecs::ContainerB.send(:remove_const, :CS_CONST201)
+ ConstantSpecs::ContainerB::ChildB.send(:remove_const, :CS_CONST201)
end
it "searches a module included in the immediate class before the superclass" do
@@ -256,6 +314,9 @@ describe "Constant resolution within methods" do
ConstantSpecs::ContainerB::ChildB.const202.should == :const202_1
ConstantSpecs::ContainerB::ChildB.new.const202.should == :const202_1
+ ensure
+ ConstantSpecs::ParentB.send(:remove_const, :CS_CONST202)
+ ConstantSpecs::ContainerB::ChildB.send(:remove_const, :CS_CONST202)
end
it "searches the superclass before a module included in the superclass" do
@@ -264,6 +325,9 @@ describe "Constant resolution within methods" do
ConstantSpecs::ContainerB::ChildB.const203.should == :const203_1
ConstantSpecs::ContainerB::ChildB.new.const203.should == :const203_1
+ ensure
+ ConstantSpecs::ParentB.send(:remove_const, :CS_CONST203)
+ ConstantSpecs::ModuleE.send(:remove_const, :CS_CONST203)
end
it "searches a module included in the superclass" do
@@ -272,6 +336,9 @@ describe "Constant resolution within methods" do
ConstantSpecs::ContainerB::ChildB.const204.should == :const204_1
ConstantSpecs::ContainerB::ChildB.new.const204.should == :const204_1
+ ensure
+ ConstantSpecs::ModuleA.send(:remove_const, :CS_CONST204)
+ ConstantSpecs::ModuleE.send(:remove_const, :CS_CONST204)
end
it "searches the superclass chain" do
@@ -279,6 +346,8 @@ describe "Constant resolution within methods" do
ConstantSpecs::ContainerB::ChildB.const205.should == :const205
ConstantSpecs::ContainerB::ChildB.new.const205.should == :const205
+ ensure
+ ConstantSpecs::ModuleA.send(:remove_const, :CS_CONST205)
end
it "searches the lexical scope of the method not the receiver's immediate class" do
@@ -290,6 +359,9 @@ describe "Constant resolution within methods" do
end
ConstantSpecs::ContainerB::ChildB.const206.should == :const206_1
+ ensure
+ ConstantSpecs::ContainerB::ChildB.send(:remove_const, :CS_CONST206)
+ ConstantSpecs::ContainerB::ChildB.singleton_class.send(:remove_const, :CS_CONST206)
end
it "searches the lexical scope of a singleton method" do
@@ -297,12 +369,17 @@ describe "Constant resolution within methods" do
ConstantSpecs::ClassB::CS_CONST207 = :const207_2
ConstantSpecs::CS_CONST208.const207.should == :const207_1
+ ensure
+ ConstantSpecs.send(:remove_const, :CS_CONST207)
+ ConstantSpecs::ClassB.send(:remove_const, :CS_CONST207)
end
it "does not search the lexical scope of the caller" do
ConstantSpecs::ClassB::CS_CONST209 = :const209
- lambda { ConstantSpecs::ClassB.const209 }.should raise_error(NameError)
+ -> { ConstantSpecs::ClassB.const209 }.should.raise(NameError)
+ ensure
+ ConstantSpecs::ClassB.send(:remove_const, :CS_CONST209)
end
it "searches the lexical scope of a block" do
@@ -310,6 +387,9 @@ describe "Constant resolution within methods" do
ConstantSpecs::ParentB::CS_CONST210 = :const210_2
ConstantSpecs::ClassB.const210.should == :const210_1
+ ensure
+ ConstantSpecs::ClassB.send(:remove_const, :CS_CONST210)
+ ConstantSpecs::ParentB.send(:remove_const, :CS_CONST210)
end
it "searches Object as a lexical scope only if Object is explicitly opened" do
@@ -320,6 +400,11 @@ describe "Constant resolution within methods" do
Object::CS_CONST212 = :const212_2
ConstantSpecs::ParentB::CS_CONST212 = :const212_1
ConstantSpecs::ContainerB::ChildB.const212.should == :const212_1
+ ensure
+ Object.send(:remove_const, :CS_CONST211)
+ ConstantSpecs::ParentB.send(:remove_const, :CS_CONST211)
+ Object.send(:remove_const, :CS_CONST212)
+ ConstantSpecs::ParentB.send(:remove_const, :CS_CONST212)
end
it "returns the updated value when a constant is reassigned" do
@@ -332,49 +417,29 @@ describe "Constant resolution within methods" do
}.should complain(/already initialized constant/)
ConstantSpecs::ContainerB::ChildB.const213.should == :const213_2
ConstantSpecs::ContainerB::ChildB.new.const213.should == :const213_2
+ ensure
+ ConstantSpecs::ParentB.send(:remove_const, :CS_CONST213)
end
it "does not search the lexical scope of qualifying modules" do
ConstantSpecs::ContainerB::CS_CONST214 = :const214
- lambda do
+ -> do
ConstantSpecs::ContainerB::ChildB.const214
- end.should raise_error(NameError)
+ end.should.raise(NameError)
+ ensure
+ ConstantSpecs::ContainerB.send(:remove_const, :CS_CONST214)
end
end
it "raises a NameError if no constant is defined in the search path" do
- lambda { ConstantSpecs::ParentA.constx }.should raise_error(NameError)
+ -> { ConstantSpecs::ParentA.constx }.should.raise(NameError)
end
it "sends #const_missing to the original class or module scope" do
ConstantSpecs::ClassA.constx.should == :CS_CONSTX
ConstantSpecs::ClassA.new.constx.should == :CS_CONSTX
end
-
- describe "with ||=" do
- it "assigns a scoped constant if previously undefined" do
- ConstantSpecs.should_not have_constant(:OpAssignUndefined)
- module ConstantSpecs
- OpAssignUndefined ||= 42
- end
- ConstantSpecs::OpAssignUndefined.should == 42
- ConstantSpecs::OpAssignUndefinedOutside ||= 42
- ConstantSpecs::OpAssignUndefinedOutside.should == 42
- ConstantSpecs.send(:remove_const, :OpAssignUndefined)
- ConstantSpecs.send(:remove_const, :OpAssignUndefinedOutside)
- end
-
- it "assigns a global constant if previously undefined" do
- OpAssignGlobalUndefined ||= 42
- ::OpAssignGlobalUndefinedExplicitScope ||= 42
- OpAssignGlobalUndefined.should == 42
- ::OpAssignGlobalUndefinedExplicitScope.should == 42
- Object.send :remove_const, :OpAssignGlobalUndefined
- Object.send :remove_const, :OpAssignGlobalUndefinedExplicitScope
- end
-
- end
end
describe "Constant resolution within a singleton class (class << obj)" do
@@ -382,25 +447,35 @@ describe "Constant resolution within a singleton class (class << obj)" do
ConstantSpecs::CS_SINGLETON1.foo.should == 1
end
- ruby_version_is "2.3" do
- it "uses its own namespace for each object" do
- a = ConstantSpecs::CS_SINGLETON2[0].foo
- b = ConstantSpecs::CS_SINGLETON2[1].foo
- [a, b].should == [1, 2]
- end
+ it "uses its own namespace for each object" do
+ a = ConstantSpecs::CS_SINGLETON2[0].foo
+ b = ConstantSpecs::CS_SINGLETON2[1].foo
+ [a, b].should == [1, 2]
+ end
- it "uses its own namespace for nested modules" do
- a = ConstantSpecs::CS_SINGLETON3[0].x
- b = ConstantSpecs::CS_SINGLETON3[1].x
- a.should_not equal(b)
- end
+ it "uses its own namespace for nested modules" do
+ a = ConstantSpecs::CS_SINGLETON3[0].x
+ b = ConstantSpecs::CS_SINGLETON3[1].x
+ a.should_not.equal?(b)
+ end
- it "allows nested modules to have proper resolution" do
- a = ConstantSpecs::CS_SINGLETON4_CLASSES[0].new
- b = ConstantSpecs::CS_SINGLETON4_CLASSES[1].new
- [a.foo, b.foo].should == [1, 2]
+ it "allows nested modules to have proper resolution" do
+ a = ConstantSpecs::CS_SINGLETON4_CLASSES[0].new
+ b = ConstantSpecs::CS_SINGLETON4_CLASSES[1].new
+ [a.foo, b.foo].should == [1, 2]
+ end
+end
+
+describe "top-level constant lookup" do
+ context "on a class" do
+ it "does not search Object after searching other scopes" do
+ -> { String::Hash }.should.raise(NameError)
end
end
+
+ it "searches Object unsuccessfully when searches on a module" do
+ -> { Enumerable::Hash }.should.raise(NameError)
+ end
end
describe "Module#private_constant marked constants" do
@@ -413,26 +488,37 @@ describe "Module#private_constant marked constants" do
mod.const_set :Foo, false
}.should complain(/already initialized constant/)
- lambda {mod::Foo}.should raise_error(NameError)
+ -> {mod::Foo}.should.raise(NameError)
+ end
+
+ it "sends #const_missing to the original class or module" do
+ mod = Module.new
+ mod.const_set :Foo, true
+ mod.send :private_constant, :Foo
+ def mod.const_missing(name)
+ name == :Foo ? name : super
+ end
+
+ mod::Foo.should == :Foo
end
describe "in a module" do
it "cannot be accessed from outside the module" do
- lambda do
+ -> do
ConstantVisibility::PrivConstModule::PRIVATE_CONSTANT_MODULE
- end.should raise_error(NameError)
+ end.should.raise(NameError)
end
it "cannot be reopened as a module from scope where constant would be private" do
- lambda do
+ -> do
module ConstantVisibility::ModuleContainer::PrivateModule; end
- end.should raise_error(NameError)
+ end.should.raise(NameError)
end
it "cannot be reopened as a class from scope where constant would be private" do
- lambda do
+ -> do
class ConstantVisibility::ModuleContainer::PrivateClass; end
- end.should raise_error(NameError)
+ end.should.raise(NameError)
end
it "can be reopened as a module where constant is not private" do
@@ -443,6 +529,10 @@ describe "Module#private_constant marked constants" do
PrivateModule::X.should == 1
end
+ ensure
+ module ::ConstantVisibility::ModuleContainer
+ PrivateModule.send(:remove_const, :X)
+ end
end
it "can be reopened as a class where constant is not private" do
@@ -453,6 +543,10 @@ describe "Module#private_constant marked constants" do
PrivateClass::X.should == 1
end
+ ensure
+ module ::ConstantVisibility::ModuleContainer
+ PrivateClass.send(:remove_const, :X)
+ end
end
it "is not defined? with A::B form" do
@@ -460,7 +554,7 @@ describe "Module#private_constant marked constants" do
end
it "can be accessed from the module itself" do
- ConstantVisibility::PrivConstModule.private_constant_from_self.should be_true
+ ConstantVisibility::PrivConstModule.private_constant_from_self.should == true
end
it "is defined? from the module itself" do
@@ -468,7 +562,7 @@ describe "Module#private_constant marked constants" do
end
it "can be accessed from lexical scope" do
- ConstantVisibility::PrivConstModule::Nested.private_constant_from_scope.should be_true
+ ConstantVisibility::PrivConstModule::Nested.private_constant_from_scope.should == true
end
it "is defined? from lexical scope" do
@@ -476,31 +570,44 @@ describe "Module#private_constant marked constants" do
end
it "can be accessed from classes that include the module" do
- ConstantVisibility::PrivConstModuleChild.new.private_constant_from_include.should be_true
+ ConstantVisibility::ClassIncludingPrivConstModule.new.private_constant_from_include.should == true
+ end
+
+ it "can be accessed from modules that include the module" do
+ ConstantVisibility::ModuleIncludingPrivConstModule.private_constant_from_include.should == true
+ end
+
+ it "raises a NameError when accessed directly from modules that include the module" do
+ -> do
+ ConstantVisibility::ModuleIncludingPrivConstModule.private_constant_self_from_include
+ end.should.raise(NameError)
+ -> do
+ ConstantVisibility::ModuleIncludingPrivConstModule.private_constant_named_from_include
+ end.should.raise(NameError)
end
it "is defined? from classes that include the module" do
- ConstantVisibility::PrivConstModuleChild.new.defined_from_include.should == "constant"
+ ConstantVisibility::ClassIncludingPrivConstModule.new.defined_from_include.should == "constant"
end
end
describe "in a class" do
it "cannot be accessed from outside the class" do
- lambda do
+ -> do
ConstantVisibility::PrivConstClass::PRIVATE_CONSTANT_CLASS
- end.should raise_error(NameError)
+ end.should.raise(NameError)
end
it "cannot be reopened as a module" do
- lambda do
+ -> do
module ConstantVisibility::ClassContainer::PrivateModule; end
- end.should raise_error(NameError)
+ end.should.raise(NameError)
end
it "cannot be reopened as a class" do
- lambda do
+ -> do
class ConstantVisibility::ClassContainer::PrivateClass; end
- end.should raise_error(NameError)
+ end.should.raise(NameError)
end
it "can be reopened as a module where constant is not private" do
@@ -511,6 +618,10 @@ describe "Module#private_constant marked constants" do
PrivateModule::X.should == 1
end
+ ensure
+ class ::ConstantVisibility::ClassContainer
+ PrivateModule.send(:remove_const, :X)
+ end
end
it "can be reopened as a class where constant is not private" do
@@ -521,6 +632,10 @@ describe "Module#private_constant marked constants" do
PrivateClass::X.should == 1
end
+ ensure
+ class ::ConstantVisibility::ClassContainer
+ PrivateClass.send(:remove_const, :X)
+ end
end
it "is not defined? with A::B form" do
@@ -528,7 +643,7 @@ describe "Module#private_constant marked constants" do
end
it "can be accessed from the class itself" do
- ConstantVisibility::PrivConstClass.private_constant_from_self.should be_true
+ ConstantVisibility::PrivConstClass.private_constant_from_self.should == true
end
it "is defined? from the class itself" do
@@ -536,7 +651,7 @@ describe "Module#private_constant marked constants" do
end
it "can be accessed from lexical scope" do
- ConstantVisibility::PrivConstClass::Nested.private_constant_from_scope.should be_true
+ ConstantVisibility::PrivConstClass::Nested.private_constant_from_scope.should == true
end
it "is defined? from lexical scope" do
@@ -544,7 +659,7 @@ describe "Module#private_constant marked constants" do
end
it "can be accessed from subclasses" do
- ConstantVisibility::PrivConstClassChild.new.private_constant_from_subclass.should be_true
+ ConstantVisibility::PrivConstClassChild.new.private_constant_from_subclass.should == true
end
it "is defined? from subclasses" do
@@ -554,9 +669,9 @@ describe "Module#private_constant marked constants" do
describe "in Object" do
it "cannot be accessed using ::Const form" do
- lambda do
+ -> do
::PRIVATE_CONSTANT_IN_OBJECT
- end.should raise_error(NameError)
+ end.should.raise(NameError)
end
it "is not defined? using ::Const form" do
@@ -571,6 +686,40 @@ describe "Module#private_constant marked constants" do
defined?(PRIVATE_CONSTANT_IN_OBJECT).should == "constant"
end
end
+
+ describe "NameError by #private_constant" do
+ it "has :receiver and :name attributes" do
+ -> do
+ ConstantVisibility::PrivConstClass::PRIVATE_CONSTANT_CLASS
+ end.should.raise(NameError) {|e|
+ e.receiver.should == ConstantVisibility::PrivConstClass
+ e.name.should == :PRIVATE_CONSTANT_CLASS
+ }
+
+ -> do
+ ConstantVisibility::PrivConstModule::PRIVATE_CONSTANT_MODULE
+ end.should.raise(NameError) {|e|
+ e.receiver.should == ConstantVisibility::PrivConstModule
+ e.name.should == :PRIVATE_CONSTANT_MODULE
+ }
+ end
+
+ it "has the defined class as the :name attribute" do
+ -> do
+ ConstantVisibility::PrivConstClassChild::PRIVATE_CONSTANT_CLASS
+ end.should.raise(NameError) {|e|
+ e.receiver.should == ConstantVisibility::PrivConstClass
+ e.name.should == :PRIVATE_CONSTANT_CLASS
+ }
+
+ -> do
+ ConstantVisibility::ClassIncludingPrivConstModule::PRIVATE_CONSTANT_MODULE
+ end.should.raise(NameError) {|e|
+ e.receiver.should == ConstantVisibility::PrivConstModule
+ e.name.should == :PRIVATE_CONSTANT_MODULE
+ }
+ end
+ end
end
describe "Module#public_constant marked constants" do
@@ -622,3 +771,39 @@ describe "Module#public_constant marked constants" do
end
end
end
+
+describe 'Allowed characters' do
+ it 'allows not ASCII characters in the middle of a name' do
+ mod = Module.new
+ mod.const_set("BBá¼BB", 1)
+
+ eval("mod::BBá¼BB").should == 1
+ end
+
+ it 'does not allow not ASCII characters that cannot be upcased or lowercased at the beginning' do
+ -> do
+ Module.new.const_set("થBB", 1)
+ end.should.raise(NameError, /wrong constant name/)
+ end
+
+ it 'allows not ASCII upcased characters at the beginning' do
+ mod = Module.new
+ mod.const_set("á¼BB", 1)
+
+ eval("mod::á¼BB").should == 1
+ end
+end
+
+describe 'Assignment' do
+ context 'dynamic assignment' do
+ it 'raises SyntaxError' do
+ -> do
+ eval <<-CODE
+ def test
+ B = 1
+ end
+ CODE
+ end.should.raise(SyntaxError, /dynamic constant assignment/)
+ end
+ end
+end
diff --git a/spec/ruby/language/def_spec.rb b/spec/ruby/language/def_spec.rb
index 55ee283b90..a589b4750b 100644
--- a/spec/ruby/language/def_spec.rb
+++ b/spec/ruby/language/def_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/def', __FILE__)
+require_relative '../spec_helper'
+require_relative 'fixtures/def'
# Language-level method behaviour
describe "Redefining a method" do
@@ -14,11 +14,11 @@ end
describe "Defining a method at the top-level" do
it "defines it on Object with private visibility by default" do
- Object.should have_private_instance_method(:some_toplevel_method, false)
+ Object.private_instance_methods(false).should.include?(:some_toplevel_method)
end
it "defines it on Object with public visibility after calling public" do
- Object.should have_public_instance_method(:public_toplevel_method, false)
+ Object.public_instance_methods(false).should.include?(:public_toplevel_method)
end
end
@@ -28,7 +28,7 @@ describe "Defining an 'initialize' method" do
def initialize
end
end
- DefInitializeSpec.should have_private_instance_method(:initialize, false)
+ DefInitializeSpec.private_instance_methods(false).should.include?(:initialize)
end
end
@@ -38,7 +38,7 @@ describe "Defining an 'initialize_copy' method" do
def initialize_copy
end
end
- DefInitializeCopySpec.should have_private_instance_method(:initialize_copy, false)
+ DefInitializeCopySpec.private_instance_methods(false).should.include?(:initialize_copy)
end
end
@@ -48,7 +48,7 @@ describe "Defining an 'initialize_dup' method" do
def initialize_dup
end
end
- DefInitializeDupSpec.should have_private_instance_method(:initialize_dup, false)
+ DefInitializeDupSpec.private_instance_methods(false).should.include?(:initialize_dup)
end
end
@@ -58,7 +58,7 @@ describe "Defining an 'initialize_clone' method" do
def initialize_clone
end
end
- DefInitializeCloneSpec.should have_private_instance_method(:initialize_clone, false)
+ DefInitializeCloneSpec.private_instance_methods(false).should.include?(:initialize_clone)
end
end
@@ -68,7 +68,7 @@ describe "Defining a 'respond_to_missing?' method" do
def respond_to_missing?
end
end
- DefRespondToMissingPSpec.should have_private_instance_method(:respond_to_missing?, false)
+ DefRespondToMissingPSpec.private_instance_methods(false).should.include?(:respond_to_missing?)
end
end
@@ -79,6 +79,40 @@ describe "Defining a method" do
end
end
+describe "An instance method" do
+ it "raises an error with too few arguments" do
+ def foo(a, b); end
+ -> { foo 1 }.should.raise(ArgumentError, 'wrong number of arguments (given 1, expected 2)')
+ end
+
+ it "raises an error with too many arguments" do
+ def foo(a); end
+ -> { foo 1, 2 }.should.raise(ArgumentError, 'wrong number of arguments (given 2, expected 1)')
+ end
+
+ it "raises FrozenError with the correct class name" do
+ -> {
+ Module.new do
+ self.freeze
+ def foo; end
+ end
+ }.should.raise(FrozenError) { |e|
+ msg_class = ruby_version_is("4.0") ? "Module" : "module"
+ e.message.should == "can't modify frozen #{msg_class}: #{e.receiver}"
+ }
+
+ -> {
+ Class.new do
+ self.freeze
+ def foo; end
+ end
+ }.should.raise(FrozenError){ |e|
+ msg_class = ruby_version_is("4.0") ? "Class" : "class"
+ e.message.should == "can't modify frozen #{msg_class}: #{e.receiver}"
+ }
+ end
+end
+
describe "An instance method definition with a splat" do
it "accepts an unnamed '*' argument" do
def foo(*); end;
@@ -101,12 +135,12 @@ describe "An instance method definition with a splat" do
end
it "allows only a single * argument" do
- lambda { eval 'def foo(a, *b, *c); end' }.should raise_error(SyntaxError)
+ -> { eval 'def foo(a, *b, *c); end' }.should.raise(SyntaxError)
end
it "requires the presence of any arguments that precede the *" do
def foo(a, b, *c); end
- lambda { foo 1 }.should raise_error(ArgumentError)
+ -> { foo 1 }.should.raise(ArgumentError, 'wrong number of arguments (given 1, expected 2+)')
end
end
@@ -139,7 +173,7 @@ describe "An instance method with a default argument" do
def foo(a, b = 2)
[a,b]
end
- lambda { foo }.should raise_error(ArgumentError)
+ -> { foo }.should.raise(ArgumentError, 'wrong number of arguments (given 0, expected 1..2)')
foo(1).should == [1, 2]
end
@@ -147,7 +181,7 @@ describe "An instance method with a default argument" do
def foo(a, b = 2, *c)
[a,b,c]
end
- lambda { foo }.should raise_error(ArgumentError)
+ -> { foo }.should.raise(ArgumentError, 'wrong number of arguments (given 0, expected 1+)')
foo(1).should == [1,2,[]]
end
@@ -165,17 +199,25 @@ describe "An instance method with a default argument" do
foo(2,3,3).should == [2,3,[3]]
end
- it "shadows an existing method with the same name as the local" do
- def bar
- 1
+ ruby_version_is ""..."3.4" do
+ it "raises a SyntaxError if using the argument in its default value" do
+ -> {
+ eval "def foo(bar = bar)
+ bar
+ end"
+ }.should.raise(SyntaxError)
+ end
+ end
+
+ ruby_version_is "3.4" do
+ it "is nil if using the argument in its default value" do
+ -> {
+ eval "def foo(bar = bar)
+ bar
+ end
+ foo"
+ }.call.should == nil
end
- -> {
- eval "def foo(bar = bar)
- bar
- end"
- }.should complain(/circular argument reference/)
- foo.should == nil
- foo(2).should == 2
end
it "calls a method with the same name as the local when explicitly using ()" do
@@ -208,7 +250,7 @@ describe "A singleton method definition" do
end
it "can be declared for a global variable" do
- $__a__ = "hi"
+ $__a__ = +"hi"
def $__a__.foo
7
end
@@ -234,42 +276,51 @@ describe "A singleton method definition" do
(obj==2).should == 2
end
- it "raises RuntimeError if frozen" do
+ it "raises FrozenError if frozen" do
obj = Object.new
obj.freeze
- lambda { def obj.foo; end }.should raise_error(RuntimeError)
+ -> { def obj.foo; end }.should.raise(FrozenError)
end
-end
-
-describe "Redefining a singleton method" do
- it "does not inherit a previously set visibility" do
- o = Object.new
-
- class << o; private; def foo; end; end;
- class << o; should have_private_instance_method(:foo); end
+ it "raises FrozenError with the correct class name" do
+ obj = Object.new
+ obj.freeze
+ msg_class = ruby_version_is("4.0") ? "Object" : "object"
+ -> { def obj.foo; end }.should.raise(FrozenError, "can't modify frozen #{msg_class}: #{obj}")
- class << o; def foo; end; end;
+ obj = Object.new
+ c = obj.singleton_class
+ c.singleton_class.freeze
+ -> { def c.foo; end }.should.raise(FrozenError, "can't modify frozen Class: #{c}")
- class << o; should_not have_private_instance_method(:foo); end
- class << o; should have_instance_method(:foo); end
+ c = Class.new
+ c.freeze
+ -> { def c.foo; end }.should.raise(FrozenError, "can't modify frozen Class: #{c}")
+ m = Module.new
+ m.freeze
+ -> { def m.foo; end }.should.raise(FrozenError, "can't modify frozen Module: #{m}")
end
end
describe "Redefining a singleton method" do
it "does not inherit a previously set visibility" do
o = Object.new
+ sc = o.singleton_class
- class << o; private; def foo; end; end;
-
- class << o; should have_private_instance_method(:foo); end
+ class << o
+ private
+ def foo; end
+ end
- class << o; def foo; end; end;
+ sc.private_instance_methods(false).should.include?(:foo)
- class << o; should_not have_private_instance_method(:foo); end
- class << o; should have_instance_method(:foo); end
+ class << o
+ def foo; end
+ end
+ sc.private_instance_methods(false).should_not.include?(:foo)
+ sc.should.method_defined?(:foo)
end
end
@@ -310,7 +361,7 @@ describe "A method defined with extreme default arguments" do
end
it "may use a lambda as a default" do
- def foo(output = 'a', prc = lambda {|n| output * n})
+ def foo(output = 'a', prc = -> n { output * n })
prc.call(5)
end
foo.should == 'aaaaa'
@@ -356,7 +407,7 @@ describe "A singleton method defined with extreme default arguments" do
it "may use a lambda as a default" do
a = Object.new
- def a.foo(output = 'a', prc = lambda {|n| output * n})
+ def a.foo(output = 'a', prc = -> n { output * n })
prc.call(5)
end
a.foo.should == 'aaaaa'
@@ -372,7 +423,7 @@ describe "A method definition inside a metaclass scope" do
end
DefSpecSingleton.a_class_method.should == DefSpecSingleton
- lambda { Object.a_class_method }.should raise_error(NoMethodError)
+ -> { Object.a_class_method }.should.raise(NoMethodError)
end
it "can create a singleton method" do
@@ -382,15 +433,15 @@ describe "A method definition inside a metaclass scope" do
end
obj.a_singleton_method.should == obj
- lambda { Object.new.a_singleton_method }.should raise_error(NoMethodError)
+ -> { Object.new.a_singleton_method }.should.raise(NoMethodError)
end
- it "raises RuntimeError if frozen" do
+ it "raises FrozenError if frozen" do
obj = Object.new
obj.freeze
class << obj
- lambda { def foo; end }.should raise_error(RuntimeError)
+ -> { def foo; end }.should.raise(FrozenError)
end
end
end
@@ -411,7 +462,7 @@ describe "A nested method definition" do
other = DefSpecNested.new
other.an_instance_method.should == other
- DefSpecNested.should have_instance_method(:an_instance_method)
+ DefSpecNested.should.method_defined?(:an_instance_method, false)
end
it "creates a class method when evaluated in a class method" do
@@ -426,11 +477,11 @@ describe "A nested method definition" do
end
end
- lambda { DefSpecNested.a_class_method }.should raise_error(NoMethodError)
+ -> { DefSpecNested.a_class_method }.should.raise(NoMethodError)
DefSpecNested.create_class_method.should == DefSpecNested
DefSpecNested.a_class_method.should == DefSpecNested
- lambda { Object.a_class_method }.should raise_error(NoMethodError)
- lambda { DefSpecNested.new.a_class_method }.should raise_error(NoMethodError)
+ -> { Object.a_class_method }.should.raise(NoMethodError)
+ -> { DefSpecNested.new.a_class_method }.should.raise(NoMethodError)
end
it "creates a singleton method when evaluated in the metaclass of an instance" do
@@ -448,7 +499,7 @@ describe "A nested method definition" do
obj.a_singleton_method.should == obj
other = DefSpecNested.new
- lambda { other.a_singleton_method }.should raise_error(NoMethodError)
+ -> { other.a_singleton_method }.should.raise(NoMethodError)
end
it "creates a method in the surrounding context when evaluated in a def expr.method" do
@@ -460,11 +511,13 @@ describe "A nested method definition" do
end
DefSpecNested::TARGET.defs_method
- DefSpecNested.should have_instance_method :inherited_method
- DefSpecNested::TARGET.should_not have_method :inherited_method
+ DefSpecNested.should.method_defined?(:inherited_method, false)
+ DefSpecNested::TARGET.should_not.respond_to? :inherited_method
obj = DefSpecNested.new
obj.inherited_method.should == obj
+ ensure
+ DefSpecNested.send(:remove_const, :TARGET)
end
# See http://yugui.jp/articles/846#label-3
@@ -481,14 +534,16 @@ describe "A nested method definition" do
obj = DefSpecNested::OBJ
obj.create_method_in_instance_eval
- obj.should have_method :arg_method
- obj.should have_method :body_method
+ obj.should.respond_to? :arg_method
+ obj.should.respond_to? :body_method
- DefSpecNested.should_not have_instance_method :arg_method
- DefSpecNested.should_not have_instance_method :body_method
+ DefSpecNested.should_not.method_defined? :arg_method
+ DefSpecNested.should_not.method_defined? :body_method
+ ensure
+ DefSpecNested.send(:remove_const, :OBJ)
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 +555,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(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(NoMethodError, /private/)
+ obj.send :do_def
+ obj.new_def.should == 1
+
+ cls.new.new_def.should == 1
+
+ -> { Object.new.new_def }.should.raise(NoMethodError)
+ end
+
+ it "at the toplevel" do
+ obj = Object.new
+ -> { obj.toplevel_define_other_method }.should.raise(NoMethodError, /private/)
+ toplevel_define_other_method
+ nested_method_in_toplevel_method.should == 42
+
+ Object.new.nested_method_in_toplevel_method.should == 42
end
end
@@ -512,7 +602,7 @@ describe "A method definition inside an instance_eval" do
obj.an_instance_eval_method.should == obj
other = Object.new
- lambda { other.an_instance_eval_method }.should raise_error(NoMethodError)
+ -> { other.an_instance_eval_method }.should.raise(NoMethodError)
end
it "creates a singleton method when evaluated inside a metaclass" do
@@ -525,7 +615,7 @@ describe "A method definition inside an instance_eval" do
obj.a_metaclass_eval_method.should == obj
other = Object.new
- lambda { other.a_metaclass_eval_method }.should raise_error(NoMethodError)
+ -> { other.a_metaclass_eval_method }.should.raise(NoMethodError)
end
it "creates a class method when the receiver is a class" do
@@ -534,7 +624,7 @@ describe "A method definition inside an instance_eval" do
end
DefSpecNested.an_instance_eval_class_method.should == DefSpecNested
- lambda { Object.an_instance_eval_class_method }.should raise_error(NoMethodError)
+ -> { Object.an_instance_eval_class_method }.should.raise(NoMethodError)
end
it "creates a class method when the receiver is an anonymous class" do
@@ -546,7 +636,7 @@ describe "A method definition inside an instance_eval" do
end
m.klass_method.should == :test
- lambda { Object.klass_method }.should raise_error(NoMethodError)
+ -> { Object.klass_method }.should.raise(NoMethodError)
end
it "creates a class method when instance_eval is within class" do
@@ -559,7 +649,7 @@ describe "A method definition inside an instance_eval" do
end
m.klass_method.should == :test
- lambda { Object.klass_method }.should raise_error(NoMethodError)
+ -> { Object.klass_method }.should.raise(NoMethodError)
end
end
@@ -572,7 +662,7 @@ describe "A method definition inside an instance_exec" do
end
DefSpecNested.an_instance_exec_class_method.should == 1
- lambda { Object.an_instance_exec_class_method }.should raise_error(NoMethodError)
+ -> { Object.an_instance_exec_class_method }.should.raise(NoMethodError)
end
it "creates a class method when the receiver is an anonymous class" do
@@ -586,7 +676,7 @@ describe "A method definition inside an instance_exec" do
end
m.klass_method.should == 1
- lambda { Object.klass_method }.should raise_error(NoMethodError)
+ -> { Object.klass_method }.should.raise(NoMethodError)
end
it "creates a class method when instance_exec is within class" do
@@ -601,7 +691,7 @@ describe "A method definition inside an instance_exec" do
end
m.klass_method.should == 2
- lambda { Object.klass_method }.should raise_error(NoMethodError)
+ -> { Object.klass_method }.should.raise(NoMethodError)
end
end
@@ -621,7 +711,7 @@ describe "A method definition in an eval" do
other = DefSpecNested.new
other.an_eval_instance_method.should == other
- lambda { Object.new.an_eval_instance_method }.should raise_error(NoMethodError)
+ -> { Object.new.an_eval_instance_method }.should.raise(NoMethodError)
end
it "creates a class method" do
@@ -637,8 +727,8 @@ describe "A method definition in an eval" do
DefSpecNestedB.eval_class_method.should == DefSpecNestedB
DefSpecNestedB.an_eval_class_method.should == DefSpecNestedB
- lambda { Object.an_eval_class_method }.should raise_error(NoMethodError)
- lambda { DefSpecNestedB.new.an_eval_class_method}.should raise_error(NoMethodError)
+ -> { Object.an_eval_class_method }.should.raise(NoMethodError)
+ -> { DefSpecNestedB.new.an_eval_class_method}.should.raise(NoMethodError)
end
it "creates a singleton method" do
@@ -656,7 +746,7 @@ describe "A method definition in an eval" do
obj.an_eval_singleton_method.should == obj
other = DefSpecNested.new
- lambda { other.an_eval_singleton_method }.should raise_error(NoMethodError)
+ -> { other.an_eval_singleton_method }.should.raise(NoMethodError)
end
end
@@ -667,8 +757,8 @@ describe "a method definition that sets more than one default parameter all to t
it "assigns them all the same object by default" do
foo.should == [{},{},{}]
a, b, c = foo
- a.should eql(b)
- a.should eql(c)
+ a.should.eql?(b)
+ a.should.eql?(c)
end
it "allows the first argument to be given, and sets the rest to null" do
@@ -678,11 +768,11 @@ describe "a method definition that sets more than one default parameter all to t
it "assigns the parameters different objects across different default calls" do
a, _b, _c = foo
d, _e, _f = foo
- a.should_not equal(d)
+ a.should_not.equal?(d)
end
it "only allows overriding the default value of the first such parameter in each set" do
- lambda { foo(1,2) }.should raise_error(ArgumentError)
+ -> { foo(1,2) }.should.raise(ArgumentError, 'wrong number of arguments (given 2, expected 0..1)')
end
def bar(a=b=c=1,d=2)
@@ -693,7 +783,7 @@ describe "a method definition that sets more than one default parameter all to t
bar.should == [1,1,1,2]
bar(3).should == [3,nil,nil,2]
bar(3,4).should == [3,nil,nil,4]
- lambda { bar(3,4,5) }.should raise_error(ArgumentError)
+ -> { bar(3,4,5) }.should.raise(ArgumentError, 'wrong number of arguments (given 3, expected 0..2)')
end
end
@@ -703,12 +793,12 @@ describe "The def keyword" do
module DefSpecsLambdaVisibility
private
- lambda {
+ -> {
def some_method; end
}.call
end
- DefSpecsLambdaVisibility.should have_private_instance_method("some_method")
+ DefSpecsLambdaVisibility.private_instance_methods(false).should.include?(:some_method)
end
end
end
diff --git a/spec/ruby/language/defined_spec.rb b/spec/ruby/language/defined_spec.rb
index 1247658381..6846179a7c 100644
--- a/spec/ruby/language/defined_spec.rb
+++ b/spec/ruby/language/defined_spec.rb
@@ -1,25 +1,29 @@
-require File.expand_path('../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/defined', __FILE__)
+require_relative '../spec_helper'
+require_relative 'fixtures/defined'
describe "The defined? keyword for literals" do
it "returns 'self' for self" do
ret = defined?(self)
ret.should == "self"
+ ret.frozen?.should == true
end
it "returns 'nil' for nil" do
ret = defined?(nil)
ret.should == "nil"
+ ret.frozen?.should == true
end
it "returns 'true' for true" do
ret = defined?(true)
ret.should == "true"
+ ret.frozen?.should == true
end
it "returns 'false' for false" do
ret = defined?(false)
ret.should == "false"
+ ret.frozen?.should == true
end
describe "for a literal Array" do
@@ -27,15 +31,16 @@ describe "The defined? keyword for literals" do
it "returns 'expression' if each element is defined" do
ret = defined?([Object, Array])
ret.should == "expression"
+ ret.frozen?.should == true
end
it "returns nil if one element is not defined" do
- ret = defined?([NonExistantConstant, Array])
+ ret = defined?([NonExistentConstant, Array])
ret.should == nil
end
it "returns nil if all elements are not defined" do
- ret = defined?([NonExistantConstant, AnotherNonExistantConstant])
+ ret = defined?([NonExistentConstant, AnotherNonExistentConstant])
ret.should == nil
end
@@ -43,13 +48,29 @@ describe "The defined? keyword for literals" do
end
describe "The defined? keyword when called with a method name" do
+ before :each do
+ ScratchPad.clear
+ end
+
+ it "does not call the method" do
+ defined?(DefinedSpecs.side_effects).should == "method"
+ ScratchPad.recorded.should != :defined_specs_side_effects
+ end
+
+ it "does not execute the arguments" do
+ defined?(DefinedSpecs.any_args(DefinedSpecs.side_effects)).should == "method"
+ ScratchPad.recorded.should != :defined_specs_side_effects
+ end
+
describe "without a receiver" do
it "returns 'method' if the method is defined" do
- defined?(puts).should == "method"
+ ret = defined?(puts)
+ ret.should == "method"
+ ret.frozen?.should == true
end
it "returns nil if the method is not defined" do
- defined?(defined_specs_undefined_method).should be_nil
+ defined?(defined_specs_undefined_method).should == nil
end
it "returns 'method' if the method is defined and private" do
@@ -69,23 +90,23 @@ describe "The defined? keyword when called with a method name" do
end
it "returns nil if the method is private" do
- defined?(Object.print).should be_nil
+ defined?(Object.print).should == nil
end
it "returns nil if the method is protected" do
- defined?(DefinedSpecs::Basic.new.protected_method).should be_nil
+ defined?(DefinedSpecs::Basic.new.protected_method).should == nil
end
it "returns nil if the method is not defined" do
- defined?(Kernel.defined_specs_undefined_method).should be_nil
+ defined?(Kernel.defined_specs_undefined_method).should == nil
end
it "returns nil if the class is not defined" do
- defined?(DefinedSpecsUndefined.puts).should be_nil
+ defined?(DefinedSpecsUndefined.puts).should == nil
end
it "returns nil if the subclass is not defined" do
- defined?(DefinedSpecs::Undefined.puts).should be_nil
+ defined?(DefinedSpecs::Undefined.puts).should == nil
end
end
@@ -95,13 +116,18 @@ describe "The defined? keyword when called with a method name" do
defined?(obj.a_defined_method).should == "method"
end
+ it "returns 'method' for []=" do
+ a = []
+ defined?(a[0] = 1).should == "method"
+ end
+
it "returns nil if the method is not defined" do
obj = DefinedSpecs::Basic.new
- defined?(obj.an_undefined_method).should be_nil
+ defined?(obj.an_undefined_method).should == nil
end
it "returns nil if the variable does not exist" do
- defined?(nonexistent_local_variable.some_method).should be_nil
+ defined?(nonexistent_local_variable.some_method).should == nil
end
it "calls #respond_to_missing?" do
@@ -119,11 +145,11 @@ describe "The defined? keyword when called with a method name" do
it "returns nil if the method is not defined" do
@defined_specs_obj = DefinedSpecs::Basic.new
- defined?(@defined_specs_obj.an_undefined_method).should be_nil
+ defined?(@defined_specs_obj.an_undefined_method).should == nil
end
it "returns nil if the variable does not exist" do
- defined?(@nonexistent_instance_variable.some_method).should be_nil
+ defined?(@nonexistent_instance_variable.some_method).should == nil
end
end
@@ -135,22 +161,22 @@ describe "The defined? keyword when called with a method name" do
it "returns nil if the method is not defined" do
$defined_specs_obj = DefinedSpecs::Basic.new
- defined?($defined_specs_obj.an_undefined_method).should be_nil
+ defined?($defined_specs_obj.an_undefined_method).should == nil
end
it "returns nil if the variable does not exist" do
- defined?($nonexistent_global_variable.some_method).should be_nil
+ defined?($nonexistent_global_variable.some_method).should == nil
end
end
describe "having a method call as a receiver" do
it "returns nil if evaluating the receiver raises an exception" do
- defined?(DefinedSpecs.exception_method / 2).should be_nil
+ defined?(DefinedSpecs.exception_method / 2).should == nil
ScratchPad.recorded.should == :defined_specs_exception
end
it "returns nil if the method is not defined on the object the receiver returns" do
- defined?(DefinedSpecs.side_effects / 2).should be_nil
+ defined?(DefinedSpecs.side_effects / 2).should == nil
ScratchPad.recorded.should == :defined_specs_side_effects
end
@@ -159,6 +185,48 @@ describe "The defined? keyword when called with a method name" do
ScratchPad.recorded.should == :defined_specs_fixnum_method
end
end
+
+ describe "having a throw in the receiver" do
+ it "escapes defined? and performs the throw semantics as normal" do
+ defined_returned = false
+ catch(:out) {
+ # NOTE: defined? behaves differently if it is called in a void context, see below
+ defined?(throw(:out, 42).foo).should == :unreachable
+ defined_returned = true
+ }.should == 42
+ defined_returned.should == false
+ end
+ end
+
+ describe "in a void context" do
+ it "does not execute the receiver" do
+ ScratchPad.record :not_executed
+ defined?(DefinedSpecs.side_effects / 2)
+ ScratchPad.recorded.should == :not_executed
+ end
+
+ it "warns about the void context when parsing it" do
+ -> {
+ eval "defined?(DefinedSpecs.side_effects / 2); 42"
+ }.should complain(/warning: possibly useless use of defined\? in void context/, verbose: true)
+ end
+ end
+
+ describe "for a protected method" do
+ it "returns 'method' when the receiver is a subclass instance" do
+ DefinedSpecs::ProtectedBase.new.defined_on(DefinedSpecs::ProtectedSubclass.new).should == "method"
+ end
+
+ it "returns 'method' when the receiver is the base class instance" do
+ DefinedSpecs::ProtectedSubclass.new.defined_on(DefinedSpecs::ProtectedBase.new).should == "method"
+ end
+
+ ruby_bug "#22076", ""..."4.1" do
+ it "returns 'method' when the receiver is a sibling class instance via a shared included module" do
+ DefinedSpecs::ProtectedIncluderA.new.defined_on(DefinedSpecs::ProtectedIncluderB.new).should == "method"
+ end
+ end
+ end
end
describe "The defined? keyword for an expression" do
@@ -167,7 +235,9 @@ describe "The defined? keyword for an expression" do
end
it "returns 'assignment' for assigning a local variable" do
- defined?(x = 2).should == "assignment"
+ ret = defined?(x = 2)
+ ret.should == "assignment"
+ ret.frozen?.should == true
end
it "returns 'assignment' for assigning an instance variable" do
@@ -182,6 +252,14 @@ describe "The defined? keyword for an expression" do
defined?(@@defined_specs_x = 2).should == "assignment"
end
+ it "returns 'assignment' for assigning a constant" do
+ defined?(A = 2).should == "assignment"
+ end
+
+ it "returns 'assignment' for assigning a fully qualified constant" do
+ defined?(Object::A = 2).should == "assignment"
+ end
+
it "returns 'assignment' for assigning multiple variables" do
defined?((a, b = 1, 2)).should == "assignment"
end
@@ -199,7 +277,27 @@ describe "The defined? keyword for an expression" do
end
it "returns 'assignment' for an expression with '+='" do
- defined?(x += 2).should == "assignment"
+ defined?(a += 1).should == "assignment"
+ defined?(@a += 1).should == "assignment"
+ defined?(@@a += 1).should == "assignment"
+ defined?($a += 1).should == "assignment"
+ defined?(A += 1).should == "assignment"
+ # fully qualified constant check is moved out into a separate test case
+ defined?(a.b += 1).should == "assignment"
+ defined?(a[:b] += 1).should == "assignment"
+ end
+
+ # https://bugs.ruby-lang.org/issues/20111
+ ruby_version_is ""..."3.4" do
+ it "returns 'expression' for an assigning a fully qualified constant with '+='" do
+ defined?(Object::A += 1).should == "expression"
+ end
+ end
+
+ ruby_version_is "3.4" do
+ it "returns 'assignment' for an assigning a fully qualified constant with '+='" do
+ defined?(Object::A += 1).should == "assignment"
+ end
end
it "returns 'assignment' for an expression with '*='" do
@@ -230,12 +328,90 @@ describe "The defined? keyword for an expression" do
defined?(x >>= 2).should == "assignment"
end
- it "returns 'assignment' for an expression with '||='" do
- defined?(x ||= 2).should == "assignment"
+ context "||=" do
+ it "returns 'assignment' for assigning a local variable with '||='" do
+ defined?(a ||= true).should == "assignment"
+ end
+
+ it "returns 'assignment' for assigning an instance variable with '||='" do
+ defined?(@a ||= true).should == "assignment"
+ end
+
+ it "returns 'assignment' for assigning a class variable with '||='" do
+ defined?(@@a ||= true).should == "assignment"
+ end
+
+ it "returns 'assignment' for assigning a global variable with '||='" do
+ defined?($a ||= true).should == "assignment"
+ end
+
+ it "returns 'assignment' for assigning a constant with '||='" do
+ defined?(A ||= true).should == "assignment"
+ end
+
+ # https://bugs.ruby-lang.org/issues/20111
+ ruby_version_is ""..."3.4" do
+ it "returns 'expression' for assigning a fully qualified constant with '||='" do
+ defined?(Object::A ||= true).should == "expression"
+ end
+ end
+
+ ruby_version_is "3.4" do
+ it "returns 'assignment' for assigning a fully qualified constant with '||='" do
+ defined?(Object::A ||= true).should == "assignment"
+ end
+ end
+
+ it "returns 'assignment' for assigning an attribute with '||='" do
+ defined?(a.b ||= true).should == "assignment"
+ end
+
+ it "returns 'assignment' for assigning a referenced element with '||='" do
+ defined?(a[:b] ||= true).should == "assignment"
+ end
end
- it "returns 'assignment' for an expression with '&&='" do
- defined?(x &&= 2).should == "assignment"
+ context "&&=" do
+ it "returns 'assignment' for assigning a local variable with '&&='" do
+ defined?(a &&= true).should == "assignment"
+ end
+
+ it "returns 'assignment' for assigning an instance variable with '&&='" do
+ defined?(@a &&= true).should == "assignment"
+ end
+
+ it "returns 'assignment' for assigning a class variable with '&&='" do
+ defined?(@@a &&= true).should == "assignment"
+ end
+
+ it "returns 'assignment' for assigning a global variable with '&&='" do
+ defined?($a &&= true).should == "assignment"
+ end
+
+ it "returns 'assignment' for assigning a constant with '&&='" do
+ defined?(A &&= true).should == "assignment"
+ end
+
+ # https://bugs.ruby-lang.org/issues/20111
+ ruby_version_is ""..."3.4" do
+ it "returns 'expression' for assigning a fully qualified constant with '&&='" do
+ defined?(Object::A &&= true).should == "expression"
+ end
+ end
+
+ ruby_version_is "3.4" do
+ it "returns 'assignment' for assigning a fully qualified constant with '&&='" do
+ defined?(Object::A &&= true).should == "assignment"
+ end
+ end
+
+ it "returns 'assignment' for assigning an attribute with '&&='" do
+ defined?(a.b &&= true).should == "assignment"
+ end
+
+ it "returns 'assignment' for assigning a referenced element with '&&='" do
+ defined?(a[:b] &&= true).should == "assignment"
+ end
end
it "returns 'assignment' for an expression with '**='" do
@@ -243,15 +419,15 @@ describe "The defined? keyword for an expression" do
end
it "returns nil for an expression with == and an undefined method" do
- defined?(defined_specs_undefined_method == 2).should be_nil
+ defined?(defined_specs_undefined_method == 2).should == nil
end
it "returns nil for an expression with != and an undefined method" do
- defined?(defined_specs_undefined_method != 2).should be_nil
+ defined?(defined_specs_undefined_method != 2).should == nil
end
it "returns nil for an expression with !~ and an undefined method" do
- defined?(defined_specs_undefined_method !~ 2).should be_nil
+ defined?(defined_specs_undefined_method !~ 2).should == nil
end
it "returns 'method' for an expression with '=='" do
@@ -271,29 +447,25 @@ describe "The defined? keyword for an expression" do
describe "with logical connectives" do
it "returns nil for an expression with '!' and an undefined method" do
- defined?(!defined_specs_undefined_method).should be_nil
+ defined?(!defined_specs_undefined_method).should == nil
end
it "returns nil for an expression with '!' and an unset class variable" do
- -> {
- @result = defined?(!@@defined_specs_undefined_class_variable)
- }.should complain(/class variable access from toplevel/)
- @result.should be_nil
+ @result = eval("class singleton_class::A; defined?(!@@doesnt_exist) end", binding, __FILE__, __LINE__)
+ @result.should == nil
end
it "returns nil for an expression with 'not' and an undefined method" do
- defined?(not defined_specs_undefined_method).should be_nil
+ defined?(not defined_specs_undefined_method).should == nil
end
it "returns nil for an expression with 'not' and an unset class variable" do
- -> {
- @result = defined?(not @@defined_specs_undefined_class_variable)
- }.should complain(/class variable access from toplevel/)
- @result.should be_nil
+ @result = eval("class singleton_class::A; defined?(not @@doesnt_exist) end", binding, __FILE__, __LINE__)
+ @result.should == nil
end
it "does not propagate an exception raised by a method in a 'not' expression" do
- defined?(not DefinedSpecs.exception_method).should be_nil
+ defined?(not DefinedSpecs.exception_method).should == nil
ScratchPad.recorded.should == :defined_specs_exception
end
@@ -332,11 +504,11 @@ describe "The defined? keyword for an expression" do
end
it "returns nil for an expression with '!' and an unset global variable" do
- defined?(!$defined_specs_undefined_global_variable).should be_nil
+ defined?(!$defined_specs_undefined_global_variable).should == nil
end
it "returns nil for an expression with '!' and an unset instance variable" do
- defined?(!@defined_specs_undefined_instance_variable).should be_nil
+ defined?(!@defined_specs_undefined_instance_variable).should == nil
end
it "returns 'method' for a 'not' expression with a method" do
@@ -349,11 +521,11 @@ describe "The defined? keyword for an expression" do
end
it "returns nil for an expression with 'not' and an unset global variable" do
- defined?(not $defined_specs_undefined_global_variable).should be_nil
+ defined?(not $defined_specs_undefined_global_variable).should == nil
end
it "returns nil for an expression with 'not' and an unset instance variable" do
- defined?(not @defined_specs_undefined_instance_variable).should be_nil
+ defined?(not @defined_specs_undefined_instance_variable).should == nil
end
it "returns 'expression' for an expression with '&&/and' and an undefined method" do
@@ -368,12 +540,12 @@ describe "The defined? keyword for an expression" do
it "does not call a method in an '&&' expression and returns 'expression'" do
defined?(DefinedSpecs.side_effects && true).should == "expression"
- ScratchPad.recorded.should be_nil
+ ScratchPad.recorded.should == nil
end
it "does not call a method in an 'and' expression and returns 'expression'" do
defined?(DefinedSpecs.side_effects and true).should == "expression"
- ScratchPad.recorded.should be_nil
+ ScratchPad.recorded.should == nil
end
it "returns 'expression' for an expression with '||/or' and an undefined method" do
@@ -388,12 +560,12 @@ describe "The defined? keyword for an expression" do
it "does not call a method in an '||' expression and returns 'expression'" do
defined?(DefinedSpecs.side_effects || true).should == "expression"
- ScratchPad.recorded.should be_nil
+ ScratchPad.recorded.should == nil
end
it "does not call a method in an 'or' expression and returns 'expression'" do
defined?(DefinedSpecs.side_effects or true).should == "expression"
- ScratchPad.recorded.should be_nil
+ ScratchPad.recorded.should == nil
end
end
@@ -416,7 +588,7 @@ describe "The defined? keyword for an expression" do
it "does not call the method in the String" do
defined?("garble #{DefinedSpecs.dynamic_string}").should == "expression"
- ScratchPad.recorded.should be_nil
+ ScratchPad.recorded.should == nil
end
end
@@ -435,7 +607,7 @@ describe "The defined? keyword for an expression" do
it "does not call the method in the Regexp" do
defined?(/garble #{DefinedSpecs.dynamic_string}/).should == "expression"
- ScratchPad.recorded.should be_nil
+ ScratchPad.recorded.should == nil
end
end
@@ -474,7 +646,9 @@ end
describe "The defined? keyword for variables" do
it "returns 'local-variable' when called with the name of a local variable" do
- DefinedSpecs::Basic.new.local_variable_defined.should == "local-variable"
+ ret = DefinedSpecs::Basic.new.local_variable_defined
+ ret.should == "local-variable"
+ ret.frozen?.should == true
end
it "returns 'local-variable' when called with the name of a local variable assigned to nil" do
@@ -482,15 +656,17 @@ describe "The defined? keyword for variables" do
end
it "returns nil for an instance variable that has not been read" do
- DefinedSpecs::Basic.new.instance_variable_undefined.should be_nil
+ DefinedSpecs::Basic.new.instance_variable_undefined.should == nil
end
it "returns nil for an instance variable that has been read but not assigned to" do
- DefinedSpecs::Basic.new.instance_variable_read.should be_nil
+ DefinedSpecs::Basic.new.instance_variable_read.should == nil
end
it "returns 'instance-variable' for an instance variable that has been assigned" do
- DefinedSpecs::Basic.new.instance_variable_defined.should == "instance-variable"
+ ret = DefinedSpecs::Basic.new.instance_variable_defined
+ ret.should == "instance-variable"
+ ret.frozen?.should == true
end
it "returns 'instance-variable' for an instance variable that has been assigned to nil" do
@@ -498,11 +674,17 @@ describe "The defined? keyword for variables" do
end
it "returns nil for a global variable that has not been read" do
- DefinedSpecs::Basic.new.global_variable_undefined.should be_nil
+ DefinedSpecs::Basic.new.global_variable_undefined.should == nil
end
it "returns nil for a global variable that has been read but not assigned to" do
- DefinedSpecs::Basic.new.global_variable_read.should be_nil
+ DefinedSpecs::Basic.new.global_variable_read.should == nil
+ end
+
+ it "returns 'global-variable' for a global variable that has been assigned nil" do
+ ret = DefinedSpecs::Basic.new.global_variable_defined_as_nil
+ ret.should == "global-variable"
+ ret.frozen?.should == true
end
# MRI appears to special case defined? for $! and $~ in that it returns
@@ -528,31 +710,27 @@ describe "The defined? keyword for variables" do
end
it "returns nil for $&" do
- defined?($&).should be_nil
+ defined?($&).should == nil
end
it "returns nil for $`" do
- defined?($`).should be_nil
+ defined?($`).should == nil
end
it "returns nil for $'" do
- defined?($').should be_nil
+ defined?($').should == nil
end
it "returns nil for $+" do
- defined?($+).should be_nil
+ defined?($+).should == nil
end
- it "returns nil for $1-$9" do
- defined?($1).should be_nil
- defined?($2).should be_nil
- defined?($3).should be_nil
- defined?($4).should be_nil
- defined?($5).should be_nil
- defined?($6).should be_nil
- defined?($7).should be_nil
- defined?($8).should be_nil
- defined?($9).should be_nil
+ it "returns nil for any last match global" do
+ defined?($1).should == nil
+ defined?($4).should == nil
+ defined?($7).should == nil
+ defined?($10).should == nil
+ defined?($200).should == nil
end
end
@@ -587,13 +765,10 @@ describe "The defined? keyword for variables" do
end
it "returns nil for non-captures" do
- defined?($3).should be_nil
- defined?($4).should be_nil
- defined?($5).should be_nil
- defined?($6).should be_nil
- defined?($7).should be_nil
- defined?($8).should be_nil
- defined?($9).should be_nil
+ defined?($4).should == nil
+ defined?($7).should == nil
+ defined?($10).should == nil
+ defined?($200).should == nil
end
end
@@ -607,31 +782,27 @@ describe "The defined? keyword for variables" do
end
it "returns nil for $&" do
- defined?($&).should be_nil
+ defined?($&).should == nil
end
it "returns nil for $`" do
- defined?($`).should be_nil
+ defined?($`).should == nil
end
it "returns nil for $'" do
- defined?($').should be_nil
+ defined?($').should == nil
end
it "returns nil for $+" do
- defined?($+).should be_nil
+ defined?($+).should == nil
end
- it "returns nil for $1-$9" do
- defined?($1).should be_nil
- defined?($2).should be_nil
- defined?($3).should be_nil
- defined?($4).should be_nil
- defined?($5).should be_nil
- defined?($6).should be_nil
- defined?($7).should be_nil
- defined?($8).should be_nil
- defined?($9).should be_nil
+ it "returns nil for any last match global" do
+ defined?($1).should == nil
+ defined?($4).should == nil
+ defined?($7).should == nil
+ defined?($10).should == nil
+ defined?($200).should == nil
end
end
@@ -666,13 +837,10 @@ describe "The defined? keyword for variables" do
end
it "returns nil for non-captures" do
- defined?($3).should be_nil
- defined?($4).should be_nil
- defined?($5).should be_nil
- defined?($6).should be_nil
- defined?($7).should be_nil
- defined?($8).should be_nil
- defined?($9).should be_nil
+ defined?($4).should == nil
+ defined?($7).should == nil
+ defined?($10).should == nil
+ defined?($200).should == nil
end
end
it "returns 'global-variable' for a global variable that has been assigned" do
@@ -680,7 +848,7 @@ describe "The defined? keyword for variables" do
end
it "returns nil for a class variable that has not been read" do
- DefinedSpecs::Basic.new.class_variable_undefined.should be_nil
+ DefinedSpecs::Basic.new.class_variable_undefined.should == nil
end
# There is no spec for a class variable that is read before being assigned
@@ -688,7 +856,9 @@ describe "The defined? keyword for variables" do
# get to the defined? call so it really has nothing to do with 'defined?'.
it "returns 'class variable' when called with the name of a class variable" do
- DefinedSpecs::Basic.new.class_variable_defined.should == "class variable"
+ ret = DefinedSpecs::Basic.new.class_variable_defined
+ ret.should == "class variable"
+ ret.frozen?.should == true
end
it "returns 'local-variable' when called with the name of a block local" do
@@ -699,16 +869,18 @@ end
describe "The defined? keyword for a simple constant" do
it "returns 'constant' when the constant is defined" do
- defined?(DefinedSpecs).should == "constant"
+ ret = defined?(DefinedSpecs)
+ ret.should == "constant"
+ ret.frozen?.should == true
end
it "returns nil when the constant is not defined" do
- defined?(DefinedSpecsUndefined).should be_nil
+ defined?(DefinedSpecsUndefined).should == nil
end
it "does not call Object.const_missing if the constant is not defined" do
Object.should_not_receive(:const_missing)
- defined?(DefinedSpecsUndefined).should be_nil
+ defined?(DefinedSpecsUndefined).should == nil
end
it "returns 'constant' for an included module" do
@@ -726,12 +898,12 @@ describe "The defined? keyword for a top-level constant" do
end
it "returns nil if the constant is not defined" do
- defined?(::DefinedSpecsUndefined).should be_nil
+ defined?(::DefinedSpecsUndefined).should == nil
end
it "does not call Object.const_missing if the constant is not defined" do
Object.should_not_receive(:const_missing)
- defined?(::DefinedSpecsUndefined).should be_nil
+ defined?(::DefinedSpecsUndefined).should == nil
end
end
@@ -741,33 +913,37 @@ describe "The defined? keyword for a scoped constant" do
end
it "returns nil when the scoped constant is not defined" do
- defined?(DefinedSpecs::Undefined).should be_nil
+ defined?(DefinedSpecs::Undefined).should == nil
+ end
+
+ it "returns nil when the constant is not defined and the outer module implements .const_missing" do
+ defined?(DefinedSpecs::ModuleWithConstMissing::Undefined).should == nil
end
it "does not call .const_missing if the constant is not defined" do
DefinedSpecs.should_not_receive(:const_missing)
- defined?(DefinedSpecs::UnknownChild).should be_nil
+ defined?(DefinedSpecs::UnknownChild).should == nil
end
it "returns nil when an undefined constant is scoped to a defined constant" do
- defined?(DefinedSpecs::Child::B).should be_nil
+ defined?(DefinedSpecs::Child::Undefined).should == nil
end
it "returns nil when a constant is scoped to an undefined constant" do
Object.should_not_receive(:const_missing)
- defined?(Undefined::Object).should be_nil
+ defined?(Undefined::Object).should == nil
end
it "returns nil when the undefined constant is scoped to an undefined constant" do
- defined?(DefinedSpecs::Undefined::Undefined).should be_nil
+ defined?(DefinedSpecs::Undefined::Undefined).should == nil
end
it "returns nil when a constant is defined on top-level but not on the module" do
- defined?(DefinedSpecs::String).should be_nil
+ defined?(DefinedSpecs::String).should == nil
end
- it "returns 'constant' when a constant is defined on top-level but not on the class" do
- defined?(DefinedSpecs::Basic::String).should == "constant"
+ it "returns nil when a constant is defined on top-level but not on the class" do
+ defined?(DefinedSpecs::Basic::String).should == nil
end
it "returns 'constant' if the scoped-scoped constant is defined" do
@@ -781,15 +957,15 @@ describe "The defined? keyword for a top-level scoped constant" do
end
it "returns nil when the scoped constant is not defined" do
- defined?(::DefinedSpecs::Undefined).should be_nil
+ defined?(::DefinedSpecs::Undefined).should == nil
end
it "returns nil when an undefined constant is scoped to a defined constant" do
- defined?(::DefinedSpecs::Child::B).should be_nil
+ defined?(::DefinedSpecs::Child::Undefined).should == nil
end
it "returns nil when the undefined constant is scoped to an undefined constant" do
- defined?(::DefinedSpecs::Undefined::Undefined).should be_nil
+ defined?(::DefinedSpecs::Undefined::Undefined).should == nil
end
it "returns 'constant' if the scoped-scoped constant is defined" do
@@ -799,7 +975,7 @@ end
describe "The defined? keyword for a self-send method call scoped constant" do
it "returns nil if the constant is not defined in the scope of the method's value" do
- defined?(defined_specs_method::Undefined).should be_nil
+ defined?(defined_specs_method::Undefined).should == nil
end
it "returns 'constant' if the constant is defined in the scope of the method's value" do
@@ -807,11 +983,11 @@ describe "The defined? keyword for a self-send method call scoped constant" do
end
it "returns nil if the last constant is not defined in the scope chain" do
- defined?(defined_specs_method::Basic::Undefined).should be_nil
+ defined?(defined_specs_method::Basic::Undefined).should == nil
end
it "returns nil if the middle constant is not defined in the scope chain" do
- defined?(defined_specs_method::Undefined::Undefined).should be_nil
+ defined?(defined_specs_method::Undefined::Undefined).should == nil
end
it "returns 'constant' if all the constants in the scope chain are defined" do
@@ -821,7 +997,7 @@ end
describe "The defined? keyword for a receiver method call scoped constant" do
it "returns nil if the constant is not defined in the scope of the method's value" do
- defined?(defined_specs_receiver.defined_method::Undefined).should be_nil
+ defined?(defined_specs_receiver.defined_method::Undefined).should == nil
end
it "returns 'constant' if the constant is defined in the scope of the method's value" do
@@ -829,11 +1005,11 @@ describe "The defined? keyword for a receiver method call scoped constant" do
end
it "returns nil if the last constant is not defined in the scope chain" do
- defined?(defined_specs_receiver.defined_method::Basic::Undefined).should be_nil
+ defined?(defined_specs_receiver.defined_method::Basic::Undefined).should == nil
end
it "returns nil if the middle constant is not defined in the scope chain" do
- defined?(defined_specs_receiver.defined_method::Undefined::Undefined).should be_nil
+ defined?(defined_specs_receiver.defined_method::Undefined::Undefined).should == nil
end
it "returns 'constant' if all the constants in the scope chain are defined" do
@@ -843,7 +1019,7 @@ end
describe "The defined? keyword for a module method call scoped constant" do
it "returns nil if the constant is not defined in the scope of the method's value" do
- defined?(DefinedSpecs.defined_method::Undefined).should be_nil
+ defined?(DefinedSpecs.defined_method::Undefined).should == nil
end
it "returns 'constant' if the constant scoped by the method's value is defined" do
@@ -851,11 +1027,11 @@ describe "The defined? keyword for a module method call scoped constant" do
end
it "returns nil if the last constant in the scope chain is not defined" do
- defined?(DefinedSpecs.defined_method::Basic::Undefined).should be_nil
+ defined?(DefinedSpecs.defined_method::Basic::Undefined).should == nil
end
it "returns nil if the middle constant in the scope chain is not defined" do
- defined?(DefinedSpecs.defined_method::Undefined::Undefined).should be_nil
+ defined?(DefinedSpecs.defined_method::Undefined::Undefined).should == nil
end
it "returns 'constant' if all the constants in the scope chain are defined" do
@@ -863,11 +1039,11 @@ describe "The defined? keyword for a module method call scoped constant" do
end
it "returns nil if the outer scope constant in the receiver is not defined" do
- defined?(Undefined::DefinedSpecs.defined_method::Basic).should be_nil
+ defined?(Undefined::DefinedSpecs.defined_method::Basic).should == nil
end
it "returns nil if the scoped constant in the receiver is not defined" do
- defined?(DefinedSpecs::Undefined.defined_method::Basic).should be_nil
+ defined?(DefinedSpecs::Undefined.defined_method::Basic).should == nil
end
it "returns 'constant' if all the constants in the receiver are defined" do
@@ -888,7 +1064,7 @@ describe "The defined? keyword for a variable scoped constant" do
it "returns nil if the instance scoped constant is not defined" do
@defined_specs_obj = DefinedSpecs::Basic
- defined?(@defined_specs_obj::Undefined).should be_nil
+ defined?(@defined_specs_obj::Undefined).should == nil
end
it "returns 'constant' if the constant is defined in the scope of the instance variable" do
@@ -898,7 +1074,7 @@ describe "The defined? keyword for a variable scoped constant" do
it "returns nil if the global scoped constant is not defined" do
$defined_specs_obj = DefinedSpecs::Basic
- defined?($defined_specs_obj::Undefined).should be_nil
+ defined?($defined_specs_obj::Undefined).should == nil
end
it "returns 'constant' if the constant is defined in the scope of the global variable" do
@@ -907,22 +1083,26 @@ describe "The defined? keyword for a variable scoped constant" do
end
it "returns nil if the class scoped constant is not defined" do
- -> {
- @@defined_specs_obj = DefinedSpecs::Basic
- defined?(@@defined_specs_obj::Undefined).should be_nil
- }.should complain(/class variable access from toplevel/)
+ eval(<<-END, binding, __FILE__, __LINE__)
+ class singleton_class::A
+ @@defined_specs_obj = DefinedSpecs::Basic
+ defined?(@@defined_specs_obj::Undefined).should == nil
+ end
+ END
end
it "returns 'constant' if the constant is defined in the scope of the class variable" do
- -> {
- @@defined_specs_obj = DefinedSpecs::Basic
- defined?(@@defined_specs_obj::A).should == "constant"
- }.should complain(/class variable access from toplevel/)
+ eval(<<-END, binding, __FILE__, __LINE__)
+ class singleton_class::A
+ @@defined_specs_obj = DefinedSpecs::Basic
+ defined?(@@defined_specs_obj::A).should == "constant"
+ end
+ END
end
it "returns nil if the local scoped constant is not defined" do
defined_specs_obj = DefinedSpecs::Basic
- defined?(defined_specs_obj::Undefined).should be_nil
+ defined?(defined_specs_obj::Undefined).should == nil
end
it "returns 'constant' if the constant is defined in the scope of the local variable" do
@@ -943,46 +1123,62 @@ end
describe "The defined? keyword for yield" do
it "returns nil if no block is passed to a method not taking a block parameter" do
- DefinedSpecs::Basic.new.no_yield_block.should be_nil
+ DefinedSpecs::Basic.new.no_yield_block.should == nil
end
it "returns nil if no block is passed to a method taking a block parameter" do
- DefinedSpecs::Basic.new.no_yield_block_parameter.should be_nil
+ DefinedSpecs::Basic.new.no_yield_block_parameter.should == nil
end
it "returns 'yield' if a block is passed to a method not taking a block parameter" do
- DefinedSpecs::Basic.new.yield_block.should == "yield"
+ ret = DefinedSpecs::Basic.new.yield_block
+ ret.should == "yield"
+ ret.frozen?.should == true
end
it "returns 'yield' if a block is passed to a method taking a block parameter" do
DefinedSpecs::Basic.new.yield_block_parameter.should == "yield"
end
+
+ it "returns 'yield' when called within a block" do
+ def yielder
+ yield
+ end
+
+ def call_defined
+ yielder { defined?(yield) }
+ end
+
+ call_defined() { }.should == "yield"
+ end
end
describe "The defined? keyword for super" do
it "returns nil when a superclass undef's the method" do
- DefinedSpecs::ClassWithoutMethod.new.test.should be_nil
+ DefinedSpecs::ClassWithoutMethod.new.test.should == nil
end
describe "for a method taking no arguments" do
it "returns nil when no superclass method exists" do
- DefinedSpecs::Super.new.no_super_method_no_args.should be_nil
+ DefinedSpecs::Super.new.no_super_method_no_args.should == nil
end
it "returns nil from a block when no superclass method exists" do
- DefinedSpecs::Super.new.no_super_method_block_no_args.should be_nil
+ DefinedSpecs::Super.new.no_super_method_block_no_args.should == nil
end
it "returns nil from a #define_method when no superclass method exists" do
- DefinedSpecs::Super.new.no_super_define_method_no_args.should be_nil
+ DefinedSpecs::Super.new.no_super_define_method_no_args.should == nil
end
it "returns nil from a block in a #define_method when no superclass method exists" do
- DefinedSpecs::Super.new.no_super_define_method_block_no_args.should be_nil
+ DefinedSpecs::Super.new.no_super_define_method_block_no_args.should == nil
end
it "returns 'super' when a superclass method exists" do
- DefinedSpecs::Super.new.method_no_args.should == "super"
+ ret = DefinedSpecs::Super.new.method_no_args
+ ret.should == "super"
+ ret.frozen?.should == true
end
it "returns 'super' from a block when a superclass method exists" do
@@ -1004,19 +1200,19 @@ describe "The defined? keyword for super" do
describe "for a method taking arguments" do
it "returns nil when no superclass method exists" do
- DefinedSpecs::Super.new.no_super_method_args.should be_nil
+ DefinedSpecs::Super.new.no_super_method_args.should == nil
end
it "returns nil from a block when no superclass method exists" do
- DefinedSpecs::Super.new.no_super_method_block_args.should be_nil
+ DefinedSpecs::Super.new.no_super_method_block_args.should == nil
end
it "returns nil from a #define_method when no superclass method exists" do
- DefinedSpecs::Super.new.no_super_define_method_args.should be_nil
+ DefinedSpecs::Super.new.no_super_define_method_args.should == nil
end
it "returns nil from a block in a #define_method when no superclass method exists" do
- DefinedSpecs::Super.new.no_super_define_method_block_args.should be_nil
+ DefinedSpecs::Super.new.no_super_define_method_block_args.should == nil
end
it "returns 'super' when a superclass method exists" do
@@ -1051,7 +1247,7 @@ describe "The defined? keyword for instance variables" do
end
it "returns nil if not assigned" do
- defined?(@unassigned_ivar).should be_nil
+ defined?(@unassigned_ivar).should == nil
end
end
diff --git a/spec/ruby/language/delegation_spec.rb b/spec/ruby/language/delegation_spec.rb
new file mode 100644
index 0000000000..efcf37aabc
--- /dev/null
+++ b/spec/ruby/language/delegation_spec.rb
@@ -0,0 +1,176 @@
+require_relative '../spec_helper'
+require_relative 'fixtures/delegation'
+
+# Forwarding anonymous parameters
+describe "delegation with def(...)" do
+ it "delegates rest and kwargs" do
+ a = Class.new(DelegationSpecs::Target)
+ a.class_eval(<<-RUBY)
+ def delegate(...)
+ target(...)
+ end
+ RUBY
+
+ a.new.delegate(1, b: 2).should == [[1], {b: 2}, nil]
+ end
+
+ it "delegates a block literal" do
+ a = Class.new(DelegationSpecs::Target)
+ a.class_eval(<<-RUBY)
+ def delegate_block(...)
+ target_block(...)
+ end
+ RUBY
+
+ a.new.delegate_block(1, b: 2) { |x| x }.should == [{b: 2}, [1]]
+ end
+
+ it "delegates a block argument" do
+ a = Class.new(DelegationSpecs::Target)
+ a.class_eval(<<-RUBY)
+ def delegate(...)
+ target(...)
+ end
+ RUBY
+
+ block = proc {}
+ a.new.delegate(1, b: 2, &block).should == [[1], {b: 2}, block]
+ end
+
+ it "delegates with additional arguments" do
+ a = Class.new(DelegationSpecs::Target)
+ a.class_eval(<<-RUBY)
+ def delegate(...)
+ target(:first, :second, ...)
+ end
+ RUBY
+ a.new.delegate(1, b: 2).should == [[:first, :second, 1], {b: 2}, nil]
+ end
+
+ it "parses as open endless Range when brackets are omitted" do
+ a = Class.new(DelegationSpecs::Target)
+ suppress_warning do
+ a.class_eval(<<-RUBY)
+ def delegate(...)
+ target ...
+ end
+ RUBY
+ end
+
+ a.new.delegate(1, b: 2).should == Range.new([[], {}, nil], nil, true)
+ end
+
+ it "passes non-keyword trailing hash through without modification" do
+ a = Class.new(DelegationSpecs::Target)
+ a.class_eval(<<-RUBY)
+ def delegate(...)
+ target_single(...)
+ end
+ RUBY
+
+ h = {a:1}
+ h.freeze
+ h2 = a.new.delegate(h)
+ h2.should.equal?(h)
+ end
+end
+
+describe "delegation with def(x, ...)" do
+ it "delegates rest and kwargs" do
+ a = Class.new(DelegationSpecs::Target)
+ a.class_eval(<<-RUBY)
+ def delegate(x, ...)
+ target(...)
+ end
+ RUBY
+
+ a.new.delegate(0, 1, b: 2).should == [[1], {b: 2}, nil]
+ end
+
+ it "delegates a block literal" do
+ a = Class.new(DelegationSpecs::Target)
+ a.class_eval(<<-RUBY)
+ def delegate_block(x, ...)
+ target_block(...)
+ end
+ RUBY
+
+ a.new.delegate_block(0, 1, b: 2) { |x| x }.should == [{b: 2}, [1]]
+ end
+
+ it "delegates a block argument" do
+ a = Class.new(DelegationSpecs::Target)
+ a.class_eval(<<-RUBY)
+ def delegate(...)
+ target(...)
+ end
+ RUBY
+
+ block = proc {}
+ a.new.delegate(1, b: 2, &block).should == [[1], {b: 2}, block]
+ end
+end
+
+describe "delegation with def(*)" do
+ it "delegates rest" do
+ a = Class.new(DelegationSpecs::Target)
+ a.class_eval(<<-RUBY)
+ def delegate(*)
+ target(*)
+ end
+ RUBY
+
+ a.new.delegate(0, 1).should == [[0, 1], {}, nil]
+ end
+
+ context "within a block that accepts anonymous rest within a method that accepts anonymous rest" do
+ it "does not allow delegating rest" do
+ -> {
+ eval "def m(*); proc { |*| n(*) } end"
+ }.should.raise(SyntaxError, /anonymous rest parameter is also used within block/)
+ end
+ end
+end
+
+describe "delegation with def(**)" do
+ it "delegates kwargs" do
+ a = Class.new(DelegationSpecs::Target)
+ a.class_eval(<<-RUBY)
+ def delegate(**)
+ target(**)
+ end
+ RUBY
+
+ a.new.delegate(a: 1) { |x| x }.should == [[], {a: 1}, nil]
+ end
+
+ context "within a block that accepts anonymous kwargs within a method that accepts anonymous kwargs" do
+ it "does not allow delegating kwargs" do
+ -> {
+ eval "def m(**); proc { |**| n(**) } end"
+ }.should.raise(SyntaxError, /anonymous keyword rest parameter is also used within block/)
+ end
+ end
+end
+
+describe "delegation with def(&)" do
+ it "delegates an anonymous block parameter" do
+ a = Class.new(DelegationSpecs::Target)
+ a.class_eval(<<-RUBY)
+ def delegate(&)
+ target(&)
+ end
+ RUBY
+
+ block = proc {}
+ a.new.delegate(&block).should == [[], {}, block]
+ end
+
+ context "within a block that accepts anonymous block within a method that accepts anonymous block" do
+ it "does not allow delegating a block" do
+ -> {
+ eval "def m(&); proc { |&| n(&) } end"
+ }.should.raise(SyntaxError, /anonymous block parameter is also used within block/)
+ end
+ end
+end
diff --git a/spec/ruby/language/encoding_spec.rb b/spec/ruby/language/encoding_spec.rb
index 070fa52bba..116f53a77d 100644
--- a/spec/ruby/language/encoding_spec.rb
+++ b/spec/ruby/language/encoding_spec.rb
@@ -1,11 +1,11 @@
# -*- encoding: us-ascii -*-
-require File.expand_path('../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/coding_us_ascii', __FILE__)
-require File.expand_path('../fixtures/coding_utf_8', __FILE__)
+require_relative '../spec_helper'
+require_relative 'fixtures/coding_us_ascii'
+require_relative 'fixtures/coding_utf_8'
describe "The __ENCODING__ pseudo-variable" do
it "is an instance of Encoding" do
- __ENCODING__.should be_kind_of(Encoding)
+ __ENCODING__.should.is_a?(Encoding)
end
it "is US-ASCII by default" do
@@ -13,15 +13,15 @@ describe "The __ENCODING__ pseudo-variable" do
end
it "is the evaluated strings's one inside an eval" do
- eval("__ENCODING__".force_encoding("US-ASCII")).should == Encoding::US_ASCII
- eval("__ENCODING__".force_encoding("ASCII-8BIT")).should == Encoding::ASCII_8BIT
+ eval("__ENCODING__".dup.force_encoding("US-ASCII")).should == Encoding::US_ASCII
+ eval("__ENCODING__".dup.force_encoding("BINARY")).should == Encoding::BINARY
end
it "is the encoding specified by a magic comment inside an eval" do
- code = "# encoding: ASCII-8BIT\n__ENCODING__".force_encoding("US-ASCII")
- eval(code).should == Encoding::ASCII_8BIT
+ code = "# encoding: BINARY\n__ENCODING__".dup.force_encoding("US-ASCII")
+ eval(code).should == Encoding::BINARY
- code = "# encoding: us-ascii\n__ENCODING__".force_encoding("ASCII-8BIT")
+ code = "# encoding: us-ascii\n__ENCODING__".dup.force_encoding("BINARY")
eval(code).should == Encoding::US_ASCII
end
@@ -31,6 +31,6 @@ describe "The __ENCODING__ pseudo-variable" do
end
it "raises a SyntaxError if assigned to" do
- lambda { eval("__ENCODING__ = 1") }.should raise_error(SyntaxError)
+ -> { eval("__ENCODING__ = 1") }.should.raise(SyntaxError)
end
end
diff --git a/spec/ruby/language/ensure_spec.rb b/spec/ruby/language/ensure_spec.rb
index ae04feb739..04ff0305ab 100644
--- a/spec/ruby/language/ensure_spec.rb
+++ b/spec/ruby/language/ensure_spec.rb
@@ -1,59 +1,53 @@
-require File.expand_path('../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/ensure', __FILE__)
+require_relative '../spec_helper'
+require_relative 'fixtures/ensure'
describe "An ensure block inside a begin block" do
before :each do
ScratchPad.record []
end
- it "is executed when an exception is raised in it's corresponding begin block" do
- begin
- lambda {
- begin
- ScratchPad << :begin
- raise "An exception occurred!"
- ensure
- ScratchPad << :ensure
- end
- }.should raise_error(RuntimeError)
+ it "is executed when an exception is raised in its corresponding begin block" do
+ -> {
+ begin
+ ScratchPad << :begin
+ raise EnsureSpec::Error
+ ensure
+ ScratchPad << :ensure
+ end
+ }.should.raise(EnsureSpec::Error)
- ScratchPad.recorded.should == [:begin, :ensure]
- end
+ ScratchPad.recorded.should == [:begin, :ensure]
end
- it "is executed when an exception is raised and rescued in it's corresponding begin block" do
+ it "is executed when an exception is raised and rescued in its corresponding begin block" do
begin
+ ScratchPad << :begin
+ raise "An exception occurred!"
+ rescue
+ ScratchPad << :rescue
+ ensure
+ ScratchPad << :ensure
+ end
+
+ ScratchPad.recorded.should == [:begin, :rescue, :ensure]
+ end
+
+ it "is executed even when a symbol is thrown in its corresponding begin block" do
+ catch(:symbol) do
begin
ScratchPad << :begin
- raise "An exception occurred!"
+ throw(:symbol)
rescue
ScratchPad << :rescue
ensure
ScratchPad << :ensure
end
-
- ScratchPad.recorded.should == [:begin, :rescue, :ensure]
end
- end
-
- it "is executed even when a symbol is thrown in it's corresponding begin block" do
- begin
- catch(:symbol) do
- begin
- ScratchPad << :begin
- throw(:symbol)
- rescue
- ScratchPad << :rescue
- ensure
- ScratchPad << :ensure
- end
- end
- ScratchPad.recorded.should == [:begin, :ensure]
- end
+ ScratchPad.recorded.should == [:begin, :ensure]
end
- it "is executed when nothing is raised or thrown in it's corresponding begin block" do
+ it "is executed when nothing is raised or thrown in its corresponding begin block" do
begin
ScratchPad << :begin
rescue
@@ -72,6 +66,18 @@ describe "An ensure block inside a begin block" do
:ensure
end.should == :begin
end
+
+ it "sets exception cause if raises exception in block and in ensure" do
+ -> {
+ begin
+ raise "from block"
+ ensure
+ raise "from ensure"
+ end
+ }.should.raise(RuntimeError, "from ensure") { |e|
+ e.cause.message.should == "from block"
+ }
+ end
end
describe "The value of an ensure expression," do
@@ -102,7 +108,7 @@ describe "An ensure block inside a method" do
end
it "is executed when an exception is raised in the method" do
- lambda { @obj.raise_in_method_with_ensure }.should raise_error(RuntimeError)
+ -> { @obj.raise_in_method_with_ensure }.should.raise(EnsureSpec::Error)
@obj.executed.should == [:method, :ensure]
end
@@ -123,4 +129,218 @@ describe "An ensure block inside a method" do
it "has an impact on the method's explicit return value" do
@obj.explicit_return_in_method_with_ensure.should == :ensure
end
+
+ it "has an impact on the method's explicit return value from rescue if returns explicitly" do
+ @obj.explicit_return_in_rescue_and_explicit_return_in_ensure.should == "returned in ensure"
+ end
+
+ it "has no impact on the method's explicit return value from rescue if returns implicitly" do
+ @obj.explicit_return_in_rescue_and_implicit_return_in_ensure.should == "returned in rescue"
+ end
+
+ it "suppresses exception raised in method if returns value explicitly" do
+ @obj.raise_and_explicit_return_in_ensure.should == "returned in ensure"
+ end
+
+ it "suppresses exception raised in rescue if returns value explicitly" do
+ @obj.raise_in_rescue_and_explicit_return_in_ensure.should == "returned in ensure"
+ end
+
+ it "overrides exception raised in rescue if raises exception itself" do
+ -> {
+ @obj.raise_in_rescue_and_raise_in_ensure
+ }.should.raise(RuntimeError, "raised in ensure")
+ end
+
+ it "suppresses exception raised in method if raises exception itself" do
+ -> {
+ @obj.raise_in_method_and_raise_in_ensure
+ }.should.raise(RuntimeError, "raised in ensure")
+ end
+end
+
+describe "An ensure block inside a class" do
+ before :each do
+ ScratchPad.record []
+ end
+
+ it "is executed when an exception is raised" do
+ -> {
+ eval <<-ruby
+ class EnsureInClassExample
+ ScratchPad << :class
+ raise EnsureSpec::Error
+ ensure
+ ScratchPad << :ensure
+ end
+ ruby
+ }.should.raise(EnsureSpec::Error)
+
+ ScratchPad.recorded.should == [:class, :ensure]
+ end
+
+ it "is executed when an exception is raised and rescued" do
+ eval <<-ruby
+ class EnsureInClassExample
+ ScratchPad << :class
+ raise
+ rescue
+ ScratchPad << :rescue
+ ensure
+ ScratchPad << :ensure
+ end
+ ruby
+
+ ScratchPad.recorded.should == [:class, :rescue, :ensure]
+ end
+
+ it "is executed even when a symbol is thrown" do
+ catch(:symbol) do
+ eval <<-ruby
+ class EnsureInClassExample
+ ScratchPad << :class
+ throw(:symbol)
+ rescue
+ ScratchPad << :rescue
+ ensure
+ ScratchPad << :ensure
+ end
+ ruby
+ end
+
+ ScratchPad.recorded.should == [:class, :ensure]
+ end
+
+ it "is executed when nothing is raised or thrown" do
+ eval <<-ruby
+ class EnsureInClassExample
+ ScratchPad << :class
+ rescue
+ ScratchPad << :rescue
+ ensure
+ ScratchPad << :ensure
+ end
+ ruby
+
+ ScratchPad.recorded.should == [:class, :ensure]
+ end
+
+ it "has no return value" do
+ result = eval <<-ruby
+ class EnsureInClassExample
+ :class
+ ensure
+ :ensure
+ end
+ ruby
+
+ result.should == :class
+ end
+end
+
+describe "An ensure block inside {} block" do
+ it "is not allowed" do
+ -> {
+ eval <<-ruby
+ lambda {
+ raise
+ ensure
+ }
+ ruby
+ }.should.raise(SyntaxError)
+ end
+end
+
+describe "An ensure block inside 'do end' block" do
+ before :each do
+ ScratchPad.record []
+ end
+
+ it "is executed when an exception is raised in its corresponding begin block" do
+ -> {
+ eval(<<-ruby).call
+ lambda do
+ ScratchPad << :begin
+ raise EnsureSpec::Error
+ ensure
+ ScratchPad << :ensure
+ end
+ ruby
+ }.should.raise(EnsureSpec::Error)
+
+ ScratchPad.recorded.should == [:begin, :ensure]
+ end
+
+ it "is executed when an exception is raised and rescued in its corresponding begin block" do
+ eval(<<-ruby).call
+ lambda do
+ ScratchPad << :begin
+ raise "An exception occurred!"
+ rescue
+ ScratchPad << :rescue
+ ensure
+ ScratchPad << :ensure
+ end
+ ruby
+
+ ScratchPad.recorded.should == [:begin, :rescue, :ensure]
+ end
+
+ it "is executed even when a symbol is thrown in its corresponding begin block" do
+ catch(:symbol) do
+ eval(<<-ruby).call
+ lambda do
+ ScratchPad << :begin
+ throw(:symbol)
+ rescue
+ ScratchPad << :rescue
+ ensure
+ ScratchPad << :ensure
+ end
+ ruby
+ end
+
+ ScratchPad.recorded.should == [:begin, :ensure]
+ end
+
+ it "is executed when nothing is raised or thrown in its corresponding begin block" do
+ eval(<<-ruby).call
+ lambda do
+ ScratchPad << :begin
+ rescue
+ ScratchPad << :rescue
+ ensure
+ ScratchPad << :ensure
+ end
+ ruby
+
+ ScratchPad.recorded.should == [:begin, :ensure]
+ end
+
+ it "has no return value" do
+ result = eval(<<-ruby).call
+ lambda do
+ :begin
+ ensure
+ :ensure
+ end
+ ruby
+
+ result.should == :begin
+ end
+
+ ruby_version_is "3.4" do
+ it "does not introduce extra backtrace entries" do
+ def foo
+ begin
+ raise "oops"
+ ensure
+ return caller(0, 2) # rubocop:disable Lint/EnsureReturn
+ end
+ end
+ line = __LINE__
+ foo[0].should =~ /#{__FILE__}:#{line-3}:in 'foo'/
+ foo[1].should =~ /#{__FILE__}:#{line+2}:in 'block/
+ end
+ end
end
diff --git a/spec/ruby/language/execution_spec.rb b/spec/ruby/language/execution_spec.rb
index 3e6e7ff48c..51bcde62e8 100644
--- a/spec/ruby/language/execution_spec.rb
+++ b/spec/ruby/language/execution_spec.rb
@@ -1,10 +1,49 @@
-require File.expand_path('../../spec_helper', __FILE__)
+require_relative '../spec_helper'
describe "``" do
it "returns the output of the executed sub-process" do
ip = 'world'
`echo disc #{ip}`.should == "disc world\n"
end
+
+ it "can be redefined and receive a frozen string as argument" do
+ called = false
+ runner = Object.new
+
+ runner.singleton_class.define_method(:`) do |str|
+ called = true
+
+ str.should == "test command"
+ str.frozen?.should == true
+ end
+
+ runner.instance_exec do
+ `test command`
+ end
+
+ called.should == true
+ end
+
+ it "the argument isn't frozen if it contains interpolation" do
+ called = false
+ runner = Object.new
+
+ runner.singleton_class.define_method(:`) do |str|
+ called = true
+
+ str.should == "test command"
+ str.frozen?.should == false
+ str << "mutated"
+ end
+
+ 2.times do
+ runner.instance_exec do
+ `test #{:command}` # rubocop:disable Lint/LiteralInInterpolation
+ end
+ end
+
+ called.should == true
+ end
end
describe "%x" do
@@ -12,4 +51,43 @@ describe "%x" do
ip = 'world'
%x(echo disc #{ip}).should == "disc world\n"
end
+
+ it "can be redefined and receive a frozen string as argument" do
+ called = false
+ runner = Object.new
+
+ runner.singleton_class.define_method(:`) do |str|
+ called = true
+
+ str.should == "test command"
+ str.frozen?.should == true
+ end
+
+ runner.instance_exec do
+ %x{test command}
+ end
+
+ called.should == true
+ end
+
+ it "the argument isn't frozen if it contains interpolation" do
+ called = false
+ runner = Object.new
+
+ runner.singleton_class.define_method(:`) do |str|
+ called = true
+
+ str.should == "test command"
+ str.frozen?.should == false
+ str << "mutated"
+ end
+
+ 2.times do
+ runner.instance_exec do
+ %x{test #{:command}} # rubocop:disable Lint/LiteralInInterpolation
+ end
+ end
+
+ called.should == true
+ end
end
diff --git a/spec/ruby/language/file_spec.rb b/spec/ruby/language/file_spec.rb
index 409400ca83..dd89ce2385 100644
--- a/spec/ruby/language/file_spec.rb
+++ b/spec/ruby/language/file_spec.rb
@@ -1,29 +1,21 @@
-require File.expand_path('../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/code_loading', __FILE__)
-require File.expand_path('../shared/__FILE__', __FILE__)
+require_relative '../spec_helper'
+require_relative '../fixtures/code_loading'
+require_relative 'shared/__FILE__'
describe "The __FILE__ pseudo-variable" do
it "raises a SyntaxError if assigned to" do
- lambda { eval("__FILE__ = 1") }.should raise_error(SyntaxError)
+ -> { eval("__FILE__ = 1") }.should.raise(SyntaxError)
end
- it "equals (eval) inside an eval" do
- eval("__FILE__").should == "(eval)"
+ it "equals (eval at __FILE__:__LINE__) inside an eval" do
+ eval("__FILE__").should == "(eval at #{__FILE__}:#{__LINE__})"
end
end
-describe "The __FILE__ pseudo-variable" do
- it_behaves_like :language___FILE__, :require, CodeLoadingSpecs::Method.new
-end
-
-describe "The __FILE__ pseudo-variable" do
+describe "The __FILE__ pseudo-variable with require" do
it_behaves_like :language___FILE__, :require, Kernel
end
-describe "The __FILE__ pseudo-variable" do
- it_behaves_like :language___FILE__, :load, CodeLoadingSpecs::Method.new
-end
-
-describe "The __FILE__ pseudo-variable" do
+describe "The __FILE__ pseudo-variable with load" do
it_behaves_like :language___FILE__, :load, Kernel
end
diff --git a/spec/ruby/language/fixtures/array.rb b/spec/ruby/language/fixtures/array.rb
index 4d8ce74ed6..c1036575ff 100644
--- a/spec/ruby/language/fixtures/array.rb
+++ b/spec/ruby/language/fixtures/array.rb
@@ -8,4 +8,25 @@ module ArraySpec
[a, b, c, d]
end
end
+
+ class SideEffect
+ def initialize()
+ @call_count = 0
+ end
+
+ attr_reader :call_count
+
+ def array_result(a_number)
+ [result(a_number), result(a_number)]
+ end
+
+ def result(a_number)
+ @call_count += 1
+ if a_number
+ 1
+ else
+ :thing
+ end
+ end
+ end
end
diff --git a/spec/ruby/language/fixtures/begin_file.rb b/spec/ruby/language/fixtures/begin_file.rb
new file mode 100644
index 0000000000..73cae61a08
--- /dev/null
+++ b/spec/ruby/language/fixtures/begin_file.rb
@@ -0,0 +1,3 @@
+BEGIN {
+ puts __FILE__
+}
diff --git a/spec/ruby/language/fixtures/block.rb b/spec/ruby/language/fixtures/block.rb
index 9848d18776..33baac6aeb 100644
--- a/spec/ruby/language/fixtures/block.rb
+++ b/spec/ruby/language/fixtures/block.rb
@@ -15,6 +15,10 @@ module BlockSpecs
def r(a)
yield(*a)
end
+
+ def k(*a)
+ yield(*a, b: true)
+ end
end
# TODO: rewrite all specs that use Yield to use Yielder
diff --git a/spec/ruby/language/fixtures/break.rb b/spec/ruby/language/fixtures/break.rb
index 50e7fcf5d9..217c20a2c0 100644
--- a/spec/ruby/language/fixtures/break.rb
+++ b/spec/ruby/language/fixtures/break.rb
@@ -106,6 +106,34 @@ module BreakSpecs
note :d
end
+ def looped_break_in_captured_block
+ note :begin
+ looped_delegate_block do |i|
+ note :prebreak
+ break if i == 1
+ note :postbreak
+ end
+ note :end
+ end
+
+ def looped_delegate_block(&block)
+ note :preloop
+ 2.times do |i|
+ note :predele
+ yield_value(i, &block)
+ note :postdele
+ end
+ note :postloop
+ end
+ private :looped_delegate_block
+
+ def yield_value(value)
+ note :preyield
+ yield value
+ note :postyield
+ end
+ private :yield_value
+
def method(v)
yield v
end
@@ -135,7 +163,7 @@ module BreakSpecs
# on the call stack when the lambda is invoked.
def break_in_defining_scope(value=true)
note :a
- note lambda {
+ note -> {
note :b
if value
break :break
@@ -149,7 +177,7 @@ module BreakSpecs
def break_in_nested_scope
note :a
- l = lambda do
+ l = -> do
note :b
break :break
note :c
@@ -169,7 +197,7 @@ module BreakSpecs
def break_in_nested_scope_yield
note :a
- l = lambda do
+ l = -> do
note :b
break :break
note :c
@@ -189,7 +217,7 @@ module BreakSpecs
def break_in_nested_scope_block
note :a
- l = lambda do
+ l = -> do
note :b
break :break
note :c
@@ -223,7 +251,7 @@ module BreakSpecs
# active on the call stack when the lambda is invoked.
def create_lambda
note :la
- l = lambda do
+ l = -> do
note :lb
break :break
note :lc
diff --git a/spec/ruby/language/fixtures/break_lambda_toplevel.rb b/spec/ruby/language/fixtures/break_lambda_toplevel.rb
index 05af1d3fdc..da5abbaf00 100644
--- a/spec/ruby/language/fixtures/break_lambda_toplevel.rb
+++ b/spec/ruby/language/fixtures/break_lambda_toplevel.rb
@@ -1,6 +1,6 @@
print "a,"
-print lambda {
+print -> {
print "b,"
break "break,"
print "c,"
diff --git a/spec/ruby/language/fixtures/break_lambda_toplevel_block.rb b/spec/ruby/language/fixtures/break_lambda_toplevel_block.rb
index a35cb8a8a1..3dcee62424 100644
--- a/spec/ruby/language/fixtures/break_lambda_toplevel_block.rb
+++ b/spec/ruby/language/fixtures/break_lambda_toplevel_block.rb
@@ -1,6 +1,6 @@
print "a,"
-l = lambda {
+l = -> {
print "b,"
break "break,"
print "c,"
diff --git a/spec/ruby/language/fixtures/break_lambda_toplevel_method.rb b/spec/ruby/language/fixtures/break_lambda_toplevel_method.rb
index 200040d614..a5936a3d70 100644
--- a/spec/ruby/language/fixtures/break_lambda_toplevel_method.rb
+++ b/spec/ruby/language/fixtures/break_lambda_toplevel_method.rb
@@ -1,6 +1,6 @@
print "a,"
-l = lambda {
+l = -> {
print "b,"
break "break,"
print "c,"
diff --git a/spec/ruby/language/fixtures/bytes_magic_comment.rb b/spec/ruby/language/fixtures/bytes_magic_comment.rb
new file mode 100644
index 0000000000..2bc2bcfb07
--- /dev/null
+++ b/spec/ruby/language/fixtures/bytes_magic_comment.rb
@@ -0,0 +1,2 @@
+# encoding: big5
+$magic_comment_result = '§A¦n'.bytes.inspect
diff --git a/spec/ruby/language/fixtures/case_magic_comment.rb b/spec/ruby/language/fixtures/case_magic_comment.rb
new file mode 100644
index 0000000000..96f35a7c94
--- /dev/null
+++ b/spec/ruby/language/fixtures/case_magic_comment.rb
@@ -0,0 +1,2 @@
+# CoDiNg: bIg5
+$magic_comment_result = __ENCODING__.name
diff --git a/spec/ruby/language/fixtures/class_with_class_variable.rb b/spec/ruby/language/fixtures/class_with_class_variable.rb
new file mode 100644
index 0000000000..0b07f16d30
--- /dev/null
+++ b/spec/ruby/language/fixtures/class_with_class_variable.rb
@@ -0,0 +1,9 @@
+module StringSpecs
+ class ClassWithClassVariable
+ @@a = "xxx"
+
+ def foo
+ "#@@a"
+ end
+ end
+end
diff --git a/spec/ruby/language/fixtures/constant_visibility.rb b/spec/ruby/language/fixtures/constant_visibility.rb
index 022554430e..af38b2d8f2 100644
--- a/spec/ruby/language/fixtures/constant_visibility.rb
+++ b/spec/ruby/language/fixtures/constant_visibility.rb
@@ -65,7 +65,7 @@ module ConstantVisibility
end
end
- class PrivConstModuleChild
+ class ClassIncludingPrivConstModule
include PrivConstModule
def private_constant_from_include
@@ -77,6 +77,22 @@ module ConstantVisibility
end
end
+ module ModuleIncludingPrivConstModule
+ include PrivConstModule
+
+ def self.private_constant_from_include
+ PRIVATE_CONSTANT_MODULE
+ end
+
+ def self.private_constant_self_from_include
+ self::PRIVATE_CONSTANT_MODULE
+ end
+
+ def self.private_constant_named_from_include
+ PrivConstModule::PRIVATE_CONSTANT_MODULE
+ end
+ end
+
class PrivConstClassChild < PrivConstClass
def private_constant_from_subclass
PRIVATE_CONSTANT_CLASS
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..15bd7c50cf 100644
--- a/spec/ruby/language/fixtures/defined.rb
+++ b/spec/ruby/language/fixtures/defined.rb
@@ -19,6 +19,9 @@ module DefinedSpecs
DefinedSpecs
end
+ def self.any_args(*)
+ end
+
class Basic
A = 42
@@ -94,6 +97,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
@@ -277,6 +285,12 @@ module DefinedSpecs
end
end
+ module ModuleWithConstMissing
+ def self.const_missing(const)
+ const
+ end
+ end
+
class SuperWithIntermediateModules
include IntermediateModule1
include IntermediateModule2
@@ -285,6 +299,33 @@ module DefinedSpecs
super
end
end
+
+ class ProtectedBase
+ def m; end
+ protected :m
+ def defined_on(o)
+ defined?(o.m)
+ end
+ end
+
+ class ProtectedSubclass < ProtectedBase
+ end
+
+ module ProtectedInModule
+ def m; end
+ protected :m
+ def defined_on(o)
+ defined?(o.m)
+ end
+ end
+
+ class ProtectedIncluderA
+ include ProtectedInModule
+ end
+
+ class ProtectedIncluderB
+ include ProtectedInModule
+ end
end
class Object
diff --git a/spec/ruby/language/fixtures/delegation.rb b/spec/ruby/language/fixtures/delegation.rb
new file mode 100644
index 0000000000..049a923e66
--- /dev/null
+++ b/spec/ruby/language/fixtures/delegation.rb
@@ -0,0 +1,15 @@
+module DelegationSpecs
+ class Target
+ def target(*args, **kwargs, &block)
+ [args, kwargs, block]
+ end
+
+ def target_block(*args, **kwargs)
+ yield [kwargs, args]
+ end
+
+ def target_single(arg)
+ arg
+ end
+ end
+end
diff --git a/spec/ruby/language/fixtures/emacs_magic_comment.rb b/spec/ruby/language/fixtures/emacs_magic_comment.rb
new file mode 100644
index 0000000000..2b09f3e74c
--- /dev/null
+++ b/spec/ruby/language/fixtures/emacs_magic_comment.rb
@@ -0,0 +1,2 @@
+# -*- encoding: big5 -*-
+$magic_comment_result = __ENCODING__.name
diff --git a/spec/ruby/language/fixtures/ensure.rb b/spec/ruby/language/fixtures/ensure.rb
index 0dad7d8401..6047ac5bc0 100644
--- a/spec/ruby/language/fixtures/ensure.rb
+++ b/spec/ruby/language/fixtures/ensure.rb
@@ -8,7 +8,7 @@ module EnsureSpec
def raise_in_method_with_ensure
@executed << :method
- raise "An Exception"
+ raise EnsureSpec::Error
ensure
@executed << :ensure
end
@@ -40,6 +40,50 @@ module EnsureSpec
ensure
return :ensure
end
+
+ def explicit_return_in_rescue_and_explicit_return_in_ensure
+ raise
+ rescue
+ return 2
+ ensure
+ return "returned in ensure"
+ end
+
+ def explicit_return_in_rescue_and_implicit_return_in_ensure
+ raise
+ rescue
+ return "returned in rescue"
+ ensure
+ 3
+ end
+
+ def raise_and_explicit_return_in_ensure
+ raise
+ ensure
+ return "returned in ensure"
+ end
+
+ def raise_in_rescue_and_explicit_return_in_ensure
+ raise
+ rescue
+ raise
+ ensure
+ return "returned in ensure"
+ end
+
+ def raise_in_rescue_and_raise_in_ensure
+ raise
+ rescue
+ raise "raised in rescue"
+ ensure
+ raise "raised in ensure"
+ end
+
+ def raise_in_method_and_raise_in_ensure
+ raise
+ ensure
+ raise "raised in ensure"
+ end
end
end
@@ -70,3 +114,8 @@ module EnsureSpec
end
end
end
+
+module EnsureSpec
+ class Error < RuntimeError
+ end
+end
diff --git a/spec/ruby/language/fixtures/for_scope.rb b/spec/ruby/language/fixtures/for_scope.rb
new file mode 100644
index 0000000000..9c44a23a2c
--- /dev/null
+++ b/spec/ruby/language/fixtures/for_scope.rb
@@ -0,0 +1,15 @@
+module ForSpecs
+ class ForInClassMethod
+ m = :same_variable_set_outside
+
+ def self.foo
+ all = []
+ for m in [:bar, :baz]
+ all << m
+ end
+ all
+ end
+
+ READER = -> { m }
+ end
+end
diff --git a/spec/ruby/language/fixtures/freeze_magic_comment_across_files.rb b/spec/ruby/language/fixtures/freeze_magic_comment_across_files.rb
index 3aed2f29b6..f3ef666a3c 100644
--- a/spec/ruby/language/fixtures/freeze_magic_comment_across_files.rb
+++ b/spec/ruby/language/fixtures/freeze_magic_comment_across_files.rb
@@ -2,4 +2,5 @@
require_relative 'freeze_magic_comment_required'
-p "abc".object_id == $second_literal_id
+p "abc".equal?($second_literal)
+$second_literal = nil
diff --git a/spec/ruby/language/fixtures/freeze_magic_comment_across_files_diff_enc.rb b/spec/ruby/language/fixtures/freeze_magic_comment_across_files_diff_enc.rb
index 53ef959970..e9ca35e7c8 100644
--- a/spec/ruby/language/fixtures/freeze_magic_comment_across_files_diff_enc.rb
+++ b/spec/ruby/language/fixtures/freeze_magic_comment_across_files_diff_enc.rb
@@ -2,4 +2,5 @@
require_relative 'freeze_magic_comment_required_diff_enc'
-p "abc".object_id != $second_literal_id
+p !"abc".equal?($second_literal)
+$second_literal = nil
diff --git a/spec/ruby/language/fixtures/freeze_magic_comment_across_files_no_comment.rb b/spec/ruby/language/fixtures/freeze_magic_comment_across_files_no_comment.rb
index fc6cd5bf82..c9eaab46a2 100644
--- a/spec/ruby/language/fixtures/freeze_magic_comment_across_files_no_comment.rb
+++ b/spec/ruby/language/fixtures/freeze_magic_comment_across_files_no_comment.rb
@@ -2,4 +2,5 @@
require_relative 'freeze_magic_comment_required_no_comment'
-p "abc".object_id != $second_literal_id
+p !"abc".equal?($second_literal)
+$second_literal = nil
diff --git a/spec/ruby/language/fixtures/freeze_magic_comment_one_literal.rb b/spec/ruby/language/fixtures/freeze_magic_comment_one_literal.rb
index d35905b332..c175b2b7a2 100644
--- a/spec/ruby/language/fixtures/freeze_magic_comment_one_literal.rb
+++ b/spec/ruby/language/fixtures/freeze_magic_comment_one_literal.rb
@@ -1,4 +1,4 @@
# frozen_string_literal: true
-ids = Array.new(2) { "abc".object_id }
-p ids.first == ids.last
+objs = Array.new(2) { "abc" }
+p objs.first.equal?(objs.last)
diff --git a/spec/ruby/language/fixtures/freeze_magic_comment_required.rb b/spec/ruby/language/fixtures/freeze_magic_comment_required.rb
index a4ff4459b1..f75acb2ce3 100644
--- a/spec/ruby/language/fixtures/freeze_magic_comment_required.rb
+++ b/spec/ruby/language/fixtures/freeze_magic_comment_required.rb
@@ -1,3 +1,3 @@
# frozen_string_literal: true
-$second_literal_id = "abc".object_id
+$second_literal = "abc"
diff --git a/spec/ruby/language/fixtures/freeze_magic_comment_required_diff_enc.rb b/spec/ruby/language/fixtures/freeze_magic_comment_required_diff_enc.rb
index d0558a2251..739e96e99a 100644
--- a/spec/ruby/language/fixtures/freeze_magic_comment_required_diff_enc.rb
+++ b/spec/ruby/language/fixtures/freeze_magic_comment_required_diff_enc.rb
Binary files differ
diff --git a/spec/ruby/language/fixtures/freeze_magic_comment_required_no_comment.rb b/spec/ruby/language/fixtures/freeze_magic_comment_required_no_comment.rb
index e09232a5f4..6fbe175b42 100644
--- a/spec/ruby/language/fixtures/freeze_magic_comment_required_no_comment.rb
+++ b/spec/ruby/language/fixtures/freeze_magic_comment_required_no_comment.rb
@@ -1 +1 @@
-$second_literal_id = "abc".object_id
+$second_literal = "abc"
diff --git a/spec/ruby/language/fixtures/freeze_magic_comment_two_literals.rb b/spec/ruby/language/fixtures/freeze_magic_comment_two_literals.rb
index a4d655ad02..cccc5969bd 100644
--- a/spec/ruby/language/fixtures/freeze_magic_comment_two_literals.rb
+++ b/spec/ruby/language/fixtures/freeze_magic_comment_two_literals.rb
@@ -1,3 +1,3 @@
# frozen_string_literal: true
-p "abc".object_id == "abc".object_id
+p "abc".equal?("abc")
diff --git a/spec/ruby/language/fixtures/hash_strings_ascii8bit.rb b/spec/ruby/language/fixtures/hash_strings_ascii8bit.rb
deleted file mode 100644
index 4ac11b9930..0000000000
--- a/spec/ruby/language/fixtures/hash_strings_ascii8bit.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-# encoding: ascii-8bit
-
-module HashStringsASCII8BIT
- def self.literal_hash
- {"foo" => "bar"}
- end
-end
diff --git a/spec/ruby/language/fixtures/hash_strings_binary.rb b/spec/ruby/language/fixtures/hash_strings_binary.rb
new file mode 100644
index 0000000000..44b99cbf80
--- /dev/null
+++ b/spec/ruby/language/fixtures/hash_strings_binary.rb
@@ -0,0 +1,7 @@
+# encoding: binary
+
+module HashStringsBinary
+ def self.literal_hash
+ {"foo" => "bar"}
+ end
+end
diff --git a/spec/ruby/language/fixtures/magic_comment.rb b/spec/ruby/language/fixtures/magic_comment.rb
new file mode 100644
index 0000000000..120ef6ff4a
--- /dev/null
+++ b/spec/ruby/language/fixtures/magic_comment.rb
@@ -0,0 +1,2 @@
+# encoding: big5
+$magic_comment_result = __ENCODING__.name
diff --git a/spec/ruby/language/fixtures/metaclass.rb b/spec/ruby/language/fixtures/metaclass.rb
index a1990b9225..a8f837e701 100644
--- a/spec/ruby/language/fixtures/metaclass.rb
+++ b/spec/ruby/language/fixtures/metaclass.rb
@@ -31,4 +31,3 @@ module MetaClassSpecs
class D < C; end
end
-
diff --git a/spec/ruby/language/fixtures/module.rb b/spec/ruby/language/fixtures/module.rb
index 33d323846e..75eee77791 100644
--- a/spec/ruby/language/fixtures/module.rb
+++ b/spec/ruby/language/fixtures/module.rb
@@ -12,13 +12,4 @@ module ModuleSpecs
module Anonymous
end
-
- module IncludedInObject
- module IncludedModuleSpecs
- end
- end
-end
-
-class Object
- include ModuleSpecs::IncludedInObject
end
diff --git a/spec/ruby/language/fixtures/no_magic_comment.rb b/spec/ruby/language/fixtures/no_magic_comment.rb
new file mode 100644
index 0000000000..743a0f9503
--- /dev/null
+++ b/spec/ruby/language/fixtures/no_magic_comment.rb
@@ -0,0 +1 @@
+$magic_comment_result = __ENCODING__.name
diff --git a/spec/ruby/language/fixtures/print_magic_comment_result_at_exit.rb b/spec/ruby/language/fixtures/print_magic_comment_result_at_exit.rb
new file mode 100644
index 0000000000..aa82cf4471
--- /dev/null
+++ b/spec/ruby/language/fixtures/print_magic_comment_result_at_exit.rb
@@ -0,0 +1,3 @@
+at_exit {
+ print $magic_comment_result
+}
diff --git a/spec/ruby/language/fixtures/private.rb b/spec/ruby/language/fixtures/private.rb
index 96f73cea3f..da3e0a97f9 100644
--- a/spec/ruby/language/fixtures/private.rb
+++ b/spec/ruby/language/fixtures/private.rb
@@ -43,17 +43,17 @@ module Private
end
end
- class E
- include D
- end
-
- class G
- def foo
- "foo"
- end
- end
-
- class H < A
- private :foo
- end
+ class E
+ include D
+ end
+
+ class G
+ def foo
+ "foo"
+ end
+ end
+
+ class H < A
+ private :foo
+ end
end
diff --git a/spec/ruby/language/fixtures/rescue.rb b/spec/ruby/language/fixtures/rescue.rb
index 3fa5df1eb5..b906e17a2f 100644
--- a/spec/ruby/language/fixtures/rescue.rb
+++ b/spec/ruby/language/fixtures/rescue.rb
@@ -60,4 +60,8 @@ module RescueSpecs
ScratchPad << :outside_begin
:return_val
end
+
+ def self.raise_standard_error
+ raise StandardError, "an error occurred"
+ end
end
diff --git a/spec/ruby/language/fixtures/rescue/top_level.rb b/spec/ruby/language/fixtures/rescue/top_level.rb
new file mode 100644
index 0000000000..59e78ef1d6
--- /dev/null
+++ b/spec/ruby/language/fixtures/rescue/top_level.rb
@@ -0,0 +1,7 @@
+# capturing in local variable at top-level
+
+begin
+ raise "message"
+rescue => e
+ ScratchPad << e.message
+end
diff --git a/spec/ruby/language/fixtures/rescue_captures.rb b/spec/ruby/language/fixtures/rescue_captures.rb
new file mode 100644
index 0000000000..69f9b83904
--- /dev/null
+++ b/spec/ruby/language/fixtures/rescue_captures.rb
@@ -0,0 +1,107 @@
+module RescueSpecs
+ class Captor
+ attr_accessor :captured_error
+
+ def self.should_capture_exception
+ captor = new
+ captor.capture('some text').should == :caught # Ensure rescue body still runs
+ captor.captured_error.message.should == 'some text'
+ end
+ end
+
+ class ClassVariableCaptor < Captor
+ def capture(msg)
+ raise msg
+ rescue => @@captured_error
+ :caught
+ end
+
+ def captured_error
+ self.class.remove_class_variable(:@@captured_error)
+ end
+ end
+
+ class ConstantCaptor < Captor
+ # Using lambda gets around the dynamic constant assignment warning
+ CAPTURE = -> msg {
+ begin
+ raise msg
+ rescue => CapturedError
+ :caught
+ end
+ }
+
+ def capture(msg)
+ CAPTURE.call(msg)
+ end
+
+ def captured_error
+ self.class.send(:remove_const, :CapturedError)
+ end
+ end
+
+ class GlobalVariableCaptor < Captor
+ def capture(msg)
+ raise msg
+ rescue => $captured_error
+ :caught
+ end
+
+ def captured_error
+ $captured_error.tap do
+ $captured_error = nil # Can't remove globals, only nil them out
+ end
+ end
+ end
+
+ class InstanceVariableCaptor < Captor
+ def capture(msg)
+ raise msg
+ rescue => @captured_error
+ :caught
+ end
+ end
+
+ class LocalVariableCaptor < Captor
+ def capture(msg)
+ raise msg
+ rescue => captured_error
+ @captured_error = captured_error
+ :caught
+ end
+ end
+
+ class SafeNavigationSetterCaptor < Captor
+ def capture(msg)
+ raise msg
+ rescue => self&.captured_error
+ :caught
+ end
+ end
+
+ class SetterCaptor < Captor
+ def capture(msg)
+ raise msg
+ rescue => self.captured_error
+ :caught
+ end
+ end
+
+ class SquareBracketsCaptor < Captor
+ def capture(msg)
+ @hash = {}
+
+ raise msg
+ rescue => self[:error]
+ :caught
+ end
+
+ def []=(key, value)
+ @hash[key] = value
+ end
+
+ def captured_error
+ @hash[:error]
+ end
+ end
+end
diff --git a/spec/ruby/language/fixtures/return.rb b/spec/ruby/language/fixtures/return.rb
index 0414c356e8..f6b143f3fa 100644
--- a/spec/ruby/language/fixtures/return.rb
+++ b/spec/ruby/language/fixtures/return.rb
@@ -101,18 +101,14 @@ module ReturnSpecs
# return value will go into val before we run the ensure.
#
# If lamb's return keeps unwinding incorrectly, val will still
- # have it's old value.
+ # have its old value.
#
# We can therefore use val to figure out what happened.
begin
val = foo()
ensure
- if val != :good
- return :bad
- end
+ return val
end
-
- return val
end
end
diff --git a/spec/ruby/language/fixtures/second_line_magic_comment.rb b/spec/ruby/language/fixtures/second_line_magic_comment.rb
new file mode 100644
index 0000000000..a3dd50393b
--- /dev/null
+++ b/spec/ruby/language/fixtures/second_line_magic_comment.rb
@@ -0,0 +1,3 @@
+
+# encoding: big5
+$magic_comment_result = __ENCODING__.name
diff --git a/spec/ruby/language/fixtures/second_token_magic_comment.rb b/spec/ruby/language/fixtures/second_token_magic_comment.rb
new file mode 100644
index 0000000000..8d443e68f3
--- /dev/null
+++ b/spec/ruby/language/fixtures/second_token_magic_comment.rb
@@ -0,0 +1,2 @@
+1 + 1 # encoding: big5
+$magic_comment_result = __ENCODING__.name
diff --git a/spec/ruby/language/fixtures/send.rb b/spec/ruby/language/fixtures/send.rb
index c3013616b2..4787abee5c 100644
--- a/spec/ruby/language/fixtures/send.rb
+++ b/spec/ruby/language/fixtures/send.rb
@@ -43,9 +43,9 @@ module LangSendSpecs
attr_writer :foo
private :foo=
- def call_self_foo_equals(value)
- self.foo = value
- end
+ def call_self_foo_equals(value)
+ self.foo = value
+ end
def call_self_foo_equals_masgn(value)
a, self.foo = 1, value
@@ -53,8 +53,9 @@ module LangSendSpecs
end
class PrivateGetter
- attr_reader :foo
+ attr_accessor :foo
private :foo
+ private :foo=
def call_self_foo
self.foo
@@ -80,6 +81,16 @@ module LangSendSpecs
end
end
+ class RawToProc
+ def initialize(to_proc)
+ @to_proc = to_proc
+ end
+
+ def to_proc
+ @to_proc
+ end
+ end
+
class ToAry
def initialize(obj)
@obj = obj
diff --git a/spec/ruby/language/fixtures/shebang_magic_comment.rb b/spec/ruby/language/fixtures/shebang_magic_comment.rb
new file mode 100755
index 0000000000..f8e5e7d8e4
--- /dev/null
+++ b/spec/ruby/language/fixtures/shebang_magic_comment.rb
@@ -0,0 +1,3 @@
+#!/usr/bin/ruby
+# encoding: big5
+$magic_comment_result = __ENCODING__.name
diff --git a/spec/ruby/language/fixtures/squiggly_heredoc.rb b/spec/ruby/language/fixtures/squiggly_heredoc.rb
index afc87514c7..984a629e5b 100644
--- a/spec/ruby/language/fixtures/squiggly_heredoc.rb
+++ b/spec/ruby/language/fixtures/squiggly_heredoc.rb
@@ -29,6 +29,22 @@ module SquigglyHeredocSpecs
HERE
end
+ def self.backslash
+ <<~HERE
+ a
+ b\
+ c
+ HERE
+ end
+
+ def self.least_indented_on_the_first_line
+ <<~HERE
+ a
+ b
+ c
+ HERE
+ end
+
def self.least_indented_on_the_last_line
<<~HERE
a
@@ -36,4 +52,20 @@ module SquigglyHeredocSpecs
c
HERE
end
+
+ def self.least_indented_on_the_first_line_single
+ <<~'HERE'
+ a
+ b
+ c
+ HERE
+ end
+
+ def self.least_indented_on_the_last_line_single
+ <<~'HERE'
+ a
+ b
+ c
+ HERE
+ end
end
diff --git a/spec/ruby/language/fixtures/super.rb b/spec/ruby/language/fixtures/super.rb
index 09a454bdf4..b6d4218b03 100644
--- a/spec/ruby/language/fixtures/super.rb
+++ b/spec/ruby/language/fixtures/super.rb
@@ -1,4 +1,4 @@
-module Super
+module SuperSpecs
module S1
class A
def foo(a)
@@ -266,7 +266,7 @@ module Super
# Use this so that we can see collect all supers that we see.
# One bug that arises is that we call Alias2#name from Alias2#name
- # as it's superclass. In that case, either we get a runaway recursion
+ # as its superclass. In that case, either we get a runaway recursion
# super OR we get the return value being [:alias2, :alias2, :alias1]
# rather than [:alias2, :alias1].
#
@@ -282,7 +282,7 @@ module Super
#
# When name3 is called then, Alias2 (NOT Alias3) is presented as the
# current module to Alias2#name, so that when super is called,
- # Alias2->superclass is next.
+ # Alias2's superclass is next.
#
# Otherwise, Alias2 is next, which is where name was to begin with,
# causing the wrong #name method to be called.
@@ -377,12 +377,12 @@ module Super
end
def b
- block_ref = lambda { 15 }
+ block_ref = -> { 15 }
[super { 14 }, super(&block_ref)]
end
def c
- block_ref = lambda { 16 }
+ block_ref = -> { 16 }
super(&block_ref)
end
end
@@ -455,12 +455,114 @@ module Super
end
end
+ module ZSuperWithRestAndPost
+ class A
+ def m(*args, a, b)
+ args
+ end
+
+ def m_modified(*args, a, b)
+ args
+ end
+ end
+
+ class B < A
+ def m(*args, a, b)
+ super
+ end
+
+ def m_modified(*args, a, b)
+ args[1] = 14
+ super
+ end
+ end
+ end
+
+ module ZSuperWithRestOthersAndPost
+ class A
+ def m(a, *args, b)
+ args
+ end
+
+ def m_modified(a, *args, b)
+ args
+ end
+ end
+
+ class B < A
+ def m(a, *args, b)
+ super
+ end
+
+ def m_modified(a, *args, b)
+ args[1] = 14
+ super
+ end
+ end
+ end
+
+ module ZSuperWithRestReassigned
+ class A
+ def a(*args)
+ args
+ end
+ end
+
+ class B < A
+ def a(*args)
+ args = ["foo"]
+
+ super
+ end
+ end
+ end
+
+ module ZSuperWithRestReassignedWithScalar
+ class A
+ def a(*args)
+ args
+ end
+ end
+
+ class B < A
+ def a(*args)
+ args = "foo"
+
+ super
+ end
+ end
+ end
+
module ZSuperWithUnderscores
class A
def m(*args)
args
end
+ def m3(*args)
+ args
+ end
+
+ def m4(*args)
+ args
+ end
+
+ def m_default(*args)
+ args
+ end
+
+ def m_rest(*args)
+ args
+ end
+
+ def m_pre_default_rest_post(*args)
+ args
+ end
+
+ def m_kwrest(**kw)
+ kw
+ end
+
def m_modified(*args)
args
end
@@ -471,6 +573,30 @@ module Super
super
end
+ def m3(_, _, _)
+ super
+ end
+
+ def m4(_, _, _, _)
+ super
+ end
+
+ def m_default(_ = 0)
+ super
+ end
+
+ def m_rest(*_)
+ super
+ end
+
+ def m_pre_default_rest_post(_, _, _=:a, _=:b, *_, _, _)
+ super
+ end
+
+ def m_kwrest(**_)
+ super
+ end
+
def m_modified(_, _)
_ = 14
super
@@ -478,6 +604,20 @@ module Super
end
end
+ module ZSuperInBlock
+ class A
+ def m(arg:)
+ arg
+ end
+ end
+
+ class B < A
+ def m(arg:)
+ proc { super }.call
+ end
+ end
+ end
+
module Keywords
class Arguments
def foo(**args)
diff --git a/spec/ruby/language/fixtures/utf16-be-nobom.rb b/spec/ruby/language/fixtures/utf16-be-nobom.rb
new file mode 100644
index 0000000000..99e2ce8ce8
--- /dev/null
+++ b/spec/ruby/language/fixtures/utf16-be-nobom.rb
Binary files differ
diff --git a/spec/ruby/language/fixtures/utf16-le-nobom.rb b/spec/ruby/language/fixtures/utf16-le-nobom.rb
new file mode 100644
index 0000000000..98de9697ca
--- /dev/null
+++ b/spec/ruby/language/fixtures/utf16-le-nobom.rb
Binary files differ
diff --git a/spec/ruby/language/fixtures/utf8-bom.rb b/spec/ruby/language/fixtures/utf8-bom.rb
new file mode 100644
index 0000000000..50c223a922
--- /dev/null
+++ b/spec/ruby/language/fixtures/utf8-bom.rb
@@ -0,0 +1,2 @@
+# encoding: utf-8
+puts 'hello'
diff --git a/spec/ruby/language/fixtures/utf8-nobom.rb b/spec/ruby/language/fixtures/utf8-nobom.rb
new file mode 100644
index 0000000000..75f5563b95
--- /dev/null
+++ b/spec/ruby/language/fixtures/utf8-nobom.rb
@@ -0,0 +1,2 @@
+# encoding: utf-8
+puts 'hello'
diff --git a/spec/ruby/language/fixtures/variables.rb b/spec/ruby/language/fixtures/variables.rb
index 07265dbb2b..527caa7a78 100644
--- a/spec/ruby/language/fixtures/variables.rb
+++ b/spec/ruby/language/fixtures/variables.rb
@@ -82,4 +82,76 @@ module VariablesSpecs
def self.false
false
end
+
+ class EvalOrder
+ attr_reader :order
+
+ def initialize
+ @order = []
+ end
+
+ def reset
+ @order = []
+ end
+
+ def foo
+ self << "foo"
+ FooClass.new(self)
+ end
+
+ def bar
+ self << "bar"
+ BarClass.new(self)
+ end
+
+ def a
+ self << "a"
+ end
+
+ def b
+ self << "b"
+ end
+
+ def node
+ self << "node"
+
+ node = Node.new
+ node.left = Node.new
+ node.left.right = Node.new
+
+ node
+ end
+
+ def <<(value)
+ order << value
+ end
+
+ class FooClass
+ attr_reader :evaluator
+
+ def initialize(evaluator)
+ @evaluator = evaluator
+ end
+
+ def []=(_index, _value)
+ evaluator << "foo[]="
+ end
+ end
+
+ class BarClass
+ attr_reader :evaluator
+
+ def initialize(evaluator)
+ @evaluator = evaluator
+ end
+
+ def baz=(_value)
+ evaluator << "bar.baz="
+ end
+ end
+
+ class Node
+ attr_accessor :left, :right
+ end
+ end
end
diff --git a/spec/ruby/language/fixtures/vim_magic_comment.rb b/spec/ruby/language/fixtures/vim_magic_comment.rb
new file mode 100644
index 0000000000..60cbe7a3bf
--- /dev/null
+++ b/spec/ruby/language/fixtures/vim_magic_comment.rb
@@ -0,0 +1,2 @@
+# vim: filetype=ruby, fileencoding=big5, tabsize=3, shiftwidth=3
+$magic_comment_result = __ENCODING__.name
diff --git a/spec/ruby/language/fixtures/yield.rb b/spec/ruby/language/fixtures/yield.rb
index a195616640..9f7a2ba238 100644
--- a/spec/ruby/language/fixtures/yield.rb
+++ b/spec/ruby/language/fixtures/yield.rb
@@ -21,6 +21,10 @@ module YieldSpecs
yield(*a)
end
+ def k(a)
+ yield(*a, b: true)
+ end
+
def rs(a, b, c)
yield(a, b, *c)
end
diff --git a/spec/ruby/language/for_spec.rb b/spec/ruby/language/for_spec.rb
index c9d043fa25..b0f3aef405 100644
--- a/spec/ruby/language/for_spec.rb
+++ b/spec/ruby/language/for_spec.rb
@@ -1,4 +1,5 @@
-require File.expand_path('../../spec_helper', __FILE__)
+require_relative '../spec_helper'
+require_relative 'fixtures/for_scope'
# for name[, name]... in expr [do]
# body
@@ -18,6 +19,27 @@ describe "The for expression" do
end
end
+ it "iterates over a list of arrays and destructures with an empty splat" do
+ for i, * in [[1,2]]
+ i.should == 1
+ end
+ end
+
+ it "iterates over a list of arrays and destructures with a splat" do
+ for i, *j in [[1,2]]
+ i.should == 1
+ j.should == [2]
+ end
+ end
+
+ it "iterates over a list of arrays and destructures with a splat and additional targets" do
+ for i, *j, k in [[1,2,3,4]]
+ i.should == 1
+ j.should == [2,3]
+ k.should == 4
+ end
+ end
+
it "iterates over an Hash passing each key-value pair to the block" do
k = 0
l = 0
@@ -32,14 +54,13 @@ describe "The for expression" do
end
it "iterates over any object responding to 'each'" do
- class XYZ
- def each
- (0..10).each { |i| yield i }
- end
+ obj = Object.new
+ def obj.each
+ (0..10).each { |i| yield i }
end
j = 0
- for i in XYZ.new
+ for i in obj
j += i
end
j.should == 55
@@ -81,6 +102,85 @@ describe "The for expression" do
end
end
+ it "allows a global variable as an iterator name" do
+ old_global_var = $var
+ m = [1,2,3]
+ n = 0
+ for $var in m
+ n += 1
+ end
+ $var.should == 3
+ n.should == 3
+ $var = old_global_var
+ end
+
+ it "allows an attribute as an iterator name" do
+ class OFor
+ attr_accessor :target
+ end
+
+ ofor = OFor.new
+ m = [1,2,3]
+ n = 0
+ for ofor.target in m
+ n += 1
+ end
+ ofor.target.should == 3
+ n.should == 3
+ end
+
+ it "allows an attribute with safe navigation as an iterator name" do
+ class OFor
+ attr_accessor :target
+ end
+
+ ofor = OFor.new
+ m = [1,2,3]
+ n = 0
+ eval <<~RUBY
+ for ofor&.target in m
+ n += 1
+ end
+ RUBY
+ ofor.target.should == 3
+ n.should == 3
+ end
+
+ it "allows an attribute with safe navigation on a nil base as an iterator name" do
+ ofor = nil
+ m = [1,2,3]
+ n = 0
+ eval <<~RUBY
+ for ofor&.target in m
+ n += 1
+ end
+ RUBY
+ ofor.should == nil
+ n.should == 3
+ end
+
+ it "allows an array index writer as an iterator name" do
+ arr = [:a, :b, :c]
+ m = [1,2,3]
+ n = 0
+ for arr[1] in m
+ n += 1
+ end
+ arr.should == [:a, 3, :c]
+ n.should == 3
+ end
+
+ it "allows a hash index writer as an iterator name" do
+ hash = { a: 10, b: 20, c: 30 }
+ m = [1,2,3]
+ n = 0
+ for hash[:b] in m
+ n += 1
+ end
+ hash.should == { a: 10, b: 3, c: 30 }
+ n.should == 3
+ end
+
# 1.9 behaviour verified by nobu in
# http://redmine.ruby-lang.org/issues/show/2053
it "yields only as many values as there are arguments" do
@@ -115,7 +215,15 @@ describe "The for expression" do
j.should == 6
end
- it "executes code in containing variable scope" do
+ it "declares iteration variables in the surrounding variable scope" do
+ for a, b in [[1,2]]
+ end
+
+ a.should == 1
+ b.should == 2
+ end
+
+ it "declares variables in the body in the surrounding variable scope" do
for i in 1..2
a = 123
end
@@ -123,7 +231,7 @@ describe "The for expression" do
a.should == 123
end
- it "executes code in containing variable scope with 'do'" do
+ it "declares variables in the body in the surrounding variable scope with 'do'" do
for i in 1..2 do
a = 123
end
@@ -131,6 +239,101 @@ describe "The for expression" do
a.should == 123
end
+ it "declares variables inside a block as normal" do
+ for i in 1..2 do
+ proc {
+ inside_proc = 42
+ }.call
+ end
+ local_variables.should == [:i]
+ end
+
+ it "declares variables inside a lambda as normal" do
+ for i in 1..2 do
+ -> {
+ inside_proc = 42
+ }.call
+ end
+ local_variables.should == [:i]
+ end
+
+ it "can be nested" do
+ for a in [6]
+ for b in [7]
+ c = a * b
+ end
+ end
+ local_variables.sort.should == [:a, :b, :c]
+ c.should == 42
+ end
+
+ it "can be nested with blocks in between" do
+ # This is an edge case spec for Ruby implementations which have
+ # their own runtime scope per for loop body (like YARV and TruffleRuby)
+ for a in [1]
+ a1 = a
+ a1.should == a
+ for b in [2]
+ b1 = b
+ a1.should == a
+ b1.should == b
+ proc {
+ inside_proc = 42
+
+ a1.should == a
+ b1.should == b
+ inside_proc.should == 42
+
+ for c in [3].map { |enum_var|
+ a1.should == a
+ b1.should == b
+ inside_proc.should == 42
+ enum_var
+ }
+ c1 = c
+
+ a1.should == a
+ b1.should == b
+ c1.should == c
+ inside_proc.should == 42
+
+ for d in [4]
+ d1 = d
+
+ a1.should == a
+ b1.should == b
+ c1.should == c
+ d1.should == d
+ inside_proc.should == 42
+ end
+ end
+ local_variables.sort.should == [:a, :a1, :b, :b1, :c, :c1, :d, :d1, :inside_proc]
+ }.call
+ end
+ end
+ local_variables.sort.should == [:a, :a1, :b, :b1]
+ end
+
+ it "can be nested with forward arguments" do
+ def bar(*args)
+ args
+ end
+
+ def foo(...)
+ for a in [1]
+ r = bar(...)
+ end
+ r
+ end
+
+ foo(2, 3).should == [2, 3]
+ end
+
+ it "does not try to access variables outside the method" do
+ ForSpecs::ForInClassMethod.foo.should == [:bar, :baz]
+ ForSpecs::ForInClassMethod::READER.call.should == :same_variable_set_outside
+ end
+
it "returns expr" do
for i in 1..3; end.should == (1..3)
for i,j in { 1 => 10, 2 => 20 }; end.should == { 1 => 10, 2 => 20 }
diff --git a/spec/ruby/language/hash_spec.rb b/spec/ruby/language/hash_spec.rb
index edd9d4fbb2..7a4a2e37c9 100644
--- a/spec/ruby/language/hash_spec.rb
+++ b/spec/ruby/language/hash_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/hash_strings_ascii8bit', __FILE__)
-require File.expand_path('../fixtures/hash_strings_utf8', __FILE__)
-require File.expand_path('../fixtures/hash_strings_usascii', __FILE__)
+require_relative '../spec_helper'
+require_relative 'fixtures/hash_strings_binary'
+require_relative 'fixtures/hash_strings_utf8'
+require_relative 'fixtures/hash_strings_usascii'
describe "Hash literal" do
it "{} should return an empty hash" do
@@ -33,12 +33,12 @@ describe "Hash literal" do
end
it "freezes string keys on initialization" do
- key = "foo"
+ key = +"foo"
h = {key => "bar"}
key.reverse!
h["foo"].should == "bar"
h.keys.first.should == "foo"
- h.keys.first.frozen?.should == true
+ h.keys.first.should.frozen?
key.should == "oof"
end
@@ -48,6 +48,24 @@ describe "Hash literal" do
}.should complain(/key :foo is duplicated|duplicated key/)
@h.keys.size.should == 1
@h.should == {foo: :foo}
+ -> {
+ @h = eval "{%q{a} => :bar, %q{a} => :foo}"
+ }.should complain(/key "a" is duplicated|duplicated key/)
+ @h.keys.size.should == 1
+ @h.should == {%q{a} => :foo}
+ -> {
+ @h = eval "{1000 => :bar, 1000 => :foo}"
+ }.should complain(/key 1000 is duplicated|duplicated key/)
+ @h.keys.size.should == 1
+ @h.should == {1000 => :foo}
+ end
+
+ it "checks duplicated float keys on initialization" do
+ -> {
+ @h = eval "{1.0 => :bar, 1.0 => :foo}"
+ }.should complain(/key 1.0 is duplicated|duplicated key/)
+ @h.keys.size.should == 1
+ @h.should == {1.0 => :foo}
end
it "accepts a hanging comma" do
@@ -57,13 +75,37 @@ describe "Hash literal" do
end
it "recognizes '=' at the end of the key" do
- eval("{:a==>1}").should == {:"a=" => 1}
- eval("{:a= =>1}").should == {:"a=" => 1}
- eval("{:a= => 1}").should == {:"a=" => 1}
+ {:a==>1}.should == {:"a=" => 1}
+ {:a= =>1}.should == {:"a=" => 1}
+ {:a= => 1}.should == {:"a=" => 1}
end
it "with '==>' in the middle raises SyntaxError" do
- lambda { eval("{:a ==> 1}") }.should raise_error(SyntaxError)
+ -> { eval("{:a ==> 1}") }.should.raise(SyntaxError)
+ end
+
+ it "recognizes '!' at the end of the key" do
+ {:a! =>1}.should == {:"a!" => 1}
+ {:a! => 1}.should == {:"a!" => 1}
+
+ {a!:1}.should == {:"a!" => 1}
+ {a!: 1}.should == {:"a!" => 1}
+ end
+
+ it "raises a SyntaxError if there is no space between `!` and `=>`" do
+ -> { eval("{:a!=> 1}") }.should.raise(SyntaxError)
+ end
+
+ it "recognizes '?' at the end of the key" do
+ {:a? =>1}.should == {:"a?" => 1}
+ {:a? => 1}.should == {:"a?" => 1}
+
+ {a?:1}.should == {:"a?" => 1}
+ {a?: 1}.should == {:"a?" => 1}
+ end
+
+ it "raises a SyntaxError if there is no space between `?` and `=>`" do
+ -> { eval("{:a?=> 1}") }.should.raise(SyntaxError)
end
it "constructs a new hash with the given elements" do
@@ -85,7 +127,7 @@ describe "Hash literal" do
it "accepts mixed 'key: value', 'key => value' and '\"key\"': value' syntax" do
h = {:a => 1, :b => 2, "c" => 3, :d => 4}
- eval('{a: 1, :b => 2, "c" => 3, "d": 4}').should == h
+ {a: 1, :b => 2, "c" => 3, "d": 4}.should == h
end
it "expands an '**{}' element into the containing Hash literal initialization" do
@@ -107,11 +149,55 @@ describe "Hash literal" do
{a: 1, **h, c: 4}.should == {a: 1, b: 2, c: 4}
end
- it "expands an '**{}' element with the last key/value pair taking precedence" do
+ ruby_version_is ""..."3.4" do
+ it "does not expand nil using ** into {} and raises TypeError" do
+ h = nil
+ -> { {a: 1, **h} }.should.raise(TypeError, "no implicit conversion of nil into Hash")
+
+ -> { {a: 1, **nil} }.should.raise(TypeError, "no implicit conversion of nil into Hash")
+ end
+ end
+
+ ruby_version_is "3.4" do
+ it "expands nil using ** into {}" do
+ h = nil
+ {**h}.should == {}
+ {a: 1, **h}.should == {a: 1}
+
+ {**nil}.should == {}
+ {a: 1, **nil}.should == {a: 1}
+ end
+
+ it "expands nil using ** into {} and provides a copy to the callable" do
+ ScratchPad.record []
+ insert = -> key, **kw do
+ kw[key] = 1
+ ScratchPad << kw
+ end
+ insert.call(:foo, **nil)
+ insert.call(:bar, **nil)
+ ScratchPad.recorded.should == [{ foo: 1 }, { bar: 1 }]
+ end
+ end
+
+ it "expands an '**{}' or '**obj' element with the last key/value pair taking precedence" do
-> {
@h = eval "{a: 1, **{a: 2, b: 3, c: 1}, c: 3}"
}.should complain(/key :a is duplicated|duplicated key/)
@h.should == {a: 2, b: 3, c: 3}
+
+ -> {
+ h = {a: 2, b: 3, c: 1}
+ @h = eval "{a: 1, **h, c: 3}"
+ }.should_not complain
+ @h.should == {a: 2, b: 3, c: 3}
+ end
+
+ it "expands an '**{}' and warns when finding an additional duplicate key afterwards" do
+ -> {
+ @h = eval "{d: 1, **{a: 2, b: 3, c: 1}, c: 3}"
+ }.should complain(/key :c is duplicated|duplicated key/)
+ @h.should == {a: 2, b: 3, c: 3, d: 1}
end
it "merges multiple nested '**obj' in Hash literals" do
@@ -128,27 +214,120 @@ describe "Hash literal" do
{a: 1, **obj, c: 3}.should == {a:1, b: 2, c: 3, d: 4}
end
- it "raises a TypeError if any splatted elements keys are not symbols" do
+ it "allows splatted elements keys that are not symbols" do
h = {1 => 2, b: 3}
- lambda { {a: 1, **h} }.should raise_error(TypeError)
+ {a: 1, **h}.should == {a: 1, 1 => 2, b: 3}
end
it "raises a TypeError if #to_hash does not return a Hash" do
obj = mock("hash splat")
obj.should_receive(:to_hash).and_return(obj)
- lambda { {**obj} }.should raise_error(TypeError)
+ -> { {**obj} }.should.raise(TypeError)
+ end
+
+ it "raises a TypeError if the object does not respond to #to_hash" do
+ obj = 42
+ -> { {**obj} }.should.raise(TypeError)
+ -> { {a: 1, **obj} }.should.raise(TypeError)
end
it "does not change encoding of literal string keys during creation" do
- ascii8bit_hash = HashStringsASCII8BIT.literal_hash
+ binary_hash = HashStringsBinary.literal_hash
utf8_hash = HashStringsUTF8.literal_hash
usascii_hash = HashStringsUSASCII.literal_hash
- ascii8bit_hash.keys.first.encoding.should == Encoding::ASCII_8BIT
- ascii8bit_hash.keys.first.should == utf8_hash.keys.first
+ binary_hash.keys.first.encoding.should == Encoding::BINARY
+ binary_hash.keys.first.should == utf8_hash.keys.first
utf8_hash.keys.first.encoding.should == Encoding::UTF_8
utf8_hash.keys.first.should == usascii_hash.keys.first
usascii_hash.keys.first.encoding.should == Encoding::US_ASCII
end
+
+ ruby_bug "#20280", ""..."3.4" do
+ it "raises a SyntaxError at parse time when Symbol key with invalid bytes" do
+ ScratchPad.record []
+ -> {
+ eval 'ScratchPad << 1; {:"\xC3" => 1}'
+ }.should.raise(SyntaxError, /invalid symbol/)
+ ScratchPad.recorded.should == []
+ end
+
+ it "raises a SyntaxError at parse time when Symbol key with invalid bytes and 'key: value' syntax used" do
+ ScratchPad.record []
+ -> {
+ eval 'ScratchPad << 1; {"\xC3": 1}'
+ }.should.raise(SyntaxError, /invalid symbol/)
+ ScratchPad.recorded.should == []
+ end
+ end
+end
+
+describe "The ** operator" do
+ it "makes a copy when calling a method taking a keyword rest argument" do
+ def m(**h)
+ h.delete(:one); h
+ end
+
+ h = { one: 1, two: 2 }
+ m(**h).should == { two: 2 }
+ m(**h).should_not.equal?(h)
+ h.should == { one: 1, two: 2 }
+ end
+
+ it "makes a copy when calling a method taking a positional Hash" do
+ def m(h)
+ h.delete(:one); h
+ end
+
+ h = { one: 1, two: 2 }
+ m(**h).should == { two: 2 }
+ m(**h).should_not.equal?(h)
+ h.should == { one: 1, two: 2 }
+ end
+
+ describe "hash with omitted value" do
+ it "accepts short notation 'key' for 'key: value' syntax" do
+ a, b, c = 1, 2, 3
+ h = {a:}
+ {a: 1}.should == h
+ h = {a:, b:, c:}
+ {a: 1, b: 2, c: 3}.should == h
+ end
+
+ it "ignores hanging comma on short notation" do
+ a, b, c = 1, 2, 3
+ h = {a:, b:, c:,}
+ {a: 1, b: 2, c: 3}.should == h
+ end
+
+ it "accepts mixed syntax" do
+ a, e = 1, 5
+ h = {a:, b: 2, "c" => 3, :d => 4, e:}
+ {a: 1, :b => 2, "c" => 3, "d": 4, e: 5}.should == h
+ end
+
+ it "works with methods and local vars" do
+ a = Class.new
+ a.class_eval(<<-RUBY)
+ def bar
+ "baz"
+ end
+
+ def foo(val)
+ {bar:, val:}
+ end
+ RUBY
+
+ a.new.foo(1).should == {bar: "baz", val: 1}
+ end
+
+ it "raises a SyntaxError when the hash key ends with `!`" do
+ -> { eval("{a!:}") }.should.raise(SyntaxError, /identifier a! is not valid to get/)
+ end
+
+ it "raises a SyntaxError when the hash key ends with `?`" do
+ -> { eval("{a?:}") }.should.raise(SyntaxError, /identifier a\? is not valid to get/)
+ end
+ end
end
diff --git a/spec/ruby/language/heredoc_spec.rb b/spec/ruby/language/heredoc_spec.rb
index a57a7b0bb9..535f18cba8 100644
--- a/spec/ruby/language/heredoc_spec.rb
+++ b/spec/ruby/language/heredoc_spec.rb
@@ -1,6 +1,6 @@
# -*- encoding: us-ascii -*-
-require File.expand_path('../../spec_helper', __FILE__)
+require_relative '../spec_helper'
describe "Heredoc string" do
@@ -13,6 +13,7 @@ describe "Heredoc string" do
foo bar#{@ip}
HERE
s.should == "foo barxxx\n"
+ s.encoding.should == Encoding::US_ASCII
end
it 'allow HEREDOC with <<"identifier", interpolated' do
@@ -20,6 +21,7 @@ HERE
foo bar#{@ip}
HERE
s.should == "foo barxxx\n"
+ s.encoding.should == Encoding::US_ASCII
end
it "allows HEREDOC with <<'identifier', no interpolation" do
@@ -27,6 +29,7 @@ HERE
foo bar#{@ip}
HERE
s.should == 'foo bar#{@ip}' + "\n"
+ s.encoding.should == Encoding::US_ASCII
end
it "allows HEREDOC with <<-identifier, allowing to indent identifier, interpolated" do
@@ -35,6 +38,7 @@ HERE
HERE
s.should == " foo barxxx\n"
+ s.encoding.should == Encoding::US_ASCII
end
it 'allows HEREDOC with <<-"identifier", allowing to indent identifier, interpolated' do
@@ -43,6 +47,7 @@ HERE
HERE
s.should == " foo barxxx\n"
+ s.encoding.should == Encoding::US_ASCII
end
it "allows HEREDOC with <<-'identifier', allowing to indent identifier, no interpolation" do
@@ -51,37 +56,64 @@ HERE
HERE
s.should == ' foo bar#{@ip}' + "\n"
+ s.encoding.should == Encoding::US_ASCII
end
- ruby_version_is "2.3" do
- it "allows HEREDOC with <<~'identifier', allowing to indent identifier and content" do
- require File.expand_path('../fixtures/squiggly_heredoc', __FILE__)
- SquigglyHeredocSpecs.message.should == "character density, n.:\n The number of very weird people in the office.\n"
- end
-
- it "trims trailing newline character for blank HEREDOC with <<~'identifier'" do
- require File.expand_path('../fixtures/squiggly_heredoc', __FILE__)
- SquigglyHeredocSpecs.blank.should == ""
- end
-
- it 'allows HEREDOC with <<~identifier, interpolated' do
- require File.expand_path('../fixtures/squiggly_heredoc', __FILE__)
- SquigglyHeredocSpecs.unquoted.should == "unquoted interpolated\n"
- end
-
- it 'allows HEREDOC with <<~"identifier", interpolated' do
- require File.expand_path('../fixtures/squiggly_heredoc', __FILE__)
- SquigglyHeredocSpecs.doublequoted.should == "doublequoted interpolated\n"
- end
-
- it "allows HEREDOC with <<~'identifier', no interpolation" do
- require File.expand_path('../fixtures/squiggly_heredoc', __FILE__)
- SquigglyHeredocSpecs.singlequoted.should == "singlequoted \#{\"interpolated\"}\n"
- end
-
- it "selects the least-indented line and removes its indentation from all the lines" do
- require File.expand_path('../fixtures/squiggly_heredoc', __FILE__)
- SquigglyHeredocSpecs.least_indented_on_the_last_line.should == " a\n b\nc\n"
- end
+ it 'raises SyntaxError if quoted HEREDOC identifier is ending not on same line' do
+ -> {
+ eval %{<<"HERE\n"\nraises syntax error\nHERE}
+ }.should.raise(SyntaxError)
+ end
+
+ it "allows HEREDOC with <<~'identifier', allowing to indent identifier and content" do
+ require_relative 'fixtures/squiggly_heredoc'
+ SquigglyHeredocSpecs.message.should == "character density, n.:\n The number of very weird people in the office.\n"
+ end
+
+ it "trims trailing newline character for blank HEREDOC with <<~'identifier'" do
+ require_relative 'fixtures/squiggly_heredoc'
+ SquigglyHeredocSpecs.blank.should == ""
+ end
+
+ it 'allows HEREDOC with <<~identifier, interpolated' do
+ require_relative 'fixtures/squiggly_heredoc'
+ SquigglyHeredocSpecs.unquoted.should == "unquoted interpolated\n"
+ end
+
+ it 'allows HEREDOC with <<~"identifier", interpolated' do
+ require_relative 'fixtures/squiggly_heredoc'
+ SquigglyHeredocSpecs.doublequoted.should == "doublequoted interpolated\n"
+ end
+
+ it "allows HEREDOC with <<~'identifier', no interpolation" do
+ require_relative 'fixtures/squiggly_heredoc'
+ SquigglyHeredocSpecs.singlequoted.should == "singlequoted \#{\"interpolated\"}\n"
+ end
+
+ it "allows HEREDOC with <<~'identifier', no interpolation, with backslash" do
+ require_relative 'fixtures/squiggly_heredoc'
+ SquigglyHeredocSpecs.backslash.should == "a\nbc\n"
+ end
+
+ it "selects the least-indented line and removes its indentation from all the lines" do
+ require_relative 'fixtures/squiggly_heredoc'
+ SquigglyHeredocSpecs.least_indented_on_the_first_line.should == "a\n b\n c\n"
+ SquigglyHeredocSpecs.least_indented_on_the_last_line.should == " a\n b\nc\n"
+ end
+
+ it "selects the least-indented line and removes its indentation from all the lines for <<~'identifier'" do
+ require_relative 'fixtures/squiggly_heredoc'
+ SquigglyHeredocSpecs.least_indented_on_the_first_line_single.should == "a\n b\n c\n"
+ SquigglyHeredocSpecs.least_indented_on_the_last_line_single.should == " a\n b\nc\n"
+ end
+
+ it "reports line numbers inside HEREDOC with method call" do
+ -> {
+ <<-HERE.chomp
+ a
+ b
+ #{c}
+ HERE
+ }.should.raise(NameError) { |e| e.backtrace[0].should.start_with?("#{__FILE__}:#{__LINE__ - 2}") }
end
end
diff --git a/spec/ruby/language/if_spec.rb b/spec/ruby/language/if_spec.rb
index 284d852462..53fcb853d5 100644
--- a/spec/ruby/language/if_spec.rb
+++ b/spec/ruby/language/if_spec.rb
@@ -1,22 +1,20 @@
-require File.expand_path('../../spec_helper', __FILE__)
+require_relative '../spec_helper'
describe "The if expression" do
- ruby_version_is '2.4' do
- describe "accepts multiple assignments in conditional expression" do
- before(:each) { ScratchPad.record([]) }
- after(:each) { ScratchPad.clear }
-
- it 'with non-nil values' do
- ary = [1, 2]
- eval "if (a, b = ary); ScratchPad.record [a, b]; end"
- ScratchPad.recorded.should == [1, 2]
- end
+ describe "accepts multiple assignments in conditional expression" do
+ before(:each) { ScratchPad.record([]) }
+ after(:each) { ScratchPad.clear }
+
+ it 'with non-nil values' do
+ ary = [1, 2]
+ eval "if (a, b = ary); ScratchPad.record [a, b]; end"
+ ScratchPad.recorded.should == [1, 2]
+ end
- it 'with nil values' do
- ary = nil
- eval "if (a, b = ary); else; ScratchPad.record [a, b]; end"
- ScratchPad.recorded.should == [nil, nil]
- end
+ it 'with nil values' do
+ ary = nil
+ eval "if (a, b = ary); else; ScratchPad.record [a, b]; end"
+ ScratchPad.recorded.should == [nil, nil]
end
end
@@ -307,6 +305,59 @@ describe "The if expression" do
6.times(&b)
ScratchPad.recorded.should == [4, 5, 4, 5]
end
+
+ it "warns when Integer literals are used instead of predicates" do
+ -> {
+ eval <<~RUBY
+ $. = 0
+ 10.times { |i| ScratchPad << i if 4..5 }
+ RUBY
+ }.should complain(/warning: integer literal in flip-flop/, verbose: true)
+ ScratchPad.recorded.should == []
+ end
+ end
+
+ describe "when a branch syntactically does not return a value" do
+ it "raises SyntaxError if both do not return a value" do
+ -> {
+ eval <<~RUBY
+ def m
+ a = if rand
+ return
+ else
+ return
+ end
+ a
+ end
+ RUBY
+ }.should.raise(SyntaxError, /void value expression/)
+ end
+
+ it "does not raise SyntaxError if one branch returns a value" do
+ eval(<<~RUBY).should == 1
+ def m
+ a = if false # using false to make it clear that's not checked for
+ 42
+ else
+ return 1
+ end
+ a
+ end
+ m
+ RUBY
+
+ eval(<<~RUBY).should == 1
+ def m
+ a = if true # using true to make it clear that's not checked for
+ return 1
+ else
+ 42
+ end
+ a
+ end
+ m
+ RUBY
+ end
end
end
diff --git a/spec/ruby/language/it_parameter_spec.rb b/spec/ruby/language/it_parameter_spec.rb
new file mode 100644
index 0000000000..6ba67cbb4f
--- /dev/null
+++ b/spec/ruby/language/it_parameter_spec.rb
@@ -0,0 +1,108 @@
+require_relative '../spec_helper'
+
+ruby_version_is "3.4" do
+ eval <<-RUBY # use eval to avoid warnings on Ruby 3.3
+ describe "The `it` parameter" do
+ it "provides it in a block" do
+ -> { it }.call("a").should == "a"
+ proc { it }.call("a").should == "a"
+ lambda { it }.call("a").should == "a"
+ ["a"].map { it }.should == ["a"]
+ end
+
+ it "assigns nil to not passed parameters" do
+ proc { it }.call().should == nil
+ end
+
+ it "can be used in both outer and nested blocks at the same time" do
+ -> { it + -> { it * it }.call(2) }.call(3).should == 7
+ end
+
+ it "can be reassigned to act as a local variable" do
+ proc { tmp = it; it = tmp * 2; it }.call(21).should == 42
+ end
+
+ it "is a regular local variable if there is already a 'it' local variable" do
+ it = 0
+ proc { it }.call("a").should == 0
+ end
+
+ it "is a regular local variable if there is a method `it` defined" do
+ o = Object.new
+ def o.it
+ 21
+ end
+
+ o.instance_eval("proc { it * 2 }").call(1).should == 2
+ end
+
+ it "is not shadowed by an reassignment in a block" do
+ a = nil
+ proc { a = it; it = 42 }.call(0)
+ a.should == 0 # if `it` were shadowed its value would be nil
+ end
+
+ it "raises SyntaxError when block parameters are specified explicitly" do
+ -> { eval("-> () { it }") }.should.raise(SyntaxError, /ordinary parameter is defined/)
+ -> { eval("-> (x) { it }") }.should.raise(SyntaxError, /ordinary parameter is defined/)
+
+ -> { eval("proc { || it }") }.should.raise(SyntaxError, /ordinary parameter is defined/)
+ -> { eval("proc { |x| it }") }.should.raise(SyntaxError, /ordinary parameter is defined/)
+
+ -> { eval("lambda { || it }") }.should.raise(SyntaxError, /ordinary parameter is defined/)
+ -> { eval("lambda { |x| it }") }.should.raise(SyntaxError, /ordinary parameter is defined/)
+
+ -> { eval("['a'].map { || it }") }.should.raise(SyntaxError, /ordinary parameter is defined/)
+ -> { eval("['a'].map { |x| it }") }.should.raise(SyntaxError, /ordinary parameter is defined/)
+ end
+
+ it "cannot be mixed with numbered parameters" do
+ -> {
+ eval("proc { it + _1 }")
+ }.should.raise(SyntaxError, /numbered parameters are not allowed when 'it' is already used|'it' is already used in/)
+
+ -> {
+ eval("proc { _1 + it }")
+ }.should.raise(SyntaxError, /numbered parameter is already used in|'it' is not allowed when a numbered parameter is already used/)
+ end
+
+ it "affects block arity" do
+ -> {}.arity.should == 0
+ -> { it }.arity.should == 1
+ end
+
+ it "affects block parameters" do
+ -> { it }.parameters.should == [[:req]]
+
+ ruby_version_is ""..."4.0" do
+ proc { it }.parameters.should == [[:opt, nil]]
+ end
+ ruby_version_is "4.0" do
+ proc { it }.parameters.should == [[:opt]]
+ end
+ end
+
+ it "does not affect binding local variables" do
+ -> { it; binding.local_variables }.call("a").should == []
+ end
+
+ it "does not work in methods" do
+ obj = Object.new
+ def obj.foo; it; end
+
+ -> { obj.foo("a") }.should.raise(ArgumentError, /wrong number of arguments/)
+ end
+
+ context "given multiple arguments" do
+ it "provides it in a block and assigns the first argument for a block" do
+ proc { it }.call("a", "b").should == "a"
+ end
+
+ it "raises ArgumentError for a proc" do
+ -> { -> { it }.call("a", "b") }.should.raise(ArgumentError, "wrong number of arguments (given 2, expected 1)")
+ -> { lambda { it }.call("a", "b") }.should.raise(ArgumentError, "wrong number of arguments (given 2, expected 1)")
+ end
+ end
+ end
+ RUBY
+end
diff --git a/spec/ruby/language/keyword_arguments_spec.rb b/spec/ruby/language/keyword_arguments_spec.rb
new file mode 100644
index 0000000000..38edc24414
--- /dev/null
+++ b/spec/ruby/language/keyword_arguments_spec.rb
@@ -0,0 +1,398 @@
+require_relative '../spec_helper'
+
+describe "Keyword arguments" do
+ def target(*args, **kwargs)
+ [args, kwargs]
+ end
+
+ it "are separated from positional arguments" do
+ def m(*args, **kwargs)
+ [args, kwargs]
+ end
+
+ empty = {}
+ m(**empty).should == [[], {}]
+ m(empty).should == [[{}], {}]
+
+ m(a: 1).should == [[], {a: 1}]
+ m({a: 1}).should == [[{a: 1}], {}]
+ end
+
+ it "when the receiving method has not keyword parameters it treats kwargs as positional" do
+ def m(*a)
+ a
+ end
+
+ m(a: 1).should == [{a: 1}]
+ m({a: 1}).should == [{a: 1}]
+ end
+
+ context "empty kwargs are treated as if they were not passed" do
+ it "when calling a method" do
+ def m(*a)
+ a
+ end
+
+ empty = {}
+ m(**empty).should == []
+ m(empty).should == [{}]
+ end
+
+ it "when yielding to a block" do
+ def y(*args, **kwargs)
+ yield(*args, **kwargs)
+ end
+
+ empty = {}
+ y(**empty) { |*a| a }.should == []
+ y(empty) { |*a| a }.should == [{}]
+ end
+ end
+
+ it "extra keywords are not allowed without **kwrest" do
+ def m(*a, kw:)
+ a
+ end
+
+ m(kw: 1).should == []
+ -> { m(kw: 1, kw2: 2) }.should.raise(ArgumentError, 'unknown keyword: :kw2')
+ -> { m(kw: 1, true => false) }.should.raise(ArgumentError, 'unknown keyword: true')
+ -> { m(kw: 1, a: 1, b: 2, c: 3) }.should.raise(ArgumentError, 'unknown keywords: :a, :b, :c')
+ end
+
+ it "raises ArgumentError exception when required keyword argument is not passed" do
+ def m(a:, b:, c:)
+ [a, b, c]
+ end
+
+ -> { m(a: 1, b: 2) }.should.raise(ArgumentError, /missing keyword: :c/)
+ -> { m() }.should.raise(ArgumentError, /missing keywords: :a, :b, :c/)
+ end
+
+ it "raises ArgumentError for missing keyword arguments even if there are extra ones" do
+ def m(a:)
+ a
+ end
+
+ -> { m(b: 1) }.should.raise(ArgumentError, /missing keyword: :a/)
+ end
+
+ it "handle * and ** at the same call site" do
+ def m(*a)
+ a
+ end
+
+ m(*[], **{}).should == []
+ m(*[], 42, **{}).should == [42]
+ end
+
+ context "marked as ruby2_keywords_hash" do
+ it "is not copied when passed as a positional argument" do
+ h = Hash.ruby2_keywords_hash(a:1)
+
+ def bar(a)
+ a
+ end
+
+ h2 = bar(h)
+ h2.should.equal?(h)
+ Hash.ruby2_keywords_hash?(h).should == true
+ end
+ end
+
+ context "**" do
+ it "copies a non-empty Hash for a method taking (*args)" do
+ def m(*args)
+ args[0]
+ end
+
+ h = {a: 1}
+ m(**h).should_not.equal?(h)
+ h.should == {a: 1}
+ end
+
+ it "copies the given Hash for a method taking (**kwargs)" do
+ def m(**kw)
+ kw
+ end
+
+ empty = {}
+ m(**empty).should == empty
+ m(**empty).should_not.equal?(empty)
+
+ h = {a: 1}
+ m(**h).should == h
+ m(**h).should_not.equal?(h)
+ end
+ end
+
+ context "delegation" do
+ it "works with (*args, **kwargs)" do
+ def m(*args, **kwargs)
+ target(*args, **kwargs)
+ end
+
+ empty = {}
+ m(**empty).should == [[], {}]
+ m(empty).should == [[{}], {}]
+
+ m(a: 1).should == [[], {a: 1}]
+ m({a: 1}).should == [[{a: 1}], {}]
+ end
+
+ it "works with proc { |*args, **kwargs| }" do
+ m = proc do |*args, **kwargs|
+ target(*args, **kwargs)
+ end
+
+ empty = {}
+ m.(**empty).should == [[], {}]
+ m.(empty).should == [[{}], {}]
+
+ m.(a: 1).should == [[], {a: 1}]
+ m.({a: 1}).should == [[{a: 1}], {}]
+
+ # no autosplatting for |*args, **kwargs|
+ m.([1, 2]).should == [[[1, 2]], {}]
+ end
+
+ it "works with -> (*args, **kwargs) {}" do
+ m = -> *args, **kwargs do
+ target(*args, **kwargs)
+ end
+
+ empty = {}
+ m.(**empty).should == [[], {}]
+ m.(empty).should == [[{}], {}]
+
+ m.(a: 1).should == [[], {a: 1}]
+ m.({a: 1}).should == [[{a: 1}], {}]
+ end
+
+ it "works with (...)" do
+ instance_eval <<~DEF
+ def m(...)
+ target(...)
+ end
+ DEF
+
+ empty = {}
+ m(**empty).should == [[], {}]
+ m(empty).should == [[{}], {}]
+
+ m(a: 1).should == [[], {a: 1}]
+ m({a: 1}).should == [[{a: 1}], {}]
+ end
+
+ it "works with call(*ruby2_keyword_args)" do
+ class << self
+ ruby2_keywords def m(*args)
+ target(*args)
+ end
+ end
+
+ empty = {}
+ m(**empty).should == [[], {}]
+ Hash.ruby2_keywords_hash?(empty).should == false
+ m(empty).should == [[{}], {}]
+ Hash.ruby2_keywords_hash?(empty).should == false
+
+ m(a: 1).should == [[], {a: 1}]
+ m({a: 1}).should == [[{a: 1}], {}]
+
+ kw = {a: 1}
+
+ m(**kw).should == [[], {a: 1}]
+ m(**kw)[1].should == kw
+ m(**kw)[1].should_not.equal?(kw)
+ Hash.ruby2_keywords_hash?(kw).should == false
+ Hash.ruby2_keywords_hash?(m(**kw)[1]).should == false
+
+ m(kw).should == [[{a: 1}], {}]
+ m(kw)[0][0].should.equal?(kw)
+ Hash.ruby2_keywords_hash?(kw).should == false
+ end
+
+ it "works with super(*ruby2_keyword_args)" do
+ parent = Class.new do
+ def m(*args, **kwargs)
+ [args, kwargs]
+ end
+ end
+
+ child = Class.new(parent) do
+ ruby2_keywords def m(*args)
+ super(*args)
+ end
+ end
+
+ obj = child.new
+
+ empty = {}
+ obj.m(**empty).should == [[], {}]
+ Hash.ruby2_keywords_hash?(empty).should == false
+ obj.m(empty).should == [[{}], {}]
+ Hash.ruby2_keywords_hash?(empty).should == false
+
+ obj.m(a: 1).should == [[], {a: 1}]
+ obj.m({a: 1}).should == [[{a: 1}], {}]
+
+ kw = {a: 1}
+
+ obj.m(**kw).should == [[], {a: 1}]
+ obj.m(**kw)[1].should == kw
+ obj.m(**kw)[1].should_not.equal?(kw)
+ Hash.ruby2_keywords_hash?(kw).should == false
+ Hash.ruby2_keywords_hash?(obj.m(**kw)[1]).should == false
+
+ obj.m(kw).should == [[{a: 1}], {}]
+ obj.m(kw)[0][0].should.equal?(kw)
+ Hash.ruby2_keywords_hash?(kw).should == false
+ end
+
+ it "works with zsuper" do
+ parent = Class.new do
+ def m(*args, **kwargs)
+ [args, kwargs]
+ end
+ end
+
+ child = Class.new(parent) do
+ ruby2_keywords def m(*args)
+ super
+ end
+ end
+
+ obj = child.new
+
+ empty = {}
+ obj.m(**empty).should == [[], {}]
+ Hash.ruby2_keywords_hash?(empty).should == false
+ obj.m(empty).should == [[{}], {}]
+ Hash.ruby2_keywords_hash?(empty).should == false
+
+ obj.m(a: 1).should == [[], {a: 1}]
+ obj.m({a: 1}).should == [[{a: 1}], {}]
+
+ kw = {a: 1}
+
+ obj.m(**kw).should == [[], {a: 1}]
+ obj.m(**kw)[1].should == kw
+ obj.m(**kw)[1].should_not.equal?(kw)
+ Hash.ruby2_keywords_hash?(kw).should == false
+ Hash.ruby2_keywords_hash?(obj.m(**kw)[1]).should == false
+
+ obj.m(kw).should == [[{a: 1}], {}]
+ obj.m(kw)[0][0].should.equal?(kw)
+ Hash.ruby2_keywords_hash?(kw).should == false
+ end
+
+ it "works with yield(*ruby2_keyword_args)" do
+ class << self
+ def y(args)
+ yield(*args)
+ end
+
+ ruby2_keywords def m(*outer_args)
+ y(outer_args, &-> *args, **kwargs { target(*args, **kwargs) })
+ end
+ end
+
+ empty = {}
+ m(**empty).should == [[], {}]
+ Hash.ruby2_keywords_hash?(empty).should == false
+ m(empty).should == [[{}], {}]
+ Hash.ruby2_keywords_hash?(empty).should == false
+
+ m(a: 1).should == [[], {a: 1}]
+ m({a: 1}).should == [[{a: 1}], {}]
+
+ kw = {a: 1}
+
+ m(**kw).should == [[], {a: 1}]
+ m(**kw)[1].should == kw
+ m(**kw)[1].should_not.equal?(kw)
+ Hash.ruby2_keywords_hash?(kw).should == false
+ Hash.ruby2_keywords_hash?(m(**kw)[1]).should == false
+
+ m(kw).should == [[{a: 1}], {}]
+ m(kw)[0][0].should.equal?(kw)
+ Hash.ruby2_keywords_hash?(kw).should == false
+ end
+
+ it "does not work with (*args)" do
+ class << self
+ def m(*args)
+ target(*args)
+ end
+ end
+
+ empty = {}
+ m(**empty).should == [[], {}]
+ m(empty).should == [[{}], {}]
+
+ m(a: 1).should == [[{a: 1}], {}]
+ m({a: 1}).should == [[{a: 1}], {}]
+ end
+
+ describe "omitted values" do
+ it "accepts short notation 'key' for 'key: value' syntax" do
+ def m(a:, b:)
+ [a, b]
+ end
+
+ a = 1
+ b = 2
+
+ m(a:, b:).should == [1, 2]
+ end
+ end
+
+ it "does not work with call(*ruby2_keyword_args) with missing ruby2_keywords in between" do
+ class << self
+ def n(*args) # Note the missing ruby2_keywords here
+ target(*args)
+ end
+
+ ruby2_keywords def m(*args)
+ n(*args)
+ end
+ end
+
+ empty = {}
+ m(**empty).should == [[], {}]
+ m(empty).should == [[{}], {}]
+
+ m(a: 1).should == [[{a: 1}], {}]
+ m({a: 1}).should == [[{a: 1}], {}]
+ end
+ end
+
+ context "in define_method(name, &proc)" do
+ # This tests that a free-standing proc used in define_method and converted to ruby2_keywords adopts that logic.
+ # See jruby/jruby#8119 for a case where aggressive JIT optimization broke later ruby2_keywords changes.
+ it "works with ruby2_keywords" do
+ m = Class.new do
+ def bar(a, foo: nil)
+ [a, foo]
+ end
+
+ # define_method and ruby2_keywords using send to avoid peephole optimizations
+ def self.setup
+ pr = make_proc
+ send :define_method, :foo, &pr
+ send :ruby2_keywords, :foo
+ end
+
+ # create proc in isolated method to force jit compilation on some implementations
+ def self.make_proc
+ proc { |a, *args| bar(a, *args) }
+ end
+ end
+
+ m.setup
+
+ m.new.foo(1, foo:2).should == [1, 2]
+ end
+ end
+end
diff --git a/spec/ruby/language/lambda_spec.rb b/spec/ruby/language/lambda_spec.rb
index 43e2d60ae3..c6239e32bb 100644
--- a/spec/ruby/language/lambda_spec.rb
+++ b/spec/ruby/language/lambda_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../spec_helper'
+require_relative 'fixtures/classes'
describe "A lambda literal -> () { }" do
SpecEvaluate.desc = "for definition"
@@ -7,19 +7,33 @@ describe "A lambda literal -> () { }" do
it "returns a Proc object when used in a BasicObject method" do
klass = Class.new(BasicObject) do
def create_lambda
- -> () { }
+ -> { }
end
end
- klass.new.create_lambda.should be_an_instance_of(Proc)
+ klass.new.create_lambda.should.instance_of?(Proc)
+ end
+
+ it "is not just syntactic sugar for Kernel#lambda" do
+ should_not_receive(:lambda)
+
+ -> {}
end
it "does not execute the block" do
- ->() { fail }.should be_an_instance_of(Proc)
+ -> { fail }.should.instance_of?(Proc)
end
it "returns a lambda" do
- -> () { }.lambda?.should be_true
+ -> { }.lambda?.should == true
+ end
+
+ it "may include a rescue clause" do
+ eval('-> do raise ArgumentError; rescue ArgumentError; 7; end').should.instance_of?(Proc)
+ end
+
+ it "may include a ensure clause" do
+ eval('-> do 1; ensure; 2; end').should.instance_of?(Proc)
end
it "has its own scope for local variables" do
@@ -40,10 +54,10 @@ describe "A lambda literal -> () { }" do
@d = -> do end
ruby
- @a.().should be_nil
- @b.().should be_nil
- @c.().should be_nil
- @d.().should be_nil
+ @a.().should == nil
+ @b.().should == nil
+ @c.().should == nil
+ @d.().should == nil
end
end
@@ -83,9 +97,9 @@ describe "A lambda literal -> () { }" do
@a = -> (*) { }
ruby
- @a.().should be_nil
- @a.(1).should be_nil
- @a.(1, 2, 3).should be_nil
+ @a.().should == nil
+ @a.(1).should == nil
+ @a.(1, 2, 3).should == nil
end
evaluate <<-ruby do
@@ -101,7 +115,7 @@ describe "A lambda literal -> () { }" do
@a = -> (a:) { a }
ruby
- lambda { @a.() }.should raise_error(ArgumentError)
+ -> { @a.() }.should.raise(ArgumentError)
@a.(a: 1).should == 1
end
@@ -117,9 +131,9 @@ describe "A lambda literal -> () { }" do
@a = -> (**) { }
ruby
- @a.().should be_nil
- @a.(a: 1, b: 2).should be_nil
- lambda { @a.(1) }.should raise_error(ArgumentError)
+ @a.().should == nil
+ @a.(a: 1, b: 2).should == nil
+ -> { @a.(1) }.should.raise(ArgumentError)
end
evaluate <<-ruby do
@@ -134,8 +148,8 @@ describe "A lambda literal -> () { }" do
@a = -> (&b) { b }
ruby
- @a.().should be_nil
- @a.() { }.should be_an_instance_of(Proc)
+ @a.().should == nil
+ @a.() { }.should.instance_of?(Proc)
end
evaluate <<-ruby do
@@ -143,8 +157,8 @@ describe "A lambda literal -> () { }" do
ruby
@a.(1, 2).should == [1, 2]
- lambda { @a.() }.should raise_error(ArgumentError)
- lambda { @a.(1) }.should raise_error(ArgumentError)
+ -> { @a.() }.should.raise(ArgumentError)
+ -> { @a.(1) }.should.raise(ArgumentError)
end
evaluate <<-ruby do
@@ -177,17 +191,17 @@ describe "A lambda literal -> () { }" do
@a.(1, 2, 3, a: 4, b: 5).should == {a: 4, b: 5}
h = mock("keyword splat")
- h.should_receive(:to_hash).and_return({a: 1})
- @a.(h).should == {a: 1}
+ h.should_not_receive(:to_hash)
+ @a.(h).should == {}
end
evaluate <<-ruby do
@a = -> (*, &b) { b }
ruby
- @a.().should be_nil
- @a.(1, 2, 3, 4).should be_nil
- @a.(&(l = ->{})).should equal(l)
+ @a.().should == nil
+ @a.(1, 2, 3, 4).should == nil
+ @a.(&(l = ->{})).should.equal?(l)
end
evaluate <<-ruby do
@@ -255,28 +269,47 @@ describe "A lambda literal -> () { }" do
end
describe "with circular optional argument reference" do
- it "shadows an existing local with the same name as the argument" do
- a = 1
- -> {
- @proc = eval "-> (a=a) { a }"
- }.should complain(/circular argument reference/)
- @proc.call.should == nil
+ ruby_version_is ""..."3.4" do
+ it "raises a SyntaxError if using the argument in its default value" do
+ a = 1
+ -> {
+ eval "-> (a=a) { a }"
+ }.should.raise(SyntaxError)
+ end
end
- it "shadows an existing method with the same name as the argument" do
- def a; 1; end
- -> {
- @proc = eval "-> (a=a) { a }"
- }.should complain(/circular argument reference/)
- @proc.call.should == nil
+ ruby_version_is "3.4" do
+ it "is nil if using the argument in its default value" do
+ -> {
+ eval "-> (a=a) { a }.call"
+ }.call.should == nil
+ end
end
it "calls an existing method with the same name as the argument if explicitly using ()" do
def a; 1; end
- -> (a=a()) { a }.call.should == 1
+ -> a=a() { a }.call.should == 1
end
end
end
+
+ evaluate <<-ruby do
+ @a = -> (**nil) { :ok }
+ ruby
+
+ @a.call().should == :ok
+ -> { @a.call(a: 1) }.should.raise(ArgumentError, 'no keywords accepted')
+ -> { @a.call(**{a: 1}) }.should.raise(ArgumentError, 'no keywords accepted')
+ -> { @a.call("a" => 1) }.should.raise(ArgumentError, 'no keywords accepted')
+ end
+
+ evaluate <<-ruby do
+ @a = -> (a, **nil) { a }
+ ruby
+
+ @a.call({a: 1}).should == {a: 1}
+ -> { @a.call(a: 1) }.should.raise(ArgumentError, 'no keywords accepted')
+ end
end
describe "A lambda expression 'lambda { ... }'" do
@@ -290,19 +323,25 @@ describe "A lambda expression 'lambda { ... }'" do
lambda { }
end
- obj.define.should equal(obj)
+ obj.define.should.equal?(obj)
end
it "does not execute the block" do
- lambda { fail }.should be_an_instance_of(Proc)
+ lambda { fail }.should.instance_of?(Proc)
end
it "returns a lambda" do
- lambda { }.lambda?.should be_true
+ lambda { }.lambda?.should == true
end
it "requires a block" do
- lambda { lambda }.should raise_error(ArgumentError)
+ suppress_warning do
+ lambda { lambda }.should.raise(ArgumentError)
+ end
+ end
+
+ it "may include a rescue clause" do
+ eval('lambda do raise ArgumentError; rescue ArgumentError; 7; end').should.instance_of?(Proc)
end
context "with an implicit block" do
@@ -310,14 +349,13 @@ describe "A lambda expression 'lambda { ... }'" do
def meth; lambda; end
end
- it "can be created" do
+ it "raises ArgumentError" do
implicit_lambda = nil
- -> {
- implicit_lambda = meth { 1 }
- }.should complain(/tried to create Proc object without a block/)
-
- implicit_lambda.lambda?.should be_true
- implicit_lambda.call.should == 1
+ suppress_warning do
+ -> {
+ meth { 1 }
+ }.should.raise(ArgumentError, /tried to create Proc object without a block/)
+ end
end
end
@@ -327,8 +365,8 @@ describe "A lambda expression 'lambda { ... }'" do
@b = lambda { || }
ruby
- @a.().should be_nil
- @b.().should be_nil
+ @a.().should == nil
+ @b.().should == nil
end
end
@@ -345,8 +383,8 @@ describe "A lambda expression 'lambda { ... }'" do
@a = lambda { |a| a }
ruby
- lambda { m(&@a) }.should raise_error(ArgumentError)
- lambda { m(1, 2, &@a) }.should raise_error(ArgumentError)
+ lambda { m(&@a) }.should.raise(ArgumentError)
+ lambda { m(1, 2, &@a) }.should.raise(ArgumentError)
end
evaluate <<-ruby do
@@ -356,8 +394,8 @@ describe "A lambda expression 'lambda { ... }'" do
@a.(1).should == 1
@a.([1, 2]).should == [1, 2]
- lambda { @a.() }.should raise_error(ArgumentError)
- lambda { @a.(1, 2) }.should raise_error(ArgumentError)
+ lambda { @a.() }.should.raise(ArgumentError)
+ lambda { @a.(1, 2) }.should.raise(ArgumentError)
end
evaluate <<-ruby do
@@ -370,7 +408,7 @@ describe "A lambda expression 'lambda { ... }'" do
m(1, &@a).should == 1
m([1, 2], &@a).should == [1, 2]
- lambda { m2(&@a) }.should raise_error(ArgumentError)
+ lambda { m2(&@a) }.should.raise(ArgumentError)
end
evaluate <<-ruby do
@@ -401,9 +439,9 @@ describe "A lambda expression 'lambda { ... }'" do
@a = lambda { |*| }
ruby
- @a.().should be_nil
- @a.(1).should be_nil
- @a.(1, 2, 3).should be_nil
+ @a.().should == nil
+ @a.(1).should == nil
+ @a.(1, 2, 3).should == nil
end
evaluate <<-ruby do
@@ -419,7 +457,7 @@ describe "A lambda expression 'lambda { ... }'" do
@a = lambda { |a:| a }
ruby
- lambda { @a.() }.should raise_error(ArgumentError)
+ lambda { @a.() }.should.raise(ArgumentError)
@a.(a: 1).should == 1
end
@@ -435,9 +473,9 @@ describe "A lambda expression 'lambda { ... }'" do
@a = lambda { |**| }
ruby
- @a.().should be_nil
- @a.(a: 1, b: 2).should be_nil
- lambda { @a.(1) }.should raise_error(ArgumentError)
+ @a.().should == nil
+ @a.(a: 1, b: 2).should == nil
+ lambda { @a.(1) }.should.raise(ArgumentError)
end
evaluate <<-ruby do
@@ -452,8 +490,8 @@ describe "A lambda expression 'lambda { ... }'" do
@a = lambda { |&b| b }
ruby
- @a.().should be_nil
- @a.() { }.should be_an_instance_of(Proc)
+ @a.().should == nil
+ @a.() { }.should.instance_of?(Proc)
end
evaluate <<-ruby do
@@ -493,17 +531,17 @@ describe "A lambda expression 'lambda { ... }'" do
@a.(1, 2, 3, a: 4, b: 5).should == {a: 4, b: 5}
h = mock("keyword splat")
- h.should_receive(:to_hash).and_return({a: 1})
- @a.(h).should == {a: 1}
+ h.should_not_receive(:to_hash)
+ @a.(h).should == {}
end
evaluate <<-ruby do
@a = lambda { |*, &b| b }
ruby
- @a.().should be_nil
- @a.(1, 2, 3, 4).should be_nil
- @a.(&(l = ->{})).should equal(l)
+ @a.().should == nil
+ @a.(1, 2, 3, 4).should == nil
+ @a.(&(l = ->{})).should.equal?(l)
end
evaluate <<-ruby do
@@ -569,5 +607,23 @@ describe "A lambda expression 'lambda { ... }'" do
result = @a.(1, 2, e: 3, g: 4, h: 5, i: 6, &(l = ->{}))
result.should == [1, 1, [], 2, 3, 2, 4, { h: 5, i: 6 }, l]
end
+
+ evaluate <<-ruby do
+ @a = lambda { |**nil| :ok }
+ ruby
+
+ @a.call().should == :ok
+ -> { @a.call(a: 1) }.should.raise(ArgumentError, 'no keywords accepted')
+ -> { @a.call(**{a: 1}) }.should.raise(ArgumentError, 'no keywords accepted')
+ -> { @a.call("a" => 1) }.should.raise(ArgumentError, 'no keywords accepted')
+ end
+
+ evaluate <<-ruby do
+ @a = lambda { |a, **nil| a }
+ ruby
+
+ @a.call({a: 1}).should == {a: 1}
+ -> { @a.call(a: 1) }.should.raise(ArgumentError, 'no keywords accepted')
+ end
end
end
diff --git a/spec/ruby/language/line_spec.rb b/spec/ruby/language/line_spec.rb
index d9fd307dab..2864798079 100644
--- a/spec/ruby/language/line_spec.rb
+++ b/spec/ruby/language/line_spec.rb
@@ -1,10 +1,10 @@
-require File.expand_path('../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/code_loading', __FILE__)
-require File.expand_path('../shared/__LINE__', __FILE__)
+require_relative '../spec_helper'
+require_relative '../fixtures/code_loading'
+require_relative 'shared/__LINE__'
describe "The __LINE__ pseudo-variable" do
it "raises a SyntaxError if assigned to" do
- lambda { eval("__LINE__ = 1") }.should raise_error(SyntaxError)
+ -> { eval("__LINE__ = 1") }.should.raise(SyntaxError)
end
before :each do
diff --git a/spec/ruby/language/loop_spec.rb b/spec/ruby/language/loop_spec.rb
index 4e60e0d8e6..9b12765a5f 100644
--- a/spec/ruby/language/loop_spec.rb
+++ b/spec/ruby/language/loop_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../spec_helper', __FILE__)
+require_relative '../spec_helper'
describe "The loop expression" do
it "repeats the given block until a break is called" do
@@ -15,7 +15,7 @@ describe "The loop expression" do
inner_loop = 123
break
end
- lambda { inner_loop }.should raise_error(NameError)
+ -> { inner_loop }.should.raise(NameError)
end
it "returns the value passed to break if interrupted by break" do
diff --git a/spec/ruby/language/magic_comment_spec.rb b/spec/ruby/language/magic_comment_spec.rb
index 2f6e3b5c3a..af9c9dbfd0 100644
--- a/spec/ruby/language/magic_comment_spec.rb
+++ b/spec/ruby/language/magic_comment_spec.rb
@@ -1,62 +1,93 @@
-require File.expand_path('../../spec_helper', __FILE__)
+require_relative '../spec_helper'
-describe "Magic comment" do
- it "is optional" do
- eval("__ENCODING__").should be_an_instance_of(Encoding)
+# See core/kernel/eval_spec.rb for more magic comments specs for eval()
+describe :magic_comments, shared: true do
+ before :each do
+ @default = @method == :locale ? Encoding.find('locale') : Encoding::UTF_8
end
- it "determines __ENCODING__" do
- eval(<<EOS.force_encoding("US-ASCII")).should == Encoding::ASCII_8BIT
-# encoding: ASCII-8BIT
-__ENCODING__
-EOS
+ it "are optional" do
+ @object.call('no_magic_comment.rb').should == @default.name
end
- it "is case-insensitive" do
- eval(<<EOS.force_encoding("US-ASCII")).should == Encoding::ASCII_8BIT
-# CoDiNg: aScIi-8bIt
-__ENCODING__
-EOS
+ it "are case-insensitive" do
+ @object.call('case_magic_comment.rb').should == Encoding::Big5.name
end
it "must be at the first line" do
- eval(<<EOS.force_encoding("US-ASCII")).should == Encoding::US_ASCII
-
-# encoding: ASCII-8BIT
-__ENCODING__
-EOS
+ @object.call('second_line_magic_comment.rb').should == @default.name
end
it "must be the first token of the line" do
- eval(<<EOS.force_encoding("US-ASCII")).should == Encoding::US_ASCII
-1+1 # encoding: ASCII-8BIT
-__ENCODING__
-EOS
- eval(<<EOS.force_encoding("US-ASCII")).should == Encoding::ASCII_8BIT
- # encoding: ASCII-8BIT
-__ENCODING__
-EOS
+ @object.call('second_token_magic_comment.rb').should == @default.name
end
it "can be after the shebang" do
- eval(<<EOS.force_encoding("US-ASCII")).should == Encoding::ASCII_8BIT
-#!/usr/bin/ruby -Ku
-# encoding: ASCII-8BIT
-__ENCODING__
-EOS
+ @object.call('shebang_magic_comment.rb').should == Encoding::Big5.name
end
it "can take Emacs style" do
- eval(<<EOS.force_encoding("US-ASCII")).should == Encoding::ASCII_8BIT
-# -*- encoding: ascii-8bit -*-
-__ENCODING__
-EOS
+ @object.call('emacs_magic_comment.rb').should == Encoding::Big5.name
end
it "can take vim style" do
- eval(<<EOS.force_encoding("US-ASCII")).should == Encoding::ASCII_8BIT
-# vim: filetype=ruby, fileencoding=ascii-8bit, tabsize=3, shiftwidth=3
-__ENCODING__
-EOS
+ @object.call('vim_magic_comment.rb').should == Encoding::Big5.name
+ end
+
+ it "determine __ENCODING__" do
+ @object.call('magic_comment.rb').should == Encoding::Big5.name
+ end
+
+ it "do not cause bytes to be mangled by passing them through the wrong encoding" do
+ @object.call('bytes_magic_comment.rb').should == [167, 65, 166, 110].inspect
+ end
+end
+
+describe "Magic comments" do
+ describe "in stdin" do
+ default = (platform_is :windows and ruby_version_is "4.0") ? :UTF8 : :locale
+ it_behaves_like :magic_comments, default, -> file {
+ print_at_exit = fixture(__FILE__, "print_magic_comment_result_at_exit.rb")
+ ruby_exe(nil, args: "< #{fixture(__FILE__, file)}", options: "-r#{print_at_exit}")
+ }
+ end
+
+ platform_is_not :windows do
+ describe "in an -e argument" do
+ it_behaves_like :magic_comments, :locale, -> file {
+ print_at_exit = fixture(__FILE__, "print_magic_comment_result_at_exit.rb")
+ # Use UTF-8, as it is the default source encoding for files
+ code = File.read(fixture(__FILE__, file), encoding: 'utf-8')
+ IO.popen([*ruby_exe, "-r", print_at_exit, "-e", code], &:read)
+ }
+ end
+ end
+
+ describe "in the main file" do
+ it_behaves_like :magic_comments, :UTF8, -> file {
+ print_at_exit = fixture(__FILE__, "print_magic_comment_result_at_exit.rb")
+ ruby_exe(fixture(__FILE__, file), options: "-r#{print_at_exit}")
+ }
+ end
+
+ describe "in a loaded file" do
+ it_behaves_like :magic_comments, :UTF8, -> file {
+ load fixture(__FILE__, file)
+ $magic_comment_result
+ }
+ end
+
+ describe "in a required file" do
+ it_behaves_like :magic_comments, :UTF8, -> file {
+ require fixture(__FILE__, file)
+ $magic_comment_result
+ }
+ end
+
+ describe "in an eval" do
+ it_behaves_like :magic_comments, :UTF8, -> file {
+ # Use UTF-8, as it is the default source encoding for files
+ eval(File.read(fixture(__FILE__, file), encoding: 'utf-8'))
+ }
end
end
diff --git a/spec/ruby/language/match_spec.rb b/spec/ruby/language/match_spec.rb
index 81604e94b2..096ebee022 100644
--- a/spec/ruby/language/match_spec.rb
+++ b/spec/ruby/language/match_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/match_operators', __FILE__)
+require_relative '../spec_helper'
+require_relative 'fixtures/match_operators'
describe "The !~ operator" do
before :each do
@@ -46,6 +46,21 @@ describe "The =~ operator with named captures" do
matched.should == "foo"
unmatched.should == nil
end
+
+ it "sets existing local variables if declared in a higher scope" do
+ a = 42
+ 1.times do
+ /(?<a>foo)/ =~ @string
+ end
+ a.should == "foo"
+ end
+ end
+
+ describe "on syntax of 'string_literal' =~ /regexp/" do
+ it "does not set local variables" do
+ 'string literal' =~ /(?<matched>str)(?<unmatched>lit)?/
+ local_variables.should == []
+ end
end
describe "on syntax of string_variable =~ /regexp/" do
diff --git a/spec/ruby/language/metaclass_spec.rb b/spec/ruby/language/metaclass_spec.rb
index b3bcd9ef18..3bee823a75 100644
--- a/spec/ruby/language/metaclass_spec.rb
+++ b/spec/ruby/language/metaclass_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/class', __FILE__)
-require File.expand_path('../fixtures/metaclass', __FILE__)
+require_relative '../spec_helper'
+require_relative '../fixtures/class'
+require_relative 'fixtures/metaclass'
describe "self in a metaclass body (class << obj)" do
it "is TrueClass for true" do
@@ -16,17 +16,17 @@ describe "self in a metaclass body (class << obj)" do
end
it "raises a TypeError for numbers" do
- lambda { class << 1; self; end }.should raise_error(TypeError)
+ -> { class << 1; self; end }.should.raise(TypeError)
end
it "raises a TypeError for symbols" do
- lambda { class << :symbol; self; end }.should raise_error(TypeError)
+ -> { class << :symbol; self; end }.should.raise(TypeError)
end
it "is a singleton Class instance" do
cls = class << mock('x'); self; end
cls.is_a?(Class).should == true
- cls.should_not equal(Object)
+ cls.should_not.equal?(Object)
end
end
@@ -57,20 +57,20 @@ describe "A constant on a metaclass" do
end
it "is not defined on the object's class" do
- @object.class.const_defined?(:CONST).should be_false
+ @object.class.const_defined?(:CONST).should == false
end
it "is not defined in the metaclass opener's scope" do
class << @object
CONST
end
- lambda { CONST }.should raise_error(NameError)
+ -> { CONST }.should.raise(NameError)
end
it "cannot be accessed via object::CONST" do
- lambda do
+ -> do
@object::CONST
- end.should raise_error(TypeError)
+ end.should.raise(TypeError)
end
it "raises a NameError for anonymous_module::CONST" do
@@ -79,33 +79,33 @@ describe "A constant on a metaclass" do
CONST = 100
end
- lambda do
+ -> do
@object::CONST
- end.should raise_error(NameError)
+ end.should.raise(NameError)
end
it "appears in the metaclass constant list" do
constants = class << @object; constants; end
- constants.should include(:CONST)
+ constants.should.include?(:CONST)
end
it "does not appear in the object's class constant list" do
- @object.class.constants.should_not include(:CONST)
+ @object.class.constants.should_not.include?(:CONST)
end
it "is not preserved when the object is duped" do
@object = @object.dup
- lambda do
+ -> do
class << @object; CONST; end
- end.should raise_error(NameError)
+ end.should.raise(NameError)
end
it "is preserved when the object is cloned" do
@object = @object.clone
class << @object
- CONST.should_not be_nil
+ CONST.should_not == nil
end
end
end
diff --git a/spec/ruby/language/method_spec.rb b/spec/ruby/language/method_spec.rb
index ca939dbab6..324bd6cea5 100644
--- a/spec/ruby/language/method_spec.rb
+++ b/spec/ruby/language/method_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../spec_helper', __FILE__)
+require_relative '../spec_helper'
describe "A method send" do
evaluate <<-ruby do
@@ -19,7 +19,7 @@ describe "A method send" do
x = mock("splat argument")
x.should_not_receive(:to_ary)
- m(*x).should equal(x)
+ m(*x).should.equal?(x)
end
it "calls #to_a" do
@@ -40,7 +40,7 @@ describe "A method send" do
x = mock("splat argument")
x.should_receive(:to_a).and_return(1)
- lambda { m(*x) }.should raise_error(TypeError)
+ -> { m(*x) }.should.raise(TypeError)
end
end
@@ -74,7 +74,7 @@ describe "A method send" do
x = mock("splat argument")
x.should_receive(:to_a).and_return(1)
- lambda { m(*x, 2, 3) }.should raise_error(TypeError)
+ -> { m(*x, 2, 3) }.should.raise(TypeError)
end
end
@@ -108,13 +108,13 @@ describe "A method send" do
x = mock("splat argument")
x.should_receive(:to_a).and_return(1)
- lambda { m(1, *x, 2, 3) }.should raise_error(TypeError)
+ -> { m(1, *x, 2, 3) }.should.raise(TypeError)
end
it "copies the splatted array" do
args = [3, 4]
m(1, 2, *args, 4, 5).should == [1, 2, [3, 4], 4, 5]
- m(1, 2, *args, 4, 5)[2].should_not equal(args)
+ m(1, 2, *args, 4, 5)[2].should_not.equal?(args)
end
it "allows an array being splatted to be modified by another argument" do
@@ -153,7 +153,27 @@ describe "A method send" do
x = mock("splat argument")
x.should_receive(:to_a).and_return(1)
- lambda { m(1, 2, *x) }.should raise_error(TypeError)
+ -> { m(1, 2, *x) }.should.raise(TypeError)
+ end
+ end
+
+ context "with a block argument" do
+ before :all do
+ def m(x)
+ if block_given?
+ [true, yield(x + 'b')]
+ else
+ [false]
+ end
+ end
+ end
+
+ it "that refers to a proc passes the proc as the block" do
+ m('a', &-> y { y + 'c'}).should == [true, 'abc']
+ end
+
+ it "that is nil passes no block" do
+ m('a', &nil).should == [false]
end
end
end
@@ -197,7 +217,7 @@ describe "An element assignment method send" do
x = mock("splat argument")
x.should_receive(:to_a).and_return(1)
- lambda { @o[*x] = 1 }.should raise_error(TypeError)
+ -> { @o[*x] = 1 }.should.raise(TypeError)
end
end
@@ -235,7 +255,7 @@ describe "An element assignment method send" do
x = mock("splat argument")
x.should_receive(:to_a).and_return(1)
- lambda { @o[*x, 2, 3] = 4 }.should raise_error(TypeError)
+ -> { @o[*x, 2, 3] = 4 }.should.raise(TypeError)
end
end
@@ -273,7 +293,7 @@ describe "An element assignment method send" do
x = mock("splat argument")
x.should_receive(:to_a).and_return(1)
- lambda { @o[1, 2, *x, 3] = 4 }.should raise_error(TypeError)
+ -> { @o[1, 2, *x, 3] = 4 }.should.raise(TypeError)
end
end
@@ -311,7 +331,7 @@ describe "An element assignment method send" do
x = mock("splat argument")
x.should_receive(:to_a).and_return(1)
- lambda { @o[1, 2, 3, *x] = 4 }.should raise_error(TypeError)
+ -> { @o[1, 2, 3, *x] = 4 }.should.raise(TypeError)
end
end
end
@@ -348,7 +368,7 @@ describe "An attribute assignment method send" do
x = mock("splat argument")
x.should_receive(:to_a).and_return(1)
- lambda { @o.send :m=, *x, 1 }.should raise_error(TypeError)
+ -> { @o.send :m=, *x, 1 }.should.raise(TypeError)
end
end
@@ -383,7 +403,7 @@ describe "An attribute assignment method send" do
x = mock("splat argument")
x.should_receive(:to_a).and_return(1)
- lambda { @o.send :m=, *x, 2, 3, 4 }.should raise_error(TypeError)
+ -> { @o.send :m=, *x, 2, 3, 4 }.should.raise(TypeError)
end
end
@@ -418,7 +438,7 @@ describe "An attribute assignment method send" do
x = mock("splat argument")
x.should_receive(:to_a).and_return(1)
- lambda { @o.send :m=, 1, 2, *x, 3, 4 }.should raise_error(TypeError)
+ -> { @o.send :m=, 1, 2, *x, 3, 4 }.should.raise(TypeError)
end
end
@@ -453,7 +473,7 @@ describe "An attribute assignment method send" do
x = mock("splat argument")
x.should_receive(:to_a).and_return(1)
- lambda { @o.send :m=, 1, 2, 3, *x, 4 }.should raise_error(TypeError)
+ -> { @o.send :m=, 1, 2, 3, *x, 4 }.should.raise(TypeError)
end
end
end
@@ -467,7 +487,7 @@ describe "A method" do
end
ruby
- m.should be_nil
+ m.should == nil
end
evaluate <<-ruby do
@@ -475,7 +495,7 @@ describe "A method" do
end
ruby
- m.should be_nil
+ m.should == nil
end
end
@@ -484,7 +504,7 @@ describe "A method" do
def m(a) a end
ruby
- m((args = 1, 2, 3)).should equal(args)
+ m((args = 1, 2, 3)).should.equal?(args)
end
evaluate <<-ruby do
@@ -512,12 +532,21 @@ describe "A method" do
end
evaluate <<-ruby do
+ def m() end
+ ruby
+
+ m().should == nil
+ m(*[]).should == nil
+ m(**{}).should == nil
+ end
+
+ evaluate <<-ruby do
def m(*) end
ruby
- m().should be_nil
- m(1).should be_nil
- m(1, 2, 3).should be_nil
+ m().should == nil
+ m(1).should == nil
+ m(1, 2, 3).should == nil
end
evaluate <<-ruby do
@@ -527,15 +556,26 @@ describe "A method" do
m().should == []
m(1).should == [1]
m(1, 2, 3).should == [1, 2, 3]
+ m(*[]).should == []
+ m(**{}).should == []
end
evaluate <<-ruby do
def m(a:) a end
ruby
- lambda { m() }.should raise_error(ArgumentError)
+ -> { m() }.should.raise(ArgumentError)
m(a: 1).should == 1
- lambda { m("a" => 1, a: 1) }.should raise_error(ArgumentError)
+ suppress_keyword_warning do
+ -> { m("a" => 1, a: 1) }.should.raise(ArgumentError)
+ end
+ end
+
+ evaluate <<-ruby do
+ def m(a:, **kw) [a, kw] end
+ ruby
+
+ -> { m(b: 1) }.should.raise(ArgumentError)
end
evaluate <<-ruby do
@@ -550,9 +590,9 @@ describe "A method" do
def m(**) end
ruby
- m().should be_nil
- m(a: 1, b: 2).should be_nil
- lambda { m(1) }.should raise_error(ArgumentError)
+ m().should == nil
+ m(a: 1, b: 2).should == nil
+ -> { m(1) }.should.raise(ArgumentError)
end
evaluate <<-ruby do
@@ -561,14 +601,26 @@ describe "A method" do
m().should == {}
m(a: 1, b: 2).should == { a: 1, b: 2 }
- lambda { m(2) }.should raise_error(ArgumentError)
+ m(*[]).should == {}
+ m(**{}).should == {}
+ suppress_warning {
+ eval "m(**{a: 1, b: 2}, **{a: 4, c: 7})"
+ }.should == { a: 4, b: 2, c: 7 }
+ -> { m(2) }.should.raise(ArgumentError)
+ end
+
+ evaluate <<-ruby do
+ def m(**k); k end;
+ ruby
+
+ m("a" => 1).should == { "a" => 1 }
end
evaluate <<-ruby do
def m(&b) b end
ruby
- m { }.should be_an_instance_of(Proc)
+ m { }.should.instance_of?(Proc)
end
evaluate <<-ruby do
@@ -598,9 +650,9 @@ describe "A method" do
def m((*), (*)) end
ruby
- m(2, 3).should be_nil
- m([2, 3, 4], [5, 6]).should be_nil
- lambda { m a: 1 }.should raise_error(ArgumentError)
+ m(2, 3).should == nil
+ m([2, 3, 4], [5, 6]).should == nil
+ -> { m a: 1 }.should.raise(ArgumentError)
end
evaluate <<-ruby do
@@ -692,7 +744,9 @@ describe "A method" do
ruby
m(1, b: 2).should == [1, 2]
- lambda { m("a" => 1, b: 2) }.should raise_error(ArgumentError)
+ suppress_keyword_warning do
+ -> { m("a" => 1, b: 2) }.should.raise(ArgumentError)
+ end
end
evaluate <<-ruby do
@@ -701,7 +755,7 @@ describe "A method" do
m(2).should == [2, 1]
m(1, b: 2).should == [1, 2]
- m("a" => 1, b: 2).should == [{"a" => 1, b: 2}, 1]
+ -> { m("a" => 1, b: 2) }.should.raise(ArgumentError)
end
evaluate <<-ruby do
@@ -710,7 +764,7 @@ describe "A method" do
m(1).should == 1
m(1, a: 2, b: 3).should == 1
- m("a" => 1, b: 2).should == {"a" => 1, b: 2}
+ -> { m("a" => 1, b: 2) }.should.raise(ArgumentError)
end
evaluate <<-ruby do
@@ -719,7 +773,7 @@ describe "A method" do
m(1).should == [1, {}]
m(1, a: 2, b: 3).should == [1, {a: 2, b: 3}]
- m("a" => 1, b: 2).should == [{"a" => 1, b: 2}, {}]
+ -> { m("a" => 1, b: 2) }.should.raise(ArgumentError)
end
evaluate <<-ruby do
@@ -794,8 +848,8 @@ describe "A method" do
def m(a=1, (*b), (*c)) [a, b, c] end
ruby
- lambda { m() }.should raise_error(ArgumentError)
- lambda { m(2) }.should raise_error(ArgumentError)
+ -> { m() }.should.raise(ArgumentError)
+ -> { m(2) }.should.raise(ArgumentError)
m(2, 3).should == [1, [2], [3]]
m(2, [3, 4], [5, 6]).should == [2, [3, 4], [5, 6]]
end
@@ -836,7 +890,7 @@ describe "A method" do
m(b: 2).should == [1, 2]
m(2, b: 1).should == [2, 1]
- m("a" => 1, b: 2).should == [{"a" => 1}, 2]
+ -> { m("a" => 1, b: 2) }.should.raise(ArgumentError)
end
evaluate <<-ruby do
@@ -846,7 +900,7 @@ describe "A method" do
m().should == [1, 2]
m(2).should == [2, 2]
m(b: 3).should == [1, 3]
- m("a" => 1, b: 2).should == [{"a" => 1}, 2]
+ -> { m("a" => 1, b: 2) }.should.raise(ArgumentError)
end
evaluate <<-ruby do
@@ -855,7 +909,7 @@ describe "A method" do
m().should == 1
m(2, a: 1, b: 0).should == 2
- m("a" => 1, a: 2).should == {"a" => 1}
+ m("a" => 1, a: 2).should == 1
end
evaluate <<-ruby do
@@ -896,157 +950,12 @@ describe "A method" do
end
evaluate <<-ruby do
- def m(*, a:) a end
- ruby
-
- m(a: 1).should == 1
- m(1, 2, a: 3).should == 3
- m("a" => 1, a: 2).should == 2
- end
-
- evaluate <<-ruby do
- def m(*a, b:) [a, b] end
- ruby
-
- m(b: 1).should == [[], 1]
- m(1, 2, b: 3).should == [[1, 2], 3]
- m("a" => 1, b: 2).should == [[{"a" => 1}], 2]
- end
-
- evaluate <<-ruby do
- def m(*, a: 1) a end
- ruby
-
- m().should == 1
- m(1, 2).should == 1
- m(a: 2).should == 2
- m(1, a: 2).should == 2
- m("a" => 1, a: 2).should == 2
- end
-
- evaluate <<-ruby do
- def m(*a, b: 1) [a, b] end
- ruby
-
- m().should == [[], 1]
- m(1, 2, 3, b: 4).should == [[1, 2, 3], 4]
- m("a" => 1, b: 2).should == [[{"a" => 1}], 2]
-
- a = mock("splat")
- a.should_not_receive(:to_ary)
- m(*a).should == [[a], 1]
- end
-
- evaluate <<-ruby do
- def m(*, **) end
- ruby
-
- m().should be_nil
- m(a: 1, b: 2).should be_nil
- m(1, 2, 3, a: 4, b: 5).should be_nil
-
- h = mock("keyword splat")
- h.should_receive(:to_hash).and_return({a: 1})
- m(h).should be_nil
-
- h = mock("keyword splat")
- error = RuntimeError.new("error while converting to a hash")
- h.should_receive(:to_hash).and_raise(error)
- lambda { m(h) }.should raise_error(error)
- end
-
- evaluate <<-ruby do
- def m(*a, **) a end
- ruby
-
- m().should == []
- m(1, 2, 3, a: 4, b: 5).should == [1, 2, 3]
- m("a" => 1, a: 1).should == [{"a" => 1}]
- m(1, **{a: 2}).should == [1]
-
- h = mock("keyword splat")
- h.should_receive(:to_hash)
- lambda { m(**h) }.should raise_error(TypeError)
- end
-
- evaluate <<-ruby do
- def m(*, **k) k end
- ruby
-
- m().should == {}
- m(1, 2, 3, a: 4, b: 5).should == {a: 4, b: 5}
- m("a" => 1, a: 1).should == {a: 1}
-
- h = mock("keyword splat")
- h.should_receive(:to_hash).and_return({a: 1})
- m(h).should == {a: 1}
- end
-
- evaluate <<-ruby do
- def m(a = nil, **k) [a, k] end
- ruby
-
- m().should == [nil, {}]
- m("a" => 1).should == [{"a" => 1}, {}]
- m(a: 1).should == [nil, {a: 1}]
- m("a" => 1, a: 1).should == [{"a" => 1}, {a: 1}]
- m({ "a" => 1 }, a: 1).should == [{"a" => 1}, {a: 1}]
- m({a: 1}, {}).should == [{a: 1}, {}]
-
- h = {"a" => 1, b: 2}
- m(h).should == [{"a" => 1}, {b: 2}]
- h.should == {"a" => 1, b: 2}
-
- h = {"a" => 1}
- m(h).first.should == h
-
- h = {}
- r = m(h)
- r.first.should be_nil
- r.last.should == {}
-
- hh = {}
- h = mock("keyword splat empty hash")
- h.should_receive(:to_hash).and_return(hh)
- r = m(h)
- r.first.should be_nil
- r.last.should == {}
-
- h = mock("keyword splat")
- h.should_receive(:to_hash).and_return({"a" => 1, a: 2})
- m(h).should == [{"a" => 1}, {a: 2}]
- end
-
- evaluate <<-ruby do
- def m(*a, **k) [a, k] end
- ruby
-
- m().should == [[], {}]
- m(1).should == [[1], {}]
- m(a: 1, b: 2).should == [[], {a: 1, b: 2}]
- m(1, 2, 3, a: 2).should == [[1, 2, 3], {a: 2}]
-
- m("a" => 1).should == [[{"a" => 1}], {}]
- m(a: 1).should == [[], {a: 1}]
- m("a" => 1, a: 1).should == [[{"a" => 1}], {a: 1}]
- m({ "a" => 1 }, a: 1).should == [[{"a" => 1}], {a: 1}]
- m({a: 1}, {}).should == [[{a: 1}], {}]
- m({a: 1}, {"a" => 1}).should == [[{a: 1}, {"a" => 1}], {}]
-
- bo = BasicObject.new
- def bo.to_a; [1, 2, 3]; end
- def bo.to_hash; {:b => 2, :c => 3}; end
-
- m(*bo, **bo).should == [[1, 2, 3], {:b => 2, :c => 3}]
- end
-
- evaluate <<-ruby do
def m(*, &b) b end
ruby
- m().should be_nil
- m(1, 2, 3, 4).should be_nil
- m(&(l = ->{})).should equal(l)
+ m().should == nil
+ m(1, 2, 3, 4).should == nil
+ m(&(l = ->{})).should.equal?(l)
end
evaluate <<-ruby do
@@ -1063,7 +972,9 @@ describe "A method" do
ruby
m(a: 1, b: 2).should == [1, 2]
- lambda { m("a" => 1, a: 1, b: 2) }.should raise_error(ArgumentError)
+ suppress_keyword_warning do
+ -> { m("a" => 1, a: 1, b: 2) }.should.raise(ArgumentError)
+ end
end
evaluate <<-ruby do
@@ -1072,7 +983,9 @@ describe "A method" do
m(a: 1).should == [1, 1]
m(a: 1, b: 2).should == [1, 2]
- lambda { m("a" => 1, a: 1, b: 2) }.should raise_error(ArgumentError)
+ suppress_keyword_warning do
+ -> { m("a" => 1, a: 1, b: 2) }.should.raise(ArgumentError)
+ end
end
evaluate <<-ruby do
@@ -1081,7 +994,7 @@ describe "A method" do
m(a: 1).should == 1
m(a: 1, b: 2).should == 1
- lambda { m("a" => 1, a: 1, b: 2) }.should raise_error(ArgumentError)
+ m("a" => 1, a: 1, b: 2).should == 1
end
evaluate <<-ruby do
@@ -1090,7 +1003,7 @@ describe "A method" do
m(a: 1).should == [1, {}]
m(a: 1, b: 2, c: 3).should == [1, {b: 2, c: 3}]
- lambda { m("a" => 1, a: 1, b: 2) }.should raise_error(ArgumentError)
+ m("a" => 1, a: 1, b: 2).should == [1, {"a" => 1, b: 2}]
end
evaluate <<-ruby do
@@ -1188,20 +1101,124 @@ describe "A method" do
end
evaluate <<-ruby do
+ def m(**nil); :ok; end;
+ ruby
+
+ m().should == :ok
+ -> { m(a: 1) }.should.raise(ArgumentError, 'no keywords accepted')
+ -> { m(**{a: 1}) }.should.raise(ArgumentError, 'no keywords accepted')
+ -> { m("a" => 1) }.should.raise(ArgumentError, 'no keywords accepted')
+ end
+
+ evaluate <<-ruby do
+ def m(a, **nil); a end;
+ ruby
+
+ m({a: 1}).should == {a: 1}
+ m({"a" => 1}).should == {"a" => 1}
+
+ -> { m(a: 1) }.should.raise(ArgumentError, 'no keywords accepted')
+ -> { m(**{a: 1}) }.should.raise(ArgumentError, 'no keywords accepted')
+ -> { m("a" => 1) }.should.raise(ArgumentError, 'no keywords accepted')
+ end
+
+ evaluate <<-ruby do
def m(a, b = nil, c = nil, d, e: nil, **f)
[a, b, c, d, e, f]
end
- ruby
+ ruby
result = m(1, 2)
result.should == [1, nil, nil, 2, nil, {}]
result = m(1, 2, {foo: :bar})
- result.should == [1, nil, nil, 2, nil, {foo: :bar}]
+ result.should == [1, 2, nil, {foo: :bar}, nil, {}]
result = m(1, {foo: :bar})
result.should == [1, nil, nil, {foo: :bar}, nil, {}]
end
+
+ ruby_version_is "4.1" do
+ evaluate <<-ruby do
+ def m(a, &nil); a end;
+ ruby
+
+ m(1).should == 1
+
+ -> { m(1) {} }.should.raise(ArgumentError, 'no block accepted')
+ -> { m(1, &proc {}) }.should.raise(ArgumentError, 'no block accepted')
+ end
+ end
+ end
+
+ context 'when passing an empty keyword splat to a method that does not accept keywords' do
+ evaluate <<-ruby do
+ def m(*a); a; end
+ ruby
+
+ h = {}
+ m(**h).should == []
+ end
+ end
+
+ context 'when passing an empty keyword splat to a method that does not accept keywords' do
+ evaluate <<-ruby do
+ def m(a); a; end
+ ruby
+ h = {}
+
+ -> do
+ m(**h).should == {}
+ end.should.raise(ArgumentError)
+ end
+ end
+
+ context "raises ArgumentError if passing hash as keyword arguments" do
+ evaluate <<-ruby do
+ def m(a: nil); a; end
+ ruby
+
+ options = {a: 1}.freeze
+ -> do
+ m(options)
+ end.should.raise(ArgumentError)
+ end
+ end
+
+ it "assigns the last Hash to the last optional argument if the Hash contains non-Symbol keys and is not passed as keywords" do
+ def m(a = nil, b = {}, v: false)
+ [a, b, v]
+ end
+
+ h = { "key" => "value" }
+ m(:a, h).should == [:a, h, false]
+ m(:a, h, v: true).should == [:a, h, true]
+ m(v: true).should == [nil, {}, true]
+ end
+end
+
+context "when passing **nil into a method that accepts keyword arguments" do
+ ruby_version_is ""..."3.4" do
+ it "raises TypeError" do
+ def m(**kw) kw; end
+
+ h = nil
+ -> { m(a: 1, **h) }.should.raise(TypeError, "no implicit conversion of nil into Hash")
+ -> { m(a: 1, **nil) }.should.raise(TypeError, "no implicit conversion of nil into Hash")
+ end
+ end
+
+ ruby_version_is "3.4" do
+ it "expands nil using ** into {}" do
+ def m(**kw) kw; end
+
+ h = nil
+ m(**h).should == {}
+ m(a: 1, **h).should == {a: 1}
+
+ m(**nil).should == {}
+ m(a: 1, **nil).should == {a: 1}
+ end
end
end
@@ -1223,22 +1240,48 @@ describe "A method call with a space between method name and parentheses" do
end
end
- context "when a single argument provided" do
- it "assigns it" do
+ context "when a single argument is provided" do
+ it "assigns a simple expression" do
+ args = m (1)
+ args.should == [1]
+ end
+
+ it "assigns an expression consisting of multiple statements" do
+ args = m ((0; 1))
+ args.should == [1]
+ end
+
+ it "assigns one single statement, without the need of parentheses" do
args = m (1 == 1 ? true : false)
args.should == [true]
end
+
+ it "supports multiple statements" do
+ eval("m (1; 2)").should == [2]
+ end
end
- context "when 2+ arguments provided" do
+ context "when multiple arguments are provided" do
+ it "assigns simple expressions" do
+ args = m (1), (2)
+ args.should == [1, 2]
+ end
+
+ it "assigns expressions consisting of multiple statements" do
+ args = m ((0; 1)), ((2; 3))
+ args.should == [1, 3]
+ end
+ end
+
+ context "when the argument looks like an argument list" do
it "raises a syntax error" do
- lambda {
+ -> {
eval("m (1, 2)")
- }.should raise_error(SyntaxError)
+ }.should.raise(SyntaxError)
- lambda {
+ -> {
eval("m (1, 2, 3)")
- }.should raise_error(SyntaxError)
+ }.should.raise(SyntaxError)
end
end
@@ -1294,3 +1337,333 @@ describe "An array-dereference method ([])" do
end
end
end
+
+describe "An endless method definition" do
+ context "without arguments" do
+ evaluate <<-ruby do
+ def m() = 42
+ ruby
+
+ m.should == 42
+ end
+
+ context "without parenthesis" do
+ evaluate <<-ruby do
+ def m = 42
+ ruby
+
+ m.should == 42
+ end
+ end
+ end
+
+ context "with arguments" do
+ evaluate <<-ruby do
+ def m(a, b) = a + b
+ ruby
+
+ m(1, 4).should == 5
+ end
+ end
+
+ context "with multiline body" do
+ evaluate <<-ruby do
+ def m(n) =
+ if n > 2
+ m(n - 2) + m(n - 1)
+ else
+ 1
+ end
+ ruby
+
+ m(6).should == 8
+ end
+ end
+
+ # tested more thoroughly in language/delegation_spec.rb
+ context "with args forwarding" do
+ evaluate <<-ruby do
+ def mm(word, num:)
+ word * num
+ end
+
+ def m(...) = mm(...) + mm(...)
+ ruby
+
+ m("meow", num: 2).should == "meow" * 4
+ end
+ end
+end
+
+describe "Keyword arguments are now separated from positional arguments" do
+ context "when the method has only positional parameters" do
+ it "treats incoming keyword arguments as positional for compatibility" do
+ def foo(a, b, c, hsh)
+ hsh[:key]
+ end
+
+ foo(1, 2, 3, key: 42).should == 42
+ end
+ end
+
+ context "when the method takes a ** parameter" do
+ it "captures the passed literal keyword arguments" do
+ def foo(a, b, c, **hsh)
+ hsh[:key]
+ end
+
+ foo(1, 2, 3, key: 42).should == 42
+ end
+
+ it "captures the passed ** keyword arguments" do
+ def foo(a, b, c, **hsh)
+ hsh[:key]
+ end
+
+ h = { key: 42 }
+ foo(1, 2, 3, **h).should == 42
+ end
+
+ it "does not convert a positional Hash to keyword arguments" do
+ def foo(a, b, c, **hsh)
+ hsh[:key]
+ end
+
+ -> {
+ foo(1, 2, 3, { key: 42 })
+ }.should.raise(ArgumentError, 'wrong number of arguments (given 4, expected 3)')
+ end
+ end
+
+ context "when the method takes a key: parameter" do
+ context "when it's called with a positional Hash and no **" do
+ it "raises ArgumentError" do
+ def foo(a, b, c, key: 1)
+ key
+ end
+
+ -> {
+ foo(1, 2, 3, { key: 42 })
+ }.should.raise(ArgumentError, 'wrong number of arguments (given 4, expected 3)')
+ end
+ end
+
+ context "when it's called with **" do
+ it "captures the passed keyword arguments" do
+ def foo(a, b, c, key: 1)
+ key
+ end
+
+ h = { key: 42 }
+ foo(1, 2, 3, **h).should == 42
+ end
+ end
+ end
+end
+
+describe "kwarg with omitted value in a method call" do
+ context "accepts short notation 'kwarg' in method call" do
+ evaluate <<-ruby do
+ def call(*args, **kwargs) = [args, kwargs]
+ ruby
+
+ a, b, c = 1, 2, 3
+ arr, h = call(a:)
+ h.should == {a: 1}
+ arr.should == []
+
+ arr, h = call(a:, b:, c:)
+ h.should == {a: 1, b: 2, c: 3}
+ arr.should == []
+
+ arr, h = call(a:, b: 10, c:)
+ h.should == {a: 1, b: 10, c: 3}
+ arr.should == []
+ end
+ end
+
+ context "with methods and local variables" do
+ evaluate <<-ruby do
+ def call(*args, **kwargs) = [args, kwargs]
+
+ def bar
+ "baz"
+ end
+
+ def foo(val)
+ call bar:, val:
+ end
+ ruby
+
+ foo(1).should == [[], {bar: "baz", val: 1}]
+ end
+ end
+end
+
+describe "Inside 'endless' method definitions" do
+ it "allows method calls without parenthesis" do
+ def greet(person) = "Hi, ".dup.concat person
+
+ greet("Homer").should == "Hi, Homer"
+ end
+end
+
+describe "warning about not used block argument" do
+ ruby_version_is "3.4" do
+ it "warns when passing a block argument to a method that never uses it" do
+ def m_that_does_not_use_block
+ 42
+ end
+
+ -> {
+ m_that_does_not_use_block { }
+ }.should complain(
+ /#{__FILE__}:#{__LINE__ - 2}: warning: the block passed to 'm_that_does_not_use_block' defined at #{__FILE__}:#{__LINE__ - 7} may be ignored/,
+ verbose: true)
+ end
+
+ it "does not warn when passing a block argument to a method that declares a block parameter" do
+ def m_with_block_parameter(&block)
+ 42
+ end
+
+ -> { m_with_block_parameter { } }.should_not complain(verbose: true)
+ end
+
+ it "does not warn when passing a block argument to a method that declares an anonymous block parameter" do
+ def m_with_anonymous_block_parameter(&)
+ 42
+ end
+
+ -> { m_with_anonymous_block_parameter { } }.should_not complain(verbose: true)
+ end
+
+ it "does not warn when passing a block argument to a method that yields an implicit block parameter" do
+ def m_with_yield
+ yield 42
+ end
+
+ -> { m_with_yield { } }.should_not complain(verbose: true)
+ end
+
+ it "warns when passing a block argument to a method that calls #block_given?" do
+ def m_with_block_given
+ block_given?
+ end
+
+ -> {
+ m_with_block_given { }
+ }.should complain(
+ /#{__FILE__}:#{__LINE__ - 2}: warning: the block passed to 'm_with_block_given' defined at #{__FILE__}:#{__LINE__ - 7} may be ignored/,
+ verbose: true)
+ end
+
+ it "does not warn when passing a block argument to a method that calls super" do
+ parent = Class.new do
+ def m
+ end
+ end
+
+ child = Class.new(parent) do
+ def m
+ super
+ end
+ end
+
+ obj = child.new
+ -> { obj.m { } }.should_not complain(verbose: true)
+ end
+
+ it "does not warn when passing a block argument to a method that calls super(...)" do
+ parent = Class.new do
+ def m(a)
+ end
+ end
+
+ child = Class.new(parent) do
+ def m(...)
+ super(...)
+ end
+ end
+
+ obj = child.new
+ -> { obj.m(42) { } }.should_not complain(verbose: true)
+ end
+
+ it "does not warn when called #initialize()" do
+ klass = Class.new do
+ def initialize
+ end
+ end
+
+ -> { klass.new {} }.should_not complain(verbose: true)
+ end
+
+ it "does not warn when passing a block argument to a method that calls super()" do
+ parent = Class.new do
+ def m
+ end
+ end
+
+ child = Class.new(parent) do
+ def m
+ super()
+ end
+ end
+
+ obj = child.new
+ -> { obj.m { } }.should_not complain(verbose: true)
+ end
+
+ it "warns only once per call site" do
+ def m_that_does_not_use_block
+ 42
+ end
+
+ def call_m_that_does_not_use_block
+ m_that_does_not_use_block {}
+ end
+
+ -> {
+ m_that_does_not_use_block { }
+ }.should complain(/the block passed to 'm_that_does_not_use_block' defined at .+ may be ignored/, verbose: true)
+
+ -> {
+ m_that_does_not_use_block { }
+ }.should_not complain(verbose: true)
+ end
+
+ it "can be disabled with :strict_unused_block warning category" do
+ def m_that_does_not_use_block
+ 42
+ end
+
+ # ensure that warning is emitted
+ -> { m_that_does_not_use_block { } }.should complain(verbose: true)
+
+ warn_strict_unused_block = Warning[:strict_unused_block]
+ Warning[:strict_unused_block] = false
+ begin
+ -> { m_that_does_not_use_block { } }.should_not complain(verbose: true)
+ ensure
+ Warning[:strict_unused_block] = warn_strict_unused_block
+ end
+ end
+
+ it "can be enabled with :strict_unused_block = true warning category in not verbose mode" do
+ def m_that_does_not_use_block
+ 42
+ end
+
+ warn_strict_unused_block = Warning[:strict_unused_block]
+ Warning[:strict_unused_block] = true
+ begin
+ -> {
+ m_that_does_not_use_block { }
+ }.should complain(/the block passed to 'm_that_does_not_use_block' defined at .+ may be ignored/)
+ ensure
+ Warning[:strict_unused_block] = warn_strict_unused_block
+ end
+ end
+ end
+end
diff --git a/spec/ruby/language/module_spec.rb b/spec/ruby/language/module_spec.rb
index d5ca71b3b4..2f22e383d5 100644
--- a/spec/ruby/language/module_spec.rb
+++ b/spec/ruby/language/module_spec.rb
@@ -1,78 +1,108 @@
-require File.expand_path('../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/module', __FILE__)
+require_relative '../spec_helper'
+require_relative 'fixtures/module'
describe "The module keyword" do
it "creates a new module without semicolon" do
module ModuleSpecsKeywordWithoutSemicolon end
- ModuleSpecsKeywordWithoutSemicolon.should be_an_instance_of(Module)
+ ModuleSpecsKeywordWithoutSemicolon.should.instance_of?(Module)
end
it "creates a new module with a non-qualified constant name" do
module ModuleSpecsToplevel; end
- ModuleSpecsToplevel.should be_an_instance_of(Module)
+ ModuleSpecsToplevel.should.instance_of?(Module)
end
it "creates a new module with a qualified constant name" do
module ModuleSpecs::Nested; end
- ModuleSpecs::Nested.should be_an_instance_of(Module)
+ ModuleSpecs::Nested.should.instance_of?(Module)
end
it "creates a new module with a variable qualified constant name" do
m = Module.new
module m::N; end
- m::N.should be_an_instance_of(Module)
+ m::N.should.instance_of?(Module)
end
it "reopens an existing module" do
module ModuleSpecs; Reopened = true; end
- ModuleSpecs::Reopened.should be_true
+ ModuleSpecs::Reopened.should == true
+ ensure
+ ModuleSpecs.send(:remove_const, :Reopened)
end
- it "reopens a module included in Object" do
- module IncludedModuleSpecs; Reopened = true; end
- ModuleSpecs::IncludedInObject::IncludedModuleSpecs::Reopened.should be_true
+ it "does not reopen a module included in Object" do
+ ruby_exe(<<~RUBY).should == "false"
+ module IncludedInObject
+ module IncludedModule; end
+ end
+ class Object
+ include IncludedInObject
+ end
+ module IncludedModule; end
+ print IncludedInObject::IncludedModule == Object::IncludedModule
+ RUBY
+ end
+
+ it "does not reopen a module included in non-Object modules" do
+ ruby_exe(<<~RUBY).should == "false/false"
+ module Included
+ module IncludedModule; end
+ end
+ module M
+ include Included
+ module IncludedModule; end
+ end
+ class C
+ include Included
+ module IncludedModule; end
+ end
+ print Included::IncludedModule == M::IncludedModule, "/",
+ Included::IncludedModule == C::IncludedModule
+ RUBY
end
it "raises a TypeError if the constant is a Class" do
- lambda do
+ -> do
module ModuleSpecs::Modules::Klass; end
- end.should raise_error(TypeError)
+ end.should.raise(TypeError)
end
it "raises a TypeError if the constant is a String" do
- lambda { module ModuleSpecs::Modules::A; end }.should raise_error(TypeError)
+ -> { module ModuleSpecs::Modules::A; end }.should.raise(TypeError)
end
- it "raises a TypeError if the constant is a Fixnum" do
- lambda { module ModuleSpecs::Modules::B; end }.should raise_error(TypeError)
+ it "raises a TypeError if the constant is an Integer" do
+ -> { module ModuleSpecs::Modules::B; end }.should.raise(TypeError)
end
it "raises a TypeError if the constant is nil" do
- lambda { module ModuleSpecs::Modules::C; end }.should raise_error(TypeError)
+ -> { module ModuleSpecs::Modules::C; end }.should.raise(TypeError)
end
it "raises a TypeError if the constant is true" do
- lambda { module ModuleSpecs::Modules::D; end }.should raise_error(TypeError)
+ -> { module ModuleSpecs::Modules::D; end }.should.raise(TypeError)
end
it "raises a TypeError if the constant is false" do
- lambda { module ModuleSpecs::Modules::D; end }.should raise_error(TypeError)
+ -> { module ModuleSpecs::Modules::D; end }.should.raise(TypeError)
end
end
describe "Assigning an anonymous module to a constant" do
it "sets the name of the module" do
mod = Module.new
- mod.name.should be_nil
+ mod.name.should == nil
::ModuleSpecs_CS1 = mod
mod.name.should == "ModuleSpecs_CS1"
+ ensure
+ Object.send(:remove_const, :ModuleSpecs_CS1)
end
- it "does not set the name of a module scoped by an anonymous module" do
+ it "sets the name of a module scoped by an anonymous module" do
a, b = Module.new, Module.new
a::B = b
- b.name.should be_nil
+ b.name.should.end_with? '::B'
end
it "sets the name of contained modules when assigning a toplevel anonymous module" do
@@ -87,5 +117,7 @@ describe "Assigning an anonymous module to a constant" do
b.name.should == "ModuleSpecs_CS2::B"
c.name.should == "ModuleSpecs_CS2::B::C"
d.name.should == "ModuleSpecs_CS2::D"
+ ensure
+ Object.send(:remove_const, :ModuleSpecs_CS2)
end
end
diff --git a/spec/ruby/language/next_spec.rb b/spec/ruby/language/next_spec.rb
index 67da5224dc..eac151eeb3 100644
--- a/spec/ruby/language/next_spec.rb
+++ b/spec/ruby/language/next_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/next', __FILE__)
+require_relative '../spec_helper'
+require_relative 'fixtures/next'
describe "The next statement from within the block" do
before :each do
@@ -8,7 +8,7 @@ describe "The next statement from within the block" do
it "ends block execution" do
a = []
- lambda {
+ -> {
a << 1
next
a << 2
@@ -17,15 +17,15 @@ describe "The next statement from within the block" do
end
it "causes block to return nil if invoked without arguments" do
- lambda { 123; next; 456 }.call.should == nil
+ -> { 123; next; 456 }.call.should == nil
end
it "causes block to return nil if invoked with an empty expression" do
- lambda { next (); 456 }.call.should be_nil
+ -> { next (); 456 }.call.should == nil
end
it "returns the argument passed" do
- lambda { 123; next 234; 345 }.call.should == 234
+ -> { 123; next 234; 345 }.call.should == 234
end
it "returns to the invoking method" do
@@ -102,16 +102,16 @@ describe "The next statement from within the block" do
it "passes the value returned by a method with omitted parenthesis and passed block" do
obj = NextSpecs::Block.new
- lambda { next obj.method :value do |x| x end }.call.should == :value
+ -> { next obj.method :value do |x| x end }.call.should == :value
end
end
describe "The next statement" do
describe "in a method" do
it "is invalid and raises a SyntaxError" do
- lambda {
+ -> {
eval("def m; next; end")
- }.should raise_error(SyntaxError)
+ }.should.raise(SyntaxError)
end
end
end
diff --git a/spec/ruby/language/not_spec.rb b/spec/ruby/language/not_spec.rb
index a0cf6b15a6..23411a8e1d 100644
--- a/spec/ruby/language/not_spec.rb
+++ b/spec/ruby/language/not_spec.rb
@@ -1,51 +1,51 @@
-require File.expand_path('../../spec_helper', __FILE__)
+require_relative '../spec_helper'
describe "The not keyword" do
it "negates a `true' value" do
- (not true).should be_false
- (not 'true').should be_false
+ (not true).should == false
+ (not 'true').should == false
end
it "negates a `false' value" do
- (not false).should be_true
- (not nil).should be_true
+ (not false).should == true
+ (not nil).should == true
end
it "accepts an argument" do
- not(true).should be_false
+ not(true).should == false
end
it "returns false if the argument is true" do
- (not(true)).should be_false
+ (not(true)).should == false
end
it "returns true if the argument is false" do
- (not(false)).should be_true
+ (not(false)).should == true
end
it "returns true if the argument is nil" do
- (not(nil)).should be_true
+ (not(nil)).should == true
end
end
describe "The `!' keyword" do
it "negates a `true' value" do
- (!true).should be_false
- (!'true').should be_false
+ (!true).should == false
+ (!'true').should == false
end
it "negates a `false' value" do
- (!false).should be_true
- (!nil).should be_true
+ (!false).should == true
+ (!nil).should == true
end
it "doubled turns a truthful object into `true'" do
- (!!true).should be_true
- (!!'true').should be_true
+ (!!true).should == true
+ (!!'true').should == true
end
it "doubled turns a not truthful object into `false'" do
- (!!false).should be_false
- (!!nil).should be_false
+ (!!false).should == false
+ (!!nil).should == false
end
end
diff --git a/spec/ruby/language/numbered_parameters_spec.rb b/spec/ruby/language/numbered_parameters_spec.rb
new file mode 100644
index 0000000000..23e89a14be
--- /dev/null
+++ b/spec/ruby/language/numbered_parameters_spec.rb
@@ -0,0 +1,113 @@
+require_relative '../spec_helper'
+
+describe "Numbered parameters" do
+ it "provides default parameters _1, _2, ... in a block" do
+ -> { _1 }.call("a").should == "a"
+ proc { _1 }.call("a").should == "a"
+ lambda { _1 }.call("a").should == "a"
+ ["a"].map { _1 }.should == ["a"]
+ end
+
+ it "assigns nil to not passed parameters" do
+ proc { [_1, _2] }.call("a").should == ["a", nil]
+ proc { [_1, _2] }.call("a", "b").should == ["a", "b"]
+ end
+
+ it "supports variables _1-_9 only for the first 9 passed parameters" do
+ block = proc { [_1, _2, _3, _4, _5, _6, _7, _8, _9] }
+ result = block.call(1, 2, 3, 4, 5, 6, 7, 8, 9)
+ result.should == [1, 2, 3, 4, 5, 6, 7, 8, 9]
+ end
+
+ it "does not support more than 9 parameters" do
+ -> {
+ proc { [_10] }.call(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
+ }.should.raise(NameError, /undefined local variable or method [`']_10'/)
+ end
+
+ it "can not be used in both outer and nested blocks at the same time" do
+ -> {
+ eval("-> { _1; -> { _2 } }")
+ }.should.raise(SyntaxError, /numbered parameter is already used in/m)
+ end
+
+ it "cannot be overwritten with local variable" do
+ -> {
+ eval <<~CODE
+ _1 = 0
+ proc { _1 }.call("a").should == 0
+ CODE
+ }.should.raise(SyntaxError, /_1 is reserved for numbered parameter/)
+ end
+
+ it "errors when numbered parameter is overwritten with local variable" do
+ -> {
+ eval("_1 = 0")
+ }.should.raise(SyntaxError, /_1 is reserved for numbered parameter/)
+ end
+
+ it "raises SyntaxError when block parameters are specified explicitly" do
+ -> { eval("-> () { _1 }") }.should.raise(SyntaxError, /ordinary parameter is defined/)
+ -> { eval("-> (x) { _1 }") }.should.raise(SyntaxError, /ordinary parameter is defined/)
+
+ -> { eval("proc { || _1 }") }.should.raise(SyntaxError, /ordinary parameter is defined/)
+ -> { eval("proc { |x| _1 }") }.should.raise(SyntaxError, /ordinary parameter is defined/)
+
+ -> { eval("lambda { || _1 }") }.should.raise(SyntaxError, /ordinary parameter is defined/)
+ -> { eval("lambda { |x| _1 }") }.should.raise(SyntaxError, /ordinary parameter is defined/)
+
+ -> { eval("['a'].map { || _1 }") }.should.raise(SyntaxError, /ordinary parameter is defined/)
+ -> { eval("['a'].map { |x| _1 }") }.should.raise(SyntaxError, /ordinary parameter is defined/)
+ end
+
+ describe "assigning to a numbered parameter" do
+ it "raises SyntaxError" do
+ -> { eval("proc { _1 = 0 }") }.should.raise(SyntaxError, /_1 is reserved for numbered parameter/)
+ end
+ end
+
+ it "affects block arity" do
+ -> { _1 }.arity.should == 1
+ -> { _2 }.arity.should == 2
+ -> { _3 }.arity.should == 3
+ -> { _4 }.arity.should == 4
+ -> { _5 }.arity.should == 5
+ -> { _6 }.arity.should == 6
+ -> { _7 }.arity.should == 7
+ -> { _8 }.arity.should == 8
+ -> { _9 }.arity.should == 9
+
+ -> { _9 }.arity.should == 9
+ proc { _9 }.arity.should == 9
+ lambda { _9 }.arity.should == 9
+ end
+
+ it "affects block parameters" do
+ -> { _1 }.parameters.should == [[:req, :_1]]
+ -> { _2 }.parameters.should == [[:req, :_1], [:req, :_2]]
+
+ proc { _1 }.parameters.should == [[:opt, :_1]]
+ proc { _2 }.parameters.should == [[:opt, :_1], [:opt, :_2]]
+ end
+
+ ruby_version_is ""..."4.0" do
+ it "affects binding local variables" do
+ -> { _1; binding.local_variables }.call("a").should == [:_1]
+ -> { _2; binding.local_variables }.call("a", "b").should == [:_1, :_2]
+ end
+ end
+
+ ruby_version_is "4.0" do
+ it "does not affect binding local variables" do
+ -> { _1; binding.local_variables }.call("a").should == []
+ -> { _2; binding.local_variables }.call("a", "b").should == []
+ end
+ end
+
+ it "does not work in methods" do
+ obj = Object.new
+ def obj.foo; _1 end
+
+ -> { obj.foo("a") }.should.raise(ArgumentError, /wrong number of arguments/)
+ end
+end
diff --git a/spec/ruby/language/numbers_spec.rb b/spec/ruby/language/numbers_spec.rb
index e8c82f09a7..ed0e49c048 100644
--- a/spec/ruby/language/numbers_spec.rb
+++ b/spec/ruby/language/numbers_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../spec_helper', __FILE__)
+require_relative '../spec_helper'
describe "A number literal" do
@@ -11,7 +11,7 @@ describe "A number literal" do
end
it "cannot have a leading underscore" do
- lambda { eval("_4_2") }.should raise_error(NameError)
+ -> { eval("_4_2") }.should.raise(NameError)
end
it "can have a decimal point" do
@@ -20,8 +20,8 @@ describe "A number literal" do
it "must have a digit before the decimal point" do
0.75.should == 0.75
- lambda { eval(".75") }.should raise_error(SyntaxError)
- lambda { eval("-.75") }.should raise_error(SyntaxError)
+ -> { eval(".75") }.should.raise(SyntaxError)
+ -> { eval("-.75") }.should.raise(SyntaxError)
end
it "can have an exponent" do
@@ -45,7 +45,15 @@ describe "A number literal" do
eval('-3r').should == Rational(-3, 1)
end
- it "can be an bignum literal with trailing 'r' to represent a Rational" do
+ it "can be an float literal with trailing 'r' to represent a Rational in a canonical form" do
+ eval('1.0r').should == Rational(1, 1)
+ end
+
+ it "can be a float literal with trailing 'r' to represent a Rational" do
+ eval('0.0174532925199432957r').should == Rational(174532925199432957, 10000000000000000000)
+ end
+
+ it "can be a bignum literal with trailing 'r' to represent a Rational" do
eval('1111111111111111111111111111111111111111111111r').should == Rational(1111111111111111111111111111111111111111111111, 1)
eval('-1111111111111111111111111111111111111111111111r').should == Rational(-1111111111111111111111111111111111111111111111, 1)
end
diff --git a/spec/ruby/language/optional_assignments_spec.rb b/spec/ruby/language/optional_assignments_spec.rb
index 0ab28985ed..ebb5d36351 100644
--- a/spec/ruby/language/optional_assignments_spec.rb
+++ b/spec/ruby/language/optional_assignments_spec.rb
@@ -1,4 +1,5 @@
-require File.expand_path('../../spec_helper', __FILE__)
+require_relative '../spec_helper'
+require_relative '../fixtures/constants'
describe 'Optional variable assignments' do
describe 'using ||=' do
@@ -42,9 +43,21 @@ describe 'Optional variable assignments' do
a.should == 10
end
+
+ it 'returns the new value if set to false' do
+ a = false
+
+ (a ||= 20).should == 20
+ end
+
+ it 'returns the original value if truthy' do
+ a = 10
+
+ (a ||= 20).should == 10
+ end
end
- describe 'using a accessor' do
+ describe 'using an accessor' do
before do
klass = Class.new { attr_accessor :b }
@a = klass.new
@@ -89,6 +102,178 @@ describe 'Optional variable assignments' do
@a.b.should == 10
end
+
+ it 'does evaluate receiver only once when assigns' do
+ ScratchPad.record []
+ @a.b = nil
+
+ (ScratchPad << :evaluated; @a).b ||= 10
+
+ ScratchPad.recorded.should == [:evaluated]
+ @a.b.should == 10
+ end
+
+ it 'returns the new value if set to false' do
+ def @a.b=(x)
+ :v
+ end
+
+ @a.b = false
+ (@a.b ||= 20).should == 20
+ end
+
+ it 'returns the original value if truthy' do
+ def @a.b=(x)
+ @b = x
+ :v
+ end
+
+ @a.b = 10
+ (@a.b ||= 20).should == 10
+ end
+
+ it 'ignores method visibility when receiver is self' do
+ klass_with_private_methods = Class.new do
+ def initialize(v) @a = v end
+ def public_method(v); self.a ||= v end
+ private
+ def a; @a end
+ def a=(v) @a = v; 42 end
+ end
+
+ a = klass_with_private_methods.new(false)
+ a.public_method(10).should == 10
+ end
+ end
+
+ describe 'using a #[]' do
+ before do
+ @a = {}
+ klass = Class.new do
+ def [](k)
+ @hash ||= {}
+ @hash[k]
+ end
+
+ def []=(k, v)
+ @hash ||= {}
+ @hash[k] = v
+ 7
+ end
+ end
+ @b = klass.new
+ end
+
+ it 'returns the assigned value, not the result of the []= method with ||=' do
+ (@b[:k] ||= 12).should == 12
+ end
+
+ it "evaluates the index precisely once" do
+ ary = [:x, :y]
+ @a[:x] = 15
+ @a[ary.pop] ||= 25
+ ary.should == [:x]
+ @a.should == { x: 15, y: 25 }
+ end
+
+ it "evaluates the index arguments in the correct order" do
+ ary = Class.new(Array) do
+ def [](x, y)
+ super(x + 3 * y)
+ end
+
+ def []=(x, y, value)
+ super(x + 3 * y, value)
+ end
+ end.new
+ ary[0, 0] = 1
+ ary[1, 0] = 1
+ ary[2, 0] = nil
+ ary[3, 0] = 1
+ ary[4, 0] = 1
+ ary[5, 0] = 1
+ ary[6, 0] = nil
+
+ foo = [0, 2]
+
+ ary[foo.pop, foo.pop] ||= 2 # expected `ary[2, 0] ||= 2`
+
+ ary[2, 0].should == 2
+ ary[6, 0].should == nil # returns the same element as `ary[0, 2]`
+ end
+
+ it 'evaluates receiver only once when assigns' do
+ ScratchPad.record []
+ @a[:k] = nil
+
+ (ScratchPad << :evaluated; @a)[:k] ||= 2
+
+ ScratchPad.recorded.should == [:evaluated]
+ @a[:k].should == 2
+ end
+
+ it 'ignores method visibility when receiver is self' do
+ klass_with_private_methods = Class.new do
+ def initialize(h) @a = h end
+ def public_method(k, v); self[k] ||= v end
+ private
+ def [](k) @a[k] end
+ def []=(k, v) @a[k] = v; 42 end
+ end
+
+ a = klass_with_private_methods.new(k: false)
+ a.public_method(:k, 10).should == 10
+ end
+
+ context 'splatted argument' do
+ it 'correctly handles it' do
+ (@b[*[:m]] ||= 10).should == 10
+ @b[:m].should == 10
+
+ (@b[*(1; [:n])] ||= 10).should == 10
+ @b[:n].should == 10
+
+ (@b[*begin 1; [:k] end] ||= 10).should == 10
+ @b[:k].should == 10
+ end
+
+ it 'calls #to_a only once' do
+ k = Object.new
+ def k.to_a
+ ScratchPad << :to_a
+ [:k]
+ end
+
+ ScratchPad.record []
+ (@b[*k] ||= 20).should == 20
+ @b[:k].should == 20
+ ScratchPad.recorded.should == [:to_a]
+ end
+
+ it 'correctly handles a nested splatted argument' do
+ (@b[*[*[:k]]] ||= 20).should == 20
+ @b[:k].should == 20
+ end
+
+ it 'correctly handles multiple nested splatted arguments' do
+ klass_with_multiple_parameters = Class.new do
+ def [](k1, k2, k3)
+ @hash ||= {}
+ @hash[:"#{k1}#{k2}#{k3}"]
+ end
+
+ def []=(k1, k2, k3, v)
+ @hash ||= {}
+ @hash[:"#{k1}#{k2}#{k3}"] = v
+ 7
+ end
+ end
+ a = klass_with_multiple_parameters.new
+
+ (a[*[:a], *[:b], *[:c]] ||= 20).should == 20
+ a[:a, :b, :c].should == 20
+ end
+ end
end
end
@@ -135,7 +320,7 @@ describe 'Optional variable assignments' do
end
end
- describe 'using a single variable' do
+ describe 'using an accessor' do
before do
klass = Class.new { attr_accessor :b }
@a = klass.new
@@ -180,11 +365,221 @@ describe 'Optional variable assignments' do
@a.b.should == 20
end
+
+ it 'does evaluate receiver only once when assigns' do
+ ScratchPad.record []
+ @a.b = 10
+
+ (ScratchPad << :evaluated; @a).b &&= 20
+
+ ScratchPad.recorded.should == [:evaluated]
+ @a.b.should == 20
+ end
+
+ it 'ignores method visibility when receiver is self' do
+ klass_with_private_methods = Class.new do
+ def initialize(v) @a = v end
+ def public_method(v); self.a &&= v end
+ private
+ def a; @a end
+ def a=(v) @a = v; 42 end
+ end
+
+ a = klass_with_private_methods.new(true)
+ a.public_method(10).should == 10
+ end
+ end
+
+ describe 'using a #[]' do
+ before do
+ @a = {}
+ klass = Class.new do
+ def [](k)
+ @hash ||= {}
+ @hash[k]
+ end
+
+ def []=(k, v)
+ @hash ||= {}
+ @hash[k] = v
+ 7
+ end
+ end
+ @b = klass.new
+ end
+
+ it 'leaves new variable unassigned' do
+ @a[:k] &&= 10
+
+ @a.key?(:k).should == false
+ end
+
+ it 'leaves false' do
+ @a[:k] = false
+ @a[:k] &&= 10
+
+ @a[:k].should == false
+ end
+
+ it 'leaves nil' do
+ @a[:k] = nil
+ @a[:k] &&= 10
+
+ @a[:k].should == nil
+ end
+
+ it 'does not evaluate the right side when not needed' do
+ @a[:k] = nil
+ @a[:k] &&= raise('should not be executed')
+ @a[:k].should == nil
+ end
+
+ it 'does re-assign a variable with a truthy value' do
+ @a[:k] = 10
+ @a[:k] &&= 20
+
+ @a[:k].should == 20
+ end
+
+ it 'does re-assign a variable with a truthy value when using an inline rescue' do
+ @a[:k] = 10
+ @a[:k] &&= 20 rescue 30
+
+ @a[:k].should == 20
+ end
+
+ it 'returns the assigned value, not the result of the []= method with ||=' do
+ @b[:k] = 10
+ (@b[:k] &&= 12).should == 12
+ end
+
+ it "evaluates the index precisely once" do
+ ary = [:x, :y]
+ @a[:x] = 15
+ @a[:y] = 20
+ @a[ary.pop] &&= 25
+ ary.should == [:x]
+ @a.should == { x: 15, y: 25 }
+ end
+
+ it "evaluates the index arguments in the correct order" do
+ ary = Class.new(Array) do
+ def [](x, y)
+ super(x + 3 * y)
+ end
+
+ def []=(x, y, value)
+ super(x + 3 * y, value)
+ end
+ end.new
+ ary[0, 0] = 1
+ ary[1, 0] = 1
+ ary[2, 0] = 1
+ ary[3, 0] = 1
+ ary[4, 0] = 1
+ ary[5, 0] = 1
+ ary[6, 0] = 1
+
+ foo = [0, 2]
+
+ ary[foo.pop, foo.pop] &&= 2 # expected `ary[2, 0] &&= 2`
+
+ ary[2, 0].should == 2
+ ary[6, 0].should == 1 # returns the same element as `ary[0, 2]`
+ end
+
+ it 'evaluates receiver only once when assigns' do
+ ScratchPad.record []
+ @a[:k] = 1
+
+ (ScratchPad << :evaluated; @a)[:k] &&= 2
+
+ ScratchPad.recorded.should == [:evaluated]
+ @a[:k].should == 2
+ end
+
+ it 'returns the assigned value, not the result of the []= method with +=' do
+ @b[:k] = 17
+ (@b[:k] += 12).should == 29
+ end
+
+ it 'ignores method visibility when receiver is self' do
+ klass_with_private_methods = Class.new do
+ def initialize(h) @a = h end
+ def public_method(k, v); self[k] &&= v end
+ private
+ def [](k) @a[k] end
+ def []=(k, v) @a[k] = v; 42 end
+ end
+
+ a = klass_with_private_methods.new(k: true)
+ a.public_method(:k, 10).should == 10
+ end
+
+ context 'splatted argument' do
+ it 'correctly handles it' do
+ @b[:m] = 0
+ (@b[*[:m]] &&= 10).should == 10
+ @b[:m].should == 10
+
+ @b[:n] = 0
+ (@b[*(1; [:n])] &&= 10).should == 10
+ @b[:n].should == 10
+
+ @b[:k] = 0
+ (@b[*begin 1; [:k] end] &&= 10).should == 10
+ @b[:k].should == 10
+ end
+
+ it 'calls #to_a only once' do
+ k = Object.new
+ def k.to_a
+ ScratchPad << :to_a
+ [:k]
+ end
+
+ ScratchPad.record []
+ @b[:k] = 10
+ (@b[*k] &&= 20).should == 20
+ @b[:k].should == 20
+ ScratchPad.recorded.should == [:to_a]
+ end
+
+ it 'correctly handles a nested splatted argument' do
+ @b[:k] = 10
+ (@b[*[*[:k]]] &&= 20).should == 20
+ @b[:k].should == 20
+ end
+
+ it 'correctly handles multiple nested splatted arguments' do
+ klass_with_multiple_parameters = Class.new do
+ def [](k1, k2, k3)
+ @hash ||= {}
+ @hash[:"#{k1}#{k2}#{k3}"]
+ end
+
+ def []=(k1, k2, k3, v)
+ @hash ||= {}
+ @hash[:"#{k1}#{k2}#{k3}"] = v
+ 7
+ end
+ end
+ a = klass_with_multiple_parameters.new
+
+ a[:a, :b, :c] = 10
+ (a[*[:a], *[:b], *[:c]] &&= 20).should == 20
+ a[:a, :b, :c].should == 20
+ end
+ end
end
end
- describe 'using compunded constants' do
- before do
+ describe 'using compounded constants' do
+ before :each do
+ Object.send(:remove_const, :A) if defined? Object::A
+ end
+
+ after :each do
Object.send(:remove_const, :A) if defined? Object::A
end
@@ -208,7 +603,7 @@ describe 'Optional variable assignments' do
end
it 'with &&= assignments will fail with non-existent constants' do
- lambda { Object::A &&= 10 }.should raise_error(NameError)
+ -> { Object::A &&= 10 }.should.raise(NameError)
end
it 'with operator assignments' do
@@ -220,7 +615,128 @@ describe 'Optional variable assignments' do
end
it 'with operator assignments will fail with non-existent constants' do
- lambda { Object::A += 10 }.should raise_error(NameError)
+ -> { Object::A += 10 }.should.raise(NameError)
+ end
+ end
+end
+
+describe 'Optional constant assignment' do
+ describe 'with ||=' do
+ it "assigns a scoped constant if previously undefined" do
+ ConstantSpecs.should_not.const_defined?(:OpAssignUndefined)
+ module ConstantSpecs
+ OpAssignUndefined ||= 42
+ end
+ ConstantSpecs::OpAssignUndefined.should == 42
+ ConstantSpecs::OpAssignUndefinedOutside ||= 42
+ ConstantSpecs::OpAssignUndefinedOutside.should == 42
+ ConstantSpecs.send(:remove_const, :OpAssignUndefined)
+ ConstantSpecs.send(:remove_const, :OpAssignUndefinedOutside)
+ end
+
+ it "assigns a global constant if previously undefined" do
+ OpAssignGlobalUndefined ||= 42
+ ::OpAssignGlobalUndefinedExplicitScope ||= 42
+ OpAssignGlobalUndefined.should == 42
+ ::OpAssignGlobalUndefinedExplicitScope.should == 42
+ Object.send :remove_const, :OpAssignGlobalUndefined
+ Object.send :remove_const, :OpAssignGlobalUndefinedExplicitScope
+ end
+
+ it 'correctly defines non-existing constants' do
+ ConstantSpecs::ClassA::OR_ASSIGNED_CONSTANT1 ||= :assigned
+ ConstantSpecs::ClassA::OR_ASSIGNED_CONSTANT1.should == :assigned
+ end
+
+ it 'correctly overwrites nil constants' do
+ suppress_warning do # already initialized constant
+ ConstantSpecs::ClassA::NIL_OR_ASSIGNED_CONSTANT1 = nil
+ ConstantSpecs::ClassA::NIL_OR_ASSIGNED_CONSTANT1 ||= :assigned
+ ConstantSpecs::ClassA::NIL_OR_ASSIGNED_CONSTANT1.should == :assigned
+ end
+ end
+
+ it 'causes side-effects of the module part to be applied only once (for undefined constant)' do
+ x = 0
+ (x += 1; ConstantSpecs::ClassA)::OR_ASSIGNED_CONSTANT2 ||= :assigned
+ x.should == 1
+ ConstantSpecs::ClassA::OR_ASSIGNED_CONSTANT2.should == :assigned
+ end
+
+ it 'causes side-effects of the module part to be applied only once (for nil constant)' do
+ suppress_warning do # already initialized constant
+ ConstantSpecs::ClassA::NIL_OR_ASSIGNED_CONSTANT2 = nil
+ x = 0
+ (x += 1; ConstantSpecs::ClassA)::NIL_OR_ASSIGNED_CONSTANT2 ||= :assigned
+ x.should == 1
+ ConstantSpecs::ClassA::NIL_OR_ASSIGNED_CONSTANT2.should == :assigned
+ end
+ end
+
+ it 'does not evaluate the right-hand side if the module part raises an exception (for undefined constant)' do
+ x = 0
+ y = 0
+
+ -> {
+ (x += 1; raise Exception; ConstantSpecs::ClassA)::OR_ASSIGNED_CONSTANT3 ||= (y += 1; :assigned)
+ }.should.raise(Exception)
+
+ x.should == 1
+ y.should == 0
+ defined?(ConstantSpecs::ClassA::OR_ASSIGNED_CONSTANT3).should == nil
+ end
+
+ it 'does not evaluate the right-hand side if the module part raises an exception (for nil constant)' do
+ ConstantSpecs::ClassA::NIL_OR_ASSIGNED_CONSTANT3 = nil
+ x = 0
+ y = 0
+
+ -> {
+ (x += 1; raise Exception; ConstantSpecs::ClassA)::NIL_OR_ASSIGNED_CONSTANT3 ||= (y += 1; :assigned)
+ }.should.raise(Exception)
+
+ x.should == 1
+ y.should == 0
+ ConstantSpecs::ClassA::NIL_OR_ASSIGNED_CONSTANT3.should == nil
+ ensure
+ ConstantSpecs::ClassA.send(:remove_const, :NIL_OR_ASSIGNED_CONSTANT3)
+ end
+ end
+
+ describe "with &&=" do
+ it "re-assigns a scoped constant if already true" do
+ module ConstantSpecs
+ OpAssignTrue = true
+ end
+ suppress_warning do
+ ConstantSpecs::OpAssignTrue &&= 1
+ end
+ ConstantSpecs::OpAssignTrue.should == 1
+ ConstantSpecs.send :remove_const, :OpAssignTrue
+ end
+
+ it "leaves scoped constant if not true" do
+ module ConstantSpecs
+ OpAssignFalse = false
+ end
+ ConstantSpecs::OpAssignFalse &&= 1
+ ConstantSpecs::OpAssignFalse.should == false
+ ConstantSpecs.send :remove_const, :OpAssignFalse
+ end
+
+ it 'causes side-effects of the module part to be applied only once (when assigns)' do
+ module ConstantSpecs
+ OpAssignTrue = true
+ end
+
+ suppress_warning do # already initialized constant
+ x = 0
+ (x += 1; ConstantSpecs)::OpAssignTrue &&= :assigned
+ x.should == 1
+ ConstantSpecs::OpAssignTrue.should == :assigned
+ end
+
+ ConstantSpecs.send :remove_const, :OpAssignTrue
end
end
end
diff --git a/spec/ruby/language/or_spec.rb b/spec/ruby/language/or_spec.rb
index 150d693996..8ae577a142 100644
--- a/spec/ruby/language/or_spec.rb
+++ b/spec/ruby/language/or_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../spec_helper', __FILE__)
+require_relative '../spec_helper'
describe "The || operator" do
it "evaluates to true if any of its operands are true" do
@@ -26,24 +26,24 @@ describe "The || operator" do
end
it "treats empty expressions as nil" do
- (() || true).should be_true
- (() || false).should be_false
- (true || ()).should be_true
- (false || ()).should be_nil
- (() || ()).should be_nil
+ (() || true).should == true
+ (() || false).should == false
+ (true || ()).should == true
+ (false || ()).should == nil
+ (() || ()).should == nil
end
it "has a higher precedence than 'break' in 'break true || false'" do
# see also 'break true or false' below
- lambda { break false || true }.call.should be_true
+ -> { break false || true }.call.should == true
end
it "has a higher precedence than 'next' in 'next true || false'" do
- lambda { next false || true }.call.should be_true
+ -> { next false || true }.call.should == true
end
it "has a higher precedence than 'return' in 'return true || false'" do
- lambda { return false || true }.call.should be_true
+ -> { return false || true }.call.should == true
end
end
@@ -68,23 +68,23 @@ describe "The or operator" do
end
it "treats empty expressions as nil" do
- (() or true).should be_true
- (() or false).should be_false
- (true or ()).should be_true
- (false or ()).should be_nil
- (() or ()).should be_nil
+ (() or true).should == true
+ (() or false).should == false
+ (true or ()).should == true
+ (false or ()).should == nil
+ (() or ()).should == nil
end
it "has a lower precedence than 'break' in 'break true or false'" do
# see also 'break true || false' above
- lambda { eval "break true or false" }.should raise_error(SyntaxError, /void value expression/)
+ -> { eval "break true or false" }.should.raise(SyntaxError, /void value expression/)
end
it "has a lower precedence than 'next' in 'next true or false'" do
- lambda { eval "next true or false" }.should raise_error(SyntaxError, /void value expression/)
+ -> { eval "next true or false" }.should.raise(SyntaxError, /void value expression/)
end
it "has a lower precedence than 'return' in 'return true or false'" do
- lambda { eval "return true or false" }.should raise_error(SyntaxError, /void value expression/)
+ -> { eval "return true or false" }.should.raise(SyntaxError, /void value expression/)
end
end
diff --git a/spec/ruby/language/order_spec.rb b/spec/ruby/language/order_spec.rb
index d02bf04077..d550f6b3f4 100644
--- a/spec/ruby/language/order_spec.rb
+++ b/spec/ruby/language/order_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../spec_helper', __FILE__)
+require_relative '../spec_helper'
describe "A method call" do
before :each do
diff --git a/spec/ruby/language/pattern_matching_spec.rb b/spec/ruby/language/pattern_matching_spec.rb
new file mode 100644
index 0000000000..a24500c9fd
--- /dev/null
+++ b/spec/ruby/language/pattern_matching_spec.rb
@@ -0,0 +1,1310 @@
+require_relative '../spec_helper'
+
+describe "Pattern matching" do
+ before :each do
+ ScratchPad.record []
+ end
+
+ describe "Rightward assignment (`=>`) that can be standalone assoc operator that" do
+ it "deconstructs value" do
+ suppress_warning do
+ [0, 1] => [a, b]
+ [a, b].should == [0, 1]
+ end
+ end
+
+ it "deconstructs value and properly scopes variables" do
+ suppress_warning do
+ a = nil
+ 1.times {
+ [0, 1] => [a, b]
+ }
+ [a, defined?(b)].should == [0, nil]
+ end
+ end
+
+ it "can work with keywords" do
+ { a: 0, b: 1 } => { a:, b: }
+ [a, b].should == [0, 1]
+ end
+ end
+
+ describe "One-line pattern matching" do
+ it "can be used to check if a pattern matches for Array-like entities" do
+ ([0, 1] in [a, b]).should == true
+ ([0, 1] in [a, b, c]).should == false
+ end
+
+ it "can be used to check if a pattern matches for Hash-like entities" do
+ ({ a: 0, b: 1 } in { a:, b: }).should == true
+ ({ a: 0, b: 1 } in { a:, b:, c: }).should == false
+ end
+ end
+
+ describe "find pattern" do
+ it "captures preceding elements to the pattern" do
+ case [0, 1, 2, 3]
+ in [*pre, 2, 3]
+ pre
+ else
+ false
+ end.should == [0, 1]
+ end
+
+ it "captures following elements to the pattern" do
+ case [0, 1, 2, 3]
+ in [0, 1, *post]
+ post
+ else
+ false
+ end.should == [2, 3]
+ end
+
+ it "captures both preceding and following elements to the pattern" do
+ case [0, 1, 2, 3, 4]
+ in [*pre, 2, *post]
+ [pre, post]
+ else
+ false
+ end.should == [[0, 1], [3, 4]]
+ end
+
+ it "can capture the entirety of the pattern" do
+ case [0, 1, 2, 3, 4]
+ in [*everything]
+ everything
+ else
+ false
+ end.should == [0, 1, 2, 3, 4]
+ end
+
+ it "will match an empty Array-like structure" do
+ case []
+ in [*everything]
+ everything
+ else
+ false
+ end.should == []
+ end
+
+ it "can be nested" do
+ case [0, [2, 4, 6], [3, 9, 27], [4, 16, 64]]
+ in [*pre, [*, 9, a], *post]
+ [pre, post, a]
+ else
+ false
+ end.should == [[0, [2, 4, 6]], [[4, 16, 64]], 27]
+ end
+
+ it "can be nested with an array pattern" do
+ case [0, [2, 4, 6], [3, 9, 27], [4, 16, 64]]
+ in [_, _, [*, 9, *], *post]
+ post
+ else
+ false
+ end.should == [[4, 16, 64]]
+ end
+
+ it "can be nested within a hash pattern" do
+ case {a: [3, 9, 27]}
+ in {a: [*, 9, *post]}
+ post
+ else
+ false
+ end.should == [27]
+ end
+
+ it "can nest hash and array patterns" do
+ case [0, {a: 42, b: [0, 1]}, {a: 42, b: [1, 2]}]
+ in [*, {a:, b: [1, c]}, *]
+ [a, c]
+ else
+ false
+ end.should == [42, 2]
+ end
+ end
+
+ it "extends case expression with case/in construction" do
+ case [0, 1]
+ in [0]
+ :foo
+ in [0, 1]
+ :bar
+ end.should == :bar
+ end
+
+ it "allows using then operator" do
+ case [0, 1]
+ in [0] then :foo
+ in [0, 1] then :bar
+ end.should == :bar
+ end
+
+ describe "warning" do
+ before :each do
+ @experimental, Warning[:experimental] = Warning[:experimental], true
+ end
+
+ after :each do
+ Warning[:experimental] = @experimental
+ end
+
+ context 'when regular form' do
+ before :each do
+ @src = 'case [0, 1]; in [a, b]; end'
+ end
+
+ it "does not warn about pattern matching is experimental feature" do
+ -> { eval @src }.should_not complain
+ end
+ end
+
+ context 'when one-line form' do
+ before :each do
+ @src = '[0, 1] => [a, b]'
+ end
+
+ it "does not warn about pattern matching is experimental feature" do
+ -> { eval @src }.should_not complain
+ end
+ end
+ end
+
+ it "binds variables" do
+ case [0, 1]
+ in [0, a]
+ a
+ end.should == 1
+ end
+
+ it "cannot mix in and when operators" do
+ -> {
+ eval <<~RUBY
+ case []
+ when 1 == 1
+ in []
+ end
+ RUBY
+ }.should.raise(SyntaxError, /syntax error, unexpected `in'|\(eval\):3: syntax error, unexpected keyword_in|unexpected 'in'/)
+
+ -> {
+ eval <<~RUBY
+ case []
+ in []
+ when 1 == 1
+ end
+ RUBY
+ }.should.raise(SyntaxError, /syntax error, unexpected `when'|\(eval\):3: syntax error, unexpected keyword_when|unexpected 'when'/)
+ end
+
+ it "checks patterns until the first matching" do
+ case [0, 1]
+ in [0]
+ :foo
+ in [0, 1]
+ :bar
+ in [0, 1]
+ :baz
+ end.should == :bar
+ end
+
+ it "executes else clause if no pattern matches" do
+ case [0, 1]
+ in [0]
+ true
+ else
+ false
+ end.should == false
+ end
+
+ it "raises NoMatchingPatternError if no pattern matches and no else clause" do
+ -> {
+ case [0, 1]
+ in [0]
+ end
+ }.should.raise(NoMatchingPatternError, /\[0, 1\]/)
+
+ error_pattern = ruby_version_is("3.4") ? /\{a: 0, b: 1\}/ : /\{:a=>0, :b=>1\}/
+ -> {
+ case {a: 0, b: 1}
+ in a: 1, b: 1
+ end
+ }.should.raise(NoMatchingPatternError, error_pattern)
+ end
+
+ it "raises NoMatchingPatternError if no pattern matches and evaluates the expression only once" do
+ evals = 0
+ -> {
+ case (evals += 1; [0, 1])
+ in [0]
+ end
+ }.should.raise(NoMatchingPatternError, /\[0, 1\]/)
+ evals.should == 1
+ end
+
+ it "does not allow calculation or method calls in a pattern" do
+ -> {
+ eval <<~RUBY
+ case 0
+ in 1 + 1
+ true
+ end
+ RUBY
+ }.should.raise(SyntaxError, /unexpected|expected a delimiter after the patterns of an `in` clause/)
+ end
+
+ it "evaluates the case expression once for multiple patterns, caching the result" do
+ case (ScratchPad << :foo; 1)
+ in 0
+ false
+ in 1
+ true
+ end.should == true
+
+ ScratchPad.recorded.should == [:foo]
+ end
+
+ describe "guards" do
+ it "supports if guard" do
+ case 0
+ in 0 if false
+ true
+ else
+ false
+ end.should == false
+
+ case 0
+ in 0 if true
+ true
+ else
+ false
+ end.should == true
+ end
+
+ it "supports unless guard" do
+ case 0
+ in 0 unless true
+ true
+ else
+ false
+ end.should == false
+
+ case 0
+ in 0 unless false
+ true
+ else
+ false
+ end.should == true
+ end
+
+ it "makes bound variables visible in guard" do
+ case [0, 1]
+ in [a, 1] if a >= 0
+ true
+ end.should == true
+ end
+
+ it "does not evaluate guard if pattern does not match" do
+ case 0
+ in 1 if (ScratchPad << :foo) || true
+ else
+ end
+
+ ScratchPad.recorded.should == []
+ end
+
+ it "takes guards into account when there are several matching patterns" do
+ case 0
+ in 0 if false
+ :foo
+ in 0 if true
+ :bar
+ end.should == :bar
+ end
+
+ it "executes else clause if no guarded pattern matches" do
+ case 0
+ in 0 if false
+ true
+ else
+ false
+ end.should == false
+ end
+
+ it "raises NoMatchingPatternError if no guarded pattern matches and no else clause" do
+ -> {
+ case [0, 1]
+ in [0, 1] if false
+ end
+ }.should.raise(NoMatchingPatternError, /\[0, 1\]/)
+ end
+ end
+
+ describe "value pattern" do
+ it "matches an object such that pattern === object" do
+ case 0
+ in 0
+ true
+ end.should == true
+
+ case 0
+ in (
+ -1..1)
+ true
+ end.should == true
+
+ case 0
+ in Integer
+ true
+ end.should == true
+
+ case "0"
+ in /0/
+ true
+ end.should == true
+
+ case "0"
+ in -> s { s == "0" }
+ true
+ end.should == true
+ end
+
+ it "allows string literal with interpolation" do
+ x = "x"
+
+ case "x"
+ in "#{x + ""}"
+ true
+ end.should == true
+ end
+ end
+
+ describe "variable pattern" do
+ it "matches a value and binds variable name to this value" do
+ case 0
+ in a
+ a
+ end.should == 0
+ end
+
+ it "makes bounded variable visible outside a case statement scope" do
+ case 0
+ in a
+ end
+
+ a.should == 0
+ end
+
+ it "create local variables even if a pattern doesn't match" do
+ case 0
+ in a
+ in b
+ in c
+ end
+
+ [a, b, c].should == [0, nil, nil]
+ end
+
+ it "allow using _ name to drop values" do
+ case [0, 1]
+ in [a, _]
+ a
+ end.should == 0
+ end
+
+ it "supports using _ in a pattern several times" do
+ case [0, 1, 2]
+ in [0, _, _]
+ true
+ end.should == true
+ end
+
+ it "supports using any name with _ at the beginning in a pattern several times" do
+ case [0, 1, 2]
+ in [0, _x, _x]
+ true
+ end.should == true
+
+ case {a: 0, b: 1, c: 2}
+ in {a: 0, b: _x, c: _x}
+ true
+ end.should == true
+ end
+
+ it "does not support using variable name (except _) several times" do
+ -> {
+ eval <<~RUBY
+ case [0]
+ in [a, a]
+ end
+ RUBY
+ }.should.raise(SyntaxError, /duplicated variable name/)
+ end
+
+ it "supports existing variables in a pattern specified with ^ operator" do
+ a = 0
+
+ case 0
+ in ^a
+ true
+ end.should == true
+ end
+
+ it "allows applying ^ operator to bound variables" do
+ case [1, 1]
+ in [n, ^n]
+ n
+ end.should == 1
+
+ case [1, 2]
+ in [n, ^n]
+ true
+ else
+ false
+ end.should == false
+ end
+
+ it "requires bound variable to be specified in a pattern before ^ operator when it relies on a bound variable" do
+ -> {
+ eval <<~RUBY
+ case [1, 2]
+ in [^n, n]
+ true
+ else
+ false
+ end
+ RUBY
+ }.should.raise(SyntaxError, /n: no such local variable/)
+ end
+ end
+
+ describe "alternative pattern" do
+ it "matches if any of patterns matches" do
+ case 0
+ in 0 | 1 | 2
+ true
+ end.should == true
+ end
+
+ it "does not support variable binding" do
+ -> {
+ eval <<~RUBY
+ case [0, 1]
+ in [0, 0] | [0, a]
+ end
+ RUBY
+ }.should.raise(SyntaxError)
+ end
+
+ it "support underscore prefixed variables in alternation" do
+ case [0, 1]
+ in [1, _]
+ false
+ in [0, 0] | [0, _a]
+ true
+ end.should == true
+ end
+
+ it "can be used as a nested pattern" do
+ case [[1], ["2"]]
+ in [[0] | nil, _]
+ false
+ in [[1], [1]]
+ false
+ in [[1], [2 | "2"]]
+ true
+ end.should == true
+
+ case [1, 2]
+ in [0, _] | {a: 0}
+ false
+ in {a: 1, b: 2} | [1, 2]
+ true
+ end.should == true
+ end
+ end
+
+ describe "AS pattern" do
+ it "binds a variable to a value if pattern matches" do
+ case 0
+ in Integer => n
+ n
+ end.should == 0
+ end
+
+ it "can be used as a nested pattern" do
+ case [1, [2, 3]]
+ in [1, Array => ary]
+ ary
+ end.should == [2, 3]
+ end
+ end
+
+ describe "Array pattern" do
+ it "supports form Constant(pat, pat, ...)" do
+ case [0, 1, 2]
+ in Array(0, 1, 2)
+ true
+ end.should == true
+ end
+
+ it "supports form Constant[pat, pat, ...]" do
+ case [0, 1, 2]
+ in Array[0, 1, 2]
+ true
+ end.should == true
+ end
+
+ it "supports form [pat, pat, ...]" do
+ case [0, 1, 2]
+ in [0, 1, 2]
+ true
+ end.should == true
+ end
+
+ it "supports form pat, pat, ..." do
+ case [0, 1, 2]
+ in 0, 1, 2
+ true
+ end.should == true
+
+ case [0, 1, 2]
+ in 0, a, 2
+ a
+ end.should == 1
+
+ case [0, 1, 2]
+ in 0, *rest
+ rest
+ end.should == [1, 2]
+ end
+
+ it "matches an object with #deconstruct method which returns an array and each element in array matches element in pattern" do
+ obj = Object.new
+
+ def obj.deconstruct
+ [0, 1]
+ end
+
+ case obj
+ in [Integer, Integer]
+ true
+ end.should == true
+ end
+
+ it "calls #deconstruct once for multiple patterns, caching the result" do
+ obj = Object.new
+
+ def obj.deconstruct
+ ScratchPad << :deconstruct
+ [0, 1]
+ end
+
+ case obj
+ in [1, 2]
+ false
+ in [0, 1]
+ true
+ end.should == true
+
+ ScratchPad.recorded.should == [:deconstruct]
+ end
+
+ it "calls #deconstruct even on objects that are already an array" do
+ obj = [1, 2]
+
+ def obj.deconstruct
+ ScratchPad << :deconstruct
+ [3, 4]
+ end
+
+ case obj
+ in [3, 4]
+ true
+ else
+ false
+ end.should == true
+
+ ScratchPad.recorded.should == [:deconstruct]
+ end
+
+ it "does not match object if Constant === object returns false" do
+ case [0, 1, 2]
+ in String[0, 1, 2]
+ true
+ else
+ false
+ end.should == false
+ end
+
+ it "checks Constant === object before calling #deconstruct" do
+ c1 = Class.new
+ obj = c1.new
+ obj.should_not_receive(:deconstruct)
+
+ case obj
+ in String[1]
+ true
+ else
+ false
+ end.should == false
+ end
+
+ it "does not match object without #deconstruct method" do
+ obj = Object.new
+ obj.should_receive(:respond_to?).with(:deconstruct)
+
+ case obj
+ in Object[]
+ true
+ else
+ false
+ end.should == false
+ end
+
+ it "raises TypeError if #deconstruct method does not return array" do
+ obj = Object.new
+
+ def obj.deconstruct
+ ""
+ end
+
+ -> {
+ case obj
+ in Object[]
+ else
+ end
+ }.should.raise(TypeError, /deconstruct must return Array/)
+ end
+
+ it "accepts a subclass of Array from #deconstruct" do
+ obj = Object.new
+
+ def obj.deconstruct
+ Class.new(Array).new([0, 1])
+ end
+
+ case obj
+ in [1, 2]
+ false
+ in [0, 1]
+ true
+ end.should == true
+ end
+
+ it "does not match object if elements of array returned by #deconstruct method does not match elements in pattern" do
+ obj = Object.new
+
+ def obj.deconstruct
+ [1]
+ end
+
+ case obj
+ in Object[0]
+ true
+ else
+ false
+ end.should == false
+ end
+
+ it "binds variables" do
+ case [0, 1, 2]
+ in [a, b, c]
+ [a, b, c]
+ end.should == [0, 1, 2]
+ end
+
+ it "supports splat operator *rest" do
+ case [0, 1, 2]
+ in [0, *rest]
+ rest
+ end.should == [1, 2]
+ end
+
+ it "does not match partially by default" do
+ case [0, 1, 2, 3]
+ in [1, 2]
+ true
+ else
+ false
+ end.should == false
+ end
+
+ it "does match partially from the array beginning if list + , syntax used" do
+ case [0, 1, 2, 3]
+ in [0, 1, ]
+ true
+ end.should == true
+
+ case [0, 1, 2, 3]
+ in 0, 1,;
+ true
+ end.should == true
+ end
+
+ it "matches [] with []" do
+ case []
+ in []
+ true
+ end.should == true
+ end
+
+ it "matches anything with *" do
+ case [0, 1]
+ in *;
+ true
+ end.should == true
+ end
+
+ it "can be used as a nested pattern" do
+ case [[1], ["2"]]
+ in [[0] | nil, _]
+ false
+ in [[1], [1]]
+ false
+ in [[1], [2 | "2"]]
+ true
+ end.should == true
+
+ case [1, 2]
+ in [0, _] | {a: 0}
+ false
+ in {a: 1, b: 2} | [1, 2]
+ true
+ end.should == true
+ end
+ end
+
+ describe "Hash pattern" do
+ it "supports form Constant(id: pat, id: pat, ...)" do
+ case {a: 0, b: 1}
+ in Hash(a: 0, b: 1)
+ true
+ end.should == true
+ end
+
+ it "supports form Constant[id: pat, id: pat, ...]" do
+ case {a: 0, b: 1}
+ in Hash[a: 0, b: 1]
+ true
+ end.should == true
+ end
+
+ it "supports form {id: pat, id: pat, ...}" do
+ case {a: 0, b: 1}
+ in {a: 0, b: 1}
+ true
+ end.should == true
+ end
+
+ it "supports form id: pat, id: pat, ..." do
+ case {a: 0, b: 1}
+ in a: 0, b: 1
+ true
+ end.should == true
+
+ case {a: 0, b: 1}
+ in a: a, b: b
+ [a, b]
+ end.should == [0, 1]
+
+ case {a: 0, b: 1, c: 2}
+ in a: 0, **rest
+ rest
+ end.should == {b: 1, c: 2}
+ end
+
+ it "supports a: which means a: a" do
+ case {a: 0, b: 1}
+ in Hash(a:, b:)
+ [a, b]
+ end.should == [0, 1]
+
+ a = b = nil
+
+ case {a: 0, b: 1}
+ in Hash[a:, b:]
+ [a, b]
+ end.should == [0, 1]
+
+ a = b = nil
+
+ case {a: 0, b: 1}
+ in {a:, b:}
+ [a, b]
+ end.should == [0, 1]
+
+ a = nil
+
+ case {a: 0, b: 1, c: 2}
+ in {a:, **rest}
+ [a, rest]
+ end.should == [0, {b: 1, c: 2}]
+
+ a = b = nil
+
+ case {a: 0, b: 1}
+ in a:, b:
+ [a, b]
+ end.should == [0, 1]
+ end
+
+ it "can mix key (a:) and key-value (a: b) declarations" do
+ case {a: 0, b: 1}
+ in Hash(a:, b: x)
+ [a, x]
+ end.should == [0, 1]
+ end
+
+ it "supports 'string': key literal" do
+ case {a: 0}
+ in {"a": 0}
+ true
+ end.should == true
+ end
+
+ it "does not support non-symbol keys" do
+ -> {
+ eval <<~RUBY
+ case {a: 1}
+ in {"a" => 1}
+ end
+ RUBY
+ }.should.raise(SyntaxError, /unexpected|expected a label as the key in the hash pattern/)
+ end
+
+ it "does not support string interpolation in keys" do
+ -> {
+ eval <<~'RUBY'
+ case {a: 1}
+ in {"#{x}": 1}
+ end
+ RUBY
+ }.should.raise(SyntaxError, /symbol literal with interpolation is not allowed|expected a label as the key in the hash pattern/)
+ end
+
+ it "raise SyntaxError when keys duplicate in pattern" do
+ -> {
+ eval <<~RUBY
+ case {a: 1}
+ in {a: 1, b: 2, a: 3}
+ end
+ RUBY
+ }.should.raise(SyntaxError, /duplicated key name/)
+ end
+
+ it "matches an object with #deconstruct_keys method which returns a Hash with equal keys and each value in Hash matches value in pattern" do
+ obj = Object.new
+
+ def obj.deconstruct_keys(*)
+ {a: 1}
+ end
+
+ case obj
+ in {a: 1}
+ true
+ end.should == true
+ end
+
+ it "calls #deconstruct_keys per pattern" do
+ obj = Object.new
+
+ def obj.deconstruct_keys(*)
+ ScratchPad << :deconstruct_keys
+ {a: 1}
+ end
+
+ case obj
+ in {b: 1}
+ false
+ in {a: 1}
+ true
+ end.should == true
+
+ ScratchPad.recorded.should == [:deconstruct_keys, :deconstruct_keys]
+ end
+
+ it "does not match object if Constant === object returns false" do
+ case {a: 1}
+ in String[a: 1]
+ true
+ else
+ false
+ end.should == false
+ end
+
+ it "checks Constant === object before calling #deconstruct_keys" do
+ c1 = Class.new
+ obj = c1.new
+ obj.should_not_receive(:deconstruct_keys)
+
+ case obj
+ in String(a: 1)
+ true
+ else
+ false
+ end.should == false
+ end
+
+ it "does not match object without #deconstruct_keys method" do
+ obj = Object.new
+ obj.should_receive(:respond_to?).with(:deconstruct_keys)
+
+ case obj
+ in Object[a: 1]
+ true
+ else
+ false
+ end.should == false
+ end
+
+ it "does not match object if #deconstruct_keys method does not return Hash" do
+ obj = Object.new
+
+ def obj.deconstruct_keys(*)
+ ""
+ end
+
+ -> {
+ case obj
+ in Object[a: 1]
+ end
+ }.should.raise(TypeError, /deconstruct_keys must return Hash/)
+ end
+
+ it "does not match object if #deconstruct_keys method returns Hash with non-symbol keys" do
+ obj = Object.new
+
+ def obj.deconstruct_keys(*)
+ {"a" => 1}
+ end
+
+ case obj
+ in Object[a: 1]
+ true
+ else
+ false
+ end.should == false
+ end
+
+ it "does not match object if elements of Hash returned by #deconstruct_keys method does not match values in pattern" do
+ obj = Object.new
+
+ def obj.deconstruct_keys(*)
+ {a: 1}
+ end
+
+ case obj
+ in Object[a: 2]
+ true
+ else
+ false
+ end.should == false
+ end
+
+ it "passes keys specified in pattern as arguments to #deconstruct_keys method" do
+ obj = Object.new
+
+ def obj.deconstruct_keys(*args)
+ ScratchPad << args
+ {a: 1, b: 2, c: 3}
+ end
+
+ case obj
+ in Object[a: 1, b: 2, c: 3]
+ end
+
+ ScratchPad.recorded.sort.should == [[[:a, :b, :c]]]
+ end
+
+ it "passes keys specified in pattern to #deconstruct_keys method if pattern contains double splat operator **" do
+ obj = Object.new
+
+ def obj.deconstruct_keys(*args)
+ ScratchPad << args
+ {a: 1, b: 2, c: 3}
+ end
+
+ case obj
+ in Object[a: 1, b: 2, **]
+ end
+
+ ScratchPad.recorded.sort.should == [[[:a, :b]]]
+ end
+
+ it "passes nil to #deconstruct_keys method if pattern contains double splat operator **rest" do
+ obj = Object.new
+
+ def obj.deconstruct_keys(*args)
+ ScratchPad << args
+ {a: 1, b: 2}
+ end
+
+ case obj
+ in Object[a: 1, **rest]
+ end
+
+ ScratchPad.recorded.should == [[nil]]
+ end
+
+ it "binds variables" do
+ case {a: 0, b: 1, c: 2}
+ in {a: x, b: y, c: z}
+ [x, y, z]
+ end.should == [0, 1, 2]
+ end
+
+ it "supports double splat operator **rest" do
+ case {a: 0, b: 1, c: 2}
+ in {a: 0, **rest}
+ rest
+ end.should == {b: 1, c: 2}
+ end
+
+ it "treats **nil like there should not be any other keys in a matched Hash" do
+ case {a: 1, b: 2}
+ in {a: 1, b: 2, **nil}
+ true
+ end.should == true
+
+ case {a: 1, b: 2}
+ in {a: 1, **nil}
+ true
+ else
+ false
+ end.should == false
+ end
+
+ it "can match partially" do
+ case {a: 1, b: 2}
+ in {a: 1}
+ true
+ end.should == true
+ end
+
+ it "matches {} with {}" do
+ case {}
+ in {}
+ true
+ end.should == true
+ end
+
+ it "in {} only matches empty hashes" do
+ case {a: 1}
+ in {}
+ true
+ else
+ false
+ end.should == false
+ end
+
+ it "in {**nil} only matches empty hashes" do
+ case {}
+ in {**nil}
+ true
+ else
+ false
+ end.should == true
+
+ case {a: 1}
+ in {**nil}
+ true
+ else
+ false
+ end.should == false
+ end
+
+ it "matches anything with **" do
+ case {a: 1}
+ in **;
+ true
+ end.should == true
+ end
+
+ it "can be used as a nested pattern" do
+ case {a: {a: 1, b: 1}, b: {a: 1, b: 2}}
+ in {a: {a: 0}}
+ false
+ in {a: {a: 1}, b: {b: 1}}
+ false
+ in {a: {a: 1}, b: {b: 2} }
+ true
+ end.should == true
+
+ case [{a: 1, b: [1]}, {a: 1, c: ["2"]}]
+ in [{a:, c:}, ]
+ false
+ in [{a: 1, b:}, {a: 1, c: [Integer]}]
+ false
+ in [_, {a: 1, c: [String]}]
+ true
+ end.should == true
+ end
+ end
+
+ describe "refinements" do
+ it "are used for #deconstruct" do
+ refinery = Module.new do
+ refine Array do
+ def deconstruct
+ [0]
+ end
+ end
+ end
+
+ result = nil
+ Module.new do
+ using refinery
+
+ result =
+ case []
+ in [0]
+ true
+ end
+ end
+
+ result.should == true
+ end
+
+ it "are used for #deconstruct_keys" do
+ refinery = Module.new do
+ refine Hash do
+ def deconstruct_keys(_)
+ {a: 0}
+ end
+ end
+ end
+
+ result = nil
+ Module.new do
+ using refinery
+
+ result =
+ case {}
+ in a: 0
+ true
+ end
+ end
+
+ result.should == true
+ end
+
+ it "are used for #=== in constant pattern" do
+ refinery = Module.new do
+ refine Array.singleton_class do
+ def ===(obj)
+ obj.is_a?(Hash)
+ end
+ end
+ end
+
+ result = nil
+ Module.new do
+ using refinery
+
+ result =
+ case {}
+ in Array
+ true
+ end
+ end
+
+ result.should == true
+ end
+ end
+
+ describe "Ruby 3.1 improvements" do
+ it "can omit parentheses in one line pattern matching" do
+ [1, 2] => a, b
+ [a, b].should == [1, 2]
+
+ {a: 1} => a:
+ a.should == 1
+ end
+
+ it "supports pinning instance variables" do
+ @a = /a/
+ case 'abc'
+ in ^@a
+ true
+ end.should == true
+ end
+
+ it "supports pinning class variables" do
+ result = nil
+ Module.new do
+ # avoid "class variable access from toplevel" runtime error with #module_eval
+ result = module_eval(<<~RUBY)
+ @@a = 0..10
+
+ case 2
+ in ^@@a
+ true
+ end
+ RUBY
+ end
+
+ result.should == true
+ end
+
+ it "supports pinning global variables" do
+ $a = /a/
+ case 'abc'
+ in ^$a
+ true
+ end.should == true
+ end
+
+ it "supports pinning expressions" do
+ case 'abc'
+ in ^(/a/)
+ true
+ end.should == true
+
+ case 0
+ in ^(0 + 0)
+ true
+ end.should == true
+ end
+
+ it "supports pinning expressions in array pattern" do
+ case [3]
+ in [^(1 + 2)]
+ true
+ end.should == true
+ end
+
+ it "supports pinning expressions in hash pattern" do
+ case {name: '2.6', released_at: Time.new(2018, 12, 25)}
+ in {released_at: ^(Time.new(2010)..Time.new(2020))}
+ true
+ end.should == true
+ end
+ end
+
+ describe "value in pattern" do
+ it "returns true if the pattern matches" do
+ (1 in 1).should == true
+
+ (1 in Integer).should == true
+
+ e = nil
+ ([1, 2] in [1, e]).should == true
+ e.should == 2
+
+ k = nil
+ ({k: 1} in {k:}).should == true
+ k.should == 1
+ end
+
+ it "returns false if the pattern does not match" do
+ (1 in 2).should == false
+
+ (1 in Float).should == false
+
+ ([1, 2] in [2, e]).should == false
+
+ ({k: 1} in {k: 2}).should == false
+ end
+ end
+end
diff --git a/spec/ruby/language/precedence_spec.rb b/spec/ruby/language/precedence_spec.rb
index 90734022ff..edb990525e 100644
--- a/spec/ruby/language/precedence_spec.rb
+++ b/spec/ruby/language/precedence_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/precedence', __FILE__)
+require_relative '../spec_helper'
+require_relative 'fixtures/precedence'
# Specifying the behavior of operators in combination could
# lead to combinatorial explosion. A better way seems to be
@@ -14,46 +14,44 @@ require File.expand_path('../fixtures/precedence', __FILE__)
# the level below (as well as showing associativity within
# the precedence level).
-=begin
-Excerpted from 'Programming Ruby: The Pragmatic Programmer's Guide'
-Second Edition by Dave Thomas, Chad Fowler, and Andy Hunt, page 324
-
-Table 22.4. Ruby operators (high to low precedence)
-Method Operator Description
------------------------------------------------------------------------
- :: .
- x* [ ] [ ]= Element reference, element set
- x ** Exponentiation
- x ! ~ + - Not, complement, unary plus and minus
- (method names for the last two are +@ and -@)
- x * / % Multiply, divide, and modulo
- x + - Plus and minus
- x >> << Right and left shift
- x & “And†(bitwise for integers)
- x ^ | Exclusive “or†and regular “or†(bitwise for integers)
- x <= < > >= Comparison operators
- x <=> == === != =~ !~ Equality and pattern match operators (!=
- and !~ may not be defined as methods)
- && Logical “andâ€
- || Logical “orâ€
- .. ... Range (inclusive and exclusive)
- ? : Ternary if-then-else
- = %= /= -= += |= &= Assignment
- >>= <<= *= &&= ||= **=
- defined? Check if symbol defined
- not Logical negation
- or and Logical composition
- if unless while until Expression modifiers
- begin/end Block expression
------------------------------------------------------------------------
-
-* Operators marked with 'x' in the Method column are implemented as methods
-and can be overridden (except != and !~ as noted). (But see the specs
-below for implementations that define != and !~ as methods.)
-
-** These are not included in the excerpted table but are shown here for
-completeness.
-=end
+# Excerpted from 'Programming Ruby: The Pragmatic Programmer's Guide'
+# Second Edition by Dave Thomas, Chad Fowler, and Andy Hunt, page 324
+#
+# Table 22.4. Ruby operators (high to low precedence)
+# Method Operator Description
+# -----------------------------------------------------------------------
+# :: .
+# x* [ ] [ ]= Element reference, element set
+# x ** Exponentiation
+# x ! ~ + - Not, complement, unary plus and minus
+# (method names for the last two are +@ and -@)
+# x * / % Multiply, divide, and modulo
+# x + - Plus and minus
+# x >> << Right and left shift
+# x & “And†(bitwise for integers)
+# x ^ | Exclusive “or†and regular “or†(bitwise for integers)
+# x <= < > >= Comparison operators
+# x <=> == === != =~ !~ Equality and pattern match operators (!=
+# and !~ may not be defined as methods)
+# && Logical “andâ€
+# || Logical “orâ€
+# .. ... Range (inclusive and exclusive)
+# ? : Ternary if-then-else
+# = %= /= -= += |= &= Assignment
+# >>= <<= *= &&= ||= **=
+# defined? Check if symbol defined
+# not Logical negation
+# or and Logical composition
+# if unless while until Expression modifiers
+# begin/end Block expression
+# -----------------------------------------------------------------------
+#
+# * Operators marked with 'x' in the Method column are implemented as methods
+# and can be overridden (except != and !~ as noted). (But see the specs
+# below for implementations that define != and !~ as methods.)
+#
+# ** These are not included in the excerpted table but are shown here for
+# completeness.
# -----------------------------------------------------------------------
# It seems that this table is not correct anymore
@@ -136,7 +134,7 @@ describe "Operators" do
# Guard against the Mathn library
# TODO: Make these specs not rely on specific behaviour / result values
# by using mocks.
- conflicts_with :Prime do
+ guard -> { !defined?(Math.rsqrt) } do
(2*1/2).should_not == 2*(1/2)
end
@@ -253,12 +251,12 @@ describe "Operators" do
end
it "<=> == === != =~ !~ are non-associative" do
- lambda { eval("1 <=> 2 <=> 3") }.should raise_error(SyntaxError)
- lambda { eval("1 == 2 == 3") }.should raise_error(SyntaxError)
- lambda { eval("1 === 2 === 3") }.should raise_error(SyntaxError)
- lambda { eval("1 != 2 != 3") }.should raise_error(SyntaxError)
- lambda { eval("1 =~ 2 =~ 3") }.should raise_error(SyntaxError)
- lambda { eval("1 !~ 2 !~ 3") }.should raise_error(SyntaxError)
+ -> { eval("1 <=> 2 <=> 3") }.should.raise(SyntaxError)
+ -> { eval("1 == 2 == 3") }.should.raise(SyntaxError)
+ -> { eval("1 === 2 === 3") }.should.raise(SyntaxError)
+ -> { eval("1 != 2 != 3") }.should.raise(SyntaxError)
+ -> { eval("1 =~ 2 =~ 3") }.should.raise(SyntaxError)
+ -> { eval("1 !~ 2 !~ 3") }.should.raise(SyntaxError)
end
it "<=> == === != =~ !~ have higher precedence than &&" do
@@ -292,19 +290,18 @@ describe "Operators" do
end
it ".. ... are non-associative" do
- lambda { eval("1..2..3") }.should raise_error(SyntaxError)
- lambda { eval("1...2...3") }.should raise_error(SyntaxError)
+ -> { eval("1..2..3") }.should.raise(SyntaxError)
+ -> { eval("1...2...3") }.should.raise(SyntaxError)
end
-# XXX: this is commented now due to a bug in compiler, which cannot
-# distinguish between range and flip-flop operator so far. zenspider is
-# currently working on a new lexer, which will be able to do that.
-# As soon as it's done, these piece should be reenabled.
-#
-# it ".. ... have higher precedence than ? :" do
-# (1..2 ? 3 : 4).should == 3
-# (1...2 ? 3 : 4).should == 3
-# end
+ it ".. ... have higher precedence than ? :" do
+ # Use variables to avoid warnings
+ from = 1
+ to = 2
+ # These are flip-flop, not Range instances
+ (from..to ? 3 : 4).should == 3
+ (from...to ? 3 : 4).should == 3
+ end
it "? : is right-associative" do
(true ? 2 : 3 ? 4 : 5).should == 2
diff --git a/spec/ruby/language/predefined/data_spec.rb b/spec/ruby/language/predefined/data_spec.rb
index f616879527..921d236ee9 100644
--- a/spec/ruby/language/predefined/data_spec.rb
+++ b/spec/ruby/language/predefined/data_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "The DATA constant" do
it "exists when the main script contains __END__" do
@@ -23,6 +23,25 @@ describe "The DATA constant" do
str.chomp.should == "data only"
end
+ it "returns a File object with the right offset" do
+ ruby_exe(fixture(__FILE__, "data_offset.rb")).should == "File\n121\n"
+ end
+
+ it "is set even if there is no data after __END__" do
+ ruby_exe(fixture(__FILE__, "empty_data.rb")).should == "31\n\"\"\n"
+ end
+
+ it "is set even if there is no newline after __END__" do
+ path = tmp("no_newline_data.rb")
+ code = File.binread(fixture(__FILE__, "empty_data.rb"))
+ touch(path, "wb") { |f| f.write code.chomp }
+ begin
+ ruby_exe(path).should == "30\n\"\"\n"
+ ensure
+ rm_r path
+ end
+ end
+
it "rewinds to the head of the main script" do
ruby_exe(fixture(__FILE__, "data5.rb")).chomp.should == "DATA.rewind"
end
diff --git a/spec/ruby/language/predefined/fixtures/data2.rb b/spec/ruby/language/predefined/fixtures/data2.rb
index 0f714b06d4..a764ca56d1 100644
--- a/spec/ruby/language/predefined/fixtures/data2.rb
+++ b/spec/ruby/language/predefined/fixtures/data2.rb
@@ -1,4 +1,3 @@
-
-require File.expand_path("../data4.rb", __FILE__)
+require_relative 'data4'
p Object.const_defined?(:DATA)
diff --git a/spec/ruby/language/predefined/fixtures/data3.rb b/spec/ruby/language/predefined/fixtures/data3.rb
index 6cbf63dae6..e37313c68b 100644
--- a/spec/ruby/language/predefined/fixtures/data3.rb
+++ b/spec/ruby/language/predefined/fixtures/data3.rb
@@ -1,5 +1,4 @@
-
-require File.expand_path("../data4.rb", __FILE__)
+require_relative 'data4'
puts DATA.read
diff --git a/spec/ruby/language/predefined/fixtures/data_offset.rb b/spec/ruby/language/predefined/fixtures/data_offset.rb
new file mode 100644
index 0000000000..9829b3f87f
--- /dev/null
+++ b/spec/ruby/language/predefined/fixtures/data_offset.rb
@@ -0,0 +1,12 @@
+# some comment
+
+foo = <<HEREDOC
+some heredoc to make the
+spec more interesting
+HEREDOC
+
+p DATA.class
+p DATA.pos
+
+__END__
+data offset
diff --git a/spec/ruby/language/predefined/fixtures/empty_data.rb b/spec/ruby/language/predefined/fixtures/empty_data.rb
new file mode 100644
index 0000000000..c6d9bc6f1f
--- /dev/null
+++ b/spec/ruby/language/predefined/fixtures/empty_data.rb
@@ -0,0 +1,3 @@
+p DATA.pos
+p DATA.read
+__END__
diff --git a/spec/ruby/language/predefined/fixtures/toplevel_binding_dynamic.rb b/spec/ruby/language/predefined/fixtures/toplevel_binding_dynamic.rb
new file mode 100644
index 0000000000..f7809109fa
--- /dev/null
+++ b/spec/ruby/language/predefined/fixtures/toplevel_binding_dynamic.rb
@@ -0,0 +1,4 @@
+p TOPLEVEL_BINDING.local_variables.sort
+TOPLEVEL_BINDING.local_variable_set(:dynamic_set_main, 2)
+p TOPLEVEL_BINDING.local_variables.sort
+main_script = 3
diff --git a/spec/ruby/language/predefined/fixtures/toplevel_binding_dynamic_required.rb b/spec/ruby/language/predefined/fixtures/toplevel_binding_dynamic_required.rb
new file mode 100644
index 0000000000..7ccf329680
--- /dev/null
+++ b/spec/ruby/language/predefined/fixtures/toplevel_binding_dynamic_required.rb
@@ -0,0 +1,2 @@
+TOPLEVEL_BINDING.local_variable_set(:dynamic_set_required, 1)
+p TOPLEVEL_BINDING.local_variables
diff --git a/spec/ruby/language/predefined/fixtures/toplevel_binding_id.rb b/spec/ruby/language/predefined/fixtures/toplevel_binding_id.rb
new file mode 100644
index 0000000000..3626ea1f10
--- /dev/null
+++ b/spec/ruby/language/predefined/fixtures/toplevel_binding_id.rb
@@ -0,0 +1,4 @@
+a = TOPLEVEL_BINDING.object_id
+require_relative 'toplevel_binding_id_required'
+c = eval('TOPLEVEL_BINDING.object_id')
+p [a, $b, c].uniq.size
diff --git a/spec/ruby/language/predefined/fixtures/toplevel_binding_id_required.rb b/spec/ruby/language/predefined/fixtures/toplevel_binding_id_required.rb
new file mode 100644
index 0000000000..b31b6e32a0
--- /dev/null
+++ b/spec/ruby/language/predefined/fixtures/toplevel_binding_id_required.rb
@@ -0,0 +1 @@
+$b = TOPLEVEL_BINDING.object_id
diff --git a/spec/ruby/language/predefined/fixtures/toplevel_binding_required_before.rb b/spec/ruby/language/predefined/fixtures/toplevel_binding_required_before.rb
new file mode 100644
index 0000000000..58924a5800
--- /dev/null
+++ b/spec/ruby/language/predefined/fixtures/toplevel_binding_required_before.rb
@@ -0,0 +1,2 @@
+required = true
+p [:required_before, TOPLEVEL_BINDING.local_variables]
diff --git a/spec/ruby/language/predefined/fixtures/toplevel_binding_values.rb b/spec/ruby/language/predefined/fixtures/toplevel_binding_values.rb
new file mode 100644
index 0000000000..42bd67f347
--- /dev/null
+++ b/spec/ruby/language/predefined/fixtures/toplevel_binding_values.rb
@@ -0,0 +1,9 @@
+p TOPLEVEL_BINDING.local_variable_get(:a)
+p TOPLEVEL_BINDING.local_variable_get(:b)
+a = 1
+p TOPLEVEL_BINDING.local_variable_get(:a)
+p TOPLEVEL_BINDING.local_variable_get(:b)
+b = 2
+a = 3
+p TOPLEVEL_BINDING.local_variable_get(:a)
+p TOPLEVEL_BINDING.local_variable_get(:b)
diff --git a/spec/ruby/language/predefined/fixtures/toplevel_binding_variables.rb b/spec/ruby/language/predefined/fixtures/toplevel_binding_variables.rb
new file mode 100644
index 0000000000..151f4340ef
--- /dev/null
+++ b/spec/ruby/language/predefined/fixtures/toplevel_binding_variables.rb
@@ -0,0 +1,4 @@
+main_script = 1
+require_relative 'toplevel_binding_variables_required'
+eval('eval_var = 3')
+p TOPLEVEL_BINDING.local_variables
diff --git a/spec/ruby/language/predefined/fixtures/toplevel_binding_variables_required.rb b/spec/ruby/language/predefined/fixtures/toplevel_binding_variables_required.rb
new file mode 100644
index 0000000000..614547fe16
--- /dev/null
+++ b/spec/ruby/language/predefined/fixtures/toplevel_binding_variables_required.rb
@@ -0,0 +1,2 @@
+required = 2
+p [:required_after, TOPLEVEL_BINDING.local_variables]
diff --git a/spec/ruby/language/predefined/toplevel_binding_spec.rb b/spec/ruby/language/predefined/toplevel_binding_spec.rb
new file mode 100644
index 0000000000..69ac28618c
--- /dev/null
+++ b/spec/ruby/language/predefined/toplevel_binding_spec.rb
@@ -0,0 +1,34 @@
+require_relative '../../spec_helper'
+
+describe "The TOPLEVEL_BINDING constant" do
+ it "only includes local variables defined in the main script, not in required files or eval" do
+ binding_toplevel_variables = ruby_exe(fixture(__FILE__, "toplevel_binding_variables.rb"))
+ binding_toplevel_variables.should == "[:required_after, [:main_script]]\n[:main_script]\n"
+ end
+
+ it "has no local variables in files required before the main script" do
+ required = fixture(__FILE__, 'toplevel_binding_required_before.rb')
+ out = ruby_exe("a=1; p TOPLEVEL_BINDING.local_variables.sort; b=2", options: "-r#{required}")
+ out.should == "[:required_before, []]\n[:a, :b]\n"
+ end
+
+ it "merges local variables of the main script with dynamically-defined Binding variables" do
+ required = fixture(__FILE__, 'toplevel_binding_dynamic_required.rb')
+ out = ruby_exe(fixture(__FILE__, 'toplevel_binding_dynamic.rb'), options: "-r#{required}")
+ out.should == <<EOS
+[:dynamic_set_required]
+[:dynamic_set_required, :main_script]
+[:dynamic_set_main, :dynamic_set_required, :main_script]
+EOS
+ end
+
+ it "gets updated variables values as they are defined and set" do
+ out = ruby_exe(fixture(__FILE__, "toplevel_binding_values.rb"))
+ out.should == "nil\nnil\n1\nnil\n3\n2\n"
+ end
+
+ it "is always the same object for all top levels" do
+ binding_toplevel_id = ruby_exe(fixture(__FILE__, "toplevel_binding_id.rb"))
+ binding_toplevel_id.should == "1\n"
+ end
+end
diff --git a/spec/ruby/language/predefined_spec.rb b/spec/ruby/language/predefined_spec.rb
index f827fb2eb5..f14f8ba93e 100644
--- a/spec/ruby/language/predefined_spec.rb
+++ b/spec/ruby/language/predefined_spec.rb
@@ -1,4 +1,5 @@
-require File.expand_path('../../spec_helper', __FILE__)
+require_relative '../spec_helper'
+require_relative '../core/exception/shared/set_backtrace'
require 'stringio'
# The following tables are excerpted from Programming Ruby: The Pragmatic Programmer's Guide'
@@ -7,56 +8,52 @@ require 'stringio'
# Entries marked [r/o] are read-only and an error will be raised of the program attempts to
# modify them. Entries marked [thread] are thread local.
-=begin
-Exception Information
----------------------------------------------------------------------------------------------------
-
-$! Exception The exception object passed to raise. [thread]
-$@ Array The stack backtrace generated by the last exception. [thread]
-=end
-
-=begin
-Pattern Matching Variables
----------------------------------------------------------------------------------------------------
-
-These variables are set to nil after an unsuccessful pattern match.
-
-$& String The string matched (following a successful pattern match). This variable is
- local to the current scope. [r/o, thread]
-$+ String The contents of the highest-numbered group matched following a successful
- pattern match. Thus, in "cat" =~/(c|a)(t|z)/, $+ will be set to “tâ€. This
- variable is local to the current scope. [r/o, thread]
-$` String The string preceding the match in a successful pattern match. This variable
- is local to the current scope. [r/o, thread]
-$' String The string following the match in a successful pattern match. This variable
- is local to the current scope. [r/o, thread]
-$1 to $9 String The contents of successive groups matched in a successful pattern match. In
- "cat" =~/(c|a)(t|z)/, $1 will be set to “a†and $2 to “tâ€. This variable
- is local to the current scope. [r/o, thread]
-$~ MatchData An object that encapsulates the results of a successful pattern match. The
- variables $&, $`, $', and $1 to $9 are all derived from $~. Assigning to $~
- changes the values of these derived variables. This variable is local to the
- current scope. [thread]
-=end
+# Exception Information
+# ---------------------------------------------------------------------------------------------------
+#
+# $! Exception The exception object passed to raise. [thread]
+# $@ Array The stack backtrace generated by the last exception. [thread]
+
+# Pattern Matching Variables
+# ---------------------------------------------------------------------------------------------------
+#
+# These variables are set to nil after an unsuccessful pattern match.
+#
+# $& String The string matched (following a successful pattern match). This variable is
+# local to the current scope. [r/o, thread]
+# $+ String The contents of the highest-numbered group matched following a successful
+# pattern match. Thus, in "cat" =~/(c|a)(t|z)/, $+ will be set to “tâ€. This
+# variable is local to the current scope. [r/o, thread]
+# $` String The string preceding the match in a successful pattern match. This variable
+# is local to the current scope. [r/o, thread]
+# $' String The string following the match in a successful pattern match. This variable
+# is local to the current scope. [r/o, thread]
+# $1 to $<N> String The contents of successive groups matched in a successful pattern match. In
+# "cat" =~/(c|a)(t|z)/, $1 will be set to “a†and $2 to “tâ€. This variable
+# is local to the current scope. [r/o, thread]
+# $~ MatchData An object that encapsulates the results of a successful pattern match. The
+# variables $&, $`, $', and $1 to $<N> are all derived from $~. Assigning to $~
+# changes the values of these derived variables. This variable is local to the
+# current scope. [thread]
describe "Predefined global $~" do
it "is set to contain the MatchData object of the last match if successful" do
md = /foo/.match 'foo'
- $~.should be_kind_of(MatchData)
- $~.object_id.should == md.object_id
+ $~.should.is_a?(MatchData)
+ $~.should.equal? md
/bar/ =~ 'bar'
- $~.should be_kind_of(MatchData)
- $~.object_id.should_not == md.object_id
+ $~.should.is_a?(MatchData)
+ $~.should_not.equal? md
end
it "is set to nil if the last match was unsuccessful" do
/foo/ =~ 'foo'
- $~.nil?.should == false
+ $~.should_not.nil?
/foo/ =~ 'bar'
- $~.nil?.should == true
+ $~.should.nil?
end
it "is set at the method-scoped level rather than block-scoped" do
@@ -75,7 +72,7 @@ describe "Predefined global $~" do
match2.should_not == nil
$~.should == match2
- eval 'match3 = /baz/.match("baz")'
+ match3 = /baz/.match("baz")
match3.should_not == nil
$~.should == match3
@@ -90,10 +87,10 @@ describe "Predefined global $~" do
$~ = nil
$~.should == nil
$~ = /foo/.match("foo")
- $~.should be_an_instance_of(MatchData)
+ $~.should.instance_of?(MatchData)
- lambda { $~ = Object.new }.should raise_error(TypeError)
- lambda { $~ = 1 }.should raise_error(TypeError)
+ -> { $~ = Object.new }.should.raise(TypeError, 'wrong argument type Object (expected MatchData)')
+ -> { $~ = 1 }.should.raise(TypeError, 'wrong argument type Integer (expected MatchData)')
end
it "changes the value of derived capture globals when assigned" do
@@ -136,11 +133,22 @@ describe "Predefined global $&" do
$&.should == 'foo'
end
- with_feature :encoding do
- it "sets the encoding to the encoding of the source String" do
- "abc".force_encoding(Encoding::EUC_JP) =~ /b/
- $&.encoding.should equal(Encoding::EUC_JP)
- end
+ it "sets the encoding to the encoding of the source String" do
+ "abc".dup.force_encoding(Encoding::EUC_JP) =~ /b/
+ $&.encoding.should.equal?(Encoding::EUC_JP)
+ end
+
+ it "is read-only" do
+ -> {
+ eval %q{$& = ""}
+ }.should.raise(SyntaxError, /Can't set variable \$&/)
+ end
+
+ it "is read-only when aliased" do
+ alias $predefined_spec_ampersand $&
+ -> {
+ $predefined_spec_ampersand = ""
+ }.should.raise(NameError, '$predefined_spec_ampersand is a read-only variable')
end
end
@@ -151,16 +159,27 @@ describe "Predefined global $`" do
$`.should == 'bar'
end
- with_feature :encoding do
- it "sets the encoding to the encoding of the source String" do
- "abc".force_encoding(Encoding::EUC_JP) =~ /b/
- $`.encoding.should equal(Encoding::EUC_JP)
- end
+ it "sets the encoding to the encoding of the source String" do
+ "abc".dup.force_encoding(Encoding::EUC_JP) =~ /b/
+ $`.encoding.should.equal?(Encoding::EUC_JP)
+ end
- it "sets an empty result to the encoding of the source String" do
- "abc".force_encoding(Encoding::ISO_8859_1) =~ /a/
- $`.encoding.should equal(Encoding::ISO_8859_1)
- end
+ it "sets an empty result to the encoding of the source String" do
+ "abc".dup.force_encoding(Encoding::ISO_8859_1) =~ /a/
+ $`.encoding.should.equal?(Encoding::ISO_8859_1)
+ end
+
+ it "is read-only" do
+ -> {
+ eval %q{$` = ""}
+ }.should.raise(SyntaxError, /Can't set variable \$`/)
+ end
+
+ it "is read-only when aliased" do
+ alias $predefined_spec_backquote $`
+ -> {
+ $predefined_spec_backquote = ""
+ }.should.raise(NameError, '$predefined_spec_backquote is a read-only variable')
end
end
@@ -171,16 +190,27 @@ describe "Predefined global $'" do
$'.should == 'baz'
end
- with_feature :encoding do
- it "sets the encoding to the encoding of the source String" do
- "abc".force_encoding(Encoding::EUC_JP) =~ /b/
- $'.encoding.should equal(Encoding::EUC_JP)
- end
+ it "sets the encoding to the encoding of the source String" do
+ "abc".dup.force_encoding(Encoding::EUC_JP) =~ /b/
+ $'.encoding.should.equal?(Encoding::EUC_JP)
+ end
- it "sets an empty result to the encoding of the source String" do
- "abc".force_encoding(Encoding::ISO_8859_1) =~ /c/
- $'.encoding.should equal(Encoding::ISO_8859_1)
- end
+ it "sets an empty result to the encoding of the source String" do
+ "abc".dup.force_encoding(Encoding::ISO_8859_1) =~ /c/
+ $'.encoding.should.equal?(Encoding::ISO_8859_1)
+ end
+
+ it "is read-only" do
+ -> {
+ eval %q{$' = ""}
+ }.should.raise(SyntaxError, /Can't set variable \$'/)
+ end
+
+ it "is read-only when aliased" do
+ alias $predefined_spec_single_quote $'
+ -> {
+ $predefined_spec_single_quote = ""
+ }.should.raise(NameError, '$predefined_spec_single_quote is a read-only variable')
end
end
@@ -196,11 +226,22 @@ describe "Predefined global $+" do
$+.should == 'a'
end
- with_feature :encoding do
- it "sets the encoding to the encoding of the source String" do
- "abc".force_encoding(Encoding::EUC_JP) =~ /(b)/
- $+.encoding.should equal(Encoding::EUC_JP)
- end
+ it "sets the encoding to the encoding of the source String" do
+ "abc".dup.force_encoding(Encoding::EUC_JP) =~ /(b)/
+ $+.encoding.should.equal?(Encoding::EUC_JP)
+ end
+
+ it "is read-only" do
+ -> {
+ eval %q{$+ = ""}
+ }.should.raise(SyntaxError, /Can't set variable \$\+/)
+ end
+
+ it "is read-only when aliased" do
+ alias $predefined_spec_plus $+
+ -> {
+ $predefined_spec_plus = ""
+ }.should.raise(NameError, '$predefined_spec_plus is a read-only variable')
end
end
@@ -225,11 +266,9 @@ describe "Predefined globals $1..N" do
test("-").should == nil
end
- with_feature :encoding do
- it "sets the encoding to the encoding of the source String" do
- "abc".force_encoding(Encoding::EUC_JP) =~ /(b)/
- $1.encoding.should equal(Encoding::EUC_JP)
- end
+ it "sets the encoding to the encoding of the source String" do
+ "abc".dup.force_encoding(Encoding::EUC_JP) =~ /(b)/
+ $1.encoding.should.equal?(Encoding::EUC_JP)
end
end
@@ -243,20 +282,36 @@ describe "Predefined global $stdout" do
end
it "raises TypeError error if assigned to nil" do
- lambda { $stdout = nil }.should raise_error(TypeError)
+ -> { $stdout = nil }.should.raise(TypeError, '$stdout must have write method, NilClass given')
end
it "raises TypeError error if assigned to object that doesn't respond to #write" do
obj = mock('object')
- lambda { $stdout = obj }.should raise_error(TypeError)
+ -> { $stdout = obj }.should.raise(TypeError)
obj.stub!(:write)
$stdout = obj
- $stdout.should equal(obj)
+ $stdout.should.equal?(obj)
end
end
describe "Predefined global $!" do
+ it "is Fiber-local" do
+ Fiber.new do
+ raise "hi"
+ rescue
+ Fiber.yield
+ end.resume
+
+ $!.should == nil
+ end
+
+ it "is read-only" do
+ -> {
+ $! = []
+ }.should.raise(NameError, '$! is a read-only variable')
+ end
+
# See http://jira.codehaus.org/browse/JRUBY-5550
it "remains nil after a failed core class \"checked\" coercion against a class that defines method_missing" do
$!.should == nil
@@ -408,6 +463,22 @@ describe "Predefined global $!" do
$!.should == nil
end
+ it "should be cleared when an exception is rescued even when a non-local return from block" do
+ def foo
+ [ 1 ].each do
+ begin
+ raise StandardError.new('err')
+ rescue => e
+ $!.should == e
+ return
+ end
+ end
+ end
+
+ foo
+ $!.should == nil
+ end
+
it "should not be cleared when an exception is not rescued" do
e = StandardError.new
begin
@@ -500,44 +571,112 @@ describe "Predefined global $!" do
end
end
-=begin
-Input/Output Variables
----------------------------------------------------------------------------------------------------
-
-$/ String The input record separator (newline by default). This is the value that rou-
- tines such as Kernel#gets use to determine record boundaries. If set to
- nil, gets will read the entire file.
-$-0 String Synonym for $/.
-$\ String The string appended to the output of every call to methods such as
- Kernel#print and IO#write. The default value is nil.
-$, String The separator string output between the parameters to methods such as
- Kernel#print and Array#join. Defaults to nil, which adds no text.
-$. Fixnum The number of the last line read from the current input file.
-$; String The default separator pattern used by String#split. May be set from the
- command line using the -F flag.
-$< Object An object that provides access to the concatenation of the contents of all
- the files given as command-line arguments or $stdin (in the case where
- there are no arguments). $< supports methods similar to a File object:
- binmode, close, closed?, each, each_byte, each_line, eof, eof?,
- file, filename, fileno, getc, gets, lineno, lineno=, path, pos, pos=,
- read, readchar, readline, readlines, rewind, seek, skip, tell, to_a,
- to_i, to_io, to_s, along with the methods in Enumerable. The method
- file returns a File object for the file currently being read. This may change
- as $< reads through the files on the command line. [r/o]
-$> IO The destination of output for Kernel#print and Kernel#printf. The
- default value is $stdout.
-$_ String The last line read by Kernel#gets or Kernel#readline. Many string-
- related functions in the Kernel module operate on $_ by default. The vari-
- able is local to the current scope. [thread]
-$-F String Synonym for $;.
-$stderr IO The current standard error output.
-$stdin IO The current standard input.
-$stdout IO The current standard output. Assignment to $stdout is deprecated: use
- $stdout.reopen instead.
-=end
+describe "Predefined global $@" do
+ it "is Fiber-local" do
+ Fiber.new do
+ raise "hi"
+ rescue
+ Fiber.yield
+ end.resume
+
+ $@.should == nil
+ end
+
+ it "is set to a backtrace of a rescued exception" do
+ begin
+ raise
+ rescue
+ $@.should.instance_of?(Array)
+ $@.should == $!.backtrace
+ end
+ end
+
+ it "is cleared when an exception is rescued" do
+ begin
+ raise
+ rescue
+ end
+
+ $@.should == nil
+ end
+
+ it "is not set when there is no current exception" do
+ $@.should == nil
+ end
+
+ it "is set to a backtrace of a rescued exception" do
+ begin
+ raise
+ rescue
+ $@.should.instance_of?(Array)
+ $@.should == $!.backtrace
+ end
+ end
+
+ it "is not read-only" do
+ begin
+ raise
+ rescue
+ $@ = []
+ $@.should == []
+ end
+ end
+
+ it_behaves_like :exception_set_backtrace, -> backtrace {
+ exception = nil
+ begin
+ raise
+ rescue
+ $@ = backtrace
+ exception = $!
+ end
+ exception
+ }
+
+ it "cannot be assigned when there is no a rescued exception" do
+ -> {
+ $@ = []
+ }.should.raise(ArgumentError, '$! not set')
+ end
+end
+
+# Input/Output Variables
+# ---------------------------------------------------------------------------------------------------
+#
+# $/ String The input record separator (newline by default). This is the value that rou-
+# tines such as Kernel#gets use to determine record boundaries. If set to
+# nil, gets will read the entire file.
+# $-0 String Synonym for $/.
+# $\ String The string appended to the output of every call to methods such as
+# Kernel#print and IO#write. The default value is nil.
+# $, String The separator string output between the parameters to methods such as
+# Kernel#print and Array#join. Defaults to nil, which adds no text.
+# $. Integer The number of the last line read from the current input file.
+# $; String The default separator pattern used by String#split. May be set from the
+# command line using the -F flag.
+# $< Object An object that provides access to the concatenation of the contents of all
+# the files given as command-line arguments or $stdin (in the case where
+# there are no arguments). $< supports methods similar to a File object:
+# binmode, close, closed?, each, each_byte, each_line, eof, eof?,
+# file, filename, fileno, getc, gets, lineno, lineno=, path, pos, pos=,
+# read, readchar, readline, readlines, rewind, seek, skip, tell, to_a,
+# to_i, to_io, to_s, along with the methods in Enumerable. The method
+# file returns a File object for the file currently being read. This may change
+# as $< reads through the files on the command line. [r/o]
+# $> IO The destination of output for Kernel#print and Kernel#printf. The
+# default value is $stdout.
+# $_ String The last line read by Kernel#gets or Kernel#readline. Many string-
+# related functions in the Kernel module operate on $_ by default. The vari-
+# able is local to the current scope. [thread]
+# $-F String Synonym for $;.
+# $stderr IO The current standard error output.
+# $stdin IO The current standard input.
+# $stdout IO The current standard output. Assignment to $stdout is deprecated: use
+# $stdout.reopen instead.
describe "Predefined global $/" do
before :each do
+ @verbose, $VERBOSE = $VERBOSE, nil
@dollar_slash = $/
@dollar_dash_zero = $-0
end
@@ -545,47 +684,80 @@ describe "Predefined global $/" do
after :each do
$/ = @dollar_slash
$-0 = @dollar_dash_zero
+ $VERBOSE = @verbose
end
- it "can be assigned a String" do
- str = "abc"
- $/ = str
- $/.should equal(str)
+ ruby_version_is ""..."4.0" do
+ it "can be assigned a String" do
+ str = +"abc"
+ $/ = str
+ $/.should.equal?(str)
+ end
+ end
+
+ ruby_version_is "4.0" do
+ it "makes a new frozen String from the assigned String" do
+ string_subclass = Class.new(String)
+ str = string_subclass.new("abc")
+ str.instance_variable_set(:@ivar, 1)
+ $/ = str
+ $/.should.frozen?
+ $/.should.instance_of?(String)
+ $/.should_not.instance_variable_defined?(:@ivar)
+ $/.should == str
+ end
+
+ it "makes a new frozen String if it's not frozen" do
+ str = +"abc"
+ $/ = str
+ $/.should.frozen?
+ $/.should == str
+ end
+
+ it "assigns the given String if it's frozen and has no instance variables" do
+ str = "abc".freeze
+ $/ = str
+ $/.should.equal?(str)
+ end
end
it "can be assigned nil" do
$/ = nil
- $/.should be_nil
+ $/.should == nil
end
it "returns the value assigned" do
($/ = "xyz").should == "xyz"
end
-
it "changes $-0" do
$/ = "xyz"
- $-0.should equal($/)
+ $-0.should.equal?($/)
end
it "does not call #to_str to convert the object to a String" do
obj = mock("$/ value")
obj.should_not_receive(:to_str)
- lambda { $/ = obj }.should raise_error(TypeError)
+ -> { $/ = obj }.should.raise(TypeError, 'value of $/ must be String')
end
- it "raises a TypeError if assigned a Fixnum" do
- lambda { $/ = 1 }.should raise_error(TypeError)
+ it "raises a TypeError if assigned an Integer" do
+ -> { $/ = 1 }.should.raise(TypeError, 'value of $/ must be String')
end
it "raises a TypeError if assigned a boolean" do
- lambda { $/ = true }.should raise_error(TypeError)
+ -> { $/ = true }.should.raise(TypeError, 'value of $/ must be String')
+ end
+
+ it "warns if assigned non-nil" do
+ -> { $/ = "_" }.should complain(/warning: (?:non-nil )?[`']\$\/' is deprecated/)
end
end
describe "Predefined global $-0" do
before :each do
+ @verbose, $VERBOSE = $VERBOSE, nil
@dollar_slash = $/
@dollar_dash_zero = $-0
end
@@ -593,17 +765,46 @@ describe "Predefined global $-0" do
after :each do
$/ = @dollar_slash
$-0 = @dollar_dash_zero
+ $VERBOSE = @verbose
end
- it "can be assigned a String" do
- str = "abc"
- $-0 = str
- $-0.should equal(str)
+ ruby_version_is ""..."4.0" do
+ it "can be assigned a String" do
+ str = +"abc"
+ $-0 = str
+ $-0.should.equal?(str)
+ end
+ end
+
+ ruby_version_is "4.0" do
+ it "makes a new frozen String from the assigned String" do
+ string_subclass = Class.new(String)
+ str = string_subclass.new("abc")
+ str.instance_variable_set(:@ivar, 1)
+ $-0 = str
+ $-0.should.frozen?
+ $-0.should.instance_of?(String)
+ $-0.should_not.instance_variable_defined?(:@ivar)
+ $-0.should == str
+ end
+
+ it "makes a new frozen String if it's not frozen" do
+ str = +"abc"
+ $-0 = str
+ $-0.should.frozen?
+ $-0.should == str
+ end
+
+ it "assigns the given String if it's frozen and has no instance variables" do
+ str = "abc".freeze
+ $-0 = str
+ $-0.should.equal?(str)
+ end
end
it "can be assigned nil" do
$-0 = nil
- $-0.should be_nil
+ $-0.should == nil
end
it "returns the value assigned" do
@@ -612,22 +813,69 @@ describe "Predefined global $-0" do
it "changes $/" do
$-0 = "xyz"
- $/.should equal($-0)
+ $/.should.equal?($-0)
end
it "does not call #to_str to convert the object to a String" do
obj = mock("$-0 value")
obj.should_not_receive(:to_str)
- lambda { $-0 = obj }.should raise_error(TypeError)
+ -> { $-0 = obj }.should.raise(TypeError, 'value of $-0 must be String')
end
- it "raises a TypeError if assigned a Fixnum" do
- lambda { $-0 = 1 }.should raise_error(TypeError)
+ it "raises a TypeError if assigned an Integer" do
+ -> { $-0 = 1 }.should.raise(TypeError, 'value of $-0 must be String')
end
it "raises a TypeError if assigned a boolean" do
- lambda { $-0 = true }.should raise_error(TypeError)
+ -> { $-0 = true }.should.raise(TypeError, 'value of $-0 must be String')
+ end
+
+ it "warns if assigned non-nil" do
+ -> { $-0 = "_" }.should complain(/warning: (?:non-nil )?[`']\$-0' is deprecated/)
+ end
+end
+
+describe "Predefined global $\\" do
+ before :each do
+ @verbose, $VERBOSE = $VERBOSE, nil
+ @dollar_backslash = $\
+ end
+
+ after :each do
+ $\ = @dollar_backslash
+ $VERBOSE = @verbose
+ end
+
+ it "can be assigned a String" do
+ str = "abc"
+ $\ = str
+ $\.should.equal?(str)
+ end
+
+ it "can be assigned nil" do
+ $\ = nil
+ $\.should == nil
+ end
+
+ it "returns the value assigned" do
+ ($\ = "xyz").should == "xyz"
+ end
+
+ it "does not call #to_str to convert the object to a String" do
+ obj = mock("$\\ value")
+ obj.should_not_receive(:to_str)
+
+ -> { $\ = obj }.should.raise(TypeError, 'value of $\ must be String')
+ end
+
+ it "raises a TypeError if assigned not String" do
+ -> { $\ = 1 }.should.raise(TypeError, 'value of $\ must be String')
+ -> { $\ = true }.should.raise(TypeError, 'value of $\ must be String')
+ end
+
+ it "warns if assigned non-nil" do
+ -> { $\ = "_" }.should complain(/warning: (?:non-nil )?[`']\$\\' is deprecated/)
end
end
@@ -637,11 +885,52 @@ describe "Predefined global $," do
end
it "defaults to nil" do
- $,.should be_nil
+ $,.should == nil
end
it "raises TypeError if assigned a non-String" do
- lambda { $, = Object.new }.should raise_error(TypeError)
+ -> { $, = Object.new }.should.raise(TypeError, 'value of $, must be String')
+ end
+
+ it "warns if assigned non-nil" do
+ -> { $, = "_" }.should complain(/warning: (?:non-nil )?[`']\$,' is deprecated/)
+ end
+end
+
+describe "Predefined global $." do
+ it "can be assigned an Integer" do
+ $. = 123
+ $..should == 123
+ end
+
+ it "can be assigned a Float" do
+ $. = 123.5
+ $..should == 123
+ end
+
+ it "should call #to_int to convert the object to an Integer" do
+ obj = mock("good-value")
+ obj.should_receive(:to_int).and_return(321)
+
+ $. = obj
+ $..should == 321
+ end
+
+ it "raises TypeError if object can't be converted to an Integer" do
+ obj = mock("bad-value")
+ obj.should_receive(:to_int).and_return('abc')
+
+ -> { $. = obj }.should.raise(TypeError)
+ end
+end
+
+describe "Predefined global $;" do
+ after :each do
+ $; = nil
+ end
+
+ it "warns if assigned non-nil" do
+ -> { $; = "_" }.should complain(/warning: (?:non-nil )?[`']\$;' is deprecated/)
end
end
@@ -675,7 +964,7 @@ describe "Predefined global $_" do
match.should == "bar\n"
$_.should == match
- eval 'match = stdin.gets'
+ match = stdin.gets
match.should == "baz\n"
$_.should == match
@@ -696,7 +985,7 @@ describe "Predefined global $_" do
end
Thread.pass until running
- $_.should be_nil
+ $_.should == nil
thr.join
end
@@ -714,56 +1003,52 @@ describe "Predefined global $_" do
end
end
-=begin
-Execution Environment Variables
----------------------------------------------------------------------------------------------------
-
-$0 String The name of the top-level Ruby program being executed. Typically this will
- be the program’s filename. On some operating systems, assigning to this
- variable will change the name of the process reported (for example) by the
- ps(1) command.
-$* Array An array of strings containing the command-line options from the invoca-
- tion of the program. Options used by the Ruby interpreter will have been
- removed. [r/o]
-$" Array An array containing the filenames of modules loaded by require. [r/o]
-$$ Fixnum The process number of the program being executed. [r/o]
-$? Process::Status The exit status of the last child process to terminate. [r/o, thread]
-$: Array An array of strings, where each string specifies a directory to be searched for
- Ruby scripts and binary extensions used by the load and require methods.
- The initial value is the value of the arguments passed via the -I command-
- line option, followed by an installation-defined standard library location, fol-
- lowed by the current directory (“.â€). This variable may be set from within a
- program to alter the default search path; typically, programs use $: << dir
- to append dir to the path. [r/o]
-$-a Object True if the -a option is specified on the command line. [r/o]
-$-d Object Synonym for $DEBUG.
-$DEBUG Object Set to true if the -d command-line option is specified.
-__FILE__ String The name of the current source file. [r/o]
-$F Array The array that receives the split input line if the -a command-line option is
- used.
-$FILENAME String The name of the current input file. Equivalent to $<.filename. [r/o]
-$-i String If in-place edit mode is enabled (perhaps using the -i command-line
- option), $-i holds the extension used when creating the backup file. If you
- set a value into $-i, enables in-place edit mode.
-$-I Array Synonym for $:. [r/o]
-$-K String Sets the multibyte coding system for strings and regular expressions. Equiv-
- alent to the -K command-line option.
-$-l Object Set to true if the -l option (which enables line-end processing) is present
- on the command line. [r/o]
-__LINE__ String The current line number in the source file. [r/o]
-$LOAD_PATH Array A synonym for $:. [r/o]
-$-p Object Set to true if the -p option (which puts an implicit while gets . . . end
- loop around your program) is present on the command line. [r/o]
-$SAFE Fixnum The current safe level. This variable’s value may never be
- reduced by assignment. [thread] (Not implemented in Rubinius)
-$VERBOSE Object Set to true if the -v, --version, -W, or -w option is specified on the com-
- mand line. Set to false if no option, or -W1 is given. Set to nil if -W0
- was specified. Setting this option to true causes the interpreter and some
- library routines to report additional information. Setting to nil suppresses
- all warnings (including the output of Kernel.warn).
-$-v Object Synonym for $VERBOSE.
-$-w Object Synonym for $VERBOSE.
-=end
+# Execution Environment Variables
+# ---------------------------------------------------------------------------------------------------
+#
+# $0 String The name of the top-level Ruby program being executed. Typically this will
+# be the program’s filename. On some operating systems, assigning to this
+# variable will change the name of the process reported (for example) by the
+# ps(1) command.
+# $* Array An array of strings containing the command-line options from the invoca-
+# tion of the program. Options used by the Ruby interpreter will have been
+# removed. [r/o]
+# $" Array An array containing the filenames of modules loaded by require. [r/o]
+# $$ Integer The process number of the program being executed. [r/o]
+# $? Process::Status The exit status of the last child process to terminate. [r/o, thread]
+# $: Array An array of strings, where each string specifies a directory to be searched for
+# Ruby scripts and binary extensions used by the load and require methods.
+# The initial value is the value of the arguments passed via the -I command-
+# line option, followed by an installation-defined standard library location, fol-
+# lowed by the current directory (“.â€). This variable may be set from within a
+# program to alter the default search path; typically, programs use $: << dir
+# to append dir to the path. [r/o]
+# $-a Object True if the -a option is specified on the command line. [r/o]
+# $-d Object Synonym for $DEBUG.
+# $DEBUG Object Set to true if the -d command-line option is specified.
+# __FILE__ String The name of the current source file. [r/o]
+# $F Array The array that receives the split input line if the -a command-line option is
+# used.
+# $FILENAME String The name of the current input file. Equivalent to $<.filename. [r/o]
+# $-i String If in-place edit mode is enabled (perhaps using the -i command-line
+# option), $-i holds the extension used when creating the backup file. If you
+# set a value into $-i, enables in-place edit mode.
+# $-I Array Synonym for $:. [r/o]
+# $-K String Sets the multibyte coding system for strings and regular expressions. Equiv-
+# alent to the -K command-line option.
+# $-l Object Set to true if the -l option (which enables line-end processing) is present
+# on the command line. [r/o]
+# __LINE__ String The current line number in the source file. [r/o]
+# $LOAD_PATH Array A synonym for $:. [r/o]
+# $-p Object Set to true if the -p option (which puts an implicit while gets . . . end
+# loop around your program) is present on the command line. [r/o]
+# $VERBOSE Object Set to true if the -v, --version, -W, or -w option is specified on the com-
+# mand line. Set to false if no option, or -W1 is given. Set to nil if -W0
+# was specified. Setting this option to true causes the interpreter and some
+# library routines to report additional information. Setting to nil suppresses
+# all warnings (including the output of Kernel.warn).
+# $-v Object Synonym for $VERBOSE.
+# $-w Object Synonym for $VERBOSE.
describe "Execution variable $:" do
it "is initialized to an array of strings" do
$:.is_a?(Array).should == true
@@ -771,7 +1056,7 @@ describe "Execution variable $:" do
end
it "does not include the current directory" do
- $:.should_not include(".")
+ $:.should_not.include?(".")
end
it "is the same object as $LOAD_PATH and $-I" do
@@ -781,84 +1066,102 @@ describe "Execution variable $:" do
it "can be changed via <<" do
$: << "foo"
- $:.should include("foo")
+ $:.should.include?("foo")
+ ensure
+ $:.delete("foo")
end
it "is read-only" do
- lambda {
+ -> {
$: = []
- }.should raise_error(NameError)
+ }.should.raise(NameError, '$: is a read-only variable')
- lambda {
+ -> {
$LOAD_PATH = []
- }.should raise_error(NameError)
+ }.should.raise(NameError, '$LOAD_PATH is a read-only variable')
- lambda {
+ -> {
$-I = []
- }.should raise_error(NameError)
+ }.should.raise(NameError, '$-I is a read-only variable')
+ end
+
+ it "default $LOAD_PATH entries until sitelibdir included have @gem_prelude_index set" do
+ skip "no sense in ruby itself" if MSpecScript.instance_variable_defined?(:@testing_ruby)
+
+ if platform_is :windows
+ # See https://github.com/ruby/setup-ruby/pull/762#issuecomment-2917460440
+ $:.should.find { |e| File.realdirpath(e) == RbConfig::CONFIG['sitelibdir'] }
+ idx = $:.index { |e| File.realdirpath(e) == RbConfig::CONFIG['sitelibdir'] }
+ else
+ $:.should.include?(RbConfig::CONFIG['sitelibdir'])
+ idx = $:.index(RbConfig::CONFIG['sitelibdir'])
+ end
+
+ $:[idx..-1].all? { |p| p.instance_variable_defined?(:@gem_prelude_index) }.should == true
+ $:[0...idx].all? { |p| !p.instance_variable_defined?(:@gem_prelude_index) }.should == true
end
end
describe "Global variable $\"" do
- it "is an alias for $LOADED_FEATURES" do
- $".object_id.should == $LOADED_FEATURES.object_id
+ it "is an alias of $LOADED_FEATURES" do
+ $".should.equal? $LOADED_FEATURES
end
it "is read-only" do
- lambda {
+ -> {
$" = []
- }.should raise_error(NameError)
+ }.should.raise(NameError, '$" is a read-only variable')
- lambda {
+ -> {
$LOADED_FEATURES = []
- }.should raise_error(NameError)
+ }.should.raise(NameError, '$LOADED_FEATURES is a read-only variable')
end
end
describe "Global variable $<" do
it "is read-only" do
- lambda {
+ -> {
$< = nil
- }.should raise_error(NameError)
+ }.should.raise(NameError, '$< is a read-only variable')
end
end
describe "Global variable $FILENAME" do
it "is read-only" do
- lambda {
+ -> {
$FILENAME = "-"
- }.should raise_error(NameError)
+ }.should.raise(NameError, '$FILENAME is a read-only variable')
end
end
describe "Global variable $?" do
it "is read-only" do
- lambda {
+ -> {
$? = nil
- }.should raise_error(NameError)
+ }.should.raise(NameError, '$? is a read-only variable')
end
it "is thread-local" do
system(ruby_cmd('exit 0'))
- Thread.new { $?.should be_nil }.join
+ Thread.new { $?.should == nil }.join
end
end
describe "Global variable $-a" do
it "is read-only" do
- lambda { $-a = true }.should raise_error(NameError)
+ -> { $-a = true }.should.raise(NameError, '$-a is a read-only variable')
end
end
describe "Global variable $-l" do
it "is read-only" do
- lambda { $-l = true }.should raise_error(NameError)
+ -> { $-l = true }.should.raise(NameError, '$-l is a read-only variable')
end
end
describe "Global variable $-p" do
it "is read-only" do
- lambda { $-p = true }.should raise_error(NameError)
+ -> { $-p = true }.should.raise(NameError, '$-p is a read-only variable')
end
end
@@ -873,28 +1176,40 @@ describe "Global variable $-d" do
it "is an alias of $DEBUG" do
$DEBUG = true
- $-d.should be_true
+ $-d.should == true
$-d = false
- $DEBUG.should be_false
+ $DEBUG.should == false
end
end
describe "Global variable $VERBOSE" do
+ before :each do
+ @verbose = $VERBOSE
+ end
+
+ after :each do
+ $VERBOSE = @verbose
+ end
+
+ it "is false by default" do
+ $VERBOSE.should == false
+ end
+
it "converts truthy values to true" do
[true, 1, 0, [], ""].each do |true_value|
$VERBOSE = true_value
- $VERBOSE.should be_true
+ $VERBOSE.should == true
end
end
it "allows false" do
$VERBOSE = false
- $VERBOSE.should be_false
+ $VERBOSE.should == false
end
it "allows nil without coercing to false" do
$VERBOSE = nil
- $VERBOSE.should be_nil
+ $VERBOSE.should == nil
end
end
@@ -909,9 +1224,9 @@ describe :verbose_global_alias, shared: true do
it "is an alias of $VERBOSE" do
$VERBOSE = true
- eval(@method).should be_true
+ eval(@method).should == true
eval("#{@method} = false")
- $VERBOSE.should be_false
+ $VERBOSE.should == false
end
end
@@ -934,7 +1249,7 @@ describe "Global variable $0" do
it "is the path given as the main script and the same as __FILE__" do
script = "fixtures/dollar_zero.rb"
- Dir.chdir(File.dirname(__FILE__)) do
+ Dir.chdir(__dir__) do
ruby_exe(script).should == "#{script}\n#{script}\nOK"
end
end
@@ -948,7 +1263,7 @@ describe "Global variable $0" do
it "actually sets the program name" do
title = "rubyspec-dollar0-test"
$0 = title
- `ps -ocommand= -p#{$$}`.should include(title)
+ `ps -ocommand= -p#{$$}`.should.include?(title)
end
end
@@ -957,26 +1272,24 @@ describe "Global variable $0" do
end
it "raises a TypeError when not given an object that can be coerced to a String" do
- lambda { $0 = nil }.should raise_error(TypeError)
+ -> { $0 = nil }.should.raise(TypeError)
end
end
-=begin
-Standard Objects
----------------------------------------------------------------------------------------------------
-
-ARGF Object A synonym for $<.
-ARGV Array A synonym for $*.
-ENV Object A hash-like object containing the program’s environment variables. An
- instance of class Object, ENV implements the full set of Hash methods. Used
- to query and set the value of an environment variable, as in ENV["PATH"]
- and ENV["term"]="ansi".
-false FalseClass Singleton instance of class FalseClass. [r/o]
-nil NilClass The singleton instance of class NilClass. The value of uninitialized
- instance and global variables. [r/o]
-self Object The receiver (object) of the current method. [r/o]
-true TrueClass Singleton instance of class TrueClass. [r/o]
-=end
+# Standard Objects
+# ---------------------------------------------------------------------------------------------------
+#
+# ARGF Object A synonym for $<.
+# ARGV Array A synonym for $*.
+# ENV Object A hash-like object containing the program’s environment variables. An
+# instance of class Object, ENV implements the full set of Hash methods. Used
+# to query and set the value of an environment variable, as in ENV["PATH"]
+# and ENV["term"]="ansi".
+# false FalseClass Singleton instance of class FalseClass. [r/o]
+# nil NilClass The singleton instance of class NilClass. The value of uninitialized
+# instance and global variables. [r/o]
+# self Object The receiver (object) of the current method. [r/o]
+# true TrueClass Singleton instance of class TrueClass. [r/o]
describe "The predefined standard objects" do
it "includes ARGF" do
@@ -995,109 +1308,85 @@ end
describe "The predefined standard object nil" do
it "is an instance of NilClass" do
- nil.should be_kind_of(NilClass)
+ nil.should.is_a?(NilClass)
end
it "raises a SyntaxError if assigned to" do
- lambda { eval("nil = true") }.should raise_error(SyntaxError)
+ -> { eval("nil = true") }.should.raise(SyntaxError, /Can't assign to nil/)
end
end
describe "The predefined standard object true" do
it "is an instance of TrueClass" do
- true.should be_kind_of(TrueClass)
+ true.should.is_a?(TrueClass)
end
it "raises a SyntaxError if assigned to" do
- lambda { eval("true = false") }.should raise_error(SyntaxError)
+ -> { eval("true = false") }.should.raise(SyntaxError, /Can't assign to true/)
end
end
describe "The predefined standard object false" do
it "is an instance of FalseClass" do
- false.should be_kind_of(FalseClass)
+ false.should.is_a?(FalseClass)
end
it "raises a SyntaxError if assigned to" do
- lambda { eval("false = nil") }.should raise_error(SyntaxError)
+ -> { eval("false = nil") }.should.raise(SyntaxError, /Can't assign to false/)
end
end
describe "The self pseudo-variable" do
it "raises a SyntaxError if assigned to" do
- lambda { eval("self = 1") }.should raise_error(SyntaxError)
+ -> { eval("self = 1") }.should.raise(SyntaxError, /Can't change the value of self/)
end
end
-=begin
-Global Constants
----------------------------------------------------------------------------------------------------
-
-The following constants are defined by the Ruby interpreter.
-
-DATA IO If the main program file contains the directive __END__, then
- the constant DATA will be initialized so that reading from it will
- return lines following __END__ from the source file.
-FALSE FalseClass Synonym for false.
-NIL NilClass Synonym for nil.
-RUBY_PLATFORM String The identifier of the platform running this program. This string
- is in the same form as the platform identifier used by the GNU
- configure utility (which is not a coincidence).
-RUBY_RELEASE_DATE String The date of this release.
-RUBY_VERSION String The version number of the interpreter.
-STDERR IO The actual standard error stream for the program. The initial
- value of $stderr.
-STDIN IO The actual standard input stream for the program. The initial
- value of $stdin.
-STDOUT IO The actual standard output stream for the program. The initial
- value of $stdout.
-SCRIPT_LINES__ Hash If a constant SCRIPT_LINES__ is defined and references a Hash,
- Ruby will store an entry containing the contents of each file it
- parses, with the file’s name as the key and an array of strings as
- the value.
-TOPLEVEL_BINDING Binding A Binding object representing the binding at Ruby’s top level—
- the level where programs are initially executed.
-TRUE TrueClass Synonym for true.
-=end
+# Global Constants
+# ---------------------------------------------------------------------------------------------------
+#
+# The following constants are defined by the Ruby interpreter.
+#
+# DATA IO If the main program file contains the directive __END__, then
+# the constant DATA will be initialized so that reading from it will
+# return lines following __END__ from the source file.
+# FALSE FalseClass Synonym for false (deprecated, removed in Ruby 3).
+# NIL NilClass Synonym for nil (deprecated, removed in Ruby 3).
+# RUBY_PLATFORM String The identifier of the platform running this program. This string
+# is in the same form as the platform identifier used by the GNU
+# configure utility (which is not a coincidence).
+# RUBY_RELEASE_DATE String The date of this release.
+# RUBY_VERSION String The version number of the interpreter.
+# STDERR IO The actual standard error stream for the program. The initial
+# value of $stderr.
+# STDIN IO The actual standard input stream for the program. The initial
+# value of $stdin.
+# STDOUT IO The actual standard output stream for the program. The initial
+# value of $stdout.
+# SCRIPT_LINES__ Hash If a constant SCRIPT_LINES__ is defined and references a Hash,
+# Ruby will store an entry containing the contents of each file it
+# parses, with the file’s name as the key and an array of strings as
+# the value.
+# TOPLEVEL_BINDING Binding A Binding object representing the binding at Ruby’s top level—
+# the level where programs are initially executed.
+# TRUE TrueClass Synonym for true (deprecated, removed in Ruby 3).
describe "The predefined global constants" do
- ruby_version_is ""..."2.4" do
- it "includes TRUE" do
- Object.const_defined?(:TRUE).should == true
- TRUE.should equal(true)
- end
-
- it "includes FALSE" do
- Object.const_defined?(:FALSE).should == true
- FALSE.should equal(false)
- end
-
- it "includes NIL" do
- Object.const_defined?(:NIL).should == true
- NIL.should equal(nil)
+ describe "TRUE" do
+ it "is no longer defined" do
+ Object.const_defined?(:TRUE).should == false
end
end
- ruby_version_is "2.4" do
- it "includes TRUE" do
- Object.const_defined?(:TRUE).should == true
- -> {
- TRUE.should equal(true)
- }.should complain(/constant ::TRUE is deprecated/)
- end
-
- it "includes FALSE" do
- Object.const_defined?(:FALSE).should == true
- -> {
- FALSE.should equal(false)
- }.should complain(/constant ::FALSE is deprecated/)
+ describe "FALSE" do
+ it "is no longer defined" do
+ Object.const_defined?(:FALSE).should == false
end
+ end
- it "includes NIL" do
- Object.const_defined?(:NIL).should == true
- -> {
- NIL.should equal(nil)
- }.should complain(/constant ::NIL is deprecated/)
+ describe "NIL" do
+ it "is no longer defined" do
+ Object.const_defined?(:NIL).should == false
end
end
@@ -1128,113 +1417,159 @@ describe "The predefined global constants" do
it "includes TOPLEVEL_BINDING" do
Object.const_defined?(:TOPLEVEL_BINDING).should == true
end
-
end
-with_feature :encoding do
- describe "The predefined global constant" do
- before :each do
- @external = Encoding.default_external
- @internal = Encoding.default_internal
- end
+describe "The predefined global constant" do
+ before :each do
+ @external = Encoding.default_external
+ @internal = Encoding.default_internal
+ end
- after :each do
- Encoding.default_external = @external
- Encoding.default_internal = @internal
- end
+ after :each do
+ Encoding.default_external = @external
+ Encoding.default_internal = @internal
+ end
- describe "STDIN" do
+ describe "STDIN" do
+ platform_is_not :windows do
it "has the same external encoding as Encoding.default_external" do
- STDIN.external_encoding.should equal(Encoding.default_external)
+ STDIN.external_encoding.should.equal?(Encoding.default_external)
end
it "has the same external encoding as Encoding.default_external when that encoding is changed" do
Encoding.default_external = Encoding::ISO_8859_16
- STDIN.external_encoding.should equal(Encoding::ISO_8859_16)
- end
-
- it "has the encodings set by #set_encoding" do
- code = "STDIN.set_encoding Encoding::IBM775, Encoding::IBM866; " \
- "p [STDIN.external_encoding.name, STDIN.internal_encoding.name]"
- ruby_exe(code).chomp.should == %{["IBM775", "IBM866"]}
- end
-
- it "retains the encoding set by #set_encoding when Encoding.default_external is changed" do
- code = "STDIN.set_encoding Encoding::IBM775, Encoding::IBM866; " \
- "Encoding.default_external = Encoding::ISO_8859_16;" \
- "p [STDIN.external_encoding.name, STDIN.internal_encoding.name]"
- ruby_exe(code).chomp.should == %{["IBM775", "IBM866"]}
+ STDIN.external_encoding.should.equal?(Encoding::ISO_8859_16)
end
it "has nil for the internal encoding" do
- STDIN.internal_encoding.should be_nil
+ STDIN.internal_encoding.should == nil
end
it "has nil for the internal encoding despite Encoding.default_internal being changed" do
Encoding.default_internal = Encoding::IBM437
- STDIN.internal_encoding.should be_nil
+ STDIN.internal_encoding.should == nil
end
end
- describe "STDOUT" do
- it "has nil for the external encoding" do
- STDOUT.external_encoding.should be_nil
- end
+ it "has the encodings set by #set_encoding" do
+ code = "STDIN.set_encoding Encoding::IBM775, Encoding::IBM866; " \
+ "p [STDIN.external_encoding.name, STDIN.internal_encoding.name]"
+ ruby_exe(code).chomp.should == %{["IBM775", "IBM866"]}
+ end
- it "has nil for the external encoding despite Encoding.default_external being changed" do
- Encoding.default_external = Encoding::ISO_8859_1
- STDOUT.external_encoding.should be_nil
- end
+ it "retains the encoding set by #set_encoding when Encoding.default_external is changed" do
+ code = "STDIN.set_encoding Encoding::IBM775, Encoding::IBM866; " \
+ "Encoding.default_external = Encoding::ISO_8859_16;" \
+ "p [STDIN.external_encoding.name, STDIN.internal_encoding.name]"
+ ruby_exe(code).chomp.should == %{["IBM775", "IBM866"]}
+ end
+ end
- it "has the encodings set by #set_encoding" do
- code = "STDOUT.set_encoding Encoding::IBM775, Encoding::IBM866; " \
- "p [STDOUT.external_encoding.name, STDOUT.internal_encoding.name]"
- ruby_exe(code).chomp.should == %{["IBM775", "IBM866"]}
- end
+ describe "STDOUT" do
+ it "has nil for the external encoding" do
+ STDOUT.external_encoding.should == nil
+ end
- it "has nil for the internal encoding" do
- STDOUT.internal_encoding.should be_nil
- end
+ it "has nil for the external encoding despite Encoding.default_external being changed" do
+ Encoding.default_external = Encoding::ISO_8859_1
+ STDOUT.external_encoding.should == nil
+ end
- it "has nil for the internal encoding despite Encoding.default_internal being changed" do
- Encoding.default_internal = Encoding::IBM437
- STDOUT.internal_encoding.should be_nil
- end
+ it "has the encodings set by #set_encoding" do
+ code = "STDOUT.set_encoding Encoding::IBM775, Encoding::IBM866; " \
+ "p [STDOUT.external_encoding.name, STDOUT.internal_encoding.name]"
+ ruby_exe(code).chomp.should == %{["IBM775", "IBM866"]}
end
- describe "STDERR" do
- it "has nil for the external encoding" do
- STDERR.external_encoding.should be_nil
- end
+ it "has nil for the internal encoding" do
+ STDOUT.internal_encoding.should == nil
+ end
- it "has nil for the external encoding despite Encoding.default_external being changed" do
- Encoding.default_external = Encoding::ISO_8859_1
- STDERR.external_encoding.should be_nil
- end
+ it "has nil for the internal encoding despite Encoding.default_internal being changed" do
+ Encoding.default_internal = Encoding::IBM437
+ STDOUT.internal_encoding.should == nil
+ end
+ end
- it "has the encodings set by #set_encoding" do
- code = "STDERR.set_encoding Encoding::IBM775, Encoding::IBM866; " \
- "p [STDERR.external_encoding.name, STDERR.internal_encoding.name]"
- ruby_exe(code).chomp.should == %{["IBM775", "IBM866"]}
- end
+ describe "STDERR" do
+ it "has nil for the external encoding" do
+ STDERR.external_encoding.should == nil
+ end
- it "has nil for the internal encoding" do
- STDERR.internal_encoding.should be_nil
- end
+ it "has nil for the external encoding despite Encoding.default_external being changed" do
+ Encoding.default_external = Encoding::ISO_8859_1
+ STDERR.external_encoding.should == nil
+ end
- it "has nil for the internal encoding despite Encoding.default_internal being changed" do
- Encoding.default_internal = Encoding::IBM437
- STDERR.internal_encoding.should be_nil
- end
+ it "has the encodings set by #set_encoding" do
+ code = "STDERR.set_encoding Encoding::IBM775, Encoding::IBM866; " \
+ "p [STDERR.external_encoding.name, STDERR.internal_encoding.name]"
+ ruby_exe(code).chomp.should == %{["IBM775", "IBM866"]}
end
- describe "ARGV" do
- it "contains Strings encoded in locale Encoding" do
- code = fixture __FILE__, "argv_encoding.rb"
- result = ruby_exe(code, args: "a b")
- encoding = Encoding.default_external
- result.chomp.should == %{["#{encoding}", "#{encoding}"]}
- end
+ it "has nil for the internal encoding" do
+ STDERR.internal_encoding.should == nil
+ end
+
+ it "has nil for the internal encoding despite Encoding.default_internal being changed" do
+ Encoding.default_internal = Encoding::IBM437
+ STDERR.internal_encoding.should == nil
end
end
+
+ describe "ARGV" do
+ it "contains Strings encoded in locale Encoding" do
+ code = fixture __FILE__, "argv_encoding.rb"
+ result = ruby_exe(code, args: "a b")
+ encoding = Encoding.default_external
+ result.chomp.should == %{["#{encoding}", "#{encoding}"]}
+ end
+ end
+end
+
+describe "$LOAD_PATH.resolve_feature_path" do
+ it "returns what will be loaded without actual loading, .rb file" do
+ extension, path = $LOAD_PATH.resolve_feature_path('pp')
+ extension.should == :rb
+ path.should.end_with?('/pp.rb')
+ end
+
+ it "returns what will be loaded without actual loading, .so file" do
+ require 'rbconfig'
+ skip "no dynamically loadable standard extension" if RbConfig::CONFIG["EXTSTATIC"] == "static"
+
+ extension, path = $LOAD_PATH.resolve_feature_path('etc')
+ extension.should == :so
+ path.should.end_with?("/etc.#{RbConfig::CONFIG['DLEXT']}")
+ end
+
+ it "return nil if feature cannot be found" do
+ $LOAD_PATH.resolve_feature_path('noop').should == nil
+ end
+end
+
+# Some other pre-defined global variables
+
+describe "Predefined global $=" do
+ before :each do
+ @verbose, $VERBOSE = $VERBOSE, nil
+ @dollar_assign = $=
+ end
+
+ after :each do
+ $= = @dollar_assign
+ $VERBOSE = @verbose
+ end
+
+ it "warns when accessed" do
+ -> { a = $= }.should complain(/is no longer effective/)
+ end
+
+ it "warns when assigned" do
+ -> { $= = "_" }.should complain(/is no longer effective/)
+ end
+
+ it "returns the value assigned" do
+ ($= = "xyz").should == "xyz"
+ end
end
diff --git a/spec/ruby/language/private_spec.rb b/spec/ruby/language/private_spec.rb
index 796c0c1711..94b56fee5b 100644
--- a/spec/ruby/language/private_spec.rb
+++ b/spec/ruby/language/private_spec.rb
@@ -1,15 +1,15 @@
-require File.expand_path('../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/private', __FILE__)
+require_relative '../spec_helper'
+require_relative 'fixtures/private'
describe "The private keyword" do
it "marks following methods as being private" do
a = Private::A.new
- a.methods.should_not include(:bar)
- lambda { a.bar }.should raise_error(NoMethodError)
+ a.methods.should_not.include?(:bar)
+ -> { a.bar }.should.raise(NoMethodError)
b = Private::B.new
- b.methods.should_not include(:bar)
- lambda { b.bar }.should raise_error(NoMethodError)
+ b.methods.should_not.include?(:bar)
+ -> { b.bar }.should.raise(NoMethodError)
end
# def expr.meth() methods are always public
@@ -19,22 +19,22 @@ describe "The private keyword" do
it "is overridden when a new class is opened" do
c = Private::B::C.new
- c.methods.should include(:baz)
+ c.methods.should.include?(:baz)
c.baz
Private::B.public_class_method1.should == 1
- lambda { Private::B.private_class_method1 }.should raise_error(NoMethodError)
+ -> { Private::B.private_class_method1 }.should.raise(NoMethodError)
end
it "is no longer in effect when the class is closed" do
b = Private::B.new
- b.methods.should include(:foo)
+ b.methods.should.include?(:foo)
b.foo
end
it "changes visibility of previously called method" do
klass = Class.new do
def foo
- "foo"
+ "foo"
end
end
f = klass.new
@@ -42,12 +42,12 @@ describe "The private keyword" do
klass.class_eval do
private :foo
end
- lambda { f.foo }.should raise_error(NoMethodError)
+ -> { f.foo }.should.raise(NoMethodError)
end
- it "changes visiblity of previously called methods with same send/call site" do
+ it "changes visibility of previously called methods with same send/call site" do
g = ::Private::G.new
- lambda {
+ -> {
2.times do
g.foo
module ::Private
@@ -56,12 +56,12 @@ describe "The private keyword" do
end
end
end
- }.should raise_error(NoMethodError)
+ }.should.raise(NoMethodError)
end
it "changes the visibility of the existing method in the subclass" do
::Private::A.new.foo.should == 'foo'
- lambda {::Private::H.new.foo}.should raise_error(NoMethodError)
+ -> { ::Private::H.new.foo }.should.raise(NoMethodError)
::Private::H.new.send(:foo).should == 'foo'
end
end
diff --git a/spec/ruby/language/proc_spec.rb b/spec/ruby/language/proc_spec.rb
index bbef318826..53a21d6b85 100644
--- a/spec/ruby/language/proc_spec.rb
+++ b/spec/ruby/language/proc_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../spec_helper', __FILE__)
+require_relative '../spec_helper'
describe "A Proc" do
it "captures locals from the surrounding scope" do
@@ -21,8 +21,8 @@ describe "A Proc" do
@l.call.should == 1
end
- it "raises an ArgumentErro if a value is passed" do
- lambda { @l.call(0) }.should raise_error(ArgumentError)
+ it "raises an ArgumentError if a value is passed" do
+ lambda { @l.call(0) }.should.raise(ArgumentError)
end
end
@@ -36,7 +36,7 @@ describe "A Proc" do
end
it "raises an ArgumentError if a value is passed" do
- lambda { @l.call(0) }.should raise_error(ArgumentError)
+ lambda { @l.call(0) }.should.raise(ArgumentError)
end
end
@@ -57,11 +57,11 @@ describe "A Proc" do
obj = mock("block yield to_ary")
obj.should_not_receive(:to_ary)
- @l.call(obj).should equal(obj)
+ @l.call(obj).should.equal?(obj)
end
it "raises an ArgumentError if no value is passed" do
- lambda { @l.call }.should raise_error(ArgumentError)
+ lambda { @l.call }.should.raise(ArgumentError)
end
end
@@ -71,11 +71,11 @@ describe "A Proc" do
end
it "raises an ArgumentError if passed no values" do
- lambda { @l.call }.should raise_error(ArgumentError)
+ lambda { @l.call }.should.raise(ArgumentError)
end
it "raises an ArgumentError if passed one value" do
- lambda { @l.call(0) }.should raise_error(ArgumentError)
+ lambda { @l.call(0) }.should.raise(ArgumentError)
end
it "assigns the values passed to the arguments" do
@@ -86,7 +86,7 @@ describe "A Proc" do
obj = mock("proc call to_ary")
obj.should_not_receive(:to_ary)
- lambda { @l.call(obj) }.should raise_error(ArgumentError)
+ lambda { @l.call(obj) }.should.raise(ArgumentError)
end
end
@@ -96,7 +96,7 @@ describe "A Proc" do
end
it "raises an ArgumentError if passed no values" do
- lambda { @l.call }.should raise_error(ArgumentError)
+ lambda { @l.call }.should.raise(ArgumentError)
end
it "does not destructure a single Array value yielded" do
@@ -104,7 +104,7 @@ describe "A Proc" do
end
it "assigns all passed values after the first to the rest argument" do
- @l.call(1, 2, 3).should == [1, [2, 3]]
+ @l.call(1, 2, 3).should == [1, [2, 3]]
end
it "does not call #to_ary to convert a single passed object to an Array" do
@@ -161,17 +161,29 @@ describe "A Proc" do
end
end
+ describe "taking |*a, b| arguments" do
+ it "assigns [] to the argument when passed no values" do
+ proc { |*a, b| [a, b] }.call.should == [[], nil]
+ end
+ end
+
+ describe "taking |a, *b, c| arguments" do
+ it "assigns [] to the argument when passed no values" do
+ proc { |a, *b, c| [a, b, c] }.call.should == [nil, [], nil]
+ end
+ end
+
describe "taking |a, | arguments" do
before :each do
@l = lambda { |a, | a }
end
it "raises an ArgumentError when passed no values" do
- lambda { @l.call }.should raise_error(ArgumentError)
+ lambda { @l.call }.should.raise(ArgumentError)
end
it "raises an ArgumentError when passed more than one value" do
- lambda { @l.call(1, 2) }.should raise_error(ArgumentError)
+ lambda { @l.call(1, 2) }.should.raise(ArgumentError)
end
it "assigns the argument the value passed" do
@@ -196,7 +208,7 @@ describe "A Proc" do
end
it "raises an ArgumentError when passed no values" do
- lambda { @l.call }.should raise_error(ArgumentError)
+ lambda { @l.call }.should.raise(ArgumentError)
end
it "destructures a single Array value yielded" do
@@ -214,7 +226,42 @@ describe "A Proc" do
obj = mock("block yield to_ary invalid")
obj.should_receive(:to_ary).and_return(1)
- lambda { @l.call(obj) }.should raise_error(TypeError)
+ lambda { @l.call(obj) }.should.raise(TypeError)
+ end
+ end
+
+ describe "taking |*a, **kw| arguments" do
+ before :each do
+ @p = proc { |*a, **kw| [a, kw] }
+ end
+
+ it 'does not autosplat keyword arguments' do
+ @p.call([1, {a: 1}]).should == [[[1, {a: 1}]], {}]
+ end
+ end
+
+ describe "taking |required keyword arguments, **kw| arguments" do
+ it "raises ArgumentError for missing required argument" do
+ p = proc { |a:, **kw| [a, kw] }
+ -> { p.call() }.should.raise(ArgumentError)
end
end
+
+ evaluate <<-ruby do
+ @p = proc { |**nil| :ok }
+ ruby
+
+ @p.call().should == :ok
+ -> { @p.call(a: 1) }.should.raise(ArgumentError, 'no keywords accepted')
+ -> { @p.call(**{a: 1}) }.should.raise(ArgumentError, 'no keywords accepted')
+ -> { @p.call("a" => 1) }.should.raise(ArgumentError, 'no keywords accepted')
+ end
+
+ evaluate <<-ruby do
+ @p = proc { |a, **nil| a }
+ ruby
+
+ @p.call({a: 1}).should == {a: 1}
+ -> { @p.call(a: 1) }.should.raise(ArgumentError, 'no keywords accepted')
+ end
end
diff --git a/spec/ruby/language/range_spec.rb b/spec/ruby/language/range_spec.rb
new file mode 100644
index 0000000000..ccc9f55537
--- /dev/null
+++ b/spec/ruby/language/range_spec.rb
@@ -0,0 +1,30 @@
+require_relative '../spec_helper'
+require_relative 'fixtures/classes'
+
+describe "Literal Ranges" do
+ it "creates range object" do
+ (1..10).should == Range.new(1, 10)
+ end
+
+ it "creates range with excluded right boundary" do
+ (1...10).should == Range.new(1, 10, true)
+ end
+
+ it "creates a simple range as an object literal" do
+ ary = []
+ 2.times do
+ ary.push(1..3)
+ end
+ ary[0].should.equal?(ary[1])
+ end
+
+ it "creates endless ranges" do
+ (1..).should == Range.new(1, nil)
+ (1...).should == Range.new(1, nil, true)
+ end
+
+ it "creates beginless ranges" do
+ (..1).should == Range.new(nil, 1)
+ (...1).should == Range.new(nil, 1, true)
+ end
+end
diff --git a/spec/ruby/language/redo_spec.rb b/spec/ruby/language/redo_spec.rb
index 53fd30b4f2..9b14c5add1 100644
--- a/spec/ruby/language/redo_spec.rb
+++ b/spec/ruby/language/redo_spec.rb
@@ -1,9 +1,9 @@
-require File.expand_path('../../spec_helper', __FILE__)
+require_relative '../spec_helper'
describe "The redo statement" do
it "restarts block execution if used within block" do
a = []
- lambda {
+ -> {
a << 1
redo if a.size < 2
a << 2
@@ -58,9 +58,9 @@ describe "The redo statement" do
describe "in a method" do
it "is invalid and raises a SyntaxError" do
- lambda {
+ -> {
eval("def m; redo; end")
- }.should raise_error(SyntaxError)
+ }.should.raise(SyntaxError)
end
end
end
diff --git a/spec/ruby/language/regexp/anchors_spec.rb b/spec/ruby/language/regexp/anchors_spec.rb
index c6a620a221..8e597b65e8 100644
--- a/spec/ruby/language/regexp/anchors_spec.rb
+++ b/spec/ruby/language/regexp/anchors_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../fixtures/classes'
describe "Regexps with anchors" do
it "supports ^ (line start anchor)" do
@@ -7,8 +7,8 @@ describe "Regexps with anchors" do
/^foo/.match("foo").to_a.should == ["foo"]
/^bar/.match("foo\nbar").to_a.should == ["bar"]
# Basic non-matching
- /^foo/.match(" foo").should be_nil
- /foo^/.match("foo\n\n\n").should be_nil
+ /^foo/.match(" foo").should == nil
+ /foo^/.match("foo\n\n\n").should == nil
# A bit advanced
/^^^foo/.match("foo").to_a.should == ["foo"]
@@ -16,8 +16,8 @@ describe "Regexps with anchors" do
(/($^)($^)/ =~ "foo\n\n").should == "foo\n".size and $~.to_a.should == ["", "", ""]
# Different start of line chars
- /^bar/.match("foo\rbar").should be_nil
- /^bar/.match("foo\0bar").should be_nil
+ /^bar/.match("foo\rbar").should == nil
+ /^bar/.match("foo\0bar").should == nil
# Trivial
/^/.match("foo").to_a.should == [""]
@@ -29,7 +29,7 @@ describe "Regexps with anchors" do
end
it "does not match ^ after trailing \\n" do
- /^(?!\A)/.match("foo\n").should be_nil # There is no (empty) line after a trailing \n
+ /^(?!\A)/.match("foo\n").should == nil # There is no (empty) line after a trailing \n
end
it "supports $ (line end anchor)" do
@@ -37,16 +37,16 @@ describe "Regexps with anchors" do
/foo$/.match("foo").to_a.should == ["foo"]
/foo$/.match("foo\nbar").to_a.should == ["foo"]
# Basic non-matching
- /foo$/.match("foo ").should be_nil
- /$foo/.match("\n\n\nfoo").should be_nil
+ /foo$/.match("foo ").should == nil
+ /$foo/.match("\n\n\nfoo").should == nil
# A bit advanced
/foo$$$/.match("foo").to_a.should == ["foo"]
(/[^o]$/ =~ "foo\n\n").should == ("foo\n".size - 1) and $~.to_a.should == ["\n"]
# Different end of line chars
- /foo$/.match("foo\r\nbar").should be_nil
- /foo$/.match("foo\0bar").should be_nil
+ /foo$/.match("foo\r\nbar").should == nil
+ /foo$/.match("foo\0bar").should == nil
# Trivial
(/$/ =~ "foo").should == "foo".size and $~.to_a.should == [""]
@@ -61,15 +61,15 @@ describe "Regexps with anchors" do
# Basic matching
/\Afoo/.match("foo").to_a.should == ["foo"]
# Basic non-matching
- /\Abar/.match("foo\nbar").should be_nil
- /\Afoo/.match(" foo").should be_nil
+ /\Abar/.match("foo\nbar").should == nil
+ /\Afoo/.match(" foo").should == nil
# A bit advanced
/\A\A\Afoo/.match("foo").to_a.should == ["foo"]
/(\A\Z)(\A\Z)/.match("").to_a.should == ["", "", ""]
# Different start of line chars
- /\Abar/.match("foo\0bar").should be_nil
+ /\Abar/.match("foo\0bar").should == nil
# Grouping
/(\Afoo)/.match("foo").to_a.should == ["foo", "foo"]
@@ -81,8 +81,8 @@ describe "Regexps with anchors" do
/foo\Z/.match("foo").to_a.should == ["foo"]
/foo\Z/.match("foo\n").to_a.should == ["foo"]
# Basic non-matching
- /foo\Z/.match("foo\nbar").should be_nil
- /foo\Z/.match("foo ").should be_nil
+ /foo\Z/.match("foo\nbar").should == nil
+ /foo\Z/.match("foo ").should == nil
# A bit advanced
/foo\Z\Z\Z/.match("foo\n").to_a.should == ["foo"]
@@ -90,8 +90,8 @@ describe "Regexps with anchors" do
(/(\z\Z)(\z\Z)/ =~ "foo\n").should == "foo\n".size and $~.to_a.should == ["", "", ""]
# Different end of line chars
- /foo\Z/.match("foo\0bar").should be_nil
- /foo\Z/.match("foo\r\n").should be_nil
+ /foo\Z/.match("foo\0bar").should == nil
+ /foo\Z/.match("foo\r\n").should == nil
# Grouping
/(foo\Z)/.match("foo").to_a.should == ["foo", "foo"]
@@ -102,17 +102,17 @@ describe "Regexps with anchors" do
# Basic matching
/foo\z/.match("foo").to_a.should == ["foo"]
# Basic non-matching
- /foo\z/.match("foo\nbar").should be_nil
- /foo\z/.match("foo\n").should be_nil
- /foo\z/.match("foo ").should be_nil
+ /foo\z/.match("foo\nbar").should == nil
+ /foo\z/.match("foo\n").should == nil
+ /foo\z/.match("foo ").should == nil
# A bit advanced
/foo\z\z\z/.match("foo").to_a.should == ["foo"]
(/($\z)($\z)/ =~ "foo").should == "foo".size and $~.to_a.should == ["", "", ""]
# Different end of line chars
- /foo\z/.match("foo\0bar").should be_nil
- /foo\z/.match("foo\r\nbar").should be_nil
+ /foo\z/.match("foo\0bar").should == nil
+ /foo\z/.match("foo\r\nbar").should == nil
# Grouping
/(foo\z)/.match("foo").to_a.should == ["foo", "foo"]
@@ -124,16 +124,16 @@ describe "Regexps with anchors" do
/foo\b/.match("foo").to_a.should == ["foo"]
/foo\b/.match("foo\n").to_a.should == ["foo"]
LanguageSpecs.white_spaces.scan(/./).each do |c|
- /foo\b/.match("foo" + c).to_a.should == ["foo"]
+ /foo\b/.match("foo" + c).to_a.should == ["foo"]
end
LanguageSpecs.non_alphanum_non_space.scan(/./).each do |c|
- /foo\b/.match("foo" + c).to_a.should == ["foo"]
+ /foo\b/.match("foo" + c).to_a.should == ["foo"]
end
/foo\b/.match("foo\0").to_a.should == ["foo"]
# Basic non-matching
- /foo\b/.match("foobar").should be_nil
- /foo\b/.match("foo123").should be_nil
- /foo\b/.match("foo_").should be_nil
+ /foo\b/.match("foobar").should == nil
+ /foo\b/.match("foo123").should == nil
+ /foo\b/.match("foo_").should == nil
end
it "supports \\B (non-word-boundary)" do
@@ -142,15 +142,15 @@ describe "Regexps with anchors" do
/foo\B/.match("foo123").to_a.should == ["foo"]
/foo\B/.match("foo_").to_a.should == ["foo"]
# Basic non-matching
- /foo\B/.match("foo").should be_nil
- /foo\B/.match("foo\n").should be_nil
+ /foo\B/.match("foo").should == nil
+ /foo\B/.match("foo\n").should == nil
LanguageSpecs.white_spaces.scan(/./).each do |c|
- /foo\B/.match("foo" + c).should be_nil
+ /foo\B/.match("foo" + c).should == nil
end
LanguageSpecs.non_alphanum_non_space.scan(/./).each do |c|
- /foo\B/.match("foo" + c).should be_nil
+ /foo\B/.match("foo" + c).should == nil
end
- /foo\B/.match("foo\0").should be_nil
+ /foo\B/.match("foo\0").should == nil
end
it "supports (?= ) (positive lookahead)" do
diff --git a/spec/ruby/language/regexp/back-references_spec.rb b/spec/ruby/language/regexp/back-references_spec.rb
index 607f4463fd..3b4c5656a2 100644
--- a/spec/ruby/language/regexp/back-references_spec.rb
+++ b/spec/ruby/language/regexp/back-references_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../fixtures/classes'
describe "Regexps with back-references" do
it "saves match data in the $~ pseudo-global variable" do
@@ -7,7 +7,7 @@ describe "Regexps with back-references" do
$~.to_a.should == ["ll"]
end
- it "saves captures in numbered $[1-9] variables" do
+ it "saves captures in numbered $[1-N] variables" do
"1234567890" =~ /(1)(2)(3)(4)(5)(6)(7)(8)(9)(0)/
$~.to_a.should == ["1234567890", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0"]
$1.should == "1"
@@ -19,6 +19,16 @@ describe "Regexps with back-references" do
$7.should == "7"
$8.should == "8"
$9.should == "9"
+ $10.should == "0"
+ end
+
+ it "returns nil for numbered variable with too large index" do
+ -> {
+ eval(<<~CODE).should == nil
+ "a" =~ /(.)/
+ eval('$4294967296')
+ CODE
+ }.should complain(/warning: ('|`)\$4294967296' is too big for a number variable, always nil/)
end
it "will not clobber capture variables across threads" do
@@ -39,10 +49,101 @@ describe "Regexps with back-references" do
it "supports \<n> (backreference to previous group match)" do
/(foo.)\1/.match("foo1foo1").to_a.should == ["foo1foo1", "foo1"]
- /(foo.)\1/.match("foo1foo2").should be_nil
+ /(foo.)\1/.match("foo1foo2").should == nil
end
it "resets nested \<n> backreference before match of outer subexpression" do
/(a\1?){2}/.match("aaaa").to_a.should == ["aa", "a"]
end
+
+ it "does not reset enclosed capture groups" do
+ /((a)|(b))+/.match("ab").captures.should == [ "b", "a", "b" ]
+ end
+
+ it "can match an optional quote, followed by content, followed by a matching quote, as the whole string" do
+ /^("|)(.*)\1$/.match('x').to_a.should == ["x", "", "x"]
+ end
+
+ it "allows forward references" do
+ /(?:(\2)|(.))+/.match("aa").to_a.should == [ "aa", "a", "a" ]
+ end
+
+ it "disallows forward references >= 10" do
+ (/\10()()()()()()()()()()/ =~ "\x08").should == 0
+ end
+
+ it "fails when trying to match a backreference to an unmatched capture group" do
+ /\1()/.match("").should == nil
+ /(?:(a)|b)\1/.match("b").should == nil
+ end
+
+ it "ignores backreferences > 1000" do
+ /\99999/.match("99999")[0].should == "99999"
+ end
+
+ it "0 is not a valid backreference" do
+ -> { Regexp.new("\\k<0>") }.should.raise(RegexpError)
+ end
+
+ it "allows numeric conditional backreferences" do
+ /(a)(?(1)a|b)/.match("aa").to_a.should == [ "aa", "a" ]
+ /(a)(?(<1>)a|b)/.match("aa").to_a.should == [ "aa", "a" ]
+ /(a)(?('1')a|b)/.match("aa").to_a.should == [ "aa", "a" ]
+ end
+
+ it "allows either <> or '' in named conditional backreferences" do
+ -> { Regexp.new("(?<a>a)(?(a)a|b)") }.should.raise(RegexpError)
+ /(?<a>a)(?(<a>)a|b)/.match("aa").to_a.should == [ "aa", "a" ]
+ /(?<a>a)(?('a')a|b)/.match("aa").to_a.should == [ "aa", "a" ]
+ end
+
+ it "allows negative numeric backreferences" do
+ /(a)\k<-1>/.match("aa").to_a.should == [ "aa", "a" ]
+ /(a)\g<-1>/.match("aa").to_a.should == [ "aa", "a" ]
+ /(a)(?(<-1>)a|b)/.match("aa").to_a.should == [ "aa", "a" ]
+ /(a)(?('-1')a|b)/.match("aa").to_a.should == [ "aa", "a" ]
+ end
+
+ it "delimited numeric backreferences can start with 0" do
+ /(a)\k<01>/.match("aa").to_a.should == [ "aa", "a" ]
+ /(a)\g<01>/.match("aa").to_a.should == [ "aa", "a" ]
+ /(a)(?(01)a|b)/.match("aa").to_a.should == [ "aa", "a" ]
+ /(a)(?(<01>)a|b)/.match("aa").to_a.should == [ "aa", "a" ]
+ /(a)(?('01')a|b)/.match("aa").to_a.should == [ "aa", "a" ]
+ end
+
+ it "regular numeric backreferences cannot start with 0" do
+ /(a)\01/.match("aa").should == nil
+ /(a)\01/.match("a\x01").to_a.should == [ "a\x01", "a" ]
+ end
+
+ it "named capture groups invalidate numeric backreferences" do
+ -> { Regexp.new("(?<a>a)\\1") }.should.raise(RegexpError)
+ -> { Regexp.new("(?<a>a)\\k<1>") }.should.raise(RegexpError)
+ -> { Regexp.new("(a)(?<a>a)\\1") }.should.raise(RegexpError)
+ -> { Regexp.new("(a)(?<a>a)\\k<1>") }.should.raise(RegexpError)
+ end
+
+ it "treats + or - as the beginning of a level specifier in \\k<> backreferences and (?(...)...|...) conditional backreferences" do
+ -> { Regexp.new("(?<a+>a)\\k<a+>") }.should.raise(RegexpError)
+ -> { Regexp.new("(?<a+b>a)\\k<a+b>") }.should.raise(RegexpError)
+ -> { Regexp.new("(?<a+1>a)\\k<a+1>") }.should.raise(RegexpError)
+ -> { Regexp.new("(?<a->a)\\k<a->") }.should.raise(RegexpError)
+ -> { Regexp.new("(?<a-b>a)\\k<a-b>") }.should.raise(RegexpError)
+ -> { Regexp.new("(?<a-1>a)\\k<a-1>") }.should.raise(RegexpError)
+
+ -> { Regexp.new("(?<a+>a)(?(<a+>)a|b)") }.should.raise(RegexpError)
+ -> { Regexp.new("(?<a+b>a)(?(<a+b>)a|b)") }.should.raise(RegexpError)
+ -> { Regexp.new("(?<a+1>a)(?(<a+1>)a|b)") }.should.raise(RegexpError)
+ -> { Regexp.new("(?<a->a)(?(<a->)a|b)") }.should.raise(RegexpError)
+ -> { Regexp.new("(?<a-b>a)(?(<a-b>)a|b)") }.should.raise(RegexpError)
+ -> { Regexp.new("(?<a-1>a)(?(<a-1>)a|b)") }.should.raise(RegexpError)
+
+ -> { Regexp.new("(?<a+>a)(?('a+')a|b)") }.should.raise(RegexpError)
+ -> { Regexp.new("(?<a+b>a)(?('a+b')a|b)") }.should.raise(RegexpError)
+ -> { Regexp.new("(?<a+1>a)(?('a+1')a|b)") }.should.raise(RegexpError)
+ -> { Regexp.new("(?<a->a)(?('a-')a|b)") }.should.raise(RegexpError)
+ -> { Regexp.new("(?<a-b>a)(?('a-b')a|b)") }.should.raise(RegexpError)
+ -> { Regexp.new("(?<a-1>a)(?('a-1')a|b)") }.should.raise(RegexpError)
+ end
end
diff --git a/spec/ruby/language/regexp/character_classes_spec.rb b/spec/ruby/language/regexp/character_classes_spec.rb
index ce66d8e65f..c6ed92b78e 100644
--- a/spec/ruby/language/regexp/character_classes_spec.rb
+++ b/spec/ruby/language/regexp/character_classes_spec.rb
@@ -1,6 +1,6 @@
# coding: utf-8
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../fixtures/classes'
describe "Regexp with character classes" do
it "supports \\w (word character)" do
@@ -9,9 +9,9 @@ describe "Regexp with character classes" do
/\w/.match("_").to_a.should == ["_"]
# Non-matches
- /\w/.match(LanguageSpecs.white_spaces).should be_nil
- /\w/.match(LanguageSpecs.non_alphanum_non_space).should be_nil
- /\w/.match("\0").should be_nil
+ /\w/.match(LanguageSpecs.white_spaces).should == nil
+ /\w/.match(LanguageSpecs.non_alphanum_non_space).should == nil
+ /\w/.match("\0").should == nil
end
it "supports \\W (non-word character)" do
@@ -20,19 +20,19 @@ describe "Regexp with character classes" do
/\W/.match("\0").to_a.should == ["\0"]
# Non-matches
- /\W/.match("a").should be_nil
- /\W/.match("1").should be_nil
- /\W/.match("_").should be_nil
+ /\W/.match("a").should == nil
+ /\W/.match("1").should == nil
+ /\W/.match("_").should == nil
end
it "supports \\s (space character)" do
/\s+/.match(LanguageSpecs.white_spaces).to_a.should == [LanguageSpecs.white_spaces]
# Non-matches
- /\s/.match("a").should be_nil
- /\s/.match("1").should be_nil
- /\s/.match(LanguageSpecs.non_alphanum_non_space).should be_nil
- /\s/.match("\0").should be_nil
+ /\s/.match("a").should == nil
+ /\s/.match("1").should == nil
+ /\s/.match(LanguageSpecs.non_alphanum_non_space).should == nil
+ /\s/.match("\0").should == nil
end
it "supports \\S (non-space character)" do
@@ -42,17 +42,17 @@ describe "Regexp with character classes" do
/\S/.match("\0").to_a.should == ["\0"]
# Non-matches
- /\S/.match(LanguageSpecs.white_spaces).should be_nil
+ /\S/.match(LanguageSpecs.white_spaces).should == nil
end
it "supports \\d (numeric digit)" do
/\d/.match("1").to_a.should == ["1"]
# Non-matches
- /\d/.match("a").should be_nil
- /\d/.match(LanguageSpecs.white_spaces).should be_nil
- /\d/.match(LanguageSpecs.non_alphanum_non_space).should be_nil
- /\d/.match("\0").should be_nil
+ /\d/.match("a").should == nil
+ /\d/.match(LanguageSpecs.white_spaces).should == nil
+ /\d/.match(LanguageSpecs.non_alphanum_non_space).should == nil
+ /\d/.match("\0").should == nil
end
it "supports \\D (non-digit)" do
@@ -62,7 +62,7 @@ describe "Regexp with character classes" do
/\D/.match("\0").to_a.should == ["\0"]
# Non-matches
- /\D/.match("1").should be_nil
+ /\D/.match("1").should == nil
end
it "supports [] (character class)" do
@@ -89,7 +89,7 @@ describe "Regexp with character classes" do
/[^[:lower:]A-C]+/.match("abcABCDEF123def").to_a.should == ["DEF123"] # negated character class
/[:alnum:]+/.match("a:l:n:u:m").to_a.should == ["a:l:n:u:m"] # should behave like regular character class composed of the individual letters
/[\[:alnum:]+/.match("[:a:l:n:u:m").to_a.should == ["[:a:l:n:u:m"] # should behave like regular character class composed of the individual letters
- lambda { eval('/[[:alpha:]-[:digit:]]/') }.should raise_error(SyntaxError) # can't use character class as a start value of range
+ -> { eval('/[[:alpha:]-[:digit:]]/') }.should.raise(SyntaxError) # can't use character class as a start value of range
end
it "matches ASCII characters with [[:ascii:]]" do
@@ -99,8 +99,8 @@ describe "Regexp with character classes" do
not_supported_on :opal do
it "doesn't match non-ASCII characters with [[:ascii:]]" do
- /[[:ascii:]]/.match("\u{80}").should be_nil
- /[[:ascii:]]/.match("\u{9898}").should be_nil
+ /[[:ascii:]]/.match("\u{80}").should == nil
+ /[[:ascii:]]/.match("\u{9898}").should == nil
end
end
@@ -113,7 +113,7 @@ describe "Regexp with character classes" do
end
it "doesn't matches Unicode marks with [[:alnum:]]" do
- "\u{36F}".match(/[[:alnum:]]/).should be_nil
+ "\u{3099}".match(/[[:alnum:]]/).should == nil
end
it "doesn't match Unicode control characters with [[:alnum:]]" do
@@ -133,7 +133,7 @@ describe "Regexp with character classes" do
end
it "doesn't matches Unicode marks with [[:alpha:]]" do
- "\u{36F}".match(/[[:alpha:]]/).should be_nil
+ "\u{3099}".match(/[[:alpha:]]/).should == nil
end
it "doesn't match Unicode control characters with [[:alpha:]]" do
@@ -149,39 +149,39 @@ describe "Regexp with character classes" do
end
it "doesn't match Unicode control characters with [[:blank:]]" do
- "\u{16}".match(/[[:blank:]]/).should be_nil
+ "\u{16}".match(/[[:blank:]]/).should == nil
end
it "doesn't match Unicode punctuation characters with [[:blank:]]" do
- "\u{3F}".match(/[[:blank:]]/).should be_nil
+ "\u{3F}".match(/[[:blank:]]/).should == nil
end
it "doesn't match Unicode letter characters with [[:blank:]]" do
- "à".match(/[[:blank:]]/).should be_nil
+ "à".match(/[[:blank:]]/).should == nil
end
it "doesn't match Unicode digits with [[:blank:]]" do
- "\u{0660}".match(/[[:blank:]]/).should be_nil
+ "\u{0660}".match(/[[:blank:]]/).should == nil
end
it "doesn't match Unicode marks with [[:blank:]]" do
- "\u{36F}".match(/[[:blank:]]/).should be_nil
+ "\u{36F}".match(/[[:blank:]]/).should == nil
end
it "doesn't Unicode letter characters with [[:cntrl:]]" do
- "à".match(/[[:cntrl:]]/).should be_nil
+ "à".match(/[[:cntrl:]]/).should == nil
end
it "doesn't match Unicode digits with [[:cntrl:]]" do
- "\u{0660}".match(/[[:cntrl:]]/).should be_nil
+ "\u{0660}".match(/[[:cntrl:]]/).should == nil
end
it "doesn't match Unicode marks with [[:cntrl:]]" do
- "\u{36F}".match(/[[:cntrl:]]/).should be_nil
+ "\u{36F}".match(/[[:cntrl:]]/).should == nil
end
it "doesn't match Unicode punctuation characters with [[:cntrl:]]" do
- "\u{3F}".match(/[[:cntrl:]]/).should be_nil
+ "\u{3F}".match(/[[:cntrl:]]/).should == nil
end
it "matches Unicode control characters with [[:cntrl:]]" do
@@ -189,15 +189,15 @@ describe "Regexp with character classes" do
end
it "doesn't match Unicode format characters with [[:cntrl:]]" do
- "\u{2060}".match(/[[:cntrl:]]/).should be_nil
+ "\u{2060}".match(/[[:cntrl:]]/).should == nil
end
it "doesn't match Unicode private-use characters with [[:cntrl:]]" do
- "\u{E001}".match(/[[:cntrl:]]/).should be_nil
+ "\u{E001}".match(/[[:cntrl:]]/).should == nil
end
it "doesn't match Unicode letter characters with [[:digit:]]" do
- "à".match(/[[:digit:]]/).should be_nil
+ "à".match(/[[:digit:]]/).should == nil
end
it "matches Unicode digits with [[:digit:]]" do
@@ -206,27 +206,27 @@ describe "Regexp with character classes" do
end
it "doesn't match Unicode marks with [[:digit:]]" do
- "\u{36F}".match(/[[:digit:]]/).should be_nil
+ "\u{36F}".match(/[[:digit:]]/).should == nil
end
it "doesn't match Unicode punctuation characters with [[:digit:]]" do
- "\u{3F}".match(/[[:digit:]]/).should be_nil
+ "\u{3F}".match(/[[:digit:]]/).should == nil
end
it "doesn't match Unicode control characters with [[:digit:]]" do
- "\u{16}".match(/[[:digit:]]/).should be_nil
+ "\u{16}".match(/[[:digit:]]/).should == nil
end
it "doesn't match Unicode format characters with [[:digit:]]" do
- "\u{2060}".match(/[[:digit:]]/).should be_nil
+ "\u{2060}".match(/[[:digit:]]/).should == nil
end
it "doesn't match Unicode private-use characters with [[:digit:]]" do
- "\u{E001}".match(/[[:digit:]]/).should be_nil
+ "\u{E001}".match(/[[:digit:]]/).should == nil
end
it "matches Unicode letter characters with [[:graph:]]" do
- "à".match(/[[:graph:]]/).to_a.should == ["à"]
+ "à".match(/[[:graph:]]/).to_a.should == ["à"]
end
it "matches Unicode digits with [[:graph:]]" do
@@ -243,7 +243,7 @@ describe "Regexp with character classes" do
end
it "doesn't match Unicode control characters with [[:graph:]]" do
- "\u{16}".match(/[[:graph:]]/).should be_nil
+ "\u{16}".match(/[[:graph:]]/).should == nil
end
it "match Unicode format characters with [[:graph:]]" do
@@ -261,40 +261,40 @@ describe "Regexp with character classes" do
end
it "doesn't match Unicode uppercase letter characters with [[:lower:]]" do
- "\u{100}".match(/[[:lower:]]/).should be_nil
- "\u{130}".match(/[[:lower:]]/).should be_nil
- "\u{405}".match(/[[:lower:]]/).should be_nil
+ "\u{100}".match(/[[:lower:]]/).should == nil
+ "\u{130}".match(/[[:lower:]]/).should == nil
+ "\u{405}".match(/[[:lower:]]/).should == nil
end
it "doesn't match Unicode title-case characters with [[:lower:]]" do
- "\u{1F88}".match(/[[:lower:]]/).should be_nil
- "\u{1FAD}".match(/[[:lower:]]/).should be_nil
- "\u{01C5}".match(/[[:lower:]]/).should be_nil
+ "\u{1F88}".match(/[[:lower:]]/).should == nil
+ "\u{1FAD}".match(/[[:lower:]]/).should == nil
+ "\u{01C5}".match(/[[:lower:]]/).should == nil
end
it "doesn't match Unicode digits with [[:lower:]]" do
- "\u{0660}".match(/[[:lower:]]/).should be_nil
- "\u{FF12}".match(/[[:lower:]]/).should be_nil
+ "\u{0660}".match(/[[:lower:]]/).should == nil
+ "\u{FF12}".match(/[[:lower:]]/).should == nil
end
it "doesn't match Unicode marks with [[:lower:]]" do
- "\u{36F}".match(/[[:lower:]]/).should be_nil
+ "\u{36F}".match(/[[:lower:]]/).should == nil
end
it "doesn't match Unicode punctuation characters with [[:lower:]]" do
- "\u{3F}".match(/[[:lower:]]/).should be_nil
+ "\u{3F}".match(/[[:lower:]]/).should == nil
end
it "doesn't match Unicode control characters with [[:lower:]]" do
- "\u{16}".match(/[[:lower:]]/).should be_nil
+ "\u{16}".match(/[[:lower:]]/).should == nil
end
it "doesn't match Unicode format characters with [[:lower:]]" do
- "\u{2060}".match(/[[:lower:]]/).should be_nil
+ "\u{2060}".match(/[[:lower:]]/).should == nil
end
it "doesn't match Unicode private-use characters with [[:lower:]]" do
- "\u{E001}".match(/[[:lower:]]/).should be_nil
+ "\u{E001}".match(/[[:lower:]]/).should == nil
end
it "matches Unicode lowercase letter characters with [[:print:]]" do
@@ -329,7 +329,7 @@ describe "Regexp with character classes" do
end
it "doesn't match Unicode control characters with [[:print:]]" do
- "\u{16}".match(/[[:print:]]/).should be_nil
+ "\u{16}".match(/[[:print:]]/).should == nil
end
it "match Unicode format characters with [[:print:]]" do
@@ -342,30 +342,30 @@ describe "Regexp with character classes" do
it "doesn't match Unicode lowercase letter characters with [[:punct:]]" do
- "\u{FF41}".match(/[[:punct:]]/).should be_nil
- "\u{1D484}".match(/[[:punct:]]/).should be_nil
- "\u{E8}".match(/[[:punct:]]/).should be_nil
+ "\u{FF41}".match(/[[:punct:]]/).should == nil
+ "\u{1D484}".match(/[[:punct:]]/).should == nil
+ "\u{E8}".match(/[[:punct:]]/).should == nil
end
it "doesn't match Unicode uppercase letter characters with [[:punct:]]" do
- "\u{100}".match(/[[:punct:]]/).should be_nil
- "\u{130}".match(/[[:punct:]]/).should be_nil
- "\u{405}".match(/[[:punct:]]/).should be_nil
+ "\u{100}".match(/[[:punct:]]/).should == nil
+ "\u{130}".match(/[[:punct:]]/).should == nil
+ "\u{405}".match(/[[:punct:]]/).should == nil
end
it "doesn't match Unicode title-case characters with [[:punct:]]" do
- "\u{1F88}".match(/[[:punct:]]/).should be_nil
- "\u{1FAD}".match(/[[:punct:]]/).should be_nil
- "\u{01C5}".match(/[[:punct:]]/).should be_nil
+ "\u{1F88}".match(/[[:punct:]]/).should == nil
+ "\u{1FAD}".match(/[[:punct:]]/).should == nil
+ "\u{01C5}".match(/[[:punct:]]/).should == nil
end
it "doesn't match Unicode digits with [[:punct:]]" do
- "\u{0660}".match(/[[:punct:]]/).should be_nil
- "\u{FF12}".match(/[[:punct:]]/).should be_nil
+ "\u{0660}".match(/[[:punct:]]/).should == nil
+ "\u{FF12}".match(/[[:punct:]]/).should == nil
end
it "doesn't match Unicode marks with [[:punct:]]" do
- "\u{36F}".match(/[[:punct:]]/).should be_nil
+ "\u{36F}".match(/[[:punct:]]/).should == nil
end
it "matches Unicode Pc characters with [[:punct:]]" do
@@ -398,38 +398,38 @@ describe "Regexp with character classes" do
end
it "doesn't match Unicode format characters with [[:punct:]]" do
- "\u{2060}".match(/[[:punct:]]/).should be_nil
+ "\u{2060}".match(/[[:punct:]]/).should == nil
end
it "doesn't match Unicode private-use characters with [[:punct:]]" do
- "\u{E001}".match(/[[:punct:]]/).should be_nil
+ "\u{E001}".match(/[[:punct:]]/).should == nil
end
it "doesn't match Unicode lowercase letter characters with [[:space:]]" do
- "\u{FF41}".match(/[[:space:]]/).should be_nil
- "\u{1D484}".match(/[[:space:]]/).should be_nil
- "\u{E8}".match(/[[:space:]]/).should be_nil
+ "\u{FF41}".match(/[[:space:]]/).should == nil
+ "\u{1D484}".match(/[[:space:]]/).should == nil
+ "\u{E8}".match(/[[:space:]]/).should == nil
end
it "doesn't match Unicode uppercase letter characters with [[:space:]]" do
- "\u{100}".match(/[[:space:]]/).should be_nil
- "\u{130}".match(/[[:space:]]/).should be_nil
- "\u{405}".match(/[[:space:]]/).should be_nil
+ "\u{100}".match(/[[:space:]]/).should == nil
+ "\u{130}".match(/[[:space:]]/).should == nil
+ "\u{405}".match(/[[:space:]]/).should == nil
end
it "doesn't match Unicode title-case characters with [[:space:]]" do
- "\u{1F88}".match(/[[:space:]]/).should be_nil
- "\u{1FAD}".match(/[[:space:]]/).should be_nil
- "\u{01C5}".match(/[[:space:]]/).should be_nil
+ "\u{1F88}".match(/[[:space:]]/).should == nil
+ "\u{1FAD}".match(/[[:space:]]/).should == nil
+ "\u{01C5}".match(/[[:space:]]/).should == nil
end
it "doesn't match Unicode digits with [[:space:]]" do
- "\u{0660}".match(/[[:space:]]/).should be_nil
- "\u{FF12}".match(/[[:space:]]/).should be_nil
+ "\u{0660}".match(/[[:space:]]/).should == nil
+ "\u{FF12}".match(/[[:space:]]/).should == nil
end
it "doesn't match Unicode marks with [[:space:]]" do
- "\u{36F}".match(/[[:space:]]/).should be_nil
+ "\u{36F}".match(/[[:space:]]/).should == nil
end
it "matches Unicode Zs characters with [[:space:]]" do
@@ -445,17 +445,17 @@ describe "Regexp with character classes" do
end
it "doesn't match Unicode format characters with [[:space:]]" do
- "\u{2060}".match(/[[:space:]]/).should be_nil
+ "\u{2060}".match(/[[:space:]]/).should == nil
end
it "doesn't match Unicode private-use characters with [[:space:]]" do
- "\u{E001}".match(/[[:space:]]/).should be_nil
+ "\u{E001}".match(/[[:space:]]/).should == nil
end
it "doesn't match Unicode lowercase characters with [[:upper:]]" do
- "\u{FF41}".match(/[[:upper:]]/).should be_nil
- "\u{1D484}".match(/[[:upper:]]/).should be_nil
- "\u{E8}".match(/[[:upper:]]/).should be_nil
+ "\u{FF41}".match(/[[:upper:]]/).should == nil
+ "\u{1D484}".match(/[[:upper:]]/).should == nil
+ "\u{E8}".match(/[[:upper:]]/).should == nil
end
it "matches Unicode uppercase characters with [[:upper:]]" do
@@ -465,40 +465,40 @@ describe "Regexp with character classes" do
end
it "doesn't match Unicode title-case characters with [[:upper:]]" do
- "\u{1F88}".match(/[[:upper:]]/).should be_nil
- "\u{1FAD}".match(/[[:upper:]]/).should be_nil
- "\u{01C5}".match(/[[:upper:]]/).should be_nil
+ "\u{1F88}".match(/[[:upper:]]/).should == nil
+ "\u{1FAD}".match(/[[:upper:]]/).should == nil
+ "\u{01C5}".match(/[[:upper:]]/).should == nil
end
it "doesn't match Unicode digits with [[:upper:]]" do
- "\u{0660}".match(/[[:upper:]]/).should be_nil
- "\u{FF12}".match(/[[:upper:]]/).should be_nil
+ "\u{0660}".match(/[[:upper:]]/).should == nil
+ "\u{FF12}".match(/[[:upper:]]/).should == nil
end
it "doesn't match Unicode marks with [[:upper:]]" do
- "\u{36F}".match(/[[:upper:]]/).should be_nil
+ "\u{36F}".match(/[[:upper:]]/).should == nil
end
it "doesn't match Unicode punctuation characters with [[:upper:]]" do
- "\u{3F}".match(/[[:upper:]]/).should be_nil
+ "\u{3F}".match(/[[:upper:]]/).should == nil
end
it "doesn't match Unicode control characters with [[:upper:]]" do
- "\u{16}".match(/[[:upper:]]/).should be_nil
+ "\u{16}".match(/[[:upper:]]/).should == nil
end
it "doesn't match Unicode format characters with [[:upper:]]" do
- "\u{2060}".match(/[[:upper:]]/).should be_nil
+ "\u{2060}".match(/[[:upper:]]/).should == nil
end
it "doesn't match Unicode private-use characters with [[:upper:]]" do
- "\u{E001}".match(/[[:upper:]]/).should be_nil
+ "\u{E001}".match(/[[:upper:]]/).should == nil
end
it "doesn't match Unicode letter characters [^a-fA-F] with [[:xdigit:]]" do
- "à".match(/[[:xdigit:]]/).should be_nil
- "g".match(/[[:xdigit:]]/).should be_nil
- "X".match(/[[:xdigit:]]/).should be_nil
+ "à".match(/[[:xdigit:]]/).should == nil
+ "g".match(/[[:xdigit:]]/).should == nil
+ "X".match(/[[:xdigit:]]/).should == nil
end
it "matches Unicode letter characters [a-fA-F] with [[:xdigit:]]" do
@@ -507,28 +507,28 @@ describe "Regexp with character classes" do
end
it "doesn't match Unicode digits [^0-9] with [[:xdigit:]]" do
- "\u{0660}".match(/[[:xdigit:]]/).should be_nil
- "\u{FF12}".match(/[[:xdigit:]]/).should be_nil
+ "\u{0660}".match(/[[:xdigit:]]/).should == nil
+ "\u{FF12}".match(/[[:xdigit:]]/).should == nil
end
it "doesn't match Unicode marks with [[:xdigit:]]" do
- "\u{36F}".match(/[[:xdigit:]]/).should be_nil
+ "\u{36F}".match(/[[:xdigit:]]/).should == nil
end
it "doesn't match Unicode punctuation characters with [[:xdigit:]]" do
- "\u{3F}".match(/[[:xdigit:]]/).should be_nil
+ "\u{3F}".match(/[[:xdigit:]]/).should == nil
end
it "doesn't match Unicode control characters with [[:xdigit:]]" do
- "\u{16}".match(/[[:xdigit:]]/).should be_nil
+ "\u{16}".match(/[[:xdigit:]]/).should == nil
end
it "doesn't match Unicode format characters with [[:xdigit:]]" do
- "\u{2060}".match(/[[:xdigit:]]/).should be_nil
+ "\u{2060}".match(/[[:xdigit:]]/).should == nil
end
it "doesn't match Unicode private-use characters with [[:xdigit:]]" do
- "\u{E001}".match(/[[:xdigit:]]/).should be_nil
+ "\u{E001}".match(/[[:xdigit:]]/).should == nil
end
it "matches Unicode lowercase characters with [[:word:]]" do
@@ -562,23 +562,30 @@ describe "Regexp with character classes" do
"\u{16EE}".match(/[[:word:]]/).to_a.should == ["\u{16EE}"]
end
+ ruby_bug "#19417", ""..."3.4.6" do
+ it "matches Unicode join control characters with [[:word:]]" do
+ "\u{200C}".match(/[[:word:]]/).to_a.should == ["\u{200C}"]
+ "\u{200D}".match(/[[:word:]]/).to_a.should == ["\u{200D}"]
+ end
+ end
+
it "doesn't match Unicode No characters with [[:word:]]" do
- "\u{17F0}".match(/[[:word:]]/).should be_nil
+ "\u{17F0}".match(/[[:word:]]/).should == nil
end
it "doesn't match Unicode punctuation characters with [[:word:]]" do
- "\u{3F}".match(/[[:word:]]/).should be_nil
+ "\u{3F}".match(/[[:word:]]/).should == nil
end
it "doesn't match Unicode control characters with [[:word:]]" do
- "\u{16}".match(/[[:word:]]/).should be_nil
+ "\u{16}".match(/[[:word:]]/).should == nil
end
it "doesn't match Unicode format characters with [[:word:]]" do
- "\u{2060}".match(/[[:word:]]/).should be_nil
+ "\u{2060}".match(/[[:word:]]/).should == nil
end
it "doesn't match Unicode private-use characters with [[:word:]]" do
- "\u{E001}".match(/[[:word:]]/).should be_nil
+ "\u{E001}".match(/[[:word:]]/).should == nil
end
it "matches unicode named character properties" do
@@ -609,25 +616,32 @@ describe "Regexp with character classes" do
"루비(Ruby)".match(/\p{Hangul}+/u).to_a.should == ["루비"]
end
- ruby_version_is "2.4" do
- it "supports \\X (unicode 9.0 with UTR #51 workarounds)" do
- # simple emoji without any fancy modifier or ZWJ
- /\X/.match("\u{1F98A}").to_a.should == ["🦊"]
+ it "supports negated property condition" do
+ "a".match(eval("/\P{L}/")).should == nil
+ "1".match(eval("/\P{N}/")).should == nil
+ end
+
+ it "raises a RegexpError for an unterminated unicode property" do
+ -> { Regexp.new('\p{') }.should.raise(RegexpError)
+ end
+
+ it "supports \\X (unicode 9.0 with UTR #51 workarounds)" do
+ # simple emoji without any fancy modifier or ZWJ
+ /\X/.match("\u{1F98A}").to_a.should == ["🦊"]
- # skin tone modifier
- /\X/.match("\u{1F918}\u{1F3FD}").to_a.should == ["🤘ðŸ½"]
+ # skin tone modifier
+ /\X/.match("\u{1F918}\u{1F3FD}").to_a.should == ["🤘ðŸ½"]
- # emoji joined with ZWJ
- /\X/.match("\u{1F3F3}\u{FE0F}\u{200D}\u{1F308}").to_a.should == ["ðŸ³ï¸â€ðŸŒˆ"]
- /\X/.match("\u{1F469}\u{200D}\u{1F469}\u{200D}\u{1F467}\u{200D}\u{1F466}").to_a.should == ["👩â€ðŸ‘©â€ðŸ‘§â€ðŸ‘¦"]
+ # emoji joined with ZWJ
+ /\X/.match("\u{1F3F3}\u{FE0F}\u{200D}\u{1F308}").to_a.should == ["ðŸ³ï¸â€ðŸŒˆ"]
+ /\X/.match("\u{1F469}\u{200D}\u{1F469}\u{200D}\u{1F467}\u{200D}\u{1F466}").to_a.should == ["👩â€ðŸ‘©â€ðŸ‘§â€ðŸ‘¦"]
- # without the ZWJ
- /\X+/.match("\u{1F3F3}\u{FE0F}\u{1F308}").to_a.should == ["ðŸ³ï¸ðŸŒˆ"]
- /\X+/.match("\u{1F469}\u{1F469}\u{1F467}\u{1F466}").to_a.should == ["👩👩👧👦"]
+ # without the ZWJ
+ /\X+/.match("\u{1F3F3}\u{FE0F}\u{1F308}").to_a.should == ["ðŸ³ï¸ðŸŒˆ"]
+ /\X+/.match("\u{1F469}\u{1F469}\u{1F467}\u{1F466}").to_a.should == ["👩👩👧👦"]
- # both of the ZWJ combined
- /\X+/.match("\u{1F3F3}\u{FE0F}\u{200D}\u{1F308}\u{1F469}\u{200D}\u{1F469}\u{200D}\u{1F467}\u{200D}\u{1F466}")
- .to_a.should == ["ðŸ³ï¸â€ðŸŒˆðŸ‘©â€ðŸ‘©â€ðŸ‘§â€ðŸ‘¦"]
- end
+ # both of the ZWJ combined
+ /\X+/.match("\u{1F3F3}\u{FE0F}\u{200D}\u{1F308}\u{1F469}\u{200D}\u{1F469}\u{200D}\u{1F467}\u{200D}\u{1F466}")
+ .to_a.should == ["ðŸ³ï¸â€ðŸŒˆðŸ‘©â€ðŸ‘©â€ðŸ‘§â€ðŸ‘¦"]
end
end
diff --git a/spec/ruby/language/regexp/empty_checks_spec.rb b/spec/ruby/language/regexp/empty_checks_spec.rb
new file mode 100644
index 0000000000..391e65b003
--- /dev/null
+++ b/spec/ruby/language/regexp/empty_checks_spec.rb
@@ -0,0 +1,135 @@
+require_relative '../../spec_helper'
+require_relative '../fixtures/classes'
+
+describe "empty checks in Regexps" do
+
+ it "allow extra empty iterations" do
+ /()?/.match("").to_a.should == ["", ""]
+ /(a*)?/.match("").to_a.should == ["", ""]
+ /(a*)*/.match("").to_a.should == ["", ""]
+ # The bounds are high to avoid DFA-based matchers in implementations
+ # and to check backtracking behavior.
+ /(?:a|()){500,1000}/.match("a" * 500).to_a.should == ["a" * 500, ""]
+
+ # Variations with non-greedy loops.
+ /()??/.match("").to_a.should == ["", nil]
+ /(a*?)?/.match("").to_a.should == ["", ""]
+ /(a*)??/.match("").to_a.should == ["", nil]
+ /(a*?)??/.match("").to_a.should == ["", nil]
+ /(a*?)*/.match("").to_a.should == ["", ""]
+ /(a*)*?/.match("").to_a.should == ["", nil]
+ /(a*?)*?/.match("").to_a.should == ["", nil]
+ end
+
+ it "allow empty iterations in the middle of a loop" do
+ # One empty iteration between a's and b's.
+ /(a|\2b|())*/.match("aaabbb").to_a.should == ["aaabbb", "", ""]
+ /(a|\2b|()){2,4}/.match("aaabbb").to_a.should == ["aaa", "", ""]
+
+ # Two empty iterations between a's and b's.
+ /(a|\2b|\3()|())*/.match("aaabbb").to_a.should == ["aaabbb", "", "", ""]
+ /(a|\2b|\3()|()){2,4}/.match("aaabbb").to_a.should == ["aaa", "", nil, ""]
+
+ # Check that the empty iteration correctly updates the loop counter.
+ /(a|\2b|()){20,24}/.match("a" * 20 + "b" * 5).to_a.should == ["a" * 20 + "b" * 3, "b", ""]
+
+ # Variations with non-greedy loops.
+ /(a|\2b|())*?/.match("aaabbb").to_a.should == ["", nil, nil]
+ /(a|\2b|()){2,4}/.match("aaabbb").to_a.should == ["aaa", "", ""]
+ /(a|\2b|\3()|())*?/.match("aaabbb").to_a.should == ["", nil, nil, nil]
+ /(a|\2b|\3()|()){2,4}/.match("aaabbb").to_a.should == ["aaa", "", nil, ""]
+ /(a|\2b|()){20,24}/.match("a" * 20 + "b" * 5).to_a.should == ["a" * 20 + "b" * 3, "b", ""]
+ end
+
+ it "make the Regexp proceed past the quantified expression on failure" do
+ # If the contents of the ()* quantified group are empty (i.e., they fail
+ # the empty check), the loop will abort. It will not try to backtrack
+ # and try other alternatives (e.g. matching the "a") like in other Regexp
+ # dialects such as ECMAScript.
+ /(?:|a)*/.match("aaa").to_a.should == [""]
+ /(?:()|a)*/.match("aaa").to_a.should == ["", ""]
+ /(|a)*/.match("aaa").to_a.should == ["", ""]
+ /(()|a)*/.match("aaa").to_a.should == ["", "", ""]
+
+ # Same expressions, but with backreferences, to force the use of non-DFA-based
+ # engines.
+ /()\1(?:|a)*/.match("aaa").to_a.should == ["", ""]
+ /()\1(?:()|a)*/.match("aaa").to_a.should == ["", "", ""]
+ /()\1(|a)*/.match("aaa").to_a.should == ["", "", ""]
+ /()\1(()|a)*/.match("aaa").to_a.should == ["", "", "", ""]
+
+ # Variations with other zero-width contents of the quantified
+ # group: backreferences, capture groups, lookarounds
+ /()(?:\1|a)*/.match("aaa").to_a.should == ["", ""]
+ /()(?:()\1|a)*/.match("aaa").to_a.should == ["", "", ""]
+ /()(?:(\1)|a)*/.match("aaa").to_a.should == ["", "", ""]
+ /()(?:\1()|a)*/.match("aaa").to_a.should == ["", "", ""]
+ /()(\1|a)*/.match("aaa").to_a.should == ["", "", ""]
+ /()(()\1|a)*/.match("aaa").to_a.should == ["", "", "", ""]
+ /()((\1)|a)*/.match("aaa").to_a.should == ["", "", "", ""]
+ /()(\1()|a)*/.match("aaa").to_a.should == ["", "", "", ""]
+
+ /(?:(?=a)|a)*/.match("aaa").to_a.should == [""]
+ /(?:(?=a)()|a)*/.match("aaa").to_a.should == ["", ""]
+ /(?:()(?=a)|a)*/.match("aaa").to_a.should == ["", ""]
+ /(?:((?=a))|a)*/.match("aaa").to_a.should == ["", ""]
+ /()\1(?:(?=a)|a)*/.match("aaa").to_a.should == ["", ""]
+ /()\1(?:(?=a)()|a)*/.match("aaa").to_a.should == ["", "", ""]
+ /()\1(?:()(?=a)|a)*/.match("aaa").to_a.should == ["", "", ""]
+ /()\1(?:((?=a))|a)*/.match("aaa").to_a.should == ["", "", ""]
+
+ # Variations with non-greedy loops.
+ /(?:|a)*?/.match("aaa").to_a.should == [""]
+ /(?:()|a)*?/.match("aaa").to_a.should == ["", nil]
+ /(|a)*?/.match("aaa").to_a.should == ["", nil]
+ /(()|a)*?/.match("aaa").to_a.should == ["", nil, nil]
+
+ /()\1(?:|a)*?/.match("aaa").to_a.should == ["", ""]
+ /()\1(?:()|a)*?/.match("aaa").to_a.should == ["", "", nil]
+ /()\1(|a)*?/.match("aaa").to_a.should == ["", "", nil]
+ /()\1(()|a)*?/.match("aaa").to_a.should == ["", "", nil, nil]
+
+ /()(?:\1|a)*?/.match("aaa").to_a.should == ["", ""]
+ /()(?:()\1|a)*?/.match("aaa").to_a.should == ["", "", nil]
+ /()(?:(\1)|a)*?/.match("aaa").to_a.should == ["", "", nil]
+ /()(?:\1()|a)*?/.match("aaa").to_a.should == ["", "", nil]
+ /()(\1|a)*?/.match("aaa").to_a.should == ["", "", nil]
+ /()(()\1|a)*?/.match("aaa").to_a.should == ["", "", nil, nil]
+ /()((\1)|a)*?/.match("aaa").to_a.should == ["", "", nil, nil]
+ /()(\1()|a)*?/.match("aaa").to_a.should == ["", "", nil, nil]
+
+ /(?:(?=a)|a)*?/.match("aaa").to_a.should == [""]
+ /(?:(?=a)()|a)*?/.match("aaa").to_a.should == ["", nil]
+ /(?:()(?=a)|a)*?/.match("aaa").to_a.should == ["", nil]
+ /(?:((?=a))|a)*?/.match("aaa").to_a.should == ["", nil]
+ /()\1(?:(?=a)|a)*?/.match("aaa").to_a.should == ["", ""]
+ /()\1(?:(?=a)()|a)*?/.match("aaa").to_a.should == ["", "", nil]
+ /()\1(?:()(?=a)|a)*?/.match("aaa").to_a.should == ["", "", nil]
+ /()\1(?:((?=a))|a)*?/.match("aaa").to_a.should == ["", "", nil]
+ end
+
+ it "shouldn't cause the Regexp parser to get stuck in a loop" do
+ /(|a|\2b|())*/.match("aaabbb").to_a.should == ["", "", nil]
+ /(a||\2b|())*/.match("aaabbb").to_a.should == ["aaa", "", nil]
+ /(a|\2b||())*/.match("aaabbb").to_a.should == ["aaa", "", nil]
+ /(a|\2b|()|)*/.match("aaabbb").to_a.should == ["aaabbb", "", ""]
+ /(()|a|\3b|())*/.match("aaabbb").to_a.should == ["", "", "", nil]
+ /(a|()|\3b|())*/.match("aaabbb").to_a.should == ["aaa", "", "", nil]
+ /(a|\2b|()|())*/.match("aaabbb").to_a.should == ["aaabbb", "", "", nil]
+ /(a|\3b|()|())*/.match("aaabbb").to_a.should == ["aaa", "", "", nil]
+ /(a|()|())*/.match("aaa").to_a.should == ["aaa", "", "", nil]
+ /^(()|a|())*$/.match("aaa").to_a.should == ["aaa", "", "", nil]
+
+ # Variations with non-greedy loops.
+ /(|a|\2b|())*?/.match("aaabbb").to_a.should == ["", nil, nil]
+ /(a||\2b|())*?/.match("aaabbb").to_a.should == ["", nil, nil]
+ /(a|\2b||())*?/.match("aaabbb").to_a.should == ["", nil, nil]
+ /(a|\2b|()|)*?/.match("aaabbb").to_a.should == ["", nil, nil]
+ /(()|a|\3b|())*?/.match("aaabbb").to_a.should == ["", nil, nil, nil]
+ /(a|()|\3b|())*?/.match("aaabbb").to_a.should == ["", nil, nil, nil]
+ /(a|\2b|()|())*?/.match("aaabbb").to_a.should == ["", nil, nil, nil]
+ /(a|\3b|()|())*?/.match("aaabbb").to_a.should == ["", nil, nil, nil]
+ /(a|()|())*?/.match("aaa").to_a.should == ["", nil, nil, nil]
+ /^(()|a|())*?$/.match("aaa").to_a.should == ["aaa", "a", "", nil]
+ end
+end
diff --git a/spec/ruby/language/regexp/encoding_spec.rb b/spec/ruby/language/regexp/encoding_spec.rb
index 1f62244a28..81e845af0c 100644
--- a/spec/ruby/language/regexp/encoding_spec.rb
+++ b/spec/ruby/language/regexp/encoding_spec.rb
@@ -1,21 +1,21 @@
-# -*- encoding: binary -*-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
+# encoding: binary
+require_relative '../../spec_helper'
+require_relative '../fixtures/classes'
describe "Regexps with encoding modifiers" do
it "supports /e (EUC encoding)" do
- match = /./e.match("\303\251".force_encoding(Encoding::EUC_JP))
- match.to_a.should == ["\303\251".force_encoding(Encoding::EUC_JP)]
+ match = /./e.match("\303\251".dup.force_encoding(Encoding::EUC_JP))
+ match.to_a.should == ["\303\251".dup.force_encoding(Encoding::EUC_JP)]
end
it "supports /e (EUC encoding) with interpolation" do
- match = /#{/./}/e.match("\303\251".force_encoding(Encoding::EUC_JP))
- match.to_a.should == ["\303\251".force_encoding(Encoding::EUC_JP)]
+ match = /#{/./}/e.match("\303\251".dup.force_encoding(Encoding::EUC_JP))
+ match.to_a.should == ["\303\251".dup.force_encoding(Encoding::EUC_JP)]
end
it "supports /e (EUC encoding) with interpolation /o" do
- match = /#{/./}/e.match("\303\251".force_encoding(Encoding::EUC_JP))
- match.to_a.should == ["\303\251".force_encoding(Encoding::EUC_JP)]
+ match = /#{/./}/e.match("\303\251".dup.force_encoding(Encoding::EUC_JP))
+ match.to_a.should == ["\303\251".dup.force_encoding(Encoding::EUC_JP)]
end
it 'uses EUC-JP as /e encoding' do
@@ -38,35 +38,47 @@ describe "Regexps with encoding modifiers" do
/#{/./}/n.match("\303\251").to_a.should == ["\303"]
end
+ it "warns when using /n with a match string with non-ASCII characters and an encoding other than ASCII-8BIT" do
+ -> {
+ eval <<~RUBY
+ /./n.match("\303\251".dup.force_encoding('utf-8'))
+ RUBY
+ }.should complain(%r{historical binary regexp match /.../n against UTF-8 string})
+ end
+
it 'uses US-ASCII as /n encoding if all chars are 7-bit' do
/./n.encoding.should == Encoding::US_ASCII
end
- it 'uses ASCII-8BIT as /n encoding if not all chars are 7-bit' do
- /\xFF/n.encoding.should == Encoding::ASCII_8BIT
+ it 'uses BINARY when is not initialized' do
+ Regexp.allocate.encoding.should == Encoding::BINARY
+ end
+
+ it 'uses BINARY as /n encoding if not all chars are 7-bit' do
+ /\xFF/n.encoding.should == Encoding::BINARY
end
it 'preserves US-ASCII as /n encoding through interpolation if all chars are 7-bit' do
/.#{/./}/n.encoding.should == Encoding::US_ASCII
end
- it 'preserves ASCII-8BIT as /n encoding through interpolation if all chars are 7-bit' do
- /\xFF#{/./}/n.encoding.should == Encoding::ASCII_8BIT
+ it 'preserves BINARY as /n encoding through interpolation if all chars are 7-bit' do
+ /\xFF#{/./}/n.encoding.should == Encoding::BINARY
end
it "supports /s (Windows_31J encoding)" do
- match = /./s.match("\303\251".force_encoding(Encoding::Windows_31J))
- match.to_a.should == ["\303".force_encoding(Encoding::Windows_31J)]
+ match = /./s.match("\303\251".dup.force_encoding(Encoding::Windows_31J))
+ match.to_a.should == ["\303".dup.force_encoding(Encoding::Windows_31J)]
end
it "supports /s (Windows_31J encoding) with interpolation" do
- match = /#{/./}/s.match("\303\251".force_encoding(Encoding::Windows_31J))
- match.to_a.should == ["\303".force_encoding(Encoding::Windows_31J)]
+ match = /#{/./}/s.match("\303\251".dup.force_encoding(Encoding::Windows_31J))
+ match.to_a.should == ["\303".dup.force_encoding(Encoding::Windows_31J)]
end
it "supports /s (Windows_31J encoding) with interpolation and /o" do
- match = /#{/./}/s.match("\303\251".force_encoding(Encoding::Windows_31J))
- match.to_a.should == ["\303".force_encoding(Encoding::Windows_31J)]
+ match = /#{/./}/s.match("\303\251".dup.force_encoding(Encoding::Windows_31J))
+ match.to_a.should == ["\303".dup.force_encoding(Encoding::Windows_31J)]
end
it 'uses Windows-31J as /s encoding' do
@@ -78,15 +90,15 @@ describe "Regexps with encoding modifiers" do
end
it "supports /u (UTF8 encoding)" do
- /./u.match("\303\251".force_encoding('utf-8')).to_a.should == ["\u{e9}"]
+ /./u.match("\303\251".dup.force_encoding('utf-8')).to_a.should == ["\u{e9}"]
end
it "supports /u (UTF8 encoding) with interpolation" do
- /#{/./}/u.match("\303\251".force_encoding('utf-8')).to_a.should == ["\u{e9}"]
+ /#{/./}/u.match("\303\251".dup.force_encoding('utf-8')).to_a.should == ["\u{e9}"]
end
it "supports /u (UTF8 encoding) with interpolation and /o" do
- /#{/./}/u.match("\303\251".force_encoding('utf-8')).to_a.should == ["\u{e9}"]
+ /#{/./}/u.match("\303\251".dup.force_encoding('utf-8')).to_a.should == ["\u{e9}"]
end
it 'uses UTF-8 as /u encoding' do
@@ -100,4 +112,41 @@ describe "Regexps with encoding modifiers" do
it "selects last of multiple encoding specifiers" do
/foo/ensuensuens.should == /foo/s
end
+
+ it "raises Encoding::CompatibilityError when trying match against different encodings" do
+ -> { /\A[[:space:]]*\z/.match(" ".encode("UTF-16LE")) }.should.raise(Encoding::CompatibilityError)
+ end
+
+ it "raises Encoding::CompatibilityError when trying match? against different encodings" do
+ -> { /\A[[:space:]]*\z/.match?(" ".encode("UTF-16LE")) }.should.raise(Encoding::CompatibilityError)
+ end
+
+ it "raises Encoding::CompatibilityError when trying =~ against different encodings" do
+ -> { /\A[[:space:]]*\z/ =~ " ".encode("UTF-16LE") }.should.raise(Encoding::CompatibilityError)
+ end
+
+ it "raises Encoding::CompatibilityError when the regexp has a fixed, non-ASCII-compatible encoding" do
+ -> { Regexp.new("".dup.force_encoding("UTF-16LE"), Regexp::FIXEDENCODING) =~ " ".encode("UTF-8") }.should.raise(Encoding::CompatibilityError)
+ end
+
+ it "raises Encoding::CompatibilityError when the regexp has a fixed encoding and the match string has non-ASCII characters" do
+ -> { Regexp.new("".dup.force_encoding("US-ASCII"), Regexp::FIXEDENCODING) =~ "\303\251".dup.force_encoding('UTF-8') }.should.raise(Encoding::CompatibilityError)
+ end
+
+ it "raises ArgumentError when trying to match a broken String" do
+ s = "\x80".dup.force_encoding('UTF-8')
+ -> { s =~ /./ }.should.raise(ArgumentError, "invalid byte sequence in UTF-8")
+ end
+
+ it "computes the Regexp Encoding for each interpolated Regexp instance" do
+ make_regexp = -> str { /#{str}/ }
+
+ r = make_regexp.call("été".dup.force_encoding(Encoding::UTF_8))
+ r.should.fixed_encoding?
+ r.encoding.should == Encoding::UTF_8
+
+ r = make_regexp.call("abc".dup.force_encoding(Encoding::UTF_8))
+ r.should_not.fixed_encoding?
+ r.encoding.should == Encoding::US_ASCII
+ end
end
diff --git a/spec/ruby/language/regexp/escapes_spec.rb b/spec/ruby/language/regexp/escapes_spec.rb
index 50ac22e51e..4a0e611540 100644
--- a/spec/ruby/language/regexp/escapes_spec.rb
+++ b/spec/ruby/language/regexp/escapes_spec.rb
@@ -1,9 +1,11 @@
-# -*- encoding: binary -*-
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
+# encoding: binary
+require_relative '../../spec_helper'
+require_relative '../fixtures/classes'
+# TODO: synchronize with spec/core/regexp/new_spec.rb -
+# escaping is also tested there
describe "Regexps with escape characters" do
- it "they're supported" do
+ it "supports escape sequences" do
/\t/.match("\t").to_a.should == ["\t"] # horizontal tab
/\v/.match("\v").to_a.should == ["\v"] # vertical tab
/\n/.match("\n").to_a.should == ["\n"] # newline
@@ -15,9 +17,7 @@ describe "Regexps with escape characters" do
# \nnn octal char (encoded byte value)
end
- it "support quoting meta-characters via escape sequence" do
- /\\/.match("\\").to_a.should == ["\\"]
- /\//.match("/").to_a.should == ["/"]
+ it "supports quoting meta-characters via escape sequence" do
# parenthesis, etc
/\(/.match("(").to_a.should == ["("]
/\)/.match(")").to_a.should == [")"]
@@ -25,6 +25,8 @@ describe "Regexps with escape characters" do
/\]/.match("]").to_a.should == ["]"]
/\{/.match("{").to_a.should == ["{"]
/\}/.match("}").to_a.should == ["}"]
+ /\</.match("<").to_a.should == ["<"]
+ /\>/.match(">").to_a.should == [">"]
# alternation separator
/\|/.match("|").to_a.should == ["|"]
# quantifiers
@@ -37,23 +39,93 @@ describe "Regexps with escape characters" do
/\$/.match("$").to_a.should == ["$"]
end
+ it "supports quoting meta-characters via escape sequence when used as a terminator" do
+ # parenthesis, etc
+ # %r[[, %r((, etc literals - are forbidden
+ %r(\().match("(").to_a.should == ["("]
+ %r(\)).match(")").to_a.should == [")"]
+ %r)\().match("(").to_a.should == ["("]
+ %r)\)).match(")").to_a.should == [")"]
+
+ %r[\[].match("[").to_a.should == ["["]
+ %r[\]].match("]").to_a.should == ["]"]
+ %r]\[].match("[").to_a.should == ["["]
+ %r]\]].match("]").to_a.should == ["]"]
+
+ %r{\{}.match("{").to_a.should == ["{"]
+ %r{\}}.match("}").to_a.should == ["}"]
+ %r}\{}.match("{").to_a.should == ["{"]
+ %r}\}}.match("}").to_a.should == ["}"]
+
+ %r<\<>.match("<").to_a.should == ["<"]
+ %r<\>>.match(">").to_a.should == [">"]
+ %r>\<>.match("<").to_a.should == ["<"]
+ %r>\>>.match(">").to_a.should == [">"]
+
+ # alternation separator
+ %r|\||.match("|").to_a.should == ["|"]
+ # quantifiers
+ %r?\??.match("?").to_a.should == ["?"]
+ %r.\...match(".").to_a.should == ["."]
+ %r*\**.match("*").to_a.should == ["*"]
+ %r+\++.match("+").to_a.should == ["+"]
+ # line anchors
+ %r^\^^.match("^").to_a.should == ["^"]
+ %r$\$$.match("$").to_a.should == ["$"]
+ end
+
+ it "supports quoting non-meta-characters via escape sequence when used as a terminator" do
+ non_meta_character_terminators = [
+ '!', '"', '#', '%', '&', "'", ',', '-', ':', ';', '@', '_', '`', '/', '=', '~'
+ ]
+
+ non_meta_character_terminators.each do |c|
+ pattern = eval("%r" + c + "\\" + c + c)
+ pattern.match(c).to_a.should == [c]
+ end
+ end
+
+ it "does not change semantics of escaped non-meta-character when used as a terminator" do
+ all_terminators = [*("!".."/"), *(":".."@"), *("[".."`"), *("{".."~")]
+ meta_character_terminators = ["$", "^", "*", "+", ".", "?", "|", "}", ")", ">", "]"]
+ special_cases = ['(', '{', '[', '<', '\\']
+
+ # it should be equivalent to
+ # [ '!', '"', '#', '%', '&', "'", ',', '-', ':', ';', '@', '_', '`', '/', '=', '~' ]
+ non_meta_character_terminators = all_terminators - meta_character_terminators - special_cases
+
+ non_meta_character_terminators.each do |c|
+ pattern = eval("%r" + c + "\\" + c + c)
+ pattern.should == /#{c}/
+ end
+ end
+
+ it "does not change semantics of escaped meta-character when used as a terminator" do
+ meta_character_terminators = ["$", "^", "*", "+", ".", "?", "|", "}", ")", ">", "]"]
+
+ meta_character_terminators.each do |c|
+ pattern = eval("%r" + c + "\\" + c + c)
+ pattern.should == eval("/\\#{c}/")
+ end
+ end
+
it "allows any character to be escaped" do
/\y/.match("y").to_a.should == ["y"]
end
- it "support \\x (hex characters)" do
+ it "supports \\x (hex characters)" do
/\xA/.match("\nxyz").to_a.should == ["\n"]
/\x0A/.match("\n").to_a.should == ["\n"]
- /\xAA/.match("\nA").should be_nil
+ /\xAA/.match("\nA").should == nil
/\x0AA/.match("\nA").to_a.should == ["\nA"]
/\xAG/.match("\nG").to_a.should == ["\nG"]
# Non-matches
- lambda { eval('/\xG/') }.should raise_error(SyntaxError)
+ -> { eval('/\xG/') }.should.raise(SyntaxError)
# \x{7HHHHHHH} wide hexadecimal char (character code point value)
end
- it "support \\c (control characters)" do
+ it "supports \\c (control characters)" do
#/\c \c@\c`/.match("\00\00\00").to_a.should == ["\00\00\00"]
/\c#\cc\cC/.match("\03\03\03").to_a.should == ["\03\03\03"]
/\c'\cG\cg/.match("\a\a\a").to_a.should == ["\a\a\a"]
@@ -64,18 +136,34 @@ describe "Regexps with escape characters" do
/\c,\cL\cl/.match("\f\f\f").to_a.should == ["\f\f\f"]
/\c-\cM\cm/.match("\r\r\r").to_a.should == ["\r\r\r"]
- /\cJ/.match("\r").should be_nil
+ /\cJ/.match("\r").should == nil
# Parsing precedence
- /\cJ+/.match("\n\n").to_a.should == ["\n\n"] # Quantifers apply to entire escape sequence
+ /\cJ+/.match("\n\n").to_a.should == ["\n\n"] # Quantifiers apply to entire escape sequence
/\\cJ/.match("\\cJ").to_a.should == ["\\cJ"]
- lambda { eval('/[abc\x]/') }.should raise_error(SyntaxError) # \x is treated as a escape sequence even inside a character class
+ -> { eval('/[abc\x]/') }.should.raise(SyntaxError) # \x is treated as a escape sequence even inside a character class
# Syntax error
- lambda { eval('/\c/') }.should raise_error(SyntaxError)
+ -> { eval('/\c/') }.should.raise(SyntaxError)
# \cx control char (character code point value)
# \C-x control char (character code point value)
# \M-x meta (x|0x80) (character code point value)
# \M-\C-x meta control char (character code point value)
end
+
+ it "handles three digit octal escapes starting with 0" do
+ /[\000-\b]/.match("\x00")[0].should == "\x00"
+ end
+
+ it "handles control escapes with \\C-x syntax" do
+ /\C-*\C-J\C-j/.match("\n\n\n")[0].should == "\n\n\n"
+ end
+
+ it "supports the \\K keep operator" do
+ /a\Kb/.match("ab")[0].should == "b"
+ end
+
+ it "supports the \\R line break escape" do
+ /\R/.match("\n")[0].should == "\n"
+ end
end
diff --git a/spec/ruby/language/regexp/grouping_spec.rb b/spec/ruby/language/regexp/grouping_spec.rb
index 443cab7ee0..80ad7460da 100644
--- a/spec/ruby/language/regexp/grouping_spec.rb
+++ b/spec/ruby/language/regexp/grouping_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../fixtures/classes'
describe "Regexps with grouping" do
it "support ()" do
@@ -12,7 +12,7 @@ describe "Regexps with grouping" do
end
it "raises a SyntaxError when parentheses aren't balanced" do
- lambda { eval "/(hay(st)ack/" }.should raise_error(SyntaxError)
+ -> { eval "/(hay(st)ack/" }.should.raise(SyntaxError)
end
it "supports (?: ) (non-capturing group)" do
@@ -20,4 +20,44 @@ describe "Regexps with grouping" do
# Parsing precedence
/(?:xdigit:)/.match("xdigit:").to_a.should == ["xdigit:"]
end
+
+ it "group names cannot start with digits or minus" do
+ -> { Regexp.new("(?<1a>a)") }.should.raise(RegexpError)
+ -> { Regexp.new("(?<-a>a)") }.should.raise(RegexpError)
+ end
+
+ it "ignore capture groups in line comments" do
+ /^
+ (a) # there is a capture group on this line
+ b # there is no capture group on this line (not even here)
+ $/x.match("ab").to_a.should == [ "ab", "a" ]
+ end
+
+ it "does not consider # inside a character class as a comment" do
+ # From https://github.com/rubocop/rubocop/blob/39fcf1c568/lib/rubocop/cop/utils/format_string.rb#L18
+ regexp = /
+ % (?<type>%) # line comment
+ | % (?<flags>(?-mix:[ #0+-]|(?-mix:(\d+)\$))*) (?#group comment)
+ (?:
+ (?: (?-mix:(?<width>(?-mix:\d+|(?-mix:\*(?-mix:(\d+)\$)?))))? (?-mix:\.(?<precision>(?-mix:\d+|(?-mix:\*(?-mix:(\d+)\$)?))))? (?-mix:<(?<name>\w+)>)?
+ | (?-mix:(?<width>(?-mix:\d+|(?-mix:\*(?-mix:(\d+)\$)?))))? (?-mix:<(?<name>\w+)>) (?-mix:\.(?<precision>(?-mix:\d+|(?-mix:\*(?-mix:(\d+)\$)?))))?
+ | (?-mix:<(?<name>\w+)>) (?<more_flags>(?-mix:[ #0+-]|(?-mix:(\d+)\$))*) (?-mix:(?<width>(?-mix:\d+|(?-mix:\*(?-mix:(\d+)\$)?))))? (?-mix:\.(?<precision>(?-mix:\d+|(?-mix:\*(?-mix:(\d+)\$)?))))?
+ ) (?-mix:(?<type>[bBdiouxXeEfgGaAcps]))
+ | (?-mix:(?<width>(?-mix:\d+|(?-mix:\*(?-mix:(\d+)\$)?))))? (?-mix:\.(?<precision>(?-mix:\d+|(?-mix:\*(?-mix:(\d+)\$)?))))? (?-mix:\{(?<name>\w+)\})
+ )
+ /x
+ regexp.named_captures.should == {
+ "type" => [1, 13],
+ "flags" => [2],
+ "width" => [3, 6, 11, 14],
+ "precision" => [4, 8, 12, 15],
+ "name" => [5, 7, 9, 16],
+ "more_flags" => [10]
+ }
+ match = regexp.match("%6.3f")
+ match[:width].should == '6'
+ match[:precision].should == '3'
+ match[:type].should == 'f'
+ match.to_a.should == [ "%6.3f", nil, "", "6", "3"] + [nil] * 8 + ["f"] + [nil] * 3
+ end
end
diff --git a/spec/ruby/language/regexp/interpolation_spec.rb b/spec/ruby/language/regexp/interpolation_spec.rb
index 5536c718f1..f771d0a395 100644
--- a/spec/ruby/language/regexp/interpolation_spec.rb
+++ b/spec/ruby/language/regexp/interpolation_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../fixtures/classes'
describe "Regexps with interpolation" do
@@ -36,14 +36,14 @@ describe "Regexps with interpolation" do
it "gives precedence to escape sequences over substitution" do
str = "J"
- /\c#{str}/.to_s.should == '(?-mix:\c#' + '{str})'
+ /\c#{str}/.to_s.should.include?('{str}')
end
it "throws RegexpError for malformed interpolation" do
s = ""
- lambda { /(#{s}/ }.should raise_error(RegexpError)
+ -> { /(#{s}/ }.should.raise(RegexpError)
s = "("
- lambda { /#{s}/ }.should raise_error(RegexpError)
+ -> { /#{s}/ }.should.raise(RegexpError)
end
it "allows interpolation in extended mode" do
diff --git a/spec/ruby/language/regexp/modifiers_spec.rb b/spec/ruby/language/regexp/modifiers_spec.rb
index a7052a941c..c96fbfa983 100644
--- a/spec/ruby/language/regexp/modifiers_spec.rb
+++ b/spec/ruby/language/regexp/modifiers_spec.rb
@@ -1,14 +1,14 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../fixtures/classes'
-describe "Regexps with modifers" do
+describe "Regexps with modifiers" do
it "supports /i (case-insensitive)" do
/foo/i.match("FOO").to_a.should == ["FOO"]
end
it "supports /m (multiline)" do
/foo.bar/m.match("foo\nbar").to_a.should == ["foo\nbar"]
- /foo.bar/.match("foo\nbar").should be_nil
+ /foo.bar/.match("foo\nbar").should == nil
end
it "supports /x (extended syntax)" do
@@ -36,69 +36,67 @@ describe "Regexps with modifers" do
/foo/imox.match("foo").to_a.should == ["foo"]
/foo/imoximox.match("foo").to_a.should == ["foo"]
- lambda { eval('/foo/a') }.should raise_error(SyntaxError)
+ -> { eval('/foo/a') }.should.raise(SyntaxError)
end
- ruby_version_is "2.4" do
- it "supports (?~) (absent operator)" do
- Regexp.new("(?~foo)").match("hello").to_a.should == ["hello"]
- "foo".scan(Regexp.new("(?~foo)")).should == ["fo","o",""]
- end
+ it "supports (?~) (absent operator)" do
+ Regexp.new("(?~foo)").match("hello").to_a.should == ["hello"]
+ "foo".scan(Regexp.new("(?~foo)")).should == ["fo","o",""]
end
it "supports (?imx-imx) (inline modifiers)" do
/(?i)foo/.match("FOO").to_a.should == ["FOO"]
- /foo(?i)/.match("FOO").should be_nil
+ /foo(?i)/.match("FOO").should == nil
# Interaction with /i
- /(?-i)foo/i.match("FOO").should be_nil
+ /(?-i)foo/i.match("FOO").should == nil
/foo(?-i)/i.match("FOO").to_a.should == ["FOO"]
# Multiple uses
/foo (?i)bar (?-i)baz/.match("foo BAR baz").to_a.should == ["foo BAR baz"]
- /foo (?i)bar (?-i)baz/.match("foo BAR BAZ").should be_nil
+ /foo (?i)bar (?-i)baz/.match("foo BAR BAZ").should == nil
/(?m)./.match("\n").to_a.should == ["\n"]
- /.(?m)/.match("\n").should be_nil
+ /.(?m)/.match("\n").should == nil
# Interaction with /m
- /(?-m)./m.match("\n").should be_nil
+ /(?-m)./m.match("\n").should == nil
/.(?-m)/m.match("\n").to_a.should == ["\n"]
# Multiple uses
/. (?m). (?-m)./.match(". \n .").to_a.should == [". \n ."]
- /. (?m). (?-m)./.match(". \n \n").should be_nil
+ /. (?m). (?-m)./.match(". \n \n").should == nil
/(?x) foo /.match("foo").to_a.should == ["foo"]
- / foo (?x)/.match("foo").should be_nil
+ / foo (?x)/.match("foo").should == nil
# Interaction with /x
- /(?-x) foo /x.match("foo").should be_nil
+ /(?-x) foo /x.match("foo").should == nil
/ foo (?-x)/x.match("foo").to_a.should == ["foo"]
# Multiple uses
/( foo )(?x)( bar )(?-x)( baz )/.match(" foo bar baz ").to_a.should == [" foo bar baz ", " foo ", "bar", " baz "]
- /( foo )(?x)( bar )(?-x)( baz )/.match(" foo barbaz").should be_nil
+ /( foo )(?x)( bar )(?-x)( baz )/.match(" foo barbaz").should == nil
# Parsing
- /(?i-i)foo/.match("FOO").should be_nil
+ /(?i-i)foo/.match("FOO").should == nil
/(?ii)foo/.match("FOO").to_a.should == ["FOO"]
/(?-)foo/.match("foo").to_a.should == ["foo"]
- lambda { eval('/(?o)/') }.should raise_error(SyntaxError)
+ -> { eval('/(?o)/') }.should.raise(SyntaxError)
end
it "supports (?imx-imx:expr) (scoped inline modifiers)" do
/foo (?i:bar) baz/.match("foo BAR baz").to_a.should == ["foo BAR baz"]
- /foo (?i:bar) baz/.match("foo BAR BAZ").should be_nil
- /foo (?-i:bar) baz/i.match("foo BAR BAZ").should be_nil
+ /foo (?i:bar) baz/.match("foo BAR BAZ").should == nil
+ /foo (?-i:bar) baz/i.match("foo BAR BAZ").should == nil
/. (?m:.) ./.match(". \n .").to_a.should == [". \n ."]
- /. (?m:.) ./.match(". \n \n").should be_nil
- /. (?-m:.) ./m.match("\n \n \n").should be_nil
+ /. (?m:.) ./.match(". \n \n").should == nil
+ /. (?-m:.) ./m.match("\n \n \n").should == nil
/( foo )(?x: bar )( baz )/.match(" foo bar baz ").to_a.should == [" foo bar baz ", " foo ", " baz "]
- /( foo )(?x: bar )( baz )/.match(" foo barbaz").should be_nil
+ /( foo )(?x: bar )( baz )/.match(" foo barbaz").should == nil
/( foo )(?-x: bar )( baz )/x.match("foo bar baz").to_a.should == ["foo bar baz", "foo", "baz"]
# Parsing
- /(?i-i:foo)/.match("FOO").should be_nil
+ /(?i-i:foo)/.match("FOO").should == nil
/(?ii:foo)/.match("FOO").to_a.should == ["FOO"]
/(?-:)foo/.match("foo").to_a.should == ["foo"]
- lambda { eval('/(?o:)/') }.should raise_error(SyntaxError)
+ -> { eval('/(?o:)/') }.should.raise(SyntaxError)
end
it "supports . with /m" do
@@ -106,7 +104,7 @@ describe "Regexps with modifers" do
/./m.match("\n").to_a.should == ["\n"]
end
- it "supports ASII/Unicode modifiers" do
+ it "supports ASCII/Unicode modifiers" do
eval('/(?a)[[:alpha:]]+/').match("a\u3042").to_a.should == ["a"]
eval('/(?d)[[:alpha:]]+/').match("a\u3042").to_a.should == ["a\u3042"]
eval('/(?u)[[:alpha:]]+/').match("a\u3042").to_a.should == ["a\u3042"]
diff --git a/spec/ruby/language/regexp/repetition_spec.rb b/spec/ruby/language/regexp/repetition_spec.rb
index 2fc8a74a47..f24323de5c 100644
--- a/spec/ruby/language/regexp/repetition_spec.rb
+++ b/spec/ruby/language/regexp/repetition_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../fixtures/classes'
describe "Regexps with repetition" do
it "supports * (0 or more of previous subexpression)" do
@@ -15,7 +15,7 @@ describe "Regexps with repetition" do
it "supports + (1 or more of previous subexpression)" do
/a+/.match("aaa").to_a.should == ["aaa"]
- /a+/.match("bbb").should be_nil
+ /a+/.match("bbb").should == nil
/<.+>/.match("<a>foo</a>").to_a.should == ["<a>foo</a>"] # it is greedy
end
@@ -34,24 +34,105 @@ describe "Regexps with repetition" do
/.([0-9]){3,5}?foo/.match("9876543210foo").to_a.should == ["543210foo", "0"]
end
- ruby_version_is ""..."2.4" do
- it "does not treat {m,n}+ as possessive" do
+ it "does not treat {m,n}+ as possessive" do
+ -> {
@regexp = eval "/foo(A{0,1}+)Abar/"
- @regexp.match("fooAAAbar").to_a.should == ["fooAAAbar", "AA"]
- end
- end
-
- ruby_version_is "2.4" do
- it "does not treat {m,n}+ as possessive" do
- -> {
- @regexp = eval "/foo(A{0,1}+)Abar/"
- }.should complain(/nested repeat operato/)
- @regexp.match("fooAAAbar").to_a.should == ["fooAAAbar", "AA"]
- end
+ }.should complain(/nested repeat operator/)
+ @regexp.match("fooAAAbar").to_a.should == ["fooAAAbar", "AA"]
end
it "supports ? (0 or 1 of previous subexpression)" do
/a?/.match("aaa").to_a.should == ["a"]
/a?/.match("bbb").to_a.should == [""]
end
+
+ it "handles incomplete range quantifiers" do
+ /a{}/.match("a{}")[0].should == "a{}"
+ /a{,}/.match("a{,}")[0].should == "a{,}"
+ /a{1/.match("a{1")[0].should == "a{1"
+ /a{1,2/.match("a{1,2")[0].should == "a{1,2"
+ /a{,5}/.match("aaa")[0].should == "aaa"
+ end
+
+ it "lets us use quantifiers on assertions" do
+ /a^?b/.match("ab")[0].should == "ab"
+ /a$?b/.match("ab")[0].should == "ab"
+ /a\A?b/.match("ab")[0].should == "ab"
+ /a\Z?b/.match("ab")[0].should == "ab"
+ /a\z?b/.match("ab")[0].should == "ab"
+ /a\G?b/.match("ab")[0].should == "ab"
+ /a\b?b/.match("ab")[0].should == "ab"
+ /a\B?b/.match("ab")[0].should == "ab"
+ /a(?=c)?b/.match("ab")[0].should == "ab"
+ /a(?!=b)?b/.match("ab")[0].should == "ab"
+ /a(?<=c)?b/.match("ab")[0].should == "ab"
+ /a(?<!a)?b/.match("ab")[0].should == "ab"
+ end
+
+ it "does not delete optional assertions" do
+ /(?=(a))?/.match("a").to_a.should == [ "", "a" ]
+ end
+
+ it "supports nested quantifiers" do
+ suppress_warning do
+ eval <<-RUBY
+ /a***/.match("aaa")[0].should == "aaa"
+
+ # a+?* should not be reduced, it should be equivalent to (a+?)*
+ # NB: the capture group prevents regex engines from reducing the two quantifiers
+ # https://bugs.ruby-lang.org/issues/17341
+ /a+?*/.match("")[0].should == ""
+ /(a+?)*/.match("")[0].should == ""
+
+ /a+?*/.match("a")[0].should == "a"
+ /(a+?)*/.match("a")[0].should == "a"
+
+ /a+?*/.match("aa")[0].should == "aa"
+ /(a+?)*/.match("aa")[0].should == "aa"
+
+ # a+?+ should not be reduced, it should be equivalent to (a+?)+
+ # https://bugs.ruby-lang.org/issues/17341
+ /a+?+/.match("").should == nil
+ /(a+?)+/.match("").should == nil
+
+ /a+?+/.match("a")[0].should == "a"
+ /(a+?)+/.match("a")[0].should == "a"
+
+ /a+?+/.match("aa")[0].should == "aa"
+ /(a+?)+/.match("aa")[0].should == "aa"
+
+ # both a**? and a+*? should be equivalent to (a+)??
+ # this quantifier would rather match nothing, but if that's not possible,
+ # it will greedily take everything
+ /a**?/.match("")[0].should == ""
+ /(a*)*?/.match("")[0].should == ""
+ /a+*?/.match("")[0].should == ""
+ /(a+)*?/.match("")[0].should == ""
+ /(a+)??/.match("")[0].should == ""
+
+ /a**?/.match("aaa")[0].should == ""
+ /(a*)*?/.match("aaa")[0].should == ""
+ /a+*?/.match("aaa")[0].should == ""
+ /(a+)*?/.match("aaa")[0].should == ""
+ /(a+)??/.match("aaa")[0].should == ""
+
+ /b.**?b/.match("baaabaaab")[0].should == "baaabaaab"
+ /b(.*)*?b/.match("baaabaaab")[0].should == "baaabaaab"
+ /b.+*?b/.match("baaabaaab")[0].should == "baaabaaab"
+ /b(.+)*?b/.match("baaabaaab")[0].should == "baaabaaab"
+ /b(.+)??b/.match("baaabaaab")[0].should == "baaabaaab"
+ RUBY
+ end
+ end
+
+ it "treats ? after {n} quantifier as another quantifier, not as non-greedy marker" do
+ /a{2}?/.match("").to_a.should == [""]
+ end
+
+ it "matches zero-width capture groups in optional iterations of loops" do
+ /()?/.match("").to_a.should == ["", ""]
+ /(a*)?/.match("").to_a.should == ["", ""]
+ /(a*)*/.match("").to_a.should == ["", ""]
+ /(?:a|()){500,1000}/.match("a" * 500).to_a.should == ["a" * 500, ""]
+ end
end
diff --git a/spec/ruby/language/regexp/subexpression_call_spec.rb b/spec/ruby/language/regexp/subexpression_call_spec.rb
new file mode 100644
index 0000000000..16b64cb327
--- /dev/null
+++ b/spec/ruby/language/regexp/subexpression_call_spec.rb
@@ -0,0 +1,50 @@
+require_relative '../../spec_helper'
+require_relative '../fixtures/classes'
+
+describe "Regexps with subexpression calls" do
+ it "allows numeric subexpression calls" do
+ /(a)\g<1>/.match("aa").to_a.should == [ "aa", "a" ]
+ end
+
+ it "treats subexpression calls as distinct from simple back-references" do
+ # Back-references only match a string which is equal to the original captured string.
+ /(?<three_digits>[0-9]{3})-\k<three_digits>/.match("123-123")[0].should == "123-123"
+ /(?<three_digits>[0-9]{3})-\k<three_digits>/.match("123-456").should == nil
+ # However, subexpression calls reuse the previous expression and can match a different
+ # string.
+ /(?<three_digits>[0-9]{3})-\g<three_digits>/.match("123-456")[0].should == "123-456"
+ end
+
+ it "allows recursive subexpression calls" do
+ # This pattern matches well-nested parenthesized expression.
+ parens = /^ (?<parens> (?: \( \g<parens> \) | [^()] )* ) $/x
+ parens.match("((a)(b))c(d)")[0].should == "((a)(b))c(d)"
+ parens.match("((a)(b)c(d)").should == nil
+ end
+
+ it "allows access to back-references from the current level" do
+ # Using \\k<first_char-0> accesses the last value captured in first_char
+ # on the current stack level.
+ mirror = /^ (?<mirror> (?: (?<first_char>.) \g<mirror> \k<first_char-0> )? ) $/x
+ mirror.match("abccba")[0].should == "abccba"
+ mirror.match("abccbd").should == nil
+
+ # OTOH, using \\k<first_char> accesses the last value captured in first_char,
+ # regardless of the stack level. Therefore, it can't be used to implement
+ # the mirror language.
+ broken_mirror = /^ (?<mirror> (?: (?<first_char>.) \g<mirror> \k<first_char> )? ) $/x
+ broken_mirror.match("abccba").should == nil
+ # This matches because the 'c' is captured in first_char and that value is
+ # then used for all subsequent back-references, regardless of nesting.
+ broken_mirror.match("abcccc")[0].should == "abcccc"
+ end
+
+ it "allows + and - in group names and referential constructs that don't use levels, i.e. subexpression calls" do
+ /(?<a+>a)\g<a+>/.match("aa").to_a.should == [ "aa", "a" ]
+ /(?<a+b>a)\g<a+b>/.match("aa").to_a.should == [ "aa", "a" ]
+ /(?<a+1>a)\g<a+1>/.match("aa").to_a.should == [ "aa", "a" ]
+ /(?<a->a)\g<a->/.match("aa").to_a.should == [ "aa", "a" ]
+ /(?<a-b>a)\g<a-b>/.match("aa").to_a.should == [ "aa", "a" ]
+ /(?<a-1>a)\g<a-1>/.match("aa").to_a.should == [ "aa", "a" ]
+ end
+end
diff --git a/spec/ruby/language/regexp_spec.rb b/spec/ruby/language/regexp_spec.rb
index d4b0c81128..1452b01935 100644
--- a/spec/ruby/language/regexp_spec.rb
+++ b/spec/ruby/language/regexp_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../spec_helper'
+require_relative 'fixtures/classes'
describe "Literal Regexps" do
it "matches against $_ (last input) in a conditional if no explicit matchee provided" do
@@ -15,7 +15,11 @@ describe "Literal Regexps" do
end
it "yields a Regexp" do
- /Hello/.should be_kind_of(Regexp)
+ /Hello/.should.is_a?(Regexp)
+ end
+
+ it "is frozen" do
+ /Hello/.should.frozen?
end
it "caches the Regexp object" do
@@ -23,11 +27,11 @@ describe "Literal Regexps" do
2.times do |i|
rs << /foo/
end
- rs[0].should equal(rs[1])
+ rs[0].should.equal?(rs[1])
end
it "throws SyntaxError for malformed literals" do
- lambda { eval('/(/') }.should raise_error(SyntaxError)
+ -> { eval('/(/') }.should.raise(SyntaxError)
end
#############################################################################
@@ -54,22 +58,22 @@ describe "Literal Regexps" do
it "disallows first part of paired delimiters to be used as non-paired delimiters" do
LanguageSpecs.paired_delimiters.each do |p0, p1|
- lambda { eval("%r#{p0} foo #{p0}") }.should raise_error(SyntaxError)
+ -> { eval("%r#{p0} foo #{p0}") }.should.raise(SyntaxError)
end
end
- it "supports non-paired delimiters delimiters with %r" do
+ it "supports non-paired delimiters with %r" do
LanguageSpecs.non_paired_delimiters.each do |c|
eval("%r#{c} foo #{c}").should == / foo /
end
end
it "disallows alphabets as non-paired delimiter with %r" do
- lambda { eval('%ra foo a') }.should raise_error(SyntaxError)
+ -> { eval('%ra foo a') }.should.raise(SyntaxError)
end
it "disallows spaces after %r and delimiter" do
- lambda { eval('%r !foo!') }.should raise_error(SyntaxError)
+ -> { eval('%r !foo!') }.should.raise(SyntaxError)
end
it "allows unescaped / to be used with %r" do
@@ -85,19 +89,18 @@ describe "Literal Regexps" do
# Basic matching
/./.match("foo").to_a.should == ["f"]
# Basic non-matching
- /./.match("").should be_nil
- /./.match("\n").should be_nil
+ /./.match("").should == nil
+ /./.match("\n").should == nil
/./.match("\0").to_a.should == ["\0"]
end
-
it "supports | (alternations)" do
/a|b/.match("a").to_a.should == ["a"]
end
it "supports (?> ) (embedded subexpression)" do
/(?>foo)(?>bar)/.match("foobar").to_a.should == ["foobar"]
- /(?>foo*)obar/.match("foooooooobar").should be_nil # it is possesive
+ /(?>foo*)obar/.match("foooooooobar").should == nil # it is possessive
end
it "supports (?# )" do
@@ -109,6 +112,13 @@ describe "Literal Regexps" do
/foo.(?<=\d)/.match("fooA foo1").to_a.should == ["foo1"]
end
+ ruby_bug "#13671", ""..."4.0" do # https://bugs.ruby-lang.org/issues/13671
+ it "handles a lookbehind with ss characters" do
+ r = Regexp.new("(?<!dss)", Regexp::IGNORECASE)
+ r.should =~ "✨"
+ end
+ end
+
it "supports (?<! ) (negative lookbehind)" do
/foo.(?<!\d)/.match("foo1 fooA").to_a.should == ["fooA"]
end
@@ -125,9 +135,9 @@ describe "Literal Regexps" do
it "supports possessive quantifiers" do
/fooA++bar/.match("fooAAAbar").to_a.should == ["fooAAAbar"]
- /fooA++Abar/.match("fooAAAbar").should be_nil
- /fooA?+Abar/.match("fooAAAbar").should be_nil
- /fooA*+Abar/.match("fooAAAbar").should be_nil
+ /fooA++Abar/.match("fooAAAbar").should == nil
+ /fooA?+Abar/.match("fooAAAbar").should == nil
+ /fooA*+Abar/.match("fooAAAbar").should == nil
end
it "supports conditional regular expressions with positional capture groups" do
@@ -147,4 +157,11 @@ describe "Literal Regexps" do
pattern.should_not =~ 'fooF'
pattern.should_not =~ 'T'
end
+
+ it "support handling unicode 9.0 characters with POSIX bracket expressions" do
+ char_lowercase = "\u{104D8}" # OSAGE SMALL LETTER A
+ /[[:lower:]]/.match(char_lowercase).to_s.should == char_lowercase
+ char_uppercase = "\u{104B0}" # OSAGE CAPITAL LETTER A
+ /[[:upper:]]/.match(char_uppercase).to_s.should == char_uppercase
+ end
end
diff --git a/spec/ruby/language/rescue_spec.rb b/spec/ruby/language/rescue_spec.rb
index 281bb8fde8..cf16d8f6f8 100644
--- a/spec/ruby/language/rescue_spec.rb
+++ b/spec/ruby/language/rescue_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/rescue', __FILE__)
+require_relative '../spec_helper'
+require_relative 'fixtures/rescue'
class SpecificExampleException < StandardError
end
@@ -23,16 +23,154 @@ describe "The rescue keyword" do
end.should == :caught
end
- it "can capture the raised exception in a local variable" do
+ describe 'can capture the raised exception' do
+ before :all do
+ require_relative 'fixtures/rescue_captures'
+ end
+
+ it 'in a local variable' do
+ RescueSpecs::LocalVariableCaptor.should_capture_exception
+ end
+
+ it 'in a class variable' do
+ RescueSpecs::ClassVariableCaptor.should_capture_exception
+ end
+
+ it 'in a constant' do
+ RescueSpecs::ConstantCaptor.should_capture_exception
+ end
+
+ it 'in a global variable' do
+ RescueSpecs::GlobalVariableCaptor.should_capture_exception
+ end
+
+ it 'in an instance variable' do
+ RescueSpecs::InstanceVariableCaptor.should_capture_exception
+ end
+
+ it 'using a safely navigated setter method' do
+ RescueSpecs::SafeNavigationSetterCaptor.should_capture_exception
+ end
+
+ it 'using a safely navigated setter method on a nil target' do
+ target = nil
+ begin
+ raise SpecificExampleException, "Raising this to be handled below"
+ rescue SpecificExampleException => target&.captured_error
+ :caught
+ end.should == :caught
+ target.should == nil
+ end
+
+ it 'using a setter method' do
+ RescueSpecs::SetterCaptor.should_capture_exception
+ end
+
+ it 'using a square brackets setter' do
+ RescueSpecs::SquareBracketsCaptor.should_capture_exception
+ end
+ end
+
+ describe 'capturing in a local variable (that defines it)' do
+ it 'captures successfully in a method' do
+ ScratchPad.record []
+
+ def a
+ raise "message"
+ rescue => e
+ ScratchPad << e.message
+ end
+
+ a
+ ScratchPad.recorded.should == ["message"]
+ end
+
+ it 'captures successfully in a block' do
+ ScratchPad.record []
+
+ p = proc do
+ raise "message"
+ rescue => e
+ ScratchPad << e.message
+ end
+
+ p.call
+ ScratchPad.recorded.should == ["message"]
+ end
+
+ it 'captures successfully in a class' do
+ ScratchPad.record []
+
+ class RescueSpecs::C
+ raise "message"
+ rescue => e
+ ScratchPad << e.message
+ end
+
+ ScratchPad.recorded.should == ["message"]
+ end
+
+ it 'captures successfully in a module' do
+ ScratchPad.record []
+
+ module RescueSpecs::M
+ raise "message"
+ rescue => e
+ ScratchPad << e.message
+ end
+
+ ScratchPad.recorded.should == ["message"]
+ end
+
+ it 'captures sucpcessfully in a singleton class' do
+ ScratchPad.record []
+
+ class << Object.new
+ raise "message"
+ rescue => e
+ ScratchPad << e.message
+ end
+
+ ScratchPad.recorded.should == ["message"]
+ end
+
+ it 'captures successfully at the top-level' do
+ ScratchPad.record []
+ loaded_features = $".dup
+ begin
+ require_relative 'fixtures/rescue/top_level'
+
+ ScratchPad.recorded.should == ["message"]
+ ensure
+ $".replace loaded_features
+ end
+ end
+ end
+
+ it "returns value from `rescue` if an exception was raised" do
begin
- raise SpecificExampleException, "some text"
- rescue SpecificExampleException => e
- e.message.should == "some text"
+ raise
+ rescue
+ :caught
+ end.should == :caught
+ end
+
+ it "returns value from `else` section if no exceptions were raised" do
+ result = begin
+ :begin
+ rescue
+ :rescue
+ else
+ :else
+ ensure
+ :ensure
end
+
+ result.should == :else
end
it "can rescue multiple raised exceptions with a single rescue block" do
- [lambda{raise ArbitraryException}, lambda{raise SpecificExampleException}].map do |block|
+ [->{raise ArbitraryException}, ->{raise SpecificExampleException}].map do |block|
begin
block.call
rescue SpecificExampleException, ArbitraryException
@@ -48,9 +186,9 @@ describe "The rescue keyword" do
rescue *exception_list
caught_it = true
end
- caught_it.should be_true
+ caught_it.should == true
caught = []
- [lambda{raise ArbitraryException}, lambda{raise SpecificExampleException}].each do |block|
+ [->{raise ArbitraryException}, ->{raise SpecificExampleException}].each do |block|
begin
block.call
rescue *exception_list
@@ -59,8 +197,20 @@ describe "The rescue keyword" do
end
caught.size.should == 2
exception_list.each do |exception_class|
- caught.map{|e| e.class}.should include(exception_class)
+ caught.map{|e| e.class}.should.include?(exception_class)
+ end
+ end
+
+ it "converts the splatted list of exceptions using #to_a" do
+ exceptions = mock("to_a")
+ exceptions.should_receive(:to_a).and_return(exception_list)
+ caught_it = false
+ begin
+ raise SpecificExampleException, "not important"
+ rescue *exceptions
+ caught_it = true
end
+ caught_it.should == true
end
it "can combine a splatted list of exceptions with a literal list of exceptions" do
@@ -70,9 +220,9 @@ describe "The rescue keyword" do
rescue ArbitraryException, *exception_list
caught_it = true
end
- caught_it.should be_true
+ caught_it.should == true
caught = []
- [lambda{raise ArbitraryException}, lambda{raise SpecificExampleException}].each do |block|
+ [->{raise ArbitraryException}, ->{raise SpecificExampleException}].each do |block|
begin
block.call
rescue ArbitraryException, *exception_list
@@ -81,17 +231,56 @@ describe "The rescue keyword" do
end
caught.size.should == 2
exception_list.each do |exception_class|
- caught.map{|e| e.class}.should include(exception_class)
+ caught.map{|e| e.class}.should.include?(exception_class)
end
end
it "will only rescue the specified exceptions when doing a splat rescue" do
- lambda do
+ -> do
begin
raise OtherCustomException, "not rescued!"
rescue *exception_list
end
- end.should raise_error(OtherCustomException)
+ end.should.raise(OtherCustomException)
+ end
+
+ it "can rescue different types of exceptions in different ways" do
+ begin
+ raise Exception
+ rescue RuntimeError
+ rescue StandardError
+ rescue Exception
+ ScratchPad << :exception
+ end
+
+ ScratchPad.recorded.should == [:exception]
+ end
+
+ it "rescues exception within the first suitable section in order of declaration" do
+ begin
+ raise StandardError
+ rescue RuntimeError
+ ScratchPad << :runtime_error
+ rescue StandardError
+ ScratchPad << :standard_error
+ rescue Exception
+ ScratchPad << :exception
+ end
+
+ ScratchPad.recorded.should == [:standard_error]
+ end
+
+ it "rescues the exception in the deepest rescue block declared to handle the appropriate exception type" do
+ begin
+ begin
+ RescueSpecs.raise_standard_error
+ rescue ArgumentError
+ end
+ rescue StandardError => e
+ e.backtrace.first.should =~ /:in [`'](?:RescueSpecs\.)?raise_standard_error'/
+ else
+ fail("exception wasn't handled by the correct rescue block")
+ end
end
it "will execute an else block only if no exceptions were raised" do
@@ -147,6 +336,18 @@ describe "The rescue keyword" do
ScratchPad.recorded.should == [:one, :else_ran, :ensure_ran, :outside_begin]
end
+ it "raises SyntaxError when else is used without rescue and ensure" do
+ -> {
+ eval <<-ruby
+ begin
+ ScratchPad << :begin
+ else
+ ScratchPad << :else
+ end
+ ruby
+ }.should.raise(SyntaxError, /else without rescue is useless/)
+ end
+
it "will not execute an else block if an exception was raised" do
result = begin
ScratchPad << :one
@@ -203,7 +404,7 @@ describe "The rescue keyword" do
end
it "will not rescue errors raised in an else block in the rescue block above it" do
- lambda do
+ -> do
begin
ScratchPad << :one
rescue Exception
@@ -212,7 +413,7 @@ describe "The rescue keyword" do
ScratchPad << :two
raise SpecificExampleException, "an error from else"
end
- end.should raise_error(SpecificExampleException)
+ end.should.raise(SpecificExampleException)
ScratchPad.recorded.should == [:one, :two]
end
@@ -223,14 +424,31 @@ describe "The rescue keyword" do
a.should == 'ac'
end
- it "without classes will not rescue Exception" do
- lambda do
+ context "without rescue expression" do
+ it "will rescue only StandardError and its subclasses" do
begin
- raise Exception
+ raise StandardError
rescue
- 'Exception wrongly rescued'
+ ScratchPad << :caught
+ end
+
+ ScratchPad.recorded.should == [:caught]
+ end
+
+ it "will not rescue exceptions except StandardError" do
+ [ Exception.new, NoMemoryError.new, ScriptError.new, SecurityError.new,
+ SignalException.new('INT'), SystemExit.new, SystemStackError.new
+ ].each do |exception|
+ -> {
+ begin
+ raise exception
+ rescue
+ ScratchPad << :caught
+ end
+ }.should.raise(exception.class)
end
- end.should raise_error(Exception)
+ ScratchPad.recorded.should == []
+ end
end
it "uses === to compare against rescued classes" do
@@ -253,34 +471,46 @@ describe "The rescue keyword" do
it "only accepts Module or Class in rescue clauses" do
rescuer = 42
- lambda {
+ -> {
begin
raise "error"
rescue rescuer
end
- }.should raise_error(TypeError) { |e|
+ }.should.raise(TypeError) { |e|
e.message.should =~ /class or module required for rescue clause/
}
end
it "only accepts Module or Class in splatted rescue clauses" do
rescuer = [42]
- lambda {
+ -> {
begin
raise "error"
rescue *rescuer
end
- }.should raise_error(TypeError) { |e|
+ }.should.raise(TypeError) { |e|
e.message.should =~ /class or module required for rescue clause/
}
end
it "evaluates rescue expressions only when needed" do
- invalid_rescuer = Object.new
begin
- :foo
- rescue rescuer
- end.should == :foo
+ ScratchPad << :foo
+ rescue -> { ScratchPad << :bar; StandardError }.call
+ end
+
+ ScratchPad.recorded.should == [:foo]
+ end
+
+ it "suppresses exception from block when raises one from rescue expression" do
+ -> {
+ begin
+ raise "from block"
+ rescue (raise "from rescue expression")
+ end
+ }.should.raise(RuntimeError, "from rescue expression") { |e|
+ e.cause.message.should == "from block"
+ }
end
it "should splat the handling Error classes" do
@@ -291,10 +521,96 @@ describe "The rescue keyword" do
end.should == :expected
end
- ruby_version_is "2.4" do
- it "allows 'rescue' in method arguments" do
- two = eval '1.+ (raise("Error") rescue 1)'
- two.should == 2
+ it "allows rescue in class" do
+ eval <<-ruby
+ class RescueInClassExample
+ raise SpecificExampleException
+ rescue SpecificExampleException
+ ScratchPad << :caught
+ end
+ ruby
+
+ ScratchPad.recorded.should == [:caught]
+ end
+
+ it "does not allow rescue in {} block" do
+ -> {
+ eval <<-ruby
+ lambda {
+ raise SpecificExampleException
+ rescue SpecificExampleException
+ :caught
+ }
+ ruby
+ }.should.raise(SyntaxError)
+ end
+
+ it "allows rescue in 'do end' block" do
+ lambda = eval <<-ruby
+ lambda do
+ raise SpecificExampleException
+ rescue SpecificExampleException
+ ScratchPad << :caught
+ end.call
+ ruby
+
+ ScratchPad.recorded.should == [:caught]
+ end
+
+ it "allows 'rescue' in method arguments" do
+ two = eval '1.+ (raise("Error") rescue 1)'
+ two.should == 2
+ end
+
+ it "requires the 'rescue' in method arguments to be wrapped in parens" do
+ -> { eval '1.+(1 rescue 1)' }.should.raise(SyntaxError)
+ eval('1.+((1 rescue 1))').should == 2
+ end
+
+ ruby_version_is "3.4" do
+ it "does not introduce extra backtrace entries" do
+ def foo
+ begin
+ raise "oops"
+ rescue
+ return caller(0, 2)
+ end
+ end
+ line = __LINE__
+ foo[0].should =~ /#{__FILE__}:#{line-3}:in 'foo'/
+ foo[1].should =~ /#{__FILE__}:#{line+2}:in 'block/
+ end
+ end
+
+ describe "inline form" do
+ it "can be inlined" do
+ a = 1/0 rescue 1
+ a.should == 1
+ end
+
+ it "doesn't except rescue expression" do
+ -> {
+ eval <<-ruby
+ a = 1 rescue RuntimeError 2
+ ruby
+ }.should.raise(SyntaxError)
+ end
+
+ it "rescues only StandardError and its subclasses" do
+ a = raise(StandardError) rescue 1
+ a.should == 1
+
+ -> {
+ a = raise(Exception) rescue 1
+ }.should.raise(Exception)
+ end
+
+ it "rescues with multiple assignment" do
+
+ a, b = raise rescue [1, 2]
+
+ a.should == 1
+ b.should == 2
end
end
end
diff --git a/spec/ruby/language/reserved_keywords.rb b/spec/ruby/language/reserved_keywords.rb
new file mode 100644
index 0000000000..bd1a55feec
--- /dev/null
+++ b/spec/ruby/language/reserved_keywords.rb
@@ -0,0 +1,149 @@
+require_relative '../spec_helper'
+
+describe "Ruby's reserved keywords" do
+ # Copied from https://github.com/ruby/ruby/blob/master/defs/keywords
+ keywords = %w[
+ alias
+ and
+ begin
+ BEGIN
+ break
+ case
+ class
+ def
+ defined?
+ do
+ else
+ elsif
+ end
+ END
+ ensure
+ false
+ for
+ if
+ in
+ module
+ next
+ nil
+ not
+ or
+ redo
+ rescue
+ retry
+ return
+ self
+ super
+ then
+ true
+ undef
+ unless
+ until
+ when
+ while
+ yield
+ __ENCODING__
+ __FILE__
+ __LINE__
+ ]
+
+ keywords.each do |name|
+ describe "keyword '#{name}'" do
+ it "can't be used as local variable name" do
+ -> { eval(<<~RUBY) }.should.raise(SyntaxError)
+ #{name} = :local_variable
+ RUBY
+ end
+
+ if name == "defined?"
+ it "can't be used as an instance variable name" do
+ -> { eval(<<~RUBY) }.should.raise(SyntaxError)
+ @#{name} = :instance_variable
+ RUBY
+ end
+
+ it "can't be used as a class variable name" do
+ -> { eval(<<~RUBY) }.should.raise(SyntaxError)
+ class C
+ @@#{name} = :class_variable
+ end
+ RUBY
+ end
+
+ it "can't be used as a global variable name" do
+ -> { eval(<<~RUBY) }.should.raise(SyntaxError)
+ $#{name} = :global_variable
+ RUBY
+ end
+ else
+ it "can be used as an instance variable name" do
+ result = eval <<~RUBY
+ @#{name} = :instance_variable
+ @#{name}
+ RUBY
+
+ result.should == :instance_variable
+ end
+
+ it "can be used as a class variable name" do
+ result = eval <<~RUBY
+ class C
+ @@#{name} = :class_variable
+ @@#{name}
+ end
+ RUBY
+
+ result.should == :class_variable
+ end
+
+ it "can be used as a global variable name" do
+ result = eval <<~RUBY
+ $#{name} = :global_variable
+ $#{name}
+ RUBY
+
+ result.should == :global_variable
+ end
+ end
+
+ it "can't be used as a positional parameter name" do
+ -> { eval(<<~RUBY) }.should.raise(SyntaxError)
+ def x(#{name}); end
+ RUBY
+ end
+
+ invalid_kw_param_names = ["BEGIN","END","defined?"]
+
+ if invalid_kw_param_names.include?(name)
+ it "can't be used a keyword parameter name" do
+ -> { eval(<<~RUBY) }.should.raise(SyntaxError)
+ def m(#{name}:); end
+ RUBY
+ end
+ else
+ it "can be used a keyword parameter name" do
+ result = instance_eval <<~RUBY
+ def m(#{name}:)
+ binding.local_variable_get(:#{name})
+ end
+
+ m(#{name}: :argument)
+ RUBY
+
+ result.should == :argument
+ end
+ end
+
+ it "can be used as a method name" do
+ result = instance_eval <<~RUBY
+ def #{name}
+ :method_return_value
+ end
+
+ send(:#{name})
+ RUBY
+
+ result.should == :method_return_value
+ end
+ end
+ end
+end
diff --git a/spec/ruby/language/retry_spec.rb b/spec/ruby/language/retry_spec.rb
index 96e69b763a..39e58b7b5d 100644
--- a/spec/ruby/language/retry_spec.rb
+++ b/spec/ruby/language/retry_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../spec_helper', __FILE__)
+require_relative '../spec_helper'
describe "The retry statement" do
it "re-executes the closest block" do
@@ -31,8 +31,11 @@ describe "The retry statement" do
results.should == [1, 2, 3, 1, 2, 4, 5, 6, 4, 5]
end
- it "raises a SyntaxError when used outside of a begin statement" do
- lambda { eval 'retry' }.should raise_error(SyntaxError)
+ it "raises a SyntaxError when used outside of a rescue statement" do
+ -> { eval 'retry' }.should.raise(SyntaxError)
+ -> { eval 'begin; retry; end' }.should.raise(SyntaxError)
+ -> { eval 'def m; retry; end' }.should.raise(SyntaxError)
+ -> { eval 'module RetrySpecs; retry; end' }.should.raise(SyntaxError)
end
end
diff --git a/spec/ruby/language/return_spec.rb b/spec/ruby/language/return_spec.rb
index 6a98fa6d12..36a3cba4d7 100644
--- a/spec/ruby/language/return_spec.rb
+++ b/spec/ruby/language/return_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/return', __FILE__)
+require_relative '../spec_helper'
+require_relative 'fixtures/return'
describe "The return keyword" do
it "returns any object directly" do
@@ -19,7 +19,7 @@ describe "The return keyword" do
it "returns nil by default" do
def r; return; end
- r().should be_nil
+ r().should == nil
end
describe "in a Thread" do
@@ -31,7 +31,7 @@ describe "The return keyword" do
e
end
}
- t.value.should be_an_instance_of(LocalJumpError)
+ t.value.should.instance_of?(LocalJumpError)
end
end
@@ -159,7 +159,7 @@ describe "The return keyword" do
end
it "executes the ensure clause when begin/ensure are inside a lambda" do
- lambda do
+ -> do
begin
return
ensure
@@ -176,15 +176,15 @@ describe "The return keyword" do
end
it "causes lambda to return nil if invoked without any arguments" do
- lambda { return; 456 }.call.should be_nil
+ -> { return; 456 }.call.should == nil
end
it "causes lambda to return nil if invoked with an empty expression" do
- lambda { return (); 456 }.call.should be_nil
+ -> { return (); 456 }.call.should == nil
end
it "causes lambda to return the value passed to return" do
- lambda { return 123; 456 }.call.should == 123
+ -> { return 123; 456 }.call.should == 123
end
it "causes the method that lexically encloses the block to return" do
@@ -229,7 +229,7 @@ describe "The return keyword" do
def f
1.times { 1.times {return true}; false}; false
end
- f.should be_true
+ f.should == true
end
end
@@ -250,216 +250,240 @@ describe "The return keyword" do
end
end
- ruby_version_is '2.4.2' do
- describe "at top level" do
- before :each do
- @filename = tmp("top_return.rb")
- ScratchPad.record []
- end
+ describe "at top level" do
+ before :each do
+ @filename = tmp("top_return.rb")
+ ScratchPad.record []
+ end
- after do
- rm_r @filename
- end
+ after do
+ rm_r @filename
+ end
- it "stops file execution" do
- ruby_exe(<<-END_OF_CODE).should == "before return\n"
- puts "before return"
- return
+ it "stops file execution" do
+ ruby_exe(<<-END_OF_CODE).should == "before return\n"
+ puts "before return"
+ return
+
+ puts "after return"
+ END_OF_CODE
+
+ $?.exitstatus.should == 0
+ end
+
+ describe "within if" do
+ it "is allowed" do
+ File.write(@filename, <<-END_OF_CODE)
+ ScratchPad << "before if"
+ if true
+ return
+ end
- puts "after return"
+ ScratchPad << "after if"
END_OF_CODE
- $?.exitstatus.should == 0
+ load @filename
+ ScratchPad.recorded.should == ["before if"]
end
+ end
- describe "within if" do
- it "is allowed" do
- File.write(@filename, <<-END_OF_CODE)
- ScratchPad << "before if"
- if true
- return
- end
+ describe "within while loop" do
+ it "is allowed" do
+ File.write(@filename, <<-END_OF_CODE)
+ ScratchPad << "before while"
+ while true
+ return
+ end
- ScratchPad << "after if"
- END_OF_CODE
+ ScratchPad << "after while"
+ END_OF_CODE
- load @filename
- ScratchPad.recorded.should == ["before if"]
- end
+ load @filename
+ ScratchPad.recorded.should == ["before while"]
end
+ end
- describe "within while loop" do
- it "is allowed" do
- File.write(@filename, <<-END_OF_CODE)
- ScratchPad << "before while"
- while true
- return
- end
+ describe "within a begin" do
+ it "is allowed in begin block" do
+ File.write(@filename, <<-END_OF_CODE)
+ ScratchPad << "before begin"
+ begin
+ return
+ end
- ScratchPad << "after while"
- END_OF_CODE
+ ScratchPad << "after begin"
+ END_OF_CODE
- load @filename
- ScratchPad.recorded.should == ["before while"]
- end
+ load @filename
+ ScratchPad.recorded.should == ["before begin"]
end
- describe "within a begin" do
- it "is allowed in begin block" do
- File.write(@filename, <<-END_OF_CODE)
- ScratchPad << "before begin"
- begin
- return
- end
+ it "is allowed in ensure block" do
+ File.write(@filename, <<-END_OF_CODE)
+ ScratchPad << "before begin"
+ begin
+ ensure
+ return
+ end
- ScratchPad << "after begin"
- END_OF_CODE
+ ScratchPad << "after begin"
+ END_OF_CODE
- load @filename
- ScratchPad.recorded.should == ["before begin"]
- end
+ load @filename
+ ScratchPad.recorded.should == ["before begin"]
+ end
- it "is allowed in ensure block" do
- File.write(@filename, <<-END_OF_CODE)
- ScratchPad << "before begin"
- begin
- ensure
- return
- end
+ it "is allowed in rescue block" do
+ File.write(@filename, <<-END_OF_CODE)
+ ScratchPad << "before begin"
+ begin
+ raise
+ rescue RuntimeError
+ return
+ end
- ScratchPad << "after begin"
- END_OF_CODE
+ ScratchPad << "after begin"
+ END_OF_CODE
- load @filename
- ScratchPad.recorded.should == ["before begin"]
- end
+ load @filename
+ ScratchPad.recorded.should == ["before begin"]
+ end
- it "is allowed in rescue block" do
- File.write(@filename, <<-END_OF_CODE)
- ScratchPad << "before begin"
- begin
- raise
- rescue RuntimeError
- return
- end
+ it "fires ensure block before returning" do
+ ruby_exe(<<-END_OF_CODE).should == "within ensure\n"
+ begin
+ return
+ ensure
+ puts "within ensure"
+ end
- ScratchPad << "after begin"
- END_OF_CODE
+ puts "after begin"
+ END_OF_CODE
+ end
- load @filename
- ScratchPad.recorded.should == ["before begin"]
- end
+ it "fires ensure block before returning while loads file" do
+ File.write(@filename, <<-END_OF_CODE)
+ ScratchPad << "before begin"
+ begin
+ return
+ ensure
+ ScratchPad << "within ensure"
+ end
- it "fires ensure block before returning" do
- ruby_exe(<<-END_OF_CODE).should == "within ensure\n"
- begin
- return
- ensure
- puts "within ensure"
- end
+ ScratchPad << "after begin"
+ END_OF_CODE
- puts "after begin"
- END_OF_CODE
- end
+ load @filename
+ ScratchPad.recorded.should == ["before begin", "within ensure"]
+ end
- ruby_bug "#14061", "2.4"..."2.6" do
- it "fires ensure block before returning while loads file" do
- File.write(@filename, <<-END_OF_CODE)
- ScratchPad << "before begin"
- begin
- return
- ensure
- ScratchPad << "within ensure"
- end
-
- ScratchPad << "after begin"
- END_OF_CODE
-
- load @filename
- ScratchPad.recorded.should == ["before begin", "within ensure"]
+ it "swallows exception if returns in ensure block" do
+ File.write(@filename, <<-END_OF_CODE)
+ begin
+ raise
+ ensure
+ ScratchPad << "before return"
+ return
end
- end
+ END_OF_CODE
- it "swallows exception if returns in ensure block" do
- File.write(@filename, <<-END_OF_CODE)
- begin
- raise
- ensure
- ScratchPad << "before return"
- return
- end
- END_OF_CODE
-
- load @filename
- ScratchPad.recorded.should == ["before return"]
- end
+ load @filename
+ ScratchPad.recorded.should == ["before return"]
end
+ end
- describe "within a block" do
- it "is allowed" do
- File.write(@filename, <<-END_OF_CODE)
- ScratchPad << "before call"
- proc { return }.call
+ describe "within a block" do
+ it "is allowed" do
+ File.write(@filename, <<-END_OF_CODE)
+ ScratchPad << "before call"
+ proc { return }.call
- ScratchPad << "after call"
- END_OF_CODE
+ ScratchPad << "after call"
+ END_OF_CODE
- load @filename
- ScratchPad.recorded.should == ["before call"]
- end
+ load @filename
+ ScratchPad.recorded.should == ["before call"]
end
+ end
- describe "within a class" do
- it "is allowed" do
- File.write(@filename, <<-END_OF_CODE)
- class A
- ScratchPad << "before return"
- return
+ describe "within a class" do
+ it "raises a SyntaxError" do
+ File.write(@filename, <<-END_OF_CODE)
+ class ReturnSpecs::A
+ ScratchPad << "before return"
+ return
- ScratchPad << "after return"
- end
- END_OF_CODE
+ ScratchPad << "after return"
+ end
+ END_OF_CODE
- load @filename
- ScratchPad.recorded.should == ["before return"]
- end
+ -> { load @filename }.should.raise(SyntaxError)
end
+ end
- describe "file loading" do
- it "stops file loading and execution" do
- File.write(@filename, <<-END_OF_CODE)
+ describe "within a block within a class" do
+ it "is not allowed" do
+ File.write(@filename, <<-END_OF_CODE)
+ class ReturnSpecs::A
ScratchPad << "before return"
- return
+ 1.times { return }
ScratchPad << "after return"
- END_OF_CODE
+ end
+ END_OF_CODE
- load @filename
- ScratchPad.recorded.should == ["before return"]
- end
+ -> { load @filename }.should.raise(LocalJumpError)
end
+ end
- describe "file requiring" do
- it "stops file loading and execution" do
- File.write(@filename, <<-END_OF_CODE)
- ScratchPad << "before return"
+ describe "within BEGIN" do
+ it "is allowed" do
+ File.write(@filename, <<-END_OF_CODE)
+ BEGIN {
+ ScratchPad << "before call"
return
- ScratchPad << "after return"
- END_OF_CODE
+ ScratchPad << "after call"
+ }
+ END_OF_CODE
- require @filename
- ScratchPad.recorded.should == ["before return"]
- end
+ load @filename
+ ScratchPad.recorded.should == ["before call"]
end
+ end
- describe "return with argument" do
- # https://bugs.ruby-lang.org/issues/14062
- it "does not affect exit status" do
- ruby_exe(<<-END_OF_CODE).should == ""
- return 10
- END_OF_CODE
+ describe "file loading" do
+ it "stops file loading and execution" do
+ File.write(@filename, <<-END_OF_CODE)
+ ScratchPad << "before return"
+ return
+ ScratchPad << "after return"
+ END_OF_CODE
- $?.exitstatus.should == 0
- end
+ load @filename
+ ScratchPad.recorded.should == ["before return"]
+ end
+ end
+
+ describe "file requiring" do
+ it "stops file loading and execution" do
+ File.write(@filename, <<-END_OF_CODE)
+ ScratchPad << "before return"
+ return
+ ScratchPad << "after return"
+ END_OF_CODE
+
+ require @filename
+ ScratchPad.recorded.should == ["before return"]
+ end
+ end
+
+ describe "return with argument" do
+ it "warns but does not affect exit status" do
+ err = ruby_exe(<<-END_OF_CODE, args: "2>&1")
+ return 10
+ END_OF_CODE
+ $?.exitstatus.should == 0
+
+ err.should =~ /warning: argument of top-level return is ignored/
end
end
end
diff --git a/spec/ruby/language/safe_navigator_spec.rb b/spec/ruby/language/safe_navigator_spec.rb
index a8b29dc5a3..e8b429631d 100644
--- a/spec/ruby/language/safe_navigator_spec.rb
+++ b/spec/ruby/language/safe_navigator_spec.rb
@@ -1,101 +1,147 @@
-require File.expand_path("../../spec_helper", __FILE__)
+require_relative '../spec_helper'
-ruby_version_is "2.3" do
- describe "Safe navigator" do
- it "requires a method name to be provided" do
- lambda { eval("obj&. {}") }.should raise_error(SyntaxError)
+describe "Safe navigator" do
+ it "requires a method name to be provided" do
+ -> { eval("obj&. {}") }.should.raise(SyntaxError)
+ end
+
+ context "when context is nil" do
+ it "always returns nil" do
+ nil&.unknown.should == nil
+ [][10]&.unknown.should == nil
end
- context "when context is nil" do
- it "always returns nil" do
- eval("nil&.unknown").should == nil
- eval("[][10]&.unknown").should == nil
- end
+ it "can be chained" do
+ nil&.one&.two&.three.should == nil
+ end
- it "can be chained" do
- eval("nil&.one&.two&.three").should == nil
- end
+ it "doesn't evaluate arguments" do
+ obj = Object.new
+ obj.should_not_receive(:m)
+ nil&.unknown(obj.m) { obj.m }
+ end
+ end
- it "doesn't evaluate arguments" do
- obj = Object.new
- obj.should_not_receive(:m)
- eval("nil&.unknown(obj.m) { obj.m }")
- end
+ context "when context is false" do
+ it "calls the method" do
+ false&.to_s.should == "false"
+
+ -> { false&.unknown }.should.raise(NoMethodError)
end
+ end
- context "when context is false" do
- it "calls the method" do
- eval("false&.to_s").should == "false"
+ context "when context is truthy" do
+ it "calls the method" do
+ 1&.to_s.should == "1"
- lambda { eval("false&.unknown") }.should raise_error(NoMethodError)
- end
+ -> { 1&.unknown }.should.raise(NoMethodError)
end
+ end
- context "when context is truthy" do
- it "calls the method" do
- eval("1&.to_s").should == "1"
+ it "takes a list of arguments" do
+ [1,2,3]&.first(2).should == [1,2]
+ end
+
+ it "takes a block" do
+ [1,2]&.map { |i| i * 2 }.should == [2, 4]
+ end
- lambda { eval("1&.unknown") }.should raise_error(NoMethodError)
+ it "allows assignment methods" do
+ klass = Class.new do
+ attr_reader :foo
+ def foo=(val)
+ @foo = val
+ 42
end
end
+ obj = klass.new
- it "takes a list of arguments" do
- eval("[1,2,3]&.first(2)").should == [1,2]
- end
+ (obj&.foo = 3).should == 3
+ obj.foo.should == 3
- it "takes a block" do
- eval("[1,2]&.map { |i| i * 2 }").should == [2, 4]
- end
+ obj = nil
+ (obj&.foo = 3).should == nil
+ end
- it "allows assignment methods" do
- klass = Class.new do
- attr_reader :foo
- def foo=(val)
- @foo = val
- 42
- end
- end
- obj = klass.new
+ it "allows assignment operators" do
+ klass = Class.new do
+ attr_reader :m
- eval("obj&.foo = 3").should == 3
- obj.foo.should == 3
+ def initialize
+ @m = 0
+ end
- obj = nil
- eval("obj&.foo = 3").should == nil
+ def m=(v)
+ @m = v
+ 42
+ end
end
- it "allows assignment operators" do
- klass = Class.new do
- attr_accessor :m
+ obj = klass.new
- def initialize
- @m = 0
- end
- end
+ obj&.m += 3
+ obj.m.should == 3
+
+ obj = nil
+ (obj&.m += 3).should == nil
+ end
- obj = klass.new
+ it "allows ||= operator" do
+ klass = Class.new do
+ attr_reader :m
- eval("obj&.m += 3")
- obj.m.should == 3
+ def initialize
+ @m = false
+ end
- obj = nil
- eval("obj&.m += 3").should == nil
+ def m=(v)
+ @m = v
+ 42
+ end
end
- it "does not call the operator method lazily with an assignment operator" do
- klass = Class.new do
- attr_writer :foo
- def foo
- nil
- end
+ obj = klass.new
+
+ (obj&.m ||= true).should == true
+ obj.m.should == true
+
+ obj = nil
+ (obj&.m ||= true).should == nil
+ obj.should == nil
+ end
+
+ it "allows &&= operator" do
+ klass = Class.new do
+ attr_accessor :m
+
+ def initialize
+ @m = true
end
- obj = klass.new
+ end
+
+ obj = klass.new
+
+ (obj&.m &&= false).should == false
+ obj.m.should == false
- lambda {
- eval("obj&.foo += 3")
- }.should raise_error(NoMethodError) { |e|
- e.name.should == :+
- }
+ obj = nil
+ (obj&.m &&= false).should == nil
+ obj.should == nil
+ end
+
+ it "does not call the operator method lazily with an assignment operator" do
+ klass = Class.new do
+ attr_writer :foo
+ def foo
+ nil
+ end
end
+ obj = klass.new
+
+ -> {
+ obj&.foo += 3
+ }.should.raise(NoMethodError) { |e|
+ e.name.should == :+
+ }
end
end
diff --git a/spec/ruby/language/safe_spec.rb b/spec/ruby/language/safe_spec.rb
new file mode 100644
index 0000000000..03ae96148e
--- /dev/null
+++ b/spec/ruby/language/safe_spec.rb
@@ -0,0 +1,11 @@
+require_relative '../spec_helper'
+
+describe "The $SAFE variable" do
+ it "$SAFE is a regular global variable" do
+ $SAFE.should == nil
+ $SAFE = 42
+ $SAFE.should == 42
+ ensure
+ $SAFE = nil
+ end
+end
diff --git a/spec/ruby/language/send_spec.rb b/spec/ruby/language/send_spec.rb
index 646a700785..f56a77d529 100644
--- a/spec/ruby/language/send_spec.rb
+++ b/spec/ruby/language/send_spec.rb
@@ -1,15 +1,15 @@
-require File.expand_path('../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/send', __FILE__)
+require_relative '../spec_helper'
+require_relative 'fixtures/send'
# Why so many fixed arg tests? JRuby and I assume other Ruby impls have
# separate call paths for simple fixed arity methods. Testing up to five
# will verify special and generic arity code paths for all impls.
#
# Method naming conventions:
-# M - Manditory Args
+# M - Mandatory Args
# O - Optional Arg
# R - Rest Arg
-# Q - Post Manditory Args
+# Q - Post Mandatory Args
specs = LangSendSpecs
@@ -20,9 +20,9 @@ describe "Invoking a method" do
end
it "raises ArgumentError if the method has a positive arity" do
- lambda {
+ -> {
specs.fooM1
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
end
end
@@ -36,14 +36,14 @@ describe "Invoking a method" do
end
it "raises ArgumentError if the methods arity doesn't match" do
- lambda {
+ -> {
specs.fooM1(1,2)
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
end
end
describe "with optional arguments" do
- it "uses the optional argument if none is is passed" do
+ it "uses the optional argument if none is passed" do
specs.fooM0O1.should == [1]
end
@@ -52,9 +52,9 @@ describe "Invoking a method" do
end
it "raises ArgumentError if extra arguments are passed" do
- lambda {
+ -> {
specs.fooM0O1(2,3)
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
end
end
@@ -64,15 +64,15 @@ describe "Invoking a method" do
end
it "raises an ArgumentError if there are no values for the mandatory args" do
- lambda {
+ -> {
specs.fooM1O1
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
end
it "raises an ArgumentError if too many values are passed" do
- lambda {
+ -> {
specs.fooM1O1(1,2,3)
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
end
end
@@ -94,7 +94,7 @@ describe "Invoking a method" do
it "with a block converts the block to a Proc" do
prc = specs.makeproc { "hello" }
- prc.should be_kind_of(Proc)
+ prc.should.is_a?(Proc)
prc.call.should == "hello"
end
@@ -106,10 +106,28 @@ describe "Invoking a method" do
specs.yield_now(&o).should == :from_to_proc
end
+ ruby_version_is "4.0" do
+ it "raises TypeError if 'to_proc' doesn't return a Proc" do
+ o = LangSendSpecs::RawToProc.new(42)
+
+ -> {
+ specs.makeproc(&o)
+ }.should raise_consistent_error(TypeError, "can't convert LangSendSpecs::RawToProc into Proc (LangSendSpecs::RawToProc#to_proc gives Integer)")
+ end
+
+ it "raises TypeError if block object isn't a Proc and doesn't respond to `to_proc`" do
+ o = Object.new
+
+ -> {
+ specs.makeproc(&o)
+ }.should.raise(TypeError, "no implicit conversion of Object into Proc")
+ end
+ end
+
it "raises a SyntaxError with both a literal block and an object as block" do
- lambda {
+ -> {
eval "specs.oneb(10, &l){ 42 }"
- }.should raise_error(SyntaxError)
+ }.should.raise(SyntaxError)
end
it "with same names as existing variables is ok" do
@@ -194,13 +212,42 @@ describe "Invoking a method" do
o.args.should == [1,2]
end
- it "raises NameError if invoked as a vcall" do
- lambda { no_such_method }.should raise_error NameError
+ describe "if invoked as a vcall" do
+ it "raises NameError" do
+ -> { no_such_method }.should.raise NameError
+ end
+
+ it "raises NameError with $! as a cause" do
+ begin
+ raise RuntimeError.new
+ rescue => cause
+ -> { no_such_method }.should.raise(NameError, cause:)
+ end
+ end
+ end
+
+ it "should omit the method_missing call from the backtrace for NameError" do
+ -> { no_such_method }.should.raise { |e| e.backtrace.first.should_not.include?("method_missing") }
+ end
+
+ describe "if invoked as an unambiguous method call" do
+ it "raises NoMethodError" do
+ -> { no_such_method() }.should.raise NoMethodError
+ -> { no_such_method(1,2,3) }.should.raise NoMethodError
+ end
+
+ it "raises NoMethodError with $! as a cause" do
+ begin
+ raise
+ rescue => cause
+ -> { no_such_method() }.should.raise(NoMethodError, cause:)
+ -> { no_such_method(1,2,3) }.should.raise(NoMethodError, cause:)
+ end
+ end
end
- it "raises NoMethodError if invoked as an unambiguous method call" do
- lambda { no_such_method() }.should raise_error NoMethodError
- lambda { no_such_method(1,2,3) }.should raise_error NoMethodError
+ it "should omit the method_missing call from the backtrace for NoMethodError" do
+ -> { no_such_method() }.should.raise { |e| e.backtrace.first.should_not.include?("method_missing") }
end
end
@@ -250,10 +297,10 @@ describe "Invoking a private setter method" do
end
describe "Invoking a private getter method" do
- it "does not permit self as a receiver" do
+ it "permits self as a receiver" do
receiver = LangSendSpecs::PrivateGetter.new
- lambda { receiver.call_self_foo }.should raise_error(NoMethodError)
- lambda { receiver.call_self_foo_or_equals(6) }.should raise_error(NoMethodError)
+ receiver.call_self_foo_or_equals(6)
+ receiver.call_self_foo.should == 6
end
end
@@ -329,7 +376,7 @@ describe "Invoking a method" do
it "with splat operator * and non-Array value uses value unchanged if it does not respond_to?(:to_ary)" do
obj = Object.new
- obj.should_not respond_to(:to_a)
+ obj.should_not.respond_to?(:to_a)
specs.fooM0R(*obj).should == [obj]
specs.fooM1R(1,*obj).should == [1, [obj]]
@@ -403,6 +450,29 @@ describe "Invoking a method" do
specs.rest_len(0,*a,4,*5,6,7,*c,-1).should == 11
end
+ it "expands the Array elements from the splat before applying block argument operations" do
+ def self.m(*args, &block)
+ [args, block]
+ end
+
+ args = [1, nil]
+ m(*args, &args.pop).should == [[1, nil], nil]
+
+ args = [1, nil]
+ order = []
+ m(*(order << :args; args), &(order << :block; args.pop)).should == [[1, nil], nil]
+ order.should == [:args, :block]
+ end
+
+ it "evaluates the splatted arguments before the block if there are other arguments after the splat" do
+ def self.m(*args, &block)
+ [args, block]
+ end
+
+ args = [1, nil]
+ m(*args, 2, &args.pop).should == [[1, nil, 2], nil]
+ end
+
it "expands an array to arguments grouped in parentheses" do
specs.destructure2([40,2]).should == 42
end
diff --git a/spec/ruby/language/shared/__FILE__.rb b/spec/ruby/language/shared/__FILE__.rb
index 3e4f5c958d..7e2e871932 100644
--- a/spec/ruby/language/shared/__FILE__.rb
+++ b/spec/ruby/language/shared/__FILE__.rb
@@ -9,14 +9,14 @@ describe :language___FILE__, shared: true do
end
it "equals the absolute path of a file loaded by an absolute path" do
- @object.send(@method, @path).should be_true
+ @object.send(@method, @path).should == true
ScratchPad.recorded.should == [@path]
end
it "equals the absolute path of a file loaded by a relative path" do
$LOAD_PATH << "."
Dir.chdir CODE_LOADING_DIR do
- @object.send(@method, "file_fixture.rb").should be_true
+ @object.send(@method, "file_fixture.rb").should == true
end
ScratchPad.recorded.should == [@path]
end
diff --git a/spec/ruby/language/shared/__LINE__.rb b/spec/ruby/language/shared/__LINE__.rb
index 076b74b3ba..6bfc8c1c17 100644
--- a/spec/ruby/language/shared/__LINE__.rb
+++ b/spec/ruby/language/shared/__LINE__.rb
@@ -9,7 +9,7 @@ describe :language___LINE__, shared: true do
end
it "equals the line number of the text in a loaded file" do
- @object.send(@method, @path).should be_true
+ @object.send(@method, @path).should == true
ScratchPad.recorded.should == [1, 5]
end
end
diff --git a/spec/ruby/language/singleton_class_spec.rb b/spec/ruby/language/singleton_class_spec.rb
index 837f479440..20256a323c 100644
--- a/spec/ruby/language/singleton_class_spec.rb
+++ b/spec/ruby/language/singleton_class_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/class', __FILE__)
+require_relative '../spec_helper'
+require_relative '../fixtures/class'
describe "A singleton class" do
it "is TrueClass for true" do
@@ -14,40 +14,40 @@ describe "A singleton class" do
nil.singleton_class.should == NilClass
end
- it "raises a TypeError for Fixnum's" do
- lambda { 1.singleton_class }.should raise_error(TypeError)
+ it "raises a TypeError for Integer's" do
+ -> { 1.singleton_class }.should.raise(TypeError)
end
it "raises a TypeError for symbols" do
- lambda { :symbol.singleton_class }.should raise_error(TypeError)
+ -> { :symbol.singleton_class }.should.raise(TypeError)
end
it "is a singleton Class instance" do
o = mock('x')
- o.singleton_class.should be_kind_of(Class)
- o.singleton_class.should_not equal(Object)
- o.should be_kind_of(o.singleton_class)
+ o.singleton_class.should.is_a?(Class)
+ o.singleton_class.should_not.equal?(Object)
+ o.should.is_a?(o.singleton_class)
end
it "is a Class for classes" do
- ClassSpecs::A.singleton_class.should be_kind_of(Class)
+ ClassSpecs::A.singleton_class.should.is_a?(Class)
end
it "inherits from Class for classes" do
- Class.should be_ancestor_of(Object.singleton_class)
+ Object.singleton_class.ancestors.should.include?(Class)
end
it "is a subclass of Class's singleton class" do
ec = ClassSpecs::A.singleton_class
- ec.should be_kind_of(Class.singleton_class)
+ ec.should.is_a?(Class.singleton_class)
end
it "is a subclass of the same level of Class's singleton class" do
ecec = ClassSpecs::A.singleton_class.singleton_class
class_ec = Class.singleton_class
- ecec.should be_kind_of(class_ec.singleton_class)
- ecec.should be_kind_of(class_ec)
+ ecec.should.is_a?(class_ec.singleton_class)
+ ecec.should.is_a?(class_ec)
end
it "is a subclass of a superclass's singleton class" do
@@ -60,7 +60,7 @@ describe "A singleton class" do
ClassSpecs::H.singleton_class.singleton_class
end
- it "for BasicObject has Class as it's superclass" do
+ it "for BasicObject has Class as its superclass" do
BasicObject.singleton_class.superclass.should == Class
end
@@ -70,11 +70,11 @@ describe "A singleton class" do
end
it "has class String as the superclass of a String instance" do
- "blah".singleton_class.superclass.should == String
+ "blah".dup.singleton_class.superclass.should == String
end
it "doesn't have singleton class" do
- lambda { bignum_value.singleton_class.superclass.should == Bignum }.should raise_error(TypeError)
+ -> { bignum_value.singleton_class }.should.raise(TypeError)
end
end
@@ -105,20 +105,20 @@ describe "A constant on a singleton class" do
end
it "is not defined on the object's class" do
- @object.class.const_defined?(:CONST).should be_false
+ @object.class.const_defined?(:CONST).should == false
end
it "is not defined in the singleton class opener's scope" do
class << @object
CONST
end
- lambda { CONST }.should raise_error(NameError)
+ -> { CONST }.should.raise(NameError)
end
it "cannot be accessed via object::CONST" do
- lambda do
+ -> do
@object::CONST
- end.should raise_error(TypeError)
+ end.should.raise(TypeError)
end
it "raises a NameError for anonymous_module::CONST" do
@@ -127,32 +127,32 @@ describe "A constant on a singleton class" do
CONST = 100
end
- lambda do
+ -> do
@object::CONST
- end.should raise_error(NameError)
+ end.should.raise(NameError)
end
it "appears in the singleton class constant list" do
- @object.singleton_class.should have_constant(:CONST)
+ @object.singleton_class.should.const_defined?(:CONST, false)
end
it "does not appear in the object's class constant list" do
- @object.class.should_not have_constant(:CONST)
+ @object.class.should_not.const_defined?(:CONST)
end
it "is not preserved when the object is duped" do
@object = @object.dup
- lambda do
+ -> do
class << @object; CONST; end
- end.should raise_error(NameError)
+ end.should.raise(NameError)
end
it "is preserved when the object is cloned" do
@object = @object.clone
class << @object
- CONST.should_not be_nil
+ CONST.should_not == nil
end
end
end
@@ -168,7 +168,7 @@ describe "Defining instance methods on a singleton class" do
end
it "defines public methods" do
- @k_sc.should have_public_instance_method(:singleton_method)
+ @k_sc.public_instance_methods(false).should.include?(:singleton_method)
end
end
@@ -181,46 +181,46 @@ describe "Instance methods of a singleton class" do
end
it "include ones of the object's class" do
- @k_sc.should have_instance_method(:example_instance_method)
+ @k_sc.should.method_defined?(:example_instance_method, true)
end
it "does not include class methods of the object's class" do
- @k_sc.should_not have_instance_method(:example_class_method)
+ @k_sc.should_not.method_defined?(:example_class_method)
end
it "include instance methods of Object" do
- @a_sc.should have_instance_method(:example_instance_method_of_object)
+ @a_sc.should.method_defined?(:example_instance_method_of_object, true)
end
it "does not include class methods of Object" do
- @a_sc.should_not have_instance_method(:example_class_method_of_object)
+ @a_sc.should_not.method_defined?(:example_class_method_of_object)
end
describe "for a class" do
it "include instance methods of Class" do
- @a_c_sc.should have_instance_method(:example_instance_method_of_class)
+ @a_c_sc.should.method_defined?(:example_instance_method_of_class, true)
end
it "does not include class methods of Class" do
- @a_c_sc.should_not have_instance_method(:example_class_method_of_class)
+ @a_c_sc.should_not.method_defined?(:example_class_method_of_class)
end
it "does not include instance methods of the singleton class of Class" do
- @a_c_sc.should_not have_instance_method(:example_instance_method_of_singleton_class)
+ @a_c_sc.should_not.method_defined?(:example_instance_method_of_singleton_class)
end
it "does not include class methods of the singleton class of Class" do
- @a_c_sc.should_not have_instance_method(:example_class_method_of_singleton_class)
+ @a_c_sc.should_not.method_defined?(:example_class_method_of_singleton_class)
end
end
describe "for a singleton class" do
it "includes instance methods of the singleton class of Class" do
- @a_c_sc.singleton_class.should have_instance_method(:example_instance_method_of_singleton_class)
+ @a_c_sc.singleton_class.should.method_defined?(:example_instance_method_of_singleton_class, true)
end
it "does not include class methods of the singleton class of Class" do
- @a_c_sc.singleton_class.should_not have_instance_method(:example_class_method_of_singleton_class)
+ @a_c_sc.singleton_class.should_not.method_defined?(:example_class_method_of_singleton_class)
end
end
end
@@ -234,60 +234,84 @@ describe "Class methods of a singleton class" do
end
it "include ones of the object's class" do
- @k_sc.should have_method(:example_class_method)
+ @k_sc.should.respond_to?(:example_class_method)
end
it "does not include instance methods of the object's class" do
- @k_sc.should_not have_method(:example_instance_method)
+ @k_sc.should_not.respond_to?(:example_instance_method)
end
it "include instance methods of Class" do
- @a_sc.should have_method(:example_instance_method_of_class)
+ @a_sc.should.respond_to?(:example_instance_method_of_class)
end
it "does not include class methods of Class" do
- @a_sc.should_not have_method(:example_class_method_of_class)
+ @a_sc.should_not.respond_to?(:example_class_method_of_class)
end
describe "for a class" do
it "include instance methods of Class" do
- @a_c_sc.should have_method(:example_instance_method_of_class)
+ @a_c_sc.should.respond_to?(:example_instance_method_of_class)
end
it "include class methods of Class" do
- @a_c_sc.should have_method(:example_class_method_of_class)
+ @a_c_sc.should.respond_to?(:example_class_method_of_class)
end
it "include instance methods of the singleton class of Class" do
- @a_c_sc.should have_method(:example_instance_method_of_singleton_class)
+ @a_c_sc.should.respond_to?(:example_instance_method_of_singleton_class)
end
it "does not include class methods of the singleton class of Class" do
- @a_c_sc.should_not have_method(:example_class_method_of_singleton_class)
+ @a_c_sc.should_not.respond_to?(:example_class_method_of_singleton_class)
end
end
describe "for a singleton class" do
it "include instance methods of the singleton class of Class" do
- @a_c_sc.singleton_class.should have_method(:example_instance_method_of_singleton_class)
+ @a_c_sc.singleton_class.should.respond_to?(:example_instance_method_of_singleton_class)
end
it "include class methods of the singleton class of Class" do
- @a_c_sc.singleton_class.should have_method(:example_class_method_of_singleton_class)
+ @a_c_sc.singleton_class.should.respond_to?(:example_class_method_of_singleton_class)
end
end
end
describe "Instantiating a singleton class" do
it "raises a TypeError when new is called" do
- lambda {
+ -> {
Object.new.singleton_class.new
- }.should raise_error(TypeError)
+ }.should.raise(TypeError)
end
it "raises a TypeError when allocate is called" do
- lambda {
+ -> {
Object.new.singleton_class.allocate
- }.should raise_error(TypeError)
+ }.should.raise(TypeError)
+ end
+end
+
+describe "Frozen properties" do
+ it "is frozen if the object it is created from is frozen" do
+ o = Object.new
+ o.freeze
+ klass = o.singleton_class
+ klass.frozen?.should == true
+ end
+
+ it "will be frozen if the object it is created from becomes frozen" do
+ o = Object.new
+ klass = o.singleton_class
+ klass.frozen?.should == false
+ o.freeze
+ klass.frozen?.should == true
+ end
+
+ it "will be unfrozen if the frozen object is cloned with freeze set to false" do
+ o = Object.new
+ o.freeze
+ o2 = o.clone(freeze: false)
+ o2.singleton_class.frozen?.should == false
end
end
diff --git a/spec/ruby/language/source_encoding_spec.rb b/spec/ruby/language/source_encoding_spec.rb
new file mode 100644
index 0000000000..5a243fa2c3
--- /dev/null
+++ b/spec/ruby/language/source_encoding_spec.rb
@@ -0,0 +1,61 @@
+require_relative '../spec_helper'
+
+describe "Source files" do
+
+ describe "encoded in UTF-8 without a BOM" do
+ it "can be parsed" do
+ ruby_exe(fixture(__FILE__, "utf8-nobom.rb"), args: "2>&1").should == "hello\n"
+ end
+ end
+
+ describe "encoded in UTF-8 with a BOM" do
+ it "can be parsed" do
+ ruby_exe(fixture(__FILE__, "utf8-bom.rb"), args: "2>&1").should == "hello\n"
+ end
+ end
+
+ describe "encoded in UTF-16 LE without a BOM" do
+ it "are parsed as empty because they contain a NUL byte before the encoding comment" do
+ ruby_exe(fixture(__FILE__, "utf16-le-nobom.rb"), args: "2>&1").should == ""
+ end
+ end
+
+ describe "encoded in UTF-16 LE with a BOM" do
+ it "are invalid because they contain an invalid UTF-8 sequence before the encoding comment" do
+ bom = "\xFF\xFE".b
+ source = "# encoding: utf-16le\nputs 'hello'\n"
+ source = bom + source.bytes.zip([0]*source.bytesize).flatten.pack('C*')
+ path = tmp("utf16-le-bom.rb")
+
+ touch(path, "wb") { |f| f.write source }
+ begin
+ ruby_exe(path, args: "2>&1", exit_status: 1).b.should =~ /invalid multibyte char/
+ ensure
+ rm_r path
+ end
+ end
+ end
+
+ describe "encoded in UTF-16 BE without a BOM" do
+ it "are parsed as empty because they contain a NUL byte before the encoding comment" do
+ ruby_exe(fixture(__FILE__, "utf16-be-nobom.rb"), args: "2>&1").should == ""
+ end
+ end
+
+ describe "encoded in UTF-16 BE with a BOM" do
+ it "are invalid because they contain an invalid UTF-8 sequence before the encoding comment" do
+ bom = "\xFE\xFF".b
+ source = "# encoding: utf-16be\nputs 'hello'\n"
+ source = bom + ([0]*source.bytesize).zip(source.bytes).flatten.pack('C*')
+ path = tmp("utf16-be-bom.rb")
+
+ touch(path, "wb") { |f| f.write source }
+ begin
+ ruby_exe(path, args: "2>&1", exit_status: 1).b.should =~ /invalid multibyte char/
+ ensure
+ rm_r path
+ end
+ end
+ end
+
+end
diff --git a/spec/ruby/language/string_spec.rb b/spec/ruby/language/string_spec.rb
index dbec2652ed..163063032f 100644
--- a/spec/ruby/language/string_spec.rb
+++ b/spec/ruby/language/string_spec.rb
@@ -1,6 +1,7 @@
-# -*- encoding: binary -*-
+# encoding: binary
-require File.expand_path('../../spec_helper', __FILE__)
+require_relative '../spec_helper'
+require_relative 'fixtures/class_with_class_variable'
# TODO: rewrite these horrid specs. it "are..." seriously?!
@@ -27,11 +28,21 @@ describe "Ruby character strings" do
"#$ip".should == 'xxx'
end
+ it "interpolate class variables just with the # character" do
+ object = StringSpecs::ClassWithClassVariable.new
+ object.foo.should == 'xxx'
+ end
+
it "allows underscore as part of a variable name in a simple interpolation" do
@my_ip = 'xxx'
"#@my_ip".should == 'xxx'
end
+ it "does not interpolate invalid variable names" do
+ "#@".should == '#@'
+ "#$%".should == '#$%'
+ end
+
it "has characters [.(=?!# end simple # interpolation" do
"#@ip[".should == 'xxx['
"#@ip.".should == 'xxx.'
@@ -42,24 +53,13 @@ describe "Ruby character strings" do
"#@ip#@ip".should == 'xxxxxx'
end
- it "taints the result of interpolation when an interpolated value is tainted" do
- "#{"".taint}".tainted?.should be_true
-
- @ip.taint
- "#@ip".tainted?.should be_true
-
- $ip.taint
- "#$ip".tainted?.should be_true
- end
-
- it "untrusts the result of interpolation when an interpolated value is untrusted" do
- "#{"".untrust}".untrusted?.should be_true
-
- @ip.untrust
- "#@ip".untrusted?.should be_true
-
- $ip.untrust
- "#$ip".untrusted?.should be_true
+ it "don't get confused by partial interpolation character sequences" do
+ "#@".should == '#@'
+ "#@ ".should == '#@ '
+ "#@@".should == '#@@'
+ "#@@ ".should == '#@@ '
+ "#$ ".should == '#$ '
+ "#\$".should == '#$'
end
it "allows using non-alnum characters as string delimiters" do
@@ -133,6 +133,12 @@ describe "Ruby character strings" do
"#{obj}".should == '42'
end
+ it "raise NoMethodError when #to_s is not defined for the object" do
+ obj = BasicObject.new
+
+ -> { "#{obj}" }.should.raise(NoMethodError)
+ end
+
it "uses an internal representation when #to_s doesn't return a String" do
obj = mock('to_s')
obj.stub!(:to_s).and_return(42)
@@ -143,7 +149,7 @@ describe "Ruby character strings" do
# is that if you interpolate an object that fails to return
# a String, you will still get a String and not raise an
# exception.
- "#{obj}".should be_an_instance_of(String)
+ "#{obj}".should.instance_of?(String)
end
it "allows a dynamic string to parse a nested do...end block as an argument to a call without parens, interpolated" do
@@ -186,11 +192,11 @@ describe "Ruby character strings" do
# TODO: spec other source encodings
describe "with ASCII_8BIT source encoding" do
it "produces an ASCII string when escaping ASCII characters via \\u" do
- "\u0000".encoding.should == Encoding::ASCII_8BIT
+ "\u0000".encoding.should == Encoding::BINARY
end
it "produces an ASCII string when escaping ASCII characters via \\u{}" do
- "\u{0000}".encoding.should == Encoding::ASCII_8BIT
+ "\u{0000}".encoding.should == Encoding::BINARY
end
it "produces a UTF-8-encoded string when escaping non-ASCII characters via \\u" do
@@ -224,59 +230,78 @@ describe "Ruby String literals" do
long_string_literals.should == "Beautiful is better than ugly.Explicit is better than implicit."
end
- ruby_version_is "2.3" do
- describe "with a magic frozen comment" do
- it "produce the same object each time" do
- ruby_exe(fixture(__FILE__, "freeze_magic_comment_one_literal.rb")).chomp.should == "true"
- end
+ describe "with a magic frozen comment" do
+ it "produce the same object each time" do
+ ruby_exe(fixture(__FILE__, "freeze_magic_comment_one_literal.rb")).chomp.should == "true"
+ end
- it "produce the same object for literals with the same content" do
- ruby_exe(fixture(__FILE__, "freeze_magic_comment_two_literals.rb")).chomp.should == "true"
- end
+ it "produce the same object for literals with the same content" do
+ ruby_exe(fixture(__FILE__, "freeze_magic_comment_two_literals.rb")).chomp.should == "true"
+ end
- it "produce the same object for literals with the same content in different files" do
- ruby_exe(fixture(__FILE__, "freeze_magic_comment_across_files.rb")).chomp.should == "true"
- end
+ it "produce the same object for literals with the same content in different files" do
+ ruby_exe(fixture(__FILE__, "freeze_magic_comment_across_files.rb")).chomp.should == "true"
+ end
- it "produce different objects for literals with the same content in different files if the other file doesn't have the comment" do
+ guard -> { !(eval("'test'").frozen? && "test".equal?("test")) } do
+ it "produces different objects for literals with the same content in different files if the other file doesn't have the comment and String literals aren't frozen by default" do
ruby_exe(fixture(__FILE__, "freeze_magic_comment_across_files_no_comment.rb")).chomp.should == "true"
end
+ end
- it "produce different objects for literals with the same content in different files if they have different encodings" do
- ruby_exe(fixture(__FILE__, "freeze_magic_comment_across_files_diff_enc.rb")).chomp.should == "true"
+ guard -> { eval("'test'").frozen? && "test".equal?("test") } do
+ it "produces the same objects for literals with the same content in different files if the other file doesn't have the comment and String literals are frozen by default" do
+ ruby_exe(fixture(__FILE__, "freeze_magic_comment_across_files_no_comment.rb")).chomp.should == "false"
end
end
+
+ it "produce different objects for literals with the same content in different files if they have different encodings" do
+ ruby_exe(fixture(__FILE__, "freeze_magic_comment_across_files_diff_enc.rb")).chomp.should == "true"
+ end
end
end
-with_feature :encoding do
- describe "Ruby String interpolation" do
- it "creates a String having an Encoding compatible with all components" do
- a = "\u3042"
- b = "abc".encode("ascii-8bit")
+describe "Ruby String interpolation" do
+ it "permits an empty expression" do
+ s = "#{}" # rubocop:disable Lint/EmptyInterpolation
+ s.should.empty?
+ s.should_not.frozen?
+ end
- str = "#{a} x #{b}"
+ it "returns a string with the source encoding by default" do
+ "a#{"b"}c".encoding.should == Encoding::BINARY
+ eval('"a#{"b"}c"'.dup.force_encoding("us-ascii")).encoding.should == Encoding::US_ASCII
+ eval("# coding: US-ASCII \n 'a#{"b"}c'").encoding.should == Encoding::US_ASCII
+ end
- str.should == "\xe3\x81\x82\x20\x78\x20\x61\x62\x63".force_encoding("utf-8")
- str.encoding.should == Encoding::UTF_8
- end
+ it "returns a string with the source encoding, even if the components have another encoding" do
+ a = "abc".dup.force_encoding("euc-jp")
+ "#{a}".encoding.should == Encoding::BINARY
- it "creates a String having the Encoding of the components when all are the same Encoding" do
- a = "abc".force_encoding("euc-jp")
- b = "def".force_encoding("euc-jp")
- str = '"#{a} x #{b}"'.force_encoding("euc-jp")
+ b = "abc".encode("utf-8")
+ "#{b}".encoding.should == Encoding::BINARY
+ end
- result = eval(str)
- result.should == "\x61\x62\x63\x20\x78\x20\x64\x65\x66".force_encoding("euc-jp")
- result.encoding.should == Encoding::EUC_JP
- end
+ it "raises an Encoding::CompatibilityError if the Encodings are not compatible" do
+ a = "\u3042"
+ b = "\xff".dup.force_encoding "binary"
- it "raises an Encoding::CompatibilityError if the Encodings are not compatible" do
- a = "\u3042"
- b = "\xff".force_encoding "ascii-8bit"
+ -> { "#{a} #{b}" }.should.raise(Encoding::CompatibilityError)
+ end
- lambda { "#{a} #{b}" }.should raise_error(Encoding::CompatibilityError)
- end
+ it "creates a non-frozen String" do
+ code = <<~'RUBY'
+ "a#{6*7}c"
+ RUBY
+ eval(code).should_not.frozen?
+ end
+
+ it "creates a non-frozen String when # frozen-string-literal: true is used" do
+ code = <<~'RUBY'
+ # frozen-string-literal: true
+ "a#{6*7}c"
+ RUBY
+ eval(code).should_not.frozen?
end
end
diff --git a/spec/ruby/language/super_spec.rb b/spec/ruby/language/super_spec.rb
index 3d3f5d6f74..f595d49395 100644
--- a/spec/ruby/language/super_spec.rb
+++ b/spec/ruby/language/super_spec.rb
@@ -1,76 +1,76 @@
-require File.expand_path('../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/super', __FILE__)
+require_relative '../spec_helper'
+require_relative 'fixtures/super'
describe "The super keyword" do
it "calls the method on the calling class" do
- Super::S1::A.new.foo([]).should == ["A#foo","A#bar"]
- Super::S1::A.new.bar([]).should == ["A#bar"]
- Super::S1::B.new.foo([]).should == ["B#foo","A#foo","B#bar","A#bar"]
- Super::S1::B.new.bar([]).should == ["B#bar","A#bar"]
+ SuperSpecs::S1::A.new.foo([]).should == ["A#foo","A#bar"]
+ SuperSpecs::S1::A.new.bar([]).should == ["A#bar"]
+ SuperSpecs::S1::B.new.foo([]).should == ["B#foo","A#foo","B#bar","A#bar"]
+ SuperSpecs::S1::B.new.bar([]).should == ["B#bar","A#bar"]
end
it "searches the full inheritance chain" do
- Super::S2::B.new.foo([]).should == ["B#foo","A#baz"]
- Super::S2::B.new.baz([]).should == ["A#baz"]
- Super::S2::C.new.foo([]).should == ["B#foo","C#baz","A#baz"]
- Super::S2::C.new.baz([]).should == ["C#baz","A#baz"]
+ SuperSpecs::S2::B.new.foo([]).should == ["B#foo","A#baz"]
+ SuperSpecs::S2::B.new.baz([]).should == ["A#baz"]
+ SuperSpecs::S2::C.new.foo([]).should == ["B#foo","C#baz","A#baz"]
+ SuperSpecs::S2::C.new.baz([]).should == ["C#baz","A#baz"]
end
it "searches class methods" do
- Super::S3::A.new.foo([]).should == ["A#foo"]
- Super::S3::A.foo([]).should == ["A.foo"]
- Super::S3::A.bar([]).should == ["A.bar","A.foo"]
- Super::S3::B.new.foo([]).should == ["A#foo"]
- Super::S3::B.foo([]).should == ["B.foo","A.foo"]
- Super::S3::B.bar([]).should == ["B.bar","A.bar","B.foo","A.foo"]
+ SuperSpecs::S3::A.new.foo([]).should == ["A#foo"]
+ SuperSpecs::S3::A.foo([]).should == ["A.foo"]
+ SuperSpecs::S3::A.bar([]).should == ["A.bar","A.foo"]
+ SuperSpecs::S3::B.new.foo([]).should == ["A#foo"]
+ SuperSpecs::S3::B.foo([]).should == ["B.foo","A.foo"]
+ SuperSpecs::S3::B.bar([]).should == ["B.bar","A.bar","B.foo","A.foo"]
end
it "calls the method on the calling class including modules" do
- Super::MS1::A.new.foo([]).should == ["ModA#foo","ModA#bar"]
- Super::MS1::A.new.bar([]).should == ["ModA#bar"]
- Super::MS1::B.new.foo([]).should == ["B#foo","ModA#foo","ModB#bar","ModA#bar"]
- Super::MS1::B.new.bar([]).should == ["ModB#bar","ModA#bar"]
+ SuperSpecs::MS1::A.new.foo([]).should == ["ModA#foo","ModA#bar"]
+ SuperSpecs::MS1::A.new.bar([]).should == ["ModA#bar"]
+ SuperSpecs::MS1::B.new.foo([]).should == ["B#foo","ModA#foo","ModB#bar","ModA#bar"]
+ SuperSpecs::MS1::B.new.bar([]).should == ["ModB#bar","ModA#bar"]
end
it "searches the full inheritance chain including modules" do
- Super::MS2::B.new.foo([]).should == ["ModB#foo","A#baz"]
- Super::MS2::B.new.baz([]).should == ["A#baz"]
- Super::MS2::C.new.baz([]).should == ["C#baz","A#baz"]
- Super::MS2::C.new.foo([]).should == ["ModB#foo","C#baz","A#baz"]
+ SuperSpecs::MS2::B.new.foo([]).should == ["ModB#foo","A#baz"]
+ SuperSpecs::MS2::B.new.baz([]).should == ["A#baz"]
+ SuperSpecs::MS2::C.new.baz([]).should == ["C#baz","A#baz"]
+ SuperSpecs::MS2::C.new.foo([]).should == ["ModB#foo","C#baz","A#baz"]
end
it "can resolve to different methods in an included module method" do
- Super::MultiSuperTargets::A.new.foo.should == :BaseA
- Super::MultiSuperTargets::B.new.foo.should == :BaseB
+ SuperSpecs::MultiSuperTargets::A.new.foo.should == :BaseA
+ SuperSpecs::MultiSuperTargets::B.new.foo.should == :BaseB
end
it "searches class methods including modules" do
- Super::MS3::A.new.foo([]).should == ["A#foo"]
- Super::MS3::A.foo([]).should == ["ModA#foo"]
- Super::MS3::A.bar([]).should == ["ModA#bar","ModA#foo"]
- Super::MS3::B.new.foo([]).should == ["A#foo"]
- Super::MS3::B.foo([]).should == ["B.foo","ModA#foo"]
- Super::MS3::B.bar([]).should == ["B.bar","ModA#bar","B.foo","ModA#foo"]
+ SuperSpecs::MS3::A.new.foo([]).should == ["A#foo"]
+ SuperSpecs::MS3::A.foo([]).should == ["ModA#foo"]
+ SuperSpecs::MS3::A.bar([]).should == ["ModA#bar","ModA#foo"]
+ SuperSpecs::MS3::B.new.foo([]).should == ["A#foo"]
+ SuperSpecs::MS3::B.foo([]).should == ["B.foo","ModA#foo"]
+ SuperSpecs::MS3::B.bar([]).should == ["B.bar","ModA#bar","B.foo","ModA#foo"]
end
it "searches BasicObject from a module for methods defined there" do
- Super::IncludesFromBasic.new.__send__(:foobar).should == 43
+ SuperSpecs::IncludesFromBasic.new.__send__(:foobar).should == 43
end
it "searches BasicObject through another module for methods defined there" do
- Super::IncludesIntermediate.new.__send__(:foobar).should == 42
+ SuperSpecs::IncludesIntermediate.new.__send__(:foobar).should == 42
end
it "calls the correct method when the method visibility is modified" do
- Super::MS4::A.new.example.should == 5
+ SuperSpecs::MS4::A.new.example.should == 5
end
it "calls the correct method when the superclass argument list is different from the subclass" do
- Super::S4::A.new.foo([]).should == ["A#foo"]
- Super::S4::B.new.foo([],"test").should == ["B#foo(a,test)", "A#foo"]
+ SuperSpecs::S4::A.new.foo([]).should == ["A#foo"]
+ SuperSpecs::S4::B.new.foo([],"test").should == ["B#foo(a,test)", "A#foo"]
end
- it "raises an error error when super method does not exist" do
+ it "raises an error when super method does not exist" do
sup = Class.new
sub_normal = Class.new(sup) do
def foo
@@ -83,8 +83,8 @@ describe "The super keyword" do
end
end
- lambda {sub_normal.new.foo}.should raise_error(NoMethodError, /super/)
- lambda {sub_zsuper.new.foo}.should raise_error(NoMethodError, /super/)
+ -> {sub_normal.new.foo}.should.raise(NoMethodError, /super/)
+ -> {sub_zsuper.new.foo}.should.raise(NoMethodError, /super/)
end
it "uses given block even if arguments are passed explicitly" do
@@ -102,16 +102,66 @@ describe "The super keyword" do
c2.new.m(:dump) { :value }.should == :value
end
+ it "can pass an explicit block" do
+ c1 = Class.new do
+ def m(v)
+ yield(v)
+ end
+ end
+ c2 = Class.new(c1) do
+ def m(v)
+ block = -> w { yield(w + 'b') }
+ super(v, &block)
+ end
+ end
+
+ c2.new.m('a') { |x| x + 'c' }.should == 'abc'
+ end
+
+ it "can pass no block using &nil" do
+ c1 = Class.new do
+ def m(v)
+ block_given?
+ end
+ end
+ c2 = Class.new(c1) do
+ def m(v)
+ super(v, &nil)
+ end
+ end
+
+ c2.new.m('a') { raise }.should == false
+ end
+
+ it "uses block argument given to method when used in a block" do
+ c1 = Class.new do
+ def m
+ yield
+ end
+ end
+ c2 = Class.new(c1) do
+ def m(v)
+ ary = []
+ 1.times do
+ ary << super()
+ end
+ ary
+ end
+ end
+
+ c2.new.m(:dump) { :value }.should == [ :value ]
+ end
+
it "calls the superclass method when in a block" do
- Super::S6.new.here.should == :good
+ SuperSpecs::S6.new.here.should == :good
end
it "calls the superclass method when initial method is defined_method'd" do
- Super::S7.new.here.should == :good
+ SuperSpecs::S7.new.here.should == :good
end
it "can call through a define_method multiple times (caching check)" do
- obj = Super::S7.new
+ obj = SuperSpecs::S7.new
2.times do
obj.here.should == :good
@@ -150,25 +200,44 @@ describe "The super keyword" do
end
end
- lambda { klass.new.a(:a_called) }.should raise_error(RuntimeError)
+ -> { klass.new.a(:a_called) }.should.raise(RuntimeError)
+ end
+
+ it "is able to navigate to super, when a method is defined dynamically on the singleton class" do
+ foo_class = Class.new do
+ def bar
+ "bar"
+ end
+ end
+
+ mixin_module = Module.new do
+ def bar
+ "super_" + super
+ end
+ end
+
+ foo = foo_class.new
+ foo.singleton_class.define_method(:bar, mixin_module.instance_method(:bar))
+
+ foo.bar.should == "super_bar"
end
# Rubinius ticket github#157
it "calls method_missing when a superclass method is not found" do
- Super::MM_B.new.is_a?(Hash).should == false
+ SuperSpecs::MM_B.new.is_a?(Hash).should == false
end
# Rubinius ticket github#180
it "respects the original module a method is aliased from" do
- Super::Alias3.new.name3.should == [:alias2, :alias1]
+ SuperSpecs::Alias3.new.name3.should == [:alias2, :alias1]
end
it "sees the included version of a module a method is alias from" do
- Super::AliasWithSuper::Trigger.foo.should == [:b, :a]
+ SuperSpecs::AliasWithSuper::Trigger.foo.should == [:b, :a]
end
it "find super from a singleton class" do
- obj = Super::SingletonCase::Foo.new
+ obj = SuperSpecs::SingletonCase::Foo.new
def obj.foobar(array)
array << :singleton
super
@@ -177,87 +246,123 @@ describe "The super keyword" do
end
it "finds super on other objects if a singleton class aliased the method" do
- orig_obj = Super::SingletonAliasCase::Foo.new
+ orig_obj = SuperSpecs::SingletonAliasCase::Foo.new
orig_obj.alias_on_singleton
orig_obj.new_foobar([]).should == [:foo, :base]
- Super::SingletonAliasCase::Foo.new.foobar([]).should == [:foo, :base]
+ SuperSpecs::SingletonAliasCase::Foo.new.foobar([]).should == [:foo, :base]
end
it "passes along modified rest args when they weren't originally empty" do
- Super::RestArgsWithSuper::B.new.a("bar").should == ["bar", "foo"]
+ SuperSpecs::RestArgsWithSuper::B.new.a("bar").should == ["bar", "foo"]
end
it "passes along modified rest args when they were originally empty" do
- Super::RestArgsWithSuper::B.new.a.should == ["foo"]
+ SuperSpecs::RestArgsWithSuper::B.new.a.should == ["foo"]
+ end
+
+ # https://bugs.ruby-lang.org/issues/14279
+ it "passes along reassigned rest args" do
+ SuperSpecs::ZSuperWithRestReassigned::B.new.a("bar").should == ["foo"]
+ end
+
+ # https://bugs.ruby-lang.org/issues/14279
+ it "wraps into array and passes along reassigned rest args with non-array scalar value" do
+ SuperSpecs::ZSuperWithRestReassignedWithScalar::B.new.a("bar").should == ["foo"]
end
it "invokes methods from a chain of anonymous modules" do
- Super::AnonymousModuleIncludedTwice.new.a([]).should == ["anon", "anon", "non-anon"]
+ SuperSpecs::AnonymousModuleIncludedTwice.new.a([]).should == ["anon", "anon", "non-anon"]
end
it "without explicit arguments can accept a block but still pass the original arguments" do
- Super::ZSuperWithBlock::B.new.a.should == 14
+ SuperSpecs::ZSuperWithBlock::B.new.a.should == 14
end
it "passes along block via reference to method expecting a reference" do
- Super::ZSuperWithBlock::B.new.b.should == [14, 15]
+ SuperSpecs::ZSuperWithBlock::B.new.b.should == [14, 15]
end
it "passes along a block via reference to a method that yields" do
- Super::ZSuperWithBlock::B.new.c.should == 16
+ SuperSpecs::ZSuperWithBlock::B.new.c.should == 16
end
it "without explicit arguments passes optional arguments that have a default value" do
- Super::ZSuperWithOptional::B.new.m(1, 2).should == 14
+ SuperSpecs::ZSuperWithOptional::B.new.m(1, 2).should == 14
end
it "without explicit arguments passes optional arguments that have a non-default value" do
- Super::ZSuperWithOptional::B.new.m(1, 2, 3).should == 3
+ SuperSpecs::ZSuperWithOptional::B.new.m(1, 2, 3).should == 3
end
it "without explicit arguments passes optional arguments that have a default value but were modified" do
- Super::ZSuperWithOptional::C.new.m(1, 2).should == 100
+ SuperSpecs::ZSuperWithOptional::C.new.m(1, 2).should == 100
end
it "without explicit arguments passes optional arguments that have a non-default value but were modified" do
- Super::ZSuperWithOptional::C.new.m(1, 2, 3).should == 100
+ SuperSpecs::ZSuperWithOptional::C.new.m(1, 2, 3).should == 100
end
it "without explicit arguments passes rest arguments" do
- Super::ZSuperWithRest::B.new.m(1, 2, 3).should == [1, 2, 3]
+ SuperSpecs::ZSuperWithRest::B.new.m(1, 2, 3).should == [1, 2, 3]
end
it "without explicit arguments passes rest arguments including any modifications" do
- Super::ZSuperWithRest::B.new.m_modified(1, 2, 3).should == [1, 14, 3]
+ SuperSpecs::ZSuperWithRest::B.new.m_modified(1, 2, 3).should == [1, 14, 3]
end
it "without explicit arguments passes arguments and rest arguments" do
- Super::ZSuperWithRestAndOthers::B.new.m(1, 2, 3, 4, 5).should == [3, 4, 5]
+ SuperSpecs::ZSuperWithRestAndOthers::B.new.m(1, 2, 3, 4, 5).should == [3, 4, 5]
+ SuperSpecs::ZSuperWithRestAndOthers::B.new.m(1, 2).should == []
+ end
+
+ it "without explicit arguments passes arguments, rest arguments, and post arguments" do
+ SuperSpecs::ZSuperWithRestAndPost::B.new.m(1, 2, 3, 4, 5).should == [1, 2, 3]
+ SuperSpecs::ZSuperWithRestOthersAndPost::B.new.m(1, 2, 3, 4, 5).should == [2, 3, 4]
+ SuperSpecs::ZSuperWithRestAndPost::B.new.m(1, 2).should == []
+ SuperSpecs::ZSuperWithRestOthersAndPost::B.new.m(1, 2).should == []
+ end
+
+ it "without explicit arguments passes arguments, rest arguments including modifications, and post arguments" do
+ SuperSpecs::ZSuperWithRestAndPost::B.new.m_modified(1, 2, 3, 4, 5).should == [1, 14, 3]
+ SuperSpecs::ZSuperWithRestOthersAndPost::B.new.m_modified(1, 2, 3, 4, 5).should == [2, 14, 4]
+ SuperSpecs::ZSuperWithRestAndPost::B.new.m_modified(1, 2).should == [nil, 14]
+ SuperSpecs::ZSuperWithRestOthersAndPost::B.new.m_modified(1, 2).should == [nil, 14]
end
it "without explicit arguments passes arguments and rest arguments including any modifications" do
- Super::ZSuperWithRestAndOthers::B.new.m_modified(1, 2, 3, 4, 5).should == [3, 14, 5]
+ SuperSpecs::ZSuperWithRestAndOthers::B.new.m_modified(1, 2, 3, 4, 5).should == [3, 14, 5]
end
it "without explicit arguments that are '_'" do
- Super::ZSuperWithUnderscores::B.new.m(1, 2).should == [1, 2]
+ SuperSpecs::ZSuperWithUnderscores::B.new.m(1, 2).should == [1, 2]
+ SuperSpecs::ZSuperWithUnderscores::B.new.m3(1, 2, 3).should == [1, 2, 3]
+ SuperSpecs::ZSuperWithUnderscores::B.new.m4(1, 2, 3, 4).should == [1, 2, 3, 4]
+ SuperSpecs::ZSuperWithUnderscores::B.new.m_default(1).should == [1]
+ SuperSpecs::ZSuperWithUnderscores::B.new.m_default.should == [0]
+ SuperSpecs::ZSuperWithUnderscores::B.new.m_pre_default_rest_post(1, 2, 3, 4, 5, 6, 7).should == [1, 2, 3, 4, 5, 6, 7]
+ SuperSpecs::ZSuperWithUnderscores::B.new.m_rest(1, 2).should == [1, 2]
+ SuperSpecs::ZSuperWithUnderscores::B.new.m_kwrest(a: 1).should == {a: 1}
end
it "without explicit arguments that are '_' including any modifications" do
- Super::ZSuperWithUnderscores::B.new.m_modified(1, 2).should == [14, 2]
+ SuperSpecs::ZSuperWithUnderscores::B.new.m_modified(1, 2).should == [14, 2]
+ end
+
+ it "should pass method arguments when called within a closure" do
+ SuperSpecs::ZSuperInBlock::B.new.m(arg: 1).should == 1
end
describe 'when using keyword arguments' do
before :each do
- @req = Super::Keywords::RequiredArguments.new
- @opts = Super::Keywords::OptionalArguments.new
- @etc = Super::Keywords::PlaceholderArguments.new
+ @req = SuperSpecs::Keywords::RequiredArguments.new
+ @opts = SuperSpecs::Keywords::OptionalArguments.new
+ @etc = SuperSpecs::Keywords::PlaceholderArguments.new
- @req_and_opts = Super::Keywords::RequiredAndOptionalArguments.new
- @req_and_etc = Super::Keywords::RequiredAndPlaceholderArguments.new
- @opts_and_etc = Super::Keywords::OptionalAndPlaceholderArguments.new
+ @req_and_opts = SuperSpecs::Keywords::RequiredAndOptionalArguments.new
+ @req_and_etc = SuperSpecs::Keywords::RequiredAndPlaceholderArguments.new
+ @opts_and_etc = SuperSpecs::Keywords::OptionalAndPlaceholderArguments.new
- @req_and_opts_and_etc = Super::Keywords::RequiredAndOptionalAndPlaceholderArguments.new
+ @req_and_opts_and_etc = SuperSpecs::Keywords::RequiredAndOptionalAndPlaceholderArguments.new
end
it 'does not pass any arguments to the parent when none are given' do
@@ -293,15 +398,15 @@ describe "The super keyword" do
describe 'when using regular and keyword arguments' do
before :each do
- @req = Super::RegularAndKeywords::RequiredArguments.new
- @opts = Super::RegularAndKeywords::OptionalArguments.new
- @etc = Super::RegularAndKeywords::PlaceholderArguments.new
+ @req = SuperSpecs::RegularAndKeywords::RequiredArguments.new
+ @opts = SuperSpecs::RegularAndKeywords::OptionalArguments.new
+ @etc = SuperSpecs::RegularAndKeywords::PlaceholderArguments.new
- @req_and_opts = Super::RegularAndKeywords::RequiredAndOptionalArguments.new
- @req_and_etc = Super::RegularAndKeywords::RequiredAndPlaceholderArguments.new
- @opts_and_etc = Super::RegularAndKeywords::OptionalAndPlaceholderArguments.new
+ @req_and_opts = SuperSpecs::RegularAndKeywords::RequiredAndOptionalArguments.new
+ @req_and_etc = SuperSpecs::RegularAndKeywords::RequiredAndPlaceholderArguments.new
+ @opts_and_etc = SuperSpecs::RegularAndKeywords::OptionalAndPlaceholderArguments.new
- @req_and_opts_and_etc = Super::RegularAndKeywords::RequiredAndOptionalAndPlaceholderArguments.new
+ @req_and_opts_and_etc = SuperSpecs::RegularAndKeywords::RequiredAndOptionalAndPlaceholderArguments.new
end
it 'passes only required regular arguments to the parent when no optional keyword arguments are given' do
@@ -337,7 +442,7 @@ describe "The super keyword" do
describe 'when using splat and keyword arguments' do
before :each do
- @all = Super::SplatAndKeywords::AllArguments.new
+ @all = SuperSpecs::SplatAndKeywords::AllArguments.new
end
it 'does not pass any arguments to the parent when none are given' do
@@ -356,4 +461,18 @@ describe "The super keyword" do
@all.foo('a', b: 'b').should == [['a'], {b: 'b'}]
end
end
+
+ it "works in method definitions using **nil" do
+ parent = Class.new do
+ def m(*args, **kwargs)
+ [args, kwargs]
+ end
+ end
+ child = Class.new(parent) do
+ def m(*args, **nil)
+ super
+ end
+ end
+ child.new.m(1, 2).should == [[1, 2], {}]
+ end
end
diff --git a/spec/ruby/language/symbol_spec.rb b/spec/ruby/language/symbol_spec.rb
index 90540f7d1d..81fe06b50b 100644
--- a/spec/ruby/language/symbol_spec.rb
+++ b/spec/ruby/language/symbol_spec.rb
@@ -1,9 +1,9 @@
-require File.expand_path('../../spec_helper', __FILE__)
+require_relative '../spec_helper'
describe "A Symbol literal" do
it "is a ':' followed by any number of valid characters" do
a = :foo
- a.should be_kind_of(Symbol)
+ a.should.is_a?(Symbol)
a.inspect.should == ':foo'
end
@@ -21,7 +21,7 @@ describe "A Symbol literal" do
:_Foo,
:&,
:_9
- ].each { |s| s.should be_kind_of(Symbol) }
+ ].each { |s| s.should.is_a?(Symbol) }
end
it "is a ':' followed by a single- or double-quoted string that may contain otherwise invalid characters" do
@@ -31,33 +31,33 @@ describe "A Symbol literal" do
[:"foo #{1 + 1}", ':"foo 2"'],
[:"foo\nbar", ':"foo\nbar"'],
].each { |sym, str|
- sym.should be_kind_of(Symbol)
+ sym.should.is_a?(Symbol)
sym.inspect.should == str
}
end
it 'inherits the encoding of the magic comment and can have a binary encoding' do
ruby_exe(fixture(__FILE__, "binary_symbol.rb"))
- .should == "[105, 108, 95, 195, 169, 116, 97, 105, 116]\nASCII-8BIT\n"
+ .should == "[105, 108, 95, 195, 169, 116, 97, 105, 116]\n#{Encoding::BINARY.name}\n"
end
it "may contain '::' in the string" do
- :'Some::Class'.should be_kind_of(Symbol)
+ :'Some::Class'.should.is_a?(Symbol)
end
it "is converted to a literal, unquoted representation if the symbol contains only valid characters" do
a, b, c = :'foo', :'+', :'Foo__9'
- a.should be_kind_of(Symbol)
+ a.should.is_a?(Symbol)
a.inspect.should == ':foo'
- b.should be_kind_of(Symbol)
+ b.should.is_a?(Symbol)
b.inspect.should == ':+'
- c.should be_kind_of(Symbol)
+ c.should.is_a?(Symbol)
c.inspect.should == ':Foo__9'
end
it "can be created by the %s-delimited expression" do
a, b = :'foo bar', %s{foo bar}
- b.should be_kind_of(Symbol)
+ b.should.is_a?(Symbol)
b.inspect.should == ':"foo bar"'
b.should == a
end
@@ -68,7 +68,7 @@ describe "A Symbol literal" do
[:'a string', :'a string'],
[:"#{var}", :"#{var}"]
].each { |a, b|
- a.should equal(b)
+ a.should.equal?(b)
}
end
@@ -78,7 +78,7 @@ describe "A Symbol literal" do
it "can be an empty string" do
c = :''
- c.should be_kind_of(Symbol)
+ c.should.is_a?(Symbol)
c.inspect.should == ':""'
end
@@ -96,11 +96,13 @@ describe "A Symbol literal" do
%I{a b #{"c"}}.should == [:a, :b, :c]
end
- it "with invalid bytes raises an EncodingError at parse time" do
- ScratchPad.record []
- -> {
- eval 'ScratchPad << 1; :"\xC3"'
- }.should raise_error(EncodingError, /invalid/)
- ScratchPad.recorded.should == []
+ ruby_bug "#20280", ""..."3.4" do
+ it "raises an SyntaxError at parse time when Symbol with invalid bytes" do
+ ScratchPad.record []
+ -> {
+ eval 'ScratchPad << 1; :"\xC3"'
+ }.should.raise(SyntaxError, /invalid symbol/)
+ ScratchPad.recorded.should == []
+ end
end
end
diff --git a/spec/ruby/language/throw_spec.rb b/spec/ruby/language/throw_spec.rb
index 92f699350c..73f64de17d 100644
--- a/spec/ruby/language/throw_spec.rb
+++ b/spec/ruby/language/throw_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../spec_helper', __FILE__)
+require_relative '../spec_helper'
describe "The throw keyword" do
it "abandons processing" do
@@ -35,7 +35,7 @@ describe "The throw keyword" do
throw :exit
end
end
- $!.should be_nil
+ $!.should == nil
end
it "allows any object as its argument" do
@@ -45,7 +45,7 @@ describe "The throw keyword" do
end
it "does not convert strings to a symbol" do
- lambda { catch(:exit) { throw "exit" } }.should raise_error(ArgumentError)
+ -> { catch(:exit) { throw "exit" } }.should.raise(ArgumentError)
end
it "unwinds stack from within a method" do
@@ -59,13 +59,13 @@ describe "The throw keyword" do
end
it "unwinds stack from within a lambda" do
- c = lambda { throw :foo, :msg }
+ c = -> { throw :foo, :msg }
catch(:foo) { c.call }.should == :msg
end
it "raises an ArgumentError if outside of scope of a matching catch" do
- lambda { throw :test, 5 }.should raise_error(ArgumentError)
- lambda { catch(:different) { throw :test, 5 } }.should raise_error(ArgumentError)
+ -> { throw :test, 5 }.should.raise(ArgumentError)
+ -> { catch(:different) { throw :test, 5 } }.should.raise(ArgumentError)
end
it "raises an UncaughtThrowError if used to exit a thread" do
@@ -73,7 +73,7 @@ describe "The throw keyword" do
t = Thread.new {
-> {
throw :what
- }.should raise_error(UncaughtThrowError)
+ }.should.raise(UncaughtThrowError)
}
t.join
end
diff --git a/spec/ruby/language/undef_spec.rb b/spec/ruby/language/undef_spec.rb
index 9e788f2a09..98ecd99c21 100644
--- a/spec/ruby/language/undef_spec.rb
+++ b/spec/ruby/language/undef_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../spec_helper', __FILE__)
+require_relative '../spec_helper'
describe "The undef keyword" do
describe "undefines a method" do
@@ -14,35 +14,42 @@ describe "The undef keyword" do
@undef_class.class_eval do
undef meth
end
- lambda { @obj.meth(5) }.should raise_error(NoMethodError)
+ -> { @obj.meth(5) }.should.raise(NoMethodError)
end
it "with a simple symbol" do
@undef_class.class_eval do
undef :meth
end
- lambda { @obj.meth(5) }.should raise_error(NoMethodError)
+ -> { @obj.meth(5) }.should.raise(NoMethodError)
end
it "with a single quoted symbol" do
@undef_class.class_eval do
undef :'meth'
end
- lambda { @obj.meth(5) }.should raise_error(NoMethodError)
+ -> { @obj.meth(5) }.should.raise(NoMethodError)
end
it "with a double quoted symbol" do
@undef_class.class_eval do
undef :"meth"
end
- lambda { @obj.meth(5) }.should raise_error(NoMethodError)
+ -> { @obj.meth(5) }.should.raise(NoMethodError)
end
- it "with a interpolated symbol" do
+ it "with an interpolated symbol" do
@undef_class.class_eval do
undef :"#{'meth'}"
end
- lambda { @obj.meth(5) }.should raise_error(NoMethodError)
+ -> { @obj.meth(5) }.should.raise(NoMethodError)
+ end
+
+ it "with an interpolated symbol when interpolated expression is not a String literal" do
+ @undef_class.class_eval do
+ undef :"#{'meth'.to_sym}"
+ end
+ -> { @obj.meth(5) }.should.raise(NoMethodError)
end
end
@@ -61,9 +68,9 @@ describe "The undef keyword" do
it "raises a NameError when passed a missing name" do
Class.new do
- lambda {
- undef not_exist
- }.should raise_error(NameError) { |e|
+ -> {
+ undef not_exist
+ }.should.raise(NameError) { |e|
# a NameError and not a NoMethodError
e.class.should == NameError
}
diff --git a/spec/ruby/language/unless_spec.rb b/spec/ruby/language/unless_spec.rb
index 681f0adfdd..98acdc083b 100644
--- a/spec/ruby/language/unless_spec.rb
+++ b/spec/ruby/language/unless_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../spec_helper', __FILE__)
+require_relative '../spec_helper'
describe "The unless expression" do
it "evaluates the unless body when the expression is false" do
diff --git a/spec/ruby/language/until_spec.rb b/spec/ruby/language/until_spec.rb
index 08898644ce..78c289ff56 100644
--- a/spec/ruby/language/until_spec.rb
+++ b/spec/ruby/language/until_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../spec_helper', __FILE__)
+require_relative '../spec_helper'
# until bool-expr [do]
# body
@@ -220,7 +220,7 @@ describe "The until modifier with begin .. end block" do
a.should == [0, 1, 2, 4]
end
- it "restart the current iteration without reevaluting condition with redo" do
+ it "restart the current iteration without reevaluating condition with redo" do
a = []
i = 0
j = 0
diff --git a/spec/ruby/language/variables_spec.rb b/spec/ruby/language/variables_spec.rb
index 81ba54840a..e01e03f01e 100644
--- a/spec/ruby/language/variables_spec.rb
+++ b/spec/ruby/language/variables_spec.rb
@@ -1,5 +1,50 @@
-require File.expand_path('../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/variables', __FILE__)
+require_relative '../spec_helper'
+require_relative 'fixtures/variables'
+
+describe "Evaluation order during assignment" do
+ context "with single assignment" do
+ it "evaluates from left to right" do
+ obj = VariablesSpecs::EvalOrder.new
+ obj.instance_eval do
+ foo[0] = a
+ end
+
+ obj.order.should == ["foo", "a", "foo[]="]
+ end
+ end
+
+ context "with multiple assignment" do
+ it "evaluates from left to right, receivers first then methods" do
+ obj = VariablesSpecs::EvalOrder.new
+ obj.instance_eval do
+ foo[0], bar.baz = a, b
+ end
+
+ obj.order.should == ["foo", "bar", "a", "b", "foo[]=", "bar.baz="]
+ end
+
+ it "can be used to swap variables with nested method calls" do
+ node = VariablesSpecs::EvalOrder.new.node
+
+ original_node = node
+ original_node_left = node.left
+ original_node_left_right = node.left.right
+
+ node.left, node.left.right, node = node.left.right, node, node.left
+ # Should evaluate in the order of:
+ # LHS: node, node.left(original_node_left)
+ # RHS: original_node_left_right, original_node, original_node_left
+ # Ops:
+ # * node(original_node), original_node.left = original_node_left_right
+ # * original_node_left.right = original_node
+ # * node = original_node_left
+
+ node.should == original_node_left
+ node.right.should == original_node
+ node.right.left.should == original_node_left_right
+ end
+ end
+end
describe "Multiple assignment" do
context "with a single RHS value" do
@@ -46,7 +91,7 @@ describe "Multiple assignment" do
x = mock("multi-assign single RHS")
x.should_receive(:to_ary).and_return(1)
- lambda { a, b, c = x }.should raise_error(TypeError)
+ -> { a, b, c = x }.should.raise(TypeError)
end
it "does not call #to_a to convert an Object RHS when assigning a simple MLHS" do
@@ -77,7 +122,7 @@ describe "Multiple assignment" do
ary = [1, 2]
x = (a, b = ary)
- x.should equal(ary)
+ x.should.equal?(ary)
end
it "returns the RHS when it is an Array subclass" do
@@ -85,7 +130,7 @@ describe "Multiple assignment" do
ary = cls.new [1, 2]
x = (a, b = ary)
- x.should equal(ary)
+ x.should.equal?(ary)
end
it "does not call #to_ary on an Array subclass instance" do
@@ -127,7 +172,7 @@ describe "Multiple assignment" do
x = mock("multi-assign splat")
x.should_receive(:to_ary).and_return(1)
- lambda { *a = x }.should raise_error(TypeError)
+ -> { *a = x }.should.raise(TypeError)
end
it "does not call #to_ary on an Array subclass" do
@@ -144,8 +189,8 @@ describe "Multiple assignment" do
ary = cls.new [1, 2]
x = (*a = ary)
- x.should equal(ary)
- a.should be_an_instance_of(Array)
+ x.should.equal?(ary)
+ a.should.instance_of?(Array)
end
it "calls #to_ary to convert an Object RHS with MLHS" do
@@ -160,7 +205,7 @@ describe "Multiple assignment" do
x = mock("multi-assign splat")
x.should_receive(:to_ary).and_return(1)
- lambda { a, *b, c = x }.should raise_error(TypeError)
+ -> { a, *b, c = x }.should.raise(TypeError)
end
it "does not call #to_a to convert an Object RHS with a MLHS" do
@@ -256,7 +301,7 @@ describe "Multiple assignment" do
x = mock("multi-assign attributes")
x.should_receive(:m).and_return(y)
- lambda { a, b = x.m }.should raise_error(TypeError)
+ -> { a, b = x.m }.should.raise(TypeError)
end
it "assigns values from a RHS method call with receiver and arguments" do
@@ -287,8 +332,13 @@ describe "Multiple assignment" do
it "assigns indexed elements" do
a = []
- a[1], a[2] = 1
- a.should == [nil, 1, nil]
+ a[1], a[2] = 1, 2
+ a.should == [nil, 1, 2]
+
+ # with splatted argument
+ a = []
+ a[*[1]], a[*[2]] = 1, 2
+ a.should == [nil, 1, 2]
end
it "assigns constants" do
@@ -296,6 +346,9 @@ describe "Multiple assignment" do
SINGLE_RHS_1, SINGLE_RHS_2 = 1
[SINGLE_RHS_1, SINGLE_RHS_2].should == [1, nil]
end
+ ensure
+ VariableSpecs.send(:remove_const, :SINGLE_RHS_1)
+ VariableSpecs.send(:remove_const, :SINGLE_RHS_2)
end
end
@@ -310,11 +363,22 @@ describe "Multiple assignment" do
a.should == []
end
- it "calls #to_a to convert nil to an empty Array" do
- nil.should_receive(:to_a).and_return([])
+ ruby_version_is "4.0" do
+ it "converts nil to empty array without calling a method" do
+ nil.should_not_receive(:to_a)
- (*a = *nil).should == []
- a.should == []
+ (*a = *nil).should == []
+ a.should == []
+ end
+ end
+
+ ruby_version_is ""..."4.0" do
+ it "calls #to_a to convert nil to an empty Array" do
+ nil.should_receive(:to_a).and_return([])
+
+ (*a = *nil).should == []
+ a.should == []
+ end
end
it "does not call #to_a on an Array" do
@@ -329,7 +393,7 @@ describe "Multiple assignment" do
ary = [1, 2]
(a = *ary).should == [1, 2]
- a.should_not equal(ary)
+ a.should_not.equal?(ary)
end
it "does not call #to_a on an Array subclass" do
@@ -348,10 +412,20 @@ describe "Multiple assignment" do
x = (a = *ary)
x.should == [1, 2]
- x.should be_an_instance_of(Array)
+ x.should.instance_of?(Array)
a.should == [1, 2]
- a.should be_an_instance_of(Array)
+ a.should.instance_of?(Array)
+ end
+
+ it "unfreezes the array returned from calling 'to_a' on the splatted value" do
+ obj = Object.new
+ def obj.to_a
+ [1,2].freeze
+ end
+ res = *obj
+ res.should == [1,2]
+ res.should_not.frozen?
end
it "consumes values for an anonymous splat" do
@@ -407,7 +481,7 @@ describe "Multiple assignment" do
x = mock("multi-assign RHS splat")
x.should_receive(:to_a).and_return(1)
- lambda { *a = *x }.should raise_error(TypeError)
+ -> { *a = *x }.should.raise(TypeError)
end
it "does not call #to_ary to convert an Object RHS with a single splat LHS" do
@@ -453,7 +527,7 @@ describe "Multiple assignment" do
x = mock("multi-assign splat")
x.should_receive(:to_a).and_return(1)
- lambda { a = *x }.should raise_error(TypeError)
+ -> { a = *x }.should.raise(TypeError)
end
it "calls #to_a to convert an Object splat RHS when assigned to a simple MLHS" do
@@ -468,7 +542,7 @@ describe "Multiple assignment" do
x = mock("multi-assign splat")
x.should_receive(:to_a).and_return(1)
- lambda { a, b, c = *x }.should raise_error(TypeError)
+ -> { a, b, c = *x }.should.raise(TypeError)
end
it "does not call #to_ary to convert an Object splat RHS when assigned to a simple MLHS" do
@@ -491,7 +565,7 @@ describe "Multiple assignment" do
x = mock("multi-assign splat")
x.should_receive(:to_a).and_return(1)
- lambda { a, *b, c = *x }.should raise_error(TypeError)
+ -> { a, *b, c = *x }.should.raise(TypeError)
end
it "does not call #to_ary to convert an Object RHS with a MLHS" do
@@ -524,6 +598,8 @@ describe "Multiple assignment" do
(*SINGLE_SPLATTED_RHS) = *1
SINGLE_SPLATTED_RHS.should == [1]
end
+ ensure
+ VariableSpecs.send(:remove_const, :SINGLE_SPLATTED_RHS)
end
end
@@ -569,7 +645,7 @@ describe "Multiple assignment" do
x = mock("multi-assign splat MRHS")
x.should_receive(:to_a).and_return(1)
- lambda { a, *b = 1, *x }.should raise_error(TypeError)
+ -> { a, *b = 1, *x }.should.raise(TypeError)
end
it "does not call #to_ary to convert a splatted Object as part of a MRHS with a splat MRHS" do
@@ -592,7 +668,7 @@ describe "Multiple assignment" do
x = mock("multi-assign splat MRHS")
x.should_receive(:to_a).and_return(1)
- lambda { a, *b = *x, 1 }.should raise_error(TypeError)
+ -> { a, *b = *x, 1 }.should.raise(TypeError)
end
it "does not call #to_ary to convert a splatted Object with a splat MRHS" do
@@ -641,7 +717,7 @@ describe "Multiple assignment" do
x = mock("multi-assign mixed RHS")
x.should_receive(:to_ary).and_return(x)
- lambda { a, (b, c), d = 1, x, 3, 4 }.should raise_error(TypeError)
+ -> { a, (b, c), d = 1, x, 3, 4 }.should.raise(TypeError)
end
it "calls #to_a to convert a splatted Object value in a MRHS" do
@@ -665,7 +741,7 @@ describe "Multiple assignment" do
x = mock("multi-assign mixed splatted RHS")
x.should_receive(:to_ary).and_return(x)
- lambda { a, *b, (c, d) = 1, 2, 3, *x }.should raise_error(TypeError)
+ -> { a, *b, (c, d) = 1, 2, 3, *x }.should.raise(TypeError)
end
it "does not call #to_ary to convert an Object when the position receiving the value is a simple variable" do
@@ -705,12 +781,27 @@ describe "Multiple assignment" do
x.should == [1, 2, 3, 4, 5]
end
+ it "can be used to swap array elements" do
+ a = [1, 2]
+ a[0], a[1] = a[1], a[0]
+ a.should == [2, 1]
+ end
+
+ it "can be used to swap range of array elements" do
+ a = [1, 2, 3, 4]
+ a[0, 2], a[2, 2] = a[2, 2], a[0, 2]
+ a.should == [3, 4, 1, 2]
+ end
+
it "assigns RHS values to LHS constants" do
module VariableSpecs
MRHS_VALUES_1, MRHS_VALUES_2 = 1, 2
MRHS_VALUES_1.should == 1
MRHS_VALUES_2.should == 2
end
+ ensure
+ VariableSpecs.send(:remove_const, :MRHS_VALUES_1)
+ VariableSpecs.send(:remove_const, :MRHS_VALUES_2)
end
it "assigns all RHS values as an array to a single LHS constant" do
@@ -718,6 +809,8 @@ describe "Multiple assignment" do
MRHS_VALUES = 1, 2, 3
MRHS_VALUES.should == [1, 2, 3]
end
+ ensure
+ VariableSpecs.send(:remove_const, :MRHS_VALUES)
end
end
@@ -758,3 +851,80 @@ describe "A local variable assigned only within a conditional block" do
end
end
end
+
+describe 'Local variable shadowing' do
+ it "does not warn in verbose mode" do
+ result = nil
+
+ -> do
+ eval <<-CODE
+ a = [1, 2, 3]
+ result = a.map { |a| a = 3 }
+ CODE
+ end.should_not complain(verbose: true)
+
+ result.should == [3, 3, 3]
+ end
+end
+
+describe 'Allowed characters' do
+ it 'allows non-ASCII lowercased characters at the beginning' do
+ result = nil
+
+ eval <<-CODE
+ def test
+ μ = 1
+ end
+
+ result = test
+ CODE
+
+ result.should == 1
+ end
+
+ it 'parses a non-ASCII upcased character as a constant identifier' do
+ -> do
+ eval <<-CODE
+ def test
+ á¼BB = 1
+ end
+ CODE
+ end.should.raise(SyntaxError, /dynamic constant assignment/)
+ end
+end
+
+describe "Instance variables" do
+ context "when instance variable is uninitialized" do
+ it "doesn't warn about accessing uninitialized instance variable" do
+ obj = Object.new
+ def obj.foobar; a = @a; end
+
+ -> { obj.foobar }.should_not complain(verbose: true)
+ end
+
+ it "doesn't warn at lazy initialization" do
+ obj = Object.new
+ def obj.foobar; @a ||= 42; end
+
+ -> { obj.foobar }.should_not complain(verbose: true)
+ end
+ end
+
+ describe "global variable" do
+ context "when global variable is uninitialized" do
+ it "warns about accessing uninitialized global variable in verbose mode" do
+ obj = Object.new
+ def obj.foobar; a = $specs_uninitialized_global_variable; end
+
+ -> { obj.foobar }.should complain(/warning: global variable [`']\$specs_uninitialized_global_variable' not initialized/, verbose: true)
+ end
+
+ it "doesn't warn at lazy initialization" do
+ obj = Object.new
+ def obj.foobar; $specs_uninitialized_global_variable_lazy ||= 42; end
+
+ -> { obj.foobar }.should_not complain(verbose: true)
+ end
+ end
+ end
+end
diff --git a/spec/ruby/language/while_spec.rb b/spec/ruby/language/while_spec.rb
index 00e948e41f..b9bf32047d 100644
--- a/spec/ruby/language/while_spec.rb
+++ b/spec/ruby/language/while_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../spec_helper', __FILE__)
+require_relative '../spec_helper'
# while bool-expr [do]
# body
@@ -88,7 +88,7 @@ describe "The while expression" do
break if c
c = false
)
- end.should be_nil
+ end.should == nil
end
it "stops running body if interrupted by break in a begin ... end element op-assign-or value" do
@@ -99,7 +99,7 @@ describe "The while expression" do
break if c
c = false
end
- end.should be_nil
+ end.should == nil
end
it "stops running body if interrupted by break in a parenthesized element op-assign value" do
@@ -111,7 +111,7 @@ describe "The while expression" do
break if c
c = false
)
- end.should be_nil
+ end.should == nil
a.should == [1, 2]
end
@@ -123,7 +123,7 @@ describe "The while expression" do
break if c
c = false
end
- end.should be_nil
+ end.should == nil
a.should == [1, 2]
end
@@ -139,7 +139,7 @@ describe "The while expression" do
break unless d
d = false
)
- end.should be_nil
+ end.should == nil
end
it "stops running body if interrupted by break with unless in a begin ... end attribute op-assign-or value" do
@@ -153,7 +153,7 @@ describe "The while expression" do
break unless d
d = false
end
- end.should be_nil
+ end.should == nil
end
it "stops running body if interrupted by break in a parenthesized attribute op-assign-or value" do
@@ -168,7 +168,7 @@ describe "The while expression" do
break if c
c = false
)
- end.should be_nil
+ end.should == nil
end
it "stops running body if interrupted by break in a begin ... end attribute op-assign-or value" do
@@ -182,7 +182,7 @@ describe "The while expression" do
break if c
c = false
end
- end.should be_nil
+ end.should == nil
end
it "returns value passed to break if interrupted by break" do
@@ -330,7 +330,7 @@ describe "The while modifier with begin .. end block" do
a.should == [0, 1, 2, 4]
end
- it "restarts the current iteration without reevaluting condition with redo" do
+ it "restarts the current iteration without reevaluating condition with redo" do
a = []
i = 0
j = 0
diff --git a/spec/ruby/language/yield_spec.rb b/spec/ruby/language/yield_spec.rb
index 663110cbe6..3173f41b0c 100644
--- a/spec/ruby/language/yield_spec.rb
+++ b/spec/ruby/language/yield_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/yield', __FILE__)
+require_relative '../spec_helper'
+require_relative 'fixtures/yield'
# Note that these specs use blocks defined as { |*a| ... } to capture the
# arguments with which the block is invoked. This is slightly confusing
@@ -13,18 +13,22 @@ describe "The yield call" do
describe "taking no arguments" do
it "raises a LocalJumpError when the method is not passed a block" do
- lambda { @y.z }.should raise_error(LocalJumpError)
+ -> { @y.z }.should.raise(LocalJumpError)
end
it "ignores assignment to the explicit block argument and calls the passed block" do
@y.ze { 42 }.should == 42
end
+
+ it "does not pass a named block to the block being yielded to" do
+ @y.z() { |&block| block == nil }.should == true
+ end
end
describe "taking a single argument" do
describe "when no block is given" do
it "raises a LocalJumpError" do
- lambda { @y.s(1) }.should raise_error(LocalJumpError)
+ -> { @y.s(1) }.should.raise(LocalJumpError)
end
end
@@ -44,44 +48,48 @@ describe "The yield call" do
it "passes a single, multi-value Array" do
@y.s([1, 2, 3]) { |*a| a }.should == [[1, 2, 3]]
end
+
+ describe "with optional argument" do
+ it "does not destructure a single array argument" do
+ @y.s([1, 2, 3]) { |a = 99| a }.should == [1, 2, 3]
+ end
+ end
end
describe "yielding to a lambda" do
it "passes an empty Array when the argument is an empty Array" do
- @y.s([], &lambda { |*a| a }).should == [[]]
+ @y.s([], &-> *a { a }).should == [[]]
end
it "passes nil as a value" do
- @y.s(nil, &lambda { |*a| a }).should == [nil]
+ @y.s(nil, &-> *a { a }).should == [nil]
end
it "passes a single value" do
- @y.s(1, &lambda { |*a| a }).should == [1]
+ @y.s(1, &-> *a { a }).should == [1]
end
it "passes a single, multi-value Array" do
- @y.s([1, 2, 3], &lambda { |*a| a }).should == [[1, 2, 3]]
+ @y.s([1, 2, 3], &-> *a { a }).should == [[1, 2, 3]]
end
it "raises an ArgumentError if too few arguments are passed" do
- lambda {
- @y.s(1, &lambda { |a,b| [a,b] })
- }.should raise_error(ArgumentError)
+ -> {
+ @y.s(1, &-> a, b { [a,b] })
+ }.should.raise(ArgumentError)
end
- ruby_bug "#12705", "2.2"..."2.5" do
- it "should not destructure an Array into multiple arguments" do
- lambda {
- @y.s([1, 2], &lambda { |a,b| [a,b] })
- }.should raise_error(ArgumentError)
- end
+ it "should not destructure an Array into multiple arguments" do
+ -> {
+ @y.s([1, 2], &-> a, b { [a,b] })
+ }.should.raise(ArgumentError)
end
end
end
describe "taking multiple arguments" do
it "raises a LocalJumpError when the method is not passed a block" do
- lambda { @y.m(1, 2, 3) }.should raise_error(LocalJumpError)
+ -> { @y.m(1, 2, 3) }.should.raise(LocalJumpError)
end
it "passes the arguments to the block" do
@@ -93,21 +101,21 @@ describe "The yield call" do
end
it "raises an ArgumentError if too many arguments are passed to a lambda" do
- lambda {
- @y.m(1, 2, 3, &lambda { |a| })
- }.should raise_error(ArgumentError)
+ -> {
+ @y.m(1, 2, 3, &-> a { })
+ }.should.raise(ArgumentError)
end
it "raises an ArgumentError if too few arguments are passed to a lambda" do
- lambda {
- @y.m(1, 2, 3, &lambda { |a,b,c,d| })
- }.should raise_error(ArgumentError)
+ -> {
+ @y.m(1, 2, 3, &-> a, b, c, d { })
+ }.should.raise(ArgumentError)
end
end
describe "taking a single splatted argument" do
it "raises a LocalJumpError when the method is not passed a block" do
- lambda { @y.r(0) }.should raise_error(LocalJumpError)
+ -> { @y.r(0) }.should.raise(LocalJumpError)
end
it "passes a single value" do
@@ -139,7 +147,7 @@ describe "The yield call" do
describe "taking multiple arguments with a splat" do
it "raises a LocalJumpError when the method is not passed a block" do
- lambda { @y.rs(1, 2, [3, 4]) }.should raise_error(LocalJumpError)
+ -> { @y.rs(1, 2, [3, 4]) }.should.raise(LocalJumpError)
end
it "passes the arguments to the block" do
@@ -164,7 +172,7 @@ describe "The yield call" do
describe "taking matching arguments with splats and post args" do
it "raises a LocalJumpError when the method is not passed a block" do
- lambda { @y.rs(1, 2, [3, 4]) }.should raise_error(LocalJumpError)
+ -> { @y.rs(1, 2, [3, 4]) }.should.raise(LocalJumpError)
end
it "passes the arguments to the block" do
@@ -172,8 +180,47 @@ describe "The yield call" do
end
end
+ describe "taking a splat and a keyword argument" do
+ it "passes it as an array of the values and a hash" do
+ @y.k([1, 2]) { |*a| a }.should == [1, 2, {:b=>true}]
+ end
+ end
+
it "uses captured block of a block used in define_method" do
@y.deep(2).should == 4
end
+end
+
+describe "Using yield in a singleton class literal" do
+ it 'raises a SyntaxError' do
+ code = <<~RUBY
+ class << Object.new
+ yield
+ end
+ RUBY
+
+ -> { eval(code) }.should.raise(SyntaxError, /Invalid yield/)
+ end
+end
+
+describe "Using yield in non-lambda block" do
+ it 'raises a SyntaxError' do
+ code = <<~RUBY
+ 1.times { yield }
+ RUBY
+ -> { eval(code) }.should.raise(SyntaxError, /Invalid yield/)
+ end
+end
+
+describe "Using yield in a module literal" do
+ it 'raises a SyntaxError' do
+ code = <<~RUBY
+ module YieldSpecs::ModuleWithYield
+ yield
+ end
+ RUBY
+
+ -> { eval(code) }.should.raise(SyntaxError, /Invalid yield/)
+ end
end
diff --git a/spec/ruby/library/English/English_spec.rb b/spec/ruby/library/English/English_spec.rb
index 75a336eba2..bdc3774608 100644
--- a/spec/ruby/library/English/English_spec.rb
+++ b/spec/ruby/library/English/English_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'English'
@@ -7,165 +7,155 @@ describe "English" do
begin
raise "error"
rescue
- $ERROR_INFO.should_not be_nil
+ $ERROR_INFO.should_not == nil
$ERROR_INFO.should == $!
end
- $ERROR_INFO.should be_nil
+ $ERROR_INFO.should == nil
end
it "aliases $ERROR_POSITION to $@" do
begin
raise "error"
rescue
- $ERROR_POSITION.should_not be_nil
+ $ERROR_POSITION.should_not == nil
$ERROR_POSITION.should == $@
end
- $ERROR_POSITION.should be_nil
+ $ERROR_POSITION.should == nil
end
it "aliases $FS to $;" do
original = $;
- $; = ","
- $FS.should_not be_nil
+ suppress_warning {$; = ","}
+ $FS.should_not == nil
$FS.should == $;
- $; = original
+ suppress_warning {$; = original}
end
it "aliases $FIELD_SEPARATOR to $;" do
original = $;
- $; = ","
- $FIELD_SEPARATOR.should_not be_nil
+ suppress_warning {$; = ","}
+ $FIELD_SEPARATOR.should_not == nil
$FIELD_SEPARATOR.should == $;
- $; = original
+ suppress_warning {$; = original}
end
it "aliases $OFS to $," do
original = $,
- $, = "|"
- $OFS.should_not be_nil
+ suppress_warning {$, = "|"}
+ $OFS.should_not == nil
$OFS.should == $,
- $, = original
+ suppress_warning {$, = original}
end
it "aliases $OUTPUT_FIELD_SEPARATOR to $," do
original = $,
- $, = "|"
- $OUTPUT_FIELD_SEPARATOR.should_not be_nil
+ suppress_warning {$, = "|"}
+ $OUTPUT_FIELD_SEPARATOR.should_not == nil
$OUTPUT_FIELD_SEPARATOR.should == $,
- $, = original
+ suppress_warning {$, = original}
end
it "aliases $RS to $/" do
- $RS.should_not be_nil
+ $RS.should_not == nil
$RS.should == $/
end
it "aliases $INPUT_RECORD_SEPARATOR to $/" do
- $INPUT_RECORD_SEPARATOR.should_not be_nil
+ $INPUT_RECORD_SEPARATOR.should_not == nil
$INPUT_RECORD_SEPARATOR.should == $/
end
it "aliases $ORS to $\\" do
original = $\
- $\ = "\t"
- $ORS.should_not be_nil
+ suppress_warning {$\ = "\t"}
+ $ORS.should_not == nil
$ORS.should == $\
- $\ = original
+ suppress_warning {$\ = original}
end
it "aliases $OUTPUT_RECORD_SEPARATOR to $\\" do
original = $\
- $\ = "\t"
- $OUTPUT_RECORD_SEPARATOR.should_not be_nil
+ suppress_warning {$\ = "\t"}
+ $OUTPUT_RECORD_SEPARATOR.should_not == nil
$OUTPUT_RECORD_SEPARATOR.should == $\
- $\ = original
+ suppress_warning {$\ = original}
end
it "aliases $INPUT_LINE_NUMBER to $." do
- $INPUT_LINE_NUMBER.should_not be_nil
+ $INPUT_LINE_NUMBER.should_not == nil
$INPUT_LINE_NUMBER.should == $.
end
it "aliases $NR to $." do
- $NR.should_not be_nil
+ $NR.should_not == nil
$NR.should == $.
end
it "aliases $LAST_READ_LINE to $_ needs to be reviewed for spec completeness"
it "aliases $DEFAULT_OUTPUT to $>" do
- $DEFAULT_OUTPUT.should_not be_nil
+ $DEFAULT_OUTPUT.should_not == nil
$DEFAULT_OUTPUT.should == $>
end
it "aliases $DEFAULT_INPUT to $<" do
- $DEFAULT_INPUT.should_not be_nil
+ $DEFAULT_INPUT.should_not == nil
$DEFAULT_INPUT.should == $<
end
it "aliases $PID to $$" do
- $PID.should_not be_nil
+ $PID.should_not == nil
$PID.should == $$
end
it "aliases $PID to $$" do
- $PID.should_not be_nil
+ $PID.should_not == nil
$PID.should == $$
end
it "aliases $PROCESS_ID to $$" do
- $PROCESS_ID.should_not be_nil
+ $PROCESS_ID.should_not == nil
$PROCESS_ID.should == $$
end
it "aliases $CHILD_STATUS to $?" do
ruby_exe('exit 0')
- $CHILD_STATUS.should_not be_nil
+ $CHILD_STATUS.should_not == nil
$CHILD_STATUS.should == $?
end
it "aliases $LAST_MATCH_INFO to $~" do
/c(a)t/ =~ "cat"
- $LAST_MATCH_INFO.should_not be_nil
+ $LAST_MATCH_INFO.should_not == nil
$LAST_MATCH_INFO.should == $~
end
- it "aliases $IGNORECASE to $=" do
- $VERBOSE, verbose = nil, $VERBOSE
- begin
- $IGNORECASE.should_not be_nil
- $IGNORECASE.should == $=
- ensure
- $VERBOSE = verbose
- end
- end
-
it "aliases $ARGV to $*" do
- $ARGV.should_not be_nil
+ $ARGV.should_not == nil
$ARGV.should == $*
end
it "aliases $MATCH to $&" do
/c(a)t/ =~ "cat"
- $MATCH.should_not be_nil
+ $MATCH.should_not == nil
$MATCH.should == $&
end
it "aliases $PREMATCH to $`" do
/c(a)t/ =~ "cat"
- $PREMATCH.should_not be_nil
+ $PREMATCH.should_not == nil
$PREMATCH.should == $`
end
it "aliases $POSTMATCH to $'" do
/c(a)t/ =~ "cat"
- $POSTMATCH.should_not be_nil
+ $POSTMATCH.should_not == nil
$POSTMATCH.should == $'
end
it "aliases $LAST_PAREN_MATCH to $+" do
/c(a)t/ =~ "cat"
- $LAST_PAREN_MATCH.should_not be_nil
+ $LAST_PAREN_MATCH.should_not == nil
$LAST_PAREN_MATCH.should == $+
end
end
diff --git a/spec/ruby/library/English/alias_spec.rb b/spec/ruby/library/English/alias_spec.rb
new file mode 100644
index 0000000000..3ff92f964d
--- /dev/null
+++ b/spec/ruby/library/English/alias_spec.rb
@@ -0,0 +1,14 @@
+require_relative '../../spec_helper'
+require 'English'
+
+describe "English" do
+ it "aliases $! to $ERROR_INFO and $ERROR_INFO still returns an Exception with a backtrace" do
+ exception = (1 / 0 rescue $ERROR_INFO)
+ exception.should.is_a?(Exception)
+ exception.backtrace.should.is_a?(Array)
+ end
+
+ it "aliases $@ to $ERROR_POSITION and $ERROR_POSITION still returns a backtrace" do
+ (1 / 0 rescue $ERROR_POSITION).should.is_a?(Array)
+ end
+end
diff --git a/spec/ruby/library/abbrev/abbrev_spec.rb b/spec/ruby/library/abbrev/abbrev_spec.rb
index b2321cc679..61b0926597 100644
--- a/spec/ruby/library/abbrev/abbrev_spec.rb
+++ b/spec/ruby/library/abbrev/abbrev_spec.rb
@@ -1,12 +1,12 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'abbrev'
#test both Abbrev.abbrev and Array#abbrev in
#the same manner, as they're more or less aliases
#of one another
-[["Abbrev.abbrev", lambda {|a| Abbrev.abbrev(a)}],
- ["Array#abbrev", lambda {|a| a.abbrev}]
+[["Abbrev.abbrev", -> a { Abbrev.abbrev(a)}],
+ ["Array#abbrev", -> a { a.abbrev}]
].each do |(name, func)|
describe name do
diff --git a/spec/ruby/library/base64/decode64_spec.rb b/spec/ruby/library/base64/decode64_spec.rb
index 34d5ed6989..6dd33dddfe 100644
--- a/spec/ruby/library/base64/decode64_spec.rb
+++ b/spec/ruby/library/base64/decode64_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'base64'
@@ -6,4 +6,24 @@ describe "Base64#decode64" do
it "returns the Base64-decoded version of the given string" do
Base64.decode64("U2VuZCByZWluZm9yY2VtZW50cw==\n").should == "Send reinforcements"
end
+
+ it "returns the Base64-decoded version of the given shared string" do
+ Base64.decode64("base64: U2VuZCByZWluZm9yY2VtZW50cw==\n".split(" ").last).should == "Send reinforcements"
+ end
+
+ it "returns the Base64-decoded version of the given string with wrong padding" do
+ Base64.decode64("XU2VuZCByZWluZm9yY2VtZW50cw===").should == "]M\x95\xB9\x90\x81\xC9\x95\xA5\xB9\x99\xBD\xC9\x8D\x95\xB5\x95\xB9\xD1\xCC".b
+ end
+
+ it "returns the Base64-decoded version of the given string that contains an invalid character" do
+ Base64.decode64("%3D").should == "\xDC".b
+ end
+
+ it "returns a binary encoded string" do
+ Base64.decode64("SEk=").encoding.should == Encoding::BINARY
+ end
+
+ it "decodes without padding suffix ==" do
+ Base64.decode64("eyJrZXkiOnsibiI6InR0dCJ9fQ").should == "{\"key\":{\"n\":\"ttt\"}}"
+ end
end
diff --git a/spec/ruby/library/base64/encode64_spec.rb b/spec/ruby/library/base64/encode64_spec.rb
index 08df694e54..64de6257bc 100644
--- a/spec/ruby/library/base64/encode64_spec.rb
+++ b/spec/ruby/library/base64/encode64_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'base64'
@@ -11,4 +11,13 @@ describe "Base64#encode64" do
it "returns the Base64-encoded version of the given string" do
Base64.encode64('Send reinforcements').should == "U2VuZCByZWluZm9yY2VtZW50cw==\n"
end
+
+ it "returns the Base64-encoded version of the given shared string" do
+ Base64.encode64("Now is the time for all good coders\nto learn Ruby".split("\n").last).should ==
+ "dG8gbGVhcm4gUnVieQ==\n"
+ end
+
+ it "returns a US_ASCII encoded string" do
+ Base64.encode64("HI").encoding.should == Encoding::US_ASCII
+ end
end
diff --git a/spec/ruby/library/base64/strict_decode64_spec.rb b/spec/ruby/library/base64/strict_decode64_spec.rb
new file mode 100644
index 0000000000..7b52f0c922
--- /dev/null
+++ b/spec/ruby/library/base64/strict_decode64_spec.rb
@@ -0,0 +1,41 @@
+require_relative '../../spec_helper'
+
+require 'base64'
+
+describe "Base64#strict_decode64" do
+ it "returns the Base64-decoded version of the given string" do
+ Base64.strict_decode64("U2VuZCByZWluZm9yY2VtZW50cw==").should == "Send reinforcements"
+ end
+
+ it "returns the Base64-decoded version of the given shared string" do
+ Base64.strict_decode64("base64: U2VuZCByZWluZm9yY2VtZW50cw==".split(" ").last).should == "Send reinforcements"
+ end
+
+ it "raises ArgumentError when the given string contains CR" do
+ -> do
+ Base64.strict_decode64("U2VuZCByZWluZm9yY2VtZW50cw==\r")
+ end.should.raise(ArgumentError)
+ end
+
+ it "raises ArgumentError when the given string contains LF" do
+ -> do
+ Base64.strict_decode64("U2VuZCByZWluZm9yY2VtZW50cw==\n")
+ end.should.raise(ArgumentError)
+ end
+
+ it "raises ArgumentError when the given string has wrong padding" do
+ -> do
+ Base64.strict_decode64("=U2VuZCByZWluZm9yY2VtZW50cw==")
+ end.should.raise(ArgumentError)
+ end
+
+ it "raises ArgumentError when the given string contains an invalid character" do
+ -> do
+ Base64.strict_decode64("%3D")
+ end.should.raise(ArgumentError)
+ end
+
+ it "returns a binary encoded string" do
+ Base64.strict_decode64("SEk=").encoding.should == Encoding::BINARY
+ end
+end
diff --git a/spec/ruby/library/base64/strict_encode64_spec.rb b/spec/ruby/library/base64/strict_encode64_spec.rb
new file mode 100644
index 0000000000..7cabcf190c
--- /dev/null
+++ b/spec/ruby/library/base64/strict_encode64_spec.rb
@@ -0,0 +1,19 @@
+require_relative '../../spec_helper'
+
+require 'base64'
+
+describe "Base64#strict_encode64" do
+ it "returns the Base64-encoded version of the given string" do
+ Base64.strict_encode64("Now is the time for all good coders\nto learn Ruby").should ==
+ "Tm93IGlzIHRoZSB0aW1lIGZvciBhbGwgZ29vZCBjb2RlcnMKdG8gbGVhcm4gUnVieQ=="
+ end
+
+ it "returns the Base64-encoded version of the given shared string" do
+ Base64.strict_encode64("Now is the time for all good coders\nto learn Ruby".split("\n").last).should ==
+ "dG8gbGVhcm4gUnVieQ=="
+ end
+
+ it "returns a US_ASCII encoded string" do
+ Base64.strict_encode64("HI").encoding.should == Encoding::US_ASCII
+ end
+end
diff --git a/spec/ruby/library/base64/urlsafe_decode64_spec.rb b/spec/ruby/library/base64/urlsafe_decode64_spec.rb
index bea9a7cefb..1b813ee1b9 100644
--- a/spec/ruby/library/base64/urlsafe_decode64_spec.rb
+++ b/spec/ruby/library/base64/urlsafe_decode64_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'base64'
@@ -13,15 +13,7 @@ describe "Base64#urlsafe_decode64" do
decoded.should == '"Being disintegrated makes me ve-ry an-gry!" <huff, huff>'
end
- ruby_version_is ""..."2.3" do
- it "requires padding" do
- lambda { Base64.urlsafe_decode64("MQ") }.should raise_error(ArgumentError)
- end
- end
-
- ruby_version_is "2.3" do
- it "does not require padding" do
- Base64.urlsafe_decode64("MQ").should == "1"
- end
+ it "does not require padding" do
+ Base64.urlsafe_decode64("MQ").should == "1"
end
end
diff --git a/spec/ruby/library/base64/urlsafe_encode64_spec.rb b/spec/ruby/library/base64/urlsafe_encode64_spec.rb
index 32fce72603..de1f235cea 100644
--- a/spec/ruby/library/base64/urlsafe_encode64_spec.rb
+++ b/spec/ruby/library/base64/urlsafe_encode64_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'base64'
@@ -13,10 +13,8 @@ describe "Base64#urlsafe_encode64" do
encoded.should == 'IkJlaW5nIGRpc2ludGVncmF0ZWQgbWFrZXMgbWUgdmUtcnkgYW4tZ3J5ISIgPGh1ZmYsIGh1ZmY-'
end
- ruby_version_is "2.3" do
- it "makes padding optional" do
- Base64.urlsafe_encode64("1", padding: false).should == "MQ"
- Base64.urlsafe_encode64("1").should == "MQ=="
- end
+ it "makes padding optional" do
+ Base64.urlsafe_encode64("1", padding: false).should == "MQ"
+ Base64.urlsafe_encode64("1").should == "MQ=="
end
end
diff --git a/spec/ruby/library/bigdecimal/BigDecimal_spec.rb b/spec/ruby/library/bigdecimal/BigDecimal_spec.rb
new file mode 100644
index 0000000000..6adebabe84
--- /dev/null
+++ b/spec/ruby/library/bigdecimal/BigDecimal_spec.rb
@@ -0,0 +1,239 @@
+require_relative '../../spec_helper'
+require 'bigdecimal'
+
+describe "BigDecimal" do
+ it "is not defined unless it is required" do
+ ruby_exe('puts Object.const_defined?(:BigDecimal)').should == "false\n"
+ end
+end
+
+describe "Kernel#BigDecimal" do
+
+ it "creates a new object of class BigDecimal" do
+ BigDecimal("3.14159").should.is_a?(BigDecimal)
+ (0..9).each {|i|
+ BigDecimal("1#{i}").should == 10 + i
+ BigDecimal("-1#{i}").should == -10 - i
+ BigDecimal("1E#{i}").should == 10**i
+ BigDecimal("1000000E-#{i}").should == 10**(6-i).to_f
+ # ^ to_f to avoid Rational type
+ }
+ (1..9).each {|i|
+ BigDecimal("100.#{i}").to_s.should =~ /\A0\.100#{i}E3\z/i
+ BigDecimal("-100.#{i}").to_s.should =~ /\A-0\.100#{i}E3\z/i
+ }
+ end
+
+ it "BigDecimal(Rational) with bigger-than-double numerator" do
+ rational = 99999999999999999999/100r
+ rational.numerator.should > 2**64
+ BigDecimal(rational, 100).to_s.should == "0.99999999999999999999e18"
+ end
+
+ it "accepts significant digits >= given precision" do
+ BigDecimal("3.1415923", 10).should == BigDecimal("3.1415923")
+ end
+
+ it "determines precision from initial value" do
+ pi_string = "3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593014782083152134043"
+ BigDecimal(pi_string).precision.should == pi_string.size-1
+ end
+
+ it "ignores leading and trailing whitespace" do
+ BigDecimal(" \t\n \r1234\t\r\n ").should == BigDecimal("1234")
+ BigDecimal(" \t\n \rNaN \n").should.nan?
+ BigDecimal(" \t\n \rInfinity \n").infinite?.should == 1
+ BigDecimal(" \t\n \r-Infinity \n").infinite?.should == -1
+ end
+
+ it "coerces the value argument with #to_str" do
+ initial = mock("value")
+ initial.should_receive(:to_str).and_return("123")
+ BigDecimal(initial).should == BigDecimal("123")
+ end
+
+ it "does not ignores trailing garbage" do
+ -> { BigDecimal("123E45ruby") }.should.raise(ArgumentError)
+ -> { BigDecimal("123x45") }.should.raise(ArgumentError)
+ -> { BigDecimal("123.4%E5") }.should.raise(ArgumentError)
+ -> { BigDecimal("1E2E3E4E5E") }.should.raise(ArgumentError)
+ end
+
+ it "raises ArgumentError for invalid strings" do
+ -> { BigDecimal("ruby") }.should.raise(ArgumentError)
+ -> { BigDecimal(" \t\n \r-\t\t\tInfinity \n") }.should.raise(ArgumentError)
+ end
+
+ it "allows omitting the integer part" do
+ BigDecimal(".123").should == BigDecimal("0.123")
+ end
+
+ it "process underscores as Float()" do
+ reference = BigDecimal("12345.67E89")
+
+ BigDecimal("12_345.67E89").should == reference
+ -> { BigDecimal("1_2_3_4_5_._6____7_E89") }.should.raise(ArgumentError)
+ -> { BigDecimal("12345_.67E_8__9_") }.should.raise(ArgumentError)
+ end
+
+ it "accepts NaN and [+-]Infinity" do
+ BigDecimal("NaN").should.nan?
+
+ pos_inf = BigDecimal("Infinity")
+ pos_inf.should_not.finite?
+ pos_inf.should > 0
+ pos_inf.should == BigDecimal("+Infinity")
+
+ neg_inf = BigDecimal("-Infinity")
+ neg_inf.should_not.finite?
+ neg_inf.should < 0
+ end
+
+ describe "with exception: false" do
+ it "returns nil for invalid strings" do
+ BigDecimal("invalid", exception: false).should == nil
+ BigDecimal("0invalid", exception: false).should == nil
+ BigDecimal("invalid0", exception: false).should == nil
+ if BigDecimal::VERSION >= "3.1.9"
+ BigDecimal("0.", exception: false).to_i.should == 0
+ else
+ BigDecimal("0.", exception: false).should == nil
+ end
+ end
+ end
+
+ describe "accepts NaN and [+-]Infinity as Float values" do
+ it "works without an explicit precision" do
+ BigDecimal(Float::NAN).should.nan?
+
+ pos_inf = BigDecimal(Float::INFINITY)
+ pos_inf.should_not.finite?
+ pos_inf.should > 0
+ pos_inf.should == BigDecimal("+Infinity")
+
+ neg_inf = BigDecimal(-Float::INFINITY)
+ neg_inf.should_not.finite?
+ neg_inf.should < 0
+ end
+
+ it "works with an explicit precision" do
+ BigDecimal(Float::NAN, Float::DIG).should.nan?
+
+ pos_inf = BigDecimal(Float::INFINITY, Float::DIG)
+ pos_inf.should_not.finite?
+ pos_inf.should > 0
+ pos_inf.should == BigDecimal("+Infinity")
+
+ neg_inf = BigDecimal(-Float::INFINITY, Float::DIG)
+ neg_inf.should_not.finite?
+ neg_inf.should < 0
+ end
+ end
+
+ it "allows for [eEdD] as exponent separator" do
+ reference = BigDecimal("12345.67E89")
+
+ BigDecimal("12345.67e89").should == reference
+ BigDecimal("12345.67E89").should == reference
+ BigDecimal("12345.67d89").should == reference
+ BigDecimal("12345.67D89").should == reference
+ end
+
+ it "allows for varying signs" do
+ reference = BigDecimal("123.456E1")
+
+ BigDecimal("+123.456E1").should == reference
+ BigDecimal("-123.456E1").should == -reference
+ BigDecimal("123.456E+1").should == reference
+ BigDecimal("12345.6E-1").should == reference
+ BigDecimal("+123.456E+1").should == reference
+ BigDecimal("+12345.6E-1").should == reference
+ BigDecimal("-123.456E+1").should == -reference
+ BigDecimal("-12345.6E-1").should == -reference
+ end
+
+ version_is BigDecimal::VERSION, "3.3.0" do
+ it "allows Float without precision" do
+ BigDecimal(1.2).should == BigDecimal("1.2")
+ end
+ end
+
+ it "returns appropriate BigDecimal zero for signed zero" do
+ BigDecimal(-0.0, Float::DIG).sign.should == -1
+ BigDecimal(0.0, Float::DIG).sign.should == 1
+ end
+
+ it "pre-coerces long integers" do
+ BigDecimal(3).add(1 << 50, 3).should == BigDecimal('0.113e16')
+ end
+
+ it "does not call to_s when calling inspect" do
+ value = BigDecimal('44.44')
+ value.to_s.should == '0.4444e2'
+ value.inspect.should == '0.4444e2'
+
+ ruby_exe( <<-'EOF').should == "cheese 0.4444e2"
+ require 'bigdecimal'
+ module BigDecimalOverride
+ def to_s; "cheese"; end
+ end
+ BigDecimal.prepend BigDecimalOverride
+ value = BigDecimal('44.44')
+ print "#{value.to_s} #{value.inspect}"
+ EOF
+ end
+
+ describe "when interacting with Rational" do
+ before :each do
+ @a = BigDecimal('166.666666666')
+ @b = Rational(500, 3)
+ @c = @a - @b
+ end
+
+ # Check the input is as we understand it
+
+ it "has the LHS print as expected" do
+ @a.to_s.should == "0.166666666666e3"
+ @a.to_f.to_s.should == "166.666666666"
+ Float(@a).to_s.should == "166.666666666"
+ end
+
+ it "has the RHS print as expected" do
+ @b.to_s.should == "500/3"
+ @b.to_f.to_s.should == "166.66666666666666"
+ Float(@b).to_s.should == "166.66666666666666"
+ end
+
+ it "produces the expected result when done via Float" do
+ (Float(@a) - Float(@b)).to_s.should == "-6.666596163995564e-10"
+ end
+
+ it "produces the expected result when done via to_f" do
+ (@a.to_f - @b.to_f).to_s.should == "-6.666596163995564e-10"
+ end
+
+ # Check underlying methods work as we understand
+
+ it "BigDecimal(Rational, 18) produces the result we expect" do
+ BigDecimal(@b, 18).to_s.should == "0.166666666666666667e3"
+ end
+
+ # Check the top-level expression works as we expect
+
+ it "produces a BigDecimal" do
+ @c.class.should == BigDecimal
+ end
+
+ it "produces the expected result" do
+ @c.round(15).should == BigDecimal("-0.666667e-9")
+ @c.round(15).to_s.should == "-0.666667e-9"
+ end
+
+ it "produces the correct class for other arithmetic operators" do
+ (@a + @b).class.should == BigDecimal
+ (@a * @b).class.should == BigDecimal
+ (@a / @b).class.should == BigDecimal
+ (@a % @b).class.should == BigDecimal
+ end
+ end
+end
diff --git a/spec/ruby/library/bigdecimal/abs_spec.rb b/spec/ruby/library/bigdecimal/abs_spec.rb
index 9027abfb47..95dc45a905 100644
--- a/spec/ruby/library/bigdecimal/abs_spec.rb
+++ b/spec/ruby/library/bigdecimal/abs_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'bigdecimal'
describe "BigDecimal#abs" do
@@ -38,7 +38,7 @@ describe "BigDecimal#abs" do
it "properly handles special values" do
@infinity.abs.should == @infinity
@infinity_minus.abs.should == @infinity
- @nan.abs.nan?.should == true # have to do it this way, since == doesn't work on NaN
+ @nan.abs.should.nan? # have to do it this way, since == doesn't work on NaN
@zero.abs.should == 0
@zero.abs.sign.should == BigDecimal::SIGN_POSITIVE_ZERO
@zero_pos.abs.should == 0
diff --git a/spec/ruby/library/bigdecimal/add_spec.rb b/spec/ruby/library/bigdecimal/add_spec.rb
index 6136c9dccb..a4237298f4 100644
--- a/spec/ruby/library/bigdecimal/add_spec.rb
+++ b/spec/ruby/library/bigdecimal/add_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
require 'bigdecimal'
@@ -24,7 +24,7 @@ describe "BigDecimal#add" do
end
it "returns a + b with given precision" do
- # documentation states, that precision ist optional, but it ain't,
+ # documentation states that precision is optional, but it ain't,
@two.add(@one, 1).should == @three
@one .add(@two, 1).should == @three
@one.add(@one_minus, 1).should == @zero
@@ -60,7 +60,7 @@ describe "BigDecimal#add" do
end
# TODO:
-# http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/17374
+# https://blade.ruby-lang.org/ruby-core/17374
#
# This doesn't work on MRI and looks like a bug to me:
# one can use BigDecimal + Float, but not Bigdecimal.add(Float)
@@ -73,6 +73,12 @@ describe "BigDecimal#add" do
# BigDecimal("0.88").add(0.0, 1).should == BigDecimal("0.9")
# end
+ describe "with Rational" do
+ it "produces a BigDecimal" do
+ (@three + Rational(500, 2)).should == BigDecimal("0.253e3")
+ end
+ end
+
it "favors the precision specified in the second argument over the global limit" do
BigDecimalSpecs.with_limit(1) do
BigDecimal('0.888').add(@zero, 3).should == BigDecimal('0.888')
@@ -122,8 +128,8 @@ describe "BigDecimal#add" do
end
it "returns NaN if NaN is involved" do
- @one.add(@nan, 10000).nan?.should == true
- @nan.add(@one, 1).nan?.should == true
+ @one.add(@nan, 10000).should.nan?
+ @nan.add(@one, 1).should.nan?
end
it "returns Infinity or -Infinity if these are involved" do
@@ -152,28 +158,28 @@ describe "BigDecimal#add" do
end
it "returns NaN if Infinity + (- Infinity)" do
- @infinity.add(@infinity_minus, 10000).nan?.should == true
- @infinity_minus.add(@infinity, 10000).nan?.should == true
+ @infinity.add(@infinity_minus, 10000).should.nan?
+ @infinity_minus.add(@infinity, 10000).should.nan?
end
it "raises TypeError when adds nil" do
- lambda {
+ -> {
@one.add(nil, 10)
- }.should raise_error(TypeError)
- lambda {
+ }.should.raise(TypeError)
+ -> {
@one.add(nil, 0)
- }.should raise_error(TypeError)
+ }.should.raise(TypeError)
end
it "raises TypeError when precision parameter is nil" do
- lambda {
+ -> {
@one.add(@one, nil)
- }.should raise_error(TypeError)
+ }.should.raise(TypeError)
end
it "raises ArgumentError when precision parameter is negative" do
- lambda {
+ -> {
@one.add(@one, -10)
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
end
end
diff --git a/spec/ruby/library/bigdecimal/case_compare_spec.rb b/spec/ruby/library/bigdecimal/case_compare_spec.rb
index dcbde80e85..1f1d223d6a 100644
--- a/spec/ruby/library/bigdecimal/case_compare_spec.rb
+++ b/spec/ruby/library/bigdecimal/case_compare_spec.rb
@@ -1,7 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/eql.rb', __FILE__)
+require_relative '../../spec_helper'
+require 'bigdecimal'
describe "BigDecimal#===" do
- it_behaves_like(:bigdecimal_eql, :===)
+ it "is an alias of BigDecimal#==" do
+ BigDecimal.instance_method(:===).should == BigDecimal.instance_method(:==)
+ end
end
diff --git a/spec/ruby/library/bigdecimal/ceil_spec.rb b/spec/ruby/library/bigdecimal/ceil_spec.rb
index d8829411b9..3d94b8e578 100644
--- a/spec/ruby/library/bigdecimal/ceil_spec.rb
+++ b/spec/ruby/library/bigdecimal/ceil_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'bigdecimal'
describe "BigDecimal#ceil" do
@@ -48,9 +48,9 @@ describe "BigDecimal#ceil" do
end
it "raise exception, if self is special value" do
- lambda { @infinity.ceil }.should raise_error(FloatDomainError)
- lambda { @infinity_neg.ceil }.should raise_error(FloatDomainError)
- lambda { @nan.ceil }.should raise_error(FloatDomainError)
+ -> { @infinity.ceil }.should.raise(FloatDomainError)
+ -> { @infinity_neg.ceil }.should.raise(FloatDomainError)
+ -> { @nan.ceil }.should.raise(FloatDomainError)
end
it "returns n digits right of the decimal point if given n > 0" do
diff --git a/spec/ruby/library/bigdecimal/clone_spec.rb b/spec/ruby/library/bigdecimal/clone_spec.rb
new file mode 100644
index 0000000000..979cc4c8e9
--- /dev/null
+++ b/spec/ruby/library/bigdecimal/clone_spec.rb
@@ -0,0 +1,8 @@
+require_relative '../../spec_helper'
+require 'bigdecimal'
+
+describe "BigDecimal#clone" do
+ it "is an alias of BigDecimal#dup" do
+ BigDecimal.instance_method(:clone).should == BigDecimal.instance_method(:dup)
+ end
+end
diff --git a/spec/ruby/library/bigdecimal/coerce_spec.rb b/spec/ruby/library/bigdecimal/coerce_spec.rb
index 1c63ddf2bc..1e5c73f969 100644
--- a/spec/ruby/library/bigdecimal/coerce_spec.rb
+++ b/spec/ruby/library/bigdecimal/coerce_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'bigdecimal'
describe "BigDecimal#coerce" do
diff --git a/spec/ruby/library/bigdecimal/comparison_spec.rb b/spec/ruby/library/bigdecimal/comparison_spec.rb
index c4de8348b2..c53187b727 100644
--- a/spec/ruby/library/bigdecimal/comparison_spec.rb
+++ b/spec/ruby/library/bigdecimal/comparison_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'bigdecimal'
describe "BigDecimal#<=>" do
@@ -18,7 +18,7 @@ describe "BigDecimal#<=>" do
def coerce(other)
return [other, BigDecimal('123')]
end
- def >= (other)
+ def >=(other)
BigDecimal('123') >= other
end
end
diff --git a/spec/ruby/library/bigdecimal/constants_spec.rb b/spec/ruby/library/bigdecimal/constants_spec.rb
new file mode 100644
index 0000000000..f2cc42dfc9
--- /dev/null
+++ b/spec/ruby/library/bigdecimal/constants_spec.rb
@@ -0,0 +1,70 @@
+require_relative '../../spec_helper'
+require 'bigdecimal'
+
+describe "BigDecimal constants" do
+ it "defines a VERSION value" do
+ BigDecimal.const_defined?(:VERSION).should == true
+ end
+
+ it "has a BASE value" do
+ # The actual one is decided based on HAVE_INT64_T in MRI,
+ # which is hard to check here.
+ [10000, 1000000000].should.include?(BigDecimal::BASE)
+ end
+
+ it "has a NaN value" do
+ BigDecimal::NAN.nan?.should == true
+ end
+
+ it "has an INFINITY value" do
+ BigDecimal::INFINITY.infinite?.should == 1
+ end
+
+ describe "exception-related constants" do
+ [
+ [:EXCEPTION_ALL, 0xff],
+ [:EXCEPTION_INFINITY, 0x01],
+ [:EXCEPTION_NaN, 0x02],
+ [:EXCEPTION_UNDERFLOW, 0x04],
+ [:EXCEPTION_OVERFLOW, 0x01],
+ [:EXCEPTION_ZERODIVIDE, 0x10]
+ ].each do |const, value|
+ it "has a #{const} value" do
+ BigDecimal.const_get(const).should == value
+ end
+ end
+ end
+
+ describe "rounding-related constants" do
+ [
+ [:ROUND_MODE, 0x100],
+ [:ROUND_UP, 1],
+ [:ROUND_DOWN, 2],
+ [:ROUND_HALF_UP, 3],
+ [:ROUND_HALF_DOWN, 4],
+ [:ROUND_CEILING, 5],
+ [:ROUND_FLOOR, 6],
+ [:ROUND_HALF_EVEN, 7]
+ ].each do |const, value|
+ it "has a #{const} value" do
+ BigDecimal.const_get(const).should == value
+ end
+ end
+ end
+
+ describe "sign-related constants" do
+ [
+ [:SIGN_NaN, 0],
+ [:SIGN_POSITIVE_ZERO, 1],
+ [:SIGN_NEGATIVE_ZERO, -1],
+ [:SIGN_POSITIVE_FINITE, 2],
+ [:SIGN_NEGATIVE_FINITE, -2],
+ [:SIGN_POSITIVE_INFINITE, 3],
+ [:SIGN_NEGATIVE_INFINITE, -3]
+ ].each do |const, value|
+ it "has a #{const} value" do
+ BigDecimal.const_get(const).should == value
+ end
+ end
+ end
+end
diff --git a/spec/ruby/library/bigdecimal/core_spec.rb b/spec/ruby/library/bigdecimal/core_spec.rb
new file mode 100644
index 0000000000..8f64fdf388
--- /dev/null
+++ b/spec/ruby/library/bigdecimal/core_spec.rb
@@ -0,0 +1,62 @@
+require_relative '../../spec_helper'
+require 'bigdecimal'
+
+describe "Core extension by bigdecimal" do
+ context "Integer#coerce" do
+ it "produces Floats" do
+ x, y = 3.coerce(BigDecimal("3.4"))
+ x.class.should == Float
+ x.should == 3.4
+ y.class.should == Float
+ y.should == 3.0
+ end
+ end
+
+ describe "Time.at passed BigDecimal" do
+ it "doesn't round input value" do
+ Time.at(BigDecimal('1.1')).to_f.should == 1.1
+ end
+ end
+
+ describe "BigDecimal#log" do
+ it "handles high-precision Rational arguments" do
+ # log(BigDecimal(r, 50), 50)
+ result1 = BigDecimal('0.22314354220170971436137296411949880462556361100856e0')
+ # log(BigDecimal(r, 1000), 50)
+ result2 = BigDecimal('0.22314354220170971436137296411949880462556361100853e0')
+ r = Rational(1_234_567_890, 987_654_321)
+ [result1, result2].should.include?(BigMath.log(r, 50).mult(1, 50))
+ end
+ end
+
+ describe "Rational#coerce" do
+ it "returns the passed argument, self as Float, when given a Float" do
+ result = Rational(3, 4).coerce(1.0)
+ result.should == [1.0, 0.75]
+ result.first.is_a?(Float).should == true
+ result.last.is_a?(Float).should == true
+ end
+
+ it "returns the passed argument, self as Rational, when given an Integer" do
+ result = Rational(3, 4).coerce(10)
+ result.should == [Rational(10, 1), Rational(3, 4)]
+ result.first.is_a?(Rational).should == true
+ result.last.is_a?(Rational).should == true
+ end
+
+ it "coerces to Rational, when given a Complex" do
+ Rational(3, 4).coerce(Complex(5)).should == [Rational(5, 1), Rational(3, 4)]
+ Rational(12, 4).coerce(Complex(5, 1)).should == [Complex(5, 1), Complex(3)]
+ end
+
+ it "returns [argument, self] when given a Rational" do
+ Rational(3, 7).coerce(Rational(9, 2)).should == [Rational(9, 2), Rational(3, 7)]
+ end
+
+ it "raises an error when passed a BigDecimal" do
+ -> {
+ Rational(500, 3).coerce(BigDecimal('166.666666666'))
+ }.should.raise(TypeError, /BigDecimal can't be coerced into Rational/)
+ end
+ end
+end
diff --git a/spec/ruby/library/bigdecimal/div_spec.rb b/spec/ruby/library/bigdecimal/div_spec.rb
index f8f8ac4e5e..967d8b5221 100644
--- a/spec/ruby/library/bigdecimal/div_spec.rb
+++ b/spec/ruby/library/bigdecimal/div_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/quo', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/quo'
require 'bigdecimal'
describe "BigDecimal#div with precision set to 0" do
@@ -42,10 +42,18 @@ describe "BigDecimal#div" do
}
end
+ describe "with Object" do
+ it "tries to coerce the other operand to self" do
+ object = mock("Object")
+ object.should_receive(:coerce).with(@one).and_return([@one, @two])
+ @one.div(object).should == @zero
+ end
+ end
+
it "raises FloatDomainError if NaN is involved" do
- lambda { @one.div(@nan) }.should raise_error(FloatDomainError)
- lambda { @nan.div(@one) }.should raise_error(FloatDomainError)
- lambda { @nan.div(@nan) }.should raise_error(FloatDomainError)
+ -> { @one.div(@nan) }.should.raise(FloatDomainError)
+ -> { @nan.div(@one) }.should.raise(FloatDomainError)
+ -> { @nan.div(@nan) }.should.raise(FloatDomainError)
end
it "returns 0 if divided by Infinity and no precision given" do
@@ -61,30 +69,30 @@ describe "BigDecimal#div" do
end
it "raises ZeroDivisionError if divided by zero and no precision given" do
- lambda { @one.div(@zero) }.should raise_error(ZeroDivisionError)
- lambda { @one.div(@zero_plus) }.should raise_error(ZeroDivisionError)
- lambda { @one.div(@zero_minus) }.should raise_error(ZeroDivisionError)
-
- lambda { @zero.div(@zero) }.should raise_error(ZeroDivisionError)
- lambda { @zero_minus.div(@zero_plus) }.should raise_error(ZeroDivisionError)
- lambda { @zero_minus.div(@zero_minus) }.should raise_error(ZeroDivisionError)
- lambda { @zero_plus.div(@zero_minus) }.should raise_error(ZeroDivisionError)
+ -> { @one.div(@zero) }.should.raise(ZeroDivisionError)
+ -> { @one.div(@zero_plus) }.should.raise(ZeroDivisionError)
+ -> { @one.div(@zero_minus) }.should.raise(ZeroDivisionError)
+
+ -> { @zero.div(@zero) }.should.raise(ZeroDivisionError)
+ -> { @zero_minus.div(@zero_plus) }.should.raise(ZeroDivisionError)
+ -> { @zero_minus.div(@zero_minus) }.should.raise(ZeroDivisionError)
+ -> { @zero_plus.div(@zero_minus) }.should.raise(ZeroDivisionError)
end
it "returns NaN if zero is divided by zero" do
- @zero.div(@zero, 0).nan?.should == true
- @zero_minus.div(@zero_plus, 0).nan?.should == true
- @zero_plus.div(@zero_minus, 0).nan?.should == true
+ @zero.div(@zero, 0).should.nan?
+ @zero_minus.div(@zero_plus, 0).should.nan?
+ @zero_plus.div(@zero_minus, 0).should.nan?
- @zero.div(@zero, 10).nan?.should == true
- @zero_minus.div(@zero_plus, 10).nan?.should == true
- @zero_plus.div(@zero_minus, 10).nan?.should == true
+ @zero.div(@zero, 10).should.nan?
+ @zero_minus.div(@zero_plus, 10).should.nan?
+ @zero_plus.div(@zero_minus, 10).should.nan?
end
it "raises FloatDomainError if (+|-) Infinity divided by 1 and no precision given" do
- lambda { @infinity_minus.div(@one) }.should raise_error(FloatDomainError)
- lambda { @infinity.div(@one) }.should raise_error(FloatDomainError)
- lambda { @infinity_minus.div(@one_minus) }.should raise_error(FloatDomainError)
+ -> { @infinity_minus.div(@one) }.should.raise(FloatDomainError)
+ -> { @infinity.div(@one) }.should.raise(FloatDomainError)
+ -> { @infinity_minus.div(@one_minus) }.should.raise(FloatDomainError)
end
it "returns (+|-)Infinity if (+|-)Infinity by 1 and precision given" do
@@ -94,8 +102,8 @@ describe "BigDecimal#div" do
end
it "returns NaN if Infinity / ((+|-) Infinity)" do
- @infinity.div(@infinity_minus, 100000).nan?.should == true
- @infinity_minus.div(@infinity, 1).nan?.should == true
+ @infinity.div(@infinity_minus, 100000).should.nan?
+ @infinity_minus.div(@infinity, 1).should.nan?
end
diff --git a/spec/ruby/library/bigdecimal/divide_spec.rb b/spec/ruby/library/bigdecimal/divide_spec.rb
index 4dfe2702bb..c62b23557d 100644
--- a/spec/ruby/library/bigdecimal/divide_spec.rb
+++ b/spec/ruby/library/bigdecimal/divide_spec.rb
@@ -1,7 +1,17 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/quo', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/quo'
require 'bigdecimal'
describe "BigDecimal#/" do
it_behaves_like :bigdecimal_quo, :/, []
+
+ before :each do
+ @three = BigDecimal("3")
+ end
+
+ describe "with Rational" do
+ it "produces a BigDecimal" do
+ (@three / Rational(500, 2)).should == BigDecimal("0.12e-1")
+ end
+ end
end
diff --git a/spec/ruby/library/bigdecimal/divmod_spec.rb b/spec/ruby/library/bigdecimal/divmod_spec.rb
index 839a289ab6..d170c6f845 100644
--- a/spec/ruby/library/bigdecimal/divmod_spec.rb
+++ b/spec/ruby/library/bigdecimal/divmod_spec.rb
@@ -1,12 +1,12 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/modulo', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/modulo'
require 'bigdecimal'
module DivmodSpecs
def self.check_both_nan(array)
array.length.should == 2
- array[0].nan?.should == true
- array[1].nan?.should == true
+ array[0].should.nan?
+ array[1].should.nan?
end
def self.check_both_bigdecimal(array)
array.length.should == 2
@@ -33,14 +33,16 @@ describe "BigDecimal#mod_part_of_divmod" do
end
end
- it_behaves_like :bigdecimal_modulo, :mod_part_of_divmod
+ version_is BigDecimal::VERSION, ""..."4.0.0" do
+ it_behaves_like :bigdecimal_modulo, :mod_part_of_divmod
+ end
it "raises ZeroDivisionError if other is zero" do
- bd5667 = BigDecimal.new("5667.19")
-
- lambda { bd5667.send(@method, 0) }.should raise_error(ZeroDivisionError)
- lambda { bd5667.send(@method, BigDecimal("0")) }.should raise_error(ZeroDivisionError)
- lambda { @zero.send(@method, @zero) }.should raise_error(ZeroDivisionError)
+ bd5667 = BigDecimal("5667.19")
+ zero = BigDecimal("0")
+ -> { bd5667.mod_part_of_divmod(0) }.should.raise(ZeroDivisionError)
+ -> { bd5667.mod_part_of_divmod(BigDecimal("0")) }.should.raise(ZeroDivisionError)
+ -> { zero.mod_part_of_divmod(zero) }.should.raise(ZeroDivisionError)
end
end
@@ -73,14 +75,25 @@ describe "BigDecimal#divmod" do
@zeroes = [@zero, @zero_pos, @zero_neg]
end
- it "divides value, returns an array" do
- res = @a.divmod(5)
- res.kind_of?(Array).should == true
+ version_is BigDecimal::VERSION, ""..."4.0.0" do
+ it "divides value, returns [BigDecimal, BigDecimal]" do
+ res = @a.divmod(5)
+ res.kind_of?(Array).should == true
+ DivmodSpecs.check_both_bigdecimal(res)
+ end
+ end
+
+ version_is BigDecimal::VERSION, "4.0.0" do
+ it "divides value, returns [Integer, BigDecimal]" do
+ res = @a.divmod(5)
+ res.kind_of?(Array).should == true
+ res[0].kind_of?(Integer).should == true
+ res[1].kind_of?(BigDecimal).should == true
+ end
end
it "array contains quotient and modulus as BigDecimal" do
res = @a.divmod(5)
- DivmodSpecs.check_both_bigdecimal(res)
res[0].should == BigDecimal('0.8E1')
res[1].should == BigDecimal('2.00000000000000000001')
@@ -96,8 +109,8 @@ describe "BigDecimal#divmod" do
it "can be reversed with * and +" do
# Example taken from BigDecimal documentation
- a = BigDecimal.new("42")
- b = BigDecimal.new("9")
+ a = BigDecimal("42")
+ b = BigDecimal("9")
q, m = a.divmod(b)
c = q * b + m
a.should == c
@@ -123,47 +136,66 @@ describe "BigDecimal#divmod" do
values_and_zeroes.each do |val1|
values.each do |val2|
res = val1.divmod(val2)
- DivmodSpecs.check_both_bigdecimal(res)
res[0].should == ((val1/val2).floor)
res[1].should == (val1 - res[0] * val2)
end
end
end
- it "returns an array of two NaNs if NaN is involved" do
- (@special_vals + @regular_vals + @zeroes).each do |val|
- DivmodSpecs.check_both_nan(val.divmod(@nan))
- DivmodSpecs.check_both_nan(@nan.divmod(val))
+ version_is BigDecimal::VERSION, "4.0.0" do
+ it "raise FloatDomainError error if NaN is involved" do
+ (@special_vals + @regular_vals + @zeroes).each do |val|
+ -> { val.divmod(@nan) }.should.raise(FloatDomainError)
+ -> { @nan.divmod(val) }.should.raise(FloatDomainError)
+ end
+ end
+ end
+
+ version_is BigDecimal::VERSION, ""..."4.0.0" do
+ it "returns an array of two NaNs if NaN is involved" do
+ (@special_vals + @regular_vals + @zeroes).each do |val|
+ DivmodSpecs.check_both_nan(val.divmod(@nan))
+ DivmodSpecs.check_both_nan(@nan.divmod(val))
+ end
end
end
it "raises ZeroDivisionError if the divisor is zero" do
(@special_vals + @regular_vals + @zeroes - [@nan]).each do |val|
@zeroes.each do |zero|
- lambda { val.divmod(zero) }.should raise_error(ZeroDivisionError)
+ -> { val.divmod(zero) }.should.raise(ZeroDivisionError)
end
end
end
- it "returns an array of Infinity and NaN if the dividend is Infinity" do
- @regular_vals.each do |val|
- array = @infinity.divmod(val)
- array.length.should == 2
- array[0].infinite?.should == (val > 0 ? 1 : -1)
- array[1].nan?.should == true
+ version_is BigDecimal::VERSION, ""..."4.0.0" do
+ it "returns an array of Infinity and NaN if the dividend is Infinity" do
+ @regular_vals.each do |val|
+ array = @infinity.divmod(val)
+ array.length.should == 2
+ array[0].infinite?.should == (val > 0 ? 1 : -1)
+ array[1].should.nan?
+ end
end
end
- it "returns an array of zero and the dividend if the divisor is Infinity" do
- @regular_vals.each do |val|
- array = val.divmod(@infinity)
- array.length.should == 2
- array[0].should == @zero
- array[1].should == val
+ version_is BigDecimal::VERSION, "3.3.0" do
+ it "returns an array of zero and the dividend or minus one and Infinity if the divisor is Infinity" do
+ @regular_vals.each do |val|
+ array = val.divmod(@infinity)
+ array.length.should == 2
+ if val >= 0
+ array[0].should == @zero
+ array[1].should == val
+ else
+ array[0].should == @one_minus
+ array[1].should == @infinity
+ end
+ end
end
end
- it "returns an array of two zero if the diviend is zero" do
+ it "returns an array of two zero if the dividend is zero" do
@zeroes.each do |zero|
@regular_vals.each do |val|
zero.divmod(val).should == [@zero, @zero]
@@ -172,9 +204,9 @@ describe "BigDecimal#divmod" do
end
it "raises TypeError if the argument cannot be coerced to BigDecimal" do
- lambda {
+ -> {
@one.divmod('1')
- }.should raise_error(TypeError)
+ }.should.raise(TypeError)
end
end
diff --git a/spec/ruby/library/bigdecimal/double_fig_spec.rb b/spec/ruby/library/bigdecimal/double_fig_spec.rb
index 3ab5c2f207..f742d68f87 100644
--- a/spec/ruby/library/bigdecimal/double_fig_spec.rb
+++ b/spec/ruby/library/bigdecimal/double_fig_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'bigdecimal'
describe "BigDecimal.double_fig" do
diff --git a/spec/ruby/library/bigdecimal/dup_spec.rb b/spec/ruby/library/bigdecimal/dup_spec.rb
new file mode 100644
index 0000000000..dbf79ce5a6
--- /dev/null
+++ b/spec/ruby/library/bigdecimal/dup_spec.rb
@@ -0,0 +1,14 @@
+require_relative '../../spec_helper'
+require 'bigdecimal'
+
+describe "BigDecimal#dup" do
+ before :each do
+ @obj = BigDecimal("1.2345")
+ end
+
+ it "returns self" do
+ copy = @obj.dup
+
+ copy.should.equal?(@obj)
+ end
+end
diff --git a/spec/ruby/library/bigdecimal/eql_spec.rb b/spec/ruby/library/bigdecimal/eql_spec.rb
index f3f525a7ba..0346175e1e 100644
--- a/spec/ruby/library/bigdecimal/eql_spec.rb
+++ b/spec/ruby/library/bigdecimal/eql_spec.rb
@@ -1,6 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/eql.rb', __FILE__)
+require_relative '../../spec_helper'
+require 'bigdecimal'
describe "BigDecimal#eql?" do
- it_behaves_like(:bigdecimal_eql, :eql?)
+ it "is an alias of BigDecimal#==" do
+ BigDecimal.instance_method(:eql?).should == BigDecimal.instance_method(:==)
+ end
end
diff --git a/spec/ruby/library/bigdecimal/equal_value_spec.rb b/spec/ruby/library/bigdecimal/equal_value_spec.rb
index bd07217b98..d1133765b1 100644
--- a/spec/ruby/library/bigdecimal/equal_value_spec.rb
+++ b/spec/ruby/library/bigdecimal/equal_value_spec.rb
@@ -1,7 +1,63 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/eql.rb', __FILE__)
+require_relative '../../spec_helper'
+require 'bigdecimal'
describe "BigDecimal#==" do
- it_behaves_like(:bigdecimal_eql, :==)
+ before :each do
+ @bg6543_21 = BigDecimal("6543.21")
+ @bg5667_19 = BigDecimal("5667.19")
+ @a = BigDecimal("1.0000000000000000000000000000000000000000005")
+ @b = BigDecimal("1.00000000000000000000000000000000000000000005")
+ @bigint = BigDecimal("1000.0")
+ @nan = BigDecimal("NaN")
+ @infinity = BigDecimal("Infinity")
+ @infinity_minus = BigDecimal("-Infinity")
+ end
+
+ it "tests for equality" do
+ (@bg6543_21 == @bg6543_21).should == true
+ (@a == @a).should == true
+ (@a == @b).should == false
+ (@bg6543_21 == @a).should == false
+ (@bigint == 1000).should == true
+ end
+
+ it "returns false for NaN as it is never equal to any number" do
+ (@nan == @nan).should == false
+ (@a == @nan).should == false
+ (@nan == @a).should == false
+ (@nan == @infinity).should == false
+ (@nan == @infinity_minus).should == false
+ (@infinity == @nan).should == false
+ (@infinity_minus == @nan).should == false
+ end
+
+ it "returns true for infinity values with the same sign" do
+ (@infinity == @infinity).should == true
+ (@infinity == BigDecimal("Infinity")).should == true
+ (BigDecimal("Infinity") == @infinity).should == true
+
+ (@infinity_minus == @infinity_minus).should == true
+ (@infinity_minus == BigDecimal("-Infinity")).should == true
+ (BigDecimal("-Infinity") == @infinity_minus).should == true
+ end
+
+ it "returns false for infinity values with different signs" do
+ (@infinity == @infinity_minus).should == false
+ (@infinity_minus == @infinity).should == false
+ end
+
+ it "returns false when infinite value compared to finite one" do
+ (@infinity == @a).should == false
+ (@infinity_minus == @a).should == false
+
+ (@a == @infinity).should == false
+ (@a == @infinity_minus).should == false
+ end
+
+ it "returns false when compared objects that can not be coerced into BigDecimal" do
+ (@infinity == nil).should == false
+ (@bigint == nil).should == false
+ (@nan == nil).should == false
+ end
end
diff --git a/spec/ruby/library/bigdecimal/exponent_spec.rb b/spec/ruby/library/bigdecimal/exponent_spec.rb
index 6bb678d4ed..8877147955 100644
--- a/spec/ruby/library/bigdecimal/exponent_spec.rb
+++ b/spec/ruby/library/bigdecimal/exponent_spec.rb
@@ -1,9 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/power', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/power'
require 'bigdecimal'
describe "BigDecimal#**" do
- it_behaves_like(:bigdecimal_power, :**)
+ it_behaves_like :bigdecimal_power, :**
end
describe "BigDecimal#exponent" do
@@ -18,17 +18,6 @@ describe "BigDecimal#exponent" do
BigDecimal("1234567E10").exponent.should == 17
end
-# commenting this spec out after discussion with Defiler, since it seems to be an MRI bug, not a real feature
-=begin
- platform_is wordsize: 32 do
- # TODO: write specs for both 32 and 64 bit
- it "returns 0 if exponent can't be represented as Fixnum" do
- BigDecimal("2E1000000000000000").exponent.should == 0
- BigDecimal("-5E-999999999999999").exponent.should == 0
- end
- end
-=end
-
it "returns 0 if self is 0" do
BigDecimal("0").exponent.should == 0
BigDecimal("+0").exponent.should == 0
diff --git a/spec/ruby/library/bigdecimal/finite_spec.rb b/spec/ruby/library/bigdecimal/finite_spec.rb
index 6d6d8398fa..8fc06029bb 100644
--- a/spec/ruby/library/bigdecimal/finite_spec.rb
+++ b/spec/ruby/library/bigdecimal/finite_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'bigdecimal'
describe "BigDecimal#finite?" do
@@ -21,15 +21,14 @@ describe "BigDecimal#finite?" do
end
it "is false if Infinity or NaN" do
- @infinity.finite?.should == false
- @infinity_minus.finite?.should == false
- @nan.finite?.should == false
+ @infinity.should_not.finite?
+ @infinity_minus.should_not.finite?
+ @nan.should_not.finite?
end
it "returns true for finite values" do
@finite_vals.each do |val|
- val.finite?.should == true
+ val.should.finite?
end
end
end
-
diff --git a/spec/ruby/library/bigdecimal/fix_spec.rb b/spec/ruby/library/bigdecimal/fix_spec.rb
index 0a4a98c241..dceb2ce867 100644
--- a/spec/ruby/library/bigdecimal/fix_spec.rb
+++ b/spec/ruby/library/bigdecimal/fix_spec.rb
@@ -1,21 +1,21 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'bigdecimal'
describe "BigDecimal#fix" do
- before :each do
- @zero = BigDecimal("0")
- @mixed = BigDecimal("1.23456789")
- @pos_int = BigDecimal("2E5555")
- @neg_int = BigDecimal("-2E5555")
- @pos_frac = BigDecimal("2E-9999")
- @neg_frac = BigDecimal("-2E-9999")
-
- @infinity = BigDecimal("Infinity")
- @infinity_neg = BigDecimal("-Infinity")
- @nan = BigDecimal("NaN")
- @zero_pos = BigDecimal("+0")
- @zero_neg = BigDecimal("-0")
- end
+ before :each do
+ @zero = BigDecimal("0")
+ @mixed = BigDecimal("1.23456789")
+ @pos_int = BigDecimal("2E5555")
+ @neg_int = BigDecimal("-2E5555")
+ @pos_frac = BigDecimal("2E-9999")
+ @neg_frac = BigDecimal("-2E-9999")
+
+ @infinity = BigDecimal("Infinity")
+ @infinity_neg = BigDecimal("-Infinity")
+ @nan = BigDecimal("NaN")
+ @zero_pos = BigDecimal("+0")
+ @zero_neg = BigDecimal("-0")
+ end
it "returns a BigDecimal" do
BigDecimal("2E100000000").fix.kind_of?(BigDecimal).should == true
@@ -34,7 +34,7 @@ describe "BigDecimal#fix" do
it "correctly handles special values" do
@infinity.fix.should == @infinity
@infinity_neg.fix.should == @infinity_neg
- @nan.fix.nan?.should == true
+ @nan.fix.should.nan?
end
it "returns 0 if the absolute value is < 1" do
@@ -49,9 +49,9 @@ describe "BigDecimal#fix" do
end
it "does not allow any arguments" do
- lambda {
+ -> {
@mixed.fix(10)
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
end
end
diff --git a/spec/ruby/library/bigdecimal/floor_spec.rb b/spec/ruby/library/bigdecimal/floor_spec.rb
index 0bae6e4ab0..c0666c668c 100644
--- a/spec/ruby/library/bigdecimal/floor_spec.rb
+++ b/spec/ruby/library/bigdecimal/floor_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'bigdecimal'
describe "BigDecimal#floor" do
@@ -41,9 +41,9 @@ describe "BigDecimal#floor" do
end
it "raise exception, if self is special value" do
- lambda { @infinity.floor }.should raise_error(FloatDomainError)
- lambda { @infinity_neg.floor }.should raise_error(FloatDomainError)
- lambda { @nan.floor }.should raise_error(FloatDomainError)
+ -> { @infinity.floor }.should.raise(FloatDomainError)
+ -> { @infinity_neg.floor }.should.raise(FloatDomainError)
+ -> { @nan.floor }.should.raise(FloatDomainError)
end
it "returns n digits right of the decimal point if given n > 0" do
diff --git a/spec/ruby/library/bigdecimal/frac_spec.rb b/spec/ruby/library/bigdecimal/frac_spec.rb
index 9a727a70dd..11ccf03c2f 100644
--- a/spec/ruby/library/bigdecimal/frac_spec.rb
+++ b/spec/ruby/library/bigdecimal/frac_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'bigdecimal'
describe "BigDecimal#frac" do
@@ -42,7 +42,7 @@ describe "BigDecimal#frac" do
it "correctly handles special values" do
@infinity.frac.should == @infinity
@infinity_neg.frac.should == @infinity_neg
- @nan.frac.nan?.should == true
+ @nan.frac.should.nan?
end
end
diff --git a/spec/ruby/library/bigdecimal/gt_spec.rb b/spec/ruby/library/bigdecimal/gt_spec.rb
index 2f9ea4fd68..e9c9a60e75 100644
--- a/spec/ruby/library/bigdecimal/gt_spec.rb
+++ b/spec/ruby/library/bigdecimal/gt_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'bigdecimal'
describe "BigDecimal#>" do
@@ -17,7 +17,7 @@ describe "BigDecimal#>" do
def coerce(other)
return [other, BigDecimal('123')]
end
- def > (other)
+ def >(other)
BigDecimal('123') > other
end
end
@@ -68,15 +68,13 @@ describe "BigDecimal#>" do
(@infinity_neg > @infinity).should == false
end
- ruby_bug "#13674", ""..."2.4" do
- it "properly handles Float infinity values" do
- @values.each { |val|
- (val > @float_infinity).should == false
- (@float_infinity > val).should == true
- (val > @float_infinity_neg).should == true
- (@float_infinity_neg > val).should == false
- }
- end
+ it "properly handles Float infinity values" do
+ @values.each { |val|
+ (val > @float_infinity).should == false
+ (@float_infinity > val).should == true
+ (val > @float_infinity_neg).should == true
+ (@float_infinity_neg > val).should == false
+ }
end
it "properly handles NaN values" do
@@ -88,11 +86,11 @@ describe "BigDecimal#>" do
end
it "raises an ArgumentError if the argument can't be coerced into a BigDecimal" do
- lambda {@zero > nil }.should raise_error(ArgumentError)
- lambda {@infinity > nil }.should raise_error(ArgumentError)
- lambda {@infinity_neg > nil }.should raise_error(ArgumentError)
- lambda {@mixed > nil }.should raise_error(ArgumentError)
- lambda {@pos_int > nil }.should raise_error(ArgumentError)
- lambda {@neg_frac > nil }.should raise_error(ArgumentError)
+ -> {@zero > nil }.should.raise(ArgumentError)
+ -> {@infinity > nil }.should.raise(ArgumentError)
+ -> {@infinity_neg > nil }.should.raise(ArgumentError)
+ -> {@mixed > nil }.should.raise(ArgumentError)
+ -> {@pos_int > nil }.should.raise(ArgumentError)
+ -> {@neg_frac > nil }.should.raise(ArgumentError)
end
end
diff --git a/spec/ruby/library/bigdecimal/gte_spec.rb b/spec/ruby/library/bigdecimal/gte_spec.rb
index aab5338ad6..548f3efe4c 100644
--- a/spec/ruby/library/bigdecimal/gte_spec.rb
+++ b/spec/ruby/library/bigdecimal/gte_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'bigdecimal'
describe "BigDecimal#>=" do
@@ -17,7 +17,7 @@ describe "BigDecimal#>=" do
def coerce(other)
return [other, BigDecimal('123')]
end
- def >= (other)
+ def >=(other)
BigDecimal('123') >= other
end
end
@@ -72,15 +72,13 @@ describe "BigDecimal#>=" do
(@infinity_neg >= @infinity).should == false
end
- ruby_bug "#13674", ""..."2.4" do
- it "properly handles Float infinity values" do
- @values.each { |val|
- (val >= @float_infinity).should == false
- (@float_infinity >= val).should == true
- (val >= @float_infinity_neg).should == true
- (@float_infinity_neg >= val).should == false
- }
- end
+ it "properly handles Float infinity values" do
+ @values.each { |val|
+ (val >= @float_infinity).should == false
+ (@float_infinity >= val).should == true
+ (val >= @float_infinity_neg).should == true
+ (@float_infinity_neg >= val).should == false
+ }
end
it "properly handles NaN values" do
@@ -92,11 +90,11 @@ describe "BigDecimal#>=" do
end
it "returns nil if the argument is nil" do
- lambda {@zero >= nil }.should raise_error(ArgumentError)
- lambda {@infinity >= nil }.should raise_error(ArgumentError)
- lambda {@infinity_neg >= nil }.should raise_error(ArgumentError)
- lambda {@mixed >= nil }.should raise_error(ArgumentError)
- lambda {@pos_int >= nil }.should raise_error(ArgumentError)
- lambda {@neg_frac >= nil }.should raise_error(ArgumentError)
+ -> {@zero >= nil }.should.raise(ArgumentError)
+ -> {@infinity >= nil }.should.raise(ArgumentError)
+ -> {@infinity_neg >= nil }.should.raise(ArgumentError)
+ -> {@mixed >= nil }.should.raise(ArgumentError)
+ -> {@pos_int >= nil }.should.raise(ArgumentError)
+ -> {@neg_frac >= nil }.should.raise(ArgumentError)
end
end
diff --git a/spec/ruby/library/bigdecimal/hash_spec.rb b/spec/ruby/library/bigdecimal/hash_spec.rb
new file mode 100644
index 0000000000..7581c90f68
--- /dev/null
+++ b/spec/ruby/library/bigdecimal/hash_spec.rb
@@ -0,0 +1,30 @@
+require_relative '../../spec_helper'
+require 'bigdecimal'
+
+describe "BidDecimal#hash" do
+ describe "two BigDecimal objects with the same value" do
+ it "should have the same hash for ordinary values" do
+ BigDecimal('1.2920').hash.should == BigDecimal('1.2920').hash
+ end
+
+ it "should have the same hash for infinite values" do
+ BigDecimal("+Infinity").hash.should == BigDecimal("+Infinity").hash
+ BigDecimal("-Infinity").hash.should == BigDecimal("-Infinity").hash
+ end
+
+ it "should have the same hash for NaNs" do
+ BigDecimal("NaN").hash.should == BigDecimal("NaN").hash
+ end
+
+ it "should have the same hash for zero values" do
+ BigDecimal("+0").hash.should == BigDecimal("+0").hash
+ BigDecimal("-0").hash.should == BigDecimal("-0").hash
+ end
+ end
+
+ describe "two BigDecimal objects with numerically equal values" do
+ it "should have the same hash value" do
+ BigDecimal("1.2920").hash.should == BigDecimal("1.2920000").hash
+ end
+ end
+end
diff --git a/spec/ruby/library/bigdecimal/infinite_spec.rb b/spec/ruby/library/bigdecimal/infinite_spec.rb
index b218ee371c..025386107f 100644
--- a/spec/ruby/library/bigdecimal/infinite_spec.rb
+++ b/spec/ruby/library/bigdecimal/infinite_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'bigdecimal'
describe "BigDecimal#infinite?" do
diff --git a/spec/ruby/library/bigdecimal/inspect_spec.rb b/spec/ruby/library/bigdecimal/inspect_spec.rb
index 9831b2be8e..7ce47142b2 100644
--- a/spec/ruby/library/bigdecimal/inspect_spec.rb
+++ b/spec/ruby/library/bigdecimal/inspect_spec.rb
@@ -1,47 +1,30 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'bigdecimal'
describe "BigDecimal#inspect" do
before :each do
- @bigdec = BigDecimal.new("1234.5678")
+ @bigdec = BigDecimal("1234.5678")
end
it "returns String" do
@bigdec.inspect.kind_of?(String).should == true
end
- ruby_version_is ""..."2.4" do
- it "returns String starting with #" do
- @bigdec.inspect[0].should == ?#
- end
-
- it "encloses information in angle brackets" do
- @bigdec.inspect.should =~ /^.<.*>$/
- end
-
- it "is comma separated list of three items" do
- @bigdec.inspect.should =~ /...*,.*,.*/
- end
-
- it "value after first comma is value as string" do
- @bigdec.inspect.split(",")[1].should == "\'0.12345678E4\'"
- end
-
- it "last part is number of significant digits" do
- signific_string = "#{@bigdec.precs[0]}(#{@bigdec.precs[1]})"
- @bigdec.inspect.split(",")[2].should == signific_string + ">"
- end
+ it "looks like this" do
+ @bigdec.inspect.should == "0.12345678e4"
+ end
- it "looks like this" do
- regex = /^\#\<BigDecimal\:.*,'0\.12345678E4',[0-9]+\([0-9]+\)>$/
- @bigdec.inspect.should =~ regex
- end
+ it "does not add an exponent for zero values" do
+ BigDecimal("0").inspect.should == "0.0"
+ BigDecimal("+0").inspect.should == "0.0"
+ BigDecimal("-0").inspect.should == "-0.0"
end
- ruby_version_is "2.4" do
- it "looks like this" do
- @bigdec.inspect.should == "0.12345678e4"
- end
+ it "properly cases non-finite values" do
+ BigDecimal("NaN").inspect.should == "NaN"
+ BigDecimal("Infinity").inspect.should == "Infinity"
+ BigDecimal("+Infinity").inspect.should == "Infinity"
+ BigDecimal("-Infinity").inspect.should == "-Infinity"
end
end
diff --git a/spec/ruby/library/bigdecimal/limit_spec.rb b/spec/ruby/library/bigdecimal/limit_spec.rb
index 41308abcd8..75cbc8b55c 100644
--- a/spec/ruby/library/bigdecimal/limit_spec.rb
+++ b/spec/ruby/library/bigdecimal/limit_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
require 'bigdecimal'
describe "BigDecimal.limit" do
@@ -11,20 +11,45 @@ describe "BigDecimal.limit" do
BigDecimal.limit(old)
end
- it "use the global limit if no precision is specified" do
+ it "uses the global limit if no precision is specified" do
BigDecimalSpecs.with_limit(0) do
(BigDecimal('0.888') + BigDecimal('0')).should == BigDecimal('0.888')
+ (BigDecimal('0.888') - BigDecimal('0')).should == BigDecimal('0.888')
(BigDecimal('0.888') * BigDecimal('3')).should == BigDecimal('2.664')
+ (BigDecimal('0.888') / BigDecimal('3')).should == BigDecimal('0.296')
end
BigDecimalSpecs.with_limit(1) do
(BigDecimal('0.888') + BigDecimal('0')).should == BigDecimal('0.9')
+ (BigDecimal('0.888') - BigDecimal('0')).should == BigDecimal('0.9')
(BigDecimal('0.888') * BigDecimal('3')).should == BigDecimal('3')
+ (BigDecimal('0.888') / BigDecimal('3')).should == BigDecimal('0.3')
end
BigDecimalSpecs.with_limit(2) do
(BigDecimal('0.888') + BigDecimal('0')).should == BigDecimal('0.89')
+ (BigDecimal('0.888') - BigDecimal('0')).should == BigDecimal('0.89')
(BigDecimal('0.888') * BigDecimal('3')).should == BigDecimal('2.7')
+ (BigDecimal('0.888') / BigDecimal('3')).should == BigDecimal('0.30')
end
end
+
+ it "picks the specified precision over global limit" do
+ BigDecimalSpecs.with_limit(3) do
+ BigDecimal('0.888').add(BigDecimal('0'), 2).should == BigDecimal('0.89')
+ BigDecimal('0.888').sub(BigDecimal('0'), 2).should == BigDecimal('0.89')
+ BigDecimal('0.888').mult(BigDecimal('3'), 2).should == BigDecimal('2.7')
+ BigDecimal('0.888').div(BigDecimal('3'), 2).should == BigDecimal('0.30')
+ end
+ end
+
+ it "picks the global precision when limit 0 specified" do
+ BigDecimalSpecs.with_limit(3) do
+ BigDecimal('0.8888').add(BigDecimal('0'), 0).should == BigDecimal('0.889')
+ BigDecimal('0.8888').sub(BigDecimal('0'), 0).should == BigDecimal('0.889')
+ BigDecimal('0.888').mult(BigDecimal('3'), 0).should == BigDecimal('2.66')
+ BigDecimal('0.8888').div(BigDecimal('3'), 0).should == BigDecimal('0.296')
+ end
+ end
+
end
diff --git a/spec/ruby/library/bigdecimal/lt_spec.rb b/spec/ruby/library/bigdecimal/lt_spec.rb
index 089e7aef73..c3f3573247 100644
--- a/spec/ruby/library/bigdecimal/lt_spec.rb
+++ b/spec/ruby/library/bigdecimal/lt_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'bigdecimal'
describe "BigDecimal#<" do
@@ -17,7 +17,7 @@ describe "BigDecimal#<" do
def coerce(other)
return [other, BigDecimal('123')]
end
- def < (other)
+ def <(other)
BigDecimal('123') < other
end
end
@@ -66,15 +66,13 @@ describe "BigDecimal#<" do
(@infinity_neg < @infinity).should == true
end
- ruby_bug "#13674", ""..."2.4" do
- it "properly handles Float infinity values" do
- @values.each { |val|
- (val < @float_infinity).should == true
- (@float_infinity < val).should == false
- (val < @float_infinity_neg).should == false
- (@float_infinity_neg < val).should == true
- }
- end
+ it "properly handles Float infinity values" do
+ @values.each { |val|
+ (val < @float_infinity).should == true
+ (@float_infinity < val).should == false
+ (val < @float_infinity_neg).should == false
+ (@float_infinity_neg < val).should == true
+ }
end
it "properly handles NaN values" do
@@ -86,11 +84,11 @@ describe "BigDecimal#<" do
end
it "raises an ArgumentError if the argument can't be coerced into a BigDecimal" do
- lambda {@zero < nil }.should raise_error(ArgumentError)
- lambda {@infinity < nil }.should raise_error(ArgumentError)
- lambda {@infinity_neg < nil }.should raise_error(ArgumentError)
- lambda {@mixed < nil }.should raise_error(ArgumentError)
- lambda {@pos_int < nil }.should raise_error(ArgumentError)
- lambda {@neg_frac < nil }.should raise_error(ArgumentError)
+ -> {@zero < nil }.should.raise(ArgumentError)
+ -> {@infinity < nil }.should.raise(ArgumentError)
+ -> {@infinity_neg < nil }.should.raise(ArgumentError)
+ -> {@mixed < nil }.should.raise(ArgumentError)
+ -> {@pos_int < nil }.should.raise(ArgumentError)
+ -> {@neg_frac < nil }.should.raise(ArgumentError)
end
end
diff --git a/spec/ruby/library/bigdecimal/lte_spec.rb b/spec/ruby/library/bigdecimal/lte_spec.rb
index 5cda9842bd..7918bde88b 100644
--- a/spec/ruby/library/bigdecimal/lte_spec.rb
+++ b/spec/ruby/library/bigdecimal/lte_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'bigdecimal'
describe "BigDecimal#<=" do
@@ -17,7 +17,7 @@ describe "BigDecimal#<=" do
def coerce(other)
return [other, BigDecimal('123')]
end
- def <= (other)
+ def <=(other)
BigDecimal('123') <= other
end
end
@@ -72,15 +72,13 @@ describe "BigDecimal#<=" do
(@infinity_neg <= @infinity).should == true
end
- ruby_bug "#13674", ""..."2.4" do
- it "properly handles Float infinity values" do
- @values.each { |val|
- (val <= @float_infinity).should == true
- (@float_infinity <= val).should == false
- (val <= @float_infinity_neg).should == false
- (@float_infinity_neg <= val).should == true
- }
- end
+ it "properly handles Float infinity values" do
+ @values.each { |val|
+ (val <= @float_infinity).should == true
+ (@float_infinity <= val).should == false
+ (val <= @float_infinity_neg).should == false
+ (@float_infinity_neg <= val).should == true
+ }
end
it "properly handles NaN values" do
@@ -92,11 +90,11 @@ describe "BigDecimal#<=" do
end
it "raises an ArgumentError if the argument can't be coerced into a BigDecimal" do
- lambda {@zero <= nil }.should raise_error(ArgumentError)
- lambda {@infinity <= nil }.should raise_error(ArgumentError)
- lambda {@infinity_neg <= nil }.should raise_error(ArgumentError)
- lambda {@mixed <= nil }.should raise_error(ArgumentError)
- lambda {@pos_int <= nil }.should raise_error(ArgumentError)
- lambda {@neg_frac <= nil }.should raise_error(ArgumentError)
+ -> {@zero <= nil }.should.raise(ArgumentError)
+ -> {@infinity <= nil }.should.raise(ArgumentError)
+ -> {@infinity_neg <= nil }.should.raise(ArgumentError)
+ -> {@mixed <= nil }.should.raise(ArgumentError)
+ -> {@pos_int <= nil }.should.raise(ArgumentError)
+ -> {@neg_frac <= nil }.should.raise(ArgumentError)
end
end
diff --git a/spec/ruby/library/bigdecimal/minus_spec.rb b/spec/ruby/library/bigdecimal/minus_spec.rb
index bdd8478465..bd3c19584b 100644
--- a/spec/ruby/library/bigdecimal/minus_spec.rb
+++ b/spec/ruby/library/bigdecimal/minus_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'bigdecimal'
describe "BigDecimal#-" do
@@ -26,18 +26,18 @@ describe "BigDecimal#-" do
end
it "returns NaN if NaN is involved" do
- (@one - @nan).nan?.should == true
- (@nan - @one).nan?.should == true
- (@nan - @nan).nan?.should == true
- (@nan - @infinity).nan?.should == true
- (@nan - @infinity_minus).nan?.should == true
- (@infinity - @nan).nan?.should == true
- (@infinity_minus - @nan).nan?.should == true
+ (@one - @nan).should.nan?
+ (@nan - @one).should.nan?
+ (@nan - @nan).should.nan?
+ (@nan - @infinity).should.nan?
+ (@nan - @infinity_minus).should.nan?
+ (@infinity - @nan).should.nan?
+ (@infinity_minus - @nan).should.nan?
end
it "returns NaN both operands are infinite with the same sign" do
- (@infinity - @infinity).nan?.should == true
- (@infinity_minus - @infinity_minus).nan?.should == true
+ (@infinity - @infinity).should.nan?
+ (@infinity_minus - @infinity_minus).should.nan?
end
it "returns Infinity or -Infinity if these are involved" do
@@ -55,4 +55,12 @@ describe "BigDecimal#-" do
(@one_minus - @infinity).should == @infinity_minus
end
+ describe "with Object" do
+ it "tries to coerce the other operand to self" do
+ object = mock("Object")
+ object.should_receive(:coerce).with(@one).and_return([@one, BigDecimal("42")])
+ (@one - object).should == BigDecimal("-41")
+ end
+ end
+
end
diff --git a/spec/ruby/library/bigdecimal/mode_spec.rb b/spec/ruby/library/bigdecimal/mode_spec.rb
index d88ac61aaf..26e6d0ea75 100644
--- a/spec/ruby/library/bigdecimal/mode_spec.rb
+++ b/spec/ruby/library/bigdecimal/mode_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'bigdecimal'
describe "BigDecimal.mode" do
@@ -12,7 +12,7 @@ describe "BigDecimal.mode" do
end
it "returns the appropriate value and continue the computation if the flag is false" do
- BigDecimal("NaN").add(BigDecimal("1"),0).nan?.should == true
+ BigDecimal("NaN").add(BigDecimal("1"),0).should.nan?
BigDecimal("0").add(BigDecimal("Infinity"),0).should == BigDecimal("Infinity")
BigDecimal("1").quo(BigDecimal("0")).should == BigDecimal("Infinity")
end
@@ -24,13 +24,13 @@ describe "BigDecimal.mode" do
it "raise an exception if the flag is true" do
BigDecimal.mode(BigDecimal::EXCEPTION_NaN, true)
- lambda { BigDecimal("NaN").add(BigDecimal("1"),0) }.should raise_error(FloatDomainError)
+ -> { BigDecimal("NaN").add(BigDecimal("1"),0) }.should.raise(FloatDomainError)
BigDecimal.mode(BigDecimal::EXCEPTION_INFINITY, true)
- lambda { BigDecimal("0").add(BigDecimal("Infinity"),0) }.should raise_error(FloatDomainError)
+ -> { BigDecimal("0").add(BigDecimal("Infinity"),0) }.should.raise(FloatDomainError)
BigDecimal.mode(BigDecimal::EXCEPTION_ZERODIVIDE, true)
- lambda { BigDecimal("1").quo(BigDecimal("0")) }.should raise_error(FloatDomainError)
+ -> { BigDecimal("1").quo(BigDecimal("0")) }.should.raise(FloatDomainError)
BigDecimal.mode(BigDecimal::EXCEPTION_OVERFLOW, true)
- lambda { BigDecimal("1E11111111111111111111") }.should raise_error(FloatDomainError)
- lambda { (BigDecimal("1E1000000000000000000")**10) }.should raise_error(FloatDomainError)
+ -> { BigDecimal("1E11111111111111111111") }.should.raise(FloatDomainError)
+ -> { (BigDecimal("1E1000000000000000000")**10) }.should.raise(FloatDomainError)
end
end
diff --git a/spec/ruby/library/bigdecimal/modulo_spec.rb b/spec/ruby/library/bigdecimal/modulo_spec.rb
index 6feeb685eb..d6b4f91b6d 100644
--- a/spec/ruby/library/bigdecimal/modulo_spec.rb
+++ b/spec/ruby/library/bigdecimal/modulo_spec.rb
@@ -1,12 +1,21 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/modulo', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/modulo'
+require 'bigdecimal'
describe "BigDecimal#%" do
- it_behaves_like(:bigdecimal_modulo, :%)
- it_behaves_like(:bigdecimal_modulo_zerodivisionerror, :%)
+ it_behaves_like :bigdecimal_modulo, :%
+
+ it "raises ZeroDivisionError if other is zero" do
+ bd5667 = BigDecimal("5667.19")
+
+ -> { bd5667 % 0 }.should.raise(ZeroDivisionError)
+ -> { bd5667 % BigDecimal("0") }.should.raise(ZeroDivisionError)
+ -> { @zero % @zero }.should.raise(ZeroDivisionError)
+ end
end
describe "BigDecimal#modulo" do
- it_behaves_like(:bigdecimal_modulo, :modulo)
- it_behaves_like(:bigdecimal_modulo_zerodivisionerror, :modulo)
+ it "is an alias of BigDecimal#%" do
+ BigDecimal.instance_method(:modulo).should == BigDecimal.instance_method(:%)
+ end
end
diff --git a/spec/ruby/library/bigdecimal/mult_spec.rb b/spec/ruby/library/bigdecimal/mult_spec.rb
index a140cf899a..2353df9cb8 100644
--- a/spec/ruby/library/bigdecimal/mult_spec.rb
+++ b/spec/ruby/library/bigdecimal/mult_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/mult', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/mult'
require 'bigdecimal'
describe "BigDecimal#mult" do
@@ -9,7 +9,8 @@ end
describe "BigDecimal#mult" do
before :each do
@one = BigDecimal "1"
- @e3_minus = BigDecimal "3E-20001"
+ @e3_minus = BigDecimal("3E-20001")
+ @e3_plus = BigDecimal("3E20001")
@e = BigDecimal "1.00000000000000000000123456789"
@tolerance = @e.sub @one, 1000
@tolerance2 = BigDecimal "30001E-20005"
@@ -20,5 +21,4 @@ describe "BigDecimal#mult" do
@e.mult(@one, 1).should be_close(@one, @tolerance)
@e3_minus.mult(@one, 1).should be_close(0, @tolerance2)
end
-
end
diff --git a/spec/ruby/library/bigdecimal/multiply_spec.rb b/spec/ruby/library/bigdecimal/multiply_spec.rb
index 842e22eaa2..a8ce1da32e 100644
--- a/spec/ruby/library/bigdecimal/multiply_spec.rb
+++ b/spec/ruby/library/bigdecimal/multiply_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/mult', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/mult'
require 'bigdecimal'
describe "BigDecimal#*" do
@@ -8,6 +8,7 @@ end
describe "BigDecimal#*" do
before :each do
+ @three = BigDecimal("3")
@e3_minus = BigDecimal("3E-20001")
@e3_plus = BigDecimal("3E20001")
@e = BigDecimal("1.00000000000000000000123456789")
@@ -23,4 +24,18 @@ describe "BigDecimal#*" do
(@e3_minus * @e3_minus).should == BigDecimal("9E-40002")
(@e * @one).should == @e
end
+
+ describe "with Object" do
+ it "tries to coerce the other operand to self" do
+ object = mock("Object")
+ object.should_receive(:coerce).with(@e3_minus).and_return([@e3_minus, @e3_plus])
+ (@e3_minus * object).should == BigDecimal("9")
+ end
+ end
+
+ describe "with Rational" do
+ it "produces a BigDecimal" do
+ (@three * Rational(500, 2)).should == BigDecimal("0.75e3")
+ end
+ end
end
diff --git a/spec/ruby/library/bigdecimal/nan_spec.rb b/spec/ruby/library/bigdecimal/nan_spec.rb
index 5c291629b3..9eaf69b610 100644
--- a/spec/ruby/library/bigdecimal/nan_spec.rb
+++ b/spec/ruby/library/bigdecimal/nan_spec.rb
@@ -1,23 +1,23 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'bigdecimal'
describe "BigDecimal#nan?" do
it "returns true if self is not a number" do
- BigDecimal("NaN").nan?.should == true
+ BigDecimal("NaN").should.nan?
end
it "returns false if self is not a NaN" do
- BigDecimal("Infinity").nan?.should == false
- BigDecimal("-Infinity").nan?.should == false
- BigDecimal("0").nan?.should == false
- BigDecimal("+0").nan?.should == false
- BigDecimal("-0").nan?.should == false
- BigDecimal("2E40001").nan?.should == false
- BigDecimal("3E-20001").nan?.should == false
- BigDecimal("0E-200000000").nan?.should == false
- BigDecimal("0E200000000000").nan?.should == false
- BigDecimal("0.000000000000000000000000").nan?.should == false
+ BigDecimal("Infinity").should_not.nan?
+ BigDecimal("-Infinity").should_not.nan?
+ BigDecimal("0").should_not.nan?
+ BigDecimal("+0").should_not.nan?
+ BigDecimal("-0").should_not.nan?
+ BigDecimal("2E40001").should_not.nan?
+ BigDecimal("3E-20001").should_not.nan?
+ BigDecimal("0E-200000000").should_not.nan?
+ BigDecimal("0E200000000000").should_not.nan?
+ BigDecimal("0.000000000000000000000000").should_not.nan?
end
end
diff --git a/spec/ruby/library/bigdecimal/new_spec.rb b/spec/ruby/library/bigdecimal/new_spec.rb
deleted file mode 100644
index de3aa195ca..0000000000
--- a/spec/ruby/library/bigdecimal/new_spec.rb
+++ /dev/null
@@ -1,109 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require 'bigdecimal'
-
-describe "BigDecimal.new" do
-
- it "creates a new object of class BigDecimal" do
- BigDecimal.new("3.14159").should be_kind_of(BigDecimal)
- (0..9).each {|i|
- BigDecimal.new("1#{i}").should == 10 + i
- BigDecimal.new("-1#{i}").should == -10 - i
- BigDecimal.new("1E#{i}").should == 10**i
- BigDecimal.new("1000000E-#{i}").should == 10**(6-i).to_f
- # ^ to_f to avoid Rational type
- }
- (1..9).each {|i|
- BigDecimal.new("100.#{i}").to_s.should =~ /\A0\.100#{i}E3\z/i
- BigDecimal.new("-100.#{i}").to_s.should =~ /\A-0\.100#{i}E3\z/i
- }
- end
-
- it "accepts significant digits >= given precision" do
- BigDecimal.new("3.1415923", 10).precs[1].should >= 10
- end
-
- it "determines precision from initial value" do
- pi_string = "3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593014782083152134043"
- BigDecimal.new(pi_string).precs[1].should >= pi_string.size-1
- end
-
- it "ignores leading whitespace" do
- BigDecimal.new(" \t\n \r1234").should == BigDecimal.new("1234")
- BigDecimal.new(" \t\n \rNaN \n").nan?.should == true
- BigDecimal.new(" \t\n \rInfinity \n").infinite?.should == 1
- BigDecimal.new(" \t\n \r-Infinity \n").infinite?.should == -1
- end
-
- it "ignores trailing garbage" do
- BigDecimal.new("123E45ruby").should == BigDecimal.new("123E45")
- BigDecimal.new("123x45").should == BigDecimal.new("123")
- BigDecimal.new("123.4%E5").should == BigDecimal.new("123.4")
- BigDecimal.new("1E2E3E4E5E").should == BigDecimal.new("100")
- end
-
- ruby_version_is ""..."2.4" do
- it "treats invalid strings as 0.0" do
- BigDecimal.new("ruby").should == BigDecimal.new("0.0")
- BigDecimal.new(" \t\n \r-\t\t\tInfinity \n").should == BigDecimal.new("0.0")
- end
- end
-
- ruby_version_is "2.4" do
- it "raises ArgumentError for invalid strings" do
- lambda { BigDecimal.new("ruby") }.should raise_error(ArgumentError)
- lambda { BigDecimal.new(" \t\n \r-\t\t\tInfinity \n") }.should raise_error(ArgumentError)
- end
- end
-
- it "allows omitting the integer part" do
- BigDecimal.new(".123").should == BigDecimal.new("0.123")
- end
-
- it "allows for underscores in all parts" do
- reference = BigDecimal.new("12345.67E89")
-
- BigDecimal.new("12_345.67E89").should == reference
- BigDecimal.new("1_2_3_4_5_._6____7_E89").should == reference
- BigDecimal.new("12345_.67E_8__9_").should == reference
- end
-
- it "accepts NaN and [+-]Infinity" do
- BigDecimal.new("NaN").nan?.should == true
-
- pos_inf = BigDecimal.new("Infinity")
- pos_inf.finite?.should == false
- pos_inf.should > 0
- pos_inf.should == BigDecimal.new("+Infinity")
-
- neg_inf = BigDecimal.new("-Infinity")
- neg_inf.finite?.should == false
- neg_inf.should < 0
- end
-
- it "allows for [eEdD] as exponent separator" do
- reference = BigDecimal.new("12345.67E89")
-
- BigDecimal.new("12345.67e89").should == reference
- BigDecimal.new("12345.67E89").should == reference
- BigDecimal.new("12345.67d89").should == reference
- BigDecimal.new("12345.67D89").should == reference
- end
-
- it "allows for varying signs" do
- reference = BigDecimal.new("123.456E1")
-
- BigDecimal.new("+123.456E1").should == reference
- BigDecimal.new("-123.456E1").should == -reference
- BigDecimal.new("123.456E+1").should == reference
- BigDecimal.new("12345.6E-1").should == reference
- BigDecimal.new("+123.456E+1").should == reference
- BigDecimal.new("+12345.6E-1").should == reference
- BigDecimal.new("-123.456E+1").should == -reference
- BigDecimal.new("-12345.6E-1").should == -reference
- end
-
- it 'raises ArgumentError when Float is used without precision' do
- lambda { BigDecimal(1.0) }.should raise_error(ArgumentError)
- end
-
-end
diff --git a/spec/ruby/library/bigdecimal/nonzero_spec.rb b/spec/ruby/library/bigdecimal/nonzero_spec.rb
index 336c72a6b2..31421ebdf4 100644
--- a/spec/ruby/library/bigdecimal/nonzero_spec.rb
+++ b/spec/ruby/library/bigdecimal/nonzero_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'bigdecimal'
describe "BigDecimal#nonzero?" do
@@ -10,11 +10,11 @@ describe "BigDecimal#nonzero?" do
infinity = BigDecimal("Infinity")
infinity_minus = BigDecimal("-Infinity")
nan = BigDecimal("NaN")
- infinity.nonzero?.should equal(infinity)
- infinity_minus.nonzero?.should equal(infinity_minus)
- nan.nonzero?.should equal(nan)
- e3_minus.nonzero?.should equal(e3_minus)
- e2_plus.nonzero?.should equal(e2_plus)
+ infinity.nonzero?.should.equal?(infinity)
+ infinity_minus.nonzero?.should.equal?(infinity_minus)
+ nan.nonzero?.should.equal?(nan)
+ e3_minus.nonzero?.should.equal?(e3_minus)
+ e2_plus.nonzero?.should.equal?(e2_plus)
end
it "returns nil otherwise" do
diff --git a/spec/ruby/library/bigdecimal/plus_spec.rb b/spec/ruby/library/bigdecimal/plus_spec.rb
index 72ec282075..d1934841c8 100644
--- a/spec/ruby/library/bigdecimal/plus_spec.rb
+++ b/spec/ruby/library/bigdecimal/plus_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'bigdecimal'
describe "BigDecimal#+" do
@@ -30,8 +30,8 @@ describe "BigDecimal#+" do
end
it "returns NaN if NaN is involved" do
- (@one + @nan).nan?.should == true
- (@nan + @one).nan?.should == true
+ (@one + @nan).should.nan?
+ (@nan + @one).should.nan?
end
it "returns Infinity or -Infinity if these are involved" do
@@ -41,7 +41,14 @@ describe "BigDecimal#+" do
end
it "returns NaN if Infinity + (- Infinity)" do
- (@infinity + @infinity_minus).nan?.should == true
+ (@infinity + @infinity_minus).should.nan?
end
+ describe "with Object" do
+ it "tries to coerce the other operand to self" do
+ object = mock("Object")
+ object.should_receive(:coerce).with(@one).and_return([@one, BigDecimal("42")])
+ (@one + object).should == BigDecimal("43")
+ end
+ end
end
diff --git a/spec/ruby/library/bigdecimal/power_spec.rb b/spec/ruby/library/bigdecimal/power_spec.rb
index f2b1a9b5c8..63a45a1887 100644
--- a/spec/ruby/library/bigdecimal/power_spec.rb
+++ b/spec/ruby/library/bigdecimal/power_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/power', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/power'
describe "BigDecimal#power" do
- it_behaves_like(:bigdecimal_power, :power)
+ it_behaves_like :bigdecimal_power, :power
end
diff --git a/spec/ruby/library/bigdecimal/precs_spec.rb b/spec/ruby/library/bigdecimal/precs_spec.rb
deleted file mode 100644
index c7700a3819..0000000000
--- a/spec/ruby/library/bigdecimal/precs_spec.rb
+++ /dev/null
@@ -1,49 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require 'bigdecimal'
-
-describe "BigDecimal#precs" do
-
- before :each do
- @infinity = BigDecimal("Infinity")
- @infinity_neg = BigDecimal("-Infinity")
- @nan = BigDecimal("NaN")
- @zero = BigDecimal("0")
- @zero_neg = BigDecimal("-0")
-
- @arr = [BigDecimal("2E40001"), BigDecimal("3E-20001"),\
- @infinity, @infinity_neg, @nan, @zero, @zero_neg]
- @precision = BigDecimal::BASE.to_s.length - 1
- end
-
- it "returns array of two values" do
- @arr.each do |x|
- x.precs.kind_of?(Array).should == true
- x.precs.size.should == 2
- end
- end
-
- it "returns Integers as array values" do
- @arr.each do |x|
- x.precs[0].kind_of?(Integer).should == true
- x.precs[1].kind_of?(Integer).should == true
- end
- end
-
- it "returns the current value of significant digits as the first value" do
- BigDecimal("3.14159").precs[0].should >= 6
- BigDecimal('1').precs[0].should == BigDecimal('1' + '0' * 100).precs[0]
- [@infinity, @infinity_neg, @nan, @zero, @zero_neg].each do |value|
- value.precs[0].should <= @precision
- end
- end
-
- it "returns the maximum number of significant digits as the second value" do
- BigDecimal("3.14159").precs[1].should >= 6
- BigDecimal('1').precs[1].should >= 1
- BigDecimal('1' + '0' * 100).precs[1] >= 101
- [@infinity, @infinity_neg, @nan, @zero, @zero_neg].each do |value|
- value.precs[1].should >= 1
- end
- end
-end
-
diff --git a/spec/ruby/library/bigdecimal/quo_spec.rb b/spec/ruby/library/bigdecimal/quo_spec.rb
index bc27fd0f5e..65a4330303 100644
--- a/spec/ruby/library/bigdecimal/quo_spec.rb
+++ b/spec/ruby/library/bigdecimal/quo_spec.rb
@@ -1,13 +1,12 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/quo', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/quo'
require 'bigdecimal'
describe "BigDecimal#quo" do
it_behaves_like :bigdecimal_quo, :quo, []
it "returns NaN if NaN is involved" do
- BigDecimal("1").quo(BigDecimal("NaN")).nan?.should == true
- BigDecimal("NaN").quo(BigDecimal("1")).nan?.should == true
+ BigDecimal("1").quo(BigDecimal("NaN")).should.nan?
+ BigDecimal("NaN").quo(BigDecimal("1")).should.nan?
end
end
-
diff --git a/spec/ruby/library/bigdecimal/remainder_spec.rb b/spec/ruby/library/bigdecimal/remainder_spec.rb
index 796522c5c8..27a2986570 100644
--- a/spec/ruby/library/bigdecimal/remainder_spec.rb
+++ b/spec/ruby/library/bigdecimal/remainder_spec.rb
@@ -1,11 +1,12 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'bigdecimal'
describe "BigDecimal#remainder" do
before :each do
@zero = BigDecimal("0")
- @one = BigDecimal("0")
+ @one = BigDecimal("1")
+ @three = BigDecimal("3")
@mixed = BigDecimal("1.23456789")
@pos_int = BigDecimal("2E5555")
@neg_int = BigDecimal("-2E5555")
@@ -36,9 +37,11 @@ describe "BigDecimal#remainder" do
@neg_int.remainder(@pos_frac).should == @neg_int - @pos_frac * (@neg_int / @pos_frac).truncate
end
- it "returns NaN used with zero" do
- @mixed.remainder(@zero).nan?.should == true
- @zero.remainder(@zero).nan?.should == true
+ version_is BigDecimal::VERSION, "3.3.0" do
+ it "raises ZeroDivisionError used with zero" do
+ -> { @mixed.remainder(@zero) }.should.raise(ZeroDivisionError)
+ -> { @zero.remainder(@zero) }.should.raise(ZeroDivisionError)
+ end
end
it "returns zero if used on zero" do
@@ -46,39 +49,29 @@ describe "BigDecimal#remainder" do
end
it "returns NaN if NaN is involved" do
- @nan.remainder(@nan).nan?.should == true
- @nan.remainder(@one).nan?.should == true
- @one.remainder(@nan).nan?.should == true
- @infinity.remainder(@nan).nan?.should == true
- @nan.remainder(@infinity).nan?.should == true
- end
-
- it "returns NaN if Infinity is involved" do
- @infinity.remainder(@infinity).nan?.should == true
- @infinity.remainder(@one).nan?.should == true
- @infinity.remainder(@mixed).nan?.should == true
- @infinity.remainder(@one_minus).nan?.should == true
- @infinity.remainder(@frac_1).nan?.should == true
- @one.remainder(@infinity).nan?.should == true
-
- @infinity_minus.remainder(@infinity_minus).nan?.should == true
- @infinity_minus.remainder(@one).nan?.should == true
- @one.remainder(@infinity_minus).nan?.should == true
- @frac_2.remainder(@infinity_minus).nan?.should == true
-
- @infinity.remainder(@infinity_minus).nan?.should == true
- @infinity_minus.remainder(@infinity).nan?.should == true
+ @nan.remainder(@nan).should.nan?
+ @nan.remainder(@one).should.nan?
+ @one.remainder(@nan).should.nan?
+ @infinity.remainder(@nan).should.nan?
+ @nan.remainder(@infinity).should.nan?
end
it "coerces arguments to BigDecimal if possible" do
- @one.remainder(2).should == @one
+ @three.remainder(2).should == @one
end
+ describe "with Object" do
+ it "tries to coerce the other operand to self" do
+ object = mock("Object")
+ object.should_receive(:coerce).with(@three).and_return([@three, 2])
+ @three.remainder(object).should == @one
+ end
+ end
it "raises TypeError if the argument cannot be coerced to BigDecimal" do
- lambda {
+ -> {
@one.remainder('2')
- }.should raise_error(TypeError)
+ }.should.raise(TypeError)
end
end
diff --git a/spec/ruby/library/bigdecimal/round_spec.rb b/spec/ruby/library/bigdecimal/round_spec.rb
index 6c1987c5d8..622e129d93 100644
--- a/spec/ruby/library/bigdecimal/round_spec.rb
+++ b/spec/ruby/library/bigdecimal/round_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'bigdecimal'
describe "BigDecimal#round" do
@@ -62,141 +62,173 @@ describe "BigDecimal#round" do
@n2_49.round(0).should == @neg_two
end
- describe "BigDecimal::ROUND_UP" do
- it "rounds values away from zero" do
- @p1_50.round(0, BigDecimal::ROUND_UP).should == @two
- @p1_51.round(0, BigDecimal::ROUND_UP).should == @two
- @p1_49.round(0, BigDecimal::ROUND_UP).should == @two
- @n1_50.round(0, BigDecimal::ROUND_UP).should == @neg_two
- @n1_51.round(0, BigDecimal::ROUND_UP).should == @neg_two
- @n1_49.round(0, BigDecimal::ROUND_UP).should == @neg_two
-
- @p2_50.round(0, BigDecimal::ROUND_UP).should == @three
- @p2_51.round(0, BigDecimal::ROUND_UP).should == @three
- @p2_49.round(0, BigDecimal::ROUND_UP).should == @three
- @n2_50.round(0, BigDecimal::ROUND_UP).should == @neg_three
- @n2_51.round(0, BigDecimal::ROUND_UP).should == @neg_three
- @n2_49.round(0, BigDecimal::ROUND_UP).should == @neg_three
+ ["BigDecimal::ROUND_UP", ":up"].each do |way|
+ describe way do
+ it "rounds values away from zero" do
+ mode = eval(way)
+
+ @p1_50.round(0, mode).should == @two
+ @p1_51.round(0, mode).should == @two
+ @p1_49.round(0, mode).should == @two
+ @n1_50.round(0, mode).should == @neg_two
+ @n1_51.round(0, mode).should == @neg_two
+ @n1_49.round(0, mode).should == @neg_two
+
+ @p2_50.round(0, mode).should == @three
+ @p2_51.round(0, mode).should == @three
+ @p2_49.round(0, mode).should == @three
+ @n2_50.round(0, mode).should == @neg_three
+ @n2_51.round(0, mode).should == @neg_three
+ @n2_49.round(0, mode).should == @neg_three
+ end
end
end
- describe "BigDecimal::ROUND_DOWN" do
- it "rounds values towards zero" do
- @p1_50.round(0, BigDecimal::ROUND_DOWN).should == @one
- @p1_51.round(0, BigDecimal::ROUND_DOWN).should == @one
- @p1_49.round(0, BigDecimal::ROUND_DOWN).should == @one
- @n1_50.round(0, BigDecimal::ROUND_DOWN).should == @neg_one
- @n1_51.round(0, BigDecimal::ROUND_DOWN).should == @neg_one
- @n1_49.round(0, BigDecimal::ROUND_DOWN).should == @neg_one
-
- @p2_50.round(0, BigDecimal::ROUND_DOWN).should == @two
- @p2_51.round(0, BigDecimal::ROUND_DOWN).should == @two
- @p2_49.round(0, BigDecimal::ROUND_DOWN).should == @two
- @n2_50.round(0, BigDecimal::ROUND_DOWN).should == @neg_two
- @n2_51.round(0, BigDecimal::ROUND_DOWN).should == @neg_two
- @n2_49.round(0, BigDecimal::ROUND_DOWN).should == @neg_two
+ ["BigDecimal::ROUND_DOWN", ":down", ":truncate"].each do |way|
+ describe way do
+ it "rounds values towards zero" do
+ mode = eval(way)
+
+ @p1_50.round(0, mode).should == @one
+ @p1_51.round(0, mode).should == @one
+ @p1_49.round(0, mode).should == @one
+ @n1_50.round(0, mode).should == @neg_one
+ @n1_51.round(0, mode).should == @neg_one
+ @n1_49.round(0, mode).should == @neg_one
+
+ @p2_50.round(0, mode).should == @two
+ @p2_51.round(0, mode).should == @two
+ @p2_49.round(0, mode).should == @two
+ @n2_50.round(0, mode).should == @neg_two
+ @n2_51.round(0, mode).should == @neg_two
+ @n2_49.round(0, mode).should == @neg_two
+ end
end
end
- describe "BigDecimal::ROUND_HALF_UP" do
- it "rounds values >= 5 up, otherwise down" do
- @p1_50.round(0, BigDecimal::ROUND_HALF_UP).should == @two
- @p1_51.round(0, BigDecimal::ROUND_HALF_UP).should == @two
- @p1_49.round(0, BigDecimal::ROUND_HALF_UP).should == @one
- @n1_50.round(0, BigDecimal::ROUND_HALF_UP).should == @neg_two
- @n1_51.round(0, BigDecimal::ROUND_HALF_UP).should == @neg_two
- @n1_49.round(0, BigDecimal::ROUND_HALF_UP).should == @neg_one
-
- @p2_50.round(0, BigDecimal::ROUND_HALF_UP).should == @three
- @p2_51.round(0, BigDecimal::ROUND_HALF_UP).should == @three
- @p2_49.round(0, BigDecimal::ROUND_HALF_UP).should == @two
- @n2_50.round(0, BigDecimal::ROUND_HALF_UP).should == @neg_three
- @n2_51.round(0, BigDecimal::ROUND_HALF_UP).should == @neg_three
- @n2_49.round(0, BigDecimal::ROUND_HALF_UP).should == @neg_two
+ ["BigDecimal::ROUND_HALF_UP", ":half_up", ":default"].each do |way|
+ describe way do
+ it "rounds values >= 5 up, otherwise down" do
+ mode = eval(way)
+
+ @p1_50.round(0, mode).should == @two
+ @p1_51.round(0, mode).should == @two
+ @p1_49.round(0, mode).should == @one
+ @n1_50.round(0, mode).should == @neg_two
+ @n1_51.round(0, mode).should == @neg_two
+ @n1_49.round(0, mode).should == @neg_one
+
+ @p2_50.round(0, mode).should == @three
+ @p2_51.round(0, mode).should == @three
+ @p2_49.round(0, mode).should == @two
+ @n2_50.round(0, mode).should == @neg_three
+ @n2_51.round(0, mode).should == @neg_three
+ @n2_49.round(0, mode).should == @neg_two
+ end
end
end
- describe "BigDecimal::ROUND_HALF_DOWN" do
- it "rounds values > 5 up, otherwise down" do
- @p1_50.round(0, BigDecimal::ROUND_HALF_DOWN).should == @one
- @p1_51.round(0, BigDecimal::ROUND_HALF_DOWN).should == @two
- @p1_49.round(0, BigDecimal::ROUND_HALF_DOWN).should == @one
- @n1_50.round(0, BigDecimal::ROUND_HALF_DOWN).should == @neg_one
- @n1_51.round(0, BigDecimal::ROUND_HALF_DOWN).should == @neg_two
- @n1_49.round(0, BigDecimal::ROUND_HALF_DOWN).should == @neg_one
-
- @p2_50.round(0, BigDecimal::ROUND_HALF_DOWN).should == @two
- @p2_51.round(0, BigDecimal::ROUND_HALF_DOWN).should == @three
- @p2_49.round(0, BigDecimal::ROUND_HALF_DOWN).should == @two
- @n2_50.round(0, BigDecimal::ROUND_HALF_DOWN).should == @neg_two
- @n2_51.round(0, BigDecimal::ROUND_HALF_DOWN).should == @neg_three
- @n2_49.round(0, BigDecimal::ROUND_HALF_DOWN).should == @neg_two
+ ["BigDecimal::ROUND_HALF_DOWN", ":half_down"].each do |way|
+ describe way do
+ it "rounds values > 5 up, otherwise down" do
+ mode = eval(way)
+
+ @p1_50.round(0, mode).should == @one
+ @p1_51.round(0, mode).should == @two
+ @p1_49.round(0, mode).should == @one
+ @n1_50.round(0, mode).should == @neg_one
+ @n1_51.round(0, mode).should == @neg_two
+ @n1_49.round(0, mode).should == @neg_one
+
+ @p2_50.round(0, mode).should == @two
+ @p2_51.round(0, mode).should == @three
+ @p2_49.round(0, mode).should == @two
+ @n2_50.round(0, mode).should == @neg_two
+ @n2_51.round(0, mode).should == @neg_three
+ @n2_49.round(0, mode).should == @neg_two
+ end
end
end
- describe "BigDecimal::ROUND_CEILING" do
- it "rounds values towards +infinity" do
- @p1_50.round(0, BigDecimal::ROUND_CEILING).should == @two
- @p1_51.round(0, BigDecimal::ROUND_CEILING).should == @two
- @p1_49.round(0, BigDecimal::ROUND_CEILING).should == @two
- @n1_50.round(0, BigDecimal::ROUND_CEILING).should == @neg_one
- @n1_51.round(0, BigDecimal::ROUND_CEILING).should == @neg_one
- @n1_49.round(0, BigDecimal::ROUND_CEILING).should == @neg_one
-
- @p2_50.round(0, BigDecimal::ROUND_CEILING).should == @three
- @p2_51.round(0, BigDecimal::ROUND_CEILING).should == @three
- @p2_49.round(0, BigDecimal::ROUND_CEILING).should == @three
- @n2_50.round(0, BigDecimal::ROUND_CEILING).should == @neg_two
- @n2_51.round(0, BigDecimal::ROUND_CEILING).should == @neg_two
- @n2_49.round(0, BigDecimal::ROUND_CEILING).should == @neg_two
+ ["BigDecimal::ROUND_CEILING", ":ceiling", ":ceil"].each do |way|
+ describe way do
+ it "rounds values towards +infinity" do
+ mode = eval(way)
+
+ @p1_50.round(0, mode).should == @two
+ @p1_51.round(0, mode).should == @two
+ @p1_49.round(0, mode).should == @two
+ @n1_50.round(0, mode).should == @neg_one
+ @n1_51.round(0, mode).should == @neg_one
+ @n1_49.round(0, mode).should == @neg_one
+
+ @p2_50.round(0, mode).should == @three
+ @p2_51.round(0, mode).should == @three
+ @p2_49.round(0, mode).should == @three
+ @n2_50.round(0, mode).should == @neg_two
+ @n2_51.round(0, mode).should == @neg_two
+ @n2_49.round(0, mode).should == @neg_two
+ end
end
end
- describe "BigDecimal::ROUND_FLOOR" do
- it "rounds values towards -infinity" do
- @p1_50.round(0, BigDecimal::ROUND_FLOOR).should == @one
- @p1_51.round(0, BigDecimal::ROUND_FLOOR).should == @one
- @p1_49.round(0, BigDecimal::ROUND_FLOOR).should == @one
- @n1_50.round(0, BigDecimal::ROUND_FLOOR).should == @neg_two
- @n1_51.round(0, BigDecimal::ROUND_FLOOR).should == @neg_two
- @n1_49.round(0, BigDecimal::ROUND_FLOOR).should == @neg_two
-
- @p2_50.round(0, BigDecimal::ROUND_FLOOR).should == @two
- @p2_51.round(0, BigDecimal::ROUND_FLOOR).should == @two
- @p2_49.round(0, BigDecimal::ROUND_FLOOR).should == @two
- @n2_50.round(0, BigDecimal::ROUND_FLOOR).should == @neg_three
- @n2_51.round(0, BigDecimal::ROUND_FLOOR).should == @neg_three
- @n2_49.round(0, BigDecimal::ROUND_FLOOR).should == @neg_three
+ ["BigDecimal::ROUND_FLOOR", ":floor"].each do |way|
+ describe way do
+ it "rounds values towards -infinity" do
+ mode = eval(way)
+
+ @p1_50.round(0, mode).should == @one
+ @p1_51.round(0, mode).should == @one
+ @p1_49.round(0, mode).should == @one
+ @n1_50.round(0, mode).should == @neg_two
+ @n1_51.round(0, mode).should == @neg_two
+ @n1_49.round(0, mode).should == @neg_two
+
+ @p2_50.round(0, mode).should == @two
+ @p2_51.round(0, mode).should == @two
+ @p2_49.round(0, mode).should == @two
+ @n2_50.round(0, mode).should == @neg_three
+ @n2_51.round(0, mode).should == @neg_three
+ @n2_49.round(0, mode).should == @neg_three
+ end
end
end
- describe "BigDecimal::ROUND_HALF_EVEN" do
- it "rounds values > 5 up, < 5 down and == 5 towards even neighbor" do
- @p1_50.round(0, BigDecimal::ROUND_HALF_EVEN).should == @two
- @p1_51.round(0, BigDecimal::ROUND_HALF_EVEN).should == @two
- @p1_49.round(0, BigDecimal::ROUND_HALF_EVEN).should == @one
- @n1_50.round(0, BigDecimal::ROUND_HALF_EVEN).should == @neg_two
- @n1_51.round(0, BigDecimal::ROUND_HALF_EVEN).should == @neg_two
- @n1_49.round(0, BigDecimal::ROUND_HALF_EVEN).should == @neg_one
-
- @p2_50.round(0, BigDecimal::ROUND_HALF_EVEN).should == @two
- @p2_51.round(0, BigDecimal::ROUND_HALF_EVEN).should == @three
- @p2_49.round(0, BigDecimal::ROUND_HALF_EVEN).should == @two
- @n2_50.round(0, BigDecimal::ROUND_HALF_EVEN).should == @neg_two
- @n2_51.round(0, BigDecimal::ROUND_HALF_EVEN).should == @neg_three
- @n2_49.round(0, BigDecimal::ROUND_HALF_EVEN).should == @neg_two
+ ["BigDecimal::ROUND_HALF_EVEN", ":half_even", ":banker"].each do |way|
+ describe way do
+ it "rounds values > 5 up, < 5 down and == 5 towards even neighbor" do
+ mode = eval(way)
+
+ @p1_50.round(0, mode).should == @two
+ @p1_51.round(0, mode).should == @two
+ @p1_49.round(0, mode).should == @one
+ @n1_50.round(0, mode).should == @neg_two
+ @n1_51.round(0, mode).should == @neg_two
+ @n1_49.round(0, mode).should == @neg_one
+
+ @p2_50.round(0, mode).should == @two
+ @p2_51.round(0, mode).should == @three
+ @p2_49.round(0, mode).should == @two
+ @n2_50.round(0, mode).should == @neg_two
+ @n2_51.round(0, mode).should == @neg_three
+ @n2_49.round(0, mode).should == @neg_two
+ end
end
end
it 'raise exception, if self is special value' do
- lambda { BigDecimal('NaN').round }.should raise_error(FloatDomainError)
- lambda { BigDecimal('Infinity').round }.should raise_error(FloatDomainError)
- lambda { BigDecimal('-Infinity').round }.should raise_error(FloatDomainError)
+ -> { BigDecimal('NaN').round }.should.raise(FloatDomainError)
+ -> { BigDecimal('Infinity').round }.should.raise(FloatDomainError)
+ -> { BigDecimal('-Infinity').round }.should.raise(FloatDomainError)
end
it 'do not raise exception, if self is special value and precision is given' do
- lambda { BigDecimal('NaN').round(2) }.should_not raise_error(FloatDomainError)
- lambda { BigDecimal('Infinity').round(2) }.should_not raise_error(FloatDomainError)
- lambda { BigDecimal('-Infinity').round(2) }.should_not raise_error(FloatDomainError)
+ -> { BigDecimal('NaN').round(2) }.should_not.raise(FloatDomainError)
+ -> { BigDecimal('Infinity').round(2) }.should_not.raise(FloatDomainError)
+ -> { BigDecimal('-Infinity').round(2) }.should_not.raise(FloatDomainError)
+ end
+
+ it 'raise for a non-existent round mode' do
+ -> { @p1_50.round(0, :nonsense) }.should.raise(ArgumentError, "invalid rounding mode (nonsense)")
end
end
diff --git a/spec/ruby/library/bigdecimal/shared/eql.rb b/spec/ruby/library/bigdecimal/shared/eql.rb
deleted file mode 100644
index eaad272e9a..0000000000
--- a/spec/ruby/library/bigdecimal/shared/eql.rb
+++ /dev/null
@@ -1,61 +0,0 @@
-require 'bigdecimal'
-
-describe :bigdecimal_eql, shared: true do
- before :each do
- @bg6543_21 = BigDecimal.new("6543.21")
- @bg5667_19 = BigDecimal.new("5667.19")
- @a = BigDecimal("1.0000000000000000000000000000000000000000005")
- @b = BigDecimal("1.00000000000000000000000000000000000000000005")
- @bigint = BigDecimal("1000.0")
- @nan = BigDecimal("NaN")
- @infinity = BigDecimal("Infinity")
- @infinity_minus = BigDecimal("-Infinity")
- end
-
- it "tests for equality" do
- @bg6543_21.send(@method, @bg6543_21).should == true
- @a.send(@method, @a).should == true
- @a.send(@method, @b).should == false
- @bg6543_21.send(@method, @a).should == false
- @bigint.send(@method, 1000).should == true
- end
-
- it "returns false for NaN as it is never equal to any number" do
- @nan.send(@method, @nan).should == false
- @a.send(@method, @nan).should == false
- @nan.send(@method, @a).should == false
- @nan.send(@method, @infinity).should == false
- @nan.send(@method, @infinity_minus).should == false
- @infinity.send(@method, @nan).should == false
- @infinity_minus.send(@method, @nan).should == false
- end
-
- it "returns true for infinity values with the same sign" do
- @infinity.send(@method, @infinity).should == true
- @infinity.send(@method, BigDecimal("Infinity")).should == true
- BigDecimal("Infinity").send(@method, @infinity).should == true
-
- @infinity_minus.send(@method, @infinity_minus).should == true
- @infinity_minus.send(@method, BigDecimal("-Infinity")).should == true
- BigDecimal("-Infinity").send(@method, @infinity_minus).should == true
- end
-
- it "returns false for infinity values with different signs" do
- @infinity.send(@method, @infinity_minus).should == false
- @infinity_minus.send(@method, @infinity).should == false
- end
-
- it "returns false when infinite value compared to finite one" do
- @infinity.send(@method, @a).should == false
- @infinity_minus.send(@method, @a).should == false
-
- @a.send(@method, @infinity).should == false
- @a.send(@method, @infinity_minus).should == false
- end
-
- it "returns false when compared objects that can not be coerced into BigDecimal" do
- @infinity.send(@method, nil).should == false
- @bigint.send(@method, nil).should == false
- @nan.send(@method, nil).should == false
- end
-end
diff --git a/spec/ruby/library/bigdecimal/shared/modulo.rb b/spec/ruby/library/bigdecimal/shared/modulo.rb
index 78ebe8360d..5b5e3503c4 100644
--- a/spec/ruby/library/bigdecimal/shared/modulo.rb
+++ b/spec/ruby/library/bigdecimal/shared/modulo.rb
@@ -18,8 +18,8 @@ describe :bigdecimal_modulo, shared: true do
end
it "returns self modulo other" do
- bd6543 = BigDecimal.new("6543.21")
- bd5667 = BigDecimal.new("5667.19")
+ bd6543 = BigDecimal("6543.21")
+ bd5667 = BigDecimal("5667.19")
a = BigDecimal("1.0000000000000000000000000000000000000000005")
b = BigDecimal("1.00000000000000000000000000000000000000000005")
@@ -70,47 +70,52 @@ describe :bigdecimal_modulo, shared: true do
res.kind_of?(BigDecimal).should == true
end
+ describe "with Object" do
+ it "tries to coerce the other operand to self" do
+ bd6543 = BigDecimal("6543.21")
+ object = mock("Object")
+ object.should_receive(:coerce).with(bd6543).and_return([bd6543, 137])
+ bd6543.send(@method, object, *@object).should == BigDecimal("104.21")
+ end
+ end
+
it "returns NaN if NaN is involved" do
- @nan.send(@method, @nan).nan?.should == true
- @nan.send(@method, @one).nan?.should == true
- @one.send(@method, @nan).nan?.should == true
- @infinity.send(@method, @nan).nan?.should == true
- @nan.send(@method, @infinity).nan?.should == true
+ @nan.send(@method, @nan).should.nan?
+ @nan.send(@method, @one).should.nan?
+ @one.send(@method, @nan).should.nan?
+ @infinity.send(@method, @nan).should.nan?
+ @nan.send(@method, @infinity).should.nan?
end
it "returns NaN if the dividend is Infinity" do
- @infinity.send(@method, @infinity).nan?.should == true
- @infinity.send(@method, @one).nan?.should == true
- @infinity.send(@method, @mixed).nan?.should == true
- @infinity.send(@method, @one_minus).nan?.should == true
- @infinity.send(@method, @frac_1).nan?.should == true
+ @infinity.send(@method, @infinity).should.nan?
+ @infinity.send(@method, @one).should.nan?
+ @infinity.send(@method, @mixed).should.nan?
+ @infinity.send(@method, @one_minus).should.nan?
+ @infinity.send(@method, @frac_1).should.nan?
- @infinity_minus.send(@method, @infinity_minus).nan?.should == true
- @infinity_minus.send(@method, @one).nan?.should == true
+ @infinity_minus.send(@method, @infinity_minus).should.nan?
+ @infinity_minus.send(@method, @one).should.nan?
- @infinity.send(@method, @infinity_minus).nan?.should == true
- @infinity_minus.send(@method, @infinity).nan?.should == true
+ @infinity.send(@method, @infinity_minus).should.nan?
+ @infinity_minus.send(@method, @infinity).should.nan?
end
- it "returns the dividend if the divisor is Infinity" do
- @one.send(@method, @infinity).should == @one
- @one.send(@method, @infinity_minus).should == @one
- @frac_2.send(@method, @infinity_minus).should == @frac_2
+ version_is BigDecimal::VERSION, "3.3.0" do
+ it "returns the dividend if the divisor is Infinity and signs are same" do
+ @one.send(@method, @infinity).should == @one
+ (-@frac_2).send(@method, @infinity_minus).should == -@frac_2
+ end
+
+ it "returns the divisor if the divisor is Infinity and signs are different" do
+ (-@one).send(@method, @infinity).should == @infinity
+ @frac_2.send(@method, @infinity_minus).should == @infinity_minus
+ end
end
it "raises TypeError if the argument cannot be coerced to BigDecimal" do
- lambda {
+ -> {
@one.send(@method, '2')
- }.should raise_error(TypeError)
- end
-end
-
-describe :bigdecimal_modulo_zerodivisionerror, shared: true do
- it "raises ZeroDivisionError if other is zero" do
- bd5667 = BigDecimal.new("5667.19")
-
- lambda { bd5667.send(@method, 0) }.should raise_error(ZeroDivisionError)
- lambda { bd5667.send(@method, BigDecimal("0")) }.should raise_error(ZeroDivisionError)
- lambda { @zero.send(@method, @zero) }.should raise_error(ZeroDivisionError)
+ }.should.raise(TypeError)
end
end
diff --git a/spec/ruby/library/bigdecimal/shared/mult.rb b/spec/ruby/library/bigdecimal/shared/mult.rb
index b94c9385de..c613df04c4 100644
--- a/spec/ruby/library/bigdecimal/shared/mult.rb
+++ b/spec/ruby/library/bigdecimal/shared/mult.rb
@@ -51,8 +51,8 @@ describe :bigdecimal_mult, shared: true do
values = @regular_vals + @zeroes
values.each do |val|
- @nan.send(@method, val, *@object).nan?.should == true
- val.send(@method, @nan, *@object).nan?.should == true
+ @nan.send(@method, val, *@object).should.nan?
+ val.send(@method, @nan, *@object).should.nan?
end
end
@@ -62,9 +62,9 @@ describe :bigdecimal_mult, shared: true do
values.each do |val|
@zeroes.each do |zero|
zero.send(@method, val, *@object).should == 0
- zero.send(@method, val, *@object).zero?.should == true
+ zero.send(@method, val, *@object).should.zero?
val.send(@method, zero, *@object).should == 0
- val.send(@method, zero, *@object).zero?.should == true
+ val.send(@method, zero, *@object).should.zero?
end
end
end
@@ -75,8 +75,8 @@ describe :bigdecimal_mult, shared: true do
values.each do |val|
infs.each do |inf|
- inf.send(@method, val, *@object).finite?.should == false
- val.send(@method, inf, *@object).finite?.should == false
+ inf.send(@method, val, *@object).should_not.finite?
+ val.send(@method, inf, *@object).should_not.finite?
end
end
@@ -89,9 +89,9 @@ describe :bigdecimal_mult, shared: true do
end
it "returns NaN if the result is undefined" do
- @zero.send(@method, @infinity, *@object).nan?.should == true
- @zero.send(@method, @infinity_minus, *@object).nan?.should == true
- @infinity.send(@method, @zero, *@object).nan?.should == true
- @infinity_minus.send(@method, @zero, *@object).nan?.should == true
+ @zero.send(@method, @infinity, *@object).should.nan?
+ @zero.send(@method, @infinity_minus, *@object).should.nan?
+ @infinity.send(@method, @zero, *@object).should.nan?
+ @infinity_minus.send(@method, @zero, *@object).should.nan?
end
end
diff --git a/spec/ruby/library/bigdecimal/shared/power.rb b/spec/ruby/library/bigdecimal/shared/power.rb
index a4848fb2e2..6dafb638e2 100644
--- a/spec/ruby/library/bigdecimal/shared/power.rb
+++ b/spec/ruby/library/bigdecimal/shared/power.rb
@@ -10,8 +10,8 @@ describe :bigdecimal_power, shared: true do
e = BigDecimal("1.00000000000000000000123456789")
one = BigDecimal("1")
ten = BigDecimal("10")
- # The tolerance is dependent upon the size of BASE_FIG
- tolerance = BigDecimal("1E-70")
+ # Accuracy is at least ndigits(== 30) + DOUBLE_FIG(== 16)
+ tolerance = BigDecimal("1E-46")
ten_powers = BigDecimal("1E10000")
pi = BigDecimal("3.14159265358979")
e3_minus.send(@method, 2).should == e3_minus_power_2
@@ -53,8 +53,8 @@ describe :bigdecimal_power, shared: true do
end
it "returns NaN if self is NaN" do
- BigDecimal("NaN").send(@method, -5).nan?.should == true
- BigDecimal("NaN").send(@method, 5).nan?.should == true
+ BigDecimal("NaN").send(@method, -5).should.nan?
+ BigDecimal("NaN").send(@method, 5).should.nan?
end
it "returns 0.0 if self is infinite and argument is negative" do
diff --git a/spec/ruby/library/bigdecimal/shared/quo.rb b/spec/ruby/library/bigdecimal/shared/quo.rb
index cb51c10d71..18ff2fe9a5 100644
--- a/spec/ruby/library/bigdecimal/shared/quo.rb
+++ b/spec/ruby/library/bigdecimal/shared/quo.rb
@@ -29,6 +29,15 @@ describe :bigdecimal_quo, shared: true do
@one.send(@method, BigDecimal('2E-5555'), *@object).should == BigDecimal('0.5E5555')
end
+ describe "with Object" do
+ it "tries to coerce the other operand to self" do
+ skip if @method == :div
+ object = mock("Object")
+ object.should_receive(:coerce).with(@one).and_return([@one, @two])
+ @one.send(@method, object, *@object).should == BigDecimal("0.5")
+ end
+ end
+
it "returns 0 if divided by Infinity" do
@zero.send(@method, @infinity, *@object).should == 0
@frac_2.send(@method, @infinity, *@object).should == 0
@@ -41,8 +50,8 @@ describe :bigdecimal_quo, shared: true do
end
it "returns NaN if Infinity / ((+|-) Infinity)" do
- @infinity.send(@method, @infinity_minus, *@object).nan?.should == true
- @infinity_minus.send(@method, @infinity, *@object).nan?.should == true
+ @infinity.send(@method, @infinity_minus, *@object).should.nan?
+ @infinity_minus.send(@method, @infinity, *@object).should.nan?
end
it "returns (+|-) Infinity if divided by zero" do
@@ -52,8 +61,8 @@ describe :bigdecimal_quo, shared: true do
end
it "returns NaN if zero is divided by zero" do
- @zero.send(@method, @zero, *@object).nan?.should == true
- @zero_minus.send(@method, @zero_plus, *@object).nan?.should == true
- @zero_plus.send(@method, @zero_minus, *@object).nan?.should == true
+ @zero.send(@method, @zero, *@object).should.nan?
+ @zero_minus.send(@method, @zero_plus, *@object).should.nan?
+ @zero_plus.send(@method, @zero_minus, *@object).should.nan?
end
end
diff --git a/spec/ruby/library/bigdecimal/shared/to_int.rb b/spec/ruby/library/bigdecimal/shared/to_int.rb
deleted file mode 100644
index 729a25f511..0000000000
--- a/spec/ruby/library/bigdecimal/shared/to_int.rb
+++ /dev/null
@@ -1,16 +0,0 @@
-require 'bigdecimal'
-
-describe :bigdecimal_to_int , shared: true do
- it "raises FloatDomainError if BigDecimal is infinity or NaN" do
- lambda { BigDecimal("Infinity").send(@method) }.should raise_error(FloatDomainError)
- lambda { BigDecimal("NaN").send(@method) }.should raise_error(FloatDomainError)
- end
-
- it "returns Integer or Bignum otherwise" do
- BigDecimal("3E-20001").send(@method).should == 0
- BigDecimal("2E4000").send(@method).should == 2 * 10 ** 4000
- BigDecimal("2").send(@method).should == 2
- BigDecimal("2E10").send(@method).should == 20000000000
- BigDecimal("3.14159").send(@method).should == 3
- end
-end
diff --git a/spec/ruby/library/bigdecimal/sign_spec.rb b/spec/ruby/library/bigdecimal/sign_spec.rb
index 85aa74741c..ae2c28e9fd 100644
--- a/spec/ruby/library/bigdecimal/sign_spec.rb
+++ b/spec/ruby/library/bigdecimal/sign_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'bigdecimal'
describe "BigDecimal#sign" do
@@ -44,4 +44,3 @@ describe "BigDecimal#sign" do
end
end
-
diff --git a/spec/ruby/library/bigdecimal/split_spec.rb b/spec/ruby/library/bigdecimal/split_spec.rb
index e2ba955a3b..53b1f649d9 100644
--- a/spec/ruby/library/bigdecimal/split_spec.rb
+++ b/spec/ruby/library/bigdecimal/split_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'bigdecimal'
describe "BigDecimal#split" do
@@ -58,16 +58,16 @@ describe "BigDecimal#split" do
end
it "third value: the base (currently always ten)" do
- @arr[2].should == 10
- @arr_neg[2].should == 10
- @arr_big[2].should == 10
- @arr_big_neg[2].should == 10
- @huge[2].should == 10
- @infinity.split[2].should == 10
- @nan.split[2].should == 10
- @infinity_neg.split[2].should == 10
- @zero.split[2].should == 10
- @zero_neg.split[2].should == 10
+ @arr[2].should == 10
+ @arr_neg[2].should == 10
+ @arr_big[2].should == 10
+ @arr_big_neg[2].should == 10
+ @huge[2].should == 10
+ @infinity.split[2].should == 10
+ @nan.split[2].should == 10
+ @infinity_neg.split[2].should == 10
+ @zero.split[2].should == 10
+ @zero_neg.split[2].should == 10
end
it "fourth value: the exponent" do
@@ -84,5 +84,3 @@ describe "BigDecimal#split" do
end
end
-
-
diff --git a/spec/ruby/library/bigdecimal/sqrt_spec.rb b/spec/ruby/library/bigdecimal/sqrt_spec.rb
index f677192b33..1f3ef9a8c3 100644
--- a/spec/ruby/library/bigdecimal/sqrt_spec.rb
+++ b/spec/ruby/library/bigdecimal/sqrt_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
require 'bigdecimal'
describe "BigDecimal#sqrt" do
@@ -36,44 +36,46 @@ describe "BigDecimal#sqrt" do
BigDecimal('121').sqrt(5).should be_close(11, 0.00001)
end
- it "returns square root of 0.9E-99999 with desired precision" do
- @frac_2.sqrt(1).to_s.should =~ /\A0\.3E-49999\z/i
+ platform_is_not c_long_size: 32 do # fails on i686
+ it "returns square root of 0.9E-99999 with desired precision" do
+ @frac_2.sqrt(1).to_s.should =~ /\A0\.3E-49999\z/i
+ end
end
it "raises ArgumentError when no argument is given" do
- lambda {
+ -> {
@one.sqrt
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
end
it "raises ArgumentError if a negative number is given" do
- lambda {
+ -> {
@one.sqrt(-1)
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
end
it "raises ArgumentError if 2 arguments are given" do
- lambda {
+ -> {
@one.sqrt(1, 1)
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
end
it "raises TypeError if nil is given" do
- lambda {
+ -> {
@one.sqrt(nil)
- }.should raise_error(TypeError)
+ }.should.raise(TypeError)
end
it "raises TypeError if a string is given" do
- lambda {
+ -> {
@one.sqrt("stuff")
- }.should raise_error(TypeError)
+ }.should.raise(TypeError)
end
it "raises TypeError if a plain Object is given" do
- lambda {
+ -> {
@one.sqrt(Object.new)
- }.should raise_error(TypeError)
+ }.should.raise(TypeError)
end
it "returns 1 if precision is 0 or 1" do
@@ -82,25 +84,25 @@ describe "BigDecimal#sqrt" do
end
it "raises FloatDomainError on negative values" do
- lambda {
+ -> {
BigDecimal('-1').sqrt(10)
- }.should raise_error(FloatDomainError)
+ }.should.raise(FloatDomainError)
end
- it "returns positive infitinity for infinity" do
+ it "returns positive infinity for infinity" do
@infinity.sqrt(1).should == @infinity
end
it "raises FloatDomainError for negative infinity" do
- lambda {
+ -> {
@infinity_minus.sqrt(1)
- }.should raise_error(FloatDomainError)
+ }.should.raise(FloatDomainError)
end
it "raises FloatDomainError for NaN" do
- lambda {
+ -> {
@nan.sqrt(1)
- }.should raise_error(FloatDomainError)
+ }.should.raise(FloatDomainError)
end
it "returns 0 for 0, +0.0 and -0.0" do
diff --git a/spec/ruby/library/bigdecimal/sub_spec.rb b/spec/ruby/library/bigdecimal/sub_spec.rb
index 06ad3b79d2..3b62a0c794 100644
--- a/spec/ruby/library/bigdecimal/sub_spec.rb
+++ b/spec/ruby/library/bigdecimal/sub_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'bigdecimal'
describe "BigDecimal#sub" do
@@ -7,12 +7,15 @@ describe "BigDecimal#sub" do
@one = BigDecimal("1")
@zero = BigDecimal("0")
@two = BigDecimal("2")
+ @three = BigDecimal("3")
@nan = BigDecimal("NaN")
@infinity = BigDecimal("Infinity")
@infinity_minus = BigDecimal("-Infinity")
@one_minus = BigDecimal("-1")
@frac_1 = BigDecimal("1E-99999")
@frac_2 = BigDecimal("0.9E-99999")
+ @frac_3 = BigDecimal("12345E10")
+ @frac_4 = BigDecimal("98765E10")
end
it "returns a - b with given precision" do
@@ -32,14 +35,20 @@ describe "BigDecimal#sub" do
@frac_1.sub(@frac_1, 1000000).should == @zero
end
+ describe "with Rational" do
+ it "produces a BigDecimal" do
+ (@three - Rational(500, 2)).should == BigDecimal('-0.247e3')
+ end
+ end
+
it "returns NaN if NaN is involved" do
- @one.sub(@nan, 1).nan?.should == true
- @nan.sub(@one, 1).nan?.should == true
+ @one.sub(@nan, 1).should.nan?
+ @nan.sub(@one, 1).should.nan?
end
it "returns NaN if both values are infinite with the same signs" do
- @infinity.sub(@infinity, 1).nan?.should == true
- @infinity_minus.sub(@infinity_minus, 1).nan?.should == true
+ @infinity.sub(@infinity, 1).should.nan?
+ @infinity_minus.sub(@infinity_minus, 1).should.nan?
end
it "returns Infinity or -Infinity if these are involved" do
diff --git a/spec/ruby/library/bigdecimal/to_d_spec.rb b/spec/ruby/library/bigdecimal/to_d_spec.rb
new file mode 100644
index 0000000000..50aea99bf7
--- /dev/null
+++ b/spec/ruby/library/bigdecimal/to_d_spec.rb
@@ -0,0 +1,10 @@
+require_relative '../../spec_helper'
+require 'bigdecimal'
+require 'bigdecimal/util'
+
+describe "Float#to_d" do
+ it "returns appropriate BigDecimal zero for signed zero" do
+ -0.0.to_d.sign.should == -1
+ 0.0.to_d.sign.should == 1
+ end
+end
diff --git a/spec/ruby/library/bigdecimal/to_f_spec.rb b/spec/ruby/library/bigdecimal/to_f_spec.rb
index b490fce4d9..f5220d995a 100644
--- a/spec/ruby/library/bigdecimal/to_f_spec.rb
+++ b/spec/ruby/library/bigdecimal/to_f_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'bigdecimal'
describe "BigDecimal#to_f" do
@@ -20,9 +20,9 @@ describe "BigDecimal#to_f" do
end
it "returns number of type float" do
- BigDecimal("3.14159").to_f.should be_kind_of(Float)
- @vals.each { |val| val.to_f.should be_kind_of(Float) }
- @spec_vals.each { |val| val.to_f.should be_kind_of(Float) }
+ BigDecimal("3.14159").to_f.should.is_a?(Float)
+ @vals.each { |val| val.to_f.should.is_a?(Float) }
+ @spec_vals.each { |val| val.to_f.should.is_a?(Float) }
end
it "rounds correctly to Float precision" do
@@ -41,7 +41,7 @@ describe "BigDecimal#to_f" do
@zero.to_f.should == 0
@zero.to_f.to_s.should == "0.0"
- @nan.to_f.nan?.should == true
+ @nan.to_f.should.nan?
@infinity.to_f.infinite?.should == 1
@infinity_minus.to_f.infinite?.should == -1
@@ -52,4 +52,3 @@ describe "BigDecimal#to_f" do
@zero_neg.to_f.to_s.should == "-0.0"
end
end
-
diff --git a/spec/ruby/library/bigdecimal/to_i_spec.rb b/spec/ruby/library/bigdecimal/to_i_spec.rb
index 8db69003c5..b6d9e43e57 100644
--- a/spec/ruby/library/bigdecimal/to_i_spec.rb
+++ b/spec/ruby/library/bigdecimal/to_i_spec.rb
@@ -1,7 +1,17 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/to_int', __FILE__)
+require_relative '../../spec_helper'
require 'bigdecimal'
describe "BigDecimal#to_i" do
- it_behaves_like(:bigdecimal_to_int, :to_i)
+ it "raises FloatDomainError if BigDecimal is infinity or NaN" do
+ -> { BigDecimal("Infinity").to_i }.should.raise(FloatDomainError)
+ -> { BigDecimal("NaN").to_i }.should.raise(FloatDomainError)
+ end
+
+ it "returns Integer otherwise" do
+ BigDecimal("3E-20001").to_i.should == 0
+ BigDecimal("2E4000").to_i.should == 2 * 10 ** 4000
+ BigDecimal("2").to_i.should == 2
+ BigDecimal("2E10").to_i.should == 20000000000
+ BigDecimal("3.14159").to_i.should == 3
+ end
end
diff --git a/spec/ruby/library/bigdecimal/to_int_spec.rb b/spec/ruby/library/bigdecimal/to_int_spec.rb
index 56a60d4a03..18f3620f5e 100644
--- a/spec/ruby/library/bigdecimal/to_int_spec.rb
+++ b/spec/ruby/library/bigdecimal/to_int_spec.rb
@@ -1,8 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/to_int', __FILE__)
+require_relative '../../spec_helper'
require 'bigdecimal'
-
describe "BigDecimal#to_int" do
- it_behaves_like(:bigdecimal_to_int, :to_int)
+ it "is an alias of BigDecimal#to_i" do
+ BigDecimal.instance_method(:to_int).should == BigDecimal.instance_method(:to_i)
+ end
end
diff --git a/spec/ruby/library/bigdecimal/to_r_spec.rb b/spec/ruby/library/bigdecimal/to_r_spec.rb
index 6f6e5a1bea..a112c002ef 100644
--- a/spec/ruby/library/bigdecimal/to_r_spec.rb
+++ b/spec/ruby/library/bigdecimal/to_r_spec.rb
@@ -1,16 +1,28 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'bigdecimal'
describe "BigDecimal#to_r" do
it "returns a Rational" do
- BigDecimal("3.14159").to_r.should be_kind_of(Rational)
+ BigDecimal("3.14159").to_r.should.is_a?(Rational)
end
it "returns a Rational with bignum values" do
- r = BigDecimal.new("3.141592653589793238462643").to_r
- r.numerator.should eql(3141592653589793238462643)
- r.denominator.should eql(1000000000000000000000000)
+ r = BigDecimal("3.141592653589793238462643").to_r
+ r.numerator.should.eql?(3141592653589793238462643)
+ r.denominator.should.eql?(1000000000000000000000000)
+ end
+
+ it "returns a Rational from a BigDecimal with an exponent" do
+ r = BigDecimal("1E2").to_r
+ r.numerator.should.eql?(100)
+ r.denominator.should.eql?(1)
+ end
+
+ it "returns a Rational from a negative BigDecimal with an exponent" do
+ r = BigDecimal("-1E2").to_r
+ r.numerator.should.eql?(-100)
+ r.denominator.should.eql?(1)
end
end
diff --git a/spec/ruby/library/bigdecimal/to_s_spec.rb b/spec/ruby/library/bigdecimal/to_s_spec.rb
index b97311c800..5ec54765b5 100644
--- a/spec/ruby/library/bigdecimal/to_s_spec.rb
+++ b/spec/ruby/library/bigdecimal/to_s_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'bigdecimal'
describe "BigDecimal#to_s" do
@@ -8,6 +8,11 @@ describe "BigDecimal#to_s" do
@bigneg_str = "-3.1415926535897932384626433832795028841971693993"
@bigdec = BigDecimal(@bigdec_str)
@bigneg = BigDecimal(@bigneg_str)
+ @internal = Encoding.default_internal
+ end
+
+ after :each do
+ Encoding.default_internal = @internal
end
it "return type is of class String" do
@@ -15,12 +20,18 @@ describe "BigDecimal#to_s" do
@bigneg.to_s.kind_of?(String).should == true
end
- it "the default format looks like 0.xxxxEnn" do
- @bigdec.to_s.should =~ /^0\.[0-9]*E[0-9]*$/i
+ it "the default format looks like 0.xxxxenn" do
+ @bigdec.to_s.should =~ /^0\.[0-9]*e[0-9]*$/
+ end
+
+ it "does not add an exponent for zero values" do
+ BigDecimal("0").to_s.should == "0.0"
+ BigDecimal("+0").to_s.should == "0.0"
+ BigDecimal("-0").to_s.should == "-0.0"
end
it "takes an optional argument" do
- lambda {@bigdec.to_s("F")}.should_not raise_error()
+ -> {@bigdec.to_s("F")}.should_not.raise()
end
it "starts with + if + is supplied and value is positive" do
@@ -28,17 +39,21 @@ describe "BigDecimal#to_s" do
@bigneg.to_s("+").should_not =~ /^\+.*/
end
- it "inserts a space every n chars, if integer n is supplied" do
+ it "inserts a space every n chars to fraction part, if integer n is supplied" do
re =\
- /\A0\.314 159 265 358 979 323 846 264 338 327 950 288 419 716 939 937E1\z/i
+ /\A0\.314 159 265 358 979 323 846 264 338 327 950 288 419 716 939 937E1\z/i
@bigdec.to_s(3).should =~ re
str1 = '-123.45678 90123 45678 9'
- BigDecimal.new("-123.45678901234567890").to_s('5F').should == str1
+ BigDecimal("-123.45678901234567890").to_s('5F').should == str1
# trailing zeroes removed
- BigDecimal.new("1.00000000000").to_s('1F').should == "1.0"
+ BigDecimal("1.00000000000").to_s('1F').should == "1.0"
# 0 is treated as no spaces
- BigDecimal.new("1.2345").to_s('0F').should == "1.2345"
+ BigDecimal("1.2345").to_s('0F').should == "1.2345"
+ end
+
+ it "inserts a space every n chars to integer part, if integer n is supplied" do
+ BigDecimal('1000010').to_s('5F').should == "10 00010.0"
end
it "can return a leading space for values > 0" do
@@ -47,15 +62,15 @@ describe "BigDecimal#to_s" do
end
it "removes trailing spaces in floating point notation" do
- BigDecimal.new('-123.45678901234567890').to_s('F').should == "-123.4567890123456789"
- BigDecimal.new('1.2500').to_s('F').should == "1.25"
- BigDecimal.new('0000.00000').to_s('F').should == "0.0"
- BigDecimal.new('-00.000010000').to_s('F').should == "-0.00001"
- BigDecimal.new("5.00000E-2").to_s("F").should == "0.05"
-
- BigDecimal.new("500000").to_s("F").should == "500000.0"
- BigDecimal.new("5E2").to_s("F").should == "500.0"
- BigDecimal.new("-5E100").to_s("F").should == "-5" + "0" * 100 + ".0"
+ BigDecimal('-123.45678901234567890').to_s('F').should == "-123.4567890123456789"
+ BigDecimal('1.2500').to_s('F').should == "1.25"
+ BigDecimal('0000.00000').to_s('F').should == "0.0"
+ BigDecimal('-00.000010000').to_s('F').should == "-0.00001"
+ BigDecimal("5.00000E-2").to_s("F").should == "0.05"
+
+ BigDecimal("500000").to_s("F").should == "500000.0"
+ BigDecimal("5E2").to_s("F").should == "500.0"
+ BigDecimal("-5E100").to_s("F").should == "-5" + "0" * 100 + ".0"
end
it "can use engineering notation" do
@@ -63,11 +78,21 @@ describe "BigDecimal#to_s" do
end
it "can use conventional floating point notation" do
- @bigdec.to_s("F").should == @bigdec_str
- @bigneg.to_s("F").should == @bigneg_str
- str2 = "+123.45678901 23456789"
- BigDecimal.new('123.45678901234567890').to_s('+8F').should == str2
+ %w[f F].each do |format_char|
+ @bigdec.to_s(format_char).should == @bigdec_str
+ @bigneg.to_s(format_char).should == @bigneg_str
+ str2 = "+123.45678901 23456789"
+ BigDecimal('123.45678901234567890').to_s("+8#{format_char}").should == str2
+ end
end
-end
+ it "returns a String in US-ASCII encoding when Encoding.default_internal is nil" do
+ Encoding.default_internal = nil
+ BigDecimal('1.23').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
+ BigDecimal('1.23').to_s.encoding.should.equal?(Encoding::US_ASCII)
+ end
+end
diff --git a/spec/ruby/library/bigdecimal/truncate_spec.rb b/spec/ruby/library/bigdecimal/truncate_spec.rb
index 41f0afc8fa..cedc662aeb 100644
--- a/spec/ruby/library/bigdecimal/truncate_spec.rb
+++ b/spec/ruby/library/bigdecimal/truncate_spec.rb
@@ -1,14 +1,14 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'bigdecimal'
describe "BigDecimal#truncate" do
before :each do
- @arr = ['3.14159', '8.7', "0.314159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593014782083152134043E1"]
- @big = BigDecimal("123456.789")
- @nan = BigDecimal('NaN')
- @infinity = BigDecimal('Infinity')
- @infinity_negative = BigDecimal('-Infinity')
+ @arr = ['3.14159', '8.7', "0.314159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593014782083152134043E1"]
+ @big = BigDecimal("123456.789")
+ @nan = BigDecimal('NaN')
+ @infinity = BigDecimal('Infinity')
+ @infinity_negative = BigDecimal('-Infinity')
end
it "returns value of type Integer." do
@@ -58,9 +58,9 @@ describe "BigDecimal#truncate" do
end
it "returns NaN if self is NaN" do
- @nan.truncate(-1).nan?.should == true
- @nan.truncate(+1).nan?.should == true
- @nan.truncate(0).nan?.should == true
+ @nan.truncate(-1).should.nan?
+ @nan.truncate(+1).should.nan?
+ @nan.truncate(0).should.nan?
end
it "returns Infinity if self is infinite" do
@@ -74,8 +74,8 @@ describe "BigDecimal#truncate" do
end
it "returns the same value if self is special value" do
- lambda { @nan.truncate }.should raise_error(FloatDomainError)
- lambda { @infinity.truncate }.should raise_error(FloatDomainError)
- lambda { @infinity_negative.truncate }.should raise_error(FloatDomainError)
+ -> { @nan.truncate }.should.raise(FloatDomainError)
+ -> { @infinity.truncate }.should.raise(FloatDomainError)
+ -> { @infinity_negative.truncate }.should.raise(FloatDomainError)
end
end
diff --git a/spec/ruby/library/bigdecimal/uminus_spec.rb b/spec/ruby/library/bigdecimal/uminus_spec.rb
index 901f9f59ce..c780cdfac5 100644
--- a/spec/ruby/library/bigdecimal/uminus_spec.rb
+++ b/spec/ruby/library/bigdecimal/uminus_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'bigdecimal'
describe "BigDecimal#-@" do
@@ -53,6 +53,6 @@ describe "BigDecimal#-@" do
@zero_neg.send(:-@).should == @zero
@zero_neg.send(:-@).sign.should == 1
- @nan.send(:-@).nan?.should == true
+ @nan.send(:-@).should.nan?
end
end
diff --git a/spec/ruby/library/bigdecimal/uplus_spec.rb b/spec/ruby/library/bigdecimal/uplus_spec.rb
index 00aadc723c..77483046b7 100644
--- a/spec/ruby/library/bigdecimal/uplus_spec.rb
+++ b/spec/ruby/library/bigdecimal/uplus_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'bigdecimal'
describe "BigDecimal#+@" do
@@ -15,6 +15,3 @@ describe "BigDecimal#+@" do
fifth.send(:+@).should == fifth
end
end
-
-
-
diff --git a/spec/ruby/library/bigdecimal/util_spec.rb b/spec/ruby/library/bigdecimal/util_spec.rb
new file mode 100644
index 0000000000..69663d4bd2
--- /dev/null
+++ b/spec/ruby/library/bigdecimal/util_spec.rb
@@ -0,0 +1,40 @@
+require_relative '../../spec_helper'
+require 'bigdecimal'
+require 'bigdecimal/util'
+
+describe "BigDecimal's util method definitions" do
+ describe "#to_d" do
+ it "should define #to_d on Integer" do
+ 42.to_d.should == BigDecimal(42)
+ end
+
+ it "should define #to_d on Float" do
+ 0.5.to_d.should == BigDecimal(0.5, Float::DIG)
+ 1.234.to_d(2).should == BigDecimal(1.234, 2)
+ end
+
+ it "should define #to_d on String" do
+ "0.5".to_d.should == BigDecimal(0.5, Float::DIG)
+ "45.67 degrees".to_d.should == BigDecimal(45.67, Float::DIG)
+ end
+
+ it "should define #to_d on BigDecimal" do
+ bd = BigDecimal("3.14")
+ bd.to_d.should.equal?(bd)
+ end
+
+ it "should define #to_d on Rational" do
+ Rational(22, 7).to_d(3).should == BigDecimal(3.14, 3)
+ end
+
+ it "should define #to_d on nil" do
+ nil.to_d.should == BigDecimal(0)
+ end
+ end
+
+ describe "#to_digits" do
+ it "should define #to_digits on BigDecimal" do
+ BigDecimal("3.14").to_digits.should == "3.14"
+ end
+ end
+end
diff --git a/spec/ruby/library/bigdecimal/ver_spec.rb b/spec/ruby/library/bigdecimal/ver_spec.rb
deleted file mode 100644
index 61b073d8f1..0000000000
--- a/spec/ruby/library/bigdecimal/ver_spec.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require 'bigdecimal'
-
-describe "BigDecimal.ver" do
-
- it "returns the Version number" do
- lambda {BigDecimal.ver }.should_not raise_error()
- BigDecimal.ver.should_not == nil
- end
-
-end
diff --git a/spec/ruby/library/bigdecimal/zero_spec.rb b/spec/ruby/library/bigdecimal/zero_spec.rb
index 7dbb0fa7f0..2563210939 100644
--- a/spec/ruby/library/bigdecimal/zero_spec.rb
+++ b/spec/ruby/library/bigdecimal/zero_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'bigdecimal'
describe "BigDecimal#zero?" do
@@ -6,23 +6,22 @@ describe "BigDecimal#zero?" do
it "returns true if self does equal zero" do
really_small_zero = BigDecimal("0E-200000000")
really_big_zero = BigDecimal("0E200000000000")
- really_small_zero.zero?.should == true
- really_big_zero.zero?.should == true
- BigDecimal("0.000000000000000000000000").zero?.should == true
- BigDecimal("0").zero?.should == true
- BigDecimal("0E0").zero?.should == true
- BigDecimal("+0").zero?.should == true
- BigDecimal("-0").zero?.should == true
+ really_small_zero.should.zero?
+ really_big_zero.should.zero?
+ BigDecimal("0.000000000000000000000000").should.zero?
+ BigDecimal("0").should.zero?
+ BigDecimal("0E0").should.zero?
+ BigDecimal("+0").should.zero?
+ BigDecimal("-0").should.zero?
end
it "returns false otherwise" do
- BigDecimal("0000000001").zero?.should == false
- BigDecimal("2E40001").zero?.should == false
- BigDecimal("3E-20001").zero?.should == false
- BigDecimal("Infinity").zero?.should == false
- BigDecimal("-Infinity").zero?.should == false
- BigDecimal("NaN").zero?.should == false
+ BigDecimal("0000000001").should_not.zero?
+ BigDecimal("2E40001").should_not.zero?
+ BigDecimal("3E-20001").should_not.zero?
+ BigDecimal("Infinity").should_not.zero?
+ BigDecimal("-Infinity").should_not.zero?
+ BigDecimal("NaN").should_not.zero?
end
end
-
diff --git a/spec/ruby/library/bigmath/log_spec.rb b/spec/ruby/library/bigmath/log_spec.rb
deleted file mode 100644
index 126461f0e8..0000000000
--- a/spec/ruby/library/bigmath/log_spec.rb
+++ /dev/null
@@ -1,10 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require 'bigdecimal'
-
-describe "BigDecimal#log" do
- it "handles high-precision Rational arguments" do
- result = BigDecimal('0.22314354220170971436137296411949880462556361100856391620766259404746040597133837784E0')
- r = Rational(1_234_567_890, 987_654_321)
- BigMath.log(r, 50).should == result
- end
-end
diff --git a/spec/ruby/library/cgi/cookie/domain_spec.rb b/spec/ruby/library/cgi/cookie/domain_spec.rb
index 05137dd4d1..c118ef6383 100644
--- a/spec/ruby/library/cgi/cookie/domain_spec.rb
+++ b/spec/ruby/library/cgi/cookie/domain_spec.rb
@@ -1,23 +1,26 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
+require_relative '../../../spec_helper'
-describe "CGI::Cookie#domain" do
- it "returns self's domain" do
- cookie = CGI::Cookie.new("test-cookie")
- cookie.domain.should be_nil
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- cookie = CGI::Cookie.new("name" => "test-cookie", "domain" => "example.com")
- cookie.domain.should == "example.com"
+ describe "CGI::Cookie#domain" do
+ it "returns self's domain" do
+ cookie = CGI::Cookie.new("test-cookie")
+ cookie.domain.should == nil
+
+ cookie = CGI::Cookie.new("name" => "test-cookie", "domain" => "example.com")
+ cookie.domain.should == "example.com"
+ end
end
-end
-describe "CGI::Cookie#domain=" do
- it "sets self's domain" do
- cookie = CGI::Cookie.new("test-cookie")
- cookie.domain = "test.com"
- cookie.domain.should == "test.com"
+ describe "CGI::Cookie#domain=" do
+ it "sets self's domain" do
+ cookie = CGI::Cookie.new("test-cookie")
+ cookie.domain = "test.com"
+ cookie.domain.should == "test.com"
- cookie.domain = "example.com"
- cookie.domain.should == "example.com"
+ cookie.domain = "example.com"
+ cookie.domain.should == "example.com"
+ end
end
end
diff --git a/spec/ruby/library/cgi/cookie/expires_spec.rb b/spec/ruby/library/cgi/cookie/expires_spec.rb
index 89f18fe071..b9cc7d5b65 100644
--- a/spec/ruby/library/cgi/cookie/expires_spec.rb
+++ b/spec/ruby/library/cgi/cookie/expires_spec.rb
@@ -1,23 +1,26 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
+require_relative '../../../spec_helper'
-describe "CGI::Cookie#expires" do
- it "returns self's expiration date" do
- cookie = CGI::Cookie.new("test-cookie")
- cookie.expires.should be_nil
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- cookie = CGI::Cookie.new("name" => "test-cookie", "expires" => Time.at(1196524602))
- cookie.expires.should == Time.at(1196524602)
+ describe "CGI::Cookie#expires" do
+ it "returns self's expiration date" do
+ cookie = CGI::Cookie.new("test-cookie")
+ cookie.expires.should == nil
+
+ cookie = CGI::Cookie.new("name" => "test-cookie", "expires" => Time.at(1196524602))
+ cookie.expires.should == Time.at(1196524602)
+ end
end
-end
-describe "CGI::Cookie#expires=" do
- it "sets self's expiration date" do
- cookie = CGI::Cookie.new("test-cookie")
- cookie.expires = Time.at(1196524602)
- cookie.expires.should == Time.at(1196524602)
+ describe "CGI::Cookie#expires=" do
+ it "sets self's expiration date" do
+ cookie = CGI::Cookie.new("test-cookie")
+ cookie.expires = Time.at(1196524602)
+ cookie.expires.should == Time.at(1196524602)
- cookie.expires = Time.at(1196525000)
- cookie.expires.should == Time.at(1196525000)
+ cookie.expires = Time.at(1196525000)
+ cookie.expires.should == Time.at(1196525000)
+ end
end
end
diff --git a/spec/ruby/library/cgi/cookie/initialize_spec.rb b/spec/ruby/library/cgi/cookie/initialize_spec.rb
index 02f2a8ed2b..80bc2c2196 100644
--- a/spec/ruby/library/cgi/cookie/initialize_spec.rb
+++ b/spec/ruby/library/cgi/cookie/initialize_spec.rb
@@ -1,147 +1,150 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
+require_relative '../../../spec_helper'
-describe "CGI::Cookie#initialize when passed String" do
- before :each do
- @cookie = CGI::Cookie.allocate
- end
-
- it "sets the self's name to the passed String" do
- @cookie.send(:initialize, "test-cookie")
- @cookie.name.should == "test-cookie"
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- it "sets the self's value to an empty Array" do
- @cookie.send(:initialize, "test-cookie")
- @cookie.value.should == []
- end
-
- it "sets self to a non-secure cookie" do
- @cookie.send(:initialize, "test")
- @cookie.secure.should be_false
- end
-
- it "does set self's path to an empty String when ENV[\"SCRIPT_NAME\"] is not set" do
- @cookie.send(:initialize, "test-cookie")
- @cookie.path.should == ""
- end
-
- it "does set self's path based on ENV[\"SCRIPT_NAME\"] when ENV[\"SCRIPT_NAME\"] is set" do
- old_script_name = ENV["SCRIPT_NAME"]
+ describe "CGI::Cookie#initialize when passed String" do
+ before :each do
+ @cookie = CGI::Cookie.allocate
+ end
- begin
- ENV["SCRIPT_NAME"] = "some/path/script.rb"
+ it "sets the self's name to the passed String" do
@cookie.send(:initialize, "test-cookie")
- @cookie.path.should == "some/path/"
+ @cookie.name.should == "test-cookie"
+ end
- ENV["SCRIPT_NAME"] = "script.rb"
+ it "sets the self's value to an empty Array" do
@cookie.send(:initialize, "test-cookie")
- @cookie.path.should == ""
+ @cookie.value.should == []
+ end
- ENV["SCRIPT_NAME"] = nil
+ it "sets self to a non-secure cookie" do
+ @cookie.send(:initialize, "test")
+ @cookie.secure.should == false
+ end
+
+ it "does set self's path to an empty String when ENV[\"SCRIPT_NAME\"] is not set" do
@cookie.send(:initialize, "test-cookie")
@cookie.path.should == ""
- ensure
- ENV["SCRIPT_NAME"] = old_script_name
end
- end
- it "does not set self's expiration date" do
- @cookie.expires.should be_nil
- end
+ it "does set self's path based on ENV[\"SCRIPT_NAME\"] when ENV[\"SCRIPT_NAME\"] is set" do
+ old_script_name = ENV["SCRIPT_NAME"]
- it "does not set self's domain" do
- @cookie.domain.should be_nil
- end
-end
+ begin
+ ENV["SCRIPT_NAME"] = "some/path/script.rb"
+ @cookie.send(:initialize, "test-cookie")
+ @cookie.path.should == "some/path/"
-describe "CGI::Cookie#initialize when passed Hash" do
- before :each do
- @cookie = CGI::Cookie.allocate
- end
+ ENV["SCRIPT_NAME"] = "script.rb"
+ @cookie.send(:initialize, "test-cookie")
+ @cookie.path.should == ""
+
+ ENV["SCRIPT_NAME"] = nil
+ @cookie.send(:initialize, "test-cookie")
+ @cookie.path.should == ""
+ ensure
+ ENV["SCRIPT_NAME"] = old_script_name
+ end
+ end
+
+ it "does not set self's expiration date" do
+ @cookie.expires.should == nil
+ end
- it "sets self's contents based on the passed Hash" do
- @cookie.send(:initialize,
- 'name' => 'test-cookie',
- 'value' => ["one", "two", "three"],
- 'path' => 'some/path/',
- 'domain' => 'example.com',
- 'expires' => Time.at(1196524602),
- 'secure' => true)
-
- @cookie.name.should == "test-cookie"
- @cookie.value.should == ["one", "two", "three"]
- @cookie.path.should == "some/path/"
- @cookie.domain.should == "example.com"
- @cookie.expires.should == Time.at(1196524602)
- @cookie.secure.should be_true
+ it "does not set self's domain" do
+ @cookie.domain.should == nil
+ end
end
- it "does set self's path based on ENV[\"SCRIPT_NAME\"] when the Hash has no 'path' entry" do
- old_script_name = ENV["SCRIPT_NAME"]
+ describe "CGI::Cookie#initialize when passed Hash" do
+ before :each do
+ @cookie = CGI::Cookie.allocate
+ end
- begin
- ENV["SCRIPT_NAME"] = "some/path/script.rb"
- @cookie.send(:initialize, 'name' => 'test-cookie')
+ it "sets self's contents based on the passed Hash" do
+ @cookie.send(:initialize,
+ 'name' => 'test-cookie',
+ 'value' => ["one", "two", "three"],
+ 'path' => 'some/path/',
+ 'domain' => 'example.com',
+ 'expires' => Time.at(1196524602),
+ 'secure' => true)
+
+ @cookie.name.should == "test-cookie"
+ @cookie.value.should == ["one", "two", "three"]
@cookie.path.should == "some/path/"
+ @cookie.domain.should == "example.com"
+ @cookie.expires.should == Time.at(1196524602)
+ @cookie.secure.should == true
+ end
- ENV["SCRIPT_NAME"] = "script.rb"
- @cookie.send(:initialize, 'name' => 'test-cookie')
- @cookie.path.should == ""
+ it "does set self's path based on ENV[\"SCRIPT_NAME\"] when the Hash has no 'path' entry" do
+ old_script_name = ENV["SCRIPT_NAME"]
- ENV["SCRIPT_NAME"] = nil
- @cookie.send(:initialize, 'name' => 'test-cookie')
- @cookie.path.should == ""
- ensure
- ENV["SCRIPT_NAME"] = old_script_name
+ begin
+ ENV["SCRIPT_NAME"] = "some/path/script.rb"
+ @cookie.send(:initialize, 'name' => 'test-cookie')
+ @cookie.path.should == "some/path/"
+
+ ENV["SCRIPT_NAME"] = "script.rb"
+ @cookie.send(:initialize, 'name' => 'test-cookie')
+ @cookie.path.should == ""
+
+ ENV["SCRIPT_NAME"] = nil
+ @cookie.send(:initialize, 'name' => 'test-cookie')
+ @cookie.path.should == ""
+ ensure
+ ENV["SCRIPT_NAME"] = old_script_name
+ end
end
- end
- it "tries to convert the Hash's 'value' to an Array using #Array" do
- obj = mock("Converted To Array")
- obj.should_receive(:to_ary).and_return(["1", "2", "3"])
- @cookie.send(:initialize,
- 'name' => 'test-cookie',
- 'value' => obj)
- @cookie.value.should == [ "1", "2", "3" ]
-
- obj = mock("Converted To Array")
- obj.should_receive(:to_a).and_return(["one", "two", "three"])
- @cookie.send(:initialize,
- 'name' => 'test-cookie',
- 'value' => obj)
- @cookie.value.should == [ "one", "two", "three" ]
-
- obj = mock("Put into an Array")
- @cookie.send(:initialize,
- 'name' => 'test-cookie',
- 'value' => obj)
- @cookie.value.should == [ obj ]
- end
+ it "tries to convert the Hash's 'value' to an Array using #Array" do
+ obj = mock("Converted To Array")
+ obj.should_receive(:to_ary).and_return(["1", "2", "3"])
+ @cookie.send(:initialize,
+ 'name' => 'test-cookie',
+ 'value' => obj)
+ @cookie.value.should == [ "1", "2", "3" ]
+
+ obj = mock("Converted To Array")
+ obj.should_receive(:to_a).and_return(["one", "two", "three"])
+ @cookie.send(:initialize,
+ 'name' => 'test-cookie',
+ 'value' => obj)
+ @cookie.value.should == [ "one", "two", "three" ]
+
+ obj = mock("Put into an Array")
+ @cookie.send(:initialize,
+ 'name' => 'test-cookie',
+ 'value' => obj)
+ @cookie.value.should == [ obj ]
+ end
- it "raises a ArgumentError when the passed Hash has no 'name' entry" do
- lambda { @cookie.send(:initialize, {}) }.should raise_error(ArgumentError)
- lambda { @cookie.send(:initialize, "value" => "test") }.should raise_error(ArgumentError)
+ it "raises a ArgumentError when the passed Hash has no 'name' entry" do
+ -> { @cookie.send(:initialize, {}) }.should.raise(ArgumentError)
+ -> { @cookie.send(:initialize, "value" => "test") }.should.raise(ArgumentError)
+ end
end
-end
-describe "CGI::Cookie#initialize when passed String, values ..." do
- before :each do
- @cookie = CGI::Cookie.allocate
- end
+ describe "CGI::Cookie#initialize when passed String, values ..." do
+ before :each do
+ @cookie = CGI::Cookie.allocate
+ end
- it "sets the self's name to the passed String" do
- @cookie.send(:initialize, "test-cookie", "one", "two", "three")
- @cookie.name.should == "test-cookie"
- end
+ it "sets the self's name to the passed String" do
+ @cookie.send(:initialize, "test-cookie", "one", "two", "three")
+ @cookie.name.should == "test-cookie"
+ end
- it "sets the self's value to an Array containing all passed values" do
- @cookie.send(:initialize, "test-cookie", "one", "two", "three")
- @cookie.value.should == ["one", "two", "three"]
- end
+ it "sets the self's value to an Array containing all passed values" do
+ @cookie.send(:initialize, "test-cookie", "one", "two", "three")
+ @cookie.value.should == ["one", "two", "three"]
+ end
- it "sets self to a non-secure cookie" do
- @cookie.send(:initialize, "test", "one", "two", "three")
- @cookie.secure.should be_false
+ it "sets self to a non-secure cookie" do
+ @cookie.send(:initialize, "test", "one", "two", "three")
+ @cookie.secure.should == false
+ end
end
end
diff --git a/spec/ruby/library/cgi/cookie/name_spec.rb b/spec/ruby/library/cgi/cookie/name_spec.rb
index 8a6be95944..4908204e8a 100644
--- a/spec/ruby/library/cgi/cookie/name_spec.rb
+++ b/spec/ruby/library/cgi/cookie/name_spec.rb
@@ -1,23 +1,26 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
+require_relative '../../../spec_helper'
-describe "CGI::Cookie#name" do
- it "returns self's name" do
- cookie = CGI::Cookie.new("test-cookie")
- cookie.name.should == "test-cookie"
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- cookie = CGI::Cookie.new("name" => "another cookie")
- cookie.name.should == "another cookie"
+ describe "CGI::Cookie#name" do
+ it "returns self's name" do
+ cookie = CGI::Cookie.new("test-cookie")
+ cookie.name.should == "test-cookie"
+
+ cookie = CGI::Cookie.new("name" => "another-cookie")
+ cookie.name.should == "another-cookie"
+ end
end
-end
-describe "CGI::Cookie#name=" do
- it "sets self's expiration date" do
- cookie = CGI::Cookie.new("test-cookie")
- cookie.name = "another name"
- cookie.name.should == "another name"
+ describe "CGI::Cookie#name=" do
+ it "sets self's expiration date" do
+ cookie = CGI::Cookie.new("test-cookie")
+ cookie.name = "another-name"
+ cookie.name.should == "another-name"
- cookie.name = "and one more"
- cookie.name.should == "and one more"
+ cookie.name = "and-one-more"
+ cookie.name.should == "and-one-more"
+ end
end
end
diff --git a/spec/ruby/library/cgi/cookie/parse_spec.rb b/spec/ruby/library/cgi/cookie/parse_spec.rb
index 6f615c0d23..bc505c37ba 100644
--- a/spec/ruby/library/cgi/cookie/parse_spec.rb
+++ b/spec/ruby/library/cgi/cookie/parse_spec.rb
@@ -1,39 +1,29 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
+require_relative '../../../spec_helper'
-describe "CGI::Cookie.parse" do
- it "parses a raw cookie string into a hash of Cookies" do
- expected = { "test-cookie" => ["one", "two", "three"] }
- CGI::Cookie.parse("test-cookie=one&two&three").should == expected
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- expected = { "second cookie" => ["three", "four"], "first cookie" => ["one", "two"] }
- CGI::Cookie.parse("first cookie=one&two;second cookie=three&four").should == expected
- end
+ describe "CGI::Cookie.parse" do
+ it "parses a raw cookie string into a hash of Cookies" do
+ expected = { "test-cookie" => ["one", "two", "three"] }
+ CGI::Cookie.parse("test-cookie=one&two&three").should == expected
- ruby_version_is ""..."2.4" do
- it "uses , for cookie separators" do
- expected = {
- "first cookie" => ["one", "two"],
- "second cookie" => ["three", "four"],
- "third_cookie" => ["five", "six"]
- }
- CGI::Cookie.parse("first cookie=one&two;second cookie=three&four,third_cookie=five&six").should == expected
+ expected = { "second-cookie" => ["three", "four"], "first-cookie" => ["one", "two"] }
+ CGI::Cookie.parse("first-cookie=one&two;second-cookie=three&four").should == expected
end
- end
- ruby_version_is "2.4" do
it "does not use , for cookie separators" do
expected = {
- "first cookie" => ["one", "two"],
- "second cookie" => ["three", "four,third_cookie=five", "six"]
+ "first-cookie" => ["one", "two"],
+ "second-cookie" => ["three", "four,third_cookie=five", "six"]
}
- CGI::Cookie.parse("first cookie=one&two;second cookie=three&four,third_cookie=five&six").should == expected
+ CGI::Cookie.parse("first-cookie=one&two;second-cookie=three&four,third_cookie=five&six").should == expected
end
- end
- it "unescapes the Cookie values" do
- cookie = "test-cookie=+%21%22%23%24%25%26%27%28%29%2A%2B%2C-.%2F0123456789%3A%3B%3C%3D%3E%3F%40ABCDEFGHIJKLMNOPQRSTUVWXYZ%5B%5C%5D%5E_%60abcdefghijklmnopqrstuvwxyz%7B%7C%7D%7E"
- expected = { "test-cookie" => [ " !\"\#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~" ] }
- CGI::Cookie.parse(cookie).should == expected
+ it "unescapes the Cookie values" do
+ cookie = "test-cookie=+%21%22%23%24%25%26%27%28%29%2A%2B%2C-.%2F0123456789%3A%3B%3C%3D%3E%3F%40ABCDEFGHIJKLMNOPQRSTUVWXYZ%5B%5C%5D%5E_%60abcdefghijklmnopqrstuvwxyz%7B%7C%7D%7E"
+ expected = { "test-cookie" => [ " !\"\#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~" ] }
+ CGI::Cookie.parse(cookie).should == expected
+ end
end
end
diff --git a/spec/ruby/library/cgi/cookie/path_spec.rb b/spec/ruby/library/cgi/cookie/path_spec.rb
index 2a21a55264..13ee5d726b 100644
--- a/spec/ruby/library/cgi/cookie/path_spec.rb
+++ b/spec/ruby/library/cgi/cookie/path_spec.rb
@@ -1,23 +1,26 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
+require_relative '../../../spec_helper'
-describe "CGI::Cookie#path" do
- it "returns self's path" do
- cookie = CGI::Cookie.new("test-cookie")
- cookie.path.should == ""
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- cookie = CGI::Cookie.new("name" => "test-cookie", "path" => "/some/path/")
- cookie.path.should == "/some/path/"
+ describe "CGI::Cookie#path" do
+ it "returns self's path" do
+ cookie = CGI::Cookie.new("test-cookie")
+ cookie.path.should == ""
+
+ cookie = CGI::Cookie.new("name" => "test-cookie", "path" => "/some/path/")
+ cookie.path.should == "/some/path/"
+ end
end
-end
-describe "CGI::Cookie#path=" do
- it "sets self's path" do
- cookie = CGI::Cookie.new("test-cookie")
- cookie.path = "/some/path/"
- cookie.path.should == "/some/path/"
+ describe "CGI::Cookie#path=" do
+ it "sets self's path" do
+ cookie = CGI::Cookie.new("test-cookie")
+ cookie.path = "/some/path/"
+ cookie.path.should == "/some/path/"
- cookie.path = "/another/path/"
- cookie.path.should == "/another/path/"
+ cookie.path = "/another/path/"
+ cookie.path.should == "/another/path/"
+ end
end
end
diff --git a/spec/ruby/library/cgi/cookie/secure_spec.rb b/spec/ruby/library/cgi/cookie/secure_spec.rb
index 37e9dbfda9..233881b173 100644
--- a/spec/ruby/library/cgi/cookie/secure_spec.rb
+++ b/spec/ruby/library/cgi/cookie/secure_spec.rb
@@ -1,70 +1,73 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
+require_relative '../../../spec_helper'
-describe "CGI::Cookie#secure" do
- before :each do
- @cookie = CGI::Cookie.new("test-cookie")
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- it "returns whether self is a secure cookie or not" do
- @cookie.secure = true
- @cookie.secure.should be_true
+ describe "CGI::Cookie#secure" do
+ before :each do
+ @cookie = CGI::Cookie.new("test-cookie")
+ end
- @cookie.secure = false
- @cookie.secure.should be_false
- end
-end
+ it "returns whether self is a secure cookie or not" do
+ @cookie.secure = true
+ @cookie.secure.should == true
-describe "CGI::Cookie#secure= when passed true" do
- before :each do
- @cookie = CGI::Cookie.new("test-cookie")
+ @cookie.secure = false
+ @cookie.secure.should == false
+ end
end
- it "returns true" do
- (@cookie.secure = true).should be_true
- end
+ describe "CGI::Cookie#secure= when passed true" do
+ before :each do
+ @cookie = CGI::Cookie.new("test-cookie")
+ end
- it "sets self to a secure cookie" do
- @cookie.secure = true
- @cookie.secure.should be_true
- end
-end
+ it "returns true" do
+ (@cookie.secure = true).should == true
+ end
-describe "CGI::Cookie#secure= when passed false" do
- before :each do
- @cookie = CGI::Cookie.new("test-cookie")
+ it "sets self to a secure cookie" do
+ @cookie.secure = true
+ @cookie.secure.should == true
+ end
end
- it "returns false" do
- (@cookie.secure = false).should be_false
- end
+ describe "CGI::Cookie#secure= when passed false" do
+ before :each do
+ @cookie = CGI::Cookie.new("test-cookie")
+ end
- it "sets self to a non-secure cookie" do
- @cookie.secure = false
- @cookie.secure.should be_false
- end
-end
+ it "returns false" do
+ (@cookie.secure = false).should == false
+ end
-describe "CGI::Cookie#secure= when passed Object" do
- before :each do
- @cookie = CGI::Cookie.new("test-cookie")
+ it "sets self to a non-secure cookie" do
+ @cookie.secure = false
+ @cookie.secure.should == false
+ end
end
- it "does not change self's secure value" do
- @cookie.secure = false
+ describe "CGI::Cookie#secure= when passed Object" do
+ before :each do
+ @cookie = CGI::Cookie.new("test-cookie")
+ end
+
+ it "does not change self's secure value" do
+ @cookie.secure = false
- @cookie.secure = Object.new
- @cookie.secure.should be_false
+ @cookie.secure = Object.new
+ @cookie.secure.should == false
- @cookie.secure = "Test"
- @cookie.secure.should be_false
+ @cookie.secure = "Test"
+ @cookie.secure.should == false
- @cookie.secure = true
+ @cookie.secure = true
- @cookie.secure = Object.new
- @cookie.secure.should be_true
+ @cookie.secure = Object.new
+ @cookie.secure.should == true
- @cookie.secure = "Test"
- @cookie.secure.should be_true
+ @cookie.secure = "Test"
+ @cookie.secure.should == true
+ end
end
end
diff --git a/spec/ruby/library/cgi/cookie/to_s_spec.rb b/spec/ruby/library/cgi/cookie/to_s_spec.rb
index 806071ba69..20d2579f8d 100644
--- a/spec/ruby/library/cgi/cookie/to_s_spec.rb
+++ b/spec/ruby/library/cgi/cookie/to_s_spec.rb
@@ -1,42 +1,36 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
-
-describe "CGI::Cookie#to_s" do
- it "returns a String representation of self" do
- cookie = CGI::Cookie.new("test-cookie")
- cookie.to_s.should == "test-cookie=; path="
-
- cookie = CGI::Cookie.new("test-cookie", "value")
- cookie.to_s.should == "test-cookie=value; path="
-
- cookie = CGI::Cookie.new("test-cookie", "one", "two", "three")
- cookie.to_s.should == "test-cookie=one&two&three; path="
-
- cookie = CGI::Cookie.new(
- 'name' => 'test-cookie',
- 'value' => ["one", "two", "three"],
- 'path' => 'some/path/',
- 'domain' => 'example.com',
- 'expires' => Time.at(1196524602),
- 'secure' => true)
- cookie.to_s.should == "test-cookie=one&two&three; domain=example.com; path=some/path/; expires=Sat, 01 Dec 2007 15:56:42 GMT; secure"
- end
-
- it "escapes the self's values" do
- cookie = CGI::Cookie.new("test-cookie", " !\"\#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}")
- cookie.to_s.should == "test-cookie=+%21%22%23%24%25%26%27%28%29%2A%2B%2C-.%2F0123456789%3A%3B%3C%3D%3E%3F%40ABCDEFGHIJKLMNOPQRSTUVWXYZ%5B%5C%5D%5E_%60abcdefghijklmnopqrstuvwxyz%7B%7C%7D; path="
- end
+require_relative '../../../spec_helper'
+
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+
+ describe "CGI::Cookie#to_s" do
+ it "returns a String representation of self" do
+ cookie = CGI::Cookie.new("test-cookie")
+ cookie.to_s.should == "test-cookie=; path="
+
+ cookie = CGI::Cookie.new("test-cookie", "value")
+ cookie.to_s.should == "test-cookie=value; path="
+
+ cookie = CGI::Cookie.new("test-cookie", "one", "two", "three")
+ cookie.to_s.should == "test-cookie=one&two&three; path="
+
+ cookie = CGI::Cookie.new(
+ 'name' => 'test-cookie',
+ 'value' => ["one", "two", "three"],
+ 'path' => 'some/path/',
+ 'domain' => 'example.com',
+ 'expires' => Time.at(1196524602),
+ 'secure' => true)
+ cookie.to_s.should == "test-cookie=one&two&three; domain=example.com; path=some/path/; expires=Sat, 01 Dec 2007 15:56:42 GMT; secure"
+ end
- ruby_version_is ""..."2.5" do
- it "escapes tilde" do
- cookie = CGI::Cookie.new("test-cookie", "~").to_s.should == "test-cookie=%7E; path="
+ it "escapes the self's values" do
+ cookie = CGI::Cookie.new("test-cookie", " !\"\#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}")
+ cookie.to_s.should == "test-cookie=+%21%22%23%24%25%26%27%28%29%2A%2B%2C-.%2F0123456789%3A%3B%3C%3D%3E%3F%40ABCDEFGHIJKLMNOPQRSTUVWXYZ%5B%5C%5D%5E_%60abcdefghijklmnopqrstuvwxyz%7B%7C%7D; path="
end
- end
- ruby_version_is "2.5" do
it "does not escape tilde" do
cookie = CGI::Cookie.new("test-cookie", "~").to_s.should == "test-cookie=~; path="
end
end
-
end
diff --git a/spec/ruby/library/cgi/cookie/value_spec.rb b/spec/ruby/library/cgi/cookie/value_spec.rb
index 81e3daf7de..45032edcbf 100644
--- a/spec/ruby/library/cgi/cookie/value_spec.rb
+++ b/spec/ruby/library/cgi/cookie/value_spec.rb
@@ -1,76 +1,79 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
+require_relative '../../../spec_helper'
-describe "CGI::Cookie#value" do
- it "returns self's value" do
- cookie = CGI::Cookie.new("test-cookie")
- cookie.value.should == []
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- cookie = CGI::Cookie.new("test-cookie", "one")
- cookie.value.should == ["one"]
+ describe "CGI::Cookie#value" do
+ it "returns self's value" do
+ cookie = CGI::Cookie.new("test-cookie")
+ cookie.value.should == []
- cookie = CGI::Cookie.new("test-cookie", "one", "two", "three")
- cookie.value.should == ["one", "two", "three"]
+ cookie = CGI::Cookie.new("test-cookie", "one")
+ cookie.value.should == ["one"]
- cookie = CGI::Cookie.new("name" => "test-cookie", "value" => ["one", "two", "three"])
- cookie.value.should == ["one", "two", "three"]
- end
+ cookie = CGI::Cookie.new("test-cookie", "one", "two", "three")
+ cookie.value.should == ["one", "two", "three"]
- it "is in synch with self" do
- fail = []
- [
- :pop,
- :shift,
- [:<<, "Hello"],
- [:push, "Hello"],
- [:unshift, "World"],
- [:replace, ["A", "B"]],
- [:[]=, 1, "Set"],
- [:delete, "first"],
- [:delete_at, 0],
- ].each do |method, *args|
- cookie1 = CGI::Cookie.new("test-cookie", "first", "second")
- cookie2 = CGI::Cookie.new("test-cookie", "first", "second")
- cookie1.send(method, *args)
- cookie2.value.send(method, *args)
- fail << method unless cookie1.value == cookie2.value
+ cookie = CGI::Cookie.new("name" => "test-cookie", "value" => ["one", "two", "three"])
+ cookie.value.should == ["one", "two", "three"]
end
- fail.should be_empty
- end
-end
-describe "CGI::Cookie#value=" do
- before :each do
- @cookie = CGI::Cookie.new("test-cookie")
+ it "is in synch with self" do
+ fail = []
+ [
+ :pop,
+ :shift,
+ [:<<, "Hello"],
+ [:push, "Hello"],
+ [:unshift, "World"],
+ [:replace, ["A", "B"]],
+ [:[]=, 1, "Set"],
+ [:delete, "first"],
+ [:delete_at, 0],
+ ].each do |method, *args|
+ cookie1 = CGI::Cookie.new("test-cookie", "first", "second")
+ cookie2 = CGI::Cookie.new("test-cookie", "first", "second")
+ cookie1.send(method, *args)
+ cookie2.value.send(method, *args)
+ fail << method unless cookie1.value == cookie2.value
+ end
+ fail.should.empty?
+ end
end
- it "sets self's value" do
- @cookie.value = ["one"]
- @cookie.value.should == ["one"]
+ describe "CGI::Cookie#value=" do
+ before :each do
+ @cookie = CGI::Cookie.new("test-cookie")
+ end
- @cookie.value = ["one", "two", "three"]
- @cookie.value.should == ["one", "two", "three"]
- end
+ it "sets self's value" do
+ @cookie.value = ["one"]
+ @cookie.value.should == ["one"]
- it "automatically converts the passed Object to an Array using #Array" do
- @cookie.value = "test"
- @cookie.value.should == ["test"]
+ @cookie.value = ["one", "two", "three"]
+ @cookie.value.should == ["one", "two", "three"]
+ end
- obj = mock("to_a")
- obj.should_receive(:to_a).and_return(["1", "2"])
- @cookie.value = obj
- @cookie.value.should == ["1", "2"]
+ it "automatically converts the passed Object to an Array using #Array" do
+ @cookie.value = "test"
+ @cookie.value.should == ["test"]
- obj = mock("to_ary")
- obj.should_receive(:to_ary).and_return(["1", "2"])
- @cookie.value = obj
- @cookie.value.should == ["1", "2"]
- end
+ obj = mock("to_a")
+ obj.should_receive(:to_a).and_return(["1", "2"])
+ @cookie.value = obj
+ @cookie.value.should == ["1", "2"]
- it "does keep self and the values in sync" do
- @cookie.value = ["one", "two", "three"]
- @cookie[0].should == "one"
- @cookie[1].should == "two"
- @cookie[2].should == "three"
+ obj = mock("to_ary")
+ obj.should_receive(:to_ary).and_return(["1", "2"])
+ @cookie.value = obj
+ @cookie.value.should == ["1", "2"]
+ end
+
+ it "does keep self and the values in sync" do
+ @cookie.value = ["one", "two", "three"]
+ @cookie[0].should == "one"
+ @cookie[1].should == "two"
+ @cookie[2].should == "three"
+ end
end
end
diff --git a/spec/ruby/library/cgi/escapeElement_spec.rb b/spec/ruby/library/cgi/escapeElement_spec.rb
index 18f804c7da..72c38d6028 100644
--- a/spec/ruby/library/cgi/escapeElement_spec.rb
+++ b/spec/ruby/library/cgi/escapeElement_spec.rb
@@ -1,5 +1,11 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require 'cgi'
+require_relative '../../spec_helper'
+
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+end
+ruby_version_is "4.0" do
+ require 'cgi/escape'
+end
describe "CGI.escapeElement when passed String, elements, ..." do
it "escapes only the tags of the passed elements in the passed String" do
diff --git a/spec/ruby/library/cgi/escapeHTML_spec.rb b/spec/ruby/library/cgi/escapeHTML_spec.rb
index a3267db4a1..6e70e87ed7 100644
--- a/spec/ruby/library/cgi/escapeHTML_spec.rb
+++ b/spec/ruby/library/cgi/escapeHTML_spec.rb
@@ -1,11 +1,19 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require 'cgi'
+require_relative '../../spec_helper'
+begin
+ require 'cgi/escape'
+rescue LoadError
+ require 'cgi'
+end
describe "CGI.escapeHTML" do
it "escapes special HTML characters (&\"<>') in the passed argument" do
CGI.escapeHTML(%[& < > " ']).should == '&amp; &lt; &gt; &quot; &#39;'
end
+ it "escapes invalid encoding" do
+ CGI.escapeHTML(%[<\xA4??>]).should == "&lt;\xA4??&gt;"
+ end
+
it "does not escape any other characters" do
chars = " !\#$%()*+,-./0123456789:;=?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
CGI.escapeHTML(chars).should == chars
diff --git a/spec/ruby/library/cgi/escapeURIComponent_spec.rb b/spec/ruby/library/cgi/escapeURIComponent_spec.rb
new file mode 100644
index 0000000000..98efa2e67e
--- /dev/null
+++ b/spec/ruby/library/cgi/escapeURIComponent_spec.rb
@@ -0,0 +1,78 @@
+require_relative '../../spec_helper'
+begin
+ require 'cgi/escape'
+rescue LoadError
+ require 'cgi'
+end
+
+describe "CGI.escapeURIComponent" do
+ it "percent-encodes characters reserved according to RFC 3986" do
+ # https://www.rfc-editor.org/rfc/rfc3986#section-2.2
+ string = ":/?#[]@!$&'()*+,;="
+ CGI.escapeURIComponent(string).should == "%3A%2F%3F%23%5B%5D%40%21%24%26%27%28%29%2A%2B%2C%3B%3D"
+ end
+
+ it "does not percent-encode unreserved characters according to RFC 3986" do
+ string = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~"
+ CGI.escapeURIComponent(string).should == "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~"
+ end
+
+ it "encodes % character as %25" do
+ CGI.escapeURIComponent("%").should == "%25"
+ end
+
+ # Compare to .escape which uses "+".
+ it "percent-encodes single whitespace" do
+ CGI.escapeURIComponent(" ").should == "%20"
+ end
+
+ it "percent-encodes all non-reserved and non-unreserved ASCII characters" do
+ special_set = ":/?#[]@!$&'()*+,;=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~"
+ all_other = (0x00..0x7F).filter_map { |i| i.chr unless special_set.include?(i.chr) }.join
+ encoded = CGI.escapeURIComponent(all_other)
+ encoded.should.match?(/\A(?:%[0-9A-F]{2}){#{all_other.length}}\z/)
+ end
+
+ it "percent-encodes non-ASCII bytes" do
+ bytes = (0x80..0xFF).map(&:chr).join
+ encoded = CGI.escapeURIComponent(bytes)
+ encoded.should.match?(/\A(?:%[0-9A-F]{2}){#{bytes.length}}\z/)
+ end
+
+ it "processes multi-byte characters as separate bytes, percent-encoding each one" do
+ CGI.escapeURIComponent("β").should == "%CE%B2" # "β" bytes representation is CE B2
+ end
+
+ it "produces a copy of an empty string" do
+ string = "".encode(Encoding::BINARY)
+ encoded = CGI.escapeURIComponent(string)
+ encoded.should == ""
+ encoded.encoding.should == Encoding::BINARY
+ string.should_not.equal?(encoded)
+ end
+
+ it "preserves string's encoding" do
+ string = "whatever".encode("ASCII-8BIT")
+ CGI.escapeURIComponent(string).encoding.should == Encoding::ASCII_8BIT
+ end
+
+ it "processes even strings with invalid encoding, percent-encoding octets as-is" do
+ string = "\xC0<<".dup.force_encoding("UTF-8")
+ CGI.escapeURIComponent(string).should == "%C0%3C%3C"
+ end
+
+ it "raises a TypeError with nil" do
+ -> {
+ CGI.escapeURIComponent(nil)
+ }.should.raise(TypeError, "no implicit conversion of nil into String")
+ end
+
+ it "uses implicit type conversion to String" do
+ object = Object.new
+ def object.to_str
+ "a b"
+ end
+
+ CGI.escapeURIComponent(object).should == "a%20b"
+ end
+end
diff --git a/spec/ruby/library/cgi/escape_spec.rb b/spec/ruby/library/cgi/escape_spec.rb
index cf8861a39f..55eb0b66c2 100644
--- a/spec/ruby/library/cgi/escape_spec.rb
+++ b/spec/ruby/library/cgi/escape_spec.rb
@@ -1,5 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require 'cgi'
+require_relative '../../spec_helper'
+begin
+ require 'cgi/escape'
+rescue LoadError
+ require 'cgi'
+end
describe "CGI.escape" do
it "url-encodes the passed argument" do
@@ -7,20 +11,12 @@ describe "CGI.escape" do
expected = "+%21%22%23%24%25%26%27%28%29%2A%2B%2C-.%2F0123456789%3A%3B%3C%3D%3E%3F%40ABCDEFGHIJKLMNOPQRSTUVWXYZ%5B%5C%5D%5E_%60abcdefghijklmnopqrstuvwxyz%7B%7C%7D"
CGI.escape(input).should == expected
- input = "http://ja.wikipedia.org/wiki/\343\203\255\343\203\240\343\202\271\343\202\253\343\203\273\343\203\221\343\203\255\343\203\273\343\202\246\343\203\253\343\203\273\343\203\251\343\203\224\343\203\245\343\202\277"
- expected = 'http%3A%2F%2Fja.wikipedia.org%2Fwiki%2F%E3%83%AD%E3%83%A0%E3%82%B9%E3%82%AB%E3%83%BB%E3%83%91%E3%83%AD%E3%83%BB%E3%82%A6%E3%83%AB%E3%83%BB%E3%83%A9%E3%83%94%E3%83%A5%E3%82%BF'
+ input = "https://ja.wikipedia.org/wiki/\343\203\255\343\203\240\343\202\271\343\202\253\343\203\273\343\203\221\343\203\255\343\203\273\343\202\246\343\203\253\343\203\273\343\203\251\343\203\224\343\203\245\343\202\277"
+ expected = 'https%3A%2F%2Fja.wikipedia.org%2Fwiki%2F%E3%83%AD%E3%83%A0%E3%82%B9%E3%82%AB%E3%83%BB%E3%83%91%E3%83%AD%E3%83%BB%E3%82%A6%E3%83%AB%E3%83%BB%E3%83%A9%E3%83%94%E3%83%A5%E3%82%BF'
CGI.escape(input).should == expected
end
- ruby_version_is ""..."2.5" do
- it "escapes tilde" do
- CGI.escape("~").should == "%7E"
- end
- end
-
- ruby_version_is "2.5" do
- it "does not escape tilde" do
- CGI.escape("~").should == "~"
- end
+ it "does not escape tilde" do
+ CGI.escape("~").should == "~"
end
end
diff --git a/spec/ruby/library/cgi/htmlextension/a_spec.rb b/spec/ruby/library/cgi/htmlextension/a_spec.rb
index a4c0ee684c..78d3dec8fa 100644
--- a/spec/ruby/library/cgi/htmlextension/a_spec.rb
+++ b/spec/ruby/library/cgi/htmlextension/a_spec.rb
@@ -1,49 +1,52 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
-require File.expand_path('../fixtures/common', __FILE__)
+require_relative '../../../spec_helper'
-describe "CGI::HtmlExtension#a" do
- before :each do
- @html = CGISpecs.cgi_new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+ require_relative 'fixtures/common'
- describe "when passed a String" do
- it "returns an 'a'-element, using the passed String as the 'href'-attribute" do
- output = @html.a("http://www.example.com")
- output.should equal_element("A", "HREF" => "http://www.example.com")
+ describe "CGI::HtmlExtension#a" do
+ before :each do
+ @html = CGISpecs.cgi_new
end
- it "includes the passed block's return value when passed a block" do
- output = @html.a("http://www.example.com") { "Example" }
- output.should equal_element("A", { "HREF" => "http://www.example.com" }, "Example")
- end
- end
+ describe "when passed a String" do
+ it "returns an 'a'-element, using the passed String as the 'href'-attribute" do
+ output = @html.a("http://www.example.com")
+ output.should equal_element("A", "HREF" => "http://www.example.com")
+ end
- describe "when passed a Hash" do
- it "returns an 'a'-element, using the passed Hash for attributes" do
- attributes = {"HREF" => "http://www.example.com", "TARGET" => "_top"}
- @html.a(attributes).should equal_element("A", attributes)
+ it "includes the passed block's return value when passed a block" do
+ output = @html.a("http://www.example.com") { "Example" }
+ output.should equal_element("A", { "HREF" => "http://www.example.com" }, "Example")
+ end
end
- it "includes the passed block's return value when passed a block" do
- attributes = {"HREF" => "http://www.example.com", "TARGET" => "_top"}
- @html.a(attributes) { "Example" }.should equal_element("A", attributes, "Example")
- end
- end
+ describe "when passed a Hash" do
+ it "returns an 'a'-element, using the passed Hash for attributes" do
+ attributes = {"HREF" => "http://www.example.com", "TARGET" => "_top"}
+ @html.a(attributes).should equal_element("A", attributes)
+ end
- describe "when each HTML generation" do
- it "returns the doctype declaration for HTML3" do
- CGISpecs.cgi_new("html3").a.should == %(<A HREF=""></A>)
- CGISpecs.cgi_new("html3").a { "link text" }.should == %(<A HREF="">link text</A>)
+ it "includes the passed block's return value when passed a block" do
+ attributes = {"HREF" => "http://www.example.com", "TARGET" => "_top"}
+ @html.a(attributes) { "Example" }.should equal_element("A", attributes, "Example")
+ end
end
- it "returns the doctype declaration for HTML4" do
- CGISpecs.cgi_new("html4").a.should == %(<A HREF=""></A>)
- CGISpecs.cgi_new("html4").a { "link text" }.should == %(<A HREF="">link text</A>)
- end
- it "returns the doctype declaration for the Transitional version of HTML4" do
- CGISpecs.cgi_new("html4Tr").a.should == %(<A HREF=""></A>)
- CGISpecs.cgi_new("html4Tr").a { "link text" }.should == %(<A HREF="">link text</A>)
+ describe "when each HTML generation" do
+ it "returns the doctype declaration for HTML3" do
+ CGISpecs.cgi_new("html3").a.should == %(<A HREF=""></A>)
+ CGISpecs.cgi_new("html3").a { "link text" }.should == %(<A HREF="">link text</A>)
+ end
+
+ it "returns the doctype declaration for HTML4" do
+ CGISpecs.cgi_new("html4").a.should == %(<A HREF=""></A>)
+ CGISpecs.cgi_new("html4").a { "link text" }.should == %(<A HREF="">link text</A>)
+ end
+ it "returns the doctype declaration for the Transitional version of HTML4" do
+ CGISpecs.cgi_new("html4Tr").a.should == %(<A HREF=""></A>)
+ CGISpecs.cgi_new("html4Tr").a { "link text" }.should == %(<A HREF="">link text</A>)
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/htmlextension/base_spec.rb b/spec/ruby/library/cgi/htmlextension/base_spec.rb
index 36a8cc55c8..1eedfdea54 100644
--- a/spec/ruby/library/cgi/htmlextension/base_spec.rb
+++ b/spec/ruby/library/cgi/htmlextension/base_spec.rb
@@ -1,33 +1,36 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
-require File.expand_path('../fixtures/common', __FILE__)
+require_relative '../../../spec_helper'
-describe "CGI::HtmlExtension#base" do
- before :each do
- @html = CGISpecs.cgi_new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+ require_relative 'fixtures/common'
- describe "when bassed a String" do
- it "returns a 'base'-element, using the passed String as the 'href'-attribute" do
- output = @html.base("http://www.example.com")
- output.should equal_element("BASE", {"HREF" => "http://www.example.com"}, nil, not_closed: true)
+ describe "CGI::HtmlExtension#base" do
+ before :each do
+ @html = CGISpecs.cgi_new
end
- it "ignores a passed block" do
- output = @html.base("http://www.example.com") { "Example" }
- output.should equal_element("BASE", {"HREF" => "http://www.example.com"}, nil, not_closed: true)
- end
- end
+ describe "when bassed a String" do
+ it "returns a 'base'-element, using the passed String as the 'href'-attribute" do
+ output = @html.base("http://www.example.com")
+ output.should equal_element("BASE", {"HREF" => "http://www.example.com"}, nil, not_closed: true)
+ end
- describe "when passed a Hash" do
- it "returns a 'base'-element, using the passed Hash for attributes" do
- output = @html.base("HREF" => "http://www.example.com", "ID" => "test")
- output.should equal_element("BASE", {"HREF" => "http://www.example.com", "ID" => "test"}, nil, not_closed: true)
+ it "ignores a passed block" do
+ output = @html.base("http://www.example.com") { "Example" }
+ output.should equal_element("BASE", {"HREF" => "http://www.example.com"}, nil, not_closed: true)
+ end
end
- it "ignores a passed block" do
- output = @html.base("HREF" => "http://www.example.com", "ID" => "test") { "Example" }
- output.should equal_element("BASE", {"HREF" => "http://www.example.com", "ID" => "test"}, nil, not_closed: true)
+ describe "when passed a Hash" do
+ it "returns a 'base'-element, using the passed Hash for attributes" do
+ output = @html.base("HREF" => "http://www.example.com", "ID" => "test")
+ output.should equal_element("BASE", {"HREF" => "http://www.example.com", "ID" => "test"}, nil, not_closed: true)
+ end
+
+ it "ignores a passed block" do
+ output = @html.base("HREF" => "http://www.example.com", "ID" => "test") { "Example" }
+ output.should equal_element("BASE", {"HREF" => "http://www.example.com", "ID" => "test"}, nil, not_closed: true)
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/htmlextension/blockquote_spec.rb b/spec/ruby/library/cgi/htmlextension/blockquote_spec.rb
index f9848375e8..883e36f78b 100644
--- a/spec/ruby/library/cgi/htmlextension/blockquote_spec.rb
+++ b/spec/ruby/library/cgi/htmlextension/blockquote_spec.rb
@@ -1,33 +1,36 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
-require File.expand_path('../fixtures/common', __FILE__)
+require_relative '../../../spec_helper'
-describe "CGI::HtmlExtension#blockquote" do
- before :each do
- @html = CGISpecs.cgi_new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+ require_relative 'fixtures/common'
- describe "when passed a String" do
- it "returns a 'blockquote'-element, using the passed String for the 'cite'-attribute" do
- output = @html.blockquote("http://www.example.com/quotes/foo.html")
- output.should equal_element("BLOCKQUOTE", "CITE" => "http://www.example.com/quotes/foo.html")
+ describe "CGI::HtmlExtension#blockquote" do
+ before :each do
+ @html = CGISpecs.cgi_new
end
- it "includes the passed block's return value when passed a block" do
- output = @html.blockquote("http://www.example.com/quotes/foo.html") { "Foo!" }
- output.should equal_element("BLOCKQUOTE", { "CITE" => "http://www.example.com/quotes/foo.html" }, "Foo!")
- end
- end
+ describe "when passed a String" do
+ it "returns a 'blockquote'-element, using the passed String for the 'cite'-attribute" do
+ output = @html.blockquote("http://www.example.com/quotes/foo.html")
+ output.should equal_element("BLOCKQUOTE", "CITE" => "http://www.example.com/quotes/foo.html")
+ end
- describe "when passed a Hash" do
- it "returns a 'blockquote'-element, using the passed Hash for attributes" do
- output = @html.blockquote("CITE" => "http://www.example.com/quotes/foo.html", "ID" => "test")
- output.should equal_element("BLOCKQUOTE", "CITE" => "http://www.example.com/quotes/foo.html", "ID" => "test")
+ it "includes the passed block's return value when passed a block" do
+ output = @html.blockquote("http://www.example.com/quotes/foo.html") { "Foo!" }
+ output.should equal_element("BLOCKQUOTE", { "CITE" => "http://www.example.com/quotes/foo.html" }, "Foo!")
+ end
end
- it "includes the passed block's return value when passed a block" do
- output = @html.blockquote("CITE" => "http://www.example.com/quotes/foo.html", "ID" => "test") { "Foo!" }
- output.should equal_element("BLOCKQUOTE", {"CITE" => "http://www.example.com/quotes/foo.html", "ID" => "test"}, "Foo!")
+ describe "when passed a Hash" do
+ it "returns a 'blockquote'-element, using the passed Hash for attributes" do
+ output = @html.blockquote("CITE" => "http://www.example.com/quotes/foo.html", "ID" => "test")
+ output.should equal_element("BLOCKQUOTE", "CITE" => "http://www.example.com/quotes/foo.html", "ID" => "test")
+ end
+
+ it "includes the passed block's return value when passed a block" do
+ output = @html.blockquote("CITE" => "http://www.example.com/quotes/foo.html", "ID" => "test") { "Foo!" }
+ output.should equal_element("BLOCKQUOTE", {"CITE" => "http://www.example.com/quotes/foo.html", "ID" => "test"}, "Foo!")
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/htmlextension/br_spec.rb b/spec/ruby/library/cgi/htmlextension/br_spec.rb
index 875d335fe5..23c2cb4a48 100644
--- a/spec/ruby/library/cgi/htmlextension/br_spec.rb
+++ b/spec/ruby/library/cgi/htmlextension/br_spec.rb
@@ -1,22 +1,25 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
-require File.expand_path('../fixtures/common', __FILE__)
+require_relative '../../../spec_helper'
-describe "CGI::HtmlExtension#br" do
- before :each do
- @html = CGISpecs.cgi_new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+ require_relative 'fixtures/common'
- describe "when each HTML generation" do
- it "returns the doctype declaration for HTML3" do
- CGISpecs.cgi_new("html3").br.should == "<BR>"
+ describe "CGI::HtmlExtension#br" do
+ before :each do
+ @html = CGISpecs.cgi_new
end
- it "returns the doctype declaration for HTML4" do
- CGISpecs.cgi_new("html4").br.should == "<BR>"
- end
- it "returns the doctype declaration for the Transitional version of HTML4" do
- CGISpecs.cgi_new("html4Tr").br.should == "<BR>"
+ describe "when each HTML generation" do
+ it "returns the doctype declaration for HTML3" do
+ CGISpecs.cgi_new("html3").br.should == "<BR>"
+ end
+
+ it "returns the doctype declaration for HTML4" do
+ CGISpecs.cgi_new("html4").br.should == "<BR>"
+ end
+ it "returns the doctype declaration for the Transitional version of HTML4" do
+ CGISpecs.cgi_new("html4Tr").br.should == "<BR>"
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/htmlextension/caption_spec.rb b/spec/ruby/library/cgi/htmlextension/caption_spec.rb
index a1b5f4d964..3d3e21ecaa 100644
--- a/spec/ruby/library/cgi/htmlextension/caption_spec.rb
+++ b/spec/ruby/library/cgi/htmlextension/caption_spec.rb
@@ -1,33 +1,36 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
-require File.expand_path('../fixtures/common', __FILE__)
+require_relative '../../../spec_helper'
-describe "CGI::HtmlExtension#caption" do
- before :each do
- @html = CGISpecs.cgi_new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+ require_relative 'fixtures/common'
- describe "when passed a String" do
- it "returns a 'caption'-element, using the passed String for the 'align'-attribute" do
- output = @html.caption("left")
- output.should equal_element("CAPTION", "ALIGN" => "left")
+ describe "CGI::HtmlExtension#caption" do
+ before :each do
+ @html = CGISpecs.cgi_new
end
- it "includes the passed block's return value when passed a block" do
- output = @html.caption("left") { "Capital Cities" }
- output.should equal_element("CAPTION", {"ALIGN" => "left"}, "Capital Cities")
- end
- end
+ describe "when passed a String" do
+ it "returns a 'caption'-element, using the passed String for the 'align'-attribute" do
+ output = @html.caption("left")
+ output.should equal_element("CAPTION", "ALIGN" => "left")
+ end
- describe "when passed a Hash" do
- it "returns a 'caption'-element, using the passed Hash for attributes" do
- output = @html.caption("ALIGN" => "left", "ID" => "test")
- output.should equal_element("CAPTION", "ALIGN" => "left", "ID" => "test")
+ it "includes the passed block's return value when passed a block" do
+ output = @html.caption("left") { "Capital Cities" }
+ output.should equal_element("CAPTION", {"ALIGN" => "left"}, "Capital Cities")
+ end
end
- it "includes the passed block's return value when passed a block" do
- output = @html.caption("ALIGN" => "left", "ID" => "test") { "Capital Cities" }
- output.should equal_element("CAPTION", {"ALIGN" => "left", "ID" => "test"}, "Capital Cities")
+ describe "when passed a Hash" do
+ it "returns a 'caption'-element, using the passed Hash for attributes" do
+ output = @html.caption("ALIGN" => "left", "ID" => "test")
+ output.should equal_element("CAPTION", "ALIGN" => "left", "ID" => "test")
+ end
+
+ it "includes the passed block's return value when passed a block" do
+ output = @html.caption("ALIGN" => "left", "ID" => "test") { "Capital Cities" }
+ output.should equal_element("CAPTION", {"ALIGN" => "left", "ID" => "test"}, "Capital Cities")
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/htmlextension/checkbox_group_spec.rb b/spec/ruby/library/cgi/htmlextension/checkbox_group_spec.rb
index f739d92a53..07163c010e 100644
--- a/spec/ruby/library/cgi/htmlextension/checkbox_group_spec.rb
+++ b/spec/ruby/library/cgi/htmlextension/checkbox_group_spec.rb
@@ -1,76 +1,79 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
-require File.expand_path('../fixtures/common', __FILE__)
+require_relative '../../../spec_helper'
-describe "CGI::HtmlExtension#checkbox_group" do
- before :each do
- @html = CGISpecs.cgi_new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+ require_relative 'fixtures/common'
- describe "when passed name, values ..." do
- it "returns a sequence of 'checkbox'-elements with the passed name and the passed values" do
- output = CGISpecs.split(@html.checkbox_group("test", "foo", "bar", "baz"))
- output[0].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "foo"}, "foo", not_closed: true)
- output[1].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "bar"}, "bar", not_closed: true)
- output[2].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "baz"}, "baz", not_closed: true)
+ describe "CGI::HtmlExtension#checkbox_group" do
+ before :each do
+ @html = CGISpecs.cgi_new
end
- it "allows passing a value inside an Array" do
- output = CGISpecs.split(@html.checkbox_group("test", ["foo"], "bar", ["baz"]))
- output[0].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "foo"}, "foo", not_closed: true)
- output[1].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "bar"}, "bar", not_closed: true)
- output[2].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "baz"}, "baz", not_closed: true)
- end
+ describe "when passed name, values ..." do
+ it "returns a sequence of 'checkbox'-elements with the passed name and the passed values" do
+ output = CGISpecs.split(@html.checkbox_group("test", "foo", "bar", "baz"))
+ output[0].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "foo"}, "foo", not_closed: true)
+ output[1].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "bar"}, "bar", not_closed: true)
+ output[2].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "baz"}, "baz", not_closed: true)
+ end
- it "allows passing a value as an Array containing the value and the checked state or a label" do
- output = CGISpecs.split(@html.checkbox_group("test", ["foo"], ["bar", true], ["baz", "label for baz"]))
- output[0].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "foo"}, "foo", not_closed: true)
- output[1].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "test", "TYPE" => "checkbox", "VALUE" => "bar"}, "bar", not_closed: true)
- output[2].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "baz"}, "label for baz", not_closed: true)
- end
+ it "allows passing a value inside an Array" do
+ output = CGISpecs.split(@html.checkbox_group("test", ["foo"], "bar", ["baz"]))
+ output[0].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "foo"}, "foo", not_closed: true)
+ output[1].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "bar"}, "bar", not_closed: true)
+ output[2].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "baz"}, "baz", not_closed: true)
+ end
- it "allows passing a value as an Array containing the value, a label and the checked state" do
- output = CGISpecs.split(@html.checkbox_group("test", ["foo", "label for foo", true], ["bar", "label for bar", false], ["baz", "label for baz", true]))
- output[0].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "test", "TYPE" => "checkbox", "VALUE" => "foo"}, "label for foo", not_closed: true)
- output[1].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "bar"}, "label for bar", not_closed: true)
- output[2].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "test", "TYPE" => "checkbox", "VALUE" => "baz"}, "label for baz", not_closed: true)
- end
+ it "allows passing a value as an Array containing the value and the checked state or a label" do
+ output = CGISpecs.split(@html.checkbox_group("test", ["foo"], ["bar", true], ["baz", "label for baz"]))
+ output[0].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "foo"}, "foo", not_closed: true)
+ output[1].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "test", "TYPE" => "checkbox", "VALUE" => "bar"}, "bar", not_closed: true)
+ output[2].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "baz"}, "label for baz", not_closed: true)
+ end
- it "returns an empty String when passed no values" do
- @html.checkbox_group("test").should == ""
- end
+ it "allows passing a value as an Array containing the value, a label and the checked state" do
+ output = CGISpecs.split(@html.checkbox_group("test", ["foo", "label for foo", true], ["bar", "label for bar", false], ["baz", "label for baz", true]))
+ output[0].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "test", "TYPE" => "checkbox", "VALUE" => "foo"}, "label for foo", not_closed: true)
+ output[1].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "bar"}, "label for bar", not_closed: true)
+ output[2].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "test", "TYPE" => "checkbox", "VALUE" => "baz"}, "label for baz", not_closed: true)
+ end
+
+ it "returns an empty String when passed no values" do
+ @html.checkbox_group("test").should == ""
+ end
- it "ignores a passed block" do
- output = CGISpecs.split(@html.checkbox_group("test", "foo", "bar", "baz") { "test" })
- output[0].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "foo"}, "foo", not_closed: true)
- output[1].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "bar"}, "bar", not_closed: true)
- output[2].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "baz"}, "baz", not_closed: true)
+ it "ignores a passed block" do
+ output = CGISpecs.split(@html.checkbox_group("test", "foo", "bar", "baz") { "test" })
+ output[0].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "foo"}, "foo", not_closed: true)
+ output[1].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "bar"}, "bar", not_closed: true)
+ output[2].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "baz"}, "baz", not_closed: true)
+ end
end
- end
- describe "when passed Hash" do
- it "uses the passed Hash to generate the checkbox sequence" do
- output = CGISpecs.split(@html.checkbox_group("NAME" => "name", "VALUES" => ["foo", "bar", "baz"]))
- output[0].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "foo"}, "foo", not_closed: true)
- output[1].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "bar"}, "bar", not_closed: true)
- output[2].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "baz"}, "baz", not_closed: true)
+ describe "when passed Hash" do
+ it "uses the passed Hash to generate the checkbox sequence" do
+ output = CGISpecs.split(@html.checkbox_group("NAME" => "name", "VALUES" => ["foo", "bar", "baz"]))
+ output[0].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "foo"}, "foo", not_closed: true)
+ output[1].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "bar"}, "bar", not_closed: true)
+ output[2].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "baz"}, "baz", not_closed: true)
- output = CGISpecs.split(@html.checkbox_group("NAME" => "name", "VALUES" => [["foo"], ["bar", true], "baz"]))
- output[0].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "foo"}, "foo", not_closed: true)
- output[1].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "name", "TYPE" => "checkbox", "VALUE" => "bar"}, "bar", not_closed: true)
- output[2].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "baz"}, "baz", not_closed: true)
+ output = CGISpecs.split(@html.checkbox_group("NAME" => "name", "VALUES" => [["foo"], ["bar", true], "baz"]))
+ output[0].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "foo"}, "foo", not_closed: true)
+ output[1].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "name", "TYPE" => "checkbox", "VALUE" => "bar"}, "bar", not_closed: true)
+ output[2].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "baz"}, "baz", not_closed: true)
- output = CGISpecs.split(@html.checkbox_group("NAME" => "name", "VALUES" => [["1", "Foo"], ["2", "Bar", true], "Baz"]))
- output[0].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "1"}, "Foo", not_closed: true)
- output[1].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "name", "TYPE" => "checkbox", "VALUE" => "2"}, "Bar", not_closed: true)
- output[2].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "Baz"}, "Baz", not_closed: true)
- end
+ output = CGISpecs.split(@html.checkbox_group("NAME" => "name", "VALUES" => [["1", "Foo"], ["2", "Bar", true], "Baz"]))
+ output[0].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "1"}, "Foo", not_closed: true)
+ output[1].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "name", "TYPE" => "checkbox", "VALUE" => "2"}, "Bar", not_closed: true)
+ output[2].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "Baz"}, "Baz", not_closed: true)
+ end
- it "ignores a passed block" do
- output = CGISpecs.split(@html.checkbox_group("NAME" => "name", "VALUES" => ["foo", "bar", "baz"]) { "test" })
- output[0].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "foo"}, "foo", not_closed: true)
- output[1].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "bar"}, "bar", not_closed: true)
- output[2].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "baz"}, "baz", not_closed: true)
+ it "ignores a passed block" do
+ output = CGISpecs.split(@html.checkbox_group("NAME" => "name", "VALUES" => ["foo", "bar", "baz"]) { "test" })
+ output[0].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "foo"}, "foo", not_closed: true)
+ output[1].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "bar"}, "bar", not_closed: true)
+ output[2].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "checkbox", "VALUE" => "baz"}, "baz", not_closed: true)
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/htmlextension/checkbox_spec.rb b/spec/ruby/library/cgi/htmlextension/checkbox_spec.rb
index 3abb3b4a31..ad87b78061 100644
--- a/spec/ruby/library/cgi/htmlextension/checkbox_spec.rb
+++ b/spec/ruby/library/cgi/htmlextension/checkbox_spec.rb
@@ -1,77 +1,80 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
-require File.expand_path('../fixtures/common', __FILE__)
+require_relative '../../../spec_helper'
-describe "CGI::HtmlExtension#checkbox" do
- before :each do
- @html = CGISpecs.cgi_new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+ require_relative 'fixtures/common'
- describe "when passed no arguments" do
- it "returns a checkbox-'input'-element without a name" do
- output = @html.checkbox
- output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "checkbox"}, "", not_closed: true)
+ describe "CGI::HtmlExtension#checkbox" do
+ before :each do
+ @html = CGISpecs.cgi_new
end
- it "ignores a passed block" do
- output = @html.checkbox { "test" }
- output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "checkbox"}, "", not_closed: true)
- end
- end
+ describe "when passed no arguments" do
+ it "returns a checkbox-'input'-element without a name" do
+ output = @html.checkbox
+ output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "checkbox"}, "", not_closed: true)
+ end
- describe "when passed name" do
- it "returns a checkbox-'input'-element with the passed name" do
- output = @html.checkbox("test")
- output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox"}, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.checkbox { "test" }
+ output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "checkbox"}, "", not_closed: true)
+ end
end
- it "ignores a passed block" do
- output = @html.checkbox("test") { "test" }
- output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox"}, "", not_closed: true)
- end
- end
+ describe "when passed name" do
+ it "returns a checkbox-'input'-element with the passed name" do
+ output = @html.checkbox("test")
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox"}, "", not_closed: true)
+ end
- describe "CGI::HtmlExtension#checkbox when passed name, value" do
- it "returns a checkbox-'input'-element with the passed name and value" do
- output = @html.checkbox("test", "test-value")
- output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "test-value"}, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.checkbox("test") { "test" }
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox"}, "", not_closed: true)
+ end
end
- it "ignores a passed block" do
- output = @html.checkbox("test", "test-value") { "test" }
- output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "test-value"}, "", not_closed: true)
+ describe "CGI::HtmlExtension#checkbox when passed name, value" do
+ it "returns a checkbox-'input'-element with the passed name and value" do
+ output = @html.checkbox("test", "test-value")
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "test-value"}, "", not_closed: true)
+ end
+
+ it "ignores a passed block" do
+ output = @html.checkbox("test", "test-value") { "test" }
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "test-value"}, "", not_closed: true)
+ end
end
- end
- describe "when passed name, value, checked" do
- it "returns a checked checkbox-'input'-element with the passed name and value when checked is true" do
- output = @html.checkbox("test", "test-value", true)
- output.should equal_element("INPUT", {"CHECKED" => true, "NAME" => "test", "TYPE" => "checkbox", "VALUE" => "test-value"}, "", not_closed: true)
+ describe "when passed name, value, checked" do
+ it "returns a checked checkbox-'input'-element with the passed name and value when checked is true" do
+ output = @html.checkbox("test", "test-value", true)
+ output.should equal_element("INPUT", {"CHECKED" => true, "NAME" => "test", "TYPE" => "checkbox", "VALUE" => "test-value"}, "", not_closed: true)
- output = @html.checkbox("test", "test-value", false)
- output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "test-value"}, "", not_closed: true)
+ output = @html.checkbox("test", "test-value", false)
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "test-value"}, "", not_closed: true)
- output = @html.checkbox("test", "test-value", nil)
- output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "test-value"}, "", not_closed: true)
- end
+ output = @html.checkbox("test", "test-value", nil)
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "test-value"}, "", not_closed: true)
+ end
- it "ignores a passed block" do
- output = @html.checkbox("test", "test-value", nil) { "test" }
- output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "test-value"}, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.checkbox("test", "test-value", nil) { "test" }
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "checkbox", "VALUE" => "test-value"}, "", not_closed: true)
+ end
end
- end
- describe "when passed Hash" do
- it "returns a checkbox-'input'-element using the passed Hash for attributes" do
- attributes = {"NAME" => "test", "VALUE" => "test-value", "CHECKED" => true}
- output = @html.checkbox(attributes)
- output.should equal_element("INPUT", attributes, "", not_closed: true)
- end
+ describe "when passed Hash" do
+ it "returns a checkbox-'input'-element using the passed Hash for attributes" do
+ attributes = {"NAME" => "test", "VALUE" => "test-value", "CHECKED" => true}
+ output = @html.checkbox(attributes)
+ output.should equal_element("INPUT", attributes, "", not_closed: true)
+ end
- it "ignores a passed block" do
- attributes = {"NAME" => "test", "VALUE" => "test-value", "CHECKED" => true}
- output = @html.checkbox(attributes) { "test" }
- output.should equal_element("INPUT", attributes, "", not_closed: true)
+ it "ignores a passed block" do
+ attributes = {"NAME" => "test", "VALUE" => "test-value", "CHECKED" => true}
+ output = @html.checkbox(attributes) { "test" }
+ output.should equal_element("INPUT", attributes, "", not_closed: true)
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/htmlextension/doctype_spec.rb b/spec/ruby/library/cgi/htmlextension/doctype_spec.rb
index 339ef20db9..02af831855 100644
--- a/spec/ruby/library/cgi/htmlextension/doctype_spec.rb
+++ b/spec/ruby/library/cgi/htmlextension/doctype_spec.rb
@@ -1,27 +1,30 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
-require File.expand_path('../fixtures/common', __FILE__)
+require_relative '../../../spec_helper'
-describe "CGI::HtmlExtension#doctype" do
- describe "when each HTML generation" do
- it "returns the doctype declaration for HTML3" do
- expect = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">'
- CGISpecs.cgi_new("html3").doctype.should == expect
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+ require_relative 'fixtures/common'
- it "returns the doctype declaration for HTML4" do
- expect = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">'
- CGISpecs.cgi_new("html4").doctype.should == expect
- end
+ describe "CGI::HtmlExtension#doctype" do
+ describe "when each HTML generation" do
+ it "returns the doctype declaration for HTML3" do
+ expect = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">'
+ CGISpecs.cgi_new("html3").doctype.should == expect
+ end
- it "returns the doctype declaration for the Frameset version of HTML4" do
- expect = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'
- CGISpecs.cgi_new("html4Fr").doctype.should == expect
- end
+ it "returns the doctype declaration for HTML4" do
+ expect = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">'
+ CGISpecs.cgi_new("html4").doctype.should == expect
+ end
+
+ it "returns the doctype declaration for the Frameset version of HTML4" do
+ expect = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'
+ CGISpecs.cgi_new("html4Fr").doctype.should == expect
+ end
- it "returns the doctype declaration for the Transitional version of HTML4" do
- expect = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">'
- CGISpecs.cgi_new("html4Tr").doctype.should == expect
+ it "returns the doctype declaration for the Transitional version of HTML4" do
+ expect = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">'
+ CGISpecs.cgi_new("html4Tr").doctype.should == expect
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/htmlextension/file_field_spec.rb b/spec/ruby/library/cgi/htmlextension/file_field_spec.rb
index 57d91b5fd9..eff077b9a2 100644
--- a/spec/ruby/library/cgi/htmlextension/file_field_spec.rb
+++ b/spec/ruby/library/cgi/htmlextension/file_field_spec.rb
@@ -1,72 +1,75 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
-require File.expand_path('../fixtures/common', __FILE__)
+require_relative '../../../spec_helper'
-describe "CGI::HtmlExtension#file_field" do
- before :each do
- @html = CGISpecs.cgi_new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+ require_relative 'fixtures/common'
- describe "when passed no arguments" do
- it "returns a file-'input'-element without a name and a size of 20" do
- output = @html.file_field
- output.should equal_element("INPUT", {"SIZE" => 20, "NAME" => "", "TYPE" => "file"}, "", not_closed: true)
+ describe "CGI::HtmlExtension#file_field" do
+ before :each do
+ @html = CGISpecs.cgi_new
end
- it "ignores a passed block" do
- output = @html.file_field { "test" }
- output.should equal_element("INPUT", {"SIZE" => 20, "NAME" => "", "TYPE" => "file"}, "", not_closed: true)
- end
- end
+ describe "when passed no arguments" do
+ it "returns a file-'input'-element without a name and a size of 20" do
+ output = @html.file_field
+ output.should equal_element("INPUT", {"SIZE" => 20, "NAME" => "", "TYPE" => "file"}, "", not_closed: true)
+ end
- describe "when passed name" do
- it "returns a checkbox-'input'-element with the passed name" do
- output = @html.file_field("Example")
- output.should equal_element("INPUT", {"SIZE" => 20, "NAME" => "Example", "TYPE" => "file"}, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.file_field { "test" }
+ output.should equal_element("INPUT", {"SIZE" => 20, "NAME" => "", "TYPE" => "file"}, "", not_closed: true)
+ end
end
- it "ignores a passed block" do
- output = @html.file_field("Example") { "test" }
- output.should equal_element("INPUT", {"SIZE" => 20, "NAME" => "Example", "TYPE" => "file"}, "", not_closed: true)
- end
- end
+ describe "when passed name" do
+ it "returns a checkbox-'input'-element with the passed name" do
+ output = @html.file_field("Example")
+ output.should equal_element("INPUT", {"SIZE" => 20, "NAME" => "Example", "TYPE" => "file"}, "", not_closed: true)
+ end
- describe "when passed name, size" do
- it "returns a checkbox-'input'-element with the passed name and size" do
- output = @html.file_field("Example", 40)
- output.should equal_element("INPUT", {"SIZE" => 40, "NAME" => "Example", "TYPE" => "file"}, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.file_field("Example") { "test" }
+ output.should equal_element("INPUT", {"SIZE" => 20, "NAME" => "Example", "TYPE" => "file"}, "", not_closed: true)
+ end
end
- it "ignores a passed block" do
- output = @html.file_field("Example", 40) { "test" }
- output.should equal_element("INPUT", {"SIZE" => 40, "NAME" => "Example", "TYPE" => "file"}, "", not_closed: true)
- end
- end
+ describe "when passed name, size" do
+ it "returns a checkbox-'input'-element with the passed name and size" do
+ output = @html.file_field("Example", 40)
+ output.should equal_element("INPUT", {"SIZE" => 40, "NAME" => "Example", "TYPE" => "file"}, "", not_closed: true)
+ end
- describe "when passed name, size, maxlength" do
- it "returns a checkbox-'input'-element with the passed name, size and maxlength" do
- output = @html.file_field("Example", 40, 100)
- output.should equal_element("INPUT", {"SIZE" => 40, "NAME" => "Example", "TYPE" => "file", "MAXLENGTH" => 100}, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.file_field("Example", 40) { "test" }
+ output.should equal_element("INPUT", {"SIZE" => 40, "NAME" => "Example", "TYPE" => "file"}, "", not_closed: true)
+ end
end
- it "ignores a passed block" do
- output = @html.file_field("Example", 40, 100) { "test" }
- output.should equal_element("INPUT", {"SIZE" => 40, "NAME" => "Example", "TYPE" => "file", "MAXLENGTH" => 100}, "", not_closed: true)
+ describe "when passed name, size, maxlength" do
+ it "returns a checkbox-'input'-element with the passed name, size and maxlength" do
+ output = @html.file_field("Example", 40, 100)
+ output.should equal_element("INPUT", {"SIZE" => 40, "NAME" => "Example", "TYPE" => "file", "MAXLENGTH" => 100}, "", not_closed: true)
+ end
+
+ it "ignores a passed block" do
+ output = @html.file_field("Example", 40, 100) { "test" }
+ output.should equal_element("INPUT", {"SIZE" => 40, "NAME" => "Example", "TYPE" => "file", "MAXLENGTH" => 100}, "", not_closed: true)
+ end
end
- end
- describe "when passed a Hash" do
- it "returns a file-'input'-element using the passed Hash for attributes" do
- output = @html.file_field("NAME" => "test", "SIZE" => 40)
- output.should equal_element("INPUT", {"NAME" => "test", "SIZE" => 40}, "", not_closed: true)
+ describe "when passed a Hash" do
+ it "returns a file-'input'-element using the passed Hash for attributes" do
+ output = @html.file_field("NAME" => "test", "SIZE" => 40)
+ output.should equal_element("INPUT", {"NAME" => "test", "SIZE" => 40}, "", not_closed: true)
- output = @html.file_field("NAME" => "test", "MAXLENGTH" => 100)
- output.should equal_element("INPUT", {"NAME" => "test", "MAXLENGTH" => 100}, "", not_closed: true)
- end
+ output = @html.file_field("NAME" => "test", "MAXLENGTH" => 100)
+ output.should equal_element("INPUT", {"NAME" => "test", "MAXLENGTH" => 100}, "", not_closed: true)
+ end
- it "ignores a passed block" do
- output = @html.file_field("NAME" => "test", "SIZE" => 40) { "test" }
- output.should equal_element("INPUT", {"NAME" => "test", "SIZE" => 40}, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.file_field("NAME" => "test", "SIZE" => 40) { "test" }
+ output.should equal_element("INPUT", {"NAME" => "test", "SIZE" => 40}, "", not_closed: true)
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/htmlextension/form_spec.rb b/spec/ruby/library/cgi/htmlextension/form_spec.rb
index 0389910cd6..55ac63152b 100644
--- a/spec/ruby/library/cgi/htmlextension/form_spec.rb
+++ b/spec/ruby/library/cgi/htmlextension/form_spec.rb
@@ -1,58 +1,61 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
-require File.expand_path('../fixtures/common', __FILE__)
-
-describe "CGI::HtmlExtension#form" do
- before :each do
- @html = CGISpecs.cgi_new
- @html.stub!(:script_name).and_return("/path/to/some/script")
- end
+require_relative '../../../spec_helper'
- describe "when passed no arguments" do
- it "returns a 'form'-element" do
- output = @html.form
- output.should equal_element("FORM", {"ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "post", "ACTION" => "/path/to/some/script"}, "")
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+ require_relative 'fixtures/common'
- it "includes the return value of the passed block when passed a block" do
- output = @html.form { "test" }
- output.should equal_element("FORM", {"ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "post", "ACTION" => "/path/to/some/script"}, "test")
+ describe "CGI::HtmlExtension#form" do
+ before :each do
+ @html = CGISpecs.cgi_new
+ @html.stub!(:script_name).and_return("/path/to/some/script")
end
- end
- describe "when passed method" do
- it "returns a 'form'-element with the passed method" do
- output = @html.form("get")
- output.should equal_element("FORM", {"ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "get", "ACTION" => "/path/to/some/script"}, "")
- end
+ describe "when passed no arguments" do
+ it "returns a 'form'-element" do
+ output = @html.form
+ output.should equal_element("FORM", {"ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "post", "ACTION" => "/path/to/some/script"}, "")
+ end
- it "includes the return value of the passed block when passed a block" do
- output = @html.form("get") { "test" }
- output.should equal_element("FORM", {"ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "get", "ACTION" => "/path/to/some/script"}, "test")
+ it "includes the return value of the passed block when passed a block" do
+ output = @html.form { "test" }
+ output.should equal_element("FORM", {"ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "post", "ACTION" => "/path/to/some/script"}, "test")
+ end
end
- end
- describe "when passed method, action" do
- it "returns a 'form'-element with the passed method and the passed action" do
- output = @html.form("get", "/some/other/script")
- output.should equal_element("FORM", {"ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "get", "ACTION" => "/some/other/script"}, "")
- end
+ describe "when passed method" do
+ it "returns a 'form'-element with the passed method" do
+ output = @html.form("get")
+ output.should equal_element("FORM", {"ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "get", "ACTION" => "/path/to/some/script"}, "")
+ end
- it "includes the return value of the passed block when passed a block" do
- output = @html.form("get", "/some/other/script") { "test" }
- output.should equal_element("FORM", {"ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "get", "ACTION" => "/some/other/script"}, "test")
+ it "includes the return value of the passed block when passed a block" do
+ output = @html.form("get") { "test" }
+ output.should equal_element("FORM", {"ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "get", "ACTION" => "/path/to/some/script"}, "test")
+ end
end
- end
- describe "when passed method, action, enctype" do
- it "returns a 'form'-element with the passed method, action and enctype" do
- output = @html.form("get", "/some/other/script", "multipart/form-data")
- output.should equal_element("FORM", {"ENCTYPE" => "multipart/form-data", "METHOD" => "get", "ACTION" => "/some/other/script"}, "")
+ describe "when passed method, action" do
+ it "returns a 'form'-element with the passed method and the passed action" do
+ output = @html.form("get", "/some/other/script")
+ output.should equal_element("FORM", {"ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "get", "ACTION" => "/some/other/script"}, "")
+ end
+
+ it "includes the return value of the passed block when passed a block" do
+ output = @html.form("get", "/some/other/script") { "test" }
+ output.should equal_element("FORM", {"ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "get", "ACTION" => "/some/other/script"}, "test")
+ end
end
- it "includes the return value of the passed block when passed a block" do
- output = @html.form("get", "/some/other/script", "multipart/form-data") { "test" }
- output.should equal_element("FORM", {"ENCTYPE" => "multipart/form-data", "METHOD" => "get", "ACTION" => "/some/other/script"}, "test")
+ describe "when passed method, action, enctype" do
+ it "returns a 'form'-element with the passed method, action and enctype" do
+ output = @html.form("get", "/some/other/script", "multipart/form-data")
+ output.should equal_element("FORM", {"ENCTYPE" => "multipart/form-data", "METHOD" => "get", "ACTION" => "/some/other/script"}, "")
+ end
+
+ it "includes the return value of the passed block when passed a block" do
+ output = @html.form("get", "/some/other/script", "multipart/form-data") { "test" }
+ output.should equal_element("FORM", {"ENCTYPE" => "multipart/form-data", "METHOD" => "get", "ACTION" => "/some/other/script"}, "test")
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/htmlextension/frame_spec.rb b/spec/ruby/library/cgi/htmlextension/frame_spec.rb
index d433d058e7..fef40849eb 100644
--- a/spec/ruby/library/cgi/htmlextension/frame_spec.rb
+++ b/spec/ruby/library/cgi/htmlextension/frame_spec.rb
@@ -1,14 +1,17 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/common', __FILE__)
-require 'cgi'
+require_relative '../../../spec_helper'
-describe "CGI::HtmlExtension#frame" do
- before :each do
- @html = CGISpecs.cgi_new("html4Fr")
- end
+ruby_version_is ""..."4.0" do
+ require_relative 'fixtures/common'
+ require 'cgi'
+
+ describe "CGI::HtmlExtension#frame" do
+ before :each do
+ @html = CGISpecs.cgi_new("html4Fr")
+ end
- it "initializes the HTML Generation methods for the Frameset version of HTML4" do
- @html.frameset.should == "<FRAMESET></FRAMESET>"
- @html.frameset { "link text" }.should == "<FRAMESET>link text</FRAMESET>"
+ it "initializes the HTML Generation methods for the Frameset version of HTML4" do
+ @html.frameset.should == "<FRAMESET></FRAMESET>"
+ @html.frameset { "link text" }.should == "<FRAMESET>link text</FRAMESET>"
+ end
end
end
diff --git a/spec/ruby/library/cgi/htmlextension/frameset_spec.rb b/spec/ruby/library/cgi/htmlextension/frameset_spec.rb
index 81e92089e4..3ad0a9c4d2 100644
--- a/spec/ruby/library/cgi/htmlextension/frameset_spec.rb
+++ b/spec/ruby/library/cgi/htmlextension/frameset_spec.rb
@@ -1,14 +1,17 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/common', __FILE__)
-require 'cgi'
+require_relative '../../../spec_helper'
-describe "CGI::HtmlExtension#frameset" do
- before :each do
- @html = CGISpecs.cgi_new("html4Fr")
- end
+ruby_version_is ""..."4.0" do
+ require_relative 'fixtures/common'
+ require 'cgi'
+
+ describe "CGI::HtmlExtension#frameset" do
+ before :each do
+ @html = CGISpecs.cgi_new("html4Fr")
+ end
- it "initializes the HTML Generation methods for the Frameset version of HTML4" do
- @html.frameset.should == "<FRAMESET></FRAMESET>"
- @html.frameset { "link text" }.should == "<FRAMESET>link text</FRAMESET>"
+ it "initializes the HTML Generation methods for the Frameset version of HTML4" do
+ @html.frameset.should == "<FRAMESET></FRAMESET>"
+ @html.frameset { "link text" }.should == "<FRAMESET>link text</FRAMESET>"
+ end
end
end
diff --git a/spec/ruby/library/cgi/htmlextension/hidden_spec.rb b/spec/ruby/library/cgi/htmlextension/hidden_spec.rb
index dd06dfc354..b2323775f6 100644
--- a/spec/ruby/library/cgi/htmlextension/hidden_spec.rb
+++ b/spec/ruby/library/cgi/htmlextension/hidden_spec.rb
@@ -1,59 +1,62 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
-require File.expand_path('../fixtures/common', __FILE__)
+require_relative '../../../spec_helper'
-describe "CGI::HtmlExtension#hidden" do
- before :each do
- @html = CGISpecs.cgi_new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+ require_relative 'fixtures/common'
- describe "when passed no arguments" do
- it "returns an hidden-'input'-element without a name" do
- output = @html.hidden
- output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "hidden"}, "", not_closed: true)
+ describe "CGI::HtmlExtension#hidden" do
+ before :each do
+ @html = CGISpecs.cgi_new
end
- it "ignores a passed block" do
- output = @html.hidden { "test" }
- output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "hidden"}, "", not_closed: true)
- end
- end
+ describe "when passed no arguments" do
+ it "returns an hidden-'input'-element without a name" do
+ output = @html.hidden
+ output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "hidden"}, "", not_closed: true)
+ end
- describe "when passed name" do
- it "returns an hidden-'input'-element with the passed name" do
- output = @html.hidden("test")
- output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "hidden"}, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.hidden { "test" }
+ output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "hidden"}, "", not_closed: true)
+ end
end
- it "ignores a passed block" do
- output = @html.hidden("test") { "test" }
- output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "hidden"}, "", not_closed: true)
- end
- end
+ describe "when passed name" do
+ it "returns an hidden-'input'-element with the passed name" do
+ output = @html.hidden("test")
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "hidden"}, "", not_closed: true)
+ end
- describe "when passed name, value" do
- it "returns an hidden-'input'-element with the passed name and value" do
- output = @html.hidden("test", "some value")
- output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "hidden", "VALUE" => "some value"}, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.hidden("test") { "test" }
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "hidden"}, "", not_closed: true)
+ end
end
- it "ignores a passed block" do
- output = @html.hidden("test", "some value") { "test" }
- output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "hidden", "VALUE" => "some value"}, "", not_closed: true)
- end
- end
+ describe "when passed name, value" do
+ it "returns an hidden-'input'-element with the passed name and value" do
+ output = @html.hidden("test", "some value")
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "hidden", "VALUE" => "some value"}, "", not_closed: true)
+ end
- describe "when passed Hash" do
- it "returns a checkbox-'input'-element using the passed Hash for attributes" do
- attributes = { "NAME" => "test", "VALUE" => "some value" }
- output = @html.hidden("test", "some value")
- output.should equal_element("INPUT", attributes, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.hidden("test", "some value") { "test" }
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "hidden", "VALUE" => "some value"}, "", not_closed: true)
+ end
end
- it "ignores a passed block" do
- attributes = { "NAME" => "test", "VALUE" => "some value" }
- output = @html.hidden("test", "some value") { "test" }
- output.should equal_element("INPUT", attributes, "", not_closed: true)
+ describe "when passed Hash" do
+ it "returns a checkbox-'input'-element using the passed Hash for attributes" do
+ attributes = { "NAME" => "test", "VALUE" => "some value" }
+ output = @html.hidden("test", "some value")
+ output.should equal_element("INPUT", attributes, "", not_closed: true)
+ end
+
+ it "ignores a passed block" do
+ attributes = { "NAME" => "test", "VALUE" => "some value" }
+ output = @html.hidden("test", "some value") { "test" }
+ output.should equal_element("INPUT", attributes, "", not_closed: true)
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/htmlextension/html_spec.rb b/spec/ruby/library/cgi/htmlextension/html_spec.rb
index 0dfba297d2..60a10fb6b4 100644
--- a/spec/ruby/library/cgi/htmlextension/html_spec.rb
+++ b/spec/ruby/library/cgi/htmlextension/html_spec.rb
@@ -1,66 +1,69 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
-require File.expand_path('../fixtures/common', __FILE__)
+require_relative '../../../spec_helper'
-describe "CGI::HtmlExtension#html" do
- before :each do
- @html = CGISpecs.cgi_new
- @html.stub!(:doctype).and_return("<!DOCTYPE SUPA-FUNKAY-RUBYSPEC-DOCTYPE>")
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+ require_relative 'fixtures/common'
- describe "when passed no arguments" do
- it "returns a self's doctype and an 'html'-element" do
- expected = '<!DOCTYPE SUPA-FUNKAY-RUBYSPEC-DOCTYPE><HTML>'
- @html.html.should == expected
+ describe "CGI::HtmlExtension#html" do
+ before :each do
+ @html = CGISpecs.cgi_new
+ @html.stub!(:doctype).and_return("<!DOCTYPE SUPA-FUNKAY-RUBYSPEC-DOCTYPE>")
end
- it "includes the passed block when passed a block" do
- expected = '<!DOCTYPE SUPA-FUNKAY-RUBYSPEC-DOCTYPE><HTML>test</HTML>'
- @html.html { "test" }.should == expected
- end
- end
+ describe "when passed no arguments" do
+ it "returns a self's doctype and an 'html'-element" do
+ expected = '<!DOCTYPE SUPA-FUNKAY-RUBYSPEC-DOCTYPE><HTML>'
+ @html.html.should == expected
+ end
- describe "when passed 'PRETTY'" do
- it "returns pretty output when the passed String is 'PRETTY" do
- expected = "<!DOCTYPE SUPA-FUNKAY-RUBYSPEC-DOCTYPE>\n<HTML>\n"
- @html.html("PRETTY").should == expected
+ it "includes the passed block when passed a block" do
+ expected = '<!DOCTYPE SUPA-FUNKAY-RUBYSPEC-DOCTYPE><HTML>test</HTML>'
+ @html.html { "test" }.should == expected
+ end
end
- it "includes the passed block when passed a block" do
- expected = "<!DOCTYPE SUPA-FUNKAY-RUBYSPEC-DOCTYPE>\n<HTML>\n test\n</HTML>\n"
- @html.html("PRETTY") { "test" }.should == expected
- end
- end
+ describe "when passed 'PRETTY'" do
+ it "returns pretty output when the passed String is 'PRETTY" do
+ expected = "<!DOCTYPE SUPA-FUNKAY-RUBYSPEC-DOCTYPE>\n<HTML>\n"
+ @html.html("PRETTY").should == expected
+ end
- describe "when passed a Hash" do
- it "returns an 'html'-element using the passed Hash for attributes" do
- expected = '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"><HTML BLA="TEST">'
- @html.html("DOCTYPE" => '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">', "BLA" => "TEST").should == expected
+ it "includes the passed block when passed a block" do
+ expected = "<!DOCTYPE SUPA-FUNKAY-RUBYSPEC-DOCTYPE>\n<HTML>\n test\n</HTML>\n"
+ @html.html("PRETTY") { "test" }.should == expected
+ end
end
- it "omits the doctype when the Hash contains a 'DOCTYPE' entry that's false or nil" do
- @html.html("DOCTYPE" => false).should == "<HTML>"
- @html.html("DOCTYPE" => nil).should == "<HTML>"
- end
- end
+ describe "when passed a Hash" do
+ it "returns an 'html'-element using the passed Hash for attributes" do
+ expected = '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"><HTML BLA="TEST">'
+ @html.html("DOCTYPE" => '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">', "BLA" => "TEST").should == expected
+ end
- describe "when each HTML generation" do
- it "returns the doctype declaration for HTML3" do
- expect = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">'
- CGISpecs.cgi_new("html3").html.should == expect + "<HTML>"
- CGISpecs.cgi_new("html3").html { "html body" }.should == expect + "<HTML>html body</HTML>"
+ it "omits the doctype when the Hash contains a 'DOCTYPE' entry that's false or nil" do
+ @html.html("DOCTYPE" => false).should == "<HTML>"
+ @html.html("DOCTYPE" => nil).should == "<HTML>"
+ end
end
- it "returns the doctype declaration for HTML4" do
- expect = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">'
- CGISpecs.cgi_new("html4").html.should == expect + "<HTML>"
- CGISpecs.cgi_new("html4").html { "html body" }.should == expect + "<HTML>html body</HTML>"
- end
+ describe "when each HTML generation" do
+ it "returns the doctype declaration for HTML3" do
+ expect = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">'
+ CGISpecs.cgi_new("html3").html.should == expect + "<HTML>"
+ CGISpecs.cgi_new("html3").html { "html body" }.should == expect + "<HTML>html body</HTML>"
+ end
+
+ it "returns the doctype declaration for HTML4" do
+ expect = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">'
+ CGISpecs.cgi_new("html4").html.should == expect + "<HTML>"
+ CGISpecs.cgi_new("html4").html { "html body" }.should == expect + "<HTML>html body</HTML>"
+ end
- it "returns the doctype declaration for the Transitional version of HTML4" do
- expect = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">'
- CGISpecs.cgi_new("html4Tr").html.should == expect + "<HTML>"
- CGISpecs.cgi_new("html4Tr").html { "html body" }.should == expect + "<HTML>html body</HTML>"
+ it "returns the doctype declaration for the Transitional version of HTML4" do
+ expect = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">'
+ CGISpecs.cgi_new("html4Tr").html.should == expect + "<HTML>"
+ CGISpecs.cgi_new("html4Tr").html { "html body" }.should == expect + "<HTML>html body</HTML>"
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/htmlextension/image_button_spec.rb b/spec/ruby/library/cgi/htmlextension/image_button_spec.rb
index f4e39d8028..f8770119d4 100644
--- a/spec/ruby/library/cgi/htmlextension/image_button_spec.rb
+++ b/spec/ruby/library/cgi/htmlextension/image_button_spec.rb
@@ -1,69 +1,72 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
-require File.expand_path('../fixtures/common', __FILE__)
+require_relative '../../../spec_helper'
-describe "CGI::HtmlExtension#image_button" do
- before :each do
- @html = CGISpecs.cgi_new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+ require_relative 'fixtures/common'
- describe "when passed no arguments" do
- it "returns an image-'input'-element without a source image" do
- output = @html.image_button
- output.should equal_element("INPUT", {"SRC" => "", "TYPE" => "image"}, "", not_closed: true)
+ describe "CGI::HtmlExtension#image_button" do
+ before :each do
+ @html = CGISpecs.cgi_new
end
- it "ignores a passed block" do
- output = @html.image_button { "test" }
- output.should equal_element("INPUT", {"SRC" => "", "TYPE" => "image"}, "", not_closed: true)
- end
- end
+ describe "when passed no arguments" do
+ it "returns an image-'input'-element without a source image" do
+ output = @html.image_button
+ output.should equal_element("INPUT", {"SRC" => "", "TYPE" => "image"}, "", not_closed: true)
+ end
- describe "when passed src" do
- it "returns an image-'input'-element with the passed src" do
- output = @html.image_button("/path/to/image.png")
- output.should equal_element("INPUT", {"SRC" => "/path/to/image.png", "TYPE" => "image"}, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.image_button { "test" }
+ output.should equal_element("INPUT", {"SRC" => "", "TYPE" => "image"}, "", not_closed: true)
+ end
end
- it "ignores a passed block" do
- output = @html.image_button("/path/to/image.png") { "test" }
- output.should equal_element("INPUT", {"SRC" => "/path/to/image.png", "TYPE" => "image"}, "", not_closed: true)
- end
- end
+ describe "when passed src" do
+ it "returns an image-'input'-element with the passed src" do
+ output = @html.image_button("/path/to/image.png")
+ output.should equal_element("INPUT", {"SRC" => "/path/to/image.png", "TYPE" => "image"}, "", not_closed: true)
+ end
- describe "when passed src, name" do
- it "returns an image-'input'-element with the passed src and name" do
- output = @html.image_button("/path/to/image.png", "test")
- output.should equal_element("INPUT", {"SRC" => "/path/to/image.png", "TYPE" => "image", "NAME" => "test"}, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.image_button("/path/to/image.png") { "test" }
+ output.should equal_element("INPUT", {"SRC" => "/path/to/image.png", "TYPE" => "image"}, "", not_closed: true)
+ end
end
- it "ignores a passed block" do
- output = @html.image_button("/path/to/image.png", "test") { "test" }
- output.should equal_element("INPUT", {"SRC" => "/path/to/image.png", "TYPE" => "image", "NAME" => "test"}, "", not_closed: true)
- end
- end
+ describe "when passed src, name" do
+ it "returns an image-'input'-element with the passed src and name" do
+ output = @html.image_button("/path/to/image.png", "test")
+ output.should equal_element("INPUT", {"SRC" => "/path/to/image.png", "TYPE" => "image", "NAME" => "test"}, "", not_closed: true)
+ end
- describe "when passed src, name, alt" do
- it "returns an image-'input'-element with the passed src, name and alt" do
- output = @html.image_button("/path/to/image.png", "test", "alternative")
- output.should equal_element("INPUT", {"SRC" => "/path/to/image.png", "TYPE" => "image", "NAME" => "test", "ALT" => "alternative"}, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.image_button("/path/to/image.png", "test") { "test" }
+ output.should equal_element("INPUT", {"SRC" => "/path/to/image.png", "TYPE" => "image", "NAME" => "test"}, "", not_closed: true)
+ end
end
- it "ignores a passed block" do
- output = @html.image_button("/path/to/image.png", "test", "alternative") { "test" }
- output.should equal_element("INPUT", {"SRC" => "/path/to/image.png", "TYPE" => "image", "NAME" => "test", "ALT" => "alternative"}, "", not_closed: true)
- end
- end
+ describe "when passed src, name, alt" do
+ it "returns an image-'input'-element with the passed src, name and alt" do
+ output = @html.image_button("/path/to/image.png", "test", "alternative")
+ output.should equal_element("INPUT", {"SRC" => "/path/to/image.png", "TYPE" => "image", "NAME" => "test", "ALT" => "alternative"}, "", not_closed: true)
+ end
- describe "when passed Hash" do
- it "returns a image-'input'-element using the passed Hash for attributes" do
- output = @html.image_button("NAME" => "test", "VALUE" => "test-value")
- output.should equal_element("INPUT", {"SRC" => "", "TYPE" => "image", "NAME" => "test", "VALUE" => "test-value"}, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.image_button("/path/to/image.png", "test", "alternative") { "test" }
+ output.should equal_element("INPUT", {"SRC" => "/path/to/image.png", "TYPE" => "image", "NAME" => "test", "ALT" => "alternative"}, "", not_closed: true)
+ end
end
- it "ignores a passed block" do
- output = @html.image_button("NAME" => "test", "VALUE" => "test-value") { "test" }
- output.should equal_element("INPUT", {"SRC" => "", "TYPE" => "image", "NAME" => "test", "VALUE" => "test-value"}, "", not_closed: true)
+ describe "when passed Hash" do
+ it "returns a image-'input'-element using the passed Hash for attributes" do
+ output = @html.image_button("NAME" => "test", "VALUE" => "test-value")
+ output.should equal_element("INPUT", {"SRC" => "", "TYPE" => "image", "NAME" => "test", "VALUE" => "test-value"}, "", not_closed: true)
+ end
+
+ it "ignores a passed block" do
+ output = @html.image_button("NAME" => "test", "VALUE" => "test-value") { "test" }
+ output.should equal_element("INPUT", {"SRC" => "", "TYPE" => "image", "NAME" => "test", "VALUE" => "test-value"}, "", not_closed: true)
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/htmlextension/img_spec.rb b/spec/ruby/library/cgi/htmlextension/img_spec.rb
index 8109bcd6c6..a05cfdea48 100644
--- a/spec/ruby/library/cgi/htmlextension/img_spec.rb
+++ b/spec/ruby/library/cgi/htmlextension/img_spec.rb
@@ -1,83 +1,86 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
-require File.expand_path('../fixtures/common', __FILE__)
+require_relative '../../../spec_helper'
-describe "CGI::HtmlExtension#img" do
- before :each do
- @html = CGISpecs.cgi_new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+ require_relative 'fixtures/common'
- describe "when passed no arguments" do
- it "returns an 'img'-element without an src-url or alt-text" do
- output = @html.img
- output.should equal_element("IMG", { "SRC" => "", "ALT" => "" }, "", not_closed: true)
+ describe "CGI::HtmlExtension#img" do
+ before :each do
+ @html = CGISpecs.cgi_new
end
- it "ignores a passed block" do
- output = @html.img { "test" }
- output.should equal_element("IMG", { "SRC" => "", "ALT" => "" }, "", not_closed: true)
- end
- end
+ describe "when passed no arguments" do
+ it "returns an 'img'-element without an src-url or alt-text" do
+ output = @html.img
+ output.should equal_element("IMG", { "SRC" => "", "ALT" => "" }, "", not_closed: true)
+ end
- describe "when passed src" do
- it "returns an 'img'-element with the passed src-url" do
- output = @html.img("/path/to/some/image.png")
- output.should equal_element("IMG", { "SRC" => "/path/to/some/image.png", "ALT" => "" }, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.img { "test" }
+ output.should equal_element("IMG", { "SRC" => "", "ALT" => "" }, "", not_closed: true)
+ end
end
- it "ignores a passed block" do
- output = @html.img("/path/to/some/image.png")
- output.should equal_element("IMG", { "SRC" => "/path/to/some/image.png", "ALT" => "" }, "", not_closed: true)
- end
- end
+ describe "when passed src" do
+ it "returns an 'img'-element with the passed src-url" do
+ output = @html.img("/path/to/some/image.png")
+ output.should equal_element("IMG", { "SRC" => "/path/to/some/image.png", "ALT" => "" }, "", not_closed: true)
+ end
- describe "when passed src, alt" do
- it "returns an 'img'-element with the passed src-url and the passed alt-text" do
- output = @html.img("/path/to/some/image.png", "Alternative")
- output.should equal_element("IMG", { "SRC" => "/path/to/some/image.png", "ALT" => "Alternative" }, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.img("/path/to/some/image.png")
+ output.should equal_element("IMG", { "SRC" => "/path/to/some/image.png", "ALT" => "" }, "", not_closed: true)
+ end
end
- it "ignores a passed block" do
- output = @html.img("/path/to/some/image.png", "Alternative") { "test" }
- output.should equal_element("IMG", { "SRC" => "/path/to/some/image.png", "ALT" => "Alternative" }, "", not_closed: true)
- end
- end
+ describe "when passed src, alt" do
+ it "returns an 'img'-element with the passed src-url and the passed alt-text" do
+ output = @html.img("/path/to/some/image.png", "Alternative")
+ output.should equal_element("IMG", { "SRC" => "/path/to/some/image.png", "ALT" => "Alternative" }, "", not_closed: true)
+ end
- describe "when passed src, alt, width" do
- it "returns an 'img'-element with the passed src-url, the passed alt-text and the passed width" do
- output = @html.img("/path/to/some/image.png", "Alternative", 40)
- output.should equal_element("IMG", { "SRC" => "/path/to/some/image.png", "ALT" => "Alternative", "WIDTH" => "40" }, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.img("/path/to/some/image.png", "Alternative") { "test" }
+ output.should equal_element("IMG", { "SRC" => "/path/to/some/image.png", "ALT" => "Alternative" }, "", not_closed: true)
+ end
end
- it "ignores a passed block" do
- output = @html.img("/path/to/some/image.png", "Alternative", 40) { "test" }
- output.should equal_element("IMG", { "SRC" => "/path/to/some/image.png", "ALT" => "Alternative", "WIDTH" => "40" }, "", not_closed: true)
- end
- end
+ describe "when passed src, alt, width" do
+ it "returns an 'img'-element with the passed src-url, the passed alt-text and the passed width" do
+ output = @html.img("/path/to/some/image.png", "Alternative", 40)
+ output.should equal_element("IMG", { "SRC" => "/path/to/some/image.png", "ALT" => "Alternative", "WIDTH" => "40" }, "", not_closed: true)
+ end
- describe "when passed src, alt, width, height" do
- it "returns an 'img'-element with the passed src-url, the passed alt-text, the passed width and the passed height" do
- output = @html.img("/path/to/some/image.png", "Alternative", 40, 60)
- output.should equal_element("IMG", { "SRC" => "/path/to/some/image.png", "ALT" => "Alternative", "WIDTH" => "40", "HEIGHT" => "60" }, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.img("/path/to/some/image.png", "Alternative", 40) { "test" }
+ output.should equal_element("IMG", { "SRC" => "/path/to/some/image.png", "ALT" => "Alternative", "WIDTH" => "40" }, "", not_closed: true)
+ end
end
- it "ignores a passed block" do
- output = @html.img { "test" }
- output.should equal_element("IMG", { "SRC" => "", "ALT" => "" }, "", not_closed: true)
- end
- end
+ describe "when passed src, alt, width, height" do
+ it "returns an 'img'-element with the passed src-url, the passed alt-text, the passed width and the passed height" do
+ output = @html.img("/path/to/some/image.png", "Alternative", 40, 60)
+ output.should equal_element("IMG", { "SRC" => "/path/to/some/image.png", "ALT" => "Alternative", "WIDTH" => "40", "HEIGHT" => "60" }, "", not_closed: true)
+ end
- describe "when passed Hash" do
- it "returns an 'img'-element with the passed Hash as attributes" do
- attributes = { "SRC" => "src", "ALT" => "alt", "WIDTH" => 100, "HEIGHT" => 50 }
- output = @html.img(attributes)
- output.should equal_element("IMG", attributes, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.img { "test" }
+ output.should equal_element("IMG", { "SRC" => "", "ALT" => "" }, "", not_closed: true)
+ end
end
- it "ignores a passed block" do
- attributes = { "SRC" => "src", "ALT" => "alt", "WIDTH" => 100, "HEIGHT" => 50 }
- output = @html.img(attributes) { "test" }
- output.should equal_element("IMG", attributes, "", not_closed: true)
+ describe "when passed Hash" do
+ it "returns an 'img'-element with the passed Hash as attributes" do
+ attributes = { "SRC" => "src", "ALT" => "alt", "WIDTH" => 100, "HEIGHT" => 50 }
+ output = @html.img(attributes)
+ output.should equal_element("IMG", attributes, "", not_closed: true)
+ end
+
+ it "ignores a passed block" do
+ attributes = { "SRC" => "src", "ALT" => "alt", "WIDTH" => 100, "HEIGHT" => 50 }
+ output = @html.img(attributes) { "test" }
+ output.should equal_element("IMG", attributes, "", not_closed: true)
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/htmlextension/multipart_form_spec.rb b/spec/ruby/library/cgi/htmlextension/multipart_form_spec.rb
index 75d1b54666..4b56a7abfe 100644
--- a/spec/ruby/library/cgi/htmlextension/multipart_form_spec.rb
+++ b/spec/ruby/library/cgi/htmlextension/multipart_form_spec.rb
@@ -1,64 +1,67 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
-require File.expand_path('../fixtures/common', __FILE__)
+require_relative '../../../spec_helper'
-describe "CGI::HtmlExtension#multipart_form" do
- before :each do
- @html = CGISpecs.cgi_new
- @html.stub!(:script_name).and_return("/path/to/some/script.rb")
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+ require_relative 'fixtures/common'
- describe "when passed no arguments" do
- it "returns a 'form'-element with it's enctype set to multipart" do
- output = @html.multipart_form
- output.should equal_element("FORM", { "ENCTYPE" => "multipart/form-data", "METHOD" => "post" }, "")
+ describe "CGI::HtmlExtension#multipart_form" do
+ before :each do
+ @html = CGISpecs.cgi_new
+ @html.stub!(:script_name).and_return("/path/to/some/script.rb")
end
- it "includes the return value of the passed block when passed a block" do
- output = @html.multipart_form { "test" }
- output.should equal_element("FORM", { "ENCTYPE" => "multipart/form-data", "METHOD" => "post" }, "test")
- end
- end
+ describe "when passed no arguments" do
+ it "returns a 'form'-element with its enctype set to multipart" do
+ output = @html.multipart_form
+ output.should equal_element("FORM", { "ENCTYPE" => "multipart/form-data", "METHOD" => "post" }, "")
+ end
- describe "when passed action" do
- it "returns a 'form'-element with the passed action" do
- output = @html.multipart_form("/some/other/script.rb")
- output.should equal_element("FORM", { "ENCTYPE" => "multipart/form-data", "METHOD" => "post", "ACTION" => "/some/other/script.rb" }, "")
+ it "includes the return value of the passed block when passed a block" do
+ output = @html.multipart_form { "test" }
+ output.should equal_element("FORM", { "ENCTYPE" => "multipart/form-data", "METHOD" => "post" }, "test")
+ end
end
- it "includes the return value of the passed block when passed a block" do
- output = @html.multipart_form("/some/other/script.rb") { "test" }
- output.should equal_element("FORM", { "ENCTYPE" => "multipart/form-data", "METHOD" => "post", "ACTION" => "/some/other/script.rb" }, "test")
- end
- end
+ describe "when passed action" do
+ it "returns a 'form'-element with the passed action" do
+ output = @html.multipart_form("/some/other/script.rb")
+ output.should equal_element("FORM", { "ENCTYPE" => "multipart/form-data", "METHOD" => "post", "ACTION" => "/some/other/script.rb" }, "")
+ end
- describe "when passed action, enctype" do
- it "returns a 'form'-element with the passed action and enctype" do
- output = @html.multipart_form("/some/other/script.rb", "application/x-www-form-urlencoded")
- output.should equal_element("FORM", { "ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "post", "ACTION" => "/some/other/script.rb" }, "")
+ it "includes the return value of the passed block when passed a block" do
+ output = @html.multipart_form("/some/other/script.rb") { "test" }
+ output.should equal_element("FORM", { "ENCTYPE" => "multipart/form-data", "METHOD" => "post", "ACTION" => "/some/other/script.rb" }, "test")
+ end
end
- it "includes the return value of the passed block when passed a block" do
- output = @html.multipart_form("/some/other/script.rb", "application/x-www-form-urlencoded") { "test" }
- output.should equal_element("FORM", { "ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "post", "ACTION" => "/some/other/script.rb" }, "test")
+ describe "when passed action, enctype" do
+ it "returns a 'form'-element with the passed action and enctype" do
+ output = @html.multipart_form("/some/other/script.rb", "application/x-www-form-urlencoded")
+ output.should equal_element("FORM", { "ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "post", "ACTION" => "/some/other/script.rb" }, "")
+ end
+
+ it "includes the return value of the passed block when passed a block" do
+ output = @html.multipart_form("/some/other/script.rb", "application/x-www-form-urlencoded") { "test" }
+ output.should equal_element("FORM", { "ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "post", "ACTION" => "/some/other/script.rb" }, "test")
+ end
end
- end
- describe "when passed Hash" do
- it "returns a 'form'-element with the passed Hash as attributes" do
- output = @html.multipart_form("ID" => "test")
- output.should equal_element("FORM", { "ENCTYPE" => "multipart/form-data", "METHOD" => "post", "ID" => "test" }, "")
+ describe "when passed Hash" do
+ it "returns a 'form'-element with the passed Hash as attributes" do
+ output = @html.multipart_form("ID" => "test")
+ output.should equal_element("FORM", { "ENCTYPE" => "multipart/form-data", "METHOD" => "post", "ID" => "test" }, "")
- output = @html.multipart_form("ID" => "test", "ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "get")
- output.should equal_element("FORM", { "ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "get", "ID" => "test" }, "")
- end
+ output = @html.multipart_form("ID" => "test", "ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "get")
+ output.should equal_element("FORM", { "ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "get", "ID" => "test" }, "")
+ end
- it "includes the return value of the passed block when passed a block" do
- output = @html.multipart_form("ID" => "test") { "test" }
- output.should equal_element("FORM", { "ENCTYPE" => "multipart/form-data", "METHOD" => "post", "ID" => "test" }, "test")
+ it "includes the return value of the passed block when passed a block" do
+ output = @html.multipart_form("ID" => "test") { "test" }
+ output.should equal_element("FORM", { "ENCTYPE" => "multipart/form-data", "METHOD" => "post", "ID" => "test" }, "test")
- output = @html.multipart_form("ID" => "test", "ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "get") { "test" }
- output.should equal_element("FORM", { "ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "get", "ID" => "test" }, "test")
+ output = @html.multipart_form("ID" => "test", "ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "get") { "test" }
+ output.should equal_element("FORM", { "ENCTYPE" => "application/x-www-form-urlencoded", "METHOD" => "get", "ID" => "test" }, "test")
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/htmlextension/password_field_spec.rb b/spec/ruby/library/cgi/htmlextension/password_field_spec.rb
index bb1181de75..0fefdd5c45 100644
--- a/spec/ruby/library/cgi/htmlextension/password_field_spec.rb
+++ b/spec/ruby/library/cgi/htmlextension/password_field_spec.rb
@@ -1,84 +1,87 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
-require File.expand_path('../fixtures/common', __FILE__)
+require_relative '../../../spec_helper'
-describe "CGI::HtmlExtension#password_field" do
- before :each do
- @html = CGISpecs.cgi_new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+ require_relative 'fixtures/common'
- describe "when passed no arguments" do
- it "returns an password-'input'-element without a name" do
- output = @html.password_field
- output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "password", "SIZE" => "40"}, "", not_closed: true)
+ describe "CGI::HtmlExtension#password_field" do
+ before :each do
+ @html = CGISpecs.cgi_new
end
- it "ignores a passed block" do
- output = @html.password_field { "test" }
- output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "password", "SIZE" => "40"}, "", not_closed: true)
- end
- end
+ describe "when passed no arguments" do
+ it "returns an password-'input'-element without a name" do
+ output = @html.password_field
+ output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "password", "SIZE" => "40"}, "", not_closed: true)
+ end
- describe "when passed name" do
- it "returns an password-'input'-element with the passed name" do
- output = @html.password_field("test")
- output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "password", "SIZE" => "40"}, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.password_field { "test" }
+ output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "password", "SIZE" => "40"}, "", not_closed: true)
+ end
end
- it "ignores a passed block" do
- output = @html.password_field("test") { "test" }
- output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "password", "SIZE" => "40"}, "", not_closed: true)
- end
- end
+ describe "when passed name" do
+ it "returns an password-'input'-element with the passed name" do
+ output = @html.password_field("test")
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "password", "SIZE" => "40"}, "", not_closed: true)
+ end
- describe "when passed name, value" do
- it "returns an password-'input'-element with the passed name and value" do
- output = @html.password_field("test", "some value")
- output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "password", "VALUE" => "some value", "SIZE" => "40"}, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.password_field("test") { "test" }
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "password", "SIZE" => "40"}, "", not_closed: true)
+ end
end
- it "ignores a passed block" do
- output = @html.password_field("test", "some value") { "test" }
- output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "password", "VALUE" => "some value", "SIZE" => "40"}, "", not_closed: true)
- end
- end
+ describe "when passed name, value" do
+ it "returns an password-'input'-element with the passed name and value" do
+ output = @html.password_field("test", "some value")
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "password", "VALUE" => "some value", "SIZE" => "40"}, "", not_closed: true)
+ end
- describe "when passed name, value, size" do
- it "returns an password-'input'-element with the passed name, value and size" do
- output = @html.password_field("test", "some value", 60)
- output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "password", "VALUE" => "some value", "SIZE" => "60"}, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.password_field("test", "some value") { "test" }
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "password", "VALUE" => "some value", "SIZE" => "40"}, "", not_closed: true)
+ end
end
- it "ignores a passed block" do
- output = @html.password_field("test", "some value", 60) { "test" }
- output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "password", "VALUE" => "some value", "SIZE" => "60"}, "", not_closed: true)
- end
- end
+ describe "when passed name, value, size" do
+ it "returns an password-'input'-element with the passed name, value and size" do
+ output = @html.password_field("test", "some value", 60)
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "password", "VALUE" => "some value", "SIZE" => "60"}, "", not_closed: true)
+ end
- describe "when passed name, value, size, maxlength" do
- it "returns an password-'input'-element with the passed name, value, size and maxlength" do
- output = @html.password_field("test", "some value", 60, 12)
- output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "password", "VALUE" => "some value", "SIZE" => "60", "MAXLENGTH" => 12}, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.password_field("test", "some value", 60) { "test" }
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "password", "VALUE" => "some value", "SIZE" => "60"}, "", not_closed: true)
+ end
end
- it "ignores a passed block" do
- output = @html.password_field("test", "some value", 60, 12) { "test" }
- output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "password", "VALUE" => "some value", "SIZE" => "60", "MAXLENGTH" => 12}, "", not_closed: true)
+ describe "when passed name, value, size, maxlength" do
+ it "returns an password-'input'-element with the passed name, value, size and maxlength" do
+ output = @html.password_field("test", "some value", 60, 12)
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "password", "VALUE" => "some value", "SIZE" => "60", "MAXLENGTH" => 12}, "", not_closed: true)
+ end
+
+ it "ignores a passed block" do
+ output = @html.password_field("test", "some value", 60, 12) { "test" }
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "password", "VALUE" => "some value", "SIZE" => "60", "MAXLENGTH" => 12}, "", not_closed: true)
+ end
end
- end
- describe "when passed Hash" do
- it "returns a checkbox-'input'-element using the passed Hash for attributes" do
- output = @html.password_field("NAME" => "test", "VALUE" => "some value")
- output.should equal_element("INPUT", { "NAME" => "test", "VALUE" => "some value", "TYPE" => "password" }, "", not_closed: true)
+ describe "when passed Hash" do
+ it "returns a checkbox-'input'-element using the passed Hash for attributes" do
+ output = @html.password_field("NAME" => "test", "VALUE" => "some value")
+ output.should equal_element("INPUT", { "NAME" => "test", "VALUE" => "some value", "TYPE" => "password" }, "", not_closed: true)
- output = @html.password_field("TYPE" => "hidden")
- output.should equal_element("INPUT", {"TYPE" => "password"}, "", not_closed: true)
- end
+ output = @html.password_field("TYPE" => "hidden")
+ output.should equal_element("INPUT", {"TYPE" => "password"}, "", not_closed: true)
+ end
- it "ignores a passed block" do
- output = @html.password_field("NAME" => "test", "VALUE" => "some value") { "test" }
- output.should equal_element("INPUT", { "NAME" => "test", "VALUE" => "some value", "TYPE" => "password" }, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.password_field("NAME" => "test", "VALUE" => "some value") { "test" }
+ output.should equal_element("INPUT", { "NAME" => "test", "VALUE" => "some value", "TYPE" => "password" }, "", not_closed: true)
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/htmlextension/popup_menu_spec.rb b/spec/ruby/library/cgi/htmlextension/popup_menu_spec.rb
index 5e94ec1a3e..7452d15317 100644
--- a/spec/ruby/library/cgi/htmlextension/popup_menu_spec.rb
+++ b/spec/ruby/library/cgi/htmlextension/popup_menu_spec.rb
@@ -1,8 +1,11 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
-require File.expand_path('../fixtures/common', __FILE__)
-require File.expand_path('../shared/popup_menu', __FILE__)
+require_relative '../../../spec_helper'
-describe "CGI::HtmlExtension#popup_menu" do
- it_behaves_like :cgi_htmlextension_popup_menu, :popup_menu
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+ require_relative 'fixtures/common'
+ require_relative 'shared/popup_menu'
+
+ describe "CGI::HtmlExtension#popup_menu" do
+ it_behaves_like :cgi_htmlextension_popup_menu, :popup_menu
+ end
end
diff --git a/spec/ruby/library/cgi/htmlextension/radio_button_spec.rb b/spec/ruby/library/cgi/htmlextension/radio_button_spec.rb
index 0ce88f20d7..8458685cdc 100644
--- a/spec/ruby/library/cgi/htmlextension/radio_button_spec.rb
+++ b/spec/ruby/library/cgi/htmlextension/radio_button_spec.rb
@@ -1,77 +1,80 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
-require File.expand_path('../fixtures/common', __FILE__)
+require_relative '../../../spec_helper'
-describe "CGI::HtmlExtension#radio_button" do
- before :each do
- @html = CGISpecs.cgi_new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+ require_relative 'fixtures/common'
- describe "when passed no arguments" do
- it "returns a radio-'input'-element without a name" do
- output = @html.radio_button
- output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "radio"}, "", not_closed: true)
+ describe "CGI::HtmlExtension#radio_button" do
+ before :each do
+ @html = CGISpecs.cgi_new
end
- it "ignores a passed block" do
- output = @html.radio_button { "test" }
- output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "radio"}, "", not_closed: true)
- end
- end
+ describe "when passed no arguments" do
+ it "returns a radio-'input'-element without a name" do
+ output = @html.radio_button
+ output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "radio"}, "", not_closed: true)
+ end
- describe "when passed name" do
- it "returns a radio-'input'-element with the passed name" do
- output = @html.radio_button("test")
- output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio"}, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.radio_button { "test" }
+ output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "radio"}, "", not_closed: true)
+ end
end
- it "ignores a passed block" do
- output = @html.radio_button("test") { "test" }
- output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio"}, "", not_closed: true)
- end
- end
+ describe "when passed name" do
+ it "returns a radio-'input'-element with the passed name" do
+ output = @html.radio_button("test")
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio"}, "", not_closed: true)
+ end
- describe "CGI::HtmlExtension#checkbox when passed name, value" do
- it "returns a radio-'input'-element with the passed name and value" do
- output = @html.radio_button("test", "test-value")
- output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "test-value"}, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.radio_button("test") { "test" }
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio"}, "", not_closed: true)
+ end
end
- it "ignores a passed block" do
- output = @html.radio_button("test", "test-value") { "test" }
- output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "test-value"}, "", not_closed: true)
+ describe "CGI::HtmlExtension#checkbox when passed name, value" do
+ it "returns a radio-'input'-element with the passed name and value" do
+ output = @html.radio_button("test", "test-value")
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "test-value"}, "", not_closed: true)
+ end
+
+ it "ignores a passed block" do
+ output = @html.radio_button("test", "test-value") { "test" }
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "test-value"}, "", not_closed: true)
+ end
end
- end
- describe "when passed name, value, checked" do
- it "returns a checked radio-'input'-element with the passed name and value when checked is true" do
- output = @html.radio_button("test", "test-value", true)
- output.should equal_element("INPUT", {"CHECKED" => true, "NAME" => "test", "TYPE" => "radio", "VALUE" => "test-value"}, "", not_closed: true)
+ describe "when passed name, value, checked" do
+ it "returns a checked radio-'input'-element with the passed name and value when checked is true" do
+ output = @html.radio_button("test", "test-value", true)
+ output.should equal_element("INPUT", {"CHECKED" => true, "NAME" => "test", "TYPE" => "radio", "VALUE" => "test-value"}, "", not_closed: true)
- output = @html.radio_button("test", "test-value", false)
- output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "test-value"}, "", not_closed: true)
+ output = @html.radio_button("test", "test-value", false)
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "test-value"}, "", not_closed: true)
- output = @html.radio_button("test", "test-value", nil)
- output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "test-value"}, "", not_closed: true)
- end
+ output = @html.radio_button("test", "test-value", nil)
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "test-value"}, "", not_closed: true)
+ end
- it "ignores a passed block" do
- output = @html.radio_button("test", "test-value", nil) { "test" }
- output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "test-value"}, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.radio_button("test", "test-value", nil) { "test" }
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "test-value"}, "", not_closed: true)
+ end
end
- end
- describe "when passed Hash" do
- it "returns a radio-'input'-element using the passed Hash for attributes" do
- attributes = {"NAME" => "test", "VALUE" => "test-value", "CHECKED" => true}
- output = @html.radio_button(attributes)
- output.should equal_element("INPUT", attributes, "", not_closed: true)
- end
+ describe "when passed Hash" do
+ it "returns a radio-'input'-element using the passed Hash for attributes" do
+ attributes = {"NAME" => "test", "VALUE" => "test-value", "CHECKED" => true}
+ output = @html.radio_button(attributes)
+ output.should equal_element("INPUT", attributes, "", not_closed: true)
+ end
- it "ignores a passed block" do
- attributes = {"NAME" => "test", "VALUE" => "test-value", "CHECKED" => true}
- output = @html.radio_button(attributes) { "test" }
- output.should equal_element("INPUT", attributes, "", not_closed: true)
+ it "ignores a passed block" do
+ attributes = {"NAME" => "test", "VALUE" => "test-value", "CHECKED" => true}
+ output = @html.radio_button(attributes) { "test" }
+ output.should equal_element("INPUT", attributes, "", not_closed: true)
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/htmlextension/radio_group_spec.rb b/spec/ruby/library/cgi/htmlextension/radio_group_spec.rb
index 69d3444072..fd925a5165 100644
--- a/spec/ruby/library/cgi/htmlextension/radio_group_spec.rb
+++ b/spec/ruby/library/cgi/htmlextension/radio_group_spec.rb
@@ -1,77 +1,80 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
-require File.expand_path('../fixtures/common', __FILE__)
+require_relative '../../../spec_helper'
-describe "CGI::HtmlExtension#radio_group" do
- before :each do
- @html = CGISpecs.cgi_new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+ require_relative 'fixtures/common'
- describe "when passed name, values ..." do
- it "returns a sequence of 'radio'-elements with the passed name and the passed values" do
- output = CGISpecs.split(@html.radio_group("test", "foo", "bar", "baz"))
- output[0].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "foo"}, "foo", not_closed: true)
- output[1].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "bar"}, "bar", not_closed: true)
- output[2].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "baz"}, "baz", not_closed: true)
+ describe "CGI::HtmlExtension#radio_group" do
+ before :each do
+ @html = CGISpecs.cgi_new
end
- it "allows passing a value inside an Array" do
- output = CGISpecs.split(@html.radio_group("test", ["foo"], "bar", ["baz"]))
- output[0].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "foo"}, "foo", not_closed: true)
- output[1].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "bar"}, "bar", not_closed: true)
- output[2].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "baz"}, "baz", not_closed: true)
- end
+ describe "when passed name, values ..." do
+ it "returns a sequence of 'radio'-elements with the passed name and the passed values" do
+ output = CGISpecs.split(@html.radio_group("test", "foo", "bar", "baz"))
+ output[0].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "foo"}, "foo", not_closed: true)
+ output[1].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "bar"}, "bar", not_closed: true)
+ output[2].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "baz"}, "baz", not_closed: true)
+ end
- it "allows passing a value as an Array containing the value and the checked state or a label" do
- output = CGISpecs.split(@html.radio_group("test", ["foo"], ["bar", true], ["baz", "label for baz"]))
- output[0].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "foo"}, "foo", not_closed: true)
- output[1].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "test", "TYPE" => "radio", "VALUE" => "bar"}, "bar", not_closed: true)
- output[2].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "baz"}, "label for baz", not_closed: true)
- end
+ it "allows passing a value inside an Array" do
+ output = CGISpecs.split(@html.radio_group("test", ["foo"], "bar", ["baz"]))
+ output[0].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "foo"}, "foo", not_closed: true)
+ output[1].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "bar"}, "bar", not_closed: true)
+ output[2].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "baz"}, "baz", not_closed: true)
+ end
- # TODO: CGI does not like passing false instead of true.
- it "allows passing a value as an Array containing the value, a label and the checked state" do
- output = CGISpecs.split(@html.radio_group("test", ["foo", "label for foo", true], ["bar", "label for bar", false], ["baz", "label for baz", true]))
- output[0].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "test", "TYPE" => "radio", "VALUE" => "foo"}, "label for foo", not_closed: true)
- output[1].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "bar"}, "label for bar", not_closed: true)
- output[2].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "test", "TYPE" => "radio", "VALUE" => "baz"}, "label for baz", not_closed: true)
- end
+ it "allows passing a value as an Array containing the value and the checked state or a label" do
+ output = CGISpecs.split(@html.radio_group("test", ["foo"], ["bar", true], ["baz", "label for baz"]))
+ output[0].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "foo"}, "foo", not_closed: true)
+ output[1].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "test", "TYPE" => "radio", "VALUE" => "bar"}, "bar", not_closed: true)
+ output[2].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "baz"}, "label for baz", not_closed: true)
+ end
- it "returns an empty String when passed no values" do
- @html.radio_group("test").should == ""
- end
+ # TODO: CGI does not like passing false instead of true.
+ it "allows passing a value as an Array containing the value, a label and the checked state" do
+ output = CGISpecs.split(@html.radio_group("test", ["foo", "label for foo", true], ["bar", "label for bar", false], ["baz", "label for baz", true]))
+ output[0].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "test", "TYPE" => "radio", "VALUE" => "foo"}, "label for foo", not_closed: true)
+ output[1].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "bar"}, "label for bar", not_closed: true)
+ output[2].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "test", "TYPE" => "radio", "VALUE" => "baz"}, "label for baz", not_closed: true)
+ end
+
+ it "returns an empty String when passed no values" do
+ @html.radio_group("test").should == ""
+ end
- it "ignores a passed block" do
- output = CGISpecs.split(@html.radio_group("test", "foo", "bar", "baz") { "test" })
- output[0].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "foo"}, "foo", not_closed: true)
- output[1].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "bar"}, "bar", not_closed: true)
- output[2].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "baz"}, "baz", not_closed: true)
+ it "ignores a passed block" do
+ output = CGISpecs.split(@html.radio_group("test", "foo", "bar", "baz") { "test" })
+ output[0].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "foo"}, "foo", not_closed: true)
+ output[1].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "bar"}, "bar", not_closed: true)
+ output[2].should equal_element("INPUT", {"NAME" => "test", "TYPE" => "radio", "VALUE" => "baz"}, "baz", not_closed: true)
+ end
end
- end
- describe "when passed Hash" do
- it "uses the passed Hash to generate the radio sequence" do
- output = CGISpecs.split(@html.radio_group("NAME" => "name", "VALUES" => ["foo", "bar", "baz"]))
- output[0].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "foo"}, "foo", not_closed: true)
- output[1].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "bar"}, "bar", not_closed: true)
- output[2].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "baz"}, "baz", not_closed: true)
+ describe "when passed Hash" do
+ it "uses the passed Hash to generate the radio sequence" do
+ output = CGISpecs.split(@html.radio_group("NAME" => "name", "VALUES" => ["foo", "bar", "baz"]))
+ output[0].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "foo"}, "foo", not_closed: true)
+ output[1].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "bar"}, "bar", not_closed: true)
+ output[2].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "baz"}, "baz", not_closed: true)
- output = CGISpecs.split(@html.radio_group("NAME" => "name", "VALUES" => [["foo"], ["bar", true], "baz"]))
- output[0].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "foo"}, "foo", not_closed: true)
- output[1].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "name", "TYPE" => "radio", "VALUE" => "bar"}, "bar", not_closed: true)
- output[2].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "baz"}, "baz", not_closed: true)
+ output = CGISpecs.split(@html.radio_group("NAME" => "name", "VALUES" => [["foo"], ["bar", true], "baz"]))
+ output[0].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "foo"}, "foo", not_closed: true)
+ output[1].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "name", "TYPE" => "radio", "VALUE" => "bar"}, "bar", not_closed: true)
+ output[2].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "baz"}, "baz", not_closed: true)
- output = CGISpecs.split(@html.radio_group("NAME" => "name", "VALUES" => [["1", "Foo"], ["2", "Bar", true], "Baz"]))
- output[0].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "1"}, "Foo", not_closed: true)
- output[1].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "name", "TYPE" => "radio", "VALUE" => "2"}, "Bar", not_closed: true)
- output[2].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "Baz"}, "Baz", not_closed: true)
- end
+ output = CGISpecs.split(@html.radio_group("NAME" => "name", "VALUES" => [["1", "Foo"], ["2", "Bar", true], "Baz"]))
+ output[0].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "1"}, "Foo", not_closed: true)
+ output[1].should equal_element("INPUT", {"CHECKED" => true, "NAME" => "name", "TYPE" => "radio", "VALUE" => "2"}, "Bar", not_closed: true)
+ output[2].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "Baz"}, "Baz", not_closed: true)
+ end
- it "ignores a passed block" do
- output = CGISpecs.split(@html.radio_group("NAME" => "name", "VALUES" => ["foo", "bar", "baz"]) { "test" })
- output[0].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "foo"}, "foo", not_closed: true)
- output[1].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "bar"}, "bar", not_closed: true)
- output[2].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "baz"}, "baz", not_closed: true)
+ it "ignores a passed block" do
+ output = CGISpecs.split(@html.radio_group("NAME" => "name", "VALUES" => ["foo", "bar", "baz"]) { "test" })
+ output[0].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "foo"}, "foo", not_closed: true)
+ output[1].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "bar"}, "bar", not_closed: true)
+ output[2].should equal_element("INPUT", {"NAME" => "name", "TYPE" => "radio", "VALUE" => "baz"}, "baz", not_closed: true)
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/htmlextension/reset_spec.rb b/spec/ruby/library/cgi/htmlextension/reset_spec.rb
index 09184347d0..80e4441b16 100644
--- a/spec/ruby/library/cgi/htmlextension/reset_spec.rb
+++ b/spec/ruby/library/cgi/htmlextension/reset_spec.rb
@@ -1,57 +1,60 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
-require File.expand_path('../fixtures/common', __FILE__)
+require_relative '../../../spec_helper'
-describe "CGI::HtmlExtension#reset" do
- before :each do
- @html = CGISpecs.cgi_new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+ require_relative 'fixtures/common'
- describe "when passed no arguments" do
- it "returns a reset-'input'-element" do
- output = @html.reset
- output.should equal_element("INPUT", {"TYPE" => "reset"}, "", not_closed: true)
+ describe "CGI::HtmlExtension#reset" do
+ before :each do
+ @html = CGISpecs.cgi_new
end
- it "ignores a passed block" do
- output = @html.reset { "test" }
- output.should equal_element("INPUT", {"TYPE" => "reset"}, "", not_closed: true)
- end
- end
+ describe "when passed no arguments" do
+ it "returns a reset-'input'-element" do
+ output = @html.reset
+ output.should equal_element("INPUT", {"TYPE" => "reset"}, "", not_closed: true)
+ end
- describe "when passed value" do
- it "returns a reset-'input'-element with the passed value" do
- output = @html.reset("Example")
- output.should equal_element("INPUT", {"TYPE" => "reset", "VALUE" => "Example"}, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.reset { "test" }
+ output.should equal_element("INPUT", {"TYPE" => "reset"}, "", not_closed: true)
+ end
end
- it "ignores a passed block" do
- output = @html.reset("Example") { "test" }
- output.should equal_element("INPUT", {"TYPE" => "reset", "VALUE" => "Example"}, "", not_closed: true)
- end
- end
+ describe "when passed value" do
+ it "returns a reset-'input'-element with the passed value" do
+ output = @html.reset("Example")
+ output.should equal_element("INPUT", {"TYPE" => "reset", "VALUE" => "Example"}, "", not_closed: true)
+ end
- describe "when passed value, name" do
- it "returns a reset-'input'-element with the passed value and the passed name" do
- output = @html.reset("Example", "test-name")
- output.should equal_element("INPUT", {"TYPE" => "reset", "VALUE" => "Example", "NAME" => "test-name"}, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.reset("Example") { "test" }
+ output.should equal_element("INPUT", {"TYPE" => "reset", "VALUE" => "Example"}, "", not_closed: true)
+ end
end
- it "ignores a passed block" do
- output = @html.reset("Example", "test-name") { "test" }
- output.should equal_element("INPUT", {"TYPE" => "reset", "VALUE" => "Example", "NAME" => "test-name"}, "", not_closed: true)
- end
- end
+ describe "when passed value, name" do
+ it "returns a reset-'input'-element with the passed value and the passed name" do
+ output = @html.reset("Example", "test-name")
+ output.should equal_element("INPUT", {"TYPE" => "reset", "VALUE" => "Example", "NAME" => "test-name"}, "", not_closed: true)
+ end
- describe "when passed Hash" do
- it "returns a reset-'input'-element with the passed value" do
- output = @html.reset("Example")
- output.should equal_element("INPUT", {"TYPE" => "reset", "VALUE" => "Example"}, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.reset("Example", "test-name") { "test" }
+ output.should equal_element("INPUT", {"TYPE" => "reset", "VALUE" => "Example", "NAME" => "test-name"}, "", not_closed: true)
+ end
end
- it "ignores a passed block" do
- output = @html.reset("Example") { "test" }
- output.should equal_element("INPUT", {"TYPE" => "reset", "VALUE" => "Example"}, "", not_closed: true)
+ describe "when passed Hash" do
+ it "returns a reset-'input'-element with the passed value" do
+ output = @html.reset("Example")
+ output.should equal_element("INPUT", {"TYPE" => "reset", "VALUE" => "Example"}, "", not_closed: true)
+ end
+
+ it "ignores a passed block" do
+ output = @html.reset("Example") { "test" }
+ output.should equal_element("INPUT", {"TYPE" => "reset", "VALUE" => "Example"}, "", not_closed: true)
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/htmlextension/scrolling_list_spec.rb b/spec/ruby/library/cgi/htmlextension/scrolling_list_spec.rb
index da295278b1..b565444679 100644
--- a/spec/ruby/library/cgi/htmlextension/scrolling_list_spec.rb
+++ b/spec/ruby/library/cgi/htmlextension/scrolling_list_spec.rb
@@ -1,8 +1,11 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/common', __FILE__)
-require 'cgi'
-require File.expand_path('../shared/popup_menu', __FILE__)
+require_relative '../../../spec_helper'
-describe "CGI::HtmlExtension#scrolling_list" do
- it_behaves_like :cgi_htmlextension_popup_menu, :scrolling_list
+ruby_version_is ""..."4.0" do
+ require_relative 'fixtures/common'
+ require 'cgi'
+ require_relative 'shared/popup_menu'
+
+ describe "CGI::HtmlExtension#scrolling_list" do
+ it_behaves_like :cgi_htmlextension_popup_menu, :scrolling_list
+ end
end
diff --git a/spec/ruby/library/cgi/htmlextension/submit_spec.rb b/spec/ruby/library/cgi/htmlextension/submit_spec.rb
index 8b9d9b02d8..bb6e079c4e 100644
--- a/spec/ruby/library/cgi/htmlextension/submit_spec.rb
+++ b/spec/ruby/library/cgi/htmlextension/submit_spec.rb
@@ -1,57 +1,60 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
-require File.expand_path('../fixtures/common', __FILE__)
+require_relative '../../../spec_helper'
-describe "CGI::HtmlExtension#submit" do
- before :each do
- @html = CGISpecs.cgi_new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+ require_relative 'fixtures/common'
- describe "when passed no arguments" do
- it "returns a submit-'input'-element" do
- output = @html.submit
- output.should equal_element("INPUT", {"TYPE" => "submit"}, "", not_closed: true)
+ describe "CGI::HtmlExtension#submit" do
+ before :each do
+ @html = CGISpecs.cgi_new
end
- it "ignores a passed block" do
- output = @html.submit { "test" }
- output.should equal_element("INPUT", {"TYPE" => "submit"}, "", not_closed: true)
- end
- end
+ describe "when passed no arguments" do
+ it "returns a submit-'input'-element" do
+ output = @html.submit
+ output.should equal_element("INPUT", {"TYPE" => "submit"}, "", not_closed: true)
+ end
- describe "when passed value" do
- it "returns a submit-'input'-element with the passed value" do
- output = @html.submit("Example")
- output.should equal_element("INPUT", {"TYPE" => "submit", "VALUE" => "Example"}, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.submit { "test" }
+ output.should equal_element("INPUT", {"TYPE" => "submit"}, "", not_closed: true)
+ end
end
- it "ignores a passed block" do
- output = @html.submit("Example") { "test" }
- output.should equal_element("INPUT", {"TYPE" => "submit", "VALUE" => "Example"}, "", not_closed: true)
- end
- end
+ describe "when passed value" do
+ it "returns a submit-'input'-element with the passed value" do
+ output = @html.submit("Example")
+ output.should equal_element("INPUT", {"TYPE" => "submit", "VALUE" => "Example"}, "", not_closed: true)
+ end
- describe "when passed value, name" do
- it "returns a submit-'input'-element with the passed value and the passed name" do
- output = @html.submit("Example", "test-name")
- output.should equal_element("INPUT", {"TYPE" => "submit", "VALUE" => "Example", "NAME" => "test-name"}, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.submit("Example") { "test" }
+ output.should equal_element("INPUT", {"TYPE" => "submit", "VALUE" => "Example"}, "", not_closed: true)
+ end
end
- it "ignores a passed block" do
- output = @html.submit("Example", "test-name") { "test" }
- output.should equal_element("INPUT", {"TYPE" => "submit", "VALUE" => "Example", "NAME" => "test-name"}, "", not_closed: true)
- end
- end
+ describe "when passed value, name" do
+ it "returns a submit-'input'-element with the passed value and the passed name" do
+ output = @html.submit("Example", "test-name")
+ output.should equal_element("INPUT", {"TYPE" => "submit", "VALUE" => "Example", "NAME" => "test-name"}, "", not_closed: true)
+ end
- describe "when passed Hash" do
- it "returns a submit-'input'-element with the passed value" do
- output = @html.submit("Example")
- output.should equal_element("INPUT", {"TYPE" => "submit", "VALUE" => "Example"}, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.submit("Example", "test-name") { "test" }
+ output.should equal_element("INPUT", {"TYPE" => "submit", "VALUE" => "Example", "NAME" => "test-name"}, "", not_closed: true)
+ end
end
- it "ignores a passed block" do
- output = @html.submit("Example") { "test" }
- output.should equal_element("INPUT", {"TYPE" => "submit", "VALUE" => "Example"}, "", not_closed: true)
+ describe "when passed Hash" do
+ it "returns a submit-'input'-element with the passed value" do
+ output = @html.submit("Example")
+ output.should equal_element("INPUT", {"TYPE" => "submit", "VALUE" => "Example"}, "", not_closed: true)
+ end
+
+ it "ignores a passed block" do
+ output = @html.submit("Example") { "test" }
+ output.should equal_element("INPUT", {"TYPE" => "submit", "VALUE" => "Example"}, "", not_closed: true)
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/htmlextension/text_field_spec.rb b/spec/ruby/library/cgi/htmlextension/text_field_spec.rb
index b8031d6ff5..37e13e3746 100644
--- a/spec/ruby/library/cgi/htmlextension/text_field_spec.rb
+++ b/spec/ruby/library/cgi/htmlextension/text_field_spec.rb
@@ -1,84 +1,87 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
-require File.expand_path('../fixtures/common', __FILE__)
+require_relative '../../../spec_helper'
-describe "CGI::HtmlExtension#text_field" do
- before :each do
- @html = CGISpecs.cgi_new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+ require_relative 'fixtures/common'
- describe "when passed no arguments" do
- it "returns an text-'input'-element without a name" do
- output = @html.text_field
- output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "text", "SIZE" => "40"}, "", not_closed: true)
+ describe "CGI::HtmlExtension#text_field" do
+ before :each do
+ @html = CGISpecs.cgi_new
end
- it "ignores a passed block" do
- output = @html.text_field { "test" }
- output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "text", "SIZE" => "40"}, "", not_closed: true)
- end
- end
+ describe "when passed no arguments" do
+ it "returns an text-'input'-element without a name" do
+ output = @html.text_field
+ output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "text", "SIZE" => "40"}, "", not_closed: true)
+ end
- describe "when passed name" do
- it "returns an text-'input'-element with the passed name" do
- output = @html.text_field("test")
- output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "text", "SIZE" => "40"}, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.text_field { "test" }
+ output.should equal_element("INPUT", {"NAME" => "", "TYPE" => "text", "SIZE" => "40"}, "", not_closed: true)
+ end
end
- it "ignores a passed block" do
- output = @html.text_field("test") { "test" }
- output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "text", "SIZE" => "40"}, "", not_closed: true)
- end
- end
+ describe "when passed name" do
+ it "returns an text-'input'-element with the passed name" do
+ output = @html.text_field("test")
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "text", "SIZE" => "40"}, "", not_closed: true)
+ end
- describe "when passed name, value" do
- it "returns an text-'input'-element with the passed name and value" do
- output = @html.text_field("test", "some value")
- output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "text", "VALUE" => "some value", "SIZE" => "40"}, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.text_field("test") { "test" }
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "text", "SIZE" => "40"}, "", not_closed: true)
+ end
end
- it "ignores a passed block" do
- output = @html.text_field("test", "some value") { "test" }
- output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "text", "VALUE" => "some value", "SIZE" => "40"}, "", not_closed: true)
- end
- end
+ describe "when passed name, value" do
+ it "returns an text-'input'-element with the passed name and value" do
+ output = @html.text_field("test", "some value")
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "text", "VALUE" => "some value", "SIZE" => "40"}, "", not_closed: true)
+ end
- describe "when passed name, value, size" do
- it "returns an text-'input'-element with the passed name, value and size" do
- output = @html.text_field("test", "some value", 60)
- output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "text", "VALUE" => "some value", "SIZE" => "60"}, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.text_field("test", "some value") { "test" }
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "text", "VALUE" => "some value", "SIZE" => "40"}, "", not_closed: true)
+ end
end
- it "ignores a passed block" do
- output = @html.text_field("test", "some value", 60) { "test" }
- output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "text", "VALUE" => "some value", "SIZE" => "60"}, "", not_closed: true)
- end
- end
+ describe "when passed name, value, size" do
+ it "returns an text-'input'-element with the passed name, value and size" do
+ output = @html.text_field("test", "some value", 60)
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "text", "VALUE" => "some value", "SIZE" => "60"}, "", not_closed: true)
+ end
- describe "when passed name, value, size, maxlength" do
- it "returns an text-'input'-element with the passed name, value, size and maxlength" do
- output = @html.text_field("test", "some value", 60, 12)
- output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "text", "VALUE" => "some value", "SIZE" => "60", "MAXLENGTH" => 12}, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.text_field("test", "some value", 60) { "test" }
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "text", "VALUE" => "some value", "SIZE" => "60"}, "", not_closed: true)
+ end
end
- it "ignores a passed block" do
- output = @html.text_field("test", "some value", 60, 12) { "test" }
- output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "text", "VALUE" => "some value", "SIZE" => "60", "MAXLENGTH" => 12}, "", not_closed: true)
+ describe "when passed name, value, size, maxlength" do
+ it "returns an text-'input'-element with the passed name, value, size and maxlength" do
+ output = @html.text_field("test", "some value", 60, 12)
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "text", "VALUE" => "some value", "SIZE" => "60", "MAXLENGTH" => 12}, "", not_closed: true)
+ end
+
+ it "ignores a passed block" do
+ output = @html.text_field("test", "some value", 60, 12) { "test" }
+ output.should equal_element("INPUT", {"NAME" => "test", "TYPE" => "text", "VALUE" => "some value", "SIZE" => "60", "MAXLENGTH" => 12}, "", not_closed: true)
+ end
end
- end
- describe "when passed Hash" do
- it "returns a checkbox-'input'-element using the passed Hash for attributes" do
- output = @html.text_field("NAME" => "test", "VALUE" => "some value")
- output.should equal_element("INPUT", { "NAME" => "test", "VALUE" => "some value", "TYPE" => "text" }, "", not_closed: true)
+ describe "when passed Hash" do
+ it "returns a checkbox-'input'-element using the passed Hash for attributes" do
+ output = @html.text_field("NAME" => "test", "VALUE" => "some value")
+ output.should equal_element("INPUT", { "NAME" => "test", "VALUE" => "some value", "TYPE" => "text" }, "", not_closed: true)
- output = @html.text_field("TYPE" => "hidden")
- output.should equal_element("INPUT", {"TYPE" => "text"}, "", not_closed: true)
- end
+ output = @html.text_field("TYPE" => "hidden")
+ output.should equal_element("INPUT", {"TYPE" => "text"}, "", not_closed: true)
+ end
- it "ignores a passed block" do
- output = @html.text_field("NAME" => "test", "VALUE" => "some value") { "test" }
- output.should equal_element("INPUT", { "NAME" => "test", "VALUE" => "some value", "TYPE" => "text" }, "", not_closed: true)
+ it "ignores a passed block" do
+ output = @html.text_field("NAME" => "test", "VALUE" => "some value") { "test" }
+ output.should equal_element("INPUT", { "NAME" => "test", "VALUE" => "some value", "TYPE" => "text" }, "", not_closed: true)
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/htmlextension/textarea_spec.rb b/spec/ruby/library/cgi/htmlextension/textarea_spec.rb
index e47e6ed417..99c6d3dd2d 100644
--- a/spec/ruby/library/cgi/htmlextension/textarea_spec.rb
+++ b/spec/ruby/library/cgi/htmlextension/textarea_spec.rb
@@ -1,73 +1,76 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
-require File.expand_path('../fixtures/common', __FILE__)
+require_relative '../../../spec_helper'
-describe "CGI::HtmlExtension#textarea" do
- before :each do
- @html = CGISpecs.cgi_new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+ require_relative 'fixtures/common'
- describe "when passed no arguments" do
- it "returns an 'textarea'-element without a name" do
- output = @html.textarea
- output.should equal_element("TEXTAREA", {"NAME" => "", "COLS" => "70", "ROWS" => "10"}, "")
+ describe "CGI::HtmlExtension#textarea" do
+ before :each do
+ @html = CGISpecs.cgi_new
end
- it "includes the return value of the passed block when passed a block" do
- output = @html.textarea { "Example" }
- output.should equal_element("TEXTAREA", {"NAME" => "", "COLS" => "70", "ROWS" => "10"}, "Example")
- end
- end
+ describe "when passed no arguments" do
+ it "returns an 'textarea'-element without a name" do
+ output = @html.textarea
+ output.should equal_element("TEXTAREA", {"NAME" => "", "COLS" => "70", "ROWS" => "10"}, "")
+ end
- describe "when passed name" do
- it "returns an 'textarea'-element with the passed name" do
- output = @html.textarea("test")
- output.should equal_element("TEXTAREA", {"NAME" => "test", "COLS" => "70", "ROWS" => "10"}, "")
+ it "includes the return value of the passed block when passed a block" do
+ output = @html.textarea { "Example" }
+ output.should equal_element("TEXTAREA", {"NAME" => "", "COLS" => "70", "ROWS" => "10"}, "Example")
+ end
end
- it "includes the return value of the passed block when passed a block" do
- output = @html.textarea("test") { "Example" }
- output.should equal_element("TEXTAREA", {"NAME" => "test", "COLS" => "70", "ROWS" => "10"}, "Example")
- end
- end
+ describe "when passed name" do
+ it "returns an 'textarea'-element with the passed name" do
+ output = @html.textarea("test")
+ output.should equal_element("TEXTAREA", {"NAME" => "test", "COLS" => "70", "ROWS" => "10"}, "")
+ end
- describe "when passed name, cols" do
- it "returns an 'textarea'-element with the passed name and the passed amount of columns" do
- output = @html.textarea("test", 40)
- output.should equal_element("TEXTAREA", {"NAME" => "test", "COLS" => "40", "ROWS" => "10"}, "")
+ it "includes the return value of the passed block when passed a block" do
+ output = @html.textarea("test") { "Example" }
+ output.should equal_element("TEXTAREA", {"NAME" => "test", "COLS" => "70", "ROWS" => "10"}, "Example")
+ end
end
- it "includes the return value of the passed block when passed a block" do
- output = @html.textarea("test", 40) { "Example" }
- output.should equal_element("TEXTAREA", {"NAME" => "test", "COLS" => "40", "ROWS" => "10"}, "Example")
- end
- end
+ describe "when passed name, cols" do
+ it "returns an 'textarea'-element with the passed name and the passed amount of columns" do
+ output = @html.textarea("test", 40)
+ output.should equal_element("TEXTAREA", {"NAME" => "test", "COLS" => "40", "ROWS" => "10"}, "")
+ end
- describe "when passed name, cols, rows" do
- it "returns an 'textarea'-element with the passed name, the passed amount of columns and the passed number of rows" do
- output = @html.textarea("test", 40, 5)
- output.should equal_element("TEXTAREA", {"NAME" => "test", "COLS" => "40", "ROWS" => "5"}, "")
+ it "includes the return value of the passed block when passed a block" do
+ output = @html.textarea("test", 40) { "Example" }
+ output.should equal_element("TEXTAREA", {"NAME" => "test", "COLS" => "40", "ROWS" => "10"}, "Example")
+ end
end
- it "includes the return value of the passed block when passed a block" do
- output = @html.textarea("test", 40, 5) { "Example" }
- output.should equal_element("TEXTAREA", {"NAME" => "test", "COLS" => "40", "ROWS" => "5"}, "Example")
+ describe "when passed name, cols, rows" do
+ it "returns an 'textarea'-element with the passed name, the passed amount of columns and the passed number of rows" do
+ output = @html.textarea("test", 40, 5)
+ output.should equal_element("TEXTAREA", {"NAME" => "test", "COLS" => "40", "ROWS" => "5"}, "")
+ end
+
+ it "includes the return value of the passed block when passed a block" do
+ output = @html.textarea("test", 40, 5) { "Example" }
+ output.should equal_element("TEXTAREA", {"NAME" => "test", "COLS" => "40", "ROWS" => "5"}, "Example")
+ end
end
- end
- describe "when passed Hash" do
- it "uses the passed Hash as attributes" do
- @html.textarea("ID" => "test").should == '<TEXTAREA ID="test"></TEXTAREA>'
+ describe "when passed Hash" do
+ it "uses the passed Hash as attributes" do
+ @html.textarea("ID" => "test").should == '<TEXTAREA ID="test"></TEXTAREA>'
- attributes = {"ID" => "test-id", "NAME" => "test-name"}
- output = @html.textarea(attributes)
- output.should equal_element("TEXTAREA", attributes, "")
- end
+ attributes = {"ID" => "test-id", "NAME" => "test-name"}
+ output = @html.textarea(attributes)
+ output.should equal_element("TEXTAREA", attributes, "")
+ end
- it "includes the return value of the passed block when passed a block" do
- attributes = {"ID" => "test-id", "NAME" => "test-name"}
- output = @html.textarea(attributes) { "test" }
- output.should equal_element("TEXTAREA", attributes, "test")
+ it "includes the return value of the passed block when passed a block" do
+ attributes = {"ID" => "test-id", "NAME" => "test-name"}
+ output = @html.textarea(attributes) { "test" }
+ output.should equal_element("TEXTAREA", attributes, "test")
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/http_header_spec.rb b/spec/ruby/library/cgi/http_header_spec.rb
index 1960d009e4..8d9f3fe9b8 100644
--- a/spec/ruby/library/cgi/http_header_spec.rb
+++ b/spec/ruby/library/cgi/http_header_spec.rb
@@ -1,8 +1,11 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require 'cgi'
+require_relative '../../spec_helper'
-require File.expand_path('../shared/http_header', __FILE__)
+ruby_version_is ""..."4.0" do
+ require 'cgi'
-describe "CGI#http_header" do
- it_behaves_like(:cgi_http_header, :http_header)
+ require_relative 'shared/http_header'
+
+ describe "CGI#http_header" do
+ it_behaves_like :cgi_http_header, :http_header
+ end
end
diff --git a/spec/ruby/library/cgi/initialize_spec.rb b/spec/ruby/library/cgi/initialize_spec.rb
index 6526aab5e8..6135522c54 100644
--- a/spec/ruby/library/cgi/initialize_spec.rb
+++ b/spec/ruby/library/cgi/initialize_spec.rb
@@ -1,133 +1,136 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require 'cgi'
+require_relative '../../spec_helper'
-describe "CGI#initialize" do
- it "is private" do
- CGI.should have_private_instance_method(:initialize)
- end
-end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
-describe "CGI#initialize when passed no arguments" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.allocate
- end
-
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- end
-
- it "extends self with CGI::QueryExtension" do
- @cgi.send(:initialize)
- @cgi.should be_kind_of(CGI::QueryExtension)
+ describe "CGI#initialize" do
+ it "is private" do
+ CGI.private_instance_methods(false).should.include?(:initialize)
+ end
end
- it "does not extend self with CGI::HtmlExtension" do
- @cgi.send(:initialize)
- @cgi.should_not be_kind_of(CGI::HtmlExtension)
- end
+ describe "CGI#initialize when passed no arguments" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.allocate
+ end
- it "does not extend self with any of the other HTML modules" do
- @cgi.send(:initialize)
- @cgi.should_not be_kind_of(CGI::Html3)
- @cgi.should_not be_kind_of(CGI::HtmlExtension)
- @cgi.should_not be_kind_of(CGI::Html4)
- @cgi.should_not be_kind_of(CGI::Html4Tr)
- @cgi.should_not be_kind_of(CGI::Html4Fr)
- end
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
- it "sets #cookies based on ENV['HTTP_COOKIE']" do
- begin
- old_env, ENV["HTTP_COOKIE"] = ENV["HTTP_COOKIE"], "test=test yay"
+ it "extends self with CGI::QueryExtension" do
@cgi.send(:initialize)
- @cgi.cookies.should == { "test"=>[ "test yay" ] }
- ensure
- ENV["HTTP_COOKIE"] = old_env
+ @cgi.should.is_a?(CGI::QueryExtension)
end
- end
- it "sets #params based on ENV['QUERY_STRING'] when ENV['REQUEST_METHOD'] is GET" do
- begin
- old_env_query, ENV["QUERY_STRING"] = ENV["QUERY_STRING"], "?test=a&test2=b"
- old_env_method, ENV["REQUEST_METHOD"] = ENV["REQUEST_METHOD"], "GET"
+ it "does not extend self with CGI::HtmlExtension" do
@cgi.send(:initialize)
- @cgi.params.should == { "test2" => ["b"], "?test" => ["a"] }
- ensure
- ENV["QUERY_STRING"] = old_env_query
- ENV["REQUEST_METHOD"] = old_env_method
+ @cgi.should_not.is_a?(CGI::HtmlExtension)
end
- end
- it "sets #params based on ENV['QUERY_STRING'] when ENV['REQUEST_METHOD'] is HEAD" do
- begin
- old_env_query, ENV["QUERY_STRING"] = ENV["QUERY_STRING"], "?test=a&test2=b"
- old_env_method, ENV["REQUEST_METHOD"] = ENV["REQUEST_METHOD"], "HEAD"
+ it "does not extend self with any of the other HTML modules" do
@cgi.send(:initialize)
- @cgi.params.should == { "test2" => ["b"], "?test" => ["a"] }
- ensure
- ENV["QUERY_STRING"] = old_env_query
- ENV["REQUEST_METHOD"] = old_env_method
+ @cgi.should_not.is_a?(CGI::HtmlExtension)
+ @cgi.should_not.is_a?(CGI::Html3)
+ @cgi.should_not.is_a?(CGI::Html4)
+ @cgi.should_not.is_a?(CGI::Html4Tr)
+ @cgi.should_not.is_a?(CGI::Html4Fr)
end
- end
-end
-describe "CGI#initialize when passed type" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.allocate
- end
+ it "sets #cookies based on ENV['HTTP_COOKIE']" do
+ begin
+ old_env, ENV["HTTP_COOKIE"] = ENV["HTTP_COOKIE"], "test=test yay"
+ @cgi.send(:initialize)
+ @cgi.cookies.should == { "test"=>[ "test yay" ] }
+ ensure
+ ENV["HTTP_COOKIE"] = old_env
+ end
+ end
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
+ it "sets #params based on ENV['QUERY_STRING'] when ENV['REQUEST_METHOD'] is GET" do
+ begin
+ old_env_query, ENV["QUERY_STRING"] = ENV["QUERY_STRING"], "?test=a&test2=b"
+ old_env_method, ENV["REQUEST_METHOD"] = ENV["REQUEST_METHOD"], "GET"
+ @cgi.send(:initialize)
+ @cgi.params.should == { "test2" => ["b"], "?test" => ["a"] }
+ ensure
+ ENV["QUERY_STRING"] = old_env_query
+ ENV["REQUEST_METHOD"] = old_env_method
+ end
+ end
+
+ it "sets #params based on ENV['QUERY_STRING'] when ENV['REQUEST_METHOD'] is HEAD" do
+ begin
+ old_env_query, ENV["QUERY_STRING"] = ENV["QUERY_STRING"], "?test=a&test2=b"
+ old_env_method, ENV["REQUEST_METHOD"] = ENV["REQUEST_METHOD"], "HEAD"
+ @cgi.send(:initialize)
+ @cgi.params.should == { "test2" => ["b"], "?test" => ["a"] }
+ ensure
+ ENV["QUERY_STRING"] = old_env_query
+ ENV["REQUEST_METHOD"] = old_env_method
+ end
+ end
end
+ describe "CGI#initialize when passed type" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.allocate
+ end
- it "extends self with CGI::QueryExtension" do
- @cgi.send(:initialize, "test")
- @cgi.should be_kind_of(CGI::QueryExtension)
- end
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
- it "extends self with CGI::QueryExtension, CGI::Html3 and CGI::HtmlExtension when the passed type is 'html3'" do
- @cgi.send(:initialize, "html3")
- @cgi.should be_kind_of(CGI::Html3)
- @cgi.should be_kind_of(CGI::HtmlExtension)
- @cgi.should be_kind_of(CGI::QueryExtension)
- @cgi.should_not be_kind_of(CGI::Html4)
- @cgi.should_not be_kind_of(CGI::Html4Tr)
- @cgi.should_not be_kind_of(CGI::Html4Fr)
- end
+ it "extends self with CGI::QueryExtension" do
+ @cgi.send(:initialize, "test")
+ @cgi.should.is_a?(CGI::QueryExtension)
+ end
- it "extends self with CGI::QueryExtension, CGI::Html4 and CGI::HtmlExtension when the passed type is 'html4'" do
- @cgi.send(:initialize, "html4")
- @cgi.should be_kind_of(CGI::Html4)
- @cgi.should be_kind_of(CGI::HtmlExtension)
- @cgi.should be_kind_of(CGI::QueryExtension)
+ it "extends self with CGI::QueryExtension, CGI::Html3 and CGI::HtmlExtension when the passed type is 'html3'" do
+ @cgi.send(:initialize, "html3")
+ @cgi.should.is_a?(CGI::Html3)
+ @cgi.should.is_a?(CGI::HtmlExtension)
+ @cgi.should.is_a?(CGI::QueryExtension)
- @cgi.should_not be_kind_of(CGI::Html3)
- @cgi.should_not be_kind_of(CGI::Html4Tr)
- @cgi.should_not be_kind_of(CGI::Html4Fr)
- end
+ @cgi.should_not.is_a?(CGI::Html4)
+ @cgi.should_not.is_a?(CGI::Html4Tr)
+ @cgi.should_not.is_a?(CGI::Html4Fr)
+ end
- it "extends self with CGI::QueryExtension, CGI::Html4Tr and CGI::HtmlExtension when the passed type is 'html4Tr'" do
- @cgi.send(:initialize, "html4Tr")
- @cgi.should be_kind_of(CGI::Html4Tr)
- @cgi.should be_kind_of(CGI::HtmlExtension)
- @cgi.should be_kind_of(CGI::QueryExtension)
+ it "extends self with CGI::QueryExtension, CGI::Html4 and CGI::HtmlExtension when the passed type is 'html4'" do
+ @cgi.send(:initialize, "html4")
+ @cgi.should.is_a?(CGI::Html4)
+ @cgi.should.is_a?(CGI::HtmlExtension)
+ @cgi.should.is_a?(CGI::QueryExtension)
- @cgi.should_not be_kind_of(CGI::Html3)
- @cgi.should_not be_kind_of(CGI::Html4)
- @cgi.should_not be_kind_of(CGI::Html4Fr)
- end
+ @cgi.should_not.is_a?(CGI::Html3)
+ @cgi.should_not.is_a?(CGI::Html4Tr)
+ @cgi.should_not.is_a?(CGI::Html4Fr)
+ end
- it "extends self with CGI::QueryExtension, CGI::Html4Tr, CGI::Html4Fr and CGI::HtmlExtension when the passed type is 'html4Fr'" do
- @cgi.send(:initialize, "html4Fr")
- @cgi.should be_kind_of(CGI::Html4Tr)
- @cgi.should be_kind_of(CGI::Html4Fr)
- @cgi.should be_kind_of(CGI::HtmlExtension)
- @cgi.should be_kind_of(CGI::QueryExtension)
+ it "extends self with CGI::QueryExtension, CGI::Html4Tr and CGI::HtmlExtension when the passed type is 'html4Tr'" do
+ @cgi.send(:initialize, "html4Tr")
+ @cgi.should.is_a?(CGI::Html4Tr)
+ @cgi.should.is_a?(CGI::HtmlExtension)
+ @cgi.should.is_a?(CGI::QueryExtension)
- @cgi.should_not be_kind_of(CGI::Html3)
- @cgi.should_not be_kind_of(CGI::Html4)
+ @cgi.should_not.is_a?(CGI::Html3)
+ @cgi.should_not.is_a?(CGI::Html4)
+ @cgi.should_not.is_a?(CGI::Html4Fr)
+ end
+
+ it "extends self with CGI::QueryExtension, CGI::Html4Tr, CGI::Html4Fr and CGI::HtmlExtension when the passed type is 'html4Fr'" do
+ @cgi.send(:initialize, "html4Fr")
+ @cgi.should.is_a?(CGI::Html4Tr)
+ @cgi.should.is_a?(CGI::Html4Fr)
+ @cgi.should.is_a?(CGI::HtmlExtension)
+ @cgi.should.is_a?(CGI::QueryExtension)
+
+ @cgi.should_not.is_a?(CGI::Html3)
+ @cgi.should_not.is_a?(CGI::Html4)
+ end
end
end
diff --git a/spec/ruby/library/cgi/out_spec.rb b/spec/ruby/library/cgi/out_spec.rb
index 05fe2662dc..e9eaf5e151 100644
--- a/spec/ruby/library/cgi/out_spec.rb
+++ b/spec/ruby/library/cgi/out_spec.rb
@@ -1,51 +1,54 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require 'cgi'
-
-describe "CGI#out" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.new
- $stdout, @old_stdout = IOStub.new, $stdout
- end
-
- after :each do
- $stdout = @old_stdout
- ENV['REQUEST_METHOD'] = @old_request_method
- end
-
- it "it writes a HTMl header based on the passed argument to $stdout" do
- @cgi.out { "" }
- $stdout.should == "Content-Type: text/html\r\nContent-Length: 0\r\n\r\n"
- end
-
- it "appends the block's return value to the HTML header" do
- @cgi.out { "test!" }
- $stdout.should == "Content-Type: text/html\r\nContent-Length: 5\r\n\r\ntest!"
- end
-
- it "automatically sets the Content-Length Header based on the block's return value" do
- @cgi.out { "0123456789" }
- $stdout.should == "Content-Type: text/html\r\nContent-Length: 10\r\n\r\n0123456789"
- end
-
- it "includes Cookies in the @output_cookies field" do
- @cgi.instance_variable_set(:@output_cookies, ["multiple", "cookies"])
- @cgi.out { "" }
- $stdout.should == "Content-Type: text/html\r\nContent-Length: 0\r\nSet-Cookie: multiple\r\nSet-Cookie: cookies\r\n\r\n"
- end
-end
-
-describe "CGI#out when passed no block" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.new
- end
-
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- end
-
- it "raises a LocalJumpError" do
- lambda { @cgi.out }.should raise_error(LocalJumpError)
+require_relative '../../spec_helper'
+
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+
+ describe "CGI#out" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ $stdout, @old_stdout = IOStub.new, $stdout
+ end
+
+ after :each do
+ $stdout = @old_stdout
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
+
+ it "it writes a HTMl header based on the passed argument to $stdout" do
+ @cgi.out { "" }
+ $stdout.should == "Content-Type: text/html\r\nContent-Length: 0\r\n\r\n"
+ end
+
+ it "appends the block's return value to the HTML header" do
+ @cgi.out { "test!" }
+ $stdout.should == "Content-Type: text/html\r\nContent-Length: 5\r\n\r\ntest!"
+ end
+
+ it "automatically sets the Content-Length Header based on the block's return value" do
+ @cgi.out { "0123456789" }
+ $stdout.should == "Content-Type: text/html\r\nContent-Length: 10\r\n\r\n0123456789"
+ end
+
+ it "includes Cookies in the @output_cookies field" do
+ @cgi.instance_variable_set(:@output_cookies, ["multiple", "cookies"])
+ @cgi.out { "" }
+ $stdout.should == "Content-Type: text/html\r\nContent-Length: 0\r\nSet-Cookie: multiple\r\nSet-Cookie: cookies\r\n\r\n"
+ end
+ end
+
+ describe "CGI#out when passed no block" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ end
+
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
+
+ it "raises a LocalJumpError" do
+ -> { @cgi.out }.should.raise(LocalJumpError)
+ end
end
end
diff --git a/spec/ruby/library/cgi/parse_spec.rb b/spec/ruby/library/cgi/parse_spec.rb
index 8f05c91c7b..f09270c195 100644
--- a/spec/ruby/library/cgi/parse_spec.rb
+++ b/spec/ruby/library/cgi/parse_spec.rb
@@ -1,24 +1,27 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require 'cgi'
+require_relative '../../spec_helper'
-describe "CGI.parse when passed String" do
- it "parses a HTTP Query String into a Hash" do
- CGI.parse("test=test&a=b").should == { "a" => ["b"], "test" => ["test"] }
- CGI.parse("test=1,2,3").should == { "test" => ["1,2,3"] }
- CGI.parse("test=a&a=&b=").should == { "test" => ["a"], "a" => [""], "b" => [""] }
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- it "parses query strings with semicolons in place of ampersands" do
- CGI.parse("test=test;a=b").should == { "a" => ["b"], "test" => ["test"] }
- CGI.parse("test=a;a=;b=").should == { "test" => ["a"], "a" => [""], "b" => [""] }
- end
+ describe "CGI.parse when passed String" do
+ it "parses a HTTP Query String into a Hash" do
+ CGI.parse("test=test&a=b").should == { "a" => ["b"], "test" => ["test"] }
+ CGI.parse("test=1,2,3").should == { "test" => ["1,2,3"] }
+ CGI.parse("test=a&a=&b=").should == { "test" => ["a"], "a" => [""], "b" => [""] }
+ end
- it "allows passing multiple values for one key" do
- CGI.parse("test=1&test=2&test=3").should == { "test" => ["1", "2", "3"] }
- CGI.parse("test[]=1&test[]=2&test[]=3").should == { "test[]" => [ "1", "2", "3" ] }
- end
+ it "parses query strings with semicolons in place of ampersands" do
+ CGI.parse("test=test;a=b").should == { "a" => ["b"], "test" => ["test"] }
+ CGI.parse("test=a;a=;b=").should == { "test" => ["a"], "a" => [""], "b" => [""] }
+ end
+
+ it "allows passing multiple values for one key" do
+ CGI.parse("test=1&test=2&test=3").should == { "test" => ["1", "2", "3"] }
+ CGI.parse("test[]=1&test[]=2&test[]=3").should == { "test[]" => [ "1", "2", "3" ] }
+ end
- it "unescapes keys and values" do
- CGI.parse("hello%3F=hello%21").should == { "hello?" => ["hello!"] }
+ it "unescapes keys and values" do
+ CGI.parse("hello%3F=hello%21").should == { "hello?" => ["hello!"] }
+ end
end
end
diff --git a/spec/ruby/library/cgi/pretty_spec.rb b/spec/ruby/library/cgi/pretty_spec.rb
index e09c327ef6..9df1611037 100644
--- a/spec/ruby/library/cgi/pretty_spec.rb
+++ b/spec/ruby/library/cgi/pretty_spec.rb
@@ -1,24 +1,27 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require 'cgi'
+require_relative '../../spec_helper'
-describe "CGI.pretty when passed html" do
- it "indents the passed html String with two spaces" do
- CGI.pretty("<HTML><BODY></BODY></HTML>").should == <<-EOS
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+
+ describe "CGI.pretty when passed html" do
+ it "indents the passed html String with two spaces" do
+ CGI.pretty("<HTML><BODY></BODY></HTML>").should == <<-EOS
<HTML>
<BODY>
</BODY>
</HTML>
EOS
+ end
end
-end
-describe "CGI.pretty when passed html, indentation_unit" do
- it "indents the passed html String with the passed indentation_unit" do
- CGI.pretty("<HTML><BODY></BODY></HTML>", "\t").should == <<-EOS
+ describe "CGI.pretty when passed html, indentation_unit" do
+ it "indents the passed html String with the passed indentation_unit" do
+ CGI.pretty("<HTML><BODY></BODY></HTML>", "\t").should == <<-EOS
<HTML>
\t<BODY>
\t</BODY>
</HTML>
EOS
+ end
end
end
diff --git a/spec/ruby/library/cgi/print_spec.rb b/spec/ruby/library/cgi/print_spec.rb
index 0db5efa0dd..f4f461c5c0 100644
--- a/spec/ruby/library/cgi/print_spec.rb
+++ b/spec/ruby/library/cgi/print_spec.rb
@@ -1,26 +1,29 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require 'cgi'
+require_relative '../../spec_helper'
-describe "CGI#print" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- end
+ describe "CGI#print" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ end
- it "passes all arguments to $stdout.print" do
- $stdout.should_receive(:print).with("test")
- @cgi.print("test")
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
- $stdout.should_receive(:print).with("one", "two", "three", ["four", "five"])
- @cgi.print("one", "two", "three", ["four", "five"])
- end
+ it "passes all arguments to $stdout.print" do
+ $stdout.should_receive(:print).with("test")
+ @cgi.print("test")
+
+ $stdout.should_receive(:print).with("one", "two", "three", ["four", "five"])
+ @cgi.print("one", "two", "three", ["four", "five"])
+ end
- it "returns the result of calling $stdout.print" do
- $stdout.should_receive(:print).with("test").and_return(:expected)
- @cgi.print("test").should == :expected
+ it "returns the result of calling $stdout.print" do
+ $stdout.should_receive(:print).with("test").and_return(:expected)
+ @cgi.print("test").should == :expected
+ end
end
end
diff --git a/spec/ruby/library/cgi/queryextension/accept_charset_spec.rb b/spec/ruby/library/cgi/queryextension/accept_charset_spec.rb
index be340b26f0..be05f0c175 100644
--- a/spec/ruby/library/cgi/queryextension/accept_charset_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/accept_charset_spec.rb
@@ -1,22 +1,25 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
+require_relative '../../../spec_helper'
-describe "CGI::QueryExtension#accept_charset" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- end
+ describe "CGI::QueryExtension#accept_charset" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ end
+
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
- it "returns ENV['HTTP_ACCEPT_CHARSET']" do
- old_value, ENV['HTTP_ACCEPT_CHARSET'] = ENV['HTTP_ACCEPT_CHARSET'], "ISO-8859-1,utf-8;q=0.7,*;q=0.7"
- begin
- @cgi.accept_charset.should == "ISO-8859-1,utf-8;q=0.7,*;q=0.7"
- ensure
- ENV['HTTP_ACCEPT_CHARSET'] = old_value
+ it "returns ENV['HTTP_ACCEPT_CHARSET']" do
+ old_value, ENV['HTTP_ACCEPT_CHARSET'] = ENV['HTTP_ACCEPT_CHARSET'], "ISO-8859-1,utf-8;q=0.7,*;q=0.7"
+ begin
+ @cgi.accept_charset.should == "ISO-8859-1,utf-8;q=0.7,*;q=0.7"
+ ensure
+ ENV['HTTP_ACCEPT_CHARSET'] = old_value
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/queryextension/accept_encoding_spec.rb b/spec/ruby/library/cgi/queryextension/accept_encoding_spec.rb
index a828ae7a42..42eb4a49b5 100644
--- a/spec/ruby/library/cgi/queryextension/accept_encoding_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/accept_encoding_spec.rb
@@ -1,22 +1,25 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
+require_relative '../../../spec_helper'
-describe "CGI::QueryExtension#accept_encoding" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- end
+ describe "CGI::QueryExtension#accept_encoding" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ end
+
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
- it "returns ENV['HTTP_ACCEPT_ENCODING']" do
- old_value, ENV['HTTP_ACCEPT_ENCODING'] = ENV['HTTP_ACCEPT_ENCODING'], "gzip,deflate"
- begin
- @cgi.accept_encoding.should == "gzip,deflate"
- ensure
- ENV['HTTP_ACCEPT_ENCODING'] = old_value
+ it "returns ENV['HTTP_ACCEPT_ENCODING']" do
+ old_value, ENV['HTTP_ACCEPT_ENCODING'] = ENV['HTTP_ACCEPT_ENCODING'], "gzip,deflate"
+ begin
+ @cgi.accept_encoding.should == "gzip,deflate"
+ ensure
+ ENV['HTTP_ACCEPT_ENCODING'] = old_value
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/queryextension/accept_language_spec.rb b/spec/ruby/library/cgi/queryextension/accept_language_spec.rb
index 77b4740251..19f29c6345 100644
--- a/spec/ruby/library/cgi/queryextension/accept_language_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/accept_language_spec.rb
@@ -1,22 +1,25 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
+require_relative '../../../spec_helper'
-describe "CGI::QueryExtension#accept_language" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- end
+ describe "CGI::QueryExtension#accept_language" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ end
+
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
- it "returns ENV['HTTP_ACCEPT_LANGUAGE']" do
- old_value, ENV['HTTP_ACCEPT_LANGUAGE'] = ENV['HTTP_ACCEPT_LANGUAGE'], "en-us,en;q=0.5"
- begin
- @cgi.accept_language.should == "en-us,en;q=0.5"
- ensure
- ENV['HTTP_ACCEPT_LANGUAGE'] = old_value
+ it "returns ENV['HTTP_ACCEPT_LANGUAGE']" do
+ old_value, ENV['HTTP_ACCEPT_LANGUAGE'] = ENV['HTTP_ACCEPT_LANGUAGE'], "en-us,en;q=0.5"
+ begin
+ @cgi.accept_language.should == "en-us,en;q=0.5"
+ ensure
+ ENV['HTTP_ACCEPT_LANGUAGE'] = old_value
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/queryextension/accept_spec.rb b/spec/ruby/library/cgi/queryextension/accept_spec.rb
index 0c7aa2ab1f..dcae39a736 100644
--- a/spec/ruby/library/cgi/queryextension/accept_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/accept_spec.rb
@@ -1,22 +1,25 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
+require_relative '../../../spec_helper'
-describe "CGI::QueryExtension#accept" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- end
+ describe "CGI::QueryExtension#accept" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ end
+
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
- it "returns ENV['HTTP_ACCEPT']" do
- old_value, ENV['HTTP_ACCEPT'] = ENV['HTTP_ACCEPT'], "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"
- begin
- @cgi.accept.should == "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"
- ensure
- ENV['HTTP_ACCEPT'] = old_value
+ it "returns ENV['HTTP_ACCEPT']" do
+ old_value, ENV['HTTP_ACCEPT'] = ENV['HTTP_ACCEPT'], "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"
+ begin
+ @cgi.accept.should == "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"
+ ensure
+ ENV['HTTP_ACCEPT'] = old_value
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/queryextension/auth_type_spec.rb b/spec/ruby/library/cgi/queryextension/auth_type_spec.rb
index 0ec2835053..75e9cdb27a 100644
--- a/spec/ruby/library/cgi/queryextension/auth_type_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/auth_type_spec.rb
@@ -1,22 +1,25 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
+require_relative '../../../spec_helper'
-describe "CGI::QueryExtension#auth_type" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- end
+ describe "CGI::QueryExtension#auth_type" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ end
+
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
- it "returns ENV['AUTH_TYPE']" do
- old_value, ENV['AUTH_TYPE'] = ENV['AUTH_TYPE'], "Basic"
- begin
- @cgi.auth_type.should == "Basic"
- ensure
- ENV['AUTH_TYPE'] = old_value
+ it "returns ENV['AUTH_TYPE']" do
+ old_value, ENV['AUTH_TYPE'] = ENV['AUTH_TYPE'], "Basic"
+ begin
+ @cgi.auth_type.should == "Basic"
+ ensure
+ ENV['AUTH_TYPE'] = old_value
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/queryextension/cache_control_spec.rb b/spec/ruby/library/cgi/queryextension/cache_control_spec.rb
index f1718b0871..c4b727e671 100644
--- a/spec/ruby/library/cgi/queryextension/cache_control_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/cache_control_spec.rb
@@ -1,22 +1,25 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
+require_relative '../../../spec_helper'
-describe "CGI::QueryExtension#cache_control" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- end
+ describe "CGI::QueryExtension#cache_control" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ end
+
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
- it "returns ENV['HTTP_CACHE_CONTROL']" do
- old_value, ENV['HTTP_CACHE_CONTROL'] = ENV['HTTP_CACHE_CONTROL'], "no-cache"
- begin
- @cgi.cache_control.should == "no-cache"
- ensure
- ENV['HTTP_CACHE_CONTROL'] = old_value
+ it "returns ENV['HTTP_CACHE_CONTROL']" do
+ old_value, ENV['HTTP_CACHE_CONTROL'] = ENV['HTTP_CACHE_CONTROL'], "no-cache"
+ begin
+ @cgi.cache_control.should == "no-cache"
+ ensure
+ ENV['HTTP_CACHE_CONTROL'] = old_value
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/queryextension/content_length_spec.rb b/spec/ruby/library/cgi/queryextension/content_length_spec.rb
index c9f0708f69..bd02f3d8da 100644
--- a/spec/ruby/library/cgi/queryextension/content_length_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/content_length_spec.rb
@@ -1,26 +1,29 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
+require_relative '../../../spec_helper'
-describe "CGI::QueryExtension#content_length" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- end
+ describe "CGI::QueryExtension#content_length" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ end
+
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
- it "returns ENV['CONTENT_LENGTH'] as Integer" do
- old_value = ENV['CONTENT_LENGTH']
- begin
- ENV['CONTENT_LENGTH'] = nil
- @cgi.content_length.should be_nil
+ it "returns ENV['CONTENT_LENGTH'] as Integer" do
+ old_value = ENV['CONTENT_LENGTH']
+ begin
+ ENV['CONTENT_LENGTH'] = nil
+ @cgi.content_length.should == nil
- ENV['CONTENT_LENGTH'] = "100"
- @cgi.content_length.should eql(100)
- ensure
- ENV['CONTENT_LENGTH'] = old_value
+ ENV['CONTENT_LENGTH'] = "100"
+ @cgi.content_length.should.eql?(100)
+ ensure
+ ENV['CONTENT_LENGTH'] = old_value
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/queryextension/content_type_spec.rb b/spec/ruby/library/cgi/queryextension/content_type_spec.rb
index a65b0a6103..d3cbdf0b14 100644
--- a/spec/ruby/library/cgi/queryextension/content_type_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/content_type_spec.rb
@@ -1,22 +1,25 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
+require_relative '../../../spec_helper'
-describe "CGI::QueryExtension#content_type" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- end
+ describe "CGI::QueryExtension#content_type" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ end
+
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
- it "returns ENV['CONTENT_TYPE']" do
- old_value, ENV['CONTENT_TYPE'] = ENV['CONTENT_TYPE'], "text/html"
- begin
- @cgi.content_type.should == "text/html"
- ensure
- ENV['CONTENT_TYPE'] = old_value
+ it "returns ENV['CONTENT_TYPE']" do
+ old_value, ENV['CONTENT_TYPE'] = ENV['CONTENT_TYPE'], "text/html"
+ begin
+ @cgi.content_type.should == "text/html"
+ ensure
+ ENV['CONTENT_TYPE'] = old_value
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/queryextension/cookies_spec.rb b/spec/ruby/library/cgi/queryextension/cookies_spec.rb
index 5df457f11c..266fe0c721 100644
--- a/spec/ruby/library/cgi/queryextension/cookies_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/cookies_spec.rb
@@ -1,10 +1,13 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
+require_relative '../../../spec_helper'
-describe "CGI::QueryExtension#cookies" do
- it "needs to be reviewed for spec completeness"
-end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+
+ describe "CGI::QueryExtension#cookies" do
+ it "needs to be reviewed for spec completeness"
+ end
-describe "CGI::QueryExtension#cookies=" do
- it "needs to be reviewed for spec completeness"
+ describe "CGI::QueryExtension#cookies=" do
+ it "needs to be reviewed for spec completeness"
+ end
end
diff --git a/spec/ruby/library/cgi/queryextension/element_reference_spec.rb b/spec/ruby/library/cgi/queryextension/element_reference_spec.rb
index 4aabfaa277..c835f385f0 100644
--- a/spec/ruby/library/cgi/queryextension/element_reference_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/element_reference_spec.rb
@@ -1,27 +1,30 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
+require_relative '../../../spec_helper'
-describe "CGI::QueryExtension#[]" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- ENV['QUERY_STRING'], @old_query_string = "one=a&two=b&two=c", ENV['QUERY_STRING']
- @cgi = CGI.new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- ENV['QUERY_STRING'] = @old_query_string
- end
+ describe "CGI::QueryExtension#[]" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ ENV['QUERY_STRING'], @old_query_string = "one=a&two=b&two=c", ENV['QUERY_STRING']
+ @cgi = CGI.new
+ end
- it "it returns the value for the parameter with the given key" do
- @cgi["one"].should == "a"
- end
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ ENV['QUERY_STRING'] = @old_query_string
+ end
- it "only returns the first value for parameters with multiple values" do
- @cgi["two"].should == "b"
- end
+ it "it returns the value for the parameter with the given key" do
+ @cgi["one"].should == "a"
+ end
+
+ it "only returns the first value for parameters with multiple values" do
+ @cgi["two"].should == "b"
+ end
- it "returns a String" do
- @cgi["one"].should be_kind_of(String)
+ it "returns a String" do
+ @cgi["one"].should.is_a?(String)
+ end
end
end
diff --git a/spec/ruby/library/cgi/queryextension/from_spec.rb b/spec/ruby/library/cgi/queryextension/from_spec.rb
index aabd9b9bb3..b341e0be10 100644
--- a/spec/ruby/library/cgi/queryextension/from_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/from_spec.rb
@@ -1,22 +1,25 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
+require_relative '../../../spec_helper'
-describe "CGI::QueryExtension#from" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- end
+ describe "CGI::QueryExtension#from" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ end
+
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
- it "returns ENV['HTTP_FROM']" do
- old_value, ENV['HTTP_FROM'] = ENV['HTTP_FROM'], "googlebot(at)googlebot.com"
- begin
- @cgi.from.should == "googlebot(at)googlebot.com"
- ensure
- ENV['HTTP_FROM'] = old_value
+ it "returns ENV['HTTP_FROM']" do
+ old_value, ENV['HTTP_FROM'] = ENV['HTTP_FROM'], "googlebot(at)googlebot.com"
+ begin
+ @cgi.from.should == "googlebot(at)googlebot.com"
+ ensure
+ ENV['HTTP_FROM'] = old_value
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/queryextension/gateway_interface_spec.rb b/spec/ruby/library/cgi/queryextension/gateway_interface_spec.rb
index 8b006063d8..c82522326b 100644
--- a/spec/ruby/library/cgi/queryextension/gateway_interface_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/gateway_interface_spec.rb
@@ -1,22 +1,25 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
+require_relative '../../../spec_helper'
-describe "CGI::QueryExtension#gateway_interface" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- end
+ describe "CGI::QueryExtension#gateway_interface" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ end
+
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
- it "returns ENV['GATEWAY_INTERFACE']" do
- old_value, ENV['GATEWAY_INTERFACE'] = ENV['GATEWAY_INTERFACE'], "CGI/1.1"
- begin
- @cgi.gateway_interface.should == "CGI/1.1"
- ensure
- ENV['GATEWAY_INTERFACE'] = old_value
+ it "returns ENV['GATEWAY_INTERFACE']" do
+ old_value, ENV['GATEWAY_INTERFACE'] = ENV['GATEWAY_INTERFACE'], "CGI/1.1"
+ begin
+ @cgi.gateway_interface.should == "CGI/1.1"
+ ensure
+ ENV['GATEWAY_INTERFACE'] = old_value
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/queryextension/has_key_spec.rb b/spec/ruby/library/cgi/queryextension/has_key_spec.rb
index 86ec3d0a29..43f7aae1b2 100644
--- a/spec/ruby/library/cgi/queryextension/has_key_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/has_key_spec.rb
@@ -1,7 +1,10 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
-require File.expand_path('../shared/has_key', __FILE__)
+require_relative '../../../spec_helper'
-describe "CGI::QueryExtension#has_key?" do
- it_behaves_like :cgi_query_extension_has_key_p, :has_key?
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+ require_relative 'shared/has_key'
+
+ describe "CGI::QueryExtension#has_key?" do
+ it_behaves_like :cgi_query_extension_has_key_p, :has_key?
+ end
end
diff --git a/spec/ruby/library/cgi/queryextension/host_spec.rb b/spec/ruby/library/cgi/queryextension/host_spec.rb
index 89e2610ba7..e1047c942b 100644
--- a/spec/ruby/library/cgi/queryextension/host_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/host_spec.rb
@@ -1,22 +1,25 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
+require_relative '../../../spec_helper'
-describe "CGI::QueryExtension#host" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- end
+ describe "CGI::QueryExtension#host" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ end
+
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
- it "returns ENV['HTTP_HOST']" do
- old_value, ENV['HTTP_HOST'] = ENV['HTTP_HOST'], "localhost"
- begin
- @cgi.host.should == "localhost"
- ensure
- ENV['HTTP_HOST'] = old_value
+ it "returns ENV['HTTP_HOST']" do
+ old_value, ENV['HTTP_HOST'] = ENV['HTTP_HOST'], "localhost"
+ begin
+ @cgi.host.should == "localhost"
+ ensure
+ ENV['HTTP_HOST'] = old_value
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/queryextension/include_spec.rb b/spec/ruby/library/cgi/queryextension/include_spec.rb
index e8f1bf14ec..7275c309f9 100644
--- a/spec/ruby/library/cgi/queryextension/include_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/include_spec.rb
@@ -1,7 +1,10 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
-require File.expand_path('../shared/has_key', __FILE__)
+require_relative '../../../spec_helper'
-describe "CGI::QueryExtension#include?" do
- it_behaves_like :cgi_query_extension_has_key_p, :include?
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+ require_relative 'shared/has_key'
+
+ describe "CGI::QueryExtension#include?" do
+ it_behaves_like :cgi_query_extension_has_key_p, :include?
+ end
end
diff --git a/spec/ruby/library/cgi/queryextension/key_spec.rb b/spec/ruby/library/cgi/queryextension/key_spec.rb
index 525a0210b2..dc2f52fbe0 100644
--- a/spec/ruby/library/cgi/queryextension/key_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/key_spec.rb
@@ -1,7 +1,10 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
-require File.expand_path('../shared/has_key', __FILE__)
+require_relative '../../../spec_helper'
-describe "CGI::QueryExtension#key?" do
- it_behaves_like :cgi_query_extension_has_key_p, :key?
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+ require_relative 'shared/has_key'
+
+ describe "CGI::QueryExtension#key?" do
+ it_behaves_like :cgi_query_extension_has_key_p, :key?
+ end
end
diff --git a/spec/ruby/library/cgi/queryextension/keys_spec.rb b/spec/ruby/library/cgi/queryextension/keys_spec.rb
index f60b1fb369..bb16914065 100644
--- a/spec/ruby/library/cgi/queryextension/keys_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/keys_spec.rb
@@ -1,20 +1,23 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
+require_relative '../../../spec_helper'
-describe "CGI::QueryExtension#keys" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- ENV['QUERY_STRING'], @old_query_string = "one=a&two=b", ENV['QUERY_STRING']
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- @cgi = CGI.new
- end
+ describe "CGI::QueryExtension#keys" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ ENV['QUERY_STRING'], @old_query_string = "one=a&two=b", ENV['QUERY_STRING']
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- ENV['QUERY_STRING'] = @old_query_string
- end
+ @cgi = CGI.new
+ end
+
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ ENV['QUERY_STRING'] = @old_query_string
+ end
- it "returns all parameter keys as an Array" do
- @cgi.keys.sort.should == ["one", "two"]
+ it "returns all parameter keys as an Array" do
+ @cgi.keys.sort.should == ["one", "two"]
+ end
end
end
diff --git a/spec/ruby/library/cgi/queryextension/multipart_spec.rb b/spec/ruby/library/cgi/queryextension/multipart_spec.rb
index 021c847fa3..1fa771ca1c 100644
--- a/spec/ruby/library/cgi/queryextension/multipart_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/multipart_spec.rb
@@ -1,20 +1,22 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
-require "stringio"
+require_relative '../../../spec_helper'
-describe "CGI::QueryExtension#multipart?" do
- before :each do
- @old_stdin = $stdin
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+ require "stringio"
- @old_request_method = ENV['REQUEST_METHOD']
- @old_content_type = ENV['CONTENT_TYPE']
- @old_content_length = ENV['CONTENT_LENGTH']
+ describe "CGI::QueryExtension#multipart?" do
+ before :each do
+ @old_stdin = $stdin
- ENV['REQUEST_METHOD'] = "POST"
- ENV["CONTENT_TYPE"] = "multipart/form-data; boundary=---------------------------1137522503144128232716531729"
- ENV["CONTENT_LENGTH"] = "222"
+ @old_request_method = ENV['REQUEST_METHOD']
+ @old_content_type = ENV['CONTENT_TYPE']
+ @old_content_length = ENV['CONTENT_LENGTH']
- $stdin = StringIO.new <<-EOS
+ ENV['REQUEST_METHOD'] = "POST"
+ ENV["CONTENT_TYPE"] = "multipart/form-data; boundary=---------------------------1137522503144128232716531729"
+ ENV["CONTENT_LENGTH"] = "222"
+
+ $stdin = StringIO.new <<-EOS
-----------------------------1137522503144128232716531729\r
Content-Disposition: form-data; name="file"; filename=""\r
Content-Type: application/octet-stream\r
@@ -23,18 +25,19 @@ Content-Type: application/octet-stream\r
-----------------------------1137522503144128232716531729--\r
EOS
- @cgi = CGI.new
- end
+ @cgi = CGI.new
+ end
- after :each do
- $stdin = @old_stdin
+ after :each do
+ $stdin = @old_stdin
- ENV['REQUEST_METHOD'] = @old_request_method
- ENV['CONTENT_TYPE'] = @old_content_type
- ENV['CONTENT_LENGTH'] = @old_content_length
- end
+ ENV['REQUEST_METHOD'] = @old_request_method
+ ENV['CONTENT_TYPE'] = @old_content_type
+ ENV['CONTENT_LENGTH'] = @old_content_length
+ end
- it "returns true if the current Request is a multipart request" do
- @cgi.multipart?.should be_true
+ it "returns true if the current Request is a multipart request" do
+ @cgi.multipart?.should == true
+ end
end
end
diff --git a/spec/ruby/library/cgi/queryextension/negotiate_spec.rb b/spec/ruby/library/cgi/queryextension/negotiate_spec.rb
index 503ae583bf..4083e6a8cd 100644
--- a/spec/ruby/library/cgi/queryextension/negotiate_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/negotiate_spec.rb
@@ -1,22 +1,25 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
+require_relative '../../../spec_helper'
-describe "CGI::QueryExtension#negotiate" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- end
+ describe "CGI::QueryExtension#negotiate" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ end
+
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
- it "returns ENV['HTTP_NEGOTIATE']" do
- old_value, ENV['HTTP_NEGOTIATE'] = ENV['HTTP_NEGOTIATE'], "trans"
- begin
- @cgi.negotiate.should == "trans"
- ensure
- ENV['HTTP_NEGOTIATE'] = old_value
+ it "returns ENV['HTTP_NEGOTIATE']" do
+ old_value, ENV['HTTP_NEGOTIATE'] = ENV['HTTP_NEGOTIATE'], "trans"
+ begin
+ @cgi.negotiate.should == "trans"
+ ensure
+ ENV['HTTP_NEGOTIATE'] = old_value
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/queryextension/params_spec.rb b/spec/ruby/library/cgi/queryextension/params_spec.rb
index 6d47b3eeee..938028ea14 100644
--- a/spec/ruby/library/cgi/queryextension/params_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/params_spec.rb
@@ -1,37 +1,40 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
-
-describe "CGI::QueryExtension#params" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- ENV['QUERY_STRING'], @old_query_string = "one=a&two=b&two=c&three", ENV['QUERY_STRING']
- @cgi = CGI.new
- end
+require_relative '../../../spec_helper'
- after :each do
- ENV['QUERY_STRING'] = @old_query_string
- ENV['REQUEST_METHOD'] = @old_request_method
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- it "returns the parsed HTTP Query Params" do
- @cgi.params.should == {"three"=>[], "two"=>["b", "c"], "one"=>["a"]}
- end
-end
+ describe "CGI::QueryExtension#params" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ ENV['QUERY_STRING'], @old_query_string = "one=a&two=b&two=c&three", ENV['QUERY_STRING']
+ @cgi = CGI.new
+ end
-describe "CGI::QueryExtension#params=" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.new
- end
+ after :each do
+ ENV['QUERY_STRING'] = @old_query_string
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
+ it "returns the parsed HTTP Query Params" do
+ @cgi.params.should == {"three"=>[], "two"=>["b", "c"], "one"=>["a"]}
+ end
end
- it "sets the HTTP Query Params to the passed argument" do
- @cgi.params.should == {}
+ describe "CGI::QueryExtension#params=" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ end
+
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
+
+ it "sets the HTTP Query Params to the passed argument" do
+ @cgi.params.should == {}
- @cgi.params = {"one"=>["a"], "two"=>["b", "c"]}
- @cgi.params.should == {"one"=>["a"], "two"=>["b", "c"]}
+ @cgi.params = {"one"=>["a"], "two"=>["b", "c"]}
+ @cgi.params.should == {"one"=>["a"], "two"=>["b", "c"]}
+ end
end
end
diff --git a/spec/ruby/library/cgi/queryextension/path_info_spec.rb b/spec/ruby/library/cgi/queryextension/path_info_spec.rb
index 8c8af27fc9..9b7834c514 100644
--- a/spec/ruby/library/cgi/queryextension/path_info_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/path_info_spec.rb
@@ -1,22 +1,25 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
+require_relative '../../../spec_helper'
-describe "CGI::QueryExtension#path_info" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- end
+ describe "CGI::QueryExtension#path_info" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ end
+
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
- it "returns ENV['PATH_INFO']" do
- old_value, ENV['PATH_INFO'] = ENV['PATH_INFO'], "/test/path"
- begin
- @cgi.path_info.should == "/test/path"
- ensure
- ENV['PATH_INFO'] = old_value
+ it "returns ENV['PATH_INFO']" do
+ old_value, ENV['PATH_INFO'] = ENV['PATH_INFO'], "/test/path"
+ begin
+ @cgi.path_info.should == "/test/path"
+ ensure
+ ENV['PATH_INFO'] = old_value
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/queryextension/path_translated_spec.rb b/spec/ruby/library/cgi/queryextension/path_translated_spec.rb
index 6e9db707b3..a773aaafdb 100644
--- a/spec/ruby/library/cgi/queryextension/path_translated_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/path_translated_spec.rb
@@ -1,22 +1,25 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
+require_relative '../../../spec_helper'
-describe "CGI::QueryExtension#path_translated" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- end
+ describe "CGI::QueryExtension#path_translated" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ end
+
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
- it "returns ENV['PATH_TRANSLATED']" do
- old_value, ENV['PATH_TRANSLATED'] = ENV['PATH_TRANSLATED'], "/full/path/to/dir"
- begin
- @cgi.path_translated.should == "/full/path/to/dir"
- ensure
- ENV['PATH_TRANSLATED'] = old_value
+ it "returns ENV['PATH_TRANSLATED']" do
+ old_value, ENV['PATH_TRANSLATED'] = ENV['PATH_TRANSLATED'], "/full/path/to/dir"
+ begin
+ @cgi.path_translated.should == "/full/path/to/dir"
+ ensure
+ ENV['PATH_TRANSLATED'] = old_value
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/queryextension/pragma_spec.rb b/spec/ruby/library/cgi/queryextension/pragma_spec.rb
index c0c7b20514..be384182a5 100644
--- a/spec/ruby/library/cgi/queryextension/pragma_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/pragma_spec.rb
@@ -1,22 +1,25 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
+require_relative '../../../spec_helper'
-describe "CGI::QueryExtension#pragma" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- end
+ describe "CGI::QueryExtension#pragma" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ end
+
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
- it "returns ENV['HTTP_PRAGMA']" do
- old_value, ENV['HTTP_PRAGMA'] = ENV['HTTP_PRAGMA'], "no-cache"
- begin
- @cgi.pragma.should == "no-cache"
- ensure
- ENV['HTTP_PRAGMA'] = old_value
+ it "returns ENV['HTTP_PRAGMA']" do
+ old_value, ENV['HTTP_PRAGMA'] = ENV['HTTP_PRAGMA'], "no-cache"
+ begin
+ @cgi.pragma.should == "no-cache"
+ ensure
+ ENV['HTTP_PRAGMA'] = old_value
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/queryextension/query_string_spec.rb b/spec/ruby/library/cgi/queryextension/query_string_spec.rb
index 1065bac7ef..64fbeaea10 100644
--- a/spec/ruby/library/cgi/queryextension/query_string_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/query_string_spec.rb
@@ -1,22 +1,25 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
+require_relative '../../../spec_helper'
-describe "CGI::QueryExtension#query_string" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- end
+ describe "CGI::QueryExtension#query_string" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ end
+
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
- it "returns ENV['QUERY_STRING']" do
- old_value, ENV['QUERY_STRING'] = ENV['QUERY_STRING'], "one=a&two=b"
- begin
- @cgi.query_string.should == "one=a&two=b"
- ensure
- ENV['QUERY_STRING'] = old_value
+ it "returns ENV['QUERY_STRING']" do
+ old_value, ENV['QUERY_STRING'] = ENV['QUERY_STRING'], "one=a&two=b"
+ begin
+ @cgi.query_string.should == "one=a&two=b"
+ ensure
+ ENV['QUERY_STRING'] = old_value
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/queryextension/raw_cookie2_spec.rb b/spec/ruby/library/cgi/queryextension/raw_cookie2_spec.rb
index 84b0e0c0dc..30d314aca1 100644
--- a/spec/ruby/library/cgi/queryextension/raw_cookie2_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/raw_cookie2_spec.rb
@@ -1,22 +1,25 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
+require_relative '../../../spec_helper'
-describe "CGI::QueryExtension#raw_cookie2" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- end
+ describe "CGI::QueryExtension#raw_cookie2" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ end
+
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
- it "returns ENV['HTTP_COOKIE2']" do
- old_value, ENV['HTTP_COOKIE2'] = ENV['HTTP_COOKIE2'], "some_cookie=data"
- begin
- @cgi.raw_cookie2.should == "some_cookie=data"
- ensure
- ENV['HTTP_COOKIE2'] = old_value
+ it "returns ENV['HTTP_COOKIE2']" do
+ old_value, ENV['HTTP_COOKIE2'] = ENV['HTTP_COOKIE2'], "some_cookie=data"
+ begin
+ @cgi.raw_cookie2.should == "some_cookie=data"
+ ensure
+ ENV['HTTP_COOKIE2'] = old_value
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/queryextension/raw_cookie_spec.rb b/spec/ruby/library/cgi/queryextension/raw_cookie_spec.rb
index 096bcf9fab..affa504b39 100644
--- a/spec/ruby/library/cgi/queryextension/raw_cookie_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/raw_cookie_spec.rb
@@ -1,22 +1,25 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
+require_relative '../../../spec_helper'
-describe "CGI::QueryExtension#raw_cookie" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- end
+ describe "CGI::QueryExtension#raw_cookie" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ end
+
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
- it "returns ENV['HTTP_COOKIE']" do
- old_value, ENV['HTTP_COOKIE'] = ENV['HTTP_COOKIE'], "some_cookie=data"
- begin
- @cgi.raw_cookie.should == "some_cookie=data"
- ensure
- ENV['HTTP_COOKIE'] = old_value
+ it "returns ENV['HTTP_COOKIE']" do
+ old_value, ENV['HTTP_COOKIE'] = ENV['HTTP_COOKIE'], "some_cookie=data"
+ begin
+ @cgi.raw_cookie.should == "some_cookie=data"
+ ensure
+ ENV['HTTP_COOKIE'] = old_value
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/queryextension/referer_spec.rb b/spec/ruby/library/cgi/queryextension/referer_spec.rb
index d52b3a501a..53fc19ddd0 100644
--- a/spec/ruby/library/cgi/queryextension/referer_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/referer_spec.rb
@@ -1,22 +1,25 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
+require_relative '../../../spec_helper'
-describe "CGI::QueryExtension#referer" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- end
+ describe "CGI::QueryExtension#referer" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ end
+
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
- it "returns ENV['HTTP_REFERER']" do
- old_value, ENV['HTTP_REFERER'] = ENV['HTTP_REFERER'], "example.com"
- begin
- @cgi.referer.should == "example.com"
- ensure
- ENV['HTTP_REFERER'] = old_value
+ it "returns ENV['HTTP_REFERER']" do
+ old_value, ENV['HTTP_REFERER'] = ENV['HTTP_REFERER'], "example.com"
+ begin
+ @cgi.referer.should == "example.com"
+ ensure
+ ENV['HTTP_REFERER'] = old_value
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/queryextension/remote_addr_spec.rb b/spec/ruby/library/cgi/queryextension/remote_addr_spec.rb
index dc94e2c953..7b5addc2d5 100644
--- a/spec/ruby/library/cgi/queryextension/remote_addr_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/remote_addr_spec.rb
@@ -1,22 +1,25 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
+require_relative '../../../spec_helper'
-describe "CGI::QueryExtension#remote_addr" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- end
+ describe "CGI::QueryExtension#remote_addr" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ end
+
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
- it "returns ENV['REMOTE_ADDR']" do
- old_value, ENV['REMOTE_ADDR'] = ENV['REMOTE_ADDR'], "127.0.0.1"
- begin
- @cgi.remote_addr.should == "127.0.0.1"
- ensure
- ENV['REMOTE_ADDR'] = old_value
+ it "returns ENV['REMOTE_ADDR']" do
+ old_value, ENV['REMOTE_ADDR'] = ENV['REMOTE_ADDR'], "127.0.0.1"
+ begin
+ @cgi.remote_addr.should == "127.0.0.1"
+ ensure
+ ENV['REMOTE_ADDR'] = old_value
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/queryextension/remote_host_spec.rb b/spec/ruby/library/cgi/queryextension/remote_host_spec.rb
index f62664b9a7..2dfe59ca38 100644
--- a/spec/ruby/library/cgi/queryextension/remote_host_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/remote_host_spec.rb
@@ -1,22 +1,25 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
+require_relative '../../../spec_helper'
-describe "CGI::QueryExtension#remote_host" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- end
+ describe "CGI::QueryExtension#remote_host" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ end
+
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
- it "returns ENV['REMOTE_HOST']" do
- old_value, ENV['REMOTE_HOST'] = ENV['REMOTE_HOST'], "test.host"
- begin
- @cgi.remote_host.should == "test.host"
- ensure
- ENV['REMOTE_HOST'] = old_value
+ it "returns ENV['REMOTE_HOST']" do
+ old_value, ENV['REMOTE_HOST'] = ENV['REMOTE_HOST'], "test.host"
+ begin
+ @cgi.remote_host.should == "test.host"
+ ensure
+ ENV['REMOTE_HOST'] = old_value
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/queryextension/remote_ident_spec.rb b/spec/ruby/library/cgi/queryextension/remote_ident_spec.rb
index 3aab059a7e..bb05fc7942 100644
--- a/spec/ruby/library/cgi/queryextension/remote_ident_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/remote_ident_spec.rb
@@ -1,22 +1,25 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
+require_relative '../../../spec_helper'
-describe "CGI::QueryExtension#remote_ident" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- end
+ describe "CGI::QueryExtension#remote_ident" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ end
+
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
- it "returns ENV['REMOTE_IDENT']" do
- old_value, ENV['REMOTE_IDENT'] = ENV['REMOTE_IDENT'], "no-idea-what-this-is-for"
- begin
- @cgi.remote_ident.should == "no-idea-what-this-is-for"
- ensure
- ENV['REMOTE_IDENT'] = old_value
+ it "returns ENV['REMOTE_IDENT']" do
+ old_value, ENV['REMOTE_IDENT'] = ENV['REMOTE_IDENT'], "no-idea-what-this-is-for"
+ begin
+ @cgi.remote_ident.should == "no-idea-what-this-is-for"
+ ensure
+ ENV['REMOTE_IDENT'] = old_value
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/queryextension/remote_user_spec.rb b/spec/ruby/library/cgi/queryextension/remote_user_spec.rb
index 5aae6bc755..29856302ab 100644
--- a/spec/ruby/library/cgi/queryextension/remote_user_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/remote_user_spec.rb
@@ -1,22 +1,25 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
+require_relative '../../../spec_helper'
-describe "CGI::QueryExtension#remote_user" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- end
+ describe "CGI::QueryExtension#remote_user" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ end
+
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
- it "returns ENV['REMOTE_USER']" do
- old_value, ENV['REMOTE_USER'] = ENV['REMOTE_USER'], "username"
- begin
- @cgi.remote_user.should == "username"
- ensure
- ENV['REMOTE_USER'] = old_value
+ it "returns ENV['REMOTE_USER']" do
+ old_value, ENV['REMOTE_USER'] = ENV['REMOTE_USER'], "username"
+ begin
+ @cgi.remote_user.should == "username"
+ ensure
+ ENV['REMOTE_USER'] = old_value
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/queryextension/request_method_spec.rb b/spec/ruby/library/cgi/queryextension/request_method_spec.rb
index 7fa85a3b34..7331b134d2 100644
--- a/spec/ruby/library/cgi/queryextension/request_method_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/request_method_spec.rb
@@ -1,22 +1,25 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
+require_relative '../../../spec_helper'
-describe "CGI::QueryExtension#request_method" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- end
+ describe "CGI::QueryExtension#request_method" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ end
+
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
- it "returns ENV['REQUEST_METHOD']" do
- old_value, ENV['REQUEST_METHOD'] = ENV['REQUEST_METHOD'], "GET"
- begin
- @cgi.request_method.should == "GET"
- ensure
- ENV['REQUEST_METHOD'] = old_value
+ it "returns ENV['REQUEST_METHOD']" do
+ old_value, ENV['REQUEST_METHOD'] = ENV['REQUEST_METHOD'], "GET"
+ begin
+ @cgi.request_method.should == "GET"
+ ensure
+ ENV['REQUEST_METHOD'] = old_value
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/queryextension/script_name_spec.rb b/spec/ruby/library/cgi/queryextension/script_name_spec.rb
index 7509e002d4..4b359a545f 100644
--- a/spec/ruby/library/cgi/queryextension/script_name_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/script_name_spec.rb
@@ -1,22 +1,25 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
+require_relative '../../../spec_helper'
-describe "CGI::QueryExtension#script_name" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- end
+ describe "CGI::QueryExtension#script_name" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ end
+
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
- it "returns ENV['SCRIPT_NAME']" do
- old_value, ENV['SCRIPT_NAME'] = ENV['SCRIPT_NAME'], "/path/to/script.rb"
- begin
- @cgi.script_name.should == "/path/to/script.rb"
- ensure
- ENV['SCRIPT_NAME'] = old_value
+ it "returns ENV['SCRIPT_NAME']" do
+ old_value, ENV['SCRIPT_NAME'] = ENV['SCRIPT_NAME'], "/path/to/script.rb"
+ begin
+ @cgi.script_name.should == "/path/to/script.rb"
+ ensure
+ ENV['SCRIPT_NAME'] = old_value
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/queryextension/server_name_spec.rb b/spec/ruby/library/cgi/queryextension/server_name_spec.rb
index acc8f9e4aa..c1f7fb4c54 100644
--- a/spec/ruby/library/cgi/queryextension/server_name_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/server_name_spec.rb
@@ -1,22 +1,25 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
+require_relative '../../../spec_helper'
-describe "CGI::QueryExtension#server_name" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- end
+ describe "CGI::QueryExtension#server_name" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ end
+
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
- it "returns ENV['SERVER_NAME']" do
- old_value, ENV['SERVER_NAME'] = ENV['SERVER_NAME'], "localhost"
- begin
- @cgi.server_name.should == "localhost"
- ensure
- ENV['SERVER_NAME'] = old_value
+ it "returns ENV['SERVER_NAME']" do
+ old_value, ENV['SERVER_NAME'] = ENV['SERVER_NAME'], "localhost"
+ begin
+ @cgi.server_name.should == "localhost"
+ ensure
+ ENV['SERVER_NAME'] = old_value
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/queryextension/server_port_spec.rb b/spec/ruby/library/cgi/queryextension/server_port_spec.rb
index adeabfda65..1c88d3225d 100644
--- a/spec/ruby/library/cgi/queryextension/server_port_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/server_port_spec.rb
@@ -1,26 +1,29 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
+require_relative '../../../spec_helper'
-describe "CGI::QueryExtension#server_port" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- end
+ describe "CGI::QueryExtension#server_port" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ end
+
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
- it "returns ENV['SERVER_PORT'] as Integer" do
- old_value = ENV['SERVER_PORT']
- begin
- ENV['SERVER_PORT'] = nil
- @cgi.server_port.should be_nil
+ it "returns ENV['SERVER_PORT'] as Integer" do
+ old_value = ENV['SERVER_PORT']
+ begin
+ ENV['SERVER_PORT'] = nil
+ @cgi.server_port.should == nil
- ENV['SERVER_PORT'] = "3000"
- @cgi.server_port.should eql(3000)
- ensure
- ENV['SERVER_PORT'] = old_value
+ ENV['SERVER_PORT'] = "3000"
+ @cgi.server_port.should.eql?(3000)
+ ensure
+ ENV['SERVER_PORT'] = old_value
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/queryextension/server_protocol_spec.rb b/spec/ruby/library/cgi/queryextension/server_protocol_spec.rb
index f1285bbd20..fdbcc2108f 100644
--- a/spec/ruby/library/cgi/queryextension/server_protocol_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/server_protocol_spec.rb
@@ -1,22 +1,25 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
+require_relative '../../../spec_helper'
-describe "CGI::QueryExtension#server_protocol" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- end
+ describe "CGI::QueryExtension#server_protocol" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ end
+
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
- it "returns ENV['SERVER_PROTOCOL']" do
- old_value, ENV['SERVER_PROTOCOL'] = ENV['SERVER_PROTOCOL'], "HTTP/1.1"
- begin
- @cgi.server_protocol.should == "HTTP/1.1"
- ensure
- ENV['SERVER_PROTOCOL'] = old_value
+ it "returns ENV['SERVER_PROTOCOL']" do
+ old_value, ENV['SERVER_PROTOCOL'] = ENV['SERVER_PROTOCOL'], "HTTP/1.1"
+ begin
+ @cgi.server_protocol.should == "HTTP/1.1"
+ ensure
+ ENV['SERVER_PROTOCOL'] = old_value
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/queryextension/server_software_spec.rb b/spec/ruby/library/cgi/queryextension/server_software_spec.rb
index e982a6f31c..c5811a2268 100644
--- a/spec/ruby/library/cgi/queryextension/server_software_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/server_software_spec.rb
@@ -1,22 +1,25 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
+require_relative '../../../spec_helper'
-describe "CGI::QueryExtension#server_software" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- end
+ describe "CGI::QueryExtension#server_software" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ end
+
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
- it "returns ENV['SERVER_SOFTWARE']" do
- old_value, ENV['SERVER_SOFTWARE'] = ENV['SERVER_SOFTWARE'], "Server/1.0.0"
- begin
- @cgi.server_software.should == "Server/1.0.0"
- ensure
- ENV['SERVER_SOFTWARE'] = old_value
+ it "returns ENV['SERVER_SOFTWARE']" do
+ old_value, ENV['SERVER_SOFTWARE'] = ENV['SERVER_SOFTWARE'], "Server/1.0.0"
+ begin
+ @cgi.server_software.should == "Server/1.0.0"
+ ensure
+ ENV['SERVER_SOFTWARE'] = old_value
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/queryextension/shared/has_key.rb b/spec/ruby/library/cgi/queryextension/shared/has_key.rb
index cfac5865fa..6231cb548e 100644
--- a/spec/ruby/library/cgi/queryextension/shared/has_key.rb
+++ b/spec/ruby/library/cgi/queryextension/shared/has_key.rb
@@ -12,8 +12,8 @@ describe :cgi_query_extension_has_key_p, shared: true do
end
it "returns true when the passed key exists in the HTTP Query" do
- @cgi.send(@method, "one").should be_true
- @cgi.send(@method, "two").should be_true
- @cgi.send(@method, "three").should be_false
+ @cgi.send(@method, "one").should == true
+ @cgi.send(@method, "two").should == true
+ @cgi.send(@method, "three").should == false
end
end
diff --git a/spec/ruby/library/cgi/queryextension/user_agent_spec.rb b/spec/ruby/library/cgi/queryextension/user_agent_spec.rb
index 8bbfed17c5..3240352ef6 100644
--- a/spec/ruby/library/cgi/queryextension/user_agent_spec.rb
+++ b/spec/ruby/library/cgi/queryextension/user_agent_spec.rb
@@ -1,22 +1,25 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'cgi'
+require_relative '../../../spec_helper'
-describe "CGI::QueryExtension#user_agent" do
- before :each do
- ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
- @cgi = CGI.new
- end
+ruby_version_is ""..."4.0" do
+ require 'cgi'
- after :each do
- ENV['REQUEST_METHOD'] = @old_request_method
- end
+ describe "CGI::QueryExtension#user_agent" do
+ before :each do
+ ENV['REQUEST_METHOD'], @old_request_method = "GET", ENV['REQUEST_METHOD']
+ @cgi = CGI.new
+ end
+
+ after :each do
+ ENV['REQUEST_METHOD'] = @old_request_method
+ end
- it "returns ENV['HTTP_USER_AGENT']" do
- old_value, ENV['HTTP_USER_AGENT'] = ENV['HTTP_USER_AGENT'], "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_2; de-de) AppleWebKit/527+ (KHTML, like Gecko) Version/3.1 Safari/525.13"
- begin
- @cgi.user_agent.should == "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_2; de-de) AppleWebKit/527+ (KHTML, like Gecko) Version/3.1 Safari/525.13"
- ensure
- ENV['HTTP_USER_AGENT'] = old_value
+ it "returns ENV['HTTP_USER_AGENT']" do
+ old_value, ENV['HTTP_USER_AGENT'] = ENV['HTTP_USER_AGENT'], "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_2; de-de) AppleWebKit/527+ (KHTML, like Gecko) Version/3.1 Safari/525.13"
+ begin
+ @cgi.user_agent.should == "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_2; de-de) AppleWebKit/527+ (KHTML, like Gecko) Version/3.1 Safari/525.13"
+ ensure
+ ENV['HTTP_USER_AGENT'] = old_value
+ end
end
end
end
diff --git a/spec/ruby/library/cgi/rfc1123_date_spec.rb b/spec/ruby/library/cgi/rfc1123_date_spec.rb
index 73e07c6fbd..636185f22c 100644
--- a/spec/ruby/library/cgi/rfc1123_date_spec.rb
+++ b/spec/ruby/library/cgi/rfc1123_date_spec.rb
@@ -1,10 +1,13 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require 'cgi'
+require_relative '../../spec_helper'
-describe "CGI.rfc1123_date when passsed Time" do
- it "returns the passed Time formatted in RFC1123 ('Sat, 01 Dec 2007 15:56:42 GMT')" do
- input = Time.at(1196524602)
- expected = 'Sat, 01 Dec 2007 15:56:42 GMT'
- CGI.rfc1123_date(input).should == expected
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+
+ describe "CGI.rfc1123_date when passed Time" do
+ it "returns the passed Time formatted in RFC1123 ('Sat, 01 Dec 2007 15:56:42 GMT')" do
+ input = Time.at(1196524602)
+ expected = 'Sat, 01 Dec 2007 15:56:42 GMT'
+ CGI.rfc1123_date(input).should == expected
+ end
end
end
diff --git a/spec/ruby/library/cgi/shared/http_header.rb b/spec/ruby/library/cgi/shared/http_header.rb
index b6d81d2e0e..e739fed538 100644
--- a/spec/ruby/library/cgi/shared/http_header.rb
+++ b/spec/ruby/library/cgi/shared/http_header.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'cgi'
describe :cgi_http_header, shared: true do
@@ -63,11 +63,11 @@ describe :cgi_http_header, shared: true do
header.should == "Content-Type: text/plain; charset=UTF-8\r\n\r\n"
header = @cgi.send(@method, "nph" => true)
- header.should include("HTTP/1.0 200 OK\r\n")
- header.should include("Date: ")
- header.should include("Server: ")
- header.should include("Connection: close\r\n")
- header.should include("Content-Type: text/html\r\n")
+ header.should.include?("HTTP/1.0 200 OK\r\n")
+ header.should.include?("Date: ")
+ header.should.include?("Server: ")
+ header.should.include?("Connection: close\r\n")
+ header.should.include?("Content-Type: text/html\r\n")
header = @cgi.send(@method, "status" => "OK")
header.should == "Status: 200 OK\r\nContent-Type: text/html\r\n\r\n"
diff --git a/spec/ruby/library/cgi/unescapeElement_spec.rb b/spec/ruby/library/cgi/unescapeElement_spec.rb
index cc26f9b484..db83f0d2fb 100644
--- a/spec/ruby/library/cgi/unescapeElement_spec.rb
+++ b/spec/ruby/library/cgi/unescapeElement_spec.rb
@@ -1,5 +1,11 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require 'cgi'
+require_relative '../../spec_helper'
+
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+end
+ruby_version_is "4.0" do
+ require 'cgi/escape'
+end
describe "CGI.unescapeElement when passed String, elements, ..." do
it "unescapes only the tags of the passed elements in the passed String" do
diff --git a/spec/ruby/library/cgi/unescapeHTML_spec.rb b/spec/ruby/library/cgi/unescapeHTML_spec.rb
index 611ce0a6f1..e43dcc83e5 100644
--- a/spec/ruby/library/cgi/unescapeHTML_spec.rb
+++ b/spec/ruby/library/cgi/unescapeHTML_spec.rb
@@ -1,5 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require 'cgi'
+require_relative '../../spec_helper'
+begin
+ require 'cgi/escape'
+rescue LoadError
+ require 'cgi'
+end
describe "CGI.unescapeHTML" do
it "unescapes '&amp; &lt; &gt; &quot;' to '& < > \"'" do
@@ -36,4 +40,9 @@ describe "CGI.unescapeHTML" do
input = "fooooooo&#"
CGI.unescapeHTML(input).should == input
end
+
+ it "unescapes invalid encoding" do
+ input = "\xFF&"
+ CGI.unescapeHTML(input).should == input
+ end
end
diff --git a/spec/ruby/library/cgi/unescapeURIComponent_spec.rb b/spec/ruby/library/cgi/unescapeURIComponent_spec.rb
new file mode 100644
index 0000000000..e0bf4b70e0
--- /dev/null
+++ b/spec/ruby/library/cgi/unescapeURIComponent_spec.rb
@@ -0,0 +1,128 @@
+require_relative '../../spec_helper'
+
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+end
+ruby_version_is "4.0" do
+ require 'cgi/escape'
+end
+
+describe "CGI.unescapeURIComponent" do
+ it "decodes any percent-encoded octets to their corresponding bytes according to RFC 3986" do
+ string = (0x00..0xff).map { |i| "%%%02x" % i }.join
+ expected = (0x00..0xff).map { |i| i.chr }.join.force_encoding(Encoding::UTF_8)
+ CGI.unescapeURIComponent(string).should == expected
+ end
+
+ it "disregards case of characters in a percent-encoding triplet" do
+ CGI.unescapeURIComponent("%CE%B2abc").should == "βabc"
+ CGI.unescapeURIComponent("%ce%b2ABC").should == "βABC"
+ end
+
+ it "leaves any non-percent-encoded characters as-is" do
+ string = "ABCDEFGHIJKLMNOPQRSTUVWXYZ:/?#[]@!$&'()*+,;=\t\x0D\xFFβᛉ▒90%"
+ decoded = CGI.unescapeURIComponent(string)
+ decoded.should == string
+ string.should_not.equal?(decoded)
+ end
+
+ it "leaves sequences which can't be a percent-encoded octet as-is" do
+ string = "%AZ%B"
+ decoded = CGI.unescapeURIComponent(string)
+ decoded.should == string
+ string.should_not.equal?(decoded)
+ end
+
+ it "creates a String with the specified target Encoding" do
+ string = CGI.unescapeURIComponent("%D2%3C%3CABC", Encoding::ISO_8859_1)
+ string.encoding.should == Encoding::ISO_8859_1
+ string.should == "Ã’<<ABC".encode("ISO-8859-1")
+ end
+
+ it "accepts a string name of an Encoding" do
+ CGI.unescapeURIComponent("%D2%3C%3CABC", "ISO-8859-1").should == "Ã’<<ABC".encode("ISO-8859-1")
+ end
+
+ it "raises ArgumentError if specified encoding is unknown" do
+ -> { CGI.unescapeURIComponent("ABC", "ISO-JOKE-1") }.should.raise(ArgumentError, "unknown encoding name - ISO-JOKE-1")
+ end
+
+ ruby_version_is ""..."4.0" do
+ it "uses CGI.accept_charset as the default target encoding" do
+ original_charset = CGI.accept_charset
+ CGI.accept_charset = "ISO-8859-1"
+ decoded = CGI.unescapeURIComponent("%D2%3C%3CABC")
+ decoded.should == "Ã’<<ABC".encode("ISO-8859-1")
+ decoded.encoding.should == Encoding::ISO_8859_1
+ ensure
+ CGI.accept_charset = original_charset
+ end
+
+ it "has CGI.accept_charset as UTF-8 by default" do
+ decoded = CGI.unescapeURIComponent("%CE%B2ABC")
+ decoded.should == "βABC"
+ decoded.encoding.should == Encoding::UTF_8
+ end
+ end
+
+ ruby_version_is "4.0" do
+ # "cgi/escape" does not have methods to access @@accept_charset.
+ # Full "cgi" gem provides them, allowing to possibly change it.
+ it "uses CGI's @@accept_charset as the default target encoding" do
+ original_charset = CGI.class_variable_get(:@@accept_charset)
+ CGI.class_variable_set(:@@accept_charset, "ISO-8859-1")
+ decoded = CGI.unescapeURIComponent("%D2%3C%3CABC")
+ decoded.should == "Ã’<<ABC".encode("ISO-8859-1")
+ decoded.encoding.should == Encoding::ISO_8859_1
+ ensure
+ CGI.class_variable_set(:@@accept_charset, original_charset)
+ end
+
+ it "has CGI's @@accept_charset as UTF-8 by default" do
+ decoded = CGI.unescapeURIComponent("%CE%B2ABC")
+ decoded.should == "βABC"
+ decoded.encoding.should == Encoding::UTF_8
+ end
+ end
+
+ context "when source string specifies octets invalid in target encoding" do
+ it "uses source string's encoding" do
+ string = "%A2%A6%A3".encode(Encoding::SHIFT_JIS)
+ decoded = CGI.unescapeURIComponent(string, Encoding::US_ASCII)
+ decoded.encoding.should == Encoding::SHIFT_JIS
+ decoded.should == "「ヲ」".encode(Encoding::SHIFT_JIS)
+ decoded.valid_encoding?.should == true
+ end
+
+ it "uses source string's encoding even if it's also invalid" do
+ string = "%FF".encode(Encoding::US_ASCII)
+ decoded = CGI.unescapeURIComponent(string, Encoding::SHIFT_JIS)
+ decoded.encoding.should == Encoding::US_ASCII
+ decoded.should == "\xFF".dup.force_encoding(Encoding::US_ASCII)
+ decoded.valid_encoding?.should == false
+ end
+ end
+
+ it "decodes an empty string as an empty string with target encoding" do
+ string = "".encode(Encoding::BINARY)
+ decoded = CGI.unescapeURIComponent(string, "UTF-8")
+ decoded.should == ""
+ decoded.encoding.should == Encoding::UTF_8
+ string.should_not.equal?(decoded)
+ end
+
+ it "raises a TypeError with nil" do
+ -> {
+ CGI.unescapeURIComponent(nil)
+ }.should.raise(TypeError, "no implicit conversion of nil into String")
+ end
+
+ it "uses implicit type conversion to String" do
+ object = Object.new
+ def object.to_str
+ "a%20b"
+ end
+
+ CGI.unescapeURIComponent(object).should == "a b"
+ end
+end
diff --git a/spec/ruby/library/cgi/unescape_spec.rb b/spec/ruby/library/cgi/unescape_spec.rb
index 8cf988b9dd..aa731b9367 100644
--- a/spec/ruby/library/cgi/unescape_spec.rb
+++ b/spec/ruby/library/cgi/unescape_spec.rb
@@ -1,6 +1,12 @@
# -*- encoding: utf-8 -*-
-require File.expand_path('../../../spec_helper', __FILE__)
-require 'cgi'
+require_relative '../../spec_helper'
+
+ruby_version_is ""..."4.0" do
+ require 'cgi'
+end
+ruby_version_is "4.0" do
+ require 'cgi/escape'
+end
describe "CGI.unescape" do
it "url-decodes the passed argument" do
@@ -8,8 +14,8 @@ describe "CGI.unescape" do
expected = " !\"\#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
CGI.unescape(input).should == expected
- input = 'http%3A%2F%2Fja.wikipedia.org%2Fwiki%2F%E3%83%AD%E3%83%A0%E3%82%B9%E3%82%AB%E3%83%BB%E3%83%91%E3%83%AD%E3%83%BB%E3%82%A6%E3%83%AB%E3%83%BB%E3%83%A9%E3%83%94%E3%83%A5%E3%82%BF'
- expected = "http://ja.wikipedia.org/wiki/\343\203\255\343\203\240\343\202\271\343\202\253\343\203\273\343\203\221\343\203\255\343\203\273\343\202\246\343\203\253\343\203\273\343\203\251\343\203\224\343\203\245\343\202\277"
+ input = 'https%3A%2F%2Fja.wikipedia.org%2Fwiki%2F%E3%83%AD%E3%83%A0%E3%82%B9%E3%82%AB%E3%83%BB%E3%83%91%E3%83%AD%E3%83%BB%E3%82%A6%E3%83%AB%E3%83%BB%E3%83%A9%E3%83%94%E3%83%A5%E3%82%BF'
+ expected = "https://ja.wikipedia.org/wiki/\343\203\255\343\203\240\343\202\271\343\202\253\343\203\273\343\203\221\343\203\255\343\203\273\343\202\246\343\203\253\343\203\273\343\203\251\343\203\224\343\203\245\343\202\277"
CGI.unescape(input).should == expected
end
end
diff --git a/spec/ruby/library/complex/math/acos_spec.rb b/spec/ruby/library/complex/math/acos_spec.rb
deleted file mode 100644
index 84425dbaa1..0000000000
--- a/spec/ruby/library/complex/math/acos_spec.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'complex'
-require File.expand_path('../shared/acos', __FILE__)
-
-describe "Math#acos" do
- it_behaves_like :complex_math_acos, :_, IncludesMath.new
-
- it "is a private instance method" do
- IncludesMath.should have_private_instance_method(:acos)
- end
-end
-
-describe "Math.acos" do
- it_behaves_like :complex_math_acos, :_, CMath
-end
diff --git a/spec/ruby/library/complex/math/acosh_spec.rb b/spec/ruby/library/complex/math/acosh_spec.rb
deleted file mode 100644
index cda9ce38d6..0000000000
--- a/spec/ruby/library/complex/math/acosh_spec.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'complex'
-require File.expand_path('../shared/acosh', __FILE__)
-
-describe "Math#acosh" do
- it_behaves_like :complex_math_acosh, :_, IncludesMath.new
-
- it "is a private instance method" do
- IncludesMath.should have_private_instance_method(:acosh)
- end
-end
-
-describe "Math.acosh" do
- it_behaves_like :complex_math_acosh, :_, CMath
-end
diff --git a/spec/ruby/library/complex/math/asin_spec.rb b/spec/ruby/library/complex/math/asin_spec.rb
deleted file mode 100644
index aa26bed11d..0000000000
--- a/spec/ruby/library/complex/math/asin_spec.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'complex'
-require File.expand_path('../shared/asin', __FILE__)
-
-describe "Math#asin" do
- it_behaves_like :complex_math_asin, :_, IncludesMath.new
-
- it "is a private instance method" do
- IncludesMath.should have_private_instance_method(:asin)
- end
-end
-
-describe "Math.asin" do
- it_behaves_like :complex_math_asin, :_, CMath
-end
diff --git a/spec/ruby/library/complex/math/asinh_spec.rb b/spec/ruby/library/complex/math/asinh_spec.rb
deleted file mode 100644
index a1b0816b33..0000000000
--- a/spec/ruby/library/complex/math/asinh_spec.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'complex'
-require File.expand_path('../shared/asinh', __FILE__)
-
-describe "Math#asinh" do
- it_behaves_like :complex_math_asinh, :_, IncludesMath.new
-
- it "is a private instance method" do
- IncludesMath.should have_private_instance_method(:asinh)
- end
-end
-
-describe "Math.asinh" do
- it_behaves_like :complex_math_asinh, :_, CMath
-end
diff --git a/spec/ruby/library/complex/math/atan2_spec.rb b/spec/ruby/library/complex/math/atan2_spec.rb
deleted file mode 100644
index 7111b4a8ec..0000000000
--- a/spec/ruby/library/complex/math/atan2_spec.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'complex'
-require File.expand_path('../shared/atan2', __FILE__)
-
-describe "Math#atan2" do
- it_behaves_like :complex_math_atan2, :_, IncludesMath.new
-
- it "is a private instance method" do
- IncludesMath.should have_private_instance_method(:atan2)
- end
-end
-
-describe "Math.atan2" do
- it_behaves_like :complex_math_atan2, :_, CMath
-end
diff --git a/spec/ruby/library/complex/math/atan_spec.rb b/spec/ruby/library/complex/math/atan_spec.rb
deleted file mode 100644
index 6659b309e4..0000000000
--- a/spec/ruby/library/complex/math/atan_spec.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'complex'
-require File.expand_path('../shared/atan', __FILE__)
-
-describe "Math#atan" do
- it_behaves_like :complex_math_atan, :_, IncludesMath.new
-
- it "is a private instance method" do
- IncludesMath.should have_private_instance_method(:atan)
- end
-end
-
-describe "Math.atan" do
- it_behaves_like :complex_math_atan, :_, CMath
-end
diff --git a/spec/ruby/library/complex/math/atanh_spec.rb b/spec/ruby/library/complex/math/atanh_spec.rb
deleted file mode 100644
index a68674f82c..0000000000
--- a/spec/ruby/library/complex/math/atanh_spec.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-require 'complex'
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../../../fixtures/math/common', __FILE__)
-require File.expand_path('../../../../shared/math/atanh', __FILE__)
-require File.expand_path('../shared/atanh', __FILE__)
-
-describe "Math#atanh" do
- it_behaves_like :math_atanh_base, :atanh, IncludesMath.new
- it_behaves_like :complex_math_atanh_complex, :atanh, IncludesMath.new
-
- it_behaves_like :math_atanh_private, :atanh, IncludesMath.new
-end
-
-describe "Math.atanh" do
- it_behaves_like :math_atanh_base, :atanh, CMath
- it_behaves_like :complex_math_atanh_complex, :atanh, CMath
-end
diff --git a/spec/ruby/library/complex/math/cos_spec.rb b/spec/ruby/library/complex/math/cos_spec.rb
deleted file mode 100644
index 4267c601a6..0000000000
--- a/spec/ruby/library/complex/math/cos_spec.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'complex'
-require File.expand_path('../shared/cos', __FILE__)
-
-describe "Math#cos" do
- it_behaves_like :complex_math_cos, :_, IncludesMath.new
-
- it "is a private instance method" do
- IncludesMath.should have_private_instance_method(:cos)
- end
-end
-
-describe "Math.cos" do
- it_behaves_like :complex_math_cos, :_, CMath
-end
diff --git a/spec/ruby/library/complex/math/cosh_spec.rb b/spec/ruby/library/complex/math/cosh_spec.rb
deleted file mode 100644
index b3aa1bdb69..0000000000
--- a/spec/ruby/library/complex/math/cosh_spec.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'complex'
-require File.expand_path('../shared/cosh', __FILE__)
-
-describe "Math#cosh" do
- it_behaves_like :complex_math_cosh, :_, IncludesMath.new
-
- it "is a private instance method" do
- IncludesMath.should have_private_instance_method(:cosh)
- end
-end
-
-describe "Math.cosh" do
- it_behaves_like :complex_math_cosh, :_, CMath
-end
diff --git a/spec/ruby/library/complex/math/exp_spec.rb b/spec/ruby/library/complex/math/exp_spec.rb
deleted file mode 100644
index df1d12bbb5..0000000000
--- a/spec/ruby/library/complex/math/exp_spec.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'complex'
-require File.expand_path('../shared/exp', __FILE__)
-
-describe "Math#exp" do
- it_behaves_like :complex_math_exp, :_, IncludesMath.new
-
- it "is a private instance method" do
- IncludesMath.should have_private_instance_method(:exp)
- end
-end
-
-describe "Math.exp" do
- it_behaves_like :complex_math_exp, :_, CMath
-end
diff --git a/spec/ruby/library/complex/math/fixtures/classes.rb b/spec/ruby/library/complex/math/fixtures/classes.rb
deleted file mode 100644
index 443c1a9ace..0000000000
--- a/spec/ruby/library/complex/math/fixtures/classes.rb
+++ /dev/null
@@ -1,4 +0,0 @@
-require 'cmath'
-class IncludesMath
- include CMath
-end
diff --git a/spec/ruby/library/complex/math/log10_spec.rb b/spec/ruby/library/complex/math/log10_spec.rb
deleted file mode 100644
index c7c5717873..0000000000
--- a/spec/ruby/library/complex/math/log10_spec.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'complex'
-require File.expand_path('../shared/log10', __FILE__)
-
-describe "Math#log10" do
- it_behaves_like :complex_math_log10, :_, IncludesMath.new
-
- it "is a private instance method" do
- IncludesMath.should have_private_instance_method(:log10)
- end
-end
-
-describe "Math.log10" do
- it_behaves_like :complex_math_log10, :_, CMath
-end
diff --git a/spec/ruby/library/complex/math/log_spec.rb b/spec/ruby/library/complex/math/log_spec.rb
deleted file mode 100644
index f55b406af8..0000000000
--- a/spec/ruby/library/complex/math/log_spec.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'complex'
-require File.expand_path('../shared/log', __FILE__)
-
-describe "Math#log" do
- it_behaves_like :complex_math_log, :_, IncludesMath.new
-
- it "is a private instance method" do
- IncludesMath.should have_private_instance_method(:log)
- end
-end
-
-describe "Math.log" do
- it_behaves_like :complex_math_log, :_, CMath
-end
diff --git a/spec/ruby/library/complex/math/shared/acos.rb b/spec/ruby/library/complex/math/shared/acos.rb
deleted file mode 100644
index 7a9e0fe1b2..0000000000
--- a/spec/ruby/library/complex/math/shared/acos.rb
+++ /dev/null
@@ -1,41 +0,0 @@
-require File.expand_path('../../fixtures/classes', __FILE__)
-
-describe :complex_math_acos, shared: true do
- it "returns the arccosine of the passed argument" do
- @object.send(:acos, 1).should be_close(0.0, TOLERANCE)
- @object.send(:acos, 0).should be_close(1.5707963267949, TOLERANCE)
- @object.send(:acos, -1).should be_close(Math::PI,TOLERANCE)
- end
-
- it "returns the arccosine for Complex numbers" do
- @object.send(:acos, Complex(3, 4)).should be_close(Complex(0.93681246115572, -2.30550903124348), TOLERANCE)
- end
-
- it "returns the arccosine for numbers greater than 1.0 as a Complex number" do
- @object.send(:acos, 1.0001).should be_close(Complex(0.0, 0.0141420177752494), TOLERANCE)
- end
-
- it "returns the arccosine for numbers less than -1.0 as a Complex number" do
- @object.send(:acos, -1.0001).should be_close(Complex(3.14159265358979, -0.0141420177752495), TOLERANCE)
- end
-end
-
-describe :complex_math_acos_bang, shared: true do
- it "returns the arccosine of the argument" do
- @object.send(:acos!, 1).should be_close(0.0, TOLERANCE)
- @object.send(:acos!, 0).should be_close(1.5707963267949, TOLERANCE)
- @object.send(:acos!, -1).should be_close(Math::PI,TOLERANCE)
- end
-
- it "raises a TypeError when passed a Complex number" do
- lambda { @object.send(:acos!, Complex(4, 5)) }.should raise_error(TypeError)
- end
-
- it "raises an Errno::EDOM for numbers greater than 1.0" do
- lambda { @object.send(:acos!, 1.0001) }.should raise_error(Errno::EDOM)
- end
-
- it "raises an Errno::EDOM for numbers less than -1.0" do
- lambda { @object.send(:acos!, -1.0001) }.should raise_error(Errno::EDOM)
- end
-end
diff --git a/spec/ruby/library/complex/math/shared/acosh.rb b/spec/ruby/library/complex/math/shared/acosh.rb
deleted file mode 100644
index b8be750f13..0000000000
--- a/spec/ruby/library/complex/math/shared/acosh.rb
+++ /dev/null
@@ -1,37 +0,0 @@
-require File.expand_path('../../fixtures/classes', __FILE__)
-
-describe :complex_math_acosh, shared: true do
- it "returns the principle value of the inverse hyperbolic cosine of the argument" do
- @object.send(:acosh, 14.2).should be_close(3.345146999647, TOLERANCE)
- @object.send(:acosh, 1.0).should be_close(0.0, TOLERANCE)
- end
-
- it "returns the principle value of the inverse hyperbolic cosine for numbers less than 1.0 as a Complex number" do
- @object.send(:acosh, 1.0 - TOLERANCE).should be_close(Complex(0.0, 0.00774598605746135), TOLERANCE)
- @object.send(:acosh, 0).should be_close(Complex(0.0, 1.5707963267949), TOLERANCE)
- @object.send(:acosh, -1.0).should be_close(Complex(0.0, 3.14159265358979), TOLERANCE)
- end
-
- it "returns the principle value of the inverse hyperbolic cosine for Complex numbers" do
- @object.send(:acosh, Complex(3, 4))
- @object.send(:acosh, Complex(3, 4)).imaginary.should be_close(0.93681246115572, TOLERANCE)
- @object.send(:acosh, Complex(3, 4)).real.should be_close(2.305509031243477, TOLERANCE)
- end
-end
-
-describe :complex_math_acosh_bang, shared: true do
- it "returns the principle value of the inverse hyperbolic cosine of the argument" do
- @object.send(:acosh!, 14.2).should be_close(3.345146999647, TOLERANCE)
- @object.send(:acosh!, 1.0).should be_close(0.0, TOLERANCE)
- end
-
- it "raises Errno::EDOM for numbers less than 1.0" do
- lambda { @object.send(:acosh!, 1.0 - TOLERANCE) }.should raise_error(Errno::EDOM)
- lambda { @object.send(:acosh!, 0) }.should raise_error(Errno::EDOM)
- lambda { @object.send(:acosh!, -1.0) }.should raise_error(Errno::EDOM)
- end
-
- it "raises a TypeError when passed a Complex number" do
- lambda { @object.send(:acosh!, Complex(4, 5)) }.should raise_error(TypeError)
- end
-end
diff --git a/spec/ruby/library/complex/math/shared/asin.rb b/spec/ruby/library/complex/math/shared/asin.rb
deleted file mode 100644
index 3b446cbe24..0000000000
--- a/spec/ruby/library/complex/math/shared/asin.rb
+++ /dev/null
@@ -1,47 +0,0 @@
-require File.expand_path('../../fixtures/classes', __FILE__)
-
-describe :complex_math_asin, shared: true do
- it "returns the arcsine of the argument" do
- @object.send(:asin, 1).should be_close(Math::PI/2, TOLERANCE)
- @object.send(:asin, 0).should be_close(0.0, TOLERANCE)
- @object.send(:asin, -1).should be_close(-Math::PI/2, TOLERANCE)
- @object.send(:asin, 0.25).should be_close(0.252680255142079, TOLERANCE)
- @object.send(:asin, 0.50).should be_close(0.523598775598299, TOLERANCE)
- @object.send(:asin, 0.75).should be_close(0.8480620789814816,TOLERANCE)
- end
-
- it "returns the arcsine for Complex numbers" do
- @object.send(:asin, Complex(3, 4)).should be_close(Complex(0.633983865639174, 2.30550903124347), TOLERANCE)
- end
-
- it "returns a Complex number when the argument is greater than 1.0" do
- @object.send(:asin, 1.0001).should be_close(Complex(1.5707963267949, -0.0141420177752494), TOLERANCE)
- end
-
- it "returns a Complex number when the argument is less than -1.0" do
- @object.send(:asin, -1.0001).should be_close(Complex(-1.5707963267949, 0.0141420177752494), TOLERANCE)
- end
-end
-
-describe :complex_math_asin_bang, shared: true do
- it "returns the arcsine of the argument" do
- @object.send(:asin!, 1).should be_close(Math::PI/2, TOLERANCE)
- @object.send(:asin!, 0).should be_close(0.0, TOLERANCE)
- @object.send(:asin!, -1).should be_close(-Math::PI/2, TOLERANCE)
- @object.send(:asin!, 0.25).should be_close(0.252680255142079, TOLERANCE)
- @object.send(:asin!, 0.50).should be_close(0.523598775598299, TOLERANCE)
- @object.send(:asin!, 0.75).should be_close(0.8480620789814816,TOLERANCE)
- end
-
- it "raises an Errno::EDOM if the argument is greater than 1.0" do
- lambda { @object.send(:asin!, 1.0001) }.should raise_error( Errno::EDOM)
- end
-
- it "raises an Errno::EDOM if the argument is less than -1.0" do
- lambda { @object.send(:asin!, -1.0001) }.should raise_error( Errno::EDOM)
- end
-
- it "raises a TypeError when passed a Complex number" do
- lambda { @object.send(:asin!, Complex(4, 5)) }.should raise_error(TypeError)
- end
-end
diff --git a/spec/ruby/library/complex/math/shared/asinh.rb b/spec/ruby/library/complex/math/shared/asinh.rb
deleted file mode 100644
index 4c2f6c8b5d..0000000000
--- a/spec/ruby/library/complex/math/shared/asinh.rb
+++ /dev/null
@@ -1,32 +0,0 @@
-require File.expand_path('../../fixtures/classes', __FILE__)
-
-describe :complex_math_asinh, shared: true do
- it "returns the inverse hyperbolic sin of the argument" do
- @object.send(:asinh, 1.5).should be_close(1.19476321728711, TOLERANCE)
- @object.send(:asinh, -2.97).should be_close(-1.8089166921397, TOLERANCE)
- @object.send(:asinh, 0.0).should == 0.0
- @object.send(:asinh, -0.0).should == -0.0
- @object.send(:asinh, 1.05367e-08).should be_close(1.05367e-08, TOLERANCE)
- @object.send(:asinh, -1.05367e-08).should be_close(-1.05367e-08, TOLERANCE)
- end
-
- it "returns the inverse hyperbolic sin for Complex numbers" do
- @object.send(:asinh, Complex(3, 4)).should be_close(Complex(2.29991404087927, 0.917616853351479), TOLERANCE)
- @object.send(:asinh, Complex(3.5, -4)).should be_close(Complex(2.36263337274419, -0.843166327537659), TOLERANCE)
- end
-end
-
-describe :complex_math_asinh_bang, shared: true do
- it "returns the inverse hyperbolic sin of the argument" do
- @object.send(:asinh!, 1.5).should be_close(1.19476321728711, TOLERANCE)
- @object.send(:asinh!, -2.97).should be_close(-1.8089166921397, TOLERANCE)
- @object.send(:asinh!, 0.0).should == 0.0
- @object.send(:asinh!, -0.0).should == -0.0
- @object.send(:asinh!, 1.05367e-08).should be_close(1.05367e-08, TOLERANCE)
- @object.send(:asinh!, -1.05367e-08).should be_close(-1.05367e-08, TOLERANCE)
- end
-
- it "raises a TypeError when passed a Complex number" do
- lambda { @object.send(:asinh!, Complex(4, 5)) }.should raise_error(TypeError)
- end
-end
diff --git a/spec/ruby/library/complex/math/shared/atan.rb b/spec/ruby/library/complex/math/shared/atan.rb
deleted file mode 100644
index 44fa65e1e9..0000000000
--- a/spec/ruby/library/complex/math/shared/atan.rb
+++ /dev/null
@@ -1,32 +0,0 @@
-require File.expand_path('../../fixtures/classes', __FILE__)
-
-describe :complex_math_atan, shared: true do
- it "returns the arctangent of the argument" do
- @object.send(:atan, 1).should be_close(Math::PI/4, TOLERANCE)
- @object.send(:atan, 0).should be_close(0.0, TOLERANCE)
- @object.send(:atan, -1).should be_close(-Math::PI/4, TOLERANCE)
- @object.send(:atan, 0.25).should be_close(0.244978663126864, TOLERANCE)
- @object.send(:atan, 0.50).should be_close(0.463647609000806, TOLERANCE)
- @object.send(:atan, 0.75).should be_close(0.643501108793284, TOLERANCE)
- end
-
- it "returns the arctangent for Complex numbers" do
- @object.send(:atan, Complex(3, 4)).should be_close(Complex(1.44830699523146, 0.158997191679999), TOLERANCE)
- @object.send(:atan, Complex(3.5, -4)).should be_close(Complex(1.44507428165589, -0.140323762363786), TOLERANCE)
- end
-end
-
-describe :complex_math_atan_bang, shared: true do
- it "returns the arctangent of the argument" do
- @object.send(:atan!, 1).should be_close(Math::PI/4, TOLERANCE)
- @object.send(:atan!, 0).should be_close(0.0, TOLERANCE)
- @object.send(:atan!, -1).should be_close(-Math::PI/4, TOLERANCE)
- @object.send(:atan!, 0.25).should be_close(0.244978663126864, TOLERANCE)
- @object.send(:atan!, 0.50).should be_close(0.463647609000806, TOLERANCE)
- @object.send(:atan!, 0.75).should be_close(0.643501108793284, TOLERANCE)
- end
-
- it "raises a TypeError when passed a Complex number" do
- lambda { @object.send(:atan!, Complex(4, 5)) }.should raise_error(TypeError)
- end
-end
diff --git a/spec/ruby/library/complex/math/shared/atan2.rb b/spec/ruby/library/complex/math/shared/atan2.rb
deleted file mode 100644
index add1dcd6fa..0000000000
--- a/spec/ruby/library/complex/math/shared/atan2.rb
+++ /dev/null
@@ -1,34 +0,0 @@
-require File.expand_path('../../fixtures/classes', __FILE__)
-
-describe :complex_math_atan2, shared: true do
- it "returns the arc tangent of the passed arguments" do
- @object.send(:atan2, 4.2, 0.3).should be_close(1.49948886200961, TOLERANCE)
- @object.send(:atan2, 0.0, 1.0).should be_close(0.0, TOLERANCE)
- @object.send(:atan2, -9.1, 3.2).should be_close(-1.23265379809025, TOLERANCE)
- @object.send(:atan2, 7.22, -3.3).should be_close(1.99950888779256, TOLERANCE)
- end
-
- it "returns the arc tangent for two Complex numbers" do
- CMath.atan2(Complex(3, 4), Complex(3.5, -4)).should be_close(Complex(-0.641757436698881, 1.10829873031207), TOLERANCE)
- end
-
- it "returns the arc tangent for Complex and real numbers" do
- CMath.atan2(Complex(3, 4), -7).should be_close(Complex(2.61576754731561, -0.494290673139855), TOLERANCE)
- CMath.atan2(5, Complex(3.5, -4)).should be_close(Complex(0.739102348493673, 0.487821626522923), TOLERANCE)
- end
-end
-
-describe :complex_math_atan2_bang, shared: true do
- it "returns the arc tangent of the passed arguments" do
- @object.send(:atan2!, 4.2, 0.3).should be_close(1.49948886200961, TOLERANCE)
- @object.send(:atan2!, 0.0, 1.0).should be_close(0.0, TOLERANCE)
- @object.send(:atan2!, -9.1, 3.2).should be_close(-1.23265379809025, TOLERANCE)
- @object.send(:atan2!, 7.22, -3.3).should be_close(1.99950888779256, TOLERANCE)
- end
-
- it "raises a TypeError when passed a Complex number" do
- lambda { @object.send(:atan2!, Complex(4, 5), Complex(4, 5)) }.should raise_error(TypeError)
- lambda { @object.send(:atan2!, 4, Complex(4, 5)) }.should raise_error(TypeError)
- lambda { @object.send(:atan2!, Complex(4, 5), 5) }.should raise_error(TypeError)
- end
-end
diff --git a/spec/ruby/library/complex/math/shared/atanh.rb b/spec/ruby/library/complex/math/shared/atanh.rb
deleted file mode 100644
index 4051af081f..0000000000
--- a/spec/ruby/library/complex/math/shared/atanh.rb
+++ /dev/null
@@ -1,30 +0,0 @@
-require File.expand_path('../../fixtures/classes', __FILE__)
-
-describe :complex_math_atanh_complex, shared: true do
- it "returns the inverse hyperbolic tangent as a Complex number for arguments greater than 1.0" do
- value = Complex(18.36840028483855, 1.5707963267948966)
- @object.send(@method, 1.0 + Float::EPSILON).should be_close(value, TOLERANCE)
-
- value = Complex(0.100335347731076, 1.5707963267949)
- @object.send(@method, 10).should be_close(value, TOLERANCE)
- end
-
- it "returns the inverse hyperbolic tangent as a Complex number for arguments greater than 1.0" do
- value = Complex(-18.36840028483855, 1.5707963267948966)
- @object.send(@method, -1.0 - Float::EPSILON).should be_close(value, TOLERANCE)
-
- value = Complex(0.100335347731076, 1.5707963267949)
- @object.send(@method, 10).should be_close(value, TOLERANCE)
- end
-
- it "returns the inverse hyperbolic tangent for Complex numbers" do
- value = Complex(0.117500907311434, 1.40992104959658)
- @object.send(@method, Complex(3, 4)).should be_close(value, TOLERANCE)
- end
-end
-
-describe :complex_math_atanh_no_complex, shared: true do
- it "raises a TypeError when passed a Complex number" do
- lambda { @object.send(:atanh!, Complex(4, 5)) }.should raise_error(TypeError)
- end
-end
diff --git a/spec/ruby/library/complex/math/shared/cos.rb b/spec/ruby/library/complex/math/shared/cos.rb
deleted file mode 100644
index ab198e1a3b..0000000000
--- a/spec/ruby/library/complex/math/shared/cos.rb
+++ /dev/null
@@ -1,30 +0,0 @@
-require File.expand_path('../../fixtures/classes', __FILE__)
-
-describe :complex_math_cos, shared: true do
- it "returns the cosine of the argument expressed in radians" do
- @object.send(:cos, CMath::PI).should be_close(-1.0, TOLERANCE)
- @object.send(:cos, 0).should be_close(1.0, TOLERANCE)
- @object.send(:cos, CMath::PI/2).should be_close(0.0, TOLERANCE)
- @object.send(:cos, 3*Math::PI/2).should be_close(0.0, TOLERANCE)
- @object.send(:cos, 2*Math::PI).should be_close(1.0, TOLERANCE)
- end
-
- it "returns the cosine for Complex numbers" do
- @object.send(:cos, Complex(0, CMath::PI)).should be_close(Complex(11.5919532755215, 0.0), TOLERANCE)
- @object.send(:cos, Complex(3, 4)).should be_close(Complex(-27.0349456030742, -3.85115333481178), TOLERANCE)
- end
-end
-
-describe :complex_math_cos_bang, shared: true do
- it "returns the cosine of the argument expressed in radians" do
- @object.send(:cos!, CMath::PI).should be_close(-1.0, TOLERANCE)
- @object.send(:cos!, 0).should be_close(1.0, TOLERANCE)
- @object.send(:cos!, CMath::PI/2).should be_close(0.0, TOLERANCE)
- @object.send(:cos!, 3*Math::PI/2).should be_close(0.0, TOLERANCE)
- @object.send(:cos!, 2*Math::PI).should be_close(1.0, TOLERANCE)
- end
-
- it "raises a TypeError when passed a Complex number" do
- lambda { @object.send(:cos!, Complex(3, 4)) }.should raise_error(TypeError)
- end
-end
diff --git a/spec/ruby/library/complex/math/shared/cosh.rb b/spec/ruby/library/complex/math/shared/cosh.rb
deleted file mode 100644
index a5f98e4e83..0000000000
--- a/spec/ruby/library/complex/math/shared/cosh.rb
+++ /dev/null
@@ -1,28 +0,0 @@
-require File.expand_path('../../fixtures/classes', __FILE__)
-
-describe :complex_math_cosh, shared: true do
- it "returns the hyperbolic cosine of the passed argument" do
- @object.send(:cosh, 0.0).should == 1.0
- @object.send(:cosh, -0.0).should == 1.0
- @object.send(:cosh, 1.5).should be_close(2.35240961524325, TOLERANCE)
- @object.send(:cosh, -2.99).should be_close(9.96798496414416, TOLERANCE)
- end
-
- it "returns the hyperbolic cosine for Complex numbers" do
- @object.send(:cosh, Complex(0, CMath::PI)).should be_close(Complex(-1.0, 0.0), TOLERANCE)
- @object.send(:cosh, Complex(3, 4)).should be_close(Complex(-6.58066304055116, -7.58155274274654), TOLERANCE)
- end
-end
-
-describe :complex_math_cosh_bang, shared: true do
- it "returns the hyperbolic cosine of the passed argument" do
- @object.send(:cosh!, 0.0).should == 1.0
- @object.send(:cosh!, -0.0).should == 1.0
- @object.send(:cosh!, 1.5).should be_close(2.35240961524325, TOLERANCE)
- @object.send(:cosh!, -2.99).should be_close(9.96798496414416, TOLERANCE)
- end
-
- it "raises a TypeError when passed a Complex number" do
- lambda { @object.send(:cosh!, Complex(4, 5)) }.should raise_error(TypeError)
- end
-end
diff --git a/spec/ruby/library/complex/math/shared/exp.rb b/spec/ruby/library/complex/math/shared/exp.rb
deleted file mode 100644
index f4e73dfb4d..0000000000
--- a/spec/ruby/library/complex/math/shared/exp.rb
+++ /dev/null
@@ -1,28 +0,0 @@
-require File.expand_path('../../fixtures/classes', __FILE__)
-
-describe :complex_math_exp, shared: true do
- it "returns the base-e exponential of the passed argument" do
- @object.send(:exp, 0.0).should == 1.0
- @object.send(:exp, -0.0).should == 1.0
- @object.send(:exp, -1.8).should be_close(0.165298888221587, TOLERANCE)
- @object.send(:exp, 1.25).should be_close(3.49034295746184, TOLERANCE)
- end
-
- it "returns the base-e exponential for Complex numbers" do
- @object.send(:exp, Complex(0, 0)).should == Complex(1.0, 0.0)
- @object.send(:exp, Complex(1, 3)).should be_close(Complex(-2.69107861381979, 0.383603953541131), TOLERANCE)
- end
-end
-
-describe :complex_math_exp_bang, shared: true do
- it "returns the base-e exponential of the passed argument" do
- @object.send(:exp!, 0.0).should == 1.0
- @object.send(:exp!, -0.0).should == 1.0
- @object.send(:exp!, -1.8).should be_close(0.165298888221587, TOLERANCE)
- @object.send(:exp!, 1.25).should be_close(3.49034295746184, TOLERANCE)
- end
-
- it "raises a TypeError when passed a Complex number" do
- lambda { @object.send(:exp!, Complex(1, 3)) }.should raise_error(TypeError)
- end
-end
diff --git a/spec/ruby/library/complex/math/shared/log.rb b/spec/ruby/library/complex/math/shared/log.rb
deleted file mode 100644
index 4e5385748a..0000000000
--- a/spec/ruby/library/complex/math/shared/log.rb
+++ /dev/null
@@ -1,39 +0,0 @@
-require File.expand_path('../../fixtures/classes', __FILE__)
-
-describe :complex_math_log, shared: true do
- it "returns the natural logarithm of the passed argument" do
- @object.send(:log, 0.0001).should be_close(-9.21034037197618, TOLERANCE)
- @object.send(:log, 0.000000000001e-15).should be_close(-62.1697975108392, TOLERANCE)
- @object.send(:log, 1).should be_close(0.0, TOLERANCE)
- @object.send(:log, 10).should be_close( 2.30258509299405, TOLERANCE)
- @object.send(:log, 10e15).should be_close(36.8413614879047, TOLERANCE)
- end
-
- it "returns the natural logarithm for Complex numbers" do
- @object.send(:log, Complex(3, 4)).should be_close(Complex(1.6094379124341, 0.927295218001612), TOLERANCE)
- @object.send(:log, Complex(-3, 4)).should be_close(Complex(1.6094379124341, 2.21429743558818), TOLERANCE)
- end
-
- it "returns the natural logarithm for negative numbers as a Complex number" do
- @object.send(:log, -10).should be_close(Complex(2.30258509299405, 3.14159265358979), TOLERANCE)
- @object.send(:log, -20).should be_close(Complex(2.99573227355399, 3.14159265358979), TOLERANCE)
- end
-end
-
-describe :complex_math_log_bang, shared: true do
- it "returns the natural logarithm of the argument" do
- @object.send(:log!, 0.0001).should be_close(-9.21034037197618, TOLERANCE)
- @object.send(:log!, 0.000000000001e-15).should be_close(-62.1697975108392, TOLERANCE)
- @object.send(:log!, 1).should be_close(0.0, TOLERANCE)
- @object.send(:log!, 10).should be_close( 2.30258509299405, TOLERANCE)
- @object.send(:log!, 10e15).should be_close(36.8413614879047, TOLERANCE)
- end
-
- it "raises an Errno::EDOM if the argument is less than 0" do
- lambda { @object.send(:log!, -10) }.should raise_error(Errno::EDOM)
- end
-
- it "raises a TypeError when passed a Complex number" do
- lambda { @object.send(:log!, Complex(4, 5)) }.should raise_error(TypeError)
- end
-end
diff --git a/spec/ruby/library/complex/math/shared/log10.rb b/spec/ruby/library/complex/math/shared/log10.rb
deleted file mode 100644
index 13518f243e..0000000000
--- a/spec/ruby/library/complex/math/shared/log10.rb
+++ /dev/null
@@ -1,41 +0,0 @@
-require File.expand_path('../../fixtures/classes', __FILE__)
-
-describe :complex_math_log10, shared: true do
- it "returns the base-10 logarithm of the passed argument" do
- @object.send(:log10, 0.0001).should be_close(-4.0, TOLERANCE)
- @object.send(:log10, 0.000000000001e-15).should be_close(-27.0, TOLERANCE)
- @object.send(:log10, 1).should be_close(0.0, TOLERANCE)
- @object.send(:log10, 10).should be_close(1.0, TOLERANCE)
- @object.send(:log10, 10e15).should be_close(16.0, TOLERANCE)
- end
-
- it "returns the base-10 logarithm for Complex numbers" do
- @object.send(:log10, Complex(3, 4)).should be_close(Complex(0.698970004336019, 0.402719196273373), TOLERANCE)
- @object.send(:log10, Complex(-3, 4)).should be_close(Complex(0.698970004336019, 0.961657157568468), TOLERANCE)
- end
-
- # BUG: does not work correctly, because Math#log10
- # does not check for negative values
- #it "returns the base-10 logarithm for negative numbers as a Complex number" do
- # @object.send(:log10, -10).should be_close(Complex(2.30258509299405, 3.14159265358979), TOLERANCE)
- # @object.send(:log10, -20).should be_close(Complex(2.99573227355399, 3.14159265358979), TOLERANCE)
- #end
-end
-
-describe :complex_math_log10_bang, shared: true do
- it "returns the base-10 logarithm of the argument" do
- @object.send(:log10!, 0.0001).should be_close(-4.0, TOLERANCE)
- @object.send(:log10!, 0.000000000001e-15).should be_close(-27.0, TOLERANCE)
- @object.send(:log10!, 1).should be_close(0.0, TOLERANCE)
- @object.send(:log10!, 10).should be_close(1.0, TOLERANCE)
- @object.send(:log10!, 10e15).should be_close(16.0, TOLERANCE)
- end
-
- it "raises an Errno::EDOM when the passed argument is negative" do
- lambda { @object.send(:log10!, -10) }.should raise_error(Errno::EDOM)
- end
-
- it "raises a TypeError when passed a Complex number" do
- lambda { @object.send(:log10!, Complex(4, 5)) }.should raise_error(TypeError)
- end
-end
diff --git a/spec/ruby/library/complex/math/shared/sin.rb b/spec/ruby/library/complex/math/shared/sin.rb
deleted file mode 100644
index e5b207b456..0000000000
--- a/spec/ruby/library/complex/math/shared/sin.rb
+++ /dev/null
@@ -1,30 +0,0 @@
-require File.expand_path('../../fixtures/classes', __FILE__)
-
-describe :complex_math_sin, shared: true do
- it "returns the sine of the passed argument expressed in radians" do
- @object.send(:sin, CMath::PI).should be_close(0.0, TOLERANCE)
- @object.send(:sin, 0).should be_close(0.0, TOLERANCE)
- @object.send(:sin, CMath::PI/2).should be_close(1.0, TOLERANCE)
- @object.send(:sin, 3*Math::PI/2).should be_close(-1.0, TOLERANCE)
- @object.send(:sin, 2*Math::PI).should be_close(0.0, TOLERANCE)
- end
-
- it "returns the sine for Complex numbers" do
- @object.send(:sin, Complex(0, CMath::PI)).should be_close(Complex(0.0, 11.5487393572577), TOLERANCE)
- @object.send(:sin, Complex(3, 4)).should be_close(Complex(3.85373803791938, -27.0168132580039), TOLERANCE)
- end
-end
-
-describe :complex_math_sin_bang, shared: true do
- it "returns the sine of the passed argument expressed in radians" do
- @object.send(:sin!, CMath::PI).should be_close(0.0, TOLERANCE)
- @object.send(:sin!, 0).should be_close(0.0, TOLERANCE)
- @object.send(:sin!, CMath::PI/2).should be_close(1.0, TOLERANCE)
- @object.send(:sin!, 3*Math::PI/2).should be_close(-1.0, TOLERANCE)
- @object.send(:sin!, 2*Math::PI).should be_close(0.0, TOLERANCE)
- end
-
- it "raises a TypeError when passed a Complex number" do
- lambda { @object.send(:sin!, Complex(4, 5)) }.should raise_error(TypeError)
- end
-end
diff --git a/spec/ruby/library/complex/math/shared/sinh.rb b/spec/ruby/library/complex/math/shared/sinh.rb
deleted file mode 100644
index abbe2c6da0..0000000000
--- a/spec/ruby/library/complex/math/shared/sinh.rb
+++ /dev/null
@@ -1,28 +0,0 @@
-require File.expand_path('../../fixtures/classes', __FILE__)
-
-describe :complex_math_sinh, shared: true do
- it "returns the hyperbolic sin of the argument" do
- @object.send(:sinh, 0.0).should == 0.0
- @object.send(:sinh, -0.0).should == 0.0
- @object.send(:sinh, 1.5).should be_close(2.12927945509482, TOLERANCE)
- @object.send(:sinh, -2.8).should be_close(-8.19191835423591, TOLERANCE)
- end
-
- it "returns the hyperbolic sin for Complex numbers" do
- @object.send(:sinh, Complex(0, CMath::PI)).should be_close(Complex(-0.0, 1.22464679914735e-16), TOLERANCE)
- @object.send(:sinh, Complex(3, 4)).should be_close(Complex(-6.548120040911, -7.61923172032141), TOLERANCE)
- end
-end
-
-describe :complex_math_sinh_bang, shared: true do
- it "returns the hyperbolic sin of the argument" do
- @object.send(:sinh!, 0.0).should == 0.0
- @object.send(:sinh!, -0.0).should == 0.0
- @object.send(:sinh!, 1.5).should be_close(2.12927945509482, TOLERANCE)
- @object.send(:sinh!, -2.8).should be_close(-8.19191835423591, TOLERANCE)
- end
-
- it "raises a TypeError when passed a Complex number" do
- lambda { @object.send(:sinh!, Complex(4, 5)) }.should raise_error(TypeError)
- end
-end
diff --git a/spec/ruby/library/complex/math/shared/sqrt.rb b/spec/ruby/library/complex/math/shared/sqrt.rb
deleted file mode 100644
index 5125710119..0000000000
--- a/spec/ruby/library/complex/math/shared/sqrt.rb
+++ /dev/null
@@ -1,34 +0,0 @@
-require File.expand_path('../../fixtures/classes', __FILE__)
-
-describe :complex_math_sqrt, shared: true do
- it "returns the square root for positive numbers" do
- @object.send(:sqrt, 4).should == 2
- @object.send(:sqrt, 19.36).should == 4.4
- end
-
- it "returns the square root for negative numbers" do
- @object.send(:sqrt, -4).should == Complex(0, 2.0)
- @object.send(:sqrt, -19.36).should == Complex(0, 4.4)
- end
-
- it "returns the square root for Complex numbers" do
- @object.send(:sqrt, Complex(4, 5)).should be_close(Complex(2.2806933416653, 1.09615788950152), TOLERANCE)
- @object.send(:sqrt, Complex(4, -5)).should be_close(Complex(2.2806933416653, -1.09615788950152), TOLERANCE)
- end
-end
-
-describe :complex_math_sqrt_bang, shared: true do
- it "returns the square root for positive numbers" do
- @object.send(:sqrt!, 4).should == 2
- @object.send(:sqrt!, 19.36).should == 4.4
- end
-
- it "raises Errno::EDOM when the passed argument is negative" do
- lambda { @object.send(:sqrt!, -4) }.should raise_error(Errno::EDOM)
- lambda { @object.send(:sqrt!, -19.36) }.should raise_error(Errno::EDOM)
- end
-
- it "raises a TypeError when passed a Complex number" do
- lambda { @object.send(:sqrt!, Complex(4, 5)) }.should raise_error(TypeError)
- end
-end
diff --git a/spec/ruby/library/complex/math/shared/tan.rb b/spec/ruby/library/complex/math/shared/tan.rb
deleted file mode 100644
index 02a1880d27..0000000000
--- a/spec/ruby/library/complex/math/shared/tan.rb
+++ /dev/null
@@ -1,28 +0,0 @@
-require File.expand_path('../../fixtures/classes', __FILE__)
-
-describe :complex_math_tan, shared: true do
- it "returns the tangent of the argument" do
- @object.send(:tan, 0.0).should == 0.0
- @object.send(:tan, -0.0).should == -0.0
- @object.send(:tan, 4.22).should be_close(1.86406937682395, TOLERANCE)
- @object.send(:tan, -9.65).should be_close(-0.229109052606441, TOLERANCE)
- end
-
- it "returns the tangent for Complex numbers" do
- @object.send(:tan, Complex(0, CMath::PI)).should be_close(Complex(0.0, 0.99627207622075), TOLERANCE)
- @object.send(:tan, Complex(3, 4)).should be_close(Complex(-0.000187346204629452, 0.999355987381473), TOLERANCE)
- end
-end
-
-describe :complex_math_tan_bang, shared: true do
- it "returns the tangent of the argument" do
- @object.send(:tan!, 0.0).should == 0.0
- @object.send(:tan!, -0.0).should == -0.0
- @object.send(:tan!, 4.22).should be_close(1.86406937682395, TOLERANCE)
- @object.send(:tan!, -9.65).should be_close(-0.229109052606441, TOLERANCE)
- end
-
- it "raises a TypeError when passed a Complex number" do
- lambda { @object.send(:tan!, Complex(4, 5)) }.should raise_error(TypeError)
- end
-end
diff --git a/spec/ruby/library/complex/math/shared/tanh.rb b/spec/ruby/library/complex/math/shared/tanh.rb
deleted file mode 100644
index a26b1349f6..0000000000
--- a/spec/ruby/library/complex/math/shared/tanh.rb
+++ /dev/null
@@ -1,32 +0,0 @@
-require File.expand_path('../../fixtures/classes', __FILE__)
-
-describe :complex_math_tanh, shared: true do
- it "returns the hyperbolic tangent of the argument" do
- @object.send(:tanh, 0.0).should == 0.0
- @object.send(:tanh, -0.0).should == -0.0
- @object.send(:tanh, infinity_value).should == 1.0
- @object.send(:tanh, -infinity_value).should == -1.0
- @object.send(:tanh, 2.5).should be_close(0.98661429815143, TOLERANCE)
- @object.send(:tanh, -4.892).should be_close(-0.999887314427707, TOLERANCE)
- end
-
- it "returns the hyperbolic tangent for Complex numbers" do
- @object.send(:tanh, Complex(0, CMath::PI)).should be_close(Complex(0.0, -1.22464679914735e-16), TOLERANCE)
- @object.send(:tanh, Complex(3, 4)).should be_close(Complex(1.00070953606723, 0.00490825806749599), TOLERANCE)
- end
-end
-
-describe :complex_math_tanh_bang, shared: true do
- it "returns the hyperbolic tangent of the argument" do
- @object.send(:tanh!, 0.0).should == 0.0
- @object.send(:tanh!, -0.0).should == -0.0
- @object.send(:tanh!, infinity_value).should == 1.0
- @object.send(:tanh!, -infinity_value).should == -1.0
- @object.send(:tanh!, 2.5).should be_close(0.98661429815143, TOLERANCE)
- @object.send(:tanh!, -4.892).should be_close(-0.999887314427707, TOLERANCE)
- end
-
- it "raises a TypeError when passed a Complex number" do
- lambda { @object.send(:tanh!, Complex(4, 5)) }.should raise_error(TypeError)
- end
-end
diff --git a/spec/ruby/library/complex/math/sin_spec.rb b/spec/ruby/library/complex/math/sin_spec.rb
deleted file mode 100644
index bbc36ecaab..0000000000
--- a/spec/ruby/library/complex/math/sin_spec.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'complex'
-require File.expand_path('../shared/sin', __FILE__)
-
-describe "Math#sin" do
- it_behaves_like :complex_math_sin, :_, IncludesMath.new
-
- it "is a private instance method" do
- IncludesMath.should have_private_instance_method(:sin)
- end
-end
-
-describe "Math.sin" do
- it_behaves_like :complex_math_sin, :_, CMath
-end
diff --git a/spec/ruby/library/complex/math/sinh_spec.rb b/spec/ruby/library/complex/math/sinh_spec.rb
deleted file mode 100644
index 25a41fbc45..0000000000
--- a/spec/ruby/library/complex/math/sinh_spec.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'complex'
-require File.expand_path('../shared/sinh', __FILE__)
-
-describe "Math#sinh" do
- it_behaves_like :complex_math_sinh, :_, IncludesMath.new
-
- it "is a private instance method" do
- IncludesMath.should have_private_instance_method(:sinh)
- end
-end
-
-describe "Math.sinh" do
- it_behaves_like :complex_math_sinh, :_, CMath
-end
diff --git a/spec/ruby/library/complex/math/sqrt_spec.rb b/spec/ruby/library/complex/math/sqrt_spec.rb
deleted file mode 100644
index 19d58ce373..0000000000
--- a/spec/ruby/library/complex/math/sqrt_spec.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'complex'
-require File.expand_path('../shared/sqrt', __FILE__)
-
-describe "Math#sqrt" do
- it_behaves_like :complex_math_sqrt, :_, IncludesMath.new
-
- it "is a private instance method" do
- IncludesMath.should have_private_instance_method(:sqrt)
- end
-end
-
-describe "Math.sqrt" do
- it_behaves_like :complex_math_sqrt, :_, CMath
-end
diff --git a/spec/ruby/library/complex/math/tan_spec.rb b/spec/ruby/library/complex/math/tan_spec.rb
deleted file mode 100644
index 3c5bc6b129..0000000000
--- a/spec/ruby/library/complex/math/tan_spec.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'complex'
-require File.expand_path('../shared/tan', __FILE__)
-
-describe "Math#tan" do
- it_behaves_like :complex_math_tan, :_, IncludesMath.new
-
- it "is a private instance method" do
- IncludesMath.should have_private_instance_method(:tan)
- end
-end
-
-describe "Math.tan" do
- it_behaves_like :complex_math_tan, :_, CMath
-end
diff --git a/spec/ruby/library/complex/math/tanh_spec.rb b/spec/ruby/library/complex/math/tanh_spec.rb
deleted file mode 100644
index f9d99347b8..0000000000
--- a/spec/ruby/library/complex/math/tanh_spec.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'complex'
-require File.expand_path('../shared/tanh', __FILE__)
-
-describe "Math#tanh" do
- it_behaves_like :complex_math_tanh, :_, IncludesMath.new
-
- it "is a private instance method" do
- IncludesMath.should have_private_instance_method(:tanh)
- end
-end
-
-describe "Math.tanh" do
- it_behaves_like :complex_math_tanh, :_, CMath
-end
diff --git a/spec/ruby/library/complex/numeric/im_spec.rb b/spec/ruby/library/complex/numeric/im_spec.rb
deleted file mode 100644
index f76796a947..0000000000
--- a/spec/ruby/library/complex/numeric/im_spec.rb
+++ /dev/null
@@ -1,3 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-
-require 'complex'
diff --git a/spec/ruby/library/conditionvariable/broadcast_spec.rb b/spec/ruby/library/conditionvariable/broadcast_spec.rb
deleted file mode 100644
index 129b124c1a..0000000000
--- a/spec/ruby/library/conditionvariable/broadcast_spec.rb
+++ /dev/null
@@ -1,67 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require 'thread'
-
-describe "ConditionVariable#broadcast" do
- it "returns self if nothing to broadcast to" do
- cv = ConditionVariable.new
- cv.broadcast.should == cv
- end
-
- it "returns self if something is waiting for a broadcast" do
- m = Mutex.new
- cv = ConditionVariable.new
- in_synchronize = false
-
- th = Thread.new do
- m.synchronize do
- in_synchronize = true
- cv.wait(m)
- end
- end
-
- # wait for m to acquire the mutex
- Thread.pass until in_synchronize
- # wait until th is sleeping (ie waiting)
- Thread.pass while th.status and th.status != "sleep"
-
- m.synchronize { cv.broadcast }.should == cv
-
- th.join
- end
-
- it "releases all threads waiting in line for this resource" do
- m = Mutex.new
- cv = ConditionVariable.new
- threads = []
- r1 = []
- r2 = []
-
- # large number to attempt to cause race conditions
- 100.times do |i|
- threads << Thread.new(i) do |tid|
- m.synchronize do
- r1 << tid
- cv.wait(m)
- r2 << tid
- end
- end
- end
-
- # wait for all threads to acquire the mutex the first time
- Thread.pass until m.synchronize { r1.size == threads.size }
- # wait until all threads are sleeping (ie waiting)
- Thread.pass until threads.all? {|th| th.status == "sleep" }
-
- r2.should be_empty
- m.synchronize do
- cv.broadcast
- end
-
- threads.each {|t| t.join }
-
- # ensure that all threads that enter cv.wait are released
- r2.sort.should == r1.sort
- # note that order is not specified as broadcast results in a race
- # condition on regaining the lock m
- end
-end
diff --git a/spec/ruby/library/conditionvariable/marshal_dump_spec.rb b/spec/ruby/library/conditionvariable/marshal_dump_spec.rb
deleted file mode 100644
index f32b784eaa..0000000000
--- a/spec/ruby/library/conditionvariable/marshal_dump_spec.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require 'thread'
-
-describe "ConditionVariable#marshal_dump" do
- it "raises a TypeError" do
- cv = ConditionVariable.new
- -> { cv.marshal_dump }.should raise_error(TypeError, /can't dump/)
- end
-end
diff --git a/spec/ruby/library/conditionvariable/signal_spec.rb b/spec/ruby/library/conditionvariable/signal_spec.rb
deleted file mode 100644
index 38bee8984b..0000000000
--- a/spec/ruby/library/conditionvariable/signal_spec.rb
+++ /dev/null
@@ -1,69 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require 'thread'
-
-describe "ConditionVariable#signal" do
- it "returns self if nothing to signal" do
- cv = ConditionVariable.new
- cv.signal.should == cv
- end
-
- it "returns self if something is waiting for a signal" do
- m = Mutex.new
- cv = ConditionVariable.new
- in_synchronize = false
-
- th = Thread.new do
- m.synchronize do
- in_synchronize = true
- cv.wait(m)
- end
- end
-
- # wait for m to acquire the mutex
- Thread.pass until in_synchronize
- # wait until th is sleeping (ie waiting)
- Thread.pass while th.status and th.status != "sleep"
-
- m.synchronize { cv.signal }.should == cv
-
- th.join
- end
-
- it "releases the first thread waiting in line for this resource" do
- m = Mutex.new
- cv = ConditionVariable.new
- threads = []
- r1 = []
- r2 = []
-
- # large number to attempt to cause race conditions
- 100.times do |i|
- threads << Thread.new(i) do |tid|
- m.synchronize do
- r1 << tid
- cv.wait(m)
- r2 << tid
- end
- end
- end
-
- # wait for all threads to acquire the mutex the first time
- Thread.pass until m.synchronize { r1.size == threads.size }
- # wait until all threads are sleeping (ie waiting)
- Thread.pass until threads.all? {|th| th.status == "sleep" }
-
- r2.should be_empty
- 100.times do |i|
- m.synchronize do
- cv.signal
- end
- Thread.pass until r2.size == i+1
- end
-
- threads.each {|t| t.join }
-
- # ensure that all the threads that went into the cv.wait are
- # released in the same order
- r2.should == r1
- end
-end
diff --git a/spec/ruby/library/conditionvariable/wait_spec.rb b/spec/ruby/library/conditionvariable/wait_spec.rb
deleted file mode 100644
index ddf6474212..0000000000
--- a/spec/ruby/library/conditionvariable/wait_spec.rb
+++ /dev/null
@@ -1,25 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require 'thread'
-
-describe "ConditionVariable#wait" do
- it "returns self" do
- m = Mutex.new
- cv = ConditionVariable.new
- in_synchronize = false
-
- th = Thread.new do
- m.synchronize do
- in_synchronize = true
- cv.wait(m).should == cv
- end
- end
-
- # wait for m to acquire the mutex
- Thread.pass until in_synchronize
- # wait until th is sleeping (ie waiting)
- Thread.pass while th.status and th.status != "sleep"
-
- m.synchronize { cv.signal }
- th.join
- end
-end
diff --git a/spec/ruby/library/coverage/fixtures/code_with_begin.rb b/spec/ruby/library/coverage/fixtures/code_with_begin.rb
new file mode 100644
index 0000000000..9a6384e337
--- /dev/null
+++ b/spec/ruby/library/coverage/fixtures/code_with_begin.rb
@@ -0,0 +1,3 @@
+begin
+ 'coverage with begin'
+end
diff --git a/spec/ruby/library/coverage/fixtures/eval_code.rb b/spec/ruby/library/coverage/fixtures/eval_code.rb
new file mode 100644
index 0000000000..8ab82218f3
--- /dev/null
+++ b/spec/ruby/library/coverage/fixtures/eval_code.rb
@@ -0,0 +1,11 @@
+5 + 5
+
+module CoverageSpecs
+
+ class_eval <<-RUBY, __FILE__, __LINE__ + 1
+ attr_reader :ok
+ RUBY
+
+end
+
+4 + 4
diff --git a/spec/ruby/library/coverage/fixtures/spec_helper.rb b/spec/ruby/library/coverage/fixtures/spec_helper.rb
deleted file mode 100644
index 19094e5c36..0000000000
--- a/spec/ruby/library/coverage/fixtures/spec_helper.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-module CoverageSpecs
- # Clear old results from the result hash
- # https://bugs.ruby-lang.org/issues/12220
- def self.filtered_result
- result = Coverage.result
- ruby_version_is ""..."2.4" do
- result = result.reject { |_k, v| v.empty? }
- end
- result
- end
-end
diff --git a/spec/ruby/library/coverage/peek_result_spec.rb b/spec/ruby/library/coverage/peek_result_spec.rb
index 44a2e2b83e..9d7c890faa 100644
--- a/spec/ruby/library/coverage/peek_result_spec.rb
+++ b/spec/ruby/library/coverage/peek_result_spec.rb
@@ -1,67 +1,64 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require fixture __FILE__, 'spec_helper'
+require_relative '../../spec_helper'
require 'coverage'
-ruby_version_is '2.3' do
- describe 'Coverage.peek_result' do
- before :all do
- @class_file = fixture __FILE__, 'some_class.rb'
- @second_class_file = fixture __FILE__, 'second_class.rb'
- end
+describe 'Coverage.peek_result' do
+ before :all do
+ @class_file = fixture __FILE__, 'some_class.rb'
+ @second_class_file = fixture __FILE__, 'second_class.rb'
+ end
- after :each do
- $LOADED_FEATURES.delete(@class_file)
- $LOADED_FEATURES.delete(@second_class_file)
- end
+ after :each do
+ $LOADED_FEATURES.delete(@class_file)
+ $LOADED_FEATURES.delete(@second_class_file)
+ end
- it 'returns the result so far' do
- Coverage.start
- require @class_file.chomp('.rb')
- result = Coverage.peek_result
- Coverage.result
+ it 'returns the result so far' do
+ Coverage.start
+ require @class_file.chomp('.rb')
+ result = Coverage.peek_result
+ Coverage.result
- result.should == {
- @class_file => [
- nil, nil, 1, nil, nil, 1, nil, nil, 0, nil, nil, nil, nil, nil, nil, nil
- ]
- }
- end
+ result.should == {
+ @class_file => [
+ nil, nil, 1, nil, nil, 1, nil, nil, 0, nil, nil, nil, nil, nil, nil, nil
+ ]
+ }
+ end
- it 'immediate second call returns same result' do
- Coverage.start
- require @class_file.chomp('.rb')
- result1 = Coverage.peek_result
- result2 = Coverage.peek_result
- Coverage.result
+ it 'immediate second call returns same result' do
+ Coverage.start
+ require @class_file.chomp('.rb')
+ result1 = Coverage.peek_result
+ result2 = Coverage.peek_result
+ Coverage.result
- result2.should == result1
- end
+ result2.should == result1
+ end
- it 'second call after require returns accumulated result' do
- Coverage.start
- require @class_file.chomp('.rb')
- Coverage.peek_result
- require @second_class_file.chomp('.rb')
- result = Coverage.peek_result
- Coverage.result
+ it 'second call after require returns accumulated result' do
+ Coverage.start
+ require @class_file.chomp('.rb')
+ Coverage.peek_result
+ require @second_class_file.chomp('.rb')
+ result = Coverage.peek_result
+ Coverage.result
- result.should == {
- @class_file => [
- nil, nil, 1, nil, nil, 1, nil, nil, 0, nil, nil, nil, nil, nil, nil, nil
- ],
- @second_class_file => [
- 1, 1, 0, nil, nil
- ]
- }
- end
+ result.should == {
+ @class_file => [
+ nil, nil, 1, nil, nil, 1, nil, nil, 0, nil, nil, nil, nil, nil, nil, nil
+ ],
+ @second_class_file => [
+ 1, 1, 0, nil, nil
+ ]
+ }
+ end
- it 'call right before Coverage.result should give equal result' do
- Coverage.start
- require @class_file.chomp('.rb')
- result1 = Coverage.peek_result
- result2 = Coverage.result
+ it 'call right before Coverage.result should give equal result' do
+ Coverage.start
+ require @class_file.chomp('.rb')
+ result1 = Coverage.peek_result
+ result2 = Coverage.result
- result1.should == result2
- end
+ result1.should == result2
end
end
diff --git a/spec/ruby/library/coverage/result_spec.rb b/spec/ruby/library/coverage/result_spec.rb
index adcc51dc80..2e7d598bb8 100644
--- a/spec/ruby/library/coverage/result_spec.rb
+++ b/spec/ruby/library/coverage/result_spec.rb
@@ -1,22 +1,31 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require fixture __FILE__, 'spec_helper'
+require_relative '../../spec_helper'
require 'coverage'
describe 'Coverage.result' do
before :all do
@class_file = fixture __FILE__, 'some_class.rb'
@config_file = fixture __FILE__, 'start_coverage.rb'
+ @eval_code_file = fixture __FILE__, 'eval_code.rb'
+ @with_begin_file = fixture __FILE__, 'code_with_begin.rb'
+ end
+
+ before :each do
+ Coverage.running?.should == false
end
after :each do
$LOADED_FEATURES.delete(@class_file)
$LOADED_FEATURES.delete(@config_file)
+ $LOADED_FEATURES.delete(@eval_code_file)
+ $LOADED_FEATURES.delete(@with_begin_file)
+
+ Coverage.result if Coverage.running?
end
it 'gives the covered files as a hash with arrays of count or nil' do
Coverage.start
require @class_file.chomp('.rb')
- result = CoverageSpecs.filtered_result
+ result = Coverage.result
result.should == {
@class_file => [
@@ -25,9 +34,42 @@ describe 'Coverage.result' do
}
end
+ it 'returns results for each mode separately when enabled :all modes' do
+ Coverage.start(:all)
+ require @class_file.chomp('.rb')
+ result = Coverage.result
+
+ result.should == {
+ @class_file => {
+ lines: [
+ nil, nil, 1, nil, nil, 1, nil, nil, 0, nil, nil, nil, nil, nil, nil, nil
+ ],
+ branches: {},
+ methods: {
+ [SomeClass, :some_method, 6, 2, 11, 5] => 0
+ }
+ }
+ }
+ end
+
+ it 'returns results for each mode separately when enabled any mode explicitly' do
+ Coverage.start(lines: true)
+ require @class_file.chomp('.rb')
+ result = Coverage.result
+
+ result.should == {
+ @class_file =>
+ {
+ lines: [
+ nil, nil, 1, nil, nil, 1, nil, nil, 0, nil, nil, nil, nil, nil, nil, nil
+ ]
+ }
+ }
+ end
+
it 'no requires/loads should give empty hash' do
Coverage.start
- result = CoverageSpecs.filtered_result
+ result = Coverage.result
result.should == {}
end
@@ -36,18 +78,19 @@ describe 'Coverage.result' do
Coverage.start
require @class_file.chomp('.rb')
Coverage.result
- -> { Coverage.result }
- .should raise_error(RuntimeError, 'coverage measurement is not enabled')
+ -> {
+ Coverage.result
+ }.should.raise(RuntimeError, 'coverage measurement is not enabled')
end
it 'second run should give same result' do
Coverage.start
load @class_file
- result1 = CoverageSpecs.filtered_result
+ result1 = Coverage.result
Coverage.start
load @class_file
- result2 = CoverageSpecs.filtered_result
+ result2 = Coverage.result
result2.should == result1
end
@@ -58,21 +101,243 @@ describe 'Coverage.result' do
Coverage.result
Coverage.start
- result = CoverageSpecs.filtered_result
+ result = Coverage.result
result.should == {}
end
- it 'second Coverage.start does nothing' do
- Coverage.start
+ it 'does not include the file starting coverage since it is not tracked' do
require @config_file.chomp('.rb')
- result = CoverageSpecs.filtered_result
+ Coverage.result.should_not.include?(@config_file)
+ end
+
+ it 'returns the correct results when eval coverage is enabled' do
+ Coverage.supported?(:eval).should == true
- result.should == { @config_file => [1, 1, 1] }
+ Coverage.start(lines: true, eval: true)
+ require @eval_code_file.chomp('.rb')
+ result = Coverage.result
+
+ result.should == {
+ @eval_code_file => {
+ lines: [1, nil, 1, nil, 1, 1, nil, nil, nil, nil, 1]
+ }
+ }
end
- it 'does not include the file starting coverage since it is not tracked' do
- require @config_file.chomp('.rb')
- CoverageSpecs.filtered_result.should_not include(@config_file)
+ it 'returns the correct results when eval coverage is disabled' do
+ Coverage.supported?(:eval).should == true
+
+ Coverage.start(lines: true, eval: false)
+ require @eval_code_file.chomp('.rb')
+ result = Coverage.result
+
+ result.should == {
+ @eval_code_file => {
+ lines: [1, nil, 1, nil, 1, nil, nil, nil, nil, nil, 1]
+ }
+ }
+ end
+
+ it "disables coverage measurement when stop option is not specified" do
+ Coverage.start
+ require @class_file.chomp('.rb')
+
+ Coverage.result
+ Coverage.running?.should == false
+ end
+
+ it "disables coverage measurement when stop: true option is specified" do
+ Coverage.start
+ require @class_file.chomp('.rb')
+
+ -> {
+ Coverage.result(stop: true)
+ }.should complain(/warning: stop implies clear/)
+
+ Coverage.running?.should == false
+ end
+
+ it "does not disable coverage measurement when stop: false option is specified" do
+ Coverage.start
+ require @class_file.chomp('.rb')
+
+ Coverage.result(stop: false)
+ Coverage.running?.should == true
+ end
+
+ it "does not disable coverage measurement when stop option is not specified but clear: true specified" do
+ Coverage.start
+ require @class_file.chomp('.rb')
+
+ Coverage.result(clear: true)
+ Coverage.running?.should == true
+ end
+
+ it "does not disable coverage measurement when stop option is not specified but clear: false specified" do
+ Coverage.start
+ require @class_file.chomp('.rb')
+
+ Coverage.result(clear: false)
+ Coverage.running?.should == true
+ end
+
+ it "disables coverage measurement when stop: true and clear: true specified" do
+ Coverage.start
+ require @class_file.chomp('.rb')
+
+ Coverage.result(stop: true, clear: true)
+ Coverage.running?.should == false
+ end
+
+ it "disables coverage measurement when stop: true and clear: false specified" do
+ Coverage.start
+ require @class_file.chomp('.rb')
+
+ -> {
+ Coverage.result(stop: true, clear: false)
+ }.should complain(/warning: stop implies clear/)
+
+ Coverage.running?.should == false
+ end
+
+ it "does not disable coverage measurement when stop: false and clear: true specified" do
+ Coverage.start
+ require @class_file.chomp('.rb')
+
+ Coverage.result(stop: false, clear: true)
+ Coverage.running?.should == true
+ end
+
+ it "does not disable coverage measurement when stop: false and clear: false specified" do
+ Coverage.start
+ require @class_file.chomp('.rb')
+
+ Coverage.result(stop: false, clear: false)
+ Coverage.running?.should == true
+ end
+
+ it "resets counters (remove them) when stop: true specified but clear option is not specified" do
+ Coverage.start
+ require @class_file.chomp('.rb')
+
+ -> {
+ Coverage.result(stop: true) # clears counters
+ }.should complain(/warning: stop implies clear/)
+
+ Coverage.start
+ Coverage.peek_result.should == {}
+ end
+
+ it "resets counters (remove them) when stop: true and clear: true specified" do
+ Coverage.start
+ require @class_file.chomp('.rb')
+
+ Coverage.result(stop: true, clear: true) # clears counters
+
+ Coverage.start
+ Coverage.peek_result.should == {}
+ end
+
+ it "resets counters (remove them) when stop: true and clear: false specified" do
+ Coverage.start
+ require @class_file.chomp('.rb')
+
+ -> {
+ Coverage.result(stop: true, clear: false) # clears counters
+ }.should complain(/warning: stop implies clear/)
+
+ Coverage.start
+ Coverage.peek_result.should == {}
+ end
+
+ it "resets counters (remove them) when both stop and clear options are not specified" do
+ Coverage.start
+ require @class_file.chomp('.rb')
+
+ Coverage.result # clears counters
+
+ Coverage.start
+ Coverage.peek_result.should == {}
+ end
+
+ it "clears counters (sets 0 values) when stop is not specified but clear: true specified" do
+ Coverage.start
+ require @class_file.chomp('.rb')
+
+ Coverage.result(clear: true) # clears counters
+
+ Coverage.peek_result.should == {
+ @class_file => [
+ nil, nil, 0, nil, nil, 0, nil, nil, 0, nil, nil, nil, nil, nil, nil, nil
+ ]
+ }
+ end
+
+ it "does not clear counters when stop is not specified but clear: false specified" do
+ Coverage.start
+ require @class_file.chomp('.rb')
+
+ result = Coverage.result(clear: false) # doesn't clear counters
+ result.should == {
+ @class_file => [
+ nil, nil, 1, nil, nil, 1, nil, nil, 0, nil, nil, nil, nil, nil, nil, nil
+ ]
+ }
+
+ Coverage.peek_result.should == result
+ end
+
+ it "does not clear counters when stop: false and clear is not specified" do
+ Coverage.start
+ require @class_file.chomp('.rb')
+
+ result = Coverage.result(stop: false) # doesn't clear counters
+ result.should == {
+ @class_file => [
+ nil, nil, 1, nil, nil, 1, nil, nil, 0, nil, nil, nil, nil, nil, nil, nil
+ ]
+ }
+
+ Coverage.peek_result.should == result
+ end
+
+ it "clears counters (sets 0 values) when stop: false and clear: true specified" do
+ Coverage.start
+ require @class_file.chomp('.rb')
+
+ Coverage.result(stop: false, clear: true) # clears counters
+
+ Coverage.peek_result.should == {
+ @class_file => [
+ nil, nil, 0, nil, nil, 0, nil, nil, 0, nil, nil, nil, nil, nil, nil, nil
+ ]
+ }
+ end
+
+ it "does not clear counters when stop: false and clear: false specified" do
+ Coverage.start
+ require @class_file.chomp('.rb')
+
+ result = Coverage.result(stop: false, clear: false) # doesn't clear counters
+ result.should == {
+ @class_file => [
+ nil, nil, 1, nil, nil, 1, nil, nil, 0, nil, nil, nil, nil, nil, nil, nil
+ ]
+ }
+
+ Coverage.peek_result.should == result
+ end
+
+ it 'covers 100% lines with begin' do
+ Coverage.start
+ require @with_begin_file.chomp('.rb')
+ result = Coverage.result
+
+ result.should == {
+ @with_begin_file => [
+ nil, 1, nil
+ ]
+ }
end
end
diff --git a/spec/ruby/library/coverage/running_spec.rb b/spec/ruby/library/coverage/running_spec.rb
new file mode 100644
index 0000000000..e9cc7ada5a
--- /dev/null
+++ b/spec/ruby/library/coverage/running_spec.rb
@@ -0,0 +1,20 @@
+require_relative '../../spec_helper'
+require 'coverage'
+
+describe 'Coverage.running?' do
+ it "returns false if coverage is not started" do
+ Coverage.running?.should == false
+ end
+
+ it "returns true if coverage is started" do
+ Coverage.start
+ Coverage.running?.should == true
+ Coverage.result
+ end
+
+ it "returns false if coverage was started and stopped" do
+ Coverage.start
+ Coverage.result
+ Coverage.running?.should == false
+ end
+end
diff --git a/spec/ruby/library/coverage/start_spec.rb b/spec/ruby/library/coverage/start_spec.rb
index 6b4ccbb043..11777347a2 100644
--- a/spec/ruby/library/coverage/start_spec.rb
+++ b/spec/ruby/library/coverage/start_spec.rb
@@ -1,6 +1,87 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'coverage'
describe 'Coverage.start' do
- it 'needs to be reviewed for spec completeness'
+ before :each do
+ Coverage.should_not.running?
+ end
+
+ after :each do
+ Coverage.result(stop: true, clear: true) if Coverage.running?
+ end
+
+ it "enables the coverage measurement" do
+ Coverage.start
+ Coverage.should.running?
+ end
+
+ it "returns nil" do
+ Coverage.start.should == nil
+ end
+
+ it 'raises error when repeated Coverage.start call happens' do
+ Coverage.start
+
+ -> {
+ Coverage.start
+ }.should.raise(RuntimeError, 'coverage measurement is already setup')
+ end
+
+ it "accepts :all optional argument" do
+ Coverage.start(:all)
+ Coverage.should.running?
+ end
+
+ it "accepts lines: optional keyword argument" do
+ Coverage.start(lines: true)
+ Coverage.should.running?
+ end
+
+ it "accepts branches: optional keyword argument" do
+ Coverage.start(branches: true)
+ Coverage.should.running?
+ end
+
+ it "accepts methods: optional keyword argument" do
+ Coverage.start(methods: true)
+ Coverage.should.running?
+ end
+
+ it "accepts eval: optional keyword argument" do
+ Coverage.start(eval: true)
+ Coverage.should.running?
+ end
+
+ it "accepts oneshot_lines: optional keyword argument" do
+ Coverage.start(oneshot_lines: true)
+ Coverage.should.running?
+ end
+
+ it "ignores unknown keyword arguments" do
+ Coverage.start(foo: true)
+ Coverage.should.running?
+ end
+
+ it "expects a Hash if not passed :all" do
+ -> {
+ Coverage.start(42)
+ }.should.raise(TypeError, "no implicit conversion of Integer into Hash")
+ end
+
+ it "does not accept both lines: and oneshot_lines: keyword arguments" do
+ -> {
+ Coverage.start(lines: true, oneshot_lines: true)
+ }.should.raise(RuntimeError, "cannot enable lines and oneshot_lines simultaneously")
+ end
+
+ it "enables the coverage measurement if passed options with `false` value" do
+ Coverage.start(lines: false, branches: false, methods: false, eval: false, oneshot_lines: false)
+ Coverage.should.running?
+ end
+
+ it "measures coverage within eval" do
+ Coverage.start(lines: true, eval: true)
+ eval("Object.new\n"*3, binding, "test.rb", 1)
+ Coverage.result["test.rb"].should == {lines: [1, 1, 1]}
+ end
end
diff --git a/spec/ruby/library/coverage/supported_spec.rb b/spec/ruby/library/coverage/supported_spec.rb
new file mode 100644
index 0000000000..fcf8a76d79
--- /dev/null
+++ b/spec/ruby/library/coverage/supported_spec.rb
@@ -0,0 +1,30 @@
+require_relative '../../spec_helper'
+require 'coverage'
+
+describe "Coverage.supported?" do
+ it "returns true or false if coverage measurement is supported for the given mode" do
+ [true, false].should.include?(Coverage.supported?(:lines))
+ [true, false].should.include?(Coverage.supported?(:branches))
+ [true, false].should.include?(Coverage.supported?(:methods))
+ [true, false].should.include?(Coverage.supported?(:eval))
+ end
+
+ it "returns false for not existing modes" do
+ Coverage.supported?(:foo).should == false
+ Coverage.supported?(:bar).should == false
+ end
+
+ it "raise TypeError if argument is not Symbol" do
+ -> {
+ Coverage.supported?("lines")
+ }.should.raise(TypeError, "wrong argument type String (expected Symbol)")
+
+ -> {
+ Coverage.supported?([])
+ }.should.raise(TypeError, "wrong argument type Array (expected Symbol)")
+
+ -> {
+ Coverage.supported?(1)
+ }.should.raise(TypeError, "wrong argument type Integer (expected Symbol)")
+ end
+end
diff --git a/spec/ruby/library/csv/basicwriter/close_on_terminate_spec.rb b/spec/ruby/library/csv/basicwriter/close_on_terminate_spec.rb
index 3a5dc85ed7..599e640624 100644
--- a/spec/ruby/library/csv/basicwriter/close_on_terminate_spec.rb
+++ b/spec/ruby/library/csv/basicwriter/close_on_terminate_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'csv'
describe "CSV::BasicWriter#close_on_terminate" do
diff --git a/spec/ruby/library/csv/basicwriter/initialize_spec.rb b/spec/ruby/library/csv/basicwriter/initialize_spec.rb
index 8ccef3fc0d..2c13c93f2e 100644
--- a/spec/ruby/library/csv/basicwriter/initialize_spec.rb
+++ b/spec/ruby/library/csv/basicwriter/initialize_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'csv'
describe "CSV::BasicWriter#initialize" do
diff --git a/spec/ruby/library/csv/basicwriter/terminate_spec.rb b/spec/ruby/library/csv/basicwriter/terminate_spec.rb
index 80581e4d61..8c53db3f0b 100644
--- a/spec/ruby/library/csv/basicwriter/terminate_spec.rb
+++ b/spec/ruby/library/csv/basicwriter/terminate_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'csv'
describe "CSV::BasicWriter#terminate" do
diff --git a/spec/ruby/library/csv/cell/data_spec.rb b/spec/ruby/library/csv/cell/data_spec.rb
index b2be38a5d6..aa034b0b62 100644
--- a/spec/ruby/library/csv/cell/data_spec.rb
+++ b/spec/ruby/library/csv/cell/data_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'csv'
describe "CSV::Cell#data" do
diff --git a/spec/ruby/library/csv/cell/initialize_spec.rb b/spec/ruby/library/csv/cell/initialize_spec.rb
index 3d10d7ada7..c9e506676c 100644
--- a/spec/ruby/library/csv/cell/initialize_spec.rb
+++ b/spec/ruby/library/csv/cell/initialize_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'csv'
describe "CSV::Cell#initialize" do
diff --git a/spec/ruby/library/csv/foreach_spec.rb b/spec/ruby/library/csv/foreach_spec.rb
index a967c450bf..36b3cd152f 100644
--- a/spec/ruby/library/csv/foreach_spec.rb
+++ b/spec/ruby/library/csv/foreach_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'csv'
describe "CSV.foreach" do
diff --git a/spec/ruby/library/csv/generate_line_spec.rb b/spec/ruby/library/csv/generate_line_spec.rb
index cc7c8de4f0..656365b109 100644
--- a/spec/ruby/library/csv/generate_line_spec.rb
+++ b/spec/ruby/library/csv/generate_line_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'csv'
describe "CSV.generate_line" do
diff --git a/spec/ruby/library/csv/generate_row_spec.rb b/spec/ruby/library/csv/generate_row_spec.rb
index d42c031ab1..79dfc34000 100644
--- a/spec/ruby/library/csv/generate_row_spec.rb
+++ b/spec/ruby/library/csv/generate_row_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'csv'
describe "CSV.generate_row" do
diff --git a/spec/ruby/library/csv/generate_spec.rb b/spec/ruby/library/csv/generate_spec.rb
index f583b5f536..62e19aa6e4 100644
--- a/spec/ruby/library/csv/generate_spec.rb
+++ b/spec/ruby/library/csv/generate_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'csv'
require 'tempfile'
@@ -21,12 +21,12 @@ describe "CSV.generate" do
end
it "appends and returns the argument itself" do
- str = ""
+ str = +""
csv_str = CSV.generate(str) do |csv|
csv.add_row [1, 2, 3]
csv << [4, 5, 6]
end
- csv_str.object_id.should == str.object_id
+ csv_str.should.equal? str
str.should == "1,2,3\n4,5,6\n"
end
end
diff --git a/spec/ruby/library/csv/iobuf/close_spec.rb b/spec/ruby/library/csv/iobuf/close_spec.rb
index d97841ad98..e2fda86080 100644
--- a/spec/ruby/library/csv/iobuf/close_spec.rb
+++ b/spec/ruby/library/csv/iobuf/close_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'csv'
describe "CSV::IOBuf#close" do
diff --git a/spec/ruby/library/csv/iobuf/initialize_spec.rb b/spec/ruby/library/csv/iobuf/initialize_spec.rb
index 5155e9047a..f08e82548a 100644
--- a/spec/ruby/library/csv/iobuf/initialize_spec.rb
+++ b/spec/ruby/library/csv/iobuf/initialize_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'csv'
describe "CSV::IOBuf#initialize" do
diff --git a/spec/ruby/library/csv/iobuf/read_spec.rb b/spec/ruby/library/csv/iobuf/read_spec.rb
index 0dbcccb7c2..b45334ee2a 100644
--- a/spec/ruby/library/csv/iobuf/read_spec.rb
+++ b/spec/ruby/library/csv/iobuf/read_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'csv'
describe "CSV::IOBuf#read" do
diff --git a/spec/ruby/library/csv/iobuf/terminate_spec.rb b/spec/ruby/library/csv/iobuf/terminate_spec.rb
index b74108cedc..69289e960c 100644
--- a/spec/ruby/library/csv/iobuf/terminate_spec.rb
+++ b/spec/ruby/library/csv/iobuf/terminate_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'csv'
describe "CSV::IOBuf#terminate" do
diff --git a/spec/ruby/library/csv/ioreader/close_on_terminate_spec.rb b/spec/ruby/library/csv/ioreader/close_on_terminate_spec.rb
index 75ce325a8b..4887ade1a1 100644
--- a/spec/ruby/library/csv/ioreader/close_on_terminate_spec.rb
+++ b/spec/ruby/library/csv/ioreader/close_on_terminate_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'csv'
describe "CSV::IOReader#close_on_terminate" do
diff --git a/spec/ruby/library/csv/ioreader/get_row_spec.rb b/spec/ruby/library/csv/ioreader/get_row_spec.rb
index 91049f014a..5fd2178b1b 100644
--- a/spec/ruby/library/csv/ioreader/get_row_spec.rb
+++ b/spec/ruby/library/csv/ioreader/get_row_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'csv'
describe "CSV::IOReader#get_row" do
diff --git a/spec/ruby/library/csv/ioreader/initialize_spec.rb b/spec/ruby/library/csv/ioreader/initialize_spec.rb
index 63a47eff73..4e8c0964df 100644
--- a/spec/ruby/library/csv/ioreader/initialize_spec.rb
+++ b/spec/ruby/library/csv/ioreader/initialize_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'csv'
describe "CSV::IOReader#initialize" do
diff --git a/spec/ruby/library/csv/ioreader/terminate_spec.rb b/spec/ruby/library/csv/ioreader/terminate_spec.rb
index 95259afd59..676cd03a0f 100644
--- a/spec/ruby/library/csv/ioreader/terminate_spec.rb
+++ b/spec/ruby/library/csv/ioreader/terminate_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'csv'
describe "CSV::IOReader#terminate" do
diff --git a/spec/ruby/library/csv/liberal_parsing_spec.rb b/spec/ruby/library/csv/liberal_parsing_spec.rb
index 99cedbcd22..9878658027 100644
--- a/spec/ruby/library/csv/liberal_parsing_spec.rb
+++ b/spec/ruby/library/csv/liberal_parsing_spec.rb
@@ -1,21 +1,19 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'csv'
-ruby_version_is '2.4' do
- describe "CSV#liberal_parsing?" do
- it "returns true if illegal input is handled" do
- csv = CSV.new("", liberal_parsing: true)
- csv.liberal_parsing?.should == true
- end
+describe "CSV#liberal_parsing?" do
+ it "returns true if illegal input is handled" do
+ csv = CSV.new("", liberal_parsing: true)
+ csv.should.liberal_parsing?
+ end
- it "returns false if illegal input is not handled" do
- csv = CSV.new("", liberal_parsing: false)
- csv.liberal_parsing?.should == false
- end
+ it "returns false if illegal input is not handled" do
+ csv = CSV.new("", liberal_parsing: false)
+ csv.should_not.liberal_parsing?
+ end
- it "returns false by default" do
- csv = CSV.new("")
- csv.liberal_parsing?.should == false
- end
+ it "returns false by default" do
+ csv = CSV.new("")
+ csv.should_not.liberal_parsing?
end
end
diff --git a/spec/ruby/library/csv/open_spec.rb b/spec/ruby/library/csv/open_spec.rb
index e0667921b9..2d310cda3e 100644
--- a/spec/ruby/library/csv/open_spec.rb
+++ b/spec/ruby/library/csv/open_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'csv'
describe "CSV.open" do
diff --git a/spec/ruby/library/csv/parse_spec.rb b/spec/ruby/library/csv/parse_spec.rb
index 47d7ebbde1..7000f03cda 100644
--- a/spec/ruby/library/csv/parse_spec.rb
+++ b/spec/ruby/library/csv/parse_spec.rb
@@ -1,11 +1,11 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'csv'
describe "CSV.parse" do
it "parses '' into []" do
result = CSV.parse ''
- result.should be_kind_of(Array)
+ result.should.is_a?(Array)
result.should == []
end
@@ -82,14 +82,12 @@ describe "CSV.parse" do
it "raises CSV::MalformedCSVError exception if input is illegal" do
-> {
CSV.parse('"quoted" field')
- }.should raise_error(CSV::MalformedCSVError)
+ }.should.raise(CSV::MalformedCSVError)
end
- ruby_version_is '2.4' do
- it "handles illegal input with the liberal_parsing option" do
- illegal_input = '"Johnson, Dwayne",Dwayne "The Rock" Johnson'
- result = CSV.parse(illegal_input, liberal_parsing: true)
- result.should == [["Johnson, Dwayne", 'Dwayne "The Rock" Johnson']]
- end
+ it "handles illegal input with the liberal_parsing option" do
+ illegal_input = '"Johnson, Dwayne",Dwayne "The Rock" Johnson'
+ result = CSV.parse(illegal_input, liberal_parsing: true)
+ result.should == [["Johnson, Dwayne", 'Dwayne "The Rock" Johnson']]
end
end
diff --git a/spec/ruby/library/csv/read_spec.rb b/spec/ruby/library/csv/read_spec.rb
index 9bdb214a6a..2e6bb65d56 100644
--- a/spec/ruby/library/csv/read_spec.rb
+++ b/spec/ruby/library/csv/read_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'csv'
describe "CSV.read" do
diff --git a/spec/ruby/library/csv/readlines_spec.rb b/spec/ruby/library/csv/readlines_spec.rb
index 452effd343..624f906489 100644
--- a/spec/ruby/library/csv/readlines_spec.rb
+++ b/spec/ruby/library/csv/readlines_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'csv'
describe "CSV.readlines" do
@@ -23,15 +23,13 @@ describe "CSV#readlines" do
it "raises CSV::MalformedCSVError exception if input is illegal" do
csv = CSV.new('"quoted" field')
- -> { csv.readlines }.should raise_error(CSV::MalformedCSVError)
+ -> { csv.readlines }.should.raise(CSV::MalformedCSVError)
end
- ruby_version_is '2.4' do
- it "handles illegal input with the liberal_parsing option" do
- illegal_input = '"Johnson, Dwayne",Dwayne "The Rock" Johnson'
- csv = CSV.new(illegal_input, liberal_parsing: true)
- result = csv.readlines
- result.should == [["Johnson, Dwayne", 'Dwayne "The Rock" Johnson']]
- end
+ it "handles illegal input with the liberal_parsing option" do
+ illegal_input = '"Johnson, Dwayne",Dwayne "The Rock" Johnson'
+ csv = CSV.new(illegal_input, liberal_parsing: true)
+ result = csv.readlines
+ result.should == [["Johnson, Dwayne", 'Dwayne "The Rock" Johnson']]
end
end
diff --git a/spec/ruby/library/csv/streambuf/add_buf_spec.rb b/spec/ruby/library/csv/streambuf/add_buf_spec.rb
index 274f40d496..58c530c500 100644
--- a/spec/ruby/library/csv/streambuf/add_buf_spec.rb
+++ b/spec/ruby/library/csv/streambuf/add_buf_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'csv'
describe "CSV::StreamBuf#add_buf" do
diff --git a/spec/ruby/library/csv/streambuf/buf_size_spec.rb b/spec/ruby/library/csv/streambuf/buf_size_spec.rb
index 30af8a44c0..1793c8b65e 100644
--- a/spec/ruby/library/csv/streambuf/buf_size_spec.rb
+++ b/spec/ruby/library/csv/streambuf/buf_size_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'csv'
describe "CSV::StreamBuf#buf_size" do
diff --git a/spec/ruby/library/csv/streambuf/drop_spec.rb b/spec/ruby/library/csv/streambuf/drop_spec.rb
index 47f32fc8c5..448f0a2196 100644
--- a/spec/ruby/library/csv/streambuf/drop_spec.rb
+++ b/spec/ruby/library/csv/streambuf/drop_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'csv'
describe "CSV::StreamBuf#drop" do
diff --git a/spec/ruby/library/csv/streambuf/element_reference_spec.rb b/spec/ruby/library/csv/streambuf/element_reference_spec.rb
index 4e4bab9a1e..5a75901830 100644
--- a/spec/ruby/library/csv/streambuf/element_reference_spec.rb
+++ b/spec/ruby/library/csv/streambuf/element_reference_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'csv'
describe "CSV::StreamBuf#[]" do
diff --git a/spec/ruby/library/csv/streambuf/get_spec.rb b/spec/ruby/library/csv/streambuf/get_spec.rb
index 4a8db3a970..2255e55e91 100644
--- a/spec/ruby/library/csv/streambuf/get_spec.rb
+++ b/spec/ruby/library/csv/streambuf/get_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'csv'
describe "CSV::StreamBuf#get" do
diff --git a/spec/ruby/library/csv/streambuf/idx_is_eos_spec.rb b/spec/ruby/library/csv/streambuf/idx_is_eos_spec.rb
index d48e6735f0..563b8b2d4a 100644
--- a/spec/ruby/library/csv/streambuf/idx_is_eos_spec.rb
+++ b/spec/ruby/library/csv/streambuf/idx_is_eos_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'csv'
describe "CSV::StreamBuf#idx_is_eos?" do
diff --git a/spec/ruby/library/csv/streambuf/initialize_spec.rb b/spec/ruby/library/csv/streambuf/initialize_spec.rb
index 0f76220d3d..1273c98094 100644
--- a/spec/ruby/library/csv/streambuf/initialize_spec.rb
+++ b/spec/ruby/library/csv/streambuf/initialize_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'csv'
describe "CSV::StreamBuf#initialize" do
diff --git a/spec/ruby/library/csv/streambuf/is_eos_spec.rb b/spec/ruby/library/csv/streambuf/is_eos_spec.rb
index 30167f30ff..a0a3c1e0b0 100644
--- a/spec/ruby/library/csv/streambuf/is_eos_spec.rb
+++ b/spec/ruby/library/csv/streambuf/is_eos_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'csv'
describe "CSV::StreamBuf#is_eos?" do
diff --git a/spec/ruby/library/csv/streambuf/read_spec.rb b/spec/ruby/library/csv/streambuf/read_spec.rb
index b07467bdb7..cf98c53409 100644
--- a/spec/ruby/library/csv/streambuf/read_spec.rb
+++ b/spec/ruby/library/csv/streambuf/read_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'csv'
describe "CSV::StreamBuf#read" do
diff --git a/spec/ruby/library/csv/streambuf/rel_buf_spec.rb b/spec/ruby/library/csv/streambuf/rel_buf_spec.rb
index e01dc39cf5..548e347200 100644
--- a/spec/ruby/library/csv/streambuf/rel_buf_spec.rb
+++ b/spec/ruby/library/csv/streambuf/rel_buf_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'csv'
describe "CSV::StreamBuf#rel_buf" do
diff --git a/spec/ruby/library/csv/streambuf/terminate_spec.rb b/spec/ruby/library/csv/streambuf/terminate_spec.rb
index 0c2bdedf6d..247b33184a 100644
--- a/spec/ruby/library/csv/streambuf/terminate_spec.rb
+++ b/spec/ruby/library/csv/streambuf/terminate_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'csv'
describe "CSV::StreamBuf#terminate" do
diff --git a/spec/ruby/library/csv/stringreader/get_row_spec.rb b/spec/ruby/library/csv/stringreader/get_row_spec.rb
index 8532fc234c..5cc3447061 100644
--- a/spec/ruby/library/csv/stringreader/get_row_spec.rb
+++ b/spec/ruby/library/csv/stringreader/get_row_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'csv'
describe "CSV::StringReader#get_row" do
diff --git a/spec/ruby/library/csv/stringreader/initialize_spec.rb b/spec/ruby/library/csv/stringreader/initialize_spec.rb
index 5ce8f652da..4e3634847e 100644
--- a/spec/ruby/library/csv/stringreader/initialize_spec.rb
+++ b/spec/ruby/library/csv/stringreader/initialize_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'csv'
describe "CSV::StringReader#initialize" do
diff --git a/spec/ruby/library/csv/writer/add_row_spec.rb b/spec/ruby/library/csv/writer/add_row_spec.rb
index 2ff5bdeee6..2f074b45db 100644
--- a/spec/ruby/library/csv/writer/add_row_spec.rb
+++ b/spec/ruby/library/csv/writer/add_row_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'csv'
describe "CSV::Writer#add_row" do
diff --git a/spec/ruby/library/csv/writer/append_spec.rb b/spec/ruby/library/csv/writer/append_spec.rb
index c6d96c72d6..4e1f6728c2 100644
--- a/spec/ruby/library/csv/writer/append_spec.rb
+++ b/spec/ruby/library/csv/writer/append_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'csv'
describe "CSV::Writer#<<" do
diff --git a/spec/ruby/library/csv/writer/close_spec.rb b/spec/ruby/library/csv/writer/close_spec.rb
index f51b9de73d..1a87094bb7 100644
--- a/spec/ruby/library/csv/writer/close_spec.rb
+++ b/spec/ruby/library/csv/writer/close_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'csv'
describe "CSV::Writer#close" do
diff --git a/spec/ruby/library/csv/writer/create_spec.rb b/spec/ruby/library/csv/writer/create_spec.rb
index 18cff887a6..a4514d5578 100644
--- a/spec/ruby/library/csv/writer/create_spec.rb
+++ b/spec/ruby/library/csv/writer/create_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'csv'
describe "CSV::Writer.create" do
diff --git a/spec/ruby/library/csv/writer/generate_spec.rb b/spec/ruby/library/csv/writer/generate_spec.rb
index 8930e26389..6ea9161777 100644
--- a/spec/ruby/library/csv/writer/generate_spec.rb
+++ b/spec/ruby/library/csv/writer/generate_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'csv'
describe "CSV::Writer.generate" do
diff --git a/spec/ruby/library/csv/writer/initialize_spec.rb b/spec/ruby/library/csv/writer/initialize_spec.rb
index 31b7d0fad8..6bba8f8d0a 100644
--- a/spec/ruby/library/csv/writer/initialize_spec.rb
+++ b/spec/ruby/library/csv/writer/initialize_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'csv'
describe "CSV::Writer#initialize" do
diff --git a/spec/ruby/library/csv/writer/terminate_spec.rb b/spec/ruby/library/csv/writer/terminate_spec.rb
index 9629c672b5..77136dd018 100644
--- a/spec/ruby/library/csv/writer/terminate_spec.rb
+++ b/spec/ruby/library/csv/writer/terminate_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'csv'
describe "CSV::Writer#terminate" do
diff --git a/spec/ruby/library/date/accessor_spec.rb b/spec/ruby/library/date/accessor_spec.rb
index 91e0c3fc88..74ed0e9c21 100644
--- a/spec/ruby/library/date/accessor_spec.rb
+++ b/spec/ruby/library/date/accessor_spec.rb
@@ -1,5 +1,5 @@
require 'date'
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Date#ajd" do
it "determines the Astronomical Julian day" do
@@ -38,7 +38,7 @@ describe "Date#year" do
end
describe "Date#yday" do
- it "determines the year" do
+ it "determines the day of the year" do
Date.civil(2007, 1, 17).yday.should == 17
Date.civil(2008, 10, 28).yday.should == 302
end
diff --git a/spec/ruby/library/date/add_month_spec.rb b/spec/ruby/library/date/add_month_spec.rb
index 46f1915b70..ab802ea97a 100644
--- a/spec/ruby/library/date/add_month_spec.rb
+++ b/spec/ruby/library/date/add_month_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date#>>" do
@@ -21,18 +21,18 @@ describe "Date#>>" do
end
it "raise a TypeError when passed a Symbol" do
- lambda { Date.civil(2007,2,27) >> :hello }.should raise_error(TypeError)
+ -> { Date.civil(2007,2,27) >> :hello }.should.raise(TypeError)
end
it "raise a TypeError when passed a String" do
- lambda { Date.civil(2007,2,27) >> "hello" }.should raise_error(TypeError)
+ -> { Date.civil(2007,2,27) >> "hello" }.should.raise(TypeError)
end
it "raise a TypeError when passed a Date" do
- lambda { Date.civil(2007,2,27) >> Date.new }.should raise_error(TypeError)
+ -> { Date.civil(2007,2,27) >> Date.new }.should.raise(TypeError)
end
it "raise a TypeError when passed an Object" do
- lambda { Date.civil(2007,2,27) >> Object.new }.should raise_error(TypeError)
+ -> { Date.civil(2007,2,27) >> Object.new }.should.raise(TypeError)
end
end
diff --git a/spec/ruby/library/date/add_spec.rb b/spec/ruby/library/date/add_spec.rb
index 022b793318..5e368decdc 100644
--- a/spec/ruby/library/date/add_spec.rb
+++ b/spec/ruby/library/date/add_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date#+" do
@@ -13,18 +13,18 @@ describe "Date#+" do
end
it "raises a TypeError when passed a Symbol" do
- lambda { Date.civil(2007,2,27) + :hello }.should raise_error(TypeError)
+ -> { Date.civil(2007,2,27) + :hello }.should.raise(TypeError)
end
it "raises a TypeError when passed a String" do
- lambda { Date.civil(2007,2,27) + "hello" }.should raise_error(TypeError)
+ -> { Date.civil(2007,2,27) + "hello" }.should.raise(TypeError)
end
it "raises a TypeError when passed a Date" do
- lambda { Date.civil(2007,2,27) + Date.new }.should raise_error(TypeError)
+ -> { Date.civil(2007,2,27) + Date.new }.should.raise(TypeError)
end
it "raises a TypeError when passed an Object" do
- lambda { Date.civil(2007,2,27) + Object.new }.should raise_error(TypeError)
+ -> { Date.civil(2007,2,27) + Object.new }.should.raise(TypeError)
end
end
diff --git a/spec/ruby/library/date/ajd_spec.rb b/spec/ruby/library/date/ajd_spec.rb
index fcbcea2426..10f1302354 100644
--- a/spec/ruby/library/date/ajd_spec.rb
+++ b/spec/ruby/library/date/ajd_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date#ajd" do
diff --git a/spec/ruby/library/date/ajd_to_amjd_spec.rb b/spec/ruby/library/date/ajd_to_amjd_spec.rb
index fc6a35d0c6..948f4c2236 100644
--- a/spec/ruby/library/date/ajd_to_amjd_spec.rb
+++ b/spec/ruby/library/date/ajd_to_amjd_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date.ajd_to_amjd" do
diff --git a/spec/ruby/library/date/ajd_to_jd_spec.rb b/spec/ruby/library/date/ajd_to_jd_spec.rb
index 1d8d6d0eb5..e55ce9f4f2 100644
--- a/spec/ruby/library/date/ajd_to_jd_spec.rb
+++ b/spec/ruby/library/date/ajd_to_jd_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date.ajd_to_jd" do
diff --git a/spec/ruby/library/date/amjd_spec.rb b/spec/ruby/library/date/amjd_spec.rb
index 212871ee18..ad7bc14965 100644
--- a/spec/ruby/library/date/amjd_spec.rb
+++ b/spec/ruby/library/date/amjd_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date#amjd" do
diff --git a/spec/ruby/library/date/amjd_to_ajd_spec.rb b/spec/ruby/library/date/amjd_to_ajd_spec.rb
index f45f202a40..66c26a16a8 100644
--- a/spec/ruby/library/date/amjd_to_ajd_spec.rb
+++ b/spec/ruby/library/date/amjd_to_ajd_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date.amjd_to_ajd" do
diff --git a/spec/ruby/library/date/append_spec.rb b/spec/ruby/library/date/append_spec.rb
index d90eff9a7a..4305a00321 100644
--- a/spec/ruby/library/date/append_spec.rb
+++ b/spec/ruby/library/date/append_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date#<<" do
diff --git a/spec/ruby/library/date/asctime_spec.rb b/spec/ruby/library/date/asctime_spec.rb
index 13dede0f05..e268ffe098 100644
--- a/spec/ruby/library/date/asctime_spec.rb
+++ b/spec/ruby/library/date/asctime_spec.rb
@@ -1,6 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date#asctime" do
- it "needs to be reviewed for spec completeness"
+ it "returns a canonical string representation of date" do
+ d = Date.today
+ d.asctime.should == d.strftime("%a %b %e %H:%M:%S %Y")
+ end
end
diff --git a/spec/ruby/library/date/boat_spec.rb b/spec/ruby/library/date/boat_spec.rb
index 3004c6bfbc..e4f1b797fc 100644
--- a/spec/ruby/library/date/boat_spec.rb
+++ b/spec/ruby/library/date/boat_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date#<=>" do
diff --git a/spec/ruby/library/date/case_compare_spec.rb b/spec/ruby/library/date/case_compare_spec.rb
index 2144a616a3..87d522ee6a 100644
--- a/spec/ruby/library/date/case_compare_spec.rb
+++ b/spec/ruby/library/date/case_compare_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date#===" do
diff --git a/spec/ruby/library/date/civil_spec.rb b/spec/ruby/library/date/civil_spec.rb
index 36e790aecd..1c780fce56 100644
--- a/spec/ruby/library/date/civil_spec.rb
+++ b/spec/ruby/library/date/civil_spec.rb
@@ -1,12 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/civil', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/civil'
require 'date'
-describe "Date#civil" do
- it_behaves_like(:date_civil, :civil)
-end
-
-
describe "Date.civil" do
- it "needs to be reviewed for spec completeness"
+ 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..8e2df79b90 100644
--- a/spec/ruby/library/date/commercial_spec.rb
+++ b/spec/ruby/library/date/commercial_spec.rb
@@ -1,12 +1,5 @@
require 'date'
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/commercial', __FILE__)
-
-describe "Date#commercial" do
-
- it_behaves_like(:date_commercial, :commercial)
-
-end
+require_relative '../../spec_helper'
# reference:
# October 1582 (the Gregorian calendar, Civil Date)
@@ -15,4 +8,42 @@ end
# 17 18 19 20 21 22 23
# 24 25 26 27 28 29 30
# 31
+describe "Date.commercial" do
+ it "creates a Date for Julian Day Number day 0 by default" do
+ d = Date.commercial
+ d.year.should == -4712
+ d.month.should == 1
+ d.day.should == 1
+ end
+ it "creates a Date for the monday in the year and week given" do
+ d = Date.commercial(2000, 1)
+ d.year.should == 2000
+ d.month.should == 1
+ d.day.should == 3
+ d.cwday.should == 1
+ end
+
+ it "creates a Date for the correct day given the year, week and day number" do
+ d = Date.commercial(2004, 1, 1)
+ d.year.should == 2003
+ d.month.should == 12
+ d.day.should == 29
+ d.cwday.should == 1
+ d.cweek.should == 1
+ d.cwyear.should == 2004
+ end
+
+ it "creates only Date objects for valid weeks" do
+ -> { Date.commercial(2004, 53, 1) }.should_not.raise(ArgumentError)
+ -> { Date.commercial(2004, 53, 0) }.should.raise(ArgumentError)
+ -> { Date.commercial(2004, 53, 8) }.should.raise(ArgumentError)
+ -> { Date.commercial(2004, 54, 1) }.should.raise(ArgumentError)
+ -> { Date.commercial(2004, 0, 1) }.should.raise(ArgumentError)
+
+ -> { Date.commercial(2003, 52, 1) }.should_not.raise(ArgumentError)
+ -> { Date.commercial(2003, 53, 1) }.should.raise(ArgumentError)
+ -> { Date.commercial(2003, 52, 0) }.should.raise(ArgumentError)
+ -> { Date.commercial(2003, 52, 8) }.should.raise(ArgumentError)
+ end
+end
diff --git a/spec/ruby/library/date/commercial_to_jd_spec.rb b/spec/ruby/library/date/commercial_to_jd_spec.rb
index 61631a7977..9b77f1229f 100644
--- a/spec/ruby/library/date/commercial_to_jd_spec.rb
+++ b/spec/ruby/library/date/commercial_to_jd_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date.commercial_to_jd" do
diff --git a/spec/ruby/library/date/comparison_spec.rb b/spec/ruby/library/date/comparison_spec.rb
index 04bfa2e8f7..1a94b9dcd2 100644
--- a/spec/ruby/library/date/comparison_spec.rb
+++ b/spec/ruby/library/date/comparison_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date#<=>" do
diff --git a/spec/ruby/library/date/constants_spec.rb b/spec/ruby/library/date/constants_spec.rb
index 8e564fe665..3494b0c296 100644
--- a/spec/ruby/library/date/constants_spec.rb
+++ b/spec/ruby/library/date/constants_spec.rb
@@ -1,5 +1,5 @@
require 'date'
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Date constants" do
@@ -34,9 +34,13 @@ describe "Date constants" do
it "freezes MONTHNAMES, DAYNAMES, ABBR_MONTHNAMES, ABBR_DAYSNAMES" do
[Date::MONTHNAMES, Date::DAYNAMES, Date::ABBR_MONTHNAMES, Date::ABBR_DAYNAMES].each do |ary|
- lambda { ary << "Unknown" }.should raise_error
+ -> {
+ ary << "Unknown"
+ }.should.raise(FrozenError, /frozen/)
ary.compact.each do |name|
- lambda { name << "modified" }.should raise_error
+ -> {
+ name << "modified"
+ }.should.raise(FrozenError, /frozen/)
end
end
end
diff --git a/spec/ruby/library/date/conversions_spec.rb b/spec/ruby/library/date/conversions_spec.rb
index c52ade7012..a9a320b0fc 100644
--- a/spec/ruby/library/date/conversions_spec.rb
+++ b/spec/ruby/library/date/conversions_spec.rb
@@ -1,5 +1,5 @@
require 'date'
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Date#new_start" do
diff --git a/spec/ruby/library/date/ctime_spec.rb b/spec/ruby/library/date/ctime_spec.rb
index 0f5d594842..330076a735 100644
--- a/spec/ruby/library/date/ctime_spec.rb
+++ b/spec/ruby/library/date/ctime_spec.rb
@@ -1,6 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date#ctime" do
- it "needs to be reviewed for spec completeness"
+ it "is an alias of Date#asctime" do
+ Date.instance_method(:ctime).should == Date.instance_method(:asctime)
+ end
end
diff --git a/spec/ruby/library/date/cwday_spec.rb b/spec/ruby/library/date/cwday_spec.rb
index 33ede37b2c..c5a39f277f 100644
--- a/spec/ruby/library/date/cwday_spec.rb
+++ b/spec/ruby/library/date/cwday_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date#cwday" do
diff --git a/spec/ruby/library/date/cweek_spec.rb b/spec/ruby/library/date/cweek_spec.rb
index d988bdd9db..6f7aab3922 100644
--- a/spec/ruby/library/date/cweek_spec.rb
+++ b/spec/ruby/library/date/cweek_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date#cweek" do
diff --git a/spec/ruby/library/date/cwyear_spec.rb b/spec/ruby/library/date/cwyear_spec.rb
index 00544927bc..a85ee29920 100644
--- a/spec/ruby/library/date/cwyear_spec.rb
+++ b/spec/ruby/library/date/cwyear_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date#cwyear" do
diff --git a/spec/ruby/library/date/day_fraction_spec.rb b/spec/ruby/library/date/day_fraction_spec.rb
index 64896a421e..12b873773f 100644
--- a/spec/ruby/library/date/day_fraction_spec.rb
+++ b/spec/ruby/library/date/day_fraction_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date#day_fraction" do
diff --git a/spec/ruby/library/date/day_fraction_to_time_spec.rb b/spec/ruby/library/date/day_fraction_to_time_spec.rb
index 609367371a..d4741d65ec 100644
--- a/spec/ruby/library/date/day_fraction_to_time_spec.rb
+++ b/spec/ruby/library/date/day_fraction_to_time_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date.day_fraction_to_time" do
diff --git a/spec/ruby/library/date/day_spec.rb b/spec/ruby/library/date/day_spec.rb
index d3561d802d..bc727c4717 100644
--- a/spec/ruby/library/date/day_spec.rb
+++ b/spec/ruby/library/date/day_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date#day" do
diff --git a/spec/ruby/library/date/deconstruct_keys_spec.rb b/spec/ruby/library/date/deconstruct_keys_spec.rb
new file mode 100644
index 0000000000..1fa1e70250
--- /dev/null
+++ b/spec/ruby/library/date/deconstruct_keys_spec.rb
@@ -0,0 +1,42 @@
+require_relative '../../spec_helper'
+require 'date'
+date_version = defined?(Date::VERSION) ? Date::VERSION : '3.1.0'
+
+describe "Date#deconstruct_keys" do
+ it "returns whole hash for nil as an argument" do
+ d = Date.new(2022, 10, 5)
+ d.deconstruct_keys(nil).should == { year: 2022, month: 10, day: 5, yday: 278, wday: 3 }
+ end
+
+ it "returns only specified keys" do
+ d = Date.new(2022, 10, 5)
+ d.deconstruct_keys([:year, :month]).should == { year: 2022, month: 10 }
+ end
+
+ it "requires one argument" do
+ -> {
+ Date.new(2022, 10, 5).deconstruct_keys
+ }.should.raise(ArgumentError)
+ end
+
+ it "it raises error when argument is neither nil nor array" do
+ d = Date.new(2022, 10, 5)
+
+ -> { d.deconstruct_keys(1) }.should.raise(TypeError, "wrong argument type Integer (expected Array or nil)")
+ -> { d.deconstruct_keys("asd") }.should.raise(TypeError, "wrong argument type String (expected Array or nil)")
+ -> { d.deconstruct_keys(:x) }.should.raise(TypeError, "wrong argument type Symbol (expected Array or nil)")
+ -> { d.deconstruct_keys({}) }.should.raise(TypeError, "wrong argument type Hash (expected Array or nil)")
+ end
+
+ it "returns {} when passed []" do
+ Date.new(2022, 10, 5).deconstruct_keys([]).should == {}
+ end
+
+ it "ignores non-Symbol keys" do
+ Date.new(2022, 10, 5).deconstruct_keys(['year', []]).should == {}
+ end
+
+ it "ignores not existing Symbol keys" do
+ Date.new(2022, 10, 5).deconstruct_keys([:year, :a]).should == { year: 2022 }
+ end
+end
diff --git a/spec/ruby/library/date/downto_spec.rb b/spec/ruby/library/date/downto_spec.rb
index ab9bf11952..84c641ee14 100644
--- a/spec/ruby/library/date/downto_spec.rb
+++ b/spec/ruby/library/date/downto_spec.rb
@@ -1,5 +1,5 @@
require 'date'
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Date#downto" do
diff --git a/spec/ruby/library/date/england_spec.rb b/spec/ruby/library/date/england_spec.rb
index 6c67c6ee86..2e30530c5a 100644
--- a/spec/ruby/library/date/england_spec.rb
+++ b/spec/ruby/library/date/england_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date#england" do
diff --git a/spec/ruby/library/date/eql_spec.rb b/spec/ruby/library/date/eql_spec.rb
index efecde8944..79fabc47f4 100644
--- a/spec/ruby/library/date/eql_spec.rb
+++ b/spec/ruby/library/date/eql_spec.rb
@@ -1,12 +1,12 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date#eql?" do
it "returns true if self is equal to another date" do
- Date.civil(2007, 10, 11).eql?(Date.civil(2007, 10, 11)).should be_true
+ Date.civil(2007, 10, 11).eql?(Date.civil(2007, 10, 11)).should == true
end
it "returns false if self is not equal to another date" do
- Date.civil(2007, 10, 11).eql?(Date.civil(2007, 10, 12)).should be_false
+ Date.civil(2007, 10, 11).eql?(Date.civil(2007, 10, 12)).should == false
end
end
diff --git a/spec/ruby/library/date/format/bag/method_missing_spec.rb b/spec/ruby/library/date/format/bag/method_missing_spec.rb
index 529fde05d2..03e4fbcd30 100644
--- a/spec/ruby/library/date/format/bag/method_missing_spec.rb
+++ b/spec/ruby/library/date/format/bag/method_missing_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
+require_relative '../../../../spec_helper'
require 'date'
describe "Date::Format::Bag#method_missing" do
diff --git a/spec/ruby/library/date/format/bag/to_hash_spec.rb b/spec/ruby/library/date/format/bag/to_hash_spec.rb
index ba9525e5e8..76734624b9 100644
--- a/spec/ruby/library/date/format/bag/to_hash_spec.rb
+++ b/spec/ruby/library/date/format/bag/to_hash_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
+require_relative '../../../../spec_helper'
require 'date'
describe "Date::Format::Bag#to_hash" do
diff --git a/spec/ruby/library/date/friday_spec.rb b/spec/ruby/library/date/friday_spec.rb
index 369b943419..62f050346e 100644
--- a/spec/ruby/library/date/friday_spec.rb
+++ b/spec/ruby/library/date/friday_spec.rb
@@ -1,12 +1,12 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date#friday?" do
it "should be friday" do
- Date.new(2000, 1, 7).friday?.should be_true
+ Date.new(2000, 1, 7).friday?.should == true
end
it "should not be friday" do
- Date.new(2000, 1, 8).friday?.should be_false
+ Date.new(2000, 1, 8).friday?.should == false
end
end
diff --git a/spec/ruby/library/date/gregorian_leap_spec.rb b/spec/ruby/library/date/gregorian_leap_spec.rb
index 043d57aa93..c27890faf4 100644
--- a/spec/ruby/library/date/gregorian_leap_spec.rb
+++ b/spec/ruby/library/date/gregorian_leap_spec.rb
@@ -1,16 +1,15 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date#gregorian_leap?" do
it "returns true if a year is a leap year in the Gregorian calendar" do
- Date.gregorian_leap?(2000).should be_true
- Date.gregorian_leap?(2004).should be_true
+ Date.gregorian_leap?(2000).should == true
+ Date.gregorian_leap?(2004).should == true
end
it "returns false if a year is not a leap year in the Gregorian calendar" do
- Date.gregorian_leap?(1900).should be_false
- Date.gregorian_leap?(1999).should be_false
- Date.gregorian_leap?(2002).should be_false
+ Date.gregorian_leap?(1900).should == false
+ Date.gregorian_leap?(1999).should == false
+ Date.gregorian_leap?(2002).should == false
end
end
-
diff --git a/spec/ruby/library/date/gregorian_spec.rb b/spec/ruby/library/date/gregorian_spec.rb
index 5d8b38b2d8..bbda13af08 100644
--- a/spec/ruby/library/date/gregorian_spec.rb
+++ b/spec/ruby/library/date/gregorian_spec.rb
@@ -1,16 +1,16 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date#gregorian?" do
it "marks a day before the calendar reform as Julian" do
- Date.civil(1007, 2, 27).gregorian?.should be_false
- Date.civil(1907, 2, 27, Date.civil(1930, 1, 1).jd).gregorian?.should be_false
+ Date.civil(1007, 2, 27).gregorian?.should == false
+ Date.civil(1907, 2, 27, Date.civil(1930, 1, 1).jd).gregorian?.should == false
end
it "marks a day after the calendar reform as Julian" do
- Date.civil(2007, 2, 27).gregorian?.should == true
- Date.civil(1607, 2, 27, Date.civil(1582, 1, 1).jd).gregorian?.should be_true
+ Date.civil(2007, 2, 27).should.gregorian?
+ Date.civil(1607, 2, 27, Date.civil(1582, 1, 1).jd).gregorian?.should == true
end
end
diff --git a/spec/ruby/library/date/hash_spec.rb b/spec/ruby/library/date/hash_spec.rb
index 271d565253..4fb452d486 100644
--- a/spec/ruby/library/date/hash_spec.rb
+++ b/spec/ruby/library/date/hash_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date#hash" do
diff --git a/spec/ruby/library/date/infinity/abs_spec.rb b/spec/ruby/library/date/infinity/abs_spec.rb
index a1107679f6..c08189155d 100644
--- a/spec/ruby/library/date/infinity/abs_spec.rb
+++ b/spec/ruby/library/date/infinity/abs_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'date'
describe "Date::Infinity#abs" do
diff --git a/spec/ruby/library/date/infinity/coerce_spec.rb b/spec/ruby/library/date/infinity/coerce_spec.rb
index e09b948064..75e5ebeab7 100644
--- a/spec/ruby/library/date/infinity/coerce_spec.rb
+++ b/spec/ruby/library/date/infinity/coerce_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'date'
describe "Date::Infinity#coerce" do
diff --git a/spec/ruby/library/date/infinity/comparison_spec.rb b/spec/ruby/library/date/infinity/comparison_spec.rb
index 7bf8fb7b9f..a9b9d124fd 100644
--- a/spec/ruby/library/date/infinity/comparison_spec.rb
+++ b/spec/ruby/library/date/infinity/comparison_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'date'
describe "Date::Infinity#<=>" do
diff --git a/spec/ruby/library/date/infinity/d_spec.rb b/spec/ruby/library/date/infinity/d_spec.rb
index 9ef1f71408..a5bd2427c7 100644
--- a/spec/ruby/library/date/infinity/d_spec.rb
+++ b/spec/ruby/library/date/infinity/d_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'date'
describe "Date::Infinity#d" do
diff --git a/spec/ruby/library/date/infinity/finite_spec.rb b/spec/ruby/library/date/infinity/finite_spec.rb
index 92806935fc..8971c2213e 100644
--- a/spec/ruby/library/date/infinity/finite_spec.rb
+++ b/spec/ruby/library/date/infinity/finite_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'date'
describe "Date::Infinity#finite?" do
diff --git a/spec/ruby/library/date/infinity/infinite_spec.rb b/spec/ruby/library/date/infinity/infinite_spec.rb
index 8c7e0bc86a..848f538672 100644
--- a/spec/ruby/library/date/infinity/infinite_spec.rb
+++ b/spec/ruby/library/date/infinity/infinite_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'date'
describe "Date::Infinity#infinite?" do
diff --git a/spec/ruby/library/date/infinity/nan_spec.rb b/spec/ruby/library/date/infinity/nan_spec.rb
index 19c7ae0af3..b0f5d8ac7a 100644
--- a/spec/ruby/library/date/infinity/nan_spec.rb
+++ b/spec/ruby/library/date/infinity/nan_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'date'
describe "Date::Infinity#nan?" do
diff --git a/spec/ruby/library/date/infinity/uminus_spec.rb b/spec/ruby/library/date/infinity/uminus_spec.rb
index 110e197231..1b1f568103 100644
--- a/spec/ruby/library/date/infinity/uminus_spec.rb
+++ b/spec/ruby/library/date/infinity/uminus_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'date'
describe "Date::Infinity#-@" do
diff --git a/spec/ruby/library/date/infinity/uplus_spec.rb b/spec/ruby/library/date/infinity/uplus_spec.rb
index dfc60b6b61..6a3b2d8442 100644
--- a/spec/ruby/library/date/infinity/uplus_spec.rb
+++ b/spec/ruby/library/date/infinity/uplus_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'date'
describe "Date::Infinity#+@" do
diff --git a/spec/ruby/library/date/infinity/zero_spec.rb b/spec/ruby/library/date/infinity/zero_spec.rb
index 2f4347255b..7df5518785 100644
--- a/spec/ruby/library/date/infinity/zero_spec.rb
+++ b/spec/ruby/library/date/infinity/zero_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'date'
describe "Date::Infinity#zero?" do
diff --git a/spec/ruby/library/date/infinity_spec.rb b/spec/ruby/library/date/infinity_spec.rb
index 127fb8c2f4..721fd76066 100644
--- a/spec/ruby/library/date/infinity_spec.rb
+++ b/spec/ruby/library/date/infinity_spec.rb
@@ -1,20 +1,20 @@
require 'date'
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Date::Infinity" do
it "should be able to check whether Infinity is zero" do
i = Date::Infinity.new
- i.zero?.should == false
+ i.should_not.zero?
end
it "should be able to check whether Infinity is finite" do
i1 = Date::Infinity.new
- i1.finite?.should == false
+ i1.should_not.finite?
i2 = Date::Infinity.new(-1)
- i2.finite?.should == false
+ i2.should_not.finite?
i3 = Date::Infinity.new(0)
- i3.finite?.should == false
+ i3.should_not.finite?
end
it "should be able to check whether Infinity is infinite" do
@@ -28,11 +28,11 @@ describe "Date::Infinity" do
it "should be able to check whether Infinity is not a number" do
i1 = Date::Infinity.new
- i1.nan?.should == false
+ i1.should_not.nan?
i2 = Date::Infinity.new(-1)
- i2.nan?.should == false
+ i2.should_not.nan?
i3 = Date::Infinity.new(0)
- i3.nan?.should == true
+ i3.should.nan?
end
it "should be able to compare Infinity objects" do
diff --git a/spec/ruby/library/date/inspect_spec.rb b/spec/ruby/library/date/inspect_spec.rb
index 150eb6bf24..81c2cc8003 100644
--- a/spec/ruby/library/date/inspect_spec.rb
+++ b/spec/ruby/library/date/inspect_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date#inspect" do
diff --git a/spec/ruby/library/date/iso8601_spec.rb b/spec/ruby/library/date/iso8601_spec.rb
new file mode 100644
index 0000000000..26815bd76c
--- /dev/null
+++ b/spec/ruby/library/date/iso8601_spec.rb
@@ -0,0 +1,56 @@
+require_relative '../../spec_helper'
+require 'date'
+
+describe "Date.iso8601" do
+ it "parses YYYY-MM-DD into a Date object" do
+ d = Date.iso8601("2018-01-01")
+ d.should == Date.civil(2018, 1, 1)
+ end
+
+ it "parses YYYYMMDD into a Date object" do
+ d = Date.iso8601("20180715")
+ d.should == Date.civil(2018, 7, 15)
+ end
+
+ it "parses a negative Date" do
+ d = Date.iso8601("-4712-01-01")
+ d.should == Date.civil(-4712, 1, 1)
+ end
+
+ it "parses a StringSubclass into a Date object" do
+ d = Date.iso8601(Class.new(String).new("-4712-01-01"))
+ d.should == Date.civil(-4712, 1, 1)
+ end
+
+ it "raises a Date::Error if the argument is a invalid Date" do
+ -> {
+ Date.iso8601('invalid')
+ }.should.raise(Date::Error, "invalid date")
+ end
+
+ it "raises a Date::Error when passed a nil" do
+ -> {
+ Date.iso8601(nil)
+ }.should.raise(Date::Error, "invalid date")
+ end
+
+ it "raises a TypeError when passed an Object" do
+ -> { Date.iso8601(Object.new) }.should.raise(TypeError)
+ end
+end
+
+describe "Date._iso8601" do
+ it "returns an empty hash if the argument is a invalid Date" do
+ h = Date._iso8601('invalid')
+ h.should == {}
+ end
+
+ it "returns an empty hash if the argument is nil" do
+ h = Date._iso8601(nil)
+ h.should == {}
+ end
+
+ it "raises a TypeError when passed an Object" do
+ -> { Date._iso8601(Object.new) }.should.raise(TypeError)
+ end
+end
diff --git a/spec/ruby/library/date/italy_spec.rb b/spec/ruby/library/date/italy_spec.rb
index 2d251db1b0..9369b05180 100644
--- a/spec/ruby/library/date/italy_spec.rb
+++ b/spec/ruby/library/date/italy_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date#italy" do
diff --git a/spec/ruby/library/date/jd_spec.rb b/spec/ruby/library/date/jd_spec.rb
index ccf6b93e06..e5cfe10eff 100644
--- a/spec/ruby/library/date/jd_spec.rb
+++ b/spec/ruby/library/date/jd_spec.rb
@@ -1,15 +1,22 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/jd', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date#jd" do
-
it "determines the Julian day for a Date object" do
Date.civil(2008, 1, 16).jd.should == 2454482
end
-
end
describe "Date.jd" do
- it_behaves_like :date_jd, :jd
+ it "constructs a Date object if passed a Julian day" do
+ Date.jd(2454482).should == Date.civil(2008, 1, 16)
+ end
+
+ it "returns a Date object representing Julian day 0 (-4712-01-01) if no arguments passed" do
+ Date.jd.should == Date.civil(-4712, 1, 1)
+ end
+
+ it "constructs a Date object if passed a negative number" do
+ Date.jd(-1).should == Date.civil(-4713, 12, 31)
+ end
end
diff --git a/spec/ruby/library/date/jd_to_ajd_spec.rb b/spec/ruby/library/date/jd_to_ajd_spec.rb
index 38a12bd65d..f946c46b8a 100644
--- a/spec/ruby/library/date/jd_to_ajd_spec.rb
+++ b/spec/ruby/library/date/jd_to_ajd_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date.jd_to_ajd" do
diff --git a/spec/ruby/library/date/jd_to_civil_spec.rb b/spec/ruby/library/date/jd_to_civil_spec.rb
index 8608de2698..13b6e47ee2 100644
--- a/spec/ruby/library/date/jd_to_civil_spec.rb
+++ b/spec/ruby/library/date/jd_to_civil_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date.jd_to_civil" do
diff --git a/spec/ruby/library/date/jd_to_commercial_spec.rb b/spec/ruby/library/date/jd_to_commercial_spec.rb
index 97d76130f2..2256b74f2a 100644
--- a/spec/ruby/library/date/jd_to_commercial_spec.rb
+++ b/spec/ruby/library/date/jd_to_commercial_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date.jd_to_commercial" do
diff --git a/spec/ruby/library/date/jd_to_ld_spec.rb b/spec/ruby/library/date/jd_to_ld_spec.rb
index d27ada6b6c..5954014f85 100644
--- a/spec/ruby/library/date/jd_to_ld_spec.rb
+++ b/spec/ruby/library/date/jd_to_ld_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date.jd_to_ld" do
diff --git a/spec/ruby/library/date/jd_to_mjd_spec.rb b/spec/ruby/library/date/jd_to_mjd_spec.rb
index 064134c7ed..24eb84e171 100644
--- a/spec/ruby/library/date/jd_to_mjd_spec.rb
+++ b/spec/ruby/library/date/jd_to_mjd_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date.jd_to_mjd" do
diff --git a/spec/ruby/library/date/jd_to_ordinal_spec.rb b/spec/ruby/library/date/jd_to_ordinal_spec.rb
index a5f5c79641..c7c1704948 100644
--- a/spec/ruby/library/date/jd_to_ordinal_spec.rb
+++ b/spec/ruby/library/date/jd_to_ordinal_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date.jd_to_ordinal" do
diff --git a/spec/ruby/library/date/jd_to_wday_spec.rb b/spec/ruby/library/date/jd_to_wday_spec.rb
index 569a53e409..27e00b2044 100644
--- a/spec/ruby/library/date/jd_to_wday_spec.rb
+++ b/spec/ruby/library/date/jd_to_wday_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date.jd_to_wday" do
diff --git a/spec/ruby/library/date/julian_leap_spec.rb b/spec/ruby/library/date/julian_leap_spec.rb
index 3915f97693..42231e012f 100644
--- a/spec/ruby/library/date/julian_leap_spec.rb
+++ b/spec/ruby/library/date/julian_leap_spec.rb
@@ -1,15 +1,15 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date.julian_leap?" do
it "determines whether a year is a leap year in the Julian calendar" do
- Date.julian_leap?(1900).should be_true
- Date.julian_leap?(2000).should be_true
- Date.julian_leap?(2004).should be_true
+ Date.julian_leap?(1900).should == true
+ Date.julian_leap?(2000).should == true
+ Date.julian_leap?(2004).should == true
end
it "determines whether a year is not a leap year in the Julian calendar" do
- Date.julian_leap?(1999).should be_false
- Date.julian_leap?(2002).should be_false
+ Date.julian_leap?(1999).should == false
+ Date.julian_leap?(2002).should == false
end
end
diff --git a/spec/ruby/library/date/julian_spec.rb b/spec/ruby/library/date/julian_spec.rb
index 8cbe27b881..9f8a670899 100644
--- a/spec/ruby/library/date/julian_spec.rb
+++ b/spec/ruby/library/date/julian_spec.rb
@@ -1,16 +1,16 @@
require 'date'
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Date#julian?" do
it "marks a day before the calendar reform as Julian" do
- Date.civil(1007, 2, 27).julian?.should == true
- Date.civil(1907, 2, 27, Date.civil(1930, 1, 1).jd).julian?.should be_true
+ Date.civil(1007, 2, 27).should.julian?
+ Date.civil(1907, 2, 27, Date.civil(1930, 1, 1).jd).julian?.should == true
end
it "marks a day after the calendar reform as Julian" do
- Date.civil(2007, 2, 27).julian?.should == false
- Date.civil(1607, 2, 27, Date.civil(1582, 1, 1).jd).julian?.should be_false
+ Date.civil(2007, 2, 27).should_not.julian?
+ Date.civil(1607, 2, 27, Date.civil(1582, 1, 1).jd).julian?.should == false
end
end
diff --git a/spec/ruby/library/date/ld_spec.rb b/spec/ruby/library/date/ld_spec.rb
index a59b519c04..73a47d2382 100644
--- a/spec/ruby/library/date/ld_spec.rb
+++ b/spec/ruby/library/date/ld_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date#ld" do
diff --git a/spec/ruby/library/date/ld_to_jd_spec.rb b/spec/ruby/library/date/ld_to_jd_spec.rb
index 7adbbede37..37abe01449 100644
--- a/spec/ruby/library/date/ld_to_jd_spec.rb
+++ b/spec/ruby/library/date/ld_to_jd_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date.ld_to_jd" do
diff --git a/spec/ruby/library/date/leap_spec.rb b/spec/ruby/library/date/leap_spec.rb
index bb8e920a3e..674b191c9f 100644
--- a/spec/ruby/library/date/leap_spec.rb
+++ b/spec/ruby/library/date/leap_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date#leap?" do
diff --git a/spec/ruby/library/date/mday_spec.rb b/spec/ruby/library/date/mday_spec.rb
index 8a1d6e8d59..32fd8fc7f1 100644
--- a/spec/ruby/library/date/mday_spec.rb
+++ b/spec/ruby/library/date/mday_spec.rb
@@ -1,6 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date#mday" do
- it "needs to be reviewed for spec completeness"
+ it "is an alias of Date#day" do
+ Date.instance_method(:mday).should == Date.instance_method(:day)
+ end
end
diff --git a/spec/ruby/library/date/minus_month_spec.rb b/spec/ruby/library/date/minus_month_spec.rb
index fbe5cb8593..d56e19dc31 100644
--- a/spec/ruby/library/date/minus_month_spec.rb
+++ b/spec/ruby/library/date/minus_month_spec.rb
@@ -1,5 +1,5 @@
require 'date'
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Date#<<" do
@@ -13,22 +13,11 @@ describe "Date#<<" do
d.should == Date.civil(2008, 2, 29)
end
- ruby_version_is ""..."2.3" do
- it "raises an error on non numeric parameters" do
- lambda { Date.civil(2007,2,27) << :hello }.should raise_error
- lambda { Date.civil(2007,2,27) << "hello" }.should raise_error
- lambda { Date.civil(2007,2,27) << Date.new }.should raise_error
- lambda { Date.civil(2007,2,27) << Object.new }.should raise_error
- end
- end
-
- ruby_version_is "2.3" do
- it "raises an error on non numeric parameters" do
- lambda { Date.civil(2007,2,27) << :hello }.should raise_error(TypeError)
- lambda { Date.civil(2007,2,27) << "hello" }.should raise_error(TypeError)
- lambda { Date.civil(2007,2,27) << Date.new }.should raise_error(TypeError)
- lambda { Date.civil(2007,2,27) << Object.new }.should raise_error(TypeError)
- end
+ it "raises an error on non numeric parameters" do
+ -> { Date.civil(2007,2,27) << :hello }.should.raise(TypeError)
+ -> { Date.civil(2007,2,27) << "hello" }.should.raise(TypeError)
+ -> { Date.civil(2007,2,27) << Date.new }.should.raise(TypeError)
+ -> { Date.civil(2007,2,27) << Object.new }.should.raise(TypeError)
end
end
diff --git a/spec/ruby/library/date/minus_spec.rb b/spec/ruby/library/date/minus_spec.rb
index fd7f3fd14c..c2a08fa5b0 100644
--- a/spec/ruby/library/date/minus_spec.rb
+++ b/spec/ruby/library/date/minus_spec.rb
@@ -1,5 +1,5 @@
require 'date'
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Date#-" do
@@ -22,9 +22,9 @@ describe "Date#-" do
end
it "raises an error for non Numeric arguments" do
- lambda { Date.civil(2007,2,27) - :hello }.should raise_error(TypeError)
- lambda { Date.civil(2007,2,27) - "hello" }.should raise_error(TypeError)
- lambda { Date.civil(2007,2,27) - Object.new }.should raise_error(TypeError)
+ -> { Date.civil(2007,2,27) - :hello }.should.raise(TypeError)
+ -> { Date.civil(2007,2,27) - "hello" }.should.raise(TypeError)
+ -> { Date.civil(2007,2,27) - Object.new }.should.raise(TypeError)
end
end
diff --git a/spec/ruby/library/date/mjd_spec.rb b/spec/ruby/library/date/mjd_spec.rb
index 7de39f0047..6f03af346b 100644
--- a/spec/ruby/library/date/mjd_spec.rb
+++ b/spec/ruby/library/date/mjd_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date#mjd" do
diff --git a/spec/ruby/library/date/mjd_to_jd_spec.rb b/spec/ruby/library/date/mjd_to_jd_spec.rb
index fdda1330e5..2009261103 100644
--- a/spec/ruby/library/date/mjd_to_jd_spec.rb
+++ b/spec/ruby/library/date/mjd_to_jd_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date.mjd_to_jd" do
diff --git a/spec/ruby/library/date/mon_spec.rb b/spec/ruby/library/date/mon_spec.rb
index c3508b53bf..15754ffb1f 100644
--- a/spec/ruby/library/date/mon_spec.rb
+++ b/spec/ruby/library/date/mon_spec.rb
@@ -1,6 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date#mon" do
- it "needs to be reviewed for spec completeness"
+ it "is an alias of Date#month" do
+ Date.instance_method(:mon).should == Date.instance_method(:month)
+ end
end
diff --git a/spec/ruby/library/date/monday_spec.rb b/spec/ruby/library/date/monday_spec.rb
index f7d968b6d6..61d728f3c5 100644
--- a/spec/ruby/library/date/monday_spec.rb
+++ b/spec/ruby/library/date/monday_spec.rb
@@ -1,8 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date#monday?" do
it "should be monday" do
- Date.new(2000, 1, 3).monday?.should be_true
+ Date.new(2000, 1, 3).monday?.should == true
end
end
diff --git a/spec/ruby/library/date/month_spec.rb b/spec/ruby/library/date/month_spec.rb
index ea35430d6b..e040f9a94c 100644
--- a/spec/ruby/library/date/month_spec.rb
+++ b/spec/ruby/library/date/month_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date#month" do
diff --git a/spec/ruby/library/date/new_spec.rb b/spec/ruby/library/date/new_spec.rb
index f468036a01..cb64cabce6 100644
--- a/spec/ruby/library/date/new_spec.rb
+++ b/spec/ruby/library/date/new_spec.rb
@@ -1,8 +1,7 @@
require 'date'
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/civil', __FILE__)
-require File.expand_path('../shared/new_bang', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/civil'
describe "Date.new" do
- it_behaves_like(:date_civil, :new)
+ it_behaves_like :date_civil, :new
end
diff --git a/spec/ruby/library/date/new_start_spec.rb b/spec/ruby/library/date/new_start_spec.rb
index 94ec6bee46..aef78f2320 100644
--- a/spec/ruby/library/date/new_start_spec.rb
+++ b/spec/ruby/library/date/new_start_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date#new_start" do
diff --git a/spec/ruby/library/date/next_day_spec.rb b/spec/ruby/library/date/next_day_spec.rb
index 795bfecf0a..3b066630e7 100644
--- a/spec/ruby/library/date/next_day_spec.rb
+++ b/spec/ruby/library/date/next_day_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date#next_day" do
diff --git a/spec/ruby/library/date/next_month_spec.rb b/spec/ruby/library/date/next_month_spec.rb
index 9becd7e37f..6ee664433f 100644
--- a/spec/ruby/library/date/next_month_spec.rb
+++ b/spec/ruby/library/date/next_month_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date#next_month" do
diff --git a/spec/ruby/library/date/next_spec.rb b/spec/ruby/library/date/next_spec.rb
index d88d31e974..8063d6a2e4 100644
--- a/spec/ruby/library/date/next_spec.rb
+++ b/spec/ruby/library/date/next_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date#next" do
diff --git a/spec/ruby/library/date/next_year_spec.rb b/spec/ruby/library/date/next_year_spec.rb
index 70f2f7ab77..dda9a44008 100644
--- a/spec/ruby/library/date/next_year_spec.rb
+++ b/spec/ruby/library/date/next_year_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date#next_year" do
diff --git a/spec/ruby/library/date/ordinal_spec.rb b/spec/ruby/library/date/ordinal_spec.rb
index a373692a7b..c8bf715163 100644
--- a/spec/ruby/library/date/ordinal_spec.rb
+++ b/spec/ruby/library/date/ordinal_spec.rb
@@ -1,8 +1,17 @@
require 'date'
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/ordinal', __FILE__)
+require_relative '../../spec_helper'
describe "Date.ordinal" do
- it_behaves_like :date_ordinal, :ordinal
+ it "constructs a Date object from an ordinal date" do
+ # October 1582 (the Gregorian calendar, Ordinal Date)
+ # S M Tu W Th F S
+ # 274 275 276 277 278 279
+ # 280 281 282 283 284 285 286
+ # 287 288 289 290 291 292 293
+ # 294
+ Date.ordinal(1582, 274).should == Date.civil(1582, 10, 1)
+ Date.ordinal(1582, 277).should == Date.civil(1582, 10, 4)
+ Date.ordinal(1582, 278).should == Date.civil(1582, 10, 15)
+ Date.ordinal(1582, 287, Date::ENGLAND).should == Date.civil(1582, 10, 14, Date::ENGLAND)
+ end
end
-
diff --git a/spec/ruby/library/date/ordinal_to_jd_spec.rb b/spec/ruby/library/date/ordinal_to_jd_spec.rb
index 0a76c69c00..44f4b3321e 100644
--- a/spec/ruby/library/date/ordinal_to_jd_spec.rb
+++ b/spec/ruby/library/date/ordinal_to_jd_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date.ordinal_to_jd" do
diff --git a/spec/ruby/library/date/parse_spec.rb b/spec/ruby/library/date/parse_spec.rb
index 092c658809..4d655f516e 100644
--- a/spec/ruby/library/date/parse_spec.rb
+++ b/spec/ruby/library/date/parse_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/parse', __FILE__)
-require File.expand_path('../shared/parse_us', __FILE__)
-require File.expand_path('../shared/parse_eu', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/parse'
+require_relative 'shared/parse_us'
+require_relative 'shared/parse_eu'
require 'date'
describe "Date#parse" do
@@ -23,7 +23,7 @@ describe "Date#parse" do
# Specs using numbers
it "throws an argument error for a single digit" do
- lambda{ Date.parse("1") }.should raise_error(ArgumentError)
+ ->{ Date.parse("1") }.should.raise(ArgumentError)
end
it "parses DD as month day number" do
@@ -64,6 +64,28 @@ describe "Date#parse" do
d = Date.parse("19101101")
d.should == Date.civil(1910, 11, 1)
end
+
+ it "raises a TypeError trying to parse non-String-like object" do
+ -> { Date.parse(1) }.should.raise(TypeError)
+ -> { Date.parse([]) }.should.raise(TypeError)
+ end
+
+ it "coerces using to_str" do
+ c = Class.new do
+ attr_accessor :string
+ def to_str
+ @string
+ end
+ end
+ o = c.new
+ o.string = "19101101"
+
+ d = Date.parse(o)
+ d.should == Date.civil(1910, 11, 1)
+
+ # parse should not modify string value
+ o.to_str.should == "19101101"
+ end
end
describe "Date#parse with '.' separator" do
@@ -71,7 +93,7 @@ describe "Date#parse with '.' separator" do
@sep = '.'
end
- it_should_behave_like "date_parse"
+ it_should_behave_like :date_parse
end
describe "Date#parse with '/' separator" do
@@ -79,7 +101,7 @@ describe "Date#parse with '/' separator" do
@sep = '/'
end
- it_should_behave_like "date_parse"
+ it_should_behave_like :date_parse
end
describe "Date#parse with ' ' separator" do
@@ -87,7 +109,7 @@ describe "Date#parse with ' ' separator" do
@sep = ' '
end
- it_should_behave_like "date_parse"
+ it_should_behave_like :date_parse
end
describe "Date#parse with '/' separator US-style" do
@@ -95,7 +117,7 @@ describe "Date#parse with '/' separator US-style" do
@sep = '/'
end
- it_should_behave_like "date_parse_us"
+ it_should_behave_like :date_parse_us
end
describe "Date#parse with '-' separator EU-style" do
@@ -103,7 +125,7 @@ describe "Date#parse with '-' separator EU-style" do
@sep = '-'
end
- it_should_behave_like "date_parse_eu"
+ it_should_behave_like :date_parse_eu
end
describe "Date#parse(.)" do
diff --git a/spec/ruby/library/date/plus_spec.rb b/spec/ruby/library/date/plus_spec.rb
index e33fb199eb..6179370fca 100644
--- a/spec/ruby/library/date/plus_spec.rb
+++ b/spec/ruby/library/date/plus_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date#+" do
@@ -15,6 +15,6 @@ describe "Date#+" do
end
it "raises TypeError if argument is not Numeric" do
- lambda { Date.today + Date.today }.should raise_error(TypeError)
+ -> { Date.today + Date.today }.should.raise(TypeError)
end
end
diff --git a/spec/ruby/library/date/prev_day_spec.rb b/spec/ruby/library/date/prev_day_spec.rb
index 149bfe9fa9..cce24da875 100644
--- a/spec/ruby/library/date/prev_day_spec.rb
+++ b/spec/ruby/library/date/prev_day_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date#prev_day" do
diff --git a/spec/ruby/library/date/prev_month_spec.rb b/spec/ruby/library/date/prev_month_spec.rb
index 440c17ffc9..3d0d1d437d 100644
--- a/spec/ruby/library/date/prev_month_spec.rb
+++ b/spec/ruby/library/date/prev_month_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date#prev_month" do
diff --git a/spec/ruby/library/date/prev_year_spec.rb b/spec/ruby/library/date/prev_year_spec.rb
index 4f27d1d1f9..ba06dd198b 100644
--- a/spec/ruby/library/date/prev_year_spec.rb
+++ b/spec/ruby/library/date/prev_year_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date#prev_year" do
diff --git a/spec/ruby/library/date/relationship_spec.rb b/spec/ruby/library/date/relationship_spec.rb
index 7c09457228..979516e164 100644
--- a/spec/ruby/library/date/relationship_spec.rb
+++ b/spec/ruby/library/date/relationship_spec.rb
@@ -1,5 +1,5 @@
require 'date'
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Date#===" do
diff --git a/spec/ruby/library/date/rfc3339_spec.rb b/spec/ruby/library/date/rfc3339_spec.rb
new file mode 100644
index 0000000000..a8711d47b2
--- /dev/null
+++ b/spec/ruby/library/date/rfc3339_spec.rb
@@ -0,0 +1,13 @@
+require_relative '../../spec_helper'
+require 'date'
+
+describe "Date.rfc3339" do
+ it "needs to be reviewed for spec completeness"
+end
+
+describe "Date._rfc3339" do
+ it "returns an empty hash if the argument is a invalid Date" do
+ h = Date._rfc3339('invalid')
+ h.should == {}
+ end
+end
diff --git a/spec/ruby/library/date/right_shift_spec.rb b/spec/ruby/library/date/right_shift_spec.rb
index 3d55e5abed..bd7de0e3d5 100644
--- a/spec/ruby/library/date/right_shift_spec.rb
+++ b/spec/ruby/library/date/right_shift_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date#>>" do
diff --git a/spec/ruby/library/date/saturday_spec.rb b/spec/ruby/library/date/saturday_spec.rb
index 1360050a69..29f8267a2b 100644
--- a/spec/ruby/library/date/saturday_spec.rb
+++ b/spec/ruby/library/date/saturday_spec.rb
@@ -1,8 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date#saturday?" do
it "should be saturday" do
- Date.new(2000, 1, 1).saturday?.should be_true
+ Date.new(2000, 1, 1).saturday?.should == true
end
end
diff --git a/spec/ruby/library/date/shared/civil.rb b/spec/ruby/library/date/shared/civil.rb
index 47dbed49fc..4499cdf8e9 100644
--- a/spec/ruby/library/date/shared/civil.rb
+++ b/spec/ruby/library/date/shared/civil.rb
@@ -5,7 +5,7 @@ describe :date_civil, shared: true do
d.year.should == -4712
d.month.should == 1
d.day.should == 1
- d.julian?.should == true
+ d.should.julian?
d.jd.should == 0
end
@@ -14,7 +14,7 @@ describe :date_civil, shared: true do
d.year.should == 2000
d.month.should == 3
d.day.should == 5
- d.julian?.should == false
+ d.should_not.julian?
d.jd.should == 2451609
# Should also work with years far in the past and future
@@ -23,27 +23,27 @@ describe :date_civil, shared: true do
d.year.should == -9000
d.month.should == 7
d.day.should == 5
- d.julian?.should == true
+ d.should.julian?
d.jd.should == -1566006
d = Date.send(@method, 9000, 10, 14)
d.year.should == 9000
d.month.should == 10
d.day.should == 14
- d.julian?.should == false
+ d.should_not.julian?
d.jd.should == 5008529
end
it "doesn't create dates for invalid arguments" do
- lambda { Date.send(@method, 2000, 13, 31) }.should raise_error(ArgumentError)
- lambda { Date.send(@method, 2000, 12, 32) }.should raise_error(ArgumentError)
- lambda { Date.send(@method, 2000, 2, 30) }.should raise_error(ArgumentError)
- lambda { Date.send(@method, 1900, 2, 29) }.should raise_error(ArgumentError)
- lambda { Date.send(@method, 2000, 2, 29) }.should_not raise_error(ArgumentError)
-
- lambda { Date.send(@method, 1582, 10, 14) }.should raise_error(ArgumentError)
- lambda { Date.send(@method, 1582, 10, 15) }.should_not raise_error(ArgumentError)
+ -> { Date.send(@method, 2000, 13, 31) }.should.raise(ArgumentError)
+ -> { Date.send(@method, 2000, 12, 32) }.should.raise(ArgumentError)
+ -> { Date.send(@method, 2000, 2, 30) }.should.raise(ArgumentError)
+ -> { Date.send(@method, 1900, 2, 29) }.should.raise(ArgumentError)
+ -> { Date.send(@method, 2000, 2, 29) }.should_not.raise(ArgumentError)
+
+ -> { Date.send(@method, 1582, 10, 14) }.should.raise(ArgumentError)
+ -> { Date.send(@method, 1582, 10, 15) }.should_not.raise(ArgumentError)
end
diff --git a/spec/ruby/library/date/shared/commercial.rb b/spec/ruby/library/date/shared/commercial.rb
deleted file mode 100644
index 354a5d5cd0..0000000000
--- a/spec/ruby/library/date/shared/commercial.rb
+++ /dev/null
@@ -1,39 +0,0 @@
-describe :date_commercial, shared: true do
- it "creates a Date for Julian Day Number day 0 by default" do
- d = Date.send(@method)
- d.year.should == -4712
- d.month.should == 1
- d.day.should == 1
- end
-
- it "creates a Date for the monday in the year and week given" do
- d = Date.send(@method, 2000, 1)
- d.year.should == 2000
- d.month.should == 1
- d.day.should == 3
- d.cwday.should == 1
- end
-
- it "creates a Date for the correct day given the year, week and day number" do
- d = Date.send(@method, 2004, 1, 1)
- d.year.should == 2003
- d.month.should == 12
- d.day.should == 29
- d.cwday.should == 1
- d.cweek.should == 1
- d.cwyear.should == 2004
- end
-
- it "creates only Date objects for valid weeks" do
- lambda { Date.send(@method, 2004, 53, 1) }.should_not raise_error(ArgumentError)
- lambda { Date.send(@method, 2004, 53, 0) }.should raise_error(ArgumentError)
- lambda { Date.send(@method, 2004, 53, 8) }.should raise_error(ArgumentError)
- lambda { Date.send(@method, 2004, 54, 1) }.should raise_error(ArgumentError)
- lambda { Date.send(@method, 2004, 0, 1) }.should raise_error(ArgumentError)
-
- lambda { Date.send(@method, 2003, 52, 1) }.should_not raise_error(ArgumentError)
- lambda { Date.send(@method, 2003, 53, 1) }.should raise_error(ArgumentError)
- lambda { Date.send(@method, 2003, 52, 0) }.should raise_error(ArgumentError)
- lambda { Date.send(@method, 2003, 52, 8) }.should raise_error(ArgumentError)
- end
-end
diff --git a/spec/ruby/library/date/shared/jd.rb b/spec/ruby/library/date/shared/jd.rb
deleted file mode 100644
index 511557b4f7..0000000000
--- a/spec/ruby/library/date/shared/jd.rb
+++ /dev/null
@@ -1,14 +0,0 @@
-describe :date_jd, shared: true do
- it "constructs a Date object if passed a Julian day" do
- Date.send(@method, 2454482).should == Date.civil(2008, 1, 16)
- end
-
- it "returns a Date object representing Julian day 0 (-4712-01-01) if no arguments passed" do
- Date.send(@method).should == Date.civil(-4712, 1, 1)
- end
-
- it "constructs a Date object if passed a negative number" do
- Date.send(@method, -1).should == Date.civil(-4713, 12, 31)
- end
-
-end
diff --git a/spec/ruby/library/date/shared/new_bang.rb b/spec/ruby/library/date/shared/new_bang.rb
deleted file mode 100644
index 90f1b432f0..0000000000
--- a/spec/ruby/library/date/shared/new_bang.rb
+++ /dev/null
@@ -1,14 +0,0 @@
-describe :date_new_bang, shared: true do
-
- it "returns a new Date object set to Astronomical Julian Day 0 if no arguments passed" do
- d = Date.send(@method)
- d.ajd.should == 0
- end
-
- it "accepts astronomical julian day number, offset as a fraction of a day and returns a new Date object" do
- d = Date.send(@method, 10, 0.5)
- d.ajd.should == 10
- d.jd.should == 11
- end
-
-end
diff --git a/spec/ruby/library/date/shared/ordinal.rb b/spec/ruby/library/date/shared/ordinal.rb
deleted file mode 100644
index 4b182d5a25..0000000000
--- a/spec/ruby/library/date/shared/ordinal.rb
+++ /dev/null
@@ -1,22 +0,0 @@
-# reference:
-# October 1582 (the Gregorian calendar, Civil Date)
-# S M Tu W Th F S
-# 1 2 3 4 15 16
-# 17 18 19 20 21 22 23
-# 24 25 26 27 28 29 30
-# 31
-
-describe :date_ordinal, shared: true do
- it "constructs a Date object from an ordinal date" do
- # October 1582 (the Gregorian calendar, Ordinal Date)
- # S M Tu W Th F S
- # 274 275 276 277 278 279
- # 280 281 282 283 284 285 286
- # 287 288 289 290 291 292 293
- # 294
- Date.send(@method, 1582, 274).should == Date.civil(1582, 10, 1)
- Date.send(@method, 1582, 277).should == Date.civil(1582, 10, 4)
- Date.send(@method, 1582, 278).should == Date.civil(1582, 10, 15)
- Date.send(@method, 1582, 287, Date::ENGLAND).should == Date.civil(1582, 10, 14, Date::ENGLAND)
- end
-end
diff --git a/spec/ruby/library/date/shared/parse.rb b/spec/ruby/library/date/shared/parse.rb
index 1015285e04..40af908386 100644
--- a/spec/ruby/library/date/shared/parse.rb
+++ b/spec/ruby/library/date/shared/parse.rb
@@ -13,7 +13,7 @@ describe :date_parse, shared: true do
d.day.should == 23
end
- it "can parse a 'mmm DD YYYY' string into a Date object" do
+ it "can parse a 'DD mmm YYYY' string into a Date object" do
d = Date.parse("23#{@sep}feb#{@sep}2008")
d.year.should == 2008
d.month.should == 2
@@ -42,7 +42,7 @@ describe :date_parse, shared: true do
d.should == Date.civil(2005, 11, 5)
end
- it "can parse a year, day and month name into a Date object" do
+ it "can parse a day, month name and year into a Date object" do
d = Date.parse("5th#{@sep}november#{@sep}2005")
d.should == Date.civil(2005, 11, 5)
end
diff --git a/spec/ruby/library/date/shared/parse_eu.rb b/spec/ruby/library/date/shared/parse_eu.rb
index ecb15e3c0e..3819524a57 100644
--- a/spec/ruby/library/date/shared/parse_eu.rb
+++ b/spec/ruby/library/date/shared/parse_eu.rb
@@ -7,28 +7,28 @@ describe :date_parse_eu, shared: true do
d.day.should == 1
end
- it "can parse a MM-DD-YYYY string into a Date object" do
+ it "can parse a DD-MM-YYYY string into a Date object" do
d = Date.parse("10#{@sep}01#{@sep}2007")
d.year.should == 2007
d.month.should == 1
d.day.should == 10
end
- it "can parse a MM-DD-YY string into a Date object" do
+ it "can parse a YY-MM-DD string into a Date object" do
d = Date.parse("10#{@sep}01#{@sep}07")
d.year.should == 2010
d.month.should == 1
d.day.should == 7
end
- it "can parse a MM-DD-YY string into a Date object NOT using the year digits as 20XX" do
+ it "can parse a YY-MM-DD string into a Date object NOT using the year digits as 20XX" do
d = Date.parse("10#{@sep}01#{@sep}07", false)
d.year.should == 10
d.month.should == 1
d.day.should == 7
end
- it "can parse a MM-DD-YY string into a Date object using the year digits as 20XX" do
+ it "can parse a YY-MM-DD string into a Date object using the year digits as 20XX" do
d = Date.parse("10#{@sep}01#{@sep}07", true)
d.year.should == 2010
d.month.should == 1
diff --git a/spec/ruby/library/date/shared/parse_us.rb b/spec/ruby/library/date/shared/parse_us.rb
index 7be62b1af1..17e2fc96c1 100644
--- a/spec/ruby/library/date/shared/parse_us.rb
+++ b/spec/ruby/library/date/shared/parse_us.rb
@@ -6,28 +6,28 @@ describe :date_parse_us, shared: true do
d.day.should == 1
end
- it "parses a MM#{@sep}DD#{@sep}YYYY string into a Date object" do
+ it "parses a DD#{@sep}MM#{@sep}YYYY string into a Date object" do
d = Date.parse("10#{@sep}01#{@sep}2007")
d.year.should == 2007
d.month.should == 1
d.day.should == 10
end
- it "parses a MM#{@sep}DD#{@sep}YY string into a Date object" do
+ it "parses a YY#{@sep}MM#{@sep}DD string into a Date object" do
d = Date.parse("10#{@sep}01#{@sep}07")
d.year.should == 2010
d.month.should == 1
d.day.should == 7
end
- it "parses a MM#{@sep}DD#{@sep}YY string into a Date object NOT using the year digits as 20XX" do
+ it "parses a YY#{@sep}MM#{@sep}DD string into a Date object NOT using the year digits as 20XX" do
d = Date.parse("10#{@sep}01#{@sep}07", false)
d.year.should == 10
d.month.should == 1
d.day.should == 7
end
- it "parses a MM#{@sep}DD#{@sep}YY string into a Date object using the year digits as 20XX" do
+ it "parses a YY#{@sep}MM#{@sep}DD string into a Date object using the year digits as 20XX" do
d = Date.parse("10#{@sep}01#{@sep}07", true)
d.year.should == 2010
d.month.should == 1
diff --git a/spec/ruby/library/date/shared/valid_civil.rb b/spec/ruby/library/date/shared/valid_civil.rb
deleted file mode 100644
index 545c207bbe..0000000000
--- a/spec/ruby/library/date/shared/valid_civil.rb
+++ /dev/null
@@ -1,36 +0,0 @@
-describe :date_valid_civil?, shared: true do
-
- # reference:
- # October 1582 (the Gregorian calendar, Civil Date)
- # S M Tu W Th F S
- # 1 2 3 4 15 16
- # 17 18 19 20 21 22 23
- # 24 25 26 27 28 29 30
- # 31
-
- it "returns true if it is a valid civil date" do
- Date.send(@method, 1582, 10, 15).should be_true
- Date.send(@method, 1582, 10, 14, Date::ENGLAND).should be_true
- end
-
- it "returns false if it is not a valid civil date" do
- Date.send(@method, 1582, 10, 14).should == false
- end
-
- it "handles negative months and days" do
- # October 1582 (the Gregorian calendar, Civil Date)
- # S M Tu W Th F S
- # -21 -20 -19 -18 -17 -16
- # -15 -14 -13 -12 -11 -10 -9
- # -8 -7 -6 -5 -4 -3 -2
- # -1
- Date.send(@method, 1582, -3, -22).should be_false
- Date.send(@method, 1582, -3, -21).should be_true
- Date.send(@method, 1582, -3, -18).should be_true
- Date.send(@method, 1582, -3, -17).should be_true
-
- Date.send(@method, 2007, -11, -10).should be_true
- Date.send(@method, 2008, -11, -10).should be_true
- end
-
-end
diff --git a/spec/ruby/library/date/shared/valid_commercial.rb b/spec/ruby/library/date/shared/valid_commercial.rb
deleted file mode 100644
index 117dfe1d3d..0000000000
--- a/spec/ruby/library/date/shared/valid_commercial.rb
+++ /dev/null
@@ -1,34 +0,0 @@
-describe :date_valid_commercial?, shared: true do
-
- it "returns true if it is a valid commercial date" do
- # October 1582 (the Gregorian calendar, Commercial Date)
- # M Tu W Th F Sa Su
- # 39: 1 2 3 4 5 6 7
- # 40: 1 2 3 4 5 6 7
- # 41: 1 2 3 4 5 6 7
- Date.send(@method, 1582, 39, 4).should be_true
- Date.send(@method, 1582, 39, 5).should be_true
- Date.send(@method, 1582, 41, 4).should be_true
- Date.send(@method, 1582, 41, 5).should be_true
- Date.send(@method, 1582, 41, 4, Date::ENGLAND).should be_true
- Date.send(@method, 1752, 37, 4, Date::ENGLAND).should be_true
- end
-
- it "returns false it is not a valid commercial date" do
- Date.send(@method, 1999, 53, 1).should be_false
- end
-
- it "handles negative week and day numbers" do
- # October 1582 (the Gregorian calendar, Commercial Date)
- # M Tu W Th F Sa Su
- # -12: -7 -6 -5 -4 -3 -2 -1
- # -11: -7 -6 -5 -4 -3 -2 -1
- # -10: -7 -6 -5 -4 -3 -2 -1
- Date.send(@method, 1582, -12, -4).should be_true
- Date.send(@method, 1582, -12, -3).should be_true
- Date.send(@method, 2007, -44, -2).should be_true
- Date.send(@method, 2008, -44, -2).should be_true
- Date.send(@method, 1999, -53, -1).should be_false
- end
-
-end
diff --git a/spec/ruby/library/date/shared/valid_jd.rb b/spec/ruby/library/date/shared/valid_jd.rb
deleted file mode 100644
index d8a35992b3..0000000000
--- a/spec/ruby/library/date/shared/valid_jd.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-describe :date_valid_jd?, shared: true do
- it "returns true if passed any value other than nil" do
- Date.send(@method, -100).should be_true
- Date.send(@method, :number).should be_true
- Date.send(@method, Rational(1,2)).should be_true
- end
-
- it "returns false if passed nil" do
- Date.send(@method, nil).should be_false
- end
-
- it "returns true if passed false" do
- Date.send(@method, false).should be_true
- end
-end
diff --git a/spec/ruby/library/date/shared/valid_ordinal.rb b/spec/ruby/library/date/shared/valid_ordinal.rb
deleted file mode 100644
index 1ed961be23..0000000000
--- a/spec/ruby/library/date/shared/valid_ordinal.rb
+++ /dev/null
@@ -1,26 +0,0 @@
-describe :date_valid_ordinal?, shared: true do
- it "determines if the date is a valid ordinal date" do
- # October 1582 (the Gregorian calendar, Ordinal Date)
- # S M Tu W Th F S
- # 274 275 276 277 278 279
- # 280 281 282 283 284 285 286
- # 287 288 289 290 291 292 293
- # 294
- Date.send(@method, 1582, 277).should == true
- Date.send(@method, 1582, 278).should == true
- Date.send(@method, 1582, 287).should == true
- Date.send(@method, 1582, 288).should == true
- end
-
- it "handles negative day numbers" do
- # October 1582 (the Gregorian calendar, Ordinal Date)
- # S M Tu W Th F S
- # -82 -81 -80 -79 -78 -77
- # -76 -75 -74 -73 -72 -71 -70
- # -69 -68 -67 -66 -65 -64 -63
- # -62
- Date.send(@method, 1582, -79).should == true
- Date.send(@method, 1582, -78).should == true
- Date.send(@method, 2007, -100).should == true
- end
-end
diff --git a/spec/ruby/library/date/start_spec.rb b/spec/ruby/library/date/start_spec.rb
index 285037b094..8ba272a7f3 100644
--- a/spec/ruby/library/date/start_spec.rb
+++ b/spec/ruby/library/date/start_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date#start" do
diff --git a/spec/ruby/library/date/step_spec.rb b/spec/ruby/library/date/step_spec.rb
index 249633e807..6bbd671840 100644
--- a/spec/ruby/library/date/step_spec.rb
+++ b/spec/ruby/library/date/step_spec.rb
@@ -1,5 +1,5 @@
require 'date'
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Date#step" do
diff --git a/spec/ruby/library/date/strftime_spec.rb b/spec/ruby/library/date/strftime_spec.rb
index 81bb162ff7..1b93a8d1b2 100644
--- a/spec/ruby/library/date/strftime_spec.rb
+++ b/spec/ruby/library/date/strftime_spec.rb
@@ -1,9 +1,11 @@
+require_relative "../../spec_helper"
require 'date'
-require File.expand_path('../../../shared/time/strftime_for_date', __FILE__)
+require_relative '../../shared/time/strftime_for_date'
+date_version = defined?(Date::VERSION) ? Date::VERSION : '3.1.0'
describe "Date#strftime" do
before :all do
- @new_date = lambda { |y,m,d| Date.civil(y,m,d) }
+ @new_date = -> y, m, d { Date.civil(y,m,d) }
@date = Date.civil(2000, 4, 9)
end
@@ -21,10 +23,9 @@ describe "Date#strftime" do
@date.strftime("%Z").should == "+00:00"
end
- # %v is %e-%b-%Y for Date/DateTime
it "should be able to show the commercial week" do
- @date.strftime("%v").should == " 9-Apr-2000"
- @date.strftime("%v").should == @date.strftime('%e-%b-%Y')
+ @date.strftime("%v").should == " 9-APR-2000"
+ @date.strftime("%v").should != @date.strftime('%e-%b-%Y')
end
# additional conversion specifiers only in Date/DateTime
diff --git a/spec/ruby/library/date/strptime_spec.rb b/spec/ruby/library/date/strptime_spec.rb
index 21a73da086..c90721751e 100644
--- a/spec/ruby/library/date/strptime_spec.rb
+++ b/spec/ruby/library/date/strptime_spec.rb
@@ -1,5 +1,5 @@
require 'date'
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "Date#strptime" do
diff --git a/spec/ruby/library/date/succ_spec.rb b/spec/ruby/library/date/succ_spec.rb
index 2650810e73..0b14d3bb73 100644
--- a/spec/ruby/library/date/succ_spec.rb
+++ b/spec/ruby/library/date/succ_spec.rb
@@ -1,6 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date#succ" do
- it "needs to be reviewed for spec completeness"
+ it "is an alias of Date#next" do
+ Date.instance_method(:succ).should == Date.instance_method(:next)
+ end
end
diff --git a/spec/ruby/library/date/sunday_spec.rb b/spec/ruby/library/date/sunday_spec.rb
index d805006264..548f36a4f0 100644
--- a/spec/ruby/library/date/sunday_spec.rb
+++ b/spec/ruby/library/date/sunday_spec.rb
@@ -1,8 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date#sunday?" do
it "should be sunday" do
- Date.new(2000, 1, 2).sunday?.should be_true
+ Date.new(2000, 1, 2).sunday?.should == true
end
end
diff --git a/spec/ruby/library/date/thursday_spec.rb b/spec/ruby/library/date/thursday_spec.rb
index a59ca3f6cf..4df3b9103a 100644
--- a/spec/ruby/library/date/thursday_spec.rb
+++ b/spec/ruby/library/date/thursday_spec.rb
@@ -1,8 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date#thursday?" do
it "should be thursday" do
- Date.new(2000, 1, 6).thursday?.should be_true
+ Date.new(2000, 1, 6).thursday?.should == true
end
end
diff --git a/spec/ruby/library/date/time/to_date_spec.rb b/spec/ruby/library/date/time/to_date_spec.rb
new file mode 100644
index 0000000000..f9132da289
--- /dev/null
+++ b/spec/ruby/library/date/time/to_date_spec.rb
@@ -0,0 +1,42 @@
+
+require_relative '../../../spec_helper'
+require 'time'
+
+describe "Time#to_date" do
+ it "yields accurate julian date for ambiguous pre-Gregorian reform value" do
+ Time.utc(1582, 10, 4).to_date.jd.should == Date::ITALY - 11 # 2299150j
+ end
+
+ it "yields accurate julian date for Julian-Gregorian gap value" do
+ Time.utc(1582, 10, 14).to_date.jd.should == Date::ITALY - 1 # 2299160j
+ end
+
+ it "yields accurate julian date for post-Gregorian reform value" do
+ Time.utc(1582, 10, 15).to_date.jd.should == Date::ITALY # 2299161j
+ end
+
+ it "yields same julian day regardless of UTC time value" do
+ Time.utc(1582, 10, 15, 00, 00, 00).to_date.jd.should == Date::ITALY
+ Time.utc(1582, 10, 15, 23, 59, 59).to_date.jd.should == Date::ITALY
+ end
+
+ it "yields same julian day regardless of local time or zone" do
+
+ with_timezone("Pacific/Pago_Pago", -11) do
+ Time.local(1582, 10, 15, 00, 00, 00).to_date.jd.should == Date::ITALY
+ Time.local(1582, 10, 15, 23, 59, 59).to_date.jd.should == Date::ITALY
+ end
+
+ with_timezone("Asia/Kamchatka", +12) do
+ Time.local(1582, 10, 15, 00, 00, 00).to_date.jd.should == Date::ITALY
+ Time.local(1582, 10, 15, 23, 59, 59).to_date.jd.should == Date::ITALY
+ end
+
+ end
+
+ it "yields date with default Calendar reform day" do
+ Time.utc(1582, 10, 4).to_date.start.should == Date::ITALY
+ Time.utc(1582, 10, 14).to_date.start.should == Date::ITALY
+ Time.utc(1582, 10, 15).to_date.start.should == Date::ITALY
+ end
+end
diff --git a/spec/ruby/library/date/time_to_day_fraction_spec.rb b/spec/ruby/library/date/time_to_day_fraction_spec.rb
index 06d477b601..e59980e036 100644
--- a/spec/ruby/library/date/time_to_day_fraction_spec.rb
+++ b/spec/ruby/library/date/time_to_day_fraction_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date.time_to_day_fraction" do
diff --git a/spec/ruby/library/date/to_s_spec.rb b/spec/ruby/library/date/to_s_spec.rb
index a81297d689..fe7cb19a46 100644
--- a/spec/ruby/library/date/to_s_spec.rb
+++ b/spec/ruby/library/date/to_s_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date#to_s" do
diff --git a/spec/ruby/library/date/today_spec.rb b/spec/ruby/library/date/today_spec.rb
index d487be089f..4be8d8e931 100644
--- a/spec/ruby/library/date/today_spec.rb
+++ b/spec/ruby/library/date/today_spec.rb
@@ -1,9 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date.today" do
it "returns a Date object" do
- Date.today.should be_kind_of Date
+ Date.today.should.is_a? Date
end
it "sets Date object to the current date" do
diff --git a/spec/ruby/library/date/tuesday_spec.rb b/spec/ruby/library/date/tuesday_spec.rb
index 10ed6755d1..db31387aed 100644
--- a/spec/ruby/library/date/tuesday_spec.rb
+++ b/spec/ruby/library/date/tuesday_spec.rb
@@ -1,8 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date#tuesday?" do
it "should be tuesday" do
- Date.new(2000, 1, 4).tuesday?.should be_true
+ Date.new(2000, 1, 4).tuesday?.should == true
end
end
diff --git a/spec/ruby/library/date/upto_spec.rb b/spec/ruby/library/date/upto_spec.rb
index c99aabd1d7..8745be85b3 100644
--- a/spec/ruby/library/date/upto_spec.rb
+++ b/spec/ruby/library/date/upto_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date#upto" do
diff --git a/spec/ruby/library/date/valid_civil_spec.rb b/spec/ruby/library/date/valid_civil_spec.rb
index 09185674ee..8cffc80310 100644
--- a/spec/ruby/library/date/valid_civil_spec.rb
+++ b/spec/ruby/library/date/valid_civil_spec.rb
@@ -1,10 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/valid_civil', __FILE__)
+require_relative '../../spec_helper'
require 'date'
-describe "Date#valid_civil?" do
-
- it_behaves_like :date_valid_civil?, :valid_civil?
-
+describe "Date.valid_civil?" do
+ it "is an alias of Date.valid_date?" do
+ Date.method(:valid_civil?).should == Date.method(:valid_date?)
+ end
end
-
diff --git a/spec/ruby/library/date/valid_commercial_spec.rb b/spec/ruby/library/date/valid_commercial_spec.rb
index 187d818233..21a91ad867 100644
--- a/spec/ruby/library/date/valid_commercial_spec.rb
+++ b/spec/ruby/library/date/valid_commercial_spec.rb
@@ -1,10 +1,35 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/valid_commercial', __FILE__)
+require_relative '../../spec_helper'
require 'date'
-describe "Date#valid_commercial?" do
-
- it_behaves_like :date_valid_commercial?, :valid_commercial?
-end
+describe "Date.valid_commercial?" do
+ it "returns true if it is a valid commercial date" do
+ # October 1582 (the Gregorian calendar, Commercial Date)
+ # M Tu W Th F Sa Su
+ # 39: 1 2 3 4 5 6 7
+ # 40: 1 2 3 4 5 6 7
+ # 41: 1 2 3 4 5 6 7
+ Date.valid_commercial?(1582, 39, 4).should == true
+ Date.valid_commercial?(1582, 39, 5).should == true
+ Date.valid_commercial?(1582, 41, 4).should == true
+ Date.valid_commercial?(1582, 41, 5).should == true
+ Date.valid_commercial?(1582, 41, 4, Date::ENGLAND).should == true
+ Date.valid_commercial?(1752, 37, 4, Date::ENGLAND).should == true
+ end
+ it "returns false it is not a valid commercial date" do
+ Date.valid_commercial?(1999, 53, 1).should == false
+ end
+ it "handles negative week and day numbers" do
+ # October 1582 (the Gregorian calendar, Commercial Date)
+ # M Tu W Th F Sa Su
+ # -12: -7 -6 -5 -4 -3 -2 -1
+ # -11: -7 -6 -5 -4 -3 -2 -1
+ # -10: -7 -6 -5 -4 -3 -2 -1
+ Date.valid_commercial?(1582, -12, -4).should == true
+ Date.valid_commercial?(1582, -12, -3).should == true
+ Date.valid_commercial?(2007, -44, -2).should == true
+ Date.valid_commercial?(2008, -44, -2).should == true
+ Date.valid_commercial?(1999, -53, -1).should == false
+ end
+end
diff --git a/spec/ruby/library/date/valid_date_spec.rb b/spec/ruby/library/date/valid_date_spec.rb
index ffaf007cd1..f0d5ec7b4d 100644
--- a/spec/ruby/library/date/valid_date_spec.rb
+++ b/spec/ruby/library/date/valid_date_spec.rb
@@ -1,7 +1,36 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/valid_civil', __FILE__)
+require_relative '../../spec_helper'
require 'date'
-describe "Date#valid_date?" do
- it_behaves_like :date_valid_civil?, :valid_date?
+describe "Date.valid_date?" do
+ # reference:
+ # October 1582 (the Gregorian calendar, Civil Date)
+ # S M Tu W Th F S
+ # 1 2 3 4 15 16
+ # 17 18 19 20 21 22 23
+ # 24 25 26 27 28 29 30
+ # 31
+ it "returns true if it is a valid civil date" do
+ Date.valid_date?(1582, 10, 15).should == true
+ Date.valid_date?(1582, 10, 14, Date::ENGLAND).should == true
+ end
+
+ it "returns false if it is not a valid civil date" do
+ Date.valid_date?(1582, 10, 14).should == false
+ end
+
+ it "handles negative months and days" do
+ # October 1582 (the Gregorian calendar, Civil Date)
+ # S M Tu W Th F S
+ # -21 -20 -19 -18 -17 -16
+ # -15 -14 -13 -12 -11 -10 -9
+ # -8 -7 -6 -5 -4 -3 -2
+ # -1
+ Date.valid_date?(1582, -3, -22).should == false
+ Date.valid_date?(1582, -3, -21).should == true
+ Date.valid_date?(1582, -3, -18).should == true
+ Date.valid_date?(1582, -3, -17).should == true
+
+ Date.valid_date?(2007, -11, -10).should == true
+ Date.valid_date?(2008, -11, -10).should == true
+ end
end
diff --git a/spec/ruby/library/date/valid_jd_spec.rb b/spec/ruby/library/date/valid_jd_spec.rb
index 9764c02f2b..46f22de497 100644
--- a/spec/ruby/library/date/valid_jd_spec.rb
+++ b/spec/ruby/library/date/valid_jd_spec.rb
@@ -1,10 +1,23 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/valid_jd', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date.valid_jd?" do
+ it "returns true if passed a number value" do
+ Date.valid_jd?(-100).should == true
+ Date.valid_jd?(100.0).should == true
+ Date.valid_jd?(2**100).should == true
+ Date.valid_jd?(Rational(1,2)).should == true
+ end
- it_behaves_like :date_valid_jd?, :valid_jd?
+ it "returns false if passed nil" do
+ Date.valid_jd?(nil).should == false
+ end
-end
+ it "returns false if passed symbol" do
+ Date.valid_jd?(:number).should == false
+ end
+ it "returns false if passed false" do
+ Date.valid_jd?(false).should == false
+ end
+end
diff --git a/spec/ruby/library/date/valid_ordinal_spec.rb b/spec/ruby/library/date/valid_ordinal_spec.rb
index e197bb2051..bb5c259606 100644
--- a/spec/ruby/library/date/valid_ordinal_spec.rb
+++ b/spec/ruby/library/date/valid_ordinal_spec.rb
@@ -1,10 +1,29 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/valid_ordinal', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date.valid_ordinal?" do
+ it "determines if the date is a valid ordinal date" do
+ # October 1582 (the Gregorian calendar, Ordinal Date)
+ # S M Tu W Th F S
+ # 274 275 276 277 278 279
+ # 280 281 282 283 284 285 286
+ # 287 288 289 290 291 292 293
+ # 294
+ Date.valid_ordinal?(1582, 277).should == true
+ Date.valid_ordinal?(1582, 278).should == true
+ Date.valid_ordinal?(1582, 287).should == true
+ Date.valid_ordinal?(1582, 288).should == true
+ end
- it_behaves_like :date_valid_ordinal?, :valid_ordinal?
-
+ it "handles negative day numbers" do
+ # October 1582 (the Gregorian calendar, Ordinal Date)
+ # S M Tu W Th F S
+ # -82 -81 -80 -79 -78 -77
+ # -76 -75 -74 -73 -72 -71 -70
+ # -69 -68 -67 -66 -65 -64 -63
+ # -62
+ Date.valid_ordinal?(1582, -79).should == true
+ Date.valid_ordinal?(1582, -78).should == true
+ Date.valid_ordinal?(2007, -100).should == true
+ end
end
-
diff --git a/spec/ruby/library/date/valid_time_spec.rb b/spec/ruby/library/date/valid_time_spec.rb
index e96f9041b7..87c239bedb 100644
--- a/spec/ruby/library/date/valid_time_spec.rb
+++ b/spec/ruby/library/date/valid_time_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date.valid_time?" do
diff --git a/spec/ruby/library/date/wday_spec.rb b/spec/ruby/library/date/wday_spec.rb
index 7303423123..303905ed35 100644
--- a/spec/ruby/library/date/wday_spec.rb
+++ b/spec/ruby/library/date/wday_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date#wday" do
diff --git a/spec/ruby/library/date/wednesday_spec.rb b/spec/ruby/library/date/wednesday_spec.rb
index 99478f21c2..4bbeead5b8 100644
--- a/spec/ruby/library/date/wednesday_spec.rb
+++ b/spec/ruby/library/date/wednesday_spec.rb
@@ -1,8 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date#wednesday?" do
it "should be wednesday" do
- Date.new(2000, 1, 5).wednesday?.should be_true
+ Date.new(2000, 1, 5).wednesday?.should == true
end
end
diff --git a/spec/ruby/library/date/yday_spec.rb b/spec/ruby/library/date/yday_spec.rb
index 92bf616406..7dd42e52a5 100644
--- a/spec/ruby/library/date/yday_spec.rb
+++ b/spec/ruby/library/date/yday_spec.rb
@@ -1,6 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
+require_relative '../../shared/time/yday'
require 'date'
describe "Date#yday" do
- it "needs to be reviewed for spec completeness"
+ it_behaves_like :time_yday, -> year, month, day { Date.new(year, month, day).yday }
end
diff --git a/spec/ruby/library/date/year_spec.rb b/spec/ruby/library/date/year_spec.rb
index 4720ddcd9a..90d14e5a39 100644
--- a/spec/ruby/library/date/year_spec.rb
+++ b/spec/ruby/library/date/year_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date#year" do
diff --git a/spec/ruby/library/date/zone_to_diff_spec.rb b/spec/ruby/library/date/zone_to_diff_spec.rb
index a39de0b58e..354daaaee4 100644
--- a/spec/ruby/library/date/zone_to_diff_spec.rb
+++ b/spec/ruby/library/date/zone_to_diff_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "Date.zone_to_diff" do
diff --git a/spec/ruby/library/datetime/_strptime_spec.rb b/spec/ruby/library/datetime/_strptime_spec.rb
index c8c910618d..abec26ff9f 100644
--- a/spec/ruby/library/datetime/_strptime_spec.rb
+++ b/spec/ruby/library/datetime/_strptime_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "DateTime._strptime" do
diff --git a/spec/ruby/library/datetime/add_spec.rb b/spec/ruby/library/datetime/add_spec.rb
new file mode 100644
index 0000000000..20288e2105
--- /dev/null
+++ b/spec/ruby/library/datetime/add_spec.rb
@@ -0,0 +1,9 @@
+require_relative '../../spec_helper'
+require 'date'
+
+describe "DateTime#+" do
+ it "is able to add sub-millisecond precision values" do
+ datetime = DateTime.new(2017)
+ (datetime + 0.00001001).to_time.usec.should == 864864
+ end
+end
diff --git a/spec/ruby/library/datetime/civil_spec.rb b/spec/ruby/library/datetime/civil_spec.rb
index 77df021e33..fb6f67f16d 100644
--- a/spec/ruby/library/datetime/civil_spec.rb
+++ b/spec/ruby/library/datetime/civil_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "DateTime.civil" do
diff --git a/spec/ruby/library/datetime/commercial_spec.rb b/spec/ruby/library/datetime/commercial_spec.rb
index 2984dd5334..ad97b2a80e 100644
--- a/spec/ruby/library/datetime/commercial_spec.rb
+++ b/spec/ruby/library/datetime/commercial_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "DateTime.commercial" do
diff --git a/spec/ruby/library/datetime/deconstruct_keys_spec.rb b/spec/ruby/library/datetime/deconstruct_keys_spec.rb
new file mode 100644
index 0000000000..07a7bda881
--- /dev/null
+++ b/spec/ruby/library/datetime/deconstruct_keys_spec.rb
@@ -0,0 +1,44 @@
+require_relative '../../spec_helper'
+require 'date'
+date_version = defined?(Date::VERSION) ? Date::VERSION : '3.1.0'
+
+describe "DateTime#deconstruct_keys" do
+ it "returns whole hash for nil as an argument" do
+ d = DateTime.new(2022, 10, 5, 13, 30)
+ res = { year: 2022, month: 10, day: 5, yday: 278, wday: 3, hour: 13,
+ min: 30, sec: 0, sec_fraction: (0/1), zone: "+00:00" }
+ d.deconstruct_keys(nil).should == res
+ end
+
+ it "returns only specified keys" do
+ d = DateTime.new(2022, 10, 5, 13, 39)
+ d.deconstruct_keys([:zone, :hour]).should == { zone: "+00:00", hour: 13 }
+ end
+
+ it "requires one argument" do
+ -> {
+ DateTime.new(2022, 10, 5, 13, 30).deconstruct_keys
+ }.should.raise(ArgumentError)
+ end
+
+ it "it raises error when argument is neither nil nor array" do
+ d = DateTime.new(2022, 10, 5, 13, 30)
+
+ -> { d.deconstruct_keys(1) }.should.raise(TypeError, "wrong argument type Integer (expected Array or nil)")
+ -> { d.deconstruct_keys("asd") }.should.raise(TypeError, "wrong argument type String (expected Array or nil)")
+ -> { d.deconstruct_keys(:x) }.should.raise(TypeError, "wrong argument type Symbol (expected Array or nil)")
+ -> { d.deconstruct_keys({}) }.should.raise(TypeError, "wrong argument type Hash (expected Array or nil)")
+ end
+
+ it "returns {} when passed []" do
+ DateTime.new(2022, 10, 5, 13, 30).deconstruct_keys([]).should == {}
+ end
+
+ it "ignores non-Symbol keys" do
+ DateTime.new(2022, 10, 5, 13, 30).deconstruct_keys(['year', []]).should == {}
+ end
+
+ it "ignores not existing Symbol keys" do
+ DateTime.new(2022, 10, 5, 13, 30).deconstruct_keys([:year, :a]).should == { year: 2022 }
+ end
+end
diff --git a/spec/ruby/library/datetime/hour_spec.rb b/spec/ruby/library/datetime/hour_spec.rb
index db89016937..5d8e75edcb 100644
--- a/spec/ruby/library/datetime/hour_spec.rb
+++ b/spec/ruby/library/datetime/hour_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "DateTime#hour" do
@@ -15,28 +15,27 @@ describe "DateTime#hour" do
end
it "raises an error for Rational" do
- lambda { new_datetime(hour: 1 + Rational(1,2)) }.should raise_error(ArgumentError)
+ -> { new_datetime(hour: 1 + Rational(1,2)) }.should.raise(ArgumentError)
end
it "raises an error for Float" do
- lambda { new_datetime(hour: 1.5).hour }.should raise_error(ArgumentError)
+ -> { new_datetime(hour: 1.5).hour }.should.raise(ArgumentError)
end
it "raises an error for Rational" do
- lambda { new_datetime(day: 1 + Rational(1,2)) }.should raise_error(ArgumentError)
+ -> { new_datetime(day: 1 + Rational(1,2)) }.should.raise(ArgumentError)
end
it "raises an error, when the hour is smaller than -24" do
- lambda { new_datetime(hour: -25) }.should raise_error(ArgumentError)
+ -> { new_datetime(hour: -25) }.should.raise(ArgumentError)
end
it "raises an error, when the hour is larger than 24" do
- lambda { new_datetime(hour: 25) }.should raise_error(ArgumentError)
+ -> { new_datetime(hour: 25) }.should.raise(ArgumentError)
end
it "raises an error for hour fractions smaller than -24" do
- lambda { new_datetime(hour: -24 - Rational(1,2)) }.should(
- raise_error(ArgumentError))
+ -> { new_datetime(hour: -24 - Rational(1,2)) }.should.raise(ArgumentError)
end
it "adds 1 to day, when 24 hours given" do
diff --git a/spec/ruby/library/datetime/httpdate_spec.rb b/spec/ruby/library/datetime/httpdate_spec.rb
index e97fda7fb4..68e45cbff0 100644
--- a/spec/ruby/library/datetime/httpdate_spec.rb
+++ b/spec/ruby/library/datetime/httpdate_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "DateTime.httpdate" do
diff --git a/spec/ruby/library/datetime/iso8601_spec.rb b/spec/ruby/library/datetime/iso8601_spec.rb
index 44887148d3..4368300fd5 100644
--- a/spec/ruby/library/datetime/iso8601_spec.rb
+++ b/spec/ruby/library/datetime/iso8601_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "DateTime.iso8601" do
@@ -6,5 +6,7 @@ describe "DateTime.iso8601" do
end
describe "DateTime#iso8601" do
- it "needs to be reviewed for spec completeness"
+ it "is an alias of DateTime#isoxmlschema8601" do
+ DateTime.instance_method(:iso8601).should == DateTime.instance_method(:xmlschema)
+ end
end
diff --git a/spec/ruby/library/datetime/jd_spec.rb b/spec/ruby/library/datetime/jd_spec.rb
index e8271089f7..1e783f5af4 100644
--- a/spec/ruby/library/datetime/jd_spec.rb
+++ b/spec/ruby/library/datetime/jd_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "DateTime.jd" do
diff --git a/spec/ruby/library/datetime/jisx0301_spec.rb b/spec/ruby/library/datetime/jisx0301_spec.rb
index 2402a21cb0..ab26aa2d73 100644
--- a/spec/ruby/library/datetime/jisx0301_spec.rb
+++ b/spec/ruby/library/datetime/jisx0301_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "DateTime.jisx0301" do
diff --git a/spec/ruby/library/datetime/min_spec.rb b/spec/ruby/library/datetime/min_spec.rb
index 5f7d7e7810..ca995a7eed 100644
--- a/spec/ruby/library/datetime/min_spec.rb
+++ b/spec/ruby/library/datetime/min_spec.rb
@@ -1,6 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/min', __FILE__)
+require_relative '../../spec_helper'
+require 'date'
-describe "DateTime.min" do
- it_behaves_like :datetime_min, :min
+describe "DateTime#min" do
+ it "is an alias of DateTime#minute" do
+ DateTime.instance_method(:min).should == DateTime.instance_method(:minute)
+ end
end
diff --git a/spec/ruby/library/datetime/minute_spec.rb b/spec/ruby/library/datetime/minute_spec.rb
index 3ab01572fe..6e99752de7 100644
--- a/spec/ruby/library/datetime/minute_spec.rb
+++ b/spec/ruby/library/datetime/minute_spec.rb
@@ -1,6 +1,40 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/min', __FILE__)
+require_relative '../../spec_helper'
+require 'date'
-describe "DateTime.minute" do
- it_behaves_like :datetime_min, :minute
+describe "DateTime#minute" do
+ it "returns 0 if no argument is passed" do
+ DateTime.new.minute.should == 0
+ end
+
+ it "returns the minute passed as argument" do
+ new_datetime(minute: 5).minute.should == 5
+ end
+
+ it "adds 60 to negative minutes" do
+ new_datetime(minute: -20).minute.should == 40
+ end
+
+ it "raises an error for Rational" do
+ -> { new_datetime minute: 5 + Rational(1,2) }.should.raise(ArgumentError)
+ end
+
+ it "raises an error for Float" do
+ -> { new_datetime minute: 5.5 }.should.raise(ArgumentError)
+ end
+
+ it "raises an error for Rational" do
+ -> { new_datetime(hour: 2 + Rational(1,2)) }.should.raise(ArgumentError)
+ end
+
+ it "raises an error, when the minute is smaller than -60" do
+ -> { new_datetime(minute: -61) }.should.raise(ArgumentError)
+ end
+
+ it "raises an error, when the minute is greater or equal than 60" do
+ -> { new_datetime(minute: 60) }.should.raise(ArgumentError)
+ end
+
+ it "raises an error for minute fractions smaller than -60" do
+ -> { new_datetime(minute: -60 - Rational(1,2))}.should.raise(ArgumentError)
+ end
end
diff --git a/spec/ruby/library/datetime/new_offset_spec.rb b/spec/ruby/library/datetime/new_offset_spec.rb
index b900de6097..bc0988f32d 100644
--- a/spec/ruby/library/datetime/new_offset_spec.rb
+++ b/spec/ruby/library/datetime/new_offset_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "DateTime#new_offset" do
diff --git a/spec/ruby/library/datetime/new_spec.rb b/spec/ruby/library/datetime/new_spec.rb
index 14ef329d56..2b3c3f156c 100644
--- a/spec/ruby/library/datetime/new_spec.rb
+++ b/spec/ruby/library/datetime/new_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "DateTime.new" do
@@ -47,6 +47,6 @@ describe "DateTime.new" do
end
it "raises an error on invalid arguments" do
- lambda { new_datetime(minute: 999) }.should raise_error(ArgumentError)
+ -> { new_datetime(minute: 999) }.should.raise(ArgumentError)
end
end
diff --git a/spec/ruby/library/datetime/now_spec.rb b/spec/ruby/library/datetime/now_spec.rb
index a5bf590aff..5c0411c2be 100644
--- a/spec/ruby/library/datetime/now_spec.rb
+++ b/spec/ruby/library/datetime/now_spec.rb
@@ -1,19 +1,19 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "DateTime.now" do
it "creates an instance of DateTime" do
- DateTime.now.should be_an_instance_of(DateTime)
+ DateTime.now.should.instance_of?(DateTime)
end
it "sets the current date" do
- (DateTime.now - Date.today).to_f.should be_close(0.0, 1.0)
+ (DateTime.now - Date.today).to_f.should be_close(0.0, TIME_TOLERANCE)
end
it "sets the current time" do
dt = DateTime.now
now = Time.now
- (dt.to_time - now).should be_close(0.0, 10.0)
+ (dt.to_time - now).should be_close(0.0, TIME_TOLERANCE)
end
it "grabs the local timezone" do
diff --git a/spec/ruby/library/datetime/offset_spec.rb b/spec/ruby/library/datetime/offset_spec.rb
index c11d28bad2..e25e7a0f35 100644
--- a/spec/ruby/library/datetime/offset_spec.rb
+++ b/spec/ruby/library/datetime/offset_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "DateTime#offset" do
diff --git a/spec/ruby/library/datetime/ordinal_spec.rb b/spec/ruby/library/datetime/ordinal_spec.rb
index 2ada512e05..64b154ee9b 100644
--- a/spec/ruby/library/datetime/ordinal_spec.rb
+++ b/spec/ruby/library/datetime/ordinal_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "DateTime.ordinal" do
diff --git a/spec/ruby/library/datetime/parse_spec.rb b/spec/ruby/library/datetime/parse_spec.rb
index 14a68f1499..0a965273a0 100644
--- a/spec/ruby/library/datetime/parse_spec.rb
+++ b/spec/ruby/library/datetime/parse_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "DateTime.parse" do
@@ -20,7 +20,7 @@ describe "DateTime.parse" do
# Specs using numbers
it "throws an argument error for a single digit" do
- lambda{ DateTime.parse("1") }.should raise_error(ArgumentError)
+ ->{ DateTime.parse("1") }.should.raise(ArgumentError)
end
it "parses DD as month day number" do
@@ -54,23 +54,23 @@ describe "DateTime.parse" do
end
it "throws an argument error for invalid month values" do
- lambda{DateTime.parse("2012-13-08T15:43:59")}.should raise_error(ArgumentError)
+ ->{DateTime.parse("2012-13-08T15:43:59")}.should.raise(ArgumentError)
end
it "throws an argument error for invalid day values" do
- lambda{DateTime.parse("2012-12-32T15:43:59")}.should raise_error(ArgumentError)
+ ->{DateTime.parse("2012-12-32T15:43:59")}.should.raise(ArgumentError)
end
it "throws an argument error for invalid hour values" do
- lambda{DateTime.parse("2012-12-31T25:43:59")}.should raise_error(ArgumentError)
+ ->{DateTime.parse("2012-12-31T25:43:59")}.should.raise(ArgumentError)
end
it "throws an argument error for invalid minute values" do
- lambda{DateTime.parse("2012-12-31T25:43:59")}.should raise_error(ArgumentError)
+ ->{DateTime.parse("2012-12-31T25:43:59")}.should.raise(ArgumentError)
end
it "throws an argument error for invalid second values" do
- lambda{DateTime.parse("2012-11-08T15:43:61")}.should raise_error(ArgumentError)
+ ->{DateTime.parse("2012-11-08T15:43:61")}.should.raise(ArgumentError)
end
end
diff --git a/spec/ruby/library/datetime/rfc2822_spec.rb b/spec/ruby/library/datetime/rfc2822_spec.rb
index 3fc4dc14b8..11b79a1e84 100644
--- a/spec/ruby/library/datetime/rfc2822_spec.rb
+++ b/spec/ruby/library/datetime/rfc2822_spec.rb
@@ -1,6 +1,10 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "DateTime.rfc2822" do
it "needs to be reviewed for spec completeness"
+
+ it "raises DateError if passed nil" do
+ -> { DateTime.rfc2822(nil) }.should.raise(Date::Error, "invalid date")
+ end
end
diff --git a/spec/ruby/library/datetime/rfc3339_spec.rb b/spec/ruby/library/datetime/rfc3339_spec.rb
index 4fea795d9e..f870a5f63b 100644
--- a/spec/ruby/library/datetime/rfc3339_spec.rb
+++ b/spec/ruby/library/datetime/rfc3339_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "DateTime.rfc3339" do
diff --git a/spec/ruby/library/datetime/rfc822_spec.rb b/spec/ruby/library/datetime/rfc822_spec.rb
index f86ee77379..0cd0aacc19 100644
--- a/spec/ruby/library/datetime/rfc822_spec.rb
+++ b/spec/ruby/library/datetime/rfc822_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "DateTime.rfc822" do
diff --git a/spec/ruby/library/datetime/sec_fraction_spec.rb b/spec/ruby/library/datetime/sec_fraction_spec.rb
index 3ed274a5bc..40383a8ca4 100644
--- a/spec/ruby/library/datetime/sec_fraction_spec.rb
+++ b/spec/ruby/library/datetime/sec_fraction_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "DateTime#sec_fraction" do
diff --git a/spec/ruby/library/datetime/sec_spec.rb b/spec/ruby/library/datetime/sec_spec.rb
index c7e9af2650..f8a8b4646e 100644
--- a/spec/ruby/library/datetime/sec_spec.rb
+++ b/spec/ruby/library/datetime/sec_spec.rb
@@ -1,6 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/sec', __FILE__)
+require_relative '../../spec_helper'
+require 'date'
-describe "DateTime.sec" do
- it_behaves_like :datetime_sec, :sec
+describe "DateTime#sec" do
+ it "is an alias of DateTime#second" do
+ DateTime.instance_method(:sec).should == DateTime.instance_method(:second)
+ end
end
diff --git a/spec/ruby/library/datetime/second_fraction_spec.rb b/spec/ruby/library/datetime/second_fraction_spec.rb
index 32dc9333f6..70f5abf560 100644
--- a/spec/ruby/library/datetime/second_fraction_spec.rb
+++ b/spec/ruby/library/datetime/second_fraction_spec.rb
@@ -1,6 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "DateTime#second_fraction" do
- it "needs to be reviewed for spec completeness"
+ it "is an alias of DateTime#sec_fraction" do
+ DateTime.instance_method(:second_fraction).should == DateTime.instance_method(:sec_fraction)
+ end
end
diff --git a/spec/ruby/library/datetime/second_spec.rb b/spec/ruby/library/datetime/second_spec.rb
index 08cdf463f7..9fb1965b73 100644
--- a/spec/ruby/library/datetime/second_spec.rb
+++ b/spec/ruby/library/datetime/second_spec.rb
@@ -1,6 +1,45 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/sec', __FILE__)
+require_relative '../../spec_helper'
+require 'date'
describe "DateTime#second" do
- it_behaves_like :datetime_sec, :second
+ it "returns 0 seconds if passed no arguments" do
+ d = DateTime.new
+ d.second.should == 0
+ end
+
+ it "returns the seconds passed in the arguments" do
+ new_datetime(second: 5).second.should == 5
+ end
+
+ it "adds 60 to negative values" do
+ new_datetime(second: -20).second.should == 40
+ end
+
+ it "returns the absolute value of a Rational" do
+ new_datetime(second: 5 + Rational(1,2)).second.should == 5
+ end
+
+ it "returns the absolute value of a float" do
+ new_datetime(second: 5.5).second.should == 5
+ end
+
+ it "raises an error when minute is given as a rational" do
+ -> { new_datetime(minute: 5 + Rational(1,2)) }.should.raise(ArgumentError)
+ end
+
+ it "raises an error, when the second is smaller than -60" do
+ -> { new_datetime(second: -61) }.should.raise(ArgumentError)
+ end
+
+ it "raises an error, when the second is greater or equal than 60" do
+ -> { new_datetime(second: 60) }.should.raise(ArgumentError)
+ end
+
+ it "raises an error for second fractions smaller than -60" do
+ -> { new_datetime(second: -60 - Rational(1,2))}.should.raise(ArgumentError)
+ end
+
+ it "takes a second fraction near 60" do
+ new_datetime(second: 59 + Rational(1,2)).second.should == 59
+ end
end
diff --git a/spec/ruby/library/datetime/shared/min.rb b/spec/ruby/library/datetime/shared/min.rb
deleted file mode 100644
index e69d86ab02..0000000000
--- a/spec/ruby/library/datetime/shared/min.rb
+++ /dev/null
@@ -1,40 +0,0 @@
-require 'date'
-
-describe :datetime_min, shared: true do
- it "returns 0 if no argument is passed" do
- DateTime.new.send(@method).should == 0
- end
-
- it "returns the minute passed as argument" do
- new_datetime(minute: 5).send(@method).should == 5
- end
-
- it "adds 60 to negative minutes" do
- new_datetime(minute: -20).send(@method).should == 40
- end
-
- it "raises an error for Rational" do
- lambda { new_datetime minute: 5 + Rational(1,2) }.should raise_error(ArgumentError)
- end
-
- it "raises an error for Float" do
- lambda { new_datetime minute: 5.5 }.should raise_error(ArgumentError)
- end
-
- it "raises an error for Rational" do
- lambda { new_datetime(hour: 2 + Rational(1,2)) }.should raise_error(ArgumentError)
- end
-
- it "raises an error, when the minute is smaller than -60" do
- lambda { new_datetime(minute: -61) }.should raise_error(ArgumentError)
- end
-
- it "raises an error, when the minute is greater or equal than 60" do
- lambda { new_datetime(minute: 60) }.should raise_error(ArgumentError)
- end
-
- it "raises an error for minute fractions smaller than -60" do
- lambda { new_datetime(minute: -60 - Rational(1,2))}.should(
- raise_error(ArgumentError))
- end
-end
diff --git a/spec/ruby/library/datetime/shared/sec.rb b/spec/ruby/library/datetime/shared/sec.rb
deleted file mode 100644
index 68e8af8e40..0000000000
--- a/spec/ruby/library/datetime/shared/sec.rb
+++ /dev/null
@@ -1,45 +0,0 @@
-require 'date'
-
-describe :datetime_sec, shared: true do
- it "returns 0 seconds if passed no arguments" do
- d = DateTime.new
- d.send(@method).should == 0
- end
-
- it "returns the seconds passed in the arguments" do
- new_datetime(second: 5).send(@method).should == 5
- end
-
- it "adds 60 to negative values" do
- new_datetime(second: -20).send(@method).should == 40
- end
-
- it "returns the absolute value of a Rational" do
- new_datetime(second: 5 + Rational(1,2)).send(@method).should == 5
- end
-
- it "returns the absolute value of a float" do
- new_datetime(second: 5.5).send(@method).should == 5
- end
-
- it "raises an error when minute is given as a rational" do
- lambda { new_datetime(minute: 5 + Rational(1,2)) }.should raise_error(ArgumentError)
- end
-
- it "raises an error, when the second is smaller than -60" do
- lambda { new_datetime(second: -61) }.should raise_error(ArgumentError)
- end
-
- it "raises an error, when the second is greater or equal than 60" do
- lambda { new_datetime(second: 60) }.should raise_error(ArgumentError)
- end
-
- it "raises an error for second fractions smaller than -60" do
- lambda { new_datetime(second: -60 - Rational(1,2))}.should(
- raise_error(ArgumentError))
- end
-
- it "takes a second fraction near 60" do
- new_datetime(second: 59 + Rational(1,2)).send(@method).should == 59
- end
-end
diff --git a/spec/ruby/library/datetime/strftime_spec.rb b/spec/ruby/library/datetime/strftime_spec.rb
index 37705788a1..a07cc9c1aa 100644
--- a/spec/ruby/library/datetime/strftime_spec.rb
+++ b/spec/ruby/library/datetime/strftime_spec.rb
@@ -1,16 +1,18 @@
+require_relative '../../spec_helper'
require 'date'
-require File.expand_path('../../../shared/time/strftime_for_date', __FILE__)
-require File.expand_path('../../../shared/time/strftime_for_time', __FILE__)
+require_relative '../../shared/time/strftime_for_date'
+require_relative '../../shared/time/strftime_for_time'
+date_version = defined?(Date::VERSION) ? Date::VERSION : '3.1.0'
describe "DateTime#strftime" do
before :all do
- @new_date = lambda { |y,m,d| DateTime.civil(y,m,d) }
- @new_time = lambda { |*args| DateTime.civil(*args) }
- @new_time_in_zone = lambda { |zone,offset,*args|
+ @new_date = -> y, m, d { DateTime.civil(y,m,d) }
+ @new_time = -> *args { DateTime.civil(*args) }
+ @new_time_in_zone = -> zone, offset, *args {
y, m, d, h, min, s = args
DateTime.new(y, m||1, d||1, h||0, min||0, s||0, Rational(offset, 24))
}
- @new_time_with_offset = lambda { |y,m,d,h,min,s,offset|
+ @new_time_with_offset = -> y, m, d, h, min, s, offset {
DateTime.new(y,m,d,h,min,s, Rational(offset, 86_400))
}
@@ -31,10 +33,9 @@ describe "DateTime#strftime" do
@time.strftime("%Z").should == "+00:00"
end
- # %v is %e-%b-%Y for Date/DateTime
it "should be able to show the commercial week" do
- @time.strftime("%v").should == " 3-Feb-2001"
- @time.strftime("%v").should == @time.strftime('%e-%b-%Y')
+ @time.strftime("%v").should == " 3-FEB-2001"
+ @time.strftime("%v").should != @time.strftime('%e-%b-%Y')
end
# additional conversion specifiers only in Date/DateTime
diff --git a/spec/ruby/library/datetime/strptime_spec.rb b/spec/ruby/library/datetime/strptime_spec.rb
index f3098f6f6b..d1e83550e4 100644
--- a/spec/ruby/library/datetime/strptime_spec.rb
+++ b/spec/ruby/library/datetime/strptime_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "DateTime.strptime" do
diff --git a/spec/ruby/library/datetime/subtract_spec.rb b/spec/ruby/library/datetime/subtract_spec.rb
new file mode 100644
index 0000000000..ba01f4eff6
--- /dev/null
+++ b/spec/ruby/library/datetime/subtract_spec.rb
@@ -0,0 +1,19 @@
+require_relative '../../spec_helper'
+require 'date'
+
+describe "DateTime#-" do
+ it "is able to subtract sub-millisecond precision values" do
+ date = DateTime.new(2017)
+ diff = Rational(123456789, 24*60*60*1000*1000)
+ ((date + diff) - date).should == diff
+ (date - (date + diff)).should == -diff
+ (date - (date - diff)).should == diff
+ ((date - diff) - date).should == -diff
+ end
+
+ it "correctly calculates sub-millisecond time differences" do #5493
+ dt1 = DateTime.new(2018, 1, 1, 0, 0, 30)
+ dt2 = DateTime.new(2018, 1, 1, 0, 1, 29.000001)
+ ((dt2 - dt1) * 24 * 60 * 60).should == 59.000001
+ end
+end
diff --git a/spec/ruby/library/datetime/time/to_datetime_spec.rb b/spec/ruby/library/datetime/time/to_datetime_spec.rb
new file mode 100644
index 0000000000..5589725238
--- /dev/null
+++ b/spec/ruby/library/datetime/time/to_datetime_spec.rb
@@ -0,0 +1,40 @@
+require_relative '../../../spec_helper'
+require 'time'
+require 'date'
+date_version = defined?(Date::VERSION) ? Date::VERSION : '3.1.0'
+
+describe "Time#to_datetime" do
+ it "returns a DateTime representing the same instant" do
+ time = Time.utc(2012, 12, 31, 23, 58, 59)
+ datetime = time.to_datetime
+ datetime.year.should == 2012
+ datetime.month.should == 12
+ datetime.day.should == 31
+ datetime.hour.should == 23
+ datetime.min.should == 58
+ datetime.sec.should == 59
+ end
+
+ it "returns a DateTime representing the same instant before Gregorian" do
+ time = Time.utc(1582, 10, 14, 23, 58, 59)
+ datetime = time.to_datetime
+ datetime.year.should == 1582
+ datetime.month.should == 10
+ datetime.day.should == 4
+ datetime.hour.should == 23
+ datetime.min.should == 58
+ datetime.sec.should == 59
+ end
+
+ it "roundtrips" do
+ time = Time.utc(3, 12, 31, 23, 58, 59)
+ datetime = time.to_datetime
+ datetime.to_time.utc.should == time
+ end
+
+ it "yields a DateTime with the default Calendar reform day" do
+ Time.utc(1582, 10, 4, 1, 2, 3).to_datetime.start.should == Date::ITALY
+ Time.utc(1582, 10, 14, 1, 2, 3).to_datetime.start.should == Date::ITALY
+ Time.utc(1582, 10, 15, 1, 2, 3).to_datetime.start.should == Date::ITALY
+ end
+end
diff --git a/spec/ruby/library/datetime/to_date_spec.rb b/spec/ruby/library/datetime/to_date_spec.rb
index 387eda9229..31ccf5ae98 100644
--- a/spec/ruby/library/datetime/to_date_spec.rb
+++ b/spec/ruby/library/datetime/to_date_spec.rb
@@ -1,10 +1,10 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "DateTime#to_date" do
it "returns an instance of Date" do
dt = DateTime.new(2012, 12, 24, 12, 23, 00, '+05:00')
- dt.to_date.should be_kind_of(Date)
+ dt.to_date.should.is_a?(Date)
end
it "maintains the same year" do
@@ -30,7 +30,7 @@ describe "DateTime#to_date" do
it "maintains the same julian day regardless of local time or zone" do
dt = DateTime.new(2012, 12, 24, 12, 23, 00, '+05:00')
- with_timezone("Pactific/Pago_Pago", -11) do
+ with_timezone("Pacific/Pago_Pago", -11) do
dt.to_date.jd.should == dt.jd
end
end
diff --git a/spec/ruby/library/datetime/to_datetime_spec.rb b/spec/ruby/library/datetime/to_datetime_spec.rb
index e4db9558f1..95ee29268f 100644
--- a/spec/ruby/library/datetime/to_datetime_spec.rb
+++ b/spec/ruby/library/datetime/to_datetime_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "DateTime#to_datetime" do
diff --git a/spec/ruby/library/datetime/to_s_spec.rb b/spec/ruby/library/datetime/to_s_spec.rb
index 9d9dfc629f..ed0746f42b 100644
--- a/spec/ruby/library/datetime/to_s_spec.rb
+++ b/spec/ruby/library/datetime/to_s_spec.rb
@@ -1,16 +1,16 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "DateTime#to_s" do
it "returns a new String object" do
dt = DateTime.new(2012, 12, 24, 1, 2, 3, "+03:00")
- dt.to_s.should be_kind_of(String)
+ dt.to_s.should.is_a?(String)
end
it "maintains timezone regardless of local time" do
dt = DateTime.new(2012, 12, 24, 1, 2, 3, "+03:00")
- with_timezone("Pactific/Pago_Pago", -11) do
+ with_timezone("Pacific/Pago_Pago", -11) do
dt.to_s.should == "2012-12-24T01:02:03+03:00"
end
end
diff --git a/spec/ruby/library/datetime/to_time_spec.rb b/spec/ruby/library/datetime/to_time_spec.rb
index f5b7cb8a23..a3ffc019fb 100644
--- a/spec/ruby/library/datetime/to_time_spec.rb
+++ b/spec/ruby/library/datetime/to_time_spec.rb
@@ -1,26 +1,48 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
+date_version = defined?(Date::VERSION) ? Date::VERSION : '3.1.0'
describe "DateTime#to_time" do
it "yields a new Time object" do
- DateTime.now.to_time.should be_kind_of(Time)
+ DateTime.now.to_time.should.is_a?(Time)
end
- ruby_version_is "2.4" do
- it "preserves the same time regardless of local time or zone" do
- date = DateTime.new(2012, 12, 24, 12, 23, 00, '+03:00')
+ it "returns a Time representing the same instant" do
+ datetime = DateTime.civil(2012, 12, 31, 23, 58, 59)
+ time = datetime.to_time.utc
- with_timezone("Pactific/Pago_Pago", -11) do
- time = date.to_time
+ time.year.should == 2012
+ time.month.should == 12
+ time.day.should == 31
+ time.hour.should == 23
+ time.min.should == 58
+ time.sec.should == 59
+ end
+
+ it "returns a Time representing the same instant before Gregorian" do
+ datetime = DateTime.civil(1582, 10, 4, 23, 58, 59)
+ time = datetime.to_time.utc
+ time.year.should == 1582
+ time.month.should == 10
+ time.day.should == 14
+ time.hour.should == 23
+ time.min.should == 58
+ time.sec.should == 59
+ end
+
+ it "preserves the same time regardless of local time or zone" do
+ date = DateTime.new(2012, 12, 24, 12, 23, 00, '+03:00')
+
+ with_timezone("Pacific/Pago_Pago", -11) do
+ time = date.to_time
- time.utc_offset.should == 3 * 3600
- time.year.should == date.year
- time.mon.should == date.mon
- time.day.should == date.day
- time.hour.should == date.hour
- time.min.should == date.min
- time.sec.should == date.sec
- end
+ time.utc_offset.should == 3 * 3600
+ time.year.should == date.year
+ time.mon.should == date.mon
+ time.day.should == date.day
+ time.hour.should == date.hour
+ time.min.should == date.min
+ time.sec.should == date.sec
end
end
end
diff --git a/spec/ruby/library/datetime/xmlschema_spec.rb b/spec/ruby/library/datetime/xmlschema_spec.rb
index 5f33d33436..42832631ed 100644
--- a/spec/ruby/library/datetime/xmlschema_spec.rb
+++ b/spec/ruby/library/datetime/xmlschema_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "DateTime.xmlschema" do
diff --git a/spec/ruby/library/datetime/yday_spec.rb b/spec/ruby/library/datetime/yday_spec.rb
new file mode 100644
index 0000000000..08a72c6480
--- /dev/null
+++ b/spec/ruby/library/datetime/yday_spec.rb
@@ -0,0 +1,7 @@
+require_relative '../../spec_helper'
+require_relative '../../shared/time/yday'
+require 'date'
+
+describe "DateTime#yday" do
+ it_behaves_like :time_yday, -> year, month, day { DateTime.new(year, month, day).yday }
+end
diff --git a/spec/ruby/library/datetime/zone_spec.rb b/spec/ruby/library/datetime/zone_spec.rb
index fa8c9a982d..b2c10b4b3b 100644
--- a/spec/ruby/library/datetime/zone_spec.rb
+++ b/spec/ruby/library/datetime/zone_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'date'
describe "DateTime#zone" do
diff --git a/spec/ruby/library/delegate/delegate_class/instance_method_spec.rb b/spec/ruby/library/delegate/delegate_class/instance_method_spec.rb
index 61680b9d5a..19ffc4cf85 100644
--- a/spec/ruby/library/delegate/delegate_class/instance_method_spec.rb
+++ b/spec/ruby/library/delegate/delegate_class/instance_method_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
describe "DelegateClass.instance_method" do
before :all do
@@ -9,44 +9,44 @@ describe "DelegateClass.instance_method" do
it "returns a method object for public instance methods of the delegated class" do
m = @klass.instance_method(:pub)
- m.should be_an_instance_of(UnboundMethod)
+ m.should.instance_of?(UnboundMethod)
m.bind(@obj).call.should == :foo
end
it "returns a method object for protected instance methods of the delegated class" do
m = @klass.instance_method(:prot)
- m.should be_an_instance_of(UnboundMethod)
+ m.should.instance_of?(UnboundMethod)
m.bind(@obj).call.should == :protected
end
it "raises a NameError for a private instance methods of the delegated class" do
- lambda {
+ -> {
@klass.instance_method(:priv)
- }.should raise_error(NameError)
+ }.should.raise(NameError)
end
it "returns a method object for public instance methods of the DelegateClass class" do
m = @klass.instance_method(:extra)
- m.should be_an_instance_of(UnboundMethod)
+ m.should.instance_of?(UnboundMethod)
m.bind(@obj).call.should == :cheese
end
it "returns a method object for protected instance methods of the DelegateClass class" do
m = @klass.instance_method(:extra_protected)
- m.should be_an_instance_of(UnboundMethod)
+ m.should.instance_of?(UnboundMethod)
m.bind(@obj).call.should == :baz
end
it "returns a method object for private instance methods of the DelegateClass class" do
m = @klass.instance_method(:extra_private)
- m.should be_an_instance_of(UnboundMethod)
+ m.should.instance_of?(UnboundMethod)
m.bind(@obj).call.should == :bar
end
it "raises a NameError for an invalid method name" do
- lambda {
+ -> {
@klass.instance_method(:invalid_and_silly_method_name)
- }.should raise_error(NameError)
+ }.should.raise(NameError)
end
end
diff --git a/spec/ruby/library/delegate/delegate_class/instance_methods_spec.rb b/spec/ruby/library/delegate/delegate_class/instance_methods_spec.rb
index ae329ab8eb..586be56cae 100644
--- a/spec/ruby/library/delegate/delegate_class/instance_methods_spec.rb
+++ b/spec/ruby/library/delegate/delegate_class/instance_methods_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
describe "DelegateClass.instance_methods" do
before :all do
@@ -7,20 +7,20 @@ describe "DelegateClass.instance_methods" do
end
it "includes all public methods of the delegated class" do
- @methods.should include :pub
+ @methods.should.include? :pub
end
it "includes all protected methods of the delegated class" do
- @methods.should include :prot
+ @methods.should.include? :prot
end
it "includes instance methods of the DelegateClass class" do
- @methods.should include :extra
- @methods.should include :extra_protected
+ @methods.should.include? :extra
+ @methods.should.include? :extra_protected
end
it "does not include private methods" do
- @methods.should_not include :priv
- @methods.should_not include :extra_private
+ @methods.should_not.include? :priv
+ @methods.should_not.include? :extra_private
end
end
diff --git a/spec/ruby/library/delegate/delegate_class/private_instance_methods_spec.rb b/spec/ruby/library/delegate/delegate_class/private_instance_methods_spec.rb
index d93b6d0e3d..18ca2a4c88 100644
--- a/spec/ruby/library/delegate/delegate_class/private_instance_methods_spec.rb
+++ b/spec/ruby/library/delegate/delegate_class/private_instance_methods_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
describe "DelegateClass.private_instance_methods" do
before :all do
@@ -7,17 +7,17 @@ describe "DelegateClass.private_instance_methods" do
end
it "does not include any instance methods of the delegated class" do
- @methods.should_not include :pub
- @methods.should_not include :prot
- @methods.should_not include :priv # since these are not forwarded...
+ @methods.should_not.include? :pub
+ @methods.should_not.include? :prot
+ @methods.should_not.include? :priv # since these are not forwarded...
end
it "includes private instance methods of the DelegateClass class" do
- @methods.should include :extra_private
+ @methods.should.include? :extra_private
end
it "does not include public or protected instance methods of the DelegateClass class" do
- @methods.should_not include :extra
- @methods.should_not include :extra_protected
+ @methods.should_not.include? :extra
+ @methods.should_not.include? :extra_protected
end
end
diff --git a/spec/ruby/library/delegate/delegate_class/protected_instance_methods_spec.rb b/spec/ruby/library/delegate/delegate_class/protected_instance_methods_spec.rb
index 3ae0270dbd..d540b45065 100644
--- a/spec/ruby/library/delegate/delegate_class/protected_instance_methods_spec.rb
+++ b/spec/ruby/library/delegate/delegate_class/protected_instance_methods_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
describe "DelegateClass.protected_instance_methods" do
before :all do
@@ -7,23 +7,23 @@ describe "DelegateClass.protected_instance_methods" do
end
it "does not include public methods of the delegated class" do
- @methods.should_not include :pub
+ @methods.should_not.include? :pub
end
it "includes the protected methods of the delegated class" do
- @methods.should include :prot
+ @methods.should.include? :prot
end
it "includes protected instance methods of the DelegateClass class" do
- @methods.should include :extra_protected
+ @methods.should.include? :extra_protected
end
it "does not include public instance methods of the DelegateClass class" do
- @methods.should_not include :extra
+ @methods.should_not.include? :extra
end
it "does not include private methods" do
- @methods.should_not include :priv
- @methods.should_not include :extra_private
+ @methods.should_not.include? :priv
+ @methods.should_not.include? :extra_private
end
end
diff --git a/spec/ruby/library/delegate/delegate_class/public_instance_methods_spec.rb b/spec/ruby/library/delegate/delegate_class/public_instance_methods_spec.rb
index e06b55612e..124b92de82 100644
--- a/spec/ruby/library/delegate/delegate_class/public_instance_methods_spec.rb
+++ b/spec/ruby/library/delegate/delegate_class/public_instance_methods_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
describe "DelegateClass.public_instance_methods" do
before :all do
@@ -7,19 +7,19 @@ describe "DelegateClass.public_instance_methods" do
end
it "includes all public methods of the delegated class" do
- @methods.should include :pub
+ @methods.should.include? :pub
end
it "does not include the protected methods of the delegated class" do
- @methods.should_not include :prot
+ @methods.should_not.include? :prot
end
it "includes public instance methods of the DelegateClass class" do
- @methods.should include :extra
+ @methods.should.include? :extra
end
it "does not include private methods" do
- @methods.should_not include :priv
- @methods.should_not include :extra_private
+ @methods.should_not.include? :priv
+ @methods.should_not.include? :extra_private
end
end
diff --git a/spec/ruby/library/delegate/delegate_class/respond_to_missing_spec.rb b/spec/ruby/library/delegate/delegate_class/respond_to_missing_spec.rb
index 729cfc96c6..3975e5208b 100644
--- a/spec/ruby/library/delegate/delegate_class/respond_to_missing_spec.rb
+++ b/spec/ruby/library/delegate/delegate_class/respond_to_missing_spec.rb
@@ -1,3 +1,4 @@
+require_relative "../../../spec_helper"
require 'delegate'
describe "DelegateClass#respond_to_missing?" do
diff --git a/spec/ruby/library/delegate/delegator/case_compare_spec.rb b/spec/ruby/library/delegate/delegator/case_compare_spec.rb
index 8bf79c1425..b62397cecf 100644
--- a/spec/ruby/library/delegate/delegator/case_compare_spec.rb
+++ b/spec/ruby/library/delegate/delegator/case_compare_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
describe "Delegator#===" do
it "is delegated" do
diff --git a/spec/ruby/library/delegate/delegator/compare_spec.rb b/spec/ruby/library/delegate/delegator/compare_spec.rb
index 93431bfeb2..7dee5c2fb5 100644
--- a/spec/ruby/library/delegate/delegator/compare_spec.rb
+++ b/spec/ruby/library/delegate/delegator/compare_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
describe "Delegator#<=>" do
it "is delegated" do
diff --git a/spec/ruby/library/delegate/delegator/complement_spec.rb b/spec/ruby/library/delegate/delegator/complement_spec.rb
index 877a6e99c6..10cb37c7ea 100644
--- a/spec/ruby/library/delegate/delegator/complement_spec.rb
+++ b/spec/ruby/library/delegate/delegator/complement_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
describe "Delegator#~" do
it "is delegated" do
diff --git a/spec/ruby/library/delegate/delegator/eql_spec.rb b/spec/ruby/library/delegate/delegator/eql_spec.rb
index fd6824ec55..b302bb7016 100644
--- a/spec/ruby/library/delegate/delegator/eql_spec.rb
+++ b/spec/ruby/library/delegate/delegator/eql_spec.rb
@@ -1,46 +1,35 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
describe "Delegator#eql?" do
- ruby_version_is ""..."2.5" do
- it "is delegated" do
- base = mock('base')
- delegator = DelegateSpecs::Delegator.new(base)
- base.should_receive(:eql?).with(42).and_return(:foo)
- delegator.eql?(42).should == :foo
- end
- end
-
- ruby_version_is "2.5" do
- it "returns true when compared with same delegator" do
- base = mock('base')
- delegator = DelegateSpecs::Delegator.new(base)
+ it "returns true when compared with same delegator" do
+ base = mock('base')
+ delegator = DelegateSpecs::Delegator.new(base)
- delegator.eql?(delegator).should be_true
- end
+ delegator.eql?(delegator).should == true
+ end
- it "returns true when compared with the inner object" do
- base = mock('base')
- delegator = DelegateSpecs::Delegator.new(base)
+ it "returns true when compared with the inner object" do
+ base = mock('base')
+ delegator = DelegateSpecs::Delegator.new(base)
- delegator.eql?(base).should be_true
- end
+ delegator.eql?(base).should == true
+ end
- it "returns false when compared with the delegator with other object" do
- base = mock('base')
- other = mock('other')
- delegator0 = DelegateSpecs::Delegator.new(base)
- delegator1 = DelegateSpecs::Delegator.new(other)
+ it "returns false when compared with the delegator with other object" do
+ base = mock('base')
+ other = mock('other')
+ delegator0 = DelegateSpecs::Delegator.new(base)
+ delegator1 = DelegateSpecs::Delegator.new(other)
- delegator0.eql?(delegator1).should be_false
- end
+ delegator0.eql?(delegator1).should == false
+ end
- it "returns false when compared with the other object" do
- base = mock('base')
- other = mock('other')
- delegator = DelegateSpecs::Delegator.new(base)
+ it "returns false when compared with the other object" do
+ base = mock('base')
+ other = mock('other')
+ delegator = DelegateSpecs::Delegator.new(base)
- delegator.eql?(other).should be_false
- end
+ delegator.eql?(other).should == false
end
end
diff --git a/spec/ruby/library/delegate/delegator/equal_spec.rb b/spec/ruby/library/delegate/delegator/equal_spec.rb
index 9333d6a303..97aabebabe 100644
--- a/spec/ruby/library/delegate/delegator/equal_spec.rb
+++ b/spec/ruby/library/delegate/delegator/equal_spec.rb
@@ -1,13 +1,13 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
describe "Delegator#equal?" do
it "returns true only when compared with the delegator" do
obj = mock('base')
delegator = DelegateSpecs::Delegator.new(obj)
obj.should_not_receive(:equal?)
- delegator.equal?(obj).should be_false
- delegator.equal?(nil).should be_false
- delegator.equal?(delegator).should be_true
+ delegator.equal?(obj).should == false
+ delegator.equal?(nil).should == false
+ delegator.equal?(delegator).should == true
end
end
diff --git a/spec/ruby/library/delegate/delegator/equal_value_spec.rb b/spec/ruby/library/delegate/delegator/equal_value_spec.rb
index 7c965d77d3..d70aad1e03 100644
--- a/spec/ruby/library/delegate/delegator/equal_value_spec.rb
+++ b/spec/ruby/library/delegate/delegator/equal_value_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
describe "Delegator#==" do
before :all do
@@ -9,16 +9,16 @@ describe "Delegator#==" do
it "is not delegated when passed self" do
@base.should_not_receive(:==)
- (@delegator == @delegator).should be_true
+ (@delegator == @delegator).should == true
end
it "is delegated when passed the delegated object" do
@base.should_receive(:==).and_return(false)
- (@delegator == @base).should be_false
+ (@delegator == @base).should == false
end
it "is delegated in general" do
@base.should_receive(:==).and_return(true)
- (@delegator == 42).should be_true
+ (@delegator == 42).should == true
end
end
diff --git a/spec/ruby/library/delegate/delegator/frozen_spec.rb b/spec/ruby/library/delegate/delegator/frozen_spec.rb
index 1fb561a349..ad87dc8bdf 100644
--- a/spec/ruby/library/delegate/delegator/frozen_spec.rb
+++ b/spec/ruby/library/delegate/delegator/frozen_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
describe "Delegator when frozen" do
before :all do
@@ -10,30 +10,30 @@ describe "Delegator when frozen" do
it "is still readable" do
@delegate.should == [42, :hello]
- @delegate.include?("bar").should be_false
+ @delegate.include?("bar").should == false
end
it "is frozen" do
- @delegate.frozen?.should be_true
+ @delegate.frozen?.should == true
end
- it "is not writeable" do
- lambda{ @delegate[0] += 2 }.should raise_error( RuntimeError )
+ it "is not writable" do
+ ->{ @delegate[0] += 2 }.should.raise( RuntimeError )
end
it "creates a frozen clone" do
- @delegate.clone.frozen?.should be_true
+ @delegate.clone.frozen?.should == true
end
it "creates an unfrozen dup" do
- @delegate.dup.frozen?.should be_false
+ @delegate.dup.frozen?.should == false
end
it "causes mutative calls to raise RuntimeError" do
- lambda{ @delegate.__setobj__("hola!") }.should raise_error( RuntimeError )
+ ->{ @delegate.__setobj__("hola!") }.should.raise( RuntimeError )
end
it "returns false if only the delegated object is frozen" do
- DelegateSpecs::Delegator.new([1,2,3].freeze).frozen?.should be_false
+ DelegateSpecs::Delegator.new([1,2,3].freeze).frozen?.should == false
end
end
diff --git a/spec/ruby/library/delegate/delegator/hash_spec.rb b/spec/ruby/library/delegate/delegator/hash_spec.rb
index 3719d1b249..132cb91ccc 100644
--- a/spec/ruby/library/delegate/delegator/hash_spec.rb
+++ b/spec/ruby/library/delegate/delegator/hash_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
describe "Delegator#hash" do
it "is delegated" do
diff --git a/spec/ruby/library/delegate/delegator/marshal_spec.rb b/spec/ruby/library/delegate/delegator/marshal_spec.rb
index 5af32b5754..2817ac7e0b 100644
--- a/spec/ruby/library/delegate/delegator/marshal_spec.rb
+++ b/spec/ruby/library/delegate/delegator/marshal_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'delegate'
describe "SimpleDelegator" do
@@ -10,7 +10,7 @@ describe "SimpleDelegator" do
it "can be marshalled" do
m = Marshal.load(Marshal.dump(@delegate))
m.class.should == SimpleDelegator
- (m == @obj).should be_true
+ (m == @obj).should == true
end
it "can be marshalled with its instance variables intact" do
diff --git a/spec/ruby/library/delegate/delegator/method_spec.rb b/spec/ruby/library/delegate/delegator/method_spec.rb
index 1760eda645..e41d3b4a53 100644
--- a/spec/ruby/library/delegate/delegator/method_spec.rb
+++ b/spec/ruby/library/delegate/delegator/method_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
describe "Delegator#method" do
before :each do
@@ -9,61 +9,61 @@ describe "Delegator#method" do
it "returns a method object for public methods of the delegate object" do
m = @delegate.method(:pub)
- m.should be_an_instance_of(Method)
+ m.should.instance_of?(Method)
m.call.should == :foo
end
it "raises a NameError for protected methods of the delegate object" do
- lambda {
+ -> {
-> {
@delegate.method(:prot)
}.should complain(/delegator does not forward private method #prot/)
- }.should raise_error(NameError)
+ }.should.raise(NameError)
end
it "raises a NameError for a private methods of the delegate object" do
- lambda {
+ -> {
-> {
@delegate.method(:priv)
}.should complain(/delegator does not forward private method #priv/)
- }.should raise_error(NameError)
+ }.should.raise(NameError)
end
it "returns a method object for public methods of the Delegator class" do
m = @delegate.method(:extra)
- m.should be_an_instance_of(Method)
+ m.should.instance_of?(Method)
m.call.should == :cheese
end
it "returns a method object for protected methods of the Delegator class" do
m = @delegate.method(:extra_protected)
- m.should be_an_instance_of(Method)
+ m.should.instance_of?(Method)
m.call.should == :baz
end
it "returns a method object for private methods of the Delegator class" do
m = @delegate.method(:extra_private)
- m.should be_an_instance_of(Method)
+ m.should.instance_of?(Method)
m.call.should == :bar
end
it "raises a NameError for an invalid method name" do
- lambda {
+ -> {
@delegate.method(:invalid_and_silly_method_name)
- }.should raise_error(NameError)
+ }.should.raise(NameError)
end
it "returns a method that respond_to_missing?" do
m = @delegate.method(:pub_too)
- m.should be_an_instance_of(Method)
+ m.should.instance_of?(Method)
m.call.should == :pub_too
end
it "raises a NameError if method is no longer valid because object has changed" do
m = @delegate.method(:pub)
@delegate.__setobj__([1,2,3])
- lambda {
+ -> {
m.call
- }.should raise_error(NameError)
+ }.should.raise(NameError)
end
end
diff --git a/spec/ruby/library/delegate/delegator/methods_spec.rb b/spec/ruby/library/delegate/delegator/methods_spec.rb
index 91a6d68bfa..928f63f21d 100644
--- a/spec/ruby/library/delegate/delegator/methods_spec.rb
+++ b/spec/ruby/library/delegate/delegator/methods_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
describe "Delegator#methods" do
before :all do
@@ -14,24 +14,24 @@ describe "Delegator#methods" do
end
it "returns singleton methods when passed false" do
- @delegate.methods(false).should include(:singleton_method)
+ @delegate.methods(false).should.include?(:singleton_method)
end
it "includes all public methods of the delegate object" do
- @methods.should include :pub
+ @methods.should.include? :pub
end
it "includes all protected methods of the delegate object" do
- @methods.should include :prot
+ @methods.should.include? :prot
end
it "includes instance methods of the Delegator class" do
- @methods.should include :extra
- @methods.should include :extra_protected
+ @methods.should.include? :extra
+ @methods.should.include? :extra_protected
end
it "does not include private methods" do
- @methods.should_not include :priv
- @methods.should_not include :extra_private
+ @methods.should_not.include? :priv
+ @methods.should_not.include? :extra_private
end
end
diff --git a/spec/ruby/library/delegate/delegator/not_equal_spec.rb b/spec/ruby/library/delegate/delegator/not_equal_spec.rb
index c2f91dcfa1..7fd234a671 100644
--- a/spec/ruby/library/delegate/delegator/not_equal_spec.rb
+++ b/spec/ruby/library/delegate/delegator/not_equal_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
describe "Delegator#!=" do
before :all do
@@ -9,16 +9,16 @@ describe "Delegator#!=" do
it "is not delegated when passed self" do
@base.should_not_receive(:"!=")
- (@delegator != @delegator).should be_false
+ (@delegator != @delegator).should == false
end
it "is delegated when passed the delegated object" do
@base.should_receive(:"!=").and_return(true)
- (@delegator != @base).should be_true
+ (@delegator != @base).should == true
end
it "is delegated in general" do
@base.should_receive(:"!=").and_return(false)
- (@delegator != 42).should be_false
+ (@delegator != 42).should == false
end
end
diff --git a/spec/ruby/library/delegate/delegator/not_spec.rb b/spec/ruby/library/delegate/delegator/not_spec.rb
index 678e07e418..50105181c3 100644
--- a/spec/ruby/library/delegate/delegator/not_spec.rb
+++ b/spec/ruby/library/delegate/delegator/not_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
describe "Delegator#!" do
it "is delegated" do
diff --git a/spec/ruby/library/delegate/delegator/private_methods_spec.rb b/spec/ruby/library/delegate/delegator/private_methods_spec.rb
index 557da9bd02..5615ed0668 100644
--- a/spec/ruby/library/delegate/delegator/private_methods_spec.rb
+++ b/spec/ruby/library/delegate/delegator/private_methods_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
describe "Delegator#private_methods" do
before :all do
@@ -9,12 +9,12 @@ describe "Delegator#private_methods" do
end
it "does not include any method of the delegate object" do # since delegates does not forward private calls
- @methods.should_not include :priv
- @methods.should_not include :prot
- @methods.should_not include :pub
+ @methods.should_not.include? :priv
+ @methods.should_not.include? :prot
+ @methods.should_not.include? :pub
end
it "includes all private instance methods of the Delegate class" do
- @methods.should include :extra_private
+ @methods.should.include? :extra_private
end
end
diff --git a/spec/ruby/library/delegate/delegator/protected_methods_spec.rb b/spec/ruby/library/delegate/delegator/protected_methods_spec.rb
index 5f03575f25..3ee999fdac 100644
--- a/spec/ruby/library/delegate/delegator/protected_methods_spec.rb
+++ b/spec/ruby/library/delegate/delegator/protected_methods_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
describe "Delegator#protected_methods" do
before :all do
@@ -9,10 +9,10 @@ describe "Delegator#protected_methods" do
end
it "includes protected methods of the delegate object" do
- @methods.should include :prot
+ @methods.should.include? :prot
end
it "includes protected instance methods of the Delegator class" do
- @methods.should include :extra_protected
+ @methods.should.include? :extra_protected
end
end
diff --git a/spec/ruby/library/delegate/delegator/public_methods_spec.rb b/spec/ruby/library/delegate/delegator/public_methods_spec.rb
index 4ed626be33..8cf6621e2d 100644
--- a/spec/ruby/library/delegate/delegator/public_methods_spec.rb
+++ b/spec/ruby/library/delegate/delegator/public_methods_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
describe "Delegator#public_methods" do
before :all do
@@ -9,10 +9,10 @@ describe "Delegator#public_methods" do
end
it "includes public methods of the delegate object" do
- @methods.should include :pub
+ @methods.should.include? :pub
end
it "includes public instance methods of the Delegator class" do
- @methods.should include :extra
+ @methods.should.include? :extra
end
end
diff --git a/spec/ruby/library/delegate/delegator/send_spec.rb b/spec/ruby/library/delegate/delegator/send_spec.rb
index b6e66cb74a..cc18a2794b 100644
--- a/spec/ruby/library/delegate/delegator/send_spec.rb
+++ b/spec/ruby/library/delegate/delegator/send_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
describe "SimpleDelegator.new" do
before :all do
@@ -12,15 +12,15 @@ describe "SimpleDelegator.new" do
end
it "forwards protected method calls" do
- lambda{ @delegate.prot }.should raise_error( NoMethodError )
+ ->{ @delegate.prot }.should.raise( NoMethodError )
end
it "doesn't forward private method calls" do
- lambda{ @delegate.priv }.should raise_error( NoMethodError )
+ ->{ @delegate.priv }.should.raise( NoMethodError )
end
it "doesn't forward private method calls even via send or __send__" do
- lambda{ @delegate.send(:priv, 42) }.should raise_error( NoMethodError )
- lambda{ @delegate.__send__(:priv, 42) }.should raise_error( NoMethodError )
+ ->{ @delegate.send(:priv, 42) }.should.raise( NoMethodError )
+ ->{ @delegate.__send__(:priv, 42) }.should.raise( NoMethodError )
end
end
diff --git a/spec/ruby/library/delegate/delegator/taint_spec.rb b/spec/ruby/library/delegate/delegator/taint_spec.rb
index f78446d018..6bf13bb73d 100644
--- a/spec/ruby/library/delegate/delegator/taint_spec.rb
+++ b/spec/ruby/library/delegate/delegator/taint_spec.rb
@@ -1,23 +1,8 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
describe "Delegator#taint" do
before :each do
@delegate = DelegateSpecs::Delegator.new("")
end
-
- it "returns self" do
- @delegate.taint.equal?(@delegate).should be_true
- end
-
- it "taints the delegator" do
- @delegate.__setobj__(nil)
- @delegate.taint
- @delegate.tainted?.should be_true
- end
-
- it "taints the delegated object" do
- @delegate.taint
- @delegate.__getobj__.tainted?.should be_true
- end
end
diff --git a/spec/ruby/library/delegate/delegator/tap_spec.rb b/spec/ruby/library/delegate/delegator/tap_spec.rb
index 1da6d82b01..916e4a37fe 100644
--- a/spec/ruby/library/delegate/delegator/tap_spec.rb
+++ b/spec/ruby/library/delegate/delegator/tap_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
describe "Delegator#tap" do
it "yield the delegator object" do
@@ -11,6 +11,6 @@ describe "Delegator#tap" do
yielded << x
end
yielded.size.should == 1
- yielded[0].equal?(delegator).should be_true
+ yielded[0].equal?(delegator).should == true
end
end
diff --git a/spec/ruby/library/delegate/delegator/trust_spec.rb b/spec/ruby/library/delegate/delegator/trust_spec.rb
index 182395c26e..f1b81814c5 100644
--- a/spec/ruby/library/delegate/delegator/trust_spec.rb
+++ b/spec/ruby/library/delegate/delegator/trust_spec.rb
@@ -1,22 +1,8 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
describe "Delegator#trust" do
before :each do
@delegate = DelegateSpecs::Delegator.new([])
end
-
- it "returns self" do
- @delegate.trust.equal?(@delegate).should be_true
- end
-
- it "trusts the delegator" do
- @delegate.trust
- @delegate.untrusted?.should be_false
- end
-
- it "trusts the delegated object" do
- @delegate.trust
- @delegate.__getobj__.untrusted?.should be_false
- end
end
diff --git a/spec/ruby/library/delegate/delegator/untaint_spec.rb b/spec/ruby/library/delegate/delegator/untaint_spec.rb
index 2cce99e206..4051fd2629 100644
--- a/spec/ruby/library/delegate/delegator/untaint_spec.rb
+++ b/spec/ruby/library/delegate/delegator/untaint_spec.rb
@@ -1,24 +1,8 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
describe "Delegator#untaint" do
before :each do
- @delegate = lambda { DelegateSpecs::Delegator.new("") }.call
- end
-
- it "returns self" do
- @delegate.untaint.equal?(@delegate).should be_true
- end
-
- it "untaints the delegator" do
- @delegate.untaint
- @delegate.tainted?.should be_false
- # No additional meaningful test; that it does or not taint
- # "for real" the delegator has no consequence
- end
-
- it "untaints the delegated object" do
- @delegate.untaint
- @delegate.__getobj__.tainted?.should be_false
+ @delegate = -> { DelegateSpecs::Delegator.new("") }.call
end
end
diff --git a/spec/ruby/library/delegate/delegator/untrust_spec.rb b/spec/ruby/library/delegate/delegator/untrust_spec.rb
index e2bbf1b294..4f7fa1e582 100644
--- a/spec/ruby/library/delegate/delegator/untrust_spec.rb
+++ b/spec/ruby/library/delegate/delegator/untrust_spec.rb
@@ -1,23 +1,8 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/classes', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
describe "Delegator#untrust" do
before :each do
@delegate = DelegateSpecs::Delegator.new("")
end
-
- it "returns self" do
- @delegate.untrust.equal?(@delegate).should be_true
- end
-
- it "untrusts the delegator" do
- @delegate.__setobj__(nil)
- @delegate.untrust
- @delegate.untrusted?.should be_true
- end
-
- it "untrusts the delegated object" do
- @delegate.untrust
- @delegate.__getobj__.untrusted?.should be_true
- end
end
diff --git a/spec/ruby/library/digest/bubblebabble_spec.rb b/spec/ruby/library/digest/bubblebabble_spec.rb
index 49cc77e623..44a9bf0e26 100644
--- a/spec/ruby/library/digest/bubblebabble_spec.rb
+++ b/spec/ruby/library/digest/bubblebabble_spec.rb
@@ -1,12 +1,12 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'digest/bubblebabble'
describe "Digest.bubblebabble" do
it "returns a String" do
- Digest.bubblebabble('').should be_an_instance_of(String)
+ Digest.bubblebabble('').should.instance_of?(String)
end
- it "returns a String in the The Bubble Babble Binary Data Encoding format" do
+ it "returns a String in the Bubble Babble Binary Data Encoding format" do
Digest.bubblebabble('').should == 'xexax'
Digest.bubblebabble('foo').should == 'xinik-zorox'
Digest.bubblebabble('bar').should == 'ximik-cosex'
@@ -20,10 +20,10 @@ describe "Digest.bubblebabble" do
end
it "raises a TypeError when passed nil" do
- lambda { Digest.bubblebabble(nil) }.should raise_error(TypeError)
+ -> { Digest.bubblebabble(nil) }.should.raise(TypeError)
end
- it "raises a TypeError when passed a Fixnum" do
- lambda { Digest.bubblebabble(9001) }.should raise_error(TypeError)
+ it "raises a TypeError when passed an Integer" do
+ -> { Digest.bubblebabble(9001) }.should.raise(TypeError)
end
end
diff --git a/spec/ruby/library/digest/hexencode_spec.rb b/spec/ruby/library/digest/hexencode_spec.rb
index 9e59e69fce..3359303d15 100644
--- a/spec/ruby/library/digest/hexencode_spec.rb
+++ b/spec/ruby/library/digest/hexencode_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'digest'
describe "Digest.hexencode" do
@@ -22,10 +22,10 @@ describe "Digest.hexencode" do
end
it "raises a TypeError when passed nil" do
- lambda { Digest.hexencode(nil) }.should raise_error(TypeError)
+ -> { Digest.hexencode(nil) }.should.raise(TypeError)
end
- it "raises a TypeError when passed a Fixnum" do
- lambda { Digest.hexencode(9001) }.should raise_error(TypeError)
+ it "raises a TypeError when passed an Integer" do
+ -> { Digest.hexencode(9001) }.should.raise(TypeError)
end
end
diff --git a/spec/ruby/library/digest/instance/append_spec.rb b/spec/ruby/library/digest/instance/append_spec.rb
new file mode 100644
index 0000000000..7f4ce3d121
--- /dev/null
+++ b/spec/ruby/library/digest/instance/append_spec.rb
@@ -0,0 +1,11 @@
+require_relative '../../../spec_helper'
+require 'digest'
+
+describe "Digest::Instance#<<" do
+ it "raises a RuntimeError if called" do
+ c = Class.new do
+ include Digest::Instance
+ end
+ -> { c.new << "test" }.should.raise(RuntimeError)
+ end
+end
diff --git a/spec/ruby/library/digest/instance/new_spec.rb b/spec/ruby/library/digest/instance/new_spec.rb
new file mode 100644
index 0000000000..3f7939844b
--- /dev/null
+++ b/spec/ruby/library/digest/instance/new_spec.rb
@@ -0,0 +1,19 @@
+require_relative '../../../spec_helper'
+require 'digest'
+require_relative '../md5/shared/constants'
+
+describe "Digest::Instance#new" do
+ it "returns a copy of the digest instance" do
+ digest = Digest::MD5.new
+ copy = digest.new
+ copy.should_not.equal?(digest)
+ end
+
+ it "calls reset" do
+ digest = Digest::MD5.new
+ digest << "test"
+ digest.hexdigest.should != MD5Constants::BlankHexdigest
+ copy = digest.new
+ copy.hexdigest.should == MD5Constants::BlankHexdigest
+ end
+end
diff --git a/spec/ruby/library/digest/instance/update_spec.rb b/spec/ruby/library/digest/instance/update_spec.rb
new file mode 100644
index 0000000000..d15b976213
--- /dev/null
+++ b/spec/ruby/library/digest/instance/update_spec.rb
@@ -0,0 +1,8 @@
+require_relative '../../../spec_helper'
+require 'digest'
+
+describe "Digest::Instance#update" do
+ it "is an alias of Digest::Instance#<<" do
+ Digest::Instance.instance_method(:update).should == Digest::Instance.instance_method(:<<)
+ end
+end
diff --git a/spec/ruby/library/digest/md5/append_spec.rb b/spec/ruby/library/digest/md5/append_spec.rb
index ad828c83c1..6f42e4f286 100644
--- a/spec/ruby/library/digest/md5/append_spec.rb
+++ b/spec/ruby/library/digest/md5/append_spec.rb
@@ -1,7 +1,10 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/constants', __FILE__)
-require File.expand_path('../shared/update', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'shared/constants'
describe "Digest::MD5#<<" do
- it_behaves_like(:md5_update, :<<)
+ it "can update" do
+ cur_digest = Digest::MD5.new
+ cur_digest << MD5Constants::Contents
+ cur_digest.digest.should == MD5Constants::Digest
+ end
end
diff --git a/spec/ruby/library/digest/md5/block_length_spec.rb b/spec/ruby/library/digest/md5/block_length_spec.rb
index acc3108da4..14fb050abd 100644
--- a/spec/ruby/library/digest/md5/block_length_spec.rb
+++ b/spec/ruby/library/digest/md5/block_length_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/constants', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'shared/constants'
describe "Digest::MD5#block_length" do
@@ -9,4 +9,3 @@ describe "Digest::MD5#block_length" do
end
end
-
diff --git a/spec/ruby/library/digest/md5/digest_bang_spec.rb b/spec/ruby/library/digest/md5/digest_bang_spec.rb
index 88b865dcba..7b884a16d9 100644
--- a/spec/ruby/library/digest/md5/digest_bang_spec.rb
+++ b/spec/ruby/library/digest/md5/digest_bang_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/constants', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'shared/constants'
describe "Digest::MD5#digest!" do
diff --git a/spec/ruby/library/digest/md5/digest_length_spec.rb b/spec/ruby/library/digest/md5/digest_length_spec.rb
index 426e42af76..47e071e329 100644
--- a/spec/ruby/library/digest/md5/digest_length_spec.rb
+++ b/spec/ruby/library/digest/md5/digest_length_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/constants', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'shared/constants'
describe "Digest::MD5#digest_length" do
@@ -9,4 +9,3 @@ describe "Digest::MD5#digest_length" do
end
end
-
diff --git a/spec/ruby/library/digest/md5/digest_spec.rb b/spec/ruby/library/digest/md5/digest_spec.rb
index 1568c630aa..d9bbc45ee2 100644
--- a/spec/ruby/library/digest/md5/digest_spec.rb
+++ b/spec/ruby/library/digest/md5/digest_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/constants', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'shared/constants'
describe "Digest::MD5#digest" do
diff --git a/spec/ruby/library/digest/md5/equal_spec.rb b/spec/ruby/library/digest/md5/equal_spec.rb
index 0b776f53c0..b0e36564cd 100644
--- a/spec/ruby/library/digest/md5/equal_spec.rb
+++ b/spec/ruby/library/digest/md5/equal_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/constants', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'shared/constants'
describe "Digest::MD5#==" do
@@ -35,4 +35,3 @@ describe "Digest::MD5#==" do
end
end
-
diff --git a/spec/ruby/library/digest/md5/file_spec.rb b/spec/ruby/library/digest/md5/file_spec.rb
index c7f4328546..9a78a8c055 100644
--- a/spec/ruby/library/digest/md5/file_spec.rb
+++ b/spec/ruby/library/digest/md5/file_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/constants', __FILE__)
-require File.expand_path('../../../../core/file/shared/read', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'shared/constants'
+require_relative '../../../core/file/shared/read'
describe "Digest::MD5.file" do
@@ -15,7 +15,7 @@ describe "Digest::MD5.file" do
end
it "returns a Digest::MD5 object" do
- Digest::MD5.file(@file).should be_kind_of(Digest::MD5)
+ Digest::MD5.file(@file).should.is_a?(Digest::MD5)
end
it "returns a Digest::MD5 object with the correct digest" do
@@ -26,7 +26,7 @@ describe "Digest::MD5.file" do
obj = mock("to_str")
obj.should_receive(:to_str).and_return(@file)
result = Digest::MD5.file(obj)
- result.should be_kind_of(Digest::MD5)
+ result.should.is_a?(Digest::MD5)
result.digest.should == MD5Constants::Digest
end
end
@@ -34,10 +34,10 @@ describe "Digest::MD5.file" do
it_behaves_like :file_read_directory, :file, Digest::MD5
it "raises a Errno::ENOENT when passed a path that does not exist" do
- lambda { Digest::MD5.file("") }.should raise_error(Errno::ENOENT)
+ -> { Digest::MD5.file("") }.should.raise(Errno::ENOENT)
end
it "raises a TypeError when passed nil" do
- lambda { Digest::MD5.file(nil) }.should raise_error(TypeError)
+ -> { Digest::MD5.file(nil) }.should.raise(TypeError)
end
end
diff --git a/spec/ruby/library/digest/md5/hexdigest_bang_spec.rb b/spec/ruby/library/digest/md5/hexdigest_bang_spec.rb
index fe67136c97..a953eb3b4c 100644
--- a/spec/ruby/library/digest/md5/hexdigest_bang_spec.rb
+++ b/spec/ruby/library/digest/md5/hexdigest_bang_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/constants', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'shared/constants'
describe "Digest::MD5#hexdigest!" do
diff --git a/spec/ruby/library/digest/md5/hexdigest_spec.rb b/spec/ruby/library/digest/md5/hexdigest_spec.rb
index 9caec29f38..03ead68b82 100644
--- a/spec/ruby/library/digest/md5/hexdigest_spec.rb
+++ b/spec/ruby/library/digest/md5/hexdigest_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/constants', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'shared/constants'
describe "Digest::MD5#hexdigest" do
diff --git a/spec/ruby/library/digest/md5/inspect_spec.rb b/spec/ruby/library/digest/md5/inspect_spec.rb
index e23465337a..decc86fba5 100644
--- a/spec/ruby/library/digest/md5/inspect_spec.rb
+++ b/spec/ruby/library/digest/md5/inspect_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/constants', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'shared/constants'
describe "Digest::MD5#inspect" do
@@ -9,4 +9,3 @@ describe "Digest::MD5#inspect" do
end
end
-
diff --git a/spec/ruby/library/digest/md5/length_spec.rb b/spec/ruby/library/digest/md5/length_spec.rb
index 13eaf2e8d5..18bda51129 100644
--- a/spec/ruby/library/digest/md5/length_spec.rb
+++ b/spec/ruby/library/digest/md5/length_spec.rb
@@ -1,8 +1,11 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/constants', __FILE__)
-require File.expand_path('../shared/length', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'shared/constants'
describe "Digest::MD5#length" do
- it_behaves_like :md5_length, :length
+ it "returns the length of the digest" do
+ cur_digest = Digest::MD5.new
+ cur_digest.length.should == MD5Constants::BlankDigest.size
+ cur_digest << MD5Constants::Contents
+ cur_digest.length.should == MD5Constants::Digest.size
+ end
end
-
diff --git a/spec/ruby/library/digest/md5/reset_spec.rb b/spec/ruby/library/digest/md5/reset_spec.rb
index d95ecfaf8c..c937844f38 100644
--- a/spec/ruby/library/digest/md5/reset_spec.rb
+++ b/spec/ruby/library/digest/md5/reset_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/constants', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'shared/constants'
describe "Digest::MD5#reset" do
@@ -12,4 +12,3 @@ describe "Digest::MD5#reset" do
end
end
-
diff --git a/spec/ruby/library/digest/md5/shared/constants.rb b/spec/ruby/library/digest/md5/shared/constants.rb
index fdfae56d63..664dd18e9c 100644
--- a/spec/ruby/library/digest/md5/shared/constants.rb
+++ b/spec/ruby/library/digest/md5/shared/constants.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require 'digest/md5'
module MD5Constants
@@ -12,5 +12,6 @@ module MD5Constants
Digest = "\2473\267qw\276\364\343\345\320\304\350\313\314\217n"
BlankHexdigest = "d41d8cd98f00b204e9800998ecf8427e"
Hexdigest = "a733b77177bef4e3e5d0c4e8cbcc8f6e"
+ Base64digest = "pzO3cXe+9OPl0MToy8yPbg=="
end
diff --git a/spec/ruby/library/digest/md5/shared/length.rb b/spec/ruby/library/digest/md5/shared/length.rb
deleted file mode 100644
index c5b2b97b58..0000000000
--- a/spec/ruby/library/digest/md5/shared/length.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-describe :md5_length, shared: true do
- it "returns the length of the digest" do
- cur_digest = Digest::MD5.new
- cur_digest.send(@method).should == MD5Constants::BlankDigest.size
- cur_digest << MD5Constants::Contents
- cur_digest.send(@method).should == MD5Constants::Digest.size
- end
-end
diff --git a/spec/ruby/library/digest/md5/shared/sample.rb b/spec/ruby/library/digest/md5/shared/sample.rb
deleted file mode 100644
index 2bb4f658b1..0000000000
--- a/spec/ruby/library/digest/md5/shared/sample.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-# -*- encoding: binary -*-
-
-require 'digest/md5'
-
-module MD5Constants
-
- Contents = "Ipsum is simply dummy text of the printing and typesetting industry. \nLorem Ipsum has been the industrys standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. \nIt has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. \nIt was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."
-
- Klass = ::Digest::MD5
- BlockLength = 64
- DigestLength = 16
- BlankDigest = "\324\035\214\331\217\000\262\004\351\200\t\230\354\370B~"
- Digest = "\2473\267qw\276\364\343\345\320\304\350\313\314\217n"
- BlankHexdigest = "d41d8cd98f00b204e9800998ecf8427e"
- Hexdigest = "a733b77177bef4e3e5d0c4e8cbcc8f6e"
-
-end
diff --git a/spec/ruby/library/digest/md5/shared/update.rb b/spec/ruby/library/digest/md5/shared/update.rb
deleted file mode 100644
index be8622aed5..0000000000
--- a/spec/ruby/library/digest/md5/shared/update.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-describe :md5_update, shared: true do
- it "can update" do
- cur_digest = Digest::MD5.new
- cur_digest.send @method, MD5Constants::Contents
- cur_digest.digest.should == MD5Constants::Digest
- end
-end
diff --git a/spec/ruby/library/digest/md5/size_spec.rb b/spec/ruby/library/digest/md5/size_spec.rb
index 311286e679..54709234de 100644
--- a/spec/ruby/library/digest/md5/size_spec.rb
+++ b/spec/ruby/library/digest/md5/size_spec.rb
@@ -1,8 +1,8 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/constants', __FILE__)
-require File.expand_path('../shared/length', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'shared/constants'
describe "Digest::MD5#size" do
- it_behaves_like :md5_length, :size
+ it "is an alias of Digest::MD5#length" do
+ Digest::MD5.instance_method(:size).should == Digest::MD5.instance_method(:length)
+ end
end
-
diff --git a/spec/ruby/library/digest/md5/to_s_spec.rb b/spec/ruby/library/digest/md5/to_s_spec.rb
index 59c17ec821..78d53d6967 100644
--- a/spec/ruby/library/digest/md5/to_s_spec.rb
+++ b/spec/ruby/library/digest/md5/to_s_spec.rb
@@ -1,8 +1,8 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'digest/md5'
-require File.expand_path('../shared/constants', __FILE__)
+require_relative 'shared/constants'
describe "Digest::MD5#to_s" do
diff --git a/spec/ruby/library/digest/md5/update_spec.rb b/spec/ruby/library/digest/md5/update_spec.rb
index 5a271481f7..830ccfead6 100644
--- a/spec/ruby/library/digest/md5/update_spec.rb
+++ b/spec/ruby/library/digest/md5/update_spec.rb
@@ -1,7 +1,8 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/constants', __FILE__)
-require File.expand_path('../shared/update', __FILE__)
+require_relative '../../../spec_helper'
+require 'digest'
describe "Digest::MD5#update" do
- it_behaves_like :md5_update, :update
+ it "is an alias of Digest::MD5#<<" do
+ Digest::MD5.instance_method(:update).should == Digest::MD5.instance_method(:<<)
+ end
end
diff --git a/spec/ruby/library/digest/sha1/digest_spec.rb b/spec/ruby/library/digest/sha1/digest_spec.rb
index abb4034a69..03f805336f 100644
--- a/spec/ruby/library/digest/sha1/digest_spec.rb
+++ b/spec/ruby/library/digest/sha1/digest_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/constants', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'shared/constants'
describe "Digest::SHA1#digest" do
diff --git a/spec/ruby/library/digest/sha1/file_spec.rb b/spec/ruby/library/digest/sha1/file_spec.rb
index 2c9fd2cb52..d36e560e21 100644
--- a/spec/ruby/library/digest/sha1/file_spec.rb
+++ b/spec/ruby/library/digest/sha1/file_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/constants', __FILE__)
-require File.expand_path('../../../../core/file/shared/read', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'shared/constants'
+require_relative '../../../core/file/shared/read'
describe "Digest::SHA1.file" do
@@ -15,7 +15,7 @@ describe "Digest::SHA1.file" do
end
it "returns a Digest::SHA1 object" do
- Digest::SHA1.file(@file).should be_kind_of(Digest::SHA1)
+ Digest::SHA1.file(@file).should.is_a?(Digest::SHA1)
end
it "returns a Digest::SHA1 object with the correct digest" do
@@ -26,7 +26,7 @@ describe "Digest::SHA1.file" do
obj = mock("to_str")
obj.should_receive(:to_str).and_return(@file)
result = Digest::SHA1.file(obj)
- result.should be_kind_of(Digest::SHA1)
+ result.should.is_a?(Digest::SHA1)
result.digest.should == SHA1Constants::Digest
end
end
@@ -34,10 +34,10 @@ describe "Digest::SHA1.file" do
it_behaves_like :file_read_directory, :file, Digest::SHA1
it "raises a Errno::ENOENT when passed a path that does not exist" do
- lambda { Digest::SHA1.file("") }.should raise_error(Errno::ENOENT)
+ -> { Digest::SHA1.file("") }.should.raise(Errno::ENOENT)
end
it "raises a TypeError when passed nil" do
- lambda { Digest::SHA1.file(nil) }.should raise_error(TypeError)
+ -> { Digest::SHA1.file(nil) }.should.raise(TypeError)
end
end
diff --git a/spec/ruby/library/digest/sha1/shared/constants.rb b/spec/ruby/library/digest/sha1/shared/constants.rb
index add86b1dd3..d77c05a968 100644
--- a/spec/ruby/library/digest/sha1/shared/constants.rb
+++ b/spec/ruby/library/digest/sha1/shared/constants.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require 'digest/sha1'
@@ -12,6 +12,7 @@ module SHA1Constants
BlankDigest = "\3329\243\356^kK\r2U\277\357\225`\030\220\257\330\a\t"
Digest = "X!\255b\323\035\352\314a|q\344+\376\317\361V9\324\343"
BlankHexdigest = "da39a3ee5e6b4b0d3255bfef95601890afd80709"
- Hexdigest = "e907d2ba21c6c74bc0efd76e44d11fb9bbb7a75e"
+ Hexdigest = "5821ad62d31deacc617c71e42bfecff15639d4e3"
+ Base64digest = "WCGtYtMd6sxhfHHkK/7P8VY51OM="
end
diff --git a/spec/ruby/library/digest/sha2/hexdigest_spec.rb b/spec/ruby/library/digest/sha2/hexdigest_spec.rb
new file mode 100644
index 0000000000..79beca5788
--- /dev/null
+++ b/spec/ruby/library/digest/sha2/hexdigest_spec.rb
@@ -0,0 +1,32 @@
+require_relative '../../../spec_helper'
+require_relative '../sha256/shared/constants'
+
+describe "Digest::SHA2#hexdigest" do
+
+ it "returns a SHA256 hexdigest by default" do
+ cur_digest = Digest::SHA2.new
+ cur_digest.hexdigest.should == SHA256Constants::BlankHexdigest
+
+ # add something to check that the state is reset later
+ cur_digest << "test"
+
+ cur_digest.hexdigest(SHA256Constants::Contents).should == SHA256Constants::Hexdigest
+ # second invocation is intentional, to make sure there are no side-effects
+ cur_digest.hexdigest(SHA256Constants::Contents).should == SHA256Constants::Hexdigest
+
+ # after all is done, verify that the digest is in the original, blank state
+ cur_digest.hexdigest.should == SHA256Constants::BlankHexdigest
+ end
+
+end
+
+describe "Digest::SHA2.hexdigest" do
+
+ it "returns a SHA256 hexdigest by default" do
+ Digest::SHA2.hexdigest(SHA256Constants::Contents).should == SHA256Constants::Hexdigest
+ # second invocation is intentional, to make sure there are no side-effects
+ Digest::SHA2.hexdigest(SHA256Constants::Contents).should == SHA256Constants::Hexdigest
+ Digest::SHA2.hexdigest("").should == SHA256Constants::BlankHexdigest
+ end
+
+end
diff --git a/spec/ruby/library/digest/sha256/append_spec.rb b/spec/ruby/library/digest/sha256/append_spec.rb
index 53e623743a..f18b06c2a1 100644
--- a/spec/ruby/library/digest/sha256/append_spec.rb
+++ b/spec/ruby/library/digest/sha256/append_spec.rb
@@ -1,7 +1,10 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/constants', __FILE__)
-require File.expand_path('../shared/update', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'shared/constants'
describe "Digest::SHA256#<<" do
- it_behaves_like(:sha256_update, :<<)
+ it "can update" do
+ cur_digest = Digest::SHA256.new
+ cur_digest << SHA256Constants::Contents
+ cur_digest.digest.should == SHA256Constants::Digest
+ end
end
diff --git a/spec/ruby/library/digest/sha256/block_length_spec.rb b/spec/ruby/library/digest/sha256/block_length_spec.rb
index 4fea959da1..1e29e832cf 100644
--- a/spec/ruby/library/digest/sha256/block_length_spec.rb
+++ b/spec/ruby/library/digest/sha256/block_length_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/constants', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'shared/constants'
describe "Digest::SHA256#block_length" do
@@ -9,4 +9,3 @@ describe "Digest::SHA256#block_length" do
end
end
-
diff --git a/spec/ruby/library/digest/sha256/digest_bang_spec.rb b/spec/ruby/library/digest/sha256/digest_bang_spec.rb
index b876c2ceed..690442221a 100644
--- a/spec/ruby/library/digest/sha256/digest_bang_spec.rb
+++ b/spec/ruby/library/digest/sha256/digest_bang_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/constants', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'shared/constants'
describe "Digest::SHA256#digest!" do
diff --git a/spec/ruby/library/digest/sha256/digest_length_spec.rb b/spec/ruby/library/digest/sha256/digest_length_spec.rb
index f3d0d66877..b5c8958e84 100644
--- a/spec/ruby/library/digest/sha256/digest_length_spec.rb
+++ b/spec/ruby/library/digest/sha256/digest_length_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/constants', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'shared/constants'
describe "Digest::SHA256#digest_length" do
@@ -9,4 +9,3 @@ describe "Digest::SHA256#digest_length" do
end
end
-
diff --git a/spec/ruby/library/digest/sha256/digest_spec.rb b/spec/ruby/library/digest/sha256/digest_spec.rb
index de30916d57..1e79f25627 100644
--- a/spec/ruby/library/digest/sha256/digest_spec.rb
+++ b/spec/ruby/library/digest/sha256/digest_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/constants', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'shared/constants'
describe "Digest::SHA256#digest" do
diff --git a/spec/ruby/library/digest/sha256/equal_spec.rb b/spec/ruby/library/digest/sha256/equal_spec.rb
index 7932b6c13d..84662aa068 100644
--- a/spec/ruby/library/digest/sha256/equal_spec.rb
+++ b/spec/ruby/library/digest/sha256/equal_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/constants', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'shared/constants'
describe "Digest::SHA256#==" do
@@ -34,4 +34,3 @@ describe "Digest::SHA256#==" do
end
end
-
diff --git a/spec/ruby/library/digest/sha256/file_spec.rb b/spec/ruby/library/digest/sha256/file_spec.rb
index a52b7939f3..d67a9ebcd6 100644
--- a/spec/ruby/library/digest/sha256/file_spec.rb
+++ b/spec/ruby/library/digest/sha256/file_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/constants', __FILE__)
-require File.expand_path('../../../../core/file/shared/read', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'shared/constants'
+require_relative '../../../core/file/shared/read'
describe "Digest::SHA256.file" do
@@ -15,18 +15,22 @@ describe "Digest::SHA256.file" do
end
it "returns a Digest::SHA256 object" do
- Digest::SHA256.file(@file).should be_kind_of(Digest::SHA256)
+ Digest::SHA256.file(@file).should.is_a?(Digest::SHA256)
end
it "returns a Digest::SHA256 object with the correct digest" do
Digest::SHA256.file(@file).digest.should == SHA256Constants::Digest
end
+ it "can be used with frozen-string-literal" do
+ ruby_exe("require 'digest'; puts Digest::SHA256.file(#{@file.inspect}).digest.inspect", options: "--enable=frozen-string-literal").chomp.should == SHA256Constants::Digest.inspect
+ end
+
it "calls #to_str on an object and returns the Digest::SHA256 with the result" do
obj = mock("to_str")
obj.should_receive(:to_str).and_return(@file)
result = Digest::SHA256.file(obj)
- result.should be_kind_of(Digest::SHA256)
+ result.should.is_a?(Digest::SHA256)
result.digest.should == SHA256Constants::Digest
end
end
@@ -34,10 +38,10 @@ describe "Digest::SHA256.file" do
it_behaves_like :file_read_directory, :file, Digest::SHA256
it "raises a Errno::ENOENT when passed a path that does not exist" do
- lambda { Digest::SHA256.file("") }.should raise_error(Errno::ENOENT)
+ -> { Digest::SHA256.file("") }.should.raise(Errno::ENOENT)
end
it "raises a TypeError when passed nil" do
- lambda { Digest::SHA256.file(nil) }.should raise_error(TypeError)
+ -> { Digest::SHA256.file(nil) }.should.raise(TypeError)
end
end
diff --git a/spec/ruby/library/digest/sha256/hexdigest_bang_spec.rb b/spec/ruby/library/digest/sha256/hexdigest_bang_spec.rb
index 98bf38f773..1acd8043b3 100644
--- a/spec/ruby/library/digest/sha256/hexdigest_bang_spec.rb
+++ b/spec/ruby/library/digest/sha256/hexdigest_bang_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/constants', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'shared/constants'
describe "Digest::SHA256#hexdigest!" do
diff --git a/spec/ruby/library/digest/sha256/hexdigest_spec.rb b/spec/ruby/library/digest/sha256/hexdigest_spec.rb
index 3ee7844a93..4f748b33b4 100644
--- a/spec/ruby/library/digest/sha256/hexdigest_spec.rb
+++ b/spec/ruby/library/digest/sha256/hexdigest_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/constants', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'shared/constants'
describe "Digest::SHA256#hexdigest" do
diff --git a/spec/ruby/library/digest/sha256/inspect_spec.rb b/spec/ruby/library/digest/sha256/inspect_spec.rb
index 5e44b58c63..ed606e4517 100644
--- a/spec/ruby/library/digest/sha256/inspect_spec.rb
+++ b/spec/ruby/library/digest/sha256/inspect_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/constants', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'shared/constants'
describe "Digest::SHA256#inspect" do
@@ -9,4 +9,3 @@ describe "Digest::SHA256#inspect" do
end
end
-
diff --git a/spec/ruby/library/digest/sha256/length_spec.rb b/spec/ruby/library/digest/sha256/length_spec.rb
index 6760511093..fc3db6548e 100644
--- a/spec/ruby/library/digest/sha256/length_spec.rb
+++ b/spec/ruby/library/digest/sha256/length_spec.rb
@@ -1,8 +1,11 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/constants', __FILE__)
-require File.expand_path('../shared/length', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'shared/constants'
describe "Digest::SHA256#length" do
- it_behaves_like :sha256_length, :length
+ it "returns the length of the digest" do
+ cur_digest = Digest::SHA256.new
+ cur_digest.length.should == SHA256Constants::BlankDigest.size
+ cur_digest << SHA256Constants::Contents
+ cur_digest.length.should == SHA256Constants::Digest.size
+ end
end
-
diff --git a/spec/ruby/library/digest/sha256/reset_spec.rb b/spec/ruby/library/digest/sha256/reset_spec.rb
index 82bb08d354..f0eb4faea6 100644
--- a/spec/ruby/library/digest/sha256/reset_spec.rb
+++ b/spec/ruby/library/digest/sha256/reset_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/constants', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'shared/constants'
describe "Digest::SHA256#reset" do
@@ -12,4 +12,3 @@ describe "Digest::SHA256#reset" do
end
end
-
diff --git a/spec/ruby/library/digest/sha256/shared/constants.rb b/spec/ruby/library/digest/sha256/shared/constants.rb
index dd5b48dca9..afe8f11426 100644
--- a/spec/ruby/library/digest/sha256/shared/constants.rb
+++ b/spec/ruby/library/digest/sha256/shared/constants.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require 'digest/sha2'
@@ -13,5 +13,6 @@ module SHA256Constants
Digest = "\230b\265\344_\337\357\337\242\004\314\311A\211jb\350\373\254\370\365M\230B\002\372\020j\as\270\376"
BlankHexdigest = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
Hexdigest = "9862b5e45fdfefdfa204ccc941896a62e8fbacf8f54d984202fa106a0773b8fe"
+ Base64digest = "mGK15F/f79+iBMzJQYlqYuj7rPj1TZhCAvoQagdzuP4="
end
diff --git a/spec/ruby/library/digest/sha256/shared/length.rb b/spec/ruby/library/digest/sha256/shared/length.rb
deleted file mode 100644
index 996673a5bd..0000000000
--- a/spec/ruby/library/digest/sha256/shared/length.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-describe :sha256_length, shared: true do
- it "returns the length of the digest" do
- cur_digest = Digest::SHA256.new
- cur_digest.send(@method).should == SHA256Constants::BlankDigest.size
- cur_digest << SHA256Constants::Contents
- cur_digest.send(@method).should == SHA256Constants::Digest.size
- end
-end
diff --git a/spec/ruby/library/digest/sha256/shared/update.rb b/spec/ruby/library/digest/sha256/shared/update.rb
deleted file mode 100644
index 0edc07935b..0000000000
--- a/spec/ruby/library/digest/sha256/shared/update.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-describe :sha256_update, shared: true do
- it "can update" do
- cur_digest = Digest::SHA256.new
- cur_digest.send @method, SHA256Constants::Contents
- cur_digest.digest.should == SHA256Constants::Digest
- end
-end
diff --git a/spec/ruby/library/digest/sha256/size_spec.rb b/spec/ruby/library/digest/sha256/size_spec.rb
index 77db876956..6102e1c8aa 100644
--- a/spec/ruby/library/digest/sha256/size_spec.rb
+++ b/spec/ruby/library/digest/sha256/size_spec.rb
@@ -1,8 +1,8 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/constants', __FILE__)
-require File.expand_path('../shared/length', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'shared/constants'
describe "Digest::SHA256#size" do
- it_behaves_like :sha256_length, :size
+ it "is an alias of Digest::SHA256#length" do
+ Digest::SHA256.instance_method(:size).should == Digest::SHA256.instance_method(:length)
+ end
end
-
diff --git a/spec/ruby/library/digest/sha256/to_s_spec.rb b/spec/ruby/library/digest/sha256/to_s_spec.rb
index b91983d157..8bedee3f98 100644
--- a/spec/ruby/library/digest/sha256/to_s_spec.rb
+++ b/spec/ruby/library/digest/sha256/to_s_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/constants', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'shared/constants'
describe "Digest::SHA256#to_s" do
diff --git a/spec/ruby/library/digest/sha256/update_spec.rb b/spec/ruby/library/digest/sha256/update_spec.rb
index 3e3eaf57a3..d6724936f1 100644
--- a/spec/ruby/library/digest/sha256/update_spec.rb
+++ b/spec/ruby/library/digest/sha256/update_spec.rb
@@ -1,7 +1,8 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/constants', __FILE__)
-require File.expand_path('../shared/update', __FILE__)
+require_relative '../../../spec_helper'
+require 'digest'
describe "Digest::SHA256#update" do
- it_behaves_like :sha256_update, :update
+ it "is an alias of Digest::SHA256#<<" do
+ Digest::SHA256.instance_method(:update).should == Digest::SHA256.instance_method(:<<)
+ end
end
diff --git a/spec/ruby/library/digest/sha384/append_spec.rb b/spec/ruby/library/digest/sha384/append_spec.rb
index d694812e85..b9a862f1c2 100644
--- a/spec/ruby/library/digest/sha384/append_spec.rb
+++ b/spec/ruby/library/digest/sha384/append_spec.rb
@@ -1,7 +1,10 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/constants', __FILE__)
-require File.expand_path('../shared/update', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'shared/constants'
describe "Digest::SHA384#<<" do
- it_behaves_like(:sha384_update, :<<)
+ it "can update" do
+ cur_digest = Digest::SHA384.new
+ cur_digest << SHA384Constants::Contents
+ cur_digest.digest.should == SHA384Constants::Digest
+ end
end
diff --git a/spec/ruby/library/digest/sha384/block_length_spec.rb b/spec/ruby/library/digest/sha384/block_length_spec.rb
index 070715b27e..dff645ffb9 100644
--- a/spec/ruby/library/digest/sha384/block_length_spec.rb
+++ b/spec/ruby/library/digest/sha384/block_length_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/constants', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'shared/constants'
describe "Digest::SHA384#block_length" do
@@ -9,4 +9,3 @@ describe "Digest::SHA384#block_length" do
end
end
-
diff --git a/spec/ruby/library/digest/sha384/digest_bang_spec.rb b/spec/ruby/library/digest/sha384/digest_bang_spec.rb
index 83b68ae7c2..8711913deb 100644
--- a/spec/ruby/library/digest/sha384/digest_bang_spec.rb
+++ b/spec/ruby/library/digest/sha384/digest_bang_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/constants', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'shared/constants'
describe "Digest::SHA384#digest!" do
diff --git a/spec/ruby/library/digest/sha384/digest_length_spec.rb b/spec/ruby/library/digest/sha384/digest_length_spec.rb
index a57616b44c..4067dd34af 100644
--- a/spec/ruby/library/digest/sha384/digest_length_spec.rb
+++ b/spec/ruby/library/digest/sha384/digest_length_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/constants', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'shared/constants'
describe "Digest::SHA384#digest_length" do
@@ -9,4 +9,3 @@ describe "Digest::SHA384#digest_length" do
end
end
-
diff --git a/spec/ruby/library/digest/sha384/digest_spec.rb b/spec/ruby/library/digest/sha384/digest_spec.rb
index 3a5cd3a5d7..d0e2825934 100644
--- a/spec/ruby/library/digest/sha384/digest_spec.rb
+++ b/spec/ruby/library/digest/sha384/digest_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/constants', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'shared/constants'
describe "Digest::SHA384#digest" do
diff --git a/spec/ruby/library/digest/sha384/equal_spec.rb b/spec/ruby/library/digest/sha384/equal_spec.rb
index a54d328edc..5d3483d79a 100644
--- a/spec/ruby/library/digest/sha384/equal_spec.rb
+++ b/spec/ruby/library/digest/sha384/equal_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/constants', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'shared/constants'
describe "Digest::SHA384#==" do
@@ -34,4 +34,3 @@ describe "Digest::SHA384#==" do
end
end
-
diff --git a/spec/ruby/library/digest/sha384/file_spec.rb b/spec/ruby/library/digest/sha384/file_spec.rb
index 7e7c8f9565..3726ad4423 100644
--- a/spec/ruby/library/digest/sha384/file_spec.rb
+++ b/spec/ruby/library/digest/sha384/file_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/constants', __FILE__)
-require File.expand_path('../../../../core/file/shared/read', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'shared/constants'
+require_relative '../../../core/file/shared/read'
describe "Digest::SHA384.file" do
@@ -15,7 +15,7 @@ describe "Digest::SHA384.file" do
end
it "returns a Digest::SHA384 object" do
- Digest::SHA384.file(@file).should be_kind_of(Digest::SHA384)
+ Digest::SHA384.file(@file).should.is_a?(Digest::SHA384)
end
it "returns a Digest::SHA384 object with the correct digest" do
@@ -26,7 +26,7 @@ describe "Digest::SHA384.file" do
obj = mock("to_str")
obj.should_receive(:to_str).and_return(@file)
result = Digest::SHA384.file(obj)
- result.should be_kind_of(Digest::SHA384)
+ result.should.is_a?(Digest::SHA384)
result.digest.should == SHA384Constants::Digest
end
end
@@ -34,10 +34,10 @@ describe "Digest::SHA384.file" do
it_behaves_like :file_read_directory, :file, Digest::SHA384
it "raises a Errno::ENOENT when passed a path that does not exist" do
- lambda { Digest::SHA384.file("") }.should raise_error(Errno::ENOENT)
+ -> { Digest::SHA384.file("") }.should.raise(Errno::ENOENT)
end
it "raises a TypeError when passed nil" do
- lambda { Digest::SHA384.file(nil) }.should raise_error(TypeError)
+ -> { Digest::SHA384.file(nil) }.should.raise(TypeError)
end
end
diff --git a/spec/ruby/library/digest/sha384/hexdigest_bang_spec.rb b/spec/ruby/library/digest/sha384/hexdigest_bang_spec.rb
index 68da8c7200..8efceec3eb 100644
--- a/spec/ruby/library/digest/sha384/hexdigest_bang_spec.rb
+++ b/spec/ruby/library/digest/sha384/hexdigest_bang_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/constants', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'shared/constants'
describe "Digest::SHA384#hexdigest!" do
diff --git a/spec/ruby/library/digest/sha384/hexdigest_spec.rb b/spec/ruby/library/digest/sha384/hexdigest_spec.rb
index a7724d1663..07ea05c541 100644
--- a/spec/ruby/library/digest/sha384/hexdigest_spec.rb
+++ b/spec/ruby/library/digest/sha384/hexdigest_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/constants', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'shared/constants'
describe "Digest::SHA384#hexdigest" do
diff --git a/spec/ruby/library/digest/sha384/inspect_spec.rb b/spec/ruby/library/digest/sha384/inspect_spec.rb
index 554a22d135..8f9f946cc5 100644
--- a/spec/ruby/library/digest/sha384/inspect_spec.rb
+++ b/spec/ruby/library/digest/sha384/inspect_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/constants', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'shared/constants'
describe "Digest::SHA384#inspect" do
@@ -9,4 +9,3 @@ describe "Digest::SHA384#inspect" do
end
end
-
diff --git a/spec/ruby/library/digest/sha384/length_spec.rb b/spec/ruby/library/digest/sha384/length_spec.rb
index 63a57ce9ca..e5cd6131fd 100644
--- a/spec/ruby/library/digest/sha384/length_spec.rb
+++ b/spec/ruby/library/digest/sha384/length_spec.rb
@@ -1,8 +1,11 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/constants', __FILE__)
-require File.expand_path('../shared/length', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'shared/constants'
describe "Digest::SHA384#length" do
- it_behaves_like :sha384_length, :length
+ it "returns the length of the digest" do
+ cur_digest = Digest::SHA384.new
+ cur_digest.length.should == SHA384Constants::BlankDigest.size
+ cur_digest << SHA384Constants::Contents
+ cur_digest.length.should == SHA384Constants::Digest.size
+ end
end
-
diff --git a/spec/ruby/library/digest/sha384/reset_spec.rb b/spec/ruby/library/digest/sha384/reset_spec.rb
index 8abe39d7e2..991b90903d 100644
--- a/spec/ruby/library/digest/sha384/reset_spec.rb
+++ b/spec/ruby/library/digest/sha384/reset_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/constants', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'shared/constants'
describe "Digest::SHA384#reset" do
@@ -12,4 +12,3 @@ describe "Digest::SHA384#reset" do
end
end
-
diff --git a/spec/ruby/library/digest/sha384/shared/constants.rb b/spec/ruby/library/digest/sha384/shared/constants.rb
index 3697384fc3..a78d571d26 100644
--- a/spec/ruby/library/digest/sha384/shared/constants.rb
+++ b/spec/ruby/library/digest/sha384/shared/constants.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require 'digest/sha2'
@@ -14,5 +14,6 @@ module SHA384Constants
Digest = "B&\266:\314\216z\361!TD\001{`\355\323\320MW%\270\272\0034n\034\026g\a\217\"\333s\202\275\002Y*\217]\207u\f\034\244\231\266f"
BlankHexdigest = "38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b"
Hexdigest = "4226b63acc8e7af1215444017b60edd3d04d5725b8ba03346e1c1667078f22db7382bd02592a8f5d87750c1ca499b666"
+ Base64digest = "Qia2OsyOevEhVEQBe2Dt09BNVyW4ugM0bhwWZwePIttzgr0CWSqPXYd1DBykmbZm"
end
diff --git a/spec/ruby/library/digest/sha384/shared/length.rb b/spec/ruby/library/digest/sha384/shared/length.rb
deleted file mode 100644
index 0c88288bcf..0000000000
--- a/spec/ruby/library/digest/sha384/shared/length.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-describe :sha384_length, shared: true do
- it "returns the length of the digest" do
- cur_digest = Digest::SHA384.new
- cur_digest.send(@method).should == SHA384Constants::BlankDigest.size
- cur_digest << SHA384Constants::Contents
- cur_digest.send(@method).should == SHA384Constants::Digest.size
- end
-end
diff --git a/spec/ruby/library/digest/sha384/shared/update.rb b/spec/ruby/library/digest/sha384/shared/update.rb
deleted file mode 100644
index 1c6e31cf6a..0000000000
--- a/spec/ruby/library/digest/sha384/shared/update.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-describe :sha384_update, shared: true do
- it "can update" do
- cur_digest = Digest::SHA384.new
- cur_digest.send @method, SHA384Constants::Contents
- cur_digest.digest.should == SHA384Constants::Digest
- end
-end
diff --git a/spec/ruby/library/digest/sha384/size_spec.rb b/spec/ruby/library/digest/sha384/size_spec.rb
index 9aea3ef592..40c291c623 100644
--- a/spec/ruby/library/digest/sha384/size_spec.rb
+++ b/spec/ruby/library/digest/sha384/size_spec.rb
@@ -1,8 +1,8 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/constants', __FILE__)
-require File.expand_path('../shared/length', __FILE__)
+require_relative '../../../spec_helper'
+require 'digest'
describe "Digest::SHA384#size" do
- it_behaves_like :sha384_length, :size
+ it "is an alias of Digest::SHA384#length" do
+ Digest::SHA384.instance_method(:size).should == Digest::SHA384.instance_method(:length)
+ end
end
-
diff --git a/spec/ruby/library/digest/sha384/to_s_spec.rb b/spec/ruby/library/digest/sha384/to_s_spec.rb
index f45f2ee915..68ea9c013f 100644
--- a/spec/ruby/library/digest/sha384/to_s_spec.rb
+++ b/spec/ruby/library/digest/sha384/to_s_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/constants', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'shared/constants'
describe "Digest::SHA384#to_s" do
diff --git a/spec/ruby/library/digest/sha384/update_spec.rb b/spec/ruby/library/digest/sha384/update_spec.rb
index 9917f86b86..561dcad3ec 100644
--- a/spec/ruby/library/digest/sha384/update_spec.rb
+++ b/spec/ruby/library/digest/sha384/update_spec.rb
@@ -1,7 +1,8 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/constants', __FILE__)
-require File.expand_path('../shared/update', __FILE__)
+require_relative '../../../spec_helper'
+require 'digest'
describe "Digest::SHA384#update" do
- it_behaves_like :sha384_update, :update
+ it "is an alias of Digest::SHA384#<<" do
+ Digest::SHA384.instance_method(:update).should == Digest::SHA384.instance_method(:<<)
+ end
end
diff --git a/spec/ruby/library/digest/sha512/append_spec.rb b/spec/ruby/library/digest/sha512/append_spec.rb
index 642e565bf6..f297005403 100644
--- a/spec/ruby/library/digest/sha512/append_spec.rb
+++ b/spec/ruby/library/digest/sha512/append_spec.rb
@@ -1,7 +1,10 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/constants', __FILE__)
-require File.expand_path('../shared/update', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'shared/constants'
describe "Digest::SHA512#<<" do
- it_behaves_like(:sha512_update, :<<)
+ it "can update" do
+ cur_digest = Digest::SHA512.new
+ cur_digest << SHA512Constants::Contents
+ cur_digest.digest.should == SHA512Constants::Digest
+ end
end
diff --git a/spec/ruby/library/digest/sha512/block_length_spec.rb b/spec/ruby/library/digest/sha512/block_length_spec.rb
index 95bb98548a..947af841dd 100644
--- a/spec/ruby/library/digest/sha512/block_length_spec.rb
+++ b/spec/ruby/library/digest/sha512/block_length_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/constants', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'shared/constants'
describe "Digest::SHA512#block_length" do
@@ -9,4 +9,3 @@ describe "Digest::SHA512#block_length" do
end
end
-
diff --git a/spec/ruby/library/digest/sha512/digest_bang_spec.rb b/spec/ruby/library/digest/sha512/digest_bang_spec.rb
index 260595152d..981570b907 100644
--- a/spec/ruby/library/digest/sha512/digest_bang_spec.rb
+++ b/spec/ruby/library/digest/sha512/digest_bang_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/constants', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'shared/constants'
describe "Digest::SHA512#digest!" do
diff --git a/spec/ruby/library/digest/sha512/digest_length_spec.rb b/spec/ruby/library/digest/sha512/digest_length_spec.rb
index 5185b6e906..ff5956dd75 100644
--- a/spec/ruby/library/digest/sha512/digest_length_spec.rb
+++ b/spec/ruby/library/digest/sha512/digest_length_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/constants', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'shared/constants'
describe "Digest::SHA512#digest_length" do
@@ -9,4 +9,3 @@ describe "Digest::SHA512#digest_length" do
end
end
-
diff --git a/spec/ruby/library/digest/sha512/digest_spec.rb b/spec/ruby/library/digest/sha512/digest_spec.rb
index 9f4264579f..092efccc62 100644
--- a/spec/ruby/library/digest/sha512/digest_spec.rb
+++ b/spec/ruby/library/digest/sha512/digest_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/constants', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'shared/constants'
describe "Digest::SHA512#digest" do
diff --git a/spec/ruby/library/digest/sha512/equal_spec.rb b/spec/ruby/library/digest/sha512/equal_spec.rb
index ec4c55f118..5100ced6e8 100644
--- a/spec/ruby/library/digest/sha512/equal_spec.rb
+++ b/spec/ruby/library/digest/sha512/equal_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/constants', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'shared/constants'
describe "Digest::SHA512#==" do
@@ -34,4 +34,3 @@ describe "Digest::SHA512#==" do
end
end
-
diff --git a/spec/ruby/library/digest/sha512/file_spec.rb b/spec/ruby/library/digest/sha512/file_spec.rb
index 365f3625b6..78d6d3d4f3 100644
--- a/spec/ruby/library/digest/sha512/file_spec.rb
+++ b/spec/ruby/library/digest/sha512/file_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/constants', __FILE__)
-require File.expand_path('../../../../core/file/shared/read', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'shared/constants'
+require_relative '../../../core/file/shared/read'
describe "Digest::SHA512.file" do
@@ -15,7 +15,7 @@ describe "Digest::SHA512.file" do
end
it "returns a Digest::SHA512 object" do
- Digest::SHA512.file(@file).should be_kind_of(Digest::SHA512)
+ Digest::SHA512.file(@file).should.is_a?(Digest::SHA512)
end
it "returns a Digest::SHA512 object with the correct digest" do
@@ -26,7 +26,7 @@ describe "Digest::SHA512.file" do
obj = mock("to_str")
obj.should_receive(:to_str).and_return(@file)
result = Digest::SHA512.file(obj)
- result.should be_kind_of(Digest::SHA512)
+ result.should.is_a?(Digest::SHA512)
result.digest.should == SHA512Constants::Digest
end
end
@@ -34,10 +34,10 @@ describe "Digest::SHA512.file" do
it_behaves_like :file_read_directory, :file, Digest::SHA512
it "raises a Errno::ENOENT when passed a path that does not exist" do
- lambda { Digest::SHA512.file("") }.should raise_error(Errno::ENOENT)
+ -> { Digest::SHA512.file("") }.should.raise(Errno::ENOENT)
end
it "raises a TypeError when passed nil" do
- lambda { Digest::SHA512.file(nil) }.should raise_error(TypeError)
+ -> { Digest::SHA512.file(nil) }.should.raise(TypeError)
end
end
diff --git a/spec/ruby/library/digest/sha512/hexdigest_bang_spec.rb b/spec/ruby/library/digest/sha512/hexdigest_bang_spec.rb
index 6eda150949..e9b0da6191 100644
--- a/spec/ruby/library/digest/sha512/hexdigest_bang_spec.rb
+++ b/spec/ruby/library/digest/sha512/hexdigest_bang_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/constants', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'shared/constants'
describe "Digest::SHA512#hexdigest!" do
diff --git a/spec/ruby/library/digest/sha512/hexdigest_spec.rb b/spec/ruby/library/digest/sha512/hexdigest_spec.rb
index 405d380490..6e1dc3c642 100644
--- a/spec/ruby/library/digest/sha512/hexdigest_spec.rb
+++ b/spec/ruby/library/digest/sha512/hexdigest_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/constants', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'shared/constants'
describe "Digest::SHA512#hexdigest" do
diff --git a/spec/ruby/library/digest/sha512/inspect_spec.rb b/spec/ruby/library/digest/sha512/inspect_spec.rb
index 97806000d2..54a466043a 100644
--- a/spec/ruby/library/digest/sha512/inspect_spec.rb
+++ b/spec/ruby/library/digest/sha512/inspect_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/constants', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'shared/constants'
describe "Digest::SHA512#inspect" do
@@ -9,4 +9,3 @@ describe "Digest::SHA512#inspect" do
end
end
-
diff --git a/spec/ruby/library/digest/sha512/length_spec.rb b/spec/ruby/library/digest/sha512/length_spec.rb
index b0b4d7e56c..8e909482c5 100644
--- a/spec/ruby/library/digest/sha512/length_spec.rb
+++ b/spec/ruby/library/digest/sha512/length_spec.rb
@@ -1,8 +1,11 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/constants', __FILE__)
-require File.expand_path('../shared/length', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'shared/constants'
describe "Digest::SHA512#length" do
- it_behaves_like :sha512_length, :length
+ it "returns the length of the digest" do
+ cur_digest = Digest::SHA512.new
+ cur_digest.length.should == SHA512Constants::BlankDigest.size
+ cur_digest << SHA512Constants::Contents
+ cur_digest.length.should == SHA512Constants::Digest.size
+ end
end
-
diff --git a/spec/ruby/library/digest/sha512/reset_spec.rb b/spec/ruby/library/digest/sha512/reset_spec.rb
index b2f28dc670..24a936d4ba 100644
--- a/spec/ruby/library/digest/sha512/reset_spec.rb
+++ b/spec/ruby/library/digest/sha512/reset_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/constants', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'shared/constants'
describe "Digest::SHA512#reset" do
@@ -12,4 +12,3 @@ describe "Digest::SHA512#reset" do
end
end
-
diff --git a/spec/ruby/library/digest/sha512/shared/constants.rb b/spec/ruby/library/digest/sha512/shared/constants.rb
index 80f5b7bc1d..91787381ee 100644
--- a/spec/ruby/library/digest/sha512/shared/constants.rb
+++ b/spec/ruby/library/digest/sha512/shared/constants.rb
@@ -1,4 +1,4 @@
-# -*- encoding: binary -*-
+# encoding: binary
require 'digest/sha2'
@@ -13,5 +13,6 @@ module SHA512Constants
Digest = "\241\231\232\365\002z\241\331\242\310=\367F\272\004\326\331g\315n\251Q\222\250\374E\257\254=\325\225\003SM\350\244\234\220\233=\031\230A;\000\203\233\340\323t\333\271\222w\266\307\2678\344\255j\003\216\300"
BlankHexdigest = "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e"
Hexdigest = "a1999af5027aa1d9a2c83df746ba04d6d967cd6ea95192a8fc45afac3dd59503534de8a49c909b3d1998413b00839be0d374dbb99277b6c7b738e4ad6a038ec0"
+ Base64digest = "oZma9QJ6odmiyD33RroE1tlnzW6pUZKo/EWvrD3VlQNTTeiknJCbPRmYQTsAg5vg03TbuZJ3tse3OOStagOOwA=="
end
diff --git a/spec/ruby/library/digest/sha512/shared/length.rb b/spec/ruby/library/digest/sha512/shared/length.rb
deleted file mode 100644
index c0609d5386..0000000000
--- a/spec/ruby/library/digest/sha512/shared/length.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-describe :sha512_length, shared: true do
- it "returns the length of the digest" do
- cur_digest = Digest::SHA512.new
- cur_digest.send(@method).should == SHA512Constants::BlankDigest.size
- cur_digest << SHA512Constants::Contents
- cur_digest.send(@method).should == SHA512Constants::Digest.size
- end
-end
diff --git a/spec/ruby/library/digest/sha512/shared/update.rb b/spec/ruby/library/digest/sha512/shared/update.rb
deleted file mode 100644
index ca74dbf4df..0000000000
--- a/spec/ruby/library/digest/sha512/shared/update.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-describe :sha512_update, shared: true do
- it "can update" do
- cur_digest = Digest::SHA512.new
- cur_digest.send @method, SHA512Constants::Contents
- cur_digest.digest.should == SHA512Constants::Digest
- end
-end
diff --git a/spec/ruby/library/digest/sha512/size_spec.rb b/spec/ruby/library/digest/sha512/size_spec.rb
index a882fe55a1..498d686802 100644
--- a/spec/ruby/library/digest/sha512/size_spec.rb
+++ b/spec/ruby/library/digest/sha512/size_spec.rb
@@ -1,8 +1,8 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/constants', __FILE__)
-require File.expand_path('../shared/length', __FILE__)
+require_relative '../../../spec_helper'
+require 'digest'
describe "Digest::SHA512#size" do
- it_behaves_like :sha512_length, :size
+ it "is an alias of Digest::SHA512#length" do
+ Digest::SHA512.instance_method(:size).should == Digest::SHA512.instance_method(:length)
+ end
end
-
diff --git a/spec/ruby/library/digest/sha512/to_s_spec.rb b/spec/ruby/library/digest/sha512/to_s_spec.rb
index b45f553e8c..68d86241c9 100644
--- a/spec/ruby/library/digest/sha512/to_s_spec.rb
+++ b/spec/ruby/library/digest/sha512/to_s_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/constants', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'shared/constants'
describe "Digest::SHA512#to_s" do
diff --git a/spec/ruby/library/digest/sha512/update_spec.rb b/spec/ruby/library/digest/sha512/update_spec.rb
index 3b82f51853..33edf216ac 100644
--- a/spec/ruby/library/digest/sha512/update_spec.rb
+++ b/spec/ruby/library/digest/sha512/update_spec.rb
@@ -1,7 +1,8 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/constants', __FILE__)
-require File.expand_path('../shared/update', __FILE__)
+require_relative '../../../spec_helper'
+require 'digest'
describe "Digest::SHA512#update" do
- it_behaves_like :sha512_update, :update
+ it "is an alias of Digest::SHA512#<<" do
+ Digest::SHA512.instance_method(:update).should == Digest::SHA512.instance_method(:<<)
+ end
end
diff --git a/spec/ruby/library/drb/start_service_spec.rb b/spec/ruby/library/drb/start_service_spec.rb
index f64021f0bd..57a8cf6e15 100644
--- a/spec/ruby/library/drb/start_service_spec.rb
+++ b/spec/ruby/library/drb/start_service_spec.rb
@@ -1,28 +1,33 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/test_server', __FILE__)
-require 'drb'
+require_relative '../../spec_helper'
-describe "DRb.start_service" do
- before :each do
- @server = DRb.start_service("druby://localhost:0", TestServer.new)
- end
+# This does not work yet when run in CRuby via make test-spec:
+# Gem::MissingSpecError: Could not find 'ruby2_keywords' (>= 0) among 28 total gem(s)
+guard_not -> { MSpecScript.instance_variable_defined?(:@testing_ruby) } do
+ require_relative 'fixtures/test_server'
+ require 'drb'
- after :each do
- DRb.stop_service if @server
- end
+ describe "DRb.start_service" do
+ before :each do
+ @server = DRb.start_service("druby://localhost:0", TestServer.new)
+ end
- it "runs a basic remote call" do
- DRb.current_server.should == @server
- obj = DRbObject.new(nil, @server.uri)
- obj.add(1,2,3).should == 6
- end
+ after :each do
+ DRb.stop_service if @server
+ end
+
+ it "runs a basic remote call" do
+ DRb.current_server.should == @server
+ obj = DRbObject.new(nil, @server.uri)
+ obj.add(1,2,3).should == 6
+ end
- it "runs a basic remote call passing a block" do
- DRb.current_server.should == @server
- obj = DRbObject.new(nil, @server.uri)
- obj.add_yield(2) do |i|
- i.should == 2
- i+1
- end.should == 4
+ it "runs a basic remote call passing a block" do
+ DRb.current_server.should == @server
+ obj = DRbObject.new(nil, @server.uri)
+ obj.add_yield(2) do |i|
+ i.should == 2
+ i+1
+ end.should == 4
+ end
end
end
diff --git a/spec/ruby/library/erb/def_class_spec.rb b/spec/ruby/library/erb/def_class_spec.rb
index ae2dcbd1e4..fb687531e0 100644
--- a/spec/ruby/library/erb/def_class_spec.rb
+++ b/spec/ruby/library/erb/def_class_spec.rb
@@ -1,5 +1,5 @@
require 'erb'
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "ERB#def_class" do
@@ -24,6 +24,8 @@ END
MyClass1ForErb = erb.def_class(MyClass1ForErb_, 'render()')
MyClass1ForErb.method_defined?(:render).should == true
MyClass1ForErb.new('foo', 123).render().should == expected
+ ensure
+ Object.send(:remove_const, :MyClass1ForErb)
end
end
diff --git a/spec/ruby/library/erb/def_method_spec.rb b/spec/ruby/library/erb/def_method_spec.rb
index e4ddedea4c..188789a693 100644
--- a/spec/ruby/library/erb/def_method_spec.rb
+++ b/spec/ruby/library/erb/def_method_spec.rb
@@ -1,5 +1,5 @@
require 'erb'
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "ERB#def_method" do
diff --git a/spec/ruby/library/erb/def_module_spec.rb b/spec/ruby/library/erb/def_module_spec.rb
index ed52fdfc15..5f67aeb2b9 100644
--- a/spec/ruby/library/erb/def_module_spec.rb
+++ b/spec/ruby/library/erb/def_module_spec.rb
@@ -1,5 +1,5 @@
require 'erb'
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "ERB#def_module" do
@@ -22,6 +22,9 @@ END
include MyModule2ForErb
end
MyClass2ForErb.new.render('foo', 123).should == expected
+ ensure
+ Object.send(:remove_const, :MyClass2ForErb)
+ Object.send(:remove_const, :MyModule2ForErb)
end
end
diff --git a/spec/ruby/library/erb/defmethod/def_erb_method_spec.rb b/spec/ruby/library/erb/defmethod/def_erb_method_spec.rb
index e1eca2fbef..1cd7582936 100644
--- a/spec/ruby/library/erb/defmethod/def_erb_method_spec.rb
+++ b/spec/ruby/library/erb/defmethod/def_erb_method_spec.rb
@@ -1,5 +1,6 @@
require 'erb'
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../fixtures/classes'
describe "ERB::DefMethod.def_erb_method" do
@@ -50,13 +51,15 @@ END
MY_INPUT4_FOR_ERB = input
class MyClass4ForErb
extend ERB::DefMethod
- erb = ERB.new(MY_INPUT4_FOR_ERB, nil, '<>')
+ erb = ERBSpecs.new_erb(MY_INPUT4_FOR_ERB, trim_mode: '<>')
def_erb_method('render()', erb)
def initialize(items)
@items = items
end
end
MyClass4ForErb.new([10,20,30]).render().should == expected
+ ensure
+ Object.send(:remove_const, :MY_INPUT4_FOR_ERB)
end
diff --git a/spec/ruby/library/erb/filename_spec.rb b/spec/ruby/library/erb/filename_spec.rb
index 4615f5d808..bbd2233bb3 100644
--- a/spec/ruby/library/erb/filename_spec.rb
+++ b/spec/ruby/library/erb/filename_spec.rb
@@ -1,19 +1,19 @@
require 'erb'
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "ERB#filename" do
it "raises an exception if there are errors processing content" do
filename = 'foobar.rhtml'
erb = ERB.new('<% if true %>') # will raise SyntaxError
erb.filename = filename
- lambda {
+ -> {
begin
erb.result(binding)
rescue Exception => e
@ex = e
raise e
end
- }.should raise_error(SyntaxError)
+ }.should.raise(SyntaxError)
expected = filename
@ex.message =~ /^(.*?):(\d+): /
@@ -23,14 +23,14 @@ describe "ERB#filename" do
it "uses '(erb)' as filename when filename is not set" do
erb = ERB.new('<% if true %>') # will raise SyntaxError
- lambda {
+ -> {
begin
erb.result(binding)
rescue Exception => e
@ex = e
raise e
end
- }.should raise_error(SyntaxError)
+ }.should.raise(SyntaxError)
expected = '(erb)'
@ex.message =~ /^(.*?):(\d+): /
diff --git a/spec/ruby/library/erb/fixtures/classes.rb b/spec/ruby/library/erb/fixtures/classes.rb
new file mode 100644
index 0000000000..e07a6ed68d
--- /dev/null
+++ b/spec/ruby/library/erb/fixtures/classes.rb
@@ -0,0 +1,5 @@
+module ERBSpecs
+ def self.new_erb(input, trim_mode: nil)
+ ERB.new(input, trim_mode: trim_mode)
+ end
+end
diff --git a/spec/ruby/library/erb/new_spec.rb b/spec/ruby/library/erb/new_spec.rb
index 917fd470b7..35ac0dfdfe 100644
--- a/spec/ruby/library/erb/new_spec.rb
+++ b/spec/ruby/library/erb/new_spec.rb
@@ -1,5 +1,6 @@
require 'erb'
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "ERB.new" do
before :all do
@@ -30,22 +31,28 @@ END
it "compiles eRuby script into ruby code when trim mode is 0 or not specified" do
expected = "<ul>\n\n\n\n<li>1</li>\n\n\n\n<li>2</li>\n\n\n\n<li>3</li>\n\n\n</ul>\n"
- [0, '', nil].each do |trim_mode|
- ERB.new(@eruby_str, nil, trim_mode).result.should == expected
+ [0, nil].each do |trim_mode|
+ ERBSpecs.new_erb(@eruby_str, trim_mode: trim_mode).result.should == expected
end
end
+ it "warns invalid trim_mode" do
+ -> do
+ ERBSpecs.new_erb(@eruby_str, trim_mode: '')
+ end.should complain(/Invalid ERB trim mode/)
+ end
+
it "removes '\n' when trim_mode is 1 or '>'" do
expected = "<ul>\n<li>1</li>\n<li>2</li>\n<li>3</li>\n</ul>\n"
[1, '>'].each do |trim_mode|
- ERB.new(@eruby_str, nil, trim_mode).result.should == expected
+ ERBSpecs.new_erb(@eruby_str, trim_mode: trim_mode).result.should == expected
end
end
it "removes spaces at beginning of line and '\n' when trim_mode is 2 or '<>'" do
expected = "<ul>\n<li>1</li>\n<li>2</li>\n<li>3</li>\n</ul>\n"
[2, '<>'].each do |trim_mode|
- ERB.new(@eruby_str, nil, trim_mode).result.should == expected
+ ERBSpecs.new_erb(@eruby_str, trim_mode: trim_mode).result.should == expected
end
end
@@ -61,11 +68,11 @@ END
</ul>
END
- ERB.new(input, nil, '-').result.should == expected
+ ERBSpecs.new_erb(input, trim_mode: '-').result.should == expected
end
- it "not support '<%-= expr %> even when trim_mode is '-'" do
+ it "does not support '<%-= expr %> even when trim_mode is '-'" do
input = <<'END'
<p>
@@ -74,22 +81,24 @@ END
</p>
END
- lambda { ERB.new(input, nil, '-').result }.should raise_error
+ -> {
+ ERBSpecs.new_erb(input, trim_mode: '-').result
+ }.should.raise(SyntaxError)
end
it "regards lines starting with '%' as '<% ... %>' when trim_mode is '%'" do
expected = "<ul>\n <li>1\n \n <li>2\n \n <li>3\n \n\n</ul>\n%%\n"
- ERB.new(@eruby_str2, nil, "%").result.should == expected
+ ERBSpecs.new_erb(@eruby_str2, trim_mode: "%").result.should == expected
end
it "regards lines starting with '%' as '<% ... %>' and remove \"\\n\" when trim_mode is '%>'" do
expected = "<ul>\n <li>1 <li>2 <li>3 </ul>\n%%\n"
- ERB.new(@eruby_str2, nil, '%>').result.should == expected
+ ERBSpecs.new_erb(@eruby_str2, trim_mode: '%>').result.should == expected
end
it "regard lines starting with '%' as '<% ... %>' and remove \"\\n\" when trim_mode is '%<>'" do
expected = "<ul>\n <li>1\n \n <li>2\n \n <li>3\n \n</ul>\n%%\n"
- ERB.new(@eruby_str2, nil, '%<>').result.should == expected
+ ERBSpecs.new_erb(@eruby_str2, trim_mode: '%<>').result.should == expected
end
@@ -104,13 +113,13 @@ END
%%%
END
- ERB.new(input, nil, '%-').result.should == expected
+ ERBSpecs.new_erb(input, trim_mode: '%-').result.should == expected
end
it "changes '_erbout' variable name in the produced source" do
input = @eruby_str
- match_erbout = ERB.new(input, nil, nil).src
- match_buf = ERB.new(input, nil, nil, 'buf').src
+ match_erbout = ERB.new(input, trim_mode: nil).src
+ match_buf = ERB.new(input, trim_mode: nil, eoutvar: 'buf').src
match_erbout.gsub("_erbout", "buf").should == match_buf
end
@@ -121,12 +130,28 @@ END
<b><%#= item %></b>
<%# end %>
END
- ERB.new(input).result.should == "\n<b></b>\n\n"
- ERB.new(input, nil, '<>').result.should == "<b></b>\n"
+ ERBSpecs.new_erb(input).result.should == "\n<b></b>\n\n"
+ ERBSpecs.new_erb(input, trim_mode: '<>').result.should == "<b></b>\n"
end
it "forget local variables defined previous one" do
ERB.new(@eruby_str).result
- lambda{ ERB.new("<%= list %>").result }.should raise_error(NameError)
+ ->{ ERB.new("<%= list %>").result }.should.raise(NameError)
+ end
+
+ version_is ERB.const_get(:VERSION, false), ""..."6.0.0" do
+ describe "warning about arguments" do
+ it "warns when passed safe_level and later arguments" do
+ -> {
+ ERB.new(@eruby_str, nil, '%')
+ }.should complain(/warning: Passing safe_level with the 2nd argument of ERB.new is deprecated. Do not use it, and specify other arguments as keyword arguments./)
+ end
+
+ it "does not warn when passed arguments as keyword argument" do
+ -> {
+ ERB.new(@eruby_str, trim_mode: '%')
+ }.should_not complain(/warning: Passing safe_level with the 2nd argument of ERB.new is deprecated. Do not use it, and specify other arguments as keyword arguments./)
+ end
+ end
end
end
diff --git a/spec/ruby/library/erb/result_spec.rb b/spec/ruby/library/erb/result_spec.rb
index d79584b221..84333031ec 100644
--- a/spec/ruby/library/erb/result_spec.rb
+++ b/spec/ruby/library/erb/result_spec.rb
@@ -1,5 +1,5 @@
require 'erb'
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "ERB#result" do
@@ -41,9 +41,9 @@ END
it "is not able to h() or u() unless including ERB::Util" do
input = "<%=h '<>' %>"
- lambda {
+ -> {
ERB.new(input).result()
- }.should raise_error(NameError)
+ }.should.raise(NameError)
end
@@ -79,8 +79,8 @@ END
expected = '123'
myerb2.new.main1().should == expected
- lambda {
+ -> {
myerb2.new.main2()
- }.should raise_error(NameError)
+ }.should.raise(NameError)
end
end
diff --git a/spec/ruby/library/erb/run_spec.rb b/spec/ruby/library/erb/run_spec.rb
index 6ad3808a16..d81d534087 100644
--- a/spec/ruby/library/erb/run_spec.rb
+++ b/spec/ruby/library/erb/run_spec.rb
@@ -1,12 +1,12 @@
require 'erb'
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "ERB#run" do
# TODO: what is this? why does it not use
# lambda { ... }.should output
def _steal_stdout
orig = $stdout
- s = ''
+ s = +''
def s.write(arg); self << arg.to_s; end
$stdout = s
begin
@@ -52,9 +52,9 @@ END
it "is not able to h() or u() unless including ERB::Util" do
input = "<%=h '<>' %>"
- lambda {
+ -> {
_steal_stdout { ERB.new(input).run() }
- }.should raise_error(NameError)
+ }.should.raise(NameError)
end
it "is able to h() or u() if ERB::Util is included" do
@@ -89,9 +89,8 @@ END
actual = _steal_stdout { myerb2.new.main1() }
actual.should == expected
- lambda {
+ -> {
_steal_stdout { myerb2.new.main2() }
- }.should raise_error(NameError)
+ }.should.raise(NameError)
end
end
-
diff --git a/spec/ruby/library/erb/src_spec.rb b/spec/ruby/library/erb/src_spec.rb
index cf5b67dcbf..fc11b7e4b7 100644
--- a/spec/ruby/library/erb/src_spec.rb
+++ b/spec/ruby/library/erb/src_spec.rb
@@ -1,5 +1,5 @@
require 'erb'
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
describe "ERB#src" do
diff --git a/spec/ruby/library/erb/util/h_spec.rb b/spec/ruby/library/erb/util/h_spec.rb
index ba36574433..6de79cfd92 100644
--- a/spec/ruby/library/erb/util/h_spec.rb
+++ b/spec/ruby/library/erb/util/h_spec.rb
@@ -1,6 +1,6 @@
require 'erb'
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/html_escape', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'shared/html_escape'
describe "ERB::Util.h" do
it_behaves_like :erb_util_html_escape, :h
diff --git a/spec/ruby/library/erb/util/html_escape_spec.rb b/spec/ruby/library/erb/util/html_escape_spec.rb
index 9bc9359f2c..1c15fb8791 100644
--- a/spec/ruby/library/erb/util/html_escape_spec.rb
+++ b/spec/ruby/library/erb/util/html_escape_spec.rb
@@ -1,8 +1,7 @@
require 'erb'
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/html_escape', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'shared/html_escape'
describe "ERB::Util.html_escape" do
it_behaves_like :erb_util_html_escape, :html_escape
end
-
diff --git a/spec/ruby/library/erb/util/shared/url_encode.rb b/spec/ruby/library/erb/util/shared/url_encode.rb
index 5ac6215523..34009c4903 100644
--- a/spec/ruby/library/erb/util/shared/url_encode.rb
+++ b/spec/ruby/library/erb/util/shared/url_encode.rb
@@ -6,21 +6,13 @@ describe :erb_util_url_encode, shared: true do
ERB::Util.__send__(@method, input).should == expected
end
- ruby_version_is ""..."2.5" do
- it "escapes tilde" do
- ERB::Util.__send__(@method, "~").should == "%7E"
- end
- end
-
- ruby_version_is "2.5" do
- it "does not escape tilde" do
- ERB::Util.__send__(@method, "~").should == "~"
- end
+ it "does not escape tilde" do
+ ERB::Util.__send__(@method, "~").should == "~"
end
it "encode unicode string" do
- input = "http://ja.wikipedia.org/wiki/\343\203\255\343\203\240\343\202\271\343\202\253\343\203\273\343\203\221\343\203\255\343\203\273\343\202\246\343\203\253\343\203\273\343\203\251\343\203\224\343\203\245\343\202\277"
- expected = 'http%3A%2F%2Fja.wikipedia.org%2Fwiki%2F%E3%83%AD%E3%83%A0%E3%82%B9%E3%82%AB%E3%83%BB%E3%83%91%E3%83%AD%E3%83%BB%E3%82%A6%E3%83%AB%E3%83%BB%E3%83%A9%E3%83%94%E3%83%A5%E3%82%BF'
+ input = "https://ja.wikipedia.org/wiki/\343\203\255\343\203\240\343\202\271\343\202\253\343\203\273\343\203\221\343\203\255\343\203\273\343\202\246\343\203\253\343\203\273\343\203\251\343\203\224\343\203\245\343\202\277"
+ expected = 'https%3A%2F%2Fja.wikipedia.org%2Fwiki%2F%E3%83%AD%E3%83%A0%E3%82%B9%E3%82%AB%E3%83%BB%E3%83%91%E3%83%AD%E3%83%BB%E3%82%A6%E3%83%AB%E3%83%BB%E3%83%A9%E3%83%94%E3%83%A5%E3%82%BF'
ERB::Util.__send__(@method, input).should == expected
end
diff --git a/spec/ruby/library/erb/util/u_spec.rb b/spec/ruby/library/erb/util/u_spec.rb
index 9200244c8e..2a08451031 100644
--- a/spec/ruby/library/erb/util/u_spec.rb
+++ b/spec/ruby/library/erb/util/u_spec.rb
@@ -1,8 +1,7 @@
require 'erb'
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/url_encode', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'shared/url_encode'
describe "ERB::Util.u" do
it_behaves_like :erb_util_url_encode, :u
end
-
diff --git a/spec/ruby/library/erb/util/url_encode_spec.rb b/spec/ruby/library/erb/util/url_encode_spec.rb
index 303a2e3cd7..5569a1cc64 100644
--- a/spec/ruby/library/erb/util/url_encode_spec.rb
+++ b/spec/ruby/library/erb/util/url_encode_spec.rb
@@ -1,6 +1,6 @@
require 'erb'
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../shared/url_encode', __FILE__)
+require_relative '../../../spec_helper'
+require_relative 'shared/url_encode'
describe "ERB::Util.url_encode" do
it_behaves_like :erb_util_url_encode, :url_encode
diff --git a/spec/ruby/library/etc/confstr_spec.rb b/spec/ruby/library/etc/confstr_spec.rb
new file mode 100644
index 0000000000..786cb16407
--- /dev/null
+++ b/spec/ruby/library/etc/confstr_spec.rb
@@ -0,0 +1,14 @@
+require_relative '../../spec_helper'
+require 'etc'
+
+platform_is_not :windows, :android do
+ describe "Etc.confstr" do
+ it "returns a String for Etc::CS_PATH" do
+ Etc.confstr(Etc::CS_PATH).should.instance_of?(String)
+ end
+
+ it "raises Errno::EINVAL for unknown configuration variables" do
+ -> { Etc.confstr(-1) }.should.raise(Errno::EINVAL)
+ end
+ end
+end
diff --git a/spec/ruby/library/etc/endgrent_spec.rb b/spec/ruby/library/etc/endgrent_spec.rb
index 95f0dc05e3..88de231d87 100644
--- a/spec/ruby/library/etc/endgrent_spec.rb
+++ b/spec/ruby/library/etc/endgrent_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/windows', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/windows'
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..e4e564d251 100644
--- a/spec/ruby/library/etc/endpwent_spec.rb
+++ b/spec/ruby/library/etc/endpwent_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/windows', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/windows'
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..45a4442262 100644
--- a/spec/ruby/library/etc/getgrent_spec.rb
+++ b/spec/ruby/library/etc/getgrent_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/windows', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/windows'
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/getgrgid_spec.rb b/spec/ruby/library/etc/getgrgid_spec.rb
index 9b6b283d52..472d4c82c8 100644
--- a/spec/ruby/library/etc/getgrgid_spec.rb
+++ b/spec/ruby/library/etc/getgrgid_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'etc'
platform_is :windows do
@@ -13,58 +13,57 @@ end
# TODO: verify these on non-windows, non-darwin OS
platform_is_not :windows do
- describe "Etc.getgrgid" do
- before :all do
- @gid = `id -g`.strip.to_i
- @name = `id -gn`.strip
- end
+ grpname = nil
+ guard -> {
+ grpname = IO.popen(%w'id -gn', err: IO::NULL, &:read).chomp
+ $?.success?
+ } do
+ describe "Etc.getgrgid" do
+ before :all do
+ @gid = `id -g`.strip.to_i
+ @name = grpname
+ end
- it "returns a Etc::Group struct instance for the given user" do
- gr = Etc.getgrgid(@gid)
+ it "returns a Etc::Group struct instance for the given user" do
+ gr = Etc.getgrgid(@gid)
- gr.is_a?(Etc::Group).should == true
- gr.gid.should == @gid
- gr.name.should == @name
- end
+ gr.is_a?(Etc::Group).should == true
+ gr.gid.should == @gid
+ gr.name.should == @name
+ end
- it "returns the Etc::Group for a given gid if it exists" do
- grp = Etc.getgrgid(@gid)
- grp.should be_kind_of(Etc::Group)
- grp.gid.should == @gid
- grp.name.should == @name
- end
+ it "returns the Etc::Group for a given gid if it exists" do
+ grp = Etc.getgrgid(@gid)
+ grp.should.is_a?(Etc::Group)
+ grp.gid.should == @gid
+ grp.name.should == @name
+ end
- it "uses Process.gid as the default value for the argument" do
- gr = Etc.getgrgid
+ it "uses Process.gid as the default value for the argument" do
+ gr = Etc.getgrgid
- gr.gid.should == @gid
- gr.name.should == @name
- end
+ gr.gid.should == @gid
+ gr.name.should == @name
+ end
- it "returns the Group for a given gid if it exists" do
- grp = Etc.getgrgid(@gid)
- grp.should be_kind_of(Struct::Group)
- grp.gid.should == @gid
- grp.name.should == @name
- end
-
- it "raises if the group does not exist" do
- lambda { Etc.getgrgid(9876)}.should raise_error(ArgumentError)
- end
+ it "raises if the group does not exist" do
+ -> { Etc.getgrgid(9876)}.should.raise(ArgumentError)
+ end
- it "raises a TypeError if not passed an Integer" do
- lambda { Etc.getgrgid("foo") }.should raise_error(TypeError)
- lambda { Etc.getgrgid(nil) }.should raise_error(TypeError)
- end
+ it "raises a TypeError if not passed an Integer" do
+ -> { Etc.getgrgid("foo") }.should.raise(TypeError)
+ -> { Etc.getgrgid(nil) }.should.raise(TypeError)
+ end
- it "can be called safely by multiple threads" do
- 20.times.map do
- Thread.new do
- 100.times do
- Etc.getgrgid(@gid).gid.should == @gid
+ it "can be called safely by multiple threads" do
+ 20.times.map do
+ Thread.new do
+ 100.times do
+ Etc.getgrgid(@gid).gid.should == @gid
+ end
end
- end
- end.each(&:join)
+ end.each(&:join)
+ end
end
end
end
diff --git a/spec/ruby/library/etc/getgrnam_spec.rb b/spec/ruby/library/etc/getgrnam_spec.rb
index 46193f49d6..325ea7b297 100644
--- a/spec/ruby/library/etc/getgrnam_spec.rb
+++ b/spec/ruby/library/etc/getgrnam_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'etc'
platform_is :windows do
@@ -11,7 +11,7 @@ platform_is :windows do
end
end
-platform_is_not :windows do
+platform_is_not :windows, :android do
describe "Etc.getgrnam" do
it "returns a Etc::Group struct instance for the given group" do
gr_name = Etc.getgrent.name
@@ -21,10 +21,10 @@ platform_is_not :windows do
end
it "only accepts strings as argument" do
- lambda {
+ -> {
Etc.getgrnam(123)
Etc.getgrnam(nil)
- }.should raise_error(TypeError)
+ }.should.raise(TypeError)
end
end
end
diff --git a/spec/ruby/library/etc/getlogin_spec.rb b/spec/ruby/library/etc/getlogin_spec.rb
index 43e654bda6..2bc598c0af 100644
--- a/spec/ruby/library/etc/getlogin_spec.rb
+++ b/spec/ruby/library/etc/getlogin_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'etc'
describe "Etc.getlogin" do
@@ -14,16 +14,21 @@ describe "Etc.getlogin" do
if ENV['TRAVIS'] and platform_is(:darwin)
# See https://travis-ci.org/ruby/spec/jobs/285967744
# and https://travis-ci.org/ruby/spec/jobs/285999602
- Etc.getlogin.should be_an_instance_of(String)
+ Etc.getlogin.should.instance_of?(String)
else
# Etc.getlogin returns the same result of logname(2)
# if it returns non NULL
- Etc.getlogin.should == `id -un`.chomp
+ if system("which logname", out: File::NULL, err: File::NULL)
+ Etc.getlogin.should == `logname`.chomp
+ else
+ # fallback to `id` command since `logname` is not available
+ Etc.getlogin.should == `id -un`.chomp
+ end
end
else
# Etc.getlogin may return nil if the login name is not set
# because of chroot or sudo or something.
- Etc.getlogin.should be_nil
+ Etc.getlogin.should == nil
getlogin_null = true
end
ensure
diff --git a/spec/ruby/library/etc/getpwent_spec.rb b/spec/ruby/library/etc/getpwent_spec.rb
index 1c8057c9e5..9a911aed8f 100644
--- a/spec/ruby/library/etc/getpwent_spec.rb
+++ b/spec/ruby/library/etc/getpwent_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/windows', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/windows'
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/getpwnam_spec.rb b/spec/ruby/library/etc/getpwnam_spec.rb
index 8610b5da91..a0b3c9e1fe 100644
--- a/spec/ruby/library/etc/getpwnam_spec.rb
+++ b/spec/ruby/library/etc/getpwnam_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'etc'
platform_is :windows do
@@ -19,10 +19,10 @@ platform_is_not :windows do
end
it "only accepts strings as argument" do
- lambda {
+ -> {
Etc.getpwnam(123)
Etc.getpwnam(nil)
- }.should raise_error(TypeError)
+ }.should.raise(TypeError)
end
end
end
diff --git a/spec/ruby/library/etc/getpwuid_spec.rb b/spec/ruby/library/etc/getpwuid_spec.rb
index f1c7218c0b..3e35dfe6d5 100644
--- a/spec/ruby/library/etc/getpwuid_spec.rb
+++ b/spec/ruby/library/etc/getpwuid_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'etc'
platform_is :windows do
@@ -27,10 +27,10 @@ platform_is_not :windows do
end
it "only accepts integers as argument" do
- lambda {
+ -> {
Etc.getpwuid("foo")
Etc.getpwuid(nil)
- }.should raise_error(TypeError)
+ }.should.raise(TypeError)
end
end
end
diff --git a/spec/ruby/library/etc/group_spec.rb b/spec/ruby/library/etc/group_spec.rb
index 8b92cb7bf0..d7addbbec1 100644
--- a/spec/ruby/library/etc/group_spec.rb
+++ b/spec/ruby/library/etc/group_spec.rb
@@ -1,18 +1,27 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/windows', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/windows'
require 'etc'
describe "Etc.group" do
- it_behaves_like(:etc_on_windows, :group)
+ it_behaves_like :etc_on_windows, :group
+
+ platform_is_not :windows, :android do
+ it "returns a Etc::Group struct" do
+ group = Etc.group
+ begin
+ group.should.instance_of?(Etc::Group)
+ ensure
+ Etc.endgrent
+ end
+ end
- platform_is_not :windows do
it "raises a RuntimeError for parallel iteration" do
proc {
Etc.group do | group |
Etc.group do | group2 |
end
end
- }.should raise_error(RuntimeError)
+ }.should.raise(RuntimeError)
end
end
end
diff --git a/spec/ruby/library/etc/nprocessors_spec.rb b/spec/ruby/library/etc/nprocessors_spec.rb
index bce11d06c5..482719dde0 100644
--- a/spec/ruby/library/etc/nprocessors_spec.rb
+++ b/spec/ruby/library/etc/nprocessors_spec.rb
@@ -1,11 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'etc'
-ruby_version_is "2.2" do
- describe "Etc.nprocessors" do
- it "returns the number of online processors" do
- Etc.nprocessors.should be_kind_of(Integer)
- Etc.nprocessors.should >= 1
- end
+describe "Etc.nprocessors" do
+ it "returns the number of online processors" do
+ Etc.nprocessors.should.is_a?(Integer)
+ Etc.nprocessors.should >= 1
end
end
diff --git a/spec/ruby/library/etc/passwd_spec.rb b/spec/ruby/library/etc/passwd_spec.rb
new file mode 100644
index 0000000000..0602b7e10b
--- /dev/null
+++ b/spec/ruby/library/etc/passwd_spec.rb
@@ -0,0 +1,15 @@
+require_relative '../../spec_helper'
+require 'etc'
+
+platform_is_not :windows do
+ describe "Etc.passwd" do
+ it "returns a Etc::Passwd struct" do
+ passwd = Etc.passwd
+ begin
+ passwd.should.instance_of?(Etc::Passwd)
+ ensure
+ Etc.endpwent
+ end
+ end
+ end
+end
diff --git a/spec/ruby/library/etc/struct_group_spec.rb b/spec/ruby/library/etc/struct_group_spec.rb
index c33a177a98..b2147e306d 100644
--- a/spec/ruby/library/etc/struct_group_spec.rb
+++ b/spec/ruby/library/etc/struct_group_spec.rb
@@ -1,14 +1,18 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'etc'
-describe "Struct::Group" do
+describe "Etc::Group" do
platform_is_not :windows do
+ grpname = IO.popen(%w'id -gn', err: IO::NULL, &:read)
+ next unless $?.success?
+ grpname.chomp!
+
before :all do
@g = Etc.getgrgid(`id -g`.strip.to_i)
end
it "returns group name" do
- @g.name.should == `id -gn`.strip
+ @g.name.should == grpname
end
it "returns group password" do
diff --git a/spec/ruby/library/etc/struct_passwd_spec.rb b/spec/ruby/library/etc/struct_passwd_spec.rb
index 3e4bfee828..dc37c17e7d 100644
--- a/spec/ruby/library/etc/struct_passwd_spec.rb
+++ b/spec/ruby/library/etc/struct_passwd_spec.rb
@@ -1,7 +1,7 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'etc'
-describe "Struct::Passwd" do
+describe "Etc::Passwd" do
platform_is_not :windows do
before :all do
@pw = Etc.getpwuid(`id -u`.strip.to_i)
diff --git a/spec/ruby/library/etc/sysconf_spec.rb b/spec/ruby/library/etc/sysconf_spec.rb
new file mode 100644
index 0000000000..81ce1ca258
--- /dev/null
+++ b/spec/ruby/library/etc/sysconf_spec.rb
@@ -0,0 +1,22 @@
+require_relative '../../spec_helper'
+require 'etc'
+
+platform_is_not :windows do
+ describe "Etc.sysconf" do
+ %w[
+ SC_ARG_MAX SC_CHILD_MAX SC_HOST_NAME_MAX SC_LOGIN_NAME_MAX SC_NGROUPS_MAX
+ SC_CLK_TCK SC_OPEN_MAX SC_PAGESIZE SC_RE_DUP_MAX SC_STREAM_MAX
+ SC_SYMLOOP_MAX SC_TTY_NAME_MAX SC_TZNAME_MAX SC_VERSION
+ ].each do |const|
+ it "returns the value of POSIX.1 system configuration variable #{const}" do
+ var = Etc.const_get(const)
+ value = Etc.sysconf(var)
+ if value.nil?
+ value.should == nil
+ else
+ value.should.is_a?(Integer)
+ end
+ end
+ end
+ end
+end
diff --git a/spec/ruby/library/etc/sysconfdir_spec.rb b/spec/ruby/library/etc/sysconfdir_spec.rb
new file mode 100644
index 0000000000..eb2d6b649a
--- /dev/null
+++ b/spec/ruby/library/etc/sysconfdir_spec.rb
@@ -0,0 +1,8 @@
+require_relative '../../spec_helper'
+require 'etc'
+
+describe "Etc.sysconfdir" do
+ it "returns a String" do
+ Etc.sysconfdir.should.instance_of?(String)
+ end
+end
diff --git a/spec/ruby/library/etc/systmpdir_spec.rb b/spec/ruby/library/etc/systmpdir_spec.rb
new file mode 100644
index 0000000000..ed34cb43fc
--- /dev/null
+++ b/spec/ruby/library/etc/systmpdir_spec.rb
@@ -0,0 +1,8 @@
+require_relative '../../spec_helper'
+require 'etc'
+
+describe "Etc.systmpdir" do
+ it "returns a String" do
+ Etc.systmpdir.should.instance_of?(String)
+ end
+end
diff --git a/spec/ruby/library/etc/uname_spec.rb b/spec/ruby/library/etc/uname_spec.rb
new file mode 100644
index 0000000000..1c5fe2a741
--- /dev/null
+++ b/spec/ruby/library/etc/uname_spec.rb
@@ -0,0 +1,14 @@
+require_relative '../../spec_helper'
+require 'etc'
+
+describe "Etc.uname" do
+ it "returns a Hash with the documented keys" do
+ uname = Etc.uname
+ uname.should.is_a?(Hash)
+ uname.should.key?(:sysname)
+ uname.should.key?(:nodename)
+ uname.should.key?(:release)
+ uname.should.key?(:version)
+ uname.should.key?(:machine)
+ end
+end
diff --git a/spec/ruby/library/expect/expect_spec.rb b/spec/ruby/library/expect/expect_spec.rb
index 080f3d7af4..ba705c5535 100644
--- a/spec/ruby/library/expect/expect_spec.rb
+++ b/spec/ruby/library/expect/expect_spec.rb
@@ -1,5 +1,6 @@
+require_relative '../../spec_helper'
+
platform_is_not :windows do
- require File.expand_path('../../../spec_helper', __FILE__)
require 'expect'
describe "IO#expect" do
@@ -37,16 +38,16 @@ platform_is_not :windows do
@write << "prompt> hello"
@read.close
- lambda {
+ -> {
@read.expect("hello")
- }.should raise_error(IOError)
+ }.should.raise(IOError)
end
it "returns nil if eof is hit" do
@write << "pro"
@write.close
- @read.expect("prompt").should be_nil
+ @read.expect("prompt").should == nil
end
it "yields the result if a block is given" do
diff --git a/spec/ruby/library/fiber/alive_spec.rb b/spec/ruby/library/fiber/alive_spec.rb
deleted file mode 100644
index fbd5c4bc1a..0000000000
--- a/spec/ruby/library/fiber/alive_spec.rb
+++ /dev/null
@@ -1,48 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-with_feature :fiber_library do
- require 'fiber'
-
- describe "Fiber#alive?" do
- it "returns true for a Fiber that hasn't had #resume called" do
- fiber = Fiber.new { true }
- fiber.alive?.should be_true
- end
-
- # FIXME: Better description?
- it "returns true for a Fiber that's yielded to the caller" do
- fiber = Fiber.new { Fiber.yield }
- fiber.resume
- fiber.alive?.should be_true
- end
-
- it "returns true when called from its Fiber" do
- fiber = Fiber.new { fiber.alive?.should be_true }
- fiber.resume
- end
-
- it "doesn't invoke the block associated with the Fiber" do
- offthehook = mock('do not call')
- offthehook.should_not_receive(:ring)
- fiber = Fiber.new { offthehook.ring }
- fiber.alive?
- end
-
- it "returns false for a Fiber that's dead" do
- fiber = Fiber.new { true }
- fiber.resume
- lambda { fiber.resume }.should raise_error(FiberError)
- fiber.alive?.should be_false
- end
-
- it "always returns false for a dead Fiber" do
- fiber = Fiber.new { true }
- fiber.resume
- lambda { fiber.resume }.should raise_error(FiberError)
- fiber.alive?.should be_false
- lambda { fiber.resume }.should raise_error(FiberError)
- fiber.alive?.should be_false
- fiber.alive?.should be_false
- end
- end
-end
diff --git a/spec/ruby/library/fiber/current_spec.rb b/spec/ruby/library/fiber/current_spec.rb
deleted file mode 100644
index fd68cd52ea..0000000000
--- a/spec/ruby/library/fiber/current_spec.rb
+++ /dev/null
@@ -1,53 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-with_feature :fiber_library do
- require 'fiber'
-
- describe "Fiber.current" do
- it "returns the root Fiber when called outside of a Fiber" do
- root = Fiber.current
- root.should be_an_instance_of(Fiber)
- # We can always transfer to the root Fiber; it will never die
- 5.times do
- root.transfer.should be_nil
- root.alive?.should be_true
- end
- end
-
- it "returns the current Fiber when called from a Fiber" do
- fiber = Fiber.new do
- this = Fiber.current
- this.should be_an_instance_of(Fiber)
- this.should == fiber
- this.alive?.should be_true
- end
- fiber.resume
- end
-
- it "returns the current Fiber when called from a Fiber that transferred to another" do
- states = []
- fiber = Fiber.new do
- states << :fiber
- this = Fiber.current
- this.should be_an_instance_of(Fiber)
- this.should == fiber
- this.alive?.should be_true
- end
-
- fiber2 = Fiber.new do
- states << :fiber2
- fiber.transfer
- flunk
- end
-
- fiber3 = Fiber.new do
- states << :fiber3
- fiber2.transfer
- flunk
- end
-
- fiber3.resume
- states.should == [:fiber3, :fiber2, :fiber]
- end
- end
-end
diff --git a/spec/ruby/library/fiber/resume_spec.rb b/spec/ruby/library/fiber/resume_spec.rb
deleted file mode 100644
index 389757b7bd..0000000000
--- a/spec/ruby/library/fiber/resume_spec.rb
+++ /dev/null
@@ -1,14 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-
-with_feature :fiber_library do
- require 'fiber'
-
- describe "Fiber#resume" do
- it "raises a FiberError if the Fiber has transferred control to another Fiber" do
- fiber1 = Fiber.new { true }
- fiber2 = Fiber.new { fiber1.transfer; Fiber.yield }
- fiber2.resume
- lambda { fiber2.resume }.should raise_error(FiberError)
- end
- end
-end
diff --git a/spec/ruby/library/fiber/transfer_spec.rb b/spec/ruby/library/fiber/transfer_spec.rb
deleted file mode 100644
index ad501c1d74..0000000000
--- a/spec/ruby/library/fiber/transfer_spec.rb
+++ /dev/null
@@ -1,51 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../../../shared/fiber/resume', __FILE__)
-
-with_feature :fiber_library do
- require 'fiber'
-
- describe "Fiber#transfer" do
- it_behaves_like :fiber_resume, :transfer
- end
-
- describe "Fiber#transfer" do
- it "transfers control from one Fiber to another when called from a Fiber" do
- fiber1 = Fiber.new { :fiber1 }
- fiber2 = Fiber.new { fiber1.transfer; :fiber2 }
- fiber2.resume.should == :fiber1
- end
-
- it "returns to the root Fiber when finished" do
- f1 = Fiber.new { :fiber_1 }
- f2 = Fiber.new { f1.transfer; :fiber_2 }
-
- f2.transfer.should == :fiber_1
- f2.transfer.should == :fiber_2
- end
-
- it "can be invoked from the same Fiber it transfers control to" do
- states = []
- fiber = Fiber.new { states << :start; fiber.transfer; states << :end }
- fiber.transfer
- states.should == [:start, :end]
-
- states = []
- fiber = Fiber.new { states << :start; fiber.transfer; states << :end }
- fiber.resume
- states.should == [:start, :end]
- end
-
- it "can transfer control to a Fiber that has transferred to another Fiber" do
- states = []
- fiber1 = Fiber.new { states << :fiber1 }
- fiber2 = Fiber.new { states << :fiber2_start; fiber1.transfer; states << :fiber2_end}
- fiber2.resume.should == [:fiber2_start, :fiber1]
- fiber2.transfer.should == [:fiber2_start, :fiber1, :fiber2_end]
- end
-
- it "raises a FiberError when transferring to a Fiber which resumes itself" do
- fiber = Fiber.new { fiber.resume }
- lambda { fiber.transfer }.should raise_error(FiberError)
- end
- end
-end
diff --git a/spec/ruby/library/fiddle/handle/initialize_spec.rb b/spec/ruby/library/fiddle/handle/initialize_spec.rb
new file mode 100644
index 0000000000..84c809a727
--- /dev/null
+++ b/spec/ruby/library/fiddle/handle/initialize_spec.rb
@@ -0,0 +1,10 @@
+require_relative '../../../spec_helper'
+require 'fiddle'
+
+describe "Fiddle::Handle#initialize" do
+ it "raises Fiddle::DLError if the library cannot be found" do
+ -> {
+ Fiddle::Handle.new("doesnotexist.doesnotexist")
+ }.should.raise(Fiddle::DLError)
+ end
+end
diff --git a/spec/ruby/library/find/find_spec.rb b/spec/ruby/library/find/find_spec.rb
index 14c9e2926e..c4ccfa76fd 100644
--- a/spec/ruby/library/find/find_spec.rb
+++ b/spec/ruby/library/find/find_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/common', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/common'
require 'find'
describe "Find.find" do
@@ -13,7 +13,7 @@ describe "Find.find" do
describe "when called without a block" do
it "returns an Enumerator" do
- Find.find(FindDirSpecs.mock_dir).should be_an_instance_of(Enumerator)
+ Find.find(FindDirSpecs.mock_dir).should.instance_of?(Enumerator)
Find.find(FindDirSpecs.mock_dir).to_a.sort.should == FindDirSpecs.expected_paths
end
end
diff --git a/spec/ruby/library/find/fixtures/common.rb b/spec/ruby/library/find/fixtures/common.rb
index 14a7edb09a..99f3bbb45a 100644
--- a/spec/ruby/library/find/fixtures/common.rb
+++ b/spec/ruby/library/find/fixtures/common.rb
@@ -71,13 +71,17 @@ module FindDirSpecs
end
def self.create_mock_dirs
+ tmp('') # make sure there is an tmpdir
umask = File.umask 0
- mock_dir_files.each do |name|
- file = File.join mock_dir, name
- mkdir_p File.dirname(file)
- touch file
+ begin
+ mock_dir_files.each do |name|
+ file = File.join mock_dir, name
+ mkdir_p File.dirname(file)
+ touch file
+ end
+ ensure
+ File.umask umask
end
- File.umask umask
end
def self.delete_mock_dirs
diff --git a/spec/ruby/library/find/prune_spec.rb b/spec/ruby/library/find/prune_spec.rb
index 1aef7d3d23..25dc2cbf3e 100644
--- a/spec/ruby/library/find/prune_spec.rb
+++ b/spec/ruby/library/find/prune_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'find'
describe "Find.prune" do
diff --git a/spec/ruby/library/getoptlong/each_option_spec.rb b/spec/ruby/library/getoptlong/each_option_spec.rb
index c58815bfa9..3349554aaa 100644
--- a/spec/ruby/library/getoptlong/each_option_spec.rb
+++ b/spec/ruby/library/getoptlong/each_option_spec.rb
@@ -1,7 +1,21 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'getoptlong'
-require File.expand_path('../shared/each', __FILE__)
describe "GetoptLong#each_option" do
- it_behaves_like(:getoptlong_each, :each_option)
+ before :each do
+ @opts = GetoptLong.new(
+ [ '--size', '-s', GetoptLong::REQUIRED_ARGUMENT ],
+ [ '--verbose', '-v', GetoptLong::NO_ARGUMENT ],
+ [ '--query', '-q', GetoptLong::NO_ARGUMENT ],
+ [ '--check', '--valid', '-c', GetoptLong::NO_ARGUMENT ]
+ )
+ end
+
+ it "passes each_option argument/value pair to the block" do
+ argv [ "--size", "10k", "-v", "-q", "a.txt", "b.txt" ] do
+ pairs = []
+ @opts.each_option { |arg, val| pairs << [ arg, val ] }
+ pairs.should == [ [ "--size", "10k" ], [ "--verbose", "" ], [ "--query", ""] ]
+ end
+ end
end
diff --git a/spec/ruby/library/getoptlong/each_spec.rb b/spec/ruby/library/getoptlong/each_spec.rb
index d09f84a6db..646c3297b5 100644
--- a/spec/ruby/library/getoptlong/each_spec.rb
+++ b/spec/ruby/library/getoptlong/each_spec.rb
@@ -1,7 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'getoptlong'
-require File.expand_path('../shared/each', __FILE__)
describe "GetoptLong#each" do
- it_behaves_like(:getoptlong_each, :each)
+ it "is an alias of GetoptLong#each_option" do
+ GetoptLong.instance_method(:each).should == GetoptLong.instance_method(:each_option)
+ end
end
diff --git a/spec/ruby/library/getoptlong/error_message_spec.rb b/spec/ruby/library/getoptlong/error_message_spec.rb
index 3f44f538c6..10435b1350 100644
--- a/spec/ruby/library/getoptlong/error_message_spec.rb
+++ b/spec/ruby/library/getoptlong/error_message_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'getoptlong'
describe "GetoptLong#error_message" do
@@ -14,7 +14,7 @@ describe "GetoptLong#error_message" do
opts.get
-> {
opts.ordering = GetoptLong::PERMUTE
- }.should raise_error(ArgumentError) { |e|
+ }.should.raise(ArgumentError) { |e|
e.message.should == "argument error"
opts.error_message.should == "argument error"
}
diff --git a/spec/ruby/library/getoptlong/get_option_spec.rb b/spec/ruby/library/getoptlong/get_option_spec.rb
index c56903e68e..1d80e3622e 100644
--- a/spec/ruby/library/getoptlong/get_option_spec.rb
+++ b/spec/ruby/library/getoptlong/get_option_spec.rb
@@ -1,7 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'getoptlong'
-require File.expand_path('../shared/get', __FILE__)
describe "GetoptLong#get_option" do
- it_behaves_like(:getoptlong_get, :get_option)
+ it "is an alias of GetoptLong#get" do
+ GetoptLong.instance_method(:get_option).should == GetoptLong.instance_method(:get)
+ end
end
diff --git a/spec/ruby/library/getoptlong/get_spec.rb b/spec/ruby/library/getoptlong/get_spec.rb
index ba1a1be6ad..bfc6697a5a 100644
--- a/spec/ruby/library/getoptlong/get_spec.rb
+++ b/spec/ruby/library/getoptlong/get_spec.rb
@@ -1,7 +1,65 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'getoptlong'
-require File.expand_path('../shared/get', __FILE__)
describe "GetoptLong#get" do
- it_behaves_like(:getoptlong_get, :get)
+ before :each do
+ @opts = GetoptLong.new(
+ [ '--size', '-s', GetoptLong::REQUIRED_ARGUMENT ],
+ [ '--verbose', '-v', GetoptLong::NO_ARGUMENT ],
+ [ '--query', '-q', GetoptLong::NO_ARGUMENT ],
+ [ '--check', '--valid', '-c', GetoptLong::NO_ARGUMENT ]
+ )
+ @opts.quiet = true # silence using $deferr
+ end
+
+ it "returns the next option name and its argument as an Array" do
+ argv [ "--size", "10k", "-v", "-q", "a.txt", "b.txt" ] do
+ @opts.get.should == [ "--size", "10k" ]
+ @opts.get.should == [ "--verbose", "" ]
+ @opts.get.should == [ "--query", ""]
+ @opts.get.should == nil
+ end
+ end
+
+ it "shifts ARGV on each call" do
+ argv [ "--size", "10k", "-v", "-q", "a.txt", "b.txt" ] do
+ @opts.get
+ ARGV.should == [ "-v", "-q", "a.txt", "b.txt" ]
+
+ @opts.get
+ ARGV.should == [ "-q", "a.txt", "b.txt" ]
+
+ @opts.get
+ ARGV.should == [ "a.txt", "b.txt" ]
+
+ @opts.get
+ ARGV.should == [ "a.txt", "b.txt" ]
+ end
+ end
+
+ it "terminates processing when encountering '--'" do
+ argv [ "--size", "10k", "--", "-v", "-q", "a.txt", "b.txt" ] do
+ @opts.get
+ ARGV.should == ["--", "-v", "-q", "a.txt", "b.txt"]
+
+ @opts.get
+ ARGV.should == ["-v", "-q", "a.txt", "b.txt"]
+
+ @opts.get
+ ARGV.should == ["-v", "-q", "a.txt", "b.txt"]
+ end
+ end
+
+ it "raises a if an argument was required, but none given" do
+ argv [ "--size" ] do
+ -> { @opts.get }.should.raise(GetoptLong::MissingArgument)
+ end
+ end
+
+ # https://bugs.ruby-lang.org/issues/13858
+ it "returns multiline argument" do
+ argv [ "--size=\n10k\n" ] do
+ @opts.get.should == [ "--size", "\n10k\n" ]
+ end
+ end
end
diff --git a/spec/ruby/library/getoptlong/initialize_spec.rb b/spec/ruby/library/getoptlong/initialize_spec.rb
index 6ac46b8b5d..782edbd981 100644
--- a/spec/ruby/library/getoptlong/initialize_spec.rb
+++ b/spec/ruby/library/getoptlong/initialize_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'getoptlong'
describe "GetoptLong#initialize" do
diff --git a/spec/ruby/library/getoptlong/ordering_spec.rb b/spec/ruby/library/getoptlong/ordering_spec.rb
index e445de2255..60ce73afaa 100644
--- a/spec/ruby/library/getoptlong/ordering_spec.rb
+++ b/spec/ruby/library/getoptlong/ordering_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'getoptlong'
describe "GetoptLong#ordering=" do
@@ -9,18 +9,18 @@ describe "GetoptLong#ordering=" do
opts.quiet = true
opts.get
- lambda {
+ -> {
opts.ordering = GetoptLong::PERMUTE
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
end
end
it "raises an ArgumentError if given an invalid value" do
opts = GetoptLong.new
- lambda {
+ -> {
opts.ordering = 12345
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
end
it "does not allow changing ordering to PERMUTE if ENV['POSIXLY_CORRECT'] is set" do
diff --git a/spec/ruby/library/getoptlong/set_options_spec.rb b/spec/ruby/library/getoptlong/set_options_spec.rb
index 39d6991bf5..f60dcc87a3 100644
--- a/spec/ruby/library/getoptlong/set_options_spec.rb
+++ b/spec/ruby/library/getoptlong/set_options_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'getoptlong'
describe "GetoptLong#set_options" do
@@ -39,60 +39,60 @@ describe "GetoptLong#set_options" do
it "raises an ArgumentError if too many argument flags where given" do
argv [] do
- lambda {
+ -> {
@opts.set_options(["--size", GetoptLong::NO_ARGUMENT, GetoptLong::REQUIRED_ARGUMENT])
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
end
end
it "raises a RuntimeError if processing has already started" do
argv [] do
@opts.get
- lambda {
+ -> {
@opts.set_options()
- }.should raise_error(RuntimeError)
+ }.should.raise(RuntimeError)
end
end
it "raises an ArgumentError if no argument flag was given" do
argv [] do
- lambda {
+ -> {
@opts.set_options(["--size"])
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
end
end
it "raises an ArgumentError if one of the given arguments is not an Array" do
argv [] do
- lambda {
+ -> {
@opts.set_options(
["--size", GetoptLong::REQUIRED_ARGUMENT],
"test")
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
end
end
it "raises an ArgumentError if the same option is given twice" do
argv [] do
- lambda {
+ -> {
@opts.set_options(
["--size", GetoptLong::NO_ARGUMENT],
["--size", GetoptLong::OPTIONAL_ARGUMENT])
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
- lambda {
+ -> {
@opts.set_options(
["--size", GetoptLong::NO_ARGUMENT],
["-s", "--size", GetoptLong::OPTIONAL_ARGUMENT])
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
end
end
it "raises an ArgumentError if the given option is invalid" do
argv [] do
- lambda {
+ -> {
@opts.set_options(["-size", GetoptLong::NO_ARGUMENT])
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
end
end
end
diff --git a/spec/ruby/library/getoptlong/shared/each.rb b/spec/ruby/library/getoptlong/shared/each.rb
deleted file mode 100644
index b534e24c0f..0000000000
--- a/spec/ruby/library/getoptlong/shared/each.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-describe :getoptlong_each, shared: true do
- before :each do
- @opts = GetoptLong.new(
- [ '--size', '-s', GetoptLong::REQUIRED_ARGUMENT ],
- [ '--verbose', '-v', GetoptLong::NO_ARGUMENT ],
- [ '--query', '-q', GetoptLong::NO_ARGUMENT ],
- [ '--check', '--valid', '-c', GetoptLong::NO_ARGUMENT ]
- )
- end
-
- it "passes each argument/value pair to the block" do
- argv [ "--size", "10k", "-v", "-q", "a.txt", "b.txt" ] do
- pairs = []
- @opts.send(@method) { |arg, val| pairs << [ arg, val ] }
- pairs.should == [ [ "--size", "10k" ], [ "--verbose", "" ], [ "--query", ""] ]
- end
- end
-end
diff --git a/spec/ruby/library/getoptlong/shared/get.rb b/spec/ruby/library/getoptlong/shared/get.rb
deleted file mode 100644
index 91a0fbaacc..0000000000
--- a/spec/ruby/library/getoptlong/shared/get.rb
+++ /dev/null
@@ -1,64 +0,0 @@
-describe :getoptlong_get, shared: true do
- before :each do
- @opts = GetoptLong.new(
- [ '--size', '-s', GetoptLong::REQUIRED_ARGUMENT ],
- [ '--verbose', '-v', GetoptLong::NO_ARGUMENT ],
- [ '--query', '-q', GetoptLong::NO_ARGUMENT ],
- [ '--check', '--valid', '-c', GetoptLong::NO_ARGUMENT ]
- )
- @opts.quiet = true # silence using $deferr
- end
-
- it "returns the next option name and its argument as an Array" do
- argv [ "--size", "10k", "-v", "-q", "a.txt", "b.txt" ] do
- @opts.send(@method).should == [ "--size", "10k" ]
- @opts.send(@method).should == [ "--verbose", "" ]
- @opts.send(@method).should == [ "--query", ""]
- @opts.send(@method).should == nil
- end
- end
-
- it "shifts ARGV on each call" do
- argv [ "--size", "10k", "-v", "-q", "a.txt", "b.txt" ] do
- @opts.send(@method)
- ARGV.should == [ "-v", "-q", "a.txt", "b.txt" ]
-
- @opts.send(@method)
- ARGV.should == [ "-q", "a.txt", "b.txt" ]
-
- @opts.send(@method)
- ARGV.should == [ "a.txt", "b.txt" ]
-
- @opts.send(@method)
- ARGV.should == [ "a.txt", "b.txt" ]
- end
- end
-
- it "terminates processing when encountering '--'" do
- argv [ "--size", "10k", "--", "-v", "-q", "a.txt", "b.txt" ] do
- @opts.send(@method)
- ARGV.should == ["--", "-v", "-q", "a.txt", "b.txt"]
-
- @opts.send(@method)
- ARGV.should == ["-v", "-q", "a.txt", "b.txt"]
-
- @opts.send(@method)
- ARGV.should == ["-v", "-q", "a.txt", "b.txt"]
- end
- end
-
- it "raises a if an argument was required, but none given" do
- argv [ "--size" ] do
- lambda { @opts.send(@method) }.should raise_error(GetoptLong::MissingArgument)
- end
- end
-
- ruby_version_is "2.5" do
- # https://bugs.ruby-lang.org/issues/13858
- it "returns multiline argument" do
- argv [ "--size=\n10k\n" ] do
- @opts.send(@method).should == [ "--size", "\n10k\n" ]
- end
- end
- end
-end
diff --git a/spec/ruby/library/getoptlong/terminate_spec.rb b/spec/ruby/library/getoptlong/terminate_spec.rb
index 66d318527b..a12d1df2ef 100644
--- a/spec/ruby/library/getoptlong/terminate_spec.rb
+++ b/spec/ruby/library/getoptlong/terminate_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'getoptlong'
describe "GetoptLong#terminate" do
@@ -19,7 +19,7 @@ describe "GetoptLong#terminate" do
end
end
- it "returns self when option processsing is terminated" do
+ it "returns self when option processing is terminated" do
@opts.terminate.should == @opts
end
diff --git a/spec/ruby/library/getoptlong/terminated_spec.rb b/spec/ruby/library/getoptlong/terminated_spec.rb
index feaf2bc09e..6108a7f6e9 100644
--- a/spec/ruby/library/getoptlong/terminated_spec.rb
+++ b/spec/ruby/library/getoptlong/terminated_spec.rb
@@ -1,17 +1,17 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'getoptlong'
describe "GetoptLong#terminated?" do
it "returns true if option processing has terminated" do
argv [ "--size", "10k" ] do
opts = GetoptLong.new(["--size", GetoptLong::REQUIRED_ARGUMENT])
- opts.terminated?.should == false
+ opts.should_not.terminated?
opts.get.should == ["--size", "10k"]
- opts.terminated?.should == false
+ opts.should_not.terminated?
opts.get.should == nil
- opts.terminated?.should == true
+ opts.should.terminated?
end
end
end
diff --git a/spec/ruby/library/io-wait/wait_readable_spec.rb b/spec/ruby/library/io-wait/wait_readable_spec.rb
new file mode 100644
index 0000000000..d7473f029f
--- /dev/null
+++ b/spec/ruby/library/io-wait/wait_readable_spec.rb
@@ -0,0 +1,42 @@
+require_relative '../../spec_helper'
+
+describe "IO#wait_readable" do
+ before :each do
+ @io = File.new(__FILE__ )
+ end
+
+ after :each do
+ @io.close
+ end
+
+ it "waits for the IO to become readable with no timeout" do
+ @io.wait_readable.should == @io
+ end
+
+ it "waits for the IO to become readable with the given timeout" do
+ @io.wait_readable(1).should == @io
+ end
+
+ it "waits for the IO to become readable with the given large timeout" do
+ @io.wait_readable(365 * 24 * 60 * 60).should == @io
+ end
+
+ it "can be interrupted" do
+ rd, wr = IO.pipe
+ start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
+
+ t = Thread.new do
+ rd.wait_readable(10)
+ end
+
+ Thread.pass until t.stop?
+ t.kill
+ t.join
+
+ finish = Process.clock_gettime(Process::CLOCK_MONOTONIC)
+ (finish - start).should < 9
+ ensure
+ rd.close
+ wr.close
+ end
+end
diff --git a/spec/ruby/library/io-wait/wait_spec.rb b/spec/ruby/library/io-wait/wait_spec.rb
new file mode 100644
index 0000000000..1d784e7aa4
--- /dev/null
+++ b/spec/ruby/library/io-wait/wait_spec.rb
@@ -0,0 +1,162 @@
+require_relative '../../spec_helper'
+require_relative '../../fixtures/io'
+
+describe "IO#wait" do
+ before :each do
+ @io = File.new(__FILE__ )
+
+ if /mswin|mingw/ =~ RUBY_PLATFORM
+ require 'socket'
+ @r, @w = Socket.pair(Socket::AF_INET, Socket::SOCK_STREAM, 0)
+ else
+ @r, @w = IO.pipe
+ end
+ end
+
+ after :each do
+ @io.close unless @io.closed?
+
+ @r.close unless @r.closed?
+ @w.close unless @w.closed?
+ end
+
+ context "[events, timeout] passed" do
+ it "returns events mask when the READABLE event is ready during the timeout" do
+ @w.write('data to read')
+ @r.wait(IO::READABLE, 2).should == IO::READABLE
+ end
+
+ it "returns events mask when the WRITABLE event is ready during the timeout" do
+ @w.wait(IO::WRITABLE, 0).should == IO::WRITABLE
+ end
+
+ it "waits for the READABLE event to be ready" do
+ @r.wait(IO::READABLE, 0).should == nil
+
+ @w.write('data to read')
+ @r.wait(IO::READABLE, 0).should_not == nil
+ end
+
+ it "waits for the WRITABLE event to be ready" do
+ written_bytes = IOSpec.exhaust_write_buffer(@w)
+ @w.wait(IO::WRITABLE, 0).should == nil
+
+ @r.read(written_bytes)
+ @w.wait(IO::WRITABLE, 0).should_not == nil
+ end
+
+ it "returns nil when the READABLE event is not ready during the timeout" do
+ @w.wait(IO::READABLE, 0).should == nil
+ end
+
+ it "returns nil when the WRITABLE event is not ready during the timeout" do
+ IOSpec.exhaust_write_buffer(@w)
+ @w.wait(IO::WRITABLE, 0).should == nil
+ end
+
+ it "raises IOError when io is closed (closed stream (IOError))" do
+ @io.close
+ -> { @io.wait(IO::READABLE, 0) }.should.raise(IOError, "closed stream")
+ end
+
+ it "raises ArgumentError when events is not positive" do
+ -> { @w.wait(0, 0) }.should.raise(ArgumentError, "Events must be positive integer!")
+ -> { @w.wait(-1, 0) }.should.raise(ArgumentError, "Events must be positive integer!")
+ end
+
+ it "changes thread status to 'sleep' when waits for READABLE event" do
+ t = Thread.new { @r.wait(IO::READABLE, 10) }
+ sleep 1
+ t.status.should == 'sleep'
+ t.kill
+ t.join # Thread#kill doesn't wait for the thread to end
+ end
+
+ # https://github.com/ruby/ruby/actions/runs/11948300522/job/33305664284?pr=12139
+ platform_is_not :windows do
+ it "changes thread status to 'sleep' when waits for WRITABLE event" do
+ IOSpec.exhaust_write_buffer(@w)
+
+ t = Thread.new { @w.wait(IO::WRITABLE, 10) }
+ sleep 1
+ t.status.should == 'sleep'
+ t.kill
+ t.join # Thread#kill doesn't wait for the thread to end
+ end
+ end
+
+ it "can be interrupted when waiting for READABLE event" do
+ start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
+
+ t = Thread.new do
+ @r.wait(IO::READABLE, 10)
+ end
+
+ Thread.pass until t.stop?
+ t.kill
+ t.join # Thread#kill doesn't wait for the thread to end
+
+ finish = Process.clock_gettime(Process::CLOCK_MONOTONIC)
+ (finish - start).should < 9
+ end
+
+ it "can be interrupted when waiting for WRITABLE event" do
+ IOSpec.exhaust_write_buffer(@w)
+ start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
+
+ t = Thread.new do
+ @w.wait(IO::WRITABLE, 10)
+ end
+
+ Thread.pass until t.stop?
+ t.kill
+ t.join # Thread#kill doesn't wait for the thread to end
+
+ finish = Process.clock_gettime(Process::CLOCK_MONOTONIC)
+ (finish - start).should < 9
+ end
+ end
+
+ context "[timeout, mode] passed" do
+ it "accepts :r, :read, :readable mode to check READABLE event" do
+ @io.wait(0, :r).should == @io
+ @io.wait(0, :read).should == @io
+ @io.wait(0, :readable).should == @io
+ end
+
+ it "accepts :w, :write, :writable mode to check WRITABLE event" do
+ @io.wait(0, :w).should == @io
+ @io.wait(0, :write).should == @io
+ @io.wait(0, :writable).should == @io
+ end
+
+ it "accepts :rw, :read_write, :readable_writable mode to check READABLE and WRITABLE events" do
+ @io.wait(0, :rw).should == @io
+ @io.wait(0, :read_write).should == @io
+ @io.wait(0, :readable_writable).should == @io
+ end
+
+ it "accepts a list of modes" do
+ @io.wait(0, :r, :w, :rw).should == @io
+ end
+
+ it "accepts timeout and mode in any order" do
+ @io.wait(0, :r).should == @io
+ @io.wait(:r, 0).should == @io
+ @io.wait(:r, 0, :w).should == @io
+ end
+
+ it "raises ArgumentError when passed wrong Symbol value as mode argument" do
+ -> { @io.wait(0, :wrong) }.should.raise(ArgumentError, "unsupported mode: wrong")
+ end
+
+ it "raises ArgumentError when several Integer arguments passed" do
+ -> { @w.wait(0, 10, :r) }.should.raise(ArgumentError, "timeout given more than once")
+ end
+
+ it "raises IOError when io is closed (closed stream (IOError))" do
+ @io.close
+ -> { @io.wait(0, :r) }.should.raise(IOError, "closed stream")
+ end
+ end
+end
diff --git a/spec/ruby/library/io-wait/wait_writable_spec.rb b/spec/ruby/library/io-wait/wait_writable_spec.rb
new file mode 100644
index 0000000000..2017817caa
--- /dev/null
+++ b/spec/ruby/library/io-wait/wait_writable_spec.rb
@@ -0,0 +1,37 @@
+require_relative '../../spec_helper'
+require_relative '../../fixtures/io'
+
+describe "IO#wait_writable" do
+ it "waits for the IO to become writable with no timeout" do
+ STDOUT.wait_writable.should == STDOUT
+ end
+
+ it "waits for the IO to become writable with the given timeout" do
+ STDOUT.wait_writable(1).should == STDOUT
+ end
+
+ it "waits for the IO to become writable with the given large timeout" do
+ # Represents one year and is larger than a 32-bit int
+ STDOUT.wait_writable(365 * 24 * 60 * 60).should == STDOUT
+ end
+
+ it "can be interrupted" do
+ rd, wr = IO.pipe
+ IOSpec.exhaust_write_buffer(wr)
+ start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
+
+ t = Thread.new do
+ wr.wait_writable(10)
+ end
+
+ Thread.pass until t.stop?
+ t.kill
+ t.join
+
+ finish = Process.clock_gettime(Process::CLOCK_MONOTONIC)
+ (finish - start).should < 9
+ ensure
+ rd.close unless rd.closed?
+ wr.close unless wr.closed?
+ end
+end
diff --git a/spec/ruby/library/ipaddr/hton_spec.rb b/spec/ruby/library/ipaddr/hton_spec.rb
index 037bb3d328..9c0b821abf 100644
--- a/spec/ruby/library/ipaddr/hton_spec.rb
+++ b/spec/ruby/library/ipaddr/hton_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'ipaddr'
describe "IPAddr#hton" do
diff --git a/spec/ruby/library/ipaddr/ipv4_conversion_spec.rb b/spec/ruby/library/ipaddr/ipv4_conversion_spec.rb
index b69be82c13..1128c16dd2 100644
--- a/spec/ruby/library/ipaddr/ipv4_conversion_spec.rb
+++ b/spec/ruby/library/ipaddr/ipv4_conversion_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'ipaddr'
describe "IPAddr#ipv4_compat" do
@@ -8,11 +8,11 @@ describe "IPAddr#ipv4_compat" do
a.to_s.should == "::192.168.1.2"
a.to_string.should == "0000:0000:0000:0000:0000:0000:c0a8:0102"
a.family.should == Socket::AF_INET6
- a.ipv4_compat?.should == true
+ a.should.ipv4_compat?
b = a.native
b.to_s.should == "192.168.1.2"
b.family.should == Socket::AF_INET
- b.ipv4_compat?.should == false
+ b.should_not.ipv4_compat?
a = IPAddr.new("192.168.1.2")
b = a.ipv4_compat
@@ -29,11 +29,11 @@ describe "IPAddr#ipv4_mapped" do
a.to_s.should == "::ffff:192.168.1.2"
a.to_string.should == "0000:0000:0000:0000:0000:ffff:c0a8:0102"
a.family.should == Socket::AF_INET6
- a.ipv4_mapped?.should == true
+ a.should.ipv4_mapped?
b = a.native
b.to_s.should == "192.168.1.2"
b.family.should == Socket::AF_INET
- b.ipv4_mapped?.should == false
+ b.should_not.ipv4_mapped?
a = IPAddr.new("192.168.1.2")
b = a.ipv4_mapped
@@ -42,5 +42,3 @@ describe "IPAddr#ipv4_mapped" do
end
end
-
-
diff --git a/spec/ruby/library/ipaddr/new_spec.rb b/spec/ruby/library/ipaddr/new_spec.rb
index d0b91af87d..7fba2b372e 100644
--- a/spec/ruby/library/ipaddr/new_spec.rb
+++ b/spec/ruby/library/ipaddr/new_spec.rb
@@ -1,11 +1,11 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'ipaddr'
describe "IPAddr#new" do
it "initializes IPAddr" do
- lambda{ IPAddr.new("3FFE:505:ffff::/48") }.should_not raise_error
- lambda{ IPAddr.new("0:0:0:1::") }.should_not raise_error
- lambda{ IPAddr.new("2001:200:300::/48") }.should_not raise_error
+ ->{ IPAddr.new("3FFE:505:ffff::/48") }.should_not.raise
+ ->{ IPAddr.new("0:0:0:1::") }.should_not.raise
+ ->{ IPAddr.new("2001:200:300::/48") }.should_not.raise
end
it "initializes IPAddr ipv6 address with short notation" do
@@ -27,8 +27,8 @@ describe "IPAddr#new" do
a.to_s.should == "3ffe:505:2::"
a.to_string.should == "3ffe:0505:0002:0000:0000:0000:0000:0000"
a.family.should == Socket::AF_INET6
- a.ipv4?.should == false
- a.ipv6?.should == true
+ a.should_not.ipv4?
+ a.should.ipv6?
a.inspect.should == "#<IPAddr: IPv6:3ffe:0505:0002:0000:0000:0000:0000:0000/ffff:ffff:ffff:0000:0000:0000:0000:0000>"
end
@@ -51,8 +51,8 @@ describe "IPAddr#new" do
a.to_s.should == "192.168.1.2"
a.to_string.should == "192.168.1.2"
a.family.should == Socket::AF_INET
- a.ipv4?.should == true
- a.ipv6?.should == false
+ a.should.ipv4?
+ a.should_not.ipv6?
end
it "initializes IPAddr ipv4 address with / subnet notation" do
@@ -79,15 +79,14 @@ describe "IPAddr#new" do
it "raises on incorrect IPAddr strings" do
[
- ["fe80::1%fxp0"],
["::1/255.255.255.0"],
[IPAddr.new("::1").to_i],
["::ffff:192.168.1.2/120", Socket::AF_INET],
["[192.168.1.2]/120"],
].each { |args|
- lambda{
+ ->{
IPAddr.new(*args)
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
}
end
end
diff --git a/spec/ruby/library/ipaddr/operator_spec.rb b/spec/ruby/library/ipaddr/operator_spec.rb
index 6d884780e3..3337d22300 100644
--- a/spec/ruby/library/ipaddr/operator_spec.rb
+++ b/spec/ruby/library/ipaddr/operator_spec.rb
@@ -1,15 +1,12 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'ipaddr'
describe "IPAddr Operator" do
- IN6MASK32 = "ffff:ffff::"
- IN6MASK128 = "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"
-
before do
@in6_addr_any = IPAddr.new()
@a = IPAddr.new("3ffe:505:2::/48")
@b = IPAddr.new("0:0:0:1::")
- @c = IPAddr.new(IN6MASK32)
+ @c = IPAddr.new("ffff:ffff::")
end
it "bitwises or" do
@@ -48,7 +45,7 @@ describe "IPAddr Operator" do
it "inverts" do
a = ~@in6_addr_any
- a.to_s.should == IN6MASK128
+ a.to_s.should == "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"
@in6_addr_any.to_s.should == "::"
end
@@ -57,11 +54,9 @@ describe "IPAddr Operator" do
@a.should_not == IPAddr.new("3ffe:505:3::")
end
- ruby_version_is '2.4' do
- # https://bugs.ruby-lang.org/issues/12799
- it "tests for equality correctly if object cannot be converted to IPAddr" do
- IPAddr.new("1.1.1.1").should_not == "sometext"
- end
+ # https://bugs.ruby-lang.org/issues/12799
+ it "tests for equality correctly if object cannot be converted to IPAddr" do
+ IPAddr.new("1.1.1.1").should_not == "sometext"
end
it "sets a mask" do
@@ -71,17 +66,17 @@ describe "IPAddr Operator" do
end
it "checks whether an address is included in a range" do
- @a.should include(IPAddr.new("3ffe:505:2::"))
- @a.should include(IPAddr.new("3ffe:505:2::1"))
- @a.should_not include(IPAddr.new("3ffe:505:3::"))
+ @a.should.include?(IPAddr.new("3ffe:505:2::"))
+ @a.should.include?(IPAddr.new("3ffe:505:2::1"))
+ @a.should_not.include?(IPAddr.new("3ffe:505:3::"))
net1 = IPAddr.new("192.168.2.0/24")
- net1.should include(IPAddr.new("192.168.2.0"))
- net1.should include(IPAddr.new("192.168.2.255"))
- net1.should_not include(IPAddr.new("192.168.3.0"))
+ net1.should.include?(IPAddr.new("192.168.2.0"))
+ net1.should.include?(IPAddr.new("192.168.2.255"))
+ net1.should_not.include?(IPAddr.new("192.168.3.0"))
# test with integer parameter
int = (192 << 24) + (168 << 16) + (2 << 8) + 13
- net1.should include(int)
- net1.should_not include(int+255)
+ net1.should.include?(int)
+ net1.should_not.include?(int+255)
end
end
diff --git a/spec/ruby/library/ipaddr/reverse_spec.rb b/spec/ruby/library/ipaddr/reverse_spec.rb
index dec5c65178..9bda60ca70 100644
--- a/spec/ruby/library/ipaddr/reverse_spec.rb
+++ b/spec/ruby/library/ipaddr/reverse_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'ipaddr'
describe "IPAddr#reverse" do
@@ -11,17 +11,17 @@ end
describe "IPAddr#ip6_arpa" do
it "converts an IPv6 address into the reverse DNS lookup representation according to RFC3172" do
IPAddr.new("3ffe:505:2::f").ip6_arpa.should == "f.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.2.0.0.0.5.0.5.0.e.f.f.3.ip6.arpa"
- lambda{
+ ->{
IPAddr.new("192.168.2.1").ip6_arpa
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
end
end
describe "IPAddr#ip6_int" do
it "converts an IPv6 address into the reverse DNS lookup representation according to RFC1886" do
IPAddr.new("3ffe:505:2::f").ip6_int.should == "f.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.2.0.0.0.5.0.5.0.e.f.f.3.ip6.int"
- lambda{
+ ->{
IPAddr.new("192.168.2.1").ip6_int
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
end
end
diff --git a/spec/ruby/library/ipaddr/to_s_spec.rb b/spec/ruby/library/ipaddr/to_s_spec.rb
index 30e5237436..2a9a027909 100644
--- a/spec/ruby/library/ipaddr/to_s_spec.rb
+++ b/spec/ruby/library/ipaddr/to_s_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'ipaddr'
describe "IPAddr#to_s" do
diff --git a/spec/ruby/library/irb/fixtures/irb.rb b/spec/ruby/library/irb/fixtures/irb.rb
new file mode 100644
index 0000000000..8d386dfda1
--- /dev/null
+++ b/spec/ruby/library/irb/fixtures/irb.rb
@@ -0,0 +1,3 @@
+a = 10
+
+binding.irb # rubocop:disable Lint/Debugger
diff --git a/spec/ruby/library/irb/irb_spec.rb b/spec/ruby/library/irb/irb_spec.rb
new file mode 100644
index 0000000000..2607c7ef33
--- /dev/null
+++ b/spec/ruby/library/irb/irb_spec.rb
@@ -0,0 +1,19 @@
+require_relative '../../spec_helper'
+require 'tmpdir'
+
+describe "Binding#irb" do
+ it "creates an IRB session with the binding in scope" do
+ irb_fixture = fixture __FILE__, "irb.rb"
+ envs = %w[IRBRC HOME XDG_CONFIG_HOME].to_h {|e| [e, nil]}
+
+ out = Dir.mktmpdir do |dir|
+ IO.popen([envs, *ruby_exe, irb_fixture, chdir: dir], "r+") do |pipe|
+ pipe.puts "a ** 2"
+ pipe.puts "exit"
+ pipe.readlines.map(&:chomp).reject(&:empty?)
+ end
+ end
+
+ out.last(3).should == ["a ** 2", "100", "exit"]
+ end
+end
diff --git a/spec/ruby/library/logger/device/close_spec.rb b/spec/ruby/library/logger/device/close_spec.rb
index 777b20baf0..1db5d582a7 100644
--- a/spec/ruby/library/logger/device/close_spec.rb
+++ b/spec/ruby/library/logger/device/close_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/common', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../fixtures/common'
describe "Logger::LogDevice#close" do
before :each do
@@ -17,6 +17,6 @@ describe "Logger::LogDevice#close" do
it "closes the LogDevice's stream" do
@device.close
- lambda { @device.write("Test") }.should complain(/\Alog writing failed\./)
+ -> { @device.write("Test") }.should complain(/\Alog shifting failed\./)
end
end
diff --git a/spec/ruby/library/logger/device/new_spec.rb b/spec/ruby/library/logger/device/new_spec.rb
index 0e08b743ed..c943e7fbe2 100644
--- a/spec/ruby/library/logger/device/new_spec.rb
+++ b/spec/ruby/library/logger/device/new_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/common', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../fixtures/common'
describe "Logger::LogDevice#new" do
before :each do
@@ -14,11 +14,11 @@ describe "Logger::LogDevice#new" do
it "creates a new log device" do
l = Logger::LogDevice.new(@log_file)
- l.dev.should be_kind_of(File)
+ l.dev.should.is_a?(File)
end
it "receives an IO object to log there as first argument" do
- @log_file.should be_kind_of(IO)
+ @log_file.should.is_a?(IO)
l = Logger::LogDevice.new(@log_file)
l.write("foo")
@log_file.rewind
@@ -31,17 +31,17 @@ describe "Logger::LogDevice#new" do
l.write("Test message")
l.close
- File.exist?(path).should be_true
+ File.should.exist?(path)
File.open(path) do |f|
- f.readlines.should_not be_empty
+ f.readlines.should_not.empty?
end
rm_r path
end
it "receives options via a hash as second argument" do
- lambda { Logger::LogDevice.new(STDERR,
- { shift_age: 8, shift_size: 10
- })}.should_not raise_error
+ -> {
+ Logger::LogDevice.new(STDERR, shift_age: 8, shift_size: 10)
+ }.should_not.raise
end
end
diff --git a/spec/ruby/library/logger/device/write_spec.rb b/spec/ruby/library/logger/device/write_spec.rb
index e3ddd61b1f..87ecf2ad6a 100644
--- a/spec/ruby/library/logger/device/write_spec.rb
+++ b/spec/ruby/library/logger/device/write_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/common', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../fixtures/common'
describe "Logger::LogDevice#write" do
before :each do
@@ -37,6 +37,6 @@ describe "Logger::LogDevice#write" do
it "fails if the device is already closed" do
@device.close
- lambda { @device.write "foo" }.should complain(/\Alog writing failed\./)
+ -> { @device.write "foo" }.should complain(/\Alog shifting failed\./)
end
end
diff --git a/spec/ruby/library/logger/logger/add_spec.rb b/spec/ruby/library/logger/logger/add_spec.rb
index 235247e9e8..98ac88f64f 100644
--- a/spec/ruby/library/logger/logger/add_spec.rb
+++ b/spec/ruby/library/logger/logger/add_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/common', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../fixtures/common'
describe "Logger#add" do
before :each do
@@ -52,30 +52,30 @@ describe "Logger#add" do
end
it "receives a block" do
- lambda {
+ -> {
@logger.log(nil, "test", "TestApp") do
1+1
end
- }.should_not raise_error
+ }.should_not.raise
end
it "calls the block if message is nil" do
temp = 0
- lambda {
+ -> {
@logger.log(nil, nil, "TestApp") do
temp = 1+1
end
- }.should_not raise_error
+ }.should_not.raise
temp.should == 2
end
it "ignores the block if the message is not nil" do
temp = 0
- lambda {
+ -> {
@logger.log(nil, "not nil", "TestApp") do
temp = 1+1
end
- }.should_not raise_error
+ }.should_not.raise
temp.should == 0
end
end
diff --git a/spec/ruby/library/logger/logger/close_spec.rb b/spec/ruby/library/logger/logger/close_spec.rb
index a4c006150b..81aac2a6cd 100644
--- a/spec/ruby/library/logger/logger/close_spec.rb
+++ b/spec/ruby/library/logger/logger/close_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/common', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../fixtures/common'
describe "Logger#close" do
before :each do
@@ -15,6 +15,6 @@ describe "Logger#close" do
it "closes the logging device" do
@logger.close
- lambda { @logger.add(nil, "Foo") }.should complain(/\Alog writing failed\./)
+ -> { @logger.add(nil, "Foo") }.should complain(/\Alog writing failed\./)
end
end
diff --git a/spec/ruby/library/logger/logger/datetime_format_spec.rb b/spec/ruby/library/logger/logger/datetime_format_spec.rb
index 2bc1f867c3..75a7f6cc03 100644
--- a/spec/ruby/library/logger/logger/datetime_format_spec.rb
+++ b/spec/ruby/library/logger/logger/datetime_format_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/common', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../fixtures/common'
describe "Logger#datetime_format" do
before :each do
@@ -49,7 +49,7 @@ describe "Logger#datetime_format=" do
end
it "follows the Time#strftime format" do
- lambda { @logger.datetime_format = "%Y-%m" }.should_not raise_error
+ -> { @logger.datetime_format = "%Y-%m" }.should_not.raise
regex = /\d{4}-\d{2}-\d{2}oo-\w+ar/
@logger.datetime_format = "%Foo-%Bar"
diff --git a/spec/ruby/library/logger/logger/debug_spec.rb b/spec/ruby/library/logger/logger/debug_spec.rb
index 2260587b23..9375ab0cc6 100644
--- a/spec/ruby/library/logger/logger/debug_spec.rb
+++ b/spec/ruby/library/logger/logger/debug_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/common', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../fixtures/common'
describe "Logger#debug?" do
before :each do
@@ -16,12 +16,12 @@ describe "Logger#debug?" do
it "returns true if severity level allows debug messages" do
@logger.level = Logger::DEBUG
- @logger.debug?.should == true
+ @logger.should.debug?
end
it "returns false if severity level does not allow debug messages" do
@logger.level = Logger::WARN
- @logger.debug?.should == false
+ @logger.should_not.debug?
end
end
diff --git a/spec/ruby/library/logger/logger/error_spec.rb b/spec/ruby/library/logger/logger/error_spec.rb
index e165396bab..42f1dbd883 100644
--- a/spec/ruby/library/logger/logger/error_spec.rb
+++ b/spec/ruby/library/logger/logger/error_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/common', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../fixtures/common'
describe "Logger#error?" do
before :each do
@@ -16,12 +16,12 @@ describe "Logger#error?" do
it "returns true if severity level allows printing errors" do
@logger.level = Logger::INFO
- @logger.error?.should == true
+ @logger.should.error?
end
it "returns false if severity level does not allow errors" do
@logger.level = Logger::FATAL
- @logger.error?.should == false
+ @logger.should_not.error?
end
end
diff --git a/spec/ruby/library/logger/logger/fatal_spec.rb b/spec/ruby/library/logger/logger/fatal_spec.rb
index ebbe8a04a5..f12fa3a89f 100644
--- a/spec/ruby/library/logger/logger/fatal_spec.rb
+++ b/spec/ruby/library/logger/logger/fatal_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/common', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../fixtures/common'
describe "Logger#fatal?" do
before :each do
@@ -16,12 +16,12 @@ describe "Logger#fatal?" do
it "returns true if severity level allows fatal messages" do
@logger.level = Logger::FATAL
- @logger.fatal?.should == true
+ @logger.should.fatal?
end
it "returns false if severity level does not allow fatal messages" do
@logger.level = Logger::UNKNOWN
- @logger.fatal?.should == false
+ @logger.should_not.fatal?
end
end
diff --git a/spec/ruby/library/logger/logger/info_spec.rb b/spec/ruby/library/logger/logger/info_spec.rb
index 7f299ea0da..eb5dca48dd 100644
--- a/spec/ruby/library/logger/logger/info_spec.rb
+++ b/spec/ruby/library/logger/logger/info_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/common', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../fixtures/common'
describe "Logger#info?" do
before :each do
@@ -16,12 +16,12 @@ describe "Logger#info?" do
it "returns true if severity level allows info messages" do
@logger.level = Logger::INFO
- @logger.info?.should == true
+ @logger.should.info?
end
it "returns false if severity level does not allow info messages" do
@logger.level = Logger::FATAL
- @logger.info?.should == false
+ @logger.should_not.info?
end
end
diff --git a/spec/ruby/library/logger/logger/new_spec.rb b/spec/ruby/library/logger/logger/new_spec.rb
index b3eed42f00..b311c96132 100644
--- a/spec/ruby/library/logger/logger/new_spec.rb
+++ b/spec/ruby/library/logger/logger/new_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/common', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../fixtures/common'
describe "Logger#new" do
@@ -13,31 +13,31 @@ describe "Logger#new" do
rm_r @file_path
end
- it "creates a new logger object" do
- l = Logger.new(STDERR)
- lambda { l.add(Logger::WARN, "Foo") }.should output_to_fd(/Foo/, STDERR)
- end
+ it "creates a new logger object" do
+ l = Logger.new(STDERR)
+ -> { l.add(Logger::WARN, "Foo") }.should output_to_fd(/Foo/, STDERR)
+ end
- it "receives a logging device as first argument" do
- l = Logger.new(@log_file)
- l.add(Logger::WARN, "Test message")
+ it "receives a logging device as first argument" do
+ l = Logger.new(@log_file)
+ l.add(Logger::WARN, "Test message")
- @log_file.rewind
- LoggerSpecs.strip_date(@log_file.readline).should == "WARN -- : Test message\n"
- l.close
- end
+ @log_file.rewind
+ LoggerSpecs.strip_date(@log_file.readline).should == "WARN -- : Test message\n"
+ l.close
+ end
it "receives a frequency rotation as second argument" do
- lambda { Logger.new(@log_file, "daily") }.should_not raise_error
- lambda { Logger.new(@log_file, "weekly") }.should_not raise_error
- lambda { Logger.new(@log_file, "monthly") }.should_not raise_error
+ -> { Logger.new(@log_file, "daily") }.should_not.raise
+ -> { Logger.new(@log_file, "weekly") }.should_not.raise
+ -> { Logger.new(@log_file, "monthly") }.should_not.raise
end
it "also receives a number of log files to keep as second argument" do
- lambda { Logger.new(@log_file, 1).close }.should_not raise_error
+ -> { Logger.new(@log_file, 1).close }.should_not.raise
end
- it "receivs a maximum logfile size as third argument" do
+ it "receives a maximum logfile size as third argument" do
# This should create 2 small log files, logfile_test and logfile_test.0
# in /tmp, each one with a different message.
path = tmp("logfile_test.log")
@@ -46,8 +46,8 @@ describe "Logger#new" do
l.add Logger::WARN, "foo"
l.add Logger::WARN, "bar"
- File.exist?(path).should be_true
- File.exist?(path + ".0").should be_true
+ File.should.exist?(path)
+ File.should.exist?(path + ".0")
# first line will be a comment so we'll have to skip it.
f = File.open(path)
@@ -61,60 +61,58 @@ describe "Logger#new" do
rm_r path, "#{path}.0"
end
- ruby_version_is "2.4" do
- it "receives level symbol as keyword argument" do
- logger = Logger.new(STDERR, level: :info)
- logger.level.should == Logger::INFO
- end
+ it "receives level symbol as keyword argument" do
+ logger = Logger.new(STDERR, level: :info)
+ logger.level.should == Logger::INFO
+ end
- it "receives level as keyword argument" do
- logger = Logger.new(STDERR, level: Logger::INFO)
- logger.level.should == Logger::INFO
- end
+ it "receives level as keyword argument" do
+ logger = Logger.new(STDERR, level: Logger::INFO)
+ logger.level.should == Logger::INFO
+ end
- it "receives progname as keyword argument" do
- progname = "progname"
+ it "receives progname as keyword argument" do
+ progname = "progname"
- logger = Logger.new(STDERR, progname: progname)
- logger.progname.should == progname
- end
+ logger = Logger.new(STDERR, progname: progname)
+ logger.progname.should == progname
+ end
- it "receives datetime_format as keyword argument" do
- datetime_format = "%H:%M:%S"
+ it "receives datetime_format as keyword argument" do
+ datetime_format = "%H:%M:%S"
- logger = Logger.new(STDERR, datetime_format: datetime_format)
- logger.datetime_format.should == datetime_format
- end
+ logger = Logger.new(STDERR, datetime_format: datetime_format)
+ logger.datetime_format.should == datetime_format
+ end
- it "receives formatter as keyword argument" do
- formatter = Class.new do
- def call(_severity, _time, _progname, _msg); end
- end.new
+ it "receives formatter as keyword argument" do
+ formatter = Class.new do
+ def call(_severity, _time, _progname, _msg); end
+ end.new
- logger = Logger.new(STDERR, formatter: formatter)
- logger.formatter.should == formatter
- end
+ logger = Logger.new(STDERR, formatter: formatter)
+ logger.formatter.should == formatter
+ end
- it "receives shift_period_suffix " do
- shift_period_suffix = "%Y-%m-%d"
- path = tmp("shift_period_suffix_test.log")
- now = Time.now
- tomorrow = Time.at(now.to_i + 60 * 60 * 24)
- logger = Logger.new(path, 'daily', shift_period_suffix: shift_period_suffix)
+ it "receives shift_period_suffix" do
+ shift_period_suffix = "%Y-%m-%d"
+ path = tmp("shift_period_suffix_test.log")
+ now = Time.now
+ tomorrow = Time.at(now.to_i + 60 * 60 * 24)
+ logger = Logger.new(path, 'daily', shift_period_suffix: shift_period_suffix)
- logger.add Logger::INFO, 'message'
+ logger.add Logger::INFO, 'message'
- Time.stub!(:now).and_return(tomorrow)
- logger.add Logger::INFO, 'second message'
+ Time.stub!(:now).and_return(tomorrow)
+ logger.add Logger::INFO, 'second message'
- shifted_path = "#{path}.#{now.strftime(shift_period_suffix)}"
+ shifted_path = "#{path}.#{now.strftime(shift_period_suffix)}"
- File.exist?(shifted_path).should == true
+ File.should.exist?(shifted_path)
- logger.close
+ logger.close
- rm_r path, shifted_path
- end
+ rm_r path, shifted_path
end
end
diff --git a/spec/ruby/library/logger/logger/unknown_spec.rb b/spec/ruby/library/logger/logger/unknown_spec.rb
index 5ef9659a9c..4d37c9797e 100644
--- a/spec/ruby/library/logger/logger/unknown_spec.rb
+++ b/spec/ruby/library/logger/logger/unknown_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/common', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../fixtures/common'
describe "Logger#unknown" do
before :each do
@@ -29,7 +29,7 @@ describe "Logger#unknown" do
end
it "receives empty messages" do
- lambda { @logger.unknown("") }.should_not raise_error
+ -> { @logger.unknown("") }.should_not.raise
@log_file.rewind
LoggerSpecs.strip_date(@log_file.readlines.first).should == "ANY -- : \n"
end
diff --git a/spec/ruby/library/logger/logger/warn_spec.rb b/spec/ruby/library/logger/logger/warn_spec.rb
index d34f19fb8e..0bca34824a 100644
--- a/spec/ruby/library/logger/logger/warn_spec.rb
+++ b/spec/ruby/library/logger/logger/warn_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../fixtures/common', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../fixtures/common'
describe "Logger#warn?" do
before :each do
@@ -16,12 +16,12 @@ describe "Logger#warn?" do
it "returns true if severity level allows printing warn messages" do
@logger.level = Logger::WARN
- @logger.warn?.should == true
+ @logger.should.warn?
end
it "returns false if severity level does not allow printing warn messages" do
@logger.level = Logger::FATAL
- @logger.warn?.should == false
+ @logger.should_not.warn?
end
end
diff --git a/spec/ruby/library/logger/severity_spec.rb b/spec/ruby/library/logger/severity_spec.rb
index a4219365dd..e9bc850c33 100644
--- a/spec/ruby/library/logger/severity_spec.rb
+++ b/spec/ruby/library/logger/severity_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'logger'
describe "Logger::Severity" do
diff --git a/spec/ruby/library/mathn/bignum/exponent_spec.rb b/spec/ruby/library/mathn/bignum/exponent_spec.rb
deleted file mode 100644
index 758c2f27fd..0000000000
--- a/spec/ruby/library/mathn/bignum/exponent_spec.rb
+++ /dev/null
@@ -1,21 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-
-ruby_version_is ''...'2.5' do
- require 'mathn'
-
- describe "Bignum#**" do
- before :each do
- @bignum = bignum_value(47)
- end
-
- it "returns self raised to other (positive) power" do
- (@bignum ** 4).should == 7237005577332262361485077344629993318496048279512298547155833600056910050625
- (@bignum ** 1.2).should be_close(57262152889751597425762.57804, TOLERANCE)
- end
-
- it "returns a complex number when negative and raised to a fractional power" do
- ((-@bignum) ** (1/3)).should be_close(Complex(1048576,1816186.907597341), TOLERANCE)
- ((-@bignum) ** (1.0/3)).should be_close(Complex(1048576,1816186.907597341), TOLERANCE)
- end
- end
-end
diff --git a/spec/ruby/library/mathn/complex/Complex_spec.rb b/spec/ruby/library/mathn/complex/Complex_spec.rb
deleted file mode 100644
index 93bb3f0c60..0000000000
--- a/spec/ruby/library/mathn/complex/Complex_spec.rb
+++ /dev/null
@@ -1,14 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-
-ruby_version_is ''...'2.5' do
- require 'mathn'
-
- describe "Kernel#Complex" do
- it "returns an Integer if imaginary part is 0" do
- Complex(42,0).should == 42
- Complex(42,0).should be_kind_of(Fixnum)
- Complex(bignum_value,0).should == bignum_value
- Complex(bignum_value,0).should be_kind_of(Bignum)
- end
- end
-end
diff --git a/spec/ruby/library/mathn/fixnum/exponent_spec.rb b/spec/ruby/library/mathn/fixnum/exponent_spec.rb
deleted file mode 100644
index d72bc5aa00..0000000000
--- a/spec/ruby/library/mathn/fixnum/exponent_spec.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-
-ruby_version_is ''...'2.5' do
- require 'mathn'
-
- describe "Fixnum#**" do
- it "returns self raised to other (positive) power" do
- (2 ** 4).should == 16
- (2 ** 1.2).should be_close(2.2973967, TOLERANCE)
- end
-
- it "returns a complex number when negative and raised to a fractional power" do
- ((-8) ** (1/3)).should be_close(Complex(1, 1.73205), TOLERANCE)
- ((-8) ** (1.0/3)).should be_close(Complex(1, 1.73205), TOLERANCE)
- end
- end
-end
diff --git a/spec/ruby/library/mathn/float/exponent_spec.rb b/spec/ruby/library/mathn/float/exponent_spec.rb
deleted file mode 100644
index 55af43ce5b..0000000000
--- a/spec/ruby/library/mathn/float/exponent_spec.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-
-ruby_version_is ''...'2.5' do
- require 'mathn'
-
- describe "Float#**" do
- it "returns self raised to other (positive) power" do
- (2.0 ** 4).should == 16.0
- (2.0 ** 1.2).should be_close(2.2973967, TOLERANCE)
- end
-
- it "returns a complex number when negative and raised to a fractional power" do
- ((-8.0) ** (1/3)).should be_close(Complex(1, 1.73205), TOLERANCE)
- ((-8.0) ** (1.0/3)).should be_close(Complex(1, 1.73205), TOLERANCE)
- end
- end
-end
diff --git a/spec/ruby/library/mathn/integer/from_prime_division_spec.rb b/spec/ruby/library/mathn/integer/from_prime_division_spec.rb
deleted file mode 100644
index 47aaf47797..0000000000
--- a/spec/ruby/library/mathn/integer/from_prime_division_spec.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-
-ruby_version_is ''...'2.5' do
- require 'mathn'
-
- describe "Integer.from_prime_division" do
- it "reverses a prime factorization of an integer" do
- Integer.from_prime_division([[2, 1], [3, 2], [7, 1]]).should == 126
- end
- end
-end
diff --git a/spec/ruby/library/mathn/integer/prime_division_spec.rb b/spec/ruby/library/mathn/integer/prime_division_spec.rb
deleted file mode 100644
index 63a5c39733..0000000000
--- a/spec/ruby/library/mathn/integer/prime_division_spec.rb
+++ /dev/null
@@ -1,21 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-
-ruby_version_is ''...'2.5' do
- require 'mathn'
-
- describe "Integer#prime_division" do
- it "performs a prime factorization of a positive integer" do
- 100.prime_division.should == [[2, 2], [5, 2]]
- end
-
- # Proper handling of negative integers has been added to MRI trunk
- # in revision 24091. Prior to that, all versions of MRI returned nonsense.
- it "performs a prime factorization of a negative integer" do
- -26.prime_division.should == [[-1, 1], [2, 1], [13, 1]]
- end
-
- it "raises a ZeroDivisionError when is called on zero" do
- lambda { 0.prime_division }.should raise_error(ZeroDivisionError)
- end
- end
-end
diff --git a/spec/ruby/library/mathn/math/fixtures/classes.rb b/spec/ruby/library/mathn/math/fixtures/classes.rb
deleted file mode 100644
index 024732fa7a..0000000000
--- a/spec/ruby/library/mathn/math/fixtures/classes.rb
+++ /dev/null
@@ -1,3 +0,0 @@
-class IncludesMath
- include Math
-end
diff --git a/spec/ruby/library/mathn/math/rsqrt_spec.rb b/spec/ruby/library/mathn/math/rsqrt_spec.rb
deleted file mode 100644
index a49efa6ff9..0000000000
--- a/spec/ruby/library/mathn/math/rsqrt_spec.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-
-ruby_version_is ''...'2.5' do
- require File.expand_path('../shared/rsqrt', __FILE__)
-
- describe "Math#rsqrt" do
- it_behaves_like :mathn_math_rsqrt, :_, IncludesMath.new
-
- it "is a private instance method" do
- IncludesMath.should have_private_instance_method(:rsqrt)
- end
- end
-
- describe "Math.rsqrt" do
- it_behaves_like :mathn_math_rsqrt, :_, Math
- end
-end
diff --git a/spec/ruby/library/mathn/math/shared/rsqrt.rb b/spec/ruby/library/mathn/math/shared/rsqrt.rb
deleted file mode 100644
index 68e2f7d02f..0000000000
--- a/spec/ruby/library/mathn/math/shared/rsqrt.rb
+++ /dev/null
@@ -1,21 +0,0 @@
-require 'mathn'
-require File.expand_path('../../fixtures/classes', __FILE__)
-
-describe :mathn_math_rsqrt, shared: true do
- it "returns the square root for Rational numbers" do
- @object.send(:rsqrt, Rational(9, 25)).should == Rational(3, 5)
- @object.send(:rsqrt, 16/64).should == Rational(1, 2)
- end
-
- it "returns the square root for positive numbers" do
- @object.send(:rsqrt, 1).should == 1
- @object.send(:rsqrt, 4.0).should == 2.0
- @object.send(:rsqrt, 12.34).should == Math.sqrt!(12.34)
- end
-
- it "raises an Math::DomainError if the argument is a negative number" do
- lambda { @object.send(:rsqrt, -1) }.should raise_error(Math::DomainError)
- lambda { @object.send(:rsqrt, -4.0) }.should raise_error(Math::DomainError)
- lambda { @object.send(:rsqrt, -16/64) }.should raise_error(Math::DomainError)
- end
-end
diff --git a/spec/ruby/library/mathn/math/shared/sqrt.rb b/spec/ruby/library/mathn/math/shared/sqrt.rb
deleted file mode 100644
index 6aab25fc5d..0000000000
--- a/spec/ruby/library/mathn/math/shared/sqrt.rb
+++ /dev/null
@@ -1,25 +0,0 @@
-require 'mathn'
-require File.expand_path('../../fixtures/classes', __FILE__)
-
-describe :mathn_math_sqrt, shared: true do
- it "returns the square root for Rational numbers" do
- @object.send(:sqrt, Rational(9, 25)).should == Rational(3, 5)
- @object.send(:sqrt, 16/64).should == Rational(1, 2)
- end
-
- it "returns the square root for Complex numbers" do
- @object.send(:sqrt, Complex(1, 0)).should == 1
- end
-
- it "returns the square root for positive numbers" do
- @object.send(:sqrt, 1).should == 1
- @object.send(:sqrt, 4.0).should == 2.0
- @object.send(:sqrt, 12.34).should == Math.sqrt!(12.34)
- end
-
- it "returns the square root for negative numbers" do
- @object.send(:sqrt, -9).should == Complex(0, 3)
- @object.send(:sqrt, -5.29).should == Complex(0, 2.3)
- @object.send(:sqrt, -16/64).should == Complex(0, 1/2)
- end
-end
diff --git a/spec/ruby/library/mathn/math/sqrt_spec.rb b/spec/ruby/library/mathn/math/sqrt_spec.rb
deleted file mode 100644
index b723360891..0000000000
--- a/spec/ruby/library/mathn/math/sqrt_spec.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-
-ruby_version_is ''...'2.5' do
- require File.expand_path('../shared/sqrt', __FILE__)
-
- describe "Math#rsqrt" do
- it_behaves_like :mathn_math_sqrt, :_, IncludesMath.new
-
- it "is a private instance method" do
- IncludesMath.should have_private_instance_method(:sqrt)
- end
- end
-
- describe "Math.rsqrt" do
- it_behaves_like :mathn_math_sqrt, :_, Math
- end
-end
diff --git a/spec/ruby/library/mathn/rational/Rational_spec.rb b/spec/ruby/library/mathn/rational/Rational_spec.rb
deleted file mode 100644
index 71433529c5..0000000000
--- a/spec/ruby/library/mathn/rational/Rational_spec.rb
+++ /dev/null
@@ -1,14 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-
-ruby_version_is ''...'2.5' do
- require 'mathn'
-
- describe "Kernel#Rational" do
- it "returns an Integer if denominator divides numerator evenly" do
- Rational(42,6).should == 7
- Rational(42,6).should be_kind_of(Fixnum)
- Rational(bignum_value,1).should == bignum_value
- Rational(bignum_value,1).should be_kind_of(Bignum)
- end
- end
-end
diff --git a/spec/ruby/library/mathn/rational/inspect_spec.rb b/spec/ruby/library/mathn/rational/inspect_spec.rb
deleted file mode 100644
index ce1205faaa..0000000000
--- a/spec/ruby/library/mathn/rational/inspect_spec.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-
-ruby_version_is ''...'2.5' do
- require 'mathn'
-
- describe "Rational#inspect" do
- it "returns a string representation of self" do
- Rational(3, 4).inspect.should == "(3/4)"
- Rational(-5, 8).inspect.should == "(-5/8)"
- Rational(-1, -2).inspect.should == "(1/2)"
- Rational(0, 2).inspect.should == "0"
- Rational(bignum_value, 1).inspect.should == "#{bignum_value}"
- end
- end
-end
diff --git a/spec/ruby/library/matrix/I_spec.rb b/spec/ruby/library/matrix/I_spec.rb
index f83cc3cec4..ca5e79279a 100644
--- a/spec/ruby/library/matrix/I_spec.rb
+++ b/spec/ruby/library/matrix/I_spec.rb
@@ -1,6 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/identity', __FILE__)
+require_relative '../../spec_helper'
+require 'matrix'
describe "Matrix.I" do
- it_behaves_like(:matrix_identity, :I)
+ it "is an alias of Matrix.identity" do
+ Matrix.method(:I).should == Matrix.method(:identity)
+ end
end
diff --git a/spec/ruby/library/matrix/antisymmetric_spec.rb b/spec/ruby/library/matrix/antisymmetric_spec.rb
new file mode 100644
index 0000000000..b4b8858f32
--- /dev/null
+++ b/spec/ruby/library/matrix/antisymmetric_spec.rb
@@ -0,0 +1,36 @@
+require_relative '../../spec_helper'
+
+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 == true
+ end
+
+ it "returns true for a 0x0 empty matrix" do
+ Matrix.empty.antisymmetric?.should == 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 == false
+ 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|
+ -> {
+ rectangular_matrix.antisymmetric?
+ }.should.raise(Matrix::ErrDimensionMismatch)
+ end
+ end
+end
diff --git a/spec/ruby/library/matrix/build_spec.rb b/spec/ruby/library/matrix/build_spec.rb
index 29fd72206f..49eb2e69a5 100644
--- a/spec/ruby/library/matrix/build_spec.rb
+++ b/spec/ruby/library/matrix/build_spec.rb
@@ -1,12 +1,12 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
require 'matrix'
describe "Matrix.build" do
it "returns a Matrix object of the given size" do
m = Matrix.build(3, 4){1}
- m.should be_an_instance_of(Matrix)
+ m.should.instance_of?(Matrix)
m.row_size.should == 3
m.column_size.should == 4
end
@@ -24,32 +24,32 @@ describe "Matrix.build" do
it "returns an Enumerator is no block is given" do
enum = Matrix.build(2, 1)
- enum.should be_an_instance_of(Enumerator)
+ enum.should.instance_of?(Enumerator)
enum.each{1}.should == Matrix[[1], [1]]
end
it "requires integers as parameters" do
- lambda { Matrix.build("1", "2"){1} }.should raise_error(TypeError)
- lambda { Matrix.build(nil, nil){1} }.should raise_error(TypeError)
- lambda { Matrix.build(1..2){1} }.should raise_error(TypeError)
+ -> { Matrix.build("1", "2"){1} }.should.raise(TypeError)
+ -> { Matrix.build(nil, nil){1} }.should.raise(TypeError)
+ -> { Matrix.build(1..2){1} }.should.raise(TypeError)
end
it "requires non-negative integers" do
- lambda { Matrix.build(-1, 1){1} }.should raise_error(ArgumentError)
- lambda { Matrix.build(+1,-1){1} }.should raise_error(ArgumentError)
+ -> { Matrix.build(-1, 1){1} }.should.raise(ArgumentError)
+ -> { Matrix.build(+1,-1){1} }.should.raise(ArgumentError)
end
it "returns empty Matrix if one argument is zero" do
m = Matrix.build(0, 3){
raise "Should not yield"
}
- m.should be_empty
+ m.should.empty?
m.column_size.should == 3
m = Matrix.build(3, 0){
raise "Should not yield"
}
- m.should be_empty
+ m.should.empty?
m.row_size.should == 3
end
@@ -68,6 +68,6 @@ end
describe "for a subclass of Matrix" do
it "returns an instance of that subclass" do
- MatrixSub.build(3){1}.should be_an_instance_of(MatrixSub)
+ MatrixSub.build(3){1}.should.instance_of?(MatrixSub)
end
end
diff --git a/spec/ruby/library/matrix/clone_spec.rb b/spec/ruby/library/matrix/clone_spec.rb
index 8819fc9b40..51aefc6010 100644
--- a/spec/ruby/library/matrix/clone_spec.rb
+++ b/spec/ruby/library/matrix/clone_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
require 'matrix'
describe "Matrix#clone" do
@@ -9,17 +9,17 @@ describe "Matrix#clone" do
it "returns a shallow copy of the matrix" do
b = @a.clone
- @a.should_not equal(b)
- b.should be_kind_of(Matrix)
+ @a.should_not.equal?(b)
+ b.should.is_a?(Matrix)
b.should == @a
0.upto(@a.row_size - 1) do |i|
- @a.row(i).should_not equal(b.row(i))
+ @a.row(i).should_not.equal?(b.row(i))
end
end
describe "for a subclass of Matrix" do
it "returns an instance of that subclass" do
- MatrixSub.ins.clone.should be_an_instance_of(MatrixSub)
+ MatrixSub.ins.clone.should.instance_of?(MatrixSub)
end
end
end
diff --git a/spec/ruby/library/matrix/coerce_spec.rb b/spec/ruby/library/matrix/coerce_spec.rb
index 6e653315a6..6032dd2f62 100644
--- a/spec/ruby/library/matrix/coerce_spec.rb
+++ b/spec/ruby/library/matrix/coerce_spec.rb
@@ -1,10 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'matrix'
describe "Matrix#coerce" do
- it "needs to be reviewed for spec completeness"
-
- it "allows the division of fixnum by a Matrix " do
+ it "allows the division of integer by a Matrix" do
(1/Matrix[[0,1],[-1,0]]).should == Matrix[[0,-1],[1,0]]
end
end
diff --git a/spec/ruby/library/matrix/collect_spec.rb b/spec/ruby/library/matrix/collect_spec.rb
index 1830aed103..664c3f3038 100644
--- a/spec/ruby/library/matrix/collect_spec.rb
+++ b/spec/ruby/library/matrix/collect_spec.rb
@@ -1,6 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/collect', __FILE__)
+require_relative '../../spec_helper'
+require 'matrix'
describe "Matrix#collect" do
- it_behaves_like(:collect, :collect)
+ it "is an alias of Matrix#map" do
+ Matrix.instance_method(:collect).should == Matrix.instance_method(:map)
+ end
end
diff --git a/spec/ruby/library/matrix/column_size_spec.rb b/spec/ruby/library/matrix/column_size_spec.rb
index b1aae01bbc..041914e5b9 100644
--- a/spec/ruby/library/matrix/column_size_spec.rb
+++ b/spec/ruby/library/matrix/column_size_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'matrix'
describe "Matrix#column_size" do
diff --git a/spec/ruby/library/matrix/column_spec.rb b/spec/ruby/library/matrix/column_spec.rb
index de84e33e8d..d5d8c80c1a 100644
--- a/spec/ruby/library/matrix/column_spec.rb
+++ b/spec/ruby/library/matrix/column_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'matrix'
describe "Matrix#column" do
@@ -21,7 +21,7 @@ describe "Matrix#column" do
end
it "returns self when called with a block" do
- @m.column(0) { |x| x }.should equal(@m)
+ @m.column(0) { |x| x }.should.equal?(@m)
end
it "returns nil when out of bounds" do
@@ -29,7 +29,7 @@ describe "Matrix#column" do
end
it "never yields when out of bounds" do
- lambda { @m.column(3){ raise } }.should_not raise_error
- lambda { @m.column(-4){ raise } }.should_not raise_error
+ -> { @m.column(3){ raise } }.should_not.raise
+ -> { @m.column(-4){ raise } }.should_not.raise
end
end
diff --git a/spec/ruby/library/matrix/column_vector_spec.rb b/spec/ruby/library/matrix/column_vector_spec.rb
index f0cc46d646..d86c3f9e42 100644
--- a/spec/ruby/library/matrix/column_vector_spec.rb
+++ b/spec/ruby/library/matrix/column_vector_spec.rb
@@ -1,25 +1,25 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
require 'matrix'
describe "Matrix.column_vector" do
it "returns a single column Matrix when called with an Array" do
m = Matrix.column_vector([4,5,6])
- m.should be_an_instance_of(Matrix)
+ m.should.instance_of?(Matrix)
m.should == Matrix[ [4],[5],[6] ]
end
it "returns an empty Matrix when called with an empty Array" do
m = Matrix.column_vector([])
- m.should be_an_instance_of(Matrix)
+ m.should.instance_of?(Matrix)
m.row_size.should == 0
m.column_size.should == 1
end
describe "for a subclass of Matrix" do
it "returns an instance of that subclass" do
- MatrixSub.column_vector([4,5,6]).should be_an_instance_of(MatrixSub)
+ MatrixSub.column_vector([4,5,6]).should.instance_of?(MatrixSub)
end
end
end
diff --git a/spec/ruby/library/matrix/column_vectors_spec.rb b/spec/ruby/library/matrix/column_vectors_spec.rb
index 8af64f83c8..7ac6871e7f 100644
--- a/spec/ruby/library/matrix/column_vectors_spec.rb
+++ b/spec/ruby/library/matrix/column_vectors_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'matrix'
describe "Matrix#column_vectors" do
@@ -8,11 +8,11 @@ describe "Matrix#column_vectors" do
end
it "returns an Array" do
- Matrix[ [1,2], [3,4] ].column_vectors.should be_an_instance_of(Array)
+ Matrix[ [1,2], [3,4] ].column_vectors.should.instance_of?(Array)
end
it "returns an Array of Vectors" do
- @vectors.all? {|v| v.should be_an_instance_of(Vector)}
+ @vectors.all? {|v| v.should.instance_of?(Vector)}
end
it "returns each column as a Vector" do
diff --git a/spec/ruby/library/matrix/columns_spec.rb b/spec/ruby/library/matrix/columns_spec.rb
index b5fd5633bf..ac9587899d 100644
--- a/spec/ruby/library/matrix/columns_spec.rb
+++ b/spec/ruby/library/matrix/columns_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
require 'matrix'
describe "Matrix.columns" do
@@ -10,7 +10,7 @@ describe "Matrix.columns" do
end
it "creates a Matrix from argument columns" do
- @m.should be_an_instance_of(Matrix)
+ @m.should.instance_of?(Matrix)
@m.column(0).to_a.should == @a
@m.column(1).to_a.should == @b
end
@@ -36,7 +36,7 @@ describe "Matrix.columns" do
describe "for a subclass of Matrix" do
it "returns an instance of that subclass" do
- MatrixSub.columns([[1]]).should be_an_instance_of(MatrixSub)
+ MatrixSub.columns([[1]]).should.instance_of?(MatrixSub)
end
end
end
diff --git a/spec/ruby/library/matrix/conj_spec.rb b/spec/ruby/library/matrix/conj_spec.rb
index 33221f7055..eff5986fc4 100644
--- a/spec/ruby/library/matrix/conj_spec.rb
+++ b/spec/ruby/library/matrix/conj_spec.rb
@@ -1,6 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/conjugate', __FILE__)
+require_relative '../../spec_helper'
+require 'matrix'
describe "Matrix#conj" do
- it_behaves_like(:matrix_conjugate, :conj)
+ it "is an alias of Matrix#conjugate" do
+ Matrix.instance_method(:conj).should == Matrix.instance_method(:conjugate)
+ end
end
diff --git a/spec/ruby/library/matrix/conjugate_spec.rb b/spec/ruby/library/matrix/conjugate_spec.rb
index fd19f7689c..46077d4fa9 100644
--- a/spec/ruby/library/matrix/conjugate_spec.rb
+++ b/spec/ruby/library/matrix/conjugate_spec.rb
@@ -1,6 +1,20 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/conjugate', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Matrix#conjugate" do
- it_behaves_like(:matrix_conjugate, :conjugate)
+ it "returns a matrix with all entries 'conjugated'" do
+ Matrix[ [1, 2], [3, 4] ].conjugate.should == Matrix[ [1, 2], [3, 4] ]
+ Matrix[ [1.9, Complex(1,1)], [3, 4] ].conjugate.should == Matrix[ [1.9, Complex(1,-1)], [3, 4] ]
+ end
+
+ it "returns empty matrices on the same size if empty" do
+ Matrix.empty(0, 3).conjugate.should == Matrix.empty(0, 3)
+ Matrix.empty(3, 0).conjugate.should == Matrix.empty(3, 0)
+ end
+
+ describe "for a subclass of Matrix" do
+ it "returns an instance of that subclass" do
+ MatrixSub.ins.conjugate.should.instance_of?(MatrixSub)
+ end
+ end
end
diff --git a/spec/ruby/library/matrix/constructor_spec.rb b/spec/ruby/library/matrix/constructor_spec.rb
index ae707166cd..026525f36d 100644
--- a/spec/ruby/library/matrix/constructor_spec.rb
+++ b/spec/ruby/library/matrix/constructor_spec.rb
@@ -1,14 +1,14 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
require 'matrix'
describe "Matrix.[]" do
it "requires arrays as parameters" do
- lambda { Matrix[5] }.should raise_error(TypeError)
- lambda { Matrix[nil] }.should raise_error(TypeError)
- lambda { Matrix[1..2] }.should raise_error(TypeError)
- lambda { Matrix[[1, 2], 3] }.should raise_error(TypeError)
+ -> { Matrix[5] }.should.raise(TypeError)
+ -> { Matrix[nil] }.should.raise(TypeError)
+ -> { Matrix[1..2] }.should.raise(TypeError)
+ -> { Matrix[[1, 2], 3] }.should.raise(TypeError)
end
it "creates an empty Matrix with no arguments" do
@@ -18,15 +18,13 @@ describe "Matrix.[]" do
end
it "raises for non-rectangular matrices" do
- lambda{ Matrix[ [0], [0,1] ] }.should \
- raise_error(Matrix::ErrDimensionMismatch)
- lambda{ Matrix[ [0,1], [0,1,2], [0,1] ]}.should \
- raise_error(Matrix::ErrDimensionMismatch)
+ ->{ Matrix[ [0], [0,1] ] }.should.raise(Matrix::ErrDimensionMismatch)
+ ->{ Matrix[ [0,1], [0,1,2], [0,1] ]}.should.raise(Matrix::ErrDimensionMismatch)
end
it "accepts vector arguments" do
a = Matrix[Vector[1, 2], Vector[3, 4]]
- a.should be_an_instance_of(Matrix)
+ a.should.instance_of?(Matrix)
a.should == Matrix[ [1, 2], [3, 4] ]
end
@@ -38,7 +36,7 @@ describe "Matrix.[]" do
it "returns a Matrix object" do
- Matrix[ [1] ].should be_an_instance_of(Matrix)
+ Matrix[ [1] ].should.instance_of?(Matrix)
end
it "can create an nxn Matrix" do
@@ -59,7 +57,7 @@ describe "Matrix.[]" do
describe "for a subclass of Matrix" do
it "returns an instance of that subclass" do
- MatrixSub[ [20,30], [40.5, 9] ].should be_an_instance_of(MatrixSub)
+ MatrixSub[ [20,30], [40.5, 9] ].should.instance_of?(MatrixSub)
end
end
end
diff --git a/spec/ruby/library/matrix/det_spec.rb b/spec/ruby/library/matrix/det_spec.rb
index 698de34fd1..fc4b1c252a 100644
--- a/spec/ruby/library/matrix/det_spec.rb
+++ b/spec/ruby/library/matrix/det_spec.rb
@@ -1,7 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/determinant', __FILE__)
+require_relative '../../spec_helper'
require 'matrix'
describe "Matrix#det" do
- it_behaves_like(:determinant, :det)
+ it "is an alias of Matrix#determinant" do
+ Matrix.instance_method(:det).should == Matrix.instance_method(:determinant)
+ end
end
diff --git a/spec/ruby/library/matrix/determinant_spec.rb b/spec/ruby/library/matrix/determinant_spec.rb
index 9ad34c6fc3..603e13ba28 100644
--- a/spec/ruby/library/matrix/determinant_spec.rb
+++ b/spec/ruby/library/matrix/determinant_spec.rb
@@ -1,7 +1,39 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/determinant', __FILE__)
+require_relative '../../spec_helper'
require 'matrix'
describe "Matrix#determinant" do
- it_behaves_like(:determinant, :determinant)
+ it "returns the determinant of a square Matrix" do
+ m = Matrix[ [7,6], [3,9] ]
+ m.determinant.should == 45
+
+ m = Matrix[ [9, 8], [6,5] ]
+ m.determinant.should == -3
+
+ m = Matrix[ [9,8,3], [4,20,5], [1,1,1] ]
+ m.determinant.should == 95
+ end
+
+ it "returns the determinant of a single-element Matrix" do
+ m = Matrix[ [2] ]
+ m.determinant.should == 2
+ end
+
+ it "returns 1 for an empty Matrix" do
+ m = Matrix[ ]
+ m.determinant.should == 1
+ end
+
+ it "returns the determinant even for Matrices containing 0 as first entry" do
+ Matrix[[0,1],[1,0]].determinant.should == -1
+ end
+
+ it "raises an error for rectangular matrices" do
+ -> {
+ Matrix[[1], [2], [3]].determinant
+ }.should.raise(Matrix::ErrDimensionMismatch)
+
+ -> {
+ Matrix.empty(3,0).determinant
+ }.should.raise(Matrix::ErrDimensionMismatch)
+ end
end
diff --git a/spec/ruby/library/matrix/diagonal_spec.rb b/spec/ruby/library/matrix/diagonal_spec.rb
index ddf5a8d292..ee84ac8c28 100644
--- a/spec/ruby/library/matrix/diagonal_spec.rb
+++ b/spec/ruby/library/matrix/diagonal_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
require 'matrix'
describe "Matrix.diagonal" do
@@ -8,7 +8,7 @@ describe "Matrix.diagonal" do
end
it "returns an object of type Matrix" do
- @m.should be_kind_of(Matrix)
+ @m.should.is_a?(Matrix)
end
it "returns a square Matrix of the right size" do
@@ -34,27 +34,27 @@ describe "Matrix.diagonal" do
describe "for a subclass of Matrix" do
it "returns an instance of that subclass" do
- MatrixSub.diagonal(1).should be_an_instance_of(MatrixSub)
+ MatrixSub.diagonal(1).should.instance_of?(MatrixSub)
end
end
end
describe "Matrix.diagonal?" do
it "returns true for a diagonal Matrix" do
- Matrix.diagonal([1, 2, 3]).diagonal?.should be_true
+ Matrix.diagonal([1, 2, 3]).diagonal?.should == true
end
it "returns true for a zero square Matrix" do
- Matrix.zero(3).diagonal?.should be_true
+ Matrix.zero(3).diagonal?.should == true
end
it "returns false for a non diagonal square Matrix" do
- Matrix[[0, 1], [0, 0]].diagonal?.should be_false
- Matrix[[1, 2, 3], [1, 2, 3], [1, 2, 3]].diagonal?.should be_false
+ Matrix[[0, 1], [0, 0]].diagonal?.should == false
+ Matrix[[1, 2, 3], [1, 2, 3], [1, 2, 3]].diagonal?.should == false
end
it "returns true for an empty 0x0 matrix" do
- Matrix.empty(0,0).diagonal?.should be_true
+ Matrix.empty(0,0).diagonal?.should == true
end
it "raises an error for rectangular matrices" do
@@ -64,9 +64,9 @@ describe "Matrix.diagonal?" do
Matrix.empty(0, 2),
Matrix.empty(2, 0),
].each do |rectangular_matrix|
- lambda {
+ -> {
rectangular_matrix.diagonal?
- }.should raise_error(Matrix::ErrDimensionMismatch)
+ }.should.raise(Matrix::ErrDimensionMismatch)
end
end
end
diff --git a/spec/ruby/library/matrix/divide_spec.rb b/spec/ruby/library/matrix/divide_spec.rb
index b602d7d10f..711a5189e4 100644
--- a/spec/ruby/library/matrix/divide_spec.rb
+++ b/spec/ruby/library/matrix/divide_spec.rb
@@ -1,6 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'spec_helper'
+require_relative 'fixtures/classes'
require 'matrix'
describe "Matrix#/" do
@@ -14,13 +14,12 @@ describe "Matrix#/" do
(@a / @b).should be_close_to_matrix([[2.5, -1.5], [1.5, -0.5]])
end
- conflicts_with :Prime do
+ # Guard against the Mathn library
+ guard -> { !defined?(Math.rsqrt) } do
it "returns the result of dividing self by a Fixnum" do
(@a / 2).should == Matrix[ [0, 1], [1, 2] ]
end
- end
- conflicts_with :Prime do
it "returns the result of dividing self by a Bignum" do
(@a / bignum_value).should == Matrix[ [0, 0], [0, 0] ]
end
@@ -31,25 +30,25 @@ describe "Matrix#/" do
end
it "raises a Matrix::ErrDimensionMismatch if the matrices are different sizes" do
- lambda { @a / Matrix[ [1] ] }.should raise_error(Matrix::ErrDimensionMismatch)
+ -> { @a / Matrix[ [1] ] }.should.raise(Matrix::ErrDimensionMismatch)
end
it "returns an instance of Matrix" do
- (@a / @b).should be_kind_of(Matrix)
+ (@a / @b).should.is_a?(Matrix)
end
describe "for a subclass of Matrix" do
it "returns an instance of that subclass" do
m = MatrixSub.ins
- (m/m).should be_an_instance_of(MatrixSub)
- (m/1).should be_an_instance_of(MatrixSub)
+ (m/m).should.instance_of?(MatrixSub)
+ (m/1).should.instance_of?(MatrixSub)
end
end
it "raises a TypeError if other is of wrong type" do
- lambda { @a / nil }.should raise_error(TypeError)
- lambda { @a / "a" }.should raise_error(TypeError)
- lambda { @a / [ [1, 2] ] }.should raise_error(TypeError)
- lambda { @a / Object.new }.should raise_error(TypeError)
+ -> { @a / nil }.should.raise(TypeError)
+ -> { @a / "a" }.should.raise(TypeError)
+ -> { @a / [ [1, 2] ] }.should.raise(TypeError)
+ -> { @a / Object.new }.should.raise(TypeError)
end
end
diff --git a/spec/ruby/library/matrix/each_spec.rb b/spec/ruby/library/matrix/each_spec.rb
index 18875692e6..b4bfd3c76f 100644
--- a/spec/ruby/library/matrix/each_spec.rb
+++ b/spec/ruby/library/matrix/each_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'matrix'
describe "Matrix#each" do
@@ -9,12 +9,12 @@ describe "Matrix#each" do
it "returns an Enumerator when called without a block" do
enum = @m.each
- enum.should be_an_instance_of(Enumerator)
+ enum.should.instance_of?(Enumerator)
enum.to_a.should == @result
end
it "returns self" do
- @m.each{}.should equal(@m)
+ @m.each{}.should.equal?(@m)
end
it "yields the elements starting with the those of the first row" do
@@ -31,15 +31,15 @@ describe "Matrix#each with an argument" do
end
it "raises an ArgumentError for unrecognized argument" do
- lambda {
+ -> {
@m.each("all"){}
- }.should raise_error(ArgumentError)
- lambda {
+ }.should.raise(ArgumentError)
+ -> {
@m.each(nil){}
- }.should raise_error(ArgumentError)
- lambda {
+ }.should.raise(ArgumentError)
+ -> {
@m.each(:left){}
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
end
it "yields the rights elements when passed :diagonal" do
diff --git a/spec/ruby/library/matrix/each_with_index_spec.rb b/spec/ruby/library/matrix/each_with_index_spec.rb
index 796a6c2a96..17e3f3f44c 100644
--- a/spec/ruby/library/matrix/each_with_index_spec.rb
+++ b/spec/ruby/library/matrix/each_with_index_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'matrix'
describe "Matrix#each_with_index" do
@@ -16,12 +16,12 @@ describe "Matrix#each_with_index" do
it "returns an Enumerator when called without a block" do
enum = @m.each_with_index
- enum.should be_an_instance_of(Enumerator)
+ enum.should.instance_of?(Enumerator)
enum.to_a.should == @result
end
it "returns self" do
- @m.each_with_index{}.should equal(@m)
+ @m.each_with_index{}.should.equal?(@m)
end
it "yields the elements starting with the those of the first row" do
@@ -38,15 +38,15 @@ describe "Matrix#each_with_index with an argument" do
end
it "raises an ArgumentError for unrecognized argument" do
- lambda {
+ -> {
@m.each_with_index("all"){}
- }.should raise_error(ArgumentError)
- lambda {
+ }.should.raise(ArgumentError)
+ -> {
@m.each_with_index(nil){}
- }.should raise_error(ArgumentError)
- lambda {
+ }.should.raise(ArgumentError)
+ -> {
@m.each_with_index(:left){}
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
end
it "yields the rights elements when passed :diagonal" do
diff --git a/spec/ruby/library/matrix/eigenvalue_decomposition/eigenvalue_matrix_spec.rb b/spec/ruby/library/matrix/eigenvalue_decomposition/eigenvalue_matrix_spec.rb
index 3443eeaaf9..67f9dd1c19 100644
--- a/spec/ruby/library/matrix/eigenvalue_decomposition/eigenvalue_matrix_spec.rb
+++ b/spec/ruby/library/matrix/eigenvalue_decomposition/eigenvalue_matrix_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'matrix'
describe "Matrix::EigenvalueDecomposition#eigenvalue_matrix" do
diff --git a/spec/ruby/library/matrix/eigenvalue_decomposition/eigenvalues_spec.rb b/spec/ruby/library/matrix/eigenvalue_decomposition/eigenvalues_spec.rb
index c175a29947..7552b7616c 100644
--- a/spec/ruby/library/matrix/eigenvalue_decomposition/eigenvalues_spec.rb
+++ b/spec/ruby/library/matrix/eigenvalue_decomposition/eigenvalues_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'matrix'
describe "Matrix::EigenvalueDecomposition#eigenvalues" do
@@ -8,7 +8,7 @@ describe "Matrix::EigenvalueDecomposition#eigenvalues" do
[ Complex(1, -1), Complex(1, 1)]
end
- it "returns an array of real eigenvalues for a symetric matrix" do
+ it "returns an array of real eigenvalues for a symmetric matrix" do
Matrix[[1, 2],
[2, 1]].eigensystem.eigenvalues.sort.map!{|x| x.round(10)}.should ==
[ -1, 3 ]
diff --git a/spec/ruby/library/matrix/eigenvalue_decomposition/eigenvector_matrix_spec.rb b/spec/ruby/library/matrix/eigenvalue_decomposition/eigenvector_matrix_spec.rb
index 709ec68d0c..09f229ee15 100644
--- a/spec/ruby/library/matrix/eigenvalue_decomposition/eigenvector_matrix_spec.rb
+++ b/spec/ruby/library/matrix/eigenvalue_decomposition/eigenvector_matrix_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'matrix'
describe "Matrix::EigenvalueDecomposition#eigenvector_matrix" do
@@ -10,7 +10,7 @@ describe "Matrix::EigenvalueDecomposition#eigenvector_matrix" do
[Complex(0, 1), Complex(0, -1)]]
end
- it "returns an real eigenvector matrix for a symetric matrix" do
+ it "returns an real eigenvector matrix for a symmetric matrix" do
# Fix me: should test for linearity, not for equality
Matrix[[1, 2],
[2, 1]].eigensystem.eigenvector_matrix.should ==
diff --git a/spec/ruby/library/matrix/eigenvalue_decomposition/eigenvectors_spec.rb b/spec/ruby/library/matrix/eigenvalue_decomposition/eigenvectors_spec.rb
index 163bebe709..2b6ce74ea8 100644
--- a/spec/ruby/library/matrix/eigenvalue_decomposition/eigenvectors_spec.rb
+++ b/spec/ruby/library/matrix/eigenvalue_decomposition/eigenvectors_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'matrix'
describe "Matrix::EigenvalueDecomposition#eigenvectors" do
@@ -11,7 +11,7 @@ describe "Matrix::EigenvalueDecomposition#eigenvectors" do
]
end
- it "returns an array of real eigenvectors for a symetric matrix" do
+ it "returns an array of real eigenvectors for a symmetric matrix" do
# Fix me: should test for linearity, not for equality
Matrix[[1, 2],
[2, 1]].eigensystem.eigenvectors.should ==
diff --git a/spec/ruby/library/matrix/eigenvalue_decomposition/initialize_spec.rb b/spec/ruby/library/matrix/eigenvalue_decomposition/initialize_spec.rb
index 97d9be8f2d..cbda82a16a 100644
--- a/spec/ruby/library/matrix/eigenvalue_decomposition/initialize_spec.rb
+++ b/spec/ruby/library/matrix/eigenvalue_decomposition/initialize_spec.rb
@@ -1,20 +1,20 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'matrix'
describe "Matrix::EigenvalueDecomposition#initialize" do
it "raises an error if argument is not a matrix" do
- lambda {
+ -> {
Matrix::EigenvalueDecomposition.new([[]])
- }.should raise_error(TypeError)
- lambda {
+ }.should.raise(TypeError)
+ -> {
Matrix::EigenvalueDecomposition.new(42)
- }.should raise_error(TypeError)
+ }.should.raise(TypeError)
end
it "raises an error if matrix is not square" do
- lambda {
+ -> {
Matrix::EigenvalueDecomposition.new(Matrix[[1, 2]])
- }.should raise_error(Matrix::ErrDimensionMismatch)
+ }.should.raise(Matrix::ErrDimensionMismatch)
end
it "never hangs" do
diff --git a/spec/ruby/library/matrix/eigenvalue_decomposition/to_a_spec.rb b/spec/ruby/library/matrix/eigenvalue_decomposition/to_a_spec.rb
index e9b849eb97..8be41a5720 100644
--- a/spec/ruby/library/matrix/eigenvalue_decomposition/to_a_spec.rb
+++ b/spec/ruby/library/matrix/eigenvalue_decomposition/to_a_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'matrix'
describe "Matrix::EigenvalueDecomposition#to_a" do
diff --git a/spec/ruby/library/matrix/element_reference_spec.rb b/spec/ruby/library/matrix/element_reference_spec.rb
index f4f63c0f65..c6804b3846 100644
--- a/spec/ruby/library/matrix/element_reference_spec.rb
+++ b/spec/ruby/library/matrix/element_reference_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'matrix'
describe "Matrix#[]" do
@@ -16,8 +16,8 @@ describe "Matrix#[]" do
end
it "returns nil for an invalid index pair" do
- @m[8,1].should be_nil
- @m[1,8].should be_nil
+ @m[8,1].should == nil
+ @m[1,8].should == nil
end
end
diff --git a/spec/ruby/library/matrix/empty_spec.rb b/spec/ruby/library/matrix/empty_spec.rb
index cead6126ff..7b0f0af9eb 100644
--- a/spec/ruby/library/matrix/empty_spec.rb
+++ b/spec/ruby/library/matrix/empty_spec.rb
@@ -1,23 +1,23 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
require 'matrix'
describe "Matrix#empty?" do
it "returns true when the Matrix is empty" do
- Matrix[ ].empty?.should be_true
- Matrix[ [], [], [] ].empty?.should be_true
- Matrix[ [], [], [] ].transpose.empty?.should be_true
+ Matrix[ ].empty?.should == true
+ Matrix[ [], [], [] ].empty?.should == true
+ Matrix[ [], [], [] ].transpose.empty?.should == true
end
it "returns false when the Matrix has elements" do
- Matrix[ [1, 2] ].empty?.should be_false
- Matrix[ [1], [2] ].empty?.should be_false
+ Matrix[ [1, 2] ].empty?.should == false
+ Matrix[ [1], [2] ].empty?.should == false
end
it "doesn't accept any parameter" do
- lambda{
+ ->{
Matrix[ [1, 2] ].empty?(42)
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
end
end
@@ -38,31 +38,31 @@ describe "Matrix.empty" do
end
it "does not accept more than two parameters" do
- lambda{
+ ->{
Matrix.empty(1, 2, 3)
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
end
it "raises an error if both dimensions are > 0" do
- lambda{
+ ->{
Matrix.empty(1, 2)
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
end
it "raises an error if any dimension is < 0" do
- lambda{
+ ->{
Matrix.empty(-2, 0)
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
- lambda{
+ ->{
Matrix.empty(0, -2)
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
end
end
describe "for a subclass of Matrix" do
it "returns an instance of that subclass" do
- MatrixSub.empty(0, 1).should be_an_instance_of(MatrixSub)
+ MatrixSub.empty(0, 1).should.instance_of?(MatrixSub)
end
end
diff --git a/spec/ruby/library/matrix/eql_spec.rb b/spec/ruby/library/matrix/eql_spec.rb
index e76d26753a..cda122f4d8 100644
--- a/spec/ruby/library/matrix/eql_spec.rb
+++ b/spec/ruby/library/matrix/eql_spec.rb
@@ -1,11 +1,11 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/equal_value', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/equal_value'
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
+ Matrix[[1, 2],[3, 4]].eql?(Matrix[[1, 2],[3, 4.0]]).should == false
end
end
diff --git a/spec/ruby/library/matrix/equal_value_spec.rb b/spec/ruby/library/matrix/equal_value_spec.rb
index e14a38b872..10cf1e6c29 100644
--- a/spec/ruby/library/matrix/equal_value_spec.rb
+++ b/spec/ruby/library/matrix/equal_value_spec.rb
@@ -1,9 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/equal_value', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/equal_value'
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/exponent_spec.rb b/spec/ruby/library/matrix/exponent_spec.rb
index 188a1b34d2..4cbe63587d 100644
--- a/spec/ruby/library/matrix/exponent_spec.rb
+++ b/spec/ruby/library/matrix/exponent_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
require 'matrix'
describe "Matrix#**" do
@@ -17,21 +17,32 @@ describe "Matrix#**" do
it "raises a ErrDimensionMismatch for non square matrices" do
m = Matrix[ [1, 1], [1, 2], [2, 3]]
- lambda { m ** 3 }.should raise_error(Matrix::ErrDimensionMismatch)
- lambda { m ** 0 }.should raise_error(Matrix::ErrDimensionMismatch)
+ -> { m ** 3 }.should.raise(Matrix::ErrDimensionMismatch)
+ -> { m ** 0 }.should.raise(Matrix::ErrDimensionMismatch)
end
- describe "that is <= 0" do
+ describe "that is < 0" do
it "returns the inverse of **(-n)" do
m = Matrix[ [1, 1], [1, 2] ]
(m ** -2).should == Matrix[ [5, -3], [-3, 2]]
(m ** -4).should == (m.inverse ** 4)
end
- it "raises a ErrDimensionMismatch for irregular matrices" do
+ it "raises a ErrNotRegular for irregular matrices" do
m = Matrix[ [1, 1], [1, 1] ]
- lambda { m ** -2 }.should raise_error(Matrix::ErrNotRegular)
- lambda { m ** 0 }.should raise_error(Matrix::ErrNotRegular)
+ -> { m ** -2 }.should.raise(Matrix::ErrNotRegular)
+ end
+ end
+
+ describe "that is 0" do
+ it "returns the identity for square matrices" do
+ m = Matrix[ [1, 1], [1, 1] ]
+ (m ** 0).should == Matrix.identity(2)
+ end
+
+ it "raises an ErrDimensionMismatch for non-square matrices" do
+ m = Matrix[ [1, 1] ]
+ -> { m ** 0 }.should.raise(Matrix::ErrDimensionMismatch)
end
end
end
@@ -45,7 +56,7 @@ describe "Matrix#**" do
describe "for a subclass of Matrix" do
it "returns an instance of that subclass" do
- (MatrixSub.ins ** 1).should be_an_instance_of(MatrixSub)
+ (MatrixSub.ins ** 1).should.instance_of?(MatrixSub)
end
end
end
diff --git a/spec/ruby/library/matrix/find_index_spec.rb b/spec/ruby/library/matrix/find_index_spec.rb
index 8ea891644a..c7278fd449 100644
--- a/spec/ruby/library/matrix/find_index_spec.rb
+++ b/spec/ruby/library/matrix/find_index_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'matrix'
describe "Matrix#find_index without any argument" do
@@ -8,12 +8,12 @@ describe "Matrix#find_index without any argument" do
it "returns an Enumerator when called without a block" do
enum = @m.find_index
- enum.should be_an_instance_of(Enumerator)
+ enum.should.instance_of?(Enumerator)
enum.to_a.should == [1, 2, 3, 4, 5, 6, 7, 8]
end
it "returns nil if the block is always false" do
- @m.find_index{false}.should be_nil
+ @m.find_index{false}.should == nil
end
it "returns the first index for which the block is true" do
@@ -48,7 +48,7 @@ describe "Matrix#find_index with a subselection argument" do
it "returns an Enumerator when called without a block" do
@tests.each do |matrix, h|
h.each do |selector, result|
- matrix.find_index(selector).should be_an_instance_of(Enumerator)
+ matrix.find_index(selector).should.instance_of?(Enumerator)
end
end
end
@@ -116,7 +116,7 @@ describe "Matrix#find_index with only a generic argument" do
end
it "returns nil if the value is not found" do
- @m.find_index(42).should be_nil
+ @m.find_index(42).should == nil
end
it "returns the first index for of the requested value" do
@@ -130,17 +130,17 @@ end
describe "Matrix#find_index with two arguments" do
it "raises an ArgumentError for an unrecognized last argument" do
- lambda {
+ -> {
@m.find_index(1, "all"){}
- }.should raise_error(ArgumentError)
- lambda {
+ }.should.raise(ArgumentError)
+ -> {
@m.find_index(1, nil){}
- }.should raise_error(ArgumentError)
- lambda {
+ }.should.raise(ArgumentError)
+ -> {
@m.find_index(1, :left){}
- }.should raise_error(ArgumentError)
- lambda {
+ }.should.raise(ArgumentError)
+ -> {
@m.find_index(:diagonal, 1){}
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
end
end
diff --git a/spec/ruby/library/matrix/hash_spec.rb b/spec/ruby/library/matrix/hash_spec.rb
index b2e5b579b7..27bf7b9751 100644
--- a/spec/ruby/library/matrix/hash_spec.rb
+++ b/spec/ruby/library/matrix/hash_spec.rb
@@ -1,10 +1,10 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'matrix'
describe "Matrix#hash" do
- it "returns a Fixnum" do
- Matrix[ [1,2] ].hash.should be_an_instance_of(Fixnum)
+ it "returns an Integer" do
+ Matrix[ [1,2] ].hash.should.instance_of?(Integer)
end
it "returns the same value for the same matrix" do
diff --git a/spec/ruby/library/matrix/hermitian_spec.rb b/spec/ruby/library/matrix/hermitian_spec.rb
index e108ba1e34..94d0dbe6b6 100644
--- a/spec/ruby/library/matrix/hermitian_spec.rb
+++ b/spec/ruby/library/matrix/hermitian_spec.rb
@@ -1,17 +1,17 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'matrix'
describe "Matrix.hermitian?" do
it "returns true for a hermitian Matrix" do
- Matrix[[1, 2, Complex(0, 3)], [2, 4, 5], [Complex(0, -3), 5, 6]].hermitian?.should be_true
+ Matrix[[1, 2, Complex(0, 3)], [2, 4, 5], [Complex(0, -3), 5, 6]].hermitian?.should == true
end
it "returns true for a 0x0 empty matrix" do
- Matrix.empty.hermitian?.should be_true
+ Matrix.empty.hermitian?.should == true
end
it "returns false for an asymmetric Matrix" do
- Matrix[[1, 2],[-2, 1]].hermitian?.should be_false
+ Matrix[[1, 2],[-2, 1]].hermitian?.should == false
end
it "raises an error for rectangular matrices" do
@@ -21,14 +21,14 @@ describe "Matrix.hermitian?" do
Matrix.empty(0, 2),
Matrix.empty(2, 0),
].each do |rectangular_matrix|
- lambda {
+ -> {
rectangular_matrix.hermitian?
- }.should raise_error(Matrix::ErrDimensionMismatch)
+ }.should.raise(Matrix::ErrDimensionMismatch)
end
end
it "returns false for a matrix with complex values on the diagonal" do
- Matrix[[Complex(1,1)]].hermitian?.should be_false
- Matrix[[Complex(1,0)]].hermitian?.should be_true
+ Matrix[[Complex(1,1)]].hermitian?.should == false
+ Matrix[[Complex(1,0)]].hermitian?.should == true
end
end
diff --git a/spec/ruby/library/matrix/identity_spec.rb b/spec/ruby/library/matrix/identity_spec.rb
index bc7df98dde..afefd27565 100644
--- a/spec/ruby/library/matrix/identity_spec.rb
+++ b/spec/ruby/library/matrix/identity_spec.rb
@@ -1,6 +1,20 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/identity', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require 'matrix'
describe "Matrix.identity" do
- it_behaves_like(:matrix_identity, :identity)
+ it "returns a Matrix" do
+ Matrix.identity(2).should.is_a?(Matrix)
+ end
+
+ it "returns a n x n identity matrix" do
+ Matrix.identity(3).should == Matrix.scalar(3, 1)
+ Matrix.identity(100).should == Matrix.scalar(100, 1)
+ end
+
+ describe "for a subclass of Matrix" do
+ it "returns an instance of that subclass" do
+ MatrixSub.identity(2).should.instance_of?(MatrixSub)
+ end
+ end
end
diff --git a/spec/ruby/library/matrix/imag_spec.rb b/spec/ruby/library/matrix/imag_spec.rb
index 41083879e4..9d6cc2e953 100644
--- a/spec/ruby/library/matrix/imag_spec.rb
+++ b/spec/ruby/library/matrix/imag_spec.rb
@@ -1,6 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/imaginary', __FILE__)
+require_relative '../../spec_helper'
+require 'matrix'
describe "Matrix#imag" do
- it_behaves_like(:matrix_imaginary, :imag)
+ it "is an alias of Matrix#imaginary" do
+ Matrix.instance_method(:imag).should == Matrix.instance_method(:imaginary)
+ end
end
diff --git a/spec/ruby/library/matrix/imaginary_spec.rb b/spec/ruby/library/matrix/imaginary_spec.rb
index 2a05f1d5c3..bbd06677b7 100644
--- a/spec/ruby/library/matrix/imaginary_spec.rb
+++ b/spec/ruby/library/matrix/imaginary_spec.rb
@@ -1,6 +1,21 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/imaginary', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require 'matrix'
describe "Matrix#imaginary" do
- it_behaves_like(:matrix_imaginary, :imaginary)
+ it "returns a matrix with the imaginary part of the elements of the receiver" do
+ Matrix[ [1, 2], [3, 4] ].imaginary.should == Matrix[ [0, 0], [0, 0] ]
+ Matrix[ [1.9, Complex(1,1)], [Complex(-2,0.42), 4] ].imaginary.should == Matrix[ [0, 1], [0.42, 0] ]
+ end
+
+ it "returns empty matrices on the same size if empty" do
+ Matrix.empty(0, 3).imaginary.should == Matrix.empty(0, 3)
+ Matrix.empty(3, 0).imaginary.should == Matrix.empty(3, 0)
+ end
+
+ describe "for a subclass of Matrix" do
+ it "returns an instance of that subclass" do
+ MatrixSub.ins.imaginary.should.instance_of?(MatrixSub)
+ end
+ end
end
diff --git a/spec/ruby/library/matrix/inspect_spec.rb b/spec/ruby/library/matrix/inspect_spec.rb
index bf623e1a85..508f478252 100644
--- a/spec/ruby/library/matrix/inspect_spec.rb
+++ b/spec/ruby/library/matrix/inspect_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
require 'matrix'
describe "Matrix#inspect" do
diff --git a/spec/ruby/library/matrix/inv_spec.rb b/spec/ruby/library/matrix/inv_spec.rb
index 0491aa7b07..02684030d2 100644
--- a/spec/ruby/library/matrix/inv_spec.rb
+++ b/spec/ruby/library/matrix/inv_spec.rb
@@ -1,7 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../spec_helper', __FILE__)
-require File.expand_path('../shared/inverse', __FILE__)
+require_relative '../../spec_helper'
+require 'matrix'
describe "Matrix#inv" do
- it_behaves_like(:inverse, :inv)
+ it "is an alias of Matrix#inverse" do
+ Matrix.instance_method(:inv).should == Matrix.instance_method(:inverse)
+ end
end
diff --git a/spec/ruby/library/matrix/inverse_from_spec.rb b/spec/ruby/library/matrix/inverse_from_spec.rb
index 958b3b7408..651d56a244 100644
--- a/spec/ruby/library/matrix/inverse_from_spec.rb
+++ b/spec/ruby/library/matrix/inverse_from_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'matrix'
describe "Matrix#inverse_from" do
diff --git a/spec/ruby/library/matrix/inverse_spec.rb b/spec/ruby/library/matrix/inverse_spec.rb
index 33a1f2f5de..38b01b28fb 100644
--- a/spec/ruby/library/matrix/inverse_spec.rb
+++ b/spec/ruby/library/matrix/inverse_spec.rb
@@ -1,7 +1,39 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../spec_helper', __FILE__)
-require File.expand_path('../shared/inverse', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'spec_helper'
+require_relative 'fixtures/classes'
+require 'matrix'
describe "Matrix#inverse" do
- it_behaves_like(:inverse, :inverse)
+ it "returns a Matrix" do
+ Matrix[ [1,2], [2,1] ].inverse.should.instance_of?(Matrix)
+ end
+
+ it "returns the inverse of the Matrix" do
+ Matrix[
+ [1, 3, 3], [1, 4, 3], [1, 3, 4]
+ ].inverse.should ==
+ Matrix[
+ [7, -3, -3], [-1, 1, 0], [-1, 0, 1]
+ ]
+ end
+
+ it "returns the inverse of the Matrix (other case)" do
+ Matrix[
+ [1, 2, 3], [0, 1, 4], [5, 6, 0]
+ ].inverse.should be_close_to_matrix([
+ [-24, 18, 5], [20, -15, -4], [-5, 4, 1]
+ ])
+ end
+
+ it "raises a ErrDimensionMismatch if the Matrix is not square" do
+ ->{
+ Matrix[ [1,2,3], [1,2,3] ].inverse
+ }.should.raise(Matrix::ErrDimensionMismatch)
+ end
+
+ describe "for a subclass of Matrix" do
+ it "returns an instance of that subclass" do
+ MatrixSub.ins.inverse.should.instance_of?(MatrixSub)
+ end
+ end
end
diff --git a/spec/ruby/library/matrix/lower_triangular_spec.rb b/spec/ruby/library/matrix/lower_triangular_spec.rb
index 62b3df2104..7e8688fd9b 100644
--- a/spec/ruby/library/matrix/lower_triangular_spec.rb
+++ b/spec/ruby/library/matrix/lower_triangular_spec.rb
@@ -1,24 +1,24 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'matrix'
describe "Matrix.lower_triangular?" do
it "returns true for a square lower triangular Matrix" do
- Matrix[[1, 0, 0], [1, 2, 0], [1, 2, 3]].lower_triangular?.should be_true
- Matrix.diagonal([1, 2, 3]).lower_triangular?.should be_true
- Matrix[[1, 0], [1, 2], [1, 2], [1, 2]].lower_triangular?.should be_true
- Matrix[[1, 0, 0, 0], [1, 2, 0, 0]].lower_triangular?.should be_true
+ Matrix[[1, 0, 0], [1, 2, 0], [1, 2, 3]].lower_triangular?.should == true
+ Matrix.diagonal([1, 2, 3]).lower_triangular?.should == true
+ Matrix[[1, 0], [1, 2], [1, 2], [1, 2]].lower_triangular?.should == true
+ Matrix[[1, 0, 0, 0], [1, 2, 0, 0]].lower_triangular?.should == true
end
it "returns true for an empty Matrix" do
- Matrix.empty(3, 0).lower_triangular?.should be_true
- Matrix.empty(0, 3).lower_triangular?.should be_true
- Matrix.empty(0, 0).lower_triangular?.should be_true
+ Matrix.empty(3, 0).lower_triangular?.should == true
+ Matrix.empty(0, 3).lower_triangular?.should == true
+ Matrix.empty(0, 0).lower_triangular?.should == true
end
it "returns false for a non lower triangular square Matrix" do
- Matrix[[0, 1], [0, 0]].lower_triangular?.should be_false
- Matrix[[1, 2, 3], [1, 2, 3], [1, 2, 3]].lower_triangular?.should be_false
- Matrix[[0, 1], [0, 0], [0, 0], [0, 0]].lower_triangular?.should be_false
- Matrix[[0, 0, 0, 1], [0, 0, 0, 0]].lower_triangular?.should be_false
+ Matrix[[0, 1], [0, 0]].lower_triangular?.should == false
+ Matrix[[1, 2, 3], [1, 2, 3], [1, 2, 3]].lower_triangular?.should == false
+ Matrix[[0, 1], [0, 0], [0, 0], [0, 0]].lower_triangular?.should == false
+ Matrix[[0, 0, 0, 1], [0, 0, 0, 0]].lower_triangular?.should == false
end
end
diff --git a/spec/ruby/library/matrix/lup_decomposition/determinant_spec.rb b/spec/ruby/library/matrix/lup_decomposition/determinant_spec.rb
index f73c65ba8f..98ac5c71a3 100644
--- a/spec/ruby/library/matrix/lup_decomposition/determinant_spec.rb
+++ b/spec/ruby/library/matrix/lup_decomposition/determinant_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'matrix'
describe "Matrix::LUPDecomposition#determinant" do
@@ -13,9 +13,9 @@ describe "Matrix::LUPDecomposition#determinant" do
Matrix[[7, 8], [14, 46], [28, 82]],
].each do |m|
lup = m.lup
- lambda {
+ -> {
lup.determinant
- }.should raise_error(Matrix::ErrDimensionMismatch)
+ }.should.raise(Matrix::ErrDimensionMismatch)
end
end
end
diff --git a/spec/ruby/library/matrix/lup_decomposition/initialize_spec.rb b/spec/ruby/library/matrix/lup_decomposition/initialize_spec.rb
index 953389083f..b813757525 100644
--- a/spec/ruby/library/matrix/lup_decomposition/initialize_spec.rb
+++ b/spec/ruby/library/matrix/lup_decomposition/initialize_spec.rb
@@ -1,13 +1,13 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'matrix'
describe "Matrix::LUPDecomposition#initialize" do
it "raises an error if argument is not a matrix" do
- lambda {
+ -> {
Matrix::LUPDecomposition.new([[]])
- }.should raise_error(TypeError)
- lambda {
+ }.should.raise(TypeError)
+ -> {
Matrix::LUPDecomposition.new(42)
- }.should raise_error(TypeError)
+ }.should.raise(TypeError)
end
end
diff --git a/spec/ruby/library/matrix/lup_decomposition/l_spec.rb b/spec/ruby/library/matrix/lup_decomposition/l_spec.rb
index c50b5f712e..0a6797cc85 100644
--- a/spec/ruby/library/matrix/lup_decomposition/l_spec.rb
+++ b/spec/ruby/library/matrix/lup_decomposition/l_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'matrix'
describe "Matrix::LUPDecomposition#l" do
@@ -13,6 +13,6 @@ describe "Matrix::LUPDecomposition#l" do
end
it "returns a lower triangular matrix" do
- @l.lower_triangular?.should be_true
+ @l.lower_triangular?.should == true
end
end
diff --git a/spec/ruby/library/matrix/lup_decomposition/p_spec.rb b/spec/ruby/library/matrix/lup_decomposition/p_spec.rb
index 837b65a915..2c44399b79 100644
--- a/spec/ruby/library/matrix/lup_decomposition/p_spec.rb
+++ b/spec/ruby/library/matrix/lup_decomposition/p_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'matrix'
describe "Matrix::LUPDecomposition#p" do
@@ -13,6 +13,6 @@ describe "Matrix::LUPDecomposition#p" do
end
it "returns a permutation matrix" do
- @p.permutation?.should be_true
+ @p.permutation?.should == true
end
end
diff --git a/spec/ruby/library/matrix/lup_decomposition/solve_spec.rb b/spec/ruby/library/matrix/lup_decomposition/solve_spec.rb
index c4ef42bcea..9927e96727 100644
--- a/spec/ruby/library/matrix/lup_decomposition/solve_spec.rb
+++ b/spec/ruby/library/matrix/lup_decomposition/solve_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'matrix'
describe "Matrix::LUPDecomposition#solve" do
@@ -6,9 +6,9 @@ describe "Matrix::LUPDecomposition#solve" do
it "raises an error for singular matrices" do
a = Matrix[[1, 2, 3], [1, 3, 5], [2, 5, 8]]
lu = Matrix::LUPDecomposition.new(a)
- lambda {
+ -> {
lu.solve(a)
- }.should raise_error(Matrix::ErrNotRegular)
+ }.should.raise(Matrix::ErrNotRegular)
end
describe "for non singular matrices" do
@@ -31,9 +31,9 @@ describe "Matrix::LUPDecomposition#solve" do
it "raises an error when given a matrix of the wrong size" do
values = Matrix[[1, 2, 3, 4], [0, 1, 2, 3]]
- lambda {
+ -> {
@lu.solve(values)
- }.should raise_error(Matrix::ErrDimensionMismatch)
+ }.should.raise(Matrix::ErrDimensionMismatch)
end
it "returns the right vector when given a vector of the appropriate size" do
@@ -44,9 +44,9 @@ describe "Matrix::LUPDecomposition#solve" do
it "raises an error when given a vector of the wrong size" do
values = Vector[14, 55]
- lambda {
+ -> {
@lu.solve(values)
- }.should raise_error(Matrix::ErrDimensionMismatch)
+ }.should.raise(Matrix::ErrDimensionMismatch)
end
end
end
diff --git a/spec/ruby/library/matrix/lup_decomposition/to_a_spec.rb b/spec/ruby/library/matrix/lup_decomposition/to_a_spec.rb
index 20be26eb9c..ab59677dd9 100644
--- a/spec/ruby/library/matrix/lup_decomposition/to_a_spec.rb
+++ b/spec/ruby/library/matrix/lup_decomposition/to_a_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'matrix'
describe "Matrix::LUPDecomposition#to_a" do
@@ -10,9 +10,9 @@ describe "Matrix::LUPDecomposition#to_a" do
end
it "returns an array of three matrices" do
- @to_a.should be_kind_of(Array)
+ @to_a.should.is_a?(Array)
@to_a.length.should == 3
- @to_a.each{|m| m.should be_kind_of(Matrix)}
+ @to_a.each{|m| m.should.is_a?(Matrix)}
end
it "returns [l, u, p] such that l*u == a*p" do
diff --git a/spec/ruby/library/matrix/lup_decomposition/u_spec.rb b/spec/ruby/library/matrix/lup_decomposition/u_spec.rb
index 97e8580c58..967bc669dc 100644
--- a/spec/ruby/library/matrix/lup_decomposition/u_spec.rb
+++ b/spec/ruby/library/matrix/lup_decomposition/u_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'matrix'
describe "Matrix::LUPDecomposition#u" do
@@ -13,6 +13,6 @@ describe "Matrix::LUPDecomposition#u" do
end
it "returns an upper triangular matrix" do
- @u.upper_triangular?.should be_true
+ @u.upper_triangular?.should == true
end
end
diff --git a/spec/ruby/library/matrix/map_spec.rb b/spec/ruby/library/matrix/map_spec.rb
index e18ab6eb7a..bae96db381 100644
--- a/spec/ruby/library/matrix/map_spec.rb
+++ b/spec/ruby/library/matrix/map_spec.rb
@@ -1,6 +1,26 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/collect', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Matrix#map" do
- it_behaves_like(:collect, :map)
+ before :all do
+ @m = Matrix[ [1, 2], [1, 2] ]
+ end
+
+ it "returns an instance of Matrix" do
+ @m.map{|n| n * 2 }.should.is_a?(Matrix)
+ end
+
+ it "returns a Matrix where each element is the result of the block" do
+ @m.map { |n| n * 2 }.should == Matrix[ [2, 4], [2, 4] ]
+ end
+
+ it "returns an enumerator if no block is given" do
+ @m.map.should.instance_of?(Enumerator)
+ end
+
+ describe "for a subclass of Matrix" do
+ it "returns an instance of that subclass" do
+ MatrixSub.ins.map{1}.should.instance_of?(MatrixSub)
+ end
+ end
end
diff --git a/spec/ruby/library/matrix/minor_spec.rb b/spec/ruby/library/matrix/minor_spec.rb
index e02e0de07d..6b29db568b 100644
--- a/spec/ruby/library/matrix/minor_spec.rb
+++ b/spec/ruby/library/matrix/minor_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
require 'matrix'
describe "Matrix#minor" do
@@ -79,7 +79,7 @@ describe "Matrix#minor" do
describe "for a subclass of Matrix" do
it "returns an instance of that subclass" do
- MatrixSub.ins.minor(0, 1, 0, 1).should be_an_instance_of(MatrixSub)
+ MatrixSub.ins.minor(0, 1, 0, 1).should.instance_of?(MatrixSub)
end
end
end
diff --git a/spec/ruby/library/matrix/minus_spec.rb b/spec/ruby/library/matrix/minus_spec.rb
index fe2d716882..7426aa2d2c 100644
--- a/spec/ruby/library/matrix/minus_spec.rb
+++ b/spec/ruby/library/matrix/minus_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
require 'matrix'
describe "Matrix#-" do
@@ -13,30 +13,30 @@ describe "Matrix#-" do
end
it "returns an instance of Matrix" do
- (@a - @b).should be_kind_of(Matrix)
+ (@a - @b).should.is_a?(Matrix)
end
it "raises a Matrix::ErrDimensionMismatch if the matrices are different sizes" do
- lambda { @a - Matrix[ [1] ] }.should raise_error(Matrix::ErrDimensionMismatch)
+ -> { @a - Matrix[ [1] ] }.should.raise(Matrix::ErrDimensionMismatch)
end
it "raises a ExceptionForMatrix::ErrOperationNotDefined if other is a Numeric Type" do
- lambda { @a - 2 }.should raise_error(Matrix::ErrOperationNotDefined)
- lambda { @a - 1.2 }.should raise_error(Matrix::ErrOperationNotDefined)
- lambda { @a - bignum_value }.should raise_error(Matrix::ErrOperationNotDefined)
+ -> { @a - 2 }.should.raise(Matrix::ErrOperationNotDefined)
+ -> { @a - 1.2 }.should.raise(Matrix::ErrOperationNotDefined)
+ -> { @a - bignum_value }.should.raise(Matrix::ErrOperationNotDefined)
end
it "raises a TypeError if other is of wrong type" do
- lambda { @a - nil }.should raise_error(TypeError)
- lambda { @a - "a" }.should raise_error(TypeError)
- lambda { @a - [ [1, 2] ] }.should raise_error(TypeError)
- lambda { @a - Object.new }.should raise_error(TypeError)
+ -> { @a - nil }.should.raise(TypeError)
+ -> { @a - "a" }.should.raise(TypeError)
+ -> { @a - [ [1, 2] ] }.should.raise(TypeError)
+ -> { @a - Object.new }.should.raise(TypeError)
end
describe "for a subclass of Matrix" do
it "returns an instance of that subclass" do
m = MatrixSub.ins
- (m-m).should be_an_instance_of(MatrixSub)
+ (m-m).should.instance_of?(MatrixSub)
end
end
end
diff --git a/spec/ruby/library/matrix/multiply_spec.rb b/spec/ruby/library/matrix/multiply_spec.rb
index dae87f5434..6c495c5521 100644
--- a/spec/ruby/library/matrix/multiply_spec.rb
+++ b/spec/ruby/library/matrix/multiply_spec.rb
@@ -1,5 +1,6 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+
+require_relative 'fixtures/classes'
require 'matrix'
describe "Matrix#*" do
@@ -22,8 +23,8 @@ describe "Matrix#*" do
it "returns the result of multiplying the elements of self and a Bignum" do
(@a * bignum_value).should == Matrix[
- [9223372036854775808, 18446744073709551616],
- [27670116110564327424, 36893488147419103232]
+ [18446744073709551616, 36893488147419103232],
+ [55340232221128654848, 73786976294838206464]
]
end
@@ -32,7 +33,7 @@ describe "Matrix#*" do
end
it "raises a Matrix::ErrDimensionMismatch if the matrices are different sizes" do
- lambda { @a * Matrix[ [1] ] }.should raise_error(Matrix::ErrDimensionMismatch)
+ -> { @a * Matrix[ [1] ] }.should.raise(Matrix::ErrDimensionMismatch)
end
it "returns a zero matrix if (nx0) * (0xn)" do
@@ -52,17 +53,17 @@ describe "Matrix#*" do
end
it "raises a TypeError if other is of wrong type" do
- lambda { @a * nil }.should raise_error(TypeError)
- lambda { @a * "a" }.should raise_error(TypeError)
- lambda { @a * [ [1, 2] ] }.should raise_error(TypeError)
- lambda { @a * Object.new }.should raise_error(TypeError)
+ -> { @a * nil }.should.raise(TypeError)
+ -> { @a * "a" }.should.raise(TypeError)
+ -> { @a * [ [1, 2] ] }.should.raise(TypeError)
+ -> { @a * Object.new }.should.raise(TypeError)
end
describe "for a subclass of Matrix" do
it "returns an instance of that subclass" do
m = MatrixSub.ins
- (m*m).should be_an_instance_of(MatrixSub)
- (m*1).should be_an_instance_of(MatrixSub)
+ (m*m).should.instance_of?(MatrixSub)
+ (m*1).should.instance_of?(MatrixSub)
end
end
end
diff --git a/spec/ruby/library/matrix/new_spec.rb b/spec/ruby/library/matrix/new_spec.rb
index 82d2bd88a7..bde9d9f4c8 100644
--- a/spec/ruby/library/matrix/new_spec.rb
+++ b/spec/ruby/library/matrix/new_spec.rb
@@ -1,8 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'matrix'
describe "Matrix.new" do
it "is private" do
- Matrix.should have_private_method(:new)
+ Matrix.private_methods(false).should.include?(:new)
end
end
diff --git a/spec/ruby/library/matrix/normal_spec.rb b/spec/ruby/library/matrix/normal_spec.rb
index 5f0b8e6362..420d4b011f 100644
--- a/spec/ruby/library/matrix/normal_spec.rb
+++ b/spec/ruby/library/matrix/normal_spec.rb
@@ -1,14 +1,14 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'matrix'
describe "Matrix.normal?" do
# it "returns false for non normal matrices" do
- # Matrix[[0, 1], [1, 2]].normal?.should == false
+ # Matrix[[0, 1], [1, 2]].should_not.normal?
# end
it "returns true for normal matrices" do
- Matrix[[1, 1, 0], [0, 1, 1], [1, 0, 1]].normal?.should == true
- Matrix[[0, Complex(0, 2)], [Complex(0, -2), 0]].normal?.should == true
+ Matrix[[1, 1, 0], [0, 1, 1], [1, 0, 1]].should.normal?
+ Matrix[[0, Complex(0, 2)], [Complex(0, -2), 0]].should.normal?
end
it "raises an error for rectangular matrices" do
@@ -18,9 +18,9 @@ describe "Matrix.normal?" do
Matrix.empty(0, 2),
Matrix.empty(2, 0),
].each do |rectangular_matrix|
- lambda {
+ -> {
rectangular_matrix.normal?
- }.should raise_error(Matrix::ErrDimensionMismatch)
+ }.should.raise(Matrix::ErrDimensionMismatch)
end
end
end
diff --git a/spec/ruby/library/matrix/orthogonal_spec.rb b/spec/ruby/library/matrix/orthogonal_spec.rb
index 78f5c1be5d..71ac831fe8 100644
--- a/spec/ruby/library/matrix/orthogonal_spec.rb
+++ b/spec/ruby/library/matrix/orthogonal_spec.rb
@@ -1,14 +1,14 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'matrix'
describe "Matrix.orthogonal?" do
it "returns false for non orthogonal matrices" do
- Matrix[[0, 1], [1, 2]].orthogonal?.should == false
- Matrix[[1, 1, 0], [0, 1, 1], [1, 0, 1]].orthogonal?.should == false
+ Matrix[[0, 1], [1, 2]].should_not.orthogonal?
+ Matrix[[1, 1, 0], [0, 1, 1], [1, 0, 1]].should_not.orthogonal?
end
it "returns true for orthogonal matrices" do
- Matrix[[0, 1], [1, 0]].orthogonal?.should == true
+ Matrix[[0, 1], [1, 0]].should.orthogonal?
end
it "raises an error for rectangular matrices" do
@@ -18,9 +18,9 @@ describe "Matrix.orthogonal?" do
Matrix.empty(0, 2),
Matrix.empty(2, 0),
].each do |rectangular_matrix|
- lambda {
+ -> {
rectangular_matrix.orthogonal?
- }.should raise_error(Matrix::ErrDimensionMismatch)
+ }.should.raise(Matrix::ErrDimensionMismatch)
end
end
end
diff --git a/spec/ruby/library/matrix/permutation_spec.rb b/spec/ruby/library/matrix/permutation_spec.rb
index f40de4f58f..43727edea1 100644
--- a/spec/ruby/library/matrix/permutation_spec.rb
+++ b/spec/ruby/library/matrix/permutation_spec.rb
@@ -1,20 +1,20 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'matrix'
describe "Matrix#permutation?" do
it "returns true for a permutation Matrix" do
- Matrix[[0, 1, 0], [0, 0, 1], [1, 0, 0]].permutation?.should be_true
+ Matrix[[0, 1, 0], [0, 0, 1], [1, 0, 0]].permutation?.should == true
end
it "returns false for a non permutation square Matrix" do
- Matrix[[0, 1], [0, 0]].permutation?.should be_false
- Matrix[[-1, 0], [0, -1]].permutation?.should be_false
- Matrix[[1, 0], [1, 0]].permutation?.should be_false
- Matrix[[1, 0], [1, 1]].permutation?.should be_false
+ Matrix[[0, 1], [0, 0]].permutation?.should == false
+ Matrix[[-1, 0], [0, -1]].permutation?.should == false
+ Matrix[[1, 0], [1, 0]].permutation?.should == false
+ Matrix[[1, 0], [1, 1]].permutation?.should == false
end
it "returns true for an empty 0x0 matrix" do
- Matrix.empty(0,0).permutation?.should be_true
+ Matrix.empty(0,0).permutation?.should == true
end
it "raises an error for rectangular matrices" do
@@ -24,9 +24,9 @@ describe "Matrix#permutation?" do
Matrix.empty(0, 2),
Matrix.empty(2, 0),
].each do |rectangular_matrix|
- lambda {
+ -> {
rectangular_matrix.permutation?
- }.should raise_error(Matrix::ErrDimensionMismatch)
+ }.should.raise(Matrix::ErrDimensionMismatch)
end
end
end
diff --git a/spec/ruby/library/matrix/plus_spec.rb b/spec/ruby/library/matrix/plus_spec.rb
index 59addfdf62..72a9ba8f8f 100644
--- a/spec/ruby/library/matrix/plus_spec.rb
+++ b/spec/ruby/library/matrix/plus_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
require 'matrix'
describe "Matrix#+" do
@@ -13,30 +13,30 @@ describe "Matrix#+" do
end
it "returns an instance of Matrix" do
- (@a + @b).should be_kind_of(Matrix)
+ (@a + @b).should.is_a?(Matrix)
end
it "raises a Matrix::ErrDimensionMismatch if the matrices are different sizes" do
- lambda { @a + Matrix[ [1] ] }.should raise_error(Matrix::ErrDimensionMismatch)
+ -> { @a + Matrix[ [1] ] }.should.raise(Matrix::ErrDimensionMismatch)
end
it "raises a ExceptionForMatrix::ErrOperationNotDefined if other is a Numeric Type" do
- lambda { @a + 2 }.should raise_error(ExceptionForMatrix::ErrOperationNotDefined)
- lambda { @a + 1.2 }.should raise_error(ExceptionForMatrix::ErrOperationNotDefined)
- lambda { @a + bignum_value }.should raise_error(ExceptionForMatrix::ErrOperationNotDefined)
+ -> { @a + 2 }.should.raise(ExceptionForMatrix::ErrOperationNotDefined)
+ -> { @a + 1.2 }.should.raise(ExceptionForMatrix::ErrOperationNotDefined)
+ -> { @a + bignum_value }.should.raise(ExceptionForMatrix::ErrOperationNotDefined)
end
it "raises a TypeError if other is of wrong type" do
- lambda { @a + nil }.should raise_error(TypeError)
- lambda { @a + "a" }.should raise_error(TypeError)
- lambda { @a + [ [1, 2] ] }.should raise_error(TypeError)
- lambda { @a + Object.new }.should raise_error(TypeError)
+ -> { @a + nil }.should.raise(TypeError)
+ -> { @a + "a" }.should.raise(TypeError)
+ -> { @a + [ [1, 2] ] }.should.raise(TypeError)
+ -> { @a + Object.new }.should.raise(TypeError)
end
describe "for a subclass of Matrix" do
it "returns an instance of that subclass" do
m = MatrixSub.ins
- (m+m).should be_an_instance_of(MatrixSub)
+ (m+m).should.instance_of?(MatrixSub)
end
end
end
diff --git a/spec/ruby/library/matrix/rank_spec.rb b/spec/ruby/library/matrix/rank_spec.rb
index 42b6de1ab8..d4403d23ed 100644
--- a/spec/ruby/library/matrix/rank_spec.rb
+++ b/spec/ruby/library/matrix/rank_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'matrix'
describe "Matrix#rank" do
diff --git a/spec/ruby/library/matrix/real_spec.rb b/spec/ruby/library/matrix/real_spec.rb
index 98da7f8a7c..4589dc22a5 100644
--- a/spec/ruby/library/matrix/real_spec.rb
+++ b/spec/ruby/library/matrix/real_spec.rb
@@ -1,24 +1,25 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
require 'matrix'
describe "Matrix#real?" do
it "returns true for matrices with all real entries" do
- Matrix[ [1, 2], [3, 4] ].real?.should be_true
- Matrix[ [1.9, 2], [3, 4] ].real?.should be_true
+ Matrix[ [1, 2], [3, 4] ].real?.should == true
+ Matrix[ [1.9, 2], [3, 4] ].real?.should == true
end
it "returns true for empty matrices" do
- Matrix.empty.real?.should be_true
+ Matrix.empty.real?.should == true
end
it "returns false if one element is a Complex" do
- Matrix[ [Complex(1,1), 2], [3, 4] ].real?.should be_false
+ Matrix[ [Complex(1,1), 2], [3, 4] ].real?.should == false
end
- conflicts_with :CMath do
+ # Guard against the Mathn library
+ guard -> { !defined?(Math.rsqrt) } do
it "returns false if one element is a Complex whose imaginary part is 0" do
- Matrix[ [Complex(1,0), 2], [3, 4] ].real?.should be_false
+ Matrix[ [Complex(1,0), 2], [3, 4] ].real?.should == false
end
end
end
@@ -36,7 +37,7 @@ describe "Matrix#real" do
describe "for a subclass of Matrix" do
it "returns an instance of that subclass" do
- MatrixSub.ins.real.should be_an_instance_of(MatrixSub)
+ MatrixSub.ins.real.should.instance_of?(MatrixSub)
end
end
end
diff --git a/spec/ruby/library/matrix/rect_spec.rb b/spec/ruby/library/matrix/rect_spec.rb
index d0a3b2705b..b0ca3f0421 100644
--- a/spec/ruby/library/matrix/rect_spec.rb
+++ b/spec/ruby/library/matrix/rect_spec.rb
@@ -1,6 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/rectangular', __FILE__)
+require_relative '../../spec_helper'
+require 'matrix'
describe "Matrix#rect" do
- it_behaves_like(:matrix_rectangular, :rect)
+ it "is an alias of Matrix#rectangular" do
+ Matrix.instance_method(:rect).should == Matrix.instance_method(:rectangular)
+ end
end
diff --git a/spec/ruby/library/matrix/rectangular_spec.rb b/spec/ruby/library/matrix/rectangular_spec.rb
index 7af446cb18..c0732f96bc 100644
--- a/spec/ruby/library/matrix/rectangular_spec.rb
+++ b/spec/ruby/library/matrix/rectangular_spec.rb
@@ -1,6 +1,19 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/rectangular', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require 'matrix'
describe "Matrix#rectangular" do
- it_behaves_like(:matrix_rectangular, :rectangular)
+ it "returns [receiver.real, receiver.imag]" do
+ m = Matrix[ [1.2, Complex(1,2)], [Complex(-2,0.42), 4] ]
+ m.rectangular.should == [m.real, m.imag]
+
+ m = Matrix.empty(3, 0)
+ m.rectangular.should == [m.real, m.imag]
+ end
+
+ describe "for a subclass of Matrix" do
+ it "returns instances of that subclass" do
+ MatrixSub.ins.rectangular.each{|m| m.should.instance_of?(MatrixSub) }
+ end
+ end
end
diff --git a/spec/ruby/library/matrix/regular_spec.rb b/spec/ruby/library/matrix/regular_spec.rb
index 2f0af99c1e..4cb00819ac 100644
--- a/spec/ruby/library/matrix/regular_spec.rb
+++ b/spec/ruby/library/matrix/regular_spec.rb
@@ -1,31 +1,31 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'matrix'
describe "Matrix#regular?" do
it "returns false for singular matrices" do
m = Matrix[ [1,2,3], [3,4,3], [0,0,0] ]
- m.regular?.should be_false
+ m.regular?.should == false
m = Matrix[ [1,2,9], [3,4,9], [1,2,9] ]
- m.regular?.should be_false
+ m.regular?.should == false
end
it "returns true if the Matrix is regular" do
- Matrix[ [0,1], [1,0] ].regular?.should be_true
+ Matrix[ [0,1], [1,0] ].regular?.should == true
end
it "returns true for an empty 0x0 matrix" do
- Matrix.empty(0,0).regular?.should be_true
+ Matrix.empty(0,0).regular?.should == true
end
it "raises an error for rectangular matrices" do
- lambda {
+ -> {
Matrix[[1], [2], [3]].regular?
- }.should raise_error(Matrix::ErrDimensionMismatch)
+ }.should.raise(Matrix::ErrDimensionMismatch)
- lambda {
+ -> {
Matrix.empty(3,0).regular?
- }.should raise_error(Matrix::ErrDimensionMismatch)
+ }.should.raise(Matrix::ErrDimensionMismatch)
end
end
diff --git a/spec/ruby/library/matrix/round_spec.rb b/spec/ruby/library/matrix/round_spec.rb
index f502a35c68..cdec646fa1 100644
--- a/spec/ruby/library/matrix/round_spec.rb
+++ b/spec/ruby/library/matrix/round_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
require 'matrix'
describe "Matrix#round" do
@@ -15,7 +15,7 @@ describe "Matrix#round" do
describe "for a subclass of Matrix" do
it "returns an instance of that subclass" do
- MatrixSub.ins.round.should be_an_instance_of(MatrixSub)
+ MatrixSub.ins.round.should.instance_of?(MatrixSub)
end
end
end
diff --git a/spec/ruby/library/matrix/row_size_spec.rb b/spec/ruby/library/matrix/row_size_spec.rb
index ee685ba5fb..eb3aef2e2f 100644
--- a/spec/ruby/library/matrix/row_size_spec.rb
+++ b/spec/ruby/library/matrix/row_size_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'matrix'
describe "Matrix#row_size" do
diff --git a/spec/ruby/library/matrix/row_spec.rb b/spec/ruby/library/matrix/row_spec.rb
index e165e48f5f..8a7662fdf2 100644
--- a/spec/ruby/library/matrix/row_spec.rb
+++ b/spec/ruby/library/matrix/row_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'matrix'
describe "Matrix#row" do
@@ -21,7 +21,7 @@ describe "Matrix#row" do
end
it "returns self when called with a block" do
- @m.row(0) { |x| x }.should equal(@m)
+ @m.row(0) { |x| x }.should.equal?(@m)
end
it "returns nil when out of bounds" do
@@ -30,7 +30,7 @@ describe "Matrix#row" do
end
it "never yields when out of bounds" do
- lambda { @m.row(3){ raise } }.should_not raise_error
- lambda { @m.row(-4){ raise } }.should_not raise_error
+ -> { @m.row(3){ raise } }.should_not.raise
+ -> { @m.row(-4){ raise } }.should_not.raise
end
end
diff --git a/spec/ruby/library/matrix/row_vector_spec.rb b/spec/ruby/library/matrix/row_vector_spec.rb
index 60907e9247..f3919fb7d8 100644
--- a/spec/ruby/library/matrix/row_vector_spec.rb
+++ b/spec/ruby/library/matrix/row_vector_spec.rb
@@ -1,11 +1,11 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
require 'matrix'
describe "Matrix.row_vector" do
it "returns a Matrix" do
- Matrix.row_vector([]).should be_an_instance_of(Matrix)
+ Matrix.row_vector([]).should.instance_of?(Matrix)
end
it "returns a single-row Matrix with the specified values" do
@@ -18,7 +18,7 @@ describe "Matrix.row_vector" do
describe "for a subclass of Matrix" do
it "returns an instance of that subclass" do
- MatrixSub.row_vector([1]).should be_an_instance_of(MatrixSub)
+ MatrixSub.row_vector([1]).should.instance_of?(MatrixSub)
end
end
end
diff --git a/spec/ruby/library/matrix/row_vectors_spec.rb b/spec/ruby/library/matrix/row_vectors_spec.rb
index 46f97bb748..4a0db67527 100644
--- a/spec/ruby/library/matrix/row_vectors_spec.rb
+++ b/spec/ruby/library/matrix/row_vectors_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'matrix'
describe "Matrix#row_vectors" do
@@ -8,11 +8,11 @@ describe "Matrix#row_vectors" do
end
it "returns an Array" do
- Matrix[ [1,2], [3,4] ].row_vectors.should be_an_instance_of(Array)
+ Matrix[ [1,2], [3,4] ].row_vectors.should.instance_of?(Array)
end
it "returns an Array of Vectors" do
- @vectors.all? {|v| v.should be_an_instance_of(Vector)}
+ @vectors.all? {|v| v.should.instance_of?(Vector)}
end
it "returns each row as a Vector" do
diff --git a/spec/ruby/library/matrix/rows_spec.rb b/spec/ruby/library/matrix/rows_spec.rb
index d583a07b30..9c248cd8a4 100644
--- a/spec/ruby/library/matrix/rows_spec.rb
+++ b/spec/ruby/library/matrix/rows_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
require 'matrix'
describe "Matrix.rows" do
@@ -10,7 +10,7 @@ describe "Matrix.rows" do
end
it "returns a Matrix" do
- @m.should be_kind_of(Matrix)
+ @m.should.is_a?(Matrix)
end
it "creates a matrix from argument rows" do
@@ -21,8 +21,8 @@ describe "Matrix.rows" do
it "copies the original rows by default" do
@a << 3
@b << 6
- @m.row(0).should_not equal(@a)
- @m.row(1).should_not equal(@b)
+ @m.row(0).should_not.equal?(@a)
+ @m.row(1).should_not.equal?(@b)
end
it "references the original rows if copy is false" do
@@ -35,7 +35,7 @@ describe "Matrix.rows" do
describe "for a subclass of Matrix" do
it "returns an instance of that subclass" do
- MatrixSub.rows([[0, 1], [0, 1]]).should be_an_instance_of(MatrixSub)
+ MatrixSub.rows([[0, 1], [0, 1]]).should.instance_of?(MatrixSub)
end
end
end
diff --git a/spec/ruby/library/matrix/scalar/Fail_spec.rb b/spec/ruby/library/matrix/scalar/Fail_spec.rb
index fbd0f3013a..9d8f9bd5e8 100644
--- a/spec/ruby/library/matrix/scalar/Fail_spec.rb
+++ b/spec/ruby/library/matrix/scalar/Fail_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'matrix'
describe "Matrix::Scalar#Fail" do
diff --git a/spec/ruby/library/matrix/scalar/Raise_spec.rb b/spec/ruby/library/matrix/scalar/Raise_spec.rb
index 3e98fcb22a..27e11c1f77 100644
--- a/spec/ruby/library/matrix/scalar/Raise_spec.rb
+++ b/spec/ruby/library/matrix/scalar/Raise_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'matrix'
describe "Matrix::Scalar#Raise" do
diff --git a/spec/ruby/library/matrix/scalar/divide_spec.rb b/spec/ruby/library/matrix/scalar/divide_spec.rb
index 6b8e0b6bcc..5d726943fe 100644
--- a/spec/ruby/library/matrix/scalar/divide_spec.rb
+++ b/spec/ruby/library/matrix/scalar/divide_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'matrix'
describe "Matrix::Scalar#/" do
diff --git a/spec/ruby/library/matrix/scalar/exponent_spec.rb b/spec/ruby/library/matrix/scalar/exponent_spec.rb
index 55997793eb..8e9ef52ff2 100644
--- a/spec/ruby/library/matrix/scalar/exponent_spec.rb
+++ b/spec/ruby/library/matrix/scalar/exponent_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'matrix'
describe "Matrix::Scalar#**" do
diff --git a/spec/ruby/library/matrix/scalar/included_spec.rb b/spec/ruby/library/matrix/scalar/included_spec.rb
index 58ee233eb3..cb3beb2ecd 100644
--- a/spec/ruby/library/matrix/scalar/included_spec.rb
+++ b/spec/ruby/library/matrix/scalar/included_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'matrix'
describe "Matrix::Scalar.included" do
diff --git a/spec/ruby/library/matrix/scalar/initialize_spec.rb b/spec/ruby/library/matrix/scalar/initialize_spec.rb
index fd6ef00211..23145ad0de 100644
--- a/spec/ruby/library/matrix/scalar/initialize_spec.rb
+++ b/spec/ruby/library/matrix/scalar/initialize_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'matrix'
describe "Matrix::Scalar#initialize" do
diff --git a/spec/ruby/library/matrix/scalar/minus_spec.rb b/spec/ruby/library/matrix/scalar/minus_spec.rb
index 19a7b4f1a1..c727ea1659 100644
--- a/spec/ruby/library/matrix/scalar/minus_spec.rb
+++ b/spec/ruby/library/matrix/scalar/minus_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'matrix'
describe "Matrix::Scalar#-" do
diff --git a/spec/ruby/library/matrix/scalar/multiply_spec.rb b/spec/ruby/library/matrix/scalar/multiply_spec.rb
index 247cc1447c..1a2a83d83e 100644
--- a/spec/ruby/library/matrix/scalar/multiply_spec.rb
+++ b/spec/ruby/library/matrix/scalar/multiply_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'matrix'
describe "Matrix::Scalar#*" do
diff --git a/spec/ruby/library/matrix/scalar/plus_spec.rb b/spec/ruby/library/matrix/scalar/plus_spec.rb
index 7cdaa1c7f3..c94689a702 100644
--- a/spec/ruby/library/matrix/scalar/plus_spec.rb
+++ b/spec/ruby/library/matrix/scalar/plus_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'matrix'
describe "Matrix::Scalar#+" do
diff --git a/spec/ruby/library/matrix/scalar_spec.rb b/spec/ruby/library/matrix/scalar_spec.rb
index 3da8771471..5b93b60533 100644
--- a/spec/ruby/library/matrix/scalar_spec.rb
+++ b/spec/ruby/library/matrix/scalar_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'matrix'
describe "Matrix.scalar" do
@@ -10,7 +10,7 @@ describe "Matrix.scalar" do
end
it "returns a Matrix" do
- @a.should be_kind_of(Matrix)
+ @a.should.is_a?(Matrix)
end
it "returns a n x n matrix" do
@@ -41,7 +41,7 @@ describe "Matrix.scalar" do
end
it "returns a Matrix" do
- @a.should be_kind_of(Matrix)
+ @a.should.is_a?(Matrix)
end
it "returns a square matrix, where the first argument specifies the side of the square" do
diff --git a/spec/ruby/library/matrix/shared/collect.rb b/spec/ruby/library/matrix/shared/collect.rb
deleted file mode 100644
index 256cd6a190..0000000000
--- a/spec/ruby/library/matrix/shared/collect.rb
+++ /dev/null
@@ -1,26 +0,0 @@
-require File.expand_path('../../fixtures/classes', __FILE__)
-require 'matrix'
-
-describe :collect, shared: true do
- before :all do
- @m = Matrix[ [1, 2], [1, 2] ]
- end
-
- it "returns an instance of Matrix" do
- @m.send(@method){|n| n * 2 }.should be_kind_of(Matrix)
- end
-
- it "returns a Matrix where each element is the result of the block" do
- @m.send(@method) { |n| n * 2 }.should == Matrix[ [2, 4], [2, 4] ]
- end
-
- it "returns an enumerator if no block is given" do
- @m.send(@method).should be_an_instance_of(Enumerator)
- end
-
- describe "for a subclass of Matrix" do
- it "returns an instance of that subclass" do
- MatrixSub.ins.send(@method){1}.should be_an_instance_of(MatrixSub)
- end
- end
-end
diff --git a/spec/ruby/library/matrix/shared/conjugate.rb b/spec/ruby/library/matrix/shared/conjugate.rb
deleted file mode 100644
index 180ff4fa98..0000000000
--- a/spec/ruby/library/matrix/shared/conjugate.rb
+++ /dev/null
@@ -1,20 +0,0 @@
-require File.expand_path('../../fixtures/classes', __FILE__)
-require 'matrix'
-
-describe :matrix_conjugate, shared: true do
- it "returns a matrix with all entries 'conjugated'" do
- Matrix[ [1, 2], [3, 4] ].send(@method).should == Matrix[ [1, 2], [3, 4] ]
- Matrix[ [1.9, Complex(1,1)], [3, 4] ].send(@method).should == Matrix[ [1.9, Complex(1,-1)], [3, 4] ]
- end
-
- it "returns empty matrices on the same size if empty" do
- Matrix.empty(0, 3).send(@method).should == Matrix.empty(0, 3)
- Matrix.empty(3, 0).send(@method).should == Matrix.empty(3, 0)
- end
-
- describe "for a subclass of Matrix" do
- it "returns an instance of that subclass" do
- MatrixSub.ins.send(@method).should be_an_instance_of(MatrixSub)
- end
- end
-end
diff --git a/spec/ruby/library/matrix/shared/determinant.rb b/spec/ruby/library/matrix/shared/determinant.rb
deleted file mode 100644
index 47a58c62a6..0000000000
--- a/spec/ruby/library/matrix/shared/determinant.rb
+++ /dev/null
@@ -1,38 +0,0 @@
-require 'matrix'
-
-describe :determinant, shared: true do
- it "returns the determinant of a square Matrix" do
- m = Matrix[ [7,6], [3,9] ]
- m.send(@method).should == 45
-
- m = Matrix[ [9, 8], [6,5] ]
- m.send(@method).should == -3
-
- m = Matrix[ [9,8,3], [4,20,5], [1,1,1] ]
- m.send(@method).should == 95
- end
-
- it "returns the determinant of a single-element Matrix" do
- m = Matrix[ [2] ]
- m.send(@method).should == 2
- end
-
- it "returns 1 for an empty Matrix" do
- m = Matrix[ ]
- m.send(@method).should == 1
- end
-
- it "returns the determinant even for Matrices containing 0 as first entry" do
- Matrix[[0,1],[1,0]].send(@method).should == -1
- end
-
- it "raises an error for rectangular matrices" do
- lambda {
- Matrix[[1], [2], [3]].send(@method)
- }.should raise_error(Matrix::ErrDimensionMismatch)
-
- lambda {
- Matrix.empty(3,0).send(@method)
- }.should raise_error(Matrix::ErrDimensionMismatch)
- end
-end
diff --git a/spec/ruby/library/matrix/shared/equal_value.rb b/spec/ruby/library/matrix/shared/equal_value.rb
index e2102e823a..9bc6ed908b 100644
--- a/spec/ruby/library/matrix/shared/equal_value.rb
+++ b/spec/ruby/library/matrix/shared/equal_value.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../fixtures/classes', __FILE__)
+require_relative '../fixtures/classes'
require 'matrix'
describe :equal, shared: true do
@@ -7,27 +7,27 @@ describe :equal, shared: true do
end
it "returns true for self" do
- @matrix.send(@method, @matrix).should be_true
+ @matrix.send(@method, @matrix).should == true
end
it "returns true for equal matrices" do
- @matrix.send(@method, Matrix[ [1, 2, 3, 4, 5], [2, 3, 4, 5, 6] ]).should be_true
+ @matrix.send(@method, Matrix[ [1, 2, 3, 4, 5], [2, 3, 4, 5, 6] ]).should == true
end
it "returns false for different matrices" do
- @matrix.send(@method, Matrix[ [42, 2, 3, 4, 5], [2, 3, 4, 5, 6] ]).should be_false
- @matrix.send(@method, Matrix[ [1, 2, 3, 4, 5, 6], [2, 3, 4, 5, 6, 7] ]).should be_false
- @matrix.send(@method, Matrix[ [1, 2, 3], [2, 3, 4] ]).should be_false
+ @matrix.send(@method, Matrix[ [42, 2, 3, 4, 5], [2, 3, 4, 5, 6] ]).should == false
+ @matrix.send(@method, Matrix[ [1, 2, 3, 4, 5, 6], [2, 3, 4, 5, 6, 7] ]).should == false
+ @matrix.send(@method, Matrix[ [1, 2, 3], [2, 3, 4] ]).should == false
end
it "returns false for different empty matrices" do
- Matrix.empty(42, 0).send(@method, Matrix.empty(6, 0)).should be_false
- Matrix.empty(0, 42).send(@method, Matrix.empty(0, 6)).should be_false
- Matrix.empty(0, 0).send(@method, Matrix.empty(6, 0)).should be_false
- Matrix.empty(0, 0).send(@method, Matrix.empty(0, 6)).should be_false
+ Matrix.empty(42, 0).send(@method, Matrix.empty(6, 0)).should == false
+ Matrix.empty(0, 42).send(@method, Matrix.empty(0, 6)).should == false
+ Matrix.empty(0, 0).send(@method, Matrix.empty(6, 0)).should == false
+ Matrix.empty(0, 0).send(@method, Matrix.empty(0, 6)).should == false
end
it "doesn't distinguish on subclasses" do
- MatrixSub.ins.send(@method, Matrix.I(2)).should be_true
+ MatrixSub.ins.send(@method, Matrix.I(2)).should == true
end
end
diff --git a/spec/ruby/library/matrix/shared/identity.rb b/spec/ruby/library/matrix/shared/identity.rb
deleted file mode 100644
index 20b35ae8e3..0000000000
--- a/spec/ruby/library/matrix/shared/identity.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-require File.expand_path('../../fixtures/classes', __FILE__)
-require 'matrix'
-
-describe :matrix_identity, shared: true do
- it "returns a Matrix" do
- Matrix.send(@method, 2).should be_kind_of(Matrix)
- end
-
- it "returns a n x n identity matrix" do
- Matrix.send(@method, 3).should == Matrix.scalar(3, 1)
- Matrix.send(@method, 100).should == Matrix.scalar(100, 1)
- end
-
- describe "for a subclass of Matrix" do
- it "returns an instance of that subclass" do
- MatrixSub.send(@method, 2).should be_an_instance_of(MatrixSub)
- end
- end
-end
diff --git a/spec/ruby/library/matrix/shared/imaginary.rb b/spec/ruby/library/matrix/shared/imaginary.rb
deleted file mode 100644
index 61a65a62ec..0000000000
--- a/spec/ruby/library/matrix/shared/imaginary.rb
+++ /dev/null
@@ -1,20 +0,0 @@
-require File.expand_path('../../fixtures/classes', __FILE__)
-require 'matrix'
-
-describe :matrix_imaginary, shared: true do
- it "returns a matrix with the imaginary part of the elements of the receiver" do
- Matrix[ [1, 2], [3, 4] ].send(@method).should == Matrix[ [0, 0], [0, 0] ]
- Matrix[ [1.9, Complex(1,1)], [Complex(-2,0.42), 4] ].send(@method).should == Matrix[ [0, 1], [0.42, 0] ]
- end
-
- it "returns empty matrices on the same size if empty" do
- Matrix.empty(0, 3).send(@method).should == Matrix.empty(0, 3)
- Matrix.empty(3, 0).send(@method).should == Matrix.empty(3, 0)
- end
-
- describe "for a subclass of Matrix" do
- it "returns an instance of that subclass" do
- MatrixSub.ins.send(@method).should be_an_instance_of(MatrixSub)
- end
- end
-end
diff --git a/spec/ruby/library/matrix/shared/inverse.rb b/spec/ruby/library/matrix/shared/inverse.rb
deleted file mode 100644
index c6996df4a3..0000000000
--- a/spec/ruby/library/matrix/shared/inverse.rb
+++ /dev/null
@@ -1,38 +0,0 @@
-require File.expand_path('../../fixtures/classes', __FILE__)
-require 'matrix'
-
-describe :inverse, shared: true do
-
- it "returns a Matrix" do
- Matrix[ [1,2], [2,1] ].send(@method).should be_an_instance_of(Matrix)
- end
-
- it "returns the inverse of the Matrix" do
- Matrix[
- [1, 3, 3], [1, 4, 3], [1, 3, 4]
- ].send(@method).should ==
- Matrix[
- [7, -3, -3], [-1, 1, 0], [-1, 0, 1]
- ]
- end
-
- it "returns the inverse of the Matrix (other case)" do
- Matrix[
- [1, 2, 3], [0, 1, 4], [5, 6, 0]
- ].send(@method).should be_close_to_matrix([
- [-24, 18, 5], [20, -15, -4], [-5, 4, 1]
- ])
- end
-
- it "raises a ErrDimensionMismatch if the Matrix is not square" do
- lambda{
- Matrix[ [1,2,3], [1,2,3] ].send(@method)
- }.should raise_error(Matrix::ErrDimensionMismatch)
- end
-
- describe "for a subclass of Matrix" do
- it "returns an instance of that subclass" do
- MatrixSub.ins.send(@method).should be_an_instance_of(MatrixSub)
- end
- end
-end
diff --git a/spec/ruby/library/matrix/shared/rectangular.rb b/spec/ruby/library/matrix/shared/rectangular.rb
deleted file mode 100644
index 4206311586..0000000000
--- a/spec/ruby/library/matrix/shared/rectangular.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-require File.expand_path('../../fixtures/classes', __FILE__)
-require 'matrix'
-
-describe :matrix_rectangular, shared: true do
- it "returns [receiver.real, receiver.imag]" do
- m = Matrix[ [1.2, Complex(1,2)], [Complex(-2,0.42), 4] ]
- m.send(@method).should == [m.real, m.imag]
-
- m = Matrix.empty(3, 0)
- m.send(@method).should == [m.real, m.imag]
- end
-
- describe "for a subclass of Matrix" do
- it "returns instances of that subclass" do
- MatrixSub.ins.send(@method).each{|m| m.should be_an_instance_of(MatrixSub) }
- end
- end
-end
diff --git a/spec/ruby/library/matrix/shared/trace.rb b/spec/ruby/library/matrix/shared/trace.rb
deleted file mode 100644
index 2a42839f5d..0000000000
--- a/spec/ruby/library/matrix/shared/trace.rb
+++ /dev/null
@@ -1,12 +0,0 @@
-require 'matrix'
-
-describe :trace, shared: true do
- it "returns the sum of diagonal elements in a square Matrix" do
- Matrix[[7,6], [3,9]].trace.should == 16
- end
-
- it "returns the sum of diagonal elements in a rectangular Matrix" do
- lambda{ Matrix[[1,2,3], [4,5,6]].trace}.should raise_error(Matrix::ErrDimensionMismatch)
- end
-
-end
diff --git a/spec/ruby/library/matrix/shared/transpose.rb b/spec/ruby/library/matrix/shared/transpose.rb
deleted file mode 100644
index dba6c71041..0000000000
--- a/spec/ruby/library/matrix/shared/transpose.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-require File.expand_path('../../fixtures/classes', __FILE__)
-require 'matrix'
-
-describe :matrix_transpose, shared: true do
- it "returns a transposed matrix" do
- Matrix[[1, 2], [3, 4], [5, 6]].send(@method).should == Matrix[[1, 3, 5], [2, 4, 6]]
- end
-
- it "can transpose empty matrices" do
- m = Matrix[[], [], []]
- m.send(@method).send(@method).should == m
- end
-
- describe "for a subclass of Matrix" do
- it "returns an instance of that subclass" do
- MatrixSub.ins.send(@method).should be_an_instance_of(MatrixSub)
- end
- end
-end
diff --git a/spec/ruby/library/matrix/singular_spec.rb b/spec/ruby/library/matrix/singular_spec.rb
index 83914befbe..00b93af495 100644
--- a/spec/ruby/library/matrix/singular_spec.rb
+++ b/spec/ruby/library/matrix/singular_spec.rb
@@ -1,31 +1,31 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'matrix'
describe "Matrix#singular?" do
it "returns true for singular matrices" do
m = Matrix[ [1,2,3], [3,4,3], [0,0,0] ]
- m.singular?.should be_true
+ m.singular?.should == true
m = Matrix[ [1,2,9], [3,4,9], [1,2,9] ]
- m.singular?.should be_true
+ m.singular?.should == true
end
it "returns false if the Matrix is regular" do
- Matrix[ [0,1], [1,0] ].singular?.should be_false
+ Matrix[ [0,1], [1,0] ].singular?.should == false
end
it "returns false for an empty 0x0 matrix" do
- Matrix.empty(0,0).singular?.should be_false
+ Matrix.empty(0,0).singular?.should == false
end
it "raises an error for rectangular matrices" do
- lambda {
+ -> {
Matrix[[1], [2], [3]].singular?
- }.should raise_error(Matrix::ErrDimensionMismatch)
+ }.should.raise(Matrix::ErrDimensionMismatch)
- lambda {
+ -> {
Matrix.empty(3,0).singular?
- }.should raise_error(Matrix::ErrDimensionMismatch)
+ }.should.raise(Matrix::ErrDimensionMismatch)
end
end
diff --git a/spec/ruby/library/matrix/square_spec.rb b/spec/ruby/library/matrix/square_spec.rb
index a117916a4c..b8cf4acf44 100644
--- a/spec/ruby/library/matrix/square_spec.rb
+++ b/spec/ruby/library/matrix/square_spec.rb
@@ -1,28 +1,28 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'matrix'
describe "Matrix#square?" do
it "returns true when the Matrix is square" do
- Matrix[ [1,2], [2,4] ].square?.should be_true
- Matrix[ [100,3,5], [9.5, 4.9, 8], [2,0,77] ].square?.should be_true
+ Matrix[ [1,2], [2,4] ].square?.should == true
+ Matrix[ [100,3,5], [9.5, 4.9, 8], [2,0,77] ].square?.should == true
end
it "returns true when the Matrix has only one element" do
- Matrix[ [9] ].square?.should be_true
+ Matrix[ [9] ].square?.should == true
end
it "returns false when the Matrix is rectangular" do
- Matrix[ [1, 2] ].square?.should be_false
+ Matrix[ [1, 2] ].square?.should == false
end
it "returns false when the Matrix is rectangular" do
- Matrix[ [1], [2] ].square?.should be_false
+ Matrix[ [1], [2] ].square?.should == false
end
it "returns handles empty matrices" do
- Matrix[].square?.should be_true
- Matrix[[]].square?.should be_false
- Matrix.columns([[]]).square?.should be_false
+ Matrix[].square?.should == true
+ Matrix[[]].square?.should == false
+ Matrix.columns([[]]).square?.should == false
end
end
diff --git a/spec/ruby/library/matrix/symmetric_spec.rb b/spec/ruby/library/matrix/symmetric_spec.rb
index c34a323510..4b86c19503 100644
--- a/spec/ruby/library/matrix/symmetric_spec.rb
+++ b/spec/ruby/library/matrix/symmetric_spec.rb
@@ -1,17 +1,17 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'matrix'
describe "Matrix.symmetric?" do
it "returns true for a symmetric Matrix" do
- Matrix[[1, 2, Complex(0, 3)], [2, 4, 5], [Complex(0, 3), 5, 6]].symmetric?.should be_true
+ Matrix[[1, 2, Complex(0, 3)], [2, 4, 5], [Complex(0, 3), 5, 6]].symmetric?.should == true
end
it "returns true for a 0x0 empty matrix" do
- Matrix.empty.symmetric?.should be_true
+ Matrix.empty.symmetric?.should == true
end
it "returns false for an asymmetric Matrix" do
- Matrix[[1, 2],[-2, 1]].symmetric?.should be_false
+ Matrix[[1, 2],[-2, 1]].symmetric?.should == false
end
it "raises an error for rectangular matrices" do
@@ -21,9 +21,9 @@ describe "Matrix.symmetric?" do
Matrix.empty(0, 2),
Matrix.empty(2, 0),
].each do |rectangular_matrix|
- lambda {
+ -> {
rectangular_matrix.symmetric?
- }.should raise_error(Matrix::ErrDimensionMismatch)
+ }.should.raise(Matrix::ErrDimensionMismatch)
end
end
end
diff --git a/spec/ruby/library/matrix/t_spec.rb b/spec/ruby/library/matrix/t_spec.rb
index 1c57c25de3..9411597e7c 100644
--- a/spec/ruby/library/matrix/t_spec.rb
+++ b/spec/ruby/library/matrix/t_spec.rb
@@ -1,6 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/transpose', __FILE__)
+require_relative '../../spec_helper'
+require 'matrix'
-describe "Matrix#transpose" do
- it_behaves_like(:matrix_transpose, :t)
+describe "Matrix#t" do
+ it "is an alias of Matrix#transpose" do
+ Matrix.instance_method(:t).should == Matrix.instance_method(:transpose)
+ end
end
diff --git a/spec/ruby/library/matrix/to_a_spec.rb b/spec/ruby/library/matrix/to_a_spec.rb
index 70db580312..b5d55c5d67 100644
--- a/spec/ruby/library/matrix/to_a_spec.rb
+++ b/spec/ruby/library/matrix/to_a_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'matrix'
describe "Matrix#to_a" do
diff --git a/spec/ruby/library/matrix/to_s_spec.rb b/spec/ruby/library/matrix/to_s_spec.rb
index eb175d486b..f529fe3bcd 100644
--- a/spec/ruby/library/matrix/to_s_spec.rb
+++ b/spec/ruby/library/matrix/to_s_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'matrix'
describe "Matrix#to_s" do
diff --git a/spec/ruby/library/matrix/tr_spec.rb b/spec/ruby/library/matrix/tr_spec.rb
index 4b07a70203..04d237d483 100644
--- a/spec/ruby/library/matrix/tr_spec.rb
+++ b/spec/ruby/library/matrix/tr_spec.rb
@@ -1,7 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/trace', __FILE__)
+require_relative '../../spec_helper'
require 'matrix'
describe "Matrix#tr" do
- it_behaves_like(:trace, :tr)
+ it "is an alias of Matrix#trace" do
+ Matrix.instance_method(:tr).should == Matrix.instance_method(:trace)
+ end
end
diff --git a/spec/ruby/library/matrix/trace_spec.rb b/spec/ruby/library/matrix/trace_spec.rb
index 08adb256c0..831278c838 100644
--- a/spec/ruby/library/matrix/trace_spec.rb
+++ b/spec/ruby/library/matrix/trace_spec.rb
@@ -1,7 +1,12 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/trace', __FILE__)
+require_relative '../../spec_helper'
require 'matrix'
describe "Matrix#trace" do
- it_behaves_like(:trace, :trace)
+ it "returns the sum of diagonal elements in a square Matrix" do
+ Matrix[[7,6], [3,9]].trace.should == 16
+ end
+
+ it "returns the sum of diagonal elements in a rectangular Matrix" do
+ ->{ Matrix[[1,2,3], [4,5,6]].trace}.should.raise(Matrix::ErrDimensionMismatch)
+ end
end
diff --git a/spec/ruby/library/matrix/transpose_spec.rb b/spec/ruby/library/matrix/transpose_spec.rb
index 2a30a80efc..0b24ab32a7 100644
--- a/spec/ruby/library/matrix/transpose_spec.rb
+++ b/spec/ruby/library/matrix/transpose_spec.rb
@@ -1,6 +1,19 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/transpose', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Matrix#transpose" do
- it_behaves_like(:matrix_transpose, :transpose)
+ it "returns a transposed matrix" do
+ Matrix[[1, 2], [3, 4], [5, 6]].transpose.should == Matrix[[1, 3, 5], [2, 4, 6]]
+ end
+
+ it "can transpose empty matrices" do
+ m = Matrix[[], [], []]
+ m.transpose.transpose.should == m
+ end
+
+ describe "for a subclass of Matrix" do
+ it "returns an instance of that subclass" do
+ MatrixSub.ins.transpose.should.instance_of?(MatrixSub)
+ end
+ end
end
diff --git a/spec/ruby/library/matrix/unit_spec.rb b/spec/ruby/library/matrix/unit_spec.rb
index 058d719043..1121996122 100644
--- a/spec/ruby/library/matrix/unit_spec.rb
+++ b/spec/ruby/library/matrix/unit_spec.rb
@@ -1,6 +1,8 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/identity', __FILE__)
+require_relative '../../spec_helper'
+require 'matrix'
describe "Matrix.unit" do
- it_behaves_like(:matrix_identity, :unit)
+ it "is an alias of Matrix.identity" do
+ Matrix.method(:unit).should == Matrix.method(:identity)
+ end
end
diff --git a/spec/ruby/library/matrix/unitary_spec.rb b/spec/ruby/library/matrix/unitary_spec.rb
index 0ea5586a6d..4490e8f8d4 100644
--- a/spec/ruby/library/matrix/unitary_spec.rb
+++ b/spec/ruby/library/matrix/unitary_spec.rb
@@ -1,16 +1,20 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
+
require 'matrix'
describe "Matrix.unitary?" do
it "returns false for non unitary matrices" do
- Matrix[[0, 1], [1, 2]].unitary?.should == false
- Matrix[[0, Complex(0, 2)], [Complex(0, 2), 0]].unitary?.should == false
- Matrix[[0, Complex(0, 1)], [Complex(0, -1), 0]].unitary?.should == false
- Matrix[[1, 1, 0], [0, 1, 1], [1, 0, 1]].unitary?.should == false
+ Matrix[[0, 1], [1, 2]].should_not.unitary?
+ Matrix[[0, Complex(0, 2)], [Complex(0, 2), 0]].should_not.unitary?
+ Matrix[[1, 1, 0], [0, 1, 1], [1, 0, 1]].should_not.unitary?
end
it "returns true for unitary matrices" do
- Matrix[[0, Complex(0, 1)], [Complex(0, 1), 0]].unitary?.should == true
+ Matrix[[0, Complex(0, 1)], [Complex(0, 1), 0]].should.unitary?
+ end
+
+ it "returns true for unitary matrices with a Complex and a negative #imag" do
+ Matrix[[0, Complex(0, 1)], [Complex(0, -1), 0]].should.unitary?
end
it "raises an error for rectangular matrices" do
@@ -20,9 +24,9 @@ describe "Matrix.unitary?" do
Matrix.empty(0, 2),
Matrix.empty(2, 0),
].each do |rectangular_matrix|
- lambda {
+ -> {
rectangular_matrix.unitary?
- }.should raise_error(Matrix::ErrDimensionMismatch)
+ }.should.raise(Matrix::ErrDimensionMismatch)
end
end
end
diff --git a/spec/ruby/library/matrix/upper_triangular_spec.rb b/spec/ruby/library/matrix/upper_triangular_spec.rb
index be88150b85..0e2bf611e2 100644
--- a/spec/ruby/library/matrix/upper_triangular_spec.rb
+++ b/spec/ruby/library/matrix/upper_triangular_spec.rb
@@ -1,24 +1,24 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'matrix'
describe "Matrix.upper_triangular?" do
it "returns true for an upper triangular Matrix" do
- Matrix[[1, 2, 3], [0, 2, 3], [0, 0, 3]].upper_triangular?.should be_true
- Matrix.diagonal([1, 2, 3]).upper_triangular?.should be_true
- Matrix[[1, 2], [0, 2], [0, 0], [0, 0]].upper_triangular?.should be_true
- Matrix[[1, 2, 3, 4], [0, 2, 3, 4]].upper_triangular?.should be_true
+ Matrix[[1, 2, 3], [0, 2, 3], [0, 0, 3]].upper_triangular?.should == true
+ Matrix.diagonal([1, 2, 3]).upper_triangular?.should == true
+ Matrix[[1, 2], [0, 2], [0, 0], [0, 0]].upper_triangular?.should == true
+ Matrix[[1, 2, 3, 4], [0, 2, 3, 4]].upper_triangular?.should == true
end
it "returns false for a non upper triangular square Matrix" do
- Matrix[[0, 0], [1, 0]].upper_triangular?.should be_false
- Matrix[[1, 2, 3], [1, 2, 3], [1, 2, 3]].upper_triangular?.should be_false
- Matrix[[0, 0], [0, 0], [0, 0], [0, 1]].upper_triangular?.should be_false
- Matrix[[0, 0, 0, 0], [1, 0, 0, 0]].upper_triangular?.should be_false
+ Matrix[[0, 0], [1, 0]].upper_triangular?.should == false
+ Matrix[[1, 2, 3], [1, 2, 3], [1, 2, 3]].upper_triangular?.should == false
+ Matrix[[0, 0], [0, 0], [0, 0], [0, 1]].upper_triangular?.should == false
+ Matrix[[0, 0, 0, 0], [1, 0, 0, 0]].upper_triangular?.should == false
end
it "returns true for an empty matrix" do
- Matrix.empty(3,0).upper_triangular?.should be_true
- Matrix.empty(0,3).upper_triangular?.should be_true
- Matrix.empty(0,0).upper_triangular?.should be_true
+ Matrix.empty(3,0).upper_triangular?.should == true
+ Matrix.empty(0,3).upper_triangular?.should == true
+ Matrix.empty(0,0).upper_triangular?.should == true
end
end
diff --git a/spec/ruby/library/matrix/vector/cross_product_spec.rb b/spec/ruby/library/matrix/vector/cross_product_spec.rb
index f26cf585da..96a462c067 100644
--- a/spec/ruby/library/matrix/vector/cross_product_spec.rb
+++ b/spec/ruby/library/matrix/vector/cross_product_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'matrix'
describe "Vector#cross_product" do
@@ -7,8 +7,8 @@ describe "Vector#cross_product" do
end
it "raises an error unless both vectors have dimension 3" do
- lambda {
+ -> {
Vector[1, 2, 3].cross_product(Vector[0, -4])
- }.should raise_error(Vector::ErrDimensionMismatch)
+ }.should.raise(Vector::ErrDimensionMismatch)
end
end
diff --git a/spec/ruby/library/matrix/vector/each2_spec.rb b/spec/ruby/library/matrix/vector/each2_spec.rb
index e9d89e21c4..86e7ed75aa 100644
--- a/spec/ruby/library/matrix/vector/each2_spec.rb
+++ b/spec/ruby/library/matrix/vector/each2_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'matrix'
describe "Vector.each2" do
@@ -8,8 +8,8 @@ describe "Vector.each2" do
end
it "requires one argument" do
- lambda { @v.each2(@v2, @v2){} }.should raise_error(ArgumentError)
- lambda { @v.each2(){} }.should raise_error(ArgumentError)
+ -> { @v.each2(@v2, @v2){} }.should.raise(ArgumentError)
+ -> { @v.each2(){} }.should.raise(ArgumentError)
end
describe "given one argument" do
@@ -20,8 +20,8 @@ describe "Vector.each2" do
end
it "raises a DimensionMismatch error if the Vector size is different" do
- lambda { @v.each2(Vector[1,2]){} }.should raise_error(Vector::ErrDimensionMismatch)
- lambda { @v.each2(Vector[1,2,3,4]){} }.should raise_error(Vector::ErrDimensionMismatch)
+ -> { @v.each2(Vector[1,2]){} }.should.raise(Vector::ErrDimensionMismatch)
+ -> { @v.each2(Vector[1,2,3,4]){} }.should.raise(Vector::ErrDimensionMismatch)
end
it "yields arguments in sequence" do
@@ -37,12 +37,12 @@ describe "Vector.each2" do
end
it "returns self when given a block" do
- @v.each2(@v2){}.should equal(@v)
+ @v.each2(@v2){}.should.equal?(@v)
end
it "returns an enumerator if no block given" do
enum = @v.each2(@v2)
- enum.should be_an_instance_of(Enumerator)
+ enum.should.instance_of?(Enumerator)
enum.to_a.should == [[1, 4], [2, 5], [3, 6]]
end
end
diff --git a/spec/ruby/library/matrix/vector/eql_spec.rb b/spec/ruby/library/matrix/vector/eql_spec.rb
index 6cc69bbf7d..6e2cd47b8e 100644
--- a/spec/ruby/library/matrix/vector/eql_spec.rb
+++ b/spec/ruby/library/matrix/vector/eql_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'matrix'
describe "Vector#eql?" do
@@ -7,10 +7,10 @@ describe "Vector#eql?" do
end
it "returns true for self" do
- @vector.eql?(@vector).should be_true
+ @vector.eql?(@vector).should == true
end
it "returns false when there are a pair corresponding elements which are not equal in the sense of Kernel#eql?" do
- @vector.eql?(Vector[1, 2, 3, 4, 5.0]).should be_false
+ @vector.eql?(Vector[1, 2, 3, 4, 5.0]).should == false
end
end
diff --git a/spec/ruby/library/matrix/vector/inner_product_spec.rb b/spec/ruby/library/matrix/vector/inner_product_spec.rb
index a953598b51..79dee10833 100644
--- a/spec/ruby/library/matrix/vector/inner_product_spec.rb
+++ b/spec/ruby/library/matrix/vector/inner_product_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'matrix'
describe "Vector#inner_product" do
@@ -11,9 +11,9 @@ describe "Vector#inner_product" do
end
it "raises an error for mismatched vectors" do
- lambda {
+ -> {
Vector[1, 2, 3].inner_product(Vector[0, -4])
- }.should raise_error(Vector::ErrDimensionMismatch)
+ }.should.raise(Vector::ErrDimensionMismatch)
end
it "uses the conjugate of its argument" do
diff --git a/spec/ruby/library/matrix/vector/normalize_spec.rb b/spec/ruby/library/matrix/vector/normalize_spec.rb
index 14aac1f5e3..bb1f046786 100644
--- a/spec/ruby/library/matrix/vector/normalize_spec.rb
+++ b/spec/ruby/library/matrix/vector/normalize_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
+require_relative '../../../spec_helper'
require 'matrix'
describe "Vector#normalize" do
@@ -8,11 +8,11 @@ describe "Vector#normalize" do
end
it "raises an error for zero vectors" do
- lambda {
+ -> {
Vector[].normalize
- }.should raise_error(Vector::ZeroVectorError)
- lambda {
+ }.should.raise(Vector::ZeroVectorError)
+ -> {
Vector[0, 0, 0].normalize
- }.should raise_error(Vector::ZeroVectorError)
+ }.should.raise(Vector::ZeroVectorError)
end
end
diff --git a/spec/ruby/library/matrix/zero_spec.rb b/spec/ruby/library/matrix/zero_spec.rb
index f83d29e837..406bcad6ed 100644
--- a/spec/ruby/library/matrix/zero_spec.rb
+++ b/spec/ruby/library/matrix/zero_spec.rb
@@ -1,10 +1,10 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
require 'matrix'
describe "Matrix.zero" do
it "returns an object of type Matrix" do
- Matrix.zero(3).should be_kind_of(Matrix)
+ Matrix.zero(3).should.is_a?(Matrix)
end
it "creates a n x n matrix" do
@@ -30,23 +30,23 @@ describe "Matrix.zero" do
describe "for a subclass of Matrix" do
it "returns an instance of that subclass" do
- MatrixSub.zero(3).should be_an_instance_of(MatrixSub)
+ MatrixSub.zero(3).should.instance_of?(MatrixSub)
end
end
end
describe "Matrix.zero?" do
it "returns true for empty matrices" do
- Matrix.empty.zero?.should == true
- Matrix.empty(3,0).zero?.should == true
- Matrix.empty(0,3).zero?.should == true
+ Matrix.empty.should.zero?
+ Matrix.empty(3,0).should.zero?
+ Matrix.empty(0,3).should.zero?
end
it "returns true for matrices with zero entries" do
- Matrix.zero(2,3).zero?.should == true
+ Matrix.zero(2,3).should.zero?
end
it "returns false for matrices with non zero entries" do
- Matrix[[1]].zero?.should == false
+ Matrix[[1]].should_not.zero?
end
end
diff --git a/spec/ruby/library/mkmf/mkmf_spec.rb b/spec/ruby/library/mkmf/mkmf_spec.rb
new file mode 100644
index 0000000000..18b090e703
--- /dev/null
+++ b/spec/ruby/library/mkmf/mkmf_spec.rb
@@ -0,0 +1,7 @@
+require_relative '../../spec_helper'
+
+describe 'mkmf' do
+ it 'can be required with --enable-frozen-string-literal' do
+ ruby_exe('p MakeMakefile', options: '-rmkmf --enable-frozen-string-literal').should == "MakeMakefile\n"
+ end
+end
diff --git a/spec/ruby/library/monitor/enter_spec.rb b/spec/ruby/library/monitor/enter_spec.rb
new file mode 100644
index 0000000000..f523c42087
--- /dev/null
+++ b/spec/ruby/library/monitor/enter_spec.rb
@@ -0,0 +1,28 @@
+require_relative '../../spec_helper'
+require 'monitor'
+
+describe "Monitor#enter" do
+ it "acquires the monitor" do
+ monitor = Monitor.new
+ 10.times do
+ wait_q = Queue.new
+ continue_q = Queue.new
+
+ thread = Thread.new do
+ begin
+ monitor.enter
+ wait_q << true
+ continue_q.pop
+ ensure
+ monitor.exit
+ end
+ end
+
+ wait_q.pop
+ monitor.mon_locked?.should == true
+ continue_q << true
+ thread.join
+ monitor.mon_locked?.should == false
+ end
+ end
+end
diff --git a/spec/ruby/library/monitor/exit_spec.rb b/spec/ruby/library/monitor/exit_spec.rb
new file mode 100644
index 0000000000..0748a523ac
--- /dev/null
+++ b/spec/ruby/library/monitor/exit_spec.rb
@@ -0,0 +1,10 @@
+require_relative '../../spec_helper'
+require 'monitor'
+
+describe "Monitor#exit" do
+ it "raises ThreadError when monitor is not entered" do
+ m = Monitor.new
+
+ -> { m.exit }.should.raise(ThreadError)
+ end
+end
diff --git a/spec/ruby/library/monitor/mon_initialize_spec.rb b/spec/ruby/library/monitor/mon_initialize_spec.rb
new file mode 100644
index 0000000000..092aee929c
--- /dev/null
+++ b/spec/ruby/library/monitor/mon_initialize_spec.rb
@@ -0,0 +1,31 @@
+require_relative '../../spec_helper'
+require 'monitor'
+
+describe "MonitorMixin#mon_initialize" do
+ it "can be called in initialize_copy to get a new Mutex and used with synchronize" do
+ cls = Class.new do
+ include MonitorMixin
+
+ def initialize(*array)
+ mon_initialize
+ @array = array
+ end
+
+ def to_a
+ synchronize { @array.dup }
+ end
+
+ def initialize_copy(other)
+ mon_initialize
+
+ synchronize do
+ @array = other.to_a
+ end
+ end
+ end
+
+ instance = cls.new(1, 2, 3)
+ copy = instance.dup
+ copy.should_not.equal?(instance)
+ end
+end
diff --git a/spec/ruby/library/monitor/new_cond_spec.rb b/spec/ruby/library/monitor/new_cond_spec.rb
new file mode 100644
index 0000000000..ec25d3f8a2
--- /dev/null
+++ b/spec/ruby/library/monitor/new_cond_spec.rb
@@ -0,0 +1,88 @@
+require_relative '../../spec_helper'
+require 'monitor'
+
+describe "Monitor#new_cond" do
+ it "creates a MonitorMixin::ConditionVariable" do
+ m = Monitor.new
+ c = m.new_cond
+ c.class.should == MonitorMixin::ConditionVariable
+ end
+
+ it 'returns a condition variable which can be waited on by a thread holding the monitor' do
+ m = Monitor.new
+ c = m.new_cond
+
+ 10.times do
+
+ wait_q = Queue.new
+ thread = Thread.new do
+ m.synchronize do
+ wait_q << true
+ c.wait
+ end
+ :done
+ end
+
+ wait_q.pop
+
+ # Synchronize can't happen until the other thread is waiting.
+ m.synchronize { c.signal }
+
+ thread.join
+ thread.value.should == :done
+ end
+ end
+
+ it 'returns a condition variable which can be waited on by a thread holding the monitor inside multiple synchronize blocks' do
+ m = Monitor.new
+ c = m.new_cond
+
+ 10.times do
+
+ wait_q = Queue.new
+ thread = Thread.new do
+ m.synchronize do
+ m.synchronize do
+ wait_q << true
+ c.wait
+ end
+ end
+ :done
+ end
+
+ wait_q.pop
+
+ #No need to wait here as we cannot synchronize until the other thread is waiting.
+ m.synchronize { c.signal }
+
+ thread.join
+ thread.value.should == :done
+ end
+ end
+
+ it 'returns a condition variable which can be signalled by a thread holding the monitor inside multiple synchronize blocks' do
+ m = Monitor.new
+ c = m.new_cond
+
+ 10.times do
+
+ wait_q = Queue.new
+ thread = Thread.new do
+ m.synchronize do
+ wait_q << true
+ c.wait
+ end
+ :done
+ end
+
+ wait_q.pop
+
+ # Synchronize can't happen until the other thread is waiting.
+ m.synchronize { m.synchronize { c.signal } }
+
+ thread.join
+ thread.value.should == :done
+ end
+ end
+
+end
diff --git a/spec/ruby/library/monitor/synchronize_spec.rb b/spec/ruby/library/monitor/synchronize_spec.rb
new file mode 100644
index 0000000000..27cc1258b4
--- /dev/null
+++ b/spec/ruby/library/monitor/synchronize_spec.rb
@@ -0,0 +1,41 @@
+require_relative '../../spec_helper'
+require 'monitor'
+
+describe "Monitor#synchronize" do
+ it "unlocks after return, even if it was interrupted by Thread#raise" do
+ exc_class = Class.new(RuntimeError)
+
+ monitor = Monitor.new
+ 10.times do
+ wait_q = Queue.new
+ continue_q = Queue.new
+
+ thread = Thread.new do
+ begin
+ monitor.synchronize do
+ wait_q << true
+ # Do not wait here, we are trying to interrupt the ensure part of #synchronize
+ end
+ continue_q.pop
+ rescue exc_class
+ monitor.should_not.mon_locked?
+ :ok
+ end
+ end
+
+ wait_q.pop
+ thread.raise exc_class, "interrupt"
+ continue_q << true
+ thread.value.should == :ok
+ end
+ end
+
+ it "raises a LocalJumpError if not passed a block" do
+ -> { Monitor.new.synchronize }.should.raise(LocalJumpError)
+ end
+
+ it "raises a thread error if the monitor is not owned on exiting the block" do
+ monitor = Monitor.new
+ -> { monitor.synchronize { monitor.exit } }.should.raise(ThreadError)
+ end
+end
diff --git a/spec/ruby/library/monitor/try_enter_spec.rb b/spec/ruby/library/monitor/try_enter_spec.rb
new file mode 100644
index 0000000000..04b878f720
--- /dev/null
+++ b/spec/ruby/library/monitor/try_enter_spec.rb
@@ -0,0 +1,39 @@
+require_relative '../../spec_helper'
+require 'monitor'
+
+describe "Monitor#try_enter" do
+ it "will acquire a monitor not held by another thread" do
+ monitor = Monitor.new
+ 10.times do
+
+ thread = Thread.new do
+ val = monitor.try_enter
+ monitor.exit if val
+ val
+ end
+
+ thread.join
+ thread.value.should == true
+ end
+ end
+
+ it "will not acquire a monitor already held by another thread" do
+ monitor = Monitor.new
+ 10.times do
+ monitor.enter
+ begin
+ thread = Thread.new do
+ val = monitor.try_enter
+ monitor.exit if val
+ val
+ end
+
+ thread.join
+ thread.value.should == false
+ ensure
+ monitor.exit
+ end
+ monitor.mon_locked?.should == false
+ end
+ end
+end
diff --git a/spec/ruby/library/net-ftp/FTPError_spec.rb b/spec/ruby/library/net-ftp/FTPError_spec.rb
new file mode 100644
index 0000000000..b447e50546
--- /dev/null
+++ b/spec/ruby/library/net-ftp/FTPError_spec.rb
@@ -0,0 +1,11 @@
+require_relative '../../spec_helper'
+
+ruby_version_is ""..."4.1" do
+ require 'net/ftp'
+
+ describe "Net::FTPError" do
+ it "is an Exception" do
+ Net::FTPError.should < Exception
+ end
+ end
+end
diff --git a/spec/ruby/library/net-ftp/FTPPermError_spec.rb b/spec/ruby/library/net-ftp/FTPPermError_spec.rb
new file mode 100644
index 0000000000..b9a2d93aef
--- /dev/null
+++ b/spec/ruby/library/net-ftp/FTPPermError_spec.rb
@@ -0,0 +1,15 @@
+require_relative '../../spec_helper'
+
+ruby_version_is ""..."4.1" do
+ require 'net/ftp'
+
+ describe "Net::FTPPermError" do
+ it "is an Exception" do
+ Net::FTPPermError.should < Exception
+ end
+
+ it "is a subclass of Net::FTPError" do
+ Net::FTPPermError.should < Net::FTPError
+ end
+ end
+end
diff --git a/spec/ruby/library/net-ftp/FTPProtoError_spec.rb b/spec/ruby/library/net-ftp/FTPProtoError_spec.rb
new file mode 100644
index 0000000000..a1d9e44d63
--- /dev/null
+++ b/spec/ruby/library/net-ftp/FTPProtoError_spec.rb
@@ -0,0 +1,15 @@
+require_relative '../../spec_helper'
+
+ruby_version_is ""..."4.1" do
+ require 'net/ftp'
+
+ describe "Net::FTPProtoError" do
+ it "is an Exception" do
+ Net::FTPProtoError.should < Exception
+ end
+
+ it "is a subclass of Net::FTPError" do
+ Net::FTPPermError.should < Net::FTPError
+ end
+ end
+end
diff --git a/spec/ruby/library/net-ftp/FTPReplyError_spec.rb b/spec/ruby/library/net-ftp/FTPReplyError_spec.rb
new file mode 100644
index 0000000000..c9e6468323
--- /dev/null
+++ b/spec/ruby/library/net-ftp/FTPReplyError_spec.rb
@@ -0,0 +1,15 @@
+require_relative '../../spec_helper'
+
+ruby_version_is ""..."4.1" do
+ require 'net/ftp'
+
+ describe "Net::FTPReplyError" do
+ it "is an Exception" do
+ Net::FTPReplyError.should < Exception
+ end
+
+ it "is a subclass of Net::FTPError" do
+ Net::FTPPermError.should < Net::FTPError
+ end
+ end
+end
diff --git a/spec/ruby/library/net-ftp/FTPTempError_spec.rb b/spec/ruby/library/net-ftp/FTPTempError_spec.rb
new file mode 100644
index 0000000000..c0953cb0f2
--- /dev/null
+++ b/spec/ruby/library/net-ftp/FTPTempError_spec.rb
@@ -0,0 +1,15 @@
+require_relative '../../spec_helper'
+
+ruby_version_is ""..."4.1" do
+ require 'net/ftp'
+
+ describe "Net::FTPTempError" do
+ it "is an Exception" do
+ Net::FTPTempError.should < Exception
+ end
+
+ it "is a subclass of Net::FTPError" do
+ Net::FTPPermError.should < Net::FTPError
+ end
+ end
+end
diff --git a/spec/ruby/library/net-ftp/abort_spec.rb b/spec/ruby/library/net-ftp/abort_spec.rb
new file mode 100644
index 0000000000..9e8be53c68
--- /dev/null
+++ b/spec/ruby/library/net-ftp/abort_spec.rb
@@ -0,0 +1,65 @@
+require_relative '../../spec_helper'
+
+ruby_version_is ""..."4.1" do
+ require_relative 'spec_helper'
+ require_relative 'fixtures/server'
+
+ describe "Net::FTP#abort" do
+ before :each do
+ @server = NetFTPSpecs::DummyFTP.new
+ @server.serve_once
+
+ @ftp = Net::FTP.new
+ @ftp.connect(@server.hostname, @server.server_port)
+ end
+
+ after :each do
+ @ftp.quit rescue nil
+ @ftp.close
+ @server.stop
+ end
+
+ it "sends the ABOR command to the server" do
+ -> { @ftp.abort }.should_not.raise
+ end
+
+ it "ignores the response" do
+ @ftp.abort
+ @ftp.last_response.should == "220 Dummy FTP Server ready!\n"
+ end
+
+ it "returns the full response" do
+ @ftp.abort.should == "226 Closing data connection. (ABOR)\n"
+ end
+
+ it "does not raise any error when the response code is 225" do
+ @server.should_receive(:abor).and_respond("225 Data connection open; no transfer in progress.")
+ -> { @ftp.abort }.should_not.raise
+ end
+
+ it "does not raise any error when the response code is 226" do
+ @server.should_receive(:abor).and_respond("226 Closing data connection.")
+ -> { @ftp.abort }.should_not.raise
+ end
+
+ it "raises a Net::FTPProtoError when the response code is 500" do
+ @server.should_receive(:abor).and_respond("500 Syntax error, command unrecognized.")
+ -> { @ftp.abort }.should.raise(Net::FTPProtoError)
+ end
+
+ it "raises a Net::FTPProtoError when the response code is 501" do
+ @server.should_receive(:abor).and_respond("501 Syntax error in parameters or arguments.")
+ -> { @ftp.abort }.should.raise(Net::FTPProtoError)
+ end
+
+ it "raises a Net::FTPProtoError when the response code is 502" do
+ @server.should_receive(:abor).and_respond("502 Command not implemented.")
+ -> { @ftp.abort }.should.raise(Net::FTPProtoError)
+ end
+
+ it "raises a Net::FTPProtoError when the response code is 421" do
+ @server.should_receive(:abor).and_respond("421 Service not available, closing control connection.")
+ -> { @ftp.abort }.should.raise(Net::FTPProtoError)
+ end
+ end
+end
diff --git a/spec/ruby/library/net-ftp/acct_spec.rb b/spec/ruby/library/net-ftp/acct_spec.rb
new file mode 100644
index 0000000000..a64a0f48a8
--- /dev/null
+++ b/spec/ruby/library/net-ftp/acct_spec.rb
@@ -0,0 +1,61 @@
+require_relative '../../spec_helper'
+
+ruby_version_is ""..."4.1" do
+ require_relative 'spec_helper'
+ require_relative 'fixtures/server'
+
+ describe "Net::FTP#acct" do
+ before :each do
+ @server = NetFTPSpecs::DummyFTP.new
+ @server.serve_once
+
+ @ftp = Net::FTP.new
+ @ftp.connect(@server.hostname, @server.server_port)
+ end
+
+ after :each do
+ @ftp.quit rescue nil
+ @ftp.close
+ @server.stop
+ end
+
+ it "writes the ACCT command to the server" do
+ @ftp.acct("my_account")
+ @ftp.last_response.should == "230 User 'my_account' logged in, proceed. (ACCT)\n"
+ end
+
+ it "returns nil" do
+ @ftp.acct("my_account").should == nil
+ end
+
+ it "does not raise any error when the response code is 230" do
+ @server.should_receive(:acct).and_respond("230 User logged in, proceed.")
+ -> { @ftp.acct("my_account") }.should_not.raise
+ end
+
+ it "raises a Net::FTPPermError when the response code is 530" do
+ @server.should_receive(:acct).and_respond("530 Not logged in.")
+ -> { @ftp.acct("my_account") }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 500" do
+ @server.should_receive(:acct).and_respond("500 Syntax error, command unrecognized.")
+ -> { @ftp.acct("my_account") }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 501" do
+ @server.should_receive(:acct).and_respond("501 Syntax error in parameters or arguments.")
+ -> { @ftp.acct("my_account") }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 503" do
+ @server.should_receive(:acct).and_respond("503 Bad sequence of commands.")
+ -> { @ftp.acct("my_account") }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPTempError when the response code is 421" do
+ @server.should_receive(:acct).and_respond("421 Service not available, closing control connection.")
+ -> { @ftp.acct("my_account") }.should.raise(Net::FTPTempError)
+ end
+ end
+end
diff --git a/spec/ruby/library/net-ftp/binary_spec.rb b/spec/ruby/library/net-ftp/binary_spec.rb
new file mode 100644
index 0000000000..de8d0ac103
--- /dev/null
+++ b/spec/ruby/library/net-ftp/binary_spec.rb
@@ -0,0 +1,27 @@
+require_relative '../../spec_helper'
+
+ruby_version_is ""..."4.1" do
+ require_relative 'spec_helper'
+
+ describe "Net::FTP#binary" do
+ it "returns true when self is in binary mode" do
+ ftp = Net::FTP.new
+ ftp.binary.should == true
+
+ ftp.binary = false
+ ftp.binary.should == false
+ end
+ end
+
+ describe "Net::FTP#binary=" do
+ it "sets self to binary mode when passed true" do
+ ftp = Net::FTP.new
+
+ ftp.binary = true
+ ftp.binary.should == true
+
+ ftp.binary = false
+ ftp.binary.should == false
+ end
+ end
+end
diff --git a/spec/ruby/library/net-ftp/chdir_spec.rb b/spec/ruby/library/net-ftp/chdir_spec.rb
new file mode 100644
index 0000000000..f8f352158c
--- /dev/null
+++ b/spec/ruby/library/net-ftp/chdir_spec.rb
@@ -0,0 +1,102 @@
+require_relative '../../spec_helper'
+
+ruby_version_is ""..."4.1" do
+ require_relative 'spec_helper'
+ require_relative 'fixtures/server'
+
+ describe "Net::FTP#chdir" do
+ before :each do
+ @server = NetFTPSpecs::DummyFTP.new
+ @server.serve_once
+
+ @ftp = Net::FTP.new
+ @ftp.connect(@server.hostname, @server.server_port)
+ end
+
+ after :each do
+ @ftp.quit rescue nil
+ @ftp.close
+ @server.stop
+ end
+
+ describe "when switching to the parent directory" do
+ it "sends the 'CDUP' command to the server" do
+ @ftp.chdir("..")
+ @ftp.last_response.should == "200 Command okay. (CDUP)\n"
+ end
+
+ it "returns nil" do
+ @ftp.chdir("..").should == nil
+ end
+
+ it "does not raise a Net::FTPPermError when the response code is 500" do
+ @server.should_receive(:cdup).and_respond("500 Syntax error, command unrecognized.")
+ -> { @ftp.chdir("..") }.should_not.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 501" do
+ @server.should_receive(:cdup).and_respond("501 Syntax error in parameters or arguments.")
+ -> { @ftp.chdir("..") }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 502" do
+ @server.should_receive(:cdup).and_respond("502 Command not implemented.")
+ -> { @ftp.chdir("..") }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPTempError when the response code is 421" do
+ @server.should_receive(:cdup).and_respond("421 Service not available, closing control connection.")
+ -> { @ftp.chdir("..") }.should.raise(Net::FTPTempError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 530" do
+ @server.should_receive(:cdup).and_respond("530 Not logged in.")
+ -> { @ftp.chdir("..") }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 550" do
+ @server.should_receive(:cdup).and_respond("550 Requested action not taken.")
+ -> { @ftp.chdir("..") }.should.raise(Net::FTPPermError)
+ end
+ end
+
+ it "writes the 'CWD' command with the passed directory to the socket" do
+ @ftp.chdir("test")
+ @ftp.last_response.should == "200 Command okay. (CWD test)\n"
+ end
+
+ it "returns nil" do
+ @ftp.chdir("test").should == nil
+ end
+
+ it "raises a Net::FTPPermError when the response code is 500" do
+ @server.should_receive(:cwd).and_respond("500 Syntax error, command unrecognized.")
+ -> { @ftp.chdir("test") }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 501" do
+ @server.should_receive(:cwd).and_respond("501 Syntax error in parameters or arguments.")
+ -> { @ftp.chdir("test") }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 502" do
+ @server.should_receive(:cwd).and_respond("502 Command not implemented.")
+ -> { @ftp.chdir("test") }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPTempError when the response code is 421" do
+ @server.should_receive(:cwd).and_respond("421 Service not available, closing control connection.")
+ -> { @ftp.chdir("test") }.should.raise(Net::FTPTempError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 530" do
+ @server.should_receive(:cwd).and_respond("530 Not logged in.")
+ -> { @ftp.chdir("test") }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 550" do
+ @server.should_receive(:cwd).and_respond("550 Requested action not taken.")
+ -> { @ftp.chdir("test") }.should.raise(Net::FTPPermError)
+ end
+ end
+end
diff --git a/spec/ruby/library/net-ftp/close_spec.rb b/spec/ruby/library/net-ftp/close_spec.rb
new file mode 100644
index 0000000000..9d5d4c638a
--- /dev/null
+++ b/spec/ruby/library/net-ftp/close_spec.rb
@@ -0,0 +1,33 @@
+require_relative '../../spec_helper'
+
+ruby_version_is ""..."4.1" do
+ require_relative 'spec_helper'
+
+ describe "Net::FTP#close" do
+ before :each do
+ @socket = mock("Socket")
+ @socket.stub!(:closed?).and_return(false)
+ @socket.stub!(:read_timeout).and_return(60)
+ @socket.stub!(:read_timeout=).and_return(3)
+
+ @ftp = Net::FTP.new
+ @ftp.instance_variable_set(:@sock, @socket)
+ end
+
+ it "closes the socket" do
+ @socket.should_receive(:close)
+ @ftp.close.should == nil
+ end
+
+ it "does not try to close the socket if it has already been closed" do
+ @socket.should_receive(:closed?).and_return(true)
+ @socket.should_not_receive(:close)
+ @ftp.close.should == nil
+ end
+
+ it "does not try to close the socket if it is nil" do
+ @ftp.instance_variable_set(:@sock, nil)
+ @ftp.close.should == nil
+ end
+ end
+end
diff --git a/spec/ruby/library/net-ftp/closed_spec.rb b/spec/ruby/library/net-ftp/closed_spec.rb
new file mode 100644
index 0000000000..1c8693932e
--- /dev/null
+++ b/spec/ruby/library/net-ftp/closed_spec.rb
@@ -0,0 +1,24 @@
+require_relative '../../spec_helper'
+
+ruby_version_is ""..."4.1" do
+ require_relative 'spec_helper'
+
+ describe "Net::FTP#closed?" do
+ before :each do
+ @socket = mock("Socket")
+
+ @ftp = Net::FTP.new
+ @ftp.instance_variable_set(:@sock, @socket)
+ end
+
+ it "returns true when the socket is closed" do
+ @socket.should_receive(:closed?).and_return(true)
+ @ftp.closed?.should == true
+ end
+
+ it "returns true when the socket is nil" do
+ @ftp.instance_variable_set(:@sock, nil)
+ @ftp.closed?.should == true
+ end
+ end
+end
diff --git a/spec/ruby/library/net-ftp/connect_spec.rb b/spec/ruby/library/net-ftp/connect_spec.rb
new file mode 100644
index 0000000000..597381f67c
--- /dev/null
+++ b/spec/ruby/library/net-ftp/connect_spec.rb
@@ -0,0 +1,46 @@
+require_relative '../../spec_helper'
+
+ruby_version_is ""..."4.1" do
+ require_relative 'spec_helper'
+ require_relative 'fixtures/server'
+
+ # TODO: Add specs for using the SOCKSSocket
+ describe "Net::FTP#connect" do
+ before :each do
+ @server = NetFTPSpecs::DummyFTP.new
+ @server.serve_once
+
+ @ftp = Net::FTP.new
+ end
+
+ after :each do
+ @server.connect_message = nil
+ @ftp.quit rescue nil
+ @ftp.close
+ @server.stop
+ end
+
+ it "tries to connect to the FTP Server on the given host and port" do
+ -> { @ftp.connect(@server.hostname, @server.server_port) }.should_not.raise
+ end
+
+ it "returns nil" do
+ @ftp.connect(@server.hostname, @server.server_port).should == nil
+ end
+
+ it "does not raise any error when the response code is 220" do
+ @server.connect_message = "220 Dummy FTP Server ready!"
+ -> { @ftp.connect(@server.hostname, @server.server_port) }.should_not.raise
+ end
+
+ it "raises a Net::FTPReplyError when the response code is 120" do
+ @server.connect_message = "120 Service ready in nnn minutes."
+ -> { @ftp.connect(@server.hostname, @server.server_port) }.should.raise(Net::FTPReplyError)
+ end
+
+ it "raises a Net::FTPTempError when the response code is 421" do
+ @server.connect_message = "421 Service not available, closing control connection."
+ -> { @ftp.connect(@server.hostname, @server.server_port) }.should.raise(Net::FTPTempError)
+ end
+ end
+end
diff --git a/spec/ruby/library/net-ftp/debug_mode_spec.rb b/spec/ruby/library/net-ftp/debug_mode_spec.rb
new file mode 100644
index 0000000000..28765b9d1c
--- /dev/null
+++ b/spec/ruby/library/net-ftp/debug_mode_spec.rb
@@ -0,0 +1,26 @@
+require_relative '../../spec_helper'
+
+ruby_version_is ""..."4.1" do
+ require_relative 'spec_helper'
+
+ describe "Net::FTP#debug_mode" do
+ it "returns true when self is in debug mode" do
+ ftp = Net::FTP.new
+ ftp.debug_mode.should == false
+
+ ftp.debug_mode = true
+ ftp.debug_mode.should == true
+ end
+ end
+
+ describe "Net::FTP#debug_mode=" do
+ it "sets self into debug mode when passed true" do
+ ftp = Net::FTP.new
+ ftp.debug_mode = true
+ ftp.debug_mode.should == true
+
+ ftp.debug_mode = false
+ ftp.debug_mode.should == false
+ end
+ end
+end
diff --git a/spec/ruby/library/net-ftp/default_passive_spec.rb b/spec/ruby/library/net-ftp/default_passive_spec.rb
new file mode 100644
index 0000000000..b47b4e9782
--- /dev/null
+++ b/spec/ruby/library/net-ftp/default_passive_spec.rb
@@ -0,0 +1,11 @@
+require_relative '../../spec_helper'
+
+ruby_version_is ""..."4.1" do
+ require_relative 'spec_helper'
+
+ describe "Net::FTP#default_passive" do
+ it "is true by default" do
+ ruby_exe(fixture(__FILE__, "default_passive.rb")).should == "true\ntrue\n"
+ end
+ end
+end
diff --git a/spec/ruby/library/net-ftp/delete_spec.rb b/spec/ruby/library/net-ftp/delete_spec.rb
new file mode 100644
index 0000000000..40cd8f1d99
--- /dev/null
+++ b/spec/ruby/library/net-ftp/delete_spec.rb
@@ -0,0 +1,62 @@
+require_relative '../../spec_helper'
+
+ruby_version_is ""..."4.1" do
+ require_relative 'spec_helper'
+ require_relative 'fixtures/server'
+
+ describe "Net::FTP#delete" do
+ before :each do
+ @server = NetFTPSpecs::DummyFTP.new
+ @server.serve_once
+
+ @ftp = Net::FTP.new
+ @ftp.connect(@server.hostname, @server.server_port)
+ end
+
+ after :each do
+ @ftp.quit rescue nil
+ @ftp.close
+ @server.stop
+ end
+
+ it "sends the DELE command with the passed filename to the server" do
+ @ftp.delete("test.file")
+ @ftp.last_response.should == "250 Requested file action okay, completed. (DELE test.file)\n"
+ end
+
+ it "raises a Net::FTPTempError when the response code is 450" do
+ @server.should_receive(:dele).and_respond("450 Requested file action not taken.")
+ -> { @ftp.delete("test.file") }.should.raise(Net::FTPTempError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 550" do
+ @server.should_receive(:dele).and_respond("550 Requested action not taken.")
+ -> { @ftp.delete("test.file") }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 500" do
+ @server.should_receive(:dele).and_respond("500 Syntax error, command unrecognized.")
+ -> { @ftp.delete("test.file") }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 501" do
+ @server.should_receive(:dele).and_respond("501 Syntax error in parameters or arguments.")
+ -> { @ftp.delete("test.file") }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 502" do
+ @server.should_receive(:dele).and_respond("502 Command not implemented.")
+ -> { @ftp.delete("test.file") }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPTempError when the response code is 421" do
+ @server.should_receive(:dele).and_respond("421 Service not available, closing control connection.")
+ -> { @ftp.delete("test.file") }.should.raise(Net::FTPTempError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 530" do
+ @server.should_receive(:dele).and_respond("530 Not logged in.")
+ -> { @ftp.delete("test.file") }.should.raise(Net::FTPPermError)
+ end
+ end
+end
diff --git a/spec/ruby/library/net-ftp/dir_spec.rb b/spec/ruby/library/net-ftp/dir_spec.rb
new file mode 100644
index 0000000000..af38724fad
--- /dev/null
+++ b/spec/ruby/library/net-ftp/dir_spec.rb
@@ -0,0 +1,11 @@
+require_relative '../../spec_helper'
+
+ruby_version_is ""..."4.1" do
+ require_relative 'spec_helper'
+ require_relative 'fixtures/server'
+ require_relative 'shared/list'
+
+ describe "Net::FTP#dir" do
+ it_behaves_like :net_ftp_list, :dir
+ end
+end
diff --git a/spec/ruby/library/net/ftp/fixtures/default_passive.rb b/spec/ruby/library/net-ftp/fixtures/default_passive.rb
index b6995d6f34..b6995d6f34 100644
--- a/spec/ruby/library/net/ftp/fixtures/default_passive.rb
+++ b/spec/ruby/library/net-ftp/fixtures/default_passive.rb
diff --git a/spec/ruby/library/net/ftp/fixtures/passive.rb b/spec/ruby/library/net-ftp/fixtures/passive.rb
index 6b5cde82df..6b5cde82df 100644
--- a/spec/ruby/library/net/ftp/fixtures/passive.rb
+++ b/spec/ruby/library/net-ftp/fixtures/passive.rb
diff --git a/spec/ruby/library/net/ftp/fixtures/putbinaryfile b/spec/ruby/library/net-ftp/fixtures/putbinaryfile
index f3130c6e43..f3130c6e43 100644
--- a/spec/ruby/library/net/ftp/fixtures/putbinaryfile
+++ b/spec/ruby/library/net-ftp/fixtures/putbinaryfile
diff --git a/spec/ruby/library/net/ftp/fixtures/puttextfile b/spec/ruby/library/net-ftp/fixtures/puttextfile
index b4f3b2b62d..b4f3b2b62d 100644
--- a/spec/ruby/library/net/ftp/fixtures/puttextfile
+++ b/spec/ruby/library/net-ftp/fixtures/puttextfile
diff --git a/spec/ruby/library/net-ftp/fixtures/server.rb b/spec/ruby/library/net-ftp/fixtures/server.rb
new file mode 100644
index 0000000000..9fc2beb57b
--- /dev/null
+++ b/spec/ruby/library/net-ftp/fixtures/server.rb
@@ -0,0 +1,279 @@
+ruby_version_is ""..."4.1" do
+ module NetFTPSpecs
+ class DummyFTP
+ attr_accessor :connect_message
+ attr_reader :login_user, :login_pass, :login_acct
+
+ # hostname or IP address
+ attr_reader :hostname
+ # port number
+ attr_reader :server_port
+
+ def initialize
+ @hostname = "127.0.0.1"
+ @server = TCPServer.new(@hostname, 0)
+ @server_port = @server.addr[1]
+
+ @handlers = {}
+ @commands = []
+ @connect_message = nil
+ end
+
+ def serve_once
+ @thread = Thread.new do
+ @socket = @server.accept
+ @socket.setsockopt(Socket::SOL_SOCKET, Socket::SO_OOBINLINE, 1)
+ begin
+ handle_request
+ ensure
+ @socket.close
+ end
+ end
+ end
+
+ def handle_request
+ # Send out the welcome message.
+ response @connect_message || "220 Dummy FTP Server ready!"
+
+ begin
+ while command = @socket.gets
+ command, argument = command.chomp.split(" ", 2)
+
+ if command == "QUIT"
+ self.response("221 OK, bye")
+ break
+ elsif proc_handler = @handlers[command.downcase.to_sym]
+ if argument.nil?
+ proc_handler.call(self)
+ else
+ proc_handler.call(self, argument)
+ end
+ else
+ if argument.nil?
+ self.send(command.downcase.to_sym)
+ else
+ self.send(command.downcase.to_sym, argument)
+ end
+ end
+ end
+ rescue => e
+ self.error_response("Exception: #{e} #{e.backtrace.inspect}")
+ end
+ end
+
+ def error_response(text)
+ self.response("451 #{text}")
+ end
+
+ def response(text)
+ @socket.puts(text) unless @socket.closed?
+ end
+
+ def stop
+ @datasocket.close unless @datasocket.nil? || @datasocket.closed?
+ @server.close
+ @thread.join
+ end
+
+
+ ##
+ def handle(sym, &block)
+ @handlers[sym] = block
+ end
+
+ def should_receive(method)
+ @handler_for = method
+ self
+ end
+
+ def and_respond(text)
+ @handlers[@handler_for] = -> s, *args { s.response(text) }
+ end
+
+ ##
+ # FTP methods
+ ##
+
+ def abor
+ self.response("226 Closing data connection. (ABOR)")
+ end
+
+ def acct(account)
+ @login_acct = account
+ self.response("230 User '#{account}' logged in, proceed. (ACCT)")
+ end
+
+ def cdup
+ self.response("200 Command okay. (CDUP)")
+ end
+
+ def cwd(dir)
+ self.response("200 Command okay. (CWD #{dir})")
+ end
+
+ def dele(file)
+ self.response("250 Requested file action okay, completed. (DELE #{file})")
+ end
+
+ def eprt(arg)
+ _, _, host, port = arg.split("|")
+
+ @datasocket = TCPSocket.new(host, port)
+ self.response("200 port opened")
+ end
+
+ def help(param = :default)
+ if param == :default
+ self.response("211 System status, or system help reply. (HELP)")
+ else
+ self.response("211 System status, or system help reply. (HELP #{param})")
+ end
+ end
+
+ def list(folder)
+ self.response("150 opening ASCII connection for file list")
+ @datasocket.puts("-rw-r--r-- 1 spec staff 507 17 Jul 18:41 last_response_code.rb")
+ @datasocket.puts("-rw-r--r-- 1 spec staff 50 17 Jul 18:41 list.rb")
+ @datasocket.puts("-rw-r--r-- 1 spec staff 48 17 Jul 18:41 pwd.rb")
+ @datasocket.close()
+ self.response("226 transfer complete (LIST #{folder})")
+ end
+
+ def mdtm(filename)
+ self.response("213 19980705132316")
+ end
+
+ def mkd(foldername)
+ self.response(%Q{257 "#{foldername.gsub('"', '""')}" created.})
+ end
+
+ def nlst(folder = nil)
+ self.response("150 opening ASCII connection for file list")
+ @datasocket.puts("last_response_code.rb")
+ @datasocket.puts("list.rb")
+ @datasocket.puts("pwd.rb")
+ @datasocket.close()
+ self.response("226 transfer complete (NLST#{folder ? " #{folder}" : ""})")
+ end
+
+ def noop
+ self.response("200 Command okay. (NOOP)")
+ end
+
+ def pass(password)
+ @login_pass = password
+ self.response("230 User logged in, proceed. (PASS #{password})")
+ end
+
+ def port(arg)
+ nums = arg.split(",")
+
+ if nums[0] == "::1"
+ # IPv6
+ port = nums[1].to_i * 256 + nums[2].to_i
+ host = nums[0]
+ else
+ # IPv4
+ port = nums[4].to_i * 256 + nums[5].to_i
+ host = nums[0..3].join(".")
+ end
+
+ @datasocket = TCPSocket.new(host, port)
+ self.response("200 port opened")
+ end
+
+ def pwd
+ self.response('257 "/some/dir/" - current directory')
+ end
+
+ def retr(file)
+ self.response("125 Data transfer starting")
+ if @restart_at && @restart_at == 20
+ @datasocket.puts("of the file named '#{file}'.")
+ @restart_at = nil
+ else
+ @datasocket.puts("This is the content")
+ @datasocket.puts("of the file named '#{file}'.")
+ end
+ @datasocket.close()
+ self.response("226 Closing data connection. (RETR #{file})")
+ end
+
+ def rest(at_bytes)
+ @restart_at = at_bytes.to_i
+ self.response("350 Requested file action pending further information. (REST)")
+ end
+
+ def rmd(folder)
+ self.response("250 Requested file action okay, completed. (RMD #{folder})")
+ end
+
+ def rnfr(from)
+ @rename_from = from
+ self.response("350 Requested file action pending further information.")
+ end
+
+ def rnto(to)
+ self.response("250 Requested file action okay, completed. (Renamed #{@rename_from} to #{to})")
+ @rename_from = nil
+ end
+
+ def site(param)
+ self.response("200 Command okay. (SITE #{param})")
+ end
+
+ def size(filename)
+ if filename == "binary"
+ self.response("213 24")
+ else
+ self.response("213 1024")
+ end
+ end
+
+ def stat(param = :default)
+ if param == :default
+ self.response("211 System status, or system help reply. (STAT)")
+ else
+ self.response("211 System status, or system help reply. (STAT #{param})")
+ end
+ end
+
+ def stor(file)
+ tmp_file = tmp("#{file}file", false)
+
+ self.response("125 Data transfer starting.")
+
+ mode = @restart_at ? "a" : "w"
+
+ File.open(tmp_file, mode + "b") do |f|
+ loop do
+ data = @datasocket.recv(1024)
+ break if !data || data.empty?
+ f << data
+ end
+ end
+
+ @datasocket.close()
+ self.response("200 OK, Data received. (STOR #{file})")
+ end
+
+ def appe(file)
+ @restart_at = true
+ stor(file)
+ end
+
+ def syst
+ self.response("215 FTP Dummy Server (SYST)")
+ end
+
+ def type(type)
+ self.response("200 TYPE switched to #{type}")
+ end
+
+ def user(name)
+ @login_user = name
+ self.response("230 User logged in, proceed. (USER #{name})")
+ end
+ end
+ end
+end
diff --git a/spec/ruby/library/net-ftp/get_spec.rb b/spec/ruby/library/net-ftp/get_spec.rb
new file mode 100644
index 0000000000..6a8aa3e206
--- /dev/null
+++ b/spec/ruby/library/net-ftp/get_spec.rb
@@ -0,0 +1,24 @@
+require_relative '../../spec_helper'
+
+ruby_version_is ""..."4.1" do
+ require_relative 'spec_helper'
+ require_relative 'fixtures/server'
+ require_relative 'shared/gettextfile'
+ require_relative 'shared/getbinaryfile'
+
+ describe "Net::FTP#get (binary mode)" do
+ before :each do
+ @binary_mode = true
+ end
+
+ it_behaves_like :net_ftp_getbinaryfile, :get
+ end
+
+ describe "Net::FTP#get (text mode)" do
+ before :each do
+ @binary_mode = false
+ end
+
+ it_behaves_like :net_ftp_gettextfile, :get
+ end
+end
diff --git a/spec/ruby/library/net-ftp/getbinaryfile_spec.rb b/spec/ruby/library/net-ftp/getbinaryfile_spec.rb
new file mode 100644
index 0000000000..6b2d38edf5
--- /dev/null
+++ b/spec/ruby/library/net-ftp/getbinaryfile_spec.rb
@@ -0,0 +1,11 @@
+require_relative '../../spec_helper'
+
+ruby_version_is ""..."4.1" do
+ require_relative 'spec_helper'
+ require_relative 'fixtures/server'
+ require_relative 'shared/getbinaryfile'
+
+ describe "Net::FTP#getbinaryfile" do
+ it_behaves_like :net_ftp_getbinaryfile, :getbinaryfile
+ end
+end
diff --git a/spec/ruby/library/net-ftp/getdir_spec.rb b/spec/ruby/library/net-ftp/getdir_spec.rb
new file mode 100644
index 0000000000..2ff62d399d
--- /dev/null
+++ b/spec/ruby/library/net-ftp/getdir_spec.rb
@@ -0,0 +1,10 @@
+require_relative '../../spec_helper'
+
+ruby_version_is ""..."4.1" do
+ require_relative 'spec_helper'
+ require_relative 'shared/pwd'
+
+ describe "Net::FTP#getdir" do
+ it_behaves_like :net_ftp_pwd, :getdir
+ end
+end
diff --git a/spec/ruby/library/net-ftp/gettextfile_spec.rb b/spec/ruby/library/net-ftp/gettextfile_spec.rb
new file mode 100644
index 0000000000..3bb037663b
--- /dev/null
+++ b/spec/ruby/library/net-ftp/gettextfile_spec.rb
@@ -0,0 +1,11 @@
+require_relative '../../spec_helper'
+
+ruby_version_is ""..."4.1" do
+ require_relative 'spec_helper'
+ require_relative 'fixtures/server'
+ require_relative 'shared/gettextfile'
+
+ describe "Net::FTP#gettextfile" do
+ it_behaves_like :net_ftp_gettextfile, :gettextfile
+ end
+end
diff --git a/spec/ruby/library/net-ftp/help_spec.rb b/spec/ruby/library/net-ftp/help_spec.rb
new file mode 100644
index 0000000000..bb52fb9e69
--- /dev/null
+++ b/spec/ruby/library/net-ftp/help_spec.rb
@@ -0,0 +1,69 @@
+require_relative '../../spec_helper'
+
+ruby_version_is ""..."4.1" do
+ require_relative 'spec_helper'
+ require_relative 'fixtures/server'
+
+ describe "Net::FTP#help" do
+ def with_connection
+ yield
+ end
+
+ before :each do
+ @server = NetFTPSpecs::DummyFTP.new
+ @server.serve_once
+
+ @ftp = Net::FTP.new
+ @ftp.connect(@server.hostname, @server.server_port)
+ end
+
+ after :each do
+ @ftp.quit rescue nil
+ @ftp.close
+ @server.stop
+ end
+
+ it "writes the HELP command to the server" do
+ @ftp.help
+ @ftp.last_response.should == "211 System status, or system help reply. (HELP)\n"
+ end
+
+ it "returns the server's response" do
+ @ftp.help.should == "211 System status, or system help reply. (HELP)\n"
+ end
+
+ it "writes the HELP command with an optional parameter to the socket" do
+ @ftp.help("some parameter").should == "211 System status, or system help reply. (HELP some parameter)\n"
+ end
+
+ it "does not raise any error when the response code is 211" do
+ @server.should_receive(:help).and_respond("211 System status, or system help reply.")
+ -> { @ftp.help }.should_not.raise
+ end
+
+ it "does not raise any error when the response code is 214" do
+ @server.should_receive(:help).and_respond("214 Help message.")
+ -> { @ftp.help }.should_not.raise
+ end
+
+ it "raises a Net::FTPPermError when the response code is 500" do
+ @server.should_receive(:help).and_respond("500 Syntax error, command unrecognized.")
+ -> { @ftp.help }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 501" do
+ @server.should_receive(:help).and_respond("501 Syntax error in parameters or arguments.")
+ -> { @ftp.help }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 502" do
+ @server.should_receive(:help).and_respond("502 Command not implemented.")
+ -> { @ftp.help }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPTempError when the response code is 421" do
+ @server.should_receive(:help).and_respond("421 Service not available, closing control connection.")
+ -> { @ftp.help }.should.raise(Net::FTPTempError)
+ end
+ end
+end
diff --git a/spec/ruby/library/net-ftp/initialize_spec.rb b/spec/ruby/library/net-ftp/initialize_spec.rb
new file mode 100644
index 0000000000..9079ad6b79
--- /dev/null
+++ b/spec/ruby/library/net-ftp/initialize_spec.rb
@@ -0,0 +1,408 @@
+require_relative '../../spec_helper'
+
+ruby_version_is ""..."4.1" do
+ require_relative 'spec_helper'
+
+ describe "Net::FTP#initialize" do
+ before :each do
+ @ftp = Net::FTP.allocate
+ @ftp.stub!(:connect)
+ @port_args = []
+ @port_args << 21
+ end
+
+ it "is private" do
+ Net::FTP.private_instance_methods(false).should.include?(:initialize)
+ end
+
+ it "sets self into binary mode" do
+ @ftp.binary.should == nil
+ @ftp.send(:initialize)
+ @ftp.binary.should == true
+ end
+
+ it "sets self into active mode" do
+ @ftp.passive.should == nil
+ @ftp.send(:initialize)
+ @ftp.passive.should == false
+ end
+
+ it "sets self into non-debug mode" do
+ @ftp.debug_mode.should == nil
+ @ftp.send(:initialize)
+ @ftp.debug_mode.should == false
+ end
+
+ it "sets self to not resume file uploads/downloads" do
+ @ftp.resume.should == nil
+ @ftp.send(:initialize)
+ @ftp.resume.should == false
+ end
+
+ describe "when passed no arguments" do
+ it "does not try to connect" do
+ @ftp.should_not_receive(:connect)
+ @ftp.send(:initialize)
+ end
+ end
+
+ describe "when passed host" do
+ it "tries to connect to the passed host" do
+ @ftp.should_receive(:connect).with("localhost", *@port_args)
+ @ftp.send(:initialize, "localhost")
+ end
+ end
+
+ describe "when passed host, user" do
+ it "tries to connect to the passed host" do
+ @ftp.should_receive(:connect).with("localhost", *@port_args)
+ @ftp.send(:initialize, "localhost")
+ end
+
+ it "tries to login with the passed username" do
+ @ftp.should_receive(:login).with("rubyspec", nil, nil)
+ @ftp.send(:initialize, "localhost", "rubyspec")
+ end
+ end
+
+ describe "when passed host, user, password" do
+ it "tries to connect to the passed host" do
+ @ftp.should_receive(:connect).with("localhost", *@port_args)
+ @ftp.send(:initialize, "localhost")
+ end
+
+ it "tries to login with the passed username and password" do
+ @ftp.should_receive(:login).with("rubyspec", "rocks", nil)
+ @ftp.send(:initialize, "localhost", "rubyspec", "rocks")
+ end
+ end
+
+ describe "when passed host, user" do
+ it "tries to connect to the passed host" do
+ @ftp.should_receive(:connect).with("localhost", *@port_args)
+ @ftp.send(:initialize, "localhost")
+ end
+
+ it "tries to login with the passed username, password and account" do
+ @ftp.should_receive(:login).with("rubyspec", "rocks", "account")
+ @ftp.send(:initialize, "localhost", "rubyspec", "rocks", "account")
+ end
+ end
+
+ before :each do
+ @ftp.stub!(:login)
+ end
+
+ describe 'when the host' do
+ describe 'is set' do
+ describe 'and port option' do
+ describe 'is set' do
+ it 'tries to connect to the host on the specified port' do
+ options = mock('ftp initialize options')
+ options.should_receive(:to_hash).and_return({ port: 8080 })
+ @ftp.should_receive(:connect).with('localhost', 8080)
+
+ @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(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/net-ftp/last_response_code_spec.rb b/spec/ruby/library/net-ftp/last_response_code_spec.rb
new file mode 100644
index 0000000000..03329758b5
--- /dev/null
+++ b/spec/ruby/library/net-ftp/last_response_code_spec.rb
@@ -0,0 +1,11 @@
+require_relative '../../spec_helper'
+
+ruby_version_is ""..."4.1" do
+ require_relative 'spec_helper'
+ require_relative 'shared/last_response_code'
+ require_relative 'fixtures/server'
+
+ describe "Net::FTP#last_response_code" do
+ it_behaves_like :net_ftp_last_response_code, :last_response_code
+ end
+end
diff --git a/spec/ruby/library/net-ftp/last_response_spec.rb b/spec/ruby/library/net-ftp/last_response_spec.rb
new file mode 100644
index 0000000000..7cda9fa7a4
--- /dev/null
+++ b/spec/ruby/library/net-ftp/last_response_spec.rb
@@ -0,0 +1,28 @@
+require_relative '../../spec_helper'
+
+ruby_version_is ""..."4.1" do
+ require_relative 'spec_helper'
+ require_relative 'fixtures/server'
+
+ describe "Net::FTP#last_response" do
+ before :each do
+ @server = NetFTPSpecs::DummyFTP.new
+ @server.serve_once
+
+ @ftp = Net::FTP.new
+ @ftp.connect(@server.hostname, @server.server_port)
+ end
+
+ after :each do
+ @ftp.quit rescue nil
+ @ftp.close
+ @server.stop
+ end
+
+ it "returns the last response" do
+ @ftp.last_response.should == "220 Dummy FTP Server ready!\n"
+ @ftp.help
+ @ftp.last_response.should == "211 System status, or system help reply. (HELP)\n"
+ end
+ end
+end
diff --git a/spec/ruby/library/net-ftp/lastresp_spec.rb b/spec/ruby/library/net-ftp/lastresp_spec.rb
new file mode 100644
index 0000000000..c373670ec4
--- /dev/null
+++ b/spec/ruby/library/net-ftp/lastresp_spec.rb
@@ -0,0 +1,11 @@
+require_relative '../../spec_helper'
+
+ruby_version_is ""..."4.1" do
+ require_relative 'spec_helper'
+ require_relative 'shared/last_response_code'
+ require_relative 'fixtures/server'
+
+ describe "Net::FTP#lastresp" do
+ it_behaves_like :net_ftp_last_response_code, :lastresp
+ end
+end
diff --git a/spec/ruby/library/net-ftp/list_spec.rb b/spec/ruby/library/net-ftp/list_spec.rb
new file mode 100644
index 0000000000..297d100dd9
--- /dev/null
+++ b/spec/ruby/library/net-ftp/list_spec.rb
@@ -0,0 +1,11 @@
+require_relative '../../spec_helper'
+
+ruby_version_is ""..."4.1" do
+ require_relative 'spec_helper'
+ require_relative 'fixtures/server'
+ require_relative 'shared/list'
+
+ describe "Net::FTP#list" do
+ it_behaves_like :net_ftp_list, :list
+ end
+end
diff --git a/spec/ruby/library/net-ftp/login_spec.rb b/spec/ruby/library/net-ftp/login_spec.rb
new file mode 100644
index 0000000000..05bb6b7f81
--- /dev/null
+++ b/spec/ruby/library/net-ftp/login_spec.rb
@@ -0,0 +1,198 @@
+require_relative '../../spec_helper'
+
+ruby_version_is ""..."4.1" do
+ require_relative 'spec_helper'
+ require_relative 'fixtures/server'
+
+ describe "Net::FTP#login" do
+ before :each do
+ @server = NetFTPSpecs::DummyFTP.new
+ @server.serve_once
+
+ @ftp = Net::FTP.new
+ @ftp.connect(@server.hostname, @server.server_port)
+ end
+
+ after :each do
+ @ftp.quit rescue nil
+ @ftp.close
+ @server.stop
+ end
+
+ describe "when passed no arguments" do
+ it "sends the USER command with 'anonymous' as name to the server" do
+ @ftp.login
+ @server.login_user.should == "anonymous"
+ end
+
+ it "sends 'anonymous@' as a password when required" do
+ @server.should_receive(:user).and_respond("331 User name okay, need password.")
+ @ftp.login
+ @server.login_pass.should == "anonymous@"
+ end
+
+ it "raises a Net::FTPReplyError when the server requests an account" do
+ @server.should_receive(:user).and_respond("331 User name okay, need password.")
+ @server.should_receive(:pass).and_respond("332 Need account for login.")
+ -> { @ftp.login }.should.raise(Net::FTPReplyError)
+ end
+ end
+
+ describe "when passed name" do
+ it "sends the USER command with the passed name to the server" do
+ @ftp.login("rubyspec")
+ @server.login_user.should == "rubyspec"
+ end
+
+ it "raises a Net::FTPReplyError when the server requests a password, but none was given" do
+ @server.should_receive(:user).and_respond("331 User name okay, need password.")
+ -> { @ftp.login("rubyspec") }.should.raise(Net::FTPReplyError)
+ end
+
+ it "raises a Net::FTPReplyError when the server requests an account, but none was given" do
+ @server.should_receive(:user).and_respond("331 User name okay, need password.")
+ @server.should_receive(:pass).and_respond("332 Need account for login.")
+ -> { @ftp.login("rubyspec") }.should.raise(Net::FTPReplyError)
+ end
+ end
+
+ describe "when passed name, password" do
+ it "sends the USER command with the passed name to the server" do
+ @ftp.login("rubyspec", "rocks")
+ @server.login_user.should == "rubyspec"
+ end
+
+ it "sends the passed password when required" do
+ @server.should_receive(:user).and_respond("331 User name okay, need password.")
+ @ftp.login("rubyspec", "rocks")
+ @server.login_pass.should == "rocks"
+ end
+
+ it "raises a Net::FTPReplyError when the server requests an account" do
+ @server.should_receive(:user).and_respond("331 User name okay, need password.")
+ @server.should_receive(:pass).and_respond("332 Need account for login.")
+ -> { @ftp.login("rubyspec", "rocks") }.should.raise(Net::FTPReplyError)
+ end
+ end
+
+ describe "when passed name, password, account" do
+ it "sends the USER command with the passed name to the server" do
+ @ftp.login("rubyspec", "rocks", "account")
+ @server.login_user.should == "rubyspec"
+ end
+
+ it "sends the passed password when required" do
+ @server.should_receive(:user).and_respond("331 User name okay, need password.")
+ @ftp.login("rubyspec", "rocks", "account")
+ @server.login_pass.should == "rocks"
+ end
+
+ it "sends the passed account when required" do
+ @server.should_receive(:user).and_respond("331 User name okay, need password.")
+ @server.should_receive(:pass).and_respond("332 Need account for login.")
+ @ftp.login("rubyspec", "rocks", "account")
+ @server.login_acct.should == "account"
+ end
+ end
+
+ describe "when the USER command fails" do
+ it "raises a Net::FTPPermError when the response code is 500" do
+ @server.should_receive(:user).and_respond("500 Syntax error, command unrecognized.")
+ -> { @ftp.login("rubyspec", "rocks", "account") }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 501" do
+ @server.should_receive(:user).and_respond("501 Syntax error in parameters or arguments.")
+ -> { @ftp.login("rubyspec", "rocks", "account") }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 502" do
+ @server.should_receive(:user).and_respond("502 Command not implemented.")
+ -> { @ftp.login("rubyspec", "rocks", "account") }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPTempError when the response code is 421" do
+ @server.should_receive(:user).and_respond("421 Service not available, closing control connection.")
+ -> { @ftp.login("rubyspec", "rocks", "account") }.should.raise(Net::FTPTempError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 530" do
+ @server.should_receive(:user).and_respond("530 Not logged in.")
+ -> { @ftp.login("rubyspec", "rocks", "account") }.should.raise(Net::FTPPermError)
+ end
+ end
+
+ describe "when the PASS command fails" do
+ before :each do
+ @server.should_receive(:user).and_respond("331 User name okay, need password.")
+ end
+
+ it "does not raise an Error when the response code is 202" do
+ @server.should_receive(:pass).and_respond("202 Command not implemented, superfluous at this site.")
+ -> { @ftp.login("rubyspec", "rocks", "account") }.should_not.raise
+ end
+
+ it "raises a Net::FTPPermError when the response code is 500" do
+ @server.should_receive(:pass).and_respond("500 Syntax error, command unrecognized.")
+ -> { @ftp.login("rubyspec", "rocks", "account") }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 501" do
+ @server.should_receive(:pass).and_respond("501 Syntax error in parameters or arguments.")
+ -> { @ftp.login("rubyspec", "rocks", "account") }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 502" do
+ @server.should_receive(:pass).and_respond("502 Command not implemented.")
+ -> { @ftp.login("rubyspec", "rocks", "account") }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPTempError when the response code is 421" do
+ @server.should_receive(:pass).and_respond("421 Service not available, closing control connection.")
+ -> { @ftp.login("rubyspec", "rocks", "account") }.should.raise(Net::FTPTempError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 530" do
+ @server.should_receive(:pass).and_respond("530 Not logged in.")
+ -> { @ftp.login("rubyspec", "rocks", "account") }.should.raise(Net::FTPPermError)
+ end
+ end
+
+ describe "when the ACCT command fails" do
+ before :each do
+ @server.should_receive(:user).and_respond("331 User name okay, need password.")
+ @server.should_receive(:pass).and_respond("332 Need account for login.")
+ end
+
+ it "does not raise an Error when the response code is 202" do
+ @server.should_receive(:acct).and_respond("202 Command not implemented, superfluous at this site.")
+ -> { @ftp.login("rubyspec", "rocks", "account") }.should_not.raise
+ end
+
+ it "raises a Net::FTPPermError when the response code is 500" do
+ @server.should_receive(:acct).and_respond("500 Syntax error, command unrecognized.")
+ -> { @ftp.login("rubyspec", "rocks", "account") }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 501" do
+ @server.should_receive(:acct).and_respond("501 Syntax error in parameters or arguments.")
+ -> { @ftp.login("rubyspec", "rocks", "account") }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 502" do
+ @server.should_receive(:acct).and_respond("502 Command not implemented.")
+ -> { @ftp.login("rubyspec", "rocks", "account") }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPTempError when the response code is 421" do
+ @server.should_receive(:acct).and_respond("421 Service not available, closing control connection.")
+ -> { @ftp.login("rubyspec", "rocks", "account") }.should.raise(Net::FTPTempError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 530" do
+ @server.should_receive(:acct).and_respond("530 Not logged in.")
+ -> { @ftp.login("rubyspec", "rocks", "account") }.should.raise(Net::FTPPermError)
+ end
+ end
+ end
+end
diff --git a/spec/ruby/library/net-ftp/ls_spec.rb b/spec/ruby/library/net-ftp/ls_spec.rb
new file mode 100644
index 0000000000..f8fdb10e8f
--- /dev/null
+++ b/spec/ruby/library/net-ftp/ls_spec.rb
@@ -0,0 +1,11 @@
+require_relative '../../spec_helper'
+
+ruby_version_is ""..."4.1" do
+ require_relative 'spec_helper'
+ require_relative 'fixtures/server'
+ require_relative 'shared/list'
+
+ describe "Net::FTP#ls" do
+ it_behaves_like :net_ftp_list, :ls
+ end
+end
diff --git a/spec/ruby/library/net-ftp/mdtm_spec.rb b/spec/ruby/library/net-ftp/mdtm_spec.rb
new file mode 100644
index 0000000000..effd22a6e4
--- /dev/null
+++ b/spec/ruby/library/net-ftp/mdtm_spec.rb
@@ -0,0 +1,41 @@
+require_relative '../../spec_helper'
+
+ruby_version_is ""..."4.1" do
+ require_relative 'spec_helper'
+ require_relative 'fixtures/server'
+
+ describe "Net::FTP#mdtm" do
+ before :each do
+ @server = NetFTPSpecs::DummyFTP.new
+ @server.serve_once
+
+ @ftp = Net::FTP.new
+ @ftp.connect(@server.hostname, @server.server_port)
+ end
+
+ after :each do
+ @ftp.quit rescue nil
+ @ftp.close
+ @server.stop
+ end
+
+ it "sends the MDTM with the passed filename command to the server" do
+ @ftp.mdtm("test.file")
+ @ftp.last_response.should == "213 19980705132316\n"
+ end
+
+ it "returns the last modification time of the passed file" do
+ @ftp.mdtm("test.file").should == "19980705132316"
+ end
+
+ it "raises a Net::FTPPermError when the response code is 550" do
+ @server.should_receive(:mdtm).and_respond("550 Requested action not taken.")
+ -> { @ftp.mdtm("test.file") }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPTempError when the response code is 421" do
+ @server.should_receive(:mdtm).and_respond("421 Service not available, closing control connection.")
+ -> { @ftp.mdtm("test.file") }.should.raise(Net::FTPTempError)
+ end
+ end
+end
diff --git a/spec/ruby/library/net-ftp/mkdir_spec.rb b/spec/ruby/library/net-ftp/mkdir_spec.rb
new file mode 100644
index 0000000000..6daeb7c022
--- /dev/null
+++ b/spec/ruby/library/net-ftp/mkdir_spec.rb
@@ -0,0 +1,64 @@
+require_relative '../../spec_helper'
+
+ruby_version_is ""..."4.1" do
+ require_relative 'spec_helper'
+ require_relative 'fixtures/server'
+
+ describe "Net::FTP#mkdir" do
+ before :each do
+ @server = NetFTPSpecs::DummyFTP.new
+ @server.serve_once
+
+ @ftp = Net::FTP.new
+ @ftp.connect(@server.hostname, @server.server_port)
+ end
+
+ after :each do
+ @ftp.quit rescue nil
+ @ftp.close
+ @server.stop
+ end
+
+ it "sends the MKD command with the passed pathname to the server" do
+ @ftp.mkdir("test.folder")
+ @ftp.last_response.should == %{257 "test.folder" created.\n}
+ end
+
+ it "returns the path to the newly created directory" do
+ @ftp.mkdir("test.folder").should == "test.folder"
+ @ftp.mkdir("/absolute/path/to/test.folder").should == "/absolute/path/to/test.folder"
+ @ftp.mkdir("relative/path/to/test.folder").should == "relative/path/to/test.folder"
+ @ftp.mkdir('/usr/dm/foo"bar').should == '/usr/dm/foo"bar'
+ end
+
+ it "raises a Net::FTPPermError when the response code is 500" do
+ @server.should_receive(:mkd).and_respond("500 Syntax error, command unrecognized.")
+ -> { @ftp.mkdir("test.folder") }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 501" do
+ @server.should_receive(:mkd).and_respond("501 Syntax error in parameters or arguments.")
+ -> { @ftp.mkdir("test.folder") }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 502" do
+ @server.should_receive(:mkd).and_respond("502 Command not implemented.")
+ -> { @ftp.mkdir("test.folder") }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPTempError when the response code is 421" do
+ @server.should_receive(:mkd).and_respond("421 Service not available, closing control connection.")
+ -> { @ftp.mkdir("test.folder") }.should.raise(Net::FTPTempError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 530" do
+ @server.should_receive(:mkd).and_respond("530 Not logged in.")
+ -> { @ftp.mkdir("test.folder") }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 550" do
+ @server.should_receive(:mkd).and_respond("550 Requested action not taken.")
+ -> { @ftp.mkdir("test.folder") }.should.raise(Net::FTPPermError)
+ end
+ end
+end
diff --git a/spec/ruby/library/net-ftp/mtime_spec.rb b/spec/ruby/library/net-ftp/mtime_spec.rb
new file mode 100644
index 0000000000..694036a296
--- /dev/null
+++ b/spec/ruby/library/net-ftp/mtime_spec.rb
@@ -0,0 +1,53 @@
+require_relative '../../spec_helper'
+
+ruby_version_is ""..."4.1" do
+ require_relative 'spec_helper'
+ require_relative 'fixtures/server'
+
+ describe "Net::FTP#mtime" do
+ before :each do
+ @server = NetFTPSpecs::DummyFTP.new
+ @server.serve_once
+
+ @ftp = Net::FTP.new
+ @ftp.connect(@server.hostname, @server.server_port)
+ end
+
+ after :each do
+ @ftp.quit rescue nil
+ @ftp.close
+ @server.stop
+ end
+
+ it "sends the MDTM with the passed filename command to the server" do
+ @ftp.mtime("test.file")
+ @ftp.last_response.should == "213 19980705132316\n"
+ end
+
+ describe "when passed filename" do
+ it "returns the last modification time of the passed file as a Time object in the local time" do
+ @ftp.mtime("test.file").should == Time.gm("1998", "07", "05", "13", "23", "16")
+ end
+ end
+
+ describe "when passed filename, local_time" do
+ it "returns the last modification time as a Time object in UTC when local_time is true" do
+ @ftp.mtime("test.file", true).should == Time.local("1998", "07", "05", "13", "23", "16")
+ end
+
+ it "returns the last modification time as a Time object in the local time when local_time is false" do
+ @ftp.mtime("test.file", false).should == Time.gm("1998", "07", "05", "13", "23", "16")
+ end
+ end
+
+ it "raises a Net::FTPPermError when the response code is 550" do
+ @server.should_receive(:mdtm).and_respond("550 Requested action not taken.")
+ -> { @ftp.mtime("test.file") }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPTempError when the response code is 421" do
+ @server.should_receive(:mdtm).and_respond("421 Service not available, closing control connection.")
+ -> { @ftp.mtime("test.file") }.should.raise(Net::FTPTempError)
+ end
+ end
+end
diff --git a/spec/ruby/library/net-ftp/nlst_spec.rb b/spec/ruby/library/net-ftp/nlst_spec.rb
new file mode 100644
index 0000000000..87b80b43fd
--- /dev/null
+++ b/spec/ruby/library/net-ftp/nlst_spec.rb
@@ -0,0 +1,95 @@
+require_relative '../../spec_helper'
+
+ruby_version_is ""..."4.1" do
+ require_relative 'spec_helper'
+ require_relative 'fixtures/server'
+
+ describe "Net::FTP#nlst" do
+ before :each do
+ @server = NetFTPSpecs::DummyFTP.new
+ @server.serve_once
+
+ @ftp = Net::FTP.new
+ @ftp.passive = false
+ @ftp.connect(@server.hostname, @server.server_port)
+ end
+
+ after :each do
+ @ftp.quit rescue nil
+ @ftp.close
+ @server.stop
+ end
+
+ describe "when passed no arguments" do
+ it "returns an Array containing a list of files in the current dir" do
+ @ftp.nlst.should == ["last_response_code.rb", "list.rb", "pwd.rb"]
+ @ftp.last_response.should == "226 transfer complete (NLST)\n"
+ end
+ end
+
+ describe "when passed dir" do
+ it "returns an Array containing a list of files in the passed dir" do
+ @ftp.nlst("test.folder").should == ["last_response_code.rb", "list.rb", "pwd.rb"]
+ @ftp.last_response.should == "226 transfer complete (NLST test.folder)\n"
+ end
+ end
+
+ describe "when the NLST command fails" do
+ it "raises a Net::FTPTempError when the response code is 450" do
+ @server.should_receive(:nlst).and_respond("450 Requested file action not taken..")
+ -> { @ftp.nlst }.should.raise(Net::FTPTempError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 500" do
+ @server.should_receive(:nlst).and_respond("500 Syntax error, command unrecognized.")
+ -> { @ftp.nlst }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 501" do
+ @server.should_receive(:nlst).and_respond("501 Syntax error, command unrecognized.")
+ -> { @ftp.nlst }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 502" do
+ @server.should_receive(:nlst).and_respond("502 Command not implemented.")
+ -> { @ftp.nlst }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPTempError when the response code is 421" do
+ @server.should_receive(:nlst).and_respond("421 Service not available, closing control connection.")
+ -> { @ftp.nlst }.should.raise(Net::FTPTempError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 530" do
+ @server.should_receive(:nlst).and_respond("530 Not logged in.")
+ -> { @ftp.nlst }.should.raise(Net::FTPPermError)
+ end
+ end
+
+ describe "when opening the data port fails" do
+ it "raises a Net::FTPPermError when the response code is 500" do
+ @server.should_receive(:eprt).and_respond("500 Syntax error, command unrecognized.")
+ @server.should_receive(:port).and_respond("500 Syntax error, command unrecognized.")
+ -> { @ftp.nlst }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 501" do
+ @server.should_receive(:eprt).and_respond("501 Syntax error in parameters or arguments.")
+ @server.should_receive(:port).and_respond("501 Syntax error in parameters or arguments.")
+ -> { @ftp.nlst }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPTempError when the response code is 421" do
+ @server.should_receive(:eprt).and_respond("421 Service not available, closing control connection.")
+ @server.should_receive(:port).and_respond("421 Service not available, closing control connection.")
+ -> { @ftp.nlst }.should.raise(Net::FTPTempError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 530" do
+ @server.should_receive(:eprt).and_respond("530 Not logged in.")
+ @server.should_receive(:port).and_respond("530 Not logged in.")
+ -> { @ftp.nlst }.should.raise(Net::FTPPermError)
+ end
+ end
+ end
+end
diff --git a/spec/ruby/library/net-ftp/noop_spec.rb b/spec/ruby/library/net-ftp/noop_spec.rb
new file mode 100644
index 0000000000..43c48e355a
--- /dev/null
+++ b/spec/ruby/library/net-ftp/noop_spec.rb
@@ -0,0 +1,41 @@
+require_relative '../../spec_helper'
+
+ruby_version_is ""..."4.1" do
+ require_relative 'spec_helper'
+ require_relative 'fixtures/server'
+
+ describe "Net::FTP#noop" do
+ before :each do
+ @server = NetFTPSpecs::DummyFTP.new
+ @server.serve_once
+
+ @ftp = Net::FTP.new
+ @ftp.connect(@server.hostname, @server.server_port)
+ end
+
+ after :each do
+ @ftp.quit rescue nil
+ @ftp.close
+ @server.stop
+ end
+
+ it "sends the NOOP command to the server" do
+ @ftp.noop
+ @ftp.last_response.should == "200 Command okay. (NOOP)\n"
+ end
+
+ it "returns nil" do
+ @ftp.noop.should == nil
+ end
+
+ it "raises a Net::FTPPermError when the response code is 500" do
+ @server.should_receive(:noop).and_respond("500 Syntax error, command unrecognized.")
+ -> { @ftp.noop }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPTempError when the response code is 421" do
+ @server.should_receive(:noop).and_respond("421 Service not available, closing control connection.")
+ -> { @ftp.noop }.should.raise(Net::FTPTempError)
+ end
+ end
+end
diff --git a/spec/ruby/library/net-ftp/open_spec.rb b/spec/ruby/library/net-ftp/open_spec.rb
new file mode 100644
index 0000000000..2d6477ec4d
--- /dev/null
+++ b/spec/ruby/library/net-ftp/open_spec.rb
@@ -0,0 +1,58 @@
+require_relative '../../spec_helper'
+
+ruby_version_is ""..."4.1" do
+ require_relative 'spec_helper'
+
+ describe "Net::FTP.open" do
+ before :each do
+ @ftp = mock("Net::FTP instance")
+ Net::FTP.stub!(:new).and_return(@ftp)
+ end
+
+ describe "when passed no block" do
+ it "returns a new Net::FTP instance" do
+ Net::FTP.open("localhost").should.equal?(@ftp)
+ end
+
+ it "passes the passed arguments down to Net::FTP.new" do
+ Net::FTP.should_receive(:new).with("localhost", "user", "password", "account")
+ Net::FTP.open("localhost", "user", "password", "account")
+ end
+ end
+
+ describe "when passed a block" do
+ before :each do
+ @ftp.stub!(:close)
+ end
+
+ it "yields a new Net::FTP instance to the passed block" do
+ yielded = false
+ Net::FTP.open("localhost") do |ftp|
+ yielded = true
+ ftp.should.equal?(@ftp)
+ end
+ yielded.should == true
+ end
+
+ it "closes the Net::FTP instance after yielding" do
+ Net::FTP.open("localhost") do |ftp|
+ ftp.should_receive(:close)
+ end
+ end
+
+ it "closes the Net::FTP instance even if an exception is raised while yielding" do
+ begin
+ Net::FTP.open("localhost") do |ftp|
+ ftp.should_receive(:close)
+ raise ArgumentError, "some exception"
+ end
+ rescue ArgumentError
+ end
+ end
+
+ it "returns the block's return value" do
+ Net::FTP.open("localhost") { :test }.should == :test
+ end
+ end
+ end
+end
diff --git a/spec/ruby/library/net-ftp/passive_spec.rb b/spec/ruby/library/net-ftp/passive_spec.rb
new file mode 100644
index 0000000000..6acabd3f98
--- /dev/null
+++ b/spec/ruby/library/net-ftp/passive_spec.rb
@@ -0,0 +1,31 @@
+require_relative '../../spec_helper'
+
+ruby_version_is ""..."4.1" do
+ require_relative 'spec_helper'
+
+ describe "Net::FTP#passive" do
+ it "returns true when self is in passive mode" do
+ ftp = Net::FTP.new
+ ftp.passive.should == false
+
+ ftp.passive = true
+ ftp.passive.should == true
+ end
+
+ it "is the value of Net::FTP.default_value by default" do
+ ruby_exe(fixture(__FILE__, "passive.rb")).should == "true"
+ end
+ end
+
+ describe "Net::FTP#passive=" do
+ it "sets self to passive mode when passed true" do
+ ftp = Net::FTP.new
+
+ ftp.passive = true
+ ftp.passive.should == true
+
+ ftp.passive = false
+ ftp.passive.should == false
+ end
+ end
+end
diff --git a/spec/ruby/library/net-ftp/put_spec.rb b/spec/ruby/library/net-ftp/put_spec.rb
new file mode 100644
index 0000000000..603409e283
--- /dev/null
+++ b/spec/ruby/library/net-ftp/put_spec.rb
@@ -0,0 +1,24 @@
+require_relative '../../spec_helper'
+
+ruby_version_is ""..."4.1" do
+ require_relative 'spec_helper'
+ require_relative 'fixtures/server'
+ require_relative 'shared/puttextfile'
+ require_relative 'shared/putbinaryfile'
+
+ describe "Net::FTP#put (binary mode)" do
+ before :each do
+ @binary_mode = true
+ end
+
+ it_behaves_like :net_ftp_putbinaryfile, :put
+ end
+
+ describe "Net::FTP#put (text mode)" do
+ before :each do
+ @binary_mode = false
+ end
+
+ it_behaves_like :net_ftp_puttextfile, :put
+ end
+end
diff --git a/spec/ruby/library/net-ftp/putbinaryfile_spec.rb b/spec/ruby/library/net-ftp/putbinaryfile_spec.rb
new file mode 100644
index 0000000000..ce8a6f0473
--- /dev/null
+++ b/spec/ruby/library/net-ftp/putbinaryfile_spec.rb
@@ -0,0 +1,11 @@
+require_relative '../../spec_helper'
+
+ruby_version_is ""..."4.1" do
+ require_relative 'spec_helper'
+ require_relative 'fixtures/server'
+ require_relative 'shared/putbinaryfile'
+
+ describe "Net::FTP#putbinaryfile" do
+ it_behaves_like :net_ftp_putbinaryfile, :putbinaryfile
+ end
+end
diff --git a/spec/ruby/library/net-ftp/puttextfile_spec.rb b/spec/ruby/library/net-ftp/puttextfile_spec.rb
new file mode 100644
index 0000000000..b4ab86aab1
--- /dev/null
+++ b/spec/ruby/library/net-ftp/puttextfile_spec.rb
@@ -0,0 +1,11 @@
+require_relative '../../spec_helper'
+
+ruby_version_is ""..."4.1" do
+ require_relative 'spec_helper'
+ require_relative 'fixtures/server'
+ require_relative 'shared/puttextfile'
+
+ describe "Net::FTP#puttextfile" do
+ it_behaves_like :net_ftp_puttextfile, :puttextfile
+ end
+end
diff --git a/spec/ruby/library/net-ftp/pwd_spec.rb b/spec/ruby/library/net-ftp/pwd_spec.rb
new file mode 100644
index 0000000000..53692b553f
--- /dev/null
+++ b/spec/ruby/library/net-ftp/pwd_spec.rb
@@ -0,0 +1,56 @@
+require_relative '../../spec_helper'
+
+ruby_version_is ""..."4.1" do
+ require_relative 'spec_helper'
+ require_relative 'fixtures/server'
+
+ describe "Net::FTP#pwd" do
+ before :each do
+ @server = NetFTPSpecs::DummyFTP.new
+ @server.serve_once
+
+ @ftp = Net::FTP.new
+ @ftp.connect(@server.hostname, @server.server_port)
+ end
+
+ after :each do
+ @ftp.quit rescue nil
+ @ftp.close
+ @server.stop
+ end
+
+ it "sends the PWD command to the server" do
+ @ftp.pwd
+ @ftp.last_response.should == "257 \"/some/dir/\" - current directory\n"
+ end
+
+ it "returns the current directory" do
+ @ftp.pwd.should == "/some/dir/"
+ end
+
+ it "raises a Net::FTPPermError when the response code is 500" do
+ @server.should_receive(:pwd).and_respond("500 Syntax error, command unrecognized.")
+ -> { @ftp.pwd }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 501" do
+ @server.should_receive(:pwd).and_respond("501 Syntax error in parameters or arguments.")
+ -> { @ftp.pwd }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 502" do
+ @server.should_receive(:pwd).and_respond("502 Command not implemented.")
+ -> { @ftp.pwd }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPTempError when the response code is 421" do
+ @server.should_receive(:pwd).and_respond("421 Service not available, closing control connection.")
+ -> { @ftp.pwd }.should.raise(Net::FTPTempError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 550" do
+ @server.should_receive(:pwd).and_respond("550 Requested action not taken.")
+ -> { @ftp.pwd }.should.raise(Net::FTPPermError)
+ end
+ end
+end
diff --git a/spec/ruby/library/net-ftp/quit_spec.rb b/spec/ruby/library/net-ftp/quit_spec.rb
new file mode 100644
index 0000000000..1af0107d34
--- /dev/null
+++ b/spec/ruby/library/net-ftp/quit_spec.rb
@@ -0,0 +1,36 @@
+require_relative '../../spec_helper'
+
+ruby_version_is ""..."4.1" do
+ require_relative 'spec_helper'
+ require_relative 'fixtures/server'
+
+ describe "Net::FTP#quit" do
+ before :each do
+ @server = NetFTPSpecs::DummyFTP.new
+ @server.serve_once
+
+ @ftp = Net::FTP.new
+ @ftp.connect(@server.hostname, @server.server_port)
+ end
+
+ after :each do
+ @ftp.quit rescue nil
+ @ftp.close
+ @server.stop
+ end
+
+ it "sends the QUIT command to the server" do
+ @ftp.quit
+ @ftp.last_response.should == "221 OK, bye\n"
+ end
+
+ it "does not close the socket automatically" do
+ @ftp.quit
+ @ftp.closed?.should == false
+ end
+
+ it "returns nil" do
+ @ftp.quit.should == nil
+ end
+ end
+end
diff --git a/spec/ruby/library/net-ftp/rename_spec.rb b/spec/ruby/library/net-ftp/rename_spec.rb
new file mode 100644
index 0000000000..6541fe5301
--- /dev/null
+++ b/spec/ruby/library/net-ftp/rename_spec.rb
@@ -0,0 +1,97 @@
+require_relative '../../spec_helper'
+
+ruby_version_is ""..."4.1" do
+ require_relative 'spec_helper'
+ require_relative 'fixtures/server'
+
+ describe "Net::FTP#rename" do
+ before :each do
+ @server = NetFTPSpecs::DummyFTP.new
+ @server.serve_once
+
+ @ftp = Net::FTP.new
+ @ftp.connect(@server.hostname, @server.server_port)
+ end
+
+ after :each do
+ @ftp.quit rescue nil
+ @ftp.close
+ @server.stop
+ end
+
+ describe "when passed from_name, to_name" do
+ it "sends the RNFR command with the passed from_name and the RNTO command with the passed to_name to the server" do
+ @ftp.rename("from.file", "to.file")
+ @ftp.last_response.should == "250 Requested file action okay, completed. (Renamed from.file to to.file)\n"
+ end
+
+ it "returns something" do
+ @ftp.rename("from.file", "to.file").should == nil
+ end
+ end
+
+ describe "when the RNFR command fails" do
+ it "raises a Net::FTPTempError when the response code is 450" do
+ @server.should_receive(:rnfr).and_respond("450 Requested file action not taken.")
+ -> { @ftp.rename("from.file", "to.file") }.should.raise(Net::FTPTempError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 550" do
+ @server.should_receive(:rnfr).and_respond("550 Requested action not taken.")
+ -> { @ftp.rename("from.file", "to.file") }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 501" do
+ @server.should_receive(:rnfr).and_respond("501 Syntax error in parameters or arguments.")
+ -> { @ftp.rename("from.file", "to.file") }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 502" do
+ @server.should_receive(:rnfr).and_respond("502 Command not implemented.")
+ -> { @ftp.rename("from.file", "to.file") }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPTempError when the response code is 421" do
+ @server.should_receive(:rnfr).and_respond("421 Service not available, closing control connection.")
+ -> { @ftp.rename("from.file", "to.file") }.should.raise(Net::FTPTempError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 530" do
+ @server.should_receive(:rnfr).and_respond("530 Not logged in.")
+ -> { @ftp.rename("from.file", "to.file") }.should.raise(Net::FTPPermError)
+ end
+ end
+
+ describe "when the RNTO command fails" do
+ it "raises a Net::FTPPermError when the response code is 532" do
+ @server.should_receive(:rnfr).and_respond("532 Need account for storing files.")
+ -> { @ftp.rename("from.file", "to.file") }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 553" do
+ @server.should_receive(:rnto).and_respond("553 Requested action not taken.")
+ -> { @ftp.rename("from.file", "to.file") }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 501" do
+ @server.should_receive(:rnto).and_respond("501 Syntax error in parameters or arguments.")
+ -> { @ftp.rename("from.file", "to.file") }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 502" do
+ @server.should_receive(:rnto).and_respond("502 Command not implemented.")
+ -> { @ftp.rename("from.file", "to.file") }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPTempError when the response code is 421" do
+ @server.should_receive(:rnto).and_respond("421 Service not available, closing control connection.")
+ -> { @ftp.rename("from.file", "to.file") }.should.raise(Net::FTPTempError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 530" do
+ @server.should_receive(:rnto).and_respond("530 Not logged in.")
+ -> { @ftp.rename("from.file", "to.file") }.should.raise(Net::FTPPermError)
+ end
+ end
+ end
+end
diff --git a/spec/ruby/library/net-ftp/resume_spec.rb b/spec/ruby/library/net-ftp/resume_spec.rb
new file mode 100644
index 0000000000..5ec565d155
--- /dev/null
+++ b/spec/ruby/library/net-ftp/resume_spec.rb
@@ -0,0 +1,26 @@
+require_relative '../../spec_helper'
+
+ruby_version_is ""..."4.1" do
+ require_relative 'spec_helper'
+
+ describe "Net::FTP#resume" do
+ it "returns true when self is set to resume uploads/downloads" do
+ ftp = Net::FTP.new
+ ftp.resume.should == false
+
+ ftp.resume = true
+ ftp.resume.should == true
+ end
+ end
+
+ describe "Net::FTP#resume=" do
+ it "sets self to resume uploads/downloads when set to true" do
+ ftp = Net::FTP.new
+ ftp.resume = true
+ ftp.resume.should == true
+
+ ftp.resume = false
+ ftp.resume.should == false
+ end
+ end
+end
diff --git a/spec/ruby/library/net-ftp/retrbinary_spec.rb b/spec/ruby/library/net-ftp/retrbinary_spec.rb
new file mode 100644
index 0000000000..ff8c8098a4
--- /dev/null
+++ b/spec/ruby/library/net-ftp/retrbinary_spec.rb
@@ -0,0 +1,33 @@
+require_relative '../../spec_helper'
+
+ruby_version_is ""..."4.1" do
+ require_relative 'spec_helper'
+ require_relative 'fixtures/server'
+
+ describe "Net::FTP#retrbinary" do
+ before :each do
+ @server = NetFTPSpecs::DummyFTP.new
+ @server.serve_once
+
+ @ftp = Net::FTP.new
+ @ftp.connect(@server.hostname, @server.server_port)
+ end
+
+ after :each do
+ @ftp.quit rescue nil
+ @ftp.close
+ @server.stop
+ end
+
+ it "sends the passed command to the server" do
+ @ftp.retrbinary("RETR test", 4096) {}
+ @ftp.last_response.should == "226 Closing data connection. (RETR test)\n"
+ end
+
+ it "yields the received content as binary blocks of the passed size" do
+ res = []
+ @ftp.retrbinary("RETR test", 10) { |bin| res << bin }
+ res.should == [ "This is th", "e content\n", "of the fil", "e named 't", "est'.\n" ]
+ end
+ end
+end
diff --git a/spec/ruby/library/net-ftp/retrlines_spec.rb b/spec/ruby/library/net-ftp/retrlines_spec.rb
new file mode 100644
index 0000000000..2963da14f7
--- /dev/null
+++ b/spec/ruby/library/net-ftp/retrlines_spec.rb
@@ -0,0 +1,37 @@
+require_relative '../../spec_helper'
+
+ruby_version_is ""..."4.1" do
+ require_relative 'spec_helper'
+ require_relative 'fixtures/server'
+
+ describe "Net::FTP#retrlines" do
+ before :each do
+ @server = NetFTPSpecs::DummyFTP.new
+ @server.serve_once
+
+ @ftp = Net::FTP.new
+ @ftp.connect(@server.hostname, @server.server_port)
+ end
+
+ after :each do
+ @ftp.quit rescue nil
+ @ftp.close
+ @server.stop
+ end
+
+ it "sends the passed command over the socket" do
+ @ftp.retrlines("LIST test.dir") {}
+ @ftp.last_response.should == "226 transfer complete (LIST test.dir)\n"
+ end
+
+ it "yields each received line to the passed block" do
+ res = []
+ @ftp.retrlines("LIST test.dir") { |x| res << x }
+ res.should == [
+ "-rw-r--r-- 1 spec staff 507 17 Jul 18:41 last_response_code.rb",
+ "-rw-r--r-- 1 spec staff 50 17 Jul 18:41 list.rb",
+ "-rw-r--r-- 1 spec staff 48 17 Jul 18:41 pwd.rb"
+ ]
+ end
+ end
+end
diff --git a/spec/ruby/library/net-ftp/return_code_spec.rb b/spec/ruby/library/net-ftp/return_code_spec.rb
new file mode 100644
index 0000000000..fcf5a32aa7
--- /dev/null
+++ b/spec/ruby/library/net-ftp/return_code_spec.rb
@@ -0,0 +1,27 @@
+require_relative '../../spec_helper'
+
+ruby_version_is ""..."4.1" do
+ require_relative 'spec_helper'
+
+ describe "Net::FTP#return_code" do
+ before :each do
+ @ftp = Net::FTP.new
+ end
+
+ it "outputs a warning and returns a newline" do
+ -> do
+ @ftp.return_code.should == "\n"
+ end.should complain(/warning: Net::FTP#return_code is obsolete and do nothing/)
+ end
+ end
+
+ describe "Net::FTP#return_code=" do
+ before :each do
+ @ftp = Net::FTP.new
+ end
+
+ it "outputs a warning" do
+ -> { @ftp.return_code = 123 }.should complain(/warning: Net::FTP#return_code= is obsolete and do nothing/)
+ end
+ end
+end
diff --git a/spec/ruby/library/net-ftp/rmdir_spec.rb b/spec/ruby/library/net-ftp/rmdir_spec.rb
new file mode 100644
index 0000000000..23650ebcc8
--- /dev/null
+++ b/spec/ruby/library/net-ftp/rmdir_spec.rb
@@ -0,0 +1,61 @@
+require_relative '../../spec_helper'
+
+ruby_version_is ""..."4.1" do
+ require_relative 'spec_helper'
+ require_relative 'fixtures/server'
+
+ describe "Net::FTP#rmdir" do
+ before :each do
+ @server = NetFTPSpecs::DummyFTP.new
+ @server.serve_once
+
+ @ftp = Net::FTP.new
+ @ftp.connect(@server.hostname, @server.server_port)
+ end
+
+ after :each do
+ @ftp.quit rescue nil
+ @ftp.close
+ @server.stop
+ end
+
+ it "sends the RMD command with the passed pathname to the server" do
+ @ftp.rmdir("test.folder")
+ @ftp.last_response.should == "250 Requested file action okay, completed. (RMD test.folder)\n"
+ end
+
+ it "returns nil" do
+ @ftp.rmdir("test.folder").should == nil
+ end
+
+ it "raises a Net::FTPPermError when the response code is 500" do
+ @server.should_receive(:rmd).and_respond("500 Syntax error, command unrecognized.")
+ -> { @ftp.rmdir("test.folder") }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 501" do
+ @server.should_receive(:rmd).and_respond("501 Syntax error in parameters or arguments.")
+ -> { @ftp.rmdir("test.folder") }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 502" do
+ @server.should_receive(:rmd).and_respond("502 Command not implemented.")
+ -> { @ftp.rmdir("test.folder") }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPTempError when the response code is 421" do
+ @server.should_receive(:rmd).and_respond("421 Service not available, closing control connection.")
+ -> { @ftp.rmdir("test.folder") }.should.raise(Net::FTPTempError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 530" do
+ @server.should_receive(:rmd).and_respond("530 Not logged in.")
+ -> { @ftp.rmdir("test.folder") }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 550" do
+ @server.should_receive(:rmd).and_respond("550 Requested action not taken.")
+ -> { @ftp.rmdir("test.folder") }.should.raise(Net::FTPPermError)
+ end
+ end
+end
diff --git a/spec/ruby/library/net-ftp/sendcmd_spec.rb b/spec/ruby/library/net-ftp/sendcmd_spec.rb
new file mode 100644
index 0000000000..67dbd3bdb8
--- /dev/null
+++ b/spec/ruby/library/net-ftp/sendcmd_spec.rb
@@ -0,0 +1,57 @@
+require_relative '../../spec_helper'
+
+ruby_version_is ""..."4.1" do
+ require_relative 'spec_helper'
+ require_relative 'fixtures/server'
+
+ describe "Net::FTP#sendcmd" do
+ before :each do
+ @server = NetFTPSpecs::DummyFTP.new
+ @server.serve_once
+
+ @ftp = Net::FTP.new
+ @ftp.connect(@server.hostname, @server.server_port)
+ end
+
+ after :each do
+ @ftp.quit rescue nil
+ @ftp.close
+ @server.stop
+ end
+
+ it "sends the passed command to the server" do
+ @ftp.sendcmd("HELP")
+ @ftp.last_response.should == "211 System status, or system help reply. (HELP)\n"
+ end
+
+ it "returns the server's response" do
+ @ftp.sendcmd("HELP").should == "211 System status, or system help reply. (HELP)\n"
+ end
+
+ it "raises no error when the response code is 1xx, 2xx or 3xx" do
+ @server.should_receive(:help).and_respond("120 Service ready in nnn minutes.")
+ -> { @ftp.sendcmd("HELP") }.should_not.raise
+
+ @server.should_receive(:help).and_respond("200 Command okay.")
+ -> { @ftp.sendcmd("HELP") }.should_not.raise
+
+ @server.should_receive(:help).and_respond("350 Requested file action pending further information.")
+ -> { @ftp.sendcmd("HELP") }.should_not.raise
+ end
+
+ it "raises a Net::FTPTempError when the response code is 4xx" do
+ @server.should_receive(:help).and_respond("421 Service not available, closing control connection.")
+ -> { @ftp.sendcmd("HELP") }.should.raise(Net::FTPTempError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 5xx" do
+ @server.should_receive(:help).and_respond("500 Syntax error, command unrecognized.")
+ -> { @ftp.sendcmd("HELP") }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPProtoError when the response code is not between 1xx-5xx" do
+ @server.should_receive(:help).and_respond("999 Invalid response.")
+ -> { @ftp.sendcmd("HELP") }.should.raise(Net::FTPProtoError)
+ end
+ end
+end
diff --git a/spec/ruby/library/net-ftp/set_socket_spec.rb b/spec/ruby/library/net-ftp/set_socket_spec.rb
new file mode 100644
index 0000000000..ad83dfcc4f
--- /dev/null
+++ b/spec/ruby/library/net-ftp/set_socket_spec.rb
@@ -0,0 +1,11 @@
+require_relative '../../spec_helper'
+
+ruby_version_is ""..."4.1" do
+ require_relative 'spec_helper'
+
+ describe "Net::FTP#set_socket" do
+ # TODO: I won't spec this method, as it is not used
+ # anywhere and it should be private anyway.
+ it "needs to be reviewed for spec completeness"
+ end
+end
diff --git a/spec/ruby/library/net-ftp/shared/getbinaryfile.rb b/spec/ruby/library/net-ftp/shared/getbinaryfile.rb
new file mode 100644
index 0000000000..4fc4731c45
--- /dev/null
+++ b/spec/ruby/library/net-ftp/shared/getbinaryfile.rb
@@ -0,0 +1,152 @@
+ruby_version_is ""..."4.1" do
+ describe :net_ftp_getbinaryfile, shared: true do
+ before :each do
+ @fixture_file = __dir__ + "/../fixtures/getbinaryfile"
+ @tmp_file = tmp("getbinaryfile")
+
+ @server = NetFTPSpecs::DummyFTP.new
+ @server.serve_once
+
+ @ftp = Net::FTP.new
+ @ftp.connect(@server.hostname, @server.server_port)
+ @ftp.binary = @binary_mode
+ end
+
+ after :each do
+ @ftp.quit rescue nil
+ @ftp.close
+ @server.stop
+
+ rm_r @tmp_file
+ end
+
+ it "sends the RETR command to the server" do
+ @ftp.send(@method, "test", @tmp_file)
+ @ftp.last_response.should == "226 Closing data connection. (RETR test)\n"
+ end
+
+ it "returns nil" do
+ @ftp.send(@method, "test", @tmp_file).should == nil
+ end
+
+ it "saves the contents of the passed remote file to the passed local file" do
+ @ftp.send(@method, "test", @tmp_file)
+ File.read(@tmp_file).should == "This is the content\nof the file named 'test'.\n"
+ end
+
+ describe "when passed a block" do
+ it "yields the received content as binary blocks of the passed size" do
+ res = []
+ @ftp.send(@method, "test", @tmp_file, 10) { |bin| res << bin }
+ res.should == [ "This is th", "e content\n", "of the fil", "e named 't", "est'.\n" ]
+ end
+ end
+
+ describe "when resuming an existing file" do
+ before :each do
+ @tmp_file = tmp("getbinaryfile_resume")
+
+ File.open(@tmp_file, "wb") do |f|
+ f << "This is the content\n"
+ end
+
+ @ftp.resume = true
+ end
+
+ it "saves the remaining content of the passed remote file to the passed local file" do
+ @ftp.send(@method, "test", @tmp_file)
+ File.read(@tmp_file).should == "This is the content\nof the file named 'test'.\n"
+ end
+
+ describe "and the REST command fails" do
+ it "raises a Net::FTPProtoError when the response code is 550" do
+ @server.should_receive(:rest).and_respond("Requested action not taken.")
+ -> { @ftp.send(@method, "test", @tmp_file) }.should.raise(Net::FTPProtoError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 500" do
+ @server.should_receive(:rest).and_respond("500 Syntax error, command unrecognized.")
+ -> { @ftp.send(@method, "test", @tmp_file) }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 501" do
+ @server.should_receive(:rest).and_respond("501 Syntax error, command unrecognized.")
+ -> { @ftp.send(@method, "test", @tmp_file) }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 502" do
+ @server.should_receive(:rest).and_respond("502 Command not implemented.")
+ -> { @ftp.send(@method, "test", @tmp_file) }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPTempError when the response code is 421" do
+ @server.should_receive(:rest).and_respond("421 Service not available, closing control connection.")
+ -> { @ftp.send(@method, "test", @tmp_file) }.should.raise(Net::FTPTempError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 530" do
+ @server.should_receive(:rest).and_respond("530 Not logged in.")
+ -> { @ftp.send(@method, "test", @tmp_file) }.should.raise(Net::FTPPermError)
+ end
+ end
+ end
+
+ describe "when the RETR command fails" do
+ it "raises a Net::FTPTempError when the response code is 450" do
+ @server.should_receive(:retr).and_respond("450 Requested file action not taken.")
+ -> { @ftp.send(@method, "test", @tmp_file) }.should.raise(Net::FTPTempError)
+ end
+
+ it "raises a Net::FTPProtoError when the response code is 550" do
+ @server.should_receive(:retr).and_respond("Requested action not taken.")
+ -> { @ftp.send(@method, "test", @tmp_file) }.should.raise(Net::FTPProtoError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 500" do
+ @server.should_receive(:retr).and_respond("500 Syntax error, command unrecognized.")
+ -> { @ftp.send(@method, "test", @tmp_file) }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 501" do
+ @server.should_receive(:retr).and_respond("501 Syntax error, command unrecognized.")
+ -> { @ftp.send(@method, "test", @tmp_file) }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPTempError when the response code is 421" do
+ @server.should_receive(:retr).and_respond("421 Service not available, closing control connection.")
+ -> { @ftp.send(@method, "test", @tmp_file) }.should.raise(Net::FTPTempError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 530" do
+ @server.should_receive(:retr).and_respond("530 Not logged in.")
+ -> { @ftp.send(@method, "test", @tmp_file) }.should.raise(Net::FTPPermError)
+ end
+ end
+
+ describe "when opening the data port fails" do
+ it "raises a Net::FTPPermError when the response code is 500" do
+ @server.should_receive(:eprt).and_respond("500 Syntax error, command unrecognized.")
+ @server.should_receive(:port).and_respond("500 Syntax error, command unrecognized.")
+ -> { @ftp.send(@method, "test", @tmp_file) }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 501" do
+ @server.should_receive(:eprt).and_respond("501 Syntax error in parameters or arguments.")
+ @server.should_receive(:port).and_respond("501 Syntax error in parameters or arguments.")
+ -> { @ftp.send(@method, "test", @tmp_file) }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPTempError when the response code is 421" do
+ @server.should_receive(:eprt).and_respond("421 Service not available, closing control connection.")
+ @server.should_receive(:port).and_respond("421 Service not available, closing control connection.")
+ -> { @ftp.send(@method, "test", @tmp_file) }.should.raise(Net::FTPTempError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 530" do
+ @server.should_receive(:eprt).and_respond("530 Not logged in.")
+ @server.should_receive(:port).and_respond("530 Not logged in.")
+ -> { @ftp.send(@method, "test", @tmp_file) }.should.raise(Net::FTPPermError)
+ end
+ end
+ end
+end
diff --git a/spec/ruby/library/net-ftp/shared/gettextfile.rb b/spec/ruby/library/net-ftp/shared/gettextfile.rb
new file mode 100644
index 0000000000..562c7a3047
--- /dev/null
+++ b/spec/ruby/library/net-ftp/shared/gettextfile.rb
@@ -0,0 +1,102 @@
+ruby_version_is ""..."4.1" do
+ describe :net_ftp_gettextfile, shared: true do
+ before :each do
+ @tmp_file = tmp("gettextfile")
+
+ @server = NetFTPSpecs::DummyFTP.new
+ @server.serve_once
+
+ @ftp = Net::FTP.new
+ @ftp.connect(@server.hostname, @server.server_port)
+ @ftp.binary = @binary_mode
+ end
+
+ after :each do
+ @ftp.quit rescue nil
+ @ftp.close
+ @server.stop
+
+ rm_r @tmp_file
+ end
+
+ it "sends the RETR command to the server" do
+ @ftp.send(@method, "test", @tmp_file)
+ @ftp.last_response.should == "226 Closing data connection. (RETR test)\n"
+ end
+
+ it "returns nil" do
+ @ftp.send(@method, "test", @tmp_file).should == nil
+ end
+
+ it "saves the contents of the passed remote file to the passed local file" do
+ @ftp.send(@method, "test", @tmp_file)
+ File.read(@tmp_file).should == "This is the content\nof the file named 'test'.\n"
+ end
+
+ describe "when passed a block" do
+ it "yields each line of the retrieved file to the passed block" do
+ res = []
+ @ftp.send(@method, "test", @tmp_file) { |line| res << line }
+ res.should == [ "This is the content", "of the file named 'test'."]
+ end
+ end
+
+ describe "when the RETR command fails" do
+ it "raises a Net::FTPTempError when the response code is 450" do
+ @server.should_receive(:retr).and_respond("450 Requested file action not taken.")
+ -> { @ftp.send(@method, "test", @tmp_file) }.should.raise(Net::FTPTempError)
+ end
+
+ it "raises a Net::FTPProtoError when the response code is 550" do
+ @server.should_receive(:retr).and_respond("Requested action not taken.")
+ -> { @ftp.send(@method, "test", @tmp_file) }.should.raise(Net::FTPProtoError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 500" do
+ @server.should_receive(:retr).and_respond("500 Syntax error, command unrecognized.")
+ -> { @ftp.send(@method, "test", @tmp_file) }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 501" do
+ @server.should_receive(:retr).and_respond("501 Syntax error, command unrecognized.")
+ -> { @ftp.send(@method, "test", @tmp_file) }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPTempError when the response code is 421" do
+ @server.should_receive(:retr).and_respond("421 Service not available, closing control connection.")
+ -> { @ftp.send(@method, "test", @tmp_file) }.should.raise(Net::FTPTempError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 530" do
+ @server.should_receive(:retr).and_respond("530 Not logged in.")
+ -> { @ftp.send(@method, "test", @tmp_file) }.should.raise(Net::FTPPermError)
+ end
+ end
+
+ describe "when opening the data port fails" do
+ it "raises a Net::FTPPermError when the response code is 500" do
+ @server.should_receive(:eprt).and_respond("500 Syntax error, command unrecognized.")
+ @server.should_receive(:port).and_respond("500 Syntax error, command unrecognized.")
+ -> { @ftp.send(@method, "test", @tmp_file) }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 501" do
+ @server.should_receive(:eprt).and_respond("501 Syntax error in parameters or arguments.")
+ @server.should_receive(:port).and_respond("501 Syntax error in parameters or arguments.")
+ -> { @ftp.send(@method, "test", @tmp_file) }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPTempError when the response code is 421" do
+ @server.should_receive(:eprt).and_respond("421 Service not available, closing control connection.")
+ @server.should_receive(:port).and_respond("421 Service not available, closing control connection.")
+ -> { @ftp.send(@method, "test", @tmp_file) }.should.raise(Net::FTPTempError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 530" do
+ @server.should_receive(:eprt).and_respond("530 Not logged in.")
+ @server.should_receive(:port).and_respond("530 Not logged in.")
+ -> { @ftp.send(@method, "test", @tmp_file) }.should.raise(Net::FTPPermError)
+ end
+ end
+ end
+end
diff --git a/spec/ruby/library/net-ftp/shared/last_response_code.rb b/spec/ruby/library/net-ftp/shared/last_response_code.rb
new file mode 100644
index 0000000000..9d36e37f0c
--- /dev/null
+++ b/spec/ruby/library/net-ftp/shared/last_response_code.rb
@@ -0,0 +1,27 @@
+ruby_version_is ""..."4.1" do
+ describe :net_ftp_last_response_code, shared: true do
+ before :each do
+ @server = NetFTPSpecs::DummyFTP.new
+ @server.serve_once
+
+ @ftp = Net::FTP.new
+ @ftp.connect(@server.hostname, @server.server_port)
+ end
+
+ after :each do
+ @ftp.quit rescue nil
+ @ftp.close
+ @server.stop
+ end
+
+ it "returns the response code for the last response" do
+ @server.should_receive(:help).and_respond("200 Command okay.")
+ @ftp.help
+ @ftp.send(@method).should == "200"
+
+ @server.should_receive(:help).and_respond("212 Directory status.")
+ @ftp.help
+ @ftp.send(@method).should == "212"
+ end
+ end
+end
diff --git a/spec/ruby/library/net-ftp/shared/list.rb b/spec/ruby/library/net-ftp/shared/list.rb
new file mode 100644
index 0000000000..ec372447e8
--- /dev/null
+++ b/spec/ruby/library/net-ftp/shared/list.rb
@@ -0,0 +1,106 @@
+ruby_version_is ""..."4.1" do
+ describe :net_ftp_list, shared: true do
+ before :each do
+ @server = NetFTPSpecs::DummyFTP.new
+ @server.serve_once
+
+ @ftp = Net::FTP.new
+ @ftp.passive = false
+ @ftp.connect(@server.hostname, @server.server_port)
+ end
+
+ after :each do
+ @ftp.quit rescue nil
+ @ftp.close
+ @server.stop
+ end
+
+ describe "when passed a block" do
+ it "yields each file in the list of files in the passed dir" do
+ expected = [
+ "-rw-r--r-- 1 spec staff 507 17 Jul 18:41 last_response_code.rb",
+ "-rw-r--r-- 1 spec staff 50 17 Jul 18:41 list.rb",
+ "-rw-r--r-- 1 spec staff 48 17 Jul 18:41 pwd.rb"
+ ]
+
+ res = []
+ @ftp.send(@method, "test.folder") { |line| res << line}
+ res.should == expected
+
+ @ftp.last_response.should == "226 transfer complete (LIST test.folder)\n"
+ end
+ end
+
+ describe "when passed no block" do
+ it "returns an Array containing a list of files in the passed dir" do
+ expected = [
+ "-rw-r--r-- 1 spec staff 507 17 Jul 18:41 last_response_code.rb",
+ "-rw-r--r-- 1 spec staff 50 17 Jul 18:41 list.rb",
+ "-rw-r--r-- 1 spec staff 48 17 Jul 18:41 pwd.rb"
+ ]
+
+ @ftp.send(@method, "test.folder").should == expected
+
+ @ftp.last_response.should == "226 transfer complete (LIST test.folder)\n"
+ end
+ end
+
+ describe "when the LIST command fails" do
+ it "raises a Net::FTPTempError when the response code is 450" do
+ @server.should_receive(:list).and_respond("450 Requested file action not taken..")
+ -> { @ftp.send(@method) }.should.raise(Net::FTPTempError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 500" do
+ @server.should_receive(:list).and_respond("500 Syntax error, command unrecognized.")
+ -> { @ftp.send(@method) }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 501" do
+ @server.should_receive(:list).and_respond("501 Syntax error, command unrecognized.")
+ -> { @ftp.send(@method) }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 502" do
+ @server.should_receive(:list).and_respond("502 Command not implemented.")
+ -> { @ftp.send(@method) }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPTempError when the response code is 421" do
+ @server.should_receive(:list).and_respond("421 Service not available, closing control connection.")
+ -> { @ftp.send(@method) }.should.raise(Net::FTPTempError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 530" do
+ @server.should_receive(:list).and_respond("530 Not logged in.")
+ -> { @ftp.send(@method) }.should.raise(Net::FTPPermError)
+ end
+ end
+
+ describe "when opening the data port fails" do
+ it "raises a Net::FTPPermError when the response code is 500" do
+ @server.should_receive(:eprt).and_respond("500 Syntax error, command unrecognized.")
+ @server.should_receive(:port).and_respond("500 Syntax error, command unrecognized.")
+ -> { @ftp.send(@method) }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 501" do
+ @server.should_receive(:eprt).and_respond("501 Syntax error in parameters or arguments.")
+ @server.should_receive(:port).and_respond("501 Syntax error in parameters or arguments.")
+ -> { @ftp.send(@method) }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPTempError when the response code is 421" do
+ @server.should_receive(:eprt).and_respond("421 Service not available, closing control connection.")
+ @server.should_receive(:port).and_respond("421 Service not available, closing control connection.")
+ -> { @ftp.send(@method) }.should.raise(Net::FTPTempError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 530" do
+ @server.should_receive(:eprt).and_respond("530 Not logged in.")
+ @server.should_receive(:port).and_respond("530 Not logged in.")
+ -> { @ftp.send(@method) }.should.raise(Net::FTPPermError)
+ end
+ end
+ end
+end
diff --git a/spec/ruby/library/net-ftp/shared/putbinaryfile.rb b/spec/ruby/library/net-ftp/shared/putbinaryfile.rb
new file mode 100644
index 0000000000..afbe3c61f8
--- /dev/null
+++ b/spec/ruby/library/net-ftp/shared/putbinaryfile.rb
@@ -0,0 +1,169 @@
+ruby_version_is ""..."4.1" do
+ describe :net_ftp_putbinaryfile, shared: true do
+ before :each do
+ @server = NetFTPSpecs::DummyFTP.new
+ @server.serve_once
+
+ @local_fixture_file = __dir__ + "/../fixtures/putbinaryfile"
+ @remote_tmp_file = tmp("binaryfile", false)
+
+ @ftp = Net::FTP.new
+ @ftp.connect(@server.hostname, @server.server_port)
+ @ftp.binary = @binary_mode
+ end
+
+ after :each do
+ @ftp.quit rescue nil
+ @ftp.close
+ @server.stop
+
+ rm_r @remote_tmp_file
+ end
+
+ it "sends the STOR command to the server" do
+ @ftp.send(@method, @local_fixture_file, "binary")
+ @ftp.last_response.should == "200 OK, Data received. (STOR binary)\n"
+ end
+
+ it "sends the contents of the passed local_file, without modifications" do
+ @ftp.send(@method, @local_fixture_file, "binary")
+
+ remote_lines = File.readlines(@remote_tmp_file)
+ local_lines = File.readlines(@local_fixture_file)
+
+ remote_lines.should == local_lines
+ end
+
+ it "returns nil" do
+ @ftp.send(@method, @local_fixture_file, "binary").should == nil
+ end
+
+ describe "when passed a block" do
+ it "yields the transmitted content as binary blocks of the passed size" do
+ res = []
+ @ftp.send(@method, @local_fixture_file, "binary", 10) { |x| res << x }
+ res.should == [
+ "This is an", " example f",
+ "ile\nwhich ", "is going t",
+ "o be trans", "mitted\nusi",
+ "ng #putbin", "aryfile.\n"
+ ]
+ end
+ end
+
+ describe "when resuming an existing file" do
+ before :each do
+ File.open(@remote_tmp_file, "w") do |f|
+ f << "This is an example file\n"
+ end
+
+ @ftp.resume = true
+ end
+
+ it "sends the remaining content of the passed local_file to the passed remote_file" do
+ @ftp.send(@method, @local_fixture_file, "binary")
+ File.read(@remote_tmp_file).should == File.read(@local_fixture_file)
+ end
+
+ describe "and the APPE command fails" do
+ it "raises a Net::FTPProtoError when the response code is 550" do
+ @server.should_receive(:appe).and_respond("Requested action not taken.")
+ -> { @ftp.send(@method, @local_fixture_file, "binary") }.should.raise(Net::FTPProtoError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 500" do
+ @server.should_receive(:appe).and_respond("500 Syntax error, command unrecognized.")
+ -> { @ftp.send(@method, @local_fixture_file, "binary") }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 501" do
+ @server.should_receive(:appe).and_respond("501 Syntax error, command unrecognized.")
+ -> { @ftp.send(@method, @local_fixture_file, "binary") }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 502" do
+ @server.should_receive(:appe).and_respond("502 Command not implemented.")
+ -> { @ftp.send(@method, @local_fixture_file, "binary") }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPTempError when the response code is 421" do
+ @server.should_receive(:appe).and_respond("421 Service not available, closing control connection.")
+ -> { @ftp.send(@method, @local_fixture_file, "binary") }.should.raise(Net::FTPTempError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 530" do
+ @server.should_receive(:appe).and_respond("530 Not logged in.")
+ -> { @ftp.send(@method, @local_fixture_file, "binary") }.should.raise(Net::FTPPermError)
+ end
+ end
+ end
+
+ describe "when the STOR command fails" do
+ it "raises a Net::FTPPermError when the response code is 532" do
+ @server.should_receive(:stor).and_respond("532 Need account for storing files.")
+ -> { @ftp.send(@method, @local_fixture_file, "binary") }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPTempError when the response code is 450" do
+ @server.should_receive(:stor).and_respond("450 Requested file action not taken.")
+ -> { @ftp.send(@method, @local_fixture_file, "binary") }.should.raise(Net::FTPTempError)
+ end
+
+ it "raises a Net::FTPTempError when the response code is 452" do
+ @server.should_receive(:stor).and_respond("452 Requested action not taken.")
+ -> { @ftp.send(@method, @local_fixture_file, "binary") }.should.raise(Net::FTPTempError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 553" do
+ @server.should_receive(:stor).and_respond("553 Requested action not taken.")
+ -> { @ftp.send(@method, @local_fixture_file, "binary") }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 500" do
+ @server.should_receive(:stor).and_respond("500 Syntax error, command unrecognized.")
+ -> { @ftp.send(@method, @local_fixture_file, "binary") }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 501" do
+ @server.should_receive(:stor).and_respond("501 Syntax error in parameters or arguments.")
+ -> { @ftp.send(@method, @local_fixture_file, "binary") }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPTempError when the response code is 421" do
+ @server.should_receive(:stor).and_respond("421 Service not available, closing control connection.")
+ -> { @ftp.send(@method, @local_fixture_file, "binary") }.should.raise(Net::FTPTempError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 530" do
+ @server.should_receive(:stor).and_respond("530 Not logged in.")
+ -> { @ftp.send(@method, @local_fixture_file, "binary") }.should.raise(Net::FTPPermError)
+ end
+ end
+
+ describe "when opening the data port fails" do
+ it "raises a Net::FTPPermError when the response code is 500" do
+ @server.should_receive(:eprt).and_respond("500 Syntax error, command unrecognized.")
+ @server.should_receive(:port).and_respond("500 Syntax error, command unrecognized.")
+ -> { @ftp.send(@method, @local_fixture_file, "binary") }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 501" do
+ @server.should_receive(:eprt).and_respond("501 Syntax error in parameters or arguments.")
+ @server.should_receive(:port).and_respond("501 Syntax error in parameters or arguments.")
+ -> { @ftp.send(@method, @local_fixture_file, "binary") }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPTempError when the response code is 421" do
+ @server.should_receive(:eprt).and_respond("421 Service not available, closing control connection.")
+ @server.should_receive(:port).and_respond("421 Service not available, closing control connection.")
+ -> { @ftp.send(@method, @local_fixture_file, "binary") }.should.raise(Net::FTPTempError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 530" do
+ @server.should_receive(:eprt).and_respond("530 Not logged in.")
+ @server.should_receive(:port).and_respond("530 Not logged in.")
+ -> { @ftp.send(@method, @local_fixture_file, "binary") }.should.raise(Net::FTPPermError)
+ end
+ end
+ end
+end
diff --git a/spec/ruby/library/net-ftp/shared/puttextfile.rb b/spec/ruby/library/net-ftp/shared/puttextfile.rb
new file mode 100644
index 0000000000..3650cad230
--- /dev/null
+++ b/spec/ruby/library/net-ftp/shared/puttextfile.rb
@@ -0,0 +1,130 @@
+ruby_version_is ""..."4.1" do
+ describe :net_ftp_puttextfile, shared: true do
+ before :each do
+ @server = NetFTPSpecs::DummyFTP.new
+ @server.serve_once
+
+ @local_fixture_file = __dir__ + "/../fixtures/puttextfile"
+ @remote_tmp_file = tmp("textfile", false)
+
+ @ftp = Net::FTP.new
+ @ftp.connect(@server.hostname, @server.server_port)
+ @ftp.binary = @binary_mode
+ end
+
+ after :each do
+ @ftp.quit rescue nil
+ @ftp.close
+ @server.stop
+
+ rm_r @remote_tmp_file
+ end
+
+ it "sends the STOR command to the server" do
+ @ftp.send(@method, @local_fixture_file, "text")
+ @ftp.last_response.should == "200 OK, Data received. (STOR text)\n"
+ end
+
+ it "sends the contents of the passed local_file, using \\r\\n as the newline separator" do
+ @ftp.send(@method, @local_fixture_file, "text")
+
+ remote_lines = File.binread(@remote_tmp_file)
+ local_lines = File.binread(@local_fixture_file)
+
+ remote_lines.should_not == local_lines
+ remote_lines.should == local_lines.gsub("\n", "\r\n")
+ end
+
+ guard -> { Net::FTP::VERSION < '0.3.6' } do
+ it "returns nil" do
+ @ftp.send(@method, @local_fixture_file, "text").should == nil
+ end
+ end
+
+ guard -> { Net::FTP::VERSION >= '0.3.6' } do
+ it "returns the response" do
+ @ftp.send(@method, @local_fixture_file, "text").should == @ftp.last_response
+ end
+ end
+
+ describe "when passed a block" do
+ it "yields each transmitted line" do
+ res = []
+ @ftp.send(@method, @local_fixture_file, "text") { |x| res << x }
+ res.should == [
+ "This is an example file\r\n",
+ "which is going to be transmitted\r\n",
+ "using #puttextfile.\r\n"
+ ]
+ end
+ end
+
+ describe "when the STOR command fails" do
+ it "raises a Net::FTPPermError when the response code is 532" do
+ @server.should_receive(:stor).and_respond("532 Need account for storing files.")
+ -> { @ftp.send(@method, @local_fixture_file, "text") }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPTempError when the response code is 450" do
+ @server.should_receive(:stor).and_respond("450 Requested file action not taken.")
+ -> { @ftp.send(@method, @local_fixture_file, "text") }.should.raise(Net::FTPTempError)
+ end
+
+ it "raises a Net::FTPTempError when the response code is 452" do
+ @server.should_receive(:stor).and_respond("452 Requested action not taken.")
+ -> { @ftp.send(@method, @local_fixture_file, "text") }.should.raise(Net::FTPTempError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 553" do
+ @server.should_receive(:stor).and_respond("553 Requested action not taken.")
+ -> { @ftp.send(@method, @local_fixture_file, "text") }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 500" do
+ @server.should_receive(:stor).and_respond("500 Syntax error, command unrecognized.")
+ -> { @ftp.send(@method, @local_fixture_file, "text") }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 501" do
+ @server.should_receive(:stor).and_respond("501 Syntax error in parameters or arguments.")
+ -> { @ftp.send(@method, @local_fixture_file, "text") }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPTempError when the response code is 421" do
+ @server.should_receive(:stor).and_respond("421 Service not available, closing control connection.")
+ -> { @ftp.send(@method, @local_fixture_file, "text") }.should.raise(Net::FTPTempError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 530" do
+ @server.should_receive(:stor).and_respond("530 Not logged in.")
+ -> { @ftp.send(@method, @local_fixture_file, "text") }.should.raise(Net::FTPPermError)
+ end
+ end
+
+ describe "when opening the data port fails" do
+ it "raises a Net::FTPPermError when the response code is 500" do
+ @server.should_receive(:eprt).and_respond("500 Syntax error, command unrecognized.")
+ @server.should_receive(:port).and_respond("500 Syntax error, command unrecognized.")
+ -> { @ftp.send(@method, @local_fixture_file, "text") }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 501" do
+ @server.should_receive(:eprt).and_respond("501 Syntax error in parameters or arguments.")
+ @server.should_receive(:port).and_respond("501 Syntax error in parameters or arguments.")
+ -> { @ftp.send(@method, @local_fixture_file, "text") }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPTempError when the response code is 421" do
+ @server.should_receive(:eprt).and_respond("421 Service not available, closing control connection.")
+ @server.should_receive(:port).and_respond("421 Service not available, closing control connection.")
+ -> { @ftp.send(@method, @local_fixture_file, "text") }.should.raise(Net::FTPTempError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 530" do
+ @server.should_receive(:eprt).and_respond("530 Not logged in.")
+ @server.should_receive(:port).and_respond("530 Not logged in.")
+ -> { @ftp.send(@method, @local_fixture_file, "text") }.should.raise(Net::FTPPermError)
+ end
+ end
+ end
+end
diff --git a/spec/ruby/library/net-ftp/shared/pwd.rb b/spec/ruby/library/net-ftp/shared/pwd.rb
new file mode 100644
index 0000000000..db3e587464
--- /dev/null
+++ b/spec/ruby/library/net-ftp/shared/pwd.rb
@@ -0,0 +1,5 @@
+ruby_version_is ""..."4.1" do
+ describe :net_ftp_pwd, shared: true do
+
+ end
+end
diff --git a/spec/ruby/library/net-ftp/site_spec.rb b/spec/ruby/library/net-ftp/site_spec.rb
new file mode 100644
index 0000000000..adc7dfafdf
--- /dev/null
+++ b/spec/ruby/library/net-ftp/site_spec.rb
@@ -0,0 +1,56 @@
+require_relative '../../spec_helper'
+
+ruby_version_is ""..."4.1" do
+ require_relative 'spec_helper'
+ require_relative 'fixtures/server'
+
+ describe "Net::FTP#site" do
+ before :each do
+ @server = NetFTPSpecs::DummyFTP.new
+ @server.serve_once
+
+ @ftp = Net::FTP.new
+ @ftp.connect(@server.hostname, @server.server_port)
+ end
+
+ after :each do
+ @ftp.quit rescue nil
+ @ftp.close
+ @server.stop
+ end
+
+ it "sends the SITE command with the passed argument to the server" do
+ @ftp.site("param")
+ @ftp.last_response.should == "200 Command okay. (SITE param)\n"
+ end
+
+ it "returns nil" do
+ @ftp.site("param").should == nil
+ end
+
+ it "does not raise an error when the response code is 202" do
+ @server.should_receive(:site).and_respond("202 Command not implemented, superfluous at this site.")
+ -> { @ftp.site("param") }.should_not.raise
+ end
+
+ it "raises a Net::FTPPermError when the response code is 500" do
+ @server.should_receive(:site).and_respond("500 Syntax error, command unrecognized.")
+ -> { @ftp.site("param") }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 501" do
+ @server.should_receive(:site).and_respond("501 Syntax error in parameters or arguments.")
+ -> { @ftp.site("param") }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPTempError when the response code is 421" do
+ @server.should_receive(:site).and_respond("421 Service not available, closing control connection.")
+ -> { @ftp.site("param") }.should.raise(Net::FTPTempError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 530" do
+ @server.should_receive(:site).and_respond("530 Requested action not taken.")
+ -> { @ftp.site("param") }.should.raise(Net::FTPPermError)
+ end
+ end
+end
diff --git a/spec/ruby/library/net-ftp/size_spec.rb b/spec/ruby/library/net-ftp/size_spec.rb
new file mode 100644
index 0000000000..dd84e5a449
--- /dev/null
+++ b/spec/ruby/library/net-ftp/size_spec.rb
@@ -0,0 +1,51 @@
+require_relative '../../spec_helper'
+
+ruby_version_is ""..."4.1" do
+ require_relative 'spec_helper'
+ require_relative 'fixtures/server'
+
+ describe "Net::FTP#size" do
+ before :each do
+ @server = NetFTPSpecs::DummyFTP.new
+ @server.serve_once
+
+ @ftp = Net::FTP.new
+ @ftp.connect(@server.hostname, @server.server_port)
+ end
+
+ after :each do
+ @ftp.quit rescue nil
+ @ftp.close
+ @server.stop
+ end
+
+ it "sends the SIZE command to the server" do
+ @ftp.size("test.file")
+ @ftp.last_response.should == "213 1024\n"
+ end
+
+ it "returns the size of the passed file as Integer" do
+ @ftp.size("test.file").should.eql?(1024)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 500" do
+ @server.should_receive(:size).and_respond("500 Syntax error, command unrecognized.")
+ -> { @ftp.size("test.file") }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 501" do
+ @server.should_receive(:size).and_respond("501 Syntax error in parameters or arguments.")
+ -> { @ftp.size("test.file") }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPTempError when the response code is 421" do
+ @server.should_receive(:size).and_respond("421 Service not available, closing control connection.")
+ -> { @ftp.size("test.file") }.should.raise(Net::FTPTempError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 550" do
+ @server.should_receive(:size).and_respond("550 Requested action not taken.")
+ -> { @ftp.size("test.file") }.should.raise(Net::FTPPermError)
+ end
+ end
+end
diff --git a/spec/ruby/library/net-ftp/spec_helper.rb b/spec/ruby/library/net-ftp/spec_helper.rb
new file mode 100644
index 0000000000..7689b4fb0c
--- /dev/null
+++ b/spec/ruby/library/net-ftp/spec_helper.rb
@@ -0,0 +1,7 @@
+ruby_version_is ""..."4.1" do
+ require "net/ftp"
+
+ if defined?(Net::FTP.default_passive)
+ Net::FTP.default_passive = false
+ end
+end
diff --git a/spec/ruby/library/net-ftp/status_spec.rb b/spec/ruby/library/net-ftp/status_spec.rb
new file mode 100644
index 0000000000..ce29e215d4
--- /dev/null
+++ b/spec/ruby/library/net-ftp/status_spec.rb
@@ -0,0 +1,70 @@
+require_relative '../../spec_helper'
+
+ruby_version_is ""..."4.1" do
+ require_relative 'spec_helper'
+ require_relative 'fixtures/server'
+
+ describe "Net::FTP#status" do
+ before :each do
+ @server = NetFTPSpecs::DummyFTP.new
+ @server.serve_once
+
+ @ftp = Net::FTP.new
+ @ftp.connect(@server.hostname, @server.server_port)
+ end
+
+ after :each do
+ @ftp.quit rescue nil
+ @ftp.close
+ @server.stop
+ end
+
+ it "sends the STAT command to the server" do
+ @ftp.status
+ @ftp.last_response.should == "211 System status, or system help reply. (STAT)\n"
+ end
+
+ it "sends the STAT command with an optional parameter to the server" do
+ @ftp.status("/pub").should == "211 System status, or system help reply. (STAT /pub)\n"
+ end
+
+ it "returns the received information" do
+ @ftp.status.should == "211 System status, or system help reply. (STAT)\n"
+ end
+
+ it "does not raise an error when the response code is 212" do
+ @server.should_receive(:stat).and_respond("212 Directory status.")
+ -> { @ftp.status }.should_not.raise
+ end
+
+ it "does not raise an error when the response code is 213" do
+ @server.should_receive(:stat).and_respond("213 File status.")
+ -> { @ftp.status }.should_not.raise
+ end
+
+ it "raises a Net::FTPPermError when the response code is 500" do
+ @server.should_receive(:stat).and_respond("500 Syntax error, command unrecognized.")
+ -> { @ftp.status }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 501" do
+ @server.should_receive(:stat).and_respond("501 Syntax error in parameters or arguments.")
+ -> { @ftp.status }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 502" do
+ @server.should_receive(:stat).and_respond("502 Command not implemented.")
+ -> { @ftp.status }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPTempError when the response code is 421" do
+ @server.should_receive(:stat).and_respond("421 Service not available, closing control connection.")
+ -> { @ftp.status }.should.raise(Net::FTPTempError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 530" do
+ @server.should_receive(:stat).and_respond("530 Requested action not taken.")
+ -> { @ftp.status }.should.raise(Net::FTPPermError)
+ end
+ end
+end
diff --git a/spec/ruby/library/net-ftp/storbinary_spec.rb b/spec/ruby/library/net-ftp/storbinary_spec.rb
new file mode 100644
index 0000000000..a2f81fc669
--- /dev/null
+++ b/spec/ruby/library/net-ftp/storbinary_spec.rb
@@ -0,0 +1,52 @@
+require_relative '../../spec_helper'
+
+ruby_version_is ""..."4.1" do
+
+ require_relative 'spec_helper'
+ require_relative 'fixtures/server'
+
+ describe "Net::FTP#storbinary" do
+ before :each do
+ @server = NetFTPSpecs::DummyFTP.new
+ @server.serve_once
+
+ @local_fixture_file = __dir__ + "/fixtures/putbinaryfile"
+ @tmp_file = tmp("binaryfile", false)
+
+ @ftp = Net::FTP.new
+ @ftp.connect(@server.hostname, @server.server_port)
+ end
+
+ after :each do
+ @ftp.quit rescue nil
+ @ftp.close
+ @server.stop
+
+ rm_r @tmp_file
+ end
+
+ it "sends the passed command and the passed File object's content to the server" do
+ File.open(@local_fixture_file) do |f|
+ f.binmode
+
+ @ftp.storbinary("STOR binary", f, 4096) {}
+ @ftp.last_response.should == "200 OK, Data received. (STOR binary)\n"
+ end
+ end
+
+ it "yields the transmitted content as binary blocks of the passed size" do
+ File.open(@local_fixture_file) do |f|
+ f.binmode
+
+ res = []
+ @ftp.storbinary("STOR binary", f, 10) { |x| res << x }
+ res.should == [
+ "This is an", " example f",
+ "ile\nwhich ", "is going t",
+ "o be trans", "mitted\nusi",
+ "ng #putbin", "aryfile.\n"
+ ]
+ end
+ end
+ end
+end
diff --git a/spec/ruby/library/net-ftp/storlines_spec.rb b/spec/ruby/library/net-ftp/storlines_spec.rb
new file mode 100644
index 0000000000..09340bafe9
--- /dev/null
+++ b/spec/ruby/library/net-ftp/storlines_spec.rb
@@ -0,0 +1,47 @@
+require_relative '../../spec_helper'
+
+ruby_version_is ""..."4.1" do
+
+ require_relative 'spec_helper'
+ require_relative 'fixtures/server'
+
+ describe "Net::FTP#storlines" do
+ before :each do
+ @server = NetFTPSpecs::DummyFTP.new
+ @server.serve_once
+
+ @local_fixture_file = __dir__ + "/fixtures/puttextfile"
+ @tmp_file = tmp("textfile", false)
+
+ @ftp = Net::FTP.new
+ @ftp.connect(@server.hostname, @server.server_port)
+ end
+
+ after :each do
+ @ftp.quit rescue nil
+ @ftp.close
+ @server.stop
+
+ rm_r @tmp_file
+ end
+
+ it "sends the passed command and the passed File object's content to the server" do
+ File.open(@local_fixture_file) do |f|
+ @ftp.storlines("STOR text", f) {}
+ @ftp.last_response.should == "200 OK, Data received. (STOR text)\n"
+ end
+ end
+
+ it "yields each line of the transmitted content" do
+ File.open(@local_fixture_file) do |f|
+ res = []
+ @ftp.storlines("STOR text", f) { |x| res << x }
+ res.should == [
+ "This is an example file\r\n",
+ "which is going to be transmitted\r\n",
+ "using #puttextfile.\r\n"
+ ]
+ end
+ end
+ end
+end
diff --git a/spec/ruby/library/net-ftp/system_spec.rb b/spec/ruby/library/net-ftp/system_spec.rb
new file mode 100644
index 0000000000..fa61776282
--- /dev/null
+++ b/spec/ruby/library/net-ftp/system_spec.rb
@@ -0,0 +1,51 @@
+require_relative '../../spec_helper'
+
+ruby_version_is ""..."4.1" do
+ require_relative 'spec_helper'
+ require_relative 'fixtures/server'
+
+ describe "Net::FTP#system" do
+ before :each do
+ @server = NetFTPSpecs::DummyFTP.new
+ @server.serve_once
+
+ @ftp = Net::FTP.new
+ @ftp.connect(@server.hostname, @server.server_port)
+ end
+
+ after :each do
+ @ftp.quit rescue nil
+ @ftp.close
+ @server.stop
+ end
+
+ it "sends the SYST command to the server" do
+ @ftp.system
+ @ftp.last_response.should =~ /\A215 FTP Dummy Server \(SYST\)\Z/
+ end
+
+ it "returns the received information" do
+ @ftp.system.should =~ /\AFTP Dummy Server \(SYST\)\Z/
+ end
+
+ it "raises a Net::FTPPermError when the response code is 500" do
+ @server.should_receive(:syst).and_respond("500 Syntax error, command unrecognized.")
+ -> { @ftp.system }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 501" do
+ @server.should_receive(:syst).and_respond("501 Syntax error in parameters or arguments.")
+ -> { @ftp.system }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 502" do
+ @server.should_receive(:syst).and_respond("502 Command not implemented.")
+ -> { @ftp.system }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPTempError when the response code is 421" do
+ @server.should_receive(:syst).and_respond("421 Service not available, closing control connection.")
+ -> { @ftp.system }.should.raise(Net::FTPTempError)
+ end
+ end
+end
diff --git a/spec/ruby/library/net-ftp/voidcmd_spec.rb b/spec/ruby/library/net-ftp/voidcmd_spec.rb
new file mode 100644
index 0000000000..4f74da7a70
--- /dev/null
+++ b/spec/ruby/library/net-ftp/voidcmd_spec.rb
@@ -0,0 +1,57 @@
+require_relative '../../spec_helper'
+
+ruby_version_is ""..."4.1" do
+ require_relative 'spec_helper'
+ require_relative 'fixtures/server'
+
+ describe "Net::FTP#voidcmd" do
+ before :each do
+ @server = NetFTPSpecs::DummyFTP.new
+ @server.serve_once
+
+ @ftp = Net::FTP.new
+ @ftp.connect(@server.hostname, @server.server_port)
+ end
+
+ after :each do
+ @ftp.quit rescue nil
+ @ftp.close
+ @server.stop
+ end
+
+ it "sends the passed command to the server" do
+ @server.should_receive(:help).and_respond("2xx Does not raise.")
+ -> { @ftp.voidcmd("HELP") }.should_not.raise
+ end
+
+ it "returns nil" do
+ @server.should_receive(:help).and_respond("2xx Does not raise.")
+ @ftp.voidcmd("HELP").should == nil
+ end
+
+ it "raises a Net::FTPReplyError when the response code is 1xx" do
+ @server.should_receive(:help).and_respond("1xx Does raise a Net::FTPReplyError.")
+ -> { @ftp.voidcmd("HELP") }.should.raise(Net::FTPReplyError)
+ end
+
+ it "raises a Net::FTPReplyError when the response code is 3xx" do
+ @server.should_receive(:help).and_respond("3xx Does raise a Net::FTPReplyError.")
+ -> { @ftp.voidcmd("HELP") }.should.raise(Net::FTPReplyError)
+ end
+
+ it "raises a Net::FTPTempError when the response code is 4xx" do
+ @server.should_receive(:help).and_respond("4xx Does raise a Net::FTPTempError.")
+ -> { @ftp.voidcmd("HELP") }.should.raise(Net::FTPTempError)
+ end
+
+ it "raises a Net::FTPPermError when the response code is 5xx" do
+ @server.should_receive(:help).and_respond("5xx Does raise a Net::FTPPermError.")
+ -> { @ftp.voidcmd("HELP") }.should.raise(Net::FTPPermError)
+ end
+
+ it "raises a Net::FTPProtoError when the response code is not valid" do
+ @server.should_receive(:help).and_respond("999 Does raise a Net::FTPProtoError.")
+ -> { @ftp.voidcmd("HELP") }.should.raise(Net::FTPProtoError)
+ end
+ end
+end
diff --git a/spec/ruby/library/net-ftp/welcome_spec.rb b/spec/ruby/library/net-ftp/welcome_spec.rb
new file mode 100644
index 0000000000..761a0f9a3e
--- /dev/null
+++ b/spec/ruby/library/net-ftp/welcome_spec.rb
@@ -0,0 +1,28 @@
+require_relative '../../spec_helper'
+
+ruby_version_is ""..."4.1" do
+ require_relative 'spec_helper'
+ require_relative 'fixtures/server'
+
+ describe "Net::FTP#welcome" do
+ before :each do
+ @server = NetFTPSpecs::DummyFTP.new
+ @server.serve_once
+
+ @ftp = Net::FTP.new
+ @ftp.connect(@server.hostname, @server.server_port)
+ end
+
+ after :each do
+ @ftp.quit rescue nil
+ @ftp.close
+ @server.stop
+ end
+
+ it "returns the server's welcome message" do
+ @ftp.welcome.should == nil
+ @ftp.login
+ @ftp.welcome.should == "230 User logged in, proceed. (USER anonymous)\n"
+ end
+ end
+end
diff --git a/spec/ruby/library/net-http/HTTPBadResponse_spec.rb b/spec/ruby/library/net-http/HTTPBadResponse_spec.rb
new file mode 100644
index 0000000000..8f2e8ccfaf
--- /dev/null
+++ b/spec/ruby/library/net-http/HTTPBadResponse_spec.rb
@@ -0,0 +1,8 @@
+require_relative '../../spec_helper'
+require 'net/http'
+
+describe "Net::HTTPBadResponse" do
+ it "is a subclass of StandardError" do
+ Net::HTTPBadResponse.should < StandardError
+ end
+end
diff --git a/spec/ruby/library/net-http/HTTPClientExcepton_spec.rb b/spec/ruby/library/net-http/HTTPClientExcepton_spec.rb
new file mode 100644
index 0000000000..2992e6596f
--- /dev/null
+++ b/spec/ruby/library/net-http/HTTPClientExcepton_spec.rb
@@ -0,0 +1,12 @@
+require_relative '../../spec_helper'
+require 'net/http'
+
+describe "Net::HTTPClientException" do
+ it "is a subclass of Net::ProtoServerError" do
+ Net::HTTPClientException.should < Net::ProtoServerError
+ end
+
+ it "includes the Net::HTTPExceptions module" do
+ Net::HTTPClientException.should < Net::HTTPExceptions
+ end
+end
diff --git a/spec/ruby/library/net-http/HTTPError_spec.rb b/spec/ruby/library/net-http/HTTPError_spec.rb
new file mode 100644
index 0000000000..7f79eef8cf
--- /dev/null
+++ b/spec/ruby/library/net-http/HTTPError_spec.rb
@@ -0,0 +1,12 @@
+require_relative '../../spec_helper'
+require 'net/http'
+
+describe "Net::HTTPError" do
+ it "is a subclass of Net::ProtocolError" do
+ Net::HTTPError.should < Net::ProtocolError
+ end
+
+ it "includes the Net::HTTPExceptions module" do
+ Net::HTTPError.should < Net::HTTPExceptions
+ end
+end
diff --git a/spec/ruby/library/net-http/HTTPFatalError_spec.rb b/spec/ruby/library/net-http/HTTPFatalError_spec.rb
new file mode 100644
index 0000000000..0113b9da2d
--- /dev/null
+++ b/spec/ruby/library/net-http/HTTPFatalError_spec.rb
@@ -0,0 +1,12 @@
+require_relative '../../spec_helper'
+require 'net/http'
+
+describe "Net::HTTPFatalError" do
+ it "is a subclass of Net::ProtoFatalError" do
+ Net::HTTPFatalError.should < Net::ProtoFatalError
+ end
+
+ it "includes the Net::HTTPExceptions module" do
+ Net::HTTPFatalError.should < Net::HTTPExceptions
+ end
+end
diff --git a/spec/ruby/library/net-http/HTTPHeaderSyntaxError_spec.rb b/spec/ruby/library/net-http/HTTPHeaderSyntaxError_spec.rb
new file mode 100644
index 0000000000..b3b73ff46f
--- /dev/null
+++ b/spec/ruby/library/net-http/HTTPHeaderSyntaxError_spec.rb
@@ -0,0 +1,8 @@
+require_relative '../../spec_helper'
+require 'net/http'
+
+describe "Net::HTTPHeaderSyntaxError" do
+ it "is a subclass of StandardError" do
+ Net::HTTPHeaderSyntaxError.should < StandardError
+ end
+end
diff --git a/spec/ruby/library/net-http/HTTPRetriableError_spec.rb b/spec/ruby/library/net-http/HTTPRetriableError_spec.rb
new file mode 100644
index 0000000000..677731fb68
--- /dev/null
+++ b/spec/ruby/library/net-http/HTTPRetriableError_spec.rb
@@ -0,0 +1,12 @@
+require_relative '../../spec_helper'
+require 'net/http'
+
+describe "Net::HTTPRetriableError" do
+ it "is a subclass of Net::ProtoRetriableError" do
+ Net::HTTPRetriableError.should < Net::ProtoRetriableError
+ end
+
+ it "includes the Net::HTTPExceptions module" do
+ Net::HTTPRetriableError.should < Net::HTTPExceptions
+ end
+end
diff --git a/spec/ruby/library/net-http/HTTPServerException_spec.rb b/spec/ruby/library/net-http/HTTPServerException_spec.rb
new file mode 100644
index 0000000000..020d3cce85
--- /dev/null
+++ b/spec/ruby/library/net-http/HTTPServerException_spec.rb
@@ -0,0 +1,12 @@
+require_relative '../../spec_helper'
+require 'net/http'
+
+describe "Net::HTTPServerException" do
+ it "is a subclass of Net::ProtoServerError and is warned as deprecated" do
+ -> { eval("Net::HTTPServerException").should < Net::ProtoServerError }.should complain(/warning: constant Net::HTTPServerException is deprecated/)
+ end
+
+ it "includes the Net::HTTPExceptions module and is warned as deprecated" do
+ -> { eval("Net::HTTPServerException").should < Net::HTTPExceptions }.should complain(/warning: constant Net::HTTPServerException is deprecated/)
+ end
+end
diff --git a/spec/ruby/library/net-http/http/Proxy_spec.rb b/spec/ruby/library/net-http/http/Proxy_spec.rb
new file mode 100644
index 0000000000..7753ce5e30
--- /dev/null
+++ b/spec/ruby/library/net-http/http/Proxy_spec.rb
@@ -0,0 +1,35 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+
+describe "Net::HTTP.Proxy" do
+ it "returns a new subclass of Net::HTTP" do
+ Net::HTTP.Proxy("localhost").should < Net::HTTP
+ end
+
+ it "returns Net::HTTP when the passed address is nil" do
+ Net::HTTP.Proxy(nil).should == Net::HTTP
+ end
+
+ it "sets the returned subclasses' proxy options based on the passed arguments" do
+ http_with_proxy = Net::HTTP.Proxy("localhost", 1234, "rspec", "rocks")
+ http_with_proxy.proxy_address.should == "localhost"
+ http_with_proxy.proxy_port.should.eql?(1234)
+ http_with_proxy.proxy_user.should == "rspec"
+ http_with_proxy.proxy_pass.should == "rocks"
+ end
+end
+
+describe "Net::HTTP#proxy?" do
+ describe "when self is no proxy class instance" do
+ it "returns false" do
+ Net::HTTP.new("localhost", 3333).proxy?.should == false
+ end
+ end
+
+ describe "when self is a proxy class instance" do
+ it "returns false" do
+ http_with_proxy = Net::HTTP.Proxy("localhost", 1234, "rspec", "rocks")
+ http_with_proxy.new("localhost", 3333).proxy?.should == true
+ end
+ end
+end
diff --git a/spec/ruby/library/net-http/http/active_spec.rb b/spec/ruby/library/net-http/http/active_spec.rb
new file mode 100644
index 0000000000..ba870b39d2
--- /dev/null
+++ b/spec/ruby/library/net-http/http/active_spec.rb
@@ -0,0 +1,8 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+
+describe "Net::HTTP#active?" do
+ it "is an alias of Net::HTTP#started?" do
+ Net::HTTP.instance_method(:active?).should == Net::HTTP.instance_method(:started?)
+ end
+end
diff --git a/spec/ruby/library/net-http/http/address_spec.rb b/spec/ruby/library/net-http/http/address_spec.rb
new file mode 100644
index 0000000000..7c5b82a8f9
--- /dev/null
+++ b/spec/ruby/library/net-http/http/address_spec.rb
@@ -0,0 +1,9 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+
+describe "Net::HTTP#address" do
+ it "returns the current host name" do
+ net = Net::HTTP.new("localhost")
+ net.address.should == "localhost"
+ end
+end
diff --git a/spec/ruby/library/net-http/http/close_on_empty_response_spec.rb b/spec/ruby/library/net-http/http/close_on_empty_response_spec.rb
new file mode 100644
index 0000000000..9cc756befb
--- /dev/null
+++ b/spec/ruby/library/net-http/http/close_on_empty_response_spec.rb
@@ -0,0 +1,10 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+
+describe "Net::HTTP#close_on_empty_response" do
+ it "needs to be reviewed for spec completeness"
+end
+
+describe "Net::HTTP#close_on_empty_response=" do
+ it "needs to be reviewed for spec completeness"
+end
diff --git a/spec/ruby/library/net-http/http/copy_spec.rb b/spec/ruby/library/net-http/http/copy_spec.rb
new file mode 100644
index 0000000000..1f3e25009f
--- /dev/null
+++ b/spec/ruby/library/net-http/http/copy_spec.rb
@@ -0,0 +1,21 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+require_relative 'fixtures/http_server'
+
+describe "Net::HTTP#copy" do
+ before :each do
+ NetHTTPSpecs.start_server
+ @http = Net::HTTP.start("localhost", NetHTTPSpecs.port)
+ end
+
+ after :each do
+ @http.finish if @http.started?
+ NetHTTPSpecs.stop_server
+ end
+
+ it "sends a COPY request to the passed path and returns the response" do
+ response = @http.copy("/request")
+ response.should.is_a?(Net::HTTPResponse)
+ response.body.should == "Request type: COPY"
+ end
+end
diff --git a/spec/ruby/library/net-http/http/default_port_spec.rb b/spec/ruby/library/net-http/http/default_port_spec.rb
new file mode 100644
index 0000000000..20407d0b12
--- /dev/null
+++ b/spec/ruby/library/net-http/http/default_port_spec.rb
@@ -0,0 +1,8 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+
+describe "Net::HTTP.default_port" do
+ it "returns 80" do
+ Net::HTTP.http_default_port.should.eql?(80)
+ end
+end
diff --git a/spec/ruby/library/net-http/http/delete_spec.rb b/spec/ruby/library/net-http/http/delete_spec.rb
new file mode 100644
index 0000000000..09ddd74000
--- /dev/null
+++ b/spec/ruby/library/net-http/http/delete_spec.rb
@@ -0,0 +1,21 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+require_relative 'fixtures/http_server'
+
+describe "Net::HTTP#delete" do
+ before :each do
+ NetHTTPSpecs.start_server
+ @http = Net::HTTP.start("localhost", NetHTTPSpecs.port)
+ end
+
+ after :each do
+ @http.finish if @http.started?
+ NetHTTPSpecs.stop_server
+ end
+
+ it "sends a DELETE request to the passed path and returns the response" do
+ response = @http.delete("/request")
+ response.should.is_a?(Net::HTTPResponse)
+ response.body.should == "Request type: DELETE"
+ end
+end
diff --git a/spec/ruby/library/net-http/http/finish_spec.rb b/spec/ruby/library/net-http/http/finish_spec.rb
new file mode 100644
index 0000000000..0d466675f3
--- /dev/null
+++ b/spec/ruby/library/net-http/http/finish_spec.rb
@@ -0,0 +1,29 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+require_relative 'fixtures/http_server'
+
+describe "Net::HTTP#finish" do
+ before :each do
+ NetHTTPSpecs.start_server
+ @http = Net::HTTP.new("localhost", NetHTTPSpecs.port)
+ end
+
+ after :each do
+ @http.finish if @http.started?
+ NetHTTPSpecs.stop_server
+ end
+
+ describe "when self has been started" do
+ it "closes the tcp connection" do
+ @http.start
+ @http.finish
+ @http.started?.should == false
+ end
+ end
+
+ describe "when self has not been started yet" do
+ it "raises an IOError" do
+ -> { @http.finish }.should.raise(IOError)
+ end
+ end
+end
diff --git a/spec/ruby/library/net-http/http/fixtures/http_server.rb b/spec/ruby/library/net-http/http/fixtures/http_server.rb
new file mode 100644
index 0000000000..c1cedbfa76
--- /dev/null
+++ b/spec/ruby/library/net-http/http/fixtures/http_server.rb
@@ -0,0 +1,123 @@
+require 'socket'
+
+module NetHTTPSpecs
+ class NullWriter
+ def <<(s) end
+ def puts(*args) end
+ def print(*args) end
+ def printf(*args) end
+ end
+
+ class SmallHTTPServer
+ def initialize(bind_address)
+ @server = TCPServer.new(bind_address, 0)
+ @thread = Thread.new {
+ Thread.current.abort_on_exception = true
+ listen
+ }
+ end
+
+ def ip
+ @server.addr[3]
+ end
+
+ def port
+ @server.addr[1]
+ end
+
+ def listen
+ until @server.closed?
+ client = @server.accept
+ handle_client(client)
+ end
+ end
+
+ def handle_client(client)
+ begin
+ until client.closed?
+ request = client.gets("\r\n\r\n")
+ break unless request
+ if request == "CLOSE"
+ @server.close
+ break
+ end
+ handle_request(client, request)
+ end
+ ensure
+ client.close
+ end
+ end
+
+ def parse_request(request)
+ request, *headers = request.chomp.lines.map { |line| line.chomp }
+ request_method, request_uri, _http_version = request.split
+ headers = headers.map { |line| line.split(': ', 2) }.to_h
+ [request_method, request_uri, headers]
+ end
+
+ def handle_request(client, request)
+ request_method, request_uri, headers = parse_request(request)
+
+ if headers.include? 'Content-Length'
+ request_body_size = Integer(headers['Content-Length'])
+ request_body = client.read(request_body_size)
+ end
+
+ case request_uri
+ when '/'
+ raise request_method unless request_method == 'GET'
+ reply(client, "This is the index page.", request_method)
+ when '/request'
+ reply(client, "Request type: #{request_method}", request_method)
+ when '/request/body'
+ reply(client, request_body, request_method)
+ when '/request/header'
+ reply(client, headers.inspect, request_method)
+ when '/request/basic_auth'
+ reply(client, "username: \npassword: ", request_method)
+ else
+ raise request_uri
+ end
+ end
+
+ def reply(client, body, request_method)
+ client.print "HTTP/1.1 200 OK\r\n"
+ if request_method == 'HEAD'
+ client.close
+ else
+ client.print "Content-Type: text/plain\r\n"
+ client.print "Content-Length: #{body.bytesize}\r\n"
+ client.print "\r\n"
+ client.print body
+ end
+ end
+
+ def close
+ TCPSocket.open(ip, port) do |socket|
+ socket.write "CLOSE"
+ end
+ @thread.join
+ end
+ end
+
+ @server = nil
+
+ class << self
+ def port
+ raise "server not started" unless @server
+ @server.port
+ end
+
+ def start_server
+ bind_address = platform_is(:windows) ? "localhost" : "127.0.0.1"
+ @server = SmallHTTPServer.new(bind_address)
+ end
+
+ def stop_server
+ if @server
+ @server.close
+ @server = nil
+ end
+ end
+ end
+end
diff --git a/spec/ruby/library/net-http/http/get2_spec.rb b/spec/ruby/library/net-http/http/get2_spec.rb
new file mode 100644
index 0000000000..046443d73e
--- /dev/null
+++ b/spec/ruby/library/net-http/http/get2_spec.rb
@@ -0,0 +1,8 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+
+describe "Net::HTTP#get2" do
+ it "is an alias of Net::HTTP#request_get" do
+ Net::HTTP.instance_method(:get2).should == Net::HTTP.instance_method(:request_get)
+ end
+end
diff --git a/spec/ruby/library/net-http/http/get_print_spec.rb b/spec/ruby/library/net-http/http/get_print_spec.rb
new file mode 100644
index 0000000000..3c24ce44ea
--- /dev/null
+++ b/spec/ruby/library/net-http/http/get_print_spec.rb
@@ -0,0 +1,30 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+require_relative 'fixtures/http_server'
+
+describe "Net::HTTP.get_print" do
+ before :each do
+ NetHTTPSpecs.start_server
+ @port = NetHTTPSpecs.port
+ end
+
+ after :each do
+ NetHTTPSpecs.stop_server
+ end
+
+ describe "when passed URI" do
+ it "it prints the body of the specified uri to $stdout" do
+ -> do
+ Net::HTTP.get_print URI.parse("http://localhost:#{@port}/")
+ end.should output(/This is the index page\./)
+ end
+ end
+
+ describe "when passed host, path, port" do
+ it "it prints the body of the specified uri to $stdout" do
+ -> do
+ Net::HTTP.get_print 'localhost', "/", @port
+ end.should output(/This is the index page\./)
+ end
+ end
+end
diff --git a/spec/ruby/library/net-http/http/get_response_spec.rb b/spec/ruby/library/net-http/http/get_response_spec.rb
new file mode 100644
index 0000000000..7133ef8101
--- /dev/null
+++ b/spec/ruby/library/net-http/http/get_response_spec.rb
@@ -0,0 +1,30 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+require_relative 'fixtures/http_server'
+
+describe "Net::HTTP.get_response" do
+ before :each do
+ NetHTTPSpecs.start_server
+ @port = NetHTTPSpecs.port
+ end
+
+ after :each do
+ NetHTTPSpecs.stop_server
+ end
+
+ describe "when passed URI" do
+ it "returns the response for the specified uri" do
+ res = Net::HTTP.get_response(URI.parse("http://localhost:#{@port}/"))
+ res.content_type.should == "text/plain"
+ res.body.should == "This is the index page."
+ end
+ end
+
+ describe "when passed host, path, port" do
+ it "returns the response for the specified host-path-combination" do
+ res = Net::HTTP.get_response('localhost', "/", @port)
+ res.content_type.should == "text/plain"
+ res.body.should == "This is the index page."
+ end
+ end
+end
diff --git a/spec/ruby/library/net-http/http/get_spec.rb b/spec/ruby/library/net-http/http/get_spec.rb
new file mode 100644
index 0000000000..9be726dc3b
--- /dev/null
+++ b/spec/ruby/library/net-http/http/get_spec.rb
@@ -0,0 +1,94 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+require_relative 'fixtures/http_server'
+
+describe "Net::HTTP.get" do
+ before :each do
+ NetHTTPSpecs.start_server
+ @port = NetHTTPSpecs.port
+ end
+
+ after :each do
+ NetHTTPSpecs.stop_server
+ end
+
+ describe "when passed URI" do
+ it "returns the body of the specified uri" do
+ Net::HTTP.get(URI.parse("http://localhost:#{@port}/")).should == "This is the index page."
+ end
+ end
+
+ describe "when passed host, path, port" do
+ it "returns the body of the specified host-path-combination" do
+ Net::HTTP.get('localhost', "/", @port).should == "This is the index page."
+ end
+ end
+end
+
+quarantine! do # These specs fail frequently with CHECK_LEAKS=true
+describe "Net::HTTP.get" do
+ describe "when reading gzipped contents" do
+ def start_threads
+ require 'zlib'
+ require 'stringio'
+
+ server = nil
+ server_thread = Thread.new do
+ server = TCPServer.new("127.0.0.1", 0)
+ begin
+ c = server.accept
+ ensure
+ server.close
+ end
+ c.print "HTTP/1.1 200\r\n"
+ c.print "Content-Type: text/plain\r\n"
+ c.print "Content-Encoding: gzip\r\n"
+ s = StringIO.new
+ z = Zlib::GzipWriter.new(s)
+ begin
+ z.write 'Hello World!'
+ ensure
+ z.close
+ end
+ c.print "Content-Length: #{s.length}\r\n\r\n"
+ # Write partial gzip content
+ c.write s.string.byteslice(0..-2)
+ c.flush
+ c
+ end
+ Thread.pass until server && server_thread.stop?
+
+ client_thread = Thread.new do
+ Thread.current.report_on_exception = false
+ Net::HTTP.get("127.0.0.1", '/', server.connect_address.ip_port)
+ end
+
+ socket = server_thread.value
+ Thread.pass until client_thread.stop?
+
+ [socket, client_thread]
+ end
+
+ it "propagates exceptions interrupting the thread and does not replace it with Zlib::BufError" do
+ my_exception = Class.new(RuntimeError)
+ socket, client_thread = start_threads
+ begin
+ client_thread.raise my_exception, "my exception"
+ -> { client_thread.value }.should.raise(my_exception)
+ ensure
+ socket.close
+ end
+ end
+
+ it "lets the kill Thread exception goes through and does not replace it with Zlib::BufError" do
+ socket, client_thread = start_threads
+ begin
+ client_thread.kill
+ client_thread.value.should == nil
+ ensure
+ socket.close
+ end
+ end
+ end
+end
+end
diff --git a/spec/ruby/library/net-http/http/head2_spec.rb b/spec/ruby/library/net-http/http/head2_spec.rb
new file mode 100644
index 0000000000..19c0cede9f
--- /dev/null
+++ b/spec/ruby/library/net-http/http/head2_spec.rb
@@ -0,0 +1,8 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+
+describe "Net::HTTP#head2" do
+ it "is an alias of Net::HTTP#request_head" do
+ Net::HTTP.instance_method(:head2).should == Net::HTTP.instance_method(:request_head)
+ end
+end
diff --git a/spec/ruby/library/net-http/http/head_spec.rb b/spec/ruby/library/net-http/http/head_spec.rb
new file mode 100644
index 0000000000..4824d22534
--- /dev/null
+++ b/spec/ruby/library/net-http/http/head_spec.rb
@@ -0,0 +1,25 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+require_relative 'fixtures/http_server'
+
+describe "Net::HTTP#head" do
+ before :each do
+ NetHTTPSpecs.start_server
+ @http = Net::HTTP.start("localhost", NetHTTPSpecs.port)
+ end
+
+ after :each do
+ @http.finish if @http.started?
+ NetHTTPSpecs.stop_server
+ end
+
+ it "sends a HEAD request to the passed path and returns the response" do
+ response = @http.head("/request")
+ # HEAD requests have no responses
+ response.body.should == nil
+ end
+
+ it "returns a Net::HTTPResponse" do
+ @http.head("/request").should.is_a?(Net::HTTPResponse)
+ end
+end
diff --git a/spec/ruby/library/net-http/http/http_default_port_spec.rb b/spec/ruby/library/net-http/http/http_default_port_spec.rb
new file mode 100644
index 0000000000..82c88e58a8
--- /dev/null
+++ b/spec/ruby/library/net-http/http/http_default_port_spec.rb
@@ -0,0 +1,8 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+
+describe "Net::HTTP.http_default_port" do
+ it "returns 80" do
+ Net::HTTP.http_default_port.should.eql?(80)
+ end
+end
diff --git a/spec/ruby/library/net-http/http/https_default_port_spec.rb b/spec/ruby/library/net-http/http/https_default_port_spec.rb
new file mode 100644
index 0000000000..24b9c3b462
--- /dev/null
+++ b/spec/ruby/library/net-http/http/https_default_port_spec.rb
@@ -0,0 +1,8 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+
+describe "Net::HTTP.https_default_port" do
+ it "returns 443" do
+ Net::HTTP.https_default_port.should.eql?(443)
+ end
+end
diff --git a/spec/ruby/library/net-http/http/initialize_spec.rb b/spec/ruby/library/net-http/http/initialize_spec.rb
new file mode 100644
index 0000000000..907314cb25
--- /dev/null
+++ b/spec/ruby/library/net-http/http/initialize_spec.rb
@@ -0,0 +1,46 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+
+describe "Net::HTTP#initialize" do
+ it "is private" do
+ Net::HTTP.private_instance_methods(false).should.include?(:initialize)
+ end
+
+ describe "when passed address" do
+ before :each do
+ @net = Net::HTTP.allocate
+ @net.send(:initialize, "localhost")
+ end
+
+ it "sets the new Net::HTTP instance's address to the passed address" do
+ @net.address.should == "localhost"
+ end
+
+ it "sets the new Net::HTTP instance's port to the default HTTP port" do
+ @net.port.should.eql?(Net::HTTP.default_port)
+ end
+
+ it "does not start the new Net::HTTP instance" do
+ @net.started?.should == false
+ end
+ end
+
+ describe "when passed address, port" do
+ before :each do
+ @net = Net::HTTP.allocate
+ @net.send(:initialize, "localhost", 3333)
+ end
+
+ it "sets the new Net::HTTP instance's address to the passed address" do
+ @net.address.should == "localhost"
+ end
+
+ it "sets the new Net::HTTP instance's port to the passed port" do
+ @net.port.should.eql?(3333)
+ end
+
+ it "does not start the new Net::HTTP instance" do
+ @net.started?.should == false
+ end
+ end
+end
diff --git a/spec/ruby/library/net-http/http/inspect_spec.rb b/spec/ruby/library/net-http/http/inspect_spec.rb
new file mode 100644
index 0000000000..fd4e6116c7
--- /dev/null
+++ b/spec/ruby/library/net-http/http/inspect_spec.rb
@@ -0,0 +1,24 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+require_relative 'fixtures/http_server'
+
+describe "Net::HTTP#inspect" do
+ before :each do
+ NetHTTPSpecs.start_server
+ @port = NetHTTPSpecs.port
+ @http = Net::HTTP.new("localhost", @port)
+ end
+
+ after :each do
+ @http.finish if @http.started?
+ NetHTTPSpecs.stop_server
+ end
+
+ it "returns a String representation of self" do
+ @http.inspect.should.is_a?(String)
+ @http.inspect.should == "#<Net::HTTP localhost:#{@port} open=false>"
+
+ @http.start
+ @http.inspect.should == "#<Net::HTTP localhost:#{@port} open=true>"
+ end
+end
diff --git a/spec/ruby/library/net-http/http/is_version_1_1_spec.rb b/spec/ruby/library/net-http/http/is_version_1_1_spec.rb
new file mode 100644
index 0000000000..f4910ef1e4
--- /dev/null
+++ b/spec/ruby/library/net-http/http/is_version_1_1_spec.rb
@@ -0,0 +1,8 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+
+describe "Net::HTTP.is_version_1_1?" do
+ it "is an alias of Net::HTTP.version_1_1?" do
+ Net::HTTP.method(:is_version_1_1?).should == Net::HTTP.method(:version_1_1?)
+ end
+end
diff --git a/spec/ruby/library/net-http/http/is_version_1_2_spec.rb b/spec/ruby/library/net-http/http/is_version_1_2_spec.rb
new file mode 100644
index 0000000000..555724babe
--- /dev/null
+++ b/spec/ruby/library/net-http/http/is_version_1_2_spec.rb
@@ -0,0 +1,8 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+
+describe "Net::HTTP.is_version_1_2?" do
+ it "is an alias of Net::HTTP.version_1_2?" do
+ Net::HTTP.method(:is_version_1_2?).should == Net::HTTP.method(:version_1_2?)
+ end
+end
diff --git a/spec/ruby/library/net-http/http/lock_spec.rb b/spec/ruby/library/net-http/http/lock_spec.rb
new file mode 100644
index 0000000000..12df138ad0
--- /dev/null
+++ b/spec/ruby/library/net-http/http/lock_spec.rb
@@ -0,0 +1,21 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+require_relative 'fixtures/http_server'
+
+describe "Net::HTTP#lock" do
+ before :each do
+ NetHTTPSpecs.start_server
+ @http = Net::HTTP.start("localhost", NetHTTPSpecs.port)
+ end
+
+ after :each do
+ @http.finish if @http.started?
+ NetHTTPSpecs.stop_server
+ end
+
+ it "sends a LOCK request to the passed path and returns the response" do
+ response = @http.lock("/request", "test=test")
+ response.should.is_a?(Net::HTTPResponse)
+ response.body.should == "Request type: LOCK"
+ end
+end
diff --git a/spec/ruby/library/net-http/http/mkcol_spec.rb b/spec/ruby/library/net-http/http/mkcol_spec.rb
new file mode 100644
index 0000000000..b1a5055982
--- /dev/null
+++ b/spec/ruby/library/net-http/http/mkcol_spec.rb
@@ -0,0 +1,21 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+require_relative 'fixtures/http_server'
+
+describe "Net::HTTP#mkcol" do
+ before :each do
+ NetHTTPSpecs.start_server
+ @http = Net::HTTP.start("localhost", NetHTTPSpecs.port)
+ end
+
+ after :each do
+ @http.finish if @http.started?
+ NetHTTPSpecs.stop_server
+ end
+
+ it "sends a MKCOL request to the passed path and returns the response" do
+ response = @http.mkcol("/request")
+ response.should.is_a?(Net::HTTPResponse)
+ response.body.should == "Request type: MKCOL"
+ end
+end
diff --git a/spec/ruby/library/net-http/http/move_spec.rb b/spec/ruby/library/net-http/http/move_spec.rb
new file mode 100644
index 0000000000..a57c2a0f49
--- /dev/null
+++ b/spec/ruby/library/net-http/http/move_spec.rb
@@ -0,0 +1,25 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+require_relative 'fixtures/http_server'
+
+describe "Net::HTTP#head" do
+ before :each do
+ NetHTTPSpecs.start_server
+ @http = Net::HTTP.start("localhost", NetHTTPSpecs.port)
+ end
+
+ after :each do
+ @http.finish if @http.started?
+ NetHTTPSpecs.stop_server
+ end
+
+ it "sends a MOVE request to the passed path and returns the response" do
+ response = @http.move("/request")
+ # HEAD requests have no responses
+ response.body.should == "Request type: MOVE"
+ end
+
+ it "returns a Net::HTTPResponse" do
+ @http.move("/request").should.is_a?(Net::HTTPResponse)
+ end
+end
diff --git a/spec/ruby/library/net-http/http/new_spec.rb b/spec/ruby/library/net-http/http/new_spec.rb
new file mode 100644
index 0000000000..8feb3d1351
--- /dev/null
+++ b/spec/ruby/library/net-http/http/new_spec.rb
@@ -0,0 +1,86 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+
+describe "Net::HTTP.new" do
+ describe "when passed address" do
+ before :each do
+ @http = Net::HTTP.new("localhost")
+ end
+
+ it "returns a Net::HTTP instance" do
+ @http.proxy?.should == false
+ @http.instance_of?(Net::HTTP).should == true
+ end
+
+ it "sets the new Net::HTTP instance's address to the passed address" do
+ @http.address.should == "localhost"
+ end
+
+ it "sets the new Net::HTTP instance's port to the default HTTP port" do
+ @http.port.should.eql?(Net::HTTP.default_port)
+ end
+
+ it "does not start the new Net::HTTP instance" do
+ @http.started?.should == false
+ end
+ end
+
+ describe "when passed address, port" do
+ before :each do
+ @http = Net::HTTP.new("localhost", 3333)
+ end
+
+ it "returns a Net::HTTP instance" do
+ @http.proxy?.should == false
+ @http.instance_of?(Net::HTTP).should == true
+ end
+
+ it "sets the new Net::HTTP instance's address to the passed address" do
+ @http.address.should == "localhost"
+ end
+
+ it "sets the new Net::HTTP instance's port to the passed port" do
+ @http.port.should.eql?(3333)
+ end
+
+ it "does not start the new Net::HTTP instance" do
+ @http.started?.should == false
+ end
+ end
+
+ describe "when passed address, port, *proxy_options" do
+ it "returns a Net::HTTP instance" do
+ http = Net::HTTP.new("localhost", 3333, "localhost")
+ http.proxy?.should == true
+ http.instance_of?(Net::HTTP).should == true
+ http.should.is_a?(Net::HTTP)
+ end
+
+ it "correctly sets the passed Proxy options" do
+ http = Net::HTTP.new("localhost", 3333, "localhost")
+ http.proxy_address.should == "localhost"
+ http.proxy_port.should.eql?(80)
+ http.proxy_user.should == nil
+ http.proxy_pass.should == nil
+
+ http = Net::HTTP.new("localhost", 3333, "localhost", 1234)
+ http.proxy_address.should == "localhost"
+ http.proxy_port.should.eql?(1234)
+ http.proxy_user.should == nil
+ http.proxy_pass.should == nil
+
+ http = Net::HTTP.new("localhost", 3333, "localhost", 1234, "rubyspec")
+ http.proxy_address.should == "localhost"
+ http.proxy_port.should.eql?(1234)
+ http.proxy_user.should == "rubyspec"
+ http.proxy_pass.should == nil
+
+ http = Net::HTTP.new("localhost", 3333, "localhost", 1234, "rubyspec", "rocks")
+ http.proxy_address.should == "localhost"
+ http.proxy_port.should.eql?(1234)
+ http.proxy_user.should == "rubyspec"
+ http.proxy_pass.should == "rocks"
+ end
+ end
+
+end
diff --git a/spec/ruby/library/net-http/http/newobj_spec.rb b/spec/ruby/library/net-http/http/newobj_spec.rb
new file mode 100644
index 0000000000..d398fb7d9a
--- /dev/null
+++ b/spec/ruby/library/net-http/http/newobj_spec.rb
@@ -0,0 +1,48 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+
+describe "Net::HTTP.newobj" do
+ before :each do
+ @net = Net::HTTP.newobj("localhost")
+ end
+
+ describe "when passed address" do
+ it "returns a new Net::HTTP instance" do
+ @net.should.is_a?(Net::HTTP)
+ end
+
+ it "sets the new Net::HTTP instance's address to the passed address" do
+ @net.address.should == "localhost"
+ end
+
+ it "sets the new Net::HTTP instance's port to the default HTTP port" do
+ @net.port.should.eql?(Net::HTTP.default_port)
+ end
+
+ it "does not start the new Net::HTTP instance" do
+ @net.started?.should == false
+ end
+ end
+
+ describe "when passed address, port" do
+ before :each do
+ @net = Net::HTTP.newobj("localhost", 3333)
+ end
+
+ it "returns a new Net::HTTP instance" do
+ @net.should.is_a?(Net::HTTP)
+ end
+
+ it "sets the new Net::HTTP instance's address to the passed address" do
+ @net.address.should == "localhost"
+ end
+
+ it "sets the new Net::HTTP instance's port to the passed port" do
+ @net.port.should.eql?(3333)
+ end
+
+ it "does not start the new Net::HTTP instance" do
+ @net.started?.should == false
+ end
+ end
+end
diff --git a/spec/ruby/library/net-http/http/open_timeout_spec.rb b/spec/ruby/library/net-http/http/open_timeout_spec.rb
new file mode 100644
index 0000000000..d00f844b38
--- /dev/null
+++ b/spec/ruby/library/net-http/http/open_timeout_spec.rb
@@ -0,0 +1,24 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+
+describe "Net::HTTP#open_timeout" do
+ it "returns the seconds to wait till the connection is open" do
+ net = Net::HTTP.new("localhost")
+ net.open_timeout.should.eql?(60)
+ net.open_timeout = 10
+ net.open_timeout.should.eql?(10)
+ end
+end
+
+describe "Net::HTTP#open_timeout=" do
+ it "sets the seconds to wait till the connection is open" do
+ net = Net::HTTP.new("localhost")
+ net.open_timeout = 10
+ net.open_timeout.should.eql?(10)
+ end
+
+ it "returns the newly set value" do
+ net = Net::HTTP.new("localhost")
+ (net.open_timeout = 10).should.eql?(10)
+ end
+end
diff --git a/spec/ruby/library/net-http/http/options_spec.rb b/spec/ruby/library/net-http/http/options_spec.rb
new file mode 100644
index 0000000000..3b90573cfa
--- /dev/null
+++ b/spec/ruby/library/net-http/http/options_spec.rb
@@ -0,0 +1,25 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+require_relative 'fixtures/http_server'
+
+describe "Net::HTTP#options" do
+ before :each do
+ NetHTTPSpecs.start_server
+ @http = Net::HTTP.start("localhost", NetHTTPSpecs.port)
+ end
+
+ after :each do
+ @http.finish if @http.started?
+ NetHTTPSpecs.stop_server
+ end
+
+ it "sends an options request to the passed path and returns the response" do
+ response = @http.options("/request")
+
+ response.body.should == "Request type: OPTIONS"
+ end
+
+ it "returns a Net::HTTPResponse" do
+ @http.options("/request").should.is_a?(Net::HTTPResponse)
+ end
+end
diff --git a/spec/ruby/library/net-http/http/port_spec.rb b/spec/ruby/library/net-http/http/port_spec.rb
new file mode 100644
index 0000000000..edb689f9ca
--- /dev/null
+++ b/spec/ruby/library/net-http/http/port_spec.rb
@@ -0,0 +1,9 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+
+describe "Net::HTTP#port" do
+ it "returns the current port number" do
+ net = Net::HTTP.new("localhost", 3333)
+ net.port.should.eql?(3333)
+ end
+end
diff --git a/spec/ruby/library/net-http/http/post2_spec.rb b/spec/ruby/library/net-http/http/post2_spec.rb
new file mode 100644
index 0000000000..68c2a9ea06
--- /dev/null
+++ b/spec/ruby/library/net-http/http/post2_spec.rb
@@ -0,0 +1,8 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+
+describe "Net::HTTP#post2" do
+ it "is an alias of Net::HTTP#request_post" do
+ Net::HTTP.instance_method(:post2).should == Net::HTTP.instance_method(:request_post)
+ end
+end
diff --git a/spec/ruby/library/net-http/http/post_form_spec.rb b/spec/ruby/library/net-http/http/post_form_spec.rb
new file mode 100644
index 0000000000..de64a25bae
--- /dev/null
+++ b/spec/ruby/library/net-http/http/post_form_spec.rb
@@ -0,0 +1,22 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+require_relative 'fixtures/http_server'
+
+describe "Net::HTTP.post_form when passed URI" do
+ before :each do
+ NetHTTPSpecs.start_server
+ @port = NetHTTPSpecs.port
+ end
+
+ after :each do
+ NetHTTPSpecs.stop_server
+ end
+
+ it "POSTs the passed form data to the given uri" do
+ uri = URI.parse("http://localhost:#{@port}/request/body")
+ data = { test: :data }
+
+ res = Net::HTTP.post_form(uri, data)
+ res.body.should == "test=data"
+ end
+end
diff --git a/spec/ruby/library/net-http/http/post_spec.rb b/spec/ruby/library/net-http/http/post_spec.rb
new file mode 100644
index 0000000000..f294411197
--- /dev/null
+++ b/spec/ruby/library/net-http/http/post_spec.rb
@@ -0,0 +1,76 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+require 'uri'
+require_relative 'fixtures/http_server'
+
+describe "Net::HTTP.post" do
+ before :each do
+ NetHTTPSpecs.start_server
+ end
+
+ after :each do
+ NetHTTPSpecs.stop_server
+ end
+
+ it "sends post request to the specified URI and returns response" do
+ response = Net::HTTP.post(
+ URI("http://localhost:#{NetHTTPSpecs.port}/request"),
+ '{ "q": "ruby", "max": "50" }',
+ "Content-Type" => "application/json")
+ response.body.should == "Request type: POST"
+ end
+
+ it "returns a Net::HTTPResponse" do
+ response = Net::HTTP.post(URI("http://localhost:#{NetHTTPSpecs.port}/request"), "test=test")
+ response.should.is_a?(Net::HTTPResponse)
+ end
+
+ ruby_version_is ""..."4.0" do
+ it "sends Content-Type: application/x-www-form-urlencoded by default" do
+ response = Net::HTTP.post(URI("http://localhost:#{NetHTTPSpecs.port}/request/header"), "test=test")
+ response.body.should.include?({ "Content-Type" => "application/x-www-form-urlencoded" }.inspect.delete("{}"))
+ end
+ end
+
+ it "does not support HTTP Basic Auth" do
+ response = Net::HTTP.post(
+ URI("http://john:qwerty@localhost:#{NetHTTPSpecs.port}/request/basic_auth"),
+ "test=test")
+ response.body.should == "username: \npassword: "
+ end
+end
+
+describe "Net::HTTP#post" do
+ before :each do
+ NetHTTPSpecs.start_server
+ @http = Net::HTTP.start("localhost", NetHTTPSpecs.port)
+ end
+
+ after :each do
+ @http.finish if @http.started?
+ NetHTTPSpecs.stop_server
+ end
+
+ it "sends an post request to the passed path and returns the response" do
+ response = @http.post("/request", "test=test")
+ response.body.should == "Request type: POST"
+ end
+
+ it "returns a Net::HTTPResponse" do
+ @http.post("/request", "test=test").should.is_a?(Net::HTTPResponse)
+ end
+
+ describe "when passed a block" do
+ it "yields fragments of the response body to the passed block" do
+ str = +""
+ @http.post("/request", "test=test") do |res|
+ str << res
+ end
+ str.should == "Request type: POST"
+ end
+
+ it "returns a Net::HTTPResponse" do
+ @http.post("/request", "test=test") {}.should.is_a?(Net::HTTPResponse)
+ end
+ end
+end
diff --git a/spec/ruby/library/net-http/http/propfind_spec.rb b/spec/ruby/library/net-http/http/propfind_spec.rb
new file mode 100644
index 0000000000..6a1be0392a
--- /dev/null
+++ b/spec/ruby/library/net-http/http/propfind_spec.rb
@@ -0,0 +1,24 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+require_relative 'fixtures/http_server'
+
+describe "Net::HTTP#propfind" do
+ before :each do
+ NetHTTPSpecs.start_server
+ @http = Net::HTTP.start("localhost", NetHTTPSpecs.port)
+ end
+
+ after :each do
+ @http.finish if @http.started?
+ NetHTTPSpecs.stop_server
+ end
+
+ it "sends an propfind request to the passed path and returns the response" do
+ response = @http.propfind("/request", "test=test")
+ response.body.should == "Request type: PROPFIND"
+ end
+
+ it "returns a Net::HTTPResponse" do
+ @http.propfind("/request", "test=test").should.is_a?(Net::HTTPResponse)
+ end
+end
diff --git a/spec/ruby/library/net-http/http/proppatch_spec.rb b/spec/ruby/library/net-http/http/proppatch_spec.rb
new file mode 100644
index 0000000000..074dfafaef
--- /dev/null
+++ b/spec/ruby/library/net-http/http/proppatch_spec.rb
@@ -0,0 +1,24 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+require_relative 'fixtures/http_server'
+
+describe "Net::HTTP#proppatch" do
+ before :each do
+ NetHTTPSpecs.start_server
+ @http = Net::HTTP.start("localhost", NetHTTPSpecs.port)
+ end
+
+ after :each do
+ @http.finish if @http.started?
+ NetHTTPSpecs.stop_server
+ end
+
+ it "sends an proppatch request to the passed path and returns the response" do
+ response = @http.proppatch("/request", "test=test")
+ response.body.should == "Request type: PROPPATCH"
+ end
+
+ it "returns a Net::HTTPResponse" do
+ @http.proppatch("/request", "test=test").should.is_a?(Net::HTTPResponse)
+ end
+end
diff --git a/spec/ruby/library/net-http/http/proxy_address_spec.rb b/spec/ruby/library/net-http/http/proxy_address_spec.rb
new file mode 100644
index 0000000000..ba040336ad
--- /dev/null
+++ b/spec/ruby/library/net-http/http/proxy_address_spec.rb
@@ -0,0 +1,31 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+
+describe "Net::HTTP.proxy_address" do
+ describe "when self is no proxy class" do
+ it "returns nil" do
+ Net::HTTP.proxy_address.should == nil
+ end
+ end
+
+ describe "when self is a proxy class" do
+ it "returns the address for self's proxy connection" do
+ Net::HTTP.Proxy("localhost", 1234, "rspec", "rocks").proxy_address.should == "localhost"
+ end
+ end
+end
+
+describe "Net::HTTP#proxy_address" do
+ describe "when self is no proxy class instance" do
+ it "returns nil" do
+ Net::HTTP.new("localhost", 3333).proxy_address.should == nil
+ end
+ end
+
+ describe "when self is a proxy class instance" do
+ it "returns the password for self's proxy connection" do
+ http_with_proxy = Net::HTTP.Proxy("localhost", 1234, "rspec", "rocks")
+ http_with_proxy.new("localhost", 3333).proxy_address.should == "localhost"
+ end
+ end
+end
diff --git a/spec/ruby/library/net-http/http/proxy_class_spec.rb b/spec/ruby/library/net-http/http/proxy_class_spec.rb
new file mode 100644
index 0000000000..eda027c893
--- /dev/null
+++ b/spec/ruby/library/net-http/http/proxy_class_spec.rb
@@ -0,0 +1,9 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+
+describe "Net::HTTP.proxy_class?" do
+ it "returns true if self is a class created with Net::HTTP.Proxy" do
+ Net::HTTP.proxy_class?.should == false
+ Net::HTTP.Proxy("localhost").proxy_class?.should == true
+ end
+end
diff --git a/spec/ruby/library/net-http/http/proxy_pass_spec.rb b/spec/ruby/library/net-http/http/proxy_pass_spec.rb
new file mode 100644
index 0000000000..ad02d896c0
--- /dev/null
+++ b/spec/ruby/library/net-http/http/proxy_pass_spec.rb
@@ -0,0 +1,39 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+
+describe "Net::HTTP.proxy_pass" do
+ describe "when self is no proxy class" do
+ it "returns nil" do
+ Net::HTTP.proxy_pass.should == nil
+ end
+ end
+
+ describe "when self is a proxy class" do
+ it "returns nil if no password was set for self's proxy connection" do
+ Net::HTTP.Proxy("localhost").proxy_pass.should == nil
+ end
+
+ it "returns the password for self's proxy connection" do
+ Net::HTTP.Proxy("localhost", 1234, "rspec", "rocks").proxy_pass.should == "rocks"
+ end
+ end
+end
+
+describe "Net::HTTP#proxy_pass" do
+ describe "when self is no proxy class instance" do
+ it "returns nil" do
+ Net::HTTP.new("localhost", 3333).proxy_pass.should == nil
+ end
+ end
+
+ describe "when self is a proxy class instance" do
+ it "returns nil if no password was set for self's proxy connection" do
+ Net::HTTP.Proxy("localhost").new("localhost", 3333).proxy_pass.should == nil
+ end
+
+ it "returns the password for self's proxy connection" do
+ http_with_proxy = Net::HTTP.Proxy("localhost", 1234, "rspec", "rocks")
+ http_with_proxy.new("localhost", 3333).proxy_pass.should == "rocks"
+ end
+ end
+end
diff --git a/spec/ruby/library/net-http/http/proxy_port_spec.rb b/spec/ruby/library/net-http/http/proxy_port_spec.rb
new file mode 100644
index 0000000000..21c1e4180e
--- /dev/null
+++ b/spec/ruby/library/net-http/http/proxy_port_spec.rb
@@ -0,0 +1,39 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+
+describe "Net::HTTP.proxy_port" do
+ describe "when self is no proxy class" do
+ it "returns nil" do
+ Net::HTTP.proxy_port.should == nil
+ end
+ end
+
+ describe "when self is a proxy class" do
+ it "returns 80 if no port was set for self's proxy connection" do
+ Net::HTTP.Proxy("localhost").proxy_port.should.eql?(80)
+ end
+
+ it "returns the port for self's proxy connection" do
+ Net::HTTP.Proxy("localhost", 1234, "rspec", "rocks").proxy_port.should.eql?(1234)
+ end
+ end
+end
+
+describe "Net::HTTP#proxy_port" do
+ describe "when self is no proxy class instance" do
+ it "returns nil" do
+ Net::HTTP.new("localhost", 3333).proxy_port.should == nil
+ end
+ end
+
+ describe "when self is a proxy class instance" do
+ it "returns 80 if no port was set for self's proxy connection" do
+ Net::HTTP.Proxy("localhost").new("localhost", 3333).proxy_port.should.eql?(80)
+ end
+
+ it "returns the port for self's proxy connection" do
+ http_with_proxy = Net::HTTP.Proxy("localhost", 1234, "rspec", "rocks")
+ http_with_proxy.new("localhost", 3333).proxy_port.should.eql?(1234)
+ end
+ end
+end
diff --git a/spec/ruby/library/net-http/http/proxy_user_spec.rb b/spec/ruby/library/net-http/http/proxy_user_spec.rb
new file mode 100644
index 0000000000..492ea2e8ee
--- /dev/null
+++ b/spec/ruby/library/net-http/http/proxy_user_spec.rb
@@ -0,0 +1,39 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+
+describe "Net::HTTP.proxy_user" do
+ describe "when self is no proxy class" do
+ it "returns nil" do
+ Net::HTTP.proxy_user.should == nil
+ end
+ end
+
+ describe "when self is a proxy class" do
+ it "returns nil if no username was set for self's proxy connection" do
+ Net::HTTP.Proxy("localhost").proxy_user.should == nil
+ end
+
+ it "returns the username for self's proxy connection" do
+ Net::HTTP.Proxy("localhost", 1234, "rspec", "rocks").proxy_user.should == "rspec"
+ end
+ end
+end
+
+describe "Net::HTTP#proxy_user" do
+ describe "when self is no proxy class instance" do
+ it "returns nil" do
+ Net::HTTP.new("localhost", 3333).proxy_user.should == nil
+ end
+ end
+
+ describe "when self is a proxy class instance" do
+ it "returns nil if no username was set for self's proxy connection" do
+ Net::HTTP.Proxy("localhost").new("localhost", 3333).proxy_user.should == nil
+ end
+
+ it "returns the username for self's proxy connection" do
+ http_with_proxy = Net::HTTP.Proxy("localhost", 1234, "rspec", "rocks")
+ http_with_proxy.new("localhost", 3333).proxy_user.should == "rspec"
+ end
+ end
+end
diff --git a/spec/ruby/library/net-http/http/put2_spec.rb b/spec/ruby/library/net-http/http/put2_spec.rb
new file mode 100644
index 0000000000..237df67e82
--- /dev/null
+++ b/spec/ruby/library/net-http/http/put2_spec.rb
@@ -0,0 +1,8 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+
+describe "Net::HTTP#put2" do
+ it "is an alias of Net::HTTP#request_put" do
+ Net::HTTP.instance_method(:put2).should == Net::HTTP.instance_method(:request_put)
+ end
+end
diff --git a/spec/ruby/library/net-http/http/put_spec.rb b/spec/ruby/library/net-http/http/put_spec.rb
new file mode 100644
index 0000000000..7ef9219f63
--- /dev/null
+++ b/spec/ruby/library/net-http/http/put_spec.rb
@@ -0,0 +1,24 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+require_relative 'fixtures/http_server'
+
+describe "Net::HTTP#put" do
+ before :each do
+ NetHTTPSpecs.start_server
+ @http = Net::HTTP.start("localhost", NetHTTPSpecs.port)
+ end
+
+ after :each do
+ @http.finish if @http.started?
+ NetHTTPSpecs.stop_server
+ end
+
+ it "sends an put request to the passed path and returns the response" do
+ response = @http.put("/request", "test=test")
+ response.body.should == "Request type: PUT"
+ end
+
+ it "returns a Net::HTTPResponse" do
+ @http.put("/request", "test=test").should.is_a?(Net::HTTPResponse)
+ end
+end
diff --git a/spec/ruby/library/net-http/http/read_timeout_spec.rb b/spec/ruby/library/net-http/http/read_timeout_spec.rb
new file mode 100644
index 0000000000..81e71337bb
--- /dev/null
+++ b/spec/ruby/library/net-http/http/read_timeout_spec.rb
@@ -0,0 +1,24 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+
+describe "Net::HTTP#read_timeout" do
+ it "returns the seconds to wait until reading one block" do
+ net = Net::HTTP.new("localhost")
+ net.read_timeout.should.eql?(60)
+ net.read_timeout = 10
+ net.read_timeout.should.eql?(10)
+ end
+end
+
+describe "Net::HTTP#read_timeout=" do
+ it "sets the seconds to wait till the connection is open" do
+ net = Net::HTTP.new("localhost")
+ net.read_timeout = 10
+ net.read_timeout.should.eql?(10)
+ end
+
+ it "returns the newly set value" do
+ net = Net::HTTP.new("localhost")
+ (net.read_timeout = 10).should.eql?(10)
+ end
+end
diff --git a/spec/ruby/library/net-http/http/request_get_spec.rb b/spec/ruby/library/net-http/http/request_get_spec.rb
new file mode 100644
index 0000000000..1737e62439
--- /dev/null
+++ b/spec/ruby/library/net-http/http/request_get_spec.rb
@@ -0,0 +1,45 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+require_relative 'fixtures/http_server'
+
+describe "Net::HTTP#request_get" do
+ before :each do
+ NetHTTPSpecs.start_server
+ @http = Net::HTTP.start("localhost", NetHTTPSpecs.port)
+ end
+
+ after :each do
+ @http.finish if @http.started?
+ NetHTTPSpecs.stop_server
+ end
+
+ describe "when passed no block" do
+ it "sends a GET request to the passed path and returns the response" do
+ response = @http.request_get("/request")
+ response.body.should == "Request type: GET"
+ end
+
+ it "returns a Net::HTTPResponse object" do
+ response = @http.request_get("/request")
+ response.should.is_a?(Net::HTTPResponse)
+ end
+ end
+
+ describe "when passed a block" do
+ it "sends a GET request to the passed path and returns the response" do
+ response = @http.request_get("/request") {}
+ response.body.should == "Request type: GET"
+ end
+
+ it "yields the response to the passed block" do
+ @http.request_get("/request") do |response|
+ response.body.should == "Request type: GET"
+ end
+ end
+
+ it "returns a Net::HTTPResponse object" do
+ response = @http.request_get("/request") {}
+ response.should.is_a?(Net::HTTPResponse)
+ end
+ end
+end
diff --git a/spec/ruby/library/net-http/http/request_head_spec.rb b/spec/ruby/library/net-http/http/request_head_spec.rb
new file mode 100644
index 0000000000..7c46ebfc53
--- /dev/null
+++ b/spec/ruby/library/net-http/http/request_head_spec.rb
@@ -0,0 +1,45 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+require_relative 'fixtures/http_server'
+
+describe "Net::HTTP#request_head" do
+ before :each do
+ NetHTTPSpecs.start_server
+ @http = Net::HTTP.start("localhost", NetHTTPSpecs.port)
+ end
+
+ after :each do
+ @http.finish if @http.started?
+ NetHTTPSpecs.stop_server
+ end
+
+ describe "when passed no block" do
+ it "sends a head request to the passed path and returns the response" do
+ response = @http.request_head("/request")
+ response.body.should == nil
+ end
+
+ it "returns a Net::HTTPResponse object" do
+ response = @http.request_head("/request")
+ response.should.is_a?(Net::HTTPResponse)
+ end
+ end
+
+ describe "when passed a block" do
+ it "sends a head request to the passed path and returns the response" do
+ response = @http.request_head("/request") {}
+ response.body.should == nil
+ end
+
+ it "yields the response to the passed block" do
+ @http.request_head("/request") do |response|
+ response.body.should == nil
+ end
+ end
+
+ it "returns a Net::HTTPResponse object" do
+ response = @http.request_head("/request") {}
+ response.should.is_a?(Net::HTTPResponse)
+ end
+ end
+end
diff --git a/spec/ruby/library/net-http/http/request_post_spec.rb b/spec/ruby/library/net-http/http/request_post_spec.rb
new file mode 100644
index 0000000000..8cfdd3469e
--- /dev/null
+++ b/spec/ruby/library/net-http/http/request_post_spec.rb
@@ -0,0 +1,45 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+require_relative 'fixtures/http_server'
+
+describe "Net::HTTP#request_post" do
+ before :each do
+ NetHTTPSpecs.start_server
+ @http = Net::HTTP.start("localhost", NetHTTPSpecs.port)
+ end
+
+ after :each do
+ @http.finish if @http.started?
+ NetHTTPSpecs.stop_server
+ end
+
+ describe "when passed no block" do
+ it "sends a post request to the passed path and returns the response" do
+ response = @http.request_post("/request", "test=test")
+ response.body.should == "Request type: POST"
+ end
+
+ it "returns a Net::HTTPResponse object" do
+ response = @http.request_post("/request", "test=test")
+ response.should.is_a?(Net::HTTPResponse)
+ end
+ end
+
+ describe "when passed a block" do
+ it "sends a post request to the passed path and returns the response" do
+ response = @http.request_post("/request", "test=test") {}
+ response.body.should == "Request type: POST"
+ end
+
+ it "yields the response to the passed block" do
+ @http.request_post("/request", "test=test") do |response|
+ response.body.should == "Request type: POST"
+ end
+ end
+
+ it "returns a Net::HTTPResponse object" do
+ response = @http.request_post("/request", "test=test") {}
+ response.should.is_a?(Net::HTTPResponse)
+ end
+ end
+end
diff --git a/spec/ruby/library/net-http/http/request_put_spec.rb b/spec/ruby/library/net-http/http/request_put_spec.rb
new file mode 100644
index 0000000000..b7388a21c8
--- /dev/null
+++ b/spec/ruby/library/net-http/http/request_put_spec.rb
@@ -0,0 +1,45 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+require_relative 'fixtures/http_server'
+
+describe "Net::HTTP#request_put" do
+ before :each do
+ NetHTTPSpecs.start_server
+ @http = Net::HTTP.start("localhost", NetHTTPSpecs.port)
+ end
+
+ after :each do
+ @http.finish if @http.started?
+ NetHTTPSpecs.stop_server
+ end
+
+ describe "when passed no block" do
+ it "sends a put request to the passed path and returns the response" do
+ response = @http.request_put("/request", "test=test")
+ response.body.should == "Request type: PUT"
+ end
+
+ it "returns a Net::HTTPResponse object" do
+ response = @http.request_put("/request", "test=test")
+ response.should.is_a?(Net::HTTPResponse)
+ end
+ end
+
+ describe "when passed a block" do
+ it "sends a put request to the passed path and returns the response" do
+ response = @http.request_put("/request", "test=test") {}
+ response.body.should == "Request type: PUT"
+ end
+
+ it "yields the response to the passed block" do
+ @http.request_put("/request", "test=test") do |response|
+ response.body.should == "Request type: PUT"
+ end
+ end
+
+ it "returns a Net::HTTPResponse object" do
+ response = @http.request_put("/request", "test=test") {}
+ response.should.is_a?(Net::HTTPResponse)
+ end
+ end
+end
diff --git a/spec/ruby/library/net-http/http/request_spec.rb b/spec/ruby/library/net-http/http/request_spec.rb
new file mode 100644
index 0000000000..e05ee96b55
--- /dev/null
+++ b/spec/ruby/library/net-http/http/request_spec.rb
@@ -0,0 +1,109 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+require_relative 'fixtures/http_server'
+
+describe "Net::HTTP#request" do
+ before :each do
+ NetHTTPSpecs.start_server
+ @http = Net::HTTP.start("localhost", NetHTTPSpecs.port)
+ end
+
+ after :each do
+ @http.finish if @http.started?
+ NetHTTPSpecs.stop_server
+ end
+
+ describe "when passed request_object" do
+ it "makes a HTTP Request based on the passed request_object" do
+ response = @http.request(Net::HTTP::Get.new("/request"), "test=test")
+ response.body.should == "Request type: GET"
+
+ response = @http.request(Net::HTTP::Head.new("/request"), "test=test")
+ response.body.should == nil
+
+ response = @http.request(Net::HTTP::Post.new("/request"), "test=test")
+ response.body.should == "Request type: POST"
+
+ response = @http.request(Net::HTTP::Put.new("/request"), "test=test")
+ response.body.should == "Request type: PUT"
+
+ response = @http.request(Net::HTTP::Proppatch.new("/request"), "test=test")
+ response.body.should == "Request type: PROPPATCH"
+
+ response = @http.request(Net::HTTP::Lock.new("/request"), "test=test")
+ response.body.should == "Request type: LOCK"
+
+ response = @http.request(Net::HTTP::Unlock.new("/request"), "test=test")
+ response.body.should == "Request type: UNLOCK"
+
+ # TODO: Does not work?
+ #response = @http.request(Net::HTTP::Options.new("/request"), "test=test")
+ #response.body.should == nil
+
+ response = @http.request(Net::HTTP::Propfind.new("/request"), "test=test")
+ response.body.should == "Request type: PROPFIND"
+
+ response = @http.request(Net::HTTP::Delete.new("/request"), "test=test")
+ response.body.should == "Request type: DELETE"
+
+ response = @http.request(Net::HTTP::Move.new("/request"), "test=test")
+ response.body.should == "Request type: MOVE"
+
+ response = @http.request(Net::HTTP::Copy.new("/request"), "test=test")
+ response.body.should == "Request type: COPY"
+
+ response = @http.request(Net::HTTP::Mkcol.new("/request"), "test=test")
+ response.body.should == "Request type: MKCOL"
+
+ response = @http.request(Net::HTTP::Trace.new("/request"), "test=test")
+ response.body.should == "Request type: TRACE"
+ end
+ end
+
+ describe "when passed request_object and request_body" do
+ it "sends the passed request_body when making the HTTP Request" do
+ response = @http.request(Net::HTTP::Get.new("/request/body"), "test=test")
+ response.body.should == "test=test"
+
+ response = @http.request(Net::HTTP::Head.new("/request/body"), "test=test")
+ response.body.should == nil
+
+ response = @http.request(Net::HTTP::Post.new("/request/body"), "test=test")
+ response.body.should == "test=test"
+
+ response = @http.request(Net::HTTP::Put.new("/request/body"), "test=test")
+ response.body.should == "test=test"
+
+ response = @http.request(Net::HTTP::Proppatch.new("/request/body"), "test=test")
+ response.body.should == "test=test"
+
+ response = @http.request(Net::HTTP::Lock.new("/request/body"), "test=test")
+ response.body.should == "test=test"
+
+ response = @http.request(Net::HTTP::Unlock.new("/request/body"), "test=test")
+ response.body.should == "test=test"
+
+ # TODO: Does not work?
+ #response = @http.request(Net::HTTP::Options.new("/request/body"), "test=test")
+ #response.body.should == nil
+
+ response = @http.request(Net::HTTP::Propfind.new("/request/body"), "test=test")
+ response.body.should == "test=test"
+
+ response = @http.request(Net::HTTP::Delete.new("/request/body"), "test=test")
+ response.body.should == "test=test"
+
+ response = @http.request(Net::HTTP::Move.new("/request/body"), "test=test")
+ response.body.should == "test=test"
+
+ response = @http.request(Net::HTTP::Copy.new("/request/body"), "test=test")
+ response.body.should == "test=test"
+
+ response = @http.request(Net::HTTP::Mkcol.new("/request/body"), "test=test")
+ response.body.should == "test=test"
+
+ response = @http.request(Net::HTTP::Trace.new("/request/body"), "test=test")
+ response.body.should == "test=test"
+ end
+ end
+end
diff --git a/spec/ruby/library/net-http/http/request_types_spec.rb b/spec/ruby/library/net-http/http/request_types_spec.rb
new file mode 100644
index 0000000000..0adc625979
--- /dev/null
+++ b/spec/ruby/library/net-http/http/request_types_spec.rb
@@ -0,0 +1,254 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+
+describe "Net::HTTP::Get" do
+ it "is a subclass of Net::HTTPRequest" do
+ Net::HTTP::Get.should < Net::HTTPRequest
+ end
+
+ it "represents the 'GET'-Request-Method" do
+ Net::HTTP::Get::METHOD.should == "GET"
+ end
+
+ it "has no Request Body" do
+ Net::HTTP::Get::REQUEST_HAS_BODY.should == false
+ end
+
+ it "has a Response Body" do
+ Net::HTTP::Get::RESPONSE_HAS_BODY.should == true
+ end
+end
+
+describe "Net::HTTP::Head" do
+ it "is a subclass of Net::HTTPRequest" do
+ Net::HTTP::Head.should < Net::HTTPRequest
+ end
+
+ it "represents the 'HEAD'-Request-Method" do
+ Net::HTTP::Head::METHOD.should == "HEAD"
+ end
+
+ it "has no Request Body" do
+ Net::HTTP::Head::REQUEST_HAS_BODY.should == false
+ end
+
+ it "has no Response Body" do
+ Net::HTTP::Head::RESPONSE_HAS_BODY.should == false
+ end
+end
+
+describe "Net::HTTP::Post" do
+ it "is a subclass of Net::HTTPRequest" do
+ Net::HTTP::Post.should < Net::HTTPRequest
+ end
+
+ it "represents the 'POST'-Request-Method" do
+ Net::HTTP::Post::METHOD.should == "POST"
+ end
+
+ it "has a Request Body" do
+ Net::HTTP::Post::REQUEST_HAS_BODY.should == true
+ end
+
+ it "has a Response Body" do
+ Net::HTTP::Post::RESPONSE_HAS_BODY.should == true
+ end
+end
+
+describe "Net::HTTP::Put" do
+ it "is a subclass of Net::HTTPRequest" do
+ Net::HTTP::Put.should < Net::HTTPRequest
+ end
+
+ it "represents the 'PUT'-Request-Method" do
+ Net::HTTP::Put::METHOD.should == "PUT"
+ end
+
+ it "has a Request Body" do
+ Net::HTTP::Put::REQUEST_HAS_BODY.should == true
+ end
+
+ it "has a Response Body" do
+ Net::HTTP::Put::RESPONSE_HAS_BODY.should == true
+ end
+end
+
+describe "Net::HTTP::Delete" do
+ it "is a subclass of Net::HTTPRequest" do
+ Net::HTTP::Delete.should < Net::HTTPRequest
+ end
+
+ it "represents the 'DELETE'-Request-Method" do
+ Net::HTTP::Delete::METHOD.should == "DELETE"
+ end
+
+ it "has no Request Body" do
+ Net::HTTP::Delete::REQUEST_HAS_BODY.should == false
+ end
+
+ it "has a Response Body" do
+ Net::HTTP::Delete::RESPONSE_HAS_BODY.should == true
+ end
+end
+
+describe "Net::HTTP::Options" do
+ it "is a subclass of Net::HTTPRequest" do
+ Net::HTTP::Options.should < Net::HTTPRequest
+ end
+
+ it "represents the 'OPTIONS'-Request-Method" do
+ Net::HTTP::Options::METHOD.should == "OPTIONS"
+ end
+
+ it "has no Request Body" do
+ Net::HTTP::Options::REQUEST_HAS_BODY.should == false
+ end
+
+ it "has no Response Body" do
+ Net::HTTP::Options::RESPONSE_HAS_BODY.should == true
+ end
+end
+
+describe "Net::HTTP::Trace" do
+ it "is a subclass of Net::HTTPRequest" do
+ Net::HTTP::Trace.should < Net::HTTPRequest
+ end
+
+ it "represents the 'TRACE'-Request-Method" do
+ Net::HTTP::Trace::METHOD.should == "TRACE"
+ end
+
+ it "has no Request Body" do
+ Net::HTTP::Trace::REQUEST_HAS_BODY.should == false
+ end
+
+ it "has a Response Body" do
+ Net::HTTP::Trace::RESPONSE_HAS_BODY.should == true
+ end
+end
+
+describe "Net::HTTP::Propfind" do
+ it "is a subclass of Net::HTTPRequest" do
+ Net::HTTP::Propfind.should < Net::HTTPRequest
+ end
+
+ it "represents the 'PROPFIND'-Request-Method" do
+ Net::HTTP::Propfind::METHOD.should == "PROPFIND"
+ end
+
+ it "has a Request Body" do
+ Net::HTTP::Propfind::REQUEST_HAS_BODY.should == true
+ end
+
+ it "has a Response Body" do
+ Net::HTTP::Propfind::RESPONSE_HAS_BODY.should == true
+ end
+end
+
+describe "Net::HTTP::Proppatch" do
+ it "is a subclass of Net::HTTPRequest" do
+ Net::HTTP::Proppatch.should < Net::HTTPRequest
+ end
+
+ it "represents the 'PROPPATCH'-Request-Method" do
+ Net::HTTP::Proppatch::METHOD.should == "PROPPATCH"
+ end
+
+ it "has a Request Body" do
+ Net::HTTP::Proppatch::REQUEST_HAS_BODY.should == true
+ end
+
+ it "has a Response Body" do
+ Net::HTTP::Proppatch::RESPONSE_HAS_BODY.should == true
+ end
+end
+
+describe "Net::HTTP::Mkcol" do
+ it "is a subclass of Net::HTTPRequest" do
+ Net::HTTP::Mkcol.should < Net::HTTPRequest
+ end
+
+ it "represents the 'MKCOL'-Request-Method" do
+ Net::HTTP::Mkcol::METHOD.should == "MKCOL"
+ end
+
+ it "has a Request Body" do
+ Net::HTTP::Mkcol::REQUEST_HAS_BODY.should == true
+ end
+
+ it "has a Response Body" do
+ Net::HTTP::Mkcol::RESPONSE_HAS_BODY.should == true
+ end
+end
+
+describe "Net::HTTP::Copy" do
+ it "is a subclass of Net::HTTPRequest" do
+ Net::HTTP::Copy.should < Net::HTTPRequest
+ end
+
+ it "represents the 'COPY'-Request-Method" do
+ Net::HTTP::Copy::METHOD.should == "COPY"
+ end
+
+ it "has no Request Body" do
+ Net::HTTP::Copy::REQUEST_HAS_BODY.should == false
+ end
+
+ it "has a Response Body" do
+ Net::HTTP::Copy::RESPONSE_HAS_BODY.should == true
+ end
+end
+
+describe "Net::HTTP::Move" do
+ it "is a subclass of Net::HTTPRequest" do
+ Net::HTTP::Move.should < Net::HTTPRequest
+ end
+
+ it "represents the 'MOVE'-Request-Method" do
+ Net::HTTP::Move::METHOD.should == "MOVE"
+ end
+
+ it "has no Request Body" do
+ Net::HTTP::Move::REQUEST_HAS_BODY.should == false
+ end
+
+ it "has a Response Body" do
+ Net::HTTP::Move::RESPONSE_HAS_BODY.should == true
+ end
+end
+
+describe "Net::HTTP::Lock" do
+ it "is a subclass of Net::HTTPRequest" do
+ Net::HTTP::Lock.should < Net::HTTPRequest
+ end
+
+ it "represents the 'LOCK'-Request-Method" do
+ Net::HTTP::Lock::METHOD.should == "LOCK"
+ end
+
+ it "has a Request Body" do
+ Net::HTTP::Lock::REQUEST_HAS_BODY.should == true
+ end
+
+ it "has a Response Body" do
+ Net::HTTP::Lock::RESPONSE_HAS_BODY.should == true
+ end
+end
+
+describe "Net::HTTP::Unlock" do
+ it "is a subclass of Net::HTTPRequest" do
+ Net::HTTP::Unlock.should < Net::HTTPRequest
+ end
+
+ it "represents the 'UNLOCK'-Request-Method" do
+ Net::HTTP::Unlock::METHOD.should == "UNLOCK"
+ end
+
+ it "has a Request Body" do
+ Net::HTTP::Unlock::REQUEST_HAS_BODY.should == true
+ end
+
+ it "has a Response Body" do
+ Net::HTTP::Unlock::RESPONSE_HAS_BODY.should == true
+ end
+end
diff --git a/spec/ruby/library/net-http/http/send_request_spec.rb b/spec/ruby/library/net-http/http/send_request_spec.rb
new file mode 100644
index 0000000000..e2dfc505b6
--- /dev/null
+++ b/spec/ruby/library/net-http/http/send_request_spec.rb
@@ -0,0 +1,61 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+require_relative 'fixtures/http_server'
+
+describe "Net::HTTP#send_request" do
+ before :each do
+ NetHTTPSpecs.start_server
+ @http = Net::HTTP.start("localhost", NetHTTPSpecs.port)
+
+ # HEAD is special so handled separately
+ @methods = %w[
+ GET POST PUT DELETE
+ OPTIONS
+ PROPFIND PROPPATCH LOCK UNLOCK
+ ]
+ end
+
+ after :each do
+ @http.finish if @http.started?
+ NetHTTPSpecs.stop_server
+ end
+
+ # TODO: Does only work with GET and POST requests
+ describe "when passed type, path" do
+ it "sends a HTTP Request of the passed type to the passed path" do
+ response = @http.send_request("HEAD", "/request")
+ response.body.should == nil
+
+ (@methods - %w[POST PUT]).each do |method|
+ response = @http.send_request(method, "/request")
+ response.body.should == "Request type: #{method}"
+ end
+ end
+ end
+
+ describe "when passed type, path, body" do
+ it "sends a HTTP Request with the passed body" do
+ response = @http.send_request("HEAD", "/request/body", "test=test")
+ response.body.should == nil
+
+ @methods.each do |method|
+ response = @http.send_request(method, "/request/body", "test=test")
+ response.body.should == "test=test"
+ end
+ end
+ end
+
+ describe "when passed type, path, body, headers" do
+ it "sends a HTTP Request with the passed headers" do
+ referer = 'https://www.ruby-lang.org/'.freeze
+
+ response = @http.send_request("HEAD", "/request/header", "test=test", "referer" => referer)
+ response.body.should == nil
+
+ @methods.each do |method|
+ response = @http.send_request(method, "/request/header", "test=test", "referer" => referer)
+ response.body.should.include?({ "Referer" => referer }.inspect.delete("{}"))
+ end
+ end
+ end
+end
diff --git a/spec/ruby/library/net-http/http/set_debug_output_spec.rb b/spec/ruby/library/net-http/http/set_debug_output_spec.rb
new file mode 100644
index 0000000000..491ac38b5d
--- /dev/null
+++ b/spec/ruby/library/net-http/http/set_debug_output_spec.rb
@@ -0,0 +1,33 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+require "stringio"
+require_relative 'fixtures/http_server'
+
+describe "Net::HTTP#set_debug_output when passed io" do
+ before :each do
+ NetHTTPSpecs.start_server
+ @http = Net::HTTP.new("localhost", NetHTTPSpecs.port)
+ end
+
+ after :each do
+ @http.finish if @http.started?
+ NetHTTPSpecs.stop_server
+ end
+
+ it "sets the passed io as output stream for debugging" do
+ io = StringIO.new
+
+ @http.set_debug_output(io)
+ @http.start
+ io.string.should_not.empty?
+ size = io.string.size
+
+ @http.get("/")
+ io.string.size.should > size
+ end
+
+ it "outputs a warning when the connection has already been started" do
+ @http.start
+ -> { @http.set_debug_output(StringIO.new) }.should complain(/Net::HTTP#set_debug_output called after HTTP started/)
+ end
+end
diff --git a/spec/ruby/library/net-http/http/socket_type_spec.rb b/spec/ruby/library/net-http/http/socket_type_spec.rb
new file mode 100644
index 0000000000..f6826777b0
--- /dev/null
+++ b/spec/ruby/library/net-http/http/socket_type_spec.rb
@@ -0,0 +1,8 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+
+describe "Net::HTTP.socket_type" do
+ it "returns BufferedIO" do
+ Net::HTTP.socket_type.should == Net::BufferedIO
+ end
+end
diff --git a/spec/ruby/library/net-http/http/start_spec.rb b/spec/ruby/library/net-http/http/start_spec.rb
new file mode 100644
index 0000000000..1aebc16f4d
--- /dev/null
+++ b/spec/ruby/library/net-http/http/start_spec.rb
@@ -0,0 +1,111 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+require_relative 'fixtures/http_server'
+
+describe "Net::HTTP.start" do
+ before :each do
+ NetHTTPSpecs.start_server
+ @port = NetHTTPSpecs.port
+ end
+
+ after :each do
+ NetHTTPSpecs.stop_server
+ end
+
+ describe "when not passed a block" do
+ before :each do
+ @http = Net::HTTP.start("localhost", @port)
+ end
+
+ after :each do
+ @http.finish if @http.started?
+ end
+
+ it "returns a new Net::HTTP object for the passed address and port" do
+ @http.should.is_a?(Net::HTTP)
+ @http.address.should == "localhost"
+ @http.port.should == @port
+ end
+
+ it "opens the tcp connection" do
+ @http.started?.should == true
+ end
+ end
+
+ describe "when passed a block" do
+ it "returns the blocks return value" do
+ Net::HTTP.start("localhost", @port) { :test }.should == :test
+ end
+
+ it "yields the new Net::HTTP object to the block" do
+ yielded = false
+ Net::HTTP.start("localhost", @port) do |net|
+ yielded = true
+ net.should.is_a?(Net::HTTP)
+ end
+ yielded.should == true
+ end
+
+ it "opens the tcp connection before yielding" do
+ Net::HTTP.start("localhost", @port) { |http| http.started?.should == true }
+ end
+
+ it "closes the tcp connection after yielding" do
+ net = nil
+ Net::HTTP.start("localhost", @port) { |x| net = x }
+ net.started?.should == false
+ end
+ end
+end
+
+describe "Net::HTTP#start" do
+ before :each do
+ NetHTTPSpecs.start_server
+ @http = Net::HTTP.new("localhost", NetHTTPSpecs.port)
+ end
+
+ after :each do
+ @http.finish if @http.started?
+ NetHTTPSpecs.stop_server
+ end
+
+ it "returns self" do
+ @http.start.should.equal?(@http)
+ end
+
+ it "opens the tcp connection" do
+ @http.start
+ @http.started?.should == true
+ end
+
+ describe "when self has already been started" do
+ it "raises an IOError" do
+ @http.start
+ -> { @http.start }.should.raise(IOError)
+ end
+ end
+
+ describe "when passed a block" do
+ it "returns the blocks return value" do
+ @http.start { :test }.should == :test
+ end
+
+ it "yields the new Net::HTTP object to the block" do
+ yielded = false
+ @http.start do |http|
+ yielded = true
+ http.should.equal?(@http)
+ end
+ yielded.should == true
+ end
+
+ it "opens the tcp connection before yielding" do
+ @http.start { |http| http.started?.should == true }
+ end
+
+ it "closes the tcp connection after yielding" do
+ @http.start { }
+ @http.started?.should == false
+ end
+ end
+end
diff --git a/spec/ruby/library/net-http/http/started_spec.rb b/spec/ruby/library/net-http/http/started_spec.rb
new file mode 100644
index 0000000000..a0b46fcbd2
--- /dev/null
+++ b/spec/ruby/library/net-http/http/started_spec.rb
@@ -0,0 +1,30 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+require_relative 'fixtures/http_server'
+
+describe "Net::HTTP#started?" do
+ before :each do
+ NetHTTPSpecs.start_server
+ @http = Net::HTTP.new("localhost", NetHTTPSpecs.port)
+ end
+
+ after :each do
+ @http.finish if @http.started?
+ NetHTTPSpecs.stop_server
+ end
+
+ it "returns true when self has been started" do
+ @http.start
+ @http.started?.should == true
+ end
+
+ it "returns false when self has not been started yet" do
+ @http.started?.should == false
+ end
+
+ it "returns false when self has been stopped again" do
+ @http.start
+ @http.finish
+ @http.started?.should == false
+ end
+end
diff --git a/spec/ruby/library/net-http/http/trace_spec.rb b/spec/ruby/library/net-http/http/trace_spec.rb
new file mode 100644
index 0000000000..e0ff741b04
--- /dev/null
+++ b/spec/ruby/library/net-http/http/trace_spec.rb
@@ -0,0 +1,24 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+require_relative 'fixtures/http_server'
+
+describe "Net::HTTP#trace" do
+ before :each do
+ NetHTTPSpecs.start_server
+ @http = Net::HTTP.start("localhost", NetHTTPSpecs.port)
+ end
+
+ after :each do
+ @http.finish if @http.started?
+ NetHTTPSpecs.stop_server
+ end
+
+ it "sends a TRACE request to the passed path and returns the response" do
+ response = @http.trace("/request")
+ response.body.should == "Request type: TRACE"
+ end
+
+ it "returns a Net::HTTPResponse" do
+ @http.trace("/request").should.is_a?(Net::HTTPResponse)
+ end
+end
diff --git a/spec/ruby/library/net-http/http/unlock_spec.rb b/spec/ruby/library/net-http/http/unlock_spec.rb
new file mode 100644
index 0000000000..cbfc803f09
--- /dev/null
+++ b/spec/ruby/library/net-http/http/unlock_spec.rb
@@ -0,0 +1,24 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+require_relative 'fixtures/http_server'
+
+describe "Net::HTTP#unlock" do
+ before :each do
+ NetHTTPSpecs.start_server
+ @http = Net::HTTP.start("localhost", NetHTTPSpecs.port)
+ end
+
+ after :each do
+ @http.finish if @http.started?
+ NetHTTPSpecs.stop_server
+ end
+
+ it "sends an UNLOCK request to the passed path and returns the response" do
+ response = @http.unlock("/request", "test=test")
+ response.body.should == "Request type: UNLOCK"
+ end
+
+ it "returns a Net::HTTPResponse" do
+ @http.unlock("/request", "test=test").should.is_a?(Net::HTTPResponse)
+ end
+end
diff --git a/spec/ruby/library/net-http/http/use_ssl_spec.rb b/spec/ruby/library/net-http/http/use_ssl_spec.rb
new file mode 100644
index 0000000000..b283655359
--- /dev/null
+++ b/spec/ruby/library/net-http/http/use_ssl_spec.rb
@@ -0,0 +1,9 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+
+describe "Net::HTTP#use_ssl?" do
+ it "returns false" do
+ http = Net::HTTP.new("localhost")
+ http.use_ssl?.should == false
+ end
+end
diff --git a/spec/ruby/library/net-http/http/version_1_1_spec.rb b/spec/ruby/library/net-http/http/version_1_1_spec.rb
new file mode 100644
index 0000000000..7f87bf30f9
--- /dev/null
+++ b/spec/ruby/library/net-http/http/version_1_1_spec.rb
@@ -0,0 +1,9 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+
+describe "Net::HTTP.version_1_1?" do
+ it "returns the state of net/http 1.1 features" do
+ Net::HTTP.version_1_2
+ Net::HTTP.version_1_1?.should == false
+ end
+end
diff --git a/spec/ruby/library/net-http/http/version_1_2_spec.rb b/spec/ruby/library/net-http/http/version_1_2_spec.rb
new file mode 100644
index 0000000000..73ca70ac7b
--- /dev/null
+++ b/spec/ruby/library/net-http/http/version_1_2_spec.rb
@@ -0,0 +1,22 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+
+describe "Net::HTTP.version_1_2" do
+ it "turns on net/http 1.2 features" do
+ Net::HTTP.version_1_2
+
+ Net::HTTP.version_1_2?.should == true
+ Net::HTTP.version_1_1?.should == false
+ end
+
+ it "returns true" do
+ Net::HTTP.version_1_2.should == true
+ end
+end
+
+describe "Net::HTTP.version_1_2?" do
+ it "returns the state of net/http 1.2 features" do
+ Net::HTTP.version_1_2
+ Net::HTTP.version_1_2?.should == true
+ end
+end
diff --git a/spec/ruby/library/net/http/httpexceptions/fixtures/classes.rb b/spec/ruby/library/net-http/httpexceptions/fixtures/classes.rb
index abe8855eff..abe8855eff 100644
--- a/spec/ruby/library/net/http/httpexceptions/fixtures/classes.rb
+++ b/spec/ruby/library/net-http/httpexceptions/fixtures/classes.rb
diff --git a/spec/ruby/library/net-http/httpexceptions/initialize_spec.rb b/spec/ruby/library/net-http/httpexceptions/initialize_spec.rb
new file mode 100644
index 0000000000..5316cca69d
--- /dev/null
+++ b/spec/ruby/library/net-http/httpexceptions/initialize_spec.rb
@@ -0,0 +1,17 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+require_relative 'fixtures/classes'
+
+describe "Net::HTTPExceptions#initialize when passed message, response" do
+ before :each do
+ @exception = NetHTTPExceptionsSpecs::Simple.new("error message", "a http response")
+ end
+
+ it "calls super with the passed message" do
+ @exception.message.should == "error message"
+ end
+
+ it "sets self's response to the passed response" do
+ @exception.response.should == "a http response"
+ end
+end
diff --git a/spec/ruby/library/net-http/httpexceptions/response_spec.rb b/spec/ruby/library/net-http/httpexceptions/response_spec.rb
new file mode 100644
index 0000000000..d718b1ae21
--- /dev/null
+++ b/spec/ruby/library/net-http/httpexceptions/response_spec.rb
@@ -0,0 +1,10 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+require_relative 'fixtures/classes'
+
+describe "Net::HTTPExceptions#response" do
+ it "returns self's response" do
+ exception = NetHTTPExceptionsSpecs::Simple.new("error message", "a http response")
+ exception.response.should == "a http response"
+ end
+end
diff --git a/spec/ruby/library/net-http/httpgenericrequest/body_exist_spec.rb b/spec/ruby/library/net-http/httpgenericrequest/body_exist_spec.rb
new file mode 100644
index 0000000000..96a761929e
--- /dev/null
+++ b/spec/ruby/library/net-http/httpgenericrequest/body_exist_spec.rb
@@ -0,0 +1,21 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+
+describe "Net::HTTPGenericRequest#body_exist?" do
+ it "returns true when the response is expected to have a body" do
+ request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path")
+ request.body_exist?.should == true
+
+ request = Net::HTTPGenericRequest.new("POST", true, false, "/some/path")
+ request.body_exist?.should == false
+ end
+
+ describe "when $VERBOSE is true" do
+ it "emits a warning" do
+ request = Net::HTTPGenericRequest.new("POST", true, false, "/some/path")
+ -> {
+ request.body_exist?
+ }.should complain(/body_exist\? is obsolete/, verbose: true)
+ end
+ end
+end
diff --git a/spec/ruby/library/net-http/httpgenericrequest/body_spec.rb b/spec/ruby/library/net-http/httpgenericrequest/body_spec.rb
new file mode 100644
index 0000000000..63cda994e5
--- /dev/null
+++ b/spec/ruby/library/net-http/httpgenericrequest/body_spec.rb
@@ -0,0 +1,30 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+require "stringio"
+
+describe "Net::HTTPGenericRequest#body" do
+ it "returns self's request body" do
+ request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path")
+ request.body.should == nil
+
+ request.body = "Some Content"
+ request.body.should == "Some Content"
+ end
+end
+
+describe "Net::HTTPGenericRequest#body=" do
+ before :each do
+ @request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path")
+ end
+
+ it "sets self's body content to the passed String" do
+ @request.body = "Some Content"
+ @request.body.should == "Some Content"
+ end
+
+ it "sets self's body stream to nil" do
+ @request.body_stream = StringIO.new("")
+ @request.body = "Some Content"
+ @request.body_stream.should == nil
+ end
+end
diff --git a/spec/ruby/library/net-http/httpgenericrequest/body_stream_spec.rb b/spec/ruby/library/net-http/httpgenericrequest/body_stream_spec.rb
new file mode 100644
index 0000000000..3237dbb861
--- /dev/null
+++ b/spec/ruby/library/net-http/httpgenericrequest/body_stream_spec.rb
@@ -0,0 +1,32 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+require "stringio"
+
+describe "Net::HTTPGenericRequest#body_stream" do
+ it "returns self's body stream Object" do
+ request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path")
+ request.body_stream.should == nil
+
+ stream = StringIO.new("test")
+ request.body_stream = stream
+ request.body_stream.should.equal?(stream)
+ end
+end
+
+describe "Net::HTTPGenericRequest#body_stream=" do
+ before :each do
+ @request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path")
+ @stream = StringIO.new("test")
+ end
+
+ it "sets self's body stream to the passed Object" do
+ @request.body_stream = @stream
+ @request.body_stream.should.equal?(@stream)
+ end
+
+ it "sets self's body to nil" do
+ @request.body = "Some Content"
+ @request.body_stream = @stream
+ @request.body.should == nil
+ end
+end
diff --git a/spec/ruby/library/net-http/httpgenericrequest/exec_spec.rb b/spec/ruby/library/net-http/httpgenericrequest/exec_spec.rb
new file mode 100644
index 0000000000..0ccf80e3b6
--- /dev/null
+++ b/spec/ruby/library/net-http/httpgenericrequest/exec_spec.rb
@@ -0,0 +1,135 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+require "stringio"
+
+describe "Net::HTTPGenericRequest#exec when passed socket, version, path" do
+ before :each do
+ @socket = StringIO.new(+"")
+ @buffered_socket = Net::BufferedIO.new(@socket)
+ end
+
+ it "executes the request over the socket to the path using the HTTP version" do
+ request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path")
+
+ request.exec(@buffered_socket, "1.1", "/some/path")
+ str = @socket.string
+
+ str.should =~ %r[POST /some/path HTTP/1.1\r\n]
+ str.should =~ %r[Accept: \*/\*\r\n]
+ str[-4..-1].should == "\r\n\r\n"
+
+ request = Net::HTTPGenericRequest.new("GET", true, true, "/some/path",
+ "Content-Type" => "text/html")
+
+ request.exec(@buffered_socket, "1.0", "/some/other/path")
+ str = @socket.string
+
+ str.should =~ %r[GET /some/other/path HTTP/1.0\r\n]
+ str.should =~ %r[Accept: \*/\*\r\n]
+ str.should =~ %r[Content-Type: text/html\r\n]
+ str[-4..-1].should == "\r\n\r\n"
+ end
+
+ describe "when a request body is set" do
+ ruby_version_is ""..."4.0" do
+ it "sets the 'Content-Type' header to 'application/x-www-form-urlencoded' unless the 'Content-Type' header is supplied" do
+ request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path")
+ request.body = "Some Content"
+
+ request.exec(@buffered_socket, "1.1", "/some/other/path")
+ str = @socket.string
+
+ str.should =~ %r[POST /some/other/path HTTP/1.1\r\n]
+ str.should =~ %r[Accept: \*/\*\r\n]
+ str.should =~ %r[Content-Type: application/x-www-form-urlencoded\r\n]
+ str.should =~ %r[Content-Length: 12\r\n]
+ str[-16..-1].should == "\r\n\r\nSome Content"
+ end
+ end
+
+ it "correctly sets the 'Content-Length' header and includes the body" do
+ request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path",
+ "Content-Type" => "text/html")
+ request.body = "Some Content"
+
+ request.exec(@buffered_socket, "1.1", "/some/other/path")
+ str = @socket.string
+
+ str.should =~ %r[POST /some/other/path HTTP/1.1\r\n]
+ str.should =~ %r[Accept: \*/\*\r\n]
+ str.should =~ %r[Content-Type: text/html\r\n]
+ str.should =~ %r[Content-Length: 12\r\n]
+ str[-16..-1].should == "\r\n\r\nSome Content"
+ end
+ end
+
+ describe "when a body stream is set" do
+ ruby_version_is ""..."4.0" do
+ it "sets the 'Content-Type' header to 'application/x-www-form-urlencoded' unless the 'Content-Type' header is supplied" do
+ request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path",
+ "Content-Length" => "10")
+ request.body_stream = StringIO.new("a" * 20)
+
+ request.exec(@buffered_socket, "1.1", "/some/other/path")
+ str = @socket.string
+
+ str.should =~ %r[POST /some/other/path HTTP/1.1\r\n]
+ str.should =~ %r[Accept: \*/\*\r\n]
+ str.should =~ %r[Content-Type: application/x-www-form-urlencoded\r\n]
+ str.should =~ %r[Content-Length: 10\r\n]
+ str[-24..-1].should == "\r\n\r\naaaaaaaaaaaaaaaaaaaa"
+ end
+ end
+
+ it "sends the whole stream, regardless of the 'Content-Length' header" do
+ request = Net::HTTPGenericRequest.new("POST", true, true,"/some/path",
+ "Content-Type" => "text/html",
+ "Content-Length" => "10")
+ request.body_stream = StringIO.new("a" * 20)
+
+ request.exec(@buffered_socket, "1.1", "/some/other/path")
+ str = @socket.string
+
+ str.should =~ %r[POST /some/other/path HTTP/1.1\r\n]
+ str.should =~ %r[Accept: \*/\*\r\n]
+ str.should =~ %r[Content-Type: text/html\r\n]
+ str.should =~ %r[Content-Length: 10\r\n]
+ str[-24..-1].should == "\r\n\r\naaaaaaaaaaaaaaaaaaaa"
+ end
+
+ it "sends the request in chunks when 'Transfer-Encoding' is set to 'chunked'" do
+ request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path",
+ "Content-Type" => "text/html",
+ "Transfer-Encoding" => "chunked")
+ datasize = 1024 * 10
+ request.body_stream = StringIO.new("a" * datasize)
+
+ request.exec(@buffered_socket, "1.1", "/some/other/path")
+ str = @socket.string
+
+ str.should =~ %r[POST /some/other/path HTTP/1.1\r\n]
+ str.should =~ %r[Accept: \*/\*\r\n]
+ str.should =~ %r[Content-Type: text/html\r\n]
+ str.should =~ %r[Transfer-Encoding: chunked\r\n]
+ str =~ %r[\r\n\r\n]
+ str = $'
+ while datasize > 0
+ chunk_size_line, str = str.split(/\r\n/, 2)
+ chunk_size = chunk_size_line[/\A[0-9A-Fa-f]+/].to_i(16)
+ str.slice!(0, chunk_size).should == 'a' * chunk_size
+ datasize -= chunk_size
+ str.slice!(0, 2).should == "\r\n"
+ end
+ datasize.should == 0
+ str.should == %"0\r\n\r\n"
+ end
+
+ it "raises an ArgumentError when the 'Content-Length' is not set or 'Transfer-Encoding' is not set to 'chunked'" do
+ request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path",
+ "Content-Type" => "text/html")
+ request.body_stream = StringIO.new("Some Content")
+
+ -> { request.exec(@buffered_socket, "1.1", "/some/other/path") }.should.raise(ArgumentError)
+ end
+ end
+end
diff --git a/spec/ruby/library/net-http/httpgenericrequest/inspect_spec.rb b/spec/ruby/library/net-http/httpgenericrequest/inspect_spec.rb
new file mode 100644
index 0000000000..d03b6e6953
--- /dev/null
+++ b/spec/ruby/library/net-http/httpgenericrequest/inspect_spec.rb
@@ -0,0 +1,25 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+
+describe "Net::HTTPGenericRequest#inspect" do
+ it "returns a String representation of self" do
+ request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path")
+ request.inspect.should == "#<Net::HTTPGenericRequest POST>"
+
+ request = Net::HTTPGenericRequest.new("GET", false, true, "/some/path")
+ request.inspect.should == "#<Net::HTTPGenericRequest GET>"
+
+ request = Net::HTTPGenericRequest.new("BLA", true, true, "/some/path")
+ request.inspect.should == "#<Net::HTTPGenericRequest BLA>"
+
+ # Subclasses
+ request = Net::HTTP::Get.new("/some/path")
+ request.inspect.should == "#<Net::HTTP::Get GET>"
+
+ request = Net::HTTP::Post.new("/some/path")
+ request.inspect.should == "#<Net::HTTP::Post POST>"
+
+ request = Net::HTTP::Trace.new("/some/path")
+ request.inspect.should == "#<Net::HTTP::Trace TRACE>"
+ end
+end
diff --git a/spec/ruby/library/net-http/httpgenericrequest/method_spec.rb b/spec/ruby/library/net-http/httpgenericrequest/method_spec.rb
new file mode 100644
index 0000000000..794bd328cd
--- /dev/null
+++ b/spec/ruby/library/net-http/httpgenericrequest/method_spec.rb
@@ -0,0 +1,15 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+
+describe "Net::HTTPGenericRequest#method" do
+ it "returns self's request method" do
+ request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path")
+ request.method.should == "POST"
+
+ request = Net::HTTPGenericRequest.new("GET", false, true, "/some/path")
+ request.method.should == "GET"
+
+ request = Net::HTTPGenericRequest.new("BLA", true, true, "/some/path")
+ request.method.should == "BLA"
+ end
+end
diff --git a/spec/ruby/library/net-http/httpgenericrequest/path_spec.rb b/spec/ruby/library/net-http/httpgenericrequest/path_spec.rb
new file mode 100644
index 0000000000..a9fac3f67e
--- /dev/null
+++ b/spec/ruby/library/net-http/httpgenericrequest/path_spec.rb
@@ -0,0 +1,12 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+
+describe "Net::HTTPGenericRequest#path" do
+ it "returns self's request path" do
+ request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path")
+ request.path.should == "/some/path"
+
+ request = Net::HTTPGenericRequest.new("POST", true, true, "/some/other/path")
+ request.path.should == "/some/other/path"
+ end
+end
diff --git a/spec/ruby/library/net-http/httpgenericrequest/request_body_permitted_spec.rb b/spec/ruby/library/net-http/httpgenericrequest/request_body_permitted_spec.rb
new file mode 100644
index 0000000000..ba836e8130
--- /dev/null
+++ b/spec/ruby/library/net-http/httpgenericrequest/request_body_permitted_spec.rb
@@ -0,0 +1,12 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+
+describe "Net::HTTPGenericRequest#request_body_permitted?" do
+ it "returns true when the request is expected to have a body" do
+ request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path")
+ request.request_body_permitted?.should == true
+
+ request = Net::HTTPGenericRequest.new("POST", false, true, "/some/path")
+ request.request_body_permitted?.should == false
+ end
+end
diff --git a/spec/ruby/library/net-http/httpgenericrequest/response_body_permitted_spec.rb b/spec/ruby/library/net-http/httpgenericrequest/response_body_permitted_spec.rb
new file mode 100644
index 0000000000..067500f60d
--- /dev/null
+++ b/spec/ruby/library/net-http/httpgenericrequest/response_body_permitted_spec.rb
@@ -0,0 +1,12 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+
+describe "Net::HTTPGenericRequest#response_body_permitted?" do
+ it "returns true when the response is expected to have a body" do
+ request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path")
+ request.response_body_permitted?.should == true
+
+ request = Net::HTTPGenericRequest.new("POST", true, false, "/some/path")
+ request.response_body_permitted?.should == false
+ end
+end
diff --git a/spec/ruby/library/net-http/httpgenericrequest/set_body_internal_spec.rb b/spec/ruby/library/net-http/httpgenericrequest/set_body_internal_spec.rb
new file mode 100644
index 0000000000..f241d8d698
--- /dev/null
+++ b/spec/ruby/library/net-http/httpgenericrequest/set_body_internal_spec.rb
@@ -0,0 +1,21 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+
+describe "Net::HTTPGenericRequest#set_body_internal when passed string" do
+ before :each do
+ @request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path")
+ end
+
+ it "sets self's body to the passed string" do
+ @request.set_body_internal("Some Content")
+ @request.body.should == "Some Content"
+ end
+
+ it "raises an ArgumentError when the body or body_stream of self have already been set" do
+ @request.body = "Some Content"
+ -> { @request.set_body_internal("Some other Content") }.should.raise(ArgumentError)
+
+ @request.body_stream = "Some Content"
+ -> { @request.set_body_internal("Some other Content") }.should.raise(ArgumentError)
+ end
+end
diff --git a/spec/ruby/library/net-http/httpheader/add_field_spec.rb b/spec/ruby/library/net-http/httpheader/add_field_spec.rb
new file mode 100644
index 0000000000..8cd3d33517
--- /dev/null
+++ b/spec/ruby/library/net-http/httpheader/add_field_spec.rb
@@ -0,0 +1,31 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+require_relative 'fixtures/classes'
+
+describe "Net::HTTPHeader#add_field when passed key, value" do
+ before :each do
+ @headers = NetHTTPHeaderSpecs::Example.new
+ end
+
+ it "adds the passed value to the header entry with the passed key" do
+ @headers.add_field("My-Header", "a")
+ @headers.get_fields("My-Header").should == ["a"]
+
+ @headers.add_field("My-Header", "b")
+ @headers.get_fields("My-Header").should == ["a", "b"]
+
+ @headers.add_field("My-Header", "c")
+ @headers.get_fields("My-Header").should == ["a", "b", "c"]
+ end
+
+ it "is case-insensitive" do
+ @headers.add_field("My-Header", "a")
+ @headers.get_fields("My-Header").should == ["a"]
+
+ @headers.add_field("my-header", "b")
+ @headers.get_fields("My-Header").should == ["a", "b"]
+
+ @headers.add_field("MY-HEADER", "c")
+ @headers.get_fields("My-Header").should == ["a", "b", "c"]
+ end
+end
diff --git a/spec/ruby/library/net-http/httpheader/basic_auth_spec.rb b/spec/ruby/library/net-http/httpheader/basic_auth_spec.rb
new file mode 100644
index 0000000000..db7ca84d13
--- /dev/null
+++ b/spec/ruby/library/net-http/httpheader/basic_auth_spec.rb
@@ -0,0 +1,14 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+require_relative 'fixtures/classes'
+
+describe "Net::HTTPHeader#basic_auth when passed account, password" do
+ before :each do
+ @headers = NetHTTPHeaderSpecs::Example.new
+ end
+
+ it "sets the 'Authorization' Header entry for basic authorization" do
+ @headers.basic_auth("rubyspec", "rocks")
+ @headers["Authorization"].should == "Basic cnVieXNwZWM6cm9ja3M="
+ end
+end
diff --git a/spec/ruby/library/net-http/httpheader/canonical_each_spec.rb b/spec/ruby/library/net-http/httpheader/canonical_each_spec.rb
new file mode 100644
index 0000000000..c009e9f7ea
--- /dev/null
+++ b/spec/ruby/library/net-http/httpheader/canonical_each_spec.rb
@@ -0,0 +1,9 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+
+describe "Net::HTTPHeader#canonical_each" do
+ it "is an alias of Net::HTTPHeader#each_capitalized" do
+ Net::HTTPHeader.instance_method(:canonical_each).should ==
+ Net::HTTPHeader.instance_method(:each_capitalized)
+ end
+end
diff --git a/spec/ruby/library/net-http/httpheader/chunked_spec.rb b/spec/ruby/library/net-http/httpheader/chunked_spec.rb
new file mode 100644
index 0000000000..4da218ae25
--- /dev/null
+++ b/spec/ruby/library/net-http/httpheader/chunked_spec.rb
@@ -0,0 +1,22 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+require_relative 'fixtures/classes'
+
+describe "Net::HTTPHeader#chunked?" do
+ before :each do
+ @headers = NetHTTPHeaderSpecs::Example.new
+ end
+
+ it "returns true if the 'Transfer-Encoding' header entry is set to chunked" do
+ @headers.chunked?.should == false
+
+ @headers["Transfer-Encoding"] = "bla"
+ @headers.chunked?.should == false
+
+ @headers["Transfer-Encoding"] = "blachunkedbla"
+ @headers.chunked?.should == false
+
+ @headers["Transfer-Encoding"] = "chunked"
+ @headers.chunked?.should == true
+ end
+end
diff --git a/spec/ruby/library/net-http/httpheader/content_length_spec.rb b/spec/ruby/library/net-http/httpheader/content_length_spec.rb
new file mode 100644
index 0000000000..c66d5673c1
--- /dev/null
+++ b/spec/ruby/library/net-http/httpheader/content_length_spec.rb
@@ -0,0 +1,54 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+require_relative 'fixtures/classes'
+
+describe "Net::HTTPHeader#content_length" do
+ before :each do
+ @headers = NetHTTPHeaderSpecs::Example.new
+ end
+
+ it "returns nil if no 'Content-Length' header entry is set" do
+ @headers.content_length.should == nil
+ end
+
+ it "raises a Net::HTTPHeaderSyntaxError when the 'Content-Length' header entry has an invalid format" do
+ @headers["Content-Length"] = "invalid"
+ -> { @headers.content_length }.should.raise(Net::HTTPHeaderSyntaxError)
+ end
+
+ it "returns the value of the 'Content-Length' header entry as an Integer" do
+ @headers["Content-Length"] = "123"
+ @headers.content_length.should.eql?(123)
+
+ @headers["Content-Length"] = "123valid"
+ @headers.content_length.should.eql?(123)
+
+ @headers["Content-Length"] = "valid123"
+ @headers.content_length.should.eql?(123)
+ end
+end
+
+describe "Net::HTTPHeader#content_length=" do
+ before :each do
+ @headers = NetHTTPHeaderSpecs::Example.new
+ end
+
+ it "removes the 'Content-Length' entry if passed false or nil" do
+ @headers["Content-Length"] = "123"
+ @headers.content_length = nil
+ @headers["Content-Length"].should == nil
+ end
+
+ it "sets the 'Content-Length' entry to the passed value" do
+ @headers.content_length = "123"
+ @headers["Content-Length"].should == "123"
+
+ @headers.content_length = "123valid"
+ @headers["Content-Length"].should == "123"
+ end
+
+ it "sets the 'Content-Length' entry to 0 if the passed value is not valid" do
+ @headers.content_length = "invalid123"
+ @headers["Content-Length"].should == "0"
+ end
+end
diff --git a/spec/ruby/library/net-http/httpheader/content_range_spec.rb b/spec/ruby/library/net-http/httpheader/content_range_spec.rb
new file mode 100644
index 0000000000..3635fb3f1b
--- /dev/null
+++ b/spec/ruby/library/net-http/httpheader/content_range_spec.rb
@@ -0,0 +1,32 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+require_relative 'fixtures/classes'
+
+describe "Net::HTTPHeader#content_range" do
+ before :each do
+ @headers = NetHTTPHeaderSpecs::Example.new
+ end
+
+ it "returns a Range object that represents the 'Content-Range' header entry" do
+ @headers["Content-Range"] = "bytes 0-499/1234"
+ @headers.content_range.should == (0..499)
+
+ @headers["Content-Range"] = "bytes 500-1233/1234"
+ @headers.content_range.should == (500..1233)
+ end
+
+ it "returns nil when there is no 'Content-Range' header entry" do
+ @headers.content_range.should == nil
+ end
+
+ it "raises a Net::HTTPHeaderSyntaxError when the 'Content-Range' has an invalid format" do
+ @headers["Content-Range"] = "invalid"
+ -> { @headers.content_range }.should.raise(Net::HTTPHeaderSyntaxError)
+
+ @headers["Content-Range"] = "bytes 123-abc"
+ -> { @headers.content_range }.should.raise(Net::HTTPHeaderSyntaxError)
+
+ @headers["Content-Range"] = "bytes abc-123"
+ -> { @headers.content_range }.should.raise(Net::HTTPHeaderSyntaxError)
+ end
+end
diff --git a/spec/ruby/library/net-http/httpheader/content_type_spec.rb b/spec/ruby/library/net-http/httpheader/content_type_spec.rb
new file mode 100644
index 0000000000..0ee43a6942
--- /dev/null
+++ b/spec/ruby/library/net-http/httpheader/content_type_spec.rb
@@ -0,0 +1,28 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+require_relative 'fixtures/classes'
+
+describe "Net::HTTPHeader#content_type" do
+ before :each do
+ @headers = NetHTTPHeaderSpecs::Example.new
+ end
+
+ it "returns the content type string, as per 'Content-Type' header entry" do
+ @headers["Content-Type"] = "text/html"
+ @headers.content_type.should == "text/html"
+
+ @headers["Content-Type"] = "text/html;charset=utf-8"
+ @headers.content_type.should == "text/html"
+ end
+
+ it "returns nil if the 'Content-Type' header entry does not exist" do
+ @headers.content_type.should == nil
+ end
+end
+
+describe "Net::HTTPHeader#content_type=" do
+ it "is an alias of Net::HTTPHeader#set_content_type" do
+ Net::HTTPHeader.instance_method(:content_type=).should ==
+ Net::HTTPHeader.instance_method(:set_content_type)
+ end
+end
diff --git a/spec/ruby/library/net-http/httpheader/delete_spec.rb b/spec/ruby/library/net-http/httpheader/delete_spec.rb
new file mode 100644
index 0000000000..09bae65a13
--- /dev/null
+++ b/spec/ruby/library/net-http/httpheader/delete_spec.rb
@@ -0,0 +1,30 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+require_relative 'fixtures/classes'
+
+describe "Net::HTTPHeader#delete when passed key" do
+ before :each do
+ @headers = NetHTTPHeaderSpecs::Example.new
+ end
+
+ it "removes the header entry with the passed key" do
+ @headers["My-Header"] = "test"
+ @headers.delete("My-Header")
+
+ @headers["My-Header"].should == nil
+ @headers.size.should.eql?(0)
+ end
+
+ it "returns the removed values" do
+ @headers["My-Header"] = "test"
+ @headers.delete("My-Header").should == ["test"]
+ end
+
+ it "is case-insensitive" do
+ @headers["My-Header"] = "test"
+ @headers.delete("my-header")
+
+ @headers["My-Header"].should == nil
+ @headers.size.should.eql?(0)
+ end
+end
diff --git a/spec/ruby/library/net-http/httpheader/each_capitalized_name_spec.rb b/spec/ruby/library/net-http/httpheader/each_capitalized_name_spec.rb
new file mode 100644
index 0000000000..54874c0535
--- /dev/null
+++ b/spec/ruby/library/net-http/httpheader/each_capitalized_name_spec.rb
@@ -0,0 +1,35 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+require_relative 'fixtures/classes'
+
+describe "Net::HTTPHeader#each_capitalized_name" do
+ before :each do
+ @headers = NetHTTPHeaderSpecs::Example.new
+ @headers["My-Header"] = "test"
+ @headers.add_field("My-Other-Header", "a")
+ @headers.add_field("My-Other-Header", "b")
+ end
+
+ describe "when passed a block" do
+ it "yields each header key to the passed block (keys capitalized)" do
+ res = []
+ @headers.each_capitalized_name do |key|
+ res << key
+ end
+ res.sort.should == ["My-Header", "My-Other-Header"]
+ end
+ end
+
+ describe "when passed no block" do
+ it "returns an Enumerator" do
+ enumerator = @headers.each_capitalized_name
+ enumerator.should.instance_of?(Enumerator)
+
+ res = []
+ enumerator.each do |key|
+ res << key
+ end
+ res.sort.should == ["My-Header", "My-Other-Header"]
+ end
+ end
+end
diff --git a/spec/ruby/library/net-http/httpheader/each_capitalized_spec.rb b/spec/ruby/library/net-http/httpheader/each_capitalized_spec.rb
new file mode 100644
index 0000000000..e24e778238
--- /dev/null
+++ b/spec/ruby/library/net-http/httpheader/each_capitalized_spec.rb
@@ -0,0 +1,35 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+require_relative 'fixtures/classes'
+
+describe "Net::HTTPHeader#each_capitalized" do
+ before :each do
+ @headers = NetHTTPHeaderSpecs::Example.new
+ @headers["my-header"] = "test"
+ @headers.add_field("my-Other-Header", "a")
+ @headers.add_field("My-Other-header", "b")
+ end
+
+ describe "when passed a block" do
+ it "yields each header entry to the passed block (capitalized keys, values joined)" do
+ res = []
+ @headers.each_capitalized do |key, value|
+ res << [key, value]
+ end
+ res.sort.should == [["My-Header", "test"], ["My-Other-Header", "a, b"]]
+ end
+ end
+
+ describe "when passed no block" do
+ it "returns an Enumerator" do
+ enumerator = @headers.each_capitalized
+ enumerator.should.instance_of?(Enumerator)
+
+ res = []
+ enumerator.each do |*key|
+ res << key
+ end
+ res.sort.should == [["My-Header", "test"], ["My-Other-Header", "a, b"]]
+ end
+ end
+end
diff --git a/spec/ruby/library/net-http/httpheader/each_header_spec.rb b/spec/ruby/library/net-http/httpheader/each_header_spec.rb
new file mode 100644
index 0000000000..63c1106d18
--- /dev/null
+++ b/spec/ruby/library/net-http/httpheader/each_header_spec.rb
@@ -0,0 +1,35 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+require_relative 'fixtures/classes'
+
+describe "Net::HTTPHeader#each_header" do
+ before :each do
+ @headers = NetHTTPHeaderSpecs::Example.new
+ @headers["My-Header"] = "test"
+ @headers.add_field("My-Other-Header", "a")
+ @headers.add_field("My-Other-Header", "b")
+ end
+
+ describe "when passed a block" do
+ it "yields each header entry to the passed block (keys in lower case, values joined)" do
+ res = []
+ @headers.each_header do |key, value|
+ res << [key, value]
+ end
+ res.sort.should == [["my-header", "test"], ["my-other-header", "a, b"]]
+ end
+ end
+
+ describe "when passed no block" do
+ it "returns an Enumerator" do
+ enumerator = @headers.each_header
+ enumerator.should.instance_of?(Enumerator)
+
+ res = []
+ enumerator.each do |*key|
+ res << key
+ end
+ res.sort.should == [["my-header", "test"], ["my-other-header", "a, b"]]
+ end
+ end
+end
diff --git a/spec/ruby/library/net-http/httpheader/each_key_spec.rb b/spec/ruby/library/net-http/httpheader/each_key_spec.rb
new file mode 100644
index 0000000000..a5635da5db
--- /dev/null
+++ b/spec/ruby/library/net-http/httpheader/each_key_spec.rb
@@ -0,0 +1,35 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+require_relative 'fixtures/classes'
+
+describe "Net::HTTPHeader#each_key" do
+ before :each do
+ @headers = NetHTTPHeaderSpecs::Example.new
+ @headers["My-Header"] = "test"
+ @headers.add_field("My-Other-Header", "a")
+ @headers.add_field("My-Other-Header", "b")
+ end
+
+ describe "when passed a block" do
+ it "yields each header key to the passed block (keys in lower case)" do
+ res = []
+ @headers.each_key do |key|
+ res << key
+ end
+ res.sort.should == ["my-header", "my-other-header"]
+ end
+ end
+
+ describe "when passed no block" do
+ it "returns an Enumerator" do
+ enumerator = @headers.each_key
+ enumerator.should.instance_of?(Enumerator)
+
+ res = []
+ enumerator.each do |key|
+ res << key
+ end
+ res.sort.should == ["my-header", "my-other-header"]
+ end
+ end
+end
diff --git a/spec/ruby/library/net-http/httpheader/each_name_spec.rb b/spec/ruby/library/net-http/httpheader/each_name_spec.rb
new file mode 100644
index 0000000000..02f9761f80
--- /dev/null
+++ b/spec/ruby/library/net-http/httpheader/each_name_spec.rb
@@ -0,0 +1,10 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+require_relative 'fixtures/classes'
+
+describe "Net::HTTPHeader#each_name" do
+ it "is an alias of Net::HTTPHeader#each_key" do
+ Net::HTTPHeader.instance_method(:each_name).should ==
+ Net::HTTPHeader.instance_method(:each_key)
+ end
+end
diff --git a/spec/ruby/library/net-http/httpheader/each_spec.rb b/spec/ruby/library/net-http/httpheader/each_spec.rb
new file mode 100644
index 0000000000..e219609b67
--- /dev/null
+++ b/spec/ruby/library/net-http/httpheader/each_spec.rb
@@ -0,0 +1,9 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+
+describe "Net::HTTPHeader#each" do
+ it "is an alias of Net::HTTPHeader#each_header" do
+ Net::HTTPHeader.instance_method(:each).should ==
+ Net::HTTPHeader.instance_method(:each_header)
+ end
+end
diff --git a/spec/ruby/library/net-http/httpheader/each_value_spec.rb b/spec/ruby/library/net-http/httpheader/each_value_spec.rb
new file mode 100644
index 0000000000..55ba4c1ef8
--- /dev/null
+++ b/spec/ruby/library/net-http/httpheader/each_value_spec.rb
@@ -0,0 +1,35 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+require_relative 'fixtures/classes'
+
+describe "Net::HTTPHeader#each_value" do
+ before :each do
+ @headers = NetHTTPHeaderSpecs::Example.new
+ @headers["My-Header"] = "test"
+ @headers.add_field("My-Other-Header", "a")
+ @headers.add_field("My-Other-Header", "b")
+ end
+
+ describe "when passed a block" do
+ it "yields each header entry's joined values" do
+ res = []
+ @headers.each_value do |value|
+ res << value
+ end
+ res.sort.should == ["a, b", "test"]
+ end
+ end
+
+ describe "when passed no block" do
+ it "returns an Enumerator" do
+ enumerator = @headers.each_value
+ enumerator.should.instance_of?(Enumerator)
+
+ res = []
+ enumerator.each do |key|
+ res << key
+ end
+ res.sort.should == ["a, b", "test"]
+ end
+ end
+end
diff --git a/spec/ruby/library/net-http/httpheader/element_reference_spec.rb b/spec/ruby/library/net-http/httpheader/element_reference_spec.rb
new file mode 100644
index 0000000000..f12f8494db
--- /dev/null
+++ b/spec/ruby/library/net-http/httpheader/element_reference_spec.rb
@@ -0,0 +1,39 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+require_relative 'fixtures/classes'
+
+describe "Net::HTTPHeader#[] when passed key" do
+ before :each do
+ @headers = NetHTTPHeaderSpecs::Example.new
+ end
+
+ it "returns the value of the header entry with the passed key" do
+ @headers["My-Header"] = "test"
+ @headers["My-Header"].should == "test"
+ @headers["My-Other-Header"] = "another test"
+ @headers["My-Other-Header"].should == "another test"
+ end
+
+ it "is case-insensitive" do
+ @headers["My-Header"] = "test"
+
+ @headers['My-Header'].should == "test"
+ @headers['my-Header'].should == "test"
+ @headers['My-header'].should == "test"
+ @headers['my-header'].should == "test"
+ @headers['MY-HEADER'].should == "test"
+ end
+
+ it "returns multi-element values joined together" do
+ @headers["My-Header"] = "test"
+ @headers.add_field("My-Header", "another test")
+ @headers.add_field("My-Header", "and one more")
+
+ @headers["My-Header"].should == "test, another test, and one more"
+ end
+
+ it "returns nil for non-existing entries" do
+ @headers["My-Header"].should == nil
+ @headers["My-Other-Header"].should == nil
+ end
+end
diff --git a/spec/ruby/library/net-http/httpheader/element_set_spec.rb b/spec/ruby/library/net-http/httpheader/element_set_spec.rb
new file mode 100644
index 0000000000..633fe18b2e
--- /dev/null
+++ b/spec/ruby/library/net-http/httpheader/element_set_spec.rb
@@ -0,0 +1,41 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+require_relative 'fixtures/classes'
+
+describe "Net::HTTPHeader#[]= when passed key, value" do
+ before :each do
+ @headers = NetHTTPHeaderSpecs::Example.new
+ end
+
+ it "sets the header entry with the passed key to the passed value" do
+ @headers["My-Header"] = "test"
+ @headers["My-Header"].should == "test"
+
+ @headers["My-Header"] = "overwritten"
+ @headers["My-Header"].should == "overwritten"
+
+ @headers["My-Other-Header"] = "another test"
+ @headers["My-Other-Header"].should == "another test"
+ end
+
+ it "is case-insensitive" do
+ @headers['My-Header'] = "test"
+ @headers['my-Header'] = "another test"
+ @headers['My-header'] = "and one more test"
+ @headers['my-header'] = "and another one"
+ @headers['MY-HEADER'] = "last one"
+
+ @headers["My-Header"].should == "last one"
+ @headers.size.should.eql?(1)
+ end
+
+ it "removes the header entry with the passed key when the value is false or nil" do
+ @headers['My-Header'] = "test"
+ @headers['My-Header'] = nil
+ @headers['My-Header'].should == nil
+
+ @headers['My-Header'] = "test"
+ @headers['My-Header'] = false
+ @headers['My-Header'].should == nil
+ end
+end
diff --git a/spec/ruby/library/net-http/httpheader/fetch_spec.rb b/spec/ruby/library/net-http/httpheader/fetch_spec.rb
new file mode 100644
index 0000000000..d1c273dada
--- /dev/null
+++ b/spec/ruby/library/net-http/httpheader/fetch_spec.rb
@@ -0,0 +1,68 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+require_relative 'fixtures/classes'
+
+describe "Net::HTTPHeader#fetch" do
+ before :each do
+ @headers = NetHTTPHeaderSpecs::Example.new
+ end
+
+ describe "when passed key" do
+ it "returns the header entry for the passed key" do
+ @headers["My-Header"] = "test"
+ @headers.fetch("My-Header").should == "test"
+
+ @headers.add_field("My-Other-Header", "a")
+ @headers.add_field("My-Other-Header", "b")
+ @headers.add_field("My-Other-Header", "c")
+ @headers.fetch("My-Other-Header").should == "a, b, c"
+ end
+
+ it "is case-insensitive" do
+ @headers["My-Header"] = "test"
+ @headers.fetch("my-header").should == "test"
+ @headers.fetch("MY-HEADER").should == "test"
+ end
+
+ it "returns nil when there is no entry for the passed key" do
+ -> { @headers.fetch("my-header") }.should.raise(IndexError)
+ end
+ end
+
+ describe "when passed key, default" do
+ it "returns the header entry for the passed key" do
+ @headers["My-Header"] = "test"
+ @headers.fetch("My-Header", "bla").should == "test"
+
+ @headers.add_field("My-Other-Header", "a")
+ @headers.add_field("My-Other-Header", "b")
+ @headers.add_field("My-Other-Header", "c")
+ @headers.fetch("My-Other-Header", "bla").should == "a, b, c"
+ end
+
+ # TODO: This raises a NoMethodError: undefined method `join' for "bla":String
+ it "returns the default value when there is no entry for the passed key" do
+ @headers.fetch("My-Header", "bla").should == "bla"
+ end
+ end
+
+ describe "when passed key and block" do
+ it "returns the header entry for the passed key" do
+ @headers["My-Header"] = "test"
+ @headers.fetch("My-Header") {}.should == "test"
+
+ @headers.add_field("My-Other-Header", "a")
+ @headers.add_field("My-Other-Header", "b")
+ @headers.add_field("My-Other-Header", "c")
+ -> {
+ @result = @headers.fetch("My-Other-Header", "bla") {}
+ }.should complain(/block supersedes default value argument/)
+ @result.should == "a, b, c"
+ end
+
+ # TODO: This raises a NoMethodError: undefined method `join' for "redaeh-ym":String
+ it "yieldsand returns the block's return value when there is no entry for the passed key" do
+ @headers.fetch("My-Header") { |key| key.reverse }.should == "redaeh-ym"
+ end
+ end
+end
diff --git a/spec/ruby/library/net/http/httpheader/fixtures/classes.rb b/spec/ruby/library/net-http/httpheader/fixtures/classes.rb
index b5ec6abd75..b5ec6abd75 100644
--- a/spec/ruby/library/net/http/httpheader/fixtures/classes.rb
+++ b/spec/ruby/library/net-http/httpheader/fixtures/classes.rb
diff --git a/spec/ruby/library/net-http/httpheader/form_data_spec.rb b/spec/ruby/library/net-http/httpheader/form_data_spec.rb
new file mode 100644
index 0000000000..8d4974cde3
--- /dev/null
+++ b/spec/ruby/library/net-http/httpheader/form_data_spec.rb
@@ -0,0 +1,10 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+require_relative 'fixtures/classes'
+
+describe "Net::HTTPHeader#form_data=" do
+ it "is an alias of Net::HTTPHeader#set_form_data" do
+ Net::HTTPHeader.instance_method(:form_data=).should ==
+ Net::HTTPHeader.instance_method(:set_form_data)
+ end
+end
diff --git a/spec/ruby/library/net-http/httpheader/get_fields_spec.rb b/spec/ruby/library/net-http/httpheader/get_fields_spec.rb
new file mode 100644
index 0000000000..76da63bc31
--- /dev/null
+++ b/spec/ruby/library/net-http/httpheader/get_fields_spec.rb
@@ -0,0 +1,39 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+require_relative 'fixtures/classes'
+
+describe "Net::HTTPHeader#get_fields when passed key" do
+ before :each do
+ @headers = NetHTTPHeaderSpecs::Example.new
+ end
+
+ it "returns an Array containing the values of the header entry with the passed key" do
+ @headers["My-Header"] = "a"
+ @headers.get_fields("My-Header").should == ["a"]
+
+ @headers.add_field("My-Header", "b")
+ @headers.get_fields("My-Header").should == ["a", "b"]
+ end
+
+ it "returns a copy of the header entry values" do
+ @headers["My-Header"] = "a"
+
+ @headers.get_fields("My-Header").clear
+ @headers.get_fields("My-Header").should == ["a"]
+
+ @headers.get_fields("My-Header") << "b"
+ @headers.get_fields("My-Header").should == ["a"]
+ end
+
+ it "returns nil for non-existing header entries" do
+ @headers.get_fields("My-Header").should == nil
+ @headers.get_fields("My-Other-header").should == nil
+ end
+
+ it "is case-insensitive" do
+ @headers["My-Header"] = "test"
+ @headers.get_fields("My-Header").should == ["test"]
+ @headers.get_fields("my-header").should == ["test"]
+ @headers.get_fields("MY-HEADER").should == ["test"]
+ end
+end
diff --git a/spec/ruby/library/net-http/httpheader/initialize_http_header_spec.rb b/spec/ruby/library/net-http/httpheader/initialize_http_header_spec.rb
new file mode 100644
index 0000000000..f9e6d208e5
--- /dev/null
+++ b/spec/ruby/library/net-http/httpheader/initialize_http_header_spec.rb
@@ -0,0 +1,21 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+require_relative 'fixtures/classes'
+
+describe "Net::HTTPHeader#initialize_http_header when passed Hash" do
+ before :each do
+ @headers = NetHTTPHeaderSpecs::Example.allocate
+ end
+
+ it "initializes the HTTP Header using the passed Hash" do
+ @headers.initialize_http_header("My-Header" => "test", "My-Other-Header" => "another test")
+ @headers["My-Header"].should == "test"
+ @headers["My-Other-Header"].should == "another test"
+ end
+
+ it "complains about duplicate keys when in verbose mode" do
+ -> do
+ @headers.initialize_http_header("My-Header" => "test", "my-header" => "another test")
+ end.should complain(/duplicated HTTP header/, verbose: true)
+ end
+end
diff --git a/spec/ruby/library/net-http/httpheader/key_spec.rb b/spec/ruby/library/net-http/httpheader/key_spec.rb
new file mode 100644
index 0000000000..65662591eb
--- /dev/null
+++ b/spec/ruby/library/net-http/httpheader/key_spec.rb
@@ -0,0 +1,21 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+require_relative 'fixtures/classes'
+
+describe "Net::HTTPHeader#key? when passed key" do
+ before :each do
+ @headers = NetHTTPHeaderSpecs::Example.new
+ end
+
+ it "returns true if the header entry with the passed key exists" do
+ @headers.key?("My-Header").should == false
+ @headers["My-Header"] = "test"
+ @headers.key?("My-Header").should == true
+ end
+
+ it "is case-insensitive" do
+ @headers["My-Header"] = "test"
+ @headers.key?("my-header").should == true
+ @headers.key?("MY-HEADER").should == true
+ end
+end
diff --git a/spec/ruby/library/net-http/httpheader/length_spec.rb b/spec/ruby/library/net-http/httpheader/length_spec.rb
new file mode 100644
index 0000000000..1f059719e9
--- /dev/null
+++ b/spec/ruby/library/net-http/httpheader/length_spec.rb
@@ -0,0 +1,9 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+
+describe "Net::HTTPHeader#length" do
+ it "is an alias of Net::HTTPHeader#size" do
+ Net::HTTPHeader.instance_method(:length).should ==
+ Net::HTTPHeader.instance_method(:size)
+ end
+end
diff --git a/spec/ruby/library/net-http/httpheader/main_type_spec.rb b/spec/ruby/library/net-http/httpheader/main_type_spec.rb
new file mode 100644
index 0000000000..af7d3e05a3
--- /dev/null
+++ b/spec/ruby/library/net-http/httpheader/main_type_spec.rb
@@ -0,0 +1,24 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+require_relative 'fixtures/classes'
+
+describe "Net::HTTPHeader#main_type" do
+ before :each do
+ @headers = NetHTTPHeaderSpecs::Example.new
+ end
+
+ it "returns the 'main-content-type', as per 'Content-Type' header entry" do
+ @headers["Content-Type"] = "text/html"
+ @headers.main_type.should == "text"
+
+ @headers["Content-Type"] = "application/pdf"
+ @headers.main_type.should == "application"
+
+ @headers["Content-Type"] = "text/html;charset=utf-8"
+ @headers.main_type.should == "text"
+ end
+
+ it "returns nil if the 'Content-Type' header entry does not exist" do
+ @headers.main_type.should == nil
+ end
+end
diff --git a/spec/ruby/library/net-http/httpheader/proxy_basic_auth_spec.rb b/spec/ruby/library/net-http/httpheader/proxy_basic_auth_spec.rb
new file mode 100644
index 0000000000..d9f6afc5a7
--- /dev/null
+++ b/spec/ruby/library/net-http/httpheader/proxy_basic_auth_spec.rb
@@ -0,0 +1,14 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+require_relative 'fixtures/classes'
+
+describe "Net::HTTPHeader#proxy_basic_auth when passed account, password" do
+ before :each do
+ @headers = NetHTTPHeaderSpecs::Example.new
+ end
+
+ it "sets the 'Proxy-Authorization' Header entry for basic authorization" do
+ @headers.proxy_basic_auth("rubyspec", "rocks")
+ @headers["Proxy-Authorization"].should == "Basic cnVieXNwZWM6cm9ja3M="
+ end
+end
diff --git a/spec/ruby/library/net-http/httpheader/range_length_spec.rb b/spec/ruby/library/net-http/httpheader/range_length_spec.rb
new file mode 100644
index 0000000000..34db7e6126
--- /dev/null
+++ b/spec/ruby/library/net-http/httpheader/range_length_spec.rb
@@ -0,0 +1,32 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+require_relative 'fixtures/classes'
+
+describe "Net::HTTPHeader#range_length" do
+ before :each do
+ @headers = NetHTTPHeaderSpecs::Example.new
+ end
+
+ it "returns the length of the Range represented by the 'Content-Range' header entry" do
+ @headers["Content-Range"] = "bytes 0-499/1234"
+ @headers.range_length.should.eql?(500)
+
+ @headers["Content-Range"] = "bytes 500-1233/1234"
+ @headers.range_length.should.eql?(734)
+ end
+
+ it "returns nil when there is no 'Content-Range' header entry" do
+ @headers.range_length.should == nil
+ end
+
+ it "raises a Net::HTTPHeaderSyntaxError when the 'Content-Range' has an invalid format" do
+ @headers["Content-Range"] = "invalid"
+ -> { @headers.range_length }.should.raise(Net::HTTPHeaderSyntaxError)
+
+ @headers["Content-Range"] = "bytes 123-abc"
+ -> { @headers.range_length }.should.raise(Net::HTTPHeaderSyntaxError)
+
+ @headers["Content-Range"] = "bytes abc-123"
+ -> { @headers.range_length }.should.raise(Net::HTTPHeaderSyntaxError)
+ end
+end
diff --git a/spec/ruby/library/net-http/httpheader/range_spec.rb b/spec/ruby/library/net-http/httpheader/range_spec.rb
new file mode 100644
index 0000000000..8944e2d5f2
--- /dev/null
+++ b/spec/ruby/library/net-http/httpheader/range_spec.rb
@@ -0,0 +1,50 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+require_relative 'fixtures/classes'
+
+describe "Net::HTTPHeader#range" do
+ before :each do
+ @headers = NetHTTPHeaderSpecs::Example.new
+ end
+
+ it "returns a Range object that represents the 'Range' header entry" do
+ @headers["Range"] = "bytes=0-499"
+ @headers.range.should == [0..499]
+
+ @headers["Range"] = "bytes=500-1233"
+ @headers.range.should == [500..1233]
+
+ @headers["Range"] = "bytes=10-"
+ @headers.range.should == [10..-1]
+
+ @headers["Range"] = "bytes=-10"
+ @headers.range.should == [-10..-1]
+ end
+
+ it "returns nil when there is no 'Range' header entry" do
+ @headers.range.should == nil
+ end
+
+ it "raises a Net::HTTPHeaderSyntaxError when the 'Range' has an invalid format" do
+ @headers["Range"] = "invalid"
+ -> { @headers.range }.should.raise(Net::HTTPHeaderSyntaxError)
+
+ @headers["Range"] = "bytes 123-abc"
+ -> { @headers.range }.should.raise(Net::HTTPHeaderSyntaxError)
+
+ @headers["Range"] = "bytes abc-123"
+ -> { @headers.range }.should.raise(Net::HTTPHeaderSyntaxError)
+ end
+
+ it "raises a Net::HTTPHeaderSyntaxError when the 'Range' was not specified" do
+ @headers["Range"] = "bytes=-"
+ -> { @headers.range }.should.raise(Net::HTTPHeaderSyntaxError)
+ end
+end
+
+describe "Net::HTTPHeader#range=" do
+ it "is an alias of Net::HTTPHeader#set_range" do
+ Net::HTTPHeader.instance_method(:range=).should ==
+ Net::HTTPHeader.instance_method(:set_range)
+ end
+end
diff --git a/spec/ruby/library/net-http/httpheader/set_content_type_spec.rb b/spec/ruby/library/net-http/httpheader/set_content_type_spec.rb
new file mode 100644
index 0000000000..3674061626
--- /dev/null
+++ b/spec/ruby/library/net-http/httpheader/set_content_type_spec.rb
@@ -0,0 +1,22 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+require_relative 'fixtures/classes'
+
+describe "Net::HTTPHeader#set_content_type" do
+ describe "when passed type, params" do
+ before :each do
+ @headers = NetHTTPHeaderSpecs::Example.new
+ end
+
+ it "sets the 'Content-Type' header entry based on the passed type and params" do
+ @headers.set_content_type("text/html")
+ @headers["Content-Type"].should == "text/html"
+
+ @headers.set_content_type("text/html", "charset" => "utf-8")
+ @headers["Content-Type"].should == "text/html; charset=utf-8"
+
+ @headers.set_content_type("text/html", "charset" => "utf-8", "rubyspec" => "rocks")
+ @headers["Content-Type"].split(/; /).sort.should == %w[charset=utf-8 rubyspec=rocks text/html]
+ end
+ end
+end
diff --git a/spec/ruby/library/net-http/httpheader/set_form_data_spec.rb b/spec/ruby/library/net-http/httpheader/set_form_data_spec.rb
new file mode 100644
index 0000000000..093dc100d5
--- /dev/null
+++ b/spec/ruby/library/net-http/httpheader/set_form_data_spec.rb
@@ -0,0 +1,31 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+require_relative 'fixtures/classes'
+
+describe "Net::HTTPHeader#set_form_data" do
+ before :each do
+ @headers = NetHTTPHeaderSpecs::Example.new
+ end
+
+ describe "when passed params" do
+ it "automatically set the 'Content-Type' to 'application/x-www-form-urlencoded'" do
+ @headers.set_form_data("cmd" => "search", "q" => "ruby", "max" => "50")
+ @headers["Content-Type"].should == "application/x-www-form-urlencoded"
+ end
+
+ it "sets self's body based on the passed form parameters" do
+ @headers.set_form_data("cmd" => "search", "q" => "ruby", "max" => "50")
+ @headers.body.split("&").sort.should == ["cmd=search", "max=50", "q=ruby"]
+ end
+ end
+
+ describe "when passed params, separator" do
+ it "sets self's body based on the passed form parameters and the passed separator" do
+ @headers.set_form_data({"cmd" => "search", "q" => "ruby", "max" => "50"}, "&")
+ @headers.body.split("&").sort.should == ["cmd=search", "max=50", "q=ruby"]
+
+ @headers.set_form_data({"cmd" => "search", "q" => "ruby", "max" => "50"}, ";")
+ @headers.body.split(";").sort.should == ["cmd=search", "max=50", "q=ruby"]
+ end
+ end
+end
diff --git a/spec/ruby/library/net-http/httpheader/set_range_spec.rb b/spec/ruby/library/net-http/httpheader/set_range_spec.rb
new file mode 100644
index 0000000000..d48ed1897a
--- /dev/null
+++ b/spec/ruby/library/net-http/httpheader/set_range_spec.rb
@@ -0,0 +1,93 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+require_relative 'fixtures/classes'
+
+describe "Net::HTTPHeader#set_range" do
+ before :each do
+ @headers = NetHTTPHeaderSpecs::Example.new
+ end
+
+ describe "when passed nil" do
+ it "returns nil" do
+ @headers.set_range(nil).should == nil
+ end
+
+ it "deletes the 'Range' header entry" do
+ @headers["Range"] = "bytes 0-499/1234"
+ @headers.set_range(nil)
+ @headers["Range"].should == nil
+ end
+ end
+
+ describe "when passed Numeric" do
+ it "sets the 'Range' header entry based on the passed Numeric" do
+ @headers.set_range(10)
+ @headers["Range"].should == "bytes=0-9"
+
+ @headers.set_range(-10)
+ @headers["Range"].should == "bytes=-10"
+
+ @headers.set_range(10.9)
+ @headers["Range"].should == "bytes=0-9"
+ end
+ end
+
+ describe "when passed Range" do
+ it "sets the 'Range' header entry based on the passed Range" do
+ @headers.set_range(10..200)
+ @headers["Range"].should == "bytes=10-200"
+
+ @headers.set_range(1..5)
+ @headers["Range"].should == "bytes=1-5"
+
+ @headers.set_range(1...5)
+ @headers["Range"].should == "bytes=1-4"
+
+ @headers.set_range(234..567)
+ @headers["Range"].should == "bytes=234-567"
+
+ @headers.set_range(-5..-1)
+ @headers["Range"].should == "bytes=-5"
+
+ @headers.set_range(1..-1)
+ @headers["Range"].should == "bytes=1-"
+ end
+
+ it "raises a Net::HTTPHeaderSyntaxError when the first Range element is negative" do
+ -> { @headers.set_range(-10..5) }.should.raise(Net::HTTPHeaderSyntaxError)
+ end
+
+ it "raises a Net::HTTPHeaderSyntaxError when the last Range element is negative" do
+ -> { @headers.set_range(10..-5) }.should.raise(Net::HTTPHeaderSyntaxError)
+ end
+
+ it "raises a Net::HTTPHeaderSyntaxError when the last Range element is smaller than the first" do
+ -> { @headers.set_range(10..5) }.should.raise(Net::HTTPHeaderSyntaxError)
+ end
+ end
+
+ describe "when passed start, end" do
+ it "sets the 'Range' header entry based on the passed start and length values" do
+ @headers.set_range(10, 200)
+ @headers["Range"].should == "bytes=10-209"
+
+ @headers.set_range(1, 5)
+ @headers["Range"].should == "bytes=1-5"
+
+ @headers.set_range(234, 567)
+ @headers["Range"].should == "bytes=234-800"
+ end
+
+ it "raises a Net::HTTPHeaderSyntaxError when start is negative" do
+ -> { @headers.set_range(-10, 5) }.should.raise(Net::HTTPHeaderSyntaxError)
+ end
+
+ it "raises a Net::HTTPHeaderSyntaxError when start + length is negative" do
+ -> { @headers.set_range(10, -15) }.should.raise(Net::HTTPHeaderSyntaxError)
+ end
+
+ it "raises a Net::HTTPHeaderSyntaxError when length is negative" do
+ -> { @headers.set_range(10, -4) }.should.raise(Net::HTTPHeaderSyntaxError)
+ end
+ end
+end
diff --git a/spec/ruby/library/net-http/httpheader/size_spec.rb b/spec/ruby/library/net-http/httpheader/size_spec.rb
new file mode 100644
index 0000000000..f84a0fb5ab
--- /dev/null
+++ b/spec/ruby/library/net-http/httpheader/size_spec.rb
@@ -0,0 +1,22 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+require_relative 'fixtures/classes'
+
+describe "Net::HTTPHeader#size" do
+ before :each do
+ @headers = NetHTTPHeaderSpecs::Example.new
+ end
+
+ it "returns the number of header entries in self" do
+ @headers.size.should.eql?(0)
+
+ @headers["a"] = "b"
+ @headers.size.should.eql?(1)
+
+ @headers["b"] = "b"
+ @headers.size.should.eql?(2)
+
+ @headers["c"] = "c"
+ @headers.size.should.eql?(3)
+ end
+end
diff --git a/spec/ruby/library/net-http/httpheader/sub_type_spec.rb b/spec/ruby/library/net-http/httpheader/sub_type_spec.rb
new file mode 100644
index 0000000000..9e7d2a5368
--- /dev/null
+++ b/spec/ruby/library/net-http/httpheader/sub_type_spec.rb
@@ -0,0 +1,32 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+require_relative 'fixtures/classes'
+
+describe "Net::HTTPHeader#sub_type" do
+ before :each do
+ @headers = NetHTTPHeaderSpecs::Example.new
+ end
+
+ it "returns the 'sub-content-type', as per 'Content-Type' header entry" do
+ @headers["Content-Type"] = "text/html"
+ @headers.sub_type.should == "html"
+
+ @headers["Content-Type"] = "application/pdf"
+ @headers.sub_type.should == "pdf"
+
+ @headers["Content-Type"] = "text/html;charset=utf-8"
+ @headers.sub_type.should == "html"
+ end
+
+ it "returns nil if no 'sub-content-type' is set" do
+ @headers["Content-Type"] = "text"
+ @headers.sub_type.should == nil
+
+ @headers["Content-Type"] = "text;charset=utf-8"
+ @headers.sub_type.should == nil
+ end
+
+ it "returns nil if the 'Content-Type' header entry does not exist" do
+ @headers.sub_type.should == nil
+ end
+end
diff --git a/spec/ruby/library/net-http/httpheader/to_hash_spec.rb b/spec/ruby/library/net-http/httpheader/to_hash_spec.rb
new file mode 100644
index 0000000000..e245c20d4c
--- /dev/null
+++ b/spec/ruby/library/net-http/httpheader/to_hash_spec.rb
@@ -0,0 +1,25 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+require_relative 'fixtures/classes'
+
+describe "Net::HTTPHeader#to_hash" do
+ before :each do
+ @headers = NetHTTPHeaderSpecs::Example.new
+ end
+
+ it "returns a Hash representing all Header entries (keys in lower case, values as arrays)" do
+ @headers.to_hash.should == {}
+
+ @headers["My-Header"] = "test"
+ @headers.to_hash.should == { "my-header" => ["test"] }
+
+ @headers.add_field("My-Header", "another test")
+ @headers.to_hash.should == { "my-header" => ["test", "another test"] }
+ end
+
+ it "does not allow modifying the headers from the returned hash" do
+ @headers.to_hash["my-header"] = ["test"]
+ @headers.to_hash.should == {}
+ @headers.key?("my-header").should == false
+ end
+end
diff --git a/spec/ruby/library/net-http/httpheader/type_params_spec.rb b/spec/ruby/library/net-http/httpheader/type_params_spec.rb
new file mode 100644
index 0000000000..ac97e2b48c
--- /dev/null
+++ b/spec/ruby/library/net-http/httpheader/type_params_spec.rb
@@ -0,0 +1,24 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+require_relative 'fixtures/classes'
+
+describe "Net::HTTPHeader#type_params" do
+ before :each do
+ @headers = NetHTTPHeaderSpecs::Example.new
+ end
+
+ it "returns additional 'Content-Type' information as a Hash" do
+ @headers["Content-Type"] = "text/html;charset=utf-8"
+ @headers.type_params.should == {"charset" => "utf-8"}
+
+ @headers["Content-Type"] = "text/html; charset=utf-8; rubyspec=rocks"
+ @headers.type_params.should == {"charset" => "utf-8", "rubyspec" => "rocks"}
+ end
+
+ it "returns an empty Hash when no additional 'Content-Type' information is set" do
+ @headers.type_params.should == {}
+
+ @headers["Content-Type"] = "text/html"
+ @headers.type_params.should == {}
+ end
+end
diff --git a/spec/ruby/library/net-http/httprequest/initialize_spec.rb b/spec/ruby/library/net-http/httprequest/initialize_spec.rb
new file mode 100644
index 0000000000..1229986bef
--- /dev/null
+++ b/spec/ruby/library/net-http/httprequest/initialize_spec.rb
@@ -0,0 +1,45 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+
+module NetHTTPRequestSpecs
+ class TestRequest < Net::HTTPRequest
+ METHOD = "TEST"
+ REQUEST_HAS_BODY = false
+ RESPONSE_HAS_BODY = true
+ end
+end
+
+describe "Net::HTTPRequest#initialize" do
+ before :each do
+ @req = NetHTTPRequestSpecs::TestRequest.allocate
+ end
+
+ it "uses the METHOD constants to set the request method" do
+ @req.send(:initialize, "/some/path")
+ @req.method.should == "TEST"
+ end
+
+ it "uses the REQUEST_HAS_BODY to set whether the Request has a body or not" do
+ @req.send(:initialize, "/some/path")
+ @req.request_body_permitted?.should == false
+ end
+
+ it "uses the RESPONSE_HAS_BODY to set whether the Response can have a body or not" do
+ @req.send(:initialize, "/some/path")
+ @req.response_body_permitted?.should == true
+ end
+
+ describe "when passed path" do
+ it "sets self's path to the passed path" do
+ @req.send(:initialize, "/some/path")
+ @req.path.should == "/some/path"
+ end
+ end
+
+ describe "when passed path, headers" do
+ it "uses the passed headers Hash to initialize self's header entries" do
+ @req.send(:initialize, "/some/path", "Content-Type" => "text/html")
+ @req["Content-Type"].should == "text/html"
+ end
+ end
+end
diff --git a/spec/ruby/library/net-http/httpresponse/body_permitted_spec.rb b/spec/ruby/library/net-http/httpresponse/body_permitted_spec.rb
new file mode 100644
index 0000000000..68965de4a1
--- /dev/null
+++ b/spec/ruby/library/net-http/httpresponse/body_permitted_spec.rb
@@ -0,0 +1,13 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+
+describe "Net::HTTPResponse.body_permitted?" do
+ it "returns true if this response type can have a response body" do
+ Net::HTTPUnknownResponse.should.body_permitted?
+ Net::HTTPInformation.should_not.body_permitted?
+ Net::HTTPSuccess.should.body_permitted?
+ Net::HTTPRedirection.should.body_permitted?
+ Net::HTTPClientError.should.body_permitted?
+ Net::HTTPServerError.should.body_permitted?
+ end
+end
diff --git a/spec/ruby/library/net-http/httpresponse/body_spec.rb b/spec/ruby/library/net-http/httpresponse/body_spec.rb
new file mode 100644
index 0000000000..5b00913687
--- /dev/null
+++ b/spec/ruby/library/net-http/httpresponse/body_spec.rb
@@ -0,0 +1,22 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+require 'stringio'
+
+describe "Net::HTTPResponse#body" do
+ before :each do
+ @res = Net::HTTPUnknownResponse.new("1.0", "???", "test response")
+ @socket = Net::BufferedIO.new(StringIO.new("test body"))
+ end
+
+ it "returns the read body" do
+ @res.reading_body(@socket, true) do
+ @res.body.should == "test body"
+ end
+ end
+
+ it "returns the previously read body if called a second time" do
+ @res.reading_body(@socket, true) do
+ @res.body.should.equal?(@res.body)
+ end
+ end
+end
diff --git a/spec/ruby/library/net-http/httpresponse/code_spec.rb b/spec/ruby/library/net-http/httpresponse/code_spec.rb
new file mode 100644
index 0000000000..699062ad97
--- /dev/null
+++ b/spec/ruby/library/net-http/httpresponse/code_spec.rb
@@ -0,0 +1,24 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+
+describe "Net::HTTPResponse#code" do
+ it "returns the result code string" do
+ res = Net::HTTPUnknownResponse.new("1.0", "???", "test response")
+ res.code.should == "???"
+
+ res = Net::HTTPInformation.new("1.0", "1xx", "test response")
+ res.code.should == "1xx"
+
+ res = Net::HTTPSuccess.new("1.0", "2xx", "test response")
+ res.code.should == "2xx"
+
+ res = Net::HTTPRedirection.new("1.0", "3xx", "test response")
+ res.code.should == "3xx"
+
+ res = Net::HTTPClientError.new("1.0", "4xx", "test response")
+ res.code.should == "4xx"
+
+ res = Net::HTTPServerError.new("1.0", "5xx", "test response")
+ res.code.should == "5xx"
+ end
+end
diff --git a/spec/ruby/library/net-http/httpresponse/code_type_spec.rb b/spec/ruby/library/net-http/httpresponse/code_type_spec.rb
new file mode 100644
index 0000000000..beb661cbbe
--- /dev/null
+++ b/spec/ruby/library/net-http/httpresponse/code_type_spec.rb
@@ -0,0 +1,24 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+
+describe "Net::HTTPResponse#code_type" do
+ it "returns self's class" do
+ res = Net::HTTPUnknownResponse.new("1.0", "???", "test response")
+ res.code_type.should == Net::HTTPUnknownResponse
+
+ res = Net::HTTPInformation.new("1.0", "1xx", "test response")
+ res.code_type.should == Net::HTTPInformation
+
+ res = Net::HTTPSuccess.new("1.0", "2xx", "test response")
+ res.code_type.should == Net::HTTPSuccess
+
+ res = Net::HTTPRedirection.new("1.0", "3xx", "test response")
+ res.code_type.should == Net::HTTPRedirection
+
+ res = Net::HTTPClientError.new("1.0", "4xx", "test response")
+ res.code_type.should == Net::HTTPClientError
+
+ res = Net::HTTPServerError.new("1.0", "5xx", "test response")
+ res.code_type.should == Net::HTTPServerError
+ end
+end
diff --git a/spec/ruby/library/net-http/httpresponse/entity_spec.rb b/spec/ruby/library/net-http/httpresponse/entity_spec.rb
new file mode 100644
index 0000000000..d2201db37b
--- /dev/null
+++ b/spec/ruby/library/net-http/httpresponse/entity_spec.rb
@@ -0,0 +1,9 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+
+describe "Net::HTTPResponse#entity" do
+ it "is an alias of Net::HTTPResponse#body" do
+ Net::HTTPResponse.instance_method(:entity).should ==
+ Net::HTTPResponse.instance_method(:body)
+ end
+end
diff --git a/spec/ruby/library/net-http/httpresponse/error_spec.rb b/spec/ruby/library/net-http/httpresponse/error_spec.rb
new file mode 100644
index 0000000000..e194df95af
--- /dev/null
+++ b/spec/ruby/library/net-http/httpresponse/error_spec.rb
@@ -0,0 +1,24 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+
+describe "Net::HTTPResponse#error!" do
+ it "raises self's class 'EXCEPTION_TYPE' Exception" do
+ res = Net::HTTPUnknownResponse.new("1.0", "???", "test response")
+ -> { res.error! }.should.raise(Net::HTTPError)
+
+ res = Net::HTTPInformation.new("1.0", "1xx", "test response")
+ -> { res.error! }.should.raise(Net::HTTPError)
+
+ res = Net::HTTPSuccess.new("1.0", "2xx", "test response")
+ -> { res.error! }.should.raise(Net::HTTPError)
+
+ res = Net::HTTPRedirection.new("1.0", "3xx", "test response")
+ -> { res.error! }.should.raise(Net::HTTPRetriableError)
+
+ res = Net::HTTPClientError.new("1.0", "4xx", "test response")
+ -> { res.error! }.should.raise(Net::HTTPClientException)
+
+ res = Net::HTTPServerError.new("1.0", "5xx", "test response")
+ -> { res.error! }.should.raise(Net::HTTPFatalError)
+ end
+end
diff --git a/spec/ruby/library/net-http/httpresponse/error_type_spec.rb b/spec/ruby/library/net-http/httpresponse/error_type_spec.rb
new file mode 100644
index 0000000000..3969621a5e
--- /dev/null
+++ b/spec/ruby/library/net-http/httpresponse/error_type_spec.rb
@@ -0,0 +1,24 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+
+describe "Net::HTTPResponse#error_type" do
+ it "returns self's class 'EXCEPTION_TYPE' constant" do
+ res = Net::HTTPUnknownResponse.new("1.0", "???", "test response")
+ res.error_type.should == Net::HTTPError
+
+ res = Net::HTTPInformation.new("1.0", "1xx", "test response")
+ res.error_type.should == Net::HTTPError
+
+ res = Net::HTTPSuccess.new("1.0", "2xx", "test response")
+ res.error_type.should == Net::HTTPError
+
+ res = Net::HTTPRedirection.new("1.0", "3xx", "test response")
+ res.error_type.should == Net::HTTPRetriableError
+
+ res = Net::HTTPClientError.new("1.0", "4xx", "test response")
+ res.error_type.should == Net::HTTPClientException
+
+ res = Net::HTTPServerError.new("1.0", "5xx", "test response")
+ res.error_type.should == Net::HTTPFatalError
+ end
+end
diff --git a/spec/ruby/library/net-http/httpresponse/exception_type_spec.rb b/spec/ruby/library/net-http/httpresponse/exception_type_spec.rb
new file mode 100644
index 0000000000..dd2761a744
--- /dev/null
+++ b/spec/ruby/library/net-http/httpresponse/exception_type_spec.rb
@@ -0,0 +1,13 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+
+describe "Net::HTTPResponse.exception_type" do
+ it "returns self's 'EXCEPTION_TYPE' constant" do
+ Net::HTTPUnknownResponse.exception_type.should == Net::HTTPError
+ Net::HTTPInformation.exception_type.should == Net::HTTPError
+ Net::HTTPSuccess.exception_type.should == Net::HTTPError
+ Net::HTTPRedirection.exception_type.should == Net::HTTPRetriableError
+ Net::HTTPClientError.exception_type.should == Net::HTTPClientException
+ Net::HTTPServerError.exception_type.should == Net::HTTPFatalError
+ end
+end
diff --git a/spec/ruby/library/net-http/httpresponse/header_spec.rb b/spec/ruby/library/net-http/httpresponse/header_spec.rb
new file mode 100644
index 0000000000..3ddadfb8e4
--- /dev/null
+++ b/spec/ruby/library/net-http/httpresponse/header_spec.rb
@@ -0,0 +1,9 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+
+describe "Net::HTTPResponse#header" do
+ it "returns self" do
+ res = Net::HTTPUnknownResponse.new("1.0", "???", "test response")
+ res.response.should.equal?(res)
+ end
+end
diff --git a/spec/ruby/library/net-http/httpresponse/http_version_spec.rb b/spec/ruby/library/net-http/httpresponse/http_version_spec.rb
new file mode 100644
index 0000000000..a3e413a360
--- /dev/null
+++ b/spec/ruby/library/net-http/httpresponse/http_version_spec.rb
@@ -0,0 +1,12 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+
+describe "Net::HTTPResponse#http_version" do
+ it "returns self's http version" do
+ res = Net::HTTPUnknownResponse.new("1.0", "???", "test response")
+ res.http_version.should == "1.0"
+
+ res = Net::HTTPUnknownResponse.new("1.1", "???", "test response")
+ res.http_version.should == "1.1"
+ end
+end
diff --git a/spec/ruby/library/net-http/httpresponse/initialize_spec.rb b/spec/ruby/library/net-http/httpresponse/initialize_spec.rb
new file mode 100644
index 0000000000..673c11a245
--- /dev/null
+++ b/spec/ruby/library/net-http/httpresponse/initialize_spec.rb
@@ -0,0 +1,11 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+
+describe "Net::HTTPResponse#initialize when passed http_version, response_code, response_message" do
+ it "sets self http_version, response_code and response_message to the passed values" do
+ res = Net::HTTPUnknownResponse.new("1.0", "???", "test response")
+ res.http_version.should == "1.0"
+ res.code.should == "???"
+ res.message.should == "test response"
+ end
+end
diff --git a/spec/ruby/library/net-http/httpresponse/inspect_spec.rb b/spec/ruby/library/net-http/httpresponse/inspect_spec.rb
new file mode 100644
index 0000000000..43071ec8cd
--- /dev/null
+++ b/spec/ruby/library/net-http/httpresponse/inspect_spec.rb
@@ -0,0 +1,15 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+require "stringio"
+
+describe "Net::HTTPResponse#inspect" do
+ it "returns a String representation of self" do
+ res = Net::HTTPUnknownResponse.new("1.0", "???", "test response")
+ res.inspect.should == "#<Net::HTTPUnknownResponse ??? test response readbody=false>"
+
+ res = Net::HTTPUnknownResponse.new("1.0", "???", "test response")
+ socket = Net::BufferedIO.new(StringIO.new("test body"))
+ res.reading_body(socket, true) {}
+ res.inspect.should == "#<Net::HTTPUnknownResponse ??? test response readbody=true>"
+ end
+end
diff --git a/spec/ruby/library/net-http/httpresponse/message_spec.rb b/spec/ruby/library/net-http/httpresponse/message_spec.rb
new file mode 100644
index 0000000000..5ba73bb449
--- /dev/null
+++ b/spec/ruby/library/net-http/httpresponse/message_spec.rb
@@ -0,0 +1,9 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+
+describe "Net::HTTPResponse#message" do
+ it "returns self's response message" do
+ res = Net::HTTPUnknownResponse.new("1.0", "???", "test response")
+ res.message.should == "test response"
+ end
+end
diff --git a/spec/ruby/library/net-http/httpresponse/msg_spec.rb b/spec/ruby/library/net-http/httpresponse/msg_spec.rb
new file mode 100644
index 0000000000..04f5836d7a
--- /dev/null
+++ b/spec/ruby/library/net-http/httpresponse/msg_spec.rb
@@ -0,0 +1,9 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+
+describe "Net::HTTPResponse#msg" do
+ it "returns self's response message" do
+ res = Net::HTTPUnknownResponse.new("1.0", "???", "test response")
+ res.message.should == "test response"
+ end
+end
diff --git a/spec/ruby/library/net-http/httpresponse/read_body_spec.rb b/spec/ruby/library/net-http/httpresponse/read_body_spec.rb
new file mode 100644
index 0000000000..d8b2418624
--- /dev/null
+++ b/spec/ruby/library/net-http/httpresponse/read_body_spec.rb
@@ -0,0 +1,86 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+require 'stringio'
+
+describe "Net::HTTPResponse#read_body" do
+ before :each do
+ @res = Net::HTTPUnknownResponse.new("1.0", "???", "test response")
+ @socket = Net::BufferedIO.new(StringIO.new("test body"))
+ end
+
+ describe "when passed no arguments" do
+ it "returns the read body" do
+ @res.reading_body(@socket, true) do
+ @res.read_body.should == "test body"
+ end
+ end
+
+ it "returns the previously read body if called a second time" do
+ @res.reading_body(@socket, true) do
+ @res.read_body.should.equal?(@res.read_body)
+ end
+ end
+ end
+
+ describe "when passed a buffer" do
+ it "reads the body to the passed buffer" do
+ @res.reading_body(@socket, true) do
+ buffer = +""
+ @res.read_body(buffer)
+ buffer.should == "test body"
+ end
+ end
+
+ it "returns the passed buffer" do
+ @res.reading_body(@socket, true) do
+ buffer = +""
+ @res.read_body(buffer).should.equal?(buffer)
+ end
+ end
+
+ it "raises an IOError if called a second time" do
+ @res.reading_body(@socket, true) do
+ @res.read_body(+"")
+ -> { @res.read_body(+"") }.should.raise(IOError)
+ end
+ end
+ end
+
+ describe "when passed a block" do
+ it "reads the body and yields it to the passed block (in chunks)" do
+ @res.reading_body(@socket, true) do
+ yielded = false
+
+ buffer = +""
+ @res.read_body do |body|
+ yielded = true
+ buffer << body
+ end
+
+ yielded.should == true
+ buffer.should == "test body"
+ end
+ end
+
+ it "returns the ReadAdapter" do
+ @res.reading_body(@socket, true) do
+ @res.read_body { nil }.should.is_a?(Net::ReadAdapter)
+ end
+ end
+
+ it "raises an IOError if called a second time" do
+ @res.reading_body(@socket, true) do
+ @res.read_body {}
+ -> { @res.read_body {} }.should.raise(IOError)
+ end
+ end
+ end
+
+ describe "when passed buffer and block" do
+ it "raises an ArgumentError" do
+ @res.reading_body(@socket, true) do
+ -> { @res.read_body(+"") {} }.should.raise(ArgumentError)
+ end
+ end
+ end
+end
diff --git a/spec/ruby/library/net-http/httpresponse/read_header_spec.rb b/spec/ruby/library/net-http/httpresponse/read_header_spec.rb
new file mode 100644
index 0000000000..70ce988502
--- /dev/null
+++ b/spec/ruby/library/net-http/httpresponse/read_header_spec.rb
@@ -0,0 +1,9 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+
+describe "Net::HTTPResponse#read_header" do
+ it "returns self" do
+ res = Net::HTTPUnknownResponse.new("1.0", "???", "test response")
+ res.response.should.equal?(res)
+ end
+end
diff --git a/spec/ruby/library/net-http/httpresponse/read_new_spec.rb b/spec/ruby/library/net-http/httpresponse/read_new_spec.rb
new file mode 100644
index 0000000000..3795e29d83
--- /dev/null
+++ b/spec/ruby/library/net-http/httpresponse/read_new_spec.rb
@@ -0,0 +1,23 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+require 'stringio'
+
+describe "Net::HTTPResponse.read_new" do
+ it "creates a HTTPResponse object based on the response read from the passed socket" do
+ socket = Net::BufferedIO.new(StringIO.new(<<EOS))
+HTTP/1.1 200 OK
+Content-Type: text/html; charset=utf-8
+
+test-body
+EOS
+ response = Net::HTTPResponse.read_new(socket)
+
+ response.should.is_a?(Net::HTTPOK)
+ response.code.should == "200"
+ response["Content-Type"].should == "text/html; charset=utf-8"
+
+ response.reading_body(socket, true) do
+ response.body.should == "test-body\n"
+ end
+ end
+end
diff --git a/spec/ruby/library/net-http/httpresponse/reading_body_spec.rb b/spec/ruby/library/net-http/httpresponse/reading_body_spec.rb
new file mode 100644
index 0000000000..a3671d6eb5
--- /dev/null
+++ b/spec/ruby/library/net-http/httpresponse/reading_body_spec.rb
@@ -0,0 +1,58 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+require "stringio"
+
+describe "Net::HTTPResponse#reading_body" do
+ before :each do
+ @res = Net::HTTPUnknownResponse.new("1.0", "???", "test response")
+ @socket = Net::BufferedIO.new(StringIO.new("test body"))
+ end
+
+ describe "when body_allowed is true" do
+ it "reads and returns the response body for self from the passed socket" do
+ @res.reading_body(@socket, true) {}.should == "test body"
+ @res.body.should == "test body"
+ end
+
+ it "yields the passed block before reading the body" do
+ yielded = false
+
+ @res.reading_body(@socket, true) do
+ @res.inspect.should == "#<Net::HTTPUnknownResponse ??? test response readbody=false>"
+ yielded = true
+ end
+
+ yielded.should == true
+ end
+
+ describe "but the response type is not allowed to have a body" do
+ before :each do
+ @res = Net::HTTPInformation.new("1.0", "???", "test response")
+ end
+
+ it "returns nil" do
+ @res.reading_body(@socket, false) {}.should == nil
+ @res.body.should == nil
+ end
+
+ it "yields the passed block" do
+ yielded = false
+ @res.reading_body(@socket, true) { yielded = true }
+ yielded.should == true
+ end
+ end
+ end
+
+ describe "when body_allowed is false" do
+ it "returns nil" do
+ @res.reading_body(@socket, false) {}.should == nil
+ @res.body.should == nil
+ end
+
+ it "yields the passed block" do
+ yielded = false
+ @res.reading_body(@socket, true) { yielded = true }
+ yielded.should == true
+ end
+ end
+end
diff --git a/spec/ruby/library/net-http/httpresponse/response_spec.rb b/spec/ruby/library/net-http/httpresponse/response_spec.rb
new file mode 100644
index 0000000000..440c33c168
--- /dev/null
+++ b/spec/ruby/library/net-http/httpresponse/response_spec.rb
@@ -0,0 +1,9 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+
+describe "Net::HTTPResponse#response" do
+ it "returns self" do
+ res = Net::HTTPUnknownResponse.new("1.0", "???", "test response")
+ res.response.should.equal?(res)
+ end
+end
diff --git a/spec/ruby/library/net-http/httpresponse/value_spec.rb b/spec/ruby/library/net-http/httpresponse/value_spec.rb
new file mode 100644
index 0000000000..e32d37500a
--- /dev/null
+++ b/spec/ruby/library/net-http/httpresponse/value_spec.rb
@@ -0,0 +1,24 @@
+require_relative '../../../spec_helper'
+require 'net/http'
+
+describe "Net::HTTPResponse#value" do
+ it "raises an HTTP error for non 2xx HTTP Responses" do
+ res = Net::HTTPUnknownResponse.new("1.0", "???", "test response")
+ -> { res.value }.should.raise(Net::HTTPError)
+
+ res = Net::HTTPInformation.new("1.0", "1xx", "test response")
+ -> { res.value }.should.raise(Net::HTTPError)
+
+ res = Net::HTTPSuccess.new("1.0", "2xx", "test response")
+ -> { res.value }.should_not.raise(Net::HTTPError)
+
+ res = Net::HTTPRedirection.new("1.0", "3xx", "test response")
+ -> { res.value }.should.raise(Net::HTTPRetriableError)
+
+ res = Net::HTTPClientError.new("1.0", "4xx", "test response")
+ -> { res.value }.should.raise(Net::HTTPClientException)
+
+ res = Net::HTTPServerError.new("1.0", "5xx", "test response")
+ -> { res.value }.should.raise(Net::HTTPFatalError)
+ end
+end
diff --git a/spec/ruby/library/net/FTPError_spec.rb b/spec/ruby/library/net/FTPError_spec.rb
deleted file mode 100644
index 7cc06f681a..0000000000
--- a/spec/ruby/library/net/FTPError_spec.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require 'net/ftp'
-
-describe "Net::FTPError" do
- it "is an Exception" do
- Net::FTPError.should < Exception
- end
-end
diff --git a/spec/ruby/library/net/FTPPermError_spec.rb b/spec/ruby/library/net/FTPPermError_spec.rb
deleted file mode 100644
index d9a7189468..0000000000
--- a/spec/ruby/library/net/FTPPermError_spec.rb
+++ /dev/null
@@ -1,12 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require 'net/ftp'
-
-describe "Net::FTPPermError" do
- it "is an Exception" do
- Net::FTPPermError.should < Exception
- end
-
- it "is a subclass of Net::FTPError" do
- Net::FTPPermError.should < Net::FTPError
- end
-end
diff --git a/spec/ruby/library/net/FTPProtoError_spec.rb b/spec/ruby/library/net/FTPProtoError_spec.rb
deleted file mode 100644
index 445ba1cd2f..0000000000
--- a/spec/ruby/library/net/FTPProtoError_spec.rb
+++ /dev/null
@@ -1,12 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require 'net/ftp'
-
-describe "Net::FTPProtoError" do
- it "is an Exception" do
- Net::FTPProtoError.should < Exception
- end
-
- it "is a subclass of Net::FTPError" do
- Net::FTPPermError.should < Net::FTPError
- end
-end
diff --git a/spec/ruby/library/net/FTPReplyError_spec.rb b/spec/ruby/library/net/FTPReplyError_spec.rb
deleted file mode 100644
index b697f0b95a..0000000000
--- a/spec/ruby/library/net/FTPReplyError_spec.rb
+++ /dev/null
@@ -1,12 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require 'net/ftp'
-
-describe "Net::FTPReplyError" do
- it "is an Exception" do
- Net::FTPReplyError.should < Exception
- end
-
- it "is a subclass of Net::FTPError" do
- Net::FTPPermError.should < Net::FTPError
- end
-end
diff --git a/spec/ruby/library/net/FTPTempError_spec.rb b/spec/ruby/library/net/FTPTempError_spec.rb
deleted file mode 100644
index 8d74d371da..0000000000
--- a/spec/ruby/library/net/FTPTempError_spec.rb
+++ /dev/null
@@ -1,12 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require 'net/ftp'
-
-describe "Net::FTPTempError" do
- it "is an Exception" do
- Net::FTPTempError.should < Exception
- end
-
- it "is a subclass of Net::FTPError" do
- Net::FTPPermError.should < Net::FTPError
- end
-end
diff --git a/spec/ruby/library/net/ftp/abort_spec.rb b/spec/ruby/library/net/ftp/abort_spec.rb
deleted file mode 100644
index ea47eaf9bf..0000000000
--- a/spec/ruby/library/net/ftp/abort_spec.rb
+++ /dev/null
@@ -1,62 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../spec_helper', __FILE__)
-require File.expand_path('../fixtures/server', __FILE__)
-
-describe "Net::FTP#abort" do
- before :each do
- @server = NetFTPSpecs::DummyFTP.new
- @server.serve_once
-
- @ftp = Net::FTP.new
- @ftp.connect(@server.hostname, @server.server_port)
- end
-
- after :each do
- @ftp.quit rescue nil
- @ftp.close
- @server.stop
- end
-
- it "sends the ABOR command to the server" do
- lambda { @ftp.abort }.should_not raise_error
- end
-
- it "ignores the response" do
- @ftp.abort
- @ftp.last_response.should == "220 Dummy FTP Server ready!\n"
- end
-
- it "returns the full response" do
- @ftp.abort.should == "226 Closing data connection. (ABOR)\n"
- end
-
- it "does not raise any error when the response code is 225" do
- @server.should_receive(:abor).and_respond("225 Data connection open; no transfer in progress.")
- lambda { @ftp.abort }.should_not raise_error
- end
-
- it "does not raise any error when the response code is 226" do
- @server.should_receive(:abor).and_respond("226 Closing data connection.")
- lambda { @ftp.abort }.should_not raise_error
- end
-
- it "raises a Net::FTPProtoError when the response code is 500" do
- @server.should_receive(:abor).and_respond("500 Syntax error, command unrecognized.")
- lambda { @ftp.abort }.should raise_error(Net::FTPProtoError)
- end
-
- it "raises a Net::FTPProtoError when the response code is 501" do
- @server.should_receive(:abor).and_respond("501 Syntax error in parameters or arguments.")
- lambda { @ftp.abort }.should raise_error(Net::FTPProtoError)
- end
-
- it "raises a Net::FTPProtoError when the response code is 502" do
- @server.should_receive(:abor).and_respond("502 Command not implemented.")
- lambda { @ftp.abort }.should raise_error(Net::FTPProtoError)
- end
-
- it "raises a Net::FTPProtoError when the response code is 421" do
- @server.should_receive(:abor).and_respond("421 Service not available, closing control connection.")
- lambda { @ftp.abort }.should raise_error(Net::FTPProtoError)
- end
-end
diff --git a/spec/ruby/library/net/ftp/acct_spec.rb b/spec/ruby/library/net/ftp/acct_spec.rb
deleted file mode 100644
index e60c6b3088..0000000000
--- a/spec/ruby/library/net/ftp/acct_spec.rb
+++ /dev/null
@@ -1,58 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../spec_helper', __FILE__)
-require File.expand_path('../fixtures/server', __FILE__)
-
-describe "Net::FTP#acct" do
- before :each do
- @server = NetFTPSpecs::DummyFTP.new
- @server.serve_once
-
- @ftp = Net::FTP.new
- @ftp.connect(@server.hostname, @server.server_port)
- end
-
- after :each do
- @ftp.quit rescue nil
- @ftp.close
- @server.stop
- end
-
- it "writes the ACCT command to the server" do
- @ftp.acct("my_account")
- @ftp.last_response.should == "230 User 'my_account' logged in, proceed. (ACCT)\n"
- end
-
- it "returns nil" do
- @ftp.acct("my_account").should == nil
- end
-
- it "does not raise any error when the response code is 230" do
- @server.should_receive(:acct).and_respond("230 User logged in, proceed.")
- lambda { @ftp.acct("my_account") }.should_not raise_error
- end
-
- it "raises a Net::FTPPermError when the response code is 530" do
- @server.should_receive(:acct).and_respond("530 Not logged in.")
- lambda { @ftp.acct("my_account") }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPPermError when the response code is 500" do
- @server.should_receive(:acct).and_respond("500 Syntax error, command unrecognized.")
- lambda { @ftp.acct("my_account") }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPPermError when the response code is 501" do
- @server.should_receive(:acct).and_respond("501 Syntax error in parameters or arguments.")
- lambda { @ftp.acct("my_account") }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPPermError when the response code is 503" do
- @server.should_receive(:acct).and_respond("503 Bad sequence of commands.")
- lambda { @ftp.acct("my_account") }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPTempError when the response code is 421" do
- @server.should_receive(:acct).and_respond("421 Service not available, closing control connection.")
- lambda { @ftp.acct("my_account") }.should raise_error(Net::FTPTempError)
- end
-end
diff --git a/spec/ruby/library/net/ftp/binary_spec.rb b/spec/ruby/library/net/ftp/binary_spec.rb
deleted file mode 100644
index 6f1a1ab8ba..0000000000
--- a/spec/ruby/library/net/ftp/binary_spec.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../spec_helper', __FILE__)
-
-describe "Net::FTP#binary" do
- it "returns true when self is in binary mode" do
- ftp = Net::FTP.new
- ftp.binary.should be_true
-
- ftp.binary = false
- ftp.binary.should be_false
- end
-end
-
-describe "Net::FTP#binary=" do
- it "sets self to binary mode when passed true" do
- ftp = Net::FTP.new
-
- ftp.binary = true
- ftp.binary.should be_true
-
- ftp.binary = false
- ftp.binary.should be_false
- end
-end
diff --git a/spec/ruby/library/net/ftp/chdir_spec.rb b/spec/ruby/library/net/ftp/chdir_spec.rb
deleted file mode 100644
index f6cfac5b66..0000000000
--- a/spec/ruby/library/net/ftp/chdir_spec.rb
+++ /dev/null
@@ -1,99 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../spec_helper', __FILE__)
-require File.expand_path('../fixtures/server', __FILE__)
-
-describe "Net::FTP#chdir" do
- before :each do
- @server = NetFTPSpecs::DummyFTP.new
- @server.serve_once
-
- @ftp = Net::FTP.new
- @ftp.connect(@server.hostname, @server.server_port)
- end
-
- after :each do
- @ftp.quit rescue nil
- @ftp.close
- @server.stop
- end
-
- describe "when switching to the parent directory" do
- it "sends the 'CDUP' command to the server" do
- @ftp.chdir("..")
- @ftp.last_response.should == "200 Command okay. (CDUP)\n"
- end
-
- it "returns nil" do
- @ftp.chdir("..").should be_nil
- end
-
- it "does not raise a Net::FTPPermError when the response code is 500" do
- @server.should_receive(:cdup).and_respond("500 Syntax error, command unrecognized.")
- lambda { @ftp.chdir("..") }.should_not raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPPermError when the response code is 501" do
- @server.should_receive(:cdup).and_respond("501 Syntax error in parameters or arguments.")
- lambda { @ftp.chdir("..") }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPPermError when the response code is 502" do
- @server.should_receive(:cdup).and_respond("502 Command not implemented.")
- lambda { @ftp.chdir("..") }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPTempError when the response code is 421" do
- @server.should_receive(:cdup).and_respond("421 Service not available, closing control connection.")
- lambda { @ftp.chdir("..") }.should raise_error(Net::FTPTempError)
- end
-
- it "raises a Net::FTPPermError when the response code is 530" do
- @server.should_receive(:cdup).and_respond("530 Not logged in.")
- lambda { @ftp.chdir("..") }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPPermError when the response code is 550" do
- @server.should_receive(:cdup).and_respond("550 Requested action not taken.")
- lambda { @ftp.chdir("..") }.should raise_error(Net::FTPPermError)
- end
- end
-
- it "writes the 'CWD' command with the passed directory to the socket" do
- @ftp.chdir("test")
- @ftp.last_response.should == "200 Command okay. (CWD test)\n"
- end
-
- it "returns nil" do
- @ftp.chdir("test").should be_nil
- end
-
- it "raises a Net::FTPPermError when the response code is 500" do
- @server.should_receive(:cwd).and_respond("500 Syntax error, command unrecognized.")
- lambda { @ftp.chdir("test") }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPPermError when the response code is 501" do
- @server.should_receive(:cwd).and_respond("501 Syntax error in parameters or arguments.")
- lambda { @ftp.chdir("test") }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPPermError when the response code is 502" do
- @server.should_receive(:cwd).and_respond("502 Command not implemented.")
- lambda { @ftp.chdir("test") }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPTempError when the response code is 421" do
- @server.should_receive(:cwd).and_respond("421 Service not available, closing control connection.")
- lambda { @ftp.chdir("test") }.should raise_error(Net::FTPTempError)
- end
-
- it "raises a Net::FTPPermError when the response code is 530" do
- @server.should_receive(:cwd).and_respond("530 Not logged in.")
- lambda { @ftp.chdir("test") }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPPermError when the response code is 550" do
- @server.should_receive(:cwd).and_respond("550 Requested action not taken.")
- lambda { @ftp.chdir("test") }.should raise_error(Net::FTPPermError)
- end
-end
diff --git a/spec/ruby/library/net/ftp/close_spec.rb b/spec/ruby/library/net/ftp/close_spec.rb
deleted file mode 100644
index 0f6866221f..0000000000
--- a/spec/ruby/library/net/ftp/close_spec.rb
+++ /dev/null
@@ -1,30 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../spec_helper', __FILE__)
-
-describe "Net::FTP#close" do
- before :each do
- @socket = mock("Socket")
- @socket.stub!(:closed?).and_return(false)
- @socket.stub!(:read_timeout).and_return(60)
- @socket.stub!(:read_timeout=).and_return(3)
-
- @ftp = Net::FTP.new
- @ftp.instance_variable_set(:@sock, @socket)
- end
-
- it "closes the socket" do
- @socket.should_receive(:close)
- @ftp.close.should be_nil
- end
-
- it "does not try to close the socket if it has already been closed" do
- @socket.should_receive(:closed?).and_return(true)
- @socket.should_not_receive(:close)
- @ftp.close.should be_nil
- end
-
- it "does not try to close the socket if it is nil" do
- @ftp.instance_variable_set(:@sock, nil)
- @ftp.close.should be_nil
- end
-end
diff --git a/spec/ruby/library/net/ftp/closed_spec.rb b/spec/ruby/library/net/ftp/closed_spec.rb
deleted file mode 100644
index 7b31717c00..0000000000
--- a/spec/ruby/library/net/ftp/closed_spec.rb
+++ /dev/null
@@ -1,21 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../spec_helper', __FILE__)
-
-describe "Net::FTP#closed?" do
- before :each do
- @socket = mock("Socket")
-
- @ftp = Net::FTP.new
- @ftp.instance_variable_set(:@sock, @socket)
- end
-
- it "returns true when the socket is closed" do
- @socket.should_receive(:closed?).and_return(true)
- @ftp.closed?.should be_true
- end
-
- it "returns true when the socket is nil" do
- @ftp.instance_variable_set(:@sock, nil)
- @ftp.closed?.should be_true
- end
-end
diff --git a/spec/ruby/library/net/ftp/connect_spec.rb b/spec/ruby/library/net/ftp/connect_spec.rb
deleted file mode 100644
index f3c1565fc2..0000000000
--- a/spec/ruby/library/net/ftp/connect_spec.rb
+++ /dev/null
@@ -1,49 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../spec_helper', __FILE__)
-require File.expand_path('../fixtures/server', __FILE__)
-
-# TODO: Add specs for using the SOCKSSocket
-describe "Net::FTP#connect" do
- before :each do
- @server = NetFTPSpecs::DummyFTP.new
- @server.serve_once
-
- @ftp = Net::FTP.new
- end
-
- after :each do
- @server.connect_message = nil
- @ftp.quit rescue nil
- @ftp.close
- @server.stop
- end
-
- it "tries to connect to the FTP Server on the given host and port" do
- lambda { @ftp.connect(@server.hostname, @server.server_port) }.should_not raise_error
- end
-
- it "returns nil" do
- @ftp.connect(@server.hostname, @server.server_port).should be_nil
- end
-
- it "prints a small debug line when in debug mode" do
- @ftp.debug_mode = true
- lambda { @ftp.connect(@server.hostname, @server.server_port) }.should output(/#{"connect: "}#{@server.hostname}#{", "}#{@server.server_port}#{"\\nget: 220 Dummy FTP Server ready!"}/)
- @ftp.debug_mode = false
- end
-
- it "does not raise any error when the response code is 220" do
- @server.connect_message = "220 Dummy FTP Server ready!"
- lambda { @ftp.connect(@server.hostname, @server.server_port) }.should_not raise_error
- end
-
- it "raises a Net::FTPReplyError when the response code is 120" do
- @server.connect_message = "120 Service ready in nnn minutes."
- lambda { @ftp.connect(@server.hostname, @server.server_port) }.should raise_error(Net::FTPReplyError)
- end
-
- it "raises a Net::FTPTempError when the response code is 421" do
- @server.connect_message = "421 Service not available, closing control connection."
- lambda { @ftp.connect(@server.hostname, @server.server_port) }.should raise_error(Net::FTPTempError)
- end
-end
diff --git a/spec/ruby/library/net/ftp/debug_mode_spec.rb b/spec/ruby/library/net/ftp/debug_mode_spec.rb
deleted file mode 100644
index c4aa5eee3c..0000000000
--- a/spec/ruby/library/net/ftp/debug_mode_spec.rb
+++ /dev/null
@@ -1,23 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../spec_helper', __FILE__)
-
-describe "Net::FTP#debug_mode" do
- it "returns true when self is in debug mode" do
- ftp = Net::FTP.new
- ftp.debug_mode.should be_false
-
- ftp.debug_mode = true
- ftp.debug_mode.should be_true
- end
-end
-
-describe "Net::FTP#debug_mode=" do
- it "sets self into debug mode when passed true" do
- ftp = Net::FTP.new
- ftp.debug_mode = true
- ftp.debug_mode.should be_true
-
- ftp.debug_mode = false
- ftp.debug_mode.should be_false
- end
-end
diff --git a/spec/ruby/library/net/ftp/default_passive_spec.rb b/spec/ruby/library/net/ftp/default_passive_spec.rb
deleted file mode 100644
index f526373b82..0000000000
--- a/spec/ruby/library/net/ftp/default_passive_spec.rb
+++ /dev/null
@@ -1,10 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../spec_helper', __FILE__)
-
-ruby_version_is "2.3" do
- describe "Net::FTP#default_passive" do
- it "is true by default" do
- ruby_exe(fixture(__FILE__, "default_passive.rb")).should == "true\ntrue\n"
- end
- end
-end
diff --git a/spec/ruby/library/net/ftp/delete_spec.rb b/spec/ruby/library/net/ftp/delete_spec.rb
deleted file mode 100644
index b20ef32651..0000000000
--- a/spec/ruby/library/net/ftp/delete_spec.rb
+++ /dev/null
@@ -1,59 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../spec_helper', __FILE__)
-require File.expand_path('../fixtures/server', __FILE__)
-
-describe "Net::FTP#delete" do
- before :each do
- @server = NetFTPSpecs::DummyFTP.new
- @server.serve_once
-
- @ftp = Net::FTP.new
- @ftp.connect(@server.hostname, @server.server_port)
- end
-
- after :each do
- @ftp.quit rescue nil
- @ftp.close
- @server.stop
- end
-
- it "sends the DELE command with the passed filename to the server" do
- @ftp.delete("test.file")
- @ftp.last_response.should == "250 Requested file action okay, completed. (DELE test.file)\n"
- end
-
- it "raises a Net::FTPTempError when the response code is 450" do
- @server.should_receive(:dele).and_respond("450 Requested file action not taken.")
- lambda { @ftp.delete("test.file") }.should raise_error(Net::FTPTempError)
- end
-
- it "raises a Net::FTPPermError when the response code is 550" do
- @server.should_receive(:dele).and_respond("550 Requested action not taken.")
- lambda { @ftp.delete("test.file") }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPPermError when the response code is 500" do
- @server.should_receive(:dele).and_respond("500 Syntax error, command unrecognized.")
- lambda { @ftp.delete("test.file") }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPPermError when the response code is 501" do
- @server.should_receive(:dele).and_respond("501 Syntax error in parameters or arguments.")
- lambda { @ftp.delete("test.file") }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPPermError when the response code is 502" do
- @server.should_receive(:dele).and_respond("502 Command not implemented.")
- lambda { @ftp.delete("test.file") }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPTempError when the response code is 421" do
- @server.should_receive(:dele).and_respond("421 Service not available, closing control connection.")
- lambda { @ftp.delete("test.file") }.should raise_error(Net::FTPTempError)
- end
-
- it "raises a Net::FTPPermError when the response code is 530" do
- @server.should_receive(:dele).and_respond("530 Not logged in.")
- lambda { @ftp.delete("test.file") }.should raise_error(Net::FTPPermError)
- end
-end
diff --git a/spec/ruby/library/net/ftp/dir_spec.rb b/spec/ruby/library/net/ftp/dir_spec.rb
deleted file mode 100644
index 6a2b766ca2..0000000000
--- a/spec/ruby/library/net/ftp/dir_spec.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../spec_helper', __FILE__)
-require File.expand_path('../fixtures/server', __FILE__)
-require File.expand_path('../shared/list', __FILE__)
-
-describe "Net::FTP#dir" do
- it_behaves_like :net_ftp_list, :dir
-end
diff --git a/spec/ruby/library/net/ftp/fixtures/server.rb b/spec/ruby/library/net/ftp/fixtures/server.rb
deleted file mode 100644
index 65339cfaf9..0000000000
--- a/spec/ruby/library/net/ftp/fixtures/server.rb
+++ /dev/null
@@ -1,277 +0,0 @@
-module NetFTPSpecs
- class DummyFTP
- attr_accessor :connect_message
- attr_reader :login_user, :login_pass, :login_acct
-
- # hostname or IP address
- attr_reader :hostname
- # port number
- attr_reader :server_port
-
- def initialize
- @hostname = "localhost"
- @server = TCPServer.new(@hostname, 0)
- @server_port = @server.addr[1]
-
- @handlers = {}
- @commands = []
- @connect_message = nil
- end
-
- def serve_once
- @thread = Thread.new do
- @socket = @server.accept
- @socket.setsockopt(Socket::SOL_SOCKET, Socket::SO_OOBINLINE, 1)
- begin
- handle_request
- ensure
- @socket.close
- end
- end
- end
-
- def handle_request
- # Send out the welcome message.
- response @connect_message || "220 Dummy FTP Server ready!"
-
- begin
- while command = @socket.gets
- command, argument = command.chomp.split(" ", 2)
-
- if command == "QUIT"
- self.response("221 OK, bye")
- break
- elsif proc_handler = @handlers[command.downcase.to_sym]
- if argument.nil?
- proc_handler.call(self)
- else
- proc_handler.call(self, argument)
- end
- else
- if argument.nil?
- self.send(command.downcase.to_sym)
- else
- self.send(command.downcase.to_sym, argument)
- end
- end
- end
- rescue => e
- self.error_response("Exception: #{e} #{e.backtrace.inspect}")
- end
- end
-
- def error_response(text)
- self.response("451 #{text}")
- end
-
- def response(text)
- @socket.puts(text) unless @socket.closed?
- end
-
- def stop
- @datasocket.close unless @datasocket.nil? || @datasocket.closed?
- @server.close
- @thread.join
- end
-
-
- ##
- def handle(sym, &block)
- @handlers[sym] = block
- end
-
- def should_receive(method)
- @handler_for = method
- self
- end
-
- def and_respond(text)
- @handlers[@handler_for] = lambda { |s, *args| s.response(text) }
- end
-
- ##
- # FTP methods
- ##
-
- def abor
- self.response("226 Closing data connection. (ABOR)")
- end
-
- def acct(account)
- @login_acct = account
- self.response("230 User '#{account}' logged in, proceed. (ACCT)")
- end
-
- def cdup
- self.response("200 Command okay. (CDUP)")
- end
-
- def cwd(dir)
- self.response("200 Command okay. (CWD #{dir})")
- end
-
- def dele(file)
- self.response("250 Requested file action okay, completed. (DELE #{file})")
- end
-
- def eprt(arg)
- _, _, host, port = arg.split("|")
-
- @datasocket = TCPSocket.new(host, port)
- self.response("200 port opened")
- end
-
- def help(param = :default)
- if param == :default
- self.response("211 System status, or system help reply. (HELP)")
- else
- self.response("211 System status, or system help reply. (HELP #{param})")
- end
- end
-
- def list(folder)
- self.response("150 opening ASCII connection for file list")
- @datasocket.puts("-rw-r--r-- 1 spec staff 507 17 Jul 18:41 last_response_code.rb")
- @datasocket.puts("-rw-r--r-- 1 spec staff 50 17 Jul 18:41 list.rb")
- @datasocket.puts("-rw-r--r-- 1 spec staff 48 17 Jul 18:41 pwd.rb")
- @datasocket.close()
- self.response("226 transfer complete (LIST #{folder})")
- end
-
- def mdtm(filename)
- self.response("213 19980705132316")
- end
-
- def mkd(foldername)
- self.response(%Q{257 "#{foldername.gsub('"', '""')}" created.})
- end
-
- def nlst(folder = nil)
- self.response("150 opening ASCII connection for file list")
- @datasocket.puts("last_response_code.rb")
- @datasocket.puts("list.rb")
- @datasocket.puts("pwd.rb")
- @datasocket.close()
- self.response("226 transfer complete (NLST#{folder ? " #{folder}" : ""})")
- end
-
- def noop
- self.response("200 Command okay. (NOOP)")
- end
-
- def pass(password)
- @login_pass = password
- self.response("230 User logged in, proceed. (PASS #{password})")
- end
-
- def port(arg)
- nums = arg.split(",")
-
- if nums[0] == "::1"
- # IPv6
- port = nums[1].to_i * 256 + nums[2].to_i
- host = nums[0]
- else
- # IPv4
- port = nums[4].to_i * 256 + nums[5].to_i
- host = nums[0..3].join(".")
- end
-
- @datasocket = TCPSocket.new(host, port)
- self.response("200 port opened")
- end
-
- def pwd
- self.response('257 "/some/dir/" - current directory')
- end
-
- def retr(file)
- self.response("125 Data transfer starting")
- if @restart_at && @restart_at == 20
- @datasocket.puts("of the file named '#{file}'.")
- @restart_at = nil
- else
- @datasocket.puts("This is the content")
- @datasocket.puts("of the file named '#{file}'.")
- end
- @datasocket.close()
- self.response("226 Closing data connection. (RETR #{file})")
- end
-
- def rest(at_bytes)
- @restart_at = at_bytes.to_i
- self.response("350 Requested file action pending further information. (REST)")
- end
-
- def rmd(folder)
- self.response("250 Requested file action okay, completed. (RMD #{folder})")
- end
-
- def rnfr(from)
- @rename_from = from
- self.response("350 Requested file action pending further information.")
- end
-
- def rnto(to)
- self.response("250 Requested file action okay, completed. (Renamed #{@rename_from} to #{to})")
- @rename_from = nil
- end
-
- def site(param)
- self.response("200 Command okay. (SITE #{param})")
- end
-
- def size(filename)
- if filename == "binary"
- self.response("213 24")
- else
- self.response("213 1024")
- end
- end
-
- def stat(param = :default)
- if param == :default
- self.response("211 System status, or system help reply. (STAT)")
- else
- self.response("211 System status, or system help reply. (STAT #{param})")
- end
- end
-
- def stor(file)
- tmp_file = tmp("#{file}file", false)
-
- self.response("125 Data transfer starting.")
-
- mode = @restart_at ? "a" : "w"
-
- File.open(tmp_file, mode + "b") do |f|
- loop do
- data = @datasocket.recv(1024)
- break if !data || data.empty?
- f << data
- end
- end
-
- #@datasocket.close()
- self.response("200 OK, Data received. (STOR #{file})")
- end
-
- def appe(file)
- @restart_at = true
- stor(file)
- end
-
- def syst
- self.response("215 FTP Dummy Server (SYST)")
- end
-
- def type(type)
- self.response("200 TYPE switched to #{type}")
- end
-
- def user(name)
- @login_user = name
- self.response("230 User logged in, proceed. (USER #{name})")
- end
- end
-end
diff --git a/spec/ruby/library/net/ftp/get_spec.rb b/spec/ruby/library/net/ftp/get_spec.rb
deleted file mode 100644
index 59fc45d010..0000000000
--- a/spec/ruby/library/net/ftp/get_spec.rb
+++ /dev/null
@@ -1,21 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../spec_helper', __FILE__)
-require File.expand_path('../fixtures/server', __FILE__)
-require File.expand_path('../shared/gettextfile', __FILE__)
-require File.expand_path('../shared/getbinaryfile', __FILE__)
-
-describe "Net::FTP#get (binary mode)" do
- before :each do
- @binary_mode = true
- end
-
- it_behaves_like :net_ftp_getbinaryfile, :get
-end
-
-describe "Net::FTP#get (text mode)" do
- before :each do
- @binary_mode = false
- end
-
- it_behaves_like :net_ftp_gettextfile, :get
-end
diff --git a/spec/ruby/library/net/ftp/getbinaryfile_spec.rb b/spec/ruby/library/net/ftp/getbinaryfile_spec.rb
deleted file mode 100644
index 0f921c8b1d..0000000000
--- a/spec/ruby/library/net/ftp/getbinaryfile_spec.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../spec_helper', __FILE__)
-require File.expand_path('../fixtures/server', __FILE__)
-require File.expand_path('../shared/getbinaryfile', __FILE__)
-
-describe "Net::FTP#getbinaryfile" do
- it_behaves_like :net_ftp_getbinaryfile, :getbinaryfile
-end
diff --git a/spec/ruby/library/net/ftp/getdir_spec.rb b/spec/ruby/library/net/ftp/getdir_spec.rb
deleted file mode 100644
index 19ace4dff9..0000000000
--- a/spec/ruby/library/net/ftp/getdir_spec.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../spec_helper', __FILE__)
-require File.expand_path('../shared/pwd', __FILE__)
-
-describe "Net::FTP#getdir" do
- it_behaves_like :net_ftp_pwd, :getdir
-end
diff --git a/spec/ruby/library/net/ftp/gettextfile_spec.rb b/spec/ruby/library/net/ftp/gettextfile_spec.rb
deleted file mode 100644
index 29077df253..0000000000
--- a/spec/ruby/library/net/ftp/gettextfile_spec.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../spec_helper', __FILE__)
-require File.expand_path('../fixtures/server', __FILE__)
-require File.expand_path('../shared/gettextfile', __FILE__)
-
-describe "Net::FTP#gettextfile" do
- it_behaves_like :net_ftp_gettextfile, :gettextfile
-end
diff --git a/spec/ruby/library/net/ftp/help_spec.rb b/spec/ruby/library/net/ftp/help_spec.rb
deleted file mode 100644
index 6f5f901024..0000000000
--- a/spec/ruby/library/net/ftp/help_spec.rb
+++ /dev/null
@@ -1,66 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../spec_helper', __FILE__)
-require File.expand_path('../fixtures/server', __FILE__)
-
-describe "Net::FTP#help" do
- def with_connection
- yield
- end
-
- before :each do
- @server = NetFTPSpecs::DummyFTP.new
- @server.serve_once
-
- @ftp = Net::FTP.new
- @ftp.connect(@server.hostname, @server.server_port)
- end
-
- after :each do
- @ftp.quit rescue nil
- @ftp.close
- @server.stop
- end
-
- it "writes the HELP command to the server" do
- @ftp.help
- @ftp.last_response.should == "211 System status, or system help reply. (HELP)\n"
- end
-
- it "returns the server's response" do
- @ftp.help.should == "211 System status, or system help reply. (HELP)\n"
- end
-
- it "writes the HELP command with an optional parameter to the socket" do
- @ftp.help("some parameter").should == "211 System status, or system help reply. (HELP some parameter)\n"
- end
-
- it "does not raise any error when the response code is 211" do
- @server.should_receive(:help).and_respond("211 System status, or system help reply.")
- lambda { @ftp.help }.should_not raise_error
- end
-
- it "does not raise any error when the response code is 214" do
- @server.should_receive(:help).and_respond("214 Help message.")
- lambda { @ftp.help }.should_not raise_error
- end
-
- it "raises a Net::FTPPermError when the response code is 500" do
- @server.should_receive(:help).and_respond("500 Syntax error, command unrecognized.")
- lambda { @ftp.help }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPPermError when the response code is 501" do
- @server.should_receive(:help).and_respond("501 Syntax error in parameters or arguments.")
- lambda { @ftp.help }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPPermError when the response code is 502" do
- @server.should_receive(:help).and_respond("502 Command not implemented.")
- lambda { @ftp.help }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPTempError when the response code is 421" do
- @server.should_receive(:help).and_respond("421 Service not available, closing control connection.")
- lambda { @ftp.help }.should raise_error(Net::FTPTempError)
- end
-end
diff --git a/spec/ruby/library/net/ftp/initialize_spec.rb b/spec/ruby/library/net/ftp/initialize_spec.rb
deleted file mode 100644
index 65105b8831..0000000000
--- a/spec/ruby/library/net/ftp/initialize_spec.rb
+++ /dev/null
@@ -1,91 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../spec_helper', __FILE__)
-
-describe "Net::FTP#initialize" do
- before :each do
- @ftp = Net::FTP.allocate
- @ftp.stub!(:connect)
- @port_args = []
- ruby_version_is "2.5" do
- @port_args << 21
- end
- end
-
- it "is private" do
- Net::FTP.should have_private_instance_method(:initialize)
- end
-
- it "sets self into binary mode" do
- @ftp.binary.should be_nil
- @ftp.send(:initialize)
- @ftp.binary.should be_true
- end
-
- it "sets self into active mode" do
- @ftp.passive.should be_nil
- @ftp.send(:initialize)
- @ftp.passive.should be_false
- end
-
- it "sets self into non-debug mode" do
- @ftp.debug_mode.should be_nil
- @ftp.send(:initialize)
- @ftp.debug_mode.should be_false
- end
-
- it "sets self to not resume file uploads/downloads" do
- @ftp.resume.should be_nil
- @ftp.send(:initialize)
- @ftp.resume.should be_false
- end
-
- describe "when passed no arguments" do
- it "does not try to connect" do
- @ftp.should_not_receive(:connect)
- @ftp.send(:initialize)
- end
- end
-
- describe "when passed host" do
- it "tries to connect to the passed host" do
- @ftp.should_receive(:connect).with("localhost", *@port_args)
- @ftp.send(:initialize, "localhost")
- end
- end
-
- describe "when passed host, user" do
- it "tries to connect to the passed host" do
- @ftp.should_receive(:connect).with("localhost", *@port_args)
- @ftp.send(:initialize, "localhost")
- end
-
- it "tries to login with the passed username" do
- @ftp.should_receive(:login).with("rubyspec", nil, nil)
- @ftp.send(:initialize, "localhost", "rubyspec")
- end
- end
-
- describe "when passed host, user, password" do
- it "tries to connect to the passed host" do
- @ftp.should_receive(:connect).with("localhost", *@port_args)
- @ftp.send(:initialize, "localhost")
- end
-
- it "tries to login with the passed username and password" do
- @ftp.should_receive(:login).with("rubyspec", "rocks", nil)
- @ftp.send(:initialize, "localhost", "rubyspec", "rocks")
- end
- end
-
- describe "when passed host, user" do
- it "tries to connect to the passed host" do
- @ftp.should_receive(:connect).with("localhost", *@port_args)
- @ftp.send(:initialize, "localhost")
- end
-
- it "tries to login with the passed username, password and account" do
- @ftp.should_receive(:login).with("rubyspec", "rocks", "account")
- @ftp.send(:initialize, "localhost", "rubyspec", "rocks", "account")
- end
- end
-end
diff --git a/spec/ruby/library/net/ftp/last_response_code_spec.rb b/spec/ruby/library/net/ftp/last_response_code_spec.rb
deleted file mode 100644
index 77651a9be4..0000000000
--- a/spec/ruby/library/net/ftp/last_response_code_spec.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../spec_helper', __FILE__)
-require File.expand_path('../shared/last_response_code', __FILE__)
-require File.expand_path('../fixtures/server', __FILE__)
-
-describe "Net::FTP#last_response_code" do
- it_behaves_like :net_ftp_last_response_code, :last_response_code
-end
diff --git a/spec/ruby/library/net/ftp/last_response_spec.rb b/spec/ruby/library/net/ftp/last_response_spec.rb
deleted file mode 100644
index eb53f92774..0000000000
--- a/spec/ruby/library/net/ftp/last_response_spec.rb
+++ /dev/null
@@ -1,25 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../spec_helper', __FILE__)
-require File.expand_path('../fixtures/server', __FILE__)
-
-describe "Net::FTP#last_response" do
- before :each do
- @server = NetFTPSpecs::DummyFTP.new
- @server.serve_once
-
- @ftp = Net::FTP.new
- @ftp.connect(@server.hostname, @server.server_port)
- end
-
- after :each do
- @ftp.quit rescue nil
- @ftp.close
- @server.stop
- end
-
- it "returns the last response" do
- @ftp.last_response.should == "220 Dummy FTP Server ready!\n"
- @ftp.help
- @ftp.last_response.should == "211 System status, or system help reply. (HELP)\n"
- end
-end
diff --git a/spec/ruby/library/net/ftp/lastresp_spec.rb b/spec/ruby/library/net/ftp/lastresp_spec.rb
deleted file mode 100644
index d2c6f44e48..0000000000
--- a/spec/ruby/library/net/ftp/lastresp_spec.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../spec_helper', __FILE__)
-require File.expand_path('../shared/last_response_code', __FILE__)
-require File.expand_path('../fixtures/server', __FILE__)
-
-describe "Net::FTP#lastresp" do
- it_behaves_like :net_ftp_last_response_code, :lastresp
-end
diff --git a/spec/ruby/library/net/ftp/list_spec.rb b/spec/ruby/library/net/ftp/list_spec.rb
deleted file mode 100644
index 41c55c42ac..0000000000
--- a/spec/ruby/library/net/ftp/list_spec.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../spec_helper', __FILE__)
-require File.expand_path('../fixtures/server', __FILE__)
-require File.expand_path('../shared/list', __FILE__)
-
-describe "Net::FTP#list" do
- it_behaves_like :net_ftp_list, :list
-end
diff --git a/spec/ruby/library/net/ftp/login_spec.rb b/spec/ruby/library/net/ftp/login_spec.rb
deleted file mode 100644
index 9768d9cf33..0000000000
--- a/spec/ruby/library/net/ftp/login_spec.rb
+++ /dev/null
@@ -1,195 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../spec_helper', __FILE__)
-require File.expand_path('../fixtures/server', __FILE__)
-
-describe "Net::FTP#login" do
- before :each do
- @server = NetFTPSpecs::DummyFTP.new
- @server.serve_once
-
- @ftp = Net::FTP.new
- @ftp.connect(@server.hostname, @server.server_port)
- end
-
- after :each do
- @ftp.quit rescue nil
- @ftp.close
- @server.stop
- end
-
- describe "when passed no arguments" do
- it "sends the USER command with 'anonymous' as name to the server" do
- @ftp.login
- @server.login_user.should == "anonymous"
- end
-
- it "sends 'anonymous@' as a password when required" do
- @server.should_receive(:user).and_respond("331 User name okay, need password.")
- @ftp.login
- @server.login_pass.should == "anonymous@"
- end
-
- it "raises a Net::FTPReplyError when the server requests an account" do
- @server.should_receive(:user).and_respond("331 User name okay, need password.")
- @server.should_receive(:pass).and_respond("332 Need account for login.")
- lambda { @ftp.login }.should raise_error(Net::FTPReplyError)
- end
- end
-
- describe "when passed name" do
- it "sends the USER command with the passed name to the server" do
- @ftp.login("rubyspec")
- @server.login_user.should == "rubyspec"
- end
-
- it "raises a Net::FTPReplyError when the server requests a password, but none was given" do
- @server.should_receive(:user).and_respond("331 User name okay, need password.")
- lambda { @ftp.login("rubyspec") }.should raise_error(Net::FTPReplyError)
- end
-
- it "raises a Net::FTPReplyError when the server requests an account, but none was given" do
- @server.should_receive(:user).and_respond("331 User name okay, need password.")
- @server.should_receive(:pass).and_respond("332 Need account for login.")
- lambda { @ftp.login("rubyspec") }.should raise_error(Net::FTPReplyError)
- end
- end
-
- describe "when passed name, password" do
- it "sends the USER command with the passed name to the server" do
- @ftp.login("rubyspec", "rocks")
- @server.login_user.should == "rubyspec"
- end
-
- it "sends the passed password when required" do
- @server.should_receive(:user).and_respond("331 User name okay, need password.")
- @ftp.login("rubyspec", "rocks")
- @server.login_pass.should == "rocks"
- end
-
- it "raises a Net::FTPReplyError when the server requests an account" do
- @server.should_receive(:user).and_respond("331 User name okay, need password.")
- @server.should_receive(:pass).and_respond("332 Need account for login.")
- lambda { @ftp.login("rubyspec", "rocks") }.should raise_error(Net::FTPReplyError)
- end
- end
-
- describe "when passed name, password, account" do
- it "sends the USER command with the passed name to the server" do
- @ftp.login("rubyspec", "rocks", "account")
- @server.login_user.should == "rubyspec"
- end
-
- it "sends the passed password when required" do
- @server.should_receive(:user).and_respond("331 User name okay, need password.")
- @ftp.login("rubyspec", "rocks", "account")
- @server.login_pass.should == "rocks"
- end
-
- it "sends the passed account when required" do
- @server.should_receive(:user).and_respond("331 User name okay, need password.")
- @server.should_receive(:pass).and_respond("332 Need account for login.")
- @ftp.login("rubyspec", "rocks", "account")
- @server.login_acct.should == "account"
- end
- end
-
- describe "when the USER command fails" do
- it "raises a Net::FTPPermError when the response code is 500" do
- @server.should_receive(:user).and_respond("500 Syntax error, command unrecognized.")
- lambda { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPPermError when the response code is 501" do
- @server.should_receive(:user).and_respond("501 Syntax error in parameters or arguments.")
- lambda { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPPermError when the response code is 502" do
- @server.should_receive(:user).and_respond("502 Command not implemented.")
- lambda { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPTempError when the response code is 421" do
- @server.should_receive(:user).and_respond("421 Service not available, closing control connection.")
- lambda { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPTempError)
- end
-
- it "raises a Net::FTPPermError when the response code is 530" do
- @server.should_receive(:user).and_respond("530 Not logged in.")
- lambda { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPPermError)
- end
- end
-
- describe "when the PASS command fails" do
- before :each do
- @server.should_receive(:user).and_respond("331 User name okay, need password.")
- end
-
- it "does not raise an Error when the response code is 202" do
- @server.should_receive(:pass).and_respond("202 Command not implemented, superfluous at this site.")
- lambda { @ftp.login("rubyspec", "rocks", "account") }.should_not raise_error
- end
-
- it "raises a Net::FTPPermError when the response code is 500" do
- @server.should_receive(:pass).and_respond("500 Syntax error, command unrecognized.")
- lambda { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPPermError when the response code is 501" do
- @server.should_receive(:pass).and_respond("501 Syntax error in parameters or arguments.")
- lambda { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPPermError when the response code is 502" do
- @server.should_receive(:pass).and_respond("502 Command not implemented.")
- lambda { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPTempError when the response code is 421" do
- @server.should_receive(:pass).and_respond("421 Service not available, closing control connection.")
- lambda { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPTempError)
- end
-
- it "raises a Net::FTPPermError when the response code is 530" do
- @server.should_receive(:pass).and_respond("530 Not logged in.")
- lambda { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPPermError)
- end
- end
-
- describe "when the ACCT command fails" do
- before :each do
- @server.should_receive(:user).and_respond("331 User name okay, need password.")
- @server.should_receive(:pass).and_respond("332 Need account for login.")
- end
-
- it "does not raise an Error when the response code is 202" do
- @server.should_receive(:acct).and_respond("202 Command not implemented, superfluous at this site.")
- lambda { @ftp.login("rubyspec", "rocks", "account") }.should_not raise_error
- end
-
- it "raises a Net::FTPPermError when the response code is 500" do
- @server.should_receive(:acct).and_respond("500 Syntax error, command unrecognized.")
- lambda { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPPermError when the response code is 501" do
- @server.should_receive(:acct).and_respond("501 Syntax error in parameters or arguments.")
- lambda { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPPermError when the response code is 502" do
- @server.should_receive(:acct).and_respond("502 Command not implemented.")
- lambda { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPTempError when the response code is 421" do
- @server.should_receive(:acct).and_respond("421 Service not available, closing control connection.")
- lambda { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPTempError)
- end
-
- it "raises a Net::FTPPermError when the response code is 530" do
- @server.should_receive(:acct).and_respond("530 Not logged in.")
- lambda { @ftp.login("rubyspec", "rocks", "account") }.should raise_error(Net::FTPPermError)
- end
- end
-end
diff --git a/spec/ruby/library/net/ftp/ls_spec.rb b/spec/ruby/library/net/ftp/ls_spec.rb
deleted file mode 100644
index f713fb46aa..0000000000
--- a/spec/ruby/library/net/ftp/ls_spec.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../spec_helper', __FILE__)
-require File.expand_path('../fixtures/server', __FILE__)
-require File.expand_path('../shared/list', __FILE__)
-
-describe "Net::FTP#ls" do
- it_behaves_like :net_ftp_list, :ls
-end
diff --git a/spec/ruby/library/net/ftp/mdtm_spec.rb b/spec/ruby/library/net/ftp/mdtm_spec.rb
deleted file mode 100644
index bbd28d10b1..0000000000
--- a/spec/ruby/library/net/ftp/mdtm_spec.rb
+++ /dev/null
@@ -1,38 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../spec_helper', __FILE__)
-require File.expand_path('../fixtures/server', __FILE__)
-
-describe "Net::FTP#mdtm" do
- before :each do
- @server = NetFTPSpecs::DummyFTP.new
- @server.serve_once
-
- @ftp = Net::FTP.new
- @ftp.connect(@server.hostname, @server.server_port)
- end
-
- after :each do
- @ftp.quit rescue nil
- @ftp.close
- @server.stop
- end
-
- it "sends the MDTM with the passed filename command to the server" do
- @ftp.mdtm("test.file")
- @ftp.last_response.should == "213 19980705132316\n"
- end
-
- it "returns the last modification time of the passed file" do
- @ftp.mdtm("test.file").should == "19980705132316"
- end
-
- it "raises a Net::FTPPermError when the response code is 550" do
- @server.should_receive(:mdtm).and_respond("550 Requested action not taken.")
- lambda { @ftp.mdtm("test.file") }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPTempError when the response code is 421" do
- @server.should_receive(:mdtm).and_respond("421 Service not available, closing control connection.")
- lambda { @ftp.mdtm("test.file") }.should raise_error(Net::FTPTempError)
- end
-end
diff --git a/spec/ruby/library/net/ftp/mkdir_spec.rb b/spec/ruby/library/net/ftp/mkdir_spec.rb
deleted file mode 100644
index 2a7088e5d9..0000000000
--- a/spec/ruby/library/net/ftp/mkdir_spec.rb
+++ /dev/null
@@ -1,61 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../spec_helper', __FILE__)
-require File.expand_path('../fixtures/server', __FILE__)
-
-describe "Net::FTP#mkdir" do
- before :each do
- @server = NetFTPSpecs::DummyFTP.new
- @server.serve_once
-
- @ftp = Net::FTP.new
- @ftp.connect(@server.hostname, @server.server_port)
- end
-
- after :each do
- @ftp.quit rescue nil
- @ftp.close
- @server.stop
- end
-
- it "sends the MKD command with the passed pathname to the server" do
- @ftp.mkdir("test.folder")
- @ftp.last_response.should == %{257 "test.folder" created.\n}
- end
-
- it "returns the path to the newly created directory" do
- @ftp.mkdir("test.folder").should == "test.folder"
- @ftp.mkdir("/absolute/path/to/test.folder").should == "/absolute/path/to/test.folder"
- @ftp.mkdir("relative/path/to/test.folder").should == "relative/path/to/test.folder"
- @ftp.mkdir('/usr/dm/foo"bar').should == '/usr/dm/foo"bar'
- end
-
- it "raises a Net::FTPPermError when the response code is 500" do
- @server.should_receive(:mkd).and_respond("500 Syntax error, command unrecognized.")
- lambda { @ftp.mkdir("test.folder") }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPPermError when the response code is 501" do
- @server.should_receive(:mkd).and_respond("501 Syntax error in parameters or arguments.")
- lambda { @ftp.mkdir("test.folder") }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPPermError when the response code is 502" do
- @server.should_receive(:mkd).and_respond("502 Command not implemented.")
- lambda { @ftp.mkdir("test.folder") }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPTempError when the response code is 421" do
- @server.should_receive(:mkd).and_respond("421 Service not available, closing control connection.")
- lambda { @ftp.mkdir("test.folder") }.should raise_error(Net::FTPTempError)
- end
-
- it "raises a Net::FTPPermError when the response code is 530" do
- @server.should_receive(:mkd).and_respond("530 Not logged in.")
- lambda { @ftp.mkdir("test.folder") }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPPermError when the response code is 550" do
- @server.should_receive(:mkd).and_respond("550 Requested action not taken.")
- lambda { @ftp.mkdir("test.folder") }.should raise_error(Net::FTPPermError)
- end
-end
diff --git a/spec/ruby/library/net/ftp/mtime_spec.rb b/spec/ruby/library/net/ftp/mtime_spec.rb
deleted file mode 100644
index 0e76aa079b..0000000000
--- a/spec/ruby/library/net/ftp/mtime_spec.rb
+++ /dev/null
@@ -1,50 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../spec_helper', __FILE__)
-require File.expand_path('../fixtures/server', __FILE__)
-
-describe "Net::FTP#mtime" do
- before :each do
- @server = NetFTPSpecs::DummyFTP.new
- @server.serve_once
-
- @ftp = Net::FTP.new
- @ftp.connect(@server.hostname, @server.server_port)
- end
-
- after :each do
- @ftp.quit rescue nil
- @ftp.close
- @server.stop
- end
-
- it "sends the MDTM with the passed filename command to the server" do
- @ftp.mtime("test.file")
- @ftp.last_response.should == "213 19980705132316\n"
- end
-
- describe "when passed filename" do
- it "returns the last modification time of the passed file as a Time object in the local time" do
- @ftp.mtime("test.file").should == Time.gm("1998", "07", "05", "13", "23", "16")
- end
- end
-
- describe "when passed filename, local_time" do
- it "returns the last modification time as a Time object in UTC when local_time is true" do
- @ftp.mtime("test.file", true).should == Time.local("1998", "07", "05", "13", "23", "16")
- end
-
- it "returns the last modification time as a Time object in the local time when local_time is false" do
- @ftp.mtime("test.file", false).should == Time.gm("1998", "07", "05", "13", "23", "16")
- end
- end
-
- it "raises a Net::FTPPermError when the response code is 550" do
- @server.should_receive(:mdtm).and_respond("550 Requested action not taken.")
- lambda { @ftp.mtime("test.file") }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPTempError when the response code is 421" do
- @server.should_receive(:mdtm).and_respond("421 Service not available, closing control connection.")
- lambda { @ftp.mtime("test.file") }.should raise_error(Net::FTPTempError)
- end
-end
diff --git a/spec/ruby/library/net/ftp/nlst_spec.rb b/spec/ruby/library/net/ftp/nlst_spec.rb
deleted file mode 100644
index 4723e9f6c6..0000000000
--- a/spec/ruby/library/net/ftp/nlst_spec.rb
+++ /dev/null
@@ -1,92 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../spec_helper', __FILE__)
-require File.expand_path('../fixtures/server', __FILE__)
-
-describe "Net::FTP#nlst" do
- before :each do
- @server = NetFTPSpecs::DummyFTP.new
- @server.serve_once
-
- @ftp = Net::FTP.new
- @ftp.passive = false
- @ftp.connect(@server.hostname, @server.server_port)
- end
-
- after :each do
- @ftp.quit rescue nil
- @ftp.close
- @server.stop
- end
-
- describe "when passed no arguments" do
- it "returns an Array containing a list of files in the current dir" do
- @ftp.nlst.should == ["last_response_code.rb", "list.rb", "pwd.rb"]
- @ftp.last_response.should == "226 transfer complete (NLST)\n"
- end
- end
-
- describe "when passed dir" do
- it "returns an Array containing a list of files in the passed dir" do
- @ftp.nlst("test.folder").should == ["last_response_code.rb", "list.rb", "pwd.rb"]
- @ftp.last_response.should == "226 transfer complete (NLST test.folder)\n"
- end
- end
-
- describe "when the NLST command fails" do
- it "raises a Net::FTPTempError when the response code is 450" do
- @server.should_receive(:nlst).and_respond("450 Requested file action not taken..")
- lambda { @ftp.nlst }.should raise_error(Net::FTPTempError)
- end
-
- it "raises a Net::FTPPermError when the response code is 500" do
- @server.should_receive(:nlst).and_respond("500 Syntax error, command unrecognized.")
- lambda { @ftp.nlst }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPPermError when the response code is 501" do
- @server.should_receive(:nlst).and_respond("501 Syntax error, command unrecognized.")
- lambda { @ftp.nlst }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPPermError when the response code is 502" do
- @server.should_receive(:nlst).and_respond("502 Command not implemented.")
- lambda { @ftp.nlst }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPTempError when the response code is 421" do
- @server.should_receive(:nlst).and_respond("421 Service not available, closing control connection.")
- lambda { @ftp.nlst }.should raise_error(Net::FTPTempError)
- end
-
- it "raises a Net::FTPPermError when the response code is 530" do
- @server.should_receive(:nlst).and_respond("530 Not logged in.")
- lambda { @ftp.nlst }.should raise_error(Net::FTPPermError)
- end
- end
-
- describe "when opening the data port fails" do
- it "raises a Net::FTPPermError when the response code is 500" do
- @server.should_receive(:eprt).and_respond("500 Syntax error, command unrecognized.")
- @server.should_receive(:port).and_respond("500 Syntax error, command unrecognized.")
- lambda { @ftp.nlst }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPPermError when the response code is 501" do
- @server.should_receive(:eprt).and_respond("501 Syntax error in parameters or arguments.")
- @server.should_receive(:port).and_respond("501 Syntax error in parameters or arguments.")
- lambda { @ftp.nlst }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPTempError when the response code is 421" do
- @server.should_receive(:eprt).and_respond("421 Service not available, closing control connection.")
- @server.should_receive(:port).and_respond("421 Service not available, closing control connection.")
- lambda { @ftp.nlst }.should raise_error(Net::FTPTempError)
- end
-
- it "raises a Net::FTPPermError when the response code is 530" do
- @server.should_receive(:eprt).and_respond("530 Not logged in.")
- @server.should_receive(:port).and_respond("530 Not logged in.")
- lambda { @ftp.nlst }.should raise_error(Net::FTPPermError)
- end
- end
-end
diff --git a/spec/ruby/library/net/ftp/noop_spec.rb b/spec/ruby/library/net/ftp/noop_spec.rb
deleted file mode 100644
index 1bc6ccd913..0000000000
--- a/spec/ruby/library/net/ftp/noop_spec.rb
+++ /dev/null
@@ -1,38 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../spec_helper', __FILE__)
-require File.expand_path('../fixtures/server', __FILE__)
-
-describe "Net::FTP#noop" do
- before :each do
- @server = NetFTPSpecs::DummyFTP.new
- @server.serve_once
-
- @ftp = Net::FTP.new
- @ftp.connect(@server.hostname, @server.server_port)
- end
-
- after :each do
- @ftp.quit rescue nil
- @ftp.close
- @server.stop
- end
-
- it "sends the NOOP command to the server" do
- @ftp.noop
- @ftp.last_response.should == "200 Command okay. (NOOP)\n"
- end
-
- it "returns nil" do
- @ftp.noop.should be_nil
- end
-
- it "raises a Net::FTPPermError when the response code is 500" do
- @server.should_receive(:noop).and_respond("500 Syntax error, command unrecognized.")
- lambda { @ftp.noop }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPTempError when the response code is 421" do
- @server.should_receive(:noop).and_respond("421 Service not available, closing control connection.")
- lambda { @ftp.noop }.should raise_error(Net::FTPTempError)
- end
-end
diff --git a/spec/ruby/library/net/ftp/open_spec.rb b/spec/ruby/library/net/ftp/open_spec.rb
deleted file mode 100644
index b422e64c87..0000000000
--- a/spec/ruby/library/net/ftp/open_spec.rb
+++ /dev/null
@@ -1,55 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../spec_helper', __FILE__)
-
-describe "Net::FTP.open" do
- before :each do
- @ftp = mock("Net::FTP instance")
- Net::FTP.stub!(:new).and_return(@ftp)
- end
-
- describe "when passed no block" do
- it "returns a new Net::FTP instance" do
- Net::FTP.open("localhost").should equal(@ftp)
- end
-
- it "passes the passed arguments down to Net::FTP.new" do
- Net::FTP.should_receive(:new).with("localhost", "user", "password", "account")
- Net::FTP.open("localhost", "user", "password", "account")
- end
- end
-
- describe "when passed a block" do
- before :each do
- @ftp.stub!(:close)
- end
-
- it "yields a new Net::FTP instance to the passed block" do
- yielded = false
- Net::FTP.open("localhost") do |ftp|
- yielded = true
- ftp.should equal(@ftp)
- end
- yielded.should be_true
- end
-
- it "closes the Net::FTP instance after yielding" do
- Net::FTP.open("localhost") do |ftp|
- ftp.should_receive(:close)
- end
- end
-
- it "closes the Net::FTP instance even if an exception is raised while yielding" do
- begin
- Net::FTP.open("localhost") do |ftp|
- ftp.should_receive(:close)
- raise ArgumentError, "some exception"
- end
- rescue ArgumentError
- end
- end
-
- it "returns the block's return value" do
- Net::FTP.open("localhost") { :test }.should == :test
- end
- end
-end
diff --git a/spec/ruby/library/net/ftp/passive_spec.rb b/spec/ruby/library/net/ftp/passive_spec.rb
deleted file mode 100644
index fd9a0dffe3..0000000000
--- a/spec/ruby/library/net/ftp/passive_spec.rb
+++ /dev/null
@@ -1,36 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../spec_helper', __FILE__)
-
-describe "Net::FTP#passive" do
- it "returns true when self is in passive mode" do
- ftp = Net::FTP.new
- ftp.passive.should be_false
-
- ftp.passive = true
- ftp.passive.should be_true
- end
-
- ruby_version_is ""..."2.3" do
- it "is false by default" do
- ruby_exe(fixture(__FILE__, "passive.rb")).should == "false"
- end
- end
-
- ruby_version_is "2.3" do
- it "is the value of Net::FTP.default_value by default" do
- ruby_exe(fixture(__FILE__, "passive.rb")).should == "true"
- end
- end
-end
-
-describe "Net::FTP#passive=" do
- it "sets self to passive mode when passed true" do
- ftp = Net::FTP.new
-
- ftp.passive = true
- ftp.passive.should be_true
-
- ftp.passive = false
- ftp.passive.should be_false
- end
-end
diff --git a/spec/ruby/library/net/ftp/put_spec.rb b/spec/ruby/library/net/ftp/put_spec.rb
deleted file mode 100644
index 61a8d00543..0000000000
--- a/spec/ruby/library/net/ftp/put_spec.rb
+++ /dev/null
@@ -1,21 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../spec_helper', __FILE__)
-require File.expand_path('../fixtures/server', __FILE__)
-require File.expand_path('../shared/puttextfile', __FILE__)
-require File.expand_path('../shared/putbinaryfile', __FILE__)
-
-describe "Net::FTP#put (binary mode)" do
- before :each do
- @binary_mode = true
- end
-
- it_behaves_like :net_ftp_putbinaryfile, :put
-end
-
-describe "Net::FTP#put (text mode)" do
- before :each do
- @binary_mode = false
- end
-
- it_behaves_like :net_ftp_puttextfile, :put
-end
diff --git a/spec/ruby/library/net/ftp/putbinaryfile_spec.rb b/spec/ruby/library/net/ftp/putbinaryfile_spec.rb
deleted file mode 100644
index 18955409b6..0000000000
--- a/spec/ruby/library/net/ftp/putbinaryfile_spec.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../spec_helper', __FILE__)
-require File.expand_path('../fixtures/server', __FILE__)
-require File.expand_path('../shared/putbinaryfile', __FILE__)
-
-describe "Net::FTP#putbinaryfile" do
- it_behaves_like :net_ftp_putbinaryfile, :putbinaryfile
-end
diff --git a/spec/ruby/library/net/ftp/puttextfile_spec.rb b/spec/ruby/library/net/ftp/puttextfile_spec.rb
deleted file mode 100644
index 2ca6e98c92..0000000000
--- a/spec/ruby/library/net/ftp/puttextfile_spec.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../spec_helper', __FILE__)
-require File.expand_path('../fixtures/server', __FILE__)
-require File.expand_path('../shared/puttextfile', __FILE__)
-
-describe "Net::FTP#puttextfile" do
- it_behaves_like :net_ftp_puttextfile, :puttextfile
-end
diff --git a/spec/ruby/library/net/ftp/pwd_spec.rb b/spec/ruby/library/net/ftp/pwd_spec.rb
deleted file mode 100644
index d5438d8e56..0000000000
--- a/spec/ruby/library/net/ftp/pwd_spec.rb
+++ /dev/null
@@ -1,53 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../spec_helper', __FILE__)
-require File.expand_path('../fixtures/server', __FILE__)
-
-describe "Net::FTP#pwd" do
- before :each do
- @server = NetFTPSpecs::DummyFTP.new
- @server.serve_once
-
- @ftp = Net::FTP.new
- @ftp.connect(@server.hostname, @server.server_port)
- end
-
- after :each do
- @ftp.quit rescue nil
- @ftp.close
- @server.stop
- end
-
- it "sends the PWD command to the server" do
- @ftp.pwd
- @ftp.last_response.should == "257 \"/some/dir/\" - current directory\n"
- end
-
- it "returns the current directory" do
- @ftp.pwd.should == "/some/dir/"
- end
-
- it "raises a Net::FTPPermError when the response code is 500" do
- @server.should_receive(:pwd).and_respond("500 Syntax error, command unrecognized.")
- lambda { @ftp.pwd }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPPermError when the response code is 501" do
- @server.should_receive(:pwd).and_respond("501 Syntax error in parameters or arguments.")
- lambda { @ftp.pwd }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPPermError when the response code is 502" do
- @server.should_receive(:pwd).and_respond("502 Command not implemented.")
- lambda { @ftp.pwd }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPTempError when the response code is 421" do
- @server.should_receive(:pwd).and_respond("421 Service not available, closing control connection.")
- lambda { @ftp.pwd }.should raise_error(Net::FTPTempError)
- end
-
- it "raises a Net::FTPPermError when the response code is 550" do
- @server.should_receive(:pwd).and_respond("550 Requested action not taken.")
- lambda { @ftp.pwd }.should raise_error(Net::FTPPermError)
- end
-end
diff --git a/spec/ruby/library/net/ftp/quit_spec.rb b/spec/ruby/library/net/ftp/quit_spec.rb
deleted file mode 100644
index c053641939..0000000000
--- a/spec/ruby/library/net/ftp/quit_spec.rb
+++ /dev/null
@@ -1,33 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../spec_helper', __FILE__)
-require File.expand_path('../fixtures/server', __FILE__)
-
-describe "Net::FTP#quit" do
- before :each do
- @server = NetFTPSpecs::DummyFTP.new
- @server.serve_once
-
- @ftp = Net::FTP.new
- @ftp.connect(@server.hostname, @server.server_port)
- end
-
- after :each do
- @ftp.quit rescue nil
- @ftp.close
- @server.stop
- end
-
- it "sends the QUIT command to the server" do
- @ftp.quit
- @ftp.last_response.should == "221 OK, bye\n"
- end
-
- it "does not close the socket automagically" do
- @ftp.quit
- @ftp.closed?.should be_false
- end
-
- it "returns nil" do
- @ftp.quit.should be_nil
- end
-end
diff --git a/spec/ruby/library/net/ftp/rename_spec.rb b/spec/ruby/library/net/ftp/rename_spec.rb
deleted file mode 100644
index 0216d2059a..0000000000
--- a/spec/ruby/library/net/ftp/rename_spec.rb
+++ /dev/null
@@ -1,94 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../spec_helper', __FILE__)
-require File.expand_path('../fixtures/server', __FILE__)
-
-describe "Net::FTP#rename" do
- before :each do
- @server = NetFTPSpecs::DummyFTP.new
- @server.serve_once
-
- @ftp = Net::FTP.new
- @ftp.connect(@server.hostname, @server.server_port)
- end
-
- after :each do
- @ftp.quit rescue nil
- @ftp.close
- @server.stop
- end
-
- describe "when passed from_name, to_name" do
- it "sends the RNFR command with the passed from_name and the RNTO command with the passed to_name to the server" do
- @ftp.rename("from.file", "to.file")
- @ftp.last_response.should == "250 Requested file action okay, completed. (Renamed from.file to to.file)\n"
- end
-
- it "returns something" do
- @ftp.rename("from.file", "to.file").should be_nil
- end
- end
-
- describe "when the RNFR command fails" do
- it "raises a Net::FTPTempError when the response code is 450" do
- @server.should_receive(:rnfr).and_respond("450 Requested file action not taken.")
- lambda { @ftp.rename("from.file", "to.file") }.should raise_error(Net::FTPTempError)
- end
-
- it "raises a Net::FTPPermError when the response code is 550" do
- @server.should_receive(:rnfr).and_respond("550 Requested action not taken.")
- lambda { @ftp.rename("from.file", "to.file") }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPPermError when the response code is 501" do
- @server.should_receive(:rnfr).and_respond("501 Syntax error in parameters or arguments.")
- lambda { @ftp.rename("from.file", "to.file") }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPPermError when the response code is 502" do
- @server.should_receive(:rnfr).and_respond("502 Command not implemented.")
- lambda { @ftp.rename("from.file", "to.file") }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPTempError when the response code is 421" do
- @server.should_receive(:rnfr).and_respond("421 Service not available, closing control connection.")
- lambda { @ftp.rename("from.file", "to.file") }.should raise_error(Net::FTPTempError)
- end
-
- it "raises a Net::FTPPermError when the response code is 530" do
- @server.should_receive(:rnfr).and_respond("530 Not logged in.")
- lambda { @ftp.rename("from.file", "to.file") }.should raise_error(Net::FTPPermError)
- end
- end
-
- describe "when the RNTO command fails" do
- it "raises a Net::FTPPermError when the response code is 532" do
- @server.should_receive(:rnfr).and_respond("532 Need account for storing files.")
- lambda { @ftp.rename("from.file", "to.file") }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPPermError when the response code is 553" do
- @server.should_receive(:rnto).and_respond("553 Requested action not taken.")
- lambda { @ftp.rename("from.file", "to.file") }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPPermError when the response code is 501" do
- @server.should_receive(:rnto).and_respond("501 Syntax error in parameters or arguments.")
- lambda { @ftp.rename("from.file", "to.file") }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPPermError when the response code is 502" do
- @server.should_receive(:rnto).and_respond("502 Command not implemented.")
- lambda { @ftp.rename("from.file", "to.file") }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPTempError when the response code is 421" do
- @server.should_receive(:rnto).and_respond("421 Service not available, closing control connection.")
- lambda { @ftp.rename("from.file", "to.file") }.should raise_error(Net::FTPTempError)
- end
-
- it "raises a Net::FTPPermError when the response code is 530" do
- @server.should_receive(:rnto).and_respond("530 Not logged in.")
- lambda { @ftp.rename("from.file", "to.file") }.should raise_error(Net::FTPPermError)
- end
- end
-end
diff --git a/spec/ruby/library/net/ftp/resume_spec.rb b/spec/ruby/library/net/ftp/resume_spec.rb
deleted file mode 100644
index 9ec4a921aa..0000000000
--- a/spec/ruby/library/net/ftp/resume_spec.rb
+++ /dev/null
@@ -1,23 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../spec_helper', __FILE__)
-
-describe "Net::FTP#resume" do
- it "returns true when self is set to resume uploads/downloads" do
- ftp = Net::FTP.new
- ftp.resume.should be_false
-
- ftp.resume = true
- ftp.resume.should be_true
- end
-end
-
-describe "Net::FTP#resume=" do
- it "sets self to resume uploads/downloads when set to true" do
- ftp = Net::FTP.new
- ftp.resume = true
- ftp.resume.should be_true
-
- ftp.resume = false
- ftp.resume.should be_false
- end
-end
diff --git a/spec/ruby/library/net/ftp/retrbinary_spec.rb b/spec/ruby/library/net/ftp/retrbinary_spec.rb
deleted file mode 100644
index fd7af0b62a..0000000000
--- a/spec/ruby/library/net/ftp/retrbinary_spec.rb
+++ /dev/null
@@ -1,30 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../spec_helper', __FILE__)
-require File.expand_path('../fixtures/server', __FILE__)
-
-describe "Net::FTP#retrbinary" do
- before :each do
- @server = NetFTPSpecs::DummyFTP.new
- @server.serve_once
-
- @ftp = Net::FTP.new
- @ftp.connect(@server.hostname, @server.server_port)
- end
-
- after :each do
- @ftp.quit rescue nil
- @ftp.close
- @server.stop
- end
-
- it "sends the passed command to the server" do
- @ftp.retrbinary("RETR test", 4096) {}
- @ftp.last_response.should == "226 Closing data connection. (RETR test)\n"
- end
-
- it "yields the received content as binary blocks of the passed size" do
- res = []
- @ftp.retrbinary("RETR test", 10) { |bin| res << bin }
- res.should == [ "This is th", "e content\n", "of the fil", "e named 't", "est'.\n" ]
- end
-end
diff --git a/spec/ruby/library/net/ftp/retrlines_spec.rb b/spec/ruby/library/net/ftp/retrlines_spec.rb
deleted file mode 100644
index cb8d48ecf7..0000000000
--- a/spec/ruby/library/net/ftp/retrlines_spec.rb
+++ /dev/null
@@ -1,34 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../spec_helper', __FILE__)
-require File.expand_path('../fixtures/server', __FILE__)
-
-describe "Net::FTP#retrlines" do
- before :each do
- @server = NetFTPSpecs::DummyFTP.new
- @server.serve_once
-
- @ftp = Net::FTP.new
- @ftp.connect(@server.hostname, @server.server_port)
- end
-
- after :each do
- @ftp.quit rescue nil
- @ftp.close
- @server.stop
- end
-
- it "sends the passed command over the socket" do
- @ftp.retrlines("LIST test.dir") {}
- @ftp.last_response.should == "226 transfer complete (LIST test.dir)\n"
- end
-
- it "yields each received line to the passed block" do
- res = []
- @ftp.retrlines("LIST test.dir") { |x| res << x }
- res.should == [
- "-rw-r--r-- 1 spec staff 507 17 Jul 18:41 last_response_code.rb",
- "-rw-r--r-- 1 spec staff 50 17 Jul 18:41 list.rb",
- "-rw-r--r-- 1 spec staff 48 17 Jul 18:41 pwd.rb"
- ]
- end
-end
diff --git a/spec/ruby/library/net/ftp/return_code_spec.rb b/spec/ruby/library/net/ftp/return_code_spec.rb
deleted file mode 100644
index b6090aeb61..0000000000
--- a/spec/ruby/library/net/ftp/return_code_spec.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../spec_helper', __FILE__)
-
-describe "Net::FTP#return_code" do
- before :each do
- @ftp = Net::FTP.new
- end
-
- it "outputs a warning and returns a newline" do
- lambda do
- @ftp.return_code.should == "\n"
- end.should complain("warning: Net::FTP#return_code is obsolete and do nothing\n")
- end
-end
-
-describe "Net::FTP#return_code=" do
- before :each do
- @ftp = Net::FTP.new
- end
-
- it "outputs a warning" do
- lambda { @ftp.return_code = 123 }.should complain("warning: Net::FTP#return_code= is obsolete and do nothing\n")
- end
-end
diff --git a/spec/ruby/library/net/ftp/rmdir_spec.rb b/spec/ruby/library/net/ftp/rmdir_spec.rb
deleted file mode 100644
index 453c7823c4..0000000000
--- a/spec/ruby/library/net/ftp/rmdir_spec.rb
+++ /dev/null
@@ -1,58 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../spec_helper', __FILE__)
-require File.expand_path('../fixtures/server', __FILE__)
-
-describe "Net::FTP#rmdir" do
- before :each do
- @server = NetFTPSpecs::DummyFTP.new
- @server.serve_once
-
- @ftp = Net::FTP.new
- @ftp.connect(@server.hostname, @server.server_port)
- end
-
- after :each do
- @ftp.quit rescue nil
- @ftp.close
- @server.stop
- end
-
- it "sends the RMD command with the passed pathname to the server" do
- @ftp.rmdir("test.folder")
- @ftp.last_response.should == "250 Requested file action okay, completed. (RMD test.folder)\n"
- end
-
- it "returns nil" do
- @ftp.rmdir("test.folder").should be_nil
- end
-
- it "raises a Net::FTPPermError when the response code is 500" do
- @server.should_receive(:rmd).and_respond("500 Syntax error, command unrecognized.")
- lambda { @ftp.rmdir("test.folder") }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPPermError when the response code is 501" do
- @server.should_receive(:rmd).and_respond("501 Syntax error in parameters or arguments.")
- lambda { @ftp.rmdir("test.folder") }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPPermError when the response code is 502" do
- @server.should_receive(:rmd).and_respond("502 Command not implemented.")
- lambda { @ftp.rmdir("test.folder") }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPTempError when the response code is 421" do
- @server.should_receive(:rmd).and_respond("421 Service not available, closing control connection.")
- lambda { @ftp.rmdir("test.folder") }.should raise_error(Net::FTPTempError)
- end
-
- it "raises a Net::FTPPermError when the response code is 530" do
- @server.should_receive(:rmd).and_respond("530 Not logged in.")
- lambda { @ftp.rmdir("test.folder") }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPPermError when the response code is 550" do
- @server.should_receive(:rmd).and_respond("550 Requested action not taken.")
- lambda { @ftp.rmdir("test.folder") }.should raise_error(Net::FTPPermError)
- end
-end
diff --git a/spec/ruby/library/net/ftp/sendcmd_spec.rb b/spec/ruby/library/net/ftp/sendcmd_spec.rb
deleted file mode 100644
index 9bdca621bc..0000000000
--- a/spec/ruby/library/net/ftp/sendcmd_spec.rb
+++ /dev/null
@@ -1,54 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../spec_helper', __FILE__)
-require File.expand_path('../fixtures/server', __FILE__)
-
-describe "Net::FTP#sendcmd" do
- before :each do
- @server = NetFTPSpecs::DummyFTP.new
- @server.serve_once
-
- @ftp = Net::FTP.new
- @ftp.connect(@server.hostname, @server.server_port)
- end
-
- after :each do
- @ftp.quit rescue nil
- @ftp.close
- @server.stop
- end
-
- it "sends the passed command to the server" do
- @ftp.sendcmd("HELP")
- @ftp.last_response.should == "211 System status, or system help reply. (HELP)\n"
- end
-
- it "returns the server's response" do
- @ftp.sendcmd("HELP").should == "211 System status, or system help reply. (HELP)\n"
- end
-
- it "raises no error when the response code is 1xx, 2xx or 3xx" do
- @server.should_receive(:help).and_respond("120 Service ready in nnn minutes.")
- lambda { @ftp.sendcmd("HELP") }.should_not raise_error
-
- @server.should_receive(:help).and_respond("200 Command okay.")
- lambda { @ftp.sendcmd("HELP") }.should_not raise_error
-
- @server.should_receive(:help).and_respond("350 Requested file action pending further information.")
- lambda { @ftp.sendcmd("HELP") }.should_not raise_error
- end
-
- it "raises a Net::FTPTempError when the response code is 4xx" do
- @server.should_receive(:help).and_respond("421 Service not available, closing control connection.")
- lambda { @ftp.sendcmd("HELP") }.should raise_error(Net::FTPTempError)
- end
-
- it "raises a Net::FTPPermError when the response code is 5xx" do
- @server.should_receive(:help).and_respond("500 Syntax error, command unrecognized.")
- lambda { @ftp.sendcmd("HELP") }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPProtoError when the response code is not between 1xx-5xx" do
- @server.should_receive(:help).and_respond("999 Invalid response.")
- lambda { @ftp.sendcmd("HELP") }.should raise_error(Net::FTPProtoError)
- end
-end
diff --git a/spec/ruby/library/net/ftp/set_socket_spec.rb b/spec/ruby/library/net/ftp/set_socket_spec.rb
deleted file mode 100644
index 1553445219..0000000000
--- a/spec/ruby/library/net/ftp/set_socket_spec.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../spec_helper', __FILE__)
-
-describe "Net::FTP#set_socket" do
- # TODO: I won't spec this method, as it is not used
- # anywhere and it should be private anyway.
- #it "needs to be reviewed for spec completeness"
-end
diff --git a/spec/ruby/library/net/ftp/shared/getbinaryfile.rb b/spec/ruby/library/net/ftp/shared/getbinaryfile.rb
deleted file mode 100644
index 2252935b2d..0000000000
--- a/spec/ruby/library/net/ftp/shared/getbinaryfile.rb
+++ /dev/null
@@ -1,150 +0,0 @@
-describe :net_ftp_getbinaryfile, shared: :true do
- before :each do
- @fixture_file = File.dirname(__FILE__) + "/../fixtures/getbinaryfile"
- @tmp_file = tmp("getbinaryfile")
-
- @server = NetFTPSpecs::DummyFTP.new
- @server.serve_once
-
- @ftp = Net::FTP.new
- @ftp.connect(@server.hostname, @server.server_port)
- @ftp.binary = @binary_mode
- end
-
- after :each do
- @ftp.quit rescue nil
- @ftp.close
- @server.stop
-
- rm_r @tmp_file
- end
-
- it "sends the RETR command to the server" do
- @ftp.send(@method, "test", @tmp_file)
- @ftp.last_response.should == "226 Closing data connection. (RETR test)\n"
- end
-
- it "returns nil" do
- @ftp.send(@method, "test", @tmp_file).should be_nil
- end
-
- it "saves the contents of the passed remote file to the passed local file" do
- @ftp.send(@method, "test", @tmp_file)
- File.read(@tmp_file).should == "This is the content\nof the file named 'test'.\n"
- end
-
- describe "when passed a block" do
- it "yields the received content as binary blocks of the passed size" do
- res = []
- @ftp.send(@method, "test", @tmp_file, 10) { |bin| res << bin }
- res.should == [ "This is th", "e content\n", "of the fil", "e named 't", "est'.\n" ]
- end
- end
-
- describe "when resuming an existing file" do
- before :each do
- @tmp_file = tmp("getbinaryfile_resume")
-
- File.open(@tmp_file, "wb") do |f|
- f << "This is the content\n"
- end
-
- @ftp.resume = true
- end
-
- it "saves the remaining content of the passed remote file to the passed local file" do
- @ftp.send(@method, "test", @tmp_file)
- File.read(@tmp_file).should == "This is the content\nof the file named 'test'.\n"
- end
-
- describe "and the REST command fails" do
- it "raises a Net::FTPProtoError when the response code is 550" do
- @server.should_receive(:rest).and_respond("Requested action not taken.")
- lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPProtoError)
- end
-
- it "raises a Net::FTPPermError when the response code is 500" do
- @server.should_receive(:rest).and_respond("500 Syntax error, command unrecognized.")
- lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPPermError when the response code is 501" do
- @server.should_receive(:rest).and_respond("501 Syntax error, command unrecognized.")
- lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPPermError when the response code is 502" do
- @server.should_receive(:rest).and_respond("502 Command not implemented.")
- lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPTempError when the response code is 421" do
- @server.should_receive(:rest).and_respond("421 Service not available, closing control connection.")
- lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPTempError)
- end
-
- it "raises a Net::FTPPermError when the response code is 530" do
- @server.should_receive(:rest).and_respond("530 Not logged in.")
- lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPPermError)
- end
- end
- end
-
- describe "when the RETR command fails" do
- it "raises a Net::FTPTempError when the response code is 450" do
- @server.should_receive(:retr).and_respond("450 Requested file action not taken.")
- lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPTempError)
- end
-
- it "raises a Net::FTPProtoError when the response code is 550" do
- @server.should_receive(:retr).and_respond("Requested action not taken.")
- lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPProtoError)
- end
-
- it "raises a Net::FTPPermError when the response code is 500" do
- @server.should_receive(:retr).and_respond("500 Syntax error, command unrecognized.")
- lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPPermError when the response code is 501" do
- @server.should_receive(:retr).and_respond("501 Syntax error, command unrecognized.")
- lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPTempError when the response code is 421" do
- @server.should_receive(:retr).and_respond("421 Service not available, closing control connection.")
- lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPTempError)
- end
-
- it "raises a Net::FTPPermError when the response code is 530" do
- @server.should_receive(:retr).and_respond("530 Not logged in.")
- lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPPermError)
- end
- end
-
- describe "when opening the data port fails" do
- it "raises a Net::FTPPermError when the response code is 500" do
- @server.should_receive(:eprt).and_respond("500 Syntax error, command unrecognized.")
- @server.should_receive(:port).and_respond("500 Syntax error, command unrecognized.")
- lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPPermError when the response code is 501" do
- @server.should_receive(:eprt).and_respond("501 Syntax error in parameters or arguments.")
- @server.should_receive(:port).and_respond("501 Syntax error in parameters or arguments.")
- lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPTempError when the response code is 421" do
- @server.should_receive(:eprt).and_respond("421 Service not available, closing control connection.")
- @server.should_receive(:port).and_respond("421 Service not available, closing control connection.")
- lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPTempError)
- end
-
- it "raises a Net::FTPPermError when the response code is 530" do
- @server.should_receive(:eprt).and_respond("530 Not logged in.")
- @server.should_receive(:port).and_respond("530 Not logged in.")
- lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPPermError)
- end
- end
-end
diff --git a/spec/ruby/library/net/ftp/shared/gettextfile.rb b/spec/ruby/library/net/ftp/shared/gettextfile.rb
deleted file mode 100644
index 6219581d12..0000000000
--- a/spec/ruby/library/net/ftp/shared/gettextfile.rb
+++ /dev/null
@@ -1,100 +0,0 @@
-describe :net_ftp_gettextfile, shared: :true do
- before :each do
- @tmp_file = tmp("gettextfile")
-
- @server = NetFTPSpecs::DummyFTP.new
- @server.serve_once
-
- @ftp = Net::FTP.new
- @ftp.connect(@server.hostname, @server.server_port)
- @ftp.binary = @binary_mode
- end
-
- after :each do
- @ftp.quit rescue nil
- @ftp.close
- @server.stop
-
- rm_r @tmp_file
- end
-
- it "sends the RETR command to the server" do
- @ftp.send(@method, "test", @tmp_file)
- @ftp.last_response.should == "226 Closing data connection. (RETR test)\n"
- end
-
- it "returns nil" do
- @ftp.send(@method, "test", @tmp_file).should be_nil
- end
-
- it "saves the contents of the passed remote file to the passed local file" do
- @ftp.send(@method, "test", @tmp_file)
- File.read(@tmp_file).should == "This is the content\nof the file named 'test'.\n"
- end
-
- describe "when passed a block" do
- it "yields each line of the retrieved file to the passed block" do
- res = []
- @ftp.send(@method, "test", @tmp_file) { |line| res << line }
- res.should == [ "This is the content", "of the file named 'test'."]
- end
- end
-
- describe "when the RETR command fails" do
- it "raises a Net::FTPTempError when the response code is 450" do
- @server.should_receive(:retr).and_respond("450 Requested file action not taken.")
- lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPTempError)
- end
-
- it "raises a Net::FTPProtoError when the response code is 550" do
- @server.should_receive(:retr).and_respond("Requested action not taken.")
- lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPProtoError)
- end
-
- it "raises a Net::FTPPermError when the response code is 500" do
- @server.should_receive(:retr).and_respond("500 Syntax error, command unrecognized.")
- lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPPermError when the response code is 501" do
- @server.should_receive(:retr).and_respond("501 Syntax error, command unrecognized.")
- lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPTempError when the response code is 421" do
- @server.should_receive(:retr).and_respond("421 Service not available, closing control connection.")
- lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPTempError)
- end
-
- it "raises a Net::FTPPermError when the response code is 530" do
- @server.should_receive(:retr).and_respond("530 Not logged in.")
- lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPPermError)
- end
- end
-
- describe "when opening the data port fails" do
- it "raises a Net::FTPPermError when the response code is 500" do
- @server.should_receive(:eprt).and_respond("500 Syntax error, command unrecognized.")
- @server.should_receive(:port).and_respond("500 Syntax error, command unrecognized.")
- lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPPermError when the response code is 501" do
- @server.should_receive(:eprt).and_respond("501 Syntax error in parameters or arguments.")
- @server.should_receive(:port).and_respond("501 Syntax error in parameters or arguments.")
- lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPTempError when the response code is 421" do
- @server.should_receive(:eprt).and_respond("421 Service not available, closing control connection.")
- @server.should_receive(:port).and_respond("421 Service not available, closing control connection.")
- lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPTempError)
- end
-
- it "raises a Net::FTPPermError when the response code is 530" do
- @server.should_receive(:eprt).and_respond("530 Not logged in.")
- @server.should_receive(:port).and_respond("530 Not logged in.")
- lambda { @ftp.send(@method, "test", @tmp_file) }.should raise_error(Net::FTPPermError)
- end
- end
-end
diff --git a/spec/ruby/library/net/ftp/shared/last_response_code.rb b/spec/ruby/library/net/ftp/shared/last_response_code.rb
deleted file mode 100644
index 4fe53677db..0000000000
--- a/spec/ruby/library/net/ftp/shared/last_response_code.rb
+++ /dev/null
@@ -1,25 +0,0 @@
-describe :net_ftp_last_response_code, shared: true do
- before :each do
- @server = NetFTPSpecs::DummyFTP.new
- @server.serve_once
-
- @ftp = Net::FTP.new
- @ftp.connect(@server.hostname, @server.server_port)
- end
-
- after :each do
- @ftp.quit rescue nil
- @ftp.close
- @server.stop
- end
-
- it "returns the response code for the last response" do
- @server.should_receive(:help).and_respond("200 Command okay.")
- @ftp.help
- @ftp.send(@method).should == "200"
-
- @server.should_receive(:help).and_respond("212 Directory status.")
- @ftp.help
- @ftp.send(@method).should == "212"
- end
-end
diff --git a/spec/ruby/library/net/ftp/shared/list.rb b/spec/ruby/library/net/ftp/shared/list.rb
deleted file mode 100644
index 50ca8ad119..0000000000
--- a/spec/ruby/library/net/ftp/shared/list.rb
+++ /dev/null
@@ -1,104 +0,0 @@
-describe :net_ftp_list, shared: true do
- before :each do
- @server = NetFTPSpecs::DummyFTP.new
- @server.serve_once
-
- @ftp = Net::FTP.new
- @ftp.passive = false
- @ftp.connect(@server.hostname, @server.server_port)
- end
-
- after :each do
- @ftp.quit rescue nil
- @ftp.close
- @server.stop
- end
-
- describe "when passed a block" do
- it "yields each file in the list of files in the passed dir" do
- expected = [
- "-rw-r--r-- 1 spec staff 507 17 Jul 18:41 last_response_code.rb",
- "-rw-r--r-- 1 spec staff 50 17 Jul 18:41 list.rb",
- "-rw-r--r-- 1 spec staff 48 17 Jul 18:41 pwd.rb"
- ]
-
- res = []
- @ftp.send(@method, "test.folder") { |line| res << line}
- res.should == expected
-
- @ftp.last_response.should == "226 transfer complete (LIST test.folder)\n"
- end
- end
-
- describe "when passed no block" do
- it "returns an Array containing a list of files in the passed dir" do
- expected = [
- "-rw-r--r-- 1 spec staff 507 17 Jul 18:41 last_response_code.rb",
- "-rw-r--r-- 1 spec staff 50 17 Jul 18:41 list.rb",
- "-rw-r--r-- 1 spec staff 48 17 Jul 18:41 pwd.rb"
- ]
-
- @ftp.send(@method, "test.folder").should == expected
-
- @ftp.last_response.should == "226 transfer complete (LIST test.folder)\n"
- end
- end
-
- describe "when the LIST command fails" do
- it "raises a Net::FTPTempError when the response code is 450" do
- @server.should_receive(:list).and_respond("450 Requested file action not taken..")
- lambda { @ftp.send(@method) }.should raise_error(Net::FTPTempError)
- end
-
- it "raises a Net::FTPPermError when the response code is 500" do
- @server.should_receive(:list).and_respond("500 Syntax error, command unrecognized.")
- lambda { @ftp.send(@method) }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPPermError when the response code is 501" do
- @server.should_receive(:list).and_respond("501 Syntax error, command unrecognized.")
- lambda { @ftp.send(@method) }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPPermError when the response code is 502" do
- @server.should_receive(:list).and_respond("502 Command not implemented.")
- lambda { @ftp.send(@method) }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPTempError when the response code is 421" do
- @server.should_receive(:list).and_respond("421 Service not available, closing control connection.")
- lambda { @ftp.send(@method) }.should raise_error(Net::FTPTempError)
- end
-
- it "raises a Net::FTPPermError when the response code is 530" do
- @server.should_receive(:list).and_respond("530 Not logged in.")
- lambda { @ftp.send(@method) }.should raise_error(Net::FTPPermError)
- end
- end
-
- describe "when opening the data port fails" do
- it "raises a Net::FTPPermError when the response code is 500" do
- @server.should_receive(:eprt).and_respond("500 Syntax error, command unrecognized.")
- @server.should_receive(:port).and_respond("500 Syntax error, command unrecognized.")
- lambda { @ftp.send(@method) }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPPermError when the response code is 501" do
- @server.should_receive(:eprt).and_respond("501 Syntax error in parameters or arguments.")
- @server.should_receive(:port).and_respond("501 Syntax error in parameters or arguments.")
- lambda { @ftp.send(@method) }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPTempError when the response code is 421" do
- @server.should_receive(:eprt).and_respond("421 Service not available, closing control connection.")
- @server.should_receive(:port).and_respond("421 Service not available, closing control connection.")
- lambda { @ftp.send(@method) }.should raise_error(Net::FTPTempError)
- end
-
- it "raises a Net::FTPPermError when the response code is 530" do
- @server.should_receive(:eprt).and_respond("530 Not logged in.")
- @server.should_receive(:port).and_respond("530 Not logged in.")
- lambda { @ftp.send(@method) }.should raise_error(Net::FTPPermError)
- end
- end
-end
diff --git a/spec/ruby/library/net/ftp/shared/putbinaryfile.rb b/spec/ruby/library/net/ftp/shared/putbinaryfile.rb
deleted file mode 100644
index 74eaf320ae..0000000000
--- a/spec/ruby/library/net/ftp/shared/putbinaryfile.rb
+++ /dev/null
@@ -1,167 +0,0 @@
-describe :net_ftp_putbinaryfile, shared: :true do
- before :each do
- @server = NetFTPSpecs::DummyFTP.new
- @server.serve_once
-
- @local_fixture_file = File.dirname(__FILE__) + "/../fixtures/putbinaryfile"
- @remote_tmp_file = tmp("binaryfile", false)
-
- @ftp = Net::FTP.new
- @ftp.connect(@server.hostname, @server.server_port)
- @ftp.binary = @binary_mode
- end
-
- after :each do
- @ftp.quit rescue nil
- @ftp.close
- @server.stop
-
- rm_r @remote_tmp_file
- end
-
- it "sends the STOR command to the server" do
- @ftp.send(@method, @local_fixture_file, "binary")
- @ftp.last_response.should == "200 OK, Data received. (STOR binary)\n"
- end
-
- it "sends the contents of the passed local_file, without modifications" do
- @ftp.send(@method, @local_fixture_file, "binary")
-
- remote_lines = File.readlines(@remote_tmp_file)
- local_lines = File.readlines(@local_fixture_file)
-
- remote_lines.should == local_lines
- end
-
- it "returns nil" do
- @ftp.send(@method, @local_fixture_file, "binary").should be_nil
- end
-
- describe "when passed a block" do
- it "yields the transmitted content as binary blocks of the passed size" do
- res = []
- @ftp.send(@method, @local_fixture_file, "binary", 10) { |x| res << x }
- res.should == [
- "This is an", " example f",
- "ile\nwhich ", "is going t",
- "o be trans", "mitted\nusi",
- "ng #putbin", "aryfile.\n"
- ]
- end
- end
-
- describe "when resuming an existing file" do
- before :each do
- File.open(@remote_tmp_file, "w") do |f|
- f << "This is an example file\n"
- end
-
- @ftp.resume = true
- end
-
- it "sends the remaining content of the passed local_file to the passed remote_file" do
- @ftp.send(@method, @local_fixture_file, "binary")
- File.read(@remote_tmp_file).should == File.read(@local_fixture_file)
- end
-
- describe "and the APPE command fails" do
- it "raises a Net::FTPProtoError when the response code is 550" do
- @server.should_receive(:appe).and_respond("Requested action not taken.")
- lambda { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPProtoError)
- end
-
- it "raises a Net::FTPPermError when the response code is 500" do
- @server.should_receive(:appe).and_respond("500 Syntax error, command unrecognized.")
- lambda { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPPermError when the response code is 501" do
- @server.should_receive(:appe).and_respond("501 Syntax error, command unrecognized.")
- lambda { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPPermError when the response code is 502" do
- @server.should_receive(:appe).and_respond("502 Command not implemented.")
- lambda { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPTempError when the response code is 421" do
- @server.should_receive(:appe).and_respond("421 Service not available, closing control connection.")
- lambda { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPTempError)
- end
-
- it "raises a Net::FTPPermError when the response code is 530" do
- @server.should_receive(:appe).and_respond("530 Not logged in.")
- lambda { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPPermError)
- end
- end
- end
-
- describe "when the STOR command fails" do
- it "raises a Net::FTPPermError when the response code is 532" do
- @server.should_receive(:stor).and_respond("532 Need account for storing files.")
- lambda { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPTempError when the response code is 450" do
- @server.should_receive(:stor).and_respond("450 Requested file action not taken.")
- lambda { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPTempError)
- end
-
- it "raises a Net::FTPTempError when the response code is 452" do
- @server.should_receive(:stor).and_respond("452 Requested action not taken.")
- lambda { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPTempError)
- end
-
- it "raises a Net::FTPPermError when the response code is 553" do
- @server.should_receive(:stor).and_respond("553 Requested action not taken.")
- lambda { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPPermError when the response code is 500" do
- @server.should_receive(:stor).and_respond("500 Syntax error, command unrecognized.")
- lambda { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPPermError when the response code is 501" do
- @server.should_receive(:stor).and_respond("501 Syntax error in parameters or arguments.")
- lambda { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPTempError when the response code is 421" do
- @server.should_receive(:stor).and_respond("421 Service not available, closing control connection.")
- lambda { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPTempError)
- end
-
- it "raises a Net::FTPPermError when the response code is 530" do
- @server.should_receive(:stor).and_respond("530 Not logged in.")
- lambda { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPPermError)
- end
- end
-
- describe "when opening the data port fails" do
- it "raises a Net::FTPPermError when the response code is 500" do
- @server.should_receive(:eprt).and_respond("500 Syntax error, command unrecognized.")
- @server.should_receive(:port).and_respond("500 Syntax error, command unrecognized.")
- lambda { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPPermError when the response code is 501" do
- @server.should_receive(:eprt).and_respond("501 Syntax error in parameters or arguments.")
- @server.should_receive(:port).and_respond("501 Syntax error in parameters or arguments.")
- lambda { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPTempError when the response code is 421" do
- @server.should_receive(:eprt).and_respond("421 Service not available, closing control connection.")
- @server.should_receive(:port).and_respond("421 Service not available, closing control connection.")
- lambda { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPTempError)
- end
-
- it "raises a Net::FTPPermError when the response code is 530" do
- @server.should_receive(:eprt).and_respond("530 Not logged in.")
- @server.should_receive(:port).and_respond("530 Not logged in.")
- lambda { @ftp.send(@method, @local_fixture_file, "binary") }.should raise_error(Net::FTPPermError)
- end
- end
-end
diff --git a/spec/ruby/library/net/ftp/shared/puttextfile.rb b/spec/ruby/library/net/ftp/shared/puttextfile.rb
deleted file mode 100644
index 9bfdc7c41e..0000000000
--- a/spec/ruby/library/net/ftp/shared/puttextfile.rb
+++ /dev/null
@@ -1,120 +0,0 @@
-describe :net_ftp_puttextfile, shared: true do
- before :each do
- @server = NetFTPSpecs::DummyFTP.new
- @server.serve_once
-
- @local_fixture_file = File.dirname(__FILE__) + "/../fixtures/puttextfile"
- @remote_tmp_file = tmp("textfile", false)
-
- @ftp = Net::FTP.new
- @ftp.connect(@server.hostname, @server.server_port)
- @ftp.binary = @binary_mode
- end
-
- after :each do
- @ftp.quit rescue nil
- @ftp.close
- @server.stop
-
- rm_r @remote_tmp_file
- end
-
- it "sends the STOR command to the server" do
- @ftp.send(@method, @local_fixture_file, "text")
- @ftp.last_response.should == "200 OK, Data received. (STOR text)\n"
- end
-
- it "sends the contents of the passed local_file, using \\r\\n as the newline separator" do
- @ftp.send(@method, @local_fixture_file, "text")
-
- remote_lines = open(@remote_tmp_file, "rb") {|f| f.read }
- local_lines = open(@local_fixture_file, "rb") {|f| f.read }
-
- remote_lines.should_not == local_lines
- remote_lines.should == local_lines.gsub("\n", "\r\n")
- end
-
- it "returns nil" do
- @ftp.send(@method, @local_fixture_file, "text").should be_nil
- end
-
- describe "when passed a block" do
- it "yields each transmitted line" do
- res = []
- @ftp.send(@method, @local_fixture_file, "text") { |x| res << x }
- res.should == [
- "This is an example file\r\n",
- "which is going to be transmitted\r\n",
- "using #puttextfile.\r\n"
- ]
- end
- end
-
- describe "when the STOR command fails" do
- it "raises a Net::FTPPermError when the response code is 532" do
- @server.should_receive(:stor).and_respond("532 Need account for storing files.")
- lambda { @ftp.send(@method, @local_fixture_file, "text") }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPTempError when the response code is 450" do
- @server.should_receive(:stor).and_respond("450 Requested file action not taken.")
- lambda { @ftp.send(@method, @local_fixture_file, "text") }.should raise_error(Net::FTPTempError)
- end
-
- it "raises a Net::FTPTempError when the response code is 452" do
- @server.should_receive(:stor).and_respond("452 Requested action not taken.")
- lambda { @ftp.send(@method, @local_fixture_file, "text") }.should raise_error(Net::FTPTempError)
- end
-
- it "raises a Net::FTPPermError when the response code is 553" do
- @server.should_receive(:stor).and_respond("553 Requested action not taken.")
- lambda { @ftp.send(@method, @local_fixture_file, "text") }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPPermError when the response code is 500" do
- @server.should_receive(:stor).and_respond("500 Syntax error, command unrecognized.")
- lambda { @ftp.send(@method, @local_fixture_file, "text") }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPPermError when the response code is 501" do
- @server.should_receive(:stor).and_respond("501 Syntax error in parameters or arguments.")
- lambda { @ftp.send(@method, @local_fixture_file, "text") }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPTempError when the response code is 421" do
- @server.should_receive(:stor).and_respond("421 Service not available, closing control connection.")
- lambda { @ftp.send(@method, @local_fixture_file, "text") }.should raise_error(Net::FTPTempError)
- end
-
- it "raises a Net::FTPPermError when the response code is 530" do
- @server.should_receive(:stor).and_respond("530 Not logged in.")
- lambda { @ftp.send(@method, @local_fixture_file, "text") }.should raise_error(Net::FTPPermError)
- end
- end
-
- describe "when opening the data port fails" do
- it "raises a Net::FTPPermError when the response code is 500" do
- @server.should_receive(:eprt).and_respond("500 Syntax error, command unrecognized.")
- @server.should_receive(:port).and_respond("500 Syntax error, command unrecognized.")
- lambda { @ftp.send(@method, @local_fixture_file, "text") }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPPermError when the response code is 501" do
- @server.should_receive(:eprt).and_respond("501 Syntax error in parameters or arguments.")
- @server.should_receive(:port).and_respond("501 Syntax error in parameters or arguments.")
- lambda { @ftp.send(@method, @local_fixture_file, "text") }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPTempError when the response code is 421" do
- @server.should_receive(:eprt).and_respond("421 Service not available, closing control connection.")
- @server.should_receive(:port).and_respond("421 Service not available, closing control connection.")
- lambda { @ftp.send(@method, @local_fixture_file, "text") }.should raise_error(Net::FTPTempError)
- end
-
- it "raises a Net::FTPPermError when the response code is 530" do
- @server.should_receive(:eprt).and_respond("530 Not logged in.")
- @server.should_receive(:port).and_respond("530 Not logged in.")
- lambda { @ftp.send(@method, @local_fixture_file, "text") }.should raise_error(Net::FTPPermError)
- end
- end
-end
diff --git a/spec/ruby/library/net/ftp/shared/pwd.rb b/spec/ruby/library/net/ftp/shared/pwd.rb
deleted file mode 100644
index 951d020f2d..0000000000
--- a/spec/ruby/library/net/ftp/shared/pwd.rb
+++ /dev/null
@@ -1,3 +0,0 @@
-describe :net_ftp_pwd, shared: true do
-
-end
diff --git a/spec/ruby/library/net/ftp/site_spec.rb b/spec/ruby/library/net/ftp/site_spec.rb
deleted file mode 100644
index d02b94e899..0000000000
--- a/spec/ruby/library/net/ftp/site_spec.rb
+++ /dev/null
@@ -1,53 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../spec_helper', __FILE__)
-require File.expand_path('../fixtures/server', __FILE__)
-
-describe "Net::FTP#site" do
- before :each do
- @server = NetFTPSpecs::DummyFTP.new
- @server.serve_once
-
- @ftp = Net::FTP.new
- @ftp.connect(@server.hostname, @server.server_port)
- end
-
- after :each do
- @ftp.quit rescue nil
- @ftp.close
- @server.stop
- end
-
- it "sends the SITE command with the passed argument to the server" do
- @ftp.site("param")
- @ftp.last_response.should == "200 Command okay. (SITE param)\n"
- end
-
- it "returns nil" do
- @ftp.site("param").should be_nil
- end
-
- it "does not raise an error when the response code is 202" do
- @server.should_receive(:site).and_respond("202 Command not implemented, superfluous at this site.")
- lambda { @ftp.site("param") }.should_not raise_error
- end
-
- it "raises a Net::FTPPermError when the response code is 500" do
- @server.should_receive(:site).and_respond("500 Syntax error, command unrecognized.")
- lambda { @ftp.site("param") }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPPermError when the response code is 501" do
- @server.should_receive(:site).and_respond("501 Syntax error in parameters or arguments.")
- lambda { @ftp.site("param") }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPTempError when the response code is 421" do
- @server.should_receive(:site).and_respond("421 Service not available, closing control connection.")
- lambda { @ftp.site("param") }.should raise_error(Net::FTPTempError)
- end
-
- it "raises a Net::FTPPermError when the response code is 530" do
- @server.should_receive(:site).and_respond("530 Requested action not taken.")
- lambda { @ftp.site("param") }.should raise_error(Net::FTPPermError)
- end
-end
diff --git a/spec/ruby/library/net/ftp/size_spec.rb b/spec/ruby/library/net/ftp/size_spec.rb
deleted file mode 100644
index a3d5db50b4..0000000000
--- a/spec/ruby/library/net/ftp/size_spec.rb
+++ /dev/null
@@ -1,48 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../spec_helper', __FILE__)
-require File.expand_path('../fixtures/server', __FILE__)
-
-describe "Net::FTP#size" do
- before :each do
- @server = NetFTPSpecs::DummyFTP.new
- @server.serve_once
-
- @ftp = Net::FTP.new
- @ftp.connect(@server.hostname, @server.server_port)
- end
-
- after :each do
- @ftp.quit rescue nil
- @ftp.close
- @server.stop
- end
-
- it "sends the SIZE command to the server" do
- @ftp.size("test.file")
- @ftp.last_response.should == "213 1024\n"
- end
-
- it "returns the size of the passed file as Integer" do
- @ftp.size("test.file").should eql(1024)
- end
-
- it "raises a Net::FTPPermError when the response code is 500" do
- @server.should_receive(:size).and_respond("500 Syntax error, command unrecognized.")
- lambda { @ftp.size("test.file") }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPPermError when the response code is 501" do
- @server.should_receive(:size).and_respond("501 Syntax error in parameters or arguments.")
- lambda { @ftp.size("test.file") }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPTempError when the response code is 421" do
- @server.should_receive(:size).and_respond("421 Service not available, closing control connection.")
- lambda { @ftp.size("test.file") }.should raise_error(Net::FTPTempError)
- end
-
- it "raises a Net::FTPPermError when the response code is 550" do
- @server.should_receive(:size).and_respond("550 Requested action not taken.")
- lambda { @ftp.size("test.file") }.should raise_error(Net::FTPPermError)
- end
-end
diff --git a/spec/ruby/library/net/ftp/spec_helper.rb b/spec/ruby/library/net/ftp/spec_helper.rb
deleted file mode 100644
index c87d16218b..0000000000
--- a/spec/ruby/library/net/ftp/spec_helper.rb
+++ /dev/null
@@ -1,5 +0,0 @@
-require "net/ftp"
-
-if defined?(Net::FTP.default_passive)
- Net::FTP.default_passive = false
-end
diff --git a/spec/ruby/library/net/ftp/status_spec.rb b/spec/ruby/library/net/ftp/status_spec.rb
deleted file mode 100644
index 243d3fc175..0000000000
--- a/spec/ruby/library/net/ftp/status_spec.rb
+++ /dev/null
@@ -1,69 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../spec_helper', __FILE__)
-require File.expand_path('../fixtures/server', __FILE__)
-
-describe "Net::FTP#status" do
- before :each do
- @server = NetFTPSpecs::DummyFTP.new
- @server.serve_once
-
- @ftp = Net::FTP.new
- @ftp.connect(@server.hostname, @server.server_port)
- end
-
- after :each do
- @ftp.quit rescue nil
- @ftp.close
- @server.stop
- end
-
- it "sends the STAT command to the server" do
- @ftp.status
- @ftp.last_response.should == "211 System status, or system help reply. (STAT)\n"
- end
-
- ruby_version_is "2.4" do
- it "sends the STAT command with an optional parameter to the server" do
- @ftp.status("/pub").should == "211 System status, or system help reply. (STAT /pub)\n"
- end
- end
-
- it "returns the received information" do
- @ftp.status.should == "211 System status, or system help reply. (STAT)\n"
- end
-
- it "does not raise an error when the response code is 212" do
- @server.should_receive(:stat).and_respond("212 Directory status.")
- lambda { @ftp.status }.should_not raise_error
- end
-
- it "does not raise an error when the response code is 213" do
- @server.should_receive(:stat).and_respond("213 File status.")
- lambda { @ftp.status }.should_not raise_error
- end
-
- it "raises a Net::FTPPermError when the response code is 500" do
- @server.should_receive(:stat).and_respond("500 Syntax error, command unrecognized.")
- lambda { @ftp.status }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPPermError when the response code is 501" do
- @server.should_receive(:stat).and_respond("501 Syntax error in parameters or arguments.")
- lambda { @ftp.status }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPPermError when the response code is 502" do
- @server.should_receive(:stat).and_respond("502 Command not implemented.")
- lambda { @ftp.status }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPTempError when the response code is 421" do
- @server.should_receive(:stat).and_respond("421 Service not available, closing control connection.")
- lambda { @ftp.status }.should raise_error(Net::FTPTempError)
- end
-
- it "raises a Net::FTPPermError when the response code is 530" do
- @server.should_receive(:stat).and_respond("530 Requested action not taken.")
- lambda { @ftp.status }.should raise_error(Net::FTPPermError)
- end
-end
diff --git a/spec/ruby/library/net/ftp/storbinary_spec.rb b/spec/ruby/library/net/ftp/storbinary_spec.rb
deleted file mode 100644
index fc7561b5a9..0000000000
--- a/spec/ruby/library/net/ftp/storbinary_spec.rb
+++ /dev/null
@@ -1,48 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../spec_helper', __FILE__)
-require File.expand_path('../fixtures/server', __FILE__)
-
-describe "Net::FTP#storbinary" do
- before :each do
- @server = NetFTPSpecs::DummyFTP.new
- @server.serve_once
-
- @local_fixture_file = File.dirname(__FILE__) + "/fixtures/putbinaryfile"
- @tmp_file = tmp("binaryfile", false)
-
- @ftp = Net::FTP.new
- @ftp.connect(@server.hostname, @server.server_port)
- end
-
- after :each do
- @ftp.quit rescue nil
- @ftp.close
- @server.stop
-
- rm_r @tmp_file
- end
-
- it "sends the passed command and the passed File object's content to the server" do
- File.open(@local_fixture_file) do |f|
- f.binmode
-
- @ftp.storbinary("STOR binary", f, 4096) {}
- @ftp.last_response.should == "200 OK, Data received. (STOR binary)\n"
- end
- end
-
- it "yields the transmitted content as binary blocks of the passed size" do
- File.open(@local_fixture_file) do |f|
- f.binmode
-
- res = []
- @ftp.storbinary("STOR binary", f, 10) { |x| res << x }
- res.should == [
- "This is an", " example f",
- "ile\nwhich ", "is going t",
- "o be trans", "mitted\nusi",
- "ng #putbin", "aryfile.\n"
- ]
- end
- end
-end
diff --git a/spec/ruby/library/net/ftp/storlines_spec.rb b/spec/ruby/library/net/ftp/storlines_spec.rb
deleted file mode 100644
index 9ea4b83603..0000000000
--- a/spec/ruby/library/net/ftp/storlines_spec.rb
+++ /dev/null
@@ -1,43 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../spec_helper', __FILE__)
-require File.expand_path('../fixtures/server', __FILE__)
-
-describe "Net::FTP#storlines" do
- before :each do
- @server = NetFTPSpecs::DummyFTP.new
- @server.serve_once
-
- @local_fixture_file = File.dirname(__FILE__) + "/fixtures/puttextfile"
- @tmp_file = tmp("textfile", false)
-
- @ftp = Net::FTP.new
- @ftp.connect(@server.hostname, @server.server_port)
- end
-
- after :each do
- @ftp.quit rescue nil
- @ftp.close
- @server.stop
-
- rm_r @tmp_file
- end
-
- it "sends the passed command and the passed File object's content to the server" do
- File.open(@local_fixture_file) do |f|
- @ftp.storlines("STOR text", f) {}
- @ftp.last_response.should == "200 OK, Data received. (STOR text)\n"
- end
- end
-
- it "yields each line of the transmitted content" do
- File.open(@local_fixture_file) do |f|
- res = []
- @ftp.storlines("STOR text", f) { |x| res << x }
- res.should == [
- "This is an example file\r\n",
- "which is going to be transmitted\r\n",
- "using #puttextfile.\r\n"
- ]
- end
- end
-end
diff --git a/spec/ruby/library/net/ftp/system_spec.rb b/spec/ruby/library/net/ftp/system_spec.rb
deleted file mode 100644
index 603dd09152..0000000000
--- a/spec/ruby/library/net/ftp/system_spec.rb
+++ /dev/null
@@ -1,48 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../spec_helper', __FILE__)
-require File.expand_path('../fixtures/server', __FILE__)
-
-describe "Net::FTP#system" do
- before :each do
- @server = NetFTPSpecs::DummyFTP.new
- @server.serve_once
-
- @ftp = Net::FTP.new
- @ftp.connect(@server.hostname, @server.server_port)
- end
-
- after :each do
- @ftp.quit rescue nil
- @ftp.close
- @server.stop
- end
-
- it "sends the SYST command to the server" do
- @ftp.system
- @ftp.last_response.should =~ /\A215 FTP Dummy Server \(SYST\)\Z/
- end
-
- it "returns the received information" do
- @ftp.system.should =~ /\AFTP Dummy Server \(SYST\)\Z/
- end
-
- it "raises a Net::FTPPermError when the response code is 500" do
- @server.should_receive(:syst).and_respond("500 Syntax error, command unrecognized.")
- lambda { @ftp.system }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPPermError when the response code is 501" do
- @server.should_receive(:syst).and_respond("501 Syntax error in parameters or arguments.")
- lambda { @ftp.system }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPPermError when the response code is 502" do
- @server.should_receive(:syst).and_respond("502 Command not implemented.")
- lambda { @ftp.system }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPTempError when the response code is 421" do
- @server.should_receive(:syst).and_respond("421 Service not available, closing control connection.")
- lambda { @ftp.system }.should raise_error(Net::FTPTempError)
- end
-end
diff --git a/spec/ruby/library/net/ftp/voidcmd_spec.rb b/spec/ruby/library/net/ftp/voidcmd_spec.rb
deleted file mode 100644
index 8b3e0c17c9..0000000000
--- a/spec/ruby/library/net/ftp/voidcmd_spec.rb
+++ /dev/null
@@ -1,54 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../spec_helper', __FILE__)
-require File.expand_path('../fixtures/server', __FILE__)
-
-describe "Net::FTP#voidcmd" do
- before :each do
- @server = NetFTPSpecs::DummyFTP.new
- @server.serve_once
-
- @ftp = Net::FTP.new
- @ftp.connect(@server.hostname, @server.server_port)
- end
-
- after :each do
- @ftp.quit rescue nil
- @ftp.close
- @server.stop
- end
-
- it "sends the passed command to the server" do
- @server.should_receive(:help).and_respond("2xx Does not raise.")
- lambda { @ftp.voidcmd("HELP") }.should_not raise_error
- end
-
- it "returns nil" do
- @server.should_receive(:help).and_respond("2xx Does not raise.")
- @ftp.voidcmd("HELP").should be_nil
- end
-
- it "raises a Net::FTPReplyError when the response code is 1xx" do
- @server.should_receive(:help).and_respond("1xx Does raise a Net::FTPReplyError.")
- lambda { @ftp.voidcmd("HELP") }.should raise_error(Net::FTPReplyError)
- end
-
- it "raises a Net::FTPReplyError when the response code is 3xx" do
- @server.should_receive(:help).and_respond("3xx Does raise a Net::FTPReplyError.")
- lambda { @ftp.voidcmd("HELP") }.should raise_error(Net::FTPReplyError)
- end
-
- it "raises a Net::FTPTempError when the response code is 4xx" do
- @server.should_receive(:help).and_respond("4xx Does raise a Net::FTPTempError.")
- lambda { @ftp.voidcmd("HELP") }.should raise_error(Net::FTPTempError)
- end
-
- it "raises a Net::FTPPermError when the response code is 5xx" do
- @server.should_receive(:help).and_respond("5xx Does raise a Net::FTPPermError.")
- lambda { @ftp.voidcmd("HELP") }.should raise_error(Net::FTPPermError)
- end
-
- it "raises a Net::FTPProtoError when the response code is not valid" do
- @server.should_receive(:help).and_respond("999 Does raise a Net::FTPProtoError.")
- lambda { @ftp.voidcmd("HELP") }.should raise_error(Net::FTPProtoError)
- end
-end
diff --git a/spec/ruby/library/net/ftp/welcome_spec.rb b/spec/ruby/library/net/ftp/welcome_spec.rb
deleted file mode 100644
index 5505623ce3..0000000000
--- a/spec/ruby/library/net/ftp/welcome_spec.rb
+++ /dev/null
@@ -1,25 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../spec_helper', __FILE__)
-require File.expand_path('../fixtures/server', __FILE__)
-
-describe "Net::FTP#welcome" do
- before :each do
- @server = NetFTPSpecs::DummyFTP.new
- @server.serve_once
-
- @ftp = Net::FTP.new
- @ftp.connect(@server.hostname, @server.server_port)
- end
-
- after :each do
- @ftp.quit rescue nil
- @ftp.close
- @server.stop
- end
-
- it "returns the server's welcome message" do
- @ftp.welcome.should be_nil
- @ftp.login
- @ftp.welcome.should == "230 User logged in, proceed. (USER anonymous)\n"
- end
-end
diff --git a/spec/ruby/library/net/http/HTTPBadResponse_spec.rb b/spec/ruby/library/net/http/HTTPBadResponse_spec.rb
deleted file mode 100644
index 78bb0c8420..0000000000
--- a/spec/ruby/library/net/http/HTTPBadResponse_spec.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'net/http'
-
-describe "Net::HTTPBadResponse" do
- it "is a subclass of StandardError" do
- Net::HTTPBadResponse.should < StandardError
- end
-end
diff --git a/spec/ruby/library/net/http/HTTPError_spec.rb b/spec/ruby/library/net/http/HTTPError_spec.rb
deleted file mode 100644
index 5fa87f140b..0000000000
--- a/spec/ruby/library/net/http/HTTPError_spec.rb
+++ /dev/null
@@ -1,12 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'net/http'
-
-describe "Net::HTTPError" do
- it "is a subclass of Net::ProtocolError" do
- Net::HTTPError.should < Net::ProtocolError
- end
-
- it "includes the Net::HTTPExceptions module" do
- Net::HTTPError.should < Net::HTTPExceptions
- end
-end
diff --git a/spec/ruby/library/net/http/HTTPFatalError_spec.rb b/spec/ruby/library/net/http/HTTPFatalError_spec.rb
deleted file mode 100644
index 72468faf8d..0000000000
--- a/spec/ruby/library/net/http/HTTPFatalError_spec.rb
+++ /dev/null
@@ -1,12 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'net/http'
-
-describe "Net::HTTPFatalError" do
- it "is a subclass of Net::ProtoFatalError" do
- Net::HTTPFatalError.should < Net::ProtoFatalError
- end
-
- it "includes the Net::HTTPExceptions module" do
- Net::HTTPFatalError.should < Net::HTTPExceptions
- end
-end
diff --git a/spec/ruby/library/net/http/HTTPHeaderSyntaxError_spec.rb b/spec/ruby/library/net/http/HTTPHeaderSyntaxError_spec.rb
deleted file mode 100644
index 3e7ee24365..0000000000
--- a/spec/ruby/library/net/http/HTTPHeaderSyntaxError_spec.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'net/http'
-
-describe "Net::HTTPHeaderSyntaxError" do
- it "is a subclass of StandardError" do
- Net::HTTPHeaderSyntaxError.should < StandardError
- end
-end
diff --git a/spec/ruby/library/net/http/HTTPRetriableError_spec.rb b/spec/ruby/library/net/http/HTTPRetriableError_spec.rb
deleted file mode 100644
index 71f6bdb196..0000000000
--- a/spec/ruby/library/net/http/HTTPRetriableError_spec.rb
+++ /dev/null
@@ -1,12 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'net/http'
-
-describe "Net::HTTPRetriableError" do
- it "is a subclass of Net::ProtoRetriableError" do
- Net::HTTPRetriableError.should < Net::ProtoRetriableError
- end
-
- it "includes the Net::HTTPExceptions module" do
- Net::HTTPRetriableError.should < Net::HTTPExceptions
- end
-end
diff --git a/spec/ruby/library/net/http/HTTPServerException_spec.rb b/spec/ruby/library/net/http/HTTPServerException_spec.rb
deleted file mode 100644
index 35566ab0c5..0000000000
--- a/spec/ruby/library/net/http/HTTPServerException_spec.rb
+++ /dev/null
@@ -1,12 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require 'net/http'
-
-describe "Net::HTTPServerException" do
- it "is a subclass of Net::ProtoServerError" do
- Net::HTTPServerException.should < Net::ProtoServerError
- end
-
- it "includes the Net::HTTPExceptions module" do
- Net::HTTPServerException.should < Net::HTTPExceptions
- end
-end
diff --git a/spec/ruby/library/net/http/http/Proxy_spec.rb b/spec/ruby/library/net/http/http/Proxy_spec.rb
deleted file mode 100644
index 2de3fb2d75..0000000000
--- a/spec/ruby/library/net/http/http/Proxy_spec.rb
+++ /dev/null
@@ -1,35 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-
-describe "Net::HTTP.Proxy" do
- it "returns a new subclass of Net::HTTP" do
- Net::HTTP.Proxy("localhost").should < Net::HTTP
- end
-
- it "returns Net::HTTP when the passed address is nil" do
- Net::HTTP.Proxy(nil).should == Net::HTTP
- end
-
- it "sets the returned subclasses' proxy options based on the passed arguments" do
- http_with_proxy = Net::HTTP.Proxy("localhost", 1234, "rspec", "rocks")
- http_with_proxy.proxy_address.should == "localhost"
- http_with_proxy.proxy_port.should eql(1234)
- http_with_proxy.proxy_user.should == "rspec"
- http_with_proxy.proxy_pass.should == "rocks"
- end
-end
-
-describe "Net::HTTP#proxy?" do
- describe "when self is no proxy class instance" do
- it "returns false" do
- Net::HTTP.new("localhost", 3333).proxy?.should be_false
- end
- end
-
- describe "when self is a proxy class instance" do
- it "returns false" do
- http_with_proxy = Net::HTTP.Proxy("localhost", 1234, "rspec", "rocks")
- http_with_proxy.new("localhost", 3333).proxy?.should be_true
- end
- end
-end
diff --git a/spec/ruby/library/net/http/http/active_spec.rb b/spec/ruby/library/net/http/http/active_spec.rb
deleted file mode 100644
index 28f1872fa9..0000000000
--- a/spec/ruby/library/net/http/http/active_spec.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../fixtures/http_server', __FILE__)
-require File.expand_path('../shared/started', __FILE__)
-
-describe "Net::HTTP#active?" do
- it_behaves_like :net_http_started_p, :active?
-end
diff --git a/spec/ruby/library/net/http/http/address_spec.rb b/spec/ruby/library/net/http/http/address_spec.rb
deleted file mode 100644
index a0fe28fb9e..0000000000
--- a/spec/ruby/library/net/http/http/address_spec.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-
-describe "Net::HTTP#address" do
- it "returns the current host name" do
- net = Net::HTTP.new("localhost")
- net.address.should == "localhost"
- end
-end
diff --git a/spec/ruby/library/net/http/http/close_on_empty_response_spec.rb b/spec/ruby/library/net/http/http/close_on_empty_response_spec.rb
deleted file mode 100644
index 52bede524e..0000000000
--- a/spec/ruby/library/net/http/http/close_on_empty_response_spec.rb
+++ /dev/null
@@ -1,10 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-
-describe "Net::HTTP#close_on_empty_response" do
- it "needs to be reviewed for spec completeness"
-end
-
-describe "Net::HTTP#close_on_empty_response=" do
- it "needs to be reviewed for spec completeness"
-end
diff --git a/spec/ruby/library/net/http/http/copy_spec.rb b/spec/ruby/library/net/http/http/copy_spec.rb
deleted file mode 100644
index c3c5e784b1..0000000000
--- a/spec/ruby/library/net/http/http/copy_spec.rb
+++ /dev/null
@@ -1,21 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../fixtures/http_server', __FILE__)
-
-describe "Net::HTTP#copy" do
- before :each do
- NetHTTPSpecs.start_server
- @http = Net::HTTP.start("localhost", NetHTTPSpecs.port)
- end
-
- after :each do
- @http.finish if @http.started?
- NetHTTPSpecs.stop_server
- end
-
- it "sends a COPY request to the passed path and returns the response" do
- response = @http.copy("/request")
- response.should be_kind_of(Net::HTTPResponse)
- response.body.should == "Request type: COPY"
- end
-end
diff --git a/spec/ruby/library/net/http/http/default_port_spec.rb b/spec/ruby/library/net/http/http/default_port_spec.rb
deleted file mode 100644
index 8d9b3ac64a..0000000000
--- a/spec/ruby/library/net/http/http/default_port_spec.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-
-describe "Net::HTTP.default_port" do
- it "returns 80" do
- Net::HTTP.http_default_port.should eql(80)
- end
-end
diff --git a/spec/ruby/library/net/http/http/delete_spec.rb b/spec/ruby/library/net/http/http/delete_spec.rb
deleted file mode 100644
index 856d3b3af3..0000000000
--- a/spec/ruby/library/net/http/http/delete_spec.rb
+++ /dev/null
@@ -1,21 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../fixtures/http_server', __FILE__)
-
-describe "Net::HTTP#delete" do
- before :each do
- NetHTTPSpecs.start_server
- @http = Net::HTTP.start("localhost", NetHTTPSpecs.port)
- end
-
- after :each do
- @http.finish if @http.started?
- NetHTTPSpecs.stop_server
- end
-
- it "sends a DELETE request to the passed path and returns the response" do
- response = @http.delete("/request")
- response.should be_kind_of(Net::HTTPResponse)
- response.body.should == "Request type: DELETE"
- end
-end
diff --git a/spec/ruby/library/net/http/http/finish_spec.rb b/spec/ruby/library/net/http/http/finish_spec.rb
deleted file mode 100644
index ccc6878961..0000000000
--- a/spec/ruby/library/net/http/http/finish_spec.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../fixtures/http_server', __FILE__)
-
-describe "Net::HTTP#finish" do
- before :each do
- NetHTTPSpecs.start_server
- @http = Net::HTTP.new("localhost", NetHTTPSpecs.port)
- end
-
- after :each do
- @http.finish if @http.started?
- NetHTTPSpecs.stop_server
- end
-
- describe "when self has been started" do
- it "closes the tcp connection" do
- @http.start
- @http.finish
- @http.started?.should be_false
- end
- end
-
- describe "when self has not been started yet" do
- it "raises an IOError" do
- lambda { @http.finish }.should raise_error(IOError)
- end
- end
-end
diff --git a/spec/ruby/library/net/http/http/fixtures/http_server.rb b/spec/ruby/library/net/http/http/fixtures/http_server.rb
deleted file mode 100644
index 198fef36fb..0000000000
--- a/spec/ruby/library/net/http/http/fixtures/http_server.rb
+++ /dev/null
@@ -1,105 +0,0 @@
-require 'webrick'
-require 'webrick/httpservlet/abstract'
-
-module NetHTTPSpecs
- class NullWriter
- def <<(s) end
- def puts(*args) end
- def print(*args) end
- def printf(*args) end
- end
-
- class SpecServlet < WEBrick::HTTPServlet::AbstractServlet
- def handle(req, res)
- reply(req, res)
- end
-
- %w{ do_GET do_HEAD do_POST do_PUT do_PROPPATCH do_LOCK do_UNLOCK
- do_OPTIONS do_PROPFIND do_DELETE do_MOVE do_COPY
- do_MKCOL do_TRACE }.each do |method|
- alias_method method.to_sym, :handle
- end
- end
-
- class RequestServlet < SpecServlet
- def reply(req, res)
- res.content_type = "text/plain"
- res.body = "Request type: #{req.request_method}"
- end
- end
-
- class RequestBodyServlet < SpecServlet
- def reply(req, res)
- res.content_type = "text/plain"
- res.body = req.body
- end
- end
-
- class RequestHeaderServlet < SpecServlet
- def reply(req, res)
- res.content_type = "text/plain"
- res.body = req.header.inspect
- end
- end
-
- class RequestBasicAuthServlet < SpecServlet
- def reply(req, res)
- res.content_type = "text/plain"
-
- WEBrick::HTTPAuth.basic_auth(req, res, "realm") do |user, pass|
- res.body = "username: #{user}\npassword: #{pass}"
- true
- end
- end
- end
-
- class << self
- @server = nil
- @server_thread = nil
-
- def port
- raise "server not started" unless @server
- @server.config[:Port]
- end
-
- def start_server
- server_config = {
- BindAddress: "localhost",
- Port: 0,
- Logger: WEBrick::Log.new(NullWriter.new),
- AccessLog: [],
- ServerType: Thread
- }
-
- @server = WEBrick::HTTPServer.new(server_config)
-
- @server.mount_proc('/') do |req, res|
- res.content_type = "text/plain"
- res.body = "This is the index page."
- end
- @server.mount('/request', RequestServlet)
- @server.mount("/request/body", RequestBodyServlet)
- @server.mount("/request/header", RequestHeaderServlet)
- @server.mount("/request/basic_auth", RequestBasicAuthServlet)
-
- @server_thread = @server.start
- end
-
- def stop_server
- if @server
- begin
- @server.shutdown
- rescue Errno::EPIPE
- # Because WEBrick is not thread-safe and only catches IOError
- end
- @server = nil
- end
- if @server_thread
- @server_thread.join
- @server_thread = nil
- end
- timeout = WEBrick::Utils::TimeoutHandler
- timeout.terminate if timeout.respond_to?(:terminate)
- end
- end
-end
diff --git a/spec/ruby/library/net/http/http/get2_spec.rb b/spec/ruby/library/net/http/http/get2_spec.rb
deleted file mode 100644
index 2173156adf..0000000000
--- a/spec/ruby/library/net/http/http/get2_spec.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../fixtures/http_server', __FILE__)
-require File.expand_path('../shared/request_get', __FILE__)
-
-describe "Net::HTTP#get2" do
- it_behaves_like :net_ftp_request_get, :get2
-end
diff --git a/spec/ruby/library/net/http/http/get_print_spec.rb b/spec/ruby/library/net/http/http/get_print_spec.rb
deleted file mode 100644
index d91a584aaa..0000000000
--- a/spec/ruby/library/net/http/http/get_print_spec.rb
+++ /dev/null
@@ -1,30 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../fixtures/http_server', __FILE__)
-
-describe "Net::HTTP.get_print" do
- before :each do
- NetHTTPSpecs.start_server
- @port = NetHTTPSpecs.port
- end
-
- after :each do
- NetHTTPSpecs.stop_server
- end
-
- describe "when passed URI" do
- it "it prints the body of the specified uri to $stdout" do
- lambda do
- Net::HTTP.get_print URI.parse("http://localhost:#{@port}/")
- end.should output(/This is the index page\./)
- end
- end
-
- describe "when passed host, path, port" do
- it "it prints the body of the specified uri to $stdout" do
- lambda do
- Net::HTTP.get_print 'localhost', "/", @port
- end.should output(/This is the index page\./)
- end
- end
-end
diff --git a/spec/ruby/library/net/http/http/get_response_spec.rb b/spec/ruby/library/net/http/http/get_response_spec.rb
deleted file mode 100644
index fdc1ae1f66..0000000000
--- a/spec/ruby/library/net/http/http/get_response_spec.rb
+++ /dev/null
@@ -1,30 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../fixtures/http_server', __FILE__)
-
-describe "Net::HTTP.get_response" do
- before :each do
- NetHTTPSpecs.start_server
- @port = NetHTTPSpecs.port
- end
-
- after :each do
- NetHTTPSpecs.stop_server
- end
-
- describe "when passed URI" do
- it "returns the response for the specified uri" do
- res = Net::HTTP.get_response(URI.parse("http://localhost:#{@port}/"))
- res.content_type.should == "text/plain"
- res.body.should == "This is the index page."
- end
- end
-
- describe "when passed host, path, port" do
- it "returns the response for the specified host-path-combination" do
- res = Net::HTTP.get_response('localhost', "/", @port)
- res.content_type.should == "text/plain"
- res.body.should == "This is the index page."
- end
- end
-end
diff --git a/spec/ruby/library/net/http/http/get_spec.rb b/spec/ruby/library/net/http/http/get_spec.rb
deleted file mode 100644
index d434191d2d..0000000000
--- a/spec/ruby/library/net/http/http/get_spec.rb
+++ /dev/null
@@ -1,26 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../fixtures/http_server', __FILE__)
-
-describe "Net::HTTP.get when passed URI" do
- before :each do
- NetHTTPSpecs.start_server
- @port = NetHTTPSpecs.port
- end
-
- after :each do
- NetHTTPSpecs.stop_server
- end
-
- describe "when passed URI" do
- it "returns the body of the specified uri" do
- Net::HTTP.get(URI.parse("http://localhost:#{@port}/")).should == "This is the index page."
- end
- end
-
- describe "when passed host, path, port" do
- it "returns the body of the specified host-path-combination" do
- Net::HTTP.get('localhost', "/", @port).should == "This is the index page."
- end
- end
-end
diff --git a/spec/ruby/library/net/http/http/head2_spec.rb b/spec/ruby/library/net/http/http/head2_spec.rb
deleted file mode 100644
index 66d533c84d..0000000000
--- a/spec/ruby/library/net/http/http/head2_spec.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../fixtures/http_server', __FILE__)
-require File.expand_path('../shared/request_head', __FILE__)
-
-describe "Net::HTTP#head2" do
- it_behaves_like :net_ftp_request_head, :head2
-end
-
diff --git a/spec/ruby/library/net/http/http/head_spec.rb b/spec/ruby/library/net/http/http/head_spec.rb
deleted file mode 100644
index d0d13a6451..0000000000
--- a/spec/ruby/library/net/http/http/head_spec.rb
+++ /dev/null
@@ -1,25 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../fixtures/http_server', __FILE__)
-
-describe "Net::HTTP#head" do
- before :each do
- NetHTTPSpecs.start_server
- @http = Net::HTTP.start("localhost", NetHTTPSpecs.port)
- end
-
- after :each do
- @http.finish if @http.started?
- NetHTTPSpecs.stop_server
- end
-
- it "sends a HEAD request to the passed path and returns the response" do
- response = @http.head("/request")
- # HEAD requests have no responses
- response.body.should be_nil
- end
-
- it "returns a Net::HTTPResponse" do
- @http.head("/request").should be_kind_of(Net::HTTPResponse)
- end
-end
diff --git a/spec/ruby/library/net/http/http/http_default_port_spec.rb b/spec/ruby/library/net/http/http/http_default_port_spec.rb
deleted file mode 100644
index 6b840bbf30..0000000000
--- a/spec/ruby/library/net/http/http/http_default_port_spec.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-
-describe "Net::HTTP.http_default_port" do
- it "returns 80" do
- Net::HTTP.http_default_port.should eql(80)
- end
-end
diff --git a/spec/ruby/library/net/http/http/https_default_port_spec.rb b/spec/ruby/library/net/http/http/https_default_port_spec.rb
deleted file mode 100644
index bd213f2325..0000000000
--- a/spec/ruby/library/net/http/http/https_default_port_spec.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-
-describe "Net::HTTP.https_default_port" do
- it "returns 443" do
- Net::HTTP.https_default_port.should eql(443)
- end
-end
diff --git a/spec/ruby/library/net/http/http/initialize_spec.rb b/spec/ruby/library/net/http/http/initialize_spec.rb
deleted file mode 100644
index 0cd59f493d..0000000000
--- a/spec/ruby/library/net/http/http/initialize_spec.rb
+++ /dev/null
@@ -1,46 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-
-describe "Net::HTTP#initialize" do
- it "is private" do
- Net::HTTP.should have_private_instance_method(:initialize)
- end
-
- describe "when passed address" do
- before :each do
- @net = Net::HTTP.allocate
- @net.send(:initialize, "localhost")
- end
-
- it "sets the new Net::HTTP instance's address to the passed address" do
- @net.address.should == "localhost"
- end
-
- it "sets the new Net::HTTP instance's port to the default HTTP port" do
- @net.port.should eql(Net::HTTP.default_port)
- end
-
- it "does not start the new Net::HTTP instance" do
- @net.started?.should be_false
- end
- end
-
- describe "when passed address, port" do
- before :each do
- @net = Net::HTTP.allocate
- @net.send(:initialize, "localhost", 3333)
- end
-
- it "sets the new Net::HTTP instance's address to the passed address" do
- @net.address.should == "localhost"
- end
-
- it "sets the new Net::HTTP instance's port to the passed port" do
- @net.port.should eql(3333)
- end
-
- it "does not start the new Net::HTTP instance" do
- @net.started?.should be_false
- end
- end
-end
diff --git a/spec/ruby/library/net/http/http/inspect_spec.rb b/spec/ruby/library/net/http/http/inspect_spec.rb
deleted file mode 100644
index 7c5d9bf0eb..0000000000
--- a/spec/ruby/library/net/http/http/inspect_spec.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../fixtures/http_server', __FILE__)
-
-describe "Net::HTTP#inspect" do
- before :each do
- NetHTTPSpecs.start_server
- @port = NetHTTPSpecs.port
- @http = Net::HTTP.new("localhost", @port)
- end
-
- after :each do
- @http.finish if @http.started?
- NetHTTPSpecs.stop_server
- end
-
- it "returns a String representation of self" do
- @http.inspect.should be_kind_of(String)
- @http.inspect.should == "#<Net::HTTP localhost:#{@port} open=false>"
-
- @http.start
- @http.inspect.should == "#<Net::HTTP localhost:#{@port} open=true>"
- end
-end
diff --git a/spec/ruby/library/net/http/http/is_version_1_1_spec.rb b/spec/ruby/library/net/http/http/is_version_1_1_spec.rb
deleted file mode 100644
index 8fa5da6be7..0000000000
--- a/spec/ruby/library/net/http/http/is_version_1_1_spec.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../shared/version_1_1', __FILE__)
-
-describe "Net::HTTP.is_version_1_1?" do
- it_behaves_like :net_http_version_1_1_p, :is_version_1_1?
-end
diff --git a/spec/ruby/library/net/http/http/is_version_1_2_spec.rb b/spec/ruby/library/net/http/http/is_version_1_2_spec.rb
deleted file mode 100644
index 344ac7f7c0..0000000000
--- a/spec/ruby/library/net/http/http/is_version_1_2_spec.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../shared/version_1_2', __FILE__)
-
-describe "Net::HTTP.is_version_1_2?" do
- it_behaves_like :net_http_version_1_2_p, :is_version_1_2?
-end
diff --git a/spec/ruby/library/net/http/http/lock_spec.rb b/spec/ruby/library/net/http/http/lock_spec.rb
deleted file mode 100644
index e44099f9e5..0000000000
--- a/spec/ruby/library/net/http/http/lock_spec.rb
+++ /dev/null
@@ -1,21 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../fixtures/http_server', __FILE__)
-
-describe "Net::HTTP#lock" do
- before :each do
- NetHTTPSpecs.start_server
- @http = Net::HTTP.start("localhost", NetHTTPSpecs.port)
- end
-
- after :each do
- @http.finish if @http.started?
- NetHTTPSpecs.stop_server
- end
-
- it "sends a LOCK request to the passed path and returns the response" do
- response = @http.lock("/request", "test=test")
- response.should be_kind_of(Net::HTTPResponse)
- response.body.should == "Request type: LOCK"
- end
-end
diff --git a/spec/ruby/library/net/http/http/mkcol_spec.rb b/spec/ruby/library/net/http/http/mkcol_spec.rb
deleted file mode 100644
index 51b0a5b9c0..0000000000
--- a/spec/ruby/library/net/http/http/mkcol_spec.rb
+++ /dev/null
@@ -1,21 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../fixtures/http_server', __FILE__)
-
-describe "Net::HTTP#mkcol" do
- before :each do
- NetHTTPSpecs.start_server
- @http = Net::HTTP.start("localhost", NetHTTPSpecs.port)
- end
-
- after :each do
- @http.finish if @http.started?
- NetHTTPSpecs.stop_server
- end
-
- it "sends a MKCOL request to the passed path and returns the response" do
- response = @http.mkcol("/request")
- response.should be_kind_of(Net::HTTPResponse)
- response.body.should == "Request type: MKCOL"
- end
-end
diff --git a/spec/ruby/library/net/http/http/move_spec.rb b/spec/ruby/library/net/http/http/move_spec.rb
deleted file mode 100644
index 0aa00195f8..0000000000
--- a/spec/ruby/library/net/http/http/move_spec.rb
+++ /dev/null
@@ -1,25 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../fixtures/http_server', __FILE__)
-
-describe "Net::HTTP#head" do
- before :each do
- NetHTTPSpecs.start_server
- @http = Net::HTTP.start("localhost", NetHTTPSpecs.port)
- end
-
- after :each do
- @http.finish if @http.started?
- NetHTTPSpecs.stop_server
- end
-
- it "sends a MOVE request to the passed path and returns the response" do
- response = @http.move("/request")
- # HEAD requests have no responses
- response.body.should == "Request type: MOVE"
- end
-
- it "returns a Net::HTTPResponse" do
- @http.move("/request").should be_kind_of(Net::HTTPResponse)
- end
-end
diff --git a/spec/ruby/library/net/http/http/new_spec.rb b/spec/ruby/library/net/http/http/new_spec.rb
deleted file mode 100644
index b741eb0a4c..0000000000
--- a/spec/ruby/library/net/http/http/new_spec.rb
+++ /dev/null
@@ -1,86 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-
-describe "Net::HTTP.new" do
- describe "when passed address" do
- before :each do
- @http = Net::HTTP.new("localhost")
- end
-
- it "returns a Net::HTTP instance" do
- @http.proxy?.should be_false
- @http.instance_of?(Net::HTTP).should be_true
- end
-
- it "sets the new Net::HTTP instance's address to the passed address" do
- @http.address.should == "localhost"
- end
-
- it "sets the new Net::HTTP instance's port to the default HTTP port" do
- @http.port.should eql(Net::HTTP.default_port)
- end
-
- it "does not start the new Net::HTTP instance" do
- @http.started?.should be_false
- end
- end
-
- describe "when passed address, port" do
- before :each do
- @http = Net::HTTP.new("localhost", 3333)
- end
-
- it "returns a Net::HTTP instance" do
- @http.proxy?.should be_false
- @http.instance_of?(Net::HTTP).should be_true
- end
-
- it "sets the new Net::HTTP instance's address to the passed address" do
- @http.address.should == "localhost"
- end
-
- it "sets the new Net::HTTP instance's port to the passed port" do
- @http.port.should eql(3333)
- end
-
- it "does not start the new Net::HTTP instance" do
- @http.started?.should be_false
- end
- end
-
- describe "when passed address, port, *proxy_options" do
- it "returns a Net::HTTP instance" do
- http = Net::HTTP.new("localhost", 3333, "localhost")
- http.proxy?.should be_true
- http.instance_of?(Net::HTTP).should be_true
- http.should be_kind_of(Net::HTTP)
- end
-
- it "correctly sets the passed Proxy options" do
- http = Net::HTTP.new("localhost", 3333, "localhost")
- http.proxy_address.should == "localhost"
- http.proxy_port.should eql(80)
- http.proxy_user.should be_nil
- http.proxy_pass.should be_nil
-
- http = Net::HTTP.new("localhost", 3333, "localhost", 1234)
- http.proxy_address.should == "localhost"
- http.proxy_port.should eql(1234)
- http.proxy_user.should be_nil
- http.proxy_pass.should be_nil
-
- http = Net::HTTP.new("localhost", 3333, "localhost", 1234, "rubyspec")
- http.proxy_address.should == "localhost"
- http.proxy_port.should eql(1234)
- http.proxy_user.should == "rubyspec"
- http.proxy_pass.should be_nil
-
- http = Net::HTTP.new("localhost", 3333, "localhost", 1234, "rubyspec", "rocks")
- http.proxy_address.should == "localhost"
- http.proxy_port.should eql(1234)
- http.proxy_user.should == "rubyspec"
- http.proxy_pass.should == "rocks"
- end
- end
-
-end
diff --git a/spec/ruby/library/net/http/http/newobj_spec.rb b/spec/ruby/library/net/http/http/newobj_spec.rb
deleted file mode 100644
index 88d5881725..0000000000
--- a/spec/ruby/library/net/http/http/newobj_spec.rb
+++ /dev/null
@@ -1,48 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-
-describe "Net::HTTP.newobj" do
- before :each do
- @net = Net::HTTP.newobj("localhost")
- end
-
- describe "when passed address" do
- it "returns a new Net::HTTP instance" do
- @net.should be_kind_of(Net::HTTP)
- end
-
- it "sets the new Net::HTTP instance's address to the passed address" do
- @net.address.should == "localhost"
- end
-
- it "sets the new Net::HTTP instance's port to the default HTTP port" do
- @net.port.should eql(Net::HTTP.default_port)
- end
-
- it "does not start the new Net::HTTP instance" do
- @net.started?.should be_false
- end
- end
-
- describe "when passed address, port" do
- before :each do
- @net = Net::HTTP.newobj("localhost", 3333)
- end
-
- it "returns a new Net::HTTP instance" do
- @net.should be_kind_of(Net::HTTP)
- end
-
- it "sets the new Net::HTTP instance's address to the passed address" do
- @net.address.should == "localhost"
- end
-
- it "sets the new Net::HTTP instance's port to the passed port" do
- @net.port.should eql(3333)
- end
-
- it "does not start the new Net::HTTP instance" do
- @net.started?.should be_false
- end
- end
-end
diff --git a/spec/ruby/library/net/http/http/open_timeout_spec.rb b/spec/ruby/library/net/http/http/open_timeout_spec.rb
deleted file mode 100644
index 0142ae6c06..0000000000
--- a/spec/ruby/library/net/http/http/open_timeout_spec.rb
+++ /dev/null
@@ -1,35 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-
-describe "Net::HTTP#open_timeout" do
- ruby_version_is ""..."2.3" do
- it "returns the seconds to wait till the connection is open" do
- net = Net::HTTP.new("localhost")
- net.open_timeout.should be_nil
- net.open_timeout = 10
- net.open_timeout.should eql(10)
- end
- end
-
- ruby_version_is "2.3" do
- it "returns the seconds to wait till the connection is open" do
- net = Net::HTTP.new("localhost")
- net.open_timeout.should eql(60)
- net.open_timeout = 10
- net.open_timeout.should eql(10)
- end
- end
-end
-
-describe "Net::HTTP#open_timeout=" do
- it "sets the seconds to wait till the connection is open" do
- net = Net::HTTP.new("localhost")
- net.open_timeout = 10
- net.open_timeout.should eql(10)
- end
-
- it "returns the newly set value" do
- net = Net::HTTP.new("localhost")
- (net.open_timeout = 10).should eql(10)
- end
-end
diff --git a/spec/ruby/library/net/http/http/options_spec.rb b/spec/ruby/library/net/http/http/options_spec.rb
deleted file mode 100644
index 9c5e810105..0000000000
--- a/spec/ruby/library/net/http/http/options_spec.rb
+++ /dev/null
@@ -1,25 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../fixtures/http_server', __FILE__)
-
-describe "Net::HTTP#options" do
- before :each do
- NetHTTPSpecs.start_server
- @http = Net::HTTP.start("localhost", NetHTTPSpecs.port)
- end
-
- after :each do
- @http.finish if @http.started?
- NetHTTPSpecs.stop_server
- end
-
- it "sends an options request to the passed path and returns the response" do
- response = @http.options("/request")
-
- response.body.should == "Request type: OPTIONS"
- end
-
- it "returns a Net::HTTPResponse" do
- @http.options("/request").should be_kind_of(Net::HTTPResponse)
- end
-end
diff --git a/spec/ruby/library/net/http/http/port_spec.rb b/spec/ruby/library/net/http/http/port_spec.rb
deleted file mode 100644
index a916f722bf..0000000000
--- a/spec/ruby/library/net/http/http/port_spec.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-
-describe "Net::HTTP#port" do
- it "returns the current port number" do
- net = Net::HTTP.new("localhost", 3333)
- net.port.should eql(3333)
- end
-end
diff --git a/spec/ruby/library/net/http/http/post2_spec.rb b/spec/ruby/library/net/http/http/post2_spec.rb
deleted file mode 100644
index 298b2277bc..0000000000
--- a/spec/ruby/library/net/http/http/post2_spec.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../fixtures/http_server', __FILE__)
-require File.expand_path('../shared/request_post', __FILE__)
-
-describe "Net::HTTP#post2" do
- it_behaves_like :net_ftp_request_post, :post2
-end
diff --git a/spec/ruby/library/net/http/http/post_form_spec.rb b/spec/ruby/library/net/http/http/post_form_spec.rb
deleted file mode 100644
index 4a5d7ec731..0000000000
--- a/spec/ruby/library/net/http/http/post_form_spec.rb
+++ /dev/null
@@ -1,22 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../fixtures/http_server', __FILE__)
-
-describe "Net::HTTP.post_form when passed URI" do
- before :each do
- NetHTTPSpecs.start_server
- @port = NetHTTPSpecs.port
- end
-
- after :each do
- NetHTTPSpecs.stop_server
- end
-
- it "POSTs the passed form data to the given uri" do
- uri = URI.parse("http://localhost:#{@port}/request/body")
- data = { test: :data }
-
- res = Net::HTTP.post_form(uri, data)
- res.body.should == "test=data"
- end
-end
diff --git a/spec/ruby/library/net/http/http/post_spec.rb b/spec/ruby/library/net/http/http/post_spec.rb
deleted file mode 100644
index 66a00f0670..0000000000
--- a/spec/ruby/library/net/http/http/post_spec.rb
+++ /dev/null
@@ -1,77 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require 'uri'
-require File.expand_path('../fixtures/http_server', __FILE__)
-
-ruby_version_is '2.4' do
- describe "Net::HTTP.post" do
- before :each do
- NetHTTPSpecs.start_server
- end
-
- after :each do
- NetHTTPSpecs.stop_server
- end
-
- it "sends post request to the specified URI and returns response" do
- response = Net::HTTP.post(
- URI("http://localhost:#{NetHTTPSpecs.port}/request"),
- '{ "q": "ruby", "max": "50" }',
- "Content-Type" => "application/json")
- response.body.should == "Request type: POST"
- end
-
- it "returns a Net::HTTPResponse" do
- response = Net::HTTP.post(URI("http://localhost:#{NetHTTPSpecs.port}/request"), "test=test")
- response.should be_kind_of(Net::HTTPResponse)
- end
-
- it "sends Content-Type: application/x-www-form-urlencoded by default" do
- response = Net::HTTP.post(URI("http://localhost:#{NetHTTPSpecs.port}/request/header"), "test=test")
- response.body.should include('"content-type"=>["application/x-www-form-urlencoded"]')
- end
-
- it "does not support HTTP Basic Auth" do
- response = Net::HTTP.post(
- URI("http://john:qwerty@localhost:#{NetHTTPSpecs.port}/request/basic_auth"),
- "test=test")
- response.body.should == "username: \npassword: "
- end
- end
-end
-
-describe "Net::HTTP#post" do
- before :each do
- NetHTTPSpecs.start_server
- @http = Net::HTTP.start("localhost", NetHTTPSpecs.port)
- end
-
- after :each do
- @http.finish if @http.started?
- NetHTTPSpecs.stop_server
- end
-
- it "sends an post request to the passed path and returns the response" do
- response = @http.post("/request", "test=test")
- response.body.should == "Request type: POST"
- end
-
- it "returns a Net::HTTPResponse" do
- @http.post("/request", "test=test").should be_kind_of(Net::HTTPResponse)
- end
-
- describe "when passed a block" do
- it "yields fragments of the response body to the passed block" do
- str = ""
- @http.post("/request", "test=test") do |res|
- str << res
- end
- str.should == "Request type: POST"
- end
-
- it "returns a Net::HTTPResponse" do
- @http.post("/request", "test=test") {}.should be_kind_of(Net::HTTPResponse)
- end
- end
-end
-
diff --git a/spec/ruby/library/net/http/http/propfind_spec.rb b/spec/ruby/library/net/http/http/propfind_spec.rb
deleted file mode 100644
index c242eeec68..0000000000
--- a/spec/ruby/library/net/http/http/propfind_spec.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../fixtures/http_server', __FILE__)
-
-describe "Net::HTTP#propfind" do
- before :each do
- NetHTTPSpecs.start_server
- @http = Net::HTTP.start("localhost", NetHTTPSpecs.port)
- end
-
- after :each do
- @http.finish if @http.started?
- NetHTTPSpecs.stop_server
- end
-
- it "sends an propfind request to the passed path and returns the response" do
- response = @http.propfind("/request", "test=test")
- response.body.should == "Request type: PROPFIND"
- end
-
- it "returns a Net::HTTPResponse" do
- @http.propfind("/request", "test=test").should be_kind_of(Net::HTTPResponse)
- end
-end
diff --git a/spec/ruby/library/net/http/http/proppatch_spec.rb b/spec/ruby/library/net/http/http/proppatch_spec.rb
deleted file mode 100644
index 8567f60719..0000000000
--- a/spec/ruby/library/net/http/http/proppatch_spec.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../fixtures/http_server', __FILE__)
-
-describe "Net::HTTP#proppatch" do
- before :each do
- NetHTTPSpecs.start_server
- @http = Net::HTTP.start("localhost", NetHTTPSpecs.port)
- end
-
- after :each do
- @http.finish if @http.started?
- NetHTTPSpecs.stop_server
- end
-
- it "sends an proppatch request to the passed path and returns the response" do
- response = @http.proppatch("/request", "test=test")
- response.body.should == "Request type: PROPPATCH"
- end
-
- it "returns a Net::HTTPResponse" do
- @http.proppatch("/request", "test=test").should be_kind_of(Net::HTTPResponse)
- end
-end
diff --git a/spec/ruby/library/net/http/http/proxy_address_spec.rb b/spec/ruby/library/net/http/http/proxy_address_spec.rb
deleted file mode 100644
index 85f8dfedb4..0000000000
--- a/spec/ruby/library/net/http/http/proxy_address_spec.rb
+++ /dev/null
@@ -1,31 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-
-describe "Net::HTTP.proxy_address" do
- describe "when self is no proxy class" do
- it "returns nil" do
- Net::HTTP.proxy_address.should be_nil
- end
- end
-
- describe "when self is a proxy class" do
- it "returns the address for self's proxy connection" do
- Net::HTTP.Proxy("localhost", 1234, "rspec", "rocks").proxy_address.should == "localhost"
- end
- end
-end
-
-describe "Net::HTTP#proxy_address" do
- describe "when self is no proxy class instance" do
- it "returns nil" do
- Net::HTTP.new("localhost", 3333).proxy_address.should be_nil
- end
- end
-
- describe "when self is a proxy class instance" do
- it "returns the password for self's proxy connection" do
- http_with_proxy = Net::HTTP.Proxy("localhost", 1234, "rspec", "rocks")
- http_with_proxy.new("localhost", 3333).proxy_address.should == "localhost"
- end
- end
-end
diff --git a/spec/ruby/library/net/http/http/proxy_class_spec.rb b/spec/ruby/library/net/http/http/proxy_class_spec.rb
deleted file mode 100644
index 30d38a93e7..0000000000
--- a/spec/ruby/library/net/http/http/proxy_class_spec.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-
-describe "Net::HTTP.proxy_class?" do
- it "returns true if sels is a class created with Net::HTTP.Proxy" do
- Net::HTTP.proxy_class?.should be_false
- Net::HTTP.Proxy("localhost").proxy_class?.should be_true
- end
-end
diff --git a/spec/ruby/library/net/http/http/proxy_pass_spec.rb b/spec/ruby/library/net/http/http/proxy_pass_spec.rb
deleted file mode 100644
index 09db6f2877..0000000000
--- a/spec/ruby/library/net/http/http/proxy_pass_spec.rb
+++ /dev/null
@@ -1,39 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-
-describe "Net::HTTP.proxy_pass" do
- describe "when self is no proxy class" do
- it "returns nil" do
- Net::HTTP.proxy_pass.should be_nil
- end
- end
-
- describe "when self is a proxy class" do
- it "returns nil if no password was set for self's proxy connection" do
- Net::HTTP.Proxy("localhost").proxy_pass.should be_nil
- end
-
- it "returns the password for self's proxy connection" do
- Net::HTTP.Proxy("localhost", 1234, "rspec", "rocks").proxy_pass.should == "rocks"
- end
- end
-end
-
-describe "Net::HTTP#proxy_pass" do
- describe "when self is no proxy class instance" do
- it "returns nil" do
- Net::HTTP.new("localhost", 3333).proxy_pass.should be_nil
- end
- end
-
- describe "when self is a proxy class instance" do
- it "returns nil if no password was set for self's proxy connection" do
- Net::HTTP.Proxy("localhost").new("localhost", 3333).proxy_pass.should be_nil
- end
-
- it "returns the password for self's proxy connection" do
- http_with_proxy = Net::HTTP.Proxy("localhost", 1234, "rspec", "rocks")
- http_with_proxy.new("localhost", 3333).proxy_pass.should == "rocks"
- end
- end
-end
diff --git a/spec/ruby/library/net/http/http/proxy_port_spec.rb b/spec/ruby/library/net/http/http/proxy_port_spec.rb
deleted file mode 100644
index 0655232c6b..0000000000
--- a/spec/ruby/library/net/http/http/proxy_port_spec.rb
+++ /dev/null
@@ -1,39 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-
-describe "Net::HTTP.proxy_port" do
- describe "when self is no proxy class" do
- it "returns nil" do
- Net::HTTP.proxy_port.should be_nil
- end
- end
-
- describe "when self is a proxy class" do
- it "returns 80 if no port was set for self's proxy connection" do
- Net::HTTP.Proxy("localhost").proxy_port.should eql(80)
- end
-
- it "returns the port for self's proxy connection" do
- Net::HTTP.Proxy("localhost", 1234, "rspec", "rocks").proxy_port.should eql(1234)
- end
- end
-end
-
-describe "Net::HTTP#proxy_port" do
- describe "when self is no proxy class instance" do
- it "returns nil" do
- Net::HTTP.new("localhost", 3333).proxy_port.should be_nil
- end
- end
-
- describe "when self is a proxy class instance" do
- it "returns 80 if no port was set for self's proxy connection" do
- Net::HTTP.Proxy("localhost").new("localhost", 3333).proxy_port.should eql(80)
- end
-
- it "returns the port for self's proxy connection" do
- http_with_proxy = Net::HTTP.Proxy("localhost", 1234, "rspec", "rocks")
- http_with_proxy.new("localhost", 3333).proxy_port.should eql(1234)
- end
- end
-end
diff --git a/spec/ruby/library/net/http/http/proxy_user_spec.rb b/spec/ruby/library/net/http/http/proxy_user_spec.rb
deleted file mode 100644
index 1beacca642..0000000000
--- a/spec/ruby/library/net/http/http/proxy_user_spec.rb
+++ /dev/null
@@ -1,39 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-
-describe "Net::HTTP.proxy_user" do
- describe "when self is no proxy class" do
- it "returns nil" do
- Net::HTTP.proxy_user.should be_nil
- end
- end
-
- describe "when self is a proxy class" do
- it "returns nil if no username was set for self's proxy connection" do
- Net::HTTP.Proxy("localhost").proxy_user.should be_nil
- end
-
- it "returns the username for self's proxy connection" do
- Net::HTTP.Proxy("localhost", 1234, "rspec", "rocks").proxy_user.should == "rspec"
- end
- end
-end
-
-describe "Net::HTTP#proxy_user" do
- describe "when self is no proxy class instance" do
- it "returns nil" do
- Net::HTTP.new("localhost", 3333).proxy_user.should be_nil
- end
- end
-
- describe "when self is a proxy class instance" do
- it "returns nil if no username was set for self's proxy connection" do
- Net::HTTP.Proxy("localhost").new("localhost", 3333).proxy_user.should be_nil
- end
-
- it "returns the username for self's proxy connection" do
- http_with_proxy = Net::HTTP.Proxy("localhost", 1234, "rspec", "rocks")
- http_with_proxy.new("localhost", 3333).proxy_user.should == "rspec"
- end
- end
-end
diff --git a/spec/ruby/library/net/http/http/put2_spec.rb b/spec/ruby/library/net/http/http/put2_spec.rb
deleted file mode 100644
index a0e832d170..0000000000
--- a/spec/ruby/library/net/http/http/put2_spec.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../fixtures/http_server', __FILE__)
-require File.expand_path('../shared/request_put', __FILE__)
-
-describe "Net::HTTP#put2" do
- it_behaves_like :net_ftp_request_put, :put2
-end
diff --git a/spec/ruby/library/net/http/http/put_spec.rb b/spec/ruby/library/net/http/http/put_spec.rb
deleted file mode 100644
index ab7e794db0..0000000000
--- a/spec/ruby/library/net/http/http/put_spec.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../fixtures/http_server', __FILE__)
-
-describe "Net::HTTP#put" do
- before :each do
- NetHTTPSpecs.start_server
- @http = Net::HTTP.start("localhost", NetHTTPSpecs.port)
- end
-
- after :each do
- @http.finish if @http.started?
- NetHTTPSpecs.stop_server
- end
-
- it "sends an put request to the passed path and returns the response" do
- response = @http.put("/request", "test=test")
- response.body.should == "Request type: PUT"
- end
-
- it "returns a Net::HTTPResponse" do
- @http.put("/request", "test=test").should be_kind_of(Net::HTTPResponse)
- end
-end
diff --git a/spec/ruby/library/net/http/http/read_timeout_spec.rb b/spec/ruby/library/net/http/http/read_timeout_spec.rb
deleted file mode 100644
index 86f2e0246d..0000000000
--- a/spec/ruby/library/net/http/http/read_timeout_spec.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-
-describe "Net::HTTP#read_timeout" do
- it "returns the seconds to wait until reading one block" do
- net = Net::HTTP.new("localhost")
- net.read_timeout.should eql(60)
- net.read_timeout = 10
- net.read_timeout.should eql(10)
- end
-end
-
-describe "Net::HTTP#read_timeout=" do
- it "sets the seconds to wait till the connection is open" do
- net = Net::HTTP.new("localhost")
- net.read_timeout = 10
- net.read_timeout.should eql(10)
- end
-
- it "returns the newly set value" do
- net = Net::HTTP.new("localhost")
- (net.read_timeout = 10).should eql(10)
- end
-end
diff --git a/spec/ruby/library/net/http/http/request_get_spec.rb b/spec/ruby/library/net/http/http/request_get_spec.rb
deleted file mode 100644
index 33b040c622..0000000000
--- a/spec/ruby/library/net/http/http/request_get_spec.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../fixtures/http_server', __FILE__)
-require File.expand_path('../shared/request_get', __FILE__)
-
-describe "Net::HTTP#request_get" do
- it_behaves_like :net_ftp_request_get, :get2
-end
diff --git a/spec/ruby/library/net/http/http/request_head_spec.rb b/spec/ruby/library/net/http/http/request_head_spec.rb
deleted file mode 100644
index 85ff56dcb5..0000000000
--- a/spec/ruby/library/net/http/http/request_head_spec.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../fixtures/http_server', __FILE__)
-require File.expand_path('../shared/request_head', __FILE__)
-
-describe "Net::HTTP#request_head" do
- it_behaves_like :net_ftp_request_head, :request_head
-end
diff --git a/spec/ruby/library/net/http/http/request_post_spec.rb b/spec/ruby/library/net/http/http/request_post_spec.rb
deleted file mode 100644
index 937b4d5d59..0000000000
--- a/spec/ruby/library/net/http/http/request_post_spec.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../fixtures/http_server', __FILE__)
-require File.expand_path('../shared/request_post', __FILE__)
-
-describe "Net::HTTP#request_post" do
- it_behaves_like :net_ftp_request_post, :request_post
-end
diff --git a/spec/ruby/library/net/http/http/request_put_spec.rb b/spec/ruby/library/net/http/http/request_put_spec.rb
deleted file mode 100644
index c3a4b6d538..0000000000
--- a/spec/ruby/library/net/http/http/request_put_spec.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../fixtures/http_server', __FILE__)
-require File.expand_path('../shared/request_put', __FILE__)
-
-describe "Net::HTTP#request_put" do
- it_behaves_like :net_ftp_request_put, :request_put
-end
diff --git a/spec/ruby/library/net/http/http/request_spec.rb b/spec/ruby/library/net/http/http/request_spec.rb
deleted file mode 100644
index d1c754df8c..0000000000
--- a/spec/ruby/library/net/http/http/request_spec.rb
+++ /dev/null
@@ -1,109 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../fixtures/http_server', __FILE__)
-
-describe "Net::HTTP#request" do
- before :each do
- NetHTTPSpecs.start_server
- @http = Net::HTTP.start("localhost", NetHTTPSpecs.port)
- end
-
- after :each do
- @http.finish if @http.started?
- NetHTTPSpecs.stop_server
- end
-
- describe "when passed request_object" do
- it "makes a HTTP Request based on the passed request_object" do
- response = @http.request(Net::HTTP::Get.new("/request"), "test=test")
- response.body.should == "Request type: GET"
-
- response = @http.request(Net::HTTP::Head.new("/request"), "test=test")
- response.body.should be_nil
-
- response = @http.request(Net::HTTP::Post.new("/request"), "test=test")
- response.body.should == "Request type: POST"
-
- response = @http.request(Net::HTTP::Put.new("/request"), "test=test")
- response.body.should == "Request type: PUT"
-
- response = @http.request(Net::HTTP::Proppatch.new("/request"), "test=test")
- response.body.should == "Request type: PROPPATCH"
-
- response = @http.request(Net::HTTP::Lock.new("/request"), "test=test")
- response.body.should == "Request type: LOCK"
-
- response = @http.request(Net::HTTP::Unlock.new("/request"), "test=test")
- response.body.should == "Request type: UNLOCK"
-
- # TODO: Does not work?
- #response = @http.request(Net::HTTP::Options.new("/request"), "test=test")
- #response.body.should be_nil
-
- response = @http.request(Net::HTTP::Propfind.new("/request"), "test=test")
- response.body.should == "Request type: PROPFIND"
-
- response = @http.request(Net::HTTP::Delete.new("/request"), "test=test")
- response.body.should == "Request type: DELETE"
-
- response = @http.request(Net::HTTP::Move.new("/request"), "test=test")
- response.body.should == "Request type: MOVE"
-
- response = @http.request(Net::HTTP::Copy.new("/request"), "test=test")
- response.body.should == "Request type: COPY"
-
- response = @http.request(Net::HTTP::Mkcol.new("/request"), "test=test")
- response.body.should == "Request type: MKCOL"
-
- response = @http.request(Net::HTTP::Trace.new("/request"), "test=test")
- response.body.should == "Request type: TRACE"
- end
- end
-
- describe "when passed request_object and request_body" do
- it "sends the passed request_body when making the HTTP Request" do
- response = @http.request(Net::HTTP::Get.new("/request/body"), "test=test")
- response.body.should == "test=test"
-
- response = @http.request(Net::HTTP::Head.new("/request/body"), "test=test")
- response.body.should be_nil
-
- response = @http.request(Net::HTTP::Post.new("/request/body"), "test=test")
- response.body.should == "test=test"
-
- response = @http.request(Net::HTTP::Put.new("/request/body"), "test=test")
- response.body.should == "test=test"
-
- response = @http.request(Net::HTTP::Proppatch.new("/request/body"), "test=test")
- response.body.should == "test=test"
-
- response = @http.request(Net::HTTP::Lock.new("/request/body"), "test=test")
- response.body.should == "test=test"
-
- response = @http.request(Net::HTTP::Unlock.new("/request/body"), "test=test")
- response.body.should == "test=test"
-
- # TODO: Does not work?
- #response = @http.request(Net::HTTP::Options.new("/request/body"), "test=test")
- #response.body.should be_nil
-
- response = @http.request(Net::HTTP::Propfind.new("/request/body"), "test=test")
- response.body.should == "test=test"
-
- response = @http.request(Net::HTTP::Delete.new("/request/body"), "test=test")
- response.body.should == "test=test"
-
- response = @http.request(Net::HTTP::Move.new("/request/body"), "test=test")
- response.body.should == "test=test"
-
- response = @http.request(Net::HTTP::Copy.new("/request/body"), "test=test")
- response.body.should == "test=test"
-
- response = @http.request(Net::HTTP::Mkcol.new("/request/body"), "test=test")
- response.body.should == "test=test"
-
- response = @http.request(Net::HTTP::Trace.new("/request/body"), "test=test")
- response.body.should == "test=test"
- end
- end
-end
diff --git a/spec/ruby/library/net/http/http/request_types_spec.rb b/spec/ruby/library/net/http/http/request_types_spec.rb
deleted file mode 100644
index 71fe863bb2..0000000000
--- a/spec/ruby/library/net/http/http/request_types_spec.rb
+++ /dev/null
@@ -1,254 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-
-describe "Net::HTTP::Get" do
- it "is a subclass of Net::HTTPRequest" do
- Net::HTTP::Get.should < Net::HTTPRequest
- end
-
- it "represents the 'GET'-Request-Method" do
- Net::HTTP::Get::METHOD.should == "GET"
- end
-
- it "has no Request Body" do
- Net::HTTP::Get::REQUEST_HAS_BODY.should be_false
- end
-
- it "has a Response Body" do
- Net::HTTP::Get::RESPONSE_HAS_BODY.should be_true
- end
-end
-
-describe "Net::HTTP::Head" do
- it "is a subclass of Net::HTTPRequest" do
- Net::HTTP::Head.should < Net::HTTPRequest
- end
-
- it "represents the 'HEAD'-Request-Method" do
- Net::HTTP::Head::METHOD.should == "HEAD"
- end
-
- it "has no Request Body" do
- Net::HTTP::Head::REQUEST_HAS_BODY.should be_false
- end
-
- it "has no Response Body" do
- Net::HTTP::Head::RESPONSE_HAS_BODY.should be_false
- end
-end
-
-describe "Net::HTTP::Post" do
- it "is a subclass of Net::HTTPRequest" do
- Net::HTTP::Post.should < Net::HTTPRequest
- end
-
- it "represents the 'POST'-Request-Method" do
- Net::HTTP::Post::METHOD.should == "POST"
- end
-
- it "has a Request Body" do
- Net::HTTP::Post::REQUEST_HAS_BODY.should be_true
- end
-
- it "has a Response Body" do
- Net::HTTP::Post::RESPONSE_HAS_BODY.should be_true
- end
-end
-
-describe "Net::HTTP::Put" do
- it "is a subclass of Net::HTTPRequest" do
- Net::HTTP::Put.should < Net::HTTPRequest
- end
-
- it "represents the 'PUT'-Request-Method" do
- Net::HTTP::Put::METHOD.should == "PUT"
- end
-
- it "has a Request Body" do
- Net::HTTP::Put::REQUEST_HAS_BODY.should be_true
- end
-
- it "has a Response Body" do
- Net::HTTP::Put::RESPONSE_HAS_BODY.should be_true
- end
-end
-
-describe "Net::HTTP::Delete" do
- it "is a subclass of Net::HTTPRequest" do
- Net::HTTP::Delete.should < Net::HTTPRequest
- end
-
- it "represents the 'DELETE'-Request-Method" do
- Net::HTTP::Delete::METHOD.should == "DELETE"
- end
-
- it "has no Request Body" do
- Net::HTTP::Delete::REQUEST_HAS_BODY.should be_false
- end
-
- it "has a Response Body" do
- Net::HTTP::Delete::RESPONSE_HAS_BODY.should be_true
- end
-end
-
-describe "Net::HTTP::Options" do
- it "is a subclass of Net::HTTPRequest" do
- Net::HTTP::Options.should < Net::HTTPRequest
- end
-
- it "represents the 'OPTIONS'-Request-Method" do
- Net::HTTP::Options::METHOD.should == "OPTIONS"
- end
-
- it "has no Request Body" do
- Net::HTTP::Options::REQUEST_HAS_BODY.should be_false
- end
-
- it "has no Response Body" do
- Net::HTTP::Options::RESPONSE_HAS_BODY.should be_true
- end
-end
-
-describe "Net::HTTP::Trace" do
- it "is a subclass of Net::HTTPRequest" do
- Net::HTTP::Trace.should < Net::HTTPRequest
- end
-
- it "represents the 'TRACE'-Request-Method" do
- Net::HTTP::Trace::METHOD.should == "TRACE"
- end
-
- it "has no Request Body" do
- Net::HTTP::Trace::REQUEST_HAS_BODY.should be_false
- end
-
- it "has a Response Body" do
- Net::HTTP::Trace::RESPONSE_HAS_BODY.should be_true
- end
-end
-
-describe "Net::HTTP::Propfind" do
- it "is a subclass of Net::HTTPRequest" do
- Net::HTTP::Propfind.should < Net::HTTPRequest
- end
-
- it "represents the 'PROPFIND'-Request-Method" do
- Net::HTTP::Propfind::METHOD.should == "PROPFIND"
- end
-
- it "has a Request Body" do
- Net::HTTP::Propfind::REQUEST_HAS_BODY.should be_true
- end
-
- it "has a Response Body" do
- Net::HTTP::Propfind::RESPONSE_HAS_BODY.should be_true
- end
-end
-
-describe "Net::HTTP::Proppatch" do
- it "is a subclass of Net::HTTPRequest" do
- Net::HTTP::Proppatch.should < Net::HTTPRequest
- end
-
- it "represents the 'PROPPATCH'-Request-Method" do
- Net::HTTP::Proppatch::METHOD.should == "PROPPATCH"
- end
-
- it "has a Request Body" do
- Net::HTTP::Proppatch::REQUEST_HAS_BODY.should be_true
- end
-
- it "has a Response Body" do
- Net::HTTP::Proppatch::RESPONSE_HAS_BODY.should be_true
- end
-end
-
-describe "Net::HTTP::Mkcol" do
- it "is a subclass of Net::HTTPRequest" do
- Net::HTTP::Mkcol.should < Net::HTTPRequest
- end
-
- it "represents the 'MKCOL'-Request-Method" do
- Net::HTTP::Mkcol::METHOD.should == "MKCOL"
- end
-
- it "has a Request Body" do
- Net::HTTP::Mkcol::REQUEST_HAS_BODY.should be_true
- end
-
- it "has a Response Body" do
- Net::HTTP::Mkcol::RESPONSE_HAS_BODY.should be_true
- end
-end
-
-describe "Net::HTTP::Copy" do
- it "is a subclass of Net::HTTPRequest" do
- Net::HTTP::Copy.should < Net::HTTPRequest
- end
-
- it "represents the 'COPY'-Request-Method" do
- Net::HTTP::Copy::METHOD.should == "COPY"
- end
-
- it "has no Request Body" do
- Net::HTTP::Copy::REQUEST_HAS_BODY.should be_false
- end
-
- it "has a Response Body" do
- Net::HTTP::Copy::RESPONSE_HAS_BODY.should be_true
- end
-end
-
-describe "Net::HTTP::Move" do
- it "is a subclass of Net::HTTPRequest" do
- Net::HTTP::Move.should < Net::HTTPRequest
- end
-
- it "represents the 'MOVE'-Request-Method" do
- Net::HTTP::Move::METHOD.should == "MOVE"
- end
-
- it "has no Request Body" do
- Net::HTTP::Move::REQUEST_HAS_BODY.should be_false
- end
-
- it "has a Response Body" do
- Net::HTTP::Move::RESPONSE_HAS_BODY.should be_true
- end
-end
-
-describe "Net::HTTP::Lock" do
- it "is a subclass of Net::HTTPRequest" do
- Net::HTTP::Lock.should < Net::HTTPRequest
- end
-
- it "represents the 'LOCK'-Request-Method" do
- Net::HTTP::Lock::METHOD.should == "LOCK"
- end
-
- it "has a Request Body" do
- Net::HTTP::Lock::REQUEST_HAS_BODY.should be_true
- end
-
- it "has a Response Body" do
- Net::HTTP::Lock::RESPONSE_HAS_BODY.should be_true
- end
-end
-
-describe "Net::HTTP::Unlock" do
- it "is a subclass of Net::HTTPRequest" do
- Net::HTTP::Unlock.should < Net::HTTPRequest
- end
-
- it "represents the 'UNLOCK'-Request-Method" do
- Net::HTTP::Unlock::METHOD.should == "UNLOCK"
- end
-
- it "has a Request Body" do
- Net::HTTP::Unlock::REQUEST_HAS_BODY.should be_true
- end
-
- it "has a Response Body" do
- Net::HTTP::Unlock::RESPONSE_HAS_BODY.should be_true
- end
-end
diff --git a/spec/ruby/library/net/http/http/send_request_spec.rb b/spec/ruby/library/net/http/http/send_request_spec.rb
deleted file mode 100644
index 5a704496ec..0000000000
--- a/spec/ruby/library/net/http/http/send_request_spec.rb
+++ /dev/null
@@ -1,61 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../fixtures/http_server', __FILE__)
-
-describe "Net::HTTP#send_request" do
- before :each do
- NetHTTPSpecs.start_server
- @http = Net::HTTP.start("localhost", NetHTTPSpecs.port)
-
- # HEAD is special so handled separately
- @methods = %w[
- GET POST PUT DELETE
- OPTIONS
- PROPFIND PROPPATCH LOCK UNLOCK
- ]
- end
-
- after :each do
- @http.finish if @http.started?
- NetHTTPSpecs.stop_server
- end
-
- # TODO: Does only work with GET and POST requests
- describe "when passed type, path" do
- it "sends a HTTP Request of the passed type to the passed path" do
- response = @http.send_request("HEAD", "/request")
- response.body.should be_nil
-
- @methods.each do |method|
- response = @http.send_request(method, "/request")
- response.body.should == "Request type: #{method}"
- end
- end
- end
-
- describe "when passed type, path, body" do
- it "sends a HTTP Request with the passed body" do
- response = @http.send_request("HEAD", "/request/body", "test=test")
- response.body.should be_nil
-
- @methods.each do |method|
- response = @http.send_request(method, "/request/body", "test=test")
- response.body.should == "test=test"
- end
- end
- end
-
- describe "when passed type, path, body, headers" do
- it "sends a HTTP Request with the passed headers" do
- referer = 'https://www.ruby-lang.org/'.freeze
-
- response = @http.send_request("HEAD", "/request/header", "test=test", "referer" => referer)
- response.body.should be_nil
-
- @methods.each do |method|
- response = @http.send_request(method, "/request/header", "test=test", "referer" => referer)
- response.body.should include('"referer"=>["' + referer + '"]')
- end
- end
- end
-end
diff --git a/spec/ruby/library/net/http/http/set_debug_output_spec.rb b/spec/ruby/library/net/http/http/set_debug_output_spec.rb
deleted file mode 100644
index 806f468a84..0000000000
--- a/spec/ruby/library/net/http/http/set_debug_output_spec.rb
+++ /dev/null
@@ -1,33 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require "stringio"
-require File.expand_path('../fixtures/http_server', __FILE__)
-
-describe "Net::HTTP#set_debug_output when passed io" do
- before :each do
- NetHTTPSpecs.start_server
- @http = Net::HTTP.new("localhost", NetHTTPSpecs.port)
- end
-
- after :each do
- @http.finish if @http.started?
- NetHTTPSpecs.stop_server
- end
-
- it "sets the passed io as output stream for debugging" do
- io = StringIO.new
-
- @http.set_debug_output(io)
- @http.start
- io.string.should_not be_empty
- size = io.string.size
-
- @http.get("/")
- io.string.size.should > size
- end
-
- it "outputs a warning when the connection has already been started" do
- @http.start
- lambda { @http.set_debug_output(StringIO.new) }.should complain("Net::HTTP#set_debug_output called after HTTP started\n")
- end
-end
diff --git a/spec/ruby/library/net/http/http/shared/request_get.rb b/spec/ruby/library/net/http/http/shared/request_get.rb
deleted file mode 100644
index b0eca665d6..0000000000
--- a/spec/ruby/library/net/http/http/shared/request_get.rb
+++ /dev/null
@@ -1,41 +0,0 @@
-describe :net_ftp_request_get, shared: true do
- before :each do
- NetHTTPSpecs.start_server
- @http = Net::HTTP.start("localhost", NetHTTPSpecs.port)
- end
-
- after :each do
- @http.finish if @http.started?
- NetHTTPSpecs.stop_server
- end
-
- describe "when passed no block" do
- it "sends a GET request to the passed path and returns the response" do
- response = @http.send(@method, "/request")
- response.body.should == "Request type: GET"
- end
-
- it "returns a Net::HTTPResponse object" do
- response = @http.send(@method, "/request")
- response.should be_kind_of(Net::HTTPResponse)
- end
- end
-
- describe "when passed a block" do
- it "sends a GET request to the passed path and returns the response" do
- response = @http.send(@method, "/request") {}
- response.body.should == "Request type: GET"
- end
-
- it "yields the response to the passed block" do
- @http.send(@method, "/request") do |response|
- response.body.should == "Request type: GET"
- end
- end
-
- it "returns a Net::HTTPResponse object" do
- response = @http.send(@method, "/request") {}
- response.should be_kind_of(Net::HTTPResponse)
- end
- end
-end
diff --git a/spec/ruby/library/net/http/http/shared/request_head.rb b/spec/ruby/library/net/http/http/shared/request_head.rb
deleted file mode 100644
index 0e669de9ac..0000000000
--- a/spec/ruby/library/net/http/http/shared/request_head.rb
+++ /dev/null
@@ -1,41 +0,0 @@
-describe :net_ftp_request_head, shared: true do
- before :each do
- NetHTTPSpecs.start_server
- @http = Net::HTTP.start("localhost", NetHTTPSpecs.port)
- end
-
- after :each do
- @http.finish if @http.started?
- NetHTTPSpecs.stop_server
- end
-
- describe "when passed no block" do
- it "sends a head request to the passed path and returns the response" do
- response = @http.send(@method, "/request")
- response.body.should be_nil
- end
-
- it "returns a Net::HTTPResponse object" do
- response = @http.send(@method, "/request")
- response.should be_kind_of(Net::HTTPResponse)
- end
- end
-
- describe "when passed a block" do
- it "sends a head request to the passed path and returns the response" do
- response = @http.send(@method, "/request") {}
- response.body.should be_nil
- end
-
- it "yields the response to the passed block" do
- @http.send(@method, "/request") do |response|
- response.body.should be_nil
- end
- end
-
- it "returns a Net::HTTPResponse object" do
- response = @http.send(@method, "/request") {}
- response.should be_kind_of(Net::HTTPResponse)
- end
- end
-end
diff --git a/spec/ruby/library/net/http/http/shared/request_post.rb b/spec/ruby/library/net/http/http/shared/request_post.rb
deleted file mode 100644
index 06c5e139f9..0000000000
--- a/spec/ruby/library/net/http/http/shared/request_post.rb
+++ /dev/null
@@ -1,41 +0,0 @@
-describe :net_ftp_request_post, shared: true do
- before :each do
- NetHTTPSpecs.start_server
- @http = Net::HTTP.start("localhost", NetHTTPSpecs.port)
- end
-
- after :each do
- @http.finish if @http.started?
- NetHTTPSpecs.stop_server
- end
-
- describe "when passed no block" do
- it "sends a post request to the passed path and returns the response" do
- response = @http.send(@method, "/request", "test=test")
- response.body.should == "Request type: POST"
- end
-
- it "returns a Net::HTTPResponse object" do
- response = @http.send(@method, "/request", "test=test")
- response.should be_kind_of(Net::HTTPResponse)
- end
- end
-
- describe "when passed a block" do
- it "sends a post request to the passed path and returns the response" do
- response = @http.send(@method, "/request", "test=test") {}
- response.body.should == "Request type: POST"
- end
-
- it "yields the response to the passed block" do
- @http.send(@method, "/request", "test=test") do |response|
- response.body.should == "Request type: POST"
- end
- end
-
- it "returns a Net::HTTPResponse object" do
- response = @http.send(@method, "/request", "test=test") {}
- response.should be_kind_of(Net::HTTPResponse)
- end
- end
-end
diff --git a/spec/ruby/library/net/http/http/shared/request_put.rb b/spec/ruby/library/net/http/http/shared/request_put.rb
deleted file mode 100644
index 6ae791d7e7..0000000000
--- a/spec/ruby/library/net/http/http/shared/request_put.rb
+++ /dev/null
@@ -1,41 +0,0 @@
-describe :net_ftp_request_put, shared: true do
- before :each do
- NetHTTPSpecs.start_server
- @http = Net::HTTP.start("localhost", NetHTTPSpecs.port)
- end
-
- after :each do
- @http.finish if @http.started?
- NetHTTPSpecs.stop_server
- end
-
- describe "when passed no block" do
- it "sends a put request to the passed path and returns the response" do
- response = @http.send(@method, "/request", "test=test")
- response.body.should == "Request type: PUT"
- end
-
- it "returns a Net::HTTPResponse object" do
- response = @http.send(@method, "/request", "test=test")
- response.should be_kind_of(Net::HTTPResponse)
- end
- end
-
- describe "when passed a block" do
- it "sends a put request to the passed path and returns the response" do
- response = @http.send(@method, "/request", "test=test") {}
- response.body.should == "Request type: PUT"
- end
-
- it "yields the response to the passed block" do
- @http.send(@method, "/request", "test=test") do |response|
- response.body.should == "Request type: PUT"
- end
- end
-
- it "returns a Net::HTTPResponse object" do
- response = @http.send(@method, "/request", "test=test") {}
- response.should be_kind_of(Net::HTTPResponse)
- end
- end
-end
diff --git a/spec/ruby/library/net/http/http/shared/started.rb b/spec/ruby/library/net/http/http/shared/started.rb
deleted file mode 100644
index 9ff6272c31..0000000000
--- a/spec/ruby/library/net/http/http/shared/started.rb
+++ /dev/null
@@ -1,26 +0,0 @@
-describe :net_http_started_p, shared: true do
- before :each do
- NetHTTPSpecs.start_server
- @http = Net::HTTP.new("localhost", NetHTTPSpecs.port)
- end
-
- after :each do
- @http.finish if @http.started?
- NetHTTPSpecs.stop_server
- end
-
- it "returns true when self has been started" do
- @http.start
- @http.send(@method).should be_true
- end
-
- it "returns false when self has not been started yet" do
- @http.send(@method).should be_false
- end
-
- it "returns false when self has been stopped again" do
- @http.start
- @http.finish
- @http.send(@method).should be_false
- end
-end
diff --git a/spec/ruby/library/net/http/http/shared/version_1_1.rb b/spec/ruby/library/net/http/http/shared/version_1_1.rb
deleted file mode 100644
index db3d6a986d..0000000000
--- a/spec/ruby/library/net/http/http/shared/version_1_1.rb
+++ /dev/null
@@ -1,6 +0,0 @@
-describe :net_http_version_1_1_p, shared: true do
- it "returns the state of net/http 1.1 features" do
- Net::HTTP.version_1_2
- Net::HTTP.send(@method).should be_false
- end
-end
diff --git a/spec/ruby/library/net/http/http/shared/version_1_2.rb b/spec/ruby/library/net/http/http/shared/version_1_2.rb
deleted file mode 100644
index b044182c60..0000000000
--- a/spec/ruby/library/net/http/http/shared/version_1_2.rb
+++ /dev/null
@@ -1,6 +0,0 @@
-describe :net_http_version_1_2_p, shared: true do
- it "returns the state of net/http 1.2 features" do
- Net::HTTP.version_1_2
- Net::HTTP.send(@method).should be_true
- end
-end
diff --git a/spec/ruby/library/net/http/http/socket_type_spec.rb b/spec/ruby/library/net/http/http/socket_type_spec.rb
deleted file mode 100644
index 4ec9b68571..0000000000
--- a/spec/ruby/library/net/http/http/socket_type_spec.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-
-describe "Net::HTTP.socket_type" do
- it "returns BufferedIO" do
- Net::HTTP.socket_type.should == Net::BufferedIO
- end
-end
diff --git a/spec/ruby/library/net/http/http/start_spec.rb b/spec/ruby/library/net/http/http/start_spec.rb
deleted file mode 100644
index 407d57e494..0000000000
--- a/spec/ruby/library/net/http/http/start_spec.rb
+++ /dev/null
@@ -1,111 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../fixtures/http_server', __FILE__)
-
-describe "Net::HTTP.start" do
- before :each do
- NetHTTPSpecs.start_server
- @port = NetHTTPSpecs.port
- end
-
- after :each do
- NetHTTPSpecs.stop_server
- end
-
- describe "when not passed a block" do
- before :each do
- @http = Net::HTTP.start("localhost", @port)
- end
-
- after :each do
- @http.finish if @http.started?
- end
-
- it "returns a new Net::HTTP object for the passed address and port" do
- @http.should be_kind_of(Net::HTTP)
- @http.address.should == "localhost"
- @http.port.should == @port
- end
-
- it "opens the tcp connection" do
- @http.started?.should be_true
- end
- end
-
- describe "when passed a block" do
- it "returns the blocks return value" do
- Net::HTTP.start("localhost", @port) { :test }.should == :test
- end
-
- it "yields the new Net::HTTP object to the block" do
- yielded = false
- Net::HTTP.start("localhost", @port) do |net|
- yielded = true
- net.should be_kind_of(Net::HTTP)
- end
- yielded.should be_true
- end
-
- it "opens the tcp connection before yielding" do
- Net::HTTP.start("localhost", @port) { |http| http.started?.should be_true }
- end
-
- it "closes the tcp connection after yielding" do
- net = nil
- Net::HTTP.start("localhost", @port) { |x| net = x }
- net.started?.should be_false
- end
- end
-end
-
-describe "Net::HTTP#start" do
- before :each do
- NetHTTPSpecs.start_server
- @http = Net::HTTP.new("localhost", NetHTTPSpecs.port)
- end
-
- after :each do
- @http.finish if @http.started?
- NetHTTPSpecs.stop_server
- end
-
- it "returns self" do
- @http.start.should equal(@http)
- end
-
- it "opens the tcp connection" do
- @http.start
- @http.started?.should be_true
- end
-
- describe "when self has already been started" do
- it "raises an IOError" do
- @http.start
- lambda { @http.start }.should raise_error(IOError)
- end
- end
-
- describe "when passed a block" do
- it "returns the blocks return value" do
- @http.start { :test }.should == :test
- end
-
- it "yields the new Net::HTTP object to the block" do
- yielded = false
- @http.start do |http|
- yielded = true
- http.should equal(@http)
- end
- yielded.should be_true
- end
-
- it "opens the tcp connection before yielding" do
- @http.start { |http| http.started?.should be_true }
- end
-
- it "closes the tcp connection after yielding" do
- @http.start { }
- @http.started?.should be_false
- end
- end
-end
diff --git a/spec/ruby/library/net/http/http/started_spec.rb b/spec/ruby/library/net/http/http/started_spec.rb
deleted file mode 100644
index 01c17c93c1..0000000000
--- a/spec/ruby/library/net/http/http/started_spec.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../fixtures/http_server', __FILE__)
-require File.expand_path('../shared/started', __FILE__)
-
-describe "Net::HTTP#started?" do
- it_behaves_like :net_http_started_p, :started?
-end
diff --git a/spec/ruby/library/net/http/http/trace_spec.rb b/spec/ruby/library/net/http/http/trace_spec.rb
deleted file mode 100644
index 6cce15fc09..0000000000
--- a/spec/ruby/library/net/http/http/trace_spec.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../fixtures/http_server', __FILE__)
-
-describe "Net::HTTP#trace" do
- before :each do
- NetHTTPSpecs.start_server
- @http = Net::HTTP.start("localhost", NetHTTPSpecs.port)
- end
-
- after :each do
- @http.finish if @http.started?
- NetHTTPSpecs.stop_server
- end
-
- it "sends a TRACE request to the passed path and returns the response" do
- response = @http.trace("/request")
- response.body.should == "Request type: TRACE"
- end
-
- it "returns a Net::HTTPResponse" do
- @http.trace("/request").should be_kind_of(Net::HTTPResponse)
- end
-end
diff --git a/spec/ruby/library/net/http/http/unlock_spec.rb b/spec/ruby/library/net/http/http/unlock_spec.rb
deleted file mode 100644
index 12df417e1a..0000000000
--- a/spec/ruby/library/net/http/http/unlock_spec.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../fixtures/http_server', __FILE__)
-
-describe "Net::HTTP#unlock" do
- before :each do
- NetHTTPSpecs.start_server
- @http = Net::HTTP.start("localhost", NetHTTPSpecs.port)
- end
-
- after :each do
- @http.finish if @http.started?
- NetHTTPSpecs.stop_server
- end
-
- it "sends an UNLOCK request to the passed path and returns the response" do
- response = @http.unlock("/request", "test=test")
- response.body.should == "Request type: UNLOCK"
- end
-
- it "returns a Net::HTTPResponse" do
- @http.unlock("/request", "test=test").should be_kind_of(Net::HTTPResponse)
- end
-end
diff --git a/spec/ruby/library/net/http/http/use_ssl_spec.rb b/spec/ruby/library/net/http/http/use_ssl_spec.rb
deleted file mode 100644
index 19d065ed8e..0000000000
--- a/spec/ruby/library/net/http/http/use_ssl_spec.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-
-describe "Net::HTTP#use_ssl?" do
- it "returns false" do
- http = Net::HTTP.new("localhost")
- http.use_ssl?.should be_false
- end
-end
diff --git a/spec/ruby/library/net/http/http/version_1_1_spec.rb b/spec/ruby/library/net/http/http/version_1_1_spec.rb
deleted file mode 100644
index f13ec9b7f1..0000000000
--- a/spec/ruby/library/net/http/http/version_1_1_spec.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../shared/version_1_1', __FILE__)
-
-describe "Net::HTTP.version_1_1?" do
- it_behaves_like :net_http_version_1_1_p, :version_1_1?
-end
diff --git a/spec/ruby/library/net/http/http/version_1_2_spec.rb b/spec/ruby/library/net/http/http/version_1_2_spec.rb
deleted file mode 100644
index 63c2112422..0000000000
--- a/spec/ruby/library/net/http/http/version_1_2_spec.rb
+++ /dev/null
@@ -1,20 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../shared/version_1_2', __FILE__)
-
-describe "Net::HTTP.version_1_2" do
- it "turns on net/http 1.2 features" do
- Net::HTTP.version_1_2
-
- Net::HTTP.version_1_2?.should be_true
- Net::HTTP.version_1_1?.should be_false
- end
-
- it "returns true" do
- Net::HTTP.version_1_2.should be_true
- end
-end
-
-describe "Net::HTTP.version_1_2?" do
- it_behaves_like :net_http_version_1_2_p, :version_1_2?
-end
diff --git a/spec/ruby/library/net/http/httpexceptions/initialize_spec.rb b/spec/ruby/library/net/http/httpexceptions/initialize_spec.rb
deleted file mode 100644
index 8c0c4934f7..0000000000
--- a/spec/ruby/library/net/http/httpexceptions/initialize_spec.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../fixtures/classes', __FILE__)
-
-describe "Net::HTTPExceptions#initialize when passed message, response" do
- before :each do
- @exception = NetHTTPExceptionsSpecs::Simple.new("error message", "a http response")
- end
-
- it "calls super with the passed message" do
- @exception.message.should == "error message"
- end
-
- it "sets self's response to the passed response" do
- @exception.response.should == "a http response"
- end
-end
diff --git a/spec/ruby/library/net/http/httpexceptions/response_spec.rb b/spec/ruby/library/net/http/httpexceptions/response_spec.rb
deleted file mode 100644
index becf74bddf..0000000000
--- a/spec/ruby/library/net/http/httpexceptions/response_spec.rb
+++ /dev/null
@@ -1,10 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../fixtures/classes', __FILE__)
-
-describe "Net::HTTPExceptions#response" do
- it "returns self's response" do
- exception = NetHTTPExceptionsSpecs::Simple.new("error message", "a http response")
- exception.response.should == "a http response"
- end
-end
diff --git a/spec/ruby/library/net/http/httpgenericrequest/body_exist_spec.rb b/spec/ruby/library/net/http/httpgenericrequest/body_exist_spec.rb
deleted file mode 100644
index cb3565b899..0000000000
--- a/spec/ruby/library/net/http/httpgenericrequest/body_exist_spec.rb
+++ /dev/null
@@ -1,22 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-
-describe "Net::HTTPGenericRequest#body_exist?" do
- it "returns true when the response is expected to have a body" do
- request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path")
- request.body_exist?.should be_true
-
- request = Net::HTTPGenericRequest.new("POST", true, false, "/some/path")
- request.body_exist?.should be_false
- end
-
- describe "when $VERBOSE is true" do
- it "emits a warning" do
- request = Net::HTTPGenericRequest.new("POST", true, false, "/some/path")
- lambda {
- $VERBOSE = true
- request.body_exist?
- }.should complain(/body_exist\? is obsolete/)
- end
- end
-end
diff --git a/spec/ruby/library/net/http/httpgenericrequest/body_spec.rb b/spec/ruby/library/net/http/httpgenericrequest/body_spec.rb
deleted file mode 100644
index 4aa4fff2bc..0000000000
--- a/spec/ruby/library/net/http/httpgenericrequest/body_spec.rb
+++ /dev/null
@@ -1,30 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require "stringio"
-
-describe "Net::HTTPGenericRequest#body" do
- it "returns self's request body" do
- request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path")
- request.body.should be_nil
-
- request.body = "Some Content"
- request.body.should == "Some Content"
- end
-end
-
-describe "Net::HTTPGenericRequest#body=" do
- before :each do
- @request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path")
- end
-
- it "sets self's body content to the passed String" do
- @request.body = "Some Content"
- @request.body.should == "Some Content"
- end
-
- it "sets self's body stream to nil" do
- @request.body_stream = StringIO.new("")
- @request.body = "Some Content"
- @request.body_stream.should be_nil
- end
-end
diff --git a/spec/ruby/library/net/http/httpgenericrequest/body_stream_spec.rb b/spec/ruby/library/net/http/httpgenericrequest/body_stream_spec.rb
deleted file mode 100644
index df6e02a8c1..0000000000
--- a/spec/ruby/library/net/http/httpgenericrequest/body_stream_spec.rb
+++ /dev/null
@@ -1,32 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require "stringio"
-
-describe "Net::HTTPGenericRequest#body_stream" do
- it "returns self's body stream Object" do
- request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path")
- request.body_stream.should be_nil
-
- stream = StringIO.new("test")
- request.body_stream = stream
- request.body_stream.should equal(stream)
- end
-end
-
-describe "Net::HTTPGenericRequest#body_stream=" do
- before :each do
- @request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path")
- @stream = StringIO.new("test")
- end
-
- it "sets self's body stream to the passed Object" do
- @request.body_stream = @stream
- @request.body_stream.should equal(@stream)
- end
-
- it "sets self's body to nil" do
- @request.body = "Some Content"
- @request.body_stream = @stream
- @request.body.should be_nil
- end
-end
diff --git a/spec/ruby/library/net/http/httpgenericrequest/exec_spec.rb b/spec/ruby/library/net/http/httpgenericrequest/exec_spec.rb
deleted file mode 100644
index b3850d6c74..0000000000
--- a/spec/ruby/library/net/http/httpgenericrequest/exec_spec.rb
+++ /dev/null
@@ -1,131 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require "stringio"
-
-describe "Net::HTTPGenericRequest#exec when passed socket, version, path" do
- before :each do
- @socket = StringIO.new("")
- @buffered_socket = Net::BufferedIO.new(@socket)
- end
-
- it "executes the request over the socket to the path using the HTTP version" do
- request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path")
-
- request.exec(@buffered_socket, "1.1", "/some/path")
- str = @socket.string
-
- str.should =~ %r[POST /some/path HTTP/1.1\r\n]
- str.should =~ %r[Accept: \*/\*\r\n]
- str[-4..-1].should == "\r\n\r\n"
-
- request = Net::HTTPGenericRequest.new("GET", true, true, "/some/path",
- "Content-Type" => "text/html")
-
- request.exec(@buffered_socket, "1.0", "/some/other/path")
- str = @socket.string
-
- str.should =~ %r[GET /some/other/path HTTP/1.0\r\n]
- str.should =~ %r[Accept: \*/\*\r\n]
- str.should =~ %r[Content-Type: text/html\r\n]
- str[-4..-1].should == "\r\n\r\n"
- end
-
- describe "when a request body is set" do
- it "sets the 'Content-Type' header to 'application/x-www-form-urlencoded' unless the 'Content-Type' header is supplied" do
- request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path")
- request.body = "Some Content"
-
- request.exec(@buffered_socket, "1.1", "/some/other/path")
- str = @socket.string
-
- str.should =~ %r[POST /some/other/path HTTP/1.1\r\n]
- str.should =~ %r[Accept: \*/\*\r\n]
- str.should =~ %r[Content-Type: application/x-www-form-urlencoded\r\n]
- str.should =~ %r[Content-Length: 12\r\n]
- str[-16..-1].should == "\r\n\r\nSome Content"
- end
-
- it "correctly sets the 'Content-Length' header and includes the body" do
- request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path",
- "Content-Type" => "text/html")
- request.body = "Some Content"
-
- request.exec(@buffered_socket, "1.1", "/some/other/path")
- str = @socket.string
-
- str.should =~ %r[POST /some/other/path HTTP/1.1\r\n]
- str.should =~ %r[Accept: \*/\*\r\n]
- str.should =~ %r[Content-Type: text/html\r\n]
- str.should =~ %r[Content-Length: 12\r\n]
- str[-16..-1].should == "\r\n\r\nSome Content"
- end
- end
-
- describe "when a body stream is set" do
- it "sets the 'Content-Type' header to 'application/x-www-form-urlencoded' unless the 'Content-Type' header is supplied" do
- request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path",
- "Content-Length" => "10")
- request.body_stream = StringIO.new("a" * 20)
-
- request.exec(@buffered_socket, "1.1", "/some/other/path")
- str = @socket.string
-
- str.should =~ %r[POST /some/other/path HTTP/1.1\r\n]
- str.should =~ %r[Accept: \*/\*\r\n]
- str.should =~ %r[Content-Type: application/x-www-form-urlencoded\r\n]
- str.should =~ %r[Content-Length: 10\r\n]
- str[-24..-1].should == "\r\n\r\naaaaaaaaaaaaaaaaaaaa"
- end
-
- it "sends the whole stream, regardless of the 'Content-Length' header" do
- request = Net::HTTPGenericRequest.new("POST", true, true,"/some/path",
- "Content-Type" => "text/html",
- "Content-Length" => "10")
- request.body_stream = StringIO.new("a" * 20)
-
- request.exec(@buffered_socket, "1.1", "/some/other/path")
- str = @socket.string
-
- str.should =~ %r[POST /some/other/path HTTP/1.1\r\n]
- str.should =~ %r[Accept: \*/\*\r\n]
- str.should =~ %r[Content-Type: text/html\r\n]
- str.should =~ %r[Content-Length: 10\r\n]
- str[-24..-1].should == "\r\n\r\naaaaaaaaaaaaaaaaaaaa"
- end
-
- it "sends the request in chunks when 'Transfer-Encoding' is set to 'chunked'" do
- request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path",
- "Content-Type" => "text/html",
- "Transfer-Encoding" => "chunked")
- datasize = 1024 * 10
- request.body_stream = StringIO.new("a" * datasize)
-
- request.exec(@buffered_socket, "1.1", "/some/other/path")
- str = @socket.string
-
- str.should =~ %r[POST /some/other/path HTTP/1.1\r\n]
- str.should =~ %r[Accept: \*/\*\r\n]
- str.should =~ %r[Content-Type: text/html\r\n]
- str.should =~ %r[Transfer-Encoding: chunked\r\n]
- str =~ %r[\r\n\r\n]
- str = $'
- while datasize > 0
- chunk_size_line, str = str.split(/\r\n/, 2)
- chunk_size = chunk_size_line[/\A[0-9A-Fa-f]+/].to_i(16)
- str.slice!(0, chunk_size).should == 'a' * chunk_size
- datasize -= chunk_size
- str.slice!(0, 2).should == "\r\n"
- end
- datasize.should == 0
- str.should == %"0\r\n\r\n"
- end
-
- it "raises an ArgumentError when the 'Content-Length' is not set or 'Transfer-Encoding' is not set to 'chunked'" do
- request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path",
- "Content-Type" => "text/html")
- request.body_stream = StringIO.new("Some Content")
-
- lambda { request.exec(@buffered_socket, "1.1", "/some/other/path") }.should raise_error(ArgumentError)
- end
- end
-end
diff --git a/spec/ruby/library/net/http/httpgenericrequest/inspect_spec.rb b/spec/ruby/library/net/http/httpgenericrequest/inspect_spec.rb
deleted file mode 100644
index 269ce4fe52..0000000000
--- a/spec/ruby/library/net/http/httpgenericrequest/inspect_spec.rb
+++ /dev/null
@@ -1,25 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-
-describe "Net::HTTPGenericRequest#inspect" do
- it "returns a String representation of self" do
- request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path")
- request.inspect.should == "#<Net::HTTPGenericRequest POST>"
-
- request = Net::HTTPGenericRequest.new("GET", false, true, "/some/path")
- request.inspect.should == "#<Net::HTTPGenericRequest GET>"
-
- request = Net::HTTPGenericRequest.new("BLA", true, true, "/some/path")
- request.inspect.should == "#<Net::HTTPGenericRequest BLA>"
-
- # Subclasses
- request = Net::HTTP::Get.new("/some/path")
- request.inspect.should == "#<Net::HTTP::Get GET>"
-
- request = Net::HTTP::Post.new("/some/path")
- request.inspect.should == "#<Net::HTTP::Post POST>"
-
- request = Net::HTTP::Trace.new("/some/path")
- request.inspect.should == "#<Net::HTTP::Trace TRACE>"
- end
-end
diff --git a/spec/ruby/library/net/http/httpgenericrequest/method_spec.rb b/spec/ruby/library/net/http/httpgenericrequest/method_spec.rb
deleted file mode 100644
index eef87ff3a7..0000000000
--- a/spec/ruby/library/net/http/httpgenericrequest/method_spec.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-
-describe "Net::HTTPGenericRequest#method" do
- it "returns self's request method" do
- request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path")
- request.method.should == "POST"
-
- request = Net::HTTPGenericRequest.new("GET", false, true, "/some/path")
- request.method.should == "GET"
-
- request = Net::HTTPGenericRequest.new("BLA", true, true, "/some/path")
- request.method.should == "BLA"
- end
-end
diff --git a/spec/ruby/library/net/http/httpgenericrequest/path_spec.rb b/spec/ruby/library/net/http/httpgenericrequest/path_spec.rb
deleted file mode 100644
index e48d37b0e9..0000000000
--- a/spec/ruby/library/net/http/httpgenericrequest/path_spec.rb
+++ /dev/null
@@ -1,12 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-
-describe "Net::HTTPGenericRequest#path" do
- it "returns self's request path" do
- request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path")
- request.path.should == "/some/path"
-
- request = Net::HTTPGenericRequest.new("POST", true, true, "/some/other/path")
- request.path.should == "/some/other/path"
- end
-end
diff --git a/spec/ruby/library/net/http/httpgenericrequest/request_body_permitted_spec.rb b/spec/ruby/library/net/http/httpgenericrequest/request_body_permitted_spec.rb
deleted file mode 100644
index 1e0b3ab028..0000000000
--- a/spec/ruby/library/net/http/httpgenericrequest/request_body_permitted_spec.rb
+++ /dev/null
@@ -1,12 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-
-describe "Net::HTTPGenericRequest#request_body_permitted?" do
- it "returns true when the request is expected to have a body" do
- request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path")
- request.request_body_permitted?.should be_true
-
- request = Net::HTTPGenericRequest.new("POST", false, true, "/some/path")
- request.request_body_permitted?.should be_false
- end
-end
diff --git a/spec/ruby/library/net/http/httpgenericrequest/response_body_permitted_spec.rb b/spec/ruby/library/net/http/httpgenericrequest/response_body_permitted_spec.rb
deleted file mode 100644
index ee5a43e637..0000000000
--- a/spec/ruby/library/net/http/httpgenericrequest/response_body_permitted_spec.rb
+++ /dev/null
@@ -1,12 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-
-describe "Net::HTTPGenericRequest#response_body_permitted?" do
- it "returns true when the response is expected to have a body" do
- request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path")
- request.response_body_permitted?.should be_true
-
- request = Net::HTTPGenericRequest.new("POST", true, false, "/some/path")
- request.response_body_permitted?.should be_false
- end
-end
diff --git a/spec/ruby/library/net/http/httpgenericrequest/set_body_internal_spec.rb b/spec/ruby/library/net/http/httpgenericrequest/set_body_internal_spec.rb
deleted file mode 100644
index bff8646d5a..0000000000
--- a/spec/ruby/library/net/http/httpgenericrequest/set_body_internal_spec.rb
+++ /dev/null
@@ -1,21 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-
-describe "Net::HTTPGenericRequest#set_body_internal when passed string" do
- before :each do
- @request = Net::HTTPGenericRequest.new("POST", true, true, "/some/path")
- end
-
- it "sets self's body to the passed string" do
- @request.set_body_internal("Some Content")
- @request.body.should == "Some Content"
- end
-
- it "raises an ArgumentError when the body or body_stream of self have already been set" do
- @request.body = "Some Content"
- lambda { @request.set_body_internal("Some other Content") }.should raise_error(ArgumentError)
-
- @request.body_stream = "Some Content"
- lambda { @request.set_body_internal("Some other Content") }.should raise_error(ArgumentError)
- end
-end
diff --git a/spec/ruby/library/net/http/httpheader/add_field_spec.rb b/spec/ruby/library/net/http/httpheader/add_field_spec.rb
deleted file mode 100644
index b736a92694..0000000000
--- a/spec/ruby/library/net/http/httpheader/add_field_spec.rb
+++ /dev/null
@@ -1,31 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../fixtures/classes', __FILE__)
-
-describe "Net::HTTPHeader#add_field when passed key, value" do
- before :each do
- @headers = NetHTTPHeaderSpecs::Example.new
- end
-
- it "adds the passed value to the header entry with the passed key" do
- @headers.add_field("My-Header", "a")
- @headers.get_fields("My-Header").should == ["a"]
-
- @headers.add_field("My-Header", "b")
- @headers.get_fields("My-Header").should == ["a", "b"]
-
- @headers.add_field("My-Header", "c")
- @headers.get_fields("My-Header").should == ["a", "b", "c"]
- end
-
- it "is case-insensitive" do
- @headers.add_field("My-Header", "a")
- @headers.get_fields("My-Header").should == ["a"]
-
- @headers.add_field("my-header", "b")
- @headers.get_fields("My-Header").should == ["a", "b"]
-
- @headers.add_field("MY-HEADER", "c")
- @headers.get_fields("My-Header").should == ["a", "b", "c"]
- end
-end
diff --git a/spec/ruby/library/net/http/httpheader/basic_auth_spec.rb b/spec/ruby/library/net/http/httpheader/basic_auth_spec.rb
deleted file mode 100644
index b9ed792d46..0000000000
--- a/spec/ruby/library/net/http/httpheader/basic_auth_spec.rb
+++ /dev/null
@@ -1,14 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../fixtures/classes', __FILE__)
-
-describe "Net::HTTPHeader#basic_auth when passed account, password" do
- before :each do
- @headers = NetHTTPHeaderSpecs::Example.new
- end
-
- it "sets the 'Authorization' Header entry for basic authorization" do
- @headers.basic_auth("rubyspec", "rocks")
- @headers["Authorization"].should == "Basic cnVieXNwZWM6cm9ja3M="
- end
-end
diff --git a/spec/ruby/library/net/http/httpheader/canonical_each_spec.rb b/spec/ruby/library/net/http/httpheader/canonical_each_spec.rb
deleted file mode 100644
index a891c12d80..0000000000
--- a/spec/ruby/library/net/http/httpheader/canonical_each_spec.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/each_capitalized', __FILE__)
-
-describe "Net::HTTPHeader#canonical_each" do
- it_behaves_like :net_httpheader_each_capitalized, :canonical_each
-end
diff --git a/spec/ruby/library/net/http/httpheader/chunked_spec.rb b/spec/ruby/library/net/http/httpheader/chunked_spec.rb
deleted file mode 100644
index 2b08baf34c..0000000000
--- a/spec/ruby/library/net/http/httpheader/chunked_spec.rb
+++ /dev/null
@@ -1,22 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../fixtures/classes', __FILE__)
-
-describe "Net::HTTPHeader#chunked?" do
- before :each do
- @headers = NetHTTPHeaderSpecs::Example.new
- end
-
- it "returns true if the 'Transfer-Encoding' header entry is set to chunked" do
- @headers.chunked?.should be_false
-
- @headers["Transfer-Encoding"] = "bla"
- @headers.chunked?.should be_false
-
- @headers["Transfer-Encoding"] = "blachunkedbla"
- @headers.chunked?.should be_false
-
- @headers["Transfer-Encoding"] = "chunked"
- @headers.chunked?.should be_true
- end
-end
diff --git a/spec/ruby/library/net/http/httpheader/content_length_spec.rb b/spec/ruby/library/net/http/httpheader/content_length_spec.rb
deleted file mode 100644
index d93eb3a608..0000000000
--- a/spec/ruby/library/net/http/httpheader/content_length_spec.rb
+++ /dev/null
@@ -1,54 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../fixtures/classes', __FILE__)
-
-describe "Net::HTTPHeader#content_length" do
- before :each do
- @headers = NetHTTPHeaderSpecs::Example.new
- end
-
- it "returns nil if no 'Content-Length' header entry is set" do
- @headers.content_length.should be_nil
- end
-
- it "raises a Net::HTTPHeaderSyntaxError when the 'Content-Length' header entry has an invalid format" do
- @headers["Content-Length"] = "invalid"
- lambda { @headers.content_length }.should raise_error(Net::HTTPHeaderSyntaxError)
- end
-
- it "returns the value of the 'Content-Length' header entry as an Integer" do
- @headers["Content-Length"] = "123"
- @headers.content_length.should eql(123)
-
- @headers["Content-Length"] = "123valid"
- @headers.content_length.should eql(123)
-
- @headers["Content-Length"] = "valid123"
- @headers.content_length.should eql(123)
- end
-end
-
-describe "Net::HTTPHeader#content_length=" do
- before :each do
- @headers = NetHTTPHeaderSpecs::Example.new
- end
-
- it "removes the 'Content-Length' entry if passed false or nil" do
- @headers["Content-Length"] = "123"
- @headers.content_length = nil
- @headers["Content-Length"].should be_nil
- end
-
- it "sets the 'Content-Length' entry to the passed value" do
- @headers.content_length = "123"
- @headers["Content-Length"].should == "123"
-
- @headers.content_length = "123valid"
- @headers["Content-Length"].should == "123"
- end
-
- it "sets the 'Content-Length' entry to 0 if the passed value is not valid" do
- @headers.content_length = "invalid123"
- @headers["Content-Length"].should == "0"
- end
-end
diff --git a/spec/ruby/library/net/http/httpheader/content_range_spec.rb b/spec/ruby/library/net/http/httpheader/content_range_spec.rb
deleted file mode 100644
index dc601fb365..0000000000
--- a/spec/ruby/library/net/http/httpheader/content_range_spec.rb
+++ /dev/null
@@ -1,32 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../fixtures/classes', __FILE__)
-
-describe "Net::HTTPHeader#content_range" do
- before :each do
- @headers = NetHTTPHeaderSpecs::Example.new
- end
-
- it "returns a Range object that represents the 'Content-Range' header entry" do
- @headers["Content-Range"] = "bytes 0-499/1234"
- @headers.content_range.should == (0..499)
-
- @headers["Content-Range"] = "bytes 500-1233/1234"
- @headers.content_range.should == (500..1233)
- end
-
- it "returns nil when there is no 'Content-Range' header entry" do
- @headers.content_range.should be_nil
- end
-
- it "raises a Net::HTTPHeaderSyntaxError when the 'Content-Range' has an invalid format" do
- @headers["Content-Range"] = "invalid"
- lambda { @headers.content_range }.should raise_error(Net::HTTPHeaderSyntaxError)
-
- @headers["Content-Range"] = "bytes 123-abc"
- lambda { @headers.content_range }.should raise_error(Net::HTTPHeaderSyntaxError)
-
- @headers["Content-Range"] = "bytes abc-123"
- lambda { @headers.content_range }.should raise_error(Net::HTTPHeaderSyntaxError)
- end
-end
diff --git a/spec/ruby/library/net/http/httpheader/content_type_spec.rb b/spec/ruby/library/net/http/httpheader/content_type_spec.rb
deleted file mode 100644
index 7c3dfba7e7..0000000000
--- a/spec/ruby/library/net/http/httpheader/content_type_spec.rb
+++ /dev/null
@@ -1,26 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/set_content_type', __FILE__)
-
-describe "Net::HTTPHeader#content_type" do
- before :each do
- @headers = NetHTTPHeaderSpecs::Example.new
- end
-
- it "returns the content type string, as per 'Content-Type' header entry" do
- @headers["Content-Type"] = "text/html"
- @headers.content_type.should == "text/html"
-
- @headers["Content-Type"] = "text/html;charset=utf-8"
- @headers.content_type.should == "text/html"
- end
-
- it "returns nil if the 'Content-Type' header entry does not exist" do
- @headers.content_type.should be_nil
- end
-end
-
-describe "Net::HTTPHeader#content_type=" do
- it_behaves_like :net_httpheader_set_content_type, :content_type=
-end
diff --git a/spec/ruby/library/net/http/httpheader/delete_spec.rb b/spec/ruby/library/net/http/httpheader/delete_spec.rb
deleted file mode 100644
index 9adbfd7813..0000000000
--- a/spec/ruby/library/net/http/httpheader/delete_spec.rb
+++ /dev/null
@@ -1,30 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../fixtures/classes', __FILE__)
-
-describe "Net::HTTPHeader#delete when passed key" do
- before :each do
- @headers = NetHTTPHeaderSpecs::Example.new
- end
-
- it "removes the header entry with the passed key" do
- @headers["My-Header"] = "test"
- @headers.delete("My-Header")
-
- @headers["My-Header"].should be_nil
- @headers.size.should eql(0)
- end
-
- it "returns the removed values" do
- @headers["My-Header"] = "test"
- @headers.delete("My-Header").should == ["test"]
- end
-
- it "is case-insensitive" do
- @headers["My-Header"] = "test"
- @headers.delete("my-header")
-
- @headers["My-Header"].should be_nil
- @headers.size.should eql(0)
- end
-end
diff --git a/spec/ruby/library/net/http/httpheader/each_capitalized_name_spec.rb b/spec/ruby/library/net/http/httpheader/each_capitalized_name_spec.rb
deleted file mode 100644
index 7adba9dec5..0000000000
--- a/spec/ruby/library/net/http/httpheader/each_capitalized_name_spec.rb
+++ /dev/null
@@ -1,35 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../fixtures/classes', __FILE__)
-
-describe "Net::HTTPHeader#each_capitalized_name" do
- before :each do
- @headers = NetHTTPHeaderSpecs::Example.new
- @headers["My-Header"] = "test"
- @headers.add_field("My-Other-Header", "a")
- @headers.add_field("My-Other-Header", "b")
- end
-
- describe "when passed a block" do
- it "yields each header key to the passed block (keys capitalized)" do
- res = []
- @headers.each_capitalized_name do |key|
- res << key
- end
- res.sort.should == ["My-Header", "My-Other-Header"]
- end
- end
-
- describe "when passed no block" do
- it "returns an Enumerator" do
- enumerator = @headers.each_capitalized_name
- enumerator.should be_an_instance_of(Enumerator)
-
- res = []
- enumerator.each do |key|
- res << key
- end
- res.sort.should == ["My-Header", "My-Other-Header"]
- end
- end
-end
diff --git a/spec/ruby/library/net/http/httpheader/each_capitalized_spec.rb b/spec/ruby/library/net/http/httpheader/each_capitalized_spec.rb
deleted file mode 100644
index 1dcf18a9d1..0000000000
--- a/spec/ruby/library/net/http/httpheader/each_capitalized_spec.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/each_capitalized', __FILE__)
-
-describe "Net::HTTPHeader#each_capitalized" do
- it_behaves_like :net_httpheader_each_capitalized, :each_capitalized
-end
-
diff --git a/spec/ruby/library/net/http/httpheader/each_header_spec.rb b/spec/ruby/library/net/http/httpheader/each_header_spec.rb
deleted file mode 100644
index 00d5894282..0000000000
--- a/spec/ruby/library/net/http/httpheader/each_header_spec.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/each_header', __FILE__)
-
-describe "Net::HTTPHeader#each_header" do
- it_behaves_like :net_httpheader_each_header, :each_header
-end
diff --git a/spec/ruby/library/net/http/httpheader/each_key_spec.rb b/spec/ruby/library/net/http/httpheader/each_key_spec.rb
deleted file mode 100644
index 5c81830be6..0000000000
--- a/spec/ruby/library/net/http/httpheader/each_key_spec.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/each_name', __FILE__)
-
-describe "Net::HTTPHeader#each_key" do
- it_behaves_like :net_httpheader_each_name, :each_key
-end
diff --git a/spec/ruby/library/net/http/httpheader/each_name_spec.rb b/spec/ruby/library/net/http/httpheader/each_name_spec.rb
deleted file mode 100644
index e785ae249a..0000000000
--- a/spec/ruby/library/net/http/httpheader/each_name_spec.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/each_name', __FILE__)
-
-describe "Net::HTTPHeader#each_name" do
- it_behaves_like :net_httpheader_each_name, :each_name
-end
diff --git a/spec/ruby/library/net/http/httpheader/each_spec.rb b/spec/ruby/library/net/http/httpheader/each_spec.rb
deleted file mode 100644
index e8fb6713c3..0000000000
--- a/spec/ruby/library/net/http/httpheader/each_spec.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/each_header', __FILE__)
-
-describe "Net::HTTPHeader#each" do
- it_behaves_like :net_httpheader_each_header, :each
-end
diff --git a/spec/ruby/library/net/http/httpheader/each_value_spec.rb b/spec/ruby/library/net/http/httpheader/each_value_spec.rb
deleted file mode 100644
index 1adb723a53..0000000000
--- a/spec/ruby/library/net/http/httpheader/each_value_spec.rb
+++ /dev/null
@@ -1,35 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../fixtures/classes', __FILE__)
-
-describe "Net::HTTPHeader#each_value" do
- before :each do
- @headers = NetHTTPHeaderSpecs::Example.new
- @headers["My-Header"] = "test"
- @headers.add_field("My-Other-Header", "a")
- @headers.add_field("My-Other-Header", "b")
- end
-
- describe "when passed a block" do
- it "yields each header entry's joined values" do
- res = []
- @headers.each_value do |value|
- res << value
- end
- res.sort.should == ["a, b", "test"]
- end
- end
-
- describe "when passed no block" do
- it "returns an Enumerator" do
- enumerator = @headers.each_value
- enumerator.should be_an_instance_of(Enumerator)
-
- res = []
- enumerator.each do |key|
- res << key
- end
- res.sort.should == ["a, b", "test"]
- end
- end
-end
diff --git a/spec/ruby/library/net/http/httpheader/element_reference_spec.rb b/spec/ruby/library/net/http/httpheader/element_reference_spec.rb
deleted file mode 100644
index bfe6b48ad4..0000000000
--- a/spec/ruby/library/net/http/httpheader/element_reference_spec.rb
+++ /dev/null
@@ -1,39 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../fixtures/classes', __FILE__)
-
-describe "Net::HTTPHeader#[] when passed key" do
- before :each do
- @headers = NetHTTPHeaderSpecs::Example.new
- end
-
- it "returns the value of the header entry with the passed key" do
- @headers["My-Header"] = "test"
- @headers["My-Header"].should == "test"
- @headers["My-Other-Header"] = "another test"
- @headers["My-Other-Header"].should == "another test"
- end
-
- it "is case-insensitive" do
- @headers["My-Header"] = "test"
-
- @headers['My-Header'].should == "test"
- @headers['my-Header'].should == "test"
- @headers['My-header'].should == "test"
- @headers['my-header'].should == "test"
- @headers['MY-HEADER'].should == "test"
- end
-
- it "returns multi-element values joined together" do
- @headers["My-Header"] = "test"
- @headers.add_field("My-Header", "another test")
- @headers.add_field("My-Header", "and one more")
-
- @headers["My-Header"].should == "test, another test, and one more"
- end
-
- it "returns nil for non-existing entries" do
- @headers["My-Header"].should be_nil
- @headers["My-Other-Header"].should be_nil
- end
-end
diff --git a/spec/ruby/library/net/http/httpheader/element_set_spec.rb b/spec/ruby/library/net/http/httpheader/element_set_spec.rb
deleted file mode 100644
index a5a2900e94..0000000000
--- a/spec/ruby/library/net/http/httpheader/element_set_spec.rb
+++ /dev/null
@@ -1,41 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../fixtures/classes', __FILE__)
-
-describe "Net::HTTPHeader#[]= when passed key, value" do
- before :each do
- @headers = NetHTTPHeaderSpecs::Example.new
- end
-
- it "sets the header entry with the passed key to the passed value" do
- @headers["My-Header"] = "test"
- @headers["My-Header"].should == "test"
-
- @headers["My-Header"] = "overwritten"
- @headers["My-Header"].should == "overwritten"
-
- @headers["My-Other-Header"] = "another test"
- @headers["My-Other-Header"].should == "another test"
- end
-
- it "is case-insensitive" do
- @headers['My-Header'] = "test"
- @headers['my-Header'] = "another test"
- @headers['My-header'] = "and one more test"
- @headers['my-header'] = "and another one"
- @headers['MY-HEADER'] = "last one"
-
- @headers["My-Header"].should == "last one"
- @headers.size.should eql(1)
- end
-
- it "removes the header entry with the passed key when the value is false or nil" do
- @headers['My-Header'] = "test"
- @headers['My-Header'] = nil
- @headers['My-Header'].should be_nil
-
- @headers['My-Header'] = "test"
- @headers['My-Header'] = false
- @headers['My-Header'].should be_nil
- end
-end
diff --git a/spec/ruby/library/net/http/httpheader/fetch_spec.rb b/spec/ruby/library/net/http/httpheader/fetch_spec.rb
deleted file mode 100644
index 7182c4396e..0000000000
--- a/spec/ruby/library/net/http/httpheader/fetch_spec.rb
+++ /dev/null
@@ -1,68 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../fixtures/classes', __FILE__)
-
-describe "Net::HTTPHeader#fetch" do
- before :each do
- @headers = NetHTTPHeaderSpecs::Example.new
- end
-
- describe "when passed key" do
- it "returns the header entry for the passed key" do
- @headers["My-Header"] = "test"
- @headers.fetch("My-Header").should == "test"
-
- @headers.add_field("My-Other-Header", "a")
- @headers.add_field("My-Other-Header", "b")
- @headers.add_field("My-Other-Header", "c")
- @headers.fetch("My-Other-Header").should == "a, b, c"
- end
-
- it "is case-insensitive" do
- @headers["My-Header"] = "test"
- @headers.fetch("my-header").should == "test"
- @headers.fetch("MY-HEADER").should == "test"
- end
-
- it "returns nil when there is no entry for the passed key" do
- lambda { @headers.fetch("my-header") }.should raise_error(IndexError)
- end
- end
-
- describe "when passed key, default" do
- it "returns the header entry for the passed key" do
- @headers["My-Header"] = "test"
- @headers.fetch("My-Header", "bla").should == "test"
-
- @headers.add_field("My-Other-Header", "a")
- @headers.add_field("My-Other-Header", "b")
- @headers.add_field("My-Other-Header", "c")
- @headers.fetch("My-Other-Header", "bla").should == "a, b, c"
- end
-
- # TODO: This raises a NoMethodError: undefined method `join' for "bla":String
- it "returns the default value when there is no entry for the passed key" do
- @headers.fetch("My-Header", "bla").should == "bla"
- end
- end
-
- describe "when passed key and block" do
- it "returns the header entry for the passed key" do
- @headers["My-Header"] = "test"
- @headers.fetch("My-Header") {}.should == "test"
-
- @headers.add_field("My-Other-Header", "a")
- @headers.add_field("My-Other-Header", "b")
- @headers.add_field("My-Other-Header", "c")
- -> {
- @result = @headers.fetch("My-Other-Header", "bla") {}
- }.should complain(/block supersedes default value argument/)
- @result.should == "a, b, c"
- end
-
- # TODO: This raises a NoMethodError: undefined method `join' for "redaeh-ym":String
- it "yieldsand returns the block's return value when there is no entry for the passed key" do
- @headers.fetch("My-Header") { |key| key.reverse }.should == "redaeh-ym"
- end
- end
-end
diff --git a/spec/ruby/library/net/http/httpheader/form_data_spec.rb b/spec/ruby/library/net/http/httpheader/form_data_spec.rb
deleted file mode 100644
index 7781990824..0000000000
--- a/spec/ruby/library/net/http/httpheader/form_data_spec.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/set_form_data', __FILE__)
-
-describe "Net::HTTPHeader#form_data=" do
- it_behaves_like :net_httpheader_set_form_data, :form_data=
-end
diff --git a/spec/ruby/library/net/http/httpheader/get_fields_spec.rb b/spec/ruby/library/net/http/httpheader/get_fields_spec.rb
deleted file mode 100644
index f7828f752c..0000000000
--- a/spec/ruby/library/net/http/httpheader/get_fields_spec.rb
+++ /dev/null
@@ -1,39 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../fixtures/classes', __FILE__)
-
-describe "Net::HTTPHeader#get_fields when passed key" do
- before :each do
- @headers = NetHTTPHeaderSpecs::Example.new
- end
-
- it "returns an Array containing the values of the header entry with the passed key" do
- @headers["My-Header"] = "a"
- @headers.get_fields("My-Header").should == ["a"]
-
- @headers.add_field("My-Header", "b")
- @headers.get_fields("My-Header").should == ["a", "b"]
- end
-
- it "returns a copy of the header entry values" do
- @headers["My-Header"] = "a"
-
- @headers.get_fields("My-Header").clear
- @headers.get_fields("My-Header").should == ["a"]
-
- @headers.get_fields("My-Header") << "b"
- @headers.get_fields("My-Header").should == ["a"]
- end
-
- it "returns nil for non-existing header entries" do
- @headers.get_fields("My-Header").should be_nil
- @headers.get_fields("My-Other-header").should be_nil
- end
-
- it "is case-insensitive" do
- @headers["My-Header"] = "test"
- @headers.get_fields("My-Header").should == ["test"]
- @headers.get_fields("my-header").should == ["test"]
- @headers.get_fields("MY-HEADER").should == ["test"]
- end
-end
diff --git a/spec/ruby/library/net/http/httpheader/initialize_http_header_spec.rb b/spec/ruby/library/net/http/httpheader/initialize_http_header_spec.rb
deleted file mode 100644
index ffb56642d4..0000000000
--- a/spec/ruby/library/net/http/httpheader/initialize_http_header_spec.rb
+++ /dev/null
@@ -1,22 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../fixtures/classes', __FILE__)
-
-describe "Net::HTTPHeader#initialize_http_header when passed Hash" do
- before :each do
- @headers = NetHTTPHeaderSpecs::Example.allocate
- end
-
- it "initializes the HTTP Header using the passed Hash" do
- @headers.initialize_http_header("My-Header" => "test", "My-Other-Header" => "another test")
- @headers["My-Header"].should == "test"
- @headers["My-Other-Header"].should == "another test"
- end
-
- it "complains about duplicate keys when in verbose mode" do
- lambda do
- $VERBOSE = true
- @headers.initialize_http_header("My-Header" => "test", "my-header" => "another test")
- end.should complain(/duplicated HTTP header/)
- end
-end
diff --git a/spec/ruby/library/net/http/httpheader/key_spec.rb b/spec/ruby/library/net/http/httpheader/key_spec.rb
deleted file mode 100644
index 0cb5f711dc..0000000000
--- a/spec/ruby/library/net/http/httpheader/key_spec.rb
+++ /dev/null
@@ -1,21 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../fixtures/classes', __FILE__)
-
-describe "Net::HTTPHeader#key? when passed key" do
- before :each do
- @headers = NetHTTPHeaderSpecs::Example.new
- end
-
- it "returns true if the header entry with the passed key exists" do
- @headers.key?("My-Header").should be_false
- @headers["My-Header"] = "test"
- @headers.key?("My-Header").should be_true
- end
-
- it "is case-insensitive" do
- @headers["My-Header"] = "test"
- @headers.key?("my-header").should be_true
- @headers.key?("MY-HEADER").should be_true
- end
-end
diff --git a/spec/ruby/library/net/http/httpheader/length_spec.rb b/spec/ruby/library/net/http/httpheader/length_spec.rb
deleted file mode 100644
index 50cb1c1f7f..0000000000
--- a/spec/ruby/library/net/http/httpheader/length_spec.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/size', __FILE__)
-
-describe "Net::HTTPHeader#length" do
- it_behaves_like :net_httpheader_size, :length
-end
diff --git a/spec/ruby/library/net/http/httpheader/main_type_spec.rb b/spec/ruby/library/net/http/httpheader/main_type_spec.rb
deleted file mode 100644
index 34e2ddbc65..0000000000
--- a/spec/ruby/library/net/http/httpheader/main_type_spec.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../fixtures/classes', __FILE__)
-
-describe "Net::HTTPHeader#main_type" do
- before :each do
- @headers = NetHTTPHeaderSpecs::Example.new
- end
-
- it "returns the 'main-content-type', as per 'Content-Type' header entry" do
- @headers["Content-Type"] = "text/html"
- @headers.main_type.should == "text"
-
- @headers["Content-Type"] = "application/pdf"
- @headers.main_type.should == "application"
-
- @headers["Content-Type"] = "text/html;charset=utf-8"
- @headers.main_type.should == "text"
- end
-
- it "returns nil if the 'Content-Type' header entry does not exist" do
- @headers.main_type.should be_nil
- end
-end
diff --git a/spec/ruby/library/net/http/httpheader/proxy_basic_auth_spec.rb b/spec/ruby/library/net/http/httpheader/proxy_basic_auth_spec.rb
deleted file mode 100644
index 5e7d87af36..0000000000
--- a/spec/ruby/library/net/http/httpheader/proxy_basic_auth_spec.rb
+++ /dev/null
@@ -1,14 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../fixtures/classes', __FILE__)
-
-describe "Net::HTTPHeader#proxy_basic_auth when passed account, password" do
- before :each do
- @headers = NetHTTPHeaderSpecs::Example.new
- end
-
- it "sets the 'Proxy-Authorization' Header entry for basic authorization" do
- @headers.proxy_basic_auth("rubyspec", "rocks")
- @headers["Proxy-Authorization"].should == "Basic cnVieXNwZWM6cm9ja3M="
- end
-end
diff --git a/spec/ruby/library/net/http/httpheader/range_length_spec.rb b/spec/ruby/library/net/http/httpheader/range_length_spec.rb
deleted file mode 100644
index ec3b00d805..0000000000
--- a/spec/ruby/library/net/http/httpheader/range_length_spec.rb
+++ /dev/null
@@ -1,32 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../fixtures/classes', __FILE__)
-
-describe "Net::HTTPHeader#range_length" do
- before :each do
- @headers = NetHTTPHeaderSpecs::Example.new
- end
-
- it "returns the length of the Range represented by the 'Content-Range' header entry" do
- @headers["Content-Range"] = "bytes 0-499/1234"
- @headers.range_length.should eql(500)
-
- @headers["Content-Range"] = "bytes 500-1233/1234"
- @headers.range_length.should eql(734)
- end
-
- it "returns nil when there is no 'Content-Range' header entry" do
- @headers.range_length.should be_nil
- end
-
- it "raises a Net::HTTPHeaderSyntaxError when the 'Content-Range' has an invalid format" do
- @headers["Content-Range"] = "invalid"
- lambda { @headers.range_length }.should raise_error(Net::HTTPHeaderSyntaxError)
-
- @headers["Content-Range"] = "bytes 123-abc"
- lambda { @headers.range_length }.should raise_error(Net::HTTPHeaderSyntaxError)
-
- @headers["Content-Range"] = "bytes abc-123"
- lambda { @headers.range_length }.should raise_error(Net::HTTPHeaderSyntaxError)
- end
-end
diff --git a/spec/ruby/library/net/http/httpheader/range_spec.rb b/spec/ruby/library/net/http/httpheader/range_spec.rb
deleted file mode 100644
index d71d2ed598..0000000000
--- a/spec/ruby/library/net/http/httpheader/range_spec.rb
+++ /dev/null
@@ -1,48 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/set_range', __FILE__)
-
-describe "Net::HTTPHeader#range" do
- before :each do
- @headers = NetHTTPHeaderSpecs::Example.new
- end
-
- it "returns a Range object that represents the 'Range' header entry" do
- @headers["Range"] = "bytes=0-499"
- @headers.range.should == [0..499]
-
- @headers["Range"] = "bytes=500-1233"
- @headers.range.should == [500..1233]
-
- @headers["Range"] = "bytes=10-"
- @headers.range.should == [10..-1]
-
- @headers["Range"] = "bytes=-10"
- @headers.range.should == [-10..-1]
- end
-
- it "returns nil when there is no 'Range' header entry" do
- @headers.range.should be_nil
- end
-
- it "raises a Net::HTTPHeaderSyntaxError when the 'Range' has an invalid format" do
- @headers["Range"] = "invalid"
- lambda { @headers.range }.should raise_error(Net::HTTPHeaderSyntaxError)
-
- @headers["Range"] = "bytes 123-abc"
- lambda { @headers.range }.should raise_error(Net::HTTPHeaderSyntaxError)
-
- @headers["Range"] = "bytes abc-123"
- lambda { @headers.range }.should raise_error(Net::HTTPHeaderSyntaxError)
- end
-
- it "raises a Net::HTTPHeaderSyntaxError when the 'Range' was not specified" do
- @headers["Range"] = "bytes=-"
- lambda { @headers.range }.should raise_error(Net::HTTPHeaderSyntaxError)
- end
-end
-
-describe "Net::HTTPHeader#range=" do
- it_behaves_like :net_httpheader_set_range, :range=
-end
diff --git a/spec/ruby/library/net/http/httpheader/set_content_type_spec.rb b/spec/ruby/library/net/http/httpheader/set_content_type_spec.rb
deleted file mode 100644
index b9a62154ad..0000000000
--- a/spec/ruby/library/net/http/httpheader/set_content_type_spec.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/set_content_type', __FILE__)
-
-describe "Net::HTTPHeader#set_content_type" do
- it_behaves_like :net_httpheader_set_content_type, :set_content_type
-end
diff --git a/spec/ruby/library/net/http/httpheader/set_form_data_spec.rb b/spec/ruby/library/net/http/httpheader/set_form_data_spec.rb
deleted file mode 100644
index e675437ba4..0000000000
--- a/spec/ruby/library/net/http/httpheader/set_form_data_spec.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/set_form_data', __FILE__)
-
-describe "Net::HTTPHeader#set_form_data" do
- it_behaves_like :net_httpheader_set_form_data, :set_form_data
-end
diff --git a/spec/ruby/library/net/http/httpheader/set_range_spec.rb b/spec/ruby/library/net/http/httpheader/set_range_spec.rb
deleted file mode 100644
index af3f00f99c..0000000000
--- a/spec/ruby/library/net/http/httpheader/set_range_spec.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/set_range', __FILE__)
-
-describe "Net::HTTPHeader#set_range" do
- it_behaves_like :net_httpheader_set_range, :set_range
-end
diff --git a/spec/ruby/library/net/http/httpheader/shared/each_capitalized.rb b/spec/ruby/library/net/http/httpheader/shared/each_capitalized.rb
deleted file mode 100644
index 3bac409876..0000000000
--- a/spec/ruby/library/net/http/httpheader/shared/each_capitalized.rb
+++ /dev/null
@@ -1,31 +0,0 @@
-describe :net_httpheader_each_capitalized, shared: true do
- before :each do
- @headers = NetHTTPHeaderSpecs::Example.new
- @headers["my-header"] = "test"
- @headers.add_field("my-Other-Header", "a")
- @headers.add_field("My-Other-header", "b")
- end
-
- describe "when passed a block" do
- it "yields each header entry to the passed block (capitalized keys, values joined)" do
- res = []
- @headers.send(@method) do |key, value|
- res << [key, value]
- end
- res.sort.should == [["My-Header", "test"], ["My-Other-Header", "a, b"]]
- end
- end
-
- describe "when passed no block" do
- it "returns an Enumerator" do
- enumerator = @headers.send(@method)
- enumerator.should be_an_instance_of(Enumerator)
-
- res = []
- enumerator.each do |*key|
- res << key
- end
- res.sort.should == [["My-Header", "test"], ["My-Other-Header", "a, b"]]
- end
- end
-end
diff --git a/spec/ruby/library/net/http/httpheader/shared/each_header.rb b/spec/ruby/library/net/http/httpheader/shared/each_header.rb
deleted file mode 100644
index 6bf3a6ddfe..0000000000
--- a/spec/ruby/library/net/http/httpheader/shared/each_header.rb
+++ /dev/null
@@ -1,31 +0,0 @@
-describe :net_httpheader_each_header, shared: true do
- before :each do
- @headers = NetHTTPHeaderSpecs::Example.new
- @headers["My-Header"] = "test"
- @headers.add_field("My-Other-Header", "a")
- @headers.add_field("My-Other-Header", "b")
- end
-
- describe "when passed a block" do
- it "yields each header entry to the passed block (keys in lower case, values joined)" do
- res = []
- @headers.send(@method) do |key, value|
- res << [key, value]
- end
- res.sort.should == [["my-header", "test"], ["my-other-header", "a, b"]]
- end
- end
-
- describe "when passed no block" do
- it "returns an Enumerator" do
- enumerator = @headers.send(@method)
- enumerator.should be_an_instance_of(Enumerator)
-
- res = []
- enumerator.each do |*key|
- res << key
- end
- res.sort.should == [["my-header", "test"], ["my-other-header", "a, b"]]
- end
- end
-end
diff --git a/spec/ruby/library/net/http/httpheader/shared/each_name.rb b/spec/ruby/library/net/http/httpheader/shared/each_name.rb
deleted file mode 100644
index efc6a09dfd..0000000000
--- a/spec/ruby/library/net/http/httpheader/shared/each_name.rb
+++ /dev/null
@@ -1,31 +0,0 @@
-describe :net_httpheader_each_name, shared: true do
- before :each do
- @headers = NetHTTPHeaderSpecs::Example.new
- @headers["My-Header"] = "test"
- @headers.add_field("My-Other-Header", "a")
- @headers.add_field("My-Other-Header", "b")
- end
-
- describe "when passed a block" do
- it "yields each header key to the passed block (keys in lower case)" do
- res = []
- @headers.send(@method) do |key|
- res << key
- end
- res.sort.should == ["my-header", "my-other-header"]
- end
- end
-
- describe "when passed no block" do
- it "returns an Enumerator" do
- enumerator = @headers.send(@method)
- enumerator.should be_an_instance_of(Enumerator)
-
- res = []
- enumerator.each do |key|
- res << key
- end
- res.sort.should == ["my-header", "my-other-header"]
- end
- end
-end
diff --git a/spec/ruby/library/net/http/httpheader/shared/set_content_type.rb b/spec/ruby/library/net/http/httpheader/shared/set_content_type.rb
deleted file mode 100644
index b7359bdca6..0000000000
--- a/spec/ruby/library/net/http/httpheader/shared/set_content_type.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-describe :net_httpheader_set_content_type, shared: true do
- describe "when passed type, params" do
- before :each do
- @headers = NetHTTPHeaderSpecs::Example.new
- end
-
- it "sets the 'Content-Type' header entry based on the passed type and params" do
- @headers.send(@method, "text/html")
- @headers["Content-Type"].should == "text/html"
-
- @headers.send(@method, "text/html", "charset" => "utf-8")
- @headers["Content-Type"].should == "text/html; charset=utf-8"
-
- @headers.send(@method, "text/html", "charset" => "utf-8", "rubyspec" => "rocks")
- @headers["Content-Type"].split(/; /).sort.should == %w[charset=utf-8 rubyspec=rocks text/html]
- end
- end
-end
diff --git a/spec/ruby/library/net/http/httpheader/shared/set_form_data.rb b/spec/ruby/library/net/http/httpheader/shared/set_form_data.rb
deleted file mode 100644
index db20b18803..0000000000
--- a/spec/ruby/library/net/http/httpheader/shared/set_form_data.rb
+++ /dev/null
@@ -1,27 +0,0 @@
-describe :net_httpheader_set_form_data, shared: true do
- before :each do
- @headers = NetHTTPHeaderSpecs::Example.new
- end
-
- describe "when passed params" do
- it "automatically set the 'Content-Type' to 'application/x-www-form-urlencoded'" do
- @headers.send(@method, "cmd" => "search", "q" => "ruby", "max" => "50")
- @headers["Content-Type"].should == "application/x-www-form-urlencoded"
- end
-
- it "sets self's body based on the passed form parameters" do
- @headers.send(@method, "cmd" => "search", "q" => "ruby", "max" => "50")
- @headers.body.split("&").sort.should == ["cmd=search", "max=50", "q=ruby"]
- end
- end
-
- describe "when passed params, separator" do
- it "sets self's body based on the passed form parameters and the passed separator" do
- @headers.send(@method, {"cmd" => "search", "q" => "ruby", "max" => "50"}, "&")
- @headers.body.split("&").sort.should == ["cmd=search", "max=50", "q=ruby"]
-
- @headers.send(@method, {"cmd" => "search", "q" => "ruby", "max" => "50"}, ";")
- @headers.body.split(";").sort.should == ["cmd=search", "max=50", "q=ruby"]
- end
- end
-end
diff --git a/spec/ruby/library/net/http/httpheader/shared/set_range.rb b/spec/ruby/library/net/http/httpheader/shared/set_range.rb
deleted file mode 100644
index 6a98edbe10..0000000000
--- a/spec/ruby/library/net/http/httpheader/shared/set_range.rb
+++ /dev/null
@@ -1,89 +0,0 @@
-describe :net_httpheader_set_range, shared: true do
- before :each do
- @headers = NetHTTPHeaderSpecs::Example.new
- end
-
- describe "when passed nil" do
- it "returns nil" do
- @headers.send(@method, nil).should be_nil
- end
-
- it "deletes the 'Range' header entry" do
- @headers["Range"] = "bytes 0-499/1234"
- @headers.send(@method, nil)
- @headers["Range"].should be_nil
- end
- end
-
- describe "when passed Numeric" do
- it "sets the 'Range' header entry based on the passed Numeric" do
- @headers.send(@method, 10)
- @headers["Range"].should == "bytes=0-9"
-
- @headers.send(@method, -10)
- @headers["Range"].should == "bytes=-10"
-
- @headers.send(@method, 10.9)
- @headers["Range"].should == "bytes=0-9"
- end
- end
-
- describe "when passed Range" do
- it "sets the 'Range' header entry based on the passed Range" do
- @headers.send(@method, 10..200)
- @headers["Range"].should == "bytes=10-200"
-
- @headers.send(@method, 1..5)
- @headers["Range"].should == "bytes=1-5"
-
- @headers.send(@method, 1...5)
- @headers["Range"].should == "bytes=1-4"
-
- @headers.send(@method, 234..567)
- @headers["Range"].should == "bytes=234-567"
-
- @headers.send(@method, -5..-1)
- @headers["Range"].should == "bytes=-5"
-
- @headers.send(@method, 1..-1)
- @headers["Range"].should == "bytes=1-"
- end
-
- it "raises a Net::HTTPHeaderSyntaxError when the first Range element is negative" do
- lambda { @headers.send(@method, -10..5) }.should raise_error(Net::HTTPHeaderSyntaxError)
- end
-
- it "raises a Net::HTTPHeaderSyntaxError when the last Range element is negative" do
- lambda { @headers.send(@method, 10..-5) }.should raise_error(Net::HTTPHeaderSyntaxError)
- end
-
- it "raises a Net::HTTPHeaderSyntaxError when the last Range element is smaller than the first" do
- lambda { @headers.send(@method, 10..5) }.should raise_error(Net::HTTPHeaderSyntaxError)
- end
- end
-
- describe "when passed start, end" do
- it "sets the 'Range' header entry based on the passed start and length values" do
- @headers.send(@method, 10, 200)
- @headers["Range"].should == "bytes=10-209"
-
- @headers.send(@method, 1, 5)
- @headers["Range"].should == "bytes=1-5"
-
- @headers.send(@method, 234, 567)
- @headers["Range"].should == "bytes=234-800"
- end
-
- it "raises a Net::HTTPHeaderSyntaxError when start is negative" do
- lambda { @headers.send(@method, -10, 5) }.should raise_error(Net::HTTPHeaderSyntaxError)
- end
-
- it "raises a Net::HTTPHeaderSyntaxError when start + length is negative" do
- lambda { @headers.send(@method, 10, -15) }.should raise_error(Net::HTTPHeaderSyntaxError)
- end
-
- it "raises a Net::HTTPHeaderSyntaxError when length is negative" do
- lambda { @headers.send(@method, 10, -4) }.should raise_error(Net::HTTPHeaderSyntaxError)
- end
- end
-end
diff --git a/spec/ruby/library/net/http/httpheader/shared/size.rb b/spec/ruby/library/net/http/httpheader/shared/size.rb
deleted file mode 100644
index e2b1e4c22b..0000000000
--- a/spec/ruby/library/net/http/httpheader/shared/size.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-describe :net_httpheader_size, shared: true do
- before :each do
- @headers = NetHTTPHeaderSpecs::Example.new
- end
-
- it "returns the number of header entries in self" do
- @headers.send(@method).should eql(0)
-
- @headers["a"] = "b"
- @headers.send(@method).should eql(1)
-
- @headers["b"] = "b"
- @headers.send(@method).should eql(2)
-
- @headers["c"] = "c"
- @headers.send(@method).should eql(3)
- end
-end
diff --git a/spec/ruby/library/net/http/httpheader/size_spec.rb b/spec/ruby/library/net/http/httpheader/size_spec.rb
deleted file mode 100644
index 3ea3969046..0000000000
--- a/spec/ruby/library/net/http/httpheader/size_spec.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../fixtures/classes', __FILE__)
-require File.expand_path('../shared/size', __FILE__)
-
-describe "Net::HTTPHeader#size" do
- it_behaves_like :net_httpheader_size, :size
-end
diff --git a/spec/ruby/library/net/http/httpheader/sub_type_spec.rb b/spec/ruby/library/net/http/httpheader/sub_type_spec.rb
deleted file mode 100644
index 65cae5a3f3..0000000000
--- a/spec/ruby/library/net/http/httpheader/sub_type_spec.rb
+++ /dev/null
@@ -1,32 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../fixtures/classes', __FILE__)
-
-describe "Net::HTTPHeader#sub_type" do
- before :each do
- @headers = NetHTTPHeaderSpecs::Example.new
- end
-
- it "returns the 'sub-content-type', as per 'Content-Type' header entry" do
- @headers["Content-Type"] = "text/html"
- @headers.sub_type.should == "html"
-
- @headers["Content-Type"] = "application/pdf"
- @headers.sub_type.should == "pdf"
-
- @headers["Content-Type"] = "text/html;charset=utf-8"
- @headers.sub_type.should == "html"
- end
-
- it "returns nil if no 'sub-content-type' is set" do
- @headers["Content-Type"] = "text"
- @headers.sub_type.should be_nil
-
- @headers["Content-Type"] = "text;charset=utf-8"
- @headers.sub_type.should be_nil
- end
-
- it "returns nil if the 'Content-Type' header entry does not exist" do
- @headers.sub_type.should be_nil
- end
-end
diff --git a/spec/ruby/library/net/http/httpheader/to_hash_spec.rb b/spec/ruby/library/net/http/httpheader/to_hash_spec.rb
deleted file mode 100644
index 4b59c78c90..0000000000
--- a/spec/ruby/library/net/http/httpheader/to_hash_spec.rb
+++ /dev/null
@@ -1,25 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../fixtures/classes', __FILE__)
-
-describe "Net::HTTPHeader#to_hash" do
- before :each do
- @headers = NetHTTPHeaderSpecs::Example.new
- end
-
- it "returns a Hash representing all Header entries (keys in lower case, values as arrays)" do
- @headers.to_hash.should == {}
-
- @headers["My-Header"] = "test"
- @headers.to_hash.should == { "my-header" => ["test"] }
-
- @headers.add_field("My-Header", "another test")
- @headers.to_hash.should == { "my-header" => ["test", "another test"] }
- end
-
- it "does not allow modifying the headers from the returned hash" do
- @headers.to_hash["my-header"] = ["test"]
- @headers.to_hash.should == {}
- @headers.key?("my-header").should be_false
- end
-end
diff --git a/spec/ruby/library/net/http/httpheader/type_params_spec.rb b/spec/ruby/library/net/http/httpheader/type_params_spec.rb
deleted file mode 100644
index f4cd54f101..0000000000
--- a/spec/ruby/library/net/http/httpheader/type_params_spec.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../fixtures/classes', __FILE__)
-
-describe "Net::HTTPHeader#type_params" do
- before :each do
- @headers = NetHTTPHeaderSpecs::Example.new
- end
-
- it "returns additional 'Content-Type' information as a Hash" do
- @headers["Content-Type"] = "text/html;charset=utf-8"
- @headers.type_params.should == {"charset" => "utf-8"}
-
- @headers["Content-Type"] = "text/html; charset=utf-8; rubyspec=rocks"
- @headers.type_params.should == {"charset" => "utf-8", "rubyspec" => "rocks"}
- end
-
- it "returns an empty Hash when no additional 'Content-Type' information is set" do
- @headers.type_params.should == {}
-
- @headers["Content-Type"] = "text/html"
- @headers.type_params.should == {}
- end
-end
diff --git a/spec/ruby/library/net/http/httprequest/initialize_spec.rb b/spec/ruby/library/net/http/httprequest/initialize_spec.rb
deleted file mode 100644
index 8abbf13c93..0000000000
--- a/spec/ruby/library/net/http/httprequest/initialize_spec.rb
+++ /dev/null
@@ -1,45 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-
-module NetHTTPRequestSpecs
- class TestRequest < Net::HTTPRequest
- METHOD = "TEST"
- REQUEST_HAS_BODY = false
- RESPONSE_HAS_BODY = true
- end
-end
-
-describe "Net::HTTPRequest#initialize" do
- before :each do
- @req = NetHTTPRequestSpecs::TestRequest.allocate
- end
-
- it "uses the METHOD constants to set the request method" do
- @req.send(:initialize, "/some/path")
- @req.method.should == "TEST"
- end
-
- it "uses the REQUEST_HAS_BODY to set whether the Request has a body or not" do
- @req.send(:initialize, "/some/path")
- @req.request_body_permitted?.should be_false
- end
-
- it "uses the RESPONSE_HAS_BODY to set whether the Response can have a body or not" do
- @req.send(:initialize, "/some/path")
- @req.response_body_permitted?.should be_true
- end
-
- describe "when passed path" do
- it "sets self's path to the passed path" do
- @req.send(:initialize, "/some/path")
- @req.path.should == "/some/path"
- end
- end
-
- describe "when passed path, headers" do
- it "uses the passed headers Hash to initialize self's header entries" do
- @req.send(:initialize, "/some/path", "Content-Type" => "text/html")
- @req["Content-Type"].should == "text/html"
- end
- end
-end
diff --git a/spec/ruby/library/net/http/httpresponse/body_permitted_spec.rb b/spec/ruby/library/net/http/httpresponse/body_permitted_spec.rb
deleted file mode 100644
index 9688b0759e..0000000000
--- a/spec/ruby/library/net/http/httpresponse/body_permitted_spec.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-
-describe "Net::HTTPResponse.body_permitted?" do
- it "returns true if this response type can have a response body" do
- Net::HTTPUnknownResponse.body_permitted?.should == true
- Net::HTTPInformation.body_permitted?.should == false
- Net::HTTPSuccess.body_permitted?.should == true
- Net::HTTPRedirection.body_permitted?.should == true
- Net::HTTPClientError.body_permitted?.should == true
- Net::HTTPServerError.body_permitted?.should == true
- end
-end
diff --git a/spec/ruby/library/net/http/httpresponse/body_spec.rb b/spec/ruby/library/net/http/httpresponse/body_spec.rb
deleted file mode 100644
index 169a6687a2..0000000000
--- a/spec/ruby/library/net/http/httpresponse/body_spec.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../shared/body', __FILE__)
-
-describe "Net::HTTPResponse#body" do
- it_behaves_like :net_httpresponse_body, :body
-end
diff --git a/spec/ruby/library/net/http/httpresponse/code_spec.rb b/spec/ruby/library/net/http/httpresponse/code_spec.rb
deleted file mode 100644
index 9430af3100..0000000000
--- a/spec/ruby/library/net/http/httpresponse/code_spec.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-
-describe "Net::HTTPResponse#code" do
- it "returns the result code string" do
- res = Net::HTTPUnknownResponse.new("1.0", "???", "test response")
- res.code.should == "???"
-
- res = Net::HTTPInformation.new("1.0", "1xx", "test response")
- res.code.should == "1xx"
-
- res = Net::HTTPSuccess.new("1.0", "2xx", "test response")
- res.code.should == "2xx"
-
- res = Net::HTTPRedirection.new("1.0", "3xx", "test response")
- res.code.should == "3xx"
-
- res = Net::HTTPClientError.new("1.0", "4xx", "test response")
- res.code.should == "4xx"
-
- res = Net::HTTPServerError.new("1.0", "5xx", "test response")
- res.code.should == "5xx"
- end
-end
diff --git a/spec/ruby/library/net/http/httpresponse/code_type_spec.rb b/spec/ruby/library/net/http/httpresponse/code_type_spec.rb
deleted file mode 100644
index 899c2ed9bf..0000000000
--- a/spec/ruby/library/net/http/httpresponse/code_type_spec.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-
-describe "Net::HTTPResponse#code_type" do
- it "returns self's class" do
- res = Net::HTTPUnknownResponse.new("1.0", "???", "test response")
- res.code_type.should == Net::HTTPUnknownResponse
-
- res = Net::HTTPInformation.new("1.0", "1xx", "test response")
- res.code_type.should == Net::HTTPInformation
-
- res = Net::HTTPSuccess.new("1.0", "2xx", "test response")
- res.code_type.should == Net::HTTPSuccess
-
- res = Net::HTTPRedirection.new("1.0", "3xx", "test response")
- res.code_type.should == Net::HTTPRedirection
-
- res = Net::HTTPClientError.new("1.0", "4xx", "test response")
- res.code_type.should == Net::HTTPClientError
-
- res = Net::HTTPServerError.new("1.0", "5xx", "test response")
- res.code_type.should == Net::HTTPServerError
- end
-end
diff --git a/spec/ruby/library/net/http/httpresponse/entity_spec.rb b/spec/ruby/library/net/http/httpresponse/entity_spec.rb
deleted file mode 100644
index 3b6be5eb00..0000000000
--- a/spec/ruby/library/net/http/httpresponse/entity_spec.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require File.expand_path('../shared/body', __FILE__)
-
-describe "Net::HTTPResponse#entity" do
- it_behaves_like :net_httpresponse_body, :entity
-end
diff --git a/spec/ruby/library/net/http/httpresponse/error_spec.rb b/spec/ruby/library/net/http/httpresponse/error_spec.rb
deleted file mode 100644
index 7b0f61e520..0000000000
--- a/spec/ruby/library/net/http/httpresponse/error_spec.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-
-describe "Net::HTTPResponse#error!" do
- it "raises self's class 'EXCEPTION_TYPE' Exception" do
- res = Net::HTTPUnknownResponse.new("1.0", "???", "test response")
- lambda { res.error! }.should raise_error(Net::HTTPError)
-
- res = Net::HTTPInformation.new("1.0", "1xx", "test response")
- lambda { res.error! }.should raise_error(Net::HTTPError)
-
- res = Net::HTTPSuccess.new("1.0", "2xx", "test response")
- lambda { res.error! }.should raise_error(Net::HTTPError)
-
- res = Net::HTTPRedirection.new("1.0", "3xx", "test response")
- lambda { res.error! }.should raise_error(Net::HTTPRetriableError)
-
- res = Net::HTTPClientError.new("1.0", "4xx", "test response")
- lambda { res.error! }.should raise_error(Net::HTTPServerException)
-
- res = Net::HTTPServerError.new("1.0", "5xx", "test response")
- lambda { res.error! }.should raise_error(Net::HTTPFatalError)
- end
-end
diff --git a/spec/ruby/library/net/http/httpresponse/error_type_spec.rb b/spec/ruby/library/net/http/httpresponse/error_type_spec.rb
deleted file mode 100644
index a6b0155998..0000000000
--- a/spec/ruby/library/net/http/httpresponse/error_type_spec.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-
-describe "Net::HTTPResponse#error_type" do
- it "returns self's class 'EXCEPTION_TYPE' constant" do
- res = Net::HTTPUnknownResponse.new("1.0", "???", "test response")
- res.error_type.should == Net::HTTPError
-
- res = Net::HTTPInformation.new("1.0", "1xx", "test response")
- res.error_type.should == Net::HTTPError
-
- res = Net::HTTPSuccess.new("1.0", "2xx", "test response")
- res.error_type.should == Net::HTTPError
-
- res = Net::HTTPRedirection.new("1.0", "3xx", "test response")
- res.error_type.should == Net::HTTPRetriableError
-
- res = Net::HTTPClientError.new("1.0", "4xx", "test response")
- res.error_type.should == Net::HTTPServerException
-
- res = Net::HTTPServerError.new("1.0", "5xx", "test response")
- res.error_type.should == Net::HTTPFatalError
- end
-end
diff --git a/spec/ruby/library/net/http/httpresponse/exception_type_spec.rb b/spec/ruby/library/net/http/httpresponse/exception_type_spec.rb
deleted file mode 100644
index e1a48e0c12..0000000000
--- a/spec/ruby/library/net/http/httpresponse/exception_type_spec.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-
-describe "Net::HTTPResponse.exception_type" do
- it "returns self's 'EXCEPTION_TYPE' constant" do
- Net::HTTPUnknownResponse.exception_type.should == Net::HTTPError
- Net::HTTPInformation.exception_type.should == Net::HTTPError
- Net::HTTPSuccess.exception_type.should == Net::HTTPError
- Net::HTTPRedirection.exception_type.should == Net::HTTPRetriableError
- Net::HTTPClientError.exception_type.should == Net::HTTPServerException
- Net::HTTPServerError.exception_type.should == Net::HTTPFatalError
- end
-end
diff --git a/spec/ruby/library/net/http/httpresponse/header_spec.rb b/spec/ruby/library/net/http/httpresponse/header_spec.rb
deleted file mode 100644
index 21e3dec418..0000000000
--- a/spec/ruby/library/net/http/httpresponse/header_spec.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-
-describe "Net::HTTPResponse#header" do
- it "returns self" do
- res = Net::HTTPUnknownResponse.new("1.0", "???", "test response")
- res.response.should equal(res)
- end
-end
diff --git a/spec/ruby/library/net/http/httpresponse/http_version_spec.rb b/spec/ruby/library/net/http/httpresponse/http_version_spec.rb
deleted file mode 100644
index a1192c1cbe..0000000000
--- a/spec/ruby/library/net/http/httpresponse/http_version_spec.rb
+++ /dev/null
@@ -1,12 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-
-describe "Net::HTTPResponse#http_version" do
- it "returns self's http version" do
- res = Net::HTTPUnknownResponse.new("1.0", "???", "test response")
- res.http_version.should == "1.0"
-
- res = Net::HTTPUnknownResponse.new("1.1", "???", "test response")
- res.http_version.should == "1.1"
- end
-end
diff --git a/spec/ruby/library/net/http/httpresponse/initialize_spec.rb b/spec/ruby/library/net/http/httpresponse/initialize_spec.rb
deleted file mode 100644
index dcb6da3afe..0000000000
--- a/spec/ruby/library/net/http/httpresponse/initialize_spec.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-
-describe "Net::HTTPResponse#initialize when passed http_version, response_code, response_message" do
- it "sets self http_version, response_code and response_message to the passed values" do
- res = Net::HTTPUnknownResponse.new("1.0", "???", "test response")
- res.http_version.should == "1.0"
- res.code.should == "???"
- res.message.should == "test response"
- end
-end
diff --git a/spec/ruby/library/net/http/httpresponse/inspect_spec.rb b/spec/ruby/library/net/http/httpresponse/inspect_spec.rb
deleted file mode 100644
index f5463afa96..0000000000
--- a/spec/ruby/library/net/http/httpresponse/inspect_spec.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require "stringio"
-
-describe "Net::HTTPResponse#inspect" do
- it "returns a String representation of self" do
- res = Net::HTTPUnknownResponse.new("1.0", "???", "test response")
- res.inspect.should == "#<Net::HTTPUnknownResponse ??? test response readbody=false>"
-
- res = Net::HTTPUnknownResponse.new("1.0", "???", "test response")
- socket = Net::BufferedIO.new(StringIO.new("test body"))
- res.reading_body(socket, true) {}
- res.inspect.should == "#<Net::HTTPUnknownResponse ??? test response readbody=true>"
- end
-end
diff --git a/spec/ruby/library/net/http/httpresponse/message_spec.rb b/spec/ruby/library/net/http/httpresponse/message_spec.rb
deleted file mode 100644
index 57a927aff0..0000000000
--- a/spec/ruby/library/net/http/httpresponse/message_spec.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-
-describe "Net::HTTPResponse#message" do
- it "returns self's response message" do
- res = Net::HTTPUnknownResponse.new("1.0", "???", "test response")
- res.message.should == "test response"
- end
-end
diff --git a/spec/ruby/library/net/http/httpresponse/msg_spec.rb b/spec/ruby/library/net/http/httpresponse/msg_spec.rb
deleted file mode 100644
index 9b19d34234..0000000000
--- a/spec/ruby/library/net/http/httpresponse/msg_spec.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-
-describe "Net::HTTPResponse#msg" do
- it "returns self's response message" do
- res = Net::HTTPUnknownResponse.new("1.0", "???", "test response")
- res.message.should == "test response"
- end
-end
diff --git a/spec/ruby/library/net/http/httpresponse/read_body_spec.rb b/spec/ruby/library/net/http/httpresponse/read_body_spec.rb
deleted file mode 100644
index d71b4144f4..0000000000
--- a/spec/ruby/library/net/http/httpresponse/read_body_spec.rb
+++ /dev/null
@@ -1,86 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-
-describe "Net::HTTPResponse#read_body" do
- before :each do
- @res = Net::HTTPUnknownResponse.new("1.0", "???", "test response")
- @socket = Net::BufferedIO.new(StringIO.new("test body"))
- end
-
- describe "when passed no arguments" do
- it "returns the read body" do
- @res.reading_body(@socket, true) do
- @res.read_body.should == "test body"
- end
- end
-
- it "returns the previously read body if called a second time" do
- @res.reading_body(@socket, true) do
- @res.read_body.should equal(@res.read_body)
- end
- end
- end
-
- describe "when passed a buffer" do
- it "reads the body to the passed buffer" do
- @res.reading_body(@socket, true) do
- buffer = ""
- @res.read_body(buffer)
- buffer.should == "test body"
- end
- end
-
- it "returns the passed buffer" do
- @res.reading_body(@socket, true) do
- buffer = ""
- @res.read_body(buffer).should equal(buffer)
- end
- end
-
- it "raises an IOError if called a second time" do
- @res.reading_body(@socket, true) do
- @res.read_body("")
- lambda { @res.read_body("") }.should raise_error(IOError)
- end
- end
- end
-
- describe "when passed a block" do
- it "reads the body and yields it to the passed block (in chunks)" do
- @res.reading_body(@socket, true) do
- yielded = false
-
- buffer = ""
- @res.read_body do |body|
- yielded = true
- buffer << body
- end
-
- yielded.should be_true
- buffer.should == "test body"
- end
- end
-
- it "returns the ReadAdapter" do
- @res.reading_body(@socket, true) do
- @res.read_body { nil }.should be_kind_of(Net::ReadAdapter)
- end
- end
-
- it "raises an IOError if called a second time" do
- @res.reading_body(@socket, true) do
- @res.read_body {}
- lambda { @res.read_body {} }.should raise_error(IOError)
- end
- end
- end
-
- describe "when passed buffer and block" do
- it "rauses an ArgumentError" do
- @res.reading_body(@socket, true) do
- lambda { @res.read_body("") {} }.should raise_error(ArgumentError)
- end
- end
- end
-end
-
diff --git a/spec/ruby/library/net/http/httpresponse/read_header_spec.rb b/spec/ruby/library/net/http/httpresponse/read_header_spec.rb
deleted file mode 100644
index 6bbabdfe10..0000000000
--- a/spec/ruby/library/net/http/httpresponse/read_header_spec.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-
-describe "Net::HTTPResponse#read_header" do
- it "returns self" do
- res = Net::HTTPUnknownResponse.new("1.0", "???", "test response")
- res.response.should equal(res)
- end
-end
diff --git a/spec/ruby/library/net/http/httpresponse/read_new_spec.rb b/spec/ruby/library/net/http/httpresponse/read_new_spec.rb
deleted file mode 100644
index e2fb0f1a05..0000000000
--- a/spec/ruby/library/net/http/httpresponse/read_new_spec.rb
+++ /dev/null
@@ -1,22 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-
-describe "Net::HTTPResponse.read_new" do
- it "creates a HTTPResponse object based on the response read from the passed socket" do
- socket = Net::BufferedIO.new(StringIO.new(<<EOS))
-HTTP/1.1 200 OK
-Content-Type: text/html; charset=utf-8
-
-test-body
-EOS
- response = Net::HTTPResponse.read_new(socket)
-
- response.should be_kind_of(Net::HTTPOK)
- response.code.should == "200"
- response["Content-Type"].should == "text/html; charset=utf-8"
-
- response.reading_body(socket, true) do
- response.body.should == "test-body\n"
- end
- end
-end
diff --git a/spec/ruby/library/net/http/httpresponse/reading_body_spec.rb b/spec/ruby/library/net/http/httpresponse/reading_body_spec.rb
deleted file mode 100644
index 5e53e00adc..0000000000
--- a/spec/ruby/library/net/http/httpresponse/reading_body_spec.rb
+++ /dev/null
@@ -1,58 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-require "stringio"
-
-describe "Net::HTTPResponse#reading_body" do
- before :each do
- @res = Net::HTTPUnknownResponse.new("1.0", "???", "test response")
- @socket = Net::BufferedIO.new(StringIO.new("test body"))
- end
-
- describe "when body_allowed is true" do
- it "reads and returns the response body for self from the passed socket" do
- @res.reading_body(@socket, true) {}.should == "test body"
- @res.body.should == "test body"
- end
-
- it "yields the passed block before reading the body" do
- yielded = false
-
- @res.reading_body(@socket, true) do
- @res.inspect.should == "#<Net::HTTPUnknownResponse ??? test response readbody=false>"
- yielded = true
- end
-
- yielded.should be_true
- end
-
- describe "but the response type is not allowed to have a body" do
- before :each do
- @res = Net::HTTPInformation.new("1.0", "???", "test response")
- end
-
- it "returns nil" do
- @res.reading_body(@socket, false) {}.should be_nil
- @res.body.should be_nil
- end
-
- it "yields the passed block" do
- yielded = false
- @res.reading_body(@socket, true) { yielded = true }
- yielded.should be_true
- end
- end
- end
-
- describe "when body_allowed is false" do
- it "returns nil" do
- @res.reading_body(@socket, false) {}.should be_nil
- @res.body.should be_nil
- end
-
- it "yields the passed block" do
- yielded = false
- @res.reading_body(@socket, true) { yielded = true }
- yielded.should be_true
- end
- end
-end
diff --git a/spec/ruby/library/net/http/httpresponse/response_spec.rb b/spec/ruby/library/net/http/httpresponse/response_spec.rb
deleted file mode 100644
index 826320be9e..0000000000
--- a/spec/ruby/library/net/http/httpresponse/response_spec.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-
-describe "Net::HTTPResponse#response" do
- it "returns self" do
- res = Net::HTTPUnknownResponse.new("1.0", "???", "test response")
- res.response.should equal(res)
- end
-end
diff --git a/spec/ruby/library/net/http/httpresponse/shared/body.rb b/spec/ruby/library/net/http/httpresponse/shared/body.rb
deleted file mode 100644
index 91d5fe6375..0000000000
--- a/spec/ruby/library/net/http/httpresponse/shared/body.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-describe :net_httpresponse_body, shared: true do
- before :each do
- @res = Net::HTTPUnknownResponse.new("1.0", "???", "test response")
- @socket = Net::BufferedIO.new(StringIO.new("test body"))
- end
-
- it "returns the read body" do
- @res.reading_body(@socket, true) do
- @res.send(@method).should == "test body"
- end
- end
-
- it "returns the previously read body if called a second time" do
- @res.reading_body(@socket, true) do
- @res.send(@method).should equal(@res.send(@method))
- end
- end
-end
diff --git a/spec/ruby/library/net/http/httpresponse/value_spec.rb b/spec/ruby/library/net/http/httpresponse/value_spec.rb
deleted file mode 100644
index 7e4f7863eb..0000000000
--- a/spec/ruby/library/net/http/httpresponse/value_spec.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-require File.expand_path('../../../../../spec_helper', __FILE__)
-require 'net/http'
-
-describe "Net::HTTPResponse#value" do
- it "raises an HTTP error for non 2xx HTTP Responses" do
- res = Net::HTTPUnknownResponse.new("1.0", "???", "test response")
- lambda { res.value }.should raise_error(Net::HTTPError)
-
- res = Net::HTTPInformation.new("1.0", "1xx", "test response")
- lambda { res.value }.should raise_error(Net::HTTPError)
-
- res = Net::HTTPSuccess.new("1.0", "2xx", "test response")
- lambda { res.value }.should_not raise_error(Net::HTTPError)
-
- res = Net::HTTPRedirection.new("1.0", "3xx", "test response")
- lambda { res.value }.should raise_error(Net::HTTPRetriableError)
-
- res = Net::HTTPClientError.new("1.0", "4xx", "test response")
- lambda { res.value }.should raise_error(Net::HTTPServerException)
-
- res = Net::HTTPServerError.new("1.0", "5xx", "test response")
- lambda { res.value }.should raise_error(Net::HTTPFatalError)
- end
-end
diff --git a/spec/ruby/library/objectspace/dump_all_spec.rb b/spec/ruby/library/objectspace/dump_all_spec.rb
new file mode 100644
index 0000000000..c92812ebd5
--- /dev/null
+++ b/spec/ruby/library/objectspace/dump_all_spec.rb
@@ -0,0 +1,112 @@
+require_relative '../../spec_helper'
+require 'objspace'
+
+describe "ObjectSpace.dump_all" do
+ it "dumps Ruby heap to string when passed output: :string" do
+ stdout = ruby_exe(<<~RUBY, options: "-robjspace")
+ string = "abc"
+ dump = ObjectSpace.dump_all(output: :string)
+ puts dump.class
+ puts dump.include?('"value":"abc"')
+ RUBY
+
+ stdout.should == "String\ntrue\n"
+ end
+
+ it "dumps Ruby heap to a temporary file when passed output: :file" do
+ stdout = ruby_exe(<<~RUBY, options: "-robjspace")
+ string = "abc"
+ file = ObjectSpace.dump_all(output: :file)
+
+ begin
+ file.flush
+ file.rewind
+ content = file.read
+
+ puts file.class
+ puts content.include?('"value":"abc"')
+ ensure
+ file.close
+ File.unlink file.path
+ end
+ RUBY
+
+ stdout.should == "File\ntrue\n"
+ end
+
+ it "dumps Ruby heap to a temporary file when :output not specified" do
+ stdout = ruby_exe(<<~RUBY, options: "-robjspace")
+ string = "abc"
+ file = ObjectSpace.dump_all
+
+ begin
+ file.flush
+ file.rewind
+ content = file.read
+
+ puts file.class
+ puts content.include?('"value":"abc"')
+ ensure
+ file.close
+ File.unlink file.path
+ end
+ RUBY
+
+ stdout.should == "File\ntrue\n"
+ end
+
+ it "dumps Ruby heap to a temporary file when passed output: :nil" do
+ stdout = ruby_exe(<<~RUBY, options: "-robjspace")
+ string = "abc"
+ file = ObjectSpace.dump_all(output: nil)
+
+ begin
+ file.flush
+ file.rewind
+ content = file.read
+
+ puts file.class
+ puts content.include?('"value":"abc"')
+ ensure
+ file.close
+ File.unlink file.path
+ end
+ RUBY
+
+ stdout.should == "File\ntrue\n"
+ end
+
+ it "dumps Ruby heap to stdout when passed output: :stdout" do
+ stdout = ruby_exe(<<~RUBY, options: "-robjspace")
+ string = "abc"
+ ObjectSpace.dump_all(output: :stdout)
+ RUBY
+
+ stdout.should.include?('"value":"abc"')
+ end
+
+ it "dumps Ruby heap to provided IO when passed output: IO" do
+ stdout = ruby_exe(<<~RUBY, options: "-robjspace -rtempfile")
+ string = "abc"
+ io = Tempfile.create("object_space_dump_all")
+
+ begin
+ result = ObjectSpace.dump_all(output: io)
+ io.rewind
+ content = io.read
+
+ puts result.equal?(io)
+ puts content.include?('"value":"abc"')
+ ensure
+ io.close
+ File.unlink io.path
+ end
+ RUBY
+
+ stdout.should == "true\ntrue\n"
+ end
+
+ it "raises ArgumentError when passed not supported :output value" do
+ -> { ObjectSpace.dump_all(output: Object.new) }.should.raise(ArgumentError, /wrong output option/)
+ end
+end
diff --git a/spec/ruby/library/objectspace/dump_spec.rb b/spec/ruby/library/objectspace/dump_spec.rb
new file mode 100644
index 0000000000..4b5e0da198
--- /dev/null
+++ b/spec/ruby/library/objectspace/dump_spec.rb
@@ -0,0 +1,70 @@
+require_relative '../../spec_helper'
+require 'objspace'
+
+describe "ObjectSpace.dump" do
+ it "dumps the content of object as JSON" do
+ require 'json'
+ string = ObjectSpace.dump("abc")
+ dump = JSON.parse(string)
+
+ dump['type'].should == "STRING"
+ dump['value'].should == "abc"
+ end
+
+ it "dumps to string when passed output: :string" do
+ string = ObjectSpace.dump("abc", output: :string)
+ string.should.is_a?(String)
+ string.should.include?('"value":"abc"')
+ end
+
+ it "dumps to string when :output not specified" do
+ string = ObjectSpace.dump("abc")
+ string.should.is_a?(String)
+ string.should.include?('"value":"abc"')
+ end
+
+ it "dumps to a temporary file when passed output: :file" do
+ file = ObjectSpace.dump("abc", output: :file)
+ file.should.is_a?(File)
+
+ file.rewind
+ content = file.read
+ content.should.include?('"value":"abc"')
+ ensure
+ file.close
+ File.unlink file.path
+ end
+
+ it "dumps to a temporary file when passed output: :nil" do
+ file = ObjectSpace.dump("abc", output: nil)
+ file.should.is_a?(File)
+
+ file.rewind
+ file.read.should.include?('"value":"abc"')
+ ensure
+ file.close
+ File.unlink file.path
+ end
+
+ it "dumps to stdout when passed output: :stdout" do
+ stdout = ruby_exe('ObjectSpace.dump("abc", output: :stdout)', options: "-robjspace").chomp
+ stdout.should.include?('"value":"abc"')
+ end
+
+ it "dumps to provided IO when passed output: IO" do
+ filename = tmp("io_read.txt")
+ io = File.open(filename, "w+")
+ result = ObjectSpace.dump("abc", output: io)
+ result.should.equal? io
+
+ io.rewind
+ io.read.should.include?('"value":"abc"')
+ ensure
+ io.close
+ rm_r filename
+ end
+
+ it "raises ArgumentError when passed not supported :output value" do
+ -> { ObjectSpace.dump("abc", output: Object.new) }.should.raise(ArgumentError, /wrong output option/)
+ end
+end
diff --git a/spec/ruby/library/objectspace/fixtures/trace.rb b/spec/ruby/library/objectspace/fixtures/trace.rb
new file mode 100644
index 0000000000..e53a7a0cac
--- /dev/null
+++ b/spec/ruby/library/objectspace/fixtures/trace.rb
@@ -0,0 +1,6 @@
+# frozen_string_literal: false
+require "objspace/trace"
+a = "foo"
+b = "b" + "a" + "r"
+c = 42
+p a, b, c
diff --git a/spec/ruby/library/objectspace/memsize_of_all_spec.rb b/spec/ruby/library/objectspace/memsize_of_all_spec.rb
new file mode 100644
index 0000000000..9fc6e8be9d
--- /dev/null
+++ b/spec/ruby/library/objectspace/memsize_of_all_spec.rb
@@ -0,0 +1,22 @@
+require_relative '../../spec_helper'
+require 'objspace'
+
+describe "ObjectSpace.memsize_of_all" do
+ it "returns a non-zero Integer for all objects" do
+ ObjectSpace.memsize_of_all.should.is_a?(Integer)
+ ObjectSpace.memsize_of_all.should > 0
+ end
+
+ it "returns a non-zero Integer for Class" do
+ ObjectSpace.memsize_of_all(Class).should.is_a?(Integer)
+ ObjectSpace.memsize_of_all(Class).should > 0
+ end
+
+ it "increases when a new object is allocated" do
+ c = Class.new
+ before = ObjectSpace.memsize_of_all(c)
+ o = c.new
+ after = ObjectSpace.memsize_of_all(c)
+ after.should > before
+ end
+end
diff --git a/spec/ruby/library/objectspace/memsize_of_spec.rb b/spec/ruby/library/objectspace/memsize_of_spec.rb
new file mode 100644
index 0000000000..9c8aea4e84
--- /dev/null
+++ b/spec/ruby/library/objectspace/memsize_of_spec.rb
@@ -0,0 +1,34 @@
+require_relative '../../spec_helper'
+require 'objspace'
+
+describe "ObjectSpace.memsize_of" do
+ it "returns 0 for true, false and nil" do
+ ObjectSpace.memsize_of(true).should == 0
+ ObjectSpace.memsize_of(false).should == 0
+ ObjectSpace.memsize_of(nil).should == 0
+ end
+
+ it "returns 0 for small Integers" do
+ ObjectSpace.memsize_of(42).should == 0
+ end
+
+ it "returns 0 for literal Symbols" do
+ ObjectSpace.memsize_of(:object_space_memsize_spec_static_sym).should == 0
+ end
+
+ it "returns a positive Integer for an Object" do
+ obj = Object.new
+ ObjectSpace.memsize_of(obj).should.is_a?(Integer)
+ ObjectSpace.memsize_of(obj).should > 0
+ end
+
+ it "is larger if the Object has more instance variables" do
+ obj = Object.new
+ before = ObjectSpace.memsize_of(obj)
+ 100.times do |i|
+ obj.instance_variable_set(:"@foo#{i}", nil)
+ end
+ after = ObjectSpace.memsize_of(obj)
+ after.should > before
+ end
+end
diff --git a/spec/ruby/library/objectspace/reachable_objects_from_spec.rb b/spec/ruby/library/objectspace/reachable_objects_from_spec.rb
new file mode 100644
index 0000000000..4620bdec31
--- /dev/null
+++ b/spec/ruby/library/objectspace/reachable_objects_from_spec.rb
@@ -0,0 +1,59 @@
+require_relative '../../spec_helper'
+require 'objspace'
+
+describe "ObjectSpace.reachable_objects_from" do
+ it "returns nil for true and false" do
+ ObjectSpace.reachable_objects_from(true).should == nil
+ ObjectSpace.reachable_objects_from(false).should == nil
+ end
+
+ it "returns nil for nil" do
+ ObjectSpace.reachable_objects_from(nil).should == nil
+ end
+
+ it "returns nil for small Integers" do
+ ObjectSpace.reachable_objects_from(42).should == nil
+ end
+
+ it "enumerates objects directly reachable from a given object" do
+ ObjectSpace.reachable_objects_from(['a', 'b', 'c']).to_set.should >= Set[Array, 'a', 'b', 'c']
+ ObjectSpace.reachable_objects_from(Object.new).should == [Object]
+ end
+
+ it "finds an object stored in an Array" do
+ obj = Object.new
+ ary = [obj]
+ reachable = ObjectSpace.reachable_objects_from(ary)
+ reachable.should.include?(obj)
+ end
+
+ it "finds an object stored in a copy-on-write Array" do
+ removed = Object.new
+ obj = Object.new
+ ary = [removed, obj]
+ ary.shift
+ reachable = ObjectSpace.reachable_objects_from(ary)
+ reachable.should.include?(obj)
+ reachable.should_not.include?(removed)
+ end
+
+ it "finds an object stored in a Queue" do
+ o = Object.new
+ q = Queue.new
+ q << o
+
+ reachable = ObjectSpace.reachable_objects_from(q)
+ reachable = reachable + reachable.flat_map { |r| ObjectSpace.reachable_objects_from(r) }
+ reachable.should.include?(o)
+ end
+
+ it "finds an object stored in a SizedQueue" do
+ o = Object.new
+ q = SizedQueue.new(3)
+ q << o
+
+ reachable = ObjectSpace.reachable_objects_from(q)
+ reachable = reachable + reachable.flat_map { |r| ObjectSpace.reachable_objects_from(r) }
+ reachable.should.include?(o)
+ end
+end
diff --git a/spec/ruby/library/objectspace/trace_object_allocations_spec.rb b/spec/ruby/library/objectspace/trace_object_allocations_spec.rb
new file mode 100644
index 0000000000..0bb6efbfa5
--- /dev/null
+++ b/spec/ruby/library/objectspace/trace_object_allocations_spec.rb
@@ -0,0 +1,163 @@
+require_relative '../../spec_helper'
+require 'objspace'
+
+describe "ObjectSpace.trace_object_allocations" do
+ def has_class_frame?
+ Class.new {
+ attr_reader :c
+
+ def initialize
+ @c = caller_locations.first.label =~ /new/
+ end
+ }.new.c
+ end
+
+ def obj_class_path
+ has_class_frame? ? "Class" : nil
+ end
+
+ it "runs a block" do
+ ScratchPad.clear
+ ObjectSpace.trace_object_allocations do
+ ScratchPad.record :a
+ end
+ ScratchPad.recorded.should == :a
+ end
+
+ it "records info for allocation_class_path" do
+ ObjectSpace.trace_object_allocations do
+ o = Object.new
+ ObjectSpace.allocation_class_path(o).should == obj_class_path
+ a = [1, 2, 3]
+ ObjectSpace.allocation_class_path(a).should == nil
+ end
+ end
+
+ it "records info for allocation_generation" do
+ ObjectSpace.trace_object_allocations do
+ o = Object.new
+ ObjectSpace.allocation_generation(o).should.kind_of?(Integer)
+ a = [1, 2, 3]
+ ObjectSpace.allocation_generation(a).should.kind_of?(Integer)
+ end
+ end
+
+ it "records info for allocation_method_id" do
+ ObjectSpace.trace_object_allocations do
+ o = Object.new
+ ObjectSpace.allocation_method_id(o).should == (has_class_frame? ? :new : nil)
+ a = [1, 2, 3]
+ ObjectSpace.allocation_method_id(a).should == nil
+ end
+ end
+
+ it "records info for allocation_sourcefile" do
+ ObjectSpace.trace_object_allocations do
+ o = Object.new
+ ObjectSpace.allocation_sourcefile(o).should == __FILE__
+ a = [1, 2, 3]
+ ObjectSpace.allocation_sourcefile(a).should == __FILE__
+ end
+ end
+
+ it "records info for allocation_sourceline" do
+ ObjectSpace.trace_object_allocations do
+ o = Object.new
+ ObjectSpace.allocation_sourceline(o).should == __LINE__ - 1
+ a = [1, 2, 3]
+ ObjectSpace.allocation_sourceline(a).should == __LINE__ - 1
+ end
+ end
+
+ it "can be cleared using trace_object_allocations_clear" do
+ ObjectSpace.trace_object_allocations do
+ o = Object.new
+ ObjectSpace.allocation_class_path(o).should == obj_class_path
+ ObjectSpace.trace_object_allocations_clear
+ ObjectSpace.allocation_class_path(o).should == nil
+ end
+ end
+
+ it "does not clears allocation data after returning" do
+ o = nil
+ ObjectSpace.trace_object_allocations do
+ o = Object.new
+ end
+ ObjectSpace.allocation_class_path(o).should == obj_class_path
+ end
+
+ it "can be used without a block using trace_object_allocations_start and _stop" do
+ ObjectSpace.trace_object_allocations_start
+ begin
+ o = Object.new
+ ObjectSpace.allocation_class_path(o).should == obj_class_path
+ a = [1, 2, 3]
+ ObjectSpace.allocation_class_path(a).should == nil
+ ensure
+ ObjectSpace.trace_object_allocations_stop
+ end
+ end
+
+ it "does not clears allocation data after trace_object_allocations_stop" do
+ ObjectSpace.trace_object_allocations_start
+ begin
+ o = Object.new
+ ensure
+ ObjectSpace.trace_object_allocations_stop
+ end
+ ObjectSpace.allocation_class_path(o).should == obj_class_path
+ end
+
+ it "can be nested" do
+ ObjectSpace.trace_object_allocations do
+ ObjectSpace.trace_object_allocations do
+ o = Object.new
+ ObjectSpace.allocation_class_path(o).should == obj_class_path
+ end
+ end
+ end
+
+ it "can be nested without a block using trace_object_allocations_start and _stop" do
+ ObjectSpace.trace_object_allocations_start
+ begin
+ ObjectSpace.trace_object_allocations_start
+ begin
+ o = Object.new
+ ObjectSpace.allocation_class_path(o).should == obj_class_path
+ ensure
+ ObjectSpace.trace_object_allocations_stop
+ end
+ ensure
+ ObjectSpace.trace_object_allocations_stop
+ end
+ end
+
+ it "can be nested with more _stop than _start" do
+ ObjectSpace.trace_object_allocations_start
+ begin
+ o = Object.new
+ ObjectSpace.allocation_class_path(o).should == obj_class_path
+ ObjectSpace.trace_object_allocations_stop
+ ensure
+ ObjectSpace.trace_object_allocations_stop
+ end
+ end
+
+ it "returns nil for class_path, generation, method_id, sourcefile, and sourceline for immutable objects" do
+ ObjectSpace.trace_object_allocations_start
+ begin
+ one = nil
+ two = 42
+ three = :foo
+ [one, two, three].each do |i|
+ ObjectSpace.allocation_class_path(i).should == nil
+ ObjectSpace.allocation_generation(i).should == nil
+ ObjectSpace.allocation_method_id(i).should == nil
+ ObjectSpace.allocation_sourcefile(i).should == nil
+ ObjectSpace.allocation_sourceline(i).should == nil
+ end
+ ensure
+ ObjectSpace.trace_object_allocations_stop
+ end
+ end
+end
diff --git a/spec/ruby/library/objectspace/trace_spec.rb b/spec/ruby/library/objectspace/trace_spec.rb
new file mode 100644
index 0000000000..3957dc930d
--- /dev/null
+++ b/spec/ruby/library/objectspace/trace_spec.rb
@@ -0,0 +1,13 @@
+require_relative '../../spec_helper'
+
+describe 'require "objspace/trace"' do
+ it "shows object allocation sites" do
+ file = fixture(__FILE__ , "trace.rb")
+ ruby_exe(file, args: "2>&1").lines(chomp: true).should == [
+ "objspace/trace is enabled",
+ "\"foo\" @ #{file}:3",
+ "\"bar\" @ #{file}:4",
+ "42"
+ ]
+ end
+end
diff --git a/spec/ruby/library/observer/add_observer_spec.rb b/spec/ruby/library/observer/add_observer_spec.rb
index 7a2d349c85..5217ae6dc4 100644
--- a/spec/ruby/library/observer/add_observer_spec.rb
+++ b/spec/ruby/library/observer/add_observer_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Observer#add_observer" do
diff --git a/spec/ruby/library/observer/count_observers_spec.rb b/spec/ruby/library/observer/count_observers_spec.rb
index 68eaccfaaa..c93674196d 100644
--- a/spec/ruby/library/observer/count_observers_spec.rb
+++ b/spec/ruby/library/observer/count_observers_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Observer#count_observers" do
before :each do
diff --git a/spec/ruby/library/observer/delete_observer_spec.rb b/spec/ruby/library/observer/delete_observer_spec.rb
index b9dc95167c..52be1a6cba 100644
--- a/spec/ruby/library/observer/delete_observer_spec.rb
+++ b/spec/ruby/library/observer/delete_observer_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Observer#delete_observer" do
before :each do
diff --git a/spec/ruby/library/observer/delete_observers_spec.rb b/spec/ruby/library/observer/delete_observers_spec.rb
index 58b10418dd..186e93a013 100644
--- a/spec/ruby/library/observer/delete_observers_spec.rb
+++ b/spec/ruby/library/observer/delete_observers_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Observer#delete_observers" do
before :each do
diff --git a/spec/ruby/library/observer/notify_observers_spec.rb b/spec/ruby/library/observer/notify_observers_spec.rb
index cafbdd56e6..6f3f984637 100644
--- a/spec/ruby/library/observer/notify_observers_spec.rb
+++ b/spec/ruby/library/observer/notify_observers_spec.rb
@@ -1,5 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Observer#notify_observers" do
@@ -16,9 +16,9 @@ describe "Observer#notify_observers" do
end
it "verifies observer responds to update" do
- lambda {
+ -> {
@observable.add_observer(@observable)
- }.should raise_error(NoMethodError)
+ }.should.raise(NoMethodError)
end
it "receives the callback" do
diff --git a/spec/ruby/library/open3/capture2_spec.rb b/spec/ruby/library/open3/capture2_spec.rb
index e5bcc67ae0..f707281d7f 100644
--- a/spec/ruby/library/open3/capture2_spec.rb
+++ b/spec/ruby/library/open3/capture2_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'open3'
describe "Open3.capture2" do
diff --git a/spec/ruby/library/open3/capture2e_spec.rb b/spec/ruby/library/open3/capture2e_spec.rb
index 6254914222..7dd42f3491 100644
--- a/spec/ruby/library/open3/capture2e_spec.rb
+++ b/spec/ruby/library/open3/capture2e_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'open3'
describe "Open3.capture2e" do
diff --git a/spec/ruby/library/open3/capture3_spec.rb b/spec/ruby/library/open3/capture3_spec.rb
index cbfa023eb5..55c858c03f 100644
--- a/spec/ruby/library/open3/capture3_spec.rb
+++ b/spec/ruby/library/open3/capture3_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'open3'
describe "Open3.capture3" do
diff --git a/spec/ruby/library/open3/pipeline_r_spec.rb b/spec/ruby/library/open3/pipeline_r_spec.rb
index c5c2f02087..e1b476f856 100644
--- a/spec/ruby/library/open3/pipeline_r_spec.rb
+++ b/spec/ruby/library/open3/pipeline_r_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'open3'
describe "Open3.pipeline_r" do
diff --git a/spec/ruby/library/open3/pipeline_rw_spec.rb b/spec/ruby/library/open3/pipeline_rw_spec.rb
index 6f9830270b..8d889a200a 100644
--- a/spec/ruby/library/open3/pipeline_rw_spec.rb
+++ b/spec/ruby/library/open3/pipeline_rw_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'open3'
describe "Open3.pipeline_rw" do
diff --git a/spec/ruby/library/open3/pipeline_spec.rb b/spec/ruby/library/open3/pipeline_spec.rb
index f8ace3d2da..5dc628dcaf 100644
--- a/spec/ruby/library/open3/pipeline_spec.rb
+++ b/spec/ruby/library/open3/pipeline_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'open3'
describe "Open3.pipeline" do
diff --git a/spec/ruby/library/open3/pipeline_start_spec.rb b/spec/ruby/library/open3/pipeline_start_spec.rb
index 76af0b88e5..af426807fe 100644
--- a/spec/ruby/library/open3/pipeline_start_spec.rb
+++ b/spec/ruby/library/open3/pipeline_start_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'open3'
describe "Open3.pipeline_start" do
diff --git a/spec/ruby/library/open3/pipeline_w_spec.rb b/spec/ruby/library/open3/pipeline_w_spec.rb
index e3336b7fe1..0c2a3ca4e7 100644
--- a/spec/ruby/library/open3/pipeline_w_spec.rb
+++ b/spec/ruby/library/open3/pipeline_w_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'open3'
describe "Open3.pipeline_w" do
diff --git a/spec/ruby/library/open3/popen2_spec.rb b/spec/ruby/library/open3/popen2_spec.rb
index 49bab91bef..a1a251660a 100644
--- a/spec/ruby/library/open3/popen2_spec.rb
+++ b/spec/ruby/library/open3/popen2_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'open3'
describe "Open3.popen2" do
diff --git a/spec/ruby/library/open3/popen2e_spec.rb b/spec/ruby/library/open3/popen2e_spec.rb
index 2361543afa..e65607160c 100644
--- a/spec/ruby/library/open3/popen2e_spec.rb
+++ b/spec/ruby/library/open3/popen2e_spec.rb
@@ -1,4 +1,4 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'open3'
describe "Open3.popen2e" do
diff --git a/spec/ruby/library/open3/popen3_spec.rb b/spec/ruby/library/open3/popen3_spec.rb
index 9733ab15cd..3651bd516c 100644
--- a/spec/ruby/library/open3/popen3_spec.rb
+++ b/spec/ruby/library/open3/popen3_spec.rb
@@ -1,14 +1,14 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
require 'open3'
describe "Open3.popen3" do
it "returns in, out, err and a thread waiting the process" do
stdin, out, err, waiter = Open3.popen3(ruby_cmd("print :foo"))
begin
- stdin.should be_kind_of IO
- out.should be_kind_of IO
- err.should be_kind_of IO
- waiter.should be_kind_of Thread
+ stdin.should.is_a? IO
+ out.should.is_a? IO
+ err.should.is_a? IO
+ waiter.should.is_a? Thread
out.read.should == "foo"
ensure
@@ -38,6 +38,4 @@ describe "Open3.popen3" do
out.read.should == "foo"
end
end
-
- it "needs to be reviewed for spec completeness"
end
diff --git a/spec/ruby/library/openssl/cipher_spec.rb b/spec/ruby/library/openssl/cipher_spec.rb
index c3eb1280a2..91da1c592c 100644
--- a/spec/ruby/library/openssl/cipher_spec.rb
+++ b/spec/ruby/library/openssl/cipher_spec.rb
@@ -1,9 +1,9 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../shared/constants', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'shared/constants'
require 'openssl'
describe "OpenSSL::Cipher's CipherError" do
it "exists under OpenSSL::Cipher namespace" do
- OpenSSL::Cipher.should have_constant :CipherError
+ OpenSSL::Cipher.should.const_defined?(:CipherError, false)
end
end
diff --git a/spec/ruby/library/openssl/config/freeze_spec.rb b/spec/ruby/library/openssl/config/freeze_spec.rb
deleted file mode 100644
index 2ed48ae629..0000000000
--- a/spec/ruby/library/openssl/config/freeze_spec.rb
+++ /dev/null
@@ -1,16 +0,0 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../shared/constants', __FILE__)
-
-require 'openssl'
-
-describe "OpenSSL::Config#freeze" do
- it "needs to be reviewed for completeness"
-
- it "freezes" do
- c = OpenSSL::Config.new
- lambda{c['foo'] = [ ['key', 'value'] ]}.should_not raise_error
- c.freeze
- c.frozen?.should be_true
- lambda{c['foo'] = [ ['key', 'value'] ]}.should raise_error
- end
-end
diff --git a/spec/ruby/library/openssl/digest/append_spec.rb b/spec/ruby/library/openssl/digest/append_spec.rb
new file mode 100644
index 0000000000..08802b7253
--- /dev/null
+++ b/spec/ruby/library/openssl/digest/append_spec.rb
@@ -0,0 +1,6 @@
+require_relative '../../../spec_helper'
+require_relative 'shared/update'
+
+describe "OpenSSL::Digest#<<" do
+ it_behaves_like :openssl_digest_update, :<<
+end
diff --git a/spec/ruby/library/openssl/digest/block_length_spec.rb b/spec/ruby/library/openssl/digest/block_length_spec.rb
new file mode 100644
index 0000000000..444ed9d20d
--- /dev/null
+++ b/spec/ruby/library/openssl/digest/block_length_spec.rb
@@ -0,0 +1,44 @@
+require_relative '../../../spec_helper'
+require_relative '../../../library/digest/sha1/shared/constants'
+require_relative '../../../library/digest/sha256/shared/constants'
+require_relative '../../../library/digest/sha384/shared/constants'
+require_relative '../../../library/digest/sha512/shared/constants'
+require 'openssl'
+
+describe "OpenSSL::Digest#block_length" do
+ context "when the digest object is created via a name argument" do
+ it "returns a SHA1 block length" do
+ OpenSSL::Digest.new('sha1').block_length.should == SHA1Constants::BlockLength
+ end
+
+ it "returns a SHA256 block length" do
+ OpenSSL::Digest.new('sha256').block_length.should == SHA256Constants::BlockLength
+ end
+
+ it "returns a SHA384 block length" do
+ OpenSSL::Digest.new('sha384').block_length.should == SHA384Constants::BlockLength
+ end
+
+ it "returns a SHA512 block length" do
+ OpenSSL::Digest.new('sha512').block_length.should == SHA512Constants::BlockLength
+ end
+ end
+
+ context "when the digest object is created via a subclass" do
+ it "returns a SHA1 block length" do
+ OpenSSL::Digest::SHA1.new.block_length.should == SHA1Constants::BlockLength
+ end
+
+ it "returns a SHA256 block length" do
+ OpenSSL::Digest::SHA256.new.block_length.should == SHA256Constants::BlockLength
+ end
+
+ it "returns a SHA384 block length" do
+ OpenSSL::Digest::SHA384.new.block_length.should == SHA384Constants::BlockLength
+ end
+
+ it "returns a SHA512 block length" do
+ OpenSSL::Digest::SHA512.new.block_length.should == SHA512Constants::BlockLength
+ end
+ end
+end
diff --git a/spec/ruby/library/openssl/digest/digest_length_spec.rb b/spec/ruby/library/openssl/digest/digest_length_spec.rb
new file mode 100644
index 0000000000..37d1cba9a7
--- /dev/null
+++ b/spec/ruby/library/openssl/digest/digest_length_spec.rb
@@ -0,0 +1,44 @@
+require_relative '../../../spec_helper'
+require_relative '../../../library/digest/sha1/shared/constants'
+require_relative '../../../library/digest/sha256/shared/constants'
+require_relative '../../../library/digest/sha384/shared/constants'
+require_relative '../../../library/digest/sha512/shared/constants'
+require 'openssl'
+
+describe "OpenSSL::Digest#digest_length" do
+ context "when the digest object is created via a name argument" do
+ it "returns a SHA1 digest length" do
+ OpenSSL::Digest.new('sha1').digest_length.should == SHA1Constants::DigestLength
+ end
+
+ it "returns a SHA256 digest length" do
+ OpenSSL::Digest.new('sha256').digest_length.should == SHA256Constants::DigestLength
+ end
+
+ it "returns a SHA384 digest length" do
+ OpenSSL::Digest.new('sha384').digest_length.should == SHA384Constants::DigestLength
+ end
+
+ it "returns a SHA512 digest length" do
+ OpenSSL::Digest.new('sha512').digest_length.should == SHA512Constants::DigestLength
+ end
+ end
+
+ context "when the digest object is created via a subclass" do
+ it "returns a SHA1 digest length" do
+ OpenSSL::Digest::SHA1.new.digest_length.should == SHA1Constants::DigestLength
+ end
+
+ it "returns a SHA256 digest length" do
+ OpenSSL::Digest::SHA256.new.digest_length.should == SHA256Constants::DigestLength
+ end
+
+ it "returns a SHA384 digest length" do
+ OpenSSL::Digest::SHA384.new.digest_length.should == SHA384Constants::DigestLength
+ end
+
+ it "returns a SHA512 digest length" do
+ OpenSSL::Digest::SHA512.new.digest_length.should == SHA512Constants::DigestLength
+ end
+ end
+end
diff --git a/spec/ruby/library/openssl/digest/digest_spec.rb b/spec/ruby/library/openssl/digest/digest_spec.rb
new file mode 100644
index 0000000000..cf27d01b6d
--- /dev/null
+++ b/spec/ruby/library/openssl/digest/digest_spec.rb
@@ -0,0 +1,62 @@
+require_relative '../../../spec_helper'
+require_relative '../../../library/digest/sha1/shared/constants'
+require_relative '../../../library/digest/sha256/shared/constants'
+require_relative '../../../library/digest/sha384/shared/constants'
+require_relative '../../../library/digest/sha512/shared/constants'
+require 'openssl'
+
+describe "OpenSSL::Digest class methods" do
+ describe ".digest" do
+ it "returns a SHA1 digest" do
+ OpenSSL::Digest.digest('sha1', SHA1Constants::Contents).should == SHA1Constants::Digest
+ end
+
+ it "returns a SHA256 digest" do
+ OpenSSL::Digest.digest('sha256', SHA256Constants::Contents).should == SHA256Constants::Digest
+ end
+
+ it "returns a SHA384 digest" do
+ OpenSSL::Digest.digest('sha384', SHA384Constants::Contents).should == SHA384Constants::Digest
+ end
+
+ it "returns a SHA512 digest" do
+ OpenSSL::Digest.digest('sha512', SHA512Constants::Contents).should == SHA512Constants::Digest
+ end
+ end
+
+ describe ".hexdigest" do
+ it "returns a SHA1 hexdigest" do
+ OpenSSL::Digest.hexdigest('sha1', SHA1Constants::Contents).should == SHA1Constants::Hexdigest
+ end
+
+ it "returns a SHA256 hexdigest" do
+ OpenSSL::Digest.hexdigest('sha256', SHA256Constants::Contents).should == SHA256Constants::Hexdigest
+ end
+
+ it "returns a SHA384 hexdigest" do
+ OpenSSL::Digest.hexdigest('sha384', SHA384Constants::Contents).should == SHA384Constants::Hexdigest
+ end
+
+ it "returns a SHA512 hexdigest" do
+ OpenSSL::Digest.hexdigest('sha512', SHA512Constants::Contents).should == SHA512Constants::Hexdigest
+ end
+ end
+
+ describe ".base64digest" do
+ it "returns a SHA1 base64digest" do
+ OpenSSL::Digest.base64digest('sha1', SHA1Constants::Contents).should == SHA1Constants::Base64digest
+ end
+
+ it "returns a SHA256 base64digest" do
+ OpenSSL::Digest.base64digest('sha256', SHA256Constants::Contents).should == SHA256Constants::Base64digest
+ end
+
+ it "returns a SHA384 base64digest" do
+ OpenSSL::Digest.base64digest('sha384', SHA384Constants::Contents).should == SHA384Constants::Base64digest
+ end
+
+ it "returns a SHA512 base64digest" do
+ OpenSSL::Digest.base64digest('sha512', SHA512Constants::Contents).should == SHA512Constants::Base64digest
+ end
+ end
+end
diff --git a/spec/ruby/library/openssl/digest/initialize_spec.rb b/spec/ruby/library/openssl/digest/initialize_spec.rb
new file mode 100644
index 0000000000..e24ab51d14
--- /dev/null
+++ b/spec/ruby/library/openssl/digest/initialize_spec.rb
@@ -0,0 +1,137 @@
+require_relative '../../../spec_helper'
+require_relative '../../../library/digest/sha1/shared/constants'
+require_relative '../../../library/digest/sha256/shared/constants'
+require_relative '../../../library/digest/sha384/shared/constants'
+require_relative '../../../library/digest/sha512/shared/constants'
+require 'openssl'
+
+describe "OpenSSL::Digest#initialize" do
+ describe "can be called with a digest name" do
+ it "returns a SHA1 object" do
+ OpenSSL::Digest.new("sha1").name.should == "SHA1"
+ end
+
+ it "returns a SHA256 object" do
+ OpenSSL::Digest.new("sha256").name.should == "SHA256"
+ end
+
+ it "returns a SHA384 object" do
+ OpenSSL::Digest.new("sha384").name.should == "SHA384"
+ end
+
+ it "returns a SHA512 object" do
+ OpenSSL::Digest.new("sha512").name.should == "SHA512"
+ end
+
+ version_is OpenSSL::VERSION, "4.0.0" do
+ it "throws an error when called with an unknown digest" do
+ -> { OpenSSL::Digest.new("wd40") }.should.raise(OpenSSL::Digest::DigestError, /wd40/)
+ end
+ end
+
+ it "cannot be called with a symbol" do
+ -> { OpenSSL::Digest.new(:SHA1) }.should.raise(TypeError)
+ end
+ end
+
+ describe "can be called with a digest object" do
+ it "returns a SHA1 object" do
+ OpenSSL::Digest.new(OpenSSL::Digest::SHA1.new).name.should == "SHA1"
+ end
+
+ it "returns a SHA256 object" do
+ OpenSSL::Digest.new(OpenSSL::Digest::SHA256.new).name.should == "SHA256"
+ end
+
+ it "returns a SHA384 object" do
+ OpenSSL::Digest.new(OpenSSL::Digest::SHA384.new).name.should == "SHA384"
+ end
+
+ it "returns a SHA512 object" do
+ OpenSSL::Digest.new(OpenSSL::Digest::SHA512.new).name.should == "SHA512"
+ end
+
+ it "ignores the state of the digest object" do
+ sha1 = OpenSSL::Digest.new('sha1', SHA1Constants::Contents)
+ OpenSSL::Digest.new(sha1).digest.should == SHA1Constants::BlankDigest
+ end
+ end
+
+ it "cannot be called with a digest class" do
+ -> { OpenSSL::Digest.new(OpenSSL::Digest::SHA1) }.should.raise(TypeError)
+ end
+
+ context "when called without an initial String argument" do
+ it "returns a SHA1 digest" do
+ OpenSSL::Digest.new("sha1").digest.should == SHA1Constants::BlankDigest
+ end
+
+ it "returns a SHA256 digest" do
+ OpenSSL::Digest.new("sha256").digest.should == SHA256Constants::BlankDigest
+ end
+
+ it "returns a SHA384 digest" do
+ OpenSSL::Digest.new("sha384").digest.should == SHA384Constants::BlankDigest
+ end
+
+ it "returns a SHA512 digest" do
+ OpenSSL::Digest.new("sha512").digest.should == SHA512Constants::BlankDigest
+ end
+ end
+
+ context "when called with an initial String argument" do
+ it "returns a SHA1 digest of that argument" do
+ OpenSSL::Digest.new("sha1", SHA1Constants::Contents).digest.should == SHA1Constants::Digest
+ end
+
+ it "returns a SHA256 digest of that argument" do
+ OpenSSL::Digest.new("sha256", SHA256Constants::Contents).digest.should == SHA256Constants::Digest
+ end
+
+ it "returns a SHA384 digest of that argument" do
+ OpenSSL::Digest.new("sha384", SHA384Constants::Contents).digest.should == SHA384Constants::Digest
+ end
+
+ it "returns a SHA512 digest of that argument" do
+ OpenSSL::Digest.new("sha512", SHA512Constants::Contents).digest.should == SHA512Constants::Digest
+ end
+ end
+
+ context "can be called on subclasses" do
+ describe "can be called without an initial String argument on subclasses" do
+ it "returns a SHA1 digest" do
+ OpenSSL::Digest::SHA1.new.digest.should == SHA1Constants::BlankDigest
+ end
+
+ it "returns a SHA256 digest" do
+ OpenSSL::Digest::SHA256.new.digest.should == SHA256Constants::BlankDigest
+ end
+
+ it "returns a SHA384 digest" do
+ OpenSSL::Digest::SHA384.new.digest.should == SHA384Constants::BlankDigest
+ end
+
+ it "returns a SHA512 digest" do
+ OpenSSL::Digest::SHA512.new.digest.should == SHA512Constants::BlankDigest
+ end
+ end
+
+ describe "can be called with an initial String argument on subclasses" do
+ it "returns a SHA1 digest" do
+ OpenSSL::Digest::SHA1.new(SHA1Constants::Contents).digest.should == SHA1Constants::Digest
+ end
+
+ it "returns a SHA256 digest" do
+ OpenSSL::Digest::SHA256.new(SHA256Constants::Contents).digest.should == SHA256Constants::Digest
+ end
+
+ it "returns a SHA384 digest" do
+ OpenSSL::Digest::SHA384.new(SHA384Constants::Contents).digest.should == SHA384Constants::Digest
+ end
+
+ it "returns a SHA512 digest" do
+ OpenSSL::Digest::SHA512.new(SHA512Constants::Contents).digest.should == SHA512Constants::Digest
+ end
+ end
+ end
+end
diff --git a/spec/ruby/library/openssl/digest/name_spec.rb b/spec/ruby/library/openssl/digest/name_spec.rb
new file mode 100644
index 0000000000..b379f35c1c
--- /dev/null
+++ b/spec/ruby/library/openssl/digest/name_spec.rb
@@ -0,0 +1,16 @@
+require_relative '../../../spec_helper'
+require 'openssl'
+
+describe "OpenSSL::Digest#name" do
+ it "returns the name of digest" do
+ OpenSSL::Digest.new('SHA1').name.should == 'SHA1'
+ end
+
+ it "converts the name to the internal representation of OpenSSL" do
+ OpenSSL::Digest.new('sha1').name.should == 'SHA1'
+ end
+
+ it "works on subclasses too" do
+ OpenSSL::Digest::SHA1.new.name.should == 'SHA1'
+ end
+end
diff --git a/spec/ruby/library/openssl/digest/reset_spec.rb b/spec/ruby/library/openssl/digest/reset_spec.rb
new file mode 100644
index 0000000000..c19bf46633
--- /dev/null
+++ b/spec/ruby/library/openssl/digest/reset_spec.rb
@@ -0,0 +1,36 @@
+require_relative '../../../spec_helper'
+require_relative '../../../library/digest/sha1/shared/constants'
+require_relative '../../../library/digest/sha256/shared/constants'
+require_relative '../../../library/digest/sha384/shared/constants'
+require_relative '../../../library/digest/sha512/shared/constants'
+require 'openssl'
+
+describe "OpenSSL::Digest#reset" do
+ it "works for a SHA1 digest" do
+ digest = OpenSSL::Digest.new('sha1', SHA1Constants::Contents)
+ digest.reset
+ digest.update(SHA1Constants::Contents)
+ digest.digest.should == SHA1Constants::Digest
+ end
+
+ it "works for a SHA256 digest" do
+ digest = OpenSSL::Digest.new('sha256', SHA256Constants::Contents)
+ digest.reset
+ digest.update(SHA256Constants::Contents)
+ digest.digest.should == SHA256Constants::Digest
+ end
+
+ it "works for a SHA384 digest" do
+ digest = OpenSSL::Digest.new('sha384', SHA384Constants::Contents)
+ digest.reset
+ digest.update(SHA384Constants::Contents)
+ digest.digest.should == SHA384Constants::Digest
+ end
+
+ it "works for a SHA512 digest" do
+ digest = OpenSSL::Digest.new('sha512', SHA512Constants::Contents)
+ digest.reset
+ digest.update(SHA512Constants::Contents)
+ digest.digest.should == SHA512Constants::Digest
+ end
+end
diff --git a/spec/ruby/library/openssl/digest/shared/update.rb b/spec/ruby/library/openssl/digest/shared/update.rb
new file mode 100644
index 0000000000..37277c945d
--- /dev/null
+++ b/spec/ruby/library/openssl/digest/shared/update.rb
@@ -0,0 +1,123 @@
+require_relative '../../../../library/digest/sha1/shared/constants'
+require_relative '../../../../library/digest/sha256/shared/constants'
+require_relative '../../../../library/digest/sha384/shared/constants'
+require_relative '../../../../library/digest/sha512/shared/constants'
+require 'openssl'
+
+describe :openssl_digest_update, shared: true do
+ context "when given input as a single string" do
+ it "returns a SHA1 digest" do
+ digest = OpenSSL::Digest.new('sha1')
+ digest.send(@method, SHA1Constants::Contents)
+ digest.digest.should == SHA1Constants::Digest
+ end
+
+ it "returns a SHA256 digest" do
+ digest = OpenSSL::Digest.new('sha256')
+ digest.send(@method, SHA256Constants::Contents)
+ digest.digest.should == SHA256Constants::Digest
+ end
+
+ it "returns a SHA384 digest" do
+ digest = OpenSSL::Digest.new('sha384')
+ digest.send(@method, SHA384Constants::Contents)
+ digest.digest.should == SHA384Constants::Digest
+ end
+
+ it "returns a SHA512 digest" do
+ digest = OpenSSL::Digest.new('sha512')
+ digest.send(@method, SHA512Constants::Contents)
+ digest.digest.should == SHA512Constants::Digest
+ end
+ end
+
+ context "when given input as multiple smaller substrings" do
+ it "returns a SHA1 digest" do
+ digest = OpenSSL::Digest.new('sha1')
+ SHA1Constants::Contents.each_char { |b| digest.send(@method, b) }
+ digest.digest.should == SHA1Constants::Digest
+ end
+
+ it "returns a SHA256 digest" do
+ digest = OpenSSL::Digest.new('sha256')
+ SHA256Constants::Contents.each_char { |b| digest.send(@method, b) }
+ digest.digest.should == SHA256Constants::Digest
+ end
+
+ it "returns a SHA384 digest" do
+ digest = OpenSSL::Digest.new('sha384')
+ SHA384Constants::Contents.each_char { |b| digest.send(@method, b) }
+ digest.digest.should == SHA384Constants::Digest
+ end
+
+ it "returns a SHA512 digest" do
+ digest = OpenSSL::Digest.new('sha512')
+ SHA512Constants::Contents.each_char { |b| digest.send(@method, b) }
+ digest.digest.should == SHA512Constants::Digest
+ end
+ end
+
+ context "when input is not a String and responds to #to_str" do
+ it "returns a SHA1 digest" do
+ str = mock('str')
+ str.should_receive(:to_str).and_return(SHA1Constants::Contents)
+ digest = OpenSSL::Digest.new('sha1')
+ digest.send(@method, str)
+ digest.digest.should == SHA1Constants::Digest
+ end
+
+ it "returns a SHA256 digest" do
+ str = mock('str')
+ str.should_receive(:to_str).and_return(SHA256Constants::Contents)
+ digest = OpenSSL::Digest.new('sha256')
+ digest.send(@method, str)
+ digest.digest.should == SHA256Constants::Digest
+ end
+
+ it "returns a SHA384 digest" do
+ str = mock('str')
+ str.should_receive(:to_str).and_return(SHA384Constants::Contents)
+ digest = OpenSSL::Digest.new('sha384')
+ digest.send(@method, str)
+ digest.digest.should == SHA384Constants::Digest
+ end
+
+ it "returns a SHA512 digest" do
+ str = mock('str')
+ str.should_receive(:to_str).and_return(SHA512Constants::Contents)
+ digest = OpenSSL::Digest.new('sha512')
+ digest.send(@method, str)
+ digest.digest.should == SHA512Constants::Digest
+ end
+ end
+
+ context "when input is not a String and does not respond to #to_str" do
+ it "raises a TypeError with SHA1" do
+ digest = OpenSSL::Digest.new('sha1')
+ -> {
+ digest.send(@method, Object.new)
+ }.should.raise(TypeError, 'no implicit conversion of Object into String')
+ end
+
+ it "raises a TypeError with SHA256" do
+ digest = OpenSSL::Digest.new('sha256')
+ -> {
+ digest.send(@method, Object.new)
+ }.should.raise(TypeError, 'no implicit conversion of Object into String')
+ end
+
+ it "raises a TypeError with SHA384" do
+ digest = OpenSSL::Digest.new('sha384')
+ -> {
+ digest.send(@method, Object.new)
+ }.should.raise(TypeError, 'no implicit conversion of Object into String')
+ end
+
+ it "raises a TypeError with SHA512" do
+ digest = OpenSSL::Digest.new('sha512')
+ -> {
+ digest.send(@method, Object.new)
+ }.should.raise(TypeError, 'no implicit conversion of Object into String')
+ end
+ end
+end
diff --git a/spec/ruby/library/openssl/digest/update_spec.rb b/spec/ruby/library/openssl/digest/update_spec.rb
new file mode 100644
index 0000000000..3a90b06c6b
--- /dev/null
+++ b/spec/ruby/library/openssl/digest/update_spec.rb
@@ -0,0 +1,6 @@
+require_relative '../../../spec_helper'
+require_relative 'shared/update'
+
+describe "OpenSSL::Digest#update" do
+ it_behaves_like :openssl_digest_update, :update
+end
diff --git a/spec/ruby/library/openssl/fixed_length_secure_compare_spec.rb b/spec/ruby/library/openssl/fixed_length_secure_compare_spec.rb
new file mode 100644
index 0000000000..cc638e1f0d
--- /dev/null
+++ b/spec/ruby/library/openssl/fixed_length_secure_compare_spec.rb
@@ -0,0 +1,42 @@
+require_relative '../../spec_helper'
+require 'openssl'
+
+describe "OpenSSL.fixed_length_secure_compare" do
+ it "returns true for two strings with the same content" do
+ input1 = "the quick brown fox jumps over the lazy dog"
+ input2 = "the quick brown fox jumps over the lazy dog"
+ OpenSSL.fixed_length_secure_compare(input1, input2).should == true
+ end
+
+ it "returns false for two strings of equal size with different content" do
+ input1 = "the quick brown fox jumps over the lazy dog"
+ input2 = "the lazy dog jumps over the quick brown fox"
+ OpenSSL.fixed_length_secure_compare(input1, input2).should == false
+ end
+
+ it "converts both arguments to strings using #to_str" do
+ input1 = mock("input1")
+ input1.should_receive(:to_str).and_return("the quick brown fox jumps over the lazy dog")
+ input2 = mock("input2")
+ input2.should_receive(:to_str).and_return("the quick brown fox jumps over the lazy dog")
+ OpenSSL.fixed_length_secure_compare(input1, input2).should == true
+ end
+
+ it "does not accept arguments that are not string and cannot be coerced into strings" do
+ -> {
+ OpenSSL.fixed_length_secure_compare("input1", :input2)
+ }.should.raise(TypeError, 'no implicit conversion of Symbol into String')
+
+ -> {
+ OpenSSL.fixed_length_secure_compare(Object.new, "input2")
+ }.should.raise(TypeError, 'no implicit conversion of Object into String')
+ end
+
+ it "raises an ArgumentError for two strings of different size" do
+ input1 = "the quick brown fox jumps over the lazy dog"
+ input2 = "the quick brown fox"
+ -> {
+ OpenSSL.fixed_length_secure_compare(input1, input2)
+ }.should.raise(ArgumentError, 'inputs must be of equal length')
+ end
+end
diff --git a/spec/ruby/library/openssl/hmac/digest_spec.rb b/spec/ruby/library/openssl/hmac/digest_spec.rb
index 36edee87bd..03ed136e64 100644
--- a/spec/ruby/library/openssl/hmac/digest_spec.rb
+++ b/spec/ruby/library/openssl/hmac/digest_spec.rb
@@ -1,10 +1,10 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../shared/constants', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../shared/constants'
require 'openssl'
describe "OpenSSL::HMAC.digest" do
it "returns an SHA1 digest" do
- cur_digest = OpenSSL::Digest::SHA1.new
+ cur_digest = OpenSSL::Digest.new("SHA1")
cur_digest.digest.should == HMACConstants::BlankSHA1Digest
digest = OpenSSL::HMAC.digest(cur_digest,
HMACConstants::Key,
diff --git a/spec/ruby/library/openssl/hmac/hexdigest_spec.rb b/spec/ruby/library/openssl/hmac/hexdigest_spec.rb
index b61bcf6a8f..3508c1bbd7 100644
--- a/spec/ruby/library/openssl/hmac/hexdigest_spec.rb
+++ b/spec/ruby/library/openssl/hmac/hexdigest_spec.rb
@@ -1,10 +1,10 @@
-require File.expand_path('../../../../spec_helper', __FILE__)
-require File.expand_path('../../shared/constants', __FILE__)
+require_relative '../../../spec_helper'
+require_relative '../shared/constants'
require 'openssl'
describe "OpenSSL::HMAC.hexdigest" do
it "returns an SHA1 hex digest" do
- cur_digest = OpenSSL::Digest::SHA1.new
+ cur_digest = OpenSSL::Digest.new("SHA1")
cur_digest.hexdigest.should == HMACConstants::BlankSHA1HexDigest
hexdigest = OpenSSL::HMAC.hexdigest(cur_digest,
HMACConstants::Key,
diff --git a/spec/ruby/library/openssl/kdf/pbkdf2_hmac_spec.rb b/spec/ruby/library/openssl/kdf/pbkdf2_hmac_spec.rb
new file mode 100644
index 0000000000..2558dbb9ec
--- /dev/null
+++ b/spec/ruby/library/openssl/kdf/pbkdf2_hmac_spec.rb
@@ -0,0 +1,162 @@
+require_relative '../../../spec_helper'
+require 'openssl'
+
+describe "OpenSSL::KDF.pbkdf2_hmac" do
+ before :each do
+ @defaults = {
+ salt: "\x00".b * 16,
+ iterations: 20_000,
+ length: 16,
+ hash: "sha1"
+ }
+ end
+
+ it "creates the same value with the same input" do
+ key = OpenSSL::KDF.pbkdf2_hmac("secret", **@defaults)
+ key.should == "!\x99+\xF0^\xD0\x8BM\x158\xC4\xAC\x9C\xF1\xF0\xE0".b
+ end
+
+ it "supports nullbytes embedded in the password" do
+ key = OpenSSL::KDF.pbkdf2_hmac("sec\x00ret".b, **@defaults)
+ key.should == "\xB9\x7F\xB0\xC2\th\xC8<\x86\xF3\x94Ij7\xEF\xF1".b
+ end
+
+ it "coerces the password into a String using #to_str" do
+ pass = mock("pass")
+ pass.should_receive(:to_str).and_return("secret")
+ key = OpenSSL::KDF.pbkdf2_hmac(pass, **@defaults)
+ key.should == "!\x99+\xF0^\xD0\x8BM\x158\xC4\xAC\x9C\xF1\xF0\xE0".b
+ end
+
+ it "coerces the salt into a String using #to_str" do
+ salt = mock("salt")
+ salt.should_receive(:to_str).and_return("\x00".b * 16)
+ key = OpenSSL::KDF.pbkdf2_hmac("secret", **@defaults, salt: salt)
+ key.should == "!\x99+\xF0^\xD0\x8BM\x158\xC4\xAC\x9C\xF1\xF0\xE0".b
+ end
+
+ it "coerces the iterations into an Integer using #to_int" do
+ iterations = mock("iterations")
+ iterations.should_receive(:to_int).and_return(20_000)
+ key = OpenSSL::KDF.pbkdf2_hmac("secret", **@defaults, iterations: iterations)
+ key.should == "!\x99+\xF0^\xD0\x8BM\x158\xC4\xAC\x9C\xF1\xF0\xE0".b
+ end
+
+ it "coerces the length into an Integer using #to_int" do
+ length = mock("length")
+ length.should_receive(:to_int).and_return(16)
+ key = OpenSSL::KDF.pbkdf2_hmac("secret", **@defaults, length: length)
+ key.should == "!\x99+\xF0^\xD0\x8BM\x158\xC4\xAC\x9C\xF1\xF0\xE0".b
+ end
+
+ it "accepts a OpenSSL::Digest object as hash" do
+ hash = OpenSSL::Digest.new("sha1")
+ key = OpenSSL::KDF.pbkdf2_hmac("secret", **@defaults, hash: hash)
+ key.should == "!\x99+\xF0^\xD0\x8BM\x158\xC4\xAC\x9C\xF1\xF0\xE0".b
+ end
+
+ it "accepts an empty password" do
+ key = OpenSSL::KDF.pbkdf2_hmac("", **@defaults)
+ key.should == "k\x9F-\xB1\xF7\x9A\v\xA1(C\xF9\x85!P\xEF\x8C".b
+ end
+
+ it "accepts an empty salt" do
+ key = OpenSSL::KDF.pbkdf2_hmac("secret", **@defaults, salt: "")
+ key.should == "\xD5f\xE5\xEA\xF91\x1D\xD3evD\xED\xDB\xE80\x80".b
+ end
+
+ it "accepts an empty length" do
+ key = OpenSSL::KDF.pbkdf2_hmac("secret", **@defaults, length: 0)
+ key.should.empty?
+ end
+
+ it "accepts an arbitrary length" do
+ key = OpenSSL::KDF.pbkdf2_hmac("secret", **@defaults, length: 19)
+ key.should == "!\x99+\xF0^\xD0\x8BM\x158\xC4\xAC\x9C\xF1\xF0\xE0\xCF\xBB\x7F".b
+ end
+
+ it "accepts any hash function known to OpenSSL" do
+ key = OpenSSL::KDF.pbkdf2_hmac("secret", **@defaults, hash: "sha512")
+ key.should == "N\x12}D\xCE\x99\xDBC\x8E\xEC\xAAr\xEA1\xDF\xFF".b
+ end
+
+ it "raises a TypeError when password is not a String and does not respond to #to_str" do
+ -> {
+ OpenSSL::KDF.pbkdf2_hmac(Object.new, **@defaults)
+ }.should.raise(TypeError, "no implicit conversion of Object into String")
+ end
+
+ it "raises a TypeError when salt is not a String and does not respond to #to_str" do
+ -> {
+ OpenSSL::KDF.pbkdf2_hmac("secret", **@defaults, salt: Object.new)
+ }.should.raise(TypeError, "no implicit conversion of Object into String")
+ end
+
+ it "raises a TypeError when iterations is not an Integer and does not respond to #to_int" do
+ -> {
+ OpenSSL::KDF.pbkdf2_hmac("secret", **@defaults, iterations: Object.new)
+ }.should.raise(TypeError, "no implicit conversion of Object into Integer")
+ end
+
+ it "raises a TypeError when length is not an Integer and does not respond to #to_int" do
+ -> {
+ OpenSSL::KDF.pbkdf2_hmac("secret", **@defaults, length: Object.new)
+ }.should.raise(TypeError, "no implicit conversion of Object into Integer")
+ end
+
+ it "raises a TypeError when hash is neither a String nor an OpenSSL::Digest" do
+ -> {
+ OpenSSL::KDF.pbkdf2_hmac("secret", **@defaults, hash: Object.new)
+ }.should.raise(TypeError)
+ end
+
+ version_is OpenSSL::VERSION, "4.0.0" do
+ it "raises a OpenSSL::Digest::DigestError for unknown digest algorithms" do
+ -> {
+ OpenSSL::KDF.pbkdf2_hmac("secret", **@defaults, hash: "wd40")
+ }.should.raise(OpenSSL::Digest::DigestError, /wd40/)
+ end
+ end
+
+ it "treats salt as a required keyword" do
+ -> {
+ OpenSSL::KDF.pbkdf2_hmac("secret", **@defaults.except(:salt))
+ }.should.raise(ArgumentError, 'missing keyword: :salt')
+ end
+
+ it "treats iterations as a required keyword" do
+ -> {
+ OpenSSL::KDF.pbkdf2_hmac("secret", **@defaults.except(:iterations))
+ }.should.raise(ArgumentError, 'missing keyword: :iterations')
+ end
+
+ it "treats length as a required keyword" do
+ -> {
+ OpenSSL::KDF.pbkdf2_hmac("secret", **@defaults.except(:length))
+ }.should.raise(ArgumentError, 'missing keyword: :length')
+ end
+
+ it "treats hash as a required keyword" do
+ -> {
+ OpenSSL::KDF.pbkdf2_hmac("secret", **@defaults.except(:hash))
+ }.should.raise(ArgumentError, 'missing keyword: :hash')
+ end
+
+ it "treats all keywords as required" do
+ -> {
+ OpenSSL::KDF.pbkdf2_hmac("secret")
+ }.should.raise(ArgumentError, 'missing keywords: :salt, :iterations, :length, :hash')
+ end
+
+ guard -> { OpenSSL::OPENSSL_VERSION_NUMBER >= 0x30000000 } do
+ it "raises an OpenSSL::KDF::KDFError for 0 or less iterations" do
+ -> {
+ OpenSSL::KDF.pbkdf2_hmac("secret", **@defaults, iterations: 0)
+ }.should.raise(OpenSSL::KDF::KDFError, "PKCS5_PBKDF2_HMAC: invalid iteration count")
+
+ -> {
+ OpenSSL::KDF.pbkdf2_hmac("secret", **@defaults, iterations: -1)
+ }.should.raise(OpenSSL::KDF::KDFError, /PKCS5_PBKDF2_HMAC/)
+ end
+ end
+end
diff --git a/spec/ruby/library/openssl/kdf/scrypt_spec.rb b/spec/ruby/library/openssl/kdf/scrypt_spec.rb
new file mode 100644
index 0000000000..c00f91bb5b
--- /dev/null
+++ b/spec/ruby/library/openssl/kdf/scrypt_spec.rb
@@ -0,0 +1,210 @@
+require_relative '../../../spec_helper'
+require 'openssl'
+
+# LibreSSL seems not to support scrypt
+guard -> { OpenSSL::OPENSSL_VERSION.start_with?('OpenSSL') and OpenSSL::OPENSSL_VERSION_NUMBER >= 0x10100000 } do
+ describe "OpenSSL::KDF.scrypt" do
+ before :each do
+ @defaults = {
+ salt: "\x00".b * 16,
+ N: 2**14,
+ r: 8,
+ p: 1,
+ length: 32
+ }
+ end
+
+ it "creates the same value with the same input" do
+ key = OpenSSL::KDF.scrypt("secret", **@defaults)
+ key.should == "h\xB2k\xDF]\xDA\xE1.-(\xCF\xAC\x91D\x8F\xC2a\x9C\x9D\x17}\xF2\x84T\xD4)\xC2>\xFE\x93\xE3\xF4".b
+ end
+
+ it "supports nullbytes embedded into the password" do
+ key = OpenSSL::KDF.scrypt("sec\x00ret".b, **@defaults)
+ key.should == "\xF9\xA4\xA0\xF1p\xF4\xF0\xCAT\xB4v\xEB\r7\x88N\xF7\x15]Ns\xFCwt4a\xC9\xC6\xA7\x13\x81&".b
+ end
+
+ it "coerces the password into a String using #to_str" do
+ pass = mock("pass")
+ pass.should_receive(:to_str).and_return("secret")
+ key = OpenSSL::KDF.scrypt(pass, **@defaults)
+ key.should == "h\xB2k\xDF]\xDA\xE1.-(\xCF\xAC\x91D\x8F\xC2a\x9C\x9D\x17}\xF2\x84T\xD4)\xC2>\xFE\x93\xE3\xF4".b
+ end
+
+ it "coerces the salt into a String using #to_str" do
+ salt = mock("salt")
+ salt.should_receive(:to_str).and_return("\x00".b * 16)
+ key = OpenSSL::KDF.scrypt("secret", **@defaults, salt: salt)
+ key.should == "h\xB2k\xDF]\xDA\xE1.-(\xCF\xAC\x91D\x8F\xC2a\x9C\x9D\x17}\xF2\x84T\xD4)\xC2>\xFE\x93\xE3\xF4".b
+ end
+
+ it "coerces the N into an Integer using #to_int" do
+ n = mock("N")
+ n.should_receive(:to_int).and_return(2**14)
+ key = OpenSSL::KDF.scrypt("secret", **@defaults, N: n)
+ key.should == "h\xB2k\xDF]\xDA\xE1.-(\xCF\xAC\x91D\x8F\xC2a\x9C\x9D\x17}\xF2\x84T\xD4)\xC2>\xFE\x93\xE3\xF4".b
+ end
+
+ it "coerces the r into an Integer using #to_int" do
+ r = mock("r")
+ r.should_receive(:to_int).and_return(8)
+ key = OpenSSL::KDF.scrypt("secret", **@defaults, r: r)
+ key.should == "h\xB2k\xDF]\xDA\xE1.-(\xCF\xAC\x91D\x8F\xC2a\x9C\x9D\x17}\xF2\x84T\xD4)\xC2>\xFE\x93\xE3\xF4".b
+ end
+
+ it "coerces the p into an Integer using #to_int" do
+ p = mock("p")
+ p.should_receive(:to_int).and_return(1)